@optima-chat/dev-skills 0.7.4 → 0.7.6

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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  快速查看服务日志,支持 CI/Stage/Prod 三个环境。
4
4
 
5
- **版本**: v0.2.0
5
+ **版本**: v0.3.0
6
6
 
7
7
  ## 使用场景
8
8
 
@@ -19,25 +19,32 @@
19
19
  ## 参数
20
20
 
21
21
  - `service` (必需): 服务名称
22
- - `commerce-backend` - 电商后端
23
- - `user-auth` - 用户认证
24
- - `mcp-host` - MCP 协调器
22
+ - `commerce-backend` - 电商后端 API
23
+ - `user-auth` - 用户认证服务
24
+ - `user-auth-admin` - 用户认证管理后台
25
25
  - `agentic-chat` - AI 聊天服务
26
- - `commerce-mcp` - 电商 MCP 服务
27
- - `comfy-mcp` - ComfyUI MCP 服务
26
+ - `bi-backend` - BI 后端
27
+ - `bi-dashboard` - BI 仪表板
28
+ - `session-gateway` - AI Shell 网关
29
+ - `ai-shell-web-ui` - Shell Web UI
30
+ - `optima-scout` - 产品研究工具
31
+ - `optima-store` - 商城前端(仅 Stage)
32
+ - `commerce-rq-worker` - RQ 后台任务
33
+ - `commerce-rq-scheduler` - RQ 定时调度
28
34
  - `lines` (可选): 显示行数,默认 50
29
35
  - `environment` (可选): 环境,默认 ci
30
36
  - `ci` - CI 持续集成环境(开发环境,默认)
31
- - `stage` - Stage 预发布环境
32
- - `prod` - 生产环境
37
+ - `stage` - Stage 预发布环境(ECS Fargate)
38
+ - `prod` - 生产环境(ECS Fargate)
33
39
 
34
40
  ## 示例
35
41
 
36
42
  ```bash
37
43
  /logs commerce-backend # 查看 CI 环境最近 50 行(默认)
38
44
  /logs user-auth 100 # 查看 CI 环境最近 100 行(默认)
39
- /logs mcp-host 200 stage # 查看 Stage 环境最近 200 行
45
+ /logs agentic-chat 200 stage # 查看 Stage 环境最近 200 行
40
46
  /logs user-auth 100 prod # 查看 Prod 环境最近 100 行
47
+ /logs session-gateway 50 prod # 查看 Prod AI Shell 网关日志
41
48
  ```
42
49
 
43
50
  ## 特殊参数处理
@@ -49,7 +56,7 @@
49
56
  **重要提示**:根据用户指定的 `environment` 参数选择执行方式:
50
57
  - `ci` 或未指定 → 使用 SSH + Docker Compose(第 0 节,默认)
51
58
  - `stage` → 使用 AWS CloudWatch Logs - ECS(第 1 节)
52
- - `prod` → 使用 AWS CloudWatch Logs - EC2(第 2 节)
59
+ - `prod` → 使用 AWS CloudWatch Logs - ECS(第 2 节)
53
60
 
54
61
  ### 0. CI 环境(environment = "ci" 或默认)
55
62
 
@@ -71,10 +78,7 @@ sshpass -p "$CI_PASSWORD" ssh -o StrictHostKeyChecking=no ${CI_USER}@${CI_HOST}
71
78
  **服务映射**(路径 + docker compose 服务名):
72
79
  - `commerce-backend` → `/data/xuhao/commerce-backend` → `commerce-backend`
73
80
  - `user-auth` → `/data/xuhao/user-auth` → `user-auth`
74
- - `mcp-host` → `/data/xuhao/mcp-host` → `app`
75
81
  - `agentic-chat` → `/data/xuhao/agentic-chat` → `optima-ai-chat`
76
- - `commerce-mcp` → `/data/xuhao/actions-runner/_work/commerce-mcp/commerce-mcp` → `commerce-mcp`
77
- - `comfy-mcp` → `/data/xuhao/actions-runner/_work/comfy-mcp/comfy-mcp` → `comfy-mcp`
78
82
 
79
83
  **完整命令示例**(先获取配置):
