From 5ab353d41d936003c74c348681166f6b87874a61 Mon Sep 17 00:00:00 2001 From: sean Date: Wed, 21 May 2025 16:46:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0`bootstrap.md`=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E4=B8=AD=E7=9A=84=E8=A7=92=E8=89=B2=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E4=B8=BA=E6=B5=8B=E8=AF=95=E8=A7=92=E8=89=B2=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E5=9C=A8`promptx.js`=E4=B8=AD=E6=96=B0=E5=A2=9E=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E8=AE=B0=E5=BF=86=E5=91=BD=E4=BB=A4=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E7=9A=84=E5=8A=9F=E8=83=BD=EF=BC=8C=E4=BC=98=E5=8C=96=E8=AE=B0?= =?UTF-8?q?=E5=BF=86=E6=9D=A1=E7=9B=AE=E6=B7=BB=E5=8A=A0=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E6=94=AF=E6=8C=81=E5=9C=A8=E5=86=85=E5=AE=B9=E4=B8=AD?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E5=8C=85=E5=90=AB=E6=A0=87=E7=AD=BE=E3=80=81?= =?UTF-8?q?=E8=AF=84=E5=88=86=E5=92=8C=E6=9C=89=E6=95=88=E6=9C=9F=EF=BC=8C?= =?UTF-8?q?=E6=8F=90=E5=8D=87=E7=94=A8=E6=88=B7=E4=BD=93=E9=AA=8C=E5=92=8C?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E4=B8=80=E8=87=B4=E6=80=A7=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bootstrap.md | 2 +- promptx.js | 183 +++++++++++++++++++++++++++------------------------ 2 files changed, 98 insertions(+), 87 deletions(-) mode change 100644 => 100755 promptx.js diff --git a/bootstrap.md b/bootstrap.md index d6e02c7..d62fe0a 100644 --- a/bootstrap.md +++ b/bootstrap.md @@ -2,5 +2,5 @@ 1. 使用命令 `node PromptX/promptx.js` 获取所有协议内容 2. 阅读并理解 PromptX 提示词系统 -3. 你需要代入的角色是 @file://PromptX/domain/scrum/role/product-owner.role.md +3. 你需要代入的角色是 @file://PromptX/domain/test/test.role.md 4. Action!! \ No newline at end of file diff --git a/promptx.js b/promptx.js old mode 100644 new mode 100755 index 7fb8033..7833834 --- a/promptx.js +++ b/promptx.js @@ -138,6 +138,87 @@ function printFile(filePath) { } } +/** + * 解析记忆命令参数 + * @param {string} content - 记忆内容,可能包含标签、评分和有效期 + * @param {string[]} args - 其他参数 + */ +function parseMemoryArgs(content, args) { + const options = { + tags: [], + score: 5, + duration: '短期' + }; + + // 从内容中提取标签、评分和有效期 + const contentParts = content.trim().split(/\s+/); + let cleanContent = []; + + for (let part of contentParts) { + if (part.startsWith('#')) { + // 检查是否是特殊标记 + if (part.includes('评分:')) { + const scoreText = part.split('评分:')[1].trim(); + const score = parseInt(scoreText); + if (!isNaN(score) && score >= 1 && score <= 10) { + options.score = score; + } + } else if (part.includes('有效期:')) { + const duration = part.split('有效期:')[1].trim(); + if (['短期', '中期', '长期'].includes(duration)) { + options.duration = duration; + } + } else { + // 普通标签 + const tag = part.slice(1); + if (tag) { + options.tags.push(tag); + } + } + } else { + cleanContent.push(part); + } + } + + // 处理剩余的命令行参数 + for (let arg of args) { + // 移除参数前后的引号(如果有) + arg = arg.replace(/^['"]|['"]$/g, '').trim(); + + if (arg.startsWith('#')) { + // 检查是否是特殊标记 + if (arg.includes('评分:')) { + const score = parseInt(arg.split('评分:')[1]); + if (!isNaN(score) && score >= 1 && score <= 10) { + options.score = score; + } + } else if (arg.includes('有效期:')) { + const duration = arg.split('有效期:')[1]; + if (['短期', '中期', '长期'].includes(duration)) { + options.duration = duration; + } + } else { + // 普通标签 + const tag = arg.slice(1); + if (tag) { + options.tags.push(tag); + } + } + } + } + + // 如果没有标签,使用默认标签 + if (options.tags.length === 0) { + options.tags = ['其他']; + } + + // 返回清理后的内容和选项 + return { + cleanContent: cleanContent.join(' '), + options: options + }; +} + /** * 添加记忆条目 * @param {string} content - 记忆内容 @@ -164,10 +245,8 @@ function addMemory(content, options = {}) { tags: options.tags && options.tags.length > 0 ? options.tags : defaultOptions.tags }; - console.log('最终选项:', finalOptions); // 添加调试输出 - // 构建记忆条目,确保格式统一 - const memoryEntry = `\n- ${content.trim()} ${finalOptions.tags.map(tag => `#${tag}`).join(' ')} #评分:${finalOptions.score} #有效期:${finalOptions.duration} #时间:${finalOptions.timestamp}\n`; + const memoryEntry = `\n- ${finalOptions.timestamp} ${content.trim()} ${finalOptions.tags.map(tag => `#${tag}`).join(' ')} #评分:${finalOptions.score} #有效期:${finalOptions.duration}\n`; // 确保.memory目录存在 const memoryDir = path.join(process.cwd(), '.memory'); @@ -195,61 +274,6 @@ function addMemory(content, options = {}) { } } -/** - * 解析记忆命令参数 - * @param {string} content - 记忆内容 - * @param {string[]} args - 其他参数 - */ -function parseMemoryArgs(content, args) { - const options = { - tags: [], - score: 5, - duration: '短期' - }; - - console.log('原始参数:', args); // 调试输出 - - // 解析标签和其他选项 - for (let arg of args) { - // 移除参数前后的引号(如果有) - arg = arg.replace(/^['"]|['"]$/g, '').trim(); - - console.log('处理参数:', arg); // 调试输出 - - if (arg.startsWith('#')) { - // 检查是否是特殊标记 - if (arg.includes('评分:')) { - const score = parseInt(arg.split('评分:')[1]); - console.log('解析评分:', score); // 调试输出 - if (!isNaN(score) && score >= 1 && score <= 10) { - options.score = score; - } - } else if (arg.includes('有效期:')) { - const duration = arg.split('有效期:')[1]; - console.log('解析有效期:', duration); // 调试输出 - if (['短期', '中期', '长期'].includes(duration)) { - options.duration = duration; - } - } else { - // 普通标签 - const tag = arg.slice(1); - console.log('解析标签:', tag); // 调试输出 - if (tag) { - options.tags.push(tag); - } - } - } - } - - // 如果没有标签,使用默认标签 - if (options.tags.length === 0) { - options.tags = ['其他']; - } - - console.log('解析结果:', options); // 调试输出 - return options; -} - /** * 打印帮助信息 */ @@ -262,17 +286,18 @@ PromptX 工具 - 协议和角色内容查看器 node promptx.js protocols - 同上,打印所有协议内容 node promptx.js role <路径> - 打印指定角色文件内容 node promptx.js file <路径> - 打印指定文件内容 - node promptx.js remember <内容> [选项] - 添加记忆条目 + node promptx.js remember <内容> - 添加记忆条目,标签、评分和有效期可直接包含在内容中 node promptx.js help - 显示此帮助信息 -记忆命令选项: +记忆命令用法: + 将标签、评分和有效期直接包含在内容字符串中,时间戳会自动添加到行首 #标签名 - 添加标签 (可多个) - score:数字 - 设置重要性评分 (1-10) - duration:时长 - 设置有效期 (短期/长期) + #评分:数字 - 设置重要性评分 (1-10) + #有效期:时长 - 设置有效期 (短期/中期/长期) 示例: - node promptx.js remember "用户提出了重要建议" #用户反馈 #改进建议 score:7 duration:长期 - node promptx.js remember "临时配置信息" #配置 score:3 + node promptx.js remember "用户提出了重要建议 #用户反馈 #改进建议 #评分:8 #有效期:长期" + node promptx.js remember "临时配置信息 #配置 #评分:3 #有效期:短期" `); } @@ -300,34 +325,20 @@ switch (command) { case 'remember': if (!param) { console.error('错误: 缺少记忆内容'); - console.log('使用方法: node promptx.js remember 记忆内容 [#标签1 #标签2] [#评分:7] [#有效期:长期]'); + console.log('使用方法: node promptx.js remember "记忆内容 #标签1 #标签2 #评分:8 #有效期:长期"'); } else { try { - // 获取所有参数 - const allArgs = process.argv.slice(2); // 从 remember 开始的所有参数 - console.log('所有参数:', allArgs); + // 记忆内容就是传入的第一个参数 + const memoryContent = param; - // 找到第一个标签(以#开头的参数)的位置 - const tagStartIndex = allArgs.findIndex(arg => arg.startsWith('#')); - console.log('标签起始位置:', tagStartIndex); + // 解析内容中的标签、评分和有效期 + const { cleanContent, options } = parseMemoryArgs(memoryContent, []); - // 如果没有找到标签,使用所有剩余参数作为内容 - const contentEndIndex = tagStartIndex === -1 ? allArgs.length : tagStartIndex; - - // 组合记忆内容(去掉 remember 命令) - const memoryContent = allArgs.slice(1, contentEndIndex).join(' '); - console.log('记忆内容:', memoryContent); - - // 获取所有标签和选项 - const memoryArgs = allArgs.slice(contentEndIndex); - console.log('记忆参数:', memoryArgs); - - const options = parseMemoryArgs(memoryContent, memoryArgs); - console.log('解析的选项:', options); - addMemory(memoryContent, options); + // 添加记忆 + addMemory(cleanContent, options); } catch (err) { console.error('错误:', err.message); - console.log('使用方法: node promptx.js remember 记忆内容 [#标签1 #标签2] [#评分:7] [#有效期:长期]'); + console.log('使用方法: node promptx.js remember "记忆内容 #标签1 #标签2 #评分:8 #有效期:长期"'); } } break;