@hexagen-monaco/sync 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -0
- package/dist/application/use-cases/stamp-generator-identity.use-case.d.ts +12 -0
- package/dist/application/use-cases/stamp-generator-identity.use-case.d.ts.map +1 -0
- package/dist/cli.js +3389 -1973
- package/dist/cli.js.map +1 -1
- package/dist/commands/arch/validate-outcome.d.ts +30 -0
- package/dist/commands/arch/validate-outcome.d.ts.map +1 -0
- package/dist/commands/arch/validate.d.ts +3 -1
- package/dist/commands/arch/validate.d.ts.map +1 -1
- package/dist/commands/bootstrap/index.d.ts.map +1 -1
- package/dist/commands/manifest/migrate.d.ts +8 -0
- package/dist/commands/manifest/migrate.d.ts.map +1 -1
- package/dist/commands/remove/index.d.ts +41 -0
- package/dist/commands/remove/index.d.ts.map +1 -0
- package/dist/commands/shared/confirm.d.ts.map +1 -1
- package/dist/commands/sync/check-json.d.ts +47 -0
- package/dist/commands/sync/check-json.d.ts.map +1 -0
- package/dist/generators/architecture-files.d.ts.map +1 -1
- package/dist/index.js +539 -525
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/config/index.d.ts +3 -0
- package/dist/infrastructure/config/index.d.ts.map +1 -0
- package/dist/infrastructure/index.d.ts +1 -0
- package/dist/infrastructure/index.d.ts.map +1 -1
- package/dist/types/manifest/generator.d.ts +2 -0
- package/dist/types/manifest/generator.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1694,7 +1694,7 @@ function assertValidToolchainVersion(version, source) {
|
|
|
1694
1694
|
function resolveToolchainVersion() {
|
|
1695
1695
|
{
|
|
1696
1696
|
return assertValidToolchainVersion(
|
|
1697
|
-
"0.
|
|
1697
|
+
"0.15.0",
|
|
1698
1698
|
"build-injected __HEXAGEN_TOOLCHAIN_VERSION__"
|
|
1699
1699
|
);
|
|
1700
1700
|
}
|
|
@@ -1984,6 +1984,392 @@ async function generateRootFiles(config, report) {
|
|
|
1984
1984
|
return result;
|
|
1985
1985
|
}
|
|
1986
1986
|
}
|
|
1987
|
+
function caseInsensitiveEnum(schema, dir = "lower") {
|
|
1988
|
+
return z.preprocess((value) => typeof value === "string" ? dir === "lower" ? value.trim().toLowerCase() : value.trim().toUpperCase() : value, schema);
|
|
1989
|
+
}
|
|
1990
|
+
var BoundedContextTypeSchema = boundedContextTypeSchema;
|
|
1991
|
+
var PLANE_NAMES = [
|
|
1992
|
+
"projection",
|
|
1993
|
+
"probabilistic",
|
|
1994
|
+
"infrastructure",
|
|
1995
|
+
"shared-kernel",
|
|
1996
|
+
"core",
|
|
1997
|
+
"supporting"
|
|
1998
|
+
];
|
|
1999
|
+
var PlaneTypeSchema = caseInsensitiveEnum(z.enum(PLANE_NAMES));
|
|
2000
|
+
var StatusTypeSchema = caseInsensitiveEnum(z.enum(["active", "frozen", "deprecated", "experimental"]));
|
|
2001
|
+
var RelationshipPatternSchema = caseInsensitiveEnum(z.enum(["U/D", "ACL", "SK", "P", "OHS"]), "upper");
|
|
2002
|
+
var RelationshipRoleSchema = caseInsensitiveEnum(z.enum(["upstream", "downstream", "peer"]));
|
|
2003
|
+
var RelationshipSchema = z.object({
|
|
2004
|
+
context: z.string(),
|
|
2005
|
+
pattern: RelationshipPatternSchema,
|
|
2006
|
+
role: RelationshipRoleSchema.optional(),
|
|
2007
|
+
acl: z.object({
|
|
2008
|
+
adapter: z.string(),
|
|
2009
|
+
location: z.string().optional(),
|
|
2010
|
+
notes: z.string().optional()
|
|
2011
|
+
}).optional(),
|
|
2012
|
+
notes: z.string().optional()
|
|
2013
|
+
});
|
|
2014
|
+
var PortDefinitionSchema = z.object({
|
|
2015
|
+
name: z.string(),
|
|
2016
|
+
owner: z.string().optional()
|
|
2017
|
+
});
|
|
2018
|
+
var LegacyOrNewPortSchema = z.union([
|
|
2019
|
+
z.string(),
|
|
2020
|
+
PortDefinitionSchema
|
|
2021
|
+
]);
|
|
2022
|
+
caseInsensitiveEnum(z.enum(["domain", "application", "infrastructure"]));
|
|
2023
|
+
var UiLayerSchema = z.object({
|
|
2024
|
+
components: z.array(z.string()).optional()
|
|
2025
|
+
}).passthrough();
|
|
2026
|
+
var BoundedContextSchema = z.object({
|
|
2027
|
+
name: z.string(),
|
|
2028
|
+
type: BoundedContextTypeSchema.optional(),
|
|
2029
|
+
plane: PlaneTypeSchema.optional(),
|
|
2030
|
+
status: StatusTypeSchema.optional(),
|
|
2031
|
+
description: z.string().optional(),
|
|
2032
|
+
relationships: z.array(RelationshipSchema).optional(),
|
|
2033
|
+
// PASSTHROUGH, not strict, at every level of this subtree — a deliberate
|
|
2034
|
+
// choice, see the note on the schema below. Zod's default `z.object` STRIPS
|
|
2035
|
+
// undeclared keys, which is how `layers.ui` disappeared between the file on
|
|
2036
|
+
// disk and every consumer of the merged manifest.
|
|
2037
|
+
layers: z.object({
|
|
2038
|
+
domain: z.object({
|
|
2039
|
+
entities: z.array(z.string()).optional(),
|
|
2040
|
+
value_objects: z.array(z.string()).optional()
|
|
2041
|
+
}).passthrough().optional(),
|
|
2042
|
+
application: z.object({
|
|
2043
|
+
use_cases: z.array(z.string()).optional(),
|
|
2044
|
+
ports: z.object({
|
|
2045
|
+
in: z.array(LegacyOrNewPortSchema).optional(),
|
|
2046
|
+
out: z.array(LegacyOrNewPortSchema).optional()
|
|
2047
|
+
}).passthrough().optional()
|
|
2048
|
+
}).passthrough().optional(),
|
|
2049
|
+
infrastructure: z.object({
|
|
2050
|
+
adapters: z.array(z.string()).optional()
|
|
2051
|
+
}).passthrough().optional(),
|
|
2052
|
+
ui: UiLayerSchema.optional()
|
|
2053
|
+
}).passthrough().optional(),
|
|
2054
|
+
depends_on: z.array(z.string()).optional(),
|
|
2055
|
+
wiring: z.array(z.string()).optional(),
|
|
2056
|
+
generator: z.record(z.unknown()).optional()
|
|
2057
|
+
}).passthrough();
|
|
2058
|
+
var AppSchema = z.object({
|
|
2059
|
+
name: z.string(),
|
|
2060
|
+
framework: z.string().optional(),
|
|
2061
|
+
version: z.string().optional(),
|
|
2062
|
+
driver: z.string().optional(),
|
|
2063
|
+
description: z.string().optional(),
|
|
2064
|
+
role: z.string().optional(),
|
|
2065
|
+
router: z.string().optional(),
|
|
2066
|
+
deployment: z.string().optional(),
|
|
2067
|
+
auth: z.string().optional(),
|
|
2068
|
+
schedule: z.string().optional(),
|
|
2069
|
+
ui: z.object({
|
|
2070
|
+
library: z.string().optional(),
|
|
2071
|
+
styling: z.string().optional()
|
|
2072
|
+
}).optional(),
|
|
2073
|
+
responsibilities: z.array(z.string()).optional(),
|
|
2074
|
+
depends_on: z.array(z.string()).optional()
|
|
2075
|
+
}).strip();
|
|
2076
|
+
var CrossContextEdgeSchema = z.object({
|
|
2077
|
+
consumer: z.string(),
|
|
2078
|
+
provider: z.string(),
|
|
2079
|
+
transport: z.enum(["event-bus", "network"]),
|
|
2080
|
+
events: z.array(z.string()).optional(),
|
|
2081
|
+
operations: z.array(z.string()).optional(),
|
|
2082
|
+
integrationPattern: z.enum(["open-host", "acl"]).optional()
|
|
2083
|
+
});
|
|
2084
|
+
var GeneratorBlockSchema = z.object({ name: z.string().min(1).optional() }).passthrough();
|
|
2085
|
+
var IndexManifestSchema = z.object({
|
|
2086
|
+
// Toolchain-compatibility stamp (see manifest-schema-version.ts). Note
|
|
2087
|
+
// `version` below is a DIFFERENT field — its `"2.0"` string is the
|
|
2088
|
+
// index-form discriminator (`isIndexManifest`), not a compatibility gate.
|
|
2089
|
+
schemaVersion: z.number().int().positive().optional(),
|
|
2090
|
+
version: z.string().optional(),
|
|
2091
|
+
description: z.string(),
|
|
2092
|
+
system: z.string().optional(),
|
|
2093
|
+
scope: z.string().optional(),
|
|
2094
|
+
architecture: z.string().optional(),
|
|
2095
|
+
planes: z.record(z.array(z.string())).optional(),
|
|
2096
|
+
bounded_contexts: z.array(z.object({
|
|
2097
|
+
name: z.string(),
|
|
2098
|
+
type: BoundedContextTypeSchema.optional(),
|
|
2099
|
+
plane: PlaneTypeSchema.optional(),
|
|
2100
|
+
status: StatusTypeSchema.optional(),
|
|
2101
|
+
file: z.string(),
|
|
2102
|
+
frozen_since: z.string().optional()
|
|
2103
|
+
})).optional(),
|
|
2104
|
+
apps: z.array(z.object({
|
|
2105
|
+
name: z.string(),
|
|
2106
|
+
file: z.string().optional()
|
|
2107
|
+
})).optional(),
|
|
2108
|
+
invariants: z.record(z.string()).optional(),
|
|
2109
|
+
governance: z.record(z.string()).optional(),
|
|
2110
|
+
agent_instructions: z.record(z.unknown()).optional(),
|
|
2111
|
+
relationship_patterns: z.record(z.object({
|
|
2112
|
+
description: z.string(),
|
|
2113
|
+
acl_required: z.union([z.boolean(), z.literal("optional")]).optional(),
|
|
2114
|
+
linter: z.string().optional()
|
|
2115
|
+
})).optional(),
|
|
2116
|
+
mvk: z.record(z.unknown()).optional(),
|
|
2117
|
+
cross_context: z.array(CrossContextEdgeSchema).optional(),
|
|
2118
|
+
workspace_config: z.string().optional(),
|
|
2119
|
+
legacy_config: z.string().optional()
|
|
2120
|
+
}).strict().refine((data) => {
|
|
2121
|
+
const contexts = data.bounded_contexts ?? [];
|
|
2122
|
+
return contexts.every((ctx) => {
|
|
2123
|
+
if (ctx.plane && ctx.file) {
|
|
2124
|
+
return ctx.file.startsWith(`contexts/${ctx.plane}/`);
|
|
2125
|
+
}
|
|
2126
|
+
return true;
|
|
2127
|
+
});
|
|
2128
|
+
}, {
|
|
2129
|
+
message: "Context plane does not match file path subdirectory",
|
|
2130
|
+
path: ["bounded_contexts"]
|
|
2131
|
+
});
|
|
2132
|
+
var ManifestSchema = z.object({
|
|
2133
|
+
// Toolchain-compatibility stamp (positive int; absent = legacy). NOT the
|
|
2134
|
+
// freeform `version` string below. Compatibility is asserted against the
|
|
2135
|
+
// RAW yaml BEFORE this `.strict()` parse (assertSupportedSchemaVersion in
|
|
2136
|
+
// manifest-schema-version.ts) — this entry only keeps strict mode from
|
|
2137
|
+
// rejecting stamped manifests as carrying an unknown key.
|
|
2138
|
+
schemaVersion: z.number().int().positive().optional(),
|
|
2139
|
+
version: z.string().optional(),
|
|
2140
|
+
description: z.string().optional(),
|
|
2141
|
+
system: z.string().optional(),
|
|
2142
|
+
scope: z.string().optional(),
|
|
2143
|
+
// Structured workspace metadata (the canonical `workspace:` block, also the
|
|
2144
|
+
// first block in the few-shot examples). `system`/`scope` above are derived
|
|
2145
|
+
// from `workspace.name`; `workspace.description` is the only carrier of the
|
|
2146
|
+
// human-readable intent. Emitted by `draftToManifest` so the generated
|
|
2147
|
+
// manifest survives `parseManifestToWizardData`'s strict parse on the
|
|
2148
|
+
// "Use this manifest" path. Optional — legacy/hand-written manifests omit it.
|
|
2149
|
+
workspace: z.object({
|
|
2150
|
+
name: z.string(),
|
|
2151
|
+
description: z.string()
|
|
2152
|
+
}).optional(),
|
|
2153
|
+
architecture: z.string().optional(),
|
|
2154
|
+
// The wizard records the chosen workspace template (e.g. "strict-enterprise")
|
|
2155
|
+
// alongside `architecture`; persisted into .architecture/manifest.yaml.
|
|
2156
|
+
workspaceTemplate: z.string().optional(),
|
|
2157
|
+
planes: z.record(z.array(z.string())).optional(),
|
|
2158
|
+
monorepo: z.record(z.unknown()).optional(),
|
|
2159
|
+
generator: GeneratorBlockSchema.optional(),
|
|
2160
|
+
mvk: z.record(z.unknown()).optional(),
|
|
2161
|
+
invariants: z.record(z.string()).optional(),
|
|
2162
|
+
governance: z.record(z.string()).optional(),
|
|
2163
|
+
agent_instructions: z.record(z.unknown()).optional(),
|
|
2164
|
+
relationship_patterns: z.record(z.object({
|
|
2165
|
+
description: z.string(),
|
|
2166
|
+
acl_required: z.union([z.boolean(), z.literal("optional")]).optional(),
|
|
2167
|
+
linter: z.string().optional()
|
|
2168
|
+
})).optional(),
|
|
2169
|
+
bounded_contexts: z.array(BoundedContextSchema),
|
|
2170
|
+
apps: z.array(AppSchema).optional(),
|
|
2171
|
+
cross_context: z.array(CrossContextEdgeSchema).optional(),
|
|
2172
|
+
context_mappings: z.array(z.object({
|
|
2173
|
+
upstream: z.string(),
|
|
2174
|
+
downstream: z.string(),
|
|
2175
|
+
pattern: z.string().optional(),
|
|
2176
|
+
mechanism: z.string().optional(),
|
|
2177
|
+
notes: z.string().optional(),
|
|
2178
|
+
events: z.array(z.string()).optional()
|
|
2179
|
+
})).optional(),
|
|
2180
|
+
workspaceDefaults: z.record(z.unknown()).optional(),
|
|
2181
|
+
// Both side-car pointers. `mergeSplitManifest` resolves `workspace_config`
|
|
2182
|
+
// into the `monorepo`/`generator` blocks above and then carries the pointer
|
|
2183
|
+
// through with every other index key, so the merged (flat) form has to
|
|
2184
|
+
// accept it — this schema is `.strict()`, and the merge output is re-parsed
|
|
2185
|
+
// against it (sync's `validateManifest`, `parseManifestToWizardData`).
|
|
2186
|
+
workspace_config: z.string().optional(),
|
|
2187
|
+
legacy_config: z.string().optional()
|
|
2188
|
+
}).strict();
|
|
2189
|
+
|
|
2190
|
+
// ../project-configuration/dist/domain/model/manifest-schema/manifest-schema-version.js
|
|
2191
|
+
var CURRENT_MANIFEST_SCHEMA_VERSION = 1;
|
|
2192
|
+
function readManifestSchemaVersion(parsed) {
|
|
2193
|
+
if (parsed === null || typeof parsed !== "object")
|
|
2194
|
+
return void 0;
|
|
2195
|
+
const raw = parsed.schemaVersion;
|
|
2196
|
+
if (raw === void 0)
|
|
2197
|
+
return void 0;
|
|
2198
|
+
if (typeof raw !== "number" || !Number.isInteger(raw) || raw < 1) {
|
|
2199
|
+
throw new Error(`Invalid manifest schemaVersion: expected a positive integer, got ${JSON.stringify(raw)}.`);
|
|
2200
|
+
}
|
|
2201
|
+
return raw;
|
|
2202
|
+
}
|
|
2203
|
+
function assertSupportedSchemaVersion(parsed) {
|
|
2204
|
+
const version = readManifestSchemaVersion(parsed);
|
|
2205
|
+
if (version === void 0)
|
|
2206
|
+
return;
|
|
2207
|
+
if (version > CURRENT_MANIFEST_SCHEMA_VERSION) {
|
|
2208
|
+
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.)`);
|
|
2209
|
+
}
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2212
|
+
// ../project-configuration/dist/domain/model/manifest-schema/generator-identity.js
|
|
2213
|
+
var HEXAGEN_GENERATOR_NAME = "@hexagen-monaco/sync";
|
|
2214
|
+
|
|
2215
|
+
// ../project-configuration/dist/domain/model/manifest-schema/is-index-manifest.js
|
|
2216
|
+
function isIndexManifest(parsed) {
|
|
2217
|
+
if (typeof parsed !== "object" || parsed === null) {
|
|
2218
|
+
return false;
|
|
2219
|
+
}
|
|
2220
|
+
const record = parsed;
|
|
2221
|
+
if (record.version !== "2.0") {
|
|
2222
|
+
return false;
|
|
2223
|
+
}
|
|
2224
|
+
const contexts = record.bounded_contexts;
|
|
2225
|
+
if (!Array.isArray(contexts)) {
|
|
2226
|
+
return false;
|
|
2227
|
+
}
|
|
2228
|
+
return contexts.some((entry) => typeof entry === "object" && entry !== null && typeof entry.file === "string");
|
|
2229
|
+
}
|
|
2230
|
+
var WorkspaceGovernanceSchema = z.object({
|
|
2231
|
+
workspaceName: z.string().min(1, "Workspace name is required"),
|
|
2232
|
+
workspaceTemplate: z.enum(["modular-monolith", "strict-enterprise", "micro-frontend"]).default("modular-monolith"),
|
|
2233
|
+
workspaceDescription: z.string().optional(),
|
|
2234
|
+
packageManager: z.enum(["yarn", "pnpm", "bun"]).default("yarn"),
|
|
2235
|
+
topologyStrictness: z.enum(["strict", "flexible"]).default("flexible"),
|
|
2236
|
+
namespacePrefix: z.string().default("@hexagen"),
|
|
2237
|
+
namingConventions: z.object({
|
|
2238
|
+
contextDirectoryPattern: z.string().default("packages/"),
|
|
2239
|
+
adapterSuffix: z.string().default(".adapter.ts")
|
|
2240
|
+
}).default({
|
|
2241
|
+
contextDirectoryPattern: "packages/",
|
|
2242
|
+
adapterSuffix: ".adapter.ts"
|
|
2243
|
+
})
|
|
2244
|
+
});
|
|
2245
|
+
var PortConfigurationSchema = z.object({
|
|
2246
|
+
inboundPorts: z.array(z.enum([
|
|
2247
|
+
"rest-controller",
|
|
2248
|
+
"graphql-resolver",
|
|
2249
|
+
"event-listener",
|
|
2250
|
+
"cli-command"
|
|
2251
|
+
])).default([]),
|
|
2252
|
+
outboundPorts: z.array(z.enum([
|
|
2253
|
+
"relational-db",
|
|
2254
|
+
"document-db",
|
|
2255
|
+
"external-service-client",
|
|
2256
|
+
"message-publisher"
|
|
2257
|
+
])).default([])
|
|
2258
|
+
});
|
|
2259
|
+
var PeerContextMappingSchema = z.object({
|
|
2260
|
+
consumerContext: z.string(),
|
|
2261
|
+
providerContext: z.string(),
|
|
2262
|
+
integrationPattern: z.enum(["open-host", "acl"]),
|
|
2263
|
+
communicationBoundary: z.enum(["in-process", "networked"])
|
|
2264
|
+
});
|
|
2265
|
+
var BoundedContextSchema2 = z.object({
|
|
2266
|
+
id: z.string(),
|
|
2267
|
+
name: z.string().min(1, "Please enter a name for this bounded context (e.g., 'UserService', 'OrderProcessing')"),
|
|
2268
|
+
description: z.string().optional(),
|
|
2269
|
+
// ADR-0041: `infrastructureTarget` (API backend) and `uiFramework` (below)
|
|
2270
|
+
// are PROJECT-LEVEL choices managed by the wizard's Applications step, which
|
|
2271
|
+
// fans a single selection out to every context. They persist per-context (the
|
|
2272
|
+
// source of truth `deriveApps` reads), but are NOT direct per-context input —
|
|
2273
|
+
// do not re-add per-context UI/API editing without revisiting ADR-0041.
|
|
2274
|
+
// `"none"` = the project opts out of a separate API backend (UI-only, e.g. a
|
|
2275
|
+
// Next.js app with built-in routes); `deriveApps` then emits no `api` app.
|
|
2276
|
+
// Distinct from `undefined` (legacy/unset → defaults to the preset).
|
|
2277
|
+
infrastructureTarget: z.enum(["nestjs", "express", "serverless", "plain-ts", "nitro", "none"]).optional(),
|
|
2278
|
+
coreDomainEntities: z.array(z.string()).default([]),
|
|
2279
|
+
valueObjects: z.array(z.string()).default([]),
|
|
2280
|
+
domainEvents: z.array(z.string()).default([]),
|
|
2281
|
+
portConfiguration: PortConfigurationSchema,
|
|
2282
|
+
// Backward compatibility: support legacy fields
|
|
2283
|
+
apiFramework: z.enum(["Fastify", "Express", "NestJS"]).optional(),
|
|
2284
|
+
uiFramework: z.enum(["", "Next.js", "React Router", "Remix", "Angular", "Vue.js"]).optional().default(""),
|
|
2285
|
+
persistenceAdapter: z.enum(["", "Prisma", "TypeORM", "Mongoose", "Drizzle"]).optional().default(""),
|
|
2286
|
+
messagingAdapter: z.enum(["", "BullMQ", "Temporal", "RabbitMQ"]).optional().default(""),
|
|
2287
|
+
telemetryProvider: z.enum(["", "OpenTelemetry", "None", "Prometheus", "Winston"]).optional().default(""),
|
|
2288
|
+
externalApiPorts: z.array(z.string()).optional(),
|
|
2289
|
+
llmProviders: z.array(z.string()).optional(),
|
|
2290
|
+
blockchainNetworks: z.array(z.string()).optional(),
|
|
2291
|
+
authenticationProvider: z.string().optional(),
|
|
2292
|
+
emailService: z.string().optional(),
|
|
2293
|
+
paymentGateway: z.string().optional(),
|
|
2294
|
+
storageProvider: z.string().optional(),
|
|
2295
|
+
searchService: z.string().optional(),
|
|
2296
|
+
webhookEndpoints: z.array(z.string()).optional(),
|
|
2297
|
+
entities: z.array(z.string()).optional(),
|
|
2298
|
+
useCases: z.array(z.string()).optional()
|
|
2299
|
+
});
|
|
2300
|
+
var ExternalContextSchema = z.object({
|
|
2301
|
+
id: z.string(),
|
|
2302
|
+
name: z.string().min(1, "Peer context name is required"),
|
|
2303
|
+
relationshipType: z.enum(["U", "D", "ACL", "SK", "P", "OHS"]),
|
|
2304
|
+
isEventDriven: z.boolean().optional(),
|
|
2305
|
+
entityNames: z.array(z.string()).optional(),
|
|
2306
|
+
useCaseNames: z.array(z.string()).optional()
|
|
2307
|
+
});
|
|
2308
|
+
z.object({
|
|
2309
|
+
boundedContexts: z.array(BoundedContextSchema2).default([]),
|
|
2310
|
+
externalContexts: z.array(ExternalContextSchema).default([]),
|
|
2311
|
+
governance: WorkspaceGovernanceSchema.default({
|
|
2312
|
+
workspaceName: "@hexagen",
|
|
2313
|
+
workspaceTemplate: "modular-monolith",
|
|
2314
|
+
packageManager: "yarn",
|
|
2315
|
+
topologyStrictness: "flexible",
|
|
2316
|
+
namespacePrefix: "@hexagen",
|
|
2317
|
+
namingConventions: {
|
|
2318
|
+
contextDirectoryPattern: "packages/",
|
|
2319
|
+
adapterSuffix: ".adapter.ts"
|
|
2320
|
+
}
|
|
2321
|
+
}),
|
|
2322
|
+
peerMappings: z.array(PeerContextMappingSchema).default([]),
|
|
2323
|
+
/**
|
|
2324
|
+
* Per-template install-time answers collected by the wizard. Keyed by
|
|
2325
|
+
* template id; each value is a record of question-id → answer. The CLI
|
|
2326
|
+
* use case consumes this via its `overrideAnswers` parameter, so the
|
|
2327
|
+
* wizard can feed answers gathered in the UI directly into a non-
|
|
2328
|
+
* interactive install. Defaults to an empty object for projects that
|
|
2329
|
+
* are scaffolded without the per-template questions step.
|
|
2330
|
+
*/
|
|
2331
|
+
addOnsAnswers: z.record(z.string(), z.record(z.string(), z.union([z.string(), z.boolean(), z.array(z.string())]))).default({}),
|
|
2332
|
+
/**
|
|
2333
|
+
* Provenance of the project's `manifestYaml` (import round-trip integrity,
|
|
2334
|
+
* Item 1). `"imported"` = the manifest is the source of truth (accepted via
|
|
2335
|
+
* `parseManifestToWizardData` — file import or AI generation) and the wizard
|
|
2336
|
+
* projection (`wizardToManifest`) is LOSSY for it, so autosave/export paths
|
|
2337
|
+
* must never overwrite or impersonate the stored manifest. Deliberately
|
|
2338
|
+
* `.optional()` rather than `.default("wizard")`: absent ≡ `"wizard"`
|
|
2339
|
+
* everywhere (guards key on `=== "imported"` only), which keeps every
|
|
2340
|
+
* wizard-authored formState byte-identical to before this field existed and
|
|
2341
|
+
* lets the load perimeter distinguish "legacy record, provenance unknown"
|
|
2342
|
+
* (absent) from an explicit value when running its one-time discriminator.
|
|
2343
|
+
*/
|
|
2344
|
+
manifestSource: z.enum(["wizard", "imported"]).optional()
|
|
2345
|
+
});
|
|
2346
|
+
var MonorepoConfigSchema = z.object({
|
|
2347
|
+
packageManager: z.string().optional(),
|
|
2348
|
+
workspaces: z.array(z.string()).optional(),
|
|
2349
|
+
rootFiles: z.record(z.unknown()).optional(),
|
|
2350
|
+
archInvariants: z.record(z.unknown()).optional()
|
|
2351
|
+
}).passthrough();
|
|
2352
|
+
var GeneratorSyncSchema = z.object({
|
|
2353
|
+
layers: z.record(z.unknown()).optional(),
|
|
2354
|
+
packageJson: z.record(z.unknown()).optional(),
|
|
2355
|
+
stubs: z.record(z.unknown()).optional(),
|
|
2356
|
+
apps: z.record(z.unknown()).optional()
|
|
2357
|
+
}).passthrough();
|
|
2358
|
+
var GeneratorConfigSchema = z.object({
|
|
2359
|
+
name: z.string().min(1).optional(),
|
|
2360
|
+
version: z.string().optional(),
|
|
2361
|
+
sync: GeneratorSyncSchema.optional()
|
|
2362
|
+
}).passthrough();
|
|
2363
|
+
var WorkspaceConfigSchema = z.object({
|
|
2364
|
+
monorepo: MonorepoConfigSchema.optional(),
|
|
2365
|
+
generator: GeneratorConfigSchema.optional(),
|
|
2366
|
+
workspaceDefaults: z.record(z.unknown()).optional(),
|
|
2367
|
+
tsConfigRoot: z.record(z.unknown()).optional(),
|
|
2368
|
+
eslint: z.record(z.unknown()).optional(),
|
|
2369
|
+
rootFiles: z.record(z.unknown()).optional(),
|
|
2370
|
+
generatorConfig: z.record(z.unknown()).optional(),
|
|
2371
|
+
turboConfig: z.record(z.unknown()).optional()
|
|
2372
|
+
}).passthrough();
|
|
1987
2373
|
|
|
1988
2374
|
// src/generators/architecture-file-templates.ts
|
|
1989
2375
|
var LAYER_RULES_COMMON = `shared_kernel:
|
|
@@ -2255,6 +2641,15 @@ function interpolateWithLogging(label, template, vars, config) {
|
|
|
2255
2641
|
}
|
|
2256
2642
|
return output;
|
|
2257
2643
|
}
|
|
2644
|
+
function withGeneratorIdentity(manifest) {
|
|
2645
|
+
return {
|
|
2646
|
+
...manifest,
|
|
2647
|
+
generator: {
|
|
2648
|
+
...manifest.generator,
|
|
2649
|
+
name: manifest.generator?.name ?? HEXAGEN_GENERATOR_NAME
|
|
2650
|
+
}
|
|
2651
|
+
};
|
|
2652
|
+
}
|
|
2258
2653
|
async function writeManifestIfFreshExternal(config, result, report) {
|
|
2259
2654
|
if (config.mode !== "external") {
|
|
2260
2655
|
return;
|
|
@@ -2287,7 +2682,7 @@ async function writeManifestIfFreshExternal(config, result, report) {
|
|
|
2287
2682
|
result.totalOps += 1;
|
|
2288
2683
|
return;
|
|
2289
2684
|
}
|
|
2290
|
-
const content = yaml3.dump(config.manifest);
|
|
2685
|
+
const content = yaml3.dump(withGeneratorIdentity(config.manifest));
|
|
2291
2686
|
config.journal?.recordWrite(manifestPath, null);
|
|
2292
2687
|
await fs5.mkdir(archDir, { recursive: true });
|
|
2293
2688
|
await fs5.writeFile(manifestPath, content, { encoding: "utf8" });
|
|
@@ -4688,542 +5083,161 @@ async function generateCrossContext(config, report) {
|
|
|
4688
5083
|
methods: operationMethods(ops),
|
|
4689
5084
|
importedTypes: operationImports(ops),
|
|
4690
5085
|
doc: "Serves this context's operations over the network boundary." + (ohsProviders.has(provider) ? OHS_NOTE : "")
|
|
4691
|
-
});
|
|
4692
|
-
}
|
|
4693
|
-
for (const consumer of [...clientOps.keys()].sort()) {
|
|
4694
|
-
const ops = [...clientOps.get(consumer) ?? []].sort();
|
|
4695
|
-
await emitPortAndAdapter(result, config, report, scope, {
|
|
4696
|
-
contextName: consumer,
|
|
4697
|
-
portKind: "out",
|
|
4698
|
-
portBase: "external-service-client",
|
|
4699
|
-
interfaceName: "ExternalServiceClientPort",
|
|
4700
|
-
methods: operationMethods(ops),
|
|
4701
|
-
importedTypes: operationImports(ops),
|
|
4702
|
-
doc: "Calls operations on the contexts this context depends on over the network." + (aclConsumers.has(consumer) ? ACL_NOTE : "")
|
|
4703
|
-
});
|
|
4704
|
-
}
|
|
4705
|
-
return result;
|
|
4706
|
-
}
|
|
4707
|
-
var RESULT_KERNEL = `// @generated by @hexagen/sync — shared Result kernel (edit freely)
|
|
4708
|
-
/**
|
|
4709
|
-
* Result is the explicit success/failure type generated use-cases return.
|
|
4710
|
-
* Mirrors @hexagen/shared's Result. Created once, then preserved on re-sync.
|
|
4711
|
-
*/
|
|
4712
|
-
export type Result<T, E = unknown> =
|
|
4713
|
-
| { success: true; value: T }
|
|
4714
|
-
| { success: false; error: E };
|
|
4715
|
-
|
|
4716
|
-
export const ok = <T>(value: T): Result<T, never> => ({ success: true, value });
|
|
4717
|
-
export const err = <E>(error: E): Result<never, E> => ({
|
|
4718
|
-
success: false,
|
|
4719
|
-
error,
|
|
4720
|
-
});
|
|
4721
|
-
`;
|
|
4722
|
-
async function generateSharedKernel(config, report) {
|
|
4723
|
-
const result = createEmptyResult();
|
|
4724
|
-
if (config.mode !== "external") return result;
|
|
4725
|
-
const hasShared = (config.manifest.bounded_contexts ?? []).some(
|
|
4726
|
-
(bc) => bc.name?.toLowerCase() === "shared"
|
|
4727
|
-
);
|
|
4728
|
-
if (!hasShared) return result;
|
|
4729
|
-
const kernelPath = path7.join(
|
|
4730
|
-
config.workspaceRoot,
|
|
4731
|
-
"packages",
|
|
4732
|
-
"shared",
|
|
4733
|
-
"src",
|
|
4734
|
-
"domain",
|
|
4735
|
-
"result.ts"
|
|
4736
|
-
);
|
|
4737
|
-
if (!isInScope(kernelPath, config)) {
|
|
4738
|
-
result.skipped.push(kernelPath);
|
|
4739
|
-
return result;
|
|
4740
|
-
}
|
|
4741
|
-
try {
|
|
4742
|
-
await fs5.stat(kernelPath);
|
|
4743
|
-
result.skipped.push(kernelPath);
|
|
4744
|
-
return result;
|
|
4745
|
-
} catch (err3) {
|
|
4746
|
-
if (err3.code !== "ENOENT") throw err3;
|
|
4747
|
-
}
|
|
4748
|
-
if (!config.dryRun) {
|
|
4749
|
-
await fs5.mkdir(path7.dirname(kernelPath), { recursive: true });
|
|
4750
|
-
}
|
|
4751
|
-
const status = await safeWriteFileAtomic(
|
|
4752
|
-
kernelPath,
|
|
4753
|
-
RESULT_KERNEL,
|
|
4754
|
-
config,
|
|
4755
|
-
report,
|
|
4756
|
-
false
|
|
4757
|
-
);
|
|
4758
|
-
recordWriteStatus(result, kernelPath, status);
|
|
4759
|
-
return result;
|
|
4760
|
-
}
|
|
4761
|
-
var execAsync = promisify(exec);
|
|
4762
|
-
var MAX_BUFFER = 1024 * 1024 * 10;
|
|
4763
|
-
async function ensureDependenciesBuilt(config) {
|
|
4764
|
-
const { logger, dryRun } = config;
|
|
4765
|
-
if (dryRun) {
|
|
4766
|
-
logger.info("Pre‑flight: skipping build in dry-run mode");
|
|
4767
|
-
return;
|
|
4768
|
-
}
|
|
4769
|
-
logger.info("Pre‑flight: ensuring package dependencies are up‑to‑date...");
|
|
4770
|
-
try {
|
|
4771
|
-
const { stdout, stderr } = await execAsync("npx turbo run build", {
|
|
4772
|
-
cwd: config.workspaceRoot,
|
|
4773
|
-
maxBuffer: MAX_BUFFER
|
|
4774
|
-
});
|
|
4775
|
-
if (stdout) logger.debug(stdout);
|
|
4776
|
-
if (stderr) logger.warn(stderr);
|
|
4777
|
-
logger.info("Pre‑flight build completed.");
|
|
4778
|
-
} catch (err3) {
|
|
4779
|
-
const e = err3;
|
|
4780
|
-
const errorDetails = e.stderr || e.stdout || e.message || String(err3);
|
|
4781
|
-
logger.error(`Pre-flight build failed. Aborting sync.`);
|
|
4782
|
-
logger.error(`Build error: ${errorDetails}`);
|
|
4783
|
-
throw new Error("Preflight build failed — sync aborted");
|
|
4784
|
-
}
|
|
4785
|
-
}
|
|
4786
|
-
|
|
4787
|
-
// src/sync-engine-helpers.ts
|
|
4788
|
-
function mergeResult2(dest, src) {
|
|
4789
|
-
dest.created.push(...src.created);
|
|
4790
|
-
dest.updated.push(...src.updated);
|
|
4791
|
-
dest.skipped.push(...src.skipped);
|
|
4792
|
-
dest.deleted.push(...src.deleted);
|
|
4793
|
-
dest.unchanged.push(...src.unchanged);
|
|
4794
|
-
dest.totalOps += src.totalOps;
|
|
4795
|
-
if (src.error && !dest.error) {
|
|
4796
|
-
dest.error = src.error;
|
|
4797
|
-
dest.summary = src.summary;
|
|
4798
|
-
}
|
|
4799
|
-
}
|
|
4800
|
-
function mergeBarrelPasses(firstPass, secondPass) {
|
|
4801
|
-
const combined = createEmptyResult();
|
|
4802
|
-
const secondPaths = /* @__PURE__ */ new Set([
|
|
4803
|
-
...secondPass.created,
|
|
4804
|
-
...secondPass.updated,
|
|
4805
|
-
...secondPass.skipped,
|
|
4806
|
-
...secondPass.deleted
|
|
4807
|
-
]);
|
|
4808
|
-
const secondAll = /* @__PURE__ */ new Set([...secondPaths, ...secondPass.unchanged]);
|
|
4809
|
-
const firstMutations = /* @__PURE__ */ new Set([
|
|
4810
|
-
...firstPass.created,
|
|
4811
|
-
...firstPass.updated,
|
|
4812
|
-
...firstPass.deleted
|
|
4813
|
-
]);
|
|
4814
|
-
for (const p of firstPass.created) {
|
|
4815
|
-
if (!secondPaths.has(p)) combined.created.push(p);
|
|
4816
|
-
}
|
|
4817
|
-
for (const p of firstPass.updated) {
|
|
4818
|
-
if (!secondPaths.has(p)) combined.updated.push(p);
|
|
4819
|
-
}
|
|
4820
|
-
for (const p of firstPass.skipped) {
|
|
4821
|
-
if (!secondAll.has(p)) combined.skipped.push(p);
|
|
4822
|
-
}
|
|
4823
|
-
for (const p of firstPass.deleted) {
|
|
4824
|
-
if (!secondPaths.has(p)) combined.deleted.push(p);
|
|
4825
|
-
}
|
|
4826
|
-
for (const p of firstPass.unchanged) {
|
|
4827
|
-
if (!secondAll.has(p)) combined.unchanged.push(p);
|
|
4828
|
-
}
|
|
4829
|
-
combined.created.push(...secondPass.created);
|
|
4830
|
-
combined.updated.push(...secondPass.updated);
|
|
4831
|
-
combined.skipped.push(...secondPass.skipped);
|
|
4832
|
-
combined.deleted.push(...secondPass.deleted);
|
|
4833
|
-
for (const p of secondPass.unchanged) {
|
|
4834
|
-
if (!firstMutations.has(p)) combined.unchanged.push(p);
|
|
4835
|
-
}
|
|
4836
|
-
combined.totalOps = combined.created.length + combined.updated.length + combined.deleted.length;
|
|
4837
|
-
if (firstPass.error) {
|
|
4838
|
-
combined.error = firstPass.error;
|
|
4839
|
-
combined.summary = firstPass.summary;
|
|
4840
|
-
} else if (secondPass.error) {
|
|
4841
|
-
combined.error = secondPass.error;
|
|
4842
|
-
combined.summary = secondPass.summary;
|
|
5086
|
+
});
|
|
4843
5087
|
}
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
|
|
5088
|
+
for (const consumer of [...clientOps.keys()].sort()) {
|
|
5089
|
+
const ops = [...clientOps.get(consumer) ?? []].sort();
|
|
5090
|
+
await emitPortAndAdapter(result, config, report, scope, {
|
|
5091
|
+
contextName: consumer,
|
|
5092
|
+
portKind: "out",
|
|
5093
|
+
portBase: "external-service-client",
|
|
5094
|
+
interfaceName: "ExternalServiceClientPort",
|
|
5095
|
+
methods: operationMethods(ops),
|
|
5096
|
+
importedTypes: operationImports(ops),
|
|
5097
|
+
doc: "Calls operations on the contexts this context depends on over the network." + (aclConsumers.has(consumer) ? ACL_NOTE : "")
|
|
5098
|
+
});
|
|
5099
|
+
}
|
|
5100
|
+
return result;
|
|
4848
5101
|
}
|
|
4849
|
-
var
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
|
|
4857
|
-
];
|
|
4858
|
-
var PlaneTypeSchema = caseInsensitiveEnum(z.enum(PLANE_NAMES));
|
|
4859
|
-
var StatusTypeSchema = caseInsensitiveEnum(z.enum(["active", "frozen", "deprecated", "experimental"]));
|
|
4860
|
-
var RelationshipPatternSchema = caseInsensitiveEnum(z.enum(["U/D", "ACL", "SK", "P", "OHS"]), "upper");
|
|
4861
|
-
var RelationshipRoleSchema = caseInsensitiveEnum(z.enum(["upstream", "downstream", "peer"]));
|
|
4862
|
-
var RelationshipSchema = z.object({
|
|
4863
|
-
context: z.string(),
|
|
4864
|
-
pattern: RelationshipPatternSchema,
|
|
4865
|
-
role: RelationshipRoleSchema.optional(),
|
|
4866
|
-
acl: z.object({
|
|
4867
|
-
adapter: z.string(),
|
|
4868
|
-
location: z.string().optional(),
|
|
4869
|
-
notes: z.string().optional()
|
|
4870
|
-
}).optional(),
|
|
4871
|
-
notes: z.string().optional()
|
|
4872
|
-
});
|
|
4873
|
-
var PortDefinitionSchema = z.object({
|
|
4874
|
-
name: z.string(),
|
|
4875
|
-
owner: z.string().optional()
|
|
4876
|
-
});
|
|
4877
|
-
var LegacyOrNewPortSchema = z.union([
|
|
4878
|
-
z.string(),
|
|
4879
|
-
PortDefinitionSchema
|
|
4880
|
-
]);
|
|
4881
|
-
caseInsensitiveEnum(z.enum(["domain", "application", "infrastructure"]));
|
|
4882
|
-
var UiLayerSchema = z.object({
|
|
4883
|
-
components: z.array(z.string()).optional()
|
|
4884
|
-
}).passthrough();
|
|
4885
|
-
var BoundedContextSchema = z.object({
|
|
4886
|
-
name: z.string(),
|
|
4887
|
-
type: BoundedContextTypeSchema.optional(),
|
|
4888
|
-
plane: PlaneTypeSchema.optional(),
|
|
4889
|
-
status: StatusTypeSchema.optional(),
|
|
4890
|
-
description: z.string().optional(),
|
|
4891
|
-
relationships: z.array(RelationshipSchema).optional(),
|
|
4892
|
-
// PASSTHROUGH, not strict, at every level of this subtree — a deliberate
|
|
4893
|
-
// choice, see the note on the schema below. Zod's default `z.object` STRIPS
|
|
4894
|
-
// undeclared keys, which is how `layers.ui` disappeared between the file on
|
|
4895
|
-
// disk and every consumer of the merged manifest.
|
|
4896
|
-
layers: z.object({
|
|
4897
|
-
domain: z.object({
|
|
4898
|
-
entities: z.array(z.string()).optional(),
|
|
4899
|
-
value_objects: z.array(z.string()).optional()
|
|
4900
|
-
}).passthrough().optional(),
|
|
4901
|
-
application: z.object({
|
|
4902
|
-
use_cases: z.array(z.string()).optional(),
|
|
4903
|
-
ports: z.object({
|
|
4904
|
-
in: z.array(LegacyOrNewPortSchema).optional(),
|
|
4905
|
-
out: z.array(LegacyOrNewPortSchema).optional()
|
|
4906
|
-
}).passthrough().optional()
|
|
4907
|
-
}).passthrough().optional(),
|
|
4908
|
-
infrastructure: z.object({
|
|
4909
|
-
adapters: z.array(z.string()).optional()
|
|
4910
|
-
}).passthrough().optional(),
|
|
4911
|
-
ui: UiLayerSchema.optional()
|
|
4912
|
-
}).passthrough().optional(),
|
|
4913
|
-
depends_on: z.array(z.string()).optional(),
|
|
4914
|
-
wiring: z.array(z.string()).optional(),
|
|
4915
|
-
generator: z.record(z.unknown()).optional()
|
|
4916
|
-
}).passthrough();
|
|
4917
|
-
var AppSchema = z.object({
|
|
4918
|
-
name: z.string(),
|
|
4919
|
-
framework: z.string().optional(),
|
|
4920
|
-
version: z.string().optional(),
|
|
4921
|
-
driver: z.string().optional(),
|
|
4922
|
-
description: z.string().optional(),
|
|
4923
|
-
role: z.string().optional(),
|
|
4924
|
-
router: z.string().optional(),
|
|
4925
|
-
deployment: z.string().optional(),
|
|
4926
|
-
auth: z.string().optional(),
|
|
4927
|
-
schedule: z.string().optional(),
|
|
4928
|
-
ui: z.object({
|
|
4929
|
-
library: z.string().optional(),
|
|
4930
|
-
styling: z.string().optional()
|
|
4931
|
-
}).optional(),
|
|
4932
|
-
responsibilities: z.array(z.string()).optional(),
|
|
4933
|
-
depends_on: z.array(z.string()).optional()
|
|
4934
|
-
}).strip();
|
|
4935
|
-
var CrossContextEdgeSchema = z.object({
|
|
4936
|
-
consumer: z.string(),
|
|
4937
|
-
provider: z.string(),
|
|
4938
|
-
transport: z.enum(["event-bus", "network"]),
|
|
4939
|
-
events: z.array(z.string()).optional(),
|
|
4940
|
-
operations: z.array(z.string()).optional(),
|
|
4941
|
-
integrationPattern: z.enum(["open-host", "acl"]).optional()
|
|
4942
|
-
});
|
|
4943
|
-
var IndexManifestSchema = z.object({
|
|
4944
|
-
// Toolchain-compatibility stamp (see manifest-schema-version.ts). Note
|
|
4945
|
-
// `version` below is a DIFFERENT field — its `"2.0"` string is the
|
|
4946
|
-
// index-form discriminator (`isIndexManifest`), not a compatibility gate.
|
|
4947
|
-
schemaVersion: z.number().int().positive().optional(),
|
|
4948
|
-
version: z.string().optional(),
|
|
4949
|
-
description: z.string(),
|
|
4950
|
-
system: z.string().optional(),
|
|
4951
|
-
scope: z.string().optional(),
|
|
4952
|
-
architecture: z.string().optional(),
|
|
4953
|
-
planes: z.record(z.array(z.string())).optional(),
|
|
4954
|
-
bounded_contexts: z.array(z.object({
|
|
4955
|
-
name: z.string(),
|
|
4956
|
-
type: BoundedContextTypeSchema.optional(),
|
|
4957
|
-
plane: PlaneTypeSchema.optional(),
|
|
4958
|
-
status: StatusTypeSchema.optional(),
|
|
4959
|
-
file: z.string(),
|
|
4960
|
-
frozen_since: z.string().optional()
|
|
4961
|
-
})).optional(),
|
|
4962
|
-
apps: z.array(z.object({
|
|
4963
|
-
name: z.string(),
|
|
4964
|
-
file: z.string().optional()
|
|
4965
|
-
})).optional(),
|
|
4966
|
-
invariants: z.record(z.string()).optional(),
|
|
4967
|
-
governance: z.record(z.string()).optional(),
|
|
4968
|
-
agent_instructions: z.record(z.unknown()).optional(),
|
|
4969
|
-
relationship_patterns: z.record(z.object({
|
|
4970
|
-
description: z.string(),
|
|
4971
|
-
acl_required: z.union([z.boolean(), z.literal("optional")]).optional(),
|
|
4972
|
-
linter: z.string().optional()
|
|
4973
|
-
})).optional(),
|
|
4974
|
-
mvk: z.record(z.unknown()).optional(),
|
|
4975
|
-
cross_context: z.array(CrossContextEdgeSchema).optional(),
|
|
4976
|
-
workspace_config: z.string().optional(),
|
|
4977
|
-
legacy_config: z.string().optional()
|
|
4978
|
-
}).strict().refine((data) => {
|
|
4979
|
-
const contexts = data.bounded_contexts ?? [];
|
|
4980
|
-
return contexts.every((ctx) => {
|
|
4981
|
-
if (ctx.plane && ctx.file) {
|
|
4982
|
-
return ctx.file.startsWith(`contexts/${ctx.plane}/`);
|
|
4983
|
-
}
|
|
4984
|
-
return true;
|
|
4985
|
-
});
|
|
4986
|
-
}, {
|
|
4987
|
-
message: "Context plane does not match file path subdirectory",
|
|
4988
|
-
path: ["bounded_contexts"]
|
|
4989
|
-
});
|
|
4990
|
-
var ManifestSchema = z.object({
|
|
4991
|
-
// Toolchain-compatibility stamp (positive int; absent = legacy). NOT the
|
|
4992
|
-
// freeform `version` string below. Compatibility is asserted against the
|
|
4993
|
-
// RAW yaml BEFORE this `.strict()` parse (assertSupportedSchemaVersion in
|
|
4994
|
-
// manifest-schema-version.ts) — this entry only keeps strict mode from
|
|
4995
|
-
// rejecting stamped manifests as carrying an unknown key.
|
|
4996
|
-
schemaVersion: z.number().int().positive().optional(),
|
|
4997
|
-
version: z.string().optional(),
|
|
4998
|
-
description: z.string().optional(),
|
|
4999
|
-
system: z.string().optional(),
|
|
5000
|
-
scope: z.string().optional(),
|
|
5001
|
-
// Structured workspace metadata (the canonical `workspace:` block, also the
|
|
5002
|
-
// first block in the few-shot examples). `system`/`scope` above are derived
|
|
5003
|
-
// from `workspace.name`; `workspace.description` is the only carrier of the
|
|
5004
|
-
// human-readable intent. Emitted by `draftToManifest` so the generated
|
|
5005
|
-
// manifest survives `parseManifestToWizardData`'s strict parse on the
|
|
5006
|
-
// "Use this manifest" path. Optional — legacy/hand-written manifests omit it.
|
|
5007
|
-
workspace: z.object({
|
|
5008
|
-
name: z.string(),
|
|
5009
|
-
description: z.string()
|
|
5010
|
-
}).optional(),
|
|
5011
|
-
architecture: z.string().optional(),
|
|
5012
|
-
// The wizard records the chosen workspace template (e.g. "strict-enterprise")
|
|
5013
|
-
// alongside `architecture`; persisted into .architecture/manifest.yaml.
|
|
5014
|
-
workspaceTemplate: z.string().optional(),
|
|
5015
|
-
planes: z.record(z.array(z.string())).optional(),
|
|
5016
|
-
monorepo: z.record(z.unknown()).optional(),
|
|
5017
|
-
generator: z.record(z.unknown()).optional(),
|
|
5018
|
-
mvk: z.record(z.unknown()).optional(),
|
|
5019
|
-
invariants: z.record(z.string()).optional(),
|
|
5020
|
-
governance: z.record(z.string()).optional(),
|
|
5021
|
-
agent_instructions: z.record(z.unknown()).optional(),
|
|
5022
|
-
relationship_patterns: z.record(z.object({
|
|
5023
|
-
description: z.string(),
|
|
5024
|
-
acl_required: z.union([z.boolean(), z.literal("optional")]).optional(),
|
|
5025
|
-
linter: z.string().optional()
|
|
5026
|
-
})).optional(),
|
|
5027
|
-
bounded_contexts: z.array(BoundedContextSchema),
|
|
5028
|
-
apps: z.array(AppSchema).optional(),
|
|
5029
|
-
cross_context: z.array(CrossContextEdgeSchema).optional(),
|
|
5030
|
-
context_mappings: z.array(z.object({
|
|
5031
|
-
upstream: z.string(),
|
|
5032
|
-
downstream: z.string(),
|
|
5033
|
-
pattern: z.string().optional(),
|
|
5034
|
-
mechanism: z.string().optional(),
|
|
5035
|
-
notes: z.string().optional(),
|
|
5036
|
-
events: z.array(z.string()).optional()
|
|
5037
|
-
})).optional(),
|
|
5038
|
-
workspaceDefaults: z.record(z.unknown()).optional(),
|
|
5039
|
-
// Both side-car pointers. `mergeSplitManifest` resolves `workspace_config`
|
|
5040
|
-
// into the `monorepo`/`generator` blocks above and then carries the pointer
|
|
5041
|
-
// through with every other index key, so the merged (flat) form has to
|
|
5042
|
-
// accept it — this schema is `.strict()`, and the merge output is re-parsed
|
|
5043
|
-
// against it (sync's `validateManifest`, `parseManifestToWizardData`).
|
|
5044
|
-
workspace_config: z.string().optional(),
|
|
5045
|
-
legacy_config: z.string().optional()
|
|
5046
|
-
}).strict();
|
|
5102
|
+
var RESULT_KERNEL = `// @generated by @hexagen/sync — shared Result kernel (edit freely)
|
|
5103
|
+
/**
|
|
5104
|
+
* Result is the explicit success/failure type generated use-cases return.
|
|
5105
|
+
* Mirrors @hexagen/shared's Result. Created once, then preserved on re-sync.
|
|
5106
|
+
*/
|
|
5107
|
+
export type Result<T, E = unknown> =
|
|
5108
|
+
| { success: true; value: T }
|
|
5109
|
+
| { success: false; error: E };
|
|
5047
5110
|
|
|
5048
|
-
|
|
5049
|
-
|
|
5050
|
-
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
if (
|
|
5057
|
-
|
|
5111
|
+
export const ok = <T>(value: T): Result<T, never> => ({ success: true, value });
|
|
5112
|
+
export const err = <E>(error: E): Result<never, E> => ({
|
|
5113
|
+
success: false,
|
|
5114
|
+
error,
|
|
5115
|
+
});
|
|
5116
|
+
`;
|
|
5117
|
+
async function generateSharedKernel(config, report) {
|
|
5118
|
+
const result = createEmptyResult();
|
|
5119
|
+
if (config.mode !== "external") return result;
|
|
5120
|
+
const hasShared = (config.manifest.bounded_contexts ?? []).some(
|
|
5121
|
+
(bc) => bc.name?.toLowerCase() === "shared"
|
|
5122
|
+
);
|
|
5123
|
+
if (!hasShared) return result;
|
|
5124
|
+
const kernelPath = path7.join(
|
|
5125
|
+
config.workspaceRoot,
|
|
5126
|
+
"packages",
|
|
5127
|
+
"shared",
|
|
5128
|
+
"src",
|
|
5129
|
+
"domain",
|
|
5130
|
+
"result.ts"
|
|
5131
|
+
);
|
|
5132
|
+
if (!isInScope(kernelPath, config)) {
|
|
5133
|
+
result.skipped.push(kernelPath);
|
|
5134
|
+
return result;
|
|
5058
5135
|
}
|
|
5059
|
-
|
|
5136
|
+
try {
|
|
5137
|
+
await fs5.stat(kernelPath);
|
|
5138
|
+
result.skipped.push(kernelPath);
|
|
5139
|
+
return result;
|
|
5140
|
+
} catch (err3) {
|
|
5141
|
+
if (err3.code !== "ENOENT") throw err3;
|
|
5142
|
+
}
|
|
5143
|
+
if (!config.dryRun) {
|
|
5144
|
+
await fs5.mkdir(path7.dirname(kernelPath), { recursive: true });
|
|
5145
|
+
}
|
|
5146
|
+
const status = await safeWriteFileAtomic(
|
|
5147
|
+
kernelPath,
|
|
5148
|
+
RESULT_KERNEL,
|
|
5149
|
+
config,
|
|
5150
|
+
report,
|
|
5151
|
+
false
|
|
5152
|
+
);
|
|
5153
|
+
recordWriteStatus(result, kernelPath, status);
|
|
5154
|
+
return result;
|
|
5060
5155
|
}
|
|
5061
|
-
|
|
5062
|
-
|
|
5063
|
-
|
|
5156
|
+
var execAsync = promisify(exec);
|
|
5157
|
+
var MAX_BUFFER = 1024 * 1024 * 10;
|
|
5158
|
+
async function ensureDependenciesBuilt(config) {
|
|
5159
|
+
const { logger, dryRun } = config;
|
|
5160
|
+
if (dryRun) {
|
|
5161
|
+
logger.info("Pre‑flight: skipping build in dry-run mode");
|
|
5064
5162
|
return;
|
|
5065
|
-
|
|
5066
|
-
|
|
5163
|
+
}
|
|
5164
|
+
logger.info("Pre‑flight: ensuring package dependencies are up‑to‑date...");
|
|
5165
|
+
try {
|
|
5166
|
+
const { stdout, stderr } = await execAsync("npx turbo run build", {
|
|
5167
|
+
cwd: config.workspaceRoot,
|
|
5168
|
+
maxBuffer: MAX_BUFFER
|
|
5169
|
+
});
|
|
5170
|
+
if (stdout) logger.debug(stdout);
|
|
5171
|
+
if (stderr) logger.warn(stderr);
|
|
5172
|
+
logger.info("Pre‑flight build completed.");
|
|
5173
|
+
} catch (err3) {
|
|
5174
|
+
const e = err3;
|
|
5175
|
+
const errorDetails = e.stderr || e.stdout || e.message || String(err3);
|
|
5176
|
+
logger.error(`Pre-flight build failed. Aborting sync.`);
|
|
5177
|
+
logger.error(`Build error: ${errorDetails}`);
|
|
5178
|
+
throw new Error("Preflight build failed — sync aborted");
|
|
5067
5179
|
}
|
|
5068
5180
|
}
|
|
5069
5181
|
|
|
5070
|
-
//
|
|
5071
|
-
function
|
|
5072
|
-
|
|
5073
|
-
|
|
5182
|
+
// src/sync-engine-helpers.ts
|
|
5183
|
+
function mergeResult2(dest, src) {
|
|
5184
|
+
dest.created.push(...src.created);
|
|
5185
|
+
dest.updated.push(...src.updated);
|
|
5186
|
+
dest.skipped.push(...src.skipped);
|
|
5187
|
+
dest.deleted.push(...src.deleted);
|
|
5188
|
+
dest.unchanged.push(...src.unchanged);
|
|
5189
|
+
dest.totalOps += src.totalOps;
|
|
5190
|
+
if (src.error && !dest.error) {
|
|
5191
|
+
dest.error = src.error;
|
|
5192
|
+
dest.summary = src.summary;
|
|
5074
5193
|
}
|
|
5075
|
-
|
|
5076
|
-
|
|
5077
|
-
|
|
5194
|
+
}
|
|
5195
|
+
function mergeBarrelPasses(firstPass, secondPass) {
|
|
5196
|
+
const combined = createEmptyResult();
|
|
5197
|
+
const secondPaths = /* @__PURE__ */ new Set([
|
|
5198
|
+
...secondPass.created,
|
|
5199
|
+
...secondPass.updated,
|
|
5200
|
+
...secondPass.skipped,
|
|
5201
|
+
...secondPass.deleted
|
|
5202
|
+
]);
|
|
5203
|
+
const secondAll = /* @__PURE__ */ new Set([...secondPaths, ...secondPass.unchanged]);
|
|
5204
|
+
const firstMutations = /* @__PURE__ */ new Set([
|
|
5205
|
+
...firstPass.created,
|
|
5206
|
+
...firstPass.updated,
|
|
5207
|
+
...firstPass.deleted
|
|
5208
|
+
]);
|
|
5209
|
+
for (const p of firstPass.created) {
|
|
5210
|
+
if (!secondPaths.has(p)) combined.created.push(p);
|
|
5078
5211
|
}
|
|
5079
|
-
const
|
|
5080
|
-
|
|
5081
|
-
return false;
|
|
5212
|
+
for (const p of firstPass.updated) {
|
|
5213
|
+
if (!secondPaths.has(p)) combined.updated.push(p);
|
|
5082
5214
|
}
|
|
5083
|
-
|
|
5215
|
+
for (const p of firstPass.skipped) {
|
|
5216
|
+
if (!secondAll.has(p)) combined.skipped.push(p);
|
|
5217
|
+
}
|
|
5218
|
+
for (const p of firstPass.deleted) {
|
|
5219
|
+
if (!secondPaths.has(p)) combined.deleted.push(p);
|
|
5220
|
+
}
|
|
5221
|
+
for (const p of firstPass.unchanged) {
|
|
5222
|
+
if (!secondAll.has(p)) combined.unchanged.push(p);
|
|
5223
|
+
}
|
|
5224
|
+
combined.created.push(...secondPass.created);
|
|
5225
|
+
combined.updated.push(...secondPass.updated);
|
|
5226
|
+
combined.skipped.push(...secondPass.skipped);
|
|
5227
|
+
combined.deleted.push(...secondPass.deleted);
|
|
5228
|
+
for (const p of secondPass.unchanged) {
|
|
5229
|
+
if (!firstMutations.has(p)) combined.unchanged.push(p);
|
|
5230
|
+
}
|
|
5231
|
+
combined.totalOps = combined.created.length + combined.updated.length + combined.deleted.length;
|
|
5232
|
+
if (firstPass.error) {
|
|
5233
|
+
combined.error = firstPass.error;
|
|
5234
|
+
combined.summary = firstPass.summary;
|
|
5235
|
+
} else if (secondPass.error) {
|
|
5236
|
+
combined.error = secondPass.error;
|
|
5237
|
+
combined.summary = secondPass.summary;
|
|
5238
|
+
}
|
|
5239
|
+
return combined;
|
|
5084
5240
|
}
|
|
5085
|
-
var WorkspaceGovernanceSchema = z.object({
|
|
5086
|
-
workspaceName: z.string().min(1, "Workspace name is required"),
|
|
5087
|
-
workspaceTemplate: z.enum(["modular-monolith", "strict-enterprise", "micro-frontend"]).default("modular-monolith"),
|
|
5088
|
-
workspaceDescription: z.string().optional(),
|
|
5089
|
-
packageManager: z.enum(["yarn", "pnpm", "bun"]).default("yarn"),
|
|
5090
|
-
topologyStrictness: z.enum(["strict", "flexible"]).default("flexible"),
|
|
5091
|
-
namespacePrefix: z.string().default("@hexagen"),
|
|
5092
|
-
namingConventions: z.object({
|
|
5093
|
-
contextDirectoryPattern: z.string().default("packages/"),
|
|
5094
|
-
adapterSuffix: z.string().default(".adapter.ts")
|
|
5095
|
-
}).default({
|
|
5096
|
-
contextDirectoryPattern: "packages/",
|
|
5097
|
-
adapterSuffix: ".adapter.ts"
|
|
5098
|
-
})
|
|
5099
|
-
});
|
|
5100
|
-
var PortConfigurationSchema = z.object({
|
|
5101
|
-
inboundPorts: z.array(z.enum([
|
|
5102
|
-
"rest-controller",
|
|
5103
|
-
"graphql-resolver",
|
|
5104
|
-
"event-listener",
|
|
5105
|
-
"cli-command"
|
|
5106
|
-
])).default([]),
|
|
5107
|
-
outboundPorts: z.array(z.enum([
|
|
5108
|
-
"relational-db",
|
|
5109
|
-
"document-db",
|
|
5110
|
-
"external-service-client",
|
|
5111
|
-
"message-publisher"
|
|
5112
|
-
])).default([])
|
|
5113
|
-
});
|
|
5114
|
-
var PeerContextMappingSchema = z.object({
|
|
5115
|
-
consumerContext: z.string(),
|
|
5116
|
-
providerContext: z.string(),
|
|
5117
|
-
integrationPattern: z.enum(["open-host", "acl"]),
|
|
5118
|
-
communicationBoundary: z.enum(["in-process", "networked"])
|
|
5119
|
-
});
|
|
5120
|
-
var BoundedContextSchema2 = z.object({
|
|
5121
|
-
id: z.string(),
|
|
5122
|
-
name: z.string().min(1, "Please enter a name for this bounded context (e.g., 'UserService', 'OrderProcessing')"),
|
|
5123
|
-
description: z.string().optional(),
|
|
5124
|
-
// ADR-0041: `infrastructureTarget` (API backend) and `uiFramework` (below)
|
|
5125
|
-
// are PROJECT-LEVEL choices managed by the wizard's Applications step, which
|
|
5126
|
-
// fans a single selection out to every context. They persist per-context (the
|
|
5127
|
-
// source of truth `deriveApps` reads), but are NOT direct per-context input —
|
|
5128
|
-
// do not re-add per-context UI/API editing without revisiting ADR-0041.
|
|
5129
|
-
// `"none"` = the project opts out of a separate API backend (UI-only, e.g. a
|
|
5130
|
-
// Next.js app with built-in routes); `deriveApps` then emits no `api` app.
|
|
5131
|
-
// Distinct from `undefined` (legacy/unset → defaults to the preset).
|
|
5132
|
-
infrastructureTarget: z.enum(["nestjs", "express", "serverless", "plain-ts", "nitro", "none"]).optional(),
|
|
5133
|
-
coreDomainEntities: z.array(z.string()).default([]),
|
|
5134
|
-
valueObjects: z.array(z.string()).default([]),
|
|
5135
|
-
domainEvents: z.array(z.string()).default([]),
|
|
5136
|
-
portConfiguration: PortConfigurationSchema,
|
|
5137
|
-
// Backward compatibility: support legacy fields
|
|
5138
|
-
apiFramework: z.enum(["Fastify", "Express", "NestJS"]).optional(),
|
|
5139
|
-
uiFramework: z.enum(["", "Next.js", "React Router", "Remix", "Angular", "Vue.js"]).optional().default(""),
|
|
5140
|
-
persistenceAdapter: z.enum(["", "Prisma", "TypeORM", "Mongoose", "Drizzle"]).optional().default(""),
|
|
5141
|
-
messagingAdapter: z.enum(["", "BullMQ", "Temporal", "RabbitMQ"]).optional().default(""),
|
|
5142
|
-
telemetryProvider: z.enum(["", "OpenTelemetry", "None", "Prometheus", "Winston"]).optional().default(""),
|
|
5143
|
-
externalApiPorts: z.array(z.string()).optional(),
|
|
5144
|
-
llmProviders: z.array(z.string()).optional(),
|
|
5145
|
-
blockchainNetworks: z.array(z.string()).optional(),
|
|
5146
|
-
authenticationProvider: z.string().optional(),
|
|
5147
|
-
emailService: z.string().optional(),
|
|
5148
|
-
paymentGateway: z.string().optional(),
|
|
5149
|
-
storageProvider: z.string().optional(),
|
|
5150
|
-
searchService: z.string().optional(),
|
|
5151
|
-
webhookEndpoints: z.array(z.string()).optional(),
|
|
5152
|
-
entities: z.array(z.string()).optional(),
|
|
5153
|
-
useCases: z.array(z.string()).optional()
|
|
5154
|
-
});
|
|
5155
|
-
var ExternalContextSchema = z.object({
|
|
5156
|
-
id: z.string(),
|
|
5157
|
-
name: z.string().min(1, "Peer context name is required"),
|
|
5158
|
-
relationshipType: z.enum(["U", "D", "ACL", "SK", "P", "OHS"]),
|
|
5159
|
-
isEventDriven: z.boolean().optional(),
|
|
5160
|
-
entityNames: z.array(z.string()).optional(),
|
|
5161
|
-
useCaseNames: z.array(z.string()).optional()
|
|
5162
|
-
});
|
|
5163
|
-
z.object({
|
|
5164
|
-
boundedContexts: z.array(BoundedContextSchema2).default([]),
|
|
5165
|
-
externalContexts: z.array(ExternalContextSchema).default([]),
|
|
5166
|
-
governance: WorkspaceGovernanceSchema.default({
|
|
5167
|
-
workspaceName: "@hexagen",
|
|
5168
|
-
workspaceTemplate: "modular-monolith",
|
|
5169
|
-
packageManager: "yarn",
|
|
5170
|
-
topologyStrictness: "flexible",
|
|
5171
|
-
namespacePrefix: "@hexagen",
|
|
5172
|
-
namingConventions: {
|
|
5173
|
-
contextDirectoryPattern: "packages/",
|
|
5174
|
-
adapterSuffix: ".adapter.ts"
|
|
5175
|
-
}
|
|
5176
|
-
}),
|
|
5177
|
-
peerMappings: z.array(PeerContextMappingSchema).default([]),
|
|
5178
|
-
/**
|
|
5179
|
-
* Per-template install-time answers collected by the wizard. Keyed by
|
|
5180
|
-
* template id; each value is a record of question-id → answer. The CLI
|
|
5181
|
-
* use case consumes this via its `overrideAnswers` parameter, so the
|
|
5182
|
-
* wizard can feed answers gathered in the UI directly into a non-
|
|
5183
|
-
* interactive install. Defaults to an empty object for projects that
|
|
5184
|
-
* are scaffolded without the per-template questions step.
|
|
5185
|
-
*/
|
|
5186
|
-
addOnsAnswers: z.record(z.string(), z.record(z.string(), z.union([z.string(), z.boolean(), z.array(z.string())]))).default({}),
|
|
5187
|
-
/**
|
|
5188
|
-
* Provenance of the project's `manifestYaml` (import round-trip integrity,
|
|
5189
|
-
* Item 1). `"imported"` = the manifest is the source of truth (accepted via
|
|
5190
|
-
* `parseManifestToWizardData` — file import or AI generation) and the wizard
|
|
5191
|
-
* projection (`wizardToManifest`) is LOSSY for it, so autosave/export paths
|
|
5192
|
-
* must never overwrite or impersonate the stored manifest. Deliberately
|
|
5193
|
-
* `.optional()` rather than `.default("wizard")`: absent ≡ `"wizard"`
|
|
5194
|
-
* everywhere (guards key on `=== "imported"` only), which keeps every
|
|
5195
|
-
* wizard-authored formState byte-identical to before this field existed and
|
|
5196
|
-
* lets the load perimeter distinguish "legacy record, provenance unknown"
|
|
5197
|
-
* (absent) from an explicit value when running its one-time discriminator.
|
|
5198
|
-
*/
|
|
5199
|
-
manifestSource: z.enum(["wizard", "imported"]).optional()
|
|
5200
|
-
});
|
|
5201
|
-
var MonorepoConfigSchema = z.object({
|
|
5202
|
-
packageManager: z.string().optional(),
|
|
5203
|
-
workspaces: z.array(z.string()).optional(),
|
|
5204
|
-
rootFiles: z.record(z.unknown()).optional(),
|
|
5205
|
-
archInvariants: z.record(z.unknown()).optional()
|
|
5206
|
-
}).passthrough();
|
|
5207
|
-
var GeneratorSyncSchema = z.object({
|
|
5208
|
-
layers: z.record(z.unknown()).optional(),
|
|
5209
|
-
packageJson: z.record(z.unknown()).optional(),
|
|
5210
|
-
stubs: z.record(z.unknown()).optional(),
|
|
5211
|
-
apps: z.record(z.unknown()).optional()
|
|
5212
|
-
}).passthrough();
|
|
5213
|
-
var GeneratorConfigSchema = z.object({
|
|
5214
|
-
version: z.string().optional(),
|
|
5215
|
-
sync: GeneratorSyncSchema.optional()
|
|
5216
|
-
}).passthrough();
|
|
5217
|
-
var WorkspaceConfigSchema = z.object({
|
|
5218
|
-
monorepo: MonorepoConfigSchema.optional(),
|
|
5219
|
-
generator: GeneratorConfigSchema.optional(),
|
|
5220
|
-
workspaceDefaults: z.record(z.unknown()).optional(),
|
|
5221
|
-
tsConfigRoot: z.record(z.unknown()).optional(),
|
|
5222
|
-
eslint: z.record(z.unknown()).optional(),
|
|
5223
|
-
rootFiles: z.record(z.unknown()).optional(),
|
|
5224
|
-
generatorConfig: z.record(z.unknown()).optional(),
|
|
5225
|
-
turboConfig: z.record(z.unknown()).optional()
|
|
5226
|
-
}).passthrough();
|
|
5227
5241
|
function assertPathWithinArchitecture(workspaceRoot, relativePath) {
|
|
5228
5242
|
const resolved = path7.resolve(workspaceRoot, ".architecture", relativePath);
|
|
5229
5243
|
const archRoot = path7.resolve(workspaceRoot, ".architecture");
|