@elevasis/core 0.1.0 → 0.2.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 (34) hide show
  1. package/dist/index.js +195 -3
  2. package/dist/organization-model/index.js +195 -3
  3. package/package.json +1 -1
  4. package/src/__tests__/template-foundations-compatibility.test.ts +95 -14
  5. package/src/auth/multi-tenancy/types.ts +2 -1
  6. package/src/execution/engine/__tests__/fixtures/test-agents.ts +4 -4
  7. package/src/execution/engine/index.ts +5 -19
  8. package/src/execution/engine/tools/platform/index.ts +9 -33
  9. package/src/execution/engine/tools/registry.ts +109 -2
  10. package/src/execution/engine/tools/tool-maps.ts +88 -0
  11. package/src/organization-model/README.md +19 -4
  12. package/src/organization-model/__tests__/graph.test.ts +612 -0
  13. package/src/organization-model/__tests__/resolve.test.ts +208 -0
  14. package/src/organization-model/defaults.ts +1 -1
  15. package/src/organization-model/organization-graph.mdx +262 -0
  16. package/src/organization-model/organization-model.mdx +257 -0
  17. package/src/organization-model/resolve.ts +26 -2
  18. package/src/organization-model/schema.ts +203 -1
  19. package/src/platform/constants/versions.ts +1 -1
  20. package/src/platform/registry/__tests__/resource-registry.integration.test.ts +24 -0
  21. package/src/platform/registry/__tests__/resource-registry.test.ts +63 -0
  22. package/src/platform/registry/resource-registry.ts +98 -10
  23. package/src/projects/api-schemas.ts +2 -1
  24. package/src/reference/_generated/contracts.md +1044 -0
  25. package/src/reference/glossary.md +88 -0
  26. package/src/server.ts +2 -3
  27. package/src/execution/engine/tools/platform/resource-invocation/__tests__/edge-cases.test.ts +0 -507
  28. package/src/execution/engine/tools/platform/resource-invocation/__tests__/resource-invocation-service.test.ts +0 -500
  29. package/src/execution/engine/tools/platform/resource-invocation/__tests__/tool.test.ts +0 -555
  30. package/src/execution/engine/tools/platform/resource-invocation/dynamic-tool.ts +0 -94
  31. package/src/execution/engine/tools/platform/resource-invocation/index.ts +0 -14
  32. package/src/execution/engine/tools/platform/resource-invocation/resource-invocation-service.ts +0 -147
  33. package/src/execution/engine/tools/platform/resource-invocation/tool.ts +0 -115
  34. package/src/execution/engine/tools/platform/resource-invocation/types.ts +0 -31
