@elementumai/edk 0.11.0 → 0.12.0

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 (72) hide show
  1. package/README.md +38 -6
  2. package/dist-sdk/src/core/triggers/on-demand.d.ts +2 -0
  3. package/dist-sdk/src/core/triggers/on-demand.js +3 -0
  4. package/dist-sdk/src/engine/coverage-gaps.d.ts +5 -0
  5. package/dist-sdk/src/engine/coverage-gaps.js +9 -0
  6. package/dist-sdk/src/engine/ei/run.d.ts +20 -1
  7. package/dist-sdk/src/engine/ei/run.js +102 -14
  8. package/dist-sdk/src/engine/pull/ref-only.d.ts +18 -0
  9. package/dist-sdk/src/engine/pull/ref-only.js +52 -0
  10. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +2 -1
  11. package/dist-sdk/src/entities/access-policy/from-tf.js +7 -1
  12. package/dist-sdk/src/entities/access-policy/module.js +5 -0
  13. package/dist-sdk/src/entities/app/build.d.ts +1 -1
  14. package/dist-sdk/src/entities/app/build.js +79 -4
  15. package/dist-sdk/src/entities/app/from-tf.js +1 -2
  16. package/dist-sdk/src/entities/app/stage-keys.d.ts +18 -3
  17. package/dist-sdk/src/entities/app/stage-keys.js +40 -6
  18. package/dist-sdk/src/entities/app/to-tf.js +1 -0
  19. package/dist-sdk/src/entities/automation/build.d.ts +50 -24
  20. package/dist-sdk/src/entities/automation/build.js +16 -6
  21. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +32 -3
  22. package/dist-sdk/src/entities/automation/from-tf.d.ts +13 -2
  23. package/dist-sdk/src/entities/automation/from-tf.js +269 -63
  24. package/dist-sdk/src/entities/automation/index.d.ts +1 -1
  25. package/dist-sdk/src/entities/automation/module.js +1 -1
  26. package/dist-sdk/src/entities/automation/run-target.d.ts +2 -0
  27. package/dist-sdk/src/entities/automation/run-target.js +5 -0
  28. package/dist-sdk/src/entities/automation/script-code.d.ts +2 -1
  29. package/dist-sdk/src/entities/automation/script-code.js +82 -1
  30. package/dist-sdk/src/entities/automation/script-lint.d.ts +13 -0
  31. package/dist-sdk/src/entities/automation/script-lint.js +418 -0
  32. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +1 -1
  33. package/dist-sdk/src/entities/automation/task-output-labels.js +9 -1
  34. package/dist-sdk/src/entities/automation/tasks.d.ts +47 -14
  35. package/dist-sdk/src/entities/automation/tasks.js +18 -4
  36. package/dist-sdk/src/entities/automation/to-tf.js +256 -28
  37. package/dist-sdk/src/entities/automation/triggers.d.ts +48 -15
  38. package/dist-sdk/src/entities/automation/triggers.js +9 -9
  39. package/dist-sdk/src/entities/chart/build.d.ts +9 -1
  40. package/dist-sdk/src/entities/chart/from-tf.d.ts +2 -2
  41. package/dist-sdk/src/entities/chart/from-tf.js +25 -1
  42. package/dist-sdk/src/entities/chart/index.d.ts +1 -1
  43. package/dist-sdk/src/entities/chart/printer.js +5 -2
  44. package/dist-sdk/src/entities/chart/to-tf.js +19 -1
  45. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +1 -0
  46. package/dist-sdk/src/entities/dynamic-layout/condition-keys.d.ts +48 -0
  47. package/dist-sdk/src/entities/dynamic-layout/condition-keys.js +261 -0
  48. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +1 -1
  49. package/dist-sdk/src/entities/dynamic-layout/module.js +2 -1
  50. package/dist-sdk/src/entities/element/to-tf.js +1 -0
  51. package/dist-sdk/src/entities/field/module.js +8 -2
  52. package/dist-sdk/src/entities/field/to-tf.d.ts +8 -2
  53. package/dist-sdk/src/entities/field/to-tf.js +57 -34
  54. package/dist-sdk/src/entities/org/role.js +5 -0
  55. package/dist-sdk/src/entities/service-account/module.js +5 -0
  56. package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +5 -5
  57. package/dist-sdk/src/entities/service-account/role-fidelity.js +21 -13
  58. package/dist-sdk/src/entities/shared/filters/ast.d.ts +2 -0
  59. package/dist-sdk/src/entities/shared/types/field-types.d.ts +6 -3
  60. package/dist-sdk/src/entities/shared/types/field-types.js +3 -1
  61. package/dist-sdk/src/entities/skill/module.js +2 -0
  62. package/dist-sdk/src/entities/task/to-tf.js +1 -0
  63. package/dist-sdk/src/entities/view/from-tf.d.ts +8 -4
  64. package/dist-sdk/src/entities/view/from-tf.js +3 -5
  65. package/dist-sdk/src/entities/view/module.js +5 -0
  66. package/dist-sdk/src/entities/widget/from-tf.js +2 -2
  67. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +5 -3
  68. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  69. package/dist-sdk/src/graph/index.d.ts +15 -2
  70. package/dist-sdk/src/graph/index.js +12 -0
  71. package/dist-sdk/src/graph/types.d.ts +38 -0
  72. package/package.json +1 -1
package/README.md CHANGED
@@ -51,6 +51,25 @@ elementum auth login --profile <profile>
51
51
  elementum --profile=<profile> auth status
