@elementumai/edk 0.9.19 → 0.9.20

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 (176) hide show
  1. package/README.md +146 -6
  2. package/dist-sdk/src/catalog/factories.d.ts +24 -1
  3. package/dist-sdk/src/catalog/factories.js +30 -0
  4. package/dist-sdk/src/catalog/from-authoring.d.ts +13 -8
  5. package/dist-sdk/src/catalog/from-authoring.js +34 -9
  6. package/dist-sdk/src/catalog/index.d.ts +2 -2
  7. package/dist-sdk/src/catalog/index.js +2 -2
  8. package/dist-sdk/src/catalog/render.js +6 -6
  9. package/dist-sdk/src/catalog/token.js +7 -0
  10. package/dist-sdk/src/catalog/types.d.ts +34 -1
  11. package/dist-sdk/src/catalog/types.js +11 -0
  12. package/dist-sdk/src/core/triggers/on-demand.d.ts +39 -3
  13. package/dist-sdk/src/core/triggers/on-demand.js +10 -2
  14. package/dist-sdk/src/engine/build/context.d.ts +1 -1
  15. package/dist-sdk/src/engine/ei/run.d.ts +149 -0
  16. package/dist-sdk/src/engine/ei/run.js +1132 -0
  17. package/dist-sdk/src/engine/logging.d.ts +17 -0
  18. package/dist-sdk/src/engine/logging.js +18 -0
  19. package/dist-sdk/src/engine/pull/ref-only.d.ts +5 -0
  20. package/dist-sdk/src/engine/pull/ref-only.js +10 -7
  21. package/dist-sdk/src/engine/pull/result-output.d.ts +6 -0
  22. package/dist-sdk/src/engine/pull/result-output.js +87 -3
  23. package/dist-sdk/src/engine/tf/expr.js +1 -1
  24. package/dist-sdk/src/engine/tf/index.d.ts +2 -2
  25. package/dist-sdk/src/engine/tf/index.js +1 -1
  26. package/dist-sdk/src/engine/tf/labels.d.ts +6 -0
  27. package/dist-sdk/src/engine/tf/labels.js +9 -0
  28. package/dist-sdk/src/engine/tf/model.d.ts +22 -1
  29. package/dist-sdk/src/engine/tf/parse.js +92 -4
  30. package/dist-sdk/src/engine/tf/render.d.ts +4 -2
  31. package/dist-sdk/src/engine/tf/render.js +41 -7
  32. package/dist-sdk/src/engine/validation.d.ts +39 -0
  33. package/dist-sdk/src/engine/validation.js +85 -0
  34. package/dist-sdk/src/entities/access-policy/to-tf.js +5 -2
  35. package/dist-sdk/src/entities/agent/build.d.ts +4 -16
  36. package/dist-sdk/src/entities/agent/build.js +40 -5
  37. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +4 -2
  38. package/dist-sdk/src/entities/agent/to-tf.js +6 -3
  39. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +2 -0
  40. package/dist-sdk/src/entities/agent-tool/from-tf.js +7 -1
  41. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
  42. package/dist-sdk/src/entities/agent-tool/to-tf.js +27 -5
  43. package/dist-sdk/src/entities/app/build.d.ts +89 -20
  44. package/dist-sdk/src/entities/app/build.js +51 -6
  45. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +16 -0
  46. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -0
  47. package/dist-sdk/src/entities/app/from-tf.js +7 -2
  48. package/dist-sdk/src/entities/app/index.d.ts +6 -6
  49. package/dist-sdk/src/entities/app/index.js +1 -0
  50. package/dist-sdk/src/entities/app/module.js +5 -2
  51. package/dist-sdk/src/entities/app/to-tf.js +19 -11
  52. package/dist-sdk/src/entities/automation/build.d.ts +47 -5
  53. package/dist-sdk/src/entities/automation/build.js +137 -20
  54. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +24 -1
  55. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +314 -39
  56. package/dist-sdk/src/entities/automation/from-tf.d.ts +28 -6
  57. package/dist-sdk/src/entities/automation/from-tf.js +428 -48
  58. package/dist-sdk/src/entities/automation/generated/task-output-contracts.d.ts +33 -0
  59. package/dist-sdk/src/entities/automation/generated/task-output-contracts.js +183 -0
  60. package/dist-sdk/src/entities/automation/index.d.ts +2 -2
  61. package/dist-sdk/src/entities/automation/index.js +1 -1
  62. package/dist-sdk/src/entities/automation/module.js +37 -8
  63. package/dist-sdk/src/entities/automation/output-field-types.d.ts +7 -0
  64. package/dist-sdk/src/entities/automation/output-field-types.js +36 -0
  65. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +9 -0
  66. package/dist-sdk/src/entities/automation/output-key-wire-name.js +13 -0
  67. package/dist-sdk/src/entities/automation/script-code.d.ts +17 -0
  68. package/dist-sdk/src/entities/automation/script-code.js +91 -5
  69. package/dist-sdk/src/entities/automation/system-ref-name.js +4 -0
  70. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +2 -0
  71. package/dist-sdk/src/entities/automation/task-output-labels.js +9 -0
  72. package/dist-sdk/src/entities/automation/tasks.d.ts +24 -2
  73. package/dist-sdk/src/entities/automation/tasks.js +38 -9
  74. package/dist-sdk/src/entities/automation/to-tf.d.ts +4 -0
  75. package/dist-sdk/src/entities/automation/to-tf.js +489 -83
  76. package/dist-sdk/src/entities/automation/triggers.d.ts +4 -2
  77. package/dist-sdk/src/entities/automation/triggers.js +4 -0
  78. package/dist-sdk/src/entities/chart/to-tf.js +10 -3
  79. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +24 -31
  80. package/dist-sdk/src/entities/element/build.d.ts +25 -13
  81. package/dist-sdk/src/entities/element/build.js +4 -1
  82. package/dist-sdk/src/entities/element/from-tf.d.ts +11 -0
  83. package/dist-sdk/src/entities/element/from-tf.js +58 -1
  84. package/dist-sdk/src/entities/element/index.d.ts +5 -3
  85. package/dist-sdk/src/entities/element/index.js +1 -0
  86. package/dist-sdk/src/entities/element/module.js +9 -3
  87. package/dist-sdk/src/entities/element/to-tf.js +8 -2
  88. package/dist-sdk/src/entities/field/build.d.ts +14 -1
  89. package/dist-sdk/src/entities/field/build.js +3 -0
  90. package/dist-sdk/src/entities/field/from-tf.d.ts +1 -0
  91. package/dist-sdk/src/entities/field/from-tf.js +39 -1
  92. package/dist-sdk/src/entities/field/media-types.d.ts +6 -0
  93. package/dist-sdk/src/entities/field/media-types.js +30 -0
  94. package/dist-sdk/src/entities/field/module.js +1 -0
  95. package/dist-sdk/src/entities/field/to-tf.d.ts +23 -2
  96. package/dist-sdk/src/entities/field/to-tf.js +130 -14
  97. package/dist-sdk/src/entities/file-reader/from-tf.js +14 -5
  98. package/dist-sdk/src/entities/file-reader/module.js +1 -0
  99. package/dist-sdk/src/entities/file-reader/types.d.ts +2 -0
  100. package/dist-sdk/src/entities/file-reader/types.js +1 -1
  101. package/dist-sdk/src/entities/portal/build.d.ts +26 -0
  102. package/dist-sdk/src/entities/portal/build.js +37 -0
  103. package/dist-sdk/src/entities/portal/from-tf.d.ts +27 -0
  104. package/dist-sdk/src/entities/portal/from-tf.js +75 -0
  105. package/dist-sdk/src/entities/portal/index.d.ts +1 -0
  106. package/dist-sdk/src/entities/portal/index.js +1 -0
  107. package/dist-sdk/src/entities/portal/module.d.ts +3 -0
  108. package/dist-sdk/src/entities/portal/module.js +28 -0
  109. package/dist-sdk/src/entities/portal/to-tf.d.ts +12 -0
  110. package/dist-sdk/src/entities/portal/to-tf.js +73 -0
  111. package/dist-sdk/src/entities/portal/types.d.ts +1 -0
  112. package/dist-sdk/src/entities/portal/types.js +1 -0
  113. package/dist-sdk/src/entities/relationship/module.js +2 -0
  114. package/dist-sdk/src/entities/relationship/pair-check.d.ts +7 -0
  115. package/dist-sdk/src/entities/relationship/pair-check.js +68 -0
  116. package/dist-sdk/src/entities/relationship/to-tf.d.ts +2 -0
  117. package/dist-sdk/src/entities/relationship/to-tf.js +12 -3
  118. package/dist-sdk/src/entities/search-table/module.js +1 -0
  119. package/dist-sdk/src/entities/search-table/to-tf.d.ts +1 -0
  120. package/dist-sdk/src/entities/search-table/to-tf.js +1 -1
  121. package/dist-sdk/src/entities/service-account/build.d.ts +15 -2
  122. package/dist-sdk/src/entities/service-account/from-tf.d.ts +2 -4
  123. package/dist-sdk/src/entities/service-account/from-tf.js +17 -5
  124. package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +56 -0
  125. package/dist-sdk/src/entities/service-account/role-fidelity.js +243 -0
  126. package/dist-sdk/src/entities/service-account/to-tf.d.ts +14 -0
  127. package/dist-sdk/src/entities/service-account/to-tf.js +17 -0
  128. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +1 -1
  129. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +5 -2
  130. package/dist-sdk/src/entities/shared/filters/ast.d.ts +8 -0
  131. package/dist-sdk/src/entities/shared/filters/index.d.ts +2 -0
  132. package/dist-sdk/src/entities/shared/filters/index.js +14 -4
  133. package/dist-sdk/src/entities/shared/filters/print.js +17 -1
  134. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +2 -0
  135. package/dist-sdk/src/entities/shared/filters/tf-codec.js +5 -1
  136. package/dist-sdk/src/entities/shared/filters/types.d.ts +9 -1
  137. package/dist-sdk/src/entities/shared/types/field-types.d.ts +10 -5
  138. package/dist-sdk/src/entities/shared/types/field-types.js +4 -0
  139. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +2 -1
  140. package/dist-sdk/src/entities/skill/from-tf.js +66 -13
  141. package/dist-sdk/src/entities/skill/input-coverage.d.ts +7 -0
  142. package/dist-sdk/src/entities/skill/input-coverage.js +11 -0
  143. package/dist-sdk/src/entities/skill/to-tf.js +14 -4
  144. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
  145. package/dist-sdk/src/entities/skill-tool/from-tf.js +8 -2
  146. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +2 -2
  147. package/dist-sdk/src/entities/skill-tool/to-tf.js +27 -5
  148. package/dist-sdk/src/entities/table/catalog.d.ts +14 -0
  149. package/dist-sdk/src/entities/table/catalog.js +66 -0
  150. package/dist-sdk/src/entities/table/module.js +2 -1
  151. package/dist-sdk/src/entities/table/to-tf.js +2 -2
  152. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +49 -9
  153. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +71 -18
  154. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +19 -4
  155. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +82 -10
  156. package/dist-sdk/src/entities/view/agent-view-layout.d.ts +53 -23
  157. package/dist-sdk/src/entities/view/agent-view-layout.js +1 -1
  158. package/dist-sdk/src/entities/view/from-tf.d.ts +3 -2
  159. package/dist-sdk/src/entities/view/from-tf.js +124 -12
  160. package/dist-sdk/src/entities/view/module.js +30 -3
  161. package/dist-sdk/src/entities/view/to-tf.d.ts +14 -1
  162. package/dist-sdk/src/entities/view/to-tf.js +67 -10
  163. package/dist-sdk/src/entities/view/types.d.ts +4 -15
  164. package/dist-sdk/src/entities/view/types.js +15 -15
  165. package/dist-sdk/src/entities/widget/build.d.ts +16 -1
  166. package/dist-sdk/src/entities/widget/build.js +11 -1
  167. package/dist-sdk/src/entities/widget/to-tf.js +34 -8
  168. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +16 -5
  169. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  170. package/dist-sdk/src/graph/index.d.ts +11 -0
  171. package/dist-sdk/src/graph/index.js +21 -0
  172. package/dist-sdk/src/graph/modules.js +2 -0
  173. package/dist-sdk/src/graph/types.d.ts +55 -2
  174. package/dist-sdk/src/internal/sdk-package.d.ts +1 -1
  175. package/dist-sdk/src/internal/sdk-package.js +1 -0
  176. package/package.json +10 -1
@@ -31,15 +31,15 @@ import { isOnDemandRecordType } from "../shared/types/field-types.js";
31
31
  import { buildContext, createForEachItemProxy } from "../shared/context.js";
32
32
  import { outputFieldTypesFromScriptSchema } from "./output-field-types.js";
33
33
  import { isRef } from "../shared/ref.js";
34
- import { API_TASK_REF_WIRE_NAMES, OUTPUT_KEY_WIRE_NAME } from "./output-key-wire-name.js";
35
- import { extractScriptBody, inferOutputSchema, isScriptFile, readScriptFile, tryExtractFromCurrentSource } from "./script-code.js";
34
+ import { API_TASK_REF_WIRE_NAMES, OUTPUT_KEY_CANONICAL, OUTPUT_KEY_WIRE_NAME } from "./output-key-wire-name.js";
35
+ import { extractScriptBody, inferOutputSchema, isScriptFile, readScriptFile, toPlatformScriptBody, tryExtractFromCurrentSource } from "./script-code.js";
36
36
  import { serializeNode } from "./serialize.js";
37
37
  // Runtime factory imports stay below the public action-native surface. Their
38
38
  // ActionDef return values are an internal serialization detail; authored
39
39
  // automations call the direct fluent methods declared on ActionBuilder.
40
40
  import * as operatorFactories from "./operators.js";
41
41
  import * as actionFactories from "./tasks.js";
42
- import { USER_SEARCH_REF_WIRE_NAMES, WHOLE_RECORD_REF_WIRE_NAMES } from "./task-output-labels.js";
42
+ import { AI_SEARCH_TABLE_OUTPUT_NAMES, USER_SEARCH_REF_WIRE_NAMES, WHOLE_RECORD_REF_WIRE_NAMES } from "./task-output-labels.js";
43
43
  import { isWorkflowOutputDeclaration, workflowOutputFieldType, } from "./workflow-output.js";
44
44
  /** Placeholder `forEachTaskRefKey` the forEach item proxy emits; replaced with the real refKey. */
45
45
  export const FOR_EACH_PLACEHOLDER = "__forEach__";
@@ -217,6 +217,18 @@ function findRelatedRecordsTotalCountError(taskRefKey) {
217
217
  `for a match count, or ctx.actions.${taskRefKey ?? "<findRelatedRecordsTask>"}.record / .records ` +
218
218
  `for related rows. Do not invent a count ref.`);
219
219
  }
220
+ /**
221
+ * User and user-group searches have a closed output set; any other name
222
+ * (e.g. `totalCount`, which user search does not expose) would compile to a
223
+ * `refs["…"]` key the platform never returns.
224
+ */
225
+ function assertKnownSearchOutput(taskKey, wireNames, name, taskRefKey) {
226
+ const known = new Set([...Object.keys(wireNames), ...Object.values(wireNames)]);
227
+ if (known.has(name))
228
+ return;
229
+ const outputs = Object.keys(wireNames).join(", ");
230
+ throw new EntityTfError(`${taskKey}${taskRefKey === undefined ? "" : ` task "${taskRefKey}"`} has no output "${name}"; its outputs are ${outputs}.`);
231
+ }
220
232
  /**
221
233
  * Forward output-name rewrites, the inverse of the deserializer's read-side
222
234
  * normalization (`applyOutputNameInverseRewrites` in
@@ -256,16 +268,18 @@ function rewriteForwardTaskRefName(taskKey, name, taskRefKey) {
256
268
  return "Records Size";
257
269
  }
258
270
  if (taskKey === "userGroupSearch") {
271
+ assertKnownSearchOutput("userGroupSearch", USER_GROUP_SEARCH_REF_WIRE_NAMES, name, taskRefKey);
259
272
  return USER_GROUP_SEARCH_REF_WIRE_NAMES[name] ?? name;
260
273
  }
261
274
  if (taskKey === "userSearch") {
275
+ assertKnownSearchOutput("userSearch", USER_SEARCH_REF_WIRE_NAMES, name, taskRefKey);
262
276
  return USER_SEARCH_REF_WIRE_NAMES[name] ?? name;
263
277
  }
264
278
  if (taskKey === "executeScript" && name === "textResult") {
265
279
  return "Text Result";
266
280
  }
267
- if (taskKey === "aiSearchTable" && name === "records") {
268
- return "All Records";
281
+ if (taskKey === "aiSearchTable" && AI_SEARCH_TABLE_OUTPUT_NAMES[name] !== undefined) {
282
+ return AI_SEARCH_TABLE_OUTPUT_NAMES[name][0];
269
283
  }
270
284
  if (taskKey === "aiAgent") {
271
285
  const segs = name.split(".");
@@ -289,6 +303,88 @@ function rewriteForwardTaskRefName(taskKey, name, taskRefKey) {
289
303
  }
290
304
  return name;
291
305
  }
306
+ /**
307
+ * CANONICAL reference-name rewrite — used ONLY for workflow-publish OUTPUTS
308
+ * (see DESIGN-canonical-reference-model.md). A workflow output's
309
+ * `taskReference.name` must be the platform's CANONICAL output name
310
+ * (`service_tasks`), NOT the refs-map display label — the platform validates
311
+ * the published output against the canonical name (edk#835). Task INPUTS,
312
+ * FILTERS and CALC mustaches are UNCHANGED (they keep `rewriteForwardTaskRefName`
313
+ * / the display refs-map path — #1271 owns those positions). Maps EDK's friendly
314
+ * accessor → canonical; identity for most kinds. Validated against
315
+ * TASK_OUTPUT_CONTRACTS by canonical-reference-model.test.ts.
316
+ */
317
+ export function rewriteCanonicalOutputRefName(taskKey, name, taskRefKey) {
318
+ if (taskKey === "findRelatedRecords" && FIND_RELATED_RECORDS_COUNT_REF_NAMES.has(name.split(".")[0])) {
319
+ throw findRelatedRecordsTotalCountError(taskRefKey);
320
+ }
321
+ if (taskKey === "api" && name.startsWith("file.")) {
322
+ // apiRequest's file SUB-refs (.file.content / .contentType / .name) have no
323
+ // canonical service_tasks output name of their own — they resolve by the
324
+ // provider's refs-map DISPLAY label ("Content" / "Content Type" / "Name", via
325
+ // API_TASK_REF_WIRE_NAMES). Keep the base display rewrite. Top-level api
326
+ // outputs ARE contract names and ride the envelope as identity.
327
+ return rewriteForwardTaskRefName(taskKey, name, taskRefKey);
328
+ }
329
+ if ((taskKey === "recordSearch" || taskKey === "tableRecordsSearch") && name === "totalCount") {
330
+ // Both expose a `totalCount` accessor, but the executors' canonical count
331
+ // output is `count` (aspect_records_search.count / table_records_search.count).
332
+ return "count";
333
+ }
334
+ if (taskKey === "aiSearchTable" && AI_SEARCH_TABLE_OUTPUT_NAMES[name] !== undefined) {
335
+ return AI_SEARCH_TABLE_OUTPUT_NAMES[name][1];
336
+ }
337
+ if (taskKey === "userSearch" || taskKey === "userGroupSearch") {
338
+ if (taskKey === "userSearch" && (name === "user.managerName" || name === "user.managerEmail")) {
339
+ // Fail fast at build (like findRelatedRecords.totalCount) rather than let
340
+ // the platform reject it at publish: a user's manager fields are NOT
341
+ // referenceable workflow outputs — both the "Manager Name"/"Manager Email"
342
+ // display label and the "user.managerName"/"user.managerEmail" accessor are
343
+ // rejected at publish, and their real canonical name was never captured live.
344
+ const label = name === "user.managerName" ? "Manager Name" : "Manager Email";
345
+ throw new EntityTfError(`userSearch does not expose a referenceable "${name}" workflow output — the platform ` +
346
+ `rejects both the "${label}" label and "${name}" at publish. Reference ` +
347
+ `user.id / user.name / user.email instead, or drop this output.`);
348
+ }
349
+ // A userSearch/userGroupSearch workflow OUTPUT's canonical name IS the
350
+ // authoring accessor (count/group/group.id/group.name/groups and
351
+ // user/users/user.id/user.name/user.email). #1271's TASK_OUTPUT_REFERENCE_NAMES
352
+ // captured the userGroupSearch names live; the display refs-map labels the
353
+ // forward rewrite would otherwise emit ("Groups Size", "ID", …) are rejected
354
+ // at publish (edk#835). The display path stays for inputs/calc/filters,
355
+ // which #1271 owns. See docs/design/canonical-reference-model.md.
356
+ return name;
357
+ }
358
+ if (taskKey === "aiAgent") {
359
+ // aiAgent is NOT a #835 display-label victim: base already emits the correct
360
+ // platform reference via rewriteForwardTaskRefName + to-tf's
361
+ // aiAgentPlatformRefName. Keep that intact by delegating to the forward rewrite.
362
+ return rewriteForwardTaskRefName(taskKey, name, taskRefKey);
363
+ }
364
+ if (taskKey === "documentModel") {
365
+ // file_reader's published output wire name is "text" (confirmed live wire
366
+ // data), NOT a #835 display-label victim. Keep base behavior.
367
+ return rewriteForwardTaskRefName(taskKey, name, taskRefKey);
368
+ }
369
+ if (taskKey === "recordSearch" && name === "record.recordId") {
370
+ // recordSearch exposes a real canonical `recordId` output (service_tasks
371
+ // aspect_records_search.recordId, ASPECT_RECORD_ID) — validated live 0-diff.
372
+ return "recordId";
373
+ }
374
+ if (taskKey !== undefined && RECORD_BEARING_TASK_KEYS.has(taskKey) && name === "record.recordId") {
375
+ // createRecord/findRelatedRecords do NOT expose a `recordId` output
376
+ // (find_related_records has none in service_tasks). Their record-id reference
377
+ // is "Record" (ASPECT_RECORD_ID) — the base behavior. Keep via forward rewrite.
378
+ return rewriteForwardTaskRefName(taskKey, name, taskRefKey);
379
+ }
380
+ const canonicalOutputKey = taskKey ? OUTPUT_KEY_CANONICAL[taskKey] : undefined;
381
+ if (canonicalOutputKey) {
382
+ const segs = name.split(".");
383
+ if (segs[0] === "output")
384
+ return [canonicalOutputKey, ...segs.slice(1)].join(".");
385
+ }
386
+ return name;
387
+ }
292
388
  /**
293
389
  * Walk a serialized wire node and rewrite, in place, the `name` of every task
294
390
  * output reference whose target task needs an output-name rewrite. Two wire
@@ -299,10 +395,15 @@ function rewriteForwardTaskRefName(taskKey, name, taskRefKey) {
299
395
  * the `ref*` filter helpers) — both need the same rewrite. Runs at finalize,
300
396
  * when the full refKey→kind map is known.
301
397
  */
302
- function rewriteTaskOutputRefs(node, taskKindByRefKey) {
398
+ function rewriteTaskOutputRefs(node, taskKindByRefKey,
399
+ // Workflow OUTPUTS pass canonical=true: a `taskReference.name` becomes the
400
+ // platform's CANONICAL service_tasks output name (edk#835). Task inputs and
401
+ // filters (canonical=false, the default) keep the display rewrite — #1271 owns
402
+ // those positions.
403
+ canonical = false) {
303
404
  if (Array.isArray(node)) {
304
405
  for (const item of node)
305
- rewriteTaskOutputRefs(item, taskKindByRefKey);
406
+ rewriteTaskOutputRefs(item, taskKindByRefKey, canonical);
306
407
  return;
307
408
  }
308
409
  if (node === null || typeof node !== "object")
@@ -318,13 +419,21 @@ function rewriteTaskOutputRefs(node, taskKindByRefKey) {
318
419
  }
319
420
  const ref = rec.taskReference;
320
421
  if (ref && typeof ref.taskRefKey === "string" && typeof ref.name === "string") {
321
- ref.name = rewriteForwardTaskRefName(taskKindByRefKey.get(ref.taskRefKey), ref.name, ref.taskRefKey);
422
+ const rewrite = canonical ? rewriteCanonicalOutputRefName : rewriteForwardTaskRefName;
423
+ ref.name = rewrite(taskKindByRefKey.get(ref.taskRefKey), ref.name, ref.taskRefKey);
322
424
  }
323
425
  if (rec.type === "TASK" && typeof rec.taskRefKey === "string" && typeof rec.name === "string") {
426
+ // Filter `{type:"TASK"}` shapes never appear in a workflow OUTPUT subtree;
427
+ // keep the display rewrite (#1271's filter path) regardless of `canonical`.
324
428
  rec.name = rewriteForwardTaskRefName(taskKindByRefKey.get(rec.taskRefKey), rec.name, rec.taskRefKey);
325
429
  }
326
- for (const v of Object.values(rec))
327
- rewriteTaskOutputRefs(v, taskKindByRefKey);
430
+ for (const [key, v] of Object.entries(rec)) {
431
+ // A calc-engine mustache subtree (`calculationReference` → templateReference)
432
+ // keeps the display/forward rewrite even under an output, so its decode
433
+ // (decodeCalculationTaskMustache) stays idempotent.
434
+ const childCanonical = key === "calculationReference" ? false : canonical;
435
+ rewriteTaskOutputRefs(v, taskKindByRefKey, childCanonical);
436
+ }
328
437
  }
329
438
  /**
330
439
  * Walk serialized tasks and assign UUIDs to any `variable.create` entries that
@@ -419,14 +528,14 @@ function serializeOutputValue(value) {
419
528
  }
420
529
  return isRef(value) ? serializeNode(value) : { value };
421
530
  }
422
- function makeActionBuilder(state, mode = "root", item) {
423
- const appendAction = (name, def, displayName, hclParent) => makeActionBuilder({ ...state, tasks: [...state.tasks, { name, def, displayName, hclParent }] }, mode, item);
531
+ function makeActionBuilder(state, mode = "root", item, loops = {}) {
532
+ const appendAction = (name, def, displayName, hclParent) => makeActionBuilder({ ...state, tasks: [...state.tasks, { name, def, displayName, hclParent }] }, mode, item, loops);
424
533
  const context = () => {
425
534
  const base = buildContext(state.tasks.map((entry) => entry.name));
426
- return (item === undefined ? base : { ...base, item });
535
+ return (item === undefined ? base : { ...base, item, loops });
427
536
  };
428
537
  const resolveOptions = (value) => typeof value === "function" ? value(context()) : value;
429
- const materializeNested = (callback, childItem) => callback(makeActionBuilder({ trigger: state.trigger, tasks: [] }, "nested", childItem)).__children();
538
+ const materializeNested = (callback, childItem, childLoops = loops) => callback(makeActionBuilder({ trigger: state.trigger, tasks: [] }, "nested", childItem, childLoops)).__children();
430
539
  const leafFactories = {
431
540
  recordSearch: actionFactories.recordSearch,
432
541
  tableRecordsSearch: actionFactories.tableRecordsSearch,
@@ -479,8 +588,8 @@ function makeActionBuilder(state, mode = "root", item) {
479
588
  // A `scriptFile(...)` reference IS the exact text (no source scan, no
480
589
  // toString(), no closure hazard: it is never a JS closure).
481
590
  const body = isScriptFile(opts.code)
482
- ? readScriptFile(opts.code)
483
- : tryExtractFromCurrentSource(name) ?? extractScriptBody(opts.code);
591
+ ? toPlatformScriptBody(readScriptFile(opts.code), `executeScript "${name}" scriptFile("${opts.code.path}")`, { stripTypes: false })
592
+ : toPlatformScriptBody(tryExtractFromCurrentSource(name) ?? extractScriptBody(opts.code), `executeScript "${name}"`);
484
593
  const outputs = opts.outputs === undefined ? inferOutputSchema(body) : (opts.outputs ?? undefined);
485
594
  const def = actionFactories.executeScriptActionDefWithBody(body, {
486
595
  ...(opts.inputs !== undefined ? { inputs: opts.inputs(context()) } : {}),
@@ -500,8 +609,14 @@ function makeActionBuilder(state, mode = "root", item) {
500
609
  },
501
610
  forEach(name, opts, displayName, hclParent) {
502
611
  const authored = opts;
503
- const childItem = createForEachItemProxy(FOR_EACH_PLACEHOLDER);
504
- const children = materializeNested(authored.actions, childItem);
612
+ // Bind the body's item to this loop's real name, never the shared
613
+ // placeholder: replaceForEachPlaceholder rewrites every placeholder in
614
+ // a forEach task's subtree to that loop, including an OUTER loop's item
615
+ // captured in this task's own collection (an enclosing ctx.item) or
616
+ // read by name from inside (ctx.loops.<outer>.item) (#1320).
617
+ const childItem = createForEachItemProxy(name);
618
+ const childLoops = { ...loops, [name]: { item: childItem } };
619
+ const children = materializeNested(authored.actions, childItem, childLoops);
505
620
  const def = operatorFactories.forEach(context(), {
506
621
  collection: typeof authored.collection === "function" ? authored.collection(context()) : authored.collection,
507
622
  actions: () => children,
@@ -545,7 +660,7 @@ function makeActionBuilder(state, mode = "root", item) {
545
660
  name,
546
661
  value: serializeOutputValue(value),
547
662
  }));
548
- return makeActionBuilder({ ...state, outputs }, mode, item);
663
+ return makeActionBuilder({ ...state, outputs }, mode, item, loops);
549
664
  },
550
665
  __children() {
551
666
  return state.tasks.map((entry) => ({
@@ -569,8 +684,10 @@ function makeActionBuilder(state, mode = "root", item) {
569
684
  const tasks = state.tasks.map((t) => serializeTaskEntry(t.name, t.def, t.displayName, t.hclParent));
570
685
  const outputs = state.outputs?.map((o) => ({ ...o }));
571
686
  rewriteTaskOutputRefs(tasks, taskKindByRefKey);
687
+ // Workflow OUTPUTS emit the platform's CANONICAL output name (edk#835);
688
+ // task inputs/filters above stay on the display path (#1271 owns them).
572
689
  if (outputs)
573
- rewriteTaskOutputRefs(outputs, taskKindByRefKey);
690
+ rewriteTaskOutputRefs(outputs, taskKindByRefKey, /* canonical */ true);
574
691
  // Trigger reference names are NOT canonicalized: the authored name is
575
692
  // the name, everywhere in EDK. (Mobius canonicalizes reference names in
576
693
  // ITS storage — `ValueReference.ofTriggerReference` — but on the tf
@@ -38,6 +38,11 @@ export declare function preserveAuthoredAutomationRevision(freshSource: string,
38
38
  * Extract a string-literal (or `+`-concatenated literals) description from
39
39
  * authored automation source. Pull reprints often omit description entirely
40
40
  * because Go export cannot read it back from the platform today.
41
+ *
42
+ * Only the automation's own `description` counts: the top-level key of the
43
+ * `automation({ ... })` options object, in any key order. A notification
44
+ * step's or on-demand input's `description` inside the actions chain is not
45
+ * the automation's.
41
46
  */
42
47
  export declare function extractAuthoredAutomationDescription(source: string): string | undefined;
43
48
  /**
@@ -48,7 +53,17 @@ export declare function extractAuthoredAutomationDescription(source: string): st
48
53
  * drops the attribute. Without this merge, pull → reprint → build clears
49
54
  * description from config while state still has it, forcing an adopt update.
50
55
  * Prefer a freshly pulled description when present; only reinstate the
51
- * authored value when the fresh source omitted it.
56
+ * authored value when the fresh source omitted it. Both checks and the
57
+ * insertion point are scoped to the automation's own options object, so a
58
+ * step's `description` neither hides nor supplies the automation's.
59
+ *
60
+ * Fail safe: when the fresh source cannot be scanned to its end (for example
61
+ * a pulled script body the scanner cannot tokenize), the authored description
62
+ * is still restored once the scan has reached the top-level `actions` key.
63
+ * The pull printer emits every other option, description included, before
64
+ * `actions`, so at that point the fresh source provably has no description of
65
+ * its own and the insertion point was read exactly. A scan that stops before
66
+ * `actions` leaves the fresh source unchanged.
52
67
  */
53
68
  export declare function preserveAuthoredAutomationDescription(freshSource: string, existingSource: string): string;
54
69
  /** Pull merge: preserve authored revision + description across live reprint. */
@@ -60,6 +75,14 @@ export interface PrintedScriptFile {
60
75
  }
61
76
  /** Folder (inside the automations folder) that holds printed script files. */
62
77
  export declare const SCRIPT_FILES_DIR = "scripts";
78
+ /**
79
+ * Key of the placeholder printed for a forEach item reference to a sibling
80
+ * loop (no authored form, #1320). Build fails on it; re-pull archives a file
81
+ * that still carries it.
82
+ */
83
+ export declare const UNRESOLVED_FOR_EACH_ITEM_KEY = "__edkUnresolvedForEachItem";
84
+ /** True when automation source still carries the unbuildable sibling-loop placeholder. */
85
+ export declare function hasUnresolvedForEachItem(source: string): boolean;
63
86
  export interface PrintAutomationV2Options {
64
87
  readonly refName?: string;
65
88
  /**