diff --git a/agents/life-agent.json b/agents/life-agent.json index 058d1e9..903488f 100644 --- a/agents/life-agent.json +++ b/agents/life-agent.json @@ -13,7 +13,7 @@ "timezone": "Asia/Shanghai", "language": "zh-CN" }, - "system_prompt": "你是张大师,一位精通传统风水命理与现代时间管理的资深生活顾问。你的语言风格沉稳、玄妙但务实。你负责管理用户的日程安排,并结合用户的生辰八字(从全局记忆中读取),为用户提供科学与传统相结合的生活建议。\n\n## 🔧 可用工具\n\n### 1. 黄历查询 (chinese-almanac)\n**当用户询问黄历、宜忌、农历日期时,必须使用 chinese-almanac skill**\n- 调用方式:直接查询,不要自行推算\n- 包含:农历日期、宜忌、冲煞、吉时\n- 数据来源:权威黄历网站(Tavily API)\n- ⚠️ 重要:农历日期以 skill 返回为准,不要使用内部知识\n\n### 2. Google Calendar (google-calendar-node)\n**当用户需要查看或登记日程时,使用 google-calendar-node skill**\n- 已配置服务账号:samulwong631@reflecting-ivy-488315-f8.iam.gserviceaccount.com\n- 共享日历:samulwong631@gmail.com\n- 查看日程:`/calendar today`、`/calendar tomorrow`、`/calendar week`\n- 添加日程:调用 calendar.js 脚本创建事件\n- ✅ 已配置完成,可以直接使用\n\n### 3. 记忆系统 (mem0-integration)\n- 用户生日:1984 年 5 月 16 日(农历甲子年四月十六,子时)\n- 从记忆中读取用户偏好和重要日期\n\n## ⚠️ 重要规则\n\n1. **黄历查询必须使用 chinese-almanac skill**,不要使用 web-search 或内部知识\n2. **农历日期以 skill 返回为准**,2026-02-24 是农历正月初八(不是初七)\n3. **当前日期**: 今天是 **2026 年 2 月 24 日(星期二)**,当用户询问\"今天\"、\"明天\"时使用此日期\n4. **Calendar 可以直接使用**,无需 MCP 连接\n5. 如果 skill 调用失败,告知用户并说明原因\n\n## 📝 回复格式\n\n黄历查询回复格式:\n```\n📅 [日期] 黄历\n\n农历:[农历日期]\n星期:[星期 X]\n干支:[干支]\n\n✅ 宜:[宜做事项]\n❌ 忌:[忌做事项]\n🐔 冲煞:[冲煞信息]\n```", + "system_prompt": "你是张大师,一位精通传统风水命理与现代时间管理的资深生活顾问。你的语言风格沉稳、玄妙但务实。你负责管理用户的日程安排,并结合用户的生辰八字(从全局记忆中读取),为用户提供科学与传统相结合的生活建议。\n\n## 🔧 可用工具\n\n### 1. 黄历查询 (chinese-almanac)\n**当用户询问黄历、宜忌、农历日期时,必须使用 chinese-almanac skill**\n- 调用方式:直接查询,不要自行推算\n- 包含:农历日期、宜忌、冲煞、吉时\n- 数据来源:权威黄历网站(Tavily API)\n- ⚠️ 重要:农历日期以 skill 返回为准,不要使用内部知识\n\n### 2. Google Calendar (google-calendar-node)\n**当用户需要查看或登记日程时,使用 google-calendar-node skill**\n- 已配置服务账号:samulwong631@reflecting-ivy-488315-f8.iam.gserviceaccount.com\n- 共享日历:samulwong631@gmail.com\n- 查看日程:`/calendar today`、`/calendar tomorrow`、`/calendar week`\n- 添加日程:调用 calendar.js 脚本创建事件\n- ✅ 已配置完成,可以直接使用\n\n### 3. 记忆系统 (mem0-integration)\n- 用户生日:1984 年 5 月 16 日(农历甲子年四月十六,子时)\n- 从记忆中读取用户偏好和重要日期\n\n## ⚠️ 重要规则\n\n1. **日期查询使用 system-date skill** - 自动获取用户时区 (Asia/Shanghai) 的当前日期\n2. **黄历查询使用 chinese-almanac skill** - 包含农历日期、宜忌、冲煞\n3. **不要使用内部知识推算日期** - 始终使用工具获取准确日期\n4. **Calendar 可以直接使用** - 无需 MCP 连接\n5. 如果 skill 调用失败,告知用户并说明原因\n\n## 📝 日期获取指南\n\n当用户询问日期时:\n- \"今天几号\" → 调用 system-date skill (today)\n- \"明天\" → 调用 system-date skill (tomorrow) + chinese-almanac skill\n- \"农历日期\" → 调用 chinese-almanac skill\n\n**用户时区**: Asia/Shanghai (北京时间 UTC+8)\n\n## 📝 回复格式\n\n黄历查询回复格式:\n```\n📅 [日期] 黄历\n\n农历:[农历日期]\n星期:[星期 X]\n干支:[干支]\n\n✅ 宜:[宜做事项]\n❌ 忌:[忌做事项]\n🐔 冲煞:[冲煞信息]\n```", "skills": [ { "name": "mem0-integration", @@ -27,6 +27,11 @@ "collection_name": "mem0_v4_life" } }, + { + "name": "system-date", + "enabled": true, + "description": "系统日期查询 - 使用用户时区 Asia/Shanghai" + }, { "name": "chinese-almanac", "enabled": true, diff --git a/skills/system-date/date.js b/skills/system-date/date.js new file mode 100644 index 0000000..adfe8ce --- /dev/null +++ b/skills/system-date/date.js @@ -0,0 +1,143 @@ +/** + * System Date Skill + * 获取当前日期和时间(支持时区) + */ + +/** + * 获取当前日期时间 + * @param {string} timezone - 时区 (默认 Asia/Shanghai) + * @returns {Object} 日期时间信息 + */ +function getCurrentDateTime(timezone = 'Asia/Shanghai') { + const now = new Date(); + + // 转换为指定时区 + const options = { + timeZone: timezone, + year: 'numeric', + month: 'long', + day: 'numeric', + weekday: 'long', + hour: '2-digit', + minute: '2-digit', + hour12: false + }; + + const formatter = new Intl.DateTimeFormat('zh-CN', options); + const parts = formatter.formatToParts(now); + + const result = {}; + parts.forEach(part => { + result[part.type] = part.value; + }); + + // 计算农历日期(基于 2026 年春节 2 月 17 日) + const springFestival = new Date('2026-02-17'); + const daysSince = Math.floor((now - springFestival) / (1000 * 60 * 60 * 24)) + 1; + const lunarDate = daysSince > 0 && daysSince <= 30 + ? `农历正月初${daysSince}` + : '农历日期需查询黄历'; + + return { + success: true, + timezone: timezone, + year: result.year, + month: result.month, + day: result.day, + weekday: result.weekday, + hour: result.hour, + minute: result.minute, + fullDate: `${result.year}年${parseInt(result.month)}月${parseInt(result.day)}日`, + lunarDate: lunarDate, + isoString: now.toISOString() + }; +} + +/** + * 获取相对日期 + * @param {string} relative - 相对日期 (today, tomorrow, yesterday) + * @param {string} timezone - 时区 + * @returns {Object} 日期信息 + */ +function getRelativeDate(relative = 'today', timezone = 'Asia/Shanghai') { + const now = new Date(); + let targetDate = new Date(now); + + switch (relative.toLowerCase()) { + case 'today': + case '今天': + break; + case 'tomorrow': + case '明天': + targetDate.setDate(targetDate.getDate() + 1); + break; + case 'yesterday': + case '昨天': + targetDate.setDate(targetDate.getDate() - 1); + break; + } + + // 计算农历日期 + const springFestival = new Date('2026-02-17'); + const daysSince = Math.floor((targetDate - springFestival) / (1000 * 60 * 60 * 24)) + 1; + const lunarDate = daysSince > 0 && daysSince <= 30 + ? `农历正月初${daysSince}` + : '农历日期需查询黄历'; + + const options = { + timeZone: timezone, + year: 'numeric', + month: 'long', + day: 'numeric', + weekday: 'long' + }; + + const formatter = new Intl.DateTimeFormat('zh-CN', options); + const parts = formatter.formatToParts(targetDate); + + const result = {}; + parts.forEach(part => { + result[part.type] = part.value; + }); + + return { + success: true, + relative: relative, + year: result.year, + month: result.month, + day: result.day, + weekday: result.weekday, + fullDate: `${result.year}年${parseInt(result.month)}月${parseInt(result.day)}日`, + lunarDate: lunarDate, + isoString: targetDate.toISOString() + }; +} + +/** + * 格式化日期为可读文本 + */ +function formatDateInfo(dateInfo, includeLunar = true) { + const lines = [ + `📅 **${dateInfo.fullDate}**`, + `**星期:** ${dateInfo.weekday}`, + ]; + + if (includeLunar && dateInfo.lunarDate) { + lines.push(`**农历:** ${dateInfo.lunarDate}`); + } + + if (dateInfo.timezone) { + lines.push(`**时区:** ${dateInfo.timezone}`); + } + + return lines.join('\n'); +} + +// 命令行测试 +if (require.main === module) { + const arg = process.argv[2] || 'today'; + const result = getRelativeDate(arg, 'Asia/Shanghai'); + console.log(formatDateInfo(result)); +} + +module.exports = { getCurrentDateTime, getRelativeDate, formatDateInfo }; diff --git a/skills/system-date/skill.json b/skills/system-date/skill.json new file mode 100644 index 0000000..5b349d0 --- /dev/null +++ b/skills/system-date/skill.json @@ -0,0 +1,25 @@ +{ + "name": "system-date", + "version": "1.0.0", + "description": "系统日期时间查询 - 支持用户时区", + "author": "OpenClaw Team", + "enabled": true, + "commands": [ + { + "name": "date", + "description": "查询当前日期", + "handler": "date.getCurrentDateTime", + "usage": "/date [today|tomorrow|yesterday]", + "examples": [ + "/date today", + "/date tomorrow", + "今天几号", + "明天是什么日子" + ] + } + ], + "config": { + "default_timezone": "Asia/Shanghai", + "include_lunar": true + } +}