ai-engineering-init 1.16.1 → 1.16.2
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.
|
@@ -42,9 +42,10 @@ description: |
|
|
|
42
42
|
|
|
43
43
|
项目目录下的配置文件,优先于全局配置。
|
|
44
44
|
|
|
45
|
-
### 优先级 3
|
|
45
|
+
### 优先级 3:全局配置(所有项目共享)
|
|
46
46
|
|
|
47
|
-
全局配置文件(通过 `npx ai-engineering-init config --scope global`
|
|
47
|
+
全局配置文件(通过 `npx ai-engineering-init config --scope global` 创建)。
|
|
48
|
+
查找路径:`~/.claude/mysql-config.json` 或 `~/.cursor/mysql-config.json`(取决于使用的工具)。
|
|
48
49
|
**推荐**:公司统一的数据库连接信息放全局,项目特定的覆盖放本地。
|
|
49
50
|
|
|
50
51
|
### 优先级 4:工程配置文件(零配置,本地开发默认)
|
|
@@ -115,11 +116,12 @@ brew install mysql-client
|
|
|
115
116
|
### 配置文件查找顺序
|
|
116
117
|
|
|
117
118
|
```
|
|
118
|
-
1. 本地项目:.claude/mysql-config.json
|
|
119
|
-
2. 全局配置:~/.claude/mysql-config.json
|
|
119
|
+
1. 本地项目:.claude/mysql-config.json(或 .cursor/mysql-config.json)
|
|
120
|
+
2. 全局配置:~/.claude/mysql-config.json(或 ~/.cursor/mysql-config.json)
|
|
120
121
|
```
|
|
121
122
|
|
|
122
123
|
本地配置优先。如果本地无配置,使用全局。两者都存在时,本地覆盖全局(同名环境取本地值)。
|
|
124
|
+
`config --scope global` 会同时写入 `~/.claude/` 和 `~/.cursor/`(如果目录存在)。
|
|
123
125
|
|
|
124
126
|
### 配置文件结构(支持 range 范围匹配)
|
|
125
127
|
|
|
@@ -25,81 +25,114 @@ description: |
|
|
|
25
25
|
|
|
26
26
|
## 多环境配置
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
### 配置文件查找顺序
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
```
|
|
31
|
+
1. 本地项目:.claude/loki-config.json(新格式)
|
|
32
|
+
2. 本地项目:.claude/skills/loki-log-query/environments.json(旧格式,兼容)
|
|
33
|
+
3. 全局配置:~/.claude/loki-config.json
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
本地配置优先。全局配置推荐用 `npx ai-engineering-init config --type loki --scope global` 创建。
|
|
37
|
+
|
|
38
|
+
### 配置结构(支持 range 范围匹配)
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"active": "monitor-dev",
|
|
43
|
+
"environments": {
|
|
44
|
+
"monitor-dev": {
|
|
45
|
+
"name": "Monitor 开发环境",
|
|
46
|
+
"url": "https://monitor-dev.xnzn.net/grafana",
|
|
47
|
+
"token": "glsa_xxx",
|
|
48
|
+
"aliases": ["mdev", "dev"],
|
|
49
|
+
"range": "dev1~15",
|
|
50
|
+
"projects": ["dev01","dev02","dev03","dev04","dev05","dev06","dev07","dev08","dev09","dev10","dev11","dev12","dev13","dev14","dev15"]
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### 环境匹配规则(含 range 范围匹配)
|
|
31
57
|
|
|
32
|
-
|
|
33
|
-
|----------|------|-----|--------|
|
|
34
|
-
| `test13` | 测试13(主测试环境) | `https://test13.xnzn.net/grafana` | test13, 13 |
|
|
35
|
-
| `monitor-test` | Monitor 测试环境 | `https://monitor-test.xnzn.net/grafana` | mtest |
|
|
36
|
-
| `monitor-dev` | Monitor 开发环境 | `https://monitor-dev.xnzn.net/grafana` | mdev, dev |
|
|
37
|
-
| `monitor02-dev` | Monitor02 开发环境 | `https://monitor02-dev.xnzn.net/grafana` | m02, monitor02 |
|
|
38
|
-
| `monitor-tyy-dev` | Monitor 体验园开发环境 | `https://monitor-tyy-dev.xnzn.net/grafana` | tyy, 体验园 |
|
|
58
|
+
用户说的话 → 匹配逻辑:
|
|
39
59
|
|
|
40
|
-
|
|
60
|
+
| 用户说法 | 匹配方式 | 结果 |
|
|
61
|
+
|---------|---------|------|
|
|
62
|
+
| "查 test13 的日志" | 精确匹配 key 或 aliases | `test13` 环境 |
|
|
63
|
+
| "去 dev10 查" | **range 匹配**:dev10 在 monitor-dev 的 projects 中 | `monitor-dev` 环境,`project="dev10"` |
|
|
64
|
+
| "去 monitor-dev 查" | 精确匹配 key | `monitor-dev` 环境 |
|
|
65
|
+
| "切到体验园" | aliases 匹配 | `monitor-tyy-dev` 环境 |
|
|
66
|
+
| 未指定环境 | 使用 `active` 字段 | 默认活跃环境 |
|
|
41
67
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
68
|
+
**range 匹配算法**:
|
|
69
|
+
```
|
|
70
|
+
1. 用户输入 "dev10"
|
|
71
|
+
2. 先精确匹配 key / aliases → 未命中
|
|
72
|
+
3. 遍历所有环境的 projects 列表,检查是否包含 "dev10"
|
|
73
|
+
4. 命中 → 使用该环境,并自动添加 project="dev10" 标签过滤
|
|
74
|
+
```
|
|
48
75
|
|
|
49
|
-
###
|
|
76
|
+
### 读取配置(含全局降级 + range 匹配)
|
|
50
77
|
|
|
51
78
|
```bash
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
echo "
|
|
79
|
+
# 按优先级查找配置文件
|
|
80
|
+
find_config() {
|
|
81
|
+
local PROJECT_DIR="${CLAUDE_PROJECT_DIR:-.}"
|
|
82
|
+
for f in \
|
|
83
|
+
"${PROJECT_DIR}/.claude/loki-config.json" \
|
|
84
|
+
"${PROJECT_DIR}/.claude/skills/loki-log-query/environments.json" \
|
|
85
|
+
"${HOME}/.claude/loki-config.json"; do
|
|
86
|
+
[ -f "$f" ] && echo "$f" && return
|
|
87
|
+
done
|
|
88
|
+
echo ""
|
|
62
89
|
}
|
|
63
90
|
|
|
64
|
-
|
|
91
|
+
ENV_FILE=$(find_config)
|
|
92
|
+
|
|
93
|
+
# 通过别名或 range 查找环境 key + project
|
|
65
94
|
find_env() {
|
|
66
95
|
python3 -c "
|
|
67
|
-
import json
|
|
96
|
+
import json, re
|
|
68
97
|
data = json.load(open('${ENV_FILE}'))
|
|
69
98
|
alias = '${1}'.lower()
|
|
99
|
+
# 1. 精确匹配 key 或 aliases
|
|
70
100
|
for key, env in data['environments'].items():
|
|
71
101
|
if alias == key or alias in env.get('aliases', []):
|
|
72
|
-
print(key)
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
102
|
+
print(f'{key}|') # key|project(project 为空)
|
|
103
|
+
exit()
|
|
104
|
+
# 2. range 匹配:在 projects 列表中查找
|
|
105
|
+
for key, env in data['environments'].items():
|
|
106
|
+
if alias in env.get('projects', []):
|
|
107
|
+
print(f'{key}|{alias}')
|
|
108
|
+
exit()
|
|
109
|
+
# 3. 未命中,返回默认
|
|
110
|
+
print(f'{data[\"active\"]}|')
|
|
76
111
|
"
|
|
77
112
|
}
|
|
113
|
+
|
|
114
|
+
# 使用示例:
|
|
115
|
+
# result=$(find_env "dev10")
|
|
116
|
+
# ENV_KEY=$(echo "$result" | cut -d'|' -f1) # monitor-dev
|
|
117
|
+
# PROJECT=$(echo "$result" | cut -d'|' -f2) # dev10
|
|
118
|
+
# 查询时:{app="yunshitang",project="${PROJECT}"}
|
|
78
119
|
```
|
|
79
120
|
|
|
80
|
-
### 切换活跃环境
|
|
121
|
+
### 切换活跃环境 / 更新 Token
|
|
81
122
|
|
|
82
123
|
```bash
|
|
83
|
-
# 切换默认环境为 monitor-dev
|
|
84
124
|
python3 -c "
|
|
85
125
|
import json
|
|
86
126
|
data = json.load(open('${ENV_FILE}'))
|
|
87
127
|
data['active'] = 'monitor-dev'
|
|
88
128
|
json.dump(data, open('${ENV_FILE}', 'w'), indent=2, ensure_ascii=False)
|
|
89
|
-
print('Switched to:', data['active'])
|
|
90
129
|
"
|
|
91
|
-
```
|
|
92
130
|
|
|
93
|
-
### 更新 Token
|
|
94
|
-
|
|
95
|
-
```bash
|
|
96
|
-
# 为某个环境设置 Token
|
|
97
131
|
python3 -c "
|
|
98
132
|
import json
|
|
99
133
|
data = json.load(open('${ENV_FILE}'))
|
|
100
|
-
data['environments']['monitor-dev']['token'] = 'glsa_
|
|
134
|
+
data['environments']['monitor-dev']['token'] = 'glsa_新token'
|
|
101
135
|
json.dump(data, open('${ENV_FILE}', 'w'), indent=2, ensure_ascii=False)
|
|
102
|
-
print('Token updated for monitor-dev')
|
|
103
136
|
"
|
|
104
137
|
```
|
|
105
138
|
|
|
@@ -27,22 +27,27 @@ description: |
|
|
|
27
27
|
|
|
28
28
|
---
|
|
29
29
|
|
|
30
|
-
##
|
|
30
|
+
## 连接信息获取(四级降级,自动查找)
|
|
31
31
|
|
|
32
32
|
当本技能被激活时,**按以下优先级获取数据库连接信息**:
|
|
33
33
|
|
|
34
34
|
### 优先级 1:用户对话中指定(最高优先级)
|
|
35
35
|
|
|
36
36
|
用户直接给出连接信息,或指定环境名:
|
|
37
|
-
- "连 dev 环境查一下" →
|
|
37
|
+
- "连 dev 环境查一下" → 使用配置中 dev 环境
|
|
38
|
+
- "去 dev10 查" → **范围匹配** dev 环境(range: "1~15")
|
|
38
39
|
- 直接给出 host/port/user/password → 直接使用
|
|
39
40
|
|
|
40
|
-
### 优先级 2
|
|
41
|
+
### 优先级 2:本地项目 `.claude/mysql-config.json`
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
**此文件为可选**,主要用于连接非本地环境(dev/prod 远程数据库)。
|
|
43
|
+
项目目录下的配置文件,优先于全局配置。
|
|
44
44
|
|
|
45
|
-
### 优先级 3
|
|
45
|
+
### 优先级 3:全局 `~/.claude/mysql-config.json`
|
|
46
|
+
|
|
47
|
+
全局配置文件(通过 `npx ai-engineering-init config --scope global` 创建),所有项目共享。
|
|
48
|
+
**推荐**:公司统一的数据库连接信息放全局,项目特定的覆盖放本地。
|
|
49
|
+
|
|
50
|
+
### 优先级 4:工程配置文件(零配置,本地开发默认)
|
|
46
51
|
|
|
47
52
|
从项目的 `bootstrap-dev.yml` 中自动提取连接信息:
|
|
48
53
|
|
|
@@ -107,43 +112,60 @@ brew install mysql-client
|
|
|
107
112
|
|
|
108
113
|
## 多环境支持
|
|
109
114
|
|
|
110
|
-
###
|
|
115
|
+
### 配置文件查找顺序
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
1. 本地项目:.claude/mysql-config.json
|
|
119
|
+
2. 全局配置:~/.claude/mysql-config.json
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
本地配置优先。如果本地无配置,使用全局。两者都存在时,本地覆盖全局(同名环境取本地值)。
|
|
111
123
|
|
|
112
|
-
|
|
124
|
+
### 配置文件结构(支持 range 范围匹配)
|
|
113
125
|
|
|
114
126
|
```json
|
|
115
127
|
{
|
|
116
128
|
"environments": {
|
|
117
|
-
"local": { "host": "127.0.0.1", "port": 3306, "user": "root", "password": "xxx" },
|
|
118
|
-
"dev": { "host": "dev-db.example.com", "port": 3306, "user": "dev_user", "password": "xxx" },
|
|
129
|
+
"local": { "host": "127.0.0.1", "port": 3306, "user": "root", "password": "xxx", "_desc": "本地环境" },
|
|
130
|
+
"dev": { "host": "dev-db.example.com", "port": 3306, "user": "dev_user", "password": "xxx", "range": "1~15", "_desc": "覆盖 dev1→dev15" },
|
|
131
|
+
"test": { "host": "test-db.example.com", "port": 3306, "user": "test_user", "password": "xxx", "range": "1~30", "_desc": "覆盖 test1→test30" },
|
|
119
132
|
"prod": { "host": "prod-db.example.com", "port": 3306, "user": "readonly", "password": "xxx" }
|
|
120
133
|
},
|
|
121
134
|
"default": "local"
|
|
122
135
|
}
|
|
123
136
|
```
|
|
124
137
|
|
|
138
|
+
### 环境范围匹配(range)
|
|
139
|
+
|
|
140
|
+
`range` 字段支持 `起始~结束` 格式,用于一个配置覆盖多个编号环境:
|
|
141
|
+
|
|
142
|
+
| 用户说法 | 匹配逻辑 | 结果 |
|
|
143
|
+
|---------|---------|------|
|
|
144
|
+
| "去 dev10 查" | 提取前缀 `dev`、编号 `10`,检查 dev 环境 range "1~15",10 在范围内 | 使用 dev 配置 |
|
|
145
|
+
| "连 test25" | 提取前缀 `test`、编号 `25`,检查 test 环境 range "1~30",25 在范围内 | 使用 test 配置 |
|
|
146
|
+
| "连 prod" | 精确匹配 prod 环境 | 使用 prod 配置 |
|
|
147
|
+
|
|
148
|
+
**匹配算法**:
|
|
149
|
+
```
|
|
150
|
+
1. 用户输入的环境名(如 "dev10")
|
|
151
|
+
2. 先精确匹配环境 key(environments["dev10"])
|
|
152
|
+
3. 未命中 → 拆分为前缀+编号("dev" + 10)
|
|
153
|
+
4. 查找有 range 字段的环境,前缀匹配 + 编号在范围内
|
|
154
|
+
5. 命中 → 使用该环境的 host/port/user/password
|
|
155
|
+
```
|
|
156
|
+
|
|
125
157
|
### 环境选择规则
|
|
126
158
|
|
|
127
159
|
| 优先级 | 来源 | 示例 |
|
|
128
160
|
|--------|------|------|
|
|
129
|
-
| 1(最高) | 用户对话中指定 | "连
|
|
161
|
+
| 1(最高) | 用户对话中指定 | "连 dev10 环境查一下" |
|
|
130
162
|
| 2 | 配置文件 `default` 字段 | `"default": "local"` |
|
|
131
163
|
|
|
132
|
-
### 环境关键词映射
|
|
133
|
-
|
|
134
|
-
用户说的话 → 对应环境名:
|
|
135
|
-
|
|
136
|
-
| 用户说法 | 环境 |
|
|
137
|
-
|---------|------|
|
|
138
|
-
| "本地"、"local"、"本地环境" | `local` |
|
|
139
|
-
| "开发"、"dev"、"测试环境"、"开发环境" | `dev` |
|
|
140
|
-
| "生产"、"prod"、"线上"、"正式环境" | `prod` |
|
|
141
|
-
|
|
142
164
|
### 连接示例
|
|
143
165
|
|
|
144
166
|
```bash
|
|
145
|
-
# 用户说"连
|
|
146
|
-
# →
|
|
167
|
+
# 用户说"连 dev10 环境查一下 order_info"
|
|
168
|
+
# → range 匹配到 dev 环境的连接信息 + 日志提取的数据库名
|
|
147
169
|
mysql -h dev-db.example.com -P 3306 -u dev_user -p'xxx' 546198574447230976 -e "SELECT ..."
|
|
148
170
|
```
|
|
149
171
|
|
package/README.md
CHANGED
|
@@ -27,6 +27,8 @@ npx ai-engineering-init --tool all # 全部
|
|
|
27
27
|
| `npx ai-engineering-init` | 交互式初始化到当前项目 |
|
|
28
28
|
| `npx ai-engineering-init@latest update` | 更新已安装的框架文件 |
|
|
29
29
|
| `npx ai-engineering-init@latest global` | 全局安装到 `~/.claude` 等,所有项目生效 |
|
|
30
|
+
| `npx ai-engineering-init config` | 初始化数据库连接 / Loki 日志配置(支持全局/本地/追加) |
|
|
31
|
+
| `npx ai-engineering-init mcp` | MCP 服务器管理(安装/卸载/状态) |
|
|
30
32
|
| `npx ai-engineering-init sync-back` | 对比本地技能修改,反馈回源仓库 |
|
|
31
33
|
|
|
32
34
|
> 所有命令均支持 `--tool <claude|cursor|codex|all>` 指定工具。运行 `--help` 查看全部选项。
|
package/bin/index.js
CHANGED
|
@@ -1350,12 +1350,23 @@ async function runMysqlConfig(ask, isGlobal) {
|
|
|
1350
1350
|
_comment: '环境支持 range 字段(如 "1~15"),用户说"dev10"时自动匹配。查找顺序:本地 .claude/ > 全局 ~/.claude/',
|
|
1351
1351
|
};
|
|
1352
1352
|
|
|
1353
|
+
const configJson = JSON.stringify(config, null, 2) + '\n';
|
|
1354
|
+
// 写入主路径
|
|
1353
1355
|
const dir = path.dirname(configPath);
|
|
1354
1356
|
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
1355
|
-
fs.writeFileSync(configPath,
|
|
1357
|
+
fs.writeFileSync(configPath, configJson, 'utf-8');
|
|
1356
1358
|
console.log(` ${fmt('green', '✔')} 已写入:${configPath}`);
|
|
1357
1359
|
|
|
1358
|
-
|
|
1360
|
+
// 全局模式:同时写入 ~/.cursor/(如果目录存在)
|
|
1361
|
+
if (isGlobal) {
|
|
1362
|
+
const cursorConfigPath = path.join(HOME_DIR, '.cursor', 'mysql-config.json');
|
|
1363
|
+
if (fs.existsSync(path.join(HOME_DIR, '.cursor'))) {
|
|
1364
|
+
fs.writeFileSync(cursorConfigPath, configJson, 'utf-8');
|
|
1365
|
+
console.log(` ${fmt('green', '✔')} 已同步:${cursorConfigPath}`);
|
|
1366
|
+
}
|
|
1367
|
+
} else {
|
|
1368
|
+
ensureGitignore(['mysql-config.json']);
|
|
1369
|
+
}
|
|
1359
1370
|
|
|
1360
1371
|
console.log('');
|
|
1361
1372
|
console.log(fmt('green', 'MySQL 数据库配置完成!'));
|
|
@@ -1540,11 +1551,22 @@ async function collectLokiEnvInput(ask, index, total) {
|
|
|
1540
1551
|
}
|
|
1541
1552
|
|
|
1542
1553
|
function writeLokiConfig(config, configPath, isGlobal) {
|
|
1554
|
+
const configJson = JSON.stringify(config, null, 2) + '\n';
|
|
1543
1555
|
const dir = path.dirname(configPath);
|
|
1544
1556
|
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
1545
|
-
fs.writeFileSync(configPath,
|
|
1557
|
+
fs.writeFileSync(configPath, configJson, 'utf-8');
|
|
1546
1558
|
console.log(` ${fmt('green', '✔')} 已写入:${configPath}`);
|
|
1547
|
-
|
|
1559
|
+
|
|
1560
|
+
// 全局模式:同时写入 ~/.cursor/(如果目录存在)
|
|
1561
|
+
if (isGlobal) {
|
|
1562
|
+
const cursorConfigPath = path.join(HOME_DIR, '.cursor', 'loki-config.json');
|
|
1563
|
+
if (fs.existsSync(path.join(HOME_DIR, '.cursor'))) {
|
|
1564
|
+
fs.writeFileSync(cursorConfigPath, configJson, 'utf-8');
|
|
1565
|
+
console.log(` ${fmt('green', '✔')} 已同步:${cursorConfigPath}`);
|
|
1566
|
+
}
|
|
1567
|
+
} else {
|
|
1568
|
+
ensureGitignore(['loki-config.json', 'environments.json']);
|
|
1569
|
+
}
|
|
1548
1570
|
console.log('');
|
|
1549
1571
|
console.log(fmt('green', 'Loki 日志查询配置完成!'));
|
|
1550
1572
|
}
|