@ppdocs/mcp 3.1.5 → 3.1.7
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 +51 -16
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -161,15 +161,15 @@ async function initProject(opts) {
|
|
|
161
161
|
hasIdeDir = true;
|
|
162
162
|
}
|
|
163
163
|
if (detectedIdes.includes('cursor')) {
|
|
164
|
-
installCursorTemplates(cwd);
|
|
164
|
+
installCursorTemplates(cwd, apiUrl);
|
|
165
165
|
hasIdeDir = true;
|
|
166
166
|
}
|
|
167
167
|
if (detectedIdes.includes('antigravity')) {
|
|
168
|
-
installAntigravityTemplates(cwd);
|
|
168
|
+
installAntigravityTemplates(cwd, apiUrl);
|
|
169
169
|
hasIdeDir = true;
|
|
170
170
|
}
|
|
171
171
|
if (detectedIdes.includes('kiro')) {
|
|
172
|
-
installKiroTemplates(cwd);
|
|
172
|
+
installKiroTemplates(cwd, apiUrl);
|
|
173
173
|
hasIdeDir = true;
|
|
174
174
|
}
|
|
175
175
|
// Fallback behavior: if no specific IDE config directories found
|
|
@@ -185,7 +185,7 @@ async function initProject(opts) {
|
|
|
185
185
|
const registered = autoRegisterMcp(apiUrl, opts.user);
|
|
186
186
|
// 如果没有检测到任何 AI CLI,并且也没有检测到配置文件夹,创建 .mcp.json 作为备用
|
|
187
187
|
if (!registered && !hasIdeDir) {
|
|
188
|
-
createMcpJson(cwd);
|
|
188
|
+
createMcpJson(cwd, apiUrl);
|
|
189
189
|
}
|
|
190
190
|
// --from: 从模板项目拉取 IDE 配置文件
|
|
191
191
|
if (opts.from) {
|
|
@@ -344,7 +344,7 @@ function autoRegisterMcp(apiUrl, user) {
|
|
|
344
344
|
return true;
|
|
345
345
|
}
|
|
346
346
|
/** 在指定路径创建或更新 mcp.json 配置 */
|
|
347
|
-
function createMcpConfigAt(mcpPath,
|
|
347
|
+
function createMcpConfigAt(mcpPath, apiUrl) {
|
|
348
348
|
let mcpConfig = {};
|
|
349
349
|
if (fs.existsSync(mcpPath)) {
|
|
350
350
|
try {
|
|
@@ -356,9 +356,13 @@ function createMcpConfigAt(mcpPath, autoCreatedTemplate) {
|
|
|
356
356
|
}
|
|
357
357
|
// Windows 需要 cmd /c 包装才能执行 npx
|
|
358
358
|
const isWindows = process.platform === 'win32';
|
|
359
|
-
const ppdocsServer =
|
|
360
|
-
|
|
361
|
-
:
|
|
359
|
+
const ppdocsServer = {
|
|
360
|
+
command: isWindows ? 'cmd' : 'npx',
|
|
361
|
+
args: isWindows ? ['/c', 'npx', '-y', '@ppdocs/mcp@latest'] : ['-y', '@ppdocs/mcp@latest'],
|
|
362
|
+
env: {
|
|
363
|
+
"PPDOCS_API_URL": apiUrl
|
|
364
|
+
}
|
|
365
|
+
};
|
|
362
366
|
mcpConfig.mcpServers = {
|
|
363
367
|
...(mcpConfig.mcpServers || {}),
|
|
364
368
|
"ppdocs-kg": ppdocsServer,
|
|
@@ -372,8 +376,8 @@ function createMcpConfigAt(mcpPath, autoCreatedTemplate) {
|
|
|
372
376
|
console.log(`✅ Configured MCP in ${mcpPath}`);
|
|
373
377
|
}
|
|
374
378
|
/** 创建 .mcp.json (手动配置备用) */
|
|
375
|
-
function createMcpJson(cwd) {
|
|
376
|
-
createMcpConfigAt(path.join(cwd, '.mcp.json'));
|
|
379
|
+
function createMcpJson(cwd, apiUrl) {
|
|
380
|
+
createMcpConfigAt(path.join(cwd, '.mcp.json'), apiUrl);
|
|
377
381
|
}
|
|
378
382
|
/** 递归复制目录 */
|
|
379
383
|
function copyDirRecursive(src, dest) {
|
|
@@ -496,9 +500,9 @@ function generateAgentsMd(cwd) {
|
|
|
496
500
|
}
|
|
497
501
|
}
|
|
498
502
|
/** 安装 Cursor 模板 */
|
|
499
|
-
function installCursorTemplates(cwd) {
|
|
503
|
+
function installCursorTemplates(cwd, apiUrl) {
|
|
500
504
|
// 1. 生成 Cursor MCP 配置
|
|
501
|
-
createMcpConfigAt(path.join(cwd, '.cursor', 'mcp.json'));
|
|
505
|
+
createMcpConfigAt(path.join(cwd, '.cursor', 'mcp.json'), apiUrl);
|
|
502
506
|
// 2. 生成 .cursorrules 提示词
|
|
503
507
|
const srcRules = path.join(TEMPLATES_DIR, 'cursorrules.md');
|
|
504
508
|
const destRules = path.join(cwd, '.cursorrules');
|
|
@@ -508,16 +512,47 @@ function installCursorTemplates(cwd) {
|
|
|
508
512
|
}
|
|
509
513
|
}
|
|
510
514
|
/** 安装 Antigravity (Gemini IDE) 模板 */
|
|
511
|
-
function installAntigravityTemplates(cwd) {
|
|
515
|
+
function installAntigravityTemplates(cwd, apiUrl) {
|
|
512
516
|
// 1. 填充 .gemini/settings.json
|
|
513
|
-
createMcpConfigAt(path.join(cwd, '.gemini', 'settings.json'));
|
|
517
|
+
createMcpConfigAt(path.join(cwd, '.gemini', 'settings.json'), apiUrl);
|
|
514
518
|
// 2. 生成 AGENTS.md
|
|
515
519
|
generateAgentsMd(cwd);
|
|
520
|
+
// 3. 安装斜杠命令 → .agents/workflows/ (Antigravity 的 slash command 机制)
|
|
521
|
+
const cmdSrcDir = path.join(TEMPLATES_DIR, 'commands', 'pp');
|
|
522
|
+
if (fs.existsSync(cmdSrcDir)) {
|
|
523
|
+
const workflowDir = path.join(cwd, '.agents', 'workflows');
|
|
524
|
+
if (!fs.existsSync(workflowDir)) {
|
|
525
|
+
fs.mkdirSync(workflowDir, { recursive: true });
|
|
526
|
+
}
|
|
527
|
+
const files = fs.readdirSync(cmdSrcDir).filter(f => f.endsWith('.md'));
|
|
528
|
+
let count = 0;
|
|
529
|
+
for (const file of files) {
|
|
530
|
+
// 命名: init.md → pp-init.md, review.md → pp-review.md
|
|
531
|
+
const baseName = path.basename(file, '.md');
|
|
532
|
+
const workflowName = `pp-${baseName.toLowerCase()}`;
|
|
533
|
+
const destFile = path.join(workflowDir, `${workflowName}.md`);
|
|
534
|
+
if (fs.existsSync(destFile))
|
|
535
|
+
continue; // 不覆盖已有的
|
|
536
|
+
const content = fs.readFileSync(path.join(cmdSrcDir, file), 'utf-8');
|
|
537
|
+
// 从第一行提取描述 (去掉 markdown 格式)
|
|
538
|
+
const firstLine = content.split('\n')[0]
|
|
539
|
+
.replace(/^\*\*[^*]+\*\*:\s*/, '') // 去掉 **角色**: 前缀
|
|
540
|
+
.replace(/^#+\s*/, '') // 去掉 # 标题前缀
|
|
541
|
+
.trim()
|
|
542
|
+
.slice(0, 80); // 限长
|
|
543
|
+
const workflow = `---\ndescription: "${firstLine}"\n---\n\n${content}`;
|
|
544
|
+
fs.writeFileSync(destFile, workflow, 'utf-8');
|
|
545
|
+
count++;
|
|
546
|
+
}
|
|
547
|
+
if (count > 0) {
|
|
548
|
+
console.log(`✅ Installed ${count} workflows to .agents/workflows/ (use /pp-sync, /pp-review ...)`);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
516
551
|
}
|
|
517
552
|
/** 安装 Kiro 模板 */
|
|
518
|
-
function installKiroTemplates(cwd) {
|
|
553
|
+
function installKiroTemplates(cwd, apiUrl) {
|
|
519
554
|
// 1. 生成 Kiro MCP 配置
|
|
520
|
-
createMcpConfigAt(path.join(cwd, '.kiro', 'settings', 'mcp.json'));
|
|
555
|
+
createMcpConfigAt(path.join(cwd, '.kiro', 'settings', 'mcp.json'), apiUrl);
|
|
521
556
|
// 2. 生成 Kiro Agent 规则
|
|
522
557
|
const kiroRulesDir = path.join(cwd, '.kiro', 'rules');
|
|
523
558
|
if (!fs.existsSync(kiroRulesDir)) {
|