@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.
Files changed (53) hide show
  1. package/AGENTS.md +294 -0
  2. package/BOOTSTRAP.md +268 -0
  3. package/DEMO.md +103 -0
  4. package/HEARTBEAT.md +444 -0
  5. package/IDENTITY.md +239 -0
  6. package/LICENSE +21 -0
  7. package/MEMORY.md +324 -0
  8. package/README.md +582 -0
  9. package/SOUL.md +254 -0
  10. package/TOOLS.md +317 -0
  11. package/USER.md +274 -0
  12. package/bootstrap-system/HOOK.md +31 -0
  13. package/bootstrap-system/README.md +109 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +155 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/systems/bootstrap.d.ts.map +1 -0
  18. package/dist/systems/bootstrap.js +272 -0
  19. package/dist/systems/bootstrap.js.map +1 -0
  20. package/dist/systems/cognition.d.ts.map +1 -0
  21. package/dist/systems/cognition.js +254 -0
  22. package/dist/systems/cognition.js.map +1 -0
  23. package/dist/systems/emotion.d.ts.map +1 -0
  24. package/dist/systems/emotion.js +194 -0
  25. package/dist/systems/emotion.js.map +1 -0
  26. package/dist/systems/input.d.ts.map +1 -0
  27. package/dist/systems/input.js +161 -0
  28. package/dist/systems/input.js.map +1 -0
  29. package/dist/systems/output.d.ts.map +1 -0
  30. package/dist/systems/output.js +224 -0
  31. package/dist/systems/output.js.map +1 -0
  32. package/dist/test.js +54 -0
  33. package/emotion-system/README.md +195 -0
  34. package/hooks/agent-lifecycle/handler.js +109 -0
  35. package/hooks/auto-bootstrap/handler.js +145 -0
  36. package/hooks/bootstrap-system/HOOK.md +74 -0
  37. package/hooks/bootstrap-system/handler.js +220 -0
  38. package/hooks/cognition-system/HOOK.md +75 -0
  39. package/hooks/cognition-system/handler.js +186 -0
  40. package/hooks/emotion-system/HOOK.md +81 -0
  41. package/hooks/emotion-system/handler.js +239 -0
  42. package/hooks/heartbeat-system/HOOK.md +63 -0
  43. package/hooks/heartbeat-system/handler.js +121 -0
  44. package/hooks/input-system/HOOK.md +79 -0
  45. package/hooks/input-system/handler.js +181 -0
  46. package/hooks/memory-system/HOOK.md +43 -0
  47. package/hooks/memory-system/handler.js +213 -0
  48. package/hooks/output-system/HOOK.md +79 -0
  49. package/hooks/output-system/handler.js +195 -0
  50. package/memory-system/README.md +291 -0
  51. package/openclaw.plugin.json +51 -0
  52. package/package.json +30 -0
  53. package/requirements.txt +11 -0
