@riddledc/riddle-proof 0.7.183 → 0.7.185

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.cjs CHANGED
@@ -7446,8 +7446,9 @@ function profileSetupWindowCallReceipts(results) {
7446
7446
  path: result.path ?? null,
7447
7447
  return_captured: result.return_captured ?? null,
7448
7448
  return_stored_to: result.return_stored_to ?? null,
7449
- reason: result.reason ?? result.error ?? result.store_reason ?? null
7449
+ reason: result.reason ?? result.store_reason ?? null
7450
7450
  };
7451
+ if (result.error !== void 0) receipt.error = result.error;
7451
7452
  if (result.returned !== void 0) receipt.returned = result.returned;
7452
7453
  if (result.expected_return !== void 0) receipt.expected_return = result.expected_return;
7453
7454
  const returnSummary = profileSetupReturnSummary(result);
@@ -7463,8 +7464,9 @@ function profileSetupWindowEvalReceipts(results) {
7463
7464
  script_length: result.script_length ?? null,
7464
7465
  return_captured: result.return_captured ?? null,
7465
7466
  return_stored_to: result.return_stored_to ?? null,
7466
- reason: result.reason ?? result.error ?? result.store_reason ?? null
7467
+ reason: result.reason ?? result.store_reason ?? null
7467
7468
  };
7469
+ if (result.error !== void 0) receipt.error = result.error;
7468
7470
  if (result.returned !== void 0) receipt.returned = result.returned;
7469
7471
  if (result.expected_return !== void 0) receipt.expected_return = result.expected_return;
7470
7472
  const returnSummary = profileSetupReturnSummary(result);
@@ -7829,6 +7831,7 @@ function profileSetupSummary(viewports, actionCount, expectedActionCountByViewpo
7829
7831
  selector: result.selector ?? null,
7830
7832
  frame_selector: result.frame_selector ?? null,
7831
7833
  reason: result.reason ?? result.error ?? null,
7834
+ error: result.error ?? null,
7832
7835
  case_insensitive_text: compactProfileSetupSummaryText(result.case_insensitive_text)
7833
7836
  })),
7834
7837
  optional_failed: optionalFailed.map((result) => ({
@@ -7837,6 +7840,7 @@ function profileSetupSummary(viewports, actionCount, expectedActionCountByViewpo
7837
7840
  selector: result.selector ?? null,
7838
7841
  frame_selector: result.frame_selector ?? null,
7839
7842
  reason: result.reason ?? result.error ?? null,
7843
+ error: result.error ?? null,
7840
7844
  case_insensitive_text: compactProfileSetupSummaryText(result.case_insensitive_text)
7841
7845
  }))
7842
7846
  };
