postgresai 0.14.0-beta.1 → 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.
Files changed (78) hide show
  1. package/README.md +104 -61
  2. package/bin/postgres-ai.ts +1304 -417
  3. package/bun.lock +258 -0
  4. package/bunfig.toml +20 -0
  5. package/dist/bin/postgres-ai.js +28559 -1778
  6. package/dist/sql/01.role.sql +16 -0
  7. package/dist/sql/02.permissions.sql +37 -0
  8. package/dist/sql/03.optional_rds.sql +6 -0
  9. package/dist/sql/04.optional_self_managed.sql +8 -0
  10. package/dist/sql/05.helpers.sql +439 -0
  11. package/dist/sql/sql/01.role.sql +16 -0
  12. package/dist/sql/sql/02.permissions.sql +37 -0
  13. package/dist/sql/sql/03.optional_rds.sql +6 -0
  14. package/dist/sql/sql/04.optional_self_managed.sql +8 -0
  15. package/dist/sql/sql/05.helpers.sql +439 -0
  16. package/lib/auth-server.ts +124 -106
  17. package/lib/checkup-api.ts +386 -0
  18. package/lib/checkup.ts +1330 -0
  19. package/lib/config.ts +6 -3
  20. package/lib/init.ts +415 -220
  21. package/lib/issues.ts +400 -191
  22. package/lib/mcp-server.ts +213 -90
  23. package/lib/metrics-embedded.ts +79 -0
  24. package/lib/metrics-loader.ts +127 -0
  25. package/lib/util.ts +61 -0
  26. package/package.json +20 -10
  27. package/packages/postgres-ai/README.md +26 -0
  28. package/packages/postgres-ai/bin/postgres-ai.js +27 -0
  29. package/packages/postgres-ai/package.json +27 -0
  30. package/scripts/embed-metrics.ts +154 -0
  31. package/sql/01.role.sql +8 -7
  32. package/sql/02.permissions.sql +9 -5
  33. package/sql/05.helpers.sql +439 -0
  34. package/test/auth.test.ts +258 -0
  35. package/test/checkup.integration.test.ts +321 -0
  36. package/test/checkup.test.ts +891 -0
  37. package/test/init.integration.test.ts +499 -0
  38. package/test/init.test.ts +417 -0
  39. package/test/issues.cli.test.ts +314 -0
  40. package/test/issues.test.ts +456 -0
  41. package/test/mcp-server.test.ts +988 -0
  42. package/test/schema-validation.test.ts +81 -0
  43. package/test/test-utils.ts +122 -0
  44. package/tsconfig.json +12 -20
  45. package/dist/bin/postgres-ai.d.ts +0 -3
  46. package/dist/bin/postgres-ai.d.ts.map +0 -1
  47. package/dist/bin/postgres-ai.js.map +0 -1
  48. package/dist/lib/auth-server.d.ts +0 -31
  49. package/dist/lib/auth-server.d.ts.map +0 -1
  50. package/dist/lib/auth-server.js +0 -263
  51. package/dist/lib/auth-server.js.map +0 -1
  52. package/dist/lib/config.d.ts +0 -45
  53. package/dist/lib/config.d.ts.map +0 -1
  54. package/dist/lib/config.js +0 -181
  55. package/dist/lib/config.js.map +0 -1
  56. package/dist/lib/init.d.ts +0 -75
  57. package/dist/lib/init.d.ts.map +0 -1
  58. package/dist/lib/init.js +0 -483
  59. package/dist/lib/init.js.map +0 -1
  60. package/dist/lib/issues.d.ts +0 -75
  61. package/dist/lib/issues.d.ts.map +0 -1
  62. package/dist/lib/issues.js +0 -336
  63. package/dist/lib/issues.js.map +0 -1
  64. package/dist/lib/mcp-server.d.ts +0 -9
  65. package/dist/lib/mcp-server.d.ts.map +0 -1
  66. package/dist/lib/mcp-server.js +0 -168
  67. package/dist/lib/mcp-server.js.map +0 -1
  68. package/dist/lib/pkce.d.ts +0 -32
  69. package/dist/lib/pkce.d.ts.map +0 -1
  70. package/dist/lib/pkce.js +0 -101
  71. package/dist/lib/pkce.js.map +0 -1
  72. package/dist/lib/util.d.ts +0 -27
  73. package/dist/lib/util.d.ts.map +0 -1
  74. package/dist/lib/util.js +0 -46
  75. package/dist/lib/util.js.map +0 -1
  76. package/dist/package.json +0 -46
  77. package/test/init.integration.test.cjs +0 -368
  78. 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 CLI provides three command aliases:
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
- postgres-ai --help
33
- postgresai --help
34
- pgai --help # short alias
49
+ npx pgai --help
35
50
  ```
36
51
 
37
- ## init (create monitoring user in Postgres)
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 init postgresql://admin@host:5432/dbname
59
+ npx postgresai prepare-db postgresql://admin@host:5432/dbname
45
60
  ```
