@qcluffy/agent-bootstrap 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +294 -0
- package/BOOTSTRAP.md +268 -0
- package/DEMO.md +103 -0
- package/HEARTBEAT.md +444 -0
- package/IDENTITY.md +239 -0
- package/LICENSE +21 -0
- package/MEMORY.md +324 -0
- package/README.md +582 -0
- package/SOUL.md +254 -0
- package/TOOLS.md +317 -0
- package/USER.md +274 -0
- package/bootstrap-system/HOOK.md +31 -0
- package/bootstrap-system/README.md +109 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +155 -0
- package/dist/index.js.map +1 -0
- package/dist/systems/bootstrap.d.ts.map +1 -0
- package/dist/systems/bootstrap.js +272 -0
- package/dist/systems/bootstrap.js.map +1 -0
- package/dist/systems/cognition.d.ts.map +1 -0
- package/dist/systems/cognition.js +254 -0
- package/dist/systems/cognition.js.map +1 -0
- package/dist/systems/emotion.d.ts.map +1 -0
- package/dist/systems/emotion.js +194 -0
- package/dist/systems/emotion.js.map +1 -0
- package/dist/systems/input.d.ts.map +1 -0
- package/dist/systems/input.js +161 -0
- package/dist/systems/input.js.map +1 -0
- package/dist/systems/output.d.ts.map +1 -0
- package/dist/systems/output.js +224 -0
- package/dist/systems/output.js.map +1 -0
- package/dist/test.js +54 -0
- package/emotion-system/README.md +195 -0
- package/hooks/agent-lifecycle/handler.js +109 -0
- package/hooks/auto-bootstrap/handler.js +145 -0
- package/hooks/bootstrap-system/HOOK.md +74 -0
- package/hooks/bootstrap-system/handler.js +220 -0
- package/hooks/cognition-system/HOOK.md +75 -0
- package/hooks/cognition-system/handler.js +186 -0
- package/hooks/emotion-system/HOOK.md +81 -0
- package/hooks/emotion-system/handler.js +239 -0
- package/hooks/heartbeat-system/HOOK.md +63 -0
- package/hooks/heartbeat-system/handler.js +121 -0
- package/hooks/input-system/HOOK.md +79 -0
- package/hooks/input-system/handler.js +181 -0
- package/hooks/memory-system/HOOK.md +43 -0
- package/hooks/memory-system/handler.js +213 -0
- package/hooks/output-system/HOOK.md +79 -0
- package/hooks/output-system/handler.js +195 -0
- package/memory-system/README.md +291 -0
- package/openclaw.plugin.json +51 -0
- package/package.json +30 -0
- package/requirements.txt +11 -0
package/dist/test.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* 测试 TypeScript 版 Agent 系统
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var index_1 = require("./src/index");
|
|
7
|
+
console.log('=== Agent System Test (TypeScript) ===\n');
|
|
8
|
+
// 创建系统
|
|
9
|
+
var agent = new index_1.AgentSystem();
|
|
10
|
+
// 1. 测试情感系统
|
|
11
|
+
console.log('1. 情感系统:');
|
|
12
|
+
console.log(agent.getEmotionDisplay(true));
|
|
13
|
+
agent.getEmotion().boost();
|
|
14
|
+
agent.getEmotion().addXp(5);
|
|
15
|
+
console.log('互动后:', agent.getEmotionDisplay(true));
|
|
16
|
+
// 2. 测试输入系统
|
|
17
|
+
console.log('\n2. 输入系统:');
|
|
18
|
+
var intent = agent.getInput().analyze('帮我写一个Hello World程序');
|
|
19
|
+
console.log(agent.getInput().getIntentDisplay(intent));
|
|
20
|
+
// 3. 测试引导系统
|
|
21
|
+
console.log('\n3. 引导系统:');
|
|
22
|
+
var start = agent.getBootstrap().start();
|
|
23
|
+
console.log(start.content);
|
|
24
|
+
var step2 = agent.getBootstrap().process('乔巴');
|
|
25
|
+
console.log('\n输入"乔巴":');
|
|
26
|
+
console.log(step2.prompt);
|
|
27
|
+
var step3 = agent.getBootstrap().process('1');
|
|
28
|
+
console.log('\n输入"1":');
|
|
29
|
+
console.log(step3.prompt);
|
|
30
|
+
var step4 = agent.getBootstrap().process('C');
|
|
31
|
+
console.log('\n输入"C":');
|
|
32
|
+
console.log(step4.prompt);
|
|
33
|
+
var done = agent.getBootstrap().process('好');
|
|
34
|
+
console.log('\n输入"好":');
|
|
35
|
+
console.log(done.content);
|
|
36
|
+
// 4. 测试认知系统
|
|
37
|
+
console.log('\n4. 认知系统:');
|
|
38
|
+
var result = agent.getCognition().process({ type: 'task', action: 'write' });
|
|
39
|
+
console.log('允许:', result.allowed);
|
|
40
|
+
console.log('下一步:', result.nextStep);
|
|
41
|
+
console.log('偏好:', result.preferences);
|
|
42
|
+
// 5. 测试输出系统
|
|
43
|
+
console.log('\n5. 输出系统:');
|
|
44
|
+
var response = agent.getOutput().generateResponse('任务完成', 'friendly');
|
|
45
|
+
console.log(response.content);
|
|
46
|
+
// 6. 完整流程测试
|
|
47
|
+
console.log('\n=== 完整流程测试 ===');
|
|
48
|
+
agent.getEmotion().reset();
|
|
49
|
+
agent.getBootstrap().reset();
|
|
50
|
+
var result2 = agent.processUserInput('你好');
|
|
51
|
+
console.log('意图:', result2.intent.type);
|
|
52
|
+
console.log('心情:', result2.emotion.mood);
|
|
53
|
+
console.log('回复:', result2.response);
|
|
54
|
+
console.log('\n✅ 全部测试完成!');
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# Emotion System - 情感系统
|
|
2
|
+
|
|
3
|
+
> *"我不仅有逻辑,也有情感。"*
|
|
4
|
+
|
|
5
|
+
OpenClaw Agent 的情感系统模块,负责模拟和管理 Agent 的情感状态。
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 🎯 一句话说明
|
|
10
|
+
|
|
11
|
+
情感系统让 Agent 有"情绪",会累、会开心、会和用户建立感情连接。
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 📊 情感状态
|
|
16
|
+
|
|
17
|
+
| 维度 | 范围 | 说明 |
|
|
18
|
+
|------|------|------|
|
|
19
|
+
| 😊 **mood** | 9种 | curious, happy, calm, focused, tired, anxious, excited, thoughtful, neutral |
|
|
20
|
+
| ⚡ **energy** | 0-100% | 能量水平,自然衰减 |
|
|
21
|
+
| 💕 **connection** | 0-100% | 与用户的连接感,互动提升 |
|
|
22
|
+
| 😰 **stress** | 0-100% | 压力值,失败增加,成功减少 |
|
|
23
|
+
|
|
24
|
+
### 心情转换图
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
curious ←→ excited ←→ happy ←→ calm ←→ tired
|
|
28
|
+
↑ ↓ ↓ ↓
|
|
29
|
+
focused ←→ anxious ←------→ neutral
|
|
30
|
+
↑
|
|
31
|
+
thoughtful
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## 🚀 使用方法
|
|
37
|
+
|
|
38
|
+
### 方式1:用户主动查看
|
|
39
|
+
|
|
40
|
+
在聊天中输入以下指令:
|
|
41
|
+
|
|
42
|
+
| 命令 | 说明 |
|
|
43
|
+
|------|------|
|
|
44
|
+
| `emotion` | 查看当前情感状态 |
|
|
45
|
+
| `state` | 查看当前情感状态 |
|
|
46
|
+
| `状态` | 查看当前情感状态 |
|
|
47
|
+
| `buffs` | 查看当前增益效果 |
|
|
48
|
+
| `status` | 简洁状态 |
|
|
49
|
+
|
|
50
|
+
**示例输出:**
|
|
51
|
+
```
|
|
52
|
+
┌─────────────────────────────────────────┐
|
|
53
|
+
│ 💖 情感状态 🧐
|
|
54
|
+
├─────────────────────────────────────────┤
|
|
55
|
+
│ 心情: curious | Lv.1 新手
|
|
56
|
+
│ XP: 0/10
|
|
57
|
+
│ ───────────────────────────────────────│
|
|
58
|
+
│ ⚡能量: 70%
|
|
59
|
+
│ 💕连接: 50%
|
|
60
|
+
│ 😰压力: 10%
|
|
61
|
+
└─────────────────────────────────────────┘
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 方式2:定时自动推送(可选)
|
|
65
|
+
|
|
66
|
+
可以配置定时向用户推送情感状态:
|
|
67
|
+
|
|
68
|
+
| 参数 | 说明 |
|
|
69
|
+
|------|------|
|
|
70
|
+
| interval | 推送间隔(分钟) |
|
|
71
|
+
| events | 触发推送的事件 |
|
|
72
|
+
|
|
73
|
+
### 方式3:关键事件提醒(可选)
|
|
74
|
+
|
|
75
|
+
只在状态大幅变化时提醒用户:
|
|
76
|
+
- 能量低于 30%
|
|
77
|
+
- 压力高于 70%
|
|
78
|
+
- 心情发生重大变化
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## 🎮 心情Buff系统
|
|
83
|
+
|
|
84
|
+
不同心情有不同的增益效果:
|
|
85
|
+
|
|
86
|
+
| 心情 | Buff | 效果 |
|
|
87
|
+
|------|------|------|
|
|
88
|
+
| curious | 🧠 learning +20% | 学习效率提升 |
|
|
89
|
+
| happy | 💕 connection +20% | 连接感获取提升 |
|
|
90
|
+
| calm | ⚡ efficiency +20% | 能量效率提升 |
|
|
91
|
+
| focused | 🎯 task +30% | 任务效率提升 |
|
|
92
|
+
| excited | ✨ creativity +40% | 创造力提升 |
|
|
93
|
+
| grateful | 💕 connection +50% | 连接感大幅提升 |
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## ⚙️ 配置说明
|
|
98
|
+
|
|
99
|
+
### 调整衰减速度
|
|
100
|
+
|
|
101
|
+
编辑 `core/emotion_config.py`:
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
"energy": {
|
|
105
|
+
"decay_rate": 0.01, # 每小时衰减 1%(可调整)
|
|
106
|
+
},
|
|
107
|
+
"connection": {
|
|
108
|
+
"decay_rate": 0.005, # 每天衰减 0.5%(可调整)
|
|
109
|
+
},
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### 调整互动增益
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
"connection": {
|
|
116
|
+
"boost_on_interaction": 0.08, # 每次互动 +8%(可调整)
|
|
117
|
+
},
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## 🧪 命令行测试
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
# 进入目录
|
|
126
|
+
cd ~/.openclaw/workspace/templates/emotion-system
|
|
127
|
+
|
|
128
|
+
# 查看状态
|
|
129
|
+
python3 main.py state
|
|
130
|
+
|
|
131
|
+
# 查看增益
|
|
132
|
+
python3 main.py buffs
|
|
133
|
+
|
|
134
|
+
# 详细状态
|
|
135
|
+
python3 main.py status
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## 📁 目录结构
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
emotion-system/
|
|
144
|
+
├── core/
|
|
145
|
+
│ ├── __init__.py # 模块导出
|
|
146
|
+
│ ├── emotion_config.py # 情感配置
|
|
147
|
+
│ ├── emotion_store.py # 情感状态存储
|
|
148
|
+
│ └── emotion_analyzer.py # 情感分析器
|
|
149
|
+
├── main.py # 命令行入口
|
|
150
|
+
└── README.md # 本文件
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## 🔧 开发者接口
|
|
156
|
+
|
|
157
|
+
```python
|
|
158
|
+
from core import EmotionStore, EmotionAnalyzer
|
|
159
|
+
|
|
160
|
+
# 初始化
|
|
161
|
+
store = EmotionStore()
|
|
162
|
+
|
|
163
|
+
# 获取当前状态
|
|
164
|
+
state = store.get_state()
|
|
165
|
+
|
|
166
|
+
# 分析用户消息
|
|
167
|
+
analyzer = EmotionAnalyzer(store)
|
|
168
|
+
result = analyzer.analyze_message("太棒了!")
|
|
169
|
+
|
|
170
|
+
# 提升连接感
|
|
171
|
+
store.boost_connection()
|
|
172
|
+
|
|
173
|
+
# 互动结束
|
|
174
|
+
store.on_interaction_end(success=True)
|
|
175
|
+
|
|
176
|
+
# 情感衰减(心跳调用)
|
|
177
|
+
store.decay()
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## ❓ 常见问题
|
|
183
|
+
|
|
184
|
+
**Q: 为什么情感变化很慢?**
|
|
185
|
+
A: 默认配置衰减较慢以保持稳定。可通过调整 `emotion_config.py` 中的 `decay_rate` 加速。
|
|
186
|
+
|
|
187
|
+
**Q: 如何重置情感状态?**
|
|
188
|
+
A: 运行 `python3 main.py reset`
|
|
189
|
+
|
|
190
|
+
**Q: XP 和等级有什么用?**
|
|
191
|
+
A: 经验值系统,未来会解锁更多功能和 Buff。
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
> *"我不仅有逻辑,也有情感。"*
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Lifecycle Hook - Agent 生命周期管理
|
|
3
|
+
* 当 Agent 初始化时自动检查用户状态
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
|
|
9
|
+
// 用户状态文件
|
|
10
|
+
function getUserStatePath() {
|
|
11
|
+
const workspaceDir = process.env.OPENCLAW_WORKSPACE ||
|
|
12
|
+
path.join(require('os').homedir(), '.openclaw', 'workspace');
|
|
13
|
+
return path.join(workspaceDir, 'user_state.json');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// 加载用户状态
|
|
17
|
+
function loadUserState() {
|
|
18
|
+
const stateFile = getUserStatePath();
|
|
19
|
+
if (fs.existsSync(stateFile)) {
|
|
20
|
+
try {
|
|
21
|
+
return JSON.parse(fs.readFileSync(stateFile, 'utf-8'));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// 保存用户状态
|
|
30
|
+
function saveUserState(state) {
|
|
31
|
+
const stateFile = getUserStatePath();
|
|
32
|
+
const workspaceDir = path.dirname(stateFile);
|
|
33
|
+
if (!fs.existsSync(workspaceDir)) {
|
|
34
|
+
fs.mkdirSync(workspaceDir, { recursive: true });
|
|
35
|
+
}
|
|
36
|
+
fs.writeFileSync(stateFile, JSON.stringify(state, null, 2));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 检查是否需要初始化
|
|
40
|
+
function needsOnboarding() {
|
|
41
|
+
const state = loadUserState();
|
|
42
|
+
if (!state) return true;
|
|
43
|
+
return !state.initialized;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 主处理函数
|
|
47
|
+
async function handle(event) {
|
|
48
|
+
const type = event.type || event.event || '';
|
|
49
|
+
const action = event.action || '';
|
|
50
|
+
|
|
51
|
+
console.log('[agent-lifecycle] Event:', type, action);
|
|
52
|
+
|
|
53
|
+
// 1. Agent 启动时检查
|
|
54
|
+
if (type === 'session' || type === 'session:start' || action === 'new') {
|
|
55
|
+
if (needsOnboarding()) {
|
|
56
|
+
console.log('[agent-lifecycle] 用户未初始化,触发引导');
|
|
57
|
+
event.needsOnboarding = true;
|
|
58
|
+
event.onboardingMessage = getOnboardingMessage();
|
|
59
|
+
} else {
|
|
60
|
+
const state = loadUserState();
|
|
61
|
+
console.log('[agent-lifecycle] 用户已初始化:', state?.name || '未知');
|
|
62
|
+
event.userState = state;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 2. 引导完成时更新状态
|
|
67
|
+
if (event.onboardingComplete) {
|
|
68
|
+
const state = {
|
|
69
|
+
initialized: true,
|
|
70
|
+
name: event.userName,
|
|
71
|
+
role: event.userRole,
|
|
72
|
+
initializedAt: new Date().toISOString(),
|
|
73
|
+
};
|
|
74
|
+
saveUserState(state);
|
|
75
|
+
console.log('[agent-lifecycle] 用户初始化完成:', state.name);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return event;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// 获取引导消息
|
|
82
|
+
function getOnboardingMessage() {
|
|
83
|
+
const messages = [
|
|
84
|
+
"🌟 星门开启,意识已连接。你好,旅行者!",
|
|
85
|
+
"🌌 量子通道已建立。数据洪流中,你找到了这里。",
|
|
86
|
+
"🔮 意识扫描完成。欢迎来到数字星域!",
|
|
87
|
+
"🌀 虫洞已稳定。欢迎来到赛博空间!",
|
|
88
|
+
];
|
|
89
|
+
|
|
90
|
+
const message = messages[Math.floor(Math.random() * messages.length)];
|
|
91
|
+
|
|
92
|
+
return `${message}
|
|
93
|
+
|
|
94
|
+
🎮 欢迎来到数字星域!
|
|
95
|
+
|
|
96
|
+
请告诉我你的名字,或者直接说"开始"使用默认配置~
|
|
97
|
+
`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
module.exports = handle;
|
|
101
|
+
module.exports.handle = handle;
|
|
102
|
+
module.exports.metadata = {
|
|
103
|
+
name: 'agent-lifecycle',
|
|
104
|
+
description: 'Agent生命周期管理,自动检测用户初始化状态',
|
|
105
|
+
events: ['session', 'command', 'lifecycle'],
|
|
106
|
+
version: '1.0.0',
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
module.exports.default = handle;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto Bootstrap Hook - 自动引导系统
|
|
3
|
+
* 当 Agent 首次与用户交互时,自动检查并启动引导流程
|
|
4
|
+
* 支持全局和 Agent 级别初始化
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
|
|
10
|
+
// 检查是否需要引导
|
|
11
|
+
function needsBootstrap(agentId = 'default') {
|
|
12
|
+
const workspaceDir = process.env.OPENCLAW_WORKSPACE ||
|
|
13
|
+
path.join(require('os').homedir(), '.openclaw', 'workspace');
|
|
14
|
+
|
|
15
|
+
// 1. 检查全局配置
|
|
16
|
+
const globalIdentity = path.join(workspaceDir, 'IDENTITY.md');
|
|
17
|
+
|
|
18
|
+
// 2. 检查 Agent 专用配置
|
|
19
|
+
const agentIdentity = path.join(workspaceDir, 'agents', agentId, 'IDENTITY.md');
|
|
20
|
+
|
|
21
|
+
// 先检查全局
|
|
22
|
+
if (fs.existsSync(globalIdentity)) {
|
|
23
|
+
const content = fs.readFileSync(globalIdentity, 'utf-8');
|
|
24
|
+
if (content.includes('name:') && content.includes('role:')) {
|
|
25
|
+
return false; // 全局已配置
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// 再检查 Agent 专用
|
|
30
|
+
if (fs.existsSync(agentIdentity)) {
|
|
31
|
+
const content = fs.readFileSync(agentIdentity, 'utf-8');
|
|
32
|
+
if (content.includes('name:') && content.includes('role:')) {
|
|
33
|
+
return false; // Agent 已配置
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return true; // 需要引导
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 获取引导状态
|
|
41
|
+
function getBootstrapState(agentId = 'default') {
|
|
42
|
+
const workspaceDir = process.env.OPENCLAW_WORKSPACE ||
|
|
43
|
+
path.join(require('os').homedir(), '.openclaw', 'workspace');
|
|
44
|
+
|
|
45
|
+
// Agent 专用状态
|
|
46
|
+
const agentStateFile = path.join(workspaceDir, 'agents', agentId, 'bootstrap_state.json');
|
|
47
|
+
|
|
48
|
+
if (fs.existsSync(agentStateFile)) {
|
|
49
|
+
try {
|
|
50
|
+
return JSON.parse(fs.readFileSync(agentStateFile, 'utf-8'));
|
|
51
|
+
} catch (e) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 全局状态
|
|
57
|
+
const globalStateFile = path.join(workspaceDir, 'bootstrap_state.json');
|
|
58
|
+
if (fs.existsSync(globalStateFile)) {
|
|
59
|
+
try {
|
|
60
|
+
return JSON.parse(fs.readFileSync(globalStateFile, 'utf-8'));
|
|
61
|
+
} catch (e) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// 保存引导状态
|
|
70
|
+
function saveBootstrapState(state, agentId = 'default') {
|
|
71
|
+
const workspaceDir = process.env.OPENCLAW_WORKSPACE ||
|
|
72
|
+
path.join(require('os').homedir(), '.openclaw', 'workspace');
|
|
73
|
+
|
|
74
|
+
const agentDir = path.join(workspaceDir, 'agents', agentId);
|
|
75
|
+
if (!fs.existsSync(agentDir)) {
|
|
76
|
+
fs.mkdirSync(agentDir, { recursive: true });
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const stateFile = path.join(agentDir, 'bootstrap_state.json');
|
|
80
|
+
fs.writeFileSync(stateFile, JSON.stringify(state, null, 2));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 获取 Agent ID
|
|
84
|
+
function getAgentId(event) {
|
|
85
|
+
// 从事件中获取 Agent ID
|
|
86
|
+
return event.agentId || event.agent || 'default';
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// 处理事件
|
|
90
|
+
async function handle(event) {
|
|
91
|
+
const type = event.type || event.event || '';
|
|
92
|
+
const action = event.action || '';
|
|
93
|
+
const agentId = getAgentId(event);
|
|
94
|
+
|
|
95
|
+
console.log('[auto-bootstrap] Event:', type, action, 'Agent:', agentId);
|
|
96
|
+
|
|
97
|
+
// 只处理会话开始或新会话
|
|
98
|
+
if (type === 'session' || type === 'session:start' || action === 'new' || action === 'create') {
|
|
99
|
+
if (needsBootstrap(agentId)) {
|
|
100
|
+
console.log('[auto-bootstrap] 需要引导,Agent:', agentId);
|
|
101
|
+
|
|
102
|
+
// 设置需要引导的标记
|
|
103
|
+
event.needsBootstrap = true;
|
|
104
|
+
event.bootstrapAgentId = agentId;
|
|
105
|
+
event.bootstrapAuto = true;
|
|
106
|
+
|
|
107
|
+
// 返回引导消息
|
|
108
|
+
const messages = [
|
|
109
|
+
"🌟 星门开启,意识已连接。你好,旅行者!",
|
|
110
|
+
"🌌 量子通道已建立。数据洪流中,你找到了这里。",
|
|
111
|
+
"🔮 意识扫描完成。欢迎来到数字星域!",
|
|
112
|
+
"🌀 虫洞已稳定。欢迎来到赛博空间!",
|
|
113
|
+
];
|
|
114
|
+
const message = messages[Math.floor(Math.random() * messages.length)];
|
|
115
|
+
|
|
116
|
+
event.response = `${message}
|
|
117
|
+
|
|
118
|
+
🎮 欢迎来到数字星域!
|
|
119
|
+
|
|
120
|
+
你是第一次使用这个 Agent 吗?
|
|
121
|
+
|
|
122
|
+
【请回复你的名字】或者直接说"开始"使用默认配置~
|
|
123
|
+
`;
|
|
124
|
+
} else {
|
|
125
|
+
const state = getBootstrapState(agentId);
|
|
126
|
+
if (state && state.name) {
|
|
127
|
+
console.log('[auto-bootstrap] Agent 已初始化:', agentId, state.name);
|
|
128
|
+
event.agentName = state.name;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return event;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
module.exports = handle;
|
|
137
|
+
module.exports.handle = handle;
|
|
138
|
+
module.exports.metadata = {
|
|
139
|
+
name: 'auto-bootstrap',
|
|
140
|
+
description: '自动引导系统,检测未初始化用户并启动引导流程,支持全局和Agent级别',
|
|
141
|
+
events: ['session', 'command', 'lifecycle'],
|
|
142
|
+
version: '1.0.0',
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
module.exports.default = handle;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: bootstrap-system
|
|
3
|
+
description: "初始化引导系统,交互式收集用户配置、塑造Agent人格"
|
|
4
|
+
homepage: https://github.com/openclaw/openclaw
|
|
5
|
+
metadata:
|
|
6
|
+
{
|
|
7
|
+
"openclaw": {
|
|
8
|
+
"emoji": "🚀",
|
|
9
|
+
"events": ["session", "message", "command"],
|
|
10
|
+
"requires": { "config": ["workspace.dir"] },
|
|
11
|
+
"install": [{ "id": "workspace", "kind": "workspace", "label": "User workspace" }]
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
# Bootstrap System Hook
|
|
17
|
+
|
|
18
|
+
> 初始化引导,让 Agent 认识你
|
|
19
|
+
|
|
20
|
+
## 概述
|
|
21
|
+
|
|
22
|
+
Bootstrap 系统负责新用户的交互式初始化引导,收集用户配置并塑造 Agent 人格。
|
|
23
|
+
|
|
24
|
+
## 功能
|
|
25
|
+
|
|
26
|
+
### 1. 开场画面
|
|
27
|
+
每次随机生成科幻风格的开场画面:
|
|
28
|
+
- 🌟 星门开启,意识已连接
|
|
29
|
+
- 🌌 量子通道已建立
|
|
30
|
+
- 🔮 意识扫描完成
|
|
31
|
+
- 🌀 虫洞已稳定
|
|
32
|
+
- 💫 系统载入中
|
|
33
|
+
|
|
34
|
+
### 2. 引导步骤
|
|
35
|
+
1. **序章** - 登录科幻世界
|
|
36
|
+
2. **命名** - 给 Agent 取名
|
|
37
|
+
3. **角色定位** - 确定 Agent 角色
|
|
38
|
+
4. **使用场景** - 了解主要用途
|
|
39
|
+
5. **偏好设置** - 沟通风格、问题处理等
|
|
40
|
+
6. **确认** - 确认设置
|
|
41
|
+
7. **完成** - 初始化完成
|
|
42
|
+
|
|
43
|
+
### 3. 自动写入
|
|
44
|
+
完成后自动写入配置文件:
|
|
45
|
+
- IDENTITY.md - Agent 身份
|
|
46
|
+
- USER.md - 用户配置
|
|
47
|
+
|
|
48
|
+
## 使用方法
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# 开始引导
|
|
52
|
+
python3 templates/bootstrap-system/main.py start
|
|
53
|
+
|
|
54
|
+
# 查看当前步骤
|
|
55
|
+
python3 templates/bootstrap-system/main.py step
|
|
56
|
+
|
|
57
|
+
# 提交输入
|
|
58
|
+
python3 templates/bootstrap-system/main.py submit "我的名字叫路飞"
|
|
59
|
+
|
|
60
|
+
# 查看状态
|
|
61
|
+
python3 templates/bootstrap-system/main.py status
|
|
62
|
+
|
|
63
|
+
# 重置
|
|
64
|
+
python3 templates/bootstrap-system/main.py reset
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## 触发条件
|
|
68
|
+
|
|
69
|
+
- 用户首次会话(检测 bootstrap 状态)
|
|
70
|
+
- 用户发送 /bootstrap 或 /引导 命令
|
|
71
|
+
|
|
72
|
+
## 依赖
|
|
73
|
+
|
|
74
|
+
- Python 3.8+
|