diff --git a/scripts/ab-corpus/apply.ts b/scripts/ab-corpus/apply.ts index dc4a34c06..3297cfb08 100644 --- a/scripts/ab-corpus/apply.ts +++ b/scripts/ab-corpus/apply.ts @@ -41,18 +41,46 @@ export const applyToFreshDoc: ApplyFn = async (parsed: ParsedOutput): Promise 0) { + let partialDoc: PenDocument | null = null; + try { + const candidate = JSON.parse(readFileSync(fp, 'utf-8')) as PenDocument; + const topLevel = (candidate.children ?? + candidate.pages?.[0]?.children ?? + []) as unknown[]; + if (topLevel.length > 0) partialDoc = candidate; + } catch { + // File unreadable or empty (e.g. every tag failed before + // the first element-tool wrote anything) — surface null. + } + return { + ok: false, + error: `${failures.length}/${parsed.calls.length} tag(s) failed: ${failures.join('; ')}`, + doc: partialDoc, + }; } } else { const result = await handleBatchDesign({