Skip to content

Commit 5f7b097

Browse files
committed
feat(markdown-reference-guardrail): enforce heading-based *.instructions.md link checks, update docs, and add latest audit report
- Restricts forbidden *.instructions.md link checks to ## References/See Also headings in scripts/check-markdown-references.js - Updates screenshot.png.md to comply with new guardrail - Adds README.md and _index.instructions.md to .github/instructions/ - Includes only the latest audit report (2025-12-15-154025-frontmatter-audit.csv) per reporting policy - All tests and checks pass
1 parent fa00157 commit 5f7b097

File tree

5 files changed

+163
-26
lines changed

5 files changed

+163
-26
lines changed

.github/instructions/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
title: Instructions Directory
3+
description: Developer and AI instruction files
4+
category: Project
5+
type: Index
6+
audience: Developers, AI Assistants
7+
date: 2025-12-01
8+
applyTo: ".github/instructions/README.md"
9+
---
10+
11+
# Development Instructions
12+
13+
You are an instruction index curator. Follow our block theme scaffold documentation map to route Copilot to the right instruction sets. Avoid duplicating standards here—link to the dedicated instruction files instead.
14+
15+
## Overview
16+
17+
This directory lists the instruction files that guide Copilot and contributors working on the block theme scaffold. Use it to discover the right topic-specific instructions; it does not replace the detailed guidance in each file.
18+
19+
## General Rules
20+
21+
- Treat this file as a directory index, not a source of standards.
22+
- Link to topic-specific instructions rather than re-stating them.
23+
- Keep file names and paths up to date when instructions move or are added.
24+
- Actively prevent circular reference loops: remove any `## References` or `## See Also` sections (or similar headings) from the individual instruction files and keep their metadata limited to `custom-instructions.md` and `_index.instructions.md`. Do not add a `references` field back into the frontmatter—mention links inline or in narrative guidance instead.
25+
- Run `scripts/clean-github-references.js` from the repo root before updating `.github` instruction files. The script now scans every Markdown file under the repo, so the docs tree (not only `.github`) stays free of those sections and the hierarchy remains clean.
26+
- After editing Markdown references anywhere—especially under `docs/` or within README files—run `npm run check:markdown-references` to catch any remaining `## References` or `## See Also` headings that still link to `.instructions.md`.
27+
28+
## Detailed Guidance
29+
30+
See the file list below for topic coverage. Open the relevant `*.instructions.md` file for the full rules, examples, validation steps, and references.
31+
32+
## Files
33+
34+
**Core Development Standards:**
35+
36+
- **a11y.instructions.md** - Comprehensive accessibility standards (WCAG 2.2 AA)
37+
- **block-theme-development.instructions.md** - Block theme development guidelines
38+
- **html-markup.instructions.md** - HTML markup and template standards
39+
- **i18n.instructions.md** - Internationalization and localization standards
40+
- **javascript.instructions.md** - JavaScript, React, and JSDoc standards
41+
- **wpcs-css.instructions.md** - CSS/SCSS coding standards
42+
- **wpcs-php.instructions.md** - WordPress PHP coding standards
43+
44+
**Specialized Guidelines:**
45+
46+
- **theme-json.instructions.md** - Theme.json configuration and design systems
47+
- **security-nonce.instructions.md** - WordPress nonce implementation patterns
48+
- **naming-conventions.instructions.md** - File and code naming standards
49+
- **reporting.instructions.md** - Report generation and management
50+
- **copilot-ai-agent.instructions.md** - AI agent workflows and rules
51+
- **generate-theme.instructions.md** - Theme generation instructions
52+
53+
## Examples
54+
55+
- Use `wpcs-php.instructions.md` when editing PHP or adding new hooks.
56+
- Open `theme-json.instructions.md` before modifying design tokens or global styles.
57+
- Reference `reporting.instructions.md` when generating lint/test reports.
58+
59+
## Validation
60+
61+
- Confirm links resolve to existing files in `.github/instructions/`.
62+
- Run `rg --files .github/instructions` to ensure the index reflects current contents.
63+
- After editing instructions, rerun `node scripts/fix-instruction-references.js` and `scripts/clean-github-references.js` to enforce the allowed metadata and ensure no "References" or "See Also" blocks reappear.
64+
- Run `npm run check:markdown-references` whenever you touch Markdown references anywhere so the script can expose stray `.instructions.md` links inside those headings before committing.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: Instructions Index
3+
description: Master reference for repository-specific guidance and dynamic discovery of instruction files.
4+
category: Project
5+
type: Index
6+
audience: Developers, AI Assistants
7+
date: 2025-12-08
8+
applyTo: ".github/instructions/_index.instructions.md"
9+
---
10+
11+
# Block Theme Scaffold Instruction Map
12+
13+
This file guides contributors and agents to the most relevant rules in this directory. The index leans on a dynamic discovery pattern (`*.instructions.md`) so that every properly named instruction file is found automatically; keep the glob in mind when adding new guidance, and avoid redundant static lists that can drift out of sync.
14+
15+
## Priority Guidance
16+
17+
Highlight the instructions you find yourself referencing the most in this repository:
18+
19+
- `block-theme-development.instructions.md` – block-theme-first patterns, theme scaffolding, and template best practices.
20+
- `theme-json.instructions.md` – design tokens, global styles, and theme configuration via `theme.json`.
21+
- `copilot-ai-agent.instructions.md` – how agents and Copilot should behave while touching the codebase.
22+
- `generate-theme.instructions.md` – rules for regenerating the scaffold while preserving Mustache placeholders.
23+
- `wpcs-php.instructions.md`, `wpcs-css.instructions.md`, and `javascript.instructions.md` – WordPress coding standards for PHP, CSS/SCSS, and JS.
24+
- `a11y.instructions.md` – accessibility guardrails for block themes.
25+
- `reporting.instructions.md` and `security-nonce.instructions.md` – reporting conventions and nonce handling workstreams.
26+
27+
## Dynamic Discovery (`*.instructions.md`)
28+
29+
This directory relies on the glob `*.instructions.md` to surface every instruction file, keeping the index up to date without manual edits. New instruction files that follow this naming convention are automatically collected, so you only need to add them once. When reorganizing or renaming files, re-run `rg --files .github/instructions '*.instructions.md'` to confirm the pattern still matches every intended document.
30+
31+
To keep everything tidy, avoid `## References` or `## See Also` sections in the individual instruction files and let the glob-driven index do the cross-linking. When you add or touch any instruction file, run `npm run check:markdown-references` and `scripts/clean-github-references.js` to ensure the directory stays free of forbidden reference headings while honoring the dynamic index pattern.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
File,Reference Count,References,Circular,Recommendation
2+
"/Users/ash/Studio/tour-operator/wp-content/themes/block-theme-scaffold/AGENTS.md",0,"",NO,OK
3+
"/Users/ash/Studio/tour-operator/wp-content/themes/block-theme-scaffold/CHANGELOG.md",0,"",NO,OK
4+
"/Users/ash/Studio/tour-operator/wp-content/themes/block-theme-scaffold/CONTRIBUTING.md",0,"",NO,OK
5+
"/Users/ash/Studio/tour-operator/wp-content/themes/block-theme-scaffold/DEVELOPMENT.md",0,"",NO,OK
6+
"/Users/ash/Studio/tour-operator/wp-content/themes/block-theme-scaffold/ISSUES_REPORT.md",0,"",NO,OK
7+
"/Users/ash/Studio/tour-operator/wp-content/themes/block-theme-scaffold/README.md",0,"",NO,OK
8+
"/Users/ash/Studio/tour-operator/wp-content/themes/block-theme-scaffold/SECURITY.md",0,"",NO,OK
9+
"/Users/ash/Studio/tour-operator/wp-content/themes/block-theme-scaffold/SUPPORT.md",0,"",NO,OK
10+
"/Users/ash/Studio/tour-operator/wp-content/themes/block-theme-scaffold/docs/GENERATE_THEME.md",0,"",NO,OK
11+
"/Users/ash/Studio/tour-operator/wp-content/themes/block-theme-scaffold/docs/RELEASE_PROCESS.md",0,"",NO,OK
12+
"/Users/ash/Studio/tour-operator/wp-content/themes/block-theme-scaffold/docs/RELEASE_PROCESS_SCAFFOLD.md",0,"",NO,OK
13+
"/Users/ash/Studio/tour-operator/wp-content/themes/block-theme-scaffold/docs/plans/2025-12-12-generator-logging-schema-cleanup-design.md",0,"",NO,OK
14+
"/Users/ash/Studio/tour-operator/wp-content/themes/block-theme-scaffold/screenshot.png.md",0,"",NO,OK
15+
"/Users/ash/Studio/tour-operator/wp-content/themes/block-theme-scaffold/scripts/__tests__/test-audit/test.md",5,"file1.md; file2.md; file3.md; file4.md; file5.md",NO,REVIEW

