px2cc 2.0.5 → 2.1.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/README.md +7 -6
- package/bin.js +1 -1
- package/cli.js +22 -11
- package/package.json +1 -1
- package/src/PromptXActionProcessor.js +34 -77
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
- 🚀 快速安装PromptX角色到Claude Code
|
|
8
8
|
- 🎭 动态获取所有可用的系统角色和用户角色
|
|
9
|
-
- 🤖 支持安装为Claude Code
|
|
9
|
+
- 🤖 支持安装为Claude Code Subagents (通过自然语言提及调用)
|
|
10
10
|
- ⚙️ 支持安装为Claude Code Commands (通过 `/command` 调用)
|
|
11
11
|
- 🎨 友好的交互式界面
|
|
12
12
|
- 📁 自动创建和管理 `.claude` 目录结构
|
|
@@ -33,9 +33,9 @@ npx px2cc
|
|
|
33
33
|
|
|
34
34
|
## 安装类型
|
|
35
35
|
|
|
36
|
-
###
|
|
36
|
+
### Subagent 模式
|
|
37
37
|
- 安装到 `.claude/agents/` 目录
|
|
38
|
-
-
|
|
38
|
+
- 通过自然语言提及调用: `Use the <角色名>-agent subagent to [任务]`
|
|
39
39
|
|
|
40
40
|
### Command 模式
|
|
41
41
|
- 安装到 `.claude/commands/` 目录
|
|
@@ -66,7 +66,7 @@ $ px2cc
|
|
|
66
66
|
📊 发现 5 个系统角色,9 个用户角色
|
|
67
67
|
|
|
68
68
|
? 请选择要安装的PromptX角色: assistant (系统角色)
|
|
69
|
-
? 安装 assistant 为: Agent -
|
|
69
|
+
? 安装 assistant 为: Agent - 通过提及"assistant-agent subagent"调用
|
|
70
70
|
? 确认安装到Claude Code? Yes
|
|
71
71
|
|
|
72
72
|
📖 加载 assistant 角色定义...
|
|
@@ -75,10 +75,11 @@ $ px2cc
|
|
|
75
75
|
✅ 角色安装完成!
|
|
76
76
|
|
|
77
77
|
📄 生成的文件:
|
|
78
|
-
- .claude/agents/assistant.md
|
|
78
|
+
- .claude/agents/assistant-agent.md
|
|
79
79
|
|
|
80
80
|
🎉 现在你可以在Claude Code中使用:
|
|
81
|
-
|
|
81
|
+
Use the assistant-agent subagent to help with my task
|
|
82
|
+
Have the assistant-agent subagent review my code
|
|
82
83
|
|
|
83
84
|
💡 提示: 重启Claude Code以确保新配置生效
|
|
84
85
|
```
|
package/bin.js
CHANGED
package/cli.js
CHANGED
|
@@ -30,10 +30,11 @@ async function discoverMCPServers() {
|
|
|
30
30
|
|
|
31
31
|
try {
|
|
32
32
|
console.log(chalk.gray(' 检查MCP服务器状态(可能需要一些时间)...'));
|
|
33
|
-
// 使用claude mcp list获取所有MCP
|
|
33
|
+
// 使用claude mcp list获取所有MCP服务器(增加超时时间到60秒)
|
|
34
34
|
const mcpOutput = execSync('claude mcp list', {
|
|
35
35
|
encoding: 'utf8',
|
|
36
|
-
timeout:
|
|
36
|
+
timeout: 60000, // 增加到60秒
|
|
37
|
+
stdio: 'pipe' // 确保错误输出被捕获
|
|
37
38
|
});
|
|
38
39
|
|
|
39
40
|
// 解析输出,提取服务器信息
|
|
@@ -58,13 +59,15 @@ async function discoverMCPServers() {
|
|
|
58
59
|
|
|
59
60
|
} catch (error) {
|
|
60
61
|
if (error.code === 'ETIMEDOUT') {
|
|
61
|
-
console.error(chalk.
|
|
62
|
-
console.error(chalk.gray('
|
|
62
|
+
console.error(chalk.yellow('⚠️ MCP服务器检查超时,将继续安装(只使用默认工具)'));
|
|
63
|
+
console.error(chalk.gray(' 如需使用MCP工具,请检查网络连接或使用 --skip-mcp 参数'));
|
|
63
64
|
} else {
|
|
64
|
-
console.error(chalk.
|
|
65
|
+
console.error(chalk.yellow('⚠️ 无法获取MCP服务器列表,将继续安装(只使用默认工具)'));
|
|
65
66
|
console.error(chalk.gray(` 原因: ${error.message}`));
|
|
66
67
|
}
|
|
67
|
-
|
|
68
|
+
// 不再抛出错误,而是继续执行,不使用MCP服务器
|
|
69
|
+
console.log(chalk.gray(' 将继承所有可用工具(Claude Code默认行为)'));
|
|
70
|
+
return servers;
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
return servers;
|
|
@@ -177,7 +180,7 @@ async function showRoleMenu(systemRoles, userRoles, availableServers) {
|
|
|
177
180
|
message: `安装 ${roleAnswer.selectedRole.role} 为:`,
|
|
178
181
|
choices: [
|
|
179
182
|
{
|
|
180
|
-
name: `🤖 Agent -
|
|
183
|
+
name: `🤖 Agent - 通过提及"${roleAnswer.selectedRole.role}-agent subagent"调用`,
|
|
181
184
|
value: 'agents',
|
|
182
185
|
short: 'Agent'
|
|
183
186
|
},
|
|
@@ -240,7 +243,7 @@ async function installRole(selectedRole, installType, claudeDir, manager, select
|
|
|
240
243
|
if (installType === 'agents') {
|
|
241
244
|
console.log(chalk.cyan(`🔧 生成 ${roleName} subagent文件...`));
|
|
242
245
|
const agentConfig = {
|
|
243
|
-
name: roleName
|
|
246
|
+
name: `${roleName}-agent`,
|
|
244
247
|
description: `基于PromptX ${roleName}角色的专业AI助手 - 完整action实现`,
|
|
245
248
|
content: processedContent,
|
|
246
249
|
targetDir: claudeDir
|
|
@@ -257,8 +260,8 @@ async function installRole(selectedRole, installType, claudeDir, manager, select
|
|
|
257
260
|
if (!subagentResult.success) {
|
|
258
261
|
throw new Error(`创建Subagent失败: ${subagentResult.error}`);
|
|
259
262
|
}
|
|
260
|
-
results.agentFile = `${roleName}.md`;
|
|
261
|
-
results.usage =
|
|
263
|
+
results.agentFile = `${roleName}-agent.md`;
|
|
264
|
+
results.usage = `Use the ${roleName}-agent subagent to [任务描述]`;
|
|
262
265
|
}
|
|
263
266
|
|
|
264
267
|
if (installType === 'commands') {
|
|
@@ -313,7 +316,15 @@ async function main() {
|
|
|
313
316
|
} else {
|
|
314
317
|
// 发现MCP服务器
|
|
315
318
|
console.log(chalk.cyan('🔍 正在发现MCP服务器...\n'));
|
|
316
|
-
|
|
319
|
+
try {
|
|
320
|
+
availableServers = await discoverMCPServers();
|
|
321
|
+
} catch (error) {
|
|
322
|
+
console.error(chalk.yellow('⚠️ MCP服务器发现失败,使用默认配置'));
|
|
323
|
+
availableServers = {
|
|
324
|
+
defaultTools: ['Read', 'Write', 'Edit', 'Bash'],
|
|
325
|
+
mcpServers: []
|
|
326
|
+
};
|
|
327
|
+
}
|
|
317
328
|
}
|
|
318
329
|
|
|
319
330
|
// 加载角色
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "px2cc",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "CLI tool that implements complete PromptX Action flow in Claude Code - role activation, dependency loading, cognition networks & memory systems",
|
|
5
5
|
"main": "cli.js",
|
|
6
6
|
"type": "module",
|
|
@@ -212,82 +212,42 @@ class CognitionLoader {
|
|
|
212
212
|
}
|
|
213
213
|
|
|
214
214
|
/**
|
|
215
|
-
*
|
|
215
|
+
* 检查认知网络是否存在(不加载具体内容)
|
|
216
216
|
* @param {string} roleId - 角色ID
|
|
217
|
-
* @returns {Object}
|
|
217
|
+
* @returns {Object} 认知网络存在状态
|
|
218
218
|
*/
|
|
219
|
-
async
|
|
219
|
+
async checkNetworkExists(roleId) {
|
|
220
220
|
console.log(chalk.cyan(`🧠 检查认知网络状态: ${roleId}`));
|
|
221
221
|
|
|
222
222
|
try {
|
|
223
223
|
const networkFilePath = path.join(this.basePath, roleId, 'network.json');
|
|
224
224
|
|
|
225
|
-
//
|
|
225
|
+
// 仅检查文件是否存在
|
|
226
226
|
try {
|
|
227
227
|
await fs.access(networkFilePath);
|
|
228
|
+
console.log(chalk.green(`✅ 发现认知网络文件: ${roleId}`));
|
|
229
|
+
return {
|
|
230
|
+
hasNetwork: true,
|
|
231
|
+
networkPath: networkFilePath
|
|
232
|
+
};
|
|
228
233
|
} catch (error) {
|
|
229
234
|
console.log(chalk.gray(` 未找到认知网络文件: ${roleId}`));
|
|
230
235
|
return {
|
|
231
236
|
hasNetwork: false,
|
|
232
|
-
networkPath: networkFilePath
|
|
233
|
-
status: 'not_found'
|
|
237
|
+
networkPath: networkFilePath
|
|
234
238
|
};
|
|
235
239
|
}
|
|
236
|
-
|
|
237
|
-
// 读取网络数据基本信息(不生成静态mindmap)
|
|
238
|
-
const networkData = JSON.parse(await fs.readFile(networkFilePath, 'utf8'));
|
|
239
|
-
const stats = this.getNetworkStats(networkData);
|
|
240
|
-
|
|
241
|
-
console.log(chalk.green(`✅ 认知网络检查完成: ${stats.nodeCount} 个节点, ${stats.connectionCount} 个连接`));
|
|
242
|
-
|
|
243
|
-
return {
|
|
244
|
-
hasNetwork: true,
|
|
245
|
-
networkPath: networkFilePath,
|
|
246
|
-
status: 'active',
|
|
247
|
-
stats,
|
|
248
|
-
lastModified: networkData.timestamp || 'unknown'
|
|
249
|
-
};
|
|
250
240
|
|
|
251
241
|
} catch (error) {
|
|
252
242
|
console.warn(chalk.yellow(`⚠️ 认知网络检查失败: ${error.message}`));
|
|
253
243
|
return {
|
|
254
244
|
hasNetwork: false,
|
|
255
245
|
networkPath: null,
|
|
256
|
-
status: 'error',
|
|
257
246
|
error: error.message
|
|
258
247
|
};
|
|
259
248
|
}
|
|
260
249
|
}
|
|
261
250
|
|
|
262
|
-
/**
|
|
263
|
-
* 获取网络统计信息
|
|
264
|
-
* @param {Object} networkData - 网络数据
|
|
265
|
-
* @returns {Object} 统计信息
|
|
266
|
-
*/
|
|
267
|
-
getNetworkStats(networkData) {
|
|
268
|
-
const cues = networkData.cues || {};
|
|
269
|
-
const nodeCount = Object.keys(cues).length;
|
|
270
|
-
let connectionCount = 0;
|
|
271
|
-
|
|
272
|
-
// 统计连接数
|
|
273
|
-
Object.values(cues).forEach(cue => {
|
|
274
|
-
connectionCount += (cue.connections || []).length;
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
// 找到最活跃的概念
|
|
278
|
-
const mostActiveCue = Object.entries(cues).reduce((max, [word, cue]) => {
|
|
279
|
-
const totalWeight = (cue.connections || []).reduce((sum, conn) => sum + (conn.weight || 0), 0);
|
|
280
|
-
return totalWeight > (max.totalWeight || 0) ? { word, totalWeight } : max;
|
|
281
|
-
}, { word: null, totalWeight: 0 });
|
|
282
|
-
|
|
283
|
-
return {
|
|
284
|
-
nodeCount,
|
|
285
|
-
connectionCount,
|
|
286
|
-
mostActiveCue: mostActiveCue.word,
|
|
287
|
-
version: networkData.version,
|
|
288
|
-
hasConnections: connectionCount > 0
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
251
|
}
|
|
292
252
|
|
|
293
253
|
/**
|
|
@@ -309,31 +269,26 @@ class LayerAssembler {
|
|
|
309
269
|
parts.push(`# 🧠 [Consciousness Prime] ${roleInfo.id}${mode === 'subagent' ? '专业助手' : '角色已激活'}`);
|
|
310
270
|
parts.push('');
|
|
311
271
|
|
|
312
|
-
// CognitionLayer -
|
|
313
|
-
parts.push('## 💭
|
|
272
|
+
// CognitionLayer - PromptX认知增强
|
|
273
|
+
parts.push('## 💭 PromptX认知增强');
|
|
314
274
|
|
|
315
275
|
if (cognitionData.hasNetwork) {
|
|
316
|
-
parts.push(
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
parts.push(`**核心概念**: ${cognitionData.stats.mostActiveCue}`);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
276
|
+
parts.push('🧠 **状态**: 该角色已建立经验网络');
|
|
277
|
+
parts.push('');
|
|
278
|
+
parts.push('🔧 **激活方式** (需要PromptX MCP服务器):');
|
|
279
|
+
parts.push(`- \`recall ${roleInfo.id}\` - 激活该角色的完整经验网络`);
|
|
280
|
+
parts.push(`- \`recall ${roleInfo.id} "具体问题"\` - 检索相关历史经验`);
|
|
281
|
+
parts.push(`- \`remember ${roleInfo.id} "新知识"\` - 将新经验加入角色记忆`);
|
|
326
282
|
parts.push('');
|
|
327
|
-
parts.push('
|
|
328
|
-
parts.push('- 使用PromptX `recall` 工具查看当前激活的记忆网络');
|
|
329
|
-
parts.push('- 使用PromptX `remember` 工具将新经验编织到认知网络中');
|
|
330
|
-
parts.push('- 每次交互都会调整概念间的关联强度');
|
|
283
|
+
parts.push('💡 **说明**: 认知网络包含该角色的历史使用经验,通过recall工具动态激活');
|
|
331
284
|
|
|
332
285
|
} else {
|
|
333
|
-
parts.push('🌱
|
|
334
|
-
parts.push('
|
|
335
|
-
parts.push('
|
|
336
|
-
parts.push('-
|
|
286
|
+
parts.push('🌱 **状态**: 该角色尚未建立经验网络');
|
|
287
|
+
parts.push('');
|
|
288
|
+
parts.push('🚀 **开始使用**:');
|
|
289
|
+
parts.push('- 安装并配置PromptX MCP服务器');
|
|
290
|
+
parts.push(`- 使用 \`recall ${roleInfo.id}\` 开始建立认知网络`);
|
|
291
|
+
parts.push('- 随着使用逐步积累该角色的专业经验');
|
|
337
292
|
}
|
|
338
293
|
|
|
339
294
|
parts.push('');
|
|
@@ -392,13 +347,15 @@ class LayerAssembler {
|
|
|
392
347
|
parts.push('请告诉我你需要什么帮助?');
|
|
393
348
|
}
|
|
394
349
|
|
|
350
|
+
parts.push('');
|
|
351
|
+
parts.push('---');
|
|
395
352
|
parts.push('');
|
|
396
353
|
parts.push('💡 **可用的PromptX工具生态**:');
|
|
397
|
-
parts.push(
|
|
398
|
-
parts.push(
|
|
399
|
-
parts.push('-
|
|
400
|
-
parts.push('-
|
|
401
|
-
parts.push('-
|
|
354
|
+
parts.push(`- \`recall ${roleInfo.id}\` - 激活该角色的历史经验网络`);
|
|
355
|
+
parts.push(`- \`remember ${roleInfo.id} "新体验"\` - 将新体验编织到角色记忆`);
|
|
356
|
+
parts.push('- `learn` - 学习新的资源和知识');
|
|
357
|
+
parts.push('- `toolx` - 执行专业工具');
|
|
358
|
+
parts.push('- 具体工具可用性取决于PromptX MCP服务器配置');
|
|
402
359
|
parts.push('');
|
|
403
360
|
|
|
404
361
|
if (mode === 'command') {
|
|
@@ -457,8 +414,8 @@ export class PromptXActionProcessor {
|
|
|
457
414
|
// 2. 分析依赖资源
|
|
458
415
|
const dependencies = await this.dependencyAnalyzer.analyzeDependencies(roleInfo);
|
|
459
416
|
|
|
460
|
-
// 3.
|
|
461
|
-
const cognitionData = await this.cognitionLoader.
|
|
417
|
+
// 3. 检查认知网络存在性
|
|
418
|
+
const cognitionData = await this.cognitionLoader.checkNetworkExists(roleId);
|
|
462
419
|
|
|
463
420
|
// 4. 三层组装
|
|
464
421
|
const content = this.layerAssembler.assembleContent(roleInfo, dependencies, cognitionData, mode);
|