@milehimikey/em 1.9.1 → 1.11.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.
Files changed (125) hide show
  1. package/.claude/skills/event-modeling/SKILL.md +1 -1
  2. package/.claude/skills/event-modeling-conform/SKILL.md +5 -1
  3. package/.claude/skills/event-modeling-design/SKILL.md +31 -12
  4. package/.claude/skills/event-modeling-discover/SKILL.md +1 -1
  5. package/.claude/skills/event-modeling-implement/SKILL.md +14 -3
  6. package/.claude/skills/event-modeling-implement/reference/implement.md +73 -6
  7. package/.claude/skills/event-modeling-review/SKILL.md +14 -3
  8. package/.claude/skills/event-modeling-shared/reference/em-dsl.md +110 -11
  9. package/.claude/skills/event-modeling-shared/reference/slice-doc-schema.md +4 -1
  10. package/.claude/skills/event-modeling-shared/templates/constitution.md +111 -0
  11. package/.claude/skills/event-modeling-shared/templates/model-readme.md +2 -2
  12. package/.claude/skills/event-modeling-shared/templates/slice.md +4 -0
  13. package/README.md +8 -1
  14. package/dist/catalog/docJoin.d.ts +8 -0
  15. package/dist/catalog/docJoin.js +4 -0
  16. package/dist/catalog/docJoin.js.map +1 -1
  17. package/dist/catalog/sliceDoc.d.ts +8 -0
  18. package/dist/catalog/sliceDoc.js +2 -0
  19. package/dist/catalog/sliceDoc.js.map +1 -1
  20. package/dist/cli/ciInit.d.ts +10 -3
  21. package/dist/cli/ciInit.js +22 -14
  22. package/dist/cli/ciInit.js.map +1 -1
  23. package/dist/cli/ledgerCheck.d.ts +72 -0
  24. package/dist/cli/ledgerCheck.js +122 -1
  25. package/dist/cli/ledgerCheck.js.map +1 -1
  26. package/dist/cli/ratify.d.ts +37 -5
  27. package/dist/cli/ratify.js +106 -9
  28. package/dist/cli/ratify.js.map +1 -1
  29. package/dist/cli/reratify.js +14 -5
  30. package/dist/cli/reratify.js.map +1 -1
  31. package/dist/cli/review.d.ts +38 -0
  32. package/dist/cli/review.js +160 -0
  33. package/dist/cli/review.js.map +1 -0
  34. package/dist/cli/sliceIndex.d.ts +3 -0
  35. package/dist/cli/sliceIndex.js +5 -4
  36. package/dist/cli/sliceIndex.js.map +1 -1
  37. package/dist/cli/stateFile.d.ts +10 -0
  38. package/dist/cli/stateFile.js +14 -0
  39. package/dist/cli/stateFile.js.map +1 -1
  40. package/dist/cli/status.d.ts +44 -3
  41. package/dist/cli/status.js +75 -18
  42. package/dist/cli/status.js.map +1 -1
  43. package/dist/cli/systemInputs.d.ts +34 -0
  44. package/dist/cli/systemInputs.js +129 -0
  45. package/dist/cli/systemInputs.js.map +1 -0
  46. package/dist/cli.js +362 -23
  47. package/dist/cli.js.map +1 -1
  48. package/dist/emit/freshnessJson.d.ts +1 -1
  49. package/dist/emit/freshnessJson.js +5 -1
  50. package/dist/emit/freshnessJson.js.map +1 -1
  51. package/dist/emit/json.d.ts +37 -1
  52. package/dist/emit/json.js +67 -1
  53. package/dist/emit/json.js.map +1 -1
  54. package/dist/emit/ledgerJson.d.ts +1 -1
  55. package/dist/emit/ledgerJson.js +6 -1
  56. package/dist/emit/ledgerJson.js.map +1 -1
  57. package/dist/emit/queryJson.d.ts +6 -0
  58. package/dist/emit/queryJson.js +33 -0
  59. package/dist/emit/queryJson.js.map +1 -0
  60. package/dist/emit/statusJson.d.ts +1 -1
  61. package/dist/emit/statusJson.js +5 -1
  62. package/dist/emit/statusJson.js.map +1 -1
  63. package/dist/emit/systemJson.d.ts +8 -0
  64. package/dist/emit/systemJson.js +38 -0
  65. package/dist/emit/systemJson.js.map +1 -0
  66. package/dist/mcp/server.d.ts +1 -1
  67. package/dist/mcp/server.js +195 -9
  68. package/dist/mcp/server.js.map +1 -1
  69. package/dist/model/edges.d.ts +28 -1
  70. package/dist/model/edges.js +77 -15
  71. package/dist/model/edges.js.map +1 -1
  72. package/dist/model/model.d.ts +6 -0
  73. package/dist/model/model.js +2 -0
  74. package/dist/model/model.js.map +1 -1
  75. package/dist/model/qualifiedRef.d.ts +47 -0
  76. package/dist/model/qualifiedRef.js +100 -0
  77. package/dist/model/qualifiedRef.js.map +1 -0
  78. package/dist/model/queryIndex.d.ts +53 -0
  79. package/dist/model/queryIndex.js +114 -0
  80. package/dist/model/queryIndex.js.map +1 -0
  81. package/dist/model/rules.d.ts +88 -0
  82. package/dist/model/rules.js +101 -0
  83. package/dist/model/rules.js.map +1 -1
  84. package/dist/model/sliceDocIndex.d.ts +30 -0
  85. package/dist/model/sliceDocIndex.js +110 -0
  86. package/dist/model/sliceDocIndex.js.map +1 -0
  87. package/dist/model/validate.js +85 -11
  88. package/dist/model/validate.js.map +1 -1
  89. package/dist/parser/ast.d.ts +25 -0
  90. package/dist/parser/parser.d.ts +2 -0
  91. package/dist/parser/parser.js +104 -34
  92. package/dist/parser/parser.js.map +1 -1
  93. package/dist/query/format.d.ts +8 -0
  94. package/dist/query/format.js +80 -0
  95. package/dist/query/format.js.map +1 -0
  96. package/dist/query/pipeline.d.ts +17 -0
  97. package/dist/query/pipeline.js +38 -0
  98. package/dist/query/pipeline.js.map +1 -0
  99. package/dist/query/system.d.ts +60 -0
  100. package/dist/query/system.js +87 -0
  101. package/dist/query/system.js.map +1 -0
  102. package/dist/query/verbs.d.ts +100 -0
  103. package/dist/query/verbs.js +306 -0
  104. package/dist/query/verbs.js.map +1 -0
  105. package/dist/render/drawEdges.js +15 -4
  106. package/dist/render/drawEdges.js.map +1 -1
  107. package/dist/render/drawNotes.d.ts +13 -3
  108. package/dist/render/drawNotes.js +96 -20
  109. package/dist/render/drawNotes.js.map +1 -1
  110. package/dist/render/render.js +6 -5
  111. package/dist/render/render.js.map +1 -1
  112. package/dist/render/sliceDiagram.js +1 -0
  113. package/dist/render/sliceDiagram.js.map +1 -1
  114. package/dist/system/manifest.d.ts +45 -0
  115. package/dist/system/manifest.js +178 -0
  116. package/dist/system/manifest.js.map +1 -0
  117. package/dist/system/verify.d.ts +88 -0
  118. package/dist/system/verify.js +263 -0
  119. package/dist/system/verify.js.map +1 -0
  120. package/dist/templates.d.ts +14 -1
  121. package/dist/templates.js +134 -5
  122. package/dist/templates.js.map +1 -1
  123. package/dist/util/slug.js +16 -10
  124. package/dist/util/slug.js.map +1 -1
  125. package/package.json +10 -1