80
84
  ```bash
@@ -89,21 +93,13 @@ sshpass -p "$CI_PASSWORD" ssh -o StrictHostKeyChecking=no ${CI_USER}@${CI_HOST}
89
93
  # user-auth
90
94
  sshpass -p "$CI_PASSWORD" ssh -o StrictHostKeyChecking=no ${CI_USER}@${CI_HOST} "cd /data/xuhao/user-auth && docker compose logs --tail 50 user-auth"
91
95
 
92
- # mcp-host
93
- sshpass -p "$CI_PASSWORD" ssh -o StrictHostKeyChecking=no ${CI_USER}@${CI_HOST} "cd /data/xuhao/mcp-host && docker compose logs --tail 50 app"
94
-
95
96
  # agentic-chat
96
97
  sshpass -p "$CI_PASSWORD" ssh -o StrictHostKeyChecking=no ${CI_USER}@${CI_HOST} "cd /data/xuhao/agentic-chat && docker compose logs --tail 50 optima-ai-chat"
97
-
98
- # commerce-mcp (via actions-runner)
99
- sshpass -p "$CI_PASSWORD" ssh -o StrictHostKeyChecking=no ${CI_USER}@${CI_HOST} "cd /data/xuhao/actions-runner/_work/commerce-mcp/commerce-mcp && docker compose logs --tail 50 commerce-mcp"
100
-
101
- # comfy-mcp (via actions-runner)
102
- sshpass -p "$CI_PASSWORD" ssh -o StrictHostKeyChecking=no ${CI_USER}@${CI_HOST} "cd /data/xuhao/actions-runner/_work/comfy-mcp/comfy-mcp && docker compose logs --tail 50 comfy-mcp"
103
98
  ```
104
99
 
105
100
  ### 1. Stage 环境(environment = "stage")
106
101
 
102
+ **部署方式**: ECS Fargate(Fargate Spot 降低成本)
107
103
  **日志路径格式**: `/ecs/{service}-stage`
108
104
 
109
105
  **步骤**:
@@ -120,54 +116,56 @@ aws logs get-log-events --log-group-name /ecs/commerce-backend-stage --log-strea
120
116
  **服务映射**:
121
117
  - `commerce-backend` → `/ecs/commerce-backend-stage`
122
118
  - `user-auth` → `/ecs/user-auth-stage`
123
- - `mcp-host` → `/ecs/mcp-host-stage`
119
+ - `user-auth-admin` → `/ecs/user-auth-admin-stage`
124
120
  - `agentic-chat` → `/ecs/agentic-chat-stage`
125
- - `commerce-mcp` → `/ecs/commerce-mcp-stage`
126
- - `comfy-mcp` → `/ecs/comfy-mcp-stage`
121
+ - `bi-backend` → `/ecs/bi-backend-stage`
122
+ - `bi-dashboard` → `/ecs/bi-dashboard-stage`
123
+ - `session-gateway` → `/ecs/session-gateway-stage`
124
+ - `ai-shell-web-ui` → `/ecs/ai-shell-web-ui-stage`
125
+ - `optima-scout` → `/ecs/optima-scout-stage`
126
+ - `optima-store` → `/ecs/optima-store-stage`
127
+ - `commerce-rq-worker` → `/ecs/commerce-rq-worker-stage`
128
+ - `commerce-rq-scheduler` → `/ecs/commerce-rq-scheduler-stage`
127
129
 
128
130
  ### 2. Prod 环境(environment = "prod")
129
131
 
130
- **日志路径格式**: `/optima/prod/{service}` `/optima/prod/ec2-1az/{service}`
132
+ **部署方式**: ECS Fargate(核心服务标准 Fargate,非核心服务 Fargate Spot)
133
+ **日志路径格式**: `/ecs/{service}-prod`
131
134
 
132
135
  **IMPORTANT**: Prod 环境必须指定 `--region ap-southeast-1`
133
136
 
134
137
  **推荐方式(使用 aws logs tail)**:
