@elementumai/edk 0.9.18 → 0.9.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (219) hide show
  1. package/README.md +154 -9
  2. package/dist-sdk/src/catalog/factories.d.ts +35 -1
  3. package/dist-sdk/src/catalog/factories.js +36 -0
  4. package/dist-sdk/src/catalog/from-authoring.d.ts +13 -8
  5. package/dist-sdk/src/catalog/from-authoring.js +34 -9
  6. package/dist-sdk/src/catalog/index.d.ts +2 -2
  7. package/dist-sdk/src/catalog/index.js +2 -2
  8. package/dist-sdk/src/catalog/org.d.ts +39 -1
  9. package/dist-sdk/src/catalog/org.js +460 -50
  10. package/dist-sdk/src/catalog/render.js +6 -6
  11. package/dist-sdk/src/catalog/token.js +7 -0
  12. package/dist-sdk/src/catalog/types.d.ts +44 -1
  13. package/dist-sdk/src/catalog/types.js +13 -0
  14. package/dist-sdk/src/core/triggers/on-demand.d.ts +39 -3
  15. package/dist-sdk/src/core/triggers/on-demand.js +10 -2
  16. package/dist-sdk/src/engine/build/context.d.ts +1 -1
  17. package/dist-sdk/src/engine/ei/run.d.ts +149 -0
  18. package/dist-sdk/src/engine/ei/run.js +1132 -0
  19. package/dist-sdk/src/engine/logging.d.ts +17 -0
  20. package/dist-sdk/src/engine/logging.js +18 -0
  21. package/dist-sdk/src/engine/pull/ref-only.d.ts +5 -0
  22. package/dist-sdk/src/engine/pull/ref-only.js +64 -27
  23. package/dist-sdk/src/engine/pull/result-output.d.ts +8 -0
  24. package/dist-sdk/src/engine/pull/result-output.js +88 -4
  25. package/dist-sdk/src/engine/tf/expr.js +39 -14
  26. package/dist-sdk/src/engine/tf/index.d.ts +3 -3
  27. package/dist-sdk/src/engine/tf/index.js +2 -2
  28. package/dist-sdk/src/engine/tf/labels.d.ts +8 -0
  29. package/dist-sdk/src/engine/tf/labels.js +13 -0
  30. package/dist-sdk/src/engine/tf/model.d.ts +22 -1
  31. package/dist-sdk/src/engine/tf/parse.d.ts +19 -0
  32. package/dist-sdk/src/engine/tf/parse.js +197 -10
  33. package/dist-sdk/src/engine/tf/render.d.ts +4 -2
  34. package/dist-sdk/src/engine/tf/render.js +41 -7
  35. package/dist-sdk/src/engine/validation.d.ts +39 -0
  36. package/dist-sdk/src/engine/validation.js +85 -0
  37. package/dist-sdk/src/engine/workspace/loader.js +49 -12
  38. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +11 -1
  39. package/dist-sdk/src/entities/access-policy/from-tf.js +6 -1
  40. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +11 -0
  41. package/dist-sdk/src/entities/access-policy/to-tf.js +16 -6
  42. package/dist-sdk/src/entities/agent/build.d.ts +4 -16
  43. package/dist-sdk/src/entities/agent/build.js +40 -5
  44. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +4 -2
  45. package/dist-sdk/src/entities/agent/to-tf.js +6 -3
  46. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +2 -0
  47. package/dist-sdk/src/entities/agent-tool/from-tf.js +7 -1
  48. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
  49. package/dist-sdk/src/entities/agent-tool/to-tf.js +29 -6
  50. package/dist-sdk/src/entities/app/build.d.ts +98 -19
  51. package/dist-sdk/src/entities/app/build.js +51 -19
  52. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +22 -1
  53. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -0
  54. package/dist-sdk/src/entities/app/from-tf.js +11 -5
  55. package/dist-sdk/src/entities/app/index.d.ts +6 -5
  56. package/dist-sdk/src/entities/app/index.js +2 -0
  57. package/dist-sdk/src/entities/app/module.js +18 -2
  58. package/dist-sdk/src/entities/app/to-tf.js +21 -11
  59. package/dist-sdk/src/entities/automation/build.d.ts +49 -6
  60. package/dist-sdk/src/entities/automation/build.js +163 -19
  61. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +24 -1
  62. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +320 -39
  63. package/dist-sdk/src/entities/automation/from-tf.d.ts +28 -6
  64. package/dist-sdk/src/entities/automation/from-tf.js +563 -74
  65. package/dist-sdk/src/entities/automation/generated/task-output-contracts.d.ts +33 -0
  66. package/dist-sdk/src/entities/automation/generated/task-output-contracts.js +183 -0
  67. package/dist-sdk/src/entities/automation/index.d.ts +2 -2
  68. package/dist-sdk/src/entities/automation/index.js +1 -1
  69. package/dist-sdk/src/entities/automation/module.d.ts +2 -0
  70. package/dist-sdk/src/entities/automation/module.js +93 -8
  71. package/dist-sdk/src/entities/automation/output-field-types.d.ts +7 -0
  72. package/dist-sdk/src/entities/automation/output-field-types.js +36 -0
  73. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +9 -0
  74. package/dist-sdk/src/entities/automation/output-key-wire-name.js +13 -0
  75. package/dist-sdk/src/entities/automation/script-code.d.ts +17 -0
  76. package/dist-sdk/src/entities/automation/script-code.js +91 -5
  77. package/dist-sdk/src/entities/automation/system-ref-name.d.ts +16 -0
  78. package/dist-sdk/src/entities/automation/system-ref-name.js +48 -0
  79. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +17 -0
  80. package/dist-sdk/src/entities/automation/task-output-labels.js +47 -0
  81. package/dist-sdk/src/entities/automation/tasks.d.ts +53 -4
  82. package/dist-sdk/src/entities/automation/tasks.js +38 -9
  83. package/dist-sdk/src/entities/automation/to-tf.d.ts +4 -0
  84. package/dist-sdk/src/entities/automation/to-tf.js +647 -167
  85. package/dist-sdk/src/entities/automation/triggers.d.ts +4 -2
  86. package/dist-sdk/src/entities/automation/triggers.js +4 -0
  87. package/dist-sdk/src/entities/automation/types.js +1 -0
  88. package/dist-sdk/src/entities/chart/from-tf.js +33 -17
  89. package/dist-sdk/src/entities/chart/module.js +3 -1
  90. package/dist-sdk/src/entities/chart/printer.d.ts +1 -0
  91. package/dist-sdk/src/entities/chart/printer.js +26 -16
  92. package/dist-sdk/src/entities/chart/rebind-owner.d.ts +3 -0
  93. package/dist-sdk/src/entities/chart/rebind-owner.js +42 -0
  94. package/dist-sdk/src/entities/chart/to-tf.js +21 -12
  95. package/dist-sdk/src/entities/dashboard/build.d.ts +4 -0
  96. package/dist-sdk/src/entities/dashboard/from-tf.js +15 -4
  97. package/dist-sdk/src/entities/dashboard/to-tf.d.ts +2 -0
  98. package/dist-sdk/src/entities/dashboard/to-tf.js +13 -0
  99. package/dist-sdk/src/entities/dashboard-widget/module.js +4 -0
  100. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +72 -30
  101. package/dist-sdk/src/entities/dynamic-layout/dialect.d.ts +3 -0
  102. package/dist-sdk/src/entities/dynamic-layout/dialect.js +5 -0
  103. package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +9 -6
  104. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +188 -26
  105. package/dist-sdk/src/entities/dynamic-layout/module.js +4 -1
  106. package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +5 -1
  107. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +254 -23
  108. package/dist-sdk/src/entities/element/build.d.ts +33 -13
  109. package/dist-sdk/src/entities/element/build.js +5 -1
  110. package/dist-sdk/src/entities/element/from-tf.d.ts +12 -0
  111. package/dist-sdk/src/entities/element/from-tf.js +64 -3
  112. package/dist-sdk/src/entities/element/index.d.ts +5 -2
  113. package/dist-sdk/src/entities/element/index.js +2 -0
  114. package/dist-sdk/src/entities/element/module.js +11 -3
  115. package/dist-sdk/src/entities/element/to-tf.js +20 -2
  116. package/dist-sdk/src/entities/field/build.d.ts +14 -1
  117. package/dist-sdk/src/entities/field/build.js +3 -0
  118. package/dist-sdk/src/entities/field/from-tf.d.ts +3 -0
  119. package/dist-sdk/src/entities/field/from-tf.js +50 -1
  120. package/dist-sdk/src/entities/field/media-types.d.ts +6 -0
  121. package/dist-sdk/src/entities/field/media-types.js +30 -0
  122. package/dist-sdk/src/entities/field/module.js +1 -0
  123. package/dist-sdk/src/entities/field/to-tf.d.ts +23 -2
  124. package/dist-sdk/src/entities/field/to-tf.js +142 -22
  125. package/dist-sdk/src/entities/file-reader/from-tf.js +14 -5
  126. package/dist-sdk/src/entities/file-reader/module.js +1 -0
  127. package/dist-sdk/src/entities/file-reader/types.d.ts +2 -0
  128. package/dist-sdk/src/entities/file-reader/types.js +1 -1
  129. package/dist-sdk/src/entities/portal/build.d.ts +26 -0
  130. package/dist-sdk/src/entities/portal/build.js +37 -0
  131. package/dist-sdk/src/entities/portal/from-tf.d.ts +27 -0
  132. package/dist-sdk/src/entities/portal/from-tf.js +75 -0
  133. package/dist-sdk/src/entities/portal/index.d.ts +1 -0
  134. package/dist-sdk/src/entities/portal/index.js +1 -0
  135. package/dist-sdk/src/entities/portal/module.d.ts +3 -0
  136. package/dist-sdk/src/entities/portal/module.js +28 -0
  137. package/dist-sdk/src/entities/portal/to-tf.d.ts +12 -0
  138. package/dist-sdk/src/entities/portal/to-tf.js +73 -0
  139. package/dist-sdk/src/entities/portal/types.d.ts +1 -0
  140. package/dist-sdk/src/entities/portal/types.js +1 -0
  141. package/dist-sdk/src/entities/relationship/from-tf.d.ts +8 -1
  142. package/dist-sdk/src/entities/relationship/from-tf.js +53 -10
  143. package/dist-sdk/src/entities/relationship/module.js +2 -0
  144. package/dist-sdk/src/entities/relationship/pair-check.d.ts +7 -0
  145. package/dist-sdk/src/entities/relationship/pair-check.js +68 -0
  146. package/dist-sdk/src/entities/relationship/to-tf.d.ts +10 -0
  147. package/dist-sdk/src/entities/relationship/to-tf.js +31 -13
  148. package/dist-sdk/src/entities/search-table/module.js +1 -0
  149. package/dist-sdk/src/entities/search-table/to-tf.d.ts +1 -0
  150. package/dist-sdk/src/entities/search-table/to-tf.js +1 -1
  151. package/dist-sdk/src/entities/service-account/build.d.ts +15 -2
  152. package/dist-sdk/src/entities/service-account/from-tf.d.ts +2 -4
  153. package/dist-sdk/src/entities/service-account/from-tf.js +17 -5
  154. package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +56 -0
  155. package/dist-sdk/src/entities/service-account/role-fidelity.js +243 -0
  156. package/dist-sdk/src/entities/service-account/to-tf.d.ts +14 -0
  157. package/dist-sdk/src/entities/service-account/to-tf.js +17 -0
  158. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +1 -1
  159. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +5 -2
  160. package/dist-sdk/src/entities/shared/filters/ast.d.ts +15 -2
  161. package/dist-sdk/src/entities/shared/filters/index.d.ts +25 -2
  162. package/dist-sdk/src/entities/shared/filters/index.js +38 -5
  163. package/dist-sdk/src/entities/shared/filters/print.js +31 -3
  164. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +25 -3
  165. package/dist-sdk/src/entities/shared/filters/tf-codec.js +51 -15
  166. package/dist-sdk/src/entities/shared/filters/types.d.ts +22 -5
  167. package/dist-sdk/src/entities/shared/foreign-ref.d.ts +16 -0
  168. package/dist-sdk/src/entities/shared/foreign-ref.js +17 -1
  169. package/dist-sdk/src/entities/shared/tool-field-ref.js +6 -9
  170. package/dist-sdk/src/entities/shared/types/field-types.d.ts +10 -5
  171. package/dist-sdk/src/entities/shared/types/field-types.js +4 -0
  172. package/dist-sdk/src/entities/skill/access-policy.d.ts +17 -0
  173. package/dist-sdk/src/entities/skill/access-policy.js +101 -0
  174. package/dist-sdk/src/entities/skill/build.d.ts +3 -0
  175. package/dist-sdk/src/entities/skill/build.js +3 -0
  176. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +4 -1
  177. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +23 -1
  178. package/dist-sdk/src/entities/skill/from-tf.d.ts +2 -0
  179. package/dist-sdk/src/entities/skill/from-tf.js +70 -22
  180. package/dist-sdk/src/entities/skill/index.d.ts +2 -0
  181. package/dist-sdk/src/entities/skill/index.js +1 -0
  182. package/dist-sdk/src/entities/skill/input-coverage.d.ts +7 -0
  183. package/dist-sdk/src/entities/skill/input-coverage.js +11 -0
  184. package/dist-sdk/src/entities/skill/module.js +1 -0
  185. package/dist-sdk/src/entities/skill/to-tf.d.ts +2 -2
  186. package/dist-sdk/src/entities/skill/to-tf.js +19 -6
  187. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
  188. package/dist-sdk/src/entities/skill-tool/from-tf.js +8 -2
  189. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +2 -2
  190. package/dist-sdk/src/entities/skill-tool/to-tf.js +29 -6
  191. package/dist-sdk/src/entities/table/catalog.d.ts +14 -0
  192. package/dist-sdk/src/entities/table/catalog.js +66 -0
  193. package/dist-sdk/src/entities/table/module.js +2 -1
  194. package/dist-sdk/src/entities/table/to-tf.js +5 -5
  195. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +89 -0
  196. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +277 -0
  197. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +51 -0
  198. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +360 -0
  199. package/dist-sdk/src/entities/view/agent-view-layout.d.ts +151 -0
  200. package/dist-sdk/src/entities/view/agent-view-layout.js +21 -0
  201. package/dist-sdk/src/entities/view/from-tf.d.ts +6 -3
  202. package/dist-sdk/src/entities/view/from-tf.js +161 -14
  203. package/dist-sdk/src/entities/view/module.js +30 -3
  204. package/dist-sdk/src/entities/view/to-tf.d.ts +24 -2
  205. package/dist-sdk/src/entities/view/to-tf.js +95 -9
  206. package/dist-sdk/src/entities/view/types.d.ts +4 -15
  207. package/dist-sdk/src/entities/view/types.js +17 -15
  208. package/dist-sdk/src/entities/widget/build.d.ts +16 -1
  209. package/dist-sdk/src/entities/widget/build.js +11 -1
  210. package/dist-sdk/src/entities/widget/to-tf.js +36 -10
  211. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +38 -10
  212. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  213. package/dist-sdk/src/graph/index.d.ts +54 -0
  214. package/dist-sdk/src/graph/index.js +30 -0
  215. package/dist-sdk/src/graph/modules.js +2 -0
  216. package/dist-sdk/src/graph/types.d.ts +133 -2
  217. package/dist-sdk/src/internal/sdk-package.d.ts +1 -1
  218. package/dist-sdk/src/internal/sdk-package.js +1 -0
  219. package/package.json +11 -1
@@ -7,11 +7,12 @@
7
7
  */
8
8
  import { EntityTfError } from "../../engine/entity.js";
9
9
  import { optionalString, resourceRefLabel } from "../../engine/pull/context.js";
10
- import { scopedLabelToBagKey } from "../../engine/tf/index.js";
10
+ import { isTfExpr, scopedLabelToBagKey } from "../../engine/tf/index.js";
11
11
  import { skillToolFromTf } from "../skill-tool/from-tf.js";
12
12
  import { APP_RESOURCE_TYPE } from "../app/module.js";
13
- import { analyzeSkillInputCoverage, decomposeSkillInstructions, skillCoverageGapDiagnostics, skillCoverageReportLines, } from "./input-coverage.js";
13
+ import { analyzeSkillInputCoverage, decomposeSkillInstructionsLossless, skillCoverageGapDiagnostics, skillCoverageReportLines, } from "./input-coverage.js";
14
14
  import { SKILL_RESOURCE_TYPE } from "./module.js";
15
+ import { skillAccessPolicyFromTf } from "./access-policy.js";
15
16
  /** Attributes `skillFromTf` understands — anything else is dialect growth, reported loudly. */
16
17
  const KNOWN_SKILL_ATTRS = new Set([
17
18
  "owner_id",
@@ -28,9 +29,6 @@ const KNOWN_SKILL_ATTRS = new Set([
28
29
  "positive_keywords",
29
30
  "negative_keywords",
30
31
  "depends_on",
31
- ]);
32
- /** Dialect attrs with no authoring slot yet — reported by name, skill still pulled. */
33
- const UNAUTHORABLE_SKILL_ATTRS = new Set([
34
32
  "user_ids",
35
33
  "group_ids",
36
34
  ]);
@@ -44,6 +42,68 @@ function optionalStringList(attrs, key, where, ctx) {
44
42
  }
45
43
  return value;
46
44
  }
45
+ /** Walk a parsed value, rejecting anything that is still a Terraform expression. */
46
+ function asPlainJson(value) {
47
+ if (isTfExpr(value))
48
+ return { ok: false };
49
+ if (Array.isArray(value)) {
50
+ const items = [];
51
+ for (const item of value) {
52
+ const plain = asPlainJson(item);
53
+ if (!plain.ok)
54
+ return plain;
55
+ items.push(plain.value);
56
+ }
57
+ return { ok: true, value: items };
58
+ }
59
+ if (typeof value === "object" && value !== null) {
60
+ const out = {};
61
+ for (const [key, child] of Object.entries(value)) {
62
+ const plain = asPlainJson(child);
63
+ if (!plain.ok)
64
+ return plain;
65
+ out[key] = plain.value;
66
+ }
67
+ return { ok: true, value: out };
68
+ }
69
+ return { ok: true, value };
70
+ }
71
+ function propertiesObject(value, where, ctx) {
72
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
73
+ ctx.diagnostics.push(`${where}: properties JSON must be an object; dropped`);
74
+ return undefined;
75
+ }
76
+ return value;
77
+ }
78
+ /**
79
+ * `properties` is a JSON string on the wire. ei emits it as `jsonencode({...})`
80
+ * so the file formats; older builds may still carry a quoted JSON string.
81
+ * Either shape keeps the skill. An unreadable shape drops only the attribute.
82
+ */
83
+ function propertiesFromTf(raw, where, ctx) {
84
+ if (raw === undefined || raw === null || raw === "")
85
+ return undefined;
86
+ if (typeof raw === "string") {
87
+ try {
88
+ // eslint-disable-next-line no-restricted-syntax -- properties is a JSON string on the resource, not an authored entity.
89
+ return propertiesObject(JSON.parse(raw), where, ctx);
90
+ }
91
+ catch {
92
+ ctx.diagnostics.push(`${where}: properties is not valid JSON; dropped`);
93
+ return undefined;
94
+ }
95
+ }
96
+ if (isTfExpr(raw) && raw.$expr === "jsonencode") {
97
+ const plain = asPlainJson(raw.value);
98
+ if (!plain.ok) {
99
+ ctx.diagnostics.push(`${where}: properties jsonencode payload is not plain JSON; dropped`);
100
+ return undefined;
101
+ }
102
+ return propertiesObject(plain.value, where, ctx);
103
+ }
104
+ ctx.diagnostics.push(`${where}: properties has an unrecognized shape; dropped`);
105
+ return undefined;
106
+ }
47
107
  /**
48
108
  * The `elementum_agentic_skill` block + its tool blocks → the normalized
49
109
  * skill. Tool blocks belonging to OTHER skills are skipped with a
@@ -61,12 +121,7 @@ export function skillFromTf(skillBlock, toolBlocks, appLabel, ctx) {
61
121
  for (const key of Object.keys(attrs)) {
62
122
  if (KNOWN_SKILL_ATTRS.has(key))
63
123
  continue;
64
- if (UNAUTHORABLE_SKILL_ATTRS.has(key)) {
65
- ctx.diagnostics.push(`${where}: ${key} has no authoring slot on the terraform path yet; a rebuilt stream will omit it`);
66
- }
67
- else {
68
- ctx.diagnostics.push(`${where}: unhandled attribute "${key}" — the export dialect grew; extend skillFromTf deliberately`);
69
- }
124
+ ctx.diagnostics.push(`${where}: unhandled attribute "${key}" — the export dialect grew; extend skillFromTf deliberately`);
70
125
  }
71
126
  const ownerType = attrs["owner_type"];
72
127
  if (ownerType !== "APP_ASPECT") {
@@ -75,17 +130,9 @@ export function skillFromTf(skillBlock, toolBlocks, appLabel, ctx) {
75
130
  if (resourceRefLabel(attrs["owner_id"], APP_RESOURCE_TYPE) !== appLabel) {
76
131
  return { skippedReason: `${where}: owner_id does not reference ${APP_RESOURCE_TYPE}.${appLabel}; skipped` };
77
132
  }
78
- let properties;
79
- const rawProperties = attrs["properties"];
80
- if (typeof rawProperties === "string" && rawProperties !== "") {
81
- try {
82
- properties = JSON.parse(rawProperties);
83
- }
84
- catch {
85
- ctx.diagnostics.push(`${where}: properties is not valid JSON; dropped`);
86
- }
87
- }
133
+ const properties = propertiesFromTf(attrs["properties"], where, ctx);
88
134
  const status = optionalString(attrs, "status", where, ctx);
135
+ const accessPolicy = skillAccessPolicyFromTf(attrs, ctx);
89
136
  const routingPriority = attrs["routing_priority"];
90
137
  if (routingPriority !== undefined && typeof routingPriority !== "number") {
91
138
  ctx.diagnostics.push(`${where}: routing_priority must be a number; dropped`);
@@ -117,7 +164,7 @@ export function skillFromTf(skillBlock, toolBlocks, appLabel, ctx) {
117
164
  const coverage = analyzeSkillInputCoverage(name, rawInstructions, coverageTools);
118
165
  ctx.reports?.push(...skillCoverageReportLines(coverage));
119
166
  ctx.diagnostics.push(...skillCoverageGapDiagnostics(coverage));
120
- const decomposed = decomposeSkillInstructions(rawInstructions);
167
+ const decomposed = decomposeSkillInstructionsLossless(rawInstructions);
121
168
  const instructions = decomposed.inputs.length > 0 || decomposed.lookups.length > 0
122
169
  ? decomposed.prose
123
170
  : rawInstructions;
@@ -132,6 +179,7 @@ export function skillFromTf(skillBlock, toolBlocks, appLabel, ctx) {
132
179
  ...((status === "ACTIVE" || status === "INACTIVE") && { status }),
133
180
  ...(properties !== undefined && { properties }),
134
181
  ...(Object.keys(discovery).length > 0 && { discovery }),
182
+ ...(accessPolicy !== undefined && { accessPolicy }),
135
183
  tools,
136
184
  },
137
185
  };
@@ -4,5 +4,7 @@
4
4
  * reference position. Standalone from v1.
5
5
  */
6
6
  export { skill, type SkillConfigured, type SkillDiscoveryOptions, type SkillInputSpec, type SkillInputsOption, type SkillLookupSpec, type SkillLookupsOption, type SkillV2Options, } from "./build.js";
7
+ export { type SkillAccessPolicy, type SkillUserRef } from "./access-policy.js";
8
+ export { userRef } from "../role/build.js";
7
9
  export { serviceAccountRef, type AgentToolRunAs, type ServiceAccountRef, } from "../agent/run-as.js";
8
10
  export { skillAutomation, skillCreateRecord, skillRunAgent, skillSearchRecords, skillSearchTable, skillUpdateRecord, type SkillRecordField, type SkillRecordFieldInput, type SkillRecordRawIdField, type SkillSearchField, type SkillSearchFieldInput, type SkillSearchRawIdField, type SkillToolStatus, type SkillTool, } from "./tools.js";
@@ -4,5 +4,6 @@
4
4
  * reference position. Standalone from v1.
5
5
  */
6
6
  export { skill, } from "./build.js";
7
+ export { userRef } from "../role/build.js";
7
8
  export { serviceAccountRef, } from "../agent/run-as.js";
8
9
  export { skillAutomation, skillCreateRecord, skillRunAgent, skillSearchRecords, skillSearchTable, skillUpdateRecord, } from "./tools.js";
@@ -79,6 +79,13 @@ export declare function formatSkillInputSchema(inputs: readonly SkillInputDefini
79
79
  export declare function formatSkillLookupNotes(lookups: readonly SkillLookupDefinition[]): string;
80
80
  export declare function deriveSkillInstructions(baseProse: string | undefined, inputs?: readonly SkillInputDefinition[], lookups?: readonly SkillLookupDefinition[]): string;
81
81
  export declare function decomposeSkillInstructions(markdown: string): DecomposedSkillInstructions;
82
+ /**
83
+ * Decompose instructions for pulled source only when build reproduces them exactly — build re-derives the
84
+ * Input Schema / Lookup Notes sections from structured inputs/lookups, printed only when non-empty. Text the
85
+ * generator would not write back byte for byte (e.g. a hand-written "## Lookup Notes" placeholder) stays verbatim
86
+ * in the prose, so a pull → build round trip never changes the platform's instructions.
87
+ */
88
+ export declare function decomposeSkillInstructionsLossless(markdown: string): DecomposedSkillInstructions;
82
89
  /** Compare instruction-declared form variables with the deployed tool surface. */
83
90
  export declare function analyzeSkillInputCoverage(skill: string, instructions: string, coverageTools: readonly SkillCoverageTool[]): SkillInputCoverageReport;
84
91
  /** Informational coverage lines emitted on stderr and in JSON `reports`. */
@@ -197,6 +197,17 @@ export function decomposeSkillInstructions(markdown) {
197
197
  const prose = proseLines.join("\n").trim();
198
198
  return { prose, inputs, lookups };
199
199
  }
200
+ /**
201
+ * Decompose instructions for pulled source only when build reproduces them exactly — build re-derives the
202
+ * Input Schema / Lookup Notes sections from structured inputs/lookups, printed only when non-empty. Text the
203
+ * generator would not write back byte for byte (e.g. a hand-written "## Lookup Notes" placeholder) stays verbatim
204
+ * in the prose, so a pull → build round trip never changes the platform's instructions.
205
+ */
206
+ export function decomposeSkillInstructionsLossless(markdown) {
207
+ const decomposed = decomposeSkillInstructions(markdown);
208
+ const rebuilt = deriveSkillInstructions(decomposed.prose, decomposed.inputs.length > 0 ? decomposed.inputs : undefined, decomposed.lookups.length > 0 ? decomposed.lookups : undefined);
209
+ return rebuilt === markdown ? decomposed : { prose: markdown, inputs: [], lookups: [] };
210
+ }
200
211
  function mentionsIdentifier(markdown, name) {
201
212
  if (name === "")
202
213
  return false;
@@ -85,6 +85,7 @@ export const skillModule = {
85
85
  refName: skill.refName,
86
86
  source: printSkillV2(skill, {
87
87
  appRefName: opts.appRefName,
88
+ orgImportPath: opts.orgImportPath,
88
89
  ...(opts.crossOrg !== undefined && { crossOrg: opts.crossOrg }),
89
90
  ...(opts.foreignAppRefNames !== undefined && { foreignAppRefNames: opts.foreignAppRefNames }),
90
91
  ...(opts.foreignElementRefNames !== undefined && { foreignElementRefNames: opts.foreignElementRefNames }),
@@ -9,8 +9,8 @@
9
9
  * repo — not `pristine-refactor`'s older, generic single-tool-resource
10
10
  * shape): `owner_id`/`owner_type` as the owning app's resource ref +
11
11
  * `"APP_ASPECT"`, `name`/`description`/`instructions`/`status`/`type`/
12
- * `properties`, plus typed discovery/routing fields. Access policy
13
- * (user_ids/group_ids) is not authored yet.
12
+ * `properties`, typed discovery/routing fields, and portable access-policy
13
+ * user/group references.
14
14
  */
15
15
  import { type OrgRefLookup, type WorkspaceAspect } from "../../engine/build/context.js";
16
16
  import { type DeployableEntity } from "../../engine/entity.js";
@@ -9,8 +9,8 @@
9
9
  * repo — not `pristine-refactor`'s older, generic single-tool-resource
10
10
  * shape): `owner_id`/`owner_type` as the owning app's resource ref +
11
11
  * `"APP_ASPECT"`, `name`/`description`/`instructions`/`status`/`type`/
12
- * `properties`, plus typed discovery/routing fields. Access policy
13
- * (user_ids/group_ids) is not authored yet.
12
+ * `properties`, typed discovery/routing fields, and portable access-policy
13
+ * user/group references.
14
14
  */
15
15
  import { workspaceAspectKey } from "../../engine/build/context.js";
16
16
  import { EntityTfError } from "../../engine/entity.js";
@@ -20,6 +20,7 @@ import { APP_RESOURCE_TYPE } from "../app/module.js";
20
20
  import { SERVICE_ACCOUNT_RESOURCE_TYPE } from "../service-account/module.js";
21
21
  import { analyzeSkillInputCoverage, coverageToolsFromWire, skillCoverageGapDiagnostics, skillCoverageReportLines, } from "./input-coverage.js";
22
22
  import { SKILL_RESOURCE_TYPE } from "./module.js";
23
+ import { skillAccessPolicyToTf } from "./access-policy.js";
23
24
  function serviceAccountValue(name, ctx) {
24
25
  const matches = Object.entries(ctx.serviceAccounts ?? {}).filter(([, account]) => `${account.firstName} ${account.lastName}`.trim() === name);
25
26
  if (matches.length > 1) {
@@ -90,8 +91,17 @@ export function skillToTf(entity, ctx) {
90
91
  type: elementum.type ?? "CUSTOM",
91
92
  };
92
93
  if (elementum.properties !== undefined) {
93
- attrs["properties"] = JSON.stringify(elementum.properties);
94
+ // Same shape ei exports: jsonencode({ ... }) of the JSON object, not a
95
+ // quoted JSON string. A quoted string still applies, but it does not match
96
+ // the export and hides a properties round-trip gap. JSON.stringify drops
97
+ // undefined members the way the previous quoted-JSON path did; leaving
98
+ // them in the object makes render throw.
99
+ // eslint-disable-next-line no-restricted-syntax -- properties is an opaque JSON object, same normalization as from-tf.
100
+ const plain = JSON.parse(JSON.stringify(elementum.properties));
101
+ attrs["properties"] = expr.jsonencode(plain);
94
102
  }
103
+ if (elementum.accessPolicy !== undefined)
104
+ Object.assign(attrs, skillAccessPolicyToTf(elementum.accessPolicy, ctx.orgRefs));
95
105
  const discovery = elementum.discovery;
96
106
  if (discovery?.routingPriority !== undefined)
97
107
  attrs["routing_priority"] = discovery.routingPriority;
@@ -116,14 +126,17 @@ export function skillToTf(entity, ctx) {
116
126
  foreignAppRef: (l, n, ns) => ctx.orgRefs.foreignApp(l, n, ns),
117
127
  foreignElementRef: (l, n, ns) => ctx.orgRefs.foreignElement(l, n, ns),
118
128
  foreignTaskRef: (l, n) => ctx.orgRefs.rawLookup("elementum_task", l, n),
119
- foreignFieldRef: (t, l, o, n) => ctx.orgRefs.foreignField(t, l, o, n),
129
+ foreignFieldRef: (t, l, o, n, extra) => ctx.orgRefs.foreignField(t, l, o, n, extra),
120
130
  workspaceAspects: ctx.workspaceAspects,
121
131
  serviceAccountRef: (_label, serviceAccountName) => serviceAccountValue(serviceAccountName, ctx),
122
- tableSearchTableRef: (label, tableRefName, tableName, searchTableName) => {
132
+ tableSearchTableRef: (label, tableRefName, tableName, searchTableName, searchTableId) => {
123
133
  const tableLabel = sanitizeName(tableRefName);
124
134
  const tableId = expr.dataAttr("elementum_table", tableLabel, ["id"]);
125
135
  ctx.orgRefs.rawLookup("elementum_table", tableLabel, tableName);
126
- ctx.orgRefs.rawLookup("elementum_search_table", label, searchTableName, { table_id: tableId });
136
+ ctx.orgRefs.rawLookup("elementum_search_table", label, searchTableName, {
137
+ table_id: tableId,
138
+ ...(searchTableId !== undefined && searchTableId !== "" ? { id: searchTableId } : {}),
139
+ });
127
140
  return expr.dataAttr("elementum_search_table", label, ["id"]);
128
141
  },
129
142
  foreignAutomationRef: (tfLabel, parentKind, _parentRefName, parentName, automationName) => {
@@ -94,6 +94,8 @@ export interface NormalizedSkillTool {
94
94
  readonly searchTableKey?: string;
95
95
  /** Foreign table lookup name when search_table_id is data.elementum_search_table. */
96
96
  readonly searchTableName?: string;
97
+ /** Pinned search-table id when the data source names more than one row. */
98
+ readonly searchTableId?: string;
97
99
  /** Display name of the owning organization table for a table-owned search table. */
98
100
  readonly searchTableOwnerName?: string;
99
101
  /** Canonical catalog refName of the owning organization table, when known. */
@@ -217,6 +217,7 @@ export function skillToolFromTf(block, owner, ctx) {
217
217
  }
218
218
  let searchTableKey;
219
219
  let searchTableName;
220
+ let searchTableId;
220
221
  let tableOwnedSearchTable = false;
221
222
  let searchTableOwnerName;
222
223
  let searchTableOwnerRefName;
@@ -240,11 +241,15 @@ export function skillToolFromTf(block, owner, ctx) {
240
241
  }
241
242
  else if (isTfExpr(value) && value.$expr === "data-attr" && value.type === "elementum_search_table") {
242
243
  searchTableName = ctx.dataName(value.type, value.label);
244
+ const dataAttrs = ctx.dataAttrs?.(value.type, value.label);
245
+ const pinnedId = dataAttrs?.["id"];
246
+ if (typeof pinnedId === "string" && pinnedId !== "")
247
+ searchTableId = pinnedId;
243
248
  // The generic search-table data source is used for both aspect-owned and
244
249
  // table-owned tables. The presence of table_id is the only portable
245
250
  // discriminator available in the HCL stream.
246
- tableOwnedSearchTable = ctx.dataAttrs?.(value.type, value.label)?.["table_id"] !== undefined;
247
- const tableLabel = dataRefLabel(ctx.dataAttrs?.(value.type, value.label)?.["table_id"], "elementum_table");
251
+ tableOwnedSearchTable = dataAttrs?.["table_id"] !== undefined;
252
+ const tableLabel = dataRefLabel(dataAttrs?.["table_id"], "elementum_table");
248
253
  if (tableLabel !== undefined) {
249
254
  searchTableOwnerName = ctx.dataName("elementum_table", tableLabel);
250
255
  if (searchTableOwnerName !== undefined) {
@@ -445,6 +450,7 @@ export function skillToolFromTf(block, owner, ctx) {
445
450
  }),
446
451
  ...(searchTableKey !== undefined && { searchTableKey }),
447
452
  ...(searchTableName !== undefined && { searchTableName }),
453
+ ...(searchTableId !== undefined && { searchTableId }),
448
454
  ...(searchTableOwnerName !== undefined && { searchTableOwnerName }),
449
455
  ...(searchTableOwnerRefName !== undefined && { searchTableOwnerRefName }),
450
456
  ...(searchTableRawId !== undefined && { searchTableRawId }),
@@ -29,13 +29,13 @@ export interface SkillToolToTfContext {
29
29
  /** Records a foreign-TASK data lookup for data.tf. */
30
30
  foreignTaskRef?(tfLabel: string, name: string, namespace?: string): void;
31
31
  /** Records an object-scoped data lookup owned by a foreign app/element. */
32
- foreignFieldRef(type: string, tfLabel: string, objectId: TfValue, name: string): void;
32
+ foreignFieldRef(type: string, tfLabel: string, objectId: TfValue, name: string, extraAttrs?: Readonly<Record<string, TfValue>>): void;
33
33
  /** App/element roots authored in this same workspace. */
34
34
  readonly workspaceAspects?: ReadonlyMap<string, WorkspaceAspect>;
35
35
  /** Records an app-scoped service-account lookup by name. */
36
36
  serviceAccountRef?(tfLabel: string, name: string): TfValue | void;
37
37
  /** Records a table-owned search-table data lookup for a pulled public ref. */
38
- tableSearchTableRef?(tfLabel: string, tableRefName: string, tableName: string, searchTableName: string): TfValue | void;
38
+ tableSearchTableRef?(tfLabel: string, tableRefName: string, tableName: string, searchTableName: string, searchTableId?: string): TfValue | void;
39
39
  /**
40
40
  * Records a cross-app/element automation data lookup (a `runAutomation`
41
41
  * skill/agent tool targeting an automation this workspace doesn't own),
@@ -8,8 +8,9 @@
8
8
  */
9
9
  import { workspaceAspectKey } from "../../engine/build/context.js";
10
10
  import { automationRunTargetResourceAttr } from "../automation/to-tf.js";
11
- import { appScopedResourceLabel, childPartFromScopedLabel, expr, sanitizeName, scopedResourceLabel, tsLabelToTfLabel } from "../../engine/tf/index.js";
12
- import { fieldRefToTfValue } from "../field/to-tf.js";
11
+ import { appScopedResourceLabel, childPartFromScopedLabel, expr, sanitizeName, scopedResourceLabel, stableIdSuffix, tsLabelToTfLabel } from "../../engine/tf/index.js";
12
+ import { authoredFieldKeysFromPayload, fieldRefToTfValue, } from "../field/to-tf.js";
13
+ import { foreignFieldDataLabel } from "../shared/foreign-ref.js";
13
14
  import { encodeOptionalHandleDescription } from "../shared/handle-description.js";
14
15
  import { SKILL_TOOL_SUB_TYPE_BY_TYPE_KEY } from "./types.js";
15
16
  function serviceAccountIdValue(token, where, ctx) {
@@ -62,6 +63,7 @@ function targetIdValue(token, ctx) {
62
63
  refName,
63
64
  kind,
64
65
  localTfLabel: sibling.tfLabel,
66
+ fieldOwnership: authoredFieldKeysFromPayload(sibling.streamRootEntity?.payload),
65
67
  };
66
68
  }
67
69
  const name = token.name ?? refName;
@@ -103,7 +105,7 @@ function targetIdValue(token, ctx) {
103
105
  function foreignTargetFieldRefValue(token, refName, target, ctx) {
104
106
  const fieldName = token.name ?? refName;
105
107
  const ownerLabel = target.foreignTfLabel ?? sanitizeName(target.refName);
106
- const fieldLabel = `${target.kind}_${ownerLabel}_${tsLabelToTfLabel(refName)}`;
108
+ const fieldLabel = foreignFieldDataLabel(target.kind, ownerLabel, fieldName);
107
109
  ctx.foreignFieldRef("elementum_field", fieldLabel, target.value, fieldName);
108
110
  return expr.dataAttr("elementum_field", fieldLabel, ["id"]);
109
111
  }
@@ -130,7 +132,7 @@ function fieldRefValue(token, where, ctx, target) {
130
132
  const authoringType = token.fieldType ?? "";
131
133
  const ref = refName === ""
132
134
  ? undefined
133
- : fieldRefToTfValue(authoringType, refName, target.localTfLabel, target.kind);
135
+ : fieldRefToTfValue(authoringType, refName, target.localTfLabel, target.kind, target.fieldOwnership);
134
136
  if (ref === undefined) {
135
137
  ctx.diagnostics.push(`${where}: field token "${refName}" has no terraform field resource mapping (fieldType ${JSON.stringify(authoringType)}); dropped`);
136
138
  return undefined;
@@ -278,6 +280,7 @@ export function skillToolToTf(entry, ctx) {
278
280
  attrs["target_id"] = "";
279
281
  if (typeKey === "searchTable") {
280
282
  const table = inner.searchTableId;
283
+ const pinnedSearchTableId = typeof table?.id === "string" && table.id !== "" ? table.id : undefined;
281
284
  // The search table itself (not its owner - that's the __variant/parent
282
285
  // fallback below) has no portable lookup at all: unsafePlatformId()
283
286
  // round-trips it as a raw id directly, before the refName check below,
@@ -309,11 +312,25 @@ export function skillToolToTf(entry, ctx) {
309
312
  const workspaceTable = table.parent === undefined
310
313
  ? undefined
311
314
  : ctx.workspaceAspects?.get(workspaceAspectKey("table", table.parent));
312
- if (workspaceTable !== undefined) {
315
+ const searchName = table.name ?? table.refName;
316
+ const tableLookupLabel = `${sanitizeName(table.parent ?? "")}_${sanitizeName(searchName)}`;
317
+ const tableLookup = pinnedSearchTableId === undefined
318
+ ? tableLookupLabel
319
+ : `${tableLookupLabel}_${stableIdSuffix(pinnedSearchTableId)}`;
320
+ if (pinnedSearchTableId !== undefined && ctx.tableSearchTableRef !== undefined && table.parent !== undefined && table.parent !== "") {
321
+ const lookup = ctx.tableSearchTableRef(tableLookup, table.parent, table.parentName ?? table.parent, searchName, pinnedSearchTableId);
322
+ if (lookup !== undefined)
323
+ attrs["search_table_id"] = lookup;
324
+ else {
325
+ ctx.diagnostics.push(`${where}: table-owned search table lookup could not be materialized; dropped`);
326
+ return undefined;
327
+ }
328
+ }
329
+ else if (workspaceTable !== undefined) {
313
330
  attrs["search_table_id"] = expr.resourceAttr("elementum_table_search_table", `tables_${workspaceTable.tfLabel}_${tsLabelToTfLabel(table.refName)}`, ["id"]);
314
331
  }
315
332
  else if (ctx.tableSearchTableRef !== undefined && table.parent !== undefined && table.parent !== "") {
316
- const lookup = ctx.tableSearchTableRef(`${sanitizeName(table.parent)}_${sanitizeName(table.name ?? table.refName)}`, table.parent, table.parentName ?? table.parent, table.name ?? table.refName);
333
+ const lookup = ctx.tableSearchTableRef(tableLookup, table.parent, table.parentName ?? table.parent, searchName);
317
334
  if (lookup !== undefined)
318
335
  attrs["search_table_id"] = lookup;
319
336
  else {
@@ -329,6 +346,12 @@ export function skillToolToTf(entry, ctx) {
329
346
  return undefined;
330
347
  }
331
348
  }
349
+ else if (pinnedSearchTableId !== undefined) {
350
+ const ownerPart = target.localTfLabel ?? target.foreignTfLabel ?? sanitizeName(target.refName);
351
+ const lookupLabel = `${sanitizeName(`${ownerPart}_${table.name ?? table.refName}`)}_${stableIdSuffix(pinnedSearchTableId)}`;
352
+ ctx.foreignFieldRef("elementum_search_table", lookupLabel, target.value, table.name ?? table.refName, { id: pinnedSearchTableId });
353
+ attrs["search_table_id"] = expr.dataAttr("elementum_search_table", lookupLabel, ["id"]);
354
+ }
332
355
  else if (target.localTfLabel === undefined) {
333
356
  const targetName = aspectId?.name ?? aspectId?.refName ?? table.parent;
334
357
  const lookupLabel = sanitizeName(`${targetName}_${table.name ?? table.refName}`);
@@ -0,0 +1,14 @@
1
+ import type { TableColumnStateV2 } from "./state.js";
2
+ export interface TableCatalogInput {
3
+ readonly handle: string;
4
+ readonly name: string;
5
+ readonly categoryId?: string;
6
+ readonly tableColumns?: Record<string, TableColumnStateV2>;
7
+ readonly datamines?: Record<string, {
8
+ readonly name: string;
9
+ }>;
10
+ }
11
+ export declare function renderTableCatalog(table: TableCatalogInput): string;
12
+ export declare function writeTableCatalog(orgRoot: string, table: TableCatalogInput): Promise<{
13
+ catalogPath: string;
14
+ }>;
@@ -0,0 +1,66 @@
1
+ import { mkdir, writeFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { sdkPackageSpecifier } from "../../internal/sdk-package.js";
4
+ const RESERVED_IDENT = new Set([
5
+ "break", "case", "catch", "class", "const", "continue", "debugger", "default",
6
+ "delete", "do", "else", "export", "extends", "false", "finally", "for",
7
+ "function", "if", "import", "in", "instanceof", "new", "null", "return",
8
+ "super", "switch", "this", "throw", "true", "try", "typeof", "var", "void",
9
+ "while", "with", "let", "static", "yield", "enum",
10
+ ]);
11
+ function q(value) {
12
+ return JSON.stringify(value);
13
+ }
14
+ function safeKey(name) {
15
+ return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name) && !RESERVED_IDENT.has(name)
16
+ ? name
17
+ : q(name);
18
+ }
19
+ export function renderTableCatalog(table) {
20
+ const lines = [];
21
+ lines.push(`import { datamineRef, tableColumnRef, tableRef } from "${sdkPackageSpecifier("catalog")}";`);
22
+ lines.push("");
23
+ lines.push("export const table = tableRef({");
24
+ // This catalog is imported directly by generated/catalog.ts, so there is no
25
+ // enclosing `orgCatalog({ tables: ... })` call to stamp the bag key later.
26
+ lines.push(` refName: ${q(table.handle)},`);
27
+ lines.push(` name: ${q(table.name)},`);
28
+ const columns = Object.entries(table.tableColumns ?? {}).sort(([a], [b]) => a.localeCompare(b));
29
+ if (columns.length > 0) {
30
+ lines.push(" columns: {");
31
+ for (const [key, col] of columns) {
32
+ // `parent` is stamped explicitly here (rather than left for a downstream
33
+ // barrel to fix up) so this per-table catalog file is correct even if
34
+ // something imports it directly instead of through the org catalog.
35
+ const parts = [`name: ${q(col.name)}`, `parent: ${q(table.handle)}`, `parentName: ${q(table.name)}`];
36
+ if (col.fieldType !== undefined)
37
+ parts.push(`fieldType: ${q(col.fieldType)}`);
38
+ if (col.tags !== undefined)
39
+ parts.push(`tags: ${JSON.stringify(col.tags)}`);
40
+ lines.push(` ${safeKey(key)}: tableColumnRef({ ${parts.join(", ")} }),`);
41
+ }
42
+ lines.push(" },");
43
+ }
44
+ const datamines = Object.entries(table.datamines ?? {}).sort(([a], [b]) => a.localeCompare(b));
45
+ if (datamines.length > 0) {
46
+ lines.push(" datamines: {");
47
+ for (const [key, datamine] of datamines) {
48
+ lines.push(` ${safeKey(key)}: datamineRef({ name: ${q(datamine.name)}, parent: ${q(table.handle)}, parentName: ${q(table.name)} }),`);
49
+ }
50
+ lines.push(" },");
51
+ }
52
+ if (table.categoryId !== undefined)
53
+ lines.push(` categoryId: ${q(table.categoryId)},`);
54
+ lines.push("});");
55
+ lines.push("");
56
+ lines.push("export default table;");
57
+ lines.push("");
58
+ return lines.join("\n");
59
+ }
60
+ export async function writeTableCatalog(orgRoot, table) {
61
+ const generatedDir = join(orgRoot, "tables", table.handle, "generated");
62
+ const catalogPath = join(generatedDir, "catalog.ts");
63
+ await mkdir(generatedDir, { recursive: true });
64
+ await writeFile(catalogPath, renderTableCatalog(table), "utf8");
65
+ return { catalogPath };
66
+ }
@@ -13,7 +13,8 @@ export const tableModule = {
13
13
  stream: { role: "streamRoot", exportVerb: "tables" },
14
14
  authoring: { unit: "ownFile", bag: "tables" },
15
15
  parents: [{ parent: "org", child: "table" }],
16
- resource: { shape: "single", resourceType: TABLE_RESOURCE_TYPE, adoptable: true },
16
+ // The platform's Table type has no description, icon or color to read back.
17
+ resource: { shape: "single", resourceType: TABLE_RESOURCE_TYPE, adoptable: true, unreadableAttributes: ["description", "icon", "color"] },
17
18
  // Cross-table relationships already emit name-keyed data lookups through
18
19
  // OrgRefLookup.rawLookup; register that real build surface in the graph.
19
20
  data: { participates: true, resourceType: "elementum_table", lookupAttr: "name", referencedByBuild: true, referenceLookups: [{ strategy: "rootName" }] },
@@ -5,8 +5,8 @@ import { CATEGORY_ORG_BAG } from "../org/category.js";
5
5
  import { categoryIdExpr, missingCategoryDiagnostic } from "../org/category-ref.js";
6
6
  import { CLOUD_LINK_ORG_BAG } from "../org/cloud-link.js";
7
7
  import { tableDataminesToTf, } from "../datamine/to-tf.js";
8
- import { fieldRefToTfValue } from "../field/to-tf.js";
9
- import { resolveForeignRef } from "../shared/foreign-ref.js";
8
+ import { authoredFieldKeysFromPayload, fieldRefToTfValue } from "../field/to-tf.js";
9
+ import { foreignFieldDataLabel, resolveForeignRef } from "../shared/foreign-ref.js";
10
10
  import { filterToTf as serializeFilterToTf } from "../shared/filters/tf-codec.js";
11
11
  import { TABLE_RESOURCE_TYPE } from "./module.js";
12
12
  function tableColumnName(column) {
@@ -91,13 +91,13 @@ function fieldId(value, orgRefs, ownRef, ownLabel, ownColumnNames, workspaceAspe
91
91
  if (local !== undefined &&
92
92
  ref.fieldType !== undefined &&
93
93
  ref.refName !== undefined) {
94
- const resolved = fieldRefToTfValue(ref.fieldType, ref.refName, local.tfLabel, kind);
94
+ const resolved = fieldRefToTfValue(ref.fieldType, ref.refName, local.tfLabel, kind, authoredFieldKeysFromPayload(local.streamRootEntity?.payload));
95
95
  if (resolved !== undefined)
96
96
  return resolved;
97
97
  }
98
98
  const parentName = ref.parentName ?? parent;
99
- const owner = resolveForeignRef(kind, { name: parentName }, orgRefs, diagnostics, "table field owner");
100
- const label = sanitizeName(`${parent}_${ref.refName ?? ref.name ?? "field"}`);
99
+ const owner = resolveForeignRef(kind, { name: parentName, namespace: ref.parentNamespace }, orgRefs, diagnostics, "table field owner");
100
+ const label = foreignFieldDataLabel(kind, owner.tfLabel, ref.name ?? ref.refName ?? "field");
101
101
  orgRefs.foreignField("elementum_field", label, owner.value, ref.name ?? ref.refName ?? "");
102
102
  return expr.dataAttr("elementum_field", label, ["id"]);
103
103
  }
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Pull: blocks layouts → normalized values the printer turns back into source.
3
+ * `elementum_agent_view.layout` → `agentViews.<key>.layout`;
4
+ * `elementum_custom_view.layout` → `customViews.<key>.layout` (see
5
+ * `viewBlocksFromTf`). References become typed markers at the per-block id
6
+ * positions, inside nested filters and inside actions; raw platform ids there
7
+ * become `unsafePlatformId(...)`. A layout this cannot represent makes the
8
+ * whole view unmanaged (skipped), never silently dropped: the code owns the
9
+ * layout, so a dropped detail would be cleared on the next apply.
10
+ */
11
+ import { type TfValue } from "../../engine/tf/index.js";
12
+ /** Another app or element a pulled blocks layout references, by its pulled catalog identity. */
13
+ export interface ViewBlocksSourceMarker {
14
+ readonly __specRef: "source";
15
+ readonly kind: "app" | "element";
16
+ readonly key: string;
17
+ readonly name: string;
18
+ readonly namespace?: string;
19
+ }
20
+ /** A field of another app or element a pulled blocks layout references. */
21
+ export interface ViewBlocksForeignFieldMarker {
22
+ readonly __specRef: "foreignField";
23
+ readonly key: string;
24
+ readonly name: string;
25
+ readonly fieldType: string;
26
+ readonly parent: string;
27
+ readonly parentKind: "app" | "element";
28
+ readonly parentName: string;
29
+ readonly parentNamespace?: string;
30
+ }
31
+ /**
32
+ * A typed reference inside a pulled blocks layout. `app` is the view's owner
33
+ * (an app or an element) and `field` one of its fields; `source` and
34
+ * `foreignField` are other apps and elements and their fields.
35
+ */
36
+ export type AgentViewSpecMarker = {
37
+ readonly __specRef: "app";
38
+ } | {
39
+ readonly __specRef: "field";
40
+ readonly key: string;
41
+ } | ViewBlocksSourceMarker | ViewBlocksForeignFieldMarker | {
42
+ readonly __specRef: "unsafe";
43
+ readonly id: string;
44
+ };
45
+ export interface NormalizedAgentViewLayout {
46
+ readonly image?: {
47
+ readonly attachment: string;
48
+ } | {
49
+ readonly url: string;
50
+ };
51
+ readonly header?: string;
52
+ readonly subHeader?: string;
53
+ readonly backgroundColor?: string;
54
+ readonly primaryColor?: string;
55
+ readonly fontFamily?: string;
56
+ /** Plain JSON with `AgentViewSpecMarker` objects at reference positions. */
57
+ readonly customView?: unknown;
58
+ }
59
+ export interface AgentViewLayoutFromTfOptions {
60
+ /** True when the value references the view's owner (`elementum_app.<owner>.id` or `elementum_element.<owner>.id`). */
61
+ readonly isOwnApp: (value: TfValue) => boolean;
62
+ /** Resolves a field reference to its bag key, a system field key, or a raw id. */
63
+ readonly fieldKey: (value: TfValue) => string | undefined;
64
+ /** Resolves another app's or element's data lookup. */
65
+ readonly foreignSource?: (value: TfValue) => ViewBlocksSourceMarker | undefined;
66
+ /** Resolves the data lookup of another app's or element's field. */
67
+ readonly foreignField?: (value: TfValue) => ViewBlocksForeignFieldMarker | undefined;
68
+ }
69
+ export type AgentViewLayoutFromTfResult = {
70
+ readonly ok: true;
71
+ readonly layout: NormalizedAgentViewLayout;
72
+ } | {
73
+ readonly ok: false;
74
+ readonly reason: string;
75
+ };
76
+ export declare function agentViewLayoutFromTf(value: TfValue, opts: AgentViewLayoutFromTfOptions): AgentViewLayoutFromTfResult;
77
+ export type ViewBlocksFromTfResult = {
78
+ readonly ok: true;
79
+ readonly layout: unknown;
80
+ } | {
81
+ readonly ok: false;
82
+ readonly reason: string;
83
+ };
84
+ /** A blocks layout (the value inside `jsonencode(...)`) → plain JSON with `AgentViewSpecMarker` objects at reference positions. */
85
+ export declare function viewBlocksFromTf(value: TfValue, opts: AgentViewLayoutFromTfOptions): ViewBlocksFromTfResult;
86
+ /** Own-app field bag keys a pulled layout references (for hoisting their consts). */
87
+ export declare function collectAgentViewLayoutFieldKeys(layout: NormalizedAgentViewLayout | undefined): string[];
88
+ /** Own field bag keys a pulled blocks layout references (for hoisting their consts). */
89
+ export declare function collectViewBlocksFieldKeys(layout: unknown): string[];