@@ -0,0 +1,178 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Parses a seam manifest (`system.yaml`, MIL-194) into a plain, validated shape — the declared
3
+ // list of models in a system plus the seams binding one model's `public` event/view to another
4
+ // model's reaction. This is the one place the manifest's own schema is enforced; everything
5
+ // downstream (src/system/verify.ts) trusts the returned `SystemManifest`.
6
+ //
7
+ // YAML because the manifest is human-authored (and JSON is a YAML subset, so a `.json` manifest
8
+ // parses here unchanged). Pure: text in, manifest + diagnostics out — the caller (src/cli/
9
+ // systemInputs.ts) owns reading the file and resolving each model's `source` path, so this
10
+ // module never touches the filesystem. Line numbers come from the YAML parser's own
11
+ // `LineCounter`, so a shape error points at the offending entry, not just "the manifest".
12
+ import { LineCounter, parseDocument, isMap, isSeq, isScalar } from "yaml";
13
+ import { pushDiag } from "../model/rules.js";
14
+ /** The only manifest schema version accepted (`systemSchemaVersion`). Bumped, with a range
15
+ * check here, the day the manifest's shape changes incompatibly. */
16
+ export const SYSTEM_MANIFEST_SCHEMA_VERSION = "1.0";
17
+ const TOP_KEYS = new Set(["systemSchemaVersion", "name", "models", "seams"]);
18
+ const MODEL_KEYS = new Set(["source", "owner"]);
19
+ const SEAM_KEYS = new Set(["from", "to", "description"]);
20
+ /** Parse and shape-check manifest text. Every problem is a `system-manifest-invalid` error
21
+ * diagnostic (never a throw), and `ok: false` means the manifest can't be used at all — the
22
+ * caller refuses rather than verifying a partial system. Unknown keys are errors, not ignored:
23
+ * a misspelled `seam:` silently declaring zero seams would defeat the whole check. */
24
+ export function parseManifest(text) {
25
+ const diagnostics = [];
26
+ const lineCounter = new LineCounter();
27
+ const doc = parseDocument(text, { lineCounter, prettyErrors: false });
28
+ const lineOf = (node) => {
29
+ const range = node && "range" in node ? node.range : isPairLike(node) ? node.key?.range : undefined;
30
+ return range ? lineCounter.linePos(range[0]).line : undefined;
31
+ };
32
+ const invalid = (message, line) => pushDiag(diagnostics, "system-manifest-invalid", { message, line });
33
+ if (doc.errors.length > 0) {
34
+ for (const e of doc.errors) {
35
+ const line = e.linePos?.[0]?.line;
36
+ invalid(`YAML parse error: ${e.message.trim()}`, line);
37
+ }
38
+ return { ok: false, diagnostics };
39
+ }
40
+ const root = doc.contents;
41
+ if (!isMap(root)) {
42
+ invalid("manifest must be a YAML mapping with `systemSchemaVersion`, `models`, and optionally `name`/`seams`");
43
+ return { ok: false, diagnostics };
44
+ }
45
+ for (const pair of root.items) {
46
+ const key = scalarString(pair.key);
47
+ if (key === undefined || !TOP_KEYS.has(key)) {
48
+ invalid(`unknown top-level key ${describeKey(pair.key)} — expected one of: ${[...TOP_KEYS].join(", ")}`, lineOf(pair));
49
+ }
50
+ }
51
+ // systemSchemaVersion — required, and exactly the one version this em understands.
52
+ const versionNode = root.get("systemSchemaVersion", true);
53
+ const version = scalarString(versionNode);
54
+ if (version === undefined) {
55
+ invalid(`missing or non-string \`systemSchemaVersion\` — set \`systemSchemaVersion: "${SYSTEM_MANIFEST_SCHEMA_VERSION}"\``, lineOf(versionNode));
56
+ }
57
+ else if (version !== SYSTEM_MANIFEST_SCHEMA_VERSION) {
58
+ invalid(`unsupported systemSchemaVersion "${version}" — this em accepts "${SYSTEM_MANIFEST_SCHEMA_VERSION}"`, lineOf(versionNode));
59
+ }
60
+ // name — optional string.
61
+ const nameNode = root.get("name", true);
62
+ let name = null;
63
+ if (nameNode !== undefined) {
64
+ const n = scalarString(nameNode);
65
+ if (n === undefined)
66
+ invalid("`name` must be a string", lineOf(nameNode));
67
+ else
68
+ name = n;
69
+ }
70
+ // models — required mapping, ≥ 1 entry, each `{ source, owner? }`.
71
+ const models = [];
72
+ const modelsNode = root.get("models", true);
73
+ if (!isMap(modelsNode)) {
74
+ invalid("`models` must be a mapping of model key -> { source, owner? } with at least one entry", lineOf(modelsNode ?? root));
75
+ }
76
+ else if (modelsNode.items.length === 0) {
77
+ invalid("`models` must declare at least one model", lineOf(modelsNode));
78
+ }
79
+ else {
80
+ for (const pair of modelsNode.items) {
81
+ const key = scalarString(pair.key);
82
+ const line = lineOf(pair) ?? lineOf(modelsNode);
83
+ if (key === undefined || key.trim() === "") {
84
+ invalid(`model key ${describeKey(pair.key)} must be a non-empty string`, line);
85
+ continue;
86
+ }
87
+ const entry = pair.value;
88
+ if (!isMap(entry)) {
89
+ invalid(`model "${key}" must be a mapping with a \`source\` (a .em file or an \`em export --json\` document)`, line);
90
+ continue;
91
+ }
92
+ for (const p of entry.items) {
93
+ const k = scalarString(p.key);
94
+ if (k === undefined || !MODEL_KEYS.has(k))
95
+ invalid(`model "${key}": unknown key ${describeKey(p.key)} — expected source, owner`, lineOf(p));
96
+ }
97
+ const source = scalarString(entry.get("source", true));
98
+ if (source === undefined || source.trim() === "") {
99
+ invalid(`model "${key}": \`source\` must be a non-empty path string`, line);
100
+ continue;
101
+ }
102
+ const ownerNode = entry.get("owner", true);
103
+ let owner = null;
104
+ if (ownerNode !== undefined) {
105
+ const o = scalarString(ownerNode);
106
+ if (o === undefined)
107
+ invalid(`model "${key}": \`owner\` must be a string`, lineOf(ownerNode));
108
+ else
109
+ owner = o;
110
+ }
111
+ models.push({ key, source, owner, line: line ?? 1 });
112
+ }
113
+ }
114
+ // seams — optional sequence of `{ from, to, description? }`.
115
+ const seams = [];
116
+ const seamsNode = root.get("seams", true);
117
+ if (seamsNode !== undefined && !(isScalar(seamsNode) && seamsNode.value === null)) {
118
+ if (!isSeq(seamsNode)) {
119
+ invalid("`seams` must be a list of { from, to, description? } entries", lineOf(seamsNode));
120
+ }
121
+ else {
122
+ seamsNode.items.forEach((item, i) => {
123
+ const line = lineOf(item) ?? lineOf(seamsNode);
124
+ if (!isMap(item)) {
125
+ invalid(`seams[${i}] must be a mapping with \`from\` and \`to\``, line);
126
+ return;
127
+ }
128
+ for (const p of item.items) {
129
+ const k = scalarString(p.key);
130
+ if (k === undefined || !SEAM_KEYS.has(k))
131
+ invalid(`seams[${i}]: unknown key ${describeKey(p.key)} — expected from, to, description`, lineOf(p));
132
+ }
133
+ const from = scalarString(item.get("from", true));
134
+ const to = scalarString(item.get("to", true));
135
+ if (from === undefined || from.trim() === "")
136
+ invalid(`seams[${i}]: \`from\` must be a qualified ref string (<modelKey>:<sliceKey>/<kind>.<slug>)`, line);
137
+ if (to === undefined || to.trim() === "")
138
+ invalid(`seams[${i}]: \`to\` must be a qualified ref string (<modelKey>:<sliceKey>/<kind>.<slug>, or <modelKey>:<sliceKey>)`, line);
139
+ const descNode = item.get("description", true);
140
+ let description = null;
141
+ if (descNode !== undefined && !(isScalar(descNode) && descNode.value === null)) {
142
+ const d = scalarString(descNode);
143
+ if (d === undefined)
144
+ invalid(`seams[${i}]: \`description\` must be a string`, lineOf(descNode));
145
+ else
146
+ description = d;
147
+ }
148
+ if (from !== undefined && from.trim() !== "" && to !== undefined && to.trim() !== "") {
149
+ seams.push({ from: from.trim(), to: to.trim(), description, line: line ?? 1 });
150
+ }
151
+ });
152
+ }
153
+ }
154
+ if (diagnostics.length > 0)
155
+ return { ok: false, diagnostics };
156
+ return {
157
+ ok: true,
158
+ manifest: { systemSchemaVersion: version, name, models, seams },
159
+ diagnostics,
160
+ };
161
+ }
162
+ function isPairLike(node) {
163
+ return typeof node === "object" && node !== null && "key" in node && "value" in node && !("range" in node);
164
+ }
165
+ /** A scalar node's value as a string — `undefined` for a missing node, a non-scalar, or a
166
+ * non-string scalar (numbers/booleans/null are never accepted where a string is required, so
167
+ * `systemSchemaVersion: 1.0` — a YAML float — is rejected, not silently coerced). */
168
+ function scalarString(node) {
169
+ if (!isScalar(node))
170
+ return undefined;
171
+ return typeof node.value === "string" ? node.value : undefined;
172
+ }
173
+ function describeKey(node) {
174
+ if (isScalar(node))
175
+ return `"${String(node.value)}"`;
176
+ return "(non-scalar key)";
177
+ }
178
+ //# sourceMappingURL=manifest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manif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CAAC,SAAS,CAAC;AACjE,CAAC;AAED,SAAS,WAAW,CAAC,IAAa;IAChC,IAAI,QAAQ,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;IACrD,OAAO,kBAAkB,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,88 @@
1
+ import { ElementKind } from "../parser/ast.js";
2
+ import type { Diagnostic } from "../model/validate.js";
3
+ import type { SystemManifest } from "./manifest.js";
4
+ /** The subset of one `em export --json` document `verifySystem` reads. */
5
+ export interface SystemExportElement {
6
+ ref: string;
7
+ kind: ElementKind;
8
+ name: string;
9
+ line: number;
10
+ public: boolean;
11
+ }
12
+ export interface SystemExportSlice {
13
+ key: string;
14
+ name: string;
15
+ elements: SystemExportElement[];
16
+ }
17
+ export interface SystemExportDoc {
18
+ schemaVersion: string;
19
+ model: {
20
+ key: string;
21
+ name: string | null;
22
+ slices: SystemExportSlice[];
23
+ edges: {
24
+ from: string;
25
+ to: string;
26
+ }[];
27
+ };
28
+ }
29
+ export type SystemSourceKind = "em" | "export";
30
+ /** One model, loaded by the caller: the manifest's entry plus its export document and the
31
+ * path diagnostics about it should point at (the `.em` file, or the export `.json`). */
32
+ export interface SystemModelInput {
33
+ key: string;
34
+ source: string;
35
+ sourceKind: SystemSourceKind;
36
+ owner: string | null;
37
+ /** Path diagnostics about this model's elements point at — resolved, as the CLI prints it. */
38
+ file: string;
39
+ doc: SystemExportDoc;
40
+ }
41
+ /** A diagnostic plus the file it concerns — `em status --json`'s multi-model convention. */
42
+ export interface SystemDiagnostic extends Diagnostic {
43
+ file: string;
44
+ }
45
+ export interface SystemModelReport {
46
+ key: string;
47
+ name: string | null;
48
+ source: string;
49
+ sourceKind: SystemSourceKind;
50
+ owner: string | null;
51
+ /** Unqualified (`<sliceKey>/<kind>.<slug>`) refs of every `public` element, export order. */
52
+ publicSurface: string[];
53
+ }
54
+ export interface SystemSeamReport {
55
+ /** Resolved, element-level qualified ref when the endpoint resolved; else the ref as written. */
56
+ from: string;
57
+ to: string;
58
+ fromSlice: string | null;
59
+ toSlice: string | null;
60
+ description: string | null;
61
+ status: "verified" | "error";
62
+ /** Codes of every diagnostic raised on this seam (errors and warnings), in raise order. */
63
+ diagnostics: string[];
64
+ }
65
+ export interface ContextMap {
66
+ nodes: {
67
+ key: string;
68
+ name: string | null;
69
+ owner: string | null;
70
+ }[];
71
+ /** One edge per ordered model pair with at least one declared seam (verified or not), sorted
72
+ * by (from, to); `seams` counts the declarations. */
73
+ edges: {
74
+ from: string;
75
+ to: string;
76
+ seams: number;
77
+ }[];
78
+ }
79
+ export interface SystemReport {
80
+ name: string | null;
81
+ models: SystemModelReport[];
82
+ seams: SystemSeamReport[];
83
+ contextMap: ContextMap;
84
+ diagnostics: SystemDiagnostic[];
85
+ }
86
+ /** Verify `manifest` against the loaded `models` (one per manifest entry, same order).
87
+ * `manifestFile` is the path manifest-level diagnostics point at. */
88
+ export declare function verifySystem(manifest: SystemManifest, models: SystemModelInput[], manifestFile: string): SystemReport;
@@ -0,0 +1,263 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Verifies a seam manifest against the models' export documents (MIL-194) — the cross-model
3
+ // half of the bedrock "both ends of a flow" rule. A seam is a `public` event/view on one side
4
+ // bound to a reaction (translation/automation-kind element) on the other; `em` already has both
5
+ // ends of every seam, it just never had them as data. This module makes the binding explicit and
6
+ // checks it: both endpoints resolve, the source really is `public`, the consumer really is a
7
+ // reaction, nothing published goes unread, nothing externally fed goes unclaimed, and the old
8
+ // portal name-matching heuristic is demoted to a lint (`undeclared-seam-candidate`).
9
+ //
10
+ // It reads EXPORT DOCUMENTS ONLY — the `SystemExportDoc` shape below is the slice of `em
11
+ // export --json` (schema >= 1.10: `model.key`, `model.edges`) this check needs, and nothing here
12
+ // touches a NormalizedModel. That's the constraint the ticket sets ("models still compile
13
+ // independently — no compile-time coupling"): a `.em` source is compiled into the same export
14
+ // document by the caller (src/cli/systemInputs.ts), so this verifier can't tell a co-located
15
+ // repo from a CI job aggregating exports from ten repos. Pure: no fs, no clock; output order
16
+ // is manifest order for models/seams and stable derivation order for everything else.
17
+ import { AUTOMATION_KINDS } from "../parser/ast.js";
18
+ import { normalizeName } from "../model/model.js";
19
+ import { formatQualifiedRef, parseQualifiedRef } from "../model/qualifiedRef.js";
20
+ import { pushDiag } from "../model/rules.js";
21
+ const SEAM_ERROR_CODES = new Set([
22
+ "system-manifest-invalid",
23
+ "seam-endpoint-unresolved",
24
+ "seam-source-not-public",
25
+ "seam-consumer-not-reaction",
26
+ ]);
27
+ /** Verify `manifest` against the loaded `models` (one per manifest entry, same order).
28
+ * `manifestFile` is the path manifest-level diagnostics point at. */
29
+ export function verifySystem(manifest, models, manifestFile) {
30
+ const diagnostics = [];
31
+ const raise = (file, code, extra) => {
32
+ const bucket = [];
33
+ pushDiag(bucket, code, extra);
34
+ diagnostics.push({ ...bucket[0], file });
35
+ };
36
+ const qualify = formatQualifiedRef;
37
+ // Models are addressed by their MANIFEST key throughout — even on a mismatch, so a seam
38
+ // written against the manifest's own vocabulary still verifies and the one error tells the
39
+ // author exactly which key to change.
40
+ const byKey = new Map();
41
+ for (const m of models) {
42
+ byKey.set(m.key, m);
43
+ if (m.doc.model.key !== m.key) {
44
+ const entry = manifest.models.find((e) => e.key === m.key);
45
+ const modelLabel = m.doc.model.name === null ? "(unnamed model)" : `model "${m.doc.model.name}"`;
46
+ raise(manifestFile, "system-model-key-mismatch", {
47
+ message: `manifest key "${m.key}" does not match the computed key "${m.doc.model.key}" of ${modelLabel} ` +
48
+ `(${m.source}) — rename the manifest entry to "${m.doc.model.key}"`,
49
+ line: entry?.line,
50
+ });
51
+ }
52
+ }
53
+ const isReaction = (el) => AUTOMATION_KINDS.has(el.kind);
54
+ const isSurface = (el) => el.public === true && (el.kind === "event" || el.kind === "view");
55
+ const findElement = (model, ref) => {
56
+ for (const slice of model.doc.model.slices) {
57
+ for (const element of slice.elements)
58
+ if (element.ref === ref)
59
+ return { slice, element };
60
+ }
61
+ return undefined;
62
+ };
63
+ // ---- Seams: resolve both endpoints, then check what each one is. ----
64
+ const consumedSurface = new Set(); // qualified refs named as a resolved `from`
65
+ const boundReactions = new Set(); // qualified refs named as a resolved `to`
66
+ const declaredPairs = new Map(); // fromQualified -> set of toQualified
67
+ const seenPairs = new Set();
68
+ const seamsByModelPair = new Map();
69
+ const seams = manifest.seams.map((seam, i) => {
70
+ const codes = [];
71
+ const seamRaise = (code, message, refs) => {
72
+ codes.push(code);
73
+ raise(manifestFile, code, { message: `seams[${i}] (${seam.from} -> ${seam.to}): ${message}`, line: seam.line, refs });
74
+ };
75
+ const resolveModel = (raw, side) => {
76
+ const parsed = parseQualifiedRef(raw);
77
+ if (parsed.modelKey === null) {
78
+ seamRaise("system-manifest-invalid", `\`${side}\` must be a model-qualified ref (<modelKey>:<sliceKey>/<kind>.<slug>), got "${raw}"`);
79
+ return undefined;
80
+ }
81
+ const model = byKey.get(parsed.modelKey);
82
+ if (!model) {
83
+ seamRaise("system-manifest-invalid", `\`${side}\` names unknown model key "${parsed.modelKey}" — declared models are: ${manifest.models.map((m) => m.key).join(", ")}`);
84
+ return undefined;
85
+ }
86
+ return { modelKey: parsed.modelKey, ref: parsed.ref, model };
87
+ };
88
+ // `from`: an element ref that must be a `public` event/view.
89
+ let from;
90
+ const fromModel = resolveModel(seam.from, "from");
91
+ if (fromModel) {
92
+ const hit = findElement(fromModel.model, fromModel.ref);
93
+ if (!hit) {
94
+ seamRaise("seam-endpoint-unresolved", `no element "${fromModel.ref}" in model "${fromModel.modelKey}" — check \`em export\`'s refs, or re-declare the seam after a rename`);
95
+ }
96
+ else {
97
+ from = { modelKey: fromModel.modelKey, model: fromModel.model, ...hit };
98
+ if (!isSurface(hit.element)) {
99
+ const why = hit.element.kind === "event" || hit.element.kind === "view"
100
+ ? "is not marked `public`"
101
+ : `is a ${hit.element.kind}, not a \`public\` event or view`;
102
+ seamRaise("seam-source-not-public", `${hit.element.kind} "${hit.element.name}" ${why}`, [qualify(from.modelKey, hit.element.ref)]);
103
+ }
104
+ }
105
+ }
106
+ // `to`: an element ref to a reaction, or a bare slice ref containing exactly one reaction.
107
+ let to;
108
+ const toModel = resolveModel(seam.to, "to");
109
+ if (toModel) {
110
+ if (toModel.ref.includes("/")) {
111
+ const hit = findElement(toModel.model, toModel.ref);
112
+ if (!hit) {
113
+ seamRaise("seam-endpoint-unresolved", `no element "${toModel.ref}" in model "${toModel.modelKey}" — check \`em export\`'s refs, or re-declare the seam after a rename`);
114
+ }
115
+ else {
116
+ to = { modelKey: toModel.modelKey, model: toModel.model, ...hit };
117
+ if (!isReaction(hit.element)) {
118
+ seamRaise("seam-consumer-not-reaction", `${hit.element.kind} "${hit.element.name}" is not a reaction — \`to\` must name a translation/automation/processor/saga element`, [qualify(to.modelKey, hit.element.ref)]);
119
+ }
120
+ }
121
+ }
122
+ else {
123
+ const slice = toModel.model.doc.model.slices.find((s) => s.key === toModel.ref);
124
+ if (!slice) {
125
+ seamRaise("seam-endpoint-unresolved", `no slice "${toModel.ref}" in model "${toModel.modelKey}"`);
126
+ }
127
+ else {
128
+ const reactions = slice.elements.filter(isReaction);
129
+ if (reactions.length === 1) {
130
+ to = { modelKey: toModel.modelKey, model: toModel.model, slice, element: reactions[0] };
131
+ }
132
+ else {
133
+ seamRaise("seam-consumer-not-reaction", reactions.length === 0
134
+ ? `slice "${slice.name}" has no reaction element — \`to\` must name (or contain exactly one) translation/automation element`
135
+ : `slice "${slice.name}" has ${reactions.length} reaction elements (${reactions.map((r) => r.ref).join(", ")}) — name one explicitly`, [qualify(toModel.modelKey, slice.key)]);
136
+ }
137
+ }
138
+ }
139
+ }
140
+ const fromQualified = from ? qualify(from.modelKey, from.element.ref) : seam.from;
141
+ const toQualified = to ? qualify(to.modelKey, to.element.ref) : seam.to;
142
+ // Duplicate: same resolved (from, to) pair declared twice (a bare-slice `to` and its
143
+ // element-level spelling are the same seam). Warned on the second occurrence.
144
+ const pairKey = `${fromQualified} -> ${toQualified}`;
145
+ if (seenPairs.has(pairKey)) {
146
+ seamRaise("seam-duplicate", "already declared earlier in the manifest");
147
+ }
148
+ seenPairs.add(pairKey);
149
+ // A half-resolved seam still claims the endpoint it did resolve, so a typo on one side
150
+ // doesn't ALSO report the other side as dangling/unbound on top of the resolution error.
151
+ if (from)
152
+ consumedSurface.add(fromQualified);
153
+ if (to)
154
+ boundReactions.add(toQualified);
155
+ if (from && to) {
156
+ if (!declaredPairs.has(fromQualified))
157
+ declaredPairs.set(fromQualified, new Set());
158
+ declaredPairs.get(fromQualified).add(toQualified);
159
+ }
160
+ if (fromModel && toModel) {
161
+ const k = `${fromModel.modelKey} ${toModel.modelKey}`;
162
+ seamsByModelPair.set(k, (seamsByModelPair.get(k) ?? 0) + 1);
163
+ }
164
+ const hasError = codes.some((c) => SEAM_ERROR_CODES.has(c));
165
+ return {
166
+ from: fromQualified,
167
+ to: toQualified,
168
+ fromSlice: from ? qualify(from.modelKey, from.slice.key) : null,
169
+ toSlice: to ? qualify(to.modelKey, to.slice.key) : null,
170
+ description: seam.description,
171
+ status: hasError ? "error" : "verified",
172
+ diagnostics: codes,
173
+ };
174
+ });
175
+ // ---- Per-model surface + the two "other end missing" checks, manifest order. ----
176
+ const modelReports = models.map((m) => {
177
+ const publicSurface = [];
178
+ for (const slice of m.doc.model.slices) {
179
+ for (const el of slice.elements) {
180
+ if (!isSurface(el))
181
+ continue;
182
+ publicSurface.push(el.ref);
183
+ const q = qualify(m.key, el.ref);
184
+ if (!consumedSurface.has(q)) {
185
+ raise(m.file, "dangling-public-event", {
186
+ message: `public ${el.kind} "${el.name}" (${q}) is consumed by no declared seam — declare its reader, or drop \`public\``,
187
+ line: el.line,
188
+ refs: [q],
189
+ });
190
+ }
191
+ }
192
+ }
193
+ return { key: m.key, name: m.doc.model.name, source: m.source, sourceKind: m.sourceKind, owner: m.owner, publicSurface };
194
+ });
195
+ // "Externally fed" is computed from the export's own edge list, never re-derived: a reaction
196
+ // with no incoming edge in `model.edges` (no `from` view feeds it — pattern, `from`, or arrow)
197
+ // is fed from outside its model by construction. With no seam claiming it, nobody in the
198
+ // system says what feeds it.
199
+ for (const m of models) {
200
+ const fedInside = new Set(m.doc.model.edges.map((e) => e.to));
201
+ for (const slice of m.doc.model.slices) {
202
+ for (const el of slice.elements) {
203
+ if (!isReaction(el) || fedInside.has(el.ref))
204
+ continue;
205
+ const q = qualify(m.key, el.ref);
206
+ if (boundReactions.has(q))
207
+ continue;
208
+ raise(m.file, "unbound-translation", {
209
+ message: `${el.kind} "${el.name}" (${q}) has no in-model source and no seam feeds it — declare the seam whose \`to\` is this reaction, or add a \`from\``,
210
+ line: el.line,
211
+ refs: [q],
212
+ });
213
+ }
214
+ }
215
+ }
216
+ // The old portal heuristic, demoted: a public element in model A sharing its normalized
217
+ // name with a reaction or event in model B (B != A), with no seam between them.
218
+ for (const a of models) {
219
+ for (const aSlice of a.doc.model.slices) {
220
+ for (const el of aSlice.elements) {
221
+ if (!isSurface(el))
222
+ continue;
223
+ const aq = qualify(a.key, el.ref);
224
+ const wanted = normalizeName(el.name);
225
+ for (const b of models) {
226
+ if (b === a)
227
+ continue;
228
+ for (const bSlice of b.doc.model.slices) {
229
+ for (const other of bSlice.elements) {
230
+ const matchKind = isReaction(other) ? "reaction" : other.kind === "event" ? "event" : undefined;
231
+ if (!matchKind || normalizeName(other.name) !== wanted)
232
+ continue;
233
+ const bq = qualify(b.key, other.ref);
234
+ const declared = declaredPairs.get(aq);
235
+ const connected = matchKind === "reaction"
236
+ ? declared?.has(bq) === true
237
+ : [...(declared ?? [])].some((t) => t.startsWith(`${b.key}:`));
238
+ if (connected)
239
+ continue;
240
+ raise(a.file, "undeclared-seam-candidate", {
241
+ message: `public ${el.kind} "${el.name}" (${aq}) and ${other.kind} "${other.name}" (${bq}) look connected by name, ` +
242
+ "but no seam declares it — declare the seam or rename",
243
+ line: el.line,
244
+ refs: [aq, bq],
245
+ });
246
+ }
247
+ }
248
+ }
249
+ }
250
+ }
251
+ }
252
+ const contextMap = {
253
+ nodes: modelReports.map((m) => ({ key: m.key, name: m.name, owner: m.owner })),
254
+ edges: [...seamsByModelPair.entries()]
255
+ .map(([k, count]) => {
256
+ const [from, to] = k.split(" ");
257
+ return { from, to, seams: count };
258
+ })
259
+ .sort((x, y) => x.from.localeCompare(y.from) || x.to.localeCompare(y.to)),
260
+ };
261
+ return { name: manifest.name, models: modelReports, seams, contextMap, diagnostics };
262
+ }
263
+ //# sourceMappingURL=verify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify.js","sourceRoot":"","sources":["../../src/system/verify.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,4FAA4F;AAC5F,8FAA8F;AAC9F,gGAAgG;AAChG,iGAAiG;AACjG,6FAA6F;AAC7F,8FAA8F;AAC9F,qFAAqF;AACrF,EAAE;AACF,yFAAyF;AACzF,iGAAiG;AACjG,0FAA0F;AAC1F,8FAA8F;AAC9F,6FAA6F;AAC7F,6FAA6F;AAC7F,sFAAsF;AAEtF,OAAO,EAAE,gBAAgB,EAAe,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AACjF,OAAO,EAAE,QAAQ,EAAY,MAAM,mBAAmB,CAAC;AA0FvD,MAAM,gBAAgB,GAAwB,IAAI,GAAG,CAAC;IACpD,yBAAyB;IACzB,0BAA0B;IAC1B,wBAAwB;IACxB,4BAA4B;CAC7B,CAAC,CAAC;AAEH;sEACsE;AACtE,MAAM,UAAU,YAAY,CAAC,QAAwB,EAAE,MAA0B,EAAE,YAAoB;IACrG,MAAM,WAAW,GAAuB,EAAE,CAAC;IAC3C,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,IAAc,EAAE,KAA0D,EAAE,EAAE;QACzG,MAAM,MAAM,GAAiB,EAAE,CAAC;QAChC,QAAQ,CAAC,MAAM,EA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EAAE,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;QAC9E,KAAK,EAAE,CAAC,GAAG,gBAAgB,CAAC,OAAO,EAAE,CAAC;aACnC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE;YAClB,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAChC,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;QACpC,CAAC,CAAC;aACD,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;KAC5E,CAAC;IAEF,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;AACvF,CAAC"}
@@ -1,8 +1,11 @@
1
1
  export declare const STARTER_EM = "model \"Order Fulfillment\"\n\npersona Customer\npersona Manager\n\ncontext Order\ncontext Payment\n\n# --- Command pattern: UI -> command -> event ---\nslice \"Browse Catalog\" {\n ui Product Catalog @Customer\n command Place Order\n event Order Placed @Order\n}\n\n# --- View pattern: event -> read model -> UI ---\nslice \"View Open Orders\" {\n view Open Orders from \"Order Placed\"\n ui Order List @Customer\n}\n\nslice \"Checkout\" {\n ui Checkout Screen @Customer\n command Submit Payment\n event Payment Requested @Payment\n}\n\n# --- View pattern: a human view of pending payments ---\nslice \"Manager Review\" {\n view Pending Payments from \"Payment Requested\"\n ui Payment Dashboard @Manager\n}\n\n# --- Read model the automation watches, in its own slice ---\nslice \"Payments To Process\" {\n view Payments To Process from \"Payment Requested\"\n}\n\n# --- Automation slice: the processor, the command it triggers, and that command's event ---\nslice \"Capture Payment\" {\n processor Payment Gateway from \"Payments To Process\"\n command Capture Payment\n event Payment Captured @Payment\n}\n\nslice \"Show Receipt\" {\n view Receipts from \"Payment Captured\"\n ui Receipt Screen @Customer\n}\n";
