@elementumai/edk 0.9.18 → 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 (219) hide show
  1. package/README.md +154 -9
  2. package/dist-sdk/src/catalog/factories.d.ts +35 -1
  3. package/dist-sdk/src/catalog/factories.js +36 -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/org.d.ts +39 -1
  9. package/dist-sdk/src/catalog/org.js +460 -50
  10. package/dist-sdk/src/catalog/render.js +6 -6
  11. package/dist-sdk/src/catalog/token.js +7 -0
  12. package/dist-sdk/src/catalog/types.d.ts +44 -1
  13. package/dist-sdk/src/catalog/types.js +13 -0
  14. package/dist-sdk/src/core/triggers/on-demand.d.ts +39 -3
  15. package/dist-sdk/src/core/triggers/on-demand.js +10 -2
  16. package/dist-sdk/src/engine/build/context.d.ts +1 -1
  17. package/dist-sdk/src/engine/ei/run.d.ts +149 -0
  18. package/dist-sdk/src/engine/ei/run.js +1132 -0
  19. package/dist-sdk/src/engine/logging.d.ts +17 -0
  20. package/dist-sdk/src/engine/logging.js +18 -0
  21. package/dist-sdk/src/engine/pull/ref-only.d.ts +5 -0
  22. package/dist-sdk/src/engine/pull/ref-only.js +64 -27
  23. package/dist-sdk/src/engine/pull/result-output.d.ts +8 -0
  24. package/dist-sdk/src/engine/pull/result-output.js +88 -4
  25. package/dist-sdk/src/engine/tf/expr.js +39 -14
  26. package/dist-sdk/src/engine/tf/index.d.ts +3 -3
  27. package/dist-sdk/src/engine/tf/index.js +2 -2
  28. package/dist-sdk/src/engine/tf/labels.d.ts +8 -0
  29. package/dist-sdk/src/engine/tf/labels.js +13 -0
  30. package/dist-sdk/src/engine/tf/model.d.ts +22 -1
  31. package/dist-sdk/src/engine/tf/parse.d.ts +19 -0
  32. package/dist-sdk/src/engine/tf/parse.js +197 -10
  33. package/dist-sdk/src/engine/tf/render.d.ts +4 -2
  34. package/dist-sdk/src/engine/tf/render.js +41 -7
  35. package/dist-sdk/src/engine/validation.d.ts +39 -0
  36. package/dist-sdk/src/engine/validation.js +85 -0
  37. package/dist-sdk/src/engine/workspace/loader.js +49 -12
  38. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +11 -1
  39. package/dist-sdk/src/entities/access-policy/from-tf.js +6 -1
  40. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +11 -0
  41. package/dist-sdk/src/entities/access-policy/to-tf.js +16 -6
  42. package/dist-sdk/src/entities/agent/build.d.ts +4 -16
  43. package/dist-sdk/src/entities/agent/build.js +40 -5
  44. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +4 -2
  45. package/dist-sdk/src/entities/agent/to-tf.js +6 -3
  46. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +2 -0
  47. package/dist-sdk/src/entities/agent-tool/from-tf.js +7 -1
  48. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
  49. package/dist-sdk/src/entities/agent-tool/to-tf.js +29 -6
  50. package/dist-sdk/src/entities/app/build.d.ts +98 -19
  51. package/dist-sdk/src/entities/app/build.js +51 -19
  52. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +22 -1
  53. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -0
  54. package/dist-sdk/src/entities/app/from-tf.js +11 -5
  55. package/dist-sdk/src/entities/app/index.d.ts +6 -5
  56. package/dist-sdk/src/entities/app/index.js +2 -0
  57. package/dist-sdk/src/entities/app/module.js +18 -2
  58. package/dist-sdk/src/entities/app/to-tf.js +21 -11
  59. package/dist-sdk/src/entities/automation/build.d.ts +49 -6
  60. package/dist-sdk/src/entities/automation/build.js +163 -19
  61. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +24 -1
  62. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +320 -39
  63. package/dist-sdk/src/entities/automation/from-tf.d.ts +28 -6
  64. package/dist-sdk/src/entities/automation/from-tf.js +563 -74
  65. package/dist-sdk/src/entities/automation/generated/task-output-contracts.d.ts +33 -0
  66. package/dist-sdk/src/entities/automation/generated/task-output-contracts.js +183 -0
  67. package/dist-sdk/src/entities/automation/index.d.ts +2 -2
  68. package/dist-sdk/src/entities/automation/index.js +1 -1
  69. package/dist-sdk/src/entities/automation/module.d.ts +2 -0
  70. package/dist-sdk/src/entities/automation/module.js +93 -8
  71. package/dist-sdk/src/entities/automation/output-field-types.d.ts +7 -0
  72. package/dist-sdk/src/entities/automation/output-field-types.js +36 -0
  73. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +9 -0
  74. package/dist-sdk/src/entities/automation/output-key-wire-name.js +13 -0
  75. package/dist-sdk/src/entities/automation/script-code.d.ts +17 -0
  76. package/dist-sdk/src/entities/automation/script-code.js +91 -5
  77. package/dist-sdk/src/entities/automation/system-ref-name.d.ts +16 -0
  78. package/dist-sdk/src/entities/automation/system-ref-name.js +48 -0
  79. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +17 -0
  80. package/dist-sdk/src/entities/automation/task-output-labels.js +47 -0
  81. package/dist-sdk/src/entities/automation/tasks.d.ts +53 -4
  82. package/dist-sdk/src/entities/automation/tasks.js +38 -9
  83. package/dist-sdk/src/entities/automation/to-tf.d.ts +4 -0
  84. package/dist-sdk/src/entities/automation/to-tf.js +647 -167
  85. package/dist-sdk/src/entities/automation/triggers.d.ts +4 -2
  86. package/dist-sdk/src/entities/automation/triggers.js +4 -0
  87. package/dist-sdk/src/entities/automation/types.js +1 -0
  88. package/dist-sdk/src/entities/chart/from-tf.js +33 -17
  89. package/dist-sdk/src/entities/chart/module.js +3 -1
  90. package/dist-sdk/src/entities/chart/printer.d.ts +1 -0
  91. package/dist-sdk/src/entities/chart/printer.js +26 -16
  92. package/dist-sdk/src/entities/chart/rebind-owner.d.ts +3 -0
  93. package/dist-sdk/src/entities/chart/rebind-owner.js +42 -0
  94. package/dist-sdk/src/entities/chart/to-tf.js +21 -12
  95. package/dist-sdk/src/entities/dashboard/build.d.ts +4 -0
  96. package/dist-sdk/src/entities/dashboard/from-tf.js +15 -4
  97. package/dist-sdk/src/entities/dashboard/to-tf.d.ts +2 -0
  98. package/dist-sdk/src/entities/dashboard/to-tf.js +13 -0
  99. package/dist-sdk/src/entities/dashboard-widget/module.js +4 -0
  100. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +72 -30
  101. package/dist-sdk/src/entities/dynamic-layout/dialect.d.ts +3 -0
  102. package/dist-sdk/src/entities/dynamic-layout/dialect.js +5 -0
  103. package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +9 -6
  104. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +188 -26
  105. package/dist-sdk/src/entities/dynamic-layout/module.js +4 -1
  106. package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +5 -1
  107. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +254 -23
  108. package/dist-sdk/src/entities/element/build.d.ts +33 -13
  109. package/dist-sdk/src/entities/element/build.js +5 -1
  110. package/dist-sdk/src/entities/element/from-tf.d.ts +12 -0
  111. package/dist-sdk/src/entities/element/from-tf.js +64 -3
  112. package/dist-sdk/src/entities/element/index.d.ts +5 -2
  113. package/dist-sdk/src/entities/element/index.js +2 -0
  114. package/dist-sdk/src/entities/element/module.js +11 -3
  115. package/dist-sdk/src/entities/element/to-tf.js +20 -2
  116. package/dist-sdk/src/entities/field/build.d.ts +14 -1
  117. package/dist-sdk/src/entities/field/build.js +3 -0
  118. package/dist-sdk/src/entities/field/from-tf.d.ts +3 -0
  119. package/dist-sdk/src/entities/field/from-tf.js +50 -1
  120. package/dist-sdk/src/entities/field/media-types.d.ts +6 -0
  121. package/dist-sdk/src/entities/field/media-types.js +30 -0
  122. package/dist-sdk/src/entities/field/module.js +1 -0
  123. package/dist-sdk/src/entities/field/to-tf.d.ts +23 -2
  124. package/dist-sdk/src/entities/field/to-tf.js +142 -22
  125. package/dist-sdk/src/entities/file-reader/from-tf.js +14 -5
  126. package/dist-sdk/src/entities/file-reader/module.js +1 -0
  127. package/dist-sdk/src/entities/file-reader/types.d.ts +2 -0
  128. package/dist-sdk/src/entities/file-reader/types.js +1 -1
  129. package/dist-sdk/src/entities/portal/build.d.ts +26 -0
  130. package/dist-sdk/src/entities/portal/build.js +37 -0
  131. package/dist-sdk/src/entities/portal/from-tf.d.ts +27 -0
  132. package/dist-sdk/src/entities/portal/from-tf.js +75 -0
  133. package/dist-sdk/src/entities/portal/index.d.ts +1 -0
  134. package/dist-sdk/src/entities/portal/index.js +1 -0
  135. package/dist-sdk/src/entities/portal/module.d.ts +3 -0
  136. package/dist-sdk/src/entities/portal/module.js +28 -0
  137. package/dist-sdk/src/entities/portal/to-tf.d.ts +12 -0
  138. package/dist-sdk/src/entities/portal/to-tf.js +73 -0
  139. package/dist-sdk/src/entities/portal/types.d.ts +1 -0
  140. package/dist-sdk/src/entities/portal/types.js +1 -0
  141. package/dist-sdk/src/entities/relationship/from-tf.d.ts +8 -1
  142. package/dist-sdk/src/entities/relationship/from-tf.js +53 -10
  143. package/dist-sdk/src/entities/relationship/module.js +2 -0
  144. package/dist-sdk/src/entities/relationship/pair-check.d.ts +7 -0
  145. package/dist-sdk/src/entities/relationship/pair-check.js +68 -0
  146. package/dist-sdk/src/entities/relationship/to-tf.d.ts +10 -0
  147. package/dist-sdk/src/entities/relationship/to-tf.js +31 -13
  148. package/dist-sdk/src/entities/search-table/module.js +1 -0
  149. package/dist-sdk/src/entities/search-table/to-tf.d.ts +1 -0
  150. package/dist-sdk/src/entities/search-table/to-tf.js +1 -1
  151. package/dist-sdk/src/entities/service-account/build.d.ts +15 -2
  152. package/dist-sdk/src/entities/service-account/from-tf.d.ts +2 -4
  153. package/dist-sdk/src/entities/service-account/from-tf.js +17 -5
  154. package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +56 -0
  155. package/dist-sdk/src/entities/service-account/role-fidelity.js +243 -0
  156. package/dist-sdk/src/entities/service-account/to-tf.d.ts +14 -0
  157. package/dist-sdk/src/entities/service-account/to-tf.js +17 -0
  158. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +1 -1
  159. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +5 -2
  160. package/dist-sdk/src/entities/shared/filters/ast.d.ts +15 -2
  161. package/dist-sdk/src/entities/shared/filters/index.d.ts +25 -2
  162. package/dist-sdk/src/entities/shared/filters/index.js +38 -5
  163. package/dist-sdk/src/entities/shared/filters/print.js +31 -3
  164. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +25 -3
  165. package/dist-sdk/src/entities/shared/filters/tf-codec.js +51 -15
  166. package/dist-sdk/src/entities/shared/filters/types.d.ts +22 -5
  167. package/dist-sdk/src/entities/shared/foreign-ref.d.ts +16 -0
  168. package/dist-sdk/src/entities/shared/foreign-ref.js +17 -1
  169. package/dist-sdk/src/entities/shared/tool-field-ref.js +6 -9
  170. package/dist-sdk/src/entities/shared/types/field-types.d.ts +10 -5
  171. package/dist-sdk/src/entities/shared/types/field-types.js +4 -0
  172. package/dist-sdk/src/entities/skill/access-policy.d.ts +17 -0
  173. package/dist-sdk/src/entities/skill/access-policy.js +101 -0
  174. package/dist-sdk/src/entities/skill/build.d.ts +3 -0
  175. package/dist-sdk/src/entities/skill/build.js +3 -0
  176. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +4 -1
  177. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +23 -1
  178. package/dist-sdk/src/entities/skill/from-tf.d.ts +2 -0
  179. package/dist-sdk/src/entities/skill/from-tf.js +70 -22
  180. package/dist-sdk/src/entities/skill/index.d.ts +2 -0
  181. package/dist-sdk/src/entities/skill/index.js +1 -0
  182. package/dist-sdk/src/entities/skill/input-coverage.d.ts +7 -0
  183. package/dist-sdk/src/entities/skill/input-coverage.js +11 -0
  184. package/dist-sdk/src/entities/skill/module.js +1 -0
  185. package/dist-sdk/src/entities/skill/to-tf.d.ts +2 -2
  186. package/dist-sdk/src/entities/skill/to-tf.js +19 -6
  187. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
  188. package/dist-sdk/src/entities/skill-tool/from-tf.js +8 -2
  189. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +2 -2
  190. package/dist-sdk/src/entities/skill-tool/to-tf.js +29 -6
  191. package/dist-sdk/src/entities/table/catalog.d.ts +14 -0
  192. package/dist-sdk/src/entities/table/catalog.js +66 -0
  193. package/dist-sdk/src/entities/table/module.js +2 -1
  194. package/dist-sdk/src/entities/table/to-tf.js +5 -5
  195. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +89 -0
  196. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +277 -0
  197. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +51 -0
  198. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +360 -0
  199. package/dist-sdk/src/entities/view/agent-view-layout.d.ts +151 -0
  200. package/dist-sdk/src/entities/view/agent-view-layout.js +21 -0
  201. package/dist-sdk/src/entities/view/from-tf.d.ts +6 -3
  202. package/dist-sdk/src/entities/view/from-tf.js +161 -14
  203. package/dist-sdk/src/entities/view/module.js +30 -3
  204. package/dist-sdk/src/entities/view/to-tf.d.ts +24 -2
  205. package/dist-sdk/src/entities/view/to-tf.js +95 -9
  206. package/dist-sdk/src/entities/view/types.d.ts +4 -15
  207. package/dist-sdk/src/entities/view/types.js +17 -15
  208. package/dist-sdk/src/entities/widget/build.d.ts +16 -1
  209. package/dist-sdk/src/entities/widget/build.js +11 -1
  210. package/dist-sdk/src/entities/widget/to-tf.js +36 -10
  211. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +38 -10
  212. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  213. package/dist-sdk/src/graph/index.d.ts +54 -0
  214. package/dist-sdk/src/graph/index.js +30 -0
  215. package/dist-sdk/src/graph/modules.js +2 -0
  216. package/dist-sdk/src/graph/types.d.ts +133 -2
  217. package/dist-sdk/src/internal/sdk-package.d.ts +1 -1
  218. package/dist-sdk/src/internal/sdk-package.js +1 -0
  219. package/package.json +11 -1
@@ -38,6 +38,7 @@ import { printFilter as printCanonicalFilter } from "../../shared/filters/print.
38
38
  import { UNRESOLVED_FIELD_MARKER } from "../../shared/ref.js";
39
39
  import { UNRESOLVED_REFERENCE_MARKER } from "../filter.js";
40
40
  import { INJECTED_TS_IGNORE, scriptFileText } from "../script-code.js";
41
+ import { isRequiredSecret } from "../tasks.js";
41
42
  import { unresolvedReferenceComment } from "../../../engine/pull/ref-only.js";
42
43
  // ---------------------------------------------------------------------------
43
44
  // Factory name mapping — decoded task `factory` → v2 factory function name.
@@ -70,6 +71,7 @@ const TASK_FACTORY_V2 = {
70
71
  sendEmail: "sendEmail",
71
72
  saveAttachment: "saveAttachment",
72
73
  userSearch: "userSearch",
74
+ userGroupSearch: "userGroupSearch",
73
75
  groupSearch: "userGroupSearch",
74
76
  initiateCall: "initiateCall",
75
77
  approvalChain: "approvalChain",
@@ -119,16 +121,222 @@ export function preserveAuthoredAutomationRevision(freshSource, existingSource)
119
121
  return freshSource;
120
122
  return freshSource.replace(REVISION_PROPERTY, (_line, prefix) => `${prefix}${JSON.stringify(authored)},`);
121
123
  }
124
+ /** Index just past the string literal opening at `i` (`'` or `"`), or -1 when unterminated. */
125
+ function skipQuoted(source, i) {
126
+ const q = source[i];
127
+ for (let j = i + 1; j < source.length; j++) {
128
+ const ch = source[j];
129
+ if (ch === "\\") {
130
+ j++;
131
+ continue;
132
+ }
133
+ if (ch === q)
134
+ return j + 1;
135
+ if (ch === "\n")
136
+ return -1;
137
+ }
138
+ return -1;
139
+ }
140
+ /** Index just past the template literal opening at `i`, skipping `${...}` holes, or -1. */
141
+ function skipTemplate(source, i) {
142
+ for (let j = i + 1; j < source.length; j++) {
143
+ const ch = source[j];
144
+ if (ch === "\\") {
145
+ j++;
146
+ continue;
147
+ }
148
+ if (ch === "`")
149
+ return j + 1;
150
+ if (ch === "$" && source[j + 1] === "{") {
151
+ const end = skipBalanced(source, j + 1);
152
+ if (end < 0)
153
+ return -1;
154
+ j = end - 1;
155
+ }
156
+ }
157
+ return -1;
158
+ }
159
+ /** Index just past the regex literal opening at `i`, or -1. */
160
+ function skipRegex(source, i) {
161
+ let inClass = false;
162
+ for (let j = i + 1; j < source.length; j++) {
163
+ const ch = source[j];
164
+ if (ch === "\\") {
165
+ j++;
166
+ continue;
167
+ }
168
+ if (ch === "\n")
169
+ return -1;
170
+ if (inClass) {
171
+ if (ch === "]")
172
+ inClass = false;
173
+ }
174
+ else if (ch === "[") {
175
+ inClass = true;
176
+ }
177
+ else if (ch === "/") {
178
+ let k = j + 1;
179
+ while (k < source.length && /[a-z]/i.test(source[k]))
180
+ k++;
181
+ return k;
182
+ }
183
+ }
184
+ return -1;
185
+ }
186
+ /** Keyword operators after which an expression, and so a regex literal, can begin. */
187
+ const REGEX_PRECEDING_KEYWORDS = new Set([
188
+ "return", "typeof", "instanceof", "in", "of", "new", "delete", "void", "throw", "case", "do", "else", "yield", "await",
189
+ ]);
190
+ const WORD_CHAR = /[\w$\u0080-￿]/;
122
191
  /**
123
- * Extract a string-literal (or `+`-concatenated literals) description from
124
- * authored automation source. Pull reprints often omit description entirely
125
- * because Go export cannot read it back from the platform today.
192
+ * Walk TypeScript source token by token, skipping comments, strings, template
193
+ * literals and regex literals. `visit` sees the first character of every
194
+ * other token (each punctuator, word, number, string or template literal),
195
+ * with the bracket depth relative to `start`: an opening bracket is seen at
196
+ * its inner depth and a closing bracket at its outer depth, so both brackets
197
+ * of a group at `start` are seen at depth 1 and 0. `visit` returns true to
198
+ * stop. Returns the index where the walk stopped, or -1 on malformed input or
199
+ * end of source.
200
+ *
201
+ * Regex or division: `/` starts a regex literal only where an expression can
202
+ * begin, i.e. at the start of input, after a punctuator other than a closing
203
+ * bracket (`( , = : [ ! & | ? { ; + - * % < > ~ ^`, their compound forms,
204
+ * `=>`, prefix `++`/`--`), or after a keyword operator (`return`, `typeof`,
205
+ * …). After `)`, `]`, `}`, an identifier, a property name (even a keyword
206
+ * one, as in `sizes.in`), a number, a postfix `++`/`--`, or a string,
207
+ * template or regex literal, it divides. Treating `/` after `}` (and `)`) as
208
+ * division misreads a regex that opens a statement after a block or an
209
+ * `if (…)` condition; that is the accepted trade-off of not running a real
210
+ * parser, and such a statement is rare in pulled source.
126
211
  */
127
- export function extractAuthoredAutomationDescription(source) {
128
- const header = /(?:^|\n)[ \t]*description[ \t]*:/m.exec(source);
129
- if (header === null || header.index === undefined)
212
+ function walkSource(source, start, visit) {
213
+ let depth = 0;
214
+ let regexAllowed = true;
215
+ let afterDot = false;
216
+ for (let i = start; i < source.length;) {
217
+ const ch = source[i];
218
+ const next = source[i + 1];
219
+ if (ch === "/" && next === "/") {
220
+ const eol = source.indexOf("\n", i);
221
+ i = eol < 0 ? source.length : eol + 1;
222
+ continue;
223
+ }
224
+ if (ch === "/" && next === "*") {
225
+ const close = source.indexOf("*/", i + 2);
226
+ if (close < 0)
227
+ return -1;
228
+ i = close + 2;
229
+ continue;
230
+ }
231
+ if (/\s/.test(ch)) {
232
+ i++;
233
+ continue;
234
+ }
235
+ if (ch === '"' || ch === "'" || ch === "`") {
236
+ if (visit(i, depth))
237
+ return i;
238
+ const end = ch === "`" ? skipTemplate(source, i) : skipQuoted(source, i);
239
+ if (end < 0)
240
+ return -1;
241
+ i = end;
242
+ regexAllowed = false;
243
+ afterDot = false;
244
+ continue;
245
+ }
246
+ if (WORD_CHAR.test(ch)) {
247
+ if (visit(i, depth))
248
+ return i;
249
+ let end = i + 1;
250
+ while (end < source.length && WORD_CHAR.test(source[end]))
251
+ end++;
252
+ // A property name (after `.`) is never a keyword operator.
253
+ regexAllowed = !afterDot && REGEX_PRECEDING_KEYWORDS.has(source.slice(i, end));
254
+ afterDot = false;
255
+ i = end;
256
+ continue;
257
+ }
258
+ if (ch === "/" && regexAllowed) {
259
+ const end = skipRegex(source, i);
260
+ if (end < 0)
261
+ return -1;
262
+ i = end;
263
+ regexAllowed = false;
264
+ afterDot = false;
265
+ continue;
266
+ }
267
+ if ((ch === "+" || ch === "-") && next === ch) {
268
+ if (visit(i, depth))
269
+ return i;
270
+ // Postfix after an operand keeps the operand's role; prefix begins one.
271
+ i += 2;
272
+ afterDot = false;
273
+ continue;
274
+ }
275
+ if (ch === "{" || ch === "(" || ch === "[")
276
+ depth++;
277
+ if (ch === "}" || ch === ")" || ch === "]") {
278
+ depth--;
279
+ if (depth < 0)
280
+ return -1;
281
+ }
282
+ if (visit(i, depth))
283
+ return i;
284
+ regexAllowed = !(ch === "}" || ch === ")" || ch === "]" || ch === ".");
285
+ afterDot = ch === ".";
286
+ i++;
287
+ }
288
+ return -1;
289
+ }
290
+ /** Index just past the bracket group opening at `open`, or -1. */
291
+ function skipBalanced(source, open) {
292
+ const end = walkSource(source, open, (index, depth) => depth === 0 && index > open);
293
+ return end < 0 ? -1 : end + 1;
294
+ }
295
+ /**
296
+ * Top-level properties of the options object passed to `automation({ ... })`.
297
+ * Keys nested deeper (a step's or trigger input's `description` inside the
298
+ * actions chain) are not included, whatever their order relative to `actions`.
299
+ * Undefined when no `automation({` call is found.
300
+ */
301
+ function automationOptionProperties(source) {
302
+ let objectStart = -1;
303
+ walkSource(source, 0, (index) => {
304
+ const match = /^automation\s*\(\s*\{/.exec(source.slice(index, index + 64));
305
+ if (match === null || /[\w$.]/.test(source[index - 1] ?? ""))
306
+ return false;
307
+ objectStart = index + match[0].length - 1;
308
+ return true;
309
+ });
310
+ if (objectStart < 0)
130
311
  return undefined;
131
- let i = header.index + header[0].length;
312
+ const properties = [];
313
+ let expectKey = true;
314
+ const end = walkSource(source, objectStart, (index, depth) => {
315
+ if (depth === 0)
316
+ return true;
317
+ if (index === objectStart)
318
+ return false;
319
+ if (depth !== 1)
320
+ return false;
321
+ const ch = source[index];
322
+ if (ch === ",") {
323
+ expectKey = true;
324
+ return false;
325
+ }
326
+ if (!expectKey)
327
+ return false;
328
+ expectKey = false;
329
+ const key = /^(?:([A-Za-z_$][\w$]*)|"([^"\\\n]*)"|'([^'\\\n]*)')\s*:/.exec(source.slice(index, index + 256));
330
+ if (key !== null) {
331
+ properties.push({ key: key[1] ?? key[2] ?? key[3], keyStart: index, valueStart: index + key[0].length });
332
+ }
333
+ return false;
334
+ });
335
+ return { properties, complete: end >= 0 };
336
+ }
337
+ /** A string literal or `+`-concatenation of string literals starting at `start`, or undefined. */
338
+ function parseStringConcat(source, start) {
339
+ let i = start;
132
340
  const parts = [];
133
341
  while (i < source.length) {
134
342
  while (i < source.length && /\s/.test(source[i]))
@@ -147,6 +355,8 @@ export function extractAuthoredAutomationDescription(source) {
147
355
  i += 2;
148
356
  continue;
149
357
  }
358
+ if (q === "`" && ch === "$" && source[i + 1] === "{")
359
+ return undefined;
150
360
  if (ch === q)
151
361
  break;
152
362
  raw += ch;
@@ -174,6 +384,21 @@ export function extractAuthoredAutomationDescription(source) {
174
384
  const joined = parts.join("");
175
385
  return joined === "" ? undefined : joined;
176
386
  }
387
+ /**
388
+ * Extract a string-literal (or `+`-concatenated literals) description from
389
+ * authored automation source. Pull reprints often omit description entirely
390
+ * because Go export cannot read it back from the platform today.
391
+ *
392
+ * Only the automation's own `description` counts: the top-level key of the
393
+ * `automation({ ... })` options object, in any key order. A notification
394
+ * step's or on-demand input's `description` inside the actions chain is not
395
+ * the automation's.
396
+ */
397
+ export function extractAuthoredAutomationDescription(source) {
398
+ // A description read before an unscannable part is still the top-level one.
399
+ const description = automationOptionProperties(source)?.properties.find((property) => property.key === "description");
400
+ return description === undefined ? undefined : parseStringConcat(source, description.valueStart);
401
+ }
177
402
  /**
178
403
  * Keep a non-empty authored `description` across pull.
179
404
  *
@@ -182,24 +407,42 @@ export function extractAuthoredAutomationDescription(source) {
182
407
  * drops the attribute. Without this merge, pull → reprint → build clears
183
408
  * description from config while state still has it, forcing an adopt update.
184
409
  * Prefer a freshly pulled description when present; only reinstate the
185
- * authored value when the fresh source omitted it.
410
+ * authored value when the fresh source omitted it. Both checks and the
411
+ * insertion point are scoped to the automation's own options object, so a
412
+ * step's `description` neither hides nor supplies the automation's.
413
+ *
414
+ * Fail safe: when the fresh source cannot be scanned to its end (for example
415
+ * a pulled script body the scanner cannot tokenize), the authored description
416
+ * is still restored once the scan has reached the top-level `actions` key.
417
+ * The pull printer emits every other option, description included, before
418
+ * `actions`, so at that point the fresh source provably has no description of
419
+ * its own and the insertion point was read exactly. A scan that stops before
420
+ * `actions` leaves the fresh source unchanged.
186
421
  */
187
422
  export function preserveAuthoredAutomationDescription(freshSource, existingSource) {
188
423
  const authored = extractAuthoredAutomationDescription(existingSource);
189
424
  if (authored === undefined)
190
425
  return freshSource;
191
- if (extractAuthoredAutomationDescription(freshSource) !== undefined)
426
+ const options = automationOptionProperties(freshSource);
427
+ if (options === undefined)
192
428
  return freshSource;
193
- const revisionLine = REVISION_PROPERTY.exec(freshSource);
194
- if (revisionLine !== null && revisionLine.index !== undefined) {
195
- const insertAt = revisionLine.index + revisionLine[0].length;
196
- const indent = /^[ \t]*/.exec(revisionLine[0])?.[0] ?? " ";
197
- return `${freshSource.slice(0, insertAt)}\n${indent}description: ${JSON.stringify(authored)},${freshSource.slice(insertAt)}`;
198
- }
199
- const nameLine = /^([ \t]*name[ \t]*:[ \t]*)(["'`])([^"'`\r\n]*)\2[ \t]*,?[ \t]*$/m.exec(freshSource);
200
- if (nameLine !== null && nameLine.index !== undefined) {
201
- const insertAt = nameLine.index + nameLine[0].length;
202
- const indent = /^[ \t]*/.exec(nameLine[0])?.[0] ?? " ";
429
+ const { properties } = options;
430
+ if (properties.some((property) => property.key === "description"))
431
+ return freshSource;
432
+ if (!options.complete && !properties.some((property) => property.key === "actions"))
433
+ return freshSource;
434
+ for (const key of ["revision", "name"]) {
435
+ const property = properties.find((candidate) => candidate.key === key);
436
+ if (property === undefined)
437
+ continue;
438
+ const lineStart = freshSource.lastIndexOf("\n", property.keyStart) + 1;
439
+ const lineEnd = freshSource.indexOf("\n", property.keyStart);
440
+ const line = freshSource.slice(lineStart, lineEnd < 0 ? freshSource.length : lineEnd);
441
+ // Insert on the line after a single-line `key: "literal",` property only.
442
+ if (!/^[ \t]*[\w$"']+[ \t]*:[ \t]*(["'`])[^"'`\r\n]*\1[ \t]*,?[ \t]*$/.test(line))
443
+ continue;
444
+ const insertAt = lineStart + line.length;
445
+ const indent = /^[ \t]*/.exec(line)?.[0] ?? " ";
203
446
  return `${freshSource.slice(0, insertAt)}\n${indent}description: ${JSON.stringify(authored)},${freshSource.slice(insertAt)}`;
204
447
  }
205
448
  return freshSource;
@@ -219,10 +462,21 @@ function emptyImports() {
219
462
  usesOrg: false,
220
463
  usesScriptInput: false,
221
464
  usesRefType: false,
465
+ usesTableSearchTableRef: false,
222
466
  };
223
467
  }
224
468
  /** Folder (inside the automations folder) that holds printed script files. */
225
469
  export const SCRIPT_FILES_DIR = "scripts";
470
+ /**
471
+ * Key of the placeholder printed for a forEach item reference to a sibling
472
+ * loop (no authored form, #1320). Build fails on it; re-pull archives a file
473
+ * that still carries it.
474
+ */
475
+ export const UNRESOLVED_FOR_EACH_ITEM_KEY = "__edkUnresolvedForEachItem";
476
+ /** True when automation source still carries the unbuildable sibling-loop placeholder. */
477
+ export function hasUnresolvedForEachItem(source) {
478
+ return source.includes(`${UNRESOLVED_FOR_EACH_ITEM_KEY}:`);
479
+ }
226
480
  /** Reprint extract-time owner handles as the authored catalog key. */
227
481
  function catalogOwnerHandle(state, appHandle) {
228
482
  if (appHandle === state.ownerHandle || appHandle === state.appRefName)
@@ -449,6 +703,9 @@ function renderHeader(ast, imports, _opts) {
449
703
  return alias ? `${name} as ${alias}` : name;
450
704
  });
451
705
  lines.push(`import { ${sortedSpecifiers.join(", ")} } from "${sdkPackageSpecifier("automations")}";`);
706
+ if (imports.usesTableSearchTableRef) {
707
+ lines.push(`import { tableSearchTableRef } from "${sdkPackageSpecifier("catalog")}";`);
708
+ }
452
709
  if (imports.usesTemplate || imports.usesUnresolvedField || imports.usesUnsafePlatformId || imports.usesRefType) {
453
710
  const coreNamed = [];
454
711
  if (imports.usesTemplate)
@@ -483,7 +740,10 @@ function printTrigger(trigger, state) {
483
740
  if (i.multiple)
484
741
  parts.push(`multiple: ${i.multiple}`);
485
742
  if (i.type !== "record" && i.defaultValue !== undefined && i.defaultValue !== null) {
486
- parts.push(`defaultValue: ${literalJson(i.defaultValue)}`);
743
+ const user = i.defaultValue;
744
+ parts.push(`defaultValue: ${user.kind === "user" && typeof user.email === "string"
745
+ ? printRef(i.defaultValue, state, DEFAULT_CTX)
746
+ : literalJson(i.defaultValue)}`);
487
747
  }
488
748
  if (i.description !== undefined)
489
749
  parts.push(`description: ${quote(i.description)}`);
@@ -1102,6 +1362,10 @@ function printArgValue(name, value, state, indent, refCtx) {
1102
1362
  const calc = trackFactory("calc", state);
1103
1363
  return `${calc}.raw(${quote(value.text)}, ${quote(value.resultType)})`;
1104
1364
  }
1365
+ if (isRequiredSecret(value)) {
1366
+ const fn = trackFactory("requiredSecret", state);
1367
+ return `${fn}(${quote(value.variable)})`;
1368
+ }
1105
1369
  if (isRefExpr(value))
1106
1370
  return printRef(value, state, refCtx);
1107
1371
  if (isFilter(value))
@@ -1225,25 +1489,26 @@ function printRef(ref, state, refCtx) {
1225
1489
  // item" - at build time it binds to whichever loop's replaceForEach
1226
1490
  // pass runs closest to this position, not to any outer ancestor.
1227
1491
  // refCtx.selfTaskRefKeys (accumulated by formatForEach on the way
1228
- // down) holds the full ancestor chain, so checking membership alone
1229
- // is not enough - only the LAST entry is actually addressable as
1230
- // ctx.item here. Live-confirmed (conciergeforfield, sanofi/us): two
1231
- // bugs of this shape. (1) A task nested inside "Matched Message"
1232
- // referenced "Matched Product" - a SIBLING loop, not an ancestor at
1233
- // all. (2) A task nested inside "Matched Message", itself nested
1234
- // inside "Matched Product", referenced "Matched Product" directly -
1235
- // a real ancestor, but not the nearest one, so `ctx.item` there binds
1236
- // to "Matched Message" instead. Both silently attributed the
1237
- // reference to the wrong loop (built HCL pointed at the wrong
1238
- // for_each task's inner.refs, which doesn't carry that key: "Invalid
1239
- // index" on every plan). EDK's authoring model has no primitive for
1240
- // "an outer loop's current item" - same escape shape as taskRef's
1241
- // out-of-scope cases above, not a claim that ctx.actions[...] is
1242
- // actually valid at runtime either.
1492
+ // down) holds the full ancestor chain; only its LAST entry is
1493
+ // addressable as ctx.item. Every other ancestor is addressable by
1494
+ // name as ctx.loops.<name>.item (#1320) - the platform offers and
1495
+ // resolves an outer loop's current item by that loop's task id.
1496
+ // Live-confirmed (conciergeforfield, sanofi/us): a task nested inside
1497
+ // "Matched Message", itself nested inside "Matched Product",
1498
+ // referenced "Matched Product" directly.
1243
1499
  const nearest = refCtx.selfTaskRefKeys?.[refCtx.selfTaskRefKeys.length - 1];
1244
1500
  if (nearest === ref.forEachTask) {
1245
1501
  return printPathAccess(`${ctxName}.item`, ref.path);
1246
1502
  }
1503
+ if (refCtx.selfTaskRefKeys?.includes(ref.forEachTask)) {
1504
+ return printPathAccess(`${ctxName}.loops${safeMember(ref.forEachTask)}.item`, ref.path);
1505
+ }
1506
+ // What's left is a loop that does NOT enclose this task - a sibling
1507
+ // (live on conciergeforfield: a task inside "Matched Message"
1508
+ // referenced a sibling "Matched Product"). The platform never offers
1509
+ // that reference and its validation flags it invalid, so EDK has no
1510
+ // public form for it.
1511
+ //
1247
1512
  // Cannot route this through `ctx.actions[...]` the way the taskRef
1248
1513
  // out-of-scope escapes above do: `ctx.actions` is a Proxy that turns
1249
1514
  // ANY property access into a valid `{ kind: "task", ... }` reference,
@@ -1256,10 +1521,7 @@ function printRef(ref, state, refCtx) {
1256
1521
  // way, but automationToTf's valueToTf recognizes the marker and
1257
1522
  // fails the build loudly instead of building a different accepted
1258
1523
  // reference (review feedback on PR #1097, cursor[bot]).
1259
- const relation = refCtx.selfTaskRefKeys?.includes(ref.forEachTask)
1260
- ? "an outer ancestor forEach, not the nearest enclosing one"
1261
- : "a sibling forEach, not an ancestor";
1262
- return `({ __edkUnresolvedForEachItem: ${quote(ref.forEachTask)}, path: [${ref.path.map(quote).join(", ")}] } as any /* TODO: "${ref.forEachTask}" is ${relation} - EDK cannot express a reference to another loop's current item; re-express by hand before this automation can build */)`;
1524
+ return `({ ${UNRESOLVED_FOR_EACH_ITEM_KEY}: ${quote(ref.forEachTask)}, path: [${ref.path.map(quote).join(", ")}] } as any /* TODO: "${ref.forEachTask}" is a sibling forEach, not an enclosing one - EDK cannot express a reference to a sibling loop's current item; re-express by hand before this automation can build */)`;
1263
1525
  }
1264
1526
  case "variableParamRef":
1265
1527
  return `${ctxName}.variables${safeMember(ref.varTask)}${safeMember(ref.name)}`;
@@ -1318,6 +1580,8 @@ function printRef(ref, state, refCtx) {
1318
1580
  }
1319
1581
  case "userField":
1320
1582
  return `catalog.users.fields${safeMember(ref.fieldKey)}`;
1583
+ case "userGroupField":
1584
+ return `catalog.userGroups.fields${safeMember(ref.fieldKey)}`;
1321
1585
  case "app": {
1322
1586
  if (ref.entityType === undefined || ref.name === undefined) {
1323
1587
  return `catalog.${catalogOwnerHandle(state, ref.appHandle)}`;
@@ -1351,6 +1615,15 @@ function printRef(ref, state, refCtx) {
1351
1615
  case "tableColumn":
1352
1616
  return `catalog.tables${safeMember(ref.tableHandle)}.columns${safeMember(ref.columnKey)}`;
1353
1617
  case "searchTable":
1618
+ if (ref.ownerKind === "table") {
1619
+ state.imports.usesTableSearchTableRef = true;
1620
+ const parts = [`name: ${quote(ref.name ?? ref.tableKey)}`, `parent: ${quote(ref.appHandle)}`];
1621
+ if (ref.parentName !== undefined)
1622
+ parts.push(`parentName: ${quote(ref.parentName)}`);
1623
+ if (ref.id !== undefined)
1624
+ parts.push(`id: ${quote(ref.id)}`);
1625
+ return `tableSearchTableRef({ ${parts.join(", ")} })`;
1626
+ }
1354
1627
  // Search tables are element- or table-owned, never app-owned. Remapping
1355
1628
  // the automation owner's export handle to its authored app refName
1356
1629
  // would bind an unpulled same-handle foreign element's table onto the
@@ -1446,6 +1719,9 @@ function printFilterField(left, state, refCtx = DEFAULT_CTX) {
1446
1719
  if (left.kind === "userField") {
1447
1720
  return `catalog.users.fields${safeMember(left.fieldKey)}`;
1448
1721
  }
1722
+ if (left.kind === "userGroupField") {
1723
+ return `catalog.userGroups.fields${safeMember(left.fieldKey)}`;
1724
+ }
1449
1725
  if (left.kind === "unresolved") {
1450
1726
  // A field placeholder (hint === "field") legitimately round-trips
1451
1727
  // through the field_id wire slot on rebuild (filter.ts's leftDescriptor).
@@ -1537,6 +1813,11 @@ const RESERVED_IDENT = new Set([
1537
1813
  "while", "with", "yield",
1538
1814
  ]);
1539
1815
  function safeKey(name) {
1816
+ // `__proto__: v` and `"__proto__": v` in an object literal both invoke the
1817
+ // prototype setter instead of defining a key; only a computed key defines
1818
+ // an own `__proto__` property.
1819
+ if (name === "__proto__")
1820
+ return `[${quote(name)}]`;
1540
1821
  if (!/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name) || RESERVED_IDENT.has(name)) {
1541
1822
  return quote(name);
1542
1823
  }
@@ -63,6 +63,16 @@ interface DecodeContext {
63
63
  /** Procedure discriminator (`procedureDiscriminator`) → org.ts's disambiguated catalog key, for overloaded same-name procedures. See `procedure-refs.ts`. */
64
64
  readonly procedureKeysByDiscriminator?: ReadonlyMap<string, string>;
65
65
  }
66
+ /**
67
+ * The same outputs as seen from a CALCULATION formula, which addresses a
68
+ * reference by its WorkflowTaskReference name rather than the refs-map
69
+ * display key above (`task-output-labels.ts`'s `TASK_OUTPUT_REFERENCE_NAMES` is the
70
+ * write side). Only the names that differ from their authoring path are
71
+ * listed; the rest already read back correctly.
72
+ */
73
+ export declare const RECORD_SEARCH_CALCULATION_REF_NAME_TO_TS: Readonly<Record<string, readonly string[]>>;
74
+ export declare const AI_SEARCH_TABLE_TASK_REF_SEGMENT_TO_TS: Readonly<Record<string, string>>;
75
+ export declare const TABLE_RECORDS_SEARCH_TASK_REF_SEGMENT_TO_TS: Readonly<Record<string, string>>;
66
76
  export declare function inferredPublishOutputType(value: TfValue, ctx: DecodeContext): {
67
77
  readonly fieldType: string;
68
78
  readonly multiple: boolean;
@@ -80,23 +90,35 @@ export declare function inferredPublishOutputType(value: TfValue, ctx: DecodeCon
80
90
  * driving spurious destroys). Deliberately lenient - tolerant of the exact
81
91
  * conditions that make real extraction fail (zero triggers, an
82
92
  * unrecognized task kind) so it over-collects rather than under-collects.
83
- * More than one trigger is not one of those cases: it throws
84
- * {@link UnsupportedMultiTriggerError} and stops the pull. A false positive
93
+ * More than one trigger throws {@link UnsupportedMultiTriggerError}. The
94
+ * stream extractor records that as a fatal validation, excludes these
95
+ * addresses, and continues so every multi-trigger automation is reported.
96
+ * A false positive
85
97
  * here just leaves one more resource unmanaged; a false negative would
86
98
  * silently destroy a live automation on apply.
87
99
  */
88
100
  export declare function automationOwnedAddresses(doc: TfDocument, automationLabel: string): readonly string[];
89
101
  /**
90
- * Pull stops on this. EDK does not author multi-trigger automations; apps
91
- * should keep one trigger and call the shared logic with a run-automation
92
- * action. Callers that otherwise turn extract failures into skips must
93
- * rethrow it.
102
+ * EDK does not author multi-trigger automations; apps should keep one
103
+ * trigger and call the shared logic with a run-automation action. Stream
104
+ * extraction records every one of these and continues. Direct
105
+ * `automationFromTf` still throws. Callers that turn other extract failures
106
+ * into soft skips must not treat this as one of those skips.
94
107
  */
95
108
  export declare class UnsupportedMultiTriggerError extends EntityTfError {
96
109
  readonly automationName: string;
97
110
  readonly triggerCount: number;
98
111
  constructor(automationName: string, triggerCount: number);
99
112
  }
113
+ /**
114
+ * #1320: a task reads the current item of a loop that doesn't enclose it.
115
+ * Pull skips the automation like any other exclusion, and additionally
116
+ * releases it from state if an earlier pull adopted it: no authored source can
117
+ * ever manage it, so keeping it bound would make the next apply destroy it.
118
+ */
119
+ export declare class ForEachItemOutsideLoopError extends EntityTfError {
120
+ constructor(automationLabel: string, reader: string, loop: string);
121
+ }
100
122
  export interface AutomationFromTfContext {
101
123
  readonly ownerHandle: string;
102
124
  readonly diagnostics: string[];