mcp-probe-kit 3.0.17 → 3.0.19
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/README.md +77 -50
- package/build/lib/__tests__/agents-md-template.unit.test.d.ts +1 -0
- package/build/lib/__tests__/agents-md-template.unit.test.js +25 -0
- package/build/lib/__tests__/project-context-layout.unit.test.d.ts +1 -0
- package/build/lib/__tests__/project-context-layout.unit.test.js +80 -0
- package/build/lib/agents-md-template.d.ts +25 -0
- package/build/lib/agents-md-template.js +55 -0
- package/build/lib/memory-orchestration.d.ts +3 -1
- package/build/lib/memory-orchestration.js +71 -5
- package/build/lib/merge-agents-md.d.ts +6 -0
- package/build/lib/merge-agents-md.js +51 -0
- package/build/lib/project-context-layout.d.ts +78 -0
- package/build/lib/project-context-layout.js +350 -0
- package/build/lib/workspace-root.js +6 -1
- package/build/resources/ui-ux-data/metadata.json +1 -1
- package/build/schemas/index.d.ts +25 -3
- package/build/schemas/memory-tools.d.ts +1 -1
- package/build/schemas/memory-tools.js +1 -1
- package/build/schemas/project-tools.d.ts +24 -2
- package/build/schemas/project-tools.js +24 -2
- package/build/tools/__tests__/code_insight.unit.test.js +3 -3
- package/build/tools/__tests__/init_project_context.unit.test.js +32 -21
- package/build/tools/__tests__/start_feature.unit.test.js +2 -1
- package/build/tools/code_insight.js +11 -9
- package/build/tools/init_project_context.js +563 -506
- package/build/tools/start_bugfix.js +254 -248
- package/build/tools/start_feature.js +137 -131
- package/build/tools/start_ui.js +402 -402
- package/docs/.mcp-probe/layout.json +11 -0
- package/docs/i18n/en.json +36 -5
- package/docs/i18n/ja.json +9 -2
- package/docs/i18n/ko.json +9 -2
- package/docs/i18n/zh-CN.json +36 -5
- package/docs/memory-local-setup.md +314 -0
- package/docs/memory-local-setup.zh-CN.md +280 -0
- package/docs/pages/getting-started.html +249 -31
- package/package.json +1 -1
|
@@ -3,6 +3,9 @@ import { okStructured } from "../lib/response.js";
|
|
|
3
3
|
import { renderOrchestrationHeader } from "../lib/orchestration-guidance.js";
|
|
4
4
|
import { detectProjectType } from "../lib/project-detector.js";
|
|
5
5
|
import { resolveWorkspaceRoot, isLikelyProjectNamedRelativePath, buildProjectRootRetryHint } from "../lib/workspace-root.js";
|
|
6
|
+
import { detectDocumentLocale, layoutAbsPath, legacyProjectContextExists, parseLayoutArgsFromRecord, resolveProjectContextLayout, toPosixPath, writeLayoutManifest, } from "../lib/project-context-layout.js";
|
|
7
|
+
import { mergeAgentsMdBlock } from "../lib/merge-agents-md.js";
|
|
8
|
+
import { generateAgentsMdInner } from "../lib/agents-md-template.js";
|
|
6
9
|
import * as fs from 'fs';
|
|
7
10
|
import * as path from 'path';
|
|
8
11
|
/**
|
|
@@ -18,9 +21,6 @@ import * as path from 'path';
|
|
|
18
21
|
*/
|
|
19
22
|
// 默认文档目录
|
|
20
23
|
const DEFAULT_DOCS_DIR = "docs";
|
|
21
|
-
function toPosixPath(value) {
|
|
22
|
-
return value.replace(/\\/g, "/");
|
|
23
|
-
}
|
|
24
24
|
function renderPlanSteps(steps) {
|
|
25
25
|
return steps
|
|
26
26
|
.map((step, index) => {
|
|
@@ -139,137 +139,183 @@ function generateDevGuide(docs) {
|
|
|
139
139
|
result += `\n### ${category}\n${items.join('\n')}\n`;
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
|
-
result += `\n### 理解代码图谱
|
|
143
|
-
- **代码图谱洞察**: [latest.md](./graph-insights/latest.md) - 需要快速理解模块依赖、调用链、影响面时优先查看
|
|
142
|
+
result += `\n### 理解代码图谱
|
|
143
|
+
- **代码图谱洞察**: [latest.md](./graph-insights/latest.md) - 需要快速理解模块依赖、调用链、影响面时优先查看
|
|
144
144
|
`;
|
|
145
145
|
return result || '\n### 开发指南\n查看上面的文档导航,根据需要选择对应的文档。\n';
|
|
146
146
|
}
|
|
147
147
|
/**
|
|
148
148
|
* 生成项目上下文文档指导
|
|
149
149
|
*/
|
|
150
|
-
async function generateProjectContext(
|
|
150
|
+
async function generateProjectContext(layout, projectRoot) {
|
|
151
151
|
try {
|
|
152
|
-
// 检测项目类型
|
|
153
152
|
const resolvedRoot = resolveWorkspaceRoot(projectRoot);
|
|
154
|
-
const
|
|
155
|
-
const
|
|
153
|
+
const projectRootAbs = layout.projectRoot || resolvedRoot;
|
|
154
|
+
const detection = detectProjectType(projectRootAbs);
|
|
155
|
+
const projectInfo = getProjectInfo(projectRootAbs);
|
|
156
156
|
const docs = getDocumentList(detection.category);
|
|
157
|
-
const
|
|
158
|
-
const
|
|
159
|
-
const
|
|
157
|
+
const docsDir = layout.contextRoot;
|
|
158
|
+
const modularExists = legacyProjectContextExists(projectRootAbs, layout);
|
|
159
|
+
const agentsPath = toPosixPath(layoutAbsPath(layout, layout.indexPath));
|
|
160
160
|
const graphDocs = {
|
|
161
|
-
latestMarkdownFilePath:
|
|
162
|
-
latestJsonFilePath:
|
|
161
|
+
latestMarkdownFilePath: layout.latestMarkdownPath,
|
|
162
|
+
latestJsonFilePath: layout.latestJsonPath,
|
|
163
163
|
};
|
|
164
|
+
const existingAgentsRaw = fs.existsSync(layoutAbsPath(layout, layout.indexPath))
|
|
165
|
+
? fs.readFileSync(layoutAbsPath(layout, layout.indexPath), "utf8")
|
|
166
|
+
: undefined;
|
|
167
|
+
const locale = detectDocumentLocale(projectRootAbs, existingAgentsRaw);
|
|
168
|
+
const agentsInner = generateAgentsMdInner({
|
|
169
|
+
layout,
|
|
170
|
+
locale,
|
|
171
|
+
projectName: projectInfo.name,
|
|
172
|
+
projectVersion: projectInfo.version,
|
|
173
|
+
description: projectInfo.description,
|
|
174
|
+
language: detection.language,
|
|
175
|
+
framework: detection.framework,
|
|
176
|
+
category: detection.category,
|
|
177
|
+
docs,
|
|
178
|
+
projectRootPosix: layout.projectRootPosix,
|
|
179
|
+
graphReady: false,
|
|
180
|
+
});
|
|
181
|
+
const mergedAgents = mergeAgentsMdBlock(existingAgentsRaw, agentsInner);
|
|
182
|
+
const manifestWritten = writeLayoutManifest(projectRootAbs, layout);
|
|
183
|
+
const codeInsightArgs = JSON.stringify({
|
|
184
|
+
mode: "auto",
|
|
185
|
+
project_root: layout.projectRootPosix,
|
|
186
|
+
docs_dir: docsDir,
|
|
187
|
+
});
|
|
188
|
+
const modularOutputs = docs.map((doc) => `${layout.modularDir}/${doc.file}`);
|
|
164
189
|
const plan = {
|
|
165
|
-
mode:
|
|
166
|
-
steps:
|
|
190
|
+
mode: "delegated",
|
|
191
|
+
steps: modularExists
|
|
167
192
|
? [
|
|
168
193
|
{
|
|
169
|
-
id:
|
|
170
|
-
action: `检测到现有 ${
|
|
194
|
+
id: "bootstrap-code-insight",
|
|
195
|
+
action: `检测到现有 ${layout.legacyIndexPath},跳过重写分类文档,调用 code_insight 补齐图谱`,
|
|
196
|
+
outputs: [graphDocs.latestMarkdownFilePath, graphDocs.latestJsonFilePath],
|
|
197
|
+
note: `调用参数: ${codeInsightArgs}`,
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
id: "persist-graph-docs",
|
|
201
|
+
action: `执行 code_insight 的 delegated plan,写入 ${layout.graphDir}/`,
|
|
171
202
|
outputs: [graphDocs.latestMarkdownFilePath, graphDocs.latestJsonFilePath],
|
|
172
|
-
note:
|
|
203
|
+
note: "保留现有 project-context 分类文档",
|
|
173
204
|
},
|
|
174
205
|
{
|
|
175
|
-
id:
|
|
176
|
-
action:
|
|
177
|
-
outputs: [
|
|
178
|
-
note:
|
|
206
|
+
id: "finalize-agents-md",
|
|
207
|
+
action: `将下方 agentsMdTemplate 写入 ${layout.indexPath}(mcp-probe 块置顶,保留用户原有内容)`,
|
|
208
|
+
outputs: [layout.indexPath],
|
|
209
|
+
note: `mergeMode: ${mergedAgents.mergeMode};layout manifest 已由服务端写入 ${manifestWritten}`,
|
|
179
210
|
},
|
|
180
211
|
]
|
|
181
212
|
: [
|
|
182
213
|
{
|
|
183
|
-
id:
|
|
184
|
-
action:
|
|
185
|
-
outputs: [
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
214
|
+
id: "write-modular-docs",
|
|
215
|
+
action: `先创建 ${layout.legacyIndexPath}(文档索引),再创建 ${layout.modularDir}/ 分类文档`,
|
|
216
|
+
outputs: [layout.legacyIndexPath, ...modularOutputs],
|
|
217
|
+
note: modularExists
|
|
218
|
+
? "跳过:索引与分类文档已存在"
|
|
219
|
+
: "project-context.md 是细节入口;AGENTS.md 仅含 MCP 规则",
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
id: "bootstrap-code-insight",
|
|
223
|
+
action: "调用 code_insight 做整体图谱分析",
|
|
224
|
+
outputs: [graphDocs.latestMarkdownFilePath, graphDocs.latestJsonFilePath],
|
|
225
|
+
note: `调用参数: ${codeInsightArgs}`,
|
|
190
226
|
},
|
|
191
227
|
{
|
|
192
|
-
id:
|
|
193
|
-
action:
|
|
228
|
+
id: "persist-graph-docs",
|
|
229
|
+
action: `执行 code_insight 的 delegated plan,写入 ${layout.graphDir}/`,
|
|
194
230
|
outputs: [graphDocs.latestMarkdownFilePath, graphDocs.latestJsonFilePath],
|
|
195
|
-
note: `调用参数建议: {"mode":"auto","project_root":"${toPosixPath(resolvedRoot)}","docs_dir":"${docsDir}"}`,
|
|
196
231
|
},
|
|
197
232
|
{
|
|
198
|
-
id:
|
|
199
|
-
action:
|
|
200
|
-
outputs: [
|
|
201
|
-
note:
|
|
233
|
+
id: "finalize-agents-md",
|
|
234
|
+
action: `将下方 agentsMdTemplate 写入 ${layout.indexPath}(mcp-probe 块置顶)`,
|
|
235
|
+
outputs: [layout.indexPath],
|
|
236
|
+
note: `mergeMode: ${mergedAgents.mergeMode};manifest 已写入 ${manifestWritten}`,
|
|
202
237
|
},
|
|
203
238
|
],
|
|
204
239
|
};
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
projectContextExists,
|
|
240
|
+
const guide = generateGuideText(detection, projectInfo, docs, layout, resolvedRoot, {
|
|
241
|
+
modularExists,
|
|
208
242
|
});
|
|
209
243
|
const header = renderOrchestrationHeader({
|
|
210
|
-
tool:
|
|
211
|
-
goal:
|
|
212
|
-
?
|
|
213
|
-
:
|
|
214
|
-
tasks:
|
|
215
|
-
? [
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
'将 graph-insights 挂回 project-context.md 索引',
|
|
224
|
-
],
|
|
225
|
-
notes: [`项目根目录: ${toPosixPath(resolvedRoot)}`, `文档目录: ${docsDir}`],
|
|
244
|
+
tool: "init_project_context",
|
|
245
|
+
goal: modularExists
|
|
246
|
+
? "补齐图谱与 AGENTS.md 入口(保留现有分类文档)"
|
|
247
|
+
: "生成项目上下文、图谱入口与 AGENTS.md 操作规则",
|
|
248
|
+
tasks: modularExists
|
|
249
|
+
? ["保留现有分类文档", "code_insight 生成图谱", `写入 ${layout.indexPath}`]
|
|
250
|
+
: ["写分类文档", "code_insight", `写入 ${layout.indexPath}`],
|
|
251
|
+
notes: [
|
|
252
|
+
`项目根目录: ${toPosixPath(resolvedRoot)}`,
|
|
253
|
+
`上下文目录: ${docsDir}`,
|
|
254
|
+
`索引: ${layout.indexPath}`,
|
|
255
|
+
`layout: ${manifestWritten}(已服务端写入)`,
|
|
256
|
+
],
|
|
226
257
|
});
|
|
227
|
-
// 构建结构化数据
|
|
228
258
|
const structuredData = {
|
|
229
|
-
summary:
|
|
230
|
-
?
|
|
231
|
-
: `生成 ${detection.category}
|
|
259
|
+
summary: modularExists
|
|
260
|
+
? `检测到现有项目上下文,补齐图谱与 ${layout.indexPath}`
|
|
261
|
+
: `生成 ${detection.category} 项目上下文与 ${layout.indexPath}`,
|
|
232
262
|
mode: "modular",
|
|
233
263
|
projectOverview: {
|
|
234
264
|
name: projectInfo.name,
|
|
235
265
|
description: projectInfo.description,
|
|
236
266
|
techStack: detection.framework ? [detection.framework] : [],
|
|
237
|
-
architecture: detection.category
|
|
267
|
+
architecture: detection.category,
|
|
238
268
|
},
|
|
239
269
|
documentation: [
|
|
270
|
+
{ path: layout.indexPath, purpose: "Harness 入口(MCP 触发规则,省 token)" },
|
|
240
271
|
{
|
|
241
|
-
path:
|
|
242
|
-
purpose:
|
|
272
|
+
path: layout.legacyIndexPath,
|
|
273
|
+
purpose: "项目上下文索引(写代码前优先读,链到分类文档)",
|
|
243
274
|
},
|
|
244
|
-
...docs.map(doc => ({
|
|
245
|
-
path: `${
|
|
246
|
-
purpose: doc.purpose
|
|
275
|
+
...docs.map((doc) => ({
|
|
276
|
+
path: `${layout.modularDir}/${doc.file}`,
|
|
277
|
+
purpose: doc.purpose,
|
|
247
278
|
})),
|
|
248
279
|
{
|
|
249
|
-
path:
|
|
250
|
-
purpose:
|
|
280
|
+
path: layout.latestMarkdownPath,
|
|
281
|
+
purpose: "最新代码图谱洞察(由 code_insight 维护)",
|
|
251
282
|
},
|
|
252
283
|
{
|
|
253
|
-
path:
|
|
254
|
-
purpose:
|
|
284
|
+
path: layout.latestJsonPath,
|
|
285
|
+
purpose: "最新代码图谱结构化结果(由 code_insight 维护)",
|
|
255
286
|
},
|
|
287
|
+
{ path: layout.manifestPath, purpose: "layout manifest(工具链路径发现)" },
|
|
256
288
|
],
|
|
257
289
|
nextSteps: [
|
|
258
|
-
...(
|
|
259
|
-
|
|
260
|
-
|
|
290
|
+
...(modularExists
|
|
291
|
+
? [`保留 ${layout.legacyIndexPath} 与分类文档`]
|
|
292
|
+
: [`生成 ${layout.modularDir}/ 分类文档`]),
|
|
293
|
+
"调用 code_insight",
|
|
294
|
+
`将 agentsMdTemplate 写入 ${layout.indexPath}`,
|
|
261
295
|
],
|
|
262
296
|
metadata: {
|
|
263
297
|
plan,
|
|
264
298
|
graphDocs,
|
|
265
|
-
|
|
266
|
-
|
|
299
|
+
layout,
|
|
300
|
+
locale,
|
|
301
|
+
agentsMdTemplate: mergedAgents.content,
|
|
302
|
+
agentsMdMergeMode: mergedAgents.mergeMode,
|
|
303
|
+
manifestWritten,
|
|
304
|
+
projectContextFilePath: agentsPath,
|
|
305
|
+
legacyProjectContextExists: modularExists,
|
|
306
|
+
projectContextExists: modularExists,
|
|
267
307
|
},
|
|
268
308
|
};
|
|
269
|
-
return okStructured(`${header}${guide}
|
|
270
|
-
|
|
271
|
-
##
|
|
272
|
-
|
|
309
|
+
return okStructured(`${header}${guide}
|
|
310
|
+
|
|
311
|
+
## AGENTS.md 终稿(finalize-agents-md 使用 fsWrite 写入 \`${layout.indexPath}\`)
|
|
312
|
+
|
|
313
|
+
\`\`\`markdown
|
|
314
|
+
${mergedAgents.content}
|
|
315
|
+
\`\`\`
|
|
316
|
+
|
|
317
|
+
## delegated plan
|
|
318
|
+
${renderPlanSteps(plan.steps)}
|
|
273
319
|
`, structuredData, {
|
|
274
320
|
schema: (await import("../schemas/output/project-tools.js")).ProjectContextSchema,
|
|
275
321
|
});
|
|
@@ -282,157 +328,159 @@ ${renderPlanSteps(plan.steps)}
|
|
|
282
328
|
/**
|
|
283
329
|
* 生成指导文本
|
|
284
330
|
*/
|
|
285
|
-
function generateGuideText(detection, projectInfo, docs,
|
|
331
|
+
function generateGuideText(detection, projectInfo, docs, layout, projectRoot, options) {
|
|
286
332
|
const timestamp = new Date().toISOString();
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
-
|
|
294
|
-
-
|
|
295
|
-
-
|
|
296
|
-
-
|
|
297
|
-
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
├──
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
333
|
+
const docsDir = layout.contextRoot;
|
|
334
|
+
const projectContextExists = options?.modularExists === true;
|
|
335
|
+
return `# 项目上下文文档生成指导
|
|
336
|
+
|
|
337
|
+
## 📊 项目信息
|
|
338
|
+
|
|
339
|
+
- **项目名称**: ${projectInfo.name}
|
|
340
|
+
- **版本**: ${projectInfo.version}
|
|
341
|
+
- **语言**: ${detection.language}
|
|
342
|
+
- **框架**: ${detection.framework || '未检测到'}
|
|
343
|
+
- **类型**: ${detection.category}
|
|
344
|
+
- **置信度**: ${detection.confidence}%
|
|
345
|
+
|
|
346
|
+
## 🔎 当前状态
|
|
347
|
+
|
|
348
|
+
- **${layout.indexPath}**: Agent 入口(finalize-agents-md 写入,mcp-probe 块置顶)
|
|
349
|
+
- **${layout.legacyIndexPath}**: ${projectContextExists ? '已存在(将保留分类文档)' : '将随分类文档一并生成'}
|
|
350
|
+
- **图谱文档**: 需要确保 ${layout.latestMarkdownPath} 与 ${layout.latestJsonPath} 可用
|
|
351
|
+
|
|
352
|
+
## 📋 需要生成的文档
|
|
353
|
+
|
|
354
|
+
请按照以下结构生成 **${docs.length + 1}** 个上下文文档,并为图谱文档预留入口:
|
|
355
|
+
|
|
356
|
+
\`\`\`
|
|
357
|
+
${docsDir}/
|
|
358
|
+
├── project-context.md # 索引文件(必须首先生成)
|
|
359
|
+
└── project-context/ # 分类文档目录
|
|
360
|
+
${docs.map(doc => ` ├── ${doc.file.padEnd(28)} # ${doc.title}`).join('\n')}
|
|
361
|
+
\n${docsDir}/graph-insights/
|
|
362
|
+
├── latest.md # 最近一次 code_insight 的 Markdown 摘要
|
|
363
|
+
└── latest.json # 最近一次 code_insight 的结构化结果
|
|
364
|
+
\`\`\`
|
|
365
|
+
|
|
366
|
+
---
|
|
367
|
+
|
|
368
|
+
## 🎯 生成步骤
|
|
369
|
+
|
|
322
370
|
${projectContextExists
|
|
323
|
-
? `### 已存在项目上下文(仅补图谱)
|
|
324
|
-
|
|
325
|
-
检测到 \`${docsDir}/project-context.md\` 已存在:
|
|
326
|
-
|
|
327
|
-
- **不要重写** 现有 \`${docsDir}/project-context.md\`
|
|
328
|
-
- **不要重写** \`${docsDir}/project-context/\` 下已有分类文档
|
|
329
|
-
- 直接调用 \`code_insight\` 补齐 \`${docsDir}/graph-insights/latest.md\` 与 \`${docsDir}/graph-insights/latest.json\`
|
|
330
|
-
- 仅在 \`project-context.md\` 中补充或刷新图谱入口
|
|
331
|
-
|
|
332
|
-
---
|
|
371
|
+
? `### 已存在项目上下文(仅补图谱)
|
|
372
|
+
|
|
373
|
+
检测到 \`${docsDir}/project-context.md\` 已存在:
|
|
374
|
+
|
|
375
|
+
- **不要重写** 现有 \`${docsDir}/project-context.md\`
|
|
376
|
+
- **不要重写** \`${docsDir}/project-context/\` 下已有分类文档
|
|
377
|
+
- 直接调用 \`code_insight\` 补齐 \`${docsDir}/graph-insights/latest.md\` 与 \`${docsDir}/graph-insights/latest.json\`
|
|
378
|
+
- 仅在 \`project-context.md\` 中补充或刷新图谱入口
|
|
379
|
+
|
|
380
|
+
---
|
|
333
381
|
`
|
|
334
|
-
: ''}
|
|
335
|
-
|
|
336
|
-
### 第一步:生成索引文件(最重要!)
|
|
337
|
-
|
|
338
|
-
**文件**: \`${docsDir}/project-context.md\`
|
|
339
|
-
|
|
340
|
-
这是项目上下文的**灵魂**,必须首先生成。它是所有文档的入口和导航中心。
|
|
341
|
-
|
|
342
|
-
**模板**:
|
|
343
|
-
|
|
344
|
-
\`\`\`markdown
|
|
345
|
-
# ${projectInfo.name} - 项目上下文
|
|
346
|
-
|
|
347
|
-
> 本文档是项目上下文的索引文件,提供项目概览和文档导航。
|
|
348
|
-
|
|
349
|
-
## 📊 项目概览
|
|
350
|
-
|
|
351
|
-
| 属性 | 值 |
|
|
352
|
-
|------|-----|
|
|
353
|
-
| 项目名称 | ${projectInfo.name} |
|
|
354
|
-
| 版本 | ${projectInfo.version} |
|
|
355
|
-
| 语言 | ${detection.language} |
|
|
356
|
-
| 框架 | ${detection.framework || '无'} |
|
|
357
|
-
| 类型 | ${detection.category} |
|
|
358
|
-
| 描述 | ${projectInfo.description || '待补充'} |
|
|
359
|
-
|
|
360
|
-
## 📚 文档导航
|
|
361
|
-
|
|
362
|
-
${docs.map(doc => `### [${doc.title}](./project-context/${doc.file})
|
|
363
|
-
${doc.purpose}
|
|
364
|
-
`).join('\n')}
|
|
365
|
-
### [代码图谱洞察](./graph-insights/latest.md)
|
|
366
|
-
最近一次 code_insight 分析结果,包含模块依赖、调用链和影响面摘要
|
|
367
|
-
|
|
368
|
-
## 🚀 快速开始
|
|
369
|
-
|
|
370
|
-
1. 阅读 [技术栈](./project-context/tech-stack.md) 了解项目使用的技术
|
|
371
|
-
2. 阅读 [架构设计](./project-context/architecture.md) 了解项目结构
|
|
372
|
-
3. 阅读 [代码图谱洞察](./graph-insights/latest.md) 快速理解模块依赖与调用链
|
|
373
|
-
4. 根据需要查看具体的操作指南
|
|
374
|
-
|
|
375
|
-
## 💡 开发时查看对应文档
|
|
376
|
-
|
|
377
|
-
根据你要做的事情,查看对应的文档:
|
|
378
|
-
|
|
379
|
-
${generateDevGuide(docs)}
|
|
380
|
-
|
|
381
|
-
---
|
|
382
|
-
*生成时间: ${timestamp}*
|
|
383
|
-
*生成工具: MCP Probe Kit - init_project_context v2.1*
|
|
384
|
-
\`\`\`
|
|
385
|
-
|
|
386
|
-
${projectContextExists ? '**如果该文件已存在,跳过此步骤,不要覆盖**' : '**使用 fsWrite 创建此文件**'}
|
|
387
|
-
|
|
388
|
-
---
|
|
389
|
-
|
|
390
|
-
### 第二步:生成分类文档
|
|
391
|
-
|
|
392
|
-
${docs.map((doc, index) => generateDocTemplate(doc, index + 2, projectInfo, detection, docsDir)).join('\n\n---\n\n')}
|
|
393
|
-
|
|
394
|
-
---
|
|
395
|
-
|
|
396
|
-
## ✅ 完成标准
|
|
397
|
-
|
|
398
|
-
请确认:
|
|
399
|
-
|
|
400
|
-
- [ ] ${projectContextExists ? '保留现有 project-context 及分类文档,不做覆盖' : `已使用 fsWrite 创建 **${docs.length + 1}** 个文件`}
|
|
401
|
-
- [ ] 索引文件 \`project-context.md\` ${projectContextExists ? '已存在并保留' : '已创建(最重要!)'}
|
|
402
|
-
- [ ] 索引文件已包含 \`graph-insights/latest.md\` 的入口
|
|
403
|
-
- [ ] 所有文档都包含**真实的文件路径**(不是 [xxx] 占位符)
|
|
404
|
-
- [ ] 所有文档都包含**实际的代码示例**(从项目中复制)
|
|
405
|
-
- [ ] 所有步骤都具体可操作
|
|
406
|
-
- [ ] 所有示例都来自项目实际代码
|
|
407
|
-
|
|
408
|
-
---
|
|
409
|
-
|
|
410
|
-
## 🔄 完成文档骨架后立即执行
|
|
411
|
-
|
|
412
|
-
1. 调用 \`code_insight\`
|
|
413
|
-
\`\`\`json
|
|
414
|
-
{
|
|
415
|
-
"mode": "auto",
|
|
416
|
-
"project_root": "${toPosixPath(projectRoot)}",
|
|
417
|
-
"docs_dir": "${docsDir}"
|
|
418
|
-
}
|
|
419
|
-
\`\`\`
|
|
420
|
-
2. 严格执行 \`code_insight\` 返回的 delegated plan
|
|
421
|
-
3. 确保 \`${docsDir}/graph-insights/latest.md\` 和 \`${docsDir}/graph-insights/latest.json\` 已写入
|
|
422
|
-
4. 若已有旧图谱,按 delegated plan 归档时间戳版本
|
|
423
|
-
|
|
424
|
-
---
|
|
425
|
-
|
|
426
|
-
**重要提示**:
|
|
427
|
-
1. **必须从项目中提取真实示例** - 不要编造代码
|
|
428
|
-
2. **路径必须真实存在** - 检查文件是否存在
|
|
429
|
-
3. **步骤必须具体** - 不要写"根据需要修改"这种模糊的话
|
|
430
|
-
4. **代码必须完整** - 不要用 ... 省略
|
|
431
|
-
|
|
432
|
-
---
|
|
433
|
-
|
|
434
|
-
*工具: MCP Probe Kit - init_project_context*
|
|
435
|
-
*版本: 2.1.0*
|
|
382
|
+
: ''}
|
|
383
|
+
|
|
384
|
+
### 第一步:生成索引文件(最重要!)
|
|
385
|
+
|
|
386
|
+
**文件**: \`${docsDir}/project-context.md\`
|
|
387
|
+
|
|
388
|
+
这是项目上下文的**灵魂**,必须首先生成。它是所有文档的入口和导航中心。
|
|
389
|
+
|
|
390
|
+
**模板**:
|
|
391
|
+
|
|
392
|
+
\`\`\`markdown
|
|
393
|
+
# ${projectInfo.name} - 项目上下文
|
|
394
|
+
|
|
395
|
+
> 本文档是项目上下文的索引文件,提供项目概览和文档导航。
|
|
396
|
+
|
|
397
|
+
## 📊 项目概览
|
|
398
|
+
|
|
399
|
+
| 属性 | 值 |
|
|
400
|
+
|------|-----|
|
|
401
|
+
| 项目名称 | ${projectInfo.name} |
|
|
402
|
+
| 版本 | ${projectInfo.version} |
|
|
403
|
+
| 语言 | ${detection.language} |
|
|
404
|
+
| 框架 | ${detection.framework || '无'} |
|
|
405
|
+
| 类型 | ${detection.category} |
|
|
406
|
+
| 描述 | ${projectInfo.description || '待补充'} |
|
|
407
|
+
|
|
408
|
+
## 📚 文档导航
|
|
409
|
+
|
|
410
|
+
${docs.map(doc => `### [${doc.title}](./project-context/${doc.file})
|
|
411
|
+
${doc.purpose}
|
|
412
|
+
`).join('\n')}
|
|
413
|
+
### [代码图谱洞察](./graph-insights/latest.md)
|
|
414
|
+
最近一次 code_insight 分析结果,包含模块依赖、调用链和影响面摘要
|
|
415
|
+
|
|
416
|
+
## 🚀 快速开始
|
|
417
|
+
|
|
418
|
+
1. 阅读 [技术栈](./project-context/tech-stack.md) 了解项目使用的技术
|
|
419
|
+
2. 阅读 [架构设计](./project-context/architecture.md) 了解项目结构
|
|
420
|
+
3. 阅读 [代码图谱洞察](./graph-insights/latest.md) 快速理解模块依赖与调用链
|
|
421
|
+
4. 根据需要查看具体的操作指南
|
|
422
|
+
|
|
423
|
+
## 💡 开发时查看对应文档
|
|
424
|
+
|
|
425
|
+
根据你要做的事情,查看对应的文档:
|
|
426
|
+
|
|
427
|
+
${generateDevGuide(docs)}
|
|
428
|
+
|
|
429
|
+
---
|
|
430
|
+
*生成时间: ${timestamp}*
|
|
431
|
+
*生成工具: MCP Probe Kit - init_project_context v2.1*
|
|
432
|
+
\`\`\`
|
|
433
|
+
|
|
434
|
+
${projectContextExists ? '**如果该文件已存在,跳过此步骤,不要覆盖**' : '**使用 fsWrite 创建此文件**'}
|
|
435
|
+
|
|
436
|
+
---
|
|
437
|
+
|
|
438
|
+
### 第二步:生成分类文档
|
|
439
|
+
|
|
440
|
+
${docs.map((doc, index) => generateDocTemplate(doc, index + 2, projectInfo, detection, docsDir)).join('\n\n---\n\n')}
|
|
441
|
+
|
|
442
|
+
---
|
|
443
|
+
|
|
444
|
+
## ✅ 完成标准
|
|
445
|
+
|
|
446
|
+
请确认:
|
|
447
|
+
|
|
448
|
+
- [ ] ${projectContextExists ? '保留现有 project-context 及分类文档,不做覆盖' : `已使用 fsWrite 创建 **${docs.length + 1}** 个文件`}
|
|
449
|
+
- [ ] 索引文件 \`project-context.md\` ${projectContextExists ? '已存在并保留' : '已创建(最重要!)'}
|
|
450
|
+
- [ ] 索引文件已包含 \`graph-insights/latest.md\` 的入口
|
|
451
|
+
- [ ] 所有文档都包含**真实的文件路径**(不是 [xxx] 占位符)
|
|
452
|
+
- [ ] 所有文档都包含**实际的代码示例**(从项目中复制)
|
|
453
|
+
- [ ] 所有步骤都具体可操作
|
|
454
|
+
- [ ] 所有示例都来自项目实际代码
|
|
455
|
+
|
|
456
|
+
---
|
|
457
|
+
|
|
458
|
+
## 🔄 完成文档骨架后立即执行
|
|
459
|
+
|
|
460
|
+
1. 调用 \`code_insight\`
|
|
461
|
+
\`\`\`json
|
|
462
|
+
{
|
|
463
|
+
"mode": "auto",
|
|
464
|
+
"project_root": "${toPosixPath(projectRoot)}",
|
|
465
|
+
"docs_dir": "${docsDir}"
|
|
466
|
+
}
|
|
467
|
+
\`\`\`
|
|
468
|
+
2. 严格执行 \`code_insight\` 返回的 delegated plan
|
|
469
|
+
3. 确保 \`${docsDir}/graph-insights/latest.md\` 和 \`${docsDir}/graph-insights/latest.json\` 已写入
|
|
470
|
+
4. 若已有旧图谱,按 delegated plan 归档时间戳版本
|
|
471
|
+
|
|
472
|
+
---
|
|
473
|
+
|
|
474
|
+
**重要提示**:
|
|
475
|
+
1. **必须从项目中提取真实示例** - 不要编造代码
|
|
476
|
+
2. **路径必须真实存在** - 检查文件是否存在
|
|
477
|
+
3. **步骤必须具体** - 不要写"根据需要修改"这种模糊的话
|
|
478
|
+
4. **代码必须完整** - 不要用 ... 省略
|
|
479
|
+
|
|
480
|
+
---
|
|
481
|
+
|
|
482
|
+
*工具: MCP Probe Kit - init_project_context*
|
|
483
|
+
*版本: 2.1.0*
|
|
436
484
|
`;
|
|
437
485
|
}
|
|
438
486
|
/**
|
|
@@ -442,286 +490,286 @@ function generateDocTemplate(doc, step, projectInfo, detection, docsDir) {
|
|
|
442
490
|
const timestamp = new Date().toISOString();
|
|
443
491
|
// 根据文档类型生成不同的模板
|
|
444
492
|
const templates = {
|
|
445
|
-
'tech-stack.md': `**文件**: \`${docsDir}/project-context/${doc.file}\`
|
|
446
|
-
|
|
447
|
-
**用途**: ${doc.purpose}
|
|
448
|
-
|
|
449
|
-
**模板**:
|
|
450
|
-
|
|
451
|
-
\`\`\`markdown
|
|
452
|
-
# 技术栈
|
|
453
|
-
|
|
454
|
-
> 本文档描述 ${projectInfo.name} 的技术栈信息。
|
|
455
|
-
|
|
456
|
-
## 基本信息
|
|
457
|
-
|
|
458
|
-
| 属性 | 值 |
|
|
459
|
-
|------|-----|
|
|
460
|
-
| 项目名称 | ${projectInfo.name} |
|
|
461
|
-
| 版本 | ${projectInfo.version} |
|
|
462
|
-
| 语言 | ${detection.language} |
|
|
463
|
-
| 框架 | ${detection.framework || '无'} |
|
|
464
|
-
|
|
465
|
-
## 技术栈详情
|
|
466
|
-
|
|
467
|
-
### 核心技术
|
|
468
|
-
|
|
469
|
-
| 类别 | 技术 | 版本 |
|
|
470
|
-
|------|------|------|
|
|
471
|
-
| 语言 | [从 package.json 或配置文件中提取] | [版本] |
|
|
472
|
-
| 运行时 | [Node.js/Python/Java 等] | [版本] |
|
|
473
|
-
| 框架 | [主要框架] | [版本] |
|
|
474
|
-
|
|
475
|
-
### 开发工具
|
|
476
|
-
|
|
477
|
-
| 类别 | 工具 | 用途 |
|
|
478
|
-
|------|------|------|
|
|
479
|
-
| 构建工具 | [如 TypeScript, Webpack] | [用途] |
|
|
480
|
-
| 测试框架 | [如 Jest, Vitest] | [用途] |
|
|
481
|
-
| 代码检查 | [如 ESLint, Prettier] | [用途] |
|
|
482
|
-
|
|
483
|
-
### 主要依赖
|
|
484
|
-
|
|
485
|
-
列出 5-10 个最重要的依赖包及其用途。
|
|
486
|
-
|
|
487
|
-
---
|
|
488
|
-
*返回索引: [../project-context.md](../project-context.md)*
|
|
489
|
-
\`\`\`
|
|
490
|
-
|
|
491
|
-
**填写指导**:
|
|
492
|
-
1. 读取 \`package.json\` 获取依赖信息
|
|
493
|
-
2. 读取 \`tsconfig.json\` 或其他配置文件
|
|
494
|
-
3. 列出最重要的 5-10 个依赖包
|
|
493
|
+
'tech-stack.md': `**文件**: \`${docsDir}/project-context/${doc.file}\`
|
|
494
|
+
|
|
495
|
+
**用途**: ${doc.purpose}
|
|
496
|
+
|
|
497
|
+
**模板**:
|
|
498
|
+
|
|
499
|
+
\`\`\`markdown
|
|
500
|
+
# 技术栈
|
|
501
|
+
|
|
502
|
+
> 本文档描述 ${projectInfo.name} 的技术栈信息。
|
|
503
|
+
|
|
504
|
+
## 基本信息
|
|
505
|
+
|
|
506
|
+
| 属性 | 值 |
|
|
507
|
+
|------|-----|
|
|
508
|
+
| 项目名称 | ${projectInfo.name} |
|
|
509
|
+
| 版本 | ${projectInfo.version} |
|
|
510
|
+
| 语言 | ${detection.language} |
|
|
511
|
+
| 框架 | ${detection.framework || '无'} |
|
|
512
|
+
|
|
513
|
+
## 技术栈详情
|
|
514
|
+
|
|
515
|
+
### 核心技术
|
|
516
|
+
|
|
517
|
+
| 类别 | 技术 | 版本 |
|
|
518
|
+
|------|------|------|
|
|
519
|
+
| 语言 | [从 package.json 或配置文件中提取] | [版本] |
|
|
520
|
+
| 运行时 | [Node.js/Python/Java 等] | [版本] |
|
|
521
|
+
| 框架 | [主要框架] | [版本] |
|
|
522
|
+
|
|
523
|
+
### 开发工具
|
|
524
|
+
|
|
525
|
+
| 类别 | 工具 | 用途 |
|
|
526
|
+
|------|------|------|
|
|
527
|
+
| 构建工具 | [如 TypeScript, Webpack] | [用途] |
|
|
528
|
+
| 测试框架 | [如 Jest, Vitest] | [用途] |
|
|
529
|
+
| 代码检查 | [如 ESLint, Prettier] | [用途] |
|
|
530
|
+
|
|
531
|
+
### 主要依赖
|
|
532
|
+
|
|
533
|
+
列出 5-10 个最重要的依赖包及其用途。
|
|
534
|
+
|
|
535
|
+
---
|
|
536
|
+
*返回索引: [../project-context.md](../project-context.md)*
|
|
537
|
+
\`\`\`
|
|
538
|
+
|
|
539
|
+
**填写指导**:
|
|
540
|
+
1. 读取 \`package.json\` 获取依赖信息
|
|
541
|
+
2. 读取 \`tsconfig.json\` 或其他配置文件
|
|
542
|
+
3. 列出最重要的 5-10 个依赖包
|
|
495
543
|
4. 说明每个依赖的用途`,
|
|
496
|
-
'architecture.md': `**文件**: \`${docsDir}/project-context/${doc.file}\`
|
|
497
|
-
|
|
498
|
-
**用途**: ${doc.purpose}
|
|
499
|
-
|
|
500
|
-
**模板**:
|
|
501
|
-
|
|
502
|
-
\`\`\`markdown
|
|
503
|
-
# 架构设计
|
|
504
|
-
|
|
505
|
-
> 本文档描述 ${projectInfo.name} 的架构和项目结构。
|
|
506
|
-
|
|
507
|
-
## 项目结构
|
|
508
|
-
|
|
509
|
-
\`\`\`
|
|
510
|
-
[使用 listDirectory 工具生成目录树,深度 2-3 层]
|
|
511
|
-
\`\`\`
|
|
512
|
-
|
|
513
|
-
## 主要目录说明
|
|
514
|
-
|
|
515
|
-
| 目录 | 用途 |
|
|
516
|
-
|------|------|
|
|
517
|
-
| [目录名] | [从实际项目中分析得出] |
|
|
518
|
-
|
|
519
|
-
## 入口文件
|
|
520
|
-
|
|
521
|
-
- **主入口**: \`[实际的入口文件路径,如 src/index.ts]\`
|
|
522
|
-
- **配置文件**: \`[如 package.json, tsconfig.json]\`
|
|
523
|
-
|
|
524
|
-
## 架构模式
|
|
525
|
-
|
|
526
|
-
- **项目类型**: ${detection.category}
|
|
527
|
-
- **设计模式**: [从代码中识别,如 MVC, 工具集合, 插件系统等]
|
|
528
|
-
- **模块划分**: [说明主要模块及其职责]
|
|
529
|
-
|
|
530
|
-
## 核心模块
|
|
531
|
-
|
|
532
|
-
### [模块名称]
|
|
533
|
-
- **位置**: \`[实际路径]\`
|
|
534
|
-
- **职责**: [模块功能]
|
|
535
|
-
- **主要文件**: [列出 2-3 个关键文件]
|
|
536
|
-
|
|
537
|
-
---
|
|
538
|
-
*返回索引: [../project-context.md](../project-context.md)*
|
|
539
|
-
\`\`\`
|
|
540
|
-
|
|
541
|
-
**填写指导**:
|
|
542
|
-
1. 使用 listDirectory 工具查看项目结构
|
|
543
|
-
2. 读取主要目录下的文件
|
|
544
|
-
3. 识别项目的组织方式
|
|
544
|
+
'architecture.md': `**文件**: \`${docsDir}/project-context/${doc.file}\`
|
|
545
|
+
|
|
546
|
+
**用途**: ${doc.purpose}
|
|
547
|
+
|
|
548
|
+
**模板**:
|
|
549
|
+
|
|
550
|
+
\`\`\`markdown
|
|
551
|
+
# 架构设计
|
|
552
|
+
|
|
553
|
+
> 本文档描述 ${projectInfo.name} 的架构和项目结构。
|
|
554
|
+
|
|
555
|
+
## 项目结构
|
|
556
|
+
|
|
557
|
+
\`\`\`
|
|
558
|
+
[使用 listDirectory 工具生成目录树,深度 2-3 层]
|
|
559
|
+
\`\`\`
|
|
560
|
+
|
|
561
|
+
## 主要目录说明
|
|
562
|
+
|
|
563
|
+
| 目录 | 用途 |
|
|
564
|
+
|------|------|
|
|
565
|
+
| [目录名] | [从实际项目中分析得出] |
|
|
566
|
+
|
|
567
|
+
## 入口文件
|
|
568
|
+
|
|
569
|
+
- **主入口**: \`[实际的入口文件路径,如 src/index.ts]\`
|
|
570
|
+
- **配置文件**: \`[如 package.json, tsconfig.json]\`
|
|
571
|
+
|
|
572
|
+
## 架构模式
|
|
573
|
+
|
|
574
|
+
- **项目类型**: ${detection.category}
|
|
575
|
+
- **设计模式**: [从代码中识别,如 MVC, 工具集合, 插件系统等]
|
|
576
|
+
- **模块划分**: [说明主要模块及其职责]
|
|
577
|
+
|
|
578
|
+
## 核心模块
|
|
579
|
+
|
|
580
|
+
### [模块名称]
|
|
581
|
+
- **位置**: \`[实际路径]\`
|
|
582
|
+
- **职责**: [模块功能]
|
|
583
|
+
- **主要文件**: [列出 2-3 个关键文件]
|
|
584
|
+
|
|
585
|
+
---
|
|
586
|
+
*返回索引: [../project-context.md](../project-context.md)*
|
|
587
|
+
\`\`\`
|
|
588
|
+
|
|
589
|
+
**填写指导**:
|
|
590
|
+
1. 使用 listDirectory 工具查看项目结构
|
|
591
|
+
2. 读取主要目录下的文件
|
|
592
|
+
3. 识别项目的组织方式
|
|
545
593
|
4. 找出核心模块和关键文件`,
|
|
546
|
-
'how-to-add-api.md': `**文件**: \`${docsDir}/project-context/${doc.file}\`
|
|
547
|
-
|
|
548
|
-
**用途**: ${doc.purpose}
|
|
549
|
-
|
|
550
|
-
**模板**:
|
|
551
|
-
|
|
552
|
-
\`\`\`markdown
|
|
553
|
-
# 如何添加新接口
|
|
554
|
-
|
|
555
|
-
> 本文档指导如何在 ${projectInfo.name} 中添加新的 API 接口。
|
|
556
|
-
|
|
557
|
-
## 第一步:找到路由定义位置
|
|
558
|
-
|
|
559
|
-
项目的路由定义在:\`[实际路径,如 src/routes/, src/api/]\`
|
|
560
|
-
|
|
561
|
-
**现有示例**(从项目中找一个真实的路由文件):
|
|
562
|
-
\`\`\`[语言]
|
|
563
|
-
[复制一个实际的路由定义代码]
|
|
564
|
-
\`\`\`
|
|
565
|
-
|
|
566
|
-
## 第二步:创建新路由
|
|
567
|
-
|
|
568
|
-
1. 在 \`[路径]\` 目录下创建文件 \`[命名规范].ts\`
|
|
569
|
-
2. 定义路由:
|
|
570
|
-
|
|
571
|
-
\`\`\`[语言]
|
|
572
|
-
[基于项目实际代码风格的示例]
|
|
573
|
-
\`\`\`
|
|
574
|
-
|
|
575
|
-
## 第三步:实现业务逻辑
|
|
576
|
-
|
|
577
|
-
业务逻辑通常在:\`[实际路径,如 src/controllers/, src/services/]\`
|
|
578
|
-
|
|
579
|
-
**现有示例**:
|
|
580
|
-
\`\`\`[语言]
|
|
581
|
-
[复制一个实际的 controller/service 代码]
|
|
582
|
-
\`\`\`
|
|
583
|
-
|
|
584
|
-
## 第四步:数据验证
|
|
585
|
-
|
|
586
|
-
项目使用 [验证库名称] 进行数据验证。
|
|
587
|
-
|
|
588
|
-
**示例**:
|
|
589
|
-
\`\`\`[语言]
|
|
590
|
-
[从项目中找一个验证示例]
|
|
591
|
-
\`\`\`
|
|
592
|
-
|
|
593
|
-
## 第五步:注册路由
|
|
594
|
-
|
|
595
|
-
在 \`[实际文件路径]\` 中注册新路由:
|
|
596
|
-
|
|
597
|
-
\`\`\`[语言]
|
|
598
|
-
[实际的路由注册代码]
|
|
599
|
-
\`\`\`
|
|
600
|
-
|
|
601
|
-
## 第六步:测试
|
|
602
|
-
|
|
603
|
-
运行测试命令:\`[实际命令,如 npm test]\`
|
|
604
|
-
|
|
605
|
-
---
|
|
606
|
-
*返回索引: [../project-context.md](../project-context.md)*
|
|
607
|
-
\`\`\`
|
|
608
|
-
|
|
609
|
-
**填写指导**:
|
|
610
|
-
1. 搜索 src/routes, src/api, src/controllers 等目录
|
|
611
|
-
2. 找 2-3 个现有的 API 接口作为参考
|
|
612
|
-
3. 复制实际的代码示例(不要编造)
|
|
594
|
+
'how-to-add-api.md': `**文件**: \`${docsDir}/project-context/${doc.file}\`
|
|
595
|
+
|
|
596
|
+
**用途**: ${doc.purpose}
|
|
597
|
+
|
|
598
|
+
**模板**:
|
|
599
|
+
|
|
600
|
+
\`\`\`markdown
|
|
601
|
+
# 如何添加新接口
|
|
602
|
+
|
|
603
|
+
> 本文档指导如何在 ${projectInfo.name} 中添加新的 API 接口。
|
|
604
|
+
|
|
605
|
+
## 第一步:找到路由定义位置
|
|
606
|
+
|
|
607
|
+
项目的路由定义在:\`[实际路径,如 src/routes/, src/api/]\`
|
|
608
|
+
|
|
609
|
+
**现有示例**(从项目中找一个真实的路由文件):
|
|
610
|
+
\`\`\`[语言]
|
|
611
|
+
[复制一个实际的路由定义代码]
|
|
612
|
+
\`\`\`
|
|
613
|
+
|
|
614
|
+
## 第二步:创建新路由
|
|
615
|
+
|
|
616
|
+
1. 在 \`[路径]\` 目录下创建文件 \`[命名规范].ts\`
|
|
617
|
+
2. 定义路由:
|
|
618
|
+
|
|
619
|
+
\`\`\`[语言]
|
|
620
|
+
[基于项目实际代码风格的示例]
|
|
621
|
+
\`\`\`
|
|
622
|
+
|
|
623
|
+
## 第三步:实现业务逻辑
|
|
624
|
+
|
|
625
|
+
业务逻辑通常在:\`[实际路径,如 src/controllers/, src/services/]\`
|
|
626
|
+
|
|
627
|
+
**现有示例**:
|
|
628
|
+
\`\`\`[语言]
|
|
629
|
+
[复制一个实际的 controller/service 代码]
|
|
630
|
+
\`\`\`
|
|
631
|
+
|
|
632
|
+
## 第四步:数据验证
|
|
633
|
+
|
|
634
|
+
项目使用 [验证库名称] 进行数据验证。
|
|
635
|
+
|
|
636
|
+
**示例**:
|
|
637
|
+
\`\`\`[语言]
|
|
638
|
+
[从项目中找一个验证示例]
|
|
639
|
+
\`\`\`
|
|
640
|
+
|
|
641
|
+
## 第五步:注册路由
|
|
642
|
+
|
|
643
|
+
在 \`[实际文件路径]\` 中注册新路由:
|
|
644
|
+
|
|
645
|
+
\`\`\`[语言]
|
|
646
|
+
[实际的路由注册代码]
|
|
647
|
+
\`\`\`
|
|
648
|
+
|
|
649
|
+
## 第六步:测试
|
|
650
|
+
|
|
651
|
+
运行测试命令:\`[实际命令,如 npm test]\`
|
|
652
|
+
|
|
653
|
+
---
|
|
654
|
+
*返回索引: [../project-context.md](../project-context.md)*
|
|
655
|
+
\`\`\`
|
|
656
|
+
|
|
657
|
+
**填写指导**:
|
|
658
|
+
1. 搜索 src/routes, src/api, src/controllers 等目录
|
|
659
|
+
2. 找 2-3 个现有的 API 接口作为参考
|
|
660
|
+
3. 复制实际的代码示例(不要编造)
|
|
613
661
|
4. 说明项目特定的命名和组织方式`,
|
|
614
|
-
'how-to-new-page.md': `**文件**: \`${docsDir}/project-context/${doc.file}\`
|
|
615
|
-
|
|
616
|
-
**用途**: ${doc.purpose}
|
|
617
|
-
|
|
618
|
-
**模板**:
|
|
619
|
-
|
|
620
|
-
\`\`\`markdown
|
|
621
|
-
# 如何创建新页面
|
|
622
|
-
|
|
623
|
-
> 本文档指导如何在 ${projectInfo.name} 中创建新的页面组件。
|
|
624
|
-
|
|
625
|
-
## 第一步:找到页面目录
|
|
626
|
-
|
|
627
|
-
项目的页面组件在:\`[实际路径,如 src/pages/, src/views/, app/]\`
|
|
628
|
-
|
|
629
|
-
**现有示例**(从项目中找一个真实的页面):
|
|
630
|
-
\`\`\`[语言]
|
|
631
|
-
[复制一个实际的页面组件代码]
|
|
632
|
-
\`\`\`
|
|
633
|
-
|
|
634
|
-
## 第二步:创建页面文件
|
|
635
|
-
|
|
636
|
-
1. 在 \`[路径]\` 目录下创建 \`[命名规范].tsx\`
|
|
637
|
-
2. 定义组件:
|
|
638
|
-
|
|
639
|
-
\`\`\`[语言]
|
|
640
|
-
[基于项目实际代码风格的示例]
|
|
641
|
-
\`\`\`
|
|
642
|
-
|
|
643
|
-
## 第三步:配置路由
|
|
644
|
-
|
|
645
|
-
项目使用 [路由库名称]。
|
|
646
|
-
|
|
647
|
-
**路由配置位置**: \`[实际文件路径]\`
|
|
648
|
-
|
|
649
|
-
**示例**:
|
|
650
|
-
\`\`\`[语言]
|
|
651
|
-
[从项目中找路由配置示例]
|
|
652
|
-
\`\`\`
|
|
653
|
-
|
|
654
|
-
## 第四步:获取数据
|
|
655
|
-
|
|
656
|
-
项目使用 [数据获取方式,如 useEffect, getServerSideProps, loader]。
|
|
657
|
-
|
|
658
|
-
**示例**:
|
|
659
|
-
\`\`\`[语言]
|
|
660
|
-
[从项目中找数据获取示例]
|
|
661
|
-
\`\`\`
|
|
662
|
-
|
|
663
|
-
## 第五步:编写样式
|
|
664
|
-
|
|
665
|
-
项目使用 [样式方案,如 CSS Modules, Tailwind, styled-components]。
|
|
666
|
-
|
|
667
|
-
**示例**:
|
|
668
|
-
\`\`\`[语言]
|
|
669
|
-
[从项目中找样式示例]
|
|
670
|
-
\`\`\`
|
|
671
|
-
|
|
672
|
-
---
|
|
673
|
-
*返回索引: [../project-context.md](../project-context.md)*
|
|
674
|
-
\`\`\`
|
|
675
|
-
|
|
676
|
-
**填写指导**:
|
|
677
|
-
1. 搜索 src/pages, src/views, app 等目录
|
|
678
|
-
2. 找 1-2 个现有页面作为参考
|
|
679
|
-
3. 复制实际的组件代码
|
|
662
|
+
'how-to-new-page.md': `**文件**: \`${docsDir}/project-context/${doc.file}\`
|
|
663
|
+
|
|
664
|
+
**用途**: ${doc.purpose}
|
|
665
|
+
|
|
666
|
+
**模板**:
|
|
667
|
+
|
|
668
|
+
\`\`\`markdown
|
|
669
|
+
# 如何创建新页面
|
|
670
|
+
|
|
671
|
+
> 本文档指导如何在 ${projectInfo.name} 中创建新的页面组件。
|
|
672
|
+
|
|
673
|
+
## 第一步:找到页面目录
|
|
674
|
+
|
|
675
|
+
项目的页面组件在:\`[实际路径,如 src/pages/, src/views/, app/]\`
|
|
676
|
+
|
|
677
|
+
**现有示例**(从项目中找一个真实的页面):
|
|
678
|
+
\`\`\`[语言]
|
|
679
|
+
[复制一个实际的页面组件代码]
|
|
680
|
+
\`\`\`
|
|
681
|
+
|
|
682
|
+
## 第二步:创建页面文件
|
|
683
|
+
|
|
684
|
+
1. 在 \`[路径]\` 目录下创建 \`[命名规范].tsx\`
|
|
685
|
+
2. 定义组件:
|
|
686
|
+
|
|
687
|
+
\`\`\`[语言]
|
|
688
|
+
[基于项目实际代码风格的示例]
|
|
689
|
+
\`\`\`
|
|
690
|
+
|
|
691
|
+
## 第三步:配置路由
|
|
692
|
+
|
|
693
|
+
项目使用 [路由库名称]。
|
|
694
|
+
|
|
695
|
+
**路由配置位置**: \`[实际文件路径]\`
|
|
696
|
+
|
|
697
|
+
**示例**:
|
|
698
|
+
\`\`\`[语言]
|
|
699
|
+
[从项目中找路由配置示例]
|
|
700
|
+
\`\`\`
|
|
701
|
+
|
|
702
|
+
## 第四步:获取数据
|
|
703
|
+
|
|
704
|
+
项目使用 [数据获取方式,如 useEffect, getServerSideProps, loader]。
|
|
705
|
+
|
|
706
|
+
**示例**:
|
|
707
|
+
\`\`\`[语言]
|
|
708
|
+
[从项目中找数据获取示例]
|
|
709
|
+
\`\`\`
|
|
710
|
+
|
|
711
|
+
## 第五步:编写样式
|
|
712
|
+
|
|
713
|
+
项目使用 [样式方案,如 CSS Modules, Tailwind, styled-components]。
|
|
714
|
+
|
|
715
|
+
**示例**:
|
|
716
|
+
\`\`\`[语言]
|
|
717
|
+
[从项目中找样式示例]
|
|
718
|
+
\`\`\`
|
|
719
|
+
|
|
720
|
+
---
|
|
721
|
+
*返回索引: [../project-context.md](../project-context.md)*
|
|
722
|
+
\`\`\`
|
|
723
|
+
|
|
724
|
+
**填写指导**:
|
|
725
|
+
1. 搜索 src/pages, src/views, app 等目录
|
|
726
|
+
2. 找 1-2 个现有页面作为参考
|
|
727
|
+
3. 复制实际的组件代码
|
|
680
728
|
4. 说明路由配置方式`
|
|
681
729
|
};
|
|
682
730
|
// 如果没有特定模板,使用通用模板
|
|
683
|
-
const template = templates[doc.file] || `**文件**: \`${docsDir}/project-context/${doc.file}\`
|
|
684
|
-
|
|
685
|
-
**用途**: ${doc.purpose}
|
|
686
|
-
|
|
687
|
-
**模板**:
|
|
688
|
-
|
|
689
|
-
\`\`\`markdown
|
|
690
|
-
# ${doc.title}
|
|
691
|
-
|
|
692
|
-
> 本文档描述 ${projectInfo.name} 的 ${doc.title.toLowerCase()}。
|
|
693
|
-
|
|
694
|
-
## 概述
|
|
695
|
-
|
|
696
|
-
[简要说明本文档的内容]
|
|
697
|
-
|
|
698
|
-
## 详细步骤
|
|
699
|
-
|
|
700
|
-
### 第一步:[步骤名称]
|
|
701
|
-
|
|
702
|
-
[具体说明]
|
|
703
|
-
|
|
704
|
-
**示例**:
|
|
705
|
-
\`\`\`[语言]
|
|
706
|
-
[从项目中提取的实际代码]
|
|
707
|
-
\`\`\`
|
|
708
|
-
|
|
709
|
-
### 第二步:[步骤名称]
|
|
710
|
-
|
|
711
|
-
[具体说明]
|
|
712
|
-
|
|
713
|
-
---
|
|
714
|
-
*返回索引: [../project-context.md](../project-context.md)*
|
|
715
|
-
\`\`\`
|
|
716
|
-
|
|
717
|
-
**填写指导**:
|
|
718
|
-
1. 分析项目相关代码
|
|
719
|
-
2. 提取真实示例
|
|
731
|
+
const template = templates[doc.file] || `**文件**: \`${docsDir}/project-context/${doc.file}\`
|
|
732
|
+
|
|
733
|
+
**用途**: ${doc.purpose}
|
|
734
|
+
|
|
735
|
+
**模板**:
|
|
736
|
+
|
|
737
|
+
\`\`\`markdown
|
|
738
|
+
# ${doc.title}
|
|
739
|
+
|
|
740
|
+
> 本文档描述 ${projectInfo.name} 的 ${doc.title.toLowerCase()}。
|
|
741
|
+
|
|
742
|
+
## 概述
|
|
743
|
+
|
|
744
|
+
[简要说明本文档的内容]
|
|
745
|
+
|
|
746
|
+
## 详细步骤
|
|
747
|
+
|
|
748
|
+
### 第一步:[步骤名称]
|
|
749
|
+
|
|
750
|
+
[具体说明]
|
|
751
|
+
|
|
752
|
+
**示例**:
|
|
753
|
+
\`\`\`[语言]
|
|
754
|
+
[从项目中提取的实际代码]
|
|
755
|
+
\`\`\`
|
|
756
|
+
|
|
757
|
+
### 第二步:[步骤名称]
|
|
758
|
+
|
|
759
|
+
[具体说明]
|
|
760
|
+
|
|
761
|
+
---
|
|
762
|
+
*返回索引: [../project-context.md](../project-context.md)*
|
|
763
|
+
\`\`\`
|
|
764
|
+
|
|
765
|
+
**填写指导**:
|
|
766
|
+
1. 分析项目相关代码
|
|
767
|
+
2. 提取真实示例
|
|
720
768
|
3. 编写具体步骤`;
|
|
721
|
-
return `### 第${step}步:${doc.title}
|
|
722
|
-
|
|
723
|
-
${template}
|
|
724
|
-
|
|
769
|
+
return `### 第${step}步:${doc.title}
|
|
770
|
+
|
|
771
|
+
${template}
|
|
772
|
+
|
|
725
773
|
**使用 fsWrite 创建此文件**`;
|
|
726
774
|
}
|
|
727
775
|
/**
|
|
@@ -736,16 +784,18 @@ export async function initProjectContext(args) {
|
|
|
736
784
|
let docsDir = DEFAULT_DOCS_DIR;
|
|
737
785
|
let projectRoot = resolveWorkspaceRoot();
|
|
738
786
|
try {
|
|
739
|
-
// 智能参数解析,支持自然语言输入
|
|
740
787
|
const parsedArgs = parseArgs(args, {
|
|
741
788
|
defaultValues: {
|
|
742
789
|
docs_dir: DEFAULT_DOCS_DIR,
|
|
743
|
-
project_root: resolveWorkspaceRoot()
|
|
790
|
+
project_root: resolveWorkspaceRoot(),
|
|
744
791
|
},
|
|
745
792
|
primaryField: "docs_dir",
|
|
746
793
|
fieldAliases: {
|
|
747
|
-
docs_dir: ["dir", "
|
|
748
|
-
project_root: ["root", "path", "项目路径"]
|
|
794
|
+
docs_dir: ["dir", "directory", "文档目录", "docsDir"],
|
|
795
|
+
project_root: ["root", "path", "项目路径"],
|
|
796
|
+
output: ["index", "index_path", "agents_md"],
|
|
797
|
+
output_dir: ["outputDir"],
|
|
798
|
+
index_style: ["indexStyle", "style"],
|
|
749
799
|
},
|
|
750
800
|
});
|
|
751
801
|
docsDir = getString(parsedArgs.docs_dir) || DEFAULT_DOCS_DIR;
|
|
@@ -764,8 +814,15 @@ export async function initProjectContext(args) {
|
|
|
764
814
|
},
|
|
765
815
|
};
|
|
766
816
|
}
|
|
767
|
-
|
|
768
|
-
|
|
817
|
+
const layoutArgs = parseLayoutArgsFromRecord({
|
|
818
|
+
docs_dir: docsDir,
|
|
819
|
+
output: getString(parsedArgs.output),
|
|
820
|
+
output_dir: getString(parsedArgs.output_dir),
|
|
821
|
+
filename: getString(parsedArgs.filename),
|
|
822
|
+
index_style: getString(parsedArgs.index_style),
|
|
823
|
+
});
|
|
824
|
+
const layout = resolveProjectContextLayout(projectRoot, layoutArgs);
|
|
825
|
+
return await generateProjectContext(layout, projectRoot);
|
|
769
826
|
}
|
|
770
827
|
catch (error) {
|
|
771
828
|
const errorMessage = error instanceof Error ? error.message : String(error);
|