caelum0x bac8f9e662 feat: Wave C+D — agent multi-skill verification engine + infra data layer
- agent: 6 auto-collecting registries (parsers/checks/risk/scoring/tools/pipelines);
  15 doc parsers, 12 check packs, 6 risk models, scoring dimensions + reconciler,
  ~15 Claude tools, 8 pipelines (financing/underwriting/dpp/compliance/grading/esg) + routes; 380 tests
- infra: BaseRepository + ~35 typed repositories, 56 composed schema modules,
  storage/queue/notifications/cache/events adapters; 203 tests
- pnpm -r typecheck/build/test all green

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-31 23:48:46 +03:00

86 lines
2.9 KiB
JavaScript

#!/usr/bin/env node
/**
* Barrel generator — the glue that lets Fill agents add files WITHOUT editing
* any shared index.
*
* For each configured directory it scans the `.ts` files, excludes the
* infrastructure files (barrel, base, types, runner, registry, tests) and
* regenerates an `index.ts` that `export *`s every remaining module in a stable,
* sorted order. Because `export *` evaluates each module, side-effect adapters
* (storage/notifications/migrations that self-register) are wired up too.
*
* Usage: node scripts/gen-barrels.mjs (or `pnpm run barrels`)
*
* Convention: NEVER hand-edit a generated `index.ts`. Add a file, run this.
*/
import { readdirSync, readFileSync, writeFileSync, existsSync } from "node:fs";
import { join, dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..");
/** Files that are never re-exported from a generated barrel. */
const ALWAYS_EXCLUDE = new Set([
"index.ts",
"base.ts",
"types.ts",
"registry.ts",
"runner.ts",
]);
/**
* Each target regenerates `<dir>/index.ts`. `keep` lists infra files that must
* be re-exported first (they hold the shared interfaces the fill files build on)
* even though they are otherwise excluded.
*/
const TARGETS = [
{ dir: "src/repositories", keep: ["base"] },
{ dir: "src/storage/adapters", keep: [] },
{ dir: "src/notifications/channels", keep: [] },
{ dir: "src/migrations/scripts", keep: [] },
];
function moduleNames(absDir) {
if (!existsSync(absDir)) return [];
return readdirSync(absDir)
.filter((f) => f.endsWith(".ts"))
.filter((f) => !f.endsWith(".test.ts") && !f.endsWith(".d.ts"))
.filter((f) => !ALWAYS_EXCLUDE.has(f))
.map((f) => f.slice(0, -3))
.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
}
function render(names) {
const header =
"// AUTO-GENERATED by scripts/gen-barrels.mjs — do not edit.\n" +
"// Add a file to this directory, then run `pnpm run barrels`.\n";
if (names.length === 0) {
return `${header}export {};\n`;
}
const lines = names.map((n) => `export * from "./${n}.js";`).join("\n");
return `${header}${lines}\n`;
}
let changed = 0;
for (const target of TARGETS) {
const absDir = join(ROOT, target.dir);
const discovered = moduleNames(absDir);
// `keep` files first (deduped), then the discovered fill files.
const ordered = [
...target.keep,
...discovered.filter((n) => !target.keep.includes(n)),
];
const output = render(ordered);
const indexPath = join(absDir, "index.ts");
const prev = existsSync(indexPath) ? readFileSync(indexPath, "utf8") : null;
if (prev !== output) {
writeFileSync(indexPath, output, "utf8");
changed += 1;
console.log(`barrels: wrote ${target.dir}/index.ts (${ordered.length} modules)`);
} else {
console.log(`barrels: ${target.dir}/index.ts up to date (${ordered.length} modules)`);
}
}
console.log(`barrels: done (${changed} file(s) changed).`);