优化角色注册,发现,nuwa 角色的提示词等
This commit is contained in:
329
docs/dpml-semantic-rendering-upgrade.md
Normal file
329
docs/dpml-semantic-rendering-upgrade.md
Normal file
@ -0,0 +1,329 @@
|
||||
# DPML语义渲染升级方案
|
||||
|
||||
## 📋 文档信息
|
||||
- **版本**: v1.0
|
||||
- **创建时间**: 2025-06-11
|
||||
- **作者**: Claude Code & Sean
|
||||
- **优先级**: High
|
||||
- **类型**: 架构升级
|
||||
|
||||
## 🎯 核心理念
|
||||
|
||||
**@引用 = 语义占位符**
|
||||
|
||||
DPML标签中的@引用不应该被视为"独立的资源",而应该被理解为"语义占位符",在渲染时在原始位置插入引用内容,保持标签的完整语义流程。
|
||||
|
||||
## 🔍 问题分析
|
||||
|
||||
### 当前实现的语义割裂
|
||||
|
||||
```xml
|
||||
<personality>
|
||||
@!thought://remember
|
||||
|
||||
# 网络杠精思维模式
|
||||
## 核心思维特征
|
||||
- 挑刺思维:看到任何观点都先找问题和漏洞
|
||||
- 抬杠本能:天生反对派,习惯性质疑一切表述
|
||||
|
||||
@!thought://recall
|
||||
|
||||
## 认知偏好模式
|
||||
- 逆向思考优先:遇到任何论点先想如何反驳
|
||||
- 细节放大镜效应:善于将小问题放大成大问题
|
||||
</personality>
|
||||
```
|
||||
|
||||
**当前渲染结果(割裂的)**:
|
||||
```
|
||||
## ✅ 🧠 思维模式:remember
|
||||
[remember的内容 - 100行]
|
||||
---
|
||||
|
||||
## ✅ 🧠 思维模式:recall
|
||||
[recall的内容 - 80行]
|
||||
---
|
||||
|
||||
## ✅ 🧠 思维模式:internet-debater-personality
|
||||
# 网络杠精思维模式
|
||||
## 核心思维特征
|
||||
- 挑刺思维:看到任何观点都先找问题和漏洞
|
||||
- 抬杠本能:天生反对派,习惯性质疑一切表述
|
||||
|
||||
## 认知偏好模式
|
||||
- 逆向思考优先:遇到任何论点先想如何反驳
|
||||
- 细节放大镜效应:善于将小问题放大成大问题
|
||||
---
|
||||
```
|
||||
|
||||
**问题**:
|
||||
1. **语义割裂**:完整的personality被分割成3个独立片段
|
||||
2. **位置语义丢失**:@引用的位置信息完全丢失
|
||||
3. **阅读体验差**:用户无法获得连贯的角色理解
|
||||
4. **违背用户意图**:用户精心设计的内容组织被破坏
|
||||
|
||||
## 💡 升级方案:语义占位符渲染
|
||||
|
||||
### 核心概念
|
||||
|
||||
**@引用 = 占位符**:在标签的原始位置插入引用内容,保持完整的语义流程。
|
||||
|
||||
### 理想渲染结果(完整的)
|
||||
|
||||
```
|
||||
## ✅ 🧠 完整思维模式:internet-debater
|
||||
|
||||
[remember的完整内容 - 100行记忆相关思维模式]
|
||||
|
||||
# 网络杠精思维模式
|
||||
## 核心思维特征
|
||||
- 挑刺思维:看到任何观点都先找问题和漏洞
|
||||
- 抬杠本能:天生反对派,习惯性质疑一切表述
|
||||
|
||||
[recall的完整内容 - 80行回忆相关思维模式]
|
||||
|
||||
## 认知偏好模式
|
||||
- 逆向思考优先:遇到任何论点先想如何反驳
|
||||
- 细节放大镜效应:善于将小问题放大成大问题
|
||||
|
||||
---
|
||||
```
|
||||
|
||||
**优势**:
|
||||
1. **语义完整性**:用户看到完整连贯的personality
|
||||
2. **位置语义保持**:内容按用户设计的顺序自然流淌
|
||||
3. **阅读体验优化**:连贯的角色理解体验
|
||||
4. **用户意图忠实**:完全按照用户的内容组织呈现
|
||||
|
||||
## 🔧 技术实现设计
|
||||
|
||||
### 1. 核心渲染算法
|
||||
|
||||
```javascript
|
||||
class SemanticRenderer {
|
||||
/**
|
||||
* 语义占位符渲染:将@引用替换为实际内容
|
||||
* @param {Object} tagSemantics - 标签语义结构
|
||||
* @param {ResourceManager} resourceManager - 资源管理器
|
||||
* @returns {string} 完整融合的语义内容
|
||||
*/
|
||||
async renderSemanticContent(tagSemantics, resourceManager) {
|
||||
let content = tagSemantics.fullSemantics // 保持原始标签内容结构
|
||||
|
||||
// 按出现顺序处理每个@引用(保持位置语义)
|
||||
for (const ref of tagSemantics.references) {
|
||||
try {
|
||||
// 解析引用内容
|
||||
const refContent = await resourceManager.resolveReference(ref)
|
||||
|
||||
// 在原始位置替换@引用为实际内容
|
||||
content = content.replace(ref.fullMatch, refContent)
|
||||
} catch (error) {
|
||||
// 引用解析失败时的优雅降级
|
||||
content = content.replace(ref.fullMatch, `<!-- 引用解析失败: ${ref.fullMatch} -->`)
|
||||
}
|
||||
}
|
||||
|
||||
return content.trim()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2. DPMLContentParser扩展
|
||||
|
||||
```javascript
|
||||
class DPMLContentParser {
|
||||
// 现有方法保持不变...
|
||||
|
||||
/**
|
||||
* 新增:获取引用的位置信息
|
||||
*/
|
||||
extractReferencesWithPosition(content) {
|
||||
const resourceRegex = /@([!?]?)([a-zA-Z][a-zA-Z0-9_-]*):\/\/([a-zA-Z0-9_\/.,-]+?)(?=[\s\)\],]|$)/g
|
||||
const matches = []
|
||||
let match
|
||||
|
||||
while ((match = resourceRegex.exec(content)) !== null) {
|
||||
matches.push({
|
||||
fullMatch: match[0],
|
||||
priority: match[1],
|
||||
protocol: match[2],
|
||||
resource: match[3],
|
||||
position: match.index, // 位置信息
|
||||
isRequired: match[1] === '!',
|
||||
isOptional: match[1] === '?'
|
||||
})
|
||||
}
|
||||
|
||||
return matches.sort((a, b) => a.position - b.position) // 按位置排序
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 3. ActionCommand升级
|
||||
|
||||
```javascript
|
||||
class ActionCommand {
|
||||
/**
|
||||
* 升级:生成语义完整的学习计划
|
||||
*/
|
||||
async generateSemanticLearningPlan(roleId, dependencies) {
|
||||
const { roleSemantics } = dependencies
|
||||
const renderer = new SemanticRenderer()
|
||||
|
||||
let content = `🎭 **角色激活完成:${roleId}** - 语义完整加载\n`
|
||||
|
||||
// 渲染完整的personality语义
|
||||
if (roleSemantics.personality) {
|
||||
content += `# 🧠 完整思维模式:${roleId}\n`
|
||||
const personalityContent = await renderer.renderSemanticContent(
|
||||
roleSemantics.personality,
|
||||
this.resourceManager
|
||||
)
|
||||
content += `${personalityContent}\n---\n`
|
||||
}
|
||||
|
||||
// 渲染完整的principle语义
|
||||
if (roleSemantics.principle) {
|
||||
content += `# ⚡ 完整执行模式:${roleId}\n`
|
||||
const principleContent = await renderer.renderSemanticContent(
|
||||
roleSemantics.principle,
|
||||
this.resourceManager
|
||||
)
|
||||
content += `${principleContent}\n---\n`
|
||||
}
|
||||
|
||||
// 渲染完整的knowledge语义
|
||||
if (roleSemantics.knowledge) {
|
||||
content += `# 📚 完整知识体系:${roleId}\n`
|
||||
const knowledgeContent = await renderer.renderSemanticContent(
|
||||
roleSemantics.knowledge,
|
||||
this.resourceManager
|
||||
)
|
||||
content += `${knowledgeContent}\n---\n`
|
||||
}
|
||||
|
||||
return content
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 📊 语义保障对比
|
||||
|
||||
### 升级前:语义割裂
|
||||
```
|
||||
独立片段1: remember内容 (100行)
|
||||
独立片段2: recall内容 (80行)
|
||||
独立片段3: 杠精思维 (50行)
|
||||
```
|
||||
**问题**: 用户无法理解这些片段的组织关系
|
||||
|
||||
### 升级后:语义完整
|
||||
```
|
||||
完整personality: remember内容 + 杠精思维 + recall内容 (230行)
|
||||
```
|
||||
**优势**: 用户获得完整连贯的角色理解
|
||||
|
||||
## 🎯 用户体验提升
|
||||
|
||||
### 1. **内容组织忠实性**
|
||||
用户精心设计的内容组织得到完全保持:
|
||||
- 引言 → @引用基础能力 → 核心特征 → @引用扩展能力 → 总结
|
||||
|
||||
### 2. **阅读连贯性**
|
||||
从分离的技术片段转变为连贯的角色叙述:
|
||||
- ❌ "这个角色有3个独立的思维片段"
|
||||
- ✅ "这个角色具有完整连贯的思维体系"
|
||||
|
||||
### 3. **角色理解深度**
|
||||
用户能够理解角色的完整图景,而不是零散的技能点。
|
||||
|
||||
## 🔧 实现阶段
|
||||
|
||||
### 阶段1:SemanticRenderer实现
|
||||
- 创建语义渲染器核心类
|
||||
- 实现占位符替换算法
|
||||
- 支持引用解析失败的优雅降级
|
||||
|
||||
### 阶段2:DPMLContentParser扩展
|
||||
- 添加位置信息提取
|
||||
- 增强引用解析能力
|
||||
- 保持向下兼容性
|
||||
|
||||
### 阶段3:ActionCommand集成
|
||||
- 更新学习计划生成逻辑
|
||||
- 集成语义渲染器
|
||||
- 全面测试各种角色类型
|
||||
|
||||
### 阶段4:全系统推广
|
||||
- 扩展到LearnCommand
|
||||
- 更新所有Protocol类
|
||||
- 建立统一的语义渲染标准
|
||||
|
||||
## 📝 测试策略
|
||||
|
||||
### 1. 语义完整性测试
|
||||
```javascript
|
||||
test('应该保持@引用的位置语义', async () => {
|
||||
const content = `intro @!thought://A middle @!thought://B end`
|
||||
const rendered = await renderer.renderSemanticContent(semantics, rm)
|
||||
expect(rendered).toBe(`intro [A的内容] middle [B的内容] end`)
|
||||
})
|
||||
```
|
||||
|
||||
### 2. 复杂布局测试
|
||||
```javascript
|
||||
test('应该处理复杂的@引用布局', async () => {
|
||||
const content = `
|
||||
# 标题
|
||||
@!thought://base
|
||||
|
||||
## 子标题
|
||||
- 列表项1
|
||||
@!execution://action
|
||||
- 列表项2
|
||||
`
|
||||
// 验证内容在正确位置插入
|
||||
})
|
||||
```
|
||||
|
||||
### 3. 错误处理测试
|
||||
```javascript
|
||||
test('应该优雅处理引用解析失败', async () => {
|
||||
// 验证失败时的降级策略
|
||||
})
|
||||
```
|
||||
|
||||
## 💡 长期价值
|
||||
|
||||
### 1. **DPML协议语义标准**
|
||||
这个升级建立了DPML协议中@引用的语义标准:
|
||||
- @引用 = 占位符,不是独立资源
|
||||
- 位置语义优于类型语义
|
||||
- 用户意图优于技术实现
|
||||
|
||||
### 2. **可扩展的语义框架**
|
||||
为未来的DPML扩展奠定基础:
|
||||
- 支持更复杂的引用类型
|
||||
- 支持条件渲染
|
||||
- 支持嵌套引用
|
||||
|
||||
### 3. **用户体验范式**
|
||||
从"技术驱动"转向"用户意图驱动"的设计范式。
|
||||
|
||||
## 🔗 相关文档
|
||||
|
||||
- [DPML基础协议](./dpml.protocol.md)
|
||||
- [角色内容解析问题](./issues/role-content-parsing-incomplete.md)
|
||||
- [ActionCommand架构设计](./action-command-architecture.md)
|
||||
|
||||
## ⚠️ 注意事项
|
||||
|
||||
1. **性能考虑**: 语义渲染涉及异步资源解析,需要考虑缓存策略
|
||||
2. **错误处理**: 引用解析失败时的用户体验设计
|
||||
3. **兼容性**: 确保现有角色的正常工作
|
||||
4. **文档更新**: 用户需要了解新的语义渲染效果
|
||||
|
||||
---
|
||||
|
||||
**这个升级将彻底解决DPML语义完整性问题,为PromptX建立真正以用户意图为中心的语义框架。**
|
||||
Reference in New Issue
Block a user