46
61
 
47
- It also accepts libpq conninfo syntax:
62
+ It also accepts libpq "conninfo" syntax:
48
63
 
49
64
  ```bash
50
- npx postgresai init "dbname=dbname host=host user=admin"
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 init -h host -p 5432 -U admin -d dbname
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 init postgresql://admin@host:5432/dbname --skip-optional-permissions
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 init postgresql://admin@host:5432/dbname --print-sql
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 init postgresql://admin@host:5432/dbname --verify
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 init postgresql://admin@host:5432/dbname --reset-password --password 'new_password'
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
- pgai auth
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
- postgres-ai mon quickstart --demo
128
+ postgresai mon local-install --demo
114
129
  ```
115
130
 
116
131
  Start monitoring with your own database:
117
132
  ```bash
118
- postgres-ai mon quickstart --db-url postgresql://user:pass@host:5432/db
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
- postgres-ai mon quickstart --api-key your_key --db-url postgresql://user:pass@host:5432/db -y
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
- postgres-ai mon quickstart # Interactive setup for production
141
- postgres-ai mon quickstart --demo # Demo mode with sample database
142
- postgres-ai mon quickstart --api-key <key> # Setup with API key
143
- postgres-ai mon quickstart --db-url <url> # Setup with database URL
144
- postgres-ai mon quickstart --api-key <key> --db-url <url> # Complete automated setup
145
- postgres-ai mon quickstart -y # Auto-accept all defaults
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
- postgres-ai mon start # Start monitoring services
149
- postgres-ai mon stop # Stop monitoring services
150
- postgres-ai mon restart [service] # Restart all or specific monitoring service
151
- postgres-ai mon status # Show monitoring services status
152
- postgres-ai mon health [--wait <sec>] # Check monitoring services health
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
- ##### Quickstart options
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
- postgres-ai mon targets list # List databases to monitor
164
- postgres-ai mon targets add <conn-string> <name> # Add database to monitor
165
- postgres-ai mon targets remove <name> # Remove monitoring target
166
- postgres-ai mon targets test <name> # Test target connectivity
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
- postgres-ai mon config # Show monitoring configuration
172
- postgres-ai mon update-config # Apply configuration changes
173
- postgres-ai mon update # Update monitoring stack
174
- postgres-ai mon reset [service] # Reset service data
175
- postgres-ai mon clean # Cleanup artifacts
176
- postgres-ai mon check # System readiness check
177
- postgres-ai mon shell <service> # Open shell to monitoring service
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
- pgai mcp start # Start MCP stdio server exposing tools
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": "pgai",
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 `pgai issues list`.
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
- pgai issues list # List issues (shows: id, title, status, created_at)
211
- pgai issues view <issueId> # View issue details and comments
212
- pgai issues post_comment <issueId> <content> # Post a comment to an issue
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
- pgai issues list --json | jq '.[] | {id, title}'
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
- pgai issues view <issueId> > issue.json
247
+ postgresai issues view <issueId> > issue.json
233
248
  ```
234
249
 
235
250
  #### Grafana management
236
251
  ```bash
237
- postgres-ai mon generate-grafana-password # Generate new Grafana password
238
- postgres-ai mon show-grafana-credentials # Show Grafana credentials
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
- postgres-ai auth # Authenticate via browser (recommended)
244
- postgres-ai add-key <key> # Manually store API key
245
- postgres-ai show-key # Show stored key (masked)
246
- postgres-ai remove-key # Remove stored key
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
- Linux/macOS (bash/zsh):
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
- pgai auth --debug
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
- pgai auth --debug
326
+ postgresai auth --debug
305
327
  ```
306
328
 
307
329
  Via CLI options (overrides env):
308
330
 
309
331
  ```bash
310
- pgai auth --debug \
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