@hexagen-monaco/sync 0.11.0 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/LICENSE +8 -5
  2. package/README.md +2 -2
  3. package/dist/application/ports/out/file-system.port.d.ts.map +1 -1
  4. package/dist/application/ports/out/symbol-reference-index.port.d.ts +9 -9
  5. package/dist/application/ports/out/symbol-reference-index.port.d.ts.map +1 -1
  6. package/dist/application/use-cases/migrate-manifest.use-case.d.ts +4 -1
  7. package/dist/application/use-cases/migrate-manifest.use-case.d.ts.map +1 -1
  8. package/dist/application/use-cases/refactoring-impact.use-case.d.ts +6 -5
  9. package/dist/application/use-cases/refactoring-impact.use-case.d.ts.map +1 -1
  10. package/dist/cli.js +893 -360
  11. package/dist/cli.js.map +1 -1
  12. package/dist/commands/adopt/index.d.ts.map +1 -1
  13. package/dist/commands/bootstrap/index.d.ts +21 -0
  14. package/dist/commands/bootstrap/index.d.ts.map +1 -1
  15. package/dist/commands/manifest/migrate.d.ts.map +1 -1
  16. package/dist/commands/scan/index.d.ts +185 -0
  17. package/dist/commands/scan/index.d.ts.map +1 -0
  18. package/dist/commands/shared/index.d.ts +1 -0
  19. package/dist/commands/shared/index.d.ts.map +1 -1
  20. package/dist/commands/shared/lstat-exists.d.ts +7 -0
  21. package/dist/commands/shared/lstat-exists.d.ts.map +1 -0
  22. package/dist/domain/services/impact-request-validator.d.ts.map +1 -1
  23. package/dist/domain/services/layer-dir-resolver.d.ts +20 -1
  24. package/dist/domain/services/layer-dir-resolver.d.ts.map +1 -1
  25. package/dist/fs-utils.d.ts.map +1 -1
  26. package/dist/generators/barrels/recursive.d.ts.map +1 -1
  27. package/dist/generators/layer-folders.d.ts +9 -1
  28. package/dist/generators/layer-folders.d.ts.map +1 -1
  29. package/dist/generators/package-src-index.d.ts +5 -0
  30. package/dist/generators/package-src-index.d.ts.map +1 -0
  31. package/dist/index.js +110 -50
  32. package/dist/index.js.map +1 -1
  33. package/dist/infrastructure/adapters/atomic-file-system.adapter.d.ts.map +1 -1
  34. package/dist/infrastructure/adapters/file-system-workspace.adapter.d.ts.map +1 -1
  35. package/dist/infrastructure/adapters/ts-morph-symbol-index.adapter.d.ts +1 -1
  36. package/dist/infrastructure/adapters/ts-morph-symbol-index.adapter.d.ts.map +1 -1
  37. package/dist/sync-engine.d.ts.map +1 -1
  38. package/dist/types/index.d.ts +20 -1
  39. package/dist/types/index.d.ts.map +1 -1
  40. package/package.json +1 -1
  41. package/dist/commands/bootstrap.d.ts +0 -30
  42. package/dist/commands/bootstrap.d.ts.map +0 -1
package/dist/cli.js CHANGED
@@ -1,17 +1,17 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command } from 'commander';
3
- import * as path35 from 'path';
4
- import path35__default, { dirname, join } from 'path';
5
- import * as fs24 from 'fs';
6
- import fs24__default, { mkdirSync, writeFileSync, renameSync, unlinkSync, existsSync, readFileSync, promises, realpathSync, lstatSync, createWriteStream } from 'fs';
7
- import fs27, { readFile } from 'fs/promises';
3
+ import * as path34 from 'path';
4
+ import path34__default, { dirname, join } from 'path';
5
+ import * as fs26 from 'fs';
6
+ import fs26__default, { mkdirSync, writeFileSync, renameSync, unlinkSync, existsSync, readFileSync, promises, realpathSync, lstatSync, createWriteStream } from 'fs';
7
+ import fs29, { readFile } from 'fs/promises';
8
8
  import { promisify, isDeepStrictEqual } from 'util';
9
- import { exec, execSync, spawn, execFileSync } from 'child_process';
9
+ import { exec, execSync, spawn, spawnSync, execFileSync } from 'child_process';
10
10
  import yaml10 from 'js-yaml';
11
11
  import crypto from 'crypto';
12
12
  import { z } from 'zod';
13
13
  import { fileURLToPath } from 'url';
14
- import { Project, SyntaxKind, MethodSignature } from 'ts-morph';
14
+ import { Project, ts, SyntaxKind, MethodSignature } from 'ts-morph';
15
15
  import * as readline from 'readline';
16
16
  import { tmpdir } from 'os';
17
17
 
@@ -32,11 +32,11 @@ var MigrationReport = class {
32
32
  );
33
33
  return;
34
34
  }
35
- const reportPath = config.report ? path35__default.resolve(config.workspaceRoot, config.report) : path35__default.join(config.workspaceRoot, "SYNC-MIGRATION-REPORT.md");
36
- await fs27.mkdir(path35__default.dirname(reportPath), { recursive: true });
35
+ const reportPath = config.report ? path34__default.resolve(config.workspaceRoot, config.report) : path34__default.join(config.workspaceRoot, "SYNC-MIGRATION-REPORT.md");
36
+ await fs29.mkdir(path34__default.dirname(reportPath), { recursive: true });
37
37
  let preContent = null;
38
38
  try {
39
- preContent = await fs27.readFile(reportPath, "utf8");
39
+ preContent = await fs29.readFile(reportPath, "utf8");
40
40
  } catch (e) {
41
41
  if (!(e instanceof Error && "code" in e && e.code === "ENOENT"))
42
42
  throw e;
@@ -86,7 +86,7 @@ var SyncJournal = class {
86
86
  */
87
87
  describeEntries(workspaceRoot) {
88
88
  return this.entries.map(
89
- (e) => `${e.kind} ${path35__default.relative(workspaceRoot, e.path)}`
89
+ (e) => `${e.kind} ${path34__default.relative(workspaceRoot, e.path)}`
90
90
  );
91
91
  }
92
92
  /**
@@ -112,11 +112,11 @@ var SyncJournal = class {
112
112
  failures: []
113
113
  };
114
114
  for (const entry of [...this.entries].reverse()) {
115
- const relative = path35__default.relative(workspaceRoot, entry.path);
115
+ const relative = path34__default.relative(workspaceRoot, entry.path);
116
116
  try {
117
117
  if (entry.preContent === null) {
118
118
  try {
119
- await fs27.unlink(entry.path);
119
+ await fs29.unlink(entry.path);
120
120
  } catch (err3) {
121
121
  if (!(err3 instanceof Error && "code" in err3 && err3.code === "ENOENT")) {
122
122
  throw err3;
@@ -124,8 +124,8 @@ var SyncJournal = class {
124
124
  }
125
125
  logger2.info(`rolled back (removed) ${relative}`);
126
126
  } else {
127
- await fs27.mkdir(path35__default.dirname(entry.path), { recursive: true });
128
- await fs27.writeFile(entry.path, entry.preContent, {
127
+ await fs29.mkdir(path34__default.dirname(entry.path), { recursive: true });
128
+ await fs29.writeFile(entry.path, entry.preContent, {
129
129
  encoding: "utf8"
130
130
  });
131
131
  logger2.info(`rolled back (restored) ${relative}`);
@@ -144,9 +144,9 @@ var SyncJournal = class {
144
144
  };
145
145
  var LOCK_FILE = ".architecture/.sync.lock";
146
146
  var LockFile = class {
147
- constructor(workspaceRoot, fsImpl = fs27, logger2 = console) {
147
+ constructor(workspaceRoot, fsImpl = fs29, logger2 = console) {
148
148
  this.workspaceRoot = workspaceRoot;
149
- this.lockPath = path35__default.join(workspaceRoot, LOCK_FILE);
149
+ this.lockPath = path34__default.join(workspaceRoot, LOCK_FILE);
150
150
  this.fsImpl = fsImpl;
151
151
  this.logger = logger2;
152
152
  }
@@ -219,7 +219,7 @@ var PACKAGE_NAMES = [
219
219
  function binEntryOf(pkgJsonPath) {
220
220
  let parsed;
221
221
  try {
222
- parsed = JSON.parse(fs24__default.readFileSync(pkgJsonPath, "utf8"));
222
+ parsed = JSON.parse(fs26__default.readFileSync(pkgJsonPath, "utf8"));
223
223
  } catch {
224
224
  return null;
225
225
  }
@@ -234,22 +234,22 @@ function binEntryOf(pkgJsonPath) {
234
234
  }
235
235
  function resolveFromPackage(dir) {
236
236
  for (const pkgName of PACKAGE_NAMES) {
237
- const pkgDir = path35__default.join(dir, "node_modules", ...pkgName.split("/"));
238
- const entry = binEntryOf(path35__default.join(pkgDir, "package.json"));
237
+ const pkgDir = path34__default.join(dir, "node_modules", ...pkgName.split("/"));
238
+ const entry = binEntryOf(path34__default.join(pkgDir, "package.json"));
239
239
  if (entry === null) continue;
240
- const binPath = path35__default.join(pkgDir, entry);
241
- if (fs24__default.existsSync(binPath)) return binPath;
240
+ const binPath = path34__default.join(pkgDir, entry);
241
+ if (fs26__default.existsSync(binPath)) return binPath;
242
242
  }
243
243
  return null;
244
244
  }
245
245
  function resolveArchLinterBin(startDir) {
246
- let dir = path35__default.resolve(startDir);
246
+ let dir = path34__default.resolve(startDir);
247
247
  for (; ; ) {
248
- const candidate = path35__default.join(dir, "node_modules", ".bin", BIN_NAME);
249
- if (fs24__default.existsSync(candidate)) return candidate;
248
+ const candidate = path34__default.join(dir, "node_modules", ".bin", BIN_NAME);
249
+ if (fs26__default.existsSync(candidate)) return candidate;
250
250
  const fromPackage = resolveFromPackage(dir);
251
251
  if (fromPackage !== null) return fromPackage;
252
- const parent = path35__default.dirname(dir);
252
+ const parent = path34__default.dirname(dir);
253
253
  if (parent === dir) return null;
254
254
  dir = parent;
255
255
  }
@@ -404,7 +404,7 @@ function isGeneratedFile(content) {
404
404
  return content.includes(GENERATED_MARKER);
405
405
  }
406
406
  function isProtectedRoot(filePath, config) {
407
- const relative = path35__default.relative(config.workspaceRoot, filePath);
407
+ const relative = path34__default.relative(config.workspaceRoot, filePath).replace(/\\/g, "/");
408
408
  const isRootLevel = !relative.startsWith("packages/") && !relative.startsWith("tools/") && !relative.startsWith("apps/");
409
409
  return isRootLevel && Array.from(protectedFiles).some(
410
410
  (f) => relative.endsWith(f) || relative.includes(f)
@@ -412,12 +412,12 @@ function isProtectedRoot(filePath, config) {
412
412
  }
413
413
  function isInScope(filePath, config) {
414
414
  if (!config.only || config.only.length === 0) return true;
415
- const relativePath = path35__default.relative(config.workspaceRoot, filePath);
415
+ const relativePath = path34__default.relative(config.workspaceRoot, filePath);
416
416
  return matchesScope(relativePath, config.only);
417
417
  }
418
418
  async function safeWriteFileAtomic(filePath, content, config, report, skipGeneratedCheck = false) {
419
419
  const { dryRun, forceRoot, logger: logger2, workspaceRoot } = config;
420
- const relativePath = path35__default.relative(workspaceRoot, filePath);
420
+ const relativePath = path34__default.relative(workspaceRoot, filePath);
421
421
  if (!isInScope(filePath, config)) {
422
422
  logger2.debug(`skipped (outside --only) ${relativePath}`);
423
423
  return "skipped";
@@ -426,7 +426,7 @@ async function safeWriteFileAtomic(filePath, content, config, report, skipGenera
426
426
  let currentContent = "";
427
427
  let currentHash = "";
428
428
  try {
429
- currentContent = await fs27.readFile(filePath, "utf8");
429
+ currentContent = await fs29.readFile(filePath, "utf8");
430
430
  currentHash = contentHash(currentContent);
431
431
  exists = true;
432
432
  } catch (e) {
@@ -457,20 +457,20 @@ async function safeWriteFileAtomic(filePath, content, config, report, skipGenera
457
457
  return exists ? "updated" : "created";
458
458
  }
459
459
  config.journal?.recordWrite(filePath, exists ? currentContent : null);
460
- await fs27.mkdir(path35__default.dirname(filePath), { recursive: true });
461
- const tmpName = `.${path35__default.basename(filePath)}.${crypto.randomUUID()}.tmp`;
462
- const tmpPath = path35__default.join(path35__default.dirname(filePath), tmpName);
463
- await fs27.writeFile(tmpPath, content, { encoding: "utf8" });
460
+ await fs29.mkdir(path34__default.dirname(filePath), { recursive: true });
461
+ const tmpName = `.${path34__default.basename(filePath)}.${crypto.randomUUID()}.tmp`;
462
+ const tmpPath = path34__default.join(path34__default.dirname(filePath), tmpName);
463
+ await fs29.writeFile(tmpPath, content, { encoding: "utf8" });
464
464
  try {
465
- await fs27.rename(tmpPath, filePath);
465
+ await fs29.rename(tmpPath, filePath);
466
466
  const status = exists ? "updated" : "created";
467
467
  logger2.info(`${status} ${relativePath}`);
468
468
  return status;
469
469
  } catch (err3) {
470
470
  if (err3 instanceof Error && "code" in err3 && err3.code === "EXDEV") {
471
471
  try {
472
- await fs27.copyFile(tmpPath, filePath);
473
- await fs27.unlink(tmpPath);
472
+ await fs29.copyFile(tmpPath, filePath);
473
+ await fs29.unlink(tmpPath);
474
474
  const status = exists ? "updated" : "created";
475
475
  logger2.info(`${status} ${relativePath}`);
476
476
  return status;
@@ -478,7 +478,7 @@ async function safeWriteFileAtomic(filePath, content, config, report, skipGenera
478
478
  logger2.warn(`EXDEV fallback failed for ${relativePath}: ${copyErr}`);
479
479
  }
480
480
  }
481
- await fs27.unlink(tmpPath).catch(() => {
481
+ await fs29.unlink(tmpPath).catch(() => {
482
482
  });
483
483
  throw err3;
484
484
  }
@@ -519,11 +519,33 @@ function resolveEmissionDir(layers, site) {
519
519
  const layer = site.slice(0, slash);
520
520
  return resolveLayerDir(layers, layer, site.slice(slash + 1));
521
521
  }
522
+ function hasDeclaredNames(value) {
523
+ return Array.isArray(value) && value.length > 0;
524
+ }
525
+ function layerDeclaresContent(layerName, contextLayers) {
526
+ if (!contextLayers) return false;
527
+ if (layerName === "domain") {
528
+ const layer = contextLayers.domain;
529
+ if (!layer) return false;
530
+ return hasDeclaredNames(layer.entities) || hasDeclaredNames(layer.value_objects) || hasDeclaredNames(layer.domain_services) || hasDeclaredNames(layer.ports?.in) || hasDeclaredNames(layer.ports?.out);
531
+ }
532
+ if (layerName === "application") {
533
+ const layer = contextLayers.application;
534
+ if (!layer) return false;
535
+ return hasDeclaredNames(layer.use_cases) || hasDeclaredNames(layer.factories) || hasDeclaredNames(layer.ports?.in) || hasDeclaredNames(layer.ports?.out);
536
+ }
537
+ if (layerName === "infrastructure") {
538
+ const layer = contextLayers.infrastructure;
539
+ if (!layer) return false;
540
+ return hasDeclaredNames(layer.adapters);
541
+ }
542
+ return false;
543
+ }
522
544
 
523
545
  // src/generators/layer-folders.ts
524
546
  async function directoryExists(dirPath) {
525
547
  try {
526
- const stats = await fs27.stat(dirPath);
548
+ const stats = await fs29.stat(dirPath);
527
549
  return stats.isDirectory();
528
550
  } catch (e) {
529
551
  if (e instanceof Error && "code" in e && e.code === "ENOENT") {
@@ -535,21 +557,21 @@ async function directoryExists(dirPath) {
535
557
  async function ensureDirectoryCounted(dirPath, config, result) {
536
558
  const existed = await directoryExists(dirPath);
537
559
  if (existed) return;
538
- const relativePath = path35__default.relative(config.workspaceRoot, dirPath);
560
+ const relativePath = path34__default.relative(config.workspaceRoot, dirPath);
539
561
  if (config.dryRun) {
540
562
  config.logger.info(`[DRY-RUN] would create directory ${relativePath}`);
541
563
  } else {
542
- await fs27.mkdir(dirPath, { recursive: true });
564
+ await fs29.mkdir(dirPath, { recursive: true });
543
565
  config.logger.info(`created directory ${relativePath}`);
544
566
  }
545
567
  result.created.push(dirPath);
546
568
  result.totalOps += 1;
547
569
  }
548
570
  async function ensureGitkeepCounted(dirPath, config, result) {
549
- const keepPath = path35__default.join(dirPath, ".gitkeep");
571
+ const keepPath = path34__default.join(dirPath, ".gitkeep");
550
572
  let entries = null;
551
573
  if (await directoryExists(dirPath)) {
552
- entries = await fs27.readdir(dirPath);
574
+ entries = await fs29.readdir(dirPath);
553
575
  }
554
576
  if (entries !== null) {
555
577
  const keepIsOnlyEntry = entries.length === 1 && entries[0] === ".gitkeep";
@@ -557,7 +579,7 @@ async function ensureGitkeepCounted(dirPath, config, result) {
557
579
  return;
558
580
  }
559
581
  if (keepIsOnlyEntry) {
560
- const existing = await fs27.readFile(keepPath, "utf8").catch(() => null);
582
+ const existing = await fs29.readFile(keepPath, "utf8").catch(() => null);
561
583
  if (existing !== null && existing !== "") {
562
584
  return;
563
585
  }
@@ -574,7 +596,7 @@ async function ensureGitkeepCounted(dirPath, config, result) {
574
596
  }
575
597
  async function loadYamlSafe(filePath) {
576
598
  try {
577
- const content = await fs27.readFile(filePath, "utf8");
599
+ const content = await fs29.readFile(filePath, "utf8");
578
600
  return yaml10.load(content);
579
601
  } catch (e) {
580
602
  if (e instanceof Error && "code" in e && e.code === "ENOENT") {
@@ -583,10 +605,10 @@ async function loadYamlSafe(filePath) {
583
605
  throw e;
584
606
  }
585
607
  }
586
- async function ensureLayerFolders(moduleDir, layers, config) {
608
+ async function ensureLayerFolders(moduleDir, layers, config, contextLayers) {
587
609
  const result = createEmptyResult();
588
610
  const { logger: logger2 } = config;
589
- const layerRulesPath = path35__default.join(
611
+ const layerRulesPath = path34__default.join(
590
612
  config.workspaceRoot,
591
613
  ".architecture",
592
614
  "invariants",
@@ -597,8 +619,11 @@ async function ensureLayerFolders(moduleDir, layers, config) {
597
619
  logger2.warn("layer-rules.yaml not found — skipping layer rule enforcement");
598
620
  }
599
621
  for (const [layerName, layerConfig] of Object.entries(layers)) {
600
- const layerPath = path35__default.join(moduleDir, resolveLayerDir(layers, layerName));
601
- if (!isInScope(layerPath, config) && !isInScope(path35__default.join(layerPath, "index.ts"), config)) {
622
+ if (!layerDeclaresContent(layerName, contextLayers)) {
623
+ continue;
624
+ }
625
+ const layerPath = path34__default.join(moduleDir, resolveLayerDir(layers, layerName));
626
+ if (!isInScope(layerPath, config) && !isInScope(path34__default.join(layerPath, "index.ts"), config)) {
602
627
  continue;
603
628
  }
604
629
  await ensureDirectoryCounted(layerPath, config, result);
@@ -614,8 +639,8 @@ async function ensureLayerFolders(moduleDir, layers, config) {
614
639
  );
615
640
  continue;
616
641
  }
617
- const subPath = path35__default.join(layerPath, normalizedSub);
618
- if (!isInScope(subPath, config) && !isInScope(path35__default.join(subPath, "index.ts"), config)) {
642
+ const subPath = path34__default.join(layerPath, normalizedSub);
643
+ if (!isInScope(subPath, config) && !isInScope(path34__default.join(subPath, "index.ts"), config)) {
619
644
  continue;
620
645
  }
621
646
  await ensureDirectoryCounted(subPath, config, result);
@@ -710,16 +735,16 @@ var CircularExportError = class extends Error {
710
735
  };
711
736
  async function generateRecursiveBarrels(moduleDir, config, report) {
712
737
  const result = createEmptyResult();
713
- const srcDir = path35__default.join(moduleDir, "src");
738
+ const srcDir = path34__default.join(moduleDir, "src");
714
739
  const layers = ["domain", "application", "infrastructure"];
715
740
  const pendingWrites = [];
716
741
  const preserved = [];
717
742
  const exportGraph = /* @__PURE__ */ new Map();
718
743
  const layersWithContent = [];
719
744
  for (const layer of layers) {
720
- const layerDir = path35__default.join(srcDir, layer);
745
+ const layerDir = path34__default.join(srcDir, layer);
721
746
  try {
722
- await fs27.access(layerDir);
747
+ await fs29.access(layerDir);
723
748
  } catch {
724
749
  continue;
725
750
  }
@@ -733,7 +758,7 @@ async function generateRecursiveBarrels(moduleDir, config, report) {
733
758
  if (layerExports.length > 0) layersWithContent.push(layer);
734
759
  }
735
760
  if (config.mode === "external" && layersWithContent.length > 0) {
736
- const rootBarrelPath = path35__default.join(srcDir, "index.ts");
761
+ const rootBarrelPath = path34__default.join(srcDir, "index.ts");
737
762
  if (await shouldGenerateBarrel(rootBarrelPath, preserved, config.logger)) {
738
763
  const content = generateBarrelContent(
739
764
  layersWithContent.map((name) => ({ name, isDirectory: true }))
@@ -747,7 +772,7 @@ async function generateRecursiveBarrels(moduleDir, config, report) {
747
772
  });
748
773
  exportGraph.set(
749
774
  rootBarrelPath,
750
- layersWithContent.map((name) => path35__default.join(srcDir, name, "index.ts"))
775
+ layersWithContent.map((name) => path34__default.join(srcDir, name, "index.ts"))
751
776
  );
752
777
  }
753
778
  }
@@ -767,9 +792,9 @@ async function generateRecursiveBarrels(moduleDir, config, report) {
767
792
  continue;
768
793
  }
769
794
  try {
770
- const preContent = await fs27.readFile(pending.filePath, "utf8");
795
+ const preContent = await fs29.readFile(pending.filePath, "utf8");
771
796
  config.journal?.recordDelete(pending.filePath, preContent);
772
- await fs27.unlink(pending.filePath);
797
+ await fs29.unlink(pending.filePath);
773
798
  result.deleted.push(pending.filePath);
774
799
  result.totalOps++;
775
800
  continue;
@@ -796,7 +821,7 @@ async function walkDirectory(dirPath, pendingWrites, preserved, exportGraph, con
796
821
  const exportEntries = [];
797
822
  let entries;
798
823
  try {
799
- entries = await fs27.readdir(dirPath, { withFileTypes: true });
824
+ entries = await fs29.readdir(dirPath, { withFileTypes: true });
800
825
  } catch {
801
826
  return exportEntries;
802
827
  }
@@ -813,7 +838,7 @@ async function walkDirectory(dirPath, pendingWrites, preserved, exportGraph, con
813
838
  }
814
839
  }
815
840
  for (const dir of directories) {
816
- const subDirPath = path35__default.join(dirPath, dir);
841
+ const subDirPath = path34__default.join(dirPath, dir);
817
842
  const subExports = await walkDirectory(
818
843
  subDirPath,
819
844
  pendingWrites,
@@ -821,7 +846,7 @@ async function walkDirectory(dirPath, pendingWrites, preserved, exportGraph, con
821
846
  exportGraph,
822
847
  config
823
848
  );
824
- const subBarrelPath = path35__default.join(subDirPath, "index.ts");
849
+ const subBarrelPath = path34__default.join(subDirPath, "index.ts");
825
850
  const isQueuedForDeletion = pendingWrites.some(
826
851
  (p) => p.filePath === subBarrelPath && p.content === ""
827
852
  );
@@ -833,59 +858,24 @@ async function walkDirectory(dirPath, pendingWrites, preserved, exportGraph, con
833
858
  exportEntries.push({ name: file, isDirectory: false });
834
859
  }
835
860
  if (exportEntries.length === 0) {
836
- const barrelPath2 = path35__default.join(dirPath, "index.ts");
861
+ const barrelPath2 = path34__default.join(dirPath, "index.ts");
837
862
  const existingBarrel = await readFileIfExists(barrelPath2);
838
- const dirName = path35__default.basename(dirPath);
839
- const isLayerDir = ["domain", "application", "infrastructure"].includes(
840
- dirName
841
- );
842
863
  if (existingBarrel) {
843
864
  const isGenerated = isGeneratedFile2(existingBarrel);
844
- const isEmptyStub = existingBarrel.includes("export {}");
845
- if ((isGenerated || isEmptyStub) && !isLayerDir) {
865
+ const statements = existingBarrel.split("\n").map((line) => line.trim()).filter((line) => line.length > 0 && !line.startsWith("//"));
866
+ const isEmptyStub = statements.length === 1 && /^export\s*\{\s*\}\s*;?$/.test(statements[0]);
867
+ if (isGenerated || isEmptyStub) {
846
868
  pendingWrites.push({
847
869
  filePath: barrelPath2,
848
870
  content: "",
849
871
  // Empty content signals deletion
850
872
  isNew: false
851
873
  });
852
- } else if (isEmptyStub && isLayerDir) {
853
- const newContent = `${GENERATED_MARKER2}
854
-
855
- export {};
856
- `;
857
- if (contentHash2(existingBarrel) !== contentHash2(newContent)) {
858
- pendingWrites.push({
859
- filePath: barrelPath2,
860
- content: newContent,
861
- isNew: false
862
- });
863
- }
864
- } else if (!existingBarrel.includes("export {}") && isLayerDir) {
865
- const newContent = `${GENERATED_MARKER2}
866
-
867
- export {};
868
- `;
869
- pendingWrites.push({
870
- filePath: barrelPath2,
871
- content: newContent,
872
- isNew: false
873
- });
874
874
  }
875
- } else if (isLayerDir) {
876
- const newContent = `${GENERATED_MARKER2}
877
-
878
- export {};
879
- `;
880
- pendingWrites.push({
881
- filePath: barrelPath2,
882
- content: newContent,
883
- isNew: true
884
- });
885
875
  }
886
876
  return [];
887
877
  }
888
- const barrelPath = path35__default.join(dirPath, "index.ts");
878
+ const barrelPath = path34__default.join(dirPath, "index.ts");
889
879
  const shouldCreateBarrel = await shouldGenerateBarrel(
890
880
  barrelPath,
891
881
  preserved,
@@ -905,14 +895,14 @@ export {};
905
895
  content,
906
896
  isNew: !existingContent
907
897
  });
908
- const exportPaths = exportEntries.filter((e) => e.isDirectory).map((e) => path35__default.join(dirPath, e.name, "index.ts"));
898
+ const exportPaths = exportEntries.filter((e) => e.isDirectory).map((e) => path34__default.join(dirPath, e.name, "index.ts"));
909
899
  exportGraph.set(barrelPath, exportPaths);
910
900
  }
911
901
  return exportEntries;
912
902
  }
913
903
  async function hasBarrel(dirPath) {
914
904
  try {
915
- await fs27.access(path35__default.join(dirPath, "index.ts"));
905
+ await fs29.access(path34__default.join(dirPath, "index.ts"));
916
906
  return true;
917
907
  } catch {
918
908
  return false;
@@ -932,7 +922,7 @@ async function shouldGenerateBarrel(barrelPath, preserved, logger2) {
932
922
  }
933
923
  async function readFileIfExists(filePath) {
934
924
  try {
935
- return await fs27.readFile(filePath, "utf8");
925
+ return await fs29.readFile(filePath, "utf8");
936
926
  } catch (err3) {
937
927
  if (err3 && typeof err3 === "object" && "code" in err3 && err3.code === "ENOENT") {
938
928
  return null;
@@ -992,7 +982,7 @@ async function generatePackageJson(modulePath, moduleName, config, report) {
992
982
  const moduleOverrides = context?.packageJson ?? {};
993
983
  const scope = config.manifest ? resolveScope(config.manifest) : "generated-project";
994
984
  const dependsOnDeps = context ? expandDependsOn(context, scope) : {};
995
- const pkgPath = path35__default.join(modulePath, "package.json");
985
+ const pkgPath = path34__default.join(modulePath, "package.json");
996
986
  const dependencies = {
997
987
  ...dependsOnDeps,
998
988
  ...defaults.dependencies ?? {},
@@ -1044,7 +1034,7 @@ async function generatePackageJson(modulePath, moduleName, config, report) {
1044
1034
  };
1045
1035
  let currentPkg = {};
1046
1036
  try {
1047
- const currentContent = await fs27.readFile(pkgPath, "utf8");
1037
+ const currentContent = await fs29.readFile(pkgPath, "utf8");
1048
1038
  currentPkg = JSON.parse(currentContent);
1049
1039
  } catch (e) {
1050
1040
  if (!(e instanceof Error && "code" in e && e.code === "ENOENT")) {
@@ -1086,11 +1076,11 @@ async function generatePackageJson(modulePath, moduleName, config, report) {
1086
1076
  );
1087
1077
  recordWriteStatus(result, pkgPath, status);
1088
1078
  if (config.mode === "external") {
1089
- const vitestConfigPath = path35__default.join(modulePath, "vitest.config.ts");
1079
+ const vitestConfigPath = path34__default.join(modulePath, "vitest.config.ts");
1090
1080
  if (isInScope(vitestConfigPath, config)) {
1091
1081
  let vitestConfigExists = false;
1092
1082
  try {
1093
- await fs27.stat(vitestConfigPath);
1083
+ await fs29.stat(vitestConfigPath);
1094
1084
  vitestConfigExists = true;
1095
1085
  } catch (e) {
1096
1086
  if (!(e instanceof Error && "code" in e && e.code === "ENOENT")) {
@@ -1187,7 +1177,7 @@ function buildTemplate(base, context, scope) {
1187
1177
  }
1188
1178
  async function generateTsconfig(moduleDir, moduleName, config, report) {
1189
1179
  const result = createEmptyResult();
1190
- const filePath = path35__default.join(moduleDir, "tsconfig.json");
1180
+ const filePath = path34__default.join(moduleDir, "tsconfig.json");
1191
1181
  try {
1192
1182
  const base = resolveWorkspaceTemplate(config.manifest);
1193
1183
  const context = config.manifest.bounded_contexts?.find(
@@ -1213,19 +1203,50 @@ async function generateTsconfig(moduleDir, moduleName, config, report) {
1213
1203
  return result;
1214
1204
  }
1215
1205
  }
1206
+ var SRC_INDEX_STUB = `${GENERATED_MARKER2}
1207
+
1208
+ export {};
1209
+ `;
1210
+ async function ensurePackageSrcIndex(moduleDir, config, report) {
1211
+ const result = createEmptyResult();
1212
+ const filePath = path34__default.join(moduleDir, "src", "index.ts");
1213
+ if (!isInScope(filePath, config)) {
1214
+ result.skipped.push(filePath);
1215
+ return result;
1216
+ }
1217
+ try {
1218
+ await fs29.stat(filePath);
1219
+ result.skipped.push(filePath);
1220
+ return result;
1221
+ } catch (err3) {
1222
+ if (err3.code !== "ENOENT") throw err3;
1223
+ }
1224
+ if (!config.dryRun) {
1225
+ await fs29.mkdir(path34__default.dirname(filePath), { recursive: true });
1226
+ }
1227
+ const status = await safeWriteFileAtomic(
1228
+ filePath,
1229
+ SRC_INDEX_STUB,
1230
+ config,
1231
+ report,
1232
+ false
1233
+ );
1234
+ recordWriteStatus(result, filePath, status);
1235
+ return result;
1236
+ }
1216
1237
  async function reapLegacyFolders(moduleDir, config, report) {
1217
1238
  const { dryRun, logger: logger2 } = config;
1218
1239
  const legacyLayers = ["domain", "application", "infrastructure"];
1219
1240
  for (const layer of legacyLayers) {
1220
- const layerPath = path35__default.join(moduleDir, layer);
1221
- const relativePath = path35__default.relative(config.workspaceRoot, layerPath);
1241
+ const layerPath = path34__default.join(moduleDir, layer);
1242
+ const relativePath = path34__default.relative(config.workspaceRoot, layerPath);
1222
1243
  try {
1223
- const entries = await fs27.readdir(layerPath);
1244
+ const entries = await fs29.readdir(layerPath);
1224
1245
  if (entries.length === 0) {
1225
1246
  if (dryRun) {
1226
1247
  logger2.info(`[DRY-RUN] would delete empty folder ${relativePath}`);
1227
1248
  } else {
1228
- await fs27.rmdir(layerPath);
1249
+ await fs29.rmdir(layerPath);
1229
1250
  logger2.info(`deleted empty folder ${relativePath}`);
1230
1251
  if (report) report.record("deleted", layerPath);
1231
1252
  }
@@ -1287,6 +1308,33 @@ function interpolate(template, vars) {
1287
1308
  });
1288
1309
  return { output, warnings };
1289
1310
  }
1311
+ var CURRENT_SCHEMA_VERSION = "1.0.0";
1312
+ function majorOf(version) {
1313
+ const match = /^(\d+)(?:\.|$)/.exec(version);
1314
+ return match ? match[1] : null;
1315
+ }
1316
+ var SUPPORTED_MAJOR = majorOf(CURRENT_SCHEMA_VERSION);
1317
+ z.object({
1318
+ schemaVersion: z.string({ required_error: "schemaVersion is required" }).refine((v) => majorOf(v) !== null, {
1319
+ message: "schemaVersion must start with a numeric major, e.g. '1.0.0'"
1320
+ }).refine((v) => majorOf(v) === SUPPORTED_MAJOR, {
1321
+ message: `Unsupported schemaVersion major; this consumer understands ${SUPPORTED_MAJOR}.x`
1322
+ }),
1323
+ // `layout` is the raw TEXT of the producer's .architecture/layout.yaml, not
1324
+ // a structured object: packages/sync reads that file, and the web adapter
1325
+ // guards on `typeof rec.layout === "string"` before clipping it to an
1326
+ // excerpt. A looser z.unknown() here let a structured fixture through that
1327
+ // the real consumer would silently ignore.
1328
+ layout: z.string().nullable().optional(),
1329
+ // Nullable like its siblings: the producer emits an explicit null when the
1330
+ // count is unknown (the linter prints "Files scanned" on inherited stdio,
1331
+ // so scan cannot see it until BF-0.3 captures that stream). Making this
1332
+ // optional-but-not-nullable would force the producer to choose between
1333
+ // omitting the key and failing its own schema.
1334
+ filesScanned: z.number().int().min(0).nullable().optional(),
1335
+ reportMarkdown: z.string().nullable().optional(),
1336
+ error: z.string().nullable().optional()
1337
+ }).passthrough();
1290
1338
 
1291
1339
  // src/generators/root-file-templates.ts
1292
1340
  var BUILTIN_PACKAGE_JSON_TEMPLATE = `{
@@ -1451,7 +1499,7 @@ function assertValidToolchainVersion(version, source) {
1451
1499
  function resolveToolchainVersion() {
1452
1500
  {
1453
1501
  return assertValidToolchainVersion(
1454
- "0.11.0",
1502
+ "0.12.1",
1455
1503
  "build-injected __HEXAGEN_TOOLCHAIN_VERSION__"
1456
1504
  );
1457
1505
  }
@@ -1545,7 +1593,7 @@ async function generateRootFiles(config, report) {
1545
1593
  "package.json"
1546
1594
  );
1547
1595
  await writeRootFile(
1548
- path35__default.join(config.workspaceRoot, "package.json"),
1596
+ path34__default.join(config.workspaceRoot, "package.json"),
1549
1597
  packageJsonContent,
1550
1598
  config,
1551
1599
  report,
@@ -1562,7 +1610,7 @@ async function generateRootFiles(config, report) {
1562
1610
  "tsconfig.base.json"
1563
1611
  );
1564
1612
  await writeRootFile(
1565
- path35__default.join(config.workspaceRoot, "tsconfig.base.json"),
1613
+ path34__default.join(config.workspaceRoot, "tsconfig.base.json"),
1566
1614
  tsconfigContent,
1567
1615
  config,
1568
1616
  report,
@@ -1577,7 +1625,7 @@ async function generateRootFiles(config, report) {
1577
1625
  "turbo.json"
1578
1626
  );
1579
1627
  await writeRootFile(
1580
- path35__default.join(config.workspaceRoot, "turbo.json"),
1628
+ path34__default.join(config.workspaceRoot, "turbo.json"),
1581
1629
  turboContent,
1582
1630
  config,
1583
1631
  report,
@@ -1588,7 +1636,7 @@ async function generateRootFiles(config, report) {
1588
1636
  BUILTIN_GITIGNORE_TEMPLATE
1589
1637
  );
1590
1638
  await writeRootFile(
1591
- path35__default.join(config.workspaceRoot, ".gitignore"),
1639
+ path34__default.join(config.workspaceRoot, ".gitignore"),
1592
1640
  interpolateAndWarn(gitignoreTemplate, vars, config, ".gitignore"),
1593
1641
  config,
1594
1642
  report,
@@ -1599,7 +1647,7 @@ async function generateRootFiles(config, report) {
1599
1647
  BUILTIN_YARNRC_TEMPLATE
1600
1648
  );
1601
1649
  await writeRootFile(
1602
- path35__default.join(config.workspaceRoot, ".yarnrc.yml"),
1650
+ path34__default.join(config.workspaceRoot, ".yarnrc.yml"),
1603
1651
  interpolateAndWarn(yarnrcTemplate, vars, config, ".yarnrc.yml"),
1604
1652
  config,
1605
1653
  report,
@@ -1610,7 +1658,7 @@ async function generateRootFiles(config, report) {
1610
1658
  BUILTIN_SETUP_MD_TEMPLATE
1611
1659
  );
1612
1660
  await writeRootFile(
1613
- path35__default.join(config.workspaceRoot, "SETUP.md"),
1661
+ path34__default.join(config.workspaceRoot, "SETUP.md"),
1614
1662
  interpolateAndWarn(setupTemplate, vars, config, "SETUP.md"),
1615
1663
  config,
1616
1664
  report,
@@ -1901,9 +1949,9 @@ async function writeManifestIfFreshExternal(config, result, report) {
1901
1949
  if (config.mode !== "external") {
1902
1950
  return;
1903
1951
  }
1904
- const archDir = path35__default.join(config.workspaceRoot, ".architecture");
1905
- const manifestPath = path35__default.join(archDir, "manifest.yaml");
1906
- const relative = path35__default.relative(config.workspaceRoot, manifestPath);
1952
+ const archDir = path34__default.join(config.workspaceRoot, ".architecture");
1953
+ const manifestPath = path34__default.join(archDir, "manifest.yaml");
1954
+ const relative = path34__default.relative(config.workspaceRoot, manifestPath);
1907
1955
  if (!isInScope(manifestPath, config)) {
1908
1956
  config.logger.debug(`skipped (outside --only) ${relative}`);
1909
1957
  result.skipped.push(manifestPath);
@@ -1911,7 +1959,7 @@ async function writeManifestIfFreshExternal(config, result, report) {
1911
1959
  }
1912
1960
  let exists = false;
1913
1961
  try {
1914
- await fs27.access(manifestPath);
1962
+ await fs29.access(manifestPath);
1915
1963
  exists = true;
1916
1964
  } catch {
1917
1965
  exists = false;
@@ -1931,8 +1979,8 @@ async function writeManifestIfFreshExternal(config, result, report) {
1931
1979
  }
1932
1980
  const content = yaml10.dump(config.manifest);
1933
1981
  config.journal?.recordWrite(manifestPath, null);
1934
- await fs27.mkdir(archDir, { recursive: true });
1935
- await fs27.writeFile(manifestPath, content, { encoding: "utf8" });
1982
+ await fs29.mkdir(archDir, { recursive: true });
1983
+ await fs29.writeFile(manifestPath, content, { encoding: "utf8" });
1936
1984
  config.logger.info(`created ${relative}`);
1937
1985
  if (report)
1938
1986
  report.record(
@@ -1946,7 +1994,7 @@ async function writeManifestIfFreshExternal(config, result, report) {
1946
1994
  async function generateArchitectureFiles(config, report) {
1947
1995
  const result = createEmptyResult();
1948
1996
  const manifest = config.manifest;
1949
- const archRoot = path35__default.join(config.workspaceRoot, ".architecture");
1997
+ const archRoot = path34__default.join(config.workspaceRoot, ".architecture");
1950
1998
  const archInvariants = manifest.monorepo?.archInvariants;
1951
1999
  const { vars, ownershipCollisions } = buildInterpolationVars(manifest);
1952
2000
  const workspaceTemplate = vars.workspaceTemplate ?? "modular-monolith";
@@ -1956,7 +2004,7 @@ async function generateArchitectureFiles(config, report) {
1956
2004
  );
1957
2005
  }
1958
2006
  await writeManifestIfFreshExternal(config, result, report);
1959
- const layerRulesPath = path35__default.join(archRoot, "invariants", "layer-rules.yaml");
2007
+ const layerRulesPath = path34__default.join(archRoot, "invariants", "layer-rules.yaml");
1960
2008
  const layerRulesTemplate = resolveTemplate2(
1961
2009
  archInvariants?.layerRules,
1962
2010
  builtInLayerRules(workspaceTemplate)
@@ -1975,7 +2023,7 @@ async function generateArchitectureFiles(config, report) {
1975
2023
  true
1976
2024
  );
1977
2025
  recordWriteStatus(result, layerRulesPath, layerRulesStatus);
1978
- const linterConfigPath = path35__default.join(
2026
+ const linterConfigPath = path34__default.join(
1979
2027
  archRoot,
1980
2028
  "invariants",
1981
2029
  "linter-config.yaml"
@@ -1998,7 +2046,7 @@ async function generateArchitectureFiles(config, report) {
1998
2046
  true
1999
2047
  );
2000
2048
  recordWriteStatus(result, linterConfigPath, linterConfigStatus);
2001
- const generatorConfigPath = path35__default.join(archRoot, "generator.config.yaml");
2049
+ const generatorConfigPath = path34__default.join(archRoot, "generator.config.yaml");
2002
2050
  const generatorConfigTemplate = resolveTemplate2(
2003
2051
  archInvariants?.generatorConfig,
2004
2052
  GENERATOR_CONFIG_TEMPLATE
@@ -2936,7 +2984,7 @@ ${content}`;
2936
2984
  }
2937
2985
  async function generateEslintConfig(moduleDir, moduleName, config, report, options = {}) {
2938
2986
  const result = createEmptyResult();
2939
- const filePath = path35__default.join(moduleDir, "eslint.config.js");
2987
+ const filePath = path34__default.join(moduleDir, "eslint.config.js");
2940
2988
  try {
2941
2989
  const { template, source } = resolveTemplate3(
2942
2990
  config.manifest,
@@ -3024,9 +3072,9 @@ async function emitAppFile(appDir, relPath, template, vars, config, report, resu
3024
3072
  `apps/${appName}/${relPath}`,
3025
3073
  config
3026
3074
  );
3027
- const target = path35__default.resolve(appDir, relPath);
3028
- const relative = path35__default.relative(appDir, target);
3029
- if (relative === "" || relative.startsWith("..") || path35__default.isAbsolute(relative)) {
3075
+ const target = path34__default.resolve(appDir, relPath);
3076
+ const relative = path34__default.relative(appDir, target);
3077
+ if (relative === "" || relative.startsWith("..") || path34__default.isAbsolute(relative)) {
3030
3078
  config.logger.warn(
3031
3079
  `[apps] skipping file with unsafe path (escapes apps/${appName}): ${relPath}`
3032
3080
  );
@@ -3041,7 +3089,7 @@ async function emitAppFile(appDir, relPath, template, vars, config, report, resu
3041
3089
  }
3042
3090
  if (!config.dryRun && isInScope(target, config)) {
3043
3091
  try {
3044
- await fs27.mkdir(path35__default.dirname(target), { recursive: true });
3092
+ await fs29.mkdir(path34__default.dirname(target), { recursive: true });
3045
3093
  } catch (err3) {
3046
3094
  const message = err3 instanceof Error ? err3.message : String(err3);
3047
3095
  config.logger.error(
@@ -3132,12 +3180,12 @@ async function generateApps(config, report) {
3132
3180
  version: app.version ?? "",
3133
3181
  depends_on: (app.depends_on ?? []).join(", ")
3134
3182
  };
3135
- const appDir = path35__default.join(config.workspaceRoot, "apps", app.name);
3136
- const srcDir = path35__default.join(appDir, "src");
3183
+ const appDir = path34__default.join(config.workspaceRoot, "apps", app.name);
3184
+ const srcDir = path34__default.join(appDir, "src");
3137
3185
  if (!config.dryRun && isInScope(appDir, config)) {
3138
3186
  try {
3139
- await fs27.mkdir(appDir, { recursive: true });
3140
- await fs27.mkdir(srcDir, { recursive: true });
3187
+ await fs29.mkdir(appDir, { recursive: true });
3188
+ await fs29.mkdir(srcDir, { recursive: true });
3141
3189
  } catch (err3) {
3142
3190
  const message = err3 instanceof Error ? err3.message : String(err3);
3143
3191
  config.logger.error(
@@ -3155,7 +3203,7 @@ async function generateApps(config, report) {
3155
3203
  `apps/${app.name}/package.json`,
3156
3204
  config
3157
3205
  );
3158
- const pkgPath = path35__default.join(appDir, "package.json");
3206
+ const pkgPath = path34__default.join(appDir, "package.json");
3159
3207
  const status = await safeWriteFileAtomic(
3160
3208
  pkgPath,
3161
3209
  pkgContent,
@@ -3171,7 +3219,7 @@ async function generateApps(config, report) {
3171
3219
  const tsConfig = frameworkConfig.tsConfig;
3172
3220
  if (tsConfig) {
3173
3221
  const tsContent = JSON.stringify(tsConfig, null, 2) + "\n";
3174
- const tsPath = path35__default.join(appDir, "tsconfig.json");
3222
+ const tsPath = path34__default.join(appDir, "tsconfig.json");
3175
3223
  const status = await safeWriteFileAtomic(
3176
3224
  tsPath,
3177
3225
  tsContent,
@@ -3238,14 +3286,14 @@ async function generateApps(config, report) {
3238
3286
  }
3239
3287
  }
3240
3288
  function relativeImportSpecifier(fromFile, toFile) {
3241
- let rel = path35__default.relative(path35__default.dirname(fromFile), toFile).split(path35__default.sep).join("/").replace(/\.tsx?$/, ".js");
3289
+ let rel = path34__default.relative(path34__default.dirname(fromFile), toFile).split(path34__default.sep).join("/").replace(/\.tsx?$/, ".js");
3242
3290
  if (!rel.startsWith(".")) rel = `./${rel}`;
3243
3291
  return rel;
3244
3292
  }
3245
3293
  function rewriteRelativeSpecifier(specifier, fromFile, toFile) {
3246
3294
  if (!specifier.startsWith(".")) return specifier;
3247
- const absolute = path35__default.resolve(path35__default.dirname(fromFile), specifier);
3248
- let rel = path35__default.relative(path35__default.dirname(toFile), absolute).split(path35__default.sep).join("/");
3295
+ const absolute = path34__default.resolve(path34__default.dirname(fromFile), specifier);
3296
+ let rel = path34__default.relative(path34__default.dirname(toFile), absolute).split(path34__default.sep).join("/");
3249
3297
  if (!rel.startsWith(".")) rel = `./${rel}`;
3250
3298
  return rel;
3251
3299
  }
@@ -3884,13 +3932,13 @@ function resolveNaming(kind, contextNaming, manifestNaming) {
3884
3932
  async function writeStubFile(filePath, content, config, report) {
3885
3933
  if (!isInScope(filePath, config)) {
3886
3934
  config.logger.debug(
3887
- `skipped (outside --only) ${path35__default.relative(config.workspaceRoot, filePath)}`
3935
+ `skipped (outside --only) ${path34__default.relative(config.workspaceRoot, filePath)}`
3888
3936
  );
3889
3937
  return "skipped";
3890
3938
  }
3891
3939
  try {
3892
- await fs27.stat(filePath);
3893
- const relative = path35__default.relative(config.workspaceRoot, filePath);
3940
+ await fs29.stat(filePath);
3941
+ const relative = path34__default.relative(config.workspaceRoot, filePath);
3894
3942
  config.logger.debug(`stub preserved ${relative}`);
3895
3943
  if (report) {
3896
3944
  report.record(
@@ -3906,7 +3954,7 @@ async function writeStubFile(filePath, content, config, report) {
3906
3954
  }
3907
3955
  }
3908
3956
  if (!config.dryRun) {
3909
- await fs27.mkdir(path35__default.dirname(filePath), { recursive: true });
3957
+ await fs29.mkdir(path34__default.dirname(filePath), { recursive: true });
3910
3958
  }
3911
3959
  return safeWriteFileAtomic(filePath, content, config, report, false);
3912
3960
  }
@@ -3929,7 +3977,7 @@ async function tryAnalyzeRelatedPort(moduleDir, name, kind, context, relatedPort
3929
3977
  `${derivedPortName}.ts`
3930
3978
  ];
3931
3979
  for (const filename of possibleFilenames) {
3932
- const portFilePath = path35__default.join(moduleDir, portSubdir, filename);
3980
+ const portFilePath = path34__default.join(moduleDir, portSubdir, filename);
3933
3981
  const analysis = analyzePortFile(portFilePath);
3934
3982
  if (analysis) {
3935
3983
  return analysis;
@@ -3985,7 +4033,7 @@ async function generateStubs(moduleDir, moduleName, config, report) {
3985
4033
  `stubs.naming.${kind}`,
3986
4034
  interpolation
3987
4035
  );
3988
- const filePath = path35__default.join(moduleDir, subdir, filename);
4036
+ const filePath = path34__default.join(moduleDir, subdir, filename);
3989
4037
  let content;
3990
4038
  if (kind === "adapter" || kind === "useCase") {
3991
4039
  const relatedPortNaming = resolveNaming(
@@ -4015,7 +4063,7 @@ async function generateStubs(moduleDir, moduleName, config, report) {
4015
4063
  contextNaming,
4016
4064
  manifestNaming
4017
4065
  );
4018
- const outPortDir = path35__default.join(
4066
+ const outPortDir = path34__default.join(
4019
4067
  moduleDir,
4020
4068
  resolveEmissionDir(layersConfig, "application/ports/out")
4021
4069
  );
@@ -4027,7 +4075,7 @@ async function generateStubs(moduleDir, moduleName, config, report) {
4027
4075
  "stubs.naming.outPort",
4028
4076
  interpolation
4029
4077
  );
4030
- const outPortPath = path35__default.join(outPortDir, outFile);
4078
+ const outPortPath = path34__default.join(outPortDir, outFile);
4031
4079
  const analyzed = analyzePortFile(outPortPath);
4032
4080
  return {
4033
4081
  interfaceName: analyzed?.interfaceName ?? `${base}Port`,
@@ -4130,19 +4178,19 @@ ${methodLines}
4130
4178
  `;
4131
4179
  }
4132
4180
  async function emitPortAndAdapter(result, config, report, scope, spec) {
4133
- const moduleRoot = path35__default.join(
4181
+ const moduleRoot = path34__default.join(
4134
4182
  config.workspaceRoot,
4135
4183
  "packages",
4136
4184
  spec.contextName
4137
4185
  );
4138
- const portDir = path35__default.join(
4186
+ const portDir = path34__default.join(
4139
4187
  moduleRoot,
4140
4188
  "src",
4141
4189
  "application",
4142
4190
  "ports",
4143
4191
  spec.portKind
4144
4192
  );
4145
- const portPath = path35__default.join(
4193
+ const portPath = path34__default.join(
4146
4194
  portDir,
4147
4195
  `${spec.portBase}.${spec.portKind}-port.ts`
4148
4196
  );
@@ -4150,7 +4198,7 @@ async function emitPortAndAdapter(result, config, report, scope, spec) {
4150
4198
  return;
4151
4199
  }
4152
4200
  if (!config.dryRun) {
4153
- await fs27.mkdir(portDir, { recursive: true });
4201
+ await fs29.mkdir(portDir, { recursive: true });
4154
4202
  }
4155
4203
  recordWriteStatus(
4156
4204
  result,
@@ -4175,13 +4223,13 @@ async function emitPortAndAdapter(result, config, report, scope, spec) {
4175
4223
  );
4176
4224
  return;
4177
4225
  }
4178
- const adapterDir = path35__default.join(moduleRoot, "src", "infrastructure", "adapters");
4179
- const adapterPath = path35__default.join(adapterDir, `${spec.portBase}.adapter.ts`);
4226
+ const adapterDir = path34__default.join(moduleRoot, "src", "infrastructure", "adapters");
4227
+ const adapterPath = path34__default.join(adapterDir, `${spec.portBase}.adapter.ts`);
4180
4228
  if (!isInScope(adapterPath, config)) {
4181
4229
  return;
4182
4230
  }
4183
4231
  if (!config.dryRun) {
4184
- await fs27.mkdir(adapterDir, { recursive: true });
4232
+ await fs29.mkdir(adapterDir, { recursive: true });
4185
4233
  }
4186
4234
  const adapterClassName = `${toPascalCaseIdentifier(spec.portBase)}Adapter`;
4187
4235
  const portSpecifier = relativeImportSpecifier(adapterPath, portPath);
@@ -4208,7 +4256,7 @@ function operationImports(ops) {
4208
4256
  return ops.flatMap((op) => [`${op}Request`, `${op}Response`]);
4209
4257
  }
4210
4258
  async function writeSharedContract(result, config, report, relSegments, content) {
4211
- const contractPath = path35__default.join(
4259
+ const contractPath = path34__default.join(
4212
4260
  config.workspaceRoot,
4213
4261
  "packages",
4214
4262
  "shared",
@@ -4216,7 +4264,7 @@ async function writeSharedContract(result, config, report, relSegments, content)
4216
4264
  ...relSegments
4217
4265
  );
4218
4266
  if (!config.dryRun) {
4219
- await fs27.mkdir(path35__default.dirname(contractPath), { recursive: true });
4267
+ await fs29.mkdir(path34__default.dirname(contractPath), { recursive: true });
4220
4268
  }
4221
4269
  recordWriteStatus(
4222
4270
  result,
@@ -4368,7 +4416,7 @@ async function generateSharedKernel(config, report) {
4368
4416
  (bc) => bc.name?.toLowerCase() === "shared"
4369
4417
  );
4370
4418
  if (!hasShared) return result;
4371
- const kernelPath = path35__default.join(
4419
+ const kernelPath = path34__default.join(
4372
4420
  config.workspaceRoot,
4373
4421
  "packages",
4374
4422
  "shared",
@@ -4381,14 +4429,14 @@ async function generateSharedKernel(config, report) {
4381
4429
  return result;
4382
4430
  }
4383
4431
  try {
4384
- await fs27.stat(kernelPath);
4432
+ await fs29.stat(kernelPath);
4385
4433
  result.skipped.push(kernelPath);
4386
4434
  return result;
4387
4435
  } catch (err3) {
4388
4436
  if (err3.code !== "ENOENT") throw err3;
4389
4437
  }
4390
4438
  if (!config.dryRun) {
4391
- await fs27.mkdir(path35__default.dirname(kernelPath), { recursive: true });
4439
+ await fs29.mkdir(path34__default.dirname(kernelPath), { recursive: true });
4392
4440
  }
4393
4441
  const status = await safeWriteFileAtomic(
4394
4442
  kernelPath,
@@ -4867,21 +4915,21 @@ var WorkspaceConfigSchema = z.object({
4867
4915
  turboConfig: z.record(z.unknown()).optional()
4868
4916
  }).passthrough();
4869
4917
  function assertPathWithinArchitecture(workspaceRoot, relativePath) {
4870
- const resolved = path35__default.resolve(workspaceRoot, ".architecture", relativePath);
4871
- const archRoot = path35__default.resolve(workspaceRoot, ".architecture");
4918
+ const resolved = path34__default.resolve(workspaceRoot, ".architecture", relativePath);
4919
+ const archRoot = path34__default.resolve(workspaceRoot, ".architecture");
4872
4920
  try {
4873
4921
  const realResolved = realpathSync(resolved);
4874
4922
  const realArchRoot = realpathSync(archRoot);
4875
- const archRootWithSep = realArchRoot + path35__default.sep;
4923
+ const archRootWithSep = realArchRoot + path34__default.sep;
4876
4924
  if (realResolved !== realArchRoot && !realResolved.startsWith(archRootWithSep)) {
4877
4925
  throw new Error(`Path traversal detected: "${relativePath}" resolves outside .architecture/`);
4878
4926
  }
4879
4927
  } catch (err3) {
4880
4928
  if (err3 instanceof Error && "code" in err3 && err3.code === "ENOENT") {
4881
4929
  let checkPath = archRoot;
4882
- const pathSegments = path35__default.relative(archRoot, resolved).split(path35__default.sep);
4930
+ const pathSegments = path34__default.relative(archRoot, resolved).split(path34__default.sep);
4883
4931
  for (const segment of pathSegments) {
4884
- checkPath = path35__default.join(checkPath, segment);
4932
+ checkPath = path34__default.join(checkPath, segment);
4885
4933
  try {
4886
4934
  const stat = lstatSync(checkPath);
4887
4935
  if (stat.isSymbolicLink()) {
@@ -4897,7 +4945,7 @@ function assertPathWithinArchitecture(workspaceRoot, relativePath) {
4897
4945
  throw statErr;
4898
4946
  }
4899
4947
  }
4900
- const archRootWithSep = archRoot + path35__default.sep;
4948
+ const archRootWithSep = archRoot + path34__default.sep;
4901
4949
  if (resolved !== archRoot && !resolved.startsWith(archRootWithSep)) {
4902
4950
  throw new Error(`Path traversal detected: "${relativePath}" resolves outside .architecture/`);
4903
4951
  }
@@ -4907,7 +4955,7 @@ function assertPathWithinArchitecture(workspaceRoot, relativePath) {
4907
4955
  }
4908
4956
  }
4909
4957
  async function mergeSplitManifest(workspaceRoot, manifestPath) {
4910
- const content = await fs27.readFile(manifestPath, "utf-8");
4958
+ const content = await fs29.readFile(manifestPath, "utf-8");
4911
4959
  const parsed = yaml10.load(content);
4912
4960
  if (parsed == null) {
4913
4961
  throw new Error("Manifest file is empty");
@@ -4936,10 +4984,10 @@ async function mergeSplitManifest(workspaceRoot, manifestPath) {
4936
4984
  };
4937
4985
  if (typeof index.workspace_config === "string") {
4938
4986
  assertPathWithinArchitecture(workspaceRoot, index.workspace_config);
4939
- const sideCarPath = path35__default.join(workspaceRoot, ".architecture", index.workspace_config);
4987
+ const sideCarPath = path34__default.join(workspaceRoot, ".architecture", index.workspace_config);
4940
4988
  let sideCarContent;
4941
4989
  try {
4942
- sideCarContent = await fs27.readFile(sideCarPath, "utf-8");
4990
+ sideCarContent = await fs29.readFile(sideCarPath, "utf-8");
4943
4991
  } catch (err3) {
4944
4992
  if (err3 instanceof Error && "code" in err3 && err3.code === "ENOENT") {
4945
4993
  throw new Error(`Workspace config file not found: ${sideCarPath}`);
@@ -4962,10 +5010,10 @@ async function mergeSplitManifest(workspaceRoot, manifestPath) {
4962
5010
  for (const entry of indexContexts) {
4963
5011
  const indexEntry = entry;
4964
5012
  assertPathWithinArchitecture(workspaceRoot, indexEntry.file);
4965
- const contextFilePath = path35__default.join(workspaceRoot, ".architecture", indexEntry.file);
5013
+ const contextFilePath = path34__default.join(workspaceRoot, ".architecture", indexEntry.file);
4966
5014
  let contextContent;
4967
5015
  try {
4968
- contextContent = await fs27.readFile(contextFilePath, "utf-8");
5016
+ contextContent = await fs29.readFile(contextFilePath, "utf-8");
4969
5017
  } catch (err3) {
4970
5018
  if (err3 instanceof Error && "code" in err3 && err3.code === "ENOENT") {
4971
5019
  throw new Error(`Context file not found: ${contextFilePath}`);
@@ -4997,10 +5045,10 @@ async function mergeSplitManifest(workspaceRoot, manifestPath) {
4997
5045
  continue;
4998
5046
  }
4999
5047
  assertPathWithinArchitecture(workspaceRoot, appEntry.file);
5000
- const appFilePath = path35__default.join(workspaceRoot, ".architecture", appEntry.file);
5048
+ const appFilePath = path34__default.join(workspaceRoot, ".architecture", appEntry.file);
5001
5049
  let appContent;
5002
5050
  try {
5003
- appContent = await fs27.readFile(appFilePath, "utf-8");
5051
+ appContent = await fs29.readFile(appFilePath, "utf-8");
5004
5052
  } catch (err3) {
5005
5053
  if (err3 instanceof Error && "code" in err3 && err3.code === "ENOENT") {
5006
5054
  throw new Error(`App file not found: ${appFilePath}`);
@@ -5019,16 +5067,16 @@ async function mergeSplitManifest(workspaceRoot, manifestPath) {
5019
5067
 
5020
5068
  // src/sync-engine-init.ts
5021
5069
  var __filename$1 = fileURLToPath(import.meta.url);
5022
- var __dirname$1 = path35__default.dirname(__filename$1);
5070
+ var __dirname$1 = path34__default.dirname(__filename$1);
5023
5071
  function isENOENT(err3) {
5024
5072
  return err3 instanceof Error && "code" in err3 && err3.code === "ENOENT";
5025
5073
  }
5026
5074
  async function findRootFrom(startDir, problems) {
5027
5075
  let currentDir = startDir;
5028
- while (currentDir !== path35__default.parse(currentDir).root) {
5029
- const pkgPath = path35__default.join(currentDir, "package.json");
5076
+ while (currentDir !== path34__default.parse(currentDir).root) {
5077
+ const pkgPath = path34__default.join(currentDir, "package.json");
5030
5078
  try {
5031
- const pkgContent = await fs27.readFile(pkgPath, "utf-8");
5079
+ const pkgContent = await fs29.readFile(pkgPath, "utf-8");
5032
5080
  const pkg = JSON.parse(pkgContent);
5033
5081
  if (pkg.workspaces && Array.isArray(pkg.workspaces)) {
5034
5082
  return currentDir;
@@ -5039,7 +5087,7 @@ async function findRootFrom(startDir, problems) {
5039
5087
  problems.push(new Error(`${pkgPath}: ${reason}`));
5040
5088
  }
5041
5089
  }
5042
- currentDir = path35__default.dirname(currentDir);
5090
+ currentDir = path34__default.dirname(currentDir);
5043
5091
  }
5044
5092
  return null;
5045
5093
  }
@@ -5064,7 +5112,7 @@ async function loadManifest(workspaceRoot, flags, options) {
5064
5112
  return { manifest: options.manifest, manifestMissing: false };
5065
5113
  }
5066
5114
  const { logger: logger2, dryRun } = flags;
5067
- const manifestPath = path35__default.join(workspaceRoot, ".architecture/manifest.yaml");
5115
+ const manifestPath = path34__default.join(workspaceRoot, ".architecture/manifest.yaml");
5068
5116
  logger2.debug(`[debug] __dirname (ESM): ${__dirname$1}`);
5069
5117
  logger2.debug(`[debug] resolved workspaceRoot: ${workspaceRoot}`);
5070
5118
  logger2.debug(`[debug] resolved manifestPath: ${manifestPath}`);
@@ -5187,11 +5235,16 @@ var SyncEngine = class {
5187
5235
  );
5188
5236
  continue;
5189
5237
  }
5190
- const moduleDir = path35__default.join(this.workspaceRoot, "packages", mod.name);
5238
+ const moduleDir = path34__default.join(this.workspaceRoot, "packages", mod.name);
5191
5239
  logger2.info(
5192
5240
  `Ensuring directories for module: ${mod.name} at ${moduleDir}`
5193
5241
  );
5194
- const layerResult = await ensureLayerFolders(moduleDir, layers, config);
5242
+ const layerResult = await ensureLayerFolders(
5243
+ moduleDir,
5244
+ layers,
5245
+ config,
5246
+ mod.layers
5247
+ );
5195
5248
  mergeResult2(result, layerResult);
5196
5249
  }
5197
5250
  return result;
@@ -5207,7 +5260,7 @@ var SyncEngine = class {
5207
5260
  const stubs = createEmptyResult();
5208
5261
  for (const module of modules) {
5209
5262
  const moduleName = module.name;
5210
- const moduleDir = path35__default.join(this.workspaceRoot, "packages", moduleName);
5263
+ const moduleDir = path34__default.join(this.workspaceRoot, "packages", moduleName);
5211
5264
  if (moduleName.includes("..") || moduleName.includes("/") || moduleName.startsWith(".")) {
5212
5265
  logger2.warn(
5213
5266
  `Skipping invalid module name (potential path traversal): ${moduleName}`
@@ -5232,6 +5285,11 @@ var SyncEngine = class {
5232
5285
  config,
5233
5286
  this.report
5234
5287
  );
5288
+ const srcIndexResult = await ensurePackageSrcIndex(
5289
+ moduleDir,
5290
+ config,
5291
+ this.report
5292
+ );
5235
5293
  const eslintResult = await generateEslintConfig(
5236
5294
  moduleDir,
5237
5295
  moduleName,
@@ -5247,6 +5305,7 @@ var SyncEngine = class {
5247
5305
  this.noteFailure("Barrels", barrelResult);
5248
5306
  this.noteFailure("package.json", pkgResult);
5249
5307
  this.noteFailure("tsconfig.json", tsResult);
5308
+ this.noteFailure("src/index.ts", srcIndexResult);
5250
5309
  this.noteFailure("ESLint", eslintResult);
5251
5310
  this.noteFailure("Stubs", stubResult);
5252
5311
  if (this.partialConfig.mode === "self-regen") {
@@ -5255,6 +5314,7 @@ var SyncEngine = class {
5255
5314
  mergeResult2(barrels, barrelResult);
5256
5315
  mergeResult2(pkgs, pkgResult);
5257
5316
  mergeResult2(tsconfigs, tsResult);
5317
+ mergeResult2(tsconfigs, srcIndexResult);
5258
5318
  mergeResult2(eslint, eslintResult);
5259
5319
  mergeResult2(stubs, stubResult);
5260
5320
  }
@@ -5386,7 +5446,7 @@ var SyncEngine = class {
5386
5446
  if (!moduleName || moduleName.includes("..") || moduleName.includes("/") || moduleName.startsWith(".")) {
5387
5447
  continue;
5388
5448
  }
5389
- const moduleDir = path35__default.join(this.workspaceRoot, "packages", moduleName);
5449
+ const moduleDir = path34__default.join(this.workspaceRoot, "packages", moduleName);
5390
5450
  const pass2 = await generateBarrels(
5391
5451
  moduleDir,
5392
5452
  this.fullConfig,
@@ -5489,7 +5549,7 @@ Sync completed with ${this.failures.length} generator failure(s) — see the FAI
5489
5549
  } else {
5490
5550
  for (const f of outcome.failures) {
5491
5551
  logger2.error(
5492
- `Rollback failed for ${path35__default.relative(this.workspaceRoot, f.path)}: intended to ${f.intended} — ${f.error}`
5552
+ `Rollback failed for ${path34__default.relative(this.workspaceRoot, f.path)}: intended to ${f.intended} — ${f.error}`
5493
5553
  );
5494
5554
  }
5495
5555
  logger2.error(
@@ -5525,7 +5585,7 @@ function err2(error) {
5525
5585
  var execAsync3 = promisify(exec);
5526
5586
  async function loadManifest2(workspaceRoot) {
5527
5587
  try {
5528
- const manifestPath = path35__default.join(
5588
+ const manifestPath = path34__default.join(
5529
5589
  workspaceRoot,
5530
5590
  ".architecture/manifest.yaml"
5531
5591
  );
@@ -5952,8 +6012,17 @@ function resolveTemplatesDir() {
5952
6012
  if (process.env.HEXAGEN_TEMPLATES_DIR) {
5953
6013
  return process.env.HEXAGEN_TEMPLATES_DIR;
5954
6014
  }
5955
- const cliDir = path35__default.dirname(fileURLToPath(import.meta.url));
5956
- return path35__default.resolve(cliDir, "templates");
6015
+ const cliDir = path34__default.dirname(fileURLToPath(import.meta.url));
6016
+ return path34__default.resolve(cliDir, "templates");
6017
+ }
6018
+ async function lstatExists(target) {
6019
+ try {
6020
+ await promises.lstat(target);
6021
+ return ok2(true);
6022
+ } catch (e) {
6023
+ if (e.code === "ENOENT") return ok2(false);
6024
+ return err2(e instanceof Error ? e : new Error(String(e)));
6025
+ }
5957
6026
  }
5958
6027
 
5959
6028
  // src/commands/arch/port.ts
@@ -7002,8 +7071,23 @@ function emptyConfig() {
7002
7071
  function isInstalled(config, templateId) {
7003
7072
  return templateId in config.templates;
7004
7073
  }
7074
+
7075
+ // ../template-engine/dist/domain/conflict-path.js
7076
+ function posixExtname(filePath) {
7077
+ let end = filePath.length;
7078
+ while (end > 0 && filePath.charCodeAt(end - 1) === 47)
7079
+ end -= 1;
7080
+ const baseStart = filePath.lastIndexOf("/", end - 1) + 1;
7081
+ const base = filePath.slice(baseStart, end);
7082
+ if (base === "." || base === "..")
7083
+ return "";
7084
+ const dot = base.lastIndexOf(".");
7085
+ if (dot <= 0)
7086
+ return "";
7087
+ return base.slice(dot);
7088
+ }
7005
7089
  function conflictFilePath(filePath) {
7006
- const ext = path35__default.extname(filePath);
7090
+ const ext = posixExtname(filePath);
7007
7091
  return ext ? filePath.slice(0, -ext.length) + ".hexagen-update" + ext : filePath + ".hexagen-update";
7008
7092
  }
7009
7093
 
@@ -7246,25 +7330,25 @@ var ValidateTemplatesUseCase = class {
7246
7330
  return { results, totalWarnings, totalErrors };
7247
7331
  }
7248
7332
  };
7249
- var PACKAGE_ROOT = path35__default.resolve(path35__default.dirname(fileURLToPath(import.meta.url)), "..", "..");
7333
+ var PACKAGE_ROOT = path34__default.resolve(path34__default.dirname(fileURLToPath(import.meta.url)), "..", "..");
7250
7334
  var FileSystemTemplateRegistry = class {
7251
7335
  templatesDir;
7252
7336
  cache = null;
7253
7337
  constructor(templatesDir) {
7254
- this.templatesDir = templatesDir ?? path35__default.join(PACKAGE_ROOT, "templates");
7338
+ this.templatesDir = templatesDir ?? path34__default.join(PACKAGE_ROOT, "templates");
7255
7339
  }
7256
7340
  async loadAll() {
7257
7341
  if (this.cache)
7258
7342
  return this.cache;
7259
7343
  let entries;
7260
7344
  try {
7261
- entries = await fs27.readdir(this.templatesDir);
7345
+ entries = await fs29.readdir(this.templatesDir);
7262
7346
  } catch {
7263
7347
  return [];
7264
7348
  }
7265
7349
  const manifests = [];
7266
7350
  for (const entry of entries) {
7267
- const manifestPath = path35__default.join(this.templatesDir, entry, "manifest.json");
7351
+ const manifestPath = path34__default.join(this.templatesDir, entry, "manifest.json");
7268
7352
  const manifest = await this.readManifest(manifestPath);
7269
7353
  if (manifest)
7270
7354
  manifests.push(manifest);
@@ -7273,13 +7357,13 @@ var FileSystemTemplateRegistry = class {
7273
7357
  return manifests;
7274
7358
  }
7275
7359
  async loadOne(id) {
7276
- const manifestPath = path35__default.join(this.templatesDir, id, "manifest.json");
7360
+ const manifestPath = path34__default.join(this.templatesDir, id, "manifest.json");
7277
7361
  return this.readManifest(manifestPath);
7278
7362
  }
7279
7363
  async readManifest(manifestPath) {
7280
7364
  let raw;
7281
7365
  try {
7282
- raw = await fs27.readFile(manifestPath, "utf-8");
7366
+ raw = await fs29.readFile(manifestPath, "utf-8");
7283
7367
  } catch {
7284
7368
  return null;
7285
7369
  }
@@ -7415,35 +7499,35 @@ ${prompt} (comma-separated numbers)`);
7415
7499
  }
7416
7500
  }
7417
7501
  };
7418
- var PACKAGE_ROOT2 = path35__default.resolve(path35__default.dirname(fileURLToPath(import.meta.url)), "..", "..");
7502
+ var PACKAGE_ROOT2 = path34__default.resolve(path34__default.dirname(fileURLToPath(import.meta.url)), "..", "..");
7419
7503
  var FileSystemFileEmitter = class {
7420
7504
  templatesDir;
7421
7505
  withTests;
7422
7506
  constructor(templatesDir, options = {}) {
7423
- this.templatesDir = templatesDir ?? path35__default.join(PACKAGE_ROOT2, "templates");
7507
+ this.templatesDir = templatesDir ?? path34__default.join(PACKAGE_ROOT2, "templates");
7424
7508
  this.withTests = options.withTests ?? false;
7425
7509
  }
7426
7510
  async emit(manifest, answers, projectRoot, config) {
7427
7511
  const warnings = [];
7428
7512
  const generatedFiles = [];
7429
- const templateFilesDir = path35__default.join(this.templatesDir, manifest.id, "files");
7430
- const resolvedRoot = path35__default.resolve(projectRoot);
7513
+ const templateFilesDir = path34__default.join(this.templatesDir, manifest.id, "files");
7514
+ const resolvedRoot = path34__default.resolve(projectRoot);
7431
7515
  for (const out of manifest.outputs) {
7432
7516
  if (!isOutputEnabled(out, answers))
7433
7517
  continue;
7434
7518
  const outputRelPath = outputPath(out);
7435
7519
  if (!this.withTests && isTestOutput(outputRelPath))
7436
7520
  continue;
7437
- const destFile = path35__default.resolve(projectRoot, outputRelPath);
7438
- if (!destFile.startsWith(resolvedRoot + path35__default.sep) && destFile !== resolvedRoot) {
7521
+ const destFile = path34__default.resolve(projectRoot, outputRelPath);
7522
+ if (!destFile.startsWith(resolvedRoot + path34__default.sep) && destFile !== resolvedRoot) {
7439
7523
  throw new Error(`Output path '${outputRelPath}' escapes the project root`);
7440
7524
  }
7441
- const sourceFile = path35__default.join(templateFilesDir, outputRelPath);
7525
+ const sourceFile = path34__default.join(templateFilesDir, outputRelPath);
7442
7526
  let templateContent;
7443
7527
  let sourceMode = 420;
7444
7528
  try {
7445
- const raw = await fs27.readFile(sourceFile, "utf-8");
7446
- sourceMode = (await fs27.stat(sourceFile)).mode & 511;
7529
+ const raw = await fs29.readFile(sourceFile, "utf-8");
7530
+ sourceMode = (await fs29.stat(sourceFile)).mode & 511;
7447
7531
  const { output, warnings: interpWarnings } = interpolate(raw, answers);
7448
7532
  templateContent = output;
7449
7533
  for (const key of interpWarnings) {
@@ -7458,7 +7542,7 @@ var FileSystemFileEmitter = class {
7458
7542
  const templateHash = sha256(templateContent);
7459
7543
  let existingContent = null;
7460
7544
  try {
7461
- existingContent = await fs27.readFile(destFile, "utf-8");
7545
+ existingContent = await fs29.readFile(destFile, "utf-8");
7462
7546
  } catch {
7463
7547
  }
7464
7548
  if (existingContent !== null) {
@@ -7468,7 +7552,7 @@ var FileSystemFileEmitter = class {
7468
7552
  if (!isAlreadyIdentical && !wasGeneratedByHexagen) {
7469
7553
  const conflictDest = conflictFilePath(destFile);
7470
7554
  await atomicWrite(conflictDest, templateContent, sourceMode);
7471
- const rel = path35__default.relative(projectRoot, conflictDest);
7555
+ const rel = path34__default.relative(projectRoot, conflictDest);
7472
7556
  warnings.push(`⚠️ Conflict: ${outputRelPath} has local changes.
7473
7557
  New version written to ${rel}
7474
7558
  Review and merge manually, then delete the conflict file.`);
@@ -7482,18 +7566,18 @@ var FileSystemFileEmitter = class {
7482
7566
  }
7483
7567
  };
7484
7568
  async function atomicWrite(filePath, content, mode) {
7485
- await fs27.mkdir(path35__default.dirname(filePath), { recursive: true });
7569
+ await fs29.mkdir(path34__default.dirname(filePath), { recursive: true });
7486
7570
  const tmp = `${filePath}.tmp.${Date.now()}`;
7487
7571
  try {
7488
- await fs27.writeFile(tmp, content, "utf-8");
7572
+ await fs29.writeFile(tmp, content, "utf-8");
7489
7573
  if (mode !== void 0 && (mode & 73) !== 0) {
7490
- const created = (await fs27.stat(tmp)).mode & 511;
7574
+ const created = (await fs29.stat(tmp)).mode & 511;
7491
7575
  const execBits = mode & 73 & ~process.umask();
7492
- await fs27.chmod(tmp, created | execBits);
7576
+ await fs29.chmod(tmp, created | execBits);
7493
7577
  }
7494
- await fs27.rename(tmp, filePath);
7578
+ await fs29.rename(tmp, filePath);
7495
7579
  } catch (err3) {
7496
- await fs27.rm(tmp, { force: true }).catch(() => {
7580
+ await fs29.rm(tmp, { force: true }).catch(() => {
7497
7581
  });
7498
7582
  throw err3;
7499
7583
  }
@@ -7503,9 +7587,9 @@ function sha256(content) {
7503
7587
  }
7504
7588
  var FileSystemTemplateConfigStore = class {
7505
7589
  async load(projectRoot) {
7506
- const configPath = path35__default.join(projectRoot, TEMPLATE_CONFIG_FILE);
7590
+ const configPath = path34__default.join(projectRoot, TEMPLATE_CONFIG_FILE);
7507
7591
  try {
7508
- const raw = await fs27.readFile(configPath, "utf-8");
7592
+ const raw = await fs29.readFile(configPath, "utf-8");
7509
7593
  return JSON.parse(raw);
7510
7594
  } catch (err3) {
7511
7595
  if (err3.code === "ENOENT")
@@ -7514,16 +7598,16 @@ var FileSystemTemplateConfigStore = class {
7514
7598
  }
7515
7599
  }
7516
7600
  async save(projectRoot, config) {
7517
- const configPath = path35__default.join(projectRoot, TEMPLATE_CONFIG_FILE);
7601
+ const configPath = path34__default.join(projectRoot, TEMPLATE_CONFIG_FILE);
7518
7602
  const tmp = `${configPath}.tmp.${Date.now()}`;
7519
- await fs27.writeFile(tmp, JSON.stringify(config, null, 2), "utf-8");
7520
- await fs27.rename(tmp, configPath);
7603
+ await fs29.writeFile(tmp, JSON.stringify(config, null, 2), "utf-8");
7604
+ await fs29.rename(tmp, configPath);
7521
7605
  }
7522
7606
  };
7523
7607
  var FileSystemProjectFilePresence = class {
7524
7608
  async exists(projectRoot, relativePath) {
7525
7609
  try {
7526
- await fs27.access(path35__default.join(projectRoot, relativePath));
7610
+ await fs29.access(path34__default.join(projectRoot, relativePath));
7527
7611
  return true;
7528
7612
  } catch {
7529
7613
  return false;
@@ -7975,35 +8059,35 @@ var FileSystemWorkspaceAdapter = class {
7975
8059
  }
7976
8060
  workspaceRoot;
7977
8061
  listPackages() {
7978
- const packagesDir = path35.join(this.workspaceRoot, "packages");
7979
- if (!fs24.existsSync(packagesDir)) {
8062
+ const packagesDir = path34.join(this.workspaceRoot, "packages");
8063
+ if (!fs26.existsSync(packagesDir)) {
7980
8064
  return [];
7981
8065
  }
7982
- return fs24.readdirSync(packagesDir, { withFileTypes: true }).filter((dirent) => dirent.isDirectory()).map((dirent) => dirent.name);
8066
+ return fs26.readdirSync(packagesDir, { withFileTypes: true }).filter((dirent) => dirent.isDirectory()).map((dirent) => dirent.name);
7983
8067
  }
7984
8068
  listApps() {
7985
- const appsDir = path35.join(this.workspaceRoot, "apps");
7986
- if (!fs24.existsSync(appsDir)) {
8069
+ const appsDir = path34.join(this.workspaceRoot, "apps");
8070
+ if (!fs26.existsSync(appsDir)) {
7987
8071
  return [];
7988
8072
  }
7989
- return fs24.readdirSync(appsDir, { withFileTypes: true }).filter((dirent) => dirent.isDirectory()).map((dirent) => dirent.name);
8073
+ return fs26.readdirSync(appsDir, { withFileTypes: true }).filter((dirent) => dirent.isDirectory()).map((dirent) => dirent.name);
7990
8074
  }
7991
8075
  getSourceFiles(dir) {
7992
- if (!fs24.existsSync(dir)) {
8076
+ if (!fs26.existsSync(dir)) {
7993
8077
  return [];
7994
8078
  }
7995
- const entries = fs24.readdirSync(dir, { withFileTypes: true });
8079
+ const entries = fs26.readdirSync(dir, { withFileTypes: true });
7996
8080
  return entries.map((entry) => ({
7997
- path: path35.join(dir, entry.name),
8081
+ path: path34.join(dir, entry.name),
7998
8082
  isDirectory: entry.isDirectory()
7999
8083
  }));
8000
8084
  }
8001
8085
  fileExists(filePath) {
8002
- return fs24.existsSync(filePath);
8086
+ return fs26.existsSync(filePath);
8003
8087
  }
8004
8088
  readFile(filePath) {
8005
8089
  try {
8006
- return fs24.readFileSync(filePath, "utf-8");
8090
+ return fs26.readFileSync(filePath, "utf-8");
8007
8091
  } catch {
8008
8092
  return null;
8009
8093
  }
@@ -8031,15 +8115,24 @@ var TsMorphSymbolIndexAdapter = class {
8031
8115
  }
8032
8116
  }
8033
8117
  findReferences(symbolName) {
8034
- return this.project.getSourceFiles().filter((file) => file.getFullText().includes(symbolName)).map((file) => ({
8035
- // `getFilePath()` returns a StandardizedFilePath: absolute and
8036
- // slash-separated even on Windows. That is exactly the dialect the DTO
8037
- // promises, so it crosses the boundary unmodified.
8038
- filePath: file.getFilePath(),
8039
- reason: describeReference(file, symbolName)
8040
- }));
8118
+ return this.project.getSourceFiles().filter((file) => file.getFullText().includes(symbolName)).map((file) => {
8119
+ const diagnostics = syntacticDiagnosticsOf(this.project, file);
8120
+ return {
8121
+ // `getFilePath()` returns a StandardizedFilePath: absolute and
8122
+ // slash-separated even on Windows. That is exactly the dialect the DTO
8123
+ // promises, so it crosses the boundary unmodified.
8124
+ filePath: file.getFilePath(),
8125
+ reason: describeReference(file, symbolName),
8126
+ ...diagnostics.length > 0 ? { diagnostics } : {}
8127
+ };
8128
+ });
8041
8129
  }
8042
8130
  };
8131
+ function syntacticDiagnosticsOf(project, file) {
8132
+ return project.getProgram().compilerObject.getSyntacticDiagnostics(file.compilerNode).map(
8133
+ (diagnostic) => ts.flattenDiagnosticMessageText(diagnostic.messageText, " ")
8134
+ );
8135
+ }
8043
8136
  function describeReference(file, symbolName) {
8044
8137
  for (const iface of file.getInterfaces()) {
8045
8138
  if (iface.getName() === symbolName) {
@@ -8089,7 +8182,7 @@ var layoutSchema = z.object({
8089
8182
 
8090
8183
  // src/infrastructure/config/load-layout-config.ts
8091
8184
  function loadLayoutConfig(workspaceRoot) {
8092
- const filePath = path35__default.join(
8185
+ const filePath = path34__default.join(
8093
8186
  workspaceRoot,
8094
8187
  ...LAYOUT_YAML_RELATIVE_PATH.split("/")
8095
8188
  );
@@ -8113,14 +8206,20 @@ function loadLayoutConfig(workspaceRoot) {
8113
8206
  // src/domain/services/impact-request-validator.ts
8114
8207
  function validateRenameRequest(type, newName) {
8115
8208
  if (!newName || newName.trim() === "") {
8116
- return { valid: false, error: "New name is required for rename operations" };
8209
+ return {
8210
+ valid: false,
8211
+ error: "New name is required for rename operations"
8212
+ };
8117
8213
  }
8118
8214
  if (type === "rename-port") {
8119
8215
  if (!newName.endsWith("Port")) {
8120
8216
  return { valid: false, error: "Port names must end with 'Port'" };
8121
8217
  }
8122
8218
  if (!/^[A-Z][a-zA-Z0-9]*Port$/.test(newName)) {
8123
- return { valid: false, error: "Port names must be in PascalCase and end with 'Port'" };
8219
+ return {
8220
+ valid: false,
8221
+ error: "Port names must be in PascalCase and end with 'Port'"
8222
+ };
8124
8223
  }
8125
8224
  }
8126
8225
  if (type === "rename-use-case") {
@@ -8128,7 +8227,10 @@ function validateRenameRequest(type, newName) {
8128
8227
  return { valid: false, error: "Use case names must end with 'UseCase'" };
8129
8228
  }
8130
8229
  if (!/^[A-Z][a-zA-Z0-9]*UseCase$/.test(newName)) {
8131
- return { valid: false, error: "Use case names must be in PascalCase and end with 'UseCase'" };
8230
+ return {
8231
+ valid: false,
8232
+ error: "Use case names must be in PascalCase and end with 'UseCase'"
8233
+ };
8132
8234
  }
8133
8235
  }
8134
8236
  if (type === "rename-entity") {
@@ -8143,7 +8245,10 @@ function validateMoveRequest(type, newLocation) {
8143
8245
  return { valid: true };
8144
8246
  }
8145
8247
  if (!newLocation || newLocation.trim() === "") {
8146
- return { valid: false, error: "New location is required for move operations" };
8248
+ return {
8249
+ valid: false,
8250
+ error: "New location is required for move operations"
8251
+ };
8147
8252
  }
8148
8253
  return { valid: true };
8149
8254
  }
@@ -8343,7 +8448,8 @@ var RefactoringImpactUseCase = class {
8343
8448
  const warnings = this.generateWarnings(
8344
8449
  filesToModify,
8345
8450
  crossPackageDeps,
8346
- architecturalImpact
8451
+ architecturalImpact,
8452
+ references
8347
8453
  );
8348
8454
  const estimatedChanges = this.estimateChanges(filesToModify);
8349
8455
  return ok2({
@@ -8450,7 +8556,7 @@ var RefactoringImpactUseCase = class {
8450
8556
  assessImpact(files, crossPackageDeps) {
8451
8557
  return assessArchitecturalImpact(files, crossPackageDeps, this.manifest);
8452
8558
  }
8453
- generateWarnings(files, crossPackageDeps, architecturalImpact) {
8559
+ generateWarnings(files, crossPackageDeps, architecturalImpact, references) {
8454
8560
  const warnings = [];
8455
8561
  if (architecturalImpact === "BOUNDARY_VIOLATION") {
8456
8562
  warnings.push("This refactoring would violate architectural boundaries");
@@ -8477,6 +8583,18 @@ var RefactoringImpactUseCase = class {
8477
8583
  `This refactoring will require updating ${testFiles.length} test files`
8478
8584
  );
8479
8585
  }
8586
+ for (const reference of references) {
8587
+ if (reference.diagnostics === void 0 || reference.diagnostics.length === 0) {
8588
+ continue;
8589
+ }
8590
+ const relativePath = toWorkspaceRelativePosixPath(
8591
+ this.workspaceRoot,
8592
+ reference.filePath
8593
+ );
8594
+ warnings.push(
8595
+ `Could not parse ${relativePath} (syntactic); impact for this file is incomplete`
8596
+ );
8597
+ }
8480
8598
  return warnings;
8481
8599
  }
8482
8600
  estimateChanges(files) {
@@ -8558,15 +8676,15 @@ async function updateBarrelExport(sourceFile, oldName, newName) {
8558
8676
  }
8559
8677
  async function updateManifestEntry(workspaceRoot, updateFn) {
8560
8678
  try {
8561
- const manifestPath = path35__default.join(
8679
+ const manifestPath = path34__default.join(
8562
8680
  workspaceRoot,
8563
8681
  ".architecture/manifest.yaml"
8564
8682
  );
8565
- const content = await fs27.readFile(manifestPath, "utf-8");
8683
+ const content = await fs29.readFile(manifestPath, "utf-8");
8566
8684
  const manifest = yaml10.load(content);
8567
8685
  updateFn(manifest);
8568
8686
  const updatedContent = yaml10.dump(manifest, { indent: 2 });
8569
- await fs27.writeFile(manifestPath, updatedContent, "utf-8");
8687
+ await fs29.writeFile(manifestPath, updatedContent, "utf-8");
8570
8688
  return ok2(void 0);
8571
8689
  } catch (error) {
8572
8690
  return err2(error);
@@ -8630,7 +8748,7 @@ var RenamePortPattern = class {
8630
8748
  (f) => f.reason.includes("Declares")
8631
8749
  );
8632
8750
  for (const file of portFiles) {
8633
- const filePath = path35__default.join(this.workspaceRoot, file.path);
8751
+ const filePath = path34__default.join(this.workspaceRoot, file.path);
8634
8752
  const sourceFile = this.project.addSourceFileAtPath(filePath);
8635
8753
  const existingInterface = sourceFile.getInterface(request.newName);
8636
8754
  if (existingInterface) {
@@ -8652,7 +8770,7 @@ var RenamePortPattern = class {
8652
8770
  const warnings = [];
8653
8771
  try {
8654
8772
  for (const file of impact.filesToModify) {
8655
- const filePath = path35__default.join(this.workspaceRoot, file.path);
8773
+ const filePath = path34__default.join(this.workspaceRoot, file.path);
8656
8774
  if (file.path.endsWith(".ts") || file.path.endsWith(".tsx")) {
8657
8775
  try {
8658
8776
  this.project.addSourceFileAtPath(filePath);
@@ -8755,7 +8873,7 @@ var RenamePortPattern = class {
8755
8873
  */
8756
8874
  async renamePortFile(relativePath, oldName, newName) {
8757
8875
  try {
8758
- const filePath = path35__default.join(this.workspaceRoot, relativePath);
8876
+ const filePath = path34__default.join(this.workspaceRoot, relativePath);
8759
8877
  const sourceFile = this.project.getSourceFile(filePath);
8760
8878
  if (!sourceFile) {
8761
8879
  return err2(new Error(`Source file not found: ${relativePath}`));
@@ -8768,17 +8886,17 @@ var RenamePortPattern = class {
8768
8886
  if (typeAlias) {
8769
8887
  typeAlias.rename(newName);
8770
8888
  }
8771
- const oldFileName = path35__default.basename(relativePath);
8889
+ const oldFileName = path34__default.basename(relativePath);
8772
8890
  const newFileName = oldFileName.replace(
8773
8891
  toKebabCase(oldName),
8774
8892
  toKebabCase(newName)
8775
8893
  );
8776
8894
  if (oldFileName !== newFileName) {
8777
- const newFilePath = path35__default.join(path35__default.dirname(filePath), newFileName);
8895
+ const newFilePath = path34__default.join(path34__default.dirname(filePath), newFileName);
8778
8896
  await sourceFile.move(newFilePath);
8779
8897
  return ok2([
8780
8898
  relativePath,
8781
- path35__default.relative(this.workspaceRoot, newFilePath)
8899
+ path34__default.relative(this.workspaceRoot, newFilePath)
8782
8900
  ]);
8783
8901
  }
8784
8902
  return ok2([relativePath]);
@@ -8791,7 +8909,7 @@ var RenamePortPattern = class {
8791
8909
  */
8792
8910
  async updateImports(relativePath, oldName, newName) {
8793
8911
  try {
8794
- const filePath = path35__default.join(this.workspaceRoot, relativePath);
8912
+ const filePath = path34__default.join(this.workspaceRoot, relativePath);
8795
8913
  const sourceFile = this.project.getSourceFile(filePath);
8796
8914
  if (!sourceFile) {
8797
8915
  return ok2([]);
@@ -8807,7 +8925,7 @@ var RenamePortPattern = class {
8807
8925
  */
8808
8926
  async updateBarrelExport(relativePath, oldName, newName) {
8809
8927
  try {
8810
- const filePath = path35__default.join(this.workspaceRoot, relativePath);
8928
+ const filePath = path34__default.join(this.workspaceRoot, relativePath);
8811
8929
  const sourceFile = this.project.getSourceFile(filePath);
8812
8930
  if (!sourceFile) {
8813
8931
  return ok2([]);
@@ -8850,7 +8968,7 @@ var RenamePortPattern = class {
8850
8968
  */
8851
8969
  async updateTestDouble(relativePath, oldName, newName) {
8852
8970
  try {
8853
- const filePath = path35__default.join(this.workspaceRoot, relativePath);
8971
+ const filePath = path34__default.join(this.workspaceRoot, relativePath);
8854
8972
  const sourceFile = this.project.getSourceFile(filePath);
8855
8973
  if (!sourceFile) {
8856
8974
  return ok2([]);
@@ -8880,17 +8998,17 @@ var RenamePortPattern = class {
8880
8998
  );
8881
8999
  modified = modified || importsModified;
8882
9000
  if (modified) {
8883
- const oldFileName = path35__default.basename(relativePath);
9001
+ const oldFileName = path34__default.basename(relativePath);
8884
9002
  const newFileName = oldFileName.replace(
8885
9003
  toKebabCase(oldName),
8886
9004
  toKebabCase(newName)
8887
9005
  );
8888
9006
  if (oldFileName !== newFileName) {
8889
- const newFilePath = path35__default.join(path35__default.dirname(filePath), newFileName);
9007
+ const newFilePath = path34__default.join(path34__default.dirname(filePath), newFileName);
8890
9008
  await sourceFile.move(newFilePath);
8891
9009
  return ok2([
8892
9010
  relativePath,
8893
- path35__default.relative(this.workspaceRoot, newFilePath)
9011
+ path34__default.relative(this.workspaceRoot, newFilePath)
8894
9012
  ]);
8895
9013
  }
8896
9014
  }
@@ -8963,7 +9081,7 @@ var RenameUseCasePattern = class {
8963
9081
  const warnings = [];
8964
9082
  try {
8965
9083
  for (const file of impact.filesToModify) {
8966
- const filePath = path35__default.join(this.workspaceRoot, file.path);
9084
+ const filePath = path34__default.join(this.workspaceRoot, file.path);
8967
9085
  if (file.path.endsWith(".ts") || file.path.endsWith(".tsx")) {
8968
9086
  try {
8969
9087
  this.project.addSourceFileAtPath(filePath);
@@ -9074,7 +9192,7 @@ var RenameUseCasePattern = class {
9074
9192
  */
9075
9193
  async renameUseCaseFile(relativePath, oldName, newName) {
9076
9194
  try {
9077
- const filePath = path35__default.join(this.workspaceRoot, relativePath);
9195
+ const filePath = path34__default.join(this.workspaceRoot, relativePath);
9078
9196
  const sourceFile = this.project.getSourceFile(filePath);
9079
9197
  if (!sourceFile) {
9080
9198
  return err2(new Error(`Source file not found: ${relativePath}`));
@@ -9083,17 +9201,17 @@ var RenameUseCasePattern = class {
9083
9201
  if (classDecl) {
9084
9202
  classDecl.rename(newName);
9085
9203
  }
9086
- const oldFileName = path35__default.basename(relativePath);
9204
+ const oldFileName = path34__default.basename(relativePath);
9087
9205
  const newFileName = oldFileName.replace(
9088
9206
  toKebabCase(oldName),
9089
9207
  toKebabCase(newName)
9090
9208
  );
9091
9209
  if (oldFileName !== newFileName) {
9092
- const newFilePath = path35__default.join(path35__default.dirname(filePath), newFileName);
9210
+ const newFilePath = path34__default.join(path34__default.dirname(filePath), newFileName);
9093
9211
  await sourceFile.move(newFilePath);
9094
9212
  return ok2([
9095
9213
  relativePath,
9096
- path35__default.relative(this.workspaceRoot, newFilePath)
9214
+ path34__default.relative(this.workspaceRoot, newFilePath)
9097
9215
  ]);
9098
9216
  }
9099
9217
  return ok2([relativePath]);
@@ -9103,7 +9221,7 @@ var RenameUseCasePattern = class {
9103
9221
  }
9104
9222
  async updateImports(relativePath, oldName, newName) {
9105
9223
  try {
9106
- const filePath = path35__default.join(this.workspaceRoot, relativePath);
9224
+ const filePath = path34__default.join(this.workspaceRoot, relativePath);
9107
9225
  const sourceFile = this.project.getSourceFile(filePath);
9108
9226
  if (!sourceFile) {
9109
9227
  return ok2([]);
@@ -9119,7 +9237,7 @@ var RenameUseCasePattern = class {
9119
9237
  */
9120
9238
  async updateBarrelExport(relativePath, oldName, newName) {
9121
9239
  try {
9122
- const filePath = path35__default.join(this.workspaceRoot, relativePath);
9240
+ const filePath = path34__default.join(this.workspaceRoot, relativePath);
9123
9241
  const sourceFile = this.project.getSourceFile(filePath);
9124
9242
  if (!sourceFile) {
9125
9243
  return ok2([]);
@@ -9156,24 +9274,24 @@ var RenameUseCasePattern = class {
9156
9274
  */
9157
9275
  async updateTestFile(relativePath, oldName, newName) {
9158
9276
  try {
9159
- const filePath = path35__default.join(this.workspaceRoot, relativePath);
9277
+ const filePath = path34__default.join(this.workspaceRoot, relativePath);
9160
9278
  const sourceFile = this.project.getSourceFile(filePath);
9161
9279
  if (!sourceFile) {
9162
9280
  return ok2([]);
9163
9281
  }
9164
9282
  const modified = await updateImports(sourceFile, oldName, newName);
9165
9283
  if (modified) {
9166
- const oldFileName = path35__default.basename(relativePath);
9284
+ const oldFileName = path34__default.basename(relativePath);
9167
9285
  const newFileName = oldFileName.replace(
9168
9286
  toKebabCase(oldName),
9169
9287
  toKebabCase(newName)
9170
9288
  );
9171
9289
  if (oldFileName !== newFileName) {
9172
- const newFilePath = path35__default.join(path35__default.dirname(filePath), newFileName);
9290
+ const newFilePath = path34__default.join(path34__default.dirname(filePath), newFileName);
9173
9291
  await sourceFile.move(newFilePath);
9174
9292
  return ok2([
9175
9293
  relativePath,
9176
- path35__default.relative(this.workspaceRoot, newFilePath)
9294
+ path34__default.relative(this.workspaceRoot, newFilePath)
9177
9295
  ]);
9178
9296
  }
9179
9297
  }
@@ -9184,7 +9302,7 @@ var RenameUseCasePattern = class {
9184
9302
  }
9185
9303
  async updateCompositionRoot(relativePath, oldName, newName) {
9186
9304
  try {
9187
- const filePath = path35__default.join(this.workspaceRoot, relativePath);
9305
+ const filePath = path34__default.join(this.workspaceRoot, relativePath);
9188
9306
  const sourceFile = this.project.getSourceFile(filePath);
9189
9307
  if (!sourceFile) {
9190
9308
  return ok2([]);
@@ -9254,7 +9372,7 @@ var RenameEntityPattern = class {
9254
9372
  if (file.path.endsWith(".ts") || file.path.endsWith(".tsx")) {
9255
9373
  try {
9256
9374
  this.project.addSourceFileAtPath(
9257
- path35__default.join(this.workspaceRoot, file.path)
9375
+ path34__default.join(this.workspaceRoot, file.path)
9258
9376
  );
9259
9377
  } catch {
9260
9378
  }
@@ -9312,7 +9430,7 @@ var RenameEntityPattern = class {
9312
9430
  async renameEntityFile(relativePath, oldName, newName) {
9313
9431
  try {
9314
9432
  const sourceFile = this.project.getSourceFile(
9315
- path35__default.join(this.workspaceRoot, relativePath)
9433
+ path34__default.join(this.workspaceRoot, relativePath)
9316
9434
  );
9317
9435
  if (!sourceFile) return err2(new Error(`File not found: ${relativePath}`));
9318
9436
  const classDecl = sourceFile.getClass(oldName);
@@ -9329,7 +9447,7 @@ var RenameEntityPattern = class {
9329
9447
  async updateReferences(relativePath, oldName, newName) {
9330
9448
  try {
9331
9449
  const sourceFile = this.project.getSourceFile(
9332
- path35__default.join(this.workspaceRoot, relativePath)
9450
+ path34__default.join(this.workspaceRoot, relativePath)
9333
9451
  );
9334
9452
  if (!sourceFile) return ok2([]);
9335
9453
  let modified = false;
@@ -9348,11 +9466,11 @@ var RenameEntityPattern = class {
9348
9466
  }
9349
9467
  async updateManifest(oldName, newName) {
9350
9468
  try {
9351
- const manifestPath = path35__default.join(
9469
+ const manifestPath = path34__default.join(
9352
9470
  this.workspaceRoot,
9353
9471
  ".architecture/manifest.yaml"
9354
9472
  );
9355
- const content = await fs27.readFile(manifestPath, "utf-8");
9473
+ const content = await fs29.readFile(manifestPath, "utf-8");
9356
9474
  const manifest = yaml10.load(content);
9357
9475
  if (manifest.bounded_contexts) {
9358
9476
  for (const context of manifest.bounded_contexts) {
@@ -9364,7 +9482,7 @@ var RenameEntityPattern = class {
9364
9482
  }
9365
9483
  }
9366
9484
  }
9367
- await fs27.writeFile(
9485
+ await fs29.writeFile(
9368
9486
  manifestPath,
9369
9487
  yaml10.dump(manifest, { indent: 2 }),
9370
9488
  "utf-8"
@@ -10048,7 +10166,7 @@ var manifestSplitCommander = new Command("split").description("Split monolithic
10048
10166
  const dryRun = options.dryRun ?? false;
10049
10167
  try {
10050
10168
  const workspaceRoot = await findWorkspaceRoot({});
10051
- const monolithicManifestPath = path35__default.join(
10169
+ const monolithicManifestPath = path34__default.join(
10052
10170
  workspaceRoot,
10053
10171
  ".architecture/manifest.yaml"
10054
10172
  );
@@ -10057,7 +10175,7 @@ var manifestSplitCommander = new Command("split").description("Split monolithic
10057
10175
  );
10058
10176
  let manifestContent;
10059
10177
  try {
10060
- manifestContent = await fs27.readFile(monolithicManifestPath, "utf-8");
10178
+ manifestContent = await fs29.readFile(monolithicManifestPath, "utf-8");
10061
10179
  } catch {
10062
10180
  throw new Error(`Failed to read manifest.yaml. Does it exist?`);
10063
10181
  }
@@ -10085,14 +10203,14 @@ Validation successful. Found ${contexts.length} bounded contexts.`
10085
10203
  const planes = rawYaml.planes ?? {};
10086
10204
  const planeLookup = buildPlaneLookup(planes);
10087
10205
  console.log("Splitting manifest into the new directory structure...");
10088
- const archDir = path35__default.join(workspaceRoot, ".architecture");
10089
- const contextsDir = path35__default.join(archDir, "contexts");
10090
- const appsDir = path35__default.join(archDir, "apps");
10091
- const invariantsDir = path35__default.join(archDir, "invariants");
10206
+ const archDir = path34__default.join(workspaceRoot, ".architecture");
10207
+ const contextsDir = path34__default.join(archDir, "contexts");
10208
+ const appsDir = path34__default.join(archDir, "apps");
10209
+ const invariantsDir = path34__default.join(archDir, "invariants");
10092
10210
  if (!dryRun) {
10093
- await fs27.mkdir(contextsDir, { recursive: true });
10094
- await fs27.mkdir(appsDir, { recursive: true });
10095
- await fs27.mkdir(invariantsDir, { recursive: true });
10211
+ await fs29.mkdir(contextsDir, { recursive: true });
10212
+ await fs29.mkdir(appsDir, { recursive: true });
10213
+ await fs29.mkdir(invariantsDir, { recursive: true });
10096
10214
  }
10097
10215
  const CATEGORY_B_KEYS = /* @__PURE__ */ new Set(["monorepo", "generator"]);
10098
10216
  const workspaceConfig = {};
@@ -10132,12 +10250,12 @@ Validation successful. Found ${contexts.length} bounded contexts.`
10132
10250
  }
10133
10251
  for (const ctx of contexts) {
10134
10252
  const plane = planeLookup.get(ctx.name) ?? ctx.plane ?? "core";
10135
- const ctxDir = path35__default.join(contextsDir, plane, ctx.name);
10253
+ const ctxDir = path34__default.join(contextsDir, plane, ctx.name);
10136
10254
  const contextData = normalizeContextData(
10137
10255
  extractContextData(ctx)
10138
10256
  );
10139
10257
  contextData.plane = plane;
10140
- const ctxFilePath = path35__default.join(ctxDir, "context.yaml");
10258
+ const ctxFilePath = path34__default.join(ctxDir, "context.yaml");
10141
10259
  const ctxYaml = yaml10.dump(contextData, {
10142
10260
  noRefs: true,
10143
10261
  sortKeys: false,
@@ -10146,8 +10264,8 @@ Validation successful. Found ${contexts.length} bounded contexts.`
10146
10264
  if (dryRun) {
10147
10265
  console.log(`[dry-run] Would create: ${ctxFilePath}`);
10148
10266
  } else {
10149
- await fs27.mkdir(ctxDir, { recursive: true });
10150
- await fs27.writeFile(ctxFilePath, ctxYaml, "utf-8");
10267
+ await fs29.mkdir(ctxDir, { recursive: true });
10268
+ await fs29.writeFile(ctxFilePath, ctxYaml, "utf-8");
10151
10269
  }
10152
10270
  indexManifest.bounded_contexts.push({
10153
10271
  name: ctx.name,
@@ -10163,7 +10281,7 @@ Validation successful. Found ${contexts.length} bounded contexts.`
10163
10281
  if (typeof app === "object" && app !== null && "name" in app) {
10164
10282
  const typedApp = app;
10165
10283
  const appName = typedApp.name;
10166
- const appFilePath = path35__default.join(appsDir, `${appName}.app.yaml`);
10284
+ const appFilePath = path34__default.join(appsDir, `${appName}.app.yaml`);
10167
10285
  const appYaml = yaml10.dump(app, {
10168
10286
  noRefs: true,
10169
10287
  sortKeys: false,
@@ -10172,7 +10290,7 @@ Validation successful. Found ${contexts.length} bounded contexts.`
10172
10290
  if (dryRun) {
10173
10291
  console.log(`[dry-run] Would create: ${appFilePath}`);
10174
10292
  } else {
10175
- await fs27.writeFile(appFilePath, appYaml, "utf-8");
10293
+ await fs29.writeFile(appFilePath, appYaml, "utf-8");
10176
10294
  }
10177
10295
  indexManifest.apps.push({
10178
10296
  name: appName,
@@ -10180,7 +10298,7 @@ Validation successful. Found ${contexts.length} bounded contexts.`
10180
10298
  });
10181
10299
  }
10182
10300
  }
10183
- const workspaceConfigPath = path35__default.join(archDir, "workspace.config.yaml");
10301
+ const workspaceConfigPath = path34__default.join(archDir, "workspace.config.yaml");
10184
10302
  const workspaceConfigYaml = yaml10.dump(workspaceConfig, {
10185
10303
  noRefs: true,
10186
10304
  sortKeys: false,
@@ -10191,7 +10309,7 @@ Validation successful. Found ${contexts.length} bounded contexts.`
10191
10309
  console.log("\n--- Preview of workspace.config.yaml ---\n");
10192
10310
  console.log(workspaceConfigYaml);
10193
10311
  } else {
10194
- await fs27.writeFile(workspaceConfigPath, workspaceConfigYaml, "utf-8");
10312
+ await fs29.writeFile(workspaceConfigPath, workspaceConfigYaml, "utf-8");
10195
10313
  }
10196
10314
  const indexYaml = yaml10.dump(indexManifest, {
10197
10315
  noRefs: true,
@@ -10212,9 +10330,9 @@ Validation successful. Found ${contexts.length} bounded contexts.`
10212
10330
  console.log(header + indexYaml);
10213
10331
  } else {
10214
10332
  const backupPath = monolithicManifestPath + ".pre-split-backup";
10215
- await fs27.copyFile(monolithicManifestPath, backupPath);
10333
+ await fs29.copyFile(monolithicManifestPath, backupPath);
10216
10334
  console.log(`Backup created at ${backupPath}`);
10217
- await fs27.writeFile(monolithicManifestPath, header + indexYaml, "utf-8");
10335
+ await fs29.writeFile(monolithicManifestPath, header + indexYaml, "utf-8");
10218
10336
  }
10219
10337
  console.log("\n✅ Manifest split completed successfully!");
10220
10338
  if (dryRun) {
@@ -10237,10 +10355,12 @@ Validation successful. Found ${contexts.length} bounded contexts.`
10237
10355
  });
10238
10356
  var MANIFEST_MIGRATIONS = [];
10239
10357
  var MigrateManifestUseCase = class {
10240
- constructor(currentVersion = CURRENT_MANIFEST_SCHEMA_VERSION, migrations = MANIFEST_MIGRATIONS) {
10358
+ constructor(deepEqual, currentVersion = CURRENT_MANIFEST_SCHEMA_VERSION, migrations = MANIFEST_MIGRATIONS) {
10359
+ this.deepEqual = deepEqual;
10241
10360
  this.currentVersion = currentVersion;
10242
10361
  this.migrations = migrations;
10243
10362
  }
10363
+ deepEqual;
10244
10364
  currentVersion;
10245
10365
  migrations;
10246
10366
  execute(content) {
@@ -10308,7 +10428,7 @@ var MigrateManifestUseCase = class {
10308
10428
  let stampedCleanly = false;
10309
10429
  try {
10310
10430
  const reparsed = yaml10.load(after);
10311
- stampedCleanly = readManifestSchemaVersion(reparsed) === this.currentVersion && isDeepStrictEqual(
10431
+ stampedCleanly = readManifestSchemaVersion(reparsed) === this.currentVersion && this.deepEqual(
10312
10432
  {
10313
10433
  ...yaml10.load(before),
10314
10434
  schemaVersion: this.currentVersion
@@ -10332,17 +10452,19 @@ var manifestMigrateCommander = new Command("migrate").description(
10332
10452
  const dryRun = options.dryRun ?? false;
10333
10453
  try {
10334
10454
  const workspaceRoot = await findWorkspaceRoot({});
10335
- const manifestPath = path35__default.join(
10455
+ const manifestPath = path34__default.join(
10336
10456
  workspaceRoot,
10337
10457
  ".architecture/manifest.yaml"
10338
10458
  );
10339
10459
  let content;
10340
10460
  try {
10341
- content = await fs27.readFile(manifestPath, "utf-8");
10461
+ content = await fs29.readFile(manifestPath, "utf-8");
10342
10462
  } catch {
10343
10463
  throw new Error(`Failed to read ${manifestPath}. Does it exist?`);
10344
10464
  }
10345
- const result = new MigrateManifestUseCase().execute(content);
10465
+ const result = new MigrateManifestUseCase(isDeepStrictEqual).execute(
10466
+ content
10467
+ );
10346
10468
  const from = result.fromVersion === void 0 ? "legacy (no schemaVersion)" : `schemaVersion ${result.fromVersion}`;
10347
10469
  console.log(`Manifest: ${manifestPath}`);
10348
10470
  console.log(`From : ${from}`);
@@ -10363,15 +10485,15 @@ var manifestMigrateCommander = new Command("migrate").description(
10363
10485
  return;
10364
10486
  }
10365
10487
  const backupPath = manifestPath + ".pre-migrate-backup";
10366
- await fs27.copyFile(manifestPath, backupPath);
10488
+ await fs29.copyFile(manifestPath, backupPath);
10367
10489
  console.log(`
10368
10490
  Backup created at ${backupPath}`);
10369
10491
  const tempPath = manifestPath + ".tmp";
10370
10492
  try {
10371
- await fs27.writeFile(tempPath, result.content, "utf-8");
10372
- await fs27.rename(tempPath, manifestPath);
10493
+ await fs29.writeFile(tempPath, result.content, "utf-8");
10494
+ await fs29.rename(tempPath, manifestPath);
10373
10495
  } catch (writeErr) {
10374
- await fs27.rm(tempPath, { force: true });
10496
+ await fs29.rm(tempPath, { force: true });
10375
10497
  throw writeErr;
10376
10498
  }
10377
10499
  console.log("✅ Manifest migrated successfully.");
@@ -10413,17 +10535,17 @@ async function pathExists(p) {
10413
10535
  }
10414
10536
  async function expandGlob(root, glob) {
10415
10537
  if (glob.endsWith("/*") && !glob.slice(0, -2).includes("*")) {
10416
- const dir = path35__default.join(root, glob.slice(0, -2));
10538
+ const dir = path34__default.join(root, glob.slice(0, -2));
10417
10539
  if (!await pathExists(dir)) return [];
10418
10540
  const entries = await promises.readdir(dir, { withFileTypes: true });
10419
- return entries.filter((e) => e.isDirectory() && !e.name.startsWith(".")).map((e) => path35__default.join(glob.slice(0, -2), e.name));
10541
+ return entries.filter((e) => e.isDirectory() && !e.name.startsWith(".")).map((e) => path34__default.join(glob.slice(0, -2), e.name));
10420
10542
  }
10421
10543
  if (glob.includes("*")) {
10422
10544
  throw new Error(
10423
10545
  `Complex globs like '${glob}' are not supported. Only simple trailing '/*' globs are currently supported.`
10424
10546
  );
10425
10547
  }
10426
- const abs = path35__default.join(root, glob);
10548
+ const abs = path34__default.join(root, glob);
10427
10549
  return await pathExists(abs) ? [glob] : [];
10428
10550
  }
10429
10551
  async function detectLayers(absRoot) {
@@ -10431,7 +10553,7 @@ async function detectLayers(absRoot) {
10431
10553
  for (const [layer, candidates] of Object.entries(LAYER_ALIASES)) {
10432
10554
  const found = [];
10433
10555
  for (const candidate of candidates) {
10434
- if (await pathExists(path35__default.join(absRoot, candidate))) {
10556
+ if (await pathExists(path34__default.join(absRoot, candidate))) {
10435
10557
  found.push(candidate);
10436
10558
  }
10437
10559
  }
@@ -10445,7 +10567,7 @@ function contextNameFrom(pkgName, dirName) {
10445
10567
  return dirName;
10446
10568
  }
10447
10569
  async function detectWorkspaces(root) {
10448
- const pkgPath = path35__default.join(root, "package.json");
10570
+ const pkgPath = path34__default.join(root, "package.json");
10449
10571
  let pkg = {};
10450
10572
  try {
10451
10573
  pkg = JSON.parse(await promises.readFile(pkgPath, "utf8"));
@@ -10458,17 +10580,17 @@ async function detectWorkspaces(root) {
10458
10580
  const packages = [];
10459
10581
  const seenNames = /* @__PURE__ */ new Set();
10460
10582
  for (const rel of candidates) {
10461
- const abs = path35__default.join(root, rel);
10583
+ const abs = path34__default.join(root, rel);
10462
10584
  let packageName;
10463
10585
  try {
10464
10586
  const child = JSON.parse(
10465
- await promises.readFile(path35__default.join(abs, "package.json"), "utf8")
10587
+ await promises.readFile(path34__default.join(abs, "package.json"), "utf8")
10466
10588
  );
10467
10589
  packageName = child.name;
10468
10590
  } catch {
10469
10591
  packageName = void 0;
10470
10592
  }
10471
- const dirName = rel === "." ? path35__default.basename(root) : path35__default.basename(rel);
10593
+ const dirName = rel === "." ? path34__default.basename(root) : path34__default.basename(rel);
10472
10594
  const name = contextNameFrom(packageName, dirName);
10473
10595
  if (seenNames.has(name)) {
10474
10596
  throw new Error(
@@ -10478,12 +10600,12 @@ async function detectWorkspaces(root) {
10478
10600
  seenNames.add(name);
10479
10601
  packages.push({
10480
10602
  name,
10481
- root: rel === "." ? "." : rel.split(path35__default.sep).join("/"),
10603
+ root: rel === "." ? "." : rel.split(path34__default.sep).join("/"),
10482
10604
  packageName,
10483
10605
  layers: await detectLayers(abs)
10484
10606
  });
10485
10607
  }
10486
- const system = typeof pkg.name === "string" && pkg.name.length > 0 ? pkg.name.replace(/^@[^/]+\//, "") : path35__default.basename(root);
10608
+ const system = typeof pkg.name === "string" && pkg.name.length > 0 ? pkg.name.replace(/^@[^/]+\//, "") : path34__default.basename(root);
10487
10609
  return { system, packages };
10488
10610
  }
10489
10611
 
@@ -10512,7 +10634,7 @@ async function runAdopt(options) {
10512
10634
  );
10513
10635
  }
10514
10636
  const contents = serializeLayout(detection);
10515
- const layoutPath = path35__default.join(options.root, ".architecture", "layout.yaml");
10637
+ const layoutPath = path34__default.join(options.root, ".architecture", "layout.yaml");
10516
10638
  if (options.dryRun === true) {
10517
10639
  return ok2({
10518
10640
  layoutPath,
@@ -10527,9 +10649,10 @@ async function runAdopt(options) {
10527
10649
  )
10528
10650
  );
10529
10651
  }
10530
- await promises.mkdir(path35__default.dirname(layoutPath), { recursive: true });
10531
- const exists = await promises.stat(layoutPath).then(() => true).catch(() => false);
10532
- if (exists && options.force !== true) {
10652
+ await promises.mkdir(path34__default.dirname(layoutPath), { recursive: true });
10653
+ const existsLookup = await lstatExists(layoutPath);
10654
+ if (!existsLookup.success) return existsLookup;
10655
+ if (existsLookup.value && options.force !== true) {
10533
10656
  return err2(
10534
10657
  new Error(
10535
10658
  `Refusing to overwrite existing ${layoutPath}. Pass --force to overwrite.`
@@ -10537,10 +10660,13 @@ async function runAdopt(options) {
10537
10660
  );
10538
10661
  }
10539
10662
  await promises.writeFile(layoutPath, contents, "utf8");
10540
- const hasManifest = await promises.stat(path35__default.join(options.root, ".architecture", "manifest.yaml")).then(() => true).catch(() => false);
10663
+ const manifestLookup = await lstatExists(
10664
+ path34__default.join(options.root, ".architecture", "manifest.yaml")
10665
+ );
10666
+ if (!manifestLookup.success) return manifestLookup;
10541
10667
  const nextSteps = [
10542
- `Wrote ${path35__default.relative(options.root, layoutPath) || ".architecture/layout.yaml"}.`,
10543
- hasManifest ? "Run `hexagen-lint --root .` to produce a first report (vacuous runs exit 2)." : "No manifest yet — run `hexagen bootstrap --yes` (or answer its questions) before linting."
10668
+ `Wrote ${path34__default.relative(options.root, layoutPath) || ".architecture/layout.yaml"}.`,
10669
+ manifestLookup.value ? "Run `hexagen-lint --root .` to produce a first report (vacuous runs exit 2)." : "No manifest yet — run `hexagen bootstrap --yes` (or answer its questions) before linting."
10544
10670
  ];
10545
10671
  if (options.invokeLint === true) {
10546
10672
  nextSteps.push(
@@ -10554,7 +10680,7 @@ async function runAdopt(options) {
10554
10680
  }
10555
10681
  async function adoptCommand(options) {
10556
10682
  const result = await runAdopt({
10557
- root: path35__default.resolve(options.root ?? process.cwd()),
10683
+ root: path34__default.resolve(options.root ?? process.cwd()),
10558
10684
  yes: options.yes,
10559
10685
  dryRun: options.dryRun,
10560
10686
  invokeLint: options.invokeLint,
@@ -10584,10 +10710,6 @@ var EMPTY_BASELINE = `{
10584
10710
  "entries": []
10585
10711
  }
10586
10712
  `;
10587
- function sanitizeScope2(raw) {
10588
- const cleaned = raw.trim().toLowerCase().replace(/^@+/, "").replace(/[^a-z0-9._-]/g, "-").replace(/[._-]{2,}/g, "-").slice(0, 214).replace(/^[._-]+|[._-]+$/g, "");
10589
- return cleaned.length > 0 ? cleaned : "generated-project";
10590
- }
10591
10713
  async function readAnswers(options) {
10592
10714
  if (options.answersPath) {
10593
10715
  try {
@@ -10624,7 +10746,7 @@ async function proposeAnswers(root, yes) {
10624
10746
  if (yes) {
10625
10747
  return ok2({
10626
10748
  system: detection.system,
10627
- scope: sanitizeScope2(detection.system),
10749
+ scope: sanitizeScope(detection.system),
10628
10750
  architecture: "modular-monolith",
10629
10751
  contexts: detection.packages.map((pkg) => ({
10630
10752
  name: pkg.name,
@@ -10649,7 +10771,7 @@ async function proposeAnswers(root, yes) {
10649
10771
  const system = await promptService.ask(
10650
10772
  `System name [${detection.system}]: `
10651
10773
  );
10652
- const scopeDefault = sanitizeScope2(system || detection.system);
10774
+ const scopeDefault = sanitizeScope(system || detection.system);
10653
10775
  const scope = await promptService.ask(`npm scope [${scopeDefault}]: `);
10654
10776
  const contexts = [];
10655
10777
  for (const pkg of detection.packages) {
@@ -10669,7 +10791,7 @@ async function proposeAnswers(root, yes) {
10669
10791
  }
10670
10792
  return ok2({
10671
10793
  system: system || detection.system,
10672
- scope: sanitizeScope2(scope || scopeDefault),
10794
+ scope: sanitizeScope(scope || scopeDefault),
10673
10795
  architecture: "modular-monolith",
10674
10796
  contexts
10675
10797
  });
@@ -10681,7 +10803,7 @@ function emitManifest(answers) {
10681
10803
  return yaml10.dump(
10682
10804
  {
10683
10805
  system: answers.system ?? "app",
10684
- scope: sanitizeScope2(answers.scope ?? answers.system ?? "app"),
10806
+ scope: sanitizeScope(answers.scope ?? answers.system ?? "app"),
10685
10807
  architecture: answers.architecture ?? "modular-monolith",
10686
10808
  bounded_contexts: answers.contexts.filter((c) => c.include).map((c) => ({
10687
10809
  name: c.name,
@@ -10740,24 +10862,22 @@ async function runBootstrap(options) {
10740
10862
  );
10741
10863
  }
10742
10864
  const detection = await detectWorkspaces(options.root);
10743
- const archDir = path35__default.join(options.root, ".architecture");
10865
+ const archDir = path34__default.join(options.root, ".architecture");
10744
10866
  const files = [
10745
- path35__default.join(archDir, "manifest.yaml"),
10746
- path35__default.join(archDir, "layout.yaml"),
10747
- path35__default.join(archDir, "arch-lint-baseline.json")
10867
+ path34__default.join(archDir, "manifest.yaml"),
10868
+ ...options.skipLayout === true ? [] : [path34__default.join(archDir, "layout.yaml")],
10869
+ path34__default.join(archDir, "arch-lint-baseline.json")
10748
10870
  ];
10749
- if (options.dryRun === true) {
10750
- return ok2({ files, wrote: false });
10751
- }
10752
10871
  if (options.force !== true) {
10753
10872
  const blockers = [];
10754
10873
  for (const file of files) {
10755
10874
  try {
10756
- await promises.stat(file);
10757
- } catch {
10758
- continue;
10875
+ await promises.lstat(file);
10876
+ } catch (e) {
10877
+ if (e.code === "ENOENT") continue;
10878
+ return err2(e instanceof Error ? e : new Error(String(e)));
10759
10879
  }
10760
- if (path35__default.basename(file) === "arch-lint-baseline.json") {
10880
+ if (path34__default.basename(file) === "arch-lint-baseline.json") {
10761
10881
  try {
10762
10882
  const parsed = JSON.parse(await promises.readFile(file, "utf8"));
10763
10883
  if (Array.isArray(parsed.entries) && parsed.entries.length > 0) {
@@ -10780,12 +10900,16 @@ ${blockers.map((b) => ` ${b}`).join("\n")}`
10780
10900
  );
10781
10901
  }
10782
10902
  }
10903
+ if (options.dryRun === true) {
10904
+ return ok2({ files, wrote: false });
10905
+ }
10783
10906
  await promises.mkdir(archDir, { recursive: true });
10784
- for (const [i, content] of [
10907
+ const contents = [
10785
10908
  emitManifest(answers),
10786
- emitLayout(answers, detection),
10909
+ ...options.skipLayout === true ? [] : [emitLayout(answers, detection)],
10787
10910
  EMPTY_BASELINE
10788
- ].entries()) {
10911
+ ];
10912
+ for (const [i, content] of contents.entries()) {
10789
10913
  await promises.writeFile(`${files[i]}.tmp`, content, "utf8");
10790
10914
  }
10791
10915
  for (const f of files) {
@@ -10798,7 +10922,7 @@ ${blockers.map((b) => ` ${b}`).join("\n")}`
10798
10922
  }
10799
10923
  async function bootstrapCommand(options) {
10800
10924
  const result = await runBootstrap({
10801
- root: path35__default.resolve(options.root ?? process.cwd()),
10925
+ root: path34__default.resolve(options.root ?? process.cwd()),
10802
10926
  yes: options.yes,
10803
10927
  answersPath: options.answers,
10804
10928
  stdinJson: options.stdinJson,
@@ -10828,7 +10952,7 @@ async function bootstrapCommand(options) {
10828
10952
  console.log("Dry-run: no files were written.");
10829
10953
  }
10830
10954
  var bootstrapCommander = new Command("bootstrap").description(
10831
- "Propose candidate bounded contexts as questions and emit manifest.yaml + layout.yaml + arch-lint-baseline.json after ratification"
10955
+ "Propose candidate bounded contexts as questions and emit manifest.yaml + layout.yaml + arch-lint-baseline.json after ratification. Does not infer depends_on from the import graph; supply contexts[].dependsOn in --answers if you need declared edges."
10832
10956
  ).option("--root <path>", "Project root (defaults to cwd)").option("--yes", "Accept every detected candidate (for tests / CI)").option(
10833
10957
  "--answers <file>",
10834
10958
  "JSON answers file (deterministic, non-interactive)"
@@ -11029,8 +11153,8 @@ var EMPTY_DRIFT = {
11029
11153
  collected: false
11030
11154
  };
11031
11155
  function buildEngagementReport(input) {
11032
- const baselinePath = path35__default.join(input.workspaceRoot, DEFAULT_BASELINE_REL);
11033
- const layoutPath = path35__default.join(input.workspaceRoot, DEFAULT_LAYOUT_REL);
11156
+ const baselinePath = path34__default.join(input.workspaceRoot, DEFAULT_BASELINE_REL);
11157
+ const layoutPath = path34__default.join(input.workspaceRoot, DEFAULT_LAYOUT_REL);
11034
11158
  const baselinePresent = existsSync(baselinePath);
11035
11159
  let suppressions = [];
11036
11160
  if (baselinePresent) {
@@ -11346,7 +11470,7 @@ function buildHandoffZip(report, workspaceRoot) {
11346
11470
  `
11347
11471
  }
11348
11472
  ];
11349
- const manifestPath = path35__default.join(
11473
+ const manifestPath = path34__default.join(
11350
11474
  workspaceRoot,
11351
11475
  ".architecture",
11352
11476
  "manifest.yaml"
@@ -11357,14 +11481,14 @@ function buildHandoffZip(report, workspaceRoot) {
11357
11481
  content: readFileSync(manifestPath, "utf8")
11358
11482
  });
11359
11483
  }
11360
- const layoutPath = path35__default.join(workspaceRoot, DEFAULT_LAYOUT_REL);
11484
+ const layoutPath = path34__default.join(workspaceRoot, DEFAULT_LAYOUT_REL);
11361
11485
  if (existsSync(layoutPath)) {
11362
11486
  entries.push({
11363
11487
  name: "layout.yaml",
11364
11488
  content: readFileSync(layoutPath, "utf8")
11365
11489
  });
11366
11490
  }
11367
- const baselinePath = path35__default.join(workspaceRoot, DEFAULT_BASELINE_REL);
11491
+ const baselinePath = path34__default.join(workspaceRoot, DEFAULT_BASELINE_REL);
11368
11492
  if (existsSync(baselinePath)) {
11369
11493
  entries.push({
11370
11494
  name: "arch-lint-baseline.json",
@@ -11460,11 +11584,11 @@ async function reportCommand(options = {}) {
11460
11584
  git: createGitReader(workspaceRoot),
11461
11585
  lint: createSpawnLintCollector(workspaceRoot)
11462
11586
  });
11463
- const outDir = path35__default.resolve(workspaceRoot, options.out ?? ".");
11587
+ const outDir = path34__default.resolve(workspaceRoot, options.out ?? ".");
11464
11588
  mkdirSync(outDir, { recursive: true });
11465
11589
  const format = options.format ?? "both";
11466
- const markdownPath = path35__default.join(outDir, "hexagen-report.md");
11467
- const htmlPath = path35__default.join(outDir, "hexagen-report.html");
11590
+ const markdownPath = path34__default.join(outDir, "hexagen-report.md");
11591
+ const htmlPath = path34__default.join(outDir, "hexagen-report.html");
11468
11592
  if (format === "md" || format === "both") {
11469
11593
  writeFileSync(markdownPath, renderReportMarkdown(report), "utf8");
11470
11594
  }
@@ -11473,11 +11597,11 @@ async function reportCommand(options = {}) {
11473
11597
  }
11474
11598
  let handoffPath;
11475
11599
  if (options.handoff) {
11476
- handoffPath = path35__default.resolve(
11600
+ handoffPath = path34__default.resolve(
11477
11601
  workspaceRoot,
11478
- options.handoffOut ?? path35__default.join(outDir, "hexagen-handoff.zip")
11602
+ options.handoffOut ?? path34__default.join(outDir, "hexagen-handoff.zip")
11479
11603
  );
11480
- mkdirSync(path35__default.dirname(handoffPath), { recursive: true });
11604
+ mkdirSync(path34__default.dirname(handoffPath), { recursive: true });
11481
11605
  writeFileSync(handoffPath, buildHandoffZip(report, workspaceRoot));
11482
11606
  }
11483
11607
  return { markdownPath, htmlPath, handoffPath };
@@ -11502,6 +11626,414 @@ async function runReportCommand(options) {
11502
11626
  }
11503
11627
  }
11504
11628
 
11629
+ // src/commands/scan/index.ts
11630
+ function readRequiredArtifact(filePath) {
11631
+ return readFileSync(filePath, "utf8");
11632
+ }
11633
+ function readOptionalArtifact(filePath) {
11634
+ try {
11635
+ return readFileSync(filePath, "utf8");
11636
+ } catch (e) {
11637
+ if (e?.code === "ENOENT") return null;
11638
+ throw e;
11639
+ }
11640
+ }
11641
+ function lintVerdict(exitCode) {
11642
+ if (exitCode === 0) {
11643
+ return "Architecture check passed (exit 0).";
11644
+ }
11645
+ if (exitCode === 1) {
11646
+ return "Architecture check found violations (exit 1). See hexagen-lint output.";
11647
+ }
11648
+ return `Architecture check could not run or scanned zero files (exit ${exitCode}). This is not a pass.`;
11649
+ }
11650
+ function uncollectedFindings(failureReason) {
11651
+ return {
11652
+ fresh: [],
11653
+ baselined: [],
11654
+ stale: [],
11655
+ expired: [],
11656
+ collected: false,
11657
+ failureReason
11658
+ };
11659
+ }
11660
+ function toLintOutcome(value) {
11661
+ if (typeof value === "number") {
11662
+ return {
11663
+ exitCode: value,
11664
+ findings: uncollectedFindings(
11665
+ "the lint runner reported an exit code only; hexagen-lint --json was not read"
11666
+ ),
11667
+ filesScanned: null
11668
+ };
11669
+ }
11670
+ return value;
11671
+ }
11672
+ function parseJsonRecord(line) {
11673
+ try {
11674
+ const value = JSON.parse(line);
11675
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
11676
+ return { ok: false, error: new Error("not a JSON object") };
11677
+ }
11678
+ return { ok: true, value };
11679
+ } catch (e) {
11680
+ return { ok: false, error: e instanceof Error ? e : new Error(String(e)) };
11681
+ }
11682
+ }
11683
+ function collectFilesScanned(stdout) {
11684
+ const line = stdout.split(/\r?\n/).map((l) => l.trim()).filter((l) => l.startsWith("{")).at(-1);
11685
+ if (line === void 0) return null;
11686
+ const parsed = parseJsonRecord(line);
11687
+ if (!parsed.ok) return null;
11688
+ {
11689
+ const raw = parsed.value;
11690
+ return typeof raw.filesScanned === "number" && Number.isInteger(raw.filesScanned) && raw.filesScanned > 0 ? raw.filesScanned : null;
11691
+ }
11692
+ }
11693
+ function collectLintFindings(stdout) {
11694
+ let parsed;
11695
+ try {
11696
+ parsed = parseLintJson(stdout);
11697
+ } catch (e) {
11698
+ return uncollectedFindings(
11699
+ `hexagen-lint --json output was not valid JSON: ${e instanceof Error ? e.message : String(e)}`
11700
+ );
11701
+ }
11702
+ if (!parsed.collected && parsed.failureReason === void 0) {
11703
+ return uncollectedFindings(
11704
+ "hexagen-lint --json printed no JSON line, so no findings could be read"
11705
+ );
11706
+ }
11707
+ return parsed;
11708
+ }
11709
+ var LINT_STDOUT_MAX_BYTES = 32 * 1024 * 1024;
11710
+ function invokeHexagenLint(root) {
11711
+ const bin = resolveArchLinterBin(root);
11712
+ if (bin === null) {
11713
+ console.error(
11714
+ "hexagen-lint not found — architecture was not checked (exit 2)."
11715
+ );
11716
+ return {
11717
+ exitCode: 2,
11718
+ findings: uncollectedFindings("hexagen-lint binary was not found"),
11719
+ filesScanned: null
11720
+ };
11721
+ }
11722
+ const useNode = /\.[cm]?js$/i.test(bin);
11723
+ const lintArgs = ["--root", root, "--json", "--ratchet"];
11724
+ const result = spawnSync(
11725
+ useNode ? process.execPath : bin,
11726
+ useNode ? [bin, ...lintArgs] : lintArgs,
11727
+ {
11728
+ cwd: root,
11729
+ stdio: ["ignore", "pipe", "inherit"],
11730
+ encoding: "utf8",
11731
+ maxBuffer: LINT_STDOUT_MAX_BYTES,
11732
+ timeout: resolveLinterTimeoutMs()
11733
+ }
11734
+ );
11735
+ if (result.error) {
11736
+ const errno = result.error.code;
11737
+ const message = errno === "ENOBUFS" ? `hexagen-lint produced more than ${LINT_STDOUT_MAX_BYTES} bytes of output and was stopped — architecture was not checked (exit 2).` : errno === "ETIMEDOUT" ? `hexagen-lint timed out and was stopped — architecture was not checked (exit 2).` : `hexagen-lint failed to start: ${result.error.message}`;
11738
+ console.error(message);
11739
+ return {
11740
+ exitCode: 2,
11741
+ findings: uncollectedFindings(message),
11742
+ filesScanned: null
11743
+ };
11744
+ }
11745
+ const stdout = typeof result.stdout === "string" ? result.stdout : "";
11746
+ for (const line of stdout.split(/\r?\n/)) {
11747
+ const trimmed = line.trim();
11748
+ if (trimmed !== "" && !trimmed.startsWith("{")) {
11749
+ console.log(line);
11750
+ }
11751
+ }
11752
+ if (result.status == null) {
11753
+ return {
11754
+ exitCode: 2,
11755
+ findings: uncollectedFindings(
11756
+ `hexagen-lint exited without a status code${result.signal ? ` (killed by ${result.signal})` : ""}`
11757
+ ),
11758
+ filesScanned: null
11759
+ };
11760
+ }
11761
+ return {
11762
+ exitCode: result.status,
11763
+ findings: collectLintFindings(stdout),
11764
+ filesScanned: collectFilesScanned(stdout)
11765
+ };
11766
+ }
11767
+ async function previewScan(root, options) {
11768
+ const layoutPath = path34__default.join(root, ".architecture", "layout.yaml");
11769
+ const manifestPath = path34__default.join(root, ".architecture", "manifest.yaml");
11770
+ const adopted = await runAdopt({ root, dryRun: true });
11771
+ if (!adopted.success) return adopted;
11772
+ const nextSteps = [...adopted.value.nextSteps];
11773
+ const manifestLookup = await lstatExists(manifestPath);
11774
+ if (!manifestLookup.success) return manifestLookup;
11775
+ if (!manifestLookup.value && options.skipBootstrap !== true) {
11776
+ const detection = await detectWorkspaces(root);
11777
+ nextSteps.push("Proposed bootstrap answers (not written):");
11778
+ nextSteps.push(` system: ${detection.system}`);
11779
+ nextSteps.push(" architecture: modular-monolith");
11780
+ for (const pkg of detection.packages) {
11781
+ nextSteps.push(` - ${pkg.name} (${pkg.root})`);
11782
+ }
11783
+ const bootstrapped = await runBootstrap({
11784
+ root,
11785
+ yes: true,
11786
+ dryRun: true,
11787
+ skipLayout: true
11788
+ });
11789
+ if (!bootstrapped.success) return bootstrapped;
11790
+ nextSteps.push("Would write:");
11791
+ for (const file of bootstrapped.value.files) {
11792
+ nextSteps.push(` ${file}`);
11793
+ }
11794
+ }
11795
+ return ok2({
11796
+ layoutPath,
11797
+ manifestPath,
11798
+ wrote: false,
11799
+ lintExitCode: 0,
11800
+ reportPaths: [],
11801
+ nextSteps,
11802
+ // --dry-run writes nothing, so there is nothing to report on. The envelope
11803
+ // is still emitted so a machine consumer gets the same shape on every
11804
+ // path and never has to special-case "preview returned no JSON".
11805
+ envelope: {
11806
+ schemaVersion: CURRENT_SCHEMA_VERSION,
11807
+ layout: null,
11808
+ filesScanned: null,
11809
+ reportMarkdown: null,
11810
+ error: null,
11811
+ // --dry-run never spawns the linter, so there is nothing to report.
11812
+ // Stated as an uncollected summary with a reason rather than four empty
11813
+ // arrays, which a consumer would render as "a clean tree".
11814
+ findings: uncollectedFindings("--dry-run does not run hexagen-lint")
11815
+ }
11816
+ });
11817
+ }
11818
+ async function runScan(options) {
11819
+ try {
11820
+ const root = options.root;
11821
+ const layoutPath = path34__default.join(root, ".architecture", "layout.yaml");
11822
+ const manifestPath = path34__default.join(root, ".architecture", "manifest.yaml");
11823
+ if (options.handoff === true && options.noReport === true) {
11824
+ return err2(
11825
+ new Error(
11826
+ "--handoff needs the engagement report; drop --no-report (the handoff zip is packed from the report)."
11827
+ )
11828
+ );
11829
+ }
11830
+ if (options.handoff === true && options.dryRun === true) {
11831
+ return err2(
11832
+ new Error(
11833
+ "--handoff writes a file, so it cannot be combined with --dry-run. Re-run with --yes to produce the handoff zip."
11834
+ )
11835
+ );
11836
+ }
11837
+ if (options.dryRun === true) {
11838
+ return previewScan(root, options);
11839
+ }
11840
+ if (options.yes !== true) {
11841
+ return err2(
11842
+ new Error(
11843
+ "Refusing to write architecture files without ratification. Re-run with --yes, or pass --dry-run to preview."
11844
+ )
11845
+ );
11846
+ }
11847
+ const layoutLookup = await lstatExists(layoutPath);
11848
+ if (!layoutLookup.success) return layoutLookup;
11849
+ const layoutExists = layoutLookup.value;
11850
+ const nextSteps = [];
11851
+ let wroteLayout = false;
11852
+ if (!layoutExists || options.force === true) {
11853
+ const adopted = await runAdopt({
11854
+ root,
11855
+ yes: true,
11856
+ force: options.force
11857
+ });
11858
+ if (!adopted.success) return adopted;
11859
+ wroteLayout = adopted.value.wrote;
11860
+ nextSteps.push(
11861
+ ...adopted.value.nextSteps.filter(
11862
+ (line) => !/No manifest yet/.test(line) && !/hexagen-lint --root/.test(line)
11863
+ )
11864
+ );
11865
+ } else {
11866
+ nextSteps.push(
11867
+ `Kept existing ${path34__default.relative(root, layoutPath) || ".architecture/layout.yaml"}.`
11868
+ );
11869
+ }
11870
+ const manifestLookup = await lstatExists(manifestPath);
11871
+ if (!manifestLookup.success) return manifestLookup;
11872
+ let wroteManifest = false;
11873
+ if (!manifestLookup.value && options.skipBootstrap !== true) {
11874
+ const bootstrapped = await runBootstrap({
11875
+ root,
11876
+ yes: true,
11877
+ force: options.force,
11878
+ // Scan owns layout.yaml via adopt. Bootstrap writes the missing
11879
+ // manifest (and an empty baseline if that is not already populated).
11880
+ skipLayout: true
11881
+ });
11882
+ if (!bootstrapped.success) return bootstrapped;
11883
+ wroteManifest = bootstrapped.value.wrote;
11884
+ if (wroteManifest) {
11885
+ nextSteps.push(
11886
+ "Wrote .architecture/manifest.yaml via bootstrap --yes (does not infer depends_on)."
11887
+ );
11888
+ }
11889
+ }
11890
+ const lintOutcome = toLintOutcome(
11891
+ await Promise.resolve((options.lint ?? invokeHexagenLint)(root))
11892
+ );
11893
+ const lintExitCode = lintOutcome.exitCode;
11894
+ nextSteps.push(lintVerdict(lintExitCode));
11895
+ const reportPaths = [];
11896
+ let handoffPath;
11897
+ const manifestNow = await lstatExists(manifestPath);
11898
+ if (!manifestNow.success) return manifestNow;
11899
+ if (options.noReport !== true) {
11900
+ if (!manifestNow.value) {
11901
+ if (options.handoff === true) {
11902
+ return err2(
11903
+ new Error(
11904
+ "Cannot write a handoff zip without .architecture/manifest.yaml — the zip is packed from the report, which needs a manifest. Omit --skip-bootstrap, or run hexagen bootstrap --yes first."
11905
+ )
11906
+ );
11907
+ }
11908
+ nextSteps.push(
11909
+ "Skipped report — no .architecture/manifest.yaml (omit --skip-bootstrap, or run hexagen bootstrap --yes)."
11910
+ );
11911
+ } else {
11912
+ try {
11913
+ const written = await (options.report ?? reportCommand)({
11914
+ cwd: root,
11915
+ format: "both",
11916
+ handoff: options.handoff === true,
11917
+ handoffOut: options.handoffOut
11918
+ });
11919
+ reportPaths.push(written.markdownPath, written.htmlPath);
11920
+ nextSteps.push(`Wrote ${written.markdownPath}`);
11921
+ nextSteps.push(`Wrote ${written.htmlPath}`);
11922
+ if (options.handoff === true) {
11923
+ if (written.handoffPath === void 0) {
11924
+ return err2(
11925
+ new Error(
11926
+ "Report ran but produced no handoff zip, so there is nothing to upload."
11927
+ )
11928
+ );
11929
+ }
11930
+ handoffPath = written.handoffPath;
11931
+ nextSteps.push(`Wrote ${handoffPath}`);
11932
+ }
11933
+ } catch (e) {
11934
+ return err2(
11935
+ new Error(
11936
+ `Report failed: ${e instanceof Error ? e.message : String(e)}`
11937
+ )
11938
+ );
11939
+ }
11940
+ }
11941
+ }
11942
+ nextSteps.push(
11943
+ "Review layout.yaml and manifest.yaml. hexagen bootstrap does not infer depends_on from the import graph."
11944
+ );
11945
+ const markdownPath = reportPaths.find((f) => f.endsWith(".md")) ?? null;
11946
+ return ok2({
11947
+ layoutPath,
11948
+ manifestPath,
11949
+ wrote: wroteLayout || wroteManifest,
11950
+ lintExitCode,
11951
+ reportPaths,
11952
+ handoffPath,
11953
+ nextSteps,
11954
+ envelope: {
11955
+ schemaVersion: CURRENT_SCHEMA_VERSION,
11956
+ layout: readRequiredArtifact(layoutPath),
11957
+ // The real count, from the same --json run the findings came from.
11958
+ // Null only when the linter could not run or its output could not be
11959
+ // parsed -- never a silent 0, which reads as "scanned nothing and
11960
+ // passed".
11961
+ filesScanned: lintOutcome.filesScanned,
11962
+ reportMarkdown: markdownPath ? readOptionalArtifact(markdownPath) : null,
11963
+ error: null,
11964
+ findings: lintOutcome.findings
11965
+ }
11966
+ });
11967
+ } catch (e) {
11968
+ return err2(e instanceof Error ? e : new Error(String(e)));
11969
+ }
11970
+ }
11971
+ async function scanCommand(options) {
11972
+ const result = await runScan({
11973
+ root: path34__default.resolve(options.root ?? process.cwd()),
11974
+ yes: options.yes,
11975
+ dryRun: options.dryRun,
11976
+ force: options.force,
11977
+ skipBootstrap: options.skipBootstrap,
11978
+ noReport: options.noReport,
11979
+ handoff: options.handoff,
11980
+ handoffOut: options.handoffOut
11981
+ });
11982
+ if (!result.success) {
11983
+ console.error(`❌ ${result.error.message}`);
11984
+ console.log(
11985
+ JSON.stringify({
11986
+ schemaVersion: CURRENT_SCHEMA_VERSION,
11987
+ layout: null,
11988
+ filesScanned: null,
11989
+ reportMarkdown: null,
11990
+ error: result.error.message,
11991
+ // The scan did not complete, so whatever the linter may or may not
11992
+ // have said is not a verdict on this tree. `collected: false` says
11993
+ // that; empty arrays alone would read as "clean".
11994
+ findings: uncollectedFindings(
11995
+ `the scan did not complete, so hexagen-lint findings were not reported: ${result.error.message}`
11996
+ )
11997
+ })
11998
+ );
11999
+ process.exitCode = 2;
12000
+ return;
12001
+ }
12002
+ for (const line of result.value.nextSteps) {
12003
+ console.log(line);
12004
+ }
12005
+ console.log(JSON.stringify(result.value.envelope));
12006
+ process.exitCode = result.value.lintExitCode;
12007
+ }
12008
+ var scanCommander = new Command("scan").description(
12009
+ "Import a brownfield tree: write layout.yaml, optionally bootstrap a starting manifest, run hexagen-lint, and write an engagement report"
12010
+ ).option("--root <path>", "Project root (defaults to cwd)").option("--yes", "Accept detected mappings and write files").option(
12011
+ "--dry-run",
12012
+ "Print the proposed layout (and bootstrap answers if no manifest) without writing"
12013
+ ).option("--force", "Overwrite existing layout.yaml").option(
12014
+ "--skip-bootstrap",
12015
+ "Do not run bootstrap even if .architecture/manifest.yaml is missing"
12016
+ ).option("--no-report", "Skip writing hexagen-report.md / hexagen-report.html").option(
12017
+ "--handoff",
12018
+ "Also write hexagen-handoff.zip (report + manifest + layout + baseline + ledger) for upload"
12019
+ ).option(
12020
+ "--handoff-out <path>",
12021
+ "Handoff zip path, relative to --root (default: <root>/hexagen-handoff.zip)"
12022
+ ).action(
12023
+ async (opts) => {
12024
+ await scanCommand({
12025
+ root: opts.root,
12026
+ yes: opts.yes,
12027
+ dryRun: opts.dryRun,
12028
+ force: opts.force,
12029
+ skipBootstrap: opts.skipBootstrap,
12030
+ noReport: opts.report === false,
12031
+ handoff: opts.handoff,
12032
+ handoffOut: opts.handoffOut
12033
+ });
12034
+ }
12035
+ );
12036
+
11505
12037
  // src/cli.ts
11506
12038
  function createLogger() {
11507
12039
  return {
@@ -11595,6 +12127,7 @@ function buildProgram() {
11595
12127
  program2.addCommand(manifestCommander);
11596
12128
  program2.addCommand(adoptCommander);
11597
12129
  program2.addCommand(bootstrapCommander);
12130
+ program2.addCommand(scanCommander);
11598
12131
  const templatesCommand = program2.command("templates").description("Manage and inspect add-on templates");
11599
12132
  templatesCommand.command("list").description("List all available add-on templates").action(async () => {
11600
12133
  await listTemplatesCommand();