Skip to content

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

feat(lenses): show lenses as tabs on the session page

Claude46bb15a7f416
diff --git a/CLAUDE.md b/CLAUDE.md
index dcc2e7b9..20111889 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -15,7 +15,7 @@ Beacon Endpoint Agent is a local-only endpoint telemetry agent for AI runtimes.
- `plugins`: TypeScript sources for the managed runtime plugins/extensions (`opencode-beacon`, `cline-beacon`, `pi-beacon`, `omp-beacon`, `openclaw-beacon`, `prime-beacon`, `omo-beacon`), each mirrored into an embedded copy under `cli/beacon/internal/endpoint/hooks/assets/`.
- `agent-skills`: publishable Agent Skills plugin for the traces-to-memory workflow (`beacon-memory-recall`, `beacon-memory-distill`, `beacon-memory-promote`) with manifests for Claude Code, Agent Plugins (Codex, Copilot, VS Code, Kiro, Devin), Cursor, Kimi Code, and Gemini CLI. At the repo root, `.claude-plugin/marketplace.json` is read by most harnesses, `.cursor-plugin/marketplace.json` by Cursor, and `package.json` (`pi.skills` only) makes the repo a Pi/Prime Agent package; keep that root `package.json` free of dependencies and scripts. `cli/beacon/cmd/agent_skills_test.go` checks every `beacon` command and flag the skills name against the real command tree, so rename a command and update the skills together.
- `rules` and `spec/threat-rules`: the open rule corpus and the Threat Rules format it conforms to.
-- `spec/lenses`: the Lenses format — single-file HTML views of one trace that the local dashboard runs in a sandboxed, network-less frame and feeds once through `window.beacon.getTrace()`. The contract types (`LensManifestV1`, `LensDataV1`) live in `pkg/asymptoteobserve/lens.go`, and `lens_test.go` pins the spec's examples and manifest schema to them. The dashboard builds the data in `BuildLensData` (`/api/lens-data`), lists lenses at `/api/lenses`, and serves each lens at `/lenses/frame/<id>` under the spec's CSP with `lenses/prelude.js` (which defines `window.beacon`) injected ahead of it; that route is the only one that may be framed. Built-in lenses are `cli/beacon/internal/endpoint/dashboard/lenses/*.lens.html`, and `activity` is byte-identical to the spec example (a test enforces it). The session-page tabs and the `beacon lenses` CLI are not built yet.
+- `spec/lenses`: the Lenses format — single-file HTML views of one trace that the local dashboard runs in a sandboxed, network-less frame and feeds once through `window.beacon.getTrace()`. The contract types (`LensManifestV1`, `LensDataV1`) live in `pkg/asymptoteobserve/lens.go`, and `lens_test.go` pins the spec's examples and manifest schema to them. The dashboard builds the data in `BuildLensData` (`/api/lens-data`), lists lenses at `/api/lenses`, and serves each lens at `/lenses/frame/<id>` under the spec's CSP with `lenses/prelude.js` (which defines `window.beacon`) injected ahead of it; that route is the only one that may be framed. Built-in lenses are `cli/beacon/internal/endpoint/dashboard/lenses/*.lens.html`, and `activity` is byte-identical to the spec example (a test enforces it). The session page (`static/session.html`, `initLensTabs` in `app.js`) shows lenses as tabs fed by `/api/lens-data?session=`, which projects exactly the events that page lists; it is the host half of the protocol and closes a lens that errors, stalls, or navigates its own frame. The `beacon lenses` CLI is not built yet.
- `beacon-sandbox`: harness that runs a real Claude Code session in a disposable sandbox and checks what Beacon captured. See `beacon-sandbox/AGENTS.md`.
- `packaging`: macOS, Linux, and Windows packaging and deployment assets.
- `docs`: the published documentation site (docs.asymptotelabs.ai).
diff --git a/cli/beacon/internal/endpoint/dashboard/lens_data.go b/cli/beacon/internal/endpoint/dashboard/lens_data.go
index a72a6bcd..4b8d3833 100644
--- a/cli/beacon/internal/endpoint/dashboard/lens_data.go
+++ b/cli/beacon/internal/endpoint/dashboard/lens_data.go
@@ -39,12 +39,6 @@ func BuildLensData(logPath, traceID string, opts LensDataOptions) (LensDataV1, b
if err != nil || !ok {
return LensDataV1{}, ok, err
}
- data := LensDataV1{
- APIVersion: asymptoteobserve.LensAPIVersion,
- Trace: TraceBundleFromShow(show, version.Version),
- }
- data.Truncated = fitLensEvents(&data.Trace, lensDataEventBudget)
-
var raw []schema.Event
err = StreamEvents(logPath, func(event schema.Event) error {
if traceProjectionID(event) == traceID {
@@ -55,6 +49,61 @@ func BuildLensData(logPath, traceID string, opts LensDataOptions) (LensDataV1, b
if err != nil {
return LensDataV1{}, false, err
}
+ return lensDataFromShow(show, raw, opts), true, nil
+}
+
+// BuildSessionLensData is BuildLensData for the dashboard's session page, which shows every event
+// whose session ID is exactly session. A session is not always one trace: a runtime's hook
+// events project to its session while its OTLP spans project to their own trace IDs. So this
+// projects the same events the session page lists, with the trace projection code, into one bundle
+// identified like a session trace. It reads the live JSONL, as the session page does.
+func BuildSessionLensData(logPath, session string, opts LensDataOptions) (LensDataV1, bool, error) {
+ result, err := ReadEvents(logPath, EventQuery{Session: session, NoLimit: true})
+ if err != nil {
+ return LensDataV1{}, false, err
+ }
+ records := make([]EventRecord, 0, len(result.Events))
+ for _, record := range result.Events {
+ if sessionID(record.Event) == session {
+ records = append(records, record)
+ }
+ }
+ if len(records) == 0 {
+ return LensDataV1{}, false, nil
+ }
+ SortRecordsAppendOrder(records)
+
+ first := records[0].Event
+ harness := asymptoteobserve.NormalizeHarnessName(first.Harness.Name)
+ if harness == "" {
+ harness = strings.TrimSpace(first.Harness.Name)
+ }
+ agg := newTraceAggregate("session:"+harness+":"+session, first)
+ raw := make([]schema.Event, 0, len(records))
+ for _, record := range records {
+ te := traceEventFromRecord(record, len(agg.events)+1)
+ agg.events = append(agg.events, te)
+ agg.update(record.Event, te)
+ raw = append(raw, record.Event)
+ }
+ agg.finish()
+ total := len(agg.events)
+ show := TraceShowResultV1{
+ Trace: agg.summary,
+ Events: agg.events,
+ Spans: spansFromEvents(agg.events),
+ Range: TraceRangeV1{TotalEvents: total, ReturnedEvents: total, Offset: 1, Limit: total},
+ }
+ return lensDataFromShow(show, raw, opts), true, nil
+}
+
+// lensDataFromShow finishes lens data from a projected trace and the endpoint events behind it.
+func lensDataFromShow(show TraceShowResultV1, raw []schema.Event, opts LensDataOptions) LensDataV1 {
+ data := LensDataV1{
+ APIVersion: asymptoteobserve.LensAPIVersion,
+ Trace: TraceBundleFromShow(show, version.Version),
+ }
+ data.Truncated = fitLensEvents(&data.Trace, lensDataEventBudget)
// Findings and coverage are each optional in the contract. A rule pack that fails to load
// leaves Findings nil -- "not scanned" -- instead of failing the whole lens, since every other
// part of the data is still right.
@@ -62,7 +111,7 @@ func BuildLensData(logPath, traceID string, opts LensDataOptions) (LensDataV1, b
data.Findings = findings
}
data.TokenCoverage = lensTokenCoverage(raw, show.Trace.Harness.Name)
- return data, true, nil
+ return data
}
// fitLensEvents keeps the longest prefix of the bundle's events that encodes within budget, and
diff --git a/cli/beacon/internal/endpoint/dashboard/lens_data_test.go b/cli/beacon/internal/endpoint/dashboard/lens_data_test.go
index 8d03a114..27d7165f 100644
--- a/cli/beacon/internal/endpoint/dashboard/lens_data_test.go
+++ b/cli/beacon/internal/endpoint/dashboard/lens_data_test.go
@@ -255,3 +255,91 @@ func TestLensDataForARotatedTraceIsNotScanned(t *testing.T) {
t.Fatalf("token coverage = %#v, want nil", data.TokenCoverage)
}
}
+
+// A session whose hook events and OTLP spans project to different traces is still one session on
+// the dashboard, and its lens must see every event the session page lists.
+func TestBuildSessionLensDataCoversEveryEventOfTheSession(t *testing.T) {
+ testenv.SetHome(t, t.TempDir())
+ withoutHistory(t)
+ hook := testSchemaEvent("2026-06-11T10:00:00Z", "codex_cli", "command.executed", "command", "repo-a")
+ hook.Event.ID = "evt-hook"
+ hook.Session = &schema.SessionInfo{ID: "codex-1"}
+ hook.Command = &schema.CommandInfo{Command: "rm -rf /"}
+ span := testSchemaEvent("2026-06-11T10:00:05Z", "codex_cli", "tool.invoked", "tool", "repo-a")
+ span.Event.ID = "evt-span"
+ span.Session = hook.Session
+ span.Trace = &schema.TraceInfo{ID: "otel-trace", SpanID: "span-1"}
+ other := testSchemaEvent("2026-06-11T10:00:06Z", "codex_cli", "command.executed", "command", "repo-a")
+ other.Event.ID = "evt-other"
+ other.Session = &schema.SessionInfo{ID: "codex-10"} // shares a prefix; must not match
+ path := newTestLog(t, marshalEvents(t, hook, span, other))
+
+ data, ok, err := BuildSessionLensData(path, "codex-1", LensDataOptions{UserMode: true})
+ if err != nil || !ok {
+ t.Fatalf("BuildSessionLensData = ok %v, err %v", ok, err)
+ }
+ var ids []string
+ for _, event := range data.Trace.Events {
+ ids = append(ids, event.ID)
+ }
+ if strings.Join(ids, ",") != "evt-hook,evt-span" {
+ t.Fatalf("session bundle events = %v, want the hook event and the span", ids)
+ }
+ if data.Trace.ID != "session:codex_cli:codex-1" || data.Trace.Summary.EventCount != 2 {
+ t.Fatalf("bundle = %s with %d events", data.Trace.ID, data.Trace.Summary.EventCount)
+ }
+ if data.Trace.Range == nil || data.Trace.Range.TotalEvents != 2 || data.Trace.Range.ReturnedEvents != 2 {
+ t.Fatalf("range = %#v", data.Trace.Range)
+ }
+ if data.Findings == nil || len(data.Findings.Items) == 0 {
+ t.Fatal("session lens data should carry the rm -rf finding")
+ }
+ for _, f := range data.Findings.Items {
+ for _, id := range f.EventIDs {
+ if id == "evt-other" {
+ t.Fatal("a finding from another session leaked in")
+ }
+ }
+ }
+
+ // The trace projection of the same session holds only the hook event; that is why the session
+ // page asks by session.
+ byTrace, ok, err := BuildLensData(path, "session:codex_cli:codex-1", LensDataOptions{UserMode: true})
+ if err != nil || !ok || len(byTrace.Trace.Events) != 1 {
+ t.Fatalf("trace-scoped lens data = %d events, ok %v, err %v", len(byTrace.Trace.Events), ok, err)
+ }
+
+ if _, ok, err := BuildSessionLensData(path, "codex", LensDataOptions{UserMode: true}); ok || err != nil {
+ t.Fatalf("a session-id prefix matched: ok %v, err %v", ok, err)
+ }
+}
+
+func TestLensDataEndpointBySession(t *testing.T) {
+ path := lensFixture(t)
+ handler, err := Handler(Options{UserMode: true, LogPath: path})
+ if err != nil {
+ t.Fatal(err)
+ }
+ get := func(url string) *httptest.ResponseRecorder {
+ rec := httptest.NewRecorder()
+ handler.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, url, nil))
+ return rec
+ }
+ rec := get("/api/lens-data?session=s1")
+ if rec.Code != http.StatusOK {
+ t.Fatalf("status = %d, body = %s", rec.Code, rec.Body.String())
+ }
+ var data asymptoteobserve.LensDataV1
+ if err := json.Unmarshal(rec.Body.Bytes(), &data); err != nil {
+ t.Fatal(err)
+ }
+ if data.Trace.ID != "session:claude_code:s1" || len(data.Trace.Events) != 2 {
+ t.Fatalf("trace = %s with %d events", data.Trace.ID, len(data.Trace.Events))
+ }
+ if rec := get("/api/lens-data?session=s1&trace=session:claude_code:s1"); rec.Code != http.StatusBadRequest {
+ t.Fatalf("both params status = %d, want 400", rec.Code)
+ }
+ if rec := get("/api/lens-data?session=nope"); rec.Code != http.StatusNotFound {
+ t.Fatalf("unknown session status = %d, want 404", rec.Code)
+ }
+}
diff --git a/cli/beacon/internal/endpoint/dashboard/server.go b/cli/beacon/internal/endpoint/dashboard/server.go
index 9717eb9c..945bcdd4 100644
--- a/cli/beacon/internal/endpoint/dashboard/server.go
+++ b/cli/beacon/internal/endpoint/dashboard/server.go
@@ -252,12 +252,24 @@ func Handler(opts Options) (http.Handler, error) {
methodNotAllowed(w)
return
}
- id := r.URL.Query().Get("trace")
- if strings.TrimSpace(id) == "" {
- writeError(w, http.StatusBadRequest, fmt.Errorf("trace id is required"))
- return
+ // The session page asks by session (the events it lists); other callers ask by trace.
+ trace := strings.TrimSpace(r.URL.Query().Get("trace"))
+ session := strings.TrimSpace(r.URL.Query().Get("session"))
+ if (trace == "") == (session == "") {
+ writeError(w, http.StatusBadRequest, fmt.Errorf("exactly one of trace or session is required"))
+ return
+ }
+ lensOpts := LensDataOptions{UserMode: rulesUserMode}
+ var (
+ data LensDataV1
+ ok bool
+ err error
+ )
+ if trace != "" {
+ data, ok, err = BuildLensData(opts.LogPath, trace, lensOpts)
+ } else {
+ data, ok, err = BuildSessionLensData(opts.LogPath, session, lensOpts)
}
- data, ok, err := BuildLensData(opts.LogPath, id, LensDataOptions{UserMode: rulesUserMode})
if err != nil {
writeError(w, http.StatusInternalServerError, err)
return
diff --git a/cli/beacon/internal/endpoint/dashboard/static/app.js b/cli/beacon/internal/endpoint/dashboard/static/app.js
index db60c83b..79d31ae9 100644
--- a/cli/beacon/internal/endpoint/dashboard/static/app.js
+++ b/cli/beacon/internal/endpoint/dashboard/static/app.js
@@ -3327,6 +3327,286 @@ $$("[data-preset]").forEach((button) => {
button.addEventListener("click", () => applyPreset(button.dataset.preset));
});
+// Lens tabs on the session page. Each lens runs in a sandboxed frame served by /lenses/frame/<id>
+// (see spec/lenses/SPEC.md). This is the host half of the protocol: it hands the frame one
+// MessagePort and answers getTrace over it with /api/lens-data. The frame never reaches the
+// dashboard any other way, and a lens that fails or stalls before it renders gives way to the full
+// session view.
+const lensAddedStorageKey = "beacon.dashboard.lenses";
+const lensRenderTimeoutMs = 10000;
+// After the data is delivered, a lens that throws within this window is treated as having failed
+// to render rather than as a lens with a late bug.
+const lensSettleMs = 1000;
+const lensMaxFrameHeight = 200000;
+
+const lensHost = {
+ session: "",
+ lenses: [],
+ added: [],
+ active: "",
+ mount: null,
+ dataPromise: null,
+};
+
+function readAddedLenses() {
+ try {
+ const value = JSON.parse(localStorage.getItem(lensAddedStorageKey) || "[]");
+ return Array.isArray(value) ? value.filter((id) => typeof id === "string") : [];
+ } catch (_) {
+ return [];
+ }
+}
+
+function writeAddedLenses(ids) {
+ try {
+ localStorage.setItem(lensAddedStorageKey, JSON.stringify(ids));
+ } catch (_) {
+ // Remembering tabs is a convenience; a browser without storage still works.
+ }
+}
+
+function lensByID(id) {
+ return lensHost.lenses.find((lens) => lens.id === id);
+}
+
+async function initLensTabs() {
+ const params = new URLSearchParams(window.location.search);
+ lensHost.session = (params.get("id") || "").trim();
+ if (!lensHost.session || !$("#lens-tabs")) return;
+ try {
+ lensHost.lenses = (await getJSON("/api/lenses")).lenses || [];
+ } catch (err) {
+ console.warn("lenses unavailable", err);
+ lensHost.lenses = [];
+ }
+ lensHost.added = readAddedLenses().filter((id) => lensByID(id));
+ const wanted = (params.get("lens") || "").trim();
+ if (wanted && lensByID(wanted) && !lensHost.added.includes(wanted)) {
+ lensHost.added.push(wanted);
+ writeAddedLenses(lensHost.added);
+ }
+
+ const addButton = $("#lens-add-button");
+ addButton.addEventListener("click", (event) => {
+ event.stopPropagation();
+ toggleLensMenu();
+ });
+ document.addEventListener("click", (event) => {
+ if (!event.target.closest(".lens-add")) toggleLensMenu(false);
+ });
+ document.addEventListener("keydown", (event) => {
+ if (event.key === "Escape") toggleLensMenu(false);
+ });
+ window.addEventListener("popstate", () => {
+ const id = new URLSearchParams(window.location.search).get("lens") || "";
+ selectLens(lensByID(id) ? id : "", { history: false });
+ });
+
+ renderLensTabs();
+ selectLens(lensByID(wanted) ? wanted : "", { history: false });
+}
+
+function renderLensTabs() {
+ const tabs = $("#lens-tabs");
+ tabs.replaceChildren();
+ const tab = (id, title) => {
+ const button = document.createElement("button");
+ button.type = "button";
+ button.className = "lens-tab";
+ button.setAttribute("role", "tab");
+ button.setAttribute("aria-selected", String(lensHost.active === id));
+ button.dataset.lens = id;
+ button.addEventListener("click", () => selectLens(id));
+ const label = document.createElement("span");
+ label.textContent = title;
+ button.append(label);
+ return button;
+ };
+ tabs.append(tab("", "Full session"));
+ for (const id of lensHost.added) {
+ const lens = lensByID(id);
+ const button = tab(id, lens.title);
+ const remove = document.createElement("span");
+ remove.className = "lens-tab-remove";
+ remove.setAttribute("role", "button");
+ remove.setAttribute("aria-label", `Remove the ${lens.title} lens`);
+ remove.textContent = "×";
+ remove.addEventListener("click", (event) => {
+ event.stopPropagation();
+ removeLens(id);
+ });
+ button.append(remove);
+ tabs.append(button);
+ }
+ renderLensMenu();
+}
+
+function renderLensMenu() {
+ const menu = $("#lens-menu");
+ menu.replaceChildren();
+ const available = lensHost.lenses.filter((lens) => !lensHost.added.includes(lens.id));
+ if (available.length === 0) {
+ const empty = document.createElement("span");
+ empty.className = "lens-menu-empty";
+ empty.textContent = lensHost.lenses.length ? "Every lens is already open." : "No lenses are installed.";
+ menu.append(empty);
+ return;
+ }
+ for (const lens of available) {
+ const item = document.createElement("button");
+ item.type = "button";
+ item.className = "lens-menu-item";
+ item.setAttribute("role", "menuitem");
+ const title = document.createElement("span");
+ title.className = "lens-menu-title";
+ title.textContent = lens.title;
+ item.append(title);
+ if (lens.description) {
+ const description = document.createElement("span");
+ description.className = "lens-menu-description";
+ description.textContent = lens.description;
+ item.append(description);
+ }
+ item.addEventListener("click", () => {
+ lensHost.added.push(lens.id);
+ writeAddedLenses(lensHost.added);
+ toggleLensMenu(false);
+ selectLens(lens.id);
+ });
+ menu.append(item);
+ }
+}
+
+function toggleLensMenu(open) {
+ const menu = $("#lens-menu");
+ const button = $("#lens-add-button");
+ if (!menu || !button) return;
+ const show = open === undefined ? menu.hidden : open;
+ menu.hidden = !show;
+ button.setAttribute("aria-expanded", String(show));
+}
+
+function removeLens(id) {
+ lensHost.added = lensHost.added.filter((added) => added !== id);
+ writeAddedLenses(lensHost.added);
+ if (lensHost.active === id) {
+ selectLens("");
+ } else {
+ renderLensTabs();
+ }
+}
+
+function selectLens(id, { history = true } = {}) {
+ lensHost.active = id;
+ if (history) {
+ const params = new URLSearchParams(window.location.search);
+ if (id) params.set("lens", id);
+ else params.delete("lens");
+ window.history.pushState(null, "", `${window.location.pathname}?${params}`);
+ }
+ if (id) $("#lens-notice").hidden = true;
+ $("#session-detail-view").dataset.view = id ? "lens" : "full";
+ $("#lens-view").hidden = !id;
+ renderLensTabs();
+ if (id) mountLens(lensByID(id));
+ else unmountLens();
+}
+
+function lensData() {
+ if (!lensHost.dataPromise) {
+ lensHost.dataPromise = getJSON(`/api/lens-data?session=${encodeURIComponent(lensHost.session)}`);
+ // A failed load is not cached, so reopening the lens tries again.
+ lensHost.dataPromise.catch(() => {
+ lensHost.dataPromise = null;
+ });
+ }
+ return lensHost.dataPromise;
+}
+
+function unmountLens() {
+ const mount = lensHost.mount;
+ if (!mount) return;
+ lensHost.mount = null;
+ clearTimeout(mount.timer);
+ clearTimeout(mount.settleTimer);
+ if (mount.port) mount.port.close();
+ mount.frame.remove();
+}
+
+function mountLens(lens) {
+ unmountLens();
+ const status = $("#lens-status");
+ status.hidden = false;
+ status.textContent = `Loading ${lens.title}...`;
+
+ const frame = document.createElement("iframe");
+ frame.className = "lens-frame";
+ frame.setAttribute("sandbox", "allow-scripts");
+ frame.referrerPolicy = "no-referrer";
+ frame.title = `${lens.title} lens`;
+ frame.src = `/lenses/frame/${encodeURIComponent(lens.id)}`;
+
+ const mount = { lens, frame, port: null, loads: 0, delivered: false, rendered: false, timer: 0, settleTimer: 0 };
+ lensHost.mount = mount;
+ const fail = (reason) => {
+ if (lensHost.mount !== mount) return;
+ const notice = $("#lens-notice");
+ selectLens("", { history: false });
+ const params = new URLSearchParams(window.location.search);
+ params.delete("lens");
+ window.history.replaceState(null, "", `${window.location.pathname}?${params}`);
+ notice.textContent = `The ${lens.title} lens could not be shown (${reason}). Showing the full session instead.`;
+ notice.hidden = false;
+ };
+ const rendered = () => {
+ if (lensHost.mount !== mount || mount.rendered) return;
+ mount.rendered = true;
+ clearTimeout(mount.timer);
+ status.hidden = true;
+ };
+ mount.timer = setTimeout(() => fail("it did not render within 10 seconds"), lensRenderTimeoutMs);
+
+ frame.addEventListener("load", () => {
+ mount.loads += 1;
+ if (mount.loads > 1) {
+ // The lens navigated its own frame. Whatever loaded now is not the lens that was vetted,
+ // so it gets no port and the lens is closed.
+ fail("it navigated away from itself");
+ return;
+ }
+ const channel = new MessageChannel();
+ mount.port = channel.port1;
+ mount.port.onmessage = (event) => {
+ if (lensHost.mount !== mount) return;
+ const message = event.data;
+ if (!message || typeof message !== "object") return;
+ if (message.type === "getTrace") {
+ lensData().then(
+ (data) => mount.port.postMessage({ type: "trace", data }),
+ (err) => mount.port.postMessage({ type: "traceError", message: String(err.message || err) }),
+ ).finally(() => {
+ mount.delivered = true;
+ mount.settleTimer = setTimeout(rendered, lensSettleMs);
+ });
+ } else if (message.type === "resize") {
+ const height = Number(message.height);
+ if (Number.isFinite(height)) {
+ frame.style.height = `${Math.min(Math.max(height, 0), lensMaxFrameHeight)}px`;
+ }
+ if (mount.delivered && height > 0) rendered();
+ } else if (message.type === "error") {
+ const reason = String(message.message || "error").slice(0, 200);
+ if (mount.rendered) console.warn(`lens ${lens.id}: ${reason}`);
+ else fail(`it raised an error: ${reason}`);
+ }
+ };
+ // The frame's origin is opaque, so "*" is the only target that reaches it. The message carries
+ // the port and nothing else; the trace only ever crosses the port.
+ frame.contentWindow.postMessage({ type: "beacon.lens.connect", version: 1 }, "*", [channel.port2]);
+ });
+ $("#lens-frame-slot").append(frame);
+}
+
if (isDetectionsPage) {
loadDetections().catch(console.error);
setInterval(() => loadDetections().catch(console.error), 15000);
@@ -3337,6 +3617,7 @@ if (isDetectionsPage) {
loadTokens().catch(console.error);
setInterval(() => loadTokens().catch(console.error), 15000);
} else if (isSessionDetailPage) {
+ initLensTabs().catch(console.error);
loadSessionPage().catch(console.error);
setInterval(() => loadSessionPage().catch(console.error), 15000);
} else if (isInventoryPage) {
diff --git a/cli/beacon/internal/endpoint/dashboard/static/session.html b/cli/beacon/internal/endpoint/dashboard/static/session.html
index b1175ebb..e1e54eb1 100644
--- a/cli/beacon/internal/endpoint/dashboard/static/session.html
+++ b/cli/beacon/internal/endpoint/dashboard/static/session.html
@@ -49,6 +49,19 @@
Back to agent activity
</a>
+ <div class="lens-bar">
+ <div id="lens-tabs" class="lens-tabs" role="tablist" aria-label="Session views"></div>
+ <div class="lens-add">
+ <button type="button" id="lens-add-button" class="lens-add-button" aria-haspopup="menu" aria-expanded="false" aria-controls="lens-menu" title="Add a lens">+</button>
+ <div id="lens-menu" class="lens-menu" role="menu" hidden></div>
+ </div>
+ </div>
+ <div id="lens-notice" class="notice lens-notice" role="status" hidden></div>
+ <section id="lens-view" class="lens-view" role="tabpanel" hidden>
+ <p id="lens-status" class="muted lens-status">Loading lens...</p>
+ <div id="lens-frame-slot"></div>
+ </section>
+
<section class="session-overview-panel">
<div class="session-overview-head">
<h2 id="session-page-title">Session Events</h2>
diff --git a/cli/beacon/internal/endpoint/dashboard/static/styles.css b/cli/beacon/internal/endpoint/dashboard/static/styles.css
index 52133f42..49dba7e1 100644
--- a/cli/beacon/internal/endpoint/dashboard/static/styles.css
+++ b/cli/beacon/internal/endpoint/dashboard/static/styles.css
@@ -3439,3 +3439,158 @@ pre {
justify-content: center;
}
}
+
+/* Lens tabs on the session page. A lens replaces the full-session panels while it is selected. */
+.session-detail-main[data-view="lens"] .session-overview-panel,
+.session-detail-main[data-view="lens"] .session-activity-panel,
+.session-detail-main[data-view="lens"] .session-events-panel {
+ display: none;
+}
+
+.lens-bar {
+ display: flex;
+ align-items: center;
+ gap: 0.4rem;
+ flex-wrap: wrap;
+}
+
+.lens-tabs {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 0.4rem;
+}
+
+.lens-tab,
+.lens-add-button {
+ min-height: 1.75rem;
+ border-color: transparent;
+ border-radius: 999px;
+ background: #f3f4f6;
+ color: #303742;
+ font-size: 0.72rem;
+ font-weight: 650;
+ padding: 0.3rem 0.75rem;
+ box-shadow: none;
+}
+
+.lens-tab {
+ display: inline-flex;
+ align-items: center;
+ gap: 0.35rem;
+}
+
+.lens-tab:hover,
+.lens-add-button:hover {
+ background: #e9eef2;
+}
+
+.lens-tab[aria-selected="true"] {
+ border-color: #94c9dd;
+ background: #dff2fa;
+ color: #075f85;
+}
+
+.lens-tab-remove {
+ border: 0;
+ padding: 0 0.15rem;
+ background: none;
+ color: inherit;
+ font-size: 0.85rem;
+ line-height: 1;
+ opacity: 0.6;
+}
+
+.lens-tab-remove:hover {
+ opacity: 1;
+}
+
+.lens-add {
+ position: relative;
+}
+
+.lens-add-button {
+ width: 1.9rem;
+ padding: 0;
+}
+
+.lens-menu {
+ position: absolute;
+ z-index: 20;
+ top: calc(100% + 0.35rem);
+ left: 0;
+ min-width: 16rem;
+ max-width: 22rem;
+ border: 1px solid var(--line);
+ border-radius: var(--radius);
+ background: var(--panel);
+ box-shadow: var(--shadow-md);
+ padding: 0.3rem;
+}
+
+.lens-menu[hidden] {
+ display: none;
+}
+
+.lens-menu-item {
+ display: block;
+ width: 100%;
+ border: 0;
+ border-radius: 0.45rem;
+ background: none;
+ padding: 0.5rem 0.6rem;
+ text-align: left;
+}
+
+.lens-menu-item:hover,
+.lens-menu-item:focus-visible {
+ background: var(--panel-soft);
+}
+
+.lens-menu-title {
+ display: block;
+ font-size: 0.78rem;
+ font-weight: 650;
+}
+
+.lens-menu-description,
+.lens-menu-empty {
+ display: block;
+ color: var(--muted);
+ font-size: 0.72rem;
+}
+
+.lens-menu-empty {
+ padding: 0.5rem 0.6rem;
+}
+
+.lens-notice {
+ margin-bottom: 0;
+ font-size: 0.78rem;
+}
+
+.lens-view {
+ border: 1px solid rgba(17, 24, 39, 0.12);
+ border-radius: 13px;
+ background: rgba(255, 255, 255, 0.98);
+ padding: 1rem 1.25rem;
+}
+
+.lens-view[hidden],
+.lens-notice[hidden],
+.lens-status[hidden] {
+ display: none;
+}
+
+.lens-status {
+ margin: 0;
+ font-size: 0.78rem;
+}
+
+.lens-frame {
+ display: block;
+ width: 100%;
+ height: 0;
+ border: 0;
+ background: transparent;
+}
+