# Validate a postmortem/PIR Markdown file has the three load-bearing pieces:
# a timestamped decision log, a named Incident Commander, and at least one
# action item with both an owner and a due date.
# All three checks are reported (ok/fail each); FAILS (exit 1) if any one
# of the three is missing.
# Usage: check_pir.sh PIR.md
if [[ -z "$PIR" || ! -f "$PIR" ]]; then
echo "Usage: $0 PIR.md" >&2
echo "error: PIR file not found: '${PIR:-<missing arg>}'" >&2
warn() { printf '⚠️ %s\n' "$1"; }
error() { printf '❌ %s\n' "$1"; fail=1; }
ok() { printf '✅ %s\n' "$1"; }
echo "== check: timestamped decision log =="
# 24hr HH:MM, or 12hr H:MM AM/PM.
time_hits=$(grep -nE '\b([01]?[0-9]|2[0-3]):[0-5][0-9]([[:space:]]*(AM|PM|am|pm))?\b' "$PIR" || true)
if [[ -n "$time_hits" ]]; then
ok "timestamped decision log entries found"
error "no timestamped log entries found (expected lines like '14:32' or '2:32 PM')"
echo "== check: named Incident Commander =="
ic_hits=$(grep -nE '(^|[^A-Za-z])(IC|Incident Commander)[[:space:]]*:[[:space:]]*[A-Za-z]' "$PIR" || true)
if [[ -n "$ic_hits" ]]; then
# Reject obvious placeholders.
if echo "$ic_hits" | grep -qiE ':\s*(TBD|TODO|N/?A|name|\[.*\])\s*$'; then
error "found an IC/Incident Commander line but it looks like a placeholder, not a real name:"
ok "named Incident Commander found"
error "no 'IC:' or 'Incident Commander:' line with a name found"
echo "== check: at least one action item with owner AND due date =="
# Liberal patterns: checkbox with @owner and a date; or "Owner:" + a date nearby on the same line.
action_hits=$(grep -nE '^\s*-\s*\[[ xX]\].*@[A-Za-z].*\b[0-9]{4}-[0-9]{2}-[0-9]{2}\b' "$PIR" || true)
owner_date_hits=$(grep -nE 'Owner\s*:\s*[A-Za-z].*\b[0-9]{4}-[0-9]{2}-[0-9]{2}\b|\b[0-9]{4}-[0-9]{2}-[0-9]{2}\b.*Owner\s*:\s*[A-Za-z]' "$PIR" || true)
at_name_date_hits=$(grep -nE '@[A-Za-z][A-Za-z0-9_-]*.*\b[0-9]{4}-[0-9]{2}-[0-9]{2}\b' "$PIR" || true)
if [[ -n "$action_hits" || -n "$owner_date_hits" || -n "$at_name_date_hits" ]]; then
ok "found at least one action item with an owner and a due date"
error "no action item found with both an owner (e.g. '@name' or 'Owner: Name') and a due date (YYYY-MM-DD)"
if [[ "$fail" -eq 0 ]]; then
echo "All checks passed."
echo "One or more checks failed — see ❌ lines above."