#!/bin/sh
# Inventory the stage-facing prompt surfaces before changing prompt policy. This is intentionally
# static: it is safe to run without a model, server, event store, or workspace mutation.
set -eu

root=${1:-.}
cd "$root"

printf '%s\n\n' '# Stage prompt inventory'
printf '%s\n' '| Surface | Source | Lines | Approx. tokens |'
printf '%s\n' '|---|---|---:|---:|'

find examples/workflows/prompts -type f -name '*.md' -print 2>/dev/null | sort | while IFS= read -r file; do
    lines=$(wc -l < "$file" | tr -d ' ')
    chars=$(wc -c < "$file" | tr -d ' ')
    printf '| workflow prompt | `%s` | %s | %s |\n' "$file" "$lines" "$((chars / 4))"
done

printf '| curated system guidance | `%s` | %s | %s |\n' \
    'core/kernel/.../DefaultSessionOrchestrator.kt' \
    "$(awk '/CURATED_STAGE_OPERATING_GUIDANCE =/{on=1} on{n++} /"""$/{if(on){print n; exit}}' core/kernel/src/main/kotlin/com/correx/core/kernel/orchestration/DefaultSessionOrchestrator.kt)" \
    "$(awk '/CURATED_STAGE_OPERATING_GUIDANCE =/{on=1} on{c+=length($0)+1} /"""$/{if(on){print int(c/4); exit}}' core/kernel/src/main/kotlin/com/correx/core/kernel/orchestration/DefaultSessionOrchestrator.kt)"

printf '\n## Candidates for review\n\n'
rg -n -i '(^|[^[:alnum:]_])(must|always|never|required|exactly)([^[:alnum:]_]|$)' \
    examples/workflows/prompts core/kernel/src/main/kotlin/com/correx/core/kernel/orchestration/DefaultSessionOrchestrator.kt \
    2>/dev/null || true
