refactor(kyberforge)!: merge skill-audit and agent-audit into factory-audit

Why

The two audit skills carried 1,724 lines of byte-identical duplication: the ADR-0020 boundary
resolver (1,061), vale-wrap.sh (526), the Vale style rules (44) and the Contributing-files parser
(93). Nothing shared them — they were held in sync by a 413-line pre-push gate and its 797-line
test suite. Sync-by-gate had already failed once: at 484357a the two parser copies drifted into
different spellings of the bullet loop while a docstring asserted they were identical. That drift
was behaviour-neutral and was re-unified by hand at 598a7c3, so the copies were identical at merge
time — but nothing had caught it, and the next drift need not be neutral.

Implementation Notes

Self-containment binds BETWEEN skills, not within one. The agentskills.io spec forbids reaching
across skill directories, which is why two separate skills needed embedded copies; two files inside
ONE skill may source a third. That is the whole reason the merge removes duplication rather than
relocating it.

The union of both bodies measured 1,532 words against BODY_MAX_WORDS=900, and only 211 of those
words were shared, so SKILL.md is a dispatch body. Step 0 resolves the flow from the target path
before any validation, and its table mirrors validate.sh's detection exactly: a directory holding
SKILL.md or a SKILL.md file (skill); a *.agent.md, or a .md directly under an agents/ directory
(agent); anything else stops without running a validator. Steps 1-3 live in
references/skill-flow.md and references/agent-flow.md, and gotchas that apply to one flow live in
that flow's file, since it is loaded on every invocation anyway. If validate.sh reports on the
other artifact type, the body restarts at Step 0.

Named factory-audit rather than forge-audit because forge is a live skill, and a family prefix that
matches a live sibling reads as ownership rather than membership.

