#!/usr/bin/env bash set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" MODE="${1:-resume}" REGISTRY_PATH="$ROOT/build/system/product_candidate_registry.json" GOVERNANCE_PATH="$ROOT/build/system/user_governance.json" CONTINUITY_RESUME_SCRIPT="$ROOT/scripts/render_continuity_flow.sh" latest_benchmark_summary() { find "$ROOT/runs/benchmark" -path '*/summary.json' -type f 2>/dev/null | sort | tail -n 1 } if [ ! -f "$REGISTRY_PATH" ]; then echo "product candidate registry missing: $REGISTRY_PATH" >&2 exit 1 fi REGISTRY_JSON="$(cat "$REGISTRY_PATH")" GOVERNANCE_JSON='{}' if [ -f "$GOVERNANCE_PATH" ]; then GOVERNANCE_JSON="$(cat "$GOVERNANCE_PATH")" fi BENCHMARK_PATH="$(latest_benchmark_summary)" if [ -n "$BENCHMARK_PATH" ] && [ -f "$BENCHMARK_PATH" ]; then BENCHMARK_JSON="$(cat "$BENCHMARK_PATH")" else BENCHMARK_JSON='{"aggregate":{},"stability":{}}' fi CONTINUITY_JSON='{}' if [ -x "$CONTINUITY_RESUME_SCRIPT" ]; then CONTINUITY_JSON="$("$CONTINUITY_RESUME_SCRIPT" 2>/dev/null || printf '{}')" fi jq -n \ --arg mode "$MODE" \ --arg registry_path "$REGISTRY_PATH" \ --arg governance_path "$GOVERNANCE_PATH" \ --arg benchmark_path "$BENCHMARK_PATH" \ --argjson registry "$REGISTRY_JSON" \ --argjson governance "$GOVERNANCE_JSON" \ --argjson benchmark "$BENCHMARK_JSON" \ --argjson continuity "$CONTINUITY_JSON" \ '{ route:{ lane:"tooling", objective:"manage product delivery through candidate registry, continuity state, and benchmark gates", mode:$mode, top_candidate_id:($registry.top_candidate_id // null) }, context:{ product_candidates:($registry.candidates[0:3] // []), live_continuity_version:($continuity.route.continuity_version_id // null), active_surface:($continuity.context.active_surface // null), benchmark:{ avg_latency_ms:($benchmark.aggregate.avg_latency_ms // null), continuity_provider_accuracy:($benchmark.aggregate.continuity_provider_accuracy // null), freshness_override_accuracy:($benchmark.aggregate.freshness_override_accuracy // null), unsupported_query_abstention_rate:($benchmark.aggregate.unsupported_query_abstention_rate // null) } }, action:{ next_step:( if $mode == "verify" then "run benchmark gate and compare delivery metrics" elif $mode == "products" then "inspect the candidate registry and choose one bounded slice" else "resume delivery from the top candidate and active continuity surface" end ), recommended_candidate:($registry.candidates[0] // null), recommended_commands:( if $mode == "verify" then ["./bin/bvtctl benchmark"] elif $mode == "products" then ["./bin/bvtctl pm-products","./bin/bvtctl pm-next"] else ["./bin/bvtctl continuity-resume","./bin/bvtctl pm-next","./bin/bvtctl pm-verify"] end ) }, receipt:{ governance_source:$governance_path, candidate_registry_path:$registry_path, benchmark_summary_path:(if $benchmark_path == "" then null else $benchmark_path end), promotion_gate:"receipts + benchmark pass" } }'