Master skill for developing, testing, and auditing CogniCode quality rules. Covers SonarQube-derived best practices, tree-sitter AST analysis, regex safety, test strategies (unit/integration/false-positive), self-improvement loops via dashboard feedback, and full ecosystem integration (axiom → quality → dashboard). Trigger: When creating, modifying, testing, or auditing CogniCode detection rules, fixing false positives, migrating regex to tree-sitter, or working with cognicode-axiom, cognicode-quality, rule catalogs, or dashboard issue reports.
Installation
Installer avec Codex ou Claude Copiez ce prompt, collez-le dans Codex, Claude ou un autre assistant, puis laissez-le vérifier la page du skill et l'installer pour vous.
Master skill for developing, testing, and auditing CogniCode quality rules. Covers SonarQube-derived best practices, tree-sitter AST analysis, regex safety, test strategies (unit/integration/false-positive), self-improvement loops via dashboard feedback, and full ecosystem integration (axiom → quality → dashboard). Trigger: When creating, modifying, testing, or auditing CogniCode detection rules, fixing false positives, migrating regex to tree-sitter, or working with cognicode-axiom, cognicode-quality, rule catalogs, or dashboard issue reports.
When a false positive is detected via dashboard or user report:
1. Identify the FP pattern
curl http://dashboard/api/issues?rule_id=SXXXX
2. Read the rule source
grep -A30 'id: "SXXXX"' crates/cognicode-axiom/src/rules/catalog.rs
3. Apply the fix
A. Add word boundaries (\b) to regex patterns
B. Add comment/string skipping logic
C. Migrate to tree-sitter query if structural
4. Add FP regression test
#[test] fn test_SXXXX_no_fp_{description}() { ... }
5. Run tests
cargo test -p cognicode-axiom --lib SXXXX
6. Verify on dashboard
curl -X POST http://dashboard/api/analysis -d '{...}' | jq '.issues'
→ Confirm the FP no longer appears
7. Commit with traceability
git commit -m "fix(axiom): SXXXX — {what was fixed} (reported via dashboard)"
// Instead of iterating source lines, use tree-sitter queriesletquery = tree_sitter::Query::new(
&ctx.language.to_ts_language(),
r#"(call_expression
function: (identifier) @func
arguments: (arguments (string) @arg))"#
)?;
// Only matches actual code, never comments or strings
┌─────────┐
│ E2E │ ← analyze real project via dashboard
├─────────┤
│Integration│ ← multi-file, multi-rule, call graph
├───────────┤
│ Rule Unit │ ← single rule, multiple test cases
├─────────────┤
│ FP Guard │ ← MANDATORY: test DOES NOT trigger
└─────────────┘
Required Test Cases Per Rule
Test Type
Minimum
Description
Detection
2+
At least 2 positive cases (different variants)
False Positive
3+
Comment, variable name, and string literal
Edge Case
1+
Boundary condition (empty file, single char)
Rule Properties
1
id(), name(), severity(), category(), language()
Common Anti-Patterns
❌ Scanning raw lines without comment filtering
// 100+ rules do this — causes FP on documentationforlinein ctx.source.lines() { ... }
Fix: r"(?:\b|_)des\b" (word boundary before/underscore, word boundary after)
❌ No false positive tests
Fix: Add 3 FP test categories (see Test Templates)
❌ Using regex when tree-sitter would be better
Fix: Use tree-sitter queries for structural patterns (SQL injection, nesting, unused vars)
❌ No self-improvement feedback loop
Fix: Monitor dashboard for user-reported FPs, fix + add regression test in same commit
Rule Development Checklist
Before submitting a rule PR:
Approach: Is regex or tree-sitter the right tool?
Regex safety: Word boundaries (\b), prefix handling ((?:\b|_))
Comment skip: Does the rule skip //, ///, //!, /* comments?
String skip: Does the rule skip string literals?
Detection tests: 2+ positive cases
FP tests: Comment, variable name, string literal
Edge case test: Empty input, boundary
Properties test: id, name, severity, category
No hardcoded paths: Use ctx.file_path, not absolute paths
Remediation message: Clear, actionable guidance
Dashboard verified: Check that issue appears correctly in dashboard
Self-improvement trace: FP fix includes dashboard issue reference
Dashboard Integration Commands
# Register project in dashboard
curl -X POST http://localhost:3000/api/projects/register \
-H "Content-Type: application/json" \
-d '{"name":"CogniCode","path":"/home/rubentxu/Proyectos/rust/CogniCode"}'# Run analysis and check issues
curl -X POST http://localhost:3000/api/analysis \
-H "Content-Type: application/json" \
-d '{"project_path":"/home/rubentxu/Proyectos/rust/CogniCode","quick":true}'# Check specific rule issues in dashboard
curl -X POST http://localhost:3000/api/issues \
-H "Content-Type: application/json" \
-d '{"project_path":"/home/rubentxu/Proyectos/rust/CogniCode","rule_id":"SXXXX"}'# Verify FP is fixed (should return 0 issues)
curl -s ... | jq '.issues | length'
Development Commands
# Run all tests for a specific rule
cargo test -p cognicode-axiom --lib SXXXX
# Run all rule tests
cargo test -p cognicode-axiom --lib
# Run with output to debug FP issues
cargo test -p cognicode-axiom --lib SXXXX -- --nocapture
# Full quality analysis (test your rule on real code)
cargo run -p cognicode-quality -- analyze /path/to/project
# Check what rules fire on a specific file
cargo test -p cognicode-axiom --lib SXXXX -- --nocapture 2>&1 | grep "assert"
- ALWAYS use word boundaries in regex: (?:\b|_)des\b not just "des"
- ALWAYS skip comment lines in line-scanning rules (//, ///, //!, #, /*)
- ALWAYS add 3+ false positive tests per rule (comment, identifier, English word)
- RuleContext has tree_sitter::Tree available — use queries instead of regex for structural patterns
- Dashboard is the feedback loop: monitor issues, fix FPs, add regression tests
- Self-improvement: FP report → fix rule → add test → verify on dashboard → commit
- Tree-sitter queries match actual code nodes, never comments or strings
- 854 rules exist; only 11 have tests; prioritize security/vulnerability rules for testing
- Use ctx.graph (CallGraph) and ctx.metrics (FileMetrics) for semantic analysis
- cognicode-quality handler: analyze_project_impl() → RuleContext → rule.check() → Issue → SQLite → Dashboard