Agent audit

From bdfinst/agentic-dev-team · View interactive version

Agent audit is an AI agent skill from the GitHub repository bdfinst/agentic-dev-team. Audit code-review agents, skills, and hooks for structural compliance. Use this when adding or modifying any agent, skill, or hook file, or for a periodic health check of the toolkit. Trigger phrases: "audit the agents", "check compliance", "validate the skills", "are the agents correct", or any tim

How to use this skill

Skill file

Agent Audit

Role: orchestrator. This skill performs mechanical compliance

checks — pattern matching against known-good structure.

You have been invoked with the /agent-audit skill. Audit agents and

skills for compliance with the eval system patterns documented in

.claude/docs/eval-system.md.

Monorepo-relative by design (#1637). Steps 8 and 2e's scripts/validate_agent_contract.py and scripts/check_registry_sync.py calls are intentionally bare, not a dangling-path defect. check_registry_sync.py hardcodes plugins/dev-team and checks this marketplace repo's own registry — it exists only at this repo's root, so no ${CLAUDE_PLUGIN_ROOT} path could ever resolve it. validate_agent_contract.py's repo-root copy is a thin wrapper delegating to plugins/marketplace-dev/scripts/validate_agent_contract.py (which does ship and is portable) — but there is no single variable spanning two independently-installed plugins, so the wrapper is reachable only from this monorepo checkout, where both plugin directories are siblings on disk. Both calls only make sense run from a dev-team-monorepo-shaped checkout (this repo, or a structural fork), never an installed plugin cache. See tests/repo/test_agent_implemented_by_resolves.py's INTENTIONAL_BARE_INVOCATION set, which checks the "does not ship" premise mechanically. (#1652 landed a Bash(...) grant in this skill's allowed-tools frontmatter covering all three of these script steps — including verify_tier.py below — by their exact bare/repo-relative invocation form, so they execute today; see the allowed-tools block above.)

Orchestrator constraints

  1. Check structure, not semantics. Verify required sections,

fields, and patterns exist. Do not evaluate whether detection

rules are good — that's agent-eval's job.

  1. Deterministic checks only. Every check should be reproducible:

does the field exist? Is the format correct? Does the section

match the expected pattern?

  1. When --fix is used, apply minimal structural fixes. Insert

missing sections/fields using templates. Do not rewrite existing

content.

  1. Be concise. Output the report table and action items. No

preambles, no per-file narration, no restating what was checked.

Steps

1. Parse arguments

Arguments: $ARGUMENTS

file only

for FAIL/WARN items

2. Audit agents

Scope: this audit covers agents from all plugins in the repository, not just

plugins/dev-team/agents/. Currently audited directories:

The automated effort-band gate (tests/agents/test_agent_effort_frontmatter.py)

discovers and checks agents from both directories; add new plugin agent directories

to AGENTS_DIRS in that test file when a new plugin is introduced.

Read each file in .claude/agents/*.md whose body contains a structured JSON

output schema — either inline (a line with "status": "pass|warn|fail|skip")

or a citation of knowledge/review-agent-output-contract.md — these are

review agents. Check:

  1. Structured output format: Does the agent specify a JSON output

schema, inline or by citing the shared contract?

fields (inline or via the cited contract)

  1. Severity definitions: Does the agent define severity levels?

criteria

  1. Detection rules: Does the agent list what it detects?

structure-review: run

python3 ${CLAUDE_PLUGIN_ROOT}/scripts/check_detect_tags.py. Each

## Detect bullet MUST carry exactly one [MECHANICAL] or [JUDGMENT]

tag, and each [MECHANICAL] bullet MUST name a lint rule

(rule: <id>) or give a reason (no rule: <reason>). The id MUST be in

templates/eslint/rule-ids.json (enabled or planned). A bullet

converted to a lint pointer MUST say "otherwise judge fully" and name a

rule listed as convertible there. FAIL on any offender. The same check runs as detect-bullets-tagged in

repo_invariants.py.

  1. Scope boundaries: Does the agent declare what it ignores?
  1. Self-describing: Does the agent depend on external config?

external config files

in the agent definition

  1. File scope: Does the agent declare which file types it

applies to?

their file scope

  1. Skip support: Does the agent define when to return

status: "skip"?

  1. Model/effort contract: Does the agent's frontmatter conform to the

native Claude Code sub-agent contract (ADR 0026)?

error into FAIL and every warning into WARN in the report. This is

the sole frontmatter-contract check — required-field presence (name,

description), name pattern, enum membership on any field present

(model, effort, permissionMode, memory, isolation, color,

background, maxTurns), unknown/misspelled-key warnings, and the

plugin-ignored-field warning for hooks/mcpServers/permissionMode.

plugins/security-assessment/ agent declares model: (an alias, full

model ID, or inherit) and effort: high — WARN if either is missing,

since that is this repo's local practice, not a contract requirement.

frontmatter. WARN if a body line restates either as prose (e.g. an

Effort: line, or a body-level model-tier label) — that duplicate is a

drift source and must be removed.

body declarations are NOT a restatement of model:/effort: and must

never be flagged by the single-source rule above. They name a different

tier — the one used for fix-verification re-dispatches only — and they

live in the body for the same reason Scope: and Cites: do (#1333:

frontmatter is reserved for the official contract; these are not part

of it). Validate them with:

```bash

python3 plugins/dev-team/scripts/verify_tier.py --all

```

This one is repo-relative, not ${CLAUDE_PLUGIN_ROOT}-qualified, even

though the script ships: /agent-audit's whole job is auditing the

agents in the current working tree the operator just edited.

${CLAUDE_PLUGIN_ROOT} would resolve to the installed plugin cache

instead — silently auditing a stale, already-released copy rather than

the edit under review.

Fold a non-empty errors array into WARN, naming the agent and the

invalid value. An agent with no declaration is correct, not incomplete —

the default is deliberately "same tier as discovery". Contract:

knowledge/verification-mode.md.

  1. Context needs: Does the agent declare a Context needs: field?

(prior-phase findings, RECON output) and does not read source

files directly; qualifies when the agent's only input is an artifact

produced by an earlier pipeline phase

valid when every token is one of the four values above (e.g.

artifact-stream, full-file is valid for an agent that reads both

upstream artifacts and full source files). An unknown token in a

combined declaration still WARNs on that token specifically.

  1. No colons in description: Does the description: frontmatter field contain a colon?

2b. Audit agent tool declarations (all agents)

Read every file in .claude/agents/*.md (team agents and review agents). Check:

  1. Skills-Skill invariant: If the agent body contains a ## Skills heading, the tools: frontmatter MUST include Skill.

Include the result in the agent report table under a Skills-Tool column.

Fix (when --fix is passed): Append , Skill to the tools: frontmatter line. Report FIXED: <agent> — Added Skill to tools:.

  1. Code-intelligence MCP invariant (review agents): Every read-only *-review agent MUST grant the five code-intelligence MCP tools in tools: — mcp__codegraph__codegraph_explore and mcp__plugin_repowise_repowise__{get_context,get_symbol,search_codebase,get_risk} — so a review on a repo with a CodeGraph/Repowise index uses verified skeletons and resolved call graphs instead of raw whole-file reads (the grant is inert when the server is absent; agents fall back to Read/Grep/Glob). This mirrors the Skills-Skill invariant: it self-extends to future *-review agents.
  1. Code-intelligence mapping invariant (non-review team agents): Every non-review team agent in the #1108 mapping MUST grant its tier's tools in tools: — the narrow tier (software-engineer, mutation-kill, qa-engineer, data-flow-tracer) grants codegraph + the four Repowise tools, with data-flow-tracer also carrying a scoped Bash(graphify *); the rationale tier (adr-author, architect, security-engineer, platform-engineer, codebase-recon) additionally grants mcp__plugin_repowise_repowise__get_why. Coverage is the union of the mapping's config keys and a structural sweep (team agents by ## Behavioral Guidelines or Enforcement: script, minus *-review, minus a documented exclusion list), so a new team agent that is neither mapped nor excluded fails rather than silently escaping the mapping. This is the non-review counterpart to invariant 2: review agents keep their five-tool set there; this check never evaluates *-review agents.
  1. Code-intelligence grant invariant (security-assessment plugin, issue #1388): Invariants 2 and 3 above cover plugins/dev-team/agents/ only. Every agent in CODE_READING_AGENTS (authorization-logic-review, business-logic-domain-review, compliance-edge-annotator, cross-repo-synthesizer, deep-code-reasoning, fp-reduction, recon-driven-scan, tool-finding-narrative-annotator) MUST grant the same five-tool BASE_MCP_TOOLS set in tools:. The remaining 5 synthesis-only plugins/security-assessment/agents/*.md files (redteam-report-generator, exec-report-generator, redteam-recon-analyzer, redteam-evasion-analyzer, redteam-extraction-analyzer) interpret a fixed set of upstream probe/report artifacts and produce narrative output rather than reasoning about arbitrary target-repo code, and are excluded — the grant would be inert for them (this is a fixed classification, not a Glob-presence heuristic: exec-report-generator carries Glob for its own artifact-directory walk yet is still excluded).

Mechanics for invariants 2–4: all three delegate to plugins/dev-team/scripts/lib/mcp_tool_grants.py's shared run_grants_check (single read+parse pass per agent, both for detection and --fix) and, under --json, report the same envelope (check/evaluated/offenders/unclassified/fixed/unfixable/ok/notes) so results are comparable across the three checks.

| Invariant | Report column | Delegated script | Config source of truth | Unclassified handling |

|---|---|---|---|---|

| 2. Code-intelligence (review agents) | Code-Intel | plugins/dev-team/scripts/check_review_agent_mcp_tools.py | MCP_TOOL_NAMES | n/a — glob-discovered, no roster |

| 3. Code-intelligence mapping (non-review) | Mapping | plugins/dev-team/scripts/check_agent_tool_mapping.py | TIER_CONFIG / EXCLUSIONS | reported, not auto-fixed |

| 4. Code-intelligence (security-assessment) | SA-MCP | plugins/dev-team/scripts/check_security_assessment_mcp_tools.py | CODE_READING_AGENTS / NON_CODE_READING_AGENTS | reported, not auto-fixed |

Include each invariant's result in the agent report table under its column above. Invariant 4 is additionally wired into scripts/ci-local.sh as chk_sa_mcp_tools, so drift fails CI, not just this manual audit pass.

All three delegated scripts above are repo-root-relative, not ${CLAUDE_PLUGIN_ROOT}-qualified — same working-tree-vs-cache reasoning as verify_tier.py above (§2b): each mutates agent files resolved relative to its own __file__, so a ${CLAUDE_PLUGIN_ROOT}-qualified invocation would silently edit the installed plugin cache's copy instead of the operator's own checkout.

Fix (when --fix is passed): run the delegated script above with --fix — it appends its missing tool names to tools: (merge, never replacing existing grants such as Read, Grep, Glob/Skill). Unclassified agents, where applicable, are reported, not auto-fixed — classify each into the config or exclusion list named above. Report FIXED: <agent> — added <tool names>.

2c. Audit team agent personas

A file is a team agent when its body contains a ## Behavioral Guidelines section. Exemption: an agent that declares Enforcement: script in its body is a script-enforced prose spec, not a persona-driven team agent — skip the persona checks below for it and instead verify it carries a > **Implemented by:** <script> pointer immediately after the H1. For each remaining team agent, check:

  1. Persona paragraph: Is there a You are… sentence immediately after the H1 heading and before the first ## section?
  1. Non-generic Output discipline: Does the ## Output discipline section exist and contain role-specific content?

Include both results in the agent report table under Persona and Output-Disc columns.

Fix (when --fix is passed):

2d. Citation drift lint (preventive)

Reviewer agents sometimes inline normative rules — numeric thresholds like

"under 50 lines" or "80% coverage" — independently of the canonical skill or

knowledge file. When that source changes, the agent silently keeps enforcing

the stale value. The citation lint makes the dependency explicit: an agent

declares its sources in a body-level Cites: list (not frontmatter — cites

is not part of the official sub-agent contract), and every numeric threshold

the agent states on an RFC-2119 line (MUST/SHOULD/SHALL/REQUIRED/NEVER/ALWAYS)

must also appear in a cited source.

Perform the check by reading (the same mechanical, deterministic style as the

other audits — no judgment):

  1. Read each agent's body and look for a Cites: list. Each entry names

a skill (skills/<name>/SKILL.md) or knowledge file (knowledge/<name>.md).

  1. In the agent body, find every line carrying an RFC-2119 keyword

(MUST/MUST NOT/SHOULD/SHALL/REQUIRED/NEVER/ALWAYS). Ignore lines inside code

fences (``` ` ``/~~~) and blockquotes (>`). On each such line, collect

the numeric thresholds (50, 80%, 40.5); ignore issue refs like #99.

  1. Read each cited source and check the threshold appears in it.

Classify:

(possible drift): report the token + line number.

adding a Cites: list.

Phase 1 is non-blocking — these are warnings, never failures. Do not

red-line the audit on a citation warning; surface it as an action item so drift

is visible while Cites: adoption grows. CI runs the deterministic counterpart,

scripts/citation_lint.py (also advisory, exit 0), on every PR.

2e. Registry completeness (preventive)

The catalog tables (knowledge/agent-registry.md for agents and agent-loaded

skills; the plugin CLAUDE.md slash-command table for user-invocable skills) are

hand-maintained. When an agent or skill is added or removed without updating the

matching table, the catalog drifts and the orchestrator routes against a roster

that no longer matches the filesystem.

Run the deterministic sensor:

python3 scripts/check_registry_sync.py

It asserts a bijection between plugins/dev-team/agents/*.md +

plugins/dev-team/skills/*/SKILL.md and the registry rows, reporting MISSING

(file with no row) and ORPHAN (row with no file). Unlike the citation lint this

is a hard gate — exit 1 on any discrepancy. Fix it by adding or removing the

catalog row by hand (the marketplace-dev plugin's /agent-create /

/agent-remove maintain these tables automatically).

Effort bands are deliberately not checked — they live only in frontmatter. The

pytest suite tests/repo/test_registry_sync.py runs this on every PR.

2e-bis. Knowledge-reference integrity (preventive)

Agents read shared guidance from knowledge/*.md. Two ways this silently

breaks (issue #1103): the file is renamed/removed but a reference lingers, or

the reference uses a bare knowledge/X.md path that resolves against the

target repo's cwd at runtime — not the plugin dir — so the agent reads

nothing and degrades to hardcoded fallbacks.

Run the deterministic sensor:

python3 -m pytest tests/agents/test_agent_knowledge_anchor.py

It hard-gates three invariants on every knowledge/X.md reference in an

agent body: it cites a valid index.json anchor or carries `Whole-file

load:`; the file is packaged on disk; and it is prefixed with

${CLAUDE_PLUGIN_ROOT}/ (the only runtime-resolvable form — a prose "lives

in plugins/dev-team/knowledge/..." pointer is tolerated). Runs on every PR.

2f. CLAUDE.md and token-efficiency structural checks

Two deterministic Python scripts validate concerns that the LLM-based review

agents (claude-setup-review and token-efficiency-review) handle as deeper

semantic checks. Run these scripts for a fast, CI-safe structural pass:

CLAUDE.md / setup review (frontmatter schema, field completeness, effort

bands, duplicate rules):

python3 "${CLAUDE_PLUGIN_ROOT}/scripts/claude_setup_review.py" --plugin-root <plugin-root-path>

Token-efficiency review (file line counts, CLAUDE.md size, LLM

anti-patterns):

python3 "${CLAUDE_PLUGIN_ROOT}/scripts/token_efficiency_review.py" --files <path>...

Both scripts exit 0 and emit JSON findings to stdout. Surface any error

or warning severity findings as FAIL/WARN rows in the audit report table.

The scripts are the authoritative structural gate — do not dispatch the

claude-setup-review or token-efficiency-review agents from this skill;

those agents run under /code-review for semantic depth.

3. Audit skills

Read each file in .claude/skills/*.md and .claude/skills/*/SKILL.md and check:

  1. Role declaration: Does the skill declare its role?

workflow initiators) MUST have an explicit Role: line in the SKILL.md

