@rigelbuild/dl-reconcile 0.0.0-stage → 0.0.0

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/LICENSE-APACHE ADDED
@@ -0,0 +1,181 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or Object
36
+ form, made available under the License, as indicated by a copyright
37
+ notice that is included in or attached to the work (an example is
38
+ provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work of authorship, whether in Source or
41
+ Object form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including the original
49
+ version of the Work and any modifications or additions to that Work or
50
+ Derivative Works thereof, that is intentionally submitted to Licensor for
51
+ inclusion in the Work by the copyright owner or by an individual or Legal
52
+ Entity authorized to submit on behalf of the copyright owner. For the
53
+ purposes of this definition, "submitted" means any form of electronic,
54
+ verbal, or written communication sent to the Licensor or its representatives,
55
+ including but not limited to communication on electronic mailing lists,
56
+ source control systems, and issue tracking systems managed by or on behalf
57
+ of the Licensor to discuss and improve the Work, but excluding communication
58
+ that is conspicuously marked or otherwise designated in writing by the
59
+ copyright owner as "Not a Contribution."
60
+
61
+ "Contributor" shall mean Licensor and any individual or Legal Entity on
62
+ behalf of whom a Contribution has been received by Licensor and subsequently
63
+ incorporated within the Work.
64
+
65
+ 2. Grant of Copyright License. Subject to the terms and conditions of this
66
+ License, each Contributor hereby grants to You a perpetual, worldwide,
67
+ non-exclusive, no-charge, royalty-free, irrevocable copyright license to
68
+ reproduce, prepare Derivative Works of, publicly display, publicly perform,
69
+ sublicense, and distribute the Work and such Derivative Works in Source or
70
+ Object form.
71
+
72
+ 3. Grant of Patent License. Subject to the terms and conditions of this License,
73
+ each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
74
+ no-charge, royalty-free, irrevocable (except as stated in this section) patent
75
+ license to make, have made, use, offer to sell, sell, import, and otherwise
76
+ transfer the Work, where such license applies only to those patent claims
77
+ licensable by such Contributor that are necessarily infringed by their
78
+ Contribution(s) alone or by combination of their Contribution(s) with the
79
+ Work to which such Contribution(s) was submitted. If You institute patent
80
+ litigation against any entity (including a cross-claim or counterclaim in a
81
+ lawsuit) alleging that the Work or a Contribution incorporated within the
82
+ Work constitutes direct or contributory patent infringement, then any patent
83
+ licenses granted to You under this License for that Work shall terminate as
84
+ of the date such litigation is filed.
85
+
86
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
87
+ Derivative Works thereof in any medium, with or without modifications, and
88
+ in Source or Object form, provided that You meet the following conditions:
89
+
90
+ (a) You must give any other recipients of the Work or Derivative Works a
91
+ copy of this License; and
92
+
93
+ (b) You must cause any modified files to carry prominent notices stating
94
+ that You changed the files; and
95
+
96
+ (c) You must retain, in the Source form of any Derivative Works that You
97
+ distribute, all copyright, patent, trademark, and attribution notices
98
+ from the Source form of the Work, excluding those notices that do not
99
+ pertain to any part of the Derivative Works; and
100
+
101
+ (d) If the Work includes a NOTICE text file as part of its distribution,
102
+ then any Derivative Works that You distribute must include a readable
103
+ copy of the attribution notices contained within such NOTICE file,
104
+ excluding those notices that do not pertain to any part of the Derivative
105
+ Works, in at least one of the following places: within a NOTICE text file
106
+ distributed as part of the Derivative Works; within the Source form or
107
+ documentation, if provided along with the Derivative Works; or, within a
108
+ display generated by the Work, if and wherever such third-party notices
109
+ normally appear. The contents of the NOTICE file are for informational
110
+ purposes only and do not modify the License. You may add Your own
111
+ attribution notices alongside the NOTICE text, provided they cannot be
112
+ construed as modifying the License.
113
+
114
+ You may add Your own copyright statement to Your modifications and may
115
+ provide additional or different license terms and conditions for use,
116
+ reproduction, and distribution of the Work otherwise in compliance with
117
+ this License.
118
+
119
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any
120
+ Contribution intentionally submitted for inclusion in the Work by You to the
121
+ Licensor shall be under the terms and conditions of this License, without
122
+ any additional terms or conditions. Notwithstanding the above, nothing herein
123
+ shall supersede or modify the terms of any separate license agreement you may
124
+ have executed with Licensor regarding such Contributions.
125
+
126
+ 6. Trademarks. This License does not grant permission to use the trade names,
127
+ trademarks, service marks, or product names of the Licensor, except as
128
+ required for reasonable and customary use in describing the origin of the
129
+ Work and reproducing the NOTICE file.
130
+
131
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
132
+ writing, Licensor provides the Work (and each Contributor provides
133
+ Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
134
+ KIND, either express or implied, including, without limitation, warranties
135
+ or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
136
+ PARTICULAR PURPOSE. You are solely responsible for determining the
137
+ appropriateness of using or redistributing the Work and assume any risks
138
+ associated with Your exercise of permissions under this License.
139
+
140
+ 8. Limitation of Liability. In no event and under no legal theory, whether in
141
+ tort (including negligence), contract, or otherwise, unless required by
142
+ applicable law or agreed to in writing, shall any Contributor be liable to
143
+ You for damages, including any direct, indirect, special, incidental, or
144
+ consequential damages of any character arising as a result of this License
145
+ or out of the use or inability to use the Work, even if such Contributor has
146
+ been advised of the possibility of such damages.
147
+
148
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work
149
+ or Derivative Works thereof, You may choose to offer, and charge a fee for,
150
+ acceptance of support, warranty, indemnity, or other liability obligations
151
+ or rights consistent with this License. However, in accepting such
152
+ obligations, You may act only on Your own behalf and on Your sole
153
+ responsibility, not on behalf of any other Contributor, and only if You agree
154
+ to indemnify, defend, and hold each Contributor harmless for any liability
155
+ incurred by, or claims asserted against, such Contributor by reason of your
156
+ accepting any such warranty or additional liability.
157
+
158
+ END OF TERMS AND CONDITIONS
159
+
160
+ APPENDIX: How to apply the Apache License to your work.
161
+
162
+ To apply the Apache License to your work, attach the following boilerplate
163
+ notice, with fields enclosed by brackets "[]" replaced with your own
164
+ identifying information. (Don't include the brackets!) The text should be
165
+ enclosed in the appropriate comment syntax for the file format. A file or
166
+ class name and purpose should be included on the same printed page as the
167
+ copyright notice for easier identification within third-party archives.
168
+
169
+ Copyright [yyyy] [name of copyright owner]
170
+
171
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not
172
+ use this file except in compliance with the License. You may obtain a copy of
173
+ the License at
174
+
175
+ http://www.apache.org/licenses/LICENSE-2.0
176
+
177
+ Unless required by applicable law or agreed to in writing, software
178
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
179
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
180
+ License for the specific language governing permissions and limitations
181
+ under the License.
package/LICENSE-MIT ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2026 Rigel AI Software Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,23 @@
1
- # Temporary Holding Version
1
+ # @rigelbuild/dl-reconcile
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Reports the decision IDs present in the configured layout to the shared counter. The response lists updated and inserted claims, stale claims, and duplicate IDs.
4
+
5
+ ## Usage
6
+
7
+ ```sh
8
+ bun packages/dl-reconcile/index.ts --config ./ledger.config.json
9
+ bun packages/dl-reconcile/index.ts --config ./ledger.config.json --check
10
+ bun packages/dl-reconcile/index.ts --config ./ledger.config.json --stale-exit
11
+ ```
12
+
13
+ The command discovers files according to the configured design layout, parses every decision, and refuses to submit an empty frontier. `--check` validates files and reports the number found without contacting the counter. `--stale-exit` exits 1 when stale claims remain.
14
+
15
+ ## Credentials
16
+
17
+ `DL_CLAIM_TOKEN` supplies the bearer token. A non-empty trimmed `DL_CLAIM_TOKEN_FILE` value takes precedence. The counter URL is read from `counter.url` in the config; there is no environment override. `GATE_ROOT` optionally sets the repository root; otherwise the Git toplevel is used.
18
+
19
+ ## Exit codes
20
+
21
+ - `0`: reconciliation succeeded, with no stale claims when `--stale-exit` is set.
22
+ - `1`: counter request or service failure, or stale claims with `--stale-exit`.
23
+ - `2`: usage, configuration, or read error.
package/index.ts ADDED
@@ -0,0 +1,355 @@
1
+ #!/usr/bin/env bun
2
+ import { readFile } from "node:fs/promises";
3
+ import { basename, resolve } from "node:path";
4
+ import type { LedgerConfig } from "@rigelbuild/design-ledger-gate";
5
+ import {
6
+ classifyDesignPath,
7
+ loadLedgerConfig,
8
+ readDlClaimToken,
9
+ validateDlClaimToken,
10
+ } from "@rigelbuild/design-ledger-gate";
11
+ import { parseDecisionFile } from "@rigelbuild/design-ledger-gate/decision-files.ts";
12
+
13
+ export interface LandedDecision {
14
+ id: string;
15
+ surface: string;
16
+ ref: string;
17
+ }
18
+
19
+ export interface ReconcileRequest {
20
+ repo: string;
21
+ landed: LandedDecision[];
22
+ }
23
+
24
+ export interface StaleClaim {
25
+ id: string;
26
+ surface: string;
27
+ ref: string;
28
+ lane: string;
29
+ date: string;
30
+ }
31
+
32
+ export interface DuplicateClaim {
33
+ id: string;
34
+ surfaces: string[];
35
+ }
36
+
37
+ export interface ReconcileResponse {
38
+ updated: number;
39
+ inserted: number;
40
+ stale: StaleClaim[];
41
+ duplicates: DuplicateClaim[];
42
+ }
43
+
44
+ export function assertReconcilableLedgers(
45
+ config: LedgerConfig,
46
+ files: ReadonlyMap<string, string>,
47
+ ): ReconcileRequest {
48
+ const surfaces = config.surfaces;
49
+ if (surfaces === undefined || surfaces.length === 0)
50
+ throw new Error("config.surfaces must contain at least one surface");
51
+ if (config.surfaceDepth === 0 && surfaces.length !== 1)
52
+ throw new Error(
53
+ "config.surfaces must contain exactly one surface at depth 0",
54
+ );
55
+ const decisions = [...files]
56
+ .filter(([path]) => classifyDesignPath(path, config) === "decision")
57
+ .sort(([left], [right]) => left.localeCompare(right));
58
+ if (decisions.length === 0)
59
+ throw new Error(
60
+ "decision file list is empty; refusing to post an empty frontier",
61
+ );
62
+ const landed: Array<{ path: string; decision: LandedDecision }> = [];
63
+ for (const [path, text] of decisions) {
64
+ const parsed = parseDecisionFile(path, text);
65
+ if (!parsed.ok)
66
+ throw new Error(
67
+ `malformed decision file ${path}: line ${parsed.error.line}: ${parsed.error.reason}`,
68
+ );
69
+ const relative = path.slice(`${config.designsRoot}/`.length).split("/");
70
+ const surface = config.surfaceDepth === 0 ? surfaces[0] : relative[0];
71
+ if (surface === undefined)
72
+ throw new Error(`cannot determine surface for decision file ${path}`);
73
+ if (!surfaces.includes(surface))
74
+ throw new Error(`unknown design surface ${surface} in ${path}`);
75
+ landed.push({
76
+ path,
77
+ decision: { id: basename(path, ".md"), surface, ref: "none" },
78
+ });
79
+ }
80
+ landed.sort(
81
+ (left, right) =>
82
+ Number(left.decision.id.slice(3)) - Number(right.decision.id.slice(3)) ||
83
+ left.path.localeCompare(right.path),
84
+ );
85
+ return {
86
+ repo: config.counter.partition,
87
+ landed: landed.map(({ decision }) => decision),
88
+ };
89
+ }
90
+
91
+ export type FetchFn = (
92
+ input: string | URL | Request,
93
+ init?: RequestInit,
94
+ ) => Promise<Response>;
95
+
96
+ export interface ReconcileDeps {
97
+ fetchFn?: FetchFn;
98
+ timeoutMs?: number;
99
+ timeoutSignal?: (timeoutMs: number) => AbortSignal;
100
+ }
101
+ function isRecord(value: unknown): value is Record<string, unknown> {
102
+ return typeof value === "object" && value !== null && !Array.isArray(value);
103
+ }
104
+
105
+ function endpoint(config: LedgerConfig): string {
106
+ return `${config.counter.url.replace(/\/+$/, "")}/reconcile`;
107
+ }
108
+
109
+ export async function reconcile(
110
+ body: ReconcileRequest,
111
+ config: LedgerConfig,
112
+ token: string,
113
+ deps: ReconcileDeps = {},
114
+ ): Promise<ReconcileResponse> {
115
+ const trimmedToken = validateDlClaimToken(token);
116
+ if (body.landed.length === 0)
117
+ throw new Error("refusing to reconcile an empty landed frontier");
118
+ const timeoutMs =
119
+ deps.timeoutMs !== undefined && deps.timeoutMs > 0
120
+ ? deps.timeoutMs
121
+ : 30_000;
122
+ let response: Response;
123
+ try {
124
+ response = await (deps.fetchFn ?? fetch)(endpoint(config), {
125
+ method: "POST",
126
+ redirect: "error",
127
+ headers: {
128
+ Authorization: `Bearer ${trimmedToken}`,
129
+ "Content-Type": "application/json",
130
+ },
131
+ body: JSON.stringify(body),
132
+ signal: (deps.timeoutSignal ?? AbortSignal.timeout)(timeoutMs),
133
+ });
134
+ } catch (error) {
135
+ const name = error instanceof Error ? error.name : "UnknownError";
136
+ throw new Error(`request to ${endpoint(config)} failed (${name})`);
137
+ }
138
+ if (!response.ok)
139
+ throw new Error(`reconciliation failed with HTTP ${response.status}`);
140
+ const payload: unknown = await response.json();
141
+ if (!isRecord(payload)) throw new Error("invalid reconciliation response");
142
+ if (
143
+ typeof payload.updated !== "number" ||
144
+ typeof payload.inserted !== "number" ||
145
+ !Array.isArray(payload.stale) ||
146
+ !Array.isArray(payload.duplicates)
147
+ )
148
+ throw new Error("invalid reconciliation response");
149
+ const staleItems: unknown[] = payload.stale;
150
+ const duplicateItems: unknown[] = payload.duplicates;
151
+ const stale: StaleClaim[] = [];
152
+ for (const item of staleItems) {
153
+ if (
154
+ !isRecord(item) ||
155
+ typeof item.id !== "string" ||
156
+ typeof item.surface !== "string" ||
157
+ typeof item.ref !== "string" ||
158
+ typeof item.lane !== "string" ||
159
+ typeof item.date !== "string"
160
+ )
161
+ throw new Error("invalid reconciliation response");
162
+ stale.push({
163
+ id: item.id,
164
+ surface: item.surface,
165
+ ref: item.ref,
166
+ lane: item.lane,
167
+ date: item.date,
168
+ });
169
+ }
170
+ const duplicates: DuplicateClaim[] = [];
171
+ for (const item of duplicateItems) {
172
+ if (
173
+ !isRecord(item) ||
174
+ typeof item.id !== "string" ||
175
+ !Array.isArray(item.surfaces) ||
176
+ !item.surfaces.every((surface: unknown) => typeof surface === "string")
177
+ )
178
+ throw new Error("invalid reconciliation response");
179
+ const surfaces: string[] = item.surfaces;
180
+ duplicates.push({ id: item.id, surfaces });
181
+ }
182
+ return {
183
+ updated: payload.updated,
184
+ inserted: payload.inserted,
185
+ stale,
186
+ duplicates,
187
+ };
188
+ }
189
+
190
+ export function formatReconcileOutput(response: ReconcileResponse): string {
191
+ const lines = [
192
+ `updated: ${response.updated} inserted: ${response.inserted}`,
193
+ ];
194
+ lines.push(`stale: ${response.stale.length}`);
195
+ for (const entry of response.stale)
196
+ lines.push(
197
+ ` ${entry.id} ${entry.surface} ${entry.lane} ${entry.ref} ${entry.date}`,
198
+ );
199
+ lines.push(`duplicates: ${response.duplicates.length}`);
200
+ for (const entry of response.duplicates)
201
+ lines.push(` ${entry.id} ${entry.surfaces.join(" ")}`);
202
+ return lines.join("\n");
203
+ }
204
+
205
+ interface CliOptions {
206
+ configPath: string;
207
+ check: boolean;
208
+ staleExit: boolean;
209
+ }
210
+
211
+ export interface RunDeps {
212
+ root?: string;
213
+ token?: string;
214
+ fetchFn?: FetchFn;
215
+ log?: (message: string) => void;
216
+ err?: (message: string) => void;
217
+ }
218
+
219
+ function parseCliArgs(args: readonly string[]): CliOptions {
220
+ let configPath: string | undefined;
221
+ let check = false;
222
+ let staleExit = false;
223
+ for (let index = 0; index < args.length; index += 1) {
224
+ const arg = args[index] ?? "";
225
+ if (arg === "--check") {
226
+ if (check) throw new Error("duplicate --check flag");
227
+ check = true;
228
+ } else if (arg === "--stale-exit") {
229
+ if (staleExit) throw new Error("duplicate --stale-exit flag");
230
+ staleExit = true;
231
+ } else if (arg === "--config") {
232
+ if (configPath !== undefined) throw new Error("duplicate --config flag");
233
+ configPath = args[index + 1];
234
+ if (configPath === undefined || configPath.startsWith("--"))
235
+ throw new Error("--config requires a path");
236
+ index += 1;
237
+ } else if (arg.startsWith("--config=")) {
238
+ if (configPath !== undefined) throw new Error("duplicate --config flag");
239
+ configPath = arg.slice("--config=".length);
240
+ if (configPath.length === 0) throw new Error("--config requires a path");
241
+ } else {
242
+ throw new Error(`unknown argument: ${arg}`);
243
+ }
244
+ }
245
+ if (configPath === undefined) throw new Error("--config is required");
246
+ return { configPath, check, staleExit };
247
+ }
248
+
249
+ function repositoryRoot(): string {
250
+ if (process.env.GATE_ROOT !== undefined)
251
+ return resolve(process.env.GATE_ROOT);
252
+ const result = Bun.spawnSync({
253
+ cmd: ["git", "rev-parse", "--show-toplevel"],
254
+ stdout: "pipe",
255
+ stderr: "pipe",
256
+ });
257
+ if (result.exitCode !== 0)
258
+ throw new Error(
259
+ new TextDecoder().decode(result.stderr).trim() || "cannot find git root",
260
+ );
261
+ return new TextDecoder().decode(result.stdout).trim();
262
+ }
263
+
264
+ async function discoverDecisionFiles(
265
+ root: string,
266
+ config: LedgerConfig,
267
+ ): Promise<Map<string, string>> {
268
+ const files = new Map<string, string>();
269
+ const glob = new Bun.Glob(`${config.designsRoot}/**`);
270
+ for await (const path of glob.scan({ cwd: root, onlyFiles: true })) {
271
+ const normalizedPath = path.replaceAll("\\", "/");
272
+ const kind = classifyDesignPath(normalizedPath, config);
273
+ if (kind === "misplaced")
274
+ throw new Error(`misplaced decision path ${normalizedPath}`);
275
+ if (kind !== "decision") continue;
276
+ files.set(
277
+ normalizedPath,
278
+ await readFile(resolve(root, normalizedPath), "utf8"),
279
+ );
280
+ }
281
+ return files;
282
+ }
283
+
284
+ export async function runOnce(
285
+ args: readonly string[],
286
+ deps: RunDeps = {},
287
+ ): Promise<number> {
288
+ const log = deps.log ?? console.log;
289
+ const err = deps.err ?? console.error;
290
+ if (args.length === 1 && args[0] === "--help") {
291
+ log("Usage: dl-reconcile --config <path> [--check] [--stale-exit]");
292
+ return 0;
293
+ }
294
+ let options: CliOptions;
295
+ try {
296
+ options = parseCliArgs(args);
297
+ } catch (error) {
298
+ err(
299
+ `dl-reconcile: ${error instanceof Error ? error.message : String(error)}`,
300
+ );
301
+ return 2;
302
+ }
303
+ let config: LedgerConfig;
304
+ let body: ReconcileRequest;
305
+ try {
306
+ config = loadLedgerConfig(options.configPath);
307
+ const root =
308
+ deps.root === undefined ? repositoryRoot() : resolve(deps.root);
309
+ body = assertReconcilableLedgers(
310
+ config,
311
+ await discoverDecisionFiles(root, config),
312
+ );
313
+ } catch (error) {
314
+ err(
315
+ `dl-reconcile: ${error instanceof Error ? error.message : String(error)}`,
316
+ );
317
+ return 2;
318
+ }
319
+ if (options.check) {
320
+ log(
321
+ `Design ledger parse check passed (${body.landed.length} decision files).`,
322
+ );
323
+ return 0;
324
+ }
325
+ let token: string;
326
+ try {
327
+ token = validateDlClaimToken(deps.token ?? (await readDlClaimToken()));
328
+ } catch (error) {
329
+ const message =
330
+ error instanceof Error && error.message === "DL_CLAIM_TOKEN is required"
331
+ ? error.message
332
+ : "DL_CLAIM_TOKEN must contain printable ASCII characters without whitespace";
333
+ err(`dl-reconcile: ${message}`);
334
+ return 2;
335
+ }
336
+ try {
337
+ const response = await reconcile(body, config, token, {
338
+ ...(deps.fetchFn === undefined ? {} : { fetchFn: deps.fetchFn }),
339
+ });
340
+ log(formatReconcileOutput(response));
341
+ return options.staleExit && response.stale.length > 0 ? 1 : 0;
342
+ } catch (error) {
343
+ if (
344
+ error instanceof Error &&
345
+ error.message.startsWith("reconciliation failed with HTTP ")
346
+ ) {
347
+ err(`dl-reconcile: ${error.message}`);
348
+ } else {
349
+ const name = error instanceof Error ? error.name : "UnknownError";
350
+ err(`dl-reconcile: request to ${endpoint(config)} failed (${name})`);
351
+ }
352
+ return 1;
353
+ }
354
+ }
355
+ if (import.meta.main) process.exitCode = await runOnce(process.argv.slice(2));
package/package.json CHANGED
@@ -1,6 +1,31 @@
1
1
  {
2
- "name": "@rigelbuild/dl-reconcile",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@rigelbuild/dl-reconcile",
3
+ "version": "0.0.0",
4
+ "type": "module",
5
+ "license": "MIT OR Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/RigelBuild/meissa.git",
9
+ "directory": "packages/dl-reconcile"
10
+ },
11
+ "bin": {
12
+ "dl-reconcile": "./index.ts"
13
+ },
14
+ "files": [
15
+ "package.json",
16
+ "index.ts",
17
+ "README.md",
18
+ "LICENSE-MIT",
19
+ "LICENSE-APACHE"
20
+ ],
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "dependencies": {
25
+ "@rigelbuild/design-ledger-gate": "0.0.0"
26
+ },
27
+ "devDependencies": {
28
+ "@types/bun": "1.4.0",
29
+ "typescript": "6.0.3"
30
+ }
31
+ }