fix(kyberforge): fix apm-scope validation gaps in agent/skill authoring scripts
Post-implementation review of PR #93 (issue #89's apm.yml-native retargeting of skill-author/skill-audit/agent-author/agent-audit) found four confirmed defects across the four scripts' apm.yml `type:` walk-up logic: - field-inventory.md's apm-agent-allowlist was missing `source_keys`, contradicting agent-author/SKILL.md's own instruction (Step 5 checklist) to allow it at plugin/APM scope — a correctly-authored file with source_keys failed validate.sh. - validate.sh's APM_TYPE_RE and validate-provenance.sh's TYPE_RE disagreed: the former tolerated a quoted `type: "skill"` value, the latter didn't, despite agent-audit/SKILL.md explicitly documenting that validate-provenance.sh walks up "the same way validate.sh does". Both also used `\b` word-boundary matching, which false-matches a malformed value like `type: prompts-only` on the `prompts` prefix. Unified both regexes to be quote-tolerant and require an exact value. - All four scripts' `.git` project-boundary check used isdir()/[[ -d ]], which misses git worktrees where `.git` is a regular file (`gitdir: ...`) rather than a directory. Switched to exists()/[[ -e ]]. - new-agent.sh and new-skill.sh had the same quote-intolerance as above via inline `grep -qE` calls (new-skill.sh's also had the `\b` false-match bug); replaced both with a shared-shape `is_apm_package_manifest` bash helper matching the Python regex's semantics. Four other findings from the same review turned out not to be bugs: a bare `plugin.json` no longer signaling plugin scope is documented, intentional behavior (agent-audit/SKILL.md:30, agent-author/SKILL.md:87), deferred to issue #90's real plugin.json-to-apm.yml conversion — not something this fix should reverse. Verified via direct reproduction of each defect plus the full test suite: 147/147 bats tests, 39/39 shell-script tests, 12/12 summary categories. Refs: #89
This commit is contained in:
@@ -83,6 +83,25 @@ if [[ ! -d "$ROOT" ]]; then
|
||||
fi
|
||||
ROOT="$(cd "$ROOT" && pwd)"
|
||||
|
||||
# True if apm_yml's top-level `type:` line names one of the four APM package
|
||||
# types (instructions/skill/hybrid/prompts) — tolerating an optional matching
|
||||
# quote around the value and requiring the value end there, so a malformed
|
||||
# value like `prompts-only` doesn't false-match on the `prompts` prefix.
|
||||
is_apm_package_manifest() {
|
||||
local apm_yml="$1" line value
|
||||
while IFS= read -r line; do
|
||||
[[ "$line" =~ ^type:[[:space:]]*(.*)$ ]] || continue
|
||||
value="${BASH_REMATCH[1]}"
|
||||
value="${value%%[[:space:]]*}"
|
||||
value="${value#\"}"; value="${value%\"}"
|
||||
value="${value#\'}"; value="${value%\'}"
|
||||
case "$value" in
|
||||
instructions|skill|hybrid|prompts) return 0 ;;
|
||||
esac
|
||||
done < "$apm_yml"
|
||||
return 1
|
||||
}
|
||||
|
||||
# --- Walk-up package-root detection ---
|
||||
#
|
||||
# Mirrors agent-audit's validate.sh scope walk-up, with apm.yml + type: swapped
|
||||
@@ -94,12 +113,13 @@ ROOT="$(cd "$ROOT" && pwd)"
|
||||
# - reaching $HOME marks the user-scope boundary — stop, even if $HOME is
|
||||
# itself a .git-tracked dotfiles directory (checked before the .git test
|
||||
# below, so a dotfiles repo at $HOME can't shadow user scope).
|
||||
# - a .git directory marks the project-scope boundary — stop.
|
||||
# - a .git file or directory marks the project-scope boundary (a worktree's
|
||||
# .git is a file, not a directory) — stop.
|
||||
# - filesystem root reached with neither found — boundary-reached.
|
||||
find_package_root() {
|
||||
local current="$1"
|
||||
while true; do
|
||||
if [[ -f "$current/apm.yml" ]] && grep -qE '^type:[[:space:]]*(instructions|skill|hybrid|prompts)([[:space:]]|$)' "$current/apm.yml"; then
|
||||
if [[ -f "$current/apm.yml" ]] && is_apm_package_manifest "$current/apm.yml"; then
|
||||
echo "plugin"
|
||||
echo "$current"
|
||||
return
|
||||
@@ -109,7 +129,7 @@ find_package_root() {
|
||||
echo "$current"
|
||||
return
|
||||
fi
|
||||
if [[ -d "$current/.git" ]]; then
|
||||
if [[ -e "$current/.git" ]]; then
|
||||
echo "project"
|
||||
echo "$current"
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user