body, immediately after the H1 (matching /plan, /build,

/code-review, /pr, /ship): Role: orchestrator, Role: worker, or

Role: implementation. A frontmatter-only role: field (lowercase key)

does NOT satisfy this — it's easy to add without stating the

orchestration-discipline contract the body line carries. WARN if a

user-invocable skill has no body Role: line.

user-invocable: true) are exempt from the body-line requirement — a

frontmatter role: field, or no role at all for pure reference

material, is acceptable. WARN only if such a skill has no role

declared anywhere (frontmatter or body).

review or modify code

  1. Constraints section: Does the skill declare its boundaries?

minimize context

JSON

changes

  1. Structured steps: Does the skill have numbered steps?
  1. Argument parsing: Does the skill document its arguments?
  1. Output format: Does the skill describe its output?
  1. Conciseness directive: Does the skill instruct concise output?

output tokens

  1. Validation gates: Does the skill run validation where

appropriate?

lint/build/tests

  1. No colons in description: Does the description: frontmatter field contain a colon?

4. Audit hooks

Read each file in .claude/hooks/*.sh and check (the *.sh glob already

excludes .claude/hooks/freeze-state.json and

.claude/hooks/careful-state.json — plugin-written runtime state, not

operator-authored hook code; see CODE0

§ Environment variables, issue #1904 item 10):

  1. Advisory behavior: Does the hook exit 0?
  1. Input handling: Does the hook read stdin and extract file

path?

  1. Scope filtering: Does the hook filter by file type?

5. Generate report

# Agent Audit Report

## Agents
| Agent | Output Format | Severity | Detection | Scope | Self-Describing | File Scope | Skip | Model Tier | Context Needs | Skills-Tool | No-Colon Desc | Status |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| test-review | PASS | PASS | PASS | PASS | PASS | N/A | PASS | PASS | PASS | PASS | PASS | OK |
| js-fp-review | PASS | PASS | PASS | PASS | PASS | PASS | PASS | PASS | PASS | N/A | PASS | OK |
| ... | | | | | | | | | | |

## Skills
| Skill | Role | Constraints | Steps | Arguments | Output | Validation | No-Colon Desc | Status |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| code-review | PASS | PASS | PASS | PASS | PASS | N/A | PASS | OK |
| apply-fixes | PASS | PASS | PASS | PASS | PASS | PASS | PASS | OK |
| ... | | | | | | | |

## Hooks
| Hook | Advisory | Input | Scope Filter | Status |
| --- | --- | --- | --- | --- |
| js-fp-review.sh | PASS | PASS | PASS | OK |
| token-efficiency-review.sh | PASS | PASS | PASS | OK |
| ... | | | | |

## Citation drift (Phase 1 — advisory)
| Agent | cites | Drift / Advisory | Status |
| --- | --- | --- | --- |
| structure-review | yes | — | PASS |
| naming-review | no | states 1 threshold, no Cites: | WARN |
| ... | | | |

## Summary
- Agents: N OK, N WARN, N FAIL
- Skills: N OK, N WARN, N FAIL
- Hooks: N OK, N WARN, N FAIL
- Citation drift: N PASS, N WARN (advisory, non-blocking)
- Action items: [list of things to fix]

6. Apply fixes (when `--fix` is passed)

If --fix was NOT passed, list action items and stop.

If --fix WAS passed, automatically apply fixes for each FAIL/WARN

item:

Agent fixes:

```text

Output JSON: per ${CLAUDE_PLUGIN_ROOT}/knowledge/review-agent-output-contract.md (Whole-file load: short, canonical schema).

```

Prefer this citation form over inlining the schema — see

knowledge/review-agent-output-contract.md for the canonical shape and

its documented per-agent extensions/status exceptions.

```text

Severity: error=<agent-specific>, warning=<agent-specific>, suggestion=<agent-specific>

```

## Detect:

```text

## Skip

Return {"status": "skip", "issues": [], "summary": "<reason>"} when:

```

Skill fixes:

## Steps with ### 1., ### 2., etc.

after the skill heading

After each fix:

  1. Read the file to confirm the fix was applied
  2. Re-run the specific check to verify it now passes
  3. Report: FIXED: <agent/skill> — <what was fixed>

7. Fix summary

If --fix was used, append a fix summary after the audit report:

## Fixes Applied
- FIXED: <name> — Added output format
- FIXED: <name> — Added skip section
- SKIPPED: <name> — <reason fix could not be auto-applied>

Re-run /agent-audit to verify all fixes.
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.