@elementumai/edk 0.8.0-preview.11 → 0.8.2-alpha.5

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 (180) hide show
  1. package/README.md +510 -324
  2. package/dist-sdk/src/catalog/ai-provider-models.d.ts +30 -0
  3. package/dist-sdk/src/catalog/ai-provider-models.js +63 -0
  4. package/dist-sdk/src/catalog/factories.d.ts +56 -3
  5. package/dist-sdk/src/catalog/factories.js +83 -4
  6. package/dist-sdk/src/catalog/from-authoring.js +19 -2
  7. package/dist-sdk/src/catalog/index.d.ts +3 -2
  8. package/dist-sdk/src/catalog/index.js +3 -2
  9. package/dist-sdk/src/catalog/org.d.ts +1 -1
  10. package/dist-sdk/src/catalog/org.js +134 -50
  11. package/dist-sdk/src/catalog/render.d.ts +13 -1
  12. package/dist-sdk/src/catalog/render.js +21 -4
  13. package/dist-sdk/src/catalog/token.js +18 -0
  14. package/dist-sdk/src/catalog/types.d.ts +75 -3
  15. package/dist-sdk/src/catalog/types.js +3 -0
  16. package/dist-sdk/src/core/system-fields.d.ts +2 -0
  17. package/dist-sdk/src/core/system-fields.js +2 -0
  18. package/dist-sdk/src/core/types/ai-provider.d.ts +10 -23
  19. package/dist-sdk/src/core/types/ai-provider.js +1 -25
  20. package/dist-sdk/src/core/types/app.d.ts +26 -1
  21. package/dist-sdk/src/engine/build/context.d.ts +58 -0
  22. package/dist-sdk/src/engine/build/context.js +11 -1
  23. package/dist-sdk/src/engine/build/source-context.d.ts +45 -0
  24. package/dist-sdk/src/engine/build/source-context.js +23 -0
  25. package/dist-sdk/src/engine/pull/context.d.ts +15 -0
  26. package/dist-sdk/src/engine/pull/org.d.ts +10 -0
  27. package/dist-sdk/src/engine/pull/org.js +34 -4
  28. package/dist-sdk/src/engine/tf/index.d.ts +2 -2
  29. package/dist-sdk/src/engine/tf/index.js +2 -2
  30. package/dist-sdk/src/engine/tf/labels.d.ts +54 -0
  31. package/dist-sdk/src/engine/tf/labels.js +75 -0
  32. package/dist-sdk/src/engine/tf/parse.d.ts +15 -0
  33. package/dist-sdk/src/engine/tf/parse.js +162 -0
  34. package/dist-sdk/src/entities/access-policy/build.d.ts +26 -0
  35. package/dist-sdk/src/entities/access-policy/build.js +7 -0
  36. package/dist-sdk/src/entities/access-policy/filter.d.ts +61 -0
  37. package/dist-sdk/src/entities/access-policy/filter.js +83 -0
  38. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +66 -0
  39. package/dist-sdk/src/entities/access-policy/from-tf.js +187 -0
  40. package/dist-sdk/src/entities/access-policy/module.d.ts +3 -0
  41. package/dist-sdk/src/entities/access-policy/module.js +17 -0
  42. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +43 -0
  43. package/dist-sdk/src/entities/access-policy/to-tf.js +164 -0
  44. package/dist-sdk/src/entities/access-policy/types.d.ts +4 -0
  45. package/dist-sdk/src/entities/access-policy/types.js +10 -0
  46. package/dist-sdk/src/entities/agent/build.d.ts +2 -0
  47. package/dist-sdk/src/entities/agent/build.js +1 -0
  48. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.d.ts +38 -3
  49. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +257 -32
  50. package/dist-sdk/src/entities/agent/from-tf.d.ts +29 -9
  51. package/dist-sdk/src/entities/agent/from-tf.js +146 -19
  52. package/dist-sdk/src/entities/agent/index.d.ts +1 -1
  53. package/dist-sdk/src/entities/agent/module.js +14 -4
  54. package/dist-sdk/src/entities/agent/to-tf.d.ts +46 -1
  55. package/dist-sdk/src/entities/agent/to-tf.js +160 -14
  56. package/dist-sdk/src/entities/agent/tools.d.ts +88 -9
  57. package/dist-sdk/src/entities/agent/tools.js +46 -7
  58. package/dist-sdk/src/entities/agent-a2a-skill/from-tf.d.ts +17 -0
  59. package/dist-sdk/src/entities/agent-a2a-skill/from-tf.js +64 -0
  60. package/dist-sdk/src/entities/agent-a2a-skill/module.d.ts +4 -0
  61. package/dist-sdk/src/entities/agent-a2a-skill/module.js +14 -0
  62. package/dist-sdk/src/entities/agent-a2a-skill/to-tf.d.ts +40 -0
  63. package/dist-sdk/src/entities/agent-a2a-skill/to-tf.js +47 -0
  64. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +51 -4
  65. package/dist-sdk/src/entities/agent-tool/from-tf.js +131 -35
  66. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +11 -4
  67. package/dist-sdk/src/entities/agent-tool/to-tf.js +176 -30
  68. package/dist-sdk/src/entities/agent-tool/types.d.ts +5 -4
  69. package/dist-sdk/src/entities/agent-tool/types.js +38 -6
  70. package/dist-sdk/src/entities/app/build.d.ts +91 -13
  71. package/dist-sdk/src/entities/app/build.js +63 -5
  72. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +3 -0
  73. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -1
  74. package/dist-sdk/src/entities/app/from-tf.js +32 -22
  75. package/dist-sdk/src/entities/app/index.d.ts +4 -1
  76. package/dist-sdk/src/entities/app/index.js +2 -1
  77. package/dist-sdk/src/entities/app/module.js +10 -2
  78. package/dist-sdk/src/entities/app/to-tf.d.ts +5 -0
  79. package/dist-sdk/src/entities/app/to-tf.js +45 -4
  80. package/dist-sdk/src/entities/automation/build.d.ts +57 -13
  81. package/dist-sdk/src/entities/automation/build.js +62 -42
  82. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +25 -8
  83. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +16 -1
  84. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +206 -47
  85. package/dist-sdk/src/entities/automation/filter.d.ts +37 -3
  86. package/dist-sdk/src/entities/automation/filter.js +54 -3
  87. package/dist-sdk/src/entities/automation/from-tf.d.ts +26 -27
  88. package/dist-sdk/src/entities/automation/from-tf.js +1344 -222
  89. package/dist-sdk/src/entities/automation/index.d.ts +4 -0
  90. package/dist-sdk/src/entities/automation/index.js +4 -0
  91. package/dist-sdk/src/entities/automation/module.js +29 -32
  92. package/dist-sdk/src/entities/automation/operators.d.ts +29 -2
  93. package/dist-sdk/src/entities/automation/operators.js +27 -1
  94. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +19 -0
  95. package/dist-sdk/src/entities/automation/output-key-wire-name.js +24 -0
  96. package/dist-sdk/src/entities/automation/script-code.d.ts +10 -21
  97. package/dist-sdk/src/entities/automation/script-code.js +272 -5
  98. package/dist-sdk/src/entities/automation/tasks.d.ts +125 -19
  99. package/dist-sdk/src/entities/automation/tasks.js +83 -15
  100. package/dist-sdk/src/entities/automation/to-tf.d.ts +10 -29
  101. package/dist-sdk/src/entities/automation/to-tf.js +1291 -230
  102. package/dist-sdk/src/entities/automation/triggers.d.ts +9 -1
  103. package/dist-sdk/src/entities/automation/types.d.ts +29 -4
  104. package/dist-sdk/src/entities/automation/types.js +76 -46
  105. package/dist-sdk/src/entities/element/build.d.ts +44 -13
  106. package/dist-sdk/src/entities/element/build.js +45 -3
  107. package/dist-sdk/src/entities/element/from-tf.d.ts +1 -1
  108. package/dist-sdk/src/entities/element/from-tf.js +28 -14
  109. package/dist-sdk/src/entities/element/index.d.ts +4 -1
  110. package/dist-sdk/src/entities/element/index.js +2 -1
  111. package/dist-sdk/src/entities/element/module.js +4 -1
  112. package/dist-sdk/src/entities/element/to-tf.js +26 -3
  113. package/dist-sdk/src/entities/field/build.d.ts +61 -14
  114. package/dist-sdk/src/entities/field/build.js +10 -0
  115. package/dist-sdk/src/entities/field/calc/runtime.js +4 -0
  116. package/dist-sdk/src/entities/field/from-tf.d.ts +5 -3
  117. package/dist-sdk/src/entities/field/from-tf.js +118 -7
  118. package/dist-sdk/src/entities/field/module.js +3 -2
  119. package/dist-sdk/src/entities/field/to-tf.d.ts +46 -11
  120. package/dist-sdk/src/entities/field/to-tf.js +166 -17
  121. package/dist-sdk/src/entities/field/types.d.ts +26 -0
  122. package/dist-sdk/src/entities/field/types.js +34 -12
  123. package/dist-sdk/src/entities/file-reader/build.d.ts +108 -50
  124. package/dist-sdk/src/entities/file-reader/build.js +23 -23
  125. package/dist-sdk/src/entities/file-reader/deserializer/print-file-reader.d.ts +6 -0
  126. package/dist-sdk/src/entities/file-reader/deserializer/print-file-reader.js +109 -0
  127. package/dist-sdk/src/entities/file-reader/from-tf.d.ts +13 -0
  128. package/dist-sdk/src/entities/file-reader/from-tf.js +172 -0
  129. package/dist-sdk/src/entities/file-reader/index.d.ts +8 -3
  130. package/dist-sdk/src/entities/file-reader/index.js +7 -2
  131. package/dist-sdk/src/entities/file-reader/module.d.ts +3 -0
  132. package/dist-sdk/src/entities/file-reader/module.js +115 -0
  133. package/dist-sdk/src/entities/file-reader/to-tf.d.ts +14 -0
  134. package/dist-sdk/src/entities/file-reader/to-tf.js +84 -0
  135. package/dist-sdk/src/entities/file-reader/types.d.ts +32 -0
  136. package/dist-sdk/src/entities/file-reader/types.js +30 -0
  137. package/dist-sdk/src/entities/org/ai-provider.d.ts +13 -0
  138. package/dist-sdk/src/entities/org/ai-provider.js +46 -0
  139. package/dist-sdk/src/entities/org/connector.d.ts +8 -1
  140. package/dist-sdk/src/entities/org/connector.js +12 -14
  141. package/dist-sdk/src/entities/org/group.js +10 -1
  142. package/dist-sdk/src/entities/org/index.d.ts +1 -0
  143. package/dist-sdk/src/entities/org/index.js +1 -0
  144. package/dist-sdk/src/entities/org/user.js +10 -1
  145. package/dist-sdk/src/entities/shared/filters/ast.d.ts +59 -9
  146. package/dist-sdk/src/entities/shared/filters/types.d.ts +1 -1
  147. package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +17 -0
  148. package/dist-sdk/src/entities/shared/tool-field-ref.js +46 -0
  149. package/dist-sdk/src/entities/shared/types/field-types.d.ts +10 -1
  150. package/dist-sdk/src/entities/shared/types/field-types.js +9 -0
  151. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +19 -0
  152. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +128 -11
  153. package/dist-sdk/src/entities/skill/from-tf.js +4 -3
  154. package/dist-sdk/src/entities/skill/index.d.ts +1 -1
  155. package/dist-sdk/src/entities/skill/module.js +7 -1
  156. package/dist-sdk/src/entities/skill/to-tf.d.ts +26 -0
  157. package/dist-sdk/src/entities/skill/to-tf.js +65 -4
  158. package/dist-sdk/src/entities/skill/tools.d.ts +37 -8
  159. package/dist-sdk/src/entities/skill/tools.js +43 -1
  160. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +34 -4
  161. package/dist-sdk/src/entities/skill-tool/from-tf.js +128 -18
  162. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +13 -1
  163. package/dist-sdk/src/entities/skill-tool/to-tf.js +164 -25
  164. package/dist-sdk/src/entities/skill-tool/types.d.ts +5 -7
  165. package/dist-sdk/src/entities/skill-tool/types.js +47 -11
  166. package/dist-sdk/src/entities/view/from-tf.d.ts +6 -2
  167. package/dist-sdk/src/entities/view/from-tf.js +11 -9
  168. package/dist-sdk/src/entities/view/to-tf.d.ts +9 -7
  169. package/dist-sdk/src/entities/view/to-tf.js +39 -18
  170. package/dist-sdk/src/entities/view/types.d.ts +1 -1
  171. package/dist-sdk/src/entities/view/types.js +1 -1
  172. package/dist-sdk/src/graph/deferred-catalog-render.d.ts +0 -5
  173. package/dist-sdk/src/graph/deferred-catalog-render.js +1 -20
  174. package/dist-sdk/src/graph/index.d.ts +8 -0
  175. package/dist-sdk/src/graph/index.js +13 -9
  176. package/dist-sdk/src/graph/modules.js +8 -1
  177. package/dist-sdk/src/graph/types.d.ts +98 -4
  178. package/package.json +49 -16
  179. package/dist-sdk/src/entities/automation/value-ref-tf.d.ts +0 -76
  180. package/dist-sdk/src/entities/automation/value-ref-tf.js +0 -190
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * v2 automation printer — walks the SAME `AutomationAst` the v1 deserializer
3
3
  * produces (`src/automations/deserializer/ast.ts`) and emits **v2** EDK
4
- * TypeScript source: an options-shaped `defineAutomation({ name, parent, status,
4
+ * TypeScript source: an options-shaped `defineAutomation({ name, parent,
5
+ * workflowRevision, status,
5
6
  * workflow: defineWorkflow().trigger(...).task(...).outputs(...) })`, exported
6
7
  * as default. `defineAutomation` itself is not chained — the trigger/task/
7
8
  * outputs chain lives on the `workflow` field.
@@ -32,6 +33,7 @@
32
33
  import { camelCase } from "../../../../pull/util.js";
33
34
  import { sdkPackageSpecifier } from "../../../internal/sdk-package.js";
34
35
  import { isRefExpr } from "../../shared/filters/ast.js";
36
+ import { UNRESOLVED_REFERENCE_MARKER } from "../filter.js";
35
37
  // ---------------------------------------------------------------------------
36
38
  // Factory name mapping — v1 AST `factory` → v2 factory function name.
37
39
  //
@@ -153,7 +155,11 @@ function printAutomation(ast, opts) {
153
155
  // can alias any factory whose v2 name collides with it before emitting a
154
156
  // single call site.
155
157
  const refName = opts.refName ?? (camelCase(ast.name) || ast.name);
156
- const state = { imports: emptyImports(), localIdentifier: refName };
158
+ const state = {
159
+ imports: emptyImports(),
160
+ localIdentifier: refName,
161
+ ...(opts.foreignAppRefNames !== undefined && { foreignAppRefNames: opts.foreignAppRefNames }),
162
+ };
157
163
  const triggerCode = printTrigger(ast.trigger, state);
158
164
  // The trigger/task/outputs chain lives on the `workflow` field, nested one
159
165
  // level inside the `defineAutomation({...})` object — so tasks print at a
@@ -168,11 +174,14 @@ function printAutomation(ast, opts) {
168
174
  const body = [];
169
175
  body.push(`const ${refName} = defineAutomation({`);
170
176
  body.push(` name: ${quote(ast.name)},`);
171
- body.push(` parent: ${quote(ast.ownerHandle)},`);
172
- body.push(` status: ${quote(ast.status)},`);
173
- if (ast.workflowRevision !== undefined) {
174
- body.push(` workflowRevision: ${quote(ast.workflowRevision)},`);
177
+ body.push(` workflowRevision: ${quote(ast.workflowRevision)},`);
178
+ if (ast.description !== undefined)
179
+ body.push(` description: ${quote(ast.description)},`);
180
+ if (ast.triggersOtherAutomations !== undefined) {
181
+ body.push(` triggersOtherAutomations: ${ast.triggersOtherAutomations},`);
175
182
  }
183
+ body.push(` parent: ${quote(opts.appRefName ?? ast.ownerHandle)},`);
184
+ body.push(` status: ${quote(ast.status)},`);
176
185
  body.push(` workflow: defineWorkflow()`);
177
186
  body.push(`${chain.join("\n")},`);
178
187
  body.push(`});`);
@@ -327,7 +336,9 @@ function printTrigger(trigger, state) {
327
336
  const approvalProcessStatusUpdated = trackFactory("approvalProcessStatusUpdated", state);
328
337
  const parts = [
329
338
  `app: ${printRef(trigger.app, state, DEFAULT_CTX)}`,
330
- `approvalChain: ${quote(trigger.approvalChain)}`,
339
+ `approvalChain: ${typeof trigger.approvalChain === "string"
340
+ ? quote(trigger.approvalChain)
341
+ : printRef(trigger.approvalChain, state, DEFAULT_CTX)}`,
331
342
  `status: ${quote(trigger.status)}`,
332
343
  ];
333
344
  return `${approvalProcessStatusUpdated}({\n ${parts.join(",\n ")}\n })`;
@@ -415,8 +426,15 @@ function printFieldRef(appHandle, fieldKey) {
415
426
  function displayNameArg(task) {
416
427
  return task.displayName ? `, ${quote(task.displayName)}` : "";
417
428
  }
429
+ function topLevelTaskTrailingArgs(task) {
430
+ if (task.hclParent === undefined)
431
+ return displayNameArg(task);
432
+ return `, ${task.displayName ? quote(task.displayName) : "undefined"}, ${quote(task.hclParent)}`;
433
+ }
418
434
  function printTask(task, state, indent) {
419
435
  const pad = " ".repeat(indent);
436
+ if (task.factory === "executeScript")
437
+ return formatExecuteScript(task, state, indent);
420
438
  if (task.factory === "forEach")
421
439
  return formatForEach(task, state, indent);
422
440
  if (task.factory === "switchTask")
@@ -425,7 +443,55 @@ function printTask(task, state, indent) {
425
443
  return formatForkJoin(task, state, indent);
426
444
  const factory = resolveTaskFactory(task.factory, state);
427
445
  const args = printTaskArgs(task, state, indent + 1, DEFAULT_CTX);
428
- return `${pad}.task(${quote(task.refKey)}, (ctx) => ${factory}(${args})${displayNameArg(task)})`;
446
+ return `${pad}.task(${quote(task.refKey)}, (ctx) => ${factory}(${args})${topLevelTaskTrailingArgs(task)})`;
447
+ }
448
+ /**
449
+ * Top-level executeScript — fluent `.executeScript(name, { inputs, code, outputs? })`
450
+ * with function-form `code`. Nested operator bodies still print
451
+ * `childTask(..., executeScript({…}))` via {@link printChildTask}.
452
+ */
453
+ function formatExecuteScript(task, state, indent) {
454
+ const pad = " ".repeat(indent);
455
+ const configPad = " ".repeat(indent + 1);
456
+ const lines = [];
457
+ if (task.args.inputs !== undefined && task.args.inputs !== null && typeof task.args.inputs === "object") {
458
+ const obj = printObjectLiteral(task.args.inputs, state, indent + 1, DEFAULT_CTX);
459
+ lines.push(`${configPad}inputs: (${lambdaParams(obj, "ctx")}) => (${obj}),`);
460
+ }
461
+ const code = task.args.code ?? task.args.script;
462
+ if (typeof code === "string") {
463
+ lines.push(`${configPad}code: ${printScriptCodeFn(code, indent + 1)},`);
464
+ }
465
+ if (task.args.outputs !== undefined && task.args.outputs !== null && typeof task.args.outputs === "object") {
466
+ lines.push(`${configPad}outputs: ${printObjectLiteral(task.args.outputs, state, indent + 1, DEFAULT_CTX)},`);
467
+ }
468
+ else {
469
+ // No `output_schema` on the platform resource — print an explicit `null`
470
+ // rather than omitting the key, so a rebuild doesn't re-infer a schema
471
+ // from the script body and drift from state.
472
+ lines.push(`${configPad}outputs: null,`);
473
+ }
474
+ if (lines.length === 0) {
475
+ return `${pad}.executeScript(${quote(task.refKey)}, {})`;
476
+ }
477
+ return `${pad}.executeScript(${quote(task.refKey)}, {\n${lines.join("\n")}\n${pad}})`;
478
+ }
479
+ /**
480
+ * Wrap a platform script body as `(input) => { … }` for authoring / pull —
481
+ * `code:` is always a real function (#125 banned a raw-string alternative).
482
+ * This writes the body's text into the `.ts` source verbatim; byte-fidelity
483
+ * through the SUBSEQUENT `elementum build` (which would otherwise reformat
484
+ * it via jiti/Babel's transpile-then-`toString()`) is handled separately at
485
+ * build time by `tryExtractFromCurrentSource` (`script-code.ts`), which reads
486
+ * this exact source text back out directly rather than trusting the
487
+ * transpiled runtime function.
488
+ */
489
+ function printScriptCodeFn(body, indent) {
490
+ const pad = " ".repeat(indent);
491
+ const innerPad = " ".repeat(indent + 1);
492
+ const lines = body.replace(/\r\n/g, "\n").split("\n");
493
+ const indented = lines.map((line) => (line.length === 0 ? "" : `${innerPad}${line}`)).join("\n");
494
+ return `(input) => {\n${indented}\n${pad}}`;
429
495
  }
430
496
  /**
431
497
  * Resolve a v1 AST factory string to its v2 factory function name and track
@@ -452,7 +518,35 @@ function formatForEach(task, state, indent) {
452
518
  const childLines = children.map((c) => printChildTask(c, state, indent + 2, childCtx));
453
519
  const tbody = childLines.length > 0 ? `[\n${childLines.join(",\n")}\n${configIndent}]` : `[]`;
454
520
  const tasksBlock = `(${lambdaParams(tbody, "item", "innerCtx")}) => ${tbody}`;
455
- return `${pad}.task(${quote(task.refKey)}, (ctx) => ${forEach}(ctx, {\n${configIndent}collection: ${collectionCode},\n${configIndent}tasks: ${tasksBlock},\n${pad}})${displayNameArg(task)})`;
521
+ return `${pad}.task(${quote(task.refKey)}, (ctx) => ${forEach}(ctx, {\n${configIndent}collection: ${collectionCode},\n${configIndent}tasks: ${tasksBlock},\n${pad}})${topLevelTaskTrailingArgs(task)})`;
522
+ }
523
+ /**
524
+ * Renders a switch's `defaultTasks:` config value. Platform-default label
525
+ * text ("Default") uses the plain `(innerCtx) => [...]` function form;
526
+ * anything else (e.g. a manual rename to "Default Path") is preserved via the
527
+ * `{ label, tasks }` object form so the build round trip reproduces it
528
+ * instead of hardcoding "Default".
529
+ */
530
+ function formatDefaultTasksBlock(defaults, state, indent, configIndent, ctxTypeName) {
531
+ const defaultTasks = defaults.flatMap((ch) => ch.tasks);
532
+ const defaultLabel = defaults.map((ch) => ch.defaultLabel).find((label) => label !== undefined);
533
+ const defaultFilterMode = defaults.map((ch) => ch.defaultFilterMode).find((mode) => mode !== undefined);
534
+ const innerCtx = { ctxName: "innerCtx" };
535
+ const defaultLines = defaultTasks.map((t) => printChildTask(t, state, indent + 2, innerCtx));
536
+ const dbody = defaultLines.length > 0 ? `[\n${defaultLines.join(",\n")}\n${configIndent}]` : `[]`;
537
+ const defaultFn = `(innerCtx: typeof ${ctxTypeName}) => ${dbody}`;
538
+ const needsLabel = defaultLabel !== undefined && defaultLabel !== "Default";
539
+ const needsFilterMode = defaultFilterMode === "explicitTrueFilter";
540
+ if (!needsLabel && !needsFilterMode)
541
+ return defaultFn;
542
+ const innerPad = `${configIndent} `;
543
+ const parts = [];
544
+ if (needsLabel)
545
+ parts.push(`${innerPad}label: ${quote(defaultLabel)}`);
546
+ parts.push(`${innerPad}tasks: ${defaultFn}`);
547
+ if (needsFilterMode)
548
+ parts.push(`${innerPad}defaultFilterMode: "explicitTrueFilter"`);
549
+ return `{\n${parts.join(",\n")},\n${configIndent}}`;
456
550
  }
457
551
  function formatSwitch(task, state, indent) {
458
552
  const pad = " ".repeat(indent);
@@ -466,14 +560,10 @@ function formatSwitch(task, state, indent) {
466
560
  const configParts = [];
467
561
  configParts.push(`${configIndent}cases: [\n${caseLines.join(",\n")}\n${configIndent}]`);
468
562
  if (defaults.length > 0) {
469
- const defaultTasks = defaults.flatMap((ch) => ch.tasks);
470
- const innerCtx = { ctxName: "innerCtx" };
471
- const defaultLines = defaultTasks.map((t) => printChildTask(t, state, indent + 2, innerCtx));
472
- const dbody = defaultLines.length > 0 ? `[\n${defaultLines.join(",\n")}\n${configIndent}]` : `[]`;
473
- const defaultBlock = `(innerCtx: typeof ctx) => ${dbody}`;
563
+ const defaultBlock = formatDefaultTasksBlock(defaults, state, indent, configIndent, "ctx");
474
564
  configParts.push(`${configIndent}defaultTasks: ${defaultBlock}`);
475
565
  }
476
- return `${pad}.task(${quote(task.refKey)}, (ctx) => ${switchTask}(ctx, {\n${configParts.join(",\n")},\n${pad}})${displayNameArg(task)})`;
566
+ return `${pad}.task(${quote(task.refKey)}, (ctx) => ${switchTask}(ctx, {\n${configParts.join(",\n")},\n${pad}})${topLevelTaskTrailingArgs(task)})`;
477
567
  }
478
568
  function formatSwitchCase(ch, state, indent, outerCtxName) {
479
569
  const pad = " ".repeat(indent);
@@ -499,7 +589,7 @@ function formatForkJoin(task, state, indent) {
499
589
  const branches = task.children ?? [];
500
590
  const branchLines = branches.map((ch) => formatForkJoinBranch(ch, state, indent + 2));
501
591
  const branchesBlock = branchLines.length > 0 ? `[\n${branchLines.join(",\n")}\n${configIndent}]` : `[]`;
502
- return `${pad}.task(${quote(task.refKey)}, (ctx) => ${forkJoin}(ctx, {\n${configIndent}branches: ${branchesBlock},\n${pad}})${displayNameArg(task)})`;
592
+ return `${pad}.task(${quote(task.refKey)}, (ctx) => ${forkJoin}(ctx, {\n${configIndent}branches: ${branchesBlock},\n${pad}})${topLevelTaskTrailingArgs(task)})`;
503
593
  }
504
594
  function formatForkJoinBranch(ch, state, indent) {
505
595
  const pad = " ".repeat(indent);
@@ -558,11 +648,7 @@ function formatChildSwitch(task, state, indent, refCtx) {
558
648
  const configParts = [];
559
649
  configParts.push(`${configIndent}cases: [\n${caseLines.join(",\n")}\n${configIndent}]`);
560
650
  if (defaults.length > 0) {
561
- const defaultTasks = defaults.flatMap((ch) => ch.tasks);
562
- const innerCtx = { ctxName: "innerCtx" };
563
- const defaultLines = defaultTasks.map((t) => printChildTask(t, state, indent + 2, innerCtx));
564
- const dbody = defaultLines.length > 0 ? `[\n${defaultLines.join(",\n")}\n${configIndent}]` : `[]`;
565
- const defaultBlock = `(innerCtx: typeof ${refCtx.ctxName}) => ${dbody}`;
651
+ const defaultBlock = formatDefaultTasksBlock(defaults, state, indent, configIndent, refCtx.ctxName);
566
652
  configParts.push(`${configIndent}defaultTasks: ${defaultBlock}`);
567
653
  }
568
654
  return `${pad}childTask(${quote(task.refKey)}, ${switchTask}(${refCtx.ctxName}, {\n${configParts.join(",\n")},\n${pad}})${displayNameArg(task)})`;
@@ -599,6 +685,12 @@ function printTaskArgs(task, state, indent, refCtx) {
599
685
  lines.push(`${pad}fields: ${printFieldAssignments(v, appHandle, state, indent + 1, refCtx)},`);
600
686
  continue;
601
687
  }
688
+ // relateRecords.sources is always a DSL array — even when HCL used a scalar.
689
+ if (k === "sources" && task.factory === "relateRecords") {
690
+ const items = Array.isArray(v) ? v : [v];
691
+ lines.push(`${pad}sources: ${printArrayLiteral(items, state, indent + 1, refCtx)},`);
692
+ continue;
693
+ }
602
694
  const outKey = renames[k] ?? k;
603
695
  lines.push(`${pad}${safeKey(outKey)}: ${printArgValue(k, v, state, indent + 1, refCtx)},`);
604
696
  }
@@ -655,10 +747,9 @@ function printArgValue(name, value, state, indent, refCtx) {
655
747
  return printRef(value, state, refCtx);
656
748
  if (isFilterAst(value))
657
749
  return printFilter(value, state);
658
- // executeScript `script` field — v2's `executeScript` takes the raw code
659
- // as a `code:` string (not an arrow body), so emit a string literal.
660
- if (name === "script" && typeof value === "string") {
661
- return quote(value);
750
+ // executeScript body (AST key `code`, legacy `script`) — always function form.
751
+ if ((name === "code" || name === "script") && typeof value === "string") {
752
+ return printScriptCodeFn(value, indent);
662
753
  }
663
754
  if (Array.isArray(value) && value.length > 0 && isSort(value[0])) {
664
755
  return printSortArray(value, state, refCtx);
@@ -717,6 +808,13 @@ function printRef(ref, state, refCtx) {
717
808
  // output) — always legitimate, so never as-any escape it: non-identifier
718
809
  // names print as typed bracket access (ctx.trigger["STUDENT NAME 2"]).
719
810
  const [head, ...rest] = ref.path;
811
+ // WebhookTriggerOutput's body/headers are Record<string, unknown> — any
812
+ // string key already type-checks there, so a sub-key prints as plain
813
+ // access. printPathAccess's "as any" escape is for genuinely untyped
814
+ // record field paths; using it here would just be a pointless cast.
815
+ if ((head === "body" || head === "headers") && rest.length > 0) {
816
+ return `${ctxName}.trigger${safeMember(head)}${rest.map(safeMember).join("")}`;
817
+ }
720
818
  return printPathAccess(`${ctxName}.trigger${safeMember(head)}`, rest);
721
819
  }
722
820
  case "forEachRef":
@@ -743,10 +841,34 @@ function printRef(ref, state, refCtx) {
743
841
  // Pure-string multi-part: plain literal concatenation is safe.
744
842
  return parts.join(" + ");
745
843
  }
746
- case "field":
747
- return `catalog.${ref.appHandle}.fields${safeMember(ref.fieldKey)}`;
748
- case "app":
749
- return `catalog.${ref.appHandle}`;
844
+ case "field": {
845
+ if (ref.foreign === undefined)
846
+ return `catalog.${ref.appHandle}.fields${safeMember(ref.fieldKey)}`;
847
+ // Same treatment as the "app" case just below: a foreign field already
848
+ // pulled into this workspace (board issue #40, app-only) resolves to a
849
+ // typed token; otherwise a literal stub (field type is unconfirmed —
850
+ // ei's `elementum_field` data source doesn't expose it).
851
+ const foreignRefName = ref.foreign.entityType === "app" ? state.foreignAppRefNames?.get(ref.foreign.name) : undefined;
852
+ if (foreignRefName !== undefined)
853
+ return `catalog.${foreignRefName}.fields${safeMember(ref.fieldKey)}`;
854
+ return (`{ __kind: "field", refName: ${quote(ref.fieldKey)}, name: ${quote(ref.foreign.fieldName ?? ref.fieldKey)}, fieldType: "TEXT", ` +
855
+ `parent: ${quote(ref.appHandle)}, parentKind: ${quote(ref.foreign.entityType)}, parentName: ${quote(ref.foreign.name)} } ` +
856
+ `// TODO: foreign field — type unconfirmed (ei's elementum_field data source doesn't expose it) and refName is a best-effort guess; verify against "${ref.foreign.name}"`);
857
+ }
858
+ case "userField":
859
+ return `catalog.users.fields${safeMember(ref.fieldKey)}`;
860
+ case "app": {
861
+ if (ref.entityType === undefined || ref.name === undefined) {
862
+ return `catalog.${ref.appHandle}`;
863
+ }
864
+ // A foreign APP (never an element — this map is app-name-keyed only,
865
+ // board issue #40) already pulled into this workspace resolves to a
866
+ // typed token instead of the always-safe literal stub.
867
+ const foreignRefName = ref.entityType === "app" ? state.foreignAppRefNames?.get(ref.name) : undefined;
868
+ if (foreignRefName !== undefined)
869
+ return `catalog.${foreignRefName}`;
870
+ return `{ __kind: ${quote(ref.entityType)}, refName: ${quote(ref.appHandle)}, name: ${quote(ref.name)} }`;
871
+ }
750
872
  case "agent":
751
873
  return `catalog.${ref.appHandle}.agents${safeMember(ref.agentKey)}`;
752
874
  case "automation":
@@ -756,18 +878,34 @@ function printRef(ref, state, refCtx) {
756
878
  case "documentModelField":
757
879
  return `catalog.${ref.appHandle}.fileReaders${safeMember(ref.documentModelKey)}.fields${safeMember(ref.fieldKey)}`;
758
880
  case "approvalChain":
759
- return `catalog.${ref.appHandle}.approvalChains${safeMember(ref.approvalChainKey)}`;
881
+ // Approval chains are reference-only in the HCL architecture: EDK does
882
+ // not have approval-chain authoring files from which catalog regeneration
883
+ // could rebuild this bag. Keep the provider label as a fully typed token
884
+ // instead of emitting a catalog lookup that disappears on `edk build`.
885
+ return `{ __kind: "approvalChain", refName: ${quote(ref.approvalChainKey)}, name: ${quote(ref.approvalChainKey)}, parent: ${quote(ref.appHandle)}${ref.unresolvedId !== undefined ? `, unresolvedId: ${quote(ref.unresolvedId)}` : ""} }`;
760
886
  case "connector": {
761
- // Connectors are org-level (no appHandle) — emit the minted catalog handle
762
- // the connector catalog resolved (matching what `elementum import connectors`
763
- // wrote), mirroring src/agents/deserializer/print-agent.ts's
764
- // `printConnector`. A catalog miss (no handle resolved) falls back to an
765
- // id-only inline literal that still structurally satisfies `ConnectorRef`.
887
+ // Connectors are org-level (no appHandle), nested under their owning
888
+ // provider — mirrors printConnectorToken in
889
+ // src/entities/agent/deserializer/print-agent-v2.ts. A resolved model
890
+ // with no resolved provider, or no resolution at all, falls back to a
891
+ // TODO that still structurally satisfies `ConnectorRef`.
766
892
  const handle = ref.handle ?? "";
767
- if (handle.length > 0)
768
- return `catalog.connectors${safeMember(handle)}`;
893
+ if (handle.length > 0 && ref.providerKey !== undefined)
894
+ return `catalog.aiProviders.${ref.providerKey}.models.${handle}`;
895
+ if (handle.length > 0) {
896
+ // NOT `catalog.aiProviders.TODO_PROVIDER.models.${handle}` — that
897
+ // reads like a TODO but is a live property-access chain, and
898
+ // TODO_PROVIDER is never a real catalog key, so evaluating it throws
899
+ // the moment anything loads this file instead of failing with the
900
+ // intended diagnostic (same class of bug print-agent-v2.ts's
901
+ // TODO_CONNECTOR_TOKEN had). A plain object literal loads safely and
902
+ // still structurally satisfies `ConnectorRef`.
903
+ return `{ __kind: "connector", refName: ${quote(handle)}, name: ${quote(handle)}, parent: "TODO_PROVIDER" } /* TODO: connector "${handle}" resolved but its AI provider could not be determined */`;
904
+ }
769
905
  return `{ __kind: "connector", refName: ${quote(ref.id)}, name: ${quote(ref.id)} } /* TODO: unresolved connector ${quote(ref.id)} */`;
770
906
  }
907
+ case "cloudLink":
908
+ return `catalog.cloudLinks${safeMember(ref.handle)}`;
771
909
  case "unresolved":
772
910
  // v2 value slots accept a literal directly — no `val()` wrapper. But this
773
911
  // RefExpr kind is also the fallback for ref-typed positions (automation,
@@ -776,6 +914,8 @@ function printRef(ref, state, refCtx) {
776
914
  // the same-purpose fallback in `printFieldAssignments` and keeps the
777
915
  // placeholder compiling regardless of which kind of slot it lands in.
778
916
  return `${quote(ref.uuid)} as any /* TODO: unresolved ${ref.hint} */`;
917
+ case "localRef":
918
+ return `{ kind: "localRef", localName: ${quote(ref.localName)}, path: ${JSON.stringify(ref.path)} }`;
779
919
  }
780
920
  }
781
921
  // ---------------------------------------------------------------------------
@@ -793,9 +933,12 @@ function printLikeOptions(f) {
793
933
  const entries = [];
794
934
  if (f.not)
795
935
  entries.push("not: true");
796
- if (f.caseInsensitive)
797
- entries.push("caseInsensitive: true");
798
- if (f.mode)
936
+ if (f.caseInsensitive !== undefined)
937
+ entries.push(`caseInsensitive: ${f.caseInsensitive}`);
938
+ // "legacy" is the platform's implicit default for a like filter that never
939
+ // had a mode authored — it's always returned on export regardless, so
940
+ // printing it back would fabricate an option the author never set.
941
+ if (f.mode && f.mode !== "legacy")
799
942
  entries.push(`mode: ${quote(f.mode)}`);
800
943
  return entries.length > 0 ? `, { ${entries.join(", ")} }` : "";
801
944
  }
@@ -870,10 +1013,23 @@ function printFilter(f, state) {
870
1013
  */
871
1014
  function printFilterField(left, state) {
872
1015
  if (left.kind === "field") {
873
- return `catalog.${left.appHandle}.fields${safeMember(left.fieldKey)}`;
1016
+ return printRef(left, state, DEFAULT_CTX);
1017
+ }
1018
+ if (left.kind === "userField") {
1019
+ return `catalog.users.fields${safeMember(left.fieldKey)}`;
874
1020
  }
875
1021
  if (left.kind === "unresolved") {
876
- return `${quote(left.uuid)} as any /* TODO: unresolved field */`;
1022
+ // A field placeholder (hint === "field") legitimately round-trips
1023
+ // through the field_id wire slot on rebuild (filter.ts's leftDescriptor).
1024
+ // Anything else stood in for a left_value/REFERENCE position that isn't
1025
+ // a field at all (e.g. a workflow-variable reference) - mark it so
1026
+ // leftDescriptor routes it through the left_value/REFERENCE slot
1027
+ // instead, reproducing the original raw reference string verbatim
1028
+ // rather than corrupting it into a field_id (#290).
1029
+ if (left.hint === "field") {
1030
+ return `${quote(left.uuid)} as any /* TODO: unresolved field */`;
1031
+ }
1032
+ return `${quote(`${UNRESOLVED_REFERENCE_MARKER}${left.uuid}`)} as any /* TODO: unresolved ${left.hint} - re-express with a typed ref when possible */`;
877
1033
  }
878
1034
  return printRef(left, state, DEFAULT_CTX);
879
1035
  }
@@ -904,7 +1060,8 @@ function printFilterPrimitive(v, state) {
904
1060
  case "null":
905
1061
  return "null";
906
1062
  case "currentUser":
907
- return `"" /* TODO: currentUser() unsupported in v2 filter */`;
1063
+ state.imports.filterOps.add("currentUser");
1064
+ return `filter.currentUser(${quote(v.currentUserType)})`;
908
1065
  case "reference":
909
1066
  return printRef(v.ref, state, DEFAULT_CTX);
910
1067
  }
@@ -1016,21 +1173,23 @@ function literalJson(value) {
1016
1173
  */
1017
1174
  function printCustomResponse(customResponse) {
1018
1175
  const parts = [];
1019
- // Print success configuration
1020
1176
  if (customResponse.success) {
1021
1177
  const successParts = [];
1022
1178
  successParts.push(`enabled: ${customResponse.success.enabled}`);
1023
1179
  successParts.push(`format: "${customResponse.success.format}"`);
1024
- successParts.push(`statusCode: ${customResponse.success.statusCode}`);
1180
+ if (customResponse.success.statusCode !== undefined) {
1181
+ successParts.push(`statusCode: ${customResponse.success.statusCode}`);
1182
+ }
1025
1183
  successParts.push(`body: ${quote(customResponse.success.body)}`);
1026
1184
  parts.push(`success: { ${successParts.join(", ")} }`);
1027
1185
  }
1028
- // Print failure configuration
1029
1186
  if (customResponse.failure) {
1030
1187
  const failureParts = [];
1031
1188
  failureParts.push(`enabled: ${customResponse.failure.enabled}`);
1032
1189
  failureParts.push(`format: "${customResponse.failure.format}"`);
1033
- failureParts.push(`statusCode: ${customResponse.failure.statusCode}`);
1190
+ if (customResponse.failure.statusCode !== undefined) {
1191
+ failureParts.push(`statusCode: ${customResponse.failure.statusCode}`);
1192
+ }
1034
1193
  failureParts.push(`body: ${quote(customResponse.failure.body)}`);
1035
1194
  parts.push(`failure: { ${failureParts.join(", ")} }`);
1036
1195
  }
@@ -22,7 +22,7 @@
22
22
  * reference-value conversion is shared with `core/filters` so the two DSLs can't
23
23
  * drift.
24
24
  */
25
- import type { FieldRef } from "../../catalog/index.js";
25
+ import type { FieldRef, UserFieldRef } from "../../catalog/index.js";
26
26
  import { type LikeMode, type ValueType } from "../shared/filters/index.js";
27
27
  import { type Ref } from "../shared/ref.js";
28
28
  /** A wire filter (may embed `FieldRef` tokens at `field` positions). */
@@ -34,9 +34,43 @@ type Primitive = string | number | boolean | null;
34
34
  * from the compared field's `fieldType` (or the operator's `leftType` when the
35
35
  * left side is itself a `Ref`).
36
36
  */
37
- export type FilterValue = Primitive | Ref<unknown> | FieldRef;
37
+ /**
38
+ * Marker produced by {@link currentUser} — compares against the acting
39
+ * user's id/email/domain rather than a literal or ref value. A plain object
40
+ * literal (not a `Ref`/`FieldRef`), recognized by {@link value} before
41
+ * falling through to the primitive cases.
42
+ */
43
+ export interface CurrentUserFilterValue {
44
+ readonly __kind: "currentUser";
45
+ readonly currentUserType: "id" | "email" | "domain";
46
+ }
47
+ export type FilterValue = Primitive | Ref<unknown> | FieldRef | UserFieldRef | CurrentUserFilterValue;
48
+ /** Compare against the current (acting) user — id by default. */
49
+ export declare function currentUser(type?: "id" | "email" | "domain"): CurrentUserFilterValue;
38
50
  /** Either side of a filter: a catalog field token, or a task/trigger/… output ref. */
39
- export type LeftRef = FieldRef | Ref<unknown>;
51
+ export type LeftRef = FieldRef | UserFieldRef | Ref<unknown>;
52
+ /**
53
+ * Marker prefix a pulled filter's left side carries when the pull-time
54
+ * deserializer couldn't decode its `left_value`/REFERENCE shape to a typed
55
+ * ref (e.g. a `variable.<uuid>` reference to a not-yet-authorable workflow
56
+ * variable — see `from-tf.ts`'s `decodeReferenceString`). Distinct from an
57
+ * unresolved FIELD placeholder (a bare uuid, no prefix), which legitimately
58
+ * round-trips through the `{ field }`/`field_id` wire slot below — a
59
+ * left_value/REFERENCE position never does, so silently routing it through
60
+ * `{ field }` would rebuild a structurally different filter than the one
61
+ * `ei` exported. `leftDescriptor` routes this marker through the SAME
62
+ * `leftValue`/REFERENCE wire slot instead, reproducing the original raw
63
+ * `value_reference` string verbatim (#290) rather than either corrupting it
64
+ * (routing to `field`) or refusing to build it (a single bad automation
65
+ * file throwing during `elementum build`'s jiti discovery aborts discovery
66
+ * for the WHOLE workspace, not just this app — confirmed in
67
+ * `engine/build/build.ts`'s `discoverOwnFileChildren`, which deliberately
68
+ * treats any load failure as fatal rather than risk a silently-missing
69
+ * entity planning as a destroy — so throwing here would trade "one
70
+ * automation invisible" for "the entire org can no longer build," a much
71
+ * worse regression).
72
+ */
73
+ export declare const UNRESOLVED_REFERENCE_MARKER = "__edkUnresolvedReference::";
40
74
  /** Match every record (the minimal valid filter). */
41
75
  export declare function whereTrue(): Filter;
42
76
  /** Match no record. */
@@ -1,5 +1,34 @@
1
1
  import { fieldTypeToValueType, refDataToFilterReference } from "../shared/filters/index.js";
2
2
  import { isRef } from "../shared/ref.js";
3
+ /** Compare against the current (acting) user — id by default. */
4
+ export function currentUser(type = "id") {
5
+ return { __kind: "currentUser", currentUserType: type };
6
+ }
7
+ function isCurrentUserValue(value) {
8
+ return typeof value === "object" && value !== null && !isRef(value) && value.__kind === "currentUser";
9
+ }
10
+ /**
11
+ * Marker prefix a pulled filter's left side carries when the pull-time
12
+ * deserializer couldn't decode its `left_value`/REFERENCE shape to a typed
13
+ * ref (e.g. a `variable.<uuid>` reference to a not-yet-authorable workflow
14
+ * variable — see `from-tf.ts`'s `decodeReferenceString`). Distinct from an
15
+ * unresolved FIELD placeholder (a bare uuid, no prefix), which legitimately
16
+ * round-trips through the `{ field }`/`field_id` wire slot below — a
17
+ * left_value/REFERENCE position never does, so silently routing it through
18
+ * `{ field }` would rebuild a structurally different filter than the one
19
+ * `ei` exported. `leftDescriptor` routes this marker through the SAME
20
+ * `leftValue`/REFERENCE wire slot instead, reproducing the original raw
21
+ * `value_reference` string verbatim (#290) rather than either corrupting it
22
+ * (routing to `field`) or refusing to build it (a single bad automation
23
+ * file throwing during `elementum build`'s jiti discovery aborts discovery
24
+ * for the WHOLE workspace, not just this app — confirmed in
25
+ * `engine/build/build.ts`'s `discoverOwnFileChildren`, which deliberately
26
+ * treats any load failure as fatal rather than risk a silently-missing
27
+ * entity planning as a destroy — so throwing here would trade "one
28
+ * automation invisible" for "the entire org can no longer build," a much
29
+ * worse regression).
30
+ */
31
+ export const UNRESOLVED_REFERENCE_MARKER = "__edkUnresolvedReference::";
3
32
  /**
4
33
  * True when `left` is a genuine `Ref` (task/trigger/… output) rather than a
5
34
  * field. Note this is *not* "is a `FieldRef`" — an unresolved-field
@@ -11,7 +40,8 @@ function isRefLeft(left) {
11
40
  return isRef(left);
12
41
  }
13
42
  function isFieldValue(value) {
14
- return typeof value === "object" && value !== null && !isRef(value) && value.__kind === "field";
43
+ const kind = typeof value === "object" && value !== null ? value.__kind : undefined;
44
+ return !isRef(value) && (kind === "field" || kind === "userField");
15
45
  }
16
46
  /** The wire LHS descriptor: `{ field }` for a FieldRef (or field placeholder), `{ leftValue }` for a Ref. */
17
47
  function leftDescriptor(left, defaultType, leftType) {
@@ -24,14 +54,35 @@ function leftDescriptor(left, defaultType, leftType) {
24
54
  },
25
55
  };
26
56
  }
57
+ const rawLeft = left;
58
+ if (typeof rawLeft === "string" && rawLeft.startsWith(UNRESOLVED_REFERENCE_MARKER)) {
59
+ return {
60
+ leftValue: {
61
+ type: "REFERENCE",
62
+ realType: leftType ?? defaultType,
63
+ // Raw pass-through, recognized by to-tf.ts's filterReferenceToTf -
64
+ // bypasses the typed TRIGGER/TASK/FOR_EACH dispatch entirely since
65
+ // there is no typed ref to dispatch on, only the original wire
66
+ // string preserved verbatim from pull.
67
+ value: { __rawFilterReference: rawLeft.slice(UNRESOLVED_REFERENCE_MARKER.length) },
68
+ },
69
+ };
70
+ }
27
71
  return { field: left };
28
72
  }
29
73
  /** The value type to compare against — from the FieldRef's fieldType, or the operator's (possibly overridden) default when the LHS is a Ref. */
30
74
  function leftValueType(left, defaultType, leftType) {
31
- return isRefLeft(left) ? (leftType ?? defaultType) : fieldTypeToValueType(left.fieldType);
75
+ if (isRefLeft(left))
76
+ return leftType ?? defaultType;
77
+ const rawLeft = left;
78
+ if (typeof rawLeft === "string" && rawLeft.startsWith(UNRESOLVED_REFERENCE_MARKER))
79
+ return leftType ?? defaultType;
80
+ return fieldTypeToValueType(left.fieldType);
32
81
  }
33
82
  /** Map a filter value to the platform's `Value` wire shape, typed `vt`. */
34
83
  function value(vt, v) {
84
+ if (isCurrentUserValue(v))
85
+ return { type: "CURRENT_USER", currentUserType: v.currentUserType };
35
86
  if (isRef(v)) {
36
87
  // A `static` ref (`val(…)`) is a literal in disguise — unwrap it so it
37
88
  // emits as a plain typed value rather than a REFERENCE the platform
@@ -89,7 +140,7 @@ export function like(left, v, options, leftType) {
89
140
  ...leftDescriptor(left, "TEXT", leftType),
90
141
  value: value(vt, v),
91
142
  ...(options?.not ? { not: true } : {}),
92
- ...(options?.caseInsensitive ? { caseInsensitive: true } : {}),
143
+ ...(options?.caseInsensitive !== undefined ? { caseInsensitive: options.caseInsensitive } : {}),
93
144
  ...(options?.mode ? { mode: options.mode } : {}),
94
145
  };
95
146
  }
@@ -1,36 +1,35 @@
1
+ import { type TfBlock, type TfDocument } from "../../engine/tf/index.js";
2
+ import type { AutomationAst } from "./deserializer/ast.js";
3
+ export interface AutomationFromTfResult {
4
+ readonly refName: string;
5
+ readonly tfLabel: string;
6
+ readonly ast: AutomationAst;
7
+ readonly blocks: readonly TfBlock[];
8
+ }
1
9
  /**
2
- * Automation extraction (Phase 1). `automationFromTf` consumes the composite
3
- * HCL blocks for ONE automation (its `elementum_automation` + trigger + task
4
- * blocks + `elementum_workflow_publish`) and produces the `AutomationAst` the
5
- * existing `printAutomationV2` renders to editable `.ts`.
6
- *
7
- * Task ORDER is reconstructed by walking the `parent` chain from the trigger:
8
- * the first task's `parent` is the trigger, each subsequent task's `parent` is
9
- * its predecessor. Unimplemented trigger/task kinds are REPORTED (plan §6),
10
- * never silently dropped — but note a kind we can't reconstruct also can't be
11
- * adopted (see module.ts), so in a full pull they never reach here.
12
- *
13
- * Per the tranche's typing decision: rather than a name-allowlist drift-guard
14
- * (the agent-tool `KNOWN_TOOL_ATTRS` pattern), each IMPLEMENTED kind has its own
15
- * small typed extractor naming the wire fields it reads. The declared-only kinds
16
- * carry no extractor — they are metadata for reporting, never parsed.
10
+ * Best-effort resource footprint of one automation, used ONLY when whole-
11
+ * automation extraction throws (module.ts's `extractAutomations` catch
12
+ * branch) so adoption can exclude the FULL graph - not just the automation
13
+ * root - from its import scope. Without this, a trigger/task/branch/publish
14
+ * address is individually still an "adoptable" resource TYPE (the kind
15
+ * works fine for OTHER automations), so it gets imported into state anyway;
16
+ * build then can't reproduce what it never wrote to source, and `plan`
17
+ * shows those addresses as destroy-on-apply (confirmed live: several
18
+ * automations that failed extraction were imported into state anyway,
19
+ * driving spurious destroys). Deliberately lenient - tolerant of the exact
20
+ * conditions that make real extraction fail (zero/multiple triggers, an
21
+ * unrecognized task kind) - so it over-collects rather than under-collects:
22
+ * a false positive here just leaves one more resource unmanaged, a false
23
+ * negative would silently destroy a live automation on apply.
17
24
  */
18
- import { type TfBlock } from "../../engine/tf/index.js";
19
- import type { AutomationAst } from "./deserializer/ast.js";
25
+ export declare function automationOwnedAddresses(doc: TfDocument, automationLabel: string): readonly string[];
20
26
  export interface AutomationFromTfContext {
21
- /** The owning app's refName — becomes `AutomationAst.ownerHandle` (catalog.<owner>). */
22
27
  readonly ownerHandle: string;
23
28
  readonly diagnostics: string[];
24
29
  }
25
- export interface AutomationFromTfResult {
30
+ export interface AutomationGraphFromTfResult {
26
31
  readonly automation?: AutomationAst;
27
32
  readonly skippedReason?: string;
28
33
  }
29
- /**
30
- * Reconstruct one automation. `blocks` are the family blocks that belong to it
31
- * (already grouped by the caller: same `automation` ref / workflow_publish
32
- * depends_on set). Returns `{ automation }` or `{ skippedReason }`.
33
- */
34
- export declare function automationFromTf(blocks: readonly TfBlock[], ctx: AutomationFromTfContext): AutomationFromTfResult;
35
- /** Recognizes the blocks that make up automation families (for the pull partition). */
36
- export declare function isAutomationFamilyType(type: string | undefined): boolean;
34
+ export declare function automationFromTf(blocks: readonly TfBlock[], ctx: AutomationFromTfContext): AutomationGraphFromTfResult;
35
+ export declare function automationFromTf(doc: TfDocument, automationLabel: string, appRefName: string): AutomationFromTfResult;