#!/usr/bin/env bash # consolidate — fold a finished run into a one-page index and archive its # artifacts, so the live `.skepticism/runs/` directory (and the context the # controller loads at routing time) stays bounded as runs accumulate. # # The controller authors the rich digest in INDEX.md (it knows the decisions); # this script provides the plumbing: ensure the index exists, append a stub # entry pulled from state.md, and move the run dir under archive/. # # Everything here lives under `.skepticism/`, which is excluded from git locally # (see `state protect`) — the index is this machine's memory of past runs, not # project documentation, and it never reaches the remote. # # Usage: consolidate (run from the project repo root) set -euo pipefail ROOT=".skepticism" slug="${1:?usage: consolidate }" dir="${ROOT}/runs/${slug}" index="${ROOT}/INDEX.md" archive="${ROOT}/archive" [[ -d "$dir" ]] || { echo "no such run: $dir" >&2; exit 1; } feature="$(grep -m1 '^- feature:' "$dir/state.md" 2>/dev/null | sed 's/^- feature:[[:space:]]*//')" tier="$(grep -m1 '^- tier:' "$dir/state.md" 2>/dev/null | sed 's/^- tier:[[:space:]]*//')" today="$(date +%Y-%m-%d)" if [[ ! -f "$index" ]]; then cat > "$index" </\`. The controller reads this at routing time instead of scanning every run. EOF fi # Append a stub the controller can enrich with decisions/links. cat >> "$index" < EOF # Register the local git exclusion before writing anything. `state init` already # does this in phase 0, but this script is also runnable on its own — and a run # directory that appears in `git status` before the exclusion exists is exactly # the footprint Iron Rule 6 forbids. `state protect` is idempotent and exits 0 # outside a git repository, so this is safe to call unconditionally. "$(dirname "$0")/state" protect >/dev/null 2>&1 || true mkdir -p "$archive" mv "$dir" "$archive/$slug" echo "consolidated ${slug} → ${archive}/${slug}; indexed in ${index}"