--- import DocsLayout from '../../../layouts/DocsLayout.astro'; ---

Watch 模式 (Watch Mode)

允许用户在代码中添加特殊注释(如 # AI: fix this),文件保存时 AI 会自动检测并处理这些注释请求。提供无需离开编辑器就能与 AI 交互的方式。

核心功能

支持的注释格式

# AI: 请优化这个函数
# AI! 这里有 bug,请修复
# FIXME: AI 请重构这段代码
# TODO: AI 添加错误处理
// AI: 请优化这个函数
// AI! 这里有 bug,请修复
/* AI: 重构这段代码 */

设计方案

类型定义

export interface AIComment {
  content: string;
  line: number;
  column: number;
  filePath: string;
  original: string;
  type: 'request' | 'todo' | 'fixme' | 'question';
}

export interface WatchConfig {
  enabled: boolean;
  patterns: string[];
  ignorePatterns: string[];
  debounceMs: number;
  autoProcess: boolean;
  confirmBeforeEdit: boolean;
}

使用示例

// 在代码中添加注释
function calculateTotal(items: Item[]): number {
  // AI: 请优化这个函数的性能
  let total = 0;
  for (const item of items) {
    total += item.price * item.quantity;
  }
  return total;
}

配置示例

# .ai-assistant.yml
watch:
  enabled: false
  patterns: ['**/*.ts', '**/*.tsx', '**/*.py']
  ignorePatterns: ['node_modules/**', 'dist/**']
  debounceMs: 1000
  autoProcess: true
  confirmBeforeEdit: false

实现状态

优先级: 中 | 状态: 待实现