postgresai 0.12.0-beta.7 → 0.14.0-beta.10
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 +154 -53
- package/bin/postgres-ai.ts +1572 -350
- package/bun.lock +258 -0
- package/bunfig.toml +20 -0
- package/dist/bin/postgres-ai.js +28575 -1487
- package/dist/sql/01.role.sql +16 -0
- package/dist/sql/02.permissions.sql +37 -0
- package/dist/sql/03.optional_rds.sql +6 -0
- package/dist/sql/04.optional_self_managed.sql +8 -0
- package/dist/sql/05.helpers.sql +439 -0
- package/dist/sql/sql/01.role.sql +16 -0
- package/dist/sql/sql/02.permissions.sql +37 -0
- package/dist/sql/sql/03.optional_rds.sql +6 -0
- package/dist/sql/sql/04.optional_self_managed.sql +8 -0
- package/dist/sql/sql/05.helpers.sql +439 -0
- package/lib/auth-server.ts +124 -106
- package/lib/checkup-api.ts +386 -0
- package/lib/checkup.ts +1330 -0
- package/lib/config.ts +6 -3
- package/lib/init.ts +760 -0
- package/lib/issues.ts +400 -191
- package/lib/mcp-server.ts +213 -90
- package/lib/metrics-embedded.ts +79 -0
- package/lib/metrics-loader.ts +127 -0
- package/lib/util.ts +61 -0
- package/package.json +20 -9
- package/packages/postgres-ai/README.md +26 -0
- package/packages/postgres-ai/bin/postgres-ai.js +27 -0
- package/packages/postgres-ai/package.json +27 -0
- package/scripts/embed-metrics.ts +154 -0
- package/sql/01.role.sql +16 -0
- package/sql/02.permissions.sql +37 -0
- package/sql/03.optional_rds.sql +6 -0
- package/sql/04.optional_self_managed.sql +8 -0
- package/sql/05.helpers.sql +439 -0
- package/test/auth.test.ts +258 -0
- package/test/checkup.integration.test.ts +321 -0
- package/test/checkup.test.ts +891 -0
- package/test/init.integration.test.ts +499 -0
- package/test/init.test.ts +417 -0
- package/test/issues.cli.test.ts +314 -0
- package/test/issues.test.ts +456 -0
- package/test/mcp-server.test.ts +988 -0
- package/test/schema-validation.test.ts +81 -0
- package/test/test-utils.ts +122 -0
- package/tsconfig.json +12 -20
- package/dist/bin/postgres-ai.d.ts +0 -3
- package/dist/bin/postgres-ai.d.ts.map +0 -1
- package/dist/bin/postgres-ai.js.map +0 -1
- package/dist/lib/auth-server.d.ts +0 -31
- package/dist/lib/auth-server.d.ts.map +0 -1
- package/dist/lib/auth-server.js +0 -263
- package/dist/lib/auth-server.js.map +0 -1
- package/dist/lib/config.d.ts +0 -45
- package/dist/lib/config.d.ts.map +0 -1
- package/dist/lib/config.js +0 -181
- package/dist/lib/config.js.map +0 -1
- package/dist/lib/issues.d.ts +0 -75
- package/dist/lib/issues.d.ts.map +0 -1
- package/dist/lib/issues.js +0 -336
- package/dist/lib/issues.js.map +0 -1
- package/dist/lib/mcp-server.d.ts +0 -9
- package/dist/lib/mcp-server.d.ts.map +0 -1
- package/dist/lib/mcp-server.js +0 -168
- package/dist/lib/mcp-server.js.map +0 -1
- package/dist/lib/pkce.d.ts +0 -32
- package/dist/lib/pkce.d.ts.map +0 -1
- package/dist/lib/pkce.js +0 -101
- package/dist/lib/pkce.js.map +0 -1
- package/dist/lib/util.d.ts +0 -27
- package/dist/lib/util.d.ts.map +0 -1
- package/dist/lib/util.js +0 -46
- package/dist/lib/util.js.map +0 -1
- package/dist/package.json +0 -45
package/README.md
CHANGED
|
@@ -10,11 +10,13 @@ Command-line interface for PostgresAI monitoring and database management.
|
|
|
10
10
|
npm install -g postgresai
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
Or install the latest
|
|
13
|
+
Or install the latest beta release explicitly:
|
|
14
14
|
```bash
|
|
15
|
-
npm install -g postgresai@
|
|
15
|
+
npm install -g postgresai@beta
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
+
Note: in this repository, `cli/package.json` uses a placeholder version (`0.0.0-dev.0`). The real published version is set by the git tag in CI when publishing to npm.
|
|
19
|
+
|
|
18
20
|
### From Homebrew (macOS)
|
|
19
21
|
|
|
20
22
|
```bash
|
|
@@ -27,11 +29,82 @@ brew install postgresai
|
|
|
27
29
|
|
|
28
30
|
## Usage
|
|
29
31
|
|
|
30
|
-
The
|
|
32
|
+
The `postgresai` package provides two command aliases:
|
|
33
|
+
```bash
|
|
34
|
+
postgresai --help # Canonical, discoverable
|
|
35
|
+
pgai --help # Short and convenient
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
You can also run it without installing via `npx`:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npx postgresai --help
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Optional shorthand: `pgai`
|
|
45
|
+
|
|
46
|
+
If you want `npx pgai ...` as a shorthand for `npx postgresai ...`, install the separate `pgai` wrapper package:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npx pgai --help
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## prepare-db (create monitoring user in Postgres)
|
|
53
|
+
|
|
54
|
+
This command creates (or updates) the `postgres_ai_mon` user, creates the required view(s), and grants the permissions described in the root `README.md` (it is idempotent). Where supported, it also enables observability extensions described there.
|
|
55
|
+
|
|
56
|
+
Run without installing (positional connection string):
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npx postgresai prepare-db postgresql://admin@host:5432/dbname
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
It also accepts libpq "conninfo" syntax:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
npx postgresai prepare-db "dbname=dbname host=host user=admin"
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
And psql-like options:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
npx postgresai prepare-db -h host -p 5432 -U admin -d dbname
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Password input options (in priority order):
|
|
75
|
+
- `--password <password>`
|
|
76
|
+
- `PGAI_MON_PASSWORD` environment variable
|
|
77
|
+
- if not provided: a strong password is generated automatically
|
|
78
|
+
|
|
79
|
+
By default, the generated password is printed **only in interactive (TTY) mode**. In non-interactive mode, you must either provide the password explicitly, or opt-in to printing it:
|
|
80
|
+
- `--print-password` (dangerous in CI logs)
|
|
81
|
+
|
|
82
|
+
Optional permissions (RDS/self-managed extras from the root `README.md`) are enabled by default. To skip them:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
npx postgresai prepare-db postgresql://admin@host:5432/dbname --skip-optional-permissions
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Print SQL / dry run
|
|
89
|
+
|
|
90
|
+
To see what SQL would be executed (passwords redacted by default):
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
npx postgresai prepare-db postgresql://admin@host:5432/dbname --print-sql
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Verify and password reset
|
|
97
|
+
|
|
98
|
+
Verify that everything is configured as expected (no changes):
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
npx postgresai prepare-db postgresql://admin@host:5432/dbname --verify
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Reset monitoring user password only (no other changes):
|
|
105
|
+
|
|
31
106
|
```bash
|
|
32
|
-
|
|
33
|
-
postgresai --help
|
|
34
|
-
pgai --help # short alias
|
|
107
|
+
npx postgresai prepare-db postgresql://admin@host:5432/dbname --reset-password --password 'new_password'
|
|
35
108
|
```
|
|
36
109
|
|
|
37
110
|
## Quick start
|
|
@@ -40,7 +113,7 @@ pgai --help # short alias
|
|
|
40
113
|
|
|
41
114
|
Authenticate via browser to obtain API key:
|
|
42
115
|
```bash
|
|
43
|
-
|
|
116
|
+
postgresai auth
|
|
44
117
|
```
|
|
45
118
|
|
|
46
119
|
This will:
|
|
@@ -52,17 +125,17 @@ This will:
|
|
|
52
125
|
|
|
53
126
|
Start monitoring with demo database:
|
|
54
127
|
```bash
|
|
55
|
-
|
|
128
|
+
postgresai mon local-install --demo
|
|
56
129
|
```
|
|
57
130
|
|
|
58
131
|
Start monitoring with your own database:
|
|
59
132
|
```bash
|
|
60
|
-
|
|
133
|
+
postgresai mon local-install --db-url postgresql://user:pass@host:5432/db
|
|
61
134
|
```
|
|
62
135
|
|
|
63
136
|
Complete automated setup with API key and database:
|
|
64
137
|
```bash
|
|
65
|
-
|
|
138
|
+
postgresai mon local-install --api-key your_key --db-url postgresql://user:pass@host:5432/db -y
|
|
66
139
|
```
|
|
67
140
|
|
|
68
141
|
This will:
|
|
@@ -79,22 +152,22 @@ This will:
|
|
|
79
152
|
#### Service lifecycle
|
|
80
153
|
```bash
|
|
81
154
|
# Complete setup with various options
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
155
|
+
postgresai mon local-install # Interactive setup for production
|
|
156
|
+
postgresai mon local-install --demo # Demo mode with sample database
|
|
157
|
+
postgresai mon local-install --api-key <key> # Setup with API key
|
|
158
|
+
postgresai mon local-install --db-url <url> # Setup with database URL
|
|
159
|
+
postgresai mon local-install --api-key <key> --db-url <url> # Complete automated setup
|
|
160
|
+
postgresai mon local-install -y # Auto-accept all defaults
|
|
88
161
|
|
|
89
162
|
# Service management
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
163
|
+
postgresai mon start # Start monitoring services
|
|
164
|
+
postgresai mon stop # Stop monitoring services
|
|
165
|
+
postgresai mon restart [service] # Restart all or specific monitoring service
|
|
166
|
+
postgresai mon status # Show monitoring services status
|
|
167
|
+
postgresai mon health [--wait <sec>] # Check monitoring services health
|
|
95
168
|
```
|
|
96
169
|
|
|
97
|
-
#####
|
|
170
|
+
##### local-install options
|
|
98
171
|
- `--demo` - Demo mode with sample database (testing only, cannot use with --api-key)
|
|
99
172
|
- `--api-key <key>` - Postgres AI API key for automated report uploads
|
|
100
173
|
- `--db-url <url>` - PostgreSQL connection URL to monitor (format: `postgresql://user:pass@host:port/db`)
|
|
@@ -102,27 +175,27 @@ postgres-ai mon health [--wait <sec>] # Check monitoring services health
|
|
|
102
175
|
|
|
103
176
|
#### Monitoring target databases (`mon targets` subgroup)
|
|
104
177
|
```bash
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
178
|
+
postgresai mon targets list # List databases to monitor
|
|
179
|
+
postgresai mon targets add <conn-string> <name> # Add database to monitor
|
|
180
|
+
postgresai mon targets remove <name> # Remove monitoring target
|
|
181
|
+
postgresai mon targets test <name> # Test target connectivity
|
|
109
182
|
```
|
|
110
183
|
|
|
111
184
|
#### Configuration and maintenance
|
|
112
185
|
```bash
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
186
|
+
postgresai mon config # Show monitoring configuration
|
|
187
|
+
postgresai mon update-config # Apply configuration changes
|
|
188
|
+
postgresai mon update # Update monitoring stack
|
|
189
|
+
postgresai mon reset [service] # Reset service data
|
|
190
|
+
postgresai mon clean # Cleanup artifacts
|
|
191
|
+
postgresai mon check # System readiness check
|
|
192
|
+
postgresai mon shell <service> # Open shell to monitoring service
|
|
120
193
|
```
|
|
121
194
|
|
|
122
195
|
### MCP server (`mcp` group)
|
|
123
196
|
|
|
124
197
|
```bash
|
|
125
|
-
|
|
198
|
+
postgresai mcp start # Start MCP stdio server exposing tools
|
|
126
199
|
```
|
|
127
200
|
|
|
128
201
|
Cursor configuration example (Settings → MCP):
|
|
@@ -131,7 +204,7 @@ Cursor configuration example (Settings → MCP):
|
|
|
131
204
|
{
|
|
132
205
|
"mcpServers": {
|
|
133
206
|
"PostgresAI": {
|
|
134
|
-
"command": "
|
|
207
|
+
"command": "postgresai",
|
|
135
208
|
"args": ["mcp", "start"],
|
|
136
209
|
"env": {
|
|
137
210
|
"PGAI_API_BASE_URL": "https://postgres.ai/api/general/"
|
|
@@ -142,16 +215,16 @@ Cursor configuration example (Settings → MCP):
|
|
|
142
215
|
```
|
|
143
216
|
|
|
144
217
|
Tools exposed:
|
|
145
|
-
- list_issues: returns the same JSON as `
|
|
218
|
+
- list_issues: returns the same JSON as `postgresai issues list`.
|
|
146
219
|
- view_issue: view a single issue with its comments (args: { issue_id, debug? })
|
|
147
220
|
- post_issue_comment: post a comment (args: { issue_id, content, parent_comment_id?, debug? })
|
|
148
221
|
|
|
149
222
|
### Issues management (`issues` group)
|
|
150
223
|
|
|
151
224
|
```bash
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
225
|
+
postgresai issues list # List issues (shows: id, title, status, created_at)
|
|
226
|
+
postgresai issues view <issueId> # View issue details and comments
|
|
227
|
+
postgresai issues post_comment <issueId> <content> # Post a comment to an issue
|
|
155
228
|
# Options:
|
|
156
229
|
# --parent <uuid> Parent comment ID (for replies)
|
|
157
230
|
# --debug Enable debug output
|
|
@@ -165,27 +238,27 @@ By default, issues commands print human-friendly YAML when writing to a terminal
|
|
|
165
238
|
- Use `--json` to force JSON output:
|
|
166
239
|
|
|
167
240
|
```bash
|
|
168
|
-
|
|
241
|
+
postgresai issues list --json | jq '.[] | {id, title}'
|
|
169
242
|
```
|
|
170
243
|
|
|
171
244
|
- Rely on auto-detection: when stdout is not a TTY (e.g., piped or redirected), output is JSON automatically:
|
|
172
245
|
|
|
173
246
|
```bash
|
|
174
|
-
|
|
247
|
+
postgresai issues view <issueId> > issue.json
|
|
175
248
|
```
|
|
176
249
|
|
|
177
250
|
#### Grafana management
|
|
178
251
|
```bash
|
|
179
|
-
|
|
180
|
-
|
|
252
|
+
postgresai mon generate-grafana-password # Generate new Grafana password
|
|
253
|
+
postgresai mon show-grafana-credentials # Show Grafana credentials
|
|
181
254
|
```
|
|
182
255
|
|
|
183
256
|
### Authentication and API key management
|
|
184
257
|
```bash
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
258
|
+
postgresai auth # Authenticate via browser (OAuth)
|
|
259
|
+
postgresai auth --set-key <key> # Store API key directly
|
|
260
|
+
postgresai show-key # Show stored key (masked)
|
|
261
|
+
postgresai remove-key # Remove stored key
|
|
189
262
|
```
|
|
190
263
|
|
|
191
264
|
## Configuration
|
|
@@ -230,26 +303,33 @@ Normalization:
|
|
|
230
303
|
|
|
231
304
|
### Examples
|
|
232
305
|
|
|
233
|
-
|
|
306
|
+
For production (uses default URLs):
|
|
234
307
|
|
|
235
308
|
```bash
|
|
309
|
+
# Production auth - uses console.postgres.ai by default
|
|
310
|
+
postgresai auth --debug
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
For staging/development environments:
|
|
314
|
+
|
|
315
|
+
```bash
|
|
316
|
+
# Linux/macOS (bash/zsh)
|
|
236
317
|
export PGAI_API_BASE_URL=https://v2.postgres.ai/api/general/
|
|
237
318
|
export PGAI_UI_BASE_URL=https://console-dev.postgres.ai
|
|
238
|
-
|
|
319
|
+
postgresai auth --debug
|
|
239
320
|
```
|
|
240
321
|
|
|
241
|
-
Windows PowerShell:
|
|
242
|
-
|
|
243
322
|
```powershell
|
|
323
|
+
# Windows PowerShell
|
|
244
324
|
$env:PGAI_API_BASE_URL = "https://v2.postgres.ai/api/general/"
|
|
245
325
|
$env:PGAI_UI_BASE_URL = "https://console-dev.postgres.ai"
|
|
246
|
-
|
|
326
|
+
postgresai auth --debug
|
|
247
327
|
```
|
|
248
328
|
|
|
249
329
|
Via CLI options (overrides env):
|
|
250
330
|
|
|
251
331
|
```bash
|
|
252
|
-
|
|
332
|
+
postgresai auth --debug \
|
|
253
333
|
--api-base-url https://v2.postgres.ai/api/general/ \
|
|
254
334
|
--ui-base-url https://console-dev.postgres.ai
|
|
255
335
|
```
|
|
@@ -257,6 +337,27 @@ pgai auth --debug \
|
|
|
257
337
|
Notes:
|
|
258
338
|
- If `PGAI_UI_BASE_URL` is not set, the default is `https://console.postgres.ai`.
|
|
259
339
|
|
|
340
|
+
## Development
|
|
341
|
+
|
|
342
|
+
### Testing
|
|
343
|
+
|
|
344
|
+
The CLI uses [Bun](https://bun.sh/) as the test runner with built-in coverage reporting.
|
|
345
|
+
|
|
346
|
+
```bash
|
|
347
|
+
# Run tests with coverage (default)
|
|
348
|
+
bun run test
|
|
349
|
+
|
|
350
|
+
# Run tests without coverage (faster iteration during development)
|
|
351
|
+
bun run test:fast
|
|
352
|
+
|
|
353
|
+
# Run tests with coverage and show report location
|
|
354
|
+
bun run test:coverage
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
Coverage configuration is in `bunfig.toml`. Reports are generated in `coverage/` directory:
|
|
358
|
+
- `coverage/lcov-report/index.html` - HTML coverage report
|
|
359
|
+
- `coverage/lcov.info` - LCOV format for CI integration
|
|
360
|
+
|
|
260
361
|
## Requirements
|
|
261
362
|
|
|
262
363
|
- Node.js 18 or higher
|