ГЛОБАЛЬНЫЙ РЕФАКТОРИНГ АРХИТЕКТУРЫ - Этап 4.5: добавлен аудит контракта Stage 4 в debug/log и закрыт расширенный quality-loop

This commit is contained in:
2026-04-12 01:24:46 +03:00
parent 88a7da4f0a
commit 963f0aa372
12 changed files with 176 additions and 2 deletions
@@ -1,6 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildDeepAnalysisDebugPayload = buildDeepAnalysisDebugPayload;
const assistantStage4AnswerContractAudit_1 = require("./assistantStage4AnswerContractAudit");
function toAnalysisContext(input) {
if (!input.active) {
return null;
@@ -15,6 +16,7 @@ function toAnalysisContext(input) {
}
function buildDeepAnalysisDebugPayload(input) {
const analysisContext = toAnalysisContext(input.runtimeAnalysisContext);
const answerContractStage4Audit = (0, assistantStage4AnswerContractAudit_1.buildStage4AnswerContractAuditV1)(input.assistantReply);
return {
trace_id: input.traceId,
prompt_version: input.promptVersion,
@@ -86,6 +88,7 @@ function buildDeepAnalysisDebugPayload(input) {
orchestration_contract_v1: input.addressRuntimeMetaForDeep?.orchestrationContract ?? null,
assistant_outcome_class_v1: input.outcomeClassV1,
assistant_orchestration_contracts_v1: input.assistantOrchestrationContractsV1,
answer_contract_stage4_v1: answerContractStage4Audit,
answer_structure_v11: input.answerStructureV11,
investigation_state_snapshot: input.investigationStateSnapshot,
normalized: input.normalizedPayload
@@ -81,6 +81,7 @@ function assembleAssistantDeepTurnPackaging(input) {
outcomeClassV1: contractsBundleV1.outcomeClassV1,
assistantOrchestrationContractsV1: contractsBundleV1.assistantOrchestrationContractsV1,
answerStructureV11: deepAnswerArtifacts.answerStructureV11,
assistantReply: deepAnswerArtifacts.safeAssistantReply,
investigationStateSnapshot: input.investigationStateSnapshot,
normalizedPayload: normalizedPayload
});
@@ -1,6 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildDeepAnalysisProcessedLogDetails = buildDeepAnalysisProcessedLogDetails;
const assistantStage4AnswerContractAudit_1 = require("./assistantStage4AnswerContractAudit");
function toAnalysisContext(input) {
if (!input.active) {
return null;
@@ -22,6 +23,7 @@ function resolveCoverageStatus(coverageReport) {
}
function buildDeepAnalysisProcessedLogDetails(input) {
const analysisContext = toAnalysisContext(input.runtimeAnalysisContext);
const answerContractStage4Audit = (0, assistantStage4AnswerContractAudit_1.buildStage4AnswerContractAuditV1)(input.assistantReply);
return {
session_id: input.sessionId,
message_id: input.messageId,
@@ -92,6 +94,7 @@ function buildDeepAnalysisProcessedLogDetails(input) {
: {}),
assistant_outcome_class_v1: input.outcomeClassV1,
assistant_orchestration_contracts_v1: input.assistantOrchestrationContractsV1,
answer_contract_stage4_v1: answerContractStage4Audit,
answer_structure_v11: input.answerStructureV11,
investigation_state_snapshot: input.investigationStateSnapshot,
fallback_type: input.compositionDebug.fallback_type,
@@ -0,0 +1,38 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildStage4AnswerContractAuditV1 = buildStage4AnswerContractAuditV1;
const STAGE4_EXPECTED_BLOCKS = [
"Коротко",
"Что именно проверено",
"Что найдено",
"Что пока не доказано"
];
const STAGE4_NEXT_STEP_BLOCKS = ["Что проверить первым", "Что могу сделать сейчас"];
const LEGACY_BLOCKS = [
"Что сломано",
"Почему это похоже на проблему",
"На чем это основано",
"Ограничения"
];
function hasBlock(reply, title) {
return reply.includes(`${title}:`);
}
function buildStage4AnswerContractAuditV1(assistantReply) {
const reply = String(assistantReply ?? "");
const expected = [...STAGE4_EXPECTED_BLOCKS, "Что проверить первым/Что могу сделать сейчас"];
const present = STAGE4_EXPECTED_BLOCKS.filter((title) => hasBlock(reply, title));
const hasPrimaryNextStep = STAGE4_NEXT_STEP_BLOCKS.some((title) => hasBlock(reply, title));
if (hasPrimaryNextStep) {
present.push("Что проверить первым/Что могу сделать сейчас");
}
const missing = expected.filter((title) => !present.includes(title));
const legacyPresent = LEGACY_BLOCKS.filter((title) => hasBlock(reply, title));
return {
schema_version: "stage4_answer_contract_audit_v1",
stage4_blocks_expected: expected,
stage4_blocks_present: present,
stage4_blocks_missing: missing,
legacy_blocks_present: legacyPresent,
is_stage4_shape: missing.length === 0 && legacyPresent.length === 0
};
}