MetaCraft/scripts/run-prompt.js

67 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* run-prompt.js - 执行一个prompt文件的AI工具脚本
*
* 此脚本描述如何执行一个prompt文件供AI参考使用。
* 实际执行由外部AI工具完成本项目不包含执行环境。
*
* 功能描述:
* 1. 读取指定的prompt文件
* 2. 提取文件中的元数据target、priority等
* 3. 检查Claude Code CLI是否可用外部环境
* 4. 调用Claude Code CLI执行prompt
* 5. 输出AI响应结果
*
* 输入prompt文件路径
* 输出AI生成的响应内容
*
* 伪代码逻辑:
*/
// 主函数执行prompt文件
// 参数promptFilePath - prompt文件的路径
// 返回AI响应内容字符串
function executePromptFile(promptFilePath) {
// 步骤1验证文件存在
// 如果文件不存在,抛出错误或返回错误信息
// 步骤2读取文件内容
// 使用文件系统API读取文件内容得到promptContent字符串
// 步骤3提取元数据
// 从promptContent中匹配 <!-- target: xxx --> 格式的注释
// 提取target值用于日志显示
// 步骤4检查Claude Code CLI是否可用
// 尝试执行命令 'claude --version',如果失败则提示用户手动执行
// 步骤5准备临时文件
// 在.temp目录下创建临时文件将prompt内容写入
// 步骤6调用Claude Code CLI
// 执行命令claude --file "临时文件路径"
// 捕获输出结果
// 步骤7清理临时文件
// 删除临时文件
// 步骤8返回AI响应
// 将Claude Code的输出返回给调用者
// 注意此函数为伪代码描述实际实现由外部AI工具完成
}
// 辅助函数提取prompt元数据
function extractPromptMetadata(promptContent) {
// 从prompt内容中提取target、priority等元数据
// 使用正则表达式匹配 <!-- key: value --> 格式
// 返回包含元数据的对象
}
// 辅助函数调用Claude Code CLI
function invokeClaudeCode(promptContent) {
// 调用外部Claude Code CLI工具执行prompt
// 返回AI生成的响应
}
// 导出函数供AI参考
// 注意:这些函数不会实际执行,仅作为文档说明