@wildo-ai/platform-config-lib 1.1.2 → 1.1.4

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 (130) hide show
  1. package/dist/esm/bootstrap/application-backend-env.contracts.d.ts.map +1 -1
  2. package/dist/esm/bootstrap/bootstrap-planner.d.ts.map +1 -1
  3. package/dist/esm/bootstrap/bootstrap.contracts.d.ts.map +1 -1
  4. package/dist/esm/bootstrap/bootstrap.schemas.d.ts +129 -1
  5. package/dist/esm/bootstrap/bootstrap.schemas.d.ts.map +1 -1
  6. package/dist/esm/bootstrap/bootstrap.schemas.js +105 -2
  7. package/dist/esm/bootstrap/bootstrap.schemas.js.map +1 -1
  8. package/dist/esm/bootstrap/platform-runtime-env.contracts.d.ts +6 -3
  9. package/dist/esm/bootstrap/platform-runtime-env.contracts.d.ts.map +1 -1
  10. package/dist/esm/bootstrap/platform-runtime-env.contracts.js +18 -3
  11. package/dist/esm/bootstrap/platform-runtime-env.contracts.js.map +1 -1
  12. package/dist/esm/bootstrap/runtime-backing-service-access.d.ts.map +1 -1
  13. package/dist/esm/bootstrap/runtime-network-policy.d.ts.map +1 -1
  14. package/dist/esm/bootstrap/runtime-network-topology.d.ts +0 -1
  15. package/dist/esm/bootstrap/runtime-network-topology.d.ts.map +1 -1
  16. package/dist/esm/bootstrap/runtime-network-topology.js +0 -2
  17. package/dist/esm/bootstrap/runtime-network-topology.js.map +1 -1
  18. package/dist/esm/bootstrap/runtime-platform-access.d.ts.map +1 -1
  19. package/dist/esm/bootstrap/runtime-principal.contracts.d.ts.map +1 -1
  20. package/dist/esm/bootstrap/runtime-topology.contracts.d.ts.map +1 -1
  21. package/dist/esm/config-authoring.entry.d.ts +1 -2
  22. package/dist/esm/config-authoring.entry.d.ts.map +1 -1
  23. package/dist/esm/config-authoring.entry.js +35 -2
  24. package/dist/esm/config-authoring.entry.js.map +1 -1
  25. package/dist/esm/index.d.ts.map +1 -1
  26. package/dist/esm/lockfile/lockfile-io.d.ts.map +1 -1
  27. package/dist/esm/lockfile/materialize-infra-section.d.ts.map +1 -1
  28. package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.d.ts +0 -20
  29. package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.d.ts.map +1 -1
  30. package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.js +0 -1
  31. package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.js.map +1 -1
  32. package/dist/esm/project-config/define-framework-config.d.ts.map +1 -1
  33. package/dist/esm/project-config/define-infra-env-config.d.ts +3 -39
  34. package/dist/esm/project-config/define-infra-env-config.d.ts.map +1 -1
  35. package/dist/esm/project-config/define-infra-env-config.js +2 -2
  36. package/dist/esm/project-config/define-infra-env-config.js.map +1 -1
  37. package/dist/esm/project-config/define-minion-config.d.ts.map +1 -1
  38. package/dist/esm/project-config/define-saas-config.d.ts +366 -14
  39. package/dist/esm/project-config/define-saas-config.d.ts.map +1 -1
  40. package/dist/esm/project-config/define-saas-config.js +121 -11
  41. package/dist/esm/project-config/define-saas-config.js.map +1 -1
  42. package/dist/esm/project-config/define-worker-config.d.ts.map +1 -1
  43. package/dist/esm/project-config/index.d.ts.map +1 -1
  44. package/dist/esm/project-config/loader.d.ts.map +1 -1
  45. package/dist/esm/project-config/provider-catalog-types.d.ts.map +1 -1
  46. package/dist/esm/project-config/provider-companion-discovery.d.ts +88 -1
  47. package/dist/esm/project-config/provider-companion-discovery.d.ts.map +1 -1
  48. package/dist/esm/project-config/provider-companion-discovery.js +275 -6
  49. package/dist/esm/project-config/provider-companion-discovery.js.map +1 -1
  50. package/dist/esm/project-config/provider-runtime-artifacts.d.ts +42 -16
  51. package/dist/esm/project-config/provider-runtime-artifacts.d.ts.map +1 -1
  52. package/dist/esm/project-config/provider-runtime-artifacts.js +132 -12
  53. package/dist/esm/project-config/provider-runtime-artifacts.js.map +1 -1
  54. package/dist/esm/project-config/shared/application-creation-verification.schemas.d.ts.map +1 -1
  55. package/dist/esm/project-config/shared/application-modules.schemas.d.ts.map +1 -1
  56. package/dist/esm/project-config/shared/application-modules.utils.d.ts.map +1 -1
  57. package/dist/esm/project-config/shared/auth.schemas.d.ts.map +1 -1
  58. package/dist/esm/project-config/shared/backing-services.schemas.d.ts +32 -43
  59. package/dist/esm/project-config/shared/backing-services.schemas.d.ts.map +1 -1
  60. package/dist/esm/project-config/shared/backing-services.schemas.js +38 -30
  61. package/dist/esm/project-config/shared/backing-services.schemas.js.map +1 -1
  62. package/dist/esm/project-config/shared/cdn.example.d.ts.map +1 -1
  63. package/dist/esm/project-config/shared/cdn.schemas.d.ts.map +1 -1
  64. package/dist/esm/project-config/shared/csp-defaults.d.ts.map +1 -1
  65. package/dist/esm/project-config/shared/csp-emit.d.ts +36 -5
  66. package/dist/esm/project-config/shared/csp-emit.d.ts.map +1 -1
  67. package/dist/esm/project-config/shared/csp-emit.js +65 -5
  68. package/dist/esm/project-config/shared/csp-emit.js.map +1 -1
  69. package/dist/esm/project-config/shared/csp.schemas.d.ts +46 -10
  70. package/dist/esm/project-config/shared/csp.schemas.d.ts.map +1 -1
  71. package/dist/esm/project-config/shared/csp.schemas.js +45 -10
  72. package/dist/esm/project-config/shared/csp.schemas.js.map +1 -1
  73. package/dist/esm/project-config/shared/data-services.schemas.d.ts.map +1 -1
  74. package/dist/esm/project-config/shared/env-example-defaults.d.ts.map +1 -1
  75. package/dist/esm/project-config/shared/environment.schemas.d.ts +8 -6
  76. package/dist/esm/project-config/shared/environment.schemas.d.ts.map +1 -1
  77. package/dist/esm/project-config/shared/environment.schemas.js +7 -5
  78. package/dist/esm/project-config/shared/environment.schemas.js.map +1 -1
  79. package/dist/esm/project-config/shared/infra-providers.schemas.d.ts +29 -3
  80. package/dist/esm/project-config/shared/infra-providers.schemas.d.ts.map +1 -1
  81. package/dist/esm/project-config/shared/infra-providers.schemas.js +34 -2
  82. package/dist/esm/project-config/shared/infra-providers.schemas.js.map +1 -1
  83. package/dist/esm/project-config/shared/infra-service.schemas.d.ts.map +1 -1
  84. package/dist/esm/project-config/shared/infrastructure-defaults.schemas.d.ts +0 -2
  85. package/dist/esm/project-config/shared/infrastructure-defaults.schemas.d.ts.map +1 -1
  86. package/dist/esm/project-config/shared/infrastructure-defaults.schemas.js +0 -2
  87. package/dist/esm/project-config/shared/infrastructure-defaults.schemas.js.map +1 -1
  88. package/dist/esm/project-config/shared/k8s-utils.d.ts +70 -10
  89. package/dist/esm/project-config/shared/k8s-utils.d.ts.map +1 -1
  90. package/dist/esm/project-config/shared/k8s-utils.js +75 -11
  91. package/dist/esm/project-config/shared/k8s-utils.js.map +1 -1
  92. package/dist/esm/project-config/shared/minion-platform-access.vocabulary.d.ts +15 -15
  93. package/dist/esm/project-config/shared/minion-platform-access.vocabulary.d.ts.map +1 -1
  94. package/dist/esm/project-config/shared/minion-platform-access.vocabulary.js +15 -15
  95. package/dist/esm/project-config/shared/minion-platform-access.vocabulary.js.map +1 -1
  96. package/dist/esm/project-config/shared/minion-resource-access.validation.d.ts +76 -0
  97. package/dist/esm/project-config/shared/minion-resource-access.validation.d.ts.map +1 -1
  98. package/dist/esm/project-config/shared/minion-resource-access.validation.js +76 -1
  99. package/dist/esm/project-config/shared/minion-resource-access.validation.js.map +1 -1
  100. package/dist/esm/project-config/shared/platform-services.schemas.d.ts +30 -0
  101. package/dist/esm/project-config/shared/platform-services.schemas.d.ts.map +1 -1
  102. package/dist/esm/project-config/shared/platform-services.schemas.js +31 -0
  103. package/dist/esm/project-config/shared/platform-services.schemas.js.map +1 -1
  104. package/dist/esm/project-config/shared/schema-version.schemas.d.ts.map +1 -1
  105. package/dist/esm/project-config/shared/service-definitions.schemas.d.ts.map +1 -1
  106. package/dist/esm/registry/artifact-domain.schemas.d.ts.map +1 -1
  107. package/dist/esm/registry/companion-api.schemas.d.ts.map +1 -1
  108. package/dist/esm/registry/digest.schemas.d.ts.map +1 -1
  109. package/dist/esm/registry/index.d.ts.map +1 -1
  110. package/dist/esm/registry/lockfile-modules-section.schemas.d.ts.map +1 -1
  111. package/dist/esm/registry/module-artifact.schemas.d.ts.map +1 -1
  112. package/dist/esm/registry/module-manifest.schemas.d.ts.map +1 -1
  113. package/dist/esm/registry/registry-config.schemas.d.ts.map +1 -1
  114. package/dist/esm/registry/registry-section-schemas.constants.d.ts.map +1 -1
  115. package/dist/esm/release/framework-release.constants.d.ts.map +1 -1
  116. package/dist/esm/release/framework-release.constants.js.map +1 -1
  117. package/dist/esm/schemas/framework-info.schemas.d.ts.map +1 -1
  118. package/dist/esm/schemas/framework-secrets.schemas.d.ts.map +1 -1
  119. package/dist/esm/schemas/platform-application-config.schemas.d.ts.map +1 -1
  120. package/dist/esm/schemas/platform-application-secrets.schemas.d.ts.map +1 -1
  121. package/dist/esm/schemas/platform-config.schemas.d.ts.map +1 -1
  122. package/dist/esm/workspace-scope/application-subject-manifest.d.ts.map +1 -1
  123. package/dist/esm/workspace-scope/index.d.ts.map +1 -1
  124. package/dist/esm/workspace-scope/resolve-homes.d.ts.map +1 -1
  125. package/dist/esm/workspace-scope/workspace-homes.schemas.d.ts +14 -0
  126. package/dist/esm/workspace-scope/workspace-homes.schemas.d.ts.map +1 -1
  127. package/dist/esm/workspace-scope/workspace-homes.schemas.js +2 -0
  128. package/dist/esm/workspace-scope/workspace-homes.schemas.js.map +1 -1
  129. package/dist/tsconfig.build.tsbuildinfo +1 -1
  130. package/package.json +7 -7