@@ -0,0 +1,239 @@
1
+ /**
2
+ * Emotion System Hook Handler
3
+ *
4
+ * 集成 Python emotion-system 到 OpenClaw
5
+ */
6
+
7
+ const fs = require('fs').promises;
8
+ const path = require('path');
9
+ const { spawn } = require('child_process');
10
+ const os = require('os');
11
+
12
+ // 配置
13
+ const CONFIG = {
14
+ emotionSystemPath: 'templates/emotion-system',
15
+ mainScript: 'main.py',
16
+ };
17
+
18
+ /**
19
+ * 运行 Python emotion-system CLI
20
+ */
21
+ async function runPythonCli(args = []) {
22
+ const workspaceDir = process.env.OPENCLAW_WORKSPACE ||
23
+ path.join(os.homedir(), '.openclaw', 'workspace');
24
+ const pythonScript = path.join(workspaceDir, CONFIG.emotionSystemPath, CONFIG.mainScript);
25
+
26
+ return new Promise((resolve) => {
27
+ fs.access(pythonScript).then(() => {
28
+ const proc = spawn('python3', [pythonScript, ...args], {
29
+ cwd: workspaceDir,
30
+ env: {
31
+ ...process.env,
32
+ OPENCLAW_WORKSPACE: workspaceDir,
33
+ PYTHONPATH: path.join(workspaceDir, CONFIG.emotionSystemPath)
34
+ }
35
+ });
36
+
37
+ let output = '';
38
+ let error = '';
39
+
40
+ proc.stdout.on('data', (data) => { output += data.toString(); });
41
+ proc.stderr.on('data', (data) => { error += data.toString(); });
42
+
43
+ proc.on('close', (code) => {
44
+ resolve({ success: code === 0, output, error });
45
+ });
46
+
47
+ proc.on('error', (err) => {
48
+ resolve({ success: false, error: err.message });
49
+ });
50
+
51
+ }).catch(() => {
52
+ resolve({ success: false, error: 'Emotion system not found' });
53
+ });
54
+ });
55
+ }
56
+
57
+ /**
58
+ * 从会话消息中提取文本内容
59
+ */
60
+ function extractMessageText(message) {
61
+ if (!message || !message.content) return '';
62
+
63
+ if (typeof message.content === 'string') {
64
+ return message.content;
65
+ }
66
+
67
+ if (Array.isArray(message.content)) {
68
+ return message.content
69
+ .filter((c) => c.type === 'text')
70
+ .map((c) => c.text || '')
71
+ .join('');
72
+ }
73
+
74
+ return '';
75
+ }
76
+
77
+ /**
78
+ * 格式化情感状态展示 - 简洁版(手机端一行)
79
+ */
80
+ function formatEmotionCompact(state) {
81
+ if (!state) return '';
82
+
83
+ const moodEmoji = {
84
+ curious: '🧐', happy: '😊', calm: '😌', focused: '🎯',
85
+ tired: '😴', anxious: '😰', excited: '🤩', thoughtful: '🤔',
86
+ neutral: '😐', sad: '😢', grateful: '🥰',
87
+ };
88
+
89
+ const emoji = moodEmoji[state.mood] || '😐';
90
+ const e = Math.round(state.energy * 100);
91
+ const c = Math.round(state.connection * 100);
92
+ const s = Math.round(state.stress * 100);
93
+
94
+ return `${emoji} Lv.${state.level} ${state.mood} | ⚡${e}% | 💕${c}% | 😰${s}%`;
95
+ }
96
+
97
+ /**
98
+ * 处理 session_start - 加载情感状态
99
+ */
100
+ async function handleSessionStart(event) {
101
+ console.log('[emotion-system] Session start, loading emotion state...');
102
+
103
+ const result = await runPythonCli(['state', '--json']);
104
+
105
+ if (result.success && result.output) {
106
+ try {
107
+ const state = JSON.parse(result.output);
108
+ event.context = event.context || {};
109
+ event.context.emotionState = state;
110
+ console.log('[emotion-system] Emotion state loaded:', state.mood);
111
+ } catch (e) {
112
+ console.log('[emotion-system] Parse state error:', e.message);
113
+ }
114
+ } else {
115
+ console.log('[emotion-system] Could not load state:', result.error);
116
+ }
117
+
118
+ return event;
119
+ }
120
+
121
+ /**
122
+ * 处理 message:received - 分析用户消息
123
+ */
124
+ async function handleMessageReceived(event) {
125
+ console.log('[emotion-system] Analyzing message...');
126
+
127
+ const context = event.context || {};
128
+ const messages = context.messages || [];
129
+
130
+ if (messages.length === 0) return event;
131
+
132
+ const reversed = [...messages].reverse();
133
+ const lastUserMsg = reversed.find((m) => m.role === 'user');
134
+
135
+ if (!lastUserMsg) return event;
136
+
137
+ const userText = extractMessageText(lastUserMsg);
138
+
139
+ if (!userText || userText.startsWith('/')) return event;
140
+
141
+ const result = await runPythonCli(['analyze', userText]);
142
+
143
+ if (result.success) {
144
+ console.log('[emotion-system] Message analyzed');
145
+ }
146
+
147
+ return event;
148
+ }
149
+
150
+ /**
151
+ * 处理 agent_end - 互动结束,更新情感
152
+ */
153
+ async function handleAgentEnd(event) {
154
+ console.log('[emotion-system] Agent end, updating emotion...');
155
+
156
+ await runPythonCli(['boost']);
157
+ await runPythonCli(['success']);
158
+
159
+ console.log('[emotion-system] Emotion updated');
160
+
161
+ return event;
162
+ }
163
+
164
+ /**
165
+ * 处理 heartbeat - 自然衰减
166
+ */
167
+ async function handleHeartbeat(event) {
168
+ console.log('[emotion-system] Heartbeat, applying decay...');
169
+ await runPythonCli(['decay']);
170
+ return event;
171
+ }
172
+
173
+ /**
174
+ * 获取当前情感状态
175
+ */
176
+ async function getEmotionState() {
177
+ const result = await runPythonCli(['state', '--json']);
178
+ if (result.success) {
179
+ try {
180
+ return JSON.parse(result.output);
181
+ } catch (e) {
182
+ return null;
183
+ }
184
+ }
185
+ return null;
186
+ }
187
+
188
+ /**
189
+ * 主 handler
190
+ */
191
+ async function handle(event) {
192
+ const type = event.type || event.event || '';
193
+ const action = event.action || '';
194
+
195
+ console.log(`[emotion-system] Event: ${type}/${action}`);
196
+
197
+ try {
198
+ if (type === 'session' || type === 'session:start') {
199
+ if (action === 'start' || action === '') {
200
+ await handleSessionStart(event);
201
+ }
202
+ }
203
+ else if (type === 'message' || type === 'message:received') {
204
+ await handleMessageReceived(event);
205
+ }
206
+ else if (type === 'lifecycle' || type === 'lifecycle:end') {
207
+ if (action === 'end' || action === '') {
208
+ await handleAgentEnd(event);
209
+ }
210
+ }
211
+ else if (type === 'heartbeat' || type === 'pulse') {
212
+ await handleHeartbeat(event);
213
+ }
214
+ else if (type === 'command') {
215
+ if (action === 'emotion' || action === '状态' || action === 'state') {
216
+ const state = await getEmotionState();
217
+ // 简洁版手机端显示
218
+ event.response = formatEmotionCompact(state);
219
+ }
220
+ }
221
+ } catch (error) {
222
+ console.error('[emotion-system] Handler error:', error.message);
223
+ }
224
+
225
+ return event;
226
+ }
227
+
228
+ module.exports = handle;
229
+ module.exports.handle = handle;
230
+ module.exports.getEmotionState = getEmotionState;
231
+ module.exports.formatEmotionCompact = formatEmotionCompact;
232
+ module.exports.metadata = {
233
+ name: 'emotion-system',
234
+ description: '集成情感系统,管理 Agent 心情、能量、连接感和压力',
235
+ events: ['session', 'message', 'lifecycle', 'heartbeat', 'command'],
236
+ version: '1.0.0',
237
+ };
238
+
239
+ module.exports.default = handle;
@@ -0,0 +1,63 @@
1
+ ---
2
+ name: heartbeat-system
3
+ description: "心跳系统,定时执行情感衰减、状态保存、垃圾清理"
4
+ homepage: https://github.com/openclaw/openclaw
5
+ metadata:
6
+ {
7
+ "openclaw": {
8
+ "emoji": "💓",
9
+ "events": ["heartbeat", "pulse", "command"],
10
+ "requires": { "config": ["workspace.dir"] },
11
+ "install": [{ "id": "workspace", "kind": "workspace", "label": "User workspace" }]
12
+ }
13
+ }
14
+ ---
15
+
16
+ # Heartbeat System Hook
17
+
18
+ > 让 Agent 拥有"心跳",定时执行维护任务
19
+
20
+ ## 概述
21
+
22
+ 心跳系统模拟 Agent 的生命体征,定时执行维护任务。
23
+
24
+ ## 心跳层次
25
+
26
+ | 层次 | 频率 | 任务 |
27
+ |------|------|------|
28
+ | 脉冲层 | 每5秒 | 存活确认 |
29
+ | 节律层 | 每分钟 | 情感衰减、状态保存 |
30
+ | 周期层 | 每小时 | 记忆整理、深度清理 |
31
+
32
+ ## 功能
33
+
34
+ 1. **情感衰减** - 定时调用情感系统,降低能量和连接感
35
+ 2. **状态保存** - 定期保存各系统状态
36
+ 3. **垃圾清理** - 清理过期临时文件
37
+ 4. **存活确认** - 确认系统正常运行
38
+
39
+ ## 使用方法
40
+
41
+ ```bash
42
+ # 查看状态
43
+ python3 templates/heartbeat-system/main.py status
44
+
45
+ # 运行一次
46
+ python3 templates/heartbeat-system/main.py run --once
47
+
48
+ # 守护进程模式
49
+ python3 templates/heartbeat-system/main.py run
50
+ ```
51
+
52
+ ## 集成方式
53
+
54
+ 推荐使用 cron 每分钟调用:
55
+
56
+ ```bash
57
+ */1 * * * * cd ~/.openclaw/workspace && python3 templates/heartbeat-system/main.py run --once
58
+ ```
59
+
60
+ ## 依赖
61
+
62
+ - Python 3.8+
63
+ - emotion-system(用于情感衰减)
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Heartbeat System Hook Handler
3
+ *
4
+ * 集成 Python heartbeat-system 到 OpenClaw
5
+ */
6
+
7
+ const fs = require('fs').promises;
8
+ const path = require('path');
9
+ const { spawn } = require('child_process');
10
+ const os = require('os');
11
+
12
+ // 配置
13
+ const CONFIG = {
14
+ heartbeatSystemPath: 'templates/heartbeat-system',
15
+ mainScript: 'main.py',
16
+ };
17
+
18
+ /**
19
+ * 运行 Python heartbeat-system CLI
20
+ */
21
+ async function runPythonCli(args = []) {
22
+ const workspaceDir = process.env.OPENCLAW_WORKSPACE ||
23
+ path.join(os.homedir(), '.openclaw', 'workspace');
24
+ const pythonScript = path.join(workspaceDir, CONFIG.heartbeatSystemPath, CONFIG.mainScript);
25
+
26
+ return new Promise((resolve) => {
27
+ fs.access(pythonScript).then(() => {
28
+ const proc = spawn('python3', [pythonScript, ...args], {
29
+ cwd: workspaceDir,
30
+ env: {
31
+ ...process.env,
32
+ OPENCLAW_WORKSPACE: workspaceDir,
33
+ PYTHONPATH: path.join(workspaceDir, CONFIG.heartbeatSystemPath)
34
+ }
35
+ });
36
+
37
+ let output = '';
38
+ let error = '';
39
+
40
+ proc.stdout.on('data', (data) => { output += data.toString(); });
41
+ proc.stderr.on('data', (data) => { error += data.toString(); });
42
+
43
+ proc.on('close', (code) => {
44
+ resolve({ success: code === 0, output, error });
45
+ });
46
+
47
+ proc.on('error', (err) => {
48
+ resolve({ success: false, error: err.message });
49
+ });
50
+
51
+ }).catch(() => {
52
+ resolve({ success: false, error: 'Heartbeat system not found' });
53
+ });
54
+ });
55
+ }
56
+
57
+ /**
58
+ * 处理 heartbeat / pulse 事件
59
+ */
60
+ async function handleHeartbeat(event) {
61
+ console.log('[heartbeat-system] Heartbeat pulse, running tasks...');
62
+
63
+ const result = await runPythonCli(['run', '--once']);
64
+
65
+ if (result.success) {
66
+ console.log('[heartbeat-system] Tasks completed');
67
+ } else {
68
+ console.log('[heartbeat-system] Tasks failed:', result.error);
69
+ }
70
+
71
+ return event;
72
+ }
73
+
74
+ /**
75
+ * 处理 status 命令
76
+ */
77
+ async function handleStatus(event) {
78
+ const result = await runPythonCli(['status', '--json']);
79
+
80
+ if (result.success) {
81
+ event.response = result.output;
82
+ }
83
+
84
+ return event;
85
+ }
86
+
87
+ /**
88
+ * 主 handler
89
+ */
90
+ async function handle(event) {
91
+ const type = event.type || event.event || '';
92
+ const action = event.action || '';
93
+
94
+ console.log(`[heartbeat-system] Event: ${type}/${action}`);
95
+
96
+ try {
97
+ if (type === 'heartbeat' || type === 'pulse') {
98
+ await handleHeartbeat(event);
99
+ }
100
+ else if (type === 'command') {
101
+ if (action === 'heartbeat' || action === 'status') {
102
+ await handleStatus(event);
103
+ }
104
+ }
105
+ } catch (error) {
106
+ console.error('[heartbeat-system] Handler error:', error.message);
107
+ }
108
+
109
+ return event;
110
+ }
111
+
112
+ module.exports = handle;
113
+ module.exports.handle = handle;
114
+ module.exports.metadata = {
115
+ name: 'heartbeat-system',
116
+ description: '心跳系统,定时执行情感衰减、状态保存、垃圾清理',
117
+ events: ['heartbeat', 'pulse', 'command'],
118
+ version: '1.0.0',
119
+ };
120
+
121
+ module.exports.default = handle;
@@ -0,0 +1,79 @@
1
+ ---
2
+ name: input-system
3
+ description: "输入感知系统,理解用户意图、提取实体、分析情感"
4
+ homepage: https://github.com/openclaw/openclaw
5
+ metadata:
6
+ {
7
+ "openclaw": {
8
+ "emoji": "🎯",
9
+ "events": ["message", "command"],
10
+ "requires": { "config": ["workspace.dir"] },
11
+ "install": [{ "id": "workspace", "kind": "workspace", "label": "User workspace" }]
12
+ }
13
+ }
14
+ ---
15
+
16
+ # Input System Hook
17
+
18
+ > 理解用户输入的"大脑"
19
+
20
+ ## 概述
21
+
22
+ 输入感知系统负责理解用户的消息,识别意图、提取实体、分析情感。
23
+
24
+ ## 功能
25
+
26
+ ### 意图识别
27
+ 识别用户想要做什么:
28
+
29
+ | 意图 | 说明 | 示例 |
30
+ |------|------|------|
31
+ | command | 命令 | /help |
32
+ | task | 任务 | 帮我写个程序 |
33
+ | question | 提问 | 怎么安装? |
34
+ | chat | 闲聊 | 好啊 |
35
+ | confirm | 确认 | 好的 |
36
+ | cancel | 取消 | 算了 |
37
+ | complaint | 抱怨 | 不好用 |
38
+ | praise | 表扬 | 很棒 |
39
+
40
+ ### 实体提取
41
+ 从文本中提取关键信息:
42
+
43
+ - 时间 (time)
44
+ - 日期 (date)
45
+ - 数字 (number)
46
+ - 代码 (code)
47
+ - 链接 (url)
48
+ - 文件 (file)
49
+
50
+ ### 情感分析
51
+ 分析用户情绪倾向
52
+
53
+ ## 使用方法
54
+
55
+ ```bash
56
+ # 分析文本
57
+ python3 templates/input-system/main.py "帮我写一个Hello World"
58
+
59
+ # 交互模式
60
+ python3 templates/input-system/main.py -i
61
+ ```
62
+
63
+ ## 输出格式
64
+
65
+ ```json
66
+ {
67
+ "type": "task",
68
+ "confidence": 0.65,
69
+ "action": "create",
70
+ "entities": [
71
+ {"type": "code", "value": "Hello World"}
72
+ ],
73
+ "slots": {"keywords": ["写", "程序"]}
74
+ }
75
+ ```
76
+
77
+ ## 依赖
78
+
79
+ - Python 3.8+
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Input System Hook Handler
3
+ *
4
+ * 集成 Python input-system 到 OpenClaw
5
+ */
6
+
7
+ const fs = require('fs').promises;
8
+ const path = require('path');
9
+ const { spawn } = require('child_process');
10
+ const os = require('os');
11
+
12
+ // 配置
13
+ const CONFIG = {
14
+ inputSystemPath: 'templates/input-system',
15
+ mainScript: 'main.py',
16
+ };
17
+
18
+ /**
19
+ * 运行 Python input-system CLI
20
+ */
21
+ async function runPythonCli(args = []) {
22
+ const workspaceDir = process.env.OPENCLAW_WORKSPACE ||
23
+ path.join(os.homedir(), '.openclaw', 'workspace');
24
+ const pythonScript = path.join(workspaceDir, CONFIG.inputSystemPath, CONFIG.mainScript);
25
+
26
+ return new Promise((resolve) => {
27
+ fs.access(pythonScript).then(() => {
28
+ const proc = spawn('python3', [pythonScript, ...args], {
29
+ cwd: workspaceDir,
30
+ env: {
31
+ ...process.env,
32
+ OPENCLAW_WORKSPACE: workspaceDir,
33
+ PYTHONPATH: path.join(workspaceDir, CONFIG.inputSystemPath)
34
+ }
35
+ });
36
+
37
+ let output = '';
38
+ let error = '';
39
+
40
+ proc.stdout.on('data', (data) => { output += data.toString(); });
41
+ proc.stderr.on('data', (data) => { error += data.toString(); });
42
+
43
+ proc.on('close', (code) => {
44
+ resolve({ success: code === 0, output, error });
45
+ });
46
+
47
+ proc.on('error', (err) => {
48
+ resolve({ success: false, error: err.message });
49
+ });
50
+
51
+ }).catch(() => {
52
+ resolve({ success: false, error: 'Input system not found' });
53
+ });
54
+ });
55
+ }
56
+
57
+ /**
58
+ * 从会话消息中提取文本内容
59
+ */
60
+ function extractMessageText(message) {
61
+ if (!message || !message.content) return '';
62
+
63
+ if (typeof message.content === 'string') {
64
+ return message.content;
65
+ }
66
+
67
+ if (Array.isArray(message.content)) {
68
+ return message.content
69
+ .filter((c) => c.type === 'text')
70
+ .map((c) => c.text || '')
71
+ .join('');
72
+ }
73
+
74
+ return '';
75
+ }
76
+
77
+ /**
78
+ * 处理 message:received - 分析用户意图
79
+ */
80
+ async function handleMessageReceived(event) {
81
+ console.log('[input-system] Analyzing user intent...');
82
+
83
+ const context = event.context || {};
84
+ const messages = context.messages || [];
85
+
86
+ if (messages.length === 0) return event;
87
+
88
+ // 获取最新用户消息
89
+ const reversed = [...messages].reverse();
90
+ const lastUserMsg = reversed.find((m) => m.role === 'user');
91
+
92
+ if (!lastUserMsg) return event;
93
+
94
+ const userText = extractMessageText(lastUserMsg);
95
+
96
+ if (!userText) return event;
97
+
98
+ // 分析意图
99
+ const result = await runPythonCli([userText, '--json']);
100
+
101
+ if (result.success && result.output) {
102
+ try {
103
+ const intent = JSON.parse(result.output);
104
+ context.intent = intent;
105
+ console.log('[input-system] Intent detected:', intent.type, '(' + Math.round(intent.confidence * 100) + '%)');
106
+
107
+ // 根据意图类型调整回复策略
108
+ context.replyStrategy = getReplyStrategy(intent.type, intent.action);
109
+
110
+ } catch (e) {
111
+ console.log('[input-system] Parse error:', e.message);
112
+ }
113
+ }
114
+
115
+ return event;
116
+ }
117
+
118
+ /**
119
+ * 根据意图类型获取回复策略
120
+ */
121
+ function getReplyStrategy(intentType, action) {
122
+ const strategies = {
123
+ 'command': { style: 'direct', format: 'action' },
124
+ 'task': { style: 'action', format: 'result' },
125
+ 'question': { style: 'explanatory', format: 'answer' },
126
+ 'chat': { style: 'casual', format: 'friendly' },
127
+ 'confirm': { style: 'brief', format: 'acknowledgment' },
128
+ 'cancel': { style: 'brief', format: 'acknowledgment' },
129
+ 'complaint': { style: 'empathetic', format: 'apology' },
130
+ 'praise': { style: 'grateful', format: 'thanks' },
131
+ 'create': { style: 'action', format: 'result' },
132
+ 'read': { style: 'informative', format: 'content' },
133
+ 'update': { style: 'action', format: 'result' },
134
+ 'delete': { style: 'cautious', format: 'confirm' },
135
+ 'search': { style: 'informative', format: 'results' },
136
+ 'execute': { style: 'action', format: 'result' },
137
+ };
138
+
139
+ return strategies[intentType] || { style: 'neutral', format: 'text' };
140
+ }
141
+
142
+ /**
143
+ * 主 handler
144
+ */
145
+ async function handle(event) {
146
+ const type = event.type || event.event || '';
147
+ const action = event.action || '';
148
+
149
+ console.log(`[input-system] Event: ${type}/${action}`);
150
+
151
+ try {
152
+ if (type === 'message' || type === 'message:received') {
153
+ await handleMessageReceived(event);
154
+ }
155
+ else if (type === 'command') {
156
+ if (action === 'analyze' || action === '意图') {
157
+ // 分析指定文本
158
+ const text = event.text || '';
159
+ if (text) {
160
+ const result = await runPythonCli([text]);
161
+ event.response = result.output;
162
+ }
163
+ }
164
+ }
165
+ } catch (error) {
166
+ console.error('[input-system] Handler error:', error.message);
167
+ }
168
+
169
+ return event;
170
+ }
171
+
172
+ module.exports = handle;
173
+ module.exports.handle = handle;
174
+ module.exports.metadata = {
175
+ name: 'input-system',
176
+ description: '输入感知系统,理解用户意图、提取实体、分析情感',
177
+ events: ['message', 'command'],
178
+ version: '1.0.0',
179
+ };
180
+
181
+ module.exports.default = handle;