Auto Tagger
Automatically detects AI-generated code blocks and adds compliant [TAG-AICODE] or [TAG-AICHECK] annotations following nl-coder-reviwer standards.
When to Use This Skill
Use this skill when:
- Analyzing existing codebases to identify AI-generated portions
- Preparing code for compliance review with nl-coder-reviwer
- Migrating legacy code to meet tagging requirements
- Batch processing multiple files for AI code audit
- Establishing AI code traceability in projects
Supported Tag Formats
The skill supports two tag formats from nl-coder-reviwer:
-
[TAG-AICODE] - General AI-generated code annotation
- Format:
AI GENERATED CODE START [TAG-AICODE] - Multiple blocks allowed per file
- No timestamp required
- Format:
-
[TAG-AICHECK] - Formal code review annotation
- Format:
AI CHECK START YYYY-MM-DD HH:MM:SS TAG-AICHECK - Single pair per file (multiple = ERROR)
- Timestamp mandatory and must match START/END
- Format:
Core Capabilities
1. AI Detection Engine
Uses multiple detection strategies in parallel:
- AI Model Analysis (primary): LLM-based code analysis with confidence scoring
- Pattern Detection: Code pattern matching for common AI characteristics
- Git History Analysis: Commit message and author analysis
- Heuristic Rules: Code complexity and formatting analysis
2. Confidence Fusion
Combines multiple detector results using weighted scoring:
- AI Model: 50% weight
- Pattern Detection: 20% weight
- Git Analysis: 15% weight
- Heuristic Rules: 15% weight
3. Smart Tagging
Automatically selects appropriate tag type:
- TAG-AICHECK: For reviewed, production-critical code
- TAG-AICODE: For general AI-generated code blocks
4. Language Support
Supports multiple programming languages with proper comment syntax:
- Python (
#) - JavaScript/TypeScript (
//) - SQL (
--) - Java (
//,/* */) - Go (
//) - And more
Quick Start
Basic Usage
# Scan single file (preview mode)
auto-tagger scan file.py --preview
# Scan single file and modify in-place
auto-tagger scan file.py --inplace
# Scan directory recursively
auto-tagger scan src/ --recursive --inplace
# Generate diff instead of modifying
auto-tagger scan file.py --diff
Configuration
Create .auto-tagger.yml in project root:
detection:
threshold: 0.7 # Confidence threshold (0.0-1.0)
min_block_size: 5 # Minimum lines for AI block
skip_test_files: true
skip_vendor: true
detectors:
ai_model:
enabled: true
model: "gpt-4"
timeout: 30
pattern:
enabled: true
git:
enabled: true
max_commits: 50
heuristic:
enabled: true
tagging:
aicode:
enabled: true
add_metadata: true
aicheck:
enabled: true
timestamp_format: "YYYY-MM-DD HH:MM:SS"
output:
format: "inplace" # inplace | preview | diff
backup: true
verbose: true
Workflow
Step 1: Analysis
When invoked with scan, the skill:
- Reads target file(s)
- Parses code structure (functions, classes, blocks)
- Runs all enabled detectors in parallel
- Collects detection results
Step 2: Confidence Scoring
For each code block:
- Combines detector results
- Calculates weighted confidence score
- Determines if
confidence >= threshold - Selects appropriate tag type
Step 3: Tag Insertion
For blocks meeting threshold:
- Generates proper tag format
- Inserts START tag before block
- Inserts END tag after block
- Preserves code structure and formatting
Step 4: Validation
After tagging:
- Validates tag format compliance
- Checks for nesting violations
- Verifies tag pairs match
- Reports any issues
Task-Based Operations
Scan Files
Detect and tag AI code in files:
# Preview changes
auto-tagger scan path/to/file.py --preview
# Apply changes with backup
auto-tagger scan path/to/file.py --inplace --backup
# Generate unified diff
auto-tagger scan path/to/file.py --diff > changes.diff
Output format:
============================================================
AI DETECTION RESULTS: file.py
============================================================
Block 1: Lines 5-15
Confidence: 0.85
Tag Type: TAG-AICODE
Reason: High-confidence AI model detection, generic variable names
📝 Proposed Tag:
AI GENERATED CODE START [TAG-AICODE]
<code block>
AI GENERATED CODE END [TAG-AICODE]
Batch Processing
Process multiple files or directories:
# Recursive directory scan
auto-tagger batch scan src/ --recursive --inplace
# Specific file types only
auto-tagger batch scan src/ --extensions py,js,ts
# Parallel processing (faster)
auto-tagger batch scan src/ --jobs 4 --inplace
Validate Existing Tags
Check existing tags for compliance:
# Validate single file
auto-tagger validate file.py
# Validate directory
auto-tagger validate src/ --recursive
# Strict mode (treat warnings as errors)
auto-tagger validate src/ --strict
Remove Tags
Remove all AI tags from files:
# Remove tags with preview
auto-tagger remove file.py --preview
# Remove tags permanently
auto-tagger remove file.py --inplace
# Remove specific tag type
auto-tagger remove file.py --tag-type aicode --inplace
Detection Strategies
AI Model Detection
Uses LLM to analyze code for AI generation patterns:
Strengths:
- Highest accuracy for complex logic
- Context-aware analysis
- Detailed reasoning
Configuration:
detectors:
ai_model:
enabled: true
model: "gpt-4" # or local model
temperature: 0.0 # Deterministic output
timeout: 30
Pattern Detection
Identifies common AI code patterns:
Detected patterns:
- Generic variable names (item1, item2, data, result)
- Standardized comment style
- Perfect code formatting
- Missing human-typical errors
- Over-optimized algorithms
- Consistent indentation
Configuration:
detectors:
pattern:
enabled: true
rules:
- generic_names
- perfect_formatting
- missing_errors
- over_optimization
Git History Analysis
Analyzes commit history for AI indicators:
Detected indicators:
- Commit keywords: "generated", "copilot", "ai", "assistant"
- Automated commit authors
- Unusual commit patterns
- Large code dumps in single commit
Configuration:
detectors:
git:
enabled: true
max_commits: 50
keywords:
- "generated"
- "copilot"
- "ai"
- "assistant"
- "gpt"
Heuristic Rules
Code quality and complexity analysis:
Rules:
- Cyclomatic complexity thresholds
- Comment-to-code ratio
- Function length analysis
- Import pattern analysis
Configuration:
detectors:
heuristic:
enabled: true
complexity_threshold: 8
max_function_length: 50
min_comment_ratio: 0.1
Tag Type Selection
The skill automatically chooses between TAG-AICODE and TAG-AICHECK based on:
TAG-AICHECK Selection Criteria
- Code is in production/backend systems
- High-availability or security-critical code
- Has been reviewed/validated
- Formal compliance required
TAG-AICODE Selection Criteria
- General AI-generated code
- Development/experimental code
- Multiple AI blocks in same file
- No formal review required
Manual Override
User can force specific tag type:
# Force AICODE
auto-tagger scan file.py --tag-type aicode
# Force AICHECK
auto-tagger scan file.py --tag-type aicheck
Advanced Features
Custom Detector Scripts
Add custom detection logic:
# scripts/custom_detector.py
from detectors.base import BaseDetector
class CustomDetector(BaseDetector):
def detect(self, code: str, context: dict) -> DetectionResult:
# Your custom logic
pass
Reference from config:
detectors:
custom:
enabled: true
script: "scripts/custom_detector.py"
weight: 0.3
Interactive Mode
Confirm each tagging decision:
auto-tagger scan file.py --interactive
# For each detected block:
# Block at lines 5-15, confidence 0.85
# Reason: High-confidence AI model detection
# Add TAG-AICODE? [y/N] y
Confidence Tuning
Adjust detection sensitivity:
# Conservative (high threshold, fewer tags)
auto-tagger scan file.py --threshold 0.85
# Aggressive (low threshold, more tags)
auto-tagger scan file.py --threshold 0.55
Output Examples
Preview Mode
$ auto-tagger scan process_data.py --preview
============================================================
AI DETECTION RESULTS: process_data.py
============================================================
Block 1: Lines 8-18
Confidence: 0.82
Tag Type: TAG-AICODE
Reason: Generic variable names, perfect formatting
--- PREVIEW ---
AI GENERATED CODE START [TAG-AICODE]
# Generated by: Auto Tagger AI Model
# Detection confidence: 0.82
# Date: 2026-02-10
def process_data(items):
result = []
for item in items:
transformed = item.upper().replace('_', ' ')
result.append(transformed)
return result
AI GENERATED CODE END [TAG-AICODE]
---
Total blocks: 1
AI code lines: 11 / 25 (44%)
Estimated accuracy: 82%
Apply changes? [y/N]
Diff Mode
$ auto-tagger scan process_data.py --diff
diff --git a/process_data.py b/process_data.py
index abc123..def456 100644
--- a/process_data.py
+++ b/process_data.py
@@ -5,0 +5,12 @@
+AI GENERATED CODE START [TAG-AICODE]
+# Generated by: Auto Tagger AI Model
+# Detection confidence: 0.82
+# Date: 2026-02-10
def process_data(items):
result = []
for item in items:
transformed = item.upper().replace('_', ' ')
result.append(transformed)
return result
+AI GENERATED CODE END [TAG-AICODE]
Troubleshooting
Low Confidence Scores
If tags aren't being added:
-
Lower threshold:
auto-tagger scan file.py --threshold 0.6 -
Enable more detectors:
detectors: pattern: enabled: true heuristic: enabled: true -
Check AI model access:
- Verify API key is configured
- Check network connectivity
- Try with alternative model
False Positives
If human code is tagged as AI:
-
Use preview mode first:
auto-tagger scan file.py --preview -
Increase threshold:
auto-tagger scan file.py --threshold 0.85 -
Manual review with interactive mode:
auto-tagger scan file.py --interactive
Performance Issues
For large codebases:
-
Use parallel processing:
auto-tagger batch scan src/ --jobs 4 -
Limit file types:
auto-tagger batch scan src/ --extensions py,js -
Disable heavy detectors:
detectors: ai_model: enabled: false # Skip LLM analysis pattern: enabled: true
Integration with nl-coder-reviwer
After tagging, validate with nl-coder-reviwer:
# Tag code with auto-tagger
auto-tagger scan src/ --recursive --inplace
# Validate tags
cd /path/to/nl-coder-reviwer
python3 nlcr.py validate ../src/ --directory --recursive
References
- Tag Standards: See tag_standards.md for complete tag format specifications
- Detection Patterns: See detection_patterns.md for detection algorithm details
- Usage Guide: See usage_guide.md for comprehensive usage examples
Notes
- This skill is designed to assist, not replace, human judgment
- Always review detected blocks before applying changes
- Use
--previewor--interactivemode for critical code - Backup files are automatically created when using
--inplace - Git-aware: Skips
.git/directory by default