2
2
  /** Raw copy of templates/model-readme.md, \`{{...}}\` placeholders intact — see scaffoldReadme(). */
3
- export declare const MODEL_README_TEMPLATE = "# {{Model Name}}\n\n{{One-paragraph description of the business process(es) this event model covers.}}\n\n## Live view\nWhile modeling, run the live view so the team can watch the diagram update:\n\n```bash\nem watch {{model-name}}.em -o {{model-name}}.svg --serve # re-render + instant push-reload\n# then open the URL it prints (http://localhost:5173/?svg={{model-name}}.svg) and share the screen\n```\n\nPan/zoom to navigate the diagram (drag, scroll; **Fit** resets), and click **Review mode** in\nthe header for a slice-by-slice walkthrough. If a save fails to render, the viewer keeps the\nlast good diagram and shows an error banner until the next successful load.\n\nStatic render: `em render {{model-name}}.em -o {{model-name}}.svg`\n\n## Patterns legend\n- **State Change** \u2014 UI \u2192 Command \u2192 Event\n- **State View** \u2014 Event(s) \u2192 Read Model \u2192 UI\n- **Automation** \u2014 Read Model (slice before) \u2192 Processor + Command \u2192 Event, together\n- **Translation** \u2014 External input (or Read Model, slice before) \u2192 Translation + Command \u2192 Event, together\n\nBetween them these are the only legal connections: `ui \u2192 command`, `command \u2192 event`,\n`event \u2192 read model`, `read model \u2192 ui`, `read model \u2192 reaction`, `reaction \u2192 command`. A command\nnever reaches a read model directly \u2014 the event goes between them. Every slice is joined up at\nboth ends: something triggers each command (the screen it's issued from, or the reaction that\ntriggers it, also in this slice), and every event a command records is read by some read model \u2014 so each State\nChange slice is paired with the State View slice that projects its event. A read model repeated\nalong the timeline (`view X again`) shows the same projection at a later point; the instances are\nnever connected to one another.\n\n## Slices\n<!-- The canonical slice index \u2014 the ONE place slices are enumerated (the state file\n points here rather than keeping its own copy). Generated \u2014 run\n `em slice index {{model-name}}.em` to (re)write the table below from the model and its\n slice docs; never hand-edit between the markers. -->\n<!-- GENERATED:slices:start -->\n| # | Slice | Pattern | Status | Ratified by | Owner | Tracking | Implemented in | Design doc |\n|---|-------|---------|--------|-------------|-------|----------|----------------|------------|\n<!-- GENERATED:slices:end -->\n\n## Status\nSee [`.event-modeling.md`](.event-modeling.md) for current phase, decisions, and open questions.\n";
3
+ export declare const MODEL_README_TEMPLATE = "# {{Model Name}}\n\n{{One-paragraph description of the business process(es) this event model covers.}}\n\n## Live view\nWhile modeling, run the live view so the team can watch the diagram update:\n\n```bash\nem watch {{model-name}}.em -o {{model-name}}.svg --serve # re-render + instant push-reload\n# then open the URL it prints (http://localhost:5173/?svg={{model-name}}.svg) and share the screen\n```\n\nPan/zoom to navigate the diagram (drag, scroll; **Fit** resets), and click **Review mode** in\nthe header for a slice-by-slice walkthrough. If a save fails to render, the viewer keeps the\nlast good diagram and shows an error banner until the next successful load.\n\nStatic render: `em render {{model-name}}.em -o {{model-name}}.svg`\n\n## Patterns legend\n- **State Change** \u2014 UI \u2192 Command \u2192 Event\n- **State View** \u2014 Event(s) \u2192 Read Model \u2192 UI\n- **Automation** \u2014 Read Model (slice before) \u2192 Processor + Command \u2192 Event, together\n- **Translation** \u2014 External input (or Read Model, slice before) \u2192 Translation + Command \u2192 Event, together\n\nBetween them these are the only legal connections: `ui \u2192 command`, `command \u2192 event`,\n`event \u2192 read model`, `read model \u2192 ui`, `read model \u2192 reaction`, `reaction \u2192 command`. A command\nnever reaches a read model directly \u2014 the event goes between them. Every slice is joined up at\nboth ends: something triggers each command (the screen it's issued from, or the reaction that\ntriggers it, also in this slice), and every event a command records is read by some read model \u2014 so each State\nChange slice is paired with the State View slice that projects its event. A read model repeated\nalong the timeline (`view X again`) shows the same projection at a later point; the instances are\nnever connected to one another.\n\n## Slices\n<!-- The canonical slice index \u2014 the ONE place slices are enumerated (the state file\n points here rather than keeping its own copy). Generated \u2014 run\n `em slice index {{model-name}}.em` to (re)write the table below from the model and its\n slice docs; never hand-edit between the markers. -->\n<!-- GENERATED:slices:start -->\n| # | Slice | Pattern | Status | Reviewed by | Ratified by | Owner | Tracking | Implemented in | Design doc |\n|---|-------|---------|--------|-------------|-------------|-------|----------|----------------|------------|\n<!-- GENERATED:slices:end -->\n\n## Status\nSee [`.event-modeling.md`](.event-modeling.md) for current phase, decisions, and open questions.\n";
4
4
  /** Raw copy of templates/state.md, \`{{...}}\` placeholders intact — see scaffoldStateFile(). */
