feat(kyberforge): retarget forge skills to author/audit APM content #93

Merged
Defame1297 merged 14 commits from feat/89-apm-native-authoring into main 2026-08-12 11:48:50 +00:00
5 changed files with 67 additions and 12 deletions
Showing only changes of commit f037d49b5c - Show all commits

View File

@@ -25,4 +25,4 @@ target disable-model-invocation user-invocable mcp-servers metadata
## apm-agent-allowlist
name description model
name description model source_keys

Allowlist contradicts agent-author's own instructions. apm-agent-allowlist omits source_keys, contradicting agent-author/SKILL.md's explicit instruction to add source_keys at plugin/APM scope when research-sourced — so a correctly-authored file fails validation.

Reproduced: a package-scope agent file with source_keys: fails validate.sh with FAIL field 'source_keys' is not in the vendor-neutral APM agent allowlist (description, model, name).

**Allowlist contradicts agent-author's own instructions.** `apm-agent-allowlist` omits `source_keys`, contradicting `agent-author/SKILL.md`'s explicit instruction to add `source_keys` at plugin/APM scope when research-sourced — so a correctly-authored file fails validation. Reproduced: a package-scope agent file with `source_keys:` fails `validate.sh` with `FAIL field 'source_keys' is not in the vendor-neutral APM agent allowlist (description, model, name)`.

View File

@@ -54,7 +54,12 @@ if not (fname.endswith('.agent.md') or fname.endswith('.md')):
print(f"Error: unrecognized extension '{fname}' — expected .md or .agent.md", file=sys.stderr)
sys.exit(2)
TYPE_RE = re.compile(r'^type:\s*(instructions|skill|hybrid|prompts)\b')
# Matches a top-level `type:` line whose value is exactly one of the four

