@lexbuild/cli 1.7.0 → 1.9.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 CHANGED
@@ -4,9 +4,9 @@
4
4
  [![CI](https://img.shields.io/github/actions/workflow/status/chris-c-thomas/LexBuild/ci.yml?style=for-the-badge&label=CI)](https://github.com/chris-c-thomas/LexBuild/actions/workflows/ci.yml)
5
5
  [![license](https://img.shields.io/github/license/chris-c-thomas/LexBuild?style=for-the-badge)](https://github.com/chris-c-thomas/LexBuild)
6
6
 
7
- This package is part of the [LexBuild monorepo](https://github.com/chris-c-thomas/LexBuild), a tool that converts U.S. legislative XML into structured Markdown optimized for AI, RAG pipelines, and semantic search. See the monorepo for full documentation, architecture details, and contribution guidelines.
7
+ This package is part of the [LexBuild monorepo](https://github.com/chris-c-thomas/LexBuild), a tool that converts U.S. legal XML into structured Markdown optimized for AI, RAG pipelines, and semantic search. See the monorepo for full documentation, architecture details, and contribution guidelines.
8
8
 
9
- It provides the CLI entry point for downloading and converting legal and civic texts. Built on [`@lexbuild/core`](https://www.npmjs.com/package/@lexbuild/core) for shared parsing and rendering infrastructure, and also [`@lexbuild/usc`](https://www.npmjs.com/package/@lexbuild/usc) for [United States Code](https://uscode.house.gov/) support. Implementing support for additional sources (CFR, state statutes) is planned.
9
+ It provides the CLI entry point for downloading and converting legal texts. Built on [`@lexbuild/core`](https://www.npmjs.com/package/@lexbuild/core) for shared parsing and rendering infrastructure, [`@lexbuild/usc`](https://www.npmjs.com/package/@lexbuild/usc) for [United States Code](https://uscode.house.gov/) support, and [`@lexbuild/ecfr`](https://www.npmjs.com/package/@lexbuild/ecfr) for [eCFR](https://www.ecfr.gov/) (Code of Federal Regulations) support.
10
10
 
11
11
  ## Install
12
12
 
@@ -19,33 +19,47 @@ npm install -g @lexbuild/cli
19
19
  Run directly with npx:
20
20
 
21
21
  ```bash
22
- npx @lexbuild/cli download --all
23
- npx @lexbuild/cli convert --all
22
+ npx @lexbuild/cli download-usc --all
23
+ npx @lexbuild/cli convert-usc --all
24
24
  ```
25
25
 
26
26
  ## Quick Start
27
27
 
28
+ ### U.S. Code
29
+
28
30
  ```bash
29
31
  # Download and convert all 54 titles
30
- lexbuild download --all && lexbuild convert --all
32
+ lexbuild download-usc --all && lexbuild convert-usc --all
31
33
 
32
34
  # Start small — download and convert Title 1
33
- lexbuild download --titles 1 && lexbuild convert --titles 1
35
+ lexbuild download-usc --titles 1 && lexbuild convert-usc --titles 1
34
36
 
35
37
  # Download and convert a range
36
- lexbuild download --titles 1-5 && lexbuild convert --titles 1-5
38
+ lexbuild download-usc --titles 1-5 && lexbuild convert-usc --titles 1-5
39
+ ```
40
+
41
+ ### eCFR (Code of Federal Regulations)
42
+
43
+ ```bash
44
+ # Download and convert all 50 titles
45
+ lexbuild download-ecfr --all && lexbuild convert-ecfr --all
46
+
47
+ # Download and convert a single title
48
+ lexbuild download-ecfr --titles 17 && lexbuild convert-ecfr --titles 17
37
49
  ```
38
50
 
39
51
  ## Commands
40
52
 
41
- ### `lexbuild download`
53
+ ### U.S. Code
54
+
55
+ #### `lexbuild download-usc`
42
56
 
43
57
  Fetch U.S. Code XML files from the OLRC.
44
58
 
45
59
  ```bash
46
- lexbuild download --titles 1 # Single title
47
- lexbuild download --titles 1-5,8,11 # Range + specific titles
48
- lexbuild download --all # All 54 titles (single bulk zip)
60
+ lexbuild download-usc --titles 1 # Single title
61
+ lexbuild download-usc --titles 1-5,8,11 # Range + specific titles
62
+ lexbuild download-usc --all # All 54 titles (single bulk zip)
49
63
  ```
50
64
 
51
65
  | Option | Default | Description |
@@ -55,18 +69,18 @@ lexbuild download --all # All 54 titles (single bulk zip)
55
69
  | `-o, --output <dir>` | `./downloads/usc/xml` | Output directory |
56
70
  | `--release-point <id>` | current | OLRC release point |
57
71
 
58
- ### `lexbuild convert`
72
+ #### `lexbuild convert-usc`
59
73
 
60
- Convert downloaded XML to Markdown.
74
+ Convert downloaded USC XML to Markdown.
61
75
 
62
76
  ```bash
63
- lexbuild convert --titles 1 # By title number
64
- lexbuild convert --all # All downloaded titles
65
- lexbuild convert ./downloads/usc/xml/usc01.xml # Direct file path
66
- lexbuild convert --titles 1 -g chapter # Chapter-level output
67
- lexbuild convert --titles 1 -g title # Title-level output (single file)
68
- lexbuild convert --titles 1 --link-style canonical # OLRC website links
69
- lexbuild convert --titles 42 --dry-run # Preview without writing
77
+ lexbuild convert-usc --titles 1 # By title number
78
+ lexbuild convert-usc --all # All downloaded titles
79
+ lexbuild convert-usc ./downloads/usc/xml/usc01.xml # Direct file path
80
+ lexbuild convert-usc --titles 1 -g chapter # Chapter-level output
81
+ lexbuild convert-usc --titles 1 -g title # Title-level output (single file)
82
+ lexbuild convert-usc --titles 1 --link-style canonical # OLRC website links
83
+ lexbuild convert-usc --titles 42 --dry-run # Preview without writing
70
84
  ```
71
85
 
72
86
  | Option | Default | Description |
@@ -85,27 +99,73 @@ lexbuild convert --titles 42 --dry-run # Preview without writing
85
99
  | `--dry-run` | — | Parse and report without writing files |
86
100
  | `-v, --verbose` | — | Verbose logging |
87
101
 
88
- ## Output
102
+ ### eCFR (Code of Federal Regulations)
89
103
 
90
- **Section granularity** (default):
104
+ #### `lexbuild download-ecfr`
91
105
 
92
- ```
93
- output/usc/title-01/chapter-01/section-1.md
106
+ Fetch eCFR XML files from govinfo.
107
+
108
+ ```bash
109
+ lexbuild download-ecfr --titles 17 # Single title
110
+ lexbuild download-ecfr --titles 1-5,17 # Range + specific titles
111
+ lexbuild download-ecfr --all # All 50 titles
94
112
  ```
95
113
 
96
- **Chapter granularity** (`-g chapter`):
114
+ | Option | Default | Description |
115
+ |--------|---------|-------------|
116
+ | `--titles <spec>` | — | Title(s) to download: `1`, `1-5`, `1-5,17` |
117
+ | `--all` | — | Download all 50 titles |
118
+ | `-o, --output <dir>` | `./downloads/ecfr/xml` | Output directory |
97
119
 
98
- ```
99
- output/usc/title-01/chapter-01/chapter-01.md
100
- ```
120
+ #### `lexbuild convert-ecfr`
101
121
 
102
- **Title granularity** (`-g title`):
122
+ Convert downloaded eCFR XML to Markdown.
103
123
 
124
+ ```bash
125
+ lexbuild convert-ecfr --titles 17 # By title number
126
+ lexbuild convert-ecfr --all # All downloaded titles
127
+ lexbuild convert-ecfr ./downloads/ecfr/xml/ECFR-title17.xml # Direct file path
128
+ lexbuild convert-ecfr --titles 17 -g part # Part-level output
129
+ lexbuild convert-ecfr --titles 17 -g title # Title-level output
130
+ lexbuild convert-ecfr --all --dry-run # Preview without writing
104
131
  ```
105
- output/usc/title-01.md
106
- ```
107
132
 
108
- Each file includes YAML frontmatter (identifier, title, chapter, section, status, source credit) followed by the statutory text with bold inline numbering. Title-level output includes enriched frontmatter with `chapter_count`, `section_count`, and `total_token_estimate`.
133
+ | Option | Default | Description |
134
+ |--------|---------|-------------|
135
+ | `--titles <spec>` | — | Title(s) to convert |
136
+ | `--all` | — | Convert all titles in input directory |
137
+ | `-i, --input-dir <dir>` | `./downloads/ecfr/xml` | Input directory for XML files |
138
+ | `-o, --output <dir>` | `./output` | Output directory |
139
+ | `-g, --granularity <level>` | `section` | `section`, `part`, `chapter`, or `title` |
140
+ | `--link-style <style>` | `plaintext` | `plaintext`, `canonical`, or `relative` |
141
+ | `--no-include-source-credits` | — | Exclude source credits |
142
+ | `--no-include-notes` | — | Exclude all notes |
143
+ | `--include-editorial-notes` | — | Include editorial notes only |
144
+ | `--include-statutory-notes` | — | Include statutory/regulatory notes only |
145
+ | `--include-amendments` | — | Include amendment notes only |
146
+ | `--dry-run` | — | Parse and report without writing files |
147
+ | `-v, --verbose` | — | Verbose logging |
148
+
149
+ ## Output
150
+
151
+ ### U.S. Code
152
+
153
+ | Granularity | Example Path |
154
+ |---|---|
155
+ | `section` (default) | `output/usc/title-01/chapter-01/section-1.md` |
156
+ | `chapter` | `output/usc/title-01/chapter-01/chapter-01.md` |
157
+ | `title` | `output/usc/title-01.md` |
158
+
159
+ ### eCFR
160
+
161
+ | Granularity | Example Path |
162
+ |---|---|
163
+ | `section` (default) | `output/ecfr/title-17/chapter-IV/part-240/section-240.10b-5.md` |
164
+ | `part` | `output/ecfr/title-17/chapter-IV/part-240.md` |
165
+ | `chapter` | `output/ecfr/title-17/chapter-IV/chapter-IV.md` |
166
+ | `title` | `output/ecfr/title-17.md` |
167
+
168
+ Each file includes YAML frontmatter with source-specific metadata (`source`, `legal_status`, identifier, hierarchy context) followed by the legal text. Section and chapter/part granularities also generate `_meta.json` sidecar files and `README.md` summaries per title.
109
169
 
110
170
  ## Performance
111
171
 
package/dist/index.js CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  // src/index.ts
4
4
  import { createRequire } from "module";
5
- import { Command as Command3 } from "commander";
5
+ import { Command as Command5 } from "commander";
6
6
 
7
- // src/commands/convert.ts
7
+ // src/commands/convert-usc.ts
8
8
  import chalk2 from "chalk";
9
9
  import { Command, Option } from "commander";
10
10
  import { existsSync, readdirSync } from "fs";
@@ -125,7 +125,7 @@ function dataTable(head, rows) {
125
125
  }
126
126
 
127
127
  // src/parse-titles.ts
128
- function parseTitles(input) {
128
+ function parseTitles(input, maxTitle = 54) {
129
129
  const trimmed = input.trim();
130
130
  if (trimmed === "") {
131
131
  throw new Error("Title specification cannot be empty");
@@ -147,14 +147,14 @@ function parseTitles(input) {
147
147
  if (start > end) {
148
148
  throw new Error(`Invalid range: "${part}" (start ${start} must be \u2264 end ${end})`);
149
149
  }
150
- validateTitleNumber(start, input);
151
- validateTitleNumber(end, input);
150
+ validateTitleNumber(start, input, maxTitle);
151
+ validateTitleNumber(end, input, maxTitle);
152
152
  for (let i = start; i <= end; i++) {
153
153
  result.add(i);
154
154
  }
155
155
  } else {
156
156
  const num = parseIntStrict(part, input);
157
- validateTitleNumber(num, input);
157
+ validateTitleNumber(num, input, maxTitle);
158
158
  result.add(num);
159
159
  }
160
160
  }
@@ -167,13 +167,13 @@ function parseIntStrict(str, fullInput) {
167
167
  }
168
168
  return parseInt(trimmed, 10);
169
169
  }
170
- function validateTitleNumber(num, fullInput) {
171
- if (num < 1 || num > 54) {
172
- throw new Error(`Title number ${num} out of range (must be 1-54) in: "${fullInput}"`);
170
+ function validateTitleNumber(num, fullInput, max = 54) {
171
+ if (num < 1 || num > max) {
172
+ throw new Error(`Title number ${num} out of range (must be 1-${max}) in: "${fullInput}"`);
173
173
  }
174
174
  }
175
175
 
176
- // src/commands/convert.ts
176
+ // src/commands/convert-usc.ts
177
177
  function buildConvertOptions(inputPath, outputPath, options) {
178
178
  const hasSelectiveFlags = options.includeEditorialNotes || options.includeStatutoryNotes || options.includeAmendments;
179
179
  const includeNotes = hasSelectiveFlags ? false : options.includeNotes;
@@ -259,7 +259,7 @@ async function convertSingleFile(inputPath, outputPath, options, spinnerLabel) {
259
259
  process.exit(1);
260
260
  }
261
261
  }
262
- var convertCommand = new Command("convert").description("Convert USC XML file(s) to Markdown").argument("[input]", "Path to a USC XML file").option("-o, --output <dir>", "Output directory", "./output").option("--titles <spec>", "Title(s) to convert: 1, 1-5, or 1-5,8,11").option("--all", "Convert all downloaded titles found in --input-dir", false).option("-i, --input-dir <dir>", "Directory containing USC XML files", "./downloads/usc/xml").addOption(
262
+ var convertUscCommand = new Command("convert-usc").description("Convert U.S. Code XML file(s) to Markdown").argument("[input]", "Path to a USC XML file").option("-o, --output <dir>", "Output directory", "./output").option("--titles <spec>", "Title(s) to convert: 1, 1-5, or 1-5,8,11").option("--all", "Convert all downloaded titles found in --input-dir", false).option("-i, --input-dir <dir>", "Directory containing USC XML files", "./downloads/usc/xml").addOption(
263
263
  new Option("-g, --granularity <level>", "Output granularity: section, chapter, or title").choices(["section", "chapter", "title"]).default("section")
264
264
  ).addOption(
265
265
  new Option("--link-style <style>", "Link style: relative, canonical, or plaintext").choices(["relative", "canonical", "plaintext"]).default("plaintext")
@@ -277,12 +277,12 @@ Granularity:
277
277
  title One .md file per title, entire hierarchy inlined
278
278
 
279
279
  Examples:
280
- $ lexbuild convert --titles 1 Convert Title 1
281
- $ lexbuild convert --titles 1-5,8,11 Convert a mix of titles
282
- $ lexbuild convert --all -g chapter All titles, chapter-level
283
- $ lexbuild convert --titles 26 -g title Title 26 as a single file
284
- $ lexbuild convert --all --dry-run Preview stats only
285
- $ lexbuild convert ./downloads/usc/xml/usc01.xml -o ./out`
280
+ $ lexbuild convert-usc --titles 1 Convert Title 1
281
+ $ lexbuild convert-usc --titles 1-5,8,11 Convert a mix of titles
282
+ $ lexbuild convert-usc --all -g chapter All titles, chapter-level
283
+ $ lexbuild convert-usc --titles 26 -g title Title 26 as a single file
284
+ $ lexbuild convert-usc --all --dry-run Preview stats only
285
+ $ lexbuild convert-usc ./downloads/usc/xml/usc01.xml -o ./out`
286
286
  ).action(async (input, options) => {
287
287
  const modeCount = [input, options.titles, options.all].filter(Boolean).length;
288
288
  if (modeCount === 0) {
@@ -432,18 +432,18 @@ Examples:
432
432
  console.log("");
433
433
  });
434
434
 
435
- // src/commands/download.ts
435
+ // src/commands/download-usc.ts
436
436
  import { Command as Command2 } from "commander";
437
437
  import { relative as relative2, resolve as resolve2 } from "path";
438
438
  import { downloadTitles, CURRENT_RELEASE_POINT } from "@lexbuild/usc";
439
- var downloadCommand = new Command2("download").description("Download U.S. Code XML from OLRC").option("-o, --output <dir>", "Download directory", "./downloads/usc/xml").option("--titles <spec>", "Title(s) to download: 1, 1-5, or 1-5,8,11").option("--all", "Download all 54 titles (single bulk zip)", false).option("--release-point <id>", "OLRC release point identifier", CURRENT_RELEASE_POINT).addHelpText(
439
+ var downloadUscCommand = new Command2("download-usc").description("Download U.S. Code XML from OLRC").option("-o, --output <dir>", "Download directory", "./downloads/usc/xml").option("--titles <spec>", "Title(s) to download: 1, 1-5, or 1-5,8,11").option("--all", "Download all 54 titles (single bulk zip)", false).option("--release-point <id>", "OLRC release point identifier", CURRENT_RELEASE_POINT).addHelpText(
440
440
  "after",
441
441
  `
442
442
  Examples:
443
- $ lexbuild download --all Download all 54 titles
444
- $ lexbuild download --titles 1 Download Title 1 only
445
- $ lexbuild download --titles 1-5,8,11 Download specific titles
446
- $ lexbuild download --all -o ./my-xml Custom output directory
443
+ $ lexbuild download-usc --all Download all 54 titles
444
+ $ lexbuild download-usc --titles 1 Download Title 1 only
445
+ $ lexbuild download-usc --titles 1-5,8,11 Download specific titles
446
+ $ lexbuild download-usc --all -o ./my-xml Custom output directory
447
447
 
448
448
  Source: https://uscode.house.gov/download/download.shtml`
449
449
  ).action(async (options) => {
@@ -508,22 +508,384 @@ Source: https://uscode.house.gov/download/download.shtml`
508
508
  }
509
509
  });
510
510
 
511
+ // src/commands/convert-ecfr.ts
512
+ import chalk3 from "chalk";
513
+ import { Command as Command3, Option as Option2 } from "commander";
514
+ import { existsSync as existsSync2, readdirSync as readdirSync2 } from "fs";
515
+ import { join as join2, relative as relative3, resolve as resolve3 } from "path";
516
+ import { convertEcfrTitle } from "@lexbuild/ecfr";
517
+ function buildConvertOptions2(inputPath, outputPath, options) {
518
+ const hasSelectiveFlags = options.includeEditorialNotes || options.includeStatutoryNotes || options.includeAmendments;
519
+ const includeNotes = hasSelectiveFlags ? false : options.includeNotes;
520
+ return {
521
+ input: inputPath,
522
+ output: outputPath,
523
+ granularity: options.granularity,
524
+ linkStyle: options.linkStyle,
525
+ includeSourceCredits: options.includeSourceCredits,
526
+ includeNotes,
527
+ includeEditorialNotes: options.includeEditorialNotes,
528
+ includeStatutoryNotes: options.includeStatutoryNotes,
529
+ includeAmendments: options.includeAmendments,
530
+ dryRun: options.dryRun
531
+ };
532
+ }
533
+ var ECFR_XML_RE = /^ECFR-title(\d+)\.xml$/;
534
+ function titleXmlPath2(inputDir, titleNum) {
535
+ return join2(inputDir, `ECFR-title${titleNum}.xml`);
536
+ }
537
+ function discoverEcfrTitles(inputDir) {
538
+ if (!existsSync2(inputDir)) return [];
539
+ return readdirSync2(inputDir).map((name) => ECFR_XML_RE.exec(name)).filter((m) => m !== null).map((m) => parseInt(m[1] ?? "0", 10)).sort((a, b) => a - b);
540
+ }
541
+ async function runConversion2(inputPath, outputPath, options) {
542
+ const startTime = performance.now();
543
+ const result = await convertEcfrTitle(buildConvertOptions2(inputPath, outputPath, options));
544
+ const elapsed = performance.now() - startTime;
545
+ return { result, elapsed };
546
+ }
547
+ async function convertSingleFile2(inputPath, outputPath, options, spinnerLabel) {
548
+ const spinner = createSpinner(spinnerLabel);
549
+ spinner.start();
550
+ try {
551
+ const { result, elapsed } = await runConversion2(inputPath, outputPath, options);
552
+ spinner.stop();
553
+ const rows = [];
554
+ if (options.granularity === "section") {
555
+ rows.push(["Sections", formatNumber(result.sectionsWritten)]);
556
+ rows.push(["Parts", formatNumber(result.partCount)]);
557
+ } else if (options.granularity === "part") {
558
+ rows.push(["Parts", formatNumber(result.partCount)]);
559
+ } else if (options.granularity === "chapter") {
560
+ rows.push(["Chapters", formatNumber(result.sectionsWritten)]);
561
+ }
562
+ rows.push(["Est. Tokens", formatNumber(result.totalTokenEstimate)]);
563
+ if (!result.dryRun) {
564
+ rows.push(["Files Written", formatNumber(result.files.length)]);
565
+ }
566
+ rows.push(
567
+ ["Peak Memory", formatBytes(result.peakMemoryBytes)],
568
+ ["Duration", formatDuration(elapsed)]
569
+ );
570
+ const titleLabel = result.dryRun ? `lexbuild \u2014 eCFR Title ${result.titleNumber}: ${result.titleName} [dry-run]` : `lexbuild \u2014 eCFR Title ${result.titleNumber}: ${result.titleName}`;
571
+ const outputRelative = relative3(process.cwd(), outputPath) || outputPath;
572
+ const output = summaryBlock({
573
+ title: titleLabel,
574
+ rows: [...rows, ["Output", outputRelative]],
575
+ footer: result.dryRun ? success("Dry run complete") : success("Conversion complete")
576
+ });
577
+ process.stdout.write(output);
578
+ if (options.verbose && !result.dryRun && result.files.length > 0) {
579
+ console.log(" Files written:");
580
+ for (const file of result.files) {
581
+ console.log(` ${relative3(process.cwd(), file) || file}`);
582
+ }
583
+ console.log("");
584
+ }
585
+ return result;
586
+ } catch (err) {
587
+ spinner.fail(err instanceof Error ? err.message : String(err));
588
+ process.exit(1);
589
+ }
590
+ }
591
+ var convertEcfrCommand = new Command3("convert-ecfr").description("Convert eCFR XML file(s) to Markdown").argument("[input]", "Path to an eCFR XML file").option("-o, --output <dir>", "Output directory", "./output").option("--titles <spec>", "Title(s) to convert: 1, 1-5, or 1-5,17").option("--all", "Convert all downloaded eCFR titles found in --input-dir", false).option("-i, --input-dir <dir>", "Directory containing eCFR XML files", "./downloads/ecfr/xml").addOption(
592
+ new Option2("-g, --granularity <level>", "Output granularity: section, part, chapter, or title").choices(["section", "part", "chapter", "title"]).default("section")
593
+ ).addOption(
594
+ new Option2("--link-style <style>", "Link style: relative, canonical, or plaintext").choices(["relative", "canonical", "plaintext"]).default("plaintext")
595
+ ).option("--include-source-credits", "Include source credit annotations", true).option("--no-include-source-credits", "Exclude source credit annotations").option("--include-notes", "Include all notes (default)", true).option("--no-include-notes", "Exclude all notes").option("--include-editorial-notes", "Include editorial notes only", false).option("--include-statutory-notes", "Include statutory/regulatory notes only", false).option("--include-amendments", "Include amendment history notes only", false).option("--dry-run", "Parse and report structure without writing files", false).option("-v, --verbose", "Enable verbose logging", false).addHelpText(
596
+ "after",
597
+ `
598
+ Input modes (use exactly one):
599
+ <input> Convert a single eCFR XML file
600
+ --titles Convert specific titles by number
601
+ --all Convert all titles in --input-dir
602
+
603
+ Granularity:
604
+ section One .md file per section (default)
605
+ part One .md file per part, sections inlined
606
+ chapter One .md file per chapter, parts and sections inlined
607
+ title One .md file per title, entire hierarchy inlined
608
+
609
+ Examples:
610
+ $ lexbuild convert-ecfr --titles 1 Convert eCFR Title 1
611
+ $ lexbuild convert-ecfr --titles 1-5,17 Convert specific titles
612
+ $ lexbuild convert-ecfr --all -g part All titles, part-level
613
+ $ lexbuild convert-ecfr --all --dry-run Preview stats only
614
+ $ lexbuild convert-ecfr ./downloads/ecfr/xml/ECFR-title1.xml -o ./out`
615
+ ).action(async (input, options) => {
616
+ const modeCount = [input, options.titles, options.all].filter(Boolean).length;
617
+ if (modeCount === 0) {
618
+ console.error(
619
+ error("Specify an input file, --titles <spec>, or --all (e.g. --titles 1-5,17)")
620
+ );
621
+ process.exit(1);
622
+ }
623
+ if (modeCount > 1) {
624
+ console.error(error("Cannot combine <input>, --titles, and --all \u2014 use only one"));
625
+ process.exit(1);
626
+ }
627
+ const outputPath = resolve3(options.output);
628
+ const dryRunLabel = options.dryRun ? " [dry-run]" : "";
629
+ if (input) {
630
+ const inputPath = resolve3(input);
631
+ if (!existsSync2(inputPath)) {
632
+ console.error(error(`Input file not found: ${inputPath}`));
633
+ process.exit(1);
634
+ }
635
+ await convertSingleFile2(inputPath, outputPath, options, `Converting eCFR${dryRunLabel}...`);
636
+ return;
637
+ }
638
+ let titles;
639
+ if (options.all) {
640
+ const inputDir2 = resolve3(options.inputDir);
641
+ titles = discoverEcfrTitles(inputDir2);
642
+ if (titles.length === 0) {
643
+ console.error(error(`No eCFR XML files found in ${inputDir2}`));
644
+ process.exit(1);
645
+ }
646
+ } else {
647
+ const titlesSpec = options.titles;
648
+ try {
649
+ titles = parseTitles(titlesSpec, 50);
650
+ } catch (err) {
651
+ console.error(error(err instanceof Error ? err.message : String(err)));
652
+ process.exit(1);
653
+ }
654
+ }
655
+ const inputDir = resolve3(options.inputDir);
656
+ const totalTitles = titles.length;
657
+ const results = [];
658
+ const spinner = createSpinner(`Converting eCFR${dryRunLabel}...`);
659
+ spinner.start();
660
+ for (const [i, titleNum] of titles.entries()) {
661
+ const xmlPath = titleXmlPath2(inputDir, titleNum);
662
+ if (!existsSync2(xmlPath)) {
663
+ spinner.stop();
664
+ console.error(error(`XML file not found: ${xmlPath}`));
665
+ process.exit(1);
666
+ }
667
+ spinner.text = `Converting eCFR Title ${titleNum}${dryRunLabel} (${i + 1}/${totalTitles})...`;
668
+ try {
669
+ const run = await runConversion2(xmlPath, outputPath, options);
670
+ results.push(run);
671
+ } catch (err) {
672
+ spinner.fail(err instanceof Error ? err.message : String(err));
673
+ process.exit(1);
674
+ }
675
+ }
676
+ spinner.stop();
677
+ const outputRelative = relative3(process.cwd(), outputPath) || outputPath;
678
+ const headerTitle = options.dryRun ? "lexbuild \u2014 eCFR Conversion Summary [dry-run]" : "lexbuild \u2014 eCFR Conversion Summary";
679
+ const header = summaryBlock({
680
+ title: headerTitle,
681
+ rows: [["Directory", outputRelative]]
682
+ });
683
+ process.stdout.write(header);
684
+ const granularity = options.granularity;
685
+ let totalSections = 0;
686
+ let totalParts = 0;
687
+ let totalTokens = 0;
688
+ let totalElapsed = 0;
689
+ const tableRows = results.map(({ result, elapsed }) => {
690
+ totalSections += result.sectionsWritten;
691
+ totalParts += result.partCount;
692
+ totalTokens += result.totalTokenEstimate;
693
+ totalElapsed += elapsed;
694
+ if (granularity === "title") {
695
+ return [
696
+ result.titleNumber,
697
+ result.titleName,
698
+ formatNumber(result.totalTokenEstimate),
699
+ formatDuration(elapsed)
700
+ ];
701
+ } else if (granularity === "chapter") {
702
+ return [
703
+ result.titleNumber,
704
+ result.titleName,
705
+ formatNumber(result.sectionsWritten),
706
+ formatNumber(result.totalTokenEstimate),
707
+ formatDuration(elapsed)
708
+ ];
709
+ } else if (granularity === "part") {
710
+ return [
711
+ result.titleNumber,
712
+ result.titleName,
713
+ formatNumber(result.partCount),
714
+ formatNumber(result.totalTokenEstimate),
715
+ formatDuration(elapsed)
716
+ ];
717
+ } else {
718
+ return [
719
+ result.titleNumber,
720
+ result.titleName,
721
+ formatNumber(result.partCount),
722
+ formatNumber(result.sectionsWritten),
723
+ formatNumber(result.totalTokenEstimate),
724
+ formatDuration(elapsed)
725
+ ];
726
+ }
727
+ });
728
+ if (granularity === "title") {
729
+ tableRows.push([
730
+ chalk3.bold("Total"),
731
+ "",
732
+ chalk3.bold(formatNumber(totalTokens)),
733
+ chalk3.bold(formatDuration(totalElapsed))
734
+ ]);
735
+ } else if (granularity === "chapter") {
736
+ tableRows.push([
737
+ chalk3.bold("Total"),
738
+ "",
739
+ chalk3.bold(formatNumber(totalSections)),
740
+ chalk3.bold(formatNumber(totalTokens)),
741
+ chalk3.bold(formatDuration(totalElapsed))
742
+ ]);
743
+ } else if (granularity === "part") {
744
+ tableRows.push([
745
+ chalk3.bold("Total"),
746
+ "",
747
+ chalk3.bold(formatNumber(totalParts)),
748
+ chalk3.bold(formatNumber(totalTokens)),
749
+ chalk3.bold(formatDuration(totalElapsed))
750
+ ]);
751
+ } else {
752
+ tableRows.push([
753
+ chalk3.bold("Total"),
754
+ "",
755
+ chalk3.bold(formatNumber(totalParts)),
756
+ chalk3.bold(formatNumber(totalSections)),
757
+ chalk3.bold(formatNumber(totalTokens)),
758
+ chalk3.bold(formatDuration(totalElapsed))
759
+ ]);
760
+ }
761
+ const tableHeaders = granularity === "title" ? ["Title", "Name", "Tokens", "Duration"] : granularity === "chapter" ? ["Title", "Name", "Chapters", "Tokens", "Duration"] : granularity === "part" ? ["Title", "Name", "Parts", "Tokens", "Duration"] : ["Title", "Name", "Parts", "Sections", "Tokens", "Duration"];
762
+ console.log(dataTable(tableHeaders, tableRows));
763
+ const titleWord = totalTitles === 1 ? "title" : "titles";
764
+ let countLabel;
765
+ if (granularity === "title") {
766
+ countLabel = `${totalTitles} ${titleWord}`;
767
+ } else if (granularity === "chapter") {
768
+ const chapterWord = totalSections === 1 ? "chapter" : "chapters";
769
+ countLabel = `${totalTitles} ${titleWord} (${formatNumber(totalSections)} ${chapterWord})`;
770
+ } else if (granularity === "part") {
771
+ const partWord = totalParts === 1 ? "part" : "parts";
772
+ countLabel = `${totalTitles} ${titleWord} (${formatNumber(totalParts)} ${partWord})`;
773
+ } else {
774
+ const sectionWord = totalSections === 1 ? "section" : "sections";
775
+ countLabel = `${totalTitles} ${titleWord} (${formatNumber(totalSections)} ${sectionWord})`;
776
+ }
777
+ console.log(`
778
+ ${success(`Converted ${countLabel} in ${formatDuration(totalElapsed)}`)}`);
779
+ console.log("");
780
+ });
781
+
782
+ // src/commands/download-ecfr.ts
783
+ import { Command as Command4 } from "commander";
784
+ import { relative as relative4, resolve as resolve4 } from "path";
785
+ import { downloadEcfrTitles } from "@lexbuild/ecfr";
786
+ var downloadEcfrCommand = new Command4("download-ecfr").description("Download eCFR XML from govinfo bulk data repository").option("-o, --output <dir>", "Download directory", "./downloads/ecfr/xml").option("--titles <spec>", "Title(s) to download: 1, 1-5, or 1-5,8,17").option("--all", "Download all 50 eCFR titles", false).addHelpText(
787
+ "after",
788
+ `
789
+ Examples:
790
+ $ lexbuild download-ecfr --all Download all 50 titles
791
+ $ lexbuild download-ecfr --titles 1 Download Title 1 only
792
+ $ lexbuild download-ecfr --titles 1-5,17 Download specific titles
793
+ $ lexbuild download-ecfr --all -o ./my-xml Custom output directory
794
+
795
+ Source: https://www.govinfo.gov/bulkdata/ECFR`
796
+ ).action(async (options) => {
797
+ if (!options.titles && !options.all) {
798
+ console.error(error("Specify --titles <spec> or --all (e.g. --titles 1-5,17)"));
799
+ process.exit(1);
800
+ }
801
+ let titles;
802
+ if (options.titles) {
803
+ try {
804
+ titles = parseTitles(options.titles, 50);
805
+ } catch (err) {
806
+ console.error(error(err instanceof Error ? err.message : String(err)));
807
+ process.exit(1);
808
+ }
809
+ }
810
+ const outputDir = resolve4(options.output);
811
+ const titleCount = titles ? titles.length : 50;
812
+ const label = titleCount === 1 ? `Downloading eCFR Title ${titles?.[0]}` : `Downloading ${titleCount} eCFR titles`;
813
+ const spinner = createSpinner(`${label}...`);
814
+ spinner.start();
815
+ const startTime = performance.now();
816
+ try {
817
+ const result = await downloadEcfrTitles({
818
+ output: outputDir,
819
+ titles
820
+ });
821
+ const elapsed = performance.now() - startTime;
822
+ spinner.stop();
823
+ const fileRows = result.files.map((file) => [
824
+ String(file.titleNumber),
825
+ formatBytes(file.size),
826
+ relative4(outputDir, file.path) || file.path
827
+ ]);
828
+ const output = summaryBlock({
829
+ title: "lexbuild \u2014 eCFR Download Summary",
830
+ rows: [
831
+ ["Source", "govinfo.gov/bulkdata/ECFR"],
832
+ ["Directory", relative4(process.cwd(), outputDir) || outputDir]
833
+ ]
834
+ });
835
+ process.stdout.write(output);
836
+ if (fileRows.length > 0) {
837
+ console.log(dataTable(["Title", "Size", "File"], fileRows));
838
+ }
839
+ const titleWord = result.titlesDownloaded === 1 ? "title" : "titles";
840
+ const summary = `Downloaded ${result.titlesDownloaded} ${titleWord} (${formatBytes(result.totalBytes)}) in ${formatDuration(elapsed)}`;
841
+ console.log(` ${success(summary)}`);
842
+ console.log("");
843
+ } catch (err) {
844
+ spinner.fail(err instanceof Error ? err.message : String(err));
845
+ process.exit(1);
846
+ }
847
+ });
848
+
511
849
  // src/index.ts
512
850
  var require2 = createRequire(import.meta.url);
513
851
  var pkg = require2("../package.json");
514
- var program = new Command3();
515
- program.name("lexbuild").description("Convert U.S. legislative XML (USLM) to structured Markdown for AI/RAG ingestion").version(pkg.version).addHelpText(
852
+ var program = new Command5();
853
+ program.name("lexbuild").description("Convert U.S. legal XML to structured Markdown for AI/RAG ingestion").version(pkg.version).addHelpText(
516
854
  "after",
517
855
  `
518
- Quick start:
519
- $ lexbuild download --all Download all 54 titles from OLRC
520
- $ lexbuild convert --all Convert all downloaded titles
521
- $ lexbuild convert --titles 1 Convert Title 1 only
522
- $ lexbuild convert --titles 1 -g title Whole title as a single file
856
+ Quick start (U.S. Code):
857
+ $ lexbuild download-usc --all Download all 54 USC titles from OLRC
858
+ $ lexbuild convert-usc --all Convert all downloaded USC titles
859
+ $ lexbuild convert-usc --titles 1 Convert USC Title 1 only
860
+
861
+ Quick start (eCFR):
862
+ $ lexbuild download-ecfr --all Download all 50 eCFR titles from govinfo
863
+ $ lexbuild convert-ecfr --all Convert all downloaded eCFR titles
864
+ $ lexbuild convert-ecfr --titles 17 Convert eCFR Title 17 only
523
865
 
524
866
  Documentation: https://github.com/chris-c-thomas/LexBuild`
525
867
  );
526
- program.addCommand(convertCommand);
527
- program.addCommand(downloadCommand);
868
+ program.addCommand(downloadUscCommand);
869
+ program.addCommand(convertUscCommand);
870
+ program.addCommand(downloadEcfrCommand);
871
+ program.addCommand(convertEcfrCommand);
872
+ program.addCommand(
873
+ new Command5("download").description("(use download-usc or download-ecfr)").allowUnknownOption().helpOption(false).action(() => {
874
+ console.error(error("Please specify a source:\n"));
875
+ console.error(" lexbuild download-usc Download U.S. Code XML from OLRC");
876
+ console.error(" lexbuild download-ecfr Download eCFR XML from govinfo");
877
+ console.error("");
878
+ process.exit(1);
879
+ })
880
+ );
881
+ program.addCommand(
882
+ new Command5("convert").description("(use convert-usc or convert-ecfr)").allowUnknownOption().helpOption(false).action(() => {
883
+ console.error(error("Please specify a source:\n"));
884
+ console.error(" lexbuild convert-usc Convert U.S. Code XML to Markdown");
885
+ console.error(" lexbuild convert-ecfr Convert eCFR XML to Markdown");
886
+ console.error("");
887
+ process.exit(1);
888
+ })
889
+ );
528
890
  program.parse();
529
891
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/commands/convert.ts","../src/ui.ts","../src/parse-titles.ts","../src/commands/download.ts"],"sourcesContent":["/** lexbuild CLI — Convert U.S. legislative XML to structured Markdown */\n\nimport { createRequire } from \"node:module\";\nimport { Command } from \"commander\";\nimport { convertCommand } from \"./commands/convert.js\";\nimport { downloadCommand } from \"./commands/download.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. legislative XML (USLM) to structured Markdown for AI/RAG ingestion\")\n .version(pkg.version)\n .addHelpText(\n \"after\",\n `\nQuick start:\n $ lexbuild download --all Download all 54 titles from OLRC\n $ lexbuild convert --all Convert all downloaded titles\n $ lexbuild convert --titles 1 Convert Title 1 only\n $ lexbuild convert --titles 1 -g title Whole title as a single file\n\nDocumentation: https://github.com/chris-c-thomas/LexBuild`,\n );\n\nprogram.addCommand(convertCommand);\nprogram.addCommand(downloadCommand);\n\nprogram.parse();\n","/**\n * `lexbuild convert` 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 convertCommand = new Command(\"convert\")\n .description(\"Convert USC 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 --titles 1 Convert Title 1\n $ lexbuild convert --titles 1-5,8,11 Convert a mix of titles\n $ lexbuild convert --all -g chapter All titles, chapter-level\n $ lexbuild convert --titles 26 -g title Title 26 as a single file\n $ lexbuild convert --all --dry-run Preview stats only\n $ lexbuild convert ./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 for the chosen granularity\n const titleWord = totalTitles === 1 ? \"title\" : \"titles\";\n let countLabel: string;\n if (granularity === \"title\") {\n countLabel = `${totalTitles} ${titleWord}`;\n } else if (granularity === \"chapter\") {\n const chapterWord = totalChapters === 1 ? \"chapter\" : \"chapters\";\n countLabel = `${totalTitles} ${titleWord} (${formatNumber(totalChapters)} ${chapterWord})`;\n } else {\n const sectionWord = totalSections === 1 ? \"section\" : \"sections\";\n countLabel = `${totalTitles} ${titleWord} (${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. */\nexport function 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): 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);\n validateTitleNumber(end, input);\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);\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 (1-54). */\nfunction validateTitleNumber(num: number, fullInput: string): void {\n if (num < 1 || num > 54) {\n throw new Error(`Title number ${num} out of range (must be 1-54) in: \"${fullInput}\"`);\n }\n}\n","/**\n * `lexbuild download` command — downloads USC XML from OLRC.\n */\n\nimport { Command } from \"commander\";\nimport { relative, resolve } from \"node:path\";\nimport { downloadTitles, CURRENT_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;\n}\n\nexport const downloadCommand = new Command(\"download\")\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 identifier\", CURRENT_RELEASE_POINT)\n .addHelpText(\n \"after\",\n `\nExamples:\n $ lexbuild download --all Download all 54 titles\n $ lexbuild download --titles 1 Download Title 1 only\n $ lexbuild download --titles 1-5,8,11 Download specific titles\n $ lexbuild download --all -o ./my-xml Custom output directory\n\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 const label =\n titleCount === 1 ? `Downloading Title ${titles?.[0]}` : `Downloading ${titleCount} 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: options.releasePoint,\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\n const output = summaryBlock({\n title: \"lexbuild — Download Summary\",\n rows: [\n [\"Release Point\", options.releasePoint],\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"],"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,SAAS,OAAO,CAAC;AACtC;AAGO,SAAS,eAAe,IAAoB;AACjD,QAAM,OAAO,KAAK;AAClB,MAAI,OAAO,IAAI;AACb,WAAO,GAAG,KAAK,QAAQ,OAAO,KAAK,IAAI,CA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,KAAK,CAAC;AAAA,EAChB;AACF,CAAC;;;AJrHH,IAAMC,WAAU,cAAc,YAAY,GAAG;AAC7C,IAAM,MAAMA,SAAQ,iBAAiB;AAErC,IAAM,UAAU,IAAIC,SAAQ;AAE5B,QACG,KAAK,UAAU,EACf,YAAY,iFAAiF,EAC7F,QAAQ,IAAI,OAAO,EACnB;AAAA,EACC;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQF;AAEF,QAAQ,WAAW,cAAc;AACjC,QAAQ,WAAW,eAAe;AAElC,QAAQ,MAAM;","names":["Command","chalk","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/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 { 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(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 for the chosen granularity\n const titleWord = totalTitles === 1 ? \"title\" : \"titles\";\n let countLabel: string;\n if (granularity === \"title\") {\n countLabel = `${totalTitles} ${titleWord}`;\n } else if (granularity === \"chapter\") {\n const chapterWord = totalChapters === 1 ? \"chapter\" : \"chapters\";\n countLabel = `${totalTitles} ${titleWord} (${formatNumber(totalChapters)} ${chapterWord})`;\n } else {\n const sectionWord = totalSections === 1 ? \"section\" : \"sections\";\n countLabel = `${totalTitles} ${titleWord} (${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. */\nexport function 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\nimport { Command } from \"commander\";\nimport { relative, resolve } from \"node:path\";\nimport { downloadTitles, CURRENT_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;\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 identifier\", CURRENT_RELEASE_POINT)\n .addHelpText(\n \"after\",\n `\nExamples:\n $ lexbuild download-usc --all Download all 54 titles\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\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 const label =\n titleCount === 1 ? `Downloading Title ${titles?.[0]}` : `Downloading ${titleCount} 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: options.releasePoint,\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\n const output = summaryBlock({\n title: \"lexbuild — Download Summary\",\n rows: [\n [\"Release Point\", options.releasePoint],\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 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 const titleWord = totalTitles === 1 ? \"title\" : \"titles\";\n let countLabel: string;\n if (granularity === \"title\") {\n countLabel = `${totalTitles} ${titleWord}`;\n } else if (granularity === \"chapter\") {\n const chapterWord = totalSections === 1 ? \"chapter\" : \"chapters\";\n countLabel = `${totalTitles} ${titleWord} (${formatNumber(totalSections)} ${chapterWord})`;\n } else if (granularity === \"part\") {\n const partWord = totalParts === 1 ? \"part\" : \"parts\";\n countLabel = `${totalTitles} ${titleWord} (${formatNumber(totalParts)} ${partWord})`;\n } else {\n const sectionWord = totalSections === 1 ? \"section\" : \"sections\";\n countLabel = `${totalTitles} ${titleWord} (${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.\n */\n\nimport { Command } from \"commander\";\nimport { relative, resolve } from \"node:path\";\nimport { downloadEcfrTitles } 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/** Parsed options from the download-ecfr command */\ninterface DownloadEcfrOptions {\n output: string;\n titles?: string | undefined;\n all: boolean;\n}\n\nexport const downloadEcfrCommand = new Command(\"download-ecfr\")\n .description(\"Download eCFR XML from govinfo bulk data repository\")\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 .addHelpText(\n \"after\",\n `\nExamples:\n $ lexbuild download-ecfr --all Download all 50 titles\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 -o ./my-xml Custom output directory\n\nSource: https://www.govinfo.gov/bulkdata/ECFR`,\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 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 label =\n titleCount === 1\n ? `Downloading eCFR Title ${titles?.[0]}`\n : `Downloading ${titleCount} eCFR titles`;\n\n const spinner = createSpinner(`${label}...`);\n spinner.start();\n\n const startTime = performance.now();\n\n try {\n const result = await downloadEcfrTitles({\n output: outputDir,\n titles,\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 const titleWord = result.titlesDownloaded === 1 ? \"title\" : \"titles\";\n const summary = `Downloaded ${result.titlesDownloaded} ${titleWord} (${formatBytes(result.totalBytes)}) in ${formatDuration(elapsed)}`;\n console.log(` ${success(summary)}`);\n console.log(\"\");\n } catch (err) {\n spinner.fail(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;A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AAQ,IAAI,OAAO,EACnB;AAAA,EACC;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYF;AAGF,QAAQ,WAAW,kBAAkB;AACrC,QAAQ,WAAW,iBAAiB;AACpC,QAAQ,WAAW,mBAAmB;AACtC,QAAQ,WAAW,kBAAkB;AAGrC,QAAQ;AAAA,EACN,IAAIA,SAAQ,UAAU,EACnB,YAAY,qCAAqC,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","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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lexbuild/cli",
3
- "version": "1.7.0",
3
+ "version": "1.9.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",
@@ -54,8 +54,9 @@
54
54
  "ora": "^8.2.0",
55
55
  "pino": "^9.6.0",
56
56
  "pino-pretty": "^13.0.0",
57
- "@lexbuild/usc": "1.7.0",
58
- "@lexbuild/core": "1.7.0"
57
+ "@lexbuild/core": "1.9.0",
58
+ "@lexbuild/ecfr": "1.9.0",
59
+ "@lexbuild/usc": "1.9.0"
59
60
  },
60
61
  "devDependencies": {
61
62
  "@types/node": "^25.3.2",