This directory contains automated validation scripts to ensure the Copilot custom instruction files stay synchronized with the codebase.
The easiest way to check and fix the custom instructions is using the Copilot slash command:
/fix-instructions
This will:
- Run both sync check scripts
- Identify all desyncs between code and custom instructions
- Automatically fix the issues in both instruction files
- Verify the fixes by re-running the checks
- Show you a summary of changes
The command is configured in .github/prompts/fix-instructions.prompt.md.
Validates .github/copilot-instructions.md (full internal guide) against the codebase.
Usage:
./scripts/check-copilot-instructions-sync.shWhat it checks:
- ✅ All hooks mentioned in custom instructions exist in code
- ✅ All hooks in code are documented in custom instructions
- ✅ Core components (
Map,Mount,With) are documented - ✅ All packages exist
- ✅ Import paths are correct
Exit codes:
0- All checks passed1- Custom instructions drift detected
Validates .github/copilot-instructions-public-api.md (public API reference) against the codebase.
Usage:
./scripts/check-public-api-instructions-sync.shWhat it checks:
- ✅ All documented hooks exist in the codebase
- ✅ All public hooks from
core/src/hooks/index.tsare documented - ✅ Core components are properly documented
- ✅ Package imports are correct
- ✅ Critical concepts explained (NO_VALUE, dual dependencies)
- ✅ Equality checks are documented
- ✅ No internal/private APIs leaked to public instructions
- ✅ Testing utilities not featured (they're internal)
- ✅ Examples use correct imports
Exit codes:
0- All checks passed1- Custom instructions drift detected
When these scripts search for Markdown code fences like typescript the shell can accidentally interpret backticks (``) as command substitution if the pattern is double-quoted. The scripts therefore use single-quoted grep patterns (for example: grep -q 'typescript') to avoid this class of errors. If you modify the scripts, keep that in mind to prevent runtime failures.
Add both scripts to your continuous integration workflow to catch custom instructions drift automatically:
# .github/workflows/ci.yml
name: CI
on: [push, pull_request]
jobs:
instructions-validation:
name: Validate Copilot Custom Instructions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check Full Instructions Sync
run: ./scripts/check-copilot-instructions-sync.sh
- name: Check Public API Instructions Sync
run: ./scripts/check-public-api-instructions-sync.shRun these scripts whenever you:
- Add/remove/modify public APIs (hooks, components, utilities)
- Update package structure
- Change import paths
- Add new best practices or patterns
Always run both scripts as part of your release checklist:
# Quick check both instruction files
./scripts/check-copilot-instructions-sync.sh && \
./scripts/check-public-api-instructions-sync.sh && \
echo "✅ All custom instructions are in sync!"Configure GitHub Actions to run these checks on every PR to prevent custom instructions drift from being merged.
When a script reports errors, you can either use the /fix-instructions slash command or follow these manual steps:
/fix-instructions
Copilot will automatically fix all desyncs and update both instruction files.
The script output shows exactly what's missing or incorrect:
⚠️ Hook 'useFacetNewFeature' exists in code but not documented in public API docs
- For new public APIs: Add full documentation with examples
- For removed APIs: Remove all references
- For changed APIs: Update signatures and examples
In both instruction files, update the maintenance section:
> **Last Updated**: DD Month YYYY./scripts/check-public-api-instructions-sync.shInclude custom instructions updates in the same commit/PR as code changes when possible.
When the project structure changes:
- New package added: Update package check lists in both scripts
- New export added: Ensure it's checked against documentation
- Critical concept added: Add to the "critical concepts" check
The public API script is intentionally stricter than the full instructions script:
- Full script: Checks everything (including internal details)
- Public API script: Only checks user-facing APIs + enforces no private API leakage
When updating one script, consider if the other needs similar changes.
chmod +x ./scripts/check-copilot-instructions-sync.sh
chmod +x ./scripts/check-public-api-instructions-sync.shIf a hook legitimately shouldn't be in public instructions (e.g., it's internal), ensure:
- It's not exported from
packages/@react-facet/core/src/hooks/index.ts - Or, update the script's exclusion logic
Both scripts use set -e to fail fast. If a command fails unexpectedly, check:
- File paths are correct
- grep patterns are accurate
- The repository structure hasn't changed significantly
.github/copilot-instructions.md- Full internal guide for contributors/Copilot.github/copilot-instructions-public-api.md- Public API reference for users.github/prompts/fix-instructions.prompt.md- Slash command configurationdocs/- User-facing documentation site (separate from custom instructions)
These scripts embody the principle: Custom instructions should be treated as code. Just like tests verify code correctness, these scripts verify custom instructions accuracy.
By automating custom instructions validation, we:
- ✅ Prevent stale custom instructions
- ✅ Catch missing documentation early
- ✅ Ensure consistency between code and custom instructions
- ✅ Make custom instructions a first-class citizen in the development process