@@ -10417,6 +10421,7 @@ function assessRiddleProofProfileEvidence(profile, evidence, options = {}) {
10417
10421
  checks,
10418
10422
  summary: summarizeRiddleProofProfileResult({ profile_name: profile.name, status, checks, viewports: evidence?.viewports || [] }),
10419
10423
  captured_at: capturedAt,
10424
+ metadata: profile.metadata,
10420
10425
  warnings: warnings.length ? warnings : void 0,
10421
10426
  evidence,
10422
10427
  riddle: options.riddle
@@ -10462,6 +10467,7 @@ function createRiddleProofProfileEnvironmentBlockedResult(input) {
10462
10467
  checks: [],
10463
10468
  summary: summarizeEnvironmentBlockedRunner(input.profile.name, environmentBlocker),
10464
10469
  captured_at: (/* @__PURE__ */ new Date()).toISOString(),
10470
+ metadata: input.profile.metadata,
10465
10471
  warnings: warnings.length ? warnings : void 0,
10466
10472
  riddle: input.riddle,
10467
10473
  environment_blocker: environmentBlocker,
@@ -10538,6 +10544,7 @@ function createRiddleProofProfileInsufficientResult(input) {
10538
10544
  checks: [],
10539
10545
  summary: `${input.profile.name} did not produce enough evidence for a profile judgment.`,
10540
10546
  captured_at: (/* @__PURE__ */ new Date()).toISOString(),
10547
+ metadata: input.profile.metadata,
10541
10548
  warnings: warnings.length ? warnings : void 0,
10542
10549
  riddle: input.riddle,
10543
10550
  error: message
@@ -11304,8 +11311,9 @@ function profileSetupWindowCallReceipts(results) {
11304
11311
  path: result.path ?? null,
11305
11312
  return_captured: result.return_captured ?? null,
11306
11313
  return_stored_to: result.return_stored_to ?? null,
11307
- reason: result.reason || result.error || result.store_reason || null,
11314
+ reason: result.reason || result.store_reason || null,
11308
11315
  };
11316
+ if (result.error !== undefined) receipt.error = result.error;
11309
11317
  if (result.returned !== undefined) receipt.returned = result.returned;
11310
11318
  if (result.expected_return !== undefined) receipt.expected_return = result.expected_return;
11311
11319
  const returnSummary = profileSetupReturnSummary(result);
@@ -11323,8 +11331,9 @@ function profileSetupWindowEvalReceipts(results) {
11323
11331
  script_length: result.script_length ?? null,
11324
11332
  return_captured: result.return_captured ?? null,
11325
11333
  return_stored_to: result.return_stored_to ?? null,
11326
- reason: result.reason || result.error || result.store_reason || null,
11334
+ reason: result.reason || result.store_reason || null,
11327
11335
  };
11336
+ if (result.error !== undefined) receipt.error = result.error;
11328
11337
  if (result.returned !== undefined) receipt.returned = result.returned;
11329
11338
  if (result.expected_return !== undefined) receipt.expected_return = result.expected_return;
11330
11339
  const returnSummary = profileSetupReturnSummary(result);
@@ -11734,6 +11743,7 @@ function profileSetupSummary(viewports, actionCount, expectedActionCountsByViewp
11734
11743
  selector: result.selector ?? null,
11735
11744
  frame_selector: result.frame_selector ?? null,
11736
11745
  reason: result.reason || result.error || null,
11746
+ error: result.error || null,
11737
11747
  case_insensitive_text: compactProfileSetupSummaryText(result.case_insensitive_text),
11738
11748
  })),
11739
11749
  optional_failed: optionalFailed.map((result) => ({
@@ -11742,6 +11752,7 @@ function profileSetupSummary(viewports, actionCount, expectedActionCountsByViewp
11742
11752
  selector: result.selector ?? null,
11743
11753
  frame_selector: result.frame_selector ?? null,
11744
11754
  reason: result.reason || result.error || null,
11755
+ error: result.error || null,
11745
11756
  case_insensitive_text: compactProfileSetupSummaryText(result.case_insensitive_text),
11746
11757
  })),
11747
11758
  };
@@ -12464,6 +12475,7 @@ function assessProfile(profile, evidence) {
12464
12475
  checks,
12465
12476
  summary,
12466
12477
  captured_at: evidence.captured_at,
12478
+ metadata: profile.metadata,
12467
12479
  warnings: profileWarnings.length ? profileWarnings : undefined,
12468
12480
  evidence,
12469
12481
  };
@@ -16179,6 +16191,10 @@ function profileResultMarkdown(result) {
16179
16191
  if (result.warnings.length > 12) lines.push(`- ${result.warnings.length - 12} additional warning(s) omitted.`);
16180
16192
  lines.push("");
16181
16193
  }
16194
+ const packMetadataLines = profilePackMetadataMarkdown(result);
16195
+ if (packMetadataLines.length) {
16196
+ lines.push("## Proof Pack", "", ...packMetadataLines, "");
16197
+ }
16182
16198
  lines.push("## Checks", "");
16183
16199
  for (const check of result.checks) {
16184
16200
  lines.push(`- ${check.status}: ${profileCheckMarkdownLabel(check)}`);
@@ -16188,6 +16204,18 @@ function profileResultMarkdown(result) {
16188
16204
  if (setupSummaryLines.length) {
16189
16205
  lines.push("", "## Setup Summary", "", ...setupSummaryLines);
16190
16206
  }
16207
+ const reachabilitySummaryLines = profileReachabilitySummaryMarkdown(result);
16208
+ if (reachabilitySummaryLines.length) {
16209
+ lines.push("", "## Reachability", "", ...reachabilitySummaryLines);
16210
+ }
16211
+ const stateContractSummaryLines = profileStateContractSummaryMarkdown(result);
16212
+ if (stateContractSummaryLines.length) {
16213
+ lines.push("", "## State Contract", "", ...stateContractSummaryLines);
16214
+ }
16215
+ const sideCaveatSummaryLines = profileSideCaveatSummaryMarkdown(result);
16216
+ if (sideCaveatSummaryLines.length) {
16217
+ lines.push("", "## Side Caveats", "", ...sideCaveatSummaryLines);
16218
+ }
16191
16219
  const networkMockSummaryLines = profileNetworkMockSummaryMarkdown(result);
16192
16220
  if (networkMockSummaryLines.length) {
16193
16221
  lines.push("", "## Network Mocks", "", ...networkMockSummaryLines);
@@ -16286,6 +16314,249 @@ function profileRiddleJobMarkdown(result) {
16286
16314
  if (splitJobs.length > 12) lines.push(`- ${splitJobs.length - 12} additional split job(s) omitted.`);
16287
16315
  return lines;
16288
16316
  }
16317
+ function profileMetadataStringArray(value) {
16318
+ return Array.isArray(value) ? value.map((item) => typeof item === "string" ? item.trim() : "").filter((item) => Boolean(item)) : [];
16319
+ }
16320
+ function profileSetupSummaryRecord(result) {
16321
+ const setupCheck = result.checks.find((check) => check.type === "setup_actions_succeeded");
16322
+ return cliRecord(setupCheck?.evidence?.setup_summary);
16323
+ }
16324
+ function profileSetupSummaryViewports(result) {
16325
+ const setupSummary = profileSetupSummaryRecord(result);
16326
+ return Array.isArray(setupSummary?.viewports) ? setupSummary.viewports.map(cliRecord).filter((viewport) => Boolean(viewport)) : [];
16327
+ }
16328
+ function profileHasPassedCheck(result, types) {
16329
+ return result.checks.some((check) => types.includes(check.type) && check.status === "passed");
16330
+ }
16331
+ function profileHasCheck(result, types) {
16332
+ return result.checks.some((check) => types.includes(check.type));
16333
+ }
16334
+ function profileSetupScreenshotCount(viewports) {
16335
+ return viewports.reduce((sum, viewport) => {
16336
+ const setupScreenshots = Array.isArray(viewport.setup_screenshots) ? viewport.setup_screenshots.filter((label) => typeof label === "string" && label.trim()).length : 0;
16337
+ const finalScreenshot = cliString(viewport.final_screenshot) || cliString(viewport.screenshot_label) ? 1 : 0;
16338
+ return sum + setupScreenshots + finalScreenshot;
16339
+ }, 0);
16340
+ }
16341
+ function profileSetupReceiptTotal(viewports, key) {
16342
+ return viewports.reduce((sum, viewport) => sum + setupReceiptArray(viewport, key).filter((receipt) => receipt.ok !== false).length, 0);
16343
+ }
16344
+ function profileSetupFailureCount(viewports) {
16345
+ return viewports.reduce((sum, viewport) => {
16346
+ const failed = Array.isArray(viewport.failed) ? viewport.failed : [];
16347
+ return sum + failed.filter((failure) => Boolean(cliRecord(failure))).length;
16348
+ }, 0);
16349
+ }
16350
+ function profileSetupObstructionCount(viewports) {
16351
+ return viewports.reduce((sum, viewport) => {
16352
+ const failed = Array.isArray(viewport.failed) ? viewport.failed.map(cliRecord).filter((failure) => Boolean(failure)) : [];
16353
+ return sum + failed.filter((failure) => Boolean(setupFailureObstructionSnippet(cliString(failure.reason)))).length;
16354
+ }, 0);
16355
+ }
16356
+ function profileResultHasArtifact(result) {
16357
+ return Boolean(
16358
+ result.artifacts.proof_json || result.artifacts.console || result.artifacts.dom_summary || result.artifacts.screenshots?.length || result.artifacts.riddle_artifacts?.some((artifact) => artifact.url || artifact.path || artifact.name)
16359
+ );
16360
+ }
16361
+ function profileReceiptSignalStatus(hasSignal, presentReason, missingReason) {
16362
+ return hasSignal ? { status: "present", reason: presentReason } : { status: "missing", reason: missingReason };
16363
+ }
16364
+ function compactProfileReceiptReason(value, limit = 180) {
16365
+ const text = cliString(value)?.replace(/\s+/g, " ").trim();
16366
+ if (!text) return void 0;
16367
+ return text.length <= limit ? text : `${text.slice(0, Math.max(0, limit - 3)).trimEnd()}...`;
16368
+ }
16369
+ function profileFailedCleanupInventoryReason(setupViewports) {
16370
+ const receipts = setupViewports.flatMap((viewport) => [
16371
+ ...setupReceiptArray(viewport, "window_eval"),
16372
+ ...setupReceiptArray(viewport, "window_call")
16373
+ ]);
16374
+ for (const receipt of receipts) {
16375
+ if (receipt.ok !== false) continue;
16376
+ const returnStoredTo = cliString(receipt.return_stored_to) || "";
16377
+ const reason = cliString(receipt.reason) || "";
16378
+ const error = cliString(receipt.error) || "";
16379
+ const summary = cliReturnSummaryLabel(receipt.return_summary) || "";
16380
+ const haystack = `${returnStoredTo} ${reason} ${error} ${summary}`.toLowerCase();
16381
+ const isCleanupReceipt = haystack.includes("cleanup") || haystack.includes("post-cleanup") || haystack.includes("stale") || haystack.includes("statehygiene") || haystack.includes("state hygiene") || haystack.includes("remained after") || haystack.includes("still present");
16382
+ if (!isCleanupReceipt) continue;
16383
+ return compactProfileReceiptReason(error) || compactProfileReceiptReason(reason) || "cleanup inventory failed";
16384
+ }
16385
+ return void 0;
16386
+ }
16387
+ function profilePackReceiptStatus(result, metadata, receipt) {
16388
+ const text = receipt.toLowerCase();
16389
+ const setupSummary = profileSetupSummaryRecord(result);
16390
+ const setupViewports = profileSetupSummaryViewports(result);
16391
+ const evidenceViewports = Array.isArray(result.evidence?.viewports) ? result.evidence.viewports : [];
16392
+ const setupResultCount = setupViewports.reduce((sum, viewport) => sum + (cliFiniteNumber(viewport.result_count) || 0), 0);
16393
+ const setupScreenshotCount = profileSetupScreenshotCount(setupViewports);
16394
+ const screenshotCount = (result.artifacts.screenshots?.length || 0) + evidenceViewports.filter((viewport) => cliString(viewport.screenshot_label)).length + setupScreenshotCount;
16395
+ const windowEvalCount = profileSetupReceiptTotal(setupViewports, "window_eval");
16396
+ const valueReceipts = [
16397
+ ...setupViewports.flatMap((viewport) => setupReceiptArray(viewport, "window_eval")),
16398
+ ...setupViewports.flatMap((viewport) => setupReceiptArray(viewport, "window_call"))
16399
+ ].filter((item) => item.ok !== false);
16400
+ const clickCount = setupViewports.reduce((sum, viewport) => sum + (cliFiniteNumber(viewport.clicked_total) || 0), 0) + profileSetupReceiptTotal(setupViewports, "click") + profileSetupReceiptTotal(setupViewports, "click_count");
16401
+ const setupFailureCount = profileSetupFailureCount(setupViewports);
16402
+ const setupObstructionCount = profileSetupObstructionCount(setupViewports);
16403
+ const inputDispatchCount = profileSetupReceiptTotal(setupViewports, "drag") + profileSetupReceiptTotal(setupViewports, "tap") + profileSetupReceiptTotal(setupViewports, "press") + profileSetupReceiptTotal(setupViewports, "keyboard_sequence");
16404
+ const canvasReceipts = setupViewports.flatMap((viewport) => setupReceiptArray(viewport, "canvas_signature"));
16405
+ const hasCanvasChange = canvasReceipts.some((item) => item.ok !== false && item.changed === true);
16406
+ const canvasSignatureHashes = canvasReceipts.filter((item) => item.ok !== false).map((item) => cliString(item.hash)).filter(Boolean);
16407
+ const hasCanvasSignatureChange = hasCanvasChange || new Set(canvasSignatureHashes).size >= 2;
16408
+ const hasNaturalInput = setupNaturalInputSummaryMarkdown(setupViewports).length > 0;
16409
+ const hasStateContract = profileStateContractSummaryMarkdown(result).length > 0 || Boolean(cliRecord(metadata.declared_state_contract));
16410
+ const hasInvalidStateReceipt = valueReceipts.some((item) => {
16411
+ const state = setupReturnSummaryValue(item, ["state", "nextState"]);
16412
+ return typeof state === "string" && state.toLowerCase().includes("invalid");
16413
+ });
16414
+ const hasErrorDetailReceipt = valueReceipts.some((item) => setupReturnSummaryValue(item, ["hasErrorDetail", "errorDetail", "error_detail"]) === true);
16415
+ const hasGridEvidence = valueReceipts.some((item) => setupReturnSummaryValue(item, ["itemCount", "grid.width", "gridWidth", "visibleGridCount"]) !== void 0);
16416
+ const hasVisibleControlReceipt = valueReceipts.some((item) => setupReturnSummaryValue(item, ["visibleButtonCount", "visibleControlCount"]) !== void 0 || setupReturnSummaryValue(item, ["buttonStillVisible", "controlStillVisible"]) === true);
16417
+ const hasToolSelectionReceipt = valueReceipts.some((item) => setupReturnSummaryValue(item, ["rectangleChecked", "toolSelected", "toolChecked", "selected"]) === true);
16418
+ const hasStateGrowthReceipt = valueReceipts.some((item) => {
16419
+ const delta = cliFiniteNumber(setupReturnSummaryValue(item, ["delta", "countDelta", "itemDelta", "stateDelta"]));
16420
+ if (delta !== void 0 && delta > 0) return true;
16421
+ const before = cliFiniteNumber(setupReturnSummaryValue(item, ["before", "beforeCount", "previousCount"]));
16422
+ const after = cliFiniteNumber(setupReturnSummaryValue(item, ["after", "afterCount", "itemCount", "count"]));
16423
+ return before !== void 0 && after !== void 0 && after > before;
16424
+ });
16425
+ const hasReachability = profileReachabilitySummaryMarkdown(result).length > 0 || result.checks.some((check) => check.type === "selector_visible" && Boolean(cliRecord(check.evidence)?.selector));
16426
+ const hasOverflowEvidence = result.checks.some((check) => check.type === "no_horizontal_overflow" || check.type === "no_mobile_horizontal_overflow" || check.type === "frame_no_horizontal_overflow") || evidenceViewports.some((viewport) => (cliFiniteNumber(viewport.overflow_px) || 0) > 0 || (cliFiniteNumber(viewport.bounds_overflow_px) || 0) > 0 || Boolean(viewport.overflow_offenders?.length));
16427
+ const hasConsoleAccounting = profileHasCheck(result, ["no_console_warnings", "no_fatal_console_errors"]) || Boolean(result.evidence?.console || result.evidence?.page_errors);
16428
+ const hasDomSummary = Boolean(result.artifacts.dom_summary || result.evidence?.dom_summary);
16429
+ const hasProofJson = Boolean(result.artifacts.proof_json || result.version === "riddle-proof.profile-result.v1");
16430
+ const hasRouteViewport = Boolean(result.route?.requested || result.route?.observed) && Boolean(evidenceViewports.length || result.route?.matched !== void 0);
16431
+ const hasSetupReceipts = setupResultCount > 0 || Boolean(setupSummary);
16432
+ const hasTextVisibility = profileHasPassedCheck(result, ["text_visible", "selector_text_visible", "selector_visible"]);
16433
+ const hasTextAbsence = profileHasPassedCheck(result, ["text_absent", "selector_text_absent"]);
16434
+ const hasMeasuredStateChange = hasNaturalInput || hasCanvasChange || valueReceipts.some((item) => setupReturnSummaryValue(item, ["changed"]) === true || setupReturnSummaryValue(item, ["nonWhiteDelta", "darkDelta", "pixelDelta", "movementDelta"]) !== void 0);
16435
+ const failedCleanupInventoryReason = profileFailedCleanupInventoryReason(setupViewports);
16436
+ if (text.includes("artifact link") || text.includes("artifact path")) {
16437
+ return profileReceiptSignalStatus(profileResultHasArtifact(result), "artifact references listed", "no artifact references found");
16438
+ }
16439
+ if (text.includes("proof json")) return profileReceiptSignalStatus(hasProofJson, "proof JSON artifact named", "proof JSON artifact missing");
16440
+ if (text.includes("dom summary")) return profileReceiptSignalStatus(hasDomSummary, "DOM summary evidence present", "DOM summary evidence missing");
16441
+ if (text.includes("console") || text.includes("warning") || text.includes("fatal") || text.includes("browser warning") || text.includes("graphics")) {
16442
+ return profileReceiptSignalStatus(hasConsoleAccounting, "console checks or evidence present", "console accounting evidence missing");
16443
+ }
16444
+ if (text.includes("route") && text.includes("viewport")) {
16445
+ return profileReceiptSignalStatus(hasRouteViewport, "route and viewport evidence present", "route or viewport evidence missing");
16446
+ }
16447
+ if (text.includes("setup action")) {
16448
+ return profileReceiptSignalStatus(hasSetupReceipts, "setup receipts present", "setup receipts missing");
16449
+ }
16450
+ if (text.includes("declared state contract")) {
16451
+ return profileReceiptSignalStatus(hasStateContract, "state contract metadata or receipts present", "state contract evidence missing");
16452
+ }
16453
+ if (text.includes("stale") || text.includes("absence")) {
16454
+ if (failedCleanupInventoryReason && (text.includes("cleanup") || text.includes("post-cleanup") || text.includes("stale-state") || text.includes("stale state"))) {
16455
+ return { status: "failed", reason: `cleanup inventory failed: ${failedCleanupInventoryReason}` };
16456
+ }
16457
+ return profileReceiptSignalStatus(hasTextAbsence, "absence check passed", "absence check missing");
16458
+ }
16459
+ if (text.includes("recovered") || text.includes("final state")) {
16460
+ return profileReceiptSignalStatus(hasStateContract || hasTextVisibility, "final state receipt present", "final state receipt missing");
16461
+ }
16462
+ if (text.includes("error detail")) {
16463
+ const hasRequiredState = !text.includes("invalid") || hasInvalidStateReceipt;
16464
+ return profileReceiptSignalStatus(
16465
+ hasRequiredState && hasErrorDetailReceipt,
16466
+ "error-detail state receipt present",
16467
+ "error-detail state receipt missing"
16468
+ );
16469
+ }
16470
+ if (text.includes("invalid state")) {
16471
+ return profileReceiptSignalStatus(hasStateContract || hasInvalidStateReceipt, "invalid-state receipt present", "invalid-state receipt missing");
16472
+ }
16473
+ if (text.includes("retry") || text.includes("repair") || text.includes("reset") || text.includes("affordance")) {
16474
+ return profileReceiptSignalStatus(hasStateContract || clickCount > 0, "affordance or transition receipt present", "affordance receipt missing");
16475
+ }
16476
+ if (text.includes("failure") || text.includes("mutation")) {
16477
+ return profileReceiptSignalStatus(hasStateContract || windowEvalCount > 0 || clickCount > 0, "failure or mutation receipt present", "failure or mutation receipt missing");
16478
+ }
16479
+ if (text.includes("initial") && (text.includes("visible") || text.includes("state"))) {
16480
+ return profileReceiptSignalStatus(hasTextVisibility || screenshotCount > 0, "initial visible-state evidence present", "initial state evidence missing");
16481
+ }
16482
+ if (text.includes("state-growth") || text.includes("state growth") || text.includes("growth receipt") || text.includes("grid grows") || text.includes("state") && text.includes("after the click")) {
16483
+ return profileReceiptSignalStatus(hasStateGrowthReceipt, "state-growth receipt present", "state-growth receipt missing");
16484
+ }
16485
+ if (text.includes("visible grid") || text.includes("control evidence") || text.includes("grid") && text.includes("control")) {
16486
+ return profileReceiptSignalStatus(
16487
+ hasGridEvidence && (hasVisibleControlReceipt || hasReachability),
16488
+ "visible grid/control evidence present",
16489
+ "visible grid/control evidence missing"
16490
+ );
16491
+ }
16492
+ if (text.includes("tool") && text.includes("selected") || text.includes("rectangle tool")) {
16493
+ return profileReceiptSignalStatus(hasToolSelectionReceipt, "tool-selection receipt present", "tool-selection receipt missing");
16494
+ }
16495
+ if (text.includes("canvas signature")) {
16496
+ return profileReceiptSignalStatus(hasCanvasSignatureChange, "canvas signature change evidence present", "canvas signature evidence missing");
16497
+ }
16498
+ if (text.includes("selector count") || text.includes("visible count") || text.includes("control visibility") || text.includes("reachability gate") || text.includes("visible control")) {
16499
+ return profileReceiptSignalStatus(hasReachability, "selector visibility or reachability evidence present", "reachability evidence missing");
16500
+ }
16501
+ if (text.includes("overflow") || text.includes("clipped") || text.includes("fit")) {
16502
+ return profileReceiptSignalStatus(hasOverflowEvidence, "overflow evidence present", "overflow evidence missing");
16503
+ }
16504
+ if (text.includes("click receipt") || text.includes("obstruction receipt") || text.includes("state mutation")) {
16505
+ return profileReceiptSignalStatus(clickCount > 0 || setupObstructionCount > 0, "click or obstruction receipt present", "click or obstruction receipt missing");
16506
+ }
16507
+ if (text.includes("target selector") || text.includes("target selector/text")) {
16508
+ return profileReceiptSignalStatus(hasReachability || hasTextVisibility, "selector or text check evidence present", "selector/text evidence missing");
16509
+ }
16510
+ if (text.includes("intercepting element")) {
16511
+ if (setupObstructionCount > 0) return { status: "present", reason: "obstruction receipt present" };
16512
+ return setupFailureCount > 0 ? { status: "missing", reason: "setup failed without intercepting element evidence" } : { status: "manual", reason: "only applies when blocked" };
16513
+ }
16514
+ if (text.includes("before and after state")) {
16515
+ return profileReceiptSignalStatus(
16516
+ hasStateContract || valueReceipts.length >= 2 || screenshotCount >= 2,
16517
+ "before/after state evidence present",
16518
+ "before/after state evidence missing"
16519
+ );
16520
+ }
16521
+ if (text.includes("screenshot")) {
16522
+ const needsBoundaryScreenshots = text.includes("each") || text.includes("before and after") || text.includes("state boundary");
16523
+ return profileReceiptSignalStatus(
16524
+ needsBoundaryScreenshots ? screenshotCount >= 2 : screenshotCount > 0,
16525
+ needsBoundaryScreenshots ? "multiple screenshots present" : "screenshot evidence present",
16526
+ needsBoundaryScreenshots ? "multiple screenshots missing" : "screenshot evidence missing"
16527
+ );
16528
+ }
16529
+ if (text.includes("input dispatch") || text.includes("pointer") || text.includes("touch") || text.includes("key event") || text.includes("trusted-event")) {
16530
+ return profileReceiptSignalStatus(inputDispatchCount > 0 || hasNaturalInput, "input dispatch evidence present", "input dispatch evidence missing");
16531
+ }
16532
+ if (text.includes("measured") || text.includes("state-change") || text.includes("pixel delta") || text.includes("movement receipt") || text.includes("canvas hash")) {
16533
+ return profileReceiptSignalStatus(hasMeasuredStateChange, "measured-change evidence present", "measured-change evidence missing");
16534
+ }
16535
+ return { status: "manual", reason: "semantic receipt requires audit review" };
16536
+ }
16537
+ function profilePackMetadataMarkdown(result) {
16538
+ const metadata = cliRecord(result.metadata);
16539
+ if (!metadata) return [];
16540
+ const packId = cliString(metadata.pack_id);
16541
+ const packPublicName = cliString(metadata.pack_public_name);
16542
+ const requiredReceipts = profileMetadataStringArray(metadata.required_receipts);
16543
+ if (!packId && !packPublicName && !requiredReceipts.length) return [];
16544
+ const lines = [];
16545
+ const packParts = [
16546
+ packId ? markdownInlineCode(packId) : "",
16547
+ packPublicName ? packPublicName : ""
16548
+ ].filter(Boolean);
16549
+ if (packParts.length) lines.push(`- pack: ${packParts.join(" - ")}`);
16550
+ if (requiredReceipts.length) {
16551
+ lines.push(`- required receipts: ${requiredReceipts.length}`);
16552
+ for (const receipt of requiredReceipts.slice(0, 20)) {
16553
+ const item = profilePackReceiptStatus(result, metadata, receipt);
16554
+ lines.push(` - ${item.status}: ${receipt} (${item.reason})`);
16555
+ }
16556
+ if (requiredReceipts.length > 20) lines.push(` - ${requiredReceipts.length - 20} additional required receipt(s) omitted.`);
16557
+ }
16558
+ return lines;
16559
+ }
16289
16560
  function markdownInlineCode(value, maxLength = 80) {
16290
16561
  const normalized = value.replace(/\s+/g, " ").trim();
16291
16562
  const clipped = normalized.length > maxLength ? `${normalized.slice(0, Math.max(0, maxLength - 3))}...` : normalized;
@@ -16547,6 +16818,221 @@ function setupNaturalInputSummaryMarkdown(viewports) {
16547
16818
  }
16548
16819
  return lines;
16549
16820
  }
16821
+ function reachabilityFailureReason(reason) {
16822
+ if (!reason) return void 0;
16823
+ const noVisibleMatch = /No visible match for selector [\s\S]*?:\s*([^\n]+)/.exec(reason);
16824
+ if (noVisibleMatch?.[1]) return noVisibleMatch[1].trim().slice(0, 120);
16825
+ if (/no_visible_match/.test(reason)) return "no_visible_match";
16826
+ if (/not visible/i.test(reason)) return "not_visible";
16827
+ return void 0;
16828
+ }
16829
+ function viewportTopBoundsOverflowPx(viewport) {
16830
+ const direct = cliFiniteNumber(viewport.bounds_overflow_px);
16831
+ if (direct !== void 0 && direct > 0) return direct;
16832
+ const offenders = Array.isArray(viewport.overflow_offenders) ? viewport.overflow_offenders.map(cliRecord).filter((item) => Boolean(item)) : [];
16833
+ for (const offender of offenders) {
16834
+ const overflow = cliFiniteNumber(offender.bounds_overflow_px) ?? cliFiniteNumber(offender.overflow_px) ?? cliFiniteNumber(offender.overflow);
16835
+ if (overflow !== void 0 && overflow > 0) return overflow;
16836
+ }
16837
+ const scrollOverflow = cliFiniteNumber(viewport.overflow_px);
16838
+ return scrollOverflow !== void 0 && scrollOverflow > 0 ? scrollOverflow : void 0;
16839
+ }
16840
+ function profileReachabilitySummaryMarkdown(result) {
16841
+ const evidenceViewports = Array.isArray(result.evidence?.viewports) ? result.evidence.viewports.map((viewport) => cliRecord(viewport)).filter((viewport) => Boolean(viewport)) : [];
16842
+ if (!evidenceViewports.length) return [];
16843
+ const evidenceByName = /* @__PURE__ */ new Map();
16844
+ for (const viewport of evidenceViewports) {
16845
+ const name = cliString(viewport.name);
16846
+ if (name) evidenceByName.set(name, viewport);
16847
+ }
16848
+ const receipts = [];
16849
+ const seen = /* @__PURE__ */ new Set();
16850
+ const addReceipt = (viewportName, selector, reason) => {
16851
+ const viewport = evidenceByName.get(viewportName);
16852
+ if (!viewport) return;
16853
+ const selectors = cliRecord(viewport.selectors);
16854
+ const selectorEvidence = cliRecord(selectors?.[selector]);
16855
+ const count = cliFiniteNumber(selectorEvidence?.count);
16856
+ const visibleCount = cliFiniteNumber(selectorEvidence?.visible_count);
16857
+ if (count === void 0 || count <= 0 || visibleCount === void 0 || visibleCount > 0) return;
16858
+ const key = `${viewportName}\0${selector}`;
16859
+ if (seen.has(key)) return;
16860
+ seen.add(key);
16861
+ const reasonText = reason || "no_visible_match";
16862
+ const boundsOverflow = viewportTopBoundsOverflowPx(viewport);
16863
+ receipts.push(`- reachability ${viewportName}: ${markdownInlineCode(selector, 120)} exists ${count}, visible ${visibleCount}, reason ${markdownInlineCode(reasonText, 80)}${boundsOverflow === void 0 ? "" : `, top bounds overflow ${boundsOverflow}px`}`);
16864
+ };
16865
+ const setupCheck = result.checks.find((check) => check.type === "setup_actions_succeeded");
16866
+ const setupSummary = cliRecord(setupCheck?.evidence?.setup_summary);
16867
+ const setupViewports = Array.isArray(setupSummary?.viewports) ? setupSummary.viewports.map(cliRecord).filter((viewport) => Boolean(viewport)) : [];
16868
+ for (const viewport of setupViewports) {
16869
+ const viewportName = cliString(viewport.name) || "viewport";
16870
+ const failed = [
16871
+ ...Array.isArray(viewport.failed) ? viewport.failed : [],
16872
+ ...Array.isArray(viewport.optional_failed) ? viewport.optional_failed : []
16873
+ ].map(cliRecord).filter((failure) => Boolean(failure));
16874
+ for (const failure of failed) {
16875
+ const selector = cliString(failure.selector);
16876
+ const reason = reachabilityFailureReason(cliString(failure.reason));
16877
+ if (selector && reason) addReceipt(viewportName, selector, reason);
16878
+ }
16879
+ }
16880
+ for (const check of result.checks) {
16881
+ if (check.type !== "selector_visible" || check.status !== "failed") continue;
16882
+ const evidence = cliRecord(check.evidence);
16883
+ const selector = cliString(evidence?.selector);
16884
+ if (!selector) continue;
16885
+ for (const viewport of evidenceViewports) {
16886
+ const viewportName = cliString(viewport.name) || "viewport";
16887
+ addReceipt(viewportName, selector, "no_visible_match");
16888
+ }
16889
+ }
16890
+ if (receipts.length > 8) {
16891
+ return [...receipts.slice(0, 8), `- ${receipts.length - 8} additional reachability receipt(s) omitted.`];
16892
+ }
16893
+ return receipts;
16894
+ }
16895
+ function stateContractReceiptName(receipt, fallbackIndex) {
16896
+ const storedTo = cliString(receipt.return_stored_to);
16897
+ if (!storedTo) return `receipt-${fallbackIndex + 1}`;
16898
+ const parts = storedTo.split(".").map((part) => part.trim()).filter(Boolean);
16899
+ return parts[parts.length - 1] || storedTo;
16900
+ }
16901
+ function stateContractReceiptValue(receipt) {
16902
+ const value = setupReturnSummaryValue(receipt, [
16903
+ "state",
16904
+ "nextState",
16905
+ "terminalState",
16906
+ "finalState",
16907
+ "status",
16908
+ "phase"
16909
+ ]);
16910
+ return cliValueLabel(value);
16911
+ }
16912
+ function stateContractSignalParts(receipts) {
16913
+ const names = [
16914
+ "hasValidate",
16915
+ "hasTryFix",
16916
+ "hasErrorDetail",
16917
+ "hasValid",
16918
+ "hasInvalid",
16919
+ "invalidGone",
16920
+ "staleGone",
16921
+ "staleCopyGone",
16922
+ "repairedTrailingCommaGone",
16923
+ "hasSuccess",
16924
+ "hasFailure",
16925
+ "hasRetry",
16926
+ "hasError",
16927
+ "success",
16928
+ "recovered"
16929
+ ];
16930
+ const seen = /* @__PURE__ */ new Set();
16931
+ const parts = [];
16932
+ for (const receipt of receipts) {
16933
+ for (const name of names) {
16934
+ const value = setupReturnSummaryValue(receipt, [name]);
16935
+ if (value === void 0) continue;
16936
+ const label = cliValueLabel(value);
16937
+ if (label === void 0) continue;
16938
+ const part = `${name}=${label}`;
16939
+ if (seen.has(part)) continue;
16940
+ seen.add(part);
16941
+ parts.push(part);
16942
+ if (parts.length >= 8) return parts;
16943
+ }
16944
+ }
16945
+ return parts;
16946
+ }
16947
+ function profileStateContractSummaryMarkdown(result) {
16948
+ const setupCheck = result.checks.find((check) => check.type === "setup_actions_succeeded");
16949
+ const setupSummary = cliRecord(setupCheck?.evidence?.setup_summary);
16950
+ const viewports = Array.isArray(setupSummary?.viewports) ? setupSummary.viewports.map(cliRecord).filter((viewport) => Boolean(viewport)) : [];
16951
+ const lines = [];
16952
+ for (const viewport of viewports.slice(0, 8)) {
16953
+ const name = cliString(viewport.name) || "viewport";
16954
+ const receipts = [
16955
+ ...setupReceiptArray(viewport, "window_eval"),
16956
+ ...setupReceiptArray(viewport, "window_call"),
16957
+ ...setupReceiptArray(viewport, "window_call_until")
16958
+ ].filter((receipt) => receipt.ok !== false);
16959
+ const states = receipts.map((receipt, index) => ({
16960
+ name: stateContractReceiptName(receipt, index),
16961
+ state: stateContractReceiptValue(receipt)
16962
+ })).filter((receipt) => Boolean(receipt.state));
16963
+ if (states.length < 2) continue;
16964
+ const stateChain = states.slice(0, 6).map((receipt) => `${markdownInlineCode(receipt.name, 60)}=${markdownInlineCode(receipt.state, 80)}`).join(" -> ");
16965
+ const omitted = states.length > 6 ? ` (+${states.length - 6} more)` : "";
16966
+ const signals = stateContractSignalParts(receipts);
16967
+ lines.push(`- state contract ${name}: ${stateChain}${omitted}${signals.length ? `; signals ${signals.map((part) => markdownInlineCode(part, 80)).join(", ")}` : ""}`);
16968
+ }
16969
+ return lines;
16970
+ }
16971
+ function sideCaveatAllowlistPart(evidence, totalKey, allowedKey) {
16972
+ const total = cliFiniteNumber(evidence[totalKey]);
16973
+ const allowed = cliFiniteNumber(evidence[allowedKey]);
16974
+ if (total === void 0 || allowed === void 0 || allowed <= 0) return void 0;
16975
+ return `${allowed}/${total} allowed`;
16976
+ }
16977
+ function sideCaveatAllowlistCounts(evidence) {
16978
+ const textCount = Array.isArray(evidence.allowed_console_texts) ? evidence.allowed_console_texts.filter((value) => typeof value === "string" && value.trim()).length : 0;
16979
+ const patternCount = Array.isArray(evidence.allowed_console_patterns) ? evidence.allowed_console_patterns.filter((value) => typeof value === "string" && value.trim()).length : 0;
16980
+ return textCount || patternCount ? `allowlist ${textCount} text${textCount === 1 ? "" : "s"}, ${patternCount} pattern${patternCount === 1 ? "" : "s"}` : void 0;
16981
+ }
16982
+ function overflowCheckFailed(result) {
16983
+ return result.checks.some((check) => check.status === "failed" && (check.type === "no_horizontal_overflow" || check.type === "no_mobile_horizontal_overflow" || check.type === "frame_no_horizontal_overflow"));
16984
+ }
16985
+ function sideCaveatOverflowLine(viewport) {
16986
+ const name = cliString(viewport.name) || "viewport";
16987
+ const scrollOverflow = cliFiniteNumber(viewport.overflow_px);
16988
+ const boundsOverflow = cliFiniteNumber(viewport.bounds_overflow_px);
16989
+ if ((scrollOverflow === void 0 || scrollOverflow <= 0) && (boundsOverflow === void 0 || boundsOverflow <= 0)) return void 0;
16990
+ const parts = [
16991
+ scrollOverflow !== void 0 && scrollOverflow > 0 ? `scroll overflow ${scrollOverflow}px` : "",
16992
+ boundsOverflow !== void 0 && boundsOverflow > 0 ? `bounds overflow ${boundsOverflow}px` : ""
16993
+ ].filter(Boolean);
16994
+ const offenders = Array.isArray(viewport.overflow_offenders) ? viewport.overflow_offenders.map(cliRecord).filter((item) => Boolean(item)) : [];
16995
+ const offender = offenders.find((item) => {
16996
+ const overflow = cliFiniteNumber(item.bounds_overflow_px) ?? cliFiniteNumber(item.overflow_px) ?? cliFiniteNumber(item.overflow);
16997
+ return overflow !== void 0 && overflow > 0;
16998
+ });
16999
+ const offenderSelector = cliString(offender?.selector);
17000
+ const offenderOverflow = offender ? cliFiniteNumber(offender.bounds_overflow_px) ?? cliFiniteNumber(offender.overflow_px) ?? cliFiniteNumber(offender.overflow) : void 0;
17001
+ return `- side caveat layout ${name}: ${parts.join(", ")}${offenderSelector && offenderOverflow !== void 0 ? `; top offender ${markdownInlineCode(offenderSelector, 100)} ${offenderOverflow}px` : ""}`;
17002
+ }
17003
+ function profileSideCaveatSummaryMarkdown(result) {
17004
+ const lines = [];
17005
+ for (const check of result.checks) {
17006
+ if (check.status !== "passed") continue;
17007
+ const evidence = cliRecord(check.evidence);
17008
+ if (!evidence) continue;
17009
+ if (check.type === "no_console_warnings") {
17010
+ const allowed = sideCaveatAllowlistPart(evidence, "total_console_warning_count", "allowed_console_warning_count");
17011
+ if (allowed) {
17012
+ const allowlist = sideCaveatAllowlistCounts(evidence);
17013
+ lines.push(`- side caveat console warnings: ${allowed}${allowlist ? `; ${allowlist}` : ""}`);
17014
+ }
17015
+ }
17016
+ if (check.type === "no_fatal_console_errors") {
17017
+ const consoleAllowed = sideCaveatAllowlistPart(evidence, "total_console_fatal_count", "allowed_console_fatal_count");
17018
+ const pageAllowed = sideCaveatAllowlistPart(evidence, "total_page_error_count", "allowed_page_error_count");
17019
+ const parts = [
17020
+ consoleAllowed ? `console fatal ${consoleAllowed}` : "",
17021
+ pageAllowed ? `page errors ${pageAllowed}` : "",
17022
+ sideCaveatAllowlistCounts(evidence)
17023
+ ].filter(Boolean);
17024
+ if (parts.length) lines.push(`- side caveat fatal errors: ${parts.join("; ")}`);
17025
+ }
17026
+ }
17027
+ if (!overflowCheckFailed(result) && Array.isArray(result.evidence?.viewports)) {
17028
+ for (const viewport of result.evidence.viewports.slice(0, 8)) {
17029
+ const line = sideCaveatOverflowLine(cliRecord(viewport) || {});
17030
+ if (line) lines.push(line);
17031
+ }
17032
+ if (result.evidence.viewports.length > 8) lines.push(`- ${result.evidence.viewports.length - 8} additional viewport side caveat(s) omitted.`);
17033
+ }
17034
+ return lines.slice(0, 12);
17035
+ }
16550
17036
  function balancedSetupReceiptDetails(groups, limit) {
16551
17037
  if (limit <= 0) return [];
16552
17038
  const total = groups.reduce((sum, group) => sum + group.length, 0);
@@ -17264,7 +17750,7 @@ async function readArtifactJson(artifact) {
17264
17750
  async function profileResultFromRiddleArtifacts(profile, artifacts, fallbackInputs) {
17265
17751
  for (const input of fallbackInputs) {
17266
17752
  const result = extractRiddleProofProfileResult(input);
17267
- if (result) return result;
17753
+ if (result) return withProfileMetadata(profile, result);
17268
17754
  }
17269
17755
  const proofArtifacts = artifacts.filter((artifact) => /(^|\/)proof\.json(?:\.json)?$/i.test(artifact.name || artifact.url || artifact.path || "")).sort((left, right) => {
17270
17756
  const leftName = left.name || left.url || left.path || "";
@@ -17274,7 +17760,7 @@ async function profileResultFromRiddleArtifacts(profile, artifacts, fallbackInpu
17274
17760
  for (const artifact of proofArtifacts) {
17275
17761
  const parsed = await readArtifactJson(artifact);
17276
17762
  const result = extractRiddleProofProfileResult(parsed);
17277
- if (result) return result;
17763
+ if (result) return withProfileMetadata(profile, result);
17278
17764
  }
17279
17765
  const evidenceArtifacts = artifacts.filter((artifact) => /profile-evidence|evidence\.json/i.test(artifact.name || artifact.url || artifact.path || ""));
17280
17766
  for (const artifact of evidenceArtifacts) {
@@ -17285,6 +17771,16 @@ async function profileResultFromRiddleArtifacts(profile, artifacts, fallbackInpu
17285
17771
  }
17286
17772
  return void 0;
17287
17773
  }
17774
+ function withProfileMetadata(profile, result) {
17775
+ if (!profile.metadata || !Object.keys(profile.metadata).length) return result;
17776
+ return {
17777
+ ...result,
17778
+ metadata: {
17779
+ ...profile.metadata,
17780
+ ...result.metadata || {}
17781
+ }
17782
+ };
17783
+ }
17288
17784
  function withRiddleMetadata(result, input) {
17289
17785
  const poll = input.poll;
17290
17786
  const staleJobIds = input.staleJobIds?.filter(Boolean);
@@ -17628,7 +18124,7 @@ async function runSingleRiddleProfileForCli(profile, options, input) {
17628
18124
  jobId = typeof created.job_id === "string" ? created.job_id : typeof created.id === "string" ? created.id : "";
17629
18125
  if (!jobId) {
17630
18126
  const directResult = extractRiddleProofProfileResult(created);
17631
- return directResult ? withRiddleMetadata(directResult, { artifacts: collectRiddleProfileArtifactRefs(created) }) : createRiddleProofProfileInsufficientResult({ profile, runner, error: "Riddle run response was missing job_id.", artifacts: collectRiddleProfileArtifactRefs(created) });
18127
+ return directResult ? withRiddleMetadata(withProfileMetadata(profile, directResult), { artifacts: collectRiddleProfileArtifactRefs(created) }) : createRiddleProofProfileInsufficientResult({ profile, runner, error: "Riddle run response was missing job_id.", artifacts: collectRiddleProfileArtifactRefs(created) });
17632
18128
  }
17633
18129
  poll = await client.pollJob(jobId, pollOptions);
17634
18130
  if (attempt < retryLimit && shouldRetryUnsubmittedRiddleJob(poll)) {