@elementumai/edk 0.12.0 → 0.13.1

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 (224) hide show
  1. package/README.md +8 -2
  2. package/dist-sdk/src/catalog/factories.d.ts +7 -1
  3. package/dist-sdk/src/catalog/factories.js +10 -2
  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 +12 -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/types/app.d.ts +6 -0
  13. package/dist-sdk/src/engine/build/context.d.ts +3 -0
  14. package/dist-sdk/src/engine/coverage-gaps.d.ts +2 -0
  15. package/dist-sdk/src/engine/coverage-gaps.js +4 -0
  16. package/dist-sdk/src/engine/ei/run.d.ts +8 -0
  17. package/dist-sdk/src/engine/ei/run.js +46 -7
  18. package/dist-sdk/src/engine/pull/authored-address.js +42 -6
  19. package/dist-sdk/src/engine/pull/authored-root.d.ts +88 -0
  20. package/dist-sdk/src/engine/pull/authored-root.js +306 -0
  21. package/dist-sdk/src/engine/pull/context.d.ts +34 -0
  22. package/dist-sdk/src/engine/pull/field-refs-registry.d.ts +114 -0
  23. package/dist-sdk/src/engine/pull/field-refs-registry.js +501 -0
  24. package/dist-sdk/src/engine/pull/org.d.ts +1 -0
  25. package/dist-sdk/src/engine/pull/org.js +2 -0
  26. package/dist-sdk/src/engine/pull/partition.d.ts +8 -0
  27. package/dist-sdk/src/engine/pull/partition.js +43 -0
  28. package/dist-sdk/src/engine/pull/pulled-roots.d.ts +89 -0
  29. package/dist-sdk/src/engine/pull/pulled-roots.js +203 -0
  30. package/dist-sdk/src/engine/pull/ref-only.d.ts +4 -0
  31. package/dist-sdk/src/engine/pull/ref-only.js +7 -1
  32. package/dist-sdk/src/engine/pull/source-resources.d.ts +39 -0
  33. package/dist-sdk/src/engine/pull/source-resources.js +110 -0
  34. package/dist-sdk/src/engine/pull/stream-root.d.ts +159 -0
  35. package/dist-sdk/src/engine/pull/stream-root.js +579 -0
  36. package/dist-sdk/src/engine/workspace/authoring-layout.js +16 -2
  37. package/dist-sdk/src/engine/workspace/reserved-catalog-keys.d.ts +47 -0
  38. package/dist-sdk/src/engine/workspace/reserved-catalog-keys.js +115 -0
  39. package/dist-sdk/src/entities/access-policy/build.d.ts +2 -1
  40. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +7 -0
  41. package/dist-sdk/src/entities/access-policy/from-tf.js +17 -5
  42. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +19 -0
  43. package/dist-sdk/src/entities/access-policy/to-tf.js +65 -8
  44. package/dist-sdk/src/entities/agent/build.d.ts +52 -1
  45. package/dist-sdk/src/entities/agent/build.js +34 -0
  46. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +70 -1
  47. package/dist-sdk/src/entities/agent/from-tf.d.ts +36 -1
  48. package/dist-sdk/src/entities/agent/from-tf.js +289 -2
  49. package/dist-sdk/src/entities/agent/index.d.ts +1 -1
  50. package/dist-sdk/src/entities/agent/module.js +1 -0
  51. package/dist-sdk/src/entities/agent/to-tf.d.ts +11 -11
  52. package/dist-sdk/src/entities/agent/to-tf.js +179 -17
  53. package/dist-sdk/src/entities/agent-tool/from-tf.js +6 -0
  54. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
  55. package/dist-sdk/src/entities/agent-tool/to-tf.js +2 -2
  56. package/dist-sdk/src/entities/app/build.d.ts +33 -13
  57. package/dist-sdk/src/entities/app/build.js +14 -12
  58. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -0
  59. package/dist-sdk/src/entities/app/from-tf.js +7 -9
  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 +3 -0
  63. package/dist-sdk/src/entities/app/stage-keys.d.ts +2 -2
  64. package/dist-sdk/src/entities/app/stage-keys.js +3 -3
  65. package/dist-sdk/src/entities/app/to-tf.js +1 -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 +10 -1
  82. package/dist-sdk/src/entities/automation/build.js +70 -27
  83. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +21 -5
  84. package/dist-sdk/src/entities/automation/from-tf.d.ts +26 -5
  85. package/dist-sdk/src/entities/automation/from-tf.js +665 -112
  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 +45 -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/slack-message-refs.d.ts +9 -0
  93. package/dist-sdk/src/entities/automation/slack-message-refs.js +75 -0
  94. package/dist-sdk/src/entities/automation/system-ref-name.d.ts +23 -3
  95. package/dist-sdk/src/entities/automation/system-ref-name.js +86 -4
  96. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +11 -0
  97. package/dist-sdk/src/entities/automation/task-output-labels.js +23 -0
  98. package/dist-sdk/src/entities/automation/tasks.d.ts +29 -4
  99. package/dist-sdk/src/entities/automation/tasks.js +34 -11
  100. package/dist-sdk/src/entities/automation/to-tf.d.ts +8 -1
  101. package/dist-sdk/src/entities/automation/to-tf.js +563 -103
  102. package/dist-sdk/src/entities/automation/triggers.d.ts +0 -8
  103. package/dist-sdk/src/entities/automation/triggers.js +26 -11
  104. package/dist-sdk/src/entities/automation/unsafe-script-output.d.ts +50 -0
  105. package/dist-sdk/src/entities/automation/unsafe-script-output.js +92 -0
  106. package/dist-sdk/src/entities/chart/build.d.ts +9 -1
  107. package/dist-sdk/src/entities/chart/from-tf.js +3 -0
  108. package/dist-sdk/src/entities/chart/to-tf.js +19 -2
  109. package/dist-sdk/src/entities/dashboard/from-tf.d.ts +3 -1
  110. package/dist-sdk/src/entities/dashboard/from-tf.js +42 -2
  111. package/dist-sdk/src/entities/dashboard/to-tf.js +9 -1
  112. package/dist-sdk/src/entities/dashboard-widget-order/module.d.ts +10 -0
  113. package/dist-sdk/src/entities/dashboard-widget-order/module.js +25 -0
  114. package/dist-sdk/src/entities/dashboard-widget-order/order.d.ts +31 -0
  115. package/dist-sdk/src/entities/dashboard-widget-order/order.js +102 -0
  116. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +2 -0
  117. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +44 -5
  118. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +46 -12
  119. package/dist-sdk/src/entities/element/audit-field-guard.d.ts +9 -0
  120. package/dist-sdk/src/entities/element/audit-field-guard.js +88 -0
  121. package/dist-sdk/src/entities/element/build.js +2 -1
  122. package/dist-sdk/src/entities/element/from-tf.d.ts +1 -0
  123. package/dist-sdk/src/entities/element/from-tf.js +4 -7
  124. package/dist-sdk/src/entities/element/module.js +5 -0
  125. package/dist-sdk/src/entities/element/system-fields.d.ts +13 -0
  126. package/dist-sdk/src/entities/element/system-fields.js +23 -0
  127. package/dist-sdk/src/entities/element/to-tf.js +1 -0
  128. package/dist-sdk/src/entities/field/build.d.ts +9 -0
  129. package/dist-sdk/src/entities/field/from-tf.d.ts +52 -1
  130. package/dist-sdk/src/entities/field/from-tf.js +212 -14
  131. package/dist-sdk/src/entities/field/module.js +4 -0
  132. package/dist-sdk/src/entities/field/to-tf.d.ts +5 -1
  133. package/dist-sdk/src/entities/field/to-tf.js +33 -12
  134. package/dist-sdk/src/entities/org/category.js +1 -0
  135. package/dist-sdk/src/entities/org/index.d.ts +1 -0
  136. package/dist-sdk/src/entities/org/index.js +1 -0
  137. package/dist-sdk/src/entities/org/voice-auth.d.ts +5 -0
  138. package/dist-sdk/src/entities/org/voice-auth.js +33 -0
  139. package/dist-sdk/src/entities/organization/build.d.ts +3 -0
  140. package/dist-sdk/src/entities/organization/build.js +2 -0
  141. package/dist-sdk/src/entities/organization/index.d.ts +1 -0
  142. package/dist-sdk/src/entities/organization/index.js +1 -0
  143. package/dist-sdk/src/entities/organization/to-tf.d.ts +2 -0
  144. package/dist-sdk/src/entities/organization/to-tf.js +59 -1
  145. package/dist-sdk/src/entities/organization/voice-auth.d.ts +60 -0
  146. package/dist-sdk/src/entities/organization/voice-auth.js +60 -0
  147. package/dist-sdk/src/entities/phone-service/build.d.ts +9 -1
  148. package/dist-sdk/src/entities/phone-service/build.js +1 -0
  149. package/dist-sdk/src/entities/phone-service/deserializer/print-phone-service.js +3 -0
  150. package/dist-sdk/src/entities/phone-service/from-tf.d.ts +1 -0
  151. package/dist-sdk/src/entities/phone-service/from-tf.js +8 -1
  152. package/dist-sdk/src/entities/phone-service/to-tf.js +16 -0
  153. package/dist-sdk/src/entities/record-create-form/from-tf.js +2 -2
  154. package/dist-sdk/src/entities/relationship/from-tf.js +9 -4
  155. package/dist-sdk/src/entities/relationship/module.js +2 -2
  156. package/dist-sdk/src/entities/relationship/pair-check.d.ts +6 -2
  157. package/dist-sdk/src/entities/relationship/pair-check.js +105 -18
  158. package/dist-sdk/src/entities/relationship/to-tf.js +5 -2
  159. package/dist-sdk/src/entities/role/build.d.ts +3 -4
  160. package/dist-sdk/src/entities/role/permission-levels.d.ts +7 -0
  161. package/dist-sdk/src/entities/role/permission-levels.js +78 -0
  162. package/dist-sdk/src/entities/role/to-tf.js +32 -2
  163. package/dist-sdk/src/entities/search-table/build.d.ts +9 -3
  164. package/dist-sdk/src/entities/search-table/build.js +4 -4
  165. package/dist-sdk/src/entities/search-table/printer.js +3 -1
  166. package/dist-sdk/src/entities/search-table/to-tf.js +20 -2
  167. package/dist-sdk/src/entities/service-account/module.d.ts +2 -1
  168. package/dist-sdk/src/entities/service-account/module.js +4 -1
  169. package/dist-sdk/src/entities/service-account/resource-type.d.ts +2 -0
  170. package/dist-sdk/src/entities/service-account/resource-type.js +2 -0
  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/context.d.ts +14 -1
  176. package/dist-sdk/src/entities/shared/filters/ast.d.ts +2 -0
  177. package/dist-sdk/src/entities/shared/filters/index.d.ts +97 -15
  178. package/dist-sdk/src/entities/shared/filters/index.js +30 -7
  179. package/dist-sdk/src/entities/shared/filters/option-lookups.d.ts +57 -0
  180. package/dist-sdk/src/entities/shared/filters/option-lookups.js +108 -0
  181. package/dist-sdk/src/entities/shared/filters/print.d.ts +2 -0
  182. package/dist-sdk/src/entities/shared/filters/print.js +19 -6
  183. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +16 -7
  184. package/dist-sdk/src/entities/shared/filters/tf-codec.js +25 -5
  185. package/dist-sdk/src/entities/shared/filters/types.d.ts +4 -0
  186. package/dist-sdk/src/entities/shared/raw-option-id.d.ts +30 -0
  187. package/dist-sdk/src/entities/shared/raw-option-id.js +41 -0
  188. package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +1 -1
  189. package/dist-sdk/src/entities/shared/tool-field-ref.js +3 -2
  190. package/dist-sdk/src/entities/skill/input-coverage.js +5 -2
  191. package/dist-sdk/src/entities/sla/build.d.ts +96 -0
  192. package/dist-sdk/src/entities/sla/build.js +124 -0
  193. package/dist-sdk/src/entities/sla/from-tf.d.ts +40 -0
  194. package/dist-sdk/src/entities/sla/from-tf.js +164 -0
  195. package/dist-sdk/src/entities/sla/index.d.ts +1 -0
  196. package/dist-sdk/src/entities/sla/index.js +1 -0
  197. package/dist-sdk/src/entities/sla/module.d.ts +4 -0
  198. package/dist-sdk/src/entities/sla/module.js +73 -0
  199. package/dist-sdk/src/entities/sla/printer.d.ts +2 -0
  200. package/dist-sdk/src/entities/sla/printer.js +84 -0
  201. package/dist-sdk/src/entities/sla/to-tf.d.ts +12 -0
  202. package/dist-sdk/src/entities/sla/to-tf.js +81 -0
  203. package/dist-sdk/src/entities/table/build.d.ts +7 -2
  204. package/dist-sdk/src/entities/table/build.js +22 -1
  205. package/dist-sdk/src/entities/table/deserializer/normalize.d.ts +4 -1
  206. package/dist-sdk/src/entities/table/from-tf.js +89 -14
  207. package/dist-sdk/src/entities/table/index.d.ts +1 -1
  208. package/dist-sdk/src/entities/table/to-tf.js +41 -2
  209. package/dist-sdk/src/entities/task/from-tf.js +3 -2
  210. package/dist-sdk/src/entities/view/custom-view-validate.d.ts +6 -4
  211. package/dist-sdk/src/entities/view/custom-view-validate.js +36 -18
  212. package/dist-sdk/src/entities/view/from-tf.js +16 -4
  213. package/dist-sdk/src/entities/view/to-tf.js +66 -47
  214. package/dist-sdk/src/entities/visual-flow/module.js +52 -1
  215. package/dist-sdk/src/entities/widget/from-tf.js +19 -8
  216. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +49 -4
  217. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  218. package/dist-sdk/src/graph/index.d.ts +9 -0
  219. package/dist-sdk/src/graph/index.js +8 -0
  220. package/dist-sdk/src/graph/modules.js +13 -1
  221. package/dist-sdk/src/graph/resource-types.d.ts +47 -0
  222. package/dist-sdk/src/graph/resource-types.js +62 -0
  223. package/dist-sdk/src/graph/types.d.ts +113 -6
  224. package/package.json +7 -4
@@ -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,6 +57,10 @@ 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
  }>;
61
65
  /** A field identity an earlier pull recorded for a managed app or element. */
62
66
  export interface ManagedFieldNameIdentity {
@@ -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,6 +283,8 @@ 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;
@@ -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
+ }
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Stream-root ORCHESTRATOR: the typed blocks of an `ei <verb> export`
3
+ * stream → one extracted stream root (plan §7 M2). Owns traversal,
4
+ * partition, and the stream-level lookups (data-source names, import-block
5
+ * ids); conversion lives on entity modules' lifecycle hooks.
6
+ *
7
+ * Posture (plan §6): resource kinds without extractors are REPORTED as
8
+ * skipped, never fatal. Structural breakage (zero or multiple root
9
+ * resources) is a loud error. Locals are ei's derived lookup maps —
10
+ * extraction never consumes them; build regenerates them.
11
+ *
12
+ * Kind switches live in the entity graph — this file walks TYPE_TO_KIND /
13
+ * lifecycle hooks and must not import entity modules (value or type).
14
+ */
15
+ import { type EntityKindId, type AdoptionAddressAlias } from "../../graph/index.js";
16
+ import type { QuarantinedOwnFile } from "../../graph/types.js";
17
+ import { type TfDocument } from "../tf/index.js";
18
+ import type { ValidationFailure } from "../validation.js";
19
+ import { type AuthoringBlocker, type FromTfContext } from "./context.js";
20
+ export type { AuthoringBlocker } from "./context.js";
21
+ /** Stream-root kinds that have extractStreamRoot wired today. */
22
+ export type StreamRootKindId = "app" | "element" | "task" | "table" | "portal";
23
+ /**
24
+ * Opaque extract result. Entity shapes live on entity modules; the CLI /
25
+ * printers cast at the boundary. Engine only requires `root.refName` for path
26
+ * wiring (same contract as graph `StreamRootExtractResult.instance`).
27
+ */
28
+ export interface StreamRootExtract {
29
+ readonly root: {
30
+ readonly refName: string;
31
+ };
32
+ /** Own-file children extracted via lifecycle hooks, keyed by kind id. */
33
+ readonly ownFileByKind: ReadonlyMap<EntityKindId, readonly unknown[]>;
34
+ /** org.ts `cloudLinks` bag key for the printer, when the root pins one. */
35
+ readonly cloudLinkHandle?: string;
36
+ /** Resource addresses in the stream that aren't extracted — reported, not fatal (plan §6). */
37
+ readonly skipped: readonly string[];
38
+ /**
39
+ * Skipped address → the own-file child it belongs to (`skippedOwnFiles`,
40
+ * #1877), so the stale-path sweep keeps a skipped child's file (edk#2926).
41
+ */
42
+ readonly skippedOwners?: ReadonlyMap<string, {
43
+ readonly kind: EntityKindId;
44
+ readonly refName: string;
45
+ }>;
46
+ /** Skipped addresses no authored source can ever manage; adoption releases any already in state (see OwnFileExtractResult). */
47
+ readonly releaseIfManaged?: readonly string[];
48
+ /** Own-file ref names whose authored files are archived because their state was released (#1858). */
49
+ readonly quarantineOwnFiles?: readonly QuarantinedOwnFile[];
50
+ readonly diagnostics: readonly string[];
51
+ /** Collected validation findings. Fatal ones also contributed their addresses to `skipped`. */
52
+ readonly validationFailures: readonly ValidationFailure[];
53
+ readonly reports: readonly string[];
54
+ /** Resource address → platform id, from the stream's import blocks (adoption consumes these). */
55
+ readonly importIds: ReadonlyMap<string, string>;
56
+ /** Export addresses whose printed current-API source rebuilds at a canonical alias. */
57
+ readonly adoptionAddressAliases: readonly AdoptionAddressAlias[];
58
+ /**
59
+ * Resource address → the addresses it `depends_on` (e.g. a workflow_publish
60
+ * depending on its automation's tasks). `tofu plan -target=X` implicitly
61
+ * pulls in and imports X's dependencies even when they aren't themselves
62
+ * targeted - adoption's expected-import-count computation needs this to
63
+ * correctly count a depended-upon resource whose OWN kind isn't adoptable
64
+ * (e.g. a declared-but-unimplemented task type - see automation/types.ts's
65
+ * TASK_SUB_TYPES for the current list) but that still gets imported as a
66
+ * side effect of its dependent being targeted.
67
+ */
68
+ readonly dependsOn: ReadonlyMap<string, readonly string[]>;
69
+ /** Foreign app/element names referenced but left unresolvable this pull (see `FromTfContext.unresolvedForeignRefs`) — feeds `--with-dependencies`. */
70
+ readonly unresolvedForeignRefs: {
71
+ readonly apps: readonly string[];
72
+ readonly elements: readonly string[];
73
+ };
74
+ /**
75
+ * Live configuration authored source cannot reproduce without the next
76
+ * apply changing it: replace-forcing parts pull cannot rebuild (see
77
+ * `FromTfContext.authoringBlockers`) and the export's unsupported-binding
78
+ * markers. Extraction never refuses on them, so read-only callers can still
79
+ * resolve identities; a caller refuses with {@link assertAuthorable} for the
80
+ * blockers in the files it is about to write.
81
+ */
82
+ readonly authoringBlockers: readonly AuthoringBlocker[];
83
+ }
84
+ export declare class StreamRootExtractError extends Error {
85
+ constructor(message: string);
86
+ }
87
+ /** Source that cannot be authored without changing live configuration. */
88
+ export declare class AuthoringBlockedError extends StreamRootExtractError {
89
+ readonly blockers: readonly AuthoringBlocker[];
90
+ constructor(blockers: readonly AuthoringBlocker[], command?: "pull" | "clone");
91
+ }
92
+ /**
93
+ * Refuse to author source over live configuration it cannot reproduce. Call
94
+ * it with the blockers of everything the caller is about to write (usually
95
+ * `extract.authoringBlockers`), before any source is written.
96
+ */
97
+ export declare function assertAuthorable(blockers: readonly AuthoringBlocker[], command?: "pull" | "clone"): void;
98
+ /** Foreign identities already resolved from the surrounding workspace. */
99
+ export interface StreamRootExtractOptions {
100
+ readonly appRefNames?: ReadonlyMap<string, string>;
101
+ readonly elementRefNames?: ReadonlyMap<string, string>;
102
+ readonly taskRefNames?: ReadonlyMap<string, string>;
103
+ readonly appRefNamespaces?: ReadonlyMap<string, string>;
104
+ readonly elementRefNamespaces?: ReadonlyMap<string, string>;
105
+ readonly taskRefNamespaces?: ReadonlyMap<string, string>;
106
+ /** See `FromTfContext.selfAspectRef` (edk#1437). */
107
+ readonly selfAspectRef?: FromTfContext["selfAspectRef"];
108
+ /** See `FromTfContext.cloning` (#1978). */
109
+ readonly cloning?: FromTfContext["cloning"];
110
+ readonly foreignFieldRefsById?: ReadonlyMap<string, {
111
+ readonly ownerRefName: string;
112
+ readonly fieldKey: string;
113
+ readonly fieldName?: string;
114
+ }>;
115
+ readonly foreignFieldRefsByDataAddress?: ReadonlyMap<string, {
116
+ readonly ownerRefName: string;
117
+ readonly fieldKey: string;
118
+ readonly options?: readonly string[];
119
+ readonly systemStage?: true;
120
+ }>;
121
+ /** See `FromTfContext.ownFieldIdsByDataAddress` (#2815). */
122
+ readonly ownFieldIdsByDataAddress?: FromTfContext["ownFieldIdsByDataAddress"];
123
+ readonly foreignSkillRefsByOwnerName?: ReadonlyMap<string, {
124
+ readonly appRefName: string;
125
+ readonly skillRefName: string;
126
+ }>;
127
+ readonly foreignSkillRefsByOwnerNamespace?: FromTfContext["foreignSkillRefsByOwnerNamespace"];
128
+ readonly foreignTableRefsById?: ReadonlyMap<string, {
129
+ readonly tableRefName: string;
130
+ readonly name: string;
131
+ readonly columnRefNamesByName?: ReadonlyMap<string, string>;
132
+ readonly columnRefNamesById?: ReadonlyMap<string, string>;
133
+ }>;
134
+ readonly foreignFileReaderRefsById?: FromTfContext["foreignFileReaderRefsById"];
135
+ readonly picklistOptionsByField?: ReadonlyMap<string, ReadonlyMap<string, string>>;
136
+ readonly fieldNamesByOwnerRefName?: ReadonlyMap<string, ReadonlyMap<string, string>>;
137
+ readonly procedureKeysByDiscriminator?: ReadonlyMap<string, string>;
138
+ /** See `FromTfContext.groupKeysByName`. */
139
+ readonly groupKeysByName?: ReadonlyMap<string, string>;
140
+ /** See `FromTfContext.serviceAccountsById`. */
141
+ readonly serviceAccountsById?: FromTfContext["serviceAccountsById"];
142
+ /** See `FromTfContext.omittedAutomationsById`. */
143
+ readonly omittedAutomationsById?: FromTfContext["omittedAutomationsById"];
144
+ /** See `FromTfContext.platformCreatorPolicyIds`. */
145
+ readonly platformCreatorPolicyIds?: FromTfContext["platformCreatorPolicyIds"];
146
+ /**
147
+ * Whether an authored own-file for a child this pull skipped stays on disk,
148
+ * so build still emits it (#1731 SF3). `root` is the extracted stream root.
149
+ * Without it, no skipped child counts as kept.
150
+ */
151
+ readonly keptOwnFile?: (root: {
152
+ readonly refName: string;
153
+ }, kind: EntityKindId, refName: string) => boolean;
154
+ }
155
+ /** Read resource address → platform identity from the export's import blocks. */
156
+ export declare function importIdsFromDocument(doc: TfDocument): ReadonlyMap<string, string>;
157
+ export declare function extractStreamRoot(doc: TfDocument, kindId: StreamRootKindId, opts?: StreamRootExtractOptions): StreamRootExtract;
158
+ /** App-stream convenience alias — same as `extractStreamRoot(doc, "app")`. */
159
+ export declare function extractApp(doc: TfDocument, opts?: StreamRootExtractOptions): StreamRootExtract;