Files
reliquary/plugins/orbit/skills/orbit/scripts/freshness.sh
T
g4borg f1de89e869 🤖 Add orbit prototype plugin for Rust code review
Standalone plugin with one skill: when to use orbit and when grep, a
mandatory preflight for stale indexes and blind regions (cfg(test),
features, macros, dyn dispatch), a scripted review pass over isolated
worktree DBs, and a JSONL feedback log for mining real usage later.
Registered in the marketplace as a prototype.
2026-09-29 19:52:59 +02:00

36 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Preflight for ad-hoc orbit questions (not a full review): is the index for this checkout fresh?
# Usage: freshness.sh [repo-dir] [--db PATH] (read-only; never indexes)
# Prints OK / STALE / MISSING plus the .rs files whose indexed state may differ from what you see on disk.
# Caveat: orbit indexes the WORKING TREE but labels the entry with HEAD's sha. A matching sha is not proof
# the index matches the files if the tree was dirty at index time or has been edited since.
set -euo pipefail
REPO=$(realpath "${1:-.}"); shift || true
DBARG=(); [ "${1:-}" = "--db" ] && DBARG=(--db "$2")
TOP=$(git -C "$REPO" rev-parse --show-toplevel)
HEAD=$(git -C "$TOP" rev-parse HEAD)
row=$(orbit sql --all "${DBARG[@]}" -F csv \
"SELECT commit_sha, status, last_indexed_at FROM _orbit_manifest WHERE repo_path = '$TOP'" 2>/dev/null | tail -n +2 | head -1)
if [ -z "$row" ]; then
echo "[MISSING] $TOP has no orbit index${DBARG:+ in ${DBARG[1]}}. Index with: orbit index '$TOP' -t 4 (shared DB: other agents see it) or use an isolated --db."
exit 2
fi
IFS=, read -r SHA STATUS AT <<<"$row"
dirty=$(git -C "$TOP" status --porcelain --untracked-files=normal -- '*.rs' | wc -l)
since=$(git -C "$TOP" diff --name-only "$SHA" -- '*.rs' 2>/dev/null | wc -l)
verdict=OK
[ "$STATUS" = indexed ] || verdict=BROKEN
[ "$SHA" = "$HEAD" ] || verdict=STALE
[ "$verdict" = OK ] && [ "$dirty" -gt 0 ] && verdict=DIRTY
echo "[$verdict] $TOP index=${SHA:0:8} ($STATUS, indexed_at ${AT} UTC) head=${HEAD:0:8} dirty_rs=$dirty rs_changed_since_index_sha=$since"
case $verdict in
STALE) echo " orbit sql will silently fall back to --all (all repos, all commits) -- note on stderr only. grep/context do not warn."
echo " Re-index (orbit index '$TOP' -t 4, check skipped_files==0) or treat every orbit answer as possibly outdated for these files:"
git -C "$TOP" diff --name-only "$SHA" -- '*.rs' | head -15 | sed 's/^/ /'
[ "$since" = 0 ] && echo " (none: .rs content likely unchanged, but orbit sql still mixes all repos unless you add WHERE commit_sha='$SHA' or re-index)"
exit 1 ;;
DIRTY) echo " sha matches, but .rs files are modified/untracked now; the index holds whatever was on disk at index time:"
git -C "$TOP" status --porcelain --untracked-files=normal -- '*.rs' | head -15 | sed 's/^/ /'
exit 1 ;;
esac