@ppdocs/mcp 3.1.9 → 3.2.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/agent.d.ts +6 -0
- package/dist/agent.js +130 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +49 -14
- package/dist/config.d.ts +12 -6
- package/dist/config.js +106 -42
- package/dist/index.js +13 -3
- package/dist/storage/discussion.d.ts +33 -0
- package/dist/storage/discussion.js +116 -0
- package/dist/storage/httpClient.d.ts +8 -0
- package/dist/storage/httpClient.js +29 -0
- package/dist/tools/analyzer.d.ts +8 -0
- package/dist/tools/analyzer.js +136 -0
- package/dist/tools/discussion.d.ts +7 -0
- package/dist/tools/discussion.js +111 -0
- package/dist/tools/docs.d.ts +3 -3
- package/dist/tools/docs.js +205 -175
- package/dist/tools/files.d.ts +3 -3
- package/dist/tools/files.js +61 -56
- package/dist/tools/index.d.ts +6 -1
- package/dist/tools/index.js +18 -3
- package/dist/tools/kg_status.d.ts +5 -0
- package/dist/tools/kg_status.js +42 -0
- package/dist/tools/projects.d.ts +3 -2
- package/dist/tools/projects.js +4 -36
- package/dist/tools/rules.d.ts +3 -3
- package/dist/tools/rules.js +88 -110
- package/dist/tools/tasks.d.ts +2 -2
- package/dist/tools/tasks.js +96 -73
- package/dist/web/server.d.ts +43 -0
- package/dist/web/server.js +611 -0
- package/dist/web/ui.d.ts +5 -0
- package/dist/web/ui.js +474 -0
- package/package.json +6 -3
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 📊 kg_status — 项目速览仪表盘 (新增)
|
|
3
|
+
*/
|
|
4
|
+
import { getClient } from '../storage/httpClient.js';
|
|
5
|
+
import { wrap, safeTool } from './shared.js';
|
|
6
|
+
export function registerStatusTool(server, projectId) {
|
|
7
|
+
const client = () => getClient();
|
|
8
|
+
server.tool('kg_status', '📊 项目速览仪表盘 — 一键了解项目健康。返回: 文档总数、目录数、活跃任务数、最近变更。每次对话开始建议首先调用', {}, async () => safeTool(async () => {
|
|
9
|
+
const [docs, activeTasks] = await Promise.all([
|
|
10
|
+
client().listDocs(),
|
|
11
|
+
client().listTasks('active'),
|
|
12
|
+
]);
|
|
13
|
+
const dirCount = docs.filter(d => d.isDir).length;
|
|
14
|
+
const docCount = docs.filter(d => !d.isDir).length;
|
|
15
|
+
const statusMap = new Map();
|
|
16
|
+
for (const d of docs) {
|
|
17
|
+
if (d.isDir)
|
|
18
|
+
continue;
|
|
19
|
+
const s = d.status || '已完成';
|
|
20
|
+
statusMap.set(s, (statusMap.get(s) || 0) + 1);
|
|
21
|
+
}
|
|
22
|
+
const lines = [
|
|
23
|
+
`📊 项目速览 [${projectId}]`,
|
|
24
|
+
``,
|
|
25
|
+
`📄 文档: ${docCount} 个 | 📁 目录: ${dirCount} 个`,
|
|
26
|
+
`📝 活跃任务: ${activeTasks.length} 个`,
|
|
27
|
+
];
|
|
28
|
+
if (statusMap.size > 0) {
|
|
29
|
+
const statusLine = Array.from(statusMap.entries())
|
|
30
|
+
.map(([s, c]) => `${s}(${c})`)
|
|
31
|
+
.join(' | ');
|
|
32
|
+
lines.push(`📋 状态分布: ${statusLine}`);
|
|
33
|
+
}
|
|
34
|
+
if (activeTasks.length > 0) {
|
|
35
|
+
lines.push(``, `🔧 进行中的任务:`);
|
|
36
|
+
for (const t of activeTasks.slice(0, 5)) {
|
|
37
|
+
lines.push(` - ${t.title} (${t.id})`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return wrap(lines.join('\n'));
|
|
41
|
+
}));
|
|
42
|
+
}
|
package/dist/tools/projects.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* kg_list_projects,
|
|
2
|
+
* 📋 kg_projects (3→1)
|
|
3
|
+
* 合并: kg_list_projects, kg_update_root → kg_doc 处理
|
|
4
|
+
* 删除: kg_create_project (桌面端操作)
|
|
4
5
|
*/
|
|
5
6
|
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
6
7
|
export declare function registerProjectTools(server: McpServer, projectId: string): void;
|
package/dist/tools/projects.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* kg_list_projects,
|
|
2
|
+
* 📋 kg_projects (3→1)
|
|
3
|
+
* 合并: kg_list_projects, kg_update_root → kg_doc 处理
|
|
4
|
+
* 删除: kg_create_project (桌面端操作)
|
|
4
5
|
*/
|
|
5
|
-
import { z } from 'zod';
|
|
6
6
|
import { getClient } from '../storage/httpClient.js';
|
|
7
|
-
import { decodeObjectStrings } from '../utils.js';
|
|
8
7
|
import { wrap, safeTool } from './shared.js';
|
|
9
8
|
export function registerProjectTools(server, projectId) {
|
|
10
9
|
const client = () => getClient();
|
|
11
|
-
|
|
12
|
-
server.tool('kg_list_projects', '列出所有可访问的项目(返回name和id)。跨项目操作的第一步:先调用此工具获取项目ID,再作为其他工具的targetProject参数', {}, async () => safeTool(async () => {
|
|
10
|
+
server.tool('kg_projects', '📋 列出所有可访问的项目(返回名称和ID)。跨项目操作的第一步: 获取项目ID后用于其他工具的 targetProject 参数', {}, async () => safeTool(async () => {
|
|
13
11
|
const projects = await client().crossListProjects();
|
|
14
12
|
if (projects.length === 0)
|
|
15
13
|
return wrap('暂无可访问的项目');
|
|
@@ -19,34 +17,4 @@ export function registerProjectTools(server, projectId) {
|
|
|
19
17
|
});
|
|
20
18
|
return wrap(`可访问的项目 (${projects.length} 个):\n\n${lines.join('\n')}`);
|
|
21
19
|
}));
|
|
22
|
-
// 创建项目
|
|
23
|
-
server.tool('kg_create_project', '创建新项目。返回项目ID和密码(密码用于MCP连接)', {
|
|
24
|
-
id: z.string().describe('项目ID(英文/数字/中文,如"my-app")'),
|
|
25
|
-
name: z.string().describe('项目名称'),
|
|
26
|
-
description: z.string().optional().describe('项目简介'),
|
|
27
|
-
projectPath: z.string().optional().describe('项目源码路径(本地绝对路径)'),
|
|
28
|
-
}, async (args) => safeTool(async () => {
|
|
29
|
-
const result = await client().createProject(args.id, args.name, args.description, args.projectPath || process.cwd());
|
|
30
|
-
return wrap(`✅ 项目创建成功\n\n- 项目ID: ${result.project.id}\n- 项目名: ${result.project.name}\n- 密码: ${result.password}\n\nMCP 连接地址: http://<服务器IP>:20001/api/${result.project.id}/${result.password}`);
|
|
31
|
-
}));
|
|
32
|
-
// 更新根文档 (项目介绍)
|
|
33
|
-
server.tool('kg_update_root', '更新项目介绍(根文档)', {
|
|
34
|
-
title: z.string().optional().describe('项目标题'),
|
|
35
|
-
description: z.string().optional().describe('项目介绍(Markdown)')
|
|
36
|
-
}, async (args) => safeTool(async () => {
|
|
37
|
-
const decoded = decodeObjectStrings(args);
|
|
38
|
-
if (decoded.title === undefined && decoded.description === undefined) {
|
|
39
|
-
return wrap('❌ 请至少提供 title 或 description');
|
|
40
|
-
}
|
|
41
|
-
const existing = await client().getDoc('/');
|
|
42
|
-
if (!existing)
|
|
43
|
-
return wrap('更新失败(根文档不存在)');
|
|
44
|
-
const updates = {};
|
|
45
|
-
if (decoded.title !== undefined)
|
|
46
|
-
updates.summary = decoded.title;
|
|
47
|
-
if (decoded.description !== undefined)
|
|
48
|
-
updates.content = decoded.description;
|
|
49
|
-
const doc = await client().updateDoc('/', updates);
|
|
50
|
-
return wrap(doc ? '✅ 项目介绍已更新' : '更新失败');
|
|
51
|
-
}));
|
|
52
20
|
}
|
package/dist/tools/rules.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* kg_get_rules, kg_save_rules, kg_get_rules_meta, kg_save_rules_meta
|
|
4
|
-
* kg_get_global_rules_meta, kg_save_global_rules_meta
|
|
2
|
+
* 📏 kg_rules (6→1)
|
|
3
|
+
* 合并: kg_get_rules, kg_save_rules, kg_get_rules_meta, kg_save_rules_meta
|
|
4
|
+
* 删除: kg_get_global_rules_meta, kg_save_global_rules_meta (管理员操作)
|
|
5
5
|
*/
|
|
6
6
|
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
7
7
|
export declare function registerRuleTools(server: McpServer, projectId: string): void;
|
package/dist/tools/rules.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* kg_get_rules, kg_save_rules, kg_get_rules_meta, kg_save_rules_meta
|
|
4
|
-
* kg_get_global_rules_meta, kg_save_global_rules_meta
|
|
2
|
+
* 📏 kg_rules (6→1)
|
|
3
|
+
* 合并: kg_get_rules, kg_save_rules, kg_get_rules_meta, kg_save_rules_meta
|
|
4
|
+
* 删除: kg_get_global_rules_meta, kg_save_global_rules_meta (管理员操作)
|
|
5
5
|
*/
|
|
6
6
|
import { z } from 'zod';
|
|
7
7
|
import { getClient } from '../storage/httpClient.js';
|
|
@@ -9,117 +9,95 @@ import { decodeObjectStrings, getRules, RULE_TYPE_LABELS } from '../utils.js';
|
|
|
9
9
|
import { wrap, safeTool, crossPrefix } from './shared.js';
|
|
10
10
|
export function registerRuleTools(server, projectId) {
|
|
11
11
|
const client = () => getClient();
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (args.ruleType) {
|
|
20
|
-
const rules = await client().crossGetRules(args.targetProject, args.ruleType);
|
|
21
|
-
if (rules.length === 0) {
|
|
22
|
-
const label = crossMeta[args.ruleType]?.label || args.ruleType;
|
|
23
|
-
return wrap(`暂无${label}规则(项目: ${args.targetProject})`);
|
|
24
|
-
}
|
|
25
|
-
return wrap(`${crossPrefix(args.targetProject)}${rules.join('\n')}`);
|
|
26
|
-
}
|
|
27
|
-
const types = Object.keys(crossMeta).length > 0 ? Object.keys(crossMeta) : Object.keys(RULE_TYPE_LABELS);
|
|
28
|
-
const allRules = [];
|
|
29
|
-
for (const type of types) {
|
|
30
|
-
const rules = await client().crossGetRules(args.targetProject, type);
|
|
31
|
-
if (rules.length > 0) {
|
|
32
|
-
const label = crossMeta[type]?.label || RULE_TYPE_LABELS[type] || type;
|
|
33
|
-
allRules.push(`## ${label}\n${rules.join('\n')}`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
if (allRules.length === 0)
|
|
37
|
-
return wrap(`暂无项目规则(项目: ${args.targetProject})`);
|
|
38
|
-
return wrap(`${crossPrefix(args.targetProject)}${allRules.join('\n\n')}`);
|
|
39
|
-
}
|
|
40
|
-
const rules = await getRules(projectId, args.ruleType || undefined);
|
|
41
|
-
if (!rules || rules.trim() === '') {
|
|
42
|
-
const meta = await client().getRulesMeta();
|
|
43
|
-
const typeName = args.ruleType ? (meta[args.ruleType]?.label || args.ruleType) : '项目';
|
|
44
|
-
return wrap(`暂无${typeName}规则`);
|
|
45
|
-
}
|
|
46
|
-
return wrap(rules);
|
|
47
|
-
}));
|
|
48
|
-
// 保存项目规则 (自动合并,去重追加)
|
|
49
|
-
server.tool('kg_save_rules', '保存单个类型的项目规则(自动合并:已有规则保留,新规则去重追加)', {
|
|
50
|
-
ruleType: z.string().describe('规则类型(如 userStyles, codeStyle, reviewRules, testRules, unitTests, 或自定义类型)'),
|
|
51
|
-
rules: z.array(z.string()).describe('规则数组')
|
|
52
|
-
}, async (args) => safeTool(async () => {
|
|
53
|
-
const decoded = decodeObjectStrings(args);
|
|
54
|
-
// appendRules 逻辑内联(原 httpClient 包装函数)
|
|
55
|
-
const existing = await client().getRulesApi(decoded.ruleType);
|
|
56
|
-
const existingSet = new Set(existing.map(r => r.trim()));
|
|
57
|
-
const toAdd = decoded.rules.filter(r => !existingSet.has(r.trim()));
|
|
58
|
-
const merged = [...existing, ...toAdd];
|
|
59
|
-
const success = await client().saveRulesApi(decoded.ruleType, merged);
|
|
60
|
-
if (!success)
|
|
61
|
-
return wrap('❌ 保存失败');
|
|
62
|
-
const meta = await client().getRulesMeta();
|
|
63
|
-
const label = meta[decoded.ruleType]?.label || decoded.ruleType;
|
|
64
|
-
return wrap(`✅ ${label}已保存 (新增${toAdd.length}条, 共${merged.length}条)`);
|
|
65
|
-
}));
|
|
66
|
-
// 获取规则触发配置
|
|
67
|
-
server.tool('kg_get_rules_meta', '获取规则触发配置(所有类型的标签、关键词、触发数)。用于查看/编辑 hooks 触发条件', {}, async () => safeTool(async () => {
|
|
68
|
-
const meta = await client().getRulesMeta();
|
|
69
|
-
if (Object.keys(meta).length === 0)
|
|
70
|
-
return wrap('暂无规则配置');
|
|
71
|
-
const lines = Object.entries(meta).map(([type, m]) => {
|
|
72
|
-
const kw = m.keywords.length > 0 ? m.keywords.join(', ') : '(无)';
|
|
73
|
-
const trigger = m.always ? '始终触发' : `关键词≥${m.min_hits}: ${kw}`;
|
|
74
|
-
return `- **${m.label}** (${type}): ${trigger}`;
|
|
75
|
-
});
|
|
76
|
-
return wrap(`规则触发配置:\n\n${lines.join('\n')}`);
|
|
77
|
-
}));
|
|
78
|
-
// 保存规则触发配置 (自动合并)
|
|
79
|
-
server.tool('kg_save_rules_meta', '保存规则触发配置(自动合并:已有类型更新,新类型创建,其他类型不受影响)', {
|
|
12
|
+
server.tool('kg_rules', '📏 项目规则管理 — 读取或保存代码风格、审查规则等。action: get(读取规则)|save(保存规则)|get_meta(读取触发配置)|save_meta(保存触发配置)', {
|
|
13
|
+
action: z.enum(['get', 'save', 'get_meta', 'save_meta'])
|
|
14
|
+
.describe('操作类型'),
|
|
15
|
+
ruleType: z.string().optional()
|
|
16
|
+
.describe('规则类型(如 userStyles, codeStyle, reviewRules)。get/save 时使用,不传则获取全部'),
|
|
17
|
+
rules: z.array(z.string()).optional()
|
|
18
|
+
.describe('save 时的规则数组'),
|
|
80
19
|
meta: z.record(z.string(), z.object({
|
|
81
20
|
label: z.string().describe('规则显示名称'),
|
|
82
21
|
keywords: z.array(z.string()).default([]).describe('触发关键词列表'),
|
|
83
22
|
min_hits: z.number().default(1).describe('最低触发关键词数'),
|
|
84
|
-
always: z.boolean().default(false).describe('是否始终触发
|
|
85
|
-
})).describe('
|
|
23
|
+
always: z.boolean().default(false).describe('是否始终触发')
|
|
24
|
+
})).optional().describe('save_meta 时的触发配置映射'),
|
|
25
|
+
targetProject: z.string().optional()
|
|
26
|
+
.describe('跨项目读取 (get)'),
|
|
86
27
|
}, async (args) => safeTool(async () => {
|
|
87
|
-
const decoded = decodeObjectStrings(args
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
28
|
+
const decoded = decodeObjectStrings(args);
|
|
29
|
+
switch (decoded.action) {
|
|
30
|
+
case 'get': {
|
|
31
|
+
if (decoded.targetProject) {
|
|
32
|
+
const crossMeta = await client().crossGetRulesMeta(decoded.targetProject);
|
|
33
|
+
if (decoded.ruleType) {
|
|
34
|
+
const rules = await client().crossGetRules(decoded.targetProject, decoded.ruleType);
|
|
35
|
+
if (rules.length === 0) {
|
|
36
|
+
const label = crossMeta[decoded.ruleType]?.label || decoded.ruleType;
|
|
37
|
+
return wrap(`暂无${label}规则(项目: ${decoded.targetProject})`);
|
|
38
|
+
}
|
|
39
|
+
return wrap(`${crossPrefix(decoded.targetProject)}${rules.join('\n')}`);
|
|
40
|
+
}
|
|
41
|
+
const types = Object.keys(crossMeta).length > 0 ? Object.keys(crossMeta) : Object.keys(RULE_TYPE_LABELS);
|
|
42
|
+
const allRules = [];
|
|
43
|
+
for (const type of types) {
|
|
44
|
+
const rules = await client().crossGetRules(decoded.targetProject, type);
|
|
45
|
+
if (rules.length > 0) {
|
|
46
|
+
const label = crossMeta[type]?.label || RULE_TYPE_LABELS[type] || type;
|
|
47
|
+
allRules.push(`## ${label}\n${rules.join('\n')}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (allRules.length === 0)
|
|
51
|
+
return wrap(`暂无项目规则(项目: ${decoded.targetProject})`);
|
|
52
|
+
return wrap(`${crossPrefix(decoded.targetProject)}${allRules.join('\n\n')}`);
|
|
53
|
+
}
|
|
54
|
+
const rules = await getRules(projectId, decoded.ruleType || undefined);
|
|
55
|
+
if (!rules || rules.trim() === '') {
|
|
56
|
+
const meta = await client().getRulesMeta();
|
|
57
|
+
const typeName = decoded.ruleType ? (meta[decoded.ruleType]?.label || decoded.ruleType) : '项目';
|
|
58
|
+
return wrap(`暂无${typeName}规则`);
|
|
59
|
+
}
|
|
60
|
+
return wrap(rules);
|
|
61
|
+
}
|
|
62
|
+
case 'save': {
|
|
63
|
+
if (!decoded.ruleType)
|
|
64
|
+
return wrap('❌ save 需要 ruleType');
|
|
65
|
+
if (!decoded.rules)
|
|
66
|
+
return wrap('❌ save 需要 rules 数组');
|
|
67
|
+
const existing = await client().getRulesApi(decoded.ruleType);
|
|
68
|
+
const existingSet = new Set(existing.map(r => r.trim()));
|
|
69
|
+
const toAdd = decoded.rules.filter((r) => !existingSet.has(r.trim()));
|
|
70
|
+
const merged = [...existing, ...toAdd];
|
|
71
|
+
const success = await client().saveRulesApi(decoded.ruleType, merged);
|
|
72
|
+
if (!success)
|
|
73
|
+
return wrap('❌ 保存失败');
|
|
74
|
+
const meta = await client().getRulesMeta();
|
|
75
|
+
const label = meta[decoded.ruleType]?.label || decoded.ruleType;
|
|
76
|
+
return wrap(`✅ ${label}已保存 (新增${toAdd.length}条, 共${merged.length}条)`);
|
|
77
|
+
}
|
|
78
|
+
case 'get_meta': {
|
|
79
|
+
const meta = await client().getRulesMeta();
|
|
80
|
+
if (Object.keys(meta).length === 0)
|
|
81
|
+
return wrap('暂无规则配置');
|
|
82
|
+
const lines = Object.entries(meta).map(([type, m]) => {
|
|
83
|
+
const kw = m.keywords.length > 0 ? m.keywords.join(', ') : '(无)';
|
|
84
|
+
const trigger = m.always ? '始终触发' : `关键词≥${m.min_hits}: ${kw}`;
|
|
85
|
+
return `- **${m.label}** (${type}): ${trigger}`;
|
|
86
|
+
});
|
|
87
|
+
return wrap(`规则触发配置:\n\n${lines.join('\n')}`);
|
|
88
|
+
}
|
|
89
|
+
case 'save_meta': {
|
|
90
|
+
if (!decoded.meta)
|
|
91
|
+
return wrap('❌ save_meta 需要 meta');
|
|
92
|
+
const existing = await client().getRulesMeta();
|
|
93
|
+
const merged = { ...existing, ...decoded.meta };
|
|
94
|
+
const success = await client().saveRulesMeta(merged);
|
|
95
|
+
if (!success)
|
|
96
|
+
return wrap('❌ 保存失败');
|
|
97
|
+
return wrap(`✅ 触发配置已保存 (更新${Object.keys(decoded.meta).length}个类型, 共${Object.keys(merged).length}个类型)`);
|
|
98
|
+
}
|
|
99
|
+
default:
|
|
100
|
+
return wrap(`❌ 未知 action: ${decoded.action}`);
|
|
101
|
+
}
|
|
124
102
|
}));
|
|
125
103
|
}
|
package/dist/tools/tasks.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* task_create, task_get, task_update, task_archive
|
|
2
|
+
* 📝 kg_task (4→1)
|
|
3
|
+
* 合并: task_create, task_get, task_update, task_archive
|
|
4
4
|
*/
|
|
5
5
|
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
6
6
|
export declare function registerTaskTools(server: McpServer, projectId: string, user: string): void;
|
package/dist/tools/tasks.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* task_create, task_get, task_update, task_archive
|
|
2
|
+
* 📝 kg_task (4→1)
|
|
3
|
+
* 合并: task_create, task_get, task_update, task_archive
|
|
4
4
|
*/
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { getClient } from '../storage/httpClient.js';
|
|
@@ -8,79 +8,102 @@ import { decodeObjectStrings } from '../utils.js';
|
|
|
8
8
|
import { wrap, safeTool } from './shared.js';
|
|
9
9
|
export function registerTaskTools(server, projectId, user) {
|
|
10
10
|
const client = () => getClient();
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
server.tool('kg_task', '📝 任务管理 — 创建、查询、更新进展、归档。action: create(创建)|get(查询)|update(添加日志)|archive(归档)', {
|
|
12
|
+
action: z.enum(['create', 'get', 'update', 'archive'])
|
|
13
|
+
.describe('操作类型'),
|
|
14
|
+
title: z.string().optional()
|
|
15
|
+
.describe('任务标题 (create/get)'),
|
|
16
|
+
description: z.string().optional()
|
|
17
|
+
.describe('任务描述Markdown (create)'),
|
|
18
|
+
goals: z.array(z.string()).optional()
|
|
19
|
+
.describe('目标清单 (create)'),
|
|
20
|
+
taskId: z.string().optional()
|
|
21
|
+
.describe('任务ID (update/archive)'),
|
|
22
|
+
log_type: z.enum(['progress', 'issue', 'solution', 'reference']).optional()
|
|
23
|
+
.describe('日志类型 (update)'),
|
|
24
|
+
content: z.string().optional()
|
|
25
|
+
.describe('日志内容Markdown (update)'),
|
|
26
|
+
summary: z.string().optional()
|
|
27
|
+
.describe('经验总结Markdown (archive)'),
|
|
28
|
+
difficulties: z.array(z.string()).optional()
|
|
29
|
+
.describe('遇到的困难 (archive)'),
|
|
30
|
+
solutions: z.array(z.string()).optional()
|
|
31
|
+
.describe('解决方案 (archive)'),
|
|
32
|
+
status: z.enum(['active', 'archived', 'all']).optional()
|
|
33
|
+
.describe('状态筛选 (get, 默认all)'),
|
|
16
34
|
}, async (args) => safeTool(async () => {
|
|
17
35
|
const decoded = decodeObjectStrings(args);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
switch (decoded.action) {
|
|
37
|
+
case 'create': {
|
|
38
|
+
if (!decoded.title)
|
|
39
|
+
return wrap('❌ create 需要 title');
|
|
40
|
+
if (!decoded.description)
|
|
41
|
+
return wrap('❌ create 需要 description');
|
|
42
|
+
const task = await client().createTask({
|
|
43
|
+
title: decoded.title,
|
|
44
|
+
description: decoded.description,
|
|
45
|
+
goals: decoded.goals || []
|
|
46
|
+
}, user);
|
|
47
|
+
return wrap(JSON.stringify(task, null, 2));
|
|
48
|
+
}
|
|
49
|
+
case 'get': {
|
|
50
|
+
if (!decoded.title)
|
|
51
|
+
return wrap('❌ get 需要 title');
|
|
52
|
+
const filterStatus = decoded.status || 'all';
|
|
53
|
+
const searchTitle = decoded.title.toLowerCase();
|
|
54
|
+
let tasks;
|
|
55
|
+
if (filterStatus === 'all') {
|
|
56
|
+
const [active, archived] = await Promise.all([
|
|
57
|
+
client().listTasks('active'),
|
|
58
|
+
client().listTasks('archived')
|
|
59
|
+
]);
|
|
60
|
+
tasks = [...active, ...archived];
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
tasks = await client().listTasks(filterStatus);
|
|
64
|
+
}
|
|
65
|
+
const matched = tasks.filter(t => t.title.toLowerCase().includes(searchTitle));
|
|
66
|
+
if (matched.length === 0)
|
|
67
|
+
return wrap(`未找到匹配 "${decoded.title}" 的任务`);
|
|
68
|
+
if (matched.length === 1) {
|
|
69
|
+
const task = await client().getTask(matched[0].id);
|
|
70
|
+
return wrap(task ? JSON.stringify(task, null, 2) : '任务详情获取失败');
|
|
71
|
+
}
|
|
72
|
+
const list = matched.map(t => ({
|
|
73
|
+
id: t.id, title: t.title, status: t.status,
|
|
74
|
+
creator: t.creator, created_at: t.created_at
|
|
75
|
+
}));
|
|
76
|
+
return wrap(`找到 ${matched.length} 个匹配任务:\n${JSON.stringify(list, null, 2)}\n\n请提供更精确的任务名称`);
|
|
77
|
+
}
|
|
78
|
+
case 'update': {
|
|
79
|
+
if (!decoded.taskId)
|
|
80
|
+
return wrap('❌ update 需要 taskId');
|
|
81
|
+
if (!decoded.log_type)
|
|
82
|
+
return wrap('❌ update 需要 log_type');
|
|
83
|
+
if (!decoded.content)
|
|
84
|
+
return wrap('❌ update 需要 content');
|
|
85
|
+
const task = await client().addTaskLog(decoded.taskId, decoded.log_type, decoded.content);
|
|
86
|
+
if (!task)
|
|
87
|
+
return wrap('更新失败(任务不存在或已归档)');
|
|
88
|
+
return wrap(`✅ 日志已添加,任务共有 ${task.logs.length} 条日志`);
|
|
89
|
+
}
|
|
90
|
+
case 'archive': {
|
|
91
|
+
if (!decoded.taskId)
|
|
92
|
+
return wrap('❌ archive 需要 taskId');
|
|
93
|
+
if (!decoded.summary)
|
|
94
|
+
return wrap('❌ archive 需要 summary');
|
|
95
|
+
const task = await client().completeTask(decoded.taskId, {
|
|
96
|
+
summary: decoded.summary,
|
|
97
|
+
difficulties: decoded.difficulties || [],
|
|
98
|
+
solutions: decoded.solutions || [],
|
|
99
|
+
references: []
|
|
100
|
+
});
|
|
101
|
+
if (!task)
|
|
102
|
+
return wrap('归档失败(任务不存在或已归档)');
|
|
103
|
+
return wrap(`✅ 任务已归档: ${task.title}`);
|
|
104
|
+
}
|
|
105
|
+
default:
|
|
106
|
+
return wrap(`❌ 未知 action: ${decoded.action}`);
|
|
42
107
|
}
|
|
43
|
-
const matched = tasks.filter(t => t.title.toLowerCase().includes(searchTitle));
|
|
44
|
-
if (matched.length === 0)
|
|
45
|
-
return wrap(`未找到匹配 "${args.title}" 的任务`);
|
|
46
|
-
if (matched.length === 1) {
|
|
47
|
-
const task = await client().getTask(matched[0].id);
|
|
48
|
-
return wrap(task ? JSON.stringify(task, null, 2) : '任务详情获取失败');
|
|
49
|
-
}
|
|
50
|
-
const list = matched.map(t => ({
|
|
51
|
-
id: t.id, title: t.title, status: t.status,
|
|
52
|
-
creator: t.creator, created_at: t.created_at
|
|
53
|
-
}));
|
|
54
|
-
return wrap(`找到 ${matched.length} 个匹配任务:\n${JSON.stringify(list, null, 2)}\n\n请提供更精确的任务名称`);
|
|
55
|
-
}));
|
|
56
|
-
// 更新任务
|
|
57
|
-
server.tool('task_update', '更新任务(添加进展日志)', {
|
|
58
|
-
taskId: z.string().describe('任务ID'),
|
|
59
|
-
log_type: z.enum(['progress', 'issue', 'solution', 'reference']).describe('日志类型: progress=进展, issue=问题, solution=方案, reference=参考'),
|
|
60
|
-
content: z.string().describe('日志内容(Markdown)')
|
|
61
|
-
}, async (args) => safeTool(async () => {
|
|
62
|
-
const decoded = decodeObjectStrings(args);
|
|
63
|
-
const task = await client().addTaskLog(args.taskId, decoded.log_type, decoded.content);
|
|
64
|
-
if (!task)
|
|
65
|
-
return wrap('更新失败(任务不存在或已归档)');
|
|
66
|
-
return wrap(`✅ 日志已添加,任务共有 ${task.logs.length} 条日志`);
|
|
67
|
-
}));
|
|
68
|
-
// 归档任务
|
|
69
|
-
server.tool('task_archive', '归档任务(完成并填写经验总结)', {
|
|
70
|
-
taskId: z.string().describe('任务ID'),
|
|
71
|
-
summary: z.string().describe('经验总结(Markdown)'),
|
|
72
|
-
difficulties: z.array(z.string()).optional().describe('遇到的困难'),
|
|
73
|
-
solutions: z.array(z.string()).optional().describe('解决方案')
|
|
74
|
-
}, async (args) => safeTool(async () => {
|
|
75
|
-
const decoded = decodeObjectStrings(args);
|
|
76
|
-
const task = await client().completeTask(args.taskId, {
|
|
77
|
-
summary: decoded.summary,
|
|
78
|
-
difficulties: decoded.difficulties || [],
|
|
79
|
-
solutions: decoded.solutions || [],
|
|
80
|
-
references: []
|
|
81
|
-
});
|
|
82
|
-
if (!task)
|
|
83
|
-
return wrap('归档失败(任务不存在或已归档)');
|
|
84
|
-
return wrap(`✅ 任务已归档: ${task.title}`);
|
|
85
108
|
}));
|
|
86
109
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PPDocs Agent V2 — Web Config Server
|
|
3
|
+
* 多项目管理 + 智能匹配 + 知识图谱预览 + MCP 安装
|
|
4
|
+
*/
|
|
5
|
+
export interface ProjectBinding {
|
|
6
|
+
localDir: string;
|
|
7
|
+
localName: string;
|
|
8
|
+
remote: {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
password: string;
|
|
12
|
+
};
|
|
13
|
+
sync: {
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
intervalSec: number;
|
|
16
|
+
};
|
|
17
|
+
createdAt: string;
|
|
18
|
+
}
|
|
19
|
+
export interface AgentConfig {
|
|
20
|
+
host: string;
|
|
21
|
+
port: number;
|
|
22
|
+
webPort: number;
|
|
23
|
+
projects: ProjectBinding[];
|
|
24
|
+
}
|
|
25
|
+
export declare function loadAgentConfig(): AgentConfig | null;
|
|
26
|
+
export declare function saveAgentConfig(config: AgentConfig): void;
|
|
27
|
+
interface ProjectStatus {
|
|
28
|
+
connected: boolean;
|
|
29
|
+
syncStatus: string;
|
|
30
|
+
lastSync: Date | null;
|
|
31
|
+
docCount?: number;
|
|
32
|
+
}
|
|
33
|
+
interface AgentState {
|
|
34
|
+
hostConnected: boolean;
|
|
35
|
+
projectStatus: Map<string, ProjectStatus>;
|
|
36
|
+
onBind?: (project: ProjectBinding) => void;
|
|
37
|
+
onUnbind?: (remoteId: string) => void;
|
|
38
|
+
}
|
|
39
|
+
export declare function getAgentState(): AgentState;
|
|
40
|
+
export declare function setAgentState(partial: Partial<AgentState>): void;
|
|
41
|
+
export declare function setProjectStatus(remoteId: string, status: Partial<ProjectStatus>): void;
|
|
42
|
+
export declare function startWebServer(webPort: number): void;
|
|
43
|
+
export {};
|