The description carries one arrow per boundary target, because ADR-0020 resolves only the first
target after an arrow. It drops the quoted "audit this skill"-style phrases, which restated
"audited" in a second register (ADR-0020's duplicate-register rule). 241 characters, Gotchas 16%
of the body: no size SUGGESTIONs.

The boundary resolver stays embedded in two files rather than imported: a cache-installed plugin
cannot read outside its own directory, and the repo-root hook resolves via .pre-commit-hooks.yaml
where entry[0] is the only token pre-commit rewrites, so no single file is reachable by both.
tests/test-adr0020-contract.sh hashes both copies for byte-identity, and asserts validate.sh sources
the resolver and that no third copy exists.

The entry scripts classify the target from its resolved parent directory, so a bare agent filename
typed inside agents/ works; resolve SCRIPT_DIR CDPATH-safely; and exit 2 when a lib-*.sh is
missing, rather than dying with exit 1, the tier the flows relay as real findings.

The provenance run functions stash their findings code in KYBERFORGE_PROV_RC and
return 0, so validate-provenance.sh calls them UNTESTED. Testing a function's
status (`f || RC=$?`) disables errexit for its entire body, and no subshell or
`set -e` inside can re-arm it once the call sits in a condition context
(measured, both spellings). Their error paths use `exit`, which is unaffected
either way; this keeps errexit armed for anything added later.

Case 0's readability guard reads the file instead of asking `[[ -r ]]`. `-r` is
access(2), which answers yes for uid 0 even on a mode-000 file, and this repo's
dev environment is root -- so the guard could never fire where it exists to fire.
A read attempt is also the stricter question, catching EIO. This is the reasoning
scripts/check-vale-style-sync.sh carried before this commit deleted it; the
hazard did not go with it.

All three entry scripts are CDPATH-safe, vale-wrap.sh included: both of its cd sites are cleared,
the --config resolution and the directory-mirror walk, where an exported CDPATH would otherwise
print a decoy path into the -print0 stream and build the mirror from the decoy's files. The two
remaining bare cd calls take absolute paths, which CDPATH is never consulted for.

Impact

BREAKING: skill-audit and agent-audit no longer exist as invocable skills. kyberforge goes to
2.0.0 (catalog 0.4.7).

Check logic is unchanged: differential runs of the old and new validators across every skill and
agent produced byte-identical stdout, stderr and exit codes, and the reconstructed Python payloads
differ only in comments and the references/field-inventory.md -> agent-field-inventory.md rename.
One doctrine governs the tiers: exit 0 is audited and clean, exit 1 is audited with findings OR a
target present but unreadable, exit 2 is that nothing was audited at all. Edge paths DID change,
deliberately (full table in ADR-0025):
- a missing target exits 2 (never ran), not 1, under its own "does not exist" message; detection is
  by path shape, so a shape-matching path that is simply absent used to reach the validator and come
  back as a FAIL against a file that never existed;
- an unshaped target exits 2 under the generic "matches neither" message, and a directory with no
  SKILL.md under a third, distinct one -- three exit-2 messages, not one;
- a dangling symlink or a symlink loop stays exit 1: it is present but broken, which is a finding
  about the artifact rather than a usage error;
- a SKILL.md file path is audited as its skill directory instead of refused;
- a .md agent outside an agents/ directory is refused rather than audited;
- a missing script library, a missing python3, a missing PyYAML, and no argument at all each exit 2.
  validate-provenance.sh already exited 2 for the last two; validate.sh now matches it.

.pre-commit-hooks.yaml is a published contract consumed by external repos. Both hook IDs and both
files: regexes are unchanged; only entry: and description: moved.

scripts/check-vale-style-sync.sh (413), scripts/sync-vale-styles.sh (21),
tests/test-check-vale-style-sync.sh (797) and agent-audit/scripts/README.md (47) are deleted. The
checker made 17 assertions: 6 compared the two Vale copies and are moot; 10 are rehomed into
tests/test-vale-wrap.sh (case 0, cases 28-31, and the suite's Vale-absent skip); and the
cross-manifest files: agreement check, which selected hooks by entry: and so could not survive both
hooks sharing one, is ported as case 33 pairing hooks by id:. Cases 28, 30 and 33 carry mutation
self-tests; narrowing the local skill prefilter to 6 of 38 SKILL.md files now fails the suite.

Skills go 39 to 38. Pre-push goes 9 repo-authored hooks to 8.

ADR: 0025
BREAKING-CHANGE: the skill-audit and agent-audit skills are removed. Both flows are served by
  factory-audit, which auto-detects whether it was handed a skill directory or an agent file.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YR2CjVumUbEGWcMikcoXBD
This commit is contained in:
2026-09-15 18:39:43 +00:00
parent a5962ba773
commit 620f20b0fd
119 changed files with 6308 additions and 5487 deletions

View File

@@ -25,14 +25,14 @@ set -euo pipefail
#
# Both spec ceilings are inclusive: a file at exactly MAX_LINES or MAX_WORDS
# passes, and only one past it fails. That matches
# skill-audit/scripts/validate.sh, which has always used `line_count <= 500` as
# factory-audit/scripts/lib-checks-skill.sh, which has always used `line_count <= 500` as
# its pass condition — the two previously disagreed at exactly 500 lines, so a
# SKILL.md could pass its own audit and still be blocked by the commit hook.
# The ADR-0020 ceilings are inclusive the same way.
#
# Token counts aren't computed exactly here — a whitespace word count is used
# as a proxy (Python's str.split(), the same primitive
# skill-audit/scripts/validate.sh applies to these two constants; `wc -w`
# factory-audit/scripts/lib-checks-skill.sh applies to these two constants; `wc -w`
# disagrees with it on Unicode separators, which is why the awk pass that used
# to live in the loop below is gone).
#
@@ -81,20 +81,21 @@ set -euo pipefail
# description differently is worse than one reader that refuses to start.
# These constants are intentionally duplicated in
# skill-audit/scripts/validate.sh (Python) rather than shared from one file:
# this script is a standalone bash pre-commit hook, that one is an in-skill
# Python validator invoked in a different context (same rationale as
# vale-wrap.sh's per-plugin duplication — see its own header comment).
# factory-audit/scripts/lib-checks-skill.sh (Python) rather than shared from one
# file: this script is a standalone bash pre-commit hook, that one is an
# in-skill Python check library invoked in a different context.
# tests/test-skill-size-check.sh asserts both files agree on these values, so
# drift between them fails CI rather than silently diverging.
#
# The ADR-0020 constants below are duplicated the same way and carry the same
# warning: skill-audit/scripts/validate.sh holds a second copy of
# warning: factory-audit/scripts/lib-checks-skill.sh holds a second copy of
# DESC_SUGGEST_CHARS / DESC_MAX_CHARS / BODY_SUGGEST_WORDS / BODY_MAX_WORDS,
# and agent-audit/scripts/validate.sh holds a third copy of the two
# and factory-audit/scripts/lib-checks-agent.sh holds a third copy of the two
# description constants (agents take the description gates and, per ADR-0020,
# deliberately take NO body word gate). If they drift, this audit reports a
# skill ready to ship that the commit hook then rejects.
# deliberately take NO body word gate). ADR-0025's merge put those two libraries
# in one directory but did NOT collapse the copies — the two flows gate
# different spans — so the drift risk is unchanged: if they diverge, the audit
# reports a skill ready to ship that the commit hook then rejects.
MAX_LINES=500
MAX_WORDS=2770
@@ -146,7 +147,7 @@ fi
# them as 0, and both ceilings passed in total silence — the one outcome
# this script forbids itself.
# * awk's NR/NF do not agree with the Python splitlines()/split() that
# skill-audit/scripts/validate.sh uses for the SAME two constants.
# factory-audit/scripts/lib-checks-skill.sh uses for the SAME two constants.
# splitlines() also breaks on \x0b \x0c \x1c \x1d \x1e \x85 U+2028 U+2029
# and split() on every Unicode space, so a body padded with U+2028 read as
# 6 lines here and 606 lines there — hook green, audit FAIL.
@@ -225,16 +226,20 @@ def info(msg):
print("INFO: %s" % msg)
# Anything inside the BEGIN/END markers below is hashed byte-for-byte against
# the plugin copy by tests/test-adr0020-contract.sh. Never edit the marked span
# in one file alone -- including its comments -- or that test fails. Change both
# copies in one commit, keeping the span's line count intact.
# ===== BEGIN ADR-0020 SHARED BOUNDARY RESOLVER =====
# ONE resolver, embedded VERBATIM in three scripts:
# ONE resolver, embedded VERBATIM in two scripts (ADR-0025 retired the third):
# scripts/skill-size-check.sh
# plugins/kyberforge/.apm/skills/skill-audit/scripts/validate.sh
# plugins/kyberforge/.apm/skills/agent-audit/scripts/validate.sh
# The block between these markers must stay byte-identical in all three. It is
# copied rather than imported because a cache-installed plugin's scripts cannot
# read files outside their own plugin directory, so there is no single file all
# three can share (same constraint that forces the ADR-0020 constants to be
# duplicated). Edit one copy, then paste it over the other two.
# plugins/kyberforge/.apm/skills/factory-audit/scripts/lib-boundary-resolver.sh
# The block between these markers must stay byte-identical in both. It is copied
# rather than imported because a cache-installed plugin's scripts cannot read
# files outside their own plugin directory, and this repo-root hook resolves via
# .pre-commit-hooks.yaml, where entry[0] is the only token pre-commit rewrites --
# so no single file is reachable by both (the same constraint that duplicates the
# ADR-0020 constants). Edit one copy, then paste it over the other.
#
# Requires: glob, os, re, yaml (imported by the host script; PyYAML is a hard
# dependency, preflighted in bash before the interpreter starts).
@@ -268,9 +273,9 @@ def read_text(path):
# The set of names a boundary clause may resolve against is derived from an
# AUTHORING ROOT found by walking up FROM THE TARGET FILE. It is NEVER derived
# from this script's own location: deriving it from ${BASH_SOURCE} leaked
# holocron's 39-skill universe into every consumer repo that ran this hook
# through pre-commit, so a consumer skill routing to `skill-audit` resolved
# against a plugin it had never installed.
# holocron's whole skill universe into every consumer repo that ran this hook
# through pre-commit, so a consumer skill routing to a holocron skill such as
# `factory-audit` resolved against a plugin it had never installed.
#
# An authoring root is the nearest ancestor holding plugins/*/.apm/skills/ or
# plugins/*/.apm/agents/ (a plugin monorepo), falling back to the nearest
@@ -530,8 +535,8 @@ def known_targets(start_dir):
# written yet, and any new process chain re-arms it. Unexercised is not the
# same as unnecessary, and the branch it guards is still load-bearing: the
# bare-arrow rule is the sole extractor for three real targets in
# kyberforge's audit skills (agent-audit -> agent-author, agent-audit ->
# skill-audit, skill-audit -> skill-author), all written unbackticked.
# kyberforge (factory-audit -> skill-author, factory-audit ->
# agent-author, apm-orchestrate -> apm-install), all written unbackticked.
# * A backticked hyphenated token counts only inside a boundary sentence.
# Unconditionally, `pre-push` or `commit-msg` in a TRIGGER clause is a hard
# FAIL with no escape hatch. Gating it costs nothing (measured over this
@@ -1164,7 +1169,7 @@ def hand_invoked(fm_text):
#
# Both read a FENCE-MASKED copy of the body. Scanning the raw body made a
# ```-fenced example a hard ERROR — and the skills most likely to carry one are
# skill-author and skill-audit, which DOCUMENT the references/ convention — and
# skill-author and factory-audit, which DOCUMENT the references/ convention — and
# let a `## Gotchas` heading inside a fenced block stand in for the real
# section. Masking preserves every byte offset (content becomes spaces,
# newlines stay), so a span found in the mask slices the original.
@@ -1189,12 +1194,12 @@ REFERENCE_POINTER = re.compile(
REFERENCE_PAST = re.compile(
r'\b(?:removed|deleted|renamed|superseded|replaced|obsolete|deprecated'
r'|former|formerly|gone|no longer|used to)\b', re.I)
# A pointer QUALIFIED by another skill's name — "skill-audit's
# references/validation-scripts.md" — names a file that is deliberately NOT in
# A pointer QUALIFIED by another skill's name — "factory-audit's
# references/skill-validation-scripts.md" — names a file that is deliberately NOT in
# this skill's directory. Requiring it on the local disk left NO legal spelling
# for a cross-skill reference at all: the only alternative, a full repo path
# (`plugins/kyberforge/.apm/skills/skill-audit/references/...`), is itself a
# FAIL under skill-audit's own file-structure rubric, because a path that climbs
# (`plugins/kyberforge/.apm/skills/factory-audit/references/...`), is itself a
# FAIL under factory-audit's own file-structure rubric, because a path climbing
# out of the skill directory stops resolving once the plugin is cache-installed.
# The possessive form is the sanctioned spelling, and it is skipped here. It is
# not checked further — this function has no way to locate another skill's
@@ -1318,7 +1323,7 @@ for path in files:
continue
# SPEC CONFORMANCE (family 1). Whole file, frontmatter included, counted
# with the SAME primitives skill-audit/scripts/validate.sh uses for these
# with the SAME primitives factory-audit/scripts/lib-checks-skill.sh uses for these
# two constants — see the note in bash above for what the previous awk pass
# got wrong.
lines = len(raw.splitlines())