@tiangong-lca/cli 0.0.23 → 0.0.24
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 +14 -6
- package/dist/src/cli.js +20 -9
- package/dist/src/cli.js.map +1 -1
- package/dist/src/lib/dataset-maintenance-apply.js +269 -4
- package/dist/src/lib/dataset-maintenance-apply.js.map +1 -1
- package/dist/src/lib/dataset-maintenance-contract.js +118 -16
- package/dist/src/lib/dataset-maintenance-contract.js.map +1 -1
- package/dist/src/lib/dataset-maintenance-derivatives.js +265 -0
- package/dist/src/lib/dataset-maintenance-derivatives.js.map +1 -0
- package/dist/src/lib/dataset-maintenance-plan.js +38 -6
- package/dist/src/lib/dataset-maintenance-plan.js.map +1 -1
- package/dist/src/lib/dataset-maintenance-remote.js +25 -0
- package/dist/src/lib/dataset-maintenance-remote.js.map +1 -1
- package/dist/src/lib/dataset-maintenance-verify.js +309 -3
- package/dist/src/lib/dataset-maintenance-verify.js.map +1 -1
- package/package.json +1 -1
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-
|
|
21
|
-
lastReviewedCommit:
|
|
20
|
+
lastReviewedAt: 2026-07-14
|
|
21
|
+
lastReviewedCommit: ce8c18f270725adad789ada8f4582ca0e97e4117
|
|
22
22
|
---
|
|
23
23
|
|
|
24
24
|
# TianGong LCA CLI
|
|
@@ -29,6 +29,8 @@ Review note, 2026-07-12: `dataset maintenance plan/apply/verify` provides curren
|
|
|
29
29
|
|
|
30
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
31
|
|
|
32
|
+
Review note, 2026-07-14: maintenance now includes the protected derivative-only `rebuild-derivatives` operation. V1 plans exactly one current-owner state-0 process with `action=rebuild_derivatives`, `target_mode=owner_draft`, and components `extracted_md` plus `embedding_ft`. Apply only proves guarded-RPC admission (`accepted`/`queued`); independent verify reports `pending`, `passed`, or `failed`.
|
|
33
|
+
|
|
32
34
|
## Run
|
|
33
35
|
|
|
34
36
|
One-off published run:
|
|
@@ -278,6 +280,7 @@ tiangong-lca dataset evidence-search plan --query "中国2026年电力结构数
|
|
|
278
280
|
tiangong-lca dataset evidence-search run --input ./evidence-search.request.json --results ./search-results.json --out-dir /abs/path/to/evidence-search --json
|
|
279
281
|
tiangong-lca dataset references rewrite --input ./rows.jsonl --from flow:<old-id>@<old-version> --to flow:<new-id>@<new-version> --out-dir /abs/path/to/dataset-rewrite --json
|
|
280
282
|
tiangong-lca dataset maintenance plan --scope ./maintenance-scope.json --operation redo-import --out-dir /abs/path/to/dataset-maintenance --page-size 1000 --timeout-ms 10000 --json
|
|
283
|
+
tiangong-lca dataset maintenance plan --scope ./derivative-rebuild-scope.json --operation rebuild-derivatives --out-dir /abs/path/to/derivative-rebuild --json
|
|
281
284
|
tiangong-lca dataset maintenance apply --plan /abs/path/to/dataset-maintenance/maintenance-plan.json --commit --approve-plan <sha256> --confirm <current-account-email> --timeout-ms 10000 --json
|
|
282
285
|
tiangong-lca dataset maintenance verify --plan /abs/path/to/dataset-maintenance/maintenance-plan.json --out-dir /abs/path/to/dataset-maintenance/verify --page-size 1000 --timeout-ms 10000 --json
|
|
283
286
|
tiangong-lca lifecyclemodel auto-build --input ./examples/lifecyclemodel-auto-build.request.json --out-dir /abs/path/to/lifecyclemodel-run --json
|
|
@@ -324,7 +327,7 @@ For `dataset references rewrite`, `--commit` executes the state-aware save-draft
|
|
|
324
327
|
|
|
325
328
|
## Dataset Maintenance
|
|
326
329
|
|
|
327
|
-
`dataset maintenance plan/apply/verify` is the row-level cleanup surface for bad imports
|
|
330
|
+
`dataset maintenance plan/apply/verify` is the row-level cleanup surface for bad imports, the fixed BAFU private alias rewrite, and one protected derivative-only process rebuild. It runs as the currently authenticated user and relies on RLS for visibility and ownership enforcement.
|
|
328
331
|
|
|
329
332
|
```bash
|
|
330
333
|
tiangong-lca dataset maintenance plan \
|
|
@@ -351,6 +354,8 @@ tiangong-lca dataset maintenance verify \
|
|
|
351
354
|
--json
|
|
352
355
|
```
|
|
353
356
|
|
|
357
|
+
For the derivative-only profile, use the same three commands with `--operation rebuild-derivatives`. Its scope must contain exactly one `processes` action with `action: "rebuild_derivatives"`, `target_mode: "owner_draft"`, expected current owner, expected `state_code: 0`, and the exact component set `extracted_md` plus `embedding_ft`.
|
|
358
|
+
|
|
354
359
|
`--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
360
|
|
|
356
361
|
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.
|
|
@@ -358,18 +363,21 @@ This completeness proof means the CLI traversed the filtered result while that t
|
|
|
358
363
|
The scope is intentionally narrow:
|
|
359
364
|
|
|
360
365
|
- Each requested row must name its table, exact `id`, exact `version`, expected current owner, and draft `state_code=0` state.
|
|
361
|
-
- `--operation` accepts `delete`, `retire`, `redo-import`, `repair-references`,
|
|
366
|
+
- `--operation` accepts `delete`, `retire`, `redo-import`, `repair-references`, `merge-support-aliases`, or `rebuild-derivatives`; it records the operator's maintenance intent and does not broaden the eligible row actions.
|
|
362
367
|
- Only current-user `contacts`, `sources`, `flows`, and `processes` can become `save_draft` or `delete` actions.
|
|
363
368
|
- `merge-support-aliases` requires top-level `target_mode: "owner_draft"` and accepts only two named batches, `time` and `length_time`. The scope must bind reviewed current-owner draft source and target FP/UG exact ids/versions to 52 `update_json_ordered` actions: 25 time rows (1 FP, 10 flows, 14 processes) and 27 length-time rows (1 FP, 13 flows, 13 processes). Process actions freeze every selected exchange index, internal id, flow id/version, direction, before hash, and both amount strings.
|
|
364
369
|
- The alias factors are exact decimal strings: `0.00011415525114155251` for time and `1000` for length-time. Planning requires exactly 20 and 39 selected exchanges, preserves exactly 309 other exchanges in the affected processes, and proves the fixed source-zero/target-reference postconditions. The transformation changes references and the selected `meanAmount`/`resultingAmount`; it does not delete the source FP/UG rows.
|
|
365
370
|
- 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.
|
|
371
|
+
- `rebuild-derivatives` accepts exactly one exact-version `processes` row and is bidirectionally bound to `action=rebuild_derivatives`, `target_mode=owner_draft`, and components `extracted_md` plus `embedding_ft`. It cannot target a public/shared row, a foreign owner, a non-draft row, another table, multiple actions, or a partial/different component set. It rebuilds derivatives only; the primary process payload, owner/state, and `modified_at` remain unchanged.
|
|
366
372
|
- 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.
|
|
367
373
|
|
|
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.
|
|
374
|
+
`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. A derivative rebuild plan additionally obtains a database-produced snapshot for only the exact target action and binds its primary and derivative preconditions into the plan; large markdown/vector fields are not added to the account-wide scan. The plan SHA-256 is the approval identity; do not edit or recompute the plan after review.
|
|
369
375
|
|
|
370
376
|
`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.
|
|
371
377
|
|
|
372
|
-
`
|
|
378
|
+
For `rebuild-derivatives`, apply submits the frozen single-action plan only to the authenticated guarded RPC. The database admission envelope must report `queued`; the CLI records that durable admission as an `accepted` action with queued proof. It does not mean markdown or embedding generation has completed. Replay must return the same durable request/proof rather than enqueueing a second rebuild. There is no fallback to a direct Edge call, `admin embedding-run`, a raw queue, SQL, service-role credentials, or raw REST mutation.
|
|
379
|
+
|
|
380
|
+
`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`. For derivative rebuild plans, verify reads the durable request plus a fresh action-scoped process snapshot and reports only `pending`, `passed`, or `failed`. Database statuses `queued`, `dispatching`, `markdown_pending`, and `embedding_pending` map to `pending`; `completed` maps to `passed` only when both requested derivatives are current and every frozen primary-field precondition remains unchanged; `stale` and `failed` map to `failed`. The raw status proof, including `phase` and `fence_active`, is preserved in the report. A failed rebuild does not by itself prove that the primary-row write fence has been released.
|
|
373
381
|
|
|
374
382
|
`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.
|
|
375
383
|
|
package/dist/src/cli.js
CHANGED
|
@@ -319,8 +319,8 @@ function renderDatasetMaintenanceHelp() {
|
|
|
319
319
|
Actions:
|
|
320
320
|
clear-account Dry-run or delete current authenticated account-owned lifecyclemodels, processes, flows, sources, and contacts.
|
|
321
321
|
plan Build an immutable maintenance plan from a scope manifest, visible remote snapshot, dependency impact report, and intended operation.
|
|
322
|
-
apply Execute an approved plan through current-user RLS and platform dataset command paths; never bypass RLS
|
|
323
|
-
verify Re-fetch
|
|
322
|
+
apply Execute or durably admit an approved plan through current-user RLS and platform dataset command paths; never bypass RLS.
|
|
323
|
+
verify Re-fetch rows, references, or derivative request state and report passed, pending, or failed independently of apply.
|
|
324
324
|
|
|
325
325
|
Safety:
|
|
326
326
|
plan and verify are read-only.
|
|
@@ -339,6 +339,7 @@ Examples:
|
|
|
339
339
|
tiangong-lca dataset maintenance clear-account --out-dir ./account-clear --json
|
|
340
340
|
tiangong-lca dataset maintenance clear-account --commit --confirm user@example.com --out-dir ./account-clear
|
|
341
341
|
tiangong-lca dataset maintenance plan --scope ./maintenance-scope.json --operation merge-support-aliases --out-dir ./dataset-maintenance
|
|
342
|
+
tiangong-lca dataset maintenance plan --scope ./derivative-rebuild-scope.json --operation rebuild-derivatives --out-dir ./derivative-rebuild
|
|
342
343
|
tiangong-lca dataset maintenance apply --plan ./dataset-maintenance/maintenance-plan.json --commit --approve-plan <sha256> --confirm user@example.com
|
|
343
344
|
tiangong-lca dataset maintenance verify --plan ./dataset-maintenance/maintenance-plan.json --out-dir ./dataset-maintenance/verify
|
|
344
345
|
`.trim();
|
|
@@ -348,7 +349,7 @@ function renderDatasetMaintenancePlanHelp() {
|
|
|
348
349
|
tiangong-lca dataset maintenance plan --scope <file> --operation <operation> --out-dir <dir> [options]
|
|
349
350
|
|
|
350
351
|
Operations:
|
|
351
|
-
delete | retire | redo-import | repair-references | merge-support-aliases
|
|
352
|
+
delete | retire | redo-import | repair-references | merge-support-aliases | rebuild-derivatives
|
|
352
353
|
|
|
353
354
|
Options:
|
|
354
355
|
--scope <file> Maintenance scope manifest
|
|
@@ -360,7 +361,8 @@ Options:
|
|
|
360
361
|
-h, --help
|
|
361
362
|
|
|
362
363
|
Outputs written under --out-dir include the immutable maintenance-plan.json, visible snapshot,
|
|
363
|
-
protected-row ledger, reference-impact report, and dry-run report.
|
|
364
|
+
protected-row ledger, reference-impact report, and dry-run report. rebuild-derivatives additionally
|
|
365
|
+
freezes one action-scoped database snapshot without expanding the account scan with vector data.
|
|
364
366
|
`.trim();
|
|
365
367
|
}
|
|
366
368
|
function renderDatasetMaintenanceApplyHelp() {
|
|
@@ -370,6 +372,7 @@ function renderDatasetMaintenanceApplyHelp() {
|
|
|
370
372
|
Behavior:
|
|
371
373
|
Commit-only. The command rejects dry-run mode, a missing --commit flag, a plan hash mismatch,
|
|
372
374
|
or a confirmation email that does not match the current authenticated account.
|
|
375
|
+
For rebuild-derivatives, success means guarded admission is queued; it never means derivatives completed.
|
|
373
376
|
|
|
374
377
|
Options:
|
|
375
378
|
--plan <file> Immutable maintenance-plan.json
|
|
@@ -380,7 +383,7 @@ Options:
|
|
|
380
383
|
--json Print compact JSON
|
|
381
384
|
-h, --help
|
|
382
385
|
|
|
383
|
-
Outputs include approval-record.json and commit-report.json alongside an append-only action ledger.
|
|
386
|
+
Outputs include approval-record.json and commit-report.json alongside an append-only action or admission ledger.
|
|
384
387
|
`.trim();
|
|
385
388
|
}
|
|
386
389
|
function renderDatasetMaintenanceVerifyHelp() {
|
|
@@ -395,7 +398,8 @@ Options:
|
|
|
395
398
|
--json Print compact JSON
|
|
396
399
|
-h, --help
|
|
397
400
|
|
|
398
|
-
Outputs include readback-verify-report.json
|
|
401
|
+
Outputs include readback-verify-report.json. rebuild-derivatives reports pending, passed, or failed;
|
|
402
|
+
pending and failed both return a non-zero exit status.
|
|
399
403
|
`.trim();
|
|
400
404
|
}
|
|
401
405
|
function renderDatasetMaintenanceClearAccountHelp() {
|
|
@@ -3062,8 +3066,15 @@ function parseDatasetMaintenancePlanFlags(args) {
|
|
|
3062
3066
|
}
|
|
3063
3067
|
const rawOperation = typeof values.operation === 'string' ? values.operation : null;
|
|
3064
3068
|
if (rawOperation !== null &&
|
|
3065
|
-
![
|
|
3066
|
-
|
|
3069
|
+
![
|
|
3070
|
+
'delete',
|
|
3071
|
+
'retire',
|
|
3072
|
+
'redo-import',
|
|
3073
|
+
'repair-references',
|
|
3074
|
+
'merge-support-aliases',
|
|
3075
|
+
'rebuild-derivatives',
|
|
3076
|
+
].includes(rawOperation)) {
|
|
3077
|
+
throw new CliError("--operation must be 'delete', 'retire', 'redo-import', 'repair-references', 'merge-support-aliases', or 'rebuild-derivatives'.", {
|
|
3067
3078
|
code: 'DATASET_MAINTENANCE_OPERATION_INVALID',
|
|
3068
3079
|
exitCode: 2,
|
|
3069
3080
|
details: rawOperation,
|
|
@@ -5630,7 +5641,7 @@ export async function executeCli(argv, deps) {
|
|
|
5630
5641
|
fetchImpl: deps.fetchImpl,
|
|
5631
5642
|
});
|
|
5632
5643
|
return {
|
|
5633
|
-
exitCode: report.status === '
|
|
5644
|
+
exitCode: report.status === 'passed' ? 0 : 1,
|
|
5634
5645
|
stdout: stringifyJson(report, datasetFlags.json),
|
|
5635
5646
|
stderr: '',
|
|
5636
5647
|
};
|