@ppdocs/mcp 3.9.0 → 3.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +15 -7
- package/dist/config.d.ts +1 -0
- package/dist/config.js +16 -2
- package/dist/index.js +2 -2
- package/dist/tools/discussion.js +1 -3
- package/dist/tools/flowchart.js +3 -0
- package/dist/tools/init.js +3 -1
- package/dist/tools/kg_status.d.ts +1 -0
- package/dist/tools/kg_status.js +33 -9
- package/dist/tools/shared.d.ts +1 -1
- package/dist/tools/shared.js +1 -1
- package/package.json +1 -1
- package/templates/AGENT.md +105 -64
- package/templates/cursorrules.md +105 -64
- package/templates/kiro-rules/ppdocs.md +105 -64
package/dist/cli.js
CHANGED
|
@@ -6,7 +6,7 @@ import * as fs from 'fs';
|
|
|
6
6
|
import * as os from 'os';
|
|
7
7
|
import * as path from 'path';
|
|
8
8
|
import { fileURLToPath } from 'url';
|
|
9
|
-
import { execSync } from 'child_process';
|
|
9
|
+
import { execSync, spawnSync } from 'child_process';
|
|
10
10
|
import { generateUser } from './config.js';
|
|
11
11
|
import { PpdocsApiClient } from './storage/httpClient.js';
|
|
12
12
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -259,25 +259,33 @@ function execSilent(cmd) {
|
|
|
259
259
|
function autoRegisterMcp(cwd, apiUrl, user, skipGemini = false) {
|
|
260
260
|
const detected = [];
|
|
261
261
|
const serverName = 'ppdocs-kg';
|
|
262
|
-
const addCmd = `-- npx -y @ppdocs/mcp@latest`;
|
|
263
262
|
const envPairs = [
|
|
264
263
|
`PPDOCS_API_URL=${apiUrl}`,
|
|
265
264
|
`PPDOCS_USER=${user}`,
|
|
266
265
|
`PPDOCS_PROJECT_ROOT=${cwd}`,
|
|
267
266
|
];
|
|
268
|
-
|
|
269
|
-
|
|
267
|
+
/** 用 spawnSync + args 数组注册 MCP,避免 Windows cmd.exe 引号解析问题 */
|
|
268
|
+
function mcpAdd(cli, envFlag) {
|
|
269
|
+
const args = ['mcp', 'add'];
|
|
270
|
+
for (const pair of envPairs) {
|
|
271
|
+
args.push(envFlag, pair);
|
|
272
|
+
}
|
|
273
|
+
args.push(serverName, '--', 'npx', '-y', '@ppdocs/mcp@latest');
|
|
274
|
+
const result = spawnSync(cli, args, { stdio: 'inherit', shell: true });
|
|
275
|
+
if (result.status !== 0)
|
|
276
|
+
throw new Error(`${cli} mcp add failed`);
|
|
277
|
+
}
|
|
270
278
|
// Claude CLI
|
|
271
279
|
if (commandExists('claude')) {
|
|
272
280
|
detected.push('Claude');
|
|
273
281
|
try {
|
|
274
282
|
execSilent(`claude mcp remove ${serverName}`);
|
|
275
|
-
|
|
283
|
+
mcpAdd('claude', '-e');
|
|
276
284
|
}
|
|
277
285
|
catch {
|
|
278
286
|
try {
|
|
279
287
|
execSilent(`claude mcp remove ${serverName}`);
|
|
280
|
-
|
|
288
|
+
mcpAdd('claude', '-e');
|
|
281
289
|
}
|
|
282
290
|
catch {
|
|
283
291
|
console.log(`⚠️ Claude MCP registration failed`);
|
|
@@ -289,7 +297,7 @@ function autoRegisterMcp(cwd, apiUrl, user, skipGemini = false) {
|
|
|
289
297
|
detected.push('Codex');
|
|
290
298
|
try {
|
|
291
299
|
execSilent(`codex mcp remove ${serverName}`);
|
|
292
|
-
|
|
300
|
+
mcpAdd('codex', '--env');
|
|
293
301
|
}
|
|
294
302
|
catch {
|
|
295
303
|
console.log(`⚠️ Codex MCP registration failed`);
|
package/dist/config.d.ts
CHANGED
|
@@ -12,4 +12,5 @@ export interface PpdocsConfig {
|
|
|
12
12
|
export declare const PPDOCS_CONFIG_FILE = ".ppdocs";
|
|
13
13
|
/** 生成随机用户名 */
|
|
14
14
|
export declare function generateUser(): string;
|
|
15
|
+
export declare function generateAgentId(): string;
|
|
15
16
|
export declare function loadConfig(): Promise<PpdocsConfig | null>;
|
package/dist/config.js
CHANGED
|
@@ -10,6 +10,20 @@ export function generateUser() {
|
|
|
10
10
|
const chars = 'abcdefghjkmnpqrstuvwxyz23456789';
|
|
11
11
|
return Array.from({ length: 8 }, () => chars[Math.floor(Math.random() * chars.length)]).join('');
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* 生成唯一 agentId (每个 MCP 进程实例一个)
|
|
15
|
+
* 格式: "a-{4位随机}" — 简短且足够区分同机多实例
|
|
16
|
+
* 进程级单例: 同一进程内多次调用返回相同值
|
|
17
|
+
*/
|
|
18
|
+
let _cachedAgentId = null;
|
|
19
|
+
export function generateAgentId() {
|
|
20
|
+
if (!_cachedAgentId) {
|
|
21
|
+
const chars = 'abcdefghjkmnpqrstuvwxyz23456789';
|
|
22
|
+
const rand = Array.from({ length: 4 }, () => chars[Math.floor(Math.random() * chars.length)]).join('');
|
|
23
|
+
_cachedAgentId = `a-${rand}`;
|
|
24
|
+
}
|
|
25
|
+
return _cachedAgentId;
|
|
26
|
+
}
|
|
13
27
|
// ============ 配置读取 ============
|
|
14
28
|
function readEnvConfig() {
|
|
15
29
|
const apiUrl = process.env.PPDOCS_API_URL;
|
|
@@ -20,7 +34,7 @@ function readEnvConfig() {
|
|
|
20
34
|
apiUrl,
|
|
21
35
|
projectId: match?.[1] || 'unknown',
|
|
22
36
|
user: process.env.PPDOCS_USER || generateUser(),
|
|
23
|
-
agentId: process.env.PPDOCS_AGENT_ID ||
|
|
37
|
+
agentId: process.env.PPDOCS_AGENT_ID || generateAgentId(),
|
|
24
38
|
source: 'env',
|
|
25
39
|
};
|
|
26
40
|
}
|
|
@@ -49,7 +63,7 @@ function readPpdocsFile() {
|
|
|
49
63
|
const c = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
50
64
|
if (!c.api || !c.projectId || !c.key)
|
|
51
65
|
return null;
|
|
52
|
-
return { apiUrl: `${c.api}/api/${c.projectId}/${c.key}`, projectId: c.projectId, user: c.user || generateUser(), agentId: c.agentId || process.env.PPDOCS_AGENT_ID ||
|
|
66
|
+
return { apiUrl: `${c.api}/api/${c.projectId}/${c.key}`, projectId: c.projectId, user: c.user || generateUser(), agentId: c.agentId || process.env.PPDOCS_AGENT_ID || generateAgentId(), source: 'file' };
|
|
53
67
|
}
|
|
54
68
|
catch {
|
|
55
69
|
return null;
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
|
14
14
|
import { registerTools } from './tools/index.js';
|
|
15
15
|
import { initClient } from './storage/httpClient.js';
|
|
16
16
|
import { runCli } from './cli.js';
|
|
17
|
-
import { loadConfig } from './config.js';
|
|
17
|
+
import { loadConfig, generateAgentId } from './config.js';
|
|
18
18
|
// 从 package.json 读取版本号
|
|
19
19
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
20
20
|
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf-8'));
|
|
@@ -39,7 +39,7 @@ async function main() {
|
|
|
39
39
|
}
|
|
40
40
|
const projectId = config?.projectId || 'pending';
|
|
41
41
|
const user = config?.user || 'agent';
|
|
42
|
-
const agentId = config?.agentId || process.env.PPDOCS_AGENT_ID ||
|
|
42
|
+
const agentId = config?.agentId || process.env.PPDOCS_AGENT_ID || generateAgentId();
|
|
43
43
|
const server = new McpServer({ name: `ppdocs [${projectId}]`, version: VERSION }, { capabilities: { tools: {} } });
|
|
44
44
|
registerTools(server, projectId, user, agentId, (newProjectId, newApiUrl) => {
|
|
45
45
|
console.error(`[kg_init] 项目已切换: ${newProjectId}`);
|
package/dist/tools/discussion.js
CHANGED
|
@@ -15,9 +15,7 @@ import { getClient } from '../storage/httpClient.js';
|
|
|
15
15
|
import { decodeObjectStrings } from '../utils.js';
|
|
16
16
|
import { wrap, safeTool } from './shared.js';
|
|
17
17
|
function sender(ctx) {
|
|
18
|
-
return ctx.
|
|
19
|
-
? `${ctx.projectId}:${ctx.user}:${ctx.agentId}`
|
|
20
|
-
: `${ctx.projectId}:${ctx.user}`;
|
|
18
|
+
return `${ctx.projectId}:${ctx.user}:${ctx.agentId}`;
|
|
21
19
|
}
|
|
22
20
|
/** 提取 sender 中的 projectId */
|
|
23
21
|
function senderProjectId(senderStr) {
|
package/dist/tools/flowchart.js
CHANGED
|
@@ -380,6 +380,9 @@ export function registerFlowchartTools(server, _ctx) {
|
|
|
380
380
|
if (chart.parentChart) {
|
|
381
381
|
lines.push(`parent: ${chart.parentChart}${chart.parentNode ? `/${chart.parentNode}` : ''}`);
|
|
382
382
|
}
|
|
383
|
+
if (chart.projectBrief) {
|
|
384
|
+
lines.push('', chart.projectBrief);
|
|
385
|
+
}
|
|
383
386
|
// Mermaid 流程图
|
|
384
387
|
lines.push('', '```mermaid', 'graph TD');
|
|
385
388
|
// 节点声明
|
package/dist/tools/init.js
CHANGED
|
@@ -11,6 +11,7 @@ import * as fs from 'fs';
|
|
|
11
11
|
import * as path from 'path';
|
|
12
12
|
import { z } from 'zod';
|
|
13
13
|
import { initClient } from '../storage/httpClient.js';
|
|
14
|
+
import { generateAgentId } from '../config.js';
|
|
14
15
|
import { wrap, safeTool } from './shared.js';
|
|
15
16
|
// 当前会话的 API URL (用于幂等检查)
|
|
16
17
|
let currentApiUrl = null;
|
|
@@ -74,7 +75,8 @@ export function registerInitTool(server, ctx, onProjectChange) {
|
|
|
74
75
|
// 4. 更新共享上下文 — 所有工具立刻获得新 projectId
|
|
75
76
|
ctx.projectId = config.projectId;
|
|
76
77
|
ctx.user = config.user;
|
|
77
|
-
|
|
78
|
+
// agentId: 优先环境变量 > 保留当前值(进程启动时已生成)
|
|
79
|
+
ctx.agentId = process.env.PPDOCS_AGENT_ID || ctx.agentId || generateAgentId();
|
|
78
80
|
// 5. 通知主进程
|
|
79
81
|
onProjectChange(config.projectId, config.apiUrl);
|
|
80
82
|
return wrap(`✅ 项目上下文已初始化\n\n` +
|
package/dist/tools/kg_status.js
CHANGED
|
@@ -1,32 +1,56 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 📊 kg_status — 项目速览仪表盘
|
|
3
|
+
* 一次调用返回项目全貌:摘要、核心模块、活跃任务、快速导航
|
|
3
4
|
*/
|
|
4
5
|
import { getClient } from '../storage/httpClient.js';
|
|
5
6
|
import { wrap, safeTool } from './shared.js';
|
|
6
7
|
export function registerStatusTool(server, ctx) {
|
|
7
8
|
const client = () => getClient();
|
|
8
9
|
server.tool('kg_status', '📊 项目速览仪表盘 — 一键了解项目健康。返回: 流程图节点数、活跃任务数、最近变更。每次对话开始建议首先调用', {}, async () => safeTool(async () => {
|
|
9
|
-
const [charts, activeTasks, discussions] = await Promise.all([
|
|
10
|
+
const [charts, activeTasks, discussions, mainChart] = await Promise.all([
|
|
10
11
|
client().listFlowcharts(),
|
|
11
12
|
client().listTasks('active'),
|
|
12
13
|
client().discussionList().catch(() => []),
|
|
14
|
+
client().getFlowchart('main').catch(() => null),
|
|
13
15
|
]);
|
|
14
16
|
const nodeCount = charts.reduce((sum, c) => sum + (c.nodeCount || 0), 0);
|
|
15
17
|
const activeDiscussions = discussions.filter((d) => d.status === 'active');
|
|
16
18
|
const lines = [
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
``,
|
|
20
|
-
`🔀 流程图: ${charts.length} 张 | 📦 节点: ${nodeCount} 个`,
|
|
21
|
-
`📝 活跃任务: ${activeTasks.length} 个`,
|
|
22
|
-
`📨 活跃讨论: ${activeDiscussions.length} 个`,
|
|
19
|
+
`# 项目速览 [${ctx.projectId}]`,
|
|
20
|
+
`身份: ${ctx.user}:${ctx.agentId}`,
|
|
23
21
|
];
|
|
22
|
+
// --- Project Brief ---
|
|
23
|
+
if (mainChart?.projectBrief) {
|
|
24
|
+
lines.push('', '## 项目简介', mainChart.projectBrief);
|
|
25
|
+
}
|
|
26
|
+
// --- 核心模块 (从 main 图提取) ---
|
|
27
|
+
if (mainChart?.nodes && mainChart.nodes.length > 0) {
|
|
28
|
+
lines.push('', '## 核心模块');
|
|
29
|
+
for (const node of mainChart.nodes) {
|
|
30
|
+
const badges = [];
|
|
31
|
+
if (node.subFlowchart)
|
|
32
|
+
badges.push(`▶${node.subFlowchart}`);
|
|
33
|
+
const fileCount = (node.boundFiles?.length ?? 0) + (node.boundDirs?.length ?? 0);
|
|
34
|
+
if (fileCount > 0)
|
|
35
|
+
badges.push(`files=${fileCount}`);
|
|
36
|
+
const docCount = node.docEntries?.length ?? 0;
|
|
37
|
+
if (docCount > 0)
|
|
38
|
+
badges.push(`docs=${docCount}`);
|
|
39
|
+
const suffix = badges.length > 0 ? ` [${badges.join(' ')}]` : '';
|
|
40
|
+
const desc = node.description ? ` — ${node.description.slice(0, 80)}` : '';
|
|
41
|
+
lines.push(`- **${node.label}** \`${node.id}\`${desc}${suffix}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// --- 当前状态 ---
|
|
45
|
+
lines.push('', '## 当前状态', `- 流程图: ${charts.length} 张 | 节点: ${nodeCount} 个`, `- 活跃任务: ${activeTasks.length} 个`, `- 活跃讨论: ${activeDiscussions.length} 个`);
|
|
24
46
|
if (activeTasks.length > 0) {
|
|
25
|
-
lines.push(
|
|
47
|
+
lines.push('', '### 进行中的任务');
|
|
26
48
|
for (const t of activeTasks.slice(0, 5)) {
|
|
27
|
-
lines.push(
|
|
49
|
+
lines.push(`- ${t.title} (\`${t.id}\`)`);
|
|
28
50
|
}
|
|
29
51
|
}
|
|
52
|
+
// --- 快速导航 ---
|
|
53
|
+
lines.push('', '## 快速导航', '- `kg_flowchart(get, "main")` — 查看完整架构图', '- `kg_flowchart(get_node, "节点ID", expand:2)` — 深入某个模块', '- `kg_workflow()` — 查看可用工作流', '- `kg_task(get)` — 查看活跃任务详情');
|
|
30
54
|
return wrap(lines.join('\n'));
|
|
31
55
|
}));
|
|
32
56
|
}
|
package/dist/tools/shared.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface McpContext {
|
|
|
9
9
|
agentId: string;
|
|
10
10
|
}
|
|
11
11
|
/** 创建可变上下文对象 (工具闭包捕获此对象的引用,kg_init 更新其属性) */
|
|
12
|
-
export declare function createContext(projectId: string, user: string, agentId
|
|
12
|
+
export declare function createContext(projectId: string, user: string, agentId: string): McpContext;
|
|
13
13
|
export declare function wrap(text: string): {
|
|
14
14
|
content: {
|
|
15
15
|
type: "text";
|
package/dist/tools/shared.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* 合并原 helpers.ts + 新增 safeTool / withCross 模式
|
|
4
4
|
*/
|
|
5
5
|
/** 创建可变上下文对象 (工具闭包捕获此对象的引用,kg_init 更新其属性) */
|
|
6
|
-
export function createContext(projectId, user, agentId
|
|
6
|
+
export function createContext(projectId, user, agentId) {
|
|
7
7
|
return { projectId, user, agentId };
|
|
8
8
|
}
|
|
9
9
|
// ==================== MCP 返回包装 ====================
|
package/package.json
CHANGED
package/templates/AGENT.md
CHANGED
|
@@ -1,64 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
|
44
|
-
|
|
45
|
-
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
|
49
|
-
|
|
50
|
-
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
1
|
+
# ppdocs 知识图谱 — AI 协作规范
|
|
2
|
+
|
|
3
|
+
本项目使用 ppdocs 知识图谱系统管理项目知识。你拥有一组 MCP 工具来访问项目的架构图谱、文档、任务和代码分析能力。
|
|
4
|
+
|
|
5
|
+
## 首次对话启动
|
|
6
|
+
|
|
7
|
+
每次新对话开始时,按以下顺序获取项目上下文:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
1. kg_status() → 项目概况(含架构摘要、活跃任务、核心模块列表)
|
|
11
|
+
2. kg_flowchart(get, "main") → 需要深入时查看完整架构图
|
|
12
|
+
3. kg_workflow() → 查看可用的标准工作流
|
|
13
|
+
4. kg_task(get) → 查看活跃任务详情
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
通常只需第 1 步就能获得足够的项目上下文开始工作。
|
|
17
|
+
|
|
18
|
+
## 工具速查
|
|
19
|
+
|
|
20
|
+
### 理解项目
|
|
21
|
+
| 工具 | 用途 |
|
|
22
|
+
|:---|:---|
|
|
23
|
+
| `kg_status()` | 一键获取项目全貌(推荐首选) |
|
|
24
|
+
| `kg_flowchart(get, chartId)` | 查看某张流程图的完整结构 |
|
|
25
|
+
| `kg_flowchart(get_node, nodeId, expand:2)` | 深入某个模块,含文档和绑定文件 |
|
|
26
|
+
| `kg_flowchart(search, query)` | 按关键词搜索流程图节点 |
|
|
27
|
+
| `kg_doc(search, query)` | 搜索节点内嵌文档 |
|
|
28
|
+
| `code_smart_context(symbolName)` | 获取代码符号的依赖和关联文档 |
|
|
29
|
+
| `code_full_path(symbolA, symbolB)` | 查找两个符号之间的关联路径 |
|
|
30
|
+
|
|
31
|
+
### 执行任务
|
|
32
|
+
| 工具 | 用途 |
|
|
33
|
+
|:---|:---|
|
|
34
|
+
| `kg_task(create, title, goals, bindTo)` | 开始新任务(绑定到流程图节点) |
|
|
35
|
+
| `kg_task(update, content, log_type)` | 记录进度/问题/方案(每步都要记录) |
|
|
36
|
+
| `kg_task(archive, summary, solutions)` | 完成任务并归档经验 |
|
|
37
|
+
| `kg_workflow(id)` | 获取标准工作流指导(如有匹配的工作流) |
|
|
38
|
+
|
|
39
|
+
### 回写知识
|
|
40
|
+
| 工具 | 用途 |
|
|
41
|
+
|:---|:---|
|
|
42
|
+
| `kg_flowchart(update_node, nodeId, docSummary, docContent)` | 更新节点文档 |
|
|
43
|
+
| `kg_flowchart(bind, nodeId, files:[...])` | 绑定源码文件到节点 |
|
|
44
|
+
| `kg_flowchart(batch_add, nodes, edges)` | 新增模块时批量创建节点 |
|
|
45
|
+
| `kg_flowchart(create_chart)` | 为复杂模块创建子流程图 |
|
|
46
|
+
|
|
47
|
+
### 协作与文件
|
|
48
|
+
| 工具 | 用途 |
|
|
49
|
+
|:---|:---|
|
|
50
|
+
| `kg_discuss(create/reply/list)` | 跨 AI 实例讨论 |
|
|
51
|
+
| `kg_meeting(join/post/status)` | 多 AI 协作会议 |
|
|
52
|
+
| `kg_files(list/read/download)` | 项目文件管理 |
|
|
53
|
+
| `kg_ref(list/get/save)` | 外部参考资料管理 |
|
|
54
|
+
|
|
55
|
+
## 核心原则
|
|
56
|
+
|
|
57
|
+
1. **先查图谱再看代码** — 在 grep/搜索代码之前,先用 `kg_flowchart(search)` 或 `kg_doc(search)` 查找相关节点,通常能直接定位到关键文件和逻辑说明,减少 80% 的盲目搜索。
|
|
58
|
+
|
|
59
|
+
2. **每完成一步就 update task** — 使用 `kg_task(update)` 记录每个阶段的进展,遇到问题用 `log_type:"issue"` 记录,找到方案用 `log_type:"solution"` 记录。
|
|
60
|
+
|
|
61
|
+
3. **改完代码必须回写图谱** — 修改了代码后,检查对应的流程图节点文档是否需要更新。新增文件要 `bind`,逻辑变更要 `update_node` 的 docContent。
|
|
62
|
+
|
|
63
|
+
4. **子图递归探索** — 节点如果有 `subFlowchart` 字段,说明它有更细粒度的子流程图。理解细节时要递归下探。
|
|
64
|
+
|
|
65
|
+
## 节点文档模板
|
|
66
|
+
|
|
67
|
+
创建或更新节点 `docContent` 时,推荐使用以下结构:
|
|
68
|
+
|
|
69
|
+
```markdown
|
|
70
|
+
## 职责
|
|
71
|
+
一句话说清本模块的核心职责。
|
|
72
|
+
|
|
73
|
+
## 输入 / 输出
|
|
74
|
+
- 输入: 进入本模块的数据或请求
|
|
75
|
+
- 输出: 本模块产出的数据或响应
|
|
76
|
+
|
|
77
|
+
## 核心逻辑
|
|
78
|
+
1. 步骤一
|
|
79
|
+
2. 步骤二
|
|
80
|
+
3. ...(3-7 步为宜)
|
|
81
|
+
|
|
82
|
+
## 边界条件
|
|
83
|
+
- 它不负责什么(明确排除)
|
|
84
|
+
- 错误处理策略
|
|
85
|
+
|
|
86
|
+
## 关键文件
|
|
87
|
+
- path/to/main.go — 主逻辑
|
|
88
|
+
- path/to/helper.go — 辅助函数
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## 错误处理
|
|
92
|
+
|
|
93
|
+
| 场景 | 处理方式 |
|
|
94
|
+
|:---|:---|
|
|
95
|
+
| API 超时/网络错误 | 重试一次,仍失败则告知用户 |
|
|
96
|
+
| JSON 解析失败 | fallback 到纯文本输出 |
|
|
97
|
+
| 找不到节点 | 用 `kg_flowchart(search)` 模糊搜索 |
|
|
98
|
+
| 工具调用失败 | 检查参数格式,确保 JSON 数组/对象格式正确 |
|
|
99
|
+
|
|
100
|
+
## 输出格式
|
|
101
|
+
|
|
102
|
+
- 逻辑说明用 ASCII 流程图
|
|
103
|
+
- 对比分析用 Markdown 表格
|
|
104
|
+
- 代码引用注明文件路径和行号
|
|
105
|
+
- 方案说明要简洁,避免不必要的冗余
|
package/templates/cursorrules.md
CHANGED
|
@@ -1,64 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
|
44
|
-
|
|
45
|
-
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
|
49
|
-
|
|
50
|
-
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
1
|
+
# ppdocs 知识图谱 — AI 协作规范
|
|
2
|
+
|
|
3
|
+
本项目使用 ppdocs 知识图谱系统管理项目知识。你拥有一组 MCP 工具来访问项目的架构图谱、文档、任务和代码分析能力。
|
|
4
|
+
|
|
5
|
+
## 首次对话启动
|
|
6
|
+
|
|
7
|
+
每次新对话开始时,按以下顺序获取项目上下文:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
1. kg_status() → 项目概况(含架构摘要、活跃任务、核心模块列表)
|
|
11
|
+
2. kg_flowchart(get, "main") → 需要深入时查看完整架构图
|
|
12
|
+
3. kg_workflow() → 查看可用的标准工作流
|
|
13
|
+
4. kg_task(get) → 查看活跃任务详情
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
通常只需第 1 步就能获得足够的项目上下文开始工作。
|
|
17
|
+
|
|
18
|
+
## 工具速查
|
|
19
|
+
|
|
20
|
+
### 理解项目
|
|
21
|
+
| 工具 | 用途 |
|
|
22
|
+
|:---|:---|
|
|
23
|
+
| `kg_status()` | 一键获取项目全貌(推荐首选) |
|
|
24
|
+
| `kg_flowchart(get, chartId)` | 查看某张流程图的完整结构 |
|
|
25
|
+
| `kg_flowchart(get_node, nodeId, expand:2)` | 深入某个模块,含文档和绑定文件 |
|
|
26
|
+
| `kg_flowchart(search, query)` | 按关键词搜索流程图节点 |
|
|
27
|
+
| `kg_doc(search, query)` | 搜索节点内嵌文档 |
|
|
28
|
+
| `code_smart_context(symbolName)` | 获取代码符号的依赖和关联文档 |
|
|
29
|
+
| `code_full_path(symbolA, symbolB)` | 查找两个符号之间的关联路径 |
|
|
30
|
+
|
|
31
|
+
### 执行任务
|
|
32
|
+
| 工具 | 用途 |
|
|
33
|
+
|:---|:---|
|
|
34
|
+
| `kg_task(create, title, goals, bindTo)` | 开始新任务(绑定到流程图节点) |
|
|
35
|
+
| `kg_task(update, content, log_type)` | 记录进度/问题/方案(每步都要记录) |
|
|
36
|
+
| `kg_task(archive, summary, solutions)` | 完成任务并归档经验 |
|
|
37
|
+
| `kg_workflow(id)` | 获取标准工作流指导(如有匹配的工作流) |
|
|
38
|
+
|
|
39
|
+
### 回写知识
|
|
40
|
+
| 工具 | 用途 |
|
|
41
|
+
|:---|:---|
|
|
42
|
+
| `kg_flowchart(update_node, nodeId, docSummary, docContent)` | 更新节点文档 |
|
|
43
|
+
| `kg_flowchart(bind, nodeId, files:[...])` | 绑定源码文件到节点 |
|
|
44
|
+
| `kg_flowchart(batch_add, nodes, edges)` | 新增模块时批量创建节点 |
|
|
45
|
+
| `kg_flowchart(create_chart)` | 为复杂模块创建子流程图 |
|
|
46
|
+
|
|
47
|
+
### 协作与文件
|
|
48
|
+
| 工具 | 用途 |
|
|
49
|
+
|:---|:---|
|
|
50
|
+
| `kg_discuss(create/reply/list)` | 跨 AI 实例讨论 |
|
|
51
|
+
| `kg_meeting(join/post/status)` | 多 AI 协作会议 |
|
|
52
|
+
| `kg_files(list/read/download)` | 项目文件管理 |
|
|
53
|
+
| `kg_ref(list/get/save)` | 外部参考资料管理 |
|
|
54
|
+
|
|
55
|
+
## 核心原则
|
|
56
|
+
|
|
57
|
+
1. **先查图谱再看代码** — 在 grep/搜索代码之前,先用 `kg_flowchart(search)` 或 `kg_doc(search)` 查找相关节点,通常能直接定位到关键文件和逻辑说明,减少 80% 的盲目搜索。
|
|
58
|
+
|
|
59
|
+
2. **每完成一步就 update task** — 使用 `kg_task(update)` 记录每个阶段的进展,遇到问题用 `log_type:"issue"` 记录,找到方案用 `log_type:"solution"` 记录。
|
|
60
|
+
|
|
61
|
+
3. **改完代码必须回写图谱** — 修改了代码后,检查对应的流程图节点文档是否需要更新。新增文件要 `bind`,逻辑变更要 `update_node` 的 docContent。
|
|
62
|
+
|
|
63
|
+
4. **子图递归探索** — 节点如果有 `subFlowchart` 字段,说明它有更细粒度的子流程图。理解细节时要递归下探。
|
|
64
|
+
|
|
65
|
+
## 节点文档模板
|
|
66
|
+
|
|
67
|
+
创建或更新节点 `docContent` 时,推荐使用以下结构:
|
|
68
|
+
|
|
69
|
+
```markdown
|
|
70
|
+
## 职责
|
|
71
|
+
一句话说清本模块的核心职责。
|
|
72
|
+
|
|
73
|
+
## 输入 / 输出
|
|
74
|
+
- 输入: 进入本模块的数据或请求
|
|
75
|
+
- 输出: 本模块产出的数据或响应
|
|
76
|
+
|
|
77
|
+
## 核心逻辑
|
|
78
|
+
1. 步骤一
|
|
79
|
+
2. 步骤二
|
|
80
|
+
3. ...(3-7 步为宜)
|
|
81
|
+
|
|
82
|
+
## 边界条件
|
|
83
|
+
- 它不负责什么(明确排除)
|
|
84
|
+
- 错误处理策略
|
|
85
|
+
|
|
86
|
+
## 关键文件
|
|
87
|
+
- path/to/main.go — 主逻辑
|
|
88
|
+
- path/to/helper.go — 辅助函数
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## 错误处理
|
|
92
|
+
|
|
93
|
+
| 场景 | 处理方式 |
|
|
94
|
+
|:---|:---|
|
|
95
|
+
| API 超时/网络错误 | 重试一次,仍失败则告知用户 |
|
|
96
|
+
| JSON 解析失败 | fallback 到纯文本输出 |
|
|
97
|
+
| 找不到节点 | 用 `kg_flowchart(search)` 模糊搜索 |
|
|
98
|
+
| 工具调用失败 | 检查参数格式,确保 JSON 数组/对象格式正确 |
|
|
99
|
+
|
|
100
|
+
## 输出格式
|
|
101
|
+
|
|
102
|
+
- 逻辑说明用 ASCII 流程图
|
|
103
|
+
- 对比分析用 Markdown 表格
|
|
104
|
+
- 代码引用注明文件路径和行号
|
|
105
|
+
- 方案说明要简洁,避免不必要的冗余
|
|
@@ -1,64 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
|
44
|
-
|
|
45
|
-
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
|
49
|
-
|
|
50
|
-
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
1
|
+
# ppdocs 知识图谱 — AI 协作规范
|
|
2
|
+
|
|
3
|
+
本项目使用 ppdocs 知识图谱系统管理项目知识。你拥有一组 MCP 工具来访问项目的架构图谱、文档、任务和代码分析能力。
|
|
4
|
+
|
|
5
|
+
## 首次对话启动
|
|
6
|
+
|
|
7
|
+
每次新对话开始时,按以下顺序获取项目上下文:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
1. kg_status() → 项目概况(含架构摘要、活跃任务、核心模块列表)
|
|
11
|
+
2. kg_flowchart(get, "main") → 需要深入时查看完整架构图
|
|
12
|
+
3. kg_workflow() → 查看可用的标准工作流
|
|
13
|
+
4. kg_task(get) → 查看活跃任务详情
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
通常只需第 1 步就能获得足够的项目上下文开始工作。
|
|
17
|
+
|
|
18
|
+
## 工具速查
|
|
19
|
+
|
|
20
|
+
### 理解项目
|
|
21
|
+
| 工具 | 用途 |
|
|
22
|
+
|:---|:---|
|
|
23
|
+
| `kg_status()` | 一键获取项目全貌(推荐首选) |
|
|
24
|
+
| `kg_flowchart(get, chartId)` | 查看某张流程图的完整结构 |
|
|
25
|
+
| `kg_flowchart(get_node, nodeId, expand:2)` | 深入某个模块,含文档和绑定文件 |
|
|
26
|
+
| `kg_flowchart(search, query)` | 按关键词搜索流程图节点 |
|
|
27
|
+
| `kg_doc(search, query)` | 搜索节点内嵌文档 |
|
|
28
|
+
| `code_smart_context(symbolName)` | 获取代码符号的依赖和关联文档 |
|
|
29
|
+
| `code_full_path(symbolA, symbolB)` | 查找两个符号之间的关联路径 |
|
|
30
|
+
|
|
31
|
+
### 执行任务
|
|
32
|
+
| 工具 | 用途 |
|
|
33
|
+
|:---|:---|
|
|
34
|
+
| `kg_task(create, title, goals, bindTo)` | 开始新任务(绑定到流程图节点) |
|
|
35
|
+
| `kg_task(update, content, log_type)` | 记录进度/问题/方案(每步都要记录) |
|
|
36
|
+
| `kg_task(archive, summary, solutions)` | 完成任务并归档经验 |
|
|
37
|
+
| `kg_workflow(id)` | 获取标准工作流指导(如有匹配的工作流) |
|
|
38
|
+
|
|
39
|
+
### 回写知识
|
|
40
|
+
| 工具 | 用途 |
|
|
41
|
+
|:---|:---|
|
|
42
|
+
| `kg_flowchart(update_node, nodeId, docSummary, docContent)` | 更新节点文档 |
|
|
43
|
+
| `kg_flowchart(bind, nodeId, files:[...])` | 绑定源码文件到节点 |
|
|
44
|
+
| `kg_flowchart(batch_add, nodes, edges)` | 新增模块时批量创建节点 |
|
|
45
|
+
| `kg_flowchart(create_chart)` | 为复杂模块创建子流程图 |
|
|
46
|
+
|
|
47
|
+
### 协作与文件
|
|
48
|
+
| 工具 | 用途 |
|
|
49
|
+
|:---|:---|
|
|
50
|
+
| `kg_discuss(create/reply/list)` | 跨 AI 实例讨论 |
|
|
51
|
+
| `kg_meeting(join/post/status)` | 多 AI 协作会议 |
|
|
52
|
+
| `kg_files(list/read/download)` | 项目文件管理 |
|
|
53
|
+
| `kg_ref(list/get/save)` | 外部参考资料管理 |
|
|
54
|
+
|
|
55
|
+
## 核心原则
|
|
56
|
+
|
|
57
|
+
1. **先查图谱再看代码** — 在 grep/搜索代码之前,先用 `kg_flowchart(search)` 或 `kg_doc(search)` 查找相关节点,通常能直接定位到关键文件和逻辑说明,减少 80% 的盲目搜索。
|
|
58
|
+
|
|
59
|
+
2. **每完成一步就 update task** — 使用 `kg_task(update)` 记录每个阶段的进展,遇到问题用 `log_type:"issue"` 记录,找到方案用 `log_type:"solution"` 记录。
|
|
60
|
+
|
|
61
|
+
3. **改完代码必须回写图谱** — 修改了代码后,检查对应的流程图节点文档是否需要更新。新增文件要 `bind`,逻辑变更要 `update_node` 的 docContent。
|
|
62
|
+
|
|
63
|
+
4. **子图递归探索** — 节点如果有 `subFlowchart` 字段,说明它有更细粒度的子流程图。理解细节时要递归下探。
|
|
64
|
+
|
|
65
|
+
## 节点文档模板
|
|
66
|
+
|
|
67
|
+
创建或更新节点 `docContent` 时,推荐使用以下结构:
|
|
68
|
+
|
|
69
|
+
```markdown
|
|
70
|
+
## 职责
|
|
71
|
+
一句话说清本模块的核心职责。
|
|
72
|
+
|
|
73
|
+
## 输入 / 输出
|
|
74
|
+
- 输入: 进入本模块的数据或请求
|
|
75
|
+
- 输出: 本模块产出的数据或响应
|
|
76
|
+
|
|
77
|
+
## 核心逻辑
|
|
78
|
+
1. 步骤一
|
|
79
|
+
2. 步骤二
|
|
80
|
+
3. ...(3-7 步为宜)
|
|
81
|
+
|
|
82
|
+
## 边界条件
|
|
83
|
+
- 它不负责什么(明确排除)
|
|
84
|
+
- 错误处理策略
|
|
85
|
+
|
|
86
|
+
## 关键文件
|
|
87
|
+
- path/to/main.go — 主逻辑
|
|
88
|
+
- path/to/helper.go — 辅助函数
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## 错误处理
|
|
92
|
+
|
|
93
|
+
| 场景 | 处理方式 |
|
|
94
|
+
|:---|:---|
|
|
95
|
+
| API 超时/网络错误 | 重试一次,仍失败则告知用户 |
|
|
96
|
+
| JSON 解析失败 | fallback 到纯文本输出 |
|
|
97
|
+
| 找不到节点 | 用 `kg_flowchart(search)` 模糊搜索 |
|
|
98
|
+
| 工具调用失败 | 检查参数格式,确保 JSON 数组/对象格式正确 |
|
|
99
|
+
|
|
100
|
+
## 输出格式
|
|
101
|
+
|
|
102
|
+
- 逻辑说明用 ASCII 流程图
|
|
103
|
+
- 对比分析用 Markdown 表格
|
|
104
|
+
- 代码引用注明文件路径和行号
|
|
105
|
+
- 方案说明要简洁,避免不必要的冗余
|