- 重构 SKILL.md,要求子 Agent 直接读取模板文件而非由主 Agent 摘要传送 - 新增 get-template-path.js 脚本,支持按账号和类型获取模板文件绝对路径 - 移除 capcut_assemble.js 中的关键字氛围词功能及相关依赖
104 lines
2.9 KiB
JavaScript
104 lines
2.9 KiB
JavaScript
#!/usr/bin/env node
|
||
|
||
/**
|
||
* 获取账号专属模板文件的完整路径
|
||
*
|
||
* 用法:
|
||
* node get-template-path.js --account 军事账号 --type storyboard
|
||
* node get-template-path.js --account 军事账号 --type image
|
||
* node get-template-path.js --account 军事账号 --type video
|
||
*
|
||
* 输出:
|
||
* 完整的绝对路径,可直接传给 Read 工具或 fs.readFileSync
|
||
*/
|
||
|
||
const fs = require('fs')
|
||
const path = require('path')
|
||
|
||
// 路径常量
|
||
const SCRIPTS_DIR = path.join(__dirname, '..')
|
||
const SKILLS_DIR = path.join(SCRIPTS_DIR, '..')
|
||
const PROJECT_ROOT = path.join(SKILLS_DIR, '..', '..')
|
||
const ACCOUNTS_DIR = path.join(PROJECT_ROOT, 'accounts')
|
||
|
||
function getTemplatePath(accountId, templateType) {
|
||
// 1. 读取账号配置
|
||
const accountPath = path.join(ACCOUNTS_DIR, accountId, 'account.json')
|
||
if (!fs.existsSync(accountPath)) {
|
||
throw new Error(`账号不存在: ${accountPath}`)
|
||
}
|
||
|
||
const account = JSON.parse(fs.readFileSync(accountPath, 'utf-8'))
|
||
|
||
// 2. 映射模板类型到字段名
|
||
const fieldMap = {
|
||
storyboard: 'storyboardPrompt',
|
||
image: 'imageStylePrompt',
|
||
video: 'videoStylePrompt'
|
||
}
|
||
|
||
const fieldName = fieldMap[templateType]
|
||
if (!fieldName) {
|
||
throw new Error(`未知模板类型: ${templateType},支持: storyboard, image, video`)
|
||
}
|
||
|
||
// 3. 获取相对路径
|
||
const relativePath = account[fieldName]
|
||
if (!relativePath) {
|
||
throw new Error(`账号配置缺少字段: ${fieldName}`)
|
||
}
|
||
|
||
// 4. 判断是否为绝对路径
|
||
let absolutePath
|
||
if (path.isAbsolute(relativePath)) {
|
||
// 已经是绝对路径,直接使用
|
||
absolutePath = relativePath
|
||
} else {
|
||
// 相对路径,拼接账号目录(相对于账号目录)
|
||
absolutePath = path.join(ACCOUNTS_DIR, accountId, relativePath)
|
||
}
|
||
|
||
// 5. 检查文件是否存在
|
||
if (!fs.existsSync(absolutePath)) {
|
||
throw new Error(`模板文件不存在: ${absolutePath}`)
|
||
}
|
||
|
||
// 6. 转换为相对于项目根目录的相对路径(子 Agent 友好)
|
||
const relativeToProject = path.relative(PROJECT_ROOT, absolutePath)
|
||
|
||
return relativeToProject
|
||
}
|
||
|
||
// ============================================================================
|
||
// CLI 入口
|
||
// ============================================================================
|
||
|
||
function main() {
|
||
const args = process.argv.slice(2)
|
||
|
||
const accountIndex = args.indexOf('--account')
|
||
const typeIndex = args.indexOf('--type')
|
||
|
||
if (accountIndex === -1 || typeIndex === -1) {
|
||
console.error('用法:node get-template-path.js --account <账号ID> --type <storyboard|image|video>')
|
||
process.exit(1)
|
||
}
|
||
|
||
const accountId = args[accountIndex + 1]
|
||
const templateType = args[typeIndex + 1]
|
||
|
||
try {
|
||
const fullPath = getTemplatePath(accountId, templateType)
|
||
console.log(fullPath)
|
||
} catch (err) {
|
||
console.error(`错误: ${err.message}`)
|
||
process.exit(1)
|
||
}
|
||
}
|
||
|
||
if (require.main === module) {
|
||
main()
|
||
}
|
||
|
||
module.exports = { getTemplatePath }
|