Files
boshu2__agentops/scripts/regen-all.sh
T
Bo 0c5554f1bc build(factory): one-shot regenerator for ao-command-landing surfaces (ag-jy12 #command-regen) (#742)
## What

A ONE-SHOT regenerator (`scripts/regen-command-surfaces.sh`) for the
`ao`-command-landing derived surfaces. When an `ao` command is
added/removed/renamed, these surfaces must update in lockstep — the
multi-surface tax that bit #720 (ag-sz3h, ~4 extra CI rounds):

- the two cobra `expectedCmds` literals in
`cli/cmd/ao/cobra_commands_test.go`
- the `cli-command-surface` heading counts:
`evals/agentops-core/fixtures/cli-command-surface-smoke.sh` +
`evals/agentops-core/cli-command-surface-matrix.json`

## How

- **Single source of truth for the command set**: the LIVE cobra tree,
dumped by the new `TestDumpRegisteredTopLevelCommands` (set
`AO_DUMP_REGISTERED_CMDS=1`). It walks `rootCmd.Commands()` (sorted,
`help` excluded) — exactly the membership the two `expectedCmds`
literals must match. A *test*, not a subcommand, so emitting the list
does not itself add a registered command (which would be circular).
- **Single source of truth for the counts**: `cli/docs/COMMANDS.md`
(itself generated from the cobra tree). `top = ### \`ao `, `sub = ####
\`ao `, `all = #{3,4} \`ao `.
- Rewrites all three derived surfaces deterministically. The
`expectedCmds` literals are reformatted one-element-per-line
(gofmt-stable) so output is canonical forever — **membership is
identical to before (pure reformat)**.
- **Idempotent**: a no-change tree is a no-op; `--check` fails on drift
without writing.
- Wired into `regen-all.sh` (both regen + `--check`) right after the
COMMANDS.md step.

## Deletion ⊃ Addition (completeness note)

Removing/renaming a command is a SUPERSET of adding one. This
regenerator covers the ADD surfaces. A delete/rename ALSO disturbs
surfaces it does NOT auto-regenerate — these need manual/quorum
attention:

- (a) codex-contract gates that hardcode command literals
(`validate-codex-rpi-contract.sh`)
- (b) skills-codex twins/overrides (`export-claude-skills-to-codex` +
`regen-codex-hashes`)
- (c) VERBATIM-PRESERVE template SHAs (`cron-loop-mode.md` frontmatter)

A "deletion ⊃ addition" note is present in the regenerator header
comment AND the `regen-all.sh` operator reminder.

## Verification

- `scripts/regen-command-surfaces.sh` → no-op on clean tree; `--check`
green.
- `go build ./cmd/ao`, `go vet ./cmd/ao`, `go test ./cmd/ao` (full
package) all pass; `gofmt -l` clean.
- `cli-command-surface-matrix` canary: pass. Smoke fixture: pass.
- Pre-push gate's only reds are pre-existing, unrelated canaries
(`context-packet-ab-wave0`, `agentops-core.pre-push-gate-governance`
bats) — not touched by this diff.

Closes-scenario: ag-jy12#command-regen
Bounded-context: BC4-Factory
Evidence: scripts/regen-command-surfaces.sh
2026-06-05 05:15:41 +00:00

85 lines
4.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# regen-all.sh — one-command finalizer for the derived-artifact gate surface.
#
# Adding a skill or `ao` command makes ~8 generated registries/goldens stale, each
# guarded by an independent CI gate that stops at the first error. Discovering them
# one CI round at a time is slow (see PR #598 / ag-nk67: 9 rounds, 0 feature-code
# failures). This composes every generator into one local pass, with a --check mode
# that runs the matching drift validators as a pre-push gate.
#
# Usage:
# scripts/regen-all.sh # regenerate all derived artifacts (writes)
# scripts/regen-all.sh --check # run all drift validators (no writes); exit 1 on drift
# scripts/regen-all.sh --skills foo,bar # scope the codex-hash step to foo,bar
# REGEN_SKILLS=foo,bar scripts/regen-all.sh # same scoping via env
#
# NOTE: Codex twins (skills-codex/<name>/{SKILL.md,prompt.md}) are MANUAL — this
# refreshes their hashes but cannot author a missing twin. Create twins by hand
# (runtime-native: no `.claude/...` tokens), then re-run.
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$REPO_ROOT"
MODE="regen"
REGEN_SKILLS="${REGEN_SKILLS:-}"
while [[ $# -gt 0 ]]; do
case "$1" in
--check) MODE="check" ;;
--skills) shift; [[ $# -gt 0 ]] || { echo "--skills requires a value" >&2; exit 2; }; REGEN_SKILLS="$1" ;;
--skills=*) REGEN_SKILLS="${1#--skills=}" ;;
*) echo "usage: $0 [--check] [--skills <skill[,skill,...]>]" >&2; exit 2 ;;
esac
shift
done
fail=0
step() { # label cmd...
local label="$1"; shift
if "$@" >/tmp/regen-all.$$.log 2>&1; then
printf ' \033[0;32m✓\033[0m %s\n' "$label"
else
printf ' \033[0;31m✗\033[0m %s\n' "$label"; sed 's/^/ /' /tmp/regen-all.$$.log | tail -6
fail=1
fi
}
if [[ "$MODE" == "regen" ]]; then
echo "== regenerating derived artifacts (dependency order) =="
step "skill counts" bash scripts/sync-skill-counts.sh
step "skill-domain-map" bash scripts/generate-skill-domain-map.sh
step "SKU catalog (registry.json)" bash scripts/generate-registry.sh
step "context-map" bash scripts/generate-context-map.sh
step "embedded skills" make -C cli sync-hooks
step "cli reference (COMMANDS.md)" bash scripts/generate-cli-reference.sh
step "command surfaces (cobra expectedCmds + heading counts)" bash scripts/regen-command-surfaces.sh
step "cli-surface inventory" bash scripts/check-cmdao-surface-parity.sh --write-surface
step "codex hashes" bash scripts/regen-codex-hashes.sh ${REGEN_SKILLS:+--only "$REGEN_SKILLS"}
echo
echo "Regenerated. Review 'git status', then run: scripts/regen-all.sh --check"
echo "Reminder: new skills also need MANUAL skills-codex/<name>/ twins."
echo "Note: cobra expectedCmds + cli-command-surface counts are now AUTO-regenerated"
echo " (regen-command-surfaces.sh). DELETING/RENAMING a command also needs manual"
echo " attention on codex-contract gates + skills-codex twins + VERBATIM template SHAs"
echo " — see the 'deletion ⊃ addition' note in scripts/regen-command-surfaces.sh."
echo "Scope tip: changed only some skills? Re-run with --skills a,b (or REGEN_SKILLS=a,b)"
echo " so the codex-hash step skips unrelated pre-existing drift instead of sweeping it in."
else
echo "== drift / gate sweep (no writes) =="
step "registry drift" bash scripts/check-registry-drift.sh
step "skill-domain-map golden" bash scripts/generate-skill-domain-map.sh --check
step "write-surfaces" bash scripts/check-agents-write-surfaces.sh
step "codex parity" bash scripts/audit-codex-parity.sh
step "codex runtime sections" bash scripts/validate-codex-runtime-sections.sh
step "codex hashes (no drift)" bash scripts/regen-codex-hashes.sh --check ${REGEN_SKILLS:+--only "$REGEN_SKILLS"}
step "SKU catalog drift" bash scripts/validate-sku-catalog-drift.sh
step "context-map drift" bash scripts/validate-context-map-drift.sh
step "command surfaces drift" bash scripts/regen-command-surfaces.sh --check
step "doc-release gate" bash tests/docs/validate-doc-release.sh
echo
[[ $fail -eq 0 ]] && echo "ALL GATES GREEN — safe to push" || echo "DRIFT DETECTED — run scripts/regen-all.sh (no flag) to fix, then commit"
fi
rm -f /tmp/regen-all.$$.log
exit $fail