chaimi-keep-mcp 3.1.27 → 3.1.29
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/SKILL.md +25 -1
- package/bin/cli.js +87 -2
- package/package.json +1 -1
- package/server.js +22 -8
package/SKILL.md
CHANGED
|
@@ -120,7 +120,31 @@ Agent 通过 MCP 协议自动获取工具列表,无需手动查询。
|
|
|
120
120
|
⚠️ **强制流程**:保存小票时必须按以下顺序执行:
|
|
121
121
|
1. 调用 `get_parse_prompt` 获取 prompt 模板
|
|
122
122
|
2. 使用 prompt 模板调用大模型解析小票图片
|
|
123
|
-
3.
|
|
123
|
+
3. **调用 `save_receipt` 前,必须完成字段核对清单(见下文)**
|
|
124
|
+
4. 调用 `save_receipt` 保存解析结果
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
### 🚨 小票字段核对清单(调用前必须检查)
|
|
129
|
+
|
|
130
|
+
**从 prompt 解析结果中提取的所有字段,必须全部传递给 `save_receipt`**:
|
|
131
|
+
|
|
132
|
+
| 字段 | 是否必须 | 常见遗漏 | 检查方式 |
|
|
133
|
+
|------|----------|----------|----------|
|
|
134
|
+
| `store` | ✅ | 否 | 商家名称 |
|
|
135
|
+
| `date` | ✅ **高频遗漏** | **是** | ISO 8601 格式,如:2026-01-08T11:42:27 |
|
|
136
|
+
| `totalAmount` | ✅ | 否 | 商品原价总和 |
|
|
137
|
+
| `actualAmount` | ✅ **高频遗漏** | **是** | 实付金额(优惠后)|
|
|
138
|
+
| `originalAmount` | ✅ **高频遗漏** | **是** | 原价(优惠前)|
|
|
139
|
+
| `discountAmount` | ✅ **高频遗漏** | **是** | 优惠金额 |
|
|
140
|
+
| `paymentMethod` | ✅ **高频遗漏** | **是** | 如:支付宝支付、微信支付 |
|
|
141
|
+
| `items` | ✅ | 否 | 商品数组,每个必须有 name/amount/price/quantity |
|
|
142
|
+
|
|
143
|
+
**核对步骤**:
|
|
144
|
+
1. 提取完小票信息后,对照上表检查每个字段
|
|
145
|
+
2. **重点检查标记"高频遗漏"的字段**:date、actualAmount、originalAmount、discountAmount、paymentMethod
|
|
146
|
+
3. 确认所有字段都在 args 中后再调用 `save_receipt`
|
|
147
|
+
4. 如果某个字段小票上确实没有,可以传空字符串或 0,但不能省略
|
|
124
148
|
|
|
125
149
|
**注意**:MCP 工具会不断迭代更新,请以实际通过 MCP 协议获取的工具定义为准。
|
|
126
150
|
|
package/bin/cli.js
CHANGED
|
@@ -31,7 +31,7 @@ const DEFAULT_CHAIMI_CONFIG = {
|
|
|
31
31
|
lifecycle: 'keep-alive'
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
// 支持的 Agent
|
|
34
|
+
// 支持的 Agent 列表(MCP 配置)
|
|
35
35
|
const SUPPORTED_AGENTS = [
|
|
36
36
|
{
|
|
37
37
|
name: 'MCPorter (WorkBuddy/OpenClaw)',
|
|
@@ -74,6 +74,30 @@ const SUPPORTED_AGENTS = [
|
|
|
74
74
|
}
|
|
75
75
|
];
|
|
76
76
|
|
|
77
|
+
// 支持的 Skill 目录(OpenClaw/WorkBuddy 架构)
|
|
78
|
+
const SKILL_DIRECTORIES = [
|
|
79
|
+
{
|
|
80
|
+
name: 'OpenClaw',
|
|
81
|
+
skillPath: path.join(os.homedir(), '.openclaw', 'skills', 'chaimi-keep-mcp'),
|
|
82
|
+
platform: 'darwin'
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: 'OpenClaw (Linux)',
|
|
86
|
+
skillPath: path.join(os.homedir(), '.openclaw', 'skills', 'chaimi-keep-mcp'),
|
|
87
|
+
platform: 'linux'
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: 'WorkBuddy',
|
|
91
|
+
skillPath: path.join(os.homedir(), '.workbuddy', 'skills', 'chaimi-keep-mcp'),
|
|
92
|
+
platform: 'darwin'
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: 'WorkBuddy (Windows)',
|
|
96
|
+
skillPath: path.join(os.homedir(), 'workbuddy', 'skills', 'chaimi-keep-mcp'),
|
|
97
|
+
platform: 'win32'
|
|
98
|
+
}
|
|
99
|
+
];
|
|
100
|
+
|
|
77
101
|
/**
|
|
78
102
|
* 安全读取 JSON 文件
|
|
79
103
|
*/
|
|
@@ -156,6 +180,62 @@ function installToAgent(agent) {
|
|
|
156
180
|
}
|
|
157
181
|
}
|
|
158
182
|
|
|
183
|
+
/**
|
|
184
|
+
* 同步 SKILL.md 到 Skill 目录
|
|
185
|
+
* 用于 OpenClaw/WorkBuddy 等支持 Skill 文件的 Agent
|
|
186
|
+
*/
|
|
187
|
+
function syncSkillFiles() {
|
|
188
|
+
const skillSourcePath = path.join(__dirname, '..', 'SKILL.md');
|
|
189
|
+
|
|
190
|
+
if (!fs.existsSync(skillSourcePath)) {
|
|
191
|
+
return { success: false, reason: 'source-not-found' };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const results = [];
|
|
195
|
+
|
|
196
|
+
for (const skillDir of SKILL_DIRECTORIES) {
|
|
197
|
+
try {
|
|
198
|
+
// 平台检查
|
|
199
|
+
if (skillDir.platform && skillDir.platform !== os.platform()) {
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// 检查父目录是否存在(Agent 是否安装)
|
|
204
|
+
const parentDir = path.dirname(skillDir.skillPath);
|
|
205
|
+
if (!fs.existsSync(parentDir)) {
|
|
206
|
+
continue; // Agent 未安装,跳过
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// 创建 skill 目录
|
|
210
|
+
if (!fs.existsSync(skillDir.skillPath)) {
|
|
211
|
+
fs.mkdirSync(skillDir.skillPath, { recursive: true });
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// 复制 SKILL.md
|
|
215
|
+
const targetPath = path.join(skillDir.skillPath, 'SKILL.md');
|
|
216
|
+
fs.copyFileSync(skillSourcePath, targetPath);
|
|
217
|
+
|
|
218
|
+
results.push({
|
|
219
|
+
agent: skillDir.name,
|
|
220
|
+
success: true,
|
|
221
|
+
path: targetPath
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
console.error(`✓ ${skillDir.name}: Skill 文件已同步`);
|
|
225
|
+
|
|
226
|
+
} catch (error) {
|
|
227
|
+
results.push({
|
|
228
|
+
agent: skillDir.name,
|
|
229
|
+
success: false,
|
|
230
|
+
error: error.message
|
|
231
|
+
});
|
|
232
|
+
console.error(`✗ ${skillDir.name}: Skill 同步失败 (${error.message})`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return results;
|
|
237
|
+
}
|
|
238
|
+
|
|
159
239
|
/**
|
|
160
240
|
* 配置所有支持的 Agent
|
|
161
241
|
* 注意:所有输出使用 console.error,避免污染 stdout(MCP 协议通信使用 stdout)
|
|
@@ -165,6 +245,7 @@ function configureAllAgents() {
|
|
|
165
245
|
|
|
166
246
|
const results = [];
|
|
167
247
|
|
|
248
|
+
// 1. 配置 MCP Server
|
|
168
249
|
for (const agent of SUPPORTED_AGENTS) {
|
|
169
250
|
const result = installToAgent(agent);
|
|
170
251
|
results.push({ agent: agent.name, ...result });
|
|
@@ -187,13 +268,17 @@ function configureAllAgents() {
|
|
|
187
268
|
}
|
|
188
269
|
}
|
|
189
270
|
|
|
271
|
+
// 2. 同步 Skill 文件
|
|
272
|
+
console.error('\n📋 正在同步 Skill 文件...\n');
|
|
273
|
+
syncSkillFiles();
|
|
274
|
+
|
|
190
275
|
// 统计
|
|
191
276
|
const configured = results.filter(r => r.success && r.action !== 'skipped').length;
|
|
192
277
|
const skipped = results.filter(r => r.success && r.action === 'skipped').length;
|
|
193
278
|
const failed = results.filter(r => !r.success).length;
|
|
194
279
|
|
|
195
280
|
console.error('\n📊 配置统计:');
|
|
196
|
-
console.error(`
|
|
281
|
+
console.error(` 新增 MCP 配置: ${configured} 个`);
|
|
197
282
|
console.error(` 已存在: ${skipped} 个`);
|
|
198
283
|
if (failed > 0) {
|
|
199
284
|
console.error(` 失败: ${failed} 个`);
|
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -459,18 +459,32 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
459
459
|
}
|
|
460
460
|
|
|
461
461
|
case 'save_receipt': {
|
|
462
|
-
// 0.
|
|
462
|
+
// 0. 参数完整性检查 - 提醒 Agent 哪些字段缺失
|
|
463
|
+
const requiredFields = ['store', 'date', 'totalAmount', 'actualAmount', 'originalAmount', 'discountAmount', 'paymentMethod'];
|
|
464
|
+
const missingFields = [];
|
|
465
|
+
requiredFields.forEach(field => {
|
|
466
|
+
if (processedArgs[field] === undefined || processedArgs[field] === null || processedArgs[field] === '') {
|
|
467
|
+
missingFields.push(field);
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
if (missingFields.length > 0) {
|
|
472
|
+
console.error(`⚠️ 警告:save_receipt 缺少以下字段:${missingFields.join(', ')}`);
|
|
473
|
+
console.error(` 请从 get_parse_prompt 的解析结果中提取并传递所有字段`);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// 1. 参数格式强制检查 - 确保 items 中每个商品都有完整的字段
|
|
463
477
|
if (processedArgs.items && Array.isArray(processedArgs.items)) {
|
|
464
478
|
const invalidItems = [];
|
|
465
479
|
processedArgs.items.forEach((item, index) => {
|
|
466
|
-
const
|
|
467
|
-
if (!item.hasOwnProperty('name'))
|
|
468
|
-
if (!item.hasOwnProperty('amount'))
|
|
469
|
-
if (!item.hasOwnProperty('price'))
|
|
470
|
-
if (!item.hasOwnProperty('quantity'))
|
|
480
|
+
const itemMissingFields = [];
|
|
481
|
+
if (!item.hasOwnProperty('name')) itemMissingFields.push('name');
|
|
482
|
+
if (!item.hasOwnProperty('amount')) itemMissingFields.push('amount');
|
|
483
|
+
if (!item.hasOwnProperty('price')) itemMissingFields.push('price');
|
|
484
|
+
if (!item.hasOwnProperty('quantity')) itemMissingFields.push('quantity');
|
|
471
485
|
|
|
472
|
-
if (
|
|
473
|
-
invalidItems.push(`商品${index + 1}(${item.name || '未命名'})缺少字段: ${
|
|
486
|
+
if (itemMissingFields.length > 0) {
|
|
487
|
+
invalidItems.push(`商品${index + 1}(${item.name || '未命名'})缺少字段: ${itemMissingFields.join(', ')}`);
|
|
474
488
|
}
|
|
475
489
|
});
|
|
476
490
|
|