5
5
  export declare const STATE_TEMPLATE = "<!--\nResumable progress state for an event model. Stored as <model>/.event-modeling.md\nThe skill reads this on `/event-modeling` (no arg) to resume where you left off.\nKeep it current at the end of every working session.\n-->\n\n# Event Modeling Progress \u2014 {{Model Name}}\n\n- **Model file:** `{{model-name}}.em`\n- **Current phase:** {{discover | extract | model | slice | implement | conform | review | validate}}\n- **Current step:** {{1\u20137, see methodology; or extraction round R1\u2013R7}}\n- **Last updated:** {{YYYY-MM-DD}}\n- **Last conformance:** {{YYYY-MM-DD @ <target-repo revision> \u2014 report: conformance/<date>-report.md | never}}\n- **Last stakeholder review:** {{YYYY-MM-DD \u2014 attendees: see Participants | never}}\n\n## Session inputs\n- **Scope line:** {{one-line description of what's in/out of bounds for this model}}\n- **PRD / spec reference:** {{path, link, or \"none\"}}\n- **Headless/API model:** {{yes | no}}\n- **Source mode:** {{greenfield | extract-event-driven | extract-procedural}}\n- **Existing system refs:** {{repo paths, event-schema/topic locations, docs \u2014 or \"n/a\"}}\n\n## Participants\n<!-- Populate at session start. Live workshop: one human proxy relays questions to the room;\n attribute every answer/decision in the Decisions log to a named participant here. -->\n- {{Name}} \u2014 {{role}} \u2014 {{domain area}}\n\n## Extraction progress (existing-system models only \u2014 delete for greenfield)\n- [ ] R1. Candidate events (extracted/synthesized, filtered, confirmed)\n- [ ] R2. Timeline order (as-is narrative, actors/callers, first render)\n- [ ] R3. Commands / inputs\n- [ ] R4. Read models / outputs (validate from here)\n- [ ] R5. Boundaries & reactions (reaction shares its slice with the command it triggers)\n- [ ] R6. Gap & TBD reconciliation\n- [ ] R7. Convergence (render + validate clean, user confirmed as-is)\n\n## Steps completed\n- [ ] 1. Brainstorm events\n- [ ] 2. Plot / storyboard (personas + UI)\n- [ ] 3. Inputs (commands)\n- [ ] 4. Outputs (read models)\n- [ ] 5. Swimlanes & apply patterns\n- [ ] 6. Elaborate scenarios\n- [ ] 7. Evaluate completeness (`em validate` clean)\n\n## Decisions log\n<!-- Resolved choices, with the reasoning, so they aren't re-litigated. In a live workshop,\n attribute each entry to the participant who made the call (see Participants above). -->\n- {{YYYY-MM-DD}}: {{decision}} \u2014 {{why}} \u2014 by {{participant, if a live workshop}}\n\n## Usage log\n<!-- The team's only usage signal today (see docs/usage-data.md) \u2014 cheap and coarse on purpose.\n One line per session: phase(s) touched, and validate diagnostic *categories* hit (one of\n the exact fixed strings in docs/usage-data.md#categories, e.g. \"read model has no\n consumer\" \u2014 never the full instance message or any domain content). Append, never edit\n past entries. -->\n- {{YYYY-MM-DD}}: phases: {{discover | extract | model | slice | implement | conform | review | validate | watch, ...}} \u2014 validate: {{diagnostic category (docs/usage-data.md#categories), ... | none}}\n\n## Open questions / parking lot\n<!-- Unresolved items to bring back to the user. Never guess these. Metadata is optional and\n flat \u2014 add only what's known: source (ticket/conversation that spawned it), blocked on\n (who/what), revisit (when). -->\n- [ ] {{question}} \u2014 source: {{ticket/conversation link, optional}} \u2014 blocked on: {{who/what, optional}} \u2014 revisit: {{when, optional}}\n\n## Slice inventory\n<!-- Deliberately NOT a table: the canonical slice index (slice, pattern, status, doc link)\n lives in README.md's \"Slices\" section \u2014 one source of truth, updated there. This file\n only tracks resumable session state. -->\nSee `README.md` \u2192 **Slices** for the slice index and per-slice doc status.\n";
