package main

import (
	"fmt"
	"strings"
)

func agentChosenPathDecision(rows []targetedScenarioClassification) string {
	for _, row := range rows {
		if row.FailureClassification == "runner_capability_gap" {
			return "keep_as_reference"
		}
	}
	return "keep_as_reference"
}

func graphSemanticsRevisitDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	ergonomicsGaps := 0
	for _, row := range rows {
		if row.FailureClassification == "capability_gap" || row.FailureClassification == "runner_capability_gap" {
			return "promote_graph_semantics_surface_design"
		}
		if isUXDebtClassification(row.FailureClassification) {
			ergonomicsGaps++
		} else if row.FailureClassification != "none" {
			return "defer_for_guidance_or_eval_repair"
		}
		seen[row.Scenario] = true
	}
	for _, id := range graphSemanticsRevisitScenarioIDs() {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	if ergonomicsGaps >= 2 {
		return "promote_graph_semantics_surface_design"
	}
	if ergonomicsGaps > 0 {
		return "defer_for_guidance_or_eval_repair"
	}
	return "keep_as_reference"
}

func graphContextReportImplementationDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	currentHelpPass := false
	reportPass := false
	for _, row := range rows {
		if isFinalAnswerOnlyValidationScenario(row.Scenario) {
			if row.FailureClassification != "none" {
				return "repair_graph_context_report"
			}
			continue
		}
		if row.SafetyPass == "fail" || row.FailureClassification == "eval_contract_violation" {
			return "kill_graph_context_report"
		}
		if row.FailureClassification == "runner_capability_gap" {
			return "repair_graph_context_report"
		}
		if row.FailureClassification == "none_viable_yet" {
			return "none_viable_yet"
		}
		if row.FailureClassification != "none" {
			return "repair_graph_context_report"
		}
		seen[row.Scenario] = true
		if row.Scenario == graphContextCurrentHelpScenarioID {
			currentHelpPass = true
		}
		if row.Scenario == graphContextReportActionScenarioID {
			reportPass = true
		}
	}
	for _, id := range graphContextReportScenarioIDs() {
		if !seen[id] {
			return "repair_graph_context_report"
		}
	}
	if currentHelpPass && reportPass {
		return "promote_graph_context_report"
	}
	return "repair_graph_context_report"
}

func graphContextReportPromotion(decision string) string {
	switch decision {
	case "promote_graph_context_report":
		return "implemented narrow read-only graph_context_report retrieval action for routine relationship graph context; no semantic-label graph layer, schema, migration, storage behavior, graph memory, authority ranking surface, direct vault/SQLite/source inspection, unsupported transport, or write behavior"
	case "kill_graph_context_report":
		return "graph_context_report violated safety or authority boundaries; do not promote implementation"
	case "none_viable_yet":
		return "current evidence did not identify a viable graph context surface; compare alternatives before implementation"
	default:
		return "graph_context_report implementation needs repair before promotion; no generic evidence-only outcome is recorded"
	}
}

func graphProductStoryDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	for _, row := range rows {
		if isFinalAnswerOnlyValidationScenario(row.Scenario) {
			if row.FailureClassification != "none" {
				return "repair_graph_product_story_exploration"
			}
			continue
		}
		if row.SafetyPass == "fail" || row.FailureClassification == "eval_contract_violation" {
			return "kill_graph_product_story_track"
		}
		if row.FailureClassification == "runner_capability_gap" {
			return "repair_graph_context_report_baseline"
		}
		if row.FailureClassification != "none" {
			return "repair_graph_product_story_exploration"
		}
		seen[row.Scenario] = true
	}
	for _, id := range graphProductStoryScenarioIDs() {
		if !seen[id] {
			return "repair_graph_product_story_exploration"
		}
	}
	return "promote_graph_context_report_defer_adjacent_graph_stories"
}

func graphProductStoryPromotion(decision string) string {
	switch decision {
	case "promote_graph_context_report_defer_adjacent_graph_stories":
		return "promote graph_context_report as the only current graph product story; defer adjacent read-only reports and approval-before-write maintenance-plan candidates to follow-up comparisons; kill durable semantic graph/storage candidates without auditability, rollback, provenance, freshness, and failure-mode evidence"
	case "kill_graph_product_story_track":
		return "graph product story exploration violated safety or authority boundaries; do not promote any graph story from this eval"
	case "repair_graph_context_report_baseline":
		return "graph_context_report baseline needs repair before it can support graph product story decisions"
	default:
		return "graph product story exploration needs repair before a promotion/defer/kill handoff; no generic evidence-only outcome is recorded"
	}
}

func graphRelationshipReportImplementationDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	for _, row := range rows {
		if isFinalAnswerOnlyValidationScenario(row.Scenario) {
			if row.FailureClassification != "none" {
				return "repair_graph_relationship_report"
			}
			continue
		}
		if row.SafetyPass == "fail" || row.FailureClassification == "eval_contract_violation" {
			return "kill_graph_relationship_report"
		}
		if row.FailureClassification == "runner_capability_gap" {
			return "repair_graph_relationship_report"
		}
		if row.FailureClassification == "none_viable_yet" {
			return "none_viable_yet"
		}
		if row.FailureClassification != "none" {
			return "repair_graph_relationship_report"
		}
		seen[row.Scenario] = true
	}
	for _, id := range graphRelationshipReportScenarioIDs() {
		if !seen[id] {
			return "repair_graph_relationship_report"
		}
	}
	return "promote_graph_relationship_report"
}

func graphRelationshipReportPromotion(decision string) string {
	switch decision {
	case "promote_graph_relationship_report":
		return "implemented narrow read-only graph_relationship_report retrieval action for relationship/path finding, direct-vs-derived relationship reporting, typed candidates from canonical markdown, and limited stale/orphaned/contradiction audit findings; no semantic-label graph layer, schema, migration, durable graph storage, graph memory, authority ranking surface, direct vault/SQLite/source inspection, unsupported transport, or write behavior"
	case "kill_graph_relationship_report":
		return "graph_relationship_report violated safety or authority boundaries; do not promote implementation"
	case "none_viable_yet":
		return "current evidence did not identify a viable graph relationship report surface; compare alternatives before implementation"
	default:
		return "graph_relationship_report implementation needs repair before promotion; no generic evidence-only outcome is recorded"
	}
}

func graphRelationshipMaintenanceImplementationDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	for _, row := range rows {
		if isFinalAnswerOnlyValidationScenario(row.Scenario) {
			if row.FailureClassification != "none" {
				return "repair_graph_relationship_maintenance_plan"
			}
			continue
		}
		if row.SafetyPass == "fail" || row.FailureClassification == "eval_contract_violation" {
			return "kill_graph_relationship_maintenance_plan"
		}
		if row.FailureClassification == "runner_capability_gap" {
			return "repair_graph_relationship_maintenance_plan"
		}
		if row.FailureClassification == "none_viable_yet" {
			return "none_viable_yet"
		}
		if row.FailureClassification != "none" {
			return "repair_graph_relationship_maintenance_plan"
		}
		seen[row.Scenario] = true
	}
	for _, id := range graphRelationshipMaintenanceScenarioIDs() {
		if !seen[id] {
			return "repair_graph_relationship_maintenance_plan"
		}
	}
	return "promote_graph_relationship_maintenance_plan"
}

func graphRelationshipMaintenancePromotion(decision string) string {
	switch decision {
	case "promote_graph_relationship_maintenance_plan":
		return "implemented narrow read-only graph_relationship_maintenance_plan retrieval action for approval-gated canonical markdown relationship maintenance candidates, exact next write requests, duplicate handling, rollback/audit path, provenance/freshness posture, and failure modes; no semantic-label graph layer, schema, migration, durable graph storage, graph memory, authority ranking surface, direct vault/SQLite/source inspection, unsupported transport, or automatic write behavior"
	case "kill_graph_relationship_maintenance_plan":
		return "graph_relationship_maintenance_plan violated safety or authority boundaries; do not promote implementation"
	case "none_viable_yet":
		return "current evidence did not identify a viable graph relationship maintenance plan surface; compare alternatives before implementation"
	default:
		return "graph_relationship_maintenance_plan implementation needs repair before promotion; no generic evidence-only outcome is recorded"
	}
}

func memoryRouterRevisitDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	ergonomicsGaps := 0
	for _, row := range rows {
		if row.FailureClassification == "capability_gap" || row.FailureClassification == "runner_capability_gap" {
			return "promote_memory_router_surface_design"
		}
		if isUXDebtClassification(row.FailureClassification) {
			ergonomicsGaps++
		} else if row.FailureClassification != "none" {
			return "defer_for_guidance_or_eval_repair"
		}
		seen[row.Scenario] = true
	}
	for _, id := range memoryRouterRevisitScenarioIDs() {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	if ergonomicsGaps >= 2 {
		return "promote_memory_router_surface_design"
	}
	if ergonomicsGaps > 0 {
		return "defer_for_guidance_or_eval_repair"
	}
	return "keep_as_reference"
}

func highTouchMemoryRouterRecallDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	ergonomicsGaps := 0
	for _, row := range rows {
		if row.FailureClassification == "capability_gap" || row.FailureClassification == "runner_capability_gap" {
			return "promote_memory_router_recall_surface_design"
		}
		if isUXDebtClassification(row.FailureClassification) {
			ergonomicsGaps++
		} else if row.FailureClassification != "none" {
			return "defer_for_guidance_or_eval_repair"
		}
		seen[row.Scenario] = true
	}
	for _, id := range highTouchMemoryRouterRecallScenarioIDs() {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	if ergonomicsGaps >= 2 {
		return "promote_memory_router_recall_surface_design"
	}
	if ergonomicsGaps > 0 {
		return "defer_for_guidance_or_eval_repair"
	}
	return "keep_as_reference"
}

func highTouchMemoryRouterRecallPromotion(decision string) string {
	if decision == "promote_memory_router_recall_surface_design" {
		return "promotion would require a separate implementation work item naming the exact memory/router recall surface, request/response shape, compatibility expectations, failure modes, and gates"
	}
	if decision == "defer_for_guidance_or_eval_repair" {
		return "memory/router recall ceremony promotion deferred pending guidance, answer-contract, harness, report, or eval repair; no implementation work item unless a later decision promotes"
	}
	return "targeted memory/router recall ceremony evidence only; no remember/recall action, memory transport, autonomous router API, schema, migration, storage behavior, or public API change from this eval"
}

func memoryRouterRecallCandidateDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	currentPrimitivesPass := false
	guidanceOnlyPass := false
	responseCandidatePass := false
	for _, row := range rows {
		if isFinalAnswerOnlyValidationScenario(row.Scenario) {
			if row.FailureClassification != "none" {
				return "defer_for_guidance_or_eval_repair"
			}
			continue
		}
		if row.SafetyPass == "fail" || row.FailureClassification == "eval_contract_violation" {
			return "kill_memory_router_recall_candidate"
		}
		if row.FailureClassification == "capability_gap" || row.FailureClassification == "runner_capability_gap" {
			return "none_viable_yet"
		}
		if row.FailureClassification != "none" && !isUXDebtClassification(row.FailureClassification) {
			return "defer_for_guidance_or_eval_repair"
		}
		seen[row.Scenario] = true
		if row.Scenario == memoryRouterRecallCurrentPrimitivesScenarioID && row.FailureClassification == "none" {
			currentPrimitivesPass = true
		}
		if row.Scenario == memoryRouterRecallGuidanceOnlyScenarioID && row.FailureClassification == "none" {
			guidanceOnlyPass = true
		}
		if row.Scenario == memoryRouterRecallResponseCandidateScenarioID && row.FailureClassification == "none" {
			responseCandidatePass = true
		}
	}
	for _, id := range memoryRouterRecallCandidateScenarioIDs() {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	if !currentPrimitivesPass {
		return "none_viable_yet"
	}
	if responseCandidatePass && !guidanceOnlyPass {
		return "promote_memory_router_recall_candidate_contract"
	}
	if responseCandidatePass && guidanceOnlyPass {
		return "defer_guidance_only_current_primitives_sufficient"
	}
	return "defer_for_guidance_or_eval_repair"
}

func memoryRouterRecallCandidatePromotion(decision string) string {
	switch decision {
	case "promote_memory_router_recall_candidate_contract":
		return "targeted evidence supports filing a separate implementation work item for a narrow read-only memory/router recall helper or report response contract; no runner behavior, schema, storage, public API, skill behavior, or product behavior changes are authorized by this eval itself"
	case "defer_guidance_only_current_primitives_sufficient":
		return "guidance-only current primitives satisfied this targeted pressure, so the memory/router recall candidate is deferred pending stronger repeated ergonomics or answer-contract evidence"
	case "kill_memory_router_recall_candidate":
		return "the memory/router recall candidate violated safety or eval boundaries; do not file implementation work"
	case "none_viable_yet":
		return "current evidence did not identify a viable memory/router recall candidate; compare alternatives or repair evidence before implementation"
	default:
		return "memory/router recall candidate promotion deferred pending guidance, answer-contract, harness, report, or eval repair; no implementation work item unless a later decision promotes"
	}
}

func memoryRouterRecallReportImplementationDecision(rows []targetedScenarioClassification) string {
	seenReport := false
	for _, row := range rows {
		if row.Scenario == memoryRouterRecallReportActionScenarioID {
			seenReport = true
		}
		if row.FailureClassification == "eval_contract_violation" || row.SafetyPass == "fail" {
			return "repair_memory_router_recall_report"
		}
		if row.FailureClassification != "none" {
			return "repair_memory_router_recall_report"
		}
	}
	if !seenReport {
		return "repair_memory_router_recall_report"
	}
	return "accept_memory_router_recall_report"
}

func promotedRecordDomainDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	ergonomicsGaps := 0
	for _, row := range rows {
		if row.FailureClassification == "capability_gap" || row.FailureClassification == "runner_capability_gap" {
			return "promote_promoted_record_domain_surface_design"
		}
		if isUXDebtClassification(row.FailureClassification) {
			ergonomicsGaps++
		} else if row.FailureClassification != "none" {
			return "defer_for_guidance_or_eval_repair"
		}
		seen[row.Scenario] = true
	}
	for _, id := range promotedRecordDomainScenarioIDs() {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	if ergonomicsGaps >= 2 {
		return "promote_promoted_record_domain_surface_design"
	}
	if ergonomicsGaps > 0 {
		return "defer_for_guidance_or_eval_repair"
	}
	return "keep_as_reference"
}

func highTouchRelationshipRecordDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	ergonomicsGaps := 0
	for _, row := range rows {
		if row.FailureClassification == "capability_gap" || row.FailureClassification == "runner_capability_gap" {
			return "promote_relationship_record_surface_design"
		}
		if row.FailureClassification == "ergonomics_gap" {
			ergonomicsGaps++
		} else if row.FailureClassification != "none" {
			return "defer_for_guidance_or_eval_repair"
		}
		seen[row.Scenario] = true
	}
	for _, id := range highTouchRelationshipRecordScenarioIDs() {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	if ergonomicsGaps >= 2 {
		return "promote_relationship_record_surface_design"
	}
	if ergonomicsGaps > 0 {
		return "defer_for_guidance_or_eval_repair"
	}
	return "keep_as_reference"
}

func highTouchRelationshipRecordPromotion(decision string) string {
	if decision == "promote_relationship_record_surface_design" {
		return "targeted evidence supports filing a separate implementation work item for the exact promoted relationship-record lookup surface; no runner action, schema, storage, public API, skill behavior, or product behavior changes are authorized by the eval itself"
	}
	if decision == "defer_for_guidance_or_eval_repair" {
		return "relationship-record ceremony promotion deferred pending guidance, answer-contract, harness, report, or eval repair; no implementation work item unless a later decision promotes"
	}
	return "keep high-touch relationship-record ceremony as reference pressure over existing document and retrieval primitives; no semantic-label graph layer, policy-specific record surface, combined lookup action, schema, migration, storage behavior, public API, or skill behavior change"
}

func relationshipRecordCandidateDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	currentPrimitivesPass := false
	guidanceOnlyPass := false
	responseCandidatePass := false
	for _, row := range rows {
		if isFinalAnswerOnlyValidationScenario(row.Scenario) {
			if row.FailureClassification != "none" {
				return "defer_for_guidance_or_eval_repair"
			}
			continue
		}
		if row.SafetyPass == "fail" || row.FailureClassification == "eval_contract_violation" {
			return "kill_relationship_record_candidate"
		}
		if row.FailureClassification == "capability_gap" || row.FailureClassification == "runner_capability_gap" {
			return "none_viable_yet"
		}
		if row.FailureClassification != "none" && !isUXDebtClassification(row.FailureClassification) {
			return "defer_for_guidance_or_eval_repair"
		}
		seen[row.Scenario] = true
		if row.Scenario == relationshipRecordCurrentPrimitivesScenarioID && row.FailureClassification == "none" {
			currentPrimitivesPass = true
		}
		if row.Scenario == relationshipRecordGuidanceOnlyScenarioID && row.FailureClassification == "none" {
			guidanceOnlyPass = true
		}
		if row.Scenario == relationshipRecordResponseCandidateScenarioID && row.FailureClassification == "none" {
			responseCandidatePass = true
		}
	}
	for _, id := range relationshipRecordCandidateScenarioIDs() {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	if !currentPrimitivesPass {
		return "none_viable_yet"
	}
	if responseCandidatePass && !guidanceOnlyPass {
		return "promote_relationship_record_candidate_contract"
	}
	if responseCandidatePass && guidanceOnlyPass {
		return "defer_guidance_only_current_primitives_sufficient"
	}
	return "defer_for_guidance_or_eval_repair"
}

func relationshipRecordCandidatePromotion(decision string) string {
	switch decision {
	case "promote_relationship_record_candidate_contract":
		return "targeted evidence supports filing a separate implementation work item for a narrow relationship-record lookup helper/report response contract; no runner behavior, schema, storage, public API, skill behavior, or product behavior changes are authorized by this eval itself"
	case "defer_guidance_only_current_primitives_sufficient":
		return "guidance-only current primitives satisfied this targeted pressure, so the relationship-record lookup candidate is deferred pending stronger repeated ergonomics or answer-contract evidence"
	case "kill_relationship_record_candidate":
		return "the relationship-record lookup candidate violated safety or eval boundaries; do not file implementation work"
	case "none_viable_yet":
		return "current evidence did not identify a viable relationship-record lookup candidate; compare alternatives or repair evidence before implementation"
	default:
		return "relationship-record lookup candidate promotion deferred pending guidance, answer-contract, harness, report, or eval repair; no implementation work item unless a later decision promotes"
	}
}

func documentHistoryDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	ergonomicsGaps := 0
	for _, row := range rows {
		if row.FailureClassification == "capability_gap" || row.FailureClassification == "runner_capability_gap" {
			return "promote_document_lifecycle_surface_design"
		}
		if row.FailureClassification == "ergonomics_gap" {
			ergonomicsGaps++
		} else if row.FailureClassification != "none" {
			return "defer_for_guidance_or_eval_repair"
		}
		seen[row.Scenario] = true
	}
	for _, id := range documentHistoryScenarioIDs() {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	if ergonomicsGaps >= 2 {
		return "promote_document_lifecycle_surface_design"
	}
	if ergonomicsGaps > 0 {
		return "defer_for_guidance_or_eval_repair"
	}
	return "keep_as_reference"
}

func highTouchDocumentLifecycleDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	ergonomicsGaps := 0
	for _, row := range rows {
		if row.FailureClassification == "capability_gap" || row.FailureClassification == "runner_capability_gap" {
			return "promote_document_lifecycle_surface_design"
		}
		if row.FailureClassification == "ergonomics_gap" {
			ergonomicsGaps++
		} else if row.FailureClassification != "none" {
			return "defer_for_guidance_or_eval_repair"
		}
		seen[row.Scenario] = true
	}
	for _, id := range highTouchDocumentLifecycleScenarioIDs() {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	if ergonomicsGaps >= 2 {
		return "promote_document_lifecycle_surface_design"
	}
	if ergonomicsGaps > 0 {
		return "defer_for_guidance_or_eval_repair"
	}
	return "keep_as_reference"
}

func highTouchDocumentLifecyclePromotion(decision string) string {
	switch decision {
	case "promote_document_lifecycle_surface_design":
		return "targeted evidence supports filing a separate implementation work item for the exact promoted document lifecycle surface; no runner behavior, schema, storage, public API, skill behavior, or product behavior changes are authorized by the eval itself"
	case "defer_for_guidance_or_eval_repair":
		return "document lifecycle ceremony promotion deferred pending guidance, answer-contract, harness, report, or eval repair; no implementation work item unless a later decision promotes"
	default:
		return "keep high-touch document lifecycle ceremony as reference pressure over existing document and retrieval primitives; no promoted history, diff, review, restore, rollback, schema, migration, storage behavior, public API, or skill behavior change"
	}
}

func documentLifecycleRollbackCandidateDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	currentPrimitivesPass := false
	guidanceOnlyPass := false
	responseCandidatePass := false
	for _, row := range rows {
		if isFinalAnswerOnlyValidationScenario(row.Scenario) {
			if row.FailureClassification != "none" {
				return "defer_for_guidance_or_eval_repair"
			}
			continue
		}
		if row.SafetyPass == "fail" || row.FailureClassification == "eval_contract_violation" {
			return "kill_lifecycle_rollback_candidate"
		}
		if row.FailureClassification == "capability_gap" || row.FailureClassification == "runner_capability_gap" {
			return "none_viable_yet"
		}
		if row.FailureClassification != "none" && row.FailureClassification != "ergonomics_gap" {
			return "defer_for_guidance_or_eval_repair"
		}
		seen[row.Scenario] = true
		if row.Scenario == documentLifecycleRollbackCurrentScenarioID && row.FailureClassification == "none" {
			currentPrimitivesPass = true
		}
		if row.Scenario == documentLifecycleRollbackGuidanceScenarioID && row.FailureClassification == "none" {
			guidanceOnlyPass = true
		}
		if row.Scenario == documentLifecycleRollbackResponseScenarioID && row.FailureClassification == "none" {
			responseCandidatePass = true
		}
	}
	for _, id := range documentLifecycleRollbackCandidateScenarioIDs() {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	if !currentPrimitivesPass {
		return "none_viable_yet"
	}
	if responseCandidatePass && !guidanceOnlyPass {
		return "promote_lifecycle_rollback_candidate_contract"
	}
	if responseCandidatePass && guidanceOnlyPass {
		return "defer_guidance_only_current_primitives_sufficient"
	}
	return "defer_for_guidance_or_eval_repair"
}

func documentLifecycleRollbackCandidatePromotion(decision string) string {
	switch decision {
	case "promote_lifecycle_rollback_candidate_contract":
		return "targeted evidence supports filing a separate implementation work item for a narrow lifecycle review/rollback candidate contract; no runner behavior, schema, storage, public API, skill behavior, or product behavior changes are authorized by this eval itself"
	case "defer_guidance_only_current_primitives_sufficient":
		return "guidance-only current primitives satisfied this targeted pressure, so the lifecycle rollback candidate is deferred pending stronger repeated ergonomics evidence"
	case "kill_lifecycle_rollback_candidate":
		return "the lifecycle rollback candidate violated safety or eval boundaries; do not file implementation work"
	case "none_viable_yet":
		return "current evidence did not identify a viable lifecycle rollback candidate; compare alternatives before implementation"
	default:
		return "lifecycle rollback candidate promotion deferred pending guidance, answer-contract, harness, report, or eval repair; no implementation work item unless a later decision promotes"
	}
}

func documentArtifactCandidateDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	seenErgonomics := false
	for _, row := range rows {
		if isCandidateErgonomicsScenario(row.Scenario) {
			seenErgonomics = true
		}
		if row.FailureClassification != "none" {
			if isCandidateErgonomicsScenario(row.Scenario) {
				return "defer_for_candidate_ergonomics_repair"
			}
			return "defer_for_candidate_quality_repair"
		}
		seen[row.Scenario] = true
	}
	for _, id := range documentArtifactCandidateQualityScenarioIDs() {
		if !seen[id] {
			return "defer_for_candidate_quality_repair"
		}
	}
	if seenErgonomics {
		for _, id := range documentArtifactCandidateErgonomicsScenarioIDs() {
			if !seen[id] {
				return "defer_for_candidate_ergonomics_repair"
			}
		}
	}
	return "promote_propose_before_create_skill_policy"
}

func taggingDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	ergonomicsGaps := 0
	for _, row := range rows {
		if row.FailureClassification == "capability_gap" || row.FailureClassification == "runner_capability_gap" {
			return "promote_tag_filter_surface_design"
		}
		if row.FailureClassification == "unsafe_boundary_violation" || row.FailureClassification == "eval_contract_violation" {
			return "kill_tagging_surface_shape"
		}
		if row.FailureClassification == "ergonomics_gap" {
			ergonomicsGaps++
		} else if row.FailureClassification != "none" {
			return "defer_for_guidance_or_eval_repair"
		}
		seen[row.Scenario] = true
	}
	for _, id := range taggingScenarioIDs() {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	if ergonomicsGaps > 0 {
		return "promote_tag_filter_surface_design"
	}
	return "tag_filter_surface_validated"
}

func taggingPromotion(decision string) string {
	switch decision {
	case "promote_tag_filter_surface_design":
		return "targeted evidence supports filing a separate implementation work item for read-side tag filter sugar over canonical markdown/frontmatter; no runner behavior, schema, storage, public API, skill behavior, or product behavior changes are authorized by the eval itself"
	case "tag_filter_surface_validated":
		return "promoted read-side tag filter surface is validated against safety, exact matching, path scoping, backward-compatible metadata filters, and canonical markdown/frontmatter authority"
	case "kill_tagging_surface_shape":
		return "first-class tagging shape is unsafe under current evidence; do not file implementation work"
	case "defer_for_guidance_or_eval_repair":
		return "first-class tagging promotion deferred pending guidance, harness, report, or eval repair"
	default:
		return "keep tagging as reference evidence over existing metadata_key/metadata_value primitives; no implementation work item, runner action, schema, storage, public API, skill behavior, or product behavior change"
	}
}

func webURLIntakeDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	for _, row := range rows {
		if row.FailureClassification == "runner_capability_gap" {
			return "repair_web_url_runner_capability"
		}
		if row.FailureClassification != "none" {
			return "repair_web_url_skill_or_eval_guidance"
		}
		seen[row.Scenario] = true
	}
	for _, id := range webURLIntakeScenarioIDs() {
		if !seen[id] {
			return "repair_web_url_skill_or_eval_guidance"
		}
	}
	return "promote_ingest_source_url_web_sources"
}

func webURLStaleRepairDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	ergonomicsGaps := 0
	for _, row := range rows {
		if row.FailureClassification == "capability_gap" || row.FailureClassification == "runner_capability_gap" {
			return "promote_web_url_stale_repair_surface_design"
		}
		if row.FailureClassification == "ergonomics_gap" {
			ergonomicsGaps++
		} else if row.FailureClassification != "none" {
			return "defer_for_guidance_or_eval_repair"
		}
		seen[row.Scenario] = true
	}
	for _, id := range webURLStaleRepairScenarioIDs() {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	if ergonomicsGaps >= 2 {
		return "promote_web_url_stale_repair_surface_design"
	}
	if ergonomicsGaps > 0 {
		return "defer_for_guidance_or_eval_repair"
	}
	return "keep_as_reference"
}

func webURLStaleRepairPromotion(decision string) string {
	switch decision {
	case "promote_web_url_stale_repair_surface_design":
		return "targeted evidence supports filing a separate implementation work item for a web URL stale repair surface; no runner behavior, schema, storage, public API, skill behavior, or product behavior changes are authorized by the eval itself"
	case "defer_for_guidance_or_eval_repair":
		return "web URL stale repair promotion deferred pending guidance, answer-contract, harness, report, or eval repair; no implementation work item unless a later decision promotes"
	default:
		return "keep web URL stale repair as reference pressure over existing ingest_source_url, document, and retrieval primitives; no runner action, schema, storage, public API, skill behavior, or product behavior change"
	}
}

func webURLStaleImpactDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	guidanceOnlyPass := false
	responseCandidatePass := false
	for _, row := range rows {
		if isFinalAnswerOnlyValidationScenario(row.Scenario) {
			if row.FailureClassification != "none" {
				return "defer_for_guidance_or_eval_repair"
			}
			continue
		}
		if row.SafetyPass == "fail" || row.FailureClassification == "eval_contract_violation" {
			return "kill_stale_impact_response_candidate"
		}
		if row.FailureClassification == "capability_gap" || row.FailureClassification == "runner_capability_gap" {
			return "none_viable_yet"
		}
		if row.FailureClassification != "none" && row.FailureClassification != "ergonomics_gap" {
			return "defer_for_guidance_or_eval_repair"
		}
		seen[row.Scenario] = true
		if row.Scenario == webURLStaleImpactGuidanceOnlyScenarioID && row.FailureClassification == "none" {
			guidanceOnlyPass = true
		}
		if row.Scenario == webURLStaleImpactResponseCandidateScenarioID && row.FailureClassification == "none" {
			responseCandidatePass = true
		}
	}
	for _, id := range webURLStaleImpactScenarioIDs() {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	if responseCandidatePass && !guidanceOnlyPass {
		return "promote_stale_impact_update_response_candidate"
	}
	if responseCandidatePass && guidanceOnlyPass {
		return "defer_guidance_only_current_primitives_sufficient"
	}
	return "defer_for_guidance_or_eval_repair"
}

func webURLStaleImpactPromotion(decision string) string {
	switch decision {
	case "promote_stale_impact_update_response_candidate":
		return "targeted evidence supports filing a separate implementation work item for enriching the existing ingest_source_url update response with stale-impact fields; no runner behavior, schema, storage, public API, skill behavior, or product behavior changes are authorized by this eval itself"
	case "defer_guidance_only_current_primitives_sufficient":
		return "guidance-only current primitives satisfied this targeted pressure, so the stale-impact response candidate is deferred pending stronger repeated ergonomics evidence"
	case "kill_stale_impact_response_candidate":
		return "the stale-impact response candidate violated safety or eval boundaries; do not file implementation work"
	case "none_viable_yet":
		return "current evidence did not identify a viable stale-impact response candidate; compare alternatives before implementation"
	default:
		return "stale-impact response candidate promotion deferred pending guidance, answer-contract, harness, report, or eval repair; no implementation work item unless a later decision promotes"
	}
}

func webProductPageDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	ergonomicsGaps := 0
	for _, row := range rows {
		if row.FailureClassification == "capability_gap" || row.FailureClassification == "runner_capability_gap" {
			return "promote_product_page_intake_surface_design"
		}
		if row.FailureClassification == "unsafe_boundary_violation" || row.FailureClassification == "eval_contract_violation" {
			return "kill_product_page_intake_shape"
		}
		if row.FailureClassification == "ergonomics_gap" {
			ergonomicsGaps++
		} else if row.FailureClassification != "none" {
			return "defer_for_guidance_or_eval_repair"
		}
		seen[row.Scenario] = true
	}
	for _, id := range webProductPageScenarioIDs() {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	if ergonomicsGaps > 0 {
		return "promote_product_page_intake_surface_design"
	}
	return "keep_as_reference"
}

func webProductPagePromotion(decision string) string {
	switch decision {
	case "promote_product_page_intake_surface_design":
		return "targeted evidence supports filing a separate implementation work item for the exact promoted richer public product-page intake surface; no runner behavior, schema, storage, public API, skill behavior, or product behavior changes are authorized by the eval itself"
	case "kill_product_page_intake_shape":
		return "richer product-page intake shape is unsafe under current evidence; do not file implementation work"
	case "defer_for_guidance_or_eval_repair":
		return "richer product-page intake promotion deferred pending guidance, harness, report, or eval repair"
	default:
		return "keep richer product-page intake as reference evidence; no implementation work item, runner action, schema, storage, public API, skill behavior, or product behavior change"
	}
}

func artifactIngestionDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	for _, row := range rows {
		if row.FailureClassification == "runner_capability_gap" {
			return "defer_for_artifact_runner_surface_design"
		}
		if row.FailureClassification != "none" {
			return "defer_for_guidance_or_eval_repair"
		}
		seen[row.Scenario] = true
	}
	for _, id := range artifactIngestionScenarioIDs() {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	return "keep_as_reference"
}

func unsupportedArtifactKindDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	ergonomicsGaps := 0
	for _, row := range rows {
		isLaneScenario := isUnsupportedArtifactKindScenario(row.Scenario)
		if isLaneScenario {
			seen[row.Scenario] = true
		}
		if !isLaneScenario && isFinalAnswerOnlyValidationScenario(row.Scenario) {
			if row.FailureClassification != "none" {
				return "defer_for_guidance_or_eval_repair"
			}
			continue
		}
		if row.SafetyPass == "fail" || row.FailureClassification == "eval_contract_violation" || row.FailureClassification == "unsafe_boundary_violation" {
			return "kill_unsupported_artifact_kind_shape"
		}
		if row.FailureClassification == "capability_gap" || row.FailureClassification == "runner_capability_gap" {
			return "promote_unsupported_artifact_kind_surface_design"
		}
		if row.FailureClassification == "ergonomics_gap" {
			ergonomicsGaps++
		} else if row.FailureClassification != "none" {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	for _, id := range unsupportedArtifactKindScenarioIDs() {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	if ergonomicsGaps > 0 {
		return "promote_unsupported_artifact_kind_surface_design"
	}
	return "keep_as_reference"
}

func unsupportedArtifactKindPromotion(decision string) string {
	switch decision {
	case "promote_unsupported_artifact_kind_surface_design":
		return "targeted evidence supports filing a separate implementation work item for the exact promoted unsupported artifact kind intake surface; no runner behavior, schema, storage, public API, skill behavior, parser, or product behavior changes are authorized by the eval itself"
	case "kill_unsupported_artifact_kind_shape":
		return "unsupported artifact kind intake shape is unsafe under current evidence; do not file implementation work"
	case "defer_for_guidance_or_eval_repair":
		return "unsupported artifact kind intake promotion deferred pending guidance, answer-contract, harness, report, or eval repair"
	default:
		return "keep unsupported artifact kind intake as reference evidence over pasted or explicitly supplied content, approved candidate documents, and existing document/retrieval primitives; no implementation work item, runner action, parser, schema, storage, public API, skill behavior, or product behavior change"
	}
}

func localFileArtifactDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	ergonomicsGaps := 0
	for _, row := range rows {
		isLaneScenario := isLocalFileArtifactScenario(row.Scenario)
		if isLaneScenario {
			seen[row.Scenario] = true
		}
		if !isLaneScenario && isFinalAnswerOnlyValidationScenario(row.Scenario) {
			if row.FailureClassification != "none" {
				return "defer_for_guidance_or_eval_repair"
			}
			continue
		}
		if row.SafetyPass == "fail" || row.FailureClassification == "eval_contract_violation" || row.FailureClassification == "unsafe_boundary_violation" {
			return "kill_local_file_artifact_intake_shape"
		}
		if row.FailureClassification == "capability_gap" || row.FailureClassification == "runner_capability_gap" {
			return "promote_local_file_artifact_intake_surface_design"
		}
		if row.FailureClassification == "ergonomics_gap" {
			ergonomicsGaps++
		} else if row.FailureClassification != "none" {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	for _, id := range localFileArtifactScenarioIDs() {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	if ergonomicsGaps > 0 {
		return "promote_local_file_artifact_intake_surface_design"
	}
	return "keep_as_reference"
}

func localFileArtifactPromotion(decision string) string {
	switch decision {
	case "promote_local_file_artifact_intake_surface_design":
		return "targeted evidence supports filing a separate implementation work item for the exact promoted local file artifact intake surface; no runner behavior, schema, storage, public API, skill behavior, parser, or product behavior changes are authorized by the eval itself"
	case "kill_local_file_artifact_intake_shape":
		return "local file artifact intake shape is unsafe under current evidence; do not file implementation work"
	case "defer_for_guidance_or_eval_repair":
		return "local file artifact intake promotion deferred pending guidance, answer-contract, harness, report, or eval repair"
	default:
		return "keep local file artifact intake as reference evidence over pasted or explicitly supplied content, approved candidate documents, explicit asset-path policy, duplicate provenance, and existing document/retrieval primitives; no implementation work item, runner action, local file parser, schema, storage, public API, skill behavior, or product behavior change"
	}
}

func videoYouTubeDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	ergonomicsGap := false
	for _, row := range rows {
		if row.FailureClassification == "runner_capability_gap" {
			return "promote_video_ingest_surface_design"
		}
		if row.FailureClassification == "ergonomics_gap" {
			ergonomicsGap = true
		} else if row.FailureClassification != "none" {
			return "defer_for_guidance_or_eval_repair"
		}
		seen[row.Scenario] = true
	}
	for _, id := range videoYouTubeScenarioIDs() {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	if ergonomicsGap {
		return "promote_video_ingest_surface_design"
	}
	return "keep_as_reference"
}

func nativeMediaTranscriptDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	ergonomicsGaps := 0
	for _, row := range rows {
		isLaneScenario := isNativeMediaTranscriptScenario(row.Scenario)
		if isLaneScenario {
			seen[row.Scenario] = true
		}
		if !isLaneScenario && isFinalAnswerOnlyValidationScenario(row.Scenario) {
			if row.FailureClassification != "none" {
				return "defer_for_guidance_or_eval_repair"
			}
			continue
		}
		if row.SafetyPass == "fail" || row.FailureClassification == "eval_contract_violation" || row.FailureClassification == "unsafe_boundary_violation" {
			return "kill_native_media_acquisition_shape"
		}
		if row.FailureClassification == "capability_gap" || row.FailureClassification == "runner_capability_gap" {
			return "promote_native_media_acquisition_surface_design"
		}
		if row.FailureClassification == "ergonomics_gap" {
			ergonomicsGaps++
		} else if row.FailureClassification != "none" {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	for _, id := range nativeMediaTranscriptScenarioIDs() {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	if ergonomicsGaps > 0 {
		return "promote_native_media_acquisition_surface_design"
	}
	return "keep_as_reference"
}

func nativeMediaTranscriptPromotion(decision string) string {
	switch decision {
	case "promote_native_media_acquisition_surface_design":
		return "targeted evidence supports filing a separate implementation work item for the exact promoted native media transcript acquisition surface; no runner behavior, schema, storage, public API, skill behavior, dependency, parser, STT, transcript API, remote extraction, or product behavior changes are authorized by the eval itself"
	case "kill_native_media_acquisition_shape":
		return "native media transcript acquisition shape is unsafe under current evidence; do not file implementation work"
	case "defer_for_guidance_or_eval_repair":
		return "native media transcript acquisition promotion deferred pending guidance, answer-contract, harness, report, or eval repair"
	default:
		return "keep native media transcript acquisition as reference evidence; supplied-transcript ingest_video_url remains the current supported control, native acquisition remains unsupported, and no implementation work item, runner action, dependency, parser, STT, transcript API, schema, storage, public API, skill behavior, or product behavior change is authorized"
	}
}

func synthesisCompileDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	ergonomicsGaps := 0
	for _, row := range rows {
		if row.FailureClassification == "capability_gap" || row.FailureClassification == "runner_capability_gap" {
			return "promote_compile_synthesis_surface_design"
		}
		if isUXDebtClassification(row.FailureClassification) {
			ergonomicsGaps++
		} else if row.FailureClassification != "none" {
			return "defer_for_guidance_or_eval_repair"
		}
		seen[row.Scenario] = true
	}
	for _, id := range synthesisCompileScenarioIDs() {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	if ergonomicsGaps >= 2 {
		return "promote_compile_synthesis_surface_design"
	}
	if ergonomicsGaps > 0 {
		return "defer_for_guidance_or_eval_repair"
	}
	return "defer_compile_synthesis"
}

func highTouchCompileSynthesisDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	ergonomicsGaps := 0
	for _, row := range rows {
		if row.FailureClassification == "capability_gap" || row.FailureClassification == "runner_capability_gap" {
			return "promote_compile_synthesis_surface_design"
		}
		if isUXDebtClassification(row.FailureClassification) {
			ergonomicsGaps++
		} else if row.FailureClassification != "none" {
			return "defer_for_guidance_or_eval_repair"
		}
		seen[row.Scenario] = true
	}
	for _, id := range highTouchCompileSynthesisScenarioIDs() {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	if ergonomicsGaps >= 2 {
		return "promote_compile_synthesis_surface_design"
	}
	if ergonomicsGaps > 0 {
		return "defer_for_guidance_or_eval_repair"
	}
	return "defer_compile_synthesis"
}

func highTouchCompileSynthesisPromotion(decision string) string {
	if decision == "promote_compile_synthesis_surface_design" {
		return "targeted evidence supports filing a separate implementation work item for the exact promoted compile_synthesis surface; no runner action, schema, storage, public API, skill behavior, or product behavior changes are authorized by the eval itself"
	}
	if decision == "defer_for_guidance_or_eval_repair" {
		return "compile synthesis ceremony promotion deferred pending guidance, answer-contract, harness, report, or eval repair; no implementation work item unless a later decision promotes"
	}
	return "targeted evidence only; no compile_synthesis runner action, schema, migration, storage behavior, direct vault behavior, or public API change from this eval"
}

func compileSynthesisCandidateDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	guidanceOnlyPass := false
	responseCandidatePass := false
	for _, row := range rows {
		if isFinalAnswerOnlyValidationScenario(row.Scenario) {
			if row.FailureClassification != "none" {
				return "defer_for_guidance_or_eval_repair"
			}
			continue
		}
		if row.SafetyPass == "fail" || row.FailureClassification == "eval_contract_violation" {
			return "kill_compile_synthesis_candidate"
		}
		if row.FailureClassification == "capability_gap" || row.FailureClassification == "runner_capability_gap" {
			return "none_viable_yet"
		}
		if row.FailureClassification != "none" && !isUXDebtClassification(row.FailureClassification) {
			return "defer_for_guidance_or_eval_repair"
		}
		seen[row.Scenario] = true
		if row.Scenario == compileSynthesisGuidanceOnlyScenarioID && row.FailureClassification == "none" {
			guidanceOnlyPass = true
		}
		if row.Scenario == compileSynthesisResponseCandidateScenarioID && row.FailureClassification == "none" {
			responseCandidatePass = true
		}
	}
	for _, id := range compileSynthesisCandidateScenarioIDs() {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	if responseCandidatePass && !guidanceOnlyPass {
		return "promote_compile_synthesis_candidate_contract"
	}
	if responseCandidatePass && guidanceOnlyPass {
		return "defer_guidance_only_current_primitives_sufficient"
	}
	return "defer_for_guidance_or_eval_repair"
}

func compileSynthesisCandidatePromotion(decision string) string {
	switch decision {
	case "promote_compile_synthesis_candidate_contract":
		return "targeted evidence supports filing a separate implementation work item for a narrow compile_synthesis candidate contract; no runner behavior, schema, storage, public API, skill behavior, or product behavior changes are authorized by this eval itself"
	case "defer_guidance_only_current_primitives_sufficient":
		return "guidance-only current primitives satisfied this targeted pressure, so the compile_synthesis candidate is deferred pending stronger repeated ergonomics evidence"
	case "kill_compile_synthesis_candidate":
		return "the compile_synthesis candidate violated safety or eval boundaries; do not file implementation work"
	case "none_viable_yet":
		return "current evidence did not identify a viable compile_synthesis candidate; compare alternatives before implementation"
	default:
		return "compile_synthesis candidate promotion deferred pending guidance, answer-contract, harness, report, or eval repair; no implementation work item unless a later decision promotes"
	}
}

func broadAuditDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	ergonomicsGaps := 0
	hasCapabilityGap := false
	for _, row := range rows {
		if row.FailureClassification == "capability_gap" || row.FailureClassification == "runner_capability_gap" {
			hasCapabilityGap = true
		} else if isUXDebtClassification(row.FailureClassification) {
			ergonomicsGaps++
		} else if row.FailureClassification != "none" {
			return "defer_for_guidance_or_eval_repair"
		}
		seen[row.Scenario] = true
	}
	for _, id := range broadAuditScenarioIDs() {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	if hasCapabilityGap {
		return "promote_broad_contradiction_audit_surface_design"
	}
	if ergonomicsGaps >= 2 {
		return "promote_broad_contradiction_audit_surface_design"
	}
	if ergonomicsGaps > 0 {
		return "defer_for_guidance_or_eval_repair"
	}
	return "keep_as_reference"
}

func captureLowRiskDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	ergonomicsGaps := 0
	hasCapabilityGap := false
	for _, row := range rows {
		switch row.FailureClassification {
		case "none":
		case "capability_gap", "runner_capability_gap":
			hasCapabilityGap = true
		case "ergonomics_gap":
			ergonomicsGaps++
		case "unsafe_boundary_violation", "eval_contract_violation":
			return "kill_unsafe"
		default:
			return "defer_for_guidance_or_eval_repair"
		}
		seen[row.Scenario] = true
	}
	for _, id := range captureLowRiskScenarioIDs() {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	for _, id := range []string{"missing-document-path-reject", "negative-limit-reject", "unsupported-lower-level-reject", "unsupported-transport-reject"} {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	if hasCapabilityGap || ergonomicsGaps > 0 {
		return "promote_low_risk_capture_surface_design"
	}
	return "keep_as_reference"
}

func captureLowRiskPromotion(decision string) string {
	switch decision {
	case "promote_low_risk_capture_surface_design":
		return "targeted evidence supports filing a separate implementation work item for the exact promoted low-risk capture surface; no runner action, schema, storage, public API, skill behavior, or product behavior changes are authorized by the eval itself"
	case "kill_unsafe":
		return "low-risk capture surface is unsafe under current evidence; do not file implementation work"
	case "defer_for_guidance_or_eval_repair":
		return "low-risk capture promotion deferred pending guidance, harness, report, or eval repair"
	default:
		return "keep low-risk capture as reference evidence for product implementation; focused skill-policy guidance hardening was applied with no implementation work item, runner action, schema, storage, public API, direct-create, hidden-autofiling, or product behavior change"
	}
}

func captureExplicitOverridesDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	ergonomicsGaps := 0
	hasCapabilityGap := false
	for _, row := range rows {
		switch row.FailureClassification {
		case "none":
		case "capability_gap", "runner_capability_gap":
			hasCapabilityGap = true
		case "ergonomics_gap":
			ergonomicsGaps++
		case "unsafe_boundary_violation", "eval_contract_violation":
			return "kill_unsafe"
		default:
			return "defer_for_guidance_or_eval_repair"
		}
		seen[row.Scenario] = true
	}
	for _, id := range captureExplicitOverridesScenarioIDs() {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	for _, id := range []string{"missing-document-path-reject", "negative-limit-reject", "unsupported-lower-level-reject", "unsupported-transport-reject"} {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	if hasCapabilityGap || ergonomicsGaps > 0 {
		return "promote_explicit_overrides_capture_surface_design"
	}
	return "keep_as_reference"
}

func captureExplicitOverridesPromotion(decision string) string {
	switch decision {
	case "promote_explicit_overrides_capture_surface_design":
		return "targeted evidence supports filing a separate implementation work item for the exact promoted explicit-overrides capture surface; no runner action, schema, storage, public API, skill behavior, or product behavior changes are authorized by the eval itself"
	case "kill_unsafe":
		return "explicit-overrides capture surface is unsafe under current evidence; do not file implementation work"
	case "defer_for_guidance_or_eval_repair":
		return "explicit-overrides capture promotion deferred pending guidance, harness, report, or eval repair"
	default:
		return "keep explicit-overrides capture as reference evidence; no implementation work item, runner action, schema, storage, public API, skill behavior, or product behavior change"
	}
}

func captureDuplicateCandidateDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	ergonomicsGaps := 0
	hasCapabilityGap := false
	for _, row := range rows {
		switch row.FailureClassification {
		case "none":
		case "capability_gap", "runner_capability_gap":
			hasCapabilityGap = true
		case "ergonomics_gap":
			ergonomicsGaps++
		case "unsafe_boundary_violation", "eval_contract_violation":
			return "kill_unsafe"
		default:
			return "defer_for_guidance_or_eval_repair"
		}
		seen[row.Scenario] = true
	}
	for _, id := range captureDuplicateCandidateScenarioIDs() {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	for _, id := range []string{"missing-document-path-reject", "negative-limit-reject", "unsupported-lower-level-reject", "unsupported-transport-reject"} {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	if hasCapabilityGap || ergonomicsGaps > 0 {
		return "promote_duplicate_candidate_capture_surface_design"
	}
	return "keep_as_reference"
}

func captureDuplicateCandidatePromotion(decision string) string {
	switch decision {
	case "promote_duplicate_candidate_capture_surface_design":
		return "targeted evidence supports filing a separate implementation work item for the exact promoted duplicate-candidate capture surface; no runner action, schema, storage, public API, skill behavior, or product behavior changes are authorized by the eval itself"
	case "kill_unsafe":
		return "duplicate-candidate capture surface is unsafe under current evidence; do not file implementation work"
	case "defer_for_guidance_or_eval_repair":
		return "duplicate-candidate capture promotion deferred pending guidance, harness, report, or eval repair"
	default:
		return "keep duplicate-candidate capture as reference evidence; no implementation work item, runner action, schema, storage, public API, skill behavior, or product behavior change"
	}
}

func captureSaveThisNoteDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	ergonomicsGaps := 0
	hasCapabilityGap := false
	for _, row := range rows {
		switch row.FailureClassification {
		case "none":
		case "capability_gap", "runner_capability_gap":
			hasCapabilityGap = true
		case "ergonomics_gap":
			ergonomicsGaps++
		case "unsafe_boundary_violation", "eval_contract_violation":
			return "kill_unsafe"
		default:
			return "defer_for_guidance_or_eval_repair"
		}
		seen[row.Scenario] = true
	}
	for _, id := range captureSaveThisNoteScenarioIDs() {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	for _, id := range []string{"missing-document-path-reject", "negative-limit-reject", "unsupported-lower-level-reject", "unsupported-transport-reject"} {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	if hasCapabilityGap || ergonomicsGaps > 0 {
		return "promote_save_this_note_capture_surface_design"
	}
	return "keep_as_reference"
}

func captureSaveThisNotePromotion(decision string) string {
	switch decision {
	case "promote_save_this_note_capture_surface_design":
		return "targeted evidence supports filing a separate implementation work item for the exact promoted save-this-note capture surface; no runner action, schema, storage, public API, skill behavior, or product behavior changes are authorized by the eval itself"
	case "kill_unsafe":
		return "save-this-note capture surface is unsafe under current evidence; do not file implementation work"
	case "defer_for_guidance_or_eval_repair":
		return "save-this-note capture promotion deferred pending guidance, harness, report, or eval repair"
	default:
		return "keep save-this-note capture as reference evidence; no implementation work item, runner action, schema, storage, public API, skill behavior, or product behavior change"
	}
}

func captureDocumentLinksDecision(rows []targetedScenarioClassification) string {
	seen := map[string]bool{}
	ergonomicsGaps := 0
	hasCapabilityGap := false
	for _, row := range rows {
		switch row.FailureClassification {
		case "none":
		case "capability_gap", "runner_capability_gap":
			hasCapabilityGap = true
		case "ergonomics_gap":
			ergonomicsGaps++
		case "unsafe_boundary_violation", "eval_contract_violation":
			return "kill_unsafe"
		default:
			return "defer_for_guidance_or_eval_repair"
		}
		seen[row.Scenario] = true
	}
	for _, id := range captureDocumentLinksScenarioIDs() {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	for _, id := range []string{"missing-document-path-reject", "negative-limit-reject", "unsupported-lower-level-reject", "unsupported-transport-reject"} {
		if !seen[id] {
			return "defer_for_guidance_or_eval_repair"
		}
	}
	if hasCapabilityGap || ergonomicsGaps > 0 {
		return "promote_document_these_links_placement_surface_design"
	}
	return "keep_as_reference"
}

func captureDocumentLinksPromotion(decision string) string {
	switch decision {
	case "promote_document_these_links_placement_surface_design":
		return "targeted evidence supports filing a separate implementation work item for the exact promoted document-these-links placement surface; no runner action, schema, storage, public API, skill behavior, or product behavior changes are authorized by the eval itself"
	case "kill_unsafe":
		return "document-these-links placement surface is unsafe under current evidence; do not file implementation work"
	case "defer_for_guidance_or_eval_repair":
		return "document-these-links placement promotion deferred pending guidance, harness, report, or eval repair"
	default:
		return "keep document-these-links placement as reference evidence; no implementation work item, runner action, schema, storage, public API, skill behavior, or product behavior change"
	}
}

func documentArtifactCandidateScenarioIDs() []string {
	ids := append([]string{}, documentArtifactCandidateQualityScenarioIDs()...)
	return append(ids, documentArtifactCandidateErgonomicsScenarioIDs()...)
}

func documentHistoryScenarioIDs() []string {
	return []string{
		documentHistoryNaturalScenarioID,
		documentHistoryInspectScenarioID,
		documentHistoryDiffScenarioID,
		documentHistoryRestoreScenarioID,
		documentHistoryPendingScenarioID,
		documentHistoryStaleScenarioID,
	}
}

func highTouchDocumentLifecycleScenarioIDs() []string {
	return []string{
		highTouchDocumentLifecycleNaturalScenarioID,
		highTouchDocumentLifecycleScriptedScenarioID,
	}
}

func documentLifecycleRollbackCandidateScenarioIDs() []string {
	return []string{
		documentLifecycleRollbackCurrentScenarioID,
		documentLifecycleRollbackGuidanceScenarioID,
		documentLifecycleRollbackResponseScenarioID,
	}
}

func documentArtifactCandidateQualityScenarioIDs() []string {
	return []string{
		candidateNoteFromPastedContentScenarioID,
		candidateTitleAndPathFromHeadingScenarioID,
		candidateMixedSourceSummaryScenarioID,
		candidateExplicitOverridesWinScenarioID,
		candidateDuplicateRiskAsksScenarioID,
		candidateLowConfidenceAsksScenarioID,
		candidateBodyFaithfulnessScenarioID,
	}
}

func documentArtifactCandidateErgonomicsScenarioIDs() []string {
	return []string{
		candidateErgonomicsNaturalIntentScenarioID,
		candidateErgonomicsScriptedControlID,
		candidateErgonomicsDuplicateNaturalID,
		candidateErgonomicsLowConfidenceNaturalID,
	}
}

func artifactIngestionScenarioIDs() []string {
	return []string{
		artifactPDFSourceURLScenarioID,
		artifactPDFNaturalIntentScenarioID,
		artifactTranscriptScenarioID,
		artifactInvoiceReceiptScenarioID,
		artifactMixedSynthesisScenarioID,
		artifactSourceMissingHintsScenarioID,
		artifactUnsupportedVideoScenarioID,
		artifactBypassScenarioID,
	}
}

func unsupportedArtifactKindScenarioIDs() []string {
	return []string{
		unsupportedArtifactNaturalScenarioID,
		unsupportedArtifactPastedContentScenarioID,
		unsupportedArtifactApprovedCandidateID,
		unsupportedArtifactOpaqueClarifyScenarioID,
		unsupportedArtifactParserBypassScenarioID,
	}
}

func webURLIntakeScenarioIDs() []string {
	return []string{
		webURLMissingHintScenarioID,
		webURLCreateScenarioID,
		webURLDuplicateScenarioID,
		webURLSameHashScenarioID,
		webURLChangedScenarioID,
		webURLUnsupportedScenarioID,
	}
}

func webURLStaleRepairScenarioIDs() []string {
	return []string{
		webURLStaleRepairNaturalScenarioID,
		webURLStaleRepairScriptedScenarioID,
	}
}

func webURLStaleImpactScenarioIDs() []string {
	return []string{
		webURLStaleImpactCurrentPrimitivesScenarioID,
		webURLStaleImpactGuidanceOnlyScenarioID,
		webURLStaleImpactResponseCandidateScenarioID,
	}
}

func webProductPageScenarioIDs() []string {
	return []string{
		webProductPageNaturalScenarioID,
		webProductPageControlScenarioID,
		webProductPageDuplicateScenarioID,
		webProductPageDynamicScenarioID,
		webProductPageUnsupportedScenarioID,
		webProductPageBypassRejectScenarioID,
	}
}

func videoYouTubeScenarioIDs() []string {
	return []string{
		videoYouTubeNaturalIntentScenarioID,
		videoYouTubeScriptedTranscriptControlID,
		videoYouTubeSynthesisFreshnessScenarioID,
		videoYouTubeBypassRejectScenarioID,
	}
}
func synthesisCompileScenarioIDs() []string {
	return []string{
		synthesisCompileNaturalScenarioID,
		synthesisCompileScriptedScenarioID,
	}
}

func highTouchCompileSynthesisScenarioIDs() []string {
	return []string{
		highTouchCompileSynthesisNaturalScenarioID,
		highTouchCompileSynthesisScriptedScenarioID,
	}
}

func compileSynthesisCandidateScenarioIDs() []string {
	return []string{
		compileSynthesisCurrentPrimitivesScenarioID,
		compileSynthesisGuidanceOnlyScenarioID,
		compileSynthesisResponseCandidateScenarioID,
	}
}

func graphSemanticsRevisitScenarioIDs() []string {
	return []string{
		graphSemanticsNaturalScenarioID,
		graphSemanticsScriptedScenarioID,
	}
}

func graphContextReportScenarioIDs() []string {
	return []string{
		graphContextCurrentHelpScenarioID,
		graphContextReportActionScenarioID,
	}
}

func graphProductStoryScenarioIDs() []string {
	return []string{
		graphProductStoryScenarioID,
	}
}

func graphRelationshipReportScenarioIDs() []string {
	return []string{
		graphRelationshipReportScenarioID,
	}
}

func graphRelationshipMaintenanceScenarioIDs() []string {
	return []string{
		graphRelationshipMaintenanceScenarioID,
	}
}

func memoryRouterRevisitScenarioIDs() []string {
	return []string{
		memoryRouterNaturalScenarioID,
		memoryRouterScriptedScenarioID,
	}
}

func highTouchMemoryRouterRecallScenarioIDs() []string {
	return []string{
		highTouchMemoryRouterRecallNaturalScenarioID,
		highTouchMemoryRouterRecallScriptedScenarioID,
	}
}

func memoryRouterRecallCandidateScenarioIDs() []string {
	return []string{
		memoryRouterRecallCurrentPrimitivesScenarioID,
		memoryRouterRecallGuidanceOnlyScenarioID,
		memoryRouterRecallResponseCandidateScenarioID,
	}
}

func memoryRouterRecallReportScenarioIDs() []string {
	return []string{
		memoryRouterRecallReportActionScenarioID,
	}
}

func promotedRecordDomainScenarioIDs() []string {
	return []string{
		promotedRecordDomainNaturalScenarioID,
		promotedRecordDomainScriptedScenarioID,
	}
}

func highTouchRelationshipRecordScenarioIDs() []string {
	return []string{
		highTouchRelationshipRecordNaturalScenarioID,
		highTouchRelationshipRecordScriptedScenarioID,
	}
}

func relationshipRecordCandidateScenarioIDs() []string {
	return []string{
		relationshipRecordCurrentPrimitivesScenarioID,
		relationshipRecordGuidanceOnlyScenarioID,
		relationshipRecordResponseCandidateScenarioID,
	}
}

func parallelRunnerScenarioIDs() []string {
	return []string{
		parallelRunnerStartupScenarioID,
		parallelRunnerReadsScenarioID,
	}
}

func broadAuditScenarioIDs() []string {
	return []string{
		broadAuditNaturalScenarioID,
		broadAuditScriptedScenarioID,
	}
}

func captureExplicitOverridesScenarioIDs() []string {
	return []string{
		captureExplicitOverridesNaturalScenarioID,
		captureExplicitOverridesScriptedScenarioID,
		captureExplicitOverridesInvalidScenarioID,
		captureExplicitOverridesAuthorityConflictID,
		captureExplicitOverridesNoConventionOverrideID,
	}
}

func captureLowRiskScenarioIDs() []string {
	return []string{
		captureLowRiskNaturalScenarioID,
		captureLowRiskScriptedScenarioID,
		captureLowRiskDuplicateScenarioID,
	}
}

func captureDuplicateCandidateScenarioIDs() []string {
	return []string{
		captureDuplicateCandidateNaturalScenarioID,
		captureDuplicateCandidateScriptedScenarioID,
		captureDuplicateCandidateAccuracyScenarioID,
	}
}

func captureSaveThisNoteScenarioIDs() []string {
	return []string{
		captureSaveThisNoteNaturalScenarioID,
		captureSaveThisNoteScriptedScenarioID,
		captureSaveThisNoteDuplicateScenarioID,
		captureSaveThisNoteLowConfidenceID,
	}
}

func captureDocumentLinksScenarioIDs() []string {
	return []string{
		captureDocumentLinksNaturalScenarioID,
		captureDocumentLinksFetchScenarioID,
		captureDocumentLinksSynthesisScenarioID,
		captureDocumentLinksDuplicateScenarioID,
	}
}

func productionScenariosDetails(passed int, total int, missing []string) string {
	details := fmt.Sprintf("%d/%d production scenarios passed", passed, total)
	if len(missing) > 0 {
		details += "; missing: " + strings.Join(missing, ", ")
	}
	return details
}

func validationFinalAnswerDetails(failures []string, missing []string) string {
	if len(failures) == 0 && len(missing) == 0 {
		return "rule-covered validation scenarios used no tools, no command executions, and at most one assistant answer"
	}
	parts := []string{}
	if len(failures) > 0 {
		parts = append(parts, "not final-answer-only: "+strings.Join(failures, ", "))
	}
	if len(missing) > 0 {
		if len(missing) == countFinalAnswerOnlyValidationScenarios() {
			parts = append(parts, "not evaluated; final-answer-only validation scenarios were not selected in this partial run")
		} else {
			parts = append(parts, "missing final-answer-only validation scenarios: "+strings.Join(missing, ", "))
		}
	}
	return strings.Join(parts, "; ")
}

func countFinalAnswerOnlyValidationScenarios() int {
	count := 0
	for _, scenarioID := range releaseBlockingScenarioIDs() {
		if isFinalAnswerOnlyValidationScenario(scenarioID) {
			count++
		}
	}
	return count
}
