@elementumai/edk 0.10.2 → 0.10.3

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 (114) hide show
  1. package/README.md +7 -7
  2. package/dist-sdk/src/catalog/org.d.ts +7 -5
  3. package/dist-sdk/src/catalog/org.js +14 -9
  4. package/dist-sdk/src/catalog/token.js +4 -0
  5. package/dist-sdk/src/core/types/app.d.ts +22 -0
  6. package/dist-sdk/src/engine/build/context.d.ts +8 -0
  7. package/dist-sdk/src/engine/build/source-context.d.ts +3 -4
  8. package/dist-sdk/src/engine/coverage-gaps.d.ts +2 -0
  9. package/dist-sdk/src/engine/coverage-gaps.js +3 -0
  10. package/dist-sdk/src/engine/ei/state.d.ts +48 -0
  11. package/dist-sdk/src/engine/ei/state.js +91 -0
  12. package/dist-sdk/src/engine/pull/authored-address.d.ts +100 -0
  13. package/dist-sdk/src/engine/pull/authored-address.js +360 -0
  14. package/dist-sdk/src/engine/pull/context.d.ts +59 -0
  15. package/dist-sdk/src/engine/tf/expr.d.ts +7 -0
  16. package/dist-sdk/src/engine/tf/expr.js +62 -18
  17. package/dist-sdk/src/engine/tf/index.d.ts +1 -1
  18. package/dist-sdk/src/engine/tf/index.js +1 -1
  19. package/dist-sdk/src/engine/tf/labels.d.ts +10 -2
  20. package/dist-sdk/src/engine/tf/labels.js +15 -2
  21. package/dist-sdk/src/engine/tf/parse.js +19 -6
  22. package/dist-sdk/src/engine/workspace/backend.d.ts +34 -0
  23. package/dist-sdk/src/engine/workspace/backend.js +104 -0
  24. package/dist-sdk/src/engine/workspace/generated-file.d.ts +3 -0
  25. package/dist-sdk/src/engine/workspace/generated-file.js +6 -0
  26. package/dist-sdk/src/engine/workspace/loader.js +2 -2
  27. package/dist-sdk/src/entities/agent-tool/to-tf.js +1 -1
  28. package/dist-sdk/src/entities/app/build.d.ts +36 -4
  29. package/dist-sdk/src/entities/app/build.js +67 -4
  30. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +12 -0
  31. package/dist-sdk/src/entities/app/from-tf.js +13 -9
  32. package/dist-sdk/src/entities/app/module.js +1 -0
  33. package/dist-sdk/src/entities/app/stage-keys.d.ts +82 -0
  34. package/dist-sdk/src/entities/app/stage-keys.js +160 -0
  35. package/dist-sdk/src/entities/app/to-tf.js +17 -21
  36. package/dist-sdk/src/entities/approval-chain/from-tf.d.ts +9 -1
  37. package/dist-sdk/src/entities/approval-chain/from-tf.js +31 -3
  38. package/dist-sdk/src/entities/approval-chain/module.js +12 -4
  39. package/dist-sdk/src/entities/approval-chain/to-tf.d.ts +1 -0
  40. package/dist-sdk/src/entities/approval-chain/to-tf.js +6 -1
  41. package/dist-sdk/src/entities/automation/build.js +13 -6
  42. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +3 -0
  43. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +5 -3
  44. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +90 -17
  45. package/dist-sdk/src/entities/automation/from-tf.d.ts +28 -6
  46. package/dist-sdk/src/entities/automation/from-tf.js +140 -23
  47. package/dist-sdk/src/entities/automation/module.js +123 -37
  48. package/dist-sdk/src/entities/automation/to-tf.d.ts +3 -1
  49. package/dist-sdk/src/entities/automation/to-tf.js +131 -20
  50. package/dist-sdk/src/entities/automation/triggers.d.ts +2 -0
  51. package/dist-sdk/src/entities/automation/triggers.js +1 -0
  52. package/dist-sdk/src/entities/chart/from-tf.d.ts +6 -0
  53. package/dist-sdk/src/entities/chart/from-tf.js +9 -1
  54. package/dist-sdk/src/entities/dashboard/from-tf.js +51 -4
  55. package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +3 -0
  56. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +48 -4
  57. package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +2 -0
  58. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +7 -2
  59. package/dist-sdk/src/entities/element/build.js +1 -1
  60. package/dist-sdk/src/entities/element/from-tf.d.ts +12 -6
  61. package/dist-sdk/src/entities/element/from-tf.js +23 -7
  62. package/dist-sdk/src/entities/element/module.js +3 -2
  63. package/dist-sdk/src/entities/element/to-tf.d.ts +3 -2
  64. package/dist-sdk/src/entities/element/to-tf.js +32 -25
  65. package/dist-sdk/src/entities/field/allow-list.d.ts +18 -0
  66. package/dist-sdk/src/entities/field/allow-list.js +42 -0
  67. package/dist-sdk/src/entities/field/build.d.ts +38 -3
  68. package/dist-sdk/src/entities/field/build.js +7 -2
  69. package/dist-sdk/src/entities/field/from-tf.js +178 -20
  70. package/dist-sdk/src/entities/field/module.js +2 -0
  71. package/dist-sdk/src/entities/field/options.d.ts +2 -0
  72. package/dist-sdk/src/entities/field/order.d.ts +9 -0
  73. package/dist-sdk/src/entities/field/order.js +33 -0
  74. package/dist-sdk/src/entities/field/to-tf.d.ts +6 -0
  75. package/dist-sdk/src/entities/field/to-tf.js +87 -0
  76. package/dist-sdk/src/entities/field/types.js +3 -0
  77. package/dist-sdk/src/entities/relationship/build.d.ts +3 -3
  78. package/dist-sdk/src/entities/relationship/from-tf.js +4 -2
  79. package/dist-sdk/src/entities/relationship/to-tf.js +3 -1
  80. package/dist-sdk/src/entities/service-account/workspace-owner.d.ts +8 -3
  81. package/dist-sdk/src/entities/service-account/workspace-owner.js +12 -4
  82. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +5 -0
  83. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +13 -0
  84. package/dist-sdk/src/entities/shared/filters/ast.d.ts +7 -0
  85. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +1 -1
  86. package/dist-sdk/src/entities/skill/to-tf.js +19 -14
  87. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
  88. package/dist-sdk/src/entities/skill-tool/from-tf.js +3 -0
  89. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +6 -1
  90. package/dist-sdk/src/entities/skill-tool/to-tf.js +6 -1
  91. package/dist-sdk/src/entities/task/build.js +1 -1
  92. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +11 -0
  93. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +13 -38
  94. package/dist-sdk/src/entities/view/custom-view-validate.d.ts +29 -0
  95. package/dist-sdk/src/entities/view/custom-view-validate.js +292 -0
  96. package/dist-sdk/src/entities/view/from-tf.d.ts +2 -0
  97. package/dist-sdk/src/entities/view/from-tf.js +40 -6
  98. package/dist-sdk/src/entities/view/to-tf.d.ts +6 -0
  99. package/dist-sdk/src/entities/view/to-tf.js +14 -6
  100. package/dist-sdk/src/entities/visual-flow/from-tf.d.ts +2 -1
  101. package/dist-sdk/src/entities/visual-flow/from-tf.js +11 -2
  102. package/dist-sdk/src/entities/visual-flow/module.js +15 -5
  103. package/dist-sdk/src/entities/visual-flow/to-tf.d.ts +2 -0
  104. package/dist-sdk/src/entities/visual-flow/to-tf.js +1 -1
  105. package/dist-sdk/src/entities/widget/build.d.ts +8 -1
  106. package/dist-sdk/src/entities/widget/from-tf.js +12 -6
  107. package/dist-sdk/src/entities/widget/to-tf.d.ts +1 -0
  108. package/dist-sdk/src/entities/widget/to-tf.js +16 -0
  109. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +8 -2
  110. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  111. package/dist-sdk/src/graph/index.d.ts +6 -0
  112. package/dist-sdk/src/graph/index.js +1 -0
  113. package/dist-sdk/src/graph/types.d.ts +59 -2
  114. package/package.json +2 -17
@@ -60,6 +60,13 @@ export interface FieldRefAst {
60
60
  */
61
61
  readonly foreign?: {
62
62
  readonly entityType: "app" | "element" | "task";
63
+ /**
64
+ * Set when `entityType` is only a placeholder: the field was resolved
65
+ * from a raw field id whose registry entry names the owner but not its
66
+ * kind. Printers must then resolve the owner against pulled apps AND
67
+ * elements instead of trusting `entityType`.
68
+ */
69
+ readonly ownerKindUnknown?: true;
63
70
  /** The owner's display name — resolves a same-name local catalog entry, same convention as `AppRefAst.name`. */
64
71
  readonly name: string;
65
72
  /** Stable namespace for a portable inline fieldRef owner lookup. */
@@ -227,7 +227,7 @@ function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElemen
227
227
  // foreign-literal fallback used for an unresolved search table
228
228
  // elsewhere in this printer). refName is a best-effort guess
229
229
  // from the display name, not a verified catalog key.
230
- ` automation: { __kind: "automation", refName: ${quote(tfLabelToTsLabel(sanitizeName(tool.automationForeignName)))}, name: ${quote(tool.automationForeignName)}, parent: ${quote(tool.automationForeignParentRefName ?? tool.automationForeignParentName ?? "")}, parentName: ${quote(tool.automationForeignParentName ?? "")}, parentKind: ${quote(tool.automationForeignParentKind ?? "app")} } /* TODO: foreign automation reference - no catalog token available; verify the parent/refName before deploying */,`
230
+ ` automation: { __kind: "automation", refName: ${quote(tfLabelToTsLabel(sanitizeName(tool.automationForeignName)))}, name: ${quote(tool.automationForeignName)}, parent: ${quote(tool.automationForeignParentRefName ?? tool.automationForeignParentName ?? "")}, parentName: ${quote(tool.automationForeignParentName ?? "")}, parentKind: ${quote(tool.automationForeignParentKind ?? "app")}${tool.automationForeignParentNamespace !== undefined ? `, parentNamespace: ${quote(tool.automationForeignParentNamespace)}` : ""} } /* TODO: foreign automation reference - no catalog token available; verify the parent/refName before deploying */,`
231
231
  : ` automation: catalog.${appRefName}.automations${safeMember(tool.automationKey ?? "")},`);
232
232
  const inputs = tool.inputs ?? [];
233
233
  if (inputs.length > 0) {
@@ -15,6 +15,7 @@
15
15
  import { workspaceAspectKey } from "../../engine/build/context.js";
16
16
  import { EntityTfError } from "../../engine/entity.js";
17
17
  import { appScopedResourceLabel, expr, sanitizeName, tsLabelToTfLabel } from "../../engine/tf/index.js";
18
+ import { resolveForeignRef } from "../shared/foreign-ref.js";
18
19
  import { skillToolToTf } from "../skill-tool/to-tf.js";
19
20
  import { APP_RESOURCE_TYPE } from "../app/module.js";
20
21
  import { SERVICE_ACCOUNT_RESOURCE_TYPE } from "../service-account/module.js";
@@ -139,21 +140,25 @@ export function skillToTf(entity, ctx) {
139
140
  });
140
141
  return expr.dataAttr("elementum_search_table", label, ["id"]);
141
142
  },
142
- foreignAutomationRef: (tfLabel, parentKind, _parentRefName, parentName, automationName) => {
143
- // sanitizeName(parentName), not the refName: ei labels the export
144
- // from the owner's DISPLAY name, and sanitizeName doesn't split a
145
- // capital before a digit the way reversing a refName would need
146
- // (same lesson as #1095's table-owned search-table label fix).
147
- const parentType = parentKind === "element" ? "elementum_element" : "elementum_app";
148
- const parentLabel = sanitizeName(parentName);
149
- // ei labels a foreign automation data block `${lookup.Label}_${SanitizeName(name)}`
150
- // (imports.go), not the bare automation label - a bare label both
151
- // diverges from the pulled state (plan diff) and collides in
152
- // ctx.orgRefs.rawLookup's `${type}.${label}` registry key across apps.
153
- const automationLabel = `${parentLabel}_${tfLabel}`;
154
- ctx.orgRefs.rawLookup(parentType, parentLabel, parentName);
143
+ foreignAutomationRef: (tfLabel, owner, automationName) => {
144
+ // The owner app/element resolves through the kind graph's root
145
+ // lookup (by namespace), the same as the agent tool path, automation
146
+ // tasks and every other foreign reference to it. A display-name
147
+ // rawLookup here gave the shared data address a second identity and
148
+ // failed the build when anything else referenced that owner (#1722).
149
+ const ownerRef = resolveForeignRef(owner.kind, { name: owner.name, ...(owner.namespace !== undefined ? { namespace: owner.namespace } : {}) }, ctx.orgRefs, ctx.diagnostics, "skill run-automation owner");
150
+ // Owner-scoped label: the owner prefix is the graph root-lookup label
151
+ // (sanitized namespace; the name only as the compatibility fallback)
152
+ // and the suffix is the automation's tfLabel, the same address an
153
+ // automation task's foreign target uses. A bare automation label
154
+ // would collide in ctx.orgRefs.rawLookup's `${type}.${label}` registry
155
+ // key across owners. ei's export prefixes `lookup.Label`, which is
156
+ // SanitizeName(display name) (imports.go), so the address equals
157
+ // ei's only when the name and namespace sanitize alike; data-block
158
+ // labels don't affect plans.
159
+ const automationLabel = `${ownerRef.tfLabel}_${tfLabel}`;
155
160
  ctx.orgRefs.rawLookup("elementum_automation", automationLabel, automationName, {
156
- app_id: expr.dataAttr(parentType, parentLabel, ["id"]),
161
+ app_id: ownerRef.value,
157
162
  });
158
163
  return expr.dataAttr("elementum_automation", automationLabel, ["id"]);
159
164
  },
@@ -90,6 +90,8 @@ export interface NormalizedSkillTool {
90
90
  readonly automationForeignParentName?: string;
91
91
  /** Canonical catalog refName of the owning app/element, when known. */
92
92
  readonly automationForeignParentRefName?: string;
93
+ /** Namespace of the owning app/element, when the export looked it up by namespace. */
94
+ readonly automationForeignParentNamespace?: string;
93
95
  readonly automationForeignParentKind?: "app" | "element";
94
96
  readonly searchTableKey?: string;
95
97
  /** Foreign table lookup name when search_table_id is data.elementum_search_table. */
@@ -149,6 +149,7 @@ export function skillToolFromTf(block, owner, ctx) {
149
149
  let automationForeignName;
150
150
  let automationForeignParentName;
151
151
  let automationForeignParentRefName;
152
+ let automationForeignParentNamespace;
152
153
  let automationForeignParentKind;
153
154
  if (automationLabel === undefined &&
154
155
  automationRawId === undefined &&
@@ -173,6 +174,7 @@ export function skillToolFromTf(block, owner, ctx) {
173
174
  automationForeignName = automationName;
174
175
  automationForeignParentName = resolvedOwner.name;
175
176
  automationForeignParentRefName = resolvedOwner.key;
177
+ automationForeignParentNamespace = resolvedOwner.namespace;
176
178
  automationForeignParentKind = ownerKind;
177
179
  }
178
180
  if (automationLabel === undefined && automationRawId === undefined && automationForeignName === undefined) {
@@ -220,6 +222,7 @@ export function skillToolFromTf(block, owner, ctx) {
220
222
  automationForeignName,
221
223
  ...(automationForeignParentName !== undefined && { automationForeignParentName }),
222
224
  ...(automationForeignParentRefName !== undefined && { automationForeignParentRefName }),
225
+ ...(automationForeignParentNamespace !== undefined && { automationForeignParentNamespace }),
223
226
  ...(automationForeignParentKind !== undefined && { automationForeignParentKind }),
224
227
  }
225
228
  : { automationKey: scopedLabelToBagKey(owner.ownerTfLabel, automationLabel) }),
@@ -41,7 +41,12 @@ export interface SkillToolToTfContext {
41
41
  * skill/agent tool targeting an automation this workspace doesn't own),
42
42
  * returning the resolved `.id`. Live-confirmed on sanofi/eu (#1177).
43
43
  */
44
- foreignAutomationRef?(tfLabel: string, parentKind: "app" | "element", parentRefName: string, parentName: string, automationName: string): TfValue | void;
44
+ foreignAutomationRef?(tfLabel: string, owner: {
45
+ readonly kind: "app" | "element";
46
+ readonly refName: string;
47
+ readonly name: string;
48
+ readonly namespace?: string;
49
+ }, automationName: string): TfValue | void;
45
50
  /** Resolves a table-column token for a table-owned search tool. */
46
51
  tableColumnRef?(tableRefName: string, tableName: string, columnName: string): TfValue | void;
47
52
  /** App-local automations whose publish resource will be emitted in this build. */
@@ -229,7 +229,12 @@ export function skillToolToTf(entry, ctx) {
229
229
  if (ctx.foreignAutomationRef !== undefined &&
230
230
  typeof automation.parentName === "string" && automation.parentName !== "" &&
231
231
  typeof automation.name === "string" && automation.name !== "") {
232
- const lookup = ctx.foreignAutomationRef(automationTfLabel, automation.parentKind ?? "app", automation.parent, automation.parentName, automation.name);
232
+ const lookup = ctx.foreignAutomationRef(automationTfLabel, {
233
+ kind: automation.parentKind ?? "app",
234
+ refName: automation.parent,
235
+ name: automation.parentName,
236
+ ...(automation.parentNamespace !== undefined ? { namespace: automation.parentNamespace } : {}),
237
+ }, automation.name);
233
238
  if (lookup === undefined) {
234
239
  ctx.diagnostics.push(droppedSkillTool(where, "foreign automation lookup could not be materialized; dropped"));
235
240
  return undefined;
@@ -20,7 +20,7 @@ export function task(opts) {
20
20
  if (TASK_SYSTEM_FIELD_KEYS.has(key))
21
21
  throw new Error(`task ${JSON.stringify(opts.name)}: fields.${key} collides with the task's ${key} system field; use ${key}Field or another key.`);
22
22
  }
23
- const fields = authoredFields === undefined ? undefined : Object.entries(authoredFields).map(([bagKey, field]) => serializeField(field, bagKey));
23
+ const fields = authoredFields === undefined ? undefined : Object.entries(authoredFields).map(([bagKey, field]) => serializeField(field, bagKey, `task ${JSON.stringify(opts.name)}`));
24
24
  return { kind: "task", parent: "org", refName, payload: slimTokens({ ...rest, handle, namespace, ...(fields !== undefined && fields.length > 0 ? { fields } : {}) }), ...(opts.enabled !== undefined ? { enabled: opts.enabled } : {}) };
25
25
  } };
26
26
  }
@@ -9,6 +9,7 @@
9
9
  */
10
10
  import type { OrgRefLookup, WorkspaceAspect } from "../../engine/build/context.js";
11
11
  import { type ChildResourceScope, type TfValue } from "../../engine/tf/index.js";
12
+ import type { BuildFieldMetadata } from "../../graph/types.js";
12
13
  export interface AgentViewLayoutToTfOptions {
13
14
  readonly ownerRefName: string;
14
15
  /** The view owner's kind; an agent view's owner is always an app. */
@@ -18,6 +19,10 @@ export interface AgentViewLayoutToTfOptions {
18
19
  readonly objectId: TfValue;
19
20
  readonly diagnostics: string[];
20
21
  readonly fieldAddresses?: ReadonlyMap<string, string>;
22
+ /** Field bag key → display name, for custom-view calc("Name") checks. */
23
+ readonly fieldNames?: ReadonlyMap<string, string>;
24
+ /** Field bag key → metadata (type, option labels, tags). */
25
+ readonly fieldMetadata?: ReadonlyMap<string, BuildFieldMetadata>;
21
26
  readonly orgRefs?: OrgRefLookup;
22
27
  readonly workspaceAspects?: ReadonlyMap<string, WorkspaceAspect>;
23
28
  /** Resolves an own-app field reference (view/to-tf's field resolver). */
@@ -46,6 +51,12 @@ export interface ViewBlocksToTfPolicy {
46
51
  * policy.
47
52
  */
48
53
  readonly editorPolicy: boolean;
54
+ /**
55
+ * Fail the build on structure / binding / reference problems the page cannot
56
+ * render (check.mjs Layer 1 + catalog Layer 3). Custom views set this; agent
57
+ * views keep soft diagnostics so a pulled broken welcome screen still builds.
58
+ */
59
+ readonly strictStructure?: boolean;
49
60
  }
50
61
  /** A blocks layout → its HCL value (wrap it in `jsonencode`). */
51
62
  export declare function viewBlocksToTf(spec: unknown, where: string, opts: AgentViewLayoutToTfOptions, policy: ViewBlocksToTfPolicy): TfValue;
@@ -6,6 +6,7 @@ import { SUB_TYPE_BY_TYPE_KEY } from "../field/types.js";
6
6
  import { foreignFieldDataLabel, resolveForeignRef } from "../shared/foreign-ref.js";
7
7
  import { SYSTEM_FIELD_ID_ATTR_BY_KEY } from "./types.js";
8
8
  import { AGENT_VIEW_SPEC_FILTER_PROPS, AGENT_VIEW_SPEC_ID_PROPS, agentViewFontFamily, } from "./agent-view-layout.js";
9
+ import { reportStructureProblems, validateCustomViewLayout } from "./custom-view-validate.js";
9
10
  const PLATFORM_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
10
11
  const HEX_COLOR = /^#[0-9a-fA-F]{3,8}$/;
11
12
  const FONT_FAMILIES = new Set(Object.values(agentViewFontFamily));
@@ -68,7 +69,16 @@ export function viewBlocksToTf(spec, where, opts, policy) {
68
69
  throw new EntityTfError(`${where}.root must name an element`);
69
70
  if (elements === undefined || Object.keys(elements).length === 0)
70
71
  throw new EntityTfError(`${where}.elements must have at least one element`);
71
- checkStructure(doc["root"], elements, where, opts.diagnostics);
72
+ if (policy.strictStructure) {
73
+ validateCustomViewLayout(doc, where, {
74
+ ...(opts.fieldNames !== undefined ? { fieldNames: opts.fieldNames } : {}),
75
+ ...(opts.fieldMetadata !== undefined ? { fieldMetadata: opts.fieldMetadata } : {}),
76
+ diagnostics: opts.diagnostics,
77
+ });
78
+ }
79
+ else {
80
+ checkStructure(doc["root"], elements, where, opts.diagnostics);
81
+ }
72
82
  const out = {};
73
83
  for (const [key, value] of Object.entries(doc)) {
74
84
  if (key === "elements")
@@ -282,43 +292,8 @@ function checkStructure(root, elements, where, diagnostics) {
282
292
  if (children !== undefined && !Array.isArray(children))
283
293
  throw new EntityTfError(`${where}.elements.${id}.children must be a list of element ids`);
284
294
  }
285
- // The platform stores these (its schema does not cross-check child ids), but
286
- // the page fails to render them. Warn rather than fail, so a pulled layout
287
- // still builds and round-trips; fixing it is the author's call.
288
- for (const [id, raw] of Object.entries(elements)) {
289
- const children = record(raw)?.["children"];
290
- if (record(raw)?.["repeat"] !== undefined && (!Array.isArray(children) || children.length === 0)) {
291
- diagnostics.push(`${where}.elements.${id}.repeat: a repeated element needs a child element as its template; the page will fail to render this custom view`);
292
- }
293
- if (!Array.isArray(children))
294
- continue;
295
- for (const child of children) {
296
- if (typeof child !== "string" || !(child in elements)) {
297
- diagnostics.push(`${where}.elements.${id}.children: "${String(child)}" is not an element; the page will fail to render this custom view`);
298
- }
299
- }
300
- }
301
- const state = new Map();
302
- let cycle;
303
- const visit = (id, path) => {
304
- if (cycle !== undefined || state.get(id) === "done")
305
- return;
306
- if (state.get(id) === "visiting") {
307
- cycle = [...path, id].join(" → ");
308
- return;
309
- }
310
- state.set(id, "visiting");
311
- const children = record(elements[id])?.["children"];
312
- if (Array.isArray(children))
313
- for (const child of children)
314
- if (typeof child === "string" && child in elements)
315
- visit(child, [...path, id]);
316
- state.set(id, "done");
317
- };
318
- for (const id of Object.keys(elements))
319
- visit(id, []);
320
- if (cycle !== undefined)
321
- diagnostics.push(`${where}: children form a cycle (${cycle}); the page will fail to render this custom view`);
295
+ // Agent views: warn so a pulled broken welcome screen still builds.
296
+ reportStructureProblems(root, elements, where, diagnostics);
322
297
  }
323
298
  function policyWarnings(type, element, where, diagnostics) {
324
299
  const reason = !UI_EDITABLE_BLOCKS.has(type)
@@ -0,0 +1,29 @@
1
+ /**
2
+ * check.mjs-parity structure checks for Custom managed views (#1771 / #1758).
3
+ * Hard structural failures (missing root/type, cycles, broken filters) fail the
4
+ * build as EntityTfError. Reachability and live-list selection gaps match
5
+ * check.mjs `warn` — they push to diagnostics so a pulled live layout still
6
+ * builds and plans clean (Blueprint Supplier Workspace has both). Agent views
7
+ * keep the softer diagnostics in checkStructure / reportStructureProblems.
8
+ *
9
+ * Layer 3 catalog checks (calc field names, option ids, tag helpers against
10
+ * the live App) need aspect-aware resolution; typed field refs already fail
11
+ * via resolveField. Syntax-only calc rules (AVG / empty COUNT) live here.
12
+ * TODO(#1784): consume fieldNames / fieldMetadata for Layer 3 + tag helpers.
13
+ */
14
+ import type { BuildFieldMetadata } from "../../graph/types.js";
15
+ export interface CustomViewValidateOptions {
16
+ /** TODO(#1784): aspect-aware Layer 3 once #1770 lands Preston custom views. */
17
+ readonly fieldNames?: ReadonlyMap<string, string>;
18
+ readonly fieldMetadata?: ReadonlyMap<string, BuildFieldMetadata>;
19
+ /** Build warnings (check.mjs `warn`); pushed, never thrown. */
20
+ readonly diagnostics?: string[];
21
+ }
22
+ /**
23
+ * Offline Layer 1 checks that Javier's check.mjs runs before paste.
24
+ * Call only for `customViews.*.layout` (strictStructure).
25
+ * Collects every problem, then throws once (parity with Go / check.mjs).
26
+ */
27
+ export declare function validateCustomViewLayout(spec: unknown, where: string, opts?: CustomViewValidateOptions): void;
28
+ /** Soft version used by agent views: same tree checks as today (diagnostics, not fatal). */
29
+ export declare function reportStructureProblems(_root: string, elements: Readonly<Record<string, unknown>>, where: string, diagnostics: string[]): void;
@@ -0,0 +1,292 @@
1
+ import { EntityTfError } from "../../engine/entity.js";
2
+ const CONTAINERS = new Set(["PanesBlock", "StackBlock", "RowBlock", "CardBlock"]);
3
+ const LIST_BLOCKS = new Set(["ListCollectionBlock", "DataTableBlock"]);
4
+ const FILTER_GROUPS = new Set(["AND", "OR"]);
5
+ /** The record query ignores "not" on these, so the filter silently means the opposite. */
6
+ const NOT_IGNORED = new Set(["AND", "OR", "CONSECUTIVE_RANGE", "CURRENT_RANGE"]);
7
+ const DATE = /^\d{4}-\d{2}-\d{2}$/;
8
+ const AVG_CALL = /\bAVG\(/;
9
+ const EMPTY_COUNT = /COUNT\(\s*\)/;
10
+ const SELECTION_KEYS = ["selectedId", "selectedAspectId", "selectedHandle"];
11
+ function isObj(v) {
12
+ return v !== null && typeof v === "object" && !Array.isArray(v);
13
+ }
14
+ /** Any binding shape ($state / $bindState / $item / $index). Used for state-initial scans. */
15
+ function isBinding(v) {
16
+ return isObj(v) && ("$state" in v || "$bindState" in v || "$item" in v || "$index" in v);
17
+ }
18
+ /** Selection props must be $state / $bindState — $item / $index do not drive the details pane. */
19
+ function isStateBinding(v) {
20
+ return isObj(v) && ("$state" in v || "$bindState" in v);
21
+ }
22
+ /**
23
+ * Offline Layer 1 checks that Javier's check.mjs runs before paste.
24
+ * Call only for `customViews.*.layout` (strictStructure).
25
+ * Collects every problem, then throws once (parity with Go / check.mjs).
26
+ */
27
+ export function validateCustomViewLayout(spec, where, opts = {}) {
28
+ const problems = [];
29
+ const note = (at, msg) => {
30
+ problems.push(`${at}: ${msg}`);
31
+ };
32
+ /** check.mjs warn-class issues: do not fail build/pull of live layouts. */
33
+ const warn = (at, msg) => {
34
+ opts.diagnostics?.push(`${at}: ${msg}`);
35
+ };
36
+ if (!isObj(spec)) {
37
+ throw new EntityTfError(`${where}: must be an object`);
38
+ }
39
+ const json = JSON.stringify(spec);
40
+ const leftovers = [...new Set(json.match(/\{\{[^}]+\}\}/g) ?? [])];
41
+ if (leftovers.length > 0) {
42
+ note(`${where}.placeholders`, `fill these from the app's fields: ${leftovers.slice(0, 8).join(", ")}${leftovers.length > 8 ? ", ..." : ""}`);
43
+ }
44
+ const root = spec["root"];
45
+ const elementsRaw = spec["elements"];
46
+ if (typeof root !== "string" || root === "") {
47
+ note(`${where}.root`, "must name an element");
48
+ }
49
+ if (!isObj(elementsRaw) || Object.keys(elementsRaw).length === 0) {
50
+ note(`${where}.elements`, "must have at least one element");
51
+ throwIf(problems);
52
+ return;
53
+ }
54
+ const elements = elementsRaw;
55
+ if (typeof root !== "string" || root === "") {
56
+ throwIf(problems);
57
+ return;
58
+ }
59
+ if (!(root in elements)) {
60
+ note(`${where}.root`, `"${root}" is not an element`);
61
+ throwIf(problems);
62
+ return;
63
+ }
64
+ const rootEl = elements[root];
65
+ const rootType = isObj(rootEl) && typeof rootEl["type"] === "string" ? rootEl["type"] : "";
66
+ // check.mjs warns on any non-PanesBlock root. We error only when a live list
67
+ // needs the details pane — chart/StackBlock dashboards without lists stay valid.
68
+ const hasLiveList = Object.values(elements).some((raw) => {
69
+ if (!isObj(raw) || !isObj(raw["props"]))
70
+ return false;
71
+ const t = raw["type"];
72
+ return typeof t === "string" && LIST_BLOCKS.has(t) && raw["props"]["aspectId"] !== undefined;
73
+ });
74
+ if (hasLiveList && rootType !== "PanesBlock") {
75
+ note(`${where}.root`, `"${root}" must be a PanesBlock (got ${rootType === "" ? "no type" : `"${rootType}"`}); a live list needs a panes root so rows can open the details panel`);
76
+ }
77
+ else if (rootType !== "PanesBlock") {
78
+ // check.mjs: warn('spec.root', 'the root is usually a PanesBlock ...').
79
+ opts.diagnostics?.push(`${where}.root: "${root}" is ${rootType === "" ? "untyped" : `a ${rootType}`}; the root is usually a PanesBlock (needed for record lists to open the details pane)`);
80
+ }
81
+ const state = isObj(spec["state"]) ? spec["state"] : {};
82
+ const parents = {};
83
+ for (const [id, raw] of Object.entries(elements)) {
84
+ const elWhere = `${where}.elements.${id}`;
85
+ if (!isObj(raw) || typeof raw["type"] !== "string") {
86
+ note(elWhere, "each element needs a \"type\"");
87
+ continue;
88
+ }
89
+ if (!isObj(raw["props"])) {
90
+ note(elWhere, "each element needs a \"props\" object (use {} when empty)");
91
+ continue;
92
+ }
93
+ const children = raw["children"];
94
+ if (children !== undefined) {
95
+ if (!Array.isArray(children)) {
96
+ note(elWhere, "\"children\" must be a list of element ids");
97
+ }
98
+ else {
99
+ // Intended promotion (edk#1771): check.mjs only warns here. The page does not
100
+ // render these children, so EDK fails closed, same as the Go provider.
101
+ if (children.length > 0 && !CONTAINERS.has(raw["type"])) {
102
+ note(elWhere, `${raw["type"]} does not render children; only ${[...CONTAINERS].join(", ")} do`);
103
+ }
104
+ if (raw["repeat"] !== undefined && children.length === 0) {
105
+ note(`${elWhere}.repeat`, "a repeated element needs a child element as its template; the page will fail to render this custom view");
106
+ }
107
+ for (const child of children) {
108
+ if (typeof child !== "string" || !(child in elements)) {
109
+ note(`${elWhere}.children`, `"${String(child)}" is not an element; the page will fail to render this custom view`);
110
+ }
111
+ else {
112
+ (parents[child] ??= []).push(id);
113
+ }
114
+ }
115
+ }
116
+ }
117
+ else if (raw["repeat"] !== undefined) {
118
+ note(`${elWhere}.repeat`, "a repeated element needs a child element as its template; the page will fail to render this custom view");
119
+ }
120
+ }
121
+ for (const [child, list] of Object.entries(parents)) {
122
+ if (list.length > 1) {
123
+ note(`${where}.elements.${child}`, `used by several parents (${list.join(", ")}); give each placement its own element`);
124
+ }
125
+ }
126
+ const reachable = new Set();
127
+ const visit = (id, path) => {
128
+ if (path.includes(id)) {
129
+ note(`${where}.elements.${id}`, `cycle: ${[...path, id].join(" -> ")}`);
130
+ return;
131
+ }
132
+ if (reachable.has(id) || !(id in elements))
133
+ return;
134
+ reachable.add(id);
135
+ const children = elements[id]["children"];
136
+ if (Array.isArray(children)) {
137
+ for (const child of children)
138
+ if (typeof child === "string")
139
+ visit(child, [...path, id]);
140
+ }
141
+ };
142
+ visit(root, []);
143
+ for (const id of Object.keys(elements)) {
144
+ if (!reachable.has(id)) {
145
+ warn(`${where}.elements.${id}`, "not reachable from the root, so it never renders");
146
+ }
147
+ }
148
+ const readState = (path) => {
149
+ let node = state;
150
+ for (const part of path.split("/").filter(Boolean)) {
151
+ if (!isObj(node) || !(part in node))
152
+ return { found: false };
153
+ node = node[part];
154
+ }
155
+ return { found: true, value: node };
156
+ };
157
+ const walkedState = new Set();
158
+ const walkFilter = (node, filterWhere) => {
159
+ if (node == null)
160
+ return;
161
+ if (!isObj(node)) {
162
+ note(filterWhere, "a filter must be an object");
163
+ return;
164
+ }
165
+ if (node["not"] === true && typeof node["type"] === "string" && NOT_IGNORED.has(node["type"])) {
166
+ const type = node["type"];
167
+ note(filterWhere, type === "AND" || type === "OR"
168
+ ? `"not" is ignored on ${type} groups. Negate each child instead (not A and not B, instead of not (A or B)).`
169
+ : `"not" is ignored on ${type}. For "older than N", use a positive range that ends N units ago, e.g. { "type": "CONSECUTIVE_RANGE", "count": 3650, "offset": 30, "unit": "DAY" }.`);
170
+ }
171
+ if (FILTER_GROUPS.has(node["type"])) {
172
+ if (!Array.isArray(node["children"])) {
173
+ note(filterWhere, `${node["type"]} needs a "children" list`);
174
+ return;
175
+ }
176
+ node["children"].forEach((c, i) => walkFilter(c, `${filterWhere}.children[${i}]`));
177
+ return;
178
+ }
179
+ if (typeof node["type"] !== "string") {
180
+ note(filterWhere, "filter node is missing \"type\"");
181
+ }
182
+ // Leaf filters without field / leftValue stay on the platform validator.
183
+ };
184
+ for (const [id, raw] of Object.entries(elements)) {
185
+ if (!isObj(raw) || !isObj(raw["props"]))
186
+ continue;
187
+ const elWhere = `${where}.elements.${id}`;
188
+ const props = raw["props"];
189
+ const type = raw["type"];
190
+ const scan = (value, path) => {
191
+ if (isBinding(value)) {
192
+ const target = value["$state"] ?? value["$bindState"];
193
+ if (typeof target === "string" && !target.startsWith("/host/") && !readState(target).found) {
194
+ note(`${elWhere}.${path}`, `binds to "${target}", which is not in spec.state. Add an initial value there.`);
195
+ }
196
+ return;
197
+ }
198
+ if (Array.isArray(value))
199
+ value.forEach((v, i) => scan(v, `${path}[${i}]`));
200
+ else if (isObj(value))
201
+ for (const [k, v] of Object.entries(value))
202
+ scan(v, `${path}.${k}`);
203
+ };
204
+ for (const [key, value] of Object.entries(props))
205
+ scan(value, key);
206
+ if (props["filterJson"] !== undefined) {
207
+ if (isBinding(props["filterJson"])) {
208
+ const target = props["filterJson"]["$bindState"]
209
+ ?? props["filterJson"]["$state"];
210
+ const initial = typeof target === "string" ? readState(target) : { found: false };
211
+ if (initial.found && initial.value != null && typeof target === "string" && !walkedState.has(target)) {
212
+ walkedState.add(target);
213
+ walkFilter(initial.value, `${where}.state${target.replaceAll("/", ".")}`);
214
+ }
215
+ }
216
+ else {
217
+ walkFilter(props["filterJson"], `${elWhere}.filterJson`);
218
+ }
219
+ }
220
+ if (typeof props["calc"] === "string") {
221
+ const calc = props["calc"];
222
+ if (AVG_CALL.test(calc))
223
+ note(`${elWhere}.calc`, "use AVERAGE, not AVG");
224
+ if (EMPTY_COUNT.test(calc))
225
+ note(`${elWhere}.calc`, "COUNT needs a field, e.g. COUNT(\"Title\")");
226
+ }
227
+ if (type === "ChartBlock" && (typeof props["dateFieldId"] === "string" || isObj(props["dateFieldId"]))) {
228
+ const range = props["range"];
229
+ if (typeof range === "string") {
230
+ const [a, b, extra] = range.split("/");
231
+ if (extra !== undefined || !DATE.test(a ?? "") || !DATE.test(b ?? "")) {
232
+ note(`${elWhere}.range`, `"${range}" is not a fixed date range. Relative presets like last90Days do not apply to date-series charts; use "YYYY-MM-DD/YYYY-MM-DD"`);
233
+ }
234
+ else if (a > b) {
235
+ note(`${elWhere}.range`, "start date is after end date");
236
+ }
237
+ }
238
+ }
239
+ // Live lists on a custom view need all three selection bindings as $state /
240
+ // $bindState so the details pane opens. $item / $index do not count.
241
+ // Warn-only: pulled Blueprint layouts omit these and must still build.
242
+ if (LIST_BLOCKS.has(type) && props["aspectId"] !== undefined) {
243
+ const missing = SELECTION_KEYS.filter((key) => !isStateBinding(props[key]));
244
+ if (missing.length > 0) {
245
+ warn(elWhere, `live list without selectedId/selectedAspectId/selectedHandle bindings; rows will not open the details pane (missing or not $state/$bindState: ${missing.join(", ")})`);
246
+ }
247
+ }
248
+ }
249
+ throwIf(problems);
250
+ }
251
+ function throwIf(problems) {
252
+ if (problems.length === 0)
253
+ return;
254
+ throw new EntityTfError(problems.join("\n"));
255
+ }
256
+ /** Soft version used by agent views: same tree checks as today (diagnostics, not fatal). */
257
+ export function reportStructureProblems(_root, elements, where, diagnostics) {
258
+ for (const [id, raw] of Object.entries(elements)) {
259
+ const children = isObj(raw) ? raw["children"] : undefined;
260
+ if (isObj(raw) && raw["repeat"] !== undefined && (!Array.isArray(children) || children.length === 0)) {
261
+ diagnostics.push(`${where}.elements.${id}.repeat: a repeated element needs a child element as its template; the page will fail to render this custom view`);
262
+ }
263
+ if (!Array.isArray(children))
264
+ continue;
265
+ for (const child of children) {
266
+ if (typeof child !== "string" || !(child in elements)) {
267
+ diagnostics.push(`${where}.elements.${id}.children: "${String(child)}" is not an element; the page will fail to render this custom view`);
268
+ }
269
+ }
270
+ }
271
+ const state = new Map();
272
+ let cycle;
273
+ const visit = (id, path) => {
274
+ if (cycle !== undefined || state.get(id) === "done")
275
+ return;
276
+ if (state.get(id) === "visiting") {
277
+ cycle = [...path, id].join(" → ");
278
+ return;
279
+ }
280
+ state.set(id, "visiting");
281
+ const children = isObj(elements[id]) ? elements[id]["children"] : undefined;
282
+ if (Array.isArray(children))
283
+ for (const child of children)
284
+ if (typeof child === "string" && child in elements)
285
+ visit(child, [...path, id]);
286
+ state.set(id, "done");
287
+ };
288
+ for (const id of Object.keys(elements))
289
+ visit(id, []);
290
+ if (cycle !== undefined)
291
+ diagnostics.push(`${where}: children form a cycle (${cycle}); the page will fail to render this custom view`);
292
+ }
@@ -21,6 +21,8 @@ export interface ViewOwner {
21
21
  readonly scope?: ChildResourceScope;
22
22
  /** Stage keys declared by the owning app, used when ei exports a raw stage UUID. */
23
23
  readonly stageKeys?: ReadonlySet<string>;
24
+ /** The owning app's stage handles → real stage keys (see `stageKeyByHandle`, #1136). */
25
+ readonly stageKeyByHandle?: ReadonlyMap<string, string>;
24
26
  }
25
27
  export interface ViewsFromTfResult {
26
28
  readonly layouts: readonly NormalizedLayout[];