@elementumai/edk 0.9.19 → 0.9.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/README.md +146 -6
  2. package/dist-sdk/src/catalog/factories.d.ts +24 -1
  3. package/dist-sdk/src/catalog/factories.js +30 -0
  4. package/dist-sdk/src/catalog/from-authoring.d.ts +13 -8
  5. package/dist-sdk/src/catalog/from-authoring.js +34 -9
  6. package/dist-sdk/src/catalog/index.d.ts +2 -2
  7. package/dist-sdk/src/catalog/index.js +2 -2
  8. package/dist-sdk/src/catalog/render.js +6 -6
  9. package/dist-sdk/src/catalog/token.js +7 -0
  10. package/dist-sdk/src/catalog/types.d.ts +34 -1
  11. package/dist-sdk/src/catalog/types.js +11 -0
  12. package/dist-sdk/src/core/triggers/on-demand.d.ts +39 -3
  13. package/dist-sdk/src/core/triggers/on-demand.js +10 -2
  14. package/dist-sdk/src/engine/build/context.d.ts +1 -1
  15. package/dist-sdk/src/engine/ei/run.d.ts +149 -0
  16. package/dist-sdk/src/engine/ei/run.js +1132 -0
  17. package/dist-sdk/src/engine/logging.d.ts +17 -0
  18. package/dist-sdk/src/engine/logging.js +18 -0
  19. package/dist-sdk/src/engine/pull/ref-only.d.ts +5 -0
  20. package/dist-sdk/src/engine/pull/ref-only.js +10 -7
  21. package/dist-sdk/src/engine/pull/result-output.d.ts +6 -0
  22. package/dist-sdk/src/engine/pull/result-output.js +87 -3
  23. package/dist-sdk/src/engine/tf/expr.js +1 -1
  24. package/dist-sdk/src/engine/tf/index.d.ts +2 -2
  25. package/dist-sdk/src/engine/tf/index.js +1 -1
  26. package/dist-sdk/src/engine/tf/labels.d.ts +6 -0
  27. package/dist-sdk/src/engine/tf/labels.js +9 -0
  28. package/dist-sdk/src/engine/tf/model.d.ts +22 -1
  29. package/dist-sdk/src/engine/tf/parse.js +92 -4
  30. package/dist-sdk/src/engine/tf/render.d.ts +4 -2
  31. package/dist-sdk/src/engine/tf/render.js +41 -7
  32. package/dist-sdk/src/engine/validation.d.ts +39 -0
  33. package/dist-sdk/src/engine/validation.js +85 -0
  34. package/dist-sdk/src/entities/access-policy/to-tf.js +5 -2
  35. package/dist-sdk/src/entities/agent/build.d.ts +4 -16
  36. package/dist-sdk/src/entities/agent/build.js +40 -5
  37. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +4 -2
  38. package/dist-sdk/src/entities/agent/to-tf.js +6 -3
  39. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +2 -0
  40. package/dist-sdk/src/entities/agent-tool/from-tf.js +7 -1
  41. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
  42. package/dist-sdk/src/entities/agent-tool/to-tf.js +27 -5
  43. package/dist-sdk/src/entities/app/build.d.ts +89 -20
  44. package/dist-sdk/src/entities/app/build.js +51 -6
  45. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +16 -0
  46. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -0
  47. package/dist-sdk/src/entities/app/from-tf.js +7 -2
  48. package/dist-sdk/src/entities/app/index.d.ts +6 -6
  49. package/dist-sdk/src/entities/app/index.js +1 -0
  50. package/dist-sdk/src/entities/app/module.js +5 -2
  51. package/dist-sdk/src/entities/app/to-tf.js +19 -11
  52. package/dist-sdk/src/entities/automation/build.d.ts +47 -5
  53. package/dist-sdk/src/entities/automation/build.js +137 -20
  54. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +24 -1
  55. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +314 -39
  56. package/dist-sdk/src/entities/automation/from-tf.d.ts +28 -6
  57. package/dist-sdk/src/entities/automation/from-tf.js +428 -48
  58. package/dist-sdk/src/entities/automation/generated/task-output-contracts.d.ts +33 -0
  59. package/dist-sdk/src/entities/automation/generated/task-output-contracts.js +183 -0
  60. package/dist-sdk/src/entities/automation/index.d.ts +2 -2
  61. package/dist-sdk/src/entities/automation/index.js +1 -1
  62. package/dist-sdk/src/entities/automation/module.js +37 -8
  63. package/dist-sdk/src/entities/automation/output-field-types.d.ts +7 -0
  64. package/dist-sdk/src/entities/automation/output-field-types.js +36 -0
  65. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +9 -0
  66. package/dist-sdk/src/entities/automation/output-key-wire-name.js +13 -0
  67. package/dist-sdk/src/entities/automation/script-code.d.ts +17 -0
  68. package/dist-sdk/src/entities/automation/script-code.js +91 -5
  69. package/dist-sdk/src/entities/automation/system-ref-name.js +4 -0
  70. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +2 -0
  71. package/dist-sdk/src/entities/automation/task-output-labels.js +9 -0
  72. package/dist-sdk/src/entities/automation/tasks.d.ts +24 -2
  73. package/dist-sdk/src/entities/automation/tasks.js +38 -9
  74. package/dist-sdk/src/entities/automation/to-tf.d.ts +4 -0
  75. package/dist-sdk/src/entities/automation/to-tf.js +489 -83
  76. package/dist-sdk/src/entities/automation/triggers.d.ts +4 -2
  77. package/dist-sdk/src/entities/automation/triggers.js +4 -0
  78. package/dist-sdk/src/entities/chart/to-tf.js +10 -3
  79. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +24 -31
  80. package/dist-sdk/src/entities/element/build.d.ts +25 -13
  81. package/dist-sdk/src/entities/element/build.js +4 -1
  82. package/dist-sdk/src/entities/element/from-tf.d.ts +11 -0
  83. package/dist-sdk/src/entities/element/from-tf.js +58 -1
  84. package/dist-sdk/src/entities/element/index.d.ts +5 -3
  85. package/dist-sdk/src/entities/element/index.js +1 -0
  86. package/dist-sdk/src/entities/element/module.js +9 -3
  87. package/dist-sdk/src/entities/element/to-tf.js +8 -2
  88. package/dist-sdk/src/entities/field/build.d.ts +14 -1
  89. package/dist-sdk/src/entities/field/build.js +3 -0
  90. package/dist-sdk/src/entities/field/from-tf.d.ts +1 -0
  91. package/dist-sdk/src/entities/field/from-tf.js +39 -1
  92. package/dist-sdk/src/entities/field/media-types.d.ts +6 -0
  93. package/dist-sdk/src/entities/field/media-types.js +30 -0
  94. package/dist-sdk/src/entities/field/module.js +1 -0
  95. package/dist-sdk/src/entities/field/to-tf.d.ts +23 -2
  96. package/dist-sdk/src/entities/field/to-tf.js +130 -14
  97. package/dist-sdk/src/entities/file-reader/from-tf.js +14 -5
  98. package/dist-sdk/src/entities/file-reader/module.js +1 -0
  99. package/dist-sdk/src/entities/file-reader/types.d.ts +2 -0
  100. package/dist-sdk/src/entities/file-reader/types.js +1 -1
  101. package/dist-sdk/src/entities/portal/build.d.ts +26 -0
  102. package/dist-sdk/src/entities/portal/build.js +37 -0
  103. package/dist-sdk/src/entities/portal/from-tf.d.ts +27 -0
  104. package/dist-sdk/src/entities/portal/from-tf.js +75 -0
  105. package/dist-sdk/src/entities/portal/index.d.ts +1 -0
  106. package/dist-sdk/src/entities/portal/index.js +1 -0
  107. package/dist-sdk/src/entities/portal/module.d.ts +3 -0
  108. package/dist-sdk/src/entities/portal/module.js +28 -0
  109. package/dist-sdk/src/entities/portal/to-tf.d.ts +12 -0
  110. package/dist-sdk/src/entities/portal/to-tf.js +73 -0
  111. package/dist-sdk/src/entities/portal/types.d.ts +1 -0
  112. package/dist-sdk/src/entities/portal/types.js +1 -0
  113. package/dist-sdk/src/entities/relationship/module.js +2 -0
  114. package/dist-sdk/src/entities/relationship/pair-check.d.ts +7 -0
  115. package/dist-sdk/src/entities/relationship/pair-check.js +68 -0
  116. package/dist-sdk/src/entities/relationship/to-tf.d.ts +2 -0
  117. package/dist-sdk/src/entities/relationship/to-tf.js +12 -3
  118. package/dist-sdk/src/entities/search-table/module.js +1 -0
  119. package/dist-sdk/src/entities/search-table/to-tf.d.ts +1 -0
  120. package/dist-sdk/src/entities/search-table/to-tf.js +1 -1
  121. package/dist-sdk/src/entities/service-account/build.d.ts +15 -2
  122. package/dist-sdk/src/entities/service-account/from-tf.d.ts +2 -4
  123. package/dist-sdk/src/entities/service-account/from-tf.js +17 -5
  124. package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +56 -0
  125. package/dist-sdk/src/entities/service-account/role-fidelity.js +243 -0
  126. package/dist-sdk/src/entities/service-account/to-tf.d.ts +14 -0
  127. package/dist-sdk/src/entities/service-account/to-tf.js +17 -0
  128. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +1 -1
  129. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +5 -2
  130. package/dist-sdk/src/entities/shared/filters/ast.d.ts +8 -0
  131. package/dist-sdk/src/entities/shared/filters/index.d.ts +2 -0
  132. package/dist-sdk/src/entities/shared/filters/index.js +14 -4
  133. package/dist-sdk/src/entities/shared/filters/print.js +17 -1
  134. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +2 -0
  135. package/dist-sdk/src/entities/shared/filters/tf-codec.js +5 -1
  136. package/dist-sdk/src/entities/shared/filters/types.d.ts +9 -1
  137. package/dist-sdk/src/entities/shared/types/field-types.d.ts +10 -5
  138. package/dist-sdk/src/entities/shared/types/field-types.js +4 -0
  139. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +2 -1
  140. package/dist-sdk/src/entities/skill/from-tf.js +66 -13
  141. package/dist-sdk/src/entities/skill/input-coverage.d.ts +7 -0
  142. package/dist-sdk/src/entities/skill/input-coverage.js +11 -0
  143. package/dist-sdk/src/entities/skill/to-tf.js +14 -4
  144. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
  145. package/dist-sdk/src/entities/skill-tool/from-tf.js +8 -2
  146. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +2 -2
  147. package/dist-sdk/src/entities/skill-tool/to-tf.js +27 -5
  148. package/dist-sdk/src/entities/table/catalog.d.ts +14 -0
  149. package/dist-sdk/src/entities/table/catalog.js +66 -0
  150. package/dist-sdk/src/entities/table/module.js +2 -1
  151. package/dist-sdk/src/entities/table/to-tf.js +2 -2
  152. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +49 -9
  153. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +71 -18
  154. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +19 -4
  155. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +82 -10
  156. package/dist-sdk/src/entities/view/agent-view-layout.d.ts +53 -23
  157. package/dist-sdk/src/entities/view/agent-view-layout.js +1 -1
  158. package/dist-sdk/src/entities/view/from-tf.d.ts +3 -2
  159. package/dist-sdk/src/entities/view/from-tf.js +124 -12
  160. package/dist-sdk/src/entities/view/module.js +30 -3
  161. package/dist-sdk/src/entities/view/to-tf.d.ts +14 -1
  162. package/dist-sdk/src/entities/view/to-tf.js +67 -10
  163. package/dist-sdk/src/entities/view/types.d.ts +4 -15
  164. package/dist-sdk/src/entities/view/types.js +15 -15
  165. package/dist-sdk/src/entities/widget/build.d.ts +16 -1
  166. package/dist-sdk/src/entities/widget/build.js +11 -1
  167. package/dist-sdk/src/entities/widget/to-tf.js +34 -8
  168. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +16 -5
  169. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  170. package/dist-sdk/src/graph/index.d.ts +11 -0
  171. package/dist-sdk/src/graph/index.js +21 -0
  172. package/dist-sdk/src/graph/modules.js +2 -0
  173. package/dist-sdk/src/graph/types.d.ts +55 -2
  174. package/dist-sdk/src/internal/sdk-package.d.ts +1 -1
  175. package/dist-sdk/src/internal/sdk-package.js +1 -0
  176. package/package.json +10 -1
@@ -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.
@@ -120,16 +121,222 @@ export function preserveAuthoredAutomationRevision(freshSource, existingSource)
120
121
  return freshSource;
121
122
  return freshSource.replace(REVISION_PROPERTY, (_line, prefix) => `${prefix}${JSON.stringify(authored)},`);
122
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-￿]/;
123
191
  /**
124
- * Extract a string-literal (or `+`-concatenated literals) description from
125
- * authored automation source. Pull reprints often omit description entirely
126
- * 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.
127
211
  */
128
- export function extractAuthoredAutomationDescription(source) {
129
- const header = /(?:^|\n)[ \t]*description[ \t]*:/m.exec(source);
130
- 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)
131
311
  return undefined;
132
- 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;
133
340
  const parts = [];
134
341
  while (i < source.length) {
135
342
  while (i < source.length && /\s/.test(source[i]))
@@ -148,6 +355,8 @@ export function extractAuthoredAutomationDescription(source) {
148
355
  i += 2;
149
356
  continue;
150
357
  }
358
+ if (q === "`" && ch === "$" && source[i + 1] === "{")
359
+ return undefined;
151
360
  if (ch === q)
152
361
  break;
153
362
  raw += ch;
@@ -175,6 +384,21 @@ export function extractAuthoredAutomationDescription(source) {
175
384
  const joined = parts.join("");
176
385
  return joined === "" ? undefined : joined;
177
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
+ }
178
402
  /**
179
403
  * Keep a non-empty authored `description` across pull.
180
404
  *
@@ -183,24 +407,42 @@ export function extractAuthoredAutomationDescription(source) {
183
407
  * drops the attribute. Without this merge, pull → reprint → build clears
184
408
  * description from config while state still has it, forcing an adopt update.
185
409
  * Prefer a freshly pulled description when present; only reinstate the
186
- * 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.
187
421
  */
188
422
  export function preserveAuthoredAutomationDescription(freshSource, existingSource) {
189
423
  const authored = extractAuthoredAutomationDescription(existingSource);
190
424
  if (authored === undefined)
191
425
  return freshSource;
192
- if (extractAuthoredAutomationDescription(freshSource) !== undefined)
426
+ const options = automationOptionProperties(freshSource);
427
+ if (options === undefined)
193
428
  return freshSource;
194
- const revisionLine = REVISION_PROPERTY.exec(freshSource);
195
- if (revisionLine !== null && revisionLine.index !== undefined) {
196
- const insertAt = revisionLine.index + revisionLine[0].length;
197
- const indent = /^[ \t]*/.exec(revisionLine[0])?.[0] ?? " ";
198
- return `${freshSource.slice(0, insertAt)}\n${indent}description: ${JSON.stringify(authored)},${freshSource.slice(insertAt)}`;
199
- }
200
- const nameLine = /^([ \t]*name[ \t]*:[ \t]*)(["'`])([^"'`\r\n]*)\2[ \t]*,?[ \t]*$/m.exec(freshSource);
201
- if (nameLine !== null && nameLine.index !== undefined) {
202
- const insertAt = nameLine.index + nameLine[0].length;
203
- 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] ?? " ";
204
446
  return `${freshSource.slice(0, insertAt)}\n${indent}description: ${JSON.stringify(authored)},${freshSource.slice(insertAt)}`;
205
447
  }
206
448
  return freshSource;
@@ -220,10 +462,21 @@ function emptyImports() {
220
462
  usesOrg: false,
221
463
  usesScriptInput: false,
222
464
  usesRefType: false,
465
+ usesTableSearchTableRef: false,
223
466
  };
224
467
  }
225
468
  /** Folder (inside the automations folder) that holds printed script files. */
226
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
+ }
227
480
  /** Reprint extract-time owner handles as the authored catalog key. */
228
481
  function catalogOwnerHandle(state, appHandle) {
229
482
  if (appHandle === state.ownerHandle || appHandle === state.appRefName)
@@ -450,6 +703,9 @@ function renderHeader(ast, imports, _opts) {
450
703
  return alias ? `${name} as ${alias}` : name;
451
704
  });
452
705
  lines.push(`import { ${sortedSpecifiers.join(", ")} } from "${sdkPackageSpecifier("automations")}";`);
706
+ if (imports.usesTableSearchTableRef) {
707
+ lines.push(`import { tableSearchTableRef } from "${sdkPackageSpecifier("catalog")}";`);
708
+ }
453
709
  if (imports.usesTemplate || imports.usesUnresolvedField || imports.usesUnsafePlatformId || imports.usesRefType) {
454
710
  const coreNamed = [];
455
711
  if (imports.usesTemplate)
@@ -484,7 +740,10 @@ function printTrigger(trigger, state) {
484
740
  if (i.multiple)
485
741
  parts.push(`multiple: ${i.multiple}`);
486
742
  if (i.type !== "record" && i.defaultValue !== undefined && i.defaultValue !== null) {
487
- 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)}`);
488
747
  }
489
748
  if (i.description !== undefined)
490
749
  parts.push(`description: ${quote(i.description)}`);
@@ -1103,6 +1362,10 @@ function printArgValue(name, value, state, indent, refCtx) {
1103
1362
  const calc = trackFactory("calc", state);
1104
1363
  return `${calc}.raw(${quote(value.text)}, ${quote(value.resultType)})`;
1105
1364
  }
1365
+ if (isRequiredSecret(value)) {
1366
+ const fn = trackFactory("requiredSecret", state);
1367
+ return `${fn}(${quote(value.variable)})`;
1368
+ }
1106
1369
  if (isRefExpr(value))
1107
1370
  return printRef(value, state, refCtx);
1108
1371
  if (isFilter(value))
@@ -1226,25 +1489,26 @@ function printRef(ref, state, refCtx) {
1226
1489
  // item" - at build time it binds to whichever loop's replaceForEach
1227
1490
  // pass runs closest to this position, not to any outer ancestor.
1228
1491
  // refCtx.selfTaskRefKeys (accumulated by formatForEach on the way
1229
- // down) holds the full ancestor chain, so checking membership alone
1230
- // is not enough - only the LAST entry is actually addressable as
1231
- // ctx.item here. Live-confirmed (conciergeforfield, sanofi/us): two
1232
- // bugs of this shape. (1) A task nested inside "Matched Message"
1233
- // referenced "Matched Product" - a SIBLING loop, not an ancestor at
1234
- // all. (2) A task nested inside "Matched Message", itself nested
1235
- // inside "Matched Product", referenced "Matched Product" directly -
1236
- // a real ancestor, but not the nearest one, so `ctx.item` there binds
1237
- // to "Matched Message" instead. Both silently attributed the
1238
- // reference to the wrong loop (built HCL pointed at the wrong
1239
- // for_each task's inner.refs, which doesn't carry that key: "Invalid
1240
- // index" on every plan). EDK's authoring model has no primitive for
1241
- // "an outer loop's current item" - same escape shape as taskRef's
1242
- // out-of-scope cases above, not a claim that ctx.actions[...] is
1243
- // 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.
1244
1499
  const nearest = refCtx.selfTaskRefKeys?.[refCtx.selfTaskRefKeys.length - 1];
1245
1500
  if (nearest === ref.forEachTask) {
1246
1501
  return printPathAccess(`${ctxName}.item`, ref.path);
1247
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
+ //
1248
1512
  // Cannot route this through `ctx.actions[...]` the way the taskRef
1249
1513
  // out-of-scope escapes above do: `ctx.actions` is a Proxy that turns
1250
1514
  // ANY property access into a valid `{ kind: "task", ... }` reference,
@@ -1257,10 +1521,7 @@ function printRef(ref, state, refCtx) {
1257
1521
  // way, but automationToTf's valueToTf recognizes the marker and
1258
1522
  // fails the build loudly instead of building a different accepted
1259
1523
  // reference (review feedback on PR #1097, cursor[bot]).
1260
- const relation = refCtx.selfTaskRefKeys?.includes(ref.forEachTask)
1261
- ? "an outer ancestor forEach, not the nearest enclosing one"
1262
- : "a sibling forEach, not an ancestor";
1263
- 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 */)`;
1264
1525
  }
1265
1526
  case "variableParamRef":
1266
1527
  return `${ctxName}.variables${safeMember(ref.varTask)}${safeMember(ref.name)}`;
@@ -1354,6 +1615,15 @@ function printRef(ref, state, refCtx) {
1354
1615
  case "tableColumn":
1355
1616
  return `catalog.tables${safeMember(ref.tableHandle)}.columns${safeMember(ref.columnKey)}`;
1356
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
+ }
1357
1627
  // Search tables are element- or table-owned, never app-owned. Remapping
1358
1628
  // the automation owner's export handle to its authored app refName
1359
1629
  // would bind an unpulled same-handle foreign element's table onto the
@@ -1543,6 +1813,11 @@ const RESERVED_IDENT = new Set([
1543
1813
  "while", "with", "yield",
1544
1814
  ]);
1545
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)}]`;
1546
1821
  if (!/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name) || RESERVED_IDENT.has(name)) {
1547
1822
  return quote(name);
1548
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[];