@elementumai/edk 0.9.10 → 0.9.12

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 (124) hide show
  1. package/README.md +39 -5
  2. package/dist-sdk/src/catalog/factories.d.ts +42 -14
  3. package/dist-sdk/src/catalog/factories.js +77 -14
  4. package/dist-sdk/src/catalog/from-authoring.js +4 -4
  5. package/dist-sdk/src/catalog/index.d.ts +2 -2
  6. package/dist-sdk/src/catalog/index.js +1 -1
  7. package/dist-sdk/src/catalog/org.js +3 -2
  8. package/dist-sdk/src/catalog/token.js +4 -0
  9. package/dist-sdk/src/catalog/types.d.ts +32 -5
  10. package/dist-sdk/src/catalog/types.js +1 -0
  11. package/dist-sdk/src/core/triggers/on-demand.d.ts +4 -28
  12. package/dist-sdk/src/core/triggers/on-demand.js +2 -4
  13. package/dist-sdk/src/engine/build/context.d.ts +3 -0
  14. package/dist-sdk/src/engine/entity.d.ts +2 -0
  15. package/dist-sdk/src/engine/logging.d.ts +90 -0
  16. package/dist-sdk/src/engine/logging.js +124 -0
  17. package/dist-sdk/src/engine/progress.d.ts +119 -0
  18. package/dist-sdk/src/engine/progress.js +647 -0
  19. package/dist-sdk/src/engine/pull/result-output.d.ts +24 -0
  20. package/dist-sdk/src/engine/pull/result-output.js +48 -0
  21. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +3 -3
  22. package/dist-sdk/src/entities/access-policy/from-tf.js +27 -8
  23. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +13 -0
  24. package/dist-sdk/src/entities/access-policy/to-tf.js +34 -3
  25. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +13 -7
  26. package/dist-sdk/src/entities/agent/tools.d.ts +2 -2
  27. package/dist-sdk/src/entities/agent-tool/to-tf.js +13 -0
  28. package/dist-sdk/src/entities/app/build.d.ts +22 -2
  29. package/dist-sdk/src/entities/app/build.js +6 -0
  30. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +13 -3
  31. package/dist-sdk/src/entities/app/from-tf.js +10 -7
  32. package/dist-sdk/src/entities/app/to-tf.js +14 -14
  33. package/dist-sdk/src/entities/automation/build.d.ts +11 -16
  34. package/dist-sdk/src/entities/automation/build.js +38 -8
  35. package/dist-sdk/src/entities/automation/catalog-render.js +1 -1
  36. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +1 -2
  37. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +23 -5
  38. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +239 -34
  39. package/dist-sdk/src/entities/automation/from-tf.js +276 -19
  40. package/dist-sdk/src/entities/automation/index.d.ts +2 -2
  41. package/dist-sdk/src/entities/automation/module.js +3 -2
  42. package/dist-sdk/src/entities/automation/output-field-types.js +25 -13
  43. package/dist-sdk/src/entities/automation/script-code.d.ts +12 -4
  44. package/dist-sdk/src/entities/automation/script-code.js +659 -101
  45. package/dist-sdk/src/entities/automation/tasks.d.ts +60 -28
  46. package/dist-sdk/src/entities/automation/tasks.js +48 -15
  47. package/dist-sdk/src/entities/automation/to-tf.d.ts +8 -0
  48. package/dist-sdk/src/entities/automation/to-tf.js +514 -103
  49. package/dist-sdk/src/entities/automation/triggers.d.ts +15 -9
  50. package/dist-sdk/src/entities/automation/triggers.js +4 -2
  51. package/dist-sdk/src/entities/automation/types.js +1 -0
  52. package/dist-sdk/src/entities/chart/build.d.ts +15 -3
  53. package/dist-sdk/src/entities/chart/build.js +6 -1
  54. package/dist-sdk/src/entities/chart/from-tf.d.ts +8 -2
  55. package/dist-sdk/src/entities/chart/from-tf.js +71 -8
  56. package/dist-sdk/src/entities/chart/index.d.ts +1 -1
  57. package/dist-sdk/src/entities/chart/index.js +1 -1
  58. package/dist-sdk/src/entities/chart/printer.js +27 -7
  59. package/dist-sdk/src/entities/chart/to-tf.js +56 -2
  60. package/dist-sdk/src/entities/dashboard/from-tf.js +11 -2
  61. package/dist-sdk/src/entities/datamine/from-tf.js +11 -1
  62. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +2 -1
  63. package/dist-sdk/src/entities/dynamic-layout/dialect.d.ts +8 -0
  64. package/dist-sdk/src/entities/dynamic-layout/dialect.js +12 -0
  65. package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +7 -0
  66. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +64 -10
  67. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +54 -6
  68. package/dist-sdk/src/entities/element/build.d.ts +8 -0
  69. package/dist-sdk/src/entities/element/from-tf.js +4 -3
  70. package/dist-sdk/src/entities/element/module.js +1 -0
  71. package/dist-sdk/src/entities/element/to-tf.d.ts +4 -1
  72. package/dist-sdk/src/entities/element/to-tf.js +28 -2
  73. package/dist-sdk/src/entities/field/build.d.ts +10 -1
  74. package/dist-sdk/src/entities/field/build.js +2 -1
  75. package/dist-sdk/src/entities/field/calc/index.js +7 -7
  76. package/dist-sdk/src/entities/field/calc/runtime.d.ts +19 -0
  77. package/dist-sdk/src/entities/field/calc/runtime.js +32 -0
  78. package/dist-sdk/src/entities/field/calc/types.d.ts +6 -0
  79. package/dist-sdk/src/entities/field/from-tf.d.ts +24 -0
  80. package/dist-sdk/src/entities/field/from-tf.js +73 -1
  81. package/dist-sdk/src/entities/field/metadata.d.ts +18 -0
  82. package/dist-sdk/src/entities/field/metadata.js +34 -0
  83. package/dist-sdk/src/entities/file-reader/to-tf.js +10 -2
  84. package/dist-sdk/src/entities/relationship/build.d.ts +27 -9
  85. package/dist-sdk/src/entities/relationship/column-contract.d.ts +24 -0
  86. package/dist-sdk/src/entities/relationship/column-contract.js +41 -0
  87. package/dist-sdk/src/entities/relationship/from-tf.js +33 -48
  88. package/dist-sdk/src/entities/relationship/to-tf.d.ts +1 -0
  89. package/dist-sdk/src/entities/relationship/to-tf.js +33 -2
  90. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +15 -0
  91. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +21 -0
  92. package/dist-sdk/src/entities/shared/context.d.ts +6 -3
  93. package/dist-sdk/src/entities/shared/context.js +19 -1
  94. package/dist-sdk/src/entities/shared/filters/index.d.ts +7 -0
  95. package/dist-sdk/src/entities/shared/filters/index.js +28 -0
  96. package/dist-sdk/src/entities/shared/filters/print.js +2 -0
  97. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +8 -1
  98. package/dist-sdk/src/entities/shared/filters/tf-codec.js +10 -6
  99. package/dist-sdk/src/entities/shared/filters/types.d.ts +1 -1
  100. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +5 -0
  101. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +52 -27
  102. package/dist-sdk/src/entities/skill/module.js +1 -0
  103. package/dist-sdk/src/entities/skill/to-tf.d.ts +1 -1
  104. package/dist-sdk/src/entities/skill/to-tf.js +17 -0
  105. package/dist-sdk/src/entities/skill/tools.d.ts +48 -12
  106. package/dist-sdk/src/entities/skill/tools.js +12 -1
  107. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +15 -12
  108. package/dist-sdk/src/entities/skill-tool/from-tf.js +50 -46
  109. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +4 -0
  110. package/dist-sdk/src/entities/skill-tool/to-tf.js +66 -7
  111. package/dist-sdk/src/entities/table/build.js +10 -2
  112. package/dist-sdk/src/entities/table/catalog-render.js +2 -1
  113. package/dist-sdk/src/entities/view/from-tf.js +9 -0
  114. package/dist-sdk/src/entities/view/to-tf.d.ts +7 -0
  115. package/dist-sdk/src/entities/view/to-tf.js +39 -12
  116. package/dist-sdk/src/entities/widget/build.d.ts +43 -7
  117. package/dist-sdk/src/entities/widget/from-tf.d.ts +1 -1
  118. package/dist-sdk/src/entities/widget/from-tf.js +162 -23
  119. package/dist-sdk/src/entities/widget/to-tf.d.ts +17 -0
  120. package/dist-sdk/src/entities/widget/to-tf.js +150 -6
  121. package/dist-sdk/src/graph/types.d.ts +13 -0
  122. package/package.json +1 -1
  123. package/dist-sdk/src/core/types/platform.d.ts +0 -2
  124. package/dist-sdk/src/core/types/platform.js +0 -1
@@ -0,0 +1,48 @@
1
+ import { renderTextEffects, writeUserOutput } from "../progress.js";
2
+ export function managedResultStatus(operation, verdict) {
3
+ const outcome = verdict.failed === true
4
+ ? "failure"
5
+ : (verdict.skipped ?? 0) > 0 || (verdict.gaps ?? 0) > 0
6
+ ? "warning"
7
+ : "success";
8
+ return { operation, outcome };
9
+ }
10
+ /**
11
+ * Pull commands are pleasant for a person on a terminal and remain stable for
12
+ * scripts: interactive stdout gets a concise user summary, while a pipe or
13
+ * redirect gets the complete machine-readable result object.
14
+ */
15
+ export function writePullResult(result, humanLines, status) {
16
+ const resultWithStatus = status !== undefined && result !== null && typeof result === "object"
17
+ ? { ...result, status: status.outcome }
18
+ : result;
19
+ if (process.stdout.isTTY === true) {
20
+ const renderedLines = humanLines.flatMap((line) => Array.isArray(line) && line.length === 0 ? [] : [renderPullResultLine(line)]);
21
+ if (status !== undefined) {
22
+ const message = status.outcome === "success"
23
+ ? `${status.operation} completed successfully`
24
+ : status.outcome === "warning"
25
+ ? `${status.operation} completed with warnings, see details above:`
26
+ : `${status.operation} has failed, see details below:`;
27
+ renderedLines.push(renderTextEffects(message, [{
28
+ start: 0,
29
+ end: message.length,
30
+ color: status.outcome === "success" ? "green" : status.outcome === "warning" ? "yellow" : "red",
31
+ bold: true,
32
+ }]));
33
+ }
34
+ writeUserOutput(`${renderedLines.join("\n")}\n`);
35
+ return;
36
+ }
37
+ process.stdout.write(`${JSON.stringify(resultWithStatus, null, 2)}\n`);
38
+ }
39
+ function renderPullResultLine(line) {
40
+ if (typeof line === "string")
41
+ return line;
42
+ return line.map((segment) => renderTextEffects(segment.text, segment.textEffects)).join("");
43
+ }
44
+ export function countSummary(entries) {
45
+ return entries
46
+ .map(([singular, count, plural]) => `${count} ${count === 1 ? singular : (plural ?? `${singular}s`)}`)
47
+ .join(", ");
48
+ }
@@ -37,8 +37,8 @@ export interface NormalizedAccessPolicy {
37
37
  }
38
38
  /** Decode one `filter` attribute through the shared exhaustive codec. */
39
39
  export declare function filterFromTf(value: TfValue, owner: AccessPolicyOwner, where: string): Filter<RefExpr, RefExpr>;
40
- export declare function principalList(value: TfValue | undefined, dataType: "elementum_user", where: string, ctx: FromTfContext): AccessPolicyUserRef[] | undefined;
41
- export declare function principalList(value: TfValue | undefined, dataType: "elementum_group", where: string, ctx: FromTfContext): AccessPolicyGroupRef[] | undefined;
42
- export declare function principalList(value: TfValue | undefined, dataType: "elementum_service_account", where: string, ctx: FromTfContext): AccessPolicyServiceAccountRef[] | undefined;
40
+ export declare function principalList(value: TfValue | undefined, dataType: "elementum_user", where: string, ctx: FromTfContext, owner?: AccessPolicyOwner): AccessPolicyUserRef[] | undefined;
41
+ export declare function principalList(value: TfValue | undefined, dataType: "elementum_group", where: string, ctx: FromTfContext, owner?: AccessPolicyOwner): AccessPolicyGroupRef[] | undefined;
42
+ export declare function principalList(value: TfValue | undefined, dataType: "elementum_service_account", where: string, ctx: FromTfContext, owner?: AccessPolicyOwner): AccessPolicyServiceAccountRef[] | undefined;
43
43
  /** One `elementum_access_policy` block → its normalized shape, or undefined when it belongs to a different owner. */
44
44
  export declare function accessPolicyFromTf(block: TfBlock, owner: AccessPolicyOwner, ctx: FromTfContext): NormalizedAccessPolicy | undefined;
@@ -77,14 +77,33 @@ export function filterFromTf(value, owner, where) {
77
77
  });
78
78
  return decoded;
79
79
  }
80
- function principalListItem(item, dataType, where, ctx) {
80
+ function principalListItem(item, dataType, where, ctx, owner) {
81
81
  const label = dataRefLabel(item, dataType);
82
82
  if (label !== undefined) {
83
83
  const value = ctx.dataName(dataType, label);
84
- if (value !== undefined)
85
- return { __kind: "orgPrincipalRef", dataType, label, value };
86
- ctx.diagnostics.push(`${where}: references data.${dataType}.${label}, but the stream has no matching data block; dropped`);
87
- return undefined;
84
+ if (value === undefined) {
85
+ ctx.diagnostics.push(`${where}: references data.${dataType}.${label}, but the stream has no matching data block; dropped`);
86
+ return undefined;
87
+ }
88
+ if (dataType === "elementum_service_account") {
89
+ const appId = ctx.dataAttrs?.(dataType, label)?.["app_id"];
90
+ const appDataLabel = dataRefLabel(appId, "elementum_app");
91
+ const appResourceLabel = resourceRefLabel(appId, "elementum_app");
92
+ const appName = appDataLabel === undefined ? undefined : ctx.dataName("elementum_app", appDataLabel);
93
+ const appRefName = appName !== undefined
94
+ ? ctx.foreignAppRefNames?.get(appName)
95
+ : appResourceLabel !== undefined && owner?.scope === "app" && owner.label === appResourceLabel
96
+ ? owner.ownerRefName
97
+ : appResourceLabel === undefined
98
+ ? undefined
99
+ : ctx.foreignAppRefNamespaces?.get(appResourceLabel);
100
+ if (appRefName === undefined) {
101
+ ctx.diagnostics.push(`${where}: data.${dataType}.${label} has no resolvable app_id owner; dropped`);
102
+ return undefined;
103
+ }
104
+ return { __kind: "serviceAccount", appRefName, name: value };
105
+ }
106
+ return { __kind: "orgPrincipalRef", dataType, label, value };
88
107
  }
89
108
  if (typeof item === "string") {
90
109
  if (dataType === "elementum_user")
@@ -97,7 +116,7 @@ function principalListItem(item, dataType, where, ctx) {
97
116
  ctx.diagnostics.push(`${where}: list item has an unrecognized shape; dropped`);
98
117
  return undefined;
99
118
  }
100
- export function principalList(value, dataType, where, ctx) {
119
+ export function principalList(value, dataType, where, ctx, owner) {
101
120
  if (value === undefined)
102
121
  return undefined;
103
122
  if (!Array.isArray(value)) {
@@ -110,7 +129,7 @@ export function principalList(value, dataType, where, ctx) {
110
129
  ? principalListItem(item, "elementum_user", where, ctx)
111
130
  : dataType === "elementum_group"
112
131
  ? principalListItem(item, "elementum_group", where, ctx)
113
- : principalListItem(item, "elementum_service_account", where, ctx);
132
+ : principalListItem(item, "elementum_service_account", where, ctx, owner);
114
133
  if (decoded !== undefined)
115
134
  items.push(decoded);
116
135
  }
@@ -138,7 +157,7 @@ export function accessPolicyFromTf(block, owner, ctx) {
138
157
  const filter = attrs["filter"] !== undefined ? filterFromTf(attrs["filter"], filterOwner, where) : { type: "TRUE" };
139
158
  const userIds = principalList(attrs["user_ids"], "elementum_user", `${where}: user_ids`, ctx);
140
159
  const groupIds = principalList(attrs["group_ids"], "elementum_group", `${where}: group_ids`, ctx);
141
- const serviceAccountIds = principalList(attrs["service_account_ids"], "elementum_service_account", `${where}: service_account_ids`, ctx);
160
+ const serviceAccountIds = principalList(attrs["service_account_ids"], "elementum_service_account", `${where}: service_account_ids`, ctx, owner);
142
161
  return {
143
162
  filter,
144
163
  ...(userIds !== undefined && { userIds }),
@@ -38,6 +38,19 @@ export interface AccessPolicyToTfContext {
38
38
  readonly appRefName?: string;
39
39
  readonly serviceAccounts?: Readonly<Record<string, AppServiceAccount>>;
40
40
  readonly fieldAddresses?: ReadonlyMap<string, string>;
41
+ /**
42
+ * Resolve an app that owns a `serviceAccountRef` in these policies but is
43
+ * NOT this policy's owner — an element granting an app's service account
44
+ * access, which publishing an automation that reads the element requires.
45
+ * The owner's to-tf supplies it (only it knows the workspace's other stream
46
+ * roots and may name the app resource type); owners that cannot host such a
47
+ * reference omit it and the ref is dropped with a diagnostic.
48
+ */
49
+ readonly resolveServiceAccountApp?: (appRefName: string) => {
50
+ readonly appTfLabel: string;
51
+ readonly appId: TfValue;
52
+ readonly serviceAccounts?: Readonly<Record<string, AppServiceAccount>>;
53
+ } | undefined;
41
54
  }
42
55
  /** Filter conversion only needs owner/field context; org lookups are accepted so full policy contexts remain assignable. */
43
56
  export interface FilterToTfContext extends Omit<AccessPolicyToTfContext, "orgRefs"> {
@@ -90,6 +90,18 @@ function isGroupToken(v) {
90
90
  function isServiceAccountToken(v) {
91
91
  return typeof v === "object" && v !== null && v.__kind === "serviceAccount";
92
92
  }
93
+ /**
94
+ * Point a cross-stream `serviceAccountRef` at the app that owns it. The
95
+ * account is not in this owner's bag, so `serviceAccounts` stays undefined and
96
+ * `serviceAccountRefToTf` takes its foreign data-source path.
97
+ */
98
+ function resolveForeignOwningApp(item, ctx) {
99
+ const appRefName = item.appRefName;
100
+ if (appRefName === undefined || appRefName === "")
101
+ return undefined;
102
+ const resolved = ctx.resolveServiceAccountApp?.(appRefName);
103
+ return resolved === undefined ? undefined : { appRefName, ...resolved };
104
+ }
93
105
  export function principalListToTf(items, dataType, where, ctx) {
94
106
  if (items === undefined || items.length === 0)
95
107
  return undefined;
@@ -99,6 +111,18 @@ export function principalListToTf(items, dataType, where, ctx) {
99
111
  if (ctx.orgRefs === undefined) {
100
112
  ctx.diagnostics.push(`${where}: pulled principal reference requires org context; dropped`);
101
113
  }
114
+ else if (item.dataType === "elementum_service_account") {
115
+ // A service account is app-owned, so its data source requires
116
+ // `app_id`. The pulled shape carries only a name, so the owner must be
117
+ // the owning app — an element cannot say which app it meant.
118
+ if (ctx.scope !== "app") {
119
+ ctx.diagnostics.push(`${where}: pulled service-account reference ${JSON.stringify(item.value)} needs an app owner to supply app_id; dropped`);
120
+ }
121
+ else {
122
+ ctx.orgRefs.rawLookup(item.dataType, item.label, item.value, { app_id: ctx.objectId });
123
+ values.push(expr.dataAttr(item.dataType, item.label, ["id"]));
124
+ }
125
+ }
102
126
  else {
103
127
  ctx.orgRefs.rawLookup(item.dataType, item.label, item.value);
104
128
  values.push(expr.dataAttr(item.dataType, item.label, ["id"]));
@@ -124,11 +148,18 @@ export function principalListToTf(items, dataType, where, ctx) {
124
148
  }
125
149
  }
126
150
  else if (dataType === "elementum_service_account" && isServiceAccountToken(item)) {
127
- if (ctx.appRefName === undefined || ctx.orgRefs === undefined) {
128
- ctx.diagnostics.push(`${where}: serviceAccount requires an app owner and org context; dropped`);
151
+ // The owner IS the owning app: its own `serviceAccounts` bag can resolve
152
+ // the name to a resource ref. Otherwise the owner is a different stream
153
+ // root and must point at the owning app for the data source's `app_id`.
154
+ const ownedByOwner = ctx.appRefName !== undefined && item.appRefName === ctx.appRefName;
155
+ const owning = ownedByOwner
156
+ ? { appRefName: ctx.appRefName, appTfLabel: ctx.ownerTfLabel, appId: ctx.objectId, serviceAccounts: ctx.serviceAccounts }
157
+ : resolveForeignOwningApp(item, ctx);
158
+ if (owning === undefined || ctx.orgRefs === undefined) {
159
+ ctx.diagnostics.push(`${where}: serviceAccount ${JSON.stringify(item.name ?? "")} cannot resolve its owning app ${JSON.stringify(item.appRefName ?? "")}; dropped`);
129
160
  }
130
161
  else {
131
- const value = serviceAccountRefToTf(item, { appRefName: ctx.appRefName, appTfLabel: ctx.ownerTfLabel, appId: ctx.objectId, serviceAccounts: ctx.serviceAccounts, orgRefs: ctx.orgRefs }, where, ctx.diagnostics);
162
+ const value = serviceAccountRefToTf(item, { ...owning, orgRefs: ctx.orgRefs }, where, ctx.diagnostics);
132
163
  if (value !== undefined)
133
164
  values.push(value);
134
165
  }
@@ -108,7 +108,9 @@ export function printAgentV2(agent, opts) {
108
108
  return ((tool.filterVariables?.length ?? 0) > 0 ||
109
109
  tool.fields?.some((field) => field.rawFieldId !== undefined) === true ||
110
110
  tool.searchTableFields?.some((field) => !searchTableFieldMatchesTarget(field.fieldId, targetOwner, opts.foreignFieldRefsById)) === true ||
111
- tool.returnFields?.some((field) => !searchTableFieldMatchesTarget(field.fieldId, targetOwner, opts.foreignFieldRefsById)) === true);
111
+ tool.returnFields?.some((field) => !searchTableFieldMatchesTarget(field.fieldId, targetOwner, opts.foreignFieldRefsById)) === true ||
112
+ tool.target?.kind === "unresolved" ||
113
+ tool.relatedTarget?.kind === "unresolved");
112
114
  });
113
115
  const lines = [];
114
116
  lines.push("/**");
@@ -476,10 +478,13 @@ function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElemen
476
478
  }
477
479
  else if (tool.target?.kind === "unresolved") {
478
480
  // Export couldn't resolve target_id to any portable app/element
479
- // reference (board issue #648) — keep the raw platform id visible and
480
- // cast past the type system instead of silently dropping the tool.
481
+ // reference (board issue #648) — keep the raw platform id visible via
482
+ // the same unsafePlatformId() escape automation/field refs already use,
483
+ // so build round-trips it directly instead of misreading it as a named
484
+ // reference; cast past the type system since the field itself is a
485
+ // strict CatalogRef.
481
486
  const entityKind = tool.typeKey === "searchTable" ? "element" : "app";
482
- lines.push(` ${entityKind}: ${quote(tool.target.uuid)} as any /* TODO: unresolved ${entityKind} - export couldn't resolve target_id to a portable reference; replace with a real ref before deploying */,`);
487
+ lines.push(` ${entityKind}: unsafePlatformId(${quote(tool.target.uuid)}) as any /* TODO: unresolved ${entityKind} - export couldn't resolve target_id to a portable reference; replace with a real ref before deploying */,`);
483
488
  }
484
489
  else if (tool.target !== undefined && tool.target.kind === "foreignApp") {
485
490
  const foreignRefName = foreignAppRefNames?.get(tool.target.name);
@@ -518,9 +523,10 @@ function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElemen
518
523
  }
519
524
  else if (tool.typeKey === "relateRecord" && tool.relatedTarget?.kind === "unresolved") {
520
525
  // Export couldn't resolve related_target_id to any portable reference
521
- // (board issue #648) — keep the raw platform id visible instead of
522
- // silently dropping the tool.
523
- lines.push(` relatedApp: ${quote(tool.relatedTarget.uuid)} as any /* TODO: unresolved relatedApp - export couldn't resolve related_target_id to a portable reference; replace with a real ref before deploying */,`);
526
+ // (board issue #648) — keep the raw platform id visible via the same
527
+ // unsafePlatformId() escape used above, instead of silently dropping
528
+ // the tool.
529
+ lines.push(` relatedApp: unsafePlatformId(${quote(tool.relatedTarget.uuid)}) as any /* TODO: unresolved relatedApp - export couldn't resolve related_target_id to a portable reference; replace with a real ref before deploying */,`);
524
530
  }
525
531
  else if (tool.typeKey === "relateRecord" && tool.relatedTarget?.kind === "foreignApp") {
526
532
  const foreignRefName = foreignAppRefNames?.get(tool.relatedTarget.name);
@@ -239,8 +239,8 @@ type KnownKeys<T> = {
239
239
  * - wide token (plain AutomationCatalogRef — foreign app or hand-written)
240
240
  * → permissive Record (graceful degradation; def() still validates).
241
241
  */
242
- type TriggerBagOf<A extends AutomationCatalogRef> = [NonNullable<A["trigger"]>] extends [never] ? EmptyBag : KnownKeys<NonNullable<A["trigger"]>> extends infer KK ? [keyof KK] extends [never] ? Readonly<Record<string, TriggerParameterRef>> : KK : never;
243
- type OutputBagOf<A extends AutomationCatalogRef> = [NonNullable<A["outputs"]>] extends [never] ? EmptyBag : KnownKeys<NonNullable<A["outputs"]>> extends infer KK ? [keyof KK] extends [never] ? Readonly<Record<string, OutputPropertyRef>> : KK : never;
242
+ export type TriggerBagOf<A extends AutomationCatalogRef> = [NonNullable<A["trigger"]>] extends [never] ? EmptyBag : KnownKeys<NonNullable<A["trigger"]>> extends infer KK ? [keyof KK] extends [never] ? Readonly<Record<string, TriggerParameterRef>> : KK : never;
243
+ export type OutputBagOf<A extends AutomationCatalogRef> = [NonNullable<A["outputs"]>] extends [never] ? EmptyBag : KnownKeys<NonNullable<A["outputs"]>> extends infer KK ? [keyof KK] extends [never] ? Readonly<Record<string, OutputPropertyRef>> : KK : never;
244
244
  /** Keys whose catalog entry carries `required: true` (rendered by the generated catalog). */
245
245
  type RequiredParamKeys<T> = {
246
246
  [K in keyof T]: T[K] extends {
@@ -37,6 +37,19 @@ function serviceAccountIdValue(token, where, ctx) {
37
37
  }
38
38
  /** authoring app/element token → its resolved target (workspace resource or foreign data ref). */
39
39
  function resolveTarget(token, ctx) {
40
+ // Legacy escape hatch (pre-#889): pull used to print an unresolved target
41
+ // as a bare platform-id string cast (`"<uuid>" as any`) rather than
42
+ // unsafePlatformId(...) — already-pulled workspaces still have this shape
43
+ // on disk and must keep round-tripping directly as target_id.
44
+ if (typeof token === "string") {
45
+ return { value: token, refName: token, kind: "app" };
46
+ }
47
+ // Pull's escape hatch for a target export couldn't resolve to any
48
+ // portable reference (#648) - the platform id round-trips directly as
49
+ // target_id, no name/namespace data lookup needed or even possible.
50
+ if (token.__unsafe === "platformId" && typeof token.value === "string" && token.value !== "") {
51
+ return { value: token.value, refName: token.value, kind: "app" };
52
+ }
40
53
  const refName = token.refName ?? "";
41
54
  const kind = token.__kind === "element" ? "element" : "app";
42
55
  if (kind === "app" && refName === ctx.appRefName) {
@@ -11,7 +11,7 @@
11
11
  * Includes typed scalar, Dropdown/Multi-Select, relation, calculation, and
12
12
  * record-experience configuration with build/pull round-trip support.
13
13
  */
14
- import { type AgentRef, type AppOrElementRef, type AutomationCatalogRef, type CatalogRef, type ChartRef, type CloudLinkRef, type DashboardRef, type FieldRef } from "../../catalog/index.js";
14
+ import { type AgentRef, type AppOrElementRef, type AutomationCatalogRef, type CatalogRef, type ChartRef, type CloudLinkRef, type DashboardRef, type FieldRef, type WidgetRef } from "../../catalog/index.js";
15
15
  import type { WorkflowFieldType } from "../shared/types/field-types.js";
16
16
  import { type SystemFieldKey } from "../../core/system-fields.js";
17
17
  import type { DeployableEntity, EntityDeployOptions } from "../../engine/entity.js";
@@ -240,6 +240,8 @@ export interface AppSystemFields {
240
240
  * one here, same as `systemFields: {}` is already keyed.
241
241
  */
242
242
  export type AppViewFieldRef = FieldRef | SystemFieldKey;
243
+ /** A typed reference to an app-owned widget for placement in a classic layout group. */
244
+ export type AppLayoutWidgetRef<Parent extends string = string, RefName extends string = string> = WidgetRef<Parent, RefName>;
243
245
  /**
244
246
  * One section of a per-stage record layout (`elementum_layout`). The
245
247
  * provider's own 9-value `type` enum (default `"group"`): only `"group"`
@@ -263,6 +265,8 @@ export interface AppLayoutSection {
263
265
  readonly maxColumns?: number;
264
266
  /** `"group"` only — the fields shown in this group, in order. */
265
267
  readonly fields?: readonly AppViewFieldRef[];
268
+ /** `"group"` only — app-owned action/record widgets shown after the fields. */
269
+ readonly widgets?: readonly AppLayoutWidgetRef[];
266
270
  }
267
271
  /** A stage's record-detail layout (`elementum_layout`) — immutable after creation; any change replaces it. */
268
272
  export interface AppLayout {
@@ -271,6 +275,12 @@ export interface AppLayout {
271
275
  /** A saved list view (`elementum_list_view`). */
272
276
  export interface AppListView extends ManagedViewSharing {
273
277
  readonly name: string;
278
+ /**
279
+ * Display columns for the saved list. Create/update also seeds the
280
+ * organization (Everyone) Display Settings table-state default
281
+ * (`owner` = this app/element, `parentId` = the list view id). Show/Hide
282
+ * Columns (ColumnOrder) and Just Me preferences are not authored here.
283
+ */
274
284
  readonly columns: readonly AppViewFieldRef[];
275
285
  readonly allowRecordCreation?: boolean;
276
286
  readonly density?: ListViewDensity;
@@ -374,6 +384,8 @@ export interface AppV2Options<F extends Record<string, AppField> = Record<string
374
384
  readonly cloudOptions?: AppCloudOptions;
375
385
  /** Enables the record-view comments panel. Platform default is `false`. */
376
386
  readonly commentsEnabled?: boolean;
387
+ /** Locks the stage selector during record creation so lifecycle automations own initial progression. */
388
+ readonly lockStages?: boolean;
377
389
  /** Fields keyed by ref name. At least one required by the compose API. */
378
390
  readonly fields: F;
379
391
  /**
@@ -419,7 +431,14 @@ export interface AppV2Options<F extends Record<string, AppField> = Record<string
419
431
  readonly recordCreateForm?: AppRecordCreateForm;
420
432
  /** Typed V2 DASHBOARD layouts, keyed by stable EDK ref name. */
421
433
  readonly dynamicLayouts?: Readonly<Record<string, AppDynamicLayout>>;
422
- /** AutoRelations keyed by stable ref name. */
434
+ /**
435
+ * Parent-owned joins keyed by stable ref name. A `relatedRecords` widget
436
+ * targeting another app/element lists rows through a matching entry here
437
+ * whose columns join comparable stored values, not through that child's
438
+ * `relationField` / `autoRelate`. Do not join system `"id"` (HANDLE) to a
439
+ * child `relationField` or dynamic dropdown (create fails with
440
+ * `Unable to validate`).
441
+ */
423
442
  readonly relationships?: Readonly<Record<string, AppRelationship>>;
424
443
  /** Display order of all authored views (by key). Defaults to declaration order by view bag. */
425
444
  readonly viewOrder?: readonly string[];
@@ -544,6 +563,7 @@ export type AppSelfRef<F extends Record<string, AppField> = Record<string, AppFi
544
563
  automation<const Name extends string>(refName: Name, name?: string): AutomationCatalogRef & CatalogRef<"automation", Name, RefName>;
545
564
  chart<const Name extends string>(refName: Name, name?: string): ChartRef<RefName, Name>;
546
565
  dashboard<const Name extends string>(refName: Name, name?: string): DashboardRef<RefName, Name>;
566
+ widget<const Name extends string>(refName: Name, name?: string): AppLayoutWidgetRef<RefName, Name>;
547
567
  };
548
568
  /** Reference-bearing app options that can safely be authored from `withRefs`. */
549
569
  export type AppReferenceConfiguration = Pick<AppV2Options, "layouts" | "listViews" | "calendarViews" | "kanbanViews" | "dashboards" | "widgets" | "dashboardViews" | "agentViews" | "recordCreateForm" | "dynamicLayouts" | "relationships" | "viewOrder" | "accessPolicies">;
@@ -14,6 +14,7 @@
14
14
  import { slimTokens } from "../../catalog/index.js";
15
15
  import { DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES, SYSTEM_FIELD_KEYS, SYSTEM_FIELD_REQUIRED, SYSTEM_FIELD_TAG_BY_KEY, WRITABLE_SYSTEM_TAG_NAMES, } from "../../core/system-fields.js";
16
16
  import { serializeDisplayBlocks } from "./display-blocks.js";
17
+ import { assertCalculatedFieldRoot } from "../field/calc/runtime.js";
17
18
  export { dashboardChartWidget, dashboardRecordsWidget, dashboardWidgetSize, } from "../dashboard/build.js";
18
19
  /**
19
20
  * Map a platform field type to the `AspectFieldInput` variant key. "relation"
@@ -154,6 +155,7 @@ export function serializeField(field, refName) {
154
155
  // Calculated field: the calc expression serializes to a text grammar string
155
156
  // (field refs emitted by name; the platform resolves them on compose).
156
157
  if (field.expression !== undefined) {
158
+ assertCalculatedFieldRoot(field.expression, field.name);
157
159
  const includeTypes = field.include === undefined || field.include === "auto" ? []
158
160
  : field.include === "manual" ? [{ manual: { type: "MANUAL" } }]
159
161
  : field.include === "both" ? [{ auto: { type: "AUTO" } }, { manual: { type: "MANUAL" } }]
@@ -370,6 +372,9 @@ export function app(opts) {
370
372
  dashboard(childRefName, name = childRefName) {
371
373
  return { __kind: "dashboard", refName: childRefName, name, parent: refName };
372
374
  },
375
+ widget(childRefName, name = childRefName) {
376
+ return { __kind: "widget", refName: childRefName, name, parent: refName };
377
+ },
373
378
  };
374
379
  return self;
375
380
  }
@@ -417,6 +422,7 @@ export function app(opts) {
417
422
  ...(opts.cloudLink !== undefined ? { cloudLinkId: opts.cloudLink } : {}), // token → id at deploy
418
423
  ...(opts.cloudOptions !== undefined ? { cloudOptions: opts.cloudOptions } : {}),
419
424
  ...(opts.commentsEnabled !== undefined ? { commentsEnabled: opts.commentsEnabled } : {}),
425
+ ...(opts.lockStages !== undefined ? { lockStages: opts.lockStages } : {}),
420
426
  fields: [
421
427
  ...serializeSystemFields(opts.systemFields),
422
428
  ...Object.entries(opts.fields).map(([bagKey, field]) => serializeField(field, bagKey)),
@@ -120,6 +120,7 @@ export interface NormalizedLayoutSection {
120
120
  readonly color?: string;
121
121
  readonly maxColumns?: number;
122
122
  readonly fields?: readonly string[];
123
+ readonly widgets?: readonly string[];
123
124
  }
124
125
  /** A stage's record-detail layout, keyed by stage key on `NormalizedApp.layouts`. */
125
126
  export interface NormalizedLayout {
@@ -190,11 +191,16 @@ export type NormalizedDashboardWidget = {
190
191
  readonly chartKey: string;
191
192
  };
192
193
  export interface NormalizedWidgetRef {
193
- readonly kind: "app" | "element" | "automation" | "field";
194
+ readonly kind: "app" | "element" | "automation" | "field" | "recordIdentity";
194
195
  readonly key: string;
195
196
  readonly name: string;
196
197
  readonly parent?: string;
197
198
  readonly fieldType?: string;
199
+ readonly target?: NormalizedWidgetRef;
200
+ /** A foreign app/element target resolved by namespace rather than a display-name lookup. */
201
+ readonly namespace?: string;
202
+ /** `key`/`name` are the target's real pulled catalog identity - print via appRef()/elementRef(). */
203
+ readonly catalogRef?: true;
198
204
  }
199
205
  export interface NormalizedWidgetButtonStyle {
200
206
  readonly buttonType: "INLINE" | "PRIMARY" | "SECONDARY";
@@ -261,10 +267,12 @@ export interface NormalizedRecordCreateForm {
261
267
  readonly sections: readonly NormalizedRecordCreateFormSection[];
262
268
  }
263
269
  export interface PulledDynamicLayoutRef {
264
- readonly __pulledRef: "field" | "automation" | "app" | "element";
270
+ readonly __pulledRef: "field" | "automation" | "agent" | "app" | "element";
265
271
  readonly key: string;
266
272
  readonly parent?: string;
267
273
  readonly name?: string;
274
+ /** A foreign app/element target resolved by namespace rather than a display-name lookup. */
275
+ readonly namespace?: string;
268
276
  }
269
277
  export interface NormalizedDynamicLayout {
270
278
  readonly key: string;
@@ -272,7 +280,7 @@ export interface NormalizedDynamicLayout {
272
280
  readonly layout: Readonly<Record<string, unknown>>;
273
281
  }
274
282
  export interface PulledRelationshipRef {
275
- readonly kind: "app" | "element" | "table" | "field" | "tableColumn";
283
+ readonly kind: "app" | "element" | "table" | "field" | "tableColumn" | "recordIdentity";
276
284
  readonly key: string;
277
285
  readonly name: string;
278
286
  readonly parent?: string;
@@ -285,6 +293,7 @@ export interface PulledRelationshipRef {
285
293
  readonly parentKind?: "app" | "element";
286
294
  readonly parentName?: string;
287
295
  readonly parentNamespace?: string;
296
+ readonly target?: PulledRelationshipRef;
288
297
  }
289
298
  export interface NormalizedRelationship {
290
299
  readonly key: string;
@@ -326,6 +335,7 @@ export interface NormalizedApp {
326
335
  readonly cloudLinkId?: string;
327
336
  readonly cloudLinkClientHandle?: string;
328
337
  readonly commentsEnabled?: boolean;
338
+ readonly lockStages?: boolean;
329
339
  readonly cloudOptions?: {
330
340
  readonly snowflake?: {
331
341
  readonly hybridTable?: boolean;
@@ -12,7 +12,7 @@ import { EntityTfError } from "../../engine/entity.js";
12
12
  import { dataRefLabel, optionalString, plainObject } from "../../engine/pull/context.js";
13
13
  import { snakeSlug, tfLabelToTsLabel } from "../../engine/tf/index.js";
14
14
  import { accessPolicyFromTf } from "../access-policy/from-tf.js";
15
- import { dynamicLayoutsFromTf } from "../dynamic-layout/from-tf.js";
15
+ import { dynamicLayoutCompanionWidgetLabels, dynamicLayoutsFromTf, } from "../dynamic-layout/from-tf.js";
16
16
  import { dashboardsFromTf } from "../dashboard/from-tf.js";
17
17
  import { fieldFromTf } from "../field/from-tf.js";
18
18
  import { optionsFromTf } from "../field/options.js";
@@ -42,6 +42,7 @@ const KNOWN_APP_ATTRS = new Set([
42
42
  "id_field_description",
43
43
  "status_field_description",
44
44
  "comments_enabled",
45
+ "lock_stages",
45
46
  "system_field_config",
46
47
  ]);
47
48
  const SYSTEM_FIELD_TYPE_BY_KEY = {
@@ -108,6 +109,7 @@ export function appFromTf(appBlock, fieldBlocks, ctx, viewBlocks = { layoutBlock
108
109
  const idFieldDescription = optionalString(attrs, "id_field_description", `app "${label}"`, ctx);
109
110
  const statusFieldDescription = optionalString(attrs, "status_field_description", `app "${label}"`, ctx);
110
111
  const commentsEnabled = typeof attrs["comments_enabled"] === "boolean" ? attrs["comments_enabled"] : undefined;
112
+ const lockStages = typeof attrs["lock_stages"] === "boolean" ? attrs["lock_stages"] : undefined;
111
113
  // --- Org data references (category / cloud link).
112
114
  let category;
113
115
  if (attrs["category_id"] !== undefined) {
@@ -147,16 +149,16 @@ export function appFromTf(appBlock, fieldBlocks, ctx, viewBlocks = { layoutBlock
147
149
  const systemConfig = systemFieldConfigFromTf(attrs["system_field_config"], `app "${label}"`, ctx);
148
150
  const titleName = optionalString(attrs, "title_field_name", `app "${label}"`, ctx);
149
151
  if (titleName !== undefined || titleFieldDescription !== undefined || systemConfig.has("title")) {
150
- fields.push(systemEntry("title", titleName ?? "Title", "TEXT", "TITLE", titleFieldDescription, systemConfig.get("title")));
152
+ fields.push(systemEntry("title", titleName ?? DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES.title, "TEXT", "TITLE", titleFieldDescription, systemConfig.get("title")));
151
153
  }
152
154
  const idName = optionalString(attrs, "id_field_name", `app "${label}"`, ctx);
153
155
  if (idName !== undefined || idFieldDescription !== undefined || systemConfig.has("id")) {
154
- fields.push(systemEntry("id", idName ?? "ID", "TEXT", "HANDLE", idFieldDescription, systemConfig.get("id")));
156
+ fields.push(systemEntry("id", idName ?? DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES.id, "TEXT", "HANDLE", idFieldDescription, systemConfig.get("id")));
155
157
  }
156
- const statusName = optionalString(attrs, "status_field_name", `app "${label}"`, ctx) ?? "Status";
158
+ const statusName = optionalString(attrs, "status_field_name", `app "${label}"`, ctx) ?? DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES.status;
157
159
  const statusOptions = optionsFromTf(attrs["status_options"], `app "${label}" status_options`, ctx);
158
160
  if (!hasCustomStatusField
159
- && (statusName !== "Status" || statusOptions !== undefined || statusFieldDescription !== undefined || systemConfig.has("status"))) {
161
+ && (statusName !== DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES.status || statusOptions !== undefined || statusFieldDescription !== undefined || systemConfig.has("status"))) {
160
162
  const flags = systemConfig.get("status");
161
163
  fields.push({
162
164
  key: "status",
@@ -211,14 +213,14 @@ export function appFromTf(appBlock, fieldBlocks, ctx, viewBlocks = { layoutBlock
211
213
  }
212
214
  // --- View pass: layouts / list views / view order (entities/view), owner passed in.
213
215
  const dashboards = dashboardsFromTf(viewBlocks.dashboardBlocks, viewBlocks.dashboardWidgetBlocks, { type: APP_RESOURCE_TYPE, label, ownerTfLabel: refName, ownerRefName: refName, scope: "app", ownerType: "APP_ASPECT" }, ctx);
214
- const { layouts, listViews, calendarViews, kanbanViews, dashboardViews, agentViews, viewOrder } = viewsFromTf(viewBlocks.layoutBlocks, viewBlocks.listViewBlocks, viewBlocks.calendarViewBlocks, viewBlocks.kanbanViewBlocks, viewBlocks.dashboardViewBlocks, viewBlocks.agentViewBlocks, viewBlocks.managedViewOrderBlocks, { type: APP_RESOURCE_TYPE, label, ownerTfLabel: refName, scope: "app", stageKeys: new Set(stages.map((stage) => stage.key)) }, ctx);
216
+ const { layouts, listViews, calendarViews, kanbanViews, dashboardViews, agentViews, viewOrder } = viewsFromTf(viewBlocks.layoutBlocks, viewBlocks.listViewBlocks, viewBlocks.calendarViewBlocks, viewBlocks.kanbanViewBlocks, viewBlocks.dashboardViewBlocks, viewBlocks.agentViewBlocks, viewBlocks.managedViewOrderBlocks, { type: APP_RESOURCE_TYPE, label, ownerTfLabel: label, scope: "app", stageKeys: new Set(stages.map((stage) => stage.key)) }, ctx);
215
217
  if (viewBlocks.recordCreateFormBlocks.length > 1) {
216
218
  ctx.diagnostics.push(`app "${label}": found ${viewBlocks.recordCreateFormBlocks.length} record create forms; only the first is used`);
217
219
  }
218
220
  const recordCreateForm = recordCreateFormFromTf(viewBlocks.recordCreateFormBlocks[0], { type: APP_RESOURCE_TYPE, label, ownerTfLabel: refName, scope: "app" }, ctx);
219
221
  const dynamicLayouts = dynamicLayoutsFromTf(viewBlocks.dynamicLayoutBlocks, { type: APP_RESOURCE_TYPE, label, ownerRefName: refName, ownerTfLabel: refName }, ctx);
220
222
  const relationships = relationshipsFromTf(viewBlocks.relationshipBlocks, { kind: "app", label, ownerRefName: refName, ownerTfLabel: refName, scope: "app" }, ctx);
221
- const widgets = widgetsFromTf(viewBlocks.widgetBlocks, { type: APP_RESOURCE_TYPE, label, ownerRefName: refName, ownerTfLabel: label, scope: "app" }, ctx);
223
+ const widgets = widgetsFromTf(viewBlocks.widgetBlocks, { type: APP_RESOURCE_TYPE, label, ownerRefName: refName, ownerTfLabel: label, scope: "app" }, ctx, dynamicLayoutCompanionWidgetLabels(viewBlocks.dynamicLayoutBlocks));
222
224
  // --- Access policies (entities/access-policy), owner passed in.
223
225
  const accessPolicyOwner = {
224
226
  type: APP_RESOURCE_TYPE,
@@ -250,6 +252,7 @@ export function appFromTf(appBlock, fieldBlocks, ctx, viewBlocks = { layoutBlock
250
252
  stages,
251
253
  ...(cloudLinkId !== undefined && { cloudLinkId }),
252
254
  ...(commentsEnabled !== undefined && { commentsEnabled }),
255
+ ...(lockStages !== undefined && { lockStages }),
253
256
  ...(layouts.length > 0 && { layouts }),
254
257
  ...(listViews.length > 0 && { listViews }),
255
258
  ...(calendarViews.length > 0 && { calendarViews }),
@@ -21,9 +21,9 @@ import { expr, snakeSlug } from "../../engine/tf/index.js";
21
21
  import { accessPolicyToTf } from "../access-policy/to-tf.js";
22
22
  import { dashboardsToTf } from "../dashboard/to-tf.js";
23
23
  import { picklistLabel } from "../field/options.js";
24
+ import { fieldMetadataFromEntries } from "../field/metadata.js";
24
25
  import { dynamicLayoutsToTf } from "../dynamic-layout/to-tf.js";
25
26
  import { fieldToTf } from "../field/to-tf.js";
26
- import { SUB_TYPE_BY_TYPE_KEY } from "../field/types.js";
27
27
  import { CATEGORY_ORG_BAG } from "../org/category.js";
28
28
  import { categoryIdExpr, missingCategoryDiagnostic } from "../org/category-ref.js";
29
29
  import { CLOUD_LINK_ORG_BAG } from "../org/cloud-link.js";
@@ -31,7 +31,7 @@ import { recordCreateFormToTf } from "../record-create-form/to-tf.js";
31
31
  import { relationshipsToTf } from "../relationship/to-tf.js";
32
32
  import { rolesToTf } from "../role/to-tf.js";
33
33
  import { serviceAccountsToTf } from "../service-account/to-tf.js";
34
- import { widgetsToTf } from "../widget/to-tf.js";
34
+ import { relationshipTargetsFromBag, widgetsToTf } from "../widget/to-tf.js";
35
35
  import { viewToTf } from "../view/to-tf.js";
36
36
  import { APP_RESOURCE_TYPE } from "./module.js";
37
37
  /** System-field tags that fold into the app resource instead of emitting a field resource. */
@@ -80,6 +80,8 @@ export function appToTf(entity, ctx) {
80
80
  appAttrs["color"] = payload.color;
81
81
  if (payload.commentsEnabled !== undefined)
82
82
  appAttrs["comments_enabled"] = payload.commentsEnabled;
83
+ if (payload.lockStages !== undefined)
84
+ appAttrs["lock_stages"] = payload.lockStages;
83
85
  const categoryName = payload.category?.name;
84
86
  if (categoryName !== undefined && categoryName !== "") {
85
87
  const category = ctx.orgRefs.byName(CATEGORY_ORG_BAG, categoryName);
@@ -112,7 +114,7 @@ export function appToTf(entity, ctx) {
112
114
  // --- Field pass: fold system-tagged fields, emit one resource per custom field.
113
115
  const blocks = [];
114
116
  const fieldAddresses = new Map();
115
- const fieldMetadata = new Map();
117
+ const fieldMetadata = fieldMetadataFromEntries(payload.fields);
116
118
  const fieldNames = new Map();
117
119
  let statusOptions;
118
120
  let stages;
@@ -126,17 +128,6 @@ export function appToTf(entity, ctx) {
126
128
  const inner = fieldEntry[typeKey];
127
129
  const name = inner.name ?? "";
128
130
  const fieldKey = inner.__refName ?? snakeSlug(name);
129
- const subType = SUB_TYPE_BY_TYPE_KEY.get(typeKey);
130
- if (fieldKey !== "" && name !== "" && subType !== undefined) {
131
- fieldMetadata.set(fieldKey, {
132
- name,
133
- fieldType: subType.authoringType,
134
- ...(inner.picklistValues !== undefined
135
- ? { options: inner.picklistValues.map((value) => picklistLabel(value)) }
136
- : {}),
137
- ...(inner.tags !== undefined ? { tags: inner.tags } : {}),
138
- });
139
- }
140
131
  if (fieldKey !== "" && name !== "")
141
132
  fieldNames.set(fieldKey, name);
142
133
  const systemTag = inner.tags?.find((tag) => SYSTEM_FIELD_TAGS.has(tag));
@@ -146,6 +137,13 @@ export function appToTf(entity, ctx) {
146
137
  ctx.diagnostics.push(`systemFields: unsupported semantic tag ${systemTag}; validation flags dropped`);
147
138
  }
148
139
  else {
140
+ // Canonical system key (title/id/status/…) must map to the display
141
+ // name even when __refName was missing and fieldKey became
142
+ // snakeSlug("App Name") → "app_name". Cross-app automation refs
143
+ // look up record.title by the system key; missing it silently
144
+ // falls back to DEPLOY_DEFAULT "Title" (tofu Invalid index).
145
+ if (name !== "")
146
+ fieldNames.set(systemKey, name);
149
147
  systemFieldConfig[SYSTEM_FIELD_HCL_KEY_BY_KEY[systemKey]] = {
150
148
  required: inner.required ?? false,
151
149
  required_on_close: inner.requiredOnClose ?? false,
@@ -260,6 +258,7 @@ export function appToTf(entity, ctx) {
260
258
  workspaceAspects: ctx.workspaceAspects,
261
259
  diagnostics: ctx.diagnostics,
262
260
  fieldAddresses,
261
+ relationshipTargets: relationshipTargetsFromBag(payload.relationships),
263
262
  }));
264
263
  const { blocks: viewBlocks } = viewToTf(payload.layouts, payload.listViews, payload.calendarViews, payload.kanbanViews, payload.dashboardViews, payload.agentViews, payload.viewOrder, {
265
264
  ownerRefName: ctx.appRefName,
@@ -271,6 +270,7 @@ export function appToTf(entity, ctx) {
271
270
  orgRefs: ctx.orgRefs,
272
271
  diagnostics: ctx.diagnostics,
273
272
  fieldAddresses,
273
+ widgetKeys: new Set(Object.keys(payload.widgets ?? {})),
274
274
  });
275
275
  blocks.push(...viewBlocks);
276
276
  const recordCreateForm = recordCreateFormToTf(payload.recordCreateForm, {