@camunda8/cli 4.5.0-alpha.1 → 4.5.0-alpha.3

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.
@@ -8258,7 +8258,8 @@ var init_dist5 = __esm({
8258
8258
  });
8259
8259
 
8260
8260
  // default-plugins/element-template/commands/apply.ts
8261
- import { createRequire } from "node:module";
8261
+ import { createRequire as createRequire2 } from "node:module";
8262
+ import { dirname as dirname3 } from "node:path";
8262
8263
 
8263
8264
  // default-plugins/element-template/migration/moddle.ts
8264
8265
  function isModdleElement(value) {
@@ -9221,8 +9222,9 @@ function parseTemplateJson(content) {
9221
9222
 
9222
9223
  // default-plugins/element-template/template-ref.ts
9223
9224
  var import_semver4 = __toESM(require_semver2(), 1);
9224
- import { existsSync as existsSync3, readFileSync as readFileSync3 } from "node:fs";
9225
- import { resolve as resolvePath2 } from "node:path";
9225
+ import { existsSync as existsSync4, readdirSync, readFileSync as readFileSync3, statSync } from "node:fs";
9226
+ import { createRequire } from "node:module";
9227
+ import { dirname as dirname2, join as join2, resolve as resolvePath3 } from "node:path";
9226
9228
 
9227
9229
  // default-plugins/element-template/cache.ts
9228
9230
  var import_semver3 = __toESM(require_semver2(), 1);
@@ -9810,13 +9812,42 @@ function searchTemplates(query, { executionPlatformVersion } = {}) {
9810
9812
  return [...byId.values()];
9811
9813
  }
9812
9814
 
9815
+ // default-plugins/element-template/vendor.ts
9816
+ import { existsSync as existsSync3 } from "node:fs";
9817
+ import { dirname, resolve as resolvePath2 } from "node:path";
9818
+ import { fileURLToPath } from "node:url";
9819
+ var __dirname = dirname(fileURLToPath(import.meta.url));
9820
+ function resolveVendorBundle() {
9821
+ const candidates = [
9822
+ resolvePath2(
9823
+ __dirname,
9824
+ "..",
9825
+ "..",
9826
+ "dist",
9827
+ "vendor",
9828
+ "bpmn-element-templates.cjs"
9829
+ ),
9830
+ resolvePath2(__dirname, "..", "..", "vendor", "bpmn-element-templates.cjs")
9831
+ ];
9832
+ for (const path of candidates) {
9833
+ if (existsSync3(path)) {
9834
+ return path;
9835
+ }
9836
+ }
9837
+ throw new Error(
9838
+ `Vendor bundle not found. Run \`npm run build:vendor\` to build it.
9839
+ Searched: ${candidates.join(", ")}`
9840
+ );
9841
+ }
9842
+
9813
9843
  // default-plugins/element-template/template-ref.ts
9814
9844
  if (!globalThis.c8ctl) throw new Error("c8ctl runtime not initialised");
9815
9845
  var c8ctl2 = globalThis.c8ctl;
9846
+ var require2 = createRequire(import.meta.url);
9816
9847
  async function readBpmnInput(filePath) {
9817
9848
  if (filePath) {
9818
- const resolved = resolvePath2(filePath);
9819
- if (!existsSync3(resolved)) {
9849
+ const resolved = resolvePath3(filePath);
9850
+ if (!existsSync4(resolved)) {
9820
9851
  throw new Error(`File not found: ${filePath}`);
9821
9852
  }
9822
9853
  return { xml: readFileSync3(resolved, "utf-8"), source: resolved };
@@ -9932,6 +9963,104 @@ async function readTemplateFromPathOrUrl(input) {
9932
9963
  const content = await readFileOrUrl(input);
9933
9964
  return parseTemplateJson(content);
9934
9965
  }
9966
+ function localTemplateDirs(startDir) {
9967
+ const dirs = [];
9968
+ for (let dir = resolvePath3(startDir); ; dir = dirname2(dir)) {
9969
+ dirs.push(join2(dir, ".camunda", "element-templates"));
9970
+ if (dirname2(dir) === dir) break;
9971
+ }
9972
+ dirs.push(join2(c8ctl2.getModelerDataDir(), "resources", "element-templates"));
9973
+ return dirs;
9974
+ }
9975
+ function isFile(path) {
9976
+ try {
9977
+ return statSync(path).isFile();
9978
+ } catch {
9979
+ return false;
9980
+ }
9981
+ }
9982
+ function readLocalTemplates(dirs) {
9983
+ const result = [];
9984
+ for (const dir of dirs) {
9985
+ let files;
9986
+ try {
9987
+ files = readdirSync(dir, { recursive: true, withFileTypes: true }).filter((e) => e.name.toLowerCase().endsWith(".json")).map((e) => join2(e.parentPath, e.name)).filter(isFile).sort();
9988
+ } catch {
9989
+ continue;
9990
+ }
9991
+ for (const file of files) {
9992
+ let parsed;
9993
+ try {
9994
+ parsed = JSON.parse(readFileSync3(file, "utf-8"));
9995
+ } catch (error3) {
9996
+ const message = error3 instanceof Error ? error3.message : String(error3);
9997
+ throw new Error(`template ${file} parse error: ${message}`);
9998
+ }
9999
+ for (const template of Array.isArray(parsed) ? parsed : [parsed]) {
10000
+ result.push({ template, file });
10001
+ }
10002
+ }
10003
+ }
10004
+ return result;
10005
+ }
10006
+ function validateLocalTemplates(id, entries) {
10007
+ const {
10008
+ Modeler,
10009
+ CloudElementTemplatesCoreModule,
10010
+ ZeebeModdleExtension,
10011
+ HeadlessTextRendererModule
10012
+ } = require2(resolveVendorBundle());
10013
+ const modeler = new Modeler({
10014
+ additionalModules: [
10015
+ HeadlessTextRendererModule,
10016
+ CloudElementTemplatesCoreModule
10017
+ ],
10018
+ moddleExtensions: { zeebe: ZeebeModdleExtension }
10019
+ });
10020
+ const fileOf = new Map(entries.map((e) => [e.template, e.file]));
10021
+ const logger = c8ctl2.getLogger();
10022
+ modeler.get("eventBus").on("elementTemplates.errors", (event) => {
10023
+ const errors = isRecord(event) && Array.isArray(event.errors) ? event.errors : [];
10024
+ for (const error3 of errors) {
10025
+ const file = isRecord(error3) ? fileOf.get(error3.template) : void 0;
10026
+ const message = error3 instanceof Error ? error3.message : String(error3);
10027
+ logger.warn(
10028
+ `Ignoring element template${file ? ` in ${file}` : ""}: ${message}`
10029
+ );
10030
+ }
10031
+ });
10032
+ modeler.get("elementTemplatesLoader").setTemplates(entries.map((e) => e.template));
10033
+ return modeler.get("elementTemplates").getAll(id) ?? [];
10034
+ }
10035
+ function findLocalTemplates(startDir, id) {
10036
+ const entries = readLocalTemplates(localTemplateDirs(startDir)).filter(
10037
+ (e) => isRecord(e.template) && e.template.id === id
10038
+ );
10039
+ return entries.length === 0 ? [] : validateLocalTemplates(id, entries);
10040
+ }
10041
+ function pickTemplate(candidates, ref, {
10042
+ executionPlatformVersion,
10043
+ requireEngineCompatibility = false
10044
+ }) {
10045
+ const eligible = requireEngineCompatibility && ref.version === void 0 ? candidates.filter(
10046
+ (template) => isEngineCompatible(template, executionPlatformVersion ?? "")
10047
+ ) : candidates;
10048
+ return pickVersion(eligible, {
10049
+ version: ref.version,
10050
+ executionPlatformVersion: requireEngineCompatibility ? void 0 : executionPlatformVersion
10051
+ });
10052
+ }
10053
+ async function resolveTemplateId(ref, {
10054
+ searchDir = process.cwd(),
10055
+ localTemplates,
10056
+ ...options
10057
+ } = {}) {
10058
+ return pickTemplate(
10059
+ localTemplates ?? findLocalTemplates(searchDir, ref.id),
10060
+ ref,
10061
+ options
10062
+ ) ?? resolveOotbTemplate(ref, options);
10063
+ }
9935
10064
  async function resolveOotbTemplate(ref, {
9936
10065
  executionPlatformVersion,
9937
10066
  requireEngineCompatibility = false,
@@ -9946,12 +10075,9 @@ async function resolveOotbTemplate(ref, {
9946
10075
  `Element template '${ref.id}' not found. Run 'c8ctl element-template sync' to refresh the cache, or use 'c8ctl element-template search <query>' to find an id.`
9947
10076
  );
9948
10077
  }
9949
- const eligible = requireEngineCompatibility && ref.version === void 0 ? candidates.filter(
9950
- (template) => isEngineCompatible(template, executionPlatformVersion ?? "")
9951
- ) : candidates;
9952
- const picked = pickVersion(eligible, {
9953
- version: ref.version,
9954
- executionPlatformVersion: requireEngineCompatibility ? void 0 : executionPlatformVersion
10078
+ const picked = pickTemplate(candidates, ref, {
10079
+ executionPlatformVersion,
10080
+ requireEngineCompatibility
9955
10081
  });
9956
10082
  if (!picked) {
9957
10083
  if (ref.version !== void 0) {
@@ -9982,7 +10108,7 @@ async function loadTemplate(templateArg, {
9982
10108
  let engineVersionIgnoredByPinnedVersion = false;
9983
10109
  if (ref.kind === "id") {
9984
10110
  engineVersionIgnoredByPinnedVersion = ref.version !== void 0 && Boolean(executionPlatformVersion);
9985
- template = await resolveOotbTemplate(ref, {
10111
+ template = await resolveTemplateId(ref, {
9986
10112
  executionPlatformVersion: ref.version === void 0 ? executionPlatformVersion : void 0
9987
10113
  });
9988
10114
  } else {
@@ -10011,38 +10137,10 @@ async function loadTemplate(templateArg, {
10011
10137
  };
10012
10138
  }
10013
10139
 
10014
- // default-plugins/element-template/vendor.ts
10015
- import { existsSync as existsSync4 } from "node:fs";
10016
- import { dirname, resolve as resolvePath3 } from "node:path";
10017
- import { fileURLToPath } from "node:url";
10018
- var __dirname = dirname(fileURLToPath(import.meta.url));
10019
- function resolveVendorBundle() {
10020
- const candidates = [
10021
- resolvePath3(
10022
- __dirname,
10023
- "..",
10024
- "..",
10025
- "dist",
10026
- "vendor",
10027
- "bpmn-element-templates.cjs"
10028
- ),
10029
- resolvePath3(__dirname, "..", "..", "vendor", "bpmn-element-templates.cjs")
10030
- ];
10031
- for (const path of candidates) {
10032
- if (existsSync4(path)) {
10033
- return path;
10034
- }
10035
- }
10036
- throw new Error(
10037
- `Vendor bundle not found. Run \`npm run build:vendor\` to build it.
10038
- Searched: ${candidates.join(", ")}`
10039
- );
10040
- }
10041
-
10042
10140
  // default-plugins/element-template/commands/apply.ts
10043
10141
  if (!globalThis.c8ctl) throw new Error("c8ctl runtime not initialised");
10044
10142
  var c8ctl3 = globalThis.c8ctl;
10045
- var require2 = createRequire(import.meta.url);
10143
+ var require3 = createRequire2(import.meta.url);
10046
10144
  function forceSetValues(modeler, element, template, setArgs) {
10047
10145
  const modeling = modeler.get("modeling");
10048
10146
  const extensionElements = getModdleElement(
@@ -10074,7 +10172,7 @@ function forceSetValues(modeler, element, template, setArgs) {
10074
10172
  }
10075
10173
  async function applyElementTemplate(xml2, template, elementId, setArgs) {
10076
10174
  const vendorPath = resolveVendorBundle();
10077
- const vendor = require2(vendorPath);
10175
+ const vendor = require3(vendorPath);
10078
10176
  const {
10079
10177
  Modeler,
10080
10178
  CloudElementTemplatesCoreModule,
@@ -10145,7 +10243,10 @@ async function applySubcommand(args) {
10145
10243
  const executionPlatformVersion = await getExecutionPlatformVersion(
10146
10244
  input.xml
10147
10245
  );
10148
- template = await resolveOotbTemplate(ref, { executionPlatformVersion });
10246
+ template = await resolveTemplateId(ref, {
10247
+ searchDir: bpmnFilePath ? dirname3(input.source) : process.cwd(),
10248
+ executionPlatformVersion
10249
+ });
10149
10250
  if (ref.version === void 0 && !executionPlatformVersion) {
10150
10251
  logger.warn(
10151
10252
  `BPMN has no modeler:executionPlatformVersion \u2014 applying latest version (${template.version}) of ${ref.id}.`
@@ -10220,11 +10321,63 @@ async function applySubcommand(args) {
10220
10321
  }
10221
10322
 
10222
10323
  // default-plugins/element-template/commands/edit.ts
10223
- import { createRequire as createRequire2 } from "node:module";
10324
+ import { createRequire as createRequire3 } from "node:module";
10325
+ import { dirname as dirname4 } from "node:path";
10326
+ import { parseArgs as parseArgv } from "node:util";
10224
10327
  if (!globalThis.c8ctl) throw new Error("c8ctl runtime not initialised");
10225
10328
  var c8ctl4 = globalThis.c8ctl;
10226
- var require3 = createRequire2(import.meta.url);
10227
- async function planEdit(modeler, elementId, setArgs) {
10329
+ var require4 = createRequire3(import.meta.url);
10330
+ function extractTemplateFlag(args) {
10331
+ const { tokens } = parseArgv({
10332
+ args,
10333
+ options: { template: { type: "string" } },
10334
+ strict: false,
10335
+ allowPositionals: true,
10336
+ tokens: true
10337
+ });
10338
+ let templateArg;
10339
+ const consumed = /* @__PURE__ */ new Set();
10340
+ for (const token of tokens) {
10341
+ if (token.kind !== "option" || token.name !== "template") continue;
10342
+ if (!token.value) {
10343
+ throw new Error(
10344
+ "--template requires a value (an OOTB id[@version], a local path, or an https:// URL)"
10345
+ );
10346
+ }
10347
+ templateArg = token.value;
10348
+ consumed.add(token.index);
10349
+ if (!token.inlineValue) consumed.add(token.index + 1);
10350
+ }
10351
+ return { templateArg, rest: args.filter((_, i) => !consumed.has(i)) };
10352
+ }
10353
+ async function resolveEditTemplate(templateArg, templateId, templateVersion, searchDir) {
10354
+ if (templateArg) {
10355
+ const ref = parseTemplateRef(templateArg);
10356
+ const template = ref?.kind === "id" ? await resolveTemplateId(
10357
+ { ...ref, version: ref.version ?? templateVersion },
10358
+ { searchDir }
10359
+ ) : await readTemplateFromPathOrUrl(templateArg);
10360
+ if (template.id !== templateId || template.version !== templateVersion) {
10361
+ throw new Error(
10362
+ `--template ${templateArg} (${template.id ?? "<no id>"} v${template.version ?? "?"}) does not match the template recorded on the element (${templateId} v${templateVersion}). Use 'apply' to switch templates or versions.`
10363
+ );
10364
+ }
10365
+ return template;
10366
+ }
10367
+ try {
10368
+ return await resolveTemplateId(
10369
+ { kind: "id", id: templateId, version: templateVersion },
10370
+ { searchDir }
10371
+ );
10372
+ } catch (error3) {
10373
+ const message = error3 instanceof Error ? error3.message : String(error3);
10374
+ throw new Error(
10375
+ `${message}
10376
+ For a custom template, place it under .camunda/element-templates/ next to the BPMN file (or in a parent directory), or pass --template <path|url>.`
10377
+ );
10378
+ }
10379
+ }
10380
+ async function planEdit(modeler, elementId, setArgs, templateArg, searchDir) {
10228
10381
  const elementRegistry = modeler.get("elementRegistry");
10229
10382
  const element = elementRegistry.get(elementId);
10230
10383
  if (!element) {
@@ -10245,11 +10398,12 @@ async function planEdit(modeler, elementId, setArgs) {
10245
10398
  `Element "${elementId}" has zeebe:modelerTemplate="${templateId}" but no recorded zeebe:modelerTemplateVersion. 'edit' requires a pinned version to resolve the exact template that was applied \u2014 use 'apply' with an explicit template reference instead.`
10246
10399
  );
10247
10400
  }
10248
- const template = await resolveOotbTemplate({
10249
- kind: "id",
10250
- id: templateId,
10251
- version: templateVersion
10252
- });
10401
+ const template = await resolveEditTemplate(
10402
+ templateArg,
10403
+ templateId,
10404
+ templateVersion,
10405
+ searchDir
10406
+ );
10253
10407
  const extensionElements = getModdleElement(
10254
10408
  element.businessObject,
10255
10409
  "extensionElements"
@@ -10300,7 +10454,8 @@ async function planEdit(modeler, elementId, setArgs) {
10300
10454
  async function editSubcommand(args) {
10301
10455
  const logger = c8ctl4.getLogger();
10302
10456
  installStdoutEpipeHandler();
10303
- const parsed = parseArgs(args);
10457
+ const { templateArg, rest } = extractTemplateFlag(args);
10458
+ const parsed = parseArgs(rest);
10304
10459
  if (parsed.error) {
10305
10460
  throw new Error(parsed.error);
10306
10461
  }
@@ -10330,7 +10485,7 @@ async function editSubcommand(args) {
10330
10485
  );
10331
10486
  }
10332
10487
  const vendorPath = resolveVendorBundle();
10333
- const vendor = require3(vendorPath);
10488
+ const vendor = require4(vendorPath);
10334
10489
  const { Modeler, ZeebeModdleExtension, HeadlessTextRendererModule } = vendor;
10335
10490
  const modeler = new Modeler({
10336
10491
  additionalModules: [HeadlessTextRendererModule],
@@ -10339,7 +10494,13 @@ async function editSubcommand(args) {
10339
10494
  let plan;
10340
10495
  try {
10341
10496
  await modeler.importXML(input.xml);
10342
- plan = await planEdit(modeler, elementId, parsed.setArgs);
10497
+ plan = await planEdit(
10498
+ modeler,
10499
+ elementId,
10500
+ parsed.setArgs,
10501
+ templateArg,
10502
+ bpmnFilePath ? dirname4(input.source) : process.cwd()
10503
+ );
10343
10504
  } catch (error3) {
10344
10505
  const message = error3 instanceof Error ? error3.message : String(error3);
10345
10506
  throw new Error(`Error editing element: ${message}`);
@@ -10442,7 +10603,7 @@ async function getSubcommand(args) {
10442
10603
  process.stdout.write(content);
10443
10604
  return;
10444
10605
  }
10445
- const template = await resolveOotbTemplate(ref);
10606
+ const template = await resolveTemplateId(ref);
10446
10607
  let cleaned = stripInternalMetadata(template);
10447
10608
  if (noIcon) {
10448
10609
  cleaned = stripIcon(cleaned);
@@ -11058,8 +11219,8 @@ import {
11058
11219
  readFileSync as readFileSync5,
11059
11220
  unlinkSync as unlinkSync3
11060
11221
  } from "node:fs";
11061
- import { createRequire as createRequire3 } from "node:module";
11062
- import { resolve as resolvePath4 } from "node:path";
11222
+ import { createRequire as createRequire4 } from "node:module";
11223
+ import { dirname as dirname6, resolve as resolvePath4 } from "node:path";
11063
11224
 
11064
11225
  // default-plugins/element-template/migration/element-values.ts
11065
11226
  var AD_HOC_PROPERTIES = [
@@ -12253,14 +12414,14 @@ import { homedir, platform } from "node:os";
12253
12414
 
12254
12415
  // src/core/runtime.ts
12255
12416
  import { readFileSync as readFileSync4 } from "node:fs";
12256
- import { dirname as dirname2, join as join2 } from "node:path";
12417
+ import { dirname as dirname5, join as join3 } from "node:path";
12257
12418
  import { fileURLToPath as fileURLToPath2 } from "node:url";
12258
12419
  var __filename = fileURLToPath2(import.meta.url);
12259
- var __dirname2 = dirname2(__filename);
12420
+ var __dirname2 = dirname5(__filename);
12260
12421
  var UNVERSIONED_DEV_BUILD = "0.0.0-semantically-released";
12261
12422
  function getVersion() {
12262
12423
  try {
12263
- const packageJsonPath = join2(__dirname2, "..", "..", "package.json");
12424
+ const packageJsonPath = join3(__dirname2, "..", "..", "package.json");
12264
12425
  const packageJson = JSON.parse(readFileSync4(packageJsonPath, "utf-8"));
12265
12426
  return packageJson.version || UNVERSIONED_DEV_BUILD;
12266
12427
  } catch {
@@ -12282,7 +12443,7 @@ var C8ctl = class {
12282
12443
  platform: process.platform,
12283
12444
  arch: process.arch,
12284
12445
  cwd: process.cwd(),
12285
- rootDir: join2(__dirname2, "..", "..")
12446
+ rootDir: join3(__dirname2, "..", "..")
12286
12447
  };
12287
12448
  /**
12288
12449
  * Inject dependencies that cannot be imported at module level
@@ -12319,6 +12480,12 @@ var C8ctl = class {
12319
12480
  }
12320
12481
  return this._deps.getUserDataDir();
12321
12482
  }
12483
+ getModelerDataDir() {
12484
+ if (!this._deps) {
12485
+ throw new Error("c8ctl.init() must be called before getModelerDataDir()");
12486
+ }
12487
+ return this._deps.getModelerDataDir();
12488
+ }
12322
12489
  npm(options) {
12323
12490
  if (!this._deps) {
12324
12491
  throw new Error("c8ctl.init() must be called before npm()");
@@ -12908,7 +13075,7 @@ function reportToJson(report, {
12908
13075
  // default-plugins/element-template/commands/migrate.ts
12909
13076
  if (!globalThis.c8ctl) throw new Error("c8ctl runtime not initialised");
12910
13077
  var c8ctl10 = globalThis.c8ctl;
12911
- var require4 = createRequire3(import.meta.url);
13078
+ var require5 = createRequire4(import.meta.url);
12912
13079
  var COMMAND = "element-template update";
12913
13080
  var USAGE = "c8ctl element-template update <template-id> [<element-id>] [<file.bpmn>] [--to <template>[@<n>]] [--recipe <file>] [--map <from>=<to>]... [--in-place]";
12914
13081
  function readFlagValue(args, index, flag) {
@@ -13052,7 +13219,7 @@ function embeddedRecipe(template) {
13052
13219
  }
13053
13220
  }
13054
13221
  function createModeler() {
13055
- const vendor = require4(resolveVendorBundle());
13222
+ const vendor = require5(resolveVendorBundle());
13056
13223
  return new vendor.Modeler({
13057
13224
  additionalModules: [
13058
13225
  vendor.HeadlessTextRendererModule,
@@ -13061,21 +13228,44 @@ function createModeler() {
13061
13228
  moddleExtensions: { zeebe: vendor.ZeebeModdleExtension }
13062
13229
  });
13063
13230
  }
13231
+ function templatePool(cachedTemplates, searchDir) {
13232
+ const local = /* @__PURE__ */ new Map();
13233
+ const localOf = (id) => {
13234
+ const templates = local.get(id) ?? findLocalTemplates(searchDir, id);
13235
+ local.set(id, templates);
13236
+ return templates;
13237
+ };
13238
+ const identity2 = (t) => JSON.stringify([t.id, t.version ?? 0]);
13239
+ return {
13240
+ localOf,
13241
+ pool(ids) {
13242
+ const shadowing = [...new Set(ids)].filter((id) => id !== void 0).flatMap(localOf);
13243
+ const shadowed = new Set(shadowing.map(identity2));
13244
+ return [
13245
+ ...shadowing,
13246
+ ...cachedTemplates.filter((t) => !shadowed.has(identity2(t)))
13247
+ ];
13248
+ }
13249
+ };
13250
+ }
13064
13251
  async function resolveTarget({
13065
13252
  templateId,
13066
13253
  to,
13067
13254
  executionPlatformVersion,
13068
- cachedTemplates
13255
+ cachedTemplates,
13256
+ templatePool: templatePool2
13069
13257
  }) {
13070
13258
  const arg = to ?? templateId;
13071
13259
  const ref = parseTemplateRef(arg);
13072
13260
  if (ref?.kind === "id") {
13073
- requireCachePresent();
13074
13261
  resolveCatalog(
13075
- migrationTemplates(cachedTemplates.filter((t) => t.id === ref.id))
13262
+ migrationTemplates(
13263
+ templatePool2.pool([ref.id]).filter((t) => t.id === ref.id)
13264
+ )
13076
13265
  );
13077
13266
  }
13078
- const target = ref?.kind === "id" ? await resolveOotbTemplate(ref, {
13267
+ const target = ref?.kind === "id" ? await resolveTemplateId(ref, {
13268
+ localTemplates: templatePool2.localOf(ref.id),
13079
13269
  executionPlatformVersion,
13080
13270
  requireEngineCompatibility: true,
13081
13271
  templates: cachedTemplates
@@ -13184,9 +13374,12 @@ async function runMigrateInternal({ parsed, templateId, elementId, bpmnFilePath
13184
13374
  const valuesOf2 = (element) => enumerateElementValues(getExtensionElements(element.businessObject));
13185
13375
  redaction.values = selected2.flatMap(({ element }) => valuesOf2(element));
13186
13376
  const cachedTemplates = loadCache() ?? [];
13187
- const lineages = (ids) => migrationTemplates(cachedTemplates).filter((t) => ids.includes(t.id));
13377
+ const pool2 = templatePool(
13378
+ cachedTemplates,
13379
+ bpmnFilePath ? dirname6(input.source) : process.cwd()
13380
+ );
13381
+ const lineages = (ids) => migrationTemplates(pool2.pool(ids)).filter((t) => ids.includes(t.id));
13188
13382
  redaction.templates = lineages([templateId, parsed.to]);
13189
- const cache = compatibleTemplates(cachedTemplates, engineVersion);
13190
13383
  const recipe = parsed.recipePath ? loadRecipeFile(parsed.recipePath) : void 0;
13191
13384
  if (recipe && !recipe.sources.some((s) => s.sourceTemplateId === templateId)) {
13192
13385
  throw new Error(
@@ -13197,8 +13390,13 @@ async function runMigrateInternal({ parsed, templateId, elementId, bpmnFilePath
13197
13390
  templateId,
13198
13391
  to: parsed.to,
13199
13392
  executionPlatformVersion: engineVersion,
13200
- cachedTemplates
13393
+ cachedTemplates,
13394
+ templatePool: pool2
13201
13395
  });
13396
+ const cache = compatibleTemplates(
13397
+ pool2.pool([templateId, target.id]),
13398
+ engineVersion
13399
+ );
13202
13400
  const templates = resolveCatalog(
13203
13401
  cache.filter((t) => t.id === templateId || t.id === target.id),
13204
13402
  [target]
@@ -13598,7 +13796,7 @@ var metadata = {
13598
13796
  commands: {
13599
13797
  "element-template": {
13600
13798
  description: "Apply, inspect, and export Camunda element templates",
13601
- helpDescription: "Apply Camunda element templates to BPMN elements, inspect template metadata and properties, search the out-of-the-box template catalogue, export raw template JSON, and manage the local template cache.\n\n<template> is a local path, an https:// URL, or an OOTB template id (optionally @<version>).\n\napply --set name=value targets a property by binding name (run `get-properties` to discover names). Pass --set multiple times to set multiple properties. Prefix with a binding type (input | output | header | property | taskDefinition) when the same name is bound across multiple types \u2014 e.g. --set input:correlationKey=order-42.\n\nedit --set name=value updates a property on an element that already has a template applied, without re-running template application \u2014 it never resets other template-owned content (including hand-customized extension values a template doesn't fully control) and doesn't need a <template> argument (it reads zeebe:modelerTemplate/-Version off the element). The tradeoff: edit can only change bindings that already have a value; a property whose gating condition was never met has nothing to edit \u2014 use apply --set to materialize it first.\n\nupdate <template-id> moves every element that uses that template to its latest compatible version, or to the template given with --to <template>[@<n>] (an id, path or URL); pass an element id to update only that element. Values the target binds under another key are moved when it carries a migration recipe (metadata.migratesFrom) or one is passed with --recipe <file>; --map <from>=<to> moves a value per element when no recipe covers it; the rest carry over by key. A report lists what was dropped, added, moved and changed. --dry-run previews the migration and writes nothing; it exits 1 when an element would fail to migrate or the write would need --allow-lossy. The file is written once, and only if every element migrates.\n\nFEEL values: properties with feel=required always store a FEEL expression (prefixed with `=`). For those properties, c8ctl auto-prepends `=` when it is missing, so `--set key=orderId` writes `=orderId` to the BPMN \u2014 equivalent to `--set key==orderId`. Properties with feel=optional keep the value verbatim; you must supply the `=` prefix yourself when you want to write a FEEL expression for those. Three forms for feel=required properties:\n --set key='=value' canonical: single-quoted FEEL value (explicit =)\n --set 'key==value' compact: whole argument single-quoted (explicit =)\n --set key=value shorthand: = auto-prepended (feel=required only)\nLeading/trailing whitespace is stripped from values, and whitespace immediately after a FEEL `=` prefix is also stripped, so `--set 'key== value'` is equivalent to `--set 'key==value'`.",
13799
+ helpDescription: "Apply Camunda element templates to BPMN elements, inspect template metadata and properties, search the out-of-the-box template catalogue, export raw template JSON, and manage the local template cache.\n\n<template> is a local path, an https:// URL, or a template id (optionally @<version>). An id is looked up in .camunda/element-templates/ (next to the BPMN file, or in the current directory, or any parent of either) and in Desktop Modeler's resources/element-templates/ before the OOTB cache.\n\napply --set name=value targets a property by binding name (run `get-properties` to discover names). Pass --set multiple times to set multiple properties. Prefix with a binding type (input | output | header | property | taskDefinition) when the same name is bound across multiple types \u2014 e.g. --set input:correlationKey=order-42.\n\nedit --set name=value updates a property on an element that already has a template applied, without re-running template application \u2014 it never resets other template-owned content (including hand-customized extension values a template doesn't fully control) and doesn't need a <template> argument (it reads zeebe:modelerTemplate/-Version off the element and resolves it from .camunda/element-templates/ next to the BPMN file or a parent directory, then the OOTB cache). Pass --template <template> to point at a custom template explicitly; it must match the element's recorded id/version. The tradeoff: edit can only change bindings that already have a value; a property whose gating condition was never met has nothing to edit \u2014 use apply --set to materialize it first.\n\nupdate <template-id> moves every element that uses that template to its latest compatible version, or to the template given with --to <template>[@<n>] (an id, path or URL; an id resolves as above, local templates first); pass an element id to update only that element. Values the target binds under another key are moved when it carries a migration recipe (metadata.migratesFrom) or one is passed with --recipe <file>; --map <from>=<to> moves a value per element when no recipe covers it; the rest carry over by key. A report lists what was dropped, added, moved and changed. --dry-run previews the migration and writes nothing; it exits 1 when an element would fail to migrate or the write would need --allow-lossy. The file is written once, and only if every element migrates.\n\nFEEL values: properties with feel=required always store a FEEL expression (prefixed with `=`). For those properties, c8ctl auto-prepends `=` when it is missing, so `--set key=orderId` writes `=orderId` to the BPMN \u2014 equivalent to `--set key==orderId`. Properties with feel=optional keep the value verbatim; you must supply the `=` prefix yourself when you want to write a FEEL expression for those. Three forms for feel=required properties:\n --set key='=value' canonical: single-quoted FEEL value (explicit =)\n --set 'key==value' compact: whole argument single-quoted (explicit =)\n --set key=value shorthand: = auto-prepended (feel=required only)\nLeading/trailing whitespace is stripped from values, and whitespace immediately after a FEEL `=` prefix is also stripped, so `--set 'key== value'` is equivalent to `--set 'key==value'`.",
13602
13800
  subcommands: [
13603
13801
  {
13604
13802
  name: "search",
@@ -13778,6 +13976,10 @@ var commands = {
13778
13976
  type: "string",
13779
13977
  description: "Cap the number of matches (default 20) [search]"
13780
13978
  },
13979
+ template: {
13980
+ type: "string",
13981
+ description: "Template to resolve the element's recorded id/version against (id[@version], path, or URL) [edit]"
13982
+ },
13781
13983
  "engine-version": {
13782
13984
  type: "string",
13783
13985
  description: "Filter to template versions compatible with the given Camunda engine version (e.g. 8.8.0) [search|info|get-properties]"
@@ -154,7 +154,7 @@ and faster than any lazy scheme.
154
154
  |---|---|---|
155
155
  | `https://...` | starts with `http(s)://` | fetched directly, no cache |
156
156
  | local path | contains `/`/`\`, starts with `.`, or ends with `.json` | read from disk |
157
- | `<id>` or `<id>@<version>` | otherwise | resolved against cache |
157
+ | `<id>` or `<id>@<version>` | otherwise | `.camunda/element-templates/`, then the cache |
158
158
 
159
159
  For `<id>` (no `@<version>`):
160
160
 
@@ -168,6 +168,39 @@ For `<id>` (no `@<version>`):
168
168
  and warns the user to pin with `id@<n>` if they want a specific one
169
169
  (same annotation as `info`).
170
170
 
171
+ An id is first looked up locally, the way Desktop Modeler's
172
+ [`ElementTemplatesProvider`](https://github.com/camunda/camunda-modeler/blob/main/app/lib/config/providers/ElementTemplatesProvider.js)
173
+ finds templates:
174
+
175
+ - `.camunda/element-templates/**/*.json` in the BPMN file's directory (or
176
+ the current directory when there is no BPMN file) and every ancestor, up
177
+ to and including the filesystem root, nearest first;
178
+ - then `resources/element-templates/**/*.json` in the Modeler's user-data
179
+ dir (`camunda-modeler` under `%APPDATA%`, `$XDG_CONFIG_HOME` or
180
+ `~/.config`, `~/Library/Application Support`; overridable via
181
+ `C8CTL_MODELER_DIR`).
182
+
183
+ A file holds one template or an array; a malformed file is an error
184
+ (`template <path> parse error`), as in the Modeler. All templates with the
185
+ id are merged into one pool and validated with the
186
+ `CloudElementTemplatesCoreModule` loader from `bpmn-js-element-templates`
187
+ (schema validation; a duplicate id+version keeps the first, i.e. nearest,
188
+ one). Rejected templates are reported as warnings and skipped. The version
189
+ is then picked once over the pool with the same rules as for the cache.
190
+ Only when no local template matches does resolution fall back to the
191
+ cache, so a local hit works with a cold cache.
192
+
193
+ The validator is reached through the core module's loader rather than the
194
+ package-root `CloudElementTemplatesValidator` export: the root entry also
195
+ pulls in the properties panel, which touches `document` at load time and
196
+ cannot be loaded in Node.
197
+
198
+ Version picking differs slightly from the Modeler's `getLatest`, which is
199
+ tied to a Modeler instance: c8ctl checks only the `camunda` engine (the
200
+ Modeler also checks the other engines it knows, e.g. `elementTemplates`),
201
+ and a deprecated latest compatible version is still picked, where
202
+ `getLatest` returns nothing.
203
+
171
204
  Errors include the available versions to make the next step obvious:
172
205
 
173
206
  ```
@@ -191,6 +224,11 @@ the same key. `update` registers the applied template as well, so
191
224
  the library's own update semantics apply, and add a recipe on top for values
192
225
  that moved.
193
226
 
227
+ - **Template resolution.** The target id resolves like every other id, local
228
+ templates first (see above), with `isEngineCompatible` as the eligibility
229
+ rule; the cache is required only on the fallback. Steps, the applied source
230
+ and redaction read template versions from the cache, with the local versions
231
+ of the involved ids shadowing cached ones of the same id and version.
194
232
  - **Recipe location.** A recipe is carried by the template it migrates *to*, in
195
233
  `metadata.migratesFrom`, so it travels with the template through the
196
234
  marketplace and the cache. `metadata` is the schema's free-form area; it
@@ -1264,6 +1264,43 @@ export declare const COMMAND_REGISTRY: {
1264
1264
  }];
1265
1265
  };
1266
1266
  };
1267
+ migrate: {
1268
+ description: string;
1269
+ helpDescription: string;
1270
+ helpResource: string;
1271
+ hasDetailedHelp: true;
1272
+ helpFooterLabel: string;
1273
+ mutating: true;
1274
+ requiresResource: true;
1275
+ helpExamples: {
1276
+ command: string;
1277
+ description: string;
1278
+ }[];
1279
+ resources: string[];
1280
+ flags: {
1281
+ targetProcessDefinitionKey: {
1282
+ type: "string";
1283
+ description: string;
1284
+ required: true;
1285
+ };
1286
+ map: {
1287
+ type: "string";
1288
+ multiple: true;
1289
+ description: string;
1290
+ };
1291
+ processDefinitionKey: {
1292
+ type: "string";
1293
+ description: string;
1294
+ validate: (value: string) => ProcessDefinitionKey;
1295
+ };
1296
+ };
1297
+ resourcePositionals: {
1298
+ "process-instance": readonly [{
1299
+ readonly name: "key";
1300
+ readonly validate: (value: string) => ProcessInstanceKey;
1301
+ }];
1302
+ };
1303
+ };
1267
1304
  await: {
1268
1305
  description: string;
1269
1306
  helpDescription: string;