QE代码智能系统Skill "QECodeIntelligence"

这是一个基于知识图谱的代码智能工具,提供语义代码搜索、依赖映射和上下文感知代码理解功能,通过智能上下文检索实现高达80%的令牌减少,优化AI编程效率。关键词:代码智能、知识图谱、语义搜索、依赖分析、AI辅助开发、令牌优化、代码理解。

AI应用 0 次安装 0 次浏览 更新于 3/9/2026

name: “QE 代码智能” description: “基于知识图谱的代码理解,提供语义搜索和通过智能上下文检索实现80%令牌减少。” trust_tier: 3 validation: schema_path: schemas/output.json validator_path: scripts/validate-config.json eval_path: evals/qe-code-intelligence.yaml


QE 代码智能

目的

指导使用 v3 的代码智能能力,包括知识图谱构建、语义代码搜索、依赖映射和具有显著令牌减少的上下文感知代码理解。

激活

  • 当理解不熟悉的代码时
  • 当语义搜索代码时
  • 当分析依赖关系时
  • 当构建代码知识图谱时
  • 当减少AI操作的上下文时

快速开始

# 将代码库索引到知识图谱中
aqe kg index --source src/ --incremental

# 语义代码搜索
aqe kg search "authentication middleware" --limit 10

# 查询依赖关系
aqe kg deps --file src/services/UserService.ts --depth 3

# 获取智能上下文
aqe kg context --query "how does payment processing work"

代理工作流

// 构建知识图谱
Task("Index codebase", `
  为项目构建知识图谱:
  - 解析 src/ 中的所有 TypeScript 文件
  - 提取实体(类、函数、类型)
  - 映射关系(导入、调用、继承)
  - 生成用于语义搜索的嵌入
  存储在 AgentDB 向量数据库中。
`, "qe-knowledge-graph")

// 语义搜索
Task("Find relevant code", `
  搜索与"用户认证流程"相关的代码:
  - 使用语义相似度(不仅仅是关键词)
  - 包括相关函数和类型
  - 按相关性得分排序
  - 返回最小上下文(80%令牌减少)
`, "qe-semantic-searcher")

知识图谱操作

1. 代码库索引

await knowledgeGraph.index({
  source: 'src/**/*.ts',
  extraction: {
    entities: ['class', 'function', 'interface', 'type', 'variable'],
    relationships: ['imports', 'calls', 'extends', 'implements', 'uses'],
    metadata: ['jsdoc', 'complexity', 'lines']
  },
  embeddings: {
    model: 'code-embedding',
    dimensions: 384,
    normalize: true
  },
  incremental: true  // 仅索引更改的文件
});

2. 语义搜索

await semanticSearcher.search({
  query: 'payment processing with stripe',
  options: {
    similarity: 'cosine',
    threshold: 0.7,
    limit: 20,
    includeContext: true
  },
  filters: {
    fileTypes: ['.ts', '.tsx'],
    excludePaths: ['node_modules', 'dist']
  }
});

3. 依赖分析

await dependencyMapper.analyze({
  entry: 'src/services/OrderService.ts',
  depth: 3,
  direction: 'both',  // 导入和被导入
  output: {
    graph: true,
    metrics: {
      afferentCoupling: true,
      efferentCoupling: true,
      instability: true
    }
  }
});

令牌减少策略

// 获取减少80%令牌的上下文
const context = await codeIntelligence.getOptimizedContext({
  query: 'implement user registration',
  budget: 4000,  // 最大令牌数
  strategy: {
    relevanceRanking: true,
    summarization: true,
    codeCompression: true,
    deduplication: true
  },
  include: {
    signatures: true,
    implementations: 'relevant-only',
    comments: 'essential',
    examples: 'top-3'
  }
});

知识图谱模式

interface KnowledgeGraph {
  entities: {
    id: string;
    type: 'class' | 'function' | 'interface' | 'type' | 'file';
    name: string;
    file: string;
    line: number;
    embedding: number[];
    metadata: Record<string, any>;
  }[];
  relationships: {
    source: string;
    target: string;
    type: 'imports' | 'calls' | 'extends' | 'implements' | 'uses';
    weight: number;
  }[];
  indexes: {
    byName: Map<string, string[]>;
    byFile: Map<string, string[]>;
    byType: Map<string, string[]>;
  };
}

搜索结果

interface SearchResult {
  entity: {
    name: string;
    type: string;
    file: string;
    line: number;
  };
  relevance: number;
  snippet: string;
  context: {
    before: string[];
    after: string[];
    related: string[];
  };
  explanation: string;
}

CLI 示例

# 完全重新索引
aqe kg index --source src/ --force

# 带过滤器的搜索
aqe kg search "database connection" --type function --file "*.service.ts"

# 显示实体详情
aqe kg show --entity UserService --relations

# 导出图谱
aqe kg export --format dot --output codebase.dot

# 统计信息
aqe kg stats

协调

主要代理: qe-knowledge-graph, qe-semantic-searcher, qe-dependency-mapper 协调者: qe-code-intelligence-coordinator 相关技能: qe-test-generation, qe-defect-intelligence