@bpmnkit/core 1.0.0 → 1.2.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 (73) hide show
  1. package/README.md +30 -3
  2. package/dist/bpmn/agentic.js +3 -1
  3. package/dist/bpmn/auto-layout.js +184 -15
  4. package/dist/bpmn/bpmn-builder.js +69 -7
  5. package/dist/bpmn/bpmn-model.d.ts +78 -0
  6. package/dist/bpmn/bpmn-parser.js +195 -37
  7. package/dist/bpmn/bpmn-serializer.js +121 -72
  8. package/dist/bpmn/bpmnlint.d.ts +153 -0
  9. package/dist/bpmn/bpmnlint.js +364 -0
  10. package/dist/bpmn/camunda-compat-data.d.ts +165 -0
  11. package/dist/bpmn/camunda-compat-data.js +423 -0
  12. package/dist/bpmn/camunda-compat-feel.d.ts +68 -0
  13. package/dist/bpmn/camunda-compat-feel.js +338 -0
  14. package/dist/bpmn/camunda-compat.d.ts +120 -0
  15. package/dist/bpmn/camunda-compat.js +1677 -0
  16. package/dist/bpmn/camunda7/juel.d.ts +41 -0
  17. package/dist/bpmn/camunda7/juel.js +333 -0
  18. package/dist/bpmn/camunda7/migrate.d.ts +72 -0
  19. package/dist/bpmn/camunda7/migrate.js +1152 -0
  20. package/dist/bpmn/compact.d.ts +4 -0
  21. package/dist/bpmn/compact.js +80 -0
  22. package/dist/bpmn/full-operations.js +5 -2
  23. package/dist/bpmn/label-style.d.ts +51 -0
  24. package/dist/bpmn/label-style.js +116 -0
  25. package/dist/bpmn/lint.d.ts +23 -3
  26. package/dist/bpmn/lint.js +47 -10
  27. package/dist/bpmn/optimize/bpmnlint-rules.d.ts +31 -0
  28. package/dist/bpmn/optimize/bpmnlint-rules.js +916 -0
  29. package/dist/bpmn/optimize/deploy.d.ts +8 -2
  30. package/dist/bpmn/optimize/deploy.js +16 -3
  31. package/dist/bpmn/optimize/index.js +11 -2
  32. package/dist/bpmn/optimize/patterns.js +3 -0
  33. package/dist/bpmn/optimize/types.d.ts +14 -0
  34. package/dist/bpmn/optimize/variable-flow.js +4 -1
  35. package/dist/bpmn/process-delta.d.ts +88 -0
  36. package/dist/bpmn/process-delta.js +236 -0
  37. package/dist/bpmn/process-text-writer.d.ts +53 -0
  38. package/dist/bpmn/process-text-writer.js +193 -0
  39. package/dist/bpmn/process-text.d.ts +175 -0
  40. package/dist/bpmn/process-text.js +1255 -0
  41. package/dist/bpmn/process-types.d.ts +112 -0
  42. package/dist/bpmn/process-types.js +490 -0
  43. package/dist/bpmn/svg.js +51 -22
  44. package/dist/doc/docx.d.ts +20 -0
  45. package/dist/doc/docx.js +253 -0
  46. package/dist/doc/html.d.ts +21 -0
  47. package/dist/doc/html.js +303 -0
  48. package/dist/doc/index.d.ts +7 -0
  49. package/dist/doc/index.js +5 -0
  50. package/dist/doc/markdown.d.ts +11 -0
  51. package/dist/doc/markdown.js +160 -0
  52. package/dist/doc/model.d.ts +129 -0
  53. package/dist/doc/model.js +617 -0
  54. package/dist/doc/zip.d.ts +5 -0
  55. package/dist/doc/zip.js +75 -0
  56. package/dist/index.d.ts +22 -0
  57. package/dist/index.js +11 -0
  58. package/dist/layout/annotations.d.ts +4 -2
  59. package/dist/layout/annotations.js +31 -2
  60. package/dist/layout/collaboration/ordering.d.ts +8 -0
  61. package/dist/layout/collaboration/ordering.js +57 -18
  62. package/dist/layout/orthogonal.d.ts +32 -0
  63. package/dist/layout/orthogonal.js +367 -0
  64. package/dist/layout/repair.d.ts +31 -0
  65. package/dist/layout/repair.js +220 -0
  66. package/dist/layout/semantic/route.js +45 -3
  67. package/dist/node/bpmnlint.d.ts +109 -0
  68. package/dist/node/bpmnlint.js +198 -0
  69. package/dist/node/index.d.ts +2 -0
  70. package/dist/node/index.js +1 -0
  71. package/dist/xml/xml-patch.d.ts +21 -0
  72. package/dist/xml/xml-patch.js +27 -1
  73. package/package.json +2 -2