135
138
  ```bash
136
- # 查看最近 1 小时的日志
137
- aws logs tail /optima/prod/commerce-backend --since 1h --region ap-southeast-1
139
+ # 查看最近日志(实时跟踪)
140
+ aws logs tail /ecs/commerce-backend-prod --since 1h --region ap-southeast-1
138
141
 
139
- # 查看 MCP 服务日志(ec2-1az 路径)
140
- aws logs tail /optima/prod/ec2-1az/commerce-mcp --since 1h --region ap-southeast-1
142
+ # 过滤错误日志
143
+ aws logs tail /ecs/user-auth-prod --filter-pattern "ERROR" --region ap-southeast-1
141
144
  ```
142
145
 
143
146
  **备用方式(使用 get-log-events)**:
144
147
  ```bash
145
- # 获取日志内容(纯文本)
146
- # IMPORTANT: 必须使用单行命令,不要使用反斜杠换行
147
- aws logs get-log-events --log-group-name /optima/prod/commerce-backend --log-stream-name backend --limit 50 --no-start-from-head --region ap-southeast-1 | jq -r '.events[] | .message'
148
+ # 1. 获取最新的 log stream(ECS Task ID 是动态的)
149
+ STREAM=$(aws logs describe-log-streams --log-group-name /ecs/commerce-backend-prod --order-by LastEventTime --descending --max-items 1 --region ap-southeast-1 | jq -r '.logStreams[0].logStreamName')
150
+
151
+ # 2. 获取日志内容(纯文本)
152
+ aws logs get-log-events --log-group-name /ecs/commerce-backend-prod --log-stream-name "$STREAM" --limit 50 --region ap-southeast-1 | jq -r '.events[] | .message'
148
153
  ```
149
154
 
150
155
  **服务映射**:
151
- - `commerce-backend` → `/optima/prod/commerce-backend`
152
- - `user-auth` → `/optima/prod/user-auth`
153
- - `mcp-host` → `/optima/prod/mcp-host`
154
- - `agentic-chat` → `/optima/prod/agentic-chat`
155
- - `commerce-mcp` → `/optima/prod/ec2-1az/commerce-mcp`
156
- - `comfy-mcp` → `/optima/prod/ec2-1az/comfy-mcp`
157
- - `fetch-mcp` → `/optima/prod/ec2-1az/fetch-mcp`
158
- - `shopify-mcp` → `/optima/prod/ec2-1az/shopify-mcp`
159
- - `perplexity-mcp` → `/optima/prod/ec2-1az/perplexity-mcp`
160
- - `google-ads-mcp` → `/optima/prod/ec2-1az/google-ads-mcp`
161
-
162
- **Log Stream 名称**:
163
- - `backend` - 主服务日志
164
- - `rq-worker` - 后台任务日志
165
- - `rq-scheduler` - 调度器日志
166
-
167
- **注意**:
168
- - MCP 服务部署在 EC2 (ec2-1az),日志路径为 `/optima/prod/ec2-1az/{service}`
169
- - 核心服务(commerce-backend、user-auth 等)日志路径为 `/optima/prod/{service}`
170
- - **必须指定 `--region ap-southeast-1`**
156
+ - `commerce-backend` → `/ecs/commerce-backend-prod`
157
+ - `user-auth` → `/ecs/user-auth-prod`
158
+ - `user-auth-admin` → `/ecs/user-auth-admin-prod`
159
+ - `agentic-chat` → `/ecs/agentic-chat-prod`
160
+ - `bi-backend` → `/ecs/bi-backend-prod`
161
+ - `bi-dashboard` → `/ecs/bi-dashboard-prod`
162
+ - `session-gateway` → `/ecs/session-gateway-prod`
163
+ - `ai-shell-web-ui` → `/ecs/ai-shell-web-ui-prod`
164
+ - `optima-scout` → `/ecs/optima-scout-prod`
165
+ - `commerce-rq-worker` → `/ecs/commerce-rq-worker-prod`
166
+ - `commerce-rq-scheduler` → `/ecs/commerce-rq-scheduler-prod`
167
+
168
+ **注意**: `optima-store` 仅在 Stage 环境部署
171
169
 
172
170
  ## 完整示例脚本
173
171
 
@@ -185,14 +183,13 @@ aws logs get-log-events --log-group-name /ecs/${SERVICE}-stage --log-stream-name
185
183
  ### Prod 环境
186
184
  ```bash
187
185
  # 推荐方式:使用 aws logs tail
188
- # 核心服务
189
- aws logs tail /optima/prod/commerce-backend --since 1h --region ap-southeast-1
190
-
191
- # MCP 服务(ec2-1az 路径)
192
- aws logs tail /optima/prod/ec2-1az/commerce-mcp --since 1h --region ap-southeast-1
186
+ aws logs tail /ecs/commerce-backend-prod --since 1h --region ap-southeast-1
193
187
 
194
- # 备用方式:使用 get-log-events
195
- aws logs get-log-events --log-group-name /optima/prod/commerce-backend --log-stream-name backend --limit 50 --no-start-from-head --region ap-southeast-1 | jq -r '.events[] | .message'
188
+ # 备用方式:使用 get-log-events(获取指定行数)
189
+ SERVICE="commerce-backend"
190
+ LINES=50
191
+ STREAM=$(aws logs describe-log-streams --log-group-name /ecs/${SERVICE}-prod --order-by LastEventTime --descending --max-items 1 --region ap-southeast-1 | jq -r '.logStreams[0].logStreamName')
192
+ aws logs get-log-events --log-group-name /ecs/${SERVICE}-prod --log-stream-name "$STREAM" --limit $LINES --region ap-southeast-1 | jq -r '.events[] | .message'
196
193
  ```
197
194
 
198
195
  ## 常见错误处理
@@ -204,8 +201,7 @@ aws logs get-log-events --log-group-name /optima/prod/commerce-backend --log-str
204
201
  **解决**:
205
202
  ```bash
206
203
  # 列出所有可用的日志组
207
- aws logs describe-log-groups --log-group-name-prefix /ecs
208
- aws logs describe-log-groups --log-group-name-prefix /optima/prod
204
+ aws logs describe-log-groups --log-group-name-prefix /ecs --region ap-southeast-1
209
205
  ```
210
206
 
211
207
  ### 错误:No log streams found
@@ -222,10 +218,10 @@ aws logs describe-log-streams \
222
218
 
223
219
  ## 注意事项
224
220
 
225
- 1. **Stage 环境**: log stream 名称是动态的(ECS Task ID),需要先查询最新的 stream
226
- 2. **Prod 环境**: log stream 通常是固定的 `backend`、`rq-worker`
227
- 3. **日志延迟**: CloudWatch Logs 可能有 1-2 秒延迟
228
- 4. **权限要求**: 需要 AWS CLI 配置了正确的凭证和权限
221
+ 1. **Stage/Prod 环境**: log stream 名称是动态的(ECS Task ID),需要先查询最新的 stream
222
+ 2. **日志延迟**: CloudWatch Logs 可能有 1-2 秒延迟
223
+ 3. **权限要求**: 需要 AWS CLI 配置了正确的凭证和权限
224
+ 4. **日志保留**: Stage Prod 环境日志保留 7 天
229
225
 
230
226
  ## 相关资源
231
227
 
@@ -32,7 +32,8 @@
32
32
  "Bash(curl -s https://auth.optima.chat/openapi.json)",
33
33
  "Bash(cat:*)",
34
34
  "Bash(node /Users/verypro/optima-dev-skills/scripts/install.js:*)",
35
- "Bash(aws logs tail:*)"
35
+ "Bash(aws logs tail:*)",
36
+ "Bash(grep:*)"
36
37
  ],
37
38
  "deny": [],
38
39
  "ask": []
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: "logs"
3
- description: "当用户请求查看日志、查看服务日志、排查问题、看看日志、检查日志、商品服务日志、后端日志、API日志、正式环境日志、生产环境日志、CI环境日志、开发环境日志、MCP日志时,使用此技能。支持 CI、Stage、Prod 三个环境的 commerce-backend、user-auth、mcp-host、agentic-chat、commerce-mcpcomfy-mcp 服务。"
3
+ description: "当用户请求查看日志、查看服务日志、排查问题、看看日志、检查日志、商品服务日志、后端日志、API日志、正式环境日志、生产环境日志、CI环境日志、开发环境日志时,使用此技能。支持 CI、Stage、Prod 三个环境的 commerce-backend、user-auth、agentic-chat、bi-backendsession-gateway 等服务。"
4
4
  allowed-tools: ["Bash", "SlashCommand"]
5
5
  ---
6
6
 
@@ -8,14 +8,14 @@ allowed-tools: ["Bash", "SlashCommand"]
8
8
 
9
9
  当你需要查看服务日志排查问题时,使用这个场景。
10
10
 
11
- ## 🎯 适用情况
11
+ ## 适用情况
12
12
 
13
13
  - API 返回错误,需要查看详细错误信息
14
14
  - 服务行为异常,需要查看运行日志
15
15
  - 监控服务状态,查看日志输出
16
16
  - 排查数据库连接、配置问题
17
17
 
18
- ## 🚀 快速操作
18
+ ## 快速操作
19
19
 
20
20
  ### 1. 查看 CI 环境日志(默认)
21
21
 
@@ -38,15 +38,14 @@ allowed-tools: ["Bash", "SlashCommand"]
38
38
 
39
39
  **说明**:
40
40
  - 查看 Stage 预发布环境
41
- - 使用 AWS CloudWatch Logs
41
+ - 使用 AWS CloudWatch Logs(ECS Fargate)
42
42
 
43
43
  **常用服务**:
44
44
  - `commerce-backend` - 电商 API
45
45
  - `user-auth` - 用户认证
46
- - `mcp-host` - MCP 协调器
47
46
  - `agentic-chat` - AI 聊天服务
48
- - `commerce-mcp` - 电商 MCP 服务
49
- - `comfy-mcp` - ComfyUI MCP 服务
47
+ - `bi-backend` - BI 后端
48
+ - `session-gateway` - AI Shell 网关
50
49
 
51
50
  ### 3. 查看更多日志行数
52
51
 
@@ -62,9 +61,9 @@ allowed-tools: ["Bash", "SlashCommand"]
62
61
  /logs commerce-backend 100 prod
63
62
  ```
64
63
 
65
- 查看生产环境日志(通过 AWS CloudWatch)。
64
+ 查看生产环境日志(通过 AWS CloudWatch,ECS Fargate)。
66
65
 
67
- ## 📋 常见问题排查
66
+ ## 常见问题排查
68
67
 
69
68
  ### 问题 1:API 返回 500 错误
70
69
 
@@ -115,7 +114,7 @@ INFO - GET /products - response_time: 3500ms (SLOW)
115
114
  INFO - Database query took 3200ms: SELECT * FROM products WHERE...
116
115
  ```
117
116
 
118
- ## 🔍 日志分析技巧
117
+ ## 日志分析技巧
119
118
 
120
119
  ### 过滤关键信息
121
120
 
@@ -140,7 +139,7 @@ INFO - Database query took 3200ms: SELECT * FROM products WHERE...
140
139
  - **INFO** - 信息,正常运行日志
141
140
  - **DEBUG** - 调试信息,详细输出
142
141
 
143
- ## 🌐 环境对比
142
+ ## 环境对比
144
143
 
145
144
  ### CI 环境
146
145
 
@@ -161,7 +160,7 @@ INFO - Database query took 3200ms: SELECT * FROM products WHERE...
161
160
 
162
161
  **特点**:
163
162
  - 预发布环境
164
- - AWS ECS 运行
163
+ - AWS ECS Fargate 运行(Fargate Spot)
165
164
  - 通过 CloudWatch Logs 查看
166
165
 
167
166
  ### Prod 环境
@@ -172,10 +171,28 @@ INFO - Database query took 3200ms: SELECT * FROM products WHERE...
172
171
 
173
172
  **特点**:
174
173
  - 生产环境
175
- - EC2 + Docker Compose
174
+ - AWS ECS Fargate 运行
176
175
  - 通过 CloudWatch Logs 查看
177
-
178
- ## 💡 最佳实践
176
+ - 日志保留 7 天
177
+
178
+ ## 支持的服务列表
179
+
180
+ | 服务 | 说明 | CI | Stage | Prod |
181
+ |------|------|:--:|:-----:|:----:|
182
+ | `commerce-backend` | 电商后端 API | ✓ | ✓ | ✓ |
183
+ | `user-auth` | 用户认证服务 | ✓ | ✓ | ✓ |
184
+ | `user-auth-admin` | 认证管理后台 | - | ✓ | ✓ |
185
+ | `agentic-chat` | AI 聊天服务 | ✓ | ✓ | ✓ |
186
+ | `bi-backend` | BI 后端 | - | ✓ | ✓ |
187
+ | `bi-dashboard` | BI 仪表板 | - | ✓ | ✓ |
188
+ | `session-gateway` | AI Shell 网关 | - | ✓ | ✓ |
189
+ | `ai-shell-web-ui` | Shell Web UI | - | ✓ | ✓ |
190
+ | `optima-scout` | 产品研究工具 | - | ✓ | ✓ |
191
+ | `optima-store` | 商城前端 | - | ✓ | - |
192
+ | `commerce-rq-worker` | RQ 后台任务 | - | ✓ | ✓ |
193
+ | `commerce-rq-scheduler` | RQ 定时调度 | - | ✓ | ✓ |
194
+
195
+ ## 最佳实践
179
196
 
180
197
  1. **先查日志,再动手修** - 不要猜测,看日志确认问题
181
198
  2. **查足够多的行数** - 有时错误原因在更早的日志里
@@ -183,6 +200,6 @@ INFO - Database query took 3200ms: SELECT * FROM products WHERE...
183
200
  4. **保留错误日志** - 复制错误信息,方便分享讨论
184
201
  5. **对比环境差异** - Stage 出错、Prod 正常?对比日志差异
185
202
 
186
- ## 🔗 相关命令
203
+ ## 相关命令
187
204
 
188
205
  - `/logs` - 查看服务日志(详细使用方法和技术细节请查看 `/logs --help`)
@@ -102,16 +102,59 @@ function setupSSHTunnel(ec2Host: string, dbHost: string, localPort: number): voi
102
102
  console.log(`✓ SSH tunnel established on port ${localPort}`);
103
103
  }
104
104
 
105
- function queryDatabase(host: string, port: number, user: string, password: string, database: string, sql: string): string {
106
- const psqlPath = '/usr/local/opt/postgresql@16/bin/psql';
105
+ function findPsqlPath(): string {
106
+ // 1. 优先从 PATH 中查找
107
+ const whichCmd = process.platform === 'win32' ? 'where psql' : 'which psql';
108
+ try {
109
+ const result = execSync(whichCmd, { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'ignore'] });
110
+ const foundPath = result.trim().split(/\r?\n/)[0]; // Windows where 可能返回 \r\n
111
+ if (foundPath && fs.existsSync(foundPath)) {
112
+ return foundPath;
113
+ }
114
+ } catch {
115
+ // which/where 失败,继续尝试常见路径
116
+ }
107
117
 
108
- if (!fs.existsSync(psqlPath)) {
109
- throw new Error('PostgreSQL client not found. Install with: brew install postgresql@16');
118
+ // 2. 回退到常见安装路径
119
+ const fallbackPaths = process.platform === 'win32'
120
+ ? [
121
+ 'C:\\Program Files\\PostgreSQL\\16\\bin\\psql.exe',
122
+ 'C:\\Program Files\\PostgreSQL\\15\\bin\\psql.exe',
123
+ 'C:\\Program Files\\PostgreSQL\\14\\bin\\psql.exe',
124
+ ]
125
+ : [
126
+ '/usr/local/opt/postgresql@16/bin/psql', // macOS Homebrew
127
+ '/usr/local/opt/postgresql@15/bin/psql',
128
+ '/opt/homebrew/bin/psql', // macOS ARM Homebrew
129
+ '/usr/bin/psql', // Linux
130
+ '/usr/local/bin/psql',
131
+ ];
132
+
133
+ for (const p of fallbackPaths) {
134
+ if (fs.existsSync(p)) {
135
+ return p;
136
+ }
110
137
  }
111
138
 
139
+ // 3. 未找到
140
+ const installHint = process.platform === 'darwin'
141
+ ? 'brew install postgresql@16'
142
+ : process.platform === 'win32'
143
+ ? 'Download from https://www.postgresql.org/download/windows/'
144
+ : 'sudo apt install postgresql-client';
145
+
146
+ throw new Error(`PostgreSQL client (psql) not found. Install with: ${installHint}`);
147
+ }
148
+
149
+ function queryDatabase(host: string, port: number, user: string, password: string, database: string, sql: string): string {
150
+ const psqlPath = findPsqlPath();
151
+
112
152
  const result = execSync(
113
- `PGPASSWORD="${password}" ${psqlPath} -h ${host} -p ${port} -U ${user} -d ${database} -c "${sql}"`,
114
- { encoding: 'utf-8' }
153
+ `"${psqlPath}" -h ${host} -p ${port} -U ${user} -d ${database} -c "${sql}"`,
154
+ {
155
+ encoding: 'utf-8',
156
+ env: { ...process.env, PGPASSWORD: password }
157
+ }
115
158
  );
116
159
  return result;
117
160
  }
@@ -104,12 +104,52 @@ function setupSSHTunnel(ec2Host, dbHost, localPort) {
104
104
  (0, child_process_1.execSync)(`ssh -i ${sshKeyPath} -f -N -o StrictHostKeyChecking=no -L ${localPort}:${dbHost}:5432 ec2-user@${ec2Host}`, { stdio: 'inherit' });
105
105
  console.log(`✓ SSH tunnel established on port ${localPort}`);
106
106
  }
107
- function queryDatabase(host, port, user, password, database, sql) {
108
- const psqlPath = '/usr/local/opt/postgresql@16/bin/psql';
109
- if (!fs.existsSync(psqlPath)) {
110
- throw new Error('PostgreSQL client not found. Install with: brew install postgresql@16');
107
+ function findPsqlPath() {
108
+ // 1. 优先从 PATH 中查找
109
+ const whichCmd = process.platform === 'win32' ? 'where psql' : 'which psql';
110
+ try {
111
+ const result = (0, child_process_1.execSync)(whichCmd, { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'ignore'] });
112
+ const foundPath = result.trim().split(/\r?\n/)[0]; // Windows where 可能返回 \r\n
113
+ if (foundPath && fs.existsSync(foundPath)) {
114
+ return foundPath;
115
+ }
116
+ }
117
+ catch {
118
+ // which/where 失败,继续尝试常见路径
111
119
  }
112
- const result = (0, child_process_1.execSync)(`PGPASSWORD="${password}" ${psqlPath} -h ${host} -p ${port} -U ${user} -d ${database} -c "${sql}"`, { encoding: 'utf-8' });
120
+ // 2. 回退到常见安装路径
121
+ const fallbackPaths = process.platform === 'win32'
122
+ ? [
123
+ 'C:\\Program Files\\PostgreSQL\\16\\bin\\psql.exe',
124
+ 'C:\\Program Files\\PostgreSQL\\15\\bin\\psql.exe',
125
+ 'C:\\Program Files\\PostgreSQL\\14\\bin\\psql.exe',
126
+ ]
127
+ : [
128
+ '/usr/local/opt/postgresql@16/bin/psql', // macOS Homebrew
129
+ '/usr/local/opt/postgresql@15/bin/psql',
130
+ '/opt/homebrew/bin/psql', // macOS ARM Homebrew
131
+ '/usr/bin/psql', // Linux
132
+ '/usr/local/bin/psql',
133
+ ];
134
+ for (const p of fallbackPaths) {
135
+ if (fs.existsSync(p)) {
136
+ return p;
137
+ }
138
+ }
139
+ // 3. 未找到
140
+ const installHint = process.platform === 'darwin'
141
+ ? 'brew install postgresql@16'
142
+ : process.platform === 'win32'
143
+ ? 'Download from https://www.postgresql.org/download/windows/'
144
+ : 'sudo apt install postgresql-client';
145
+ throw new Error(`PostgreSQL client (psql) not found. Install with: ${installHint}`);
146
+ }
147
+ function queryDatabase(host, port, user, password, database, sql) {
148
+ const psqlPath = findPsqlPath();
149
+ const result = (0, child_process_1.execSync)(`"${psqlPath}" -h ${host} -p ${port} -U ${user} -d ${database} -c "${sql}"`, {
150
+ encoding: 'utf-8',
151
+ env: { ...process.env, PGPASSWORD: password }
152
+ });
113
153
  return result;
114
154
  }
115
155
  async function main() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optima-chat/dev-skills",
3
- "version": "0.7.4",
3
+ "version": "0.7.6",
4
4
  "description": "Claude Code Skills for Optima development team - cross-environment collaboration tools",
5
5
  "main": "index.js",
6
6
  "bin": {