52
52
  ```
53
53
 
54
+ `auth login` asks how to sign in. **Browser** (recommended) needs only your
55
+ Elementum URL: the browser opens, you click **Approve**, and the organization,
56
+ environment and profile name are filled in from the URL. Pass the URL to skip
57
+ the form, with or without a terminal:
58
+
59
+ ```sh
60
+ elementum auth login --url https://acme.elementum.io
61
+ ```
62
+
63
+ A browser login stores no client secret. Its tokens are kept in the OS keychain
64
+ and renew automatically for 30 days from the last use, up to 90 days from the
65
+ sign-in; approving requires the CREATE_OAUTH_TOKENS permission in the org.
66
+ It works for every command, `plan` and `apply` included. `auth env` prints its
67
+ current access token (good for up to 24 hours, it does not renew), and `auth
68
+ export` carries the profile's settings without its tokens, so you sign in once
69
+ on the other machine. **Client ID and secret** (from an OAuth token created on
70
+ the OAuth settings page) remains available, for CI and other places where no
71
+ one can click Approve.
72
+
54
73
  A profile selects the organization, instance, optional organization
55
74
  environment, credentials, and custom endpoints. Pass it explicitly before any
56
75
  command when reproducibility matters:
@@ -203,7 +222,9 @@ elementum plan --smart [--base <branch>] [orgRoot-or-nested-target] [bridge args
203
222
  elementum apply --smart [--base <branch>] [orgRoot-or-nested-target] [-auto-approve] [bridge args...]
204
223
 
205
224
  elementum list apps|elements|users|groups|categories|cloud-links
206
- elementum list ai-provider-connectors|automations|tables
225
+ elementum list ai-provider-connectors|automations|tables|portals
226
+ elementum list relationships <namespace-or-id> [--json] # read-only: the related end and column mappings of each relationship
227
+ elementum apps export <namespace> [--recursive=false] [--directory <dir>] # raw Terraform export (runs the bridge's `ei apps export`)
207
228
  elementum new category --name "Operations"
208
229
  elementum new app --name "Support Tickets" --namespace support --category "Operations" --handle SUPPORT
209
230
  elementum new element --name "Locations" --namespace locations --category "Operations" --handle LOCATION
@@ -219,6 +240,15 @@ elementum playbooks list|install|status|path|print
219
240
  `auth` and other bridge-owned commands route through the managed bridge. Run
220
241
  `elementum --help` for the combined local and bridge command surface.
221
242
 
243
+ `elementum apps export` is the supported way to get a raw Terraform export of a
244
+ live app. It is a pass-through to the bridge's `ei apps export`, which does the
245
+ work: the same flags, the same output, and the same exit code. When an export
246
+ stops on an incomplete read, the error names the read. If the platform sent
247
+ errors, it also gives their message and ends with a `[not retried: …]` or
248
+ `[retries exhausted …]` detail. A stop with no platform errors (for example a
249
+ null workflow and no GraphQL errors) has no bracket. Report the error as
250
+ printed. Use `elementum apps export` rather than calling `ei` directly.
251
+
222
252
  `build` loads app, element, and supported child authoring files and replaces its
223
253
  marker-owned files under `.tf/out/`; it never calls the platform. `plan` and
224
254
  `apply` run from `.tf/out/`, initialize OpenTofu there when necessary, and
@@ -287,10 +317,12 @@ The server exposes `run` (any CLI command as argument tokens after
287
317
  login, auth-check, pull/build/plan/apply, and pass profiles. Nested
288
318
  `mcp`/`canvas`/`chat` are refused, as are `auth env` / `auth export` /
289
319
  `auth import` (credential dump or passphrase TTY). `auth login` over MCP is
290
- non-interactive: it reads `ELEMENTUM_ORGANIZATION`, `ELEMENTUM_INSTANCE`,
291
- `ELEMENTUM_CLIENT_ID`, `ELEMENTUM_CLIENT_SECRET`, and optional
292
- `ELEMENTUM_PROFILE` (or the matching flags) and persists a profile. A human
293
- TTY login still uses the form. `apply` still goes through the real CLI; after
320
+ non-interactive. With `["auth", "login", "--url", "<the user's Elementum
321
+ URL>"]` it opens the user's browser and waits up to five minutes for them to
322
+ click **Approve**, then persists a profile. Without `--url` it reads
323
+ `ELEMENTUM_ORGANIZATION`, `ELEMENTUM_INSTANCE`, `ELEMENTUM_CLIENT_ID`,
324
+ `ELEMENTUM_CLIENT_SECRET`, and optional `ELEMENTUM_PROFILE` (or the matching
325
+ flags). A human TTY login still uses the form. `apply` still goes through the real CLI; after
294
326
  the user reviews the plan, use `["apply", "-auto-approve"]` (stdin is not a
295
327
  TTY, so a bare apply cannot prompt).
296
328
 
@@ -643,7 +675,7 @@ GitHub Actions job (the public signed toolchain is macOS-only today) looks like:
643
675
  ```yaml
644
676
  jobs:
645
677
  apply:
646
- runs-on: macos-14
678
+ runs-on: macos-26
647
679
  concurrency:
648
680
  group: elementum-prod
649
681
  cancel-in-progress: false
@@ -140,6 +140,8 @@ type WireDefaultValue = {
140
140
  datetime: string;
141
141
  } | {
142
142
  userId: OnDemandUserDefault;
143
+ } | {
144
+ groupId: string;
143
145
  } | {
144
146
  attachmentId: string;
145
147
  };
@@ -89,6 +89,9 @@ function wrapDefaultValueForWire(alias, value) {
89
89
  }
90
90
  return { userId: { __kind: "user", email: user.email } };
91
91
  }
92
+ case "groupId":
93
+ // A group's platform id, like attachmentId's (#2204).
94
+ return { groupId: value };
92
95
  case "attachmentId":
93
96
  return { attachmentId: value };
94
97
  case "record":
@@ -13,8 +13,13 @@
13
13
  * - the unbumped-automation revision reminder
14
14
  * - a live runAutomation call into a record input the platform already runs
15
15
  * (edk#2250; the mapping is emitted, and the called workflow fails at run time)
16
+ * - a synchronous Dynamic Reference runAutomation inside a forEach (edk#1870;
17
+ * the task is emitted, and the caller never resumes at run time)
16
18
  * - the custom-view non-PanesBlock root hint (check.mjs `warn`; the layout is
17
19
  * emitted exactly as authored, edk#1771)
20
+ * - the executeScript lint for an undeclared input, an output no return sets
21
+ * (edk#2286), or a script with no top-level return (edk#2364); the script is
22
+ * emitted as authored
18
23
  *
19
24
  * The ~600 emit sites push free-form `"<where>: <what>; dropped"` strings.
20
25
  * Rather than rewrite every site, they are classified here, where they leave
@@ -13,8 +13,13 @@
13
13
  * - the unbumped-automation revision reminder
14
14
  * - a live runAutomation call into a record input the platform already runs
15
15
  * (edk#2250; the mapping is emitted, and the called workflow fails at run time)
16
+ * - a synchronous Dynamic Reference runAutomation inside a forEach (edk#1870;
17
+ * the task is emitted, and the caller never resumes at run time)
16
18
  * - the custom-view non-PanesBlock root hint (check.mjs `warn`; the layout is
17
19
  * emitted exactly as authored, edk#1771)
20
+ * - the executeScript lint for an undeclared input, an output no return sets
21
+ * (edk#2286), or a script with no top-level return (edk#2364); the script is
22
+ * emitted as authored
18
23
  *
19
24
  * The ~600 emit sites push free-form `"<where>: <what>; dropped"` strings.
20
25
  * Rather than rewrite every site, they are classified here, where they leave
@@ -26,6 +31,10 @@ const ADVISORY_DIAGNOSTICS = [
26
31
  INPUT_COVERAGE,
27
32
  /^automation \S+: compiled steps changed since the last apply but its revision is still /,
28
33
  /^automation \S+: maps automation /,
34
+ // edk#1870. The task and loop names are quoted as authored and may contain `"`, so match them with
35
+ // [\s\S]* and anchor on the fixed rest of the message, end included (the label is a sanitized TF label).
36
+ /^automation \S+: task "[\s\S]*" is a synchronous Dynamic Reference runAutomation inside forEach "[\s\S]*"; the platform never resumes the caller after the called automation finishes, so the steps after it never run and the run stays parked\. Move the call out of the forEach, or call a known automation by its catalog ref \(Select Automation\)$/,
37
+ /^automation \S+: executeScript ".*" (?:reads input|declares output|has no top-level return) /,
29
38
  /^applied-automation-revisions\.json .*; until then no automation is checked for an edit without a revision bump$/,
30
39
  /\.root: "[^"]*" is (?:untyped|a [A-Za-z0-9_]+); the root is usually a PanesBlock \(needed for record lists to open the details pane\)$/,
