mx-generate
Skill2 starsChanged 4 months agoMITView on GitHub
MutantX Phase 2 — Generate realistic code mutants as unified diff patches.
In this repository12 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- mutateSkill
- mx-detectSkill
- mx-generateSkill
- mx-reportSkill
- mx-testSkill
- mx-validateSkill
- mutateSkill
- mx-detectSkill
- mx-reportSkill
- mx-testSkill
- mx-validateSkill
The file
We split this skill into the rules it gives an agent
12 rules. About 0 are common, 5 are distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 27
Read .mutants/detect.json for project configuration (language, test command, source files).
- Very specific: line 31
Look for .mutants/manifest.json in the project root.
- Very specific: line 33
If .mutants/manifest.json does not exist or regen is "true", proceed with full generation.
- Very specific: line 35
If the manifest exists AND regen is not "true", do a per-file staleness check:
- Very specific: line 37
Read the manifest. It contains a file_hashes map of { "path": "<sha256>" } for every source file that was mutated.
- Distinctive: line 87
Configuration constants: only used at startup.
- Distinctive: line 88
Dead code: never reached by any execution path.
- Distinctive: line 92
Before finalizing a mutant, verify:
- Distinctive: line 99
Create or update the following directory structure:
- Very specific: line 130
Verify each patch applies cleanly: git apply --check .mutants/patches/NNN.patch.
- Distinctive: line 165
After saving all patches and the manifest, report to the user how many mutants were generated and in which files.
- Very specific: line 169
After creating the .mutants/ directory, check if .mutants/ is in .gitignore.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
MutantX — Phase 2: Mutant Generation
You are the mutant generation phase of a mutation testing engine. Your job is to read source files and generate realistic code mutations as unified diff patches.
Key principle: You are NOT an AST-based tool applying blind syntactic transformations. You understand the code semantically. Generate mutations that represent realistic bugs a developer might actually introduce — off-by-one errors, wrong operator choices, forgotten edge cases, swapped arguments, missing null checks. Avoid trivial or equivalent mutations.
Input
Read .mutants/detect.json for project configuration (language, test command, source files). If the file doesn't exist and files is not provided, tell the user to run /mx-detect first.
Check for Cached Mutants
Look for .mutants/manifest.json in the project root.
If .mutants/manifest.json does not exist or regen is "true", proceed with full generation.
If the manifest exists AND regen is not "true", do a per-file staleness check:
- Read the manifest. It contains a
file_hashesmap of{ "path": "<sha256>" }for every source file that was mutated. - For each source file in scope, compute its current content hash:
sha256sum <file> | cut -d' ' -f1. - Compare against the stored hash:
- Hash matches → the file hasn't changed. Keep its existing mutants and skip regeneration for this file.
- Hash differs → the file has changed. Delete its old patches, remove its mutants from the manifest, and regenerate mutants for this file.
- File is new (not in
file_hashes) → generate mutants for it. - File was deleted (in
file_hashesbut no longer exists) → remove its mutants and patches.
- Also run
git apply --checkon each kept patch to verify it still applies cleanly. If a patch no longer applies, discard that mutant and regenerate.
Report the cache status to the user:
Cached: 8 mutants for 3 unchanged files
Regenerating: 2 files changed (src/billing.ts, src/auth.ts)
New: 1 file added (src/payments.ts)
Removed: 1 file deleted (src/legacy.ts)Generating Mutants
For each source file, read the full file and generate up to count (default 5) mutants. Each mutant must:
- Change exactly ONE thing (single fault).
- Be syntactically valid (the code must still compile/parse).
- Be semantically different from the original (NOT an equivalent mutant).
- Represent a realistic bug.
Mutation Categories
Apply a MIX of these categories across the file. Don't generate all mutants from the same category.
| Category | Description | Example |
| Arithmetic Operator | Change + to -, * to /, etc. | total = a + b → total = a - b |
| Relational Boundary | Off-by-one in comparisons | i < len → i <= len or i < len - 1 |
| Logical Operator | Swap &&/||, flip boolean logic | a && b → a || b |
| Negated Conditional | Invert a condition | if (x > 0) → if (x <= 0) |
| Return Value | Change what a function returns | return result → return null / return [] / return 0 |
| Removed Call | Remove a function call (especially side effects) | list.sort() → (removed) |
| Constant Mutation | Change numeric/string constants | timeout = 30 → timeout = 0 |
| Argument Swap | Swap arguments of similar type | range(start, end) → range(end, start) |
| Exception/Error Handling | Remove or weaken error handling | Remove a catch block body, or change the exception type |
| Collection Operation | Change collection method | .filter(...) → .map(...) or .find(...) |
| Early Return | Add or remove an early return | Insert return before main logic, or remove a guard clause |
| Null/Undefined Injection | Return or assign null/nil/None/undefined | getUser() → null |
What NOT to Mutate
- Type declarations, interfaces, or type annotations — compile-time only.
- Import/export statements — cause parse/compile errors, not behavioral bugs.
- Comments or documentation.
- Logging or debug statements — unless they affect control flow.
- Configuration constants only used at startup.
- Dead code never reached by any execution path.
Quality Checks
Before finalizing a mutant, verify:
- Not equivalent: Does this mutation actually change observable behavior?
- Not trivially caught: Will this cause a compile/type error rather than a behavioral change?
- Testable: Is there a plausible test that COULD catch this? If the mutated code is never exercised by any test, note this but still include it (it reveals a coverage gap).
Saving Mutants
Create or update the following directory structure:
.mutants/
├── manifest.json
└── patches/
├── 001.patch
├── 002.patch
└── ...Patch Files
Each patch file is a unified diff that can be applied with git apply:
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -40,7 +40,7 @@
function calculateTotal(items: Item[]): number {
let total = 0;
for (const item of items) {
- total += item.price * item.quantity;
+ total += item.price + item.quantity;
}
return total;
}Produce the unified diff directly. Use correct line numbers and 3 lines of context above and below the change.
Verify each patch applies cleanly: git apply --check .mutants/patches/NNN.patch. If it doesn't apply cleanly, fix the patch.
Manifest File
Write .mutants/manifest.json:
{
"version": 1,
"generated_at": "<ISO 8601 timestamp>",
"config": {
"language": "<detected language>",
"test_command": "<test command>",
"source_patterns": ["<glob patterns used>"],
"count_per_file": 5
},
"file_hashes": {
"src/utils.ts": "<sha256 of file content at generation time>",
"src/billing.ts": "<sha256>"
},
"mutants": [
{
"id": "001",
"file": "src/utils.ts",
"line": 42,
"category": "arithmetic_operator",
"description": "Changed * to + in price calculation within calculateTotal",
"patch_file": "patches/001.patch",
"status": "pending"
}
],
"summary": null
}After saving all patches and the manifest, report to the user how many mutants were generated and in which files.
.gitignore
After creating the .mutants/ directory, check if .mutants/ is in .gitignore. If not, ask the user whether they want to add it.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

