px2cc 2.0.0 → 2.0.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/package.json +1 -1
- package/src/PromptXActionProcessor.js +57 -74
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "px2cc",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.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",
|
|
@@ -212,12 +212,12 @@ 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
219
|
async loadCognitionNetwork(roleId) {
|
|
220
|
-
console.log(chalk.cyan(`🧠
|
|
220
|
+
console.log(chalk.cyan(`🧠 检查认知网络状态: ${roleId}`));
|
|
221
221
|
|
|
222
222
|
try {
|
|
223
223
|
const networkFilePath = path.join(this.basePath, roleId, 'network.json');
|
|
@@ -228,96 +228,64 @@ class CognitionLoader {
|
|
|
228
228
|
} catch (error) {
|
|
229
229
|
console.log(chalk.gray(` 未找到认知网络文件: ${roleId}`));
|
|
230
230
|
return {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
231
|
+
hasNetwork: false,
|
|
232
|
+
networkPath: networkFilePath,
|
|
233
|
+
status: 'not_found'
|
|
234
234
|
};
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
-
//
|
|
237
|
+
// 读取网络数据基本信息(不生成静态mindmap)
|
|
238
238
|
const networkData = JSON.parse(await fs.readFile(networkFilePath, 'utf8'));
|
|
239
|
+
const stats = this.getNetworkStats(networkData);
|
|
239
240
|
|
|
240
|
-
|
|
241
|
-
const mindmap = this.generateMindmap(networkData);
|
|
242
|
-
|
|
243
|
-
// 构建Mind对象
|
|
244
|
-
const mind = this.buildMindObject(networkData);
|
|
245
|
-
|
|
246
|
-
console.log(chalk.green(`✅ 认知网络加载成功: ${mind.nodeCount} 个节点, ${mind.connectionCount} 个连接`));
|
|
241
|
+
console.log(chalk.green(`✅ 认知网络检查完成: ${stats.nodeCount} 个节点, ${stats.connectionCount} 个连接`));
|
|
247
242
|
|
|
248
243
|
return {
|
|
249
|
-
mind,
|
|
250
|
-
mindmap,
|
|
251
244
|
hasNetwork: true,
|
|
252
|
-
|
|
245
|
+
networkPath: networkFilePath,
|
|
246
|
+
status: 'active',
|
|
247
|
+
stats,
|
|
248
|
+
lastModified: networkData.timestamp || 'unknown'
|
|
253
249
|
};
|
|
254
250
|
|
|
255
251
|
} catch (error) {
|
|
256
|
-
console.warn(chalk.yellow(`⚠️
|
|
252
|
+
console.warn(chalk.yellow(`⚠️ 认知网络检查失败: ${error.message}`));
|
|
257
253
|
return {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
254
|
+
hasNetwork: false,
|
|
255
|
+
networkPath: null,
|
|
256
|
+
status: 'error',
|
|
257
|
+
error: error.message
|
|
261
258
|
};
|
|
262
259
|
}
|
|
263
260
|
}
|
|
264
261
|
|
|
265
262
|
/**
|
|
266
|
-
*
|
|
267
|
-
* @param {Object} networkData - 网络数据
|
|
268
|
-
* @returns {string} mindmap代码
|
|
269
|
-
*/
|
|
270
|
-
generateMindmap(networkData) {
|
|
271
|
-
if (!networkData.cues || Object.keys(networkData.cues).length === 0) {
|
|
272
|
-
return 'mindmap\n root((暂无认知数据))';
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// 找到权重最高的概念作为根节点
|
|
276
|
-
const cues = Object.entries(networkData.cues);
|
|
277
|
-
const rootCue = cues.reduce((max, [word, cue]) => {
|
|
278
|
-
const totalWeight = (cue.connections || []).reduce((sum, conn) => sum + (conn.weight || 0), 0);
|
|
279
|
-
return totalWeight > (max.totalWeight || 0) ? { word, totalWeight } : max;
|
|
280
|
-
}, {});
|
|
281
|
-
|
|
282
|
-
let mindmap = 'mindmap\n';
|
|
283
|
-
mindmap += ` root((${rootCue.word || '认知中心'}))\n`;
|
|
284
|
-
|
|
285
|
-
// 添加相关概念(取权重前10的连接)
|
|
286
|
-
if (rootCue.word && networkData.cues[rootCue.word]?.connections) {
|
|
287
|
-
const connections = networkData.cues[rootCue.word].connections
|
|
288
|
-
.sort((a, b) => (b.weight || 0) - (a.weight || 0))
|
|
289
|
-
.slice(0, 10);
|
|
290
|
-
|
|
291
|
-
connections.forEach(conn => {
|
|
292
|
-
if (conn.target) {
|
|
293
|
-
mindmap += ` ${conn.target}\n`;
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
return mindmap;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* 构建Mind对象
|
|
263
|
+
* 获取网络统计信息
|
|
303
264
|
* @param {Object} networkData - 网络数据
|
|
304
|
-
* @returns {Object}
|
|
265
|
+
* @returns {Object} 统计信息
|
|
305
266
|
*/
|
|
306
|
-
|
|
267
|
+
getNetworkStats(networkData) {
|
|
307
268
|
const cues = networkData.cues || {};
|
|
308
269
|
const nodeCount = Object.keys(cues).length;
|
|
309
270
|
let connectionCount = 0;
|
|
310
|
-
|
|
271
|
+
|
|
272
|
+
// 统计连接数
|
|
311
273
|
Object.values(cues).forEach(cue => {
|
|
312
274
|
connectionCount += (cue.connections || []).length;
|
|
313
275
|
});
|
|
314
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
|
+
|
|
315
283
|
return {
|
|
316
284
|
nodeCount,
|
|
317
285
|
connectionCount,
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
286
|
+
mostActiveCue: mostActiveCue.word,
|
|
287
|
+
version: networkData.version,
|
|
288
|
+
hasConnections: connectionCount > 0
|
|
321
289
|
};
|
|
322
290
|
}
|
|
323
291
|
}
|
|
@@ -341,19 +309,34 @@ class LayerAssembler {
|
|
|
341
309
|
parts.push(`# 🧠 [Consciousness Prime] ${roleInfo.id}${mode === 'subagent' ? '专业助手' : '角色已激活'}`);
|
|
342
310
|
parts.push('');
|
|
343
311
|
|
|
344
|
-
// CognitionLayer -
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
parts.push(cognitionData.
|
|
349
|
-
parts.push('```');
|
|
350
|
-
parts.push('');
|
|
312
|
+
// CognitionLayer - 动态认知网络状态
|
|
313
|
+
parts.push('## 💭 Hippocampus网络');
|
|
314
|
+
|
|
315
|
+
if (cognitionData.hasNetwork) {
|
|
316
|
+
parts.push(`**认知网络状态**: ${cognitionData.status === 'active' ? '🟢 激活' : '🔴 未激活'}`);
|
|
351
317
|
|
|
352
|
-
if (cognitionData.
|
|
353
|
-
parts.push(
|
|
354
|
-
|
|
318
|
+
if (cognitionData.stats) {
|
|
319
|
+
parts.push(`**基础统计**: ${cognitionData.stats.nodeCount} 个概念节点,${cognitionData.stats.connectionCount} 个关联连接`);
|
|
320
|
+
|
|
321
|
+
if (cognitionData.stats.mostActiveCue) {
|
|
322
|
+
parts.push(`**核心概念**: ${cognitionData.stats.mostActiveCue}`);
|
|
323
|
+
}
|
|
355
324
|
}
|
|
325
|
+
|
|
326
|
+
parts.push('');
|
|
327
|
+
parts.push('🔄 **动态认知网络**: 网络状态随着你的学习和记忆而实时进化');
|
|
328
|
+
parts.push('- 使用PromptX `recall` 工具查看当前激活的记忆网络');
|
|
329
|
+
parts.push('- 使用PromptX `remember` 工具将新经验编织到认知网络中');
|
|
330
|
+
parts.push('- 每次交互都会调整概念间的关联强度');
|
|
331
|
+
|
|
332
|
+
} else {
|
|
333
|
+
parts.push('🌱 **初始状态**: 认知网络尚未建立');
|
|
334
|
+
parts.push('- 开始使用PromptX工具与该角色互动');
|
|
335
|
+
parts.push('- 系统会自动建立和完善认知网络');
|
|
336
|
+
parts.push('- 随着经验积累,网络会变得越来越丰富');
|
|
356
337
|
}
|
|
338
|
+
|
|
339
|
+
parts.push('');
|
|
357
340
|
|
|
358
341
|
// RoleLayer - 角色定义
|
|
359
342
|
if (roleInfo.sections.personality) {
|