@blackbelt-technology/pi-dashboard-forms-bpmn 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.
Files changed (164) hide show
  1. package/.pi/skills/bpmn-package-explorer/SKILL.md +120 -0
  2. package/.pi/skills/bpmn-package-explorer/assets/LICENSE.bpmn-io.txt +23 -0
  3. package/.pi/skills/bpmn-package-explorer/assets/VENDORED.md +90 -0
  4. package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/css/bpmn-codes.css +108 -0
  5. package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/css/bpmn-embedded.css +166 -0
  6. package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/css/bpmn.css +164 -0
  7. package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/font/bpmn.eot +0 -0
  8. package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/font/bpmn.svg +224 -0
  9. package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/font/bpmn.ttf +0 -0
  10. package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/font/bpmn.woff +0 -0
  11. package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/font/bpmn.woff2 +0 -0
  12. package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-navigated-viewer.production.min.js +22 -0
  13. package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn.css +145 -0
  14. package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/diagram-js.css +1249 -0
  15. package/.pi/skills/bpmn-package-explorer/assets/dmn-js/diagram-js.css +1133 -0
  16. package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/css/dmn-codes.css +41 -0
  17. package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/css/dmn-embedded.css +98 -0
  18. package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/css/dmn.css +97 -0
  19. package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/font/dmn.eot +0 -0
  20. package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/font/dmn.svg +90 -0
  21. package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/font/dmn.ttf +0 -0
  22. package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/font/dmn.woff +0 -0
  23. package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/font/dmn.woff2 +0 -0
  24. package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-js-decision-table.css +580 -0
  25. package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-js-drd.css +108 -0
  26. package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-js-literal-expression.css +165 -0
  27. package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-js-shared.css +221 -0
  28. package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-viewer.production.min.js +16 -0
  29. package/.pi/skills/bpmn-package-explorer/assets/lib/bpmn-pipeline.mjs +6981 -0
  30. package/.pi/skills/bpmn-package-explorer/assets/lib/yaml.mjs +7372 -0
  31. package/.pi/skills/bpmn-package-explorer/fixtures/geometry/g1-identical-bounds.bpmn +17 -0
  32. package/.pi/skills/bpmn-package-explorer/fixtures/geometry/g2-zero-size.bpmn +17 -0
  33. package/.pi/skills/bpmn-package-explorer/fixtures/geometry/g3-child-outside.bpmn +16 -0
  34. package/.pi/skills/bpmn-package-explorer/fixtures/geometry/g4-negative-coord.bpmn +17 -0
  35. package/.pi/skills/bpmn-package-explorer/fixtures/geometry/g5-overlap.bpmn +17 -0
  36. package/.pi/skills/bpmn-package-explorer/fixtures/measured/1-linear.bpmn +12 -0
  37. package/.pi/skills/bpmn-package-explorer/fixtures/measured/2-gateway.bpmn +19 -0
  38. package/.pi/skills/bpmn-package-explorer/fixtures/measured/3-boundary.bpmn +13 -0
  39. package/.pi/skills/bpmn-package-explorer/fixtures/measured/4-subprocess.bpmn +17 -0
  40. package/.pi/skills/bpmn-package-explorer/fixtures/measured/5-pools.bpmn +21 -0
  41. package/.pi/skills/bpmn-package-explorer/fixtures/measured/6-lanes-only.bpmn +16 -0
  42. package/.pi/skills/bpmn-package-explorer/fixtures/measured/7-loop.bpmn +13 -0
  43. package/.pi/skills/bpmn-package-explorer/fixtures/measured/8-long-chain.bpmn +32 -0
  44. package/.pi/skills/bpmn-package-explorer/fixtures/nesting/expanded-subprocess-ok.bpmn +25 -0
  45. package/.pi/skills/bpmn-package-explorer/fixtures/provisional/call-activity.bpmn +10 -0
  46. package/.pi/skills/bpmn-package-explorer/fixtures/provisional/intermediate-catch.bpmn +10 -0
  47. package/.pi/skills/bpmn-package-explorer/fixtures/provisional/intermediate-throw.bpmn +10 -0
  48. package/.pi/skills/bpmn-package-explorer/fixtures/provisional/manual-task.bpmn +10 -0
  49. package/.pi/skills/bpmn-package-explorer/fixtures/provisional/multi-boundary.bpmn +16 -0
  50. package/.pi/skills/bpmn-package-explorer/fixtures/provisional/parallel-gateway.bpmn +10 -0
  51. package/.pi/skills/bpmn-package-explorer/fixtures/provisional/receive-task.bpmn +10 -0
  52. package/.pi/skills/bpmn-package-explorer/fixtures/provisional/rule-task.bpmn +10 -0
  53. package/.pi/skills/bpmn-package-explorer/fixtures/provisional/script-task.bpmn +10 -0
  54. package/.pi/skills/bpmn-package-explorer/fixtures/provisional/send-task.bpmn +10 -0
  55. package/.pi/skills/bpmn-package-explorer/references/authoring-envelope.md +52 -0
  56. package/.pi/skills/bpmn-package-explorer/references/identifiers.md +102 -0
  57. package/.pi/skills/bpmn-package-explorer/references/layout-envelope.md +105 -0
  58. package/.pi/skills/bpmn-package-explorer/references/licensing.md +48 -0
  59. package/.pi/skills/bpmn-package-explorer/references/package-manifest.md +104 -0
  60. package/.pi/skills/bpmn-package-explorer/scripts/build-fixtures.mjs +299 -0
  61. package/.pi/skills/bpmn-package-explorer/scripts/demo.mjs +128 -0
  62. package/.pi/skills/bpmn-package-explorer/scripts/diagnostics.mjs +37 -0
  63. package/.pi/skills/bpmn-package-explorer/scripts/envelope.mjs +160 -0
  64. package/.pi/skills/bpmn-package-explorer/scripts/fixtures.mjs +140 -0
  65. package/.pi/skills/bpmn-package-explorer/scripts/generate-cli.mjs +31 -0
  66. package/.pi/skills/bpmn-package-explorer/scripts/generate.mjs +103 -0
  67. package/.pi/skills/bpmn-package-explorer/scripts/guard.mjs +335 -0
  68. package/.pi/skills/bpmn-package-explorer/scripts/harness.mjs +12 -0
  69. package/.pi/skills/bpmn-package-explorer/scripts/identifiers.mjs +117 -0
  70. package/.pi/skills/bpmn-package-explorer/scripts/ingest.mjs +95 -0
  71. package/.pi/skills/bpmn-package-explorer/scripts/manifest.mjs +374 -0
  72. package/.pi/skills/bpmn-package-explorer/scripts/pipeline.mjs +49 -0
  73. package/.pi/skills/bpmn-package-explorer/scripts/render.mjs +130 -0
  74. package/.pi/skills/bpmn-package-explorer/scripts/runguard.mjs +38 -0
  75. package/.pi/skills/bpmn-package-explorer/scripts/selftest-e2e.mjs +87 -0
  76. package/.pi/skills/bpmn-package-explorer/scripts/selftest-guard.mjs +99 -0
  77. package/.pi/skills/bpmn-package-explorer/scripts/selftest-manifest.mjs +170 -0
  78. package/.pi/skills/bpmn-package-explorer/scripts/selftest-more.mjs +87 -0
  79. package/.pi/skills/bpmn-package-explorer/scripts/selftest-workflow.mjs +73 -0
  80. package/.pi/skills/bpmn-package-explorer/scripts/selftest.mjs +57 -0
  81. package/.pi/skills/bpmn-package-explorer/scripts/vendor.mjs +141 -0
  82. package/.pi/skills/bpmn-package-explorer/scripts/view-cli.mjs +19 -0
  83. package/.pi/skills/bpmn-package-explorer/templates/shell.html +141 -0
  84. package/.pi/skills/bpmn-package-explorer/templates/viewer.js +301 -0
  85. package/.pi/skills/canvas-webapp/SKILL.md +104 -0
  86. package/.pi/skills/openforms-mui/SKILL.md +187 -0
  87. package/.pi/skills/openforms-mui/references/a11y.md +68 -0
  88. package/.pi/skills/openforms-mui/references/field-widget-map.md +64 -0
  89. package/.pi/skills/openforms-mui/references/hu-locale.md +45 -0
  90. package/.pi/skills/openforms-mui/references/logic.md +94 -0
  91. package/.pi/skills/openforms-mui/references/schema.md +94 -0
  92. package/.pi/skills/openforms-mui/references/theme-bridge.md +65 -0
  93. package/.pi/skills/openforms-mui/tools/canvas-serve.mjs +51 -0
  94. package/.pi/skills/openforms-mui/tools/demo-schema.json +80 -0
  95. package/.pi/skills/openforms-mui/tools/mockups/tokens.css +27 -0
  96. package/.pi/skills/openforms-mui/tools/mockups/ui-contract.tokens.json +16 -0
  97. package/.pi/skills/openforms-mui/tools/package-lock.json +5919 -0
  98. package/.pi/skills/openforms-mui/tools/package.json +61 -0
  99. package/.pi/skills/openforms-mui/tools/preview/RenderPanel.tsx +105 -0
  100. package/.pi/skills/openforms-mui/tools/preview/canvas-app.tsx +66 -0
  101. package/.pi/skills/openforms-mui/tools/preview/canvas-index.html +16 -0
  102. package/.pi/skills/openforms-mui/tools/preview/cli.ts +99 -0
  103. package/.pi/skills/openforms-mui/tools/preview/index.html +17 -0
  104. package/.pi/skills/openforms-mui/tools/preview/main.tsx +228 -0
  105. package/.pi/skills/openforms-mui/tools/preview/vite-plugin.ts +41 -0
  106. package/.pi/skills/openforms-mui/tools/scripts/assert-peer-deps.mjs +39 -0
  107. package/.pi/skills/openforms-mui/tools/src/OpenFormsMui.tsx +391 -0
  108. package/.pi/skills/openforms-mui/tools/src/css.d.ts +2 -0
  109. package/.pi/skills/openforms-mui/tools/src/fields/ErrorSummary.tsx +72 -0
  110. package/.pi/skills/openforms-mui/tools/src/fields/FieldRenderer.tsx +328 -0
  111. package/.pi/skills/openforms-mui/tools/src/fields/FieldShell.tsx +50 -0
  112. package/.pi/skills/openforms-mui/tools/src/fields/FileField.tsx +91 -0
  113. package/.pi/skills/openforms-mui/tools/src/fields/MatrixField.tsx +146 -0
  114. package/.pi/skills/openforms-mui/tools/src/fields/RepeaterField.tsx +82 -0
  115. package/.pi/skills/openforms-mui/tools/src/fields/SignatureCanvas.tsx +121 -0
  116. package/.pi/skills/openforms-mui/tools/src/fields/context.tsx +34 -0
  117. package/.pi/skills/openforms-mui/tools/src/fields/index.ts +7 -0
  118. package/.pi/skills/openforms-mui/tools/src/fields/label.ts +42 -0
  119. package/.pi/skills/openforms-mui/tools/src/fonts.ts +8 -0
  120. package/.pi/skills/openforms-mui/tools/src/i18n/dictionary.ts +58 -0
  121. package/.pi/skills/openforms-mui/tools/src/i18n/hu.ts +56 -0
  122. package/.pi/skills/openforms-mui/tools/src/i18n/index.ts +43 -0
  123. package/.pi/skills/openforms-mui/tools/src/index.ts +27 -0
  124. package/.pi/skills/openforms-mui/tools/src/logic/cnf.ts +206 -0
  125. package/.pi/skills/openforms-mui/tools/src/logic/formula.ts +285 -0
  126. package/.pi/skills/openforms-mui/tools/src/logic/index.ts +4 -0
  127. package/.pi/skills/openforms-mui/tools/src/logic/operators.ts +43 -0
  128. package/.pi/skills/openforms-mui/tools/src/logic/state.ts +183 -0
  129. package/.pi/skills/openforms-mui/tools/src/payload.ts +83 -0
  130. package/.pi/skills/openforms-mui/tools/src/provenance.ts +21 -0
  131. package/.pi/skills/openforms-mui/tools/src/schema/diagnose.ts +256 -0
  132. package/.pi/skills/openforms-mui/tools/src/schema/index.ts +4 -0
  133. package/.pi/skills/openforms-mui/tools/src/schema/normalize.ts +163 -0
  134. package/.pi/skills/openforms-mui/tools/src/schema/types.ts +299 -0
  135. package/.pi/skills/openforms-mui/tools/src/schema/walk.ts +68 -0
  136. package/.pi/skills/openforms-mui/tools/src/theme/from-tokens.ts +102 -0
  137. package/.pi/skills/openforms-mui/tools/src/theme/index.ts +1 -0
  138. package/.pi/skills/openforms-mui/tools/src/validation/constrain.ts +83 -0
  139. package/.pi/skills/openforms-mui/tools/src/validation/diagnostics.ts +62 -0
  140. package/.pi/skills/openforms-mui/tools/src/validation/empty.ts +53 -0
  141. package/.pi/skills/openforms-mui/tools/src/validation/index.ts +5 -0
  142. package/.pi/skills/openforms-mui/tools/src/validation/resolver.ts +14 -0
  143. package/.pi/skills/openforms-mui/tools/src/validation/zod-from-schema.ts +169 -0
  144. package/.pi/skills/openforms-mui/tools/tests/a11y.test.tsx +82 -0
  145. package/.pi/skills/openforms-mui/tools/tests/cli.test.ts +74 -0
  146. package/.pi/skills/openforms-mui/tools/tests/component.test.tsx +295 -0
  147. package/.pi/skills/openforms-mui/tools/tests/diagnose.test.ts +163 -0
  148. package/.pi/skills/openforms-mui/tools/tests/fixtures/all-field-types.json +45 -0
  149. package/.pi/skills/openforms-mui/tools/tests/logic.test.ts +175 -0
  150. package/.pi/skills/openforms-mui/tools/tests/normalize.test.ts +105 -0
  151. package/.pi/skills/openforms-mui/tools/tests/reference-semantics.test.ts +131 -0
  152. package/.pi/skills/openforms-mui/tools/tests/responsive.test.tsx +158 -0
  153. package/.pi/skills/openforms-mui/tools/tests/setup.ts +16 -0
  154. package/.pi/skills/openforms-mui/tools/tests/singleton.test.tsx +31 -0
  155. package/.pi/skills/openforms-mui/tools/tests/theme.test.ts +65 -0
  156. package/.pi/skills/openforms-mui/tools/tests/toolchain.test.ts +33 -0
  157. package/.pi/skills/openforms-mui/tools/tests/validation.test.ts +222 -0
  158. package/.pi/skills/openforms-mui/tools/tsconfig.json +21 -0
  159. package/.pi/skills/openforms-mui/tools/vite.canvas.config.ts +21 -0
  160. package/.pi/skills/openforms-mui/tools/vitest.config.ts +17 -0
  161. package/NOTICE +46 -0
  162. package/README.md +62 -0
  163. package/package.json +46 -0
  164. package/scripts/ensure-openforms-deps.mjs +38 -0
