agentskeptic 6.0.1 → 6.2.0

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.
Files changed (89) hide show
  1. package/dist/actionableFailure.d.ts +8 -1
  2. package/dist/actionableFailure.d.ts.map +1 -1
  3. package/dist/actionableFailure.js +588 -1
  4. package/dist/actionableFailure.js.map +1 -1
  5. package/dist/correctnessDefinition.d.ts.map +1 -1
  6. package/dist/correctnessDefinition.js +2 -22
  7. package/dist/correctnessDefinition.js.map +1 -1
  8. package/dist/evidenceCompleteness.d.ts +9 -5
  9. package/dist/evidenceCompleteness.d.ts.map +1 -1
  10. package/dist/evidenceCompleteness.js +65 -111
  11. package/dist/evidenceCompleteness.js.map +1 -1
  12. package/dist/execution-identity.v1.json +1 -1
  13. package/dist/failureSpine.d.ts +5 -2
  14. package/dist/failureSpine.d.ts.map +1 -1
  15. package/dist/failureSpine.js +3 -81
  16. package/dist/failureSpine.js.map +1 -1
  17. package/dist/failureSpine.test.js +3 -0
  18. package/dist/failureSpine.test.js.map +1 -1
  19. package/dist/formatEvidenceCompletenessHuman.d.ts +1 -1
  20. package/dist/formatEvidenceCompletenessHuman.d.ts.map +1 -1
  21. package/dist/formatEvidenceCompletenessHuman.js +34 -1
  22. package/dist/formatEvidenceCompletenessHuman.js.map +1 -1
  23. package/dist/formatFailureSpineHuman.d.ts.map +1 -1
  24. package/dist/formatFailureSpineHuman.js +5 -1
  25. package/dist/formatFailureSpineHuman.js.map +1 -1
  26. package/dist/index.d.ts +3 -1
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +2 -1
  29. package/dist/index.js.map +1 -1
  30. package/dist/loop/loopOutput.contract.test.d.ts +2 -0
  31. package/dist/loop/loopOutput.contract.test.d.ts.map +1 -0
  32. package/dist/loop/loopOutput.contract.test.js +22 -0
  33. package/dist/loop/loopOutput.contract.test.js.map +1 -0
  34. package/dist/loop/loopOutput.d.ts +2 -1
  35. package/dist/loop/loopOutput.d.ts.map +1 -1
  36. package/dist/loop/loopOutput.js +9 -2
  37. package/dist/loop/loopOutput.js.map +1 -1
  38. package/dist/loop/runLoopSubcommand.d.ts.map +1 -1
  39. package/dist/loop/runLoopSubcommand.js +1 -1
  40. package/dist/loop/runLoopSubcommand.js.map +1 -1
  41. package/dist/outcomeCertificate.d.ts +3 -1
  42. package/dist/outcomeCertificate.d.ts.map +1 -1
  43. package/dist/outcomeCertificate.js +39 -4
  44. package/dist/outcomeCertificate.js.map +1 -1
  45. package/dist/outcomeCertificate.test.js +130 -0
  46. package/dist/outcomeCertificate.test.js.map +1 -1
  47. package/dist/publicDistribution.generated.d.ts +1 -1
  48. package/dist/publicDistribution.generated.js +1 -1
  49. package/dist/quickSyntheticWorkflow.d.ts +8 -0
  50. package/dist/quickSyntheticWorkflow.d.ts.map +1 -0
  51. package/dist/quickSyntheticWorkflow.js +59 -0
  52. package/dist/quickSyntheticWorkflow.js.map +1 -0
  53. package/dist/quickVerify/canonicalJson.d.ts.map +1 -1
  54. package/dist/quickVerify/canonicalJson.js +6 -1
  55. package/dist/quickVerify/canonicalJson.js.map +1 -1
  56. package/dist/quickVerify/formatQuickVerifyHumanReport.test.js +92 -2
  57. package/dist/quickVerify/formatQuickVerifyHumanReport.test.js.map +1 -1
  58. package/dist/quickVerify/runQuickVerify.d.ts.map +1 -1
  59. package/dist/quickVerify/runQuickVerify.js +48 -4
  60. package/dist/quickVerify/runQuickVerify.js.map +1 -1
  61. package/dist/remediationConsumptionGuard.test.js +1 -0
  62. package/dist/remediationConsumptionGuard.test.js.map +1 -1
  63. package/dist/remediationDecision.parity.test.d.ts +2 -0
  64. package/dist/remediationDecision.parity.test.d.ts.map +1 -0
  65. package/dist/remediationDecision.parity.test.js +22 -0
  66. package/dist/remediationDecision.parity.test.js.map +1 -0
  67. package/dist/remediationMessage.d.ts +2 -0
  68. package/dist/remediationMessage.d.ts.map +1 -1
  69. package/dist/remediationMessage.js +2 -0
  70. package/dist/remediationMessage.js.map +1 -1
  71. package/dist/remediationWireSurfaceGuard.test.js +1 -0
  72. package/dist/remediationWireSurfaceGuard.test.js.map +1 -1
  73. package/dist/sdk/_generated/openapi-types.d.ts +2 -2
  74. package/dist/sdk/_generated/openapi-types.d.ts.map +1 -1
  75. package/dist/types.d.ts +50 -0
  76. package/dist/types.d.ts.map +1 -1
  77. package/dist/workflowFailureSignals.d.ts +8 -0
  78. package/dist/workflowFailureSignals.d.ts.map +1 -0
  79. package/dist/workflowFailureSignals.js +65 -0
  80. package/dist/workflowFailureSignals.js.map +1 -0
  81. package/dist/workflowResultSlice.d.ts +6 -0
  82. package/dist/workflowResultSlice.d.ts.map +1 -0
  83. package/dist/workflowResultSlice.js +8 -0
  84. package/dist/workflowResultSlice.js.map +1 -0
  85. package/package.json +1 -1
  86. package/schemas/evidence-completeness-v1.schema.json +180 -1
  87. package/schemas/openapi-commercial-v1.in.yaml +2 -2
  88. package/schemas/openapi-commercial-v1.yaml +3 -3
  89. package/schemas/outcome-certificate-v3.schema.json +8 -0
@@ -3,7 +3,8 @@
3
3
  * Pair with JSON Schema enums on workflowTruthReport / cli-error-envelope / run-comparison-report.
4
4
  */
5
5
  import { type OperationalCode } from "./cliOperationalCodes.js";
6
- import type { ActionableFailure, ActionableFailureCategory, ActionableFailureSeverity, FailureAnalysisBase, RecommendedActionCode, WorkflowEngineResult } from "./types.js";
6
+ import type { QuickVerifyReport } from "./quickVerify/runQuickVerify.js";
7
+ import type { ActionableFailure, ActionableFailureCategory, ActionableFailureSeverity, FailureAnalysisBase, RecommendedActionCode, RemediationDecision, WorkflowEngineResult, WorkflowResult } from "./types.js";
7
8
  export declare const ACTIONABLE_FAILURE_CATEGORIES: readonly ["decision_error", "bad_input", "retrieval_failure", "control_flow_problem", "state_inconsistency", "downstream_execution_failure", "ambiguous", "unclassified"];
8
9
  export declare const ACTIONABLE_FAILURE_SEVERITIES: readonly ["high", "medium", "low"];
9
10
  type RemediationRow = {
@@ -29,6 +30,12 @@ export declare const OPERATIONAL_CODE_TO_SEVERITY: Record<OperationalCode, Actio
29
30
  export declare const OPERATIONAL_CODE_TO_RECOMMENDED_ACTION: Record<OperationalCode, RecommendedActionCode>;
30
31
  export declare const OPERATIONAL_CODE_TO_AUTOMATION_SAFE: Record<OperationalCode, boolean>;
31
32
  export declare function deriveActionableFailureOperational(code: string): ActionableFailure;
33
+ export declare function deriveQuickRemediationAlignment(reasonCodes: readonly string[]): {
34
+ recommendedAction: RecommendedActionCode;
35
+ automationSafe: boolean;
36
+ };
37
+ export declare function deriveRemediationDecisionFromWorkflowResult(result: WorkflowResult): RemediationDecision;
38
+ export declare function deriveRemediationDecisionFromQuickReport(report: QuickVerifyReport, workflowId: string): RemediationDecision;
32
39
  export type PerRunActionable = {
33
40
  runIndex: number;
34
41
  category: string;
@@ -1 +1 @@
1
- {"version":3,"file":"actionableFailure.d.ts","sourceRoot":"","sources":["../src/actionableFailure.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAyB,KAAK,eAAe,EAAE,MAAM,0BAA0B,CAAC;AASvF,OAAO,KAAK,EACV,iBAAiB,EACjB,yBAAyB,EACzB,yBAAyB,EACzB,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,6BAA6B,2KASe,CAAC;AAE1D,eAAO,MAAM,6BAA6B,oCAAoF,CAAC;AAE/H,KAAK,cAAc,GAAG;IAAE,iBAAiB,EAAE,qBAAqB,CAAC;IAAC,cAAc,EAAE,OAAO,CAAA;CAAE,CAAC;AAyB5F,eAAO,MAAM,6BAA6B,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAIxE,CAAC;AAEF,eAAO,MAAM,kCAAkC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAG7E,CAAC;AAEF,eAAO,MAAM,+BAA+B,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAS1E,CAAC;AA6NF,4GAA4G;AAC5G,wBAAgB,4CAA4C,C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AE,CAAC;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,uBAAuB,EAAE,MAAM,CAAC;CACjC,CAAC;AAEF,8EAA8E;AAC9E,wBAAgB,oBAAoB,CAAC,mBAAmB,EAAE,MAAM,EAAE,GAAG,MAAM,CAa1E;AAED,wBAAgB,iCAAiC,CAAC,MAAM,EAAE,gBAAgB,EAAE,GAAG,+BAA+B,EAAE,CAoB/G;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,gBAAgB,EAAE,GAAG,KAAK,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAS7G"}
@@ -5,7 +5,13 @@
5
5
  import { CLI_OPERATIONAL_CODES } from "./cliOperationalCodes.js";
6
6
  import { REASON_CODE_TO_ORIGIN, RUN_LEVEL_CODE_TO_ORIGIN, STEP_NO_REASON_CODE, TEST_BLOCKING_CODE, } from "./failureOriginCatalog.js";
7
7
  import { OPERATIONAL_DISPOSITION } from "./operationalDisposition.js";
8
+ import { buildFailureAnalysis } from "./failureAnalysis.js";
8
9
  import { REGISTRY_RESOLVER_CODE, SQL_VERIFICATION_OUTCOME_CODE } from "./wireReasonCodes.js";
10
+ import { quickVerifyReportToSyntheticEngine, syntheticQuickFailureAnalysis, } from "./quickSyntheticWorkflow.js";
11
+ import { redactEvidenceString } from "./redactEvidenceString.js";
12
+ import { classifyWorkflowBlocker, collectWorkflowCodes } from "./workflowFailureSignals.js";
13
+ import { workflowResultToEngineSlice } from "./workflowResultSlice.js";
14
+ import { AUTOMATION_BOUNDARY_CONNECTOR, remediationMessageForRecommendedAction } from "./remediationMessage.js";
9
15
  export const ACTIONABLE_FAILURE_CATEGORIES = [
10
16
  "decision_error",
11
17
  "bad_input",
@@ -155,7 +161,7 @@ const STEP_CODE_TO_REMEDIATION = {
155
161
  },
156
162
  [SQL_VERIFICATION_OUTCOME_CODE.CONNECTOR_ERROR]: {
157
163
  recommendedAction: "improve_read_connectivity",
158
- automationSafe: false,
164
+ automationSafe: true,
159
165
  },
160
166
  [SQL_VERIFICATION_OUTCOME_CODE.ROW_SHAPE_MISMATCH]: {
161
167
  recommendedAction: "improve_read_connectivity",
@@ -467,6 +473,587 @@ export function deriveActionableFailureOperational(code) {
467
473
  automationSafe: row.automationSafe,
468
474
  };
469
475
  }
476
+ function syntheticFailureBaseWorkflow(result) {
477
+ const codes = [...collectWorkflowCodes(result)].sort((a, b) => a.localeCompare(b)).slice(0, 12);
478
+ return {
479
+ summary: "Synthetic failure analysis for evidence completeness fallback.",
480
+ primaryOrigin: "workflow_flow",
481
+ confidence: "medium",
482
+ unknownReasonCodes: [],
483
+ evidence: codes.length > 0
484
+ ? [{ scope: "run_level", codes }]
485
+ : [{ scope: "step", codes: ["UNCLASSIFIED_GAP"], seq: 0, toolId: "" }],
486
+ alternativeHypotheses: undefined,
487
+ };
488
+ }
489
+ function nextActionEntry(code) {
490
+ return {
491
+ id: code,
492
+ text: redactEvidenceString(remediationMessageForRecommendedAction(code), 500),
493
+ };
494
+ }
495
+ const AUTOMATION_LABELS = {
496
+ read_only_retry: "Safe automatic action: retry read-only verification with the same inputs.",
497
+ input_regeneration_candidate: "Automation candidate: repair inputs outside the verifier; AgentSkeptic will not mutate external systems.",
498
+ human_write_required: "Human or external system must change state; AgentSkeptic will not mutate data.",
499
+ never_auto_mutate: "Manual judgment required; do not automate mutation from this result.",
500
+ };
501
+ const AUTOMATION_BOUNDARY = "AgentSkeptic is a read-only verifier. It does not mutate databases, rewrite inputs, or execute remediation.";
502
+ const RERUN_LABELS = {
503
+ same_input_verify: "Rerun verify with the same inputs after the read-only prerequisite is restored.",
504
+ after_input_fix_verify: "Rerun verify after registry, events, tool parameters, or verification inputs are corrected.",
505
+ after_state_fix_verify: "Rerun verify after downstream state matches the expected state.",
506
+ after_manual_review_verify: "Rerun verify after a human reviewer chooses and applies the correct fix path.",
507
+ no_rerun_needed: "No rerun is required for this trusted outcome.",
508
+ };
509
+ function sortUniqueStrings(values) {
510
+ return [...new Set(values.filter((v) => v.length > 0))].sort((a, b) => a.localeCompare(b));
511
+ }
512
+ function primaryCode(codes) {
513
+ return codes[0] ?? "";
514
+ }
515
+ function automationClassForAction(row, code) {
516
+ if (row.automationSafe && row.recommendedAction === "improve_read_connectivity")
517
+ return "read_only_retry";
518
+ const action = row.recommendedAction;
519
+ switch (action) {
520
+ case "correct_verification_inputs":
521
+ case "fix_event_ingest_and_steps":
522
+ case "fix_event_sequence_order":
523
+ case "fix_run_context_controls":
524
+ case "fix_cli_usage":
525
+ case "fix_registry_events_or_compare_files":
526
+ case "fix_verification_database_connection":
527
+ case "fix_saved_workflow_json":
528
+ case "fix_compare_workflow_inputs":
529
+ case "fix_execution_trace_structure":
530
+ case "fix_verification_policy_and_hook":
531
+ case "fix_plan_document_and_patterns":
532
+ case "fix_plan_transition_cli_and_refs":
533
+ case "upgrade_git_or_retry_git":
534
+ return "input_regeneration_candidate";
535
+ case "reconcile_downstream_state":
536
+ case "deduplicate":
537
+ return "human_write_required";
538
+ case "improve_read_connectivity":
539
+ return code === SQL_VERIFICATION_OUTCOME_CODE.CONNECTOR_ERROR ? "read_only_retry" : "input_regeneration_candidate";
540
+ case "manual_review":
541
+ case "resolve_multi_effect_failures":
542
+ case "align_tool_observations":
543
+ return "never_auto_mutate";
544
+ case "none":
545
+ return "read_only_retry";
546
+ default:
547
+ return "never_auto_mutate";
548
+ }
549
+ }
550
+ function rerunPathTypeForAction(row, automationClass) {
551
+ if (row.recommendedAction === "none")
552
+ return "no_rerun_needed";
553
+ if (automationClass === "read_only_retry")
554
+ return "same_input_verify";
555
+ if (automationClass === "human_write_required")
556
+ return "after_state_fix_verify";
557
+ if (automationClass === "never_auto_mutate")
558
+ return "after_manual_review_verify";
559
+ return "after_input_fix_verify";
560
+ }
561
+ function rerunPathForType(type) {
562
+ switch (type) {
563
+ case "same_input_verify":
564
+ return {
565
+ type,
566
+ sameInputs: true,
567
+ prerequisite: "Read-only database or witness connectivity is restored.",
568
+ meaningfulWhen: "The same captured events, registry, workflow, and read target can be checked again.",
569
+ readinessLabel: RERUN_LABELS[type],
570
+ };
571
+ case "after_input_fix_verify":
572
+ return {
573
+ type,
574
+ sameInputs: false,
575
+ prerequisite: "Registry, events, tool parameters, or verification inputs are corrected.",
576
+ meaningfulWhen: "The corrected inputs express the expected state the verifier should check.",
577
+ readinessLabel: RERUN_LABELS[type],
578
+ };
579
+ case "after_state_fix_verify":
580
+ return {
581
+ type,
582
+ sameInputs: false,
583
+ prerequisite: "Downstream state has been reconciled to the expected state.",
584
+ meaningfulWhen: "The database or external witness state should now satisfy the verification expectation.",
585
+ readinessLabel: RERUN_LABELS[type],
586
+ };
587
+ case "after_manual_review_verify":
588
+ return {
589
+ type,
590
+ sameInputs: false,
591
+ prerequisite: "A human reviewer chooses and applies the correct fix path.",
592
+ meaningfulWhen: "The reviewer has resolved which hypothesis is true and updated state or inputs accordingly.",
593
+ readinessLabel: RERUN_LABELS[type],
594
+ };
595
+ case "no_rerun_needed":
596
+ return {
597
+ type,
598
+ sameInputs: true,
599
+ prerequisite: "Verification is already trusted under the configured rules.",
600
+ meaningfulWhen: "No failed check blocks trust.",
601
+ readinessLabel: RERUN_LABELS[type],
602
+ };
603
+ }
604
+ }
605
+ function rowForCodes(scope, codes) {
606
+ const list = [...codes];
607
+ switch (scope) {
608
+ case "run_level":
609
+ case "quick_ingest":
610
+ return remediationForRunLevelItem(list);
611
+ case "event_sequence":
612
+ return remediationForEventSequenceItem(list);
613
+ case "run_context":
614
+ return remediationForRunContextItem(list);
615
+ case "step":
616
+ case "effect":
617
+ case "quick_unit":
618
+ return remediationForStepOrEffectItem(list);
619
+ }
620
+ }
621
+ export function deriveQuickRemediationAlignment(reasonCodes) {
622
+ const sorted = sortUniqueStrings(reasonCodes);
623
+ const c = sorted[0] ?? "";
624
+ if (c === "CONNECTOR_ERROR")
625
+ return { recommendedAction: "improve_read_connectivity", automationSafe: false };
626
+ if (c === "MAPPING_FAILED" || c.startsWith("RESOLVE_") || c.includes("REGISTRY") || c === "UNKNOWN_TOOL") {
627
+ return { recommendedAction: "correct_verification_inputs", automationSafe: false };
628
+ }
629
+ if (c === "ROW_ABSENT" ||
630
+ c === "VALUE_MISMATCH" ||
631
+ c === "DUPLICATE_ROWS" ||
632
+ c === "RELATIONAL_EXPECTATION_MISMATCH" ||
633
+ c === "RELATIONAL_SCALAR_UNUSABLE" ||
634
+ c === "ROW_PRESENT_WHEN_FORBIDDEN") {
635
+ return { recommendedAction: "reconcile_downstream_state", automationSafe: false };
636
+ }
637
+ return { recommendedAction: "manual_review", automationSafe: false };
638
+ }
639
+ function itemAutomation(row, code) {
640
+ const cls = automationClassForAction(row, code);
641
+ return {
642
+ class: cls,
643
+ label: AUTOMATION_LABELS[cls],
644
+ boundary: cls === "read_only_retry" ? AUTOMATION_BOUNDARY_CONNECTOR : AUTOMATION_BOUNDARY,
645
+ };
646
+ }
647
+ function reviewForItem(opts) {
648
+ const required = opts.action === "manual_review";
649
+ if (!required)
650
+ return { required: false };
651
+ const hypotheses = opts.fa?.alternativeHypotheses?.map((h) => `origin=${h.primaryOrigin}: ${h.rationale}`).slice(0, 6) ?? [];
652
+ return {
653
+ required: true,
654
+ decisionPrompt: "Decide which hypothesis explains the mismatch before changing state or inputs.",
655
+ ...(hypotheses.length ? { hypotheses } : {}),
656
+ knownFacts: opts.fa !== null && opts.fa !== undefined
657
+ ? [
658
+ `primary_origin=${opts.fa.primaryOrigin}`,
659
+ `confidence=${opts.fa.confidence}`,
660
+ `summary=${opts.fa.summary}`,
661
+ ].slice(0, 12)
662
+ : undefined,
663
+ evidenceToInspect: opts.evidenceToInspect.slice(0, 8),
664
+ };
665
+ }
666
+ function makeRemediationItem(opts) {
667
+ const codes = sortUniqueStrings(opts.reasonCodes).slice(0, 8);
668
+ const row = opts.forceManualReview ? MANUAL_REMEDIATION : (opts.row ?? rowForCodes(opts.scope, codes));
669
+ const automation = itemAutomation(row, primaryCode(codes));
670
+ const rerunPath = rerunPathForType(rerunPathTypeForAction(row, automation.class));
671
+ const actionText = redactEvidenceString(remediationMessageForRecommendedAction(row.recommendedAction), 500);
672
+ return {
673
+ id: redactEvidenceString(opts.id, 128),
674
+ scope: opts.scope,
675
+ primary: opts.primary,
676
+ failedCheck: redactEvidenceString(opts.failedCheck, 256),
677
+ reasonCodes: codes.map((c) => redactEvidenceString(c, 128)),
678
+ reason: redactEvidenceString(opts.reason || "Verification check did not pass.", 1024),
679
+ recommendedAction: row.recommendedAction,
680
+ actionText,
681
+ expectedState: {
682
+ summary: redactEvidenceString(opts.expectedSummary || "Expected state must satisfy the verification contract.", 1024),
683
+ ...(opts.projectionKind !== undefined ? { projectionKind: opts.projectionKind } : {}),
684
+ },
685
+ automation,
686
+ humanReview: reviewForItem({
687
+ action: row.recommendedAction,
688
+ fa: opts.fa,
689
+ evidenceToInspect: opts.evidenceToInspect,
690
+ }),
691
+ rerunPath,
692
+ };
693
+ }
694
+ function primaryEvidenceKey(fa) {
695
+ const ev = fa?.evidence[0];
696
+ if (ev === undefined)
697
+ return null;
698
+ if (ev.scope === "step" && ev.seq !== undefined)
699
+ return `step:${ev.seq}`;
700
+ if (ev.scope === "effect" && ev.seq !== undefined && ev.effectId !== undefined)
701
+ return `effect:${ev.seq}:${ev.effectId}`;
702
+ if (ev.scope === "run_level")
703
+ return "run_level";
704
+ if (ev.scope === "event_sequence")
705
+ return "event_sequence";
706
+ if (ev.scope === "run_context")
707
+ return "run_context";
708
+ return null;
709
+ }
710
+ function effectReasonCodes(effect) {
711
+ return effect.reasons.map((r) => r.code);
712
+ }
713
+ function stepReasonCodes(step) {
714
+ return step.reasons.map((r) => r.code);
715
+ }
716
+ function stepExpectedSummary(step) {
717
+ return `Expected state: ${step.verifyTarget ?? step.intendedEffect.narrative}; observed: ${step.observedStateSummary}`;
718
+ }
719
+ function effectExpectedSummary(step, effectId) {
720
+ return `Expected effect ${effectId} within ${step.verifyTarget ?? step.intendedEffect.narrative}; observed: ${step.observedStateSummary}`;
721
+ }
722
+ function buildWorkflowRemediationItems(result) {
723
+ if (result.status === "complete" && result.workflowTruthReport.failureAnalysis === null)
724
+ return [];
725
+ const truth = result.workflowTruthReport;
726
+ const fa = truth.failureAnalysis;
727
+ const primaryKey = primaryEvidenceKey(fa);
728
+ const projectionKind = truth.correctnessDefinition?.enforcementKind;
729
+ const primaryExpected = truth.correctnessDefinition?.mustAlwaysHold;
730
+ const items = [];
731
+ if (truth.runLevelIssues.length > 0) {
732
+ const codes = truth.runLevelIssues.map((r) => r.code);
733
+ items.push(makeRemediationItem({
734
+ id: "run_level",
735
+ scope: "run_level",
736
+ primary: primaryKey === "run_level",
737
+ failedCheck: "run-level verification input",
738
+ reasonCodes: codes,
739
+ reason: truth.runLevelIssues.map((r) => r.message).join("; "),
740
+ expectedSummary: primaryKey === "run_level" && primaryExpected !== undefined
741
+ ? primaryExpected
742
+ : "Expected a valid captured run with no run-level ingest or planning failures.",
743
+ projectionKind: primaryKey === "run_level" ? projectionKind : undefined,
744
+ fa,
745
+ evidenceToInspect: ["workflowTruthReport.runLevelIssues", "workflowTruthReport.failureAnalysis"],
746
+ }));
747
+ }
748
+ if (truth.eventSequence.kind === "irregular") {
749
+ const codes = truth.eventSequence.issues.map((r) => r.code);
750
+ items.push(makeRemediationItem({
751
+ id: "event_sequence",
752
+ scope: "event_sequence",
753
+ primary: primaryKey === "event_sequence",
754
+ failedCheck: "event sequence",
755
+ reasonCodes: codes,
756
+ reason: truth.eventSequence.issues.map((r) => r.message).join("; "),
757
+ expectedSummary: primaryKey === "event_sequence" && primaryExpected !== undefined
758
+ ? primaryExpected
759
+ : "Expected monotonic, coherent event capture for this workflow.",
760
+ projectionKind: primaryKey === "event_sequence" ? projectionKind : undefined,
761
+ fa,
762
+ evidenceToInspect: ["workflowTruthReport.eventSequence", "eventSequenceIntegrity"],
763
+ }));
764
+ }
765
+ for (const ev of fa?.evidence ?? []) {
766
+ if (ev.scope !== "run_context")
767
+ continue;
768
+ const codes = ev.codes ?? [];
769
+ items.push(makeRemediationItem({
770
+ id: `run_context:${ev.ingestIndex ?? 0}`,
771
+ scope: "run_context",
772
+ primary: primaryKey === "run_context",
773
+ failedCheck: `run context before ingest ${ev.ingestIndex ?? "unknown"}`,
774
+ reasonCodes: codes,
775
+ reason: `Run context failed before the evaluated observation: ${codes.join(",")}`,
776
+ expectedSummary: primaryKey === "run_context" && primaryExpected !== undefined
777
+ ? primaryExpected
778
+ : "Expected retrieval, model, control, and tool context to allow fair verification.",
779
+ projectionKind: primaryKey === "run_context" ? projectionKind : undefined,
780
+ fa,
781
+ evidenceToInspect: ["workflowTruthReport.executionPathFindings", "verificationRunContext"],
782
+ }));
783
+ }
784
+ for (const step of truth.steps) {
785
+ if (step.outcomeLabel === "VERIFIED")
786
+ continue;
787
+ if (step.effects !== undefined && step.effects.length > 0) {
788
+ for (const effect of step.effects) {
789
+ if (effect.outcomeLabel === "VERIFIED")
790
+ continue;
791
+ const id = `effect:${step.seq}:${effect.id}`;
792
+ const codes = effectReasonCodes(effect);
793
+ items.push(makeRemediationItem({
794
+ id,
795
+ scope: "effect",
796
+ primary: primaryKey === id,
797
+ failedCheck: `Failed check: effect ${effect.id} on step ${step.seq}`,
798
+ reasonCodes: codes,
799
+ reason: effect.reasons[0]?.message ?? effect.outcomeLabel,
800
+ expectedSummary: effectExpectedSummary(step, effect.id),
801
+ fa: null,
802
+ evidenceToInspect: [
803
+ `workflowTruthReport.steps[seq=${step.seq}].effects[id=${effect.id}]`,
804
+ `workflowTruthReport.steps[seq=${step.seq}].observedStateSummary`,
805
+ ],
806
+ }));
807
+ }
808
+ continue;
809
+ }
810
+ const id = `step:${step.seq}`;
811
+ const codes = stepReasonCodes(step);
812
+ items.push(makeRemediationItem({
813
+ id,
814
+ scope: "step",
815
+ primary: primaryKey === id,
816
+ failedCheck: `Failed check: step ${step.seq}${step.toolId ? ` (${step.toolId})` : ""}`,
817
+ reasonCodes: codes,
818
+ reason: step.reasons[0]?.message ?? step.outcomeLabel,
819
+ expectedSummary: primaryKey === id && primaryExpected !== undefined ? primaryExpected : stepExpectedSummary(step),
820
+ projectionKind: primaryKey === id ? projectionKind : undefined,
821
+ fa: primaryKey === id ? fa : null,
822
+ evidenceToInspect: [
823
+ `workflowTruthReport.steps[seq=${step.seq}]`,
824
+ "workflowTruthReport.failureExplanation",
825
+ "workflowTruthReport.correctnessDefinition",
826
+ ],
827
+ forceManualReview: primaryKey === id &&
828
+ fa !== null &&
829
+ fa !== undefined &&
830
+ fa.actionableFailure.recommendedAction === "manual_review",
831
+ }));
832
+ }
833
+ if (items.length === 0 && fa !== null) {
834
+ items.push(makeRemediationItem({
835
+ id: "failure_analysis",
836
+ scope: "run_level",
837
+ primary: true,
838
+ failedCheck: "verification failure analysis",
839
+ reasonCodes: fa.evidence[0]?.codes ?? ["UNCLASSIFIED_GAP"],
840
+ reason: fa.summary,
841
+ expectedSummary: primaryExpected ?? "Expected state must satisfy the verification contract.",
842
+ projectionKind,
843
+ fa,
844
+ evidenceToInspect: ["workflowTruthReport.failureAnalysis"],
845
+ forceManualReview: true,
846
+ }));
847
+ }
848
+ return items.slice(0, 32);
849
+ }
850
+ function buildQuickRemediationItems(report) {
851
+ if (report.verdict === "pass")
852
+ return [];
853
+ const items = [];
854
+ if (report.ingest.reasonCodes.length > 0 || report.units.length === 0) {
855
+ const codes = report.ingest.reasonCodes.length ? report.ingest.reasonCodes : ["INGEST_NO_STRUCTURED_TOOL_ACTIVITY"];
856
+ const row = deriveQuickRemediationAlignment(codes);
857
+ items.push(makeRemediationItem({
858
+ id: "quick_ingest",
859
+ scope: "quick_ingest",
860
+ primary: true,
861
+ failedCheck: "quick verify ingest",
862
+ reasonCodes: codes,
863
+ reason: codes.join(","),
864
+ expectedSummary: "Expected structured tool activity that can be mapped into provisional read-only SQL checks.",
865
+ row,
866
+ evidenceToInspect: ["quick.ingest.reasonCodes", "quick.units"],
867
+ }));
868
+ }
869
+ for (const unit of report.units) {
870
+ if (unit.verdict === "verified")
871
+ continue;
872
+ const row = deriveQuickRemediationAlignment(unit.reasonCodes);
873
+ items.push(makeRemediationItem({
874
+ id: `quick:${unit.unitId}`,
875
+ scope: "quick_unit",
876
+ primary: items.length === 0,
877
+ failedCheck: `Failed check: quick unit ${unit.unitId}`,
878
+ reasonCodes: unit.reasonCodes.length ? unit.reasonCodes : [`quick_unit_${unit.verdict}`],
879
+ reason: unit.reconciliation.verification_verdict,
880
+ expectedSummary: unit.correctnessDefinition?.mustAlwaysHold ?? unit.reconciliation.expected,
881
+ projectionKind: unit.correctnessDefinition?.enforcementKind,
882
+ row,
883
+ evidenceToInspect: [`quick.units[id=${unit.unitId}]`, "quick.evidenceCompleteness"],
884
+ }));
885
+ }
886
+ return items.slice(0, 32);
887
+ }
888
+ function buildOrderedNextActionsWorkflow(result, primary) {
889
+ const out = [nextActionEntry(primary)];
890
+ const seen = new Set([primary]);
891
+ const C = collectWorkflowCodes(result);
892
+ if (C.has(SQL_VERIFICATION_OUTCOME_CODE.UNKNOWN_TOOL) && !seen.has("fix_registry_events_or_compare_files")) {
893
+ seen.add("fix_registry_events_or_compare_files");
894
+ out.push(nextActionEntry("fix_registry_events_or_compare_files"));
895
+ }
896
+ if (!(result.status === "complete" && primary === "none")) {
897
+ const sec = "fix_registry_events_or_compare_files";
898
+ if (!seen.has(sec)) {
899
+ seen.add(sec);
900
+ out.push(nextActionEntry(sec));
901
+ }
902
+ }
903
+ return out.slice(0, 5);
904
+ }
905
+ function deriveRerunReadinessWorkflow(actionableFailure, blocker, status) {
906
+ if (status === "complete" && actionableFailure.recommendedAction === "none")
907
+ return "rerun_ready_same_inputs";
908
+ if (actionableFailure.automationSafe &&
909
+ actionableFailure.recommendedAction === "improve_read_connectivity") {
910
+ return "rerun_ready_same_inputs";
911
+ }
912
+ switch (blocker) {
913
+ case "ingest_empty":
914
+ case "ingest_unstructured":
915
+ return "fix_inputs_before_rerun";
916
+ case "registry_unknown_tool":
917
+ case "registry_resolution":
918
+ return "fix_registry_before_rerun";
919
+ case "state_mismatch":
920
+ case "database_access":
921
+ return "reconcile_state_before_rerun";
922
+ case "verification_incomplete":
923
+ return "manual_review_before_rerun";
924
+ default:
925
+ return "manual_review_before_rerun";
926
+ }
927
+ }
928
+ function quickSignalFromReport(report) {
929
+ const ingest = report.ingest;
930
+ const units = report.units;
931
+ const verdict = report.verdict;
932
+ let quickSignal = "sql_ran_uncertain";
933
+ if (ingest.reasonCodes.includes("INGEST_NO_ACTIONS")) {
934
+ quickSignal = "no_actions";
935
+ }
936
+ else if (ingest.reasonCodes.includes("INGEST_NO_STRUCTURED_TOOL_ACTIVITY")) {
937
+ quickSignal = "no_structured_activity";
938
+ }
939
+ else if (units.length === 0) {
940
+ quickSignal = "no_sql_candidates";
941
+ }
942
+ else {
943
+ const mappedOk = units.filter((u) => !u.reasonCodes.includes("MAPPING_FAILED")).length > 0;
944
+ if (!mappedOk) {
945
+ quickSignal = "no_sql_candidates";
946
+ }
947
+ else if (verdict === "pass")
948
+ quickSignal = "sql_ran_passed";
949
+ else if (verdict === "fail")
950
+ quickSignal = "sql_ran_failed";
951
+ else
952
+ quickSignal = "sql_ran_uncertain";
953
+ }
954
+ return { quickSignal };
955
+ }
956
+ function classifyQuickPreviewBlocker(quickSignal, verdict) {
957
+ if (quickSignal === "no_actions")
958
+ return "ingest_empty";
959
+ if (quickSignal === "no_structured_activity")
960
+ return "ingest_unstructured";
961
+ if (quickSignal === "no_sql_candidates")
962
+ return "registry_resolution";
963
+ if (quickSignal === "sql_ran_failed")
964
+ return "state_mismatch";
965
+ if (verdict === "uncertain")
966
+ return "verification_incomplete";
967
+ return "preview_lane";
968
+ }
969
+ function buildOrderedNextActionsQuick(report, primary) {
970
+ const out = [nextActionEntry(primary)];
971
+ const seen = new Set([primary]);
972
+ if (report.verdict !== "pass") {
973
+ const sec = "fix_registry_events_or_compare_files";
974
+ if (!seen.has(sec)) {
975
+ seen.add(sec);
976
+ out.push(nextActionEntry(sec));
977
+ }
978
+ }
979
+ return out.slice(0, 5);
980
+ }
981
+ function deriveRerunReadinessQuick(blocker, verdict, actionableFailure) {
982
+ if (verdict === "pass")
983
+ return "rerun_ready_same_inputs";
984
+ if (actionableFailure.automationSafe &&
985
+ actionableFailure.recommendedAction === "improve_read_connectivity") {
986
+ return "rerun_ready_same_inputs";
987
+ }
988
+ switch (blocker) {
989
+ case "ingest_empty":
990
+ case "ingest_unstructured":
991
+ return "fix_inputs_before_rerun";
992
+ case "registry_resolution":
993
+ return "fix_registry_before_rerun";
994
+ case "state_mismatch":
995
+ return "reconcile_state_before_rerun";
996
+ case "verification_incomplete":
997
+ return "manual_review_before_rerun";
998
+ default:
999
+ return "manual_review_before_rerun";
1000
+ }
1001
+ }
1002
+ export function deriveRemediationDecisionFromWorkflowResult(result) {
1003
+ const truth = result.workflowTruthReport;
1004
+ const fa = truth.failureAnalysis;
1005
+ const engineSlice = workflowResultToEngineSlice(result);
1006
+ if (fa === null && result.status === "complete") {
1007
+ const noneFailure = {
1008
+ category: "unclassified",
1009
+ severity: "low",
1010
+ recommendedAction: "none",
1011
+ automationSafe: false,
1012
+ };
1013
+ return {
1014
+ actionableFailure: noneFailure,
1015
+ orderedNextActions: [nextActionEntry("none")],
1016
+ rerunReadiness: "rerun_ready_same_inputs",
1017
+ remediationItems: [],
1018
+ rerunPath: rerunPathForType("no_rerun_needed"),
1019
+ };
1020
+ }
1021
+ let actionableFailure;
1022
+ if (fa !== null) {
1023
+ actionableFailure = fa.actionableFailure;
1024
+ }
1025
+ else {
1026
+ actionableFailure = deriveActionableFailureWorkflow(engineSlice, syntheticFailureBaseWorkflow(result));
1027
+ }
1028
+ const blocker = classifyWorkflowBlocker(result);
1029
+ const orderedNextActions = buildOrderedNextActionsWorkflow(result, actionableFailure.recommendedAction);
1030
+ const rerunReadiness = deriveRerunReadinessWorkflow(actionableFailure, blocker, result.status);
1031
+ const remediationItems = buildWorkflowRemediationItems(result);
1032
+ const rerunPath = remediationItems.find((i) => i.primary)?.rerunPath ?? remediationItems[0]?.rerunPath ?? rerunPathForType("after_manual_review_verify");
1033
+ return { actionableFailure, orderedNextActions, rerunReadiness, remediationItems, rerunPath };
1034
+ }
1035
+ export function deriveRemediationDecisionFromQuickReport(report, workflowId) {
1036
+ const engine = quickVerifyReportToSyntheticEngine(report, workflowId);
1037
+ const fa = buildFailureAnalysis(engine);
1038
+ let actionableFailure;
1039
+ if (fa !== null) {
1040
+ actionableFailure = deriveActionableFailureWorkflow(engine, fa);
1041
+ }
1042
+ else {
1043
+ actionableFailure = deriveActionableFailureWorkflow(engine, syntheticQuickFailureAnalysis(report));
1044
+ }
1045
+ const { quickSignal } = quickSignalFromReport(report);
1046
+ const blocker = classifyQuickPreviewBlocker(quickSignal, report.verdict);
1047
+ const orderedNextActions = buildOrderedNextActionsQuick(report, actionableFailure.recommendedAction);
1048
+ const rerunReadiness = deriveRerunReadinessQuick(blocker, report.verdict, actionableFailure);
1049
+ const remediationItems = buildQuickRemediationItems(report);
1050
+ const rerunPath = report.verdict === "pass"
1051
+ ? rerunPathForType("no_rerun_needed")
1052
+ : remediationItems.find((i) => i.primary)?.rerunPath ??
1053
+ remediationItems[0]?.rerunPath ??
1054
+ rerunPathForType("after_manual_review_verify");
1055
+ return { actionableFailure, orderedNextActions, rerunReadiness, remediationItems, rerunPath };
1056
+ }
470
1057
  /** Longest run of consecutive integers contained in `sortedUniqueIndices`. */
471
1058
  export function maxConsecutiveStreak(sortedUniqueIndices) {
472
1059
  if (sortedUniqueIndices.length === 0)