--- name: diagnose-extraction description: Deep-dive diagnostics on a low-quality or failed extraction. Analyzes field traces, content provenance, fallback usage, and suggests mapping improvements. argument-hint: [scraper-name-or-url] --- # Deep Extraction Diagnostics Perform a thorough analysis of an extraction result to understand why quality is low or fields are missing. Goes beyond `/extract` by analyzing each field's extraction strategy, suggesting fixes, and identifying structural issues. ## Inputs `$ARGUMENTS` can be: - A scraper name (runs against existing fixture) - A URL (fetches and analyzes) - A file path to HTML ## Workflow ### Step 1: Run extraction with full diagnostics Write and execute an inline script to get the complete diagnostic output: ```bash cd astro-app && npx tsx -e " import { readFileSync } from 'fs'; import { extractFromHtml } from './src/lib/extractor/html-extractor.js'; const html = readFileSync('', 'utf-8'); const result = extractFromHtml({ html, sourceUrl: '', scraperMappingName: '', }); const d = result.diagnostics; console.log(JSON.stringify({ grade: d?.qualityGrade, label: d?.qualityLabel, extractionRate: d?.extractionRate, weightedRate: d?.weightedExtractionRate, totalFields: d?.totalFields, populated: d?.populatedFields, extractable: d?.extractableFields, populatedExtractable: d?.populatedExtractableFields, criticalMissing: d?.criticalFieldsMissing, emptyFields: d?.emptyFields, contentAnalysis: d?.contentAnalysis, fieldTraces: d?.fieldTraces, splitSchema: result.splitSchema, }, null, 2)); " ``` ### Step 2: Analyze content provenance Check the `contentAnalysis` section: - **`appearsBlocked: true`** — The page was likely bot-blocked (captcha/verify page). The user needs to provide HTML from a real browser session. - **`appearsJsOnly: true`** — The page is a JS-only shell. The user needs to capture the rendered HTML (browser "Save As" after rendering). - **`jsonLdCount > 0`** — JSON-LD structured data is available. Consider adding `jsonLdPath` strategies. - **`scriptJsonVarsFound`** — Known script variables detected (PAGE_MODEL, __NEXT_DATA__, etc). Consider adding `scriptJsonPath` strategies. ### Step 3: Analyze field traces For each empty or problematic field: 1. **Read the field trace** — what strategy was attempted? 2. **Read the mapping** — is the CSS selector still valid? 3. **Search the HTML fixture** — where does the data actually live? 4. **Check for fallbacks** — does the field have fallback strategies? 5. **Check the field importance** — is it critical (title, price), important (coords, address), or optional? ### Step 4: Analyze the HTML structure Look at the fixture HTML for: - **JSON-LD blocks** (`