mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-25 16:14:26 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Hosted Paperclip Cloud records browser sessions with PostHog session replay > - Replay masked all text and showed only an allowlist of chrome, so most replays showed only stars > - The team cannot see how people use the board, and the allowlist needed a review for each new label > - The owner decided to show text by default and mask only marked customer content, the way PostHog normally works > - This pull request flips the default, removes the allowlist, and marks every surface that can show connected-account content > - The benefit is readable replays, while Google user data and Slack data stay masked ## Linked Issues or Issue Description **Subsystem affected** Hosted Cloud browser analytics: PostHog session replay in the board UI (`ui/src/lib/analytics/`). **Problem or motivation** Replay masked every text node. Only sidebar items and opt-in components showed text. Replays were almost unreadable. Each new label needed an `analyticsChrome` opt-in and an allowlist review. **Proposed solution** Record text as it is. Mask text only inside `ph-mask` (customer content), `ph-no-capture` (secrets, blocked) and editable content. Add `ANALYTICS_MASK_CLASS` to every surface that can show connected-account content (Gmail, Calendar, Drive and Docs, Slack) or other free-form text from agents or customers. **Alternatives considered** Keep "mask all" and grow the allowlist. This needs a review for each label and still hides most of the board. ## What Changed - `privacy.ts`: `ANALYTICS_MASK_TEXT_SELECTOR` is now `.ph-mask, .ph-no-capture, [contenteditable]:not([contenteditable="false"])`. rrweb masks a text node only when its parent or an ancestor matches the selector. Removed `maskReplayText`, `isReplayTextRevealed`, `ANALYTICS_UNMASK_ATTRIBUTE` and `ANALYTICS_UNMASK_PROPS`. - `product-analytics.ts`: removed `maskTextFn`, so rrweb uses its default star masking. `maskAllInputs`, `blockClass`, `maskAttributeFn`, `mask_all_text` and `mask_all_element_attributes` do not change. - Removed the `analyticsChrome` prop from `Button`, `Label`, `TabsTrigger`, `EmptyState` and `SidebarNavItem`, and from all sidebar call sites. - Added `ANALYTICS_MASK_CLASS` to the content element (not the chrome) of these surfaces: - Link preview cards, task quicklook description, external object pills and rows, related-work titles. - Email message cards and email send intents. - Connected account names and email addresses (Browse, Connections, app detail headers, app sidebar, connection choice list, connection access and repair cards), GitHub login and repositories, Slack workspace names, chat channel and linked user labels. - Inbox and decision rows (subject and detail), obligation evidence, Needs You notes and receipts, decision options and result summaries, and the interaction card roots (questions, options, answers, tool action requests, suggested tasks). - Approval payloads, action card input and reason, recovery card headline, evidence and options, run ledger retry detail, interrupt handoff previews. - Run transcripts, run failure details and run events on the agent page. - Search result snippets, toast bodies, voice and call transcripts, case summary, files and fields, attachment previews, artifact previews (text, tables, patches and documents). - Replaced `unmask-allowlist.test.ts` with `replay-masking.test.tsx`. It checks that unmarked chrome records as it is, that each marker masks, that a rendered voice transcript and run transcript mask, that each surface above has the class, and that autocapture records no element text. Updated `privacy.test.ts`, `shared-chrome.test.tsx` and `product-analytics.test.ts`. - Updated `doc/cloud-browser-analytics.md`: new default, marker classes, masked surfaces, and residual risk. ## Verification - `pnpm exec vitest run src/lib/analytics` in `ui/`: 83 tests pass. - Vitest for the 48 test files next to the changed components: 994 tests pass. - `tsc --noEmit -p ui/tsconfig.json`: no new errors (only the existing generated Storybook catalog errors). - `pnpm verify` exits 2 because a doc is a global CI input. Required CI supplies the broad coverage. - Manual: I ran an isolated local instance with a Cloud-like browser analytics config. `PAPERCLIP_POSTHOG_HOST` pointed to a local capture server, not PostHog. I opened a task page in headless Chromium, hovered a GitHub pull request link, and decoded the captured `/s/` replay payloads: - Clear text: sidebar (`New task`, `Chat`, `Tasks`, `Inbox`, `More`), breadcrumb, task title `Quarterly launch checklist`, `REP-1`, the Connectors promo heading and button. - Masked (stars only): the markdown task body, the chat comment, the link preview card (pull request title, author, URL, status), and the company menu. - Marker strings in the body, comment and preview never appeared in clear text in any payload. - The page `<title>` (task title and company name) is in the replay head. This is accepted residual risk. ## Risks - Text that is not marked is now recorded. Task titles, agent names, project names, company names, routine names, artifact and document titles, and activity rows are visible in replays. The owner accepted this. An agent can copy email or Slack text into a task title. - A new surface that shows connected-account content without `ANALYTICS_MASK_CLASS` is recorded until somebody marks it. `replay-masking.test.tsx` and the doc list the marked surfaces. - The masking options in `posthog.init` take precedence over the PostHog project masking settings (posthog-js 1.450), so a dashboard change cannot unmask content. Keep the project settings empty to avoid a console warning. - Some masked areas also mask nearby fixed labels (for example the interaction card buttons). This is safe. - Analytics is off on self-hosted and local installs, so they see no change. > For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and discuss it in `#dev` before opening the PR. Feature PRs that overlap with planned core work may need to be redirected — check the roadmap first. See `CONTRIBUTING.md`. ## Model Used - Claude Opus 5.5 (claude-opus-5-5), Anthropic, with tool use and code execution in Claude Code. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1245 lines
63 KiB
TypeScript
1245 lines
63 KiB
TypeScript
import {
|
||
useCallback,
|
||
useEffect,
|
||
useLayoutEffect,
|
||
useMemo,
|
||
useRef,
|
||
useState,
|
||
} from "react";
|
||
import type {
|
||
HeartbeatRunEvent,
|
||
ProviderTraceFieldMapping,
|
||
ProviderTraceFrame,
|
||
} from "@paperclipai/shared";
|
||
import {
|
||
ArrowRight,
|
||
Braces,
|
||
Check,
|
||
ChevronDown,
|
||
ChevronRight,
|
||
CircleOff,
|
||
Copy,
|
||
Download,
|
||
Eye,
|
||
EyeOff,
|
||
FileJson2,
|
||
Layers3,
|
||
RefreshCw,
|
||
Search,
|
||
ShieldAlert,
|
||
Trash2,
|
||
} from "lucide-react";
|
||
import { heartbeatsApi, type ProviderTraceInspection } from "@/api/heartbeats";
|
||
import { accessApi } from "@/api/access";
|
||
import { QueryErrorState } from "@/components/QueryView";
|
||
import { useResilientFetch } from "@/hooks/useResilientFetch";
|
||
import { parsePaperclipRunnerStdoutLine } from "@/adapters/paperclip-runner";
|
||
import { TaskChatProtocolCard } from "@/components/task-chat/TaskChatProtocolCard";
|
||
import type { TaskChatProtocolItem } from "@/components/task-chat/task-chat-model";
|
||
import { transcriptToTaskChatItems } from "@/components/task-chat/transcript-adapter";
|
||
import { TASK_PROTOCOL_EVENT_SURFACE_REGISTRY } from "@/components/task-chat/task-protocol-surfaces";
|
||
import { Badge } from "@/components/ui/badge";
|
||
import { Button } from "@/components/ui/button";
|
||
import { Input } from "@/components/ui/input";
|
||
import { ScrollArea } from "@/components/ui/scroll-area";
|
||
import {
|
||
Select,
|
||
SelectContent,
|
||
SelectItem,
|
||
SelectTrigger,
|
||
SelectValue,
|
||
} from "@/components/ui/select";
|
||
import {
|
||
Sheet,
|
||
SheetContent,
|
||
SheetDescription,
|
||
SheetHeader,
|
||
SheetTitle,
|
||
} from "@/components/ui/sheet";
|
||
import { cn } from "@/lib/utils";
|
||
import { ANALYTICS_MASK_CLASS, ANALYTICS_NO_CAPTURE_CLASS } from "@/lib/analytics/privacy";
|
||
import { useCopyAction } from "@/lib/use-copy-action";
|
||
|
||
type TraceEntry = Record<string, unknown>;
|
||
type InspectorView = "overview" | "pipeline" | "trace";
|
||
|
||
type RawTraceAccess = {
|
||
runId: string;
|
||
allowed: boolean;
|
||
epoch: number;
|
||
phase: "granted" | "denied" | "deleting";
|
||
};
|
||
|
||
type TraceOperation = {
|
||
key: string;
|
||
frames: TraceEntry[];
|
||
interpretations: TraceEntry[];
|
||
events: HeartbeatRunEvent[];
|
||
title: string;
|
||
subtitle: string;
|
||
itemType: string;
|
||
nativeMethods: string[];
|
||
directions: string[];
|
||
dispositions: string[];
|
||
prpTypes: string[];
|
||
visible: boolean;
|
||
timestamp: number;
|
||
};
|
||
|
||
const VIEW_OPTIONS: Array<{
|
||
value: InspectorView;
|
||
label: string;
|
||
icon: typeof Layers3;
|
||
}> = [
|
||
{ value: "overview", label: "Overview", icon: Layers3 },
|
||
{ value: "pipeline", label: "Pipeline", icon: ArrowRight },
|
||
{ value: "trace", label: "Exact trace", icon: FileJson2 },
|
||
];
|
||
|
||
const RAW_TRACE_ACCESS_REVALIDATION_MS = 1_000;
|
||
|
||
function record(value: unknown): Record<string, unknown> {
|
||
return value && typeof value === "object" && !Array.isArray(value)
|
||
? (value as Record<string, unknown>)
|
||
: {};
|
||
}
|
||
|
||
function text(value: unknown): string {
|
||
return typeof value === "string" ? value : "";
|
||
}
|
||
|
||
function revealedFrameKey(runId: string, frameId: number): string {
|
||
return `${runId}:${frameId}`;
|
||
}
|
||
|
||
function scalar(value: unknown): string {
|
||
if (typeof value === "string") return value;
|
||
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
||
return "";
|
||
}
|
||
|
||
function unique(values: string[]) {
|
||
return [...new Set(values.filter(Boolean))];
|
||
}
|
||
|
||
function formatBytes(value: number) {
|
||
if (value < 1_024) return `${value} B`;
|
||
if (value < 1_024 * 1_024) return `${(value / 1_024).toFixed(1)} KiB`;
|
||
return `${(value / (1_024 * 1_024)).toFixed(1)} MiB`;
|
||
}
|
||
|
||
function downloadBlob(blob: Blob, filename: string) {
|
||
const href = URL.createObjectURL(blob);
|
||
const anchor = document.createElement("a");
|
||
anchor.href = href;
|
||
anchor.download = filename;
|
||
anchor.click();
|
||
URL.revokeObjectURL(href);
|
||
}
|
||
|
||
function decodeExactFrame(rawBase64: string): unknown {
|
||
const decoded = atob(rawBase64);
|
||
try {
|
||
return JSON.parse(decoded);
|
||
} catch {
|
||
return decoded;
|
||
}
|
||
}
|
||
|
||
function statusVariant(status: string | undefined) {
|
||
if (status === "complete") return "secondary" as const;
|
||
if (status === "incomplete" || status === "truncated")
|
||
return "destructive" as const;
|
||
return "outline" as const;
|
||
}
|
||
|
||
function traceBadgeLabel(status: string, expiresAt: string | Date) {
|
||
if (status === "capturing") return "Raw trace enabled";
|
||
if (status === "incomplete") return "Incomplete";
|
||
if (status === "truncated") return "Truncated";
|
||
if (status === "deleted") return "Deleted";
|
||
if (status === "expired") return "Expired";
|
||
const remainingMs = new Date(expiresAt).getTime() - Date.now();
|
||
if (!Number.isFinite(remainingMs) || remainingMs <= 0) return "Expired";
|
||
const hours = Math.max(1, Math.ceil(remainingMs / (60 * 60 * 1_000)));
|
||
return `Expires in ${hours}h`;
|
||
}
|
||
|
||
function frameParsed(entry: TraceEntry) {
|
||
return record(entry.parsed);
|
||
}
|
||
|
||
function frameMethod(entry: TraceEntry) {
|
||
const parsed = frameParsed(entry);
|
||
return text(parsed.method) || text(record(parsed.params).method);
|
||
}
|
||
|
||
function frameItem(entry: TraceEntry) {
|
||
const parsed = frameParsed(entry);
|
||
const params = record(parsed.params);
|
||
return record(params.item ?? parsed.item);
|
||
}
|
||
|
||
function frameItemType(entry: TraceEntry) {
|
||
const parsed = frameParsed(entry);
|
||
const params = record(parsed.params);
|
||
return text(frameItem(entry).type) || text(params.itemType) || text(parsed.type);
|
||
}
|
||
|
||
function eventPrp(event: HeartbeatRunEvent) {
|
||
const payload = record(event.payload);
|
||
const prpEvent = record(payload.prpEvent);
|
||
return Object.keys(prpEvent).length > 0 ? prpEvent : payload;
|
||
}
|
||
|
||
function eventSourceId(event: HeartbeatRunEvent) {
|
||
return text(eventPrp(event).sourceEventId);
|
||
}
|
||
|
||
function eventTimestamp(event: HeartbeatRunEvent) {
|
||
const value = new Date(event.createdAt).getTime();
|
||
return Number.isFinite(value) ? value : Number.MAX_SAFE_INTEGER;
|
||
}
|
||
|
||
function frameTimestamp(frame: TraceEntry) {
|
||
const raw = scalar(frame.timestamp);
|
||
const numeric = Number(raw);
|
||
if (Number.isFinite(numeric)) {
|
||
return numeric < 10_000_000_000 ? numeric * 1_000 : numeric;
|
||
}
|
||
const parsed = Date.parse(raw);
|
||
return Number.isFinite(parsed) ? parsed : Number.MAX_SAFE_INTEGER;
|
||
}
|
||
|
||
function visibilityDecision(event: HeartbeatRunEvent) {
|
||
const registration = TASK_PROTOCOL_EVENT_SURFACE_REGISTRY[event.eventType];
|
||
if (!registration) {
|
||
return {
|
||
visible: false,
|
||
surface: "run_debug",
|
||
container: "Runner Inspector",
|
||
state: "hidden",
|
||
action: "none",
|
||
reasonCode: "presentation_surface_unregistered",
|
||
reason: "No production surface registration exists for this event type.",
|
||
};
|
||
}
|
||
return {
|
||
visible: registration.disposition !== "debug-only",
|
||
surface: registration.surface,
|
||
container:
|
||
registration.disposition === "inline"
|
||
? "primary run turn"
|
||
: "collapsed activity",
|
||
state: registration.disposition,
|
||
action:
|
||
registration.disposition === "inline"
|
||
? "render"
|
||
: registration.disposition === "folded"
|
||
? "fold"
|
||
: "operator only",
|
||
reasonCode: `presentation_${registration.disposition}`,
|
||
reason: registration.rationale,
|
||
};
|
||
}
|
||
|
||
function interpretationEventIds(entry: TraceEntry) {
|
||
return Array.isArray(entry.emittedEventIds)
|
||
? entry.emittedEventIds.map(String)
|
||
: [];
|
||
}
|
||
|
||
function frameCorrelationTokens(frame: TraceEntry, interpretations: TraceEntry[]) {
|
||
const parsed = frameParsed(frame);
|
||
const params = record(parsed.params);
|
||
const item = frameItem(frame);
|
||
const tokens = interpretations.flatMap(interpretationEventIds).map((id) => `event:${id}`);
|
||
const rpcId = scalar(parsed.id);
|
||
if (rpcId) {
|
||
const direction = text(frame.direction);
|
||
const isRequest = Boolean(frameMethod(frame));
|
||
const requestOrigin = isRequest
|
||
? direction === "client_to_provider" ? "client" : "provider"
|
||
: direction === "client_to_provider" ? "provider" : "client";
|
||
tokens.push(`rpc:${requestOrigin}:${rpcId}`);
|
||
}
|
||
for (const id of [item.id, params.itemId, params.callId, parsed.itemId]) {
|
||
const value = scalar(id);
|
||
if (value) tokens.push(`item:${value}`);
|
||
}
|
||
return unique(tokens);
|
||
}
|
||
|
||
function buildOperations(
|
||
frames: TraceEntry[],
|
||
interpretations: TraceEntry[],
|
||
events: HeartbeatRunEvent[],
|
||
): TraceOperation[] {
|
||
const sortedFrames = [...frames].sort(
|
||
(left, right) => Number(left.frameId) - Number(right.frameId),
|
||
);
|
||
const frameById = new Map(sortedFrames.map((frame) => [Number(frame.frameId), frame]));
|
||
const parent = new Map([...frameById.keys()].map((id) => [id, id]));
|
||
const find = (id: number): number => {
|
||
const current = parent.get(id) ?? id;
|
||
if (current === id) return id;
|
||
const root = find(current);
|
||
parent.set(id, root);
|
||
return root;
|
||
};
|
||
const union = (left: number, right: number) => {
|
||
const leftRoot = find(left);
|
||
const rightRoot = find(right);
|
||
if (leftRoot !== rightRoot) parent.set(rightRoot, leftRoot);
|
||
};
|
||
const tokenOwner = new Map<string, number>();
|
||
for (const frame of sortedFrames) {
|
||
const frameId = Number(frame.frameId);
|
||
const stages = interpretations.filter((entry) => Number(entry.frameId) === frameId);
|
||
for (const token of frameCorrelationTokens(frame, stages)) {
|
||
const owner = tokenOwner.get(token);
|
||
if (owner === undefined) tokenOwner.set(token, frameId);
|
||
else union(owner, frameId);
|
||
}
|
||
}
|
||
|
||
const groupedFrames = new Map<number, TraceEntry[]>();
|
||
for (const frame of sortedFrames) {
|
||
const root = find(Number(frame.frameId));
|
||
groupedFrames.set(root, [...(groupedFrames.get(root) ?? []), frame]);
|
||
}
|
||
const claimedEvents = new Set<number>();
|
||
const operations: TraceOperation[] = [];
|
||
for (const groupFrames of groupedFrames.values()) {
|
||
const frameIds = new Set(groupFrames.map((frame) => Number(frame.frameId)));
|
||
const stages = interpretations.filter((entry) => frameIds.has(Number(entry.frameId)));
|
||
const emittedIds = new Set(stages.flatMap(interpretationEventIds));
|
||
const groupEvents = events.filter((event) => emittedIds.has(eventSourceId(event)));
|
||
groupEvents.forEach((event) => claimedEvents.add(event.id));
|
||
const methods = unique(groupFrames.map(frameMethod));
|
||
const itemTypes = unique(groupFrames.map(frameItemType));
|
||
const title = itemTypes.at(-1) || methods.at(-1) || text(groupFrames[0]?.direction) || "Provider frame";
|
||
const firstFrame = groupFrames[0];
|
||
const lastFrame = groupFrames.at(-1);
|
||
const range = firstFrame === lastFrame
|
||
? `frame ${firstFrame?.frameId}`
|
||
: `frames ${firstFrame?.frameId}–${lastFrame?.frameId}`;
|
||
operations.push({
|
||
key: `frames:${firstFrame?.frameId}`,
|
||
frames: groupFrames,
|
||
interpretations: stages,
|
||
events: groupEvents,
|
||
title,
|
||
subtitle: `${range} · ${groupEvents.length} PRP event${groupEvents.length === 1 ? "" : "s"}`,
|
||
itemType: itemTypes.at(-1) ?? "",
|
||
nativeMethods: methods,
|
||
directions: unique(groupFrames.map((frame) => text(frame.direction))),
|
||
dispositions: unique(stages.map((entry) => text(entry.disposition))),
|
||
prpTypes: unique(groupEvents.map((event) => event.eventType)),
|
||
visible: groupEvents.some((event) => visibilityDecision(event).visible),
|
||
timestamp: Math.min(...groupFrames.map(frameTimestamp)),
|
||
});
|
||
}
|
||
for (const event of events) {
|
||
if (claimedEvents.has(event.id)) continue;
|
||
const decision = visibilityDecision(event);
|
||
operations.push({
|
||
key: `event:${event.id}`,
|
||
frames: [],
|
||
interpretations: [],
|
||
events: [event],
|
||
title: event.eventType,
|
||
subtitle: `PRP ${eventSourceId(event) || `event ${event.seq}`} · no raw correlation`,
|
||
itemType: "",
|
||
nativeMethods: [],
|
||
directions: [],
|
||
dispositions: [],
|
||
prpTypes: [event.eventType],
|
||
visible: decision.visible,
|
||
timestamp: eventTimestamp(event),
|
||
});
|
||
}
|
||
return operations.sort((left, right) => left.timestamp - right.timestamp);
|
||
}
|
||
|
||
async function loadAllRunEvents(runId: string) {
|
||
const events: HeartbeatRunEvent[] = [];
|
||
let afterSeq = 0;
|
||
for (;;) {
|
||
const page = await heartbeatsApi.events(runId, afterSeq, 1_000);
|
||
events.push(...page);
|
||
if (page.length < 1_000) return events;
|
||
const nextSeq = page.at(-1)?.seq ?? afterSeq;
|
||
if (nextSeq <= afterSeq) return events;
|
||
afterSeq = nextSeq;
|
||
}
|
||
}
|
||
|
||
function jsonMatches(value: unknown, query: string): boolean {
|
||
if (!query) return true;
|
||
try {
|
||
return JSON.stringify(value).toLowerCase().includes(query.toLowerCase());
|
||
} catch {
|
||
return String(value).toLowerCase().includes(query.toLowerCase());
|
||
}
|
||
}
|
||
|
||
function JsonPrimitive({ value }: { value: unknown }) {
|
||
if (typeof value === "string") return <span className="text-primary">"{value}"</span>;
|
||
if (typeof value === "number") return <span className="text-muted-foreground">{value}</span>;
|
||
if (typeof value === "boolean") return <span className="text-secondary-foreground">{String(value)}</span>;
|
||
if (value === null) return <span className="text-muted-foreground">null</span>;
|
||
return <span>{String(value)}</span>;
|
||
}
|
||
|
||
function JsonNode({
|
||
label,
|
||
value,
|
||
path,
|
||
depth,
|
||
query,
|
||
}: {
|
||
label?: string;
|
||
value: unknown;
|
||
path: string;
|
||
depth: number;
|
||
query: string;
|
||
}) {
|
||
const expandable = value !== null && typeof value === "object";
|
||
const entries = Array.isArray(value)
|
||
? value.map((child, index) => [String(index), child] as const)
|
||
: Object.entries(record(value));
|
||
const large = entries.length > 8;
|
||
const [expanded, setExpanded] = useState(depth < 1 && !large);
|
||
const forcedOpen = Boolean(query) && jsonMatches(value, query);
|
||
const isOpen = expandable && (expanded || forcedOpen);
|
||
const visibleEntries = query
|
||
? entries.filter(([key, child]) =>
|
||
key.toLowerCase().includes(query.toLowerCase()) || jsonMatches(child, query),
|
||
)
|
||
: entries;
|
||
const pathCopy = useCopyAction();
|
||
const valueCopy = useCopyAction();
|
||
const copyValue = () => {
|
||
const serialized = typeof value === "string" ? value : JSON.stringify(value, null, 2);
|
||
void valueCopy.copy(serialized ?? String(value));
|
||
};
|
||
return (
|
||
<div className={cn(depth > 0 && "border-l border-border/60 pl-3")}>
|
||
<div className="group flex min-h-6 items-start gap-1 font-mono text-xs leading-6">
|
||
{expandable ? (
|
||
<button
|
||
type="button"
|
||
className="mt-1 rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground"
|
||
onClick={() => setExpanded(!isOpen)}
|
||
aria-label={isOpen ? "Collapse JSON value" : "Expand JSON value"}
|
||
>
|
||
{isOpen ? <ChevronDown className="h-3 w-3" /> : <ChevronRight className="h-3 w-3" />}
|
||
</button>
|
||
) : (
|
||
<span className="w-4" />
|
||
)}
|
||
{label !== undefined ? <span className="text-primary">{label}:</span> : null}
|
||
{expandable ? (
|
||
<span className="text-muted-foreground">
|
||
{Array.isArray(value) ? `[${entries.length}]` : `{${entries.length}}`}
|
||
</span>
|
||
) : (
|
||
<JsonPrimitive value={value} />
|
||
)}
|
||
<span className="ml-auto hidden items-center gap-0.5 group-hover:flex">
|
||
<button
|
||
type="button"
|
||
title={pathCopy.copied ? "JSON path copied" : pathCopy.failed ? "Copy failed" : "Copy JSON path"}
|
||
className="rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground"
|
||
onClick={() => void pathCopy.copy(path)}
|
||
>
|
||
{pathCopy.copied ? <Check className="h-3 w-3" /> : <Braces className="h-3 w-3" />}
|
||
</button>
|
||
<button
|
||
type="button"
|
||
title={valueCopy.copied ? "Value copied" : valueCopy.failed ? "Copy failed" : "Copy value"}
|
||
className="rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground"
|
||
onClick={copyValue}
|
||
>
|
||
{valueCopy.copied ? <Check className="h-3 w-3" /> : <Copy className="h-3 w-3" />}
|
||
</button>
|
||
</span>
|
||
</div>
|
||
{isOpen ? (
|
||
<div>
|
||
{visibleEntries.map(([key, child]) => (
|
||
<JsonNode
|
||
key={`${path}.${key}`}
|
||
label={key}
|
||
value={child}
|
||
path={Array.isArray(value) ? `${path}[${key}]` : `${path}.${key}`}
|
||
depth={depth + 1}
|
||
query={query}
|
||
/>
|
||
))}
|
||
{query && visibleEntries.length === 0 ? (
|
||
<p className="pl-5 text-xs text-muted-foreground">No fields match.</p>
|
||
) : null}
|
||
</div>
|
||
) : null}
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function JsonExplorer({ value, label = "Search this JSON" }: { value: unknown; label?: string }) {
|
||
const [query, setQuery] = useState("");
|
||
return (
|
||
<div className={cn("overflow-hidden rounded-md border border-border bg-muted/20", ANALYTICS_MASK_CLASS)}>
|
||
<div className="relative border-b border-border bg-background/60">
|
||
<Search className="absolute left-2.5 top-2.5 h-3.5 w-3.5 text-muted-foreground" />
|
||
<Input
|
||
value={query}
|
||
onChange={(event) => setQuery(event.target.value)}
|
||
placeholder={label}
|
||
className="h-8 border-0 bg-transparent pl-8 text-xs shadow-none focus-visible:ring-0"
|
||
/>
|
||
</div>
|
||
<div className="max-h-80 overflow-auto p-3">
|
||
<JsonNode value={value} path="$" depth={0} query={query.trim()} />
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function fieldMappings(entry: TraceEntry): ProviderTraceFieldMapping[] {
|
||
const explicit = Array.isArray(entry.fieldMappings)
|
||
? entry.fieldMappings
|
||
.map(record)
|
||
.filter((mapping) => text(mapping.action))
|
||
.map((mapping) => ({
|
||
inputPath: text(mapping.inputPath) || undefined,
|
||
outputPath: text(mapping.outputPath) || undefined,
|
||
action: text(mapping.action) as ProviderTraceFieldMapping["action"],
|
||
reason: text(mapping.reason) || undefined,
|
||
}))
|
||
: [];
|
||
const knownDrops = new Set(explicit.filter((mapping) => mapping.action === "dropped").map((mapping) => mapping.inputPath));
|
||
const legacy = Array.isArray(entry.droppedFields)
|
||
? entry.droppedFields
|
||
.map(String)
|
||
.filter((path) => !knownDrops.has(path))
|
||
.map((path) => ({
|
||
inputPath: path,
|
||
action: "dropped" as const,
|
||
reason: text(entry.reason) || "Field was not carried into the next stage",
|
||
}))
|
||
: [];
|
||
return [...explicit, ...legacy];
|
||
}
|
||
|
||
function mappingTone(action: ProviderTraceFieldMapping["action"]) {
|
||
if (action === "dropped" || action === "redacted") return "border-destructive/30 bg-destructive/10 text-destructive";
|
||
if (action === "derived") return "border-secondary bg-secondary text-secondary-foreground";
|
||
return "border-primary/30 bg-primary/10 text-primary";
|
||
}
|
||
|
||
function InterpretationStage({ entry, last }: { entry: TraceEntry; last: boolean }) {
|
||
const mappings = fieldMappings(entry);
|
||
return (
|
||
<div className="relative grid grid-cols-(--gtc-runner-inspector-stage) gap-3">
|
||
<div className="relative flex justify-center">
|
||
{!last ? <span className="absolute bottom-(--sz-neg-1_25rem) top-4 w-px bg-border" /> : null}
|
||
<span className={cn(
|
||
"relative mt-1 h-3 w-3 rounded-full border-2 bg-background",
|
||
entry.disposition === "rejected" ? "border-destructive" : entry.disposition === "ignored" ? "border-muted-foreground" : "border-primary",
|
||
)} />
|
||
</div>
|
||
<div className="mb-4 overflow-hidden rounded-lg border border-border bg-card">
|
||
<div className="flex flex-wrap items-center gap-2 border-b border-border/70 px-3 py-2">
|
||
<code className="text-xs font-semibold">{text(entry.stage)}</code>
|
||
<Badge variant="outline" className="capitalize">{text(entry.disposition)}</Badge>
|
||
<code className="ml-auto text-(length:--text-nano) text-muted-foreground">{text(entry.ruleId)}</code>
|
||
</div>
|
||
<p className="px-3 py-2 text-xs text-muted-foreground">{text(entry.reason)}</p>
|
||
{mappings.length > 0 ? (
|
||
<div className="overflow-x-auto border-t border-border/70">
|
||
<table className="w-full min-w-(--sz-36rem) text-left text-xs">
|
||
<thead className="bg-muted/30 text-muted-foreground">
|
||
<tr>
|
||
<th className="px-3 py-1.5 font-medium">Action</th>
|
||
<th className="px-3 py-1.5 font-medium">Provider path</th>
|
||
<th className="px-3 py-1.5 font-medium">Output path</th>
|
||
<th className="px-3 py-1.5 font-medium">Reason</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{mappings.map((mapping, index) => (
|
||
<tr key={`${mapping.inputPath}:${mapping.outputPath}:${index}`} className="border-t border-border/50 align-top">
|
||
<td className="px-3 py-2">
|
||
<span className={cn("rounded border px-1.5 py-0.5 text-(length:--text-nano)", mappingTone(mapping.action))}>{mapping.action}</span>
|
||
</td>
|
||
<td className="px-3 py-2 font-mono">{mapping.inputPath ?? "—"}</td>
|
||
<td className="px-3 py-2 font-mono">{mapping.outputPath ?? "—"}</td>
|
||
<td className="max-w-xs px-3 py-2 text-muted-foreground">{mapping.reason ?? "—"}</td>
|
||
</tr>
|
||
))}
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
) : (
|
||
<p className="border-t border-border/70 px-3 py-2 text-(length:--text-nano) text-muted-foreground">No field-level mapping was recorded at this stage.</p>
|
||
)}
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function typedPrpFields(event: HeartbeatRunEvent) {
|
||
const prp = eventPrp(event);
|
||
const payload = record(prp.payload);
|
||
const item = record(payload.item);
|
||
return [
|
||
["Event type", event.eventType],
|
||
["Source event", text(prp.sourceEventId)],
|
||
["Sequence", scalar(prp.sourceSequence) || String(event.seq)],
|
||
["Item type", text(item.type) || text(payload.kind)],
|
||
["Status", text(payload.status) || text(item.status)],
|
||
["Query", text(payload.query) || text(item.query)],
|
||
].filter(([, value]) => Boolean(value));
|
||
}
|
||
|
||
function ProductionSurfacePreview({ event, runId }: { event: HeartbeatRunEvent; runId: string }) {
|
||
const prp = eventPrp(event);
|
||
const ts = new Date(event.createdAt).toISOString();
|
||
const entries = parsePaperclipRunnerStdoutLine(
|
||
JSON.stringify({ type: "paperclip.prp.event", event: prp }),
|
||
ts,
|
||
);
|
||
const item = transcriptToTaskChatItems(entries, {
|
||
runId,
|
||
agentName: "Runner",
|
||
running: false,
|
||
}).find((candidate): candidate is TaskChatProtocolItem => candidate.kind === "protocol");
|
||
if (item) return <TaskChatProtocolCard item={item} />;
|
||
const decision = visibilityDecision(event);
|
||
const VisibleIcon = decision.visible ? Eye : EyeOff;
|
||
return (
|
||
<div className="rounded-md border border-border bg-card/60 px-3 py-2.5">
|
||
<div className="flex items-start gap-2">
|
||
<VisibleIcon className="mt-0.5 h-4 w-4 text-muted-foreground" />
|
||
<div className="min-w-0">
|
||
<p className="text-sm font-medium">{event.eventType}</p>
|
||
<p className="mt-0.5 text-xs text-muted-foreground">
|
||
Production surface: {decision.surface} · {decision.action} in {decision.container}
|
||
</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function StatCard({ label, value, detail }: { label: string; value: string | number; detail?: string }) {
|
||
return (
|
||
<div className="rounded-lg border border-border bg-card px-4 py-3">
|
||
<p className="text-(length:--text-nano) font-medium uppercase tracking-wide text-muted-foreground">{label}</p>
|
||
<p className="mt-1 text-2xl font-semibold tracking-tight">{value}</p>
|
||
{detail ? <p className="mt-1 text-xs text-muted-foreground">{detail}</p> : null}
|
||
</div>
|
||
);
|
||
}
|
||
|
||
export function RunnerInspector({
|
||
runId,
|
||
run,
|
||
open,
|
||
onOpenChange,
|
||
onRerunWithTrace,
|
||
}: {
|
||
runId: string;
|
||
run?: { resultJson: Record<string, unknown> | null; status: string } | null;
|
||
open: boolean;
|
||
onOpenChange: (open: boolean) => void;
|
||
onRerunWithTrace?: () => void;
|
||
}) {
|
||
const [inspection, setInspection] = useState<ProviderTraceInspection | null>(null);
|
||
const [events, setEvents] = useState<HeartbeatRunEvent[]>([]);
|
||
const [actionError, setActionError] = useState<unknown>(null);
|
||
const [view, setView] = useState<InspectorView>("pipeline");
|
||
const [selectedKey, setSelectedKey] = useState<string | null>(null);
|
||
const [selectedFrameId, setSelectedFrameId] = useState<number | null>(null);
|
||
const [query, setQuery] = useState("");
|
||
const [direction, setDirection] = useState("all");
|
||
const [nativeMethod, setNativeMethod] = useState("all");
|
||
const [disposition, setDisposition] = useState("all");
|
||
const [prpType, setPrpType] = useState("all");
|
||
const [visibility, setVisibility] = useState("all");
|
||
const [revealed, setRevealed] = useState<Record<string, ProviderTraceFrame>>({});
|
||
const [rawTraceAccess, setRawTraceAccess] = useState<RawTraceAccess | null>(null);
|
||
const rawTraceAccessRef = useRef<RawTraceAccess | null>(null);
|
||
const rawTraceAccessEpochRef = useRef(0);
|
||
const canInspectRaw =
|
||
open && rawTraceAccess?.runId === runId ? rawTraceAccess.allowed : null;
|
||
|
||
useLayoutEffect(() => {
|
||
rawTraceAccessEpochRef.current += 1;
|
||
rawTraceAccessRef.current = null;
|
||
setRawTraceAccess(null);
|
||
setInspection(null);
|
||
setEvents([]);
|
||
setActionError(null);
|
||
setSelectedKey(null);
|
||
setSelectedFrameId(null);
|
||
setRevealed({});
|
||
}, [open, runId]);
|
||
|
||
const denyRawTraceAccess = useCallback(() => {
|
||
const currentAccess = rawTraceAccessRef.current;
|
||
if (
|
||
currentAccess?.runId === runId &&
|
||
currentAccess.phase === "denied"
|
||
) {
|
||
return;
|
||
}
|
||
rawTraceAccessEpochRef.current += 1;
|
||
const deniedAccess: RawTraceAccess = {
|
||
runId,
|
||
allowed: false,
|
||
epoch: rawTraceAccessEpochRef.current,
|
||
phase: "denied",
|
||
};
|
||
rawTraceAccessRef.current = deniedAccess;
|
||
setRawTraceAccess(deniedAccess);
|
||
setInspection({ trace: null, entries: [] });
|
||
setActionError(null);
|
||
setSelectedKey(null);
|
||
setSelectedFrameId(null);
|
||
setRevealed({});
|
||
}, [runId]);
|
||
|
||
useEffect(() => {
|
||
if (!open) return;
|
||
const params = new URLSearchParams(window.location.search);
|
||
const requestedView = params.get("traceView");
|
||
if (requestedView === "overview" || requestedView === "pipeline" || requestedView === "trace") setView(requestedView);
|
||
const requestedOperation = params.get("traceOperation");
|
||
if (requestedOperation) setSelectedKey(requestedOperation);
|
||
}, [open]);
|
||
|
||
// The initial load: the board's current access, every canonical event, and
|
||
// (only for an administrator) the redacted provider trace. The permission
|
||
// epoch fences it: a denial or deletion while it is in flight makes its
|
||
// result stale, and a stale result never reveals or restores raw access.
|
||
// Transient failures keep what is shown and retry; a real failure is
|
||
// rendered as readable copy with a Retry button.
|
||
const load = useResilientFetch({
|
||
key: ["runner-inspection", runId, open],
|
||
enabled: open,
|
||
fetcher: async () => {
|
||
const loadEpoch = rawTraceAccessEpochRef.current;
|
||
const [boardAccess, nextEvents] = await Promise.all([
|
||
accessApi.getCurrentBoardAccess(),
|
||
loadAllRunEvents(runId),
|
||
]);
|
||
// Superseded by a newer denial or deletion: do not read the raw trace.
|
||
if (rawTraceAccessEpochRef.current !== loadEpoch || rawTraceAccessRef.current?.phase === "deleting") return null;
|
||
const canRaw = boardAccess.source === "local_implicit" || boardAccess.isInstanceAdmin;
|
||
const trace = canRaw
|
||
? await heartbeatsApi.providerTrace(runId)
|
||
: ({ trace: null, entries: [] } satisfies ProviderTraceInspection);
|
||
return { loadEpoch, canRaw, trace, events: nextEvents };
|
||
},
|
||
onSuccess: (result) => {
|
||
if (!result || rawTraceAccessEpochRef.current !== result.loadEpoch || rawTraceAccessRef.current?.phase === "deleting") return;
|
||
const access: RawTraceAccess = {
|
||
runId,
|
||
allowed: result.canRaw,
|
||
epoch: result.loadEpoch,
|
||
phase: result.canRaw ? "granted" : "denied",
|
||
};
|
||
rawTraceAccessRef.current = access;
|
||
setRawTraceAccess(access);
|
||
if (!result.canRaw) setRevealed({});
|
||
setInspection(result.trace);
|
||
setEvents(result.events);
|
||
},
|
||
});
|
||
// Once access for this run is decided (a newer denial while the load is
|
||
// still in flight counts) the inspector is no longer loading: the pending
|
||
// result is stale and will be discarded.
|
||
const loading =
|
||
rawTraceAccess?.runId !== runId &&
|
||
(load.view.kind === "loading" || load.view.kind === "reconnecting");
|
||
const loadError = load.view.kind === "error" ? load.view.error : null;
|
||
|
||
useEffect(() => {
|
||
if (!open) return;
|
||
let active = true;
|
||
const revalidate = async () => {
|
||
try {
|
||
const boardAccess = await accessApi.getCurrentBoardAccess();
|
||
if (!active) return;
|
||
const canRaw =
|
||
boardAccess.source === "local_implicit" ||
|
||
boardAccess.isInstanceAdmin;
|
||
if (!canRaw) denyRawTraceAccess();
|
||
} catch {
|
||
if (active) denyRawTraceAccess();
|
||
}
|
||
};
|
||
const onFocus = () => void revalidate();
|
||
const onVisibilityChange = () => {
|
||
if (document.visibilityState === "visible") void revalidate();
|
||
};
|
||
const interval = window.setInterval(
|
||
() => void revalidate(),
|
||
RAW_TRACE_ACCESS_REVALIDATION_MS,
|
||
);
|
||
window.addEventListener("focus", onFocus);
|
||
document.addEventListener("visibilitychange", onVisibilityChange);
|
||
return () => {
|
||
active = false;
|
||
window.clearInterval(interval);
|
||
window.removeEventListener("focus", onFocus);
|
||
document.removeEventListener("visibilitychange", onVisibilityChange);
|
||
};
|
||
}, [denyRawTraceAccess, open]);
|
||
|
||
const entries = inspection?.entries ?? [];
|
||
const frames = useMemo(() => entries.filter((entry) => entry.kind === "frame"), [entries]);
|
||
const interpretations = useMemo(() => entries.filter((entry) => entry.kind === "interpretation"), [entries]);
|
||
const capturedProviders = unique(frames.map((frame) => text(frame.provider)));
|
||
const operations = useMemo(
|
||
() => buildOperations(frames, interpretations, events),
|
||
[events, frames, interpretations],
|
||
);
|
||
const filteredOperations = useMemo(
|
||
() => operations.filter((operation) => {
|
||
if (query.trim() && !jsonMatches(operation, query.trim())) return false;
|
||
if (direction !== "all" && !operation.directions.includes(direction)) return false;
|
||
if (nativeMethod !== "all" && !operation.nativeMethods.includes(nativeMethod)) return false;
|
||
if (disposition !== "all" && !operation.dispositions.includes(disposition)) return false;
|
||
if (prpType !== "all" && !operation.prpTypes.includes(prpType)) return false;
|
||
if (visibility === "visible" && !operation.visible) return false;
|
||
if (visibility === "hidden" && operation.visible) return false;
|
||
return true;
|
||
}),
|
||
[direction, disposition, nativeMethod, operations, prpType, query, visibility],
|
||
);
|
||
|
||
useEffect(() => {
|
||
if (!filteredOperations.length) return;
|
||
if (!selectedKey || !filteredOperations.some((operation) => operation.key === selectedKey)) {
|
||
const preferred =
|
||
filteredOperations.find(
|
||
(operation) => operation.itemType && operation.events.length > 0,
|
||
) ??
|
||
filteredOperations.find(
|
||
(operation) => operation.frames.length > 0 && operation.events.length > 0,
|
||
) ??
|
||
filteredOperations[0]!;
|
||
setSelectedKey(preferred.key);
|
||
}
|
||
}, [filteredOperations, selectedKey]);
|
||
|
||
const selectedOperation = filteredOperations.find((operation) => operation.key === selectedKey) ?? filteredOperations[0] ?? null;
|
||
useEffect(() => {
|
||
if (!selectedOperation) return;
|
||
if (!selectedOperation.frames.some((frame) => Number(frame.frameId) === selectedFrameId)) {
|
||
const preferred = [...selectedOperation.frames].reverse().find((frame) => frameMethod(frame).includes("completed")) ?? selectedOperation.frames.at(-1);
|
||
setSelectedFrameId(preferred ? Number(preferred.frameId) : null);
|
||
}
|
||
}, [selectedFrameId, selectedOperation]);
|
||
|
||
useEffect(() => {
|
||
if (!open || !selectedOperation) return;
|
||
const params = new URLSearchParams(window.location.search);
|
||
params.set("inspectRun", runId);
|
||
params.set("traceView", view);
|
||
params.set("traceOperation", selectedOperation.key);
|
||
const next = `${window.location.pathname}?${params.toString()}${window.location.hash}`;
|
||
window.history.replaceState(window.history.state, "", next);
|
||
}, [open, runId, selectedOperation, view]);
|
||
|
||
const selectedFrame = selectedOperation?.frames.find((frame) => Number(frame.frameId) === selectedFrameId) ?? selectedOperation?.frames.at(-1) ?? null;
|
||
const revealedFrame =
|
||
canInspectRaw === true && selectedFrame
|
||
? (revealed[
|
||
revealedFrameKey(runId, Number(selectedFrame.frameId))
|
||
] ?? null)
|
||
: null;
|
||
const selectedInterpretations = selectedFrame
|
||
? selectedOperation?.interpretations.filter((entry) => Number(entry.frameId) === Number(selectedFrame.frameId)) ?? []
|
||
: selectedOperation?.interpretations ?? [];
|
||
const selectedEvents = selectedOperation?.events ?? [];
|
||
const runResultJson = record(run?.resultJson);
|
||
const presentationDecision = record(runResultJson.presentationDecision);
|
||
const verificationCaveats = Array.isArray(runResultJson.verificationCaveats)
|
||
? runResultJson.verificationCaveats
|
||
: [];
|
||
const ignoredAttentionRequests = Array.isArray(runResultJson.ignoredAttentionRequests)
|
||
? runResultJson.ignoredAttentionRequests
|
||
: [];
|
||
const visibleEventCount = events.filter((event) => visibilityDecision(event).visible).length;
|
||
const ignoredCount = interpretations.filter((entry) => entry.disposition === "ignored").length;
|
||
const dispositionCounts = interpretations.reduce<Record<string, number>>((counts, entry) => {
|
||
const key = text(entry.disposition) || "unknown";
|
||
counts[key] = (counts[key] ?? 0) + 1;
|
||
return counts;
|
||
}, {});
|
||
|
||
const selectOperation = (operation: TraceOperation) => {
|
||
setSelectedKey(operation.key);
|
||
setView("pipeline");
|
||
};
|
||
|
||
const reveal = async (frameId: number) => {
|
||
if (canInspectRaw !== true) return;
|
||
const requestedAccess = rawTraceAccessRef.current;
|
||
if (requestedAccess?.runId !== runId || requestedAccess.allowed !== true) {
|
||
return;
|
||
}
|
||
if (!window.confirm("This exact provider frame may contain prompts, tool arguments, secrets, or reasoning. Reveal it now?")) return;
|
||
const requestedRunId = runId;
|
||
const frame = await heartbeatsApi.revealProviderTraceFrame(
|
||
requestedRunId,
|
||
frameId,
|
||
);
|
||
const currentAccess = rawTraceAccessRef.current;
|
||
if (
|
||
currentAccess?.runId !== requestedRunId ||
|
||
currentAccess.allowed !== true ||
|
||
currentAccess.epoch !== requestedAccess.epoch
|
||
) {
|
||
return;
|
||
}
|
||
setRevealed((current) => ({
|
||
...current,
|
||
[revealedFrameKey(requestedRunId, frameId)]: frame,
|
||
}));
|
||
};
|
||
|
||
const downloadTrace = async () => {
|
||
if (canInspectRaw !== true) return;
|
||
const requestedAccess = rawTraceAccessRef.current;
|
||
if (requestedAccess?.runId !== runId || requestedAccess.allowed !== true) {
|
||
return;
|
||
}
|
||
if (!window.confirm("Download the exact raw trace? It may contain sensitive prompts, tool arguments, and provider-only fields.")) return;
|
||
const blob = await heartbeatsApi.downloadProviderTrace(runId);
|
||
const currentAccess = rawTraceAccessRef.current;
|
||
if (
|
||
currentAccess?.runId !== runId ||
|
||
currentAccess.allowed !== true ||
|
||
currentAccess.epoch !== requestedAccess.epoch
|
||
) {
|
||
return;
|
||
}
|
||
downloadBlob(blob, `provider-trace-${runId}.ndjson`);
|
||
};
|
||
|
||
const deleteTrace = async () => {
|
||
if (canInspectRaw !== true) return;
|
||
const currentAccess = rawTraceAccessRef.current;
|
||
if (currentAccess?.runId !== runId || currentAccess.allowed !== true) {
|
||
return;
|
||
}
|
||
if (!window.confirm("Delete this raw trace immediately? This cannot be undone.")) return;
|
||
rawTraceAccessEpochRef.current += 1;
|
||
const deletionAccess: RawTraceAccess = {
|
||
...currentAccess,
|
||
allowed: false,
|
||
epoch: rawTraceAccessEpochRef.current,
|
||
phase: "deleting",
|
||
};
|
||
rawTraceAccessRef.current = deletionAccess;
|
||
setRawTraceAccess(deletionAccess);
|
||
setRevealed({});
|
||
try {
|
||
await heartbeatsApi.deleteProviderTrace(runId);
|
||
} catch (cause) {
|
||
if (rawTraceAccessRef.current?.epoch === deletionAccess.epoch) {
|
||
setActionError(cause);
|
||
}
|
||
return;
|
||
}
|
||
if (rawTraceAccessRef.current?.epoch !== deletionAccess.epoch) return;
|
||
let boardAccess;
|
||
try {
|
||
boardAccess = await accessApi.getCurrentBoardAccess();
|
||
} catch {
|
||
if (rawTraceAccessRef.current?.epoch === deletionAccess.epoch) {
|
||
denyRawTraceAccess();
|
||
}
|
||
return;
|
||
}
|
||
if (rawTraceAccessRef.current?.epoch !== deletionAccess.epoch) return;
|
||
const canRaw =
|
||
boardAccess.source === "local_implicit" || boardAccess.isInstanceAdmin;
|
||
if (!canRaw) {
|
||
denyRawTraceAccess();
|
||
return;
|
||
}
|
||
rawTraceAccessEpochRef.current += 1;
|
||
const restoredAccess: RawTraceAccess = {
|
||
runId,
|
||
allowed: true,
|
||
epoch: rawTraceAccessEpochRef.current,
|
||
phase: "granted",
|
||
};
|
||
rawTraceAccessRef.current = restoredAccess;
|
||
setRawTraceAccess(restoredAccess);
|
||
setInspection({ trace: null, entries: [] });
|
||
setSelectedKey(null);
|
||
setSelectedFrameId(null);
|
||
};
|
||
|
||
const handleOpenChange = (nextOpen: boolean) => {
|
||
if (!nextOpen) {
|
||
rawTraceAccessEpochRef.current += 1;
|
||
rawTraceAccessRef.current = null;
|
||
setRawTraceAccess(null);
|
||
setInspection(null);
|
||
setEvents([]);
|
||
setSelectedKey(null);
|
||
setSelectedFrameId(null);
|
||
setRevealed({});
|
||
const params = new URLSearchParams(window.location.search);
|
||
params.delete("inspectRun");
|
||
params.delete("traceView");
|
||
params.delete("traceOperation");
|
||
const suffix = params.toString();
|
||
window.history.replaceState(
|
||
window.history.state,
|
||
"",
|
||
`${window.location.pathname}${suffix ? `?${suffix}` : ""}${window.location.hash}`,
|
||
);
|
||
}
|
||
onOpenChange(nextOpen);
|
||
};
|
||
|
||
return (
|
||
<Sheet open={open} onOpenChange={handleOpenChange}>
|
||
<SheetContent
|
||
className="w-(--sz-calc-43) max-w-none gap-0 p-0 sm:max-w-none"
|
||
aria-describedby="runner-inspector-description"
|
||
>
|
||
<SheetHeader className="border-b border-border pr-12">
|
||
<div className="flex flex-wrap items-center gap-2">
|
||
<SheetTitle>Runner Inspector</SheetTitle>
|
||
{inspection?.trace ? (
|
||
<>
|
||
<Badge variant={statusVariant(inspection.trace.status)}>
|
||
{traceBadgeLabel(inspection.trace.status, inspection.trace.expiresAt)}
|
||
</Badge>
|
||
<Badge variant="outline" className="font-mono">
|
||
{capturedProviders.join(", ") || inspection.trace.provider}
|
||
</Badge>
|
||
</>
|
||
) : null}
|
||
</div>
|
||
<SheetDescription id="runner-inspector-description">
|
||
Correlate exact provider traffic with every interpretation stage, canonical PRP event, and production surface.
|
||
</SheetDescription>
|
||
<div className="flex gap-1 pt-1" role="tablist" aria-label="Runner inspector views">
|
||
{VIEW_OPTIONS.map((option) => {
|
||
const Icon = option.icon;
|
||
return (
|
||
<button
|
||
key={option.value}
|
||
type="button"
|
||
role="tab"
|
||
aria-selected={view === option.value}
|
||
onClick={() => setView(option.value)}
|
||
className={cn(
|
||
"inline-flex items-center gap-1.5 border-b-2 px-3 py-2 text-sm font-medium transition-colors",
|
||
view === option.value ? "border-foreground text-foreground" : "border-transparent text-muted-foreground hover:text-foreground",
|
||
)}
|
||
>
|
||
<Icon className="h-4 w-4" /> {option.label}
|
||
</button>
|
||
);
|
||
})}
|
||
</div>
|
||
</SheetHeader>
|
||
|
||
<div className="flex min-h-0 flex-1 flex-col">
|
||
{loadError ? (
|
||
<QueryErrorState
|
||
className="m-4"
|
||
error={loadError}
|
||
action="load the runner inspection"
|
||
onRetry={load.view.retry}
|
||
retrying={load.view.isFetching}
|
||
/>
|
||
) : null}
|
||
{actionError !== null && actionError !== undefined ? (
|
||
<QueryErrorState className="m-4" error={actionError} action="delete the raw trace" />
|
||
) : null}
|
||
{!loading && !loadError && canInspectRaw === false ? (
|
||
<div className="m-4 rounded-md border border-border bg-muted/20 p-4">
|
||
<p className="font-medium">Raw provider traces require an instance administrator.</p>
|
||
<p className="mt-1 text-sm text-muted-foreground">Canonical PRP events and presentation decisions remain inspectable below.</p>
|
||
</div>
|
||
) : null}
|
||
{!loading && !loadError && canInspectRaw === true && !inspection?.trace ? (
|
||
<div className="m-4 flex items-start justify-between gap-4 rounded-md border border-border bg-muted/20 p-4">
|
||
<div>
|
||
<p className="font-medium">Raw provider capture was off for this run.</p>
|
||
<p className="mt-1 text-sm text-muted-foreground">Canonical PRP events and persisted presentation decisions remain available below.</p>
|
||
</div>
|
||
{onRerunWithTrace && canInspectRaw === true ? (
|
||
<Button size="sm" onClick={onRerunWithTrace}><RefreshCw className="mr-1.5 h-4 w-4" />Re-run with provider trace</Button>
|
||
) : null}
|
||
</div>
|
||
) : null}
|
||
|
||
{view === "overview" ? (
|
||
<ScrollArea className="min-h-0 flex-1">
|
||
<div className="space-y-6 p-5">
|
||
{loading ? <p className="text-sm text-muted-foreground">Loading run pipeline…</p> : null}
|
||
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-6">
|
||
<StatCard label="Provider" value={capturedProviders.join(", ") || inspection?.trace?.provider || "PRP only"} detail={inspection?.trace ? `captured through ${inspection.trace.provider}` : "capture was off"} />
|
||
<StatCard label="Raw frames" value={frames.length} detail={inspection?.trace ? formatBytes(inspection.trace.byteCount) : "no exact bytes"} />
|
||
<StatCard label="Operations" value={operations.length} detail="correlated groups" />
|
||
<StatCard label="PRP events" value={events.length} detail={`${visibleEventCount} visible`} />
|
||
<StatCard label="Mappings" value={interpretations.length} detail={`${ignoredCount} ignored`} />
|
||
<StatCard label="Run status" value={run?.status ?? "unknown"} detail={inspection?.trace ? traceBadgeLabel(inspection.trace.status, inspection.trace.expiresAt) : "Raw capture off"} />
|
||
</div>
|
||
<div className="grid gap-4 lg:grid-cols-2">
|
||
<section className="rounded-lg border border-border bg-card p-4">
|
||
<h3 className="text-sm font-semibold">Interpretation outcomes</h3>
|
||
<div className="mt-3 space-y-2">
|
||
{Object.entries(dispositionCounts).length ? Object.entries(dispositionCounts).map(([label, count]) => (
|
||
<div key={label} className="flex items-center gap-3 text-sm">
|
||
<Badge variant="outline" className="w-24 justify-center capitalize">{label}</Badge>
|
||
<div className="h-2 flex-1 overflow-hidden rounded-full bg-muted"><div className="h-full rounded-full bg-primary" style={{ width: `${Math.max(4, (count / Math.max(1, interpretations.length)) * 100)}%` }} /></div>
|
||
<span className="w-8 text-right font-mono text-xs">{count}</span>
|
||
</div>
|
||
)) : <p className="text-sm text-muted-foreground">No interpretation records were persisted.</p>}
|
||
</div>
|
||
</section>
|
||
<section className="rounded-lg border border-border bg-card p-4">
|
||
<h3 className="text-sm font-semibold">Recent correlated operations</h3>
|
||
<div className="mt-2 divide-y divide-border/70">
|
||
{operations.slice(-6).reverse().map((operation) => (
|
||
<button key={operation.key} type="button" onClick={() => selectOperation(operation)} className="flex w-full items-center gap-3 py-2 text-left hover:text-primary">
|
||
<span className={cn("h-2 w-2 rounded-full", operation.events.length ? "bg-primary" : "bg-muted-foreground")} />
|
||
<span className="min-w-0 flex-1"><span className="block truncate text-sm font-medium">{operation.title}</span><span className="block truncate text-xs text-muted-foreground">{operation.subtitle}</span></span>
|
||
<ArrowRight className="h-4 w-4 text-muted-foreground" />
|
||
</button>
|
||
))}
|
||
</div>
|
||
</section>
|
||
</div>
|
||
<section className="rounded-lg border border-border bg-accent/30 p-4">
|
||
<div className="flex gap-3"><ShieldAlert className="mt-0.5 h-5 w-5 shrink-0 text-accent-foreground" /><div><h3 className="text-sm font-semibold">Sensitive debug data</h3><p className="mt-1 text-sm text-muted-foreground">Parsed frames are redacted on the server. Exact reveals and downloads are administrator-only, warned, audited, and automatically expire.</p></div></div>
|
||
</section>
|
||
</div>
|
||
</ScrollArea>
|
||
) : null}
|
||
|
||
{view === "pipeline" ? (
|
||
<>
|
||
<div className="grid gap-2 border-b border-border p-3 sm:grid-cols-2 xl:grid-cols-(--gtc-runner-inspector-filters)">
|
||
<div className="relative"><Search className="absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground" /><Input className="pl-8" value={query} onChange={(event) => setQuery(event.target.value)} placeholder="Search operations, fields, and events" /></div>
|
||
<Select value={direction} onValueChange={setDirection}><SelectTrigger><SelectValue placeholder="Direction" /></SelectTrigger><SelectContent><SelectItem value="all">All directions</SelectItem><SelectItem value="client_to_provider">Client → provider</SelectItem><SelectItem value="provider_to_client">Provider → client</SelectItem><SelectItem value="provider_stderr">Provider stderr</SelectItem></SelectContent></Select>
|
||
<Select value={nativeMethod} onValueChange={setNativeMethod}><SelectTrigger><SelectValue placeholder="Native method" /></SelectTrigger><SelectContent><SelectItem value="all">All native methods</SelectItem>{unique(frames.map(frameMethod)).sort().map((value) => <SelectItem key={value} value={value}>{value}</SelectItem>)}</SelectContent></Select>
|
||
<Select value={disposition} onValueChange={setDisposition}><SelectTrigger><SelectValue placeholder="Mapping" /></SelectTrigger><SelectContent><SelectItem value="all">All mappings</SelectItem>{["mapped", "generic", "ignored", "rejected", "operator_only"].map((value) => <SelectItem key={value} value={value}>{value}</SelectItem>)}</SelectContent></Select>
|
||
<Select value={prpType} onValueChange={setPrpType}><SelectTrigger><SelectValue placeholder="PRP type" /></SelectTrigger><SelectContent><SelectItem value="all">All PRP types</SelectItem>{unique(events.map((event) => event.eventType)).sort().map((value) => <SelectItem key={value} value={value}>{value}</SelectItem>)}</SelectContent></Select>
|
||
<Select value={visibility} onValueChange={setVisibility}><SelectTrigger><SelectValue placeholder="Visibility" /></SelectTrigger><SelectContent><SelectItem value="all">Visible + hidden</SelectItem><SelectItem value="visible">Visible</SelectItem><SelectItem value="hidden">Hidden</SelectItem></SelectContent></Select>
|
||
</div>
|
||
<div className="grid min-h-0 flex-1 lg:grid-cols-(--gtc-runner-inspector-pipeline)">
|
||
<ScrollArea className="border-r border-border">
|
||
<div className="p-2">
|
||
{loading ? <p className="p-3 text-sm text-muted-foreground">Loading run pipeline…</p> : null}
|
||
{!loading && filteredOperations.length === 0 ? <p className="p-3 text-sm text-muted-foreground">No operations match these filters.</p> : null}
|
||
{filteredOperations.map((operation) => (
|
||
<button key={operation.key} type="button" onClick={() => setSelectedKey(operation.key)} className="mb-1 w-full rounded-lg border border-transparent px-3 py-2.5 text-left hover:bg-muted/50 data-[selected=true]:border-border data-[selected=true]:bg-muted" data-selected={selectedOperation?.key === operation.key}>
|
||
<span className="flex items-center gap-2"><span className={cn("h-2 w-2 shrink-0 rounded-full", operation.events.length ? operation.visible ? "bg-primary" : "bg-secondary-foreground" : "bg-muted-foreground")} role="img" aria-label={operation.events.length ? operation.visible ? "Visible production event" : "Hidden production event" : "No production event"} /><span className="min-w-0 flex-1 truncate text-sm font-medium">{operation.title}</span>{operation.frames.length > 1 ? <Badge variant="outline" className="px-1.5 text-(length:--text-nano)">{operation.frames.length} frames</Badge> : null}</span>
|
||
<span className="mt-1 block truncate pl-4 text-(length:--text-nano) text-muted-foreground">{operation.subtitle}</span>
|
||
<span className="mt-1.5 flex flex-wrap gap-1 pl-4">{operation.prpTypes.slice(0, 3).map((type) => <span key={type} className="rounded bg-background px-1.5 py-0.5 font-mono text-(length:--text-nano) text-muted-foreground">{type}</span>)}</span>
|
||
</button>
|
||
))}
|
||
</div>
|
||
</ScrollArea>
|
||
<ScrollArea>
|
||
{selectedOperation ? (
|
||
<div className="space-y-6 p-5">
|
||
<div className="flex flex-wrap items-center gap-2 rounded-lg border border-border bg-muted/20 px-4 py-3">
|
||
<strong className="text-sm">{selectedOperation.title}</strong><ArrowRight className="h-3.5 w-3.5 text-muted-foreground" /><span className="text-xs text-muted-foreground">{selectedOperation.frames.length} raw frame{selectedOperation.frames.length === 1 ? "" : "s"}</span><ArrowRight className="h-3.5 w-3.5 text-muted-foreground" /><span className="text-xs text-muted-foreground">{selectedOperation.interpretations.length} mapping stage{selectedOperation.interpretations.length === 1 ? "" : "s"}</span><ArrowRight className="h-3.5 w-3.5 text-muted-foreground" /><span className="text-xs text-muted-foreground">{selectedEvents.length} PRP event{selectedEvents.length === 1 ? "" : "s"}</span>
|
||
</div>
|
||
<section>
|
||
<div className="mb-2 flex flex-wrap items-center gap-2"><span className="flex h-6 w-6 items-center justify-center rounded-full bg-accent text-xs font-semibold text-accent-foreground">1</span><h3 className="text-sm font-semibold">Provider frames</h3><span className="text-xs text-muted-foreground">server-redacted by default</span></div>
|
||
{selectedOperation.frames.length > 1 ? <div className="mb-2 flex flex-wrap gap-1">{selectedOperation.frames.map((frame) => <button key={Number(frame.frameId)} type="button" onClick={() => setSelectedFrameId(Number(frame.frameId))} className={cn("rounded-md border px-2 py-1 font-mono text-xs", Number(frame.frameId) === Number(selectedFrame?.frameId) ? "border-primary/50 bg-primary/10 text-foreground" : "border-border text-muted-foreground hover:bg-muted")}>#{String(frame.frameId)} {frameMethod(frame) || text(frame.direction)}</button>)}</div> : null}
|
||
{selectedFrame ? (
|
||
<div className="space-y-2">
|
||
<div className="flex flex-wrap items-center gap-2 text-xs text-muted-foreground"><Badge variant="outline">frame {String(selectedFrame.frameId)}</Badge><span>{text(selectedFrame.direction).replaceAll("_", " ")}</span><span>{formatBytes(Number(selectedFrame.byteLength) || 0)}</span><code className="truncate">{text(selectedFrame.digest)}</code></div>
|
||
<JsonExplorer value={selectedFrame.parsed} />
|
||
{Array.isArray(selectedFrame.withheldPaths) && selectedFrame.withheldPaths.length > 0 ? <div className="flex items-start gap-2 rounded-md border border-border bg-accent/30 px-3 py-2 text-xs text-muted-foreground"><ShieldAlert className="mt-0.5 h-3.5 w-3.5 shrink-0 text-accent-foreground" /><span>Withheld paths: {selectedFrame.withheldPaths.join(", ")}</span></div> : null}
|
||
{canInspectRaw === true ? <Button size="sm" variant="outline" onClick={() => void reveal(Number(selectedFrame.frameId))}><Eye className="mr-1.5 h-4 w-4" />Reveal exact frame</Button> : null}
|
||
{revealedFrame ? <div className={cn("rounded-md border border-destructive/30 p-2", ANALYTICS_NO_CAPTURE_CLASS)}><p className="mb-2 flex items-center gap-1.5 text-xs font-medium text-destructive"><ShieldAlert className="h-3.5 w-3.5" />Exact unredacted frame</p><JsonExplorer value={decodeExactFrame(revealedFrame.rawBase64)} label="Search exact frame" /></div> : null}
|
||
</div>
|
||
) : <p className="text-sm text-muted-foreground">This PRP event has no recoverable raw frame.</p>}
|
||
</section>
|
||
<section>
|
||
<div className="mb-3 flex items-center gap-2"><span className="flex h-6 w-6 items-center justify-center rounded-full bg-primary/10 text-xs font-semibold text-primary">2</span><h3 className="text-sm font-semibold">Interpretation stages</h3></div>
|
||
{selectedInterpretations.length ? selectedInterpretations.map((entry, index) => <InterpretationStage key={`${entry.debugChannel}:${entry.debugSequence}:${index}`} entry={entry} last={index === selectedInterpretations.length - 1} />) : <p className="text-sm text-muted-foreground">No interpretation stage was recorded for this frame.</p>}
|
||
</section>
|
||
<section>
|
||
<div className="mb-3 flex items-center gap-2"><span className="flex h-6 w-6 items-center justify-center rounded-full bg-secondary text-xs font-semibold text-secondary-foreground">3</span><h3 className="text-sm font-semibold">Canonical PRP events</h3></div>
|
||
{selectedEvents.length ? selectedEvents.map((event) => (
|
||
<div key={event.id} className="mb-3 overflow-hidden rounded-lg border border-border bg-card">
|
||
<div className="flex flex-wrap items-center gap-2 border-b border-border/70 px-3 py-2"><code className="text-xs font-semibold">{event.eventType}</code><Badge variant="outline">seq {event.seq}</Badge><button type="button" className="ml-auto text-xs text-primary underline-offset-4 hover:underline" onClick={() => { setVisibility(visibilityDecision(event).visible ? "visible" : "hidden"); setSelectedKey(selectedOperation.key); }}>Why isn’t this visible?</button></div>
|
||
<dl className="grid gap-x-4 gap-y-1 px-3 py-2 text-xs sm:grid-cols-(--gtc-runner-inspector-fields)">{typedPrpFields(event).map(([label, value]) => <div key={label} className="contents"><dt className="text-muted-foreground">{label}</dt><dd className="min-w-0 break-words font-mono">{value}</dd></div>)}</dl>
|
||
<details className="border-t border-border/70"><summary className="flex cursor-pointer list-none items-center gap-1 px-3 py-2 text-xs font-medium text-muted-foreground"><ChevronDown className="h-3.5 w-3.5" />Canonical event JSON</summary><div className="p-3 pt-0"><JsonExplorer value={eventPrp(event)} /></div></details>
|
||
</div>
|
||
)) : <p className="text-sm text-muted-foreground">This provider operation emitted no canonical PRP events.</p>}
|
||
</section>
|
||
<section>
|
||
<div className="mb-3 flex items-center gap-2"><span className="flex h-6 w-6 items-center justify-center rounded-full bg-muted text-xs font-semibold text-foreground">4</span><h3 className="text-sm font-semibold">Production presentation</h3></div>
|
||
{selectedEvents.length ? selectedEvents.map((event) => {
|
||
const decision = visibilityDecision(event);
|
||
return <div key={event.id} className="mb-4 grid gap-3 xl:grid-cols-(--gtc-runner-inspector-presentation)"><dl className="grid grid-cols-(--gtc-runner-inspector-fields) gap-x-3 gap-y-1 rounded-lg border border-border p-3 text-sm"><dt className="text-muted-foreground">Visible</dt><dd className="flex items-center gap-1.5">{decision.visible ? <Check className="h-3.5 w-3.5 text-primary" /> : <CircleOff className="h-3.5 w-3.5 text-muted-foreground" />}{decision.visible ? "yes" : "no"}</dd><dt className="text-muted-foreground">Surface</dt><dd>{decision.surface}</dd><dt className="text-muted-foreground">Container</dt><dd>{decision.container}</dd><dt className="text-muted-foreground">State</dt><dd>{decision.state}</dd><dt className="text-muted-foreground">Action</dt><dd>{decision.action}</dd><dt className="text-muted-foreground">Reason</dt><dd>{decision.reason}</dd><dt className="text-muted-foreground">Reason code</dt><dd><code className="text-xs">{decision.reasonCode}</code></dd></dl><div><p className="mb-2 text-(length:--text-nano) font-medium uppercase tracking-wide text-muted-foreground">Production surface preview</p><ProductionSurfacePreview event={event} runId={runId} /></div></div>;
|
||
}) : <p className="text-sm text-muted-foreground">No presentation surface was emitted for this operation.</p>}
|
||
{Object.keys(presentationDecision).length > 0 ? <details className="rounded-lg border border-border"><summary className="cursor-pointer px-3 py-2 text-xs font-medium text-muted-foreground">Resolved final response decision</summary><div className="p-3 pt-0"><JsonExplorer value={presentationDecision} /></div></details> : null}
|
||
{verificationCaveats.length > 0 || ignoredAttentionRequests.length > 0 ? (
|
||
<div className="mt-3 rounded-lg border border-border bg-accent/30 p-3">
|
||
<p className="text-xs font-semibold text-accent-foreground">Semantic finalization lineage</p>
|
||
<p className="mt-1 text-xs text-muted-foreground">
|
||
Provider-native transport and model-authored tool arguments are separate layers. PRP normalized the model payload, then server policy chose the issue disposition.
|
||
</p>
|
||
{ignoredAttentionRequests.some((candidate) => record(candidate).sourceKind === "environment_constraint") ? (
|
||
<p className="mt-2 text-xs">
|
||
<code>environment_constraint</code> was model-authored tool payload data, not a Codex app-server event. It was normalized into a non-blocking verification caveat.
|
||
</p>
|
||
) : null}
|
||
<dl className="mt-2 grid grid-cols-(--gtc-runner-inspector-fields) gap-x-3 gap-y-1 text-xs">
|
||
<dt className="text-muted-foreground">Policy</dt><dd><code>{text(runResultJson.finalizationPolicyVersion) || "unknown"}</code></dd>
|
||
<dt className="text-muted-foreground">Decision reason</dt><dd><code>{text(runResultJson.finalizationReasonCode) || "unknown"}</code></dd>
|
||
</dl>
|
||
<details className="mt-2"><summary className="cursor-pointer text-xs font-medium text-muted-foreground">Normalized caveats and ignored requests</summary><div className="mt-2"><JsonExplorer value={{ verificationCaveats, ignoredAttentionRequests }} /></div></details>
|
||
</div>
|
||
) : null}
|
||
</section>
|
||
</div>
|
||
) : <div className="p-5 text-sm text-muted-foreground">Select a correlated operation to inspect its pipeline.</div>}
|
||
</ScrollArea>
|
||
</div>
|
||
</>
|
||
) : null}
|
||
|
||
{view === "trace" ? (
|
||
<div className="grid min-h-0 flex-1 md:grid-cols-(--gtc-runner-inspector-trace)">
|
||
<ScrollArea className="border-r border-border"><div className="p-2">{frames.length ? [...frames].sort((left, right) => Number(left.frameId) - Number(right.frameId)).map((frame) => <button key={Number(frame.frameId)} type="button" onClick={() => { const operation = operations.find((candidate) => candidate.frames.some((candidateFrame) => Number(candidateFrame.frameId) === Number(frame.frameId))); if (operation) setSelectedKey(operation.key); setSelectedFrameId(Number(frame.frameId)); }} className={cn("mb-1 w-full rounded-md border px-3 py-2 text-left", Number(frame.frameId) === Number(selectedFrame?.frameId) ? "border-primary/40 bg-primary/10" : "border-transparent hover:bg-muted/50")}><span className="flex items-center gap-2 text-sm font-medium"><span className="font-mono text-xs text-muted-foreground">#{String(frame.frameId)}</span><span className="truncate">{frameMethod(frame) || text(frame.direction)}</span></span><span className="mt-1 block text-(length:--text-nano) text-muted-foreground">{text(frame.direction).replaceAll("_", " ")} · {formatBytes(Number(frame.byteLength) || 0)}</span></button>) : <p className="p-3 text-sm text-muted-foreground">No raw frames were captured for this run.</p>}</div></ScrollArea>
|
||
<ScrollArea><div className="space-y-3 p-5">{selectedFrame ? <><div className="flex flex-wrap items-center gap-2"><h3 className="text-sm font-semibold">Exact trace frame #{String(selectedFrame.frameId)}</h3><Badge variant="outline">{frameMethod(selectedFrame) || text(selectedFrame.direction)}</Badge></div><JsonExplorer value={selectedFrame.parsed} />{canInspectRaw === true ? <Button size="sm" variant="outline" onClick={() => void reveal(Number(selectedFrame.frameId))}><Eye className="mr-1.5 h-4 w-4" />Reveal exact frame</Button> : null}{revealedFrame ? <div className={ANALYTICS_NO_CAPTURE_CLASS}><JsonExplorer value={decodeExactFrame(revealedFrame.rawBase64)} label="Search exact frame" /></div> : null}</> : <p className="text-sm text-muted-foreground">Select a frame from the chronological trace.</p>}</div></ScrollArea>
|
||
</div>
|
||
) : null}
|
||
|
||
{canInspectRaw === true && inspection?.trace?.runId === runId ? (
|
||
<div className="flex flex-wrap items-center justify-between gap-2 border-t border-border p-3">
|
||
<p className="text-xs text-muted-foreground">{inspection.trace.frameCount} frames · {formatBytes(inspection.trace.byteCount)} · expires {new Date(inspection.trace.expiresAt).toLocaleString()}</p>
|
||
<div className="flex gap-2"><Button size="sm" variant="outline" onClick={() => void downloadTrace()}><Download className="mr-1.5 h-4 w-4" />Download exact trace</Button><Button size="sm" variant="destructive" onClick={() => void deleteTrace()}><Trash2 className="mr-1.5 h-4 w-4" />Delete trace</Button></div>
|
||
</div>
|
||
) : null}
|
||
</div>
|
||
</SheetContent>
|
||
</Sheet>
|
||
);
|
||
}
|