Skip to content

Add agent instruction validators #1

Add agent instruction validators

Add agent instruction validators #1

name: Agent & Instruction Check
on:
pull_request:
branches: [main]
types: [opened, synchronize, reopened]
paths:
- "agents/**"
- "instructions/**"
permissions:
contents: read
jobs:
agent-instruction-check:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: 20
- name: Install dependencies
run: npm ci
# ── Detect changed agent & instruction files ──────────────────
- name: Detect changed agent and instruction files
id: detect
run: |
declare -A SEEN_AGENT_FILES=()
declare -A SEEN_INSTRUCTION_FILES=()
AGENT_FILES=()
INSTRUCTION_FILES=()
while IFS= read -r -d '' file; do
case "$file" in
agents/*.agent.md)
if [ -f "$file" ] && [ -z "${SEEN_AGENT_FILES[$file]+x}" ]; then
SEEN_AGENT_FILES["$file"]=1
AGENT_FILES+=("$file")
fi
;;
instructions/*.instructions.md)
if [ -f "$file" ] && [ -z "${SEEN_INSTRUCTION_FILES[$file]+x}" ]; then
SEEN_INSTRUCTION_FILES["$file"]=1
INSTRUCTION_FILES+=("$file")
fi
;;
esac
done < <(git diff --name-only -z "origin/${{ github.base_ref }}...HEAD")
AGENT_COUNT=${#AGENT_FILES[@]}
INSTRUCTION_COUNT=${#INSTRUCTION_FILES[@]}
TOTAL=$((AGENT_COUNT + INSTRUCTION_COUNT))
{
echo "total=$TOTAL"
echo "agent_count=$AGENT_COUNT"
echo "instruction_count=$INSTRUCTION_COUNT"
echo "agent_files<<EOF"
printf '%s\n' "${AGENT_FILES[@]}"
echo "EOF"
echo "instruction_files<<EOF"
printf '%s\n' "${INSTRUCTION_FILES[@]}"
echo "EOF"
} >> "$GITHUB_OUTPUT"
echo "Found $AGENT_COUNT agent file(s) and $INSTRUCTION_COUNT instruction file(s) to check."
# ── Validate changed agent files ───────────────────────────────
- name: Validate agent files
if: steps.detect.outputs.agent_count != '0'
env:
AGENT_FILES_RAW: ${{ steps.detect.outputs.agent_files }}
run: |
AGENT_FILES=()
while IFS= read -r file; do
[ -n "$file" ] && AGENT_FILES+=("$file")
done <<< "$AGENT_FILES_RAW"
node ./eng/validate-agents.mjs "${AGENT_FILES[@]}"
# ── Validate changed instruction files ─────────────────────────
- name: Validate instruction files
if: steps.detect.outputs.instruction_count != '0'
env:
INSTRUCTION_FILES_RAW: ${{ steps.detect.outputs.instruction_files }}
run: |
INSTRUCTION_FILES=()
while IFS= read -r file; do
[ -n "$file" ] && INSTRUCTION_FILES+=("$file")
done <<< "$INSTRUCTION_FILES_RAW"
node ./eng/validate-instructions.mjs "${INSTRUCTION_FILES[@]}"
- name: Post skip notice if nothing changed
if: steps.detect.outputs.total == '0'
run: echo "No agent or instruction files changed in this PR — skipping validation."