chore(plugins): sync generated content mirrors
Regenerate plugins/*/skills/ from plugins/*/.apm/ after the previous four commits, via scripts/sync-plugin-content.sh --all. The mirror is generated output (ADR-0017) that check-plugin-content-sync's pre-push hook diffs against .apm/; nothing here is hand-edited. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EeH8SCbcrCAQrtymkNuhKP
This commit is contained in:
@@ -3,12 +3,19 @@ set -euo pipefail
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage: validate-provenance.sh <skill-dir>
|
||||
Usage: validate-provenance.sh <skill-dir> [--base-ref=<ref>]
|
||||
|
||||
Validate that a skill's sources provenance chain is complete and internally consistent.
|
||||
|
||||
Arguments:
|
||||
skill-dir Path to the skill directory to validate.
|
||||
skill-dir Path to the skill directory to validate.
|
||||
--base-ref=REF Git ref to diff references/sources.md against for check 9.
|
||||
Defaults to \`git merge-base HEAD origin/main\`. Override this
|
||||
when origin/main is not the right comparison point (a fork,
|
||||
a long-lived branch, a mirror with a different remote name).
|
||||
The VALIDATE_PROVENANCE_BASE_REF environment variable is an
|
||||
equivalent, lower-precedence way to set it — the flag wins
|
||||
if both are given.
|
||||
|
||||
Exit codes:
|
||||
0 All checks passed (or nothing to validate)
|
||||
@@ -38,6 +45,12 @@ Checks performed:
|
||||
resolved; a path that still does not resolve is reported as an INFO saying
|
||||
checks 7 and 8 did not run, never skipped silently.
|
||||
8 Extracted non-(none) slug in research doc present in sources.md
|
||||
9 Description or Contributing files text changed since --base-ref (INFO
|
||||
only — a bash script cannot verify the claim is still TRUE, only that it
|
||||
changed; the auditor reads the named files to check that). A slug absent
|
||||
at the base ref is a creation, not a change, and is not flagged. When the
|
||||
base ref cannot be resolved at all, this is announced as ONE INFO for the
|
||||
whole check, never a silent skip.
|
||||
|
||||
Checks 7 and 8 apply ONLY when the Research doc value names a research SOURCE
|
||||
INDEX — a file whose basename is sources.md, whose H2 headings ARE source
|
||||
@@ -52,13 +65,31 @@ if [[ "${1:-}" == "--help" || "${1:-}" == "-h" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# --base-ref=<ref> is the only recognised flag, for check 9's base-ref
|
||||
# override. It is pulled out before the positional-count checks below so it
|
||||
# never counts against them — a caller passing it alongside skill-dir sees
|
||||
# the same argument-count behaviour as one who does not pass it at all, and a
|
||||
# genuinely extra positional argument is still rejected.
|
||||
declare -a POSITIONAL_ARGS=()
|
||||
BASE_REF_OVERRIDE=""
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--base-ref=*)
|
||||
BASE_REF_OVERRIDE="${arg#--base-ref=}"
|
||||
;;
|
||||
*)
|
||||
POSITIONAL_ARGS+=("$arg")
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Usage and environment problems exit 2, findings exit 1. See the usage text
|
||||
# above for why the two must not share a code. This is a deliberate divergence
|
||||
# from validate.sh, which has no 2 tier: validate.sh always prints PASS lines,
|
||||
# so a usage error there is visibly not a findings report. This script prints
|
||||
# NOTHING on a clean run, so exit 1 plus empty stdout was the only signal a
|
||||
# caller got either way.
|
||||
if [[ $# -lt 1 ]]; then
|
||||
if [[ ${#POSITIONAL_ARGS[@]} -lt 1 ]]; then
|
||||
echo "Error: skill-dir is required." >&2
|
||||
echo "" >&2
|
||||
usage >&2
|
||||
@@ -67,13 +98,20 @@ fi
|
||||
|
||||
# Extra positional arguments were silently dropped, so a typo'd flag or a second
|
||||
# path looked like it had been honoured.
|
||||
if [[ $# -gt 1 ]]; then
|
||||
echo "Error: expected exactly one argument, got $#: $*" >&2
|
||||
if [[ ${#POSITIONAL_ARGS[@]} -gt 1 ]]; then
|
||||
echo "Error: expected exactly one argument, got ${#POSITIONAL_ARGS[@]}: ${POSITIONAL_ARGS[*]}" >&2
|
||||
echo "" >&2
|
||||
usage >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
SKILL_DIR_ARG="${POSITIONAL_ARGS[0]}"
|
||||
|
||||
# The flag wins over the environment variable when both are given; either is
|
||||
# empty-string when unset, and an empty string tells the Python body to fall
|
||||
# back to `git merge-base HEAD origin/main`.
|
||||
BASE_REF="${BASE_REF_OVERRIDE:-${VALIDATE_PROVENANCE_BASE_REF:-}}"
|
||||
|
||||
# python3 is a HARD dependency. Without this preflight a missing interpreter
|
||||
# produced 'line NN: python3: command not found' and exit 127 — an exit code no
|
||||
# caller maps to anything, from a message that names this script's line number
|
||||
@@ -91,24 +129,25 @@ fi
|
||||
# references/validation-scripts.md explicitly told the auditor to read as a
|
||||
# pass. A typo'd target was therefore indistinguishable from a clean skill.
|
||||
# vale-wrap.sh hard-errors on a nonexistent path for exactly this reason.
|
||||
if [[ ! -d "$1" ]]; then
|
||||
echo "Error: not a directory: $1" >&2
|
||||
if [[ ! -d "$SKILL_DIR_ARG" ]]; then
|
||||
echo "Error: not a directory: $SKILL_DIR_ARG" >&2
|
||||
echo " Why: a nonexistent target would otherwise report a silent pass." >&2
|
||||
echo " Fix: pass the path of the skill directory to validate." >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [[ ! -f "$1/SKILL.md" ]]; then
|
||||
echo "Error: not a skill directory (no SKILL.md): $1" >&2
|
||||
if [[ ! -f "$SKILL_DIR_ARG/SKILL.md" ]]; then
|
||||
echo "Error: not a skill directory (no SKILL.md): $SKILL_DIR_ARG" >&2
|
||||
echo " Why: a directory with no SKILL.md has no provenance chain to validate, and reporting that as a pass hides the wrong-target mistake." >&2
|
||||
echo " Fix: pass the skill directory itself, not its parent or its references/ subdirectory." >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
python3 -u - "$1" <<'PYTHON'
|
||||
python3 -u - "$SKILL_DIR_ARG" "$BASE_REF" <<'PYTHON'
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
# Output is UTF-8 for the same reason input is: under LC_ALL=C the streams
|
||||
# default to ASCII, and every finding this script prints contains an em dash.
|
||||
@@ -125,6 +164,11 @@ skill_dir = os.path.abspath(sys.argv[1])
|
||||
sources_md_path = os.path.join(skill_dir, "references", "sources.md")
|
||||
refs_dir = os.path.join(skill_dir, "references")
|
||||
|
||||
# Empty string (the shell side passes "" when neither --base-ref nor
|
||||
# VALIDATE_PROVENANCE_BASE_REF was given) means: resolve the default via
|
||||
# `git merge-base HEAD origin/main` at check-9 time, below.
|
||||
base_ref_override = sys.argv[2] if len(sys.argv) > 2 else ""
|
||||
|
||||
# --- Helpers ---
|
||||
|
||||
# The trailing character class used to be CONSUMING — `[^`\n]` — so a
|
||||
@@ -444,6 +488,81 @@ def find_repo_root(start_dir):
|
||||
return None
|
||||
current = parent
|
||||
|
||||
# --- Check 9 helpers ---------------------------------------------------
|
||||
# Check 9 needs a raw field VALUE (as text, to diff against an earlier
|
||||
# version), not the parsed structure parse_contributing_files() and
|
||||
# parse_status() return — a Contributing files list that reordered its
|
||||
# entries without changing them is not what this check is looking for, but
|
||||
# neither is normalizing so hard that a genuine rewrite disappears. Raw text,
|
||||
# whitespace-normalized, is the middle ground.
|
||||
|
||||
def run_git(args, cwd):
|
||||
"""Run `git <args>` in cwd. Returns (returncode, stdout, stderr) — never
|
||||
raises, so a missing git binary or an unexpected OSError is just another
|
||||
non-zero result the caller folds into "could not run", not a crash."""
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["git"] + args, cwd=cwd, capture_output=True, text=True,
|
||||
encoding="utf-8", errors="replace"
|
||||
)
|
||||
return result.returncode, result.stdout, result.stderr
|
||||
except OSError as exc:
|
||||
return 1, "", str(exc)
|
||||
|
||||
def ref_exists(ref, cwd):
|
||||
"""True when ref resolves to a commit in the repo at cwd."""
|
||||
rc, _out, _err = run_git(["rev-parse", "--verify", "--quiet", ref + "^{commit}"], cwd)
|
||||
return rc == 0
|
||||
|
||||
def find_slug_block(content, slug):
|
||||
"""The raw text of a '## <slug>' entry's body, or None if no such H2."""
|
||||
pattern = re.compile(
|
||||
r'^## ' + re.escape(slug) + r'\s*\n(.*?)(?=^## |\Z)',
|
||||
re.MULTILINE | re.DOTALL
|
||||
)
|
||||
m = pattern.search(content)
|
||||
return m.group(1) if m else None
|
||||
|
||||
def parse_field_raw(content, slug, field_name):
|
||||
"""Raw text of a '**<field_name>:**' field under a slug H2.
|
||||
|
||||
Mirrors the two authored shapes parse_contributing_files() and
|
||||
parse_status() already handle (inline value on the same line, or a
|
||||
bare heading followed by '- ' bullets), but returns text rather than a
|
||||
parsed structure, because check 9 diffs wording, not semantics.
|
||||
|
||||
Returns None when the H2 itself is absent (the slug did not exist at
|
||||
this content's revision) or the field is absent — both read as "no
|
||||
earlier claim to compare against" to the caller, which is deliberate:
|
||||
a field appearing for the first time is a creation, not a change.
|
||||
"""
|
||||
block = find_slug_block(content, slug)
|
||||
if block is None:
|
||||
return None
|
||||
inline_re = re.compile(r'^\- \*\*' + re.escape(field_name) + r':\*\* (.+)$', re.MULTILINE)
|
||||
im = inline_re.search(block)
|
||||
if im:
|
||||
return im.group(1).strip()
|
||||
heading_re = re.compile(r'^\*\*' + re.escape(field_name) + r':\*\*\s*$', re.MULTILINE)
|
||||
hm = heading_re.search(block)
|
||||
if not hm:
|
||||
return None
|
||||
lines = []
|
||||
for line in block[hm.end():].splitlines():
|
||||
line = line.strip()
|
||||
if not line:
|
||||
if lines:
|
||||
break
|
||||
continue
|
||||
if not line.startswith("- "):
|
||||
break
|
||||
lines.append(line[2:].strip())
|
||||
return ", ".join(lines) if lines else None
|
||||
|
||||
def normalize_field_text(value):
|
||||
"""Collapse whitespace so reformatting alone never registers as a change."""
|
||||
return re.sub(r'\s+', ' ', value).strip()
|
||||
|
||||
findings = []
|
||||
has_fail = False
|
||||
|
||||
@@ -859,6 +978,89 @@ for rd_abs, (rd_rel, known_slugs, rd_content) in research_docs_seen.items():
|
||||
f"Add '## {rd_slug}' to references/sources.md or mark it as '(none)' in the research doc's Contributing files."
|
||||
)
|
||||
|
||||
# --- Check 9: Description / Contributing files changed since --base-ref ---
|
||||
# A structural fact — the field's TEXT differs from an earlier revision — is
|
||||
# all git can tell us. Whether the (possibly stronger) new wording is still
|
||||
# TRUE is a semantic question no parser here can answer; that is what sent
|
||||
# the earlier literal-text approaches (flagging a named-but-missing filename)
|
||||
# to 3/3 false positives against the real corpus without even catching the
|
||||
# bug that motivated this check. So check 9 does the one thing git reliably
|
||||
# can: detect the change, and hand the auditor the slug and field to go read,
|
||||
# never a verdict on the claim itself. Always INFO, never FAIL.
|
||||
if repo_root is None:
|
||||
emit_info(
|
||||
"Check 9 skipped — no repo root above the skill directory",
|
||||
"references/sources.md",
|
||||
"No ancestor of the skill directory contains a .git entry, so there is no git history to diff "
|
||||
"references/sources.md against. Check 9 did not run for any slug in this skill. "
|
||||
"Run this script against a skill inside a checkout to get this check."
|
||||
)
|
||||
else:
|
||||
resolved_base_ref = base_ref_override.strip()
|
||||
resolve_error = None
|
||||
if not resolved_base_ref:
|
||||
rc, mb_out, mb_err = run_git(["merge-base", "HEAD", "origin/main"], repo_root)
|
||||
if rc == 0 and mb_out.strip():
|
||||
resolved_base_ref = mb_out.strip()
|
||||
else:
|
||||
resolve_error = (
|
||||
"`git merge-base HEAD origin/main` could not resolve a base ref"
|
||||
+ (f" ({mb_err.strip()})" if mb_err.strip() else "")
|
||||
+ " — there may be no origin/main remote, HEAD may be detached, or the clone may be shallow."
|
||||
)
|
||||
elif not ref_exists(resolved_base_ref, repo_root):
|
||||
resolve_error = f"--base-ref value '{resolved_base_ref}' does not resolve to a commit in this repository."
|
||||
|
||||
if resolve_error:
|
||||
emit_info(
|
||||
"Check 9 skipped — no base ref could be resolved",
|
||||
"references/sources.md",
|
||||
resolve_error + " Check 9 did not run for any slug in this skill. "
|
||||
"Pass --base-ref=<ref>, or set the VALIDATE_PROVENANCE_BASE_REF environment variable, "
|
||||
"to compare against something other than origin/main."
|
||||
)
|
||||
else:
|
||||
sources_md_relpath = os.path.relpath(sources_md_path, repo_root)
|
||||
rc, old_sources_content, show_err = run_git(
|
||||
["show", f"{resolved_base_ref}:{sources_md_relpath}"], repo_root
|
||||
)
|
||||
if rc != 0:
|
||||
# The base ref resolved fine, but references/sources.md did not
|
||||
# exist there at all — the whole file is new. Every entry in it
|
||||
# is therefore a creation, not a change: nothing to flag, and
|
||||
# this is not a structural failure of the check, so no INFO
|
||||
# either. Same reasoning applies per-slug below when the ref
|
||||
# resolved but a given '## <slug>' heading did not exist yet.
|
||||
old_sources_content = None
|
||||
|
||||
if old_sources_content is not None:
|
||||
for slug in unique_slugs:
|
||||
changed_fields = []
|
||||
for field_name in ("Description", "Contributing files"):
|
||||
old_value = parse_field_raw(old_sources_content, slug, field_name)
|
||||
new_value = parse_field_raw(sources_content, slug, field_name)
|
||||
if old_value is None or new_value is None:
|
||||
# No earlier claim to compare against — a brand-new
|
||||
# entry, or a field that did not exist yet at the
|
||||
# base ref. That is a creation, not a change, and is
|
||||
# never flagged.
|
||||
continue
|
||||
if normalize_field_text(old_value) != normalize_field_text(new_value):
|
||||
changed_fields.append(field_name)
|
||||
if changed_fields:
|
||||
field_list = " and ".join(changed_fields)
|
||||
emit_info(
|
||||
f"'{field_list}' changed for '{slug}' since {resolved_base_ref}",
|
||||
f"references/sources.md (## {slug})",
|
||||
f"The '## {slug}' entry's {field_list} text differs from the version at "
|
||||
f"{resolved_base_ref}. This script can confirm the entry is internally "
|
||||
f"consistent, but it cannot verify whether the claim itself is still true — a "
|
||||
f"retrofit once turned an honest hedge into an unsupported confident claim and "
|
||||
f"every structural check here passed it silently. Re-read the upstream research "
|
||||
f"doc named in this entry's Research doc field and the Contributing files it "
|
||||
f"lists, and confirm by hand that the wording still holds."
|
||||
)
|
||||
|
||||
print_findings()
|
||||
sys.exit(1 if has_fail else 0)
|
||||
PYTHON
|
||||
|
||||
Reference in New Issue
Block a user