@elementumai/edk 0.10.2 → 0.10.4

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 (127) hide show
  1. package/README.md +7 -7
  2. package/dist-sdk/src/catalog/org.d.ts +7 -5
  3. package/dist-sdk/src/catalog/org.js +14 -9
  4. package/dist-sdk/src/catalog/token.js +4 -0
  5. package/dist-sdk/src/core/types/app.d.ts +22 -0
  6. package/dist-sdk/src/engine/build/context.d.ts +8 -0
  7. package/dist-sdk/src/engine/build/source-context.d.ts +3 -4
  8. package/dist-sdk/src/engine/coverage-gaps.d.ts +2 -0
  9. package/dist-sdk/src/engine/coverage-gaps.js +3 -0
  10. package/dist-sdk/src/engine/ei/state.d.ts +48 -0
  11. package/dist-sdk/src/engine/ei/state.js +91 -0
  12. package/dist-sdk/src/engine/pull/authored-address.d.ts +100 -0
  13. package/dist-sdk/src/engine/pull/authored-address.js +360 -0
  14. package/dist-sdk/src/engine/pull/context.d.ts +69 -0
  15. package/dist-sdk/src/engine/tf/expr.d.ts +7 -0
  16. package/dist-sdk/src/engine/tf/expr.js +62 -18
  17. package/dist-sdk/src/engine/tf/index.d.ts +2 -1
  18. package/dist-sdk/src/engine/tf/index.js +2 -1
  19. package/dist-sdk/src/engine/tf/labels.d.ts +10 -2
  20. package/dist-sdk/src/engine/tf/labels.js +15 -2
  21. package/dist-sdk/src/engine/tf/parse.js +19 -6
  22. package/dist-sdk/src/engine/tf/scan.d.ts +22 -0
  23. package/dist-sdk/src/engine/tf/scan.js +123 -0
  24. package/dist-sdk/src/engine/workspace/backend.d.ts +34 -0
  25. package/dist-sdk/src/engine/workspace/backend.js +104 -0
  26. package/dist-sdk/src/engine/workspace/generated-file.d.ts +3 -0
  27. package/dist-sdk/src/engine/workspace/generated-file.js +6 -0
  28. package/dist-sdk/src/engine/workspace/loader.d.ts +8 -0
  29. package/dist-sdk/src/engine/workspace/loader.js +22 -2
  30. package/dist-sdk/src/entities/agent/to-tf.d.ts +13 -11
  31. package/dist-sdk/src/entities/agent/to-tf.js +17 -12
  32. package/dist-sdk/src/entities/agent-tool/from-tf.js +2 -2
  33. package/dist-sdk/src/entities/agent-tool/to-tf.js +10 -1
  34. package/dist-sdk/src/entities/app/build.d.ts +36 -4
  35. package/dist-sdk/src/entities/app/build.js +67 -4
  36. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +18 -0
  37. package/dist-sdk/src/entities/app/from-tf.js +17 -9
  38. package/dist-sdk/src/entities/app/module.js +1 -0
  39. package/dist-sdk/src/entities/app/stage-keys.d.ts +82 -0
  40. package/dist-sdk/src/entities/app/stage-keys.js +160 -0
  41. package/dist-sdk/src/entities/app/to-tf.js +17 -21
  42. package/dist-sdk/src/entities/approval-chain/from-tf.d.ts +9 -1
  43. package/dist-sdk/src/entities/approval-chain/from-tf.js +31 -3
  44. package/dist-sdk/src/entities/approval-chain/module.js +12 -4
  45. package/dist-sdk/src/entities/approval-chain/to-tf.d.ts +1 -0
  46. package/dist-sdk/src/entities/approval-chain/to-tf.js +6 -1
  47. package/dist-sdk/src/entities/automation/build.js +25 -8
  48. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +3 -0
  49. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +5 -3
  50. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +90 -17
  51. package/dist-sdk/src/entities/automation/from-tf.d.ts +28 -6
  52. package/dist-sdk/src/entities/automation/from-tf.js +140 -23
  53. package/dist-sdk/src/entities/automation/module.js +158 -44
  54. package/dist-sdk/src/entities/automation/output-field-types.d.ts +8 -0
  55. package/dist-sdk/src/entities/automation/output-field-types.js +20 -0
  56. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +2 -0
  57. package/dist-sdk/src/entities/automation/output-key-wire-name.js +18 -0
  58. package/dist-sdk/src/entities/automation/to-tf.d.ts +10 -1
  59. package/dist-sdk/src/entities/automation/to-tf.js +200 -38
  60. package/dist-sdk/src/entities/automation/triggers.d.ts +2 -0
  61. package/dist-sdk/src/entities/automation/triggers.js +1 -0
  62. package/dist-sdk/src/entities/chart/from-tf.d.ts +6 -0
  63. package/dist-sdk/src/entities/chart/from-tf.js +9 -1
  64. package/dist-sdk/src/entities/dashboard/from-tf.js +51 -4
  65. package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +3 -0
  66. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +48 -4
  67. package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +2 -0
  68. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +7 -2
  69. package/dist-sdk/src/entities/element/build.js +1 -1
  70. package/dist-sdk/src/entities/element/from-tf.d.ts +12 -6
  71. package/dist-sdk/src/entities/element/from-tf.js +26 -8
  72. package/dist-sdk/src/entities/element/module.js +3 -2
  73. package/dist-sdk/src/entities/element/to-tf.d.ts +3 -2
  74. package/dist-sdk/src/entities/element/to-tf.js +32 -25
  75. package/dist-sdk/src/entities/field/allow-list.d.ts +18 -0
  76. package/dist-sdk/src/entities/field/allow-list.js +42 -0
  77. package/dist-sdk/src/entities/field/build.d.ts +38 -3
  78. package/dist-sdk/src/entities/field/build.js +7 -2
  79. package/dist-sdk/src/entities/field/from-tf.js +178 -20
  80. package/dist-sdk/src/entities/field/module.js +2 -0
  81. package/dist-sdk/src/entities/field/options.d.ts +2 -0
  82. package/dist-sdk/src/entities/field/order.d.ts +9 -0
  83. package/dist-sdk/src/entities/field/order.js +33 -0
  84. package/dist-sdk/src/entities/field/to-tf.d.ts +6 -0
  85. package/dist-sdk/src/entities/field/to-tf.js +87 -0
  86. package/dist-sdk/src/entities/field/types.js +3 -0
  87. package/dist-sdk/src/entities/relationship/build.d.ts +3 -3
  88. package/dist-sdk/src/entities/relationship/from-tf.js +4 -2
  89. package/dist-sdk/src/entities/relationship/to-tf.js +3 -1
  90. package/dist-sdk/src/entities/service-account/workspace-owner.d.ts +8 -3
  91. package/dist-sdk/src/entities/service-account/workspace-owner.js +12 -4
  92. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +5 -0
  93. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +13 -0
  94. package/dist-sdk/src/entities/shared/filters/ast.d.ts +7 -0
  95. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +1 -1
  96. package/dist-sdk/src/entities/skill/module.js +28 -2
  97. package/dist-sdk/src/entities/skill/to-tf.js +19 -14
  98. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
  99. package/dist-sdk/src/entities/skill-tool/from-tf.js +3 -0
  100. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +6 -1
  101. package/dist-sdk/src/entities/skill-tool/to-tf.js +6 -1
  102. package/dist-sdk/src/entities/task/build.js +1 -1
  103. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +2 -0
  104. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +6 -2
  105. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +11 -0
  106. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +13 -38
  107. package/dist-sdk/src/entities/view/custom-view-validate.d.ts +29 -0
  108. package/dist-sdk/src/entities/view/custom-view-validate.js +293 -0
  109. package/dist-sdk/src/entities/view/from-tf.d.ts +10 -0
  110. package/dist-sdk/src/entities/view/from-tf.js +164 -26
  111. package/dist-sdk/src/entities/view/to-tf.d.ts +6 -0
  112. package/dist-sdk/src/entities/view/to-tf.js +14 -6
  113. package/dist-sdk/src/entities/visual-flow/from-tf.d.ts +2 -1
  114. package/dist-sdk/src/entities/visual-flow/from-tf.js +11 -2
  115. package/dist-sdk/src/entities/visual-flow/module.js +15 -5
  116. package/dist-sdk/src/entities/visual-flow/to-tf.d.ts +2 -0
  117. package/dist-sdk/src/entities/visual-flow/to-tf.js +1 -1
  118. package/dist-sdk/src/entities/widget/build.d.ts +8 -1
  119. package/dist-sdk/src/entities/widget/from-tf.js +12 -6
  120. package/dist-sdk/src/entities/widget/to-tf.d.ts +1 -0
  121. package/dist-sdk/src/entities/widget/to-tf.js +16 -0
  122. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +8 -2
  123. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  124. package/dist-sdk/src/graph/index.d.ts +6 -0
  125. package/dist-sdk/src/graph/index.js +1 -0
  126. package/dist-sdk/src/graph/types.d.ts +66 -2
  127. package/package.json +2 -17
@@ -2,10 +2,27 @@ import { EntityTfError } from "../../engine/entity.js";
2
2
  import { resourceRefLabel } from "../../engine/pull/context.js";
3
3
  import { isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel } from "../../engine/tf/index.js";
4
4
  import { fieldKeyFromTfRef } from "../field/from-tf.js";
5
+ import { LostStageHandleError, lostStageMessage, pulledStageHandle } from "../app/stage-keys.js";
5
6
  import { APPROVAL_PROCESS_RESOURCE_TYPE } from "./module.js";
6
7
  const KNOWN = new Set(["id", "app_id", "name", "stage_id", "number_of_dynamic_approvers", "locked_field_ids", "managed_by_automation", "approve_button_text", "deny_button_text", "exception_button_text", "default_reason", "approval_summary"]);
7
8
  function stringAttr(attrs, key) { return typeof attrs[key] === "string" ? attrs[key] : undefined; }
8
- export function approvalChainFromTf(block, appTfLabel, ctx) {
9
+ /**
10
+ * The lost-stage warning when an approval process sits on a stage with no
11
+ * handle of its own (see `pulledStageHandle`, #1136), else undefined. Such a
12
+ * chain is left unmanaged, so anything that references it (an automation's
13
+ * approval task or trigger) cannot be authored either.
14
+ */
15
+ export function approvalChainLostStage(block, appTfLabel, stageHandles) {
16
+ const stageValue = block.attrs["stage_id"];
17
+ if (!isTfExpr(stageValue) || stageValue.$expr !== "local" || stageValue.name !== `${appTfLabel}_stage_ids_by_key`)
18
+ return undefined;
19
+ const index = stageValue.path[0];
20
+ if (typeof index !== "object")
21
+ return undefined;
22
+ const pulled = pulledStageHandle(index.index, stageHandles);
23
+ return pulled.kind === "lost" ? lostStageMessage(`${block.type}.${block.label}`, index.index, pulled, "the approval chain is left unmanaged") : undefined;
24
+ }
25
+ export function approvalChainFromTf(block, appTfLabel, ctx, stageHandles) {
9
26
  if (block.type !== APPROVAL_PROCESS_RESOURCE_TYPE || block.label === undefined)
10
27
  throw new EntityTfError(`expected ${APPROVAL_PROCESS_RESOURCE_TYPE}`);
11
28
  for (const key of Object.keys(block.attrs))
@@ -30,8 +47,19 @@ export function approvalChainFromTf(block, appTfLabel, ctx) {
30
47
  let stageId;
31
48
  if (isTfExpr(stageValue) && stageValue.$expr === "local" && stageValue.name === `${appTfLabel}_stage_ids_by_key`) {
32
49
  const index = stageValue.path[0];
33
- if (typeof index === "object")
34
- stage = tfLabelToTsLabel(index.index);
50
+ if (typeof index === "object") {
51
+ // Imported keys may keep punctuation ("approval_&_execution"); pull a
52
+ // handle that build maps back to this same stage (#1136). A stage whose
53
+ // only handle is another stage's key keeps the chain unmanaged rather
54
+ // than binding it to that stage.
55
+ const lost = approvalChainLostStage(block, appTfLabel, stageHandles);
56
+ if (lost !== undefined)
57
+ throw new LostStageHandleError(lost);
58
+ const pulled = pulledStageHandle(index.index, stageHandles);
59
+ if (pulled.kind !== "handle")
60
+ throw new EntityTfError(`${block.type}.${block.label}: stage key ${JSON.stringify(index.index)} has no terraform label handle`);
61
+ stage = tfLabelToTsLabel(pulled.handle);
62
+ }
35
63
  }
36
64
  else if (typeof stageValue === "string")
37
65
  stageId = stageValue;
@@ -2,6 +2,7 @@ import { rootParentFactoryEntry } from "../../catalog/render-helpers.js";
2
2
  import { NO_DATA } from "../../graph/types.js";
3
3
  import { approvalChainFromTf } from "./from-tf.js";
4
4
  import { printApprovalChain } from "./printer.js";
5
+ import { appStageKeyByHandle, LostStageHandleError, stageHandleIndexFromTfStages } from "../app/stage-keys.js";
5
6
  import { approvalChainToTf } from "./to-tf.js";
6
7
  export const APPROVAL_PROCESS_RESOURCE_TYPE = "elementum_approval_process";
7
8
  function stub(refName, parent) { return { __kind: "approvalChain", refName, name: refName, parent }; }
@@ -25,17 +26,24 @@ function refFromAuthoring(args) {
25
26
  function extract(blocks, _stream, ctx) {
26
27
  const items = [];
27
28
  const skipped = [];
29
+ const releaseIfManaged = [];
28
30
  const diagnostics = [];
31
+ const stageHandles = stageHandleIndexFromTfStages(ctx.resourceByAddress?.(`elementum_app.${ctx.appTfLabel}`)?.attrs["stages"]);
29
32
  for (const block of blocks) {
30
33
  try {
31
- items.push(approvalChainFromTf(block, ctx.appTfLabel, ctx));
34
+ items.push(approvalChainFromTf(block, ctx.appTfLabel, ctx, stageHandles));
32
35
  }
33
36
  catch (error) {
34
- skipped.push(`${block.type}.${block.label ?? ""}`);
37
+ const address = `${block.type}.${block.label ?? ""}`;
38
+ skipped.push(address);
39
+ // A chain on a stage with no handle of its own has no authored form:
40
+ // release an earlier adoption instead of destroying it (#1136).
41
+ if (error instanceof LostStageHandleError)
42
+ releaseIfManaged.push(address);
35
43
  diagnostics.push(error instanceof Error ? error.message : String(error));
36
44
  }
37
45
  }
38
- return { items, skipped, diagnostics };
46
+ return { items, skipped, ...(releaseIfManaged.length > 0 && { releaseIfManaged }), diagnostics };
39
47
  }
40
48
  export const approvalChainModule = {
41
49
  kind: "approval-chain", stream: { role: "streamMember" }, authoring: { unit: "ownFile", bag: "approval-chains" },
@@ -44,7 +52,7 @@ export const approvalChainModule = {
44
52
  lifecycle: {
45
53
  participates: true, extractOwnFile: extract,
46
54
  printOwnFile: (item, opts) => { const chain = item; return { refName: chain.refName, source: printApprovalChain(chain, opts.appRefName) }; },
47
- toTf: (entity, ctx) => approvalChainToTf(entity, { appRefName: ctx.appRefName, appTfLabel: ctx.appTfLabel }),
55
+ toTf: (entity, ctx) => approvalChainToTf(entity, { appRefName: ctx.appRefName, appTfLabel: ctx.appTfLabel, stageKeyByTfLabel: appStageKeyByHandle(ctx.streamRootEntity?.payload) }),
48
56
  },
49
57
  canvas: { participates: true, label: "Approval processes", glyph: "✓", component: "generic" },
50
58
  catalog: { participates: true, refKind: "approvalChain", catalogBag: "approvalChains", renderOrder: 26, catalogRoot: "app", renderEntry: rootParentFactoryEntry("approvalChainRef"), stubRef: stub, refFromAuthoring },
@@ -3,6 +3,7 @@ import { type TfBlock } from "../../engine/tf/index.js";
3
3
  export declare function approvalChainToTf(entity: DeployableEntity, ctx: {
4
4
  appRefName: string;
5
5
  appTfLabel: string;
6
+ stageKeyByTfLabel?: ReadonlyMap<string, string>;
6
7
  }): {
7
8
  blocks: readonly TfBlock[];
8
9
  address: string;
@@ -20,7 +20,7 @@ export function approvalChainToTf(entity, ctx) {
20
20
  approve_button_text: payload.approveButton ?? "Approve",
21
21
  };
22
22
  if (payload.stage !== undefined)
23
- attrs["stage_id"] = expr.local(`${ctx.appTfLabel}_stage_ids_by_key`, [{ index: tsLabelToTfLabel(payload.stage) }]);
23
+ attrs["stage_id"] = expr.local(`${ctx.appTfLabel}_stage_ids_by_key`, [{ index: stageIndex(payload.stage, ctx.stageKeyByTfLabel) }]);
24
24
  else if (payload.stageId !== undefined)
25
25
  attrs["stage_id"] = payload.stageId;
26
26
  if (payload.exceptionButton !== undefined)
@@ -44,3 +44,8 @@ export function approvalChainToTf(entity, ctx) {
44
44
  const block = { kind: "resource", type: APPROVAL_PROCESS_RESOURCE_TYPE, label, attrs };
45
45
  return { blocks: [block], address: `${APPROVAL_PROCESS_RESOURCE_TYPE}.${label}` };
46
46
  }
47
+ /** The `stage_ids_by_key` index for a stage handle; imported keys may keep punctuation (#1136). */
48
+ function stageIndex(stage, stageKeyByTfLabel) {
49
+ const tfLabel = tsLabelToTfLabel(stage);
50
+ return stageKeyByTfLabel?.get(tfLabel) ?? tfLabel;
51
+ }
@@ -29,7 +29,7 @@ import { valid as validSemver } from "semver";
29
29
  import { EntityTfError } from "../../engine/entity.js";
30
30
  import { isOnDemandRecordType } from "../shared/types/field-types.js";
31
31
  import { buildContext, createForEachItemProxy } from "../shared/context.js";
32
- import { outputFieldTypesFromScriptSchema } from "./output-field-types.js";
32
+ import { outputFieldTypesFromScriptSchema, scriptSchemaIsSingleStringArray } from "./output-field-types.js";
33
33
  import { isRef } from "../shared/ref.js";
34
34
  import { API_TASK_REF_WIRE_NAMES, OUTPUT_KEY_CANONICAL, OUTPUT_KEY_WIRE_NAME } from "./output-key-wire-name.js";
35
35
  import { extractScriptBody, inferOutputSchema, isScriptFile, readScriptFile, toPlatformScriptBody, tryExtractFromCurrentSource } from "./script-code.js";
@@ -286,8 +286,18 @@ function assertKnownScriptOutput(name, taskRefKey, schema, checkDeclaredResult)
286
286
  throw new EntityTfError(`executeScript${taskRefKey === undefined ? "" : ` task "${taskRefKey}"`} has no output "${name}"; ` +
287
287
  `declared result properties are ${listed === "" ? "(none)" : listed}.`);
288
288
  }
289
+ // Only suggest reads that exist: a `.result.<name>` the schema doesn't declare
290
+ // builds in a filter but reads nothing at runtime (#1725).
291
+ const declared = declaredScriptResultProperties(schema);
292
+ const missing = declared !== undefined && !declared.has(name.split(".")[0] ?? "");
293
+ const at = `ctx.actions.${taskRefKey ?? "<script>"}`;
294
+ const uses = missing ? [...declared].map((p) => `${at}.result.${p}`) : [`${at}.result.${name}`];
295
+ if ((missing || !name.includes(".")) && scriptSchemaIsSingleStringArray(schema))
296
+ uses.push(`${at}.stringArrayResult`);
289
297
  throw new EntityTfError(`executeScript${taskRefKey === undefined ? "" : ` task "${taskRefKey}"`} has no output "${name}"; ` +
290
- `script outputs are read under result. Use ctx.actions.${taskRefKey ?? "<script>"}.result.${name}.`);
298
+ `script outputs are read under result` +
299
+ (missing ? ` and the declared result properties are ${declared.size === 0 ? "(none)" : [...declared].join(", ")}` : "") +
300
+ (uses.length > 0 ? `. Use ${uses.join(" or ")}.` : "."));
291
301
  }
292
302
  /**
293
303
  * Forward output-name rewrites, the inverse of the deserializer's read-side
@@ -380,8 +390,9 @@ export function rewriteCanonicalOutputRefName(taskKey, name, taskRefKey, schema)
380
390
  if (taskKey === "findRelatedRecords" && FIND_RELATED_RECORDS_COUNT_REF_NAMES.has(name.split(".")[0])) {
381
391
  throw findRelatedRecordsTotalCountError(taskRefKey);
382
392
  }
393
+ // Workflow outputs are jsonencode envelopes on the task id, not refs-map indexes.
383
394
  if (taskKey === "executeScript")
384
- assertKnownScriptOutput(name, taskRefKey, schema, true);
395
+ assertKnownScriptOutput(name, taskRefKey, schema, false);
385
396
  if (taskKey === "api" && name.startsWith("file.")) {
386
397
  // apiRequest's file SUB-refs (.file.content / .contentType / .name) have no
387
398
  // canonical service_tasks output name of their own — they resolve by the
@@ -464,10 +475,12 @@ function rewriteTaskOutputRefs(node, taskKindByRefKey, scriptSchemas,
464
475
  // platform's CANONICAL service_tasks output name (edk#835). Task inputs and
465
476
  // filters (canonical=false, the default) keep the display rewrite — #1271 owns
466
477
  // those positions.
467
- canonical = false) {
478
+ canonical = false,
479
+ // Field assignments rebuild an undeclared result.* as the value envelope.
480
+ checkDeclaredScriptResult = true) {
468
481
  if (Array.isArray(node)) {
469
482
  for (const item of node)
470
- rewriteTaskOutputRefs(item, taskKindByRefKey, scriptSchemas, canonical);
483
+ rewriteTaskOutputRefs(item, taskKindByRefKey, scriptSchemas, canonical, checkDeclaredScriptResult);
471
484
  return;
472
485
  }
473
486
  if (node === null || typeof node !== "object")
@@ -489,8 +502,11 @@ canonical = false) {
489
502
  }
490
503
  const ref = rec.taskReference;
491
504
  if (ref && typeof ref.taskRefKey === "string" && typeof ref.name === "string") {
492
- const rewrite = canonical ? rewriteCanonicalOutputRefName : rewriteForwardTaskRefName;
493
- ref.name = rewrite(taskKindByRefKey.get(ref.taskRefKey), ref.name, ref.taskRefKey, scriptSchemas.get(ref.taskRefKey));
505
+ const kind = taskKindByRefKey.get(ref.taskRefKey);
506
+ const schema = scriptSchemas.get(ref.taskRefKey);
507
+ ref.name = canonical
508
+ ? rewriteCanonicalOutputRefName(kind, ref.name, ref.taskRefKey, schema)
509
+ : rewriteForwardTaskRefName(kind, ref.name, ref.taskRefKey, schema, checkDeclaredScriptResult);
494
510
  }
495
511
  if (rec.type === "TASK" && typeof rec.taskRefKey === "string" && typeof rec.name === "string") {
496
512
  // Filter `{type:"TASK"}` shapes never appear in a workflow OUTPUT subtree;
@@ -502,7 +518,8 @@ canonical = false) {
502
518
  // keeps the display/forward rewrite even under an output, so its decode
503
519
  // (decodeCalculationTaskMustache) stays idempotent.
504
520
  const childCanonical = key === "calculationReference" ? false : canonical;
505
- rewriteTaskOutputRefs(v, taskKindByRefKey, scriptSchemas, childCanonical);
521
+ const childCheck = key === "workflowFields" ? false : checkDeclaredScriptResult;
522
+ rewriteTaskOutputRefs(v, taskKindByRefKey, scriptSchemas, childCanonical, childCheck);
506
523
  }
507
524
  }
508
525
  /**
@@ -119,6 +119,7 @@ export type TriggerAst = {
119
119
  app: AppRefAst | UnresolvedRefAst;
120
120
  approvalChain?: string | ApprovalChainRefAst;
121
121
  status: "ACTIVE" | "STEP_APPROVED" | "CANCELLED" | "DENIED" | "APPROVED";
122
+ filter?: Filter<RefExpr, RefExpr>;
122
123
  } | {
123
124
  kind: "schedule";
124
125
  frequency: "HOURLY" | "DAILY" | "WEEKLY" | "MONTHLY";
@@ -150,6 +151,8 @@ export interface AutomationAst {
150
151
  readonly triggersOtherAutomations?: boolean;
151
152
  readonly status: AutomationStatus;
152
153
  readonly serviceAccountName?: string;
154
+ /** Owning app's catalog key when the service account belongs to another app. */
155
+ readonly serviceAccountAppRefName?: string;
153
156
  readonly trigger: TriggerAst;
154
157
  readonly tasks: readonly TaskCall[];
155
158
  readonly outputs?: readonly {
@@ -41,9 +41,11 @@ import type { MergePulledSourceContext, UnresolvedReferenceDiagnostic } from "..
41
41
  * least the baseline — the state revision, or the freshly printed live revision
42
42
  * when state has no entry yet (adoption is about to import it). An older
43
43
  * authored token is replaced by that baseline. Without readable state the
44
- * pre-#1590 behaviour (always keep authored) is unchanged.
44
+ * pre-#1590 behaviour (always keep authored) is unchanged. With no existing
45
+ * source, a publish already bound in state keeps the state revision: the
46
+ * export prints `1.0.<live version>`, which Read never writes back (#1902).
45
47
  */
46
- export declare function preserveAuthoredAutomationRevision(freshSource: string, existingSource: string, context?: MergePulledSourceContext): string;
48
+ export declare function preserveAuthoredAutomationRevision(freshSource: string, existingSource: string | undefined, context?: MergePulledSourceContext): string;
47
49
  /**
48
50
  * Extract a string-literal (or `+`-concatenated literals) description from
49
51
  * authored automation source. Pull reprints often omit description entirely
@@ -77,7 +79,7 @@ export declare function extractAuthoredAutomationDescription(source: string): st
77
79
  */
78
80
  export declare function preserveAuthoredAutomationDescription(freshSource: string, existingSource: string): string;
79
81
  /** Pull merge: preserve authored revision + description across live reprint. */
80
- export declare function preserveAuthoredAutomationPullMeta(freshSource: string, existingSource: string, context?: MergePulledSourceContext): string;
82
+ export declare function preserveAuthoredAutomationPullMeta(freshSource: string, existingSource: string | undefined, context?: MergePulledSourceContext): string;
81
83
  /** A plain-JS script file printed beside the automation, relative to the automations folder. */
82
84
  export interface PrintedScriptFile {
83
85
  readonly path: string;
@@ -35,11 +35,12 @@ import { sdkPackageSpecifier } from "../../../internal/sdk-package.js";
35
35
  import { safeIdentifier } from "../../../internal/safe-identifier.js";
36
36
  import { isRefExpr } from "../../shared/filters/ast.js";
37
37
  import { printFilter as printCanonicalFilter } from "../../shared/filters/print.js";
38
- import { isUuid } from "../../../engine/tf/labels.js";
38
+ import { isUuid, sanitizeName, tfLabelToTsLabel } from "../../../engine/tf/labels.js";
39
39
  import { UNRESOLVED_FIELD_MARKER } from "../../shared/ref.js";
40
40
  import { UNRESOLVED_REFERENCE_MARKER } from "../filter.js";
41
41
  import { INJECTED_TS_IGNORE, scriptFileText } from "../script-code.js";
42
42
  import { isRequiredSecret } from "../tasks.js";
43
+ import { canonicalImportId } from "../../../engine/pull/authored-address.js";
43
44
  import { unresolvedReferenceComment } from "../../../engine/pull/ref-only.js";
44
45
  // ---------------------------------------------------------------------------
45
46
  // Factory name mapping — decoded task `factory` → v2 factory function name.
@@ -141,14 +142,20 @@ function revisionAtLeast(a, b) {
141
142
  function stateWorkflowRevision(context) {
142
143
  if (context?.platformId === undefined || context.stateResources === undefined)
143
144
  return undefined;
145
+ const want = canonicalImportId(context.platformId);
146
+ if (want === "")
147
+ return undefined;
144
148
  for (const resource of context.stateResources) {
145
- if (resource.type !== "elementum_workflow_publish")
149
+ if (resource.mode !== "managed" || resource.module !== undefined || resource.type !== "elementum_workflow_publish")
146
150
  continue;
147
- for (const instance of resource.instances ?? []) {
148
- const attrs = instance.attributes;
149
- if (attrs?.id === context.platformId && typeof attrs.workflow_revision === "string")
150
- return attrs.workflow_revision;
151
- }
151
+ const attrs = resource.instances?.[0]?.attributes;
152
+ const id = attrs?.id;
153
+ const revision = attrs?.workflow_revision;
154
+ if (typeof id !== "string" || canonicalImportId(id) !== want)
155
+ continue;
156
+ if (typeof revision !== "string" || revision === "")
157
+ continue;
158
+ return revision;
152
159
  }
153
160
  return undefined;
154
161
  }
@@ -161,9 +168,17 @@ function stateWorkflowRevision(context) {
161
168
  * least the baseline — the state revision, or the freshly printed live revision
162
169
  * when state has no entry yet (adoption is about to import it). An older
163
170
  * authored token is replaced by that baseline. Without readable state the
164
- * pre-#1590 behaviour (always keep authored) is unchanged.
171
+ * pre-#1590 behaviour (always keep authored) is unchanged. With no existing
172
+ * source, a publish already bound in state keeps the state revision: the
173
+ * export prints `1.0.<live version>`, which Read never writes back (#1902).
165
174
  */
166
175
  export function preserveAuthoredAutomationRevision(freshSource, existingSource, context) {
176
+ if (existingSource === undefined) {
177
+ const bound = stateWorkflowRevision(context);
178
+ if (bound === undefined || !REVISION_PROPERTY.test(freshSource))
179
+ return freshSource;
180
+ return freshSource.replace(REVISION_PROPERTY, (_line, prefix) => `${prefix}${JSON.stringify(bound)},`);
181
+ }
167
182
  const authored = REVISION_PROPERTY.exec(existingSource)?.[3];
168
183
  if (authored === undefined || authored === "")
169
184
  return freshSource;
@@ -503,7 +518,8 @@ export function preserveAuthoredAutomationDescription(freshSource, existingSourc
503
518
  }
504
519
  /** Pull merge: preserve authored revision + description across live reprint. */
505
520
  export function preserveAuthoredAutomationPullMeta(freshSource, existingSource, context) {
506
- return preserveAuthoredAutomationDescription(preserveAuthoredAutomationRevision(freshSource, existingSource, context), existingSource);
521
+ const revised = preserveAuthoredAutomationRevision(freshSource, existingSource, context);
522
+ return existingSource === undefined ? revised : preserveAuthoredAutomationDescription(revised, existingSource);
507
523
  }
508
524
  function emptyImports() {
509
525
  return {
@@ -654,7 +670,7 @@ function printAutomation(ast, opts, externalScripts) {
654
670
  }
655
671
  body.push(` app: catalog.${appRefName},`);
656
672
  if (ast.serviceAccountName !== undefined) {
657
- body.push(` serviceAccount: serviceAccountRef({ app: catalog.${appRefName}, name: ${quote(ast.serviceAccountName)} }),`);
673
+ body.push(` serviceAccount: serviceAccountRef({ app: catalog.${ast.serviceAccountAppRefName ?? appRefName}, name: ${quote(ast.serviceAccountName)} }),`);
658
674
  }
659
675
  body.push(` status: automationStatus.${automationStatusKey(ast.status)},`);
660
676
  body.push(` actions: actions()`);
@@ -882,6 +898,7 @@ function printTrigger(trigger, state) {
882
898
  `app: ${printRef(trigger.app, state, DEFAULT_CTX)}`,
883
899
  ...(approvalChain !== undefined ? [`approvalChain: ${approvalChain}`] : []),
884
900
  `status: ${quote(trigger.status)}`,
901
+ ...(trigger.filter ? [`filter: ${printFilter(trigger.filter, state)}`] : []),
885
902
  ];
886
903
  return `${approvalProcessStatusUpdated}({\n ${parts.join(",\n ")}\n })`;
887
904
  }
@@ -1387,7 +1404,7 @@ function printFieldAssignments(values, target, state, indent, refCtx) {
1387
1404
  const parentRef = target?.refName ?? assignment?.foreignOwnerName ?? "task";
1388
1405
  const parentName = target?.name ?? assignment?.foreignOwnerName ?? parentRef;
1389
1406
  const fieldName = assignment?.foreignFieldName ?? fieldKey;
1390
- const fieldType = assignment?.foreignFieldType ?? "TEXT";
1407
+ const fieldType = assignment?.foreignFieldType ?? unconfirmedFieldType(assignment?.value);
1391
1408
  fieldExpr = (`{ __kind: "field", refName: ${quote(fieldKey)}, name: ${quote(fieldName)}, fieldType: ${quote(fieldType)}, ` +
1392
1409
  `parent: ${quote(parentRef)}, parentKind: "task", parentName: ${quote(parentName)} }`);
1393
1410
  }
@@ -1395,7 +1412,7 @@ function printFieldAssignments(values, target, state, indent, refCtx) {
1395
1412
  !target.inCatalog &&
1396
1413
  assignment?.foreignOwnerNamespace !== undefined &&
1397
1414
  !fieldKey.startsWith(UNRESOLVED_FIELD_MARKER)) {
1398
- const fieldType = assignment.foreignFieldType ?? "TEXT";
1415
+ const fieldType = assignment.foreignFieldType ?? unconfirmedFieldType(assignment.value);
1399
1416
  const parentName = assignment.foreignOwnerName ?? target.name ?? target.refName;
1400
1417
  fieldExpr = (`{ __kind: "field", refName: ${quote(fieldKey)}, name: ${quote(assignment.foreignFieldName ?? fieldKey)}, fieldType: ${quote(fieldType)}, ` +
1401
1418
  `parent: ${quote(target.refName)}, parentKind: ${quote(target.kind)}, parentName: ${quote(parentName)}, ` +
@@ -1416,7 +1433,10 @@ function printFieldAssignments(values, target, state, indent, refCtx) {
1416
1433
  const foreignOwner = assignment?.foreignOwnerName;
1417
1434
  const foreignKind = assignment?.foreignEntityType;
1418
1435
  if ((foreignKind === "app" || foreignKind === "element") && foreignOwner !== undefined && foreignOwner !== "" && !isUuid(rawKey) && assignment?.foreignFieldType !== undefined) {
1419
- fieldExpr = `catalog.${foreignOwner}.fields${safeMember(rawKey)}`;
1436
+ const ownerKey = workspaceAspectRefName(state, foreignKind, foreignOwner, assignment.foreignOwnerNamespace)
1437
+ ?? namespaceCatalogKey(assignment.foreignOwnerNamespace)
1438
+ ?? foreignOwner;
1439
+ fieldExpr = `catalog.${ownerKey}.fields${safeMember(rawKey)}`;
1420
1440
  }
1421
1441
  else if (!isUuid(rawKey)) {
1422
1442
  const platformFieldId = assignment?.platformFieldId;
@@ -1444,6 +1464,15 @@ function printFieldAssignments(values, target, state, indent, refCtx) {
1444
1464
  });
1445
1465
  return `[\n${lines.join("\n")}\n${pad}]`;
1446
1466
  }
1467
+ /**
1468
+ * The type a foreign field stub prints with when ei's data source can't
1469
+ * confirm it. Only a Multi-Select takes an array value, so an array (a
1470
+ * `jsonencode([...])` value, including the `[]` clear) prints as one;
1471
+ * anything else keeps the TEXT guess (#1707).
1472
+ */
1473
+ function unconfirmedFieldType(value) {
1474
+ return Array.isArray(value) ? "MULTI_PICKLIST" : "TEXT";
1475
+ }
1447
1476
  /**
1448
1477
  * The task's primary target, used to resolve `values:` field keys to
1449
1478
  * `<target>.fields.<key>` tokens (or inline field stubs for tasks).
@@ -1466,10 +1495,13 @@ function taskPrimaryTarget(args, state) {
1466
1495
  }
1467
1496
  if (v.entityType === "element") {
1468
1497
  const foreignRefName = workspaceAspectRefName(state, "element", v.name, v.namespace);
1469
- return { kind: "element", refName: foreignRefName ?? v.appHandle, name: v.name, inCatalog: v.name === undefined || foreignRefName !== undefined };
1498
+ const refName = foreignRefName ?? namespaceCatalogKey(v.namespace) ?? v.appHandle;
1499
+ return { kind: "element", refName, name: v.name, inCatalog: v.name === undefined || foreignRefName !== undefined };
1470
1500
  }
1471
1501
  const foreignRefName = workspaceAspectRefName(state, "app", v.name, v.namespace);
1472
- const refName = foreignRefName ?? catalogOwnerHandle(state, v.appHandle);
1502
+ const refName = foreignRefName
1503
+ ?? (v.entityType === "app" ? namespaceCatalogKey(v.namespace) : undefined)
1504
+ ?? catalogOwnerHandle(state, v.appHandle);
1473
1505
  return { kind: "app", refName, name: v.name, inCatalog: v.entityType === undefined || v.name === undefined || foreignRefName !== undefined };
1474
1506
  }
1475
1507
  const aspectId = typeof v === "string"
@@ -1504,6 +1536,48 @@ function workspaceAspectRefName(state, kind, name, namespace) {
1504
1536
  return (namespace !== undefined ? namespaces?.get(namespace) : undefined)
1505
1537
  ?? (name !== undefined ? names?.get(name) : undefined);
1506
1538
  }
1539
+ /**
1540
+ * A foreign field's owner as a workspace catalog key.
1541
+ *
1542
+ * A known kind searches only that kind. An unknown kind (`ownerKindUnknown`)
1543
+ * is a raw field id the registry named by catalog key and did not classify.
1544
+ * That key is a namespace-map or name-map value, not a display name. Joining
1545
+ * it there first keeps an app whose display name equals the element ref from
1546
+ * being chosen ahead of a renamed element's namespace-map entry.
1547
+ */
1548
+ function workspaceFieldOwnerRefName(state, foreign, appHandle) {
1549
+ const knownKind = foreign.entityType === "element" ? "element" : "app";
1550
+ if (!foreign.ownerKindUnknown) {
1551
+ return workspaceAspectRefName(state, knownKind, foreign.name, foreign.namespace)
1552
+ ?? (isWorkspaceAspectRefName(state, knownKind, appHandle) ? appHandle : undefined);
1553
+ }
1554
+ const elementOwnsKey = isWorkspaceAspectRefName(state, "element", appHandle);
1555
+ const appOwnsKey = isWorkspaceAspectRefName(state, "app", appHandle);
1556
+ if (elementOwnsKey !== appOwnsKey)
1557
+ return appHandle;
1558
+ if (foreign.namespace !== undefined) {
1559
+ const elementRef = state.foreignElementRefNamespaces?.get(foreign.namespace);
1560
+ const appRef = state.foreignAppRefNamespaces?.get(foreign.namespace);
1561
+ if (elementRef !== undefined && appRef === undefined)
1562
+ return elementRef;
1563
+ if (appRef !== undefined && elementRef === undefined)
1564
+ return appRef;
1565
+ }
1566
+ for (const kind of ["app", "element"]) {
1567
+ const found = workspaceAspectRefName(state, kind, foreign.name, foreign.namespace)
1568
+ ?? (isWorkspaceAspectRefName(state, kind, appHandle) ? appHandle : undefined);
1569
+ if (found !== undefined)
1570
+ return found;
1571
+ }
1572
+ return undefined;
1573
+ }
1574
+ /**
1575
+ * An app's or element's catalog key is its sanitized namespace (its stream
1576
+ * label), so a foreign target that is not on disk yet still has a stable key.
1577
+ */
1578
+ function namespaceCatalogKey(namespace) {
1579
+ return namespace === undefined || namespace === "" ? undefined : tfLabelToTsLabel(sanitizeName(namespace));
1580
+ }
1507
1581
  /** The pulled field registry names a field's owner by its catalog key, not its platform name. */
1508
1582
  function isWorkspaceAspectRefName(state, kind, refName) {
1509
1583
  const namespaces = kind === "app" ? state.foreignAppRefNamespaces : state.foreignElementRefNamespaces;
@@ -1705,8 +1779,7 @@ function printRef(ref, state, refCtx) {
1705
1779
  // typed token; otherwise a literal stub (field type is unconfirmed —
1706
1780
  // ei's `elementum_field` data source doesn't expose it).
1707
1781
  const foreignRefName = ref.foreign.entityType === "element" || ref.foreign.entityType === "app"
1708
- ? workspaceAspectRefName(state, ref.foreign.entityType, ref.foreign.name, ref.foreign.namespace) ??
1709
- (isWorkspaceAspectRefName(state, ref.foreign.entityType, ref.appHandle) ? ref.appHandle : undefined)
1782
+ ? workspaceFieldOwnerRefName(state, ref.foreign, ref.appHandle)
1710
1783
  : ref.foreign.entityType === "task"
1711
1784
  ? state.foreignTaskRefNames?.get(ref.foreign.name)
1712
1785
  : undefined;
@@ -1,4 +1,5 @@
1
1
  import { EntityTfError } from "../../engine/entity.js";
2
+ import { type FromTfContext } from "../../engine/pull/context.js";
2
3
  import { type ChildResourceScope, type TfBlock, type TfDocument, type TfValue } from "../../engine/tf/index.js";
3
4
  import type { AutomationAst } from "./deserializer/ast.js";
4
5
  export interface AutomationFromTfResult {
@@ -13,6 +14,14 @@ export interface AutomationFromTfResult {
13
14
  }[];
14
15
  /** Non-fatal issues found while extracting (edk#785: a task anchored to the trigger because its real parent is unsupported). */
15
16
  readonly diagnostics?: readonly string[];
17
+ /**
18
+ * The export embeds a stringified ValueReference envelope whose task,
19
+ * trigger, or variable is not in this automation, so source cannot
20
+ * reproduce it (edk#1646 / #1798). Envelopes that decode to a ctx
21
+ * reference don't set this: the adoption gate checks those like any
22
+ * other value.
23
+ */
24
+ readonly stringifiedValueReferences?: boolean;
16
25
  }
17
26
  interface DecodeContext {
18
27
  readonly appRefName: string;
@@ -68,6 +77,10 @@ interface DecodeContext {
68
77
  readonly procedureKeysByDiscriminator?: ReadonlyMap<string, string>;
69
78
  /** Group name → org.ts's `org.groups` key, for static recipients (edk#1412). See `FromTfContext.groupKeysByName`. */
70
79
  readonly groupKeysByName?: ReadonlyMap<string, string>;
80
+ /** Set when this automation's export contains a stringified ValueReference envelope that does not resolve. */
81
+ readonly stringifiedValueReferences?: {
82
+ unresolved: boolean;
83
+ };
71
84
  }
72
85
  /**
73
86
  * The same outputs as seen from a CALCULATION formula, which addresses a
@@ -97,8 +110,8 @@ export declare function inferredPublishOutputType(value: TfValue, ctx: DecodeCon
97
110
  * conditions that make real extraction fail (zero triggers, an
98
111
  * unrecognized task kind) so it over-collects rather than under-collects.
99
112
  * More than one trigger throws {@link UnsupportedMultiTriggerError}. The
100
- * stream extractor records that as a fatal validation, excludes these
101
- * addresses, and continues so every multi-trigger automation is reported.
113
+ * stream extractor soft-skips those automations (diagnostic + skipped +
114
+ * releaseIfManaged), so the rest of the app can still adopt (#1785).
102
115
  * A false positive
103
116
  * here just leaves one more resource unmanaged; a false negative would
104
117
  * silently destroy a live automation on apply.
@@ -107,15 +120,23 @@ export declare function automationOwnedAddresses(doc: TfDocument, automationLabe
107
120
  /**
108
121
  * EDK does not author multi-trigger automations; apps should keep one
109
122
  * trigger and call the shared logic with a run-automation action. Stream
110
- * extraction records every one of these and continues. Direct
111
- * `automationFromTf` still throws. Callers that turn other extract failures
112
- * into soft skips must not treat this as one of those skips.
123
+ * extraction soft-skips every one of these (warn + skip + releaseIfManaged)
124
+ * so the rest of the app can still adopt (#1785). Direct `automationFromTf`
125
+ * still throws so callers that need a hard signal can catch it.
113
126
  */
114
127
  export declare class UnsupportedMultiTriggerError extends EntityTfError {
115
128
  readonly automationName: string;
116
129
  readonly triggerCount: number;
117
130
  constructor(automationName: string, triggerCount: number);
118
131
  }
132
+ /**
133
+ * A bare service_account_id belongs to an app this export does not contain.
134
+ * Pull cannot print a serviceAccountRef until that app is in the workspace,
135
+ * and printing nothing would clear the live account.
136
+ */
137
+ export declare class UnresolvedForeignServiceAccountError extends EntityTfError {
138
+ constructor(automationLabel: string);
139
+ }
119
140
  /**
120
141
  * #1320: a task reads the current item of a loop that doesn't enclose it.
121
142
  * Pull skips the automation like any other exclusion, and additionally
@@ -154,6 +175,7 @@ export interface AutomationFromTfContext {
154
175
  readonly foreignTaskRefNames?: ReadonlyMap<string, string>;
155
176
  readonly procedureKeysByDiscriminator?: ReadonlyMap<string, string>;
156
177
  readonly groupKeysByName?: ReadonlyMap<string, string>;
178
+ readonly serviceAccountsById?: FromTfContext["serviceAccountsById"];
157
179
  }
158
180
  export interface AutomationGraphFromTfResult {
159
181
  readonly automation?: AutomationAst;
@@ -177,5 +199,5 @@ export declare function automationFromTf(doc: TfDocument, automationLabel: strin
177
199
  }>, foreignTableRefsById?: ReadonlyMap<string, {
178
200
  readonly tableRefName: string;
179
201
  readonly name: string;
180
- }>, picklistOptionLabelById?: ReadonlyMap<string, string>, fieldNamesByOwnerRefName?: ReadonlyMap<string, ReadonlyMap<string, string>>, foreignAppRefNames?: ReadonlyMap<string, string>, foreignElementRefNames?: ReadonlyMap<string, string>, procedureKeysByDiscriminator?: ReadonlyMap<string, string>, foreignTaskRefNames?: ReadonlyMap<string, string>, groupKeysByName?: ReadonlyMap<string, string>): AutomationFromTfResult;
202
+ }>, picklistOptionLabelById?: ReadonlyMap<string, string>, fieldNamesByOwnerRefName?: ReadonlyMap<string, ReadonlyMap<string, string>>, foreignAppRefNames?: ReadonlyMap<string, string>, foreignElementRefNames?: ReadonlyMap<string, string>, procedureKeysByDiscriminator?: ReadonlyMap<string, string>, foreignTaskRefNames?: ReadonlyMap<string, string>, groupKeysByName?: ReadonlyMap<string, string>, serviceAccountsById?: FromTfContext["serviceAccountsById"]): AutomationFromTfResult;
181
203
  export {};