@@ -0,0 +1,128 @@
1
+ #!/usr/bin/env node
2
+ // Emits a Hungarian multi-file demo package (a worked example and the §10
3
+ // end-to-end fixture): a user task + form, a business-rule task + decision, a
4
+ // call activity + sub-process, and a second participant pool, plus a role.
5
+ //
6
+ // node scripts/demo.mjs [targetDir]
7
+ // Then: node scripts/generate-cli.mjs <targetDir> (layout + validate)
8
+
9
+ import { mkdtempSync, mkdirSync, writeFileSync } from 'node:fs';
10
+ import { tmpdir } from 'node:os';
11
+ import { join } from 'node:path';
12
+
13
+ const NS = 'xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL"';
14
+ function defs(inner) {
15
+ return `<?xml version="1.0" encoding="UTF-8"?>\n<bpmn:definitions ${NS} id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn">\n${inner}\n</bpmn:definitions>\n`;
16
+ }
17
+ function proc(id, nodes, flows) {
18
+ const inc = {}, out = {};
19
+ for (const [f, s, tg] of flows) { (out[s] ||= []).push(f); (inc[tg] ||= []).push(f); }
20
+ const body = nodes.map(([type, nid, name]) => {
21
+ const io = `${(inc[nid] || []).map((f) => `<bpmn:incoming>${f}</bpmn:incoming>`).join('')}${(out[nid] || []).map((f) => `<bpmn:outgoing>${f}</bpmn:outgoing>`).join('')}`;
22
+ return ` <bpmn:${type} id="${nid}"${name ? ` name="${name}"` : ''}>${io}</bpmn:${type}>`;
23
+ }).join('\n');
24
+ const seq = flows.map(([f, s, tg]) => ` <bpmn:sequenceFlow id="${f}" sourceRef="${s}" targetRef="${tg}"/>`).join('\n');
25
+ return ` <bpmn:process id="${id}" isExecutable="false">\n${body}\n${seq}\n </bpmn:process>`;
26
+ }
27
+
28
+ export function emitDemo(dir) {
29
+ mkdirSync(join(dir, 'decisions'), { recursive: true });
30
+ mkdirSync(join(dir, 'forms'), { recursive: true });
31
+ mkdirSync(join(dir, 'subprocesses'), { recursive: true });
32
+ mkdirSync(join(dir, 'pools'), { recursive: true });
33
+
34
+ // entry: Rendelés kezelése
35
+ writeFileSync(join(dir, 'main.bpmn'), defs(proc('Process_rendeles', [
36
+ ['startEvent', 'Start_beerkezes', 'Beérkezés'],
37
+ ['userTask', 'Task_rendeles_rogzitese', 'Rendelés rögzítése'],
38
+ ['businessRuleTask', 'Rule_arazas', 'Árazás'],
39
+ ['callActivity', 'Call_visszaterites', 'Visszatérítés'],
40
+ ['exclusiveGateway', 'Gateway_dontes', 'Elfogadva?'],
41
+ ['endEvent', 'End_kesz', 'Kész'],
42
+ ['endEvent', 'End_elutasitva', 'Elutasítva'],
43
+ ], [
44
+ ['Flow_1', 'Start_beerkezes', 'Task_rendeles_rogzitese'],
45
+ ['Flow_2', 'Task_rendeles_rogzitese', 'Rule_arazas'],
46
+ ['Flow_3', 'Rule_arazas', 'Gateway_dontes'],
47
+ ['Flow_4', 'Gateway_dontes', 'Call_visszaterites'],
48
+ ['Flow_5', 'Call_visszaterites', 'End_elutasitva'],
49
+ ['Flow_6', 'Gateway_dontes', 'End_kesz'],
50
+ ])));
51
+
52
+ // sub-process reached by the call activity
53
+ writeFileSync(join(dir, 'subprocesses', 'refund.bpmn'), defs(proc('Process_visszaterites', [
54
+ ['startEvent', 'Start_v', 'Kezdés'],
55
+ ['serviceTask', 'Service_utalas', 'Utalás indítása'],
56
+ ['endEvent', 'End_v', 'Vége'],
57
+ ], [
58
+ ['Flow_v1', 'Start_v', 'Service_utalas'],
59
+ ['Flow_v2', 'Service_utalas', 'End_v'],
60
+ ])));
61
+
62
+ // second participant pool: Raktár
63
+ writeFileSync(join(dir, 'pools', 'shop.bpmn'), defs(proc('Process_raktar', [
64
+ ['startEvent', 'Start_r', 'Rendelés'],
65
+ ['userTask', 'Task_osszekeszites', 'Összekészítés'],
66
+ ['endEvent', 'End_r', 'Kiszállítva'],
67
+ ], [
68
+ ['Flow_r1', 'Start_r', 'Task_osszekeszites'],
69
+ ['Flow_r2', 'Task_osszekeszites', 'End_r'],
70
+ ])));
71
+
72
+ // single-decision DMN (needs no DI to render in the decision-table view)
73
+ writeFileSync(join(dir, 'decisions', 'arazas.dmn'), `<?xml version="1.0" encoding="UTF-8"?>
74
+ <definitions xmlns="https://www.omg.org/spec/DMN/20191111/MODEL/" id="Def_arazas" name="Árazás" namespace="http://camunda.org/dmn">
75
+ <decision id="Decision_arazas" name="Árazás">
76
+ <decisionTable id="DT_arazas" hitPolicy="UNIQUE">
77
+ <input id="in1" label="Összeg"><inputExpression id="ie1" typeRef="number"><text>osszeg</text></inputExpression></input>
78
+ <output id="out1" label="Kedvezmény" typeRef="number"/>
79
+ <rule id="r1"><inputEntry id="i1"><text>&lt; 10000</text></inputEntry><outputEntry id="o1"><text>0</text></outputEntry></rule>
80
+ <rule id="r2"><inputEntry id="i2"><text>&gt;= 10000</text></inputEntry><outputEntry id="o2"><text>5</text></outputEntry></rule>
81
+ </decisionTable>
82
+ </decision>
83
+ </definitions>
84
+ `);
85
+
86
+ // form schema (structural JSON object)
87
+ writeFileSync(join(dir, 'forms', 'rendeles.form'), JSON.stringify({
88
+ type: 'object',
89
+ title: 'Rendelés rögzítése',
90
+ components: [
91
+ { key: 'nev', type: 'textfield', label: 'Név' },
92
+ { key: 'osszeg', type: 'number', label: 'Összeg' },
93
+ ],
94
+ }, null, 2));
95
+
96
+ // manifest
97
+ writeFileSync(join(dir, 'package.yaml'), `name: Rendelés kezelése
98
+ entry: main.bpmn
99
+ bindings:
100
+ - kind: form
101
+ ref: forms/rendeles.form
102
+ element: Task_rendeles_rogzitese
103
+ name: Rendelés rögzítése
104
+ - kind: decision
105
+ ref: decisions/arazas.dmn
106
+ element: Rule_arazas
107
+ name: Árazás
108
+ - kind: process
109
+ ref: subprocesses/refund.bpmn
110
+ element: Call_visszaterites
111
+ name: Visszatérítés
112
+ - kind: participant
113
+ ref: pools/shop.bpmn
114
+ name: Raktár
115
+ roles:
116
+ - element: Task_rendeles_rogzitese
117
+ role: Ügyfélszolgálat
118
+ name: Rendelés rögzítése
119
+ `);
120
+
121
+ return dir;
122
+ }
123
+
124
+ if (import.meta.url === `file://${process.argv[1]}`) {
125
+ const dir = process.argv[2] || mkdtempSync(join(tmpdir(), 'bpmn-demo-'));
126
+ emitDemo(dir);
127
+ console.log(dir);
128
+ }
@@ -0,0 +1,37 @@
1
+ // Package diagnostics channel (§6.17, viewer §7.16).
2
+ //
3
+ // Every warning produced during generation and validation is written to
4
+ // `diagnostics.json` inside the package so the viewer shell can surface it to an
5
+ // operator who only opens the served URL — no access to the generating terminal
6
+ // required.
7
+
8
+ import { writeFileSync, readFileSync, existsSync } from 'node:fs';
9
+ import { join } from 'node:path';
10
+
11
+ export const DIAGNOSTICS_FILE = 'diagnostics.json';
12
+
13
+ /**
14
+ * Write the package diagnostics file.
15
+ * @param pkgDir package root
16
+ * @param payload { errors?, warnings?, diagnostics?, guard? } — arrays of
17
+ * { code, message } (or the guard's { code, elements, detail, corrective })
18
+ */
19
+ export function writeDiagnostics(pkgDir, payload) {
20
+ const norm = (arr) => (arr || []).map((x) =>
21
+ x.detail
22
+ ? { code: x.code, message: `${x.detail} → ${x.corrective}`, elements: x.elements }
23
+ : { code: x.code, message: x.message, elements: x.elements });
24
+ const out = {
25
+ generatedAt: new Date().toISOString(),
26
+ errors: norm(payload.errors),
27
+ warnings: norm(payload.warnings),
28
+ notes: norm(payload.diagnostics),
29
+ };
30
+ writeFileSync(join(pkgDir, DIAGNOSTICS_FILE), JSON.stringify(out, null, 2));
31
+ return out;
32
+ }
33
+
34
+ export function readDiagnostics(pkgDir) {
35
+ const p = join(pkgDir, DIAGNOSTICS_FILE);
36
+ return existsSync(p) ? JSON.parse(readFileSync(p, 'utf8')) : null;
37
+ }
@@ -0,0 +1,160 @@
1
+ // Authoring envelope — the semantics-only generation contract (§3).
2
+ //
3
+ // Confines GENERATED BPMN to the measured-safe construct set, rejects geometry,
4
+ // vendor namespaces and the three data-loss constructs (inline subProcess,
5
+ // collaboration, laneSet) plus messageFlow, each with a specific substitution
6
+ // diagnostic. Governs AUTHORING only; ingestion of laid-out files is lenient
7
+ // (see checkIngested).
8
+
9
+ // Constructs the authoring step may generate. `serviceTask`/`userTask` are
10
+ // covered by fixture 1-linear, `task` by 2-gateway; the rest are provisional
11
+ // and each is confirmed by its own fixture (scripts/fixtures.mjs) before
12
+ // implementation proceeds against it.
13
+ export const ALLOW_LIST = [
14
+ 'startEvent', 'endEvent', 'intermediateCatchEvent', 'intermediateThrowEvent',
15
+ 'task', 'userTask', 'serviceTask', 'businessRuleTask', 'manualTask',
16
+ 'scriptTask', 'sendTask', 'receiveTask', 'callActivity',
17
+ 'exclusiveGateway', 'parallelGateway', 'boundaryEvent', 'sequenceFlow',
18
+ ];
19
+
20
+ // Element-type → identifier prefix (normative table, §4.1).
21
+ export const PREFIX = {
22
+ startEvent: 'Start', endEvent: 'End',
23
+ intermediateCatchEvent: 'CatchEvent', intermediateThrowEvent: 'ThrowEvent',
24
+ boundaryEvent: 'Boundary',
25
+ task: 'Activity', userTask: 'Task', serviceTask: 'Service',
26
+ businessRuleTask: 'Rule', manualTask: 'Manual', scriptTask: 'Script',
27
+ sendTask: 'Send', receiveTask: 'Receive', callActivity: 'Call',
28
+ exclusiveGateway: 'Gateway', parallelGateway: 'Fork', sequenceFlow: 'Flow',
29
+ };
30
+
31
+ // Bindable element types (a binding/role may target these; must be named).
32
+ export const BINDABLE = new Set(['userTask', 'businessRuleTask', 'callActivity']);
33
+
34
+ const VENDOR_NS = ['camunda', 'zeebe', 'activiti', 'flowable'];
35
+
36
+ function localName(tag) {
37
+ const m = tag.match(/^<\/?([A-Za-z0-9_]+:)?([A-Za-z0-9_]+)/);
38
+ return m ? { prefix: (m[1] || '').replace(':', ''), name: m[2] } : null;
39
+ }
40
+
41
+ /**
42
+ * Check AUTHORED (generated) BPMN XML against the envelope. Returns
43
+ * { ok, diagnostics:[{code, message}] }. Any diagnostic is a hard error:
44
+ * authoring aborts. No element is ever dropped silently.
45
+ */
46
+ export function checkAuthored(xml) {
47
+ const d = [];
48
+ const add = (code, message) => d.push({ code, message });
49
+
50
+ // Semantics-only: reject any DI or hand-written coordinate.
51
+ if (/<(\w+:)?BPMNDiagram[\s>]/.test(xml) || /<bpmndi:/.test(xml)) {
52
+ add('DI-PRESENT', 'authored output contains bpmndi: geometry; coordinates are produced exclusively by the layout step, not authored');
53
+ }
54
+ if (/<(\w+:)?Bounds[\s/>]/.test(xml) || /<dc:Bounds/.test(xml)) {
55
+ add('DC-BOUNDS', 'authored output contains a dc:Bounds element; coordinates are produced by the layout step');
56
+ }
57
+ if (/<(\w+:)?waypoint[\s/>]/.test(xml) || /<di:waypoint/.test(xml)) {
58
+ add('DI-WAYPOINT', 'authored output contains a di:waypoint; edge geometry is produced by the layout step');
59
+ }
60
+
61
+ // Plain BPMN 2.0 only: reject vendor namespaces, elements, attributes.
62
+ for (const ns of VENDOR_NS) {
63
+ if (new RegExp(`xmlns:${ns}\\s*=`).test(xml) || new RegExp(`[<\\s]${ns}:`).test(xml)) {
64
+ add('VENDOR-NS', `authored output references the '${ns}:' vendor namespace; the .bpmn must stay plain BPMN 2.0 — put link information in package.yaml, not in a vendor extension`);
65
+ }
66
+ }
67
+
68
+ // Rejected data-loss constructs with substitution diagnostics.
69
+ if (/<(\w+:)?subProcess[\s>]/.test(xml)) {
70
+ add('SUBPROCESS', 'inline subProcess is rejected: the layout step assigns child elements coordinates identical to parent-level elements (measured G1+G3 corruption). Emit a callActivity referencing a separate .bpmn file, bound in the manifest with kind: process.');
71
+ }
72
+ if (/<(\w+:)?collaboration[\s>]/.test(xml)) {
73
+ add('COLLABORATION', 'collaboration/participant is rejected: the layout step lays out only the first process, so further participants, lanes and message flows lose geometry. Emit one .bpmn file per participant, each bound with kind: participant.');
74
+ }
75
+ if (/<(\w+:)?laneSet[\s>]/.test(xml)) {
76
+ add('LANESET', 'laneSet/lane is rejected: lane shapes are never emitted by the layout step. Use manifest roles entries instead.');
77
+ }
78
+ if (/<(\w+:)?messageFlow[\s>]/.test(xml)) {
79
+ add('MESSAGEFLOW', 'messageFlow is rejected: pool decomposition into one file per participant leaves cross-participant message flows unrepresentable in this change. sendTask/receiveTask are allowed but their counterpart link is not drawn.');
80
+ }
81
+
82
+ // Multiple boundary events on one activity — measured to OVERLAP (fixture
83
+ // provisional/multi-boundary: two boundary events land at 190.33–226.33 and
84
+ // 223.66–259.66, both y=92, colliding). A SINGLE boundary event is supported
85
+ // (fixture 3-boundary passes); a second on the same host is outside the
86
+ // measured-safe envelope (2.3a/2.3b).
87
+ {
88
+ const attach = {};
89
+ const be = /<(\w+:)?boundaryEvent\b[^>]*\battachedToRef="([^"]+)"/g;
90
+ let bm;
91
+ while ((bm = be.exec(xml))) { attach[bm[2]] = (attach[bm[2]] || 0) + 1; }
92
+ for (const [host, count] of Object.entries(attach)) {
93
+ if (count > 1) add('MULTI-BOUNDARY', `activity '${host}' carries ${count} boundary events; the layout step overlaps multiple boundary events on one activity (measured), so only a single boundary event per activity is supported. Split the interruptions across separate activities.`);
94
+ }
95
+ }
96
+
97
+ // Supported-construct allow-list: reject any flow element outside the list.
98
+ // Scan element tags in the bpmn namespace that are flow elements.
99
+ const tagRe = /<(\w+):([A-Za-z][A-Za-z0-9]*)[\s/>]/g;
100
+ const seen = new Set();
101
+ let m;
102
+ const NON_FLOW = new Set([
103
+ 'definitions', 'process', 'incoming', 'outgoing', 'extensionElements',
104
+ 'documentation', 'text', 'flowNodeRef', 'timerEventDefinition',
105
+ 'messageEventDefinition', 'errorEventDefinition', 'signalEventDefinition',
106
+ 'conditionExpression', 'multiInstanceLoopCharacteristics', 'ioSpecification',
107
+ 'dataInput', 'dataOutput', 'property',
108
+ ]);
109
+ while ((m = tagRe.exec(xml))) {
110
+ const [, prefix, name] = m;
111
+ if (prefix === 'bpmndi' || prefix === 'dc' || prefix === 'di') continue;
112
+ if (NON_FLOW.has(name)) continue;
113
+ if (name.endsWith('EventDefinition')) continue;
114
+ seen.add(name);
115
+ }
116
+ for (const name of seen) {
117
+ // messageFlow/subProcess/collaboration/laneSet already reported above
118
+ if (['subProcess', 'collaboration', 'laneSet', 'lane', 'participant', 'messageFlow'].includes(name)) continue;
119
+ if (!ALLOW_LIST.includes(name)) {
120
+ add('NOT-ALLOWED', `construct '${name}' is not in the authoring allow-list; only measured-safe constructs may be generated (see references/authoring-envelope.md)`);
121
+ }
122
+ }
123
+
124
+ return { ok: d.length === 0, diagnostics: d };
125
+ }
126
+
127
+ /**
128
+ * Ingestion posture: a file authored elsewhere and carrying DI is lenient —
129
+ * a rejected construct becomes a WARNING, not a refusal, because the envelope
130
+ * governs generation, not ingestion of already-laid-out diagrams. A DI-LESS
131
+ * ingested file is handled by the layout guard's strict precedence instead
132
+ * (refused if it contains a rejected construct) — see scripts/view.mjs.
133
+ */
134
+ export function checkIngestedWithDI(xml) {
135
+ const warnings = [];
136
+ if (/<(\w+:)?subProcess[\s>]/.test(xml)) warnings.push('file contains an inline subProcess (rendered as authored; the envelope only governs generation)');
137
+ if (/<(\w+:)?laneSet[\s>]/.test(xml)) warnings.push('file contains lanes (rendered as authored)');
138
+ if (/<(\w+:)?collaboration[\s>]/.test(xml)) warnings.push('file contains a collaboration (rendered as authored)');
139
+ return { ok: true, warnings };
140
+ }
141
+
142
+ /**
143
+ * Non-fatal authoring warnings (§8.8). A sendTask/receiveTask is accepted, but
144
+ * its message-flow counterpart is not drawn (pool decomposition), so the author
145
+ * is warned that the link is not rendered.
146
+ */
147
+ export function authoringWarnings(xml) {
148
+ const warnings = [];
149
+ if (/<(\w+:)?sendTask[\s>]/.test(xml) || /<(\w+:)?receiveTask[\s>]/.test(xml)) {
150
+ warnings.push({ code: 'UNLINKED-MESSAGE-TASK', message: 'the process contains a sendTask/receiveTask; its message-flow counterpart in another participant is not drawn (cross-participant message flows are unrepresentable after pool decomposition in this change)' });
151
+ }
152
+ return warnings;
153
+ }
154
+
155
+ /** Which rejected construct (if any) a DI-less ingested file contains. */
156
+ export function rejectedConstructIn(xml) {
157
+ const r = checkAuthored(xml);
158
+ const blocking = r.diagnostics.filter((x) => ['SUBPROCESS', 'COLLABORATION', 'LANESET', 'MESSAGEFLOW'].includes(x.code));
159
+ return blocking.length ? blocking : null;
160
+ }
@@ -0,0 +1,140 @@
1
+ #!/usr/bin/env node
2
+ // Fixture regression suite. Runs every fixture through layout (when semantics-
3
+ // only) and the layout guard (strict mode), asserting the RECORDED outcome.
4
+ //
5
+ // Runs headless under Node: no browser, no network, no node_modules. If an
6
+ // outcome changes, an upstream `bpmn-auto-layout` version bump has drifted and
7
+ // the suite fails (layout-guard spec "Upstream behaviour change is detected").
8
+ //
9
+ // node scripts/fixtures.mjs
10
+
11
+ import { readFileSync, readdirSync } from 'node:fs';
12
+ import { fileURLToPath } from 'node:url';
13
+ import { dirname, join } from 'node:path';
14
+ import { parse, layout, xmlHasDI } from './pipeline.mjs';
15
+ import { runGuard } from './guard.mjs';
16
+ import { ALLOW_LIST } from './envelope.mjs';
17
+
18
+ const SKILL = dirname(dirname(fileURLToPath(import.meta.url)));
19
+ const F = join(SKILL, 'fixtures');
20
+
21
+ // ── Recorded expected outcomes ──────────────────────────────────────────
22
+ // pass:true → strict guard reports no violation.
23
+ // pass:false → strict guard MUST report a violation including `codes`.
24
+ const EXPECTED = {
25
+ // eight measured fixtures
26
+ 'measured/1-linear.bpmn': { pass: true },
27
+ 'measured/2-gateway.bpmn': { pass: true },
28
+ 'measured/3-boundary.bpmn': { pass: true },
29
+ 'measured/7-loop.bpmn': { pass: true },
30
+ 'measured/8-long-chain.bpmn': { pass: true },
31
+ 'measured/4-subprocess.bpmn': { pass: false, codes: ['G1', 'G3'] }, // identical bounds + non-containment
32
+ 'measured/5-pools.bpmn': { pass: false, codes: ['P1'] }, // missing shapes (2nd participant)
33
+ 'measured/6-lanes-only.bpmn': { pass: false, codes: ['P1'] }, // lane shapes absent
34
+ // provisional constructs — each must lay out cleanly to stay in the allow-list
35
+ 'provisional/manual-task.bpmn': { pass: true },
36
+ 'provisional/script-task.bpmn': { pass: true },
37
+ 'provisional/send-task.bpmn': { pass: true },
38
+ 'provisional/receive-task.bpmn': { pass: true },
39
+ 'provisional/call-activity.bpmn': { pass: true },
40
+ 'provisional/parallel-gateway.bpmn': { pass: true },
41
+ 'provisional/rule-task.bpmn': { pass: true },
42
+ 'provisional/intermediate-catch.bpmn': { pass: true },
43
+ 'provisional/intermediate-throw.bpmn': { pass: true },
44
+ // 2.3a/2.3b: measured evidence — two boundary events on one activity OVERLAP
45
+ // (Boundary_timer 190.33–226.33 vs Boundary_error 223.66–259.66, both y=92).
46
+ // The construct is therefore NOT in the safe envelope; authoring rejects it.
47
+ 'provisional/multi-boundary.bpmn': { pass: false, codes: ['G5'] },
48
+ // synthetic geometric-violation fixtures (carry DI; strict-guarded, not laid out)
49
+ 'geometry/g1-identical-bounds.bpmn': { pass: false, codes: ['G1'] },
50
+ 'geometry/g2-zero-size.bpmn': { pass: false, codes: ['G2'] },
51
+ 'geometry/g3-child-outside.bpmn': { pass: false, codes: ['G3'] },
52
+ 'geometry/g4-negative-coord.bpmn': { pass: false, codes: ['G4'] },
53
+ 'geometry/g5-overlap.bpmn': { pass: false, codes: ['G5'] },
54
+ // correct expanded sub-process (carries DI) — guard must NOT fire
55
+ 'nesting/expanded-subprocess-ok.bpmn': { pass: true },
56
+ };
57
+
58
+ // Which fixture establishes each allow-listed construct (2.8 agreement).
59
+ const CONSTRUCT_FIXTURE = {
60
+ startEvent: 'measured/1-linear.bpmn',
61
+ endEvent: 'measured/1-linear.bpmn',
62
+ userTask: 'measured/1-linear.bpmn',
63
+ serviceTask: 'measured/1-linear.bpmn',
64
+ task: 'measured/2-gateway.bpmn',
65
+ exclusiveGateway: 'measured/2-gateway.bpmn',
66
+ boundaryEvent: 'measured/3-boundary.bpmn',
67
+ sequenceFlow: 'measured/1-linear.bpmn',
68
+ manualTask: 'provisional/manual-task.bpmn',
69
+ scriptTask: 'provisional/script-task.bpmn',
70
+ sendTask: 'provisional/send-task.bpmn',
71
+ receiveTask: 'provisional/receive-task.bpmn',
72
+ callActivity: 'provisional/call-activity.bpmn',
73
+ parallelGateway: 'provisional/parallel-gateway.bpmn',
74
+ businessRuleTask: 'provisional/rule-task.bpmn',
75
+ intermediateCatchEvent: 'provisional/intermediate-catch.bpmn',
76
+ intermediateThrowEvent: 'provisional/intermediate-throw.bpmn',
77
+ };
78
+
79
+ function listFixtures() {
80
+ const out = [];
81
+ for (const sub of ['measured', 'provisional', 'geometry', 'nesting']) {
82
+ for (const f of readdirSync(join(F, sub))) {
83
+ if (f.endsWith('.bpmn')) out.push(`${sub}/${f}`);
84
+ }
85
+ }
86
+ return out.sort();
87
+ }
88
+
89
+ async function evaluate(rel) {
90
+ const xml = readFileSync(join(F, rel), 'utf8');
91
+ let toGuard = xml;
92
+ if (!xmlHasDI(xml)) {
93
+ // semantics-only → lay it out (this run's geometry → strict)
94
+ toGuard = await layout(xml);
95
+ }
96
+ const { rootElement } = await parse(toGuard);
97
+ return runGuard(rootElement, { mode: 'strict' });
98
+ }
99
+
100
+ async function main() {
101
+ let failures = 0;
102
+ const files = listFixtures();
103
+
104
+ // 1) every fixture must have a recorded expectation
105
+ for (const rel of files) {
106
+ if (!(rel in EXPECTED)) { console.error(`NO EXPECTATION for ${rel}`); failures++; }
107
+ }
108
+
109
+ // 2) run each fixture and compare to recorded outcome
110
+ for (const rel of files) {
111
+ const exp = EXPECTED[rel];
112
+ if (!exp) continue;
113
+ let res;
114
+ try { res = await evaluate(rel); }
115
+ catch (e) { console.error(`ERROR ${rel}: ${e.message}`); failures++; continue; }
116
+ const codes = res.violations.map((v) => v.code);
117
+ if (exp.pass) {
118
+ if (res.ok) console.log(`PASS ${rel}`);
119
+ else { console.error(`FAIL ${rel} expected pass, got violations [${codes.join(',')}]`); failures++; }
120
+ } else {
121
+ const hasExpected = (exp.codes || []).some((c) => codes.includes(c));
122
+ if (!res.ok && hasExpected) console.log(`PASS ${rel} (correctly failed: [${codes.join(',')}])`);
123
+ else { console.error(`FAIL ${rel} expected failure with one of [${(exp.codes || []).join(',')}], got ok=${res.ok} [${codes.join(',')}]`); failures++; }
124
+ }
125
+ }
126
+
127
+ // 3) allow-list ⊆ fixtures agreement (2.8)
128
+ for (const construct of ALLOW_LIST) {
129
+ const fx = CONSTRUCT_FIXTURE[construct];
130
+ if (!fx) { console.error(`ALLOW-LIST construct '${construct}' has NO fixture`); failures++; continue; }
131
+ const exp = EXPECTED[fx];
132
+ if (!exp || !exp.pass) { console.error(`ALLOW-LIST construct '${construct}' fixture ${fx} does not pass`); failures++; }
133
+ }
134
+ console.log(`\nallow-list constructs: ${ALLOW_LIST.length}, all mapped to a passing fixture: ${ALLOW_LIST.every((c) => CONSTRUCT_FIXTURE[c] && EXPECTED[CONSTRUCT_FIXTURE[c]]?.pass)}`);
135
+
136
+ if (failures) { console.error(`\n${failures} fixture check(s) failed`); process.exit(1); }
137
+ console.log(`\nAll ${files.length} fixtures match their recorded outcomes.`);
138
+ }
139
+
140
+ main();
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env node
2
+ // Build a package (envelope → manifest validation → layout + guard) and assemble
3
+ // a render root ready to serve. Fails loudly; stops before serving on any error.
4
+ //
5
+ // node scripts/generate-cli.mjs <packageDir> [renderOutDir]
6
+ // → prints the render-root path on success (serve it with serve_mockup)
7
+
8
+ import { buildPackage, WorkflowError } from './generate.mjs';
9
+ import { assembleRenderRoot } from './render.mjs';
10
+
11
+ const [pkgDir, outDir] = process.argv.slice(2);
12
+ if (!pkgDir) { console.error('usage: node scripts/generate-cli.mjs <packageDir> [renderOutDir]'); process.exit(1); }
13
+
14
+ try {
15
+ const { validation } = await buildPackage(pkgDir);
16
+ if (!validation.ok) {
17
+ console.error('MANIFEST VALIDATION FAILED — not serving:');
18
+ for (const e of validation.errors) console.error(` [${e.code}] ${e.message}`);
19
+ process.exit(2);
20
+ }
21
+ for (const w of validation.warnings) console.error(` warning [${w.code}] ${w.message}`);
22
+ const { renderRoot } = await assembleRenderRoot(pkgDir, outDir);
23
+ console.log(renderRoot);
24
+ } catch (e) {
25
+ if (e instanceof WorkflowError) {
26
+ console.error(`PIPELINE ABORTED at stage '${e.stage}':`);
27
+ console.error(JSON.stringify(e.detail, null, 2));
28
+ process.exit(3);
29
+ }
30
+ throw e;
31
+ }
@@ -0,0 +1,103 @@
1
+ // Generation + display workflows (§8).
2
+ //
3
+ // The AGENT authors the semantics-only .bpmn files, the .dmn / .form artifacts
4
+ // and package.yaml (guided by the references). This module runs the mechanical
5
+ // pipeline over them, in order, each step failing loudly rather than degrading:
6
+ //
7
+ // 1. author semantics (agent; validated here by the envelope)
8
+ // 2. author artifacts (agent)
9
+ // 3. write package.yaml (agent)
10
+ // 4. validate the manifest ← stops before serving on error (8.2)
11
+ // 5. layout + layout guard ← strict; aborts on a corrupt diagram
12
+ // 6. serve + canvas (render.mjs / the skill)
13
+
14
+ import { readFileSync, writeFileSync, existsSync } from 'node:fs';
15
+ import { join } from 'node:path';
16
+ import { xmlHasDI } from './pipeline.mjs';
17
+ import { checkAuthored, authoringWarnings } from './envelope.mjs';
18
+ import { guardXml } from './runguard.mjs';
19
+ import { loadManifest, validatePackage } from './manifest.mjs';
20
+ import { writeDiagnostics } from './diagnostics.mjs';
21
+
22
+ export class WorkflowError extends Error {
23
+ constructor(stage, detail) { super(`${stage}: ${JSON.stringify(detail)}`); this.stage = stage; this.detail = detail; }
24
+ }
25
+
26
+ /** The .bpmn files a package owns: entry + participant/process refs. */
27
+ export function packageBpmnFiles(manifest) {
28
+ const files = new Set([manifest.entry]);
29
+ for (const b of manifest.bindings || []) {
30
+ if ((b.kind === 'process' || b.kind === 'participant') && b.ref) files.add(b.ref);
31
+ }
32
+ return [...files];
33
+ }
34
+
35
+ /**
36
+ * Lay out one generated semantics-only .bpmn, verify strict, write DI back into
37
+ * the file (it is a generated file, not an operator file). A file already
38
+ * carrying DI is left untouched (D5: the file is the source of truth).
39
+ */
40
+ export async function layoutGeneratedFile(pkgDir, relFile) {
41
+ const p = join(pkgDir, relFile);
42
+ const xml = readFileSync(p, 'utf8');
43
+ if (xmlHasDI(xml)) return { file: relFile, skipped: true };
44
+ const env = checkAuthored(xml);
45
+ if (!env.ok) throw new WorkflowError('envelope', { file: relFile, diagnostics: env.diagnostics });
46
+ const g = await guardXml(xml, { provenance: 'generated' });
47
+ if (!g.result.ok) throw new WorkflowError('guard', { file: relFile, violations: g.result.violations });
48
+ writeFileSync(p, g.laidOut);
49
+ return { file: relFile, laidOut: true };
50
+ }
51
+
52
+ /**
53
+ * Full build over an assembled package directory. Returns
54
+ * { validation, laidOut }. Throws WorkflowError on envelope/guard failure;
55
+ * returns validation.ok=false (without serving) on a manifest error (8.2).
56
+ */
57
+ export async function buildPackage(pkgDir) {
58
+ const { manifest, errors } = loadManifest(pkgDir);
59
+ if (errors.length) throw new WorkflowError('manifest-parse', errors);
60
+
61
+ // step 1: envelope-check every generated (DI-less) .bpmn before anything else
62
+ const files = packageBpmnFiles(manifest).filter((f) => existsSync(join(pkgDir, f)));
63
+ for (const f of files) {
64
+ const xml = readFileSync(join(pkgDir, f), 'utf8');
65
+ if (!xmlHasDI(xml)) {
66
+ const env = checkAuthored(xml);
67
+ if (!env.ok) throw new WorkflowError('envelope', { file: f, diagnostics: env.diagnostics });
68
+ }
69
+ }
70
+
71
+ // step 4: validate the manifest — stop before serving on error
72
+ const validation = await validatePackage(pkgDir);
73
+ if (!validation.ok) { writeDiagnostics(pkgDir, validation); return { validation, laidOut: [] }; }
74
+
75
+ // step 5: layout + guard (strict)
76
+ const laidOut = [];
77
+ for (const f of files) laidOut.push(await layoutGeneratedFile(pkgDir, f));
78
+
79
+ // 8.8 — collect sendTask/receiveTask unlinked-counterpart warnings
80
+ const authorWarn = [];
81
+ for (const f of files) authorWarn.push(...authoringWarnings(readFileSync(join(pkgDir, f), 'utf8')).map((w) => ({ ...w, message: `${f}: ${w.message}` })));
82
+
83
+ // re-validate after layout (element resolution unaffected, but keeps diagnostics fresh)
84
+ const post = await validatePackage(pkgDir);
85
+ post.warnings = [...post.warnings, ...authorWarn];
86
+ writeDiagnostics(pkgDir, post);
87
+ return { validation: post, laidOut };
88
+ }
89
+
90
+ // ── standalone view of a single file (§8.4, 8.5) ────────────────────────
91
+ /**
92
+ * Prepare a standalone .bpmn/.dmn for viewing WITHOUT a manifest.
93
+ * A DI-bearing file renders as authored (advisory). A DI-less .bpmn is laid out
94
+ * strictly and written to a SEPARATE render artifact, never over the source.
95
+ * Returns { renderXml, mode, refused?, diagnostics? }.
96
+ */
97
+ export async function prepareStandalone(srcPath) {
98
+ const xml = readFileSync(srcPath, 'utf8');
99
+ if (srcPath.endsWith('.dmn')) return { renderXml: xml, mode: 'dmn' };
100
+ const g = await guardXml(xml, { provenance: 'ingested' });
101
+ if (g.refused) return { refused: true, diagnostics: g.diagnostics };
102
+ return { renderXml: g.laidOut, mode: g.mode, warnings: g.result.warnings };
103
+ }