#!/usr/bin/env bash set -euo pipefail ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)" TS="$(date +%F_%H%M%S)" OUT_DIR="${ROOT_DIR}/reports/gates" mkdir -p "${OUT_DIR}" REPORT_FILE="${OUT_DIR}/final_decision_consistency_${TS}.md" LOG_FILE="${OUT_DIR}/final_decision_consistency_${TS}.log" latest_file_or_empty() { local pattern="$1" local latest latest="$(ls -1t ${pattern} 2>/dev/null | head -n 1 || true)" echo "${latest}" } parse_checkbox_decision() { local file="$1" local go="0" local cgo="0" local nogo="0" if [[ ! -f "${file}" ]]; then echo "UNKNOWN" return fi grep -Eq '^- \[x\] (GO|通过)' "${file}" && go="1" || true grep -Eq '^- \[x\] (CONDITIONAL GO|有条件通过)' "${file}" && cgo="1" || true grep -Eq '^- \[x\] (NO-GO|不通过)' "${file}" && nogo="1" || true if [[ "${go}" == "1" ]]; then echo "GO" return fi if [[ "${cgo}" == "1" ]]; then echo "CONDITIONAL_GO" return fi if [[ "${nogo}" == "1" ]]; then echo "NO_GO" return fi echo "UNKNOWN" } parse_machine_decision() { local file="$1" if [[ ! -f "${file}" ]]; then echo "UNKNOWN" return fi local row row="$(grep -E '^\- (机判结论|决策):\*\*' "${file}" | head -n 1 || true)" if [[ -z "${row}" ]]; then echo "UNKNOWN" return fi if echo "${row}" | grep -q 'NO_GO'; then echo "NO_GO" return fi if echo "${row}" | grep -q 'CONDITIONAL_GO'; then echo "CONDITIONAL_GO" return fi if echo "${row}" | grep -q 'GO'; then echo "GO" return fi echo "UNKNOWN" } FINAL_DECISION_FILE="${ROOT_DIR}/review/final_decision_2026-03-31.md" TOK007_FILE="$(latest_file_or_empty "${ROOT_DIR}/review/outputs/tok007_release_recheck_*.md")" SP_FILE="$(latest_file_or_empty "${ROOT_DIR}/reports/gates/superpowers_stage_validation_*.md")" FINAL_DECISION="$(parse_checkbox_decision "${FINAL_DECISION_FILE}")" TOK007_DECISION="$(parse_machine_decision "${TOK007_FILE}")" SP_DECISION="$(parse_machine_decision "${SP_FILE}")" CONSISTENCY_STATUS="PASS" CONSISTENCY_NOTE="final decision is aligned with latest machine recheck" if [[ "${FINAL_DECISION}" == "UNKNOWN" || "${TOK007_DECISION}" == "UNKNOWN" || "${SP_DECISION}" == "UNKNOWN" ]]; then CONSISTENCY_STATUS="FAIL" CONSISTENCY_NOTE="cannot parse one or more decision sources" elif [[ "${FINAL_DECISION}" != "${TOK007_DECISION}" ]]; then CONSISTENCY_STATUS="WARN" CONSISTENCY_NOTE="final signed decision lags latest machine recheck; requires manual review update" fi cat > "${REPORT_FILE}" <