Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

check-skill-refs: fail on stale donor-remnant allowlist entries (F10)

garrytand25ea86952bf
diff --git a/scripts/check-skill-refs.mjs b/scripts/check-skill-refs.mjs
index c4e9c541df..554e721e27 100755
--- a/scripts/check-skill-refs.mjs
+++ b/scripts/check-skill-refs.mjs
@@ -12,7 +12,8 @@
// 2. DONOR REMNANTS (fail, allowlist-ratcheted): donor-workspace path prefixes
// must not appear outside files listed in scripts/skill-refs-allowlist.txt.
// The allowlist is a ratchet: it may shrink, never silently grow — add a
-// line only with a review-visible commit.
+// line only with a review-visible commit. An entry whose file has no donor
+// hit (cleaned or deleted) fails as stale, so the list shrinks with it.
// 3. CLI REFS (warn only): `gbrain <cmd>` tokens inside fenced code blocks are
// checked against the CLI's --tools-json surface. Warnings never fail the
// build; they exist so a skill body promising a nonexistent command is
@@ -88,6 +89,7 @@ const allowlist = new Set(
const files = walk(SKILLS_DIR);
const failures = [];
const warnings = [];
+const allowlistHits = new Set();
for (const file of files) {
// Path identity is always "skills/<path-under-skills-dir>", independent of cwd
@@ -98,7 +100,9 @@ for (const file of files) {
const text = readFileSync(file, 'utf8');
// --- 2. donor remnants (skip migrations wholesale) ---
- if (!inMigrations && !allowlist.has(rel)) {
+ if (!inMigrations && allowlist.has(rel)) {
+ if (DONOR_PREFIXES.some((prefix) => text.includes(prefix))) allowlistHits.add(rel);
+ } else if (!inMigrations) {
for (const prefix of DONOR_PREFIXES) {
if (text.includes(prefix)) {
const line = text.split('\n').findIndex((l) => l.includes(prefix)) + 1;
@@ -247,6 +251,13 @@ if (RUN_CLI_REFS) {
}
}
+// The ratchet only shrinks if a clean file leaves the list: an entry whose
+// file no longer carries a donor prefix (or no longer exists) fails.
+for (const entry of allowlist) {
+ if (allowlistHits.has(entry)) continue;
+ failures.push(`[stale-allowlist] ${entry} — listed in ${ALLOWLIST_PATH} but has no donor-remnant hit. Why: an unused entry would let a future donor path in that file pass unreviewed. Fix: delete the line "${entry}" from ${ALLOWLIST_PATH}`);
+}
+
for (const w of warnings) console.error(`WARN ${w}`);
if (failures.length) {
for (const f of failures) console.error(`FAIL ${f}`);
diff --git a/scripts/skill-refs-allowlist.txt b/scripts/skill-refs-allowlist.txt
index 3cbef7f6b6..31500a3332 100644
--- a/scripts/skill-refs-allowlist.txt
+++ b/scripts/skill-refs-allowlist.txt
@@ -1,5 +1,4 @@
# check-skill-refs donor-remnant allowlist (ratchet: may shrink, never silently grow).
# These files legitimately DOCUMENT donor/OpenClaw environments; they do not
# instruct writes to those paths. Review any addition like a permission grant.
-skills/setup/SKILL.md
skills/smoke-test/SKILL.md
diff --git a/test/scripts/check-skill-refs.test.ts b/test/scripts/check-skill-refs.test.ts
index 5b13b79d78..d95a81c228 100644
--- a/test/scripts/check-skill-refs.test.ts
+++ b/test/scripts/check-skill-refs.test.ts
@@ -88,6 +88,20 @@ describe('check-skill-refs', () => {
expect(pass.code).toBe(0);
});
+ test('fails on an allowlist entry whose file has no donor hit (stale) or does not exist', () => {
+ const setup = (skills: string) => {
+ mkdirSync(join(skills, 'alpha'));
+ writeFileSync(join(skills, 'alpha', 'SKILL.md'), '---\nname: alpha\n---\nclean body\n');
+ };
+ const clean = runOn(setup, 'skills/alpha/SKILL.md\n');
+ expect(clean.code).toBe(1);
+ expect(clean.out).toContain('[stale-allowlist] skills/alpha/SKILL.md');
+ expect(clean.out).toContain('Fix: delete the line "skills/alpha/SKILL.md"');
+ const missing = runOn(setup, 'skills/gone/SKILL.md\n');
+ expect(missing.code).toBe(1);
+ expect(missing.out).toContain('[stale-allowlist] skills/gone/SKILL.md');
+ });
+
test('scans .jsonl (routing-eval) files for donor remnants; allowlist ratchets them too', () => {
// Assemble the banned prefix at runtime (repo-wide privacy check bans the literal).
const bannedPath = ['/data', 'brain', 'fixture.md'].join('/');