diff --git a/engineering/engineering-universal-document-compiler.md b/engineering/engineering-universal-document-compiler.md index 01f2bb6c..113055b0 100644 --- a/engineering/engineering-universal-document-compiler.md +++ b/engineering/engineering-universal-document-compiler.md @@ -191,14 +191,22 @@ export class DataShapeClassifier { if (Array.isArray(data)) { if (data.length === 0) return 'leaf_item'; + // Classify the whole sequence; a first-item guess can hide later content. + // Mixed scalars/mappings and nested sequences need structural rendering. + const allScalars = data.every(item => typeof item !== 'object' || item === null); + const allMappings = data.every(item => + typeof item === 'object' && item !== null && !Array.isArray(item) + ); + if (!allScalars && !allMappings) return 'block_group'; + // Sequence of Scalars - if (typeof data[0] !== 'object' || data[0] === null) { + if (allScalars) { const avgLength = data.reduce((acc, str) => acc + String(str).length, 0) / data.length; return avgLength <= 35 ? 'badge_list' : 'prose_flow'; } // Sequence of Mappings - const records = data.filter(item => typeof item === 'object' && item !== null); + const records = data; // allMappings: every original item participates const uniformity = this.calculateJaccardUniformity(records); if (uniformity >= 0.55) {