@fabricorg/fabric-gen 0.6.2 → 0.7.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/CHANGELOG.md +34 -0
- package/dist/{chunk-4QFNFERM.js → chunk-J4IM2BKQ.js} +216 -24
- package/dist/chunk-J4IM2BKQ.js.map +1 -0
- package/dist/cli.cjs +213 -23
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.cjs +215 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -6
- package/dist/index.d.ts +24 -6
- package/dist/index.js +3 -1
- package/package.json +22 -14
- package/dist/chunk-4QFNFERM.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- c9fb3b4: Close the authoring loop and locate the errors in it. `fabric-gen export --module <file> --out <manifest.json>` imports an authored `FabricModule`, normalizes it with `exportModuleManifest()`, and compiles the result before writing, so a bad field is reported against the module the author just wrote. Nothing shipped connected the two halves before: `init capability` scaffolded an empty manifest, and filling it in by hand was a guess at the normalizer's output.
|
|
8
|
+
|
|
9
|
+
`init capability` now scaffolds `module.ts`, a working capability with one object type, one event, and one action declaring all six execution dimensions, so export, generate, and `--check` all succeed on the scaffold. `init experience` now writes the assembly lockfile and runtime capability file its own application config names, so `check-application` passes on the scaffold instead of failing on a missing file, plus a README naming the three packages the scaffolded code imports.
|
|
10
|
+
|
|
11
|
+
Compiler validation reports one field per message with its path, replacing checks that folded six conditions into one message and printed `undefined` for the field that was missing.
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [c9fb3b4]
|
|
16
|
+
- @fabricorg/compiler@2.2.3
|
|
17
|
+
|
|
18
|
+
## 0.6.3
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- 1b81b20: Publish with real build provenance, and name the repository each attestation points at. `pnpm publish` accepts `--provenance` and drops it, so every release until now was unattested while the release document claimed otherwise. The pipeline now packs with pnpm and uploads the tarball with `npm publish --provenance`, and every package declares `repository`, `homepage`, and `bugs`.
|
|
23
|
+
- Updated dependencies [1b81b20]
|
|
24
|
+
- @fabricorg/assembly@0.4.2
|
|
25
|
+
- @fabricorg/compiler@2.2.2
|
|
26
|
+
- @fabricorg/gen-capability@0.5.2
|
|
27
|
+
- @fabricorg/gen-conformance@1.0.1
|
|
28
|
+
- @fabricorg/gen-docs@0.2.5
|
|
29
|
+
- @fabricorg/gen-events@0.2.5
|
|
30
|
+
- @fabricorg/gen-graphql@4.0.1
|
|
31
|
+
- @fabricorg/gen-prisma@2.0.3
|
|
32
|
+
- @fabricorg/gen-sdui@0.5.3
|
|
33
|
+
- @fabricorg/gen-types@2.0.3
|
|
34
|
+
- @fabricorg/sdui-composer@0.2.4
|
|
35
|
+
- @fabricorg/sdui-release@0.7.3
|
|
36
|
+
|
|
3
37
|
## 0.6.2
|
|
4
38
|
|
|
5
39
|
### Patch Changes
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
import { access, mkdir, readFile, readdir, rm, writeFile } from "fs/promises";
|
|
3
3
|
import { createPrivateKey } from "crypto";
|
|
4
4
|
import path from "path";
|
|
5
|
+
import { pathToFileURL } from "url";
|
|
5
6
|
import { compileManifestBundle, runGenerator } from "@fabricorg/compiler";
|
|
7
|
+
import { exportModuleManifest } from "@fabricorg/platform/manifest";
|
|
6
8
|
import { capabilityGenerator } from "@fabricorg/gen-capability";
|
|
7
9
|
import { docsGenerator } from "@fabricorg/gen-docs";
|
|
8
10
|
import { eventsGenerator } from "@fabricorg/gen-events";
|
|
@@ -14,6 +16,7 @@ import { createEs256ReleaseSigner, promoteExperienceRelease } from "@fabricorg/s
|
|
|
14
16
|
import { conformanceGenerator } from "@fabricorg/gen-conformance";
|
|
15
17
|
import {
|
|
16
18
|
assertAssemblyLockfile,
|
|
19
|
+
resolveAssembly,
|
|
17
20
|
assertAssemblyRuntimeCompatible
|
|
18
21
|
} from "@fabricorg/assembly";
|
|
19
22
|
import {
|
|
@@ -33,6 +36,7 @@ var compareCanonicalStrings = (left, right) => left < right ? -1 : left > right
|
|
|
33
36
|
var usage = [
|
|
34
37
|
"Usage:",
|
|
35
38
|
" fabric-gen init capability <namespace> [--directory <path>]",
|
|
39
|
+
" fabric-gen export --module <file> [--export <name>] --out <manifest.json>",
|
|
36
40
|
" fabric-gen init experience <application> [--directory <path>]",
|
|
37
41
|
" fabric-gen check-application [--config <path>]",
|
|
38
42
|
" fabric-gen promote-experience --config <path> --key <pem> [--out <path>]",
|
|
@@ -52,6 +56,13 @@ function flagValue(args, flag) {
|
|
|
52
56
|
return value;
|
|
53
57
|
}
|
|
54
58
|
async function runFabricGenCommand(args) {
|
|
59
|
+
if (args[0] === "export") {
|
|
60
|
+
const moduleFile = flagValue(args, "--module");
|
|
61
|
+
const out = flagValue(args, "--out");
|
|
62
|
+
if (!moduleFile || !out) throw new FabricGenUsageError(usage);
|
|
63
|
+
const result2 = await exportModuleManifestFile({ moduleFile, out, exportName: flagValue(args, "--export") });
|
|
64
|
+
return `Exported "${result2.namespace}" from ${result2.exportName} to ${out}: ${result2.objectTypes} object types, ${result2.actions} actions, ${result2.eventTypes} event types.`;
|
|
65
|
+
}
|
|
55
66
|
if (args[0] === "init") {
|
|
56
67
|
if (!args[2] || args[2].startsWith("--")) {
|
|
57
68
|
throw new FabricGenUsageError(usage);
|
|
@@ -101,6 +112,40 @@ async function runFabricGenCommand(args) {
|
|
|
101
112
|
});
|
|
102
113
|
return `${args.includes("--check") ? "Checked" : "Generated"} ${result.files.length} files.`;
|
|
103
114
|
}
|
|
115
|
+
function experienceReadme(application) {
|
|
116
|
+
return [
|
|
117
|
+
`# ${application} experience integration`,
|
|
118
|
+
"",
|
|
119
|
+
"| File | What it is |",
|
|
120
|
+
"| --- | --- |",
|
|
121
|
+
"| `fabric.experience.ts` | The server runtime and gateway, wired to your host. |",
|
|
122
|
+
"| `fabric.component-pack.ts` | The components this application is allowed to render. |",
|
|
123
|
+
"| `fabric.application.json` | What the deployment gate reads. |",
|
|
124
|
+
"| `fabric.assembly.lock.json` | The resolved assembly. Empty until you add capabilities. |",
|
|
125
|
+
"| `fabric.runtime.json` | Capabilities the running host actually registers. |",
|
|
126
|
+
"",
|
|
127
|
+
"## Install",
|
|
128
|
+
"",
|
|
129
|
+
"The scaffolded files import three packages this generator does not install:",
|
|
130
|
+
"",
|
|
131
|
+
"```bash",
|
|
132
|
+
"pnpm add @fabricorg/experience-runtime @fabricorg/experience-gateway @fabricorg/component-pack",
|
|
133
|
+
"```",
|
|
134
|
+
"",
|
|
135
|
+
"## Check it",
|
|
136
|
+
"",
|
|
137
|
+
"```bash",
|
|
138
|
+
"fabric-gen check-application --config fabric.application.json",
|
|
139
|
+
"```",
|
|
140
|
+
"",
|
|
141
|
+
"It passes on the scaffold and keeps passing as you add capabilities, as long",
|
|
142
|
+
"as the lockfile, the runtime capabilities, and every promoted release agree.",
|
|
143
|
+
"Regenerate the lockfile from your composition root with `resolveAssembly`;",
|
|
144
|
+
"`fabric.runtime.json` must list what that same root registers with the host,",
|
|
145
|
+
"which is what stops a deployment from serving a plan its host cannot answer.",
|
|
146
|
+
""
|
|
147
|
+
].join("\n");
|
|
148
|
+
}
|
|
104
149
|
async function initializeExperience(options) {
|
|
105
150
|
if (!/^[a-z][a-z0-9-]*$/.test(options.application)) {
|
|
106
151
|
throw new Error("Application name must use lowercase letters, numbers, and hyphens.");
|
|
@@ -152,6 +197,35 @@ async function initializeExperience(options) {
|
|
|
152
197
|
releases: []
|
|
153
198
|
}, null, 2)}
|
|
154
199
|
`
|
|
200
|
+
],
|
|
201
|
+
// The application config names these two files, so the scaffold has to
|
|
202
|
+
// produce them. Without them `fabric-gen check-application`, the very
|
|
203
|
+
// next step, failed on a missing file rather than on anything the
|
|
204
|
+
// author had done. The lockfile is resolved here, not hand-written, so
|
|
205
|
+
// it carries a real assembly digest from the first commit.
|
|
206
|
+
[
|
|
207
|
+
path.join(options.directory, "fabric.assembly.lock.json"),
|
|
208
|
+
`${JSON.stringify(resolveAssembly({
|
|
209
|
+
manifest: {
|
|
210
|
+
formatVersion: 2,
|
|
211
|
+
application: options.application,
|
|
212
|
+
capabilities: [],
|
|
213
|
+
componentPacks: [],
|
|
214
|
+
bindings: [],
|
|
215
|
+
contracts: []
|
|
216
|
+
},
|
|
217
|
+
capabilities: [],
|
|
218
|
+
componentPacks: []
|
|
219
|
+
}).lockfile, null, 2)}
|
|
220
|
+
`
|
|
221
|
+
],
|
|
222
|
+
[
|
|
223
|
+
path.join(options.directory, "fabric.runtime.json"),
|
|
224
|
+
"[]\n"
|
|
225
|
+
],
|
|
226
|
+
[
|
|
227
|
+
path.join(options.directory, "README.md"),
|
|
228
|
+
experienceReadme(options.application)
|
|
155
229
|
]
|
|
156
230
|
];
|
|
157
231
|
await mkdir(options.directory, { recursive: true });
|
|
@@ -225,14 +299,54 @@ async function checkApplication(options) {
|
|
|
225
299
|
assemblyDigest: assembly.assemblyDigest
|
|
226
300
|
};
|
|
227
301
|
}
|
|
302
|
+
async function exportModuleManifestFile(options) {
|
|
303
|
+
const absolute = path.resolve(options.moduleFile);
|
|
304
|
+
let loaded;
|
|
305
|
+
try {
|
|
306
|
+
loaded = await import(pathToFileURL(absolute).href);
|
|
307
|
+
} catch (error) {
|
|
308
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
309
|
+
throw new Error(`Could not load module file "${options.moduleFile}": ${reason}
|
|
310
|
+
A TypeScript file needs a runtime that strips types (Node 22.18 or newer); otherwise point --module at the built JavaScript.`);
|
|
311
|
+
}
|
|
312
|
+
const candidates = Object.entries(loaded).filter(([, value]) => isFabricModuleLike(value));
|
|
313
|
+
let entry;
|
|
314
|
+
if (options.exportName) {
|
|
315
|
+
const named = loaded[options.exportName];
|
|
316
|
+
if (named === void 0) throw new Error(`"${options.moduleFile}" has no export named "${options.exportName}". It exports: ${Object.keys(loaded).join(", ") || "nothing"}.`);
|
|
317
|
+
if (!isFabricModuleLike(named)) throw new Error(`Export "${options.exportName}" of "${options.moduleFile}" is not a FabricModule: it has no string "namespace".`);
|
|
318
|
+
entry = [options.exportName, named];
|
|
319
|
+
} else if (candidates.length === 1) {
|
|
320
|
+
entry = candidates[0];
|
|
321
|
+
} else if (candidates.length === 0) {
|
|
322
|
+
throw new Error(`"${options.moduleFile}" exports no FabricModule. Export one, with a string "namespace", or name it with --export.`);
|
|
323
|
+
} else {
|
|
324
|
+
throw new Error(`"${options.moduleFile}" exports ${candidates.length} modules (${candidates.map(([name]) => name).join(", ")}). Choose one with --export.`);
|
|
325
|
+
}
|
|
326
|
+
const manifest = exportModuleManifest(entry[1]);
|
|
327
|
+
compileManifestBundle({ manifestVersion: 2, modules: [manifest] });
|
|
328
|
+
await mkdir(path.dirname(path.resolve(options.out)), { recursive: true });
|
|
329
|
+
await writeFile(path.resolve(options.out), `${JSON.stringify(manifest, null, 2)}
|
|
330
|
+
`, "utf8");
|
|
331
|
+
return {
|
|
332
|
+
namespace: manifest.namespace,
|
|
333
|
+
exportName: entry[0],
|
|
334
|
+
objectTypes: manifest.objectTypes.length,
|
|
335
|
+
actions: manifest.actions.length,
|
|
336
|
+
eventTypes: manifest.eventTypes.length
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
function isFabricModuleLike(value) {
|
|
340
|
+
return typeof value === "object" && value !== null && typeof value.namespace === "string";
|
|
341
|
+
}
|
|
228
342
|
async function initializeCapability(options) {
|
|
229
343
|
if (!/^[a-z][a-z0-9-]*$/.test(options.namespace)) {
|
|
230
344
|
throw new Error("Capability namespace must use lowercase letters, numbers, and hyphens.");
|
|
231
345
|
}
|
|
232
346
|
const displayName = options.namespace.split("-").map((part, index) => index === 0 ? `${part.charAt(0).toUpperCase()}${part.slice(1)}` : part).join(" ");
|
|
233
|
-
const
|
|
347
|
+
const modulePath = path.join(options.directory, "module.ts");
|
|
234
348
|
const readmePath = path.join(options.directory, "README.md");
|
|
235
|
-
for (const file of [readmePath,
|
|
349
|
+
for (const file of [readmePath, modulePath]) {
|
|
236
350
|
try {
|
|
237
351
|
await access(file);
|
|
238
352
|
throw new Error(`Refusing to overwrite existing file "${file}".`);
|
|
@@ -241,33 +355,108 @@ async function initializeCapability(options) {
|
|
|
241
355
|
if (error.code !== "ENOENT") throw error;
|
|
242
356
|
}
|
|
243
357
|
}
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
358
|
+
const module = [
|
|
359
|
+
`import type { ActionDefinition } from "@fabricorg/platform/actions";`,
|
|
360
|
+
`import type { FabricModule } from "@fabricorg/platform/modules";`,
|
|
361
|
+
"",
|
|
362
|
+
`/** One governed action. Every field below is checked when the manifest is exported. */`,
|
|
363
|
+
`const recordExample: ActionDefinition = {`,
|
|
364
|
+
` actionId: "${options.namespace}.record_example",`,
|
|
365
|
+
` namespace: "${options.namespace}",`,
|
|
366
|
+
" version: 1,",
|
|
367
|
+
' kind: "atomic",',
|
|
368
|
+
" idempotent: true,",
|
|
369
|
+
" mutatesDomain: true,",
|
|
370
|
+
' emitsEvents: ["ExampleRecorded"],',
|
|
371
|
+
" // The six execution dimensions. A strict certification profile requires all of them.",
|
|
372
|
+
" execution: {",
|
|
373
|
+
' connectivity: "online-required",',
|
|
374
|
+
' authorityMoment: "execution",',
|
|
375
|
+
' idempotency: "required",',
|
|
376
|
+
' completion: "immediate",',
|
|
377
|
+
' consistency: "authoritative-now",',
|
|
378
|
+
' sensitivity: "internal",',
|
|
379
|
+
" },",
|
|
380
|
+
" schema: {",
|
|
381
|
+
" parse(value: unknown): { exampleId: string } {",
|
|
382
|
+
" const input = value as { exampleId?: unknown };",
|
|
383
|
+
' if (typeof input?.exampleId !== "string") throw new Error("exampleId is required");',
|
|
384
|
+
" return { exampleId: input.exampleId };",
|
|
385
|
+
" },",
|
|
386
|
+
" safeParse(value: unknown) {",
|
|
387
|
+
" try {",
|
|
388
|
+
" return { success: true as const, data: this.parse(value) };",
|
|
389
|
+
" } catch (error) {",
|
|
390
|
+
' return { success: false as const, error: { issues: [{ path: ["exampleId"], message: error instanceof Error ? error.message : String(error) }] } };',
|
|
391
|
+
" }",
|
|
392
|
+
" },",
|
|
393
|
+
" },",
|
|
394
|
+
" handler: async (_context, parameters) => ({",
|
|
395
|
+
" success: true,",
|
|
396
|
+
" data: {",
|
|
397
|
+
" ...(parameters as { exampleId: string }),",
|
|
398
|
+
" _events: [{",
|
|
399
|
+
' eventType: "ExampleRecorded",',
|
|
400
|
+
' entityType: "Example",',
|
|
401
|
+
" entityId: (parameters as { exampleId: string }).exampleId,",
|
|
402
|
+
" payload: parameters,",
|
|
403
|
+
" }],",
|
|
404
|
+
" },",
|
|
405
|
+
" }),",
|
|
406
|
+
"};",
|
|
407
|
+
"",
|
|
408
|
+
`export const ${camelCase(options.namespace)}Module: FabricModule = {`,
|
|
409
|
+
` namespace: "${options.namespace}",`,
|
|
410
|
+
' version: "0.1.0",',
|
|
411
|
+
" capability: {",
|
|
412
|
+
` displayName: "${displayName}",`,
|
|
413
|
+
` description: "Governed ${displayName.toLowerCase()} capability.",`,
|
|
414
|
+
' stability: "experimental",',
|
|
415
|
+
" },",
|
|
416
|
+
" objectTypes: [{",
|
|
417
|
+
' type: "Example",',
|
|
418
|
+
" schema: {",
|
|
419
|
+
' type: "object",',
|
|
420
|
+
' properties: { exampleId: { type: "string" } },',
|
|
421
|
+
' required: ["exampleId"],',
|
|
422
|
+
" },",
|
|
423
|
+
" }],",
|
|
424
|
+
` idPrefixes: [{ prefix: "exm", name: "Example", module: "${options.namespace}" }],`,
|
|
425
|
+
' eventTypes: [{ eventType: "ExampleRecorded", schemaVersion: 1 }],',
|
|
426
|
+
" actions: [recordExample],",
|
|
427
|
+
"};",
|
|
428
|
+
""
|
|
429
|
+
].join("\n");
|
|
262
430
|
const readme = [
|
|
263
431
|
`# ${displayName}`,
|
|
264
432
|
"",
|
|
265
|
-
"
|
|
433
|
+
"`module.ts` is the source of truth. It is TypeScript, so the shape of every",
|
|
434
|
+
"action, object type, and event is checked as you write it.",
|
|
435
|
+
"",
|
|
436
|
+
"## The loop",
|
|
266
437
|
"",
|
|
267
438
|
"```bash",
|
|
439
|
+
"# 1. Export the authored module to the normalized manifest the generators read.",
|
|
440
|
+
"fabric-gen export --module module.ts --out fabric.manifest.json",
|
|
441
|
+
"",
|
|
442
|
+
"# 2. Generate types, event contracts, the usage contract, and docs.",
|
|
268
443
|
"fabric-gen --input fabric.manifest.json --out generated",
|
|
444
|
+
"",
|
|
445
|
+
"# 3. In CI, prove the generated files match the manifest.",
|
|
269
446
|
"fabric-gen --input fabric.manifest.json --out generated --check",
|
|
270
447
|
"```",
|
|
448
|
+
"",
|
|
449
|
+
"Commit both `fabric.manifest.json` and `generated/`. The manifest is the",
|
|
450
|
+
"contract other capabilities and applications compile against; regenerating",
|
|
451
|
+
"is how a consumer learns what changed.",
|
|
452
|
+
"",
|
|
453
|
+
"## What to edit",
|
|
454
|
+
"",
|
|
455
|
+
"- **Object types** carry a portable JSON Schema. They become generated TypeScript types.",
|
|
456
|
+
"- **Actions** declare six execution dimensions. A host refuses an action whose",
|
|
457
|
+
" declaration does not match how it is invoked, so declare them honestly.",
|
|
458
|
+
"- **Events** are the capability's public vocabulary. Adding a field is compatible;",
|
|
459
|
+
" removing or retyping one is not.",
|
|
271
460
|
""
|
|
272
461
|
].join("\n");
|
|
273
462
|
await mkdir(options.directory, { recursive: true });
|
|
@@ -275,8 +464,7 @@ async function initializeCapability(options) {
|
|
|
275
464
|
try {
|
|
276
465
|
for (const [file, content] of [
|
|
277
466
|
[readmePath, readme],
|
|
278
|
-
[
|
|
279
|
-
`]
|
|
467
|
+
[modulePath, module]
|
|
280
468
|
]) {
|
|
281
469
|
await writeFile(file, content, { encoding: "utf8", flag: "wx" });
|
|
282
470
|
created.push(file);
|
|
@@ -290,6 +478,9 @@ async function initializeCapability(options) {
|
|
|
290
478
|
}
|
|
291
479
|
return { created };
|
|
292
480
|
}
|
|
481
|
+
function camelCase(namespace) {
|
|
482
|
+
return namespace.split("-").map((part, index) => index === 0 ? part : `${part.charAt(0).toUpperCase()}${part.slice(1)}`).join("");
|
|
483
|
+
}
|
|
293
484
|
async function generateFromManifest(options) {
|
|
294
485
|
const input = JSON.parse(await readFile(options.inputPath, "utf8"));
|
|
295
486
|
if (!input || typeof input !== "object" || Array.isArray(input)) throw new Error("Manifest input must be a JSON object.");
|
|
@@ -406,8 +597,9 @@ export {
|
|
|
406
597
|
runFabricGenCommand,
|
|
407
598
|
initializeExperience,
|
|
408
599
|
checkApplication,
|
|
600
|
+
exportModuleManifestFile,
|
|
409
601
|
initializeCapability,
|
|
410
602
|
generateFromManifest,
|
|
411
603
|
promoteExperience
|
|
412
604
|
};
|
|
413
|
-
//# sourceMappingURL=chunk-
|
|
605
|
+
//# sourceMappingURL=chunk-J4IM2BKQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../index.ts"],"sourcesContent":["import { access, mkdir, readFile, readdir, rm, writeFile } from \"node:fs/promises\";\nimport { createPrivateKey } from \"node:crypto\";\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { compileManifestBundle, runGenerator, type GeneratedFile, type GeneratorTarget } from \"@fabricorg/compiler\";\nimport { exportModuleManifest } from \"@fabricorg/platform/manifest\";\nimport { capabilityGenerator } from \"@fabricorg/gen-capability\";\nimport { docsGenerator } from \"@fabricorg/gen-docs\";\nimport { eventsGenerator } from \"@fabricorg/gen-events\";\nimport { typesGenerator } from \"@fabricorg/gen-types\";\nimport { prismaGenerator } from \"@fabricorg/gen-prisma\";\nimport { graphqlGenerator } from \"@fabricorg/gen-graphql\";\nimport { sduiGenerator } from \"@fabricorg/gen-sdui\";\nimport type { UsageContractDocument } from \"@fabricorg/gen-capability\";\nimport { createEs256ReleaseSigner, promoteExperienceRelease } from \"@fabricorg/sdui-composer\";\nimport { conformanceGenerator } from \"@fabricorg/gen-conformance\";\nimport {\n\tassertAssemblyLockfile,\n\tresolveAssembly,\n\tassertAssemblyRuntimeCompatible,\n\ttype AssemblyLockfile,\n\ttype AvailableCapability,\n} from \"@fabricorg/assembly\";\nimport {\n\tassertSduiReleaseIntegrity,\n\ttype SduiRelease,\n} from \"@fabricorg/sdui-release\";\n\nexport const GENERATOR_TARGETS: Record<string, GeneratorTarget> = {\n\ttypes: typesGenerator,\n\tevents: eventsGenerator,\n\tcapability: capabilityGenerator,\n\tdocs: docsGenerator,\n\tprisma: prismaGenerator,\n\tgraphql: graphqlGenerator,\n\tsdui: sduiGenerator,\n\tconformance: conformanceGenerator,\n};\nconst compareCanonicalStrings = (left: string, right: string): number => left < right ? -1 : left > right ? 1 : 0;\n\nexport interface GenerateOptions { inputPath: string; outputDirectory: string; targets: string[]; check?: boolean; }\nexport interface GenerateResult { changed: string[]; stale: string[]; files: GeneratedFile[]; }\nexport interface InitializeCapabilityOptions { directory: string; namespace: string; }\nexport interface InitializeCapabilityResult { created: string[]; }\nexport interface InitializeExperienceOptions { directory: string; application: string; }\nexport interface InitializeExperienceResult { created: string[]; }\nexport interface CheckApplicationOptions { configPath: string; }\nexport interface PromoteExperienceOptions {\n\tconfigPath: string;\n\t/** PEM-encoded ES256 private key. Never read from the configuration file. */\n\tprivateKeyPath: string;\n\toutputPath?: string;\n}\nexport interface PromoteExperienceResult {\n\tapplication: string;\n\treleaseDigest: string;\n\tassemblyDigest: string;\n\troutes: { views: number; intents: number };\n\toutputPath: string;\n}\nexport interface CheckApplicationResult {\n\tapplication: string;\n\tcapabilities: number;\n\treleases: number;\n\tassemblyDigest: string;\n}\n\nconst usage = [\n\t\"Usage:\",\n\t\" fabric-gen init capability <namespace> [--directory <path>]\",\n\t\" fabric-gen export --module <file> [--export <name>] --out <manifest.json>\",\n\t\" fabric-gen init experience <application> [--directory <path>]\",\n\t\" fabric-gen check-application [--config <path>]\",\n\t\" fabric-gen promote-experience --config <path> --key <pem> [--out <path>]\",\n\t\" fabric-gen --input <manifest.json> --out <directory> [--targets <list>] [--check]\",\n].join(\"\\n\");\n\nexport class FabricGenUsageError extends Error {\n\toverride readonly name = \"FabricGenUsageError\";\n}\n\nexport function fabricGenCliExitCode(error: unknown): number {\n\treturn error instanceof FabricGenUsageError ? 2 : 1;\n}\n\nfunction flagValue(args: readonly string[], flag: string): string | undefined {\n\tconst index = args.indexOf(flag);\n\tif (index < 0) return undefined;\n\tconst value = args[index + 1];\n\tif (!value || value.startsWith(\"--\")) throw new FabricGenUsageError(usage);\n\treturn value;\n}\n\n/** Execute one CLI command and return its single human-readable result line. */\nexport async function runFabricGenCommand(args: readonly string[]): Promise<string> {\n\tif (args[0] === \"export\") {\n\t\tconst moduleFile = flagValue(args, \"--module\");\n\t\tconst out = flagValue(args, \"--out\");\n\t\tif (!moduleFile || !out) throw new FabricGenUsageError(usage);\n\t\tconst result = await exportModuleManifestFile({ moduleFile, out, exportName: flagValue(args, \"--export\") });\n\t\treturn `Exported \"${result.namespace}\" from ${result.exportName} to ${out}: ${result.objectTypes} object types, ${result.actions} actions, ${result.eventTypes} event types.`;\n\t}\n\tif (args[0] === \"init\") {\n\t\tif (!args[2] || args[2].startsWith(\"--\")) {\n\t\t\tthrow new FabricGenUsageError(usage);\n\t\t}\n\t\tconst name = args[2];\n\t\tconst directory = flagValue(args, \"--directory\") ?? name;\n\t\tif (args[1] === \"capability\") {\n\t\t\tconst result = await initializeCapability({ directory, namespace: name });\n\t\t\treturn `Initialized capability \"${name}\" with ${result.created.length} files.`;\n\t\t}\n\t\tif (args[1] === \"experience\") {\n\t\t\tconst result = await initializeExperience({ directory, application: name });\n\t\t\treturn `Initialized experience integration \"${name}\" with ${result.created.length} files.`;\n\t\t}\n\t\tthrow new FabricGenUsageError(usage);\n\t}\n\tif (args[0] === \"promote-experience\") {\n\t\tconst configPath = flagValue(args, \"--config\");\n\t\tconst privateKeyPath = flagValue(args, \"--key\");\n\t\tif (!configPath) throw new FabricGenUsageError(\"promote-experience requires --config.\");\n\t\tif (!privateKeyPath) throw new FabricGenUsageError(\"promote-experience requires --key.\");\n\t\tconst outputPath = flagValue(args, \"--out\");\n\t\tconst result = await promoteExperience({\n\t\t\tconfigPath,\n\t\t\tprivateKeyPath,\n\t\t\t...(outputPath ? { outputPath } : {}),\n\t\t});\n\t\treturn [\n\t\t\t`Promoted ${result.application} release ${result.releaseDigest.slice(0, 12)} against assembly ${result.assemblyDigest.slice(0, 12)}.`,\n\t\t\t`Routes: ${result.routes.views} views, ${result.routes.intents} intents.`,\n\t\t\t`Wrote ${result.outputPath}`,\n\t\t].join(\"\\n\");\n\t}\n\n\tif (args[0] === \"check-application\") {\n\t\tconst configPath = flagValue(args, \"--config\") ?? \"fabric.application.json\";\n\t\tconst result = await checkApplication({ configPath });\n\t\treturn `Checked \"${result.application}\": ${result.capabilities} capabilities, ${result.releases} releases.`;\n\t}\n\tconst inputPath = flagValue(args, \"--input\");\n\tconst outputDirectory = flagValue(args, \"--out\");\n\tif (!inputPath || !outputDirectory) throw new FabricGenUsageError(usage);\n\tconst result = await generateFromManifest({\n\t\tinputPath,\n\t\toutputDirectory,\n\t\ttargets: (flagValue(args, \"--targets\") ?? \"types,events,capability,docs\")\n\t\t\t.split(\",\")\n\t\t\t.filter(Boolean),\n\t\tcheck: args.includes(\"--check\"),\n\t});\n\treturn `${args.includes(\"--check\") ? \"Checked\" : \"Generated\"} ${result.files.length} files.`;\n}\n\n/**\n * Add experience integration files to an existing application. It deliberately\n * does not create package.json, routes, authentication, billing, or navigation:\n * those remain owned by the Supastarter-derived application shell.\n */\n/** What the scaffolded files are, and what has to be installed for them to compile. */\nfunction experienceReadme(application: string): string {\n\treturn [\n\t\t`# ${application} experience integration`,\n\t\t\"\",\n\t\t\"| File | What it is |\",\n\t\t\"| --- | --- |\",\n\t\t\"| `fabric.experience.ts` | The server runtime and gateway, wired to your host. |\",\n\t\t\"| `fabric.component-pack.ts` | The components this application is allowed to render. |\",\n\t\t\"| `fabric.application.json` | What the deployment gate reads. |\",\n\t\t\"| `fabric.assembly.lock.json` | The resolved assembly. Empty until you add capabilities. |\",\n\t\t\"| `fabric.runtime.json` | Capabilities the running host actually registers. |\",\n\t\t\"\",\n\t\t\"## Install\",\n\t\t\"\",\n\t\t\"The scaffolded files import three packages this generator does not install:\",\n\t\t\"\",\n\t\t\"```bash\",\n\t\t\"pnpm add @fabricorg/experience-runtime @fabricorg/experience-gateway @fabricorg/component-pack\",\n\t\t\"```\",\n\t\t\"\",\n\t\t\"## Check it\",\n\t\t\"\",\n\t\t\"```bash\",\n\t\t\"fabric-gen check-application --config fabric.application.json\",\n\t\t\"```\",\n\t\t\"\",\n\t\t\"It passes on the scaffold and keeps passing as you add capabilities, as long\",\n\t\t\"as the lockfile, the runtime capabilities, and every promoted release agree.\",\n\t\t\"Regenerate the lockfile from your composition root with `resolveAssembly`;\",\n\t\t\"`fabric.runtime.json` must list what that same root registers with the host,\",\n\t\t\"which is what stops a deployment from serving a plan its host cannot answer.\",\n\t\t\"\",\n\t].join(\"\\n\");\n}\n\nexport async function initializeExperience(\n\toptions: InitializeExperienceOptions,\n): Promise<InitializeExperienceResult> {\n\tif (!/^[a-z][a-z0-9-]*$/.test(options.application)) {\n\t\tthrow new Error(\"Application name must use lowercase letters, numbers, and hyphens.\");\n\t}\n\tconst functionName = options.application\n\t\t.split(\"-\")\n\t\t.map((part) => `${part.charAt(0).toUpperCase()}${part.slice(1)}`)\n\t\t.join(\"\");\n\tconst files = [\n\t\t[\n\t\t\tpath.join(options.directory, \"fabric.experience.ts\"),\n\t\t\t[\n\t\t\t\t'import { createExperienceServerRuntime } from \"@fabricorg/experience-runtime/server\";',\n\t\t\t\t'import { createExperienceGateway } from \"@fabricorg/experience-gateway\";',\n\t\t\t\t\"\",\n\t\t\t\t`export const create${functionName}ExperienceRuntime = (`,\n\t\t\t\t\"\\toptions: Parameters<typeof createExperienceServerRuntime>[0],\",\n\t\t\t\t\") => createExperienceServerRuntime(options);\",\n\t\t\t\t\"\",\n\t\t\t\t`export const create${functionName}ExperienceGateway = (`,\n\t\t\t\t\"\\toptions: Parameters<typeof createExperienceGateway>[0],\",\n\t\t\t\t\") => createExperienceGateway(options);\",\n\t\t\t\t\"\",\n\t\t\t].join(\"\\n\"),\n\t\t],\n\t\t[\n\t\t\tpath.join(options.directory, \"fabric.component-pack.ts\"),\n\t\t\t[\n\t\t\t\t'import { defineComponentPack } from \"@fabricorg/component-pack\";',\n\t\t\t\t\"\",\n\t\t\t\t`export const define${functionName}ComponentPack = (artifactDigest: string) =>`,\n\t\t\t\t\"\\tdefineComponentPack({\",\n\t\t\t\t`\\t\\tname: \"${options.application}\",`,\n\t\t\t\t`\\t\\tnamespace: \"${options.application}\",`,\n\t\t\t\t'\\t\\tversion: \"0.1.0\",',\n\t\t\t\t\"\\t\\tartifactDigest,\",\n\t\t\t\t'\\t\\ttokenContract: { name: \"fabric-family\", version: \"1.0.0\" },',\n\t\t\t\t\"\\t\\tcomponents: {\",\n\t\t\t\t'\\t\\t\\tText: { module: \"./components/text.js\", roles: [\"content\"], slots: [] },',\n\t\t\t\t\"\\t\\t},\",\n\t\t\t\t\"\\t});\",\n\t\t\t\t\"\",\n\t\t\t].join(\"\\n\"),\n\t\t],\n\t\t[\n\t\t\tpath.join(options.directory, \"fabric.application.json\"),\n\t\t\t`${JSON.stringify({\n\t\t\t\tformatVersion: 1,\n\t\t\t\tapplication: options.application,\n\t\t\t\tassembly: \"./fabric.assembly.lock.json\",\n\t\t\t\truntimeCapabilities: \"./fabric.runtime.json\",\n\t\t\t\treleases: [],\n\t\t\t}, null, 2)}\\n`,\n\t\t],\n\t\t// The application config names these two files, so the scaffold has to\n\t\t// produce them. Without them `fabric-gen check-application`, the very\n\t\t// next step, failed on a missing file rather than on anything the\n\t\t// author had done. The lockfile is resolved here, not hand-written, so\n\t\t// it carries a real assembly digest from the first commit.\n\t\t[\n\t\t\tpath.join(options.directory, \"fabric.assembly.lock.json\"),\n\t\t\t`${JSON.stringify(resolveAssembly({\n\t\t\t\tmanifest: {\n\t\t\t\t\tformatVersion: 2,\n\t\t\t\t\tapplication: options.application,\n\t\t\t\t\tcapabilities: [],\n\t\t\t\t\tcomponentPacks: [],\n\t\t\t\t\tbindings: [],\n\t\t\t\t\tcontracts: [],\n\t\t\t\t},\n\t\t\t\tcapabilities: [],\n\t\t\t\tcomponentPacks: [],\n\t\t\t}).lockfile, null, 2)}\\n`,\n\t\t],\n\t\t[\n\t\t\tpath.join(options.directory, \"fabric.runtime.json\"),\n\t\t\t\"[]\\n\",\n\t\t],\n\t\t[\n\t\t\tpath.join(options.directory, \"README.md\"),\n\t\t\texperienceReadme(options.application),\n\t\t],\n\t] as const;\n\tawait mkdir(options.directory, { recursive: true });\n\tconst created: string[] = [];\n\ttry {\n\t\tfor (const [file, content] of files) {\n\t\t\tawait writeFile(file, content, { encoding: \"utf8\", flag: \"wx\" });\n\t\t\tcreated.push(file);\n\t\t}\n\t} catch (error) {\n\t\tawait Promise.all(created.map((file) => rm(file, { force: true })));\n\t\tif ((error as NodeJS.ErrnoException).code === \"EEXIST\") {\n\t\t\tthrow new Error(\"Refusing to overwrite an existing experience integration file.\");\n\t\t}\n\t\tthrow error;\n\t}\n\treturn { created };\n}\n\ninterface ApplicationCheckConfig {\n\tformatVersion: 1;\n\tassembly: string;\n\truntimeCapabilities: string;\n\treleases: string[];\n}\n\nasync function readJson(file: string): Promise<unknown> {\n\treturn JSON.parse(await readFile(file, \"utf8\"));\n}\n\nfunction assertApplicationCheckConfig(value: unknown): asserts value is ApplicationCheckConfig {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) {\n\t\tthrow new Error(\"Application check configuration must be a JSON object.\");\n\t}\n\tconst config = value as Record<string, unknown>;\n\tif (config.formatVersion !== 1) throw new Error(\"Application check configuration formatVersion must be 1.\");\n\tif (typeof config.assembly !== \"string\" || !config.assembly) {\n\t\tthrow new Error(\"Application check configuration assembly must be a file path.\");\n\t}\n\tif (typeof config.runtimeCapabilities !== \"string\" || !config.runtimeCapabilities) {\n\t\tthrow new Error(\"Application check configuration runtimeCapabilities must be a file path.\");\n\t}\n\tif (!Array.isArray(config.releases) || !config.releases.every((entry) => typeof entry === \"string\" && entry)) {\n\t\tthrow new Error(\"Application check configuration releases must be an array of file paths.\");\n\t}\n}\n\n/**\n * Verify an application's immutable composition inputs before deployment.\n * Every runtime capability must exactly match the approved lockfile, and every\n * promoted experience release must be intact and bound to that assembly.\n */\nexport async function checkApplication(\n\toptions: CheckApplicationOptions,\n): Promise<CheckApplicationResult> {\n\tconst configValue = await readJson(options.configPath);\n\tassertApplicationCheckConfig(configValue);\n\tconst base = path.dirname(options.configPath);\n\tconst resolve = (file: string): string => path.resolve(base, file);\n\tconst assembly = await readJson(resolve(configValue.assembly)) as AssemblyLockfile;\n\tassertAssemblyLockfile(assembly);\n\tconst runtimeCapabilities = await readJson(\n\t\tresolve(configValue.runtimeCapabilities),\n\t) as AvailableCapability[];\n\tif (!Array.isArray(runtimeCapabilities)) {\n\t\tthrow new Error(\"Runtime capabilities must be a JSON array.\");\n\t}\n\tassertAssemblyRuntimeCompatible(assembly, runtimeCapabilities);\n\tfor (const releasePath of configValue.releases) {\n\t\tconst release = await readJson(resolve(releasePath)) as SduiRelease;\n\t\ttry {\n\t\t\tassertSduiReleaseIntegrity(release);\n\t\t} catch (error) {\n\t\t\tthrow new Error(\n\t\t\t\t`Experience release \"${releasePath}\" is invalid: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t}\n\t\tif (release.assemblyDigest !== assembly.assemblyDigest) {\n\t\t\tthrow new Error(\n\t\t\t\t`Experience release \"${release.document.name}@${release.document.version}\" belongs to assembly \"${release.assemblyDigest}\", not \"${assembly.assemblyDigest}\".`,\n\t\t\t);\n\t\t}\n\t}\n\treturn {\n\t\tapplication: assembly.application,\n\t\tcapabilities: assembly.capabilities.length,\n\t\treleases: configValue.releases.length,\n\t\tassemblyDigest: assembly.assemblyDigest,\n\t};\n}\n\n/**\n * Create the smallest useful capability source tree. The manifest is accepted\n * by the compiler immediately, while leaving domain vocabulary to the adopter.\n */\nexport interface ExportModuleManifestFileOptions {\n\tmoduleFile: string;\n\tout: string;\n\texportName?: string;\n}\n\nexport interface ExportModuleManifestFileResult {\n\tnamespace: string;\n\texportName: string;\n\tobjectTypes: number;\n\tactions: number;\n\teventTypes: number;\n}\n\n/**\n * Turn an authored FabricModule into the normalized manifest every generator reads.\n *\n * This is the seam between the two halves of the authoring loop. The module is\n * TypeScript, so the compiler checks it as you write; the manifest is the\n * normalized JSON the code generators and the assembly compiler consume. Until\n * this command existed, nothing shipped connected them: `init capability`\n * scaffolded an empty manifest, and an author who filled it in by hand was\n * guessing at the shape of `exportModuleManifest`'s output.\n */\nexport async function exportModuleManifestFile(\n\toptions: ExportModuleManifestFileOptions,\n): Promise<ExportModuleManifestFileResult> {\n\tconst absolute = path.resolve(options.moduleFile);\n\tlet loaded: Record<string, unknown>;\n\ttry {\n\t\tloaded = (await import(pathToFileURL(absolute).href)) as Record<string, unknown>;\n\t} catch (error) {\n\t\tconst reason = error instanceof Error ? error.message : String(error);\n\t\tthrow new Error(`Could not load module file \"${options.moduleFile}\": ${reason}\\nA TypeScript file needs a runtime that strips types (Node 22.18 or newer); otherwise point --module at the built JavaScript.`);\n\t}\n\tconst candidates = Object.entries(loaded).filter(([, value]) => isFabricModuleLike(value));\n\tlet entry: [string, unknown] | undefined;\n\tif (options.exportName) {\n\t\tconst named = loaded[options.exportName];\n\t\tif (named === undefined) throw new Error(`\"${options.moduleFile}\" has no export named \"${options.exportName}\". It exports: ${Object.keys(loaded).join(\", \") || \"nothing\"}.`);\n\t\tif (!isFabricModuleLike(named)) throw new Error(`Export \"${options.exportName}\" of \"${options.moduleFile}\" is not a FabricModule: it has no string \"namespace\".`);\n\t\tentry = [options.exportName, named];\n\t} else if (candidates.length === 1) {\n\t\tentry = candidates[0];\n\t} else if (candidates.length === 0) {\n\t\tthrow new Error(`\"${options.moduleFile}\" exports no FabricModule. Export one, with a string \"namespace\", or name it with --export.`);\n\t} else {\n\t\tthrow new Error(`\"${options.moduleFile}\" exports ${candidates.length} modules (${candidates.map(([name]) => name).join(\", \")}). Choose one with --export.`);\n\t}\n\tconst manifest = exportModuleManifest(entry[1] as Parameters<typeof exportModuleManifest>[0]);\n\t// Compile it here so the author learns about a bad field from this command,\n\t// standing in their own module, rather than from a generator two steps later.\n\tcompileManifestBundle({ manifestVersion: 2, modules: [manifest] });\n\tawait mkdir(path.dirname(path.resolve(options.out)), { recursive: true });\n\tawait writeFile(path.resolve(options.out), `${JSON.stringify(manifest, null, 2)}\\n`, \"utf8\");\n\treturn {\n\t\tnamespace: manifest.namespace,\n\t\texportName: entry[0],\n\t\tobjectTypes: manifest.objectTypes.length,\n\t\tactions: manifest.actions.length,\n\t\teventTypes: manifest.eventTypes.length,\n\t};\n}\n\nfunction isFabricModuleLike(value: unknown): boolean {\n\treturn typeof value === \"object\" && value !== null && typeof (value as { namespace?: unknown }).namespace === \"string\";\n}\n\nexport async function initializeCapability(\n\toptions: InitializeCapabilityOptions,\n): Promise<InitializeCapabilityResult> {\n\tif (!/^[a-z][a-z0-9-]*$/.test(options.namespace)) {\n\t\tthrow new Error(\"Capability namespace must use lowercase letters, numbers, and hyphens.\");\n\t}\n\tconst displayName = options.namespace\n\t\t.split(\"-\")\n\t\t.map((part, index) => index === 0\n\t\t\t? `${part.charAt(0).toUpperCase()}${part.slice(1)}`\n\t\t\t: part)\n\t\t.join(\" \");\n\tconst modulePath = path.join(options.directory, \"module.ts\");\n\tconst readmePath = path.join(options.directory, \"README.md\");\n\tfor (const file of [readmePath, modulePath]) {\n\t\ttry {\n\t\t\tawait access(file);\n\t\t\tthrow new Error(`Refusing to overwrite existing file \"${file}\".`);\n\t\t} catch (error) {\n\t\t\tif (error instanceof Error && error.message.startsWith(\"Refusing to overwrite\")) throw error;\n\t\t\tif ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n\t\t}\n\t}\n\t// The scaffold is a working module, not an empty shell. An empty manifest\n\t// teaches nothing about the shape it has to reach, and a manifest authored\n\t// by hand is a guess at the output of exportModuleManifest(). The module is\n\t// the source; `fabric-gen export` produces the manifest from it.\n\tconst module = [\n\t\t`import type { ActionDefinition } from \"@fabricorg/platform/actions\";`,\n\t\t`import type { FabricModule } from \"@fabricorg/platform/modules\";`,\n\t\t\"\",\n\t\t`/** One governed action. Every field below is checked when the manifest is exported. */`,\n\t\t`const recordExample: ActionDefinition = {`,\n\t\t`\\tactionId: \"${options.namespace}.record_example\",`,\n\t\t`\\tnamespace: \"${options.namespace}\",`,\n\t\t\"\\tversion: 1,\",\n\t\t'\\tkind: \"atomic\",',\n\t\t\"\\tidempotent: true,\",\n\t\t\"\\tmutatesDomain: true,\",\n\t\t'\\temitsEvents: [\"ExampleRecorded\"],',\n\t\t\"\\t// The six execution dimensions. A strict certification profile requires all of them.\",\n\t\t\"\\texecution: {\",\n\t\t'\\t\\tconnectivity: \"online-required\",',\n\t\t'\\t\\tauthorityMoment: \"execution\",',\n\t\t'\\t\\tidempotency: \"required\",',\n\t\t'\\t\\tcompletion: \"immediate\",',\n\t\t'\\t\\tconsistency: \"authoritative-now\",',\n\t\t'\\t\\tsensitivity: \"internal\",',\n\t\t\"\\t},\",\n\t\t\"\\tschema: {\",\n\t\t\"\\t\\tparse(value: unknown): { exampleId: string } {\",\n\t\t\"\\t\\t\\tconst input = value as { exampleId?: unknown };\",\n\t\t'\\t\\t\\tif (typeof input?.exampleId !== \"string\") throw new Error(\"exampleId is required\");',\n\t\t\"\\t\\t\\treturn { exampleId: input.exampleId };\",\n\t\t\"\\t\\t},\",\n\t\t\"\\t\\tsafeParse(value: unknown) {\",\n\t\t\"\\t\\t\\ttry {\",\n\t\t\"\\t\\t\\t\\treturn { success: true as const, data: this.parse(value) };\",\n\t\t\"\\t\\t\\t} catch (error) {\",\n\t\t'\\t\\t\\t\\treturn { success: false as const, error: { issues: [{ path: [\"exampleId\"], message: error instanceof Error ? error.message : String(error) }] } };',\n\t\t\"\\t\\t\\t}\",\n\t\t\"\\t\\t},\",\n\t\t\"\\t},\",\n\t\t\"\\thandler: async (_context, parameters) => ({\",\n\t\t\"\\t\\tsuccess: true,\",\n\t\t\"\\t\\tdata: {\",\n\t\t\"\\t\\t\\t...(parameters as { exampleId: string }),\",\n\t\t\"\\t\\t\\t_events: [{\",\n\t\t'\\t\\t\\t\\teventType: \"ExampleRecorded\",',\n\t\t\"\\t\\t\\t\\tentityType: \\\"Example\\\",\",\n\t\t\"\\t\\t\\t\\tentityId: (parameters as { exampleId: string }).exampleId,\",\n\t\t\"\\t\\t\\t\\tpayload: parameters,\",\n\t\t\"\\t\\t\\t}],\",\n\t\t\"\\t\\t},\",\n\t\t\"\\t}),\",\n\t\t\"};\",\n\t\t\"\",\n\t\t`export const ${camelCase(options.namespace)}Module: FabricModule = {`,\n\t\t`\\tnamespace: \"${options.namespace}\",`,\n\t\t'\\tversion: \"0.1.0\",',\n\t\t\"\\tcapability: {\",\n\t\t`\\t\\tdisplayName: \"${displayName}\",`,\n\t\t`\\t\\tdescription: \"Governed ${displayName.toLowerCase()} capability.\",`,\n\t\t'\\t\\tstability: \"experimental\",',\n\t\t\"\\t},\",\n\t\t\"\\tobjectTypes: [{\",\n\t\t'\\t\\ttype: \"Example\",',\n\t\t\"\\t\\tschema: {\",\n\t\t'\\t\\t\\ttype: \"object\",',\n\t\t'\\t\\t\\tproperties: { exampleId: { type: \"string\" } },',\n\t\t'\\t\\t\\trequired: [\"exampleId\"],',\n\t\t\"\\t\\t},\",\n\t\t\"\\t}],\",\n\t\t`\\tidPrefixes: [{ prefix: \"exm\", name: \"Example\", module: \"${options.namespace}\" }],`,\n\t\t'\\teventTypes: [{ eventType: \"ExampleRecorded\", schemaVersion: 1 }],',\n\t\t\"\\tactions: [recordExample],\",\n\t\t\"};\",\n\t\t\"\",\n\t].join(\"\\n\");\n\tconst readme = [\n\t\t`# ${displayName}`,\n\t\t\"\",\n\t\t\"`module.ts` is the source of truth. It is TypeScript, so the shape of every\",\n\t\t\"action, object type, and event is checked as you write it.\",\n\t\t\"\",\n\t\t\"## The loop\",\n\t\t\"\",\n\t\t\"```bash\",\n\t\t\"# 1. Export the authored module to the normalized manifest the generators read.\",\n\t\t\"fabric-gen export --module module.ts --out fabric.manifest.json\",\n\t\t\"\",\n\t\t\"# 2. Generate types, event contracts, the usage contract, and docs.\",\n\t\t\"fabric-gen --input fabric.manifest.json --out generated\",\n\t\t\"\",\n\t\t\"# 3. In CI, prove the generated files match the manifest.\",\n\t\t\"fabric-gen --input fabric.manifest.json --out generated --check\",\n\t\t\"```\",\n\t\t\"\",\n\t\t\"Commit both `fabric.manifest.json` and `generated/`. The manifest is the\",\n\t\t\"contract other capabilities and applications compile against; regenerating\",\n\t\t\"is how a consumer learns what changed.\",\n\t\t\"\",\n\t\t\"## What to edit\",\n\t\t\"\",\n\t\t\"- **Object types** carry a portable JSON Schema. They become generated TypeScript types.\",\n\t\t\"- **Actions** declare six execution dimensions. A host refuses an action whose\",\n\t\t\" declaration does not match how it is invoked, so declare them honestly.\",\n\t\t\"- **Events** are the capability's public vocabulary. Adding a field is compatible;\",\n\t\t\" removing or retyping one is not.\",\n\t\t\"\",\n\t].join(\"\\n\");\n\tawait mkdir(options.directory, { recursive: true });\n\tconst created: string[] = [];\n\ttry {\n\t\tfor (const [file, content] of [\n\t\t\t[readmePath, readme],\n\t\t\t[modulePath, module],\n\t\t] as const) {\n\t\t\tawait writeFile(file, content, { encoding: \"utf8\", flag: \"wx\" });\n\t\t\tcreated.push(file);\n\t\t}\n\t} catch (error) {\n\t\tawait Promise.all(created.map((file) => rm(file, { force: true })));\n\t\tif ((error as NodeJS.ErrnoException).code === \"EEXIST\") {\n\t\t\tthrow new Error(\"Refusing to overwrite a file created during capability initialization.\");\n\t\t}\n\t\tthrow error;\n\t}\n\treturn { created };\n}\n\nfunction camelCase(namespace: string): string {\n\treturn namespace.split(\"-\").map((part, index) => index === 0 ? part : `${part.charAt(0).toUpperCase()}${part.slice(1)}`).join(\"\");\n}\n\nexport async function generateFromManifest(options: GenerateOptions): Promise<GenerateResult> {\n\tconst input = JSON.parse(await readFile(options.inputPath, \"utf8\"));\n\tif (!input || typeof input !== \"object\" || Array.isArray(input)) throw new Error(\"Manifest input must be a JSON object.\");\n\tconst bundle = \"modules\" in input ? input : { manifestVersion: input.manifestVersion, modules: [input] };\n\tconst ir = compileManifestBundle(bundle);\n\tconst files = (await Promise.all(options.targets.map(async (name) => {\n\t\tconst target = GENERATOR_TARGETS[name];\n\t\tif (!target) throw new Error(`Unknown generator target \"${name}\".`);\n\t\treturn (await runGenerator(target, ir)).map((file) => ({ ...file, path: `${name}/${file.path}` }));\n\t}))).flat().sort((left, right) => compareCanonicalStrings(left.path, right.path));\n\tconst expected = new Set(files.map((file) => file.path));\n\tconst existing = await listFiles(options.outputDirectory);\n\tconst selectedPrefixes = options.targets.map((target) => `${target}/`);\n\tconst stale = existing.filter((file) => selectedPrefixes.some((prefix) => file.startsWith(prefix)) && !expected.has(file));\n\tif (!options.check) await Promise.all(stale.map((file) => rm(path.join(options.outputDirectory, file), { force: true })));\n\tconst changed: string[] = [];\n\tfor (const file of files) {\n\t\tconst target = path.join(options.outputDirectory, file.path);\n\t\tlet current: string | undefined;\n\t\ttry { current = await readFile(target, \"utf8\"); } catch { current = undefined; }\n\t\tif (current !== file.content) {\n\t\t\tchanged.push(file.path);\n\t\t\tif (!options.check) { await mkdir(path.dirname(target), { recursive: true }); await writeFile(target, file.content, \"utf8\"); }\n\t\t}\n\t}\n\tif (options.check && (changed.length || stale.length)) throw new Error(`Generated artifacts drifted: ${[...changed, ...stale.map((file) => `stale:${file}`)].join(\", \")}`);\n\treturn { changed, stale, files };\n}\n\nasync function listFiles(directory: string, prefix = \"\"): Promise<string[]> {\n\tlet entries;\n\ttry { entries = await readdir(directory, { withFileTypes: true }); } catch { return []; }\n\tconst nested = await Promise.all(entries.map((entry) => entry.isDirectory() ? listFiles(path.join(directory, entry.name), `${prefix}${entry.name}/`) : [`${prefix}${entry.name}`]));\n\treturn nested.flat().sort();\n}\n\ninterface ExperiencePromotionConfig {\n\tformatVersion: 1;\n\tapplication: string;\n\tissuer: string;\n\tkeyId: string;\n\tassembly: string;\n\trelease: string;\n\tcontracts: string[];\n}\n\nfunction assertExperiencePromotionConfig(value: unknown): asserts value is ExperiencePromotionConfig {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) {\n\t\tthrow new Error(\"Experience promotion configuration must be a JSON object.\");\n\t}\n\tconst config = value as Record<string, unknown>;\n\tif (config.formatVersion !== 1) throw new Error(\"Experience promotion configuration formatVersion must be 1.\");\n\tfor (const field of [\"application\", \"issuer\", \"keyId\", \"assembly\", \"release\"] as const) {\n\t\tif (typeof config[field] !== \"string\" || !config[field]) {\n\t\t\tthrow new Error(`Experience promotion configuration ${field} must be a non-empty string.`);\n\t\t}\n\t}\n\t// The application name is interpolated into the default output path and\n\t// signed into the release body, so \"../../x\" would escape the configuration\n\t// directory and \"/etc/x\" would ignore it entirely.\n\tif (!/^[a-z][a-z0-9-]*$/.test(config.application as string)) {\n\t\tthrow new Error(\"Experience promotion configuration application must be lowercase letters, numbers, and hyphens.\");\n\t}\n\tif (!Array.isArray(config.contracts) || !config.contracts.every((entry) => typeof entry === \"string\" && entry)) {\n\t\tthrow new Error(\"Experience promotion configuration contracts must be an array of file paths.\");\n\t}\n\t// A signing key in a checked-in configuration file is a key in version\n\t// control. Enumerating two spellings only catches two spellings, so reject\n\t// anything that reads like one, and reject unknown fields so a future\n\t// spelling cannot arrive unnoticed.\n\tconst known = new Set([\"formatVersion\", \"application\", \"issuer\", \"keyId\", \"assembly\", \"release\", \"contracts\"]);\n\tfor (const field of Object.keys(config)) {\n\t\tif (/key|secret|credential|token|pem|password/i.test(field) && field !== \"keyId\") {\n\t\t\tthrow new Error(`Experience promotion configuration must not carry \"${field}\"; pass the signing key with --key.`);\n\t\t}\n\t\tif (!known.has(field)) {\n\t\t\tthrow new Error(`Experience promotion configuration has an unknown field \"${field}\".`);\n\t\t}\n\t}\n}\n\n/**\n * Turn a validated release into a signed one.\n *\n * Promotion is where a granted `capability://` reference becomes a concrete\n * action id and version, so it is also where that mapping has to be bound to\n * the assembly that approved it. The signing key is a command-line argument\n * rather than a configuration field, because a configuration file is the kind\n * of thing that ends up committed.\n */\nexport async function promoteExperience(\n\toptions: PromoteExperienceOptions,\n): Promise<PromoteExperienceResult> {\n\tconst configValue = await readJson(options.configPath);\n\tassertExperiencePromotionConfig(configValue);\n\tconst base = path.dirname(options.configPath);\n\tconst resolve = (file: string): string => path.resolve(base, file);\n\n\tconst assembly = await readJson(resolve(configValue.assembly)) as AssemblyLockfile;\n\tassertAssemblyLockfile(assembly);\n\tconst release = await readJson(resolve(configValue.release)) as SduiRelease;\n\tassertSduiReleaseIntegrity(release);\n\tconst contracts = await Promise.all(\n\t\tconfigValue.contracts.map(async (file) => await readJson(resolve(file)) as UsageContractDocument),\n\t);\n\n\tconst privateKey = createPrivateKey(await readFile(options.privateKeyPath, \"utf8\"));\n\tconst promoted = await promoteExperienceRelease({\n\t\tapplication: configValue.application,\n\t\trelease,\n\t\tcontracts,\n\t\tassembly,\n\t\tissuer: configValue.issuer,\n\t\tsigner: createEs256ReleaseSigner({ keyId: configValue.keyId, privateKey }),\n\t});\n\n\tconst outputPath = options.outputPath\n\t\t? path.resolve(options.outputPath)\n\t\t: resolve(`${configValue.application}.experience-release.jws`);\n\tawait mkdir(path.dirname(outputPath), { recursive: true });\n\tawait writeFile(outputPath, `${promoted.compactJws}\\n`, \"utf8\");\n\n\treturn {\n\t\tapplication: configValue.application,\n\t\treleaseDigest: release.releaseDigest,\n\t\tassemblyDigest: assembly.assemblyDigest,\n\t\troutes: {\n\t\t\tviews: promoted.release.routes.views.length,\n\t\t\tintents: promoted.release.routes.intents.length,\n\t\t},\n\t\toutputPath,\n\t};\n}\n"],"mappings":";AAAA,SAAS,QAAQ,OAAO,UAAU,SAAS,IAAI,iBAAiB;AAChE,SAAS,wBAAwB;AACjC,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB,oBAA8D;AAC9F,SAAS,4BAA4B;AACrC,SAAS,2BAA2B;AACpC,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB;AAChC,SAAS,sBAAsB;AAC/B,SAAS,uBAAuB;AAChC,SAAS,wBAAwB;AACjC,SAAS,qBAAqB;AAE9B,SAAS,0BAA0B,gCAAgC;AACnE,SAAS,4BAA4B;AACrC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAGM;AACP;AAAA,EACC;AAAA,OAEM;AAEA,IAAM,oBAAqD;AAAA,EACjE,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,MAAM;AAAA,EACN,aAAa;AACd;AACA,IAAM,0BAA0B,CAAC,MAAc,UAA0B,OAAO,QAAQ,KAAK,OAAO,QAAQ,IAAI;AA6BhH,IAAM,QAAQ;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,EAAE,KAAK,IAAI;AAEJ,IAAM,sBAAN,cAAkC,MAAM;AAAA,EAC5B,OAAO;AAC1B;AAEO,SAAS,qBAAqB,OAAwB;AAC5D,SAAO,iBAAiB,sBAAsB,IAAI;AACnD;AAEA,SAAS,UAAU,MAAyB,MAAkC;AAC7E,QAAM,QAAQ,KAAK,QAAQ,IAAI;AAC/B,MAAI,QAAQ,EAAG,QAAO;AACtB,QAAM,QAAQ,KAAK,QAAQ,CAAC;AAC5B,MAAI,CAAC,SAAS,MAAM,WAAW,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