@elementumai/edk 0.9.19 → 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 (176) hide show
  1. package/README.md +146 -6
  2. package/dist-sdk/src/catalog/factories.d.ts +24 -1
  3. package/dist-sdk/src/catalog/factories.js +30 -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/render.js +6 -6
  9. package/dist-sdk/src/catalog/token.js +7 -0
  10. package/dist-sdk/src/catalog/types.d.ts +34 -1
  11. package/dist-sdk/src/catalog/types.js +11 -0
  12. package/dist-sdk/src/core/triggers/on-demand.d.ts +39 -3
  13. package/dist-sdk/src/core/triggers/on-demand.js +10 -2
  14. package/dist-sdk/src/engine/build/context.d.ts +1 -1
  15. package/dist-sdk/src/engine/ei/run.d.ts +149 -0
  16. package/dist-sdk/src/engine/ei/run.js +1132 -0
  17. package/dist-sdk/src/engine/logging.d.ts +17 -0
  18. package/dist-sdk/src/engine/logging.js +18 -0
  19. package/dist-sdk/src/engine/pull/ref-only.d.ts +5 -0
  20. package/dist-sdk/src/engine/pull/ref-only.js +10 -7
  21. package/dist-sdk/src/engine/pull/result-output.d.ts +6 -0
  22. package/dist-sdk/src/engine/pull/result-output.js +87 -3
  23. package/dist-sdk/src/engine/tf/expr.js +1 -1
  24. package/dist-sdk/src/engine/tf/index.d.ts +2 -2
  25. package/dist-sdk/src/engine/tf/index.js +1 -1
  26. package/dist-sdk/src/engine/tf/labels.d.ts +6 -0
  27. package/dist-sdk/src/engine/tf/labels.js +9 -0
  28. package/dist-sdk/src/engine/tf/model.d.ts +22 -1
  29. package/dist-sdk/src/engine/tf/parse.js +92 -4
  30. package/dist-sdk/src/engine/tf/render.d.ts +4 -2
  31. package/dist-sdk/src/engine/tf/render.js +41 -7
  32. package/dist-sdk/src/engine/validation.d.ts +39 -0
  33. package/dist-sdk/src/engine/validation.js +85 -0
  34. package/dist-sdk/src/entities/access-policy/to-tf.js +5 -2
  35. package/dist-sdk/src/entities/agent/build.d.ts +4 -16
  36. package/dist-sdk/src/entities/agent/build.js +40 -5
  37. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +4 -2
  38. package/dist-sdk/src/entities/agent/to-tf.js +6 -3
  39. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +2 -0
  40. package/dist-sdk/src/entities/agent-tool/from-tf.js +7 -1
  41. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
  42. package/dist-sdk/src/entities/agent-tool/to-tf.js +27 -5
  43. package/dist-sdk/src/entities/app/build.d.ts +89 -20
  44. package/dist-sdk/src/entities/app/build.js +51 -6
  45. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +16 -0
  46. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -0
  47. package/dist-sdk/src/entities/app/from-tf.js +7 -2
  48. package/dist-sdk/src/entities/app/index.d.ts +6 -6
  49. package/dist-sdk/src/entities/app/index.js +1 -0
  50. package/dist-sdk/src/entities/app/module.js +5 -2
  51. package/dist-sdk/src/entities/app/to-tf.js +19 -11
  52. package/dist-sdk/src/entities/automation/build.d.ts +47 -5
  53. package/dist-sdk/src/entities/automation/build.js +137 -20
  54. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +24 -1
  55. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +314 -39
  56. package/dist-sdk/src/entities/automation/from-tf.d.ts +28 -6
  57. package/dist-sdk/src/entities/automation/from-tf.js +428 -48
  58. package/dist-sdk/src/entities/automation/generated/task-output-contracts.d.ts +33 -0
  59. package/dist-sdk/src/entities/automation/generated/task-output-contracts.js +183 -0
  60. package/dist-sdk/src/entities/automation/index.d.ts +2 -2
  61. package/dist-sdk/src/entities/automation/index.js +1 -1
  62. package/dist-sdk/src/entities/automation/module.js +37 -8
  63. package/dist-sdk/src/entities/automation/output-field-types.d.ts +7 -0
  64. package/dist-sdk/src/entities/automation/output-field-types.js +36 -0
  65. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +9 -0
  66. package/dist-sdk/src/entities/automation/output-key-wire-name.js +13 -0
  67. package/dist-sdk/src/entities/automation/script-code.d.ts +17 -0
  68. package/dist-sdk/src/entities/automation/script-code.js +91 -5
  69. package/dist-sdk/src/entities/automation/system-ref-name.js +4 -0
  70. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +2 -0
  71. package/dist-sdk/src/entities/automation/task-output-labels.js +9 -0
  72. package/dist-sdk/src/entities/automation/tasks.d.ts +24 -2
  73. package/dist-sdk/src/entities/automation/tasks.js +38 -9
  74. package/dist-sdk/src/entities/automation/to-tf.d.ts +4 -0
  75. package/dist-sdk/src/entities/automation/to-tf.js +489 -83
  76. package/dist-sdk/src/entities/automation/triggers.d.ts +4 -2
  77. package/dist-sdk/src/entities/automation/triggers.js +4 -0
  78. package/dist-sdk/src/entities/chart/to-tf.js +10 -3
  79. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +24 -31
  80. package/dist-sdk/src/entities/element/build.d.ts +25 -13
  81. package/dist-sdk/src/entities/element/build.js +4 -1
  82. package/dist-sdk/src/entities/element/from-tf.d.ts +11 -0
  83. package/dist-sdk/src/entities/element/from-tf.js +58 -1
  84. package/dist-sdk/src/entities/element/index.d.ts +5 -3
  85. package/dist-sdk/src/entities/element/index.js +1 -0
  86. package/dist-sdk/src/entities/element/module.js +9 -3
  87. package/dist-sdk/src/entities/element/to-tf.js +8 -2
  88. package/dist-sdk/src/entities/field/build.d.ts +14 -1
  89. package/dist-sdk/src/entities/field/build.js +3 -0
  90. package/dist-sdk/src/entities/field/from-tf.d.ts +1 -0
  91. package/dist-sdk/src/entities/field/from-tf.js +39 -1
  92. package/dist-sdk/src/entities/field/media-types.d.ts +6 -0
  93. package/dist-sdk/src/entities/field/media-types.js +30 -0
  94. package/dist-sdk/src/entities/field/module.js +1 -0
  95. package/dist-sdk/src/entities/field/to-tf.d.ts +23 -2
  96. package/dist-sdk/src/entities/field/to-tf.js +130 -14
  97. package/dist-sdk/src/entities/file-reader/from-tf.js +14 -5
  98. package/dist-sdk/src/entities/file-reader/module.js +1 -0
  99. package/dist-sdk/src/entities/file-reader/types.d.ts +2 -0
  100. package/dist-sdk/src/entities/file-reader/types.js +1 -1
  101. package/dist-sdk/src/entities/portal/build.d.ts +26 -0
  102. package/dist-sdk/src/entities/portal/build.js +37 -0
  103. package/dist-sdk/src/entities/portal/from-tf.d.ts +27 -0
  104. package/dist-sdk/src/entities/portal/from-tf.js +75 -0
  105. package/dist-sdk/src/entities/portal/index.d.ts +1 -0
  106. package/dist-sdk/src/entities/portal/index.js +1 -0
  107. package/dist-sdk/src/entities/portal/module.d.ts +3 -0
  108. package/dist-sdk/src/entities/portal/module.js +28 -0
  109. package/dist-sdk/src/entities/portal/to-tf.d.ts +12 -0
  110. package/dist-sdk/src/entities/portal/to-tf.js +73 -0
  111. package/dist-sdk/src/entities/portal/types.d.ts +1 -0
  112. package/dist-sdk/src/entities/portal/types.js +1 -0
  113. package/dist-sdk/src/entities/relationship/module.js +2 -0
  114. package/dist-sdk/src/entities/relationship/pair-check.d.ts +7 -0
  115. package/dist-sdk/src/entities/relationship/pair-check.js +68 -0
  116. package/dist-sdk/src/entities/relationship/to-tf.d.ts +2 -0
  117. package/dist-sdk/src/entities/relationship/to-tf.js +12 -3
  118. package/dist-sdk/src/entities/search-table/module.js +1 -0
  119. package/dist-sdk/src/entities/search-table/to-tf.d.ts +1 -0
  120. package/dist-sdk/src/entities/search-table/to-tf.js +1 -1
  121. package/dist-sdk/src/entities/service-account/build.d.ts +15 -2
  122. package/dist-sdk/src/entities/service-account/from-tf.d.ts +2 -4
  123. package/dist-sdk/src/entities/service-account/from-tf.js +17 -5
  124. package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +56 -0
  125. package/dist-sdk/src/entities/service-account/role-fidelity.js +243 -0
  126. package/dist-sdk/src/entities/service-account/to-tf.d.ts +14 -0
  127. package/dist-sdk/src/entities/service-account/to-tf.js +17 -0
  128. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +1 -1
  129. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +5 -2
  130. package/dist-sdk/src/entities/shared/filters/ast.d.ts +8 -0
  131. package/dist-sdk/src/entities/shared/filters/index.d.ts +2 -0
  132. package/dist-sdk/src/entities/shared/filters/index.js +14 -4
  133. package/dist-sdk/src/entities/shared/filters/print.js +17 -1
  134. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +2 -0
  135. package/dist-sdk/src/entities/shared/filters/tf-codec.js +5 -1
  136. package/dist-sdk/src/entities/shared/filters/types.d.ts +9 -1
  137. package/dist-sdk/src/entities/shared/types/field-types.d.ts +10 -5
  138. package/dist-sdk/src/entities/shared/types/field-types.js +4 -0
  139. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +2 -1
  140. package/dist-sdk/src/entities/skill/from-tf.js +66 -13
  141. package/dist-sdk/src/entities/skill/input-coverage.d.ts +7 -0
  142. package/dist-sdk/src/entities/skill/input-coverage.js +11 -0
  143. package/dist-sdk/src/entities/skill/to-tf.js +14 -4
  144. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
  145. package/dist-sdk/src/entities/skill-tool/from-tf.js +8 -2
  146. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +2 -2
  147. package/dist-sdk/src/entities/skill-tool/to-tf.js +27 -5
  148. package/dist-sdk/src/entities/table/catalog.d.ts +14 -0
  149. package/dist-sdk/src/entities/table/catalog.js +66 -0
  150. package/dist-sdk/src/entities/table/module.js +2 -1
  151. package/dist-sdk/src/entities/table/to-tf.js +2 -2
  152. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +49 -9
  153. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +71 -18
  154. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +19 -4
  155. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +82 -10
  156. package/dist-sdk/src/entities/view/agent-view-layout.d.ts +53 -23
  157. package/dist-sdk/src/entities/view/agent-view-layout.js +1 -1
  158. package/dist-sdk/src/entities/view/from-tf.d.ts +3 -2
  159. package/dist-sdk/src/entities/view/from-tf.js +124 -12
  160. package/dist-sdk/src/entities/view/module.js +30 -3
  161. package/dist-sdk/src/entities/view/to-tf.d.ts +14 -1
  162. package/dist-sdk/src/entities/view/to-tf.js +67 -10
  163. package/dist-sdk/src/entities/view/types.d.ts +4 -15
  164. package/dist-sdk/src/entities/view/types.js +15 -15
  165. package/dist-sdk/src/entities/widget/build.d.ts +16 -1
  166. package/dist-sdk/src/entities/widget/build.js +11 -1
  167. package/dist-sdk/src/entities/widget/to-tf.js +34 -8
  168. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +16 -5
  169. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  170. package/dist-sdk/src/graph/index.d.ts +11 -0
  171. package/dist-sdk/src/graph/index.js +21 -0
  172. package/dist-sdk/src/graph/modules.js +2 -0
  173. package/dist-sdk/src/graph/types.d.ts +55 -2
  174. package/dist-sdk/src/internal/sdk-package.d.ts +1 -1
  175. package/dist-sdk/src/internal/sdk-package.js +1 -0
  176. package/package.json +10 -1
@@ -67,6 +67,23 @@ export interface BridgeLogEvent {
67
67
  readonly message: string;
68
68
  readonly text_effects?: readonly TextEffect[];
69
69
  }
70
+ /**
71
+ * A GraphQL error the bridge read alongside query data: the field at `path` was
72
+ * not read (docs/design/graphql-error-standard.md).
73
+ */
74
+ export interface PartialReadEvent {
75
+ readonly protocol_version: number;
76
+ readonly sequence: number;
77
+ readonly timestamp: string;
78
+ readonly event: "partial_read";
79
+ readonly operation: string;
80
+ readonly path: readonly (string | number)[];
81
+ readonly code?: string;
82
+ readonly message: string;
83
+ readonly category: "source" | "platform";
84
+ readonly guidance: string;
85
+ }
86
+ export declare function parsePartialReadEvent(line: string): PartialReadEvent | undefined;
70
87
  export declare function parseProgressEvent(line: string): ProgressEvent | undefined;
71
88
  export declare function parseBridgeLogEvent(line: string): BridgeLogEvent | undefined;
72
89
  /** Convert common JS camelCase keys to the contract's flat snake_case keys. */
@@ -7,6 +7,24 @@ export const LOG_LEVELS = ["DEBUG", "INFO", "WARN", "ERROR"];
7
7
  export const LOG_COMPONENTS = ["edk", "ei", "provider", "tofu"];
8
8
  /** Diagnostic rendering defaults to structured plaintext; JSON is explicit. */
9
9
  export const LOG_FORMATS = ["text", "json"];
10
+ export function parsePartialReadEvent(line) {
11
+ try {
12
+ const value = JSON.parse(line);
13
+ if (typeof value !== "object" || value === null)
14
+ return undefined;
15
+ const event = value;
16
+ if (event.protocol_version !== 1 || event.event !== "partial_read" || typeof event.sequence !== "number" ||
17
+ typeof event.timestamp !== "string" || typeof event.operation !== "string" || typeof event.message !== "string" ||
18
+ typeof event.guidance !== "string" || (event.category !== "source" && event.category !== "platform") ||
19
+ !Array.isArray(event.path) || !event.path.every((segment) => typeof segment === "string" || typeof segment === "number") ||
20
+ (event.code !== undefined && typeof event.code !== "string"))
21
+ return undefined;
22
+ return value;
23
+ }
24
+ catch {
25
+ return undefined;
26
+ }
27
+ }
10
28
  export function parseProgressEvent(line) {
11
29
  try {
12
30
  const value = JSON.parse(line);
@@ -33,6 +33,11 @@ export interface DirectReferenceRoot {
33
33
  readonly refName: string;
34
34
  readonly name: string;
35
35
  }[];
36
+ /** The owner's AI search tables, keyed as the owner's own export keys them. */
37
+ readonly searchTables?: readonly {
38
+ readonly refName: string;
39
+ readonly name: string;
40
+ }[];
36
41
  }
37
42
  export type UnresolvedReference = UnresolvedReferenceDiagnostic;
38
43
  /** Format the diagnostic suffix printed beside an existing `unsafePlatformId(...)` call. */
@@ -143,16 +143,18 @@ function parseRoot(payload) {
143
143
  outputs,
144
144
  }];
145
145
  });
146
- const skills = (Array.isArray(obj.skills) ? obj.skills : []).flatMap((rawSkill) => {
147
- const skill = record(rawSkill);
148
- if (skill === undefined)
146
+ const namedItems = (raw) => (Array.isArray(raw) ? raw : []).flatMap((rawItem) => {
147
+ const item = record(rawItem);
148
+ if (item === undefined)
149
149
  return [];
150
- const skillName = stringAt(skill, "name");
151
- const skillRefName = stringAt(skill, "refName");
152
- return skillName === undefined || skillRefName === undefined
150
+ const itemName = stringAt(item, "name");
151
+ const itemRefName = stringAt(item, "refName");
152
+ return itemName === undefined || itemRefName === undefined
153
153
  ? []
154
- : [{ refName: tfLabelToTsLabel(skillRefName), name: skillName }];
154
+ : [{ refName: tfLabelToTsLabel(itemRefName), name: itemName }];
155
155
  });
156
+ const skills = namedItems(obj.skills);
157
+ const searchTables = namedItems(obj.searchTables);
156
158
  return {
157
159
  root: {
158
160
  kind,
@@ -164,6 +166,7 @@ function parseRoot(payload) {
164
166
  datamines,
165
167
  automations,
166
168
  skills,
169
+ ...(searchTables.length > 0 ? { searchTables } : {}),
167
170
  },
168
171
  diagnostics,
169
172
  };
@@ -23,4 +23,10 @@ export declare function managedResultStatus(operation: string, verdict: ManagedR
23
23
  * redirect gets the complete machine-readable result object.
24
24
  */
25
25
  export declare function writePullResult(result: unknown, humanLines: readonly PullResultLine[], status?: ManagedResultStatus): void;
26
+ /**
27
+ * Reports partial reads no pull summary took: exports outside `pull` (clone,
28
+ * the refresh after apply) and a pull that failed before its summary. Called
29
+ * once when a CLI command ends.
30
+ */
31
+ export declare function reportPendingPartialReads(): void;
26
32
  export declare function countSummary(entries: readonly (readonly [singular: string, count: number, plural?: string])[]): string;
@@ -1,4 +1,5 @@
1
- import { flushRepeatedTechnicalLogs, machineReadableLogsEnabled, renderTextEffects, writeUserOutput } from "../progress.js";
1
+ import { takePartialReads } from "../ei/run.js";
2
+ import { flushRepeatedTechnicalLogs, machineReadableLogsEnabled, renderTextEffects, writeTechnicalLog, writeUserOutput } from "../progress.js";
2
3
  export function managedResultStatus(operation, verdict) {
3
4
  const outcome = verdict.failed === true
4
5
  ? "failure"
@@ -16,11 +17,27 @@ export function writePullResult(result, humanLines, status) {
16
17
  // Put duplicate-warning summaries before the final success/warning/failure
17
18
  // marker, so the marker remains the last diagnostic signal of the command.
18
19
  flushRepeatedTechnicalLogs();
19
- const resultWithStatus = status !== undefined && result !== null && typeof result === "object"
20
- ? { ...result, status: status.outcome }
20
+ const reads = takeReads();
21
+ const partialReads = groupPartialReads(reads);
22
+ const detail = partialReadDetail();
23
+ // A partial read means some fields were never read: the pull is incomplete
24
+ // even when everything that was read was written (docs/design/graphql-error-standard.md).
25
+ const effectiveStatus = status !== undefined && status.outcome === "success" && reads.length > 0
26
+ ? { ...status, outcome: "warning" }
27
+ : status;
28
+ const resultWithStatus = result !== null && typeof result === "object"
29
+ ? {
30
+ ...result,
31
+ partialReads,
32
+ ...(detail === "verbose" ? { partialReadDetails: reads } : {}),
33
+ ...(reads.length > 0 && "exportComplete" in result ? { exportComplete: false } : {}),
34
+ ...(effectiveStatus === undefined ? {} : { status: effectiveStatus.outcome }),
35
+ }
21
36
  : result;
37
+ status = effectiveStatus;
22
38
  if (process.stdout.isTTY === true && !machineReadableLogsEnabled()) {
23
39
  const renderedLines = humanLines.flatMap((line) => Array.isArray(line) && line.length === 0 ? [] : [renderPullResultLine(line)]);
40
+ renderedLines.push(...partialReadLines(reads, detail));
24
41
  if (status !== undefined) {
25
42
  const message = status.outcome === "success"
26
43
  ? `${status.operation} completed successfully`
@@ -47,6 +64,73 @@ export function writePullResult(result, humanLines, status) {
47
64
  }
48
65
  process.stdout.write(`${JSON.stringify(resultWithStatus, null, 2)}\n`);
49
66
  }
67
+ /**
68
+ * Reports partial reads no pull summary took: exports outside `pull` (clone,
69
+ * the refresh after apply) and a pull that failed before its summary. Called
70
+ * once when a CLI command ends.
71
+ */
72
+ export function reportPendingPartialReads() {
73
+ const reads = takeReads();
74
+ partialReadLines(reads, partialReadDetail()).forEach((line, index) => {
75
+ if (machineReadableLogsEnabled())
76
+ writeTechnicalLog("WARN", "edk", line);
77
+ else
78
+ console.error(index === 0 ? `Warning: ${line}` : line);
79
+ });
80
+ }
81
+ function takeReads() {
82
+ return takePartialReads().map(({ operation, path, code, message, category, guidance }) => ({ operation, path, ...(code === undefined ? {} : { code }), message, category, guidance }));
83
+ }
84
+ /** The human lines for partial reads at a detail level; off hides the listing, not the fact. */
85
+ function partialReadLines(reads, detail) {
86
+ if (reads.length === 0)
87
+ return [];
88
+ if (detail === "verbose") {
89
+ return reads.flatMap((read) => [
90
+ `Incomplete read of ${pathText(read.path)} in ${read.operation}: ${read.message}`,
91
+ ` [${read.category}] ${read.guidance}`,
92
+ ]);
93
+ }
94
+ if (detail === "summary") {
95
+ const groups = groupPartialReads(reads);
96
+ const allPlatform = groups.every((group) => group.category === "platform");
97
+ return [
98
+ `${reads.length} field(s) were not read (${groups.length} kind(s)${allPlatform ? ", platform-side" : ""}); rerun with --partial-reads=verbose for every path:`,
99
+ ...groups.map((group) => ` - ${group.field} in ${group.operation} (${group.count}) [${group.category}] ${group.guidance}`),
100
+ ];
101
+ }
102
+ return [`${reads.length} field(s) were not read; rerun with --partial-reads=summary to see which`];
103
+ }
104
+ function partialReadDetail() {
105
+ const value = process.env["ELEMENTUM_PARTIAL_READS"]?.toLowerCase();
106
+ return value === "off" || value === "verbose" ? value : "summary";
107
+ }
108
+ /** One entry per operation and field (list indexes ignored), in first-seen order. */
109
+ function groupPartialReads(reads) {
110
+ const groups = new Map();
111
+ for (const read of reads) {
112
+ const field = read.path.map((segment) => typeof segment === "number" ? "[]" : segment).join(".").replace(/\.\[\]/g, "[]");
113
+ const key = `${read.operation}\u0000${field}`;
114
+ const group = groups.get(key);
115
+ if (group !== undefined) {
116
+ group.count += 1;
117
+ continue;
118
+ }
119
+ groups.set(key, {
120
+ operation: read.operation,
121
+ field,
122
+ count: 1,
123
+ ...(read.code === undefined ? {} : { code: read.code }),
124
+ message: read.message,
125
+ category: read.category,
126
+ guidance: read.guidance,
127
+ });
128
+ }
129
+ return [...groups.values()];
130
+ }
131
+ function pathText(path) {
132
+ return path.map((segment, index) => typeof segment === "number" ? `[${segment}]` : `${index === 0 ? "" : "."}${segment}`).join("");
133
+ }
50
134
  function renderPullResultLine(line) {
51
135
  if (typeof line === "string")
52
136
  return line;
@@ -190,7 +190,7 @@ class Parser {
190
190
  }
191
191
  if (first === "var") {
192
192
  if (this.options.allowVariables !== true) {
193
- throw new TfExprError("Terraform variables are only supported in modeled credential attributes", this.src);
193
+ throw new TfExprError("Terraform variables are only supported in modeled credential attributes and write-only API secrets", this.src);
194
194
  }
195
195
  this.expect(".");
196
196
  const name = this.takeIdent();
@@ -3,10 +3,10 @@
3
3
  * A second dialect must not exist: extractors consume TfBlock from parseHcl;
4
4
  * toHcl emitters produce TfBlock rendered by renderDocument.
5
5
  */
6
- export type { PathSeg, TfBlock, TfBlockKind, TfDocument, TfExpr, TfValue } from "./model.js";
6
+ export type { PathSeg, TfBlock, TfBlockKind, TfDocument, TfExpr, TfLifecycle, TfValue, TfVariableValidation } from "./model.js";
7
7
  export { expr, isTfExpr } from "./model.js";
8
8
  export { decodeTemplateEscapes, encodeTemplateEscapes, quoteHclString } from "./escape.js";
9
9
  export { parseExpression, parseStringValue, TfExprError } from "./expr.js";
10
10
  export { assertNoUnsafeIntegers, inspectBackendHcl, parseHcl, parseHclDocuments, TfParseError, type BackendHclInspection, } from "./parse.js";
11
11
  export { renderBlock, renderDocument } from "./render.js";
12
- export { appResourceLabelPrefix, appScopedResourceLabel, bareChildResourceLabel, childPartFromScopedLabel, elementResourceLabelPrefix, elementScopedResourceLabel, isCanonicalTsLabel, isTfLabel, isUuid, sanitizeName, scopedLabelToBagKey, scopedResourceLabel, snakeSlug, splitCamelCase, tfLabelToTsLabel, tsLabelToTfLabel, type ChildResourceScope, } from "./labels.js";
12
+ export { appResourceLabelPrefix, appScopedResourceLabel, bareChildResourceLabel, childPartFromScopedLabel, elementResourceLabelPrefix, elementScopedResourceLabel, isCanonicalTsLabel, isTfLabel, isUuid, sanitizeName, scopedLabelToBagKey, scopedResourceLabel, snakeSlug, splitCamelCase, stableIdSuffix, tfLabelToTsLabel, tsLabelToTfLabel, type ChildResourceScope, } from "./labels.js";
@@ -8,4 +8,4 @@ export { decodeTemplateEscapes, encodeTemplateEscapes, quoteHclString } from "./
8
8
  export { parseExpression, parseStringValue, TfExprError } from "./expr.js";
9
9
  export { assertNoUnsafeIntegers, inspectBackendHcl, parseHcl, parseHclDocuments, TfParseError, } from "./parse.js";
10
10
  export { renderBlock, renderDocument } from "./render.js";
11
- export { appResourceLabelPrefix, appScopedResourceLabel, bareChildResourceLabel, childPartFromScopedLabel, elementResourceLabelPrefix, elementScopedResourceLabel, isCanonicalTsLabel, isTfLabel, isUuid, sanitizeName, scopedLabelToBagKey, scopedResourceLabel, snakeSlug, splitCamelCase, tfLabelToTsLabel, tsLabelToTfLabel, } from "./labels.js";
11
+ export { appResourceLabelPrefix, appScopedResourceLabel, bareChildResourceLabel, childPartFromScopedLabel, elementResourceLabelPrefix, elementScopedResourceLabel, isCanonicalTsLabel, isTfLabel, isUuid, sanitizeName, scopedLabelToBagKey, scopedResourceLabel, snakeSlug, splitCamelCase, stableIdSuffix, tfLabelToTsLabel, tsLabelToTfLabel, } from "./labels.js";
@@ -83,5 +83,11 @@ export declare function bareChildResourceLabel(ownerTfLabel: string, scopedLabel
83
83
  * kept only to no-op on unprefixed input.
84
84
  */
85
85
  export declare function childPartFromScopedLabel(ownerTfLabel: string, scopedLabel: string, scope: ChildResourceScope): string;
86
+ /**
87
+ * First 8 alphanumeric characters of `id`, lowercased. ei export's
88
+ * `stableIDSuffix` (cmd/elementum/export/search_table_refs.go) must stay
89
+ * identical so an id-keyed data source address matches on both sides.
90
+ */
91
+ export declare function stableIdSuffix(id: string): string;
86
92
  /** Scoped terraform label → authoring bag key / ref key. */
87
93
  export declare function scopedLabelToBagKey(ownerTfLabel: string, scopedLabel: string, scope?: ChildResourceScope): string;
@@ -198,6 +198,15 @@ export function childPartFromScopedLabel(ownerTfLabel, scopedLabel, scope) {
198
198
  const nsPrefix = `${ownerTfLabel}_`;
199
199
  return bare.startsWith(nsPrefix) ? bare.slice(nsPrefix.length) : bare;
200
200
  }
201
+ /**
202
+ * First 8 alphanumeric characters of `id`, lowercased. ei export's
203
+ * `stableIDSuffix` (cmd/elementum/export/search_table_refs.go) must stay
204
+ * identical so an id-keyed data source address matches on both sides.
205
+ */
206
+ export function stableIdSuffix(id) {
207
+ const normalized = id.toLowerCase().replace(/[^a-z0-9]/g, "");
208
+ return normalized.slice(0, 8);
209
+ }
201
210
  /** Scoped terraform label → authoring bag key / ref key. */
202
211
  export function scopedLabelToBagKey(ownerTfLabel, scopedLabel, scope = "app") {
203
212
  return tfLabelToTsLabel(childPartFromScopedLabel(ownerTfLabel, scopedLabel, scope));
@@ -67,13 +67,34 @@ export type TfValue = string | number | boolean | null | TfValue[] | {
67
67
  [k: string]: TfValue;
68
68
  } | TfExpr;
69
69
  export type TfBlockKind = "resource" | "data" | "locals" | "import" | "provider" | "terraform" | "variable";
70
+ /**
71
+ * A resource's nested `lifecycle { ignore_changes = ... }` block — `"all"` or
72
+ * named top-level attributes. Never part of the ei dialect: only smart apply
73
+ * emits it, to stop a limited plan changing items that aren't the caller's.
74
+ */
75
+ export interface TfLifecycle {
76
+ ignoreChanges: "all" | readonly string[];
77
+ }
78
+ /**
79
+ * A variable's nested `validation` block. The condition is raw HCL, not a
80
+ * closed-grammar expression: `var.name != ""` is outside that grammar, and
81
+ * pull must still accept the block. Only required write-only secrets emit it.
82
+ */
83
+ export interface TfVariableValidation {
84
+ readonly condition: string;
85
+ readonly errorMessage: string;
86
+ }
70
87
  export interface TfBlock {
71
88
  kind: TfBlockKind;
72
89
  /** resource/data only: the terraform type, e.g. "elementum_app" */
73
90
  type?: string;
74
- /** resource/data: the label; provider: the provider name */
91
+ /** resource/data: the label; provider: the provider name; variable: the variable name */
75
92
  label?: string;
76
93
  attrs: Record<string, TfValue>;
94
+ /** resource only: rendered as a nested `lifecycle` block after the attributes. */
95
+ lifecycle?: TfLifecycle;
96
+ /** variable only: rendered as a nested `validation` block. */
97
+ variableValidation?: TfVariableValidation;
77
98
  }
78
99
  export interface TfDocument {
79
100
  blocks: TfBlock[];
@@ -328,7 +328,14 @@ function documentFromHcl2Json(raw) {
328
328
  for (const [type, byLabel] of Object.entries(byType)) {
329
329
  for (const [label, bodies] of Object.entries(byLabel)) {
330
330
  for (const body of bodies) {
331
- blocks.push({ kind, type, label, attrs: convertBody(body, `${kind}.${type}.${label}`) });
331
+ const ctx = `${kind}.${type}.${label}`;
332
+ if (kind === "resource" && isRecord(body) && "lifecycle" in body) {
333
+ const { lifecycle, ...rest } = body;
334
+ blocks.push({ kind, type, label, attrs: convertBody(rest, ctx), lifecycle: convertLifecycle(lifecycle, ctx) });
335
+ }
336
+ else {
337
+ blocks.push({ kind, type, label, attrs: convertBody(body, ctx) });
338
+ }
332
339
  }
333
340
  }
334
341
  }
@@ -354,8 +361,20 @@ function documentFromHcl2Json(raw) {
354
361
  const variables = raw["variable"];
355
362
  if (variables) {
356
363
  for (const [name, bodies] of Object.entries(variables)) {
357
- for (const body of bodies)
358
- blocks.push({ kind: "variable", label: name, attrs: convertBody(body, `variable.${name}`) });
364
+ for (const body of bodies) {
365
+ if (isRecord(body) && "validation" in body) {
366
+ const { validation, ...rest } = body;
367
+ blocks.push({
368
+ kind: "variable",
369
+ label: name,
370
+ attrs: convertBody(rest, `variable.${name}`),
371
+ variableValidation: convertVariableValidation(validation, `variable.${name}`),
372
+ });
373
+ }
374
+ else {
375
+ blocks.push({ kind: "variable", label: name, attrs: convertBody(body, `variable.${name}`) });
376
+ }
377
+ }
359
378
  }
360
379
  }
361
380
  const terraformBodies = raw["terraform"];
@@ -366,6 +385,39 @@ function documentFromHcl2Json(raw) {
366
385
  }
367
386
  return { blocks };
368
387
  }
388
+ function isRecord(value) {
389
+ return typeof value === "object" && value !== null && !Array.isArray(value);
390
+ }
391
+ const BARE_REFERENCE_RE = /^\$\{([A-Za-z_][A-Za-z0-9_]*)\}$/;
392
+ /**
393
+ * hcl2json reads `lifecycle { ignore_changes = all }` as
394
+ * `[{ "ignore_changes": "${all}" }]` and a name list as `["${name}", ...]`.
395
+ * Only that one shape is accepted — any other lifecycle setting stays loud.
396
+ */
397
+ function convertLifecycle(value, ctx) {
398
+ const at = `${ctx}.lifecycle`;
399
+ if (!Array.isArray(value) || value.length !== 1 || !isRecord(value[0])) {
400
+ throw new TfParseError(`unexpected lifecycle block shape at ${at}`);
401
+ }
402
+ const keys = Object.keys(value[0]);
403
+ if (keys.length !== 1 || keys[0] !== "ignore_changes") {
404
+ throw new TfParseError(`at ${at}: only ignore_changes is supported, got ${keys.join(", ") || "nothing"}`);
405
+ }
406
+ const ignore = value[0]["ignore_changes"];
407
+ if (ignore === "${all}")
408
+ return { ignoreChanges: "all" };
409
+ if (Array.isArray(ignore)) {
410
+ return {
411
+ ignoreChanges: ignore.map((entry) => {
412
+ const match = typeof entry === "string" ? BARE_REFERENCE_RE.exec(entry) : null;
413
+ if (match === null)
414
+ throw new TfParseError(`at ${at}.ignore_changes: expected attribute names, got ${JSON.stringify(entry)}`);
415
+ return match[1];
416
+ }),
417
+ };
418
+ }
419
+ throw new TfParseError(`at ${at}.ignore_changes: expected all or a list of attribute names`);
420
+ }
369
421
  function convertBody(body, ctx) {
370
422
  if (typeof body !== "object" || body === null || Array.isArray(body)) {
371
423
  throw new TfParseError(`unexpected block body shape at ${ctx}`);
@@ -383,7 +435,7 @@ function convertValue(value, ctx) {
383
435
  return value;
384
436
  if (typeof value === "string") {
385
437
  try {
386
- return parseStringValue(value, { allowVariables: isCredentialVariableContext(ctx) });
438
+ return parseStringValue(value, { allowVariables: allowsVariableReference(ctx) });
387
439
  }
388
440
  catch (e) {
389
441
  if (e instanceof TfExprError) {
@@ -409,10 +461,46 @@ function convertValue(value, ctx) {
409
461
  }
410
462
  throw new TfParseError(`unsupported value type "${typeof value}" at ${ctx}`);
411
463
  }
464
+ function allowsVariableReference(ctx) {
465
+ return isCredentialVariableContext(ctx) || isWriteOnlyApiSecretContext(ctx);
466
+ }
412
467
  function isCredentialVariableContext(ctx) {
468
+ // Resource types stay inside regex literals. src/engine must not contain
469
+ // quoted elementum_* resource-type strings.
413
470
  return /^resource\.elementum_cloudlink\.[^.]+\.credentials(?:\.|$)/.test(ctx) ||
414
471
  /^resource\.elementum_phone_provider\.[^.]+\.twilio(?:\.|$)/.test(ctx);
415
472
  }
473
+ function isWriteOnlyApiSecretContext(ctx) {
474
+ return /^resource\.elementum_api_task\.[^.]+\.headers\[\d+\]\.value$/.test(ctx) ||
475
+ /^resource\.elementum_api_task\.[^.]+\.basic_auth\.username$/.test(ctx);
476
+ }
477
+ /**
478
+ * hcl2json reads `validation { condition = var.x != "" }` as
479
+ * `[{ condition: "${var.x != \"\"}", error_message: "..." }]`. The condition
480
+ * is not a closed-grammar expression, so it is preserved as raw text.
481
+ */
482
+ function convertVariableValidation(value, ctx) {
483
+ const at = `${ctx}.validation`;
484
+ if (!Array.isArray(value) || value.length !== 1 || !isRecord(value[0])) {
485
+ throw new TfParseError(`unexpected validation block shape at ${at}`);
486
+ }
487
+ const condition = unwrapHclExpr(value[0]["condition"]);
488
+ const errorMessage = value[0]["error_message"];
489
+ if (condition === undefined || condition === "") {
490
+ throw new TfParseError(`at ${at}: validation condition must be an expression`);
491
+ }
492
+ if (typeof errorMessage !== "string") {
493
+ throw new TfParseError(`at ${at}: validation error_message must be a string`);
494
+ }
495
+ return { condition, errorMessage };
496
+ }
497
+ function unwrapHclExpr(value) {
498
+ if (typeof value !== "string")
499
+ return undefined;
500
+ if (value.startsWith("${") && value.endsWith("}") && value.length >= 3)
501
+ return value.slice(2, -1);
502
+ return value;
503
+ }
416
504
  /**
417
505
  * Refuse to parse text whose integer literals exceed Number.MAX_SAFE_INTEGER —
418
506
  * hcl2json would round them silently (verified: 2^53+1 → 2^53).
@@ -5,8 +5,10 @@
5
5
  * Formatting is OURS (deterministic, 2-space indent, attrs sorted
6
6
  * alphabetically) — ei's incidental formatting is not replicated; the
7
7
  * round-trip check is structural, both sides parsed by the same parser.
8
- * The ei dialect is attributes-only (verified across real exports), so no
9
- * nested-block syntax is emitted.
8
+ * The ei resource dialect is attributes-only (verified across real exports).
9
+ * Two nested blocks are emitted outside that dialect: a resource's
10
+ * `lifecycle`, which only smart apply sets, and a variable's `validation`,
11
+ * which only a required write-only secret sets.
10
12
  */
11
13
  import type { TfBlock, TfDocument } from "./model.js";
12
14
  export declare function renderDocument(doc: TfDocument): string;
@@ -5,8 +5,10 @@
5
5
  * Formatting is OURS (deterministic, 2-space indent, attrs sorted
6
6
  * alphabetically) — ei's incidental formatting is not replicated; the
7
7
  * round-trip check is structural, both sides parsed by the same parser.
8
- * The ei dialect is attributes-only (verified across real exports), so no
9
- * nested-block syntax is emitted.
8
+ * The ei resource dialect is attributes-only (verified across real exports).
9
+ * Two nested blocks are emitted outside that dialect: a resource's
10
+ * `lifecycle`, which only smart apply sets, and a variable's `validation`,
11
+ * which only a required write-only secret sets.
10
12
  */
11
13
  import { quoteHclString } from "./escape.js";
12
14
  import { isTfExpr } from "./model.js";
@@ -15,11 +17,40 @@ export function renderDocument(doc) {
15
17
  }
16
18
  export function renderBlock(block) {
17
19
  const header = blockHeader(block);
18
- const body = Object.entries(block.attrs)
20
+ const lines = Object.entries(block.attrs)
19
21
  .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
20
- .map(([key, value]) => ` ${key} = ${renderValue(value, 1)}`)
21
- .join("\n");
22
- return `${header} {\n${body}\n}\n`;
22
+ .map(([key, value]) => ` ${key} = ${renderValue(value, 1)}`);
23
+ if (block.lifecycle !== undefined) {
24
+ if (block.kind !== "resource")
25
+ throw new Error(`a lifecycle block is only valid on a resource, not ${block.kind}`);
26
+ lines.push(renderLifecycle(block.lifecycle));
27
+ }
28
+ if (block.variableValidation !== undefined) {
29
+ if (block.kind !== "variable")
30
+ throw new Error(`a validation block is only valid on a variable, not ${block.kind}`);
31
+ lines.push(renderVariableValidation(block.label, block.variableValidation));
32
+ }
33
+ return `${header} {\n${lines.join("\n")}\n}\n`;
34
+ }
35
+ const ATTRIBUTE_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
36
+ function renderLifecycle(lifecycle) {
37
+ if (lifecycle.ignoreChanges === "all")
38
+ return " lifecycle {\n ignore_changes = all\n }";
39
+ const names = lifecycle.ignoreChanges.map((name) => {
40
+ if (!ATTRIBUTE_NAME_RE.test(name))
41
+ throw new Error(`ignore_changes names a top-level attribute, got "${name}"`);
42
+ return name;
43
+ });
44
+ return ` lifecycle {\n ignore_changes = [${names.join(", ")}]\n }`;
45
+ }
46
+ const REQUIRED_SECRET_CONDITION = /^var\.[A-Za-z_][A-Za-z0-9_]* != ""$/;
47
+ function renderVariableValidation(label, validation) {
48
+ if (!label || !ATTRIBUTE_NAME_RE.test(label))
49
+ throw new Error(`variable validation needs an identifier name, got "${label ?? ""}"`);
50
+ if (!REQUIRED_SECRET_CONDITION.test(validation.condition)) {
51
+ throw new Error(`variable ${label} validation condition must refuse an empty value`);
52
+ }
53
+ return ` validation {\n condition = ${validation.condition}\n error_message = ${quoteHclString(validation.errorMessage)}\n }`;
23
54
  }
24
55
  function blockHeader(block) {
25
56
  switch (block.kind) {
@@ -67,8 +98,11 @@ function renderValue(value, depth) {
67
98
  return `{\n${body}\n${close}}`;
68
99
  }
69
100
  const BARE_KEY_RE = /^[A-Za-z_][A-Za-z0-9_-]*$/;
101
+ // `for` starts a for-expression, so `{ for = 1 }` is not an object. `null`,
102
+ // `true`, and `false` are literals; quote them too. `if` is a valid bare key.
103
+ const RESERVED_OBJECT_KEYS = new Set(["false", "for", "null", "true"]);
70
104
  function objectKey(k) {
71
- return BARE_KEY_RE.test(k) ? k : quoteHclString(k);
105
+ return BARE_KEY_RE.test(k) && !RESERVED_OBJECT_KEYS.has(k) ? k : quoteHclString(k);
72
106
  }
73
107
  function renderExpr(e, depth) {
74
108
  switch (e.$expr) {
@@ -0,0 +1,39 @@
1
+ export type ValidationSeverity = "fatal" | "warning";
2
+ export type ValidationMode = "pull" | "build";
3
+ export interface ValidationFailure {
4
+ readonly severity: ValidationSeverity;
5
+ /** Terraform resource address, `type.label`. */
6
+ readonly address: string;
7
+ /** Automation or agent display name. */
8
+ readonly name: string;
9
+ readonly ownerKind: string;
10
+ readonly message: string;
11
+ /**
12
+ * A reference the live config no longer satisfies (for example a run-automation
13
+ * tool that does not map a newly required trigger parameter). Pull downgrades
14
+ * these to warnings; build/plan/apply keep them fatal.
15
+ */
16
+ readonly staleReference?: boolean;
17
+ }
18
+ export declare function formatValidationFailure(failure: ValidationFailure): string;
19
+ export declare class ValidationFailureError extends Error {
20
+ readonly failures: readonly ValidationFailure[];
21
+ constructor(failures: readonly ValidationFailure[]);
22
+ }
23
+ /** True for this module's class and for the same-shaped error from a loader copy. */
24
+ export declare function isValidationFailureError(error: unknown): error is ValidationFailureError;
25
+ export declare function withValidationSession<T>(mode: ValidationMode, run: () => T): T;
26
+ export declare function withValidationSessionAsync<T>(mode: ValidationMode, run: () => Promise<T>): Promise<T>;
27
+ export declare function currentValidationMode(): ValidationMode | undefined;
28
+ export declare function currentValidationScope(): {
29
+ readonly appTfLabel?: string;
30
+ readonly parentScope?: "app" | "element" | "table";
31
+ };
32
+ export declare function setValidationScope(scope: {
33
+ appTfLabel?: string;
34
+ parentScope?: "app" | "element" | "table";
35
+ }): void;
36
+ export declare function sessionValidationFailures(): readonly ValidationFailure[];
37
+ /** Record failures into the active session. No-op when nothing is collecting. */
38
+ export declare function recordValidations(incoming: readonly ValidationFailure[]): void;
39
+ export declare function hasFatalValidation(failures: readonly ValidationFailure[]): boolean;