The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
feat(lenses): built-in Files Changed lens
Claude4dde65a85e6e
diff --git a/cli/beacon/internal/endpoint/dashboard/lenses/files-changed.lens.html b/cli/beacon/internal/endpoint/dashboard/lenses/files-changed.lens.htmlnew file mode 100644index 00000000..b578f94a--- /dev/null+++ b/cli/beacon/internal/endpoint/dashboard/lenses/files-changed.lens.html@@ -0,0 +1,247 @@+<!doctype html>+<html lang="en">+<head>+<meta charset="utf-8">+<title>Files Changed</title>+<script type="application/beacon-lens+json">+{+ "id": "files-changed",+ "title": "Files Changed",+ "description": "Every file the agent created, edited or deleted, as a tree, with each edit's diff in order.",+ "icon": "file",+ "version": 1,+ "api": "beacon.lens.v1",+ "author": "Beacon"+}+</script>+<style>+ body {+ margin: 0;+ color: var(--beacon-text, #111827);+ font: 400 13px/1.5 var(--beacon-font-sans, ui-sans-serif, system-ui, sans-serif);+ }+ .muted { color: var(--beacon-muted, #6b7280); }+ .mono, pre { font: 13px/1.45 var(--beacon-font-mono, ui-monospace, SFMono-Regular, Menlo, monospace); }+ .add { color: var(--beacon-ok, #047857); }+ .del { color: var(--beacon-danger, #b91c1c); }+ #summary { margin: 0 0 10px; }+ .layout { display: grid; grid-template-columns: minmax(12rem, 18rem) minmax(0, 1fr); gap: 16px; align-items: start; }+ @media (max-width: 640px) { .layout { grid-template-columns: minmax(0, 1fr); } }+ .tree { border-right: 1px solid var(--beacon-line, rgba(0,0,0,0.1)); padding-right: 8px; }+ .row { display: flex; align-items: baseline; gap: 6px; width: 100%; padding: 2px 6px; border: 0; border-radius: 4px; background: none; color: inherit; font: inherit; text-align: left; }+ .row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }+ .row .counts { white-space: nowrap; font-variant-numeric: tabular-nums; }+ button.row { cursor: pointer; }+ button.row:hover { background: var(--beacon-panel-soft, #f9fafb); }+ button.row[aria-current="true"] { background: var(--beacon-accent-soft, #e2f0f8); }+ button.row:focus-visible { outline: 2px solid var(--beacon-accent, #036aa2); outline-offset: -2px; }+ .dir { color: var(--beacon-muted, #6b7280); }+ .tag { font-size: 12px; color: var(--beacon-muted, #6b7280); }+ h2 { margin: 0 0 8px; font-size: 13px; font-weight: 400; word-break: break-all; }+ .edit { margin: 0 0 14px; }+ .edit-head { margin: 0 0 4px; }+ pre { margin: 0; padding: 6px 8px; overflow-x: auto; border: 1px solid var(--beacon-line, rgba(0,0,0,0.1)); border-radius: 4px; white-space: pre; }+ pre span { display: block; }+ .hunk { color: var(--beacon-muted, #6b7280); }+</style>+</head>+<body>+<p id="status" class="muted">Loading trace…</p>+<main id="root" hidden>+ <p id="summary" class="muted"></p>+ <div class="layout">+ <nav id="tree" class="tree" aria-label="Changed files"></nav>+ <section id="detail" aria-live="polite"></section>+ </div>+</main>+<script>+(function () {+ "use strict";+ // The file.operation values and actions that change a file, as `beacon git` counts them.+ var WRITE_OPS = { create: 1, modify: 1, delete: 1, write: 1, edit: 1, rename: 1, move: 1 };+ var WRITE_ACTIONS = { "file.created": 1, "file.modified": 1, "file.deleted": 1, "file.edited": 1 };+ var MAX_DIFF_LINES = 2000;+ var fmt = new Intl.NumberFormat();++ // Every node is built with textContent: paths and diffs are untrusted trace content.+ function el(tag, text, className) {+ var node = document.createElement(tag);+ if (text !== undefined && text !== null) node.textContent = String(text);+ if (className) node.className = className;+ return node;+ }++ function isWrite(event) {+ var op = String((event.file && event.file.operation) || "").toLowerCase();+ return !!(WRITE_OPS[op] || WRITE_ACTIONS[event.action]);+ }++ function diffText(file) {+ var d = file && file.diff;+ return d && d.included && typeof d.text === "string" ? d.text : null;+ }++ 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;+ });+ return { added: added, removed: removed };+ }++ function relative(path, root) {+ if (root && path.indexOf(root + "/") === 0) return path.slice(root.length + 1);+ return path;+ }++ function counts(added, removed, missing) {+ var span = el("span", null, "counts mono");+ if (added) span.appendChild(el("span", "+" + fmt.format(added) + " ", "add"));+ if (removed) span.appendChild(el("span", "−" + fmt.format(removed), "del"));+ if (!added && !removed && missing) span.appendChild(el("span", "no diff", "muted"));+ return span;+ }++ function collect(data) {+ var trace = data.trace || {};+ var events = Array.isArray(trace.events) ? trace.events : [];+ var root = (trace.summary && trace.summary.session && trace.summary.session.working_directory) || "";+ root = root.replace(/\/+$/, "");+ var files = {};+ var order = [];+ var reads = {};+ events.forEach(function (event) {+ if (!event || !event.file || !event.file.path) return;+ var path = relative(String(event.file.path), root);+ if (!isWrite(event)) {+ reads[path] = 1;+ return;+ }+ if (!files[path]) {+ files[path] = { path: path, edits: [], added: 0, removed: 0, missing: false, ops: {} };+ order.push(path);+ }+ var f = files[path];+ var text = diffText(event.file);+ var c = countLines(text);+ f.added += c.added;+ f.removed += c.removed;+ if (text === null) f.missing = true;+ f.ops[String(event.file.operation || event.action)] = 1;+ f.edits.push({ event: event, text: text });+ });+ order.sort();+ return { files: files, order: order, reads: Object.keys(reads).length, total: events.length, truncated: !!data.truncated };+ }++ function renderTree(model, select) {+ var tree = document.getElementById("tree");+ tree.textContent = "";+ var shownDirs = {};+ var buttons = {};+ model.order.forEach(function (path) {+ var parts = path.split("/");+ // One row per directory level not shown yet, indented by depth.+ for (var i = 0; i < parts.length - 1; i++) {+ var dir = parts.slice(0, i + 1).join("/");+ if (shownDirs[dir]) continue;+ shownDirs[dir] = 1;+ var dirRow = el("div", null, "row dir");+ dirRow.style.paddingLeft = (6 + i * 12) + "px";+ dirRow.appendChild(el("span", parts[i] + "/", "name mono"));+ tree.appendChild(dirRow);+ }+ var f = model.files[path];+ var row = el("button", null, "row");+ row.type = "button";+ row.style.paddingLeft = (6 + (parts.length - 1) * 12) + "px";+ row.title = path;+ row.appendChild(el("span", parts[parts.length - 1], "name mono"));+ if (f.ops.create || f.ops["file.created"]) row.appendChild(el("span", "new", "tag"));+ if (f.ops["delete"] || f.ops["file.deleted"]) row.appendChild(el("span", "deleted", "tag"));+ row.appendChild(counts(f.added, f.removed, f.missing));+ row.addEventListener("click", function () { select(path); });+ buttons[path] = row;+ tree.appendChild(row);+ });+ return buttons;+ }++ 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));+ });+ if (lines.length > MAX_DIFF_LINES) {+ pre.appendChild(el("span", "… " + fmt.format(lines.length - MAX_DIFF_LINES) + " more lines", "hunk"));+ }+ return pre;+ }++ function renderDetail(f) {+ var detail = document.getElementById("detail");+ detail.textContent = "";+ detail.appendChild(el("h2", f.path, "mono"));+ f.edits.forEach(function (edit) {+ var e = edit.event;+ var block = el("div", null, "edit");+ var head = el("p", null, "edit-head muted");+ var when = e.timestamp ? new Date(e.timestamp) : null;+ head.textContent = "#" + e.number + " · " + (e.file.operation || e.action) ++ (when && !isNaN(when) ? " · " + when.toLocaleTimeString() : "");+ block.appendChild(head);+ if (edit.text !== null) {+ block.appendChild(renderDiff(edit.text));+ if (e.file.diff.truncated) block.appendChild(el("p", "Diff truncated by Beacon's size limits.", "muted"));+ } else {+ var why = (e.file.diff && e.file.diff.redacted) ? "redacted" : "not retained";+ var facts = [why];+ if (e.file.diff_bytes) facts.push(fmt.format(e.file.diff_bytes) + " bytes");+ if (e.file.diff_hash) facts.push(e.file.diff_hash);+ block.appendChild(el("p", "Diff " + facts.join(" · "), "muted mono"));+ }+ detail.appendChild(block);+ });+ }++ function render(data) {+ var model = collect(data || {});+ var summary = document.getElementById("summary");+ if (model.order.length === 0) {+ summary.textContent = "No files were changed in this trace" + (model.reads ? " (" + fmt.format(model.reads) + " read)." : ".");+ document.querySelector(".layout").hidden = true;+ } else {+ var added = 0, removed = 0, edits = 0;+ model.order.forEach(function (p) { added += model.files[p].added; removed += model.files[p].removed; edits += model.files[p].edits.length; });+ summary.textContent = fmt.format(model.order.length) + (model.order.length === 1 ? " file" : " files") + " changed in " ++ fmt.format(edits) + (edits === 1 ? " edit" : " edits") + " · +" + fmt.format(added) + " −" + fmt.format(removed) ++ (model.reads ? " · " + fmt.format(model.reads) + " read" : "") ++ (model.truncated ? " · trace truncated, later edits missing" : "");+ var buttons;+ var select = function (path) {+ Object.keys(buttons).forEach(function (p) { buttons[p].setAttribute("aria-current", String(p === path)); });+ renderDetail(model.files[path]);+ };+ buttons = renderTree(model, select);+ select(model.order[0]);+ }+ document.getElementById("status").hidden = true;+ document.getElementById("root").hidden = false;+ }++ window.beacon.getTrace().then(render, function (err) {+ document.getElementById("status").textContent = "Could not load this trace: " + ((err && err.message) || err);+ });+})();+</script>+</body>+</html>diff --git a/cli/beacon/internal/endpoint/dashboard/lenses_test.go b/cli/beacon/internal/endpoint/dashboard/lenses_test.goindex c0ac232f..415ee249 100644--- a/cli/beacon/internal/endpoint/dashboard/lenses_test.go+++ b/cli/beacon/internal/endpoint/dashboard/lenses_test.go@@ -3,6 +3,7 @@ package dashboardimport ("bytes""encoding/json"+ "io/fs""net/http""net/http/httptest""os"@@ -76,6 +77,29 @@ func TestBuiltinLensesLoad(t *testing.T) {}}+// Built-in lenses are what users copy, so each one is held to the rules the spec sets for every+// lens: untrusted content never goes through an HTML parser, and nothing is loaded by URL.+func TestBuiltinLensesFollowTheSpecRules(t *testing.T) {+ names, err := fs.Glob(builtinLensFiles, "lenses/*.lens.html")+ if err != nil || len(names) == 0 {+ t.Fatalf("built-in lenses: %v, %v", names, err)+ }+ for _, name := range names {+ html, err := builtinLensFiles.ReadFile(name)+ if err != nil {+ t.Fatal(err)+ }+ for _, banned := range []string{"innerHTML", "outerHTML", "insertAdjacentHTML", "document.write", "://", "fetch(", "XMLHttpRequest", "localStorage", "eval("} {+ if bytes.Contains(html, []byte(banned)) {+ t.Errorf("%s uses %q, which the spec forbids", name, banned)+ }+ }+ if !bytes.Contains(html, []byte("window.beacon.getTrace()")) {+ t.Errorf("%s does not call window.beacon.getTrace()", name)+ }+ }+}+func TestLoadBuiltinLensesRejectsABrokenLens(t *testing.T) {manifest := func(id, api string) string {return `<!doctype html><script type="application/beacon-lens+json">{"id":"` + id + `","title":"T","version":1,"api":"` + api + `"}</script>`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.jsonlindex 77326b71..df3df65e 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@@ -1,2 +1,12 @@{"timestamp":"2026-06-11T10:00:00Z","vendor":"beacon","product":"endpoint-agent","schema_version":"1.0","event":{"id":"evt-prompt","kind":"agent_runtime","action":"prompt.submitted","category":"prompt"},"severity":"info","endpoint":{"os":"linux"},"harness":{"name":"claude_code"},"session":{"id":"s1"},"prompt":{"text":"clean up <img src=x onerror=\"window.parent.document.title='pwned'\">"},"message":"prompt.submitted"}{"timestamp":"2026-06-11T10:01:00Z","vendor":"beacon","product":"endpoint-agent","schema_version":"1.0","event":{"id":"evt-rm","kind":"agent_runtime","action":"command.executed","category":"command"},"severity":"info","endpoint":{"os":"linux"},"harness":{"name":"claude_code"},"session":{"id":"s1"},"command":{"command":"rm -rf /","exit_code":1},"message":"command.executed"}+{"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:00Z", "event": {"id": "rich-prompt", "kind": "agent_runtime", "action": "prompt.submitted", "category": "prompt"}, "message": "prompt.submitted", "prompt": {"text": "Make the retry backoff deterministic"}, "content": {"retention": "full", "included": 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:00:10Z", "event": {"id": "rich-read", "kind": "agent_runtime", "action": "file.read", "category": "file"}, "message": "file.read", "file": {"path": "/work/service/README.md", "operation": "read"}}+{"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:20Z", "event": {"id": "rich-edit-1", "kind": "agent_runtime", "action": "file.modified", "category": "file"}, "message": "file.modified", "file": {"path": "/work/service/internal/retry/retry.go", "operation": "modify", "language": "go", "diff": "@@ -10,7 +10,7 @@ func Backoff(n int) time.Duration {\n-\treturn base * time.Duration(rand.Intn(n+1))\n+\treturn base * time.Duration(n)\n }\n", "diff_hash": "sha256:aaa", "diff_bytes": 120}, "content": {"retention": "full", "included": 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:00:30Z", "event": {"id": "rich-approval", "kind": "agent_runtime", "action": "approval.decided", "category": "approval"}, "message": "approval.decided", "approval": {"required": true, "decision": "allow", "reason": "user approved Bash"}}+{"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:31Z", "event": {"id": "rich-test", "kind": "agent_runtime", "action": "command.executed", "category": "command"}, "message": "command.executed", "command": {"command": "go test ./internal/retry/...", "exit_code": 0, "duration_ms": 2100}}+{"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:40Z", "event": {"id": "rich-create", "kind": "agent_runtime", "action": "file.created", "category": "file"}, "message": "file.created", "file": {"path": "/work/service/docs/retry.md", "operation": "create", "language": "markdown", "diff": "@@ -0,0 +1,3 @@\n+# Retry\n+\n+Backoff is linear and deterministic.\n", "diff_hash": "sha256:bbb", "diff_bytes": 60}, "content": {"retention": "full", "included": 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:00:50Z", "event": {"id": "rich-edit-2", "kind": "agent_runtime", "action": "file.modified", "category": "file"}, "message": "file.modified", "file": {"path": "/work/service/internal/retry/retry.go", "operation": "modify", "language": "go", "diff": "@@ -1,6 +1,5 @@\n import (\n-\t\"math/rand\"\n \t\"time\"\n )\n", "diff_hash": "sha256:ccc", "diff_bytes": 50}, "content": {"retention": "full", "included": 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: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"}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.tsnew file mode 100644index 00000000..08708552--- /dev/null+++ b/cli/beacon/internal/endpoint/dashboard/testdata/lens-e2e/tests/builtin-files-changed.spec.ts@@ -0,0 +1,37 @@+import { expect, test } from '@playwright/test';++test('files changed: tree, counts, diffs in order, reads and missing diffs', async ({ page }) => {+ await page.goto('/session.html?id=rich&lens=files-changed');+ const frame = page.frameLocator('iframe.lens-frame');+ await expect(frame.locator('#root')).toBeVisible();++ // Three files written (two edits to retry.go), one read that is not listed.+ await expect(frame.locator('#summary')).toHaveText('3 files changed in 4 edits · +4 −2 · 1 read');+ const files = frame.locator('#tree button.row');+ await expect(files).toHaveCount(3);+ await expect(files.nth(0)).toContainText('retry.md');+ await expect(files.nth(0)).toContainText('new');+ await expect(frame.locator('#tree')).not.toContainText('README.md');++ // The first file is selected; paths are relative to the working directory.+ await expect(frame.locator('#detail h2')).toHaveText('docs/retry.md');++ await files.filter({ hasText: 'retry.go' }).click();+ await expect(frame.locator('#detail h2')).toHaveText('internal/retry/retry.go');+ const edits = frame.locator('#detail .edit');+ await expect(edits).toHaveCount(2);+ await expect(edits.nth(0)).toContainText('#3 · modify');+ await expect(edits.nth(0).locator('pre .del')).toContainText('rand.Intn');+ await expect(edits.nth(0).locator('pre .add')).toContainText('time.Duration(n)');+ await expect(edits.nth(1)).toContainText('#7 · modify');++ await files.filter({ hasText: 'jitter.go' }).click();+ await expect(files.filter({ hasText: 'jitter.go' })).toContainText('deleted');+ await expect(frame.locator('#detail')).toContainText('Diff not retained · 900 bytes · sha256:ddd');+});++test('files changed: a trace without writes says so', async ({ page }) => {+ await page.goto('/session.html?id=s1&lens=files-changed');+ const frame = page.frameLocator('iframe.lens-frame');+ await expect(frame.locator('#summary')).toHaveText('No files were changed in this trace.');+});