Not quote-tolerant, unlike validate.sh. TYPE_RE lacks the quote-tolerant ['\"]? group that validate.sh's APM_TYPE_RE has, so a quoted type: "skill" value is recognized as plugin scope by validate.sh but not by validate-provenance.sh (or new-agent.sh/new-skill.sh).

Reproduced: with type: "skill" in apm.yml, validate.sh correctly detects plugin scope; validate-provenance.sh on the same file exits 0 silently even with an unresolved source_keys entry that should have FAILed.

**Not quote-tolerant, unlike validate.sh.** `TYPE_RE` lacks the quote-tolerant `['\"]?` group that `validate.sh`'s `APM_TYPE_RE` has, so a quoted `type: "skill"` value is recognized as plugin scope by `validate.sh` but not by `validate-provenance.sh` (or `new-agent.sh`/`new-skill.sh`). Reproduced: with `type: "skill"` in `apm.yml`, `validate.sh` correctly detects plugin scope; `validate-provenance.sh` on the same file exits 0 silently even with an unresolved `source_keys` entry that should have FAILed.
# package content types — identical to validate.sh's APM_TYPE_RE. Group 1's
# optional quote must be closed by \1 (or nothing), and the value must be
# followed by whitespace/end-of-line so a malformed value like `prompts-only`
# doesn't false-match on the `prompts` prefix.
TYPE_RE = re.compile(r"^type:\s*(['\"]?)(instructions|skill|hybrid|prompts)\1(?:\s|$)")
# --- Find package root: walk up for the nearest ancestor apm.yml that

Silent no-op on plugin.json-only plugins. find_plugin_root() shares validate.sh's plugin.json blind spot, so provenance validation silently exits 0 (no check performed) for every existing plugin.json-only plugin.

Reproduced: validate-provenance.sh plugins/kyberforge/agents/apm-orchestrate.md exits 0 with no output even though the file has real source_keys and a matching sources.md exists — the check this script exists to run never fires, with no signal that it was skipped.

**Silent no-op on plugin.json-only plugins.** `find_plugin_root()` shares `validate.sh`'s plugin.json blind spot, so provenance validation silently exits 0 (no check performed) for every existing plugin.json-only plugin. Reproduced: `validate-provenance.sh plugins/kyberforge/agents/apm-orchestrate.md` exits 0 with no output even though the file has real `source_keys` and a matching `sources.md` exists — the check this script exists to run never fires, with no signal that it was skipped.
# declares a top-level type: field. An apm.yml with no type: field is a
@@ -69,7 +74,9 @@ def find_plugin_root(start_dir):
with open(apm_yml) as f:
if any(TYPE_RE.match(line) for line in f):
return current
if os.path.isdir(os.path.join(current, '.git')):
# .git is a directory in a normal checkout but a file (`gitdir: ...`)
# in a git worktree — exists() covers both.
if os.path.exists(os.path.join(current, '.git')):
return None
parent = os.path.dirname(current)
if parent == current:

View File

@@ -133,9 +133,13 @@ def is_copilot_cloud_ide(fpath):
# --- Detect scope ---
# APM_TYPE_RE matches a top-level (column-0) `type:` line in apm.yml whose value is
# one of the four package content types. `[\'"]?` tolerates a quoted value; the
# pattern doesn't anchor the line end, so trailing whitespace/comments don't matter.
APM_TYPE_RE = re.compile(r"^type:\s*['\"]?(instructions|skill|hybrid|prompts)\b")
# exactly one of the four package content types. Group 1 captures an optional
# opening quote; \1 requires the same character (or nothing) to close it, so
# "skill" and '"skill"' both match but a mismatched quote doesn't. The value
# must then be followed by whitespace or end-of-line — not just a non-word
# character — so a malformed value like `prompts-only` is correctly rejected
# instead of false-matching on the `prompts` prefix.
APM_TYPE_RE = re.compile(r"^type:\s*(['\"]?)(instructions|skill|hybrid|prompts)\1(?:\s|$)")
def find_apm_package_root(apm_yml_path):
"""Return True if apm_yml_path has a top-level type: line (i.e. is a package
@@ -158,7 +162,9 @@ def detect_scope(start_dir):
# can't shadow user scope by being its own .git repo.
if current == home:
return 'user', home

Root-fallback scope disagrees with new-agent.sh. detect_scope()'s filesystem-root fallback returns 'user' scope (pinned to real $HOME), while new-agent.sh's equivalent fallback returns 'project' scope rooted at the given path — the two scripts disagree on any directory outside $HOME with no .git/apm.yml above it.

Reproduced: new-agent.sh test-agent /tmp/scratch (outside $HOME, no .git anywhere above it) correctly creates a project-scope pair. Running validate.sh on the created file then falls back to user scope and looks for the counterpart at $HOME/.copilot/agents/test-agent.agent.md, failing with FAIL counterpart file not found even though the valid pair sits right there.

**Root-fallback scope disagrees with new-agent.sh.** `detect_scope()`'s filesystem-root fallback returns 'user' scope (pinned to real `$HOME`), while `new-agent.sh`'s equivalent fallback returns 'project' scope rooted at the given path — the two scripts disagree on any directory outside `$HOME` with no `.git`/`apm.yml` above it. Reproduced: `new-agent.sh test-agent /tmp/scratch` (outside `$HOME`, no `.git` anywhere above it) correctly creates a project-scope pair. Running `validate.sh` on the created file then falls back to user scope and looks for the counterpart at `$HOME/.copilot/agents/test-agent.agent.md`, failing with `FAIL counterpart file not found` even though the valid pair sits right there.
if os.path.isdir(os.path.join(current, '.git')):
# .git is a directory in a normal checkout but a file (`gitdir: ...`)
# in a git worktree — exists() covers both.
if os.path.exists(os.path.join(current, '.git')):
return 'project', current
parent = os.path.dirname(current)
if parent == current:

View File

@@ -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 ;;

Scaffolds into the wrong directory for existing plugins. find_package_root() dropped the direct plugin.json check at $ROOT, so scaffolding a new agent inside an existing plugin.json-only plugin creates files in the wrong place.

Reproduced: new-agent.sh <name> plugins/kyberforge/ creates plugins/kyberforge/.claude/agents/<name>.md + .github/agents/<name>.agent.md instead of plugins/kyberforge/agents/<name>.md/.agent.md, diverging from where every other agent in that plugin actually lives.

**Scaffolds into the wrong directory for existing plugins.** `find_package_root()` dropped the direct `plugin.json` check at `$ROOT`, so scaffolding a new agent inside an existing plugin.json-only plugin creates files in the wrong place. Reproduced: `new-agent.sh <name> plugins/kyberforge/` creates `plugins/kyberforge/.claude/agents/<name>.md` + `.github/agents/<name>.agent.md` instead of `plugins/kyberforge/agents/<name>.md`/`.agent.md`, diverging from where every other agent in that plugin actually lives.
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

View File

@@ -81,6 +81,26 @@ if [[ ! -d "$TARGET_INPUT" ]]; then
exit 1
fi
# 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.
# Identical to agent-author's new-agent.sh copy of this helper.
is_apm_package_manifest() {
local apm_yml="$1" line value

Missing $HOME boundary check. find_package_root() has no $HOME boundary check (unlike new-agent.sh's), so the walk-up can continue past $HOME and bind to an unrelated ancestor package.

Reproduced with a fake $HOME nested under a directory with a type-bearing apm.yml above it: new-skill.sh my-skill $HOME/skills walked past $HOME and scaffolded into the ancestor package's .apm/skills/my-skill/ instead of the intended standalone location under $HOME.

**Missing $HOME boundary check.** `find_package_root()` has no `$HOME` boundary check (unlike `new-agent.sh`'s), so the walk-up can continue past `$HOME` and bind to an unrelated ancestor package. Reproduced with a fake `$HOME` nested under a directory with a type-bearing `apm.yml` above it: `new-skill.sh my-skill $HOME/skills` walked past `$HOME` and scaffolded into the ancestor package's `.apm/skills/my-skill/` instead of the intended standalone location under `$HOME`.
while IFS= read -r line; do
[[ "$line" =~ ^type:[[:space:]]*(.*)$ ]] || continue
value="${BASH_REMATCH[1]}"
value="${value%%[[:space:]]*}"
value="${value#\"}"; value="${value%\"}"

Loose regex lets malformed type: values false-match. This type: regex uses \b word-boundary matching (also present in validate.sh/validate-provenance.sh) instead of new-agent.sh's stricter ([[:space:]]|$), so a malformed value like type: prompts-only false-matches as valid prompts in three scripts but is correctly rejected in new-agent.sh.

An apm.yml with type: prompts-only (typo) is treated as a valid type: prompts package by validate.sh, validate-provenance.sh, and new-skill.sh, but new-agent.sh walks past it looking for a different package root — an agent and a skill scaffolded from the same directory land in different roots for the same manifest.

**Loose regex lets malformed `type:` values false-match.** This `type:` regex uses `\b` word-boundary matching (also present in `validate.sh`/`validate-provenance.sh`) instead of `new-agent.sh`'s stricter `([[:space:]]|$)`, so a malformed value like `type: prompts-only` false-matches as valid `prompts` in three scripts but is correctly rejected in `new-agent.sh`. An `apm.yml` with `type: prompts-only` (typo) is treated as a valid `type: prompts` package by `validate.sh`, `validate-provenance.sh`, and `new-skill.sh`, but `new-agent.sh` walks past it looking for a different package root — an agent and a skill scaffolded from the same directory land in different roots for the same manifest.
value="${value#\'}"; value="${value%\'}"
case "$value" in
instructions|skill|hybrid|prompts) return 0 ;;
esac
done < "$apm_yml"
return 1
}
# ---------------------------------------------------------------------------
# Walk up from <path> looking for a type-bearing apm.yml (package mode) or a
# .git boundary / filesystem root (standalone mode). An apm.yml with no
@@ -92,7 +112,7 @@ find_package_root() {
current="$(cd "$1" && pwd)"
while true; do
if [[ -f "$current/apm.yml" ]]; then
if grep -qE '^type:[[:space:]]*(instructions|skill|hybrid|prompts)\b' "$current/apm.yml"; then
if is_apm_package_manifest "$current/apm.yml"; then
echo "$current"
echo "package"
return 0
@@ -100,7 +120,9 @@ find_package_root() {
# apm.yml exists but has no type: field — marketplace-only manifest.
# Not a package match; keep walking up.
fi
if [[ -d "$current/.git" ]]; then
# .git is a directory in a normal checkout but a file (`gitdir: ...`) in
# a git worktree — -e covers both.
if [[ -e "$current/.git" ]]; then
echo "$current"
echo "no-package"
return 0