@@ -0,0 +1,257 @@
1
+ ---
2
+ title: Organization Model
3
+ description: Organization OS Model layer documentation for the semantic organization contract, covering domains, features, navigation surfaces, resource mappings, and the curated @elevasis/core public API.
4
+ ---
5
+
6
+ ## Overview
7
+
8
+ Within Organization OS, the organization model is the **Model** layer and part of the cross-cutting **Public API** layer. It is the semantic contract that maps an organization's product shape to domains, features, navigation surfaces and groups, domain-specific semantics (CRM pipeline, lead-gen lifecycle, delivery status), and resource mappings. It is schema-first, versioned, and validated.
9
+
10
+ The model is authored in `@repo/core` and published as a curated external package `@elevasis/core`. It is consumed by:
11
+
12
+ - `@repo/ui`'s feature-shell provider to resolve nav labels, surface paths, and feature state at runtime
13
+ - command-center's root shell as its canonical organization model
14
+ - `external/_template/foundations` and downstream derivatives as the adapter-backed source of organization truth
15
+
16
+ The model does **not** replace the shared feature-provider system. It enriches and constrains it.
17
+
18
+ ## Source of Truth
19
+
20
+ - `packages/core/src/organization-model/schema.ts` -- `OrganizationModelSchema`
21
+ - `packages/core/src/organization-model/types.ts` -- exported TypeScript types
22
+ - `packages/core/src/organization-model/defaults.ts` -- `DEFAULT_ORGANIZATION_MODEL`
23
+ - `packages/core/src/organization-model/resolve.ts` -- `defineOrganizationModel`, `resolveOrganizationModel`
24
+ - `packages/core/src/organization-model/domains/*.ts` -- feature keys, navigation surfaces, CRM/lead-gen/delivery semantics
25
+ - `packages/core/src/published.ts` -- curated root barrel for the published package
26
+ - `packages/core/src/organization-model/published.ts` -- curated organization-model barrel
27
+ - `packages/core/src/__tests__/template-foundations-compatibility.test.ts` -- adapter-baseline guard
28
+
29
+ ## Contract Shape
30
+
31
+ Top-level fields on `OrganizationModel`:
32
+
33
+ - `version`
34
+ - `domains` -- semantic domains (`crm`, `lead-gen`, `delivery`, `operations`)
35
+ - `branding`
36
+ - `features` -- `enabled` map and `labels` overrides
37
+ - `navigation` -- surfaces, groups, `defaultSurfaceId`
38
+ - `crm` -- pipeline stages and stage semantics
39
+ - `leadGen` -- company/contact lifecycle stages
40
+ - `delivery` -- project/milestone/task statuses
41
+ - `resourceMappings`
42
+
43
+ ### Branding Shape
44
+
45
+ `OrganizationModelBranding` holds display identity for the organization:
46
+
47
+ - `organizationName` -- the human-readable org name (required)
48
+ - `productName` -- the product label shown in the shell (required)
49
+ - `shortName` -- abbreviated name, max 40 chars (required)
50
+ - `description` -- optional long-form description
51
+ - `logos` -- optional object with `light` and `dark` URL strings (each max 2048 chars); defaults to `{}`
52
+
53
+ ### ModelId Format Rules
54
+
55
+ All `id` fields, `parentId`, `defaultSurfaceId`, and reference ID arrays use `ModelIdSchema`:
56
+
57
+ - Regex: `/^[a-z0-9]+(?:[-._][a-z0-9]+)*$/`
58
+ - Max length: 100 chars
59
+ - Allowed separators: `-`, `_`, `.`
60
+ - Examples: `crm.pipeline`, `lead-gen.lists`, `operations.organization-graph`
61
+
62
+ This applies to domain IDs, surface IDs, navigation group IDs, and resource mapping IDs.
63
+
64
+ ### Default Feature Keys
65
+
66
+ ```ts
67
+ type OrganizationModelFeatureKey =
68
+ | 'acquisition'
69
+ | 'delivery'
70
+ | 'operations'
71
+ | 'monitoring'
72
+ | 'settings'
73
+ | 'seo'
74
+ | 'calibration'
75
+ ```
76
+
77
+ These are the **grouped** published access/visibility keys. They differ from shell feature-module keys (`crm`, `lead-gen`, `delivery`). See [Feature Shell](../ui/feature-shell.mdx) for how the provider bridges the two.
78
+
79
+ ### Default Semantic Domains
80
+
81
+ Four domains ship by default -- `crm`, `lead-gen`, `delivery`, `operations`. Each binds together entity IDs, surface IDs, resource IDs, and capability IDs. Domains are semantic, not purely navigational -- they describe what area of the business or resource model a thing belongs to, not which access key gates it.
82
+
83
+ ### ResourceMapping Shape
84
+
85
+ `OrganizationModelResourceMapping` links a deployable resource into the semantic model:
86
+
87
+ - `id` -- unique mapping ID (ModelId format)
88
+ - `resourceId` -- the actual resource identifier (string, max 255 chars)
89
+ - `resourceType` -- one of `'workflow' | 'agent' | 'trigger' | 'integration' | 'external' | 'human_checkpoint'`
90
+ - `label`, `description`, `color`, `icon` -- display metadata (from `DisplayMetadataSchema`)
91
+ - `domainIds` -- domains this resource belongs to
92
+ - `entityIds` -- entities this resource operates on
93
+ - `surfaceIds` -- surfaces this resource is exposed in
94
+ - `capabilityIds` -- capabilities this resource fulfills
95
+
96
+ All four ID arrays are bidirectionally validated against their counterparts (see Referential Integrity).
97
+
98
+ ### Default Navigation
99
+
100
+ Surfaces such as `crm.pipeline`, `lead-gen.lists`, `projects.index`, `operations.organization-graph`, and `operations.command-view`. Groups include `primary-workspace` and `primary-operations`. The model can shape shell meaning even when route files stay app-local.
101
+
102
+ ### SurfaceDefinition Shape
103
+
104
+ `OrganizationModelSurface` (inferred from `SurfaceDefinitionSchema`) defines a navigable view:
105
+
106
+ - `id` -- ModelId (e.g. `crm.pipeline`)
107
+ - `label` -- display name
108
+ - `path` -- route path, must start with `/`, max 300 chars
109
+ - `surfaceType` -- `'page' | 'dashboard' | 'graph' | 'detail' | 'list' | 'settings'`
110
+ - `description` -- optional
111
+ - `icon` -- optional icon name token (max 80 chars)
112
+ - `featureKey` -- optional `OrganizationModelFeatureKey` that gates this surface
113
+ - `parentId` -- optional ModelId referencing a parent surface; validated to exist
114
+ - `domainIds` -- domains this surface belongs to (bidirectionally validated)
115
+ - `entityIds` -- entity IDs relevant to this surface
116
+ - `resourceIds` -- resources exposed on this surface (bidirectionally validated against resource mappings)
117
+ - `capabilityIds` -- capabilities this surface fulfills
118
+
119
+ ### NavigationGroup Placement
120
+
121
+ `NavigationGroupSchema` has a `placement` field with three allowed values:
122
+
123
+ - `'primary'` -- main workspace or operations nav rail
124
+ - `'secondary'` -- secondary grouping (below primary)
125
+ - `'bottom'` -- pinned to the bottom of the nav rail
126
+
127
+ The default groups (`primary-workspace`, `primary-operations`) both use `placement: 'primary'`.
128
+
129
+ ### Domain-Specific Semantics
130
+
131
+ - **CRM** -- pipeline stages and stage semantics
132
+ - **Lead-gen** -- company and contact lifecycle stages
133
+ - **Delivery** -- project, milestone, and task statuses
134
+
135
+ This is why the organization model is semantic, not just nav config -- it owns product meaning for the business objects the shell surfaces expose.
136
+
137
+ ## Authoring & Resolution
138
+
139
+ - `defineOrganizationModel()` -- typed authoring helper; returns the input unchanged but constrains the type.
140
+ - `resolveOrganizationModel(partial)` -- deep-merges a partial override into `DEFAULT_ORGANIZATION_MODEL` and validates the result against `OrganizationModelSchema`.
141
+
142
+ Merge semantics:
143
+
144
+ - plain objects merge recursively
145
+ - arrays **replace** defaults (no element-by-element merge)
146
+ - if `navigation.surfaces` is replaced without also supplying `navigation.groups`, inherited groups are normalized so they only keep still-valid surface IDs and any now-empty groups are dropped
147
+ - missing fields fall back to defaults
148
+
149
+ ### Referential Integrity
150
+
151
+ `OrganizationModelSchema` validates more than top-level shape. The `superRefine` pass enforces:
152
+
153
+ **Uniqueness checks** -- IDs must be unique within their respective collections:
154
+
155
+ - `domains[].id`
156
+ - `navigation.surfaces[].id`
157
+ - `navigation.groups[].id`
158
+ - `resourceMappings[].id`
159
+ - `resourceMappings[].resourceId` (separate uniqueness check -- two mappings cannot share a `resourceId`)
160
+
161
+ **Dangling reference detection** -- every cross-reference must resolve:
162
+
163
+ - `navigation.defaultSurfaceId` must point at a declared surface
164
+ - every `surfaceId` in a navigation group must resolve to a declared surface
165
+ - every `surfaceId` in a domain must resolve to a declared surface
166
+ - every `resourceId` in a domain must resolve to a declared resource mapping (by `resourceId`)
167
+ - surface `parentId` must reference an existing surface
168
+ - every `domainId` on a surface must resolve to a declared domain
169
+ - every `resourceId` on a surface must resolve to a declared resource mapping
170
+ - every `domainId` on a resource mapping must resolve to a declared domain
171
+ - every `surfaceId` on a resource mapping must resolve to a declared surface
172
+
173
+ **Bidirectional reference enforcement** -- cross-references must be mutual, not one-sided:
174
+
175
+ - a domain listing `surfaceId` S requires surface S to list that domain's ID in its `domainIds`
176
+ - a surface listing `domainId` D requires domain D to list that surface's ID in its `surfaceIds`
177
+ - a domain listing `resourceId` R requires resource mapping R to list that domain's ID in its `domainIds`
178
+ - a resource mapping listing `domainId` D requires domain D to list that resource's `resourceId` in its `resourceIds`
179
+ - a surface listing `resourceId` R requires resource mapping R to list that surface's ID in its `surfaceIds`
180
+ - a resource mapping listing `surfaceId` S requires surface S to list that resource's `resourceId` in its `resourceIds`
181
+
182
+ This bidirectional enforcement is what keeps the organization model semantically consistent rather than loosely structured config.
183
+
184
+ ## Provider Integration
185
+
186
+ `ElevasisFeaturesProvider` uses the organization model in three ways:
187
+
188
+ 1. **Feature resolution** -- provider first checks `useFeatureAccess()`, then refines through organization-model feature state when the model knows the key.
189
+ 2. **Nav label and path resolution** -- when `organizationModel` is present, feature labels resolve from `organizationModel.features.labels`, and surface labels and paths resolve from `organizationModel.navigation.surfaces`. Semantic customization without changing manifest code.
190
+ 3. **Organization-graph bridge** -- the `operationsManifest` declares `organizationGraph.surfaceId = 'operations.organization-graph'`. The provider resolves that against organization-model surfaces and exposes the result as `organizationGraph` in context. See [Organization Graph](./organization-graph.mdx).
191
+
192
+ ## Published Package: `@elevasis/core`
193
+
194
+ `@elevasis/core` is a curated publish wrapper around `packages/core`, released through `$sdk release-core`. It exists so external foundations (`_template/foundations`, `nirvana-marketing/foundations`, `ZentaraHQ/foundations`) can depend on a stable, browser-safe organization-model contract without reaching into monorepo-only `@repo/core`.
195
+
196
+ ### Published surface
197
+
198
+ Intentionally narrow:
199
+
200
+ - `.` -- curated root barrel (`packages/core/src/published.ts`)
201
+ - `./organization-model` -- curated organization-model barrel (`packages/core/src/organization-model/published.ts`)
202
+
203
+ Exports on the first published surface:
204
+
205
+ - `OrganizationModelSchema`
206
+ - top-level organization-model types
207
+ - `DEFAULT_ORGANIZATION_MODEL`
208
+ - `defineOrganizationModel`
209
+ - `resolveOrganizationModel`
210
+
211
+ ### Intentionally excluded
212
+
213
+ - wider `@repo/core` browser barrel
214
+ - organization-graph types/builder (`buildOrganizationGraph`, DTO types) -- graph work remains monorepo-first; external consumers should not assume graph contracts are published
215
+
216
+ ### Build
217
+
218
+ - `pnpm --filter @repo/core build:publish` emits `dist/index.{js,d.ts}` and `dist/organization-model/index.{js,d.ts}` via tsup + `rollup-plugin-dts`.
219
+ - Shipped types are browser-safe and verified to contain no `@repo/*` imports.
220
+
221
+ ### Release
222
+
223
+ - `.claude/sub-commands/sdk/release-core.md` -- dedicated publish flow
224
+ - `$sdk verify` -- covers publish metadata, bundled declarations, and the first template-foundation compatibility guard
225
+
226
+ ## Downstream Adoption
227
+
228
+ External foundations consume `@elevasis/core/organization-model` via an **adapter**, not a fork. The adapter pattern in `external/_template/foundations/config/organization-model.ts`:
229
+
230
+ 1. Define a canonical override with `defineOrganizationModel(...)`.
231
+ 2. Resolve it with `resolveOrganizationModel(...)`.
232
+ 3. Adapt the result into a template-local helper shape that adds consumer-only fields (`homeLabel`, `quickAccessSurfaceIds`, icon aliases, `getOrganizationSurface()`).
233
+
234
+ Exports the foundations module provides to consumers:
235
+
236
+ - `canonicalOrganizationModel` -- passed to `ElevasisFeaturesProvider`
237
+ - `organizationModel` -- widened adapter shape for template-local helpers
238
+ - `FoundationFeatureKey`, `FoundationSurfaceIcon`, `FoundationNavigationSurface`, `FoundationOrganizationModel`
239
+ - `homeLabel`, `quickAccessSurfaceIds`, `getOrganizationSurface(surfaceId)`
240
+
241
+ Downstream template shells pass `canonicalOrganizationModel` into `ElevasisFeaturesProvider`, preserving host-local dashboard/nav customizations alongside the shared runtime. Grouped core features map onto template vocabulary -- `crm` and `lead-gen` project from `acquisition`, `projects` from `delivery`.
242
+
243
+ Derivative projects (`external/nirvana-marketing`, `external/ZentaraHQ`) follow the same adapter + provider-wiring baseline with their own project-local customizations.
244
+
245
+ ## Verification
246
+
247
+ - `pnpm --filter @repo/core build:publish` -- published bundle
248
+ - `pnpm --filter @repo/core test -- publish template-foundations-compatibility` -- published surface + adapter guard
249
+ - `pnpm -C external/_template/foundations test` -- foundations adapter and import-boundary guard
250
+ - `pnpm -C external/_template/ui test -- src/routes/__tests__/__root.test.tsx` -- provider-level `organizationModel` wiring in the template shell
251
+
252
+ ## Design Constraints
253
+
254
+ - `@elevasis/core` must stay browser-safe. Build output inlines or eliminates `@repo/*` references from shipped types.
255
+ - The published surface stays curated -- do not reflexively re-export new `@repo/core` internals. Widening the surface is a deliberate decision, not a default.
256
+ - Organization-graph helpers remain internal until a concrete external consumer needs them.
257
+ - Foundations adapters preserve the semantic contract; they do not fork it. If a template needs a concept the canonical model can't express, extend the canonical model first.
@@ -31,12 +31,36 @@ function deepMerge<T>(base: T, override: DeepPartial<T> | undefined): T {
31
31
  return result as T
32
32
  }
33
33
 
34
+ function normalizeInheritedNavigationGroups(
35
+ model: OrganizationModel,
36
+ override?: DeepPartial<OrganizationModel>
37
+ ): OrganizationModel {
38
+ if (override?.navigation?.surfaces === undefined || override.navigation.groups !== undefined) {
39
+ return model
40
+ }
41
+
42
+ const validSurfaceIds = new Set(model.navigation.surfaces.map((surface) => surface.id))
43
+ const groups = model.navigation.groups
44
+ .map((group) => ({
45
+ ...group,
46
+ surfaceIds: group.surfaceIds.filter((surfaceId) => validSurfaceIds.has(surfaceId))
47
+ }))
48
+ .filter((group) => group.surfaceIds.length > 0)
49
+
50
+ return {
51
+ ...model,
52
+ navigation: {
53
+ ...model.navigation,
54
+ groups
55
+ }
56
+ }
57
+ }
58
+
34
59
  export function defineOrganizationModel<T extends DeepPartial<OrganizationModel>>(model: T): T {
35
60
  return model
36
61
  }
37
62
 
38
63
  export function resolveOrganizationModel(override?: DeepPartial<OrganizationModel>): OrganizationModel {
39
- const merged = deepMerge(DEFAULT_ORGANIZATION_MODEL, override)
64
+ const merged = normalizeInheritedNavigationGroups(deepMerge(DEFAULT_ORGANIZATION_MODEL, override), override)
40
65
  return OrganizationModelSchema.parse(merged)
41
66
  }
42
-
@@ -7,7 +7,7 @@ import { OrganizationModelLeadGenSchema } from './domains/lead-gen'
7
7
  import { OrganizationModelNavigationSchema } from './domains/navigation'
8
8
  import { ResourceMappingSchema, SemanticDomainSchema } from './domains/shared'
9
9
 
10
- export const OrganizationModelSchema = z.object({
10
+ const OrganizationModelSchemaBase = z.object({
11
11
  version: z.literal(1).default(1),
12
12
  domains: z.array(SemanticDomainSchema).default([]),
13
13
  branding: OrganizationModelBrandingSchema,
@@ -19,3 +19,205 @@ export const OrganizationModelSchema = z.object({
19
19
  resourceMappings: z.array(ResourceMappingSchema).default([])
20
20
  })
21
21
 
22
+ function addIssue(ctx: z.RefinementCtx, path: Array<string | number>, message: string): void {
23
+ ctx.addIssue({
24
+ code: z.ZodIssueCode.custom,
25
+ path,
26
+ message
27
+ })
28
+ }
29
+
30
+ function collectIds<T extends { id: string }>(
31
+ items: T[],
32
+ ctx: z.RefinementCtx,
33
+ collectionPath: Array<string | number>,
34
+ label: string
35
+ ): Map<string, T> {
36
+ const itemsById = new Map<string, T>()
37
+
38
+ items.forEach((item, index) => {
39
+ if (itemsById.has(item.id)) {
40
+ addIssue(ctx, [...collectionPath, index, 'id'], `${label} id "${item.id}" must be unique`)
41
+ return
42
+ }
43
+
44
+ itemsById.set(item.id, item)
45
+ })
46
+
47
+ return itemsById
48
+ }
49
+
50
+ export const OrganizationModelSchema = OrganizationModelSchemaBase.superRefine((model, ctx) => {
51
+ const domainsById = collectIds(model.domains, ctx, ['domains'], 'Domain')
52
+ const surfacesById = collectIds(model.navigation.surfaces, ctx, ['navigation', 'surfaces'], 'Surface')
53
+ collectIds(model.navigation.groups, ctx, ['navigation', 'groups'], 'Navigation group')
54
+ collectIds(model.resourceMappings, ctx, ['resourceMappings'], 'Resource mapping')
55
+
56
+ const resourceMappingsByResourceId = new Map<string, (typeof model.resourceMappings)[number]>()
57
+ model.resourceMappings.forEach((resourceMapping, index) => {
58
+ if (resourceMappingsByResourceId.has(resourceMapping.resourceId)) {
59
+ addIssue(
60
+ ctx,
61
+ ['resourceMappings', index, 'resourceId'],
62
+ `Resource mapping resourceId "${resourceMapping.resourceId}" must be unique`
63
+ )
64
+ return
65
+ }
66
+
67
+ resourceMappingsByResourceId.set(resourceMapping.resourceId, resourceMapping)
68
+ })
69
+
70
+ if (model.navigation.defaultSurfaceId && !surfacesById.has(model.navigation.defaultSurfaceId)) {
71
+ addIssue(
72
+ ctx,
73
+ ['navigation', 'defaultSurfaceId'],
74
+ `Default surface "${model.navigation.defaultSurfaceId}" must reference a declared navigation surface`
75
+ )
76
+ }
77
+
78
+ model.navigation.groups.forEach((group, groupIndex) => {
79
+ group.surfaceIds.forEach((surfaceId, surfaceIndex) => {
80
+ if (!surfacesById.has(surfaceId)) {
81
+ addIssue(
82
+ ctx,
83
+ ['navigation', 'groups', groupIndex, 'surfaceIds', surfaceIndex],
84
+ `Navigation group "${group.id}" references unknown surface "${surfaceId}"`
85
+ )
86
+ }
87
+ })
88
+ })
89
+
90
+ model.domains.forEach((domain, domainIndex) => {
91
+ domain.surfaceIds.forEach((surfaceId, surfaceIndex) => {
92
+ const surface = surfacesById.get(surfaceId)
93
+ if (!surface) {
94
+ addIssue(
95
+ ctx,
96
+ ['domains', domainIndex, 'surfaceIds', surfaceIndex],
97
+ `Domain "${domain.id}" references unknown surface "${surfaceId}"`
98
+ )
99
+ return
100
+ }
101
+
102
+ if (!surface.domainIds.includes(domain.id)) {
103
+ addIssue(
104
+ ctx,
105
+ ['domains', domainIndex, 'surfaceIds', surfaceIndex],
106
+ `Domain "${domain.id}" references surface "${surfaceId}" but that surface does not include domain "${domain.id}"`
107
+ )
108
+ }
109
+ })
110
+
111
+ domain.resourceIds.forEach((resourceId, resourceIndex) => {
112
+ const resourceMapping = resourceMappingsByResourceId.get(resourceId)
113
+ if (!resourceMapping) {
114
+ addIssue(
115
+ ctx,
116
+ ['domains', domainIndex, 'resourceIds', resourceIndex],
117
+ `Domain "${domain.id}" references unknown resource "${resourceId}"`
118
+ )
119
+ return
120
+ }
121
+
122
+ if (!resourceMapping.domainIds.includes(domain.id)) {
123
+ addIssue(
124
+ ctx,
125
+ ['domains', domainIndex, 'resourceIds', resourceIndex],
126
+ `Domain "${domain.id}" references resource "${resourceId}" but that resource mapping does not include domain "${domain.id}"`
127
+ )
128
+ }
129
+ })
130
+ })
131
+
132
+ model.navigation.surfaces.forEach((surface, surfaceIndex) => {
133
+ if (surface.parentId && !surfacesById.has(surface.parentId)) {
134
+ addIssue(
135
+ ctx,
136
+ ['navigation', 'surfaces', surfaceIndex, 'parentId'],
137
+ `Surface "${surface.id}" references unknown parent surface "${surface.parentId}"`
138
+ )
139
+ }
140
+
141
+ surface.domainIds.forEach((domainId, domainIndex) => {
142
+ const domain = domainsById.get(domainId)
143
+ if (!domain) {
144
+ addIssue(
145
+ ctx,
146
+ ['navigation', 'surfaces', surfaceIndex, 'domainIds', domainIndex],
147
+ `Surface "${surface.id}" references unknown domain "${domainId}"`
148
+ )
149
+ return
150
+ }
151
+
152
+ if (!domain.surfaceIds.includes(surface.id)) {
153
+ addIssue(
154
+ ctx,
155
+ ['navigation', 'surfaces', surfaceIndex, 'domainIds', domainIndex],
156
+ `Surface "${surface.id}" references domain "${domainId}" but that domain does not include surface "${surface.id}"`
157
+ )
158
+ }
159
+ })
160
+
161
+ surface.resourceIds.forEach((resourceId, resourceIndex) => {
162
+ const resourceMapping = resourceMappingsByResourceId.get(resourceId)
163
+ if (!resourceMapping) {
164
+ addIssue(
165
+ ctx,
166
+ ['navigation', 'surfaces', surfaceIndex, 'resourceIds', resourceIndex],
167
+ `Surface "${surface.id}" references unknown resource "${resourceId}"`
168
+ )
169
+ return
170
+ }
171
+
172
+ if (!resourceMapping.surfaceIds.includes(surface.id)) {
173
+ addIssue(
174
+ ctx,
175
+ ['navigation', 'surfaces', surfaceIndex, 'resourceIds', resourceIndex],
176
+ `Surface "${surface.id}" references resource "${resourceId}" but that resource mapping does not include surface "${surface.id}"`
177
+ )
178
+ }
179
+ })
180
+ })
181
+
182
+ model.resourceMappings.forEach((resourceMapping, resourceIndex) => {
183
+ resourceMapping.domainIds.forEach((domainId, domainIndex) => {
184
+ const domain = domainsById.get(domainId)
185
+ if (!domain) {
186
+ addIssue(
187
+ ctx,
188
+ ['resourceMappings', resourceIndex, 'domainIds', domainIndex],
189
+ `Resource mapping "${resourceMapping.id}" references unknown domain "${domainId}"`
190
+ )
191
+ return
192
+ }
193
+
194
+ if (!domain.resourceIds.includes(resourceMapping.resourceId)) {
195
+ addIssue(
196
+ ctx,
197
+ ['resourceMappings', resourceIndex, 'domainIds', domainIndex],
198
+ `Resource mapping "${resourceMapping.id}" references domain "${domainId}" but that domain does not include resource "${resourceMapping.resourceId}"`
199
+ )
200
+ }
201
+ })
202
+
203
+ resourceMapping.surfaceIds.forEach((surfaceId, surfaceIndex) => {
204
+ const surface = surfacesById.get(surfaceId)
205
+ if (!surface) {
206
+ addIssue(
207
+ ctx,
208
+ ['resourceMappings', resourceIndex, 'surfaceIds', surfaceIndex],
209
+ `Resource mapping "${resourceMapping.id}" references unknown surface "${surfaceId}"`
210
+ )
211
+ return
212
+ }
213
+
214
+ if (!surface.resourceIds.includes(resourceMapping.resourceId)) {
215
+ addIssue(
216
+ ctx,
217
+ ['resourceMappings', resourceIndex, 'surfaceIds', surfaceIndex],
218
+ `Resource mapping "${resourceMapping.id}" references surface "${surfaceId}" but that surface does not include resource "${resourceMapping.resourceId}"`
219
+ )
220
+ }
221
+ })
222
+ })
223
+ })
@@ -1,3 +1,3 @@
1
1
  export const VERSION = {
2
- CURRENT: '1.5.5'
2
+ CURRENT: '1.5.6'
3
3
  }
@@ -892,6 +892,18 @@ describe('ResourceRegistry Integration', () => {
892
892
  // Deploy stubs with their own relationships
893
893
  const stubs: DeploymentSpec = {
894
894
  workflows: [createMockWorkflow('remote-workflow')],
895
+ integrations: [
896
+ {
897
+ resourceId: 'integration-crm',
898
+ type: 'integration',
899
+ version: '1.0.0',
900
+ status: 'dev',
901
+ provider: 'crm',
902
+ credentialName: 'crm-cred',
903
+ name: 'CRM',
904
+ description: 'CRM integration'
905
+ }
906
+ ],
895
907
  relationships: {
896
908
  'remote-workflow': {
897
909
  uses: { integrations: ['integration-crm'] }
@@ -979,6 +991,18 @@ describe('ResourceRegistry Integration', () => {
979
991
  // Register remote stubs with relationships
980
992
  const stubs: DeploymentSpec = {
981
993
  workflows: [createMockWorkflow('remote-workflow')],
994
+ integrations: [
995
+ {
996
+ resourceId: 'integration-crm',
997
+ type: 'integration',
998
+ version: '1.0.0',
999
+ status: 'dev',
1000
+ provider: 'crm',
1001
+ credentialName: 'crm-cred',
1002
+ name: 'CRM',
1003
+ description: 'CRM integration'
1004
+ }
1005
+ ],
982
1006
  relationships: {
983
1007
  'remote-workflow': {
984
1008
  triggers: { workflows: ['static-workflow'] },
@@ -1611,6 +1611,31 @@ describe('ResourceRegistry', () => {
1611
1611
  registry.registerOrganization('new-org', { workflows: [workflow1, workflow2] }, createMockRemoteConfig())
1612
1612
  }).toThrow("Duplicate resource ID 'dup-id' in deployment")
1613
1613
  })
1614
+
1615
+ it('throws a validation error when incoming relationships reference missing resources after merge', () => {
1616
+ const remoteWorkflow = createMockWorkflow('remote-wf')
1617
+
1618
+ const registry = new ResourceRegistry({
1619
+ 'test-org': {
1620
+ workflows: [createMockWorkflow('static-wf')]
1621
+ }
1622
+ })
1623
+
1624
+ expect(() => {
1625
+ registry.registerOrganization(
1626
+ 'test-org',
1627
+ {
1628
+ workflows: [remoteWorkflow],
1629
+ relationships: {
1630
+ 'remote-wf': {
1631
+ triggers: { workflows: ['missing-target'] }
1632
+ }
1633
+ }
1634
+ },
1635
+ createMockRemoteConfig()
1636
+ )
1637
+ }).toThrow("[test-org] Resource 'remote-wf' triggers non-existent workflow: missing-target")
1638
+ })
1614
1639
  })
1615
1640
 
1616
1641
  describe('registerOrganization -- new org (no static resources)', () => {
@@ -1783,6 +1808,44 @@ describe('ResourceRegistry', () => {
1783
1808
  expect(config?.deploymentId).toBe('deploy-new')
1784
1809
  expect(config?.storagePath).toBe('test-org/deploy-new/bundle.js')
1785
1810
  })
1811
+
1812
+ it('preserves the current remote deployment when a redeploy fails merged validation', () => {
1813
+ const staticWorkflow = createMockWorkflow('static-wf')
1814
+ const remoteWorkflow = createMockWorkflow('remote-wf')
1815
+ const replacementWorkflow = createMockWorkflow('remote-wf-v2')
1816
+
1817
+ const registry = new ResourceRegistry({
1818
+ 'test-org': {
1819
+ workflows: [staticWorkflow]
1820
+ }
1821
+ })
1822
+
1823
+ registry.registerOrganization(
1824
+ 'test-org',
1825
+ {
1826
+ workflows: [remoteWorkflow],
1827
+ relationships: {
1828
+ 'static-wf': {
1829
+ triggers: { workflows: ['remote-wf'] }
1830
+ }
1831
+ }
1832
+ },
1833
+ createMockRemoteConfig({ deploymentId: 'deploy-old' })
1834
+ )
1835
+
1836
+ expect(() => {
1837
+ registry.registerOrganization(
1838
+ 'test-org',
1839
+ { workflows: [replacementWorkflow] },
1840
+ createMockRemoteConfig({ deploymentId: 'deploy-new' })
1841
+ )
1842
+ }).toThrow("[test-org] Resource 'static-wf' triggers non-existent workflow: remote-wf")
1843
+
1844
+ const result = registry.listResourcesForOrganization('test-org')
1845
+ expect(result.workflows.find((w) => w.resourceId === 'remote-wf')).toBeDefined()
1846
+ expect(result.workflows.find((w) => w.resourceId === 'remote-wf-v2')).toBeUndefined()
1847
+ expect(registry.getRemoteConfig('test-org', 'remote-wf')?.deploymentId).toBe('deploy-old')
1848
+ })
1786
1849
  })
1787
1850
 
1788
1851
  describe('environment filter with remote resources', () => {