Files
raea/tools/skills-sections.sh
shane d873402ac5 raea goal is the loop, raea make the asset tools (#269)
One loop, raea goal: every rule in TypeScript, held at edit, render, publish and done (goal check, tasks, judge, seen, gates, next); the brief's contract is goal: (one goal or a list, a workflow inline), and its plan is plan:. raea make is making a finished asset: character, clothes, motion, solid, wear, splat, physics, bake, sounds, component, the kit pipeline and shots. Instruments (check, judge, ask, world, scene faults, light check) stay top-level. With it: the montage pack (MK48-MK51), JavaScriptCore fixes raea goal needs (CommonJS named exports, reserved words too, dynamic import of file URLs, process.exit from a promise, stdin for -), raea-cli-goal and raea-cli-refused split out of raea-cli, and skills at raea-skills 105aede.
2026-11-29 18:43:09 -08:00

51 lines
3.1 KiB
Bash
Executable File

# Sourced by tools/skills.sh (its sections, split out to keep it under 500 lines): the hand-written sections of the
# skill and the craft guides that name their sources (`<!-- sources: PATH ... -->`), cochange()'s SK4 warning when a
# change touches a section's sources and leaves the section alone (check runs it), and stale(), every such section by
# how many commits to its sources it has missed (`tools/skills.sh stale`). Reads SK and texts() from skills.sh.
# each hand-written section that names its sources: file, its first and last line, heading, sources
sections() {
texts | while IFS= read -r f; do
awk -v f="$f" '
function flush() { if (head != "" && src != "") printf "%s\t%d\t%d\t%s\t%s\n", f, start, NR - 1, head, src }
/^## / { flush(); head = substr($0, 4); start = NR; src = "" }
/^<!-- sources: / { s = $0; sub(/^<!-- sources: /, "", s); sub(/ *-->.*$/, "", s); src = s }
END { NR++; flush() }' "$f"
done
}
# a change to a section's sources that leaves the section alone (SK4): a warning, answered in the landing message
cochange() {
local changed
if [ -n "${SKILLS_CHANGED:-}" ]; then changed=$SKILLS_CHANGED
else changed=$(git diff --name-only "$(git merge-base HEAD origin/main 2>/dev/null || echo HEAD)" 2>/dev/null; git diff --name-only HEAD 2>/dev/null); fi
[ -n "$changed" ] || return 0
sections | while IFS=$'\t' read -r f a b head src; do
local hit="" s
for s in $src; do grep -qE "^${s//./\\.}(/|$)" <<< "$changed" && hit="$hit $s"; done
[ -n "$hit" ] || continue
# the section counts as touched when its file changed within its lines (or, with no history here, at all)
# (a skill in raea-skills counts as touched when the pointer moved: raea's history doesn't see inside it)
case $f in "$SK"/*) grep -qx skills <<< "$changed" && continue ;; esac
if grep -qx "$f" <<< "$changed"; then
[ -n "${SKILLS_CHANGED:-}" ] && continue
git diff -U0 "$(git merge-base HEAD origin/main 2>/dev/null || echo HEAD)" -- "$f" | grep -E '^@@' | sed -E 's/^@@ [^+]*\+([0-9]+)(,([0-9]+))?.*/\1 \3/' |
awk -v a="$a" -v b="$b" '{ n = ($2 == "" ? 1 : $2); if ($1 <= b && $1 + n - 1 >= a) t = 1 } END { exit !t }' && continue
fi
echo "skills: warning $f:$a: \"$head\" names$hit, which changed while it didn't; say in the landing message whether it still holds (\"checked, still true\") or edit it"
done
}
# every section with sources, by how many commits to them it has missed since its own lines last changed
stale() {
sections | while IFS=$'\t' read -r f a b head src; do
local t n bl
case $f in "$SK"/*) bl=(git -C skills blame -L "$a,$b" --porcelain -- "${f#skills/}") ;; *) bl=(git blame -L "$a,$b" --porcelain -- "$f") ;; esac
t=$("${bl[@]}" 2>/dev/null | awk '/^committer-time / { if ($2 > m) m = $2 } END { print m + 0 }')
[ "$t" -gt 0 ] || t=$(date +%s)
# shellcheck disable=SC2086
n=$(git rev-list --count --since="$t" HEAD -- $src 2>/dev/null || echo 0)
printf '%s\t%s:%s\t%s\n' "$n" "$f" "$a" "$head"
done | sort -rn -k1,1 | awk -F'\t' 'BEGIN { print "missed section" } { printf "%6d %s %s\n", $1, $2, $3 }'
}