跳到主要内容

分析 API

用于代码分析和 AI 驱动洞察的端点。

语义搜索

使用自然语言搜索代码。

POST /v1/projects/:id/search

请求体:

{
"query": "用户认证流程",
"limit": 10
}

响应:

{
"success": true,
"results": [
{
"filePath": "src/auth/login.ts",
"lineStart": 45,
"lineEnd": 78,
"content": "async function authenticate(email, password) {...}",
"score": 0.92,
"context": "LoginService - 处理用户认证"
}
]
}

询问 AI 助手

询问关于您代码库的问题。

POST /v1/projects/:id/ask

请求体:

{
"question": "认证系统是如何工作的?",
"language": "zh"
}

响应:

{
"success": true,
"answer": "认证系统使用 JWT 令牌...",
"references": [
{
"filePath": "src/auth/login.ts",
"description": "主要认证逻辑"
}
]
}

影响分析

分析文件更改的影响。

POST /v1/projects/:id/analyze

请求体:

{
"path": "src/services/user.ts"
}

响应:

{
"success": true,
"impact": {
"directDependencies": [
"src/utils/crypto.ts",
"src/db/models/user.ts"
],
"dependents": [
"src/controllers/auth.ts",
"src/controllers/profile.ts"
],
"affectedTests": [
"tests/user.test.ts"
],
"riskLevel": "medium",
"recommendation": "更改需要测试认证和个人资料流程"
}
}

代码指标

获取代码质量指标。

GET /v1/projects/:id/metrics

查询参数:

参数类型描述
pathstring按路径过滤(可选)

响应:

{
"success": true,
"metrics": {
"summary": {
"totalFiles": 234,
"totalLines": 15420,
"avgComplexity": 4.2,
"maxComplexity": 18,
"duplicatePercentage": 3.1
},
"byFile": [
{
"path": "src/services/complex.ts",
"lines": 450,
"complexity": 18,
"maintainability": 62
}
]
}
}

安全扫描

获取安全漏洞扫描结果。

GET /v1/projects/:id/security

响应:

{
"success": true,
"scan": {
"status": "completed",
"scannedAt": "2024-01-15T10:30:00Z",
"summary": {
"high": 2,
"medium": 5,
"low": 8
},
"issues": [
{
"severity": "high",
"type": "sql-injection",
"file": "src/db/query.ts",
"line": 34,
"description": "潜在的 SQL 注入漏洞",
"recommendation": "使用参数化查询"
}
]
}
}

死代码检测

查找未使用的代码。

GET /v1/projects/:id/dead-code

响应:

{
"success": true,
"deadCode": {
"unusedExports": [
{
"file": "src/utils/helpers.ts",
"name": "formatDate",
"line": 45,
"type": "function"
}
],
"unusedFiles": [
"src/legacy/old-service.ts"
],
"estimatedLines": 234
}
}

代码重复

查找重复的代码块。

GET /v1/projects/:id/duplication

响应:

{
"success": true,
"duplication": {
"percentage": 3.1,
"duplicates": [
{
"lines": 15,
"occurrences": [
{ "file": "src/api/users.ts", "start": 45, "end": 60 },
{ "file": "src/api/products.ts", "start": 32, "end": 47 }
]
}
]
}
}