feat: 准备snapshot发布 - 简化角色系统,完善核心命令
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
const BasePouchCommand = require('../BasePouchCommand');
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const { buildCommand } = require('../../../../constants');
|
||||
|
||||
/**
|
||||
* 角色发现锦囊命令
|
||||
@ -9,110 +10,127 @@ const path = require('path');
|
||||
class HelloCommand extends BasePouchCommand {
|
||||
constructor() {
|
||||
super();
|
||||
// 角色注册表 - 硬编码版本,未来可扩展为动态发现
|
||||
this.ROLES_REGISTRY = [
|
||||
{
|
||||
id: 'video-copywriter',
|
||||
name: '🎬 视频文案专家',
|
||||
description: '专业视频内容创作与营销文案,具备创意性、故事性和营销性思维',
|
||||
category: '内容创作',
|
||||
domain: 'video-copywriting',
|
||||
file: '@package://prompt/domain/copywriter/video-copywriter.role.md'
|
||||
},
|
||||
{
|
||||
id: 'product-owner',
|
||||
name: '🎯 产品负责人',
|
||||
description: '敏捷开发核心决策者,具备全栈产品管理能力和技术理解',
|
||||
category: '项目管理',
|
||||
domain: 'scrum-product-ownership',
|
||||
file: '@package://prompt/domain/scrum/role/product-owner.role.md'
|
||||
},
|
||||
{
|
||||
id: 'prompt-developer',
|
||||
name: '🔧 提示词开发者',
|
||||
description: '探索性、系统性和批判性思维的提示词设计专家',
|
||||
category: '技术开发',
|
||||
domain: 'prompt-engineering',
|
||||
file: '@package://prompt/domain/prompt/prompt-developer.role.md'
|
||||
},
|
||||
{
|
||||
id: 'test-assistant',
|
||||
name: '🧪 测试助手',
|
||||
description: '基础测试角色,具备思考和记忆处理能力',
|
||||
category: '质量保证',
|
||||
domain: 'testing',
|
||||
file: '@package://prompt/domain/test/test.role.md'
|
||||
},
|
||||
{
|
||||
id: 'assistant',
|
||||
name: '🙋 智能助手',
|
||||
description: '通用助理角色,提供基础的助理服务和记忆支持',
|
||||
category: '通用服务',
|
||||
domain: 'general-assistance',
|
||||
file: '@package://prompt/domain/assistant/assistant.role.md'
|
||||
}
|
||||
];
|
||||
this.roleRegistry = null; // 角色注册表将从资源系统动态加载
|
||||
}
|
||||
|
||||
getPurpose() {
|
||||
return '发现并展示所有可用的AI角色和领域专家,帮助选择合适的专业身份开始工作';
|
||||
return '为AI提供可用角色信息,以便AI向主人汇报专业服务选项';
|
||||
}
|
||||
|
||||
/**
|
||||
* 动态加载角色注册表
|
||||
*/
|
||||
async loadRoleRegistry() {
|
||||
if (this.roleRegistry) {
|
||||
return this.roleRegistry;
|
||||
}
|
||||
|
||||
try {
|
||||
// 从ResourceManager获取统一注册表
|
||||
const ResourceManager = require('../../resource/resourceManager');
|
||||
const resourceManager = new ResourceManager();
|
||||
await resourceManager.initialize(); // 确保初始化完成
|
||||
|
||||
if (resourceManager.registry && resourceManager.registry.protocols && resourceManager.registry.protocols.role && resourceManager.registry.protocols.role.registry) {
|
||||
this.roleRegistry = resourceManager.registry.protocols.role.registry;
|
||||
} else {
|
||||
// 备用:如果资源系统不可用,使用基础角色
|
||||
this.roleRegistry = {
|
||||
'assistant': {
|
||||
"file": "@package://prompt/domain/assistant/assistant.role.md",
|
||||
"name": "🙋 智能助手",
|
||||
"description": "通用助理角色,提供基础的助理服务和记忆支持"
|
||||
}
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('角色注册表加载失败,使用基础角色:', error.message);
|
||||
this.roleRegistry = {
|
||||
'assistant': {
|
||||
"file": "@package://prompt/domain/assistant/assistant.role.md",
|
||||
"name": "🙋 智能助手",
|
||||
"description": "通用助理角色,提供基础的助理服务和记忆支持"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return this.roleRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有角色列表(转换为数组格式)
|
||||
*/
|
||||
async getAllRoles() {
|
||||
const registry = await this.loadRoleRegistry();
|
||||
return Object.entries(registry).map(([id, roleInfo]) => ({
|
||||
id: id,
|
||||
name: roleInfo.name,
|
||||
description: roleInfo.description,
|
||||
file: roleInfo.file
|
||||
}));
|
||||
}
|
||||
|
||||
async getContent(args) {
|
||||
const rolesByCategory = this.groupRolesByCategory();
|
||||
const totalRoles = this.ROLES_REGISTRY.length;
|
||||
await this.loadRoleRegistry();
|
||||
const allRoles = await this.getAllRoles();
|
||||
const totalRoles = allRoles.length;
|
||||
|
||||
let content = `👋 欢迎来到 PromptX 锦囊系统!
|
||||
let content = `🤖 **AI专业角色服务清单** (共 ${totalRoles} 个专业角色可供选择)
|
||||
|
||||
🎭 **可用的AI角色与领域专家** (共 ${totalRoles} 个角色)
|
||||
> 💡 **重要说明**:以下是可激活的AI专业角色。每个角色都有唯一的ID,使用action命令激活。
|
||||
|
||||
## 📋 可用角色列表
|
||||
|
||||
`;
|
||||
|
||||
// 按分类展示角色
|
||||
for (const [category, roles] of Object.entries(rolesByCategory)) {
|
||||
content += `## ${this.getCategoryIcon(category)} ${category}\n\n`;
|
||||
|
||||
roles.forEach(role => {
|
||||
content += `### ${role.name}\n`;
|
||||
content += `- **角色ID**: \`${role.id}\`\n`;
|
||||
content += `- **专业领域**: ${role.domain}\n`;
|
||||
content += `- **能力描述**: ${role.description}\n\n`;
|
||||
});
|
||||
}
|
||||
// 清楚显示角色ID和激活命令
|
||||
allRoles.forEach((role, index) => {
|
||||
content += `### ${index + 1}. ${role.name}
|
||||
**角色ID**: \`${role.id}\`
|
||||
**专业能力**: ${role.description}
|
||||
**激活命令**: \`npx promptx action ${role.id}\`
|
||||
|
||||
---
|
||||
|
||||
`;
|
||||
});
|
||||
|
||||
content += `
|
||||
🎯 **下一步操作指南**
|
||||
## 🎯 **角色激活指南**
|
||||
|
||||
选择一个角色,使用以下命令激活专业能力:
|
||||
### 🔧 激活步骤
|
||||
1. **选择角色**: 从上述列表中选择需要的专业角色
|
||||
2. **使用角色ID**: 复制对应的角色ID(如:\`${allRoles[0]?.id || 'assistant'}\`)
|
||||
3. **执行命令**: 运行 \`npx promptx action <角色ID>\`
|
||||
|
||||
### 📝 激活示例
|
||||
\`\`\`bash
|
||||
# 1. 激活角色 (推荐)
|
||||
promptx action <角色ID>
|
||||
|
||||
# 2. 或直接学习角色知识
|
||||
promptx learn <角色ID>
|
||||
# 激活智能助手角色
|
||||
npx promptx action ${allRoles[0]?.id || 'assistant'}
|
||||
\`\`\`
|
||||
|
||||
💡 **使用示例**
|
||||
\`\`\`bash
|
||||
promptx action video-copywriter # 激活视频文案专家
|
||||
promptx action product-owner # 激活产品负责人
|
||||
promptx action prompt-developer # 激活提示词开发者
|
||||
\`\`\`
|
||||
### ⚡ 激活后效果
|
||||
- ✅ **获得专业能力** - AI将具备该角色的专业技能
|
||||
- ✅ **学习技能组合** - 自动学习角色需要的思维和行为模式
|
||||
- ✅ **即时专业化** - 立即可以提供该领域的专业服务
|
||||
|
||||
🔄 **锦囊串联流程**
|
||||
👋 **hello**(发现角色) → ⚡ **action**(激活角色) → 📚 **learn**(学习知识) → 🔍 **recall**(应用经验)
|
||||
---
|
||||
|
||||
⚠️ **AI执行指令**:
|
||||
📢 **向主人汇报角色选项,明确说明使用方法:"请选择角色ID,然后我将执行对应的action命令"**
|
||||
🎯 **等待主人指定具体的角色ID后,立即执行 \`npx promptx action <角色ID>\`**
|
||||
💡 **强调:action命令需要具体的角色ID,不是角色名称**
|
||||
`;
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
getPATEOAS(args) {
|
||||
const availableRoles = this.ROLES_REGISTRY.map(role => ({
|
||||
async getPATEOAS(args) {
|
||||
const allRoles = await this.getAllRoles();
|
||||
const availableRoles = allRoles.map(role => ({
|
||||
roleId: role.id,
|
||||
name: role.name,
|
||||
category: role.category,
|
||||
actionCommand: `promptx action ${role.id}`
|
||||
actionCommand: buildCommand.action(role.id)
|
||||
}));
|
||||
|
||||
return {
|
||||
@ -120,91 +138,42 @@ promptx action prompt-developer # 激活提示词开发者
|
||||
availableTransitions: ['action', 'learn', 'init', 'recall'],
|
||||
nextActions: [
|
||||
{
|
||||
name: '激活视频文案专家',
|
||||
description: '成为专业的视频内容创作者',
|
||||
command: 'promptx action video-copywriter',
|
||||
priority: 'high'
|
||||
},
|
||||
{
|
||||
name: '激活产品负责人',
|
||||
description: '成为敏捷开发的决策者',
|
||||
command: 'promptx action product-owner',
|
||||
priority: 'high'
|
||||
},
|
||||
{
|
||||
name: '激活提示词开发者',
|
||||
description: '成为提示词设计专家',
|
||||
command: 'promptx action prompt-developer',
|
||||
priority: 'medium'
|
||||
},
|
||||
{
|
||||
name: '激活智能助手',
|
||||
description: '成为通用助理',
|
||||
command: 'promptx action assistant',
|
||||
priority: 'low'
|
||||
},
|
||||
{
|
||||
name: '学习特定领域',
|
||||
description: '深入学习某个专业领域',
|
||||
command: 'promptx learn <domain>',
|
||||
parameters: {
|
||||
domain: '可选值:copywriter, scrum, prompt, test, assistant'
|
||||
}
|
||||
name: '向主人汇报服务选项',
|
||||
description: '将上述专业服务清单告知主人,并询问需求',
|
||||
command: '等待主人选择后使用: ' + buildCommand.action('<选择的角色ID>'),
|
||||
priority: 'critical',
|
||||
instruction: '必须先询问主人需求,不要自主选择角色'
|
||||
}
|
||||
],
|
||||
metadata: {
|
||||
totalRoles: this.ROLES_REGISTRY.length,
|
||||
categories: [...new Set(this.ROLES_REGISTRY.map(r => r.category))],
|
||||
totalRoles: allRoles.length,
|
||||
availableRoles: availableRoles,
|
||||
dataSource: 'resource.registry.json',
|
||||
systemVersion: '锦囊串联状态机 v1.0',
|
||||
designPhilosophy: 'AI use CLI get prompt for AI'
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 按分类分组角色
|
||||
*/
|
||||
groupRolesByCategory() {
|
||||
const grouped = {};
|
||||
|
||||
this.ROLES_REGISTRY.forEach(role => {
|
||||
if (!grouped[role.category]) {
|
||||
grouped[role.category] = [];
|
||||
}
|
||||
grouped[role.category].push(role);
|
||||
});
|
||||
|
||||
return grouped;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分类图标
|
||||
*/
|
||||
getCategoryIcon(category) {
|
||||
const icons = {
|
||||
'内容创作': '✍️',
|
||||
'项目管理': '📊',
|
||||
'技术开发': '💻',
|
||||
'质量保证': '🔍',
|
||||
'通用服务': '🤖'
|
||||
};
|
||||
|
||||
return icons[category] || '🎯';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取角色信息(提供给其他命令使用)
|
||||
*/
|
||||
getRoleInfo(roleId) {
|
||||
return this.ROLES_REGISTRY.find(role => role.id === roleId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有角色列表
|
||||
*/
|
||||
getAllRoles() {
|
||||
return this.ROLES_REGISTRY;
|
||||
async getRoleInfo(roleId) {
|
||||
const registry = await this.loadRoleRegistry();
|
||||
const roleData = registry[roleId];
|
||||
|
||||
if (!roleData) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
id: roleId,
|
||||
name: roleData.name,
|
||||
description: roleData.description,
|
||||
file: roleData.file
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -212,13 +181,9 @@ promptx action prompt-developer # 激活提示词开发者
|
||||
* TODO: 实现真正的文件扫描和解析
|
||||
*/
|
||||
async discoverAvailableDomains() {
|
||||
// 预留接口,未来实现动态角色发现
|
||||
// 1. 扫描 prompt/domain/ 目录
|
||||
// 2. 解析 .role.md 文件
|
||||
// 3. 提取元数据和描述
|
||||
// 4. 构建动态注册表
|
||||
|
||||
return this.ROLES_REGISTRY.map(role => role.domain);
|
||||
// 现在基于注册表返回角色ID列表
|
||||
const allRoles = await this.getAllRoles();
|
||||
return allRoles.map(role => role.id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user