name: code-maintainer description: Fix bugs, optimize performance, and maintain code quality in CClean-Killer. Use when asked to fix detection issues, false positives, false negatives, optimize scan speed, improve performance, refactor code, or do quick maintenance tasks like version bumps or linting. allowed-tools: Read, Grep, Glob, Bash, Edit, Write
Code Maintainer
Fix bugs, optimize performance, and maintain code quality in the CClean-Killer codebase.
Purpose
Handle day-to-day development tasks:
- Fix detection issues (false positives/negatives)
- Optimize script performance
- Quick maintenance tasks
Modes
Mode: fix
Debug and fix detection issues including false positives and false negatives.
When to use: User says "fix detection", "false positive", "false negative", "not detecting", "wrongly detecting"
Workflow:
-
Diagnose Phase
- Identify the specific issue (FP or FN)
- Run detection with verbose output:
./scripts/macos/find-parasites.sh --verbose 2>&1 | grep -i "[pattern]" ./scripts/macos/find-orphans.sh --verbose 2>&1 | grep -i "[pattern]" - Check pattern matching logic in script
-
Trace Phase
- Read the detection function in
scripts/macos/find-parasites.sh - Check
is_known_parasite()function - Verify bundle ID extraction from plist
- Check skip patterns in
scripts/macos/lib/common.sh
- Read the detection function in
-
Fix Phase
- For false positive: Add to skip patterns or refine match
- For false negative: Add/fix pattern in KNOWN_PARASITES array
- Update
knowledge/parasite-fingerprints.jsonif needed
-
Verify Phase
- Run tests:
npm run test:unit - Verify fix works on real data
- Run tests:
Files Modified:
scripts/macos/find-parasites.shscripts/macos/find-orphans.shscripts/macos/lib/common.sh(SKIP_PATTERNS)knowledge/parasite-fingerprints.jsontests/unit/test-parasite-patterns.sh
Common Issues:
| Issue | Location | Fix |
|---|---|---|
| Pattern too broad | KNOWN_PARASITES array | Make pattern more specific |
| Pattern too narrow | KNOWN_PARASITES array | Use broader glob pattern |
| Wrong bundle ID extraction | get_bundle_id_from_plist() | Fix plist parsing |
| App check failing | app_exists_for_agent() | Fix mdfind or /Applications check |
| Safe item flagged | SKIP_PATTERNS | Add to skip list |
Mode: optimize
Improve performance of scanning and detection scripts.
When to use: User says "optimize", "slow scan", "improve performance", "speed up", "benchmark"
Workflow:
-
Profile Phase
- Run benchmark:
time ./scripts/macos/scan.sh --dry-run time ./scripts/macos/find-parasites.sh --dry-run - Identify slow operations
- Run benchmark:
-
Analyze Phase
- Check for:
- Repeated file system operations
- Inefficient loops
- Missing caching
- Sequential operations that could be parallel
- Reference
scripts/macos/lib/optimized-patterns.shfor existing optimizations
- Check for:
-
Implement Phase
- Apply optimization techniques:
# Cache app list instead of repeated mdfind declare -A APP_CACHE # Use find with -prune for skipping find "$dir" -name ".git" -prune -o -type f -print # Parallel processing find ... | xargs -P 4 ...
- Apply optimization techniques:
-
Benchmark Phase
- Compare before/after:
./scripts/benchmark.sh --compare - Document improvement in
docs/OPTIMIZATION-REPORT.md
- Compare before/after:
Files Modified:
scripts/macos/*.shscripts/macos/lib/common.shscripts/macos/lib/optimized-patterns.shdocs/OPTIMIZATION-REPORT.md
Optimization Techniques:
| Technique | When to Use | Example |
|---|---|---|
| Associative arrays | Repeated lookups | declare -A cache |
| Find with -prune | Skip directories | -name ".git" -prune |
| Parallel xargs | Independent operations | xargs -P 4 |
| Early termination | First match sufficient | return after match |
| Caching | Expensive repeated calls | Cache mdfind results |
Mode: maintain
Quick maintenance tasks: version bumps, linting, syncing, cleanup.
When to use: User says "bump version", "lint", "sync json", "cleanup", "maintenance"
Quick Tasks:
-
Version Bump
# Update version in package.json npm version patch # or minor/major -
Lint Scripts
# Check shell scripts shellcheck scripts/macos/*.sh scripts/macos/lib/*.sh -
Sync JSON Database
- Ensure
parasite-fingerprints.jsonmatchescommon-parasites.md - Update
totalParasitescount - Update
lastUpdateddate
- Ensure
-
Validate Configs
# Check JSON syntax jq . knowledge/parasite-fingerprints.json > /dev/null # Check all scripts are executable find scripts -name "*.sh" ! -executable -
Clean Temp Files
rm -f scripts/**/*.bak rm -f **/*.tmp
Files Modified:
package.json(version)knowledge/parasite-fingerprints.json(metadata)- Various (linting fixes)
Safety Rules
- ALWAYS run tests after fixes
- NEVER remove safety checks during optimization
- PRESERVE backward compatibility in function signatures
- VERIFY optimizations don't change output
- DOCUMENT non-obvious optimizations with comments
Debugging Commands
# Verbose detection output
./scripts/macos/find-parasites.sh --verbose
# Dry run (no changes)
./scripts/macos/clean.sh --dry-run --all
# JSON output for parsing
./scripts/macos/scan.sh --json | jq .
# Test specific pattern
grep -r "com.example" knowledge/
# Check if pattern matches
[[ "com.google.keystone.agent" == com.google.* ]] && echo "matches"
Examples
Example 1: Fix false positive
User: "Google Chrome is being flagged as a parasite but it's installed"
1. Check detection: ./scripts/macos/find-parasites.sh --verbose | grep google
2. Find: com.google.keystone.agent flagged as zombie
3. Trace: app_exists_for_agent() not finding Chrome.app
4. Fix: Update app detection to check "Google Chrome.app"
5. Verify: Run detection again, no longer flagged
Example 2: Optimize slow scan
User: "Scanning takes 30 seconds, can we speed it up?"
1. Profile: time ./scripts/macos/scan.sh shows 25s in du calls
2. Analyze: Repeated du on same directories
3. Implement: Cache directory sizes in associative array
4. Benchmark: New time is 8 seconds
5. Document in OPTIMIZATION-REPORT.md
Related Skills
- knowledge-manager: For adding new parasites after fixing detection
- quality-assurance: For adding regression tests after fixes