Skip to content
| Marketplace
Sign in
Visual Studio Code>Machine Learning>AI Code DetectionNew to Visual Studio Code? Get it now.
AI Code Detection

AI Code Detection

Nie XRyu

|
2 installs
| (0) | Free
统计 AI 生成代码和用户手动输入代码的行数,帮助开发者了解 AI 工具的实际贡献
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

VSCode AI 代码检测插件

一个用于统计 AI 生成代码和用户手动输入代码行数的 VSCode 插件,帮助开发者了解 AI 工具的实际贡献。

功能特性

✅ 已实现(Phase 1)

  • 实时代码检测:监听文档变更,自动分类 AI 和用户代码
  • 内容哈希映射:通过内容 hash 追踪代码来源,抵抗格式化变化
  • 多维度检测:
    • 多行插入检测
    • 输入速度分析
    • 代码完整性分析
    • 时间特征分析
  • 智能过滤:
    • 格式化操作过滤(format-on-save、Format Document)
    • 粘贴操作检测与可配置处理(忽略/计为用户/智能检测)
  • 实时统计展示:
    • 状态栏显示 AI 采纳率
    • 命令面板查看详细统计
    • 导出 JSON 报告

🚧 待实现(后续 Phase)

  • Git Commit 集成(统计 staged diff)
  • Copilot 特定检测
  • Diff 归因迁移(高级模式)
  • WebView 统计面板
  • 数据持久化到 .git/ai-stats/
  • Husky Hook 安装

快速开始

安装依赖

pnpm install

编译插件

pnpm run compile

在 VSCode 中调试

  1. 按 F5 启动调试
  2. 在新打开的 VSCode 窗口中编写代码
  3. 观察右下角状态栏的统计信息

使用方法

查看统计信息

  • 状态栏:右下角实时显示 AI 采纳率
  • 命令面板:Ctrl+Shift+P → AI Detect: Show Statistics

生成报告

  1. 打开命令面板:Ctrl+Shift+P
  2. 运行:AI Detect: Generate Report
  3. 报告保存到:.ai-stats/report.json

重置统计

  • 命令面板 → AI Detect: Reset Statistics

配置选项

在 VSCode 设置中配置:

{
  // 启用插件
  "aiDetect.enabled": true,

  // 归因模式(当前仅支持 hash)
  "aiDetect.attributionMode": "hash",

  // 检测置信度阈值
  "aiDetect.detection.confidenceThreshold": 0.6,

  // 过滤选项
  "aiDetect.filters.formatting": true,
  "aiDetect.filters.pasteHandling": "ignore",  // 可选: "ignore", "human", "detect"

  // 存储位置
  "aiDetect.storage.location": "git",

  // 显示状态栏
  "aiDetect.ui.showStatusBar": true
}

粘贴操作处理

三种模式:

  • ignore (默认):粘贴的代码不计入统计(保守策略)
  • human:粘贴视为用户输入(操作角度统计)
  • detect:智能检测粘贴内容本身的来源(内容分析)

工作原理

核心算法

  1. 内容哈希映射:

    • 编辑时:记录每行代码的标准化 hash
    • 格式化后:通过 hash 映射找到原始归因
    • 优点:抵抗格式化、空白变化
  2. 分层检测:

    • 层 A(高置信):检测格式化、粘贴等特殊操作
    • 层 B(启发式):5 维度加权评分判断 AI/用户
  3. 多维度评分:

    最终得分 = 多行插入(30%) + 输入速度(25%) + 代码完整性(20%)
             + 光标行为(15%) + 时间特征(10%)
    

数据结构

// 每一行都有归因记录
interface LineOrigin {
  content: string;
  contentHash: string;      // 标准化后的 hash
  type: 'ai' | 'human' | 'unknown';
  confidence: number;       // 0-1
  source?: 'copilot' | 'claude-code' | ...;
}

项目结构

src/
├── types.ts                          # 类型定义
├── extension.ts                      # 插件入口
├── attribution/
│   ├── ContentHasher.ts              # 内容哈希计算
│   └── HashMapper.ts                 # 哈希映射器
├── core/
│   └── DetectionEngine.ts            # 检测引擎
├── filters/
│   ├── FormatFilter.ts               # 格式化过滤
│   └── PasteFilter.ts                # 粘贴过滤
└── utils/
    └── Logger.ts                     # 日志工具

开发路线图

  • [x] Phase 1: 核心框架(已完成)
  • [ ] Phase 2: Git 集成
  • [ ] Phase 3: 高级检测
  • [ ] Phase 4: UI 增强
  • [ ] Phase 5: 持久化

许可证

ISC

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft