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.
- package/README.md +154 -0
- package/dist/bin/postgres-ai.js +2911 -255
- package/package.json +12 -3
- package/schemas/A002.schema.json +63 -0
- package/schemas/A003.schema.json +73 -0
- package/schemas/A004.schema.json +81 -0
- package/schemas/A007.schema.json +71 -0
- package/schemas/A013.schema.json +61 -0
- package/schemas/D001.schema.json +71 -0
- package/schemas/D004.schema.json +136 -0
- package/schemas/F001.schema.json +73 -0
- package/schemas/F002.schema.json +108 -0
- package/schemas/F003.schema.json +138 -0
- package/schemas/F004.schema.json +125 -0
- package/schemas/F005.schema.json +131 -0
- package/schemas/F009.schema.json +155 -0
- package/schemas/G001.schema.json +135 -0
- package/schemas/G003.schema.json +90 -0
- package/schemas/H001.schema.json +141 -0
- package/schemas/H002.schema.json +129 -0
- package/schemas/H004.schema.json +128 -0
- package/schemas/I001.schema.json +149 -0
- package/schemas/K001.schema.json +161 -0
- package/schemas/K003.schema.json +163 -0
- package/schemas/K004.schema.json +110 -0
- package/schemas/K005.schema.json +110 -0
- package/schemas/K006.schema.json +110 -0
- package/schemas/K007.schema.json +110 -0
- package/schemas/K008.schema.json +110 -0
- package/schemas/M001.schema.json +119 -0
- package/schemas/M002.schema.json +110 -0
- package/schemas/M003.schema.json +128 -0
- package/schemas/N001.schema.json +161 -0
- package/schemas/query.schema.json +62 -0
- package/CHANGELOG.md +0 -11
- package/bin/postgres-ai.ts +0 -5578
- package/bun.lock +0 -258
- package/bunfig.toml +0 -20
- package/lib/aas-onboard.ts +0 -251
- package/lib/auth-server.ts +0 -285
- package/lib/checkup-api.ts +0 -526
- package/lib/checkup-dictionary.ts +0 -103
- package/lib/checkup-summary.ts +0 -338
- package/lib/checkup.ts +0 -2261
- package/lib/config.ts +0 -171
- package/lib/init.ts +0 -1152
- package/lib/instances.ts +0 -245
- package/lib/issues.ts +0 -1060
- package/lib/mcp-server.ts +0 -667
- package/lib/metrics-loader.ts +0 -134
- package/lib/pkce.ts +0 -79
- package/lib/reports.ts +0 -373
- package/lib/storage.ts +0 -367
- package/lib/supabase.ts +0 -826
- package/lib/util.ts +0 -134
- package/packages/postgres-ai/README.md +0 -26
- package/packages/postgres-ai/bin/postgres-ai.js +0 -27
- package/packages/postgres-ai/package.json +0 -27
- package/scripts/embed-checkup-dictionary.ts +0 -115
- package/scripts/embed-metrics.ts +0 -160
- package/scripts/generate-release-notes.ts +0 -668
- package/test/PERMISSION_CHECK_TEST_SUMMARY.md +0 -139
- package/test/aas-onboard.test.ts +0 -301
- package/test/auth.test.ts +0 -287
- package/test/checkup.integration.test.ts +0 -413
- package/test/checkup.test.ts +0 -3626
- package/test/compose-cmd.test.ts +0 -120
- package/test/config-consistency.test.ts +0 -352
- package/test/init.integration.test.ts +0 -438
- package/test/init.test.ts +0 -1816
- package/test/issues.cli.test.ts +0 -1162
- package/test/issues.test.ts +0 -456
- package/test/mcp-server.test.ts +0 -2530
- package/test/monitoring.test.ts +0 -746
- package/test/permission-check-sql.test.ts +0 -116
- package/test/reports.cli.test.ts +0 -793
- package/test/reports.test.ts +0 -977
- package/test/schema-validation.test.ts +0 -231
- package/test/storage.test.ts +0 -935
- package/test/supabase.test.ts +0 -709
- package/test/targets-add-config.test.ts +0 -28
- package/test/test-utils.ts +0 -190
- package/test/upgrade.test.ts +0 -1056
- package/test/util.test.ts +0 -44
- package/tsconfig.json +0 -20
package/README.md
CHANGED
|
@@ -445,6 +445,155 @@ postgresai auth --debug \
|
|
|
445
445
|
Notes:
|
|
446
446
|
- If `PGAI_UI_BASE_URL` is not set, the default is `https://console.postgres.ai`.
|
|
447
447
|
|
|
448
|
+
## Embedding checkup
|
|
449
|
+
|
|
450
|
+
Express checkup is designed to be embedded by **host applications** — for
|
|
451
|
+
example Rails/Django/Node applications and database-diagnostics admin UIs that
|
|
452
|
+
want to run PostgreSQL health checks and render the findings themselves. The
|
|
453
|
+
supported integration surface is the CLI's machine contract: run the checkup
|
|
454
|
+
command, read a single JSON document from stdout, and parse it against the
|
|
455
|
+
published JSON schemas.
|
|
456
|
+
|
|
457
|
+
### The `--no-upload --json` ABI
|
|
458
|
+
|
|
459
|
+
```bash
|
|
460
|
+
PGPASSWORD=... postgresai checkup \
|
|
461
|
+
postgresql://monitoring_user@host:5432/dbname \
|
|
462
|
+
--no-upload --json
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
- **stdout** carries **exactly one JSON object**, keyed by check ID:
|
|
466
|
+
|
|
467
|
+
```json
|
|
468
|
+
{
|
|
469
|
+
"H002": { "contract_version": "1.0.0", "checkId": "H002", "...": "..." },
|
|
470
|
+
"F003": { "contract_version": "1.0.0", "checkId": "F003", "...": "..." }
|
|
471
|
+
}
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
It is a single document (not newline-delimited JSON). Each value is a report
|
|
475
|
+
that validates against the schema shipped at
|
|
476
|
+
`postgresai/schemas/<CHECK_ID>.schema.json`.
|
|
477
|
+
- Restrict the run to one check with `--check-id <ID>` (or the positional form
|
|
478
|
+
`postgresai checkup <ID> <conn>`); stdout is then a one-key object.
|
|
479
|
+
- **stderr** carries only human-readable diagnostics (progress, warnings,
|
|
480
|
+
errors). It never contains report JSON — machine consumers should read stdout
|
|
481
|
+
only. Do not parse stderr as JSON.
|
|
482
|
+
- **Exit codes**: `0` on success; non-zero when the run fails (connection
|
|
483
|
+
failure, insufficient permissions, an unknown/unavailable check ID, or a
|
|
484
|
+
failing check). On a non-zero exit, no JSON report object is written to
|
|
485
|
+
stdout.
|
|
486
|
+
- Pass `--no-upload` to keep the run fully local (no network calls to the
|
|
487
|
+
PostgresAI API and no API key required).
|
|
488
|
+
|
|
489
|
+
### Passing credentials
|
|
490
|
+
|
|
491
|
+
Pass the database password via the **`PGPASSWORD`** environment variable (the
|
|
492
|
+
libpq standard), never on the command line. Credentials in `argv` are visible to
|
|
493
|
+
other processes (e.g. `ps`); `PGPASSWORD` is not. All other libpq environment
|
|
494
|
+
variables (`PGHOST`, `PGPORT`, `PGUSER`, `PGDATABASE`, `PGSSLMODE`) are also
|
|
495
|
+
honored.
|
|
496
|
+
|
|
497
|
+
### Permissions the connection needs
|
|
498
|
+
|
|
499
|
+
The checkup command runs a permissions preflight and expects a prepared
|
|
500
|
+
monitoring role. Provision it once with `prepare-db` (run as an admin/superuser):
|
|
501
|
+
|
|
502
|
+
```bash
|
|
503
|
+
PGPASSWORD=<admin-pw> postgresai prepare-db \
|
|
504
|
+
postgresql://admin@host:5432/dbname \
|
|
505
|
+
--monitoring-user postgres_ai_mon \
|
|
506
|
+
--password <monitoring-pw>
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
This creates the monitoring role, the `postgres_ai` schema and helper
|
|
510
|
+
function(s), and grants the required read-only privileges (`pg_monitor`
|
|
511
|
+
membership, `SELECT` on the relevant catalogs/views, and the appropriate
|
|
512
|
+
`search_path`). Host applications then run checkup as that role. See
|
|
513
|
+
[prepare-db](#prepare-db-create-monitoring-user-in-postgres) for details and
|
|
514
|
+
provider-specific behavior.
|
|
515
|
+
|
|
516
|
+
### What runs locally vs. server-side
|
|
517
|
+
|
|
518
|
+
| Output | Where it is produced | Available offline (`--no-upload`) |
|
|
519
|
+
|--------|----------------------|-----------------------------------|
|
|
520
|
+
| Schema-valid JSON reports | Local (CLI) | Yes |
|
|
521
|
+
| Severity summaries (`summary`: `status` + `message`) | Local (CLI) | Yes |
|
|
522
|
+
| Local conclusions/recommendations for the checks that implement them (e.g. F003, H001) | Local (CLI) | Yes |
|
|
523
|
+
| Rich markdown analysis and prose recommendations | **Server-side** (PostgresAI API, via `--markdown`) | No — requires a network call and, for full detail, an API key |
|
|
524
|
+
|
|
525
|
+
In short: the local embed gives you structured JSON, per-check severity, and
|
|
526
|
+
the conclusions each check implements today. The full narrative analysis is an
|
|
527
|
+
API-side capability. Embedders that only need structured findings and severity
|
|
528
|
+
never have to call the API.
|
|
529
|
+
|
|
530
|
+
For every new or updated check, local JSON must include `conclusions` and
|
|
531
|
+
`recommendations`. Server-side markdown analysis can enrich those verdicts, but
|
|
532
|
+
must never be their only source. The coverage checklist in
|
|
533
|
+
[work item #285](https://gitlab.com/postgres-ai/postgresai/-/work_items/285)
|
|
534
|
+
tracks which existing checks have completed this migration.
|
|
535
|
+
|
|
536
|
+
### Loading a check schema
|
|
537
|
+
|
|
538
|
+
Every published `postgresai` package contains the JSON Schemas used by that
|
|
539
|
+
exact CLI build. Resolve schemas through the public package subpath instead of
|
|
540
|
+
depending on the tarball layout:
|
|
541
|
+
|
|
542
|
+
```js
|
|
543
|
+
import { readFile } from "node:fs/promises";
|
|
544
|
+
import { createRequire } from "node:module";
|
|
545
|
+
|
|
546
|
+
const require = createRequire(import.meta.url);
|
|
547
|
+
const schemaPath = require.resolve("postgresai/schemas/H002.schema.json");
|
|
548
|
+
const schema = JSON.parse(await readFile(schemaPath, "utf8"));
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
Schemas are generated during build and package lifecycle hooks. For an unbuilt
|
|
552
|
+
linked checkout or workspace dependency, run `npm run sync-schemas` first.
|
|
553
|
+
|
|
554
|
+
Replace `H002` with the report's `checkId`. The package ships one
|
|
555
|
+
`*.schema.json` file per check, plus `query.schema.json`. These files follow the
|
|
556
|
+
`contract_version` policy below: additive schema changes require a minor
|
|
557
|
+
contract-version bump, while breaking changes require a major bump.
|
|
558
|
+
|
|
559
|
+
### The versioned JSON contract
|
|
560
|
+
|
|
561
|
+
Every report envelope carries a **`contract_version`** (semver). This is the
|
|
562
|
+
public compatibility surface — the report envelope plus the per-check JSON
|
|
563
|
+
schemas shipped in `postgresai/schemas/` plus this stdout/stderr/exit-code ABI. It is
|
|
564
|
+
independent of the CLI/package `version`: the CLI can be released many times
|
|
565
|
+
without the contract changing.
|
|
566
|
+
|
|
567
|
+
Compatibility policy (semver applied to the contract, not the code):
|
|
568
|
+
|
|
569
|
+
- **PATCH** (`x.y.Z`) — editorial/no-op changes that cannot affect a consumer.
|
|
570
|
+
- **MINOR** (`x.Y.0`) — **additive, backward-compatible** changes: new optional
|
|
571
|
+
fields in the envelope or a report, new checks, new schema files. Existing
|
|
572
|
+
valid reports stay valid and existing consumers keep working untouched.
|
|
573
|
+
- **MAJOR** (`X.0.0`) — **breaking** changes: removing/renaming a field,
|
|
574
|
+
tightening a type, making an optional field required, or changing the JSON ABI
|
|
575
|
+
in a way that could break a consumer parsing the previous format.
|
|
576
|
+
|
|
577
|
+
A consumer should accept any report whose `contract_version` shares its **major**
|
|
578
|
+
and has a **minor ≥** the minimum it was built against. Pin the major, tolerate
|
|
579
|
+
additive minors, and treat a major bump as a required review.
|
|
580
|
+
|
|
581
|
+
The current contract version is **`1.0.0`**.
|
|
582
|
+
|
|
583
|
+
### Envelope fields
|
|
584
|
+
|
|
585
|
+
Beyond the check-specific `results`, every report includes:
|
|
586
|
+
|
|
587
|
+
| Field | Meaning |
|
|
588
|
+
|-------|---------|
|
|
589
|
+
| `contract_version` | Version of the JSON report contract (see above). |
|
|
590
|
+
| `checkId` / `checkTitle` | The check identifier and its human title. |
|
|
591
|
+
| `generation_mode` | `"express"` for CLI-generated reports. |
|
|
592
|
+
| `summary` | Optional `{ "status": "ok" \| "warning" \| "info", "message": string }` severity summary. |
|
|
593
|
+
| `timestamptz` | Report generation time (ISO 8601). |
|
|
594
|
+
| `nodes` | `{ "primary": string, "standbys": string[] }`. |
|
|
595
|
+
| `version` / `build_ts` | CLI/package version and build timestamp (may be null). |
|
|
596
|
+
|
|
448
597
|
## Development
|
|
449
598
|
|
|
450
599
|
### Testing
|
|
@@ -471,7 +620,12 @@ Coverage configuration is in `bunfig.toml`. Reports are generated in `coverage/`
|
|
|
471
620
|
- Node.js 18 or higher
|
|
472
621
|
- Docker and Docker Compose
|
|
473
622
|
|
|
623
|
+
## Feedback
|
|
624
|
+
|
|
625
|
+
Have an idea or found a rough edge? Run `pgai feedback` (or `pgai feedback --open`) or share it directly at https://gitlab.com/postgres-ai/postgresai/-/work_items/300. Set `PGAI_NO_FEEDBACK_TIP=1` to silence the occasional in-CLI reminder.
|
|
626
|
+
|
|
474
627
|
## Learn more
|
|
475
628
|
|
|
476
629
|
- Documentation: https://postgres.ai/docs
|
|
477
630
|
- Issues: https://gitlab.com/postgres-ai/postgres_ai/-/issues
|
|
631
|
+
- Ideas / feedback: https://gitlab.com/postgres-ai/postgresai/-/work_items/300
|