31
40
  ];
@@ -166,10 +166,27 @@ export type TofuJsonEvent = {
166
166
  } | {
167
167
  readonly type: "diagnostic";
168
168
  readonly level: "INFO" | "WARN" | "ERROR";
169
+ /** `summary: detail`, as logged. */
169
170
  readonly message: string;
171
+ readonly summary: string;
172
+ readonly detail?: string;
173
+ /** Where OpenTofu says the error is (`range` and `address`), when it says. */
174
+ readonly location?: TofuDiagnosticLocation;
170
175
  } | {
171
176
  readonly type: "other";
172
177
  };
178
+ /**
179
+ * Where an OpenTofu diagnostic points: the file and line from its location
180
+ * line or JSON `range`, and the resource address from its `with` line or JSON
181
+ * `address` (edk#2295). Names only; never a snippet or a value.
182
+ */
183
+ export interface TofuDiagnosticLocation {
184
+ readonly file?: string;
185
+ readonly line?: number;
186
+ readonly address?: string;
187
+ }
188
+ /** `automations.tf line 27, elementum_x.y`: the location as one parenthetical. */
189
+ export declare function formatTofuDiagnosticLocation(location: TofuDiagnosticLocation): string;
173
190
  /** Parse the stable subset of OpenTofu's line-delimited JSON UI used by adoption. */
174
191
  export declare function parseTofuJsonEvent(line: string): TofuJsonEvent;
175
192
  /** Capture both bridge output streams for small machine-inspection commands. */
@@ -186,6 +203,8 @@ export declare function capTofuDiagnostics(diagnostics: readonly string[], max?:
186
203
  * Error diagnostics from a failed OpenTofu run: `diagnostic` events with
187
204
  * severity error from `-json` stdout, plus human `Error:` blocks from stderr.
188
205
  * Deduplicated, in order. Used to explain why `ei plan` failed instead of
189
- * discarding its output (edk#1402).
206
+ * discarding its output (edk#1402). Each names the file, line and resource
207
+ * address OpenTofu reported, right after the summary (edk#2295):
208
+ * `Invalid index (automations.tf line 27, elementum_x.y): The given key …`.
190
209
  */
191
210
  export declare function tofuErrorDiagnostics(stdout: string | undefined, stderr: string | undefined): string[];
@@ -1001,6 +1001,26 @@ export function runEiCapture(args, opts) {
1001
1001
  });
1002
1002
  });
1003
1003
  }
1004
+ function jsonDiagnosticLocation(fields) {
1005
+ const range = typeof fields.range === "object" && fields.range !== null ? fields.range : undefined;
1006
+ const file = typeof range?.filename === "string" && range.filename !== "" ? range.filename : undefined;
1007
+ const start = typeof range?.start === "object" && range.start !== null ? range.start : undefined;
1008
+ const line = typeof start?.line === "number" && Number.isInteger(start.line) && start.line > 0 ? start.line : undefined;
1009
+ // OpenTofu sets `address` only for some diagnostics; `snippet.context` is
1010
+ // the enclosing block header (`resource "type" "name"`), never the code.
1011
+ const snippet = typeof fields.snippet === "object" && fields.snippet !== null ? fields.snippet : undefined;
1012
+ const address = typeof fields.address === "string" && fields.address !== ""
1013
+ ? fields.address
1014
+ : typeof snippet?.context === "string" ? blockAddress(snippet.context) : undefined;
1015
+ if (file === undefined && address === undefined)
1016
+ return undefined;
1017
+ return { ...(file !== undefined ? { file } : {}), ...(file !== undefined && line !== undefined ? { line } : {}), ...(address !== undefined ? { address } : {}) };
1018
+ }
1019
+ /** `automations.tf line 27, elementum_x.y`: the location as one parenthetical. */
1020
+ export function formatTofuDiagnosticLocation(location) {
1021
+ const where = location.file === undefined ? undefined : location.line === undefined ? location.file : `${location.file} line ${location.line}`;
1022
+ return [where, location.address].filter((part) => part !== undefined).join(", ");
1023
+ }
1004
1024
  /** Parse the stable subset of OpenTofu's line-delimited JSON UI used by adoption. */
1005
1025
  export function parseTofuJsonEvent(line) {
1006
1026
  try {
@@ -1028,9 +1048,17 @@ export function parseTofuJsonEvent(line) {
1028
1048
  const fields = diagnostic;
1029
1049
  if (typeof fields.summary !== "string")
1030
1050
  return { type: "other" };
1031
- const detail = typeof fields.detail === "string" && fields.detail !== "" ? `: ${fields.detail}` : "";
1051
+ const detail = typeof fields.detail === "string" && fields.detail !== "" ? fields.detail : undefined;
1032
1052
  const level = fields.severity === "error" ? "ERROR" : fields.severity === "warning" ? "WARN" : "INFO";
1033
- return { type: "diagnostic", level, message: fields.summary + detail };
1053
+ const location = jsonDiagnosticLocation(fields);
1054
+ return {
1055
+ type: "diagnostic",
1056
+ level,
1057
+ message: detail !== undefined ? `${fields.summary}: ${detail}` : fields.summary,
1058
+ summary: fields.summary,
1059
+ ...(detail !== undefined ? { detail } : {}),
1060
+ ...(location !== undefined ? { location } : {}),
1061
+ };
1034
1062
  }
1035
1063
  return { type: "other" };
1036
1064
  }
@@ -1228,6 +1256,39 @@ const TOFU_SNIPPET_LINE = /^(?:\d+:|[\u251c\u2502\u2514]|\(and \d+ more\))/;
1228
1256
  /** `with var.x,` / `on main.tf line 4, in …:` lines; only dropped inside the leading location block. */
1229
1257
  const TOFU_WITH_LINE = /^with [^ ]+,$/;
1230
1258
  const TOFU_LOCATION_LINE = /^on .+ line \d+(?:, in .+)?:$/;
1259
+ /** The parts of a location line: file, line and the optional `in <block>`. */
1260
+ const TOFU_LOCATION_PARTS = /^on (.+) line (\d+)(?:, in (.+))?:$/;
1261
+ /** `resource "type" "name"` / `data "type" "name"`: a block header. */
1262
+ const TOFU_BLOCK_ADDRESS = /^(resource|data) "([^"]+)" "([^"]+)"$/;
1263
+ /** Any other top-level block header: `output "x"`, `module "m"`, `locals`. */
1264
+ const TOFU_BLOCK_HEADER = /^[a-z_]+(?: "[^"]+")?$/;
1265
+ /** The address a block header names: `type.name`, `data.type.name`, or the header as written. */
1266
+ function blockAddress(header) {
1267
+ const block = TOFU_BLOCK_ADDRESS.exec(header);
1268
+ if (block !== null)
1269
+ return block[1] === "data" ? `data.${block[2]}.${block[3]}` : `${block[2]}.${block[3]}`;
1270
+ return TOFU_BLOCK_HEADER.test(header) ? header : undefined;
1271
+ }
1272
+ /**
1273
+ * The location a human `Error:` block's leading paragraph names. The `with`
1274
+ * line carries the instance address; without one, a `resource`/`data` block
1275
+ * header gives the block address, and any other block (`output "x"`, `locals`)
1276
+ * is kept as written. Snippet and value lines are never read here.
1277
+ */
1278
+ function humanDiagnosticLocation(paragraph) {
1279
+ // Only the header lines: `with <address>,` then `on <file> line N, in …:`.
1280
+ const header = paragraph.slice(0, 2);
1281
+ const withLine = header.find((l) => TOFU_WITH_LINE.test(l));
1282
+ const withAddress = withLine?.slice("with ".length, -1);
1283
+ const parts = header.map((l) => TOFU_LOCATION_PARTS.exec(l)).find((m) => m !== null);
1284
+ const address = withAddress ?? (parts?.[3] !== undefined ? blockAddress(parts[3]) : undefined);
1285
+ if (parts === undefined && address === undefined)
1286
+ return undefined;
1287
+ return {
1288
+ ...(parts !== undefined ? { file: parts[1], line: Number(parts[2]) } : {}),
1289
+ ...(address !== undefined ? { address } : {}),
1290
+ };
1291
+ }
1231
1292
  /** Cap a diagnostic list to `max` entries, adding an "… and N more" line. */
1232
1293
  export function capTofuDiagnostics(diagnostics, max = TOFU_DIAGNOSTIC_MAX_ENTRIES) {
1233
1294
  if (diagnostics.length <= max)
@@ -1238,26 +1299,51 @@ export function capTofuDiagnostics(diagnostics, max = TOFU_DIAGNOSTIC_MAX_ENTRIE
1238
1299
  * Error diagnostics from a failed OpenTofu run: `diagnostic` events with
1239
1300
  * severity error from `-json` stdout, plus human `Error:` blocks from stderr.
1240
1301
  * Deduplicated, in order. Used to explain why `ei plan` failed instead of
1241
- * discarding its output (edk#1402).
1302
+ * discarding its output (edk#1402). Each names the file, line and resource
1303
+ * address OpenTofu reported, right after the summary (edk#2295):
1304
+ * `Invalid index (automations.tf line 27, elementum_x.y): The given key …`.
1242
1305
  */
1243
1306
  export function tofuErrorDiagnostics(stdout, stderr) {
1244
1307
  const out = [];
1245
- const seen = new Set();
1246
- const add = (message) => {
1247
- let trimmed = message.replace(/\s+/g, " ").trim();
1248
- if (trimmed.length > TOFU_DIAGNOSTIC_MAX_CHARS)
1249
- trimmed = `${trimmed.slice(0, TOFU_DIAGNOSTIC_MAX_CHARS)}… (truncated)`;
1250
- if (trimmed === "" || seen.has(trimmed))
1308
+ // The same error can come from JSON and from stderr: keep it once, and let
1309
+ // the copy that names a location replace one that doesn't. The same error
1310
+ // on two resources stays two entries.
1311
+ const texts = new Set();
1312
+ const byKey = new Map();
1313
+ const clean = (text) => text.replace(/\s+/g, " ").trim();
1314
+ const add = (summary, detail, location) => {
1315
+ const cleanSummary = clean(summary);
1316
+ const cleanDetail = detail === undefined ? "" : clean(detail);
1317
+ const key = cleanDetail !== "" ? `${cleanSummary}: ${cleanDetail}` : cleanSummary;
1318
+ if (key === "")
1319
+ return;
1320
+ const where = location === undefined ? "" : clean(formatTofuDiagnosticLocation(location));
1321
+ const head = where !== "" ? `${cleanSummary} (${where})` : cleanSummary;
1322
+ let text = cleanDetail !== "" ? `${head}: ${cleanDetail}` : head;
1323
+ if (text.length > TOFU_DIAGNOSTIC_MAX_CHARS)
1324
+ text = `${text.slice(0, TOFU_DIAGNOSTIC_MAX_CHARS)}… (truncated)`;
1325
+ if (texts.has(text))
1251
1326
  return;
1252
- seen.add(trimmed);
1253
- out.push(trimmed);
1327
+ const same = byKey.get(key) ?? [];
1328
+ if (where === "" && same.length > 0)
1329
+ return;
1330
+ const unlocated = where !== "" ? same.find((entry) => !entry.located) : undefined;
1331
+ texts.add(text);
1332
+ if (unlocated !== undefined) {
1333
+ out[unlocated.index] = text;
1334
+ unlocated.located = true;
1335
+ return;
1336
+ }
1337
+ same.push({ index: out.length, located: where !== "" });
1338
+ byKey.set(key, same);
1339
+ out.push(text);
1254
1340
  };
1255
1341
  for (const line of (stdout ?? "").split("\n")) {
1256
1342
  if (line.trim() === "")
1257
1343
  continue;
1258
1344
  const event = parseTofuJsonEvent(line);
1259
1345
  if (event.type === "diagnostic" && event.level === "ERROR")
1260
- add(event.message);
1346
+ add(event.summary, event.detail, event.location);
1261
1347
  }
1262
1348
  const lines = (stderr ?? "").split("\n").map((l) => l.replace(ANSI_SEQUENCE, "").replace(/\r$/, ""));
1263
1349
  for (let i = 0; i < lines.length; i++) {
@@ -1268,7 +1354,8 @@ export function tofuErrorDiagnostics(stdout, stderr) {
1268
1354
  // text output is: Error line, blank, location + source snippet (+ optional
1269
1355
  // ├──/│ expression values), blank, explanation. Drop the location paragraph
1270
1356
  // and any snippet/value lines so only the explanation is kept; snippets can
1271
- // carry config literals and non-sensitive variable values.
1357
+ // carry config literals and non-sensitive variable values. The location
1358
+ // paragraph's file, line and address are kept (edk#2295).
1272
1359
  const paragraphs = [[]];
1273
1360
  for (let j = i + 1; j < lines.length; j++) {
1274
1361
  const raw = lines[j];
@@ -1288,13 +1375,14 @@ export function tofuErrorDiagnostics(stdout, stderr) {
1288
1375
  // no line filter can recognise. Line filters remain a second layer for
1289
1376
  // snippet/value lines elsewhere.
1290
1377
  const isLocationBlock = (p) => TOFU_WITH_LINE.test(p[0]) || TOFU_LOCATION_LINE.test(p[0]);
1378
+ const location = nonEmpty.length > 0 && isLocationBlock(nonEmpty[0]) ? humanDiagnosticLocation(nonEmpty[0]) : undefined;
1291
1379
  const detail = nonEmpty
1292
1380
  .filter((p, idx) => !(idx === 0 && isLocationBlock(p)))
1293
1381
  .map((p) => p.filter((l) => !TOFU_SNIPPET_LINE.test(l)))
1294
1382
  .filter((p) => p.length > 0)
1295
1383
  .map((p) => p.join(" "))
1296
1384
  .join(" ");
1297
- add(detail !== "" ? `${match[1]}: ${detail}` : match[1]);
1385
+ add(match[1], detail !== "" ? detail : undefined, location);
1298
1386
  }
1299
1387
  return out;
1300
1388
  }
@@ -58,3 +58,21 @@ export declare function fieldDataReferenceMap(doc: TfDocument, roots: readonly D
58
58
  readonly fieldName?: string;
59
59
  readonly fieldType?: string;
60
60
  }>;
61
+ /** A field identity an earlier pull recorded for a managed app or element. */
62
+ export interface ManagedFieldNameIdentity {
63
+ readonly ownerRefName: string;
64
+ readonly fieldKey: string;
65
+ readonly fieldName?: string;
66
+ }
67
+ /**
68
+ * Point a managed root's ref-only fields at the keys its source authors.
69
+ *
70
+ * The export keys a field by its current display name. A managed root keeps
71
+ * the authored key across a UI rename, and build addresses that key. A
72
+ * system-tagged field already carries its canonical key (`title`, `id`, …),
73
+ * which a display-name lookup must not replace. A display name that belongs
74
+ * to more than one field on that owner is left on the export key: the name
75
+ * index is last-write-wins and would otherwise stamp one survivor onto both.
76
+ * `refOnly:` guesses are not identities, so they do not count.
77
+ */
78
+ export declare function withManagedRefOnlyIdentity<T extends DirectReferenceRoot>(root: T, managedRefName: string, fieldRefsById: ReadonlyMap<string, ManagedFieldNameIdentity> | undefined): T;
@@ -283,3 +283,55 @@ export function fieldDataReferenceMap(doc, roots) {
283
283
  }
284
284
  return out;
285
285
  }
286
+ /**
287
+ * Point a managed root's ref-only fields at the keys its source authors.
288
+ *
289
+ * The export keys a field by its current display name. A managed root keeps
290
+ * the authored key across a UI rename, and build addresses that key. A
291
+ * system-tagged field already carries its canonical key (`title`, `id`, …),
292
+ * which a display-name lookup must not replace. A display name that belongs
293
+ * to more than one field on that owner is left on the export key: the name
294
+ * index is last-write-wins and would otherwise stamp one survivor onto both.
295
+ * `refOnly:` guesses are not identities, so they do not count.
296
+ */
297
+ export function withManagedRefOnlyIdentity(root, managedRefName, fieldRefsById) {
298
+ const authoredKeyByName = uniqueAuthoredFieldKeys(fieldRefsById, managedRefName);
299
+ return {
300
+ ...root,
301
+ refName: managedRefName,
302
+ fields: root.fields.map((field) => {
303
+ const authoredKey = systemFieldTag(field) === undefined
304
+ ? authoredKeyByName.get(field.name.toLowerCase())
305
+ : undefined;
306
+ return {
307
+ ...field,
308
+ parent: managedRefName,
309
+ ...(authoredKey !== undefined ? { refName: authoredKey } : {}),
310
+ };
311
+ }),
312
+ };
313
+ }
314
+ function uniqueAuthoredFieldKeys(fieldRefsById, ownerRefName) {
315
+ const counts = new Map();
316
+ const keys = new Map();
317
+ if (fieldRefsById === undefined)
318
+ return keys;
319
+ for (const [id, identity] of fieldRefsById) {
320
+ if (id.startsWith("refOnly:"))
321
+ continue;
322
+ if (identity.ownerRefName !== ownerRefName)
323
+ continue;
324
+ const name = identity.fieldName;
325
+ if (name === undefined || name === "")
326
+ continue;
327
+ const lower = name.toLowerCase();
328
+ counts.set(lower, (counts.get(lower) ?? 0) + 1);
329
+ if (!keys.has(lower))
330
+ keys.set(lower, identity.fieldKey);
331
+ }
332
+ for (const [lower, count] of counts) {
333
+ if (count !== 1)
334
+ keys.delete(lower);
335
+ }
336
+ return keys;
337
+ }
@@ -50,7 +50,8 @@ export declare function filterFromTf(value: TfValue, owner: AccessPolicyOwner, w
50
50
  /**
51
51
  * The EDK ref of the app that owns a service-account block, read from the
52
52
  * block's `app_id`: the owner itself when that is the app the ref points at,
53
- * otherwise a foreign app the workspace knows by name or namespace. Undefined
53
+ * otherwise a foreign app the workspace knows by name or namespace (a
54
+ * namespace-only `data "elementum_app"` lookup included). Undefined
54
55
  * when it doesn't resolve, so the caller drops the member.
55
56
  */
56
57
  export declare function serviceAccountAppRefName(appId: TfValue | undefined, owner: {
@@ -121,7 +121,8 @@ function stageName(value, owner, ctx) {
121
121
  /**
122
122
  * The EDK ref of the app that owns a service-account block, read from the
123
123
  * block's `app_id`: the owner itself when that is the app the ref points at,
124
- * otherwise a foreign app the workspace knows by name or namespace. Undefined
124
+ * otherwise a foreign app the workspace knows by name or namespace (a
125
+ * namespace-only `data "elementum_app"` lookup included). Undefined
125
126
  * when it doesn't resolve, so the caller drops the member.
126
127
  */
127
128
  export function serviceAccountAppRefName(appId, owner, ctx) {
@@ -130,6 +131,11 @@ export function serviceAccountAppRefName(appId, owner, ctx) {
130
131
  const appName = appDataLabel === undefined ? undefined : ctx.dataName("elementum_app", appDataLabel);
131
132
  if (appName !== undefined)
132
133
  return ctx.foreignAppRefNames?.get(appName);
134
+ // Export looks up another app's service account through its owning app by
135
+ // namespace (edk#2197).
136
+ const appNamespace = appDataLabel === undefined ? undefined : ctx.dataAttrs?.("elementum_app", appDataLabel)?.["namespace"];
137
+ if (typeof appNamespace === "string")
138
+ return ctx.foreignAppRefNamespaces?.get(appNamespace);
133
139
  if (appResourceLabel === undefined)
134
140
  return undefined;
135
141
  if (owner?.scope === "app" && owner.label === appResourceLabel)
@@ -14,6 +14,11 @@ export const accessPolicyModule = {
14
14
  lifecycle: NO_LIFECYCLE,
15
15
  canvas: { participates: true, label: "Access Policies", glyph: "🔒", component: "generic" },
16
16
  catalog: NO_CATALOG,
17
+ roundtrip: {
18
+ referenceAliases: [],
19
+ // Provider set attributes (edk#2437): order carries no meaning.
20
+ unorderedListAttributes: ["user_ids", "group_ids", "service_account_ids"],
21
+ },
17
22
  // The platform creates one for the creator with every app, element and task,
18
23
  // and it can't be told apart from the others, so a portable source has none.
19
24
  portable: {
@@ -32,7 +32,7 @@ import type { AppServiceAccount } from "../service-account/build.js";
32
32
  import type { Filter } from "../shared/filters/types.js";
33
33
  import { type DisplayBlock } from "./display-blocks.js";
34
34
  import type { CalculationInclude, Expr, ExprContext, ExprType } from "../field/calc.js";
35
- import type { UnsafePlatformId } from "../../core/platform-id.js";
35
+ import { type UnsafePlatformId } from "../../core/platform-id.js";
36
36
  /**
37
37
  * One entry of a dynamic picklist's `sort.orders` — `field` is a token on
38
38
  * the related aspect (same convention as `relatedLabelFieldId`), resolved
@@ -4,6 +4,7 @@ import { serializeDisplayBlocks } from "./display-blocks.js";
4
4
  import { assertCalculatedFieldRoot } from "../field/calc/runtime.js";
5
5
  import { assertAttachmentMediaTypes } from "../field/media-types.js";
6
6
  import { assertFieldAllowList } from "../field/allow-list.js";
7
+ import { isUnsafePlatformId } from "../../core/platform-id.js";
7
8
  /** Where a classic layout section renders: the main area or the record side panel. */
8
9
  export const layoutSectionDisplayLocation = {
9
10
  center: "CENTER",
@@ -137,15 +138,16 @@ function unwrapUnsafePlatformIds(value) {
137
138
  * added without re-running `elementum generate`) evaluates to `undefined`; the
138
139
  * TF emitter then drops the whole dynamic config, omits the field resource,
139
140
  * and the plan destroys the field. Throw instead, naming the owner, the
140
- * field's bag key and the missing ref, so the build fails closed. `filter`
141
- * operands are NOT checked here (out of scope for #1780).
141
+ * field's bag key and the missing ref, so the build fails closed. Every field
142
+ * operand inside `filter` is checked the same way (#2309): see
143
+ * {@link assertDynamicFilterRefs}.
142
144
  */
143
145
  function assertDynamicPicklistRefs(field, dynamic, refName, owner) {
144
146
  const typeLabel = field.type === "MULTI_PICKLIST" ? "Multi-Select" : "Dropdown";
145
147
  const where = `${owner !== undefined ? `${owner} ` : ""}${refName !== undefined ? `fields.${refName}` : "field"} ` +
146
148
  `(${JSON.stringify(field.name)}, dynamic ${typeLabel})`;
147
- const missing = (path) => {
148
- throw new Error(`${where}: ${path} is undefined. The catalog ref it names doesn't resolve: the referenced field, app, element ` +
149
+ const missing = (path, refersTo) => {
150
+ throw new Error(`${where}: ${path} is undefined${refersTo !== undefined ? ` (${refersTo})` : ""}. The catalog ref it names doesn't resolve: the referenced field, app, element ` +
149
151
  `or task was removed or renamed, or it was just added and the catalog hasn't been regenerated (run ` +
150
152
  `\`elementum generate\`, then build again). Building would drop this field's dynamic config and the plan ` +
151
153
  `would destroy the field; fix or remove the ref.`);
@@ -169,6 +171,79 @@ function assertDynamicPicklistRefs(field, dynamic, refName, owner) {
169
171
  missing(`config.dynamic.sort[${i}].field`);
170
172
  });
171
173
  }
174
+ if (dynamic.filter !== undefined) {
175
+ // Name where each filter field lives (#2309): a left side or `fieldValue`
176
+ // operand is a field of the Dropdown's source, a `recordField` operand a
177
+ // field of the record that owns the Dropdown.
178
+ const source = describeDynamicSource(dynamic.relatedAspectId);
179
+ const scopes = {
180
+ source: source !== undefined ? `a field of the Dropdown's source, ${source}` : "a field of the Dropdown's source",
181
+ record: `a field of ${owner ?? "the record that owns this Dropdown"}`,
182
+ };
183
+ assertDynamicFilterRefs(dynamic.filter, "config.dynamic.filter", missing, scopes);
184
+ }
185
+ }
186
+ /** `element "demoSharedVendor"` for a catalog ref, `platform id "…"` for an unsafe id; `undefined` if absent. */
187
+ function describeDynamicSource(source) {
188
+ if (source === null || typeof source !== "object")
189
+ return undefined;
190
+ if (isUnsafePlatformId(source))
191
+ return `platform id ${JSON.stringify(source.value)}`;
192
+ const ref = source;
193
+ if (typeof ref.__kind !== "string" || typeof ref.refName !== "string")
194
+ return undefined;
195
+ return `${ref.__kind} ${JSON.stringify(ref.refName)}`;
196
+ }
197
+ /** Filter types whose node carries children or nothing, not a left side. */
198
+ const DYNAMIC_FILTER_BRANCH_TYPES = new Set(["AND", "OR"]);
199
+ const DYNAMIC_FILTER_CONSTANT_TYPES = new Set(["TRUE", "FALSE"]);
200
+ /**
201
+ * A dynamic Dropdown filter's field operands must be present, the same rule as
202
+ * the refs {@link assertDynamicPicklistRefs} checks (#2309). A removed field
203
+ * evaluates to `undefined`: `filter.isNotNull(catalog.x.fields.removed)` keeps
204
+ * `field: undefined`, and `fieldValue(...)` / `recordField(...)` keep an
205
+ * `undefined` operand. The TF emitter can't build that filter, drops the whole
206
+ * dynamic config, leaves the field out, and the plan destroys it. Walks
207
+ * `and`/`or` children so the error names the exact path.
208
+ */
209
+ function assertDynamicFilterRefs(node, path, missing, scopes) {
210
+ if (node == null)
211
+ missing(path);
212
+ if (typeof node !== "object")
213
+ return;
214
+ const filter = node;
215
+ const type = typeof filter.type === "string" ? filter.type.toUpperCase() : undefined;
216
+ if (type === undefined || DYNAMIC_FILTER_CONSTANT_TYPES.has(type))
217
+ return;
218
+ if (DYNAMIC_FILTER_BRANCH_TYPES.has(type)) {
219
+ if (Array.isArray(filter.children)) {
220
+ filter.children.forEach((child, i) => assertDynamicFilterRefs(child, `${path}.children[${i}]`, missing, scopes));
221
+ }
222
+ return;
223
+ }
224
+ const hasLeft = ["field", "field_id", "leftValue", "left_value"].some((key) => Object.hasOwn(filter, key));
225
+ if (!hasLeft || (Object.hasOwn(filter, "field") && filter.field == null))
226
+ missing(`${path}.field`, scopes.source);
227
+ if (Object.hasOwn(filter, "leftValue"))
228
+ assertDynamicFilterOperand(filter.leftValue, `${path}.leftValue`, missing, scopes);
229
+ for (const key of ["value", "min", "max"]) {
230
+ if (Object.hasOwn(filter, key))
231
+ assertDynamicFilterOperand(filter[key], `${path}.${key}`, missing, scopes);
232
+ }
233
+ if (Array.isArray(filter.values)) {
234
+ filter.values.forEach((value, i) => assertDynamicFilterOperand(value, `${path}.values[${i}]`, missing, scopes));
235
+ }
236
+ }
237
+ /** A `FIELD` or `RECORD_FIELD` operand whose field is `undefined` names a removed field. */
238
+ function assertDynamicFilterOperand(operand, path, missing, scopes) {
239
+ if (operand === null || typeof operand !== "object")
240
+ return;
241
+ const value = operand;
242
+ const type = typeof value.type === "string" ? value.type.toUpperCase() : undefined;
243
+ if (type === "FIELD" && value.value == null && value.field == null && value.field_id == null)
244
+ missing(`${path}.value`, scopes.source);
245
+ if (type === "RECORD_FIELD" && value.field == null)
246
+ missing(`${path}.field`, scopes.record);
172
247
  }
173
248
  /**
174
249
  * Serialize an authored field to its `AspectFieldInput` wire shape — shared
@@ -223,8 +223,7 @@ export function appFromTf(appBlock, fieldBlocks, ctx, viewBlocks = { layoutBlock
223
223
  const unextracted = { type: APP_RESOURCE_TYPE, label, ownerTfLabel: label, scope: "app", fieldKeys, fieldKeysByName, unextractedFieldIds };
224
224
  const { layouts, listViews, calendarViews, kanbanViews, dashboardViews, agentViews, customViews, viewOrder, deleteDefaultListView } = viewsFromTf(viewBlocks.layoutBlocks, viewBlocks.listViewBlocks, viewBlocks.calendarViewBlocks, viewBlocks.kanbanViewBlocks, viewBlocks.dashboardViewBlocks, viewBlocks.agentViewBlocks, viewBlocks.managedViewOrderBlocks, {
225
225
  type: APP_RESOURCE_TYPE, label, ownerTfLabel: label, scope: "app",
226
- stageKeys: stageHandles.keys,
227
- stageKeyByHandle: stageHandles.byHandle,
226
+ stageHandles,
228
227
  fieldKeys,
229
228
  fieldKeysByName,
230
229
  unextractedFieldIds,