@tiangong-lca/cli 0.0.22 → 0.0.23

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 CHANGED
@@ -17,8 +17,8 @@ checkPaths:
17
17
  - bin/**
18
18
  - src/cli.ts
19
19
  - src/main.ts
20
- lastReviewedAt: 2026-07-12
21
- lastReviewedCommit: 192ce9cb233af85b8bcf50136d37fd08d4ae8292
20
+ lastReviewedAt: 2026-07-13
21
+ lastReviewedCommit: 4c79df4623e3cf296bc8d1baeea688d78351570a
22
22
  ---
23
23
 
24
24
  # TianGong LCA CLI
@@ -27,6 +27,8 @@ Package: `@tiangong-lca/cli` Executable: `tiangong-lca` Node: `24.x`
27
27
 
28
28
  Review note, 2026-07-12: `dataset maintenance plan/apply/verify` provides current-user RLS-scoped exact-row maintenance with immutable plans, explicit approval, per-action logs, platform audit correlation, and independent readback. `merge-support-aliases` now runs only in `target_mode=owner_draft`: source/target support and all changed rows stay private `state_code=0`; publication is a separate future workflow.
29
29
 
30
+ Review note, 2026-07-13: maintenance scans now prove exact-count pagination even when PostgREST returns fewer rows than the requested `--page-size`. An incomplete or inconsistent scan fails before artifacts, approval, or mutation; under stable filtered membership/order the proof represents a complete ordered multi-request traversal, not one transaction-level/MVCC snapshot.
31
+
30
32
  ## Run
31
33
 
32
34
  One-off published run:
@@ -349,6 +351,10 @@ tiangong-lca dataset maintenance verify \
349
351
  --json
350
352
  ```
351
353
 
354
+ `--page-size` accepts `1-5000` and is only the requested maximum. PostgREST may enforce a lower server-side cap. The CLI requests `Prefer: count=exact`, validates the exact total and returned range from each `Content-Range`, advances the next offset by the number of rows actually returned, and requires strict `id`/`version` ordering without missing or duplicate identities. Each accepted scan records per-table requested/effective page size, page count, rows fetched, exact total, and aggregate entity counts.
355
+
356
+ This completeness proof means the CLI traversed the filtered result while that table's membership and ordering keys remained stable. Because the tables are read through multiple HTTP requests, it is not a transaction-level or MVCC snapshot of one instant; same-cardinality delete/insert churn can evade total and ordering checks. Plan hashes and apply-time drift checks provide the later mutation guard, and operators must avoid concurrent maintenance of the same account while planning or clearing it.
357
+
352
358
  The scope is intentionally narrow:
353
359
 
354
360
  - Each requested row must name its table, exact `id`, exact `version`, expected current owner, and draft `state_code=0` state.
@@ -359,11 +365,13 @@ The scope is intentionally narrow:
359
365
  - Source alias support, target FP/UG, and every changed flow/process must all belong to the authenticated account at `state_code=0`. Public/shared, foreign-owner, mixed-visibility, non-draft, lifecyclemodel, and unsupported action/table rows remain protected.
360
366
  - The CLI classifies and executes an operator-authored scope; it does not decide whether rows are semantically duplicates, canonical replacements, or safe business-level cleanup targets.
361
367
 
362
- `plan` writes the frozen `maintenance-scope.json`, `rls-visible-snapshot.json`, `protected-rows.jsonl`, `reference-impact-report.json`, `maintenance-plan.json`, and `dry-run-report.json`. Alias plans additionally write `exchange-rewrite-plan.jsonl`, freeze current-owner state-0 target FP, target UG, and source UG snapshots for each batch, derive schema-valid desired payloads with matching embedded UUID/version, and include the exact closure, `modified_at`, hashes, conversion evidence, and postconditions in the approved plan. The plan SHA-256 is the approval identity; do not edit or recompute the plan after review.
368
+ `plan` accepts the account scan only after its exact-count proof is complete, then writes the frozen `maintenance-scope.json`, `rls-visible-snapshot.json`, `protected-rows.jsonl`, `reference-impact-report.json`, `maintenance-plan.json`, and `dry-run-report.json`. The snapshot, dry-run report, and newly generated plan carry the aggregate completeness proof, so it is bound into the plan SHA-256. Alias plans additionally write `exchange-rewrite-plan.jsonl`, freeze current-owner state-0 target FP, target UG, and source UG snapshots for each batch, derive schema-valid desired payloads with matching embedded UUID/version, and include the exact closure, `modified_at`, hashes, conversion evidence, and postconditions in the approved plan. The plan SHA-256 is the approval identity; do not edit or recompute the plan after review.
369
+
370
+ `apply` is write-disabled unless all three commit guards are present: `--commit`, `--approve-plan <sha256>`, and `--confirm <current-account-email>`. Before approval is persisted or any write runs, it requires a fresh complete exact-count account scan and re-checks the whole plan for drift; the current completeness proof is recorded in `approval-record.json`. Ordinary draft updates/deletes use their platform paths. The ordered `time` plus `length_time` alias request is sent once to `cmd_dataset_alias_plan_guarded` with `target_visibility=owner_draft`; the CLI has neither a per-dimension fallback nor a 52-write sequential fallback. The RPC locks and validates the complete 52-row/59-exchange closure before both dimensions commit, so a second-dimension failure rolls back the first. It checks actor ownership, state 0, exact payload/timestamp locks and embedded UUID/version, rejects missing or phantom flow/exchange references, and returns one plan summary audit id plus both batch and per-row audit proofs. The CLI writes `alias-plan-progress.jsonl` together with plan-bound per-batch, per-row, and per-exchange ledgers. A lost response or incomplete derived ledger is repaired only by replaying the same whole plan and matching every returned plan and batch proof.
363
371
 
364
- `apply` is write-disabled unless all three commit guards are present: `--commit`, `--approve-plan <sha256>`, and `--confirm <current-account-email>`. Before the first write it re-checks the whole plan for drift and persists `approval-record.json`. Ordinary draft updates/deletes use their platform paths. The ordered `time` plus `length_time` alias request is sent once to `cmd_dataset_alias_plan_guarded` with `target_visibility=owner_draft`; the CLI has neither a per-dimension fallback nor a 52-write sequential fallback. The RPC locks and validates the complete 52-row/59-exchange closure before both dimensions commit, so a second-dimension failure rolls back the first. It checks actor ownership, state 0, exact payload/timestamp locks and embedded UUID/version, rejects missing or phantom flow/exchange references, and returns one plan summary audit id plus both batch and per-row audit proofs. The CLI writes `alias-plan-progress.jsonl` together with plan-bound per-batch, per-row, and per-exchange ledgers. A lost response or incomplete derived ledger is repaired only by replaying the same whole plan and matching every returned plan and batch proof.
372
+ `verify` requires another complete exact-count account readback rather than trusting the apply report, records its completeness proof, and writes `readback-verify-report.json` in its own output directory. For alias plans it also requires both successful batch records, all 52 correlated row records, all 59 unique exchange records, unchanged support snapshots, and exact desired row payloads. It validates the RPC-returned audit ids against the local proof chain; it does not independently query `public.command_audit_log`.
365
373
 
366
- `verify` performs a fresh remote readback rather than trusting the apply report and writes `readback-verify-report.json` in its own output directory. For alias plans it also requires both successful batch records, all 52 correlated row records, all 59 unique exchange records, unchanged support snapshots, and exact desired row payloads. It validates the RPC-returned audit ids against the local proof chain; it does not independently query `public.command_audit_log`.
374
+ `dataset maintenance clear-account` uses the same exact-count rule for its initial five-table snapshot, per-table commit checks, and a final fresh scan of all five tables. It reports `cleared_account` only when that final aggregate proof exists with `row_count=0`; if the final proof fails after deletions begin, it still writes a `completed_with_failures` audit report. If the initial scan cannot prove completeness, it writes no snapshot or approval artifact and performs zero deletes.
367
375
 
368
376
  Foundry and skills may prepare the scope, invoke these commands, and retain their artifacts. They must not replace the CLI with direct SQL, service-role access, raw REST mutation, or private Supabase delete/update code.
369
377
 
package/dist/src/cli.js CHANGED
@@ -354,7 +354,7 @@ Options:
354
354
  --scope <file> Maintenance scope manifest
355
355
  --operation <value> Intended row-level maintenance operation
356
356
  --out-dir <dir> Artifact directory
357
- --page-size <n> Snapshot page size
357
+ --page-size <n> Requested snapshot page size, 1-5000 (default: 1000); server caps are followed using exact counts
358
358
  --timeout-ms <n> Request timeout in milliseconds
359
359
  --json Print compact JSON
360
360
  -h, --help
@@ -390,7 +390,7 @@ function renderDatasetMaintenanceVerifyHelp() {
390
390
  Options:
391
391
  --plan <file> Immutable maintenance-plan.json
392
392
  --out-dir <dir> Optional verification artifact directory
393
- --page-size <n> Readback page size
393
+ --page-size <n> Requested readback page size, 1-5000 (default: 1000); server caps are followed using exact counts
394
394
  --timeout-ms <n> Request timeout in milliseconds
395
395
  --json Print compact JSON
396
396
  -h, --help
@@ -410,7 +410,7 @@ Behavior:
410
410
  Options:
411
411
  --state-code <n> Optional repeatable state_code filter. Omit to clear all state codes for the current account.
412
412
  --out-dir <dir> Artifact directory (default: ./dataset-maintenance/clear-account)
413
- --page-size <n> Snapshot page size, 1-5000 (default: 1000)
413
+ --page-size <n> Requested snapshot page size, 1-5000 (default: 1000); server caps are followed using exact counts
414
414
  --timeout-ms <n> Request timeout in milliseconds (default: 10000)
415
415
  --commit Execute deletion. Without this flag the command only writes a dry-run report.
416
416
  --dry-run Explicit dry-run mode
@@ -424,6 +424,8 @@ Outputs written under --out-dir:
424
424
  - approval-record.json (commit only)
425
425
  - commit-report.json (commit only)
426
426
  - readback-verify-report.json (commit only)
427
+
428
+ Every snapshot/readback must prove complete exact-count pagination before an artifact or delete is accepted.
427
429
  `.trim();
428
430
  }
429
431
  function renderDatasetContractHelp() {