invariant-miner
Invariant miner: scans for code signals that imply hidden invariants (array[0] without guards, division by computed values, JSON.parse assumptions, Async state-readiness patterns) and presents them to
SKILL.mdskills/quality/invariant-miner/SKILL.md
GitHubWhat this is for
Every function body relies on implicit invariants nobody wrote down: "list is never empty here", "id is always positive", "config is loaded by now". Daikon mines invariants dynamically from execution traces. This skill mines them STATICALLY from code structure: array-index without bounds check, division by computed values, JSON.parse without schema validation, async-state expectations.
Each signal the collector finds becomes a candidate invariant sentence. The LLM judges whether the assumption is guaranteed-by-construction or fragile and proposes an assertion or doc comment to make the implicit explicit.
PROTECTION RULE - never ~/.claude/
Read-only skill. Guard required if write mode added later.
## What You Must Do When Invoked
During analysis, assign a confidence level to each finding: proven (confirmed by evidence), likely (strong signal, needs review), or suspected (weak signal).
Step 1
- If
-helpis passed, print the## Usageblock below and stop.
Step 2
- Confirm
-ProjectDiris provided and the path exists.
Step 3
- Run:
scripts/assumption-scan.ps1 -ProjectDir "<path>"
Step 4
- LLM reads the JSON output. For each signal:
Step 5
- Read the
contextlines.
Step 6
- Formulate the implicit invariant as a sentence.
Step 7
- Judge:
guaranteed-by-construction/probably-holds/fragile.
Step 8
- For
fragilesignals: propose a guard (assertion) or doc comment.
Step 9
- Write
invariant-report.mdto the working directory.
Usage
/invariants # interactive
/invariants <dir> # scan project directory
/invariants -help # show usage
Returns JSON with signals[] (kind, subject, expression, context, file, line)
plus summary counts.