@cartanova/qgrid-cli 2.5.0 → 2.5.2

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.
@@ -4,7 +4,7 @@ Use this reference for qgrid startup, configuration, and runtime-facing environm
4
4
 
5
5
  ## CLI options
6
6
 
7
- - `--db <url>`: PostgreSQL URL in `postgres://user:password@host:port/dbname` or `postgresql://...` form. Parsed by `packages/cli/src/cli.ts` and copied into `SONAMU_DB_*` env vars before server boot.
7
+ - `--db <url>`: PostgreSQL URL in `postgres://user:password@host:port/dbname` or `postgresql://...` form. Parsed by `packages/cli/src/cli.ts` as the highest-priority database input.
8
8
  - `-p, --port <port>`: server port. Default `44900`. The CLI validates the port and refuses to start if it is already in use.
9
9
  - `--skip-update`: skip qgrid CLI self-update check.
10
10
 
@@ -15,15 +15,31 @@ The CLI also ensures runtime CLIs are installed/current enough:
15
15
  - `codex` from `@openai/codex`, required for OpenAI tokens.
16
16
  - `claude` from `@anthropic-ai/claude-code`, required for Anthropic tokens.
17
17
 
18
+ ## CLI database env vars
19
+
20
+ `QGRID_DB_*` is the public database configuration for the packaged qgrid CLI.
21
+ Immediately before server boot, the CLI copies the resolved values into
22
+ Sonamu's internal `SONAMU_DB_*` variables. `--db` overrides `QGRID_DB_*`;
23
+ `QGRID_DB_*` overrides an existing `SONAMU_DB_*` value. The latter remains a
24
+ compatibility fallback and should not be the environment contract shown to CLI
25
+ users.
26
+
27
+ | Env | Default | Meaning |
28
+ |---|---:|---|
29
+ | `QGRID_DB_HOST` | `localhost` | PostgreSQL host. |
30
+ | `QGRID_DB_PORT` | `5432` | PostgreSQL port. |
31
+ | `QGRID_DB_USER` | `postgres` | PostgreSQL user. |
32
+ | `QGRID_DB_PASSWORD` | `postgres` | PostgreSQL password. |
33
+ | `QGRID_DB_NAME` | `qgrid` | PostgreSQL database. |
34
+
35
+ Source deployments that run `packages/api` without the packaged CLI must use
36
+ Sonamu's native `SONAMU_DB_HOST`, `SONAMU_DB_PORT`, `SONAMU_DB_USER`,
37
+ `SONAMU_DB_PASSWORD`, and `SONAMU_DB_NAME` variables directly.
38
+
18
39
  ## Server env vars agents should know
19
40
 
20
41
  | Env | Default | Meaning |
21
42
  |---|---:|---|
22
- | `SONAMU_DB_HOST` | `localhost` | PostgreSQL host. |
23
- | `SONAMU_DB_PORT` | `5432` | PostgreSQL port. |
24
- | `SONAMU_DB_USER` | `postgres` | PostgreSQL user. |
25
- | `SONAMU_DB_PASSWORD` | `postgres` | PostgreSQL password. |
26
- | `SONAMU_DB_NAME` | `qgrid` | PostgreSQL database. |
27
43
  | `NODE_ENV` | direct API: `development`; packaged CLI: `production` | Sonamu runtime profile. Use `staging` for remote non-production API deployments such as dev0. The profile does not create or rename the explicitly configured DB. |
28
44
  | `HOST` | `localhost` | Sonamu server listen host when running API directly. |
29
45
  | `PORT` | `44900` | Sonamu server listen port. In CLI mode this is derived from `--port`, not read as user input. |
@@ -64,7 +80,7 @@ When helping a user set up qgrid locally, check for `QGRID_PROJECT_NAME` or conf
64
80
 
65
81
  `packages/api/src/index.ts` runs `bootstrapServer` (`server-bootstrap.ts`) with a strict init → migrate → listen order:
66
82
 
67
- 1. `Sonamu.init()` loads Sonamu's native dotenv snapshot for the active `NODE_ENV` and reads the database connection from `SONAMU_DB_*`. Selecting `staging` alone does not create a staging DB; `SONAMU_DB_NAME` remains the explicit database name.
83
+ 1. The packaged CLI maps public `QGRID_DB_*` inputs to internal `SONAMU_DB_*`, then `Sonamu.init()` loads Sonamu's native dotenv snapshot for the active `NODE_ENV` and reads that internal database connection. Direct source API deployments set `SONAMU_DB_*` themselves. Selecting `staging` alone does not create a staging DB; the explicit database name remains authoritative.
68
84
  2. `runRequiredMigrations` (`startup-migrations.ts`) applies latest migrations from `packages/api/src/migrations` before the server listens. Migration failure exits the process — qgrid must not boot against a schema missing required columns such as `tokens.weight`. This is a hard-fail; it used to be a soft-fail warn inside `onStart`.
69
85
  3. `Sonamu.createServer()` starts the server. Its `onStart` in `packages/api/src/sonamu.config.ts`:
70
86
  1. Ensures PostgreSQL `tokens_changed` triggers.
@@ -98,6 +98,7 @@ Key decisions:
98
98
  - Claude Code `stream-json` drops structural assistant role replay in the outbound API payload. qgrid flattens prior history into text because structural role replay through the CLI is not reliable.
99
99
  - Claude Code `--json-schema` is not constrained native tool calling. It creates a `StructuredOutput` tool and validates after model generation. Keep schemas strict and fail on non-success subtypes or retry exhaustion.
100
100
  - `MAX_STRUCTURED_OUTPUT_RETRIES=1` means one attempt. Do not set it to 0 expecting "no retry but one attempt"; that can mean no useful attempt.
101
+ - The retry pin is scoped to **streaming** structured calls only. SON-495 fixed retries to 1 because a retry inside a stream doubles wall-clock time — a latency argument that does not hold for non-streaming `generate`. Applying the pin to both paths made every non-streaming structured call fail on its first rejected attempt, and since Claude complies with structured output less reliably than OpenAI, that produced a 39.6% `error_max_structured_output_retries` rate for `deti_production` on Opus 4.8 (dev0, 2026-07). Non-streaming now uses Claude Code's default retry budget; `includePartialMessages` is the streaming discriminator.
101
102
  - 1M context support is measured per model and is a mitigation, not a guarantee. It reduces compaction/hang frequency for huge prompts, but does not make every structured prompt reliable.
102
103
  - Spawn env must be whitelisted. Never pass inherited `ANTHROPIC_API_KEY`, `ANTHROPIC_AUTH_TOKEN`, or `ANTHROPIC_BASE_URL` unless intentionally building an API-key/proxy path.
103
104
  - `--setting-sources project` is required for shared-service isolation. User/local Claude settings can load hooks or memory and leak context across requests.