@@ -0,0 +1,1677 @@
1
+ /**
2
+ * Camunda version compatibility — what Camunda Modeler reports through
3
+ * `@camunda/linting` when a diagram uses something the Camunda 8 version it
4
+ * targets cannot run, or leaves out a property that version requires.
5
+ *
6
+ * The target is read from `modeler:executionPlatformVersion` on
7
+ * `<bpmn:definitions>`, or pinned by a `.bpmnlintrc` that extends
8
+ * `plugin:camunda-compat/camunda-cloud-X-Y`. Which construct needs which
9
+ * version lives in `camunda-compat-data.ts`, taken from
10
+ * `bpmnlint-plugin-camunda-compat`; this module applies it. Findings are
11
+ * `compat/<plugin rule name>`, in the `deploy` category: they are deployability
12
+ * findings for the target version, and a new category would widen a union the
13
+ * 1.0 API returns.
14
+ *
15
+ * Problems an existing `deploy/*` (or `feel/*`) check already reports on the
16
+ * same element are left to that check — see `dedupeCamundaCompat`.
17
+ *
18
+ * @packageDocumentation
19
+ */
20
+ import { CAMUNDA_COMPAT_RULES, CAMUNDA_COMPAT_VERSIONS, CRON_TIMER_SINCE, ELEMENT_SUPPORT, FEATURE_SINCE, FEEL_BUILTIN_SINCE, IMPLEMENTATION_SUPPORT, INBOUND_CONNECTOR_PROPERTY_SINCE, TIMER_SUPPORT, } from "./camunda-compat-data.js";
21
+ import { SECRET_REFERENCE_LITERAL, feelBuiltinCalls, fromAiCalls, secretReferenceViolations, } from "./camunda-compat-feel.js";
22
+ // ---------------------------------------------------------------------------
23
+ // Versions
24
+ // ---------------------------------------------------------------------------
25
+ const NEWEST = CAMUNDA_COMPAT_VERSIONS[CAMUNDA_COMPAT_VERSIONS.length - 1];
26
+ function rank(version) {
27
+ return CAMUNDA_COMPAT_VERSIONS.indexOf(version);
28
+ }
29
+ function atLeast(version, since) {
30
+ return rank(version) >= rank(since);
31
+ }
32
+ /**
33
+ * Reduces a Camunda version to the `major.minor` the compatibility tables use:
34
+ * `"8.6.2"` → `"8.6"`. A Camunda 8 version newer than the tables is checked as
35
+ * the newest one they know, since later versions only lift restrictions.
36
+ *
37
+ * @param raw - A version such as `modeler:executionPlatformVersion` holds.
38
+ * @returns The table version, or `undefined` for anything that is not a
39
+ * Camunda Cloud 1.x or Camunda 8 version.
40
+ */
41
+ export function normalizeCamundaVersion(raw) {
42
+ const match = /^\s*(\d+)\.(\d+)/.exec(raw ?? "");
43
+ if (match === null)
44
+ return undefined;
45
+ const major = Number(match[1]);
46
+ const minor = Number(match[2]);
47
+ const exact = CAMUNDA_COMPAT_VERSIONS.find((v) => v === `${major}.${minor}`);
48
+ if (exact !== undefined)
49
+ return exact;
50
+ return major === 8 && minor > 10 ? NEWEST : undefined;
51
+ }
52
+ /**
53
+ * The Camunda version a model targets, from `modeler:executionPlatform` (a
54
+ * Camunda Cloud / Camunda 8 platform) and `modeler:executionPlatformVersion`.
55
+ *
56
+ * @param definitions - The model to read.
57
+ * @returns The table version, or `undefined` when the model targets no
58
+ * Camunda 8 version — then no compatibility check runs, as in Modeler.
59
+ */
60
+ export function targetCamundaVersion(definitions) {
61
+ const platform = definitions.unknownAttributes["modeler:executionPlatform"];
62
+ if (platform === undefined || !platform.toLowerCase().includes("cloud"))
63
+ return undefined;
64
+ return normalizeCamundaVersion(definitions.unknownAttributes["modeler:executionPlatformVersion"]);
65
+ }
66
+ function ruleActive(rule, version) {
67
+ const entry = CAMUNDA_COMPAT_RULES[rule];
68
+ if (entry === undefined)
69
+ return false;
70
+ if (entry.since !== undefined && !atLeast(version, entry.since))
71
+ return false;
72
+ return entry.until === undefined || !atLeast(version, entry.until);
73
+ }
74
+ function isContainer(el) {
75
+ return "flowElements" in el;
76
+ }
77
+ function isEventSubProcess(el) {
78
+ return (el !== undefined &&
79
+ (el.type === "eventSubProcess" || (el.type === "subProcess" && el.triggeredByEvent === true)));
80
+ }
81
+ const CATCH_EVENTS = new Set(["startEvent", "intermediateCatchEvent", "boundaryEvent"]);
82
+ const THROW_EVENTS = new Set(["intermediateThrowEvent", "endEvent"]);
83
+ const TASKS = new Set([
84
+ "task",
85
+ "serviceTask",
86
+ "scriptTask",
87
+ "userTask",
88
+ "sendTask",
89
+ "receiveTask",
90
+ "businessRuleTask",
91
+ "manualTask",
92
+ ]);
93
+ const ACTIVITIES = new Set([
94
+ ...TASKS,
95
+ "callActivity",
96
+ "subProcess",
97
+ "adHocSubProcess",
98
+ "eventSubProcess",
99
+ "transaction",
100
+ ]);
101
+ function eventDefinitionOf(el) {
102
+ return "eventDefinitions" in el ? el.eventDefinitions[0] : undefined;
103
+ }
104
+ function bpmnType(el) {
105
+ if (el.type === "eventSubProcess")
106
+ return "bpmn:SubProcess";
107
+ return `bpmn:${el.type.charAt(0).toUpperCase()}${el.type.slice(1)}`;
108
+ }
109
+ function bpmnEventDefinitionType(def) {
110
+ return `bpmn:${def.type.charAt(0).toUpperCase()}${def.type.slice(1)}EventDefinition`;
111
+ }
112
+ function zeebe(extensions, name) {
113
+ return (extensions ?? []).filter((e) => e.name === `zeebe:${name}`);
114
+ }
115
+ function children(parent, name) {
116
+ return parent === undefined ? [] : parent.children.filter((c) => c.name === `zeebe:${name}`);
117
+ }
118
+ function isEmpty(value) {
119
+ return value === undefined || value === "";
120
+ }
121
+ const TYPE_LABEL = {
122
+ startEvent: "start event",
123
+ endEvent: "end event",
124
+ intermediateThrowEvent: "intermediate throw event",
125
+ intermediateCatchEvent: "intermediate catch event",
126
+ boundaryEvent: "boundary event",
127
+ task: "task",
128
+ serviceTask: "service task",
129
+ scriptTask: "script task",
130
+ userTask: "user task",
131
+ sendTask: "send task",
132
+ receiveTask: "receive task",
133
+ businessRuleTask: "business rule task",
134
+ manualTask: "manual task",
135
+ callActivity: "call activity",
136
+ exclusiveGateway: "exclusive gateway",
137
+ parallelGateway: "parallel gateway",
138
+ inclusiveGateway: "inclusive gateway",
139
+ eventBasedGateway: "event-based gateway",
140
+ complexGateway: "complex gateway",
141
+ subProcess: "sub-process",
142
+ adHocSubProcess: "ad-hoc sub-process",
143
+ eventSubProcess: "event sub-process",
144
+ transaction: "transaction",
145
+ dataObject: "data object",
146
+ dataObjectReference: "data object reference",
147
+ dataStoreReference: "data store reference",
148
+ };
149
+ /** `Signal end event "Notify"` — the event definition, the type, then the name. */
150
+ function describe(el, withDefinition = true) {
151
+ const def = withDefinition ? eventDefinitionOf(el) : undefined;
152
+ const type = TYPE_LABEL[el.type];
153
+ const label = def !== undefined
154
+ ? `${def.type} ${type}`
155
+ : el.type === "subProcess" && el.triggeredByEvent === true
156
+ ? "event sub-process"
157
+ : type;
158
+ return `${label.charAt(0).toUpperCase()}${label.slice(1)} "${el.name ?? el.id}"`;
159
+ }
160
+ // ---------------------------------------------------------------------------
161
+ // Timer value syntax — ported from the plugin's utils/iso8601.js and cron.js
162
+ // ---------------------------------------------------------------------------
163
+ const ISO_DATE_RE = /^(?<date>\d{4}-(?<month>0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01]))T(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](Z|([+-](0[0-9]|1[0-3]):[0-5][0-9](\[[^\]]+\])?))$/;
164
+ const ISO_DURATION = "P(?!$)(\\d+(\\.\\d+)?[Yy])?(\\d+(\\.\\d+)?[Mm])?(\\d+(\\.\\d+)?[Ww])?(\\d+(\\.\\d+)?[Dd])?(T(?!$)(\\d+(\\.\\d+)?[Hh])?(\\d+(\\.\\d+)?[Mm])?(\\d+(\\.\\d+)?[Ss])?)?$";
165
+ const ISO_DURATION_RE = new RegExp(`^${ISO_DURATION}$`);
166
+ const ISO_CYCLE_RE = new RegExp(`^R(-1|\\d+)?/(${ISO_DATE_RE.source.slice(1, -1)}/)?${ISO_DURATION}$`.replace(/\(\?<(date|month)>/g, "("));
167
+ function isIsoDate(value) {
168
+ const match = ISO_DATE_RE.exec(value);
169
+ if (match?.groups === undefined)
170
+ return false;
171
+ // Rejects dates like 2024-02-31, which `Date` rolls into the next month.
172
+ return new Date(match.groups.date).getMonth() + 1 === Number(match.groups.month);
173
+ }
174
+ const cronAlt = (...patterns) => `(${patterns.join("|")})`;
175
+ const cronRange = (p) => `${p}(-${p})?`;
176
+ const cronList = (p) => `${p}(,${p})*`;
177
+ const cronStep = (p) => `${p}/\\d+`;
178
+ const CRON_SECOND = "([0-5]?[0-9])";
179
+ const CRON_HOUR = "([01]?[0-9]|2[0-3])";
180
+ const CRON_DOM = cronAlt(`L(-${cronAlt("[0-2]?[0-9]", "3[0-1]")})?`, "[0-2]?[0-9]", "3[0-1]", `${cronAlt("L", "[0-2]?[0-9]", "3[0-1]")}W`);
181
+ const CRON_MONTH = cronAlt("[0]?[1-9]", "1[0-2]", ..."JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC".split(" "));
182
+ const CRON_DOW = cronAlt("[0-7]", ..."MON TUE WED THU FRI SAT SUN".split(" "));
183
+ const cronTime = (p) => cronAlt("\\*", cronStep("\\*"), cronList(cronAlt(cronStep(p), cronRange(p))));
184
+ const CRON_RE = new RegExp(`^${[
185
+ cronTime(CRON_SECOND),
186
+ cronTime(CRON_SECOND),
187
+ cronTime(CRON_HOUR),
188
+ cronAlt("\\*", "\\?", cronList(cronRange(CRON_DOM))),
189
+ cronAlt("\\*", cronList(cronRange(CRON_MONTH))),
190
+ cronAlt("\\*", "\\?", cronList(cronAlt(cronRange(CRON_DOW), `${CRON_DOW}(#[1-5]|L)`))),
191
+ ].join(" ")}$`, "i");
192
+ const CRON_MACRO_RE = /^@(yearly|annually|monthly|weekly|daily|midnight|hourly)$/;
193
+ function isCron(value) {
194
+ return CRON_MACRO_RE.test(value) || CRON_RE.test(value);
195
+ }
196
+ // ---------------------------------------------------------------------------
197
+ // Analysis
198
+ // ---------------------------------------------------------------------------
199
+ const SEVERITY = { error: "error", warn: "warning" };
200
+ function report(ctx, rule, elementId, message, suggestion, severity) {
201
+ if (!ruleActive(rule, ctx.version))
202
+ return;
203
+ ctx.findings.push({
204
+ id: `compat/${rule}`,
205
+ category: "deploy",
206
+ severity: severity ?? SEVERITY[CAMUNDA_COMPAT_RULES[rule]?.severity ?? "error"],
207
+ message,
208
+ suggestion,
209
+ processId: ctx.process.id,
210
+ elementIds: [elementId],
211
+ });
212
+ }
213
+ function targets(ctx) {
214
+ return `this model targets Camunda ${ctx.version}`;
215
+ }
216
+ function raise(since) {
217
+ return `Target Camunda ${since} or newer (modeler:executionPlatformVersion), or remove it.`;
218
+ }
219
+ /**
220
+ * Checks a model against the Camunda 8 version it targets, the way
221
+ * `bpmnlint-plugin-camunda-compat` does in Camunda Modeler.
222
+ *
223
+ * Reports each element, event definition, Zeebe extension or property the
224
+ * target version does not support, and each property that version requires
225
+ * but the model leaves out. From Camunda 8.2 on, processes not marked
226
+ * executable are skipped, as Modeler skips them.
227
+ *
228
+ * @param definitions - The model to check.
229
+ * @param version - The target, e.g. `"8.6"` or `"8.6.2"`. Defaults to the
230
+ * model's own `modeler:executionPlatformVersion`.
231
+ * @returns `compat/*` findings; none when there is no Camunda 8 target.
232
+ *
233
+ * @example
234
+ * ```typescript
235
+ * const findings = analyzeCamundaCompat(Bpmn.parse(xml), "8.5");
236
+ * // compat/element-type: Ad-hoc sub-process "Tools" needs Camunda 8.7 or newer; ...
237
+ * ```
238
+ */
239
+ export function analyzeCamundaCompat(definitions, version) {
240
+ const target = version !== undefined ? normalizeCamundaVersion(version) : targetCamundaVersion(definitions);
241
+ if (target === undefined)
242
+ return [];
243
+ const findings = [];
244
+ for (const process of definitions.processes) {
245
+ if (atLeast(target, "8.2") && process.isExecutable !== true)
246
+ continue;
247
+ const ctx = {
248
+ version: target,
249
+ definitions,
250
+ process,
251
+ findings,
252
+ subProcessIds: new Set(),
253
+ elements: new Map(),
254
+ flows: new Map(),
255
+ };
256
+ locate(ctx, process.flowElements, process.sequenceFlows, undefined);
257
+ checkProcess(ctx);
258
+ checkScope(ctx, process.flowElements, process.sequenceFlows, undefined);
259
+ checkCollapsed(ctx);
260
+ checkContents(ctx);
261
+ }
262
+ return findings;
263
+ }
264
+ function locate(ctx, elements, flows, parent) {
265
+ for (const flow of flows)
266
+ ctx.flows.set(flow.id, { el: flow, parent });
267
+ for (const el of elements) {
268
+ ctx.elements.set(el.id, { el, parent });
269
+ if (isContainer(el))
270
+ locate(ctx, el.flowElements, el.sequenceFlows, el);
271
+ }
272
+ }
273
+ function checkProcess(ctx) {
274
+ const { process } = ctx;
275
+ const ext = process.extensionElements;
276
+ checkListeners(ctx, process.id, ext, `Process "${process.name ?? process.id}"`, true, false);
277
+ checkTemplate(ctx, process.id, process.unknownAttributes, `Process "${process.name ?? process.id}"`);
278
+ checkNoExtension(ctx, "no-zeebe-properties", process.id, ext, "properties", "Process");
279
+ const versionTag = zeebe(ext, "versionTag")[0];
280
+ if (versionTag !== undefined) {
281
+ report(ctx, "no-version-tag", process.id, `Process "${process.name ?? process.id}" has a zeebe:versionTag, which needs Camunda ${FEATURE_SINCE.versionTag} or newer; ${targets(ctx)}.`, raise(FEATURE_SINCE.versionTag));
282
+ if (isEmpty(versionTag.attributes.value)) {
283
+ report(ctx, "version-tag", process.id, `Process "${process.name ?? process.id}" has a zeebe:versionTag with no value.`, "Set the version tag, or remove it.");
284
+ }
285
+ }
286
+ const noneStarts = process.flowElements.filter((el) => el.type === "startEvent" && el.eventDefinitions.length === 0);
287
+ if (noneStarts.length > 1) {
288
+ for (const start of noneStarts) {
289
+ report(ctx, "no-multiple-none-start-events", start.id, `${describe(start)} is one of ${noneStarts.length} blank start events in process "${process.name ?? process.id}"; Camunda allows one.`, "Keep one blank start event and give the others an event definition.");
290
+ }
291
+ }
292
+ }
293
+ function checkCollapsed(ctx) {
294
+ for (const diagram of ctx.definitions.diagrams) {
295
+ for (const shape of diagram.plane.shapes) {
296
+ if (!ctx.subProcessIds.has(shape.bpmnElement) || shape.isExpanded === true)
297
+ continue;
298
+ report(ctx, "collapsed-subprocess", shape.bpmnElement, `Sub-process "${shape.bpmnElement}" is drawn collapsed, which needs Camunda ${FEATURE_SINCE.collapsedSubProcess} or newer; ${targets(ctx)}.`, `Expand the sub-process, or target Camunda ${FEATURE_SINCE.collapsedSubProcess} or newer.`);
299
+ }
300
+ }
301
+ }
302
+ function checkScope(ctx, elements, flows, parent) {
303
+ const byId = new Map(elements.map((el) => [el.id, el]));
304
+ const outgoing = new Map();
305
+ for (const flow of flows) {
306
+ const list = outgoing.get(flow.sourceRef) ?? [];
307
+ list.push(flow);
308
+ outgoing.set(flow.sourceRef, list);
309
+ }
310
+ for (const el of elements) {
311
+ checkElement(ctx, el, parent, byId, flows);
312
+ if (isContainer(el)) {
313
+ ctx.subProcessIds.add(el.id);
314
+ checkScope(ctx, el.flowElements, el.sequenceFlows, el);
315
+ }
316
+ }
317
+ checkSequenceFlows(ctx, byId, flows, outgoing);
318
+ }
319
+ function checkSequenceFlows(ctx, byId, flows, outgoing) {
320
+ for (const flow of flows) {
321
+ const source = byId.get(flow.sourceRef);
322
+ if (source === undefined)
323
+ continue;
324
+ const decides = source.type === "exclusiveGateway" || source.type === "inclusiveGateway";
325
+ if (decides) {
326
+ const siblings = outgoing.get(source.id) ?? [];
327
+ if (siblings.length > 1 &&
328
+ flow.id !== source.default &&
329
+ flow.conditionExpression === undefined) {
330
+ report(ctx, "sequence-flow-condition", flow.id, `Sequence flow "${flow.name ?? flow.id}" leaves ${describe(source)} without a condition and is not its default flow.`, "Add a condition expression, or make it the gateway's default flow.");
331
+ }
332
+ }
333
+ else if (flow.conditionExpression !== undefined) {
334
+ report(ctx, "sequence-flow-condition", flow.id, `Sequence flow "${flow.name ?? flow.id}" has a condition, but only flows leaving an exclusive or inclusive gateway may.`, "Remove the condition, or route the flow through a gateway.");
335
+ }
336
+ }
337
+ }
338
+ function checkElement(ctx, el, parent, scope, flows) {
339
+ const supported = checkElementType(ctx, el);
340
+ if (supported)
341
+ checkImplementation(ctx, el);
342
+ checkTimer(ctx, el, parent);
343
+ checkReferences(ctx, el, parent);
344
+ checkExtensions(ctx, el);
345
+ checkLoop(ctx, el);
346
+ checkForms(ctx, el);
347
+ const joined = el.type === "inclusiveGateway" ? flows.filter((f) => f.targetRef === el.id).length : 0;
348
+ if (joined > 1) {
349
+ report(ctx, "inclusive-gateway", el.id, `${describe(el)} joins ${joined} flows; Camunda ${ctx.version} only runs inclusive gateways that fork, joining needs Camunda 8.6 or newer.`, "Give it a single incoming flow, or target Camunda 8.6 or newer.");
350
+ }
351
+ if (el.type === "receiveTask") {
352
+ const fromEventGateway = flows.some((f) => f.targetRef === el.id && scope.get(f.sourceRef)?.type === "eventBasedGateway");
353
+ if (fromEventGateway) {
354
+ report(ctx, "event-based-gateway-target", el.id, `${describe(el)} follows an event-based gateway; Camunda only accepts catch events there.`, "Replace the receive task with a message intermediate catch event.");
355
+ }
356
+ }
357
+ const def = eventDefinitionOf(el);
358
+ if (el.type === "boundaryEvent" && def?.type === "escalation") {
359
+ const host = scope.get(el.attachedToRef);
360
+ if (host !== undefined && TASKS.has(host.type)) {
361
+ report(ctx, "escalation-boundary-event-attached-to-ref", el.id, `${describe(el)} is attached to ${describe(host, false)}; a task cannot throw an escalation, so Camunda does not allow it there.`, "Attach it to a sub-process or call activity instead.");
362
+ }
363
+ }
364
+ if (THROW_EVENTS.has(el.type) && def?.type === "compensate") {
365
+ if (def.unknownAttributes?.waitForCompletion === "false") {
366
+ report(ctx, "wait-for-completion", el.id, `${describe(el)} sets waitForCompletion="false"; Camunda always waits for compensation to complete.`, 'Remove waitForCompletion, or set it to "true".');
367
+ }
368
+ }
369
+ if (el.type === "adHocSubProcess")
370
+ checkAdHoc(ctx, el);
371
+ if (el.type === "startEvent" && parent !== undefined) {
372
+ if (def?.type === "signal") {
373
+ report(ctx, "no-signal-event-sub-process", el.id, `${describe(el)} starts a sub-process, which needs Camunda ${FEATURE_SINCE.signalEventSubProcess} or newer; ${targets(ctx)}.`, raise(FEATURE_SINCE.signalEventSubProcess));
374
+ }
375
+ if (el.isInterrupting !== false && isEventSubProcess(parent)) {
376
+ const grandparent = findParent(ctx.process.flowElements, parent.id);
377
+ if (grandparent?.type === "adHocSubProcess") {
378
+ report(ctx, "no-interrupting-event-subprocess", el.id, `${describe(el)} interrupts an event sub-process inside ad-hoc sub-process "${grandparent.name ?? grandparent.id}"; Camunda only allows non-interrupting ones there.`, 'Set isInterrupting="false".');
379
+ }
380
+ }
381
+ }
382
+ }
383
+ function findParent(elements, childId, parent) {
384
+ for (const el of elements) {
385
+ if (el.id === childId)
386
+ return parent;
387
+ if (isContainer(el)) {
388
+ const found = findParent(el.flowElements, childId, el);
389
+ if (found !== undefined)
390
+ return found;
391
+ }
392
+ }
393
+ return undefined;
394
+ }
395
+ /** `element-type`. Returns whether the target version runs the element. */
396
+ function checkElementType(ctx, el) {
397
+ const support = ELEMENT_SUPPORT[bpmnType(el)];
398
+ let since;
399
+ if (typeof support === "string") {
400
+ since = support;
401
+ }
402
+ else if (support !== undefined) {
403
+ const def = eventDefinitionOf(el);
404
+ since = support[def === undefined ? "_" : bpmnEventDefinitionType(def)];
405
+ }
406
+ if (since === undefined) {
407
+ report(ctx, "element-type", el.id, `${describe(el)} is not supported by any Camunda 8 version.`, "Model it with an element Camunda 8 executes.");
408
+ return false;
409
+ }
410
+ if (!atLeast(ctx.version, since)) {
411
+ report(ctx, "element-type", el.id, `${describe(el)} needs Camunda ${since} or newer; ${targets(ctx)}.`, raise(since));
412
+ return false;
413
+ }
414
+ return true;
415
+ }
416
+ function implementationSince(kind, el) {
417
+ const support = IMPLEMENTATION_SUPPORT[kind][bpmnType(el)];
418
+ if (typeof support === "string" || support === undefined)
419
+ return support;
420
+ const def = eventDefinitionOf(el);
421
+ return def === undefined ? undefined : support[bpmnEventDefinitionType(def)];
422
+ }
423
+ const IMPLEMENTATION_PROPERTIES = {
424
+ calledDecision: ["decisionId", "resultVariable"],
425
+ script: ["expression", "resultVariable"],
426
+ taskDefinition: ["type"],
427
+ };
428
+ /** `implementation` — how the task is carried out, and when that was introduced. */
429
+ function checkImplementation(ctx, el) {
430
+ const def = eventDefinitionOf(el);
431
+ if (THROW_EVENTS.has(el.type) && def === undefined)
432
+ return;
433
+ const kinds = ["calledDecision", "script", "taskDefinition"];
434
+ const present = kinds.filter((kind) => zeebe(el.extensionElements, kind).length > 0);
435
+ if (present.length === 1) {
436
+ const kind = present[0];
437
+ const since = implementationSince(kind, el);
438
+ if (since === undefined || !atLeast(ctx.version, since)) {
439
+ report(ctx, "implementation", el.id, since === undefined
440
+ ? `${describe(el)} has a zeebe:${kind}, which Camunda does not allow on it.`
441
+ : `${describe(el)} has a zeebe:${kind}, which needs Camunda ${since} or newer here; ${targets(ctx)}.`, since === undefined ? `Remove the zeebe:${kind}.` : raise(since));
442
+ return;
443
+ }
444
+ const ext = zeebe(el.extensionElements, kind)[0];
445
+ const missing = IMPLEMENTATION_PROPERTIES[kind].filter((p) => isEmpty(ext.attributes[p]));
446
+ for (const property of missing) {
447
+ report(ctx, "implementation", el.id, `${describe(el)} has a zeebe:${kind} with no ${property}.`, `Set ${property} on the zeebe:${kind}.`);
448
+ }
449
+ if (missing.length > 0)
450
+ return;
451
+ }
452
+ const allowed = kinds.filter((kind) => {
453
+ const since = implementationSince(kind, el);
454
+ return since !== undefined && atLeast(ctx.version, since);
455
+ });
456
+ // An ad-hoc sub-process is carried out by its own contents unless it has a task definition.
457
+ if (allowed.length === 0 || el.type === "adHocSubProcess")
458
+ return;
459
+ const count = allowed.reduce((n, kind) => n + zeebe(el.extensionElements, kind).length, 0);
460
+ if (count !== 1) {
461
+ const names = allowed.map((k) => `zeebe:${k}`).join(" or ");
462
+ report(ctx, "implementation", el.id, count === 0
463
+ ? `${describe(el)} has no implementation; Camunda needs a ${names}.`
464
+ : `${describe(el)} has ${count} implementations; Camunda needs exactly one ${names}.`, allowed.includes("taskDefinition")
465
+ ? "Set a job type (zeebe:taskDefinition)."
466
+ : `Add one ${names}.`);
467
+ }
468
+ }
469
+ const TIMER_PROPERTIES = ["timeCycle", "timeDate", "timeDuration"];
470
+ /** `timer` — which timer properties the event takes, and whether the value parses. */
471
+ function checkTimer(ctx, el, parent) {
472
+ const def = eventDefinitionOf(el);
473
+ if (def?.type !== "timer")
474
+ return;
475
+ const support = TIMER_SUPPORT[bpmnType(el)];
476
+ if (support === undefined)
477
+ return;
478
+ const interrupting = el.type === "boundaryEvent"
479
+ ? el.cancelActivity !== false
480
+ : el.type === "startEvent"
481
+ ? el.isInterrupting !== false
482
+ : true;
483
+ const inEventSubProcess = isEventSubProcess(parent);
484
+ const sinceOf = (p) => support[p](interrupting, inEventSubProcess);
485
+ const property = TIMER_PROPERTIES.find((p) => def[p] !== undefined);
486
+ if (property === undefined) {
487
+ const allowed = TIMER_PROPERTIES.filter((p) => {
488
+ const since = sinceOf(p);
489
+ return since !== null && atLeast(ctx.version, since);
490
+ });
491
+ report(ctx, "timer", el.id, `${describe(el)} has no timer value; set one of ${allowed.join(", ")}.`, "Set when the timer fires.");
492
+ return;
493
+ }
494
+ const since = sinceOf(property);
495
+ if (since === null || !atLeast(ctx.version, since)) {
496
+ report(ctx, "timer", el.id, since === null
497
+ ? `${describe(el)} uses ${property}, which Camunda does not allow on this event.`
498
+ : `${describe(el)} uses ${property}, which needs Camunda ${since} or newer on this event; ${targets(ctx)}.`, since === null ? "Use another kind of timer." : raise(since));
499
+ return;
500
+ }
501
+ const value = (def[property] ?? "").trim();
502
+ if (value === "") {
503
+ report(ctx, "timer", el.id, `${describe(el)} has an empty ${property}.`, "Set a timer value.");
504
+ return;
505
+ }
506
+ if (value.startsWith("="))
507
+ return;
508
+ if (property === "timeCycle" && !ISO_CYCLE_RE.test(value) && isCron(value)) {
509
+ if (!atLeast(ctx.version, CRON_TIMER_SINCE)) {
510
+ report(ctx, "timer", el.id, `${describe(el)} uses a cron expression, which needs Camunda ${CRON_TIMER_SINCE} or newer; ${targets(ctx)}.`, "Use an ISO 8601 repeating interval (R/PT1H), or target Camunda 8.1 or newer.");
511
+ }
512
+ return;
513
+ }
514
+ const valid = property === "timeCycle"
515
+ ? ISO_CYCLE_RE.test(value)
516
+ : property === "timeDate"
517
+ ? isIsoDate(value)
518
+ : ISO_DURATION_RE.test(value);
519
+ if (!valid) {
520
+ const expected = property === "timeCycle"
521
+ ? "an ISO 8601 repeating interval (R3/PT10M) or a cron expression"
522
+ : property === "timeDate"
523
+ ? "an ISO 8601 date-time (2026-01-01T09:00:00Z)"
524
+ : "an ISO 8601 duration (PT15M)";
525
+ report(ctx, "timer", el.id, `${describe(el)} has ${property} "${value}", which is not ${expected}.`, `Write ${expected}, or a FEEL expression starting with "=".`);
526
+ }
527
+ }
528
+ /** Message, error, escalation and signal references, and their codes and names. */
529
+ function checkReferences(ctx, el, parent) {
530
+ const def = eventDefinitionOf(el);
531
+ const isCatch = CATCH_EVENTS.has(el.type);
532
+ const isThrow = THROW_EVENTS.has(el.type);
533
+ const { definitions } = ctx;
534
+ // message-reference, subscription
535
+ const messageRef = el.type === "receiveTask" ? el.messageRef : def?.type === "message" ? def.messageRef : undefined;
536
+ const takesMessage = el.type === "receiveTask" || def?.type === "message";
537
+ if (takesMessage) {
538
+ const message = messageRef === undefined ? undefined : definitions.messages.find((m) => m.id === messageRef);
539
+ if ((isCatch || el.type === "receiveTask") && message === undefined) {
540
+ report(ctx, "message-reference", el.id, messageRef === undefined
541
+ ? `${describe(el)} references no message.`
542
+ : `${describe(el)} references message "${messageRef}", which does not exist.`, "Reference a bpmn:message with a name.");
543
+ }
544
+ else if ((isCatch || el.type === "receiveTask") && isEmpty(message?.name)) {
545
+ report(ctx, "message-reference", el.id, `${describe(el)} references message "${messageRef}", which has no name.`, "Name the message — Camunda correlates on it.");
546
+ }
547
+ // A message start event of the process itself is correlated by name alone.
548
+ const subscribes = !(el.type === "startEvent" && parent === undefined);
549
+ if (subscribes && message !== undefined) {
550
+ const onMessage = zeebe(message.extensionElements, "subscription");
551
+ const onElement = zeebe(el.extensionElements, "subscription")[0];
552
+ if (onMessage.length !== 1) {
553
+ const keyOnElement = !isEmpty(onElement?.attributes.correlationKey);
554
+ report(ctx, "subscription", el.id, keyOnElement
555
+ ? `${describe(el)} carries its zeebe:subscription itself; Camunda Modeler expects it on message "${message.name ?? message.id}".`
556
+ : `Message "${message.name ?? message.id}" used by ${describe(el)} has no zeebe:subscription.`, keyOnElement
557
+ ? "Move the zeebe:subscription onto the bpmn:message."
558
+ : "Add a zeebe:subscription with a correlationKey to the message.");
559
+ }
560
+ else if (isEmpty(onMessage[0]?.attributes.correlationKey)) {
561
+ report(ctx, "subscription", el.id, `Message "${message.name ?? message.id}" used by ${describe(el)} has a zeebe:subscription with no correlationKey.`, "Set the correlation key.");
562
+ }
563
+ }
564
+ }
565
+ if (def?.type === "error" && (isCatch || isThrow)) {
566
+ const optional = isCatch && atLeast(ctx.version, FEATURE_SINCE.errorCatchWithoutRef);
567
+ const error = def.errorRef === undefined ? undefined : definitions.errors.find((e) => e.id === def.errorRef);
568
+ if (error === undefined && !optional) {
569
+ report(ctx, "error-reference", el.id, isCatch
570
+ ? `${describe(el)} references no error; catching every error needs Camunda ${FEATURE_SINCE.errorCatchWithoutRef} or newer, ${targets(ctx)}.`
571
+ : `${describe(el)} references no error.`, "Reference a bpmn:error with an error code.");
572
+ }
573
+ else if (error !== undefined && isEmpty(error.errorCode)) {
574
+ report(ctx, "error-reference", el.id, `${describe(el)} references error "${error.name ?? error.id}", which has no error code.`, "Set the error code.");
575
+ }
576
+ else if (error?.errorCode?.startsWith("=")) {
577
+ const before82 = !atLeast(ctx.version, "8.2");
578
+ const before84 = !atLeast(ctx.version, "8.4");
579
+ if (before82 || (before84 && isCatch)) {
580
+ report(ctx, "no-expression", el.id, isCatch
581
+ ? `${describe(el)} catches error code "${error.errorCode}", an expression, which Camunda ${ctx.version} does not support in a catch event.`
582
+ : `${describe(el)} throws error code "${error.errorCode}", an expression, which needs Camunda ${FEATURE_SINCE.errorCodeExpression} or newer; ${targets(ctx)}.`, isCatch ? "Use a static error code." : raise(FEATURE_SINCE.errorCodeExpression));
583
+ }
584
+ }
585
+ }
586
+ if (def?.type === "escalation" && (isCatch || isThrow)) {
587
+ const escalation = def.escalationRef === undefined
588
+ ? undefined
589
+ : definitions.escalations.find((e) => e.id === def.escalationRef);
590
+ if (escalation === undefined && isThrow) {
591
+ report(ctx, "escalation-reference", el.id, `${describe(el)} references no escalation.`, "Reference a bpmn:escalation with an escalation code.");
592
+ }
593
+ else if (escalation !== undefined && isEmpty(escalation.escalationCode)) {
594
+ report(ctx, "escalation-reference", el.id, `${describe(el)} references escalation "${escalation.name ?? escalation.id}", which has no escalation code.`, "Set the escalation code.");
595
+ }
596
+ else if (isCatch &&
597
+ escalation?.escalationCode?.startsWith("=") &&
598
+ atLeast(ctx.version, "8.2") &&
599
+ !atLeast(ctx.version, "8.4")) {
600
+ report(ctx, "no-expression", el.id, `${describe(el)} catches escalation code "${escalation.escalationCode}", an expression, which Camunda ${ctx.version} does not support in a catch event.`, "Use a static escalation code.");
601
+ }
602
+ }
603
+ if (def?.type === "signal" && (isCatch || isThrow)) {
604
+ const signal = def.signalRef === undefined
605
+ ? undefined
606
+ : definitions.signals.find((s) => s.id === def.signalRef);
607
+ if (signal === undefined) {
608
+ report(ctx, "signal-reference", el.id, `${describe(el)} references no signal.`, "Reference a bpmn:signal with a name.");
609
+ }
610
+ else if (isEmpty(signal.name)) {
611
+ report(ctx, "signal-reference", el.id, `${describe(el)} references signal "${signal.id}", which has no name.`, "Name the signal — Camunda broadcasts on it.");
612
+ }
613
+ }
614
+ }
615
+ function checkNoExtension(ctx, rule, elementId, ext, name, label) {
616
+ if (zeebe(ext, name).length === 0)
617
+ return;
618
+ const since = NO_EXTENSION[rule];
619
+ report(ctx, rule, elementId, `${label} has a zeebe:${name}, which needs Camunda ${since} or newer; ${targets(ctx)}.`, raise(since));
620
+ }
621
+ const NO_EXTENSION = {
622
+ "no-zeebe-properties": FEATURE_SINCE.zeebeProperties,
623
+ "no-task-schedule": FEATURE_SINCE.taskSchedule,
624
+ "no-zeebe-user-task": FEATURE_SINCE.zeebeUserTask,
625
+ "no-priority-definition": FEATURE_SINCE.priorityDefinition,
626
+ "no-task-listeners": FEATURE_SINCE.taskListeners,
627
+ "no-job-priority-definition": FEATURE_SINCE.jobPriorityDefinition,
628
+ };
629
+ /** Execution listeners — present at all, then their event types, types and headers. */
630
+ function checkListeners(ctx, elementId, ext, label, isProcess, multiInstance) {
631
+ const container = zeebe(ext, "executionListeners")[0];
632
+ if (container === undefined)
633
+ return;
634
+ report(ctx, "no-execution-listeners", elementId, `${label} has execution listeners, which need Camunda ${FEATURE_SINCE.executionListeners} or newer; ${targets(ctx)}.`, raise(FEATURE_SINCE.executionListeners));
635
+ const listeners = children(container, "executionListener");
636
+ const seen = new Set();
637
+ for (const listener of listeners) {
638
+ const { eventType, type } = listener.attributes;
639
+ if (isEmpty(type)) {
640
+ report(ctx, "execution-listener", elementId, `${label} has an execution listener with no job type.`, "Set the listener's type.");
641
+ }
642
+ const key = `${eventType ?? ""}\u0000${type ?? ""}`;
643
+ if (!isEmpty(type) && seen.has(key)) {
644
+ report(ctx, "duplicate-execution-listeners", elementId, `${label} has two "${eventType}" execution listeners of type "${type}".`, "Remove the duplicate listener.");
645
+ }
646
+ seen.add(key);
647
+ if (children(listener, "taskHeaders").length > 0) {
648
+ report(ctx, "no-execution-listener-headers", elementId, `${label} has an execution listener with headers, which need Camunda ${FEATURE_SINCE.executionListenerHeaders} or newer; ${targets(ctx)}.`, raise(FEATURE_SINCE.executionListenerHeaders));
649
+ }
650
+ if (eventType === "beforeAll") {
651
+ report(ctx, "no-before-all-execution-listener", elementId, `${label} has a "beforeAll" execution listener, which needs Camunda ${FEATURE_SINCE.beforeAllExecutionListener} or newer; ${targets(ctx)}.`, raise(FEATURE_SINCE.beforeAllExecutionListener));
652
+ if (!multiInstance) {
653
+ report(ctx, "before-all-execution-listener", elementId, `${label} has a "beforeAll" execution listener but is not multi-instance.`, 'Use "start", or make the element multi-instance.');
654
+ }
655
+ }
656
+ if (eventType === "cancel") {
657
+ report(ctx, "no-cancel-execution-listener", elementId, `${label} has a "cancel" execution listener, which needs Camunda ${FEATURE_SINCE.cancelExecutionListener} or newer; ${targets(ctx)}.`, raise(FEATURE_SINCE.cancelExecutionListener));
658
+ if (!isProcess) {
659
+ report(ctx, "cancel-execution-listener", elementId, `${label} has a "cancel" execution listener; Camunda only allows those on a process.`, "Move the listener to the process.");
660
+ }
661
+ }
662
+ }
663
+ }
664
+ function checkTemplate(ctx, elementId, attributes, label) {
665
+ const template = attributes["zeebe:modelerTemplate"];
666
+ if (isEmpty(template))
667
+ return;
668
+ report(ctx, "no-template", elementId, `${label} applies element template "${template}", which needs Camunda ${FEATURE_SINCE.modelerTemplate} or newer; ${targets(ctx)}.`, raise(FEATURE_SINCE.modelerTemplate));
669
+ }
670
+ /** Zeebe extensions that are version-gated or have required properties. */
671
+ function checkExtensions(ctx, el) {
672
+ const ext = el.extensionElements;
673
+ const label = describe(el);
674
+ const multiInstance = "loopCharacteristics" in el && el.loopCharacteristics !== undefined;
675
+ checkListeners(ctx, el.id, ext, label, false, multiInstance);
676
+ checkTemplate(ctx, el.id, el.unknownAttributes, label);
677
+ checkNoExtension(ctx, "no-zeebe-properties", el.id, ext, "properties", label);
678
+ checkNoExtension(ctx, "no-job-priority-definition", el.id, ext, "jobPriorityDefinition", label);
679
+ for (const kind of ["calledDecision", "calledElement", "formDefinition"]) {
680
+ const holder = zeebe(ext, kind)[0];
681
+ const binding = holder?.attributes.bindingType;
682
+ if (holder === undefined || isEmpty(binding))
683
+ continue;
684
+ if (binding !== "latest") {
685
+ report(ctx, "no-binding-type", el.id, `${label} binds its zeebe:${kind} by "${binding}", which needs Camunda ${FEATURE_SINCE.bindingType} or newer; ${targets(ctx)}.`, raise(FEATURE_SINCE.bindingType));
686
+ }
687
+ if (binding === "versionTag" &&
688
+ ["businessRuleTask", "callActivity", "userTask"].includes(el.type)) {
689
+ const tag = holder.attributes.versionTag;
690
+ if (isEmpty(tag)) {
691
+ report(ctx, "version-tag", el.id, `${label} binds its zeebe:${kind} by version tag but sets no versionTag.`, "Set the version tag to bind to.");
692
+ }
693
+ else if (el.type === "businessRuleTask" &&
694
+ tag?.startsWith("=") &&
695
+ !atLeast(ctx.version, FEATURE_SINCE.decisionVersionTagExpression)) {
696
+ report(ctx, "version-tag", el.id, `${label} binds its decision by a version tag expression, which needs Camunda ${FEATURE_SINCE.decisionVersionTagExpression} or newer; ${targets(ctx)}.`, raise(FEATURE_SINCE.decisionVersionTagExpression));
697
+ }
698
+ }
699
+ }
700
+ if (el.type === "callActivity") {
701
+ const called = zeebe(ext, "calledElement")[0];
702
+ if (called === undefined || isEmpty(called.attributes.processId)) {
703
+ report(ctx, "called-element", el.id, `${label} has no zeebe:calledElement processId.`, "Set the id of the process to call.");
704
+ }
705
+ if (called?.attributes.propagateAllParentVariables === "false") {
706
+ report(ctx, "no-propagate-all-parent-variables", el.id, `${label} sets propagateAllParentVariables="false", which needs Camunda ${FEATURE_SINCE.propagateAllParentVariablesFalse} or newer; ${targets(ctx)}.`, raise(FEATURE_SINCE.propagateAllParentVariablesFalse));
707
+ }
708
+ if (!isEmpty(called?.attributes.businessId)) {
709
+ report(ctx, "no-business-id", el.id, `${label} sets a businessId, which needs Camunda ${FEATURE_SINCE.businessId} or newer; ${targets(ctx)}.`, raise(FEATURE_SINCE.businessId));
710
+ }
711
+ }
712
+ if (el.type === "userTask") {
713
+ checkNoExtension(ctx, "no-task-schedule", el.id, ext, "taskSchedule", label);
714
+ checkNoExtension(ctx, "no-zeebe-user-task", el.id, ext, "userTask", label);
715
+ checkNoExtension(ctx, "no-priority-definition", el.id, ext, "priorityDefinition", label);
716
+ checkNoExtension(ctx, "no-task-listeners", el.id, ext, "taskListeners", label);
717
+ if (!isEmpty(zeebe(ext, "assignmentDefinition")[0]?.attributes.candidateUsers)) {
718
+ report(ctx, "no-candidate-users", el.id, `${label} assigns candidate users, which needs Camunda ${FEATURE_SINCE.candidateUsers} or newer; ${targets(ctx)}.`, raise(FEATURE_SINCE.candidateUsers));
719
+ }
720
+ if (zeebe(ext, "userTask").length !== 1) {
721
+ report(ctx, "zeebe-user-task", el.id, `${label} is a job-worker user task; Camunda ${ctx.version} deprecates those in favour of Camunda user tasks.`, "Add zeebe:userTask to make it a Camunda user task.");
722
+ }
723
+ const schedule = zeebe(ext, "taskSchedule")[0];
724
+ for (const field of ["dueDate", "followUpDate"]) {
725
+ const value = schedule?.attributes[field];
726
+ if (value === undefined || value.startsWith("=") || isIsoDate(value))
727
+ continue;
728
+ report(ctx, "task-schedule", el.id, `${label} has ${field} "${value}", which is not an ISO 8601 date-time.`, 'Write an ISO 8601 date-time (2026-01-01T09:00:00Z) or a FEEL expression starting with "=".');
729
+ }
730
+ const priority = zeebe(ext, "priorityDefinition")[0]?.attributes.priority;
731
+ if (priority !== undefined && !priority.startsWith("=")) {
732
+ const valid = /^\d+$/.test(priority) && Number(priority) <= 100;
733
+ if (!valid) {
734
+ report(ctx, "priority-definition", el.id, `${label} has priority "${priority}"; Camunda takes a whole number from 0 to 100.`, 'Use 0–100, or a FEEL expression starting with "=".');
735
+ }
736
+ }
737
+ for (const listener of children(zeebe(ext, "taskListeners")[0], "taskListener")) {
738
+ if (isEmpty(listener.attributes.type)) {
739
+ report(ctx, "task-listener", el.id, `${label} has a task listener with no job type.`, "Set the listener's type.");
740
+ }
741
+ }
742
+ }
743
+ const headerHolders = new Set([
744
+ "userTask",
745
+ "serviceTask",
746
+ "businessRuleTask",
747
+ "scriptTask",
748
+ "sendTask",
749
+ "endEvent",
750
+ "intermediateThrowEvent",
751
+ "adHocSubProcess",
752
+ ]);
753
+ if (headerHolders.has(el.type)) {
754
+ const keys = children(zeebe(ext, "taskHeaders")[0], "header").map((h) => h.attributes.key);
755
+ const duplicates = new Set(keys.filter((key, i) => key !== undefined && keys.indexOf(key) !== i));
756
+ for (const key of duplicates) {
757
+ report(ctx, "duplicate-task-headers", el.id, `${label} has more than one task header "${key}".`, "Remove the duplicate header.");
758
+ }
759
+ }
760
+ const io = zeebe(ext, "ioMapping")[0];
761
+ for (const input of children(io, "input")) {
762
+ if (isEmpty(input.attributes.target)) {
763
+ report(ctx, "io-mapping", el.id, `${label} has an input mapping with no target.`, "Set the target.");
764
+ }
765
+ if (isEmpty(input.attributes.source) &&
766
+ !atLeast(ctx.version, FEATURE_SINCE.inputWithoutSource)) {
767
+ report(ctx, "io-mapping", el.id, `${label} has an input mapping with no source, which needs Camunda ${FEATURE_SINCE.inputWithoutSource} or newer; ${targets(ctx)}.`, "Set the source.");
768
+ }
769
+ }
770
+ for (const output of children(io, "output")) {
771
+ for (const field of ["source", "target"]) {
772
+ if (isEmpty(output.attributes[field])) {
773
+ report(ctx, "io-mapping", el.id, `${label} has an output mapping with no ${field}.`, `Set the ${field}.`);
774
+ }
775
+ }
776
+ }
777
+ }
778
+ /** `loop-characteristics` — only multi-instance, with an input collection. */
779
+ function checkLoop(ctx, el) {
780
+ if (!ACTIVITIES.has(el.type))
781
+ return;
782
+ if (el.unknownChildren?.some((c) => c.name.endsWith("standardLoopCharacteristics"))) {
783
+ report(ctx, "loop-characteristics", el.id, `${describe(el)} is a standard loop; Camunda only runs multi-instance loops.`, "Make it multi-instance, or model the loop with a gateway.");
784
+ return;
785
+ }
786
+ const loop = "loopCharacteristics" in el ? el.loopCharacteristics : undefined;
787
+ if (loop === undefined)
788
+ return;
789
+ const zeebeLoop = zeebe(loop.extensionElements, "loopCharacteristics");
790
+ if (zeebeLoop.length !== 1) {
791
+ report(ctx, "loop-characteristics", el.id, `${describe(el)} is multi-instance without a zeebe:loopCharacteristics.`, "Set the input collection to iterate over.");
792
+ return;
793
+ }
794
+ const { inputCollection, outputCollection, outputElement } = zeebeLoop[0]
795
+ .attributes;
796
+ if (isEmpty(inputCollection)) {
797
+ report(ctx, "loop-characteristics", el.id, `${describe(el)} is multi-instance with no input collection.`, "Set the input collection to iterate over.");
798
+ }
799
+ if (isEmpty(outputCollection) !== isEmpty(outputElement)) {
800
+ report(ctx, "loop-characteristics", el.id, `${describe(el)} sets ${isEmpty(outputCollection) ? "an output element but no output collection" : "an output collection but no output element"}.`, "Set both the output collection and the output element, or neither.");
801
+ }
802
+ }
803
+ /** `ad-hoc-sub-process` — contents, completion and output collection. */
804
+ function checkAdHoc(ctx, el) {
805
+ const label = describe(el);
806
+ if (!el.flowElements.some((child) => ACTIVITIES.has(child.type))) {
807
+ report(ctx, "ad-hoc-sub-process", el.id, `${label} contains no activity.`, "Add at least one task or sub-process to it.");
808
+ }
809
+ const since = FEATURE_SINCE.adHocCompletion;
810
+ if (!atLeast(ctx.version, since)) {
811
+ const used = [
812
+ el.completionCondition !== undefined ? "a completion condition" : undefined,
813
+ el.cancelRemainingInstances === false ? 'cancelRemainingInstances="false"' : undefined,
814
+ ...["outputCollection", "outputElement"].map((a) => isEmpty(zeebe(el.extensionElements, "adHoc")[0]?.attributes[a]) ? undefined : a),
815
+ ].filter((u) => u !== undefined);
816
+ for (const feature of used) {
817
+ report(ctx, "ad-hoc-sub-process", el.id, `${label} uses ${feature}, which needs Camunda ${since} or newer; ${targets(ctx)}.`, raise(since));
818
+ }
819
+ if (used.length > 0)
820
+ return;
821
+ }
822
+ const adHoc = zeebe(el.extensionElements, "adHoc")[0];
823
+ if (adHoc !== undefined &&
824
+ isEmpty(adHoc.attributes.outputCollection) !== isEmpty(adHoc.attributes.outputElement)) {
825
+ report(ctx, "ad-hoc-sub-process", el.id, `${label} sets only one of outputCollection and outputElement.`, "Set both, or neither.");
826
+ }
827
+ }
828
+ /** User task and start event forms. */
829
+ function checkForms(ctx, el) {
830
+ if (el.type !== "userTask" && el.type !== "startEvent")
831
+ return;
832
+ const label = describe(el);
833
+ const forms = zeebe(el.extensionElements, "formDefinition");
834
+ const form = forms[0];
835
+ if (el.type === "userTask" && forms.length !== 1) {
836
+ report(ctx, "user-task-definition", el.id, `${label} has no zeebe:formDefinition.`, "Link a form (formId), an external form, or an embedded form.");
837
+ }
838
+ if (el.type === "startEvent" && form !== undefined) {
839
+ if (!atLeast(ctx.version, FEATURE_SINCE.startEventForm)) {
840
+ report(ctx, "start-event-form", el.id, `${label} has a form, which needs Camunda ${FEATURE_SINCE.startEventForm} or newer on a start event; ${targets(ctx)}.`, raise(FEATURE_SINCE.startEventForm));
841
+ return;
842
+ }
843
+ if (form.attributes.formKey?.startsWith("camunda-forms:bpmn:")) {
844
+ report(ctx, "start-event-form-embedded", el.id, `${label} embeds its form; embedded forms on start events are deprecated.`, "Link a deployed form by formId instead.");
845
+ }
846
+ }
847
+ if (form === undefined)
848
+ return;
849
+ const zeebeUserTask = el.type === "userTask" && zeebe(el.extensionElements, "userTask").length > 0;
850
+ let allowed;
851
+ if (el.type === "startEvent") {
852
+ allowed = ["formKey", "formId"];
853
+ }
854
+ else if (zeebeUserTask) {
855
+ if (!atLeast(ctx.version, FEATURE_SINCE.zeebeUserTask))
856
+ return;
857
+ allowed = ["externalReference", "formId"];
858
+ }
859
+ else if (atLeast(ctx.version, FEATURE_SINCE.userTaskFormId)) {
860
+ allowed = ["formKey", "formId"];
861
+ }
862
+ else {
863
+ if (!isEmpty(form.attributes.formId)) {
864
+ report(ctx, "user-task-form", el.id, `${label} links a form by formId, which needs Camunda ${FEATURE_SINCE.userTaskFormId} or newer; ${targets(ctx)}.`, raise(FEATURE_SINCE.userTaskFormId));
865
+ return;
866
+ }
867
+ allowed = ["formKey"];
868
+ }
869
+ const set = allowed.filter((a) => !isEmpty(form.attributes[a]));
870
+ if (set.length !== 1) {
871
+ report(ctx, el.type === "startEvent" ? "start-event-form" : "user-task-form", el.id, `${label} has a zeebe:formDefinition that must set exactly one of ${allowed.join(", ")}.`, `Set one of ${allowed.join(", ")}.`);
872
+ return;
873
+ }
874
+ const formKey = form.attributes.formKey;
875
+ if (formKey?.startsWith("camunda-forms:bpmn:")) {
876
+ const id = formKey.slice("camunda-forms:bpmn:".length);
877
+ const embedded = zeebe(ctx.process.extensionElements, "userTaskForm").find((f) => f.attributes.id === id);
878
+ if (embedded !== undefined && (embedded.text ?? "").trim() === "") {
879
+ report(ctx, el.type === "startEvent" ? "start-event-form" : "user-task-form", el.id, `${label} embeds form "${id}", which is empty.`, "Put the form's JSON in the zeebe:userTaskForm.");
880
+ }
881
+ }
882
+ }
883
+ const DATA_ELEMENTS = new Set(["dataObject", "dataObjectReference", "dataStoreReference"]);
884
+ /** The rules that read an element's expressions, properties and tool flow. */
885
+ function checkContents(ctx) {
886
+ const owners = [
887
+ ctx.process,
888
+ ...[...ctx.elements.values()].map((l) => l.el),
889
+ ...[...ctx.flows.values()].map((l) => l.el),
890
+ ];
891
+ const unavailable = Object.keys(FEEL_BUILTIN_SINCE).filter((name) => !atLeast(ctx.version, FEEL_BUILTIN_SINCE[name]));
892
+ for (const owner of owners) {
893
+ if (unavailable.length > 0)
894
+ checkFeelCompatibility(ctx, owner, new Set(unavailable));
895
+ checkConnectorProperties(ctx, owner);
896
+ if ("sourceRef" in owner) {
897
+ checkFromAiCondition(ctx, owner);
898
+ continue;
899
+ }
900
+ checkVariableNames(ctx, owner);
901
+ checkSecrets(ctx, owner);
902
+ checkSecretReferences(ctx, owner);
903
+ checkListenerHeaders(ctx, owner);
904
+ if ("type" in owner) {
905
+ checkFromAi(ctx, owner);
906
+ if (isToolEntry(ctx, owner))
907
+ checkToolOutput(ctx, owner);
908
+ }
909
+ }
910
+ checkLinkEvents(ctx);
911
+ checkNoLoop(ctx);
912
+ }
913
+ function truncate(value) {
914
+ return value.length > 10 ? `${value.slice(0, 10)}...` : value;
915
+ }
916
+ /** Attributes `feel-compatibility` does not read, per Zeebe element (`utils/feel.js`). */
917
+ const NOT_FEEL = {
918
+ "zeebe:input": ["target"],
919
+ "zeebe:output": ["target"],
920
+ "zeebe:header": ["key", "value"],
921
+ "zeebe:property": ["name", "value"],
922
+ "zeebe:calledDecision": ["resultVariable"],
923
+ "zeebe:script": ["resultVariable"],
924
+ };
925
+ /** The FEEL expressions (values starting with `=`) on an element and its extensions. */
926
+ function feelExpressions(owner) {
927
+ const values = [owner.documentation];
928
+ const extension = (x) => {
929
+ if (!x.name.startsWith("zeebe:"))
930
+ return;
931
+ const skipped = NOT_FEEL[x.name] ?? [];
932
+ for (const [key, value] of Object.entries(x.attributes)) {
933
+ if (key !== "name" && !key.includes(":") && !skipped.includes(key))
934
+ values.push(value);
935
+ }
936
+ for (const child of x.children)
937
+ extension(child);
938
+ };
939
+ for (const x of owner.extensionElements)
940
+ extension(x);
941
+ if ("conditionExpression" in owner)
942
+ values.push(owner.conditionExpression?.text);
943
+ if ("eventDefinitions" in owner) {
944
+ for (const def of owner.eventDefinitions) {
945
+ if (def.type === "timer")
946
+ values.push(def.timeCycle, def.timeDate, def.timeDuration);
947
+ if (def.type === "conditional")
948
+ values.push(def.condition);
949
+ }
950
+ }
951
+ const loop = "loopCharacteristics" in owner ? owner.loopCharacteristics : undefined;
952
+ if (loop !== undefined) {
953
+ values.push(loop.loopCardinality?.text, loop.completionCondition?.text);
954
+ for (const x of loop.extensionElements)
955
+ extension(x);
956
+ }
957
+ if ("type" in owner && owner.type === "adHocSubProcess") {
958
+ values.push(owner.completionCondition?.text);
959
+ }
960
+ return values.filter((v) => v?.startsWith("=") === true);
961
+ }
962
+ /** `feel-compatibility` — a FEEL built-in newer than the target. */
963
+ function checkFeelCompatibility(ctx, owner, unavailable) {
964
+ for (const expression of feelExpressions(owner)) {
965
+ const calls = feelBuiltinCalls(expression.slice(1), BUILTINS);
966
+ const name = calls?.find((call) => unavailable.has(call));
967
+ if (name === undefined)
968
+ continue;
969
+ const since = FEEL_BUILTIN_SINCE[name];
970
+ report(ctx, "feel-compatibility", owner.id, `FEEL function <${name}> requires Camunda >=${since}`, `Target Camunda ${since} or newer (modeler:executionPlatformVersion), or do without ${name}().`);
971
+ }
972
+ }
973
+ const BUILTINS = new Set(Object.keys(FEEL_BUILTIN_SINCE));
974
+ const VARIABLE_NAME = /^[a-zA-Z_][a-zA-Z0-9_]*(?:\.[a-zA-Z_][a-zA-Z0-9_]*)*$/;
975
+ /** `variable-name` — the variables an element writes must be plain FEEL names. */
976
+ function checkVariableNames(ctx, owner) {
977
+ const ext = owner.extensionElements;
978
+ const io = zeebe(ext, "ioMapping")[0];
979
+ const written = [
980
+ ...children(io, "input").map((i) => ["input target", i.attributes.target]),
981
+ ...children(io, "output").map((o) => ["output target", o.attributes.target]),
982
+ ];
983
+ const loop = "loopCharacteristics" in owner ? owner.loopCharacteristics : undefined;
984
+ const zeebeLoop = zeebe(loop?.extensionElements, "loopCharacteristics")[0];
985
+ written.push(["input element", zeebeLoop?.attributes.inputElement], ["output collection", zeebeLoop?.attributes.outputCollection]);
986
+ const type = "type" in owner ? owner.type : "process";
987
+ if (type === "scriptTask") {
988
+ written.push(["result variable", zeebe(ext, "script")[0]?.attributes.resultVariable]);
989
+ }
990
+ if (type === "businessRuleTask") {
991
+ written.push(["result variable", zeebe(ext, "calledDecision")[0]?.attributes.resultVariable]);
992
+ }
993
+ if (type === "adHocSubProcess") {
994
+ written.push(["output collection", zeebe(ext, "adHoc")[0]?.attributes.outputCollection]);
995
+ }
996
+ for (const [what, value] of written) {
997
+ if (value === undefined || VARIABLE_NAME.test(value))
998
+ continue;
999
+ report(ctx, "variable-name", owner.id, `Property value of <${truncate(value)}> not allowed`, `The ${what} "${value}" is not a variable name: use letters, digits and underscores, not starting with a digit, with dots between nested names.`);
1000
+ }
1001
+ }
1002
+ /**
1003
+ * `secrets` — the format a secret is written in: `deprecated` for a bare
1004
+ * `secrets.X`, `legacy` for `{{secrets.X}}` once `camunda.secrets.X` exists.
1005
+ */
1006
+ function secretFormat(ctx, value) {
1007
+ if (value === undefined || !value.includes("secrets."))
1008
+ return undefined;
1009
+ if (/camunda\.secrets\.(?:[\w-]+|`[^`]+`)/.test(value))
1010
+ return undefined;
1011
+ const legacy = /{{\s*secrets\.[\w-]+\s*}}/.test(value);
1012
+ if (atLeast(ctx.version, FEATURE_SINCE.camundaSecrets))
1013
+ return legacy ? "legacy" : "deprecated";
1014
+ return legacy ? undefined : "deprecated";
1015
+ }
1016
+ /** `secrets` — input sources, property values and correlation keys. */
1017
+ function checkSecrets(ctx, owner) {
1018
+ const values = [
1019
+ ...children(zeebe(owner.extensionElements, "ioMapping")[0], "input").map((i) => ["source", i.attributes.source]),
1020
+ ...children(zeebe(owner.extensionElements, "properties")[0], "property").map((p) => ["value", p.attributes.value]),
1021
+ ];
1022
+ if ("type" in owner) {
1023
+ const def = eventDefinitionOf(owner);
1024
+ const messageRef = owner.type === "receiveTask"
1025
+ ? owner.messageRef
1026
+ : def?.type === "message"
1027
+ ? def.messageRef
1028
+ : undefined;
1029
+ const message = ctx.definitions.messages.find((m) => m.id === messageRef);
1030
+ const subscription = zeebe(message?.extensionElements, "subscription")[0];
1031
+ if (subscription !== undefined) {
1032
+ values.push(["correlationKey", subscription.attributes.correlationKey]);
1033
+ }
1034
+ }
1035
+ for (const [property, value] of values) {
1036
+ const format = secretFormat(ctx, value);
1037
+ if (format === undefined)
1038
+ continue;
1039
+ report(ctx, "secrets", owner.id, `Property <${property}> uses ${format} secret expression format`, atLeast(ctx.version, FEATURE_SINCE.camundaSecrets)
1040
+ ? "Reference the secret as =camunda.secrets.NAME."
1041
+ : "Write the secret as {{secrets.NAME}}.");
1042
+ }
1043
+ }
1044
+ /** `unresolvable-secret-reference` — `camunda.secrets.X` written where the engine cannot resolve it. */
1045
+ function checkSecretReferences(ctx, owner) {
1046
+ const literal = (property, value) => {
1047
+ if (value === undefined || !value.includes("secrets."))
1048
+ return;
1049
+ const inert = value.startsWith("=")
1050
+ ? secretReferenceViolations(value.slice(1)).stringLiteral
1051
+ : SECRET_REFERENCE_LITERAL.test(value);
1052
+ if (!inert)
1053
+ return;
1054
+ report(ctx, "unresolvable-secret-reference", owner.id, `Property <${property}> must use a secret reference as an expression (e.g. =camunda.secrets.NAME), not as a string literal`, "Write the reference as a FEEL expression, outside quotes.");
1055
+ };
1056
+ for (const input of children(zeebe(owner.extensionElements, "ioMapping")[0], "input")) {
1057
+ const source = input.attributes.source;
1058
+ literal("source", source);
1059
+ if (source === undefined || !source.includes("secrets.") || !source.startsWith("="))
1060
+ continue;
1061
+ const violations = secretReferenceViolations(source.slice(1));
1062
+ if (violations.insideList) {
1063
+ report(ctx, "unresolvable-secret-reference", owner.id, "Property <source> must not assign a secret reference inside a list", "Map the secret to a variable of its own, and build the list from that variable.");
1064
+ }
1065
+ if (violations.insideIfBranchContext) {
1066
+ report(ctx, "unresolvable-secret-reference", owner.id, "Property <source> must not assign a secret reference inside a context returned by an if expression branch", "Map the secret to a variable of its own, and build the context from that variable.");
1067
+ }
1068
+ }
1069
+ for (const property of children(zeebe(owner.extensionElements, "properties")[0], "property")) {
1070
+ literal("value", property.attributes.value);
1071
+ }
1072
+ }
1073
+ /** `connector-properties` — inbound connector properties newer than the target. */
1074
+ function checkConnectorProperties(ctx, owner) {
1075
+ const properties = children(zeebe(owner.extensionElements, "properties")[0], "property");
1076
+ const named = (name) => properties.find((p) => p.attributes.name === name);
1077
+ const connector = named("inbound.type")?.attributes.value;
1078
+ if (connector === undefined)
1079
+ return;
1080
+ for (const [name, { since, connectors }] of Object.entries(INBOUND_CONNECTOR_PROPERTY_SINCE)) {
1081
+ if (atLeast(ctx.version, since) || !connectors.includes(connector))
1082
+ continue;
1083
+ if (named(name) === undefined)
1084
+ continue;
1085
+ report(ctx, "connector-properties", owner.id, `Connector property <name> with value <${name}> only allowed by Camunda ${since} or newer.`, `Remove the ${name} property, or target Camunda ${since} or newer.`);
1086
+ }
1087
+ }
1088
+ /** `duplicate-execution-listener-headers` — one header key twice on one listener. */
1089
+ function checkListenerHeaders(ctx, owner) {
1090
+ const listeners = children(zeebe(owner.extensionElements, "executionListeners")[0], "executionListener");
1091
+ for (const listener of listeners) {
1092
+ const headers = children(listener, "taskHeaders")[0];
1093
+ if (headers === undefined)
1094
+ continue;
1095
+ const keys = children(headers, "header").map((h) => h.attributes.key);
1096
+ const duplicates = keys.filter((key, i) => keys.indexOf(key) !== i);
1097
+ for (const key of new Set(duplicates)) {
1098
+ report(ctx, "duplicate-execution-listener-headers", owner.id, `Properties of type <zeebe:Header> have property <key> with duplicate value of <${key}>`, "Remove the duplicate header from the execution listener.");
1099
+ }
1100
+ }
1101
+ }
1102
+ /** `link-event` — link events need a name, and a link catch name must be unique in the process. */
1103
+ function checkLinkEvents(ctx) {
1104
+ const linkDefinition = (el) => {
1105
+ const def = eventDefinitionOf(el);
1106
+ return def?.type === "link" ? def : undefined;
1107
+ };
1108
+ for (const { el } of ctx.elements.values()) {
1109
+ if (el.type !== "intermediateCatchEvent" && el.type !== "intermediateThrowEvent")
1110
+ continue;
1111
+ const def = linkDefinition(el);
1112
+ if (def === undefined || (def.name ?? "").trim() !== "")
1113
+ continue;
1114
+ report(ctx, "link-event", el.id, "Element of type <bpmn:LinkEventDefinition> must have property <name>", "Name the link — a throw and its catch are paired by name.");
1115
+ }
1116
+ const catches = [];
1117
+ const collect = (elements) => {
1118
+ for (const el of elements) {
1119
+ if (el.type === "intermediateCatchEvent" && linkDefinition(el) !== undefined)
1120
+ catches.push(el);
1121
+ else if (isContainer(el))
1122
+ collect(el.flowElements);
1123
+ }
1124
+ };
1125
+ collect(ctx.process.flowElements);
1126
+ const names = catches.map((el) => linkDefinition(el)?.name);
1127
+ const duplicates = new Set(names.filter((name, i) => name && names.indexOf(name) !== i));
1128
+ for (const name of duplicates) {
1129
+ for (const el of catches.filter((c) => linkDefinition(c)?.name === name)) {
1130
+ report(ctx, "link-event", el.id, `Property of type <bpmn:LinkEventDefinition> has property <name> with duplicate value of <${name}>`, "Give each link catch event in the process its own name.");
1131
+ }
1132
+ }
1133
+ }
1134
+ // ── no-loop ─────────────────────────────────────────────────────────────────
1135
+ /** Elements a straight-through loop can consist of — none of them waits. */
1136
+ const LOOP_REQUIRED = new Set(["bpmn:CallActivity", "bpmn:ManualTask", "bpmn:Task"]);
1137
+ const LOOP_ELEMENTS = new Set([
1138
+ ...LOOP_REQUIRED,
1139
+ "bpmn:StartEvent",
1140
+ "bpmn:EndEvent",
1141
+ "bpmn:ExclusiveGateway",
1142
+ "bpmn:InclusiveGateway",
1143
+ "bpmn:ParallelGateway",
1144
+ "bpmn:SubProcess",
1145
+ ]);
1146
+ /**
1147
+ * `no-loop` — a cycle of elements that never wait, which Zeebe would run
1148
+ * without end. A port of the plugin's rule: the graph is reduced to its
1149
+ * call activities, manual tasks and plain tasks, joined through the gateways,
1150
+ * start and end events and sub-processes between them, then searched
1151
+ * breadth-first. Kept literal, down to the visiting order, so the same loops
1152
+ * are found.
1153
+ */
1154
+ function checkNoLoop(ctx) {
1155
+ const typeOf = (id) => {
1156
+ const el = ctx.elements.get(id)?.el;
1157
+ return el === undefined ? undefined : bpmnType(el);
1158
+ };
1159
+ const next = (id) => {
1160
+ const located = ctx.elements.get(id);
1161
+ if (located === undefined)
1162
+ return [];
1163
+ let { el } = located;
1164
+ if (el.type === "callActivity") {
1165
+ const processId = zeebe(el.extensionElements, "calledElement")[0]?.attributes.processId;
1166
+ if (processId !== undefined && !processId.startsWith("=") && processId === ctx.process.id) {
1167
+ return ctx.process.flowElements.filter((e) => e.type === "startEvent").map((e) => e.id);
1168
+ }
1169
+ }
1170
+ else if (isContainer(el)) {
1171
+ return el.flowElements.filter((e) => e.type === "startEvent").map((e) => e.id);
1172
+ }
1173
+ else if (el.type === "endEvent" && located.parent !== undefined) {
1174
+ el = located.parent;
1175
+ }
1176
+ return el.outgoing.flatMap((flowId) => {
1177
+ const target = ctx.flows.get(flowId)?.el.targetRef;
1178
+ return target !== undefined && ctx.elements.has(target) ? [target] : [];
1179
+ });
1180
+ };
1181
+ const graph = new Map();
1182
+ const node = (id) => {
1183
+ let found = graph.get(id);
1184
+ if (found === undefined) {
1185
+ found = { element: id, incoming: new Map(), outgoing: new Map() };
1186
+ graph.set(id, found);
1187
+ }
1188
+ return found;
1189
+ };
1190
+ for (const id of ctx.elements.keys()) {
1191
+ if (!LOOP_ELEMENTS.has(typeOf(id) ?? ""))
1192
+ continue;
1193
+ const current = node(id);
1194
+ for (const target of next(id)) {
1195
+ node(target).incoming.set(id, []);
1196
+ current.outgoing.set(target, []);
1197
+ }
1198
+ }
1199
+ // Drop every element that is not required, joining its neighbours directly.
1200
+ breadthFirst(graph, (n) => {
1201
+ if (!LOOP_REQUIRED.has(typeOf(n.element) ?? "")) {
1202
+ for (const [fromKey, fromPath] of n.incoming) {
1203
+ for (const [toKey, toPath] of n.outgoing) {
1204
+ const from = graph.get(fromKey);
1205
+ const to = graph.get(toKey);
1206
+ if (from === undefined || to === undefined)
1207
+ continue;
1208
+ const path = [...fromPath, n.element, ...toPath];
1209
+ if (!from.outgoing.has(toKey))
1210
+ from.outgoing.set(toKey, path);
1211
+ if (!to.incoming.has(fromKey))
1212
+ to.incoming.set(fromKey, path);
1213
+ }
1214
+ }
1215
+ graph.delete(n.element);
1216
+ }
1217
+ return [...n.outgoing.keys()].map((key) => graph.get(key));
1218
+ });
1219
+ for (const { incoming, outgoing } of graph.values()) {
1220
+ for (const key of incoming.keys())
1221
+ if (!graph.has(key))
1222
+ incoming.delete(key);
1223
+ for (const key of outgoing.keys())
1224
+ if (!graph.has(key))
1225
+ outgoing.delete(key);
1226
+ }
1227
+ breadthFirst(graph, (n) => {
1228
+ const found = [];
1229
+ for (const [target, via] of n.outgoing) {
1230
+ const path = [...(n.path ?? []), n.element, ...via];
1231
+ if (path.includes(target)) {
1232
+ const loop = path.slice(path.indexOf(target));
1233
+ if (!loop.some((id) => LOOP_REQUIRED.has(typeOf(id) ?? "")))
1234
+ continue;
1235
+ report(ctx, "no-loop", ctx.process.id, `Loop detected: ${loop.join(" -> ")} -> ${target}`, "Put a wait state in the loop — a service, user or receive task, or a catch event — or remove it.");
1236
+ }
1237
+ else {
1238
+ const targetNode = graph.get(target);
1239
+ targetNode.path = targetNode.path ?? path;
1240
+ found.push(targetNode);
1241
+ }
1242
+ }
1243
+ return found;
1244
+ });
1245
+ }
1246
+ function breadthFirst(graph, visit) {
1247
+ const unvisited = new Set(graph.values());
1248
+ for (const first of unvisited) {
1249
+ unvisited.delete(first);
1250
+ const queue = [first];
1251
+ for (let n = queue.shift(); n !== undefined; n = queue.shift()) {
1252
+ for (const next of visit(n)) {
1253
+ if (next === undefined || !unvisited.has(next))
1254
+ continue;
1255
+ unvisited.delete(next);
1256
+ queue.push(next);
1257
+ }
1258
+ }
1259
+ }
1260
+ }
1261
+ // ── Agent tools ─────────────────────────────────────────────────────────────
1262
+ /** A `zeebe:property` the AI Agent templates set on an ad-hoc sub-process that holds tools. */
1263
+ const TOOL_CONTAINER_PROPERTY = "io.camunda.agenticai.toolContainer";
1264
+ /** The AI Agent job-worker template, whose older versions predate that property. */
1265
+ const AI_AGENT_TEMPLATE = "io.camunda.connectors.agenticai.aiagent.jobworker.v1";
1266
+ /** The job type of the AI Agent job worker, which forks of the template keep. */
1267
+ const AI_AGENT_JOB_TYPE_PREFIX = "io.camunda.agenticai:aiagent-job-worker:";
1268
+ /** Whether the agent rules lint this ad-hoc sub-process's tools (`isAgenticAdHocSubProcess`). */
1269
+ function isAgentic(ctx, adHoc) {
1270
+ const ext = adHoc.extensionElements;
1271
+ const marked = children(zeebe(ext, "properties")[0], "property").some((p) => p.attributes.name === TOOL_CONTAINER_PROPERTY && p.attributes.value === "true");
1272
+ return (marked ||
1273
+ adHoc.unknownAttributes["zeebe:modelerTemplate"] === AI_AGENT_TEMPLATE ||
1274
+ zeebe(ext, "taskDefinition")[0]?.attributes.type?.startsWith(AI_AGENT_JOB_TYPE_PREFIX) ===
1275
+ true ||
1276
+ (atLeast(ctx.version, FEATURE_SINCE.agentDefinition) &&
1277
+ zeebe(ext, "agentDefinition").length > 0));
1278
+ }
1279
+ /** The nearest ad-hoc sub-process around an element or flow. */
1280
+ function enclosingAdHoc(ctx, parent) {
1281
+ for (let p = parent; p !== undefined; p = ctx.elements.get(p.id)?.parent) {
1282
+ if (p.type === "adHocSubProcess")
1283
+ return p;
1284
+ }
1285
+ return undefined;
1286
+ }
1287
+ /** A tool: an activity directly in an agentic ad-hoc sub-process that nothing flows into. */
1288
+ function isToolEntry(ctx, el) {
1289
+ const parent = ctx.elements.get(el.id)?.parent;
1290
+ return (ACTIVITIES.has(el.type) &&
1291
+ !isEventSubProcess(el) &&
1292
+ el.incoming.length === 0 &&
1293
+ parent?.type === "adHocSubProcess" &&
1294
+ isAgentic(ctx, parent));
1295
+ }
1296
+ /** Every write of a tool's result along its flow, and whether that flow is one straight chain. */
1297
+ function resultChannels(ctx, entry) {
1298
+ const channels = [];
1299
+ const visited = new Set();
1300
+ const queue = [entry];
1301
+ let linear = true;
1302
+ for (let el = queue.shift(); el !== undefined; el = queue.shift()) {
1303
+ if (visited.has(el.id))
1304
+ continue;
1305
+ visited.add(el.id);
1306
+ for (const x of el.extensionElements) {
1307
+ if (x.name === "zeebe:ioMapping") {
1308
+ for (const output of children(x, "output")) {
1309
+ const { target, source } = output.attributes;
1310
+ channels.push({ kind: "output", value: target ?? "", source, element: el });
1311
+ }
1312
+ }
1313
+ if (x.name === "zeebe:script" || x.name === "zeebe:calledDecision") {
1314
+ const value = x.attributes.resultVariable;
1315
+ if (value)
1316
+ channels.push({ kind: "resultVariable", value, element: el });
1317
+ }
1318
+ if (x.name === "zeebe:taskHeaders") {
1319
+ for (const header of children(x, "header")) {
1320
+ const { key, value } = header.attributes;
1321
+ if (key === "resultVariable" || key === "resultExpression") {
1322
+ channels.push({ kind: key, value: value ?? "", element: el });
1323
+ }
1324
+ }
1325
+ }
1326
+ }
1327
+ if (el.outgoing.length > 1 || el.incoming.length > 1)
1328
+ linear = false;
1329
+ for (const flowId of el.outgoing) {
1330
+ const target = ctx.elements.get(ctx.flows.get(flowId)?.el.targetRef ?? "")?.el;
1331
+ if (target !== undefined)
1332
+ queue.push(target);
1333
+ }
1334
+ const parent = ctx.elements.get(el.id)?.parent;
1335
+ for (const sibling of parent?.flowElements ?? ctx.process.flowElements) {
1336
+ if (sibling.type === "boundaryEvent" && sibling.attachedToRef === el.id) {
1337
+ linear = false;
1338
+ queue.push(sibling);
1339
+ }
1340
+ }
1341
+ if (isContainer(el)) {
1342
+ queue.push(...el.flowElements.filter((child) => !DATA_ELEMENTS.has(child.type)));
1343
+ }
1344
+ }
1345
+ return { channels, linear };
1346
+ }
1347
+ function writesToolCallResult({ kind, value }) {
1348
+ if (kind === "resultExpression")
1349
+ return /\btoolCallResult\b/.test(value);
1350
+ return value === "toolCallResult" || value.startsWith("toolCallResult.");
1351
+ }
1352
+ /** The first `toolCallResult` written in the wrong case, if any. */
1353
+ function miscased(channel) {
1354
+ if (channel.kind === "resultExpression") {
1355
+ return (channel.value.match(/\btoolcallresult\b/gi) ?? []).find((t) => t !== "toolCallResult");
1356
+ }
1357
+ const lower = channel.value.toLowerCase();
1358
+ const variant = lower === "toolcallresult" || lower.startsWith("toolcallresult.");
1359
+ return variant && !writesToolCallResult(channel) ? channel.value : undefined;
1360
+ }
1361
+ /** A write that replaces `toolCallResult` whole, rather than a part of it or `context put()` onto it. */
1362
+ function overwrites({ kind, value, source }) {
1363
+ if (kind !== "output")
1364
+ return true;
1365
+ if (value !== "toolCallResult")
1366
+ return false;
1367
+ return !/^=?\s*context\s+put\s*\(\s*toolCallResult\s*,/.test(source ?? "");
1368
+ }
1369
+ /** `agent-tool-output-key` — a tool must hand its result back as `toolCallResult`. */
1370
+ function checkToolOutput(ctx, entry) {
1371
+ const { channels, linear } = resultChannels(ctx, entry);
1372
+ const rule = "agent-tool-output-key";
1373
+ const casing = (channel, text) => report(ctx, rule, channel.element.id, `Wrong casing "${text}": use toolCallResult (case-sensitive).`, "Write toolCallResult exactly; Camunda reads variable names case-sensitively.");
1374
+ if (channels.length === 0) {
1375
+ report(ctx, rule, entry.id, 'Tool returns nothing to the agent. Set a "toolCallResult" (at minimum, note the task completed).', "Add an output mapping with target toolCallResult.");
1376
+ return;
1377
+ }
1378
+ if (!channels.some(writesToolCallResult)) {
1379
+ for (const channel of channels) {
1380
+ const wrong = miscased(channel);
1381
+ if (wrong !== undefined) {
1382
+ casing(channel, wrong);
1383
+ continue;
1384
+ }
1385
+ report(ctx, rule, channel.element.id, '"toolCallResult" output is not mapped.', "Map the tool's result to toolCallResult — the agent reads nothing else.");
1386
+ }
1387
+ return;
1388
+ }
1389
+ for (const channel of channels) {
1390
+ const wrong = miscased(channel);
1391
+ if (wrong !== undefined)
1392
+ casing(channel, wrong);
1393
+ }
1394
+ if (!linear)
1395
+ return;
1396
+ const writes = channels.filter((c) => writesToolCallResult(c) && overwrites(c));
1397
+ for (let i = 1; i < writes.length; i++) {
1398
+ const earlier = writes[i - 1].element;
1399
+ report(ctx, rule, writes[i].element.id, `This overwrites the "toolCallResult" value set on "${earlier.name || earlier.id}".`, "Write parts of the result (toolCallResult.part), or combine them with context put(toolCallResult, ...).");
1400
+ }
1401
+ }
1402
+ /** `agent-fromai-contract` on a sequence flow's condition. */
1403
+ function checkFromAiCondition(ctx, flow) {
1404
+ const body = flow.conditionExpression?.text;
1405
+ if (body === undefined || !body.startsWith("="))
1406
+ return;
1407
+ const calls = fromAiCalls(body.slice(1).trim());
1408
+ const adHoc = enclosingAdHoc(ctx, ctx.flows.get(flow.id)?.parent);
1409
+ if (calls.length === 0 || adHoc === undefined || !isAgentic(ctx, adHoc))
1410
+ return;
1411
+ for (const _ of calls) {
1412
+ report(ctx, "agent-fromai-contract", flow.id, "fromAi() defines a tool input and cannot be used in a sequence flow condition. Define it in an input mapping on the tool's entry element.", "Read the value from the toolCall variable instead.");
1413
+ }
1414
+ }
1415
+ /** Why a `fromAi()` key argument cannot name a tool parameter, if it cannot. */
1416
+ function fromAiKeyProblem(arg) {
1417
+ switch (arg.type) {
1418
+ case "StringLiteral":
1419
+ return `fromAi() key must be a FEEL path, not a string literal. Remove the quotes around ${arg.text}.`;
1420
+ case "null":
1421
+ return 'fromAi() key must be a FEEL path starting with "toolCall.", not null.';
1422
+ case "NumericLiteral":
1423
+ return 'fromAi() key must be a FEEL path starting with "toolCall.", not a number.';
1424
+ case "ArithmeticExpression":
1425
+ return 'fromAi() key must be a FEEL path starting with "toolCall.", not an arithmetic expression.';
1426
+ case "FilterExpression":
1427
+ return 'fromAi() key must use dot notation, not bracket notation. Use toolCall.name instead of toolCall["name"].';
1428
+ case "VariableName":
1429
+ return `fromAi() key must start with "toolCall.". Use toolCall.${arg.text} instead of a bare name.`;
1430
+ case "PathExpression": {
1431
+ if (!arg.text.startsWith("toolCall.")) {
1432
+ return `fromAi() key must start with "toolCall.". Got ${arg.text}.`;
1433
+ }
1434
+ const segments = arg.text.split(".");
1435
+ return segments.length > 2
1436
+ ? `fromAi() key must be a single name under toolCall. Use toolCall.${segments[segments.length - 1]} instead of ${arg.text}.`
1437
+ : undefined;
1438
+ }
1439
+ case "IfExpression":
1440
+ return 'fromAi() key must be a FEEL path starting with "toolCall.", not a conditional expression. The connector requires a plain reference regardless of which branch would apply at runtime.';
1441
+ default:
1442
+ return `fromAi() key must be a FEEL path starting with "toolCall.", not a ${arg.type}.`;
1443
+ }
1444
+ }
1445
+ /**
1446
+ * `agent-fromai-contract` — `fromAi()` only defines a tool input in an input
1447
+ * mapping of a tool's entry element, with a `toolCall.<name>` key and a
1448
+ * literal description.
1449
+ */
1450
+ function checkFromAi(ctx, el) {
1451
+ const rule = "agent-fromai-contract";
1452
+ const parent = ctx.elements.get(el.id)?.parent;
1453
+ const adHoc = enclosingAdHoc(ctx, parent);
1454
+ const agentic = adHoc !== undefined && isAgentic(ctx, adHoc);
1455
+ const mappings = zeebe(el.extensionElements, "ioMapping");
1456
+ const say = (message, suggestion) => report(ctx, rule, el.id, message, suggestion);
1457
+ if (ACTIVITIES.has(el.type) && el.incoming.length === 0 && agentic && parent === adHoc) {
1458
+ const keys = new Map();
1459
+ for (const input of children(mappings[0], "input")) {
1460
+ const source = input.attributes.source;
1461
+ if (source === undefined || !source.startsWith("="))
1462
+ continue;
1463
+ for (const call of fromAiCalls(source.slice(1).trim())) {
1464
+ const key = call.args[0];
1465
+ if (key?.type === "PathExpression" && key.text.startsWith("toolCall.")) {
1466
+ keys.set(key.text, (keys.get(key.text) ?? 0) + 1);
1467
+ }
1468
+ }
1469
+ }
1470
+ for (const [key, count] of keys) {
1471
+ if (count < 2)
1472
+ continue;
1473
+ say(`fromAi() key ${key} is declared more than once in this tool. Declare it once and reference it directly elsewhere.`, "Declare each tool parameter once.");
1474
+ }
1475
+ }
1476
+ if (DATA_ELEMENTS.has(el.type))
1477
+ return;
1478
+ for (const mapping of mappings) {
1479
+ for (const output of children(mapping, "output")) {
1480
+ const source = output.attributes.source;
1481
+ if (source === undefined || !source.startsWith("=") || !agentic)
1482
+ continue;
1483
+ for (const _ of fromAiCalls(source.slice(1).trim())) {
1484
+ say("fromAi() defines a tool input and has no effect in an output mapping. Define it in an input mapping on the tool's entry element.", "Move the fromAi() call to an input mapping.");
1485
+ }
1486
+ }
1487
+ for (const input of children(mapping, "input")) {
1488
+ const source = input.attributes.source;
1489
+ if (source === undefined || !source.startsWith("="))
1490
+ continue;
1491
+ const calls = fromAiCalls(source.slice(1).trim());
1492
+ if (calls.length === 0)
1493
+ continue;
1494
+ if (adHoc === undefined || !agentic || el.incoming.length > 0 || parent !== adHoc) {
1495
+ const [message, suggestion] = adHoc === undefined
1496
+ ? [
1497
+ "fromAi() should only be used inside an agentic sub-process.",
1498
+ "Use fromAi() only in a tool of an AI Agent ad-hoc sub-process.",
1499
+ ]
1500
+ : !agentic
1501
+ ? [
1502
+ `The "${adHoc.name || adHoc.id}" sub-process is not marked as agentic, so fromAi() has no effect.`,
1503
+ `Set the zeebe:property ${TOOL_CONTAINER_PROPERTY}="true" on the ad-hoc sub-process, or apply the AI Agent template.`,
1504
+ ]
1505
+ : [
1506
+ "fromAi() is ignored here: only the tool's entry element defines AI inputs. Define it there and read the toolCall variable directly.",
1507
+ "Move the fromAi() call to the tool's first element.",
1508
+ ];
1509
+ for (const _ of calls)
1510
+ say(message, suggestion);
1511
+ continue;
1512
+ }
1513
+ for (const call of calls) {
1514
+ if (call.name !== "fromAi") {
1515
+ say(`Wrong function name "${call.name}". Use fromAi (case-sensitive).`, "Write fromAi exactly.");
1516
+ continue;
1517
+ }
1518
+ const [key, description] = call.args;
1519
+ if (key === undefined) {
1520
+ say("fromAi() requires a key argument: a FEEL path like toolCall.url.", "Pass the parameter as fromAi(toolCall.name, ...).");
1521
+ continue;
1522
+ }
1523
+ const problem = fromAiKeyProblem(key);
1524
+ if (problem !== undefined)
1525
+ say(problem, "Pass the parameter as fromAi(toolCall.name, ...).");
1526
+ if (description !== undefined && description.type !== "StringLiteral") {
1527
+ say("fromAi() description must be a string literal: a quoted string describing what the agent should provide.", 'Describe the parameter in a quoted string: fromAi(toolCall.name, "…").');
1528
+ }
1529
+ }
1530
+ }
1531
+ }
1532
+ }
1533
+ // ---------------------------------------------------------------------------
1534
+ // Existing checks
1535
+ // ---------------------------------------------------------------------------
1536
+ /** Whether a finding comes from the Camunda-version compatibility check (`compat/…`). */
1537
+ export function isCamundaCompatFinding(finding) {
1538
+ return finding.id.startsWith("compat/");
1539
+ }
1540
+ /**
1541
+ * Drops the compatibility findings another BPMN Kit check already reports on
1542
+ * the same element — `compat/implementation` where `deploy/service-task-no-type`
1543
+ * fired, and so on through each rule's `equivalents`. Keeps the existing
1544
+ * finding: it is the one fixes and docs point at.
1545
+ *
1546
+ * @param findings - Every finding of one `optimize()` run.
1547
+ */
1548
+ export function dedupeCamundaCompat(findings) {
1549
+ const reported = new Set(findings.map((f) => `${f.id}\u0000${f.elementIds[0] ?? ""}`));
1550
+ return findings.filter((f) => {
1551
+ if (!isCamundaCompatFinding(f))
1552
+ return true;
1553
+ const equivalents = CAMUNDA_COMPAT_RULES[f.id.slice("compat/".length)]?.equivalents ?? [];
1554
+ return !equivalents.some((id) => reported.has(`${id}\u0000${f.elementIds[0] ?? ""}`));
1555
+ });
1556
+ }
1557
+ // ---------------------------------------------------------------------------
1558
+ // .bpmnlintrc
1559
+ // ---------------------------------------------------------------------------
1560
+ const PLUGIN_NAMES = ["camunda-compat", "bpmnlint-plugin-camunda-compat"];
1561
+ const RULE_PREFIX = "camunda-compat/";
1562
+ /**
1563
+ * Takes the `bpmnlint-plugin-camunda-compat` part out of a resolved
1564
+ * `.bpmnlintrc`, so BPMN Kit's own compatibility check can stand in for it.
1565
+ *
1566
+ * - `extends: "plugin:camunda-compat/camunda-cloud-8-6"` (or the
1567
+ * `bpmnlint-plugin-camunda-compat` spelling) pins the target to 8.6 and
1568
+ * enables that config's rules at the plugin's severities; the last such
1569
+ * entry wins. It also enables bpmnlint's `start-event-required`, as the
1570
+ * plugin's configs do.
1571
+ * - `camunda-compat/<rule>` entries under `rules` override those severities.
1572
+ * - Everything else stays in `rest`, for `applyBpmnlintConfig`.
1573
+ *
1574
+ * @param config - A resolved `.bpmnlintrc`.
1575
+ * @returns `compat` when the file mentions the plugin at all, and the rest.
1576
+ */
1577
+ export function splitCamundaCompatConfig(config) {
1578
+ let version;
1579
+ let mentioned = false;
1580
+ const unresolvedExtends = [];
1581
+ for (const entry of config.unresolvedExtends) {
1582
+ const match = /^plugin:([^/]+)\/camunda-cloud-(\d+)-(\d+)$/.exec(entry);
1583
+ const found = match !== null && PLUGIN_NAMES.includes(match[1])
1584
+ ? normalizeCamundaVersion(`${match[2]}.${match[3]}`)
1585
+ : undefined;
1586
+ if (found === undefined) {
1587
+ unresolvedExtends.push(entry);
1588
+ continue;
1589
+ }
1590
+ version = found;
1591
+ mentioned = true;
1592
+ }
1593
+ const compatRules = {};
1594
+ if (version !== undefined) {
1595
+ for (const [rule, entry] of Object.entries(CAMUNDA_COMPAT_RULES)) {
1596
+ if (ruleActive(rule, version))
1597
+ compatRules[rule] = { severity: entry.severity };
1598
+ }
1599
+ }
1600
+ const rules = {};
1601
+ for (const [name, setting] of Object.entries(config.rules)) {
1602
+ if (name.startsWith(RULE_PREFIX)) {
1603
+ compatRules[name.slice(RULE_PREFIX.length)] = setting;
1604
+ mentioned = true;
1605
+ }
1606
+ else {
1607
+ rules[name] = setting;
1608
+ }
1609
+ }
1610
+ if (version !== undefined && rules["start-event-required"] === undefined) {
1611
+ rules["start-event-required"] = { severity: "error" };
1612
+ }
1613
+ const rest = { rules, unresolvedExtends };
1614
+ if (!mentioned)
1615
+ return { rest: config };
1616
+ return {
1617
+ compat: version !== undefined ? { version, rules: compatRules } : { rules: compatRules },
1618
+ rest,
1619
+ };
1620
+ }
1621
+ const CONFIG_SEVERITY = {
1622
+ error: "error",
1623
+ warn: "warning",
1624
+ info: "info",
1625
+ };
1626
+ /**
1627
+ * Applies the camunda-compat part of a `.bpmnlintrc` to a set of findings.
1628
+ *
1629
+ * A finding a configured plugin rule governs — its `compat/<rule>` findings
1630
+ * and the `equivalents` standing in for it — takes the rule's severity and
1631
+ * name, or is dropped when the rule is `off`, or when real bpmnlint already
1632
+ * ran it (`delegated`). Configured rules BPMN Kit does not check come back as
1633
+ * `unsupported`.
1634
+ *
1635
+ * @param findings - Output of `optimize()`, possibly filtered.
1636
+ * @param compat - From {@link splitCamundaCompatConfig}.
1637
+ * @param options - `delegated`: the project's bpmnlint reported these rules.
1638
+ */
1639
+ export function applyCamundaCompatConfig(findings, compat, options = {}) {
1640
+ const governing = new Map();
1641
+ for (const rule of Object.keys(compat.rules)) {
1642
+ governing.set(`compat/${rule}`, rule);
1643
+ for (const id of CAMUNDA_COMPAT_RULES[rule]?.equivalents ?? [])
1644
+ governing.set(id, rule);
1645
+ }
1646
+ const result = [];
1647
+ for (const finding of findings) {
1648
+ const rule = governing.get(finding.id);
1649
+ const setting = rule === undefined ? undefined : compat.rules[rule];
1650
+ if (rule === undefined || setting === undefined) {
1651
+ result.push(finding);
1652
+ continue;
1653
+ }
1654
+ if (options.delegated === true || setting.severity === "off")
1655
+ continue;
1656
+ result.push({
1657
+ ...finding,
1658
+ severity: CONFIG_SEVERITY[setting.severity],
1659
+ bpmnlintRule: `${RULE_PREFIX}${rule}`,
1660
+ });
1661
+ }
1662
+ const unsupported = options.delegated === true
1663
+ ? []
1664
+ : Object.entries(compat.rules)
1665
+ .filter(([rule, setting]) => {
1666
+ const coverage = CAMUNDA_COMPAT_RULES[rule]?.coverage;
1667
+ return (setting.severity !== "off" &&
1668
+ (coverage === undefined || coverage === "not-implemented"));
1669
+ })
1670
+ .map(([rule, setting]) => ({
1671
+ name: `${RULE_PREFIX}${rule}`,
1672
+ reason: "plugin-rule",
1673
+ severity: setting.severity,
1674
+ }));
1675
+ return { findings: result, unsupported };
1676
+ }
1677
+ //# sourceMappingURL=camunda-compat.js.map