@elementumai/edk 0.12.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 (193) hide show
  1. package/README.md +2 -0
  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/types/app.d.ts +6 -0
  13. package/dist-sdk/src/engine/build/context.d.ts +3 -0
  14. package/dist-sdk/src/engine/pull/authored-address.js +42 -6
  15. package/dist-sdk/src/engine/pull/authored-root.d.ts +88 -0
  16. package/dist-sdk/src/engine/pull/authored-root.js +306 -0
  17. package/dist-sdk/src/engine/pull/context.d.ts +10 -0
  18. package/dist-sdk/src/engine/pull/field-refs-registry.d.ts +114 -0
  19. package/dist-sdk/src/engine/pull/field-refs-registry.js +501 -0
  20. package/dist-sdk/src/engine/pull/org.d.ts +1 -0
  21. package/dist-sdk/src/engine/pull/org.js +2 -0
  22. package/dist-sdk/src/engine/pull/partition.d.ts +8 -0
  23. package/dist-sdk/src/engine/pull/partition.js +43 -0
  24. package/dist-sdk/src/engine/pull/pulled-roots.d.ts +89 -0
  25. package/dist-sdk/src/engine/pull/pulled-roots.js +203 -0
  26. package/dist-sdk/src/engine/pull/ref-only.d.ts +4 -0
  27. package/dist-sdk/src/engine/pull/ref-only.js +7 -1
  28. package/dist-sdk/src/engine/pull/source-resources.d.ts +39 -0
  29. package/dist-sdk/src/engine/pull/source-resources.js +110 -0
  30. package/dist-sdk/src/engine/pull/stream-root.d.ts +148 -0
  31. package/dist-sdk/src/engine/pull/stream-root.js +563 -0
  32. package/dist-sdk/src/engine/workspace/reserved-catalog-keys.d.ts +47 -0
  33. package/dist-sdk/src/engine/workspace/reserved-catalog-keys.js +115 -0
  34. package/dist-sdk/src/entities/access-policy/build.d.ts +2 -1
  35. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +7 -0
  36. package/dist-sdk/src/entities/access-policy/from-tf.js +18 -3
  37. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +19 -0
  38. package/dist-sdk/src/entities/access-policy/to-tf.js +65 -8
  39. package/dist-sdk/src/entities/agent/build.d.ts +52 -1
  40. package/dist-sdk/src/entities/agent/build.js +34 -0
  41. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +68 -0
  42. package/dist-sdk/src/entities/agent/from-tf.d.ts +34 -1
  43. package/dist-sdk/src/entities/agent/from-tf.js +262 -2
  44. package/dist-sdk/src/entities/agent/index.d.ts +1 -1
  45. package/dist-sdk/src/entities/agent/to-tf.d.ts +8 -10
  46. package/dist-sdk/src/entities/agent/to-tf.js +158 -14
  47. package/dist-sdk/src/entities/agent-tool/from-tf.js +6 -0
  48. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
  49. package/dist-sdk/src/entities/agent-tool/to-tf.js +2 -2
  50. package/dist-sdk/src/entities/app/build.d.ts +33 -13
  51. package/dist-sdk/src/entities/app/build.js +14 -12
  52. package/dist-sdk/src/entities/app/from-tf.js +24 -9
  53. package/dist-sdk/src/entities/app/index.d.ts +1 -0
  54. package/dist-sdk/src/entities/app/index.js +1 -0
  55. package/dist-sdk/src/entities/app/module.js +1 -0
  56. package/dist-sdk/src/entities/app/stage-keys.d.ts +2 -2
  57. package/dist-sdk/src/entities/app/stage-keys.js +3 -3
  58. package/dist-sdk/src/entities/app/to-tf.js +1 -0
  59. package/dist-sdk/src/entities/approval-chain/build.d.ts +46 -11
  60. package/dist-sdk/src/entities/approval-chain/build.js +120 -8
  61. package/dist-sdk/src/entities/approval-chain/from-tf.d.ts +24 -2
  62. package/dist-sdk/src/entities/approval-chain/from-tf.js +148 -6
  63. package/dist-sdk/src/entities/approval-chain/index.d.ts +4 -1
  64. package/dist-sdk/src/entities/approval-chain/index.js +4 -1
  65. package/dist-sdk/src/entities/approval-chain/module.js +23 -5
  66. package/dist-sdk/src/entities/approval-chain/printer.d.ts +1 -1
  67. package/dist-sdk/src/entities/approval-chain/printer.js +91 -5
  68. package/dist-sdk/src/entities/approval-chain/steps-tf.d.ts +77 -0
  69. package/dist-sdk/src/entities/approval-chain/steps-tf.js +255 -0
  70. package/dist-sdk/src/entities/approval-chain/steps.d.ts +71 -0
  71. package/dist-sdk/src/entities/approval-chain/steps.js +83 -0
  72. package/dist-sdk/src/entities/approval-chain/to-tf.d.ts +16 -6
  73. package/dist-sdk/src/entities/approval-chain/to-tf.js +37 -4
  74. package/dist-sdk/src/entities/automation/build.js +70 -27
  75. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +20 -5
  76. package/dist-sdk/src/entities/automation/from-tf.d.ts +26 -5
  77. package/dist-sdk/src/entities/automation/from-tf.js +593 -101
  78. package/dist-sdk/src/entities/automation/index.d.ts +1 -0
  79. package/dist-sdk/src/entities/automation/index.js +1 -0
  80. package/dist-sdk/src/entities/automation/module.d.ts +4 -3
  81. package/dist-sdk/src/entities/automation/module.js +33 -12
  82. package/dist-sdk/src/entities/automation/refs-read.d.ts +19 -0
  83. package/dist-sdk/src/entities/automation/refs-read.js +48 -0
  84. package/dist-sdk/src/entities/automation/slack-message-refs.d.ts +9 -0
  85. package/dist-sdk/src/entities/automation/slack-message-refs.js +75 -0
  86. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +11 -0
  87. package/dist-sdk/src/entities/automation/task-output-labels.js +23 -0
  88. package/dist-sdk/src/entities/automation/tasks.d.ts +29 -4
  89. package/dist-sdk/src/entities/automation/tasks.js +34 -11
  90. package/dist-sdk/src/entities/automation/to-tf.d.ts +3 -0
  91. package/dist-sdk/src/entities/automation/to-tf.js +337 -77
  92. package/dist-sdk/src/entities/automation/triggers.d.ts +0 -8
  93. package/dist-sdk/src/entities/automation/triggers.js +26 -11
  94. package/dist-sdk/src/entities/automation/unsafe-script-output.d.ts +50 -0
  95. package/dist-sdk/src/entities/automation/unsafe-script-output.js +92 -0
  96. package/dist-sdk/src/entities/chart/build.d.ts +9 -1
  97. package/dist-sdk/src/entities/chart/from-tf.js +3 -0
  98. package/dist-sdk/src/entities/chart/to-tf.js +19 -2
  99. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +2 -0
  100. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +44 -5
  101. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +46 -12
  102. package/dist-sdk/src/entities/element/audit-field-guard.d.ts +9 -0
  103. package/dist-sdk/src/entities/element/audit-field-guard.js +88 -0
  104. package/dist-sdk/src/entities/element/build.js +2 -1
  105. package/dist-sdk/src/entities/element/from-tf.js +15 -2
  106. package/dist-sdk/src/entities/element/module.js +3 -0
  107. package/dist-sdk/src/entities/element/system-fields.d.ts +13 -0
  108. package/dist-sdk/src/entities/element/system-fields.js +23 -0
  109. package/dist-sdk/src/entities/element/to-tf.js +1 -0
  110. package/dist-sdk/src/entities/field/build.d.ts +9 -0
  111. package/dist-sdk/src/entities/field/from-tf.d.ts +29 -1
  112. package/dist-sdk/src/entities/field/from-tf.js +99 -6
  113. package/dist-sdk/src/entities/field/module.js +4 -0
  114. package/dist-sdk/src/entities/field/to-tf.d.ts +5 -1
  115. package/dist-sdk/src/entities/field/to-tf.js +33 -12
  116. package/dist-sdk/src/entities/org/category.js +1 -0
  117. package/dist-sdk/src/entities/org/index.d.ts +1 -0
  118. package/dist-sdk/src/entities/org/index.js +1 -0
  119. package/dist-sdk/src/entities/org/voice-auth.d.ts +5 -0
  120. package/dist-sdk/src/entities/org/voice-auth.js +33 -0
  121. package/dist-sdk/src/entities/organization/build.d.ts +3 -0
  122. package/dist-sdk/src/entities/organization/build.js +2 -0
  123. package/dist-sdk/src/entities/organization/index.d.ts +1 -0
  124. package/dist-sdk/src/entities/organization/index.js +1 -0
  125. package/dist-sdk/src/entities/organization/to-tf.d.ts +2 -0
  126. package/dist-sdk/src/entities/organization/to-tf.js +59 -1
  127. package/dist-sdk/src/entities/organization/voice-auth.d.ts +60 -0
  128. package/dist-sdk/src/entities/organization/voice-auth.js +60 -0
  129. package/dist-sdk/src/entities/phone-service/build.d.ts +9 -1
  130. package/dist-sdk/src/entities/phone-service/build.js +1 -0
  131. package/dist-sdk/src/entities/phone-service/deserializer/print-phone-service.js +3 -0
  132. package/dist-sdk/src/entities/phone-service/from-tf.d.ts +1 -0
  133. package/dist-sdk/src/entities/phone-service/from-tf.js +8 -1
  134. package/dist-sdk/src/entities/phone-service/to-tf.js +16 -0
  135. package/dist-sdk/src/entities/record-create-form/from-tf.js +2 -2
  136. package/dist-sdk/src/entities/relationship/from-tf.js +7 -2
  137. package/dist-sdk/src/entities/relationship/module.js +2 -2
  138. package/dist-sdk/src/entities/relationship/pair-check.d.ts +6 -2
  139. package/dist-sdk/src/entities/relationship/pair-check.js +105 -18
  140. package/dist-sdk/src/entities/relationship/to-tf.js +5 -2
  141. package/dist-sdk/src/entities/role/permission-levels.d.ts +7 -0
  142. package/dist-sdk/src/entities/role/permission-levels.js +78 -0
  143. package/dist-sdk/src/entities/role/to-tf.js +32 -2
  144. package/dist-sdk/src/entities/service-account/module.d.ts +2 -1
  145. package/dist-sdk/src/entities/service-account/module.js +4 -1
  146. package/dist-sdk/src/entities/service-account/resource-type.d.ts +2 -0
  147. package/dist-sdk/src/entities/service-account/resource-type.js +2 -0
  148. package/dist-sdk/src/entities/service-account/role-membership-check.d.ts +20 -0
  149. package/dist-sdk/src/entities/service-account/role-membership-check.js +80 -0
  150. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +15 -0
  151. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +36 -0
  152. package/dist-sdk/src/entities/shared/filters/ast.d.ts +2 -0
  153. package/dist-sdk/src/entities/shared/filters/index.d.ts +85 -14
  154. package/dist-sdk/src/entities/shared/filters/index.js +18 -6
  155. package/dist-sdk/src/entities/shared/filters/option-lookups.d.ts +57 -0
  156. package/dist-sdk/src/entities/shared/filters/option-lookups.js +108 -0
  157. package/dist-sdk/src/entities/shared/filters/print.js +9 -5
  158. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +12 -7
  159. package/dist-sdk/src/entities/shared/filters/tf-codec.js +9 -5
  160. package/dist-sdk/src/entities/shared/raw-option-id.d.ts +30 -0
  161. package/dist-sdk/src/entities/shared/raw-option-id.js +41 -0
  162. package/dist-sdk/src/entities/shared/tool-field-ref.js +6 -2
  163. package/dist-sdk/src/entities/skill/input-coverage.js +5 -2
  164. package/dist-sdk/src/entities/sla/build.d.ts +96 -0
  165. package/dist-sdk/src/entities/sla/build.js +124 -0
  166. package/dist-sdk/src/entities/sla/from-tf.d.ts +40 -0
  167. package/dist-sdk/src/entities/sla/from-tf.js +164 -0
  168. package/dist-sdk/src/entities/sla/index.d.ts +1 -0
  169. package/dist-sdk/src/entities/sla/index.js +1 -0
  170. package/dist-sdk/src/entities/sla/module.d.ts +4 -0
  171. package/dist-sdk/src/entities/sla/module.js +73 -0
  172. package/dist-sdk/src/entities/sla/printer.d.ts +2 -0
  173. package/dist-sdk/src/entities/sla/printer.js +84 -0
  174. package/dist-sdk/src/entities/sla/to-tf.d.ts +12 -0
  175. package/dist-sdk/src/entities/sla/to-tf.js +81 -0
  176. package/dist-sdk/src/entities/table/build.d.ts +7 -2
  177. package/dist-sdk/src/entities/table/build.js +22 -1
  178. package/dist-sdk/src/entities/table/deserializer/normalize.d.ts +4 -1
  179. package/dist-sdk/src/entities/table/from-tf.js +89 -14
  180. package/dist-sdk/src/entities/table/index.d.ts +1 -1
  181. package/dist-sdk/src/entities/table/to-tf.js +41 -2
  182. package/dist-sdk/src/entities/task/from-tf.js +2 -1
  183. package/dist-sdk/src/entities/view/from-tf.js +7 -4
  184. package/dist-sdk/src/entities/widget/from-tf.js +13 -2
  185. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +49 -4
  186. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  187. package/dist-sdk/src/graph/index.d.ts +5 -0
  188. package/dist-sdk/src/graph/index.js +7 -0
  189. package/dist-sdk/src/graph/modules.js +11 -1
  190. package/dist-sdk/src/graph/resource-types.d.ts +47 -0
  191. package/dist-sdk/src/graph/resource-types.js +62 -0
  192. package/dist-sdk/src/graph/types.d.ts +78 -6
  193. package/package.json +6 -3
package/README.md CHANGED
@@ -214,6 +214,8 @@ elementum pull app <namespace> [--root <orgRoot>] [--no-adopt] [--skip-unsupport
214
214
  elementum pull element <namespace> [--root <orgRoot>] [--no-adopt] [--skip-unsupported-layouts] [--portable [--map <file>]]
215
215
  elementum pull task <namespace> [--root <orgRoot>] [--no-adopt] [--portable [--map <file>]]
216
216
  elementum pull --restore-previous [--root <orgRoot>] # after a failed pull: .tf/in.previous -> .tf/in (failed copy kept as .tf/in.failed); never automatic
217
+ # A failed `pull app`/`pull element` adoption settles the .ts itself: unchanged state puts apps|elements/<ref>/ back as it was before
218
+ # the pull (pulled copy kept under .edk-state/failed-pulls/); changed state keeps the pulled source (previous copy kept there instead).
217
219
  elementum clone app <namespace> --as <newName> [--namespace <newns>] [--root <orgRoot>] [--target-root <destOrgRoot>] [--map <file>]
218
220
  elementum build [orgRoot]
219
221
  elementum plan [orgRoot-or-nested-target] [--json] [bridge args...]
@@ -21,7 +21,7 @@
21
21
  * nothing reads those interim values.
22
22
  */
23
23
  import type { AiProviderLlmModel, AiProviderType } from "./ai-provider-models.js";
24
- import type { AgentEvaluationRef, AgentRef, AppCatalogRef, AppOrElementRef, AiProviderRef, ApprovalChainRef, AutomationCatalogRef, CatalogRef, CategoryRef, ChartRef, DashboardRef, WidgetRef, CloudLinkRef, ConnectorRef, DatamineRef, RelationshipRef, GroupRef, PhoneProviderRef, PhoneServiceRef, ProcedureParameterType, ProcedureRef, FileReaderCatalogRef, DocumentModelFieldRef, ElementCatalogRef, FieldRef, ViewRef, ViewType, OutputPropertyRef, RecordIdentityRef, SearchTableRef, StoredFunctionRef, StoredFunctionScalarType, SkillRef, TableColumnRef, TableOwnedSearchTableRef, TableRef, TaskCatalogRef, TriggerParameterRef } from "./types.js";
24
+ import type { AgentEvaluationRef, AgentRef, AppCatalogRef, AppOrElementRef, AiProviderRef, ApprovalChainRef, AutomationCatalogRef, CatalogRef, CategoryRef, ChartRef, DashboardRef, WidgetRef, CloudLinkRef, ConnectorRef, DatamineRef, RelationshipRef, GroupRef, PhoneProviderRef, PhoneServiceRef, VoiceAuthRef, ProcedureParameterType, ProcedureRef, FileReaderCatalogRef, DocumentModelFieldRef, ElementCatalogRef, FieldRef, ViewRef, ViewType, OutputPropertyRef, RecordIdentityRef, SearchTableRef, StoredFunctionRef, StoredFunctionScalarType, SkillRef, TableColumnRef, TableOwnedSearchTableRef, TableRef, TaskCatalogRef, TriggerParameterRef } from "./types.js";
25
25
  export declare function recordIdentity<const Target extends AppOrElementRef | TaskCatalogRef | TableRef>(target: Target): RecordIdentityRef<Target>;
26
26
  /** Fixed platform user-directory schema used by userSearch filters. */
27
27
  export declare const usersCatalog: {
@@ -308,6 +308,10 @@ export declare const phoneProviderRef: (opts: Omit<PhoneProviderRef, "refName" |
308
308
  readonly __kind: "phoneProvider";
309
309
  readonly refName: string;
310
310
  };
311
+ export declare const voiceAuthRef: (opts: Omit<VoiceAuthRef, "refName" | "__kind">) => Omit<VoiceAuthRef, "refName" | "__kind"> & {
312
+ readonly __kind: "voiceAuth";
313
+ readonly refName: string;
314
+ };
311
315
  export declare function tableColumnRef(opts: Omit<TableColumnRef, "__kind" | "refName" | "parent"> & {
312
316
  readonly parent?: string;
313
317
  }): TableColumnRef;
@@ -392,6 +396,7 @@ export declare function elementCatalog<const RefName extends string, B extends E
392
396
  */
393
397
  type PhoneProviderOrgCatalogBag = {
394
398
  readonly phoneProviders: Readonly<Record<string, PhoneProviderRef>>;
399
+ readonly voiceAuths: Readonly<Record<string, VoiceAuthRef>>;
395
400
  };
396
401
  export declare function orgCatalog<B extends {
397
402
  aiProviders?: Record<string, AiProviderRef>;
@@ -399,6 +404,7 @@ export declare function orgCatalog<B extends {
399
404
  categories?: Record<string, CategoryRef>;
400
405
  groups?: Record<string, GroupRef>;
401
406
  phoneProviders?: Record<string, PhoneProviderRef>;
407
+ voiceAuths?: Record<string, VoiceAuthRef>;
402
408
  tables?: Record<string, TableRef>;
403
409
  }>(bags: B): {
404
410
  readonly handle: "org";
@@ -243,6 +243,7 @@ export function procedureRef(opts) {
243
243
  export const categoryRef = refFactory("category");
244
244
  export const groupRef = refFactory("group");
245
245
  export const phoneProviderRef = refFactory("phoneProvider");
246
+ export const voiceAuthRef = refFactory("voiceAuth");
246
247
  export function tableColumnRef(opts) {
247
248
  return {
248
249
  __kind: "tableColumn",
@@ -496,6 +497,7 @@ export function orgCatalog(bags) {
496
497
  categories: withOwnKeyAsHandle(bags.categories) ?? {},
497
498
  groups: withOwnKeyAsHandle(bags.groups) ?? {},
498
499
  phoneProviders: withOwnKeyAsHandle(bags.phoneProviders) ?? {},
500
+ voiceAuths: withOwnKeyAsHandle(bags.voiceAuths) ?? {},
499
501
  tables: stampTableRefs(bags.tables) ?? {},
500
502
  };
501
503
  }
@@ -4,9 +4,9 @@
4
4
  * ids appear here (identity lives in `src/deploy/state`).
5
5
  */
6
6
  export { AI_PROVIDER_LLM_MODELS, type AiProviderLlmModel, type AiProviderType } from "./ai-provider-models.js";
7
- export { REF_SCOPE, REF_UPDATABLE, type AgentRef, type AgentEvaluationRef, type AiProviderRef, type ApprovalChainRef, type ApprovalProcessRef, type AppCatalogRef, type AppOrElementRef, type AutomationCatalogRef, type AutomationRef, type CatalogRef, type CatalogRefKind, type CategoryRef, type ChartRef, type DashboardRef, type WidgetRef, type CloudLinkRef, type AiServiceRef, type ConnectorRef, type GroupRef, type PhoneProviderRef, type PhoneServiceRef, PROCEDURE_PARAMETER_TYPES, type ProcedureParameterType, type ProcedureRef, type FileReaderCatalogRef, type DocumentModelFieldRef, type ElementCatalogRef, type TaskCatalogRef, type AppOrElementOrTaskRef, type FieldRef, type OutputPropertyRef, type RecordIdentityRef, type SearchTableRef, type TableOwnedSearchTableRef, type StoredFunctionRef, type StoredFunctionScalarType, type DatamineRef, type RelationshipRef, type SkillRef, type TableColumnRef, type TableRef, type TriggerParameterRef, USER_FIELD_KEYS, type UserFieldKey, type UserFieldRef, USER_GROUP_FIELD_KEYS, type UserGroupFieldKey, type UserGroupFieldRef, viewType, type ViewRef, type ViewType, } from "./types.js";
7
+ export { REF_SCOPE, REF_UPDATABLE, type AgentRef, type AgentEvaluationRef, type AiProviderRef, type ApprovalChainRef, type ApprovalProcessRef, type AppCatalogRef, type AppOrElementRef, type AutomationCatalogRef, type AutomationRef, type CatalogRef, type CatalogRefKind, type CategoryRef, type ChartRef, type DashboardRef, type WidgetRef, type CloudLinkRef, type AiServiceRef, type ConnectorRef, type GroupRef, type PhoneProviderRef, type VoiceAuthRef, type PhoneServiceRef, PROCEDURE_PARAMETER_TYPES, type ProcedureParameterType, type ProcedureRef, type FileReaderCatalogRef, type DocumentModelFieldRef, type ElementCatalogRef, type TaskCatalogRef, type AppOrElementOrTaskRef, type FieldRef, type OutputPropertyRef, type RecordIdentityRef, type SearchTableRef, type TableOwnedSearchTableRef, type StoredFunctionRef, type StoredFunctionScalarType, type DatamineRef, type RelationshipRef, type SkillRef, type TableColumnRef, type TableRef, type TriggerParameterRef, USER_FIELD_KEYS, type UserFieldKey, type UserFieldRef, USER_GROUP_FIELD_KEYS, type UserGroupFieldKey, type UserGroupFieldRef, viewType, type ViewRef, type ViewType, } from "./types.js";
8
8
  export { renderBarrel, renderCatalog, renderFragment, type BarrelEntry, type BarrelRoot, } from "./render.js";
9
9
  export { appCatalogTarget, barrelPathFor, orgCatalogTarget, regenerateBarrel, writeCatalog, writeFlatCatalog, writeFragment, type CatalogTarget, } from "./write.js";
10
10
  export { isCatalogToken, slimToken, slimTokens } from "./token.js";
11
11
  export { buildAppCatalogFromAuthoring, listEntityFilesFromPaths, refNameOf, regenerateAppCatalogsUnder, writeAppCatalog, writeAppCatalogFromAuthoring, type AppAuthoringCatalog, type AppCatalogRegenResult, type ConfiguredEntity, } from "./from-authoring.js";
12
- export { agentRef, agentEvaluationRef, appRef, appCatalog, approvalChainRef, automationRef, categoryRef, chartRef, dashboardRef, widgetRef, cloudLinkRef, connectorRef, aiProvider, groupRef, linkedSearchTableRef, phoneProviderRef, phoneServiceRef, procedureRef, documentModelFieldRef, documentModelRef, elementCatalog, elementRef, fieldRef, orgCatalog, outputPropertyRef, recordIdentity, searchTableRef, datamineRef, relationshipRef, skillRef, storedFunctionRef, tableColumnRef, tableRef, tableSearchTableRef, taskRef, triggerParameterRef, userGroupsCatalog, usersCatalog, viewRef, type CatalogViewRefOptions, type OutsideViewRefOptions, } from "./factories.js";
12
+ export { agentRef, agentEvaluationRef, appRef, appCatalog, approvalChainRef, automationRef, categoryRef, chartRef, dashboardRef, widgetRef, cloudLinkRef, connectorRef, aiProvider, groupRef, linkedSearchTableRef, phoneProviderRef, phoneServiceRef, voiceAuthRef, procedureRef, documentModelFieldRef, documentModelRef, elementCatalog, elementRef, fieldRef, orgCatalog, outputPropertyRef, recordIdentity, searchTableRef, datamineRef, relationshipRef, skillRef, storedFunctionRef, tableColumnRef, tableRef, tableSearchTableRef, taskRef, triggerParameterRef, userGroupsCatalog, usersCatalog, viewRef, type CatalogViewRefOptions, type OutsideViewRefOptions, } from "./factories.js";
@@ -9,4 +9,4 @@ export { renderBarrel, renderCatalog, renderFragment, } from "./render.js";
9
9
  export { appCatalogTarget, barrelPathFor, orgCatalogTarget, regenerateBarrel, writeCatalog, writeFlatCatalog, writeFragment, } from "./write.js";
10
10
  export { isCatalogToken, slimToken, slimTokens } from "./token.js";
11
11
  export { buildAppCatalogFromAuthoring, listEntityFilesFromPaths, refNameOf, regenerateAppCatalogsUnder, writeAppCatalog, writeAppCatalogFromAuthoring, } from "./from-authoring.js";
12
- export { agentRef, agentEvaluationRef, appRef, appCatalog, approvalChainRef, automationRef, categoryRef, chartRef, dashboardRef, widgetRef, cloudLinkRef, connectorRef, aiProvider, groupRef, linkedSearchTableRef, phoneProviderRef, phoneServiceRef, procedureRef, documentModelFieldRef, documentModelRef, elementCatalog, elementRef, fieldRef, orgCatalog, outputPropertyRef, recordIdentity, searchTableRef, datamineRef, relationshipRef, skillRef, storedFunctionRef, tableColumnRef, tableRef, tableSearchTableRef, taskRef, triggerParameterRef, userGroupsCatalog, usersCatalog, viewRef, } from "./factories.js";
12
+ export { agentRef, agentEvaluationRef, appRef, appCatalog, approvalChainRef, automationRef, categoryRef, chartRef, dashboardRef, widgetRef, cloudLinkRef, connectorRef, aiProvider, groupRef, linkedSearchTableRef, phoneProviderRef, phoneServiceRef, voiceAuthRef, procedureRef, documentModelFieldRef, documentModelRef, elementCatalog, elementRef, fieldRef, orgCatalog, outputPropertyRef, recordIdentity, searchTableRef, datamineRef, relationshipRef, skillRef, storedFunctionRef, tableColumnRef, tableRef, tableSearchTableRef, taskRef, triggerParameterRef, userGroupsCatalog, usersCatalog, viewRef, } from "./factories.js";
@@ -26,6 +26,8 @@ import { sanitizeName, tfLabelToTsLabel, tsLabelToTfLabel } from "../engine/tf/i
26
26
  import { sdkPackageSpecifier } from "../internal/sdk-package.js";
27
27
  import { OrgExtractError } from "../engine/pull/org.js";
28
28
  import { writeTechnicalLog } from "../engine/progress.js";
29
+ import { computeElementKeys, isGeneratedOnlyFolder, isShadowedCatalogKey, ORG_CATALOG_KEYS, shadowedFolderWarning, } from "../engine/workspace/reserved-catalog-keys.js";
30
+ import { reservedRootFolder } from "../engine/pull/authored-root.js";
29
31
  // ---------------------------------------------------------------------------
30
32
  // Public entry points
31
33
  // ---------------------------------------------------------------------------
@@ -97,20 +99,25 @@ async function readBarrelState(root) {
97
99
  const worktree = await readOptional(join(root, BARREL_RELATIVE_PATH));
98
100
  const git = barrelGitStatus(root);
99
101
  const barrel = worktree ?? (git.kind === "tracked" ? indexedBarrel(root) : undefined);
102
+ const listed = new Set(barrel === undefined ? [] : [...barrel.matchAll(BARREL_ENTRY_PATH)].map((m) => `${m[1]}/${m[2]}`));
103
+ // A listed table entry may be kept (keptReason), and then `tables` is emitted.
104
+ const keptTables = git.kind !== "untracked" && [...listed].some((e) => e.startsWith("tables/"));
100
105
  const handles = await discoverOrgRootHandles(root);
106
+ const droppedSet = shadowedBarrelRoots(root, handles, keptTables);
101
107
  const expected = new Set([
102
108
  ...handles.appHandles.map((h) => `apps/${h}`),
103
109
  ...handles.elementHandles.map((h) => `elements/${h}`),
104
110
  ...handles.tableHandles.map((h) => `tables/${h}`),
105
- ]);
106
- const listed = new Set(barrel === undefined ? [] : [...barrel.matchAll(BARREL_ENTRY_PATH)].map((m) => `${m[1]}/${m[2]}`));
111
+ ].filter((e) => !droppedSet.has(e)));
107
112
  const expectedFolded = new Set([...expected].map((e) => e.toLowerCase()));
108
- const notExpected = [...listed].filter((e) => !expected.has(e));
113
+ const notExpected = [...listed].filter((e) => !expected.has(e) && !droppedSet.has(e));
109
114
  return {
110
115
  present: worktree !== undefined,
111
116
  shadowed: notExpected.filter((e) => expectedFolded.has(e.toLowerCase())).sort(),
112
117
  git,
113
118
  handles,
119
+ reservedListed: [...listed].filter((e) => droppedSet.has(e)).sort(),
120
+ shadowedRoots: [...droppedSet].sort(),
114
121
  missing: [...expected].filter((e) => !listed.has(e)).sort(),
115
122
  stale: notExpected.filter((e) => !expectedFolded.has(e.toLowerCase())).sort(),
116
123
  };
@@ -166,10 +173,11 @@ export async function refreshCatalogBarrel(root) {
166
173
  const { missing, stale } = state;
167
174
  const reason = keptReason(state);
168
175
  const kept = { keptStale: reason !== undefined, ...(reason !== undefined && { keptReason: reason }) };
169
- if (state.present && missing.length === 0 && state.shadowed.length === 0 && (stale.length === 0 || reason !== undefined)) {
176
+ if (state.present && missing.length === 0 && state.shadowed.length === 0 && state.reservedListed.length === 0 &&
177
+ (stale.length === 0 || reason !== undefined)) {
170
178
  await ensureBarrelIgnored(root);
171
179
  const entries = state.handles.appHandles.length + state.handles.elementHandles.length +
172
- state.handles.tableHandles.length + (reason === undefined ? 0 : stale.length);
180
+ state.handles.tableHandles.length - state.shadowedRoots.length + (reason === undefined ? 0 : stale.length);
173
181
  return { missing, stale, created: false, written: false, entries, ...kept };
174
182
  }
175
183
  const entries = await writeBarrel(root, state);
@@ -640,6 +648,21 @@ function renderAiProvidersBag(extract) {
640
648
  lines.push(" },");
641
649
  return lines;
642
650
  }
651
+ /**
652
+ * The org entries renderBarrel writes after the app and element getters, in
653
+ * ORG_CATALOG_KEYS order. Keyed by that list, so the reserved names pull and
654
+ * `elementum new` avoid (edk#2839) can't drift from what the barrel emits.
655
+ */
656
+ const ORG_CATALOG_ENTRY_VALUES = {
657
+ users: "usersCatalog",
658
+ userGroups: "userGroupsCatalog",
659
+ aiProviders: "orgIdentities.aiProviders",
660
+ cloudLinks: "orgIdentities.cloudLinks",
661
+ categories: "orgIdentities.categories",
662
+ groups: "orgIdentities.groups",
663
+ phoneProviders: "orgIdentities.phoneProviders",
664
+ voiceAuths: "orgIdentities.voiceAuths",
665
+ };
643
666
  /**
644
667
  * Render generated/catalog.ts as a pure barrel over org.ts + disk-scanned
645
668
  * catalogs — every app/element/table entry is a lazy `get` accessor (a
@@ -665,11 +688,20 @@ function renderAiProvidersBag(extract) {
665
688
  * invoked, so its self-referential chain never runs).
666
689
  */
667
690
  function renderBarrel(appHandles, elementHandles, tableHandles) {
691
+ // Element keys come from every app and element folder, as on main. Then
692
+ // an app whose folder name, or an element whose key, is an org entry below
693
+ // is left out: that entry wins, so the getter would never be reached
694
+ // (edk#2839).
695
+ const tablesEmitted = tableHandles.length > 0;
668
696
  const elementKeys = computeElementKeys(appHandles, elementHandles);
697
+ appHandles = appHandles.filter((handle) => !isShadowedCatalogKey(handle, tablesEmitted));
698
+ elementHandles = elementHandles.filter((handle) => !isShadowedCatalogKey(elementKeys.get(handle), tablesEmitted));
669
699
  for (const [handle, key] of elementKeys) {
670
700
  if (key === handle)
671
701
  continue;
672
- writeTechnicalLog("WARN", "edk", `"${handle}" names both an app and an element — the element is exposed as catalog.${key} (the app keeps catalog.${handle}) to avoid a collision.`);
702
+ writeTechnicalLog("WARN", "edk", isShadowedCatalogKey(handle, tablesEmitted)
703
+ ? `"${handle}" names both an app and an element — the element is exposed as catalog.${key}; catalog.${handle} is the org's own entry.`
704
+ : `"${handle}" names both an app and an element — the element is exposed as catalog.${key} (the app keeps catalog.${handle}) to avoid a collision.`);
673
705
  }
674
706
  const hasLazyEntries = appHandles.length > 0 || elementHandles.length > 0 || tableHandles.length > 0;
675
707
  const lines = [
@@ -701,13 +733,8 @@ function renderBarrel(appHandles, elementHandles, tableHandles) {
701
733
  for (const h of elementHandles) {
702
734
  lines.push(...lazyAspectGetter(elementKeys.get(h), `../elements/${h}/generated/catalog.js`, h));
703
735
  }
704
- lines.push(" users: usersCatalog,");
705
- lines.push(" userGroups: userGroupsCatalog,");
706
- lines.push(" aiProviders: orgIdentities.aiProviders,");
707
- lines.push(" cloudLinks: orgIdentities.cloudLinks,");
708
- lines.push(" categories: orgIdentities.categories,");
709
- lines.push(" groups: orgIdentities.groups,");
710
- lines.push(" phoneProviders: orgIdentities.phoneProviders,");
736
+ for (const key of ORG_CATALOG_KEYS)
737
+ lines.push(` ${key}: ${ORG_CATALOG_ENTRY_VALUES[key]},`);
711
738
  if (tableHandles.length > 0)
712
739
  lines.push(" tables,");
713
740
  lines.push("};");
@@ -731,27 +758,6 @@ function lazyAspectGetter(key, importPath, exportName, indent = " ") {
731
758
  `${indent}get ${key}() { return (catalogRequire(${quoted}) as typeof import(${quoted})).${exportName}; },`,
732
759
  ];
733
760
  }
734
- /** Pure shared allocator: app/element collisions receive disambiguated keys. */
735
- function computeElementKeys(appHandles, elementHandles) {
736
- const used = new Set(appHandles);
737
- const elementKeys = new Map();
738
- for (const h of elementHandles) {
739
- if (!used.has(h)) {
740
- elementKeys.set(h, h);
741
- used.add(h);
742
- continue;
743
- }
744
- let i = 2;
745
- let candidate = `${h}${i}`;
746
- while (used.has(candidate)) {
747
- i++;
748
- candidate = `${h}${i}`;
749
- }
750
- elementKeys.set(h, candidate);
751
- used.add(candidate);
752
- }
753
- return elementKeys;
754
- }
755
761
  // ---------------------------------------------------------------------------
756
762
  // App / element / table handle discovery (dirs from orgRootOwnFileBags)
757
763
  // ---------------------------------------------------------------------------
@@ -771,6 +777,45 @@ async function discoverHandles(root, subdir) {
771
777
  catch { /* subdir doesn't exist yet — no handles */ }
772
778
  return handles.sort();
773
779
  }
780
+ /**
781
+ * The app and element folders the barrel's org entries shadow (`users`,
782
+ * `groups`, …, and `tables` while a table catalog is emitted; edk#2839): an
783
+ * app by its folder name, an element by the key computeElementKeys gives it,
784
+ * so `elements/groups/` beside `apps/groups/` (key `groups2`) stays. Their
785
+ * getter would never be reached, so the barrel leaves them out. Pull and
786
+ * `elementum new` no longer write one. An older pull's dependency stub there
787
+ * (only `generated/`) moves on the next pull; a folder with source gets one
788
+ * warning naming how to move it. `keptTables` counts table entries a tracked
789
+ * barrel keeps as well as those on disk.
790
+ */
791
+ function shadowedBarrelRoots(root, handles, keptTables) {
792
+ const tablesEmitted = handles.tableHandles.length > 0 || keptTables;
793
+ const elementKeys = computeElementKeys(handles.appHandles, handles.elementHandles);
794
+ const shadowed = new Set();
795
+ const check = (bag, handle, key) => {
796
+ if (!isShadowedCatalogKey(key, tablesEmitted))
797
+ return;
798
+ shadowed.add(`${bag}/${handle}`);
799
+ const warned = `${root}\0${bag}/${handle}`;
800
+ if (!isGeneratedOnlyFolder(join(root, bag, handle)) && !warnedShadowedFolders.has(warned)) {
801
+ warnedShadowedFolders.add(warned);
802
+ const sharedWithElement = bag === "apps" && handles.elementHandles.includes(handle);
803
+ writeTechnicalLog("WARN", "edk", shadowedFolderWarning(bag, handle, reservedRootFolder(root, bag, handle, undefined, bag === "elements" ? handle : undefined)) +
804
+ (sharedWithElement
805
+ ? ` Move elements/${handle}/ to elements/${reservedRootFolder(root, "elements", handle, undefined, handle)}/ first ` +
806
+ `(pull it again, or pull an app that references it when it is only a dependency stub; a folder with source can be renamed the same way): ` +
807
+ `once the app leaves, the element's key becomes catalog.${handle}, the org entry, and catalog.${elementKeys.get(handle)} stops resolving.`
808
+ : ""));
809
+ }
810
+ };
811
+ for (const handle of handles.appHandles)
812
+ check("apps", handle, handle);
813
+ for (const handle of handles.elementHandles)
814
+ check("elements", handle, elementKeys.get(handle));
815
+ return shadowed;
816
+ }
817
+ /** One warning per shadowed folder per process; the barrel is read many times per command. */
818
+ const warnedShadowedFolders = new Set();
774
819
  /**
775
820
  * Scan org-root own-file bags from the graph. Apps/elements stay flat on the
776
821
  * barrel; `tables` nests under `catalog.tables` (historical shape).
@@ -102,6 +102,11 @@ export function slimToken(token) {
102
102
  else if ((token.__kind === "field" || token.__kind === "tableColumn") && Array.isArray(token.semanticTags)) {
103
103
  out.tags = token.semanticTags.filter((tag) => typeof tag === "string");
104
104
  }
105
+ // #1871 re-key map: keep the natural TF child part on the slim field token
106
+ // so option locals and address fallbacks match the emitted resource.
107
+ if (token.__kind === "field" && typeof token.resourceKey === "string" && token.resourceKey !== "") {
108
+ out.resourceKey = token.resourceKey;
109
+ }
105
110
  return out;
106
111
  }
107
112
  /**
@@ -36,7 +36,7 @@ import type { AiProviderLlmModel, AiProviderType } from "./ai-provider-models.js
36
36
  * resolved to the current-version param/output id via the parent
37
37
  * automation's state binding.
38
38
  */
39
- export type CatalogRefKind = "automation" | "agent" | "agent-evaluation" | "chart" | "dashboard" | "widget" | "skill" | "visual-flow" | "approvalChain" | "table" | "tableColumn" | "cloudLink" | "storedFunction" | "procedure" | "field" | "view" | "searchTable" | "documentModel" | "documentModelField" | "connector" | "aiProvider" | "category" | "group" | "phoneProvider" | "phone-service" | "datamine" | "relationship" | "app" | "element" | "task" | "portal" | "triggerParameter" | "outputProperty";
39
+ export type CatalogRefKind = "automation" | "agent" | "agent-evaluation" | "sla" | "chart" | "dashboard" | "widget" | "skill" | "visual-flow" | "approvalChain" | "table" | "tableColumn" | "cloudLink" | "storedFunction" | "procedure" | "field" | "view" | "searchTable" | "documentModel" | "documentModelField" | "connector" | "aiProvider" | "category" | "group" | "phoneProvider" | "voiceAuth" | "phone-service" | "datamine" | "relationship" | "app" | "element" | "task" | "portal" | "triggerParameter" | "outputProperty";
40
40
  /**
41
41
  * The reference surface for a catalog entity. `handle` is the stable join key
42
42
  * (no id); `name` is for readability/diagnostics, never a match key.
@@ -204,6 +204,7 @@ export interface CloudLinkRef<Functions extends Readonly<Record<string, StoredFu
204
204
  export type CategoryRef = CatalogRef<"category">;
205
205
  export type GroupRef = CatalogRef<"group">;
206
206
  export type PhoneProviderRef = CatalogRef<"phoneProvider">;
207
+ export type VoiceAuthRef = CatalogRef<"voiceAuth">;
207
208
  export type PhoneServiceRef<Parent extends string = string, RefName extends string = string> = CatalogRef<"phone-service", RefName, Parent>;
208
209
  /** Typed references to app and element catalog roots. */
209
210
  export type AppCatalogRef<RefName extends string = string> = CatalogRef<"app", RefName> & {
@@ -262,6 +263,11 @@ export interface FieldRef<Parent extends string = string, RefName extends string
262
263
  readonly fieldType: FieldType;
263
264
  readonly tags?: readonly string[];
264
265
  readonly options?: readonly string[];
266
+ /**
267
+ * Natural bag key when pull re-keyed this field off a reserved system key
268
+ * (#1871). Option locals and address fallbacks use this child part.
269
+ */
270
+ readonly resourceKey?: string;
265
271
  /** Authoring metadata: this Dropdown/Multi-Select sources values from records. */
266
272
  readonly dynamicSource?: true;
267
273
  /**
@@ -51,6 +51,7 @@ export const REF_SCOPE = {
51
51
  automation: "app",
52
52
  agent: "app",
53
53
  "agent-evaluation": "app",
54
+ sla: "app",
54
55
  chart: "app",
55
56
  dashboard: "app",
56
57
  widget: "app",
@@ -74,6 +75,7 @@ export const REF_SCOPE = {
74
75
  category: "org",
75
76
  group: "org",
76
77
  phoneProvider: "org",
78
+ voiceAuth: "org",
77
79
  "phone-service": "app",
78
80
  app: "registry",
79
81
  element: "registry",
@@ -104,6 +106,7 @@ export const REF_UPDATABLE = new Set([
104
106
  "automation",
105
107
  "agent",
106
108
  "agent-evaluation",
109
+ "sla",
107
110
  "skill",
108
111
  "approvalChain",
109
112
  "table",
@@ -48,7 +48,7 @@ export declare function isReadOnlySystemField(f: SystemFieldProbe): boolean;
48
48
  * Canonical `systemFields` bag key → platform semantic tag. These keys are the
49
49
  * ONLY authoring/catalog identity for system fields: pulled source keys its
50
50
  * hoisted refs and overrides by them, `ref()` exposes `fields.<key>` tokens
51
- * under them, and the custom `fields: {}` bag rejects them as collisions.
51
+ * under them, and a custom `fields:` key matching one is rejected at build (#1871).
52
52
  */
53
53
  export declare const SYSTEM_FIELD_TAG_BY_KEY: {
54
54
  readonly id: "HANDLE";
@@ -85,7 +85,7 @@ export function isReadOnlySystemField(f) {
85
85
  * Canonical `systemFields` bag key → platform semantic tag. These keys are the
86
86
  * ONLY authoring/catalog identity for system fields: pulled source keys its
87
87
  * hoisted refs and overrides by them, `ref()` exposes `fields.<key>` tokens
88
- * under them, and the custom `fields: {}` bag rejects them as collisions.
88
+ * under them, and a custom `fields:` key matching one is rejected at build (#1871).
89
89
  */
90
90
  export const SYSTEM_FIELD_TAG_BY_KEY = {
91
91
  id: "HANDLE",
@@ -142,6 +142,12 @@ export interface AspectFieldBase<Scope extends FieldScope = "unscoped"> {
142
142
  readonly tags?: readonly string[];
143
143
  readonly lockOnCreate?: boolean;
144
144
  readonly defaultValue?: unknown;
145
+ /**
146
+ * Natural bag key when pull re-keyed this field off a reserved system key
147
+ * (#1871). Build uses it as the terraform child part. Hand-authored
148
+ * fields omit this.
149
+ */
150
+ readonly resourceKey?: string;
145
151
  /**
146
152
  * Runtime metadata stamped on pulled fields by `print-aspect.ts`.
147
153
  * Records the variant the field was when pulled — `serializeAspectForUpdate`
@@ -6,6 +6,7 @@
6
6
  import type { ChildResourceScope, TfValue } from "../tf/index.js";
7
7
  import type { KindId } from "../../graph/types.js";
8
8
  import type { DeployableEntity } from "../entity.js";
9
+ import type { OptionIdIndex } from "../pull/field-refs-registry.js";
9
10
  export interface ForeignRootIdentity {
10
11
  readonly name: string;
11
12
  readonly namespace?: string;
@@ -124,6 +125,8 @@ export interface ToTfContext {
124
125
  readonly diagnostics: string[];
125
126
  /** Informational build reports, kept separate from warnings. */
126
127
  readonly reports?: string[];
128
+ /** Option ids known offline, for the raw-option-id warnings (#1733). */
129
+ readonly optionIds?: OptionIdIndex;
127
130
  /**
128
131
  * Every app/element stream root discovered in THIS build, keyed by
129
132
  * {@link workspaceAspectKey} — lets a cross-aspect reference (e.g. a
@@ -181,6 +181,7 @@ export function authoredAddressAmbiguityWarning(ambiguity) {
181
181
  * join throws rather than print one key twice.
182
182
  */
183
183
  function resolveAuthoredAddresses(importIds, authoredById, inState) {
184
+ assertEachObjectOnce(importIds);
184
185
  const exportAtSlot = new Map();
185
186
  for (const address of importIds.keys()) {
186
187
  const slot = labelSlot(address);
@@ -190,7 +191,11 @@ function resolveAuthoredAddresses(importIds, authoredById, inState) {
190
191
  else
191
192
  held.push(address);
192
193
  }
193
- const occupantsOf = (slot, except) => (exportAtSlot.get(slot) ?? []).filter((address) => address !== except);
194
+ // Export address → the authored address this pull moved it to.
195
+ const accepted = new Map();
196
+ // The export addresses still at a label. One this pull already moved has
197
+ // left it, so it holds nothing there (#2181).
198
+ const occupantsOf = (slot, except) => (exportAtSlot.get(slot) ?? []).filter((address) => address !== except && !accepted.has(address));
194
199
  const claimsBySlot = new Map();
195
200
  for (const [from, id] of importIds) {
196
201
  const type = addressType(from);
@@ -224,7 +229,6 @@ function resolveAuthoredAddresses(importIds, authoredById, inState) {
224
229
  // Authored labels of identities this export still has. One whose identity
225
230
  // is absent from the export was deleted live and does not hold its label.
226
231
  const liveAuthoredSlots = new Set([...authoredById].filter(([identity]) => exportIdentities.has(identity)).map(([, address]) => labelSlot(address)));
227
- const accepted = new Map();
228
232
  const acceptedSlots = new Set();
229
233
  const aliases = [];
230
234
  const accept = (from, to) => {
@@ -277,16 +281,16 @@ function resolveAuthoredAddresses(importIds, authoredById, inState) {
277
281
  for (let progressed = true; progressed && pending.size > 0;) {
278
282
  progressed = false;
279
283
  for (const [from, to] of pending) {
280
- const sourceId = importIds.get(from);
281
284
  const occupants = occupantsOf(labelSlot(to), from);
282
- const free = occupants.every((address) => canonicalImportId(importIds.get(address)) === canonicalImportId(sourceId));
283
- const vacated = occupants.length > 0 && occupants.every((address) => accepted.has(address));
285
+ // A label is free only when nothing sits on it. An occupant this pull
286
+ // already moved is not listed (#2181).
287
+ const free = occupants.length === 0;
284
288
  const occupant = occupants.length === 1 ? occupants[0] : undefined;
285
289
  const occupantIdentity = occupant === undefined ? undefined : typedIdentity(addressType(occupant), importIds.get(occupant));
286
290
  const occupantNew = occupantIdentity !== undefined && inState !== undefined && !inState.has(occupantIdentity) && !authoredById.has(occupantIdentity);
287
291
  const rotation = occupant !== undefined && pending.has(occupant) ? rotationFrom(from) : undefined;
288
292
  const occupantLabel = occupantNew ? freeLabelAfterChain(from) : undefined;
289
- if (free || vacated) {
293
+ if (free) {
290
294
  accept(from, to);
291
295
  pending.delete(from);
292
296
  }
@@ -335,6 +339,38 @@ function withLabelOf(address, labelSource) {
335
339
  function isFieldSlot(slot) {
336
340
  return slot.startsWith("\u0000field.");
337
341
  }
342
+ /**
343
+ * The export printed one platform object at two addresses. Renaming can't
344
+ * separate one object, so say what happened instead of asking for a rename
345
+ * (#2182).
346
+ */
347
+ function oneObjectTwiceError(addresses, id) {
348
+ return new Error(`pull stopped: the export holds one platform object twice, as ${addresses.join(" and ")} (both platform id ${id}). ` +
349
+ "They are the same object, so renaming can't separate them, and pulling both would bind it at two addresses. " +
350
+ "This is an export problem; report it with this message.");
351
+ }
352
+ /**
353
+ * Stop before any move when the export prints one platform object at two
354
+ * addresses (#2182): two blocks of one type with the same platform id, or two
355
+ * field blocks with the same platform id across field types (one field has
356
+ * one type, so its id at two field types is still one field). Moving or
357
+ * keeping either block would bind that object at two addresses. Other types
358
+ * may share a platform id on purpose (a composite resource exposes two
359
+ * provider types backed by one object), so only these two cases stop.
360
+ */
361
+ function assertEachObjectOnce(importIds) {
362
+ const seen = new Map();
363
+ for (const [address, importId] of importIds) {
364
+ const type = addressType(address);
365
+ if (type === undefined)
366
+ continue;
367
+ const key = FIELD_RESOURCE_TYPE_SET.has(type) ? `\u0000field\u0000${canonicalImportId(importId)}` : typedIdentity(type, importId);
368
+ const first = seen.get(key);
369
+ if (first !== undefined)
370
+ throw oneObjectTwiceError([first, address], canonicalImportId(importId));
371
+ seen.set(key, address);
372
+ }
373
+ }
338
374
  /**
339
375
  * Two fields at one label would print one bag key twice, and the build would
340
376
  * keep only the second, planning to replace the other's live field (#1859).
@@ -0,0 +1,88 @@
1
+ export type AuthoredRootBag = "apps" | "elements" | "tasks";
2
+ export interface AuthoredRoot {
3
+ readonly refName: string;
4
+ readonly namespace?: string;
5
+ }
6
+ export declare function readAuthoredRootNamespace(source: string): string | undefined;
7
+ export declare function listAuthoredRoots(orgRoot: string, bag: AuthoredRootBag): readonly AuthoredRoot[];
8
+ /**
9
+ * Last-write-wins namespace → refName index (same contract as the previous
10
+ * `readNamespaceMap` scan). Duplicate namespaces stay visible to
11
+ * {@link resolveAuthoredRootRefName} via {@link listAuthoredRoots}.
12
+ */
13
+ export declare function authoredNamespaceMap(orgRoot: string, bag: AuthoredRootBag): Map<string, string>;
14
+ /** Case-insensitive map lookup; exact key wins, otherwise a unique fold match. */
15
+ export declare function lookupNamespaceMap(map: ReadonlyMap<string, string>, namespace: string): string | undefined;
16
+ export interface ResolveAuthoredRootRefNameOptions {
17
+ readonly orgRoot: string;
18
+ readonly bag: AuthoredRootBag;
19
+ readonly liveNamespace: string;
20
+ readonly extractedRefName: string;
21
+ }
22
+ /**
23
+ * Existing authored stream-root whose identity matches `liveNamespace`, or
24
+ * `undefined` when pull should create/use the extract-derived path.
25
+ */
26
+ export declare function findAuthoredRootRefName(options: ResolveAuthoredRootRefNameOptions): string | undefined;
27
+ /**
28
+ * Pull keeps an app or element in `<bag>/<refName>/` only when that folder
29
+ * name isn't an org entry (edk#2839; `tables` only while a table catalog is
30
+ * emitted). Pulled source names a root by its folder (`catalog.<refName>`
31
+ * in agents, automations and fields), not by the barrel key, so an element
32
+ * the barrel exposes as `catalog.groups2` beside `apps/groups/` would still
33
+ * be printed as `catalog.groups`, the org entry. It moves to
34
+ * reservedRootFolder instead (`groups3`), where folder and key agree.
35
+ * `tablesEmitted` defaults to whether a table catalog is on disk.
36
+ */
37
+ export declare function rootIsShadowed(orgRoot: string, refName: string, tablesEmitted?: boolean): boolean;
38
+ /**
39
+ * Choose the on-disk stream-root refName to write/adopt. Prefers an existing
40
+ * authored tree whose `namespace:` matches the live namespace
41
+ * (case-insensitive). Falls back to a case-insensitive directory name match
42
+ * against the live namespace when the file has no parseable namespace.
43
+ * Otherwise returns the extracted refName (first pull), or
44
+ * {@link reservedRootFolder} (`users2`, …) when that is a reserved `@catalog`
45
+ * key (`users`, `groups`, …).
46
+ */
47
+ export declare function resolveAuthoredRootRefName(options: ResolveAuthoredRootRefNameOptions): string;
48
+ /**
49
+ * The folder for an app or element whose export ref name is a reserved
50
+ * `@catalog` key (`users` → `users2`, edk#2839). A `<base>N` folder in `bag`
51
+ * that already holds `liveNamespace` is reused (the lowest such N), so a
52
+ * re-pull keeps its folder. Otherwise the first `<base>N` (N ≥ 2) that no app
53
+ * or element folder uses and that isn't already another element's catalog
54
+ * key (`vacated` names the folder this root is leaving, whose key it takes):
55
+ * apps and elements share one key space, so a name taken there would shift a
56
+ * key (`elements/users2/` beside `apps/users2/` is `catalog.users22`).
57
+ */
58
+ export declare function reservedRootFolder(orgRoot: string, bag: "apps" | "elements", base: string, liveNamespace?: string, vacated?: string): string;
59
+ /**
60
+ * After pull wrote a root that moved off a reserved key (`users` →
61
+ * `users2`), remove the dependency stub an older pull left at
62
+ * `<bag>/<extractedRefName>/` (only `generated/`) when the barrel shadows
63
+ * it, so the workspace holds one tree for the namespace. Call it only once
64
+ * the new root is on disk. Source there is never touched. Returns whether it
65
+ * removed one.
66
+ */
67
+ export declare function retireShadowedStub(orgRoot: string, bag: AuthoredRootBag, extractedRefName: string, refName: string): boolean;
68
+ /**
69
+ * The log line for a pull that writes `<bag>/<refName>/` instead of the
70
+ * export's ref name: an existing authored tree, or a new folder because the
71
+ * export's name is a reserved `@catalog` key (edk#2839).
72
+ */
73
+ export declare function authoredRootChoiceMessage(orgRoot: string, bag: AuthoredRootBag, refName: string, extractedRefName: string, namespace: string): string;
74
+ /**
75
+ * Rewrite a pulled stream-root so printers emit the authored directory
76
+ * casing (`const eDKCloudBuilder`, `parent: "eDKCloudBuilder"`) instead of
77
+ * the extract-derived export label. Never touches `namespace` — that stays
78
+ * the live platform address.
79
+ */
80
+ export declare function rebindAuthoredRootRefName<T extends {
81
+ readonly refName: string;
82
+ }>(root: T, authoredRefName: string): T;
83
+ /**
84
+ * Rewrite extract-time owner handles on an own-file child (automation,
85
+ * agent, …) so printers emit `catalog.eDKCloudBuilder.fields…` instead of
86
+ * the export-label key (`catalog.edkcloudbuilder.fields…`).
87
+ */
88
+ export declare function rebindAuthoredOwnerRefs<T>(value: T, extractedOwnerRefName: string, authoredOwnerRefName: string): T;