code-intelligence

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Code Intelligence Skill

Code Intelligence 技能

Advanced codebase analysis and search tools inspired by hybrid memory systems. This skill enables the agent to understand code relationships, search semantically, and analyze the impact of changes.
受混合内存系统启发的高级代码库分析与搜索工具。该技能使Agent能够理解代码关系、进行语义搜索并分析变更的影响。

Setup

设置

bash
cd /job/.pi/skills/code-intelligence
npm install
bash
cd /job/.pi/skills/code-intelligence
npm install

Tools

工具

Index Codebase

索引代码库

Build a searchable index of the codebase:
bash
node index.js --scan /path/to/project
This creates:
  • Symbol table (functions, classes, exports)
  • Import/dependency graph
  • File metadata index
构建代码库的可搜索索引:
bash
node index.js --scan /path/to/project
这将生成:
  • 符号表(函数、类、导出项)
  • 导入/依赖图谱
  • 文件元数据索引

Semantic Search

语义搜索

Search for code by meaning, not just text:
bash
undefined
按含义搜索代码,而非仅按文本:
bash
undefined

Find code related to authentication

Find code related to authentication

node search.js "authentication middleware"
node search.js "authentication middleware"

Find where database connections are established

Find where database connections are established

node search.js "database connection setup"
node search.js "database connection setup"

Search with filters

Search with filters

node search.js "user validation" --type function --ext js,ts
undefined
node search.js "user validation" --type function --ext js,ts
undefined

Relationship Analysis

关系分析

Understand code dependencies:
bash
undefined
理解代码依赖:
bash
undefined

What depends on this file?

What depends on this file?

node deps.js --dependents src/utils/api.js
node deps.js --dependents src/utils/api.js

What does this file import?

What does this file import?

node deps.js --imports src/utils/api.js
node deps.js --imports src/utils/api.js

Show full dependency chain

Show full dependency chain

node deps.js --chain src/app.js
undefined
node deps.js --chain src/app.js
undefined

Impact Analysis

影响分析

Predict what might break with changes:
bash
undefined
预测变更可能导致的问题:
bash
undefined

Analyze impact of modifying a function

Analyze impact of modifying a function

node impact.js src/utils/auth.js --function verifyToken
node impact.js src/utils/auth.js --function verifyToken

Check impact of file changes

Check impact of file changes

node impact.js src/config/database.js
undefined
node impact.js src/config/database.js
undefined

Code Q&A

代码问答

Ask questions about the codebase:
bash
node ask.js "Where is the JWT secret configured?"
node ask.js "How does error handling work in this project?"
node ask.js "What functions use the database connection?"
针对代码库提问:
bash
node ask.js "Where is the JWT secret configured?"
node ask.js "How does error handling work in this project?"
node ask.js "What functions use the database connection?"

Architecture

架构

The skill uses a layered approach:
  1. Parser Layer: Tree-sitter for AST parsing
  2. Index Layer: SQLite for fast lookups + JSON for graph data
  3. Search Layer: Hybrid keyword + semantic matching
  4. Analysis Layer: Graph algorithms for relationship mapping
该技能采用分层架构:
  1. 解析层:使用Tree-sitter进行AST解析
  2. 索引层:SQLite用于快速查询 + JSON用于图谱数据
  3. 搜索层:混合关键词+语义匹配
  4. 分析层:图谱算法用于关系映射

Output Format

输出格式

All tools output JSON for programmatic use or formatted text for readability:
bash
undefined
所有工具均输出JSON供程序化使用,或输出格式化文本以提升可读性:
bash
undefined

JSON output (for piping to other tools)

JSON output (for piping to other tools)

node search.js "auth" --json
node search.js "auth" --json

Formatted text (default)

Formatted text (default)

node search.js "auth"
undefined
node search.js "auth"
undefined

When to Use

使用场景

  • Understanding large or unfamiliar codebases
  • Finding all usages of a function or variable
  • Assessing risk before making changes
  • Discovering patterns across the codebase
  • Answering "where is X?" questions
  • Code review preparation
  • Refactoring planning
  • 理解大型或陌生的代码库
  • 查找函数或变量的所有用法
  • 在变更前评估风险
  • 发现代码库中的模式
  • 解答“X在哪里?”这类问题
  • 代码审查准备
  • 重构规划

Requirements

要求

  • Node.js ≥18
  • Tree-sitter parsers for supported languages (auto-installed)
  • Node.js ≥18
  • 支持语言对应的Tree-sitter解析器(自动安装)

Supported Languages

支持的语言

  • JavaScript/TypeScript
  • Python
  • Rust
  • Go
  • Java
  • Ruby
  • And more via tree-sitter
  • JavaScript/TypeScript
  • Python
  • Rust
  • Go
  • Java
  • Ruby
  • 更多语言可通过tree-sitter扩展

Data Storage

数据存储

Index files are stored in
.code-intelligence/
:
  • index.db
    - SQLite database
  • graph.json
    - Dependency graph
  • cache/
    - Parsed AST cache
Add
.code-intelligence/
to your
.gitignore
.
索引文件存储在
.code-intelligence/
目录下:
  • index.db
    - SQLite数据库
  • graph.json
    - 依赖图谱
  • cache/
    - 已解析的AST缓存
.code-intelligence/
添加到你的
.gitignore
中。