@elementumai/edk 0.8.1 → 0.8.2-alpha.6

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 (74) hide show
  1. package/README.md +166 -34
  2. package/dist-sdk/src/catalog/factories.js +18 -2
  3. package/dist-sdk/src/catalog/from-authoring.js +13 -1
  4. package/dist-sdk/src/catalog/org.js +51 -44
  5. package/dist-sdk/src/catalog/token.js +4 -0
  6. package/dist-sdk/src/catalog/types.d.ts +15 -0
  7. package/dist-sdk/src/core/types/app.d.ts +14 -8
  8. package/dist-sdk/src/engine/build/context.d.ts +40 -0
  9. package/dist-sdk/src/engine/build/context.js +11 -1
  10. package/dist-sdk/src/engine/tf/index.d.ts +2 -2
  11. package/dist-sdk/src/engine/tf/index.js +2 -2
  12. package/dist-sdk/src/engine/tf/labels.d.ts +29 -20
  13. package/dist-sdk/src/engine/tf/labels.js +32 -28
  14. package/dist-sdk/src/engine/tf/parse.d.ts +15 -0
  15. package/dist-sdk/src/engine/tf/parse.js +162 -0
  16. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +19 -1
  17. package/dist-sdk/src/entities/access-policy/from-tf.js +4 -6
  18. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +12 -5
  19. package/dist-sdk/src/entities/access-policy/to-tf.js +21 -6
  20. package/dist-sdk/src/entities/agent/build.d.ts +2 -0
  21. package/dist-sdk/src/entities/agent/build.js +1 -0
  22. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +60 -2
  23. package/dist-sdk/src/entities/agent/from-tf.d.ts +12 -7
  24. package/dist-sdk/src/entities/agent/from-tf.js +22 -15
  25. package/dist-sdk/src/entities/agent/module.js +7 -3
  26. package/dist-sdk/src/entities/agent/to-tf.d.ts +46 -1
  27. package/dist-sdk/src/entities/agent/to-tf.js +102 -8
  28. package/dist-sdk/src/entities/agent-a2a-skill/from-tf.d.ts +17 -0
  29. package/dist-sdk/src/entities/agent-a2a-skill/from-tf.js +64 -0
  30. package/dist-sdk/src/entities/agent-a2a-skill/module.d.ts +4 -0
  31. package/dist-sdk/src/entities/agent-a2a-skill/module.js +14 -0
  32. package/dist-sdk/src/entities/agent-a2a-skill/to-tf.d.ts +40 -0
  33. package/dist-sdk/src/entities/agent-a2a-skill/to-tf.js +47 -0
  34. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +7 -2
  35. package/dist-sdk/src/entities/agent-tool/to-tf.js +86 -26
  36. package/dist-sdk/src/entities/app/build.d.ts +35 -7
  37. package/dist-sdk/src/entities/app/build.js +19 -8
  38. package/dist-sdk/src/entities/app/from-tf.js +0 -7
  39. package/dist-sdk/src/entities/app/module.js +1 -0
  40. package/dist-sdk/src/entities/app/to-tf.js +13 -1
  41. package/dist-sdk/src/entities/automation/build.js +14 -6
  42. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +27 -4
  43. package/dist-sdk/src/entities/automation/filter.d.ts +22 -0
  44. package/dist-sdk/src/entities/automation/filter.js +42 -1
  45. package/dist-sdk/src/entities/automation/from-tf.js +127 -11
  46. package/dist-sdk/src/entities/automation/to-tf.js +176 -18
  47. package/dist-sdk/src/entities/element/build.d.ts +26 -8
  48. package/dist-sdk/src/entities/element/build.js +44 -3
  49. package/dist-sdk/src/entities/element/from-tf.js +10 -11
  50. package/dist-sdk/src/entities/element/module.js +1 -0
  51. package/dist-sdk/src/entities/element/to-tf.js +5 -0
  52. package/dist-sdk/src/entities/field/build.d.ts +9 -5
  53. package/dist-sdk/src/entities/field/calc/runtime.js +2 -2
  54. package/dist-sdk/src/entities/field/from-tf.js +10 -10
  55. package/dist-sdk/src/entities/field/to-tf.d.ts +35 -18
  56. package/dist-sdk/src/entities/field/to-tf.js +110 -6
  57. package/dist-sdk/src/entities/shared/filters/ast.d.ts +15 -0
  58. package/dist-sdk/src/entities/shared/tool-field-ref.js +15 -0
  59. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +97 -8
  60. package/dist-sdk/src/entities/skill/module.js +1 -0
  61. package/dist-sdk/src/entities/skill/to-tf.d.ts +26 -0
  62. package/dist-sdk/src/entities/skill/to-tf.js +63 -3
  63. package/dist-sdk/src/entities/skill/tools.d.ts +12 -5
  64. package/dist-sdk/src/entities/skill/tools.js +26 -1
  65. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +19 -2
  66. package/dist-sdk/src/entities/skill-tool/from-tf.js +97 -8
  67. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +11 -1
  68. package/dist-sdk/src/entities/skill-tool/to-tf.js +143 -27
  69. package/dist-sdk/src/entities/skill-tool/types.d.ts +5 -7
  70. package/dist-sdk/src/entities/skill-tool/types.js +47 -11
  71. package/dist-sdk/src/entities/view/to-tf.js +6 -0
  72. package/dist-sdk/src/graph/modules.js +2 -0
  73. package/dist-sdk/src/graph/types.d.ts +22 -2
  74. package/package.json +12 -7
@@ -6,6 +6,6 @@
6
6
  export { expr, isTfExpr } from "./model.js";
7
7
  export { decodeTemplateEscapes, encodeTemplateEscapes, quoteHclString } from "./escape.js";
8
8
  export { parseExpression, parseStringValue, TfExprError } from "./expr.js";
9
- export { assertNoUnsafeIntegers, parseHcl, TfParseError } from "./parse.js";
9
+ export { assertNoUnsafeIntegers, inspectBackendHcl, parseHcl, TfParseError, } from "./parse.js";
10
10
  export { renderBlock, renderDocument } from "./render.js";
11
- export { appResourceLabelPrefix, appScopedResourceLabel, bareChildResourceLabel, childPartFromScopedLabel, elementResourceLabelPrefix, elementScopedResourceLabel, isCanonicalTsLabel, isUuid, ownerChildBareLabel, sanitizeName, scopedLabelToBagKey, scopedResourceLabel, snakeSlug, splitCamelCase, tfLabelToTsLabel, tsLabelToTfLabel, } from "./labels.js";
11
+ export { appResourceLabelPrefix, appScopedResourceLabel, bareChildResourceLabel, childPartFromScopedLabel, elementResourceLabelPrefix, elementScopedResourceLabel, isCanonicalTsLabel, isUuid, sanitizeName, scopedLabelToBagKey, scopedResourceLabel, snakeSlug, splitCamelCase, tfLabelToTsLabel, tsLabelToTfLabel, } from "./labels.js";
@@ -40,36 +40,45 @@ export type ChildResourceScope = "app" | "element";
40
40
  export declare function appResourceLabelPrefix(appTfLabel: string): string;
41
41
  /** Prefix for element-owned children in a shared `.tf/out/` workspace. */
42
42
  export declare function elementResourceLabelPrefix(elementTfLabel: string): string;
43
- /**
44
- * Bare child label before scope prefix: `<ownerNs>_<childPart>` unless already qualified.
45
- * Used ONLY by the element path, whose childPart already INCLUDES the namespace (element bag
46
- * keys carry it), so the `startsWith` guard correctly avoids doubling. The app path must NOT
47
- * use this — an app childPart omits the namespace and may legitimately begin with `<ns>_`
48
- * (e.g. field `sourcingStatus` → `sourcing_status` under app `sourcing`), which the guard would
49
- * misread as "already qualified", collapsing it onto the same label as a field named `status`
50
- * (issue #115). Apps therefore always owner-prefix — see `appScopedResourceLabel`.
51
- */
52
- export declare function ownerChildBareLabel(ownerTfLabel: string, childPart: string): string;
53
43
  /**
54
44
  * App-owned child resource label: `apps_<namespace>_<namespace>_<childPart>`, ALWAYS.
55
- * An app childPart omits the namespace, so the owner prefix is prepended unconditionally to keep
56
- * the encoding injective — `childPartFromScopedLabel` is its exact inverse (strips `apps_<ns>_`
57
- * then one `<ns>_`). Never collapse when the childPart already starts with `<ns>_` (issue #115).
45
+ * The owner prefix is prepended unconditionally — never collapsed just because `childPart`
46
+ * already happens to start with `<ns>_` (issue #115: a field named e.g. `sourcingStatus` under
47
+ * app `sourcing` is a real, distinct field from one named `status`, not a re-encoding of it) —
48
+ * to keep the encoding injective. `childPartFromScopedLabel` is its exact inverse (strips
49
+ * `apps_<ns>_` then one more `<ns>_`, unconditionally).
58
50
  */
59
51
  export declare function appScopedResourceLabel(appTfLabel: string, childPart: string): string;
60
- /** Element-owned child resource label: `elements_<namespace>_<namespace>_<childPart>`. */
52
+ /**
53
+ * Element-owned child resource label: `elements_<namespace>_<namespace>_<childPart>`, ALWAYS —
54
+ * same unconditional doubling as {@link appScopedResourceLabel}, for the same reason (issue
55
+ * #115): a field named e.g. `ticketsPriority` under element `tickets` is a real, distinct field
56
+ * from one named `priority`, not a re-encoding of it. A prior version of this function skipped
57
+ * the double when `childPart` already started with `<ns>_`, which collapsed both onto the same
58
+ * label — reported live against a real `tickets` element field pulling ambiguously.
59
+ *
60
+ * One-time upgrade characteristic, not an ongoing bug: this changes the computed address ONLY
61
+ * for a STALE bag key an older (pre-fix) pull already wrote to disk and that was never
62
+ * re-pulled — the old extractor never stripped the namespace, so it left prefixed bag keys
63
+ * (e.g. `ticketsActive`) that now over-double when rebuilt. A field FRESHLY re-extracted with
64
+ * `childPartFromScopedLabel`'s current (also-fixed) stripping round-trips to the exact same
65
+ * address ei already uses — see `__tests__/tf/labels.test.ts`'s "element-prefixed child labels
66
+ * round-trip" block. Re-pull an existing element (`elementum pull element <ns>`) before your
67
+ * next build/plan if it predates this fix; adoption's rename guard (board item 225,
68
+ * `docs/design/rename-label-identity.md`) safely `state mv`s any address that does shift.
69
+ */
61
70
  export declare function elementScopedResourceLabel(elementTfLabel: string, childPart: string): string;
62
71
  /** Emit a scoped child label for the owning stream root kind. */
63
72
  export declare function scopedResourceLabel(ownerTfLabel: string, childPart: string, scope: ChildResourceScope): string;
64
73
  /** Strip a scoped child label back to its bare form (no-op when unprefixed). */
65
74
  export declare function bareChildResourceLabel(ownerTfLabel: string, scopedLabel: string, scope?: ChildResourceScope): string;
66
75
  /**
67
- * Child part after the owner namespace — for apps, bag keys omit the namespace
68
- * prefix; for elements, the bare label (which includes namespace) maps directly.
69
- *
70
- * The app branch strips `apps_<ns>_` then exactly one `<ns>_` — the exact inverse of
71
- * `appScopedResourceLabel`'s always-double encoding (issue #115). The `startsWith` check is
72
- * therefore always true for a well-formed app label; it is kept only to no-op on unprefixed input.
76
+ * Child part after the owner namespace — bag keys omit the namespace prefix
77
+ * for both apps and elements. Strips `apps_<ns>_`/`elements_<ns>_` then
78
+ * exactly one `<ns>_` — the exact inverse of `appScopedResourceLabel`'s /
79
+ * `elementScopedResourceLabel`'s always-double encoding (issue #115). The
80
+ * `startsWith` check is therefore always true for a well-formed label; it is
81
+ * kept only to no-op on unprefixed input.
73
82
  */
74
83
  export declare function childPartFromScopedLabel(ownerTfLabel: string, scopedLabel: string, scope: ChildResourceScope): string;
75
84
  /** Scoped terraform label → authoring bag key / ref key. */
@@ -140,30 +140,37 @@ export function appResourceLabelPrefix(appTfLabel) {
140
140
  export function elementResourceLabelPrefix(elementTfLabel) {
141
141
  return `elements_${elementTfLabel}_`;
142
142
  }
143
- /**
144
- * Bare child label before scope prefix: `<ownerNs>_<childPart>` unless already qualified.
145
- * Used ONLY by the element path, whose childPart already INCLUDES the namespace (element bag
146
- * keys carry it), so the `startsWith` guard correctly avoids doubling. The app path must NOT
147
- * use this — an app childPart omits the namespace and may legitimately begin with `<ns>_`
148
- * (e.g. field `sourcingStatus` → `sourcing_status` under app `sourcing`), which the guard would
149
- * misread as "already qualified", collapsing it onto the same label as a field named `status`
150
- * (issue #115). Apps therefore always owner-prefix — see `appScopedResourceLabel`.
151
- */
152
- export function ownerChildBareLabel(ownerTfLabel, childPart) {
153
- return childPart.startsWith(`${ownerTfLabel}_`) ? childPart : `${ownerTfLabel}_${childPart}`;
154
- }
155
143
  /**
156
144
  * App-owned child resource label: `apps_<namespace>_<namespace>_<childPart>`, ALWAYS.
157
- * An app childPart omits the namespace, so the owner prefix is prepended unconditionally to keep
158
- * the encoding injective — `childPartFromScopedLabel` is its exact inverse (strips `apps_<ns>_`
159
- * then one `<ns>_`). Never collapse when the childPart already starts with `<ns>_` (issue #115).
145
+ * The owner prefix is prepended unconditionally — never collapsed just because `childPart`
146
+ * already happens to start with `<ns>_` (issue #115: a field named e.g. `sourcingStatus` under
147
+ * app `sourcing` is a real, distinct field from one named `status`, not a re-encoding of it) —
148
+ * to keep the encoding injective. `childPartFromScopedLabel` is its exact inverse (strips
149
+ * `apps_<ns>_` then one more `<ns>_`, unconditionally).
160
150
  */
161
151
  export function appScopedResourceLabel(appTfLabel, childPart) {
162
152
  return `${appResourceLabelPrefix(appTfLabel)}${appTfLabel}_${childPart}`;
163
153
  }
164
- /** Element-owned child resource label: `elements_<namespace>_<namespace>_<childPart>`. */
154
+ /**
155
+ * Element-owned child resource label: `elements_<namespace>_<namespace>_<childPart>`, ALWAYS —
156
+ * same unconditional doubling as {@link appScopedResourceLabel}, for the same reason (issue
157
+ * #115): a field named e.g. `ticketsPriority` under element `tickets` is a real, distinct field
158
+ * from one named `priority`, not a re-encoding of it. A prior version of this function skipped
159
+ * the double when `childPart` already started with `<ns>_`, which collapsed both onto the same
160
+ * label — reported live against a real `tickets` element field pulling ambiguously.
161
+ *
162
+ * One-time upgrade characteristic, not an ongoing bug: this changes the computed address ONLY
163
+ * for a STALE bag key an older (pre-fix) pull already wrote to disk and that was never
164
+ * re-pulled — the old extractor never stripped the namespace, so it left prefixed bag keys
165
+ * (e.g. `ticketsActive`) that now over-double when rebuilt. A field FRESHLY re-extracted with
166
+ * `childPartFromScopedLabel`'s current (also-fixed) stripping round-trips to the exact same
167
+ * address ei already uses — see `__tests__/tf/labels.test.ts`'s "element-prefixed child labels
168
+ * round-trip" block. Re-pull an existing element (`elementum pull element <ns>`) before your
169
+ * next build/plan if it predates this fix; adoption's rename guard (board item 225,
170
+ * `docs/design/rename-label-identity.md`) safely `state mv`s any address that does shift.
171
+ */
165
172
  export function elementScopedResourceLabel(elementTfLabel, childPart) {
166
- return `${elementResourceLabelPrefix(elementTfLabel)}${ownerChildBareLabel(elementTfLabel, childPart)}`;
173
+ return `${elementResourceLabelPrefix(elementTfLabel)}${elementTfLabel}_${childPart}`;
167
174
  }
168
175
  /** Emit a scoped child label for the owning stream root kind. */
169
176
  export function scopedResourceLabel(ownerTfLabel, childPart, scope) {
@@ -175,20 +182,17 @@ export function bareChildResourceLabel(ownerTfLabel, scopedLabel, scope = "app")
175
182
  return scopedLabel.startsWith(prefix) ? scopedLabel.slice(prefix.length) : scopedLabel;
176
183
  }
177
184
  /**
178
- * Child part after the owner namespace — for apps, bag keys omit the namespace
179
- * prefix; for elements, the bare label (which includes namespace) maps directly.
180
- *
181
- * The app branch strips `apps_<ns>_` then exactly one `<ns>_` — the exact inverse of
182
- * `appScopedResourceLabel`'s always-double encoding (issue #115). The `startsWith` check is
183
- * therefore always true for a well-formed app label; it is kept only to no-op on unprefixed input.
185
+ * Child part after the owner namespace — bag keys omit the namespace prefix
186
+ * for both apps and elements. Strips `apps_<ns>_`/`elements_<ns>_` then
187
+ * exactly one `<ns>_` — the exact inverse of `appScopedResourceLabel`'s /
188
+ * `elementScopedResourceLabel`'s always-double encoding (issue #115). The
189
+ * `startsWith` check is therefore always true for a well-formed label; it is
190
+ * kept only to no-op on unprefixed input.
184
191
  */
185
192
  export function childPartFromScopedLabel(ownerTfLabel, scopedLabel, scope) {
186
193
  const bare = bareChildResourceLabel(ownerTfLabel, scopedLabel, scope);
187
- if (scope === "app") {
188
- const nsPrefix = `${ownerTfLabel}_`;
189
- return bare.startsWith(nsPrefix) ? bare.slice(nsPrefix.length) : bare;
190
- }
191
- return bare;
194
+ const nsPrefix = `${ownerTfLabel}_`;
195
+ return bare.startsWith(nsPrefix) ? bare.slice(nsPrefix.length) : bare;
192
196
  }
193
197
  /** Scoped terraform label → authoring bag key / ref key. */
194
198
  export function scopedLabelToBagKey(ownerTfLabel, scopedLabel, scope = "app") {
@@ -24,6 +24,21 @@ export declare function installHcl2JsonRuntime(parser: Hcl2JsonParser): void;
24
24
  export declare class TfParseError extends Error {
25
25
  constructor(message: string);
26
26
  }
27
+ export interface BackendHclInspection {
28
+ readonly type: string;
29
+ }
30
+ /**
31
+ * Validate the dedicated workspace backend source. Credential-bearing keys
32
+ * and the small set of backend-specific locking switches are policy-critical;
33
+ * every other backend argument stays opaque and is preserved verbatim.
34
+ *
35
+ * This deliberately reuses the ONE hcl2json entry point while bypassing the
36
+ * entity expression grammar: OpenTofu backend configuration may contain
37
+ * init-time `var.*`, `local.*`, and nested backend blocks that are not part of
38
+ * ei's entity dialect. The source is projected byte-for-byte after validation;
39
+ * OpenTofu remains the authority for backend-specific arguments.
40
+ */
41
+ export declare function inspectBackendHcl(text: string): Promise<BackendHclInspection>;
27
42
  export declare function parseHcl(text: string): Promise<TfDocument>;
28
43
  /**
29
44
  * Refuse to parse text whose integer literals exceed Number.MAX_SAFE_INTEGER —
@@ -44,6 +44,168 @@ export class TfParseError extends Error {
44
44
  }
45
45
  }
46
46
  const KNOWN_TOP_LEVEL = new Set(["resource", "data", "locals", "import", "provider", "terraform"]);
47
+ const BACKEND_TOP_LEVEL = new Set(["terraform", "variable", "locals"]);
48
+ const BACKEND_SECRET_KEYS = new Set([
49
+ "access_key",
50
+ "access_token",
51
+ "account_key",
52
+ "authorization",
53
+ "bearer_token",
54
+ "client_certificate",
55
+ "client_certificate_password",
56
+ "client_certificate_path",
57
+ "client_key",
58
+ "client_key_password",
59
+ "client_key_pem",
60
+ "client_key_path",
61
+ "client_secret",
62
+ "conn_str",
63
+ "credentials",
64
+ "credentials_file",
65
+ "credentials_json",
66
+ "encryption_key",
67
+ "id_token",
68
+ "password",
69
+ "private_key",
70
+ "private_key_path",
71
+ "sas_token",
72
+ "secret_access_key",
73
+ "secret_id",
74
+ "secret_key",
75
+ "shared_credentials_file",
76
+ "shared_credentials_files",
77
+ "sse_customer_key",
78
+ "token",
79
+ "username",
80
+ "web_identity_token",
81
+ "web_identity_token_file",
82
+ ]);
83
+ const ALWAYS_LOCKING_BACKENDS = new Set([
84
+ "azurerm",
85
+ "cos",
86
+ "gcs",
87
+ "kubernetes",
88
+ "pg",
89
+ "remote",
90
+ ]);
91
+ const SUPPORTED_LOCKING_BACKENDS = [
92
+ ...ALWAYS_LOCKING_BACKENDS,
93
+ "consul",
94
+ "http",
95
+ "oss",
96
+ "s3",
97
+ ].sort();
98
+ /**
99
+ * Validate the dedicated workspace backend source. Credential-bearing keys
100
+ * and the small set of backend-specific locking switches are policy-critical;
101
+ * every other backend argument stays opaque and is preserved verbatim.
102
+ *
103
+ * This deliberately reuses the ONE hcl2json entry point while bypassing the
104
+ * entity expression grammar: OpenTofu backend configuration may contain
105
+ * init-time `var.*`, `local.*`, and nested backend blocks that are not part of
106
+ * ei's entity dialect. The source is projected byte-for-byte after validation;
107
+ * OpenTofu remains the authority for backend-specific arguments.
108
+ */
109
+ export async function inspectBackendHcl(text) {
110
+ assertNoUnsafeIntegers(text);
111
+ let raw;
112
+ try {
113
+ raw = await parseWithHcl2Json("backend.tf", text);
114
+ }
115
+ catch (e) {
116
+ throw new TfParseError(`backend.tf HCL parse failed: ${e instanceof Error ? e.message : String(e)}`);
117
+ }
118
+ for (const key of Object.keys(raw)) {
119
+ if (!BACKEND_TOP_LEVEL.has(key)) {
120
+ throw new TfParseError(`backend.tf contains unsupported top-level "${key}" content — only terraform, variable, and locals blocks belong in the backend source`);
121
+ }
122
+ }
123
+ const rejectSecretKeys = (node, path = []) => {
124
+ if (Array.isArray(node)) {
125
+ for (const [index, child] of node.entries())
126
+ rejectSecretKeys(child, [...path, String(index)]);
127
+ return;
128
+ }
129
+ if (typeof node !== "object" || node === null)
130
+ return;
131
+ for (const [key, child] of Object.entries(node)) {
132
+ if (BACKEND_SECRET_KEYS.has(key.toLowerCase())) {
133
+ throw new TfParseError(`backend.tf contains credential-bearing "${[...path, key].join(".")}" configuration — ` +
134
+ "backend credentials must come from environment variables or workload identity");
135
+ }
136
+ rejectSecretKeys(child, [...path, key]);
137
+ }
138
+ };
139
+ rejectSecretKeys(raw);
140
+ const declarations = [];
141
+ const terraformBodies = raw["terraform"];
142
+ if (terraformBodies !== undefined && !Array.isArray(terraformBodies)) {
143
+ throw new TfParseError("backend.tf has an unexpected terraform block shape");
144
+ }
145
+ for (const [index, body] of (terraformBodies ?? []).entries()) {
146
+ if (typeof body !== "object" || body === null || Array.isArray(body)) {
147
+ throw new TfParseError(`backend.tf has an unexpected terraform block body at index ${index}`);
148
+ }
149
+ const nested = body["backend"];
150
+ if (nested === undefined)
151
+ continue;
152
+ if (typeof nested !== "object" || nested === null || Array.isArray(nested)) {
153
+ throw new TfParseError(`backend.tf has an unexpected backend declaration shape at terraform block ${index}`);
154
+ }
155
+ for (const [type, bodies] of Object.entries(nested)) {
156
+ if (!Array.isArray(bodies)) {
157
+ throw new TfParseError(`backend.tf has an unexpected backend "${type}" body shape`);
158
+ }
159
+ for (const body of bodies) {
160
+ if (typeof body !== "object" || body === null || Array.isArray(body)) {
161
+ throw new TfParseError(`backend.tf has an unexpected backend "${type}" body shape`);
162
+ }
163
+ declarations.push({ type, body: body });
164
+ }
165
+ }
166
+ }
167
+ if (declarations.length !== 1) {
168
+ throw new TfParseError(`backend.tf must contain exactly one backend declaration; found ${declarations.length}`);
169
+ }
170
+ const declaration = declarations[0];
171
+ assertLockingBackend(declaration.type, declaration.body);
172
+ return { type: declaration.type };
173
+ }
174
+ function assertLockingBackend(type, body) {
175
+ if (ALWAYS_LOCKING_BACKENDS.has(type))
176
+ return;
177
+ if (type === "consul") {
178
+ if (body["lock"] === undefined || body["lock"] === true || body["lock"] === "${true}")
179
+ return;
180
+ throw new TfParseError('backend "consul" must omit lock or set lock = true');
181
+ }
182
+ if (type === "http") {
183
+ if (hasLiteralBackendValue(body, "lock_address") && hasLiteralBackendValue(body, "unlock_address"))
184
+ return;
185
+ throw new TfParseError('backend "http" must configure both lock_address and unlock_address; HTTP state is otherwise unlocked');
186
+ }
187
+ if (type === "oss") {
188
+ if (hasLiteralBackendValue(body, "tablestore_endpoint") &&
189
+ hasLiteralBackendValue(body, "tablestore_table")) {
190
+ return;
191
+ }
192
+ throw new TfParseError('backend "oss" must configure tablestore_endpoint and tablestore_table for state locking');
193
+ }
194
+ if (type === "s3") {
195
+ if (body["use_lockfile"] === true ||
196
+ body["use_lockfile"] === "${true}" ||
197
+ hasLiteralBackendValue(body, "dynamodb_table")) {
198
+ return;
199
+ }
200
+ throw new TfParseError('backend "s3" must set use_lockfile = true or configure dynamodb_table for state locking');
201
+ }
202
+ throw new TfParseError(`backend "${type}" is not accepted because EDK cannot verify state locking; supported locking backends: ` +
203
+ SUPPORTED_LOCKING_BACKENDS.join(", "));
204
+ }
205
+ function hasLiteralBackendValue(body, key) {
206
+ const value = body[key];
207
+ return typeof value === "string" && value !== "" && !value.startsWith("${");
208
+ }
47
209
  export async function parseHcl(text) {
48
210
  assertNoUnsafeIntegers(text);
49
211
  let raw;
@@ -37,8 +37,26 @@ export interface AccessPolicyPrincipalRef {
37
37
  /** The data block's lookup-attr value ("email" for a user, "name" for a group). */
38
38
  readonly value: string;
39
39
  }
40
+ /**
41
+ * FilterAst kinds {@link decodeFilter} can emit — same set as
42
+ * `access-policy/filter.ts` (no consecutiveRange / contains / overlaps).
43
+ * Printer + hoist walker switch on this, not the full automation FilterAst,
44
+ * so an automation-only kind cannot silently grow AP coverage. A new
45
+ * FilterAst kind still fails exhaustiveness here until it is excluded or
46
+ * implemented in decodeFilter + filter.ts.
47
+ */
48
+ export type AccessPolicyFilterAst = Exclude<FilterAst, {
49
+ kind: "and" | "or";
50
+ } | {
51
+ kind: "consecutiveRange";
52
+ } | {
53
+ kind: "contains" | "overlaps";
54
+ }> | {
55
+ kind: "and" | "or";
56
+ children: readonly AccessPolicyFilterAst[];
57
+ };
40
58
  export interface NormalizedAccessPolicy {
41
- readonly filter: FilterAst;
59
+ readonly filter: AccessPolicyFilterAst;
42
60
  readonly userIds?: readonly (string | AccessPolicyPrincipalRef)[];
43
61
  readonly groupIds?: readonly (string | AccessPolicyPrincipalRef)[];
44
62
  /** Always raw platform ids — ei's exporter carries no `elementum_service_account` resource to reference yet. */
@@ -76,12 +76,10 @@ function filterValue(value, owner, where) {
76
76
  throw new EntityTfError(`${where}: unsupported filter value type "${type}"`);
77
77
  }
78
78
  /**
79
- * Decode one `filter` attribute. Coverage matches automation's own
80
- * `decodeFilter` (`entities/automation/from-tf.ts`) — the only proven,
81
- * working filter-grammar round-trip in this codebase — minus the
82
- * trigger/task `left_value.value_reference` branch, which cannot occur here
83
- * (access policies have no trigger/task context to reference; the left side
84
- * is always a `field_id`).
79
+ * Decode one `filter` attribute. Kinds are the {@link AccessPolicyFilterAst}
80
+ * set — `filter.ts` builders plus what ei actually exports. consecutiveRange /
81
+ * contains / overlaps throw here rather than decode into FilterAst nodes the
82
+ * printer cannot author.
85
83
  */
86
84
  function decodeFilter(value, owner, where) {
87
85
  if (!isObject(value) || isTfExpr(value) || typeof value.type !== "string")
@@ -4,11 +4,18 @@
4
4
  * app/element's to-tf drives the pass and supplies the `object_id`
5
5
  * back-reference — this module never names the owner's resource type.
6
6
  *
7
- * Label: `<ownerLabel>_access_policy` for the first entry, `..._access_policy_N`
8
- * (0-indexed, matching ei's own numbering) for later ones — access policies
9
- * have no display name on the platform, so identity is purely positional,
10
- * same discipline as `cmd/elementum/export/imports.go`'s own
11
- * `AppChildResourceName(app, "access_policy"/"access_policy_N")` scheme.
7
+ * Label: apps use `AppChildResourceName` (`apps_<ns>_<ns>_access_policy`);
8
+ * elements use ei's actual export label (`<ns>_access_policy`) — NOT
9
+ * `ElementChildResourceName` (`elements_<ns>_<ns>_access_policy`). ei's
10
+ * element access-policy import/HCL path never took the scoped prefix
11
+ * other element children (fields, list views) use. First entry has no
12
+ * suffix; later ones are `_1`, `_2`, … (0-indexed, matching ei).
13
+ *
14
+ * This pass emits authored entries only. Creating an app/element has a
15
+ * platform side-effect: it mints an extra policy for the creating user
16
+ * (`user_ids = [you]`, typically `filter = { type = "true" }`) that is not
17
+ * in `accessPolicies[]` and must not be synthesized here. Pull sees it;
18
+ * the integration harness strips it for fidelity against authored fixtures.
12
19
  */
13
20
  import type { OrgRefLookup } from "../../engine/build/context.js";
14
21
  import { type ChildResourceScope, type TfBlock, type TfValue } from "../../engine/tf/index.js";
@@ -4,11 +4,18 @@
4
4
  * app/element's to-tf drives the pass and supplies the `object_id`
5
5
  * back-reference — this module never names the owner's resource type.
6
6
  *
7
- * Label: `<ownerLabel>_access_policy` for the first entry, `..._access_policy_N`
8
- * (0-indexed, matching ei's own numbering) for later ones — access policies
9
- * have no display name on the platform, so identity is purely positional,
10
- * same discipline as `cmd/elementum/export/imports.go`'s own
11
- * `AppChildResourceName(app, "access_policy"/"access_policy_N")` scheme.
7
+ * Label: apps use `AppChildResourceName` (`apps_<ns>_<ns>_access_policy`);
8
+ * elements use ei's actual export label (`<ns>_access_policy`) — NOT
9
+ * `ElementChildResourceName` (`elements_<ns>_<ns>_access_policy`). ei's
10
+ * element access-policy import/HCL path never took the scoped prefix
11
+ * other element children (fields, list views) use. First entry has no
12
+ * suffix; later ones are `_1`, `_2`, … (0-indexed, matching ei).
13
+ *
14
+ * This pass emits authored entries only. Creating an app/element has a
15
+ * platform side-effect: it mints an extra policy for the creating user
16
+ * (`user_ids = [you]`, typically `filter = { type = "true" }`) that is not
17
+ * in `accessPolicies[]` and must not be synthesized here. Pull sees it;
18
+ * the integration harness strips it for fidelity against authored fixtures.
12
19
  */
13
20
  import { EntityTfError } from "../../engine/entity.js";
14
21
  import { expr, scopedResourceLabel } from "../../engine/tf/index.js";
@@ -125,9 +132,17 @@ function principalListToTf(items, dataType, where, ctx) {
125
132
  }
126
133
  return values.length > 0 ? values : undefined;
127
134
  }
135
+ function accessPolicyTfLabel(ownerTfLabel, index, scope) {
136
+ const childPart = index === 0 ? "access_policy" : `access_policy_${index}`;
137
+ // ei element export: ElementResourceName + "_access_policy" (imports.go
138
+ // `prefix + "_access_policy"`, hcl_access_policy.go FallbackBaseName).
139
+ if (scope === "element")
140
+ return `${ownerTfLabel}_${childPart}`;
141
+ return scopedResourceLabel(ownerTfLabel, childPart, scope);
142
+ }
128
143
  /** One authored access-policy entry → its resource block, positioned by `index` (0-based) for label numbering. */
129
144
  export function accessPolicyToTf(entry, index, ctx) {
130
- const label = scopedResourceLabel(ctx.ownerTfLabel, index === 0 ? "access_policy" : `access_policy_${index}`, ctx.scope);
145
+ const label = accessPolicyTfLabel(ctx.ownerTfLabel, index, ctx.scope);
131
146
  const where = `accessPolicies[${index}]`;
132
147
  const attrs = {
133
148
  object_id: ctx.objectId,
@@ -70,6 +70,8 @@ export interface AgentV2Options extends EntityDeployOptions {
70
70
  readonly runAs?: AgentToolRunAs;
71
71
  readonly startingActions?: readonly Record<string, unknown>[];
72
72
  readonly a2aStreaming?: boolean;
73
+ /** Enable A2A record creation — when set, allows A2A conversations to create records through this agent. */
74
+ readonly a2aCreateRecordEnabled?: boolean;
73
75
  readonly conversationIdleTimeout?: string;
74
76
  readonly skillAccess?: SkillAccess;
75
77
  readonly agentAuthentication?: AgentAuthentication;
@@ -113,6 +113,7 @@ export function defineAgent(opts) {
113
113
  ...(opts.runAs !== undefined ? { runAs: opts.runAs } : {}),
114
114
  ...(opts.startingActions !== undefined ? { startingActions: opts.startingActions } : {}),
115
115
  ...(opts.a2aStreaming !== undefined ? { a2aStreaming: opts.a2aStreaming } : {}),
116
+ ...(opts.a2aCreateRecordEnabled !== undefined ? { a2aCreateRecordEnabled: opts.a2aCreateRecordEnabled } : {}),
116
117
  ...(opts.conversationIdleTimeout !== undefined
117
118
  ? { conversationIdleTimeout: opts.conversationIdleTimeout }
118
119
  : {}),
@@ -103,6 +103,15 @@ export function printAgentV2(agent, opts) {
103
103
  }
104
104
  if (agent.a2aStreaming !== undefined)
105
105
  lines.push(` a2aStreaming: ${String(agent.a2aStreaming)},`);
106
+ if (agent.a2aCreateRecordEnabled !== undefined)
107
+ lines.push(` a2aCreateRecordEnabled: ${String(agent.a2aCreateRecordEnabled)},`);
108
+ if (agent.a2aSkills !== undefined && agent.a2aSkills.length > 0) {
109
+ lines.push(" a2aSkills: [");
110
+ for (const skill of agent.a2aSkills) {
111
+ lines.push(...printA2ASkill(skill).map((l) => ` ${l}`));
112
+ }
113
+ lines.push(" ],");
114
+ }
106
115
  if (agent.tools.length > 0) {
107
116
  lines.push(" tools: [");
108
117
  for (const tool of agent.tools) {
@@ -205,6 +214,40 @@ function printAgentAuthentication(auth) {
205
214
  lines.push(`},`);
206
215
  return lines;
207
216
  }
217
+ /**
218
+ * One A2A skill → its object-literal lines, same multi-line style `printTool`
219
+ * uses for factory calls — pure metadata (no catalog tokens), same shape
220
+ * `serializeA2ASkill` (build.ts) expects back.
221
+ */
222
+ function printA2ASkill(skill) {
223
+ const lines = ["{"];
224
+ lines.push(` name: ${quote(skill.name)},`);
225
+ lines.push(` description: ${quote(skill.description)},`);
226
+ if (skill.tags !== undefined && skill.tags.length > 0)
227
+ lines.push(` tags: [${skill.tags.map(quote).join(", ")}],`);
228
+ if (skill.examples !== undefined && skill.examples.length > 0)
229
+ lines.push(` examples: [${skill.examples.map(quote).join(", ")}],`);
230
+ if (skill.inputModes !== undefined && skill.inputModes.length > 0)
231
+ lines.push(` inputModes: [${skill.inputModes.map(quote).join(", ")}],`);
232
+ if (skill.outputModes !== undefined && skill.outputModes.length > 0)
233
+ lines.push(` outputModes: [${skill.outputModes.map(quote).join(", ")}],`);
234
+ lines.push("},");
235
+ return lines;
236
+ }
237
+ function fieldOwnerRef(tool, appRefName, foreignAppRefNames, foreignElementRefNames) {
238
+ if (tool.target === undefined || tool.target.kind === "self")
239
+ return { kind: "catalog", expr: `catalog.${appRefName}` };
240
+ if (tool.target.kind === "foreignApp") {
241
+ const foreignRefName = foreignAppRefNames?.get(tool.target.name);
242
+ return foreignRefName !== undefined
243
+ ? { kind: "catalog", expr: `catalog.${foreignRefName}` }
244
+ : { kind: "raw", entityType: "app", name: tool.target.name };
245
+ }
246
+ const foreignRefName = foreignElementRefNames?.get(tool.target.name);
247
+ return foreignRefName !== undefined
248
+ ? { kind: "catalog", expr: `catalog.${foreignRefName}` }
249
+ : { kind: "raw", entityType: "element", name: tool.target.name };
250
+ }
208
251
  function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElementRefNames) {
209
252
  const factory = TOOL_FACTORY_BY_TYPE_KEY[tool.typeKey] ?? "agentSearchAspect";
210
253
  const lines = [`${factory}({`];
@@ -292,6 +335,7 @@ function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElemen
292
335
  lines.push(` table: ${quote(tool.searchTableId)}, // TODO: raw search table id - ei's export never resolves this to a reference`);
293
336
  }
294
337
  if (tool.fields !== undefined && tool.fields.length > 0) {
338
+ const owner = fieldOwnerRef(tool, appRefName, foreignAppRefNames, foreignElementRefNames);
295
339
  lines.push(" fields: [");
296
340
  for (const f of tool.fields) {
297
341
  // A foreign/out-of-scope aspect's field has no field resource ei can
@@ -299,7 +343,17 @@ function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElemen
299
343
  // print the raw-id shape (AgentSearchRawIdField/AgentRecordRawIdField)
300
344
  // instead of a catalog token.
301
345
  const isRaw = f.key === undefined;
302
- const parts = isRaw ? [`fieldId: ${quote(f.rawFieldId ?? "")}`] : [`field: catalog.${appRefName}.fields.${f.key}`];
346
+ // A field always belongs to the tool's TARGET, not necessarily the
347
+ // owning app — `owner` (self/foreign-resolved/foreign-unresolved)
348
+ // mirrors the `aspect:` resolution just above.
349
+ const parts = isRaw
350
+ ? [`fieldId: ${quote(f.rawFieldId ?? "")}`]
351
+ : owner.kind === "catalog"
352
+ ? [`field: ${owner.expr}.fields.${f.key}`]
353
+ : [
354
+ `field: { __kind: "field", refName: ${quote(f.key)}, name: ${quote(f.name ?? f.key)}, fieldType: "TEXT", ` +
355
+ `parent: ${quote(owner.name)}, parentKind: ${quote(owner.entityType)}, parentName: ${quote(owner.name)} }`,
356
+ ];
303
357
  if (f.name !== undefined)
304
358
  parts.push(`name: ${quote(f.name)}`);
305
359
  // Always emit description (backfill "") so pulled source satisfies
@@ -307,7 +361,11 @@ function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElemen
307
361
  parts.push(`description: ${quote(f.description ?? "")}`);
308
362
  if (f.required !== undefined)
309
363
  parts.push(`required: ${f.required}`);
310
- const todo = isRaw ? " // TODO: raw platform field id - the field belongs to a foreign/out-of-scope aspect ei can't resolve to a reference" : "";
364
+ const todo = isRaw
365
+ ? " // TODO: raw platform field id - the field belongs to a foreign/out-of-scope aspect ei can't resolve to a reference"
366
+ : owner.kind === "raw"
367
+ ? ` // TODO: foreign field — type unconfirmed (ei's elementum_field data source doesn't expose it) and refName is a best-effort guess; verify against "${owner.name}"`
368
+ : "";
311
369
  lines.push(` { ${parts.join(", ")} },${todo}`);
312
370
  }
313
371
  lines.push(" ],");
@@ -1,12 +1,14 @@
1
1
  /**
2
2
  * Agent extraction (M3, plan §4.3): `agentFromTf` turns an
3
3
  * `elementum_agent` block + its tool blocks (delegated to
4
- * `entities/agent-tool/from-tf.ts`) into the normalized shape
5
- * `printAgentV2` consumes. Platform ids come only from the stream's import
6
- * blocks and stay data-side — they never reach printed source.
4
+ * `entities/agent-tool/from-tf.ts`) + its a2a-skill blocks (delegated to
5
+ * `entities/agent-a2a-skill/from-tf.ts`, issue #68) into the normalized
6
+ * shape `printAgentV2` consumes. Platform ids come only from the stream's
7
+ * import blocks and stay data-side — they never reach printed source.
7
8
  */
8
9
  import { type FromTfContext } from "../../engine/pull/context.js";
9
10
  import { type TfBlock } from "../../engine/tf/index.js";
11
+ import { type NormalizedA2ASkill } from "../agent-a2a-skill/from-tf.js";
10
12
  import { type NormalizedAgentTool } from "../agent-tool/from-tf.js";
11
13
  import type { AgentAuthentication } from "./build.js";
12
14
  import type { AgentToolRunAs } from "./tools.js";
@@ -50,7 +52,9 @@ export interface NormalizedAgent {
50
52
  readonly agentAuthentication?: AgentAuthentication;
51
53
  readonly conversationIdleTimeout?: string;
52
54
  readonly a2aStreaming?: boolean;
55
+ readonly a2aCreateRecordEnabled?: boolean;
53
56
  readonly tools: readonly NormalizedAgentTool[];
57
+ readonly a2aSkills?: readonly NormalizedA2ASkill[];
54
58
  }
55
59
  export interface AgentFromTfResult {
56
60
  readonly agent?: NormalizedAgent;
@@ -58,8 +62,9 @@ export interface AgentFromTfResult {
58
62
  readonly skippedReason?: string;
59
63
  }
60
64
  /**
61
- * The `elementum_agent` block + its tool blocks → the normalized agent.
62
- * Tool blocks belonging to OTHER agents are skipped with a diagnostic (the
63
- * caller partitions per-agent by agent_id, but stays defensive).
65
+ * The `elementum_agent` block + its tool blocks + its a2a-skill blocks →
66
+ * the normalized agent. Blocks belonging to OTHER agents are skipped with a
67
+ * diagnostic (the caller partitions per-agent by agent_id, but stays
68
+ * defensive).
64
69
  */
65
- export declare function agentFromTf(agentBlock: TfBlock, toolBlocks: readonly TfBlock[], appLabel: string, _appRefName: string, ctx: FromTfContext): AgentFromTfResult;
70
+ export declare function agentFromTf(agentBlock: TfBlock, toolBlocks: readonly TfBlock[], appLabel: string, _appRefName: string, ctx: FromTfContext, a2aSkillBlocks?: readonly TfBlock[]): AgentFromTfResult;