@tiangong-lca/cli 0.0.6 → 0.0.8

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 (90) hide show
  1. package/README.md +154 -30
  2. package/dist/src/cli.js +2235 -149
  3. package/dist/src/cli.js.map +1 -1
  4. package/dist/src/lib/dataset-author.js +100 -0
  5. package/dist/src/lib/dataset-author.js.map +1 -0
  6. package/dist/src/lib/dataset-bilingual.js +545 -0
  7. package/dist/src/lib/dataset-bilingual.js.map +1 -0
  8. package/dist/src/lib/dataset-contract.js +350 -0
  9. package/dist/src/lib/dataset-contract.js.map +1 -0
  10. package/dist/src/lib/dataset-evidence-search.js +636 -0
  11. package/dist/src/lib/dataset-evidence-search.js.map +1 -0
  12. package/dist/src/lib/dataset-import-lca.js +171 -0
  13. package/dist/src/lib/dataset-import-lca.js.map +1 -0
  14. package/dist/src/lib/dataset-local.js +231 -0
  15. package/dist/src/lib/dataset-local.js.map +1 -0
  16. package/dist/src/lib/dataset-references-rewrite.js +214 -0
  17. package/dist/src/lib/dataset-references-rewrite.js.map +1 -0
  18. package/dist/src/lib/dataset-remote-refresh.js +166 -0
  19. package/dist/src/lib/dataset-remote-refresh.js.map +1 -0
  20. package/dist/src/lib/dataset-remote-verify.js +543 -0
  21. package/dist/src/lib/dataset-remote-verify.js.map +1 -0
  22. package/dist/src/lib/dataset-validate.js +247 -0
  23. package/dist/src/lib/dataset-validate.js.map +1 -0
  24. package/dist/src/lib/flow-payload-validation.js +51 -0
  25. package/dist/src/lib/flow-payload-validation.js.map +1 -0
  26. package/dist/src/lib/flow-publish-reviewed-data.js +16 -0
  27. package/dist/src/lib/flow-publish-reviewed-data.js.map +1 -1
  28. package/dist/src/lib/flow-publish-version.js +182 -12
  29. package/dist/src/lib/flow-publish-version.js.map +1 -1
  30. package/dist/src/lib/flow-regen-product.js +2 -10
  31. package/dist/src/lib/flow-regen-product.js.map +1 -1
  32. package/dist/src/lib/flow-remediate.js +4 -8
  33. package/dist/src/lib/flow-remediate.js.map +1 -1
  34. package/dist/src/lib/identity-preflight.js +1021 -0
  35. package/dist/src/lib/identity-preflight.js.map +1 -0
  36. package/dist/src/lib/lifecyclemodel-auto-build.js +11 -8
  37. package/dist/src/lib/lifecyclemodel-auto-build.js.map +1 -1
  38. package/dist/src/lib/lifecyclemodel-graph.js +248 -0
  39. package/dist/src/lib/lifecyclemodel-graph.js.map +1 -0
  40. package/dist/src/lib/lifecyclemodel-publish-build.js +1 -1
  41. package/dist/src/lib/lifecyclemodel-publish-build.js.map +1 -1
  42. package/dist/src/lib/lifecyclemodel-save-draft-run.js +245 -0
  43. package/dist/src/lib/lifecyclemodel-save-draft-run.js.map +1 -0
  44. package/dist/src/lib/lifecyclemodel-validate-build.js +1 -1
  45. package/dist/src/lib/lifecyclemodel-validate-build.js.map +1 -1
  46. package/dist/src/lib/process-auto-build.js +158 -8
  47. package/dist/src/lib/process-auto-build.js.map +1 -1
  48. package/dist/src/lib/process-batch-build.js +6 -3
  49. package/dist/src/lib/process-batch-build.js.map +1 -1
  50. package/dist/src/lib/process-dedup-review.js +921 -0
  51. package/dist/src/lib/process-dedup-review.js.map +1 -0
  52. package/dist/src/lib/process-flow-build-plan.js +1071 -0
  53. package/dist/src/lib/process-flow-build-plan.js.map +1 -0
  54. package/dist/src/lib/process-payload-validation.js +57 -0
  55. package/dist/src/lib/process-payload-validation.js.map +1 -0
  56. package/dist/src/lib/process-publish-build.js +126 -10
  57. package/dist/src/lib/process-publish-build.js.map +1 -1
  58. package/dist/src/lib/process-refresh-references.js +1037 -0
  59. package/dist/src/lib/process-refresh-references.js.map +1 -0
  60. package/dist/src/lib/process-required-fields.js +810 -0
  61. package/dist/src/lib/process-required-fields.js.map +1 -0
  62. package/dist/src/lib/process-resume-build.js +4 -6
  63. package/dist/src/lib/process-resume-build.js.map +1 -1
  64. package/dist/src/lib/process-save-draft-run.js +35 -13
  65. package/dist/src/lib/process-save-draft-run.js.map +1 -1
  66. package/dist/src/lib/process-scope-statistics.js +859 -0
  67. package/dist/src/lib/process-scope-statistics.js.map +1 -0
  68. package/dist/src/lib/process-verify-rows.js +250 -0
  69. package/dist/src/lib/process-verify-rows.js.map +1 -0
  70. package/dist/src/lib/publish.js +101 -1
  71. package/dist/src/lib/publish.js.map +1 -1
  72. package/dist/src/lib/remote.js +4 -4
  73. package/dist/src/lib/remote.js.map +1 -1
  74. package/dist/src/lib/review-flow.js +58 -0
  75. package/dist/src/lib/review-flow.js.map +1 -1
  76. package/dist/src/lib/review-lifecyclemodel.js +2 -2
  77. package/dist/src/lib/review-lifecyclemodel.js.map +1 -1
  78. package/dist/src/lib/review-process.js +150 -2
  79. package/dist/src/lib/review-process.js.map +1 -1
  80. package/dist/src/lib/runtime-rulesets.js +283 -0
  81. package/dist/src/lib/runtime-rulesets.js.map +1 -0
  82. package/dist/src/lib/tidas-sdk-package-validator.js +28 -9
  83. package/dist/src/lib/tidas-sdk-package-validator.js.map +1 -1
  84. package/dist/src/lib/tidas-sdk-validation.js +96 -0
  85. package/dist/src/lib/tidas-sdk-validation.js.map +1 -0
  86. package/dist/src/lib/user-api-key.js +1 -1
  87. package/dist/src/lib/user-api-key.js.map +1 -1
  88. package/package.json +5 -5
  89. /package/bin/{tiangong.d.ts → tiangong-lca.d.ts} +0 -0
  90. /package/bin/{tiangong.js → tiangong-lca.js} +0 -0
package/README.md CHANGED
@@ -1,24 +1,47 @@
1
+ ---
2
+ docType: guide
3
+ scope: repo
4
+ status: active
5
+ authoritative: false
6
+ owner: cli
7
+ language: en
8
+ whenToUse:
9
+ - when installing or invoking the TianGong LCA CLI
10
+ - when checking public command examples
11
+ whenToUpdate:
12
+ - when the published CLI executable or invocation contract changes
13
+ - when user-facing command examples change
14
+ checkPaths:
15
+ - README.md
16
+ - package.json
17
+ - bin/**
18
+ - src/cli.ts
19
+ - src/main.ts
20
+ lastReviewedAt: 2026-06-01
21
+ lastReviewedCommit: 24f96578290267865df3ee1244a96723129bc376
22
+ ---
23
+
1
24
  # TianGong LCA CLI
2
25
 
3
- Package: `@tiangong-lca/cli` Executable: `tiangong` Node: `24.x`
26
+ Package: `@tiangong-lca/cli` Executable: `tiangong-lca` Node: `24.x`
4
27
 
5
28
  ## Run
6
29
 
7
30
  One-off published run:
8
31
 
9
32
  ```bash
10
- npm exec --yes --package=@tiangong-lca/cli@latest -- tiangong --help
11
- npm exec --yes --package=@tiangong-lca/cli@latest -- tiangong doctor
12
- npm exec --yes --package=@tiangong-lca/cli@latest -- tiangong flow --help
33
+ npm exec --yes --package=@tiangong-lca/cli@latest -- tiangong-lca --help
34
+ npm exec --yes --package=@tiangong-lca/cli@latest -- tiangong-lca doctor
35
+ npm exec --yes --package=@tiangong-lca/cli@latest -- tiangong-lca flow --help
13
36
  ```
14
37
 
15
38
  Install the published CLI:
16
39
 
17
40
  ```bash
18
41
  npm install --global @tiangong-lca/cli
19
- tiangong --help
20
- tiangong doctor
21
- tiangong flow --help
42
+ tiangong-lca --help
43
+ tiangong-lca doctor
44
+ tiangong-lca flow --help
22
45
  ```
23
46
 
24
47
  Run from this repository:
@@ -26,7 +49,7 @@ Run from this repository:
26
49
  ```bash
27
50
  npm ci
28
51
  npm run build
29
- node ./bin/tiangong.js --help
52
+ node ./bin/tiangong-lca.js --help
30
53
  ```
31
54
 
32
55
  ## Env
@@ -78,9 +101,9 @@ Minimal `search flow` request:
78
101
  Run:
79
102
 
80
103
  ```bash
81
- tiangong search flow --input ./search-flow.request.json --json
82
- tiangong search process --input ./search-process.request.json --json
83
- tiangong search lifecyclemodel --input ./search-lifecyclemodel.request.json --json
104
+ tiangong-lca search flow --input ./search-flow.request.json --json
105
+ tiangong-lca search process --input ./search-process.request.json --json
106
+ tiangong-lca search lifecyclemodel --input ./search-lifecyclemodel.request.json --json
84
107
  ```
85
108
 
86
109
  Empty search results should be treated as empty whether the response is `[]` or `{"data":[]}`.
@@ -88,12 +111,72 @@ Empty search results should be treated as empty whether the response is `[]` or
88
111
  ## Read
89
112
 
90
113
  ```bash
91
- tiangong flow get --id <flow-id> --version <version> --json
92
- tiangong flow list --id <flow-id> --state-code 100 --limit 20 --json
93
- tiangong process get --id <process-id> --version <version> --json
94
- tiangong process list --state-code 100 --limit 20 --json
114
+ tiangong-lca flow get --id <flow-id> --version <version> --json
115
+ tiangong-lca flow list --id <flow-id> --state-code 100 --limit 20 --json
116
+ tiangong-lca process get --id <process-id> --version <version> --json
117
+ tiangong-lca process list --state-code 100 --limit 20 --json
95
118
  ```
96
119
 
120
+ ## Identity Preflight
121
+
122
+ Use identity preflight before generating new process or flow rows. The command compares one target against local candidate rows and emits a machine-readable `IdentityDecision` so automation can reuse, update, block, or route uncertain cases before payload generation.
123
+
124
+ ```bash
125
+ tiangong-lca process identity-preflight --input ./process-preflight.json --out-dir ./process-preflight --json
126
+ tiangong-lca flow identity-preflight --input ./flow-preflight.json --out-dir ./flow-preflight --json
127
+ tiangong-lca process identity-preflight --input ./process-preflight.json --candidate-input ./exports/processes.jsonl --candidate-input ./local-process-catalog --out-dir ./process-preflight --json
128
+ tiangong-lca flow identity-preflight --input ./flow-preflight.json --remote-candidates --remote-query "electricity medium voltage" --remote-limit 20 --out-dir ./flow-preflight --json
129
+ ```
130
+
131
+ Minimal input:
132
+
133
+ ```json
134
+ {
135
+ "target": {
136
+ "name_en": "market for electricity, medium voltage",
137
+ "reference_flow_id": "flow-electricity",
138
+ "operation": "produce"
139
+ },
140
+ "candidates": [
141
+ {
142
+ "id": "existing-process",
143
+ "name_en": "market for electricity, medium voltage",
144
+ "reference_flow_id": "flow-electricity",
145
+ "operation": "produce"
146
+ }
147
+ ]
148
+ }
149
+ ```
150
+
151
+ Key outputs under `--out-dir`:
152
+
153
+ - `outputs/identity-decision.json`
154
+ - `outputs/identity-candidates.jsonl`
155
+ - `outputs/identity-candidate-sources.json`
156
+
157
+ `--candidate-input` is repeatable and accepts JSON, JSONL, or a directory scanned recursively for JSON/JSONL candidate rows. Embedded `candidates` from the request and local-scan candidates are evaluated together. Add `--remote-candidates` when the preflight should also call `process_hybrid_search` or `flow_hybrid_search`; `--remote-query` overrides the target-derived search text and `--remote-limit` caps returned candidate rows. Remote candidate search uses the normal Supabase session env: `TIANGONG_LCA_API_BASE_URL`, `TIANGONG_LCA_API_KEY`, `TIANGONG_LCA_SUPABASE_PUBLISHABLE_KEY`, and optional `TIANGONG_LCA_REGION`.
158
+
159
+ Exact process exchange fingerprints with matching identity context block duplicate creation, while weaker inventory-only matches still route to manual review. Flow preflight also blocks alias-equivalent flows when type, reference property, unit, and category/CAS evidence match.
160
+
161
+ ## Build Plan Gate
162
+
163
+ Use build-plan gates after identity preflight and before publish handoff. These commands validate the minimum authoring contract for a process or flow build plan, write a standard `GateReport` for Foundry/skill orchestration, and materialize deterministic canonical TIDAS payloads when no explicit payload is embedded in the plan.
164
+
165
+ ```bash
166
+ tiangong-lca process build-plan validate --input ./process-build-plan.json --out-dir ./process-build-plan --json
167
+ tiangong-lca process build-plan materialize --input ./process-build-plan.json --out-dir ./process-build-plan --json
168
+ tiangong-lca flow build-plan validate --input ./flow-build-plan.json --out-dir ./flow-build-plan --json
169
+ tiangong-lca flow build-plan materialize --input ./flow-build-plan.json --out-dir ./flow-build-plan --json
170
+ ```
171
+
172
+ The minimum plan contract requires an automatic identity decision, EvidenceManifest sources and field bindings, name plan, and the relevant process reference-flow or flow-property fields. Process materialization carries name, quantitative reference, exchange, source evidence, modelling, administrative, and annual supply/production fields from the plan into `processDataSet`; when annual volume is not explicit, it falls back to reference-flow `meanAmount` and then `resultingAmount`. Flow materialization carries name, flow type, reference property, source evidence, administrative, and classification fields into `flowDataSet`. `--report-only` keeps exit code `0` while still reporting blockers.
173
+
174
+ Key outputs under `--out-dir`:
175
+
176
+ - `outputs/build-plan-gate-report.json`
177
+ - `outputs/materialized-process.json`
178
+ - `outputs/materialized-flow.json`
179
+
97
180
  ## Real DB Flow Review
98
181
 
99
182
  1. Search or otherwise collect exact flow refs.
@@ -138,15 +221,15 @@ tiangong process list --state-code 100 --limit 20 --json
138
221
  Run:
139
222
 
140
223
  ```bash
141
- tiangong flow fetch-rows \
224
+ tiangong-lca flow fetch-rows \
142
225
  --refs-file ./flow-refs.json \
143
226
  --out-dir ./flow-fetch
144
227
 
145
- tiangong review flow \
228
+ tiangong-lca review flow \
146
229
  --rows-file ./flow-fetch/review-input-rows.jsonl \
147
230
  --out-dir ./flow-review
148
231
 
149
- tiangong flow materialize-decisions \
232
+ tiangong-lca flow materialize-decisions \
150
233
  --decision-file ./approved-decisions.json \
151
234
  --flow-rows-file ./flow-fetch/review-input-rows.jsonl \
152
235
  --out-dir ./flow-decisions
@@ -170,29 +253,70 @@ Key `flow materialize-decisions` outputs:
170
253
  ## Other Common Commands
171
254
 
172
255
  ```bash
173
- tiangong review process --rows-file ./process-list-report.json --out-dir ./review
174
- tiangong review process --run-root ./artifacts/process_from_flow/<run_id> --run-id <run_id> --out-dir ./review
175
- tiangong publish run --input ./publish-request.json --dry-run
176
- tiangong doctor --json
256
+ tiangong-lca process identity-preflight --input ./process-preflight.json --candidate-input /abs/path/to/process-candidates.jsonl --out-dir /abs/path/to/process-preflight --json
257
+ tiangong-lca flow identity-preflight --input ./flow-preflight.json --candidate-input /abs/path/to/flow-catalog --out-dir /abs/path/to/flow-preflight --json
258
+ tiangong-lca process identity-preflight --input ./process-preflight.json --remote-candidates --remote-limit 20 --out-dir /abs/path/to/process-preflight --json
259
+ tiangong-lca process build-plan validate --input ./process-build-plan.json --out-dir /abs/path/to/process-build-plan --json
260
+ tiangong-lca flow build-plan validate --input ./flow-build-plan.json --out-dir /abs/path/to/flow-build-plan --json
261
+ tiangong-lca process auto-build --input ./examples/process-auto-build.request.json --out-dir /abs/path/to/process-run --json
262
+ tiangong-lca process resume-build --run-dir /abs/path/to/process-run --json
263
+ tiangong-lca process publish-build --run-dir /abs/path/to/process-run --json
264
+ tiangong-lca process batch-build --input ./examples/process-batch-build.request.json --out-dir /abs/path/to/process-batch --json
265
+ tiangong-lca dataset validate --input ./rows.jsonl --type auto --out-dir /abs/path/to/dataset-validate --json
266
+ tiangong-lca dataset evidence-search plan --query "中国2026年电力结构数据" --out-dir /abs/path/to/evidence-search --json
267
+ tiangong-lca dataset evidence-search run --input ./evidence-search.request.json --results ./search-results.json --out-dir /abs/path/to/evidence-search --json
268
+ 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
269
+ tiangong-lca lifecyclemodel auto-build --input ./examples/lifecyclemodel-auto-build.request.json --out-dir /abs/path/to/lifecyclemodel-run --json
270
+ tiangong-lca lifecyclemodel validate-build --run-dir /abs/path/to/lifecyclemodel-run --json
271
+ tiangong-lca lifecyclemodel publish-build --run-dir /abs/path/to/lifecyclemodel-run --json
272
+ tiangong-lca lifecyclemodel save-draft --input ./lifecyclemodels.jsonl --out-dir /abs/path/to/lifecyclemodel-save-draft --dry-run --json
273
+ tiangong-lca lifecyclemodel graph --input ./lifecyclemodels.jsonl --out-dir /abs/path/to/lifecyclemodel-graph --format all --json
274
+ tiangong-lca lifecyclemodel orchestrate plan --input ./lifecyclemodel-orchestrate.request.json --out-dir /abs/path/to/lifecyclemodel-recursive-run --json
275
+ tiangong-lca review process --rows-file ./process-list-report.json --out-dir ./review
276
+ tiangong-lca review process --run-root /abs/path/to/process-run --run-id <run_id> --out-dir ./review
277
+ tiangong-lca process save-draft --input ./patched-processes.jsonl --out-dir /abs/path/to/process-save-draft --dry-run --json
278
+ tiangong-lca process save-draft --input ./patched-processes.jsonl --out-dir /abs/path/to/process-save-draft --commit --json
279
+ tiangong-lca flow publish-version --input-file ./ready-flows.jsonl --out-dir /abs/path/to/flow-publish --dry-run --json
280
+ tiangong-lca flow publish-reviewed-data --flow-rows-file ./reviewed-flows.jsonl --out-dir /abs/path/to/reviewed-publish --dry-run --json
281
+ tiangong-lca publish run --input ./publish-request.json --dry-run
282
+ tiangong-lca doctor --json
177
283
  ```
178
284
 
179
285
  For `publish run`, relative `out_dir` values from either the request body or `--out-dir` are resolved against the request file directory, not the shell `cwd`. Use an absolute path when you want a fixed destination independent of the request file location.
180
286
 
181
- For `review process`, `--rows-file` accepts either raw process rows as JSON/JSONL or the full JSON report emitted by `tiangong process list --json`, as long as it contains a `rows` array.
287
+ For `review process`, `--rows-file` accepts either raw process rows as JSON/JSONL or the full JSON report emitted by `tiangong-lca process list --json`, as long as it contains a `rows` array.
288
+
289
+ For `process identity-preflight` and `flow identity-preflight`, canonical TIDAS wrappers are schema-checked when present. Loose target objects are accepted for early planning and produce `schema_validation.status: "not_applicable"` until materialization. Candidate rows can be embedded in the request, loaded from repeatable `--candidate-input` local files/directories, or fetched through explicit `--remote-candidates` hybrid search; `identity-candidate-sources.json` records scanned files, remote endpoints, queries, filters, and row counts.
290
+
291
+ For `process build-plan` and `flow build-plan`, canonical payloads embedded in the plan are schema-checked during `materialize`. Plan-only materialization now creates deterministic canonical `processDataSet` / `flowDataSet` wrappers from the build plan and validates them with the TIDAS SDK before reporting `passed`.
292
+
293
+ For `process save-draft`, canonical process payloads are validated locally with `ProcessSchema` before any `--commit` write. Schema-invalid rows remain in `outputs/save-draft-rpc/failures.jsonl` instead of being persisted.
294
+
295
+ For `flow publish-version`, canonical flow payloads are validated locally with `FlowSchema` before remote visibility planning or writes. The command always writes `flow-publish-version-gate-report.json`; blocked rows are written to the remote-failure JSONL without calling the remote service.
296
+
297
+ For `process publish-build`, canonical process payloads are validated locally with `ProcessSchema` before publish handoff artifacts are written. The gate report is `reports/process-publish-schema-gate.json`.
298
+
299
+ For `publish run`, `verification-report.json` is written next to `publish-report.json` and summarizes the publish ruleset status, blockers, failed entries, deferred entries, and executed entries.
300
+
301
+ For `lifecyclemodel save-draft`, canonical lifecyclemodel payloads are validated locally with `LifeCycleModelSchema` before any `--commit` write. Schema-invalid rows remain in `outputs/save-draft-bundle/failures.jsonl` instead of being persisted.
302
+
303
+ For `dataset evidence-search`, `plan` creates the field-level query matrix and search budget. `run` accepts normalized external search results from browser/web-search tools or a generic JSON provider endpoint, then writes `outputs/evidence-search-plan.json`, `outputs/evidence-search-results.jsonl`, `outputs/evidence-search-report.json`, and `outputs/evidence-search-declaration.json` when evidence is absent or only partial. The CLI records scope and normalization; Codex/skills still own semantic judgement and source selection.
304
+
305
+ For `dataset references rewrite`, `--commit` executes the state-aware save-draft path for patched process and lifecyclemodel rows; without `--commit`, the command only writes local rewrite artifacts.
182
306
 
183
307
  ## More Docs
184
308
 
185
309
  - `docs/IMPLEMENTATION_GUIDE_CN.md`: maintainer-facing command contract and implementation notes
186
- - `--help`: the canonical command surface for `tiangong`, `tiangong flow`, `tiangong review`, `tiangong process`, `tiangong lifecyclemodel`, and `tiangong publish`
310
+ - `--help`: the canonical command surface for `tiangong-lca`, `tiangong-lca flow`, `tiangong-lca review`, `tiangong-lca process`, `tiangong-lca lifecyclemodel`, and `tiangong-lca publish`
187
311
  - `tiangong-lca-skills`: use the skill-specific `SKILL.md` and wrapper docs for agent workflows; the CLI README only covers the public invocation contract
188
312
 
189
313
  ## Help
190
314
 
191
315
  ```bash
192
- tiangong --help
193
- tiangong flow --help
194
- tiangong review --help
195
- tiangong process --help
196
- tiangong lifecyclemodel --help
197
- tiangong publish --help
316
+ tiangong-lca --help
317
+ tiangong-lca flow --help
318
+ tiangong-lca review --help
319
+ tiangong-lca process --help
320
+ tiangong-lca lifecyclemodel --help
321
+ tiangong-lca publish --help
198
322
  ```