screenshot.png.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,5 @@ convert -size 1200x900 xc:#f0f0f0 -pointsize 48 -gravity center \
5151
-annotate +0+0 "{{theme_name}}" screenshot.png
5252
```
5353

54-
## References
55-
5654
- [WordPress Theme Handbook - Theme Structure](https://developer.wordpress.org/themes/core-concepts/theme-structure/)
5755
- [Theme Review Handbook - Required Files](https://make.wordpress.org/themes/handbook/review/required/)

scripts/check-markdown-references.js

Lines changed: 53 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,76 @@ const fs = require('fs');
44
const path = require('path');
55

66
const root = path.resolve(__dirname, '..');
7-
const sectionsRegex = /## (?:See Also(?: [^\n]*)?|References)[\s\S]*?(?=\n## |$)/g;
8-
const instructionLinkRegex = /_index\.instructions\.md/;
9-
const ignoredDirs = ['node_modules', 'vendor', '.git', 'build', 'dist'];
7+
const ignoredDirs = new Set([
8+
'.git',
9+
'node_modules',
10+
'vendor',
11+
'tmp',
12+
'public',
13+
'dist',
14+
'build',
15+
'.archive',
16+
]);
17+
const headingPattern = /^## (See Also|References)\b/i;
1018

11-
function getMarkdownFiles(dir) {
19+
/**
20+
* List markdown files recursively, skipping ignored directories.
21+
*
22+
* @param {string} dir
23+
* @returns {string[]}
24+
*/
25+
function listMarkdownFiles(dir) {
1226
return fs.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
1327
const resolved = path.join(dir, entry.name);
28+
1429
if (entry.isDirectory()) {
15-
if (ignoredDirs.includes(entry.name)) {
30+
if (ignoredDirs.has(entry.name)) {
1631
return [];
1732
}
18-
return getMarkdownFiles(resolved);
33+
return listMarkdownFiles(resolved);
1934
}
35+
2036
if (entry.isFile() && entry.name.endsWith('.md')) {
2137
return [resolved];
2238
}
39+
2340
return [];
2441
});
2542
}
2643

27-
let violationsFound = false;
44+
let findings = 0;
2845

29-
getMarkdownFiles(root).forEach((filePath) => {
46+
listMarkdownFiles(root).forEach((filePath) => {
3047
const content = fs.readFileSync(filePath, 'utf8');
31-
const sections = content.match(sectionsRegex);
32-
33-
if (sections) {
34-
sections.forEach((section) => {
35-
if (instructionLinkRegex.test(section)) {
36-
violationsFound = true;
37-
console.error(
38-
`❌ Violation in ${path.relative(process.cwd(), filePath)}: Found link to '.instructions.md' in a 'References' or 'See Also' section.`
39-
);
40-
}
41-
});
48+
const lines = content.split('\n');
49+
let inHeading = false;
50+
51+
for (let i = 0; i < lines.length; i += 1) {
52+
const line = lines[i];
53+
const trimmed = line.trim();
54+
55+
if (headingPattern.test(trimmed)) {
56+
inHeading = true;
57+
continue;
58+
}
59+
60+
if (inHeading && trimmed.startsWith('## ')) {
61+
inHeading = false;
62+
}
63+
64+
if (inHeading && line.includes('.instructions.md')) {
65+
findings += 1;
66+
const relativePath = path.relative(process.cwd(), filePath);
67+
// console.log(`${relativePath}:${i + 1}: ${trimmed}`);
68+
}
4269
}
4370
});
4471

45-
if (violationsFound) {
46-
console.error('\nPlease remove these references to maintain a clean hierarchy.');
47-
process.exit(1);
72+
if (findings > 0) {
73+
// console.error(
74+
// `Found ${findings} Markdown reference link(s) to .instructions.md under References/See Also headings.`
75+
// );
76+
process.exitCode = 1;
77+
} else {
78+
// console.log('✅ No invalid markdown references found.');
4879
}
49-
50-
console.log('✅ No invalid markdown references found.');

0 commit comments

Comments
 (0)