6
+ /** Raw copy of templates/constitution.md, \`{{...}}\` placeholders intact — see
7
+ * scaffoldConstitution(). */
8
+ export declare const CONSTITUTION_TEMPLATE = "<!--\nThe implementation constitution: the house rules an implementing agent follows on EVERY slice \u2014\nstack, code style, testing norms, NFR baselines, review norms. It answers \"how do we build things\nhere\" once, so no slice doc has to repeat it and no agent has to invent it. Slice docs say WHAT to\nbuild; this says HOW it gets built here.\n\nWhere this document lives:\n - No SDD tool: `constitution.md` beside the model \u2014 `em scaffold` writes it there.\n - spec-kit project (a `.specify/` directory exists anywhere above the model): the document IS\n `.specify/memory/constitution.md`. em writes no second copy; the sections below merge into\n that file under these same headings, never overwriting text already there, and ratification is\n recorded in spec-kit's own `**Ratified**:` footer line instead of the frontmatter below.\n\nHow it gets filled: not by an agent guessing. Each section opens with the question a short\nfacilitated conversation asks before the first slice is implemented \u2014 the procedure is \"Before the\nfirst slice: the constitution\" in the `event-modeling-implement` skill's `reference/implement.md`\n(`em contract` prints it). Replace each `{{...}}` block with the real answers; delete the guidance\ncomments and any row that doesn't apply.\n\nRatification: `ratifiedBy:`/`ratifiedOn:` are the same identity discipline slice docs use \u2014 a\nNAMED human and an ISO date, hand-filled at sign-off (no `em` command writes this file).\n**A constitution with an empty `ratifiedBy:` is a draft**: an implementing agent treats it as\nunratified, says so, and does not proceed on unilateral style or stack decisions for a first slice.\n\n`em status` reports this document as present or absent per model \u2014 existence only. em never reads\nor validates its content, and nothing here is machine-parsed.\n-->\n\n---\nschemaVersion: 1\nratifiedBy:\nratifiedOn:\n---\n# {{Project Name}} \u2014 implementation constitution\n\nThe house rules for how implementation happens in this project. They bound every \"purely\ntechnical choice\" an implementing agent would otherwise make alone.\n\n## Stack and architectural shape\n\n> **What do we build on, what shape does the code take, and which implementation skill or\n> approach does each slice pattern route to?**\n\n- **Languages / runtimes:** {{e.g. Kotlin 2.x on JVM 21; TypeScript 5 on Node 24}}\n- **Frameworks / platform:** {{web framework, persistence, messaging, build tool}}\n- **Architectural pattern:** {{e.g. event-sourced CQRS with vertical slices; layered service over\n a relational store; functional core / imperative shell}}\n- **Where a slice's code lives:** {{one package per slice, per context, ...}}\n\nRouting \u2014 which implementation skill or approach each of the four slice patterns uses:\n\n| Pattern | Skill / approach |\n|---|---|\n| State Change | {{e.g. the `axon-*` skill set \u2014 axon-entity-patterns, then axon-entity-testing}} |\n| State View | {{e.g. the `axon-*` skill set \u2014 axon-projection-patterns, then axon-projection-testing}} |\n| Automation | {{e.g. the `axon-*` skill set \u2014 axon-policy-patterns, then axon-policy-testing}} |\n| Translation | {{e.g. the `axon-*` skill set \u2014 axon-translation-patterns}} |\n\nAn agent implementing a slice reads the doc's `pattern:` frontmatter and follows that row \u2014 this\ntable is the only routing rule.\n\n## Code style\n\n> **What does \"idiomatic\" mean in this codebase \u2014 formatting, naming, module layout?**\n\n- **Formatter / linter:** {{the tool and the command that runs it \u2014 never hand-format against it}}\n- **Naming:** {{commands, events, handlers, files, test names}}\n- **Module layout:** {{what lives in which file/package, and what may not import what}}\n- **Idiomatic here means:** {{the two or three habits a new contributor most often gets wrong}}\n\n## Testing norms\n\n> **What must be tested for each slice pattern, where do those tests live, and how are they named\n> so `em coverage` can trace invariant IDs?**\n\n- **Levels required per pattern:** {{e.g. State Change \u2014 decider unit tests plus a\n given/when/then fixture test; State View \u2014 projection tests; Automation / Translation \u2014\n reaction tests, including a negative case}}\n- **Invariant tests:** {{where they live}} \u2014 every `INV-<MNEMONIC>-n` in a slice doc needs at least\n one test **citing that exact ID** in its name or a comment, so\n `em coverage <model>.em --tests <dir>` can trace it.\n- **Scenario tests:** {{where they live}} \u2014 one per `## Scenarios (Given / When / Then)` entry,\n with rejection scenarios asserting the doc's named rejection reason.\n- **Test naming convention:** {{the exact pattern, e.g. `INV-ORD-3: rejects a second submit`}}\n- **What \"green\" means:** {{the command CI runs}}\n\n## NFR baselines\n\n> **What standing non-functional defaults does every slice inherit \u2014 authz, PII, performance,\n> observability?**\n\n- **Authorization model:** {{who may issue which commands, how it's enforced, and where}}\n- **PII / data handling:** {{what is sensitive, what may be logged, retention}}\n- **Performance defaults:** {{latency / throughput budgets that apply unless a slice says otherwise}}\n- **Observability:** {{logging, metrics, tracing every slice is expected to emit}}\n\nA slice doc's own `## Non-Functional Requirements` section overrides these for that slice; where\nit is silent, these apply.\n\n## Review and merge norms\n\n> **Who reviews an implementation PR, what blocks a merge, and how does the slice doc's status\n> flip fit in?**\n\n- **Reviewers:** {{who \u2014 a team, a CODEOWNERS rule, the slice's ratifier}}\n- **What blocks a merge:** {{e.g. a failing suite, an uncovered invariant, a gap that belongs back\n at the model}}\n- **Branch / commit conventions:** {{...}}\n- **At merge:** run `em slice mark-implemented <model>.em <slice-key> <pr-url>` \u2014 the one edit an\n implementing agent makes to a ratified slice doc, run by {{the PR author | CI}}. Never bump\n `version:`; that moves only when a delta is ratified.\n";
6
9
  /** Same STARTER_EM content `em init` writes, titled from an arbitrary display name — used by
7
10
  * `em scaffold`, which (unlike `em init`) knows a name to title the model with. */
8
11
  export declare function starterEmFor(title: string): string;
@@ -18,3 +21,13 @@ export declare function scaffoldReadme(displayName: string, slugName: string): s
18
21
  * the template's own guidance comment intact where it has one — per the skill's "don't guess,
19
22
  * park it" principle, never a fabricated example. Never leaves \`{{...}}\` in the result. */
20
23
  export declare function scaffoldStateFile(displayName: string, slugName: string, today: string): string;
24
+ /** Fill CONSTITUTION_TEMPLATE's project-name placeholder for `em scaffold` (MIL-202).
25
+ *
26
+ * Unlike `scaffoldReadme`/`scaffoldStateFile`, this one **deliberately leaves every other
27
+ * \`{{...}}\` block intact**: they are the unanswered questions of the elicitation conversation
28
+ * the implement skill runs before the first slice ("Before the first slice: the constitution"),
29
+ * not mechanical fields em could fill. An unanswered constitution must read as unanswered — the
30
+ * placeholders are the todo list, and the empty `ratifiedBy:` frontmatter says it's still a
31
+ * draft. Nothing in `em` ever parses this file's body; only its existence is reported
32
+ * (`em status`'s `constitution` field). */
33
+ export declare function scaffoldConstitution(displayName: string): string;