chaimi-keep-mcp 3.1.49 → 3.2.1-beta.0
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/README.md +6 -0
- package/SKILL.md +185 -280
- package/_meta.json +59 -0
- package/bin/global-install.js +56 -0
- package/bin/sync-skill.js +89 -24
- package/oauth.js +5 -3
- package/package.json +3 -1
- package/references/advanced-features.md +146 -0
- package/references/api-reference.md +205 -0
- package/references/authentication.md +142 -0
- package/references/response-templates-test.md +243 -0
- package/references/response-templates.md +424 -0
- package/references/troubleshooting.md +269 -0
- package/server.js +31 -5
- package/utils/machine-id.js +165 -0
package/bin/sync-skill.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Skill 文件同步脚本
|
|
4
4
|
*
|
|
5
|
-
*
|
|
5
|
+
* 功能:安装时自动同步完整 Skill 目录到 Skill 架构的 Agent
|
|
6
6
|
* 支持:OpenClaw、WorkBuddy 等
|
|
7
7
|
* 扩展:可通过 ~/.chaimi-mcp/skill-config.json 添加自定义路径
|
|
8
8
|
*/
|
|
@@ -22,6 +22,11 @@ const BUILT_IN_PATHS = [
|
|
|
22
22
|
name: 'WorkBuddy',
|
|
23
23
|
skillPath: path.join(os.homedir(), '.workbuddy', 'skills', 'chaimi-keep-mcp'),
|
|
24
24
|
platform: ['darwin', 'linux', 'win32']
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'Hermes',
|
|
28
|
+
skillPath: path.join(os.homedir(), '.hermes', 'skills', 'chaimi-keep-mcp'),
|
|
29
|
+
platform: ['darwin', 'linux', 'win32']
|
|
25
30
|
}
|
|
26
31
|
];
|
|
27
32
|
|
|
@@ -44,39 +49,99 @@ function loadUserConfig() {
|
|
|
44
49
|
}
|
|
45
50
|
|
|
46
51
|
/**
|
|
47
|
-
*
|
|
52
|
+
* 同步整个 Skill 目录到指定路径
|
|
48
53
|
*/
|
|
49
|
-
function
|
|
54
|
+
function syncSkillDirectory(targetPath, agentName) {
|
|
55
|
+
const results = [];
|
|
56
|
+
|
|
50
57
|
try {
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
//
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
const skillSourceDir = path.join(__dirname, '..');
|
|
59
|
+
|
|
60
|
+
// 需要同步的文件和目录
|
|
61
|
+
const itemsToSync = [
|
|
62
|
+
{ source: 'SKILL.md', target: 'SKILL.md', required: true },
|
|
63
|
+
{ source: '_meta.json', target: '_meta.json', required: true },
|
|
64
|
+
{ source: 'references', target: 'references', required: true, isDirectory: true }
|
|
65
|
+
];
|
|
66
|
+
|
|
59
67
|
// 检查父目录是否存在(Agent 是否安装)
|
|
60
68
|
const parentDir = path.dirname(targetPath);
|
|
61
69
|
if (!fs.existsSync(parentDir)) {
|
|
62
|
-
|
|
63
|
-
return { success: false, reason: 'agent-not-installed' };
|
|
70
|
+
return { success: false, reason: 'agent-not-installed', details: results };
|
|
64
71
|
}
|
|
65
|
-
|
|
72
|
+
|
|
66
73
|
// 创建 skill 目录
|
|
67
74
|
if (!fs.existsSync(targetPath)) {
|
|
68
75
|
fs.mkdirSync(targetPath, { recursive: true });
|
|
69
76
|
}
|
|
70
|
-
|
|
71
|
-
//
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
|
|
78
|
+
// 同步每个文件/目录
|
|
79
|
+
for (const item of itemsToSync) {
|
|
80
|
+
const sourcePath = path.join(skillSourceDir, item.source);
|
|
81
|
+
const targetItemPath = path.join(targetPath, item.target);
|
|
82
|
+
|
|
83
|
+
// 检查源文件是否存在
|
|
84
|
+
if (!fs.existsSync(sourcePath)) {
|
|
85
|
+
if (item.required) {
|
|
86
|
+
console.error(`❌ ${agentName}: ${item.source} 源文件不存在`);
|
|
87
|
+
results.push({ file: item.source, success: false, error: 'source-not-found' });
|
|
88
|
+
}
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
if (item.isDirectory) {
|
|
94
|
+
// 同步目录
|
|
95
|
+
syncDirectory(sourcePath, targetItemPath);
|
|
96
|
+
} else {
|
|
97
|
+
// 同步文件
|
|
98
|
+
fs.copyFileSync(sourcePath, targetItemPath);
|
|
99
|
+
}
|
|
100
|
+
results.push({ file: item.source, success: true });
|
|
101
|
+
} catch (error) {
|
|
102
|
+
console.error(`❌ ${agentName}: 同步 ${item.source} 失败 - ${error.message}`);
|
|
103
|
+
results.push({ file: item.source, success: false, error: error.message });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const allSuccess = results.filter(r => r.required !== false).every(r => r.success);
|
|
108
|
+
return {
|
|
109
|
+
success: allSuccess,
|
|
110
|
+
path: targetPath,
|
|
111
|
+
details: results
|
|
112
|
+
};
|
|
113
|
+
|
|
77
114
|
} catch (error) {
|
|
78
115
|
console.error(`❌ ${agentName}: 同步失败 - ${error.message}`);
|
|
79
|
-
return { success: false, error: error.message };
|
|
116
|
+
return { success: false, error: error.message, details: results };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 递归同步目录
|
|
122
|
+
*/
|
|
123
|
+
function syncDirectory(sourceDir, targetDir) {
|
|
124
|
+
// 创建目标目录
|
|
125
|
+
if (!fs.existsSync(targetDir)) {
|
|
126
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// 读取源目录内容
|
|
130
|
+
const items = fs.readdirSync(sourceDir);
|
|
131
|
+
|
|
132
|
+
for (const item of items) {
|
|
133
|
+
const sourcePath = path.join(sourceDir, item);
|
|
134
|
+
const targetPath = path.join(targetDir, item);
|
|
135
|
+
|
|
136
|
+
const stat = fs.statSync(sourcePath);
|
|
137
|
+
|
|
138
|
+
if (stat.isDirectory()) {
|
|
139
|
+
// 递归同步子目录
|
|
140
|
+
syncDirectory(sourcePath, targetPath);
|
|
141
|
+
} else {
|
|
142
|
+
// 复制文件
|
|
143
|
+
fs.copyFileSync(sourcePath, targetPath);
|
|
144
|
+
}
|
|
80
145
|
}
|
|
81
146
|
}
|
|
82
147
|
|
|
@@ -95,7 +160,7 @@ function main() {
|
|
|
95
160
|
continue;
|
|
96
161
|
}
|
|
97
162
|
|
|
98
|
-
const result =
|
|
163
|
+
const result = syncSkillDirectory(agent.skillPath, agent.name);
|
|
99
164
|
results.push({ agent: agent.name, ...result });
|
|
100
165
|
|
|
101
166
|
if (result.success) {
|
|
@@ -115,7 +180,7 @@ function main() {
|
|
|
115
180
|
continue;
|
|
116
181
|
}
|
|
117
182
|
|
|
118
|
-
const result =
|
|
183
|
+
const result = syncSkillDirectory(userPath.path, userPath.name);
|
|
119
184
|
results.push({ agent: userPath.name, ...result });
|
|
120
185
|
|
|
121
186
|
if (result.success) {
|
package/oauth.js
CHANGED
|
@@ -146,7 +146,7 @@ class OAuthManager {
|
|
|
146
146
|
await execPromise(command);
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
async requestDeviceCode(useUrlScheme = false) {
|
|
149
|
+
async requestDeviceCode(useUrlScheme = false, extraParams = {}) {
|
|
150
150
|
const response = await fetch(this.mcpOAuthUrl, {
|
|
151
151
|
method: 'POST',
|
|
152
152
|
headers: {
|
|
@@ -156,7 +156,8 @@ class OAuthManager {
|
|
|
156
156
|
tool: 'deviceCode',
|
|
157
157
|
params: {
|
|
158
158
|
clientId: 'chaihuo-mcp-client',
|
|
159
|
-
useUrlScheme: useUrlScheme
|
|
159
|
+
useUrlScheme: useUrlScheme,
|
|
160
|
+
...extraParams
|
|
160
161
|
}
|
|
161
162
|
})
|
|
162
163
|
});
|
|
@@ -494,8 +495,9 @@ class FileTokenStorage extends TokenStorage {
|
|
|
494
495
|
updatedAt: new Date().toISOString()
|
|
495
496
|
};
|
|
496
497
|
await this.fs.writeFile(agentNamePath, JSON.stringify(data, null, 2), { mode: 0o600 });
|
|
498
|
+
console.error('✅ Agent 名称已保存:', agentNamePath);
|
|
497
499
|
} catch (err) {
|
|
498
|
-
|
|
500
|
+
console.error('❌ 保存 Agent 名称失败:', err.message);
|
|
499
501
|
}
|
|
500
502
|
}
|
|
501
503
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chaimi-keep-mcp",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.2.1-beta.0",
|
|
4
4
|
"description": "柴米记账 MCP Server - 支持 Claude、Cursor、OpenClaw、WorkBuddy 等 AI 工具直接记账",
|
|
5
5
|
"main": "server.js",
|
|
6
6
|
"bin": {
|
|
@@ -9,9 +9,11 @@
|
|
|
9
9
|
"files": [
|
|
10
10
|
"bin/",
|
|
11
11
|
"utils/",
|
|
12
|
+
"references/",
|
|
12
13
|
"server.js",
|
|
13
14
|
"oauth.js",
|
|
14
15
|
"SKILL.md",
|
|
16
|
+
"_meta.json",
|
|
15
17
|
"README.md",
|
|
16
18
|
"config.example.yaml",
|
|
17
19
|
".env.example"
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: "chaimi-keep-advanced-features"
|
|
3
|
+
description: 柴米AI记账高级功能详解,包含深度分析和智能洞察
|
|
4
|
+
version: "1.0.0"
|
|
5
|
+
updated: "2026-04-25"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# 柴米AI记账高级功能
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 目录
|
|
13
|
+
|
|
14
|
+
- [一、智能洞察详解](#一智能洞察详解)
|
|
15
|
+
- [二、消费模式分析](#二消费模式分析)
|
|
16
|
+
- [三、数据导出与分析](#三数据导出与分析)
|
|
17
|
+
- [四、高级查询技巧](#四高级查询技巧)
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 一、智能洞察详解
|
|
22
|
+
|
|
23
|
+
### 1.1 洞察维度
|
|
24
|
+
|
|
25
|
+
| 维度 | 说明 | 示例 |
|
|
26
|
+
|:-----|:-----|:-----|
|
|
27
|
+
| **消费频次** | 某类消费次数 | "本周餐饮消费5次" |
|
|
28
|
+
| **消费趋势** | 环比变化 | "比上月增长20%" |
|
|
29
|
+
| **异常检测** | 超出常规的消费 | "今日消费超过日均3倍" |
|
|
30
|
+
| **时段分析** | 高频消费时间 | "午餐时间消费占比60%" |
|
|
31
|
+
| **商家偏好** | 常去商家统计 | "本月麦当劳消费8次" |
|
|
32
|
+
|
|
33
|
+
### 1.2 洞察生成逻辑
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
原始数据
|
|
37
|
+
↓
|
|
38
|
+
数据清洗(去除异常值)
|
|
39
|
+
↓
|
|
40
|
+
模式识别(聚类分析)
|
|
41
|
+
↓
|
|
42
|
+
趋势计算(环比/同比)
|
|
43
|
+
↓
|
|
44
|
+
洞察生成(自然语言)
|
|
45
|
+
↓
|
|
46
|
+
建议推荐(基于规则)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## 二、消费模式分析
|
|
52
|
+
|
|
53
|
+
### 2.1 分析类型
|
|
54
|
+
|
|
55
|
+
#### 餐饮消费模式
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
分析维度:
|
|
59
|
+
- 用餐时段偏好(早餐/午餐/晚餐)
|
|
60
|
+
- 用餐方式分布(外卖/堂食/自制)
|
|
61
|
+
- 人均消费区间
|
|
62
|
+
- 高频商家TOP5
|
|
63
|
+
|
|
64
|
+
输出示例:
|
|
65
|
+
"您偏好午餐外出就餐(占餐饮消费65%),
|
|
66
|
+
平均消费35元/餐,
|
|
67
|
+
常去商家:麦当劳、肯德基、真功夫"
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
#### 交通消费模式
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
分析维度:
|
|
74
|
+
- 出行方式占比(地铁/打车/公交)
|
|
75
|
+
- 通勤成本趋势
|
|
76
|
+
- 高频路线
|
|
77
|
+
|
|
78
|
+
输出示例:
|
|
79
|
+
"地铁通勤为主(占交通费用80%),
|
|
80
|
+
日均通勤成本12元,
|
|
81
|
+
建议购买月票可节省20%"
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## 三、数据导出与分析
|
|
87
|
+
|
|
88
|
+
### 3.1 导出格式
|
|
89
|
+
|
|
90
|
+
| 格式 | 适用场景 | 工具 |
|
|
91
|
+
|:-----|:---------|:-----|
|
|
92
|
+
| JSON | 程序处理 | Python/JavaScript |
|
|
93
|
+
| CSV | Excel分析 | Excel/Google Sheets |
|
|
94
|
+
| Markdown | 报告生成 | Markdown编辑器 |
|
|
95
|
+
|
|
96
|
+
### 3.2 分析示例
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
# Python分析示例
|
|
100
|
+
import json
|
|
101
|
+
|
|
102
|
+
# 加载导出的数据
|
|
103
|
+
with open('chaimi_data.json') as f:
|
|
104
|
+
data = json.load(f)
|
|
105
|
+
|
|
106
|
+
# 计算日均消费
|
|
107
|
+
total = sum(item['amount'] for item in data['expenses'])
|
|
108
|
+
days = 30
|
|
109
|
+
daily_avg = total / days
|
|
110
|
+
|
|
111
|
+
print(f"日均消费:¥{daily_avg:.2f}")
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## 四、高级查询技巧
|
|
117
|
+
|
|
118
|
+
### 4.1 时间范围技巧
|
|
119
|
+
|
|
120
|
+
| 查询需求 | 参数设置 | 说明 |
|
|
121
|
+
|:---------|:---------|:-----|
|
|
122
|
+
| 本周 | period="this_week" | 周一到周日 |
|
|
123
|
+
| 本月 | period="this_month" | 1号到今天 |
|
|
124
|
+
| 上月 | period="last_month" | 完整上月 |
|
|
125
|
+
| 自定义 | start_date + end_date | 任意范围 |
|
|
126
|
+
|
|
127
|
+
### 4.2 筛选组合
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
# 查询本月餐饮消费
|
|
131
|
+
{
|
|
132
|
+
"period": "this_month",
|
|
133
|
+
"category": "餐饮"
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
# 查询大额消费(>500)
|
|
137
|
+
{
|
|
138
|
+
"period": "this_month",
|
|
139
|
+
"min_amount": 500
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
**文档版本:v1.0.0**
|
|
146
|
+
**最后更新:2026-04-25**
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: "chaimi-keep-api-reference"
|
|
3
|
+
description: 柴米AI记账API参考 - 查询分析类工具说明
|
|
4
|
+
description: >-
|
|
5
|
+
柴米AI记账MCP Server API参考。包含查询、统计、分析类工具说明。
|
|
6
|
+
TRIGGER: 需要查询消费记录、查看统计、导出数据时。
|
|
7
|
+
DO NOT TRIGGER: 记账操作(直接使用工具即可)。
|
|
8
|
+
version: "1.0.0"
|
|
9
|
+
updated: "2026-04-25"
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# 柴米AI记账 API 参考
|
|
13
|
+
|
|
14
|
+
> ⚠️ **保密提示**:记账类工具(save_expense/save_income/save_receipt)为内部实现,不对外开放详细文档
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 目录
|
|
19
|
+
|
|
20
|
+
- [一、工具分类说明](#一工具分类说明)
|
|
21
|
+
- [二、查询工具](#二查询工具)
|
|
22
|
+
- [三、分析工具](#三分析工具)
|
|
23
|
+
- [四、辅助工具](#四辅助工具)
|
|
24
|
+
- [五、错误码](#五错误码)
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## 一、工具分类说明
|
|
29
|
+
|
|
30
|
+
| 分类 | 工具 | 说明 |
|
|
31
|
+
|:-----|:-----|:-----|
|
|
32
|
+
| **记账** | save_expense、save_income、save_receipt | 核心功能,直接调用即可 |
|
|
33
|
+
| **查询** | get_expenses、get_statistics、get_receipt_list | 查询消费记录和统计 |
|
|
34
|
+
| **分析** | get_insights、export_data | AI洞察和数据导出 |
|
|
35
|
+
| **辅助** | get_skill、submit_feedback | 获取文档、提交反馈 |
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## 二、查询工具
|
|
40
|
+
|
|
41
|
+
### 2.1 get_expenses - 查询消费记录
|
|
42
|
+
|
|
43
|
+
**功能:** 按时间范围查询消费记录
|
|
44
|
+
|
|
45
|
+
**参数:**
|
|
46
|
+
|
|
47
|
+
| 参数名 | 类型 | 必填 | 说明 | 示例 |
|
|
48
|
+
|:-------|:-----|:----:|:-----|:-----|
|
|
49
|
+
| period | string | ✅ | 时间范围 | "this_week", "this_month", "last_month" |
|
|
50
|
+
| start_date | string | ❌ | 开始日期 | "2026-04-01" |
|
|
51
|
+
| end_date | string | ❌ | 结束日期 | "2026-04-30" |
|
|
52
|
+
| category | string | ❌ | 分类筛选 | "餐饮" |
|
|
53
|
+
| limit | number | ❌ | 返回条数 | 10 |
|
|
54
|
+
|
|
55
|
+
**返回值:**
|
|
56
|
+
|
|
57
|
+
```json
|
|
58
|
+
{
|
|
59
|
+
"success": true,
|
|
60
|
+
"data": {
|
|
61
|
+
"total": 1250.00,
|
|
62
|
+
"count": 15,
|
|
63
|
+
"items": [
|
|
64
|
+
{
|
|
65
|
+
"id": "exp_123",
|
|
66
|
+
"amount": 35.00,
|
|
67
|
+
"item": "午餐",
|
|
68
|
+
"category": "餐饮",
|
|
69
|
+
"date": "2026-04-24"
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
### 2.2 get_statistics - 统计分析
|
|
79
|
+
|
|
80
|
+
**功能:** 获取消费统计分析
|
|
81
|
+
|
|
82
|
+
**参数:**
|
|
83
|
+
|
|
84
|
+
| 参数名 | 类型 | 必填 | 说明 | 示例 |
|
|
85
|
+
|:-------|:-----|:----:|:-----|:-----|
|
|
86
|
+
| period | string | ✅ | 时间范围 | "this_month" |
|
|
87
|
+
| group_by | string | ❌ | 分组方式 | "category", "day" |
|
|
88
|
+
|
|
89
|
+
**返回值:**
|
|
90
|
+
|
|
91
|
+
```json
|
|
92
|
+
{
|
|
93
|
+
"success": true,
|
|
94
|
+
"data": {
|
|
95
|
+
"total": 3500.00,
|
|
96
|
+
"by_category": {
|
|
97
|
+
"餐饮": 1200.00,
|
|
98
|
+
"交通": 500.00,
|
|
99
|
+
"购物": 800.00
|
|
100
|
+
},
|
|
101
|
+
"daily_avg": 116.67
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
### 2.3 get_receipt_list - 小票列表
|
|
109
|
+
|
|
110
|
+
**功能:** 查询已识别的小票记录
|
|
111
|
+
|
|
112
|
+
**参数:**
|
|
113
|
+
|
|
114
|
+
| 参数名 | 类型 | 必填 | 说明 |
|
|
115
|
+
|:-------|:-----|:----:|:-----|
|
|
116
|
+
| period | string | ❌ | 时间范围 |
|
|
117
|
+
| limit | number | ❌ | 返回条数 |
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## 三、分析工具
|
|
122
|
+
|
|
123
|
+
### 3.1 get_insights - 智能洞察
|
|
124
|
+
|
|
125
|
+
**功能:** AI分析消费习惯
|
|
126
|
+
|
|
127
|
+
**参数:**
|
|
128
|
+
|
|
129
|
+
| 参数名 | 类型 | 必填 | 说明 | 示例 |
|
|
130
|
+
|:-------|:-----|:----:|:-----|:-----|
|
|
131
|
+
| period | string | ✅ | 分析周期 | "this_month" |
|
|
132
|
+
| focus | string | ❌ | 关注维度 | "category", "trend" |
|
|
133
|
+
|
|
134
|
+
**返回值:**
|
|
135
|
+
|
|
136
|
+
```json
|
|
137
|
+
{
|
|
138
|
+
"success": true,
|
|
139
|
+
"data": {
|
|
140
|
+
"insights": [
|
|
141
|
+
"本周餐饮消费偏高,建议控制",
|
|
142
|
+
"通勤费用稳定,继续保持"
|
|
143
|
+
],
|
|
144
|
+
"suggestions": [
|
|
145
|
+
"尝试自带午餐,可节省约200元/周"
|
|
146
|
+
]
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
### 3.2 export_data - 数据导出
|
|
154
|
+
|
|
155
|
+
**功能:** 导出完整数据
|
|
156
|
+
|
|
157
|
+
**参数:**
|
|
158
|
+
|
|
159
|
+
| 参数名 | 类型 | 必填 | 说明 | 示例 |
|
|
160
|
+
|:-------|:-----|:----:|:-----|:-----|
|
|
161
|
+
| format | string | ✅ | 导出格式 | "json", "csv" |
|
|
162
|
+
| period | string | ✅ | 时间范围 | "this_year" |
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## 四、辅助工具
|
|
167
|
+
|
|
168
|
+
### 4.1 get_skill - 获取Skill文档
|
|
169
|
+
|
|
170
|
+
**功能:** 获取最新Skill文档
|
|
171
|
+
|
|
172
|
+
**参数:** 无
|
|
173
|
+
|
|
174
|
+
**⚠️ 重要:** 首次使用时调用,获取最新规范
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
### 4.2 submit_feedback - 提交反馈
|
|
179
|
+
|
|
180
|
+
**功能:** 提交问题反馈
|
|
181
|
+
|
|
182
|
+
**参数:**
|
|
183
|
+
|
|
184
|
+
| 参数名 | 类型 | 必填 | 说明 |
|
|
185
|
+
|:-------|:-----|:----:|:-----|
|
|
186
|
+
| content | string | ✅ | 反馈内容 |
|
|
187
|
+
| type | string | ❌ | 反馈类型 |
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## 五、错误码
|
|
192
|
+
|
|
193
|
+
| 错误码 | 说明 | 解决方案 |
|
|
194
|
+
|:-------|:-----|:---------|
|
|
195
|
+
| 400 | 参数错误 | 检查参数格式 |
|
|
196
|
+
| 401 | 未授权 | 完成授权流程 |
|
|
197
|
+
| 403 | 权限不足 | 检查Token权限 |
|
|
198
|
+
| 404 | 记录不存在 | 确认记录ID |
|
|
199
|
+
| 408 | 请求超时 | 稍后重试 |
|
|
200
|
+
| 500 | 服务器错误 | 联系技术支持 |
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
**文档版本:v1.0.0**
|
|
205
|
+
**最后更新:2026-04-25**
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: "chaimi-keep-authentication"
|
|
3
|
+
description: 柴米AI记账授权流程详解
|
|
4
|
+
version: "1.0.0"
|
|
5
|
+
updated: "2026-04-25"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# 柴米AI记账授权流程
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 目录
|
|
13
|
+
|
|
14
|
+
- [一、授权原理](#一授权原理)
|
|
15
|
+
- [二、授权流程](#二授权流程)
|
|
16
|
+
- [三、Token管理](#三token管理)
|
|
17
|
+
- [四、安全最佳实践](#四安全最佳实践)
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 一、授权原理
|
|
22
|
+
|
|
23
|
+
### 1.1 授权模型
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
用户(小程序端) Agent(MCP端)
|
|
27
|
+
│ │
|
|
28
|
+
│ 1. 请求授权 │
|
|
29
|
+
│────────────────────────>│
|
|
30
|
+
│ │
|
|
31
|
+
│ 2. 生成验证码 │
|
|
32
|
+
│<────────────────────────│
|
|
33
|
+
│ │
|
|
34
|
+
│ 3. 小程序确认 │
|
|
35
|
+
│────────────────────────>│
|
|
36
|
+
│ │
|
|
37
|
+
│ 4. 发放Token │
|
|
38
|
+
│<────────────────────────│
|
|
39
|
+
│ │
|
|
40
|
+
│ 5. Token记账 │
|
|
41
|
+
│────────────────────────>│
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 1.2 Token有效期
|
|
45
|
+
|
|
46
|
+
| Token类型 | 有效期 | 说明 |
|
|
47
|
+
|:----------|:-------|:-----|
|
|
48
|
+
| Access Token | 24小时 | 日常记账使用 |
|
|
49
|
+
| Refresh Token | 7天 | 用于刷新Access Token |
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## 二、授权流程
|
|
54
|
+
|
|
55
|
+
### 2.1 首次授权
|
|
56
|
+
|
|
57
|
+
**步骤:**
|
|
58
|
+
|
|
59
|
+
1. **生成验证码**
|
|
60
|
+
```bash
|
|
61
|
+
./scripts/auth-flow.sh
|
|
62
|
+
```
|
|
63
|
+
输出:
|
|
64
|
+
```
|
|
65
|
+
🔐 柴米AI记账授权
|
|
66
|
+
═══════════════════════════
|
|
67
|
+
📱 验证码:GGCY-AC84
|
|
68
|
+
⏰ 有效期:5分钟
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
2. **小程序确认**
|
|
72
|
+
- 打开"柴米AI记账"小程序
|
|
73
|
+
- 点击"我的" → "Agent 授权"
|
|
74
|
+
- 输入验证码
|
|
75
|
+
- 点击确认
|
|
76
|
+
|
|
77
|
+
3. **完成授权**
|
|
78
|
+
- Agent显示授权成功
|
|
79
|
+
- 开始记账
|
|
80
|
+
|
|
81
|
+
### 2.2 重新授权
|
|
82
|
+
|
|
83
|
+
**场景:** Token过期、更换设备、安全考虑
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# 方式1:直接重新授权
|
|
87
|
+
./scripts/auth-flow.sh
|
|
88
|
+
|
|
89
|
+
# 方式2:先撤销再授权
|
|
90
|
+
./scripts/revoke-auth.sh
|
|
91
|
+
./scripts/auth-flow.sh
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## 三、Token管理
|
|
97
|
+
|
|
98
|
+
### 3.1 检查Token状态
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
./scripts/check-auth.sh
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**输出:**
|
|
105
|
+
```
|
|
106
|
+
✅ 授权状态:有效
|
|
107
|
+
📅 Token有效期:还剩 23 小时
|
|
108
|
+
🔒 安全等级:高
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### 3.2 Token刷新
|
|
112
|
+
|
|
113
|
+
Token将在过期前自动刷新,无需手动操作。
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## 四、安全最佳实践
|
|
118
|
+
|
|
119
|
+
### 4.1 安全建议
|
|
120
|
+
|
|
121
|
+
| 建议 | 说明 |
|
|
122
|
+
|:-----|:-----|
|
|
123
|
+
| 定期更换 | 建议每周重新授权一次 |
|
|
124
|
+
| 设备专用 | 不同设备使用不同Token |
|
|
125
|
+
| 及时撤销 | 不再使用时立即撤销 |
|
|
126
|
+
| 保护验证码 | 勿将验证码告知他人 |
|
|
127
|
+
|
|
128
|
+
### 4.2 撤销授权
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
./scripts/revoke-auth.sh
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
**场景:**
|
|
135
|
+
- 更换Agent
|
|
136
|
+
- 安全考虑
|
|
137
|
+
- 不再使用
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
**文档版本:v1.0.0**
|
|
142
|
+
**最后更新:2026-04-25**
|