/** * Pattern-matching schema discovery for `.trace` bundles. v1.14 item B. * * Pre-v1.14 the trace-side analyzers hardcoded their schema names * (`potential-hangs`, `time-profile`, etc.) into the xpath queries * (`/trace-toc/run/data/table[@schema="X"]`). Robust as long as Apple * never renames a schema. When they DO rename one (or split into * `hang-risks` alongside `potential-hangs`, see item F), the analyzer * silently returns "schema absent" against a trace that has the data * just under a different name. * * XcodeTraceMCP solves this with a regex-pattern lookup: each schema * "family" maps to a list of regex patterns; discovery walks the TOC, * matches schema names against the patterns, returns the first hit. * Falls through gracefully when nothing matches (callers fall back to * the hardcoded canonical name). * * The patterns mirror XcodeTraceMCP's `SCHEMA_PATTERNS` plus the * families memorydetective already analyzes: * `hangs`, `animation-hitches`, `time-profile`, `allocations`, * `app-launch`, `memory`, `network`, `energy`, `leaks`. */ export declare const SCHEMA_FAMILIES: { readonly hangs: [RegExp]; readonly "hang-risks": [RegExp]; readonly "animation-hitches": [RegExp, RegExp]; readonly "time-profile": [RegExp]; readonly "time-sample": [RegExp]; readonly allocations: [RegExp, RegExp, RegExp]; readonly "app-launch": [RegExp, RegExp]; readonly memory: [RegExp, RegExp, RegExp]; readonly network: [RegExp, RegExp, RegExp]; readonly energy: [RegExp, RegExp, RegExp, RegExp]; readonly leaks: [RegExp, RegExp]; }; export type SchemaFamily = keyof typeof SCHEMA_FAMILIES; /** Canonical schema name we hardcoded before v1.14. Used as the fallback * when discovery does not match anything in the TOC. */ export declare const CANONICAL_SCHEMA_NAME: Record; /** * Pure: extract all `` names from a TOC XML * string. Returns the names in document order, including duplicates * (a trace can have the same schema appear with different filter * attributes; the caller decides what to do with duplicates). * * Accepts both self-closing `
` (Apple's --toc shape) * and open-close `
...
` (test fixtures). */ export declare function extractSchemaNamesFromToc(tocXml: string): string[]; /** * Pure: find the schema name in the TOC that matches the requested * family. Returns the FIRST match in document order so deterministic * across runs. Falls back to the canonical hardcoded name when no * pattern matches; never returns null so callers can plug the result * straight into an xpath query. * * The hardcoded fallback preserves pre-v1.14 behavior: if the trace * uses the canonical name, the xpath still works because the canonical * name itself matches its own family pattern. */ export declare function discoverSchema(tocXml: string, family: SchemaFamily): string; /** * Pure: bulk variant. Resolves multiple families against the same TOC * in one pass. Useful when an analyzer needs more than one schema * (e.g. `analyzeHangs` reading both `hangs` and `hang-risks`). */ export declare function discoverSchemas(tocXml: string, families: readonly F[]): Record; /** * Async wrapper for the trace-side analyzers. Runs `xcrun xctrace * export --input --toc` once and applies {@link discoverSchemas} * to the result. Failures (xctrace error, parse glitch, missing trace) * fall back to the canonical hardcoded names so the analyzer pipeline * still works at pre-v1.14 behavior. v1.14 item B. * * `runCommand` is injected (not imported from runtime/exec) to keep * this module dependency-free and unit-testable without spawning * processes. */ export interface SchemaDiscoveryRunner { (cmd: string, args: string[], options: { timeoutMs: number; }): Promise<{ code: number; stdout: string; stderr: string; }>; } export declare function fetchDiscoveredSchemas(runCommand: SchemaDiscoveryRunner, tracePath: string, families: readonly F[]): Promise>; /** * v1.18 D-02. Cache-aware schema resolution for the trace analyzers. * * When the caller already has a `discoveredSchemas` map (typically because * a higher-level orchestrator like `summarizeTrace` ran discovery once up * front and is fanning out to multiple analyzers in parallel), each analyzer * uses the cached entries instead of paying the `xctrace --toc` cost again. * * Pre-v1.18 every analyzer ran its own `xctrace --toc`. `summarizeTrace` * fan-outs to 6 analyzers, so the TOC was fetched 6 times for one trace. * Measured penalty: +600-3000ms wall-clock on real Apple traces (xctrace * cold-start dominated). With this helper + a single up-front discovery * call, the penalty drops to a single fetch. * * When `cached` is `undefined`, falls back to {@link fetchDiscoveredSchemas} * (the cold path) so direct callers that do not orchestrate keep working. * * When `cached` is provided but missing a family, the canonical name from * {@link CANONICAL_SCHEMA_NAME} is used (same fallback as the cold path's * pattern-not-matched branch). This keeps the analyzer pipeline working * even when the orchestrator forgot to discover a family. * * Mirrors the optional-input pattern used elsewhere in the codebase * (e.g. `analyzeHangs.hangRisksXml`): one path that wraps the * runtime call, one that takes pre-fetched data. */ export declare function resolveSchemasForAnalyzer(runCommand: SchemaDiscoveryRunner, tracePath: string, families: readonly F[], cached?: Partial>): Promise>; /** * v1.17 B-06. Same as {@link fetchDiscoveredSchemas} but also returns a * discovery status so callers can surface "we fell back" via the unified * `supportStatus[]` instead of silently using canonical names. * * Status values: * * - `ok`: TOC fetched, pattern match succeeded for at least one family. * (When a specific family does not match, the canonical name is still * returned for it, but the overall status is still `ok` because the TOC * itself was readable.) * - `failed`: `xctrace --toc` returned non-zero, or threw, or returned * empty stdout. `schemas` are all canonical fallbacks. * * The legacy `fetchDiscoveredSchemas` keeps its existing silent-fallback * contract for callers that do not care. */ export interface SchemaDiscoveryStatus { schemas: Record; status: "ok" | "failed"; /** When status is `failed`, a short reason suitable for `supportStatus.reason`. */ reason?: string; } export declare function fetchDiscoveredSchemasWithStatus(runCommand: SchemaDiscoveryRunner, tracePath: string, families: readonly F[]): Promise>; /** Test hook — clears the one-time warning dedupe. */ export declare function _resetSchemaDiscoveryWarningsForTests(): void;