167 lines
6.0 KiB
JavaScript
167 lines
6.0 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.readAgentSemanticSpecSummaryFromFile = readAgentSemanticSpecSummaryFromFile;
|
|
exports.findLatestAgentSemanticAcceptanceSummary = findLatestAgentSemanticAcceptanceSummary;
|
|
const fs_1 = __importDefault(require("fs"));
|
|
const path_1 = __importDefault(require("path"));
|
|
function toRecord(value) {
|
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
return null;
|
|
}
|
|
return value;
|
|
}
|
|
function toStringSafe(value) {
|
|
if (typeof value !== "string") {
|
|
return null;
|
|
}
|
|
const trimmed = value.trim();
|
|
return trimmed.length > 0 ? trimmed : null;
|
|
}
|
|
function toBooleanSafe(value) {
|
|
if (typeof value === "boolean") {
|
|
return value;
|
|
}
|
|
if (typeof value === "string") {
|
|
const lowered = value.trim().toLowerCase();
|
|
if (["1", "true", "yes", "on"].includes(lowered))
|
|
return true;
|
|
if (["0", "false", "no", "off"].includes(lowered))
|
|
return false;
|
|
}
|
|
return null;
|
|
}
|
|
function toNumberSafe(value) {
|
|
if (typeof value === "number" && Number.isFinite(value)) {
|
|
return value;
|
|
}
|
|
if (typeof value === "string" && value.trim().length > 0) {
|
|
const parsed = Number(value);
|
|
return Number.isFinite(parsed) ? parsed : null;
|
|
}
|
|
return null;
|
|
}
|
|
function readJsonFile(filePath) {
|
|
return JSON.parse(fs_1.default.readFileSync(filePath, "utf-8"));
|
|
}
|
|
function normalizeSemanticTags(rawSteps) {
|
|
if (!Array.isArray(rawSteps)) {
|
|
return [];
|
|
}
|
|
const tags = new Set();
|
|
for (const rawStep of rawSteps) {
|
|
const step = toRecord(rawStep);
|
|
if (!step || !Array.isArray(step.semantic_tags)) {
|
|
continue;
|
|
}
|
|
for (const rawTag of step.semantic_tags) {
|
|
const tag = toStringSafe(rawTag);
|
|
if (tag) {
|
|
tags.add(tag);
|
|
}
|
|
}
|
|
}
|
|
return Array.from(tags).sort((left, right) => left.localeCompare(right));
|
|
}
|
|
function readAgentSemanticSpecSummaryFromFile(sourceSpecFile) {
|
|
const normalizedPath = toStringSafe(sourceSpecFile);
|
|
if (!normalizedPath || !fs_1.default.existsSync(normalizedPath)) {
|
|
return null;
|
|
}
|
|
try {
|
|
const parsed = readJsonFile(normalizedPath);
|
|
const record = toRecord(parsed);
|
|
if (!record) {
|
|
return null;
|
|
}
|
|
const scenarioId = toStringSafe(record.scenario_id);
|
|
if (!scenarioId) {
|
|
return null;
|
|
}
|
|
const semanticTags = normalizeSemanticTags(record.steps);
|
|
return {
|
|
scenario_id: scenarioId,
|
|
domain: toStringSafe(record.domain),
|
|
title: toStringSafe(record.title),
|
|
semantic_tags: semanticTags,
|
|
steps_total: Array.isArray(record.steps) ? record.steps.length : 0
|
|
};
|
|
}
|
|
catch {
|
|
return null;
|
|
}
|
|
}
|
|
function buildInvariantSummary(rawValue) {
|
|
const record = toRecord(rawValue);
|
|
return {
|
|
direct_answer_ok: toBooleanSafe(record?.direct_answer_ok),
|
|
temporal_honesty_ok: toBooleanSafe(record?.temporal_honesty_ok),
|
|
selected_object_continuity_ok: toBooleanSafe(record?.selected_object_continuity_ok),
|
|
truth_gate_ok: toBooleanSafe(record?.truth_gate_ok),
|
|
human_answer_quality_ok: toBooleanSafe(record?.human_answer_quality_ok),
|
|
meta_context_integrity_ok: toBooleanSafe(record?.meta_context_integrity_ok)
|
|
};
|
|
}
|
|
function findLatestAgentSemanticAcceptanceSummary(input) {
|
|
const scenarioId = toStringSafe(input.scenarioId);
|
|
if (!scenarioId) {
|
|
return null;
|
|
}
|
|
if (!fs_1.default.existsSync(input.artifactsRootDir)) {
|
|
return null;
|
|
}
|
|
const candidates = fs_1.default
|
|
.readdirSync(input.artifactsRootDir, { withFileTypes: true })
|
|
.filter((entry) => entry.isDirectory() && entry.name.startsWith(`${scenarioId}_`))
|
|
.map((entry) => {
|
|
const outputDir = path_1.default.resolve(input.artifactsRootDir, entry.name);
|
|
const packStatePath = path_1.default.resolve(outputDir, "pack_state.json");
|
|
if (!fs_1.default.existsSync(packStatePath)) {
|
|
return null;
|
|
}
|
|
const stats = fs_1.default.statSync(packStatePath);
|
|
return {
|
|
outputDir,
|
|
packStatePath,
|
|
mtimeMs: stats.mtimeMs
|
|
};
|
|
})
|
|
.filter((item) => item !== null)
|
|
.sort((left, right) => right.mtimeMs - left.mtimeMs);
|
|
const latest = candidates[0];
|
|
if (!latest) {
|
|
return null;
|
|
}
|
|
try {
|
|
const parsed = readJsonFile(latest.packStatePath);
|
|
const packState = toRecord(parsed);
|
|
if (!packState) {
|
|
return null;
|
|
}
|
|
return {
|
|
scenario_id: scenarioId,
|
|
output_dir: latest.outputDir,
|
|
relative_output_dir: path_1.default.relative(input.repoRootDir, latest.outputDir).replace(/\\/g, "/"),
|
|
final_status: toStringSafe(packState.final_status),
|
|
final_status_reason: toStringSafe(packState.final_status_reason),
|
|
review_overall_status: toStringSafe(packState.review_overall_status),
|
|
acceptance_gate_passed: toBooleanSafe(packState.acceptance_gate_passed),
|
|
critical_path_green: toBooleanSafe(packState.critical_path_green),
|
|
unresolved_p0_count: toNumberSafe(packState.unresolved_p0_count),
|
|
unresolved_p1_count: toNumberSafe(packState.unresolved_p1_count),
|
|
unresolved_p2_count: toNumberSafe(packState.unresolved_p2_count),
|
|
steps_total: toNumberSafe(packState.steps_total),
|
|
steps_passed: toNumberSafe(packState.steps_passed),
|
|
steps_with_warning: toNumberSafe(packState.steps_with_warning),
|
|
steps_failed: toNumberSafe(packState.steps_failed),
|
|
updated_at: toStringSafe(packState.updated_at),
|
|
invariants: buildInvariantSummary(packState.invariants)
|
|
};
|
|
}
|
|
catch {
|
|
return null;
|
|
}
|
|
}
|