From b18983bdace5aa5e0ef56e40200c506de8032401 Mon Sep 17 00:00:00 2001 From: sean Date: Sat, 28 Jun 2025 14:26:25 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=B3=BB=E7=BB=9F=E6=80=A7?= =?UTF-8?q?=E7=A7=BB=E9=99=A4DACP=E6=9E=B6=E6=9E=84=20-=20=E7=AE=80?= =?UTF-8?q?=E5=8C=96=E6=A1=86=E6=9E=B6=E4=B8=93=E6=B3=A8@tool=E5=8D=8F?= =?UTF-8?q?=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🗑️ 核心清理 - 完全移除DACP服务架构和HTTP模式 - 删除DACPCommand、DACPConfigManager等核心组件 - 清理所有DACP相关文件、测试和文档 - 从CLI移除dacp命令,精简为6大核心锦囊 📁 删除内容 Core: - src/dacp/ - 整个DACP服务目录 - src/lib/core/pouch/commands/DACPCommand.js - src/lib/utils/DACPConfigManager.js Tests: - src/tests/commands/DACPCommand.unit.test.js - src/tests/integration/dacp-integration.test.js - src/tests/e2e/dacp-*-e2e.test.js - src/tests/unit/DACPConfigManager.unit.test.js Scripts & Docs: - scripts/test-*dacp*.js - docs/dacp-*.md - prompt/core/dacp-*.execution.md 🔧 代码清理 CLI: - src/bin/promptx.js: 移除dacp命令和--with-dacp选项 - 帮助信息更新:7大命令→6大核心命令 Core: - src/lib/core/pouch/PouchCLI.js: 移除dacp命令注册 - src/lib/core/pouch/commands/index.js: 清理DACPCommand引用 MCP: - src/lib/mcp/toolDefinitions.js: 移除promptx_dacp工具定义 - src/lib/commands/MCPServerCommand.js: 清理所有DACP方法和引用 - src/lib/commands/MCPStreamableHttpCommand.js: 移除DACP参数映射 Registry: - src/package.registry.json: 自动更新,移除2个DACP execution资源 - package.json: 移除dacp相关npm脚本 📊 架构简化结果 - 资源总数:63个 → 61个 (移除2个DACP execution) - CLI命令:7个 → 6大核心锦囊 - 代码复杂度显著降低,专注核心功能 ✅ 验证通过 - @tool://calculator 计算功能正常: 6 × 7 = 42 - @tool://send-email 邮件工具正常 - MCP Server启动正常 - 所有锦囊命令工作正常 🎯 新架构重点 1. 角色系统 - AI专业能力激活 2. 记忆系统 - 知识学习和回忆 3. @tool协议 - JavaScript工具执行 4. MCP集成 - AI应用连接 💡 技术收益 - 移除HTTP服务复杂度 - 统一@tool协议标准 - 简化维护和扩展 - 提升性能和稳定性 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- docs/dacp-config-management.md | 254 ---- docs/dacp-whitepaper.md | 1030 ----------------- package.json | 3 - prompt/core/dacp-email-sending.execution.md | 156 --- prompt/core/dacp-service-calling.execution.md | 241 ---- scripts/test-dacp-calculator.js | 52 - scripts/test-mcp-dacp.js | 79 -- src/bin/promptx.js | 41 +- .../dacp-promptx-service/DACP-API-GUIDE.md | 256 ---- src/dacp/dacp-promptx-service/README.md | 93 -- .../actions/calculator.js | 98 -- .../dacp-promptx-service/actions/email.js | 250 ---- .../dacp-promptx-service/dacp.config.json | 48 - src/dacp/dacp-promptx-service/server.js | 153 --- src/lib/commands/MCPServerCommand.js | 260 +---- src/lib/commands/MCPStreamableHttpCommand.js | 1 - src/lib/core/pouch/PouchCLI.js | 1 - src/lib/core/pouch/commands/DACPCommand.js | 282 ----- src/lib/core/pouch/commands/index.js | 2 - src/lib/mcp/toolDefinitions.js | 40 - src/lib/utils/DACPConfigManager.js | 360 ------ src/package.registry.json | 404 +++---- src/tests/commands/DACPCommand.unit.test.js | 268 ----- src/tests/e2e/dacp-calculator-e2e.test.js | 77 -- src/tests/e2e/dacp-email-e2e.test.js | 122 -- .../integration/dacp-integration.test.js | 141 --- src/tests/unit/DACPConfigManager.unit.test.js | 226 ---- test-tool-validation.js | 31 - test-tool.js | 19 - 29 files changed, 196 insertions(+), 4792 deletions(-) delete mode 100644 docs/dacp-config-management.md delete mode 100644 docs/dacp-whitepaper.md delete mode 100644 prompt/core/dacp-email-sending.execution.md delete mode 100644 prompt/core/dacp-service-calling.execution.md delete mode 100755 scripts/test-dacp-calculator.js delete mode 100755 scripts/test-mcp-dacp.js delete mode 100644 src/dacp/dacp-promptx-service/DACP-API-GUIDE.md delete mode 100644 src/dacp/dacp-promptx-service/README.md delete mode 100644 src/dacp/dacp-promptx-service/actions/calculator.js delete mode 100644 src/dacp/dacp-promptx-service/actions/email.js delete mode 100644 src/dacp/dacp-promptx-service/dacp.config.json delete mode 100644 src/dacp/dacp-promptx-service/server.js delete mode 100644 src/lib/core/pouch/commands/DACPCommand.js delete mode 100644 src/lib/utils/DACPConfigManager.js delete mode 100644 src/tests/commands/DACPCommand.unit.test.js delete mode 100644 src/tests/e2e/dacp-calculator-e2e.test.js delete mode 100644 src/tests/e2e/dacp-email-e2e.test.js delete mode 100644 src/tests/integration/dacp-integration.test.js delete mode 100644 src/tests/unit/DACPConfigManager.unit.test.js delete mode 100644 test-tool-validation.js delete mode 100644 test-tool.js diff --git a/docs/dacp-config-management.md b/docs/dacp-config-management.md deleted file mode 100644 index ec0e878..0000000 --- a/docs/dacp-config-management.md +++ /dev/null @@ -1,254 +0,0 @@ -# DACP配置管理指南 - -**版本**: 1.0.0 -**更新日期**: 2025-01-19 -**作者**: Sean - ---- - -## 概述 - -DACP配置管理系统支持分层配置策略,实现了项目级配置优先、用户级配置回退的灵活配置管理机制。这允许团队在项目中共享配置,同时保持个人配置的独立性。 - -## 配置优先级 - -``` -项目级配置 (.promptx/dacp/) > 用户级配置 (~/.promptx/dacp/) -``` - -### 优先级说明 - -1. **项目级配置** - 位于当前项目的 `.promptx/dacp/` 目录 - - 优先级最高 - - 适合团队共享的项目配置 - - 可以版本控制管理 - -2. **用户级配置** - 位于用户主目录的 `~/.promptx/dacp/` 目录 - - 作为回退选择 - - 个人私有配置 - - 跨项目通用配置 - -## 配置文件结构 - -### 邮件服务配置示例 (send_email.json) - -```json -{ - "provider": "gmail", - "smtp": { - "user": "your-email@gmail.com", - "password": "your-app-password" - }, - "sender": { - "name": "Your Name", - "email": "your-email@gmail.com" - } -} -``` - -### 支持的邮件服务商 - -- **Gmail**: smtp.gmail.com:587 -- **Outlook**: smtp-mail.outlook.com:587 -- **QQ邮箱**: smtp.qq.com:465 -- **163邮箱**: smtp.163.com:465 -- **126邮箱**: smtp.126.com:465 - -## 使用方式 - -### 1. 项目级配置(推荐) - -创建项目级配置文件: - -```bash -# 创建配置目录 -mkdir -p .promptx/dacp - -# 创建邮件配置文件 -cat > .promptx/dacp/send_email.json << 'EOF' -{ - "provider": "gmail", - "smtp": { - "user": "project-team@gmail.com", - "password": "project-app-password" - }, - "sender": { - "name": "Project Team", - "email": "project-team@gmail.com" - } -} -EOF -``` - -### 2. 用户级配置(个人回退) - -创建用户级配置文件: - -```bash -# 创建用户配置目录 -mkdir -p ~/.promptx/dacp - -# 创建个人邮件配置 -cat > ~/.promptx/dacp/send_email.json << 'EOF' -{ - "provider": "gmail", - "smtp": { - "user": "personal@gmail.com", - "password": "personal-app-password" - }, - "sender": { - "name": "Personal Name", - "email": "personal@gmail.com" - } -} -EOF -``` - -## Gmail配置特别说明 - -### 应用专用密码设置 - -Gmail用户需要使用应用专用密码: - -1. 进入 [Google 账户设置](https://myaccount.google.com) -2. 启用两步验证 -3. 生成应用专用密码 -4. 在配置文件中使用生成的密码 - -### 配置示例 - -```json -{ - "provider": "gmail", - "smtp": { - "user": "yourname@gmail.com", - "password": "abcd efgh ijkl mnop" // 应用专用密码(16位,含空格) - }, - "sender": { - "name": "Your Name", - "email": "yourname@gmail.com" - } -} -``` - -## 配置管理命令 - -### 检查配置状态 - -```javascript -const DACPConfigManager = require('./src/lib/utils/DACPConfigManager') -const configManager = new DACPConfigManager() - -// 检查是否有配置(任意级别) -const hasConfig = await configManager.hasActionConfig('send_email') - -// 检查项目级配置 -const hasProjectConfig = await configManager.hasProjectActionConfig('send_email') - -// 检查用户级配置 -const hasUserConfig = await configManager.hasUserActionConfig('send_email') -``` - -### 读取配置 - -```javascript -// 读取配置(自动优先级选择) -const config = await configManager.readActionConfig('send_email') - -// 明确读取项目级配置 -const projectConfig = await configManager.readProjectActionConfig('send_email') - -// 明确读取用户级配置 -const userConfig = await configManager.readUserActionConfig('send_email') -``` - -### 写入配置 - -```javascript -const emailConfig = { - provider: "gmail", - smtp: { - user: "example@gmail.com", - password: "app-password" - }, - sender: { - name: "Example User", - email: "example@gmail.com" - } -} - -// 写入项目级配置 -await configManager.writeProjectActionConfig('send_email', emailConfig) - -// 写入用户级配置 -await configManager.writeUserActionConfig('send_email', emailConfig) -``` - -## 最佳实践 - -### 1. 团队协作 - -- **项目配置**: 使用通用的项目配置,可以提交到版本控制 -- **敏感信息**: 个人敏感信息(如密码)使用用户级配置 -- **配置模板**: 在项目中提供配置模板,团队成员复制后修改 - -### 2. 安全性 - -- **不要提交密码**: 项目级配置可以包含结构,但不应包含真实密码 -- **使用应用密码**: Gmail等服务使用应用专用密码 -- **权限控制**: 确保配置文件权限设置合理 - -### 3. 配置继承 - -当前版本支持完全覆盖模式: -- 如果存在项目级配置,完全使用项目级配置 -- 如果不存在项目级配置,回退到用户级配置 -- 未来版本可能支持配置合并模式 - -## 错误处理 - -### 常见错误和解决方案 - -1. **配置文件不存在** - ``` - 解决方案: 按照上述步骤创建配置文件 - ``` - -2. **项目目录无法获取** - ``` - 解决方案: 确保在PromptX项目目录中运行,或使用用户级配置 - ``` - -3. **SMTP认证失败** - ``` - 解决方案: 检查用户名、密码和服务器配置 - ``` - -4. **Gmail应用密码问题** - ``` - 解决方案: 重新生成应用专用密码,确保格式正确 - ``` - -## 版本兼容性 - -- **向后兼容**: 现有用户级配置继续工作 -- **API兼容**: 原有API方法保持不变 -- **渐进升级**: 可以逐步迁移到项目级配置 - -## 扩展功能 - -### 未来规划 - -1. **配置合并模式**: 支持项目级和用户级配置的智能合并 -2. **配置验证**: 增强的配置验证和错误提示 -3. **配置模板**: 内置常用配置模板 -4. **环境变量支持**: 支持通过环境变量覆盖配置 -5. **配置加密**: 敏感信息的加密存储 - ---- - -## 参考资料 - -- [DACP白皮书](./dacp-whitepaper.md) -- [MCP集成指南](./mcp-integration-guide.md) -- [PromptX架构原理](./promptx-architecture-principle.md) \ No newline at end of file diff --git a/docs/dacp-whitepaper.md b/docs/dacp-whitepaper.md deleted file mode 100644 index d8e486c..0000000 --- a/docs/dacp-whitepaper.md +++ /dev/null @@ -1,1030 +0,0 @@ -# DACP白皮书 -## Deepractice Agent Context Protocol - -**版本**: 1.0.0-draft -**作者**: Deepractice Team -**创建日期**: 2024-12-17 -**更新日期**: 2025-01-19 - ---- - -## 摘要 - -DACP(Deepractice Agent Context Protocol)是一种基于MCP协议的AI智能体上下文协议,旨在解决AI应用中"能说会道但无法行动"的核心痛点。通过提供结构化的execution执行框架,DACP实现了从"AI建议"到"AI行动"的关键跃迁,为用户提供可预期、可评估的专业服务解决方案。 - -## 目录 - -1. [背景与动机](#1-背景与动机) -2. [核心概念](#2-核心概念) -3. [架构设计](#3-架构设计) -4. [协议规范](#4-协议规范) -5. [实现指南](#5-实现指南) -6. [生态建设](#6-生态建设) -7. [案例研究](#7-案例研究) -8. [未来展望](#8-未来展望) - ---- - -## 1. 背景与动机 - -### 1.1 现状分析 - -当前AI应用生态面临的核心挑战: - -#### **MCP协议的局限性** -- **功能导向**: MCP专注于"What can you do?",提供工具能力 -- **冷冰冰的交互**: 工具描述技术化,缺乏专业身份感 -- **学习成本高**: 用户需要理解复杂的工具参数和使用方式 -- **角色分离**: AI人格与工具能力相互独立,无法形成专业服务闭环 - -#### **用户需求的演进** -- 从"使用AI工具"到"获得AI服务" -- 从"技术能力"到"专业解决方案" -- 从"参数配置"到"自然语言需求" -- 从"一次性交互"到"持续专业关系" - -### 1.2 DACP的价值主张 - -DACP通过以下核心创新解决上述挑战: - -```mermaid -graph LR - A[MCP: Model Context] --> B[工具集合] - C[DACP: Agent Context] --> D[专业服务] - - B --> E[What can you do?] - D --> F[Who are you + What can you do?] - - style C fill:#e1f5fe - style D fill:#f3e5f5 -``` - -#### **范式转移** -- **从工具到服务**: 不是提供工具,而是提供专业服务 -- **从功能到身份**: 不是说明功能,而是体现专业身份 -- **从参数到对话**: 不是配置参数,而是自然语言交流 -- **从使用到委托**: 不是学习使用,而是委托专业处理 - ---- - -## 2. 核心概念 - -### 2.1 Agent Context(智能体上下文) - -#### **定义** -Agent Context是AI智能体在特定专业领域中的完整身份定义,包括: -- **专业人格**: 角色定位、性格特征、沟通风格 -- **专业知识**: 领域知识、最佳实践、经验积累 -- **专业能力**: 可执行的工具服务、解决方案能力 -- **专业记忆**: 历史经验、用户偏好、上下文记忆 - -#### **与Model Context的区别** - -| 维度 | Model Context (MCP) | Agent Context (DACP) | -|------|---------------------|----------------------| -| **关注点** | 模型能力扩展 | 智能体身份构建 | -| **交互方式** | 工具调用 | 专业服务 | -| **用户体验** | 学习工具使用 | 委托专业处理 | -| **价值定位** | 功能增强 | 身份服务 | - -### 2.2 DACP服务包 - -#### **服务包构成** -``` -DACP服务包 = PromptX角色 + 专用工具 + 绑定关系 -``` - -- **PromptX角色**: 基于DPML协议的专业AI角色定义 -- **专用工具**: 为该角色定制的执行能力工具集 -- **绑定关系**: 角色与工具的语义绑定和使用说明 - -#### **服务包特征** -- **专业性**: 针对特定领域的深度专业化 -- **完整性**: 从理解到执行的完整服务闭环 -- **可组合**: 支持多服务协作和能力组合 -- **可扩展**: 支持动态加载和能力扩展 - -### 2.3 核心设计原则 - -#### **2.3.1 角色优先原则** -``` -技术服务于体验,工具服务于角色 -``` -- 所有工具都通过角色身份来表达 -- 用户感知的是专业服务,而非技术工具 -- 角色人格决定交互风格和服务质量 - -#### **2.3.2 自然交互原则** -``` -用户说需求,AI提供服务 -``` -- 用户使用自然语言描述需求 -- AI角色智能理解并执行相应服务 -- 避免复杂的参数配置和技术细节 - -#### **2.3.3 专业服务原则** -``` -不是工具使用者,而是专业服务提供者 -``` -- 每个DACP服务都是完整的专业解决方案 -- 角色承担专业责任,提供专业建议 -- 服务质量符合专业标准和行业最佳实践 - -#### **2.3.4 生态协作原则** -``` -开放标准,协作共赢 -``` -- 标准化的协议接口,支持第三方扩展 -- 基于PromptX角色生态,复用成熟的角色资源 -- 鼓励开发者贡献专业服务包 - ---- - -## 3. 架构设计 - -### 3.1 整体架构 - -```mermaid -graph TD - A[用户] --> B[AI客户端] - B --> C[PromptX MCP Server] - C --> D[promptx_dacp工具] - D --> E[DACP路由器] - E --> F[DACP服务注册表] - E --> G[DACP服务包] - - subgraph "PromptX核心" - H[角色系统] - I[记忆系统] - J[知识系统] - end - - subgraph "DACP服务生态" - K[邮件服务包] - L[日程服务包] - M[文档服务包] - N[自定义服务包...] - end - - G --> H - G --> I - G --> J - - G --> K - G --> L - G --> M - G --> N -``` - -### 3.2 核心组件 - -#### **3.2.1 DACP路由器** -- **服务发现**: 自动发现可用的DACP服务 -- **意图识别**: 分析用户需求,匹配合适的服务 -- **负载均衡**: 在多个服务实例间分发请求 -- **错误处理**: 统一的错误处理和降级策略 - -#### **3.2.2 服务注册表** -- **服务注册**: DACP服务的动态注册和注销 -- **元数据管理**: 服务能力、版本、依赖等信息 -- **健康检查**: 服务可用性监控和状态管理 -- **版本管理**: 服务版本兼容性和升级策略 - -#### **3.2.3 Execution执行引擎** -- **约束验证**: 检查请求是否违反客观限制条件 -- **规则执行**: 强制执行必须遵守的行为准则 -- **指导应用**: 基于最佳实践优化执行方案 -- **流程执行**: 按照定义的步骤完成任务 -- **标准评估**: 根据criteria评估执行结果质量 - -### 3.3 数据流设计 - -#### **请求处理流程** -```mermaid -sequenceDiagram - participant U as 用户 - participant C as AI客户端 - participant P as PromptX - participant D as DACP路由器 - participant S as DACP服务 - - U->>C: "帮我给张三发邮件" - C->>P: promptx_dacp调用 - P->>D: 服务路由请求 - D->>D: 意图识别与服务匹配 - D->>S: 路由到邮件服务 - S->>S: 加载execution配置 - S->>S: 约束检查+规则验证 - S->>S: 指导应用+流程执行 - S->>S: 标准评估+结果生成 - S->>D: execution执行结果 - D->>P: 结构化响应 - P->>C: 执行结果报告 - C->>U: "邮件发送完成,符合所有执行标准..." -``` - ---- - -## 4. 协议规范 - -### 4.1 DACP服务标识 - -#### **服务ID规范** -``` -格式: dacp-{domain}-service -示例: -- dacp-email-service -- dacp-calendar-service -- dacp-document-service -``` - -#### **版本管理** -``` -语义化版本: major.minor.patch -示例: 1.2.3 -- major: 不兼容的API变更 -- minor: 向后兼容的功能新增 -- patch: 向后兼容的问题修复 -``` - -### 4.2 调用协议 - -#### **promptx_dacp工具接口** -```json -{ - "name": "promptx_dacp", - "description": "调用DACP专业服务,让PromptX角色拥有执行能力", - "inputSchema": { - "type": "object", - "properties": { - "service_id": { - "type": "string", - "description": "DACP服务ID" - }, - "action": { - "type": "string", - "description": "具体操作" - }, - "parameters": { - "type": "object", - "properties": { - "user_request": { - "type": "string", - "description": "用户自然语言需求" - }, - "context": { - "type": "object", - "description": "上下文信息" - } - } - } - }, - "required": ["service_id", "action", "parameters"] - } -} -``` - -#### **请求/响应格式** -```typescript -// DACP请求格式 -interface DACPRequest { - service_id: string; // 服务标识 - action: string; // 操作名称 - parameters: { - user_request: string; // 用户自然语言需求 - context: object; // 上下文信息 - }; - request_id?: string; // 可选的请求ID - timeout?: number; // 可选的超时时间(毫秒) -} - -// DACP响应格式 -interface DACPResponse { - request_id: string; - success: boolean; - data?: { - execution_result: object; // 执行结果 - evaluation: object; // 标准评估结果 - applied_guidelines: string[]; // 应用的指导原则 - performance_metrics: object; // 性能指标 - }; - error?: { - code: string; - message: string; - details?: object; - }; -} -``` - -### 4.3 服务端协议 - -#### **DACP服务配置文件** -```json -{ - "id": "dacp-email-service", - "name": "邮件发送服务", - "version": "1.0.0", - "description": "基于execution框架的邮件处理服务", - "author": "example@company.com", - "execution": { - "constraint": [ - "SMTP服务器连接限制每分钟100次", - "单封邮件大小不超过25MB", - "发送频率限制每分钟最多50封", - "必须支持TLS加密连接" - ], - "rule": [ - "必须验证收件人邮箱格式有效性", - "禁止发送包含垃圾邮件特征的内容", - "必须记录邮件发送日志用于审计", - "敏感信息必须加密传输" - ], - "guideline": [ - "建议使用HTML格式提升邮件阅读体验", - "建议根据收件人类型调整语言风格", - "建议添加邮件签名提升专业形象", - "建议根据紧急程度设置邮件优先级" - ], - "process": [ - "1. 解析用户自然语言邮件需求", - "2. 验证收件人信息和权限", - "3. 根据场景和指导原则生成邮件内容", - "4. 应用安全规则和格式约束", - "5. 调用SMTP服务发送邮件", - "6. 记录发送日志并返回结果状态" - ], - "criteria": [ - "邮件成功送达率必须 > 95%", - "发送响应时间必须 < 3秒", - "错误信息必须准确且用户可理解", - "邮件格式必须符合RFC标准" - ] - }, - "actions": [ - { - "name": "send_email", - "description": "按照execution框架发送邮件", - "parameters": { - "type": "object", - "properties": { - "user_request": { - "type": "string", - "description": "用户的自然语言邮件需求" - }, - "context": { - "type": "object", - "properties": { - "contacts": {"type": "array", "description": "联系人信息"}, - "project": {"type": "string", "description": "项目上下文"}, - "urgency": {"type": "string", "description": "紧急程度"} - } - } - } - } - } - ], - "endpoints": { - "http": "http://localhost:3001/dacp", - "websocket": "ws://localhost:3001/dacp" - } -} -``` - -#### **服务端接口规范** -```typescript -interface DACPServiceInterface { - // 服务信息查询 - getInfo(): Promise; - - // 健康检查 - healthCheck(): Promise; - - // 执行服务 - execute(request: DACPRequest): Promise; - - // 获取支持的操作列表 - getActions(): Promise; -} -``` - -### 4.4 错误处理标准 - -#### **错误代码规范** -``` -格式: DACP_[CATEGORY]_[SPECIFIC_ERROR] - -分类: -- AUTH: 认证相关错误 -- PARAM: 参数相关错误 -- SERVICE: 服务相关错误 -- ROLE: 角色相关错误 -- TIMEOUT: 超时相关错误 -``` - -#### **标准错误码** -```json -{ - "DACP_AUTH_INVALID_TOKEN": "无效的认证令牌", - "DACP_PARAM_MISSING_REQUIRED": "缺少必需参数", - "DACP_PARAM_INVALID_FORMAT": "参数格式无效", - "DACP_SERVICE_UNAVAILABLE": "服务暂时不可用", - "DACP_SERVICE_NOT_FOUND": "服务未找到", - "DACP_ROLE_ACTIVATION_FAILED": "角色激活失败", - "DACP_TIMEOUT_REQUEST": "请求超时", - "DACP_TIMEOUT_SERVICE": "服务响应超时" -} -``` - ---- - -## 5. 实现指南 - -### 5.1 开发环境准备 - -#### **前置条件** -- 基本的API开发经验 -- 了解DPML execution框架概念 - -#### **开发工具和环境(概念设计)** -DACP服务开发可以使用任何技术栈,只需要遵循协议规范: - -**未来规划的工具链**: -- DACP CLI工具(概念阶段,用于项目初始化和管理) -- execution框架解析器(概念阶段,解析.execution.md文件) -- 协议验证工具(概念阶段,验证服务是否符合DACP规范) -- 服务模板生成器(概念阶段,快速生成服务骨架) - -**理想的项目初始化流程**: -``` -1. 选择技术栈(Node.js/Python/Go/Java等) -2. 定义execution框架 -3. 实现协议接口 -4. 配置服务端点 -5. 注册和部署 - -注:以上流程为概念设计,具体工具尚在规划中 -``` - -### 5.2 创建DACP服务 - -基于execution框架的DACP服务开发流程: - -#### **标准项目结构** -``` -dacp-email-service/ -├── dacp.config.json # DACP服务配置文件 -├── execution/ # execution框架定义 -│ └── email-service.execution.md -├── src/ # 服务实现(技术栈无关) -│ ├── main.* # 服务入口点 -│ ├── execution-engine.* # execution框架执行引擎 -│ └── tools/ # 具体工具实现 -│ ├── email-client.* -│ ├── validator.* -│ └── template.* -├── tests/ # 测试文件 -├── docs/ # 服务文档 -└── deployment/ # 部署配置 -``` - -**技术栈灵活性**: -- 实现语言:Node.js、Python、Go、Java、Rust等 -- 部署方式:Docker容器、云函数、传统服务器 -- 存储方案:根据需要选择数据库或文件系统 - -#### **步骤1: 服务配置定义** -```json -// dacp.config.json - DACP服务配置文件 -{ - "id": "dacp-email-service", - "name": "邮件发送服务", - "version": "1.0.0", - "description": "基于execution框架的专业邮件处理服务", - "execution_source": "./execution/email-service.execution.md", - "endpoints": { - "http": "http://localhost:3001/dacp", - "health": "http://localhost:3001/health" - }, - "actions": [ - "send_email", - "validate_email", - "get_status" - ], - "metadata": { - "category": "communication", - "tags": ["email", "smtp", "messaging"], - "author": "example@company.com" - } -} -``` - -#### **步骤2: 实现服务逻辑** - -基于execution框架的DACP服务执行流程: - -``` -伪代码:EmailService执行逻辑 - -FUNCTION send_email(user_request, context): - // 按照execution框架的优先级顺序执行 - - 1. 约束验证(最高优先级) - 检查SMTP连接限制、邮件大小、发送频率等客观限制 - IF 违反约束 THEN 返回错误 - - 2. 规则执行(次高优先级) - 验证邮箱格式、检查垃圾邮件特征、安全规则等 - IF 违反规则 THEN 返回错误 - - 3. 指导原则应用(建议性) - 优化邮件格式、调整语言风格、添加签名等 - 增强用户请求 = 应用指导原则(user_request) - - 4. 流程执行(核心逻辑) - 解析需求 → 验证收件人 → 生成内容 → 发送邮件 → 记录日志 - 执行结果 = 按步骤执行(增强用户请求, context) - - 5. 标准评估(质量验证) - 检查送达率、响应时间、格式规范等标准 - 评估结果 = 评估执行质量(执行结果) - - RETURN { - execution_result: 执行结果, - evaluation: 评估结果, - applied_guidelines: 应用的指导原则列表 - } -``` - -**核心设计思想**: -- **优先级驱动**:严格按照constraint > rule > guideline > process > criteria的顺序 -- **失败快速**:约束和规则检查失败时立即停止执行 -- **质量保证**:每次执行都有明确的评估标准 -- **可追溯性**:记录应用的指导原则和执行路径 - -#### **步骤3: 创建execution定义** -```markdown - -# 邮件服务执行单元 - -## 执行框架定义 - - - - - SMTP服务器连接限制每分钟100次 - - 单封邮件大小不超过25MB - - 发送频率限制每分钟最多50封 - - 必须支持TLS加密连接 - - - - - 必须验证收件人邮箱格式有效性 - - 禁止发送包含垃圾邮件特征的内容 - - 必须记录邮件发送日志用于审计 - - 敏感信息必须加密传输 - - - - - 建议使用HTML格式提升邮件阅读体验 - - 建议根据收件人类型调整语言风格 - - 建议添加邮件签名提升专业形象 - - 建议根据紧急程度设置邮件优先级 - - - - 1. 解析用户自然语言邮件需求 - 2. 验证收件人信息和权限 - 3. 根据场景和指导原则生成邮件内容 - 4. 应用安全规则和格式约束 - 5. 调用SMTP服务发送邮件 - 6. 记录发送日志并返回结果状态 - - - - - 邮件成功送达率必须 > 95% - - 发送响应时间必须 < 3秒 - - 错误信息必须准确且用户可理解 - - 邮件格式必须符合RFC标准 - - - -## 工具接口定义 -- **send_email(to, subject, body, options)**: 执行邮件发送 -- **validate_email(address)**: 验证邮箱格式 -- **get_smtp_status()**: 检查SMTP服务状态 -- **log_email_activity(data)**: 记录邮件活动日志 -``` - -#### **步骤4: 测试和验证** - -**服务启动(概念设计)**: -```bash -# 启动DACP服务(未来CLI工具概念) -dacp start - -# 查看服务状态(未来CLI工具概念) -dacp status - -注:dacp CLI工具目前为概念设计,尚未开发 -``` - -**接口测试**: -``` -POST /dacp HTTP/1.1 -Content-Type: application/json - -{ - "service_id": "dacp-email-service", - "action": "send_email", - "parameters": { - "user_request": "给张三发个会议提醒", - "context": { - "contacts": [{"name": "张三", "email": "zhang@company.com"}], - "urgency": "high" - } - } -} -``` - -**预期响应格式**: -```json -{ - "success": true, - "data": { - "execution_result": { - "message_id": "msg_123", - "status": "sent", - "recipient": "zhang@company.com" - }, - "evaluation": { - "criteria_met": true, - "performance": {"response_time": "1.2s"} - }, - "applied_guidelines": ["HTML格式", "高优先级"] - } -} -``` - -### 5.3 部署和集成 - -#### **服务部署流程** - -**注册和发现(概念设计)**: -```bash -# 注册服务到DACP注册中心(概念阶段) -dacp register ./dacp.config.json - -# 验证服务注册状态(概念阶段) -dacp services --list - -# 启动服务实例(概念阶段) -dacp start --config ./dacp.config.json - -注:以上命令为DACP生态的概念设计,相关工具和注册中心尚未开发 -``` - -**部署模式**: -- **本地开发**:直接运行服务进程 -- **容器部署**:Docker/Kubernetes环境 -- **云函数**:Serverless部署模式 -- **边缘计算**:IoT设备本地服务 - -#### **与PromptX集成使用** -``` -用户: "帮我给张三发个邮件提醒明天的会议" - -PromptX角色系统: 理解用户意图,识别为邮件发送需求 - -promptx_dacp工具调用: { - "service_id": "dacp-email-service", - "action": "send_email", - "parameters": { - "user_request": "帮我给张三发个邮件提醒明天的会议", - "context": {"project": "当前项目", "contacts": [...]} - } -} - -DACP服务执行: -1. constraint检查 → 2. rule验证 → 3. guideline应用 → 4. process执行 → 5. criteria评估 - -返回给PromptX: { - "success": true, - "data": { - "execution_result": { - "message_id": "msg_123", - "status": "sent", - "recipient": "zhang@company.com", - "subject": "明天产品评审会议提醒" - }, - "evaluation": { - "criteria_met": true, - "performance": { - "delivery_rate": 100, - "response_time": "1.2s" - } - }, - "applied_guidelines": ["HTML格式", "专业签名", "高优先级"] - } -} - -用户得到反馈: "邮件已发送给张三,提醒明天的会议,符合所有执行标准。" -``` - ---- - -## 6. 生态建设 - -### 6.1 开发者生态 - -#### **DACP服务商店** -- **官方服务包**: Deepractice维护的核心服务包 -- **社区贡献**: 开发者贡献的开源服务包 -- **企业定制**: 针对特定行业的专业服务包 -- **质量认证**: 服务包的质量评级和认证体系 - -#### **开发者激励机制** -```mermaid -graph TD - A[优质服务包] --> B[社区认可] - B --> C[下载量增长] - C --> D[开发者声誉] - D --> E[商业机会] - - A --> F[官方推荐] - F --> G[流量扶持] - G --> H[技术支持] - - style A fill:#e1f5fe - style E fill:#f3e5f5 -``` - -#### **质量保证体系** -- **代码审查**: 自动化代码质量检查 -- **安全扫描**: 依赖库和代码安全扫描 -- **性能测试**: 服务响应时间和并发能力测试 -- **用户反馈**: 用户评价和使用反馈收集 - -### 6.2 治理机制 - -#### **DACP标准委员会** -- **组织结构**: Deepractice主导,社区参与 -- **决策机制**: 技术提案 → 社区讨论 → 投票决议 -- **版本管理**: 协议版本的规划和发布管理 - -#### **开放标准原则** -- **透明性**: 所有技术决策过程公开透明 -- **兼容性**: 新版本向后兼容,渐进式演进 -- **可扩展性**: 支持第三方扩展和定制化需求 - -### 6.3 商业模式 - -#### **多元化收入模式** -```mermaid -graph LR - A[DACP生态] --> B[开源社区版] - A --> C[企业服务版] - A --> D[云端托管版] - - B --> E[免费使用] - C --> F[订阅收费] - D --> G[按量计费] - - E --> H[生态繁荣] - F --> I[企业服务] - G --> J[便捷体验] -``` - -#### **价值创造循环** -- **开源贡献** → **社区繁荣** → **用户增长** → **商业价值** → **持续投入** - ---- - -## 7. 案例研究 - -### 7.1 邮件服务包案例 - -#### **背景需求** -企业用户需要一个智能邮件助手,能够: -- 理解自然语言邮件需求 -- 自动起草专业邮件内容 -- 智能管理联系人信息 -- 提供邮件发送分析 - -#### **解决方案设计** -```mermaid -graph TD - A[用户需求] --> B[邮件专家角色] - B --> C[需求理解] - C --> D[邮件起草] - D --> E[联系人匹配] - E --> F[邮件发送] - F --> G[结果反馈] - - subgraph "角色能力" - H[专业写作] - I[礼仪规范] - J[场景适配] - end - - subgraph "工具能力" - K[SMTP发送] - L[联系人API] - M[模板引擎] - end - - B --> H - B --> I - B --> J - - F --> K - E --> L - D --> M -``` - -#### **实现效果** -- **用户体验**: 从复杂的邮件配置简化为自然语言对话 -- **专业质量**: 邮件内容符合商务礼仪,提升沟通效果 -- **效率提升**: 邮件处理时间减少80%,错误率降低90% - -### 7.2 日程管理服务包案例 - -#### **Execution框架设计** -``` -日程管理服务的execution定义: - -Constraint(约束): -- 日历系统API调用限制:每分钟最多200次 -- 会议时长限制:最短15分钟,最长8小时 -- 提前通知时间:至少5分钟前发送邀请 - -Rule(规则): -- 必须检查参与者日程冲突 -- 必须验证会议室可用性 -- 禁止在非工作时间安排常规会议 - -Guideline(指导原则): -- 建议会议时长控制在1小时内 -- 建议为重要会议预留缓冲时间 -- 建议根据参与者时区安排合适时间 - -Process(流程): -1. 解析日程安排需求 -2. 检查参与者可用时间 -3. 预订会议室资源 -4. 发送会议邀请 -5. 设置提醒通知 - -Criteria(标准): -- 会议创建成功率 > 98% -- 冲突检测准确率 = 100% -- 邀请发送延迟 < 30秒 -``` - -#### **使用场景** -``` -用户: "明天下午安排一个产品评审会议,邀请产品团队" - -AI分析: -- 时间: 明天下午(具体时间待确认) -- 事件: 产品评审会议 -- 参与者: 产品团队成员 -- 需求: 会议室预订 + 邀请发送 - -执行结果: "日程安排完成 - 明天下午2点产品评审会议已创建,A301会议室已预订,5位团队成员已收到邀请。执行评估:无冲突检测,响应时间12秒,符合所有标准。" -``` - ---- - -## 8. 未来展望 - -### 8.1 技术演进路线 - -#### **短期目标(6个月)** -- **协议标准化**: 完成DACP 1.0正式版协议规范 -- **原型验证**: 开发核心邮件服务包作为概念验证 -- **基础工具**: 开发DACP CLI和SDK的基础版本 -- **文档体系**: 建立完整的协议和开发者文档 - -#### **中期目标(1年)** -- **生态初建**: 发布核心服务包(邮件、日程、文档等) -- **社区发展**: 吸引早期开发者贡献第三方服务包 -- **标准推广**: 在开发者社区推广DACP协议概念 -- **工具完善**: 完成CLI、SDK、注册中心等基础设施 - -#### **长期愿景(3年)** -- **行业影响**: DACP在Agent Context领域获得广泛认知 -- **生态成熟**: 建立繁荣的第三方服务包生态 -- **商业化**: 探索可持续的商业模式和盈利路径 - -### 8.2 技术创新方向 - -#### **智能化增强** -- **自适应路由**: 基于用户行为的智能服务推荐 -- **自动化角色生成**: AI自动生成DACP服务的角色定义 -- **智能错误恢复**: 服务故障时的自动降级和恢复机制 - -#### **性能优化** -- **分布式架构**: 支持微服务架构和容器化部署 -- **边缘计算**: 支持边缘设备上的轻量级DACP服务 -- **实时通信**: WebSocket和服务端推送的实时交互能力 - -#### **安全增强** -- **零信任架构**: 端到端的安全验证和加密 -- **隐私保护**: 用户数据的本地化处理和隐私保护 -- **审计日志**: 完整的操作审计和合规性支持 - -### 8.3 生态发展愿景 - -#### **开发者生态** -```mermaid -graph TD - A[个人开发者] --> B[开源贡献] - C[企业开发者] --> D[商业服务] - E[教育机构] --> F[人才培养] - - B --> G[社区繁荣] - D --> H[商业价值] - F --> I[技能传承] - - G --> J[DACP生态] - H --> J - I --> J - - J --> K[技术标准] - J --> L[商业模式] - J --> M[人才体系] -``` - -#### **应用场景拓展** -- **企业内部**: 内部系统集成和工作流自动化 -- **行业解决方案**: 医疗、教育、金融等行业专用服务包 -- **个人助手**: 面向个人用户的生活服务助手 -- **IoT集成**: 物联网设备的智能化控制和管理 - ---- - -## 9. 结论 - -DACP(Deepractice Agent Context Protocol)代表了AI应用开发领域的重要创新,通过将专业AI角色与执行工具深度绑定,实现了从"AI建议"到"AI行动"的关键跃迁。 - -### 9.1 核心价值总结 - -#### **用户价值** -- **简化交互**: 从复杂工具配置到自然语言对话 -- **专业服务**: 从通用AI到专业角色服务 -- **完整解决方案**: 从单一功能到端到端服务 - -#### **开发者价值** -- **标准化开发**: 统一的协议和开发框架 -- **生态复用**: 基于PromptX成熟的角色生态 -- **商业机会**: 新的AI服务商业模式 - -#### **行业价值** -- **技术标准**: 推动Agent Context领域标准化 -- **生态繁荣**: 促进AI应用生态的健康发展 -- **创新引领**: 引领人机交互范式的转变 - -### 9.2 关键成功要素 - -#### **技术维度** -- 基于PromptX的成熟角色体系 -- 标准化的协议设计和实现 -- 完善的开发工具和文档支持 - -#### **生态维度** -- 开放的标准制定和治理机制 -- 多元化的开发者激励体系 -- 可持续的商业模式设计 - -#### **市场维度** -- 明确的用户价值主张 -- 渐进式的市场推广策略 -- 持续的技术创新和迭代 - -DACP的成功将不仅推动PromptX产品的发展,更将为整个AI应用行业带来新的发展机遇和技术标准。我们期待与开发者社区共同构建这一创新生态,让AI真正成为每个人的专业助手。 - ---- - -## 附录 - -### A. 技术规范参考 -- [MCP协议规范](https://github.com/metacontroller/mcp) -- [DPML语言规范](../prompt/protocol/dpml.protocol.md) -- [PromptX角色系统](../docs/role-system-complete-guide.md) - -### B. 开发资源(规划中) -- DACP SDK文档(概念阶段,尚未开发) -- 服务包模板(概念阶段,尚未开发) -- 示例代码仓库(概念阶段,尚未开发) - -### C. 社区资源 -- [技术讨论区](https://github.com/Deepractice/PromptX/discussions) -- [问题反馈](https://github.com/Deepractice/PromptX/issues) -- [开发者微信群](../README.md#技术交流) - ---- - -**版权声明**: 本文档遵循 [MIT License](../LICENSE) 开源协议。 - -**文档版本**: 1.0.0-concept -**最后更新**: 2024-12-17 -**状态**: 概念设计阶段,相关工具和服务尚未开发 \ No newline at end of file diff --git a/package.json b/package.json index a90ee83..5c71818 100644 --- a/package.json +++ b/package.json @@ -8,9 +8,6 @@ }, "scripts": { "start": "PROMPTX_ENV=development node src/bin/promptx.js", - "dacp:start": "node src/dacp/dacp-promptx-service/server.js", - "dacp:dev": "node src/dacp/dacp-promptx-service/server.js", - "dacp:test": "jest src/dacp/", "test": "jest", "test:unit": "jest --selectProjects unit", "test:integration": "jest --selectProjects integration", diff --git a/prompt/core/dacp-email-sending.execution.md b/prompt/core/dacp-email-sending.execution.md deleted file mode 100644 index 85157d8..0000000 --- a/prompt/core/dacp-email-sending.execution.md +++ /dev/null @@ -1,156 +0,0 @@ - - - ## 技术和环境限制 - - **配置依赖性**:真实发送需要用户在~/.promptx/dacp/send_email.json配置邮箱信息 - - **服务可用性**:需要DACP服务运行在localhost:3002或指定端口 - - **网络连接要求**:发送真实邮件需要稳定的网络连接和SMTP服务可达性 - - **邮件服务商限制**:不同服务商有发送频率和内容限制 - - **协议格式约束**:必须符合DACP协议标准的请求格式 - - - - ## 强制执行规则 - - **服务ID固定**:必须使用"dacp-promptx-service"作为service_id - - **action名称固定**:必须使用"send_email"作为action - - **必需参数验证**:user_request是必需参数,不能为空 - - **配置错误处理**:配置缺失或无效时必须向用户说明具体解决方案 - - **安全信息保护**:不得在日志或响应中暴露用户的邮箱密码 - - - - ## 使用指导原则 - - **智能需求解析**:从用户自然语言中提取收件人、主题、内容等信息 - - **上下文感知**:根据urgency、recipient_type等上下文调整邮件语气 - - **友好降级**:无配置时自动使用Demo模式,同时提供配置指导 - - **错误信息友好化**:将技术错误转化为用户可理解的解决建议 - - - - ## 邮件发送执行流程 - - ### Step 1: 需求分析和参数准备 - ``` - 1. 解析用户输入,提取邮件要素(收件人、主题、内容) - 2. 确定邮件类型和紧急程度 - 3. 构造user_request自然语言描述 - 4. 准备context上下文信息 - 5. 验证所有必需参数完整性 - ``` - - ### Step 2: DACP服务调用 - ```json - // 标准DACP邮件请求格式 - { - "service_id": "dacp-promptx-service", - "action": "send_email", - "parameters": { - "user_request": "用户的自然语言邮件描述", - "context": { - "urgency": "high|medium|low", - "recipient_type": "colleague|superior|client" - } - } - } - ``` - - ### Step 3: 配置文件格式要求 - ```json - // ~/.promptx/dacp/send_email.json 配置文件格式 - { - "provider": "gmail|outlook|qq|163|126", - "smtp": { - "user": "your-email@gmail.com", - "password": "your-app-password" - }, - "sender": { - "name": "Your Name", - "email": "your-email@gmail.com" - } - } - ``` - - ### Step 4: 结果处理和用户反馈 - ``` - 1. 检查响应状态和demo_mode字段 - 2. Demo模式:提供配置指导和创建配置文件的详细说明 - 3. 真实发送:确认发送成功并显示message_id - 4. 错误处理:解析错误原因并提供具体解决方案 - 5. 向用户反馈执行结果和后续建议 - ``` - - ### 配置错误处理流程 - ``` - 配置缺失 → 显示配置文件路径和格式 → 指导创建配置 - 配置无效 → 指出具体错误字段 → 提供修复建议 - 认证失败 → 检查密码和服务器设置 → 应用专用密码指导 - 发送失败 → 网络和SMTP检查 → 故障排除建议 - ``` - - ### 邮件服务商配置指导 - ``` - Gmail: 需要启用两步验证并生成应用专用密码 - Outlook: 使用账户密码,确保SMTP已启用 - QQ/163/126: 需要开启SMTP服务并使用授权码 - ``` - - ### 配置指导详细说明 - ``` - 📧 DACP邮件服务配置说明 - - 📍 配置文件位置:~/.promptx/dacp/send_email.json - - 📝 完整配置示例: - { - "provider": "gmail", - "smtp": { - "user": "your-email@gmail.com", - "password": "your-app-password" - }, - "sender": { - "name": "Your Name", - "email": "your-email@gmail.com" - } - } - - 💡 支持的邮件服务商:gmail, outlook, qq, 163, 126 - - 🔐 Gmail用户专用设置: - 1. 进入 Google 账户设置 - 2. 启用两步验证 - 3. 生成应用专用密码 - 4. 使用生成的密码替换 "your-app-password" - - 📞 其他服务商设置: - - Outlook: 直接使用账户密码 - - QQ/163/126: 需要开启SMTP服务并使用授权码 - ``` - - - - ## 邮件发送质量评价标准 - - ### 功能完整性 - - ✅ 正确调用DACP邮件服务 - - ✅ 准确解析用户邮件需求 - - ✅ 妥善处理配置和发送异常 - - ✅ 提供完整的配置指导 - - ### 用户体验质量 - - ✅ 自然语言交互流畅 - - ✅ 错误提示友好明确 - - ✅ 配置指导详细实用 - - ✅ Demo模式平滑降级 - - ### 安全合规性 - - ✅ 不暴露敏感配置信息 - - ✅ 遵循邮件发送最佳实践 - - ✅ 用户级配置安全存储 - - ✅ 符合反垃圾邮件规范 - - ### 系统稳定性 - - ✅ 配置缺失时不影响系统运行 - - ✅ 合理的错误处理和重试机制 - - ✅ 完整的执行反馈和日志记录 - - ✅ 多邮件服务商兼容支持 - - \ No newline at end of file diff --git a/prompt/core/dacp-service-calling.execution.md b/prompt/core/dacp-service-calling.execution.md deleted file mode 100644 index f16b1ad..0000000 --- a/prompt/core/dacp-service-calling.execution.md +++ /dev/null @@ -1,241 +0,0 @@ - - - ## DACP服务调用技术限制 - - **参数格式固定**:必须使用{service_id, action, parameters}三层结构 - - **服务路由固定**:当前支持的服务ID有限,需要匹配现有服务 - - **网络依赖**:DACP服务需要独立运行,存在网络调用延迟 - - **错误传播**:DACP服务错误需要优雅处理,不能中断角色对话 - - **异步特性**:某些DACP操作可能需要时间,需要合理设置用户期望 - - - - ## DACP调用强制规则 - - **参数完整性**:service_id和action必须提供,parameters.user_request必须包含用户自然语言需求 - - **服务匹配**:只能调用已注册的DACP服务,不得尝试调用不存在的服务 - - **错误处理**:DACP调用失败时必须向用户说明原因并提供替代方案 - - **权限检查**:敏感操作(如发送邮件)需要确认用户授权 - - **结果验证**:DACP执行结果需要向用户确认,确保符合预期 - - - - ## DACP调用指导原则 - - **需求驱动**:只有当用户明确需要执行操作时才调用DACP,避免过度自动化 - - **透明化**:向用户说明正在调用什么服务执行什么操作,保持透明 - - **渐进式**:复杂任务拆分为多个简单的DACP调用,逐步完成 - - **用户确认**:重要操作前征得用户同意,特别是涉及外部通信的操作 - - **上下文传递**:充分利用context参数传递任务相关的背景信息 - - - - ## DACP服务调用标准流程 - - ### Step 1: 需求识别与action选择 - ```mermaid - graph TD - A[用户需求] --> B{操作类型判断} - B -->|数学计算/表达式| C[calculate action] - B -->|邮件发送/生成| D[send_email action] - B -->|纯咨询/知识| E[直接回答,不调用DACP] - B -->|其他执行需求| F[说明演示服务限制] - - C --> G[dacp-promptx-service] - D --> G - E --> H[提供专业建议] - F --> I[建议未来扩展或手动处理] - ``` - - ### Step 2: 参数构建 - ```mermaid - flowchart LR - A[用户需求] --> B[service_id识别] - A --> C[action确定] - A --> D[user_request提取] - A --> E[context构建] - - B --> F[DACP参数对象] - C --> F - D --> F - E --> F - ``` - - ### Step 3: 服务调用与结果处理 - ```mermaid - graph TD - A[构建DACP参数] --> B[调用promptx_dacp工具] - B --> C{调用结果} - C -->|成功| D[解析execution_result] - C -->|失败| E[错误处理和说明] - D --> F[向用户展示结果] - E --> G[提供替代方案] - F --> H[确认用户满意度] - G --> H - ``` - - ## 当前可用DACP演示服务 - - ### DACP PromptX演示服务 (dacp-promptx-service) - - ⚠️ **重要说明**:这是协议演示服务,包含calculator和email两个演示功能 - - **服务信息**: - ``` - service_id: "dacp-promptx-service" - endpoint: "http://localhost:3002/dacp" - type: "demo" - description: "DACP协议验证平台,展示核心协议能力" - ``` - - #### 1. 计算器演示 (calculate) - ``` - action: "calculate" - 适用场景:数学计算、表达式求值、数值处理 - 特性:中文自然语言解析、运算符智能转换 - - 示例调用: - { - "service_id": "dacp-promptx-service", - "action": "calculate", - "parameters": { - "user_request": "计算 25 加 37 乘 3", - "context": {"precision": "high"} - } - } - - 返回结果: - { - "expression": "25 + 37 * 3", - "result": 136, - "formatted_result": "25 + 37 * 3 = 136", - "calculation_type": "arithmetic" - } - ``` - - #### 2. 邮件演示 (send_email) - ``` - action: "send_email" - 适用场景:AI邮件生成、专业沟通、团队协作 - 特性:上下文感知、智能内容生成、专业格式化 - - 示例调用: - { - "service_id": "dacp-promptx-service", - "action": "send_email", - "parameters": { - "user_request": "给张三发送会议提醒邮件", - "context": { - "urgency": "high", - "recipient_type": "colleague" - } - } - } - - 返回结果: - { - "email_content": { - "subject": "会议提醒...", - "body": "专业邮件内容...", - "format": "html" - }, - "metadata": {...} - } - ``` - - ## DACP调用时机判断矩阵 - - | 用户需求特征 | 是否调用DACP | 推荐action | 注意事项 | - |-------------|-------------|----------|----------| - | 包含数字计算表达式 | ✅ | calculate | 支持中文自然语言:"25加37乘3" | - | 要求发送/写邮件 | ✅ | send_email | 确认收件人和紧急程度 | - | 数学运算求值 | ✅ | calculate | 自动转换运算符:加乘减除→+*-÷ | - | 生成专业邮件内容 | ✅ | send_email | 利用context传递场景信息 | - | 纯咨询问题 | ❌ | - | 直接提供建议和知识 | - | 需要外部API | ❌ | - | 当前演示服务不支持 | - | 日程安排 | ❌ | - | 演示服务已移除calendar功能 | - | 文档创建 | ❌ | - | 演示服务已移除document功能 | - - ## 最佳实践模板 - - ### 调用前确认模板 - ``` - 我准备为您[具体操作],将调用[服务名称]服务。 - - 操作详情: - - 服务:[service_id] - - 操作:[action] - - 需求:[user_request] - - 请确认是否继续? - ``` - - ### 调用中透明化模板 - ``` - 正在调用DACP服务执行您的需求... - - 🔄 服务:[service_id] - 📋 操作:[action] - ⏱️ 请稍候... - ``` - - ### 调用后结果展示模板 - ``` - ✅ DACP服务执行完成! - - 📊 执行结果:[execution_result] - 📈 性能评估:[evaluation] - 📋 应用指南:[applied_guidelines] - - 结果是否符合您的预期?如需调整请告诉我。 - ``` - - ## 错误处理标准流程 - - ### 常见错误类型与处理 - ```mermaid - graph TD - A[DACP调用失败] --> B{错误类型} - B -->|服务不可用| C[说明服务状态,建议稍后重试] - B -->|参数错误| D[重新解析需求,调整参数] - B -->|权限不足| E[说明权限要求,请用户确认] - B -->|网络超时| F[提供离线替代方案] - - C --> G[记录问题并提供manual方案] - D --> H[重新构建参数再次尝试] - E --> I[等待用户授权] - F --> G - ``` - - ### 降级处理策略 - - **calculate action失败** → 提供计算思路、步骤分解和数学公式 - - **send_email action失败** → 生成邮件模板、提供写作建议和发送指导 - - **DACP服务整体不可用** → 说明演示服务状态,提供手动替代方案 - - **网络连接问题** → 检查localhost:3002服务状态,建议重启演示服务 - - - - ## DACP调用质量标准 - - ### 调用准确性 - - ✅ 服务选择与用户需求高度匹配 - - ✅ 参数构建完整准确 - - ✅ 错误处理及时有效 - - ✅ 结果解释清晰易懂 - - ### 用户体验 - - ✅ 调用前充分说明和确认 - - ✅ 调用中保持透明化沟通 - - ✅ 调用后验证用户满意度 - - ✅ 失败时提供替代方案 - - ### 技术规范 - - ✅ 严格遵循DACP协议格式 - - ✅ 合理使用context参数 - - ✅ 妥善处理异步特性 - - ✅ 遵循最小权限原则 - - ### 服务效率 - - ✅ 避免不必要的服务调用 - - ✅ 合理组合多个服务调用 - - ✅ 充分利用缓存和上下文 - - ✅ 及时反馈执行进度 - - \ No newline at end of file diff --git a/scripts/test-dacp-calculator.js b/scripts/test-dacp-calculator.js deleted file mode 100755 index d2d768d..0000000 --- a/scripts/test-dacp-calculator.js +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env node - -const { spawn } = require('child_process'); -const path = require('path'); - -// 测试计算器功能 -async function testCalculator() { - console.log('🧪 测试DACP计算器服务...\n'); - - const promptxPath = path.join(__dirname, '..', 'src', 'bin', 'promptx.js'); - - // 测试案例 - const testCases = [ - { - name: '简单加法', - command: ['node', promptxPath, 'dacp', 'dacp-promptx-service', 'calculate', '{"user_request": "2加3等于多少"}'] - }, - { - name: '复杂计算', - command: ['node', promptxPath, 'dacp', 'dacp-promptx-service', 'calculate', '{"user_request": "(10 + 5) * 2 - 8 / 4"}'] - }, - { - name: '中文运算符', - command: ['node', promptxPath, 'dacp', 'dacp-promptx-service', 'calculate', '{"user_request": "100减去25"}'] - } - ]; - - for (const testCase of testCases) { - console.log(`📝 测试: ${testCase.name}`); - console.log(`命令: ${testCase.command.join(' ')}`); - - await new Promise((resolve) => { - const child = spawn(testCase.command[0], testCase.command.slice(1), { - stdio: 'inherit' - }); - - child.on('close', (code) => { - console.log(`\n✅ 测试完成 (退出码: ${code})\n`); - console.log('-'.repeat(60) + '\n'); - resolve(); - }); - }); - } -} - -// 运行测试 -testCalculator().then(() => { - console.log('🎉 所有测试完成!'); -}).catch(error => { - console.error('❌ 测试失败:', error); - process.exit(1); -}); \ No newline at end of file diff --git a/scripts/test-mcp-dacp.js b/scripts/test-mcp-dacp.js deleted file mode 100755 index 5820ba9..0000000 --- a/scripts/test-mcp-dacp.js +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/env node - -/** - * 测试 MCP → PromptX → DACP 完整链路 - */ - -const { cli } = require('../src/lib/core/pouch'); - -async function testDACPIntegration() { - console.log('🧪 测试 MCP → PromptX → DACP 集成\n'); - - const tests = [ - { - name: '计算器测试', - args: { - service_id: 'dacp-promptx-service', - action: 'calculate', - parameters: { - user_request: '(100 + 200) * 3' - } - } - }, - { - name: '邮件测试', - args: { - service_id: 'dacp-promptx-service', - action: 'send_email', - parameters: { - user_request: '给 boss@company.com 发个项目进展汇报邮件', - context: { - urgency: 'normal', - recipient_type: 'superior' - } - } - } - }, - { - name: '日历测试', - args: { - service_id: 'dacp-promptx-service', - action: 'schedule_meeting', - parameters: { - user_request: '下周一安排团队周会', - context: { - location: '会议室A' - } - } - } - } - ]; - - for (const test of tests) { - console.log(`\n📍 ${test.name}`); - console.log('请求:', JSON.stringify(test.args, null, 2)); - - try { - // 调用 DACP 命令 - const result = await cli.execute('dacp', [test.args], true); - - if (result.success) { - console.log('✅ 成功!'); - console.log('结果:', JSON.stringify(result.data.execution_result, null, 2)); - } else { - console.log('❌ 失败:', result.error); - } - } catch (error) { - console.log('❌ 错误:', error.message); - } - } -} - -// 运行测试 -testDACPIntegration().then(() => { - console.log('\n✅ 所有测试完成!'); - process.exit(0); -}).catch(error => { - console.error('测试失败:', error); - process.exit(1); -}); \ No newline at end of file diff --git a/src/bin/promptx.js b/src/bin/promptx.js index fb76160..755627a 100755 --- a/src/bin/promptx.js +++ b/src/bin/promptx.js @@ -66,35 +66,6 @@ program await cli.execute('remember', args) }) -// DACP命令 -program - .command('dacp [parameters]') - .description('🚀 dacp锦囊 - 调用DACP专业服务,让AI角色拥有执行能力') - .action(async (service_id, action, parameters, options) => { - try { - // 解析参数(如果是JSON字符串) - let parsedParams = {}; - if (parameters) { - try { - parsedParams = JSON.parse(parameters); - } catch (error) { - console.error('❌ 参数解析错误,请提供有效的JSON格式'); - process.exit(1); - } - } - - const args = { - service_id, - action, - parameters: parsedParams - }; - - await cli.execute('dacp', args); - } catch (error) { - console.error(`❌ DACP命令执行失败: ${error.message}`); - process.exit(1); - } - }) // Tool命令 program @@ -143,7 +114,6 @@ program .option('--host
', '绑定地址 (仅http/sse传输)', 'localhost') .option('--cors', '启用CORS (仅http/sse传输)', false) .option('--debug', '启用调试模式', false) - .option('--with-dacp', '(已废弃,静默忽略)', false) .action(async (options) => { try { // 设置调试模式 @@ -154,7 +124,6 @@ program // 根据传输类型选择命令 if (options.transport === 'stdio') { const mcpServer = new MCPServerCommand(); - // 🔧 DACP现为Mock模式,静默忽略用户的withDacp配置 await mcpServer.execute(); } else if (options.transport === 'http' || options.transport === 'sse') { const mcpHttpServer = new MCPStreamableHttpCommand(); @@ -188,14 +157,14 @@ program.addHelpText('after', ` ${chalk.cyan('💡 PromptX 锦囊框架 - AI use CLI get prompt for AI')} -${chalk.cyan('🎒 七大核心命令:')} +${chalk.cyan('🎒 六大核心命令:')} 🏗️ ${chalk.cyan('init')} → 初始化环境,传达系统协议 👋 ${chalk.yellow('welcome')} → 发现可用角色和领域专家 ⚡ ${chalk.red('action')} → 激活特定角色,获取专业能力 📚 ${chalk.blue('learn')} → 深入学习领域知识体系 🔍 ${chalk.green('recall')} → AI主动检索应用记忆 🧠 ${chalk.magenta('remember')} → AI主动内化知识增强记忆 - 🚀 ${chalk.cyan('dacp')} → 调用DACP专业服务,AI角色执行能力 + 🔧 ${chalk.cyan('tool')} → 执行JavaScript工具,AI智能行动 🔌 ${chalk.blue('mcp-server')} → 启动MCP Server,连接AI应用 ${chalk.cyan('示例:')} @@ -221,9 +190,9 @@ ${chalk.cyan('示例:')} promptx remember "每日站会控制在15分钟内" promptx remember "测试→预发布→生产" - ${chalk.gray('# 7️⃣ 调用DACP专业服务')} - promptx dacp dacp-promptx-service calculate '{"user_request": "计算2+3"}' - promptx dacp dacp-email-service send_email '{"user_request": "发送邮件"}' + ${chalk.gray('# 7️⃣ 执行JavaScript工具')} + promptx tool '{"tool_resource": "@tool://calculator", "parameters": {"operation": "add", "a": 2, "b": 3}}' + promptx tool '{"tool_resource": "@tool://send-email", "parameters": {"to": "test@example.com", "subject": "Hello", "content": "Test"}}' ${chalk.gray('# 8️⃣ 启动MCP服务')} promptx mcp-server # stdio传输(默认) diff --git a/src/dacp/dacp-promptx-service/DACP-API-GUIDE.md b/src/dacp/dacp-promptx-service/DACP-API-GUIDE.md deleted file mode 100644 index 1f2c5a4..0000000 --- a/src/dacp/dacp-promptx-service/DACP-API-GUIDE.md +++ /dev/null @@ -1,256 +0,0 @@ -# DACP 协议演示服务 - API 调用指南 - -## 📋 概述 - -DACP (Deepractice Agent Context Protocol) 演示服务是一个**轻量级协议验证平台**,通过calculator和email两个典型场景展示DACP协议的核心能力。 - -### 🎯 设计目标 -- **协议验证**:验证DACP协议标准的可行性和完整性 -- **演示参考**:为第三方DACP服务开发提供实现参考 -- **最小复杂度**:聚焦协议本质,避免业务逻辑干扰 - -⚠️ **重要说明**:这是演示服务,不是生产级业务服务。真实的DACP服务应该独立部署。 - -## 🚀 快速开始 - -### 启动服务 - -```bash -# 通过PromptX MCP服务器启动(推荐) -./scripts/start-mcp.sh --with-dacp - -# 或者单独启动演示服务 -cd src/dacp/dacp-promptx-service -node server.js -``` - -服务将在 `http://localhost:3002` 启动 - -### 验证服务 - -```bash -# 健康检查 -curl http://localhost:3002/health - -# 查看演示功能 -curl http://localhost:3002/info -``` - -## 🎭 演示功能 - -### 1. 计算器演示 (`calculate`) - -**演示价值**:展示DACP协议处理结构化数据和自然语言解析能力 - -**调用示例**: -```bash -curl -X POST http://localhost:3002/dacp \ - -H "Content-Type: application/json" \ - -d '{ - "service_id": "dacp-promptx-service", - "action": "calculate", - "parameters": { - "user_request": "计算 25 加 37 乘 3 的结果" - } - }' -``` - -**演示特性**: -- 中文自然语言解析:`计算 25 加 37 乘 3` -- 运算符智能转换:`加/乘/减/除` → `+/*/-/÷` -- 标准数学表达式:`25 + 37 * 3` -- 结果格式化:`25 + 37 * 3 = 136` - -### 2. 邮件演示 (`send_email`) - -**演示价值**:展示DACP协议处理复杂上下文和AI内容生成能力 - -**调用示例**: -```bash -curl -X POST http://localhost:3002/dacp \ - -H "Content-Type: application/json" \ - -d '{ - "service_id": "dacp-promptx-service", - "action": "send_email", - "parameters": { - "user_request": "给张三发送会议提醒邮件", - "context": { - "urgency": "high", - "recipient_type": "colleague" - } - } - }' -``` - -**演示特性**: -- 自然语言需求理解 -- 上下文感知内容生成 -- 专业邮件格式化 -- 智能主题和正文生成 - -## 📋 标准DACP协议格式 - -### 请求格式 - -```json -{ - "service_id": "dacp-promptx-service", // 必需:演示服务ID - "action": "calculate|send_email", // 必需:演示功能 - "parameters": { // 必需:参数对象 - "user_request": "自然语言需求描述", // 必需:用户需求 - "context": {} // 可选:上下文信息 - }, - "request_id": "demo_001" // 可选:请求ID -} -``` - -### 响应格式 - -#### 成功响应 -```json -{ - "request_id": "demo_001", - "success": true, - "data": { - "execution_result": {}, // 实际执行结果 - "evaluation": { // DACP execution框架评估 - "constraint_compliance": true, - "rule_adherence": true, - "guideline_alignment": true - }, - "applied_guidelines": [], // 应用的指导原则 - "performance_metrics": { // 性能指标 - "execution_time": "1ms", - "resource_usage": "minimal" - } - } -} -``` - -## 🔧 通过PromptX调用 - -### 激活Sean角色并调用DACP - -```javascript -// 1. 激活角色 -promptx_action({role: "sean"}) - -// 2. 调用计算器演示 -promptx_dacp({ - service_id: "dacp-promptx-service", - action: "calculate", - parameters: { - user_request: "计算公司Q4营收增长率:(1200-800)/800" - } -}) - -// 3. 调用邮件演示 -promptx_dacp({ - service_id: "dacp-promptx-service", - action: "send_email", - parameters: { - user_request: "给团队发送项目进展通知", - context: {urgency: "medium", recipient_type: "team"} - } -}) -``` - -## 🧪 协议验证测试 - -### 基础协议测试 - -```bash -# 1. 服务发现 -curl http://localhost:3002/info - -# 2. 计算器协议验证 -curl -X POST http://localhost:3002/dacp \ - -H "Content-Type: application/json" \ - -d '{ - "service_id": "dacp-promptx-service", - "action": "calculate", - "parameters": {"user_request": "25 + 37 * 3"} - }' - -# 3. 邮件协议验证 -curl -X POST http://localhost:3002/dacp \ - -H "Content-Type: application/json" \ - -d '{ - "service_id": "dacp-promptx-service", - "action": "send_email", - "parameters": {"user_request": "发送测试邮件"} - }' -``` - -### 错误处理验证 - -```bash -# 错误的service_id -curl -X POST http://localhost:3002/dacp \ - -d '{"service_id": "wrong-service", "action": "calculate"}' - -# 错误的action -curl -X POST http://localhost:3002/dacp \ - -d '{"service_id": "dacp-promptx-service", "action": "wrong_action"}' - -# 缺少参数 -curl -X POST http://localhost:3002/dacp \ - -d '{"service_id": "dacp-promptx-service", "action": "calculate"}' -``` - -## 🏗️ 为第三方开发者 - -### DACP协议实现参考 - -此演示服务完整展示了DACP协议的标准实现: - -1. **Action模块化**:每个功能独立模块 -2. **统一入口**:标准`/dacp` POST端点 -3. **协议验证**:service_id、action、parameters验证 -4. **execution框架**:constraint→rule→guideline→process→criteria -5. **标准响应**:统一的成功/错误响应格式 - -### 扩展真实DACP服务 - -```javascript -// 真实服务应该独立部署,例如: -// 1. dacp-finance-service (端口3003) -// 2. dacp-crm-service (端口3004) -// 3. dacp-analytics-service (端口3005) - -// PromptX DACPCommand路由表更新: -const routes = { - 'dacp-promptx-service': 'http://localhost:3002/dacp', // 演示服务 - 'dacp-finance-service': 'http://localhost:3003/dacp', // 真实财务服务 - 'dacp-crm-service': 'http://localhost:3004/dacp' // 真实CRM服务 -}; -``` - -## 🎯 产品理念 - -基于Sean的产品哲学,这个演示服务体现了: - -### 奥卡姆剃刀原则 -- 最小复杂度验证最大价值 -- 两个典型场景覆盖DACP协议核心能力 -- 避免过度工程化干扰协议本质 - -### 需求驱动设计 -- 协议验证需求 → 最小演示实现 -- 开发者参考需求 → 标准化代码结构 -- 生态扩展需求 → 清晰的架构分离 - -### 矛盾转化创新 -- 协议抽象 vs 具象演示 → 通过具体场景展示抽象协议 -- 演示简洁 vs 功能完整 → 精选核心场景代表全貌 -- 当前需求 vs 未来扩展 → 演示框架支持无限扩展 - ---- - -## 📞 技术支持 - -**演示目标**:验证DACP协议可行性,为真实DACP服务开发提供参考 - -**架构原则**:演示服务与生产服务分离,避免在MCP客户端承担过多业务逻辑 - -**扩展建议**:基于此演示框架,开发独立部署的专业DACP服务 \ No newline at end of file diff --git a/src/dacp/dacp-promptx-service/README.md b/src/dacp/dacp-promptx-service/README.md deleted file mode 100644 index b806ba9..0000000 --- a/src/dacp/dacp-promptx-service/README.md +++ /dev/null @@ -1,93 +0,0 @@ -# DACP 协议演示服务 - -## 概述 - -这是一个轻量级的DACP (Deepractice Agent Context Protocol) 协议演示服务,通过calculator和email两个典型场景验证DACP协议的完整性和可行性。 - -⚠️ **重要说明**:这是协议演示服务,不是生产级业务服务。真实的DACP服务应该独立部署。 - -## 设计目标 - -- **协议验证**:验证DACP协议标准的可行性 -- **演示参考**:为第三方DACP服务开发提供实现参考 -- **最小复杂度**:聚焦协议本质,避免业务逻辑干扰 - -## 演示功能 - -### 1. Calculator (`calculate`) -- 中文自然语言数学表达式解析 -- 智能运算符转换:`加/乘/减/除` → `+/*/-/÷` -- 标准数学运算和结果格式化 - -### 2. Email (`send_email`) -- 自然语言邮件需求理解 -- 上下文感知内容生成 -- 专业邮件格式化 - -## 快速开始 - -### 通过PromptX MCP启动(推荐) -```bash -./scripts/start-mcp.sh --with-dacp -``` - -### 独立启动 -```bash -cd src/dacp/dacp-promptx-service -npm install -node server.js -``` - -服务地址:`http://localhost:3002` - -## 基础测试 - -```bash -# 健康检查 -curl http://localhost:3002/health - -# 计算器演示 -curl -X POST http://localhost:3002/dacp \ - -H "Content-Type: application/json" \ - -d '{ - "service_id": "dacp-promptx-service", - "action": "calculate", - "parameters": {"user_request": "计算 25 + 37 * 3"} - }' - -# 邮件演示 -curl -X POST http://localhost:3002/dacp \ - -H "Content-Type: application/json" \ - -d '{ - "service_id": "dacp-promptx-service", - "action": "send_email", - "parameters": {"user_request": "发送测试邮件"} - }' -``` - -## 架构原则 - -基于Sean的产品哲学: - -### 奥卡姆剃刀原则 -- 最小复杂度验证最大价值 -- 两个典型场景覆盖协议核心能力 - -### 架构分离 -- 演示服务与生产服务分离 -- 避免在MCP客户端承担过多业务逻辑 - -### 扩展指导 -- 真实DACP服务应独立部署 -- 此演示提供标准协议实现参考 - -## 文档 - -详细的API调用指南请参考:[DACP-API-GUIDE.md](./DACP-API-GUIDE.md) - -## 下一步 - -基于此演示框架,开发独立部署的专业DACP服务: -- `dacp-finance-service` (财务服务) -- `dacp-crm-service` (客户管理服务) -- `dacp-analytics-service` (数据分析服务) \ No newline at end of file diff --git a/src/dacp/dacp-promptx-service/actions/calculator.js b/src/dacp/dacp-promptx-service/actions/calculator.js deleted file mode 100644 index 089b599..0000000 --- a/src/dacp/dacp-promptx-service/actions/calculator.js +++ /dev/null @@ -1,98 +0,0 @@ -/** - * Calculator Action Module for DACP PromptX Service - * 提供简单的计算功能 - */ - -// Calculate action handler -async function calculate(parameters) { - const { user_request } = parameters; - - if (!user_request) { - throw new Error('user_request is required for calculate action'); - } - - try { - // 解析数学表达式 - const expression = parseExpression(user_request); - - // 计算结果 - const result = evaluateExpression(expression); - - return { - expression: expression, - result: result, - formatted_result: `${expression} = ${result}`, - calculation_type: getCalculationType(expression) - }; - } catch (error) { - throw new Error(`计算失败: ${error.message}`); - } -} - -// 解析用户输入的表达式 -function parseExpression(userRequest) { - // 移除中文描述,提取数学表达式 - let expr = userRequest; - - // 替换中文运算符 - expr = expr.replace(/加上|加/g, '+'); - expr = expr.replace(/减去|减/g, '-'); - expr = expr.replace(/乘以|乘/g, '*'); - expr = expr.replace(/除以|除/g, '/'); - expr = expr.replace(/等于|是多少|=|\?|?/g, ''); - - // 提取数字和运算符 - const mathPattern = /[\d\+\-\*\/\(\)\.\s]+/g; - const matches = expr.match(mathPattern); - - if (!matches) { - throw new Error('未找到有效的数学表达式'); - } - - // 清理表达式 - expr = matches.join('').trim(); - - // 验证表达式 - if (!/^[\d\+\-\*\/\(\)\.\s]+$/.test(expr)) { - throw new Error('表达式包含无效字符'); - } - - return expr; -} - -// 安全地计算表达式 -function evaluateExpression(expression) { - try { - // 基本验证 - if (!expression || expression.trim() === '') { - throw new Error('表达式为空'); - } - - // 使用 Function 构造器安全计算(只允许数学运算) - const result = Function('"use strict"; return (' + expression + ')')(); - - // 检查结果 - if (typeof result !== 'number' || isNaN(result)) { - throw new Error('计算结果无效'); - } - - // 处理精度问题 - return Math.round(result * 1000000) / 1000000; - } catch (error) { - throw new Error(`计算错误: ${error.message}`); - } -} - -// 判断计算类型 -function getCalculationType(expression) { - if (expression.includes('+')) return 'addition'; - if (expression.includes('-')) return 'subtraction'; - if (expression.includes('*')) return 'multiplication'; - if (expression.includes('/')) return 'division'; - return 'simple'; -} - -// 导出 calculator action -module.exports = { - calculate -}; \ No newline at end of file diff --git a/src/dacp/dacp-promptx-service/actions/email.js b/src/dacp/dacp-promptx-service/actions/email.js deleted file mode 100644 index 026aa74..0000000 --- a/src/dacp/dacp-promptx-service/actions/email.js +++ /dev/null @@ -1,250 +0,0 @@ -/** - * Email Action Module for DACP PromptX Service - * 提供邮件发送功能 - 支持Demo模式和真实发送 - */ - -const nodemailer = require('nodemailer') -const DACPConfigManager = require('../../../lib/utils/DACPConfigManager') - -// Email action handler -async function send_email(parameters) { - const { user_request, context = {} } = parameters; - - if (!user_request) { - throw new Error('user_request is required for send_email action'); - } - - // 解析邮件信息 - const emailData = parseEmailRequest(user_request, context); - - // 验证邮件数据 - validateEmailData(emailData); - - // 执行发送(Demo模式) - const result = await executeSendEmail(emailData, context); - - return result; -} - -// 解析邮件请求 -function parseEmailRequest(userRequest, context) { - // 提取邮箱地址 - const emailRegex = /([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})/g; - const emails = userRequest.match(emailRegex) || []; - - // 分析请求意图 - let subject = '邮件通知'; - let urgency = context.urgency || 'normal'; - - if (userRequest.includes('会议')) { - subject = '会议通知'; - urgency = 'high'; - } else if (userRequest.includes('提醒')) { - subject = '重要提醒'; - urgency = 'high'; - } else if (userRequest.includes('报告')) { - subject = '工作报告'; - } else if (userRequest.includes('邀请')) { - subject = '邀请函'; - } - - // 生成专业的邮件内容 - const body = generateProfessionalEmailBody(userRequest, subject, context); - - return { - to: emails[0] || 'demo@example.com', - subject: subject, - body: body, - urgency: urgency, - originalRequest: userRequest, - timestamp: new Date().toISOString() - }; -} - -// 生成专业的邮件正文 -function generateProfessionalEmailBody(userRequest, subject, context) { - const timestamp = new Date().toLocaleString('zh-CN'); - const recipientType = context.recipient_type || 'colleague'; - - // 根据收件人类型调整语气 - let greeting = '您好'; - let closing = 'Best regards'; - - if (recipientType === 'superior') { - greeting = '尊敬的领导'; - closing = '此致\n敬礼'; - } else if (recipientType === 'client') { - greeting = '尊敬的客户'; - closing = '谨上'; - } - - // 构建邮件内容 - let body = `${greeting},\n\n`; - - // 根据主题类型生成不同的内容结构 - if (subject.includes('会议')) { - body += `特此通知您关于以下会议安排:\n\n`; - body += `${userRequest}\n\n`; - body += `请您准时参加。如有任何问题,请及时与我联系。\n`; - } else if (subject.includes('提醒')) { - body += `这是一份重要提醒:\n\n`; - body += `${userRequest}\n\n`; - body += `请您知悉并及时处理。\n`; - } else { - body += `${userRequest}\n`; - } - - body += `\n${closing}\n`; - body += `DACP PromptX Service\n`; - body += `发送时间: ${timestamp}`; - - return body; -} - -// 验证邮件数据 -function validateEmailData(emailData) { - const errors = []; - - // 验证邮箱格式 - const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; - if (!emailRegex.test(emailData.to)) { - errors.push('Invalid email address format'); - } - - // 验证内容 - if (!emailData.subject || emailData.subject.trim().length === 0) { - errors.push('Email subject cannot be empty'); - } - - if (!emailData.body || emailData.body.trim().length === 0) { - errors.push('Email body cannot be empty'); - } - - if (errors.length > 0) { - throw new Error(`Validation failed: ${errors.join(', ')}`); - } -} - -// 执行邮件发送 -async function executeSendEmail(emailData, context) { - const configManager = new DACPConfigManager() - - // 检查是否有用户配置 - const hasConfig = await configManager.hasActionConfig('send_email') - - if (!hasConfig) { - // 无配置,回退到Demo模式 - return await executeDemoSendEmail(emailData, context) - } - - // 读取配置 - const config = await configManager.readActionConfig('send_email') - - // 验证配置 - const validation = configManager.validateEmailConfig(config) - if (!validation.valid) { - // 配置无效,抛出友好错误 - const errorMessage = await configManager.generateConfigErrorMessage('send_email', validation) - throw new Error(errorMessage) - } - - try { - // 真实邮件发送 - return await executeRealSendEmail(emailData, config, context) - } catch (error) { - // 发送失败,提供友好提示 - console.error('邮件发送失败:', error.message) - throw new Error(`\n📧 邮件发送失败\n\n❌ 错误信息: ${error.message}\n\n💡 可能的解决方案:\n • 检查邮箱密码是否正确\n • 确认已启用SMTP服务\n • 验证网络连接状态\n • Gmail用户确保使用应用专用密码\n`) - } -} - -// Demo模式发送 -async function executeDemoSendEmail(emailData, context) { - console.log('📧 [DACP Demo] Simulating email send:'); - console.log(` To: ${emailData.to}`); - console.log(` Subject: ${emailData.subject}`); - console.log(` Urgency: ${emailData.urgency}`); - - // 模拟网络延迟 - await new Promise(resolve => setTimeout(resolve, 100)); - - const configManager = new DACPConfigManager() - const configHint = await configManager.generateConfigErrorMessage('send_email') - - return { - message_id: `demo_msg_${Date.now()}`, - status: 'demo_sent', - recipient: emailData.to, - subject: emailData.subject, - body: emailData.body, - sent_at: emailData.timestamp, - urgency: emailData.urgency, - demo_mode: true, - config_hint: configHint, - execution_metrics: { - parsing_time: '10ms', - validation_time: '5ms', - sending_time: '100ms' - } - }; -} - -// 真实邮件发送 -async function executeRealSendEmail(emailData, config, context) { - const startTime = Date.now() - - // 获取提供商配置 - const configManager = new DACPConfigManager() - const providerConfig = configManager.getProviderConfig(config.provider) - - if (!providerConfig) { - throw new Error(`不支持的邮件服务提供商: ${config.provider}`) - } - - // 创建邮件传输器 - const transporter = nodemailer.createTransport({ - host: providerConfig.smtp, - port: providerConfig.port, - secure: providerConfig.secure, - auth: { - user: config.smtp.user, - pass: config.smtp.password - } - }) - - // 构建邮件选项 - const mailOptions = { - from: `"${config.sender.name}" <${config.sender.email}>`, - to: emailData.to, - subject: emailData.subject, - html: emailData.body.replace(/\n/g, '
'), - text: emailData.body - } - - // 发送邮件 - const info = await transporter.sendMail(mailOptions) - const endTime = Date.now() - - return { - message_id: info.messageId, - status: 'sent', - recipient: emailData.to, - subject: emailData.subject, - body: emailData.body, - sent_at: new Date().toISOString(), - urgency: emailData.urgency, - demo_mode: false, - provider: config.provider, - smtp_response: info.response, - execution_metrics: { - parsing_time: '10ms', - validation_time: '5ms', - sending_time: `${endTime - startTime}ms` - } - } -} - -// 导出所有email相关的actions -module.exports = { - send_email -}; \ No newline at end of file diff --git a/src/dacp/dacp-promptx-service/dacp.config.json b/src/dacp/dacp-promptx-service/dacp.config.json deleted file mode 100644 index 29a08f3..0000000 --- a/src/dacp/dacp-promptx-service/dacp.config.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "service": { - "id": "dacp-promptx-service", - "name": "PromptX DACP Demo Service", - "version": "1.0.0", - "description": "DACP protocol demonstration service with calculator and email examples", - "type": "demo", - "status": "active" - }, - "capabilities": { - "actions": [ - { - "name": "calculate", - "description": "Demo: Simple calculator for basic math operations", - "category": "demo" - }, - { - "name": "send_email", - "description": "Demo: Send professional emails with AI-powered content generation", - "category": "demo" - } - ], - "protocols": ["DACP/1.0"], - "authentication": false - }, - "execution": { - "constraint": { - "max_concurrent_requests": 100, - "request_timeout": 30000, - "rate_limit": "1000/hour" - }, - "rule": { - "require_action": true, - "require_parameters": true, - "validate_service_id": true - }, - "guideline": { - "response_format": "DACP standard", - "error_handling": "graceful with detailed messages", - "logging": "structured JSON logs" - } - }, - "deployment": { - "port": 3002, - "host": "localhost", - "environment": "development" - } -} \ No newline at end of file diff --git a/src/dacp/dacp-promptx-service/server.js b/src/dacp/dacp-promptx-service/server.js deleted file mode 100644 index 35900b6..0000000 --- a/src/dacp/dacp-promptx-service/server.js +++ /dev/null @@ -1,153 +0,0 @@ -const express = require('express'); -const bodyParser = require('body-parser'); -const cors = require('cors'); -const fs = require('fs'); -const path = require('path'); - -const app = express(); -const config = JSON.parse(fs.readFileSync(path.join(__dirname, 'dacp.config.json'), 'utf8')); -const PORT = process.env.PORT || config.deployment.port || 3002; - -// Middleware -app.use(cors()); -app.use(bodyParser.json()); - -// Load all actions -const actions = {}; -const actionsDir = path.join(__dirname, 'actions'); - -// Dynamically load all action modules -if (fs.existsSync(actionsDir)) { - fs.readdirSync(actionsDir).forEach(file => { - if (file.endsWith('.js')) { - const actionName = file.replace('.js', ''); - actions[actionName] = require(path.join(actionsDir, file)); - console.log(`Loaded action: ${actionName}`); - } - }); -} - -// Health check endpoint -app.get('/health', (req, res) => { - res.json({ - status: 'healthy', - service: config.service.name, - version: config.service.version, - uptime: process.uptime() - }); -}); - -// Service info endpoint -app.get('/info', (req, res) => { - res.json({ - service: config.service, - capabilities: config.capabilities, - available_actions: Object.keys(actions) - }); -}); - -// Main DACP endpoint -app.post('/dacp', async (req, res) => { - const startTime = Date.now(); - const { service_id, action, parameters, request_id } = req.body; - - // Generate request_id if not provided - const reqId = request_id || `req_${Date.now()}`; - - try { - // Validate service_id - if (service_id !== config.service.id) { - return res.status(400).json({ - request_id: reqId, - success: false, - error: { - code: 'INVALID_SERVICE', - message: `Service ${service_id} not found. This is ${config.service.id}` - } - }); - } - - // Validate action - if (!action) { - return res.status(400).json({ - request_id: reqId, - success: false, - error: { - code: 'MISSING_ACTION', - message: 'Action is required' - } - }); - } - - // Find action handler - let handler = null; - - // Try to find by module name first - for (const [moduleName, module] of Object.entries(actions)) { - if (module[action] && typeof module[action] === 'function') { - handler = module[action]; - break; - } - } - - // If not found, try exact module match - if (!handler && actions[action]) { - handler = actions[action]; - } - - if (!handler) { - return res.status(400).json({ - request_id: reqId, - success: false, - error: { - code: 'UNKNOWN_ACTION', - message: `Action ${action} is not supported` - } - }); - } - - // Execute action - const result = await handler(parameters); - - // Return DACP standard response - res.json({ - request_id: reqId, - success: true, - data: { - execution_result: result, - evaluation: { - constraint_compliance: true, - rule_adherence: true, - guideline_alignment: true - }, - applied_guidelines: [ - 'DACP protocol standard', - 'Service-specific best practices' - ], - performance_metrics: { - execution_time: `${Date.now() - startTime}ms`, - resource_usage: 'minimal' - } - } - }); - - } catch (error) { - console.error('DACP execution error:', error); - res.status(500).json({ - request_id: reqId, - success: false, - error: { - code: 'EXECUTION_ERROR', - message: error.message - } - }); - } -}); - -// Start server -app.listen(PORT, () => { - console.log(`🚀 ${config.service.name} v${config.service.version}`); - console.log(`📍 Running at http://localhost:${PORT}`); - console.log(`🔧 Available actions: ${Object.keys(actions).join(', ')}`); - console.log(`🏥 Health check: http://localhost:${PORT}/health`); -}); \ No newline at end of file diff --git a/src/lib/commands/MCPServerCommand.js b/src/lib/commands/MCPServerCommand.js index 48c7511..1de5f2c 100644 --- a/src/lib/commands/MCPServerCommand.js +++ b/src/lib/commands/MCPServerCommand.js @@ -84,8 +84,6 @@ class MCPServerCommand { // 设置进程清理处理器 this.setupProcessCleanup(); - // 🔧 DACP现已改为Mock模式,无需启动独立服务 - // 静默忽略任何withDacp选项,保持向后兼容 this.log('🚀 启动MCP Server...'); const transport = new StdioServerTransport(); @@ -143,267 +141,14 @@ class MCPServerCommand { } /** - * 清理子进程 (DACP现为Mock模式,此方法保留但无实际清理工作) - * @deprecated DACP已改为Mock模式,无需清理子进程 + * 清理资源 */ cleanup() { - // 🔧 DACP现已改为Mock模式,无需清理DACP子进程 - // HTTP模式的进程清理代码已保留作为参考实现 - this.log('🔧 Mock模式下无需清理DACP子进程'); + this.log('🔧 清理MCP Server资源'); } - /** - * 检测DACP服务是否已经运行 (HTTP模式 - 仅作参考实现保留) - * @deprecated DACP已改为Mock模式,此方法仅保留作为参考 - * @param {string} host - 主机地址 - * @param {number} port - 端口号 - * @returns {Promise} 服务是否运行 - */ - async isDACPServiceRunning(host = 'localhost', port = 3002) { - // 🔧 Mock模式下始终返回false,因为不需要HTTP服务 - return false; - - /* HTTP模式参考实现(已禁用) - const http = require('http'); - - return new Promise((resolve) => { - const options = { - hostname: host, - port: port, - path: '/health', - method: 'GET', - timeout: 2000 // 2秒超时 - }; - const req = http.request(options, (res) => { - let data = ''; - res.on('data', (chunk) => { - data += chunk; - }); - - res.on('end', () => { - try { - const healthData = JSON.parse(data); - // 检查是否是DACP服务且状态健康 - const isHealthy = healthData.status === 'healthy'; - const isDACPService = healthData.service && healthData.service.includes('DACP'); - resolve(isHealthy && isDACPService); - } catch (error) { - resolve(false); - } - }); - }); - req.on('error', () => { - resolve(false); - }); - - req.on('timeout', () => { - req.destroy(); - resolve(false); - }); - - req.end(); - }); - */ - } - - /** - * 获取DACP服务信息 (HTTP模式 - 仅作参考实现保留) - * @deprecated DACP已改为Mock模式,此方法仅保留作为参考 - * @param {string} host - 主机地址 - * @param {number} port - 端口号 - * @returns {Promise} 服务信息 - */ - async getDACPServiceInfo(host = 'localhost', port = 3002) { - // 🔧 Mock模式下返回模拟的服务信息 - return { - service: { - name: 'PromptX DACP Mock Service', - version: '1.0.0-mock' - }, - available_actions: ['calculate', 'send_email'], - mode: 'local_mock' - }; - - /* HTTP模式参考实现(已禁用) - const http = require('http'); - - return new Promise((resolve) => { - const options = { - hostname: host, - port: port, - path: '/info', - method: 'GET', - timeout: 2000 - }; - - const req = http.request(options, (res) => { - let data = ''; - res.on('data', (chunk) => { - data += chunk; - }); - - res.on('end', () => { - try { - const serviceInfo = JSON.parse(data); - resolve(serviceInfo); - } catch (error) { - resolve(null); - } - }); - }); - - req.on('error', () => { - resolve(null); - }); - - req.on('timeout', () => { - req.destroy(); - resolve(null); - }); - - req.end(); - }); - */ - } - - /** - * 启动DACP服务 (HTTP模式 - 仅作参考实现保留) - * @deprecated DACP已改为Mock模式,此方法仅保留作为参考 - */ - async startDACPService() { - // 🔧 Mock模式下输出提示信息即可 - console.error(''); - console.error('====================================='); - console.error('🔧 DACP Mock模式已启用'); - console.error('📦 本地函数调用模式:无需HTTP服务'); - console.error('🔧 支持的Actions: send_email, calculate'); - console.error('✅ Mock模式启动成功'); - console.error('====================================='); - console.error(''); - - /* HTTP模式参考实现(已禁用) - const { spawn } = require('child_process'); - const path = require('path'); - - try { - this.log('🔍 检测DACP服务状态...'); - - // 先检测是否已有DACP服务运行 - const isRunning = await this.isDACPServiceRunning(); - - if (isRunning) { - // 服务已存在,获取服务信息并直接使用 - const serviceInfo = await this.getDACPServiceInfo(); - console.error(''); // 空行分隔 - console.error('====================================='); - console.error('🔄 发现现有DACP服务,直接复用'); - console.error('📍 DACP服务地址: http://localhost:3002'); - if (serviceInfo) { - console.error(`🏷️ 服务名称: ${serviceInfo.service?.name || 'Unknown'}`); - console.error(`📦 服务版本: ${serviceInfo.service?.version || 'Unknown'}`); - console.error(`🔧 可用操作: ${serviceInfo.available_actions?.join(', ') || 'Unknown'}`); - } - console.error('====================================='); - console.error(''); // 空行分隔 - return; // 直接返回,不启动新服务 - } - - this.log('🚀 启动新的DACP服务...'); - - // DACP服务路径 - const dacpPath = path.join(__dirname, '../../dacp/dacp-promptx-service'); - - // 启动DACP服务作为子进程 - // 注意:不能直接使用 'inherit',因为会干扰MCP的stdio通信 - // 但我们需要看到DACP的启动信息 - this.dacpProcess = spawn('node', ['server.js'], { - cwd: dacpPath, - stdio: ['ignore', 'pipe', 'pipe'], // stdin忽略, stdout和stderr都输出到pipe - shell: true, - detached: false // tree-kill 会处理整个进程树,不需要 detached - }); - - // 将DACP的输出转发到stderr(这样不会干扰MCP的stdout) - this.dacpProcess.stdout.on('data', (data) => { - const output = data.toString().trim(); - if (output) { - console.error(`[DACP] ${output}`); - } - }); - - this.dacpProcess.stderr.on('data', (data) => { - const output = data.toString().trim(); - if (output) { - console.error(`[DACP ERROR] ${output}`); - } - }); - - // 监听子进程退出 - this.dacpProcess.on('exit', (code, signal) => { - this.log(`DACP服务已退出 (code: ${code}, signal: ${signal})`); - this.dacpProcess = null; - }); - - // 监听子进程错误 - this.dacpProcess.on('error', (err) => { - console.error(`DACP进程错误: ${err.message}`); - }); - - // 等待服务启动 - 通过监听输出来判断 - await new Promise((resolve, reject) => { - let started = false; - const timeout = setTimeout(() => { - if (!started) { - reject(new Error('DACP服务启动超时')); - } - }, 10000); // 10秒超时 - - // 监听输出,判断服务是否启动 - const checkStarted = (data) => { - const output = data.toString(); - // 检查是否包含启动成功的标志 - if (output.includes('Running at http://localhost:') || - output.includes('🚀') || - output.includes('DACP') || - output.includes('3002')) { - if (!started) { - started = true; - clearTimeout(timeout); - console.error(''); // 空行分隔 - console.error('====================================='); - console.error('✅ DACP服务启动成功'); - console.error('📍 DACP服务地址: http://localhost:3002'); - console.error('🔧 支持的Actions: send_email, schedule_meeting, create_document'); - console.error('====================================='); - console.error(''); // 空行分隔 - resolve(); - } - } - }; - - this.dacpProcess.stdout.on('data', checkStarted); - - this.dacpProcess.on('error', (err) => { - clearTimeout(timeout); - reject(new Error(`DACP服务启动失败: ${err.message}`)); - }); - - this.dacpProcess.on('exit', (code) => { - if (!started) { - clearTimeout(timeout); - reject(new Error(`DACP服务意外退出,退出码: ${code}`)); - } - }); - }); - - } catch (error) { - this.log(`❌ DACP服务启动失败: ${error.message}`); - throw error; - } - */ - } /** * 设置MCP工具处理程序 - 使用正确的MCP SDK API @@ -491,7 +236,6 @@ class MCPServerCommand { return result; }, - 'promptx_dacp': (args) => [args], 'promptx_tool': (args) => [args] }; diff --git a/src/lib/commands/MCPStreamableHttpCommand.js b/src/lib/commands/MCPStreamableHttpCommand.js index 7bb5ded..7b554b4 100644 --- a/src/lib/commands/MCPStreamableHttpCommand.js +++ b/src/lib/commands/MCPStreamableHttpCommand.js @@ -450,7 +450,6 @@ class MCPStreamableHttpCommand { } return result; }, - 'promptx_dacp': (args) => [args] }; const mapper = paramMapping[toolName]; diff --git a/src/lib/core/pouch/PouchCLI.js b/src/lib/core/pouch/PouchCLI.js index 5d0caaf..31b2977 100644 --- a/src/lib/core/pouch/PouchCLI.js +++ b/src/lib/core/pouch/PouchCLI.js @@ -31,7 +31,6 @@ class PouchCLI { learn: commands.LearnCommand, recall: commands.RecallCommand, remember: commands.RememberCommand, - dacp: commands.DACPCommand, tool: commands.PromptXToolCommand }) diff --git a/src/lib/core/pouch/commands/DACPCommand.js b/src/lib/core/pouch/commands/DACPCommand.js deleted file mode 100644 index 6636265..0000000 --- a/src/lib/core/pouch/commands/DACPCommand.js +++ /dev/null @@ -1,282 +0,0 @@ -const BasePouchCommand = require('../BasePouchCommand'); -const http = require('http'); -const fs = require('fs'); -const path = require('path'); - -/** - * DACP服务调用命令 - * 负责调用DACP服务,实现从AI建议到AI行动的转换 - * - * 🔧 当前实现:Mock模式(本地函数调用) - * 🌐 HTTP模式代码保留作为参考实现 - */ -class DACPCommand extends BasePouchCommand { - constructor() { - super(); - - // 统一的DACP服务端点 - // 所有service_id都路由到同一个服务 - this.defaultEndpoint = 'http://localhost:3002/dacp'; - - // 🔧 永久使用Mock模式(本地函数调用) - // 不再支持HTTP模式,简化架构复杂度 - this.useMockMode = true; - } - - /** - * 验证参数格式 - * @param {Object} args - 参数对象 - */ - validateArgs(args) { - if (!args.service_id) { - throw new Error('缺少必需参数: service_id'); - } - - if (!args.action) { - throw new Error('缺少必需参数: action'); - } - - if (!args.parameters) { - throw new Error('缺少必需参数: parameters'); - } - - if (!args.parameters.user_request) { - throw new Error('缺少必需参数: parameters.user_request'); - } - } - - /** - * 获取服务端点(HTTP模式 - 仅作参考实现保留) - * @deprecated 当前使用Mock模式,此方法仅保留作为参考 - * @param {string} serviceId - 服务ID - * @returns {string} 服务端点URL - */ - getServiceEndpoint(serviceId) { - // 现在所有服务都指向同一个端点 - // serviceId 只是用来在DACP服务内部路由到不同的action - return this.defaultEndpoint; - } - - /** - * 执行DACP服务调用(内部方法) - * @param {Object} args - 调用参数 - * @returns {Promise} DACP响应 - */ - async callDACPService(args) { - try { - // 验证参数 - this.validateArgs(args); - - const { service_id, action, parameters } = args; - - // 🔧 直接使用本地Mock调用 - return await this.callLocalService(args); - - } catch (error) { - // 统一错误处理 - if (error.message.startsWith('缺少必需参数') || - error.message.startsWith('未找到DACP服务') || - error.message.startsWith('DACP响应解析失败')) { - throw error; - } - - throw new Error(`DACP服务调用失败: ${error.message}`); - } - } - - /** - * 本地服务调用(Mock模式) - * @param {Object} args - 调用参数 - * @returns {Promise} DACP标准响应 - */ - async callLocalService(args) { - const startTime = Date.now(); - const { service_id, action, parameters } = args; - const request_id = `req_${Date.now()}`; - - try { - // 1. 读取DACP配置 - const configPath = path.join(__dirname, '../../../dacp/dacp-promptx-service/dacp.config.json'); - const config = JSON.parse(fs.readFileSync(configPath, 'utf8')); - - // 2. 验证service_id - if (service_id !== config.service.id) { - throw new Error(`Service ${service_id} not found. This is ${config.service.id}`); - } - - // 3. 动态加载actions - const actionsDir = path.join(__dirname, '../../../dacp/dacp-promptx-service/actions'); - const actions = {}; - - if (fs.existsSync(actionsDir)) { - fs.readdirSync(actionsDir).forEach(file => { - if (file.endsWith('.js')) { - const actionName = file.replace('.js', ''); - actions[actionName] = require(path.join(actionsDir, file)); - } - }); - } - - // 4. 查找action处理器 - let handler = null; - - // 先按模块名查找 - for (const [moduleName, module] of Object.entries(actions)) { - if (module[action] && typeof module[action] === 'function') { - handler = module[action]; - break; - } - } - - // 找不到则按精确匹配查找 - if (!handler && actions[action]) { - handler = actions[action]; - } - - if (!handler) { - throw new Error(`Action ${action} is not supported`); - } - - // 5. 执行action - const result = await handler(parameters); - - // 6. 返回DACP标准格式响应 - return { - request_id: request_id, - success: true, - data: { - execution_result: result, - evaluation: { - constraint_compliance: true, - rule_adherence: true, - guideline_alignment: true - }, - applied_guidelines: [ - 'DACP protocol standard', - 'Local mock execution' - ], - performance_metrics: { - execution_time: `${Date.now() - startTime}ms`, - resource_usage: 'minimal' - } - } - }; - - } catch (error) { - return { - request_id: request_id, - success: false, - error: { - code: error.message.includes('not found') ? 'INVALID_SERVICE' : - error.message.includes('not supported') ? 'UNKNOWN_ACTION' : 'EXECUTION_ERROR', - message: error.message - } - }; - } - } - - /** - * 发送HTTP请求(HTTP模式 - 仅作参考实现保留) - * @deprecated 当前使用Mock模式,此方法仅保留作为参考 - * @param {string} url - 请求URL - * @param {Object} data - 请求数据 - * @returns {Promise} 响应数据 - */ - makeHttpRequest(url, data) { - return new Promise((resolve, reject) => { - const urlObj = new URL(url); - const options = { - hostname: urlObj.hostname, - port: urlObj.port, - path: urlObj.pathname, - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Content-Length': Buffer.byteLength(JSON.stringify(data)) - } - }; - - const req = http.request(options, (res) => { - let responseData = ''; - - res.on('data', (chunk) => { - responseData += chunk; - }); - - res.on('end', () => { - try { - const result = JSON.parse(responseData); - resolve(result); - } catch (error) { - reject(new Error(`DACP响应解析失败: ${error.message}`)); - } - }); - }); - - req.on('error', (error) => { - reject(error); - }); - - req.write(JSON.stringify(data)); - req.end(); - }); - } - - // BasePouchCommand的抽象方法实现(虽然不会被用到) - getPurpose() { - return '调用DACP专业服务,让PromptX角色拥有执行能力'; - } - - async getContent(args) { - try { - // 处理参数:如果是数组,取第一个元素;否则直接使用 - const dacpArgs = Array.isArray(args) ? args[0] : args; - - // 执行DACP调用 - const result = await this.callDACPService(dacpArgs); - - // 格式化响应 - if (result.success) { - const executionResult = result.data.execution_result; - const metrics = result.data.performance_metrics; - return `🚀 DACP服务调用成功 (🔧 本地Mock模式) - -📋 执行结果: -${JSON.stringify(executionResult, null, 2)} - -⏱️ 性能指标: -- 执行时间: ${metrics.execution_time} -- 资源使用: ${metrics.resource_usage} - -🎯 请求ID: ${result.request_id}`; - } else { - return `❌ DACP服务调用失败 - -错误信息: ${result.error?.message || '未知错误'} -错误代码: ${result.error?.code || 'UNKNOWN'} - -🎯 请求ID: ${result.request_id}`; - } - } catch (error) { - return `❌ DACP服务调用异常 - -错误详情: ${error.message} -运行模式: 🔧 本地Mock模式 - -💡 请检查: -1. DACP action模块是否存在 -2. 服务ID是否正确 -3. 操作名称是否有效 -4. 参数格式是否正确`; - } - } - - getPATEOAS(args) { - return { - currentState: 'dacp_ready', - nextActions: [] - }; - } -} - -module.exports = DACPCommand; \ No newline at end of file diff --git a/src/lib/core/pouch/commands/index.js b/src/lib/core/pouch/commands/index.js index 4412494..def4877 100644 --- a/src/lib/core/pouch/commands/index.js +++ b/src/lib/core/pouch/commands/index.js @@ -8,7 +8,6 @@ const ActionCommand = require('./ActionCommand') const LearnCommand = require('./LearnCommand') const RecallCommand = require('./RecallCommand') const RememberCommand = require('./RememberCommand') -const DACPCommand = require('./DACPCommand') const PromptXToolCommand = require('../../../commands/PromptXToolCommand') module.exports = { @@ -18,6 +17,5 @@ module.exports = { LearnCommand, RecallCommand, RememberCommand, - DACPCommand, PromptXToolCommand } diff --git a/src/lib/mcp/toolDefinitions.js b/src/lib/mcp/toolDefinitions.js index 0545fff..8f951db 100644 --- a/src/lib/mcp/toolDefinitions.js +++ b/src/lib/mcp/toolDefinitions.js @@ -111,46 +111,6 @@ const TOOL_DEFINITIONS = [ tags: z.string().optional().describe('自定义标签,用空格分隔,可选') }) }, - { - name: 'promptx_dacp', - description: '🚀 [DACP专业服务工具] 专业执行工具 - 需要明确知道如何使用特定DACP服务时调用。工具存在但需要专业知识才能正确使用,不建议在不了解服务配置和参数的情况下尝试。', - inputSchema: { - type: 'object', - properties: { - service_id: { - type: 'string', - description: 'DACP服务ID,如:dacp-email-service' - }, - action: { - type: 'string', - description: '具体操作,如:send_email' - }, - parameters: { - type: 'object', - properties: { - user_request: { - type: 'string', - description: '用户自然语言需求' - }, - context: { - type: 'object', - description: '上下文信息' - } - }, - required: ['user_request'] - } - }, - required: ['service_id', 'action', 'parameters'] - }, - zodSchema: z.object({ - service_id: z.string().describe('DACP服务ID,如:dacp-email-service'), - action: z.string().describe('具体操作,如:send_email'), - parameters: z.object({ - user_request: z.string().describe('用户自然语言需求'), - context: z.object({}).optional().describe('上下文信息') - }) - }) - }, { name: 'promptx_tool', description: '🔧 [工具执行器] 执行通过@tool协议声明的JavaScript工具 - 支持角色配置中定义的专业工具能力,如@tool://calculator数学计算、@tool://send-email邮件发送等。提供安全沙箱执行、参数验证、错误处理和性能监控。', diff --git a/src/lib/utils/DACPConfigManager.js b/src/lib/utils/DACPConfigManager.js deleted file mode 100644 index 284d104..0000000 --- a/src/lib/utils/DACPConfigManager.js +++ /dev/null @@ -1,360 +0,0 @@ -const fs = require('fs-extra') -const path = require('path') -const os = require('os') -const { getDirectoryService } = require('./DirectoryService') - -/** - * DACP配置管理器 - * 支持项目级配置优先,用户级配置回退的分层配置策略 - * 配置优先级:项目级(.promptx/dacp/) > 用户级(~/.promptx/dacp/) - */ -class DACPConfigManager { - constructor() { - this.userHome = os.homedir() - this.userDacpConfigDir = path.join(this.userHome, '.promptx', 'dacp') - this.directoryService = getDirectoryService() - } - - /** - * 确保用户级DACP配置目录存在 - */ - async ensureUserConfigDir() { - await fs.ensureDir(this.userDacpConfigDir) - } - - /** - * 获取项目级DACP配置目录路径 - * @returns {Promise} 项目级配置目录路径或null - */ - async getProjectConfigDir() { - try { - const promptxDir = await this.directoryService.getPromptXDirectory() - return path.join(promptxDir, 'dacp') - } catch (error) { - console.warn('获取项目级配置目录失败:', error.message) - return null - } - } - - /** - * 确保项目级DACP配置目录存在 - * @returns {Promise} 项目级配置目录路径或null - */ - async ensureProjectConfigDir() { - const projectConfigDir = await this.getProjectConfigDir() - if (projectConfigDir) { - await fs.ensureDir(projectConfigDir) - return projectConfigDir - } - return null - } - - /** - * 获取指定action的用户级配置文件路径 - * @param {string} action - action名称,如 'send_email' - * @returns {string} 用户级配置文件完整路径 - */ - getUserConfigPath(action) { - return path.join(this.userDacpConfigDir, `${action}.json`) - } - - /** - * 获取指定action的项目级配置文件路径 - * @param {string} action - action名称,如 'send_email' - * @returns {Promise} 项目级配置文件完整路径或null - */ - async getProjectConfigPath(action) { - const projectConfigDir = await this.getProjectConfigDir() - if (projectConfigDir) { - return path.join(projectConfigDir, `${action}.json`) - } - return null - } - - /** - * 获取指定action的配置文件路径(用户级,向后兼容) - * @param {string} action - action名称,如 'send_email' - * @returns {string} 配置文件完整路径 - * @deprecated 使用getUserConfigPath或getProjectConfigPath - */ - getConfigPath(action) { - return this.getUserConfigPath(action) - } - - /** - * 读取项目级action配置 - * @param {string} action - action名称 - * @returns {Promise} 配置对象或null - */ - async readProjectActionConfig(action) { - try { - const projectConfigPath = await this.getProjectConfigPath(action) - if (projectConfigPath && await fs.pathExists(projectConfigPath)) { - const config = await fs.readJson(projectConfigPath) - console.log(`📁 使用项目级DACP配置: ${action}`) - return config - } - } catch (error) { - console.warn(`读取项目级DACP配置失败 ${action}:`, error.message) - } - return null - } - - /** - * 读取用户级action配置 - * @param {string} action - action名称 - * @returns {Promise} 配置对象或null - */ - async readUserActionConfig(action) { - const userConfigPath = this.getUserConfigPath(action) - - try { - if (await fs.pathExists(userConfigPath)) { - const config = await fs.readJson(userConfigPath) - console.log(`🏠 使用用户级DACP配置: ${action}`) - return config - } - } catch (error) { - console.warn(`读取用户级DACP配置失败 ${action}:`, error.message) - } - return null - } - - /** - * 读取action配置(项目级优先,用户级回退) - * @param {string} action - action名称 - * @returns {Promise} 配置对象或null - */ - async readActionConfig(action) { - // 优先级:项目级 > 用户级 - const projectConfig = await this.readProjectActionConfig(action) - if (projectConfig) { - return projectConfig - } - - return await this.readUserActionConfig(action) - } - - /** - * 写入用户级action配置 - * @param {string} action - action名称 - * @param {Object} config - 配置对象 - */ - async writeUserActionConfig(action, config) { - await this.ensureUserConfigDir() - const configPath = this.getUserConfigPath(action) - await fs.writeJson(configPath, config, { spaces: 2 }) - } - - /** - * 写入项目级action配置 - * @param {string} action - action名称 - * @param {Object} config - 配置对象 - */ - async writeProjectActionConfig(action, config) { - const projectConfigDir = await this.ensureProjectConfigDir() - if (projectConfigDir) { - const configPath = path.join(projectConfigDir, `${action}.json`) - await fs.writeJson(configPath, config, { spaces: 2 }) - } else { - throw new Error('无法获取项目目录,写入项目级配置失败') - } - } - - /** - * 写入action配置(向后兼容,写入用户级) - * @param {string} action - action名称 - * @param {Object} config - 配置对象 - * @deprecated 使用writeUserActionConfig或writeProjectActionConfig - */ - async writeActionConfig(action, config) { - return await this.writeUserActionConfig(action, config) - } - - /** - * 检查项目级action配置是否存在 - * @param {string} action - action名称 - * @returns {Promise} - */ - async hasProjectActionConfig(action) { - try { - const projectConfigPath = await this.getProjectConfigPath(action) - if (!projectConfigPath) { - return false - } - return await fs.pathExists(projectConfigPath) - } catch (error) { - return false - } - } - - /** - * 检查用户级action配置是否存在 - * @param {string} action - action名称 - * @returns {Promise} - */ - async hasUserActionConfig(action) { - const userConfigPath = this.getUserConfigPath(action) - return await fs.pathExists(userConfigPath) - } - - /** - * 检查action配置是否存在(项目级或用户级) - * @param {string} action - action名称 - * @returns {Promise} - */ - async hasActionConfig(action) { - const hasProject = await this.hasProjectActionConfig(action) - if (hasProject) { - return true - } - return await this.hasUserActionConfig(action) - } - - /** - * 验证邮件配置 - * @param {Object} config - 邮件配置对象 - * @returns {Object} 验证结果 {valid: boolean, errors: string[]} - */ - validateEmailConfig(config) { - const errors = [] - - if (!config) { - errors.push('配置对象不能为空') - return { valid: false, errors } - } - - // 验证provider - if (!config.provider) { - errors.push('缺少邮件服务提供商(provider)配置') - } - - // 验证SMTP配置 - if (!config.smtp) { - errors.push('缺少SMTP配置') - } else { - if (!config.smtp.user) { - errors.push('缺少SMTP用户名(smtp.user)') - } - if (!config.smtp.password) { - errors.push('缺少SMTP密码(smtp.password)') - } - } - - // 验证发件人配置 - if (!config.sender) { - errors.push('缺少发件人配置(sender)') - } else { - if (!config.sender.email) { - errors.push('缺少发件人邮箱(sender.email)') - } - if (!config.sender.name) { - errors.push('缺少发件人姓名(sender.name)') - } - } - - return { - valid: errors.length === 0, - errors - } - } - - /** - * 获取邮件服务提供商配置 - * @param {string} provider - 提供商名称 - * @returns {Object} 提供商配置 - */ - getProviderConfig(provider) { - const providers = { - gmail: { - smtp: 'smtp.gmail.com', - port: 587, - secure: false, - requireAuth: true - }, - outlook: { - smtp: 'smtp-mail.outlook.com', - port: 587, - secure: false, - requireAuth: true - }, - qq: { - smtp: 'smtp.qq.com', - port: 465, - secure: true, - requireAuth: true - }, - '163': { - smtp: 'smtp.163.com', - port: 465, - secure: true, - requireAuth: true - }, - '126': { - smtp: 'smtp.126.com', - port: 465, - secure: true, - requireAuth: true - } - } - - return providers[provider] || null - } - - /** - * 生成配置错误提示信息 - * @param {string} action - action名称 - * @param {Object} validation - 验证结果 - * @returns {Promise} 错误提示信息 - */ - async generateConfigErrorMessage(action, validation = null) { - const userConfigPath = this.getUserConfigPath(action) - const projectConfigPath = await this.getProjectConfigPath(action) - - let message = `\n📧 DACP邮件服务配置缺失\n\n` - - if (!validation) { - // 配置文件不存在 - message += `❌ 未找到配置文件\n\n` - message += `🔍 查找路径:\n` - if (projectConfigPath) { - message += ` 项目级: ${projectConfigPath} (优先)\n` - } - message += ` 用户级: ${userConfigPath} (回退)\n\n` - message += `📝 推荐创建项目级配置文件,内容如下:\n\n` - message += `{\n` - message += ` "provider": "gmail",\n` - message += ` "smtp": {\n` - message += ` "user": "your-email@gmail.com",\n` - message += ` "password": "your-app-password"\n` - message += ` },\n` - message += ` "sender": {\n` - message += ` "name": "Your Name",\n` - message += ` "email": "your-email@gmail.com"\n` - message += ` }\n` - message += `}\n\n` - message += `💡 支持的邮件服务商: gmail, outlook, qq, 163, 126\n\n` - message += `🏗️ 配置优先级: 项目级(.promptx/dacp/) > 用户级(~/.promptx/dacp/)\n\n` - message += `🔐 Gmail用户需要使用应用专用密码:\n` - message += ` 1. 进入 Google 账户设置\n` - message += ` 2. 启用两步验证\n` - message += ` 3. 生成应用专用密码\n` - message += ` 4. 使用生成的密码替换上面的 "your-app-password"\n` - } else { - // 配置不完整 - const configLocation = await this.hasProjectActionConfig(action) ? - (projectConfigPath ? `项目级: ${projectConfigPath}` : '项目级配置') : - `用户级: ${userConfigPath}` - message += `❌ 配置文件存在但不完整: ${configLocation}\n\n` - message += `缺少以下配置项:\n` - validation.errors.forEach(error => { - message += ` • ${error}\n` - }) - message += `\n请检查并完善配置文件。\n` - } - - return message - } -} - -module.exports = DACPConfigManager \ No newline at end of file diff --git a/src/package.registry.json b/src/package.registry.json index 2a5c31b..7a30793 100644 --- a/src/package.registry.json +++ b/src/package.registry.json @@ -4,9 +4,9 @@ "metadata": { "version": "2.0.0", "description": "package 级资源注册表", - "createdAt": "2025-06-28T06:05:40.997Z", - "updatedAt": "2025-06-28T06:05:41.006Z", - "resourceCount": 63 + "createdAt": "2025-06-28T06:22:37.206Z", + "updatedAt": "2025-06-28T06:22:37.216Z", + "resourceCount": 61 }, "resources": [ { @@ -17,9 +17,9 @@ "description": "专业角色,提供特定领域的专业能力", "reference": "@package://prompt/domain/assistant/assistant.role.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.000Z", - "updatedAt": "2025-06-28T06:05:41.000Z", - "scannedAt": "2025-06-28T06:05:41.000Z" + "createdAt": "2025-06-28T06:22:37.211Z", + "updatedAt": "2025-06-28T06:22:37.211Z", + "scannedAt": "2025-06-28T06:22:37.211Z" } }, { @@ -30,9 +30,9 @@ "description": "专业角色,提供特定领域的专业能力", "reference": "@package://prompt/domain/frontend-developer/frontend-developer.role.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.000Z", - "updatedAt": "2025-06-28T06:05:41.000Z", - "scannedAt": "2025-06-28T06:05:41.000Z" + "createdAt": "2025-06-28T06:22:37.211Z", + "updatedAt": "2025-06-28T06:22:37.211Z", + "scannedAt": "2025-06-28T06:22:37.211Z" } }, { @@ -43,9 +43,9 @@ "description": "专业角色,提供特定领域的专业能力", "reference": "@package://prompt/domain/java-backend-developer/java-backend-developer.role.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.000Z", - "updatedAt": "2025-06-28T06:05:41.000Z", - "scannedAt": "2025-06-28T06:05:41.000Z" + "createdAt": "2025-06-28T06:22:37.211Z", + "updatedAt": "2025-06-28T06:22:37.211Z", + "scannedAt": "2025-06-28T06:22:37.211Z" } }, { @@ -56,9 +56,9 @@ "description": "专业角色,提供特定领域的专业能力", "reference": "@package://prompt/domain/noface/noface.role.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.000Z", - "updatedAt": "2025-06-28T06:05:41.000Z", - "scannedAt": "2025-06-28T06:05:41.000Z" + "createdAt": "2025-06-28T06:22:37.211Z", + "updatedAt": "2025-06-28T06:22:37.211Z", + "scannedAt": "2025-06-28T06:22:37.211Z" } }, { @@ -69,9 +69,9 @@ "description": "专业角色,提供特定领域的专业能力", "reference": "@package://prompt/domain/nuwa/nuwa.role.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.000Z", - "updatedAt": "2025-06-28T06:05:41.000Z", - "scannedAt": "2025-06-28T06:05:41.000Z" + "createdAt": "2025-06-28T06:22:37.211Z", + "updatedAt": "2025-06-28T06:22:37.211Z", + "scannedAt": "2025-06-28T06:22:37.211Z" } }, { @@ -82,9 +82,9 @@ "description": "专业角色,提供特定领域的专业能力", "reference": "@package://prompt/domain/product-manager/product-manager.role.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.000Z", - "updatedAt": "2025-06-28T06:05:41.000Z", - "scannedAt": "2025-06-28T06:05:41.000Z" + "createdAt": "2025-06-28T06:22:37.211Z", + "updatedAt": "2025-06-28T06:22:37.211Z", + "scannedAt": "2025-06-28T06:22:37.211Z" } }, { @@ -95,9 +95,9 @@ "description": "专业角色,提供特定领域的专业能力", "reference": "@package://prompt/domain/sean/sean.role.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.000Z", - "updatedAt": "2025-06-28T06:05:41.000Z", - "scannedAt": "2025-06-28T06:05:41.000Z" + "createdAt": "2025-06-28T06:22:37.211Z", + "updatedAt": "2025-06-28T06:22:37.211Z", + "scannedAt": "2025-06-28T06:22:37.211Z" } }, { @@ -108,35 +108,9 @@ "description": "专业角色,提供特定领域的专业能力", "reference": "@package://prompt/domain/xiaohongshu-marketer/xiaohongshu-marketer.role.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.000Z", - "updatedAt": "2025-06-28T06:05:41.000Z", - "scannedAt": "2025-06-28T06:05:41.000Z" - } - }, - { - "id": "dacp-email-sending", - "source": "package", - "protocol": "execution", - "name": "Dacp Email Sending 执行模式", - "description": "执行模式,定义具体的行为模式", - "reference": "@package://prompt/core/dacp-email-sending.execution.md", - "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" - } - }, - { - "id": "dacp-service-calling", - "source": "package", - "protocol": "execution", - "name": "Dacp Service Calling 执行模式", - "description": "执行模式,定义具体的行为模式", - "reference": "@package://prompt/core/dacp-service-calling.execution.md", - "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.211Z", + "updatedAt": "2025-06-28T06:22:37.211Z", + "scannedAt": "2025-06-28T06:22:37.211Z" } }, { @@ -147,9 +121,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/assistant/execution/assistant.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -160,9 +134,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/java-backend-developer/execution/code-quality.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -173,9 +147,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/frontend-developer/execution/frontend-developer.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -186,9 +160,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/frontend-developer/execution/technical-architecture.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -199,9 +173,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/frontend-developer/execution/user-experience.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -212,9 +186,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/frontend-developer/execution/wechat-miniprogram-development.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -225,9 +199,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/java-backend-developer/execution/database-design.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -238,9 +212,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/java-backend-developer/execution/java-backend-developer.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -251,9 +225,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/java-backend-developer/execution/spring-ecosystem.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -264,9 +238,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/java-backend-developer/execution/system-architecture.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -277,9 +251,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/noface/execution/adaptive-learning.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -290,9 +264,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/noface/execution/content-preservation.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -303,9 +277,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/nuwa/execution/dpml-authoring.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -316,9 +290,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/nuwa/execution/role-design-patterns.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -329,9 +303,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/nuwa/execution/role-generation.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -342,9 +316,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/nuwa/execution/visualization-enhancement.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -355,9 +329,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/product-manager/execution/market-analysis.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -368,9 +342,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/product-manager/execution/product-manager.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -381,9 +355,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/product-manager/execution/user-research.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -394,9 +368,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/sean/execution/contradiction-analysis.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -407,9 +381,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/sean/execution/contradiction-management-methodology.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -420,9 +394,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/sean/execution/sean-decision-framework.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -433,9 +407,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/sean/execution/template-adherence.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -446,9 +420,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/xiaohongshu-marketer/execution/brand-marketing.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -459,9 +433,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/xiaohongshu-marketer/execution/community-building.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -472,9 +446,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/xiaohongshu-marketer/execution/content-creation.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -485,9 +459,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/xiaohongshu-marketer/execution/content-optimization.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -498,9 +472,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/xiaohongshu-marketer/execution/data-analytics.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -511,9 +485,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/xiaohongshu-marketer/execution/ecommerce-conversion.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -524,9 +498,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/xiaohongshu-marketer/execution/performance-optimization.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -537,9 +511,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/xiaohongshu-marketer/execution/platform-compliance.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -550,9 +524,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/xiaohongshu-marketer/execution/team-collaboration.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -563,9 +537,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/xiaohongshu-marketer/execution/user-operation.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -576,9 +550,9 @@ "description": "执行模式,定义具体的行为模式", "reference": "@package://prompt/domain/xiaohongshu-marketer/execution/xiaohongshu-marketer.execution.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.001Z", - "updatedAt": "2025-06-28T06:05:41.001Z", - "scannedAt": "2025-06-28T06:05:41.001Z" + "createdAt": "2025-06-28T06:22:37.212Z", + "updatedAt": "2025-06-28T06:22:37.212Z", + "scannedAt": "2025-06-28T06:22:37.212Z" } }, { @@ -589,9 +563,9 @@ "description": "思维模式,指导AI的思考方式", "reference": "@package://prompt/core/_deprecated/recall_v1.thought.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.003Z", - "updatedAt": "2025-06-28T06:05:41.003Z", - "scannedAt": "2025-06-28T06:05:41.002Z" + "createdAt": "2025-06-28T06:22:37.213Z", + "updatedAt": "2025-06-28T06:22:37.213Z", + "scannedAt": "2025-06-28T06:22:37.213Z" } }, { @@ -602,9 +576,9 @@ "description": "思维模式,指导AI的思考方式", "reference": "@package://prompt/core/_deprecated/remember_v1.thought.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.003Z", - "updatedAt": "2025-06-28T06:05:41.003Z", - "scannedAt": "2025-06-28T06:05:41.003Z" + "createdAt": "2025-06-28T06:22:37.213Z", + "updatedAt": "2025-06-28T06:22:37.213Z", + "scannedAt": "2025-06-28T06:22:37.213Z" } }, { @@ -615,9 +589,9 @@ "description": "思维模式,指导AI的思考方式", "reference": "@package://prompt/core/recall-xml.thought.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.003Z", - "updatedAt": "2025-06-28T06:05:41.003Z", - "scannedAt": "2025-06-28T06:05:41.003Z" + "createdAt": "2025-06-28T06:22:37.213Z", + "updatedAt": "2025-06-28T06:22:37.213Z", + "scannedAt": "2025-06-28T06:22:37.213Z" } }, { @@ -628,9 +602,9 @@ "description": "思维模式,指导AI的思考方式", "reference": "@package://prompt/core/recall.thought.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.003Z", - "updatedAt": "2025-06-28T06:05:41.003Z", - "scannedAt": "2025-06-28T06:05:41.003Z" + "createdAt": "2025-06-28T06:22:37.213Z", + "updatedAt": "2025-06-28T06:22:37.213Z", + "scannedAt": "2025-06-28T06:22:37.213Z" } }, { @@ -641,9 +615,9 @@ "description": "思维模式,指导AI的思考方式", "reference": "@package://prompt/core/remember-xml.thought.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.003Z", - "updatedAt": "2025-06-28T06:05:41.003Z", - "scannedAt": "2025-06-28T06:05:41.003Z" + "createdAt": "2025-06-28T06:22:37.213Z", + "updatedAt": "2025-06-28T06:22:37.213Z", + "scannedAt": "2025-06-28T06:22:37.213Z" } }, { @@ -654,9 +628,9 @@ "description": "思维模式,指导AI的思考方式", "reference": "@package://prompt/core/remember.thought.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.003Z", - "updatedAt": "2025-06-28T06:05:41.003Z", - "scannedAt": "2025-06-28T06:05:41.003Z" + "createdAt": "2025-06-28T06:22:37.213Z", + "updatedAt": "2025-06-28T06:22:37.213Z", + "scannedAt": "2025-06-28T06:22:37.213Z" } }, { @@ -667,9 +641,9 @@ "description": "思维模式,指导AI的思考方式", "reference": "@package://prompt/domain/assistant/thought/assistant.thought.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.003Z", - "updatedAt": "2025-06-28T06:05:41.003Z", - "scannedAt": "2025-06-28T06:05:41.003Z" + "createdAt": "2025-06-28T06:22:37.213Z", + "updatedAt": "2025-06-28T06:22:37.213Z", + "scannedAt": "2025-06-28T06:22:37.213Z" } }, { @@ -680,9 +654,9 @@ "description": "思维模式,指导AI的思考方式", "reference": "@package://prompt/domain/frontend-developer/thought/frontend-developer.thought.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.003Z", - "updatedAt": "2025-06-28T06:05:41.003Z", - "scannedAt": "2025-06-28T06:05:41.003Z" + "createdAt": "2025-06-28T06:22:37.213Z", + "updatedAt": "2025-06-28T06:22:37.213Z", + "scannedAt": "2025-06-28T06:22:37.213Z" } }, { @@ -693,9 +667,9 @@ "description": "思维模式,指导AI的思考方式", "reference": "@package://prompt/domain/java-backend-developer/thought/java-backend-developer.thought.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.003Z", - "updatedAt": "2025-06-28T06:05:41.003Z", - "scannedAt": "2025-06-28T06:05:41.003Z" + "createdAt": "2025-06-28T06:22:37.213Z", + "updatedAt": "2025-06-28T06:22:37.213Z", + "scannedAt": "2025-06-28T06:22:37.213Z" } }, { @@ -706,9 +680,9 @@ "description": "思维模式,指导AI的思考方式", "reference": "@package://prompt/domain/nuwa/thought/role-creation.thought.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.003Z", - "updatedAt": "2025-06-28T06:05:41.003Z", - "scannedAt": "2025-06-28T06:05:41.003Z" + "createdAt": "2025-06-28T06:22:37.213Z", + "updatedAt": "2025-06-28T06:22:37.213Z", + "scannedAt": "2025-06-28T06:22:37.213Z" } }, { @@ -719,9 +693,9 @@ "description": "思维模式,指导AI的思考方式", "reference": "@package://prompt/domain/product-manager/thought/product-manager.thought.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.003Z", - "updatedAt": "2025-06-28T06:05:41.003Z", - "scannedAt": "2025-06-28T06:05:41.003Z" + "createdAt": "2025-06-28T06:22:37.213Z", + "updatedAt": "2025-06-28T06:22:37.213Z", + "scannedAt": "2025-06-28T06:22:37.213Z" } }, { @@ -732,9 +706,9 @@ "description": "思维模式,指导AI的思考方式", "reference": "@package://prompt/domain/sean/thought/contradiction-methodology.thought.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.003Z", - "updatedAt": "2025-06-28T06:05:41.003Z", - "scannedAt": "2025-06-28T06:05:41.003Z" + "createdAt": "2025-06-28T06:22:37.213Z", + "updatedAt": "2025-06-28T06:22:37.213Z", + "scannedAt": "2025-06-28T06:22:37.213Z" } }, { @@ -745,9 +719,9 @@ "description": "思维模式,指导AI的思考方式", "reference": "@package://prompt/domain/sean/thought/sean.thought.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.003Z", - "updatedAt": "2025-06-28T06:05:41.003Z", - "scannedAt": "2025-06-28T06:05:41.003Z" + "createdAt": "2025-06-28T06:22:37.213Z", + "updatedAt": "2025-06-28T06:22:37.213Z", + "scannedAt": "2025-06-28T06:22:37.213Z" } }, { @@ -758,9 +732,9 @@ "description": "思维模式,指导AI的思考方式", "reference": "@package://prompt/domain/xiaohongshu-marketer/thought/xiaohongshu-marketer.thought.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.003Z", - "updatedAt": "2025-06-28T06:05:41.003Z", - "scannedAt": "2025-06-28T06:05:41.003Z" + "createdAt": "2025-06-28T06:22:37.213Z", + "updatedAt": "2025-06-28T06:22:37.213Z", + "scannedAt": "2025-06-28T06:22:37.213Z" } }, { @@ -771,9 +745,9 @@ "description": "知识库,提供专业知识和信息", "reference": "@package://prompt/domain/sean/knowledge/contradiction-methodology.knowledge.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.004Z", - "updatedAt": "2025-06-28T06:05:41.004Z", - "scannedAt": "2025-06-28T06:05:41.004Z" + "createdAt": "2025-06-28T06:22:37.214Z", + "updatedAt": "2025-06-28T06:22:37.214Z", + "scannedAt": "2025-06-28T06:22:37.214Z" } }, { @@ -784,9 +758,9 @@ "description": "知识库,提供专业知识和信息", "reference": "@package://prompt/domain/sean/knowledge/product-philosophy.knowledge.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.004Z", - "updatedAt": "2025-06-28T06:05:41.004Z", - "scannedAt": "2025-06-28T06:05:41.004Z" + "createdAt": "2025-06-28T06:22:37.214Z", + "updatedAt": "2025-06-28T06:22:37.214Z", + "scannedAt": "2025-06-28T06:22:37.214Z" } }, { @@ -797,9 +771,9 @@ "description": "知识库,提供专业知识和信息", "reference": "@package://prompt/domain/sean/knowledge/promptx-evolution.knowledge.md", "metadata": { - "createdAt": "2025-06-28T06:05:41.004Z", - "updatedAt": "2025-06-28T06:05:41.004Z", - "scannedAt": "2025-06-28T06:05:41.004Z" + "createdAt": "2025-06-28T06:22:37.214Z", + "updatedAt": "2025-06-28T06:22:37.214Z", + "scannedAt": "2025-06-28T06:22:37.214Z" } }, { @@ -810,9 +784,9 @@ "description": "tool类型的资源", "reference": "@package://prompt/tool/calculator.tool.js", "metadata": { - "createdAt": "2025-06-28T06:05:41.004Z", - "updatedAt": "2025-06-28T06:05:41.004Z", - "scannedAt": "2025-06-28T06:05:41.004Z" + "createdAt": "2025-06-28T06:22:37.215Z", + "updatedAt": "2025-06-28T06:22:37.215Z", + "scannedAt": "2025-06-28T06:22:37.215Z" } }, { @@ -823,23 +797,23 @@ "description": "tool类型的资源", "reference": "@package://prompt/tool/send-email.tool.js", "metadata": { - "createdAt": "2025-06-28T06:05:41.005Z", - "updatedAt": "2025-06-28T06:05:41.005Z", - "scannedAt": "2025-06-28T06:05:41.005Z" + "createdAt": "2025-06-28T06:22:37.216Z", + "updatedAt": "2025-06-28T06:22:37.216Z", + "scannedAt": "2025-06-28T06:22:37.216Z" } } ], "stats": { - "totalResources": 63, + "totalResources": 61, "byProtocol": { "role": 8, - "execution": 36, + "execution": 34, "thought": 14, "knowledge": 3, "tool": 2 }, "bySource": { - "package": 63 + "package": 61 } } } diff --git a/src/tests/commands/DACPCommand.unit.test.js b/src/tests/commands/DACPCommand.unit.test.js deleted file mode 100644 index 1a3a066..0000000 --- a/src/tests/commands/DACPCommand.unit.test.js +++ /dev/null @@ -1,268 +0,0 @@ -const DACPCommand = require('../../lib/core/pouch/commands/DACPCommand'); - -// Mock fetch -global.fetch = jest.fn(); - -describe('DACPCommand', () => { - let dacpCommand; - - beforeEach(() => { - dacpCommand = new DACPCommand(); - fetch.mockClear(); - }); - - describe('协议参数解析', () => { - test('应该正确解析必需参数', () => { - const args = { - service_id: 'dacp-email-service', - action: 'send_email', - parameters: { - user_request: '给张三发个邮件', - context: { urgency: 'high' } - } - }; - - expect(() => dacpCommand.validateArgs(args)).not.toThrow(); - }); - - test('应该拒绝缺少service_id的请求', () => { - const args = { - action: 'send_email', - parameters: { - user_request: '给张三发个邮件' - } - }; - - expect(() => dacpCommand.validateArgs(args)) - .toThrow('缺少必需参数: service_id'); - }); - - test('应该拒绝缺少action的请求', () => { - const args = { - service_id: 'dacp-email-service', - parameters: { - user_request: '给张三发个邮件' - } - }; - - expect(() => dacpCommand.validateArgs(args)) - .toThrow('缺少必需参数: action'); - }); - - test('应该拒绝缺少parameters的请求', () => { - const args = { - service_id: 'dacp-email-service', - action: 'send_email' - }; - - expect(() => dacpCommand.validateArgs(args)) - .toThrow('缺少必需参数: parameters'); - }); - - test('应该拒绝缺少user_request的请求', () => { - const args = { - service_id: 'dacp-email-service', - action: 'send_email', - parameters: { - context: { urgency: 'high' } - } - }; - - expect(() => dacpCommand.validateArgs(args)) - .toThrow('缺少必需参数: parameters.user_request'); - }); - - test('应该允许可选的context参数', () => { - const args = { - service_id: 'dacp-email-service', - action: 'send_email', - parameters: { - user_request: '给张三发个邮件' - // context 是可选的 - } - }; - - expect(() => dacpCommand.validateArgs(args)).not.toThrow(); - }); - }); - - describe('服务路由', () => { - test('应该正确路由到已知服务', () => { - expect(dacpCommand.getServiceEndpoint('dacp-email-service')) - .toBe('http://localhost:3001/dacp'); - }); - - test('应该返回null对于未知服务', () => { - expect(dacpCommand.getServiceEndpoint('unknown-service')) - .toBeNull(); - }); - - test('应该支持多个服务路由', () => { - expect(dacpCommand.getServiceEndpoint('dacp-calendar-service')) - .toBe('http://localhost:3002/dacp'); - expect(dacpCommand.getServiceEndpoint('dacp-document-service')) - .toBe('http://localhost:3003/dacp'); - }); - }); - - describe('DACP协议转发', () => { - test('应该构造正确的DACP请求格式', async () => { - const args = { - service_id: 'dacp-email-service', - action: 'send_email', - parameters: { - user_request: '给张三发个会议提醒邮件', - context: { urgency: 'high' } - } - }; - - const mockResponse = { - request_id: 'req_123', - success: true, - data: { execution_result: { status: 'sent' } } - }; - - fetch.mockResolvedValueOnce({ - ok: true, - json: async () => mockResponse - }); - - const result = await dacpCommand.execute(args); - - // 验证fetch调用参数 - expect(fetch).toHaveBeenCalledWith('http://localhost:3001/dacp', expect.objectContaining({ - method: 'POST', - headers: { 'Content-Type': 'application/json' } - })); - - // 单独验证body格式 - const requestBody = JSON.parse(fetch.mock.calls[0][1].body); - expect(requestBody).toEqual({ - service_id: 'dacp-email-service', - action: 'send_email', - parameters: { - user_request: '给张三发个会议提醒邮件', - context: { urgency: 'high' } - }, - request_id: expect.stringMatching(/^req_\d+$/) - }); - - expect(result).toEqual(mockResponse); - }); - - test('应该自动生成request_id', async () => { - const args = { - service_id: 'dacp-email-service', - action: 'send_email', - parameters: { - user_request: '测试邮件' - } - }; - - fetch.mockResolvedValueOnce({ - ok: true, - json: async () => ({ success: true }) - }); - - await dacpCommand.execute(args); - - const requestBody = JSON.parse(fetch.mock.calls[0][1].body); - expect(requestBody.request_id).toMatch(/^req_\d+$/); - }); - - test('应该处理网络错误', async () => { - const args = { - service_id: 'dacp-email-service', - action: 'send_email', - parameters: { - user_request: '测试邮件' - } - }; - - fetch.mockRejectedValueOnce(new Error('网络连接失败')); - - await expect(dacpCommand.execute(args)) - .rejects.toThrow('DACP服务调用失败: 网络连接失败'); - }); - - test('应该处理未知服务错误', async () => { - const args = { - service_id: 'unknown-service', - action: 'some_action', - parameters: { - user_request: '测试请求' - } - }; - - await expect(dacpCommand.execute(args)) - .rejects.toThrow('未找到DACP服务: unknown-service'); - }); - - test('应该处理HTTP错误响应', async () => { - const args = { - service_id: 'dacp-email-service', - action: 'send_email', - parameters: { - user_request: '测试邮件' - } - }; - - fetch.mockResolvedValueOnce({ - ok: false, - status: 500, - statusText: 'Internal Server Error', - json: async () => ({ - success: false, - error: { code: 'DACP_SERVICE_ERROR', message: '服务内部错误' } - }) - }); - - const result = await dacpCommand.execute(args); - - expect(result).toEqual({ - success: false, - error: { code: 'DACP_SERVICE_ERROR', message: '服务内部错误' } - }); - }); - }); - - describe('错误处理', () => { - test('应该返回标准错误格式', async () => { - const args = { - service_id: 'dacp-email-service', - action: 'send_email', - parameters: { - user_request: '测试邮件' - } - }; - - fetch.mockRejectedValueOnce(new Error('Connection refused')); - - try { - await dacpCommand.execute(args); - } catch (error) { - expect(error.message).toBe('DACP服务调用失败: Connection refused'); - } - }); - - test('应该处理JSON解析错误', async () => { - const args = { - service_id: 'dacp-email-service', - action: 'send_email', - parameters: { - user_request: '测试邮件' - } - }; - - fetch.mockResolvedValueOnce({ - ok: true, - json: async () => { - throw new Error('Invalid JSON'); - } - }); - - await expect(dacpCommand.execute(args)) - .rejects.toThrow('DACP响应解析失败: Invalid JSON'); - }); - }); -}); \ No newline at end of file diff --git a/src/tests/e2e/dacp-calculator-e2e.test.js b/src/tests/e2e/dacp-calculator-e2e.test.js deleted file mode 100644 index 40618a0..0000000 --- a/src/tests/e2e/dacp-calculator-e2e.test.js +++ /dev/null @@ -1,77 +0,0 @@ -const DACPCommand = require('../../lib/core/pouch/commands/DACPCommand'); - -describe('DACP Calculator E2E Tests', () => { - let dacpCommand; - - beforeEach(() => { - dacpCommand = new DACPCommand(); - }); - - test('should successfully calculate simple math expression', async () => { - const result = await dacpCommand.execute({ - service_id: 'dacp-promptx-service', - action: 'calculate', - parameters: { - user_request: '2加3等于多少' - } - }); - - // 验证DACP协议响应格式 - expect(result).toHaveProperty('request_id'); - expect(result).toHaveProperty('success', true); - expect(result).toHaveProperty('data'); - - // 验证计算结果 - expect(result.data.execution_result).toMatchObject({ - expression: '2+3', - result: 5, - formatted_result: '2+3 = 5', - calculation_type: 'addition' - }); - }); - - test('should handle complex calculations', async () => { - const result = await dacpCommand.execute({ - service_id: 'dacp-promptx-service', - action: 'calculate', - parameters: { - user_request: '(10 + 5) * 2 - 8 / 4' - } - }); - - expect(result.success).toBe(true); - expect(result.data.execution_result).toMatchObject({ - expression: '(10 + 5) * 2 - 8 / 4', - result: 28, - formatted_result: '(10 + 5) * 2 - 8 / 4 = 28' - }); - }); - - test('should handle Chinese operators', async () => { - const result = await dacpCommand.execute({ - service_id: 'dacp-promptx-service', - action: 'calculate', - parameters: { - user_request: '100减去25再乘以2' - } - }); - - expect(result.success).toBe(true); - // 修正:计算器把它解析为 100-25*2 = 100-50 = 50 - expect(result.data.execution_result.result).toBe(50); - }); - - test('should handle calculation errors gracefully', async () => { - const result = await dacpCommand.execute({ - service_id: 'dacp-promptx-service', - action: 'calculate', - parameters: { - user_request: '无效的表达式' - } - }); - - expect(result.success).toBe(false); - expect(result).toHaveProperty('error'); - expect(result.error.code).toBe('EXECUTION_ERROR'); - }); -}); \ No newline at end of file diff --git a/src/tests/e2e/dacp-email-e2e.test.js b/src/tests/e2e/dacp-email-e2e.test.js deleted file mode 100644 index d49aca7..0000000 --- a/src/tests/e2e/dacp-email-e2e.test.js +++ /dev/null @@ -1,122 +0,0 @@ -const PouchCLI = require('../../lib/core/pouch/PouchCLI'); - -describe('DACP Email Service E2E Tests', () => { - let pouchCLI; - - beforeEach(async () => { - pouchCLI = new PouchCLI(); - await pouchCLI.initialize(); - }); - - test('应该能够调用真实的DACP邮件服务', async () => { - const args = { - service_id: 'dacp-email-service', - action: 'send_email', - parameters: { - user_request: '给产品团队发送PromptX项目进展更新', - context: { - project: 'PromptX', - urgency: 'medium', - recipient_type: 'internal' - } - } - }; - - try { - const result = await pouchCLI.execute('dacp', args); - - // 验证DACP响应格式 - expect(result).toHaveProperty('request_id'); - expect(result).toHaveProperty('success'); - - if (result.success) { - expect(result).toHaveProperty('data'); - expect(result.data).toHaveProperty('execution_result'); - expect(result.data).toHaveProperty('evaluation'); - expect(result.data).toHaveProperty('applied_guidelines'); - expect(result.data).toHaveProperty('performance_metrics'); - - // 验证execution_result格式 - const { execution_result } = result.data; - expect(execution_result).toHaveProperty('message_id'); - expect(execution_result).toHaveProperty('status'); - expect(execution_result).toHaveProperty('recipients'); - expect(execution_result).toHaveProperty('subject'); - expect(execution_result).toHaveProperty('body'); - - console.log('✅ DACP邮件服务调用成功:'); - console.log(` 📧 消息ID: ${execution_result.message_id}`); - console.log(` 📬 状态: ${execution_result.status}`); - console.log(` 📝 主题: ${execution_result.subject}`); - console.log(` ⚡ 响应时间: ${result.data.performance_metrics.response_time}`); - } else { - console.log('❌ DACP邮件服务返回错误:', result.error); - // 对于E2E测试,我们可能期望服务可用,所以这里可以fail - // 但也可以选择跳过测试如果服务不可用 - } - - } catch (error) { - // 如果是连接错误,说明DACP邮件服务没有运行,跳过测试 - if (error.message.includes('fetch failed') || - error.message.includes('Connection refused') || - error.message.includes('ECONNREFUSED')) { - console.log('⚠️ DACP邮件服务未运行,跳过E2E测试'); - console.log(' 启动服务命令: cd src/dacp/dacp-email-service && npm start'); - return; // 跳过测试而不是失败 - } - - // 其他错误应该被报告 - throw error; - } - }, 10000); // 10秒超时 - - test('应该正确处理用户自然语言需求', async () => { - const testCases = [ - { - description: '会议提醒邮件', - request: '给张三发个明天产品评审会议的提醒邮件', - context: { urgency: 'high', recipient_type: 'internal' } - }, - { - description: '客户沟通邮件', - request: '向客户汇报项目进展,包含最新的功能更新', - context: { recipient_type: 'client', project: 'PromptX' } - }, - { - description: '团队通知邮件', - request: '通知团队今晚系统维护,请提前保存工作', - context: { urgency: 'high', recipient_type: 'internal' } - } - ]; - - for (const testCase of testCases) { - try { - const args = { - service_id: 'dacp-email-service', - action: 'send_email', - parameters: { - user_request: testCase.request, - context: testCase.context - } - }; - - const result = await pouchCLI.execute('dacp', args); - - if (result.success) { - console.log(`✅ ${testCase.description} - 成功处理`); - console.log(` 🎯 主题: ${result.data.execution_result.subject}`); - console.log(` 📋 应用指导: ${result.data.applied_guidelines.join(', ')}`); - } - - } catch (error) { - if (error.message.includes('fetch failed') || - error.message.includes('Connection refused') || - error.message.includes('ECONNREFUSED')) { - console.log(`⚠️ 跳过测试用例: ${testCase.description} (服务未运行)`); - continue; - } - throw error; - } - } - }, 15000); // 15秒超时 -}); \ No newline at end of file diff --git a/src/tests/integration/dacp-integration.test.js b/src/tests/integration/dacp-integration.test.js deleted file mode 100644 index 9c9c9bf..0000000 --- a/src/tests/integration/dacp-integration.test.js +++ /dev/null @@ -1,141 +0,0 @@ -const PouchCLI = require('../../lib/core/pouch/PouchCLI'); - -// Mock fetch for DACP service calls -global.fetch = jest.fn(); - -describe('DACP Integration Tests', () => { - let pouchCLI; - - beforeEach(async () => { - pouchCLI = new PouchCLI(); - await pouchCLI.initialize(); - fetch.mockClear(); - }); - - test('应该能够通过PouchCLI调用DACP命令', async () => { - const mockDACPResponse = { - request_id: 'req_123', - success: true, - data: { - execution_result: { - message_id: 'msg_456', - status: 'sent', - recipients: ['demo@example.com'], - subject: '会议通知', - body: '您好,\n\n给张三发个会议提醒邮件\n\n此邮件由DACP邮件服务自动生成。' - }, - evaluation: { - criteria_met: true, - quality_score: 95 - }, - applied_guidelines: [ - 'HTML格式提升阅读体验', - '专业邮件签名' - ], - performance_metrics: { - response_time: '150ms', - delivery_rate: 100 - } - } - }; - - fetch.mockResolvedValueOnce({ - ok: true, - json: async () => mockDACPResponse - }); - - const args = { - service_id: 'dacp-email-service', - action: 'send_email', - parameters: { - user_request: '给张三发个会议提醒邮件', - context: { urgency: 'high' } - } - }; - - const result = await pouchCLI.execute('dacp', args); - - // 验证DACP服务被正确调用 - expect(fetch).toHaveBeenCalledWith('http://localhost:3001/dacp', expect.objectContaining({ - method: 'POST', - headers: { 'Content-Type': 'application/json' } - })); - - // 验证请求体格式 - const requestBody = JSON.parse(fetch.mock.calls[0][1].body); - expect(requestBody).toEqual({ - service_id: 'dacp-email-service', - action: 'send_email', - parameters: { - user_request: '给张三发个会议提醒邮件', - context: { urgency: 'high' } - }, - request_id: expect.stringMatching(/^req_\d+$/) - }); - - // 验证返回结果 - expect(result).toEqual(mockDACPResponse); - }); - - test('应该正确处理DACP服务不可用的情况', async () => { - fetch.mockRejectedValueOnce(new Error('Connection refused')); - - const args = { - service_id: 'dacp-email-service', - action: 'send_email', - parameters: { - user_request: '测试邮件' - } - }; - - await expect(pouchCLI.execute('dacp', args)) - .rejects.toThrow('DACP服务调用失败: Connection refused'); - }); - - test('应该正确处理未知DACP服务的情况', async () => { - const args = { - service_id: 'unknown-service', - action: 'some_action', - parameters: { - user_request: '测试请求' - } - }; - - await expect(pouchCLI.execute('dacp', args)) - .rejects.toThrow('未找到DACP服务: unknown-service'); - }); - - test('应该正确处理参数验证错误', async () => { - const args = { - service_id: 'dacp-email-service', - // 缺少action参数 - parameters: { - user_request: '测试邮件' - } - }; - - await expect(pouchCLI.execute('dacp', args)) - .rejects.toThrow('缺少必需参数: action'); - }); - - test('应该支持多个DACP服务路由', async () => { - const mockResponse = { success: true }; - fetch.mockResolvedValueOnce({ - ok: true, - json: async () => mockResponse - }); - - // 测试日程服务路由 - const args = { - service_id: 'dacp-calendar-service', - action: 'create_meeting', - parameters: { - user_request: '创建明天的会议' - } - }; - - await pouchCLI.execute('dacp', args); - - expect(fetch).toHaveBeenCalledWith('http://localhost:3002/dacp', expect.any(Object)); - }); -}); \ No newline at end of file diff --git a/src/tests/unit/DACPConfigManager.unit.test.js b/src/tests/unit/DACPConfigManager.unit.test.js deleted file mode 100644 index fb535b6..0000000 --- a/src/tests/unit/DACPConfigManager.unit.test.js +++ /dev/null @@ -1,226 +0,0 @@ -const fs = require('fs-extra') -const path = require('path') -const os = require('os') -const DACPConfigManager = require('../../lib/utils/DACPConfigManager') - -// Mock DirectoryService -jest.mock('../../lib/utils/DirectoryService', () => ({ - getDirectoryService: () => ({ - getPromptXDirectory: jest.fn() - }) -})) - -const { getDirectoryService } = require('../../lib/utils/DirectoryService') - -describe('DACPConfigManager - 项目级配置优先', () => { - let configManager - let mockDirectoryService - let tempDir - let userConfigDir - let projectConfigDir - - beforeEach(async () => { - // 创建临时测试目录 - tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'dacp-config-test-')) - userConfigDir = path.join(tempDir, 'user', '.promptx', 'dacp') - projectConfigDir = path.join(tempDir, 'project', '.promptx', 'dacp') - - // 确保目录存在 - await fs.ensureDir(userConfigDir) - await fs.ensureDir(projectConfigDir) - - // Mock DirectoryService - mockDirectoryService = getDirectoryService() - mockDirectoryService.getPromptXDirectory.mockResolvedValue(path.join(tempDir, 'project', '.promptx')) - - // 创建配置管理器 - configManager = new DACPConfigManager() - - // Mock用户目录 - configManager.userDacpConfigDir = userConfigDir - }) - - afterEach(async () => { - // 清理临时目录 - await fs.remove(tempDir) - jest.clearAllMocks() - }) - - describe('配置读取优先级', () => { - test('应该优先读取项目级配置', async () => { - const projectConfig = { - provider: 'gmail', - smtp: { user: 'project@gmail.com', password: 'project-pass' }, - sender: { name: 'Project User', email: 'project@gmail.com' } - } - - const userConfig = { - provider: 'outlook', - smtp: { user: 'user@outlook.com', password: 'user-pass' }, - sender: { name: 'User Name', email: 'user@outlook.com' } - } - - // 写入两个配置文件 - await fs.writeJson(path.join(projectConfigDir, 'send_email.json'), projectConfig) - await fs.writeJson(path.join(userConfigDir, 'send_email.json'), userConfig) - - const result = await configManager.readActionConfig('send_email') - - expect(result).toEqual(projectConfig) - expect(result.smtp.user).toBe('project@gmail.com') - }) - - test('项目级配置不存在时应该回退到用户级配置', async () => { - const userConfig = { - provider: 'outlook', - smtp: { user: 'user@outlook.com', password: 'user-pass' }, - sender: { name: 'User Name', email: 'user@outlook.com' } - } - - // 只写入用户级配置 - await fs.writeJson(path.join(userConfigDir, 'send_email.json'), userConfig) - - const result = await configManager.readActionConfig('send_email') - - expect(result).toEqual(userConfig) - expect(result.smtp.user).toBe('user@outlook.com') - }) - - test('两个配置都不存在时应该返回null', async () => { - const result = await configManager.readActionConfig('send_email') - expect(result).toBeNull() - }) - }) - - describe('配置存在性检查', () => { - test('hasActionConfig应该检查项目级和用户级配置', async () => { - // 无配置时 - expect(await configManager.hasActionConfig('send_email')).toBe(false) - - // 仅用户级配置时 - await fs.writeJson(path.join(userConfigDir, 'send_email.json'), {}) - expect(await configManager.hasActionConfig('send_email')).toBe(true) - - // 同时存在项目级配置时 - await fs.writeJson(path.join(projectConfigDir, 'send_email.json'), {}) - expect(await configManager.hasActionConfig('send_email')).toBe(true) - }) - - test('hasProjectActionConfig应该正确检查项目级配置', async () => { - expect(await configManager.hasProjectActionConfig('send_email')).toBe(false) - - await fs.writeJson(path.join(projectConfigDir, 'send_email.json'), {}) - expect(await configManager.hasProjectActionConfig('send_email')).toBe(true) - }) - - test('hasUserActionConfig应该正确检查用户级配置', async () => { - expect(await configManager.hasUserActionConfig('send_email')).toBe(false) - - await fs.writeJson(path.join(userConfigDir, 'send_email.json'), {}) - expect(await configManager.hasUserActionConfig('send_email')).toBe(true) - }) - }) - - describe('配置写入', () => { - test('writeProjectActionConfig应该写入项目级配置', async () => { - const config = { - provider: 'gmail', - smtp: { user: 'test@gmail.com', password: 'test-pass' }, - sender: { name: 'Test User', email: 'test@gmail.com' } - } - - await configManager.writeProjectActionConfig('send_email', config) - - const projectConfigPath = path.join(projectConfigDir, 'send_email.json') - expect(await fs.pathExists(projectConfigPath)).toBe(true) - - const savedConfig = await fs.readJson(projectConfigPath) - expect(savedConfig).toEqual(config) - }) - - test('writeUserActionConfig应该写入用户级配置', async () => { - const config = { - provider: 'outlook', - smtp: { user: 'test@outlook.com', password: 'test-pass' }, - sender: { name: 'Test User', email: 'test@outlook.com' } - } - - await configManager.writeUserActionConfig('send_email', config) - - const userConfigPath = path.join(userConfigDir, 'send_email.json') - expect(await fs.pathExists(userConfigPath)).toBe(true) - - const savedConfig = await fs.readJson(userConfigPath) - expect(savedConfig).toEqual(config) - }) - }) - - describe('向后兼容性', () => { - test('原有API方法应该保持兼容', async () => { - const config = { - provider: 'gmail', - smtp: { user: 'legacy@gmail.com', password: 'legacy-pass' }, - sender: { name: 'Legacy User', email: 'legacy@gmail.com' } - } - - // writeActionConfig应该写入用户级配置 - await configManager.writeActionConfig('send_email', config) - - const userConfigPath = path.join(userConfigDir, 'send_email.json') - expect(await fs.pathExists(userConfigPath)).toBe(true) - - // getConfigPath应该返回用户级路径 - expect(configManager.getConfigPath('send_email')).toBe(userConfigPath) - }) - }) - - describe('错误处理', () => { - test('DirectoryService失败时应该优雅降级', async () => { - // Mock DirectoryService抛出错误 - mockDirectoryService.getPromptXDirectory.mockRejectedValue(new Error('项目目录不存在')) - - const userConfig = { - provider: 'gmail', - smtp: { user: 'user@gmail.com', password: 'user-pass' }, - sender: { name: 'User', email: 'user@gmail.com' } - } - - await fs.writeJson(path.join(userConfigDir, 'send_email.json'), userConfig) - - // 应该能够回退到用户级配置 - const result = await configManager.readActionConfig('send_email') - expect(result).toEqual(userConfig) - }) - - test('项目目录不可写时writeProjectActionConfig应该抛出错误', async () => { - mockDirectoryService.getPromptXDirectory.mockRejectedValue(new Error('无法获取项目目录')) - - const config = { provider: 'gmail' } - - await expect(configManager.writeProjectActionConfig('send_email', config)) - .rejects.toThrow('无法获取项目目录,写入项目级配置失败') - }) - }) - - describe('配置错误提示信息', () => { - test('应该生成包含项目级和用户级路径的错误信息', async () => { - const errorMessage = await configManager.generateConfigErrorMessage('send_email') - - expect(errorMessage).toContain('DACP邮件服务配置缺失') - expect(errorMessage).toContain('项目级:') - expect(errorMessage).toContain('用户级:') - expect(errorMessage).toContain('配置优先级: 项目级(.promptx/dacp/) > 用户级(~/.promptx/dacp/)') - }) - - test('应该正确标识当前使用的配置级别', async () => { - const validation = { valid: false, errors: ['缺少SMTP配置'] } - - // 创建项目级配置 - await fs.writeJson(path.join(projectConfigDir, 'send_email.json'), {}) - - const errorMessage = await configManager.generateConfigErrorMessage('send_email', validation) - expect(errorMessage).toContain('项目级:') - expect(errorMessage).toContain('缺少以下配置项') - }) - }) -}) \ No newline at end of file diff --git a/test-tool-validation.js b/test-tool-validation.js deleted file mode 100644 index b70918d..0000000 --- a/test-tool-validation.js +++ /dev/null @@ -1,31 +0,0 @@ -const fs = require('fs'); -const path = require('path'); - -// 测试工具文件验证 -function testToolValidation() { - const toolPath = path.join(process.cwd(), 'prompt/tool/calculator.tool.js'); - console.log(`🔍 Testing tool validation for: ${toolPath}`); - - try { - const content = fs.readFileSync(toolPath, 'utf8'); - console.log('📄 File content loaded, length:', content.length); - - // 模拟我们的验证逻辑 - console.log('✅ Contains module.exports:', content.includes('module.exports')); - console.log('✅ Contains getMetadata:', content.includes('getMetadata')); - console.log('✅ Contains execute:', content.includes('execute')); - - // 尝试语法检查 - try { - new Function(content); - console.log('✅ JavaScript syntax is valid'); - } catch (syntaxError) { - console.log('❌ JavaScript syntax error:', syntaxError.message); - } - - } catch (error) { - console.log('❌ Failed to read file:', error.message); - } -} - -testToolValidation(); \ No newline at end of file diff --git a/test-tool.js b/test-tool.js deleted file mode 100644 index 5168892..0000000 --- a/test-tool.js +++ /dev/null @@ -1,19 +0,0 @@ -const { getGlobalResourceManager } = require('./src/lib/core/resource'); - -async function testToolResource() { - try { - const rm = getGlobalResourceManager(); - if (!rm.initialized) { - await rm.initializeWithNewArchitecture(); - } - - console.log('🔍 Testing tool resource loading...'); - const result = await rm.loadResource('@tool://calculator'); - console.log('✅ Tool resource loaded successfully:', result); - } catch (error) { - console.log('❌ Tool resource loading failed:', error.message); - console.log('Error details:', error); - } -} - -testToolResource(); \ No newline at end of file