@tiangong-lca/cli 0.1.0 → 0.1.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.
Files changed (159) hide show
  1. package/README.md +58 -6
  2. package/dist/src/batch.d.ts +6 -0
  3. package/dist/src/batch.js +6 -0
  4. package/dist/src/batch.js.map +1 -0
  5. package/dist/src/cli.d.ts +161 -0
  6. package/dist/src/cli.js +130 -0
  7. package/dist/src/cli.js.map +1 -1
  8. package/dist/src/command-spec.d.ts +90 -0
  9. package/dist/src/command-spec.js +400 -0
  10. package/dist/src/command-spec.js.map +1 -0
  11. package/dist/src/lib/artifacts.d.ts +9 -0
  12. package/dist/src/lib/auth-identity-receipt.d.ts +160 -0
  13. package/dist/src/lib/auth-identity-receipt.js +634 -0
  14. package/dist/src/lib/auth-identity-receipt.js.map +1 -0
  15. package/dist/src/lib/batch/attempt-recovery.d.ts +12 -0
  16. package/dist/src/lib/batch/attempt-recovery.js +183 -0
  17. package/dist/src/lib/batch/attempt-recovery.js.map +1 -0
  18. package/dist/src/lib/batch/canonical-contracts.d.ts +21 -0
  19. package/dist/src/lib/batch/canonical-contracts.js +180 -0
  20. package/dist/src/lib/batch/canonical-contracts.js.map +1 -0
  21. package/dist/src/lib/batch/engine.d.ts +2 -0
  22. package/dist/src/lib/batch/engine.js +294 -0
  23. package/dist/src/lib/batch/engine.js.map +1 -0
  24. package/dist/src/lib/batch/errors.d.ts +51 -0
  25. package/dist/src/lib/batch/errors.js +81 -0
  26. package/dist/src/lib/batch/errors.js.map +1 -0
  27. package/dist/src/lib/batch/item-projection.d.ts +10 -0
  28. package/dist/src/lib/batch/item-projection.js +118 -0
  29. package/dist/src/lib/batch/item-projection.js.map +1 -0
  30. package/dist/src/lib/batch/run-lock.d.ts +4 -0
  31. package/dist/src/lib/batch/run-lock.js +155 -0
  32. package/dist/src/lib/batch/run-lock.js.map +1 -0
  33. package/dist/src/lib/batch/scheduler-runtime.d.ts +29 -0
  34. package/dist/src/lib/batch/scheduler-runtime.js +114 -0
  35. package/dist/src/lib/batch/scheduler-runtime.js.map +1 -0
  36. package/dist/src/lib/batch/types.d.ts +183 -0
  37. package/dist/src/lib/batch/types.js +2 -0
  38. package/dist/src/lib/batch/types.js.map +1 -0
  39. package/dist/src/lib/dataset-author.d.ts +39 -0
  40. package/dist/src/lib/dataset-bilingual.d.ts +165 -0
  41. package/dist/src/lib/dataset-classification.d.ts +279 -0
  42. package/dist/src/lib/dataset-command.d.ts +53 -0
  43. package/dist/src/lib/dataset-contract.d.ts +82 -0
  44. package/dist/src/lib/dataset-curation-queue.d.ts +219 -0
  45. package/dist/src/lib/dataset-evidence-search.d.ts +134 -0
  46. package/dist/src/lib/dataset-import-lca.d.ts +136 -0
  47. package/dist/src/lib/dataset-local.d.ts +23 -0
  48. package/dist/src/lib/dataset-maintenance-alias-request.d.ts +12 -0
  49. package/dist/src/lib/dataset-maintenance-alias-rewrite.d.ts +111 -0
  50. package/dist/src/lib/dataset-maintenance-apply.d.ts +458 -0
  51. package/dist/src/lib/dataset-maintenance-clear-account.d.ts +161 -0
  52. package/dist/src/lib/dataset-maintenance-contract.d.ts +317 -0
  53. package/dist/src/lib/dataset-maintenance-derivatives.d.ts +48 -0
  54. package/dist/src/lib/dataset-maintenance-flow-identity-approval-claim.d.ts +50 -0
  55. package/dist/src/lib/dataset-maintenance-flow-identity-capture.d.ts +110 -0
  56. package/dist/src/lib/dataset-maintenance-flow-identity-command.d.ts +15 -0
  57. package/dist/src/lib/dataset-maintenance-flow-identity-contract.d.ts +387 -0
  58. package/dist/src/lib/dataset-maintenance-flow-identity-execution-contract.d.ts +456 -0
  59. package/dist/src/lib/dataset-maintenance-flow-identity-freeze.d.ts +99 -0
  60. package/dist/src/lib/dataset-maintenance-flow-identity-plan.d.ts +85 -0
  61. package/dist/src/lib/dataset-maintenance-flow-identity-recovery.d.ts +268 -0
  62. package/dist/src/lib/dataset-maintenance-flow-identity-run.d.ts +123 -0
  63. package/dist/src/lib/dataset-maintenance-flow-identity-seal.d.ts +50 -0
  64. package/dist/src/lib/dataset-maintenance-flow-identity-verify.d.ts +85 -0
  65. package/dist/src/lib/dataset-maintenance-flow-identity-wire.d.ts +32 -0
  66. package/dist/src/lib/dataset-maintenance-pagination.d.ts +58 -0
  67. package/dist/src/lib/dataset-maintenance-plan.d.ts +40 -0
  68. package/dist/src/lib/dataset-maintenance-protected-artifacts.d.ts +16 -0
  69. package/dist/src/lib/dataset-maintenance-protected-before.d.ts +71 -0
  70. package/dist/src/lib/dataset-maintenance-protected-contract.d.ts +385 -0
  71. package/dist/src/lib/dataset-maintenance-protected-freeze.d.ts +148 -0
  72. package/dist/src/lib/dataset-maintenance-protected-preparation.d.ts +76 -0
  73. package/dist/src/lib/dataset-maintenance-protected-run.d.ts +252 -0
  74. package/dist/src/lib/dataset-maintenance-protected-seal.d.ts +93 -0
  75. package/dist/src/lib/dataset-maintenance-protected-toolchain.d.ts +31 -0
  76. package/dist/src/lib/dataset-maintenance-protected-verify.d.ts +99 -0
  77. package/dist/src/lib/dataset-maintenance-remote.d.ts +212 -0
  78. package/dist/src/lib/dataset-maintenance-support-validation.d.ts +18 -0
  79. package/dist/src/lib/dataset-maintenance-verify.d.ts +102 -0
  80. package/dist/src/lib/dataset-patch.d.ts +193 -0
  81. package/dist/src/lib/dataset-references-rewrite.d.ts +77 -0
  82. package/dist/src/lib/dataset-remote-refresh.d.ts +64 -0
  83. package/dist/src/lib/dataset-remote-verify.d.ts +168 -0
  84. package/dist/src/lib/dataset-save-draft-run.d.ts +283 -0
  85. package/dist/src/lib/dataset-save-draft-run.js +54 -21
  86. package/dist/src/lib/dataset-save-draft-run.js.map +1 -1
  87. package/dist/src/lib/dataset-source-upload-attachments.d.ts +109 -0
  88. package/dist/src/lib/dataset-validate.d.ts +62 -0
  89. package/dist/src/lib/dotenv.d.ts +6 -0
  90. package/dist/src/lib/env.d.ts +59 -0
  91. package/dist/src/lib/errors.d.ts +18 -0
  92. package/dist/src/lib/flow-build-alias-map.d.ts +80 -0
  93. package/dist/src/lib/flow-fetch-rows.d.ts +70 -0
  94. package/dist/src/lib/flow-get.d.ts +35 -0
  95. package/dist/src/lib/flow-governance.d.ts +22 -0
  96. package/dist/src/lib/flow-list.d.ts +57 -0
  97. package/dist/src/lib/flow-materialize-decisions.d.ts +67 -0
  98. package/dist/src/lib/flow-payload-validation.d.ts +32 -0
  99. package/dist/src/lib/flow-publish-reviewed-data.d.ts +262 -0
  100. package/dist/src/lib/flow-publish-version.d.ts +193 -0
  101. package/dist/src/lib/flow-qa.d.ts +289 -0
  102. package/dist/src/lib/flow-read.d.ts +70 -0
  103. package/dist/src/lib/flow-regen-product.d.ts +431 -0
  104. package/dist/src/lib/flow-remediate.d.ts +133 -0
  105. package/dist/src/lib/http.d.ts +25 -0
  106. package/dist/src/lib/http.js.map +1 -1
  107. package/dist/src/lib/identity-preflight.d.ts +235 -0
  108. package/dist/src/lib/io.d.ts +2 -0
  109. package/dist/src/lib/kb-search.d.ts +23 -0
  110. package/dist/src/lib/lca-release.d.ts +105 -0
  111. package/dist/src/lib/lifecyclemodel-auto-build.d.ts +223 -0
  112. package/dist/src/lib/lifecyclemodel-bundle-save.d.ts +71 -0
  113. package/dist/src/lib/lifecyclemodel-graph.d.ts +91 -0
  114. package/dist/src/lib/lifecyclemodel-orchestrate.d.ts +349 -0
  115. package/dist/src/lib/lifecyclemodel-publish-build.d.ts +77 -0
  116. package/dist/src/lib/lifecyclemodel-publish-resulting-process.d.ts +27 -0
  117. package/dist/src/lib/lifecyclemodel-qa.d.ts +206 -0
  118. package/dist/src/lib/lifecyclemodel-resulting-process.d.ts +204 -0
  119. package/dist/src/lib/lifecyclemodel-save-draft-run.d.ts +96 -0
  120. package/dist/src/lib/lifecyclemodel-validate-build.d.ts +78 -0
  121. package/dist/src/lib/llm.d.ts +51 -0
  122. package/dist/src/lib/package-version.d.ts +3 -0
  123. package/dist/src/lib/process-auto-build.d.ts +168 -0
  124. package/dist/src/lib/process-batch-build.d.ts +97 -0
  125. package/dist/src/lib/process-dedup-review.d.ts +253 -0
  126. package/dist/src/lib/process-flow-build-plan.d.ts +108 -0
  127. package/dist/src/lib/process-get.d.ts +26 -0
  128. package/dist/src/lib/process-list.d.ts +87 -0
  129. package/dist/src/lib/process-payload-validation.d.ts +27 -0
  130. package/dist/src/lib/process-publish-build.d.ts +148 -0
  131. package/dist/src/lib/process-qa.d.ts +243 -0
  132. package/dist/src/lib/process-refresh-references.d.ts +179 -0
  133. package/dist/src/lib/process-required-fields.d.ts +142 -0
  134. package/dist/src/lib/process-resume-build.d.ts +77 -0
  135. package/dist/src/lib/process-save-draft-run.d.ts +72 -0
  136. package/dist/src/lib/process-save-draft.d.ts +53 -0
  137. package/dist/src/lib/process-scope-statistics.d.ts +210 -0
  138. package/dist/src/lib/process-verify-rows.d.ts +71 -0
  139. package/dist/src/lib/publish.d.ts +219 -0
  140. package/dist/src/lib/remote.d.ts +19 -0
  141. package/dist/src/lib/run.d.ts +60 -0
  142. package/dist/src/lib/runtime-rulesets.d.ts +29 -0
  143. package/dist/src/lib/state-lock.d.ts +25 -0
  144. package/dist/src/lib/state-lock.js +23 -1
  145. package/dist/src/lib/state-lock.js.map +1 -1
  146. package/dist/src/lib/supabase-client.d.ts +47 -0
  147. package/dist/src/lib/supabase-data-api-contract.d.ts +304 -0
  148. package/dist/src/lib/supabase-data-api-replay.d.ts +74 -0
  149. package/dist/src/lib/supabase-json-ordered-write.d.ts +65 -0
  150. package/dist/src/lib/supabase-rest.d.ts +26 -0
  151. package/dist/src/lib/supabase-session.d.ts +115 -0
  152. package/dist/src/lib/tidas-languages.d.ts +3 -0
  153. package/dist/src/lib/tidas-sdk-package-validator.d.ts +111 -0
  154. package/dist/src/lib/tidas-sdk-validation.d.ts +42 -0
  155. package/dist/src/lib/unstructured.d.ts +32 -0
  156. package/dist/src/lib/user-api-key.d.ts +16 -0
  157. package/dist/src/lib/validation.d.ts +82 -0
  158. package/dist/src/main.d.ts +4 -0
  159. package/package.json +17 -3
@@ -0,0 +1,168 @@
1
+ import { type RunLayout } from './run.js';
2
+ type JsonRecord = Record<string, unknown>;
3
+ export type ProcessAutoBuildOperation = 'produce' | 'treat';
4
+ export type ProcessAutoBuildSourceInputType = 'local_file' | 'local_text';
5
+ export type ProcessAutoBuildSourcePolicy = {
6
+ step1_route: {
7
+ preferred: string[];
8
+ fallback: string;
9
+ };
10
+ step2_process_split: {
11
+ preferred: string[];
12
+ fallback: string;
13
+ };
14
+ step3b_exchange_values: {
15
+ preferred: string[];
16
+ require_numeric_evidence: boolean;
17
+ allow_estimation: boolean;
18
+ };
19
+ };
20
+ export type ProcessAutoBuildFlowSummary = {
21
+ wrapper: 'flowDataSet' | 'direct';
22
+ uuid: string | null;
23
+ version: string | null;
24
+ base_name: string | null;
25
+ permanent_uri: string | null;
26
+ };
27
+ export type NormalizedProcessAutoBuildSourceInput = {
28
+ source_id: string;
29
+ type: ProcessAutoBuildSourceInputType;
30
+ source_path: string;
31
+ artifact_path: string;
32
+ artifact_file_name: string;
33
+ intended_roles: string[];
34
+ };
35
+ export type NormalizedProcessAutoBuildRequest = {
36
+ schema_version: 1;
37
+ request_path: string;
38
+ request_id: string;
39
+ flow_file: string;
40
+ flow_summary: ProcessAutoBuildFlowSummary;
41
+ flow_dataset: JsonRecord;
42
+ operation: ProcessAutoBuildOperation;
43
+ run_id: string;
44
+ run_root: string;
45
+ source_inputs: NormalizedProcessAutoBuildSourceInput[];
46
+ source_policy: ProcessAutoBuildSourcePolicy;
47
+ };
48
+ export type ProcessAutoBuildLayout = RunLayout & {
49
+ requestDir: string;
50
+ evidenceDir: string;
51
+ evidenceIncomingDir: string;
52
+ evidenceNormalizedDir: string;
53
+ evidenceTextDir: string;
54
+ evidenceStructuredDir: string;
55
+ stageOutputsDir: string;
56
+ reviewsDir: string;
57
+ requestSnapshotPath: string;
58
+ normalizedRequestPath: string;
59
+ sourcePolicyPath: string;
60
+ flowSummaryPath: string;
61
+ inputManifestPath: string;
62
+ buildPlanPath: string;
63
+ assemblyPlanPath: string;
64
+ lineageManifestPath: string;
65
+ invocationIndexPath: string;
66
+ runManifestPath: string;
67
+ reportPath: string;
68
+ statePath: string;
69
+ handoffSummaryPath: string;
70
+ processExportsDir: string;
71
+ sourceExportsDir: string;
72
+ };
73
+ export type ProcessAutoBuildReport = {
74
+ schema_version: 1;
75
+ generated_at_utc: string;
76
+ status: 'prepared_local_process_auto_build_run';
77
+ request_path: string;
78
+ request_id: string;
79
+ run_id: string;
80
+ run_root: string;
81
+ operation: ProcessAutoBuildOperation;
82
+ flow: {
83
+ source_path: string;
84
+ artifact_path: string;
85
+ wrapper: 'flowDataSet' | 'direct';
86
+ uuid: string | null;
87
+ version: string | null;
88
+ base_name: string | null;
89
+ };
90
+ source_input_count: number;
91
+ stage_count: number;
92
+ files: {
93
+ request_snapshot: string;
94
+ normalized_request: string;
95
+ source_policy: string;
96
+ flow_summary: string;
97
+ input_manifest: string;
98
+ build_plan: string;
99
+ assembly_plan: string;
100
+ lineage_manifest: string;
101
+ invocation_index: string;
102
+ run_manifest: string;
103
+ state: string;
104
+ handoff_summary: string;
105
+ report: string;
106
+ };
107
+ next_actions: string[];
108
+ };
109
+ export type RunProcessAutoBuildOptions = {
110
+ inputPath: string;
111
+ outDir?: string | null;
112
+ now?: Date;
113
+ cwd?: string;
114
+ inputValue?: unknown;
115
+ requestIdOverride?: string;
116
+ runIdOverride?: string;
117
+ };
118
+ type ProcessAutoBuildStage = {
119
+ id: string;
120
+ title: string;
121
+ output: string;
122
+ createsCandidatesDir: boolean;
123
+ modules: string[];
124
+ };
125
+ declare function extractText(value: unknown): string | null;
126
+ declare function normalizeOperation(value: unknown): ProcessAutoBuildOperation;
127
+ declare function normalizeSourcePolicy(value: unknown): ProcessAutoBuildSourcePolicy;
128
+ declare function extractFlowDatasetRoot(payload: unknown): {
129
+ flowPayload: JsonRecord;
130
+ flowDataset: JsonRecord;
131
+ wrapper: 'flowDataSet' | 'direct';
132
+ };
133
+ declare function extractFlowSummary(flowDataset: JsonRecord, wrapper: 'flowDataSet' | 'direct'): ProcessAutoBuildFlowSummary;
134
+ declare function buildProcessAutoBuildRunId(flowFilePath: string, operation: ProcessAutoBuildOperation, summary: ProcessAutoBuildFlowSummary, now?: Date): string;
135
+ declare function buildLayout(runRoot: string, runId: string): ProcessAutoBuildLayout;
136
+ declare function buildAssemblyPlan(runRoot: string): JsonRecord;
137
+ declare function buildInitialProcessBuildPlan(normalized: NormalizedProcessAutoBuildRequest, flowArtifactPath: string): JsonRecord;
138
+ declare function buildLineageManifest(normalized: NormalizedProcessAutoBuildRequest): JsonRecord;
139
+ declare function buildInvocationIndex(normalized: NormalizedProcessAutoBuildRequest, options: RunProcessAutoBuildOptions, reportPath: string, now: Date): JsonRecord;
140
+ declare function buildInitialState(normalized: NormalizedProcessAutoBuildRequest, flowArtifactPath: string, now: Date): JsonRecord;
141
+ declare function buildAgentHandoffSummary(normalized: NormalizedProcessAutoBuildRequest, layout: ProcessAutoBuildLayout, flowArtifactPath: string, now: Date): JsonRecord;
142
+ declare function buildReport(normalized: NormalizedProcessAutoBuildRequest, layout: ProcessAutoBuildLayout, flowArtifactPath: string, now: Date): ProcessAutoBuildReport;
143
+ export declare function normalizeProcessAutoBuildRequest(input: unknown, options: {
144
+ inputPath: string;
145
+ outDir?: string | null;
146
+ now?: Date;
147
+ requestIdOverride?: string;
148
+ runIdOverride?: string;
149
+ }): NormalizedProcessAutoBuildRequest;
150
+ export declare function runProcessAutoBuild(options: RunProcessAutoBuildOptions): Promise<ProcessAutoBuildReport>;
151
+ export declare const __testInternals: {
152
+ PROCESS_AUTO_BUILD_STAGES: ProcessAutoBuildStage[];
153
+ extractText: typeof extractText;
154
+ normalizeOperation: typeof normalizeOperation;
155
+ normalizeSourcePolicy: typeof normalizeSourcePolicy;
156
+ extractFlowDatasetRoot: typeof extractFlowDatasetRoot;
157
+ extractFlowSummary: typeof extractFlowSummary;
158
+ buildProcessAutoBuildRunId: typeof buildProcessAutoBuildRunId;
159
+ buildLayout: typeof buildLayout;
160
+ buildAssemblyPlan: typeof buildAssemblyPlan;
161
+ buildInitialProcessBuildPlan: typeof buildInitialProcessBuildPlan;
162
+ buildLineageManifest: typeof buildLineageManifest;
163
+ buildInvocationIndex: typeof buildInvocationIndex;
164
+ buildInitialState: typeof buildInitialState;
165
+ buildAgentHandoffSummary: typeof buildAgentHandoffSummary;
166
+ buildReport: typeof buildReport;
167
+ };
168
+ export {};
@@ -0,0 +1,97 @@
1
+ import { type ErrorPayload } from './errors.js';
2
+ import { type RunLayout } from './run.js';
3
+ type JsonRecord = Record<string, unknown>;
4
+ type ProcessBatchBuildStatus = 'completed' | 'completed_with_failures';
5
+ type ProcessBatchBuildItemStatus = 'prepared' | 'failed' | 'skipped';
6
+ type ProcessBatchBuildManifestItem = {
7
+ item_id: string;
8
+ input_path: string;
9
+ out_dir: string;
10
+ };
11
+ export type ProcessBatchBuildLayout = RunLayout & {
12
+ requestDir: string;
13
+ runsDir: string;
14
+ requestSnapshotPath: string;
15
+ normalizedRequestPath: string;
16
+ invocationIndexPath: string;
17
+ runManifestPath: string;
18
+ reportPath: string;
19
+ };
20
+ export type NormalizedProcessBatchBuildRequest = {
21
+ schema_version: 1;
22
+ manifest_path: string;
23
+ batch_id: string;
24
+ batch_root: string;
25
+ continue_on_error: boolean;
26
+ items: ProcessBatchBuildManifestItem[];
27
+ };
28
+ export type ProcessBatchBuildItemReport = {
29
+ item_id: string;
30
+ index: number;
31
+ input_path: string;
32
+ out_dir: string;
33
+ status: ProcessBatchBuildItemStatus;
34
+ run_id: string | null;
35
+ run_root: string | null;
36
+ request_id: string | null;
37
+ files: {
38
+ request_snapshot: string | null;
39
+ report: string | null;
40
+ state: string | null;
41
+ handoff_summary: string | null;
42
+ run_manifest: string | null;
43
+ };
44
+ error: ErrorPayload['error'] | null;
45
+ };
46
+ export type ProcessBatchBuildReport = {
47
+ schema_version: 1;
48
+ generated_at_utc: string;
49
+ status: ProcessBatchBuildStatus;
50
+ manifest_path: string;
51
+ batch_id: string;
52
+ batch_root: string;
53
+ continue_on_error: boolean;
54
+ counts: {
55
+ total: number;
56
+ prepared: number;
57
+ failed: number;
58
+ skipped: number;
59
+ };
60
+ files: {
61
+ request_snapshot: string;
62
+ normalized_request: string;
63
+ invocation_index: string;
64
+ run_manifest: string;
65
+ report: string;
66
+ };
67
+ items: ProcessBatchBuildItemReport[];
68
+ next_actions: string[];
69
+ };
70
+ export type RunProcessBatchBuildOptions = {
71
+ inputPath: string;
72
+ outDir?: string | null;
73
+ now?: Date;
74
+ cwd?: string;
75
+ };
76
+ declare function resolveBatchRoot(manifestDir: string, outDirOverride: string | null | undefined, requestOutDir: unknown): string;
77
+ declare function buildLayout(batchRoot: string, batchId: string): ProcessBatchBuildLayout;
78
+ declare function normalizeItems(value: unknown, manifestDir: string, batchRoot: string): ProcessBatchBuildManifestItem[];
79
+ export declare function normalizeProcessBatchBuildRequest(input: unknown, options: {
80
+ inputPath: string;
81
+ outDir?: string | null;
82
+ now?: Date;
83
+ }): NormalizedProcessBatchBuildRequest;
84
+ declare function buildInvocationIndex(normalized: NormalizedProcessBatchBuildRequest, options: RunProcessBatchBuildOptions, layout: ProcessBatchBuildLayout, now: Date): JsonRecord;
85
+ declare function buildNextActions(layout: ProcessBatchBuildLayout): string[];
86
+ declare function buildReport(normalized: NormalizedProcessBatchBuildRequest, layout: ProcessBatchBuildLayout, items: ProcessBatchBuildItemReport[], now: Date): ProcessBatchBuildReport;
87
+ export declare function runProcessBatchBuild(options: RunProcessBatchBuildOptions): Promise<ProcessBatchBuildReport>;
88
+ export declare const __testInternals: {
89
+ buildLayout: typeof buildLayout;
90
+ resolveBatchRoot: typeof resolveBatchRoot;
91
+ normalizeItems: typeof normalizeItems;
92
+ normalizeProcessBatchBuildRequest: typeof normalizeProcessBatchBuildRequest;
93
+ buildInvocationIndex: typeof buildInvocationIndex;
94
+ buildNextActions: typeof buildNextActions;
95
+ buildReport: typeof buildReport;
96
+ };
97
+ export {};
@@ -0,0 +1,253 @@
1
+ import type { FetchLike, ResponseLike } from './http.js';
2
+ type JsonRecord = Record<string, unknown>;
3
+ type ProcessGroupId = string | number;
4
+ type ExchangeSummaryRow = {
5
+ exchange_internal_id: string;
6
+ flow_id: string;
7
+ flow_version: string;
8
+ direction: string;
9
+ mean_amount: string;
10
+ resulting_amount: string;
11
+ flow_short_description_en: string;
12
+ flow_short_description_zh: string;
13
+ };
14
+ type DedupInputProcess = {
15
+ process_id: string;
16
+ version: string;
17
+ name_en: string;
18
+ name_zh: string;
19
+ exchange_count: number | null;
20
+ overview_fingerprint: string;
21
+ sheet_exchange_rows: ExchangeSummaryRow[];
22
+ };
23
+ type DedupInputGroup = {
24
+ group_id: ProcessGroupId;
25
+ processes: DedupInputProcess[];
26
+ };
27
+ type RemoteMetadataRecord = {
28
+ process_id: string;
29
+ version: string;
30
+ state_code: number | null;
31
+ created_at: string | null;
32
+ modified_at: string | null;
33
+ user_id: string | null;
34
+ team_id: string | null;
35
+ model_id: string | null;
36
+ remote_name_en: string;
37
+ remote_name_zh: string;
38
+ remote_exchanges: ExchangeSummaryRow[];
39
+ };
40
+ type ReferenceHitRecord = {
41
+ id: string;
42
+ version: string;
43
+ state_code: number | null;
44
+ model_id?: string | null;
45
+ };
46
+ type ReferenceHits = {
47
+ processes: Record<string, ReferenceHitRecord[]>;
48
+ lifecyclemodels: Record<string, ReferenceHitRecord[]>;
49
+ };
50
+ type RemoteStatus = {
51
+ enabled: boolean;
52
+ loaded: number;
53
+ error: string | null;
54
+ reference_scan: 'not_run' | 'skipped_by_flag' | 'skipped_missing_user_id' | 'current_user_completed' | 'failed';
55
+ };
56
+ type ProcessDedupGate = {
57
+ status: 'passed' | 'blocked';
58
+ ruleset_id: 'process-dedup/default';
59
+ ruleset_version: '1';
60
+ ruleset_source_version: string;
61
+ ruleset_rule_ids: string[];
62
+ counts: {
63
+ duplicate_groups: number;
64
+ blocker_groups: number;
65
+ };
66
+ blockers: Array<{
67
+ group_id: ProcessGroupId;
68
+ code: 'process_exact_duplicate_fingerprint';
69
+ methodology_rule_id: string | null;
70
+ severity: 'blocker';
71
+ message: string;
72
+ }>;
73
+ next_action: 'continue' | 'resolve_duplicate_processes';
74
+ };
75
+ type DedupAnalyzedProcess = DedupInputProcess & Partial<RemoteMetadataRecord> & {
76
+ analysis_exchanges: ExchangeSummaryRow[];
77
+ normalized_exchange_signature: Array<[string, string, string, string]>;
78
+ name_score: number;
79
+ name_score_reasons: string[];
80
+ };
81
+ export type ProcessDedupReviewGroup = {
82
+ group_id: ProcessGroupId;
83
+ group_pattern: string;
84
+ exact_duplicate: boolean;
85
+ rule_id?: 'process_exact_duplicate_fingerprint';
86
+ methodology_rule_id?: string | null;
87
+ severity?: 'blocker';
88
+ blocker?: boolean;
89
+ processes: DedupAnalyzedProcess[];
90
+ };
91
+ type DeletePlanGroup = {
92
+ group_id: ProcessGroupId;
93
+ status: 'priority_delete_candidates';
94
+ confidence: 'high' | 'medium' | 'low';
95
+ current_user_reference_hits: {
96
+ keep_process_refs: number;
97
+ keep_lifecyclemodel_refs: number;
98
+ delete_refs: Record<string, {
99
+ process_refs: number;
100
+ lifecyclemodel_refs: number;
101
+ }>;
102
+ };
103
+ keep: {
104
+ process_id: string;
105
+ name_en: string;
106
+ name_zh: string;
107
+ score: number;
108
+ reasons: string[];
109
+ };
110
+ delete: Array<{
111
+ process_id: string;
112
+ name_en: string;
113
+ name_zh: string;
114
+ score: number;
115
+ reasons: string[];
116
+ }>;
117
+ notes: string[];
118
+ };
119
+ type RemoteAuthContext = {
120
+ projectBaseUrl: string;
121
+ publishableKey: string;
122
+ accessToken: string;
123
+ userId: string | null;
124
+ };
125
+ export type RunProcessDedupReviewOptions = {
126
+ inputPath: string;
127
+ outDir: string;
128
+ skipRemote?: boolean;
129
+ env?: NodeJS.ProcessEnv;
130
+ fetchImpl?: FetchLike;
131
+ timeoutMs?: number;
132
+ maxRetries?: number;
133
+ now?: Date;
134
+ };
135
+ export type ProcessDedupReviewReport = {
136
+ schema_version: 1;
137
+ generated_at_utc: string;
138
+ status: 'completed_process_dedup_review';
139
+ input_file: string;
140
+ out_dir: string;
141
+ source_label: string;
142
+ group_count: number;
143
+ exact_duplicate_group_count: number;
144
+ ruleset_id?: 'process-dedup/default';
145
+ ruleset_version?: '1';
146
+ ruleset_source_version?: string;
147
+ ruleset_rule_ids?: string[];
148
+ gate?: ProcessDedupGate;
149
+ remote_status: RemoteStatus;
150
+ files: {
151
+ input_manifest: string;
152
+ remote_metadata: string | null;
153
+ duplicate_groups: string;
154
+ delete_plan: string;
155
+ current_user_reference_scan: string | null;
156
+ };
157
+ };
158
+ declare function errorMessage(error: unknown): string;
159
+ declare function normalizeAmount(value: unknown): string;
160
+ declare function getLangList(value: unknown): JsonRecord[];
161
+ declare function getLangText(value: unknown, lang: string): string;
162
+ declare function normalizeExchangeRows(value: unknown): ExchangeSummaryRow[];
163
+ declare function normalizeInputDocument(value: unknown, resolvedInputPath: string): {
164
+ sourceLabel: string;
165
+ groups: DedupInputGroup[];
166
+ };
167
+ declare function parseJsonResponse(response: ResponseLike, label: string): Promise<unknown>;
168
+ declare function fetchJsonWithRetry(options: {
169
+ url: string;
170
+ init: RequestInit;
171
+ label: string;
172
+ fetchImpl: FetchLike;
173
+ timeoutMs: number;
174
+ maxRetries: number;
175
+ }): Promise<{
176
+ status: number;
177
+ headers: Headers;
178
+ body: unknown;
179
+ }>;
180
+ declare function fetchCurrentUserId(options: {
181
+ projectBaseUrl: string;
182
+ publishableKey: string;
183
+ accessToken: string;
184
+ fetchImpl: FetchLike;
185
+ timeoutMs: number;
186
+ maxRetries: number;
187
+ }): Promise<string | null>;
188
+ declare function resolveRemoteAuthContext(options: {
189
+ env: NodeJS.ProcessEnv;
190
+ fetchImpl: FetchLike;
191
+ timeoutMs: number;
192
+ maxRetries: number;
193
+ now: Date;
194
+ }): Promise<RemoteAuthContext>;
195
+ declare function fetchRemoteMetadata(options: {
196
+ processIds: string[];
197
+ auth: RemoteAuthContext;
198
+ fetchImpl: FetchLike;
199
+ timeoutMs: number;
200
+ maxRetries: number;
201
+ }): Promise<Record<string, RemoteMetadataRecord>>;
202
+ declare function fetchCurrentUserRows(options: {
203
+ auth: RemoteAuthContext;
204
+ tableName: 'processes' | 'lifecyclemodels';
205
+ userId: string;
206
+ select: string;
207
+ fetchImpl: FetchLike;
208
+ timeoutMs: number;
209
+ maxRetries: number;
210
+ }): Promise<unknown[]>;
211
+ declare function collectReferenceHits(root: unknown, targetIds: Set<string>): string[];
212
+ declare function fetchCurrentUserReferenceHits(options: {
213
+ auth: RemoteAuthContext;
214
+ userId: string;
215
+ targetProcessIds: string[];
216
+ fetchImpl: FetchLike;
217
+ timeoutMs: number;
218
+ maxRetries: number;
219
+ }): Promise<ReferenceHits>;
220
+ declare function normalizedSignature(exchanges: ExchangeSummaryRow[]): Array<[string, string, string, string]>;
221
+ declare function detectGroupPattern(processes: DedupAnalyzedProcess[]): string;
222
+ declare function scoreProcessName(process: Pick<DedupAnalyzedProcess, 'name_en' | 'name_zh' | 'remote_name_en' | 'remote_name_zh'>, groupPattern: string): {
223
+ score: number;
224
+ reasons: string[];
225
+ };
226
+ declare function analyzeGroups(groups: DedupInputGroup[], remoteById: Record<string, RemoteMetadataRecord>, referenceHits: ReferenceHits): {
227
+ duplicateGroups: ProcessDedupReviewGroup[];
228
+ deletePlanGroups: DeletePlanGroup[];
229
+ };
230
+ declare function buildDedupGate(duplicateGroups: ProcessDedupReviewGroup[]): ProcessDedupGate;
231
+ export declare function runProcessDedupReview(options: RunProcessDedupReviewOptions): Promise<ProcessDedupReviewReport>;
232
+ export declare const __testInternals: {
233
+ analyzeGroups: typeof analyzeGroups;
234
+ buildDedupGate: typeof buildDedupGate;
235
+ collectReferenceHits: typeof collectReferenceHits;
236
+ detectGroupPattern: typeof detectGroupPattern;
237
+ errorMessage: typeof errorMessage;
238
+ fetchCurrentUserId: typeof fetchCurrentUserId;
239
+ fetchCurrentUserReferenceHits: typeof fetchCurrentUserReferenceHits;
240
+ fetchCurrentUserRows: typeof fetchCurrentUserRows;
241
+ fetchJsonWithRetry: typeof fetchJsonWithRetry;
242
+ fetchRemoteMetadata: typeof fetchRemoteMetadata;
243
+ getLangList: typeof getLangList;
244
+ getLangText: typeof getLangText;
245
+ normalizeAmount: typeof normalizeAmount;
246
+ normalizeExchangeRows: typeof normalizeExchangeRows;
247
+ normalizeInputDocument: typeof normalizeInputDocument;
248
+ normalizedSignature: typeof normalizedSignature;
249
+ parseJsonResponse: typeof parseJsonResponse;
250
+ resolveRemoteAuthContext: typeof resolveRemoteAuthContext;
251
+ scoreProcessName: typeof scoreProcessName;
252
+ };
253
+ export {};
@@ -0,0 +1,108 @@
1
+ import { type JsonObject } from './dataset-local.js';
2
+ import { type SafeParseSchema } from './tidas-sdk-validation.js';
3
+ type BuildPlanKind = 'process' | 'flow';
4
+ type BuildPlanAction = 'validate' | 'materialize';
5
+ type BuildPlanStatus = 'passed' | 'blocked';
6
+ type BuildPlanDecision = 'reuse' | 'update_same_row' | 'version_bump' | 'create_new' | 'block_duplicate' | 'manual_review';
7
+ type UnitOfAnalysisDecision = 'ready_for_materialization' | 'declared_unit_dataset' | 'blocked_until_scaling_evidence' | 'manual_review';
8
+ type GateFinding = {
9
+ code: string;
10
+ severity: 'info' | 'warning' | 'blocker';
11
+ message: string;
12
+ path?: string;
13
+ };
14
+ type SchemaValidationSummary = {
15
+ status: 'passed' | 'failed' | 'not_applicable';
16
+ validator: string | null;
17
+ issue_count: number;
18
+ issues: Array<{
19
+ path: string;
20
+ message: string;
21
+ code: string;
22
+ }>;
23
+ };
24
+ type BuildPlanRequiredFields = {
25
+ required: string[];
26
+ satisfied: string[];
27
+ missing: string[];
28
+ };
29
+ type BuildPlanFiles = {
30
+ gate_report: string | null;
31
+ materialized_artifact: string | null;
32
+ };
33
+ export type BuildPlanGateReport = {
34
+ schema_version: 1;
35
+ generated_at_utc: string;
36
+ kind: BuildPlanKind;
37
+ action: BuildPlanAction;
38
+ status: BuildPlanStatus;
39
+ ruleset_id: string;
40
+ ruleset_version: string;
41
+ input_path: string;
42
+ out_dir: string | null;
43
+ report_only: boolean;
44
+ inputs: {
45
+ plan_schema_version: number | string | null;
46
+ identity_decision: BuildPlanDecision | null;
47
+ unit_of_analysis_decision: UnitOfAnalysisDecision | null;
48
+ };
49
+ required_fields: BuildPlanRequiredFields;
50
+ schema_validation: SchemaValidationSummary;
51
+ findings: GateFinding[];
52
+ blockers: GateFinding[];
53
+ next_action: 'materialize_payload' | 'use_materialized_artifact' | 'fix_build_plan';
54
+ files: BuildPlanFiles;
55
+ };
56
+ export type RunBuildPlanOptions = {
57
+ inputPath: string;
58
+ outDir?: string | null;
59
+ reportOnly?: boolean;
60
+ rawInput?: unknown;
61
+ now?: Date;
62
+ schemas?: Partial<Record<BuildPlanKind, SafeParseSchema>>;
63
+ };
64
+ export type RunProcessBuildPlanValidateOptions = RunBuildPlanOptions;
65
+ export type RunProcessBuildPlanMaterializeOptions = RunBuildPlanOptions;
66
+ export type RunFlowBuildPlanValidateOptions = RunBuildPlanOptions;
67
+ export type RunFlowBuildPlanMaterializeOptions = RunBuildPlanOptions;
68
+ export type ProcessBuildPlanGateReport = BuildPlanGateReport & {
69
+ kind: 'process';
70
+ };
71
+ export type FlowBuildPlanGateReport = BuildPlanGateReport & {
72
+ kind: 'flow';
73
+ };
74
+ type Evaluation = {
75
+ plan: JsonObject;
76
+ findings: GateFinding[];
77
+ blockers: GateFinding[];
78
+ requiredFields: BuildPlanRequiredFields;
79
+ decision: BuildPlanDecision | null;
80
+ unitOfAnalysisDecision: UnitOfAnalysisDecision | null;
81
+ };
82
+ declare function loadBuildPlan(inputPath: string, rawInput: unknown): JsonObject;
83
+ declare function multiLangFromValue(value: unknown, fallback: string, fallbackLang?: string): JsonObject[];
84
+ declare function buildAnnualSupply(plan: JsonObject, referenceExchange: JsonObject): JsonObject[];
85
+ declare function buildCanonicalFlowPayload(plan: JsonObject, inputPath: string): JsonObject;
86
+ declare function buildCanonicalProcessPayload(plan: JsonObject, inputPath: string): JsonObject;
87
+ declare function evidenceBindingPaths(plan: JsonObject): Set<string>;
88
+ declare function decisionFromPlan(plan: JsonObject): BuildPlanDecision | null;
89
+ declare function evaluateBuildPlan(plan: JsonObject, kind: BuildPlanKind): Evaluation;
90
+ declare function validateMaterializedSchema(artifact: JsonObject, kind: BuildPlanKind, schemas: Partial<Record<BuildPlanKind, SafeParseSchema>> | undefined): SchemaValidationSummary;
91
+ declare function materializePlan(plan: JsonObject, kind: BuildPlanKind, inputPath: string): JsonObject;
92
+ export declare function runProcessBuildPlanValidate(options: RunProcessBuildPlanValidateOptions): Promise<ProcessBuildPlanGateReport>;
93
+ export declare function runProcessBuildPlanMaterialize(options: RunProcessBuildPlanMaterializeOptions): Promise<ProcessBuildPlanGateReport>;
94
+ export declare function runFlowBuildPlanValidate(options: RunFlowBuildPlanValidateOptions): Promise<FlowBuildPlanGateReport>;
95
+ export declare function runFlowBuildPlanMaterialize(options: RunFlowBuildPlanMaterializeOptions): Promise<FlowBuildPlanGateReport>;
96
+ export declare const __testInternals: {
97
+ decisionFromPlan: typeof decisionFromPlan;
98
+ evidenceBindingPaths: typeof evidenceBindingPaths;
99
+ evaluateBuildPlan: typeof evaluateBuildPlan;
100
+ loadBuildPlan: typeof loadBuildPlan;
101
+ materializePlan: typeof materializePlan;
102
+ validateMaterializedSchema: typeof validateMaterializedSchema;
103
+ buildCanonicalFlowPayload: typeof buildCanonicalFlowPayload;
104
+ buildCanonicalProcessPayload: typeof buildCanonicalProcessPayload;
105
+ buildAnnualSupply: typeof buildAnnualSupply;
106
+ multiLangFromValue: typeof multiLangFromValue;
107
+ };
108
+ export {};
@@ -0,0 +1,26 @@
1
+ import type { FetchLike } from './http.js';
2
+ import { type SupabaseProcessLookup } from './supabase-rest.js';
3
+ type JsonObject = Record<string, unknown>;
4
+ export type RunProcessGetOptions = {
5
+ processId: string;
6
+ version?: string | null;
7
+ env?: NodeJS.ProcessEnv;
8
+ fetchImpl?: FetchLike;
9
+ timeoutMs?: number;
10
+ now?: Date;
11
+ };
12
+ export type ProcessGetReport = {
13
+ schema_version: 1;
14
+ generated_at_utc: string;
15
+ status: 'resolved_remote_process';
16
+ process_id: string;
17
+ requested_version: string | null;
18
+ resolved_version: string;
19
+ resolution: SupabaseProcessLookup['resolution'];
20
+ source_url: string;
21
+ modified_at: string | null;
22
+ state_code: number | null;
23
+ process: JsonObject;
24
+ };
25
+ export declare function runProcessGet(options: RunProcessGetOptions): Promise<ProcessGetReport>;
26
+ export {};