/** * `summarizeTrace`: the trace-to-summary-card-in-one-call feature. * * Today an agent handed a `.trace` chains inspectTrace + up to 5 * analyzers + reasons over tens of KB of JSON. That's 6 round-trips * and ~$0.10-0.20 in tokens, most of which get thrown away after the * agent identifies the one user-visible finding. * * summarizeTrace does it all in one call: * * 1. Inspects the TOC via inspectTrace (reuses the v1.11 path). * 2. For each populated known schema, runs the matching analyzer in * parallel with smart defaults tuned for "what would a user care * about?" (Apple's 100ms hitch threshold, top-10 hangs, top-15 * time-profile symbols, etc). * 3. Cross-correlates findings (v1.13 Phase 2): hangs overlapping * with hitches, allocation spikes preceding hangs, etc. * 4. Produces a structured result PLUS a pre-rendered compact * markdown card (< 10 KB target) suitable for direct presentation * to the user without further reasoning. * * Strategic positioning: this is memorydetective's "synthesis over * raw-query" play vs trace-MCPs that go deep on single-schema access. * See `~/Desktop/internal/v1.9-notelet-retro-market.md` ยง4.5 for the * full framing. */ import { z } from "zod"; import { type InspectTraceResult } from "./inspectTrace.js"; import { type AnalyzeHangsResult } from "./analyzeHangs.js"; import { type AnalyzeAnimationHitchesResult } from "./analyzeAnimationHitches.js"; import { type AnalyzeTimeProfileResult } from "./analyzeTimeProfile.js"; import { type AnalyzeAllocationsResult } from "./analyzeAllocations.js"; import { type AnalyzeAppLaunchResult } from "./analyzeAppLaunch.js"; import { type AnalyzeNetworkActivityResult } from "./analyzeNetworkActivity.js"; export declare const summarizeTraceSchema: z.ZodObject<{ tracePath: z.ZodString; focus: z.ZodDefault>; verbose: z.ZodDefault; }, "strip", z.ZodTypeAny, { tracePath: string; focus: "allocations" | "all" | "hangs" | "network" | "hitches" | "launch"; verbose: boolean; }, { tracePath: string; focus?: "allocations" | "all" | "hangs" | "network" | "hitches" | "launch" | undefined; verbose?: boolean | undefined; }>; export type SummarizeTraceInput = z.infer; /** * Per-analyzer entry on the structured result. `status` distinguishes * "ran successfully", "schema absent in trace", and "ran but failed". * Callers branching on the summary can decide whether to retry / refine. */ export interface SummarizeAreaSummary { status: "ok" | "schema-absent" | "failed"; /** Why the status is what it is (one sentence). Surfaces SIGSEGV / missing-schema / parser-error reasons. */ diagnosis: string; /** Full analyzer result when status === "ok". Useful when a caller wants to drill in without re-running the analyzer. */ result?: TResult; } /** * v1.13 Phase 2: cross-area correlation. Each entry is a finding * tying TWO areas together via timestamp overlap. The narrative * field is the human-scannable string that goes into the markdown * card; the structured fields (`kind`, `confidence`, evidence ids) * are what callers can branch on programmatically. */ export interface Correlation { /** Which two areas this correlation ties together. Currently only `hangs+hitches` is supported; `hangs+allocations` and `hitches+allocations` are deferred to v1.14+ because the analyzer doesn't currently expose per-timestamp allocation rows. */ kind: "hangs+hitches"; /** `high` when the overlap is substantial (both events > 100ms and the windows overlap significantly); `medium` when one event is short; `low` when timestamps are only adjacent. */ confidence: "high" | "medium" | "low"; /** Pre-formatted human-scannable narrative. Goes into the markdown card. */ narrative: string; /** Start time in seconds (for the hang event). Used to rank correlations by user-relevance (earliest first). */ atSec: number; } export interface SummarizeTraceResult { ok: boolean; tracePath: string; /** TOC + suggestedNextCalls from inspectTrace. Always present. */ inspection: InspectTraceResult; /** Per-area summaries. Each section is independent; absence of one doesn't fail the call. */ areas: { hangs: SummarizeAreaSummary; hitches: SummarizeAreaSummary; timeProfile: SummarizeAreaSummary; allocations: SummarizeAreaSummary; appLaunch: SummarizeAreaSummary; /** v1.15: network-connections schema. Absent when the trace was recorded with a non-Network template. */ network: SummarizeAreaSummary; }; /** Cross-area correlations (v1.13 Phase 2). Empty when areas don't have enough data to correlate. */ correlations: Correlation[]; /** Headline string: 1-2 sentences naming the biggest user-impact finding across all areas. */ headline: string; /** Pre-rendered markdown summary card. Target < 10 KB at default `verbose: false`. */ markdown: string; } /** * Pure: detect hangs whose window overlaps with animation hitches. * When a user sees a hang AND a hitch in the same time window, * they almost certainly perceived the impact (the main-thread block * delayed render commits, dropping frames). * * The overlap check is symmetric: a hitch can fall within a hang's * window OR a hang can fall within a hitch's window. Both directions * are treated equally. * * Confidence: * * - `high`: both events >= 250ms AND the overlap span >= 100ms. * - `medium`: at least one event >= 250ms. * - `low`: neither event >= 250ms but the windows touch. * * Results are sorted by `atSec` ascending so the markdown card lists * correlations in trace order. */ export declare function correlateHangsAndHitches(hangs: Array<{ startNs: number; durationNs: number; durationMs: number; }>, hitches: Array<{ startNs: number; durationNs: number; durationMs: number; hitchType?: string; }>): Correlation[]; /** * Pure: build all cross-area correlations from per-area summaries. * Currently only `hangs+hitches` produces entries; allocation-based * correlations need per-timestamp allocation data the existing * analyzeAllocations doesn't expose (v1.14+ candidate). */ export declare function buildCorrelations(areas: SummarizeTraceResult["areas"]): Correlation[]; /** * Pure: produce the one-or-two-sentence headline that goes at the top * of the markdown card. Picks the most user-visible finding across * all areas. Order of priority: longest hang above 250ms > worst * launch phase > worst hitch > largest allocation spike. */ export declare function buildHeadline(areas: SummarizeTraceResult["areas"]): string; /** * Pure: assemble the compact markdown summary card. Designed to be * <10 KB at default settings. The structured `areas` field carries * the full data for callers who need it; this is the human view. */ export declare function buildMarkdownCard(result: Omit, verbose: boolean): string; export declare function summarizeTrace(input: SummarizeTraceInput): Promise; export declare const SUMMARIZE_AREA_KEYS: readonly ["hangs", "hitches", "timeProfile", "allocations", "appLaunch"];