postgresai 0.14.0-beta.1 → 0.14.0-beta.11
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 +104 -61
- package/bin/postgres-ai.ts +1304 -417
- package/bun.lock +258 -0
- package/bunfig.toml +20 -0
- package/dist/bin/postgres-ai.js +28560 -1778
- 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 +415 -220
- 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 -10
- 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 +8 -7
- package/sql/02.permissions.sql +9 -5
- 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/init.d.ts +0 -75
- package/dist/lib/init.d.ts.map +0 -1
- package/dist/lib/init.js +0 -483
- package/dist/lib/init.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 -46
- package/test/init.integration.test.cjs +0 -368
- package/test/init.test.cjs +0 -154
package/README.md
CHANGED
|
@@ -15,6 +15,8 @@ Or install the latest beta release explicitly:
|
|
|
15
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,33 +29,46 @@ 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
|
+
|
|
31
48
|
```bash
|
|
32
|
-
|
|
33
|
-
postgresai --help
|
|
34
|
-
pgai --help # short alias
|
|
49
|
+
npx pgai --help
|
|
35
50
|
```
|
|
36
51
|
|
|
37
|
-
##
|
|
52
|
+
## prepare-db (create monitoring user in Postgres)
|
|
38
53
|
|
|
39
|
-
This command creates (or updates) the `postgres_ai_mon` user and grants the permissions described in the root `README.md` (it is idempotent).
|
|
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.
|
|
40
55
|
|
|
41
56
|
Run without installing (positional connection string):
|
|
42
57
|
|
|
43
58
|
```bash
|
|
44
|
-
npx postgresai
|
|
59
|
+
npx postgresai prepare-db postgresql://admin@host:5432/dbname
|
|
45
60
|
```
|
|
46
61
|
|
|
47
|
-
It also accepts libpq
|
|
62
|
+
It also accepts libpq "conninfo" syntax:
|
|
48
63
|
|
|
49
64
|
```bash
|
|
50
|
-
npx postgresai
|
|
65
|
+
npx postgresai prepare-db "dbname=dbname host=host user=admin"
|
|
51
66
|
```
|
|
52
67
|
|
|
53
68
|
And psql-like options:
|
|
54
69
|
|
|
55
70
|
```bash
|
|
56
|
-
npx postgresai
|
|
71
|
+
npx postgresai prepare-db -h host -p 5432 -U admin -d dbname
|
|
57
72
|
```
|
|
58
73
|
|
|
59
74
|
Password input options (in priority order):
|
|
@@ -67,7 +82,7 @@ By default, the generated password is printed **only in interactive (TTY) mode**
|
|
|
67
82
|
Optional permissions (RDS/self-managed extras from the root `README.md`) are enabled by default. To skip them:
|
|
68
83
|
|
|
69
84
|
```bash
|
|
70
|
-
npx postgresai
|
|
85
|
+
npx postgresai prepare-db postgresql://admin@host:5432/dbname --skip-optional-permissions
|
|
71
86
|
```
|
|
72
87
|
|
|
73
88
|
### Print SQL / dry run
|
|
@@ -75,7 +90,7 @@ npx postgresai init postgresql://admin@host:5432/dbname --skip-optional-permissi
|
|
|
75
90
|
To see what SQL would be executed (passwords redacted by default):
|
|
76
91
|
|
|
77
92
|
```bash
|
|
78
|
-
npx postgresai
|
|
93
|
+
npx postgresai prepare-db postgresql://admin@host:5432/dbname --print-sql
|
|
79
94
|
```
|
|
80
95
|
|
|
81
96
|
### Verify and password reset
|
|
@@ -83,13 +98,13 @@ npx postgresai init postgresql://admin@host:5432/dbname --print-sql
|
|
|
83
98
|
Verify that everything is configured as expected (no changes):
|
|
84
99
|
|
|
85
100
|
```bash
|
|
86
|
-
npx postgresai
|
|
101
|
+
npx postgresai prepare-db postgresql://admin@host:5432/dbname --verify
|
|
87
102
|
```
|
|
88
103
|
|
|
89
104
|
Reset monitoring user password only (no other changes):
|
|
90
105
|
|
|
91
106
|
```bash
|
|
92
|
-
npx postgresai
|
|
107
|
+
npx postgresai prepare-db postgresql://admin@host:5432/dbname --reset-password --password 'new_password'
|
|
93
108
|
```
|
|
94
109
|
|
|
95
110
|
## Quick start
|
|
@@ -98,7 +113,7 @@ npx postgresai init postgresql://admin@host:5432/dbname --reset-password --passw
|
|
|
98
113
|
|
|
99
114
|
Authenticate via browser to obtain API key:
|
|
100
115
|
```bash
|
|
101
|
-
|
|
116
|
+
postgresai auth
|
|
102
117
|
```
|
|
103
118
|
|
|
104
119
|
This will:
|
|
@@ -110,17 +125,17 @@ This will:
|
|
|
110
125
|
|
|
111
126
|
Start monitoring with demo database:
|
|
112
127
|
```bash
|
|
113
|
-
|
|
128
|
+
postgresai mon local-install --demo
|
|
114
129
|
```
|
|
115
130
|
|
|
116
131
|
Start monitoring with your own database:
|
|
117
132
|
```bash
|
|
118
|
-
|
|
133
|
+
postgresai mon local-install --db-url postgresql://user:pass@host:5432/db
|
|
119
134
|
```
|
|
120
135
|
|
|
121
136
|
Complete automated setup with API key and database:
|
|
122
137
|
```bash
|
|
123
|
-
|
|
138
|
+
postgresai mon local-install --api-key your_key --db-url postgresql://user:pass@host:5432/db -y
|
|
124
139
|
```
|
|
125
140
|
|
|
126
141
|
This will:
|
|
@@ -137,22 +152,22 @@ This will:
|
|
|
137
152
|
#### Service lifecycle
|
|
138
153
|
```bash
|
|
139
154
|
# Complete setup with various options
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
|
146
161
|
|
|
147
162
|
# Service management
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
|
153
168
|
```
|
|
154
169
|
|
|
155
|
-
#####
|
|
170
|
+
##### local-install options
|
|
156
171
|
- `--demo` - Demo mode with sample database (testing only, cannot use with --api-key)
|
|
157
172
|
- `--api-key <key>` - Postgres AI API key for automated report uploads
|
|
158
173
|
- `--db-url <url>` - PostgreSQL connection URL to monitor (format: `postgresql://user:pass@host:port/db`)
|
|
@@ -160,27 +175,27 @@ postgres-ai mon health [--wait <sec>] # Check monitoring services health
|
|
|
160
175
|
|
|
161
176
|
#### Monitoring target databases (`mon targets` subgroup)
|
|
162
177
|
```bash
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
|
167
182
|
```
|
|
168
183
|
|
|
169
184
|
#### Configuration and maintenance
|
|
170
185
|
```bash
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
|
178
193
|
```
|
|
179
194
|
|
|
180
195
|
### MCP server (`mcp` group)
|
|
181
196
|
|
|
182
197
|
```bash
|
|
183
|
-
|
|
198
|
+
postgresai mcp start # Start MCP stdio server exposing tools
|
|
184
199
|
```
|
|
185
200
|
|
|
186
201
|
Cursor configuration example (Settings → MCP):
|
|
@@ -189,7 +204,7 @@ Cursor configuration example (Settings → MCP):
|
|
|
189
204
|
{
|
|
190
205
|
"mcpServers": {
|
|
191
206
|
"PostgresAI": {
|
|
192
|
-
"command": "
|
|
207
|
+
"command": "postgresai",
|
|
193
208
|
"args": ["mcp", "start"],
|
|
194
209
|
"env": {
|
|
195
210
|
"PGAI_API_BASE_URL": "https://postgres.ai/api/general/"
|
|
@@ -200,16 +215,16 @@ Cursor configuration example (Settings → MCP):
|
|
|
200
215
|
```
|
|
201
216
|
|
|
202
217
|
Tools exposed:
|
|
203
|
-
- list_issues: returns the same JSON as `
|
|
218
|
+
- list_issues: returns the same JSON as `postgresai issues list`.
|
|
204
219
|
- view_issue: view a single issue with its comments (args: { issue_id, debug? })
|
|
205
220
|
- post_issue_comment: post a comment (args: { issue_id, content, parent_comment_id?, debug? })
|
|
206
221
|
|
|
207
222
|
### Issues management (`issues` group)
|
|
208
223
|
|
|
209
224
|
```bash
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
|
213
228
|
# Options:
|
|
214
229
|
# --parent <uuid> Parent comment ID (for replies)
|
|
215
230
|
# --debug Enable debug output
|
|
@@ -223,27 +238,27 @@ By default, issues commands print human-friendly YAML when writing to a terminal
|
|
|
223
238
|
- Use `--json` to force JSON output:
|
|
224
239
|
|
|
225
240
|
```bash
|
|
226
|
-
|
|
241
|
+
postgresai issues list --json | jq '.[] | {id, title}'
|
|
227
242
|
```
|
|
228
243
|
|
|
229
244
|
- Rely on auto-detection: when stdout is not a TTY (e.g., piped or redirected), output is JSON automatically:
|
|
230
245
|
|
|
231
246
|
```bash
|
|
232
|
-
|
|
247
|
+
postgresai issues view <issueId> > issue.json
|
|
233
248
|
```
|
|
234
249
|
|
|
235
250
|
#### Grafana management
|
|
236
251
|
```bash
|
|
237
|
-
|
|
238
|
-
|
|
252
|
+
postgresai mon generate-grafana-password # Generate new Grafana password
|
|
253
|
+
postgresai mon show-grafana-credentials # Show Grafana credentials
|
|
239
254
|
```
|
|
240
255
|
|
|
241
256
|
### Authentication and API key management
|
|
242
257
|
```bash
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
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
|
|
247
262
|
```
|
|
248
263
|
|
|
249
264
|
## Configuration
|
|
@@ -288,26 +303,33 @@ Normalization:
|
|
|
288
303
|
|
|
289
304
|
### Examples
|
|
290
305
|
|
|
291
|
-
|
|
306
|
+
For production (uses default URLs):
|
|
307
|
+
|
|
308
|
+
```bash
|
|
309
|
+
# Production auth - uses console.postgres.ai by default
|
|
310
|
+
postgresai auth --debug
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
For staging/development environments:
|
|
292
314
|
|
|
293
315
|
```bash
|
|
316
|
+
# Linux/macOS (bash/zsh)
|
|
294
317
|
export PGAI_API_BASE_URL=https://v2.postgres.ai/api/general/
|
|
295
318
|
export PGAI_UI_BASE_URL=https://console-dev.postgres.ai
|
|
296
|
-
|
|
319
|
+
postgresai auth --debug
|
|
297
320
|
```
|
|
298
321
|
|
|
299
|
-
Windows PowerShell:
|
|
300
|
-
|
|
301
322
|
```powershell
|
|
323
|
+
# Windows PowerShell
|
|
302
324
|
$env:PGAI_API_BASE_URL = "https://v2.postgres.ai/api/general/"
|
|
303
325
|
$env:PGAI_UI_BASE_URL = "https://console-dev.postgres.ai"
|
|
304
|
-
|
|
326
|
+
postgresai auth --debug
|
|
305
327
|
```
|
|
306
328
|
|
|
307
329
|
Via CLI options (overrides env):
|
|
308
330
|
|
|
309
331
|
```bash
|
|
310
|
-
|
|
332
|
+
postgresai auth --debug \
|
|
311
333
|
--api-base-url https://v2.postgres.ai/api/general/ \
|
|
312
334
|
--ui-base-url https://console-dev.postgres.ai
|
|
313
335
|
```
|
|
@@ -315,6 +337,27 @@ pgai auth --debug \
|
|
|
315
337
|
Notes:
|
|
316
338
|
- If `PGAI_UI_BASE_URL` is not set, the default is `https://console.postgres.ai`.
|
|
317
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
|
+
|
|
318
361
|
## Requirements
|
|
319
362
|
|
|
320
363
|
- Node.js 18 or higher
|