@hexagen-monaco/sync 0.7.0 → 0.7.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.
- package/dist/application/use-cases/index.d.ts +1 -0
- package/dist/application/use-cases/index.d.ts.map +1 -1
- package/dist/application/use-cases/migrate-manifest.use-case.d.ts +48 -0
- package/dist/application/use-cases/migrate-manifest.use-case.d.ts.map +1 -0
- package/dist/cli.js +342 -59
- package/dist/cli.js.map +1 -1
- package/dist/commands/arch/validate.d.ts.map +1 -1
- package/dist/commands/manifest/index.d.ts.map +1 -1
- package/dist/commands/manifest/migrate.d.ts +10 -0
- package/dist/commands/manifest/migrate.d.ts.map +1 -0
- package/dist/generators/architecture-file-templates.d.ts +1 -1
- package/dist/generators/architecture-file-templates.d.ts.map +1 -1
- package/dist/generators/architecture-files.d.ts.map +1 -1
- package/dist/generators/layer-folders.d.ts +7 -2
- package/dist/generators/layer-folders.d.ts.map +1 -1
- package/dist/generators/reap.d.ts.map +1 -1
- package/dist/index.js +155 -29
- package/dist/index.js.map +1 -1
- package/dist/linter.d.ts.map +1 -1
- package/dist/results.d.ts +8 -0
- package/dist/results.d.ts.map +1 -1
- package/dist/sync-engine-init.d.ts +24 -2
- package/dist/sync-engine-init.d.ts.map +1 -1
- package/dist/sync-engine.d.ts +1 -0
- package/dist/sync-engine.d.ts.map +1 -1
- package/dist/templates/agents-md/files/AGENTS.md +7 -5
- package/dist/templates/env-setup/files/.gitignore.hexagen +4 -3
- package/dist/templates/observability/files/.agents/logging.md +34 -0
- package/dist/templates/observability/manifest.json +1 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -5,7 +5,7 @@ import path34__default, { dirname, join } from 'path';
|
|
|
5
5
|
import * as fs24 from 'fs';
|
|
6
6
|
import fs24__default, { mkdirSync, writeFileSync, renameSync, unlinkSync, existsSync, readFileSync, realpathSync, lstatSync, createWriteStream } from 'fs';
|
|
7
7
|
import fs27, { readFile } from 'fs/promises';
|
|
8
|
-
import { promisify } from 'util';
|
|
8
|
+
import { promisify, isDeepStrictEqual } from 'util';
|
|
9
9
|
import { exec, execSync, spawn } from 'child_process';
|
|
10
10
|
import yaml9 from 'js-yaml';
|
|
11
11
|
import crypto from 'crypto';
|
|
@@ -250,7 +250,7 @@ async function runArchLinter(config) {
|
|
|
250
250
|
});
|
|
251
251
|
if (stdout) logger2.info(stdout.trim());
|
|
252
252
|
if (stderr) logger2.error(stderr.trim());
|
|
253
|
-
logger2.info("✅ Architecture
|
|
253
|
+
logger2.info("✅ Architecture check passed (arch-linter).");
|
|
254
254
|
} catch (error) {
|
|
255
255
|
const message = error instanceof Error && "stderr" in error && error.stderr || error instanceof Error && error.message || "Unknown linter error";
|
|
256
256
|
logger2.error(`Architectural Integrity Check Failed:
|
|
@@ -456,6 +456,33 @@ async function ensureDirectoryCounted(dirPath, config, result) {
|
|
|
456
456
|
result.created.push(dirPath);
|
|
457
457
|
result.totalOps += 1;
|
|
458
458
|
}
|
|
459
|
+
async function ensureGitkeepCounted(dirPath, config, result) {
|
|
460
|
+
const keepPath = path34__default.join(dirPath, ".gitkeep");
|
|
461
|
+
let entries = null;
|
|
462
|
+
if (await directoryExists(dirPath)) {
|
|
463
|
+
entries = await fs27.readdir(dirPath);
|
|
464
|
+
}
|
|
465
|
+
if (entries !== null) {
|
|
466
|
+
const keepIsOnlyEntry = entries.length === 1 && entries[0] === ".gitkeep";
|
|
467
|
+
if (entries.length > 0 && !keepIsOnlyEntry) {
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
if (keepIsOnlyEntry) {
|
|
471
|
+
const existing = await fs27.readFile(keepPath, "utf8").catch(() => null);
|
|
472
|
+
if (existing !== null && existing !== "") {
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
const status = await safeWriteFileAtomic(
|
|
478
|
+
keepPath,
|
|
479
|
+
"",
|
|
480
|
+
config,
|
|
481
|
+
void 0,
|
|
482
|
+
true
|
|
483
|
+
);
|
|
484
|
+
recordWriteStatus(result, keepPath, status);
|
|
485
|
+
}
|
|
459
486
|
async function loadYamlSafe(filePath) {
|
|
460
487
|
try {
|
|
461
488
|
const content = await fs27.readFile(filePath, "utf8");
|
|
@@ -487,12 +514,16 @@ async function ensureLayerFolders(moduleDir, layers, config) {
|
|
|
487
514
|
}
|
|
488
515
|
await ensureDirectoryCounted(layerPath, config, result);
|
|
489
516
|
const subfolders = layerConfig.subfolders ?? [];
|
|
517
|
+
if (subfolders.length === 0) {
|
|
518
|
+
await ensureGitkeepCounted(layerPath, config, result);
|
|
519
|
+
}
|
|
490
520
|
for (const sub of subfolders) {
|
|
491
521
|
const subPath = path34__default.join(layerPath, sub);
|
|
492
522
|
if (!isInScope(subPath, config) && !isInScope(path34__default.join(subPath, "index.ts"), config)) {
|
|
493
523
|
continue;
|
|
494
524
|
}
|
|
495
525
|
await ensureDirectoryCounted(subPath, config, result);
|
|
526
|
+
await ensureGitkeepCounted(subPath, config, result);
|
|
496
527
|
}
|
|
497
528
|
}
|
|
498
529
|
return result;
|
|
@@ -524,18 +555,18 @@ function contentHash2(content) {
|
|
|
524
555
|
function detectCircularExports(exportGraph) {
|
|
525
556
|
const visited = /* @__PURE__ */ new Set();
|
|
526
557
|
const recursionStack = /* @__PURE__ */ new Set();
|
|
527
|
-
const
|
|
558
|
+
const path39 = [];
|
|
528
559
|
function dfs(node) {
|
|
529
560
|
if (recursionStack.has(node)) {
|
|
530
|
-
const cycleStart =
|
|
531
|
-
return [...
|
|
561
|
+
const cycleStart = path39.indexOf(node);
|
|
562
|
+
return [...path39.slice(cycleStart), node];
|
|
532
563
|
}
|
|
533
564
|
if (visited.has(node)) {
|
|
534
565
|
return null;
|
|
535
566
|
}
|
|
536
567
|
visited.add(node);
|
|
537
568
|
recursionStack.add(node);
|
|
538
|
-
|
|
569
|
+
path39.push(node);
|
|
539
570
|
const exports$1 = exportGraph.get(node) ?? [];
|
|
540
571
|
for (const exportPath of exports$1) {
|
|
541
572
|
const cycle = dfs(exportPath);
|
|
@@ -543,7 +574,7 @@ function detectCircularExports(exportGraph) {
|
|
|
543
574
|
return cycle;
|
|
544
575
|
}
|
|
545
576
|
}
|
|
546
|
-
|
|
577
|
+
path39.pop();
|
|
547
578
|
recursionStack.delete(node);
|
|
548
579
|
return null;
|
|
549
580
|
}
|
|
@@ -560,8 +591,8 @@ function generateBarrelContent(entries) {
|
|
|
560
591
|
return null;
|
|
561
592
|
}
|
|
562
593
|
const exportLines = entries.sort((a, b) => a.name.localeCompare(b.name)).map((entry) => {
|
|
563
|
-
const
|
|
564
|
-
return `export * from "${
|
|
594
|
+
const path39 = entry.isDirectory ? `./${entry.name}/index.js` : `./${entry.name}.js`;
|
|
595
|
+
return `export * from "${path39}";`;
|
|
565
596
|
});
|
|
566
597
|
return `${GENERATED_MARKER2}
|
|
567
598
|
|
|
@@ -1533,8 +1564,8 @@ function getErrorMap() {
|
|
|
1533
1564
|
|
|
1534
1565
|
// ../../node_modules/zod/v3/helpers/parseUtil.js
|
|
1535
1566
|
var makeIssue = (params) => {
|
|
1536
|
-
const { data, path:
|
|
1537
|
-
const fullPath = [...
|
|
1567
|
+
const { data, path: path39, errorMaps, issueData } = params;
|
|
1568
|
+
const fullPath = [...path39, ...issueData.path || []];
|
|
1538
1569
|
const fullIssue = {
|
|
1539
1570
|
...issueData,
|
|
1540
1571
|
path: fullPath
|
|
@@ -1650,11 +1681,11 @@ var errorUtil;
|
|
|
1650
1681
|
|
|
1651
1682
|
// ../../node_modules/zod/v3/types.js
|
|
1652
1683
|
var ParseInputLazyPath = class {
|
|
1653
|
-
constructor(parent, value,
|
|
1684
|
+
constructor(parent, value, path39, key) {
|
|
1654
1685
|
this._cachedPath = [];
|
|
1655
1686
|
this.parent = parent;
|
|
1656
1687
|
this.data = value;
|
|
1657
|
-
this._path =
|
|
1688
|
+
this._path = path39;
|
|
1658
1689
|
this._key = key;
|
|
1659
1690
|
}
|
|
1660
1691
|
get path() {
|
|
@@ -5302,7 +5333,7 @@ function assertValidToolchainVersion(version, source) {
|
|
|
5302
5333
|
function resolveToolchainVersion() {
|
|
5303
5334
|
{
|
|
5304
5335
|
return assertValidToolchainVersion(
|
|
5305
|
-
"0.7.
|
|
5336
|
+
"0.7.1",
|
|
5306
5337
|
"build-injected __HEXAGEN_TOOLCHAIN_VERSION__"
|
|
5307
5338
|
);
|
|
5308
5339
|
}
|
|
@@ -5515,7 +5546,7 @@ test_double_rules:
|
|
|
5515
5546
|
var GENERATOR_CONFIG_TEMPLATE = `generator:
|
|
5516
5547
|
version: "1.0"
|
|
5517
5548
|
description: "Global invariants and safety rules"
|
|
5518
|
-
|
|
5549
|
+
workspaceTemplate: "{workspaceTemplate}"
|
|
5519
5550
|
|
|
5520
5551
|
invariants:
|
|
5521
5552
|
- name: composite-safety
|
|
@@ -5596,37 +5627,65 @@ function resolveWorkspaceTemplate2(manifest) {
|
|
|
5596
5627
|
function toPascalCase(stem) {
|
|
5597
5628
|
return stem.split(/[-.]/).filter((part) => part.length > 0).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
5598
5629
|
}
|
|
5630
|
+
function yamlScalar(value) {
|
|
5631
|
+
const plainSafe = /^[A-Za-z][A-Za-z0-9._-]*$/.test(value);
|
|
5632
|
+
const reserved = /^(?:true|false|null|yes|no|on|off)$/i.test(value);
|
|
5633
|
+
return plainSafe && !reserved ? value : JSON.stringify(value);
|
|
5634
|
+
}
|
|
5599
5635
|
function buildOwnershipBlock(manifest) {
|
|
5600
5636
|
const contexts = manifest.bounded_contexts ?? [];
|
|
5601
5637
|
const entries = [];
|
|
5638
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5639
|
+
const owners = /* @__PURE__ */ new Map();
|
|
5640
|
+
const add = (name, context) => {
|
|
5641
|
+
const key = JSON.stringify([name, context]);
|
|
5642
|
+
if (seen.has(key)) return;
|
|
5643
|
+
seen.add(key);
|
|
5644
|
+
entries.push({ name, context });
|
|
5645
|
+
let contextsForName = owners.get(name);
|
|
5646
|
+
if (!contextsForName) {
|
|
5647
|
+
contextsForName = /* @__PURE__ */ new Set();
|
|
5648
|
+
owners.set(name, contextsForName);
|
|
5649
|
+
}
|
|
5650
|
+
contextsForName.add(context);
|
|
5651
|
+
};
|
|
5602
5652
|
for (const bc of contexts) {
|
|
5603
5653
|
if (bc.name === "shared") continue;
|
|
5604
5654
|
const application = bc.layers?.application;
|
|
5605
5655
|
const infrastructure = bc.layers?.infrastructure;
|
|
5606
5656
|
for (const p of application?.ports?.in ?? []) {
|
|
5607
|
-
|
|
5608
|
-
entries.push(` ${name}: ${bc.name}`);
|
|
5657
|
+
add(toPascalCase(portName(p).replace(/\.in-port\.ts$/, "")), bc.name);
|
|
5609
5658
|
}
|
|
5610
5659
|
for (const p of application?.ports?.out ?? []) {
|
|
5611
|
-
|
|
5612
|
-
entries.push(` ${name}: ${bc.name}`);
|
|
5660
|
+
add(toPascalCase(portName(p).replace(/\.out-port\.ts$/, "")), bc.name);
|
|
5613
5661
|
}
|
|
5614
5662
|
for (const a of infrastructure?.adapters ?? []) {
|
|
5615
|
-
|
|
5616
|
-
entries.push(` ${name}: ${bc.name}`);
|
|
5663
|
+
add(toPascalCase(a.replace(/\.adapter\.ts$/, "")), bc.name);
|
|
5617
5664
|
}
|
|
5618
5665
|
}
|
|
5619
|
-
|
|
5666
|
+
const collisions = [...owners.entries()].filter(([, contextsForName]) => contextsForName.size > 1).map(([name]) => name);
|
|
5667
|
+
const contested = new Set(collisions);
|
|
5668
|
+
const lines = entries.map(
|
|
5669
|
+
({ name, context }) => contested.has(name) ? ` ${JSON.stringify(`${context}.${name}`)}: ${yamlScalar(context)}` : ` ${name}: ${yamlScalar(context)}`
|
|
5670
|
+
);
|
|
5671
|
+
return {
|
|
5672
|
+
block: lines.length > 0 ? lines.join("\n") : " # No ports declared",
|
|
5673
|
+
collisions
|
|
5674
|
+
};
|
|
5620
5675
|
}
|
|
5621
5676
|
function buildInterpolationVars(manifest) {
|
|
5622
5677
|
const scope = resolveScope(manifest);
|
|
5623
5678
|
const workspaceTemplate = resolveWorkspaceTemplate2(manifest);
|
|
5679
|
+
const { block, collisions } = buildOwnershipBlock(manifest);
|
|
5624
5680
|
return {
|
|
5625
|
-
|
|
5626
|
-
|
|
5627
|
-
|
|
5628
|
-
|
|
5629
|
-
|
|
5681
|
+
vars: {
|
|
5682
|
+
scope,
|
|
5683
|
+
template: workspaceTemplate,
|
|
5684
|
+
workspaceTemplate,
|
|
5685
|
+
system: typeof manifest.system === "string" ? manifest.system : "",
|
|
5686
|
+
ownershipBlock: block
|
|
5687
|
+
},
|
|
5688
|
+
ownershipCollisions: collisions
|
|
5630
5689
|
};
|
|
5631
5690
|
}
|
|
5632
5691
|
function builtInLayerRules(workspaceTemplate) {
|
|
@@ -5706,8 +5765,13 @@ async function generateArchitectureFiles(config, report) {
|
|
|
5706
5765
|
const manifest = config.manifest;
|
|
5707
5766
|
const archRoot = path34__default.join(config.workspaceRoot, ".architecture");
|
|
5708
5767
|
const archInvariants = manifest.monorepo?.archInvariants;
|
|
5709
|
-
const vars = buildInterpolationVars(manifest);
|
|
5768
|
+
const { vars, ownershipCollisions } = buildInterpolationVars(manifest);
|
|
5710
5769
|
const workspaceTemplate = vars.workspaceTemplate ?? "modular-monolith";
|
|
5770
|
+
if (ownershipCollisions.length > 0) {
|
|
5771
|
+
config.logger.warn(
|
|
5772
|
+
`architecture-files: ownership-registry name collision${ownershipCollisions.length === 1 ? "" : "s"} — ${ownershipCollisions.join(", ")} declared by more than one context; emitted with context-qualified keys (the port-single-ownership invariant expects exactly one owner).`
|
|
5773
|
+
);
|
|
5774
|
+
}
|
|
5711
5775
|
await writeManifestIfFreshExternal(config, result, report);
|
|
5712
5776
|
const layerRulesPath = path34__default.join(archRoot, "invariants", "layer-rules.yaml");
|
|
5713
5777
|
const layerRulesTemplate = resolveTemplate2(
|
|
@@ -7647,6 +7711,10 @@ var AppSchema = external_exports.object({
|
|
|
7647
7711
|
depends_on: external_exports.array(external_exports.string()).optional()
|
|
7648
7712
|
}).strip();
|
|
7649
7713
|
var IndexManifestSchema = external_exports.object({
|
|
7714
|
+
// Toolchain-compatibility stamp (see manifest-schema-version.ts). Note
|
|
7715
|
+
// `version` below is a DIFFERENT field — its `"2.0"` string is the
|
|
7716
|
+
// index-form discriminator (`isIndexManifest`), not a compatibility gate.
|
|
7717
|
+
schemaVersion: external_exports.number().int().positive().optional(),
|
|
7650
7718
|
version: external_exports.string().optional(),
|
|
7651
7719
|
description: external_exports.string(),
|
|
7652
7720
|
system: external_exports.string().optional(),
|
|
@@ -7697,6 +7765,12 @@ var CrossContextEdgeSchema = external_exports.object({
|
|
|
7697
7765
|
integrationPattern: external_exports.enum(["open-host", "acl"]).optional()
|
|
7698
7766
|
});
|
|
7699
7767
|
var ManifestSchema = external_exports.object({
|
|
7768
|
+
// Toolchain-compatibility stamp (positive int; absent = legacy). NOT the
|
|
7769
|
+
// freeform `version` string below. Compatibility is asserted against the
|
|
7770
|
+
// RAW yaml BEFORE this `.strict()` parse (assertSupportedSchemaVersion in
|
|
7771
|
+
// manifest-schema-version.ts) — this entry only keeps strict mode from
|
|
7772
|
+
// rejecting stamped manifests as carrying an unknown key.
|
|
7773
|
+
schemaVersion: external_exports.number().int().positive().optional(),
|
|
7700
7774
|
version: external_exports.string().optional(),
|
|
7701
7775
|
description: external_exports.string().optional(),
|
|
7702
7776
|
system: external_exports.string().optional(),
|
|
@@ -7732,6 +7806,28 @@ var ManifestSchema = external_exports.object({
|
|
|
7732
7806
|
legacy_config: external_exports.string().optional()
|
|
7733
7807
|
}).strict();
|
|
7734
7808
|
|
|
7809
|
+
// ../project-configuration/dist/domain/model/manifest-schema/manifest-schema-version.js
|
|
7810
|
+
var CURRENT_MANIFEST_SCHEMA_VERSION = 1;
|
|
7811
|
+
function readManifestSchemaVersion(parsed) {
|
|
7812
|
+
if (parsed === null || typeof parsed !== "object")
|
|
7813
|
+
return void 0;
|
|
7814
|
+
const raw = parsed.schemaVersion;
|
|
7815
|
+
if (raw === void 0)
|
|
7816
|
+
return void 0;
|
|
7817
|
+
if (typeof raw !== "number" || !Number.isInteger(raw) || raw < 1) {
|
|
7818
|
+
throw new Error(`Invalid manifest schemaVersion: expected a positive integer, got ${JSON.stringify(raw)}.`);
|
|
7819
|
+
}
|
|
7820
|
+
return raw;
|
|
7821
|
+
}
|
|
7822
|
+
function assertSupportedSchemaVersion(parsed) {
|
|
7823
|
+
const version = readManifestSchemaVersion(parsed);
|
|
7824
|
+
if (version === void 0)
|
|
7825
|
+
return;
|
|
7826
|
+
if (version > CURRENT_MANIFEST_SCHEMA_VERSION) {
|
|
7827
|
+
throw new Error(`Manifest schemaVersion ${version} is newer than this toolchain supports (reads ≤ ${CURRENT_MANIFEST_SCHEMA_VERSION}). This manifest requires a newer @hexagen-monaco/sync — upgrade it. (Upgrading is always safe: a newer toolchain reads every older manifest, and \`hexagen manifest migrate\` brings one forward on demand.)`);
|
|
7828
|
+
}
|
|
7829
|
+
}
|
|
7830
|
+
|
|
7735
7831
|
// ../project-configuration/dist/domain/model/manifest-schema/is-index-manifest.js
|
|
7736
7832
|
function isIndexManifest(parsed) {
|
|
7737
7833
|
if (typeof parsed !== "object" || parsed === null) {
|
|
@@ -7926,6 +8022,7 @@ async function mergeSplitManifest(workspaceRoot, manifestPath) {
|
|
|
7926
8022
|
if (parsed == null) {
|
|
7927
8023
|
throw new Error("Manifest file is empty");
|
|
7928
8024
|
}
|
|
8025
|
+
assertSupportedSchemaVersion(parsed);
|
|
7929
8026
|
if (!isIndexManifest(parsed)) {
|
|
7930
8027
|
const manifestData = {
|
|
7931
8028
|
...parsed,
|
|
@@ -7940,6 +8037,9 @@ async function mergeSplitManifest(workspaceRoot, manifestPath) {
|
|
|
7940
8037
|
}
|
|
7941
8038
|
const index = indexResult.data;
|
|
7942
8039
|
const result = {
|
|
8040
|
+
// Carry the (already-validated) stamp into the merged form so consumers
|
|
8041
|
+
// of the merge see the same version the root file declares.
|
|
8042
|
+
schemaVersion: index.schemaVersion,
|
|
7943
8043
|
description: index.description ?? "Auto-generated manifest",
|
|
7944
8044
|
system: index.system,
|
|
7945
8045
|
scope: index.scope,
|
|
@@ -8012,30 +8112,48 @@ async function mergeSplitManifest(workspaceRoot, manifestPath) {
|
|
|
8012
8112
|
// src/sync-engine-init.ts
|
|
8013
8113
|
var __filename$1 = fileURLToPath(import.meta.url);
|
|
8014
8114
|
var __dirname$1 = path34__default.dirname(__filename$1);
|
|
8015
|
-
|
|
8016
|
-
|
|
8017
|
-
|
|
8018
|
-
|
|
8019
|
-
let currentDir =
|
|
8115
|
+
function isENOENT(err3) {
|
|
8116
|
+
return err3 instanceof Error && "code" in err3 && err3.code === "ENOENT";
|
|
8117
|
+
}
|
|
8118
|
+
async function findRootFrom(startDir, problems) {
|
|
8119
|
+
let currentDir = startDir;
|
|
8020
8120
|
while (currentDir !== path34__default.parse(currentDir).root) {
|
|
8121
|
+
const pkgPath = path34__default.join(currentDir, "package.json");
|
|
8021
8122
|
try {
|
|
8022
|
-
const pkgPath = path34__default.join(currentDir, "package.json");
|
|
8023
8123
|
const pkgContent = await fs27.readFile(pkgPath, "utf-8");
|
|
8024
8124
|
const pkg = JSON.parse(pkgContent);
|
|
8025
8125
|
if (pkg.workspaces && Array.isArray(pkg.workspaces)) {
|
|
8026
8126
|
return currentDir;
|
|
8027
8127
|
}
|
|
8028
|
-
} catch {
|
|
8128
|
+
} catch (err3) {
|
|
8129
|
+
if (!isENOENT(err3)) {
|
|
8130
|
+
const reason = err3 instanceof Error ? err3.message : String(err3);
|
|
8131
|
+
problems.push(new Error(`${pkgPath}: ${reason}`));
|
|
8132
|
+
}
|
|
8029
8133
|
}
|
|
8030
8134
|
currentDir = path34__default.dirname(currentDir);
|
|
8031
8135
|
}
|
|
8136
|
+
return null;
|
|
8137
|
+
}
|
|
8138
|
+
async function findWorkspaceRoot(options, probeStarts = [process.cwd(), __dirname$1]) {
|
|
8139
|
+
if (options.targetRoot) {
|
|
8140
|
+
return options.targetRoot;
|
|
8141
|
+
}
|
|
8142
|
+
const problems = [];
|
|
8143
|
+
for (const start of probeStarts) {
|
|
8144
|
+
const root = await findRootFrom(start, problems);
|
|
8145
|
+
if (root !== null) {
|
|
8146
|
+
return root;
|
|
8147
|
+
}
|
|
8148
|
+
}
|
|
8149
|
+
const detail = problems.length > 0 ? ` A package.json was found but could not be read or parsed: ${problems[0].message}.` : "";
|
|
8032
8150
|
throw new Error(
|
|
8033
|
-
|
|
8151
|
+
`Could not locate monorepo root: no package.json with a "workspaces" array found walking up from ${probeStarts.join(" or ")}.${detail} Run the command from inside your workspace (any subdirectory works), and check that the root package.json declares "workspaces". Note: a globally- or npx-installed CLI can only resolve the root from your current directory.`
|
|
8034
8152
|
);
|
|
8035
8153
|
}
|
|
8036
8154
|
async function loadManifest(workspaceRoot, flags, options) {
|
|
8037
8155
|
if (options.manifest) {
|
|
8038
|
-
return options.manifest;
|
|
8156
|
+
return { manifest: options.manifest, manifestMissing: false };
|
|
8039
8157
|
}
|
|
8040
8158
|
const { logger: logger2, dryRun } = flags;
|
|
8041
8159
|
const manifestPath = path34__default.join(workspaceRoot, ".architecture/manifest.yaml");
|
|
@@ -8048,11 +8166,14 @@ async function loadManifest(workspaceRoot, flags, options) {
|
|
|
8048
8166
|
manifestPath
|
|
8049
8167
|
);
|
|
8050
8168
|
logger2.info(`Loaded manifest from ${manifestPath}`);
|
|
8051
|
-
return manifest;
|
|
8169
|
+
return { manifest, manifestMissing: false };
|
|
8052
8170
|
} catch (err3) {
|
|
8053
|
-
if (err3
|
|
8171
|
+
if (isENOENT(err3) && dryRun) {
|
|
8054
8172
|
logger2.warn(`Manifest not found — using empty for dry-run`);
|
|
8055
|
-
return {
|
|
8173
|
+
return {
|
|
8174
|
+
manifest: { description: "Empty manifest", bounded_contexts: [] },
|
|
8175
|
+
manifestMissing: true
|
|
8176
|
+
};
|
|
8056
8177
|
}
|
|
8057
8178
|
const message = err3 instanceof Error ? err3.message : "Unknown parse error";
|
|
8058
8179
|
throw new Error(`Failed to parse manifest: ${message}`);
|
|
@@ -8112,6 +8233,7 @@ var SyncEngine = class {
|
|
|
8112
8233
|
partialConfig;
|
|
8113
8234
|
fullConfig = null;
|
|
8114
8235
|
manifest = {};
|
|
8236
|
+
manifestMissing = false;
|
|
8115
8237
|
workspaceRoot = "";
|
|
8116
8238
|
options;
|
|
8117
8239
|
constructor(flags, options) {
|
|
@@ -8246,6 +8368,7 @@ var SyncEngine = class {
|
|
|
8246
8368
|
let lockFile = null;
|
|
8247
8369
|
this.journal = new SyncJournal();
|
|
8248
8370
|
this.failures = [];
|
|
8371
|
+
this.manifestMissing = false;
|
|
8249
8372
|
logger2.info(
|
|
8250
8373
|
dryRun ? "[DRY-RUN MODE] Starting sync..." : "Starting sync..."
|
|
8251
8374
|
);
|
|
@@ -8285,11 +8408,13 @@ var SyncEngine = class {
|
|
|
8285
8408
|
try {
|
|
8286
8409
|
const initOptions = this.getInitOptions();
|
|
8287
8410
|
this.workspaceRoot = await findWorkspaceRoot(initOptions);
|
|
8288
|
-
|
|
8411
|
+
const loaded = await loadManifest(
|
|
8289
8412
|
this.workspaceRoot,
|
|
8290
8413
|
this.partialConfig,
|
|
8291
8414
|
initOptions
|
|
8292
8415
|
);
|
|
8416
|
+
this.manifest = loaded.manifest;
|
|
8417
|
+
this.manifestMissing = loaded.manifestMissing;
|
|
8293
8418
|
validateManifest(this.manifest, this.partialConfig);
|
|
8294
8419
|
this.fullConfig = {
|
|
8295
8420
|
...this.partialConfig,
|
|
@@ -8382,6 +8507,7 @@ var SyncEngine = class {
|
|
|
8382
8507
|
skipped: 0,
|
|
8383
8508
|
totalOps: 0,
|
|
8384
8509
|
errors: this.failures.length,
|
|
8510
|
+
manifestMissing: this.manifestMissing,
|
|
8385
8511
|
durationMs: 0
|
|
8386
8512
|
};
|
|
8387
8513
|
for (const [, r] of rows) {
|
|
@@ -8648,7 +8774,9 @@ async function validateCommand() {
|
|
|
8648
8774
|
process.exit(1);
|
|
8649
8775
|
return;
|
|
8650
8776
|
}
|
|
8651
|
-
console.log(
|
|
8777
|
+
console.log(
|
|
8778
|
+
"✅ Architecture is compliant (arch-linter: cross-context imports via manifest depends_on + linter-config, layer rules, subpath conventions, server markers, required communication)."
|
|
8779
|
+
);
|
|
8652
8780
|
}
|
|
8653
8781
|
var YamlLoadError = class extends Error {
|
|
8654
8782
|
constructor(message, filePath) {
|
|
@@ -8677,27 +8805,27 @@ var YamlSaveError = class extends Error {
|
|
|
8677
8805
|
filePath;
|
|
8678
8806
|
};
|
|
8679
8807
|
var YamlService = class {
|
|
8680
|
-
async loadManifest(
|
|
8808
|
+
async loadManifest(path39) {
|
|
8681
8809
|
try {
|
|
8682
|
-
const content = await readFile(
|
|
8810
|
+
const content = await readFile(path39, "utf-8");
|
|
8683
8811
|
const manifest = yaml9.load(content);
|
|
8684
8812
|
return ok2(manifest);
|
|
8685
8813
|
} catch (e) {
|
|
8686
8814
|
const error = e;
|
|
8687
8815
|
if (error.code === "ENOENT") {
|
|
8688
|
-
return err2(new YamlLoadError(`File not found: ${
|
|
8816
|
+
return err2(new YamlLoadError(`File not found: ${path39}`, path39));
|
|
8689
8817
|
}
|
|
8690
|
-
return err2(new YamlLoadError(error.message,
|
|
8818
|
+
return err2(new YamlLoadError(error.message, path39));
|
|
8691
8819
|
}
|
|
8692
8820
|
}
|
|
8693
|
-
saveManifest(manifest,
|
|
8694
|
-
const dir = dirname(
|
|
8695
|
-
const tempPath = `${
|
|
8821
|
+
saveManifest(manifest, path39) {
|
|
8822
|
+
const dir = dirname(path39);
|
|
8823
|
+
const tempPath = `${path39}.tmp`;
|
|
8696
8824
|
try {
|
|
8697
8825
|
mkdirSync(dir, { recursive: true });
|
|
8698
8826
|
const content = yaml9.dump(manifest, { indent: 2 });
|
|
8699
8827
|
writeFileSync(tempPath, content, "utf-8");
|
|
8700
|
-
renameSync(tempPath,
|
|
8828
|
+
renameSync(tempPath, path39);
|
|
8701
8829
|
return ok2(void 0);
|
|
8702
8830
|
} catch (e) {
|
|
8703
8831
|
const error = e;
|
|
@@ -8705,7 +8833,7 @@ var YamlService = class {
|
|
|
8705
8833
|
if (existsSync(tempPath)) unlinkSync(tempPath);
|
|
8706
8834
|
} catch {
|
|
8707
8835
|
}
|
|
8708
|
-
return err2(new YamlSaveError(error.message,
|
|
8836
|
+
return err2(new YamlSaveError(error.message, path39));
|
|
8709
8837
|
}
|
|
8710
8838
|
}
|
|
8711
8839
|
parse(content) {
|
|
@@ -9543,8 +9671,8 @@ var removeCommander = new Command("remove").description("Remove a port or bounde
|
|
|
9543
9671
|
function getManifestPath2(cwd) {
|
|
9544
9672
|
return join(cwd, ".architecture", "manifest.yaml");
|
|
9545
9673
|
}
|
|
9546
|
-
async function loadManifestFromPath(
|
|
9547
|
-
const result = await yamlService.loadManifest(
|
|
9674
|
+
async function loadManifestFromPath(path39) {
|
|
9675
|
+
const result = await yamlService.loadManifest(path39);
|
|
9548
9676
|
if (!result.success) {
|
|
9549
9677
|
return err2(result.error);
|
|
9550
9678
|
}
|
|
@@ -10025,19 +10153,19 @@ function resolveDependencies(requested, registry) {
|
|
|
10025
10153
|
}
|
|
10026
10154
|
const sorted = [];
|
|
10027
10155
|
const state = /* @__PURE__ */ new Map();
|
|
10028
|
-
function visit(id,
|
|
10156
|
+
function visit(id, path39) {
|
|
10029
10157
|
const s = state.get(id);
|
|
10030
10158
|
if (s === "done")
|
|
10031
10159
|
return;
|
|
10032
10160
|
if (s === "visiting") {
|
|
10033
|
-
const cycleStart =
|
|
10034
|
-
throw new CyclicDependencyError([...
|
|
10161
|
+
const cycleStart = path39.indexOf(id);
|
|
10162
|
+
throw new CyclicDependencyError([...path39.slice(cycleStart), id]);
|
|
10035
10163
|
}
|
|
10036
10164
|
state.set(id, "visiting");
|
|
10037
10165
|
const manifest = registry.get(id);
|
|
10038
10166
|
for (const dep of manifest.requires) {
|
|
10039
10167
|
if (needed.has(dep))
|
|
10040
|
-
visit(dep, [...
|
|
10168
|
+
visit(dep, [...path39, id]);
|
|
10041
10169
|
}
|
|
10042
10170
|
state.set(id, "done");
|
|
10043
10171
|
sorted.push(id);
|
|
@@ -10706,8 +10834,8 @@ Installed templates: ${installed}
|
|
|
10706
10834
|
function getManifestPath3(cwd) {
|
|
10707
10835
|
return join(cwd, ".architecture", "manifest.yaml");
|
|
10708
10836
|
}
|
|
10709
|
-
async function loadManifest4(
|
|
10710
|
-
const result = await yamlService.loadManifest(
|
|
10837
|
+
async function loadManifest4(path39) {
|
|
10838
|
+
const result = await yamlService.loadManifest(path39);
|
|
10711
10839
|
if (!result.success) {
|
|
10712
10840
|
throw result.error;
|
|
10713
10841
|
}
|
|
@@ -13029,12 +13157,161 @@ Validation successful. Found ${contexts.length} bounded contexts.`
|
|
|
13029
13157
|
process.exit(1);
|
|
13030
13158
|
}
|
|
13031
13159
|
});
|
|
13160
|
+
var MANIFEST_MIGRATIONS = [];
|
|
13161
|
+
var MigrateManifestUseCase = class {
|
|
13162
|
+
constructor(currentVersion = CURRENT_MANIFEST_SCHEMA_VERSION, migrations = MANIFEST_MIGRATIONS) {
|
|
13163
|
+
this.currentVersion = currentVersion;
|
|
13164
|
+
this.migrations = migrations;
|
|
13165
|
+
}
|
|
13166
|
+
currentVersion;
|
|
13167
|
+
migrations;
|
|
13168
|
+
execute(content) {
|
|
13169
|
+
const parsed = yaml9.load(content);
|
|
13170
|
+
if (parsed == null) {
|
|
13171
|
+
throw new Error("Manifest file is empty");
|
|
13172
|
+
}
|
|
13173
|
+
if (typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
13174
|
+
throw new Error(
|
|
13175
|
+
"Manifest root must be a YAML mapping — nothing to migrate."
|
|
13176
|
+
);
|
|
13177
|
+
}
|
|
13178
|
+
const fromVersion = readManifestSchemaVersion(parsed);
|
|
13179
|
+
if (fromVersion !== void 0 && fromVersion > this.currentVersion) {
|
|
13180
|
+
throw new Error(
|
|
13181
|
+
`Manifest schemaVersion ${fromVersion} is newer than this toolchain supports (reads ≤ ${this.currentVersion}). Migration only goes forward — upgrade @hexagen-monaco/sync instead.`
|
|
13182
|
+
);
|
|
13183
|
+
}
|
|
13184
|
+
const steps = [...this.migrations].filter(
|
|
13185
|
+
(m) => m.toVersion > (fromVersion ?? 0) && m.toVersion <= this.currentVersion
|
|
13186
|
+
).sort((a, b) => a.toVersion - b.toVersion);
|
|
13187
|
+
let migrated = content;
|
|
13188
|
+
const applied = [];
|
|
13189
|
+
for (const step of steps) {
|
|
13190
|
+
migrated = step.apply(migrated);
|
|
13191
|
+
applied.push(`v${step.toVersion}: ${step.description}`);
|
|
13192
|
+
}
|
|
13193
|
+
const stamped = this.stamp(migrated, fromVersion);
|
|
13194
|
+
this.assertStampOnlyAddedTheVersion(migrated, stamped);
|
|
13195
|
+
return {
|
|
13196
|
+
content: stamped,
|
|
13197
|
+
fromVersion,
|
|
13198
|
+
toVersion: this.currentVersion,
|
|
13199
|
+
applied,
|
|
13200
|
+
changed: stamped !== content
|
|
13201
|
+
};
|
|
13202
|
+
}
|
|
13203
|
+
/**
|
|
13204
|
+
* Textually stamp `schemaVersion: <current>` — replace an existing
|
|
13205
|
+
* top-level stamp line in place, or insert one above the first content
|
|
13206
|
+
* line. YAML nesting is indentation, so a top-level key is exactly a
|
|
13207
|
+
* column-0 `schemaVersion:` line; comments (`# …`) and the document-start
|
|
13208
|
+
* marker (`---`) never match it.
|
|
13209
|
+
*/
|
|
13210
|
+
stamp(content, fromVersion) {
|
|
13211
|
+
const stampLine = `schemaVersion: ${this.currentVersion}`;
|
|
13212
|
+
if (fromVersion === this.currentVersion) return content;
|
|
13213
|
+
if (fromVersion !== void 0) {
|
|
13214
|
+
return content.replace(/^schemaVersion:[^\n]*$/m, stampLine);
|
|
13215
|
+
}
|
|
13216
|
+
const lines = content.split("\n");
|
|
13217
|
+
const firstContent = lines.findIndex(
|
|
13218
|
+
(line) => line.trim() !== "" && !line.trimStart().startsWith("#") && line.trim() !== "---"
|
|
13219
|
+
);
|
|
13220
|
+
lines.splice(firstContent, 0, stampLine);
|
|
13221
|
+
return lines.join("\n");
|
|
13222
|
+
}
|
|
13223
|
+
/**
|
|
13224
|
+
* The refusal that makes the textual edit safe: re-parse and require the
|
|
13225
|
+
* result to be the input plus (only) the current `schemaVersion`. A result
|
|
13226
|
+
* that no longer parses at all (e.g. a stamp inserted above a flow-style
|
|
13227
|
+
* root mapping) is the same failure, not a parser stack trace.
|
|
13228
|
+
*/
|
|
13229
|
+
assertStampOnlyAddedTheVersion(before, after) {
|
|
13230
|
+
let stampedCleanly = false;
|
|
13231
|
+
try {
|
|
13232
|
+
const reparsed = yaml9.load(after);
|
|
13233
|
+
stampedCleanly = readManifestSchemaVersion(reparsed) === this.currentVersion && isDeepStrictEqual(
|
|
13234
|
+
{
|
|
13235
|
+
...yaml9.load(before),
|
|
13236
|
+
schemaVersion: this.currentVersion
|
|
13237
|
+
},
|
|
13238
|
+
reparsed
|
|
13239
|
+
);
|
|
13240
|
+
} catch {
|
|
13241
|
+
}
|
|
13242
|
+
if (!stampedCleanly) {
|
|
13243
|
+
throw new Error(
|
|
13244
|
+
`Could not stamp schemaVersion ${this.currentVersion} without altering the manifest (unsupported YAML layout — e.g. a flow-style root mapping). Add \`schemaVersion: ${this.currentVersion}\` as a top-level key by hand.`
|
|
13245
|
+
);
|
|
13246
|
+
}
|
|
13247
|
+
}
|
|
13248
|
+
};
|
|
13249
|
+
|
|
13250
|
+
// src/commands/manifest/migrate.ts
|
|
13251
|
+
var manifestMigrateCommander = new Command("migrate").description(
|
|
13252
|
+
"Bring .architecture/manifest.yaml to the current schema version (stamps schemaVersion, applies registered migrations)"
|
|
13253
|
+
).option("--dry-run", "Preview changes without writing files").action(async (options) => {
|
|
13254
|
+
const dryRun = options.dryRun ?? false;
|
|
13255
|
+
try {
|
|
13256
|
+
const workspaceRoot = await findWorkspaceRoot({});
|
|
13257
|
+
const manifestPath = path34__default.join(
|
|
13258
|
+
workspaceRoot,
|
|
13259
|
+
".architecture/manifest.yaml"
|
|
13260
|
+
);
|
|
13261
|
+
let content;
|
|
13262
|
+
try {
|
|
13263
|
+
content = await fs27.readFile(manifestPath, "utf-8");
|
|
13264
|
+
} catch {
|
|
13265
|
+
throw new Error(`Failed to read ${manifestPath}. Does it exist?`);
|
|
13266
|
+
}
|
|
13267
|
+
const result = new MigrateManifestUseCase().execute(content);
|
|
13268
|
+
const from = result.fromVersion === void 0 ? "legacy (no schemaVersion)" : `schemaVersion ${result.fromVersion}`;
|
|
13269
|
+
console.log(`Manifest: ${manifestPath}`);
|
|
13270
|
+
console.log(`From : ${from}`);
|
|
13271
|
+
console.log(`To : schemaVersion ${result.toVersion}`);
|
|
13272
|
+
for (const step of result.applied) {
|
|
13273
|
+
console.log(`Applied : ${step}`);
|
|
13274
|
+
}
|
|
13275
|
+
if (!result.changed) {
|
|
13276
|
+
console.log(
|
|
13277
|
+
"\n✅ Already at the current schema version — nothing to do."
|
|
13278
|
+
);
|
|
13279
|
+
return;
|
|
13280
|
+
}
|
|
13281
|
+
if (dryRun) {
|
|
13282
|
+
console.log(
|
|
13283
|
+
"\n[dry-run] Would rewrite the manifest. No files written."
|
|
13284
|
+
);
|
|
13285
|
+
return;
|
|
13286
|
+
}
|
|
13287
|
+
const backupPath = manifestPath + ".pre-migrate-backup";
|
|
13288
|
+
await fs27.copyFile(manifestPath, backupPath);
|
|
13289
|
+
console.log(`
|
|
13290
|
+
Backup created at ${backupPath}`);
|
|
13291
|
+
const tempPath = manifestPath + ".tmp";
|
|
13292
|
+
try {
|
|
13293
|
+
await fs27.writeFile(tempPath, result.content, "utf-8");
|
|
13294
|
+
await fs27.rename(tempPath, manifestPath);
|
|
13295
|
+
} catch (writeErr) {
|
|
13296
|
+
await fs27.rm(tempPath, { force: true });
|
|
13297
|
+
throw writeErr;
|
|
13298
|
+
}
|
|
13299
|
+
console.log("✅ Manifest migrated successfully.");
|
|
13300
|
+
} catch (err3) {
|
|
13301
|
+
console.error(
|
|
13302
|
+
`
|
|
13303
|
+
❌ Migration failed: ${err3 instanceof Error ? err3.message : String(err3)}`
|
|
13304
|
+
);
|
|
13305
|
+
process.exit(1);
|
|
13306
|
+
}
|
|
13307
|
+
});
|
|
13032
13308
|
|
|
13033
13309
|
// src/commands/manifest/index.ts
|
|
13034
13310
|
var manifestCommander = new Command("manifest").description(
|
|
13035
13311
|
"Manage the architecture manifest lifecycle"
|
|
13036
13312
|
);
|
|
13037
13313
|
manifestCommander.addCommand(manifestSplitCommander);
|
|
13314
|
+
manifestCommander.addCommand(manifestMigrateCommander);
|
|
13038
13315
|
|
|
13039
13316
|
// src/cli.ts
|
|
13040
13317
|
function createLogger() {
|
|
@@ -13092,6 +13369,12 @@ function buildProgram() {
|
|
|
13092
13369
|
);
|
|
13093
13370
|
process.exitCode = 1;
|
|
13094
13371
|
}
|
|
13372
|
+
if (check && summary.manifestMissing) {
|
|
13373
|
+
console.error(
|
|
13374
|
+
"Manifest not found — `--check` cannot verify drift without a manifest at `.architecture/manifest.yaml`. Check you are running from inside the intended workspace (cwd is resolved first)."
|
|
13375
|
+
);
|
|
13376
|
+
process.exitCode = 1;
|
|
13377
|
+
}
|
|
13095
13378
|
if (check && summary.totalOps > 0) {
|
|
13096
13379
|
console.error(
|
|
13097
13380
|
`Drift detected: ${summary.totalOps} pending change(s) (${summary.created} to create, ${summary.updated} to update, ${summary.deleted} to delete). Run \`hexagen sync\` to converge.`
|