@@ -1,6 +1,72 @@
1
1
  import { type ProviderCompanionContribution } from '@wildo-ai/saas-models';
2
2
  import type { WildoSaasConfig } from './define-saas-config';
3
- type ProviderContributionOwnerKind = 'service' | 'library' | 'minion' | 'worker';
3
+ /**
4
+ * `providerPackage` was added by #330 and is the point of that slice on this file.
5
+ *
6
+ * The other four owner kinds are RUNTIME OWNERS declared in `wildo.saas.config.ts` — an application's
7
+ * own services, libraries, minions and workers. Walking only those is what made a provider shipped as
8
+ * its own npm package invisible to discovery (audit finding PL-1): the package is a DEPENDENCY, not a
9
+ * runtime owner, so nothing ever asked it what it contributes, and an application had to hand-author a
10
+ * contribution for a provider whose own package already knew everything about it.
11
+ */
12
+ export declare enum ProviderContributionOwnerKind {
13
+ /** A service package declared in `wildo.saas.config.ts` — the application's backend or a frontend. */
14
+ SERVICE = "service",
15
+ /** A shared library package of the application. */
16
+ LIBRARY = "library",
17
+ /** A minion runtime, keyed by its minion name. */
18
+ MINION = "minion",
19
+ /** A Node worker runtime, keyed by its worker name. */
20
+ WORKER = "worker",
21
+ /**
22
+ * A provider shipped as its own npm package (#330) — a DEPENDENCY rather than a runtime owner,
23
+ * which is why it needed its own walk and its own member. The value stays camelCase because it is
24
+ * substituted into operator-facing diagnostics beside the four above.
25
+ */
26
+ PROVIDER_PACKAGE = "providerPackage"
27
+ }
28
+ /**
29
+ * Package-name prefixes whose dependencies are treated as provider packages.
30
+ *
31
+ * `@wildo-ai/provider-` is the framework convention (#337 D3). An application's OWN provider packages
32
+ * are admitted through the scope of its root manifest — an application published as `@acme/…` gets
33
+ * `@acme/provider-…` for free — so a private provider needs no configuration to be discovered, and a
34
+ * dependency belonging to somebody else's scope is never executed by this walk.
35
+ */
36
+ export declare const FRAMEWORK_PROVIDER_PACKAGE_PREFIX = "@wildo-ai/provider-";
37
+ /**
38
+ * The framework's own scraped catalogue, admitted by exact NAME because it does not fit the prefix.
39
+ *
40
+ * Paul decided on 2026-09-06 that the transposed catalogue ships as ONE package with a subpath per
41
+ * vendor — `@wildo-ai/providers/slack` — rather than as 697 packages. The prefix above predates that
42
+ * decision and describes the shape it replaced, and `'@wildo-ai/providers'.startsWith('@wildo-ai/provider-')`
43
+ * is **false**: the `s` is not a `-`.
44
+ *
45
+ * So discovery could not see the catalogue at all. What it DID admit, measured 2026-09-07, was
46
+ * `@wildo-ai/provider-simulators` — the test doubles — and nothing else in the repository matches the
47
+ * prefix. A rule that admits only the simulator of a thing is worse than no rule, because it looks
48
+ * like coverage.
49
+ *
50
+ * An exact name rather than a loosened prefix (`@wildo-ai/provider`, no hyphen) on purpose: that
51
+ * would also admit any future `@wildo-ai/providerfoo`, and the catalogue is ONE known package, not a
52
+ * family. The prefix keeps serving the family it was written for — an application's own
53
+ * `@acme/provider-thing`.
54
+ */
55
+ export declare const FRAMEWORK_PROVIDER_CATALOGUE_PACKAGE = "@wildo-ai/providers";
56
+ /**
57
+ * The ENGINE's own provider barrel, admitted exactly as the catalogue is.
58
+ *
59
+ * The engine ships 23 providers and exports them through `./companion` — the same shape every
60
+ * provider package uses. Discovery did not admit it, so an application that wanted `resend` declared
61
+ * it THREE times: the scope, a hand-authored `provider-contributions.ts` projecting the engine's own
62
+ * metadata back at it, and the package dependency. The middle one carried no information the other
63
+ * two lacked; config sync refused a scoped-but-uncontributed provider, so it was not optional either
64
+ * (#358).
65
+ *
66
+ * A NAME rather than a prefix, for the reason the catalogue's own note gives: this is one known
67
+ * package, not a family.
68
+ */
69
+ export declare const FRAMEWORK_ENGINE_PROVIDER_PACKAGE = "@wildo-ai/external-connectors-private";
4
70
  interface ProviderContributionOwner {
5
71
  kind: ProviderContributionOwnerKind;
6
72
  key: string;
@@ -16,6 +82,27 @@ export declare function discoverSaasProviderCompanionContributions(input: {
16
82
  saasRoot: string;
17
83
  saasConfig: Pick<WildoSaasConfig, 'services' | 'libraries' | 'minions' | 'providers' | 'workers'>;
18
84
  }): Promise<DiscoverSaasProviderCompanionContributionsResult>;
85
+ /**
86
+ * Walk an application's provider contributions and VALIDATE them — one step, because the two must
87
+ * never come apart (#334).
88
+ *
89
+ * The walk was already shared; what was duplicated is the PAIRING. `wildo config sync` and
90
+ * `wildo lock check` each called the walker and then, separately, the validator — and the validator
91
+ * sits outside the walker, so a consumer that forgot it would compute a lockfile section from
92
+ * contributions nobody had checked against the authored scope. Three correct call sites with nothing
93
+ * making a fourth correct is the shape `.claude/rules/invariant-call-site-enumeration.md` is about.
94
+ *
95
+ * The caller still LOADS the config. That is deliberate rather than an omission: loading is one line
96
+ * each caller already owns with its own error handling, it is not the part that can silently come
97
+ * apart, and folding it in here would put the load behind a seam that the sync service's own tests
98
+ * mock — `loadSaasConfig` mocked as a module export is not seen by a caller INSIDE this module, so
99
+ * those tests would have had to mock this function instead and would then no longer exercise the real
100
+ * discovery and the real validation they exist to check.
101
+ */
102
+ export declare function resolveValidatedSaasProviderContributions(input: {
103
+ saasRoot: string;
104
+ saasConfig: Pick<WildoSaasConfig, 'modules' | 'services' | 'libraries' | 'minions' | 'providers' | 'workers'>;
105
+ }): Promise<DiscoveredProviderCompanionContribution[]>;
19
106
  export declare function validateDiscoveredSaasProviderContributions(input: {
20
107
  saasConfig: Pick<WildoSaasConfig, 'modules' | 'providers' | 'services' | 'minions' | 'workers'>;
21
108
  discoveredContributions: DiscoveredProviderCompanionContribution[];
@@ -1 +1 @@
1
- {"version":3,"file":"provider-companion-discovery.d.ts","sourceRoot":"","sources":["../../../../src/project-config/provider-companion-discovery.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,6BAA6B,EAGnC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAG5D,KAAK,6BAA6B,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEjF,UAAU,yBAAyB;IACjC,IAAI,EAAE,6BAA6B,CAAC;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;CACrB;AAMD,MAAM,WAAW,uCAAwC,SAAQ,6BAA6B;IAC5F,KAAK,EAAE,yBAAyB,CAAC;CAClC;AAED,MAAM,WAAW,gDAAgD;IAC/D,aAAa,EAAE,uCAAuC,EAAE,CAAC;CAC1D;AAED,wBAAsB,0CAA0C,CAAC,KAAK,EAAE;IACtE,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,IAAI,CAAC,eAAe,EAAE,UAAU,GAAG,WAAW,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,CAAC,CAAC;CACnG,GAAG,OAAO,CAAC,gDAAgD,CAAC,CA0B5D;AAED,wBAAgB,2CAA2C,CAAC,KAAK,EAAE;IACjE,UAAU,EAAE,IAAI,CAAC,eAAe,EAAE,SAAS,GAAG,WAAW,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,CAAC,CAAC;IAChG,uBAAuB,EAAE,uCAAuC,EAAE,CAAC;CACpE,GAAG,IAAI,CAmIP"}
1
+ {"version":3,"file":"provider-companion-discovery.d.ts","sourceRoot":"","sources":["../../../src/project-config/provider-companion-discovery.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,6BAA6B,EAGnC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAG5D;;;;;;;;GAQG;AACH,oBAAY,6BAA6B;IACvC,sGAAsG;IACtG,OAAO,YAAY;IACnB,mDAAmD;IACnD,OAAO,YAAY;IACnB,kDAAkD;IAClD,MAAM,WAAW;IACjB,uDAAuD;IACvD,MAAM,WAAW;IACjB;;;;OAIG;IACH,gBAAgB,oBAAoB;CACrC;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,iCAAiC,wBAAwB,CAAC;AAEvE;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,oCAAoC,wBAAwB,CAAC;AAE1E;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,iCAAiC,0CAA0C,CAAC;AAEzF,UAAU,yBAAyB;IACjC,IAAI,EAAE,6BAA6B,CAAC;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;CACrB;AAMD,MAAM,WAAW,uCAAwC,SAAQ,6BAA6B;IAC5F,KAAK,EAAE,yBAAyB,CAAC;CAClC;AAED,MAAM,WAAW,gDAAgD;IAC/D,aAAa,EAAE,uCAAuC,EAAE,CAAC;CAC1D;AAmDD,wBAAsB,0CAA0C,CAAC,KAAK,EAAE;IACtE,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,IAAI,CAAC,eAAe,EAAE,UAAU,GAAG,WAAW,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,CAAC,CAAC;CACnG,GAAG,OAAO,CAAC,gDAAgD,CAAC,CAuC5D;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,yCAAyC,CAAC,KAAK,EAAE;IACrE,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,IAAI,CAAC,eAAe,EAAE,SAAS,GAAG,UAAU,GAAG,WAAW,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,CAAC,CAAC;CAC/G,GAAG,OAAO,CAAC,uCAAuC,EAAE,CAAC,CAOrD;AAED,wBAAgB,2CAA2C,CAAC,KAAK,EAAE;IACjE,UAAU,EAAE,IAAI,CAAC,eAAe,EAAE,SAAS,GAAG,WAAW,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,CAAC,CAAC;IAChG,uBAAuB,EAAE,uCAAuC,EAAE,CAAC;CACpE,GAAG,IAAI,CAmIP"}
@@ -1,17 +1,146 @@
1
+ import { createRequire } from 'node:module';
1
2
  import { existsSync, readFileSync } from 'node:fs';
2
- import { join, resolve } from 'node:path';
3
+ import { dirname, join, resolve } from 'node:path';
3
4
  import { ProviderCompanionContributionSchema, } from '@wildo-ai/saas-models';
4
5
  import { loadPackageCompanionExport, resolvePackageCompanionEntryPath } from './loader.js';
6
+ /**
7
+ * `providerPackage` was added by #330 and is the point of that slice on this file.
8
+ *
9
+ * The other four owner kinds are RUNTIME OWNERS declared in `wildo.saas.config.ts` — an application's
10
+ * own services, libraries, minions and workers. Walking only those is what made a provider shipped as
11
+ * its own npm package invisible to discovery (audit finding PL-1): the package is a DEPENDENCY, not a
12
+ * runtime owner, so nothing ever asked it what it contributes, and an application had to hand-author a
13
+ * contribution for a provider whose own package already knew everything about it.
14
+ */
15
+ export var ProviderContributionOwnerKind;
16
+ (function (ProviderContributionOwnerKind) {
17
+ /** A service package declared in `wildo.saas.config.ts` — the application's backend or a frontend. */
18
+ ProviderContributionOwnerKind["SERVICE"] = "service";
19
+ /** A shared library package of the application. */
20
+ ProviderContributionOwnerKind["LIBRARY"] = "library";
21
+ /** A minion runtime, keyed by its minion name. */
22
+ ProviderContributionOwnerKind["MINION"] = "minion";
23
+ /** A Node worker runtime, keyed by its worker name. */
24
+ ProviderContributionOwnerKind["WORKER"] = "worker";
25
+ /**
26
+ * A provider shipped as its own npm package (#330) — a DEPENDENCY rather than a runtime owner,
27
+ * which is why it needed its own walk and its own member. The value stays camelCase because it is
28
+ * substituted into operator-facing diagnostics beside the four above.
29
+ */
30
+ ProviderContributionOwnerKind["PROVIDER_PACKAGE"] = "providerPackage";
31
+ })(ProviderContributionOwnerKind || (ProviderContributionOwnerKind = {}));
32
+ /**
33
+ * Package-name prefixes whose dependencies are treated as provider packages.
34
+ *
35
+ * `@wildo-ai/provider-` is the framework convention (#337 D3). An application's OWN provider packages
36
+ * are admitted through the scope of its root manifest — an application published as `@acme/…` gets
37
+ * `@acme/provider-…` for free — so a private provider needs no configuration to be discovered, and a
38
+ * dependency belonging to somebody else's scope is never executed by this walk.
39
+ */
40
+ export const FRAMEWORK_PROVIDER_PACKAGE_PREFIX = '@wildo-ai/provider-';
41
+ /**
42
+ * The framework's own scraped catalogue, admitted by exact NAME because it does not fit the prefix.
43
+ *
44
+ * Paul decided on 2026-09-06 that the transposed catalogue ships as ONE package with a subpath per
45
+ * vendor — `@wildo-ai/providers/slack` — rather than as 697 packages. The prefix above predates that
46
+ * decision and describes the shape it replaced, and `'@wildo-ai/providers'.startsWith('@wildo-ai/provider-')`
47
+ * is **false**: the `s` is not a `-`.
48
+ *
49
+ * So discovery could not see the catalogue at all. What it DID admit, measured 2026-09-07, was
50
+ * `@wildo-ai/provider-simulators` — the test doubles — and nothing else in the repository matches the
51
+ * prefix. A rule that admits only the simulator of a thing is worse than no rule, because it looks
52
+ * like coverage.
53
+ *
54
+ * An exact name rather than a loosened prefix (`@wildo-ai/provider`, no hyphen) on purpose: that
55
+ * would also admit any future `@wildo-ai/providerfoo`, and the catalogue is ONE known package, not a
56
+ * family. The prefix keeps serving the family it was written for — an application's own
57
+ * `@acme/provider-thing`.
58
+ */
59
+ export const FRAMEWORK_PROVIDER_CATALOGUE_PACKAGE = '@wildo-ai/providers';
60
+ /**
61
+ * The ENGINE's own provider barrel, admitted exactly as the catalogue is.
62
+ *
63
+ * The engine ships 23 providers and exports them through `./companion` — the same shape every
64
+ * provider package uses. Discovery did not admit it, so an application that wanted `resend` declared
65
+ * it THREE times: the scope, a hand-authored `provider-contributions.ts` projecting the engine's own
66
+ * metadata back at it, and the package dependency. The middle one carried no information the other
67
+ * two lacked; config sync refused a scoped-but-uncontributed provider, so it was not optional either
68
+ * (#358).
69
+ *
70
+ * A NAME rather than a prefix, for the reason the catalogue's own note gives: this is one known
71
+ * package, not a family.
72
+ */
73
+ export const FRAMEWORK_ENGINE_PROVIDER_PACKAGE = '@wildo-ai/external-connectors-private';
74
+ /**
75
+ * The runtime targets an application's SCOPES imply for one provider ref.
76
+ *
77
+ * ## Why a package's declared targets cannot be the answer
78
+ *
79
+ * A provider PACKAGE is shipped once and installed by many applications, so it cannot know any of
80
+ * their runtime topologies. Measured 2026-09-09: all 682 catalogue vendors declare
81
+ * `[{ kind: 'backend' }]` and every engine contribution declares `backend` (plus `companion` for the
82
+ * model-ish ones). Those are defaults standing in for an answer the package is not able to give —
83
+ * a minion key or a worker key exists only in `wildo.saas.config.ts`.
84
+ *
85
+ * The consequence was latent rather than theoretical: a CATALOGUE provider scoped to a minion would
86
+ * have failed materialization with "no discovered contribution supplies its secret-contract shape
87
+ * for this runtime", because the package declares a `backend` target and the minion scope looks for
88
+ * a `minion` one. No application had scoped one to a minion yet, so nothing had reported it.
89
+ *
90
+ * ## Why the scopes ARE the answer
91
+ *
92
+ * `providers.scopes` is where an application says which runtimes reach which provider — it is the
93
+ * same decision, already authored, in the place the runtime artifact is built from. Measured against
94
+ * Wonder Todos' hand-authored projections: the scopes reproduce 9 of 10 target sets EXACTLY, and the
95
+ * tenth is a SURPLUS (a `companion` target for a provider the companion scope does not name) which
96
+ * the artifact discards anyway, since it is built from scope INTERSECT contribution.
97
+ *
98
+ * So nothing is lost by deriving, and what is gained is that an application declares a provider once.
99
+ *
100
+ * Applies to contributions discovered from a PACKAGE. A runtime owner's own companion barrel keeps
101
+ * whatever it declares: that is the application's own file talking about itself, and an application
102
+ * package is entitled to state a target the scopes do not.
103
+ */
104
+ function resolveScopeImpliedRuntimeTargets(providerRef, saasConfig) {
105
+ const scopes = saasConfig.providers?.scopes;
106
+ if (!scopes)
107
+ return [];
108
+ const targets = [];
109
+ if (scopes.backend?.providers?.[providerRef])
110
+ targets.push({ kind: 'backend' });
111
+ if (scopes.companion?.providers?.[providerRef])
112
+ targets.push({ kind: 'companion' });
113
+ for (const [minionKey, scope] of Object.entries(scopes.minions ?? {})) {
114
+ if (scope?.providers?.[providerRef])
115
+ targets.push({ kind: 'minion', minionKey });
116
+ }
117
+ for (const [workerKey, scope] of Object.entries(scopes.workers ?? {})) {
118
+ if (scope?.providers?.[providerRef])
119
+ targets.push({ kind: 'worker', workerKey });
120
+ }
121
+ return targets;
122
+ }
5
123
  export async function discoverSaasProviderCompanionContributions(input) {
6
124
  const contributions = [];
7
- for (const target of resolveContributionTargets(input.saasRoot, input.saasConfig)) {
125
+ const runtimeOwnerTargets = resolveContributionTargets(input.saasRoot, input.saasConfig);
126
+ for (const target of [
127
+ ...runtimeOwnerTargets,
128
+ ...resolveProviderPackageTargets(input.saasRoot, runtimeOwnerTargets),
129
+ ]) {
8
130
  const companionExports = await tryLoadRuntimeOwnerCompanionExports(target.packageRoot);
9
131
  if (!companionExports) {
10
132
  continue;
11
133
  }
12
134
  const parsedContributions = ProviderCompanionContributionSchema.array().parse(companionExports.providerContributions ?? []);
135
+ // A PACKAGE cannot know this application's runtime topology, so its declared targets are a
136
+ // default and the SCOPES are the answer. A runtime owner's own barrel keeps what it declares —
137
+ // see `resolveScopeImpliedRuntimeTargets`.
138
+ const derivesTargetsFromScopes = target.kind === ProviderContributionOwnerKind.PROVIDER_PACKAGE;
13
139
  contributions.push(...parsedContributions.map((contribution) => ({
14
140
  ...contribution,
141
+ runtimeTargets: derivesTargetsFromScopes
142
+ ? resolveScopeImpliedRuntimeTargets(contribution.ref, input.saasConfig)
143
+ : contribution.runtimeTargets,
15
144
  owner: {
16
145
  kind: target.kind,
17
146
  key: target.key,
@@ -21,6 +150,31 @@ export async function discoverSaasProviderCompanionContributions(input) {
21
150
  }
22
151
  return { contributions };
23
152
  }
153
+ /**
154
+ * Walk an application's provider contributions and VALIDATE them — one step, because the two must
155
+ * never come apart (#334).
156
+ *
157
+ * The walk was already shared; what was duplicated is the PAIRING. `wildo config sync` and
158
+ * `wildo lock check` each called the walker and then, separately, the validator — and the validator
159
+ * sits outside the walker, so a consumer that forgot it would compute a lockfile section from
160
+ * contributions nobody had checked against the authored scope. Three correct call sites with nothing
161
+ * making a fourth correct is the shape `.claude/rules/invariant-call-site-enumeration.md` is about.
162
+ *
163
+ * The caller still LOADS the config. That is deliberate rather than an omission: loading is one line
164
+ * each caller already owns with its own error handling, it is not the part that can silently come
165
+ * apart, and folding it in here would put the load behind a seam that the sync service's own tests
166
+ * mock — `loadSaasConfig` mocked as a module export is not seen by a caller INSIDE this module, so
167
+ * those tests would have had to mock this function instead and would then no longer exercise the real
168
+ * discovery and the real validation they exist to check.
169
+ */
170
+ export async function resolveValidatedSaasProviderContributions(input) {
171
+ const { contributions } = await discoverSaasProviderCompanionContributions(input);
172
+ validateDiscoveredSaasProviderContributions({
173
+ saasConfig: input.saasConfig,
174
+ discoveredContributions: contributions,
175
+ });
176
+ return contributions;
177
+ }
24
178
  export function validateDiscoveredSaasProviderContributions(input) {
25
179
  const { saasConfig, discoveredContributions } = input;
26
180
  const errors = [];
@@ -145,13 +299,13 @@ function resolveContributionTargets(saasRoot, saasConfig) {
145
299
  ? frontendServiceProviderScopes.includes(key)
146
300
  : shouldIncludeBackendServices))
147
301
  .map(([key, definition]) => ({
148
- kind: 'service',
302
+ kind: ProviderContributionOwnerKind.SERVICE,
149
303
  key,
150
304
  ownerLabel: `service "${key}"`,
151
305
  packageRoot: resolve(saasRoot, definition.path),
152
306
  })),
153
307
  ...Object.entries(saasConfig.libraries ?? {}).map(([key, definition]) => ({
154
- kind: 'library',
308
+ kind: ProviderContributionOwnerKind.LIBRARY,
155
309
  key,
156
310
  ownerLabel: `library "${key}"`,
157
311
  packageRoot: resolve(saasRoot, definition.path),
@@ -159,7 +313,7 @@ function resolveContributionTargets(saasRoot, saasConfig) {
159
313
  ...Object.entries(saasConfig.minions ?? {})
160
314
  .filter(([key]) => minionProviderScopes.includes(key))
161
315
  .map(([key, definition]) => ({
162
- kind: 'minion',
316
+ kind: ProviderContributionOwnerKind.MINION,
163
317
  key,
164
318
  ownerLabel: `minion "${key}"`,
165
319
  packageRoot: resolve(saasRoot, definition.path),
@@ -167,13 +321,128 @@ function resolveContributionTargets(saasRoot, saasConfig) {
167
321
  ...Object.entries(saasConfig.workers ?? {})
168
322
  .filter(([key]) => workerProviderScopes.includes(key))
169
323
  .map(([key, definition]) => ({
170
- kind: 'worker',
324
+ kind: ProviderContributionOwnerKind.WORKER,
171
325
  key,
172
326
  ownerLabel: `worker "${key}"`,
173
327
  packageRoot: resolve(saasRoot, definition.path),
174
328
  })),
175
329
  ];
176
330
  }
331
+ /**
332
+ * Every provider PACKAGE this application depends on, as a contribution target.
333
+ *
334
+ * Candidates come from the application root manifest AND from each runtime owner's manifest, because
335
+ * both layouts are real: a scaffolded application declares its provider packages in the runtime owner
336
+ * that imports them (`backend-api`), while a workspace root may hoist them. The union is deduplicated
337
+ * by resolved package root, so a package declared in both places is walked once.
338
+ *
339
+ * A candidate that cannot be resolved on disk is SKIPPED rather than refused. The manifest is the
340
+ * declaration and `node_modules` is the install; a name declared but not installed is an install
341
+ * problem that `pnpm install` reports far better than a config-sync stack trace would, and refusing
342
+ * here would make `wildo config sync` unrunnable in exactly the state where an operator runs it to
343
+ * find out what is wrong.
344
+ */
345
+ function resolveProviderPackageTargets(saasRoot, runtimeOwnerTargets) {
346
+ const prefixes = resolveProviderPackagePrefixes(saasRoot);
347
+ const searchRoots = [saasRoot, ...runtimeOwnerTargets.map((target) => target.packageRoot)];
348
+ const candidateNames = new Set();
349
+ for (const searchRoot of searchRoots) {
350
+ for (const dependencyName of readRuntimeReachablePackageNames(searchRoot)) {
351
+ if (dependencyName === FRAMEWORK_PROVIDER_CATALOGUE_PACKAGE
352
+ || dependencyName === FRAMEWORK_ENGINE_PROVIDER_PACKAGE
353
+ || prefixes.some((prefix) => dependencyName.startsWith(prefix))) {
354
+ candidateNames.add(dependencyName);
355
+ }
356
+ }
357
+ }
358
+ const targetsByRoot = new Map();
359
+ for (const packageName of [...candidateNames].sort()) {
360
+ const packageRoot = resolveProviderPackageRoot(packageName, searchRoots);
361
+ if (!packageRoot || targetsByRoot.has(packageRoot)) {
362
+ continue;
363
+ }
364
+ targetsByRoot.set(packageRoot, {
365
+ kind: ProviderContributionOwnerKind.PROVIDER_PACKAGE,
366
+ key: packageName,
367
+ ownerLabel: `provider package "${packageName}"`,
368
+ packageRoot,
369
+ });
370
+ }
371
+ return [...targetsByRoot.values()];
372
+ }
373
+ /**
374
+ * The framework prefix, plus the application's own scope when its root manifest has one.
375
+ *
376
+ * Deriving the second from the root package name rather than reading it from configuration keeps the
377
+ * "one declaration" promise of #330 intact: installing `@acme/provider-thing` in an `@acme` application
378
+ * and scoping the ref is the whole of it — there is no third place to remember.
379
+ */
380
+ function resolveProviderPackagePrefixes(saasRoot) {
381
+ const prefixes = [FRAMEWORK_PROVIDER_PACKAGE_PREFIX];
382
+ const rootPackageName = readPackageName(saasRoot);
383
+ const scope = rootPackageName?.startsWith('@') ? rootPackageName.split('/')[0] : undefined;
384
+ if (scope && scope !== '@wildo-ai') {
385
+ prefixes.push(`${scope}/provider-`);
386
+ }
387
+ return prefixes;
388
+ }
389
+ /**
390
+ * Locate an installed package's ROOT DIRECTORY, which is what the companion-entry resolver needs.
391
+ *
392
+ * The direct `node_modules` probe comes first because it is what pnpm actually produces — a symlink
393
+ * per importer — and because it works for a package whose `exports` map declares no `./package.json`,
394
+ * which `require.resolve` cannot see past. `createRequire` is the fallback for hoisted or otherwise
395
+ * unusual layouts; it resolves the companion subpath (the one door every provider package declares)
396
+ * and walks up to the manifest that names the package.
397
+ */
398
+ function resolveProviderPackageRoot(packageName, searchRoots) {
399
+ /*
400
+ * The name comes from a manifest and is spliced into a filesystem path, so a segment that is `.` or
401
+ * `..` would walk OUT of `node_modules` — and the prefix gate would not stop it, since
402
+ * `@wildo-ai/provider-x/../../elsewhere` starts with the framework prefix. npm forbids such a name,
403
+ * which is precisely why nothing downstream would question it; the check costs one line and is the
404
+ * only thing standing between an authored dependency name and an arbitrary directory whose
405
+ * companion entry this walk EXECUTES.
406
+ */
407
+ const segments = packageName.split('/');
408
+ if (segments.some((segment) => segment.length === 0 || segment === '.' || segment === '..')) {
409
+ return undefined;
410
+ }
411
+ for (const searchRoot of searchRoots) {
412
+ const candidate = join(searchRoot, 'node_modules', ...segments);
413
+ if (existsSync(join(candidate, 'package.json'))) {
414
+ return candidate;
415
+ }
416
+ }
417
+ for (const searchRoot of searchRoots) {
418
+ try {
419
+ const resolved = createRequire(join(searchRoot, 'package.json')).resolve(`${packageName}/companion`);
420
+ let directory = dirname(resolved);
421
+ while (directory !== dirname(directory)) {
422
+ if (readPackageName(directory) === packageName) {
423
+ return directory;
424
+ }
425
+ directory = dirname(directory);
426
+ }
427
+ }
428
+ catch {
429
+ // Not resolvable from this root; try the next one, then give up quietly (see the JSDoc above).
430
+ }
431
+ }
432
+ return undefined;
433
+ }
434
+ function readPackageName(packageRoot) {
435
+ const packageJsonPath = join(packageRoot, 'package.json');
436
+ if (!existsSync(packageJsonPath)) {
437
+ return undefined;
438
+ }
439
+ try {
440
+ return JSON.parse(readFileSync(packageJsonPath, 'utf-8')).name;
441
+ }
442
+ catch {
443
+ return undefined;
444
+ }
445
+ }
177
446
  async function tryLoadRuntimeOwnerCompanionExports(packageRoot) {
178
447
  try {
179
448
  resolvePackageCompanionEntryPath(packageRoot);
@@ -1 +1 @@
1
- {"version":3,"file":"provider-companion-discovery.js","sourceRoot":"","sources":["../../../../src/project-config/provider-companion-discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EACL,mCAAmC,GAIpC,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,0BAA0B,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAsBxF,MAAM,CAAC,KAAK,UAAU,0CAA0C,CAAC,KAGhE;IACC,MAAM,aAAa,GAA8C,EAAE,CAAC;IAEpE,KAAK,MAAM,MAAM,IAAI,0BAA0B,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC;QAClF,MAAM,gBAAgB,GAAG,MAAM,mCAAmC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QACvF,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtB,SAAS;QACX,CAAC;QAED,MAAM,mBAAmB,GAAG,mCAAmC,CAAC,KAAK,EAAE,CAAC,KAAK,CAC3E,gBAAgB,CAAC,qBAAqB,IAAI,EAAE,CAC7C,CAAC;QAEF,aAAa,CAAC,IAAI,CAChB,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;YAC5C,GAAG,YAAY;YACf,KAAK,EAAE;gBACL,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,GAAG,EAAE,MAAM,CAAC,GAAG;gBACf,WAAW,EAAE,MAAM,CAAC,WAAW;aAChC;SACF,CAAC,CAAC,CACJ,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,aAAa,EAAE,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,2CAA2C,CAAC,KAG3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Ae,CACtB,SAA8C;IAE9C,OAAO,OAAO,CAAC,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\nimport {\n ProviderCompanionContributionSchema,\n type ProviderCompanionContribution,\n type ProviderCompanionRuntimeTarget,\n type RuntimeOwnerCompanionExports,\n} from '@wildo-ai/saas-models';\nimport type { WildoSaasConfig } from './define-saas-config';\nimport { loadPackageCompanionExport, resolvePackageCompanionEntryPath } from './loader';\n\ntype ProviderContributionOwnerKind = 'service' | 'library' | 'minion' | 'worker';\n\ninterface ProviderContributionOwner {\n kind: ProviderContributionOwnerKind;\n key: string;\n packageRoot: string;\n}\n\ninterface ProviderContributionTarget extends ProviderContributionOwner {\n ownerLabel: string;\n}\n\nexport interface DiscoveredProviderCompanionContribution extends ProviderCompanionContribution {\n owner: ProviderContributionOwner;\n}\n\nexport interface DiscoverSaasProviderCompanionContributionsResult {\n contributions: DiscoveredProviderCompanionContribution[];\n}\n\nexport async function discoverSaasProviderCompanionContributions(input: {\n saasRoot: string;\n saasConfig: Pick<WildoSaasConfig, 'services' | 'libraries' | 'minions' | 'providers' | 'workers'>;\n}): Promise<DiscoverSaasProviderCompanionContributionsResult> {\n const contributions: DiscoveredProviderCompanionContribution[] = [];\n\n for (const target of resolveContributionTargets(input.saasRoot, input.saasConfig)) {\n const companionExports = await tryLoadRuntimeOwnerCompanionExports(target.packageRoot);\n if (!companionExports) {\n continue;\n }\n\n const parsedContributions = ProviderCompanionContributionSchema.array().parse(\n companionExports.providerContributions ?? [],\n );\n\n contributions.push(\n ...parsedContributions.map((contribution) => ({\n ...contribution,\n owner: {\n kind: target.kind,\n key: target.key,\n packageRoot: target.packageRoot,\n },\n })),\n );\n }\n\n return { contributions };\n}\n\nexport function validateDiscoveredSaasProviderContributions(input: {\n saasConfig: Pick<WildoSaasConfig, 'modules' | 'providers' | 'services' | 'minions' | 'workers'>;\n discoveredContributions: DiscoveredProviderCompanionContribution[];\n}): void {\n const { saasConfig, discoveredContributions } = input;\n const errors: string[] = [];\n const declaredModuleIds = new Set(Object.keys(saasConfig.modules ?? {}));\n const declaredServiceKeys = new Set(Object.keys(saasConfig.services ?? {}));\n const serviceKeyToFrontendType = new Map<string, string>(\n Object.entries(saasConfig.services ?? {})\n .filter(([, definition]) => definition.frontendType !== undefined)\n .map(([serviceKey, definition]) => [serviceKey, definition.frontendType as string]),\n );\n const declaredFrontendServiceKeys = new Set(serviceKeyToFrontendType.keys());\n const declaredFrontendTypes = new Set(serviceKeyToFrontendType.values());\n const declaredMinionKeys = new Set(Object.keys(saasConfig.minions ?? {}));\n const declaredWorkerKeys = new Set(Object.keys(saasConfig.workers ?? {}));\n\n for (const contribution of discoveredContributions) {\n if (contribution.sourceModuleId && !declaredModuleIds.has(contribution.sourceModuleId)) {\n errors.push(\n `${describeContribution(contribution)} references sourceModuleId \"${contribution.sourceModuleId}\" ` +\n 'but that module is not declared in wildo.saas.config.ts.',\n );\n }\n\n const dependencyNames = readRuntimeReachablePackageNames(contribution.owner.packageRoot);\n const runtimePackageName = extractPackageName(contribution.runtimeImportPath);\n if (!dependencyNames.has(runtimePackageName)) {\n errors.push(\n `${describeContribution(contribution)} declares runtimeImportPath \"${contribution.runtimeImportPath}\" ` +\n `but ${contribution.owner.kind} \"${contribution.owner.key}\" does not depend on \"${runtimePackageName}\".`,\n );\n }\n\n for (const target of contribution.runtimeTargets) {\n switch (target.kind) {\n case 'frontendService':\n if (!declaredFrontendTypes.has(target.serviceType)) {\n errors.push(\n `${describeContribution(contribution)} targets frontendType \"${target.serviceType}\" ` +\n 'but no service with that frontendType is declared in wildo.saas.config.ts.',\n );\n } else if (!contribution.frontendEntry) {\n errors.push(\n `${describeContribution(contribution)} targets frontendType \"${target.serviceType}\" ` +\n 'but does not provide a frontendEntry payload for bootstrap materialization.',\n );\n }\n break;\n case 'minion':\n if (!declaredMinionKeys.has(target.minionKey)) {\n errors.push(\n `${describeContribution(contribution)} targets unknown minion \"${target.minionKey}\".`,\n );\n }\n break;\n case 'worker':\n if (!declaredWorkerKeys.has(target.workerKey)) {\n errors.push(\n `${describeContribution(contribution)} targets unknown worker \"${target.workerKey}\".`,\n );\n }\n break;\n case 'backend':\n case 'companion':\n break;\n }\n }\n }\n\n const runtimeScopes = saasConfig.providers.scopes;\n validateRuntimeScopeAgainstDiscovery({\n errors,\n discoveredContributions,\n scopeLabel: 'backend',\n providers: runtimeScopes.backend?.providers ?? {},\n matchesTarget: (target) => target.kind === 'backend',\n });\n validateRuntimeScopeAgainstDiscovery({\n errors,\n discoveredContributions,\n scopeLabel: 'companion',\n providers: runtimeScopes.companion?.providers ?? {},\n matchesTarget: (target) => target.kind === 'companion',\n });\n\n for (const [serviceKey, scope] of Object.entries(runtimeScopes.frontendServices ?? {})) {\n if (!declaredServiceKeys.has(serviceKey)) {\n errors.push(`Provider scope references unknown frontend service \"${serviceKey}\".`);\n continue;\n }\n if (!declaredFrontendServiceKeys.has(serviceKey)) {\n errors.push(\n `Provider scope references non-frontend service \"${serviceKey}\". ` +\n 'Only services with a frontendType may appear under providers.scopes.frontendServices.',\n );\n continue;\n }\n const serviceType = serviceKeyToFrontendType.get(serviceKey);\n validateRuntimeScopeAgainstDiscovery({\n errors,\n discoveredContributions,\n scopeLabel: `frontendServices.${serviceKey}`,\n providers: scope.providers,\n matchesTarget: (target) => target.kind === 'frontendService' && target.serviceType === serviceType,\n });\n }\n\n for (const [minionKey, scope] of Object.entries(runtimeScopes.minions ?? {})) {\n validateRuntimeScopeAgainstDiscovery({\n errors,\n discoveredContributions,\n scopeLabel: `minions.${minionKey}`,\n providers: scope.providers,\n matchesTarget: (target) => target.kind === 'minion' && target.minionKey === minionKey,\n });\n }\n\n for (const [workerKey, scope] of Object.entries(runtimeScopes.workers ?? {})) {\n validateRuntimeScopeAgainstDiscovery({\n errors,\n discoveredContributions,\n scopeLabel: `workers.${workerKey}`,\n providers: scope.providers,\n matchesTarget: (target) => target.kind === 'worker' && target.workerKey === workerKey,\n });\n }\n\n if (errors.length > 0) {\n throw new Error(\n `Provider companion-export discovery validation failed:\\n- ${errors.join('\\n- ')}`,\n );\n }\n}\n\nfunction resolveContributionTargets(\n saasRoot: string,\n saasConfig: Pick<WildoSaasConfig, 'services' | 'libraries' | 'minions' | 'providers' | 'workers'>,\n): ProviderContributionTarget[] {\n const shouldIncludeBackendServices = hasAnyProviders(saasConfig.providers.scopes.backend?.providers);\n const frontendServiceProviderScopes = Object.entries(saasConfig.providers.scopes.frontendServices ?? {})\n .filter(([, scope]) => hasAnyProviders(scope.providers))\n .map(([serviceKey]) => serviceKey);\n const minionProviderScopes = Object.entries(saasConfig.providers.scopes.minions ?? {})\n .filter(([, scope]) => hasAnyProviders(scope.providers))\n .map(([minionKey]) => minionKey);\n const workerProviderScopes = Object.entries(saasConfig.providers.scopes.workers ?? {})\n .filter(([, scope]) => hasAnyProviders(scope.providers))\n .map(([workerKey]) => workerKey);\n\n return [\n ...Object.entries(saasConfig.services)\n .filter(([key, definition]) => (\n definition.frontendType\n ? frontendServiceProviderScopes.includes(key)\n : shouldIncludeBackendServices\n ))\n .map(([key, definition]) => ({\n kind: 'service' as const,\n key,\n ownerLabel: `service \"${key}\"`,\n packageRoot: resolve(saasRoot, definition.path),\n })),\n ...Object.entries(saasConfig.libraries ?? {}).map(([key, definition]) => ({\n kind: 'library' as const,\n key,\n ownerLabel: `library \"${key}\"`,\n packageRoot: resolve(saasRoot, definition.path),\n })),\n ...Object.entries(saasConfig.minions ?? {})\n .filter(([key]) => minionProviderScopes.includes(key))\n .map(([key, definition]) => ({\n kind: 'minion' as const,\n key,\n ownerLabel: `minion \"${key}\"`,\n packageRoot: resolve(saasRoot, definition.path),\n })),\n ...Object.entries(saasConfig.workers ?? {})\n .filter(([key]) => workerProviderScopes.includes(key))\n .map(([key, definition]) => ({\n kind: 'worker' as const,\n key,\n ownerLabel: `worker \"${key}\"`,\n packageRoot: resolve(saasRoot, definition.path),\n })),\n ];\n}\n\nasync function tryLoadRuntimeOwnerCompanionExports(\n packageRoot: string,\n): Promise<RuntimeOwnerCompanionExports | undefined> {\n try {\n resolvePackageCompanionEntryPath(packageRoot);\n } catch {\n return undefined;\n }\n\n return loadPackageCompanionExport<RuntimeOwnerCompanionExports>(packageRoot);\n}\n\nfunction validateRuntimeScopeAgainstDiscovery(input: {\n errors: string[];\n discoveredContributions: DiscoveredProviderCompanionContribution[];\n scopeLabel: string;\n providers: NonNullable<WildoSaasConfig['providers']['scopes']['backend']>['providers'];\n matchesTarget: (target: ProviderCompanionRuntimeTarget) => boolean;\n}): void {\n const { errors, discoveredContributions, matchesTarget, providers, scopeLabel } = input;\n\n for (const [providerRef, authoredSelection] of Object.entries(providers)) {\n const matchingContributions = discoveredContributions.filter(\n (contribution) => contribution.ref === providerRef\n && contribution.runtimeTargets.some(matchesTarget),\n );\n\n if (matchingContributions.length === 0) {\n errors.push(\n `Provider \"${providerRef}\" is authored in scope \"${scopeLabel}\" but no companion export contributes it for that runtime.`,\n );\n continue;\n }\n\n const discoveredEngineCapabilities = new Set(\n matchingContributions.flatMap((contribution) => contribution.engineCapabilities),\n );\n const discoveredProviderCapabilities = new Set(\n matchingContributions.flatMap((contribution) => contribution.providerCapabilities),\n );\n const discoveredProtocols = new Set(\n matchingContributions.flatMap((contribution) => contribution.protocols),\n );\n\n for (const capability of authoredSelection.engineCapabilities) {\n if (!discoveredEngineCapabilities.has(capability)) {\n errors.push(\n `Provider \"${providerRef}\" in scope \"${scopeLabel}\" declares engine capability \"${capability}\" ` +\n 'but discovery does not report that capability for the same runtime.',\n );\n }\n }\n\n for (const capability of authoredSelection.providerCapabilities) {\n if (!discoveredProviderCapabilities.has(capability)) {\n errors.push(\n `Provider \"${providerRef}\" in scope \"${scopeLabel}\" declares provider capability \"${capability}\" ` +\n 'but discovery does not report that capability for the same runtime.',\n );\n }\n }\n\n for (const protocol of authoredSelection.protocols) {\n if (!discoveredProtocols.has(protocol)) {\n errors.push(\n `Provider \"${providerRef}\" in scope \"${scopeLabel}\" declares protocol \"${protocol}\" ` +\n 'but discovery does not report that protocol for the same runtime.',\n );\n }\n }\n }\n}\n\nfunction describeContribution(contribution: DiscoveredProviderCompanionContribution): string {\n return `Provider contribution \"${contribution.ref}\" from ${contribution.owner.kind} \"${contribution.owner.key}\"`;\n}\n\nfunction readRuntimeReachablePackageNames(packageRoot: string): Set<string> {\n const packageJsonPath = join(packageRoot, 'package.json');\n if (!existsSync(packageJsonPath)) {\n return new Set<string>();\n }\n\n const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8')) as {\n name?: string;\n dependencies?: Record<string, string>;\n peerDependencies?: Record<string, string>;\n optionalDependencies?: Record<string, string>;\n };\n\n return new Set([\n ...(packageJson.name ? [packageJson.name] : []),\n ...Object.keys(packageJson.dependencies ?? {}),\n ...Object.keys(packageJson.peerDependencies ?? {}),\n ...Object.keys(packageJson.optionalDependencies ?? {}),\n ]);\n}\n\nfunction extractPackageName(importPath: string): string {\n if (importPath.startsWith('@')) {\n const [scope, pkg] = importPath.split('/');\n return `${scope}/${pkg}`;\n }\n return importPath.split('/')[0] ?? importPath;\n}\n\nfunction hasAnyProviders(\n providers: Record<string, unknown> | undefined,\n): boolean {\n return Boolean(providers && Object.keys(providers).length > 0);\n}\n"]}
1
+ {"version":3,"file":"provider-companion-discovery.js","sourceRoot":"","sources":["../../../src/project-config/provider-companion-discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EACL,mCAAmC,GAIpC,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,0BAA0B,EAAE,gCAAgC,EAAE,MAAM,UAAU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L,CAAC;AAED,SAAS,kBAAkB,CAAC,UAAkB;IAC5C,IAAI,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/B,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC3C,OAAO,GAAG,KAAK,IAAI,GAAG,EAAE,CAAC;IAC3B,CAAC;IACD,OAAO,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC;AAChD,CAAC;AAED,SAAS,eAAe,CACtB,SAA8C;IAE9C,OAAO,OAAO,CAAC,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import { createRequire } from 'node:module';\nimport { existsSync, readFileSync } from 'node:fs';\nimport { dirname, join, resolve } from 'node:path';\nimport {\n ProviderCompanionContributionSchema,\n type ProviderCompanionContribution,\n type ProviderCompanionRuntimeTarget,\n type RuntimeOwnerCompanionExports,\n} from '@wildo-ai/saas-models';\nimport type { WildoSaasConfig } from './define-saas-config';\nimport { loadPackageCompanionExport, resolvePackageCompanionEntryPath } from './loader';\n\n/**\n * `providerPackage` was added by #330 and is the point of that slice on this file.\n *\n * The other four owner kinds are RUNTIME OWNERS declared in `wildo.saas.config.ts` — an application's\n * own services, libraries, minions and workers. Walking only those is what made a provider shipped as\n * its own npm package invisible to discovery (audit finding PL-1): the package is a DEPENDENCY, not a\n * runtime owner, so nothing ever asked it what it contributes, and an application had to hand-author a\n * contribution for a provider whose own package already knew everything about it.\n */\nexport enum ProviderContributionOwnerKind {\n /** A service package declared in `wildo.saas.config.ts` — the application's backend or a frontend. */\n SERVICE = 'service',\n /** A shared library package of the application. */\n LIBRARY = 'library',\n /** A minion runtime, keyed by its minion name. */\n MINION = 'minion',\n /** A Node worker runtime, keyed by its worker name. */\n WORKER = 'worker',\n /**\n * A provider shipped as its own npm package (#330) — a DEPENDENCY rather than a runtime owner,\n * which is why it needed its own walk and its own member. The value stays camelCase because it is\n * substituted into operator-facing diagnostics beside the four above.\n */\n PROVIDER_PACKAGE = 'providerPackage',\n}\n\n/**\n * Package-name prefixes whose dependencies are treated as provider packages.\n *\n * `@wildo-ai/provider-` is the framework convention (#337 D3). An application's OWN provider packages\n * are admitted through the scope of its root manifest — an application published as `@acme/…` gets\n * `@acme/provider-…` for free — so a private provider needs no configuration to be discovered, and a\n * dependency belonging to somebody else's scope is never executed by this walk.\n */\nexport const FRAMEWORK_PROVIDER_PACKAGE_PREFIX = '@wildo-ai/provider-';\n\n/**\n * The framework's own scraped catalogue, admitted by exact NAME because it does not fit the prefix.\n *\n * Paul decided on 2026-09-06 that the transposed catalogue ships as ONE package with a subpath per\n * vendor — `@wildo-ai/providers/slack` — rather than as 697 packages. The prefix above predates that\n * decision and describes the shape it replaced, and `'@wildo-ai/providers'.startsWith('@wildo-ai/provider-')`\n * is **false**: the `s` is not a `-`.\n *\n * So discovery could not see the catalogue at all. What it DID admit, measured 2026-09-07, was\n * `@wildo-ai/provider-simulators` — the test doubles — and nothing else in the repository matches the\n * prefix. A rule that admits only the simulator of a thing is worse than no rule, because it looks\n * like coverage.\n *\n * An exact name rather than a loosened prefix (`@wildo-ai/provider`, no hyphen) on purpose: that\n * would also admit any future `@wildo-ai/providerfoo`, and the catalogue is ONE known package, not a\n * family. The prefix keeps serving the family it was written for — an application's own\n * `@acme/provider-thing`.\n */\nexport const FRAMEWORK_PROVIDER_CATALOGUE_PACKAGE = '@wildo-ai/providers';\n\n/**\n * The ENGINE's own provider barrel, admitted exactly as the catalogue is.\n *\n * The engine ships 23 providers and exports them through `./companion` — the same shape every\n * provider package uses. Discovery did not admit it, so an application that wanted `resend` declared\n * it THREE times: the scope, a hand-authored `provider-contributions.ts` projecting the engine's own\n * metadata back at it, and the package dependency. The middle one carried no information the other\n * two lacked; config sync refused a scoped-but-uncontributed provider, so it was not optional either\n * (#358).\n *\n * A NAME rather than a prefix, for the reason the catalogue's own note gives: this is one known\n * package, not a family.\n */\nexport const FRAMEWORK_ENGINE_PROVIDER_PACKAGE = '@wildo-ai/external-connectors-private';\n\ninterface ProviderContributionOwner {\n kind: ProviderContributionOwnerKind;\n key: string;\n packageRoot: string;\n}\n\ninterface ProviderContributionTarget extends ProviderContributionOwner {\n ownerLabel: string;\n}\n\nexport interface DiscoveredProviderCompanionContribution extends ProviderCompanionContribution {\n owner: ProviderContributionOwner;\n}\n\nexport interface DiscoverSaasProviderCompanionContributionsResult {\n contributions: DiscoveredProviderCompanionContribution[];\n}\n\n/**\n * The runtime targets an application's SCOPES imply for one provider ref.\n *\n * ## Why a package's declared targets cannot be the answer\n *\n * A provider PACKAGE is shipped once and installed by many applications, so it cannot know any of\n * their runtime topologies. Measured 2026-09-09: all 682 catalogue vendors declare\n * `[{ kind: 'backend' }]` and every engine contribution declares `backend` (plus `companion` for the\n * model-ish ones). Those are defaults standing in for an answer the package is not able to give —\n * a minion key or a worker key exists only in `wildo.saas.config.ts`.\n *\n * The consequence was latent rather than theoretical: a CATALOGUE provider scoped to a minion would\n * have failed materialization with \"no discovered contribution supplies its secret-contract shape\n * for this runtime\", because the package declares a `backend` target and the minion scope looks for\n * a `minion` one. No application had scoped one to a minion yet, so nothing had reported it.\n *\n * ## Why the scopes ARE the answer\n *\n * `providers.scopes` is where an application says which runtimes reach which provider — it is the\n * same decision, already authored, in the place the runtime artifact is built from. Measured against\n * Wonder Todos' hand-authored projections: the scopes reproduce 9 of 10 target sets EXACTLY, and the\n * tenth is a SURPLUS (a `companion` target for a provider the companion scope does not name) which\n * the artifact discards anyway, since it is built from scope INTERSECT contribution.\n *\n * So nothing is lost by deriving, and what is gained is that an application declares a provider once.\n *\n * Applies to contributions discovered from a PACKAGE. A runtime owner's own companion barrel keeps\n * whatever it declares: that is the application's own file talking about itself, and an application\n * package is entitled to state a target the scopes do not.\n */\nfunction resolveScopeImpliedRuntimeTargets(\n providerRef: string,\n saasConfig: Pick<WildoSaasConfig, 'providers'>,\n): ProviderCompanionContribution['runtimeTargets'] {\n const scopes = saasConfig.providers?.scopes;\n if (!scopes) return [];\n const targets: ProviderCompanionContribution['runtimeTargets'] = [];\n\n if (scopes.backend?.providers?.[providerRef]) targets.push({ kind: 'backend' });\n if (scopes.companion?.providers?.[providerRef]) targets.push({ kind: 'companion' });\n for (const [minionKey, scope] of Object.entries(scopes.minions ?? {})) {\n if (scope?.providers?.[providerRef]) targets.push({ kind: 'minion', minionKey });\n }\n for (const [workerKey, scope] of Object.entries(scopes.workers ?? {})) {\n if (scope?.providers?.[providerRef]) targets.push({ kind: 'worker', workerKey });\n }\n return targets;\n}\n\nexport async function discoverSaasProviderCompanionContributions(input: {\n saasRoot: string;\n saasConfig: Pick<WildoSaasConfig, 'services' | 'libraries' | 'minions' | 'providers' | 'workers'>;\n}): Promise<DiscoverSaasProviderCompanionContributionsResult> {\n const contributions: DiscoveredProviderCompanionContribution[] = [];\n\n const runtimeOwnerTargets = resolveContributionTargets(input.saasRoot, input.saasConfig);\n\n for (const target of [\n ...runtimeOwnerTargets,\n ...resolveProviderPackageTargets(input.saasRoot, runtimeOwnerTargets),\n ]) {\n const companionExports = await tryLoadRuntimeOwnerCompanionExports(target.packageRoot);\n if (!companionExports) {\n continue;\n }\n\n const parsedContributions = ProviderCompanionContributionSchema.array().parse(\n companionExports.providerContributions ?? [],\n );\n\n // A PACKAGE cannot know this application's runtime topology, so its declared targets are a\n // default and the SCOPES are the answer. A runtime owner's own barrel keeps what it declares —\n // see `resolveScopeImpliedRuntimeTargets`.\n const derivesTargetsFromScopes = target.kind === ProviderContributionOwnerKind.PROVIDER_PACKAGE;\n\n contributions.push(\n ...parsedContributions.map((contribution) => ({\n ...contribution,\n runtimeTargets: derivesTargetsFromScopes\n ? resolveScopeImpliedRuntimeTargets(contribution.ref, input.saasConfig)\n : contribution.runtimeTargets,\n owner: {\n kind: target.kind,\n key: target.key,\n packageRoot: target.packageRoot,\n },\n })),\n );\n }\n\n return { contributions };\n}\n\n/**\n * Walk an application's provider contributions and VALIDATE them — one step, because the two must\n * never come apart (#334).\n *\n * The walk was already shared; what was duplicated is the PAIRING. `wildo config sync` and\n * `wildo lock check` each called the walker and then, separately, the validator — and the validator\n * sits outside the walker, so a consumer that forgot it would compute a lockfile section from\n * contributions nobody had checked against the authored scope. Three correct call sites with nothing\n * making a fourth correct is the shape `.claude/rules/invariant-call-site-enumeration.md` is about.\n *\n * The caller still LOADS the config. That is deliberate rather than an omission: loading is one line\n * each caller already owns with its own error handling, it is not the part that can silently come\n * apart, and folding it in here would put the load behind a seam that the sync service's own tests\n * mock — `loadSaasConfig` mocked as a module export is not seen by a caller INSIDE this module, so\n * those tests would have had to mock this function instead and would then no longer exercise the real\n * discovery and the real validation they exist to check.\n */\nexport async function resolveValidatedSaasProviderContributions(input: {\n saasRoot: string;\n saasConfig: Pick<WildoSaasConfig, 'modules' | 'services' | 'libraries' | 'minions' | 'providers' | 'workers'>;\n}): Promise<DiscoveredProviderCompanionContribution[]> {\n const { contributions } = await discoverSaasProviderCompanionContributions(input);\n validateDiscoveredSaasProviderContributions({\n saasConfig: input.saasConfig,\n discoveredContributions: contributions,\n });\n return contributions;\n}\n\nexport function validateDiscoveredSaasProviderContributions(input: {\n saasConfig: Pick<WildoSaasConfig, 'modules' | 'providers' | 'services' | 'minions' | 'workers'>;\n discoveredContributions: DiscoveredProviderCompanionContribution[];\n}): void {\n const { saasConfig, discoveredContributions } = input;\n const errors: string[] = [];\n const declaredModuleIds = new Set(Object.keys(saasConfig.modules ?? {}));\n const declaredServiceKeys = new Set(Object.keys(saasConfig.services ?? {}));\n const serviceKeyToFrontendType = new Map<string, string>(\n Object.entries(saasConfig.services ?? {})\n .filter(([, definition]) => definition.frontendType !== undefined)\n .map(([serviceKey, definition]) => [serviceKey, definition.frontendType as string]),\n );\n const declaredFrontendServiceKeys = new Set(serviceKeyToFrontendType.keys());\n const declaredFrontendTypes = new Set(serviceKeyToFrontendType.values());\n const declaredMinionKeys = new Set(Object.keys(saasConfig.minions ?? {}));\n const declaredWorkerKeys = new Set(Object.keys(saasConfig.workers ?? {}));\n\n for (const contribution of discoveredContributions) {\n if (contribution.sourceModuleId && !declaredModuleIds.has(contribution.sourceModuleId)) {\n errors.push(\n `${describeContribution(contribution)} references sourceModuleId \"${contribution.sourceModuleId}\" ` +\n 'but that module is not declared in wildo.saas.config.ts.',\n );\n }\n\n const dependencyNames = readRuntimeReachablePackageNames(contribution.owner.packageRoot);\n const runtimePackageName = extractPackageName(contribution.runtimeImportPath);\n if (!dependencyNames.has(runtimePackageName)) {\n errors.push(\n `${describeContribution(contribution)} declares runtimeImportPath \"${contribution.runtimeImportPath}\" ` +\n `but ${contribution.owner.kind} \"${contribution.owner.key}\" does not depend on \"${runtimePackageName}\".`,\n );\n }\n\n for (const target of contribution.runtimeTargets) {\n switch (target.kind) {\n case 'frontendService':\n if (!declaredFrontendTypes.has(target.serviceType)) {\n errors.push(\n `${describeContribution(contribution)} targets frontendType \"${target.serviceType}\" ` +\n 'but no service with that frontendType is declared in wildo.saas.config.ts.',\n );\n } else if (!contribution.frontendEntry) {\n errors.push(\n `${describeContribution(contribution)} targets frontendType \"${target.serviceType}\" ` +\n 'but does not provide a frontendEntry payload for bootstrap materialization.',\n );\n }\n break;\n case 'minion':\n if (!declaredMinionKeys.has(target.minionKey)) {\n errors.push(\n `${describeContribution(contribution)} targets unknown minion \"${target.minionKey}\".`,\n );\n }\n break;\n case 'worker':\n if (!declaredWorkerKeys.has(target.workerKey)) {\n errors.push(\n `${describeContribution(contribution)} targets unknown worker \"${target.workerKey}\".`,\n );\n }\n break;\n case 'backend':\n case 'companion':\n break;\n }\n }\n }\n\n const runtimeScopes = saasConfig.providers.scopes;\n validateRuntimeScopeAgainstDiscovery({\n errors,\n discoveredContributions,\n scopeLabel: 'backend',\n providers: runtimeScopes.backend?.providers ?? {},\n matchesTarget: (target) => target.kind === 'backend',\n });\n validateRuntimeScopeAgainstDiscovery({\n errors,\n discoveredContributions,\n scopeLabel: 'companion',\n providers: runtimeScopes.companion?.providers ?? {},\n matchesTarget: (target) => target.kind === 'companion',\n });\n\n for (const [serviceKey, scope] of Object.entries(runtimeScopes.frontendServices ?? {})) {\n if (!declaredServiceKeys.has(serviceKey)) {\n errors.push(`Provider scope references unknown frontend service \"${serviceKey}\".`);\n continue;\n }\n if (!declaredFrontendServiceKeys.has(serviceKey)) {\n errors.push(\n `Provider scope references non-frontend service \"${serviceKey}\". ` +\n 'Only services with a frontendType may appear under providers.scopes.frontendServices.',\n );\n continue;\n }\n const serviceType = serviceKeyToFrontendType.get(serviceKey);\n validateRuntimeScopeAgainstDiscovery({\n errors,\n discoveredContributions,\n scopeLabel: `frontendServices.${serviceKey}`,\n providers: scope.providers,\n matchesTarget: (target) => target.kind === 'frontendService' && target.serviceType === serviceType,\n });\n }\n\n for (const [minionKey, scope] of Object.entries(runtimeScopes.minions ?? {})) {\n validateRuntimeScopeAgainstDiscovery({\n errors,\n discoveredContributions,\n scopeLabel: `minions.${minionKey}`,\n providers: scope.providers,\n matchesTarget: (target) => target.kind === 'minion' && target.minionKey === minionKey,\n });\n }\n\n for (const [workerKey, scope] of Object.entries(runtimeScopes.workers ?? {})) {\n validateRuntimeScopeAgainstDiscovery({\n errors,\n discoveredContributions,\n scopeLabel: `workers.${workerKey}`,\n providers: scope.providers,\n matchesTarget: (target) => target.kind === 'worker' && target.workerKey === workerKey,\n });\n }\n\n if (errors.length > 0) {\n throw new Error(\n `Provider companion-export discovery validation failed:\\n- ${errors.join('\\n- ')}`,\n );\n }\n}\n\nfunction resolveContributionTargets(\n saasRoot: string,\n saasConfig: Pick<WildoSaasConfig, 'services' | 'libraries' | 'minions' | 'providers' | 'workers'>,\n): ProviderContributionTarget[] {\n const shouldIncludeBackendServices = hasAnyProviders(saasConfig.providers.scopes.backend?.providers);\n const frontendServiceProviderScopes = Object.entries(saasConfig.providers.scopes.frontendServices ?? {})\n .filter(([, scope]) => hasAnyProviders(scope.providers))\n .map(([serviceKey]) => serviceKey);\n const minionProviderScopes = Object.entries(saasConfig.providers.scopes.minions ?? {})\n .filter(([, scope]) => hasAnyProviders(scope.providers))\n .map(([minionKey]) => minionKey);\n const workerProviderScopes = Object.entries(saasConfig.providers.scopes.workers ?? {})\n .filter(([, scope]) => hasAnyProviders(scope.providers))\n .map(([workerKey]) => workerKey);\n\n return [\n ...Object.entries(saasConfig.services)\n .filter(([key, definition]) => (\n definition.frontendType\n ? frontendServiceProviderScopes.includes(key)\n : shouldIncludeBackendServices\n ))\n .map(([key, definition]) => ({\n kind: ProviderContributionOwnerKind.SERVICE,\n key,\n ownerLabel: `service \"${key}\"`,\n packageRoot: resolve(saasRoot, definition.path),\n })),\n ...Object.entries(saasConfig.libraries ?? {}).map(([key, definition]) => ({\n kind: ProviderContributionOwnerKind.LIBRARY,\n key,\n ownerLabel: `library \"${key}\"`,\n packageRoot: resolve(saasRoot, definition.path),\n })),\n ...Object.entries(saasConfig.minions ?? {})\n .filter(([key]) => minionProviderScopes.includes(key))\n .map(([key, definition]) => ({\n kind: ProviderContributionOwnerKind.MINION,\n key,\n ownerLabel: `minion \"${key}\"`,\n packageRoot: resolve(saasRoot, definition.path),\n })),\n ...Object.entries(saasConfig.workers ?? {})\n .filter(([key]) => workerProviderScopes.includes(key))\n .map(([key, definition]) => ({\n kind: ProviderContributionOwnerKind.WORKER,\n key,\n ownerLabel: `worker \"${key}\"`,\n packageRoot: resolve(saasRoot, definition.path),\n })),\n ];\n}\n\n/**\n * Every provider PACKAGE this application depends on, as a contribution target.\n *\n * Candidates come from the application root manifest AND from each runtime owner's manifest, because\n * both layouts are real: a scaffolded application declares its provider packages in the runtime owner\n * that imports them (`backend-api`), while a workspace root may hoist them. The union is deduplicated\n * by resolved package root, so a package declared in both places is walked once.\n *\n * A candidate that cannot be resolved on disk is SKIPPED rather than refused. The manifest is the\n * declaration and `node_modules` is the install; a name declared but not installed is an install\n * problem that `pnpm install` reports far better than a config-sync stack trace would, and refusing\n * here would make `wildo config sync` unrunnable in exactly the state where an operator runs it to\n * find out what is wrong.\n */\nfunction resolveProviderPackageTargets(\n saasRoot: string,\n runtimeOwnerTargets: ProviderContributionTarget[],\n): ProviderContributionTarget[] {\n const prefixes = resolveProviderPackagePrefixes(saasRoot);\n const searchRoots = [saasRoot, ...runtimeOwnerTargets.map((target) => target.packageRoot)];\n\n const candidateNames = new Set<string>();\n for (const searchRoot of searchRoots) {\n for (const dependencyName of readRuntimeReachablePackageNames(searchRoot)) {\n if (dependencyName === FRAMEWORK_PROVIDER_CATALOGUE_PACKAGE\n || dependencyName === FRAMEWORK_ENGINE_PROVIDER_PACKAGE\n || prefixes.some((prefix) => dependencyName.startsWith(prefix))) {\n candidateNames.add(dependencyName);\n }\n }\n }\n\n const targetsByRoot = new Map<string, ProviderContributionTarget>();\n for (const packageName of [...candidateNames].sort()) {\n const packageRoot = resolveProviderPackageRoot(packageName, searchRoots);\n if (!packageRoot || targetsByRoot.has(packageRoot)) {\n continue;\n }\n targetsByRoot.set(packageRoot, {\n kind: ProviderContributionOwnerKind.PROVIDER_PACKAGE,\n key: packageName,\n ownerLabel: `provider package \"${packageName}\"`,\n packageRoot,\n });\n }\n\n return [...targetsByRoot.values()];\n}\n\n/**\n * The framework prefix, plus the application's own scope when its root manifest has one.\n *\n * Deriving the second from the root package name rather than reading it from configuration keeps the\n * \"one declaration\" promise of #330 intact: installing `@acme/provider-thing` in an `@acme` application\n * and scoping the ref is the whole of it — there is no third place to remember.\n */\nfunction resolveProviderPackagePrefixes(saasRoot: string): string[] {\n const prefixes = [FRAMEWORK_PROVIDER_PACKAGE_PREFIX];\n const rootPackageName = readPackageName(saasRoot);\n const scope = rootPackageName?.startsWith('@') ? rootPackageName.split('/')[0] : undefined;\n if (scope && scope !== '@wildo-ai') {\n prefixes.push(`${scope}/provider-`);\n }\n return prefixes;\n}\n\n/**\n * Locate an installed package's ROOT DIRECTORY, which is what the companion-entry resolver needs.\n *\n * The direct `node_modules` probe comes first because it is what pnpm actually produces — a symlink\n * per importer — and because it works for a package whose `exports` map declares no `./package.json`,\n * which `require.resolve` cannot see past. `createRequire` is the fallback for hoisted or otherwise\n * unusual layouts; it resolves the companion subpath (the one door every provider package declares)\n * and walks up to the manifest that names the package.\n */\nfunction resolveProviderPackageRoot(packageName: string, searchRoots: string[]): string | undefined {\n /*\n * The name comes from a manifest and is spliced into a filesystem path, so a segment that is `.` or\n * `..` would walk OUT of `node_modules` — and the prefix gate would not stop it, since\n * `@wildo-ai/provider-x/../../elsewhere` starts with the framework prefix. npm forbids such a name,\n * which is precisely why nothing downstream would question it; the check costs one line and is the\n * only thing standing between an authored dependency name and an arbitrary directory whose\n * companion entry this walk EXECUTES.\n */\n const segments = packageName.split('/');\n if (segments.some((segment) => segment.length === 0 || segment === '.' || segment === '..')) {\n return undefined;\n }\n\n for (const searchRoot of searchRoots) {\n const candidate = join(searchRoot, 'node_modules', ...segments);\n if (existsSync(join(candidate, 'package.json'))) {\n return candidate;\n }\n }\n\n for (const searchRoot of searchRoots) {\n try {\n const resolved = createRequire(join(searchRoot, 'package.json')).resolve(`${packageName}/companion`);\n let directory = dirname(resolved);\n while (directory !== dirname(directory)) {\n if (readPackageName(directory) === packageName) {\n return directory;\n }\n directory = dirname(directory);\n }\n } catch {\n // Not resolvable from this root; try the next one, then give up quietly (see the JSDoc above).\n }\n }\n\n return undefined;\n}\n\nfunction readPackageName(packageRoot: string): string | undefined {\n const packageJsonPath = join(packageRoot, 'package.json');\n if (!existsSync(packageJsonPath)) {\n return undefined;\n }\n try {\n return (JSON.parse(readFileSync(packageJsonPath, 'utf-8')) as { name?: string }).name;\n } catch {\n return undefined;\n }\n}\n\nasync function tryLoadRuntimeOwnerCompanionExports(\n packageRoot: string,\n): Promise<RuntimeOwnerCompanionExports | undefined> {\n try {\n resolvePackageCompanionEntryPath(packageRoot);\n } catch {\n return undefined;\n }\n\n return loadPackageCompanionExport<RuntimeOwnerCompanionExports>(packageRoot);\n}\n\nfunction validateRuntimeScopeAgainstDiscovery(input: {\n errors: string[];\n discoveredContributions: DiscoveredProviderCompanionContribution[];\n scopeLabel: string;\n providers: NonNullable<WildoSaasConfig['providers']['scopes']['backend']>['providers'];\n matchesTarget: (target: ProviderCompanionRuntimeTarget) => boolean;\n}): void {\n const { errors, discoveredContributions, matchesTarget, providers, scopeLabel } = input;\n\n for (const [providerRef, authoredSelection] of Object.entries(providers)) {\n const matchingContributions = discoveredContributions.filter(\n (contribution) => contribution.ref === providerRef\n && contribution.runtimeTargets.some(matchesTarget),\n );\n\n if (matchingContributions.length === 0) {\n errors.push(\n `Provider \"${providerRef}\" is authored in scope \"${scopeLabel}\" but no companion export contributes it for that runtime.`,\n );\n continue;\n }\n\n const discoveredEngineCapabilities = new Set(\n matchingContributions.flatMap((contribution) => contribution.engineCapabilities),\n );\n const discoveredProviderCapabilities = new Set(\n matchingContributions.flatMap((contribution) => contribution.providerCapabilities),\n );\n const discoveredProtocols = new Set(\n matchingContributions.flatMap((contribution) => contribution.protocols),\n );\n\n for (const capability of authoredSelection.engineCapabilities) {\n if (!discoveredEngineCapabilities.has(capability)) {\n errors.push(\n `Provider \"${providerRef}\" in scope \"${scopeLabel}\" declares engine capability \"${capability}\" ` +\n 'but discovery does not report that capability for the same runtime.',\n );\n }\n }\n\n for (const capability of authoredSelection.providerCapabilities) {\n if (!discoveredProviderCapabilities.has(capability)) {\n errors.push(\n `Provider \"${providerRef}\" in scope \"${scopeLabel}\" declares provider capability \"${capability}\" ` +\n 'but discovery does not report that capability for the same runtime.',\n );\n }\n }\n\n for (const protocol of authoredSelection.protocols) {\n if (!discoveredProtocols.has(protocol)) {\n errors.push(\n `Provider \"${providerRef}\" in scope \"${scopeLabel}\" declares protocol \"${protocol}\" ` +\n 'but discovery does not report that protocol for the same runtime.',\n );\n }\n }\n }\n}\n\nfunction describeContribution(contribution: DiscoveredProviderCompanionContribution): string {\n return `Provider contribution \"${contribution.ref}\" from ${contribution.owner.kind} \"${contribution.owner.key}\"`;\n}\n\nfunction readRuntimeReachablePackageNames(packageRoot: string): Set<string> {\n const packageJsonPath = join(packageRoot, 'package.json');\n if (!existsSync(packageJsonPath)) {\n return new Set<string>();\n }\n\n const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8')) as {\n name?: string;\n dependencies?: Record<string, string>;\n peerDependencies?: Record<string, string>;\n optionalDependencies?: Record<string, string>;\n };\n\n return new Set([\n ...(packageJson.name ? [packageJson.name] : []),\n ...Object.keys(packageJson.dependencies ?? {}),\n ...Object.keys(packageJson.peerDependencies ?? {}),\n ...Object.keys(packageJson.optionalDependencies ?? {}),\n ]);\n}\n\nfunction extractPackageName(importPath: string): string {\n if (importPath.startsWith('@')) {\n const [scope, pkg] = importPath.split('/');\n return `${scope}/${pkg}`;\n }\n return importPath.split('/')[0] ?? importPath;\n}\n\nfunction hasAnyProviders(\n providers: Record<string, unknown> | undefined,\n): boolean {\n return Boolean(providers && Object.keys(providers).length > 0);\n}\n"]}