| name | okq-maintain |
| description | Find and fix OKF doc-bundle rot with okq โ dead links, orphans, stale status. Use after renames or moves, before committing doc changes, or in CI. |
| allowed-tools | Bash, Read, Edit |
Keep the bundle's graph connected and its metadata honest. okq reports the
problems; you fix them in the files. See okq-reference for the command contract.
Health checks
okq --bundle <dir> deadlinks
okq --bundle <dir> orphans
okq --bundle <dir> stats
Clean output means nothing to fix. Run all three after any rename, move, or
delete.
Audit a document against the code
The checks above catch structural rot. This catches semantic rot โ a doc that
parses and links fine but no longer matches what the code does. Do this when
auditing a doc, after a feature changes, or when a doc is suspected stale.
-
Read the doc's claims. okq get <id> (or --section for a big doc).
Pull out the concrete, checkable assertions: commands, flags, file paths, API
names, types, defaults, behavior, exit codes โ not the prose.
-
Compare each claim to the code. Find the implementation (grep/read the
relevant source, run the command, check the actual signature). For every
claim, mark it: matches, drifted (code changed), or wrong (doc was
never right). Note exactly what differs โ old value โ current value.
-
Confirm discrepancies with the user before changing anything. Present the
list: for each, say whether the doc looks stale or the code looks like the
regression, and ask which to treat as the source of truth. Don't assume the
code is always right โ a doc may capture intended behavior the code drifted
from. Decisions in committed ADRs are immutable: if one is now wrong, supersede
it with a new record rather than rewriting it (follow the bundle's convention).
-
Apply the agreed fixes to the doc; bump updated: if the bundle tracks
it. Flag any code-side issues separately for the user.
-
Check related nodes for the same problem. A change rarely sits in one doc.
Walk the graph and re-audit the neighbors:
okq neighbors <id> --depth 1
okq backlinks <id>
For each linked doc, confirm it's still consistent with the fix you just made
(a corrected flag name, a renamed concept, a reversed decision). Repeat steps
1โ4 on any that drifted. Stop when the neighborhood is consistent.
Fixing dead links
deadlinks reports each broken link with its source path:line and the target
it failed to resolve.
- Decide whether the target moved/renamed or the link is wrong.
- If the target moved, update every link to the new id โ find them with
okq backlinks <old-or-new-id> and okq search "<old name>".
- Re-run
okq deadlinks until it's clean.
Fixing orphans
An orphan has no inbound links. Either it should be linked from somewhere, or
it's genuinely stale.
- For each orphan, find where it should be referenced (
okq search for its
topic) and add a link from the relevant doc โ or a related: entry.
- If it's obsolete, mark it (
status: deprecated if the bundle uses status) or
remove it. Don't leave it dangling silently.
- Note: an index/landing doc with no inbound links can be a legitimate root โ
confirm before "fixing" it.
Status & metadata hygiene
If the bundle uses a status lifecycle (e.g. draft โ accepted โ active โ
deprecated):
okq find --where status=draft
okq find --where status=accepted
Advance or close out stragglers; update updated: dates when the bundle tracks
them. Keep tags consistent โ okq stats surfaces near-duplicate tags to merge.
CI gating
--check makes a check fail the build (exit 3) when problems exist:
okq deadlinks --check && okq orphans --check
Use it in CI or a pre-commit hook so doc rot can't land. Branch on $?, not the
text output.