360 Secure SkillHub
360 安全技能中心

Auto Tagger

该 Skill 通过 AI 模型分析、模式匹配、Git 历史与启发式规则加权打分,识别代码文件中的 AI 生成块,并按阈值插入 TAG-AICODE 或 TAG-AICHECK 合规标记;支持预览、差异输出、目录批处理、校验与移除标记,用于 AI 代码合规审查流程。

FloatingClouds
FloatingClouds
热度 16.87
最近更新 2026-03-19 20:39:12
分类:开发依赖:代码执行 / 读写文件 / 第三方 API / 内部调用大模型应用场景:代码审查 / 自动化脚本 / 模板

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add auto-tagger
Metadata
name
auto-tagger
description
Automatically detect and add [TAG-AICODE] or [TAG-AICHECK] annotations to AI-generated code blocks. Use when you need to identify AI-generated code in existing files and add proper compliance tags according to nl-coder-reviwer standards.

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:

  1. [TAG-AICODE] - General AI-generated code annotation

    • Format: AI GENERATED CODE START [TAG-AICODE]
    • Multiple blocks allowed per file
    • No timestamp required
  2. [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

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:

  1. Reads target file(s)
  2. Parses code structure (functions, classes, blocks)
  3. Runs all enabled detectors in parallel
  4. Collects detection results

Step 2: Confidence Scoring

For each code block:

  1. Combines detector results
  2. Calculates weighted confidence score
  3. Determines if confidence >= threshold
  4. Selects appropriate tag type

Step 3: Tag Insertion

For blocks meeting threshold:

  1. Generates proper tag format
  2. Inserts START tag before block
  3. Inserts END tag after block
  4. Preserves code structure and formatting

Step 4: Validation

After tagging:

  1. Validates tag format compliance
  2. Checks for nesting violations
  3. Verifies tag pairs match
  4. 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:

  1. Lower threshold:

    auto-tagger scan file.py --threshold 0.6
    
  2. Enable more detectors:

    detectors:
      pattern:
        enabled: true
      heuristic:
        enabled: true
    
  3. 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:

  1. Use preview mode first:

    auto-tagger scan file.py --preview
    
  2. Increase threshold:

    auto-tagger scan file.py --threshold 0.85
    
  3. Manual review with interactive mode:

    auto-tagger scan file.py --interactive
    

Performance Issues

For large codebases:

  1. Use parallel processing:

    auto-tagger batch scan src/ --jobs 4
    
  2. Limit file types:

    auto-tagger batch scan src/ --extensions py,js
    
  3. 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

Notes

  • This skill is designed to assist, not replace, human judgment
  • Always review detected blocks before applying changes
  • Use --preview or --interactive mode for critical code
  • Backup files are automatically created when using --inplace
  • Git-aware: Skips .git/ directory by default