refactor: 重构resource/domain为resource/role - 提升目录语义化
## 核心改进 - 将resource/domain重命名为resource/role,语义更清晰直观 - 统一更新所有硬编码路径引用,确保系统完整性 - 重新生成注册表,所有61个资源引用路径完全更新 ## 目录结构优化 - resource/role (原domain) - 角色定义和专家能力 - resource/tool - JavaScript工具资源 - resource/protocol - 协议规范文档 - resource/core - 核心思维和执行模式 ## 技术实现 ### 发现器更新 - ProjectDiscovery.js: _scanDomainDirectory → _scanRoleDirectory - PackageDiscovery.js: 同步更新函数名和路径引用 - 所有@project://.promptx/resource/domain/ → @project://.promptx/resource/role/ - 所有@package://resource/domain/ → @package://resource/role/ ### 协议处理器 - PromptProtocol.js: domain注册表映射 → role注册表映射 - 更新协议示例和描述信息 ### 注册表重新生成 - 使用generate-package-registry.js重新生成 - 61个资源路径引用全部更新为resource/role/ - 保持所有功能完全兼容 ## 验证结果 - ✅ 角色发现功能正常:8个系统角色+1个项目角色 - ✅ 资源加载完全正常:61个资源正确识别 - ✅ 零功能影响:所有现有功能继续工作 这个重构显著提升了代码的语义化程度,role比domain更直观地表达目录用途, 同时建立了清晰的资源分类体系:role、tool、protocol、core。 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -143,8 +143,8 @@ class PackageDiscovery extends BaseDiscovery {
|
||||
// 这里可以实现动态扫描逻辑,或者返回空Map
|
||||
// 为了简化,我们返回一个基础的assistant角色
|
||||
const fallbackRegistry = new Map()
|
||||
fallbackRegistry.set('assistant', '@package://resource/domain/assistant/assistant.role.md')
|
||||
fallbackRegistry.set('package:assistant', '@package://resource/domain/assistant/assistant.role.md')
|
||||
fallbackRegistry.set('assistant', '@package://resource/role/assistant/assistant.role.md')
|
||||
fallbackRegistry.set('package:assistant', '@package://resource/role/assistant/assistant.role.md')
|
||||
|
||||
logger.warn(`[PackageDiscovery] 🆘 使用回退资源: assistant`)
|
||||
return fallbackRegistry
|
||||
@ -292,23 +292,23 @@ class PackageDiscovery extends BaseDiscovery {
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫描domain目录(角色资源)
|
||||
* @param {string} domainDir - domain目录路径
|
||||
* 扫描role目录(角色资源)
|
||||
* @param {string} roleDir - role目录路径
|
||||
* @param {RegistryData} registryData - 注册表数据
|
||||
* @private
|
||||
*/
|
||||
async _scanDomainDirectory(domainDir, registryData) {
|
||||
const items = await fs.readdir(domainDir)
|
||||
async _scanRoleDirectory(roleDir, registryData) {
|
||||
const items = await fs.readdir(roleDir)
|
||||
|
||||
for (const item of items) {
|
||||
const itemPath = path.join(domainDir, item)
|
||||
const itemPath = path.join(roleDir, item)
|
||||
const stat = await fs.stat(itemPath)
|
||||
|
||||
if (stat.isDirectory()) {
|
||||
// 查找角色文件
|
||||
const roleFile = path.join(itemPath, `${item}.role.md`)
|
||||
if (await fs.pathExists(roleFile)) {
|
||||
const reference = `@package://resource/domain/${item}/${item}.role.md`
|
||||
const reference = `@package://resource/role/${item}/${item}.role.md`
|
||||
|
||||
const resourceData = new ResourceData({
|
||||
id: item,
|
||||
@ -334,7 +334,7 @@ class PackageDiscovery extends BaseDiscovery {
|
||||
const thoughtId = ResourceFileNaming.extractResourceId(thoughtFile, 'thought')
|
||||
if (thoughtId) {
|
||||
const fileName = path.basename(thoughtFile)
|
||||
const reference = `@package://resource/domain/${item}/thought/${fileName}`
|
||||
const reference = `@package://resource/role/${item}/thought/${fileName}`
|
||||
|
||||
const resourceData = new ResourceData({
|
||||
id: thoughtId,
|
||||
@ -360,7 +360,7 @@ class PackageDiscovery extends BaseDiscovery {
|
||||
for (const execFile of executionFiles) {
|
||||
if (execFile.endsWith('.execution.md')) {
|
||||
const execId = path.basename(execFile, '.execution.md')
|
||||
const reference = `@package://resource/domain/${item}/execution/${execFile}`
|
||||
const reference = `@package://resource/role/${item}/execution/${execFile}`
|
||||
|
||||
const resourceData = new ResourceData({
|
||||
id: execId,
|
||||
|
||||
@ -353,31 +353,31 @@ class ProjectDiscovery extends BaseDiscovery {
|
||||
* @private
|
||||
*/
|
||||
async _scanDirectory(resourcesDir, registryData) {
|
||||
// 扫描domain目录
|
||||
const domainDir = path.join(resourcesDir, 'domain')
|
||||
if (await this._fsExists(domainDir)) {
|
||||
await this._scanDomainDirectory(domainDir, registryData)
|
||||
// 扫描role目录
|
||||
const roleDir = path.join(resourcesDir, 'role')
|
||||
if (await this._fsExists(roleDir)) {
|
||||
await this._scanRoleDirectory(roleDir, registryData)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫描domain目录(项目角色资源)
|
||||
* @param {string} domainDir - domain目录路径
|
||||
* 扫描role目录(项目角色资源)
|
||||
* @param {string} roleDir - role目录路径
|
||||
* @param {RegistryData} registryData - 注册表数据
|
||||
* @private
|
||||
*/
|
||||
async _scanDomainDirectory(domainDir, registryData) {
|
||||
const items = await fs.readdir(domainDir)
|
||||
async _scanRoleDirectory(roleDir, registryData) {
|
||||
const items = await fs.readdir(roleDir)
|
||||
|
||||
for (const item of items) {
|
||||
const itemPath = path.join(domainDir, item)
|
||||
const itemPath = path.join(roleDir, item)
|
||||
const stat = await fs.stat(itemPath)
|
||||
|
||||
if (stat.isDirectory()) {
|
||||
// 查找role文件
|
||||
const roleFile = path.join(itemPath, `${item}.role.md`)
|
||||
if (await this._fsExists(roleFile)) {
|
||||
const reference = `@project://.promptx/resource/domain/${item}/${item}.role.md`
|
||||
const reference = `@project://.promptx/resource/role/${item}/${item}.role.md`
|
||||
|
||||
const resourceData = new ResourceData({
|
||||
id: item,
|
||||
@ -401,7 +401,7 @@ class ProjectDiscovery extends BaseDiscovery {
|
||||
for (const thoughtFile of thoughtFiles) {
|
||||
if (thoughtFile.endsWith('.thought.md')) {
|
||||
const thoughtId = path.basename(thoughtFile, '.thought.md')
|
||||
const reference = `@project://.promptx/resource/domain/${item}/thought/${thoughtFile}`
|
||||
const reference = `@project://.promptx/resource/role/${item}/thought/${thoughtFile}`
|
||||
|
||||
const resourceData = new ResourceData({
|
||||
id: thoughtId,
|
||||
@ -427,7 +427,7 @@ class ProjectDiscovery extends BaseDiscovery {
|
||||
for (const execFile of executionFiles) {
|
||||
if (execFile.endsWith('.execution.md')) {
|
||||
const execId = path.basename(execFile, '.execution.md')
|
||||
const reference = `@project://.promptx/resource/domain/${item}/execution/${execFile}`
|
||||
const reference = `@project://.promptx/resource/role/${item}/execution/${execFile}`
|
||||
|
||||
const resourceData = new ResourceData({
|
||||
id: execId,
|
||||
@ -453,7 +453,7 @@ class ProjectDiscovery extends BaseDiscovery {
|
||||
for (const knowledgeFile of knowledgeFiles) {
|
||||
if (knowledgeFile.endsWith('.knowledge.md')) {
|
||||
const knowledgeId = path.basename(knowledgeFile, '.knowledge.md')
|
||||
const reference = `@project://.promptx/resource/domain/${item}/knowledge/${knowledgeFile}`
|
||||
const reference = `@project://.promptx/resource/role/${item}/knowledge/${knowledgeFile}`
|
||||
|
||||
const resourceData = new ResourceData({
|
||||
id: knowledgeId,
|
||||
|
||||
@ -16,7 +16,7 @@ class PromptProtocol extends ResourceProtocol {
|
||||
this.registry = new Map([
|
||||
['protocols', '@package://resource/protocol/**/*.md'],
|
||||
['core', '@package://resource/core/**/*.md'],
|
||||
['domain', '@package://resource/domain/**/*.md'],
|
||||
['role', '@package://resource/role/**/*.md'],
|
||||
['resource', '@package://resource/resource/**/*.md'],
|
||||
['bootstrap', '@package://bootstrap.md']
|
||||
])
|
||||
@ -62,7 +62,7 @@ class PromptProtocol extends ResourceProtocol {
|
||||
examples: [
|
||||
'prompt://protocols',
|
||||
'prompt://core',
|
||||
'prompt://domain',
|
||||
'prompt://role',
|
||||
'prompt://bootstrap'
|
||||
],
|
||||
availableResources: Array.from(this.registry.keys()),
|
||||
@ -257,7 +257,7 @@ class PromptProtocol extends ResourceProtocol {
|
||||
const descriptions = {
|
||||
protocols: 'DPML协议规范文档',
|
||||
core: '核心思维和执行模式',
|
||||
domain: '领域专家角色定义',
|
||||
role: '角色定义和专家能力',
|
||||
resource: '资源管理和路径解析',
|
||||
bootstrap: 'PromptX启动引导文件'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user