postgresai 0.16.0-rc.4 → 0.16.0

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 (85) hide show
  1. package/README.md +154 -0
  2. package/dist/bin/postgres-ai.js +2911 -255
  3. package/package.json +12 -3
  4. package/schemas/A002.schema.json +63 -0
  5. package/schemas/A003.schema.json +73 -0
  6. package/schemas/A004.schema.json +81 -0
  7. package/schemas/A007.schema.json +71 -0
  8. package/schemas/A013.schema.json +61 -0
  9. package/schemas/D001.schema.json +71 -0
  10. package/schemas/D004.schema.json +136 -0
  11. package/schemas/F001.schema.json +73 -0
  12. package/schemas/F002.schema.json +108 -0
  13. package/schemas/F003.schema.json +138 -0
  14. package/schemas/F004.schema.json +125 -0
  15. package/schemas/F005.schema.json +131 -0
  16. package/schemas/F009.schema.json +155 -0
  17. package/schemas/G001.schema.json +135 -0
  18. package/schemas/G003.schema.json +90 -0
  19. package/schemas/H001.schema.json +141 -0
  20. package/schemas/H002.schema.json +129 -0
  21. package/schemas/H004.schema.json +128 -0
  22. package/schemas/I001.schema.json +149 -0
  23. package/schemas/K001.schema.json +161 -0
  24. package/schemas/K003.schema.json +163 -0
  25. package/schemas/K004.schema.json +110 -0
  26. package/schemas/K005.schema.json +110 -0
  27. package/schemas/K006.schema.json +110 -0
  28. package/schemas/K007.schema.json +110 -0
  29. package/schemas/K008.schema.json +110 -0
  30. package/schemas/M001.schema.json +119 -0
  31. package/schemas/M002.schema.json +110 -0
  32. package/schemas/M003.schema.json +128 -0
  33. package/schemas/N001.schema.json +161 -0
  34. package/schemas/query.schema.json +62 -0
  35. package/CHANGELOG.md +0 -11
  36. package/bin/postgres-ai.ts +0 -5578
  37. package/bun.lock +0 -258
  38. package/bunfig.toml +0 -20
  39. package/lib/aas-onboard.ts +0 -251
  40. package/lib/auth-server.ts +0 -285
  41. package/lib/checkup-api.ts +0 -526
  42. package/lib/checkup-dictionary.ts +0 -103
  43. package/lib/checkup-summary.ts +0 -338
  44. package/lib/checkup.ts +0 -2261
  45. package/lib/config.ts +0 -171
  46. package/lib/init.ts +0 -1152
  47. package/lib/instances.ts +0 -245
  48. package/lib/issues.ts +0 -1060
  49. package/lib/mcp-server.ts +0 -667
  50. package/lib/metrics-loader.ts +0 -134
  51. package/lib/pkce.ts +0 -79
  52. package/lib/reports.ts +0 -373
  53. package/lib/storage.ts +0 -367
  54. package/lib/supabase.ts +0 -826
  55. package/lib/util.ts +0 -134
  56. package/packages/postgres-ai/README.md +0 -26
  57. package/packages/postgres-ai/bin/postgres-ai.js +0 -27
  58. package/packages/postgres-ai/package.json +0 -27
  59. package/scripts/embed-checkup-dictionary.ts +0 -115
  60. package/scripts/embed-metrics.ts +0 -160
  61. package/scripts/generate-release-notes.ts +0 -668
  62. package/test/PERMISSION_CHECK_TEST_SUMMARY.md +0 -139
  63. package/test/aas-onboard.test.ts +0 -301
  64. package/test/auth.test.ts +0 -287
  65. package/test/checkup.integration.test.ts +0 -413
  66. package/test/checkup.test.ts +0 -3626
  67. package/test/compose-cmd.test.ts +0 -120
  68. package/test/config-consistency.test.ts +0 -352
  69. package/test/init.integration.test.ts +0 -438
  70. package/test/init.test.ts +0 -1816
  71. package/test/issues.cli.test.ts +0 -1162
  72. package/test/issues.test.ts +0 -456
  73. package/test/mcp-server.test.ts +0 -2530
  74. package/test/monitoring.test.ts +0 -746
  75. package/test/permission-check-sql.test.ts +0 -116
  76. package/test/reports.cli.test.ts +0 -793
  77. package/test/reports.test.ts +0 -977
  78. package/test/schema-validation.test.ts +0 -231
  79. package/test/storage.test.ts +0 -935
  80. package/test/supabase.test.ts +0 -709
  81. package/test/targets-add-config.test.ts +0 -28
  82. package/test/test-utils.ts +0 -190
  83. package/test/upgrade.test.ts +0 -1056
  84. package/test/util.test.ts +0 -44
  85. package/tsconfig.json +0 -20
@@ -1,338 +0,0 @@
1
- /**
2
- * Generate human-readable summaries from checkup report JSON.
3
- * Used for default CLI output without requiring API calls.
4
- *
5
- * NOTE: This file uses `any` types for report structures to maintain flexibility
6
- * with the dynamic JSON schema from the API. Future improvement: define proper
7
- * TypeScript interfaces for report structures based on schema files.
8
- */
9
-
10
- export interface CheckSummary {
11
- status: 'ok' | 'warning' | 'info';
12
- message: string;
13
- }
14
-
15
- /**
16
- * Extract summary information from a checkup report.
17
- * Parses the JSON structure to extract key metrics for CLI display.
18
- */
19
- export function generateCheckSummary(checkId: string, report: any): CheckSummary {
20
- const nodeIds = Object.keys(report.results || {});
21
- if (nodeIds.length === 0) {
22
- return { status: 'info', message: 'No data' };
23
- }
24
-
25
- // Take first node for summary (most deployments use single node)
26
- const nodeData = report.results[nodeIds[0]];
27
-
28
- switch (checkId) {
29
- // Index health checks
30
- case 'H001': return summarizeH001(nodeData);
31
- case 'H002': return summarizeH002(nodeData);
32
- case 'H004': return summarizeH004(nodeData);
33
- // Version checks
34
- case 'A002': return summarizeA002(nodeData);
35
- case 'A013': return summarizeA013(nodeData);
36
- // Settings checks
37
- case 'A003': return summarizeA003(nodeData);
38
- case 'A004': return summarizeA004(nodeData);
39
- case 'A007': return summarizeA007(nodeData);
40
- case 'D001': return summarizeD001(nodeData);
41
- case 'D004': return summarizeD004(nodeData);
42
- case 'F001': return summarizeF001(nodeData);
43
- case 'F003': return summarizeF003(nodeData);
44
- case 'F004': return summarizeBloat(nodeData, 'table');
45
- case 'F005': return summarizeBloat(nodeData, 'index');
46
- case 'G001': return summarizeG001(nodeData);
47
- case 'G003': return summarizeG003(nodeData);
48
- default:
49
- return { status: 'info', message: 'Check completed' };
50
- }
51
- }
52
-
53
- function summarizeA003(nodeData: any): CheckSummary {
54
- const data = nodeData?.data || {};
55
- const settingsCount = Object.keys(data).length;
56
-
57
- if (settingsCount === 0) {
58
- return { status: 'info', message: 'No settings found' };
59
- }
60
-
61
- return {
62
- status: 'info',
63
- message: `${settingsCount} setting${settingsCount > 1 ? 's' : ''} collected`
64
- };
65
- }
66
-
67
- function summarizeA004(nodeData: any): CheckSummary {
68
- const data = nodeData?.data;
69
- if (!data) {
70
- return { status: 'info', message: 'Cluster information collected' };
71
- }
72
-
73
- const dbCount = Object.keys(data.database_sizes || {}).length;
74
- if (dbCount > 0) {
75
- return { status: 'info', message: `${dbCount} database${dbCount > 1 ? 's' : ''} analyzed` };
76
- }
77
-
78
- return { status: 'info', message: 'Cluster information collected' };
79
- }
80
-
81
- function summarizeA007(nodeData: any): CheckSummary {
82
- const data = nodeData?.data || {};
83
- const alteredCount = Object.keys(data).length;
84
-
85
- if (alteredCount === 0) {
86
- return { status: 'ok', message: 'No altered settings' };
87
- }
88
-
89
- return {
90
- status: 'info',
91
- message: `${alteredCount} setting${alteredCount > 1 ? 's' : ''} altered from defaults`
92
- };
93
- }
94
-
95
- function formatBytes(bytes: number): string {
96
- if (bytes === 0) return '0 B';
97
- if (bytes < 1024) return `${bytes} B`;
98
- if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(0)} KiB`;
99
- if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(0)} MiB`;
100
- return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)} GiB`;
101
- }
102
-
103
- function summarizeH001(nodeData: any): CheckSummary {
104
- const data = nodeData?.data || {};
105
- let totalCount = 0;
106
- let totalSize = 0;
107
-
108
- // Aggregate across all databases
109
- for (const dbData of Object.values(data)) {
110
- const dbEntry = dbData as any;
111
- totalCount += dbEntry.total_count || 0;
112
- totalSize += dbEntry.total_size_bytes || 0;
113
- }
114
-
115
- if (totalCount === 0) {
116
- return { status: 'ok', message: 'No invalid indexes' };
117
- }
118
-
119
- return {
120
- status: 'warning',
121
- message: `Found ${totalCount} invalid index${totalCount > 1 ? 'es' : ''} (${formatBytes(totalSize)})`
122
- };
123
- }
124
-
125
- function summarizeH002(nodeData: any): CheckSummary {
126
- const data = nodeData?.data || {};
127
- let totalCount = 0;
128
- let totalSize = 0;
129
-
130
- // Aggregate across all databases
131
- for (const dbData of Object.values(data)) {
132
- const dbEntry = dbData as any;
133
- totalCount += dbEntry.total_count || 0;
134
- totalSize += dbEntry.total_size_bytes || 0;
135
- }
136
-
137
- if (totalCount === 0) {
138
- return { status: 'ok', message: 'All indexes utilized' };
139
- }
140
-
141
- return {
142
- status: 'warning',
143
- message: `Found ${totalCount} unused index${totalCount > 1 ? 'es' : ''} (${formatBytes(totalSize)})`
144
- };
145
- }
146
-
147
- function summarizeH004(nodeData: any): CheckSummary {
148
- const data = nodeData?.data || {};
149
- let totalCount = 0;
150
- let totalSize = 0;
151
-
152
- // Aggregate across all databases
153
- for (const dbData of Object.values(data)) {
154
- const dbEntry = dbData as any;
155
- totalCount += dbEntry.total_count || 0;
156
- totalSize += dbEntry.total_size_bytes || 0;
157
- }
158
-
159
- if (totalCount === 0) {
160
- return { status: 'ok', message: 'No redundant indexes' };
161
- }
162
-
163
- return {
164
- status: 'warning',
165
- message: `Found ${totalCount} redundant index${totalCount > 1 ? 'es' : ''} (${formatBytes(totalSize)})`
166
- };
167
- }
168
-
169
- function summarizeA002(nodeData: any): CheckSummary {
170
- // A002 stores version in data.version (not postgres_version)
171
- const ver = nodeData?.data?.version;
172
- if (!ver) {
173
- return { status: 'info', message: 'Version checked' };
174
- }
175
-
176
- const major = parseInt(ver.server_major_ver, 10);
177
-
178
- // PostgreSQL 17 is current (as of early 2025)
179
- if (major >= 17) {
180
- return { status: 'ok', message: `PostgreSQL ${major}` };
181
- }
182
-
183
- if (major >= 15) {
184
- return { status: 'info', message: `PostgreSQL ${major}` };
185
- }
186
-
187
- return {
188
- status: 'warning',
189
- message: `PostgreSQL ${major} (consider upgrading)`
190
- };
191
- }
192
-
193
- function summarizeA013(nodeData: any): CheckSummary {
194
- // A013 stores version in data.version (not postgres_version)
195
- const ver = nodeData?.data?.version;
196
- if (!ver) {
197
- return { status: 'info', message: 'Minor version checked' };
198
- }
199
-
200
- const current = ver.version || '';
201
- return {
202
- status: 'info',
203
- message: `Version ${current}`
204
- };
205
- }
206
-
207
- function summarizeD001(nodeData: any): CheckSummary {
208
- const data = nodeData?.data || {};
209
- const settingsCount = Object.keys(data).length;
210
-
211
- if (settingsCount === 0) {
212
- return { status: 'info', message: 'No logging settings found' };
213
- }
214
-
215
- return {
216
- status: 'info',
217
- message: `${settingsCount} logging setting${settingsCount > 1 ? 's' : ''} collected`
218
- };
219
- }
220
-
221
- function summarizeD004(nodeData: any): CheckSummary {
222
- const data = nodeData?.data || {};
223
- const settingsCount = Object.keys(data).length;
224
-
225
- if (settingsCount === 0) {
226
- return { status: 'info', message: 'No pg_stat_statements settings found' };
227
- }
228
-
229
- return {
230
- status: 'info',
231
- message: `${settingsCount} pg_stat_statements setting${settingsCount > 1 ? 's' : ''} collected`
232
- };
233
- }
234
-
235
- function summarizeF001(nodeData: any): CheckSummary {
236
- const data = nodeData?.data || {};
237
- const settingsCount = Object.keys(data).length;
238
-
239
- if (settingsCount === 0) {
240
- return { status: 'info', message: 'No autovacuum settings found' };
241
- }
242
-
243
- return {
244
- status: 'info',
245
- message: `${settingsCount} autovacuum setting${settingsCount > 1 ? 's' : ''} collected`
246
- };
247
- }
248
-
249
- function summarizeF003(nodeData: any): CheckSummary {
250
- const data = nodeData?.data || {};
251
- let flaggedCount = 0;
252
- let disabledCount = 0;
253
-
254
- // Aggregate across all databases. Only non-tiny disabled-autovacuum tables
255
- // (autovacuum_disabled_flagged_count) trigger a warning - tiny tables with
256
- // autovacuum off are common and not worth alerting on.
257
- for (const dbData of Object.values(data)) {
258
- const dbEntry = dbData as any;
259
- flaggedCount += dbEntry.flagged_count || 0;
260
- disabledCount += dbEntry.autovacuum_disabled_flagged_count || 0;
261
- }
262
-
263
- if (flaggedCount === 0 && disabledCount === 0) {
264
- return { status: 'ok', message: 'No significant dead tuple accumulation' };
265
- }
266
-
267
- const parts: string[] = [];
268
- if (flaggedCount > 0) {
269
- parts.push(`${flaggedCount} table${flaggedCount > 1 ? 's' : ''} with excessive dead tuples`);
270
- }
271
- if (disabledCount > 0) {
272
- parts.push(`${disabledCount} table${disabledCount > 1 ? 's' : ''} with autovacuum disabled`);
273
- }
274
-
275
- return { status: 'warning', message: parts.join(', ') };
276
- }
277
-
278
- function summarizeBloat(nodeData: any, kind: 'table' | 'index'): CheckSummary {
279
- const data = nodeData?.data || {};
280
- let totalCount = 0;
281
-
282
- for (const dbData of Object.values(data)) {
283
- const dbEntry = dbData as any;
284
- if (dbEntry?.status?.ok === false) {
285
- const reason = String(dbEntry.status.reason || 'query_error').replaceAll('_', ' ');
286
- return { status: 'warning', message: `Bloat estimate degraded: ${reason}` };
287
- }
288
- totalCount += dbEntry?.total_count || 0;
289
- }
290
-
291
- if (totalCount === 0) {
292
- return { status: 'ok', message: `No bloated ${kind}${kind === 'index' ? 'es' : 's'} found` };
293
- }
294
-
295
- return {
296
- status: 'warning',
297
- message: `Found ${totalCount} bloated ${kind}${totalCount === 1 ? '' : kind === 'index' ? 'es' : 's'}`,
298
- };
299
- }
300
-
301
- function summarizeG001(nodeData: any): CheckSummary {
302
- const data = nodeData?.data || {};
303
- const settingsCount = Object.keys(data).length;
304
-
305
- if (settingsCount === 0) {
306
- return { status: 'info', message: 'No memory settings found' };
307
- }
308
-
309
- return {
310
- status: 'info',
311
- message: `${settingsCount} memory setting${settingsCount > 1 ? 's' : ''} collected`
312
- };
313
- }
314
-
315
- function summarizeG003(nodeData: any): CheckSummary {
316
- const data = nodeData?.data || {};
317
-
318
- // G003 has settings and deadlock_stats
319
- const settings = data.settings || {};
320
- const deadlockStats = data.deadlock_stats;
321
- const settingsCount = Object.keys(settings).length;
322
-
323
- if (deadlockStats && typeof deadlockStats.deadlocks === 'number' && deadlockStats.deadlocks > 0) {
324
- return {
325
- status: 'warning',
326
- message: `${deadlockStats.deadlocks} deadlock${deadlockStats.deadlocks > 1 ? 's' : ''} detected`
327
- };
328
- }
329
-
330
- if (settingsCount === 0) {
331
- return { status: 'info', message: 'No timeout/lock settings found' };
332
- }
333
-
334
- return {
335
- status: 'info',
336
- message: `${settingsCount} timeout/lock setting${settingsCount > 1 ? 's' : ''} collected`
337
- };
338
- }