fix: prefer terminal markdown final response
This commit is contained in:
@@ -111,9 +111,10 @@ export async function runProbe(args) {
|
||||
await waitForMessageCards(page, args, actions);
|
||||
await page.screenshot({ path: screenshotPath, fullPage: true });
|
||||
const dom = await collectDomEvidence(page);
|
||||
const promptValidation = validatePromptFinalResponse(dom, args);
|
||||
result = {
|
||||
ok: true,
|
||||
status: dom.requiredSelectors.workspace && dom.requiredSelectors.commandInput && dom.requiredSelectors.conversationList ? "pass" : "blocked",
|
||||
status: dom.requiredSelectors.workspace && dom.requiredSelectors.commandInput && dom.requiredSelectors.conversationList && promptValidation.ok ? "pass" : "blocked",
|
||||
command: "web-live-dom-probe run",
|
||||
generatedAt: new Date().toISOString(),
|
||||
startedAt,
|
||||
@@ -123,6 +124,7 @@ export async function runProbe(args) {
|
||||
browser: browser.hwlabLaunchPlan ?? null,
|
||||
actions,
|
||||
dom,
|
||||
promptValidation,
|
||||
artifacts: { reportPath, screenshotPath },
|
||||
safety: {
|
||||
repoOwnedLauncher: true,
|
||||
@@ -155,6 +157,32 @@ export async function runProbe(args) {
|
||||
return result;
|
||||
}
|
||||
|
||||
function validatePromptFinalResponse(dom, args) {
|
||||
if (!args.message) return { ok: true, applicable: false, reason: "no-prompt-submitted" };
|
||||
const messages = Array.isArray(dom.messages) ? dom.messages : [];
|
||||
const latestAgent = [...messages].reverse().find((message) => message.role === "agent");
|
||||
const finalResponse = latestAgent?.finalResponse ?? null;
|
||||
const markdown = finalResponse?.markdown ?? null;
|
||||
const failures = [];
|
||||
if (!latestAgent) failures.push("agent-message-missing");
|
||||
if (latestAgent?.status !== "completed") failures.push("agent-not-completed");
|
||||
if (finalResponse?.present !== true) failures.push("final-response-missing");
|
||||
if (!finalResponse || Number(finalResponse.textChars ?? 0) <= 0) failures.push("final-response-empty");
|
||||
if (Number(markdown?.headings ?? 0) <= 0) failures.push("markdown-heading-missing");
|
||||
if (Number(markdown?.lists ?? 0) <= 0 || Number(markdown?.listItems ?? 0) <= 0) failures.push("markdown-list-missing");
|
||||
if (Number(markdown?.codeBlocks ?? 0) <= 0) failures.push("markdown-code-block-missing");
|
||||
return {
|
||||
ok: failures.length === 0,
|
||||
applicable: true,
|
||||
failures,
|
||||
finalResponse: finalResponse ? {
|
||||
textChars: finalResponse.textChars ?? null,
|
||||
textPreview: finalResponse.textPreview ?? null,
|
||||
markdown: finalResponse.markdown ?? null
|
||||
} : null
|
||||
};
|
||||
}
|
||||
|
||||
async function startProbe(args) {
|
||||
await mkdir(stateRoot, { recursive: true });
|
||||
const jobId = args.jobId || `web-live-dom-probe-${Date.now()}-${process.pid}`;
|
||||
|
||||
Reference in New Issue
Block a user