feat(replay): infer workflow phase from gate title so WorkflowBar lights the right dot

extract.mjs: inferPhase() maps gate titles ("F1 — …", "Fase 3 completata …") to F1..F8;
server.mjs: carries the inferred phase through the replayed ui_request stream.
This commit is contained in:
2026-07-06 23:29:49 +02:00
committed by Marco Pancotti
parent e9b2934ef7
commit 9403147c98
2 changed files with 73 additions and 14 deletions
+20 -1
View File
@@ -139,9 +139,28 @@ if (sessionCounts.size > 1) {
const answered = calls.filter((c) => resultsByCallId.has(c.callId));
// --- build descriptors (mirrors harness/.pi/extensions/gate/builders.js) ----
// Infer the workflow phase (F1..F8) of a gate from its title, so the frontend's
// WorkflowBar lights up the correct dot during replay. Patterns (from real
// session titles):
// "F1 — Chiarimento 1/3: …" → F1
// "Fase 3 completata — passo alla → F3 (the gate that CLOSES phase 3)
// Fase 4 (Schema linking)?"
// "F6 — CTE 2 approvato: …" → F6
// Returns null when no phase can be inferred (the frontend keeps the previous
// phase in that case, which is fine for transitional gates).
function inferPhase(title) {
if (typeof title !== "string") return null;
let m = title.match(/Fase\s+(\d+)\s+completata/i);
if (m) return `F${m[1]}`;
m = title.match(/\bF([1-8])\b/);
if (m) return `F${m[1]}`;
return null;
}
function buildDescriptor(name, args, idx) {
const id = `u${idx}`;
const phase = "replay";
const phase = inferPhase(args.title) ?? "replay";
if (name === "reviewer_select") {
const opts = parseOptions(args.options).filter((o) => !isReserved(o.label));
const recommendedId = parseOptions(args.options).find((o) => o.recommended)?.id ?? null;