@lexbuild/cli 1.13.2 → 1.14.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/README.md +61 -3
- package/dist/index.js +293 -12
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](https://github.com/chris-c-thomas/LexBuild/actions/workflows/ci.yml)
|
|
5
5
|
[](https://github.com/chris-c-thomas/LexBuild/blob/main/LICENSE)
|
|
6
6
|
|
|
7
|
-
Download and convert U.S. legal XML into structured Markdown optimized for AI, RAG pipelines, and semantic search. Supports the [U.S. Code](https://uscode.house.gov/) (54 titles, 60,000+ sections)
|
|
7
|
+
Download and convert U.S. legal XML into structured Markdown optimized for AI, RAG pipelines, and semantic search. Supports the [U.S. Code](https://uscode.house.gov/) (54 titles, 60,000+ sections), the [eCFR](https://www.ecfr.gov/) (50 titles, 200,000+ sections), and the [Federal Register](https://www.federalregister.gov/) (~30,000 documents/year).
|
|
8
8
|
|
|
9
9
|
## Install
|
|
10
10
|
|
|
@@ -27,9 +27,14 @@ lexbuild convert-usc --all
|
|
|
27
27
|
lexbuild download-ecfr --all
|
|
28
28
|
lexbuild convert-ecfr --all
|
|
29
29
|
|
|
30
|
-
#
|
|
30
|
+
# Federal Register — download and convert recent documents
|
|
31
|
+
lexbuild download-fr --recent 30
|
|
32
|
+
lexbuild convert-fr --all
|
|
33
|
+
|
|
34
|
+
# Start small — a single title or document
|
|
31
35
|
lexbuild download-usc --titles 1 && lexbuild convert-usc --titles 1
|
|
32
36
|
lexbuild download-ecfr --titles 17 && lexbuild convert-ecfr --titles 17
|
|
37
|
+
lexbuild download-fr --document 2026-06029 && lexbuild convert-fr --all
|
|
33
38
|
```
|
|
34
39
|
|
|
35
40
|
## Commands
|
|
@@ -140,6 +145,50 @@ lexbuild convert-ecfr ./downloads/ecfr/xml/ECFR-title17.xml # Direct file path
|
|
|
140
145
|
| `--dry-run` | — | Parse and report without writing |
|
|
141
146
|
| `-v, --verbose` | — | Verbose file output |
|
|
142
147
|
|
|
148
|
+
### `download-fr`
|
|
149
|
+
|
|
150
|
+
Download Federal Register XML and metadata from the FederalRegister.gov API.
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
lexbuild download-fr --recent 30 # Last 30 days
|
|
154
|
+
lexbuild download-fr --from 2026-01-01 --to 2026-03-31 # Date range
|
|
155
|
+
lexbuild download-fr --from 2026-01-01 --types rule,proposed_rule # Filter by type
|
|
156
|
+
lexbuild download-fr --document 2026-06029 # Single document
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
| Option | Default | Description |
|
|
160
|
+
|--------|---------|-------------|
|
|
161
|
+
| `--from <YYYY-MM-DD>` | — | Start date (inclusive) |
|
|
162
|
+
| `--to <YYYY-MM-DD>` | today | End date (inclusive) |
|
|
163
|
+
| `--recent <days>` | — | Download last N days |
|
|
164
|
+
| `--document <number>` | — | Download single document by number |
|
|
165
|
+
| `-o, --output <dir>` | `./downloads/fr` | Output directory |
|
|
166
|
+
| `--types` | all | `rule`, `proposed_rule`, `notice`, `presidential_document` |
|
|
167
|
+
| `--limit <n>` | — | Max documents (for testing) |
|
|
168
|
+
|
|
169
|
+
### `convert-fr`
|
|
170
|
+
|
|
171
|
+
Convert downloaded FR XML to Markdown.
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
lexbuild convert-fr --all # All downloaded documents
|
|
175
|
+
lexbuild convert-fr --from 2026-01-01 --to 2026-03-31 # Filter by date range
|
|
176
|
+
lexbuild convert-fr --all --types rule # Filter by type
|
|
177
|
+
lexbuild convert-fr ./downloads/fr/2026/03/2026-06029.xml # Single file
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
| Option | Default | Description |
|
|
181
|
+
|--------|---------|-------------|
|
|
182
|
+
| `--all` | — | Convert all documents in input directory |
|
|
183
|
+
| `--from <YYYY-MM-DD>` | — | Filter start date |
|
|
184
|
+
| `--to <YYYY-MM-DD>` | — | Filter end date |
|
|
185
|
+
| `-i, --input-dir <dir>` | `./downloads/fr` | Input directory |
|
|
186
|
+
| `-o, --output <dir>` | `./output` | Output directory |
|
|
187
|
+
| `--types` | all | Filter by document type |
|
|
188
|
+
| `--link-style` | `plaintext` | `plaintext`, `canonical`, or `relative` |
|
|
189
|
+
| `--dry-run` | — | Parse and report without writing |
|
|
190
|
+
| `-v, --verbose` | — | Verbose file output |
|
|
191
|
+
|
|
143
192
|
## Output Structure
|
|
144
193
|
|
|
145
194
|
### U.S. Code
|
|
@@ -159,6 +208,14 @@ lexbuild convert-ecfr ./downloads/ecfr/xml/ECFR-title17.xml # Direct file path
|
|
|
159
208
|
| `chapter` | `output/ecfr/title-17/chapter-IV/chapter-IV.md` |
|
|
160
209
|
| `title` | `output/ecfr/title-17.md` |
|
|
161
210
|
|
|
211
|
+
### Federal Register
|
|
212
|
+
|
|
213
|
+
| Example Path |
|
|
214
|
+
|---|
|
|
215
|
+
| `output/fr/2026/03/2026-06029.md` |
|
|
216
|
+
|
|
217
|
+
FR documents are atomic — one file per document, organized by year and month. No granularity options.
|
|
218
|
+
|
|
162
219
|
Every file includes YAML frontmatter with source metadata (`source`, `legal_status`, identifier, hierarchy context) followed by the legal text in Markdown. Section and chapter/part granularities generate `_meta.json` sidecar files and `README.md` summaries per title.
|
|
163
220
|
|
|
164
221
|
## Performance
|
|
@@ -172,7 +229,7 @@ The full U.S. Code — all 54 titles, 60,000+ sections, ~85 million estimated to
|
|
|
172
229
|
|
|
173
230
|
## Monorepo Context
|
|
174
231
|
|
|
175
|
-
This is the published CLI for the [LexBuild](https://github.com/chris-c-thomas/LexBuild) monorepo. It depends on [`@lexbuild/core`](https://www.npmjs.com/package/@lexbuild/core), [`@lexbuild/usc`](https://www.npmjs.com/package/@lexbuild/usc),
|
|
232
|
+
This is the published CLI for the [LexBuild](https://github.com/chris-c-thomas/LexBuild) monorepo. It depends on [`@lexbuild/core`](https://www.npmjs.com/package/@lexbuild/core), [`@lexbuild/usc`](https://www.npmjs.com/package/@lexbuild/usc), [`@lexbuild/ecfr`](https://www.npmjs.com/package/@lexbuild/ecfr), and [`@lexbuild/fr`](https://www.npmjs.com/package/@lexbuild/fr) for all conversion and download logic.
|
|
176
233
|
|
|
177
234
|
```bash
|
|
178
235
|
pnpm turbo build --filter=@lexbuild/cli
|
|
@@ -186,6 +243,7 @@ pnpm turbo typecheck --filter=@lexbuild/cli
|
|
|
186
243
|
| [`@lexbuild/core`](https://www.npmjs.com/package/@lexbuild/core) | Shared parsing, AST, and rendering infrastructure |
|
|
187
244
|
| [`@lexbuild/usc`](https://www.npmjs.com/package/@lexbuild/usc) | U.S. Code converter — programmatic API |
|
|
188
245
|
| [`@lexbuild/ecfr`](https://www.npmjs.com/package/@lexbuild/ecfr) | eCFR converter — programmatic API |
|
|
246
|
+
| [`@lexbuild/fr`](https://www.npmjs.com/package/@lexbuild/fr) | Federal Register converter — programmatic API |
|
|
189
247
|
|
|
190
248
|
## License
|
|
191
249
|
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
import { createRequire } from "module";
|
|
5
|
-
import { Command as
|
|
5
|
+
import { Command as Command8 } from "commander";
|
|
6
6
|
|
|
7
7
|
// src/commands/convert-usc.ts
|
|
8
8
|
import chalk2 from "chalk";
|
|
@@ -488,13 +488,13 @@ Source: https://uscode.house.gov/download/download.shtml`
|
|
|
488
488
|
releasePoint,
|
|
489
489
|
onProgress: ({ current, total, titleNumber, phase }) => {
|
|
490
490
|
if (phase === "extracting") {
|
|
491
|
-
spinner.text = `Extracting USC titles (${current}/${total}) \u2014 Title ${titleNumber}
|
|
491
|
+
spinner.text = `Extracting USC titles (${current}/${total}) \u2014 Title ${titleNumber}`;
|
|
492
492
|
} else if (total === 1) {
|
|
493
|
-
spinner.text = `Downloading USC Title ${titleNumber}
|
|
493
|
+
spinner.text = `Downloading USC Title ${titleNumber}`;
|
|
494
494
|
} else if (current === 0) {
|
|
495
|
-
spinner.text = "Downloading USC bulk archive
|
|
495
|
+
spinner.text = "Downloading USC bulk archive";
|
|
496
496
|
} else {
|
|
497
|
-
spinner.text = `Downloading USC titles (${current}/${total}) \u2014 Title ${titleNumber}
|
|
497
|
+
spinner.text = `Downloading USC titles (${current}/${total}) \u2014 Title ${titleNumber}`;
|
|
498
498
|
}
|
|
499
499
|
}
|
|
500
500
|
});
|
|
@@ -972,9 +972,9 @@ async function downloadFromGovinfo(titles, outputDir, spinner, startTime) {
|
|
|
972
972
|
titles,
|
|
973
973
|
onProgress: ({ current, total, titleNumber }) => {
|
|
974
974
|
if (total === 1) {
|
|
975
|
-
spinner.text = `Downloading eCFR Title ${titleNumber} from govinfo
|
|
975
|
+
spinner.text = `Downloading eCFR Title ${titleNumber} from govinfo`;
|
|
976
976
|
} else {
|
|
977
|
-
spinner.text = `Downloading eCFR titles from govinfo (${current}/${total}) \u2014 Title ${titleNumber}
|
|
977
|
+
spinner.text = `Downloading eCFR titles from govinfo (${current}/${total}) \u2014 Title ${titleNumber}`;
|
|
978
978
|
}
|
|
979
979
|
}
|
|
980
980
|
});
|
|
@@ -1015,9 +1015,9 @@ async function downloadFromApi(options, titles, outputDir, spinner, startTime, m
|
|
|
1015
1015
|
titlesMeta: meta,
|
|
1016
1016
|
onProgress: ({ current, total, titleNumber }) => {
|
|
1017
1017
|
if (total === 1) {
|
|
1018
|
-
spinner.text = `Downloading eCFR Title ${titleNumber} from eCFR API
|
|
1018
|
+
spinner.text = `Downloading eCFR Title ${titleNumber} from eCFR API`;
|
|
1019
1019
|
} else {
|
|
1020
|
-
spinner.text = `Downloading eCFR titles from eCFR API (${current}/${total}) \u2014 Title ${titleNumber}
|
|
1020
|
+
spinner.text = `Downloading eCFR titles from eCFR API (${current}/${total}) \u2014 Title ${titleNumber}`;
|
|
1021
1021
|
}
|
|
1022
1022
|
}
|
|
1023
1023
|
});
|
|
@@ -1074,10 +1074,283 @@ async function downloadFromApi(options, titles, outputDir, spinner, startTime, m
|
|
|
1074
1074
|
console.log("");
|
|
1075
1075
|
}
|
|
1076
1076
|
|
|
1077
|
+
// src/commands/download-fr.ts
|
|
1078
|
+
import { Command as Command6 } from "commander";
|
|
1079
|
+
import { relative as relative5, resolve as resolve5 } from "path";
|
|
1080
|
+
import { downloadFrDocuments, downloadSingleFrDocument } from "@lexbuild/fr";
|
|
1081
|
+
var VALID_TYPES = /* @__PURE__ */ new Map([
|
|
1082
|
+
["rule", "RULE"],
|
|
1083
|
+
["proposed_rule", "PRORULE"],
|
|
1084
|
+
["notice", "NOTICE"],
|
|
1085
|
+
["presidential_document", "PRESDOCU"]
|
|
1086
|
+
]);
|
|
1087
|
+
var downloadFrCommand = new Command6("download-fr").description("Download Federal Register XML and metadata from federalregister.gov").option("-o, --output <dir>", "Download directory", "./downloads/fr").option("--from <YYYY-MM-DD>", "Start date (inclusive)").option("--to <YYYY-MM-DD>", "End date (inclusive, defaults to today)").option("--types <types>", "Document types: rule, proposed_rule, notice, presidential_document").option("--recent <days>", "Download last N days").option("--document <number>", "Download a single document by number").option("--limit <n>", "Maximum number of documents (for testing)").addHelpText(
|
|
1088
|
+
"after",
|
|
1089
|
+
`
|
|
1090
|
+
Examples:
|
|
1091
|
+
$ lexbuild download-fr --from 2026-01-01 --to 2026-03-31
|
|
1092
|
+
$ lexbuild download-fr --from 2026-01-01 --types rule,proposed_rule
|
|
1093
|
+
$ lexbuild download-fr --recent 30
|
|
1094
|
+
$ lexbuild download-fr --document 2026-06029
|
|
1095
|
+
|
|
1096
|
+
Document types:
|
|
1097
|
+
rule Final rules
|
|
1098
|
+
proposed_rule Proposed rules (NPRMs)
|
|
1099
|
+
notice Notices
|
|
1100
|
+
presidential_document Executive orders, memoranda, proclamations`
|
|
1101
|
+
).action(async (options) => {
|
|
1102
|
+
if (!options.from && !options.recent && !options.document) {
|
|
1103
|
+
console.error(
|
|
1104
|
+
error(
|
|
1105
|
+
"Specify --from <date>, --recent <days>, or --document <number>\nExamples: --from 2026-01-01, --recent 30, --document 2026-06029"
|
|
1106
|
+
)
|
|
1107
|
+
);
|
|
1108
|
+
process.exit(1);
|
|
1109
|
+
}
|
|
1110
|
+
if (options.from && !/^\d{4}-\d{2}-\d{2}$/.test(options.from)) {
|
|
1111
|
+
console.error(error("--from must be in YYYY-MM-DD format"));
|
|
1112
|
+
process.exit(1);
|
|
1113
|
+
}
|
|
1114
|
+
if (options.to && !/^\d{4}-\d{2}-\d{2}$/.test(options.to)) {
|
|
1115
|
+
console.error(error("--to must be in YYYY-MM-DD format"));
|
|
1116
|
+
process.exit(1);
|
|
1117
|
+
}
|
|
1118
|
+
let types;
|
|
1119
|
+
if (options.types) {
|
|
1120
|
+
types = [];
|
|
1121
|
+
for (const raw of options.types.split(",")) {
|
|
1122
|
+
const normalized = raw.trim().toLowerCase();
|
|
1123
|
+
const mapped = VALID_TYPES.get(normalized);
|
|
1124
|
+
if (!mapped) {
|
|
1125
|
+
console.error(
|
|
1126
|
+
error(
|
|
1127
|
+
`Invalid document type "${raw.trim()}". Valid types: ${[...VALID_TYPES.keys()].join(", ")}`
|
|
1128
|
+
)
|
|
1129
|
+
);
|
|
1130
|
+
process.exit(1);
|
|
1131
|
+
}
|
|
1132
|
+
types.push(mapped);
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
const outputDir = resolve5(options.output);
|
|
1136
|
+
const startTime = performance.now();
|
|
1137
|
+
if (options.document) {
|
|
1138
|
+
const spinner2 = createSpinner(`Downloading FR document ${options.document}`);
|
|
1139
|
+
try {
|
|
1140
|
+
const file = await downloadSingleFrDocument(options.document, outputDir);
|
|
1141
|
+
spinner2.succeed(`Downloaded FR document ${options.document}`);
|
|
1142
|
+
console.log();
|
|
1143
|
+
console.log(
|
|
1144
|
+
summaryBlock({
|
|
1145
|
+
title: "Download Complete",
|
|
1146
|
+
rows: [
|
|
1147
|
+
["Document", file.documentNumber],
|
|
1148
|
+
["Date", file.publicationDate],
|
|
1149
|
+
["Size", formatBytes(file.size)],
|
|
1150
|
+
["XML", relative5(process.cwd(), file.xmlPath)],
|
|
1151
|
+
["JSON", relative5(process.cwd(), file.jsonPath)]
|
|
1152
|
+
]
|
|
1153
|
+
})
|
|
1154
|
+
);
|
|
1155
|
+
} catch (err) {
|
|
1156
|
+
spinner2.fail(`Failed to download ${options.document}`);
|
|
1157
|
+
console.error(error(err instanceof Error ? err.message : String(err)));
|
|
1158
|
+
process.exit(1);
|
|
1159
|
+
}
|
|
1160
|
+
return;
|
|
1161
|
+
}
|
|
1162
|
+
let from;
|
|
1163
|
+
if (options.recent) {
|
|
1164
|
+
const days = parseInt(options.recent, 10);
|
|
1165
|
+
if (isNaN(days) || days <= 0) {
|
|
1166
|
+
console.error(error("--recent must be a positive integer"));
|
|
1167
|
+
process.exit(1);
|
|
1168
|
+
}
|
|
1169
|
+
const d = /* @__PURE__ */ new Date();
|
|
1170
|
+
d.setDate(d.getDate() - days);
|
|
1171
|
+
from = d.toISOString().slice(0, 10);
|
|
1172
|
+
} else {
|
|
1173
|
+
from = options.from ?? "";
|
|
1174
|
+
}
|
|
1175
|
+
const to = options.to ?? (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
1176
|
+
let limit;
|
|
1177
|
+
if (options.limit) {
|
|
1178
|
+
limit = parseInt(options.limit, 10);
|
|
1179
|
+
if (isNaN(limit) || limit <= 0) {
|
|
1180
|
+
console.error(error("--limit must be a positive integer"));
|
|
1181
|
+
process.exit(1);
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
const spinner = createSpinner(`Downloading Federal Register documents from ${from} to ${to}`);
|
|
1185
|
+
try {
|
|
1186
|
+
const result = await downloadFrDocuments({
|
|
1187
|
+
output: outputDir,
|
|
1188
|
+
from,
|
|
1189
|
+
to,
|
|
1190
|
+
types,
|
|
1191
|
+
limit,
|
|
1192
|
+
onProgress: (progress) => {
|
|
1193
|
+
const pct = progress.totalDocuments > 0 ? Math.round(progress.documentsDownloaded / progress.totalDocuments * 100) : 0;
|
|
1194
|
+
spinner.text = `Downloading FR documents (${formatNumber(progress.documentsDownloaded)}/${formatNumber(progress.totalDocuments)}) ${pct}% \u2014 ${progress.currentDocument}`;
|
|
1195
|
+
}
|
|
1196
|
+
});
|
|
1197
|
+
const elapsed = performance.now() - startTime;
|
|
1198
|
+
spinner.succeed(
|
|
1199
|
+
`Downloaded ${formatNumber(result.documentsDownloaded)} Federal Register documents`
|
|
1200
|
+
);
|
|
1201
|
+
console.log();
|
|
1202
|
+
const rows = [
|
|
1203
|
+
["Date range", `${result.dateRange.from} \u2192 ${result.dateRange.to}`],
|
|
1204
|
+
["Documents", formatNumber(result.documentsDownloaded)],
|
|
1205
|
+
["Total size", formatBytes(result.totalBytes)],
|
|
1206
|
+
["Duration", formatDuration(elapsed)]
|
|
1207
|
+
];
|
|
1208
|
+
if (types) {
|
|
1209
|
+
rows.push(["Types", types.join(", ")]);
|
|
1210
|
+
}
|
|
1211
|
+
if (result.skipped > 0) {
|
|
1212
|
+
rows.push(["Skipped (no XML)", formatNumber(result.skipped)]);
|
|
1213
|
+
}
|
|
1214
|
+
if (result.failed.length > 0) {
|
|
1215
|
+
rows.push(["Failed", formatNumber(result.failed.length)]);
|
|
1216
|
+
}
|
|
1217
|
+
rows.push(["Output", relative5(process.cwd(), outputDir)]);
|
|
1218
|
+
console.log(summaryBlock({ title: "Download Complete", rows }));
|
|
1219
|
+
if (result.failed.length > 0) {
|
|
1220
|
+
console.log();
|
|
1221
|
+
console.log(error(`${result.failed.length} document(s) failed to download:`));
|
|
1222
|
+
for (const f of result.failed.slice(0, 10)) {
|
|
1223
|
+
console.error(` ${f.documentNumber}: ${f.error}`);
|
|
1224
|
+
}
|
|
1225
|
+
if (result.failed.length > 10) {
|
|
1226
|
+
console.error(` ... and ${result.failed.length - 10} more`);
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
} catch (err) {
|
|
1230
|
+
spinner.fail("Download failed");
|
|
1231
|
+
console.error(error(err instanceof Error ? err.message : String(err)));
|
|
1232
|
+
process.exit(1);
|
|
1233
|
+
}
|
|
1234
|
+
});
|
|
1235
|
+
|
|
1236
|
+
// src/commands/convert-fr.ts
|
|
1237
|
+
import { Command as Command7 } from "commander";
|
|
1238
|
+
import { existsSync as existsSync3 } from "fs";
|
|
1239
|
+
import { relative as relative6, resolve as resolve6 } from "path";
|
|
1240
|
+
import { convertFrDocuments } from "@lexbuild/fr";
|
|
1241
|
+
var VALID_TYPES2 = /* @__PURE__ */ new Map([
|
|
1242
|
+
["rule", "RULE"],
|
|
1243
|
+
["proposed_rule", "PRORULE"],
|
|
1244
|
+
["notice", "NOTICE"],
|
|
1245
|
+
["presidential_document", "PRESDOCU"]
|
|
1246
|
+
]);
|
|
1247
|
+
var convertFrCommand = new Command7("convert-fr").description("Convert Federal Register XML to Markdown").argument("[input]", "Path to single FR XML file (optional)").option("-o, --output <dir>", "Output directory", "./output").option("-i, --input-dir <dir>", "Directory containing downloaded FR files", "./downloads/fr").option("--all", "Convert all downloaded documents in input directory", false).option("--from <YYYY-MM-DD>", "Filter: start date").option("--to <YYYY-MM-DD>", "Filter: end date").option("--types <types>", "Filter: document types (rule, proposed_rule, notice, presidential_document)").option("--link-style <style>", "Link style: relative, canonical, plaintext", "plaintext").option("--dry-run", "Parse only, don't write files", false).option("-v, --verbose", "Print detailed file output", false).addHelpText(
|
|
1248
|
+
"after",
|
|
1249
|
+
`
|
|
1250
|
+
Examples:
|
|
1251
|
+
$ lexbuild convert-fr --all Convert all downloaded FR documents
|
|
1252
|
+
$ lexbuild convert-fr --from 2026-01-01 --to 2026-03-31 Convert by date range
|
|
1253
|
+
$ lexbuild convert-fr --all --types rule Convert only rules
|
|
1254
|
+
$ lexbuild convert-fr ./downloads/fr/2026/03/2026-06029.xml Convert single document
|
|
1255
|
+
$ lexbuild convert-fr --all --dry-run Preview without writing files`
|
|
1256
|
+
).action(async (inputArg, options) => {
|
|
1257
|
+
if (!inputArg && !options.all && !options.from) {
|
|
1258
|
+
console.error(
|
|
1259
|
+
error(
|
|
1260
|
+
"Specify a path to an XML file, --all, or --from <date>\nExamples: convert-fr --all, convert-fr --from 2026-01-01"
|
|
1261
|
+
)
|
|
1262
|
+
);
|
|
1263
|
+
process.exit(1);
|
|
1264
|
+
}
|
|
1265
|
+
let types;
|
|
1266
|
+
if (options.types) {
|
|
1267
|
+
types = [];
|
|
1268
|
+
for (const raw of options.types.split(",")) {
|
|
1269
|
+
const normalized = raw.trim().toLowerCase();
|
|
1270
|
+
const mapped = VALID_TYPES2.get(normalized);
|
|
1271
|
+
if (!mapped) {
|
|
1272
|
+
console.error(
|
|
1273
|
+
error(
|
|
1274
|
+
`Invalid document type "${raw.trim()}". Valid types: ${[...VALID_TYPES2.keys()].join(", ")}`
|
|
1275
|
+
)
|
|
1276
|
+
);
|
|
1277
|
+
process.exit(1);
|
|
1278
|
+
}
|
|
1279
|
+
types.push(mapped);
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
let inputPath;
|
|
1283
|
+
if (inputArg) {
|
|
1284
|
+
inputPath = resolve6(inputArg);
|
|
1285
|
+
if (!existsSync3(inputPath)) {
|
|
1286
|
+
console.error(error(`File not found: ${inputArg}`));
|
|
1287
|
+
process.exit(1);
|
|
1288
|
+
}
|
|
1289
|
+
} else {
|
|
1290
|
+
inputPath = resolve6(options.inputDir);
|
|
1291
|
+
if (!existsSync3(inputPath)) {
|
|
1292
|
+
console.error(error(`Input directory not found: ${options.inputDir}`));
|
|
1293
|
+
process.exit(1);
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
const outputPath = resolve6(options.output);
|
|
1297
|
+
const startTime = performance.now();
|
|
1298
|
+
const spinner = createSpinner(
|
|
1299
|
+
options.dryRun ? "Analyzing Federal Register documents (dry run)" : "Converting Federal Register documents"
|
|
1300
|
+
);
|
|
1301
|
+
try {
|
|
1302
|
+
const result = await convertFrDocuments({
|
|
1303
|
+
input: inputPath,
|
|
1304
|
+
output: outputPath,
|
|
1305
|
+
linkStyle: options.linkStyle,
|
|
1306
|
+
dryRun: options.dryRun,
|
|
1307
|
+
from: options.from,
|
|
1308
|
+
to: options.to,
|
|
1309
|
+
types
|
|
1310
|
+
});
|
|
1311
|
+
const elapsed = performance.now() - startTime;
|
|
1312
|
+
if (options.dryRun) {
|
|
1313
|
+
spinner.succeed(
|
|
1314
|
+
`Dry run: ${formatNumber(result.documentsConverted)} documents would be converted`
|
|
1315
|
+
);
|
|
1316
|
+
} else {
|
|
1317
|
+
spinner.succeed(
|
|
1318
|
+
`Converted ${formatNumber(result.documentsConverted)} Federal Register documents`
|
|
1319
|
+
);
|
|
1320
|
+
}
|
|
1321
|
+
console.log();
|
|
1322
|
+
const rows = [
|
|
1323
|
+
["Documents", formatNumber(result.documentsConverted)]
|
|
1324
|
+
];
|
|
1325
|
+
if (!options.dryRun) {
|
|
1326
|
+
rows.push(["Est. tokens", formatNumber(result.totalTokenEstimate)]);
|
|
1327
|
+
}
|
|
1328
|
+
rows.push(["Duration", formatDuration(elapsed)]);
|
|
1329
|
+
if (!options.dryRun) {
|
|
1330
|
+
rows.push(["Output", relative6(process.cwd(), outputPath) + "/fr/"]);
|
|
1331
|
+
}
|
|
1332
|
+
const footer = options.dryRun ? void 0 : `Converted ${formatNumber(result.documentsConverted)} documents in ${formatDuration(elapsed)}`;
|
|
1333
|
+
console.log(summaryBlock({ title: "Conversion Complete", rows, footer }));
|
|
1334
|
+
if (options.verbose && !options.dryRun) {
|
|
1335
|
+
console.log();
|
|
1336
|
+
for (const file of result.files.slice(0, 20)) {
|
|
1337
|
+
console.log(` ${relative6(process.cwd(), file)}`);
|
|
1338
|
+
}
|
|
1339
|
+
if (result.files.length > 20) {
|
|
1340
|
+
console.log(` ... and ${result.files.length - 20} more`);
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
} catch (err) {
|
|
1344
|
+
spinner.fail("Conversion failed");
|
|
1345
|
+
console.error(error(err instanceof Error ? err.message : String(err)));
|
|
1346
|
+
process.exit(1);
|
|
1347
|
+
}
|
|
1348
|
+
});
|
|
1349
|
+
|
|
1077
1350
|
// src/index.ts
|
|
1078
1351
|
var require2 = createRequire(import.meta.url);
|
|
1079
1352
|
var pkg = require2("../package.json");
|
|
1080
|
-
var program = new
|
|
1353
|
+
var program = new Command8();
|
|
1081
1354
|
program.name("lexbuild").description("Convert U.S. legal XML to structured Markdown for AI/RAG ingestion").version(pkg.version).addHelpText(
|
|
1082
1355
|
"after",
|
|
1083
1356
|
`
|
|
@@ -1091,6 +1364,10 @@ Quick start (eCFR):
|
|
|
1091
1364
|
$ lexbuild convert-ecfr --all Convert all downloaded eCFR titles
|
|
1092
1365
|
$ lexbuild convert-ecfr --titles 17 Convert eCFR Title 17 only
|
|
1093
1366
|
|
|
1367
|
+
Quick start (Federal Register):
|
|
1368
|
+
$ lexbuild download-fr --recent 30 Download last 30 days of FR documents
|
|
1369
|
+
$ lexbuild convert-fr --all Convert all downloaded FR documents
|
|
1370
|
+
|
|
1094
1371
|
Documentation: https://github.com/chris-c-thomas/LexBuild`
|
|
1095
1372
|
);
|
|
1096
1373
|
program.addCommand(downloadUscCommand);
|
|
@@ -1098,20 +1375,24 @@ program.addCommand(convertUscCommand);
|
|
|
1098
1375
|
program.addCommand(listReleasePointsCommand);
|
|
1099
1376
|
program.addCommand(downloadEcfrCommand);
|
|
1100
1377
|
program.addCommand(convertEcfrCommand);
|
|
1378
|
+
program.addCommand(downloadFrCommand);
|
|
1379
|
+
program.addCommand(convertFrCommand);
|
|
1101
1380
|
program.addCommand(
|
|
1102
|
-
new
|
|
1381
|
+
new Command8("download").description("(use download-usc or download-ecfr)").allowUnknownOption().helpOption(false).action(() => {
|
|
1103
1382
|
console.error(error("Please specify a source:\n"));
|
|
1104
1383
|
console.error(" lexbuild download-usc Download U.S. Code XML from OLRC");
|
|
1105
1384
|
console.error(" lexbuild download-ecfr Download eCFR XML from govinfo");
|
|
1385
|
+
console.error(" lexbuild download-fr Download Federal Register XML from federalregister.gov");
|
|
1106
1386
|
console.error("");
|
|
1107
1387
|
process.exit(1);
|
|
1108
1388
|
})
|
|
1109
1389
|
);
|
|
1110
1390
|
program.addCommand(
|
|
1111
|
-
new
|
|
1391
|
+
new Command8("convert").description("(use convert-usc or convert-ecfr)").allowUnknownOption().helpOption(false).action(() => {
|
|
1112
1392
|
console.error(error("Please specify a source:\n"));
|
|
1113
1393
|
console.error(" lexbuild convert-usc Convert U.S. Code XML to Markdown");
|
|
1114
1394
|
console.error(" lexbuild convert-ecfr Convert eCFR XML to Markdown");
|
|
1395
|
+
console.error(" lexbuild convert-fr Convert Federal Register XML to Markdown");
|
|
1115
1396
|
console.error("");
|
|
1116
1397
|
process.exit(1);
|
|
1117
1398
|
})
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/commands/convert-usc.ts","../src/ui.ts","../src/parse-titles.ts","../src/commands/download-usc.ts","../src/commands/list-release-points.ts","../src/commands/convert-ecfr.ts","../src/commands/download-ecfr.ts"],"sourcesContent":["/** lexbuild CLI — Convert U.S. legal XML to structured Markdown */\n\nimport { createRequire } from \"node:module\";\nimport { Command } from \"commander\";\nimport { convertUscCommand } from \"./commands/convert-usc.js\";\nimport { downloadUscCommand } from \"./commands/download-usc.js\";\nimport { listReleasePointsCommand } from \"./commands/list-release-points.js\";\nimport { convertEcfrCommand } from \"./commands/convert-ecfr.js\";\nimport { downloadEcfrCommand } from \"./commands/download-ecfr.js\";\nimport { error } from \"./ui.js\";\n\nconst require = createRequire(import.meta.url);\nconst pkg = require(\"../package.json\") as { version: string };\n\nconst program = new Command();\n\nprogram\n .name(\"lexbuild\")\n .description(\"Convert U.S. legal XML to structured Markdown for AI/RAG ingestion\")\n .version(pkg.version)\n .addHelpText(\n \"after\",\n `\nQuick start (U.S. Code):\n $ lexbuild download-usc --all Download all 54 USC titles from OLRC\n $ lexbuild convert-usc --all Convert all downloaded USC titles\n $ lexbuild convert-usc --titles 1 Convert USC Title 1 only\n\nQuick start (eCFR):\n $ lexbuild download-ecfr --all Download all 50 eCFR titles from govinfo\n $ lexbuild convert-ecfr --all Convert all downloaded eCFR titles\n $ lexbuild convert-ecfr --titles 17 Convert eCFR Title 17 only\n\nDocumentation: https://github.com/chris-c-thomas/LexBuild`,\n );\n\n// Source-specific commands\nprogram.addCommand(downloadUscCommand);\nprogram.addCommand(convertUscCommand);\nprogram.addCommand(listReleasePointsCommand);\nprogram.addCommand(downloadEcfrCommand);\nprogram.addCommand(convertEcfrCommand);\n\n// Bare \"download\" and \"convert\" stubs — guide users to source-specific commands\nprogram.addCommand(\n new Command(\"download\")\n .description(\"(use download-usc or download-ecfr)\")\n .allowUnknownOption()\n .helpOption(false)\n .action(() => {\n console.error(error(\"Please specify a source:\\n\"));\n console.error(\" lexbuild download-usc Download U.S. Code XML from OLRC\");\n console.error(\" lexbuild download-ecfr Download eCFR XML from govinfo\");\n console.error(\"\");\n process.exit(1);\n }),\n);\n\nprogram.addCommand(\n new Command(\"convert\")\n .description(\"(use convert-usc or convert-ecfr)\")\n .allowUnknownOption()\n .helpOption(false)\n .action(() => {\n console.error(error(\"Please specify a source:\\n\"));\n console.error(\" lexbuild convert-usc Convert U.S. Code XML to Markdown\");\n console.error(\" lexbuild convert-ecfr Convert eCFR XML to Markdown\");\n console.error(\"\");\n process.exit(1);\n }),\n);\n\nprogram.parse();\n","/**\n * `lexbuild convert-usc` command — converts USC XML files to Markdown.\n */\n\nimport chalk from \"chalk\";\nimport { Command, Option } from \"commander\";\nimport { existsSync, readdirSync } from \"node:fs\";\nimport { basename, dirname, join, relative, resolve } from \"node:path\";\nimport { convertTitle } from \"@lexbuild/usc\";\nimport {\n createSpinner,\n summaryBlock,\n dataTable,\n formatDuration,\n formatBytes,\n formatNumber,\n success,\n error,\n} from \"../ui.js\";\nimport { parseTitles } from \"../parse-titles.js\";\n\n/** Parsed options from the convert command */\ninterface ConvertCommandOptions {\n output: string;\n titles?: string | undefined;\n all: boolean;\n inputDir: string;\n granularity: \"section\" | \"chapter\" | \"title\";\n linkStyle: \"relative\" | \"canonical\" | \"plaintext\";\n includeSourceCredits: boolean;\n includeNotes: boolean;\n includeEditorialNotes: boolean;\n includeStatutoryNotes: boolean;\n includeAmendments: boolean;\n dryRun: boolean;\n verbose: boolean;\n}\n\n/** Build the shared convert options from CLI flags. */\nfunction buildConvertOptions(\n inputPath: string,\n outputPath: string,\n options: ConvertCommandOptions,\n) {\n const hasSelectiveFlags =\n options.includeEditorialNotes || options.includeStatutoryNotes || options.includeAmendments;\n const includeNotes = hasSelectiveFlags ? false : options.includeNotes;\n\n return {\n input: inputPath,\n output: outputPath,\n granularity: options.granularity,\n linkStyle: options.linkStyle,\n includeSourceCredits: options.includeSourceCredits,\n includeNotes,\n includeEditorialNotes: options.includeEditorialNotes,\n includeStatutoryNotes: options.includeStatutoryNotes,\n includeAmendments: options.includeAmendments,\n dryRun: options.dryRun,\n };\n}\n\n/** Resolve the XML file path for a given title number. */\nfunction titleXmlPath(inputDir: string, titleNum: number): string {\n const padded = String(titleNum).padStart(2, \"0\");\n return join(inputDir, `usc${padded}.xml`);\n}\n\n/** Try to resolve a USC XML path, falling back to zero-padded filename. */\nexport function resolveUscXmlPath(inputPath: string): string | undefined {\n if (existsSync(inputPath)) return inputPath;\n\n // Check if filename matches usc{N}.xml pattern and try zero-padded\n const dir = dirname(inputPath);\n const base = basename(inputPath);\n const match = /^usc(\\d+)\\.xml$/.exec(base);\n if (match?.[1]) {\n const padded = match[1].padStart(2, \"0\");\n const paddedPath = join(dir, `usc${padded}.xml`);\n if (existsSync(paddedPath)) return paddedPath;\n }\n\n return undefined;\n}\n\n/** Regex matching USC XML filenames like usc01.xml, usc54.xml */\nconst USC_XML_RE = /^usc(\\d{2})\\.xml$/;\n\n/**\n * Scan a directory for USC XML files and return their title numbers, sorted.\n */\nexport function discoverTitles(inputDir: string): number[] {\n if (!existsSync(inputDir)) return [];\n\n return readdirSync(inputDir)\n .map((name) => USC_XML_RE.exec(name))\n .filter((m): m is RegExpExecArray => m !== null)\n .map((m) => parseInt(m[1] ?? \"0\", 10))\n .sort((a, b) => a - b);\n}\n\n/** Result from runConversion including elapsed time. */\ninterface ConversionRun {\n result: Awaited<ReturnType<typeof convertTitle>>;\n elapsed: number;\n}\n\n/** Run a conversion without printing output. Returns the result and elapsed time. */\nasync function runConversion(\n inputPath: string,\n outputPath: string,\n options: ConvertCommandOptions,\n): Promise<ConversionRun> {\n const startTime = performance.now();\n const result = await convertTitle(buildConvertOptions(inputPath, outputPath, options));\n const elapsed = performance.now() - startTime;\n return { result, elapsed };\n}\n\n/** Convert a single XML file and print its detailed summary. */\nasync function convertSingleFile(\n inputPath: string,\n outputPath: string,\n options: ConvertCommandOptions,\n spinnerLabel: string,\n) {\n const spinner = createSpinner(spinnerLabel);\n spinner.start();\n\n try {\n const { result, elapsed } = await runConversion(inputPath, outputPath, options);\n\n spinner.stop();\n\n const rows: Array<[string, string]> = [];\n if (options.granularity === \"section\") {\n rows.push([\"Sections\", formatNumber(result.sectionsWritten)]);\n rows.push([\"Chapters\", formatNumber(result.chapterCount)]);\n } else if (options.granularity === \"chapter\") {\n rows.push([\"Chapters\", formatNumber(result.chapterCount)]);\n }\n rows.push([\"Est. Tokens\", formatNumber(result.totalTokenEstimate)]);\n\n if (!result.dryRun) {\n rows.push([\"Files Written\", formatNumber(result.files.length)]);\n }\n\n rows.push(\n [\"Peak Memory\", formatBytes(result.peakMemoryBytes)],\n [\"Duration\", formatDuration(elapsed)],\n );\n\n const titleLabel = result.dryRun\n ? `lexbuild — Title ${result.titleNumber}: ${result.titleName} [dry-run]`\n : `lexbuild — Title ${result.titleNumber}: ${result.titleName}`;\n\n const outputRelative = relative(process.cwd(), outputPath) || outputPath;\n\n const output = summaryBlock({\n title: titleLabel,\n rows: [...rows, [\"Output\", outputRelative]],\n footer: result.dryRun ? success(\"Dry run complete\") : success(\"Conversion complete\"),\n });\n process.stdout.write(output);\n\n if (options.verbose && !result.dryRun && result.files.length > 0) {\n console.log(\" Files written:\");\n for (const file of result.files) {\n console.log(` ${relative(process.cwd(), file) || file}`);\n }\n console.log(\"\");\n }\n\n return result;\n } catch (err) {\n spinner.fail(err instanceof Error ? err.message : String(err));\n process.exit(1);\n }\n}\n\nexport const convertUscCommand = new Command(\"convert-usc\")\n .description(\"Convert U.S. Code XML file(s) to Markdown\")\n .argument(\"[input]\", \"Path to a USC XML file\")\n .option(\"-o, --output <dir>\", \"Output directory\", \"./output\")\n .option(\"--titles <spec>\", \"Title(s) to convert: 1, 1-5, or 1-5,8,11\")\n .option(\"--all\", \"Convert all downloaded titles found in --input-dir\", false)\n .option(\"-i, --input-dir <dir>\", \"Directory containing USC XML files\", \"./downloads/usc/xml\")\n .addOption(\n new Option(\"-g, --granularity <level>\", \"Output granularity: section, chapter, or title\")\n .choices([\"section\", \"chapter\", \"title\"])\n .default(\"section\"),\n )\n .addOption(\n new Option(\"--link-style <style>\", \"Link style: relative, canonical, or plaintext\")\n .choices([\"relative\", \"canonical\", \"plaintext\"])\n .default(\"plaintext\"),\n )\n .option(\"--include-source-credits\", \"Include source credit annotations\", true)\n .option(\"--no-include-source-credits\", \"Exclude source credit annotations\")\n .option(\"--include-notes\", \"Include all notes (default)\", true)\n .option(\"--no-include-notes\", \"Exclude all notes\")\n .option(\"--include-editorial-notes\", \"Include editorial notes only\", false)\n .option(\"--include-statutory-notes\", \"Include statutory notes only\", false)\n .option(\"--include-amendments\", \"Include amendment history notes only\", false)\n .option(\"--dry-run\", \"Parse and report structure without writing files\", false)\n .option(\"-v, --verbose\", \"Enable verbose logging\", false)\n .addHelpText(\n \"after\",\n `\nInput modes (use exactly one):\n <input> Convert a single XML file\n --titles Convert specific titles by number\n --all Convert all titles in --input-dir\n\nGranularity:\n section One .md file per section (default)\n chapter One .md file per chapter, sections inlined\n title One .md file per title, entire hierarchy inlined\n\nExamples:\n $ lexbuild convert-usc --titles 1 Convert Title 1\n $ lexbuild convert-usc --titles 1-5,8,11 Convert a mix of titles\n $ lexbuild convert-usc --all -g chapter All titles, chapter-level\n $ lexbuild convert-usc --titles 26 -g title Title 26 as a single file\n $ lexbuild convert-usc --all --dry-run Preview stats only\n $ lexbuild convert-usc ./downloads/usc/xml/usc01.xml -o ./out`,\n )\n .action(async (input: string | undefined, options: ConvertCommandOptions) => {\n // Validate: must specify exactly one of <input>, --titles, or --all\n const modeCount = [input, options.titles, options.all].filter(Boolean).length;\n if (modeCount === 0) {\n console.error(\n error(\"Specify an input file, --titles <spec>, or --all (e.g. --titles 1-5,8,11)\"),\n );\n process.exit(1);\n }\n if (modeCount > 1) {\n console.error(error(\"Cannot combine <input>, --titles, and --all — use only one\"));\n process.exit(1);\n }\n\n const outputPath = resolve(options.output);\n const dryRunLabel = options.dryRun ? \" [dry-run]\" : \"\";\n\n // Single-file mode\n if (input) {\n const rawPath = resolve(input);\n const inputPath = resolveUscXmlPath(rawPath);\n if (!inputPath) {\n console.error(error(`Input file not found: ${rawPath}`));\n process.exit(1);\n }\n await convertSingleFile(inputPath, outputPath, options, `Converting${dryRunLabel}...`);\n return;\n }\n\n // Multi-title mode\n let titles: number[];\n if (options.all) {\n const inputDir = resolve(options.inputDir);\n titles = discoverTitles(inputDir);\n if (titles.length === 0) {\n console.error(error(`No USC XML files found in ${inputDir}`));\n process.exit(1);\n }\n } else {\n const titlesSpec = options.titles as string;\n try {\n titles = parseTitles(titlesSpec);\n } catch (err) {\n console.error(error(err instanceof Error ? err.message : String(err)));\n process.exit(1);\n }\n }\n\n const inputDir = resolve(options.inputDir);\n const totalTitles = titles.length;\n const results: ConversionRun[] = [];\n\n const spinner = createSpinner(`Converting${dryRunLabel}...`);\n spinner.start();\n\n for (const [i, titleNum] of titles.entries()) {\n const xmlPath = titleXmlPath(inputDir, titleNum);\n\n if (!existsSync(xmlPath)) {\n spinner.stop();\n console.error(error(`XML file not found: ${xmlPath}`));\n process.exit(1);\n }\n\n spinner.text = `Converting Title ${titleNum}${dryRunLabel} (${i + 1}/${totalTitles})...`;\n\n try {\n const run = await runConversion(xmlPath, outputPath, options);\n results.push(run);\n } catch (err) {\n spinner.fail(err instanceof Error ? err.message : String(err));\n process.exit(1);\n }\n }\n\n spinner.stop();\n\n // Summary header\n const outputRelative = relative(process.cwd(), outputPath) || outputPath;\n const headerTitle = options.dryRun\n ? \"lexbuild — Conversion Summary [dry-run]\"\n : \"lexbuild — Conversion Summary\";\n const header = summaryBlock({\n title: headerTitle,\n rows: [[\"Directory\", outputRelative]],\n });\n process.stdout.write(header);\n\n // Build data table rows — adapt columns to granularity\n const granularity = options.granularity;\n let totalSections = 0;\n let totalChapters = 0;\n let totalTokens = 0;\n let totalElapsed = 0;\n\n const tableRows = results.map(({ result, elapsed }) => {\n totalSections += result.sectionsWritten;\n totalChapters += result.chapterCount;\n totalTokens += result.totalTokenEstimate;\n totalElapsed += elapsed;\n\n if (granularity === \"title\") {\n return [\n result.titleNumber,\n result.titleName,\n formatNumber(result.totalTokenEstimate),\n formatDuration(elapsed),\n ];\n } else if (granularity === \"chapter\") {\n return [\n result.titleNumber,\n result.titleName,\n formatNumber(result.chapterCount),\n formatNumber(result.totalTokenEstimate),\n formatDuration(elapsed),\n ];\n } else {\n return [\n result.titleNumber,\n result.titleName,\n formatNumber(result.chapterCount),\n formatNumber(result.sectionsWritten),\n formatNumber(result.totalTokenEstimate),\n formatDuration(elapsed),\n ];\n }\n });\n\n // Totals row\n if (granularity === \"title\") {\n tableRows.push([\n chalk.bold(\"Total\"),\n \"\",\n chalk.bold(formatNumber(totalTokens)),\n chalk.bold(formatDuration(totalElapsed)),\n ]);\n } else if (granularity === \"chapter\") {\n tableRows.push([\n chalk.bold(\"Total\"),\n \"\",\n chalk.bold(formatNumber(totalChapters)),\n chalk.bold(formatNumber(totalTokens)),\n chalk.bold(formatDuration(totalElapsed)),\n ]);\n } else {\n tableRows.push([\n chalk.bold(\"Total\"),\n \"\",\n chalk.bold(formatNumber(totalChapters)),\n chalk.bold(formatNumber(totalSections)),\n chalk.bold(formatNumber(totalTokens)),\n chalk.bold(formatDuration(totalElapsed)),\n ]);\n }\n\n // Table headers and footer — adapt to granularity\n const tableHeaders =\n granularity === \"title\"\n ? [\"Title\", \"Name\", \"Tokens\", \"Duration\"]\n : granularity === \"chapter\"\n ? [\"Title\", \"Name\", \"Chapters\", \"Tokens\", \"Duration\"]\n : [\"Title\", \"Name\", \"Chapters\", \"Sections\", \"Tokens\", \"Duration\"];\n\n console.log(dataTable(tableHeaders, tableRows));\n\n // Footer — show the primary unit that was converted\n let countLabel: string;\n if (granularity === \"title\") {\n const titleWord = totalTitles === 1 ? \"title\" : \"titles\";\n countLabel = `${formatNumber(totalTitles)} ${titleWord}`;\n } else if (granularity === \"chapter\") {\n const chapterWord = totalChapters === 1 ? \"chapter\" : \"chapters\";\n countLabel = `${formatNumber(totalChapters)} ${chapterWord}`;\n } else {\n const sectionWord = totalSections === 1 ? \"section\" : \"sections\";\n countLabel = `${formatNumber(totalSections)} ${sectionWord}`;\n }\n console.log(`\\n ${success(`Converted ${countLabel} in ${formatDuration(totalElapsed)}`)}`);\n console.log(\"\");\n });\n","/**\n * Shared terminal UI utilities — spinners, tables, and formatting helpers.\n */\n\nimport chalk from \"chalk\";\nimport ora from \"ora\";\nimport type { Ora } from \"ora\";\nimport Table from \"cli-table3\";\n\n/** Create an ora spinner with consistent styling. */\nexport function createSpinner(text: string): Ora {\n return ora({ text, spinner: \"dots\" });\n}\n\n/** Format milliseconds as human-readable duration (e.g. \"1.5s\" or \"1m 23s\"). */\nexport function formatDuration(ms: number): string {\n const secs = ms / 1000;\n if (secs < 60) {\n return `${secs.toFixed(secs < 10 ? 2 : 1)}s`;\n }\n const mins = Math.floor(secs / 60);\n const remainSecs = Math.round(secs % 60);\n return `${mins}m ${remainSecs}s`;\n}\n\n/** Format bytes as human-readable size (e.g. \"11.0 MB\"). */\nexport function formatBytes(bytes: number): string {\n if (bytes < 1024) return `${bytes} B`;\n const kb = bytes / 1024;\n if (kb < 1024) return `${kb.toFixed(1)} KB`;\n const mb = kb / 1024;\n if (mb < 1024) return `${mb.toFixed(1)} MB`;\n const gb = mb / 1024;\n return `${gb.toFixed(2)} GB`;\n}\n\n/** Format a number with locale-aware separators (e.g. 1,234,567). */\nexport function formatNumber(n: number): string {\n return n.toLocaleString();\n}\n\n/** Regex matching ANSI escape sequences (SGR codes). */\n// eslint-disable-next-line no-control-regex\nconst ANSI_RE = /\\x1B\\[[0-9;]*m/g;\n\n/** Strip ANSI escape codes and return visual string length. */\nfunction visualLength(s: string): number {\n return s.replace(ANSI_RE, \"\").length;\n}\n\n/**\n * Compute column widths that fill the terminal.\n * Expands `flexCol` to absorb remaining space.\n */\nfunction fillWidths(columns: string[][], colCount: number, flexCol: number): number[] | undefined {\n const termWidth = process.stdout.columns || 80;\n // Compute natural width per column (max visual length across all rows)\n const natural = Array.from<number>({ length: colCount }).fill(0);\n for (const row of columns) {\n for (let i = 0; i < colCount; i++) {\n natural[i] = Math.max(natural[i] ?? 0, visualLength(row[i] ?? \"\"));\n }\n }\n // Overhead: 2 chars left pad + 2 chars per column separator (between cols)\n const overhead = 2 + 2 * (colCount - 1);\n const naturalTotal = overhead + natural.reduce((a, b) => a + b, 0);\n if (naturalTotal >= termWidth) return undefined; // already fills or exceeds\n const extra = termWidth - naturalTotal;\n const widths = [...natural];\n widths[flexCol] = (widths[flexCol] ?? 0) + extra;\n return widths;\n}\n\n/**\n * Shared cli-table3 border characters.\n *\n * Uses 2-char left indent (\" \"), 2-char column gap (\" \"), no right border.\n * The \"mid\" intersection chars (\"──\") must match the 2-char width of \"middle\"\n * so horizontal rules span the full table width.\n */\nconst TABLE_CHARS = {\n top: \"─\",\n \"top-mid\": \"──\",\n \"top-left\": \" \",\n \"top-right\": \"\",\n bottom: \"─\",\n \"bottom-mid\": \"──\",\n \"bottom-left\": \" \",\n \"bottom-right\": \"\",\n left: \" \",\n \"left-mid\": \" \",\n right: \"\",\n \"right-mid\": \"\",\n mid: \"─\",\n \"mid-mid\": \"──\",\n middle: \" \",\n} as const;\n\n/** Shared cli-table3 style. */\nconst TABLE_STYLE: {\n head: string[];\n border: string[];\n \"padding-left\": number;\n \"padding-right\": number;\n} = {\n head: [],\n border: [],\n \"padding-left\": 0,\n \"padding-right\": 0,\n};\n\n/** Render a styled heading line. */\nfunction heading(text: string): string {\n return chalk.bold(text);\n}\n\n/** Render a success message with green checkmark. */\nexport function success(text: string): string {\n return chalk.green(`✔ ${text}`);\n}\n\n/** Render an error message with red X. */\nexport function error(text: string): string {\n return chalk.red(`✘ ${text}`);\n}\n\n/** Options for a key-value summary block. */\ninterface SummaryBlockOptions {\n /** Title line displayed above the table */\n title: string;\n /** Key-value pairs to display */\n rows: Array<[label: string, value: string]>;\n /** Optional footer line displayed below the table */\n footer?: string | undefined;\n}\n\n/** Render a key-value summary block with horizontal rules. */\nexport function summaryBlock({ title, rows, footer }: SummaryBlockOptions): string {\n const allCells = rows.map(([l, v]) => [l, v]);\n const colWidths = fillWidths(allCells, 2, 1);\n\n const table = new Table({\n chars: TABLE_CHARS,\n style: TABLE_STYLE,\n ...(colWidths ? { colWidths } : {}),\n });\n\n for (const [label, value] of rows) {\n table.push([chalk.dim(label), value]);\n }\n\n const lines: string[] = [];\n lines.push(\"\");\n lines.push(` ${heading(title)}`);\n lines.push(table.toString());\n if (footer !== undefined) {\n lines.push(` ${footer}`);\n }\n lines.push(\"\");\n\n return lines.join(\"\\n\");\n}\n\n/** Render a multi-column data table. */\nexport function dataTable(head: string[], rows: string[][]): string {\n const table = new Table({\n head: head.map((h) => chalk.dim(h)),\n chars: TABLE_CHARS,\n style: TABLE_STYLE,\n });\n\n for (const row of rows) {\n table.push(row);\n }\n\n return table.toString();\n}\n","/**\n * Parses a title specification string into an array of title numbers.\n *\n * Supports single numbers, comma-separated lists, ranges, and mixed:\n * - `\"29\"` → `[29]`\n * - `\"1,3,8,11\"` → `[1, 3, 8, 11]`\n * - `\"1-5\"` → `[1, 2, 3, 4, 5]`\n * - `\"1-5,8,11\"` → `[1, 2, 3, 4, 5, 8, 11]`\n */\nexport function parseTitles(input: string, maxTitle = 54): number[] {\n const trimmed = input.trim();\n if (trimmed === \"\") {\n throw new Error(\"Title specification cannot be empty\");\n }\n\n const result = new Set<number>();\n const segments = trimmed.split(\",\");\n\n for (const segment of segments) {\n const part = segment.trim();\n if (part === \"\") {\n throw new Error(`Invalid title specification: \"${input}\" (empty segment)`);\n }\n\n if (part.includes(\"-\")) {\n const [startStr, endStr, ...rest] = part.split(\"-\");\n if (rest.length > 0 || !startStr || !endStr) {\n throw new Error(`Invalid range: \"${part}\" (expected format: start-end)`);\n }\n\n const start = parseIntStrict(startStr, input);\n const end = parseIntStrict(endStr, input);\n\n if (start > end) {\n throw new Error(`Invalid range: \"${part}\" (start ${start} must be ≤ end ${end})`);\n }\n\n validateTitleNumber(start, input, maxTitle);\n validateTitleNumber(end, input, maxTitle);\n\n for (let i = start; i <= end; i++) {\n result.add(i);\n }\n } else {\n const num = parseIntStrict(part, input);\n validateTitleNumber(num, input, maxTitle);\n result.add(num);\n }\n }\n\n return [...result].sort((a, b) => a - b);\n}\n\n/** Parse an integer strictly — no NaN, no floats. */\nfunction parseIntStrict(str: string, fullInput: string): number {\n const trimmed = str.trim();\n if (!/^\\d+$/.test(trimmed)) {\n throw new Error(`Invalid number \"${trimmed}\" in title specification: \"${fullInput}\"`);\n }\n return parseInt(trimmed, 10);\n}\n\n/** Validate that a title number is in the valid range. */\nfunction validateTitleNumber(num: number, fullInput: string, max = 54): void {\n if (num < 1 || num > max) {\n throw new Error(`Title number ${num} out of range (must be 1-${max}) in: \"${fullInput}\"`);\n }\n}\n","/**\n * `lexbuild download-usc` command — downloads USC XML from OLRC.\n *\n * Auto-detects the latest OLRC release point unless overridden with --release-point.\n */\n\nimport { Command } from \"commander\";\nimport { relative, resolve } from \"node:path\";\nimport { downloadTitles, detectLatestReleasePoint, FALLBACK_RELEASE_POINT } from \"@lexbuild/usc\";\nimport {\n createSpinner,\n summaryBlock,\n dataTable,\n formatDuration,\n formatBytes,\n success,\n error,\n} from \"../ui.js\";\nimport { parseTitles } from \"../parse-titles.js\";\n\n/** Parsed options from the download command */\ninterface DownloadCommandOptions {\n output: string;\n titles?: string | undefined;\n all: boolean;\n releasePoint?: string | undefined;\n}\n\nexport const downloadUscCommand = new Command(\"download-usc\")\n .description(\"Download U.S. Code XML from OLRC\")\n .option(\"-o, --output <dir>\", \"Download directory\", \"./downloads/usc/xml\")\n .option(\"--titles <spec>\", \"Title(s) to download: 1, 1-5, or 1-5,8,11\")\n .option(\"--all\", \"Download all 54 titles (single bulk zip)\", false)\n .option(\"--release-point <id>\", \"OLRC release point (auto-detected if omitted)\")\n .addHelpText(\n \"after\",\n `\nExamples:\n $ lexbuild download-usc --all Download all 54 titles (latest release)\n $ lexbuild download-usc --titles 1 Download Title 1 only\n $ lexbuild download-usc --titles 1-5,8,11 Download specific titles\n $ lexbuild download-usc --all -o ./my-xml Custom output directory\n $ lexbuild download-usc --all --release-point 119-73not60 Pin a specific release\n\nThe latest release point is auto-detected from the OLRC download page.\nSource: https://uscode.house.gov/download/download.shtml`,\n )\n .action(async (options: DownloadCommandOptions) => {\n // Validate: must specify --titles or --all\n if (!options.titles && !options.all) {\n console.error(error(\"Specify --titles <spec> or --all (e.g. --titles 1-5,8,11)\"));\n process.exit(1);\n }\n\n // Parse title numbers\n let titles: number[] | undefined;\n if (options.titles) {\n try {\n titles = parseTitles(options.titles);\n } catch (err) {\n console.error(error(err instanceof Error ? err.message : String(err)));\n process.exit(1);\n }\n }\n\n const outputDir = resolve(options.output);\n const titleCount = titles ? titles.length : 54;\n\n // Resolve release point: use explicit flag, auto-detect, or fall back\n let releasePoint = options.releasePoint;\n if (!releasePoint) {\n const detectSpinner = createSpinner(\"Detecting latest OLRC release point...\");\n detectSpinner.start();\n const detected = await detectLatestReleasePoint();\n if (detected) {\n releasePoint = detected.releasePoint;\n detectSpinner.succeed(`Release point: ${detected.releasePoint}`);\n } else {\n releasePoint = FALLBACK_RELEASE_POINT;\n detectSpinner.warn(`Could not detect release point, using fallback: ${releasePoint}`);\n }\n }\n\n const label =\n titleCount === 1 ? `Downloading Title ${titles?.[0]}` : `Downloading ${titleCount} USC titles`;\n\n const spinner = createSpinner(`${label}...`);\n spinner.start();\n\n const startTime = performance.now();\n\n try {\n const result = await downloadTitles({\n outputDir,\n titles,\n releasePoint,\n onProgress: ({ current, total, titleNumber, phase }) => {\n if (phase === \"extracting\") {\n spinner.text = `Extracting USC titles (${current}/${total}) — Title ${titleNumber}...`;\n } else if (total === 1) {\n spinner.text = `Downloading USC Title ${titleNumber}...`;\n } else if (current === 0) {\n spinner.text = \"Downloading USC bulk archive...\";\n } else {\n spinner.text = `Downloading USC titles (${current}/${total}) — Title ${titleNumber}...`;\n }\n },\n });\n\n const elapsed = performance.now() - startTime;\n\n spinner.stop();\n\n // Build file table rows\n const fileRows = result.files.map((file) => [\n String(file.titleNumber),\n formatBytes(file.size),\n relative(outputDir, file.filePath) || file.filePath,\n ]);\n\n const totalBytes = result.files.reduce((sum, f) => sum + f.size, 0);\n\n // Summary header — show the actual release point used (may be auto-detected)\n const rpLabel = options.releasePoint\n ? result.releasePoint\n : `${result.releasePoint} (auto-detected)`;\n\n const output = summaryBlock({\n title: \"lexbuild — Download Summary\",\n rows: [\n [\"Release Point\", rpLabel],\n [\"Directory\", relative(process.cwd(), outputDir) || outputDir],\n ],\n });\n process.stdout.write(output);\n\n // File table\n if (fileRows.length > 0) {\n console.log(dataTable([\"Title\", \"Size\", \"File\"], fileRows));\n }\n\n // Errors\n if (result.errors.length > 0) {\n console.log(\"\");\n for (const err of result.errors) {\n console.log(` ${error(`Title ${err.titleNumber}: ${err.message}`)}`);\n }\n }\n\n // Footer\n const titleWord = result.files.length === 1 ? \"title\" : \"titles\";\n const summary = `Downloaded ${result.files.length} ${titleWord} (${formatBytes(totalBytes)}) in ${formatDuration(elapsed)}`;\n const failSuffix = result.errors.length > 0 ? ` (${result.errors.length} failed)` : \"\";\n console.log(` ${success(summary + failSuffix)}`);\n console.log(\"\");\n } catch (err) {\n spinner.fail(err instanceof Error ? err.message : String(err));\n process.exit(1);\n }\n });\n","/**\n * `lexbuild list-release-points` command — lists available OLRC release points.\n *\n * Fetches the current release point from the OLRC download page and the full\n * history from the prior release points page, then displays them in a table.\n */\n\nimport { Command } from \"commander\";\nimport {\n detectLatestReleasePoint,\n fetchReleasePointHistory,\n FALLBACK_RELEASE_POINT,\n} from \"@lexbuild/usc\";\nimport { createSpinner, summaryBlock, dataTable, error } from \"../ui.js\";\n\n/** Parsed options from the list-release-points command */\ninterface ListReleasePointsOptions {\n limit: string;\n}\n\nexport const listReleasePointsCommand = new Command(\"list-release-points\")\n .description(\"List available OLRC release points for the U.S. Code\")\n .option(\"-n, --limit <count>\", \"Maximum number of release points to show\", \"20\")\n .addHelpText(\n \"after\",\n `\nExamples:\n $ lexbuild list-release-points Show the 20 most recent release points\n $ lexbuild list-release-points -n 5 Show the 5 most recent\n $ lexbuild list-release-points -n 0 Show all available release points\n\nUse --release-point <id> with download-usc to pin a specific release.\nSource: https://uscode.house.gov/download/priorreleasepoints.htm`,\n )\n .action(async (options: ListReleasePointsOptions) => {\n const limit = parseInt(options.limit, 10);\n if (Number.isNaN(limit) || limit < 0) {\n console.error(error(\"--limit must be a non-negative integer\"));\n process.exit(1);\n }\n\n const spinner = createSpinner(\"Fetching release points from OLRC...\");\n spinner.start();\n\n // Fetch current and history in parallel\n const [current, history] = await Promise.all([\n detectLatestReleasePoint(),\n fetchReleasePointHistory(),\n ]);\n\n spinner.stop();\n\n // Current release point summary\n const currentRp = current?.releasePoint ?? FALLBACK_RELEASE_POINT;\n const currentDesc = current?.description ?? \"(detection failed — showing fallback)\";\n\n const output = summaryBlock({\n title: \"lexbuild — OLRC Release Points\",\n rows: [\n [\"Latest\", `${currentRp} ${currentDesc}`],\n [\"Prior releases\", `${history.length} available`],\n ],\n });\n process.stdout.write(output);\n\n if (history.length === 0) {\n console.log(\" No prior release points found.\\n\");\n return;\n }\n\n // Apply limit (0 = show all)\n const displayed = limit > 0 ? history.slice(0, limit) : history;\n\n // Build table rows: Release Point, Date, Affected Titles\n const rows = displayed.map((rp) => [\n rp.releasePoint,\n rp.date,\n rp.affectedTitles.length > 0 ? rp.affectedTitles.join(\", \") : \"—\",\n ]);\n\n console.log(dataTable([\"Release Point\", \"Date\", \"Affected Titles\"], rows));\n\n if (limit > 0 && history.length > limit) {\n console.log(` Showing ${limit} of ${history.length} — use -n 0 to show all.\\n`);\n }\n\n console.log(\" Use with: lexbuild download-usc --all --release-point <id>\\n\");\n });\n","/**\n * `lexbuild convert-ecfr` command — converts eCFR XML files to Markdown.\n */\n\nimport chalk from \"chalk\";\nimport { Command, Option } from \"commander\";\nimport { existsSync, readdirSync } from \"node:fs\";\nimport { join, relative, resolve } from \"node:path\";\nimport { convertEcfrTitle } from \"@lexbuild/ecfr\";\nimport type { EcfrConvertOptions, EcfrConvertResult } from \"@lexbuild/ecfr\";\nimport {\n createSpinner,\n summaryBlock,\n dataTable,\n formatDuration,\n formatBytes,\n formatNumber,\n success,\n error,\n} from \"../ui.js\";\nimport { parseTitles } from \"../parse-titles.js\";\n\n/** Parsed options from the convert-ecfr command */\ninterface ConvertEcfrCommandOptions {\n output: string;\n titles?: string | undefined;\n all: boolean;\n inputDir: string;\n granularity: \"section\" | \"part\" | \"chapter\" | \"title\";\n linkStyle: \"relative\" | \"canonical\" | \"plaintext\";\n includeSourceCredits: boolean;\n includeNotes: boolean;\n includeEditorialNotes: boolean;\n includeStatutoryNotes: boolean;\n includeAmendments: boolean;\n dryRun: boolean;\n verbose: boolean;\n}\n\n/** Build EcfrConvertOptions from CLI flags. */\nfunction buildConvertOptions(\n inputPath: string,\n outputPath: string,\n options: ConvertEcfrCommandOptions,\n): EcfrConvertOptions {\n const hasSelectiveFlags =\n options.includeEditorialNotes || options.includeStatutoryNotes || options.includeAmendments;\n const includeNotes = hasSelectiveFlags ? false : options.includeNotes;\n\n return {\n input: inputPath,\n output: outputPath,\n granularity: options.granularity,\n linkStyle: options.linkStyle,\n includeSourceCredits: options.includeSourceCredits,\n includeNotes,\n includeEditorialNotes: options.includeEditorialNotes,\n includeStatutoryNotes: options.includeStatutoryNotes,\n includeAmendments: options.includeAmendments,\n dryRun: options.dryRun,\n };\n}\n\n/** Regex matching eCFR XML filenames like ECFR-title1.xml, ECFR-title17.xml */\nconst ECFR_XML_RE = /^ECFR-title(\\d+)\\.xml$/;\n\n/** Resolve the XML file path for a given eCFR title number. */\nfunction titleXmlPath(inputDir: string, titleNum: number): string {\n return join(inputDir, `ECFR-title${titleNum}.xml`);\n}\n\n/** Scan a directory for eCFR XML files and return their title numbers, sorted. */\nfunction discoverEcfrTitles(inputDir: string): number[] {\n if (!existsSync(inputDir)) return [];\n\n return readdirSync(inputDir)\n .map((name) => ECFR_XML_RE.exec(name))\n .filter((m): m is RegExpExecArray => m !== null)\n .map((m) => parseInt(m[1] ?? \"0\", 10))\n .sort((a, b) => a - b);\n}\n\n/** Result from running a conversion including elapsed time. */\ninterface ConversionRun {\n result: EcfrConvertResult;\n elapsed: number;\n}\n\n/** Run a conversion without printing output. */\nasync function runConversion(\n inputPath: string,\n outputPath: string,\n options: ConvertEcfrCommandOptions,\n): Promise<ConversionRun> {\n const startTime = performance.now();\n const result = await convertEcfrTitle(buildConvertOptions(inputPath, outputPath, options));\n const elapsed = performance.now() - startTime;\n return { result, elapsed };\n}\n\n/** Convert a single file and print its detailed summary. */\nasync function convertSingleFile(\n inputPath: string,\n outputPath: string,\n options: ConvertEcfrCommandOptions,\n spinnerLabel: string,\n) {\n const spinner = createSpinner(spinnerLabel);\n spinner.start();\n\n try {\n const { result, elapsed } = await runConversion(inputPath, outputPath, options);\n spinner.stop();\n\n const rows: Array<[string, string]> = [];\n if (options.granularity === \"section\") {\n rows.push([\"Sections\", formatNumber(result.sectionsWritten)]);\n rows.push([\"Parts\", formatNumber(result.partCount)]);\n } else if (options.granularity === \"part\") {\n rows.push([\"Parts\", formatNumber(result.partCount)]);\n } else if (options.granularity === \"chapter\") {\n rows.push([\"Chapters\", formatNumber(result.sectionsWritten)]);\n }\n rows.push([\"Est. Tokens\", formatNumber(result.totalTokenEstimate)]);\n\n if (!result.dryRun) {\n rows.push([\"Files Written\", formatNumber(result.files.length)]);\n }\n\n rows.push(\n [\"Peak Memory\", formatBytes(result.peakMemoryBytes)],\n [\"Duration\", formatDuration(elapsed)],\n );\n\n const titleLabel = result.dryRun\n ? `lexbuild — eCFR Title ${result.titleNumber}: ${result.titleName} [dry-run]`\n : `lexbuild — eCFR Title ${result.titleNumber}: ${result.titleName}`;\n\n const outputRelative = relative(process.cwd(), outputPath) || outputPath;\n\n const output = summaryBlock({\n title: titleLabel,\n rows: [...rows, [\"Output\", outputRelative]],\n footer: result.dryRun ? success(\"Dry run complete\") : success(\"Conversion complete\"),\n });\n process.stdout.write(output);\n\n if (options.verbose && !result.dryRun && result.files.length > 0) {\n console.log(\" Files written:\");\n for (const file of result.files) {\n console.log(` ${relative(process.cwd(), file) || file}`);\n }\n console.log(\"\");\n }\n\n return result;\n } catch (err) {\n spinner.fail(err instanceof Error ? err.message : String(err));\n process.exit(1);\n }\n}\n\nexport const convertEcfrCommand = new Command(\"convert-ecfr\")\n .description(\"Convert eCFR XML file(s) to Markdown\")\n .argument(\"[input]\", \"Path to an eCFR XML file\")\n .option(\"-o, --output <dir>\", \"Output directory\", \"./output\")\n .option(\"--titles <spec>\", \"Title(s) to convert: 1, 1-5, or 1-5,17\")\n .option(\"--all\", \"Convert all downloaded eCFR titles found in --input-dir\", false)\n .option(\"-i, --input-dir <dir>\", \"Directory containing eCFR XML files\", \"./downloads/ecfr/xml\")\n .addOption(\n new Option(\"-g, --granularity <level>\", \"Output granularity: section, part, chapter, or title\")\n .choices([\"section\", \"part\", \"chapter\", \"title\"])\n .default(\"section\"),\n )\n .addOption(\n new Option(\"--link-style <style>\", \"Link style: relative, canonical, or plaintext\")\n .choices([\"relative\", \"canonical\", \"plaintext\"])\n .default(\"plaintext\"),\n )\n .option(\"--include-source-credits\", \"Include source credit annotations\", true)\n .option(\"--no-include-source-credits\", \"Exclude source credit annotations\")\n .option(\"--include-notes\", \"Include all notes (default)\", true)\n .option(\"--no-include-notes\", \"Exclude all notes\")\n .option(\"--include-editorial-notes\", \"Include editorial notes only\", false)\n .option(\"--include-statutory-notes\", \"Include statutory/regulatory notes only\", false)\n .option(\"--include-amendments\", \"Include amendment history notes only\", false)\n .option(\"--dry-run\", \"Parse and report structure without writing files\", false)\n .option(\"-v, --verbose\", \"Enable verbose logging\", false)\n .addHelpText(\n \"after\",\n `\nInput modes (use exactly one):\n <input> Convert a single eCFR XML file\n --titles Convert specific titles by number\n --all Convert all titles in --input-dir\n\nGranularity:\n section One .md file per section (default)\n part One .md file per part, sections inlined\n chapter One .md file per chapter, parts and sections inlined\n title One .md file per title, entire hierarchy inlined\n\nExamples:\n $ lexbuild convert-ecfr --titles 1 Convert eCFR Title 1\n $ lexbuild convert-ecfr --titles 1-5,17 Convert specific titles\n $ lexbuild convert-ecfr --all -g part All titles, part-level\n $ lexbuild convert-ecfr --all --dry-run Preview stats only\n $ lexbuild convert-ecfr ./downloads/ecfr/xml/ECFR-title1.xml -o ./out`,\n )\n .action(async (input: string | undefined, options: ConvertEcfrCommandOptions) => {\n const modeCount = [input, options.titles, options.all].filter(Boolean).length;\n if (modeCount === 0) {\n console.error(\n error(\"Specify an input file, --titles <spec>, or --all (e.g. --titles 1-5,17)\"),\n );\n process.exit(1);\n }\n if (modeCount > 1) {\n console.error(error(\"Cannot combine <input>, --titles, and --all — use only one\"));\n process.exit(1);\n }\n\n const outputPath = resolve(options.output);\n const dryRunLabel = options.dryRun ? \" [dry-run]\" : \"\";\n\n // Single-file mode\n if (input) {\n const inputPath = resolve(input);\n if (!existsSync(inputPath)) {\n console.error(error(`Input file not found: ${inputPath}`));\n process.exit(1);\n }\n await convertSingleFile(inputPath, outputPath, options, `Converting eCFR${dryRunLabel}...`);\n return;\n }\n\n // Multi-title mode\n let titles: number[];\n if (options.all) {\n const inputDir = resolve(options.inputDir);\n titles = discoverEcfrTitles(inputDir);\n if (titles.length === 0) {\n console.error(error(`No eCFR XML files found in ${inputDir}`));\n process.exit(1);\n }\n } else {\n const titlesSpec = options.titles as string;\n try {\n titles = parseTitles(titlesSpec, 50);\n } catch (err) {\n console.error(error(err instanceof Error ? err.message : String(err)));\n process.exit(1);\n }\n }\n\n const inputDir = resolve(options.inputDir);\n const totalTitles = titles.length;\n const results: ConversionRun[] = [];\n\n const spinner = createSpinner(`Converting eCFR${dryRunLabel}...`);\n spinner.start();\n\n for (const [i, titleNum] of titles.entries()) {\n const xmlPath = titleXmlPath(inputDir, titleNum);\n\n if (!existsSync(xmlPath)) {\n spinner.stop();\n console.error(error(`XML file not found: ${xmlPath}`));\n process.exit(1);\n }\n\n spinner.text = `Converting eCFR Title ${titleNum}${dryRunLabel} (${i + 1}/${totalTitles})...`;\n\n try {\n const run = await runConversion(xmlPath, outputPath, options);\n results.push(run);\n } catch (err) {\n spinner.fail(err instanceof Error ? err.message : String(err));\n process.exit(1);\n }\n }\n\n spinner.stop();\n\n const outputRelative = relative(process.cwd(), outputPath) || outputPath;\n const headerTitle = options.dryRun\n ? \"lexbuild — eCFR Conversion Summary [dry-run]\"\n : \"lexbuild — eCFR Conversion Summary\";\n const header = summaryBlock({\n title: headerTitle,\n rows: [[\"Directory\", outputRelative]],\n });\n process.stdout.write(header);\n\n const granularity = options.granularity;\n let totalSections = 0;\n let totalParts = 0;\n let totalTokens = 0;\n let totalElapsed = 0;\n\n const tableRows = results.map(({ result, elapsed }) => {\n totalSections += result.sectionsWritten;\n totalParts += result.partCount;\n totalTokens += result.totalTokenEstimate;\n totalElapsed += elapsed;\n\n if (granularity === \"title\") {\n return [\n result.titleNumber,\n result.titleName,\n formatNumber(result.totalTokenEstimate),\n formatDuration(elapsed),\n ];\n } else if (granularity === \"chapter\") {\n return [\n result.titleNumber,\n result.titleName,\n formatNumber(result.sectionsWritten),\n formatNumber(result.totalTokenEstimate),\n formatDuration(elapsed),\n ];\n } else if (granularity === \"part\") {\n return [\n result.titleNumber,\n result.titleName,\n formatNumber(result.partCount),\n formatNumber(result.totalTokenEstimate),\n formatDuration(elapsed),\n ];\n } else {\n return [\n result.titleNumber,\n result.titleName,\n formatNumber(result.partCount),\n formatNumber(result.sectionsWritten),\n formatNumber(result.totalTokenEstimate),\n formatDuration(elapsed),\n ];\n }\n });\n\n if (granularity === \"title\") {\n tableRows.push([\n chalk.bold(\"Total\"),\n \"\",\n chalk.bold(formatNumber(totalTokens)),\n chalk.bold(formatDuration(totalElapsed)),\n ]);\n } else if (granularity === \"chapter\") {\n tableRows.push([\n chalk.bold(\"Total\"),\n \"\",\n chalk.bold(formatNumber(totalSections)),\n chalk.bold(formatNumber(totalTokens)),\n chalk.bold(formatDuration(totalElapsed)),\n ]);\n } else if (granularity === \"part\") {\n tableRows.push([\n chalk.bold(\"Total\"),\n \"\",\n chalk.bold(formatNumber(totalParts)),\n chalk.bold(formatNumber(totalTokens)),\n chalk.bold(formatDuration(totalElapsed)),\n ]);\n } else {\n tableRows.push([\n chalk.bold(\"Total\"),\n \"\",\n chalk.bold(formatNumber(totalParts)),\n chalk.bold(formatNumber(totalSections)),\n chalk.bold(formatNumber(totalTokens)),\n chalk.bold(formatDuration(totalElapsed)),\n ]);\n }\n\n const tableHeaders =\n granularity === \"title\"\n ? [\"Title\", \"Name\", \"Tokens\", \"Duration\"]\n : granularity === \"chapter\"\n ? [\"Title\", \"Name\", \"Chapters\", \"Tokens\", \"Duration\"]\n : granularity === \"part\"\n ? [\"Title\", \"Name\", \"Parts\", \"Tokens\", \"Duration\"]\n : [\"Title\", \"Name\", \"Parts\", \"Sections\", \"Tokens\", \"Duration\"];\n\n console.log(dataTable(tableHeaders, tableRows));\n\n // Footer — show the primary unit that was converted\n let countLabel: string;\n if (granularity === \"title\") {\n const titleWord = totalTitles === 1 ? \"title\" : \"titles\";\n countLabel = `${formatNumber(totalTitles)} ${titleWord}`;\n } else if (granularity === \"chapter\") {\n const chapterWord = totalSections === 1 ? \"chapter\" : \"chapters\";\n countLabel = `${formatNumber(totalSections)} ${chapterWord}`;\n } else if (granularity === \"part\") {\n const partWord = totalParts === 1 ? \"part\" : \"parts\";\n countLabel = `${formatNumber(totalParts)} ${partWord}`;\n } else {\n const sectionWord = totalSections === 1 ? \"section\" : \"sections\";\n countLabel = `${formatNumber(totalSections)} ${sectionWord}`;\n }\n console.log(`\\n ${success(`Converted ${countLabel} in ${formatDuration(totalElapsed)}`)}`);\n console.log(\"\");\n });\n","/**\n * `lexbuild download-ecfr` command — downloads eCFR XML from govinfo or eCFR API.\n */\n\nimport { Command } from \"commander\";\nimport { relative, resolve } from \"node:path\";\nimport { downloadEcfrTitles, downloadEcfrTitlesFromApi, fetchEcfrTitlesMeta } from \"@lexbuild/ecfr\";\nimport type { EcfrTitlesResponse } from \"@lexbuild/ecfr\";\nimport {\n createSpinner,\n summaryBlock,\n dataTable,\n formatDuration,\n formatBytes,\n success,\n error,\n} from \"../ui.js\";\nimport { parseTitles } from \"../parse-titles.js\";\n\n/** Valid download source values */\ntype EcfrSource = \"govinfo\" | \"ecfr-api\";\n\n/** Parsed options from the download-ecfr command */\ninterface DownloadEcfrOptions {\n output: string;\n titles?: string | undefined;\n all: boolean;\n source: EcfrSource;\n date?: string | undefined;\n}\n\nexport const downloadEcfrCommand = new Command(\"download-ecfr\")\n .description(\"Download eCFR XML from govinfo or eCFR API\")\n .option(\"-o, --output <dir>\", \"Download directory\", \"./downloads/ecfr/xml\")\n .option(\"--titles <spec>\", \"Title(s) to download: 1, 1-5, or 1-5,8,17\")\n .option(\"--all\", \"Download all 50 eCFR titles\", false)\n .option(\n \"--source <source>\",\n \"Download source: ecfr-api (daily-updated) or govinfo (bulk data)\",\n \"ecfr-api\",\n )\n .option(\"--date <YYYY-MM-DD>\", \"Point-in-time date (ecfr-api source only)\")\n .addHelpText(\n \"after\",\n `\nExamples:\n $ lexbuild download-ecfr --all Download all titles from eCFR API\n $ lexbuild download-ecfr --titles 1 Download Title 1 only\n $ lexbuild download-ecfr --titles 1-5,17 Download specific titles\n $ lexbuild download-ecfr --all --date 2026-01-01 Point-in-time download\n $ lexbuild download-ecfr --all --source govinfo Download from govinfo bulk data\n\nSources:\n ecfr-api — eCFR API from ecfr.gov (default, daily-updated, point-in-time support)\n govinfo — Bulk XML from govinfo.gov (updates irregularly)`,\n )\n .action(async (options: DownloadEcfrOptions) => {\n if (!options.titles && !options.all) {\n console.error(error(\"Specify --titles <spec> or --all (e.g. --titles 1-5,17)\"));\n process.exit(1);\n }\n\n // Validate source\n const validSources: EcfrSource[] = [\"govinfo\", \"ecfr-api\"];\n if (!validSources.includes(options.source)) {\n console.error(\n error(`Invalid source \"${options.source}\". Valid sources: ${validSources.join(\", \")}`),\n );\n process.exit(1);\n }\n\n // --date is only valid with ecfr-api source\n if (options.date && options.source !== \"ecfr-api\") {\n console.error(error(\"--date is only supported with --source ecfr-api\"));\n process.exit(1);\n }\n\n // Validate date format if provided\n if (options.date && !/^\\d{4}-\\d{2}-\\d{2}$/.test(options.date)) {\n console.error(error(\"--date must be in YYYY-MM-DD format\"));\n process.exit(1);\n }\n\n let titles: number[] | undefined;\n if (options.titles) {\n try {\n titles = parseTitles(options.titles, 50);\n } catch (err) {\n console.error(error(err instanceof Error ? err.message : String(err)));\n process.exit(1);\n }\n }\n\n const outputDir = resolve(options.output);\n const titleCount = titles ? titles.length : 50;\n const sourceLabel = options.source === \"ecfr-api\" ? \"eCFR API\" : \"govinfo\";\n\n // For ecfr-api, fetch metadata upfront to resolve dates and display status\n let meta: EcfrTitlesResponse | undefined;\n if (options.source === \"ecfr-api\" && !options.date) {\n const metaSpinner = createSpinner(\"Fetching eCFR title metadata...\");\n metaSpinner.start();\n try {\n meta = await fetchEcfrTitlesMeta();\n metaSpinner.succeed(\"eCFR title metadata loaded\");\n } catch (err) {\n metaSpinner.fail(err instanceof Error ? err.message : String(err));\n process.exit(1);\n }\n }\n\n // Build spinner label with date info\n let dateLabel = \"\";\n let statusNote = \"\";\n if (options.date) {\n dateLabel = ` as of ${options.date}`;\n } else if (meta) {\n const primaryDate = meta.importInProgress\n ? (() => {\n const prev = new Date(meta.date);\n prev.setDate(prev.getDate() - 1);\n return prev.toISOString().slice(0, 10);\n })()\n : meta.date;\n dateLabel = ` as of ${primaryDate}`;\n\n // Check for titles with individual processing\n const processingTitles = meta.titles.filter((t) => t.processingInProgress && !t.reserved);\n if (meta.importInProgress && processingTitles.length > 0) {\n const titleWord = processingTitles.length === 1 ? \"title uses\" : \"titles use\";\n statusNote = ` (import in progress, ${processingTitles.length} ${titleWord} earlier dates)`;\n } else if (meta.importInProgress) {\n statusNote = \" (import in progress, using previous day)\";\n } else if (processingTitles.length > 0) {\n const nums = processingTitles.map((t) => t.number).join(\", \");\n statusNote = ` (Title ${nums} processing, using earlier date)`;\n }\n }\n\n const label =\n titleCount === 1\n ? `Downloading eCFR Title ${titles?.[0]} from ${sourceLabel}${dateLabel}${statusNote}`\n : `Downloading ${titleCount} eCFR titles from ${sourceLabel}${dateLabel}${statusNote}`;\n\n const spinner = createSpinner(`${label}...`);\n spinner.start();\n\n const startTime = performance.now();\n\n try {\n if (options.source === \"ecfr-api\") {\n await downloadFromApi(options, titles, outputDir, spinner, startTime, meta);\n } else {\n await downloadFromGovinfo(titles, outputDir, spinner, startTime);\n }\n } catch (err) {\n spinner.fail(err instanceof Error ? err.message : String(err));\n process.exit(1);\n }\n });\n\n/** Download from govinfo bulk data (existing behavior) */\nasync function downloadFromGovinfo(\n titles: number[] | undefined,\n outputDir: string,\n spinner: ReturnType<typeof createSpinner>,\n startTime: number,\n): Promise<void> {\n const result = await downloadEcfrTitles({\n output: outputDir,\n titles,\n onProgress: ({ current, total, titleNumber }) => {\n if (total === 1) {\n spinner.text = `Downloading eCFR Title ${titleNumber} from govinfo...`;\n } else {\n spinner.text = `Downloading eCFR titles from govinfo (${current}/${total}) — Title ${titleNumber}...`;\n }\n },\n });\n\n const elapsed = performance.now() - startTime;\n spinner.stop();\n\n const fileRows = result.files.map((file) => [\n String(file.titleNumber),\n formatBytes(file.size),\n relative(outputDir, file.path) || file.path,\n ]);\n\n const output = summaryBlock({\n title: \"lexbuild — eCFR Download Summary\",\n rows: [\n [\"Source\", \"govinfo.gov/bulkdata/ECFR\"],\n [\"Directory\", relative(process.cwd(), outputDir) || outputDir],\n ],\n });\n process.stdout.write(output);\n\n if (fileRows.length > 0) {\n console.log(dataTable([\"Title\", \"Size\", \"File\"], fileRows));\n }\n\n if (result.errors.length > 0) {\n for (const err of result.errors) {\n console.log(` ${error(`Title ${err.titleNumber}: ${err.error}`)}`);\n }\n }\n\n const titleWord = result.titlesDownloaded === 1 ? \"title\" : \"titles\";\n const failSuffix = result.errors.length > 0 ? ` (${result.errors.length} failed)` : \"\";\n const summary = `Downloaded ${result.titlesDownloaded} ${titleWord} (${formatBytes(result.totalBytes)}) in ${formatDuration(elapsed)}`;\n console.log(` ${success(summary + failSuffix)}`);\n console.log(\"\");\n}\n\n/** Download from eCFR API (daily-updated, point-in-time) */\nasync function downloadFromApi(\n options: DownloadEcfrOptions,\n titles: number[] | undefined,\n outputDir: string,\n spinner: ReturnType<typeof createSpinner>,\n startTime: number,\n meta?: EcfrTitlesResponse,\n): Promise<void> {\n const result = await downloadEcfrTitlesFromApi({\n output: outputDir,\n titles,\n date: options.date,\n titlesMeta: meta,\n onProgress: ({ current, total, titleNumber }) => {\n if (total === 1) {\n spinner.text = `Downloading eCFR Title ${titleNumber} from eCFR API...`;\n } else {\n spinner.text = `Downloading eCFR titles from eCFR API (${current}/${total}) — Title ${titleNumber}...`;\n }\n },\n });\n\n const elapsed = performance.now() - startTime;\n spinner.stop();\n\n // Check if any titles used different dates\n const uniqueDates = new Set(result.files.map((f) => f.asOfDate));\n const dateDisplay =\n uniqueDates.size <= 1\n ? result.asOfDate\n : `${result.asOfDate} (${uniqueDates.size - 1} titles at earlier dates)`;\n\n const fileRows = result.files.map((file) => {\n const row = [\n String(file.titleNumber),\n formatBytes(file.size),\n relative(outputDir, file.path) || file.path,\n ];\n // Show the date if it differs from the primary\n if (file.asOfDate !== result.asOfDate) {\n row.push(file.asOfDate);\n }\n return row;\n });\n\n const summaryRows: [string, string][] = [\n [\"Source\", \"ecfr.gov/api/versioner/v1\"],\n [\"As of date\", dateDisplay],\n [\"Directory\", relative(process.cwd(), outputDir) || outputDir],\n ];\n\n const output = summaryBlock({\n title: \"lexbuild — eCFR Download Summary\",\n rows: summaryRows,\n });\n process.stdout.write(output);\n\n // Include date column only if some titles used different dates\n const hasMultipleDates = uniqueDates.size > 1;\n const headings = hasMultipleDates ? [\"Title\", \"Size\", \"File\", \"Date\"] : [\"Title\", \"Size\", \"File\"];\n\n if (fileRows.length > 0) {\n console.log(dataTable(headings, fileRows));\n }\n\n // Report failures with context\n if (result.failed.length > 0) {\n const processing = result.failed.filter((f) => f.status === 503);\n const other = result.failed.filter((f) => f.status !== 503);\n\n if (processing.length > 0) {\n const nums = processing.map((f) => `Title ${f.titleNumber}`).join(\", \");\n console.log(` ${error(`Unavailable (processing on server): ${nums}`)}`);\n console.log(` The eCFR API cannot serve these titles while an import is in progress.`);\n console.log(\n ` Re-run this command later to download them. Existing local files (if any) are preserved.`,\n );\n }\n if (other.length > 0) {\n const nums = other.map((f) => `Title ${f.titleNumber} (${f.status})`).join(\", \");\n console.log(` ${error(`Failed: ${nums}`)}`);\n }\n }\n\n const titleWord = result.titlesDownloaded === 1 ? \"title\" : \"titles\";\n const failSuffix = result.failed.length > 0 ? ` (${result.failed.length} failed)` : \"\";\n const summary = `Downloaded ${result.titlesDownloaded} ${titleWord} (${formatBytes(result.totalBytes)}) in ${formatDuration(elapsed)}`;\n console.log(` ${success(summary + failSuffix)}`);\n console.log(\"\");\n}\n"],"mappings":";;;AAEA,SAAS,qBAAqB;AAC9B,SAAS,WAAAA,gBAAe;;;ACCxB,OAAOC,YAAW;AAClB,SAAS,SAAS,cAAc;AAChC,SAAS,YAAY,mBAAmB;AACxC,SAAS,UAAU,S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,EACjD,mBAAmB,EACnB,WAAW,KAAK,EAChB,OAAO,MAAM;AACZ,YAAQ,MAAM,MAAM,4BAA4B,CAAC;AACjD,YAAQ,MAAM,8DAA8D;AAC5E,YAAQ,MAAM,4DAA4D;AAC1E,YAAQ,MAAM,EAAE;AAChB,YAAQ,KAAK,CAAC;AAAA,EAChB,CAAC;AACL;AAEA,QAAQ;AAAA,EACN,IAAIA,SAAQ,SAAS,EAClB,YAAY,mCAAmC,EAC/C,mBAAmB,EACnB,WAAW,KAAK,EAChB,OAAO,MAAM;AACZ,YAAQ,MAAM,MAAM,4BAA4B,CAAC;AACjD,YAAQ,MAAM,+DAA+D;AAC7E,YAAQ,MAAM,0DAA0D;AACxE,YAAQ,MAAM,EAAE;AAChB,YAAQ,KAAK,CAAC;AAAA,EAChB,CAAC;AACL;AAEA,QAAQ,MAAM;","names":["Command","chalk","inputDir","chalk","Command","relative","resolve","Command","resolve","relative","Command","detectLatestReleasePoint","FALLBACK_RELEASE_POINT","Command","detectLatestReleasePoint","FALLBACK_RELEASE_POINT","chalk","Command","Option","existsSync","readdirSync","join","relative","resolve","buildConvertOptions","titleXmlPath","join","existsSync","readdirSync","runConversion","convertSingleFile","relative","Command","Option","resolve","inputDir","chalk","Command","relative","resolve","Command","resolve","relative","require","Command"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/commands/convert-usc.ts","../src/ui.ts","../src/parse-titles.ts","../src/commands/download-usc.ts","../src/commands/list-release-points.ts","../src/commands/convert-ecfr.ts","../src/commands/download-ecfr.ts","../src/commands/download-fr.ts","../src/commands/convert-fr.ts"],"sourcesContent":["/** lexbuild CLI — Convert U.S. legal XML to structured Markdown */\n\nimport { createRequire } from \"node:module\";\nimport { Command } from \"commander\";\nimport { convertUscCommand } from \"./commands/convert-usc.js\";\nimport { downloadUscCommand } from \"./commands/download-usc.js\";\nimport { listReleasePointsCommand } from \"./commands/list-release-points.js\";\nimport { convertEcfrCommand } from \"./commands/convert-ecfr.js\";\nimport { downloadEcfrCommand } from \"./commands/download-ecfr.js\";\nimport { downloadFrCommand } from \"./commands/download-fr.js\";\nimport { convertFrCommand } from \"./commands/convert-fr.js\";\nimport { error } from \"./ui.js\";\n\nconst require = createRequire(import.meta.url);\nconst pkg = require(\"../package.json\") as { version: string };\n\nconst program = new Command();\n\nprogram\n .name(\"lexbuild\")\n .description(\"Convert U.S. legal XML to structured Markdown for AI/RAG ingestion\")\n .version(pkg.version)\n .addHelpText(\n \"after\",\n `\nQuick start (U.S. Code):\n $ lexbuild download-usc --all Download all 54 USC titles from OLRC\n $ lexbuild convert-usc --all Convert all downloaded USC titles\n $ lexbuild convert-usc --titles 1 Convert USC Title 1 only\n\nQuick start (eCFR):\n $ lexbuild download-ecfr --all Download all 50 eCFR titles from govinfo\n $ lexbuild convert-ecfr --all Convert all downloaded eCFR titles\n $ lexbuild convert-ecfr --titles 17 Convert eCFR Title 17 only\n\nQuick start (Federal Register):\n $ lexbuild download-fr --recent 30 Download last 30 days of FR documents\n $ lexbuild convert-fr --all Convert all downloaded FR documents\n\nDocumentation: https://github.com/chris-c-thomas/LexBuild`,\n );\n\n// Source-specific commands\nprogram.addCommand(downloadUscCommand);\nprogram.addCommand(convertUscCommand);\nprogram.addCommand(listReleasePointsCommand);\nprogram.addCommand(downloadEcfrCommand);\nprogram.addCommand(convertEcfrCommand);\nprogram.addCommand(downloadFrCommand);\nprogram.addCommand(convertFrCommand);\n\n// Bare \"download\" and \"convert\" stubs — guide users to source-specific commands\nprogram.addCommand(\n new Command(\"download\")\n .description(\"(use download-usc or download-ecfr)\")\n .allowUnknownOption()\n .helpOption(false)\n .action(() => {\n console.error(error(\"Please specify a source:\\n\"));\n console.error(\" lexbuild download-usc Download U.S. Code XML from OLRC\");\n console.error(\" lexbuild download-ecfr Download eCFR XML from govinfo\");\n console.error(\" lexbuild download-fr Download Federal Register XML from federalregister.gov\");\n console.error(\"\");\n process.exit(1);\n }),\n);\n\nprogram.addCommand(\n new Command(\"convert\")\n .description(\"(use convert-usc or convert-ecfr)\")\n .allowUnknownOption()\n .helpOption(false)\n .action(() => {\n console.error(error(\"Please specify a source:\\n\"));\n console.error(\" lexbuild convert-usc Convert U.S. Code XML to Markdown\");\n console.error(\" lexbuild convert-ecfr Convert eCFR XML to Markdown\");\n console.error(\" lexbuild convert-fr Convert Federal Register XML to Markdown\");\n console.error(\"\");\n process.exit(1);\n }),\n);\n\nprogram.parse();\n","/**\n * `lexbuild convert-usc` command — converts USC XML files to Markdown.\n */\n\nimport chalk from \"chalk\";\nimport { Command, Option } from \"commander\";\nimport { existsSync, readdirSync } from \"node:fs\";\nimport { basename, dirname, join, relative, resolve } from \"node:path\";\nimport { convertTitle } from \"@lexbuild/usc\";\nimport {\n createSpinner,\n summaryBlock,\n dataTable,\n formatDuration,\n formatBytes,\n formatNumber,\n success,\n error,\n} from \"../ui.js\";\nimport { parseTitles } from \"../parse-titles.js\";\n\n/** Parsed options from the convert command */\ninterface ConvertCommandOptions {\n output: string;\n titles?: string | undefined;\n all: boolean;\n inputDir: string;\n granularity: \"section\" | \"chapter\" | \"title\";\n linkStyle: \"relative\" | \"canonical\" | \"plaintext\";\n includeSourceCredits: boolean;\n includeNotes: boolean;\n includeEditorialNotes: boolean;\n includeStatutoryNotes: boolean;\n includeAmendments: boolean;\n dryRun: boolean;\n verbose: boolean;\n}\n\n/** Build the shared convert options from CLI flags. */\nfunction buildConvertOptions(\n inputPath: string,\n outputPath: string,\n options: ConvertCommandOptions,\n) {\n const hasSelectiveFlags =\n options.includeEditorialNotes || options.includeStatutoryNotes || options.includeAmendments;\n const includeNotes = hasSelectiveFlags ? false : options.includeNotes;\n\n return {\n input: inputPath,\n output: outputPath,\n granularity: options.granularity,\n linkStyle: options.linkStyle,\n includeSourceCredits: options.includeSourceCredits,\n includeNotes,\n includeEditorialNotes: options.includeEditorialNotes,\n includeStatutoryNotes: options.includeStatutoryNotes,\n includeAmendments: options.includeAmendments,\n dryRun: options.dryRun,\n };\n}\n\n/** Resolve the XML file path for a given title number. */\nfunction titleXmlPath(inputDir: string, titleNum: number): string {\n const padded = String(titleNum).padStart(2, \"0\");\n return join(inputDir, `usc${padded}.xml`);\n}\n\n/** Try to resolve a USC XML path, falling back to zero-padded filename. */\nexport function resolveUscXmlPath(inputPath: string): string | undefined {\n if (existsSync(inputPath)) return inputPath;\n\n // Check if filename matches usc{N}.xml pattern and try zero-padded\n const dir = dirname(inputPath);\n const base = basename(inputPath);\n const match = /^usc(\\d+)\\.xml$/.exec(base);\n if (match?.[1]) {\n const padded = match[1].padStart(2, \"0\");\n const paddedPath = join(dir, `usc${padded}.xml`);\n if (existsSync(paddedPath)) return paddedPath;\n }\n\n return undefined;\n}\n\n/** Regex matching USC XML filenames like usc01.xml, usc54.xml */\nconst USC_XML_RE = /^usc(\\d{2})\\.xml$/;\n\n/**\n * Scan a directory for USC XML files and return their title numbers, sorted.\n */\nexport function discoverTitles(inputDir: string): number[] {\n if (!existsSync(inputDir)) return [];\n\n return readdirSync(inputDir)\n .map((name) => USC_XML_RE.exec(name))\n .filter((m): m is RegExpExecArray => m !== null)\n .map((m) => parseInt(m[1] ?? \"0\", 10))\n .sort((a, b) => a - b);\n}\n\n/** Result from runConversion including elapsed time. */\ninterface ConversionRun {\n result: Awaited<ReturnType<typeof convertTitle>>;\n elapsed: number;\n}\n\n/** Run a conversion without printing output. Returns the result and elapsed time. */\nasync function runConversion(\n inputPath: string,\n outputPath: string,\n options: ConvertCommandOptions,\n): Promise<ConversionRun> {\n const startTime = performance.now();\n const result = await convertTitle(buildConvertOptions(inputPath, outputPath, options));\n const elapsed = performance.now() - startTime;\n return { result, elapsed };\n}\n\n/** Convert a single XML file and print its detailed summary. */\nasync function convertSingleFile(\n inputPath: string,\n outputPath: string,\n options: ConvertCommandOptions,\n spinnerLabel: string,\n) {\n const spinner = createSpinner(spinnerLabel);\n spinner.start();\n\n try {\n const { result, elapsed } = await runConversion(inputPath, outputPath, options);\n\n spinner.stop();\n\n const rows: Array<[string, string]> = [];\n if (options.granularity === \"section\") {\n rows.push([\"Sections\", formatNumber(result.sectionsWritten)]);\n rows.push([\"Chapters\", formatNumber(result.chapterCount)]);\n } else if (options.granularity === \"chapter\") {\n rows.push([\"Chapters\", formatNumber(result.chapterCount)]);\n }\n rows.push([\"Est. Tokens\", formatNumber(result.totalTokenEstimate)]);\n\n if (!result.dryRun) {\n rows.push([\"Files Written\", formatNumber(result.files.length)]);\n }\n\n rows.push(\n [\"Peak Memory\", formatBytes(result.peakMemoryBytes)],\n [\"Duration\", formatDuration(elapsed)],\n );\n\n const titleLabel = result.dryRun\n ? `lexbuild — Title ${result.titleNumber}: ${result.titleName} [dry-run]`\n : `lexbuild — Title ${result.titleNumber}: ${result.titleName}`;\n\n const outputRelative = relative(process.cwd(), outputPath) || outputPath;\n\n const output = summaryBlock({\n title: titleLabel,\n rows: [...rows, [\"Output\", outputRelative]],\n footer: result.dryRun ? success(\"Dry run complete\") : success(\"Conversion complete\"),\n });\n process.stdout.write(output);\n\n if (options.verbose && !result.dryRun && result.files.length > 0) {\n console.log(\" Files written:\");\n for (const file of result.files) {\n console.log(` ${relative(process.cwd(), file) || file}`);\n }\n console.log(\"\");\n }\n\n return result;\n } catch (err) {\n spinner.fail(err instanceof Error ? err.message : String(err));\n process.exit(1);\n }\n}\n\nexport const convertUscCommand = new Command(\"convert-usc\")\n .description(\"Convert U.S. Code XML file(s) to Markdown\")\n .argument(\"[input]\", \"Path to a USC XML file\")\n .option(\"-o, --output <dir>\", \"Output directory\", \"./output\")\n .option(\"--titles <spec>\", \"Title(s) to convert: 1, 1-5, or 1-5,8,11\")\n .option(\"--all\", \"Convert all downloaded titles found in --input-dir\", false)\n .option(\"-i, --input-dir <dir>\", \"Directory containing USC XML files\", \"./downloads/usc/xml\")\n .addOption(\n new Option(\"-g, --granularity <level>\", \"Output granularity: section, chapter, or title\")\n .choices([\"section\", \"chapter\", \"title\"])\n .default(\"section\"),\n )\n .addOption(\n new Option(\"--link-style <style>\", \"Link style: relative, canonical, or plaintext\")\n .choices([\"relative\", \"canonical\", \"plaintext\"])\n .default(\"plaintext\"),\n )\n .option(\"--include-source-credits\", \"Include source credit annotations\", true)\n .option(\"--no-include-source-credits\", \"Exclude source credit annotations\")\n .option(\"--include-notes\", \"Include all notes (default)\", true)\n .option(\"--no-include-notes\", \"Exclude all notes\")\n .option(\"--include-editorial-notes\", \"Include editorial notes only\", false)\n .option(\"--include-statutory-notes\", \"Include statutory notes only\", false)\n .option(\"--include-amendments\", \"Include amendment history notes only\", false)\n .option(\"--dry-run\", \"Parse and report structure without writing files\", false)\n .option(\"-v, --verbose\", \"Enable verbose logging\", false)\n .addHelpText(\n \"after\",\n `\nInput modes (use exactly one):\n <input> Convert a single XML file\n --titles Convert specific titles by number\n --all Convert all titles in --input-dir\n\nGranularity:\n section One .md file per section (default)\n chapter One .md file per chapter, sections inlined\n title One .md file per title, entire hierarchy inlined\n\nExamples:\n $ lexbuild convert-usc --titles 1 Convert Title 1\n $ lexbuild convert-usc --titles 1-5,8,11 Convert a mix of titles\n $ lexbuild convert-usc --all -g chapter All titles, chapter-level\n $ lexbuild convert-usc --titles 26 -g title Title 26 as a single file\n $ lexbuild convert-usc --all --dry-run Preview stats only\n $ lexbuild convert-usc ./downloads/usc/xml/usc01.xml -o ./out`,\n )\n .action(async (input: string | undefined, options: ConvertCommandOptions) => {\n // Validate: must specify exactly one of <input>, --titles, or --all\n const modeCount = [input, options.titles, options.all].filter(Boolean).length;\n if (modeCount === 0) {\n console.error(\n error(\"Specify an input file, --titles <spec>, or --all (e.g. --titles 1-5,8,11)\"),\n );\n process.exit(1);\n }\n if (modeCount > 1) {\n console.error(error(\"Cannot combine <input>, --titles, and --all — use only one\"));\n process.exit(1);\n }\n\n const outputPath = resolve(options.output);\n const dryRunLabel = options.dryRun ? \" [dry-run]\" : \"\";\n\n // Single-file mode\n if (input) {\n const rawPath = resolve(input);\n const inputPath = resolveUscXmlPath(rawPath);\n if (!inputPath) {\n console.error(error(`Input file not found: ${rawPath}`));\n process.exit(1);\n }\n await convertSingleFile(inputPath, outputPath, options, `Converting${dryRunLabel}...`);\n return;\n }\n\n // Multi-title mode\n let titles: number[];\n if (options.all) {\n const inputDir = resolve(options.inputDir);\n titles = discoverTitles(inputDir);\n if (titles.length === 0) {\n console.error(error(`No USC XML files found in ${inputDir}`));\n process.exit(1);\n }\n } else {\n const titlesSpec = options.titles as string;\n try {\n titles = parseTitles(titlesSpec);\n } catch (err) {\n console.error(error(err instanceof Error ? err.message : String(err)));\n process.exit(1);\n }\n }\n\n const inputDir = resolve(options.inputDir);\n const totalTitles = titles.length;\n const results: ConversionRun[] = [];\n\n const spinner = createSpinner(`Converting${dryRunLabel}...`);\n spinner.start();\n\n for (const [i, titleNum] of titles.entries()) {\n const xmlPath = titleXmlPath(inputDir, titleNum);\n\n if (!existsSync(xmlPath)) {\n spinner.stop();\n console.error(error(`XML file not found: ${xmlPath}`));\n process.exit(1);\n }\n\n spinner.text = `Converting Title ${titleNum}${dryRunLabel} (${i + 1}/${totalTitles})...`;\n\n try {\n const run = await runConversion(xmlPath, outputPath, options);\n results.push(run);\n } catch (err) {\n spinner.fail(err instanceof Error ? err.message : String(err));\n process.exit(1);\n }\n }\n\n spinner.stop();\n\n // Summary header\n const outputRelative = relative(process.cwd(), outputPath) || outputPath;\n const headerTitle = options.dryRun\n ? \"lexbuild — Conversion Summary [dry-run]\"\n : \"lexbuild — Conversion Summary\";\n const header = summaryBlock({\n title: headerTitle,\n rows: [[\"Directory\", outputRelative]],\n });\n process.stdout.write(header);\n\n // Build data table rows — adapt columns to granularity\n const granularity = options.granularity;\n let totalSections = 0;\n let totalChapters = 0;\n let totalTokens = 0;\n let totalElapsed = 0;\n\n const tableRows = results.map(({ result, elapsed }) => {\n totalSections += result.sectionsWritten;\n totalChapters += result.chapterCount;\n totalTokens += result.totalTokenEstimate;\n totalElapsed += elapsed;\n\n if (granularity === \"title\") {\n return [\n result.titleNumber,\n result.titleName,\n formatNumber(result.totalTokenEstimate),\n formatDuration(elapsed),\n ];\n } else if (granularity === \"chapter\") {\n return [\n result.titleNumber,\n result.titleName,\n formatNumber(result.chapterCount),\n formatNumber(result.totalTokenEstimate),\n formatDuration(elapsed),\n ];\n } else {\n return [\n result.titleNumber,\n result.titleName,\n formatNumber(result.chapterCount),\n formatNumber(result.sectionsWritten),\n formatNumber(result.totalTokenEstimate),\n formatDuration(elapsed),\n ];\n }\n });\n\n // Totals row\n if (granularity === \"title\") {\n tableRows.push([\n chalk.bold(\"Total\"),\n \"\",\n chalk.bold(formatNumber(totalTokens)),\n chalk.bold(formatDuration(totalElapsed)),\n ]);\n } else if (granularity === \"chapter\") {\n tableRows.push([\n chalk.bold(\"Total\"),\n \"\",\n chalk.bold(formatNumber(totalChapters)),\n chalk.bold(formatNumber(totalTokens)),\n chalk.bold(formatDuration(totalElapsed)),\n ]);\n } else {\n tableRows.push([\n chalk.bold(\"Total\"),\n \"\",\n chalk.bold(formatNumber(totalChapters)),\n chalk.bold(formatNumber(totalSections)),\n chalk.bold(formatNumber(totalTokens)),\n chalk.bold(formatDuration(totalElapsed)),\n ]);\n }\n\n // Table headers and footer — adapt to granularity\n const tableHeaders =\n granularity === \"title\"\n ? [\"Title\", \"Name\", \"Tokens\", \"Duration\"]\n : granularity === \"chapter\"\n ? [\"Title\", \"Name\", \"Chapters\", \"Tokens\", \"Duration\"]\n : [\"Title\", \"Name\", \"Chapters\", \"Sections\", \"Tokens\", \"Duration\"];\n\n console.log(dataTable(tableHeaders, tableRows));\n\n // Footer — show the primary unit that was converted\n let countLabel: string;\n if (granularity === \"title\") {\n const titleWord = totalTitles === 1 ? \"title\" : \"titles\";\n countLabel = `${formatNumber(totalTitles)} ${titleWord}`;\n } else if (granularity === \"chapter\") {\n const chapterWord = totalChapters === 1 ? \"chapter\" : \"chapters\";\n countLabel = `${formatNumber(totalChapters)} ${chapterWord}`;\n } else {\n const sectionWord = totalSections === 1 ? \"section\" : \"sections\";\n countLabel = `${formatNumber(totalSections)} ${sectionWord}`;\n }\n console.log(`\\n ${success(`Converted ${countLabel} in ${formatDuration(totalElapsed)}`)}`);\n console.log(\"\");\n });\n","/**\n * Shared terminal UI utilities — spinners, tables, and formatting helpers.\n */\n\nimport chalk from \"chalk\";\nimport ora from \"ora\";\nimport type { Ora } from \"ora\";\nimport Table from \"cli-table3\";\n\n/** Create an ora spinner with consistent styling. */\nexport function createSpinner(text: string): Ora {\n return ora({ text, spinner: \"dots\" });\n}\n\n/** Format milliseconds as human-readable duration (e.g. \"1.5s\" or \"1m 23s\"). */\nexport function formatDuration(ms: number): string {\n const secs = ms / 1000;\n if (secs < 60) {\n return `${secs.toFixed(secs < 10 ? 2 : 1)}s`;\n }\n const mins = Math.floor(secs / 60);\n const remainSecs = Math.round(secs % 60);\n return `${mins}m ${remainSecs}s`;\n}\n\n/** Format bytes as human-readable size (e.g. \"11.0 MB\"). */\nexport function formatBytes(bytes: number): string {\n if (bytes < 1024) return `${bytes} B`;\n const kb = bytes / 1024;\n if (kb < 1024) return `${kb.toFixed(1)} KB`;\n const mb = kb / 1024;\n if (mb < 1024) return `${mb.toFixed(1)} MB`;\n const gb = mb / 1024;\n return `${gb.toFixed(2)} GB`;\n}\n\n/** Format a number with locale-aware separators (e.g. 1,234,567). */\nexport function formatNumber(n: number): string {\n return n.toLocaleString();\n}\n\n/** Regex matching ANSI escape sequences (SGR codes). */\n// eslint-disable-next-line no-control-regex\nconst ANSI_RE = /\\x1B\\[[0-9;]*m/g;\n\n/** Strip ANSI escape codes and return visual string length. */\nfunction visualLength(s: string): number {\n return s.replace(ANSI_RE, \"\").length;\n}\n\n/**\n * Compute column widths that fill the terminal.\n * Expands `flexCol` to absorb remaining space.\n */\nfunction fillWidths(columns: string[][], colCount: number, flexCol: number): number[] | undefined {\n const termWidth = process.stdout.columns || 80;\n // Compute natural width per column (max visual length across all rows)\n const natural = Array.from<number>({ length: colCount }).fill(0);\n for (const row of columns) {\n for (let i = 0; i < colCount; i++) {\n natural[i] = Math.max(natural[i] ?? 0, visualLength(row[i] ?? \"\"));\n }\n }\n // Overhead: 2 chars left pad + 2 chars per column separator (between cols)\n const overhead = 2 + 2 * (colCount - 1);\n const naturalTotal = overhead + natural.reduce((a, b) => a + b, 0);\n if (naturalTotal >= termWidth) return undefined; // already fills or exceeds\n const extra = termWidth - naturalTotal;\n const widths = [...natural];\n widths[flexCol] = (widths[flexCol] ?? 0) + extra;\n return widths;\n}\n\n/**\n * Shared cli-table3 border characters.\n *\n * Uses 2-char left indent (\" \"), 2-char column gap (\" \"), no right border.\n * The \"mid\" intersection chars (\"──\") must match the 2-char width of \"middle\"\n * so horizontal rules span the full table width.\n */\nconst TABLE_CHARS = {\n top: \"─\",\n \"top-mid\": \"──\",\n \"top-left\": \" \",\n \"top-right\": \"\",\n bottom: \"─\",\n \"bottom-mid\": \"──\",\n \"bottom-left\": \" \",\n \"bottom-right\": \"\",\n left: \" \",\n \"left-mid\": \" \",\n right: \"\",\n \"right-mid\": \"\",\n mid: \"─\",\n \"mid-mid\": \"──\",\n middle: \" \",\n} as const;\n\n/** Shared cli-table3 style. */\nconst TABLE_STYLE: {\n head: string[];\n border: string[];\n \"padding-left\": number;\n \"padding-right\": number;\n} = {\n head: [],\n border: [],\n \"padding-left\": 0,\n \"padding-right\": 0,\n};\n\n/** Render a styled heading line. */\nfunction heading(text: string): string {\n return chalk.bold(text);\n}\n\n/** Render a success message with green checkmark. */\nexport function success(text: string): string {\n return chalk.green(`✔ ${text}`);\n}\n\n/** Render an error message with red X. */\nexport function error(text: string): string {\n return chalk.red(`✘ ${text}`);\n}\n\n/** Options for a key-value summary block. */\ninterface SummaryBlockOptions {\n /** Title line displayed above the table */\n title: string;\n /** Key-value pairs to display */\n rows: Array<[label: string, value: string]>;\n /** Optional footer line displayed below the table */\n footer?: string | undefined;\n}\n\n/** Render a key-value summary block with horizontal rules. */\nexport function summaryBlock({ title, rows, footer }: SummaryBlockOptions): string {\n const allCells = rows.map(([l, v]) => [l, v]);\n const colWidths = fillWidths(allCells, 2, 1);\n\n const table = new Table({\n chars: TABLE_CHARS,\n style: TABLE_STYLE,\n ...(colWidths ? { colWidths } : {}),\n });\n\n for (const [label, value] of rows) {\n table.push([chalk.dim(label), value]);\n }\n\n const lines: string[] = [];\n lines.push(\"\");\n lines.push(` ${heading(title)}`);\n lines.push(table.toString());\n if (footer !== undefined) {\n lines.push(` ${footer}`);\n }\n lines.push(\"\");\n\n return lines.join(\"\\n\");\n}\n\n/** Render a multi-column data table. */\nexport function dataTable(head: string[], rows: string[][]): string {\n const table = new Table({\n head: head.map((h) => chalk.dim(h)),\n chars: TABLE_CHARS,\n style: TABLE_STYLE,\n });\n\n for (const row of rows) {\n table.push(row);\n }\n\n return table.toString();\n}\n","/**\n * Parses a title specification string into an array of title numbers.\n *\n * Supports single numbers, comma-separated lists, ranges, and mixed:\n * - `\"29\"` → `[29]`\n * - `\"1,3,8,11\"` → `[1, 3, 8, 11]`\n * - `\"1-5\"` → `[1, 2, 3, 4, 5]`\n * - `\"1-5,8,11\"` → `[1, 2, 3, 4, 5, 8, 11]`\n */\nexport function parseTitles(input: string, maxTitle = 54): number[] {\n const trimmed = input.trim();\n if (trimmed === \"\") {\n throw new Error(\"Title specification cannot be empty\");\n }\n\n const result = new Set<number>();\n const segments = trimmed.split(\",\");\n\n for (const segment of segments) {\n const part = segment.trim();\n if (part === \"\") {\n throw new Error(`Invalid title specification: \"${input}\" (empty segment)`);\n }\n\n if (part.includes(\"-\")) {\n const [startStr, endStr, ...rest] = part.split(\"-\");\n if (rest.length > 0 || !startStr || !endStr) {\n throw new Error(`Invalid range: \"${part}\" (expected format: start-end)`);\n }\n\n const start = parseIntStrict(startStr, input);\n const end = parseIntStrict(endStr, input);\n\n if (start > end) {\n throw new Error(`Invalid range: \"${part}\" (start ${start} must be ≤ end ${end})`);\n }\n\n validateTitleNumber(start, input, maxTitle);\n validateTitleNumber(end, input, maxTitle);\n\n for (let i = start; i <= end; i++) {\n result.add(i);\n }\n } else {\n const num = parseIntStrict(part, input);\n validateTitleNumber(num, input, maxTitle);\n result.add(num);\n }\n }\n\n return [...result].sort((a, b) => a - b);\n}\n\n/** Parse an integer strictly — no NaN, no floats. */\nfunction parseIntStrict(str: string, fullInput: string): number {\n const trimmed = str.trim();\n if (!/^\\d+$/.test(trimmed)) {\n throw new Error(`Invalid number \"${trimmed}\" in title specification: \"${fullInput}\"`);\n }\n return parseInt(trimmed, 10);\n}\n\n/** Validate that a title number is in the valid range. */\nfunction validateTitleNumber(num: number, fullInput: string, max = 54): void {\n if (num < 1 || num > max) {\n throw new Error(`Title number ${num} out of range (must be 1-${max}) in: \"${fullInput}\"`);\n }\n}\n","/**\n * `lexbuild download-usc` command — downloads USC XML from OLRC.\n *\n * Auto-detects the latest OLRC release point unless overridden with --release-point.\n */\n\nimport { Command } from \"commander\";\nimport { relative, resolve } from \"node:path\";\nimport { downloadTitles, detectLatestReleasePoint, FALLBACK_RELEASE_POINT } from \"@lexbuild/usc\";\nimport {\n createSpinner,\n summaryBlock,\n dataTable,\n formatDuration,\n formatBytes,\n success,\n error,\n} from \"../ui.js\";\nimport { parseTitles } from \"../parse-titles.js\";\n\n/** Parsed options from the download command */\ninterface DownloadCommandOptions {\n output: string;\n titles?: string | undefined;\n all: boolean;\n releasePoint?: string | undefined;\n}\n\nexport const downloadUscCommand = new Command(\"download-usc\")\n .description(\"Download U.S. Code XML from OLRC\")\n .option(\"-o, --output <dir>\", \"Download directory\", \"./downloads/usc/xml\")\n .option(\"--titles <spec>\", \"Title(s) to download: 1, 1-5, or 1-5,8,11\")\n .option(\"--all\", \"Download all 54 titles (single bulk zip)\", false)\n .option(\"--release-point <id>\", \"OLRC release point (auto-detected if omitted)\")\n .addHelpText(\n \"after\",\n `\nExamples:\n $ lexbuild download-usc --all Download all 54 titles (latest release)\n $ lexbuild download-usc --titles 1 Download Title 1 only\n $ lexbuild download-usc --titles 1-5,8,11 Download specific titles\n $ lexbuild download-usc --all -o ./my-xml Custom output directory\n $ lexbuild download-usc --all --release-point 119-73not60 Pin a specific release\n\nThe latest release point is auto-detected from the OLRC download page.\nSource: https://uscode.house.gov/download/download.shtml`,\n )\n .action(async (options: DownloadCommandOptions) => {\n // Validate: must specify --titles or --all\n if (!options.titles && !options.all) {\n console.error(error(\"Specify --titles <spec> or --all (e.g. --titles 1-5,8,11)\"));\n process.exit(1);\n }\n\n // Parse title numbers\n let titles: number[] | undefined;\n if (options.titles) {\n try {\n titles = parseTitles(options.titles);\n } catch (err) {\n console.error(error(err instanceof Error ? err.message : String(err)));\n process.exit(1);\n }\n }\n\n const outputDir = resolve(options.output);\n const titleCount = titles ? titles.length : 54;\n\n // Resolve release point: use explicit flag, auto-detect, or fall back\n let releasePoint = options.releasePoint;\n if (!releasePoint) {\n const detectSpinner = createSpinner(\"Detecting latest OLRC release point...\");\n detectSpinner.start();\n const detected = await detectLatestReleasePoint();\n if (detected) {\n releasePoint = detected.releasePoint;\n detectSpinner.succeed(`Release point: ${detected.releasePoint}`);\n } else {\n releasePoint = FALLBACK_RELEASE_POINT;\n detectSpinner.warn(`Could not detect release point, using fallback: ${releasePoint}`);\n }\n }\n\n const label =\n titleCount === 1 ? `Downloading Title ${titles?.[0]}` : `Downloading ${titleCount} USC titles`;\n\n const spinner = createSpinner(`${label}...`);\n spinner.start();\n\n const startTime = performance.now();\n\n try {\n const result = await downloadTitles({\n outputDir,\n titles,\n releasePoint,\n onProgress: ({ current, total, titleNumber, phase }) => {\n if (phase === \"extracting\") {\n spinner.text = `Extracting USC titles (${current}/${total}) — Title ${titleNumber}`;\n } else if (total === 1) {\n spinner.text = `Downloading USC Title ${titleNumber}`;\n } else if (current === 0) {\n spinner.text = \"Downloading USC bulk archive\";\n } else {\n spinner.text = `Downloading USC titles (${current}/${total}) — Title ${titleNumber}`;\n }\n },\n });\n\n const elapsed = performance.now() - startTime;\n\n spinner.stop();\n\n // Build file table rows\n const fileRows = result.files.map((file) => [\n String(file.titleNumber),\n formatBytes(file.size),\n relative(outputDir, file.filePath) || file.filePath,\n ]);\n\n const totalBytes = result.files.reduce((sum, f) => sum + f.size, 0);\n\n // Summary header — show the actual release point used (may be auto-detected)\n const rpLabel = options.releasePoint\n ? result.releasePoint\n : `${result.releasePoint} (auto-detected)`;\n\n const output = summaryBlock({\n title: \"lexbuild — Download Summary\",\n rows: [\n [\"Release Point\", rpLabel],\n [\"Directory\", relative(process.cwd(), outputDir) || outputDir],\n ],\n });\n process.stdout.write(output);\n\n // File table\n if (fileRows.length > 0) {\n console.log(dataTable([\"Title\", \"Size\", \"File\"], fileRows));\n }\n\n // Errors\n if (result.errors.length > 0) {\n console.log(\"\");\n for (const err of result.errors) {\n console.log(` ${error(`Title ${err.titleNumber}: ${err.message}`)}`);\n }\n }\n\n // Footer\n const titleWord = result.files.length === 1 ? \"title\" : \"titles\";\n const summary = `Downloaded ${result.files.length} ${titleWord} (${formatBytes(totalBytes)}) in ${formatDuration(elapsed)}`;\n const failSuffix = result.errors.length > 0 ? ` (${result.errors.length} failed)` : \"\";\n console.log(` ${success(summary + failSuffix)}`);\n console.log(\"\");\n } catch (err) {\n spinner.fail(err instanceof Error ? err.message : String(err));\n process.exit(1);\n }\n });\n","/**\n * `lexbuild list-release-points` command — lists available OLRC release points.\n *\n * Fetches the current release point from the OLRC download page and the full\n * history from the prior release points page, then displays them in a table.\n */\n\nimport { Command } from \"commander\";\nimport {\n detectLatestReleasePoint,\n fetchReleasePointHistory,\n FALLBACK_RELEASE_POINT,\n} from \"@lexbuild/usc\";\nimport { createSpinner, summaryBlock, dataTable, error } from \"../ui.js\";\n\n/** Parsed options from the list-release-points command */\ninterface ListReleasePointsOptions {\n limit: string;\n}\n\nexport const listReleasePointsCommand = new Command(\"list-release-points\")\n .description(\"List available OLRC release points for the U.S. Code\")\n .option(\"-n, --limit <count>\", \"Maximum number of release points to show\", \"20\")\n .addHelpText(\n \"after\",\n `\nExamples:\n $ lexbuild list-release-points Show the 20 most recent release points\n $ lexbuild list-release-points -n 5 Show the 5 most recent\n $ lexbuild list-release-points -n 0 Show all available release points\n\nUse --release-point <id> with download-usc to pin a specific release.\nSource: https://uscode.house.gov/download/priorreleasepoints.htm`,\n )\n .action(async (options: ListReleasePointsOptions) => {\n const limit = parseInt(options.limit, 10);\n if (Number.isNaN(limit) || limit < 0) {\n console.error(error(\"--limit must be a non-negative integer\"));\n process.exit(1);\n }\n\n const spinner = createSpinner(\"Fetching release points from OLRC...\");\n spinner.start();\n\n // Fetch current and history in parallel\n const [current, history] = await Promise.all([\n detectLatestReleasePoint(),\n fetchReleasePointHistory(),\n ]);\n\n spinner.stop();\n\n // Current release point summary\n const currentRp = current?.releasePoint ?? FALLBACK_RELEASE_POINT;\n const currentDesc = current?.description ?? \"(detection failed — showing fallback)\";\n\n const output = summaryBlock({\n title: \"lexbuild — OLRC Release Points\",\n rows: [\n [\"Latest\", `${currentRp} ${currentDesc}`],\n [\"Prior releases\", `${history.length} available`],\n ],\n });\n process.stdout.write(output);\n\n if (history.length === 0) {\n console.log(\" No prior release points found.\\n\");\n return;\n }\n\n // Apply limit (0 = show all)\n const displayed = limit > 0 ? history.slice(0, limit) : history;\n\n // Build table rows: Release Point, Date, Affected Titles\n const rows = displayed.map((rp) => [\n rp.releasePoint,\n rp.date,\n rp.affectedTitles.length > 0 ? rp.affectedTitles.join(\", \") : \"—\",\n ]);\n\n console.log(dataTable([\"Release Point\", \"Date\", \"Affected Titles\"], rows));\n\n if (limit > 0 && history.length > limit) {\n console.log(` Showing ${limit} of ${history.length} — use -n 0 to show all.\\n`);\n }\n\n console.log(\" Use with: lexbuild download-usc --all --release-point <id>\\n\");\n });\n","/**\n * `lexbuild convert-ecfr` command — converts eCFR XML files to Markdown.\n */\n\nimport chalk from \"chalk\";\nimport { Command, Option } from \"commander\";\nimport { existsSync, readdirSync } from \"node:fs\";\nimport { join, relative, resolve } from \"node:path\";\nimport { convertEcfrTitle } from \"@lexbuild/ecfr\";\nimport type { EcfrConvertOptions, EcfrConvertResult } from \"@lexbuild/ecfr\";\nimport {\n createSpinner,\n summaryBlock,\n dataTable,\n formatDuration,\n formatBytes,\n formatNumber,\n success,\n error,\n} from \"../ui.js\";\nimport { parseTitles } from \"../parse-titles.js\";\n\n/** Parsed options from the convert-ecfr command */\ninterface ConvertEcfrCommandOptions {\n output: string;\n titles?: string | undefined;\n all: boolean;\n inputDir: string;\n granularity: \"section\" | \"part\" | \"chapter\" | \"title\";\n linkStyle: \"relative\" | \"canonical\" | \"plaintext\";\n includeSourceCredits: boolean;\n includeNotes: boolean;\n includeEditorialNotes: boolean;\n includeStatutoryNotes: boolean;\n includeAmendments: boolean;\n dryRun: boolean;\n verbose: boolean;\n}\n\n/** Build EcfrConvertOptions from CLI flags. */\nfunction buildConvertOptions(\n inputPath: string,\n outputPath: string,\n options: ConvertEcfrCommandOptions,\n): EcfrConvertOptions {\n const hasSelectiveFlags =\n options.includeEditorialNotes || options.includeStatutoryNotes || options.includeAmendments;\n const includeNotes = hasSelectiveFlags ? false : options.includeNotes;\n\n return {\n input: inputPath,\n output: outputPath,\n granularity: options.granularity,\n linkStyle: options.linkStyle,\n includeSourceCredits: options.includeSourceCredits,\n includeNotes,\n includeEditorialNotes: options.includeEditorialNotes,\n includeStatutoryNotes: options.includeStatutoryNotes,\n includeAmendments: options.includeAmendments,\n dryRun: options.dryRun,\n };\n}\n\n/** Regex matching eCFR XML filenames like ECFR-title1.xml, ECFR-title17.xml */\nconst ECFR_XML_RE = /^ECFR-title(\\d+)\\.xml$/;\n\n/** Resolve the XML file path for a given eCFR title number. */\nfunction titleXmlPath(inputDir: string, titleNum: number): string {\n return join(inputDir, `ECFR-title${titleNum}.xml`);\n}\n\n/** Scan a directory for eCFR XML files and return their title numbers, sorted. */\nfunction discoverEcfrTitles(inputDir: string): number[] {\n if (!existsSync(inputDir)) return [];\n\n return readdirSync(inputDir)\n .map((name) => ECFR_XML_RE.exec(name))\n .filter((m): m is RegExpExecArray => m !== null)\n .map((m) => parseInt(m[1] ?? \"0\", 10))\n .sort((a, b) => a - b);\n}\n\n/** Result from running a conversion including elapsed time. */\ninterface ConversionRun {\n result: EcfrConvertResult;\n elapsed: number;\n}\n\n/** Run a conversion without printing output. */\nasync function runConversion(\n inputPath: string,\n outputPath: string,\n options: ConvertEcfrCommandOptions,\n): Promise<ConversionRun> {\n const startTime = performance.now();\n const result = await convertEcfrTitle(buildConvertOptions(inputPath, outputPath, options));\n const elapsed = performance.now() - startTime;\n return { result, elapsed };\n}\n\n/** Convert a single file and print its detailed summary. */\nasync function convertSingleFile(\n inputPath: string,\n outputPath: string,\n options: ConvertEcfrCommandOptions,\n spinnerLabel: string,\n) {\n const spinner = createSpinner(spinnerLabel);\n spinner.start();\n\n try {\n const { result, elapsed } = await runConversion(inputPath, outputPath, options);\n spinner.stop();\n\n const rows: Array<[string, string]> = [];\n if (options.granularity === \"section\") {\n rows.push([\"Sections\", formatNumber(result.sectionsWritten)]);\n rows.push([\"Parts\", formatNumber(result.partCount)]);\n } else if (options.granularity === \"part\") {\n rows.push([\"Parts\", formatNumber(result.partCount)]);\n } else if (options.granularity === \"chapter\") {\n rows.push([\"Chapters\", formatNumber(result.sectionsWritten)]);\n }\n rows.push([\"Est. Tokens\", formatNumber(result.totalTokenEstimate)]);\n\n if (!result.dryRun) {\n rows.push([\"Files Written\", formatNumber(result.files.length)]);\n }\n\n rows.push(\n [\"Peak Memory\", formatBytes(result.peakMemoryBytes)],\n [\"Duration\", formatDuration(elapsed)],\n );\n\n const titleLabel = result.dryRun\n ? `lexbuild — eCFR Title ${result.titleNumber}: ${result.titleName} [dry-run]`\n : `lexbuild — eCFR Title ${result.titleNumber}: ${result.titleName}`;\n\n const outputRelative = relative(process.cwd(), outputPath) || outputPath;\n\n const output = summaryBlock({\n title: titleLabel,\n rows: [...rows, [\"Output\", outputRelative]],\n footer: result.dryRun ? success(\"Dry run complete\") : success(\"Conversion complete\"),\n });\n process.stdout.write(output);\n\n if (options.verbose && !result.dryRun && result.files.length > 0) {\n console.log(\" Files written:\");\n for (const file of result.files) {\n console.log(` ${relative(process.cwd(), file) || file}`);\n }\n console.log(\"\");\n }\n\n return result;\n } catch (err) {\n spinner.fail(err instanceof Error ? err.message : String(err));\n process.exit(1);\n }\n}\n\nexport const convertEcfrCommand = new Command(\"convert-ecfr\")\n .description(\"Convert eCFR XML file(s) to Markdown\")\n .argument(\"[input]\", \"Path to an eCFR XML file\")\n .option(\"-o, --output <dir>\", \"Output directory\", \"./output\")\n .option(\"--titles <spec>\", \"Title(s) to convert: 1, 1-5, or 1-5,17\")\n .option(\"--all\", \"Convert all downloaded eCFR titles found in --input-dir\", false)\n .option(\"-i, --input-dir <dir>\", \"Directory containing eCFR XML files\", \"./downloads/ecfr/xml\")\n .addOption(\n new Option(\"-g, --granularity <level>\", \"Output granularity: section, part, chapter, or title\")\n .choices([\"section\", \"part\", \"chapter\", \"title\"])\n .default(\"section\"),\n )\n .addOption(\n new Option(\"--link-style <style>\", \"Link style: relative, canonical, or plaintext\")\n .choices([\"relative\", \"canonical\", \"plaintext\"])\n .default(\"plaintext\"),\n )\n .option(\"--include-source-credits\", \"Include source credit annotations\", true)\n .option(\"--no-include-source-credits\", \"Exclude source credit annotations\")\n .option(\"--include-notes\", \"Include all notes (default)\", true)\n .option(\"--no-include-notes\", \"Exclude all notes\")\n .option(\"--include-editorial-notes\", \"Include editorial notes only\", false)\n .option(\"--include-statutory-notes\", \"Include statutory/regulatory notes only\", false)\n .option(\"--include-amendments\", \"Include amendment history notes only\", false)\n .option(\"--dry-run\", \"Parse and report structure without writing files\", false)\n .option(\"-v, --verbose\", \"Enable verbose logging\", false)\n .addHelpText(\n \"after\",\n `\nInput modes (use exactly one):\n <input> Convert a single eCFR XML file\n --titles Convert specific titles by number\n --all Convert all titles in --input-dir\n\nGranularity:\n section One .md file per section (default)\n part One .md file per part, sections inlined\n chapter One .md file per chapter, parts and sections inlined\n title One .md file per title, entire hierarchy inlined\n\nExamples:\n $ lexbuild convert-ecfr --titles 1 Convert eCFR Title 1\n $ lexbuild convert-ecfr --titles 1-5,17 Convert specific titles\n $ lexbuild convert-ecfr --all -g part All titles, part-level\n $ lexbuild convert-ecfr --all --dry-run Preview stats only\n $ lexbuild convert-ecfr ./downloads/ecfr/xml/ECFR-title1.xml -o ./out`,\n )\n .action(async (input: string | undefined, options: ConvertEcfrCommandOptions) => {\n const modeCount = [input, options.titles, options.all].filter(Boolean).length;\n if (modeCount === 0) {\n console.error(\n error(\"Specify an input file, --titles <spec>, or --all (e.g. --titles 1-5,17)\"),\n );\n process.exit(1);\n }\n if (modeCount > 1) {\n console.error(error(\"Cannot combine <input>, --titles, and --all — use only one\"));\n process.exit(1);\n }\n\n const outputPath = resolve(options.output);\n const dryRunLabel = options.dryRun ? \" [dry-run]\" : \"\";\n\n // Single-file mode\n if (input) {\n const inputPath = resolve(input);\n if (!existsSync(inputPath)) {\n console.error(error(`Input file not found: ${inputPath}`));\n process.exit(1);\n }\n await convertSingleFile(inputPath, outputPath, options, `Converting eCFR${dryRunLabel}...`);\n return;\n }\n\n // Multi-title mode\n let titles: number[];\n if (options.all) {\n const inputDir = resolve(options.inputDir);\n titles = discoverEcfrTitles(inputDir);\n if (titles.length === 0) {\n console.error(error(`No eCFR XML files found in ${inputDir}`));\n process.exit(1);\n }\n } else {\n const titlesSpec = options.titles as string;\n try {\n titles = parseTitles(titlesSpec, 50);\n } catch (err) {\n console.error(error(err instanceof Error ? err.message : String(err)));\n process.exit(1);\n }\n }\n\n const inputDir = resolve(options.inputDir);\n const totalTitles = titles.length;\n const results: ConversionRun[] = [];\n\n const spinner = createSpinner(`Converting eCFR${dryRunLabel}...`);\n spinner.start();\n\n for (const [i, titleNum] of titles.entries()) {\n const xmlPath = titleXmlPath(inputDir, titleNum);\n\n if (!existsSync(xmlPath)) {\n spinner.stop();\n console.error(error(`XML file not found: ${xmlPath}`));\n process.exit(1);\n }\n\n spinner.text = `Converting eCFR Title ${titleNum}${dryRunLabel} (${i + 1}/${totalTitles})...`;\n\n try {\n const run = await runConversion(xmlPath, outputPath, options);\n results.push(run);\n } catch (err) {\n spinner.fail(err instanceof Error ? err.message : String(err));\n process.exit(1);\n }\n }\n\n spinner.stop();\n\n const outputRelative = relative(process.cwd(), outputPath) || outputPath;\n const headerTitle = options.dryRun\n ? \"lexbuild — eCFR Conversion Summary [dry-run]\"\n : \"lexbuild — eCFR Conversion Summary\";\n const header = summaryBlock({\n title: headerTitle,\n rows: [[\"Directory\", outputRelative]],\n });\n process.stdout.write(header);\n\n const granularity = options.granularity;\n let totalSections = 0;\n let totalParts = 0;\n let totalTokens = 0;\n let totalElapsed = 0;\n\n const tableRows = results.map(({ result, elapsed }) => {\n totalSections += result.sectionsWritten;\n totalParts += result.partCount;\n totalTokens += result.totalTokenEstimate;\n totalElapsed += elapsed;\n\n if (granularity === \"title\") {\n return [\n result.titleNumber,\n result.titleName,\n formatNumber(result.totalTokenEstimate),\n formatDuration(elapsed),\n ];\n } else if (granularity === \"chapter\") {\n return [\n result.titleNumber,\n result.titleName,\n formatNumber(result.sectionsWritten),\n formatNumber(result.totalTokenEstimate),\n formatDuration(elapsed),\n ];\n } else if (granularity === \"part\") {\n return [\n result.titleNumber,\n result.titleName,\n formatNumber(result.partCount),\n formatNumber(result.totalTokenEstimate),\n formatDuration(elapsed),\n ];\n } else {\n return [\n result.titleNumber,\n result.titleName,\n formatNumber(result.partCount),\n formatNumber(result.sectionsWritten),\n formatNumber(result.totalTokenEstimate),\n formatDuration(elapsed),\n ];\n }\n });\n\n if (granularity === \"title\") {\n tableRows.push([\n chalk.bold(\"Total\"),\n \"\",\n chalk.bold(formatNumber(totalTokens)),\n chalk.bold(formatDuration(totalElapsed)),\n ]);\n } else if (granularity === \"chapter\") {\n tableRows.push([\n chalk.bold(\"Total\"),\n \"\",\n chalk.bold(formatNumber(totalSections)),\n chalk.bold(formatNumber(totalTokens)),\n chalk.bold(formatDuration(totalElapsed)),\n ]);\n } else if (granularity === \"part\") {\n tableRows.push([\n chalk.bold(\"Total\"),\n \"\",\n chalk.bold(formatNumber(totalParts)),\n chalk.bold(formatNumber(totalTokens)),\n chalk.bold(formatDuration(totalElapsed)),\n ]);\n } else {\n tableRows.push([\n chalk.bold(\"Total\"),\n \"\",\n chalk.bold(formatNumber(totalParts)),\n chalk.bold(formatNumber(totalSections)),\n chalk.bold(formatNumber(totalTokens)),\n chalk.bold(formatDuration(totalElapsed)),\n ]);\n }\n\n const tableHeaders =\n granularity === \"title\"\n ? [\"Title\", \"Name\", \"Tokens\", \"Duration\"]\n : granularity === \"chapter\"\n ? [\"Title\", \"Name\", \"Chapters\", \"Tokens\", \"Duration\"]\n : granularity === \"part\"\n ? [\"Title\", \"Name\", \"Parts\", \"Tokens\", \"Duration\"]\n : [\"Title\", \"Name\", \"Parts\", \"Sections\", \"Tokens\", \"Duration\"];\n\n console.log(dataTable(tableHeaders, tableRows));\n\n // Footer — show the primary unit that was converted\n let countLabel: string;\n if (granularity === \"title\") {\n const titleWord = totalTitles === 1 ? \"title\" : \"titles\";\n countLabel = `${formatNumber(totalTitles)} ${titleWord}`;\n } else if (granularity === \"chapter\") {\n const chapterWord = totalSections === 1 ? \"chapter\" : \"chapters\";\n countLabel = `${formatNumber(totalSections)} ${chapterWord}`;\n } else if (granularity === \"part\") {\n const partWord = totalParts === 1 ? \"part\" : \"parts\";\n countLabel = `${formatNumber(totalParts)} ${partWord}`;\n } else {\n const sectionWord = totalSections === 1 ? \"section\" : \"sections\";\n countLabel = `${formatNumber(totalSections)} ${sectionWord}`;\n }\n console.log(`\\n ${success(`Converted ${countLabel} in ${formatDuration(totalElapsed)}`)}`);\n console.log(\"\");\n });\n","/**\n * `lexbuild download-ecfr` command — downloads eCFR XML from govinfo or eCFR API.\n */\n\nimport { Command } from \"commander\";\nimport { relative, resolve } from \"node:path\";\nimport { downloadEcfrTitles, downloadEcfrTitlesFromApi, fetchEcfrTitlesMeta } from \"@lexbuild/ecfr\";\nimport type { EcfrTitlesResponse } from \"@lexbuild/ecfr\";\nimport {\n createSpinner,\n summaryBlock,\n dataTable,\n formatDuration,\n formatBytes,\n success,\n error,\n} from \"../ui.js\";\nimport { parseTitles } from \"../parse-titles.js\";\n\n/** Valid download source values */\ntype EcfrSource = \"govinfo\" | \"ecfr-api\";\n\n/** Parsed options from the download-ecfr command */\ninterface DownloadEcfrOptions {\n output: string;\n titles?: string | undefined;\n all: boolean;\n source: EcfrSource;\n date?: string | undefined;\n}\n\nexport const downloadEcfrCommand = new Command(\"download-ecfr\")\n .description(\"Download eCFR XML from govinfo or eCFR API\")\n .option(\"-o, --output <dir>\", \"Download directory\", \"./downloads/ecfr/xml\")\n .option(\"--titles <spec>\", \"Title(s) to download: 1, 1-5, or 1-5,8,17\")\n .option(\"--all\", \"Download all 50 eCFR titles\", false)\n .option(\n \"--source <source>\",\n \"Download source: ecfr-api (daily-updated) or govinfo (bulk data)\",\n \"ecfr-api\",\n )\n .option(\"--date <YYYY-MM-DD>\", \"Point-in-time date (ecfr-api source only)\")\n .addHelpText(\n \"after\",\n `\nExamples:\n $ lexbuild download-ecfr --all Download all titles from eCFR API\n $ lexbuild download-ecfr --titles 1 Download Title 1 only\n $ lexbuild download-ecfr --titles 1-5,17 Download specific titles\n $ lexbuild download-ecfr --all --date 2026-01-01 Point-in-time download\n $ lexbuild download-ecfr --all --source govinfo Download from govinfo bulk data\n\nSources:\n ecfr-api — eCFR API from ecfr.gov (default, daily-updated, point-in-time support)\n govinfo — Bulk XML from govinfo.gov (updates irregularly)`,\n )\n .action(async (options: DownloadEcfrOptions) => {\n if (!options.titles && !options.all) {\n console.error(error(\"Specify --titles <spec> or --all (e.g. --titles 1-5,17)\"));\n process.exit(1);\n }\n\n // Validate source\n const validSources: EcfrSource[] = [\"govinfo\", \"ecfr-api\"];\n if (!validSources.includes(options.source)) {\n console.error(\n error(`Invalid source \"${options.source}\". Valid sources: ${validSources.join(\", \")}`),\n );\n process.exit(1);\n }\n\n // --date is only valid with ecfr-api source\n if (options.date && options.source !== \"ecfr-api\") {\n console.error(error(\"--date is only supported with --source ecfr-api\"));\n process.exit(1);\n }\n\n // Validate date format if provided\n if (options.date && !/^\\d{4}-\\d{2}-\\d{2}$/.test(options.date)) {\n console.error(error(\"--date must be in YYYY-MM-DD format\"));\n process.exit(1);\n }\n\n let titles: number[] | undefined;\n if (options.titles) {\n try {\n titles = parseTitles(options.titles, 50);\n } catch (err) {\n console.error(error(err instanceof Error ? err.message : String(err)));\n process.exit(1);\n }\n }\n\n const outputDir = resolve(options.output);\n const titleCount = titles ? titles.length : 50;\n const sourceLabel = options.source === \"ecfr-api\" ? \"eCFR API\" : \"govinfo\";\n\n // For ecfr-api, fetch metadata upfront to resolve dates and display status\n let meta: EcfrTitlesResponse | undefined;\n if (options.source === \"ecfr-api\" && !options.date) {\n const metaSpinner = createSpinner(\"Fetching eCFR title metadata...\");\n metaSpinner.start();\n try {\n meta = await fetchEcfrTitlesMeta();\n metaSpinner.succeed(\"eCFR title metadata loaded\");\n } catch (err) {\n metaSpinner.fail(err instanceof Error ? err.message : String(err));\n process.exit(1);\n }\n }\n\n // Build spinner label with date info\n let dateLabel = \"\";\n let statusNote = \"\";\n if (options.date) {\n dateLabel = ` as of ${options.date}`;\n } else if (meta) {\n const primaryDate = meta.importInProgress\n ? (() => {\n const prev = new Date(meta.date);\n prev.setDate(prev.getDate() - 1);\n return prev.toISOString().slice(0, 10);\n })()\n : meta.date;\n dateLabel = ` as of ${primaryDate}`;\n\n // Check for titles with individual processing\n const processingTitles = meta.titles.filter((t) => t.processingInProgress && !t.reserved);\n if (meta.importInProgress && processingTitles.length > 0) {\n const titleWord = processingTitles.length === 1 ? \"title uses\" : \"titles use\";\n statusNote = ` (import in progress, ${processingTitles.length} ${titleWord} earlier dates)`;\n } else if (meta.importInProgress) {\n statusNote = \" (import in progress, using previous day)\";\n } else if (processingTitles.length > 0) {\n const nums = processingTitles.map((t) => t.number).join(\", \");\n statusNote = ` (Title ${nums} processing, using earlier date)`;\n }\n }\n\n const label =\n titleCount === 1\n ? `Downloading eCFR Title ${titles?.[0]} from ${sourceLabel}${dateLabel}${statusNote}`\n : `Downloading ${titleCount} eCFR titles from ${sourceLabel}${dateLabel}${statusNote}`;\n\n const spinner = createSpinner(`${label}...`);\n spinner.start();\n\n const startTime = performance.now();\n\n try {\n if (options.source === \"ecfr-api\") {\n await downloadFromApi(options, titles, outputDir, spinner, startTime, meta);\n } else {\n await downloadFromGovinfo(titles, outputDir, spinner, startTime);\n }\n } catch (err) {\n spinner.fail(err instanceof Error ? err.message : String(err));\n process.exit(1);\n }\n });\n\n/** Download from govinfo bulk data (existing behavior) */\nasync function downloadFromGovinfo(\n titles: number[] | undefined,\n outputDir: string,\n spinner: ReturnType<typeof createSpinner>,\n startTime: number,\n): Promise<void> {\n const result = await downloadEcfrTitles({\n output: outputDir,\n titles,\n onProgress: ({ current, total, titleNumber }) => {\n if (total === 1) {\n spinner.text = `Downloading eCFR Title ${titleNumber} from govinfo`;\n } else {\n spinner.text = `Downloading eCFR titles from govinfo (${current}/${total}) — Title ${titleNumber}`;\n }\n },\n });\n\n const elapsed = performance.now() - startTime;\n spinner.stop();\n\n const fileRows = result.files.map((file) => [\n String(file.titleNumber),\n formatBytes(file.size),\n relative(outputDir, file.path) || file.path,\n ]);\n\n const output = summaryBlock({\n title: \"lexbuild — eCFR Download Summary\",\n rows: [\n [\"Source\", \"govinfo.gov/bulkdata/ECFR\"],\n [\"Directory\", relative(process.cwd(), outputDir) || outputDir],\n ],\n });\n process.stdout.write(output);\n\n if (fileRows.length > 0) {\n console.log(dataTable([\"Title\", \"Size\", \"File\"], fileRows));\n }\n\n if (result.errors.length > 0) {\n for (const err of result.errors) {\n console.log(` ${error(`Title ${err.titleNumber}: ${err.error}`)}`);\n }\n }\n\n const titleWord = result.titlesDownloaded === 1 ? \"title\" : \"titles\";\n const failSuffix = result.errors.length > 0 ? ` (${result.errors.length} failed)` : \"\";\n const summary = `Downloaded ${result.titlesDownloaded} ${titleWord} (${formatBytes(result.totalBytes)}) in ${formatDuration(elapsed)}`;\n console.log(` ${success(summary + failSuffix)}`);\n console.log(\"\");\n}\n\n/** Download from eCFR API (daily-updated, point-in-time) */\nasync function downloadFromApi(\n options: DownloadEcfrOptions,\n titles: number[] | undefined,\n outputDir: string,\n spinner: ReturnType<typeof createSpinner>,\n startTime: number,\n meta?: EcfrTitlesResponse,\n): Promise<void> {\n const result = await downloadEcfrTitlesFromApi({\n output: outputDir,\n titles,\n date: options.date,\n titlesMeta: meta,\n onProgress: ({ current, total, titleNumber }) => {\n if (total === 1) {\n spinner.text = `Downloading eCFR Title ${titleNumber} from eCFR API`;\n } else {\n spinner.text = `Downloading eCFR titles from eCFR API (${current}/${total}) — Title ${titleNumber}`;\n }\n },\n });\n\n const elapsed = performance.now() - startTime;\n spinner.stop();\n\n // Check if any titles used different dates\n const uniqueDates = new Set(result.files.map((f) => f.asOfDate));\n const dateDisplay =\n uniqueDates.size <= 1\n ? result.asOfDate\n : `${result.asOfDate} (${uniqueDates.size - 1} titles at earlier dates)`;\n\n const fileRows = result.files.map((file) => {\n const row = [\n String(file.titleNumber),\n formatBytes(file.size),\n relative(outputDir, file.path) || file.path,\n ];\n // Show the date if it differs from the primary\n if (file.asOfDate !== result.asOfDate) {\n row.push(file.asOfDate);\n }\n return row;\n });\n\n const summaryRows: [string, string][] = [\n [\"Source\", \"ecfr.gov/api/versioner/v1\"],\n [\"As of date\", dateDisplay],\n [\"Directory\", relative(process.cwd(), outputDir) || outputDir],\n ];\n\n const output = summaryBlock({\n title: \"lexbuild — eCFR Download Summary\",\n rows: summaryRows,\n });\n process.stdout.write(output);\n\n // Include date column only if some titles used different dates\n const hasMultipleDates = uniqueDates.size > 1;\n const headings = hasMultipleDates ? [\"Title\", \"Size\", \"File\", \"Date\"] : [\"Title\", \"Size\", \"File\"];\n\n if (fileRows.length > 0) {\n console.log(dataTable(headings, fileRows));\n }\n\n // Report failures with context\n if (result.failed.length > 0) {\n const processing = result.failed.filter((f) => f.status === 503);\n const other = result.failed.filter((f) => f.status !== 503);\n\n if (processing.length > 0) {\n const nums = processing.map((f) => `Title ${f.titleNumber}`).join(\", \");\n console.log(` ${error(`Unavailable (processing on server): ${nums}`)}`);\n console.log(` The eCFR API cannot serve these titles while an import is in progress.`);\n console.log(\n ` Re-run this command later to download them. Existing local files (if any) are preserved.`,\n );\n }\n if (other.length > 0) {\n const nums = other.map((f) => `Title ${f.titleNumber} (${f.status})`).join(\", \");\n console.log(` ${error(`Failed: ${nums}`)}`);\n }\n }\n\n const titleWord = result.titlesDownloaded === 1 ? \"title\" : \"titles\";\n const failSuffix = result.failed.length > 0 ? ` (${result.failed.length} failed)` : \"\";\n const summary = `Downloaded ${result.titlesDownloaded} ${titleWord} (${formatBytes(result.totalBytes)}) in ${formatDuration(elapsed)}`;\n console.log(` ${success(summary + failSuffix)}`);\n console.log(\"\");\n}\n","/**\n * `lexbuild download-fr` command — downloads Federal Register XML + JSON from the API.\n */\n\nimport { Command } from \"commander\";\nimport { relative, resolve } from \"node:path\";\nimport { downloadFrDocuments, downloadSingleFrDocument } from \"@lexbuild/fr\";\nimport type { FrDocumentType } from \"@lexbuild/fr\";\nimport {\n createSpinner,\n summaryBlock,\n formatDuration,\n formatBytes,\n formatNumber,\n error,\n} from \"../ui.js\";\n\n/** Valid document type values for --types flag */\nconst VALID_TYPES = new Map<string, FrDocumentType>([\n [\"rule\", \"RULE\"],\n [\"proposed_rule\", \"PRORULE\"],\n [\"notice\", \"NOTICE\"],\n [\"presidential_document\", \"PRESDOCU\"],\n]);\n\n/** Parsed options from the download-fr command */\ninterface DownloadFrOptions {\n output: string;\n from?: string | undefined;\n to?: string | undefined;\n types?: string | undefined;\n recent?: string | undefined;\n document?: string | undefined;\n limit?: string | undefined;\n}\n\nexport const downloadFrCommand = new Command(\"download-fr\")\n .description(\"Download Federal Register XML and metadata from federalregister.gov\")\n .option(\"-o, --output <dir>\", \"Download directory\", \"./downloads/fr\")\n .option(\"--from <YYYY-MM-DD>\", \"Start date (inclusive)\")\n .option(\"--to <YYYY-MM-DD>\", \"End date (inclusive, defaults to today)\")\n .option(\"--types <types>\", \"Document types: rule, proposed_rule, notice, presidential_document\")\n .option(\"--recent <days>\", \"Download last N days\")\n .option(\"--document <number>\", \"Download a single document by number\")\n .option(\"--limit <n>\", \"Maximum number of documents (for testing)\")\n .addHelpText(\n \"after\",\n `\nExamples:\n $ lexbuild download-fr --from 2026-01-01 --to 2026-03-31\n $ lexbuild download-fr --from 2026-01-01 --types rule,proposed_rule\n $ lexbuild download-fr --recent 30\n $ lexbuild download-fr --document 2026-06029\n\nDocument types:\n rule Final rules\n proposed_rule Proposed rules (NPRMs)\n notice Notices\n presidential_document Executive orders, memoranda, proclamations`,\n )\n .action(async (options: DownloadFrOptions) => {\n // Validate: need --from, --recent, or --document\n if (!options.from && !options.recent && !options.document) {\n console.error(\n error(\n \"Specify --from <date>, --recent <days>, or --document <number>\\n\" +\n \"Examples: --from 2026-01-01, --recent 30, --document 2026-06029\",\n ),\n );\n process.exit(1);\n }\n\n // Validate date format\n if (options.from && !/^\\d{4}-\\d{2}-\\d{2}$/.test(options.from)) {\n console.error(error(\"--from must be in YYYY-MM-DD format\"));\n process.exit(1);\n }\n if (options.to && !/^\\d{4}-\\d{2}-\\d{2}$/.test(options.to)) {\n console.error(error(\"--to must be in YYYY-MM-DD format\"));\n process.exit(1);\n }\n\n // Parse --types\n let types: FrDocumentType[] | undefined;\n if (options.types) {\n types = [];\n for (const raw of options.types.split(\",\")) {\n const normalized = raw.trim().toLowerCase();\n const mapped = VALID_TYPES.get(normalized);\n if (!mapped) {\n console.error(\n error(\n `Invalid document type \"${raw.trim()}\". Valid types: ${[...VALID_TYPES.keys()].join(\", \")}`,\n ),\n );\n process.exit(1);\n }\n types.push(mapped);\n }\n }\n\n const outputDir = resolve(options.output);\n const startTime = performance.now();\n\n // ── Single document mode ──\n if (options.document) {\n const spinner = createSpinner(`Downloading FR document ${options.document}`);\n try {\n const file = await downloadSingleFrDocument(options.document, outputDir);\n spinner.succeed(`Downloaded FR document ${options.document}`);\n console.log();\n console.log(\n summaryBlock({\n title: \"Download Complete\",\n rows: [\n [\"Document\", file.documentNumber],\n [\"Date\", file.publicationDate],\n [\"Size\", formatBytes(file.size)],\n [\"XML\", relative(process.cwd(), file.xmlPath)],\n [\"JSON\", relative(process.cwd(), file.jsonPath)],\n ],\n }),\n );\n } catch (err) {\n spinner.fail(`Failed to download ${options.document}`);\n console.error(error(err instanceof Error ? err.message : String(err)));\n process.exit(1);\n }\n return;\n }\n\n // ── Date range mode ──\n let from: string;\n if (options.recent) {\n const days = parseInt(options.recent, 10);\n if (isNaN(days) || days <= 0) {\n console.error(error(\"--recent must be a positive integer\"));\n process.exit(1);\n }\n const d = new Date();\n d.setDate(d.getDate() - days);\n from = d.toISOString().slice(0, 10);\n } else {\n // Validated above: options.from is defined at this point\n from = options.from ?? \"\";\n }\n\n const to = options.to ?? new Date().toISOString().slice(0, 10);\n let limit: number | undefined;\n if (options.limit) {\n limit = parseInt(options.limit, 10);\n if (isNaN(limit) || limit <= 0) {\n console.error(error(\"--limit must be a positive integer\"));\n process.exit(1);\n }\n }\n\n const spinner = createSpinner(`Downloading Federal Register documents from ${from} to ${to}`);\n\n try {\n const result = await downloadFrDocuments({\n output: outputDir,\n from,\n to,\n types,\n limit,\n onProgress: (progress) => {\n const pct = progress.totalDocuments > 0\n ? Math.round((progress.documentsDownloaded / progress.totalDocuments) * 100)\n : 0;\n spinner.text = `Downloading FR documents (${formatNumber(progress.documentsDownloaded)}/${formatNumber(progress.totalDocuments)}) ${pct}% — ${progress.currentDocument}`;\n },\n });\n\n const elapsed = performance.now() - startTime;\n spinner.succeed(\n `Downloaded ${formatNumber(result.documentsDownloaded)} Federal Register documents`,\n );\n\n console.log();\n const rows: [string, string][] = [\n [\"Date range\", `${result.dateRange.from} → ${result.dateRange.to}`],\n [\"Documents\", formatNumber(result.documentsDownloaded)],\n [\"Total size\", formatBytes(result.totalBytes)],\n [\"Duration\", formatDuration(elapsed)],\n ];\n if (types) {\n rows.push([\"Types\", types.join(\", \")]);\n }\n if (result.skipped > 0) {\n rows.push([\"Skipped (no XML)\", formatNumber(result.skipped)]);\n }\n if (result.failed.length > 0) {\n rows.push([\"Failed\", formatNumber(result.failed.length)]);\n }\n rows.push([\"Output\", relative(process.cwd(), outputDir)]);\n\n console.log(summaryBlock({ title: \"Download Complete\", rows }));\n\n if (result.failed.length > 0) {\n console.log();\n console.log(error(`${result.failed.length} document(s) failed to download:`));\n for (const f of result.failed.slice(0, 10)) {\n console.error(` ${f.documentNumber}: ${f.error}`);\n }\n if (result.failed.length > 10) {\n console.error(` ... and ${result.failed.length - 10} more`);\n }\n }\n } catch (err) {\n spinner.fail(\"Download failed\");\n console.error(error(err instanceof Error ? err.message : String(err)));\n process.exit(1);\n }\n });\n","/**\n * `lexbuild convert-fr` command — converts Federal Register XML files to Markdown.\n */\n\nimport { Command } from \"commander\";\nimport { existsSync } from \"node:fs\";\nimport { relative, resolve } from \"node:path\";\nimport { convertFrDocuments } from \"@lexbuild/fr\";\nimport type { FrDocumentType } from \"@lexbuild/fr\";\nimport {\n createSpinner,\n summaryBlock,\n formatDuration,\n formatNumber,\n error,\n} from \"../ui.js\";\n\n/** Valid document type values for --types flag */\nconst VALID_TYPES = new Map<string, FrDocumentType>([\n [\"rule\", \"RULE\"],\n [\"proposed_rule\", \"PRORULE\"],\n [\"notice\", \"NOTICE\"],\n [\"presidential_document\", \"PRESDOCU\"],\n]);\n\n/** Parsed options from the convert-fr command */\ninterface ConvertFrCommandOptions {\n output: string;\n inputDir: string;\n all: boolean;\n from?: string | undefined;\n to?: string | undefined;\n types?: string | undefined;\n linkStyle: \"relative\" | \"canonical\" | \"plaintext\";\n dryRun: boolean;\n verbose: boolean;\n}\n\nexport const convertFrCommand = new Command(\"convert-fr\")\n .description(\"Convert Federal Register XML to Markdown\")\n .argument(\"[input]\", \"Path to single FR XML file (optional)\")\n .option(\"-o, --output <dir>\", \"Output directory\", \"./output\")\n .option(\"-i, --input-dir <dir>\", \"Directory containing downloaded FR files\", \"./downloads/fr\")\n .option(\"--all\", \"Convert all downloaded documents in input directory\", false)\n .option(\"--from <YYYY-MM-DD>\", \"Filter: start date\")\n .option(\"--to <YYYY-MM-DD>\", \"Filter: end date\")\n .option(\"--types <types>\", \"Filter: document types (rule, proposed_rule, notice, presidential_document)\")\n .option(\"--link-style <style>\", \"Link style: relative, canonical, plaintext\", \"plaintext\")\n .option(\"--dry-run\", \"Parse only, don't write files\", false)\n .option(\"-v, --verbose\", \"Print detailed file output\", false)\n .addHelpText(\n \"after\",\n `\nExamples:\n $ lexbuild convert-fr --all Convert all downloaded FR documents\n $ lexbuild convert-fr --from 2026-01-01 --to 2026-03-31 Convert by date range\n $ lexbuild convert-fr --all --types rule Convert only rules\n $ lexbuild convert-fr ./downloads/fr/2026/03/2026-06029.xml Convert single document\n $ lexbuild convert-fr --all --dry-run Preview without writing files`,\n )\n .action(async (inputArg: string | undefined, options: ConvertFrCommandOptions) => {\n // Validate: need [input], --all, or --from\n if (!inputArg && !options.all && !options.from) {\n console.error(\n error(\n \"Specify a path to an XML file, --all, or --from <date>\\n\" +\n \"Examples: convert-fr --all, convert-fr --from 2026-01-01\",\n ),\n );\n process.exit(1);\n }\n\n // Parse --types\n let types: FrDocumentType[] | undefined;\n if (options.types) {\n types = [];\n for (const raw of options.types.split(\",\")) {\n const normalized = raw.trim().toLowerCase();\n const mapped = VALID_TYPES.get(normalized);\n if (!mapped) {\n console.error(\n error(\n `Invalid document type \"${raw.trim()}\". Valid types: ${[...VALID_TYPES.keys()].join(\", \")}`,\n ),\n );\n process.exit(1);\n }\n types.push(mapped);\n }\n }\n\n // Determine input path\n let inputPath: string;\n if (inputArg) {\n inputPath = resolve(inputArg);\n if (!existsSync(inputPath)) {\n console.error(error(`File not found: ${inputArg}`));\n process.exit(1);\n }\n } else {\n inputPath = resolve(options.inputDir);\n if (!existsSync(inputPath)) {\n console.error(error(`Input directory not found: ${options.inputDir}`));\n process.exit(1);\n }\n }\n\n const outputPath = resolve(options.output);\n const startTime = performance.now();\n\n const spinner = createSpinner(\n options.dryRun\n ? \"Analyzing Federal Register documents (dry run)\"\n : \"Converting Federal Register documents\",\n );\n\n try {\n const result = await convertFrDocuments({\n input: inputPath,\n output: outputPath,\n linkStyle: options.linkStyle,\n dryRun: options.dryRun,\n from: options.from,\n to: options.to,\n types,\n });\n\n const elapsed = performance.now() - startTime;\n\n if (options.dryRun) {\n spinner.succeed(\n `Dry run: ${formatNumber(result.documentsConverted)} documents would be converted`,\n );\n } else {\n spinner.succeed(\n `Converted ${formatNumber(result.documentsConverted)} Federal Register documents`,\n );\n }\n\n console.log();\n\n const rows: [string, string][] = [\n [\"Documents\", formatNumber(result.documentsConverted)],\n ];\n\n if (!options.dryRun) {\n rows.push([\"Est. tokens\", formatNumber(result.totalTokenEstimate)]);\n }\n\n rows.push([\"Duration\", formatDuration(elapsed)]);\n\n if (!options.dryRun) {\n rows.push([\"Output\", relative(process.cwd(), outputPath) + \"/fr/\"]);\n }\n\n const footer = options.dryRun\n ? undefined\n : `Converted ${formatNumber(result.documentsConverted)} documents in ${formatDuration(elapsed)}`;\n\n console.log(summaryBlock({ title: \"Conversion Complete\", rows, footer }));\n\n if (options.verbose && !options.dryRun) {\n console.log();\n for (const file of result.files.slice(0, 20)) {\n console.log(` ${relative(process.cwd(), file)}`);\n }\n if (result.files.length > 20) {\n console.log(` ... and ${result.files.length - 20} more`);\n }\n }\n } catch (err) {\n spinner.fail(\"Conversion failed\");\n console.error(error(err instanceof Error ? err.message : String(err)));\n process.exit(1);\n }\n });\n"],"mappings":";;;AAEA,SAAS,qBAAqB;AAC9B,SAAS,WAAAA,gBAAe;;;ACCxB,OAAOC,YAAW;AAClB,SAAS,SAAS,cAAc;AAChC,SAAS,YAAY,mBAAmB;AACxC,SAAS,UAAU,SAAS,MAAM,UAAU,eAAe;AAC3D,SAAS,oBAAoB;;;ACJ7B,OAAO,WAAW;AAClB,OAAO,SAAS;AAEhB,OAAO,WAAW;AAGX,SAAS,cAAc,MAAmB;AAC/C,SAAO,IAAI,EAAE,MAAM,SA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+DAA+D;AAC7E,YAAQ,MAAM,0DAA0D;AACxE,YAAQ,MAAM,sEAAsE;AACpF,YAAQ,MAAM,EAAE;AAChB,YAAQ,KAAK,CAAC;AAAA,EAChB,CAAC;AACL;AAEA,QAAQ,MAAM;","names":["Command","chalk","inputDir","chalk","Command","relative","resolve","Command","resolve","relative","Command","detectLatestReleasePoint","FALLBACK_RELEASE_POINT","Command","detectLatestReleasePoint","FALLBACK_RELEASE_POINT","chalk","Command","Option","existsSync","readdirSync","join","relative","resolve","buildConvertOptions","titleXmlPath","join","existsSync","readdirSync","runConversion","convertSingleFile","relative","Command","Option","resolve","inputDir","chalk","Command","relative","resolve","Command","resolve","relative","Command","relative","resolve","Command","resolve","spinner","relative","Command","existsSync","relative","resolve","VALID_TYPES","Command","resolve","existsSync","relative","require","Command"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lexbuild/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"description": "Compiler for legal and civic texts. Converts disparate statutory data into structured formats optimized for AI, RAG, and semantic search.",
|
|
5
5
|
"author": "Chris Thomas",
|
|
6
6
|
"license": "MIT",
|
|
@@ -52,8 +52,9 @@
|
|
|
52
52
|
"cli-table3": "^0.6.5",
|
|
53
53
|
"commander": "^13.1.0",
|
|
54
54
|
"ora": "^8.2.0",
|
|
55
|
-
"@lexbuild/ecfr": "1.
|
|
56
|
-
"@lexbuild/
|
|
55
|
+
"@lexbuild/ecfr": "1.14.0",
|
|
56
|
+
"@lexbuild/fr": "1.14.0",
|
|
57
|
+
"@lexbuild/usc": "1.14.0"
|
|
57
58
|
},
|
|
58
59
|
"devDependencies": {
|
|
59
60
|
"@types/node": "^25.3.2",
|