scaffold-agent.js
2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env node
/**
* scaffold-agent.js — CLI 脚本,供 agent_creator 通过 Bash 调用
*
* 用法:
* node scripts/scaffold-agent.js --id poetry_writer --name "诗词大师" --type skill --parent agent-creator
*
* 输出:
* 创建完整的 Agent 目录结构到 data/agents/{id}/
*/
import { AgentScaffold } from '../packages/agent-core/AgentScaffold.js';
import { resolve, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const DATA_DIR = resolve(__dirname, '../data/agents');
// 解析命令行参数
function parseArgs(args) {
const result = {};
for (let i = 0; i < args.length; i++) {
if (args[i].startsWith('--')) {
const key = args[i].slice(2);
const val = args[i+1] && !args[i+1].startsWith('--') ? args[++i] : true;
result[key] = val;
}
}
return result;
}
const opts = parseArgs(process.argv.slice(2));
if (!opts.id) {
console.error('❌ 必须指定 --id <agent_id>');
console.error('用法: node scripts/scaffold-agent.js --id <id> --name <name> [--type skill] [--parent <parentId>]');
process.exit(1);
}
const config = {
id: opts.id,
type: opts.type || 'skill',
name: opts.name || opts.id,
parentId: opts.parent || null,
};
try {
const scaffold = new AgentScaffold(DATA_DIR);
const agentDir = await scaffold.create(config);
console.log(`✅ Agent "${config.name}" (${config.id}) 创建成功`);
console.log(`📁 目录: ${agentDir}`);
console.log(`📄 结构:`);
console.log(` ├── agent.md`);
console.log(` ├── soul.md`);
console.log(` ├── identity.md`);
console.log(` ├── user.md`);
console.log(` ├── tools.md`);
console.log(` ├── heartbeat.md`);
console.log(` ├── config.json`);
console.log(` ├── .claude/skills/main_skill/SKILL.md`);
console.log(` ├── memory/`);
console.log(` ├── knowledge/`);
console.log(` ├── workspace/`);
console.log(` └── logs/`);
} catch (err) {
console.error(`❌ 创建失败: ${err.message}`);
process.exit(1);
}