@elementumai/edk 0.9.19 → 0.10.1

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 (240) hide show
  1. package/README.md +159 -7
  2. package/dist-sdk/src/catalog/factories.d.ts +33 -2
  3. package/dist-sdk/src/catalog/factories.js +40 -1
  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 +11 -0
  10. package/dist-sdk/src/catalog/types.d.ts +40 -1
  11. package/dist-sdk/src/catalog/types.js +12 -0
  12. package/dist-sdk/src/core/triggers/on-demand.d.ts +40 -4
  13. package/dist-sdk/src/core/triggers/on-demand.js +17 -2
  14. package/dist-sdk/src/core/types/app.d.ts +2 -2
  15. package/dist-sdk/src/engine/build/context.d.ts +1 -1
  16. package/dist-sdk/src/engine/coverage-gaps.d.ts +86 -0
  17. package/dist-sdk/src/engine/coverage-gaps.js +156 -0
  18. package/dist-sdk/src/engine/ei/run.d.ts +169 -0
  19. package/dist-sdk/src/engine/ei/run.js +1219 -0
  20. package/dist-sdk/src/engine/logging.d.ts +17 -0
  21. package/dist-sdk/src/engine/logging.js +18 -0
  22. package/dist-sdk/src/engine/pull/catalog-ref.d.ts +16 -0
  23. package/dist-sdk/src/engine/pull/catalog-ref.js +24 -0
  24. package/dist-sdk/src/engine/pull/context.d.ts +68 -6
  25. package/dist-sdk/src/engine/pull/context.js +40 -1
  26. package/dist-sdk/src/engine/pull/procedure-refs.d.ts +8 -0
  27. package/dist-sdk/src/engine/pull/procedure-refs.js +28 -0
  28. package/dist-sdk/src/engine/pull/ref-only.d.ts +5 -0
  29. package/dist-sdk/src/engine/pull/ref-only.js +10 -7
  30. package/dist-sdk/src/engine/pull/result-output.d.ts +6 -0
  31. package/dist-sdk/src/engine/pull/result-output.js +113 -3
  32. package/dist-sdk/src/engine/tf/expr.js +1 -1
  33. package/dist-sdk/src/engine/tf/index.d.ts +2 -2
  34. package/dist-sdk/src/engine/tf/index.js +1 -1
  35. package/dist-sdk/src/engine/tf/labels.d.ts +28 -5
  36. package/dist-sdk/src/engine/tf/labels.js +54 -3
  37. package/dist-sdk/src/engine/tf/model.d.ts +22 -1
  38. package/dist-sdk/src/engine/tf/parse.js +93 -4
  39. package/dist-sdk/src/engine/tf/render.d.ts +4 -2
  40. package/dist-sdk/src/engine/tf/render.js +41 -7
  41. package/dist-sdk/src/engine/validation.d.ts +44 -0
  42. package/dist-sdk/src/engine/validation.js +95 -0
  43. package/dist-sdk/src/entities/access-policy/from-tf.js +38 -1
  44. package/dist-sdk/src/entities/access-policy/principal.d.ts +2 -0
  45. package/dist-sdk/src/entities/access-policy/to-tf.js +5 -2
  46. package/dist-sdk/src/entities/agent/build.d.ts +4 -16
  47. package/dist-sdk/src/entities/agent/build.js +40 -5
  48. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.d.ts +3 -0
  49. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +46 -21
  50. package/dist-sdk/src/entities/agent/from-tf.js +11 -3
  51. package/dist-sdk/src/entities/agent/module.js +2 -0
  52. package/dist-sdk/src/entities/agent/to-tf.js +20 -6
  53. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +10 -1
  54. package/dist-sdk/src/entities/agent-tool/from-tf.js +18 -6
  55. package/dist-sdk/src/entities/agent-tool/module.js +3 -0
  56. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
  57. package/dist-sdk/src/entities/agent-tool/to-tf.js +27 -5
  58. package/dist-sdk/src/entities/app/auto-share.d.ts +38 -0
  59. package/dist-sdk/src/entities/app/auto-share.js +49 -0
  60. package/dist-sdk/src/entities/app/build.d.ts +105 -22
  61. package/dist-sdk/src/entities/app/build.js +107 -10
  62. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +22 -1
  63. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -0
  64. package/dist-sdk/src/entities/app/from-tf.js +11 -2
  65. package/dist-sdk/src/entities/app/index.d.ts +7 -6
  66. package/dist-sdk/src/entities/app/index.js +2 -8
  67. package/dist-sdk/src/entities/app/module.js +5 -2
  68. package/dist-sdk/src/entities/app/to-tf.d.ts +6 -0
  69. package/dist-sdk/src/entities/app/to-tf.js +40 -13
  70. package/dist-sdk/src/entities/automation/build.d.ts +56 -6
  71. package/dist-sdk/src/entities/automation/build.js +230 -26
  72. package/dist-sdk/src/entities/automation/calculation-expression.d.ts +7 -7
  73. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +41 -5
  74. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +470 -58
  75. package/dist-sdk/src/entities/automation/from-tf.d.ts +37 -8
  76. package/dist-sdk/src/entities/automation/from-tf.js +791 -131
  77. package/dist-sdk/src/entities/automation/generated/task-output-contracts.d.ts +33 -0
  78. package/dist-sdk/src/entities/automation/generated/task-output-contracts.js +183 -0
  79. package/dist-sdk/src/entities/automation/index.d.ts +2 -2
  80. package/dist-sdk/src/entities/automation/index.js +1 -1
  81. package/dist-sdk/src/entities/automation/module.d.ts +3 -0
  82. package/dist-sdk/src/entities/automation/module.js +107 -15
  83. package/dist-sdk/src/entities/automation/output-field-types.d.ts +7 -0
  84. package/dist-sdk/src/entities/automation/output-field-types.js +36 -0
  85. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +9 -0
  86. package/dist-sdk/src/entities/automation/output-key-wire-name.js +13 -0
  87. package/dist-sdk/src/entities/automation/script-code.d.ts +20 -0
  88. package/dist-sdk/src/entities/automation/script-code.js +109 -5
  89. package/dist-sdk/src/entities/automation/system-ref-name.js +4 -0
  90. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +39 -0
  91. package/dist-sdk/src/entities/automation/task-output-labels.js +85 -0
  92. package/dist-sdk/src/entities/automation/tasks.d.ts +116 -22
  93. package/dist-sdk/src/entities/automation/tasks.js +86 -24
  94. package/dist-sdk/src/entities/automation/to-tf.d.ts +24 -3
  95. package/dist-sdk/src/entities/automation/to-tf.js +1082 -132
  96. package/dist-sdk/src/entities/automation/triggers.d.ts +12 -6
  97. package/dist-sdk/src/entities/automation/triggers.js +4 -0
  98. package/dist-sdk/src/entities/automation/types.d.ts +9 -0
  99. package/dist-sdk/src/entities/automation/types.js +19 -0
  100. package/dist-sdk/src/entities/automation/value-ref-tf.d.ts +1 -1
  101. package/dist-sdk/src/entities/automation/value-ref-tf.js +1 -1
  102. package/dist-sdk/src/entities/chart/from-tf.js +9 -1
  103. package/dist-sdk/src/entities/chart/to-tf.js +10 -3
  104. package/dist-sdk/src/entities/data-lookup/module.js +2 -0
  105. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +24 -31
  106. package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +1 -0
  107. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +7 -5
  108. package/dist-sdk/src/entities/element/build.d.ts +28 -13
  109. package/dist-sdk/src/entities/element/build.js +5 -1
  110. package/dist-sdk/src/entities/element/from-tf.d.ts +11 -0
  111. package/dist-sdk/src/entities/element/from-tf.js +62 -1
  112. package/dist-sdk/src/entities/element/index.d.ts +5 -3
  113. package/dist-sdk/src/entities/element/index.js +1 -0
  114. package/dist-sdk/src/entities/element/module.js +9 -3
  115. package/dist-sdk/src/entities/element/to-tf.d.ts +1 -1
  116. package/dist-sdk/src/entities/element/to-tf.js +16 -16
  117. package/dist-sdk/src/entities/field/build.d.ts +17 -3
  118. package/dist-sdk/src/entities/field/build.js +3 -0
  119. package/dist-sdk/src/entities/field/calc.d.ts +7 -7
  120. package/dist-sdk/src/entities/field/from-tf.d.ts +5 -4
  121. package/dist-sdk/src/entities/field/from-tf.js +244 -49
  122. package/dist-sdk/src/entities/field/media-types.d.ts +6 -0
  123. package/dist-sdk/src/entities/field/media-types.js +30 -0
  124. package/dist-sdk/src/entities/field/module.js +2 -0
  125. package/dist-sdk/src/entities/field/options.js +6 -1
  126. package/dist-sdk/src/entities/field/to-tf.d.ts +26 -5
  127. package/dist-sdk/src/entities/field/to-tf.js +137 -15
  128. package/dist-sdk/src/entities/field/types.d.ts +2 -0
  129. package/dist-sdk/src/entities/field/types.js +27 -0
  130. package/dist-sdk/src/entities/file-reader/from-tf.js +14 -5
  131. package/dist-sdk/src/entities/file-reader/module.js +1 -0
  132. package/dist-sdk/src/entities/file-reader/types.d.ts +2 -0
  133. package/dist-sdk/src/entities/file-reader/types.js +1 -1
  134. package/dist-sdk/src/entities/portal/build.d.ts +26 -0
  135. package/dist-sdk/src/entities/portal/build.js +37 -0
  136. package/dist-sdk/src/entities/portal/from-tf.d.ts +27 -0
  137. package/dist-sdk/src/entities/portal/from-tf.js +75 -0
  138. package/dist-sdk/src/entities/portal/index.d.ts +1 -0
  139. package/dist-sdk/src/entities/portal/index.js +1 -0
  140. package/dist-sdk/src/entities/portal/module.d.ts +3 -0
  141. package/dist-sdk/src/entities/portal/module.js +28 -0
  142. package/dist-sdk/src/entities/portal/to-tf.d.ts +12 -0
  143. package/dist-sdk/src/entities/portal/to-tf.js +73 -0
  144. package/dist-sdk/src/entities/portal/types.d.ts +1 -0
  145. package/dist-sdk/src/entities/portal/types.js +1 -0
  146. package/dist-sdk/src/entities/relationship/module.js +2 -0
  147. package/dist-sdk/src/entities/relationship/pair-check.d.ts +7 -0
  148. package/dist-sdk/src/entities/relationship/pair-check.js +68 -0
  149. package/dist-sdk/src/entities/relationship/to-tf.d.ts +2 -0
  150. package/dist-sdk/src/entities/relationship/to-tf.js +12 -3
  151. package/dist-sdk/src/entities/role/from-tf.js +3 -3
  152. package/dist-sdk/src/entities/role/to-tf.d.ts +2 -0
  153. package/dist-sdk/src/entities/role/to-tf.js +12 -4
  154. package/dist-sdk/src/entities/search-table/module.js +1 -0
  155. package/dist-sdk/src/entities/search-table/to-tf.d.ts +1 -0
  156. package/dist-sdk/src/entities/search-table/to-tf.js +1 -1
  157. package/dist-sdk/src/entities/service-account/build.d.ts +15 -2
  158. package/dist-sdk/src/entities/service-account/from-tf.d.ts +2 -4
  159. package/dist-sdk/src/entities/service-account/from-tf.js +20 -8
  160. package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +56 -0
  161. package/dist-sdk/src/entities/service-account/role-fidelity.js +243 -0
  162. package/dist-sdk/src/entities/service-account/to-tf.d.ts +14 -0
  163. package/dist-sdk/src/entities/service-account/to-tf.js +17 -0
  164. package/dist-sdk/src/entities/service-account/workspace-owner.d.ts +16 -0
  165. package/dist-sdk/src/entities/service-account/workspace-owner.js +22 -0
  166. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +1 -1
  167. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +5 -2
  168. package/dist-sdk/src/entities/shared/filters/ast.d.ts +23 -1
  169. package/dist-sdk/src/entities/shared/filters/ast.js +2 -0
  170. package/dist-sdk/src/entities/shared/filters/index.d.ts +7 -0
  171. package/dist-sdk/src/entities/shared/filters/index.js +19 -4
  172. package/dist-sdk/src/entities/shared/filters/print.js +24 -3
  173. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +7 -0
  174. package/dist-sdk/src/entities/shared/filters/tf-codec.js +46 -7
  175. package/dist-sdk/src/entities/shared/filters/types.d.ts +15 -2
  176. package/dist-sdk/src/entities/shared/ref.d.ts +5 -7
  177. package/dist-sdk/src/entities/shared/ref.js +5 -7
  178. package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +9 -0
  179. package/dist-sdk/src/entities/shared/tool-field-ref.js +35 -2
  180. package/dist-sdk/src/entities/shared/types/field-types.d.ts +20 -5
  181. package/dist-sdk/src/entities/shared/types/field-types.js +8 -0
  182. package/dist-sdk/src/entities/skill/access-policy.js +3 -3
  183. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +3 -0
  184. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +14 -6
  185. package/dist-sdk/src/entities/skill/from-tf.js +70 -15
  186. package/dist-sdk/src/entities/skill/input-coverage.d.ts +7 -0
  187. package/dist-sdk/src/entities/skill/input-coverage.js +11 -0
  188. package/dist-sdk/src/entities/skill/module.js +2 -0
  189. package/dist-sdk/src/entities/skill/to-tf.js +14 -4
  190. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
  191. package/dist-sdk/src/entities/skill-tool/from-tf.js +49 -10
  192. package/dist-sdk/src/entities/skill-tool/module.js +3 -0
  193. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +2 -8
  194. package/dist-sdk/src/entities/skill-tool/to-tf.js +49 -14
  195. package/dist-sdk/src/entities/table/catalog.d.ts +14 -0
  196. package/dist-sdk/src/entities/table/catalog.js +66 -0
  197. package/dist-sdk/src/entities/table/module.js +2 -1
  198. package/dist-sdk/src/entities/table/to-tf.js +2 -2
  199. package/dist-sdk/src/entities/task/build.d.ts +8 -0
  200. package/dist-sdk/src/entities/task/build.js +10 -1
  201. package/dist-sdk/src/entities/task/from-tf.d.ts +4 -2
  202. package/dist-sdk/src/entities/task/from-tf.js +7 -2
  203. package/dist-sdk/src/entities/task/module.js +2 -2
  204. package/dist-sdk/src/entities/task/to-tf.d.ts +8 -4
  205. package/dist-sdk/src/entities/task/to-tf.js +28 -1
  206. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +49 -9
  207. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +71 -18
  208. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +19 -4
  209. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +82 -10
  210. package/dist-sdk/src/entities/view/agent-view-layout.d.ts +53 -23
  211. package/dist-sdk/src/entities/view/agent-view-layout.js +1 -1
  212. package/dist-sdk/src/entities/view/from-tf.d.ts +3 -2
  213. package/dist-sdk/src/entities/view/from-tf.js +133 -13
  214. package/dist-sdk/src/entities/view/module.js +30 -3
  215. package/dist-sdk/src/entities/view/to-tf.d.ts +20 -8
  216. package/dist-sdk/src/entities/view/to-tf.js +86 -18
  217. package/dist-sdk/src/entities/view/types.d.ts +4 -15
  218. package/dist-sdk/src/entities/view/types.js +15 -15
  219. package/dist-sdk/src/entities/visual-flow/build.d.ts +16 -1
  220. package/dist-sdk/src/entities/visual-flow/build.js +9 -0
  221. package/dist-sdk/src/entities/visual-flow/from-tf.d.ts +14 -0
  222. package/dist-sdk/src/entities/visual-flow/from-tf.js +51 -3
  223. package/dist-sdk/src/entities/visual-flow/index.d.ts +1 -1
  224. package/dist-sdk/src/entities/visual-flow/index.js +1 -1
  225. package/dist-sdk/src/entities/visual-flow/printer.js +19 -0
  226. package/dist-sdk/src/entities/visual-flow/to-tf.js +87 -3
  227. package/dist-sdk/src/entities/widget/build.d.ts +16 -1
  228. package/dist-sdk/src/entities/widget/build.js +11 -1
  229. package/dist-sdk/src/entities/widget/from-tf.js +3 -3
  230. package/dist-sdk/src/entities/widget/to-tf.d.ts +2 -0
  231. package/dist-sdk/src/entities/widget/to-tf.js +41 -14
  232. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +148 -13
  233. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  234. package/dist-sdk/src/graph/index.d.ts +12 -0
  235. package/dist-sdk/src/graph/index.js +21 -0
  236. package/dist-sdk/src/graph/modules.js +2 -0
  237. package/dist-sdk/src/graph/types.d.ts +83 -4
  238. package/dist-sdk/src/internal/sdk-package.d.ts +1 -1
  239. package/dist-sdk/src/internal/sdk-package.js +1 -0
  240. package/package.json +16 -3
@@ -205,13 +205,23 @@ function wireFilterValueToTf(value, field, codec, role = "value", operator) {
205
205
  throw new EntityTfError("reference filter value requires value");
206
206
  const authored = raw.realType ?? raw.real_type;
207
207
  const authoredType = typeof authored === "string" ? authored : undefined;
208
- const inferred = codec.referenceRealType?.(reference, role, authoredType);
208
+ // `filter.text()` and the other typed wrappers set `explicit`. That type
209
+ // is the comparison the author wrote. Metadata inference replaces only an
210
+ // unmarked operator fallback (dropdown `.id` TEXT → UUID). An operator
211
+ // fallback of TEXT, and a trigger-field inference that agrees with the
212
+ // authored type, stay off the reference callback so a runAutomation left
213
+ // ref is not enveloped.
214
+ const explicit = raw.explicit === true;
215
+ const inferred = explicit ? authoredType : codec.referenceRealType?.(reference, role, authoredType);
209
216
  const realType = String(inferred ?? authoredType ?? "TEXT");
217
+ const inferenceDisagrees = inferred !== undefined
218
+ && inferred.toUpperCase() !== (authoredType ?? "").toUpperCase();
219
+ const referenceRealType = explicit ? realType : inferenceDisagrees ? inferred : undefined;
210
220
  // ei export always writes an explicit `multiple = false` on scalar text
211
221
  // references. Omitting it plans null-vs-false drift after pull.
212
222
  return {
213
223
  type,
214
- value_reference: codec.reference(reference, role, realType, operator),
224
+ value_reference: codec.reference(reference, role, referenceRealType, operator),
215
225
  real_type: realType.toLowerCase(),
216
226
  multiple: typeof raw.multiple === "boolean" ? raw.multiple : false,
217
227
  };
@@ -233,7 +243,14 @@ function wireFilterValueToTf(value, field, codec, role = "value", operator) {
233
243
  if (type === "record_field") {
234
244
  if (raw.field === undefined)
235
245
  throw new EntityTfError("record_field filter value requires field");
236
- const aspect = raw.aspect ?? raw.object;
246
+ let object = (raw.aspect ?? raw.object);
247
+ if (raw.includeOwner === true) {
248
+ if (object !== undefined)
249
+ throw new EntityTfError("record_field filter value cannot set includeOwner and also name a raw app id");
250
+ if (codec.recordFieldOwner === undefined)
251
+ throw new EntityTfError("a record_field filter value with includeOwner needs an owning app or element in this filter context");
252
+ object = codec.recordFieldOwner();
253
+ }
237
254
  const sourceFieldType = raw.sourceFieldType ?? raw.source_field_type;
238
255
  let field;
239
256
  if (codec.recordField !== undefined)
@@ -245,7 +262,7 @@ function wireFilterValueToTf(value, field, codec, role = "value", operator) {
245
262
  return {
246
263
  type,
247
264
  field,
248
- ...(aspect !== undefined && { object: aspect }),
265
+ ...(object !== undefined && { object }),
249
266
  ...(sourceFieldType !== undefined && { source_field_type: String(sourceFieldType).toLowerCase() }),
250
267
  ...((raw.dynamicField ?? raw.dynamic_field) !== undefined && { dynamic_field: (raw.dynamicField ?? raw.dynamic_field) }),
251
268
  ...((raw.dynamicFieldAspect ?? raw.dynamic_field_object) !== undefined && { dynamic_field_object: (raw.dynamicFieldAspect ?? raw.dynamic_field_object) }),
@@ -574,8 +591,30 @@ function filterValueFromTf(value, codec, fieldScope) {
574
591
  case "record_field": {
575
592
  if (value.field === undefined)
576
593
  throw new EntityTfError("record_field filter value requires field");
577
- if ((value.object !== undefined && typeof value.object !== "string") || (value.source_field_type !== undefined && typeof value.source_field_type !== "string")) {
578
- throw new EntityTfError("record_field filter value object and source_field_type must be literal strings");
594
+ if (value.source_field_type !== undefined && typeof value.source_field_type !== "string") {
595
+ throw new EntityTfError("record_field filter value source_field_type must be a literal string");
596
+ }
597
+ // The exporter resolves the platform's dynamicField / dynamicFieldAspect
598
+ // to references (e.g. `data.elementum_app.parent.id`). No typed public
599
+ // value rebuilds them yet, so refuse rather than keep the rest of the
600
+ // value and let a rebuild silently omit them. RECORD_FIELD values only
601
+ // occur in dynamic Dropdown filters.
602
+ for (const key of ["dynamic_field", "dynamic_field_object"]) {
603
+ if (value[key] !== undefined && typeof value[key] !== "string") {
604
+ throw new EntityTfError(`record_field filter value ${key} reference cannot be reconstructed: the EDK cannot yet represent a dynamic-field comparison in a Dropdown filter`);
605
+ }
606
+ }
607
+ // A literal id stays as stored; a reference must name the owning app or
608
+ // element, which the owner context rebuilds, so only the fact survives.
609
+ let owner;
610
+ if (typeof value.object === "string")
611
+ owner = { aspect: value.object };
612
+ else if (value.object !== undefined) {
613
+ if (codec.recordFieldOwner === undefined)
614
+ throw new EntityTfError("record_field filter value object reference cannot be reconstructed in this filter context");
615
+ if (!codec.recordFieldOwner(value.object))
616
+ throw new EntityTfError("record_field filter value object must name the owning app or element");
617
+ owner = { includeOwner: true };
579
618
  }
580
619
  let field;
581
620
  if (typeof value.field === "string")
@@ -587,7 +626,7 @@ function filterValueFromTf(value, codec, fieldScope) {
587
626
  return {
588
627
  type: "RECORD_FIELD",
589
628
  field,
590
- ...(value.object !== undefined && { aspect: value.object }),
629
+ ...owner,
591
630
  ...(value.source_field_type !== undefined && { sourceFieldType: value.source_field_type.toUpperCase() }),
592
631
  ...(typeof value.dynamic_field === "string" && { dynamicField: value.dynamic_field }),
593
632
  ...(typeof value.dynamic_field_object === "string" && { dynamicFieldAspect: value.dynamic_field_object }),
@@ -69,17 +69,30 @@ export type FilterValue<FieldValue = string, ReferenceValue = FilterReference> =
69
69
  } | {
70
70
  type: "CURRENT_USER";
71
71
  valueType?: "ID" | "EMAIL" | "DOMAIN";
72
- } | {
72
+ } | ({
73
73
  type: "RECORD_FIELD";
74
74
  field: FieldValue | string;
75
- aspect?: string;
76
75
  sourceFieldType?: string;
77
76
  dynamicField?: string;
78
77
  dynamicFieldAspect?: string;
79
78
  required?: boolean;
79
+ } & ({
80
+ aspect?: string;
81
+ includeOwner?: never;
80
82
  } | {
83
+ includeOwner: true;
84
+ aspect?: never;
85
+ }))
86
+ /**
87
+ * `explicit` is set by `filter.text()` / `filter.uuid()` / the other typed
88
+ * wrappers, and by an explicit comparison type. Build keeps that type.
89
+ * Without it, `realType` is only the operator fallback and field metadata
90
+ * may replace TEXT (a dropdown `.id` infers UUID).
91
+ */
92
+ | {
81
93
  type: "REFERENCE";
82
94
  realType?: ValueType;
95
+ explicit?: true;
83
96
  value: ReferenceValue;
84
97
  label?: string;
85
98
  multiple?: boolean;
@@ -118,16 +118,14 @@ export type ValidateTemplateArgs<Args extends readonly unknown[]> = Args extends
118
118
  */
119
119
  export declare function template<const Args extends readonly (string | Ref<unknown>)[]>(...parts: Args & ValidateTemplateArgs<Args>): Ref<string>;
120
120
  /**
121
- * Reference a named secret by id. The resolver at execution time fetches
122
- * the plaintext from the Elementum secret vault. EDK never sees the
123
- * plaintext.
121
+ * Reference an existing Elementum vault entry by key. The platform resolves
122
+ * its value only when the automation runs; EDK never reads or stores it.
124
123
  *
125
124
  * @example
126
125
  * ```ts
127
- * apiRequest({
128
- * url: "https://api.example.com",
129
- * method: "GET",
130
- * authorization: { type: "bearer", token: secret("payments-provider-token") },
126
+ * .executeScript("Call API", {
127
+ * inputs: { baseUrl: secret("ELEMENTUM_BASE_URL") },
128
+ * code: (input) => ({ url: input.parameters.baseUrl }),
131
129
  * })
132
130
  * ```
133
131
  */
@@ -50,16 +50,14 @@ export function template(...parts) {
50
50
  return createRef({ kind: "template", parts: data });
51
51
  }
52
52
  /**
53
- * Reference a named secret by id. The resolver at execution time fetches
54
- * the plaintext from the Elementum secret vault. EDK never sees the
55
- * plaintext.
53
+ * Reference an existing Elementum vault entry by key. The platform resolves
54
+ * its value only when the automation runs; EDK never reads or stores it.
56
55
  *
57
56
  * @example
58
57
  * ```ts
59
- * apiRequest({
60
- * url: "https://api.example.com",
61
- * method: "GET",
62
- * authorization: { type: "bearer", token: secret("payments-provider-token") },
58
+ * .executeScript("Call API", {
59
+ * inputs: { baseUrl: secret("ELEMENTUM_BASE_URL") },
60
+ * code: (input) => ({ url: input.parameters.baseUrl }),
63
61
  * })
64
62
  * ```
65
63
  */
@@ -17,3 +17,12 @@
17
17
  import type { FromTfContext } from "../../engine/pull/context.js";
18
18
  import { type ChildResourceScope, type TfValue } from "../../engine/tf/index.js";
19
19
  export declare function resolveToolFieldKey(fieldRef: TfValue | undefined, scopeTfLabel: string, scope?: ChildResourceScope | "task", ctx?: Pick<FromTfContext, "dataAttrs" | "foreignFieldRefsByDataAddress">): string | undefined;
20
+ /**
21
+ * When `fieldRef` is a field resource whose scoped label names a different
22
+ * owner than the tool's resolved target, return that owner as
23
+ * `<scope> "<label>"` for diagnostics. Unscoped labels can't be attributed
24
+ * and return undefined.
25
+ */
26
+ export declare function toolFieldRefOtherOwner(fieldRef: TfValue | undefined, scopeTfLabel: string, scope?: ChildResourceScope | "task"): string | undefined;
27
+ /** Diagnostic for a tool fields item whose field_id could not be kept. */
28
+ export declare function droppedToolFieldDiagnostic(where: string, fieldRef: TfValue | undefined, scopeTfLabel: string, scope?: ChildResourceScope | "task"): string;
@@ -1,10 +1,14 @@
1
- import { isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel } from "../../engine/tf/index.js";
1
+ import { isTfExpr, ownerFromScopedChildLabel, scopedLabelToBagKey, tfLabelToTsLabel } from "../../engine/tf/index.js";
2
2
  import { SUB_TYPE_BY_RESOURCE as FIELD_SUB_TYPE_BY_RESOURCE } from "../field/types.js";
3
3
  export function resolveToolFieldKey(fieldRef, scopeTfLabel, scope = "app", ctx) {
4
4
  if (fieldRef === undefined)
5
5
  return undefined;
6
6
  if (isTfExpr(fieldRef) && fieldRef.$expr === "resource-attr" && FIELD_SUB_TYPE_BY_RESOURCE.has(fieldRef.type)) {
7
- return scopedLabelToBagKey(scopeTfLabel, fieldRef.label, scope === "task" ? "app" : scope);
7
+ // A field resource owned by a different app/element must not be renamed
8
+ // into a key on this tool's target (edk#1403 review S1).
9
+ if (toolFieldRefOtherOwner(fieldRef, scopeTfLabel, scope) !== undefined)
10
+ return undefined;
11
+ return scopedLabelToBagKey(scopeTfLabel, fieldRef.label, scope);
8
12
  }
9
13
  if (isTfExpr(fieldRef) && fieldRef.$expr === "data-attr" && fieldRef.type === "elementum_field") {
10
14
  const fieldAttrs = ctx?.dataAttrs?.("elementum_field", fieldRef.label);
@@ -40,3 +44,32 @@ export function resolveToolFieldKey(fieldRef, scopeTfLabel, scope = "app", ctx)
40
44
  }
41
45
  return undefined;
42
46
  }
47
+ /**
48
+ * When `fieldRef` is a field resource whose scoped label names a different
49
+ * owner than the tool's resolved target, return that owner as
50
+ * `<scope> "<label>"` for diagnostics. Unscoped labels can't be attributed
51
+ * and return undefined.
52
+ */
53
+ export function toolFieldRefOtherOwner(fieldRef, scopeTfLabel, scope = "app") {
54
+ if (fieldRef === undefined || !isTfExpr(fieldRef) || fieldRef.$expr !== "resource-attr")
55
+ return undefined;
56
+ if (!FIELD_SUB_TYPE_BY_RESOURCE.has(fieldRef.type))
57
+ return undefined;
58
+ const owner = ownerFromScopedChildLabel(fieldRef.label);
59
+ if (owner === undefined)
60
+ return undefined;
61
+ if (owner.scope === scope && owner.ownerTfLabel === scopeTfLabel)
62
+ return undefined;
63
+ return `${owner.scope} "${owner.ownerTfLabel}"`;
64
+ }
65
+ /** Diagnostic for a tool fields item whose field_id could not be kept. */
66
+ export function droppedToolFieldDiagnostic(where, fieldRef, scopeTfLabel, scope = "app") {
67
+ if (fieldRef === undefined || fieldRef === "")
68
+ return `${where}: fields item has no field_id; dropped`;
69
+ const other = toolFieldRefOtherOwner(fieldRef, scopeTfLabel, scope);
70
+ if (other !== undefined && isTfExpr(fieldRef) && fieldRef.$expr === "resource-attr") {
71
+ return `${where}: fields item's field_id references ${fieldRef.type}.${fieldRef.label}, a field of ${other}, ` +
72
+ `not of this tool's target "${scopeTfLabel}"; dropped - set this field on the tool by hand`;
73
+ }
74
+ return `${where}: fields item's field_id is not a field resource reference; dropped`;
75
+ }
@@ -1,5 +1,6 @@
1
1
  import type { AppOrElementRef } from "../../../catalog/types.js";
2
2
  import type { RecordShape } from "../../field/record-shape.js";
3
+ import type { CalculationTypedValue } from "../ref.js";
3
4
  /**
4
5
  * WorkflowFieldType — mirrors the Java enum in
5
6
  * jarvis/util/.../WorkflowFieldType.java
@@ -21,6 +22,9 @@ export type WorkflowFieldType = "TEXT" | "HANDLE" | "NUMBER" | "DECIMAL" | "BOOL
21
22
  * ATTACHMENT_ID -> "attachment" (and from-tf.ts the inverse) rather than
22
23
  * renaming this alias, to avoid a breaking change to authored `onDemand({})`
23
24
  * calls that already use `type: "attachmentId"`.
25
+ *
26
+ * `userId` follows the same rule: the provider's attribute spells USER_ID as
27
+ * a bare "user", so to-tf maps USER_ID -> "user" and from-tf maps it back.
24
28
  */
25
29
  export declare const FIELD_TYPE_MAP: {
26
30
  readonly text: "TEXT";
@@ -30,6 +34,7 @@ export declare const FIELD_TYPE_MAP: {
30
34
  readonly date: "DATE";
31
35
  readonly datetime: "DATETIME";
32
36
  readonly user: "USER";
37
+ readonly userId: "USER_ID";
33
38
  readonly json: "JSON";
34
39
  readonly object: "OBJECT";
35
40
  readonly attachmentId: "ATTACHMENT_ID";
@@ -41,16 +46,26 @@ export declare function isOnDemandRecordType(type: string | undefined): boolean;
41
46
  /**
42
47
  * Subset of {@link FieldTypeAlias} that Mobius's `onDemand` trigger
43
48
  * validator accepts. Mobius rejects `WorkflowFieldType.USER` and
44
- * `WorkflowFieldType.GROUP` (and other `*_ID` types) on trigger params:
49
+ * `WorkflowFieldType.GROUP` on trigger params:
45
50
  *
46
51
  * parameter[submitter]: Parameter type USER is not valid for this trigger.
47
52
  *
48
53
  * We model the restriction at the type level so `onDemand({ x: { type: "user" } })`
49
- * is a compile-time error, not a deploy-time 400. When Mobius widens the
50
- * accepted set, add the alias back here and the full enum will open up
51
- * for authors.
54
+ * is a compile-time error, not a deploy-time 400. A user input is a
55
+ * `userId` (USER_ID) parameter; a Run Automation button binds it to the
56
+ * clicking user with `runAutomationParameterValue.triggeredByUser`.
52
57
  */
53
58
  export type TriggerFieldTypeAlias = Exclude<FieldTypeAlias, "user">;
59
+ /**
60
+ * Subset of {@link TriggerFieldTypeAlias} that an `onDemand` input may
61
+ * declare. Mirrors the provider's `elementum_on_demand_trigger`
62
+ * `parameters[].type` enum (text, number, decimal, boolean, date, datetime,
63
+ * user, group, attachment, record): `json` and `object` have no provider
64
+ * spelling, so OpenTofu rejects the generated config at plan time (#1415).
65
+ */
66
+ export type OnDemandParamTypeAlias = Exclude<TriggerFieldTypeAlias, "json" | "object">;
67
+ /** Runtime list of {@link OnDemandParamTypeAlias} values. */
68
+ export declare const ON_DEMAND_PARAM_TYPES: readonly ["text", "number", "decimal", "boolean", "date", "datetime", "userId", "attachmentId", "record"];
54
69
  /**
55
70
  * Maps a user-friendly FieldTypeAlias to the TypeScript type it represents.
56
71
  * Used to derive the phantom T in Ref<T> for trigger inputs.
@@ -60,4 +75,4 @@ export type TriggerFieldTypeAlias = Exclude<FieldTypeAlias, "user">;
60
75
  * Used when generating app definitions from Hydra's field metadata.
61
76
  */
62
77
  export declare const ASPECT_FIELD_TYPE_NAME_TO_WORKFLOW_FIELD_TYPE: Record<string, WorkflowFieldType>;
63
- export type FieldTypeToTS<A extends FieldTypeAlias> = A extends "text" ? string : A extends "number" | "decimal" ? number : A extends "boolean" ? boolean : A extends "date" | "datetime" ? string : A extends "user" ? string : A extends "attachmentId" ? string : A extends "json" | "object" ? unknown : A extends "record" ? RecordShape<AppOrElementRef> : unknown;
78
+ export type FieldTypeToTS<A extends FieldTypeAlias> = A extends "text" ? string : A extends "number" | "decimal" ? number : A extends "boolean" ? boolean : A extends "date" | "datetime" ? string : A extends "user" ? string : A extends "userId" ? CalculationTypedValue<string, "user"> : A extends "attachmentId" ? string : A extends "json" | "object" ? unknown : A extends "record" ? RecordShape<AppOrElementRef> : unknown;
@@ -10,6 +10,9 @@
10
10
  * ATTACHMENT_ID -> "attachment" (and from-tf.ts the inverse) rather than
11
11
  * renaming this alias, to avoid a breaking change to authored `onDemand({})`
12
12
  * calls that already use `type: "attachmentId"`.
13
+ *
14
+ * `userId` follows the same rule: the provider's attribute spells USER_ID as
15
+ * a bare "user", so to-tf maps USER_ID -> "user" and from-tf maps it back.
13
16
  */
14
17
  export const FIELD_TYPE_MAP = {
15
18
  text: "TEXT",
@@ -19,6 +22,7 @@ export const FIELD_TYPE_MAP = {
19
22
  date: "DATE",
20
23
  datetime: "DATETIME",
21
24
  user: "USER",
25
+ userId: "USER_ID",
22
26
  json: "JSON",
23
27
  object: "OBJECT",
24
28
  attachmentId: "ATTACHMENT_ID",
@@ -28,6 +32,10 @@ export const FIELD_TYPE_MAP = {
28
32
  export function isOnDemandRecordType(type) {
29
33
  return type === "record" || type === "ASPECT_RECORD";
30
34
  }
35
+ /** Runtime list of {@link OnDemandParamTypeAlias} values. */
36
+ export const ON_DEMAND_PARAM_TYPES = [
37
+ "text", "number", "decimal", "boolean", "date", "datetime", "userId", "attachmentId", "record",
38
+ ];
31
39
  /**
32
40
  * Maps a user-friendly FieldTypeAlias to the TypeScript type it represents.
33
41
  * Used to derive the phantom T in Ref<T> for trigger inputs.
@@ -1,6 +1,6 @@
1
1
  import { EntityTfError } from "../../engine/entity.js";
2
- import { dataRefLabel } from "../../engine/pull/context.js";
3
- import { expr, sanitizeName, tfLabelToTsLabel } from "../../engine/tf/index.js";
2
+ import { dataRefLabel, groupCatalogKey } from "../../engine/pull/context.js";
3
+ import { expr, sanitizeName } from "../../engine/tf/index.js";
4
4
  function object(value) {
5
5
  return value !== null && typeof value === "object" && !Array.isArray(value);
6
6
  }
@@ -90,7 +90,7 @@ export function skillAccessPolicyFromTf(attrs, ctx) {
90
90
  if (output === "users")
91
91
  users.push({ __kind: "user", email: identity });
92
92
  else
93
- groups.push({ __kind: "group", refName: tfLabelToTsLabel(label), name: identity });
93
+ groups.push({ __kind: "group", refName: groupCatalogKey(ctx, label, identity), name: identity });
94
94
  }
95
95
  if (output === "users")
96
96
  policy.users = users;
@@ -44,6 +44,9 @@ export interface PrintSkillV2Options {
44
44
  * `catalog.<refName>` instead of the literal stub.
45
45
  */
46
46
  readonly foreignTaskRefNames?: ReadonlyMap<string, string>;
47
+ /** Terraform label → authored catalog ref. Field identities stay on the label. */
48
+ readonly foreignAppRefNamespaces?: ReadonlyMap<string, string>;
49
+ readonly foreignElementRefNamespaces?: ReadonlyMap<string, string>;
47
50
  /** Raw foreign field id → typed catalog field identity, supplied by recursive pull. */
48
51
  readonly foreignFieldRefsById?: ReadonlyMap<string, {
49
52
  readonly ownerRefName: string;
@@ -13,6 +13,7 @@
13
13
  * Unresolved field and automation platform ids print as `unsafePlatformId(...)`.
14
14
  */
15
15
  import { quote } from "../../../../pull/util.js";
16
+ import { catalogRefForFieldOwner } from "../../../engine/pull/catalog-ref.js";
16
17
  import { sanitizeName, tfLabelToTsLabel } from "../../../engine/tf/index.js";
17
18
  import { sdkPackageSpecifier } from "../../../internal/sdk-package.js";
18
19
  import { safeIdentifier } from "../../../internal/safe-identifier.js";
@@ -139,7 +140,7 @@ export function printSkillV2(skill, opts) {
139
140
  if (skill.tools.length > 0) {
140
141
  lines.push(" tools: [");
141
142
  for (const tool of skill.tools) {
142
- lines.push(...printTool(tool, appRefName, crossOrg, opts.foreignAppRefNames, opts.foreignElementRefNames, opts.foreignTaskRefNames, opts.foreignFieldRefsById, opts.foreignSearchTableRefsByName).map((l) => ` ${l}`));
143
+ lines.push(...printTool(tool, appRefName, crossOrg, opts.foreignAppRefNames, opts.foreignElementRefNames, opts.foreignTaskRefNames, opts.foreignFieldRefsById, opts.foreignSearchTableRefsByName, opts.foreignAppRefNamespaces, opts.foreignElementRefNamespaces).map((l) => ` ${l}`));
143
144
  }
144
145
  lines.push(" ],");
145
146
  }
@@ -191,7 +192,7 @@ function fieldOwnerRef(tool, appRefName, foreignAppRefNames, foreignElementRefNa
191
192
  }
192
193
  : { kind: "raw", entityType: entityKind, name: tool.target.name, refName: tool.target.name };
193
194
  }
194
- function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElementRefNames, foreignTaskRefNames, foreignFieldRefsById, foreignSearchTableRefsByName) {
195
+ function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElementRefNames, foreignTaskRefNames, foreignFieldRefsById, foreignSearchTableRefsByName, foreignAppRefNamespaces, foreignElementRefNamespaces) {
195
196
  const factory = TOOL_FACTORY_BY_TYPE_KEY[tool.typeKey] ?? "skillSearchRecords";
196
197
  const lines = [`${factory}({`];
197
198
  const targetRefName = tool.target?.kind === "self"
@@ -286,7 +287,12 @@ function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElemen
286
287
  : tool.target.kind === "foreignTask"
287
288
  ? foreignTaskRefNames
288
289
  : foreignAppRefNames;
289
- const catalogRefName = refNames?.get(tool.target.name);
290
+ // Display-name map first: the terraform label and the authored catalog key
291
+ // differ (#1427). Extract-time refName is the state/namespace join for
292
+ // apps and elements. Task refNames are terraform labels, so they stay on
293
+ // the inline stub unless the map names a workspace catalog key (#1452).
294
+ const mapped = refNames?.get(tool.target.name);
295
+ const catalogRefName = mapped ?? (tool.target.kind === "foreignTask" ? undefined : tool.target.refName);
290
296
  if (catalogRefName !== undefined) {
291
297
  lines.push(` ${entityKind}: catalog.${catalogRefName},`);
292
298
  }
@@ -341,10 +347,12 @@ function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElemen
341
347
  if (tool.target?.kind === "tableOwned") {
342
348
  const owner = tool.searchTableOwnerRefName ?? parent;
343
349
  const ownerName = tool.searchTableOwnerName;
344
- lines.push(` table: tableSearchTableRef({ name: ${quote(tool.searchTableName ?? "")}, parent: ${quote(owner)}${ownerName !== undefined ? `, parentName: ${quote(ownerName)}` : ""} }),`);
350
+ const pinnedId = tool.searchTableId !== undefined ? `, id: ${quote(tool.searchTableId)}` : "";
351
+ lines.push(` table: tableSearchTableRef({ name: ${quote(tool.searchTableName ?? "")}, parent: ${quote(owner)}${ownerName !== undefined ? `, parentName: ${quote(ownerName)}` : ""}${pinnedId} }),`);
345
352
  }
346
353
  else if (typedTable !== undefined) {
347
- lines.push(` table: catalog.${typedTable.ownerRefName}.searchTables${safeMember(typedTable.tableKey)},`);
354
+ const tableOwner = catalogRefForFieldOwner(typedTable.ownerRefName, foreignAppRefNamespaces, foreignElementRefNamespaces);
355
+ lines.push(` table: catalog.${tableOwner}.searchTables${safeMember(typedTable.tableKey)},`);
348
356
  }
349
357
  else {
350
358
  lines.push(` table: { __kind: "searchTable", refName: ${quote(tool.searchTableName ?? "")}, name: ${quote(tool.searchTableName ?? "")}, parent: ${quote(parent)} },`);
@@ -380,7 +388,7 @@ function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElemen
380
388
  const parts = isRaw
381
389
  ? [`fieldId: unsafePlatformId(${quote(f.rawFieldId ?? "")})`]
382
390
  : resolvedRaw !== undefined
383
- ? [`field: catalog.${resolvedRaw.ownerRefName}.fields.${resolvedRaw.fieldKey}`]
391
+ ? [`field: catalog.${catalogRefForFieldOwner(resolvedRaw.ownerRefName, foreignAppRefNamespaces, foreignElementRefNamespaces)}.fields.${resolvedRaw.fieldKey}`]
384
392
  : owner.kind === "catalog"
385
393
  ? [`field: ${owner.expr}.fields.${f.key}`]
386
394
  : owner.kind === "table"
@@ -6,11 +6,11 @@
6
6
  * source. Mirrors `entities/agent/from-tf.ts`.
7
7
  */
8
8
  import { EntityTfError } from "../../engine/entity.js";
9
- import { optionalString, resourceRefLabel } from "../../engine/pull/context.js";
10
- import { scopedLabelToBagKey } from "../../engine/tf/index.js";
9
+ import { optionalString, ownerMismatchBlocker, reportAuthoringBlocker, resourceRefLabel } from "../../engine/pull/context.js";
10
+ import { isTfExpr, scopedLabelToBagKey } from "../../engine/tf/index.js";
11
11
  import { skillToolFromTf } from "../skill-tool/from-tf.js";
12
12
  import { APP_RESOURCE_TYPE } from "../app/module.js";
13
- import { analyzeSkillInputCoverage, decomposeSkillInstructions, skillCoverageGapDiagnostics, skillCoverageReportLines, } from "./input-coverage.js";
13
+ import { analyzeSkillInputCoverage, decomposeSkillInstructionsLossless, skillCoverageGapDiagnostics, skillCoverageReportLines, } from "./input-coverage.js";
14
14
  import { SKILL_RESOURCE_TYPE } from "./module.js";
15
15
  import { skillAccessPolicyFromTf } from "./access-policy.js";
16
16
  /** Attributes `skillFromTf` understands — anything else is dialect growth, reported loudly. */
@@ -42,6 +42,68 @@ function optionalStringList(attrs, key, where, ctx) {
42
42
  }
43
43
  return value;
44
44
  }
45
+ /** Walk a parsed value, rejecting anything that is still a Terraform expression. */
46
+ function asPlainJson(value) {
47
+ if (isTfExpr(value))
48
+ return { ok: false };
49
+ if (Array.isArray(value)) {
50
+ const items = [];
51
+ for (const item of value) {
52
+ const plain = asPlainJson(item);
53
+ if (!plain.ok)
54
+ return plain;
55
+ items.push(plain.value);
56
+ }
57
+ return { ok: true, value: items };
58
+ }
59
+ if (typeof value === "object" && value !== null) {
60
+ const out = {};
61
+ for (const [key, child] of Object.entries(value)) {
62
+ const plain = asPlainJson(child);
63
+ if (!plain.ok)
64
+ return plain;
65
+ out[key] = plain.value;
66
+ }
67
+ return { ok: true, value: out };
68
+ }
69
+ return { ok: true, value };
70
+ }
71
+ function propertiesObject(value, where, ctx) {
72
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
73
+ ctx.diagnostics.push(`${where}: properties JSON must be an object; dropped`);
74
+ return undefined;
75
+ }
76
+ return value;
77
+ }
78
+ /**
79
+ * `properties` is a JSON string on the wire. ei emits it as `jsonencode({...})`
80
+ * so the file formats; older builds may still carry a quoted JSON string.
81
+ * Either shape keeps the skill. An unreadable shape drops only the attribute.
82
+ */
83
+ function propertiesFromTf(raw, where, ctx) {
84
+ if (raw === undefined || raw === null || raw === "")
85
+ return undefined;
86
+ if (typeof raw === "string") {
87
+ try {
88
+ // eslint-disable-next-line no-restricted-syntax -- properties is a JSON string on the resource, not an authored entity.
89
+ return propertiesObject(JSON.parse(raw), where, ctx);
90
+ }
91
+ catch {
92
+ ctx.diagnostics.push(`${where}: properties is not valid JSON; dropped`);
93
+ return undefined;
94
+ }
95
+ }
96
+ if (isTfExpr(raw) && raw.$expr === "jsonencode") {
97
+ const plain = asPlainJson(raw.value);
98
+ if (!plain.ok) {
99
+ ctx.diagnostics.push(`${where}: properties jsonencode payload is not plain JSON; dropped`);
100
+ return undefined;
101
+ }
102
+ return propertiesObject(plain.value, where, ctx);
103
+ }
104
+ ctx.diagnostics.push(`${where}: properties has an unrecognized shape; dropped`);
105
+ return undefined;
106
+ }
45
107
  /**
46
108
  * The `elementum_agentic_skill` block + its tool blocks → the normalized
47
109
  * skill. Tool blocks belonging to OTHER skills are skipped with a
@@ -66,18 +128,11 @@ export function skillFromTf(skillBlock, toolBlocks, appLabel, ctx) {
66
128
  return { skippedReason: `${where}: owner_type ${JSON.stringify(ownerType)} has no terraform-path authoring yet; skipped` };
67
129
  }
68
130
  if (resourceRefLabel(attrs["owner_id"], APP_RESOURCE_TYPE) !== appLabel) {
69
- return { skippedReason: `${where}: owner_id does not reference ${APP_RESOURCE_TYPE}.${appLabel}; skipped` };
70
- }
71
- let properties;
72
- const rawProperties = attrs["properties"];
73
- if (typeof rawProperties === "string" && rawProperties !== "") {
74
- try {
75
- properties = JSON.parse(rawProperties);
76
- }
77
- catch {
78
- ctx.diagnostics.push(`${where}: properties is not valid JSON; dropped`);
79
- }
131
+ const reason = `${where}: owner_id does not reference ${APP_RESOURCE_TYPE}.${appLabel}`;
132
+ reportAuthoringBlocker(ctx, ownerMismatchBlocker(`${SKILL_RESOURCE_TYPE}.${label}`, reason, "skill"));
133
+ return { skippedReason: `${reason}; skipped` };
80
134
  }
135
+ const properties = propertiesFromTf(attrs["properties"], where, ctx);
81
136
  const status = optionalString(attrs, "status", where, ctx);
82
137
  const accessPolicy = skillAccessPolicyFromTf(attrs, ctx);
83
138
  const routingPriority = attrs["routing_priority"];
@@ -111,7 +166,7 @@ export function skillFromTf(skillBlock, toolBlocks, appLabel, ctx) {
111
166
  const coverage = analyzeSkillInputCoverage(name, rawInstructions, coverageTools);
112
167
  ctx.reports?.push(...skillCoverageReportLines(coverage));
113
168
  ctx.diagnostics.push(...skillCoverageGapDiagnostics(coverage));
114
- const decomposed = decomposeSkillInstructions(rawInstructions);
169
+ const decomposed = decomposeSkillInstructionsLossless(rawInstructions);
115
170
  const instructions = decomposed.inputs.length > 0 || decomposed.lookups.length > 0
116
171
  ? decomposed.prose
117
172
  : rawInstructions;
@@ -79,6 +79,13 @@ export declare function formatSkillInputSchema(inputs: readonly SkillInputDefini
79
79
  export declare function formatSkillLookupNotes(lookups: readonly SkillLookupDefinition[]): string;
80
80
  export declare function deriveSkillInstructions(baseProse: string | undefined, inputs?: readonly SkillInputDefinition[], lookups?: readonly SkillLookupDefinition[]): string;
81
81
  export declare function decomposeSkillInstructions(markdown: string): DecomposedSkillInstructions;
82
+ /**
83
+ * Decompose instructions for pulled source only when build reproduces them exactly — build re-derives the
84
+ * Input Schema / Lookup Notes sections from structured inputs/lookups, printed only when non-empty. Text the
85
+ * generator would not write back byte for byte (e.g. a hand-written "## Lookup Notes" placeholder) stays verbatim
86
+ * in the prose, so a pull → build round trip never changes the platform's instructions.
87
+ */
88
+ export declare function decomposeSkillInstructionsLossless(markdown: string): DecomposedSkillInstructions;
82
89
  /** Compare instruction-declared form variables with the deployed tool surface. */
83
90
  export declare function analyzeSkillInputCoverage(skill: string, instructions: string, coverageTools: readonly SkillCoverageTool[]): SkillInputCoverageReport;
84
91
  /** Informational coverage lines emitted on stderr and in JSON `reports`. */
@@ -197,6 +197,17 @@ export function decomposeSkillInstructions(markdown) {
197
197
  const prose = proseLines.join("\n").trim();
198
198
  return { prose, inputs, lookups };
199
199
  }
200
+ /**
201
+ * Decompose instructions for pulled source only when build reproduces them exactly — build re-derives the
202
+ * Input Schema / Lookup Notes sections from structured inputs/lookups, printed only when non-empty. Text the
203
+ * generator would not write back byte for byte (e.g. a hand-written "## Lookup Notes" placeholder) stays verbatim
204
+ * in the prose, so a pull → build round trip never changes the platform's instructions.
205
+ */
206
+ export function decomposeSkillInstructionsLossless(markdown) {
207
+ const decomposed = decomposeSkillInstructions(markdown);
208
+ const rebuilt = deriveSkillInstructions(decomposed.prose, decomposed.inputs.length > 0 ? decomposed.inputs : undefined, decomposed.lookups.length > 0 ? decomposed.lookups : undefined);
209
+ return rebuilt === markdown ? decomposed : { prose: markdown, inputs: [], lookups: [] };
210
+ }
200
211
  function mentionsIdentifier(markdown, name) {
201
212
  if (name === "")
202
213
  return false;
@@ -90,6 +90,8 @@ export const skillModule = {
90
90
  ...(opts.foreignAppRefNames !== undefined && { foreignAppRefNames: opts.foreignAppRefNames }),
91
91
  ...(opts.foreignElementRefNames !== undefined && { foreignElementRefNames: opts.foreignElementRefNames }),
92
92
  ...(opts.foreignTaskRefNames !== undefined && { foreignTaskRefNames: opts.foreignTaskRefNames }),
93
+ ...(opts.foreignAppRefNamespaces !== undefined && { foreignAppRefNamespaces: opts.foreignAppRefNamespaces }),
94
+ ...(opts.foreignElementRefNamespaces !== undefined && { foreignElementRefNamespaces: opts.foreignElementRefNamespaces }),
93
95
  ...(opts.foreignFieldRefsById !== undefined && { foreignFieldRefsById: opts.foreignFieldRefsById }),
94
96
  ...(opts.foreignTableRefsById !== undefined && { foreignTableRefsById: opts.foreignTableRefsById }),
95
97
  ...(opts.foreignSearchTableRefsByName !== undefined && {
@@ -91,7 +91,14 @@ export function skillToTf(entity, ctx) {
91
91
  type: elementum.type ?? "CUSTOM",
92
92
  };
93
93
  if (elementum.properties !== undefined) {
94
- attrs["properties"] = JSON.stringify(elementum.properties);
94
+ // Same shape ei exports: jsonencode({ ... }) of the JSON object, not a
95
+ // quoted JSON string. A quoted string still applies, but it does not match
96
+ // the export and hides a properties round-trip gap. JSON.stringify drops
97
+ // undefined members the way the previous quoted-JSON path did; leaving
98
+ // them in the object makes render throw.
99
+ // eslint-disable-next-line no-restricted-syntax -- properties is an opaque JSON object, same normalization as from-tf.
100
+ const plain = JSON.parse(JSON.stringify(elementum.properties));
101
+ attrs["properties"] = expr.jsonencode(plain);
95
102
  }
96
103
  if (elementum.accessPolicy !== undefined)
97
104
  Object.assign(attrs, skillAccessPolicyToTf(elementum.accessPolicy, ctx.orgRefs));
@@ -119,14 +126,17 @@ export function skillToTf(entity, ctx) {
119
126
  foreignAppRef: (l, n, ns) => ctx.orgRefs.foreignApp(l, n, ns),
120
127
  foreignElementRef: (l, n, ns) => ctx.orgRefs.foreignElement(l, n, ns),
121
128
  foreignTaskRef: (l, n) => ctx.orgRefs.rawLookup("elementum_task", l, n),
122
- foreignFieldRef: (t, l, o, n) => ctx.orgRefs.foreignField(t, l, o, n),
129
+ foreignFieldRef: (t, l, o, n, extra) => ctx.orgRefs.foreignField(t, l, o, n, extra),
123
130
  workspaceAspects: ctx.workspaceAspects,
124
131
  serviceAccountRef: (_label, serviceAccountName) => serviceAccountValue(serviceAccountName, ctx),
125
- tableSearchTableRef: (label, tableRefName, tableName, searchTableName) => {
132
+ tableSearchTableRef: (label, tableRefName, tableName, searchTableName, searchTableId) => {
126
133
  const tableLabel = sanitizeName(tableRefName);
127
134
  const tableId = expr.dataAttr("elementum_table", tableLabel, ["id"]);
128
135
  ctx.orgRefs.rawLookup("elementum_table", tableLabel, tableName);
129
- ctx.orgRefs.rawLookup("elementum_search_table", label, searchTableName, { table_id: tableId });
136
+ ctx.orgRefs.rawLookup("elementum_search_table", label, searchTableName, {
137
+ table_id: tableId,
138
+ ...(searchTableId !== undefined && searchTableId !== "" ? { id: searchTableId } : {}),
139
+ });
130
140
  return expr.dataAttr("elementum_search_table", label, ["id"]);
131
141
  },
132
142
  foreignAutomationRef: (tfLabel, parentKind, _parentRefName, parentName, automationName) => {
@@ -94,6 +94,8 @@ export interface NormalizedSkillTool {
94
94
  readonly searchTableKey?: string;
95
95
  /** Foreign table lookup name when search_table_id is data.elementum_search_table. */
96
96
  readonly searchTableName?: string;
97
+ /** Pinned search-table id when the data source names more than one row. */
98
+ readonly searchTableId?: string;
97
99
  /** Display name of the owning organization table for a table-owned search table. */
98
100
  readonly searchTableOwnerName?: string;
99
101
  /** Canonical catalog refName of the owning organization table, when known. */