Documentation maintenance
A periodic skill that audits the documentation knowledge base, detects gaps and drift, validates correctness against the codebase, and opens PRs to incrementally close issues. Designed to be run repeatedly — each invocation checks previous PR outcomes to calibrate effort, uses a complexity budget to address the highest-priority findings, and tracks structural issues in a persistent backlog across runs.
For the architectural rationale behind this skill's design — including the materialized view concept, the distinction between code-coupled facts and human intent, and the prioritization philosophy — see intent.md.
Hard constraints
These constraints are absolute and override any other instructions:
- NEVER modify source code files. This skill may only create or edit markdown (
.md, .mdc) and text files. No .ts, .tsx, .js, .jsx, .json, .css, or any other code files — ever. This applies to all sub-agents invoked by this skill.
- Before opening a PR, verify this constraint. Run
git diff --name-only and confirm every changed file ends in .md or .mdc. If any source file appears, abort and report the violation.
- Ignore
docs/design/ entirely. Design documents are maintained by humans using the design-review skill. They are not documentation and are not in scope.
- Do not rewrite documentation from scratch. This skill makes targeted, incremental edits. If a doc needs major restructuring, recommend it for separate work with a rationale — do not attempt it in this run.
- Run
npm run prettier before committing. The CI build chain requires formatted files.
- NEVER commit or push directly to main. All changes must be on a feature branch submitted as a PR.
Duplication governance principle
The documentation has two tiers with distinct roles:
.cursor/rules/ files: Compact, prescriptive agent constraints. What agents must do or must not do when working in a domain. These are loaded into agent context.
docs/developer/ files: Comprehensive reference documentation. How things work in detail, with examples and explanations. These are for deep dives.
When both tiers cover the same topic, the rule file should include a "For full reference, see docs/developer/..." link. Neither should duplicate the other's content verbatim. When drift is detected, the resolution is: check the codebase to determine which version is correct, update the incorrect version, then ensure the cross-reference link exists in both directions.
Design rationale in docs
Some docs/developer/ files contain design rationale — ## Key Design Decisions, ### Why X? subsections, or inline explanations of tradeoffs. This rationale is valuable context for agents making implementation decisions.
The maintain-docs skill treats design rationale as opportunistic, not systematic:
- When validating a doc for staleness, check whether existing rationale sections are still accurate against the code. Fix factual errors in rationale the same way you fix factual errors in any other section.
- When extracting rationale from code comments or design docs during a staleness fix, it is acceptable to add a brief
## Design notes section summarizing what was found — but only when there is substantial, citable content to extract. Every claim must cite its source (e.g., (from code comment in X) or (from design doc Y)).
- Never create stub sections with TODO placeholders. A doc with no design rationale section is better than a doc with an empty template prompting humans to fill it in. Those stubs become permanent debt.
- Never fabricate rationale. If the code and design docs don't contain clear rationale signals, leave the doc as-is. The absence of documented rationale is information, not a gap to be filled with guesses.
Maintenance backlog
The file docs/_maintenance-backlog.md is the skill's persistent memory across runs. It has three sections:
- Work items — structural recommendations and deferred issues that cannot be resolved through incremental edits (e.g., "rule file is too long and should be split," "two docs should be merged").
- Validated docs — a record of which docs were checked against their source code and found accurate, with the date of validation. This prevents the skill from re-checking docs that haven't meaningfully changed since last validation.
- Exclusions — files that have been reviewed and confirmed as not needing an AGENTS.md entry. These are filtered out of orphan detection so the skill stops flagging them.
Rules for the backlog file:
- If the file does not exist, create it on the first run with the template below.
- Read it at the start of Phase 0 to incorporate carry-forward items, validated timestamps, and exclusions.
- Write to it at the end of Phase 3 — add new structural recommendations, remove resolved items, update validated timestamps, and add new exclusions.
- Each work item has a date, a brief description, and a rationale. Keep entries concise.
- Each validated entry has a doc path and a date. Update the date when a doc is re-validated.
- Each exclusion has a doc path and a brief reason why it does not need indexing.
- If a backlog work item has been present for 3+ runs without progress and is not blocked by external factors, consider closing it with a brief note explaining why it was dropped.
Backlog file template:
# Documentation maintenance backlog
Persistent tracker for the maintain-docs skill's persistent state across runs.
## Work items
<!-- Structural issues requiring dedicated effort. Format: date, description, rationale. Remove when resolved. -->
## Validated docs
<!-- Docs checked against source and found accurate. Format: date, doc path. Update date on re-validation. -->
## Exclusions
<!-- Files confirmed as not needing an AGENTS.md entry. Format: path, reason. -->
Workflow
Phase 0: Feedback check
Goal: Determine whether previous skill runs produced value, and calibrate this run accordingly.
- Read
docs/_maintenance-backlog.md if it exists. Load work items, validated doc timestamps, and exclusions into memory for use in later phases.
- Check the outcome of recent PRs from this skill:
gh pr list --state all --label documentation --search "skill:maintain-docs" --limit 5 --json number,state,mergedAt,closedAt,title
- Classify each recent PR:
- Merged: The skill's work was accepted. Normal operation.
- Closed without merge: The skill's work was rejected. This is a signal to reduce scope or change approach.
- Open for >7 days: The PR is creating review burden. Likely too large or too marginal to prioritize.
- Apply calibration rules:
- If the last 2+ PRs were closed without merge, report the pattern to the user and exit without making changes. The skill's output is not aligned with team needs and requires human guidance.
- If the last PR is still open after 7+ days, reduce the complexity budget for this run to 4 points (from 7). Smaller PRs are easier to review.
- If recent PRs were merged promptly, proceed normally.
Phase 1: Lightweight audit
Goal: Build a prioritized list of documentation issues without reading every file in full.
Step 1: Parse the discovery graph
- Read
AGENTS.md
- Extract all file references from:
- The "On-demand context" table
- Inline links and references throughout the file
- The "PR reviews" section
- Any other tables or lists that reference documentation files
- This produces the indexed set — files reachable from the agent entry point
Step 2: Discover all documentation files
- Glob
docs/**/*.md excluding docs/design/**. Note: docs/sources/ contains plugin documentation published to Grafana.com for external human readers. Index and maintain these like any other docs, but be aware their audience is end users, not agents — they are high-level and functionality-oriented.
- Glob
.cursor/rules/*
- Glob
.cursor/skills/**/SKILL.md
- This produces the full set
Step 3: Classify findings
For each file in the full set, assign one status:
- Indexed: File is in the indexed set. Candidate for staleness check.
- Orphaned: File exists but has no path from AGENTS.md. Candidate for indexing.
- Missing: Referenced in AGENTS.md but file does not exist. Broken link, candidate for cleanup.
For each orphaned file:
- Check the exclusions list from the backlog. If the file is listed there, skip it — it has been reviewed and confirmed as not needing indexing.
- For files not excluded, read only the first ~30 lines to classify its task domain and estimate its value. Do NOT read full file contents in this phase — context budget matters.
For each indexed file:
- Check whether a corresponding file exists in the other tier (
.cursor/rules/ ↔ docs/developer/). If a pair exists, flag it as a drift check candidate.
- Staleness check: Infer which source directories the doc describes from its content path or AGENTS.md glob triggers (e.g.,
docs/developer/engines/context-engine.md describes src/context-engine/). Then apply a two-stage filter:
- Validated recently? Check the backlog's "Validated docs" section. If this doc was validated within the last 30 days, skip the staleness check entirely — it was recently confirmed accurate.
- Structural changes? For docs not recently validated, check the source directory for structural changes since the doc's last modification: new or deleted files (
git diff --name-status --diff-filter=ADR between the doc's last commit and HEAD), or renamed exports. Cosmetic changes (formatting, typo fixes, test-only changes) are not meaningful staleness signals. Use git log --stat or git diff --stat to gauge change magnitude. Only flag the doc as a staleness candidate if structural changes are detected.
Step 4: Score findings
| Priority |
Criteria |
| HIGH |
Operational doc with no discovery path that constrains a common agent task (releases, feature flags, interactive authoring, CLI tools) |
| HIGH |
.cursor/rules/ ↔ docs/developer/ pair with suspected drift (both cover the same topic) |
| HIGH |
Missing referenced file — broken link in AGENTS.md |
| HIGH |
Indexed doc with structural source changes (new/deleted/renamed files) in a high-traffic domain |
| HIGH |
Backlog work item older than 3 runs that has not been addressed |
| MEDIUM |
Indexed doc with structural source changes in a lower-traffic domain |
| MEDIUM |
Engine or subsystem doc that helps agents working on specific code areas (orphaned) |
| MEDIUM |
Recent backlog work item (carried forward from last 1-2 runs) |
| LOW |
Supplementary docs (known issues, scale testing) that agents rarely need (orphaned) |
| LOW |
README files for stable, rarely-changed areas (orphaned) |
Steady-state behavior
If the audit finds no orphaned docs (after applying exclusions), no staleness candidates (after checking validated timestamps and filtering for structural changes), no drift pairs, and the backlog work items section is empty — do nothing. Report that everything is clean and exit without creating a branch or PR.
If the only actionable items are in the backlog (no new findings from the filesystem audit), use the complexity budget to burn down backlog work items. The backlog is not just a record — it is a work queue. Structural issues that were too large for previous runs should be attempted when they are the highest-priority remaining work.
Branch setup (before making any changes)
Before making any edits, prepare the working branch:
- Run
git checkout main && git pull origin main to ensure you have the latest main.
- Create and switch to a new branch:
git checkout -b docs/maintain-docs-YYYY-MM-DD-<2 unique chars>
All Phase 2 edits happen on this branch. Never edit files while on main.
Phase 2: Scoped fixes
Select findings from the top of the scored list, using a complexity budget rather than a flat item count:
| Fix type |
Cost |
Examples |
| Light |
1 point |
Add an index entry to AGENTS.md, add a cross-reference link, fix a stale file path, add an exclusion entry |
| Heavy |
3 points |
Drift correction between rule/doc pair, new rule file creation, staleness validation with factual corrections |
Budget per run: 7 points (reduced to 4 if Phase 0 detects review burden). This allows up to 7 light fixes, or 2 heavy fixes + 1 light fix, or similar combinations. When related docs share a domain (e.g., all files under docs/developer/engines/), group them as a single finding.
For each selected finding, delegate to a sub-agent with a tightly scoped task description.
CRITICAL: Every sub-agent invocation must include this instruction: "You may ONLY modify .md and .mdc files. No source code changes are permitted under any circumstances."
Fix type: Orphaned doc needs indexing
Sub-agent task:
- Read the orphaned doc in full
- Decide whether indexing is appropriate. Not every doc belongs in AGENTS.md. Component READMEs, local utility docs, and end-user-facing docs in
docs/sources/ may serve their purpose without agent indexing. If the doc does not constrain agent behavior or provide context agents need for implementation tasks, add it to the backlog's Exclusions section with a brief reason and move on. This is a light fix (1 point).
- If indexing is appropriate, read any related
.cursor/rules/ file if one exists for the same domain
- Validate key claims against the codebase:
- Do referenced file paths still exist?
- Do mentioned npm scripts exist in
package.json?
- Do described APIs, functions, or components exist in the source?
- Fix factual errors found in the doc (stale file paths, renamed scripts, changed API names)
- Propose the AGENTS.md table entry: file path, "when to load" description, and glob trigger if appropriate
- If a
.cursor/rules/ counterpart exists for the same domain, add cross-reference links in both directions
Fix type: Rule/doc drift
Sub-agent task:
- Read both the
.cursor/rules/ file and its docs/developer/ counterpart
- Identify claims that differ between them
- For each difference, check the codebase to determine which version is correct
- Update the incorrect version to match the code
- Ensure the rule file contains a "For full reference, see
docs/developer/..." pointer
- Keep the rule file compact and prescriptive; keep the doc comprehensive and explanatory
Fix type: Staleness validation
For an indexed doc flagged as stale (structural source changes detected):
Sub-agent task:
- Read the flagged doc in full
- Identify the source directories it describes (from path conventions or AGENTS.md glob triggers)
- Focus on the structural changes detected in Phase 1 (new/deleted/renamed files) and compare against claims in the doc:
- File paths and directory structures mentioned
- Function, class, and component names referenced
- npm scripts and CLI commands documented
- Configuration values, constants, and default behaviors described
- Architecture descriptions and data flow claims
- Fix all factual errors found (stale paths, renamed symbols, changed defaults, outdated descriptions)
- If the doc also contains design rationale sections, verify those claims are still accurate against the code. Fix factual errors. If substantial rationale exists in code comments or design docs that isn't captured, it is acceptable to add a brief
## Design notes section — but only with citable, real content (see "Design rationale in docs" above).
- If corrections are extensive enough that the doc's overall structure no longer holds, do not attempt a rewrite — add it to the maintenance backlog as a work item instead
- Record validation: After fixing or confirming the doc is accurate, update the backlog's "Validated docs" section with today's date and the doc path. This prevents the same doc from being re-checked next run unless new structural changes occur.
This is a heavy fix (3 points). Prioritize staleness validation for docs that constrain common agent tasks (feature flags, interactive authoring, engines) over docs for rarely-touched areas.
Fix type: New rule file needed
For a complex domain that has a docs/developer/ reference but no .cursor/rules/ constraint file:
- Read the reference doc and the relevant source code to verify accuracy
- Draft a compact
.cursor/rules/ file with prescriptive constraints only — not a copy of the reference doc
- Include a "For full reference, see
docs/developer/..." pointer
- Add appropriate frontmatter (
alwaysApply: false, description, and glob triggers if applicable)
- Propose an AGENTS.md table entry for the new rule
Fix type: Structural recommendation only
If an issue is too large for incremental editing (e.g., a doc needs a complete rewrite, or multiple docs should be merged):
- Do NOT attempt the restructuring
- Add the item to
docs/_maintenance-backlog.md with the current date and a brief rationale
- Include this in the PR description under "Recommendations for separate work"
Phase 2.5: Verification
After all sub-agents have completed their work, review the combined diff before proceeding to PR creation.
- Run
git diff and read the full output.
- For each changed file, verify:
- The change makes a factual claim → spot-check that claim against the code. If a sub-agent changed "function
foo" to "function bar", confirm bar actually exists.
- The change doesn't introduce contradictions with other parts of the same doc or with other changed files.
- The change doesn't remove content that was correct (sub-agents may over-correct).
- If a sub-agent's change looks wrong or dubious, revert that file (
git checkout -- <file>) rather than trying to fix it. A skipped fix is better than an incorrect one.
- If all sub-agent changes are reverted, exit cleanly without creating a PR. Report what was attempted and why it was reverted.
Phase 3: PR creation
Update the maintenance backlog
- Add any new work items discovered in this run to the "Work items" section with today's date.
- Remove any work items that were resolved by this PR's changes.
- Update the "Validated docs" section — add or update entries for docs that were validated in this run (even if no corrections were needed).
- Add any new exclusions identified during orphan processing.
- If the file does not exist yet, create it using the template from the "Maintenance backlog" section above.
- Review the work items list: if any item has been present for 3+ consecutive runs (compare dates) and hasn't been attempted, either attempt it in this run (if budget allows) or add a note explaining why it's blocked.
Safety checks
- Run
git diff --name-only and verify every changed file ends in .md or .mdc. If any other file type appears, stop immediately and report the problem. Do not proceed.
- Run
npm run prettier to format all markdown files per CI rules.
- Run
git diff --name-only again after prettier. Prettier should only touch markdown files. If it modified anything else, abort and report.
Commit and PR
You should already be on the docs/maintain-docs-* branch created before Phase 2.
- Verify you are NOT on main: run
git branch --show-current and confirm it starts with docs/maintain-docs-. If you are on main, stop immediately.
- Stage and commit all changes.
- Push the branch and open a PR with the label
documentation and using the template below.
PR conventions
- Title prefix: Always start the PR title with
skill:maintain-docs so humans can identify skill-generated PRs. Example: skill:maintain-docs index orphaned operational docs in AGENTS.md
- Label: Always add the
documentation label to the PR (e.g., gh pr create --label documentation ...)
PR template
Use this structure for the PR body:
## Summary
Documentation maintenance run — [DATE].
### Changes made
- [Brief description of each change]
### Full audit findings
| Priority | Finding | Status |
| -------- | ------- | ------ |
| HIGH | [description] | Fixed in this PR |
| HIGH | [description] | Deferred |
| MEDIUM | [description] | Deferred |
| LOW | [description] | Deferred |
### Recommendations for separate work
- [Any structural recommendations that need a dedicated effort]
### Validation checklist
- [ ] All changed files are `.md` or `.mdc` (verified via `git diff --name-only`)
- [ ] Phase 2.5 verification passed (sub-agent output reviewed)
- [ ] `npm run prettier` passed
- [ ] No source code files were modified
Context window management
This skill is designed to stay within context limits:
- Phase 0 reads the backlog file and runs one
gh command — minimal context
- Phase 1 reads only AGENTS.md, file listings, and first ~30 lines of orphaned docs (after exclusion filtering)
- Phase 2 delegates deep reads to sub-agents, each scoped to one doc plus its related code
- Phase 2.5 reads the combined
git diff for verification — proportional to the number of fixes attempted
- Phase 3 is mechanical (backlog update, git operations, prettier, PR creation)
- Each run is bounded by a 7-point complexity budget (or 4 points under review burden), not a flat item count
Expected invocation patterns
- Post-feature work: Run after a large feature lands to catch docs that fell behind. This is the highest-value trigger.
- Periodic maintenance: Run on a schedule (weekly or biweekly) to catch gradual drift.
- On demand: User asks "audit the docs" or "check if documentation is up to date."
Adaptive frequency
The skill self-regulates through several mechanisms:
- Phase 0 feedback check halts the skill entirely if recent PRs were rejected, preventing wasted effort.
- Validated doc timestamps prevent re-checking docs that were recently confirmed accurate, so repeated runs on an unchanged codebase converge to no-ops.
- Exclusion list permanently silences false-positive orphan detections.
- Structural change filtering in staleness detection ignores cosmetic commits, reducing noise.
- Steady-state exit skips PR creation when no actionable findings exist.
If the skill produces no-op runs for 3+ consecutive invocations, consider reducing frequency to biweekly or trigger-based only. The skill works best when run in response to actual codebase changes, not on a fixed calendar.
1---2name: maintain-docs3description: Periodic documentation maintenance audit. Finds orphaned docs, detects drift between .cursor/rules/ and docs/developer/, validates doc correctness against source code, tracks structural issues in a persistent backlog, and opens PRs to close highest-priority gaps per run. Use when the user asks to audit documentation, sync docs, or maintain the knowledge base.4---56# Documentation maintenance78A periodic skill that audits the documentation knowledge base, detects gaps and drift, validates correctness against the codebase, and opens PRs to incrementally close issues. Designed to be run repeatedly — each invocation checks previous PR outcomes to calibrate effort, uses a complexity budget to address the highest-priority findings, and tracks structural issues in a persistent backlog across runs.910For the architectural rationale behind this skill's design — including the materialized view concept, the distinction between code-coupled facts and human intent, and the prioritization philosophy — see [`intent.md`](intent.md).1112## Hard constraints1314These constraints are absolute and override any other instructions:15161. **NEVER modify source code files.** This skill may only create or edit markdown (`.md`, `.mdc`) and text files. No `.ts`, `.tsx`, `.js`, `.jsx`, `.json`, `.css`, or any other code files — ever. This applies to all sub-agents invoked by this skill.172. **Before opening a PR, verify this constraint.** Run `git diff --name-only` and confirm every changed file ends in `.md` or `.mdc`. If any source file appears, abort and report the violation.183. **Ignore `docs/design/`** entirely. Design documents are maintained by humans using the design-review skill. They are not documentation and are not in scope.194. **Do not rewrite documentation from scratch.** This skill makes targeted, incremental edits. If a doc needs major restructuring, recommend it for separate work with a rationale — do not attempt it in this run.205. **Run `npm run prettier` before committing.** The CI build chain requires formatted files.216. **NEVER commit or push directly to main.** All changes must be on a feature branch submitted as a PR.2223## Duplication governance principle2425The documentation has two tiers with distinct roles:2627- **`.cursor/rules/` files**: Compact, prescriptive agent constraints. What agents **must do** or **must not do** when working in a domain. These are loaded into agent context.28- **`docs/developer/` files**: Comprehensive reference documentation. How things work in detail, with examples and explanations. These are for deep dives.2930When both tiers cover the same topic, the rule file should include a "For full reference, see `docs/developer/...`" link. Neither should duplicate the other's content verbatim. When drift is detected, the resolution is: check the codebase to determine which version is correct, update the incorrect version, then ensure the cross-reference link exists in both directions.3132### Design rationale in docs3334Some `docs/developer/` files contain design rationale — `## Key Design Decisions`, `### Why X?` subsections, or inline explanations of tradeoffs. This rationale is valuable context for agents making implementation decisions.3536The maintain-docs skill treats design rationale as **opportunistic, not systematic**:3738- When validating a doc for staleness, check whether existing rationale sections are still accurate against the code. Fix factual errors in rationale the same way you fix factual errors in any other section.39- When extracting rationale from code comments or design docs during a staleness fix, it is acceptable to add a brief `## Design notes` section summarizing what was found — but only when there is substantial, citable content to extract. Every claim must cite its source (e.g., `(from code comment in X)` or `(from design doc Y)`).40- **Never create stub sections with TODO placeholders.** A doc with no design rationale section is better than a doc with an empty template prompting humans to fill it in. Those stubs become permanent debt.41- **Never fabricate rationale.** If the code and design docs don't contain clear rationale signals, leave the doc as-is. The absence of documented rationale is information, not a gap to be filled with guesses.4243## Maintenance backlog4445The file `docs/_maintenance-backlog.md` is the skill's persistent memory across runs. It has three sections:46471. **Work items** — structural recommendations and deferred issues that cannot be resolved through incremental edits (e.g., "rule file is too long and should be split," "two docs should be merged").482. **Validated docs** — a record of which docs were checked against their source code and found accurate, with the date of validation. This prevents the skill from re-checking docs that haven't meaningfully changed since last validation.493. **Exclusions** — files that have been reviewed and confirmed as not needing an AGENTS.md entry. These are filtered out of orphan detection so the skill stops flagging them.5051**Rules for the backlog file**:5253- If the file does not exist, create it on the first run with the template below.54- Read it at the start of Phase 0 to incorporate carry-forward items, validated timestamps, and exclusions.55- Write to it at the end of Phase 3 — add new structural recommendations, remove resolved items, update validated timestamps, and add new exclusions.56- Each work item has a date, a brief description, and a rationale. Keep entries concise.57- Each validated entry has a doc path and a date. Update the date when a doc is re-validated.58- Each exclusion has a doc path and a brief reason why it does not need indexing.59- If a backlog work item has been present for 3+ runs without progress and is not blocked by external factors, consider closing it with a brief note explaining why it was dropped.6061**Backlog file template**:6263```markdown64# Documentation maintenance backlog6566Persistent tracker for the maintain-docs skill's persistent state across runs.6768## Work items6970<!-- Structural issues requiring dedicated effort. Format: date, description, rationale. Remove when resolved. -->7172## Validated docs7374<!-- Docs checked against source and found accurate. Format: date, doc path. Update date on re-validation. -->7576## Exclusions7778<!-- Files confirmed as not needing an AGENTS.md entry. Format: path, reason. -->79```8081## Workflow8283### Phase 0: Feedback check8485Goal: Determine whether previous skill runs produced value, and calibrate this run accordingly.86871. Read `docs/_maintenance-backlog.md` if it exists. Load work items, validated doc timestamps, and exclusions into memory for use in later phases.882. Check the outcome of recent PRs from this skill:89 ```90 gh pr list --state all --label documentation --search "skill:maintain-docs" --limit 5 --json number,state,mergedAt,closedAt,title91 ```923. Classify each recent PR:93 - **Merged**: The skill's work was accepted. Normal operation.94 - **Closed without merge**: The skill's work was rejected. This is a signal to reduce scope or change approach.95 - **Open for >7 days**: The PR is creating review burden. Likely too large or too marginal to prioritize.964. Apply calibration rules:97 - If the **last 2+ PRs were closed without merge**, report the pattern to the user and **exit without making changes**. The skill's output is not aligned with team needs and requires human guidance.98 - If the **last PR is still open after 7+ days**, reduce the complexity budget for this run to **4 points** (from 7). Smaller PRs are easier to review.99 - If recent PRs were merged promptly, proceed normally.100101### Phase 1: Lightweight audit102103Goal: Build a prioritized list of documentation issues without reading every file in full.104105#### Step 1: Parse the discovery graph1061071. Read `AGENTS.md`1082. Extract all file references from:109 - The "On-demand context" table110 - Inline links and references throughout the file111 - The "PR reviews" section112 - Any other tables or lists that reference documentation files1133. This produces the **indexed set** — files reachable from the agent entry point114115#### Step 2: Discover all documentation files1161171. Glob `docs/**/*.md` excluding `docs/design/**`. Note: `docs/sources/` contains plugin documentation published to Grafana.com for external human readers. Index and maintain these like any other docs, but be aware their audience is end users, not agents — they are high-level and functionality-oriented.1182. Glob `.cursor/rules/*`1193. Glob `.cursor/skills/**/SKILL.md`1204. This produces the **full set**121122#### Step 3: Classify findings123124For each file in the full set, assign one status:125126- **Indexed**: File is in the indexed set. Candidate for staleness check.127- **Orphaned**: File exists but has no path from AGENTS.md. Candidate for indexing.128- **Missing**: Referenced in AGENTS.md but file does not exist. Broken link, candidate for cleanup.129130For each **orphaned** file:131132- Check the **exclusions list** from the backlog. If the file is listed there, skip it — it has been reviewed and confirmed as not needing indexing.133- For files not excluded, read only the first ~30 lines to classify its task domain and estimate its value. Do NOT read full file contents in this phase — context budget matters.134135For each **indexed** file:136137- Check whether a corresponding file exists in the other tier (`.cursor/rules/` ↔ `docs/developer/`). If a pair exists, flag it as a drift check candidate.138- **Staleness check**: Infer which source directories the doc describes from its content path or AGENTS.md glob triggers (e.g., `docs/developer/engines/context-engine.md` describes `src/context-engine/`). Then apply a two-stage filter:139 1. **Validated recently?** Check the backlog's "Validated docs" section. If this doc was validated within the last 30 days, skip the staleness check entirely — it was recently confirmed accurate.140 2. **Structural changes?** For docs not recently validated, check the source directory for _structural_ changes since the doc's last modification: new or deleted files (`git diff --name-status --diff-filter=ADR` between the doc's last commit and HEAD), or renamed exports. Cosmetic changes (formatting, typo fixes, test-only changes) are not meaningful staleness signals. Use `git log --stat` or `git diff --stat` to gauge change magnitude. Only flag the doc as a staleness candidate if structural changes are detected.141142#### Step 4: Score findings143144| Priority | Criteria |145| ---------- | -------------------------------------------------------------------------------------------------------------------------------------- |146| **HIGH** | Operational doc with no discovery path that constrains a common agent task (releases, feature flags, interactive authoring, CLI tools) |147| **HIGH** | `.cursor/rules/` ↔ `docs/developer/` pair with suspected drift (both cover the same topic) |148| **HIGH** | Missing referenced file — broken link in AGENTS.md |149| **HIGH** | Indexed doc with structural source changes (new/deleted/renamed files) in a high-traffic domain |150| **HIGH** | Backlog work item older than 3 runs that has not been addressed |151| **MEDIUM** | Indexed doc with structural source changes in a lower-traffic domain |152| **MEDIUM** | Engine or subsystem doc that helps agents working on specific code areas (orphaned) |153| **MEDIUM** | Recent backlog work item (carried forward from last 1-2 runs) |154| **LOW** | Supplementary docs (known issues, scale testing) that agents rarely need (orphaned) |155| **LOW** | README files for stable, rarely-changed areas (orphaned) |156157#### Steady-state behavior158159If the audit finds no orphaned docs (after applying exclusions), no staleness candidates (after checking validated timestamps and filtering for structural changes), no drift pairs, and the backlog work items section is empty — **do nothing**. Report that everything is clean and exit without creating a branch or PR.160161If the only actionable items are in the backlog (no new findings from the filesystem audit), use the complexity budget to burn down backlog work items. The backlog is not just a record — it is a work queue. Structural issues that were too large for previous runs should be attempted when they are the highest-priority remaining work.162163### Branch setup (before making any changes)164165Before making any edits, prepare the working branch:1661671. Run `git checkout main && git pull origin main` to ensure you have the latest main.1682. Create and switch to a new branch: `git checkout -b docs/maintain-docs-YYYY-MM-DD-<2 unique chars>`169170All Phase 2 edits happen on this branch. Never edit files while on main.171172### Phase 2: Scoped fixes173174Select findings from the top of the scored list, using a **complexity budget** rather than a flat item count:175176| Fix type | Cost | Examples |177| --------- | -------- | ------------------------------------------------------------------------------------------------------------- |178| **Light** | 1 point | Add an index entry to AGENTS.md, add a cross-reference link, fix a stale file path, add an exclusion entry |179| **Heavy** | 3 points | Drift correction between rule/doc pair, new rule file creation, staleness validation with factual corrections |180181**Budget per run: 7 points** (reduced to 4 if Phase 0 detects review burden). This allows up to 7 light fixes, or 2 heavy fixes + 1 light fix, or similar combinations. When related docs share a domain (e.g., all files under `docs/developer/engines/`), group them as a single finding.182183For each selected finding, delegate to a sub-agent with a tightly scoped task description.184185**CRITICAL**: Every sub-agent invocation must include this instruction: "You may ONLY modify `.md` and `.mdc` files. No source code changes are permitted under any circumstances."186187#### Fix type: Orphaned doc needs indexing188189Sub-agent task:1901911. Read the orphaned doc in full1922. **Decide whether indexing is appropriate.** Not every doc belongs in AGENTS.md. Component READMEs, local utility docs, and end-user-facing docs in `docs/sources/` may serve their purpose without agent indexing. If the doc does not constrain agent behavior or provide context agents need for implementation tasks, add it to the backlog's **Exclusions** section with a brief reason and move on. This is a **light fix** (1 point).1933. If indexing is appropriate, read any related `.cursor/rules/` file if one exists for the same domain1944. Validate key claims against the codebase:195 - Do referenced file paths still exist?196 - Do mentioned npm scripts exist in `package.json`?197 - Do described APIs, functions, or components exist in the source?1985. Fix factual errors found in the doc (stale file paths, renamed scripts, changed API names)1996. Propose the AGENTS.md table entry: file path, "when to load" description, and glob trigger if appropriate2007. If a `.cursor/rules/` counterpart exists for the same domain, add cross-reference links in both directions201202#### Fix type: Rule/doc drift203204Sub-agent task:2052061. Read both the `.cursor/rules/` file and its `docs/developer/` counterpart2072. Identify claims that differ between them2083. For each difference, check the codebase to determine which version is correct2094. Update the incorrect version to match the code2105. Ensure the rule file contains a "For full reference, see `docs/developer/...`" pointer2116. Keep the rule file compact and prescriptive; keep the doc comprehensive and explanatory212213#### Fix type: Staleness validation214215For an indexed doc flagged as stale (structural source changes detected):216217Sub-agent task:2182191. Read the flagged doc in full2202. Identify the source directories it describes (from path conventions or AGENTS.md glob triggers)2213. Focus on the structural changes detected in Phase 1 (new/deleted/renamed files) and compare against claims in the doc:222 - File paths and directory structures mentioned223 - Function, class, and component names referenced224 - npm scripts and CLI commands documented225 - Configuration values, constants, and default behaviors described226 - Architecture descriptions and data flow claims2274. Fix all factual errors found (stale paths, renamed symbols, changed defaults, outdated descriptions)2285. If the doc also contains design rationale sections, verify those claims are still accurate against the code. Fix factual errors. If substantial rationale exists in code comments or design docs that isn't captured, it is acceptable to add a brief `## Design notes` section — but only with citable, real content (see "Design rationale in docs" above).2296. If corrections are extensive enough that the doc's overall structure no longer holds, do not attempt a rewrite — add it to the maintenance backlog as a work item instead2307. **Record validation**: After fixing or confirming the doc is accurate, update the backlog's "Validated docs" section with today's date and the doc path. This prevents the same doc from being re-checked next run unless new structural changes occur.231232This is a **heavy fix** (3 points). Prioritize staleness validation for docs that constrain common agent tasks (feature flags, interactive authoring, engines) over docs for rarely-touched areas.233234#### Fix type: New rule file needed235236For a complex domain that has a `docs/developer/` reference but no `.cursor/rules/` constraint file:2372381. Read the reference doc and the relevant source code to verify accuracy2392. Draft a compact `.cursor/rules/` file with prescriptive constraints only — not a copy of the reference doc2403. Include a "For full reference, see `docs/developer/...`" pointer2414. Add appropriate frontmatter (`alwaysApply: false`, `description`, and glob triggers if applicable)2425. Propose an AGENTS.md table entry for the new rule243244#### Fix type: Structural recommendation only245246If an issue is too large for incremental editing (e.g., a doc needs a complete rewrite, or multiple docs should be merged):2472481. Do NOT attempt the restructuring2492. Add the item to `docs/_maintenance-backlog.md` with the current date and a brief rationale2503. Include this in the PR description under "Recommendations for separate work"251252### Phase 2.5: Verification253254After all sub-agents have completed their work, review the combined diff before proceeding to PR creation.2552561. Run `git diff` and read the full output.2572. For each changed file, verify:258 - The change makes a factual claim → spot-check that claim against the code. If a sub-agent changed "function `foo`" to "function `bar`", confirm `bar` actually exists.259 - The change doesn't introduce contradictions with other parts of the same doc or with other changed files.260 - The change doesn't remove content that was correct (sub-agents may over-correct).2613. If a sub-agent's change looks wrong or dubious, **revert that file** (`git checkout -- <file>`) rather than trying to fix it. A skipped fix is better than an incorrect one.2624. If all sub-agent changes are reverted, exit cleanly without creating a PR. Report what was attempted and why it was reverted.263264### Phase 3: PR creation265266#### Update the maintenance backlog2672681. Add any new work items discovered in this run to the "Work items" section with today's date.2692. Remove any work items that were resolved by this PR's changes.2703. Update the "Validated docs" section — add or update entries for docs that were validated in this run (even if no corrections were needed).2714. Add any new exclusions identified during orphan processing.2725. If the file does not exist yet, create it using the template from the "Maintenance backlog" section above.2736. Review the work items list: if any item has been present for 3+ consecutive runs (compare dates) and hasn't been attempted, either attempt it in this run (if budget allows) or add a note explaining why it's blocked.274275#### Safety checks2762771. Run `git diff --name-only` and verify **every** changed file ends in `.md` or `.mdc`. If any other file type appears, **stop immediately** and report the problem. Do not proceed.2782. Run `npm run prettier` to format all markdown files per CI rules.2793. Run `git diff --name-only` again after prettier. Prettier should only touch markdown files. If it modified anything else, abort and report.280281#### Commit and PR282283You should already be on the `docs/maintain-docs-*` branch created before Phase 2.2842851. Verify you are NOT on main: run `git branch --show-current` and confirm it starts with `docs/maintain-docs-`. If you are on main, **stop immediately**.2862. Stage and commit all changes.2873. Push the branch and open a PR with the label `documentation` and using the template below.288289#### PR conventions290291- **Title prefix**: Always start the PR title with `skill:maintain-docs` so humans can identify skill-generated PRs. Example: `skill:maintain-docs index orphaned operational docs in AGENTS.md`292- **Label**: Always add the `documentation` label to the PR (e.g., `gh pr create --label documentation ...`)293294#### PR template295296Use this structure for the PR body:297298```299## Summary300301Documentation maintenance run — [DATE].302303### Changes made304305- [Brief description of each change]306307### Full audit findings308309| Priority | Finding | Status |310| -------- | ------- | ------ |311| HIGH | [description] | Fixed in this PR |312| HIGH | [description] | Deferred |313| MEDIUM | [description] | Deferred |314| LOW | [description] | Deferred |315316### Recommendations for separate work317318- [Any structural recommendations that need a dedicated effort]319320### Validation checklist321322- [ ] All changed files are `.md` or `.mdc` (verified via `git diff --name-only`)323- [ ] Phase 2.5 verification passed (sub-agent output reviewed)324- [ ] `npm run prettier` passed325- [ ] No source code files were modified326```327328## Context window management329330This skill is designed to stay within context limits:331332- **Phase 0** reads the backlog file and runs one `gh` command — minimal context333- **Phase 1** reads only AGENTS.md, file listings, and first ~30 lines of orphaned docs (after exclusion filtering)334- **Phase 2** delegates deep reads to sub-agents, each scoped to one doc plus its related code335- **Phase 2.5** reads the combined `git diff` for verification — proportional to the number of fixes attempted336- **Phase 3** is mechanical (backlog update, git operations, prettier, PR creation)337- Each run is bounded by a 7-point complexity budget (or 4 points under review burden), not a flat item count338339## Expected invocation patterns340341- **Post-feature work**: Run after a large feature lands to catch docs that fell behind. This is the highest-value trigger.342- **Periodic maintenance**: Run on a schedule (weekly or biweekly) to catch gradual drift.343- **On demand**: User asks "audit the docs" or "check if documentation is up to date."344345### Adaptive frequency346347The skill self-regulates through several mechanisms:348349- **Phase 0 feedback check** halts the skill entirely if recent PRs were rejected, preventing wasted effort.350- **Validated doc timestamps** prevent re-checking docs that were recently confirmed accurate, so repeated runs on an unchanged codebase converge to no-ops.351- **Exclusion list** permanently silences false-positive orphan detections.352- **Structural change filtering** in staleness detection ignores cosmetic commits, reducing noise.353- **Steady-state exit** skips PR creation when no actionable findings exist.354355If the skill produces no-op runs for 3+ consecutive invocations, consider reducing frequency to biweekly or trigger-based only. The skill works best when run in response to actual codebase changes, not on a fixed calendar.