ГЛОБАЛЬНЫЙ РЕФАКТОРИНГ АРХИТЕКТУРЫ - Рефакторинг этапов 3.1 - Добавлен строгий контракт семантического извлечения (валидность, качество, reason-codes, рекомендация применять canonical). Подключен semantic guard в predecompose/runtime: мягкое отклонение плохого canonical: отдельный safe-кейс для сырого полезного raw-фрагмента; fallback теперь выигрывает только когда это оправдано. Подключty semantic arbitration в tool-gate

This commit is contained in:
2026-04-11 16:45:43 +03:00
parent 66402439dc
commit a7ccc92a9c
18 changed files with 750 additions and 26 deletions
@@ -104,6 +104,7 @@ function normalizeLlmPreDecomposeMeta(value: unknown): AddressLlmPreDecomposeMet
const addressRetryAuditRaw = toRecordObject(source.addressRetryAudit);
const predecomposeContractRaw = toRecordObject(source.predecomposeContract);
const predecomposePeriodRaw = toRecordObject(predecomposeContractRaw?.period);
const semanticExtractionContractRaw = toRecordObject(source.semanticExtractionContract);
const normalized: AddressLlmPreDecomposeMetaLogInput = {};
@@ -170,6 +171,27 @@ function normalizeLlmPreDecomposeMeta(value: unknown): AddressLlmPreDecomposeMet
}
}
if (semanticExtractionContractRaw) {
const valid = toNullableBoolean(semanticExtractionContractRaw.valid);
const quality = toNullableString(semanticExtractionContractRaw.quality);
const applyCanonicalRecommended = toNullableBoolean(
semanticExtractionContractRaw.apply_canonical_recommended
);
const reasonCodes = Array.isArray(semanticExtractionContractRaw.reason_codes)
? semanticExtractionContractRaw.reason_codes
.map((item) => toNullableString(item))
.filter((item): item is string => Boolean(item))
: [];
if (valid !== undefined || quality || applyCanonicalRecommended !== undefined || reasonCodes.length > 0) {
normalized.semanticExtractionContract = {
valid: valid ?? null,
quality,
apply_canonical_recommended: applyCanonicalRecommended ?? null,
reason_codes: reasonCodes
};
}
}
const hasUsefulField = Object.values(normalized).some((item) => item !== undefined && item !== null);
return hasUsefulField ? normalized : null;
}