@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,335 @@
1
+ // Layout guard — verifies a laid-out BPMN document against its own semantics.
2
+ //
3
+ // Every measured failure mode of `bpmn-auto-layout` produces schema-valid XML
4
+ // that parses through `bpmn-moddle` with zero errors (see references/
5
+ // layout-envelope.md). Verification therefore compares the DI against the
6
+ // semantics along two axes — Presence (P1–P3) and Geometry (G1–G5) — plus the
7
+ // collaboration data-loss signature. It NEVER relies on the layout function
8
+ // raising.
9
+ //
10
+ // Two modes (layout-guard spec "Two guard modes with an explicit precedence"):
11
+ // * strict — geometry produced by THIS run. Any violation aborts (ok:false).
12
+ // This is where "no corrupt diagram is ever written" holds.
13
+ // * advisory — geometry already on disk when read. Every violation is a
14
+ // warning; the document still renders (ok:true). G4 is not even
15
+ // evaluated in advisory mode (negative coords are legal DI).
16
+ //
17
+ // Provenance is computed, not historical: geometry produced by the current
18
+ // layout run is strict; geometry already present on disk is advisory.
19
+
20
+ const FLOW_NODE_TYPES = new Set([
21
+ 'bpmn:StartEvent', 'bpmn:EndEvent', 'bpmn:IntermediateCatchEvent',
22
+ 'bpmn:IntermediateThrowEvent', 'bpmn:BoundaryEvent',
23
+ 'bpmn:Task', 'bpmn:UserTask', 'bpmn:ServiceTask', 'bpmn:BusinessRuleTask',
24
+ 'bpmn:ManualTask', 'bpmn:ScriptTask', 'bpmn:SendTask', 'bpmn:ReceiveTask',
25
+ 'bpmn:CallActivity', 'bpmn:SubProcess', 'bpmn:AdHocSubProcess', 'bpmn:Transaction',
26
+ 'bpmn:ExclusiveGateway', 'bpmn:ParallelGateway', 'bpmn:InclusiveGateway',
27
+ 'bpmn:ComplexGateway', 'bpmn:EventBasedGateway',
28
+ ]);
29
+ const CONTAINER_TYPES = new Set([
30
+ 'bpmn:SubProcess', 'bpmn:AdHocSubProcess', 'bpmn:Transaction',
31
+ ]);
32
+ const ARTIFACT_TYPES = new Set([
33
+ 'bpmn:TextAnnotation', 'bpmn:Group', 'bpmn:DataObjectReference',
34
+ 'bpmn:DataStoreReference', 'bpmn:DataObject', 'bpmn:DataStoreReference',
35
+ ]);
36
+ const FLOW_TYPES = new Set(['bpmn:SequenceFlow', 'bpmn:MessageFlow']);
37
+
38
+ /**
39
+ * Walk the semantics of a parsed Definitions.
40
+ * Returns maps keyed by element id.
41
+ */
42
+ export function collectSemantics(rootElement) {
43
+ const flowNodes = new Map(); // id -> { type, parentId|null, attachedTo|null, isContainer }
44
+ const flows = new Map(); // id -> { type }
45
+ const participants = new Map(); // id -> { processRef }
46
+ const lanes = new Map(); // id -> { name }
47
+ const artifacts = new Map(); // id -> { type }
48
+ const containerChildren = new Map(); // containerId -> Set(childId)
49
+
50
+ const roots = rootElement.rootElements || [];
51
+
52
+ function walkProcess(proc, ownerContainerId) {
53
+ for (const fe of proc.flowElements || []) {
54
+ const t = fe.$type;
55
+ if (FLOW_TYPES.has(t)) {
56
+ flows.set(fe.id, { type: t });
57
+ } else if (ARTIFACT_TYPES.has(t)) {
58
+ artifacts.set(fe.id, { type: t });
59
+ } else if (FLOW_NODE_TYPES.has(t)) {
60
+ const isContainer = CONTAINER_TYPES.has(t);
61
+ flowNodes.set(fe.id, {
62
+ type: t,
63
+ parentId: ownerContainerId || null,
64
+ attachedTo: fe.attachedToRef ? fe.attachedToRef.id : null,
65
+ isContainer,
66
+ });
67
+ if (ownerContainerId) {
68
+ if (!containerChildren.has(ownerContainerId)) containerChildren.set(ownerContainerId, new Set());
69
+ containerChildren.get(ownerContainerId).add(fe.id);
70
+ }
71
+ if (isContainer) walkProcess(fe, fe.id); // recurse into sub-process children
72
+ } else {
73
+ // artifacts not in the set, or unknown — record loosely as artifact
74
+ artifacts.set(fe.id, { type: t });
75
+ }
76
+ }
77
+ for (const ls of proc.laneSets || []) {
78
+ for (const lane of ls.lanes || []) lanes.set(lane.id, { name: lane.name || null });
79
+ }
80
+ // artifacts array (annotations/associations live here in some models)
81
+ for (const a of proc.artifacts || []) {
82
+ if (a.$type === 'bpmn:Association') continue;
83
+ artifacts.set(a.id, { type: a.$type });
84
+ }
85
+ }
86
+
87
+ for (const r of roots) {
88
+ if (r.$type === 'bpmn:Process') {
89
+ walkProcess(r, null);
90
+ } else if (r.$type === 'bpmn:Collaboration') {
91
+ for (const p of r.participants || []) {
92
+ participants.set(p.id, { processRef: p.processRef ? p.processRef.id : null });
93
+ }
94
+ for (const mf of r.messageFlows || []) flows.set(mf.id, { type: 'bpmn:MessageFlow' });
95
+ }
96
+ }
97
+ // processes referenced by participants but sitting as sibling rootElements
98
+ for (const r of roots) {
99
+ if (r.$type === 'bpmn:Process') { /* already walked above */ }
100
+ }
101
+
102
+ return { flowNodes, flows, participants, lanes, artifacts, containerChildren };
103
+ }
104
+
105
+ /** Collect DI: shapes and edges across every plane. */
106
+ export function collectDI(rootElement) {
107
+ const shapes = new Map(); // bpmnElementId -> [ { bounds, isExpanded, planeId } ]
108
+ const edges = new Map(); // bpmnElementId -> [ { waypoints, planeId } ]
109
+ const planeOf = new Map(); // bpmnElementId -> planeId (first)
110
+ const planes = [];
111
+
112
+ for (const dia of rootElement.diagrams || []) {
113
+ const plane = dia.plane;
114
+ if (!plane) continue;
115
+ const planeId = plane.bpmnElement ? plane.bpmnElement.id : `plane_${planes.length}`;
116
+ planes.push(planeId);
117
+ for (const pe of plane.planeElement || []) {
118
+ const ref = pe.bpmnElement ? pe.bpmnElement.id : null;
119
+ if (pe.$type === 'bpmndi:BPMNShape') {
120
+ const b = pe.bounds || {};
121
+ const entry = { bounds: { x: b.x, y: b.y, width: b.width, height: b.height }, isExpanded: pe.isExpanded, planeId };
122
+ if (!shapes.has(ref)) shapes.set(ref, []);
123
+ shapes.get(ref).push(entry);
124
+ if (!planeOf.has(ref)) planeOf.set(ref, planeId);
125
+ } else if (pe.$type === 'bpmndi:BPMNEdge') {
126
+ const entry = { waypoints: pe.waypoint || [], planeId };
127
+ if (!edges.has(ref)) edges.set(ref, []);
128
+ edges.get(ref).push(entry);
129
+ }
130
+ }
131
+ }
132
+ return { shapes, edges, planeOf, planes };
133
+ }
134
+
135
+ function boundsEqual(a, b) {
136
+ return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
137
+ }
138
+ function rectsOverlap(a, b) {
139
+ return a.x < b.x + b.width && a.x + a.width > b.x &&
140
+ a.y < b.y + b.height && a.y + a.height > b.y;
141
+ }
142
+ function contains(outer, inner) {
143
+ return inner.x >= outer.x && inner.y >= outer.y &&
144
+ inner.x + inner.width <= outer.x + outer.width &&
145
+ inner.y + inner.height <= outer.y + outer.height;
146
+ }
147
+
148
+ /**
149
+ * Run the guard.
150
+ * @param rootElement parsed Definitions
151
+ * @param opts { mode: 'strict'|'advisory' }
152
+ * @returns { ok, mode, violations:[{code,elements,detail,corrective}], warnings:[...] }
153
+ * In strict mode ok is false when any violation exists.
154
+ * In advisory mode ok is always true; violations are reported as warnings.
155
+ */
156
+ export function runGuard(rootElement, { mode = 'strict' } = {}) {
157
+ const sem = collectSemantics(rootElement);
158
+ const di = collectDI(rootElement);
159
+ const v = []; // violations
160
+
161
+ const record = (code, elements, detail, corrective) =>
162
+ v.push({ code, elements, detail, corrective });
163
+
164
+ // ── Presence ──────────────────────────────────────────────────────────
165
+ // P1 — every flow node, participant and lane owns exactly one BPMNShape.
166
+ const shapeBearing = [
167
+ ...[...sem.flowNodes.keys()].map((id) => [id, 'flow node']),
168
+ ...[...sem.participants.keys()].map((id) => [id, 'participant']),
169
+ ...[...sem.lanes.keys()].map((id) => [id, 'lane']),
170
+ ];
171
+ const missingShape = [];
172
+ for (const [id, what] of shapeBearing) {
173
+ const n = (di.shapes.get(id) || []).length;
174
+ if (n !== 1) missingShape.push({ id, what, count: n });
175
+ }
176
+ if (missingShape.length) {
177
+ record('P1', missingShape.map((m) => m.id),
178
+ `every flow node, participant and lane must own exactly one BPMNShape; ` +
179
+ missingShape.map((m) => `${m.id} (${m.what}) has ${m.count}`).join(', '),
180
+ 'ensure the layout produced a shape for each semantic element; a collaboration ' +
181
+ 'or lane set that lost geometry must be emitted as one .bpmn per participant ' +
182
+ 'with kind: participant bindings, and lanes as manifest roles');
183
+ }
184
+
185
+ // P2 — every sequence/message flow owns exactly one edge with >= 2 waypoints.
186
+ const badEdge = [];
187
+ for (const [id] of sem.flows) {
188
+ const list = di.edges.get(id) || [];
189
+ if (list.length !== 1) { badEdge.push({ id, reason: `owns ${list.length} edges` }); continue; }
190
+ const wp = list[0].waypoints || [];
191
+ if (wp.length < 2) badEdge.push({ id, reason: `edge carries ${wp.length} waypoints` });
192
+ }
193
+ if (badEdge.length) {
194
+ record('P2', badEdge.map((b) => b.id),
195
+ `every sequenceFlow/messageFlow must own one BPMNEdge with >= 2 waypoints; ` +
196
+ badEdge.map((b) => `${b.id} ${b.reason}`).join(', '),
197
+ 'regenerate layout; a waypoint-less or missing edge indicates a layout failure');
198
+ }
199
+
200
+ // P3 — no shape or edge references an element absent from the semantics.
201
+ const known = new Set([
202
+ ...sem.flowNodes.keys(), ...sem.participants.keys(), ...sem.lanes.keys(),
203
+ ...sem.flows.keys(), ...sem.artifacts.keys(),
204
+ ]);
205
+ const extraneous = [];
206
+ for (const id of di.shapes.keys()) if (id && !known.has(id)) extraneous.push(`shape ${id}`);
207
+ for (const id of di.edges.keys()) if (id && !known.has(id)) extraneous.push(`edge ${id}`);
208
+ if (extraneous.length) {
209
+ record('P3', extraneous,
210
+ `DI references elements absent from the semantics: ${extraneous.join(', ')}`,
211
+ 'remove the extraneous geometry; the DI must reference only semantic elements');
212
+ }
213
+
214
+ // Collaboration data-loss signature: a declared participant/lane with no shape.
215
+ // (Already covered by P1, but name it explicitly for the collaboration case.)
216
+ const lostCollab = missingShape.filter((m) => m.what !== 'flow node' && m.count === 0);
217
+ if (lostCollab.length) {
218
+ record('COLLAB', lostCollab.map((m) => m.id),
219
+ `only the first process received a plane; these received no shape: ` +
220
+ lostCollab.map((m) => `${m.id} (${m.what})`).join(', '),
221
+ 'emit one .bpmn per participant with kind: participant bindings, and lanes as manifest roles');
222
+ }
223
+
224
+ // ── Geometry ──────────────────────────────────────────────────────────
225
+ // Build per-plane shape lists (single-shape elements only; ignore missing).
226
+ const perPlane = new Map(); // planeId -> [ {id, bounds, type} ]
227
+ for (const [id, list] of di.shapes) {
228
+ for (const s of list) {
229
+ if (!perPlane.has(s.planeId)) perPlane.set(s.planeId, []);
230
+ const type = sem.flowNodes.get(id)?.type || sem.participants.get(id)?.type ||
231
+ (sem.lanes.has(id) ? 'bpmn:Lane' : (sem.artifacts.get(id)?.type || 'unknown'));
232
+ perPlane.get(s.planeId).push({ id, bounds: s.bounds, type });
233
+ }
234
+ }
235
+
236
+ // G1 — no two shapes in a plane share identical bounds.
237
+ for (const [planeId, list] of perPlane) {
238
+ for (let i = 0; i < list.length; i++) {
239
+ for (let j = i + 1; j < list.length; j++) {
240
+ const a = list[i], b = list[j];
241
+ if (a.bounds.x != null && boundsEqual(a.bounds, b.bounds)) {
242
+ record('G1', [a.id, b.id],
243
+ `${a.id} and ${b.id} share identical bounds ` +
244
+ `${a.bounds.x},${a.bounds.y},${a.bounds.width},${a.bounds.height} in plane ${planeId}`,
245
+ 'this is the measured inline-subProcess corruption signature; replace the ' +
246
+ 'sub-process with a callActivity + separate .bpmn file + kind: process binding');
247
+ }
248
+ }
249
+ }
250
+ }
251
+
252
+ // G2 — every shape has non-zero width and height.
253
+ for (const [id, list] of di.shapes) {
254
+ for (const s of list) {
255
+ if (!(s.bounds.width > 0) || !(s.bounds.height > 0)) {
256
+ record('G2', [id],
257
+ `${id} has zero-or-negative size ${s.bounds.width}x${s.bounds.height}`,
258
+ 'a shape must have positive width and height; regenerate layout');
259
+ }
260
+ }
261
+ }
262
+
263
+ // G3 — a child of an expanded container lies within that container's bounds.
264
+ for (const [containerId, childIds] of sem.containerChildren) {
265
+ const contShapes = di.shapes.get(containerId) || [];
266
+ if (!contShapes.length) continue;
267
+ const cont = contShapes[0];
268
+ // Only enforce for an EXPANDED container whose children sit in the same plane.
269
+ const expanded = cont.isExpanded !== false;
270
+ if (!expanded) continue;
271
+ for (const childId of childIds) {
272
+ const cs = (di.shapes.get(childId) || [])[0];
273
+ if (!cs) continue;
274
+ if (cs.planeId !== cont.planeId) continue; // collapsed-plane children exempt
275
+ if (cont.bounds.x != null && cs.bounds.x != null && !contains(cont.bounds, cs.bounds)) {
276
+ record('G3', [containerId, childId],
277
+ `child ${childId} at ${cs.bounds.x},${cs.bounds.y},${cs.bounds.width},${cs.bounds.height} ` +
278
+ `lies outside expanded container ${containerId} bounds ` +
279
+ `${cont.bounds.x},${cont.bounds.y},${cont.bounds.width},${cont.bounds.height}`,
280
+ 'this is the measured inline-subProcess corruption signature; replace the ' +
281
+ 'sub-process with a callActivity + separate .bpmn file + kind: process binding');
282
+ }
283
+ }
284
+ }
285
+
286
+ // G4 — no negative coordinate. STRICT MODE ONLY.
287
+ if (mode === 'strict') {
288
+ for (const [id, list] of di.shapes) {
289
+ for (const s of list) {
290
+ if (s.bounds.x < 0 || s.bounds.y < 0) {
291
+ record('G4', [id],
292
+ `${id} has a negative coordinate ${s.bounds.x},${s.bounds.y}`,
293
+ 'generated geometry must not be negative; regenerate layout');
294
+ }
295
+ }
296
+ }
297
+ }
298
+
299
+ // G5 — no overlap between FLOW NODE shapes not in host/boundary or container/child.
300
+ for (const [planeId, list] of perPlane) {
301
+ const flowNodeShapes = list.filter((s) => sem.flowNodes.has(s.id) && !CONTAINER_TYPES.has(s.type));
302
+ for (let i = 0; i < flowNodeShapes.length; i++) {
303
+ for (let j = i + 1; j < flowNodeShapes.length; j++) {
304
+ const a = flowNodeShapes[i], b = flowNodeShapes[j];
305
+ if (a.bounds.x == null || b.bounds.x == null) continue;
306
+ if (!rectsOverlap(a.bounds, b.bounds)) continue;
307
+ // exempt host/boundary
308
+ const an = sem.flowNodes.get(a.id), bn = sem.flowNodes.get(b.id);
309
+ if (an.attachedTo === b.id || bn.attachedTo === a.id) continue;
310
+ // exempt container/child
311
+ if (an.parentId === b.id || bn.parentId === a.id) continue;
312
+ record('G5', [a.id, b.id],
313
+ `flow-node shapes ${a.id} and ${b.id} overlap and are not in a ` +
314
+ `host/boundary or container/child relationship`,
315
+ 'regenerate layout; unrelated flow nodes must not overlap');
316
+ }
317
+ }
318
+ }
319
+
320
+ const ok = mode === 'advisory' ? true : v.length === 0;
321
+ return {
322
+ ok,
323
+ mode,
324
+ violations: mode === 'strict' ? v : [],
325
+ warnings: mode === 'advisory' ? v : [],
326
+ };
327
+ }
328
+
329
+ /** Format a guard result as human diagnostics. */
330
+ export function formatDiagnostics(result) {
331
+ const items = result.mode === 'advisory' ? result.warnings : result.violations;
332
+ return items.map((it) =>
333
+ `[${it.code}] elements: ${it.elements.join(', ')}\n ${it.detail}\n → ${it.corrective}`
334
+ ).join('\n');
335
+ }
@@ -0,0 +1,12 @@
1
+ // Tiny shared test harness for the skill's self-tests. No dependencies.
2
+ let passed = 0, failed = 0;
3
+
4
+ export async function t(name, fn) {
5
+ try { await fn(); passed++; console.log(`ok ${name}`); }
6
+ catch (e) { failed++; console.error(`FAIL ${name}\n ${e.message}`); }
7
+ }
8
+
9
+ export function report() {
10
+ console.log(`\n${passed} passed, ${failed} failed`);
11
+ if (failed) process.exit(1);
12
+ }
@@ -0,0 +1,117 @@
1
+ // Deterministic identifier derivation and naming/uniqueness rules (§4).
2
+ //
3
+ // GOVERNS AUTHORING ONLY. Once a .bpmn exists its identifiers are opaque and are
4
+ // never re-derived (see isOpaqueExistingFile / preserveIdentifiers). A named
5
+ // element's id is `<Prefix>_<slug(deburr(name))>`, a pure function of type+name
6
+ // with no positional state; an unnamed element gets an ordinal discriminator and
7
+ // is not bindable.
8
+
9
+ import { PREFIX, BINDABLE } from './envelope.mjs';
10
+
11
+ /** Strip diacritics to ASCII. Hungarian ő/ű decompose to o/u under NFKD. */
12
+ export function deburr(str) {
13
+ return (str || '')
14
+ .normalize('NFKD')
15
+ .replace(/[\u0300-\u036f]/g, '') // combining marks
16
+ .replace(/[^\x00-\x7f]/g, ''); // any remaining non-ASCII
17
+ }
18
+
19
+ /** name → slug: lowercase, deburr, non-alphanumeric runs → single underscore. */
20
+ export function slug(name) {
21
+ return deburr(String(name).toLowerCase())
22
+ .replace(/[^a-z0-9]+/g, '_')
23
+ .replace(/^_+|_+$/g, '');
24
+ }
25
+
26
+ export function prefixFor(type) {
27
+ const p = PREFIX[type];
28
+ if (!p) throw new Error(`no identifier prefix for element type '${type}'`);
29
+ return p;
30
+ }
31
+
32
+ /** Derive the id of a single NAMED element. Pure function of type + name. */
33
+ export function deriveNamedId(type, name) {
34
+ return `${prefixFor(type)}_${slug(name)}`;
35
+ }
36
+
37
+ /**
38
+ * Derive identifiers for a whole authored process and enforce the naming and
39
+ * uniqueness rules. Input: elements = [{ key, type, name }] (key is any stable
40
+ * caller handle). Returns { ids: Map(key->id), diagnostics: [{code,message}] }.
41
+ * Any diagnostic is a hard error.
42
+ *
43
+ * Rules:
44
+ * 4.8 two elements sharing a prefix may not share a name
45
+ * 4.9 two elements may not produce the same id after deburring (xsd:ID)
46
+ * 4.10 a bindable element (userTask/businessRuleTask/callActivity) must be named
47
+ * 4.4 an unnamed non-bindable element gets an ordinal discriminator
48
+ */
49
+ export function deriveIdentifiers(elements) {
50
+ const diagnostics = [];
51
+ const add = (code, message) => diagnostics.push({ code, message });
52
+ const ids = new Map();
53
+
54
+ // 4.10 — bindable elements must be named.
55
+ for (const el of elements) {
56
+ if (BINDABLE.has(el.type) && !(el.name && String(el.name).trim())) {
57
+ add('UNNAMED-BINDABLE', `${el.type} '${el.key}' has no name; a bindable element requires a name to derive a stable identifier`);
58
+ }
59
+ }
60
+
61
+ // 4.8 — duplicate name within a shared prefix.
62
+ const byPrefixName = new Map(); // `${prefix}\u0000${name}` -> [keys]
63
+ for (const el of elements) {
64
+ if (!(el.name && String(el.name).trim())) continue;
65
+ const k = `${prefixFor(el.type)}\u0000${el.name}`;
66
+ if (!byPrefixName.has(k)) byPrefixName.set(k, []);
67
+ byPrefixName.get(k).push(el.key);
68
+ }
69
+ for (const [k, keys] of byPrefixName) {
70
+ if (keys.length > 1) {
71
+ const name = k.split('\u0000')[1];
72
+ add('DUP-NAME', `elements ${keys.join(', ')} share the prefix and the name '${name}'; disambiguate the names (e.g. '${name} (manager)' and '${name} (finance)')`);
73
+ }
74
+ }
75
+
76
+ // Derive ids: named → slug; unnamed → ordinal per prefix.
77
+ const ordinalCounter = new Map();
78
+ for (const el of elements) {
79
+ if (el.name && String(el.name).trim()) {
80
+ ids.set(el.key, deriveNamedId(el.type, el.name));
81
+ } else {
82
+ const pfx = prefixFor(el.type);
83
+ const n = (ordinalCounter.get(pfx) || 0) + 1;
84
+ ordinalCounter.set(pfx, n);
85
+ ids.set(el.key, `${pfx}_${n}`);
86
+ }
87
+ }
88
+
89
+ // 4.9 — post-deburr duplicate identifier (would be an invalid duplicate xsd:ID).
90
+ const byId = new Map();
91
+ for (const [key, id] of ids) {
92
+ if (!byId.has(id)) byId.set(id, []);
93
+ byId.get(id).push(key);
94
+ }
95
+ for (const [id, keys] of byId) {
96
+ if (keys.length > 1) {
97
+ add('DUP-ID', `elements ${keys.join(', ')} produce the same identifier '${id}' after deburring; a duplicate xsd:ID is invalid XML — rename to differ after diacritic removal`);
98
+ }
99
+ }
100
+
101
+ return { ids, diagnostics, ok: diagnostics.length === 0 };
102
+ }
103
+
104
+ /** Which element ids are ordinal (unnamed) and therefore NOT bindable (4.5). */
105
+ export function unnamedOrdinalIds(elements) {
106
+ const set = new Set();
107
+ const ordinalCounter = new Map();
108
+ for (const el of elements) {
109
+ if (!(el.name && String(el.name).trim())) {
110
+ const pfx = prefixFor(el.type);
111
+ const n = (ordinalCounter.get(pfx) || 0) + 1;
112
+ ordinalCounter.set(pfx, n);
113
+ set.add(`${pfx}_${n}`);
114
+ }
115
+ }
116
+ return set;
117
+ }
@@ -0,0 +1,95 @@
1
+ // Ingestion boundary (§4.11–4.14): an existing .bpmn is source-of-truth. Its
2
+ // identifiers are OPAQUE — never re-derived, re-slugged or normalised — and the
3
+ // authoring naming rules become warnings, not refusals. Regenerating an existing
4
+ // file from prose is refused.
5
+
6
+ import { collectSemantics } from './guard.mjs';
7
+ import { deriveIdentifiers } from './identifiers.mjs';
8
+ import { BINDABLE } from './envelope.mjs';
9
+
10
+ /**
11
+ * Extract authored elements from a parsed Definitions as
12
+ * [{ key, id, type, name }], type stripped of the bpmn: prefix and lower-cased
13
+ * to match the PREFIX table keys. key === id (the on-disk identifier).
14
+ */
15
+ export function extractElements(rootElement) {
16
+ const { flowNodes } = collectSemantics(rootElement);
17
+ const out = [];
18
+ // names live on the semantic element; re-walk to fetch them.
19
+ const nameById = new Map();
20
+ for (const r of rootElement.rootElements || []) {
21
+ walkNames(r, nameById);
22
+ }
23
+ for (const [id, info] of flowNodes) {
24
+ const type = info.type.replace('bpmn:', '');
25
+ const t = type.charAt(0).toLowerCase() + type.slice(1);
26
+ out.push({ key: id, id, type: t, name: nameById.get(id) || null });
27
+ }
28
+ return out;
29
+ }
30
+ function walkNames(node, map) {
31
+ for (const fe of node.flowElements || []) {
32
+ if (fe.name != null) map.set(fe.id, fe.name);
33
+ if (fe.flowElements) walkNames(fe, map);
34
+ }
35
+ }
36
+
37
+ /**
38
+ * 4.11 — identifier opacity. Returns the file's identifiers unchanged. This is
39
+ * the whole implementation: ingested ids are used as-is, never passed through
40
+ * deriveIdentifiers.
41
+ */
42
+ export function existingIdentifiers(rootElement) {
43
+ return extractElements(rootElement).map((e) => e.id);
44
+ }
45
+
46
+ /**
47
+ * 4.12 — naming rules produce WARNINGS on an existing file, never a refusal.
48
+ * Runs the same duplicate-name / unnamed-bindable checks the authoring path
49
+ * uses, but downgrades every diagnostic to a warning.
50
+ */
51
+ export function ingestionWarnings(rootElement) {
52
+ const els = extractElements(rootElement);
53
+ const warnings = [];
54
+ // duplicate names / duplicate ids — reuse the authoring logic, downgrade.
55
+ const { diagnostics } = deriveIdentifiers(
56
+ // deriveIdentifiers would derive slug ids; here we only want its rule
57
+ // detection, so feed the real names but ignore the returned ids.
58
+ els.map((e) => ({ key: e.id, type: e.type, name: e.name }))
59
+ );
60
+ for (const d of diagnostics) {
61
+ warnings.push(`${d.code} (ingested, not enforced): ${d.message}`);
62
+ }
63
+ return { warnings };
64
+ }
65
+
66
+ /**
67
+ * 4.13 — refuse to regenerate an existing .bpmn from prose. Lists the manifest
68
+ * bindings and roles that reference the file, which regeneration would
69
+ * invalidate. `manifest` is the parsed package.yaml object; `relPath` is the
70
+ * file's path relative to the package root (matched against binding.in / entry).
71
+ */
72
+ export function refuseRegeneration(relPath, manifest, entry) {
73
+ const invalidated = [];
74
+ const target = relPath;
75
+ const ownerOf = (b) => (b.in || entry);
76
+ for (const b of manifest?.bindings || []) {
77
+ if (b.kind === 'participant') { if (b.ref === target) invalidated.push(`participant binding '${b.name || b.ref}'`); continue; }
78
+ if (b.kind === 'process' && b.ref === target) invalidated.push(`process binding on ${b.element} → ${b.ref}`);
79
+ if (ownerOf(b) === target) invalidated.push(`${b.kind} binding on ${b.element} (in ${ownerOf(b)})`);
80
+ }
81
+ for (const r of manifest?.roles || []) {
82
+ if ((r.in || entry) === target) invalidated.push(`role '${r.role}' on ${r.element} (in ${r.in || entry})`);
83
+ }
84
+ return {
85
+ refuse: true,
86
+ reason: `${relPath} already exists and is the source of truth; edit it in place rather than regenerating from prose`,
87
+ invalidatedBindings: invalidated,
88
+ };
89
+ }
90
+
91
+ /** True if every id in `before` is still present (unchanged) in `after`. */
92
+ export function identifiersPreserved(beforeIds, afterIds) {
93
+ const after = new Set(afterIds);
94
+ return beforeIds.every((id) => after.has(id));
95
+ }