px2cc 2.0.6 → 2.1.1
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 +16 -8
- package/cli.js +7 -7
- package/package.json +2 -2
- 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
|
@@ -2,16 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Px2CC 启动器 - 通用版本
|
|
5
|
-
*
|
|
5
|
+
* 直接调用主函数,确保跨平台兼容
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
// 设置环境变量来抑制PromptX内部日志
|
|
9
9
|
process.env.LOG_LEVEL = 'silent';
|
|
10
10
|
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
// 动态导入并直接调用main函数
|
|
12
|
+
(async () => {
|
|
13
|
+
try {
|
|
14
|
+
const { main } = await import('./cli.js');
|
|
15
|
+
if (typeof main === 'function') {
|
|
16
|
+
await main();
|
|
17
|
+
} else {
|
|
18
|
+
// 如果没有导出main函数,直接导入模块(会自动执行)
|
|
19
|
+
await import('./cli.js');
|
|
20
|
+
}
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.error('启动失败:', error.message);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
})();
|
package/cli.js
CHANGED
|
@@ -180,7 +180,7 @@ async function showRoleMenu(systemRoles, userRoles, availableServers) {
|
|
|
180
180
|
message: `安装 ${roleAnswer.selectedRole.role} 为:`,
|
|
181
181
|
choices: [
|
|
182
182
|
{
|
|
183
|
-
name: `🤖 Agent -
|
|
183
|
+
name: `🤖 Agent - 通过提及"${roleAnswer.selectedRole.role}-agent subagent"调用`,
|
|
184
184
|
value: 'agents',
|
|
185
185
|
short: 'Agent'
|
|
186
186
|
},
|
|
@@ -243,7 +243,7 @@ async function installRole(selectedRole, installType, claudeDir, manager, select
|
|
|
243
243
|
if (installType === 'agents') {
|
|
244
244
|
console.log(chalk.cyan(`🔧 生成 ${roleName} subagent文件...`));
|
|
245
245
|
const agentConfig = {
|
|
246
|
-
name: roleName
|
|
246
|
+
name: `${roleName}-agent`,
|
|
247
247
|
description: `基于PromptX ${roleName}角色的专业AI助手 - 完整action实现`,
|
|
248
248
|
content: processedContent,
|
|
249
249
|
targetDir: claudeDir
|
|
@@ -260,8 +260,8 @@ async function installRole(selectedRole, installType, claudeDir, manager, select
|
|
|
260
260
|
if (!subagentResult.success) {
|
|
261
261
|
throw new Error(`创建Subagent失败: ${subagentResult.error}`);
|
|
262
262
|
}
|
|
263
|
-
results.agentFile = `${roleName}.md`;
|
|
264
|
-
results.usage =
|
|
263
|
+
results.agentFile = `${roleName}-agent.md`;
|
|
264
|
+
results.usage = `Use the ${roleName}-agent subagent to [任务描述]`;
|
|
265
265
|
}
|
|
266
266
|
|
|
267
267
|
if (installType === 'commands') {
|
|
@@ -299,7 +299,7 @@ async function installRole(selectedRole, installType, claudeDir, manager, select
|
|
|
299
299
|
}
|
|
300
300
|
|
|
301
301
|
// 主程序入口
|
|
302
|
-
async function main() {
|
|
302
|
+
export async function main() {
|
|
303
303
|
try {
|
|
304
304
|
showWelcome();
|
|
305
305
|
|
|
@@ -373,8 +373,8 @@ async function main() {
|
|
|
373
373
|
}
|
|
374
374
|
}
|
|
375
375
|
|
|
376
|
-
// 运行主程序
|
|
377
|
-
if (import.meta.url === new URL(process.argv[1], 'file:').href) {
|
|
376
|
+
// 运行主程序 - 简化条件判断以提高兼容性
|
|
377
|
+
if (import.meta.url === new URL(process.argv[1], 'file:').href || process.argv[1].endsWith('cli.js')) {
|
|
378
378
|
main().catch(error => {
|
|
379
379
|
console.error(chalk.red('❌ 程序异常:'), error.message);
|
|
380
380
|
process.exit(1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "px2cc",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
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",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"author": "PromptX Bridge Team",
|
|
39
39
|
"license": "MIT",
|
|
40
40
|
"engines": {
|
|
41
|
-
"node": ">=
|
|
41
|
+
"node": ">=18.0.0"
|
|
42
42
|
},
|
|
43
43
|
"repository": {
|
|
44
44
|
"type": "git",
|
|
@@ -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);
|