@elementumai/edk 0.11.0 → 0.13.0

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 (222) hide show
  1. package/README.md +40 -6
  2. package/dist-sdk/src/catalog/factories.d.ts +7 -1
  3. package/dist-sdk/src/catalog/factories.js +2 -0
  4. package/dist-sdk/src/catalog/index.d.ts +2 -2
  5. package/dist-sdk/src/catalog/index.js +1 -1
  6. package/dist-sdk/src/catalog/org.js +79 -34
  7. package/dist-sdk/src/catalog/token.js +5 -0
  8. package/dist-sdk/src/catalog/types.d.ts +7 -1
  9. package/dist-sdk/src/catalog/types.js +3 -0
  10. package/dist-sdk/src/core/system-fields.d.ts +1 -1
  11. package/dist-sdk/src/core/system-fields.js +1 -1
  12. package/dist-sdk/src/core/triggers/on-demand.d.ts +2 -0
  13. package/dist-sdk/src/core/triggers/on-demand.js +3 -0
  14. package/dist-sdk/src/core/types/app.d.ts +6 -0
  15. package/dist-sdk/src/engine/build/context.d.ts +3 -0
  16. package/dist-sdk/src/engine/coverage-gaps.d.ts +5 -0
  17. package/dist-sdk/src/engine/coverage-gaps.js +9 -0
  18. package/dist-sdk/src/engine/ei/run.d.ts +20 -1
  19. package/dist-sdk/src/engine/ei/run.js +102 -14
  20. package/dist-sdk/src/engine/pull/authored-address.js +42 -6
  21. package/dist-sdk/src/engine/pull/authored-root.d.ts +88 -0
  22. package/dist-sdk/src/engine/pull/authored-root.js +306 -0
  23. package/dist-sdk/src/engine/pull/context.d.ts +10 -0
  24. package/dist-sdk/src/engine/pull/field-refs-registry.d.ts +114 -0
  25. package/dist-sdk/src/engine/pull/field-refs-registry.js +501 -0
  26. package/dist-sdk/src/engine/pull/org.d.ts +1 -0
  27. package/dist-sdk/src/engine/pull/org.js +2 -0
  28. package/dist-sdk/src/engine/pull/partition.d.ts +8 -0
  29. package/dist-sdk/src/engine/pull/partition.js +43 -0
  30. package/dist-sdk/src/engine/pull/pulled-roots.d.ts +89 -0
  31. package/dist-sdk/src/engine/pull/pulled-roots.js +203 -0
  32. package/dist-sdk/src/engine/pull/ref-only.d.ts +22 -0
  33. package/dist-sdk/src/engine/pull/ref-only.js +59 -1
  34. package/dist-sdk/src/engine/pull/source-resources.d.ts +39 -0
  35. package/dist-sdk/src/engine/pull/source-resources.js +110 -0
  36. package/dist-sdk/src/engine/pull/stream-root.d.ts +148 -0
  37. package/dist-sdk/src/engine/pull/stream-root.js +563 -0
  38. package/dist-sdk/src/engine/workspace/reserved-catalog-keys.d.ts +47 -0
  39. package/dist-sdk/src/engine/workspace/reserved-catalog-keys.js +115 -0
  40. package/dist-sdk/src/entities/access-policy/build.d.ts +2 -1
  41. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +9 -1
  42. package/dist-sdk/src/entities/access-policy/from-tf.js +25 -4
  43. package/dist-sdk/src/entities/access-policy/module.js +5 -0
  44. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +19 -0
  45. package/dist-sdk/src/entities/access-policy/to-tf.js +65 -8
  46. package/dist-sdk/src/entities/agent/build.d.ts +52 -1
  47. package/dist-sdk/src/entities/agent/build.js +34 -0
  48. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +68 -0
  49. package/dist-sdk/src/entities/agent/from-tf.d.ts +34 -1
  50. package/dist-sdk/src/entities/agent/from-tf.js +262 -2
  51. package/dist-sdk/src/entities/agent/index.d.ts +1 -1
  52. package/dist-sdk/src/entities/agent/to-tf.d.ts +8 -10
  53. package/dist-sdk/src/entities/agent/to-tf.js +158 -14
  54. package/dist-sdk/src/entities/agent-tool/from-tf.js +6 -0
  55. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
  56. package/dist-sdk/src/entities/agent-tool/to-tf.js +2 -2
  57. package/dist-sdk/src/entities/app/build.d.ts +34 -14
  58. package/dist-sdk/src/entities/app/build.js +93 -16
  59. package/dist-sdk/src/entities/app/from-tf.js +25 -11
  60. package/dist-sdk/src/entities/app/index.d.ts +1 -0
  61. package/dist-sdk/src/entities/app/index.js +1 -0
  62. package/dist-sdk/src/entities/app/module.js +1 -0
  63. package/dist-sdk/src/entities/app/stage-keys.d.ts +20 -5
  64. package/dist-sdk/src/entities/app/stage-keys.js +43 -9
  65. package/dist-sdk/src/entities/app/to-tf.js +2 -0
  66. package/dist-sdk/src/entities/approval-chain/build.d.ts +46 -11
  67. package/dist-sdk/src/entities/approval-chain/build.js +120 -8
  68. package/dist-sdk/src/entities/approval-chain/from-tf.d.ts +24 -2
  69. package/dist-sdk/src/entities/approval-chain/from-tf.js +148 -6
  70. package/dist-sdk/src/entities/approval-chain/index.d.ts +4 -1
  71. package/dist-sdk/src/entities/approval-chain/index.js +4 -1
  72. package/dist-sdk/src/entities/approval-chain/module.js +23 -5
  73. package/dist-sdk/src/entities/approval-chain/printer.d.ts +1 -1
  74. package/dist-sdk/src/entities/approval-chain/printer.js +91 -5
  75. package/dist-sdk/src/entities/approval-chain/steps-tf.d.ts +77 -0
  76. package/dist-sdk/src/entities/approval-chain/steps-tf.js +255 -0
  77. package/dist-sdk/src/entities/approval-chain/steps.d.ts +71 -0
  78. package/dist-sdk/src/entities/approval-chain/steps.js +83 -0
  79. package/dist-sdk/src/entities/approval-chain/to-tf.d.ts +16 -6
  80. package/dist-sdk/src/entities/approval-chain/to-tf.js +37 -4
  81. package/dist-sdk/src/entities/automation/build.d.ts +50 -24
  82. package/dist-sdk/src/entities/automation/build.js +86 -33
  83. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +52 -8
  84. package/dist-sdk/src/entities/automation/from-tf.d.ts +38 -6
  85. package/dist-sdk/src/entities/automation/from-tf.js +855 -157
  86. package/dist-sdk/src/entities/automation/index.d.ts +2 -1
  87. package/dist-sdk/src/entities/automation/index.js +1 -0
  88. package/dist-sdk/src/entities/automation/module.d.ts +4 -3
  89. package/dist-sdk/src/entities/automation/module.js +33 -12
  90. package/dist-sdk/src/entities/automation/refs-read.d.ts +19 -0
  91. package/dist-sdk/src/entities/automation/refs-read.js +48 -0
  92. package/dist-sdk/src/entities/automation/run-target.d.ts +2 -0
  93. package/dist-sdk/src/entities/automation/run-target.js +5 -0
  94. package/dist-sdk/src/entities/automation/script-code.d.ts +2 -1
  95. package/dist-sdk/src/entities/automation/script-code.js +82 -1
  96. package/dist-sdk/src/entities/automation/script-lint.d.ts +13 -0
  97. package/dist-sdk/src/entities/automation/script-lint.js +418 -0
  98. package/dist-sdk/src/entities/automation/slack-message-refs.d.ts +9 -0
  99. package/dist-sdk/src/entities/automation/slack-message-refs.js +75 -0
  100. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +12 -1
  101. package/dist-sdk/src/entities/automation/task-output-labels.js +32 -1
  102. package/dist-sdk/src/entities/automation/tasks.d.ts +76 -18
  103. package/dist-sdk/src/entities/automation/tasks.js +52 -15
  104. package/dist-sdk/src/entities/automation/to-tf.d.ts +3 -0
  105. package/dist-sdk/src/entities/automation/to-tf.js +585 -97
  106. package/dist-sdk/src/entities/automation/triggers.d.ts +48 -23
  107. package/dist-sdk/src/entities/automation/triggers.js +27 -12
  108. package/dist-sdk/src/entities/automation/unsafe-script-output.d.ts +50 -0
  109. package/dist-sdk/src/entities/automation/unsafe-script-output.js +92 -0
  110. package/dist-sdk/src/entities/chart/build.d.ts +18 -2
  111. package/dist-sdk/src/entities/chart/from-tf.d.ts +2 -2
  112. package/dist-sdk/src/entities/chart/from-tf.js +28 -1
  113. package/dist-sdk/src/entities/chart/index.d.ts +1 -1
  114. package/dist-sdk/src/entities/chart/printer.js +5 -2
  115. package/dist-sdk/src/entities/chart/to-tf.js +38 -3
  116. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +3 -0
  117. package/dist-sdk/src/entities/dynamic-layout/condition-keys.d.ts +48 -0
  118. package/dist-sdk/src/entities/dynamic-layout/condition-keys.js +261 -0
  119. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +45 -6
  120. package/dist-sdk/src/entities/dynamic-layout/module.js +2 -1
  121. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +46 -12
  122. package/dist-sdk/src/entities/element/audit-field-guard.d.ts +9 -0
  123. package/dist-sdk/src/entities/element/audit-field-guard.js +88 -0
  124. package/dist-sdk/src/entities/element/build.js +2 -1
  125. package/dist-sdk/src/entities/element/from-tf.js +15 -2
  126. package/dist-sdk/src/entities/element/module.js +3 -0
  127. package/dist-sdk/src/entities/element/system-fields.d.ts +13 -0
  128. package/dist-sdk/src/entities/element/system-fields.js +23 -0
  129. package/dist-sdk/src/entities/element/to-tf.js +2 -0
  130. package/dist-sdk/src/entities/field/build.d.ts +9 -0
  131. package/dist-sdk/src/entities/field/from-tf.d.ts +29 -1
  132. package/dist-sdk/src/entities/field/from-tf.js +99 -6
  133. package/dist-sdk/src/entities/field/module.js +12 -2
  134. package/dist-sdk/src/entities/field/to-tf.d.ts +13 -3
  135. package/dist-sdk/src/entities/field/to-tf.js +90 -46
  136. package/dist-sdk/src/entities/org/category.js +1 -0
  137. package/dist-sdk/src/entities/org/index.d.ts +1 -0
  138. package/dist-sdk/src/entities/org/index.js +1 -0
  139. package/dist-sdk/src/entities/org/role.js +5 -0
  140. package/dist-sdk/src/entities/org/voice-auth.d.ts +5 -0
  141. package/dist-sdk/src/entities/org/voice-auth.js +33 -0
  142. package/dist-sdk/src/entities/organization/build.d.ts +3 -0
  143. package/dist-sdk/src/entities/organization/build.js +2 -0
  144. package/dist-sdk/src/entities/organization/index.d.ts +1 -0
  145. package/dist-sdk/src/entities/organization/index.js +1 -0
  146. package/dist-sdk/src/entities/organization/to-tf.d.ts +2 -0
  147. package/dist-sdk/src/entities/organization/to-tf.js +59 -1
  148. package/dist-sdk/src/entities/organization/voice-auth.d.ts +60 -0
  149. package/dist-sdk/src/entities/organization/voice-auth.js +60 -0
  150. package/dist-sdk/src/entities/phone-service/build.d.ts +9 -1
  151. package/dist-sdk/src/entities/phone-service/build.js +1 -0
  152. package/dist-sdk/src/entities/phone-service/deserializer/print-phone-service.js +3 -0
  153. package/dist-sdk/src/entities/phone-service/from-tf.d.ts +1 -0
  154. package/dist-sdk/src/entities/phone-service/from-tf.js +8 -1
  155. package/dist-sdk/src/entities/phone-service/to-tf.js +16 -0
  156. package/dist-sdk/src/entities/record-create-form/from-tf.js +2 -2
  157. package/dist-sdk/src/entities/relationship/from-tf.js +7 -2
  158. package/dist-sdk/src/entities/relationship/module.js +2 -2
  159. package/dist-sdk/src/entities/relationship/pair-check.d.ts +6 -2
  160. package/dist-sdk/src/entities/relationship/pair-check.js +105 -18
  161. package/dist-sdk/src/entities/relationship/to-tf.js +5 -2
  162. package/dist-sdk/src/entities/role/permission-levels.d.ts +7 -0
  163. package/dist-sdk/src/entities/role/permission-levels.js +78 -0
  164. package/dist-sdk/src/entities/role/to-tf.js +32 -2
  165. package/dist-sdk/src/entities/service-account/module.d.ts +2 -1
  166. package/dist-sdk/src/entities/service-account/module.js +9 -1
  167. package/dist-sdk/src/entities/service-account/resource-type.d.ts +2 -0
  168. package/dist-sdk/src/entities/service-account/resource-type.js +2 -0
  169. package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +5 -5
  170. package/dist-sdk/src/entities/service-account/role-fidelity.js +21 -13
  171. package/dist-sdk/src/entities/service-account/role-membership-check.d.ts +20 -0
  172. package/dist-sdk/src/entities/service-account/role-membership-check.js +80 -0
  173. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +15 -0
  174. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +36 -0
  175. package/dist-sdk/src/entities/shared/filters/ast.d.ts +4 -0
  176. package/dist-sdk/src/entities/shared/filters/index.d.ts +85 -14
  177. package/dist-sdk/src/entities/shared/filters/index.js +18 -6
  178. package/dist-sdk/src/entities/shared/filters/option-lookups.d.ts +57 -0
  179. package/dist-sdk/src/entities/shared/filters/option-lookups.js +108 -0
  180. package/dist-sdk/src/entities/shared/filters/print.js +9 -5
  181. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +12 -7
  182. package/dist-sdk/src/entities/shared/filters/tf-codec.js +9 -5
  183. package/dist-sdk/src/entities/shared/raw-option-id.d.ts +30 -0
  184. package/dist-sdk/src/entities/shared/raw-option-id.js +41 -0
  185. package/dist-sdk/src/entities/shared/tool-field-ref.js +6 -2
  186. package/dist-sdk/src/entities/shared/types/field-types.d.ts +6 -3
  187. package/dist-sdk/src/entities/shared/types/field-types.js +3 -1
  188. package/dist-sdk/src/entities/skill/input-coverage.js +5 -2
  189. package/dist-sdk/src/entities/skill/module.js +2 -0
  190. package/dist-sdk/src/entities/sla/build.d.ts +96 -0
  191. package/dist-sdk/src/entities/sla/build.js +124 -0
  192. package/dist-sdk/src/entities/sla/from-tf.d.ts +40 -0
  193. package/dist-sdk/src/entities/sla/from-tf.js +164 -0
  194. package/dist-sdk/src/entities/sla/index.d.ts +1 -0
  195. package/dist-sdk/src/entities/sla/index.js +1 -0
  196. package/dist-sdk/src/entities/sla/module.d.ts +4 -0
  197. package/dist-sdk/src/entities/sla/module.js +73 -0
  198. package/dist-sdk/src/entities/sla/printer.d.ts +2 -0
  199. package/dist-sdk/src/entities/sla/printer.js +84 -0
  200. package/dist-sdk/src/entities/sla/to-tf.d.ts +12 -0
  201. package/dist-sdk/src/entities/sla/to-tf.js +81 -0
  202. package/dist-sdk/src/entities/table/build.d.ts +7 -2
  203. package/dist-sdk/src/entities/table/build.js +22 -1
  204. package/dist-sdk/src/entities/table/deserializer/normalize.d.ts +4 -1
  205. package/dist-sdk/src/entities/table/from-tf.js +89 -14
  206. package/dist-sdk/src/entities/table/index.d.ts +1 -1
  207. package/dist-sdk/src/entities/table/to-tf.js +41 -2
  208. package/dist-sdk/src/entities/task/from-tf.js +2 -1
  209. package/dist-sdk/src/entities/task/to-tf.js +1 -0
  210. package/dist-sdk/src/entities/view/from-tf.d.ts +8 -4
  211. package/dist-sdk/src/entities/view/from-tf.js +10 -9
  212. package/dist-sdk/src/entities/view/module.js +5 -0
  213. package/dist-sdk/src/entities/widget/from-tf.js +15 -4
  214. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +51 -4
  215. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  216. package/dist-sdk/src/graph/index.d.ts +20 -2
  217. package/dist-sdk/src/graph/index.js +19 -0
  218. package/dist-sdk/src/graph/modules.js +11 -1
  219. package/dist-sdk/src/graph/resource-types.d.ts +47 -0
  220. package/dist-sdk/src/graph/resource-types.js +62 -0
  221. package/dist-sdk/src/graph/types.d.ts +116 -6
  222. package/package.json +6 -3
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Generic stream partition: terraform resource blocks → buckets by entity
3
+ * kind, using the registry's TYPE_TO_KIND + matchType. Unknown types and
4
+ * known-but-unimplemented subtypes are reported, never silently dropped.
5
+ */
6
+ import { matchResourceType } from "../../graph/index.js";
7
+ export function partitionStream(doc) {
8
+ const byKind = new Map();
9
+ const familyByKind = new Map();
10
+ const reported = [];
11
+ const unknown = [];
12
+ const allResources = [];
13
+ const push = (map, kind, block) => {
14
+ const list = map.get(kind);
15
+ if (list !== undefined)
16
+ list.push(block);
17
+ else
18
+ map.set(kind, [block]);
19
+ };
20
+ for (const block of doc.blocks) {
21
+ if (block.kind !== "resource")
22
+ continue;
23
+ allResources.push(block);
24
+ const type = block.type ?? "";
25
+ const hit = matchResourceType(type);
26
+ if (hit === undefined) {
27
+ unknown.push(`${type}.${block.label ?? "?"}`);
28
+ continue;
29
+ }
30
+ switch (hit.match) {
31
+ case "extract":
32
+ push(byKind, hit.module.kind, block);
33
+ break;
34
+ case "family":
35
+ push(familyByKind, hit.module.kind, block);
36
+ break;
37
+ case "reported":
38
+ reported.push(`${type}.${block.label ?? "?"}`);
39
+ break;
40
+ }
41
+ }
42
+ return { byKind, familyByKind, reported, unknown, allResources, allBlocks: doc.blocks };
43
+ }
@@ -0,0 +1,89 @@
1
+ /** What a pull wrote to a root's own file (edk#2430). */
2
+ interface PulledSource {
3
+ readonly sha256: string;
4
+ /** ISO time of the pull. */
5
+ readonly pulledAt: string;
6
+ /** The pull run that wrote it; roots one run wrote are the same age however far apart their times are. */
7
+ readonly pullRun?: string;
8
+ /**
9
+ * Hash of each compared group (a relationship pair) built from exactly this text, keyed by group; set by
10
+ * whole-workspace builds that see the file unchanged.
11
+ */
12
+ readonly compared?: Readonly<Record<string, string>>;
13
+ }
14
+ interface PulledAge {
15
+ readonly pulledAt: string;
16
+ readonly pullRun?: string;
17
+ }
18
+ /**
19
+ * A root's compared group (one relationship pair) against its last pull on this machine:
20
+ * - `unchecked`: this build doesn't compare (smart apply's build of the starting commit).
21
+ * - `unreadable`: the pull record or the root file couldn't be read, so it isn't known.
22
+ * - `unrecorded`: no pull on this machine recorded the root.
23
+ * - `unchanged` / `edited`: the group's blocks match, or don't, what was pulled. `fileEdited` says an
24
+ * unchanged group's file was still edited elsewhere.
25
+ * - `unknown`: the file was edited and no build recorded this group as pulled, so whether the edit
26
+ * touched it isn't known.
27
+ */
28
+ export type PulledSourceStatus = {
29
+ readonly state: "unchecked";
30
+ } | {
31
+ readonly state: "unreadable";
32
+ readonly what: "record" | "file";
33
+ } | {
34
+ readonly state: "unrecorded";
35
+ } | (PulledAge & {
36
+ readonly state: "unchanged";
37
+ readonly fileEdited: boolean;
38
+ }) | (PulledAge & {
39
+ readonly state: "edited" | "unknown";
40
+ });
41
+ /**
42
+ * Record that `elementum pull <kind> <refName>` just wrote this root's own file. With `source`, also record
43
+ * what it wrote. `markPulled: false` records only the source, for a file a pull writes as a dependency without
44
+ * that counting as pulling the root.
45
+ */
46
+ export declare function recordPulledRoot(orgRoot: string, kind: string, refName: string, source?: string, options?: {
47
+ readonly markPulled?: boolean;
48
+ }): Promise<void>;
49
+ /** One root's pull record, as {@link readPulledRootRecord} reads it and {@link restorePulledRootRecord} puts it back. */
50
+ export interface PulledRootRecord {
51
+ readonly pulled: boolean;
52
+ readonly source?: PulledSource;
53
+ }
54
+ /**
55
+ * This root's pull record before a pull rewrites it, so a pull that restores the root's source after a failed
56
+ * adoption can restore the record too (edk#2628). `undefined` when the record can't be read.
57
+ */
58
+ export declare function readPulledRootRecord(orgRoot: string, kind: string, refName: string): Promise<PulledRootRecord | undefined>;
59
+ /** Put back a record {@link readPulledRootRecord} read. */
60
+ export declare function restorePulledRootRecord(orgRoot: string, kind: string, refName: string, record: PulledRootRecord): Promise<void>;
61
+ /** Was this root's own file actually written by a real pull, not just cloned/hand-authored? */
62
+ export declare function wasRootPulled(orgRoot: string, kind: string, refName: string): Promise<boolean>;
63
+ export interface PulledSourceInput {
64
+ readonly kind: string;
65
+ readonly refName: string;
66
+ /** The root file's text, or `undefined` when it couldn't be read. */
67
+ readonly source: string | undefined;
68
+ /** A stable hash of each compared group the root builds now, keyed by group. */
69
+ readonly compared: ReadonlyMap<string, string>;
70
+ }
71
+ /** A root against its last pull: `group(key)` is one compared group's status. */
72
+ export interface PulledRootStatus {
73
+ readonly group: (key: string) => PulledSourceStatus;
74
+ }
75
+ /** Pull records aren't compared in this build (smart apply's build of the starting commit). */
76
+ export declare const UNCHECKED_PULL: PulledRootStatus;
77
+ /**
78
+ * Each root's compared groups against what the last pull on this machine wrote. A file that still matches its
79
+ * pull is unchanged throughout; with `record: true` its current group hashes are recorded, so a later edit
80
+ * elsewhere in the file isn't mistaken for a change to them. An edited file is judged per group by those
81
+ * hashes, and a group they don't have (none recorded yet, or a pair that only formed since, such as after
82
+ * the other side was pulled) isn't known.
83
+ */
84
+ export declare function pulledSourceStatuses(orgRoot: string, roots: readonly PulledSourceInput[], options: {
85
+ readonly record: boolean;
86
+ }): Promise<PulledRootStatus[]>;
87
+ /** A stable hash of blocks: key order and block order don't matter. */
88
+ export declare function blocksSha256(blocks: readonly unknown[]): string;
89
+ export {};
@@ -0,0 +1,203 @@
1
+ /**
2
+ * Local, machine-owned record of which stream-root refs (`apps/<ref>`,
3
+ * `elements/<ref>`, `tables/<ref>`, …) this workspace's `elementum pull *`
4
+ * has actually written — distinct from a root file merely *looking* pulled.
5
+ *
6
+ * `printAppV2`/`printElementV2`/etc. stamp the same "Auto-generated by EDK
7
+ * (v2 pull)" header regardless of caller, and `elementum clone app`
8
+ * deliberately reuses those unmodified printers for its own CREATE output
9
+ * while clone is never adopted. So the header text alone can't tell
10
+ * "pulled, adoption may have failed" apart from
11
+ * "freshly cloned, never meant to be adopted." This file is the
12
+ * corroborating, authoring-only signal: only a real pull writes it.
13
+ *
14
+ * No live platform call — one small local JSON file under `.edk-state/`,
15
+ * same locality as `managed-paths.ts`'s own-file tracker. Best-effort: a
16
+ * read/write failure here never blocks the pull or the diagnostic that
17
+ * consumes it.
18
+ *
19
+ * Each record can also carry what the pull wrote, so build can say whether the
20
+ * part of a root that cross-root checks compare (each relationship pair)
21
+ * changed since that pull (edk#2430): a hash of the file text and, once a
22
+ * build has seen the file unchanged, a hash per compared group built from it.
23
+ */
24
+ import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
25
+ import { join, resolve } from "node:path";
26
+ import { createHash, randomUUID } from "node:crypto";
27
+ const MANIFEST_VERSION = 1;
28
+ /** One CLI process is one pull run: roots it records count as pulled together (edk#2430). */
29
+ const PULL_RUN = randomUUID();
30
+ function manifestPath(orgRoot) {
31
+ return join(resolve(orgRoot), ".edk-state", "pulled-roots.json");
32
+ }
33
+ function key(kind, refName) {
34
+ return `${kind}:${refName}`;
35
+ }
36
+ function sha256(text) {
37
+ return createHash("sha256").update(text).digest("hex");
38
+ }
39
+ function isPulledSource(value) {
40
+ const source = value;
41
+ return typeof source?.sha256 === "string" && typeof source.pulledAt === "string" &&
42
+ (source.pullRun === undefined || typeof source.pullRun === "string") &&
43
+ (source.compared === undefined || (typeof source.compared === "object" && source.compared !== null &&
44
+ Object.values(source.compared).every((hash) => typeof hash === "string")));
45
+ }
46
+ async function readManifest(orgRoot) {
47
+ let raw;
48
+ try {
49
+ raw = await readFile(manifestPath(orgRoot), "utf8");
50
+ }
51
+ catch (err) {
52
+ return { entries: new Set(), sources: new Map(), unreadable: err.code !== "ENOENT" };
53
+ }
54
+ try {
55
+ // eslint-disable-next-line no-restricted-syntax -- pulled-roots state is local machine-owned JSON
56
+ const parsed = JSON.parse(raw);
57
+ if (parsed.version !== MANIFEST_VERSION || !Array.isArray(parsed.entries))
58
+ return { entries: new Set(), sources: new Map(), unreadable: true };
59
+ const sources = new Map(Object.entries(parsed.sources ?? {}).filter((entry) => isPulledSource(entry[1])));
60
+ return { entries: new Set(parsed.entries.filter((entry) => typeof entry === "string")), sources, unreadable: false };
61
+ }
62
+ catch {
63
+ return { entries: new Set(), sources: new Map(), unreadable: true };
64
+ }
65
+ }
66
+ async function writeManifest(orgRoot, entries, sources) {
67
+ const path = manifestPath(orgRoot);
68
+ const manifest = {
69
+ version: MANIFEST_VERSION,
70
+ entries: [...entries].sort(),
71
+ ...(sources.size > 0 && { sources: Object.fromEntries([...sources].sort(([a], [b]) => a.localeCompare(b))) }),
72
+ };
73
+ await mkdir(join(resolve(orgRoot), ".edk-state"), { recursive: true });
74
+ const tmpPath = `${path}.tmp-${randomUUID()}`;
75
+ await writeFile(tmpPath, JSON.stringify(manifest, null, 2), "utf8");
76
+ await rename(tmpPath, path);
77
+ }
78
+ let recording = Promise.resolve();
79
+ /** One read-modify-write at a time within this process: a recursive pull writes several roots concurrently. */
80
+ function serialized(update) {
81
+ const run = recording.then(update);
82
+ recording = run.catch(() => undefined);
83
+ return run;
84
+ }
85
+ /**
86
+ * Record that `elementum pull <kind> <refName>` just wrote this root's own file. With `source`, also record
87
+ * what it wrote. `markPulled: false` records only the source, for a file a pull writes as a dependency without
88
+ * that counting as pulling the root.
89
+ */
90
+ export function recordPulledRoot(orgRoot, kind, refName, source, options = {}) {
91
+ return serialized(async () => {
92
+ const { entries, sources } = await readManifest(orgRoot);
93
+ if (options.markPulled !== false)
94
+ entries.add(key(kind, refName));
95
+ if (source !== undefined)
96
+ sources.set(key(kind, refName), { sha256: sha256(source), pulledAt: new Date().toISOString(), pullRun: PULL_RUN });
97
+ await writeManifest(orgRoot, entries, sources);
98
+ });
99
+ }
100
+ /**
101
+ * This root's pull record before a pull rewrites it, so a pull that restores the root's source after a failed
102
+ * adoption can restore the record too (edk#2628). `undefined` when the record can't be read.
103
+ */
104
+ export async function readPulledRootRecord(orgRoot, kind, refName) {
105
+ await recording;
106
+ const { entries, sources, unreadable } = await readManifest(orgRoot);
107
+ if (unreadable)
108
+ return undefined;
109
+ const source = sources.get(key(kind, refName));
110
+ return { pulled: entries.has(key(kind, refName)), ...(source !== undefined && { source }) };
111
+ }
112
+ /** Put back a record {@link readPulledRootRecord} read. */
113
+ export function restorePulledRootRecord(orgRoot, kind, refName, record) {
114
+ return serialized(async () => {
115
+ const { entries, sources } = await readManifest(orgRoot);
116
+ if (record.pulled)
117
+ entries.add(key(kind, refName));
118
+ else
119
+ entries.delete(key(kind, refName));
120
+ if (record.source !== undefined)
121
+ sources.set(key(kind, refName), record.source);
122
+ else
123
+ sources.delete(key(kind, refName));
124
+ await writeManifest(orgRoot, entries, sources);
125
+ });
126
+ }
127
+ /** Was this root's own file actually written by a real pull, not just cloned/hand-authored? */
128
+ export async function wasRootPulled(orgRoot, kind, refName) {
129
+ const { entries } = await readManifest(orgRoot);
130
+ return entries.has(key(kind, refName));
131
+ }
132
+ function rootWide(status) {
133
+ return { group: () => status };
134
+ }
135
+ /** Pull records aren't compared in this build (smart apply's build of the starting commit). */
136
+ export const UNCHECKED_PULL = rootWide({ state: "unchecked" });
137
+ /**
138
+ * Each root's compared groups against what the last pull on this machine wrote. A file that still matches its
139
+ * pull is unchanged throughout; with `record: true` its current group hashes are recorded, so a later edit
140
+ * elsewhere in the file isn't mistaken for a change to them. An edited file is judged per group by those
141
+ * hashes, and a group they don't have (none recorded yet, or a pair that only formed since, such as after
142
+ * the other side was pulled) isn't known.
143
+ */
144
+ export async function pulledSourceStatuses(orgRoot, roots, options) {
145
+ const { sources, unreadable } = await readManifest(orgRoot);
146
+ if (unreadable)
147
+ return roots.map(() => rootWide({ state: "unreadable", what: "record" }));
148
+ const backfill = new Map();
149
+ const statuses = roots.map((root) => {
150
+ const pulled = sources.get(key(root.kind, root.refName));
151
+ if (pulled === undefined)
152
+ return rootWide({ state: "unrecorded" });
153
+ const age = { pulledAt: pulled.pulledAt, ...(pulled.pullRun !== undefined && { pullRun: pulled.pullRun }) };
154
+ const fileEdited = root.source === undefined ? undefined : sha256(root.source) !== pulled.sha256;
155
+ if (fileEdited === false) {
156
+ const compared = Object.fromEntries([...root.compared].sort(([a], [b]) => a.localeCompare(b)));
157
+ if (JSON.stringify(compared) !== JSON.stringify(pulled.compared ?? null))
158
+ backfill.set(key(root.kind, root.refName), { sha256: pulled.sha256, compared });
159
+ return rootWide({ ...age, state: "unchanged", fileEdited: false });
160
+ }
161
+ const recorded = pulled.compared ?? {};
162
+ return {
163
+ group: (group) => {
164
+ if (!Object.hasOwn(recorded, group))
165
+ return fileEdited === undefined ? { state: "unreadable", what: "file" } : { ...age, state: "unknown" };
166
+ return root.compared.get(group) === recorded[group]
167
+ ? { ...age, state: "unchanged", fileEdited: fileEdited === true }
168
+ : { ...age, state: "edited" };
169
+ },
170
+ };
171
+ });
172
+ if (options.record && backfill.size > 0) {
173
+ // Best-effort, and only onto the record it was computed from: a pull that rewrote the file since wins.
174
+ await serialized(async () => {
175
+ const current = await readManifest(orgRoot);
176
+ if (current.unreadable)
177
+ return;
178
+ let changed = false;
179
+ for (const [rootKey, seen] of backfill) {
180
+ const record = current.sources.get(rootKey);
181
+ if (record === undefined || record.sha256 !== seen.sha256)
182
+ continue;
183
+ current.sources.set(rootKey, { ...record, compared: seen.compared });
184
+ changed = true;
185
+ }
186
+ if (changed)
187
+ await writeManifest(orgRoot, current.entries, current.sources);
188
+ }).catch(() => undefined);
189
+ }
190
+ return statuses;
191
+ }
192
+ /** A stable hash of blocks: key order and block order don't matter. */
193
+ export function blocksSha256(blocks) {
194
+ const canonical = (value) => {
195
+ if (Array.isArray(value))
196
+ return value.map(canonical);
197
+ if (value !== null && typeof value === "object") {
198
+ return Object.fromEntries(Object.entries(value).filter(([, v]) => v !== undefined).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)).map(([k, v]) => [k, canonical(v)]));
199
+ }
200
+ return value;
201
+ };
202
+ return sha256(JSON.stringify(blocks.map((block) => JSON.stringify(canonical(block))).sort()));
203
+ }
@@ -57,4 +57,26 @@ export declare function fieldDataReferenceMap(doc: TfDocument, roots: readonly D
57
57
  readonly fieldKey: string;
58
58
  readonly fieldName?: string;
59
59
  readonly fieldType?: string;
60
+ /** Static option labels from the ref-only catalog. Absent for a record-sourced Dropdown. */
61
+ readonly options?: readonly string[];
62
+ /** The platform Stage system field, from its semantic tag, not from a picklist type. */
63
+ readonly systemStage?: true;
60
64
  }>;
65
+ /** A field identity an earlier pull recorded for a managed app or element. */
66
+ export interface ManagedFieldNameIdentity {
67
+ readonly ownerRefName: string;
68
+ readonly fieldKey: string;
69
+ readonly fieldName?: string;
70
+ }
71
+ /**
72
+ * Point a managed root's ref-only fields at the keys its source authors.
73
+ *
74
+ * The export keys a field by its current display name. A managed root keeps
75
+ * the authored key across a UI rename, and build addresses that key. A
76
+ * system-tagged field already carries its canonical key (`title`, `id`, …),
77
+ * which a display-name lookup must not replace. A display name that belongs
78
+ * to more than one field on that owner is left on the export key: the name
79
+ * index is last-write-wins and would otherwise stamp one survivor onto both.
80
+ * `refOnly:` guesses are not identities, so they do not count.
81
+ */
82
+ export declare function withManagedRefOnlyIdentity<T extends DirectReferenceRoot>(root: T, managedRefName: string, fieldRefsById: ReadonlyMap<string, ManagedFieldNameIdentity> | undefined): T;
@@ -186,7 +186,11 @@ function parseUnresolved(payload) {
186
186
  const kind = stringAt(obj, "kind", "Kind") ?? "unknown";
187
187
  const uuid = stringAt(obj, "uuid", "UUID");
188
188
  const reason = stringAt(obj, "reason", "Reason") ?? "metadata lookup failed";
189
- return uuid === undefined ? undefined : { usage, kind, uuid, reason, portability: "source-org-only" };
189
+ const table = stringAt(obj, "table", "Table");
190
+ const ownerless = obj["ownerless"] === true || obj["Ownerless"] === true;
191
+ return uuid === undefined
192
+ ? undefined
193
+ : { usage, kind, uuid, reason, portability: "source-org-only", ...(ownerless ? { ownerless } : {}), ...(table !== undefined ? { table } : {}) };
190
194
  }
191
195
  /** Reads bridge-owned, ID-free reference metadata without knowing provider resource names. */
192
196
  export function readRefOnlyMetadata(doc) {
@@ -279,7 +283,61 @@ export function fieldDataReferenceMap(doc, roots) {
279
283
  fieldKey: field.refName,
280
284
  fieldName: field.name,
281
285
  fieldType: field.fieldType,
286
+ ...(field.options !== undefined && field.options.length > 0 ? { options: field.options } : {}),
287
+ ...(systemFieldTag(field) === "STAGE" ? { systemStage: true } : {}),
282
288
  });
283
289
  }
284
290
  return out;
285
291
  }
292
+ /**
293
+ * Point a managed root's ref-only fields at the keys its source authors.
294
+ *
295
+ * The export keys a field by its current display name. A managed root keeps
296
+ * the authored key across a UI rename, and build addresses that key. A
297
+ * system-tagged field already carries its canonical key (`title`, `id`, …),
298
+ * which a display-name lookup must not replace. A display name that belongs
299
+ * to more than one field on that owner is left on the export key: the name
300
+ * index is last-write-wins and would otherwise stamp one survivor onto both.
301
+ * `refOnly:` guesses are not identities, so they do not count.
302
+ */
303
+ export function withManagedRefOnlyIdentity(root, managedRefName, fieldRefsById) {
304
+ const authoredKeyByName = uniqueAuthoredFieldKeys(fieldRefsById, managedRefName);
305
+ return {
306
+ ...root,
307
+ refName: managedRefName,
308
+ fields: root.fields.map((field) => {
309
+ const authoredKey = systemFieldTag(field) === undefined
310
+ ? authoredKeyByName.get(field.name.toLowerCase())
311
+ : undefined;
312
+ return {
313
+ ...field,
314
+ parent: managedRefName,
315
+ ...(authoredKey !== undefined ? { refName: authoredKey } : {}),
316
+ };
317
+ }),
318
+ };
319
+ }
320
+ function uniqueAuthoredFieldKeys(fieldRefsById, ownerRefName) {
321
+ const counts = new Map();
322
+ const keys = new Map();
323
+ if (fieldRefsById === undefined)
324
+ return keys;
325
+ for (const [id, identity] of fieldRefsById) {
326
+ if (id.startsWith("refOnly:"))
327
+ continue;
328
+ if (identity.ownerRefName !== ownerRefName)
329
+ continue;
330
+ const name = identity.fieldName;
331
+ if (name === undefined || name === "")
332
+ continue;
333
+ const lower = name.toLowerCase();
334
+ counts.set(lower, (counts.get(lower) ?? 0) + 1);
335
+ if (!keys.has(lower))
336
+ keys.set(lower, identity.fieldKey);
337
+ }
338
+ for (const [lower, count] of counts) {
339
+ if (count !== 1)
340
+ keys.delete(lower);
341
+ }
342
+ return keys;
343
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Which of a stream's resources stay in source after this pull (#1877), one
3
+ * resource at a time, from what the pull actually extracted:
4
+ *
5
+ * - The stream root stays.
6
+ * - An own-file entity's resources (an automation and its trigger, tasks and
7
+ * publish) stay when their kind is extracted by this root and pull did not
8
+ * skip them. Skipped ones stay only while their authored file is kept (the
9
+ * own-file sweep is off while a sibling is skipped, #1731 SF3), so build
10
+ * still emits the earlier file. The extractor names that file
11
+ * (`skippedOwnFiles`); otherwise an entity's own resource is matched by its
12
+ * label, and a skipped family member with no named file is gone. A kind
13
+ * this root never extracts (a skill or agent in an element export) is never
14
+ * printed.
15
+ * - An inline resource (a skill tool, an agent tool, a layout) stays when pull
16
+ * did not skip it and the parent it references stays.
17
+ *
18
+ * A type no kind claims, or an inline resource with no parent in the stream,
19
+ * counts as staying, so callers keep files rather than break build.
20
+ */
21
+ import { type EntityKindId, type StreamPartition } from "../../graph/index.js";
22
+ export interface SourceResourcesInput {
23
+ readonly stream: StreamPartition;
24
+ readonly rootKind: EntityKindId;
25
+ /** The stream root's own label, the scope own-file ref names derive from. */
26
+ readonly rootLabel: string;
27
+ /** Own-file kinds this root extracted (`ownFileByKind` keys), items or not. */
28
+ readonly extractedKinds: ReadonlySet<EntityKindId>;
29
+ /** Every address pull skipped, after #1731's dependents are dropped. */
30
+ readonly skipped: ReadonlySet<string>;
31
+ /** Skipped address → the own-file entity it belongs to, from `skippedOwnFiles`. */
32
+ readonly skippedOwners: ReadonlyMap<string, {
33
+ readonly kind: EntityKindId;
34
+ readonly refName: string;
35
+ }>;
36
+ /** Whether a skipped own-file entity's authored file is kept. Undefined: assume it is. */
37
+ readonly keptOwnFile?: (kind: EntityKindId, refName: string) => boolean;
38
+ }
39
+ export declare function resourcesInSource(input: SourceResourcesInput): (address: string) => boolean;
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Which of a stream's resources stay in source after this pull (#1877), one
3
+ * resource at a time, from what the pull actually extracted:
4
+ *
5
+ * - The stream root stays.
6
+ * - An own-file entity's resources (an automation and its trigger, tasks and
7
+ * publish) stay when their kind is extracted by this root and pull did not
8
+ * skip them. Skipped ones stay only while their authored file is kept (the
9
+ * own-file sweep is off while a sibling is skipped, #1731 SF3), so build
10
+ * still emits the earlier file. The extractor names that file
11
+ * (`skippedOwnFiles`); otherwise an entity's own resource is matched by its
12
+ * label, and a skipped family member with no named file is gone. A kind
13
+ * this root never extracts (a skill or agent in an element export) is never
14
+ * printed.
15
+ * - An inline resource (a skill tool, an agent tool, a layout) stays when pull
16
+ * did not skip it and the parent it references stays.
17
+ *
18
+ * A type no kind claims, or an inline resource with no parent in the stream,
19
+ * counts as staying, so callers keep files rather than break build.
20
+ */
21
+ import { matchResourceType } from "../../graph/index.js";
22
+ import { scopedLabelToBagKey } from "../tf/index.js";
23
+ export function resourcesInSource(input) {
24
+ const { stream, rootKind, rootLabel, extractedKinds, skipped, skippedOwners, keptOwnFile } = input;
25
+ const blocks = new Map();
26
+ for (const block of stream.allResources) {
27
+ if (block.type !== undefined && block.label !== undefined)
28
+ blocks.set(`${block.type}.${block.label}`, block);
29
+ }
30
+ const memo = new Map();
31
+ const stays = (address) => {
32
+ const known = memo.get(address);
33
+ if (known !== undefined)
34
+ return known;
35
+ // A reference cycle resolves to staying, the cautious answer.
36
+ memo.set(address, true);
37
+ const result = decide(address);
38
+ memo.set(address, result);
39
+ return result;
40
+ };
41
+ const decide = (address) => {
42
+ const block = blocks.get(address);
43
+ const hit = block?.type === undefined ? undefined : matchResourceType(block.type);
44
+ if (block === undefined || hit === undefined)
45
+ return true;
46
+ const kind = hit.module.kind;
47
+ if (kind === rootKind)
48
+ return true;
49
+ // A known type pull does not implement yet is reported, never printed.
50
+ if (hit.match === "reported")
51
+ return false;
52
+ switch (hit.module.authoring.unit) {
53
+ case "ownFile": {
54
+ if (!extractedKinds.has(kind))
55
+ return false;
56
+ if (!skipped.has(address))
57
+ return true;
58
+ const owner = skippedOwners.get(address);
59
+ if (owner !== undefined)
60
+ return keptOwnFile?.(owner.kind, owner.refName) ?? true;
61
+ if (hit.match === "extract") {
62
+ if (keptOwnFile === undefined)
63
+ return true;
64
+ // Kinds scope their ref names differently, so either name's file keeps it.
65
+ const label = block.label ?? "";
66
+ return keptOwnFile(kind, scopedLabelToBagKey(rootLabel, label))
67
+ || (rootKind === "element" && keptOwnFile(kind, scopedLabelToBagKey(rootLabel, label, "element")));
68
+ }
69
+ return false;
70
+ }
71
+ case "inline": {
72
+ if (skipped.has(address))
73
+ return false;
74
+ const parents = new Set(hit.module.parents.map((edge) => edge.parent));
75
+ const parentRefs = referencedAddresses(block).filter((ref) => {
76
+ const type = blocks.get(ref)?.type;
77
+ const refKind = type === undefined ? undefined : matchResourceType(type)?.module.kind;
78
+ return refKind !== undefined && parents.has(refKind);
79
+ });
80
+ return parentRefs.length === 0 || parentRefs.some(stays);
81
+ }
82
+ default:
83
+ return true;
84
+ }
85
+ };
86
+ return stays;
87
+ }
88
+ /** Resource addresses `block` references by source name, ignoring `depends_on`. */
89
+ function referencedAddresses(block) {
90
+ const found = [];
91
+ const walk = (value) => {
92
+ if (Array.isArray(value)) {
93
+ for (const item of value)
94
+ walk(item);
95
+ return;
96
+ }
97
+ if (value === null || typeof value !== "object")
98
+ return;
99
+ const record = value;
100
+ if (record["$expr"] === "resource-attr" && typeof record["type"] === "string" && typeof record["label"] === "string") {
101
+ found.push(`${record["type"]}.${record["label"]}`);
102
+ }
103
+ for (const item of Object.values(record))
104
+ walk(item);
105
+ };
106
+ for (const [key, value] of Object.entries(block.attrs))
107
+ if (key !== "depends_on")
108
+ walk(value);
109
+ return found;
110
+ }