feat: 优化鲁班角色并完善ToolSandbox工具开发体系

## 鲁班角色优化
- 新增tool-best-practices知识模块:工具设计最佳实践、性能优化、安全防护
- 新增dpml-tool-tagging知识模块:DPML工具标签四组件架构精通
- 增强craftsmanship思维模式:现代工具特征完善
- 资源迁移到包级别:支持跨项目共享

## ToolSandbox架构完善
- 实现ToolSandbox类:支持@tool://协议的三阶段执行流程
- 优化依赖管理:getDependencies()接口标准化
- 完善UserProtocol:支持@user://沙箱目录访问
- 增强工具发现:FilePatternDiscovery支持多种文件模式

## 工具生态建设
- 添加tool.tag.md:DPML工具标签框架完整定义
- 重构ToolInterface:统一getDependencies()接口规范
- 优化ToolExecutor:集成ToolSandbox执行流程
- 更新注册表:29个资源完整注册发现

## 技术架构改进
- pnpm依赖集成:自动化沙箱环境管理
- 协议系统完善:@tool://和@user://协议标准化
- 资源结构统一:包级别和项目级别一致性
- 开发流程标准化:从需求分析到质量保证的完整工作流

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
sean
2025-06-28 19:42:16 +08:00
parent 5f9fa4c92c
commit eea46a8ee1
20 changed files with 3250 additions and 536 deletions

View File

@ -190,12 +190,9 @@ class FilePatternDiscovery extends BaseDiscovery {
if (fileName.endsWith(extension)) {
const baseName = fileName.slice(0, -extension.length)
// role类型直接返回基础名称,其他类型添加前缀
if (resourceType === 'role') {
return baseName
} else {
return `${resourceType}:${baseName}`
}
// 所有资源类型直接返回基础名称,添加前缀
// 协议信息已经在resource对象的protocol字段中
return baseName
}
}

View File

@ -32,7 +32,7 @@ const getUserDirectories = () => {
/**
* 用户目录协议实现
* 实现@user://协议,用于访问用户的标准目录Documents、Desktop、Downloads等
* 实现@user://协议,直接映射到用户主目录,提供简洁的用户文件访问
*/
class UserProtocol extends ResourceProtocol {
constructor (options = {}) {
@ -74,18 +74,17 @@ class UserProtocol extends ResourceProtocol {
getProtocolInfo () {
return {
name: 'user',
description: '用户目录协议,提供跨平台的用户标准目录访问',
location: 'user://{directory}/{path}',
description: '用户目录协议,直接映射到用户主目录',
location: 'user://{path}',
examples: [
'user://documents/notes.txt',
'user://desktop/readme.md',
'user://downloads/',
'user://home/.bashrc',
'user://config/promptx.json',
'user://data/memories.json',
'user://cache/temp-data.json'
'user://.promptx/toolbox/text-analyzer',
'user://.bashrc',
'user://Documents/notes.txt',
'user://Desktop/readme.md',
'user://Downloads/file.zip',
'user://.promptx/config.json'
],
supportedDirectories: Object.keys(this.userDirs),
basePath: '用户主目录 (~)',
params: this.getSupportedParams()
}
}
@ -121,34 +120,25 @@ class UserProtocol extends ResourceProtocol {
/**
* 解析用户目录路径
* @param {string} resourcePath - 原始资源路径,如 "documents/notes.txt"
* @param {string} resourcePath - 原始资源路径,如 ".promptx/toolbox/test-tool"
* @param {QueryParams} queryParams - 查询参数
* @returns {Promise<string>} 解析后的绝对路径
*/
async resolvePath (resourcePath, queryParams) {
const parts = resourcePath.split('/')
const dirType = parts[0]
const relativePath = parts.slice(1).join('/')
// 验证目录类型
if (!this.userDirs[dirType]) {
throw new Error(`不支持的用户目录类型: ${dirType}。支持的类型: ${Object.keys(this.userDirs).join(', ')}`)
}
// 获取用户目录路径
const userDirPath = await this.getUserDirectory(dirType)
// 如果没有相对路径,返回目录本身
if (!relativePath) {
return userDirPath
// 直接使用用户主目录作为基础路径
const userHomeDir = getUserDirectories().getHomeFolder()
// 如果没有相对路径,返回用户主目录本身
if (!resourcePath) {
return userHomeDir
}
// 拼接完整路径
const fullPath = path.join(userDirPath, relativePath)
const fullPath = path.join(userHomeDir, resourcePath)
// 安全检查:确保路径在用户目录内
// 安全检查:确保路径在用户目录内
const resolvedPath = path.resolve(fullPath)
const resolvedUserDir = path.resolve(userDirPath)
const resolvedUserDir = path.resolve(userHomeDir)
if (!resolvedPath.startsWith(resolvedUserDir)) {
throw new Error(`安全错误:路径超出用户目录范围: ${resolvedPath}`)