@wildo-ai/platform-config-lib 1.1.5 → 1.1.7
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.
- package/dist/esm/_unimplemented/index.d.ts.map +1 -1
- package/dist/esm/_unimplemented/index.js.map +1 -1
- package/dist/esm/_unimplemented/soft-warn.d.ts.map +1 -1
- package/dist/esm/_unimplemented/soft-warn.js.map +1 -1
- package/dist/esm/_unimplemented/unimplemented-field-warning.d.ts.map +1 -1
- package/dist/esm/_unimplemented/unimplemented-field-warning.js.map +1 -1
- package/dist/esm/bootstrap/application-backend-env.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/application-backend-env.contracts.js.map +1 -1
- package/dist/esm/bootstrap/application-creation-verification-env.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/application-creation-verification-env.contracts.js.map +1 -1
- package/dist/esm/bootstrap/bootstrap-planner.d.ts.map +1 -1
- package/dist/esm/bootstrap/bootstrap-planner.js.map +1 -1
- package/dist/esm/bootstrap/bootstrap.contracts.d.ts +3 -2
- package/dist/esm/bootstrap/bootstrap.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/bootstrap.contracts.js +3 -2
- package/dist/esm/bootstrap/bootstrap.contracts.js.map +1 -1
- package/dist/esm/bootstrap/bootstrap.schemas.d.ts +47 -0
- package/dist/esm/bootstrap/bootstrap.schemas.d.ts.map +1 -1
- package/dist/esm/bootstrap/bootstrap.schemas.js +8 -0
- package/dist/esm/bootstrap/bootstrap.schemas.js.map +1 -1
- package/dist/esm/bootstrap/platform-runtime-env.contracts.d.ts +12 -1
- package/dist/esm/bootstrap/platform-runtime-env.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/platform-runtime-env.contracts.js +12 -0
- package/dist/esm/bootstrap/platform-runtime-env.contracts.js.map +1 -1
- package/dist/esm/bootstrap/platform-store-preconnect.d.ts +37 -0
- package/dist/esm/bootstrap/platform-store-preconnect.d.ts.map +1 -0
- package/dist/esm/bootstrap/platform-store-preconnect.js +43 -0
- package/dist/esm/bootstrap/platform-store-preconnect.js.map +1 -0
- package/dist/esm/bootstrap/runtime-backing-service-access.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-backing-service-access.js +8 -4
- package/dist/esm/bootstrap/runtime-backing-service-access.js.map +1 -1
- package/dist/esm/bootstrap/runtime-network-policy.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-network-policy.js.map +1 -1
- package/dist/esm/bootstrap/runtime-network-topology.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-network-topology.js.map +1 -1
- package/dist/esm/bootstrap/runtime-platform-access.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-platform-access.js.map +1 -1
- package/dist/esm/bootstrap/runtime-principal.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-principal.contracts.js.map +1 -1
- package/dist/esm/bootstrap/runtime-topology.contracts.d.ts +36 -3
- package/dist/esm/bootstrap/runtime-topology.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-topology.contracts.js +36 -13
- package/dist/esm/bootstrap/runtime-topology.contracts.js.map +1 -1
- package/dist/esm/bootstrap/wildo-owner-organization.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/wildo-owner-organization.contracts.js.map +1 -1
- package/dist/esm/config-authoring.entry.d.ts.map +1 -1
- package/dist/esm/config-authoring.entry.js.map +1 -1
- package/dist/esm/credentials/credential-generator.service.d.ts.map +1 -1
- package/dist/esm/credentials/credential-generator.service.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lockfile/build-parallelism.d.ts.map +1 -1
- package/dist/esm/lockfile/build-parallelism.js.map +1 -1
- package/dist/esm/lockfile/canonical-json.d.ts.map +1 -1
- package/dist/esm/lockfile/canonical-json.js.map +1 -1
- package/dist/esm/lockfile/lockfile-io.d.ts +7 -1
- package/dist/esm/lockfile/lockfile-io.d.ts.map +1 -1
- package/dist/esm/lockfile/lockfile-io.js +17 -3
- package/dist/esm/lockfile/lockfile-io.js.map +1 -1
- package/dist/esm/lockfile/materialize-infra-section.d.ts +27 -6
- package/dist/esm/lockfile/materialize-infra-section.d.ts.map +1 -1
- package/dist/esm/lockfile/materialize-infra-section.js +23 -10
- package/dist/esm/lockfile/materialize-infra-section.js.map +1 -1
- package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.d.ts +455 -6
- package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.d.ts.map +1 -1
- package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.js +27 -0
- package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.js.map +1 -1
- package/dist/esm/project-config/application-public-pricing-catalog.loader.d.ts +13 -0
- package/dist/esm/project-config/application-public-pricing-catalog.loader.d.ts.map +1 -0
- package/dist/esm/project-config/application-public-pricing-catalog.loader.js +56 -0
- package/dist/esm/project-config/application-public-pricing-catalog.loader.js.map +1 -0
- package/dist/esm/project-config/define-framework-config.d.ts.map +1 -1
- package/dist/esm/project-config/define-framework-config.js.map +1 -1
- package/dist/esm/project-config/define-infra-env-config.d.ts +0 -27
- package/dist/esm/project-config/define-infra-env-config.d.ts.map +1 -1
- package/dist/esm/project-config/define-infra-env-config.js +0 -2
- package/dist/esm/project-config/define-infra-env-config.js.map +1 -1
- package/dist/esm/project-config/define-minion-config.d.ts.map +1 -1
- package/dist/esm/project-config/define-minion-config.js.map +1 -1
- package/dist/esm/project-config/define-saas-config.d.ts +52 -0
- package/dist/esm/project-config/define-saas-config.d.ts.map +1 -1
- package/dist/esm/project-config/define-saas-config.js +65 -15
- package/dist/esm/project-config/define-saas-config.js.map +1 -1
- package/dist/esm/project-config/define-worker-config.d.ts.map +1 -1
- package/dist/esm/project-config/define-worker-config.js.map +1 -1
- package/dist/esm/project-config/hosted-infra-env-config.d.ts.map +1 -1
- package/dist/esm/project-config/hosted-infra-env-config.js.map +1 -1
- package/dist/esm/project-config/index.d.ts +3 -0
- package/dist/esm/project-config/index.d.ts.map +1 -1
- package/dist/esm/project-config/index.js +3 -0
- package/dist/esm/project-config/index.js.map +1 -1
- package/dist/esm/project-config/loader.d.ts +11 -0
- package/dist/esm/project-config/loader.d.ts.map +1 -1
- package/dist/esm/project-config/loader.js +34 -7
- package/dist/esm/project-config/loader.js.map +1 -1
- package/dist/esm/project-config/minion-local-provider-registration.d.ts.map +1 -1
- package/dist/esm/project-config/minion-local-provider-registration.js.map +1 -1
- package/dist/esm/project-config/npm-version-range.d.ts +23 -0
- package/dist/esm/project-config/npm-version-range.d.ts.map +1 -0
- package/dist/esm/project-config/npm-version-range.js +175 -0
- package/dist/esm/project-config/npm-version-range.js.map +1 -0
- package/dist/esm/project-config/provider-catalog-types.d.ts.map +1 -1
- package/dist/esm/project-config/provider-catalog-types.js.map +1 -1
- package/dist/esm/project-config/provider-companion-discovery.d.ts +256 -30
- package/dist/esm/project-config/provider-companion-discovery.d.ts.map +1 -1
- package/dist/esm/project-config/provider-companion-discovery.js +719 -40
- package/dist/esm/project-config/provider-companion-discovery.js.map +1 -1
- package/dist/esm/project-config/provider-runtime-artifacts.d.ts +125 -2
- package/dist/esm/project-config/provider-runtime-artifacts.d.ts.map +1 -1
- package/dist/esm/project-config/provider-runtime-artifacts.js +283 -66
- package/dist/esm/project-config/provider-runtime-artifacts.js.map +1 -1
- package/dist/esm/project-config/shared/application-creation-verification.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/application-creation-verification.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/application-modules.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/application-modules.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/application-modules.utils.d.ts.map +1 -1
- package/dist/esm/project-config/shared/application-modules.utils.js.map +1 -1
- package/dist/esm/project-config/shared/auth.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/auth.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/backing-service-servability.d.ts +157 -0
- package/dist/esm/project-config/shared/backing-service-servability.d.ts.map +1 -0
- package/dist/esm/project-config/shared/backing-service-servability.js +256 -0
- package/dist/esm/project-config/shared/backing-service-servability.js.map +1 -0
- package/dist/esm/project-config/shared/backing-services.schemas.d.ts +62 -67
- package/dist/esm/project-config/shared/backing-services.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/backing-services.schemas.js +71 -68
- package/dist/esm/project-config/shared/backing-services.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/cdn.example.d.ts.map +1 -1
- package/dist/esm/project-config/shared/cdn.example.js.map +1 -1
- package/dist/esm/project-config/shared/cdn.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/cdn.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/csp-defaults.d.ts.map +1 -1
- package/dist/esm/project-config/shared/csp-defaults.js.map +1 -1
- package/dist/esm/project-config/shared/csp-emit.d.ts.map +1 -1
- package/dist/esm/project-config/shared/csp-emit.js +41 -2
- package/dist/esm/project-config/shared/csp-emit.js.map +1 -1
- package/dist/esm/project-config/shared/csp.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/csp.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/data-services.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/data-services.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/env-example-defaults.d.ts.map +1 -1
- package/dist/esm/project-config/shared/env-example-defaults.js.map +1 -1
- package/dist/esm/project-config/shared/environment.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/environment.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/infra-providers.schemas.d.ts +180 -4
- package/dist/esm/project-config/shared/infra-providers.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/infra-providers.schemas.js +40 -0
- package/dist/esm/project-config/shared/infra-providers.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/infra-service.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/infra-service.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/infrastructure-defaults.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/infrastructure-defaults.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/k8s-utils.d.ts.map +1 -1
- package/dist/esm/project-config/shared/k8s-utils.js.map +1 -1
- package/dist/esm/project-config/shared/minion-platform-access.vocabulary.d.ts.map +1 -1
- package/dist/esm/project-config/shared/minion-platform-access.vocabulary.js.map +1 -1
- package/dist/esm/project-config/shared/minion-resource-access.validation.d.ts.map +1 -1
- package/dist/esm/project-config/shared/minion-resource-access.validation.js.map +1 -1
- package/dist/esm/project-config/shared/object-storage-session-policy.d.ts.map +1 -1
- package/dist/esm/project-config/shared/object-storage-session-policy.js.map +1 -1
- package/dist/esm/project-config/shared/platform-services.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/platform-services.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/platform-storage.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/platform-storage.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/schema-version.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/schema-version.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/service-definitions.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/service-definitions.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/systems-of-record-env.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/systems-of-record-env.schemas.js.map +1 -1
- package/dist/esm/project-config/static-asset-import-noop.d.ts +26 -0
- package/dist/esm/project-config/static-asset-import-noop.d.ts.map +1 -0
- package/dist/esm/project-config/static-asset-import-noop.js +49 -0
- package/dist/esm/project-config/static-asset-import-noop.js.map +1 -0
- package/dist/esm/registry/artifact-domain.schemas.d.ts.map +1 -1
- package/dist/esm/registry/artifact-domain.schemas.js.map +1 -1
- package/dist/esm/registry/digest.schemas.d.ts.map +1 -1
- package/dist/esm/registry/digest.schemas.js.map +1 -1
- package/dist/esm/registry/index.d.ts +3 -1
- package/dist/esm/registry/index.d.ts.map +1 -1
- package/dist/esm/registry/index.js +3 -1
- package/dist/esm/registry/index.js.map +1 -1
- package/dist/esm/registry/local-checkout-source.d.ts +31 -0
- package/dist/esm/registry/local-checkout-source.d.ts.map +1 -0
- package/dist/esm/registry/local-checkout-source.js +45 -0
- package/dist/esm/registry/local-checkout-source.js.map +1 -0
- package/dist/esm/registry/lockfile-modules-section.schemas.d.ts +174 -14
- package/dist/esm/registry/lockfile-modules-section.schemas.d.ts.map +1 -1
- package/dist/esm/registry/lockfile-modules-section.schemas.js +120 -11
- package/dist/esm/registry/lockfile-modules-section.schemas.js.map +1 -1
- package/dist/esm/registry/module-artifact.schemas.d.ts +79 -0
- package/dist/esm/registry/module-artifact.schemas.d.ts.map +1 -1
- package/dist/esm/registry/module-artifact.schemas.js +36 -0
- package/dist/esm/registry/module-artifact.schemas.js.map +1 -1
- package/dist/esm/registry/module-manifest.schemas.d.ts +393 -7
- package/dist/esm/registry/module-manifest.schemas.d.ts.map +1 -1
- package/dist/esm/registry/module-manifest.schemas.js +488 -40
- package/dist/esm/registry/module-manifest.schemas.js.map +1 -1
- package/dist/esm/registry/module-search.schemas.d.ts +80 -0
- package/dist/esm/registry/module-search.schemas.d.ts.map +1 -0
- package/dist/esm/registry/module-search.schemas.js +112 -0
- package/dist/esm/registry/module-search.schemas.js.map +1 -0
- package/dist/esm/registry/registry-config.schemas.d.ts +16 -0
- package/dist/esm/registry/registry-config.schemas.d.ts.map +1 -1
- package/dist/esm/registry/registry-config.schemas.js +8 -0
- package/dist/esm/registry/registry-config.schemas.js.map +1 -1
- package/dist/esm/registry/registry-defaults.constants.d.ts.map +1 -1
- package/dist/esm/registry/registry-defaults.constants.js.map +1 -1
- package/dist/esm/registry/registry-errors.d.ts +126 -2
- package/dist/esm/registry/registry-errors.d.ts.map +1 -1
- package/dist/esm/registry/registry-errors.js +183 -14
- package/dist/esm/registry/registry-errors.js.map +1 -1
- package/dist/esm/registry/registry-keys.schemas.d.ts +80 -0
- package/dist/esm/registry/registry-keys.schemas.d.ts.map +1 -0
- package/dist/esm/registry/registry-keys.schemas.js +68 -0
- package/dist/esm/registry/registry-keys.schemas.js.map +1 -0
- package/dist/esm/registry/registry-section-schemas.constants.d.ts +25 -3
- package/dist/esm/registry/registry-section-schemas.constants.d.ts.map +1 -1
- package/dist/esm/registry/registry-section-schemas.constants.js.map +1 -1
- package/dist/esm/release/framework-release.constants.d.ts.map +1 -1
- package/dist/esm/release/framework-release.constants.js.map +1 -1
- package/dist/esm/schemas/framework-info.schemas.d.ts.map +1 -1
- package/dist/esm/schemas/framework-info.schemas.js.map +1 -1
- package/dist/esm/schemas/framework-secrets.schemas.d.ts.map +1 -1
- package/dist/esm/schemas/framework-secrets.schemas.js.map +1 -1
- package/dist/esm/schemas/platform-application-config.schemas.d.ts.map +1 -1
- package/dist/esm/schemas/platform-application-config.schemas.js.map +1 -1
- package/dist/esm/schemas/platform-application-secrets.schemas.d.ts.map +1 -1
- package/dist/esm/schemas/platform-application-secrets.schemas.js.map +1 -1
- package/dist/esm/schemas/platform-config.schemas.d.ts.map +1 -1
- package/dist/esm/schemas/platform-config.schemas.js.map +1 -1
- package/dist/esm/workspace-scope/application-subject-manifest.d.ts.map +1 -1
- package/dist/esm/workspace-scope/application-subject-manifest.js.map +1 -1
- package/dist/esm/workspace-scope/index.d.ts.map +1 -1
- package/dist/esm/workspace-scope/index.js.map +1 -1
- package/dist/esm/workspace-scope/resolve-homes.d.ts.map +1 -1
- package/dist/esm/workspace-scope/resolve-homes.js.map +1 -1
- package/dist/esm/workspace-scope/workspace-homes.schemas.d.ts +13 -11
- package/dist/esm/workspace-scope/workspace-homes.schemas.d.ts.map +1 -1
- package/dist/esm/workspace-scope/workspace-homes.schemas.js +2 -2
- package/dist/esm/workspace-scope/workspace-homes.schemas.js.map +1 -1
- package/dist/esm/workspace-scope/workspace-scope-detector.d.ts.map +1 -1
- package/dist/esm/workspace-scope/workspace-scope-detector.js.map +1 -1
- package/dist/esm/workspace-scope/workspace-scope.schemas.d.ts.map +1 -1
- package/dist/esm/workspace-scope/workspace-scope.schemas.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/dist/esm/registry/companion-api.schemas.d.ts +0 -176
- package/dist/esm/registry/companion-api.schemas.d.ts.map +0 -1
- package/dist/esm/registry/companion-api.schemas.js +0 -165
- package/dist/esm/registry/companion-api.schemas.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wildo-owner-organization.contracts.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"wildo-owner-organization.contracts.js","sourceRoot":"","sources":["../../../src/bootstrap/wildo-owner-organization.contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,wBAAwB,EAAsD,MAAM,uBAAuB,CAAC;AAuDvJ;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,QAAQ,CAAC;AAExD,MAAM,CAAC,MAAM,yBAAyB,GAAoB;IACxD,CAAC,+BAA+B,CAAC,EAAE,wBAAwB,CAAC,KAAK,CAAC;QAChE,IAAI,EAAE,EAAE,YAAY,EAAE,EAAE,IAAI,EAAE,gBAAgB,CAAC,QAAQ,EAAE,EAAE;KAC5D,CAAC;CACH,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,mBAAmB,CAAC;AAEpE,MAAM,CAAC,MAAM,iCAAiC,GAA4B;IACxE,CAAC,gCAAgC,CAAC,EAAE;QAClC,SAAS,EAAE,CAAC,+BAA+B,CAAC;QAC5C,iBAAiB,EAAE,CAAC,cAAc,CAAC,SAAS,EAAE,cAAc,CAAC,SAAS,EAAE,cAAc,CAAC,UAAU,CAAC;QAClG,iBAAiB,EAAE,cAAc,CAAC,UAAU;QAC5C,aAAa,EAAE,SAAS;KACzB;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,wBAAwB,GAAmC;IACtE,IAAI,EAAE,OAAO;IACb,IAAI,EAAE,OAAO;IACb,IAAI,EAAE,gCAAgC;CACvC,CAAC","sourcesContent":["import { CORE_ORG_ROLES, RegistrationMode, UserTypeDefinitionSchema, type OrganizationTypesConfig, type UserTypesConfig } from '@wildo-ai/saas-models';\n\n/**\n * The ONE identity of the organization that owns Wildo's own applications.\n *\n * ## Why this constant exists\n *\n * This identity used to be hardcoded FOUR times, in two files, as TWO DIFFERENT VALUES — and the\n * result was a platform carrying two organizations, neither of them a customer:\n *\n * | declared in | value |\n * |---|---|\n * | `init-mode-startup.apps-manager.service.ts` (twice) | `wildo-platform` / `Wildo Platform` |\n * | `maintenance/services/app-initialization.service.ts` (twice) | `wildo` / `Wildo` |\n *\n * The two paths provision different things, so ownership split along them. Measured on the dogfood\n * platform (2026-09-01): `wildo-ai-application` — the bootstrap row — was owned by `wildo-platform`,\n * while `wonder-crm`, `wonder-todos` and `secrets-proof` were owned by `wildo`. Worse, OPERATOR\n * REACH followed the same split: the admin seeded by INIT was `ORG_ADMIN` of BOTH organizations,\n * while an admin seeded later by the maintenance path was a member of `wildo` ONLY. Nothing declared\n * that they should differ; it was decided by which code path happened to run.\n *\n * The bootstrap organization is also `ACTIVE` and authority-conferring, so everything that\n * ENUMERATES tenants — an organization switcher, the owner-floor boot report, a cross-tenant audit,\n * a subject-erasure sweep — counted a bootstrap artifact as a real tenant.\n *\n * ## Why ONE organization rather than two declared ones\n *\n * The second organization was never a design. `seedBootstrapApplicationRecord` needs *an* owner for\n * the minimal APPLICATION row it seeds to break a chicken-and-egg (an APPLICATION-primary-scoped\n * execution context resolves its `applicationId` by READING that row). It needs an owner; it never\n * needed a DIFFERENT one. Wildo owning all Wildo applications — including its own — is the coherent\n * reading, and it is what the duplication suggests was intended before the two literals drifted.\n *\n * If a future decision genuinely wants the platform's own application in a separate tenant, that is\n * a SECOND named constant here plus an explicit statement of which consumers must tell them apart —\n * not a second literal at a call site.\n *\n * ## What this does NOT do\n *\n * It does not retrofit an existing platform. Both bootstrap seeding arms look a row up by business\n * key and insert ONLY when absent, and the registration path prefers an existing application's\n * recorded `ownerOrganizationId` over the seeded id — so an installation that already carries two\n * organizations keeps both, with its existing linkage untouched. Only a FRESH platform gets one.\n * Merging the two on an existing installation is a migration with its own decision.\n */\nexport interface WildoOwnerOrganizationIdentity {\n /** Business key. Both provisioning paths upsert the organization by THIS field. */\n readonly slug: string;\n /** Display name written on first seed. */\n readonly name: string;\n /** The organization type written on first seed — a key of {@link WILDO_PLATFORM_ORGANIZATION_TYPES}. */\n readonly type: typeof WILDO_PLATFORM_ORGANIZATION_TYPE;\n}\n\n/**\n * The user type the platform seeds its first administrator with, and the one its organization type grants.\n *\n * Declared because it was already HELD: the platform's INIT seed gave its first administrator `member` long before\n * the platform declared any user type, and nothing checked the pair until organization types — whose granted user\n * types must be declared — became mandatory (#1032). Registration is DISABLED: a platform user exists because the\n * platform seeded them, never because someone signed up.\n */\nexport const WILDO_PLATFORM_MEMBER_USER_TYPE = 'member';\n\nexport const WILDO_PLATFORM_USER_TYPES: UserTypesConfig = {\n [WILDO_PLATFORM_MEMBER_USER_TYPE]: UserTypeDefinitionSchema.parse({\n auth: { registration: { mode: RegistrationMode.DISABLED } },\n }),\n};\n\n/**\n * The ONE organization type the platform's own tenancy declares (#1032, decided 2026-09-14).\n *\n * Every organization carries a type that names a declared organization type, because a member of an\n * organization whose type resolves to nothing cannot sign in. An application declares its types in\n * `wildo.saas.config.ts`; the platform has no such file, so its declaration lives here, beside the\n * identity of the organization it types. Before this, the platform seeded its organizations with no\n * type at all, and `wildo_platform` held two of them.\n *\n * It grants {@link WILDO_PLATFORM_MEMBER_USER_TYPE}, the user type the platform's INIT seeds its first administrator\n * with, so the platform's own first-organization derivation resolves to this type rather than refusing — and a\n * configuration carrying this map must carry {@link WILDO_PLATFORM_USER_TYPES} beside it, or its granted user type\n * is undeclared.\n */\nexport const WILDO_PLATFORM_ORGANIZATION_TYPE = 'platform-operator';\n\nexport const WILDO_PLATFORM_ORGANIZATION_TYPES: OrganizationTypesConfig = {\n [WILDO_PLATFORM_ORGANIZATION_TYPE]: {\n userTypes: [WILDO_PLATFORM_MEMBER_USER_TYPE],\n availableOrgRoles: [CORE_ORG_ROLES.ORG_OWNER, CORE_ORG_ROLES.ORG_ADMIN, CORE_ORG_ROLES.ORG_MEMBER],\n defaultMemberRole: CORE_ORG_ROLES.ORG_MEMBER,\n authOverrides: undefined,\n },\n};\n\nexport const WILDO_OWNER_ORGANIZATION: WildoOwnerOrganizationIdentity = {\n slug: 'wildo',\n name: 'Wildo',\n type: WILDO_PLATFORM_ORGANIZATION_TYPE,\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-authoring.entry.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"config-authoring.entry.d.ts","sourceRoot":"","sources":["../../src/config-authoring.entry.ts"],"names":[],"mappings":"AAsCA,cAAc,SAAS,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-authoring.entry.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"config-authoring.entry.js","sourceRoot":"","sources":["../../src/config-authoring.entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,iBAAiB,EAAE,CAAC;AAEpB,cAAc,SAAS,CAAC","sourcesContent":["/**\n * What `@wildo-ai/platform-config-lib` resolves to while the CONFIG LOADER evaluates a configuration\n * file from source (`loader.ts` → `resolvePlatformConfigLibEntry`).\n *\n * It is the package root plus one side effect: the Zod decorators are initialized before any schema\n * module in the evaluated graph runs, because a config file's own schemas may be authored with them\n * and the loader owns no other moment to do it.\n *\n * ## It re-exports the WHOLE root, and that is the point\n *\n * Until 2026-09-09 this entry exported `./project-config` and `./workspace-scope` and nothing else,\n * and the narrowing was never a boundary — it was a trap that fired twice, the same way both times.\n * The loader substitutes this file for the package specifier in EVERY module of the evaluated\n * graph, and that graph is not only the authored config: `wildo.saas.config.ts` and the backend\n * config import `@wildo-ai/saas-backend-lib`, which the loader also aliases to source, and the\n * engine's own modules import `@wildo-ai/platform-config-lib` expecting the root. A symbol the\n * root exports but this entry did not was not refused — under jiti it arrived as `undefined`, at\n * the first module-eval use:\n *\n * - `MinionPlatformAccessScope`: an app config importing it beside `AppFrontendType`, same\n * package, same statement, got one and `undefined` for the other. The symptom was answered by\n * moving the enum out of `bootstrap/` into `project-config/` (`minion-platform-access.vocabulary.ts`).\n * - `AdminAppManagedMinionsSchema` / `AdminAppManagedWorkersSchema`: the engine's configuration\n * loader began composing its wire schema from these at module load (removing a hand copy that\n * had silently stripped fields twice). Under the loader it threw\n * \"Cannot read properties of undefined (reading 'optional')\" and `wildo local dev` shut the\n * whole stack down at \"Registering application once and materializing every runtime target\".\n *\n * Moving symbols around cures one name at a time and teaches nothing; an entry that carries the\n * root's value surface cannot have this defect. Nothing in the root is unsafe here — the loader\n * runs under Node, and the root's Node-only modules (lockfile IO, credential generation) are\n * exactly what a Node process may load. If a module ever becomes unsuitable for config evaluation,\n * exclude THAT module from the root, explicitly, with its reason — never narrow this file again.\n */\nimport { initZodDecorators } from '@wildo-ai/zod-decorators';\n\ninitZodDecorators();\n\nexport * from './index';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credential-generator.service.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"credential-generator.service.d.ts","sourceRoot":"","sources":["../../../src/credentials/credential-generator.service.ts"],"names":[],"mappings":"AAMA,qBAAa,mBAAmB;IAE9B,MAAM,CAAC,iBAAiB,IAAI;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE;IASrE,MAAM,CAAC,gBAAgB,CAAC,MAAM,GAAE,MAAW,GAAG,MAAM;IAIpD,MAAM,CAAC,cAAc,CAAC,MAAM,GAAE,MAAW,GAAG,MAAM;IAIlD,MAAM,CAAC,oBAAoB,IAAI,MAAM;IAIrC,MAAM,CAAC,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM;CASpE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credential-generator.service.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"credential-generator.service.js","sourceRoot":"","sources":["../../../src/credentials/credential-generator.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAE1D,MAAM,YAAY,GAAG,gEAAgE,CAAC;AACtF,MAAM,cAAc,GAAG,YAAY,GAAG,KAAK,CAAC;AAG5C,MAAM,OAAO,mBAAmB;IAE9B,MAAM,CAAC,iBAAiB;QACtB,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,mBAAmB,CAAC,IAAI,EAAE;YAC1D,UAAU,EAAE,YAAY;YACxB,iBAAiB,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE;YAClD,kBAAkB,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE;SACpD,CAAC,CAAC;QACH,OAAO,EAAE,UAAU,EAAE,UAAU,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC;IACxE,CAAC;IAED,MAAM,CAAC,gBAAgB,CAAC,SAAiB,EAAE;QACzC,OAAO,IAAI,CAAC,mBAAmB,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC1D,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,SAAiB,EAAE;QACvC,OAAO,IAAI,CAAC,mBAAmB,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACxD,CAAC;IAED,MAAM,CAAC,oBAAoB;QACzB,OAAO,IAAI,CAAC,mBAAmB,CAAC,EAAE,EAAE,YAAY,CAAC,CAAC;IACpD,CAAC;IAED,MAAM,CAAC,mBAAmB,CAAC,MAAc,EAAE,OAAe;QACxD,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;QAClC,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAChC,MAAM,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;QAC/C,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CAEF","sourcesContent":["import { generateKeyPairSync, randomBytes } from 'crypto';\n\nconst ALPHANUMERIC = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\nconst PASSWORD_CHARS = ALPHANUMERIC + '_+-';\n\n\nexport class CredentialGenerator {\n\n static generateECKeyPair(): { privateKey: string; publicKey: string } {\n const { publicKey, privateKey } = generateKeyPairSync('ec', {\n namedCurve: 'prime256v1',\n publicKeyEncoding: { type: 'spki', format: 'pem' },\n privateKeyEncoding: { type: 'sec1', format: 'pem' },\n });\n return { privateKey: privateKey.trim(), publicKey: publicKey.trim() };\n }\n\n static generatePassword(length: number = 24): string {\n return this.generateFromCharset(length, PASSWORD_CHARS);\n }\n\n static generateSecret(length: number = 48): string {\n return this.generateFromCharset(length, ALPHANUMERIC);\n }\n\n static generateErlangCookie(): string {\n return this.generateFromCharset(32, ALPHANUMERIC);\n }\n\n static generateFromCharset(length: number, charset: string): string {\n const bytes = randomBytes(length);\n let result = '';\n for (let i = 0; i < length; i++) {\n result += charset[bytes[i] % charset.length];\n }\n return result;\n }\n\n}\n"]}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export * from './bootstrap/platform-runtime-env.contracts';
|
|
|
17
17
|
export * from './bootstrap/runtime-topology.contracts';
|
|
18
18
|
export * from './bootstrap/runtime-principal.contracts';
|
|
19
19
|
export * from './bootstrap/runtime-backing-service-access';
|
|
20
|
+
export * from './bootstrap/platform-store-preconnect';
|
|
20
21
|
export * from './bootstrap/runtime-network-topology';
|
|
21
22
|
export * from './bootstrap/runtime-network-policy';
|
|
22
23
|
export * from './bootstrap/runtime-platform-access';
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4CAA4C,CAAC;AAE3D,cAAc,+CAA+C,CAAC;AAC9D,cAAc,gDAAgD,CAAC;AAC/D,cAAc,mCAAmC,CAAC;AAClD,cAAc,kCAAkC,CAAC;AACjD,cAAc,qCAAqC,CAAC;AACpD,cAAc,uCAAuC,CAAC;AACtD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iCAAiC,CAAC;AAChD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+CAA+C,CAAC;AAC9D,cAAc,gDAAgD,CAAC;AAC/D,cAAc,6DAA6D,CAAC;AAC5E,cAAc,4CAA4C,CAAC;AAC3D,cAAc,wCAAwC,CAAC;AACvD,cAAc,yCAAyC,CAAC;AACxD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,uCAAuC,CAAC;AACtD,cAAc,sCAAsC,CAAC;AACrD,cAAc,oCAAoC,CAAC;AACnD,cAAc,qCAAqC,CAAC;AACpD,cAAc,qDAAqD,CAAC;AACpE,cAAc,2DAA2D,CAAC;AAC1E,cAAc,uDAAuD,CAAC;AACtE,cAAc,2CAA2C,CAAC;AAC1D,cAAc,wBAAwB,CAAC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sCAAsC,CAAC;AACrD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -17,6 +17,7 @@ export * from './bootstrap/platform-runtime-env.contracts.js';
|
|
|
17
17
|
export * from './bootstrap/runtime-topology.contracts.js';
|
|
18
18
|
export * from './bootstrap/runtime-principal.contracts.js';
|
|
19
19
|
export * from './bootstrap/runtime-backing-service-access.js';
|
|
20
|
+
export * from './bootstrap/platform-store-preconnect.js';
|
|
20
21
|
export * from './bootstrap/runtime-network-topology.js';
|
|
21
22
|
export * from './bootstrap/runtime-network-policy.js';
|
|
22
23
|
export * from './bootstrap/runtime-platform-access.js';
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4CAA4C,CAAC;AAE3D,cAAc,+CAA+C,CAAC;AAC9D,cAAc,gDAAgD,CAAC;AAC/D,cAAc,mCAAmC,CAAC;AAClD,cAAc,kCAAkC,CAAC;AACjD,cAAc,qCAAqC,CAAC;AACpD,cAAc,uCAAuC,CAAC;AACtD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iCAAiC,CAAC;AAChD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+CAA+C,CAAC;AAC9D,cAAc,gDAAgD,CAAC;AAC/D,cAAc,6DAA6D,CAAC;AAC5E,cAAc,4CAA4C,CAAC;AAC3D,cAAc,wCAAwC,CAAC;AACvD,cAAc,yCAAyC,CAAC;AACxD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,uCAAuC,CAAC;AACtD,cAAc,sCAAsC,CAAC;AACrD,cAAc,oCAAoC,CAAC;AACnD,cAAc,qCAAqC,CAAC;AACpD,cAAc,qDAAqD,CAAC;AACpE,cAAc,2DAA2D,CAAC;AAC1E,cAAc,uDAAuD,CAAC;AACtE,cAAc,2CAA2C,CAAC;AAC1D,cAAc,wBAAwB,CAAC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sCAAsC,CAAC;AACrD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC","sourcesContent":["export * from './project-config';\nexport * from './workspace-scope';\nexport * from './credentials/credential-generator.service';\n\nexport * from './schemas/platform-application-config.schemas';\nexport * from './schemas/platform-application-secrets.schemas';\nexport * from './schemas/platform-config.schemas';\nexport * from './schemas/framework-info.schemas';\nexport * from './schemas/framework-secrets.schemas';\nexport * from './release/framework-release.constants';\nexport * from './bootstrap/bootstrap.schemas';\nexport * from './bootstrap/bootstrap.contracts';\nexport * from './bootstrap/bootstrap-planner';\nexport * from './bootstrap/application-backend-env.contracts';\nexport * from './bootstrap/wildo-owner-organization.contracts';\nexport * from './bootstrap/application-creation-verification-env.contracts';\nexport * from './bootstrap/platform-runtime-env.contracts';\nexport * from './bootstrap/runtime-topology.contracts';\nexport * from './bootstrap/runtime-principal.contracts';\nexport * from './bootstrap/runtime-backing-service-access';\nexport * from './bootstrap/platform-store-preconnect';\nexport * from './bootstrap/runtime-network-topology';\nexport * from './bootstrap/runtime-network-policy';\nexport * from './bootstrap/runtime-platform-access';\nexport * from './project-config/minion-local-provider-registration';\nexport * from './project-config/shared/minion-resource-access.validation';\nexport * from './project-config/shared/object-storage-session-policy';\nexport * from './lockfile/wildo-saas-lock.shared.schemas';\nexport * from './lockfile/lockfile-io';\nexport * from './lockfile/build-parallelism';\nexport * from './lockfile/materialize-infra-section';\nexport * from './lockfile/canonical-json';\nexport * from './registry';\nexport * from './_unimplemented';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-parallelism.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"build-parallelism.d.ts","sourceRoot":"","sources":["../../../src/lockfile/build-parallelism.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,+BAA+B,EAAE,MAAmD,CAAC;AAElG;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,IAAI,CAAC;AAE3C;;;GAGG;AACH,eAAO,MAAM,yBAAyB,KAAK,CAAC;AAE5C,mEAAmE;AACnE,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEhE;AAED,0GAA0G;AAC1G,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAGhE;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAQ7D;AAED,iGAAiG;AACjG,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAM9E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-parallelism.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"build-parallelism.js","sourceRoot":"","sources":["../../../src/lockfile/build-parallelism.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAW,0CAA0C,CAAC;AAElG;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAE3C;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAE5C,mEAAmE;AACnE,MAAM,UAAU,uBAAuB,CAAC,QAAgB;IACtD,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,+BAA+B,CAAC,CAAC;AAC9D,CAAC;AAED,0GAA0G;AAC1G,MAAM,U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existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport path from 'node:path';\n\n/**\n * How many build-plan coding tasks the creation lane may run AT ONCE in one application (#1528).\n *\n * An OPERATIONAL setting, not product truth: it decides how fast the build spends, never what it\n * builds, so it lives in the application's machine-local state beside the workspace-mutation lock and\n * is safe to delete. The companion reads it at every wave, so it changes without a restart; the CLI\n * writes it (`wildo workbench parallelism <n>`).\n *\n * Absent means {@link DEFAULT_BUILD_PARALLELISM}. `1` is the lane's single-flight behaviour, and remains\n * one command away. Parallel runs share ONE worktree by decision (Paul, 2026-09-24): concurrent agents\n * editing the same tree reconcile fine in practice, so the lane detects and repairs interference instead\n * of preventing it.\n */\nexport const BUILD_PARALLELISM_RELATIVE_PATH: string = '.wildo-saas/state/build-parallelism.json';\n\n/**\n * Five runs at once, by decision (Paul, 2026-09-24): parallel is the lane's normal mode, not an opt-in.\n *\n * Five rather than more because each slot is a live agent spending on its own, and the wave is already\n * measured to cut wall-clock by more than three at four runs (a live wave of four real agents: 28 s\n * against 86 s of combined run time). It sits under the ACP provider's own limit of ten concurrent\n * sessions, so the setting — not the provider — is what decides the width.\n */\nexport const DEFAULT_BUILD_PARALLELISM = 5;\n\n/**\n * A breaker, not a budget. Each slot is a live coding agent spending on its own, so the ceiling stops\n * a typo (`100`) from becoming a hundred concurrent agents; any value up to it is the operator's call.\n */\nexport const MAXIMUM_BUILD_PARALLELISM = 16;\n\n/** Absolute path of an application's build-parallelism setting. */\nexport function getBuildParallelismPath(saasRoot: string): string {\n return path.join(saasRoot, BUILD_PARALLELISM_RELATIVE_PATH);\n}\n\n/** Clamp a requested degree into `[1, MAXIMUM_BUILD_PARALLELISM]`; anything unreadable is the default. */\nexport function normalizeBuildParallelism(value: unknown): number {\n if (typeof value !== 'number' || !Number.isFinite(value)) return DEFAULT_BUILD_PARALLELISM;\n return Math.min(MAXIMUM_BUILD_PARALLELISM, Math.max(1, Math.floor(value)));\n}\n\n/**\n * The application's build parallelism. Never throws: an absent, unreadable or malformed file reads as\n * the default, because a throughput knob that cannot be read must not stop the build.\n */\nexport function readBuildParallelism(saasRoot: string): number {\n const filePath = getBuildParallelismPath(saasRoot);\n if (!existsSync(filePath)) return DEFAULT_BUILD_PARALLELISM;\n try {\n return normalizeBuildParallelism((JSON.parse(readFileSync(filePath, 'utf8')) as { degree?: unknown }).degree);\n } catch {\n return DEFAULT_BUILD_PARALLELISM;\n }\n}\n\n/** Record the application's build parallelism, clamped. Returns the degree actually recorded. */\nexport function writeBuildParallelism(saasRoot: string, degree: number): number {\n const recorded = normalizeBuildParallelism(degree);\n const filePath = getBuildParallelismPath(saasRoot);\n mkdirSync(path.dirname(filePath), { recursive: true });\n writeFileSync(filePath, `${JSON.stringify({ degree: recorded, recordedAt: new Date().toISOString() }, null, 2)}\\n`, 'utf8');\n return recorded;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canonical-json.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"canonical-json.d.ts","sourceRoot":"","sources":["../../../src/lockfile/canonical-json.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAW1D;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAGzD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canonical-json.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"canonical-json.js","sourceRoot":"","sources":["../../../src/lockfile/canonical-json.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;;;;;;;GASG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAc;IAChD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE;QACvC,IAAI,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;YACpD,MAAM,MAAM,GAA4B,EAAE,CAAC;YAC3C,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;gBACtC,MAAM,CAAC,CAAC,CAAC,GAAI,CAA6B,CAAC,CAAC,CAAC,CAAC;YAChD,CAAC;YACD,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,OAAO,CAAC,CAAC;IACX,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,MAAM,SAAS,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;IAC7C,OAAO,UAAU,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;AAC1E,CAAC","sourcesContent":["/**\n * Canonical JSON serialization helpers shared by lockfile writers and\n * lockfile readers (Slice 4.A.1 / H2 of `infra-provider-planner.md`).\n *\n * `JSON.stringify`'s built-in second argument can either filter+order\n * top-level keys (when given an array) or transform values (when given\n * a function). To get a *recursive* canonical serialization — the\n * SAME byte output for two semantically equal inputs regardless of\n * property-insertion order at any nesting level — we need a transform\n * that returns a new object with sorted keys at every layer.\n *\n * The legacy in-line implementation in `materialize-infra-section.ts`\n * sorted only top-level keys. That meant nested objects (e.g.\n * `MongoBackingService.options: {retryWrites, w, authSource}`) drifted\n * across editor saves that re-ordered the nested keys, falsely\n * triggering lockfile-drift CI failures.\n *\n * This helper is the canonical fix.\n */\n\nimport { createHash } from 'node:crypto';\n\n/**\n * `JSON.stringify` with sorted keys at every nesting level. Stable\n * across platforms, editor save formats, and Node versions.\n *\n * Special-cases:\n * - Arrays preserve order (semantic — array order is meaningful).\n * - Objects sort their own keys (lexicographic).\n * - Primitives pass through.\n * - `undefined` values are dropped (matches `JSON.stringify` default).\n */\nexport function stableJsonStringify(value: unknown): string {\n return JSON.stringify(value, (_key, v) => {\n if (v && typeof v === 'object' && !Array.isArray(v)) {\n const sorted: Record<string, unknown> = {};\n for (const k of Object.keys(v).sort()) {\n sorted[k] = (v as Record<string, unknown>)[k];\n }\n return sorted;\n }\n return v;\n });\n}\n\n/**\n * Stable sha256 digest of any JSON-serializable value. Output format:\n * `sha256:<hex>` (matches the digest convention used elsewhere in the\n * lockfile envelope, e.g. provider-runtime artifacts).\n *\n * Two inputs with the same canonical serialization (per\n * `stableJsonStringify`) produce the same digest regardless of\n * property-insertion order at any nesting level.\n */\nexport function stableSha256Digest(value: unknown): string {\n const canonical = stableJsonStringify(value);\n return `sha256:${createHash('sha256').update(canonical).digest('hex')}`;\n}\n"]}
|
|
@@ -142,7 +142,13 @@ export declare function readWildoSaasLock(options: Pick<LockfileMutateOptions, '
|
|
|
142
142
|
* re-validated against the envelope schema (and any caller-supplied
|
|
143
143
|
* `sectionSchemas`) before being atomically written.
|
|
144
144
|
*
|
|
145
|
-
* `generatedAt` is
|
|
145
|
+
* `generatedAt` is refreshed only when the mutation changes the file. When the bytes that would be
|
|
146
|
+
* written — with the previous `generatedAt` — equal the bytes on disk, nothing is written and the
|
|
147
|
+
* envelope is returned as it was. The lockfile is committed, and a timestamp that moved on every no-op
|
|
148
|
+
* sync dirtied the tree with nothing in it: a `wildo registry add` + `remove` round trip left exactly
|
|
149
|
+
* one diff, this field (#1765). The comparison is on BYTES rather than on the parsed sections so a
|
|
150
|
+
* no-op mutation still writes back what normalization changed (schema defaults, a missing trailing
|
|
151
|
+
* newline).
|
|
146
152
|
*
|
|
147
153
|
* The library never inspects `sections.providers.runtimeScopes`,
|
|
148
154
|
* `sections.modules`, or `sections.i18n` — it only enforces the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lockfile-io.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"lockfile-io.d.ts","sourceRoot":"","sources":["../../../src/lockfile/lockfile-io.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAMH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAEL,KAAK,oBAAoB,EAE1B,MAAM,kCAAkC,CAAC;AAE1C;;GAEG;AACH,eAAO,MAAM,6BAA6B,qCAAqC,CAAC;AAEhF;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;CAIuB,CAAC;AAEzD;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3G,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B,CAAC;AAiCF,MAAM,WAAW,qBAAqB;IACpC,kDAAkD;IAClD,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;;;;;OASG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC;IAC9C;;;;OAIG;IACH,WAAW,CAAC,EAAE,wBAAwB,CAAC;IACvC;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,IAAI,CAA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,yDAAyD;IACzD,cAAc,EAAE,MAAM,CAAC,CAAC;CACzB,EACD,OAAO,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,GACpD,OAAO,CAAC,CAAC,CAAC,CAuBZ"}
|
|
@@ -183,6 +183,10 @@ lockOptions) {
|
|
|
183
183
|
await release();
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
|
+
/** The one on-disk form of the envelope: two-space JSON with a trailing newline. */
|
|
187
|
+
function serializeLockfile(envelope) {
|
|
188
|
+
return JSON.stringify(envelope, null, 2) + '\n';
|
|
189
|
+
}
|
|
186
190
|
function emptyEnvelope() {
|
|
187
191
|
return {
|
|
188
192
|
schemaVersion: 2,
|
|
@@ -209,7 +213,13 @@ async function writeFileAtomicAsync(filePath, content) {
|
|
|
209
213
|
* re-validated against the envelope schema (and any caller-supplied
|
|
210
214
|
* `sectionSchemas`) before being atomically written.
|
|
211
215
|
*
|
|
212
|
-
* `generatedAt` is
|
|
216
|
+
* `generatedAt` is refreshed only when the mutation changes the file. When the bytes that would be
|
|
217
|
+
* written — with the previous `generatedAt` — equal the bytes on disk, nothing is written and the
|
|
218
|
+
* envelope is returned as it was. The lockfile is committed, and a timestamp that moved on every no-op
|
|
219
|
+
* sync dirtied the tree with nothing in it: a `wildo registry add` + `remove` round trip left exactly
|
|
220
|
+
* one diff, this field (#1765). The comparison is on BYTES rather than on the parsed sections so a
|
|
221
|
+
* no-op mutation still writes back what normalization changed (schema defaults, a missing trailing
|
|
222
|
+
* newline).
|
|
213
223
|
*
|
|
214
224
|
* The library never inspects `sections.providers.runtimeScopes`,
|
|
215
225
|
* `sections.modules`, or `sections.i18n` — it only enforces the
|
|
@@ -227,14 +237,18 @@ export async function withLockfileMutate(options, mutator) {
|
|
|
227
237
|
});
|
|
228
238
|
const next = structuredClone(before);
|
|
229
239
|
await mutator(next);
|
|
230
|
-
next.generatedAt = new Date().toISOString();
|
|
231
240
|
// Re-validate AFTER mutation; the mutator may have introduced
|
|
232
241
|
// structurally-invalid input.
|
|
233
242
|
SaasLockfileEnvelopeSchema.parse(next);
|
|
234
243
|
if (options.sectionSchemas) {
|
|
235
244
|
validateAndNormalizeSections(next.sections, options.sectionSchemas);
|
|
236
245
|
}
|
|
237
|
-
await
|
|
246
|
+
const onDisk = await fs.readFile(filePath, 'utf8').catch(() => null);
|
|
247
|
+
if (onDisk === serializeLockfile({ ...next, generatedAt: before.generatedAt })) {
|
|
248
|
+
return { ...next, generatedAt: before.generatedAt };
|
|
249
|
+
}
|
|
250
|
+
next.generatedAt = new Date().toISOString();
|
|
251
|
+
await writeFileAtomicAsync(filePath, serializeLockfile(next));
|
|
238
252
|
return next;
|
|
239
253
|
}, lockOptions);
|
|
240
254
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lockfile-io.js","sourceRoot":"","sources":["../../../../src/lockfile/lockfile-io.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACL,0BAA0B,GAG3B,MAAM,kCAAkC,CAAC;AAE1C;;GAEG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,kCAAkC,CAAC;AAEhF;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,QAAgB;IACnD,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,6BAA6B,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,OAAO,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,EAA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C3D,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,qCAAqC,CAAC,CAAC;AACpE,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC7C,OAOC,EACD,OAAqD;IAErD,IAAI,UAAc,CAAC;IACnB,MAAM,kBAAkB,CACtB;QACE,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,cAAc,EAAE;YACd,GAAG,OAAO,CAAC,cAAc;YACzB,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC,aAAa;SAC5C;KACF,EACD,KAAK,EAAE,QAAQ,EAAE,EAAE;QACjB,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAmC,CAAC;QAC9D,MAAM,OAAO,GAAI,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAmB,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;QAC5F,MAAM,MAAM,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;QACxC,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;QAClC,MAAM,IAAI,GAAG,CAAC,GAAG,IAAI,MAAM,CAAM,CAAC;QAClC,sEAAsE;QACtE,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC/C,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC;IAC5C,CAAC,CACF,CAAC;IACF,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["/**\n * Shared `wildo-saas.lock.json` IO primitives.\n *\n * Phase 1 graduates the locking + atomic-write surface validated by\n * the Phase 0.B contention spike (`module-registry-analysis.md`)\n * into `platform-config-lib`. Both the dev companion's\n * `WildoSaasLockCompanionService` and the CLI-side\n * `RegistryLockfileService` consume this module so concurrent\n * writers — across processes (CLI + companion + minions) — never\n * lose updates and never observe a half-written envelope.\n *\n * Exposes two layers:\n *\n * 1. `withLockfileMutate(opts, mutator)` — full-envelope mutate\n * under `proper-lockfile` + `write-file-atomic`. The companion\n * uses this so it can preserve its full-envelope contract and\n * validate its companion-owned i18n schema in the same pass.\n *\n * 2. `withLockfileSectionMutate(opts, mutator)` — section-scoped\n * mutate. The CLI uses this so it can ONLY touch one section\n * (e.g. `sections.modules`) and never accidentally clobber a\n * sibling section.\n *\n * Both layers preserve unknown sections verbatim — every consumer\n * MUST round-trip every `sections.*` key it does not recognize.\n *\n * Hard contract (KD-4 / KD-15 / KD-18):\n * - The library NEVER writes provider runtime artifacts under\n * `.wildo-saas/generated/providers/*.runtime-providers.generated.json` or\n * `src/generated/wildo-provider-runtime.generated.ts`. Those are\n * produced by the provider materialization workflow alone.\n * - `sections.providers.runtimeScopes` is owned end-to-end by the\n * provider workstream; module-registry callers MUST NOT mutate it.\n * This module is unaware of the provider section beyond\n * preserving its bytes.\n */\n\nimport { promises as fs } from 'node:fs';\nimport * as path from 'node:path';\nimport lockfile from 'proper-lockfile';\nimport writeFileAtomic from 'write-file-atomic';\nimport { z } from 'zod';\nimport {\n SaasLockfileEnvelopeSchema,\n type SaasLockfileEnvelope,\n type SaasLockfileKnownSections,\n} from './wildo-saas-lock.shared.schemas';\n\n/**\n * Canonical path of the saas-app lockfile, relative to the saas root.\n */\nexport const WILDO_SAAS_LOCK_RELATIVE_PATH = '.wildo-saas/wildo-saas.lock.json';\n\n/**\n * Build the absolute lockfile path for a given saas root.\n */\nexport function getWildoSaasLockPath(saasRoot: string): string {\n return path.resolve(saasRoot, WILDO_SAAS_LOCK_RELATIVE_PATH);\n}\n\n/**\n * Default `proper-lockfile` options. The 5s `stale` window matches\n * the Phase 0.B spike (`module-registry-analysis.md` Phase 0.B\n * Findings): typical lock-hold time is < 50ms; 5s is generous enough\n * to absorb a CI pause without compromising legitimate locks. Tests\n * 4a-4d all passed under these settings.\n *\n * `realpath: false` is required when the saas root is symlinked\n * (common with pnpm `dependenciesMeta.injected: true` workspaces).\n */\nexport const DEFAULT_LOCK_OPTIONS = {\n retries: { retries: 200, minTimeout: 5, maxTimeout: 50, factor: 1.2 },\n stale: 5000,\n realpath: false,\n} as const satisfies Parameters<typeof lockfile.lock>[1];\n\n/**\n * The result of merging caller options over {@link DEFAULT_LOCK_OPTIONS}.\n *\n * Its leaves are WIDENED (`number` / `boolean`) and that is the point: the\n * defaults are `as const`, so `typeof DEFAULT_LOCK_OPTIONS` describes those exact\n * literals — `stale: 5000`, `realpath: false`. A merge that honours a caller\n * override cannot satisfy it, because an overridden `stale` is not `5000`.\n *\n * Annotating the merge as `typeof DEFAULT_LOCK_OPTIONS` claimed the result was\n * always the defaults, which is true only when nothing was overridden — i.e. in\n * the one case the function exists to avoid.\n */\nexport type ResolvedLockOptions = {\n /**\n * Either a retry POLICY or a bare attempt count — `proper-lockfile` accepts\n * both, and the merge passes a bare number straight through\n * (`overrideRetries ?? baseRetries`). Omitting `number` made the merge unable to\n * describe its own fallback branch.\n */\n readonly retries: number | { retries?: number; minTimeout?: number; maxTimeout?: number; factor?: number };\n readonly stale: number;\n readonly realpath: boolean;\n};\n\n/**\n * Deep-merge caller-supplied lock options on top of `DEFAULT_LOCK_OPTIONS`.\n *\n * Phase 1 review (M-2.1): a shallow merge replaced the entire\n * `retries` object whenever a caller passed a partial — so\n * `lockOptions: { retries: { retries: 5 } }` silently lost the\n * `minTimeout`/`maxTimeout`/`factor` defaults that Phase 0.B\n * validated. The deep merge keeps every default intact unless\n * the caller explicitly overrides each leaf.\n */\nfunction mergeLockOptions(\n // `DedicatedFileLockOptions`, NOT `Partial<typeof DEFAULT_LOCK_OPTIONS>`: that constant is\n // `as const`, so every leaf is a LITERAL type and `Partial` only reaches the top level — which\n // made the very call shape this merge exists to support (`{ retries: { retries: 5 } }`) a type\n // error, because `5` is not `200`. It also removes the cast the dedicated-lock caller needed.\n override?: DedicatedFileLockOptions,\n): ResolvedLockOptions {\n if (!override) return DEFAULT_LOCK_OPTIONS;\n const baseRetries = DEFAULT_LOCK_OPTIONS.retries;\n const overrideRetries = override.retries;\n const mergedRetries =\n typeof overrideRetries === 'object' && overrideRetries !== null\n ? { ...baseRetries, ...overrideRetries }\n : overrideRetries ?? baseRetries;\n return {\n ...DEFAULT_LOCK_OPTIONS,\n ...override,\n retries: mergedRetries,\n };\n}\n\nexport interface LockfileMutateOptions {\n /** Absolute path to the saas application root. */\n saasRoot: string;\n /**\n * Optional Zod schemas to validate sibling sections at parse time.\n * Companion-owned sections (e.g. `i18n`) are validated by passing\n * them here. CLI callers can pass\n * `DEFAULT_REGISTRY_SECTION_SCHEMAS` to validate `modules`.\n *\n * Sections not listed here are still PRESERVED on round-trip via\n * the envelope's `.catchall(z.unknown())` — they are simply not\n * type-narrowed.\n */\n sectionSchemas?: Record<string, z.ZodTypeAny>;\n /**\n * Override `proper-lockfile` options. Phase 0.B's measurements\n * suggest the defaults are fine for both CLI and companion\n * call patterns; this hook exists for tests + tuning.\n */\n lockOptions?: DedicatedFileLockOptions;\n /**\n * If true (default), the lockfile is created on first read with an\n * empty `sections` map. Set to false to fail with ENOENT.\n */\n createIfMissing?: boolean;\n}\n\n/**\n * Read the lockfile envelope, applying schema validation.\n *\n * - Returns a fresh empty envelope if the file does not exist\n * (and `createIfMissing` is not explicitly false).\n * - Validates the canonical envelope shape (schemaVersion, generatedAt,\n * sections) against `SaasLockfileEnvelopeSchema`.\n * - Applies caller-supplied `sectionSchemas` after the envelope\n * shape passes — failures throw a `ZodError` so the caller knows\n * exactly which section + field rejected.\n *\n * Does NOT acquire a lock; reads are unsynchronized. Callers that\n * need read-after-write coherence must read INSIDE `withLockfileMutate`.\n */\nexport async function readWildoSaasLock(\n options: Pick<LockfileMutateOptions, 'saasRoot' | 'sectionSchemas' | 'createIfMissing'>,\n): Promise<SaasLockfileEnvelope> {\n const filePath = getWildoSaasLockPath(options.saasRoot);\n let raw: string;\n try {\n raw = await fs.readFile(filePath, 'utf8');\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT' && options.createIfMissing !== false) {\n return {\n schemaVersion: 2,\n generatedAt: new Date().toISOString(),\n sections: {},\n };\n }\n throw err;\n }\n const json = JSON.parse(raw) as unknown;\n const envelope = SaasLockfileEnvelopeSchema.parse(json);\n if (options.sectionSchemas) {\n validateAndNormalizeSections(envelope.sections, options.sectionSchemas);\n }\n return envelope;\n}\n\n/**\n * Validate every present `sections.<key>` against its caller-supplied\n * Zod schema AND write the parsed (default-expanded) value back so\n * defaults declared in those schemas actually persist on disk.\n *\n * Phase 1 review (H-2.1 / M-1.2): the prior implementation called\n * `.parse(value)` and discarded the result, which meant\n * `.default(...)` clauses in section schemas were only ever applied\n * during validation — never written. Schemas with shallow defaults\n * (e.g. `installed: z.record(...).default({})`) tolerated the bug\n * because mutators always set `installed` directly, but a future\n * schema with deep defaults would silently lose them.\n */\nfunction validateAndNormalizeSections(\n sections: SaasLockfileKnownSections,\n sectionSchemas: Record<string, z.ZodTypeAny>,\n): void {\n const mutable = sections as Record<string, unknown>;\n for (const [key, schema] of Object.entries(sectionSchemas)) {\n const value = mutable[key];\n if (value === undefined) continue;\n mutable[key] = schema.parse(value);\n }\n}\n\n/**\n * Acquire the OS-level lockfile lock, run `fn`, then release it.\n *\n * Wrapper around `proper-lockfile` that:\n * - Creates the parent dir + an empty file if missing (proper-lockfile\n * refuses to lock a non-existent file).\n * - Forwards `realpath: false` so symlinked workspaces lock correctly.\n * - Always releases the lock, even on error.\n */\nasync function withLock<T>(\n filePath: string,\n fn: () => Promise<T>,\n // A MERGED value, not the defaults — see `ResolvedLockOptions`. Typing this as\n // `typeof DEFAULT_LOCK_OPTIONS` demanded the literal `200`/`5000`/`false`, so any\n // caller-overridden option was a type error at the point of USE rather than at\n // the point of override, which is why it read as a failure in the merge.\n lockOptions: ResolvedLockOptions,\n): Promise<T> {\n await fs.mkdir(path.dirname(filePath), { recursive: true });\n // Ensure the file exists; `proper-lockfile.lock` refuses ENOENT.\n try {\n await fs.access(filePath);\n } catch {\n await writeFileAtomicAsync(filePath, JSON.stringify(emptyEnvelope(), null, 2));\n }\n const release = await lockfile.lock(filePath, lockOptions);\n try {\n return await fn();\n } finally {\n await release();\n }\n}\n\nfunction emptyEnvelope(): SaasLockfileEnvelope {\n return {\n schemaVersion: 2,\n generatedAt: new Date().toISOString(),\n sections: {},\n };\n}\n\nasync function writeFileAtomicAsync(filePath: string, content: string): Promise<void> {\n await new Promise<void>((resolve, reject) => {\n writeFileAtomic(filePath, content, (err: Error | undefined) => {\n if (err) reject(err);\n else resolve();\n });\n });\n}\n\n/**\n * Read-modify-write a lockfile under an OS-level lock.\n *\n * The mutator receives a deep-cloned, schema-validated envelope —\n * any in-place mutation is safe and won't bleed back into the\n * pre-write copy. After the mutator returns, the result is\n * re-validated against the envelope schema (and any caller-supplied\n * `sectionSchemas`) before being atomically written.\n *\n * `generatedAt` is always refreshed after a successful mutation.\n *\n * The library never inspects `sections.providers.runtimeScopes`,\n * `sections.modules`, or `sections.i18n` — it only enforces the\n * envelope shape. Concrete section semantics live in their owning\n * subsystems.\n */\nexport async function withLockfileMutate(\n options: LockfileMutateOptions,\n mutator: (envelope: SaasLockfileEnvelope) => void | Promise<void>,\n): Promise<SaasLockfileEnvelope> {\n const filePath = getWildoSaasLockPath(options.saasRoot);\n const lockOptions = mergeLockOptions(options.lockOptions);\n return withLock(filePath, async () => {\n const before = await readWildoSaasLock({\n saasRoot: options.saasRoot,\n sectionSchemas: options.sectionSchemas,\n createIfMissing: true,\n });\n const next: SaasLockfileEnvelope = structuredClone(before);\n await mutator(next);\n next.generatedAt = new Date().toISOString();\n // Re-validate AFTER mutation; the mutator may have introduced\n // structurally-invalid input.\n SaasLockfileEnvelopeSchema.parse(next);\n if (options.sectionSchemas) {\n validateAndNormalizeSections(next.sections, options.sectionSchemas);\n }\n await writeFileAtomicAsync(filePath, JSON.stringify(next, null, 2) + '\\n');\n return next;\n }, lockOptions);\n}\n\n/**\n * Hold an OS-level `proper-lockfile` lock on an ARBITRARY dedicated lock\n * target while `fn` runs — the path-parameterized sibling of\n * `withLockfileMutate` for callers that need cross-process mutual\n * exclusion WITHOUT the `wildo-saas.lock.json` envelope semantics.\n *\n * Why this exists (meta-workflows P-20, 2026-07-03): the companion's\n * coding-agent dispatch lane serializes workspace mutations on a\n * dedicated target (`<saasRoot>/.wildo-saas/state/workspace-mutation.lock`)\n * held for the WHOLE agent run (minutes). Routing that through\n * `withLockfileMutate` would hold the shared saas lockfile hostage —\n * starving i18n/registry writers — and the envelope re-validation is\n * meaningless for a pure mutex. The primitive lives HERE (not\n * companion-local) so the CLI can adopt the SAME lock target with the\n * SAME semantics when its worktree-mutating commands learn to respect it.\n *\n * Semantics:\n * - Parent directory + an empty placeholder file are created if missing\n * (`proper-lockfile` refuses ENOENT targets). The file content is never\n * read or written by this helper — it is a pure lock anchor.\n * - `proper-lockfile` auto-refreshes the lock mtime while the holder is\n * alive, so long-running holds survive the `stale` window; a crashed\n * holder's lock goes stale and is reclaimed by the next acquirer.\n * - Lock options merge over {@link DEFAULT_LOCK_OPTIONS}. Callers that\n * want fail-fast contention (HTTP 409 instead of queueing) pass\n * `{ retries: { retries: 0 } }`.\n * - The lock is always released (or at least attempted) on completion,\n * including the error path.\n *\n * Contention surfaces as the `proper-lockfile` `ELOCKED` error\n * (`error.code === 'ELOCKED'`) — callers map it to their own conflict\n * vocabulary.\n */\nexport interface DedicatedFileLockOptions {\n /** `proper-lockfile` retry policy — `{ retries: { retries: 0 } }` = fail-fast contention. */\n retries?: { retries?: number; minTimeout?: number; maxTimeout?: number; factor?: number };\n /** Stale window in ms (lock mtime auto-refreshes while the holder lives). */\n stale?: number;\n /** Keep `false` for symlinked (pnpm-injected) workspaces. */\n realpath?: boolean;\n}\n\nexport async function withDedicatedFileLock<T>(\n lockTargetPath: string,\n fn: () => Promise<T>,\n lockOptions?: DedicatedFileLockOptions,\n): Promise<T> {\n await fs.mkdir(path.dirname(lockTargetPath), { recursive: true });\n try {\n await fs.access(lockTargetPath);\n } catch {\n await writeFileAtomicAsync(lockTargetPath, '');\n }\n const release = await lockfile.lock(\n lockTargetPath,\n mergeLockOptions(lockOptions),\n );\n try {\n return await fn();\n } finally {\n await release();\n }\n}\n\n/**\n * Canonical workspace-mutation lock target, app-root-relative. ONE constant\n * shared by every process that mutates the application worktree in a way\n * that must serialize against coding-agent dispatch runs (meta-workflows\n * P-20): the companion's dispatch lane holds it for the whole agent run;\n * CLI worktree-writers (e.g. `wildo config sync`) acquire it fail-fast\n * around their write phase. Deliberately NOT taken by human/parallel-session\n * edits (P-19b — per-file attribution compensates, never exclusion).\n * Keep companion and CLI on THIS constant — a hand-copied path is drift.\n */\nexport const WORKSPACE_MUTATION_LOCK_RELATIVE_PATH: string =\n '.wildo-saas/state/workspace-mutation.lock';\n\n/** Absolute workspace-mutation lock target for an application root. */\nexport function getWorkspaceMutationLockPath(saasRoot: string): string {\n return path.join(saasRoot, WORKSPACE_MUTATION_LOCK_RELATIVE_PATH);\n}\n\n/**\n * Section-scoped mutate. The mutator only sees one section's payload\n * (`sections.<sectionKey>`) and CANNOT reach sibling sections —\n * preventing accidental clobbers. Returns the mutated section.\n *\n * Use this from CLI callers (`RegistryLockfileService`) so cross-\n * section bugs are impossible by construction. Companion callers\n * that legitimately need full-envelope access keep using\n * `withLockfileMutate` directly.\n */\nexport async function withLockfileSectionMutate<S>(\n options: LockfileMutateOptions & {\n /** Section key under `sections` (e.g. `'modules'`, `'i18n'`). */\n sectionKey: string;\n /** Zod schema validating the section payload. Required. */\n sectionSchema: z.ZodType<S>;\n /** Initial value when the section does not yet exist. */\n initialSection: () => S;\n },\n mutator: (section: S) => S | void | Promise<S | void>,\n): Promise<S> {\n let mutatedOut!: S;\n await withLockfileMutate(\n {\n saasRoot: options.saasRoot,\n lockOptions: options.lockOptions,\n sectionSchemas: {\n ...options.sectionSchemas,\n [options.sectionKey]: options.sectionSchema,\n },\n },\n async (envelope) => {\n const sections = envelope.sections as Record<string, unknown>;\n const current = (sections[options.sectionKey] as S | undefined) ?? options.initialSection();\n const cloned = structuredClone(current);\n const ret = await mutator(cloned);\n const next = (ret ?? cloned) as S;\n // Per-section validation (also covers initial-default re-validation).\n mutatedOut = options.sectionSchema.parse(next);\n sections[options.sectionKey] = mutatedOut;\n },\n );\n return mutatedOut;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"lockfile-io.js","sourceRoot":"","sources":["../../../src/lockfile/lockfile-io.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACL,0BAA0B,GAG3B,MAAM,kCAAkC,CAAC;AAE1C;;GAEG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,kCAAkC,CAAC;AAEhF;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,QAAgB;IACnD,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,6BAA6B,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,OAAO,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE;IACrE,KAAK,EAAE,IAAI;IACX,QAAQ,EAAE,KAAK;CACuC,CAAC;AA0BzD;;;;;;;;;GASG;AACH,SAAS,gBAAgB;AACvB,2FAA2F;AAC3F,+FAA+F;AAC/F,+FAA+F;AAC/F,8FAA8F;AAC9F,QAAmC;IAEnC,IAAI,CAAC,QAAQ;QAAE,OAAO,oBAAoB,CAAC;IAC3C,MAAM,WAAW,GAAG,oBAAoB,CAAC,OAAO,CAAC;IACjD,MAAM,eAAe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MAAM,CAAC,MAAM,qCAAqC,GAChD,2CAA2C,CAAC;AAE9C,uEAAuE;AACvE,MAAM,UAAU,4BAA4B,CAAC,QAAgB;IAC3D,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,qCAAqC,CAAC,CAAC;AACpE,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC7C,OAOC,EACD,OAAqD;IAErD,IAAI,UAAc,CAAC;IACnB,MAAM,kBAAkB,CACtB;QACE,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,cAAc,EAAE;YACd,GAAG,OAAO,CAAC,cAAc;YACzB,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC,aAAa;SAC5C;KACF,EACD,KAAK,EAAE,QAAQ,EAAE,EAAE;QACjB,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAmC,CAAC;QAC9D,MAAM,OAAO,GAAI,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAmB,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;QAC5F,MAAM,MAAM,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;QACxC,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;QAClC,MAAM,IAAI,GAAG,CAAC,GAAG,IAAI,MAAM,CAAM,CAAC;QAClC,sEAAsE;QACtE,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC/C,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC;IAC5C,CAAC,CACF,CAAC;IACF,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["/**\n * Shared `wildo-saas.lock.json` IO primitives.\n *\n * Phase 1 graduates the locking + atomic-write surface validated by\n * the Phase 0.B contention spike (`module-registry-analysis.md`)\n * into `platform-config-lib`. Both the dev companion's\n * `WildoSaasLockCompanionService` and the CLI-side\n * `RegistryLockfileService` consume this module so concurrent\n * writers — across processes (CLI + companion + minions) — never\n * lose updates and never observe a half-written envelope.\n *\n * Exposes two layers:\n *\n * 1. `withLockfileMutate(opts, mutator)` — full-envelope mutate\n * under `proper-lockfile` + `write-file-atomic`. The companion\n * uses this so it can preserve its full-envelope contract and\n * validate its companion-owned i18n schema in the same pass.\n *\n * 2. `withLockfileSectionMutate(opts, mutator)` — section-scoped\n * mutate. The CLI uses this so it can ONLY touch one section\n * (e.g. `sections.modules`) and never accidentally clobber a\n * sibling section.\n *\n * Both layers preserve unknown sections verbatim — every consumer\n * MUST round-trip every `sections.*` key it does not recognize.\n *\n * Hard contract (KD-4 / KD-15 / KD-18):\n * - The library NEVER writes provider runtime artifacts under\n * `.wildo-saas/generated/providers/*.runtime-providers.generated.json` or\n * `src/generated/wildo-provider-runtime.generated.ts`. Those are\n * produced by the provider materialization workflow alone.\n * - `sections.providers.runtimeScopes` is owned end-to-end by the\n * provider workstream; module-registry callers MUST NOT mutate it.\n * This module is unaware of the provider section beyond\n * preserving its bytes.\n */\n\nimport { promises as fs } from 'node:fs';\nimport * as path from 'node:path';\nimport lockfile from 'proper-lockfile';\nimport writeFileAtomic from 'write-file-atomic';\nimport { z } from 'zod';\nimport {\n SaasLockfileEnvelopeSchema,\n type SaasLockfileEnvelope,\n type SaasLockfileKnownSections,\n} from './wildo-saas-lock.shared.schemas';\n\n/**\n * Canonical path of the saas-app lockfile, relative to the saas root.\n */\nexport const WILDO_SAAS_LOCK_RELATIVE_PATH = '.wildo-saas/wildo-saas.lock.json';\n\n/**\n * Build the absolute lockfile path for a given saas root.\n */\nexport function getWildoSaasLockPath(saasRoot: string): string {\n return path.resolve(saasRoot, WILDO_SAAS_LOCK_RELATIVE_PATH);\n}\n\n/**\n * Default `proper-lockfile` options. The 5s `stale` window matches\n * the Phase 0.B spike (`module-registry-analysis.md` Phase 0.B\n * Findings): typical lock-hold time is < 50ms; 5s is generous enough\n * to absorb a CI pause without compromising legitimate locks. Tests\n * 4a-4d all passed under these settings.\n *\n * `realpath: false` is required when the saas root is symlinked\n * (common with pnpm `dependenciesMeta.injected: true` workspaces).\n */\nexport const DEFAULT_LOCK_OPTIONS = {\n retries: { retries: 200, minTimeout: 5, maxTimeout: 50, factor: 1.2 },\n stale: 5000,\n realpath: false,\n} as const satisfies Parameters<typeof lockfile.lock>[1];\n\n/**\n * The result of merging caller options over {@link DEFAULT_LOCK_OPTIONS}.\n *\n * Its leaves are WIDENED (`number` / `boolean`) and that is the point: the\n * defaults are `as const`, so `typeof DEFAULT_LOCK_OPTIONS` describes those exact\n * literals — `stale: 5000`, `realpath: false`. A merge that honours a caller\n * override cannot satisfy it, because an overridden `stale` is not `5000`.\n *\n * Annotating the merge as `typeof DEFAULT_LOCK_OPTIONS` claimed the result was\n * always the defaults, which is true only when nothing was overridden — i.e. in\n * the one case the function exists to avoid.\n */\nexport type ResolvedLockOptions = {\n /**\n * Either a retry POLICY or a bare attempt count — `proper-lockfile` accepts\n * both, and the merge passes a bare number straight through\n * (`overrideRetries ?? baseRetries`). Omitting `number` made the merge unable to\n * describe its own fallback branch.\n */\n readonly retries: number | { retries?: number; minTimeout?: number; maxTimeout?: number; factor?: number };\n readonly stale: number;\n readonly realpath: boolean;\n};\n\n/**\n * Deep-merge caller-supplied lock options on top of `DEFAULT_LOCK_OPTIONS`.\n *\n * Phase 1 review (M-2.1): a shallow merge replaced the entire\n * `retries` object whenever a caller passed a partial — so\n * `lockOptions: { retries: { retries: 5 } }` silently lost the\n * `minTimeout`/`maxTimeout`/`factor` defaults that Phase 0.B\n * validated. The deep merge keeps every default intact unless\n * the caller explicitly overrides each leaf.\n */\nfunction mergeLockOptions(\n // `DedicatedFileLockOptions`, NOT `Partial<typeof DEFAULT_LOCK_OPTIONS>`: that constant is\n // `as const`, so every leaf is a LITERAL type and `Partial` only reaches the top level — which\n // made the very call shape this merge exists to support (`{ retries: { retries: 5 } }`) a type\n // error, because `5` is not `200`. It also removes the cast the dedicated-lock caller needed.\n override?: DedicatedFileLockOptions,\n): ResolvedLockOptions {\n if (!override) return DEFAULT_LOCK_OPTIONS;\n const baseRetries = DEFAULT_LOCK_OPTIONS.retries;\n const overrideRetries = override.retries;\n const mergedRetries =\n typeof overrideRetries === 'object' && overrideRetries !== null\n ? { ...baseRetries, ...overrideRetries }\n : overrideRetries ?? baseRetries;\n return {\n ...DEFAULT_LOCK_OPTIONS,\n ...override,\n retries: mergedRetries,\n };\n}\n\nexport interface LockfileMutateOptions {\n /** Absolute path to the saas application root. */\n saasRoot: string;\n /**\n * Optional Zod schemas to validate sibling sections at parse time.\n * Companion-owned sections (e.g. `i18n`) are validated by passing\n * them here. CLI callers can pass\n * `DEFAULT_REGISTRY_SECTION_SCHEMAS` to validate `modules`.\n *\n * Sections not listed here are still PRESERVED on round-trip via\n * the envelope's `.catchall(z.unknown())` — they are simply not\n * type-narrowed.\n */\n sectionSchemas?: Record<string, z.ZodTypeAny>;\n /**\n * Override `proper-lockfile` options. Phase 0.B's measurements\n * suggest the defaults are fine for both CLI and companion\n * call patterns; this hook exists for tests + tuning.\n */\n lockOptions?: DedicatedFileLockOptions;\n /**\n * If true (default), the lockfile is created on first read with an\n * empty `sections` map. Set to false to fail with ENOENT.\n */\n createIfMissing?: boolean;\n}\n\n/**\n * Read the lockfile envelope, applying schema validation.\n *\n * - Returns a fresh empty envelope if the file does not exist\n * (and `createIfMissing` is not explicitly false).\n * - Validates the canonical envelope shape (schemaVersion, generatedAt,\n * sections) against `SaasLockfileEnvelopeSchema`.\n * - Applies caller-supplied `sectionSchemas` after the envelope\n * shape passes — failures throw a `ZodError` so the caller knows\n * exactly which section + field rejected.\n *\n * Does NOT acquire a lock; reads are unsynchronized. Callers that\n * need read-after-write coherence must read INSIDE `withLockfileMutate`.\n */\nexport async function readWildoSaasLock(\n options: Pick<LockfileMutateOptions, 'saasRoot' | 'sectionSchemas' | 'createIfMissing'>,\n): Promise<SaasLockfileEnvelope> {\n const filePath = getWildoSaasLockPath(options.saasRoot);\n let raw: string;\n try {\n raw = await fs.readFile(filePath, 'utf8');\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT' && options.createIfMissing !== false) {\n return {\n schemaVersion: 2,\n generatedAt: new Date().toISOString(),\n sections: {},\n };\n }\n throw err;\n }\n const json = JSON.parse(raw) as unknown;\n const envelope = SaasLockfileEnvelopeSchema.parse(json);\n if (options.sectionSchemas) {\n validateAndNormalizeSections(envelope.sections, options.sectionSchemas);\n }\n return envelope;\n}\n\n/**\n * Validate every present `sections.<key>` against its caller-supplied\n * Zod schema AND write the parsed (default-expanded) value back so\n * defaults declared in those schemas actually persist on disk.\n *\n * Phase 1 review (H-2.1 / M-1.2): the prior implementation called\n * `.parse(value)` and discarded the result, which meant\n * `.default(...)` clauses in section schemas were only ever applied\n * during validation — never written. Schemas with shallow defaults\n * (e.g. `installed: z.record(...).default({})`) tolerated the bug\n * because mutators always set `installed` directly, but a future\n * schema with deep defaults would silently lose them.\n */\nfunction validateAndNormalizeSections(\n sections: SaasLockfileKnownSections,\n sectionSchemas: Record<string, z.ZodTypeAny>,\n): void {\n const mutable = sections as Record<string, unknown>;\n for (const [key, schema] of Object.entries(sectionSchemas)) {\n const value = mutable[key];\n if (value === undefined) continue;\n mutable[key] = schema.parse(value);\n }\n}\n\n/**\n * Acquire the OS-level lockfile lock, run `fn`, then release it.\n *\n * Wrapper around `proper-lockfile` that:\n * - Creates the parent dir + an empty file if missing (proper-lockfile\n * refuses to lock a non-existent file).\n * - Forwards `realpath: false` so symlinked workspaces lock correctly.\n * - Always releases the lock, even on error.\n */\nasync function withLock<T>(\n filePath: string,\n fn: () => Promise<T>,\n // A MERGED value, not the defaults — see `ResolvedLockOptions`. Typing this as\n // `typeof DEFAULT_LOCK_OPTIONS` demanded the literal `200`/`5000`/`false`, so any\n // caller-overridden option was a type error at the point of USE rather than at\n // the point of override, which is why it read as a failure in the merge.\n lockOptions: ResolvedLockOptions,\n): Promise<T> {\n await fs.mkdir(path.dirname(filePath), { recursive: true });\n // Ensure the file exists; `proper-lockfile.lock` refuses ENOENT.\n try {\n await fs.access(filePath);\n } catch {\n await writeFileAtomicAsync(filePath, JSON.stringify(emptyEnvelope(), null, 2));\n }\n const release = await lockfile.lock(filePath, lockOptions);\n try {\n return await fn();\n } finally {\n await release();\n }\n}\n\n/** The one on-disk form of the envelope: two-space JSON with a trailing newline. */\nfunction serializeLockfile(envelope: SaasLockfileEnvelope): string {\n return JSON.stringify(envelope, null, 2) + '\\n';\n}\n\nfunction emptyEnvelope(): SaasLockfileEnvelope {\n return {\n schemaVersion: 2,\n generatedAt: new Date().toISOString(),\n sections: {},\n };\n}\n\nasync function writeFileAtomicAsync(filePath: string, content: string): Promise<void> {\n await new Promise<void>((resolve, reject) => {\n writeFileAtomic(filePath, content, (err: Error | undefined) => {\n if (err) reject(err);\n else resolve();\n });\n });\n}\n\n/**\n * Read-modify-write a lockfile under an OS-level lock.\n *\n * The mutator receives a deep-cloned, schema-validated envelope —\n * any in-place mutation is safe and won't bleed back into the\n * pre-write copy. After the mutator returns, the result is\n * re-validated against the envelope schema (and any caller-supplied\n * `sectionSchemas`) before being atomically written.\n *\n * `generatedAt` is refreshed only when the mutation changes the file. When the bytes that would be\n * written — with the previous `generatedAt` — equal the bytes on disk, nothing is written and the\n * envelope is returned as it was. The lockfile is committed, and a timestamp that moved on every no-op\n * sync dirtied the tree with nothing in it: a `wildo registry add` + `remove` round trip left exactly\n * one diff, this field (#1765). The comparison is on BYTES rather than on the parsed sections so a\n * no-op mutation still writes back what normalization changed (schema defaults, a missing trailing\n * newline).\n *\n * The library never inspects `sections.providers.runtimeScopes`,\n * `sections.modules`, or `sections.i18n` — it only enforces the\n * envelope shape. Concrete section semantics live in their owning\n * subsystems.\n */\nexport async function withLockfileMutate(\n options: LockfileMutateOptions,\n mutator: (envelope: SaasLockfileEnvelope) => void | Promise<void>,\n): Promise<SaasLockfileEnvelope> {\n const filePath = getWildoSaasLockPath(options.saasRoot);\n const lockOptions = mergeLockOptions(options.lockOptions);\n return withLock(filePath, async () => {\n const before = await readWildoSaasLock({\n saasRoot: options.saasRoot,\n sectionSchemas: options.sectionSchemas,\n createIfMissing: true,\n });\n const next: SaasLockfileEnvelope = structuredClone(before);\n await mutator(next);\n // Re-validate AFTER mutation; the mutator may have introduced\n // structurally-invalid input.\n SaasLockfileEnvelopeSchema.parse(next);\n if (options.sectionSchemas) {\n validateAndNormalizeSections(next.sections, options.sectionSchemas);\n }\n const onDisk = await fs.readFile(filePath, 'utf8').catch(() => null);\n if (onDisk === serializeLockfile({ ...next, generatedAt: before.generatedAt })) {\n return { ...next, generatedAt: before.generatedAt };\n }\n next.generatedAt = new Date().toISOString();\n await writeFileAtomicAsync(filePath, serializeLockfile(next));\n return next;\n }, lockOptions);\n}\n\n/**\n * Hold an OS-level `proper-lockfile` lock on an ARBITRARY dedicated lock\n * target while `fn` runs — the path-parameterized sibling of\n * `withLockfileMutate` for callers that need cross-process mutual\n * exclusion WITHOUT the `wildo-saas.lock.json` envelope semantics.\n *\n * Why this exists (meta-workflows P-20, 2026-07-03): the companion's\n * coding-agent dispatch lane serializes workspace mutations on a\n * dedicated target (`<saasRoot>/.wildo-saas/state/workspace-mutation.lock`)\n * held for the WHOLE agent run (minutes). Routing that through\n * `withLockfileMutate` would hold the shared saas lockfile hostage —\n * starving i18n/registry writers — and the envelope re-validation is\n * meaningless for a pure mutex. The primitive lives HERE (not\n * companion-local) so the CLI can adopt the SAME lock target with the\n * SAME semantics when its worktree-mutating commands learn to respect it.\n *\n * Semantics:\n * - Parent directory + an empty placeholder file are created if missing\n * (`proper-lockfile` refuses ENOENT targets). The file content is never\n * read or written by this helper — it is a pure lock anchor.\n * - `proper-lockfile` auto-refreshes the lock mtime while the holder is\n * alive, so long-running holds survive the `stale` window; a crashed\n * holder's lock goes stale and is reclaimed by the next acquirer.\n * - Lock options merge over {@link DEFAULT_LOCK_OPTIONS}. Callers that\n * want fail-fast contention (HTTP 409 instead of queueing) pass\n * `{ retries: { retries: 0 } }`.\n * - The lock is always released (or at least attempted) on completion,\n * including the error path.\n *\n * Contention surfaces as the `proper-lockfile` `ELOCKED` error\n * (`error.code === 'ELOCKED'`) — callers map it to their own conflict\n * vocabulary.\n */\nexport interface DedicatedFileLockOptions {\n /** `proper-lockfile` retry policy — `{ retries: { retries: 0 } }` = fail-fast contention. */\n retries?: { retries?: number; minTimeout?: number; maxTimeout?: number; factor?: number };\n /** Stale window in ms (lock mtime auto-refreshes while the holder lives). */\n stale?: number;\n /** Keep `false` for symlinked (pnpm-injected) workspaces. */\n realpath?: boolean;\n}\n\nexport async function withDedicatedFileLock<T>(\n lockTargetPath: string,\n fn: () => Promise<T>,\n lockOptions?: DedicatedFileLockOptions,\n): Promise<T> {\n await fs.mkdir(path.dirname(lockTargetPath), { recursive: true });\n try {\n await fs.access(lockTargetPath);\n } catch {\n await writeFileAtomicAsync(lockTargetPath, '');\n }\n const release = await lockfile.lock(\n lockTargetPath,\n mergeLockOptions(lockOptions),\n );\n try {\n return await fn();\n } finally {\n await release();\n }\n}\n\n/**\n * Canonical workspace-mutation lock target, app-root-relative. ONE constant\n * shared by every process that mutates the application worktree in a way\n * that must serialize against coding-agent dispatch runs (meta-workflows\n * P-20): the companion's dispatch lane holds it for the whole agent run;\n * CLI worktree-writers (e.g. `wildo config sync`) acquire it fail-fast\n * around their write phase. Deliberately NOT taken by human/parallel-session\n * edits (P-19b — per-file attribution compensates, never exclusion).\n * Keep companion and CLI on THIS constant — a hand-copied path is drift.\n */\nexport const WORKSPACE_MUTATION_LOCK_RELATIVE_PATH: string =\n '.wildo-saas/state/workspace-mutation.lock';\n\n/** Absolute workspace-mutation lock target for an application root. */\nexport function getWorkspaceMutationLockPath(saasRoot: string): string {\n return path.join(saasRoot, WORKSPACE_MUTATION_LOCK_RELATIVE_PATH);\n}\n\n/**\n * Section-scoped mutate. The mutator only sees one section's payload\n * (`sections.<sectionKey>`) and CANNOT reach sibling sections —\n * preventing accidental clobbers. Returns the mutated section.\n *\n * Use this from CLI callers (`RegistryLockfileService`) so cross-\n * section bugs are impossible by construction. Companion callers\n * that legitimately need full-envelope access keep using\n * `withLockfileMutate` directly.\n */\nexport async function withLockfileSectionMutate<S>(\n options: LockfileMutateOptions & {\n /** Section key under `sections` (e.g. `'modules'`, `'i18n'`). */\n sectionKey: string;\n /** Zod schema validating the section payload. Required. */\n sectionSchema: z.ZodType<S>;\n /** Initial value when the section does not yet exist. */\n initialSection: () => S;\n },\n mutator: (section: S) => S | void | Promise<S | void>,\n): Promise<S> {\n let mutatedOut!: S;\n await withLockfileMutate(\n {\n saasRoot: options.saasRoot,\n lockOptions: options.lockOptions,\n sectionSchemas: {\n ...options.sectionSchemas,\n [options.sectionKey]: options.sectionSchema,\n },\n },\n async (envelope) => {\n const sections = envelope.sections as Record<string, unknown>;\n const current = (sections[options.sectionKey] as S | undefined) ?? options.initialSection();\n const cloned = structuredClone(current);\n const ret = await mutator(cloned);\n const next = (ret ?? cloned) as S;\n // Per-section validation (also covers initial-default re-validation).\n mutatedOut = options.sectionSchema.parse(next);\n sections[options.sectionKey] = mutatedOut;\n },\n );\n return mutatedOut;\n}\n"]}
|
|
@@ -19,8 +19,20 @@
|
|
|
19
19
|
* map is omitted, behavior matches Slice 2.5b — backward-compatible.
|
|
20
20
|
* When the map IS supplied but doesn't contain a module for the
|
|
21
21
|
* resolved `InfraProvider`, the materializer falls back to the
|
|
22
|
-
* authored-entry digest for that capability
|
|
23
|
-
*
|
|
22
|
+
* authored-entry digest for that capability. After #1693 that can only
|
|
23
|
+
* happen for a provider the catalogue declares servable WITHOUT a module
|
|
24
|
+
* (`OPERATOR_CREDENTIALED_INFRA_PROVIDERS`, empty since #1696 gave
|
|
25
|
+
* `IMMUDB_SELF` its module): every other module-less provider is refused
|
|
26
|
+
* before any digest is computed.
|
|
27
|
+
*
|
|
28
|
+
* **#1693 (2026-09-26)**: the materializer REFUSES any declaration the
|
|
29
|
+
* platform cannot serve — one that resolves to no `InfraProvider`, or to
|
|
30
|
+
* one outside the `servableProviders` set the caller must supply. It used
|
|
31
|
+
* to skip the first silently and hash the second, so the lockfile either
|
|
32
|
+
* omitted a declared kind or recorded a selection nothing executes. Both
|
|
33
|
+
* of its callers (`wildo config sync`, `wildo lock check`) reach the one
|
|
34
|
+
* check here, so the two projections cannot disagree about what is
|
|
35
|
+
* refused. See `backing-service-servability.ts`.
|
|
24
36
|
*
|
|
25
37
|
* **Slice 4.A.1 / H2 fix (2026-05-07)**: digest computation uses
|
|
26
38
|
* `stableSha256Digest` (recursive sorted-keys serialization via
|
|
@@ -63,12 +75,21 @@ export interface MaterializeInfraSectionOptions {
|
|
|
63
75
|
* `buildInfraProviderModuleMap()`. Apps-manager-side callers
|
|
64
76
|
* (none today) would do the same.
|
|
65
77
|
*
|
|
66
|
-
* **
|
|
67
|
-
* falls back to the authored-entry digest
|
|
68
|
-
*
|
|
69
|
-
*
|
|
78
|
+
* **Module-less providers**: a resolved provider with no entry here
|
|
79
|
+
* falls back to the authored-entry digest. Only a provider in
|
|
80
|
+
* `servableProviders` can reach that point, so the fallback covers
|
|
81
|
+
* exactly the catalogue's explicit module-less exemptions.
|
|
70
82
|
*/
|
|
71
83
|
moduleMap?: ReadonlyMap<InfraProvider, InfraProviderModule>;
|
|
84
|
+
/**
|
|
85
|
+
* The providers the platform can actually SERVE — from
|
|
86
|
+
* `collectServableInfraProviders()` in `@wildo-ai/platform-infra-providers`.
|
|
87
|
+
* REQUIRED, not optional: a caller that could omit it would be a
|
|
88
|
+
* projection that skips the refusal, and the whole point is that
|
|
89
|
+
* `wildo config sync` and `wildo lock check` refuse the same
|
|
90
|
+
* declarations (#1693).
|
|
91
|
+
*/
|
|
92
|
+
servableProviders: ReadonlySet<InfraProvider>;
|
|
72
93
|
/**
|
|
73
94
|
* The previous lockfile's `sections.infra` (when present). Threaded
|
|
74
95
|
* so `providerSelectedAt` is STICKY: a capability whose resolved
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"materialize-infra-section.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"materialize-infra-section.d.ts","sourceRoot":"","sources":["../../../src/lockfile/materialize-infra-section.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,EAKL,KAAK,wBAAwB,EAC9B,MAAM,mDAAmD,CAAC;AAE3D,OAAO,KAAK,EACV,aAAa,EACb,mBAAmB,EAEpB,MAAM,kDAAkD,CAAC;AAC1D,OAAO,KAAK,EAEV,wBAAwB,EACzB,MAAM,kCAAkC,CAAC;AAG1C;;;;;;GAMG;AACH,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,wBAAwB,GAAG,SAAS,CAAC;CACvD;AAED,MAAM,WAAW,8BAA8B;IAC7C,IAAI,EAAE,aAAa,CAAC,sBAAsB,CAAC,CAAC;IAC5C;;;;;;OAMG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;;;;;;;;;;;;;;;OAgBG;IACH,SAAS,CAAC,EAAE,WAAW,CAAC,aAAa,EAAE,mBAAmB,CAAC,CAAC;IAC5D;;;;;;;OAOG;IACH,iBAAiB,EAAE,WAAW,CAAC,aAAa,CAAC,CAAC;IAC9C;;;;;;;;;;;;;;;;;OAiBG;IACH,eAAe,CAAC,EAAE,wBAAwB,CAAC;CAC5C;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,8BAA8B,GACtC,wBAAwB,GAAG,SAAS,CAuBtC"}
|
|
@@ -19,8 +19,20 @@
|
|
|
19
19
|
* map is omitted, behavior matches Slice 2.5b — backward-compatible.
|
|
20
20
|
* When the map IS supplied but doesn't contain a module for the
|
|
21
21
|
* resolved `InfraProvider`, the materializer falls back to the
|
|
22
|
-
* authored-entry digest for that capability
|
|
23
|
-
*
|
|
22
|
+
* authored-entry digest for that capability. After #1693 that can only
|
|
23
|
+
* happen for a provider the catalogue declares servable WITHOUT a module
|
|
24
|
+
* (`OPERATOR_CREDENTIALED_INFRA_PROVIDERS`, empty since #1696 gave
|
|
25
|
+
* `IMMUDB_SELF` its module): every other module-less provider is refused
|
|
26
|
+
* before any digest is computed.
|
|
27
|
+
*
|
|
28
|
+
* **#1693 (2026-09-26)**: the materializer REFUSES any declaration the
|
|
29
|
+
* platform cannot serve — one that resolves to no `InfraProvider`, or to
|
|
30
|
+
* one outside the `servableProviders` set the caller must supply. It used
|
|
31
|
+
* to skip the first silently and hash the second, so the lockfile either
|
|
32
|
+
* omitted a declared kind or recorded a selection nothing executes. Both
|
|
33
|
+
* of its callers (`wildo config sync`, `wildo lock check`) reach the one
|
|
34
|
+
* check here, so the two projections cannot disagree about what is
|
|
35
|
+
* refused. See `backing-service-servability.ts`.
|
|
24
36
|
*
|
|
25
37
|
* **Slice 4.A.1 / H2 fix (2026-05-07)**: digest computation uses
|
|
26
38
|
* `stableSha256Digest` (recursive sorted-keys serialization via
|
|
@@ -28,6 +40,7 @@
|
|
|
28
40
|
* spuriously trigger drift.
|
|
29
41
|
*/
|
|
30
42
|
import { BackingServiceKind, BackingServiceKindToInfraCapability, resolveInfraProvider, } from '../project-config/shared/backing-services.schemas.js';
|
|
43
|
+
import { assertBackingServiceDeclarationsServable } from '../project-config/shared/backing-service-servability.js';
|
|
31
44
|
import { stableSha256Digest } from './canonical-json.js';
|
|
32
45
|
/**
|
|
33
46
|
* Project authored infra envs into the lockfile `sections.infra`
|
|
@@ -38,6 +51,8 @@ import { stableSha256Digest } from './canonical-json.js';
|
|
|
38
51
|
export function materializeInfraSection(options) {
|
|
39
52
|
if (options.envs.length === 0)
|
|
40
53
|
return undefined;
|
|
54
|
+
// Refuse every unservable declaration, across every environment, before projecting any of them.
|
|
55
|
+
assertBackingServiceDeclarationsServable({ envs: options.envs, servableProviders: options.servableProviders });
|
|
41
56
|
const environments = {};
|
|
42
57
|
let recordedAny = false;
|
|
43
58
|
for (const env of options.envs) {
|
|
@@ -71,17 +86,15 @@ function projectBackingServicesToCapabilities(backingServices, generatedAt, envN
|
|
|
71
86
|
const providerBrand = entry.provider;
|
|
72
87
|
const provider = resolveInfraProvider(kind, entry.source, providerBrand);
|
|
73
88
|
if (!provider) {
|
|
74
|
-
//
|
|
75
|
-
//
|
|
76
|
-
//
|
|
77
|
-
|
|
78
|
-
continue;
|
|
89
|
+
// Unreachable: `assertBackingServiceDeclarationsServable` has already refused every declaration
|
|
90
|
+
// that resolves to no provider. Kept as a throw rather than a `continue`, because a silent skip
|
|
91
|
+
// here is precisely the defect that assertion closed (#1693).
|
|
92
|
+
throw new Error(`backingServices.${kind} in environment '${envName}' resolved to no provider after the servability check.`);
|
|
79
93
|
}
|
|
80
94
|
// Slice 2.5c-1: prefer module.plan() digest when the catalog
|
|
81
95
|
// exposes a module for this provider. Falls back to the
|
|
82
|
-
// authored-entry digest for
|
|
83
|
-
//
|
|
84
|
-
// break materialization.
|
|
96
|
+
// authored-entry digest only for a servable provider the catalogue
|
|
97
|
+
// serves without a module (the operator-credentialed exemptions).
|
|
85
98
|
const planContributionDigest = computeModulePlanDigest(provider, kind, entry, generatedAt, envName, moduleMap)
|
|
86
99
|
?? computeAuthoredEntryDigest(entry);
|
|
87
100
|
// `providerSelectedAt` is STICKY — only a provider's first
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"materialize-infra-section.js","sourceRoot":"","sources":["../../../../src/lockfile/materialize-infra-section.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EACL,kBAAkB,EAClB,mCAAmC,EACnC,oBAAoB,GAGrB,MAAM,mDAAmD,CAAC;AAU3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AA+DtD;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CACrC,OAAuC;IAEvC,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SA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AAC,CAAC;IACvC,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAC9B,MAAM,eAAe,GAAiC;QACpD,WAAW,EAAE,OAAO;QACpB,OAAO,EAAE,SAAS,EAAE,uDAAuD;QAC3E,iBAAiB,EAAE,IAAI;QACvB,MAAM,EAAE,KAAK;KACd,CAAC;IACF,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAClD,OAAO,kBAAkB,CAAC,YAAY,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["/**\n * `materializeInfraSection` — pure function that projects authored\n * `wildo.infra.<envName>.config.ts` files into the\n * `sections.infra` slice of `wildo-saas.lock.json` (Slice 2.5b of\n * `infra-provider-planner.md`).\n *\n * Lives in `platform-config-lib` (no runtime, no DI, no I/O — pure\n * projection). The CLI-side caller is responsible for loading the\n * authored configs from disk via\n * `loadInfraEnvConfig` (this package; the CLI's `loadAuthoredInfraEnvConfig` delegates to it) and passing\n * the parsed `backingServices` slice plus the env name.\n *\n * **Slice 2.5c-1 (2026-05-10)**: when the caller supplies an optional\n * `moduleMap` of `InfraProvider → InfraProviderModule`, the digest\n * is computed from `module.plan(planningContext)` instead of from\n * the authored entry. This captures **provider-version drift**\n * (e.g., a module change to plumbing port, secret env vars,\n * per-app blob paths) on top of authored-config drift. When the\n * map is omitted, behavior matches Slice 2.5b — backward-compatible.\n * When the map IS supplied but doesn't contain a module for the\n * resolved `InfraProvider`, the materializer falls back to the\n * authored-entry digest for that capability (allows partial\n * coverage as the catalog grows in Slice 5).\n *\n * **Slice 4.A.1 / H2 fix (2026-05-07)**: digest computation uses\n * `stableSha256Digest` (recursive sorted-keys serialization via\n * `canonical-json.ts`) so nested-object property reorders don't\n * spuriously trigger drift.\n */\n\nimport {\n BackingServiceKind,\n BackingServiceKindToInfraCapability,\n resolveInfraProvider,\n type BackingServiceEnvConfig,\n type BackingServicesEnvConfig,\n} from '../project-config/shared/backing-services.schemas';\nimport type {\n InfraProvider,\n InfraProviderModule,\n InfraProviderPlanningContext,\n} from '../project-config/shared/infra-providers.schemas';\nimport type {\n SaasLockfileInfraEnvironment,\n SaasLockfileInfraSection,\n} from './wildo-saas-lock.shared.schemas';\nimport { stableSha256Digest } from './canonical-json';\n\n/**\n * Per-env input for the materializer. The caller has already loaded\n * the authored `wildo.infra.<envName>.config.ts` and parsed it via\n * `defineInfraEnvConfig`; we only consume the `backingServices`\n * slice (the only authored surface that maps to `InfraCapability`\n * selections).\n */\nexport interface InfraEnvSelectionInput {\n envName: string;\n backingServices: BackingServicesEnvConfig | undefined;\n}\n\nexport interface MaterializeInfraSectionOptions {\n envs: ReadonlyArray<InfraEnvSelectionInput>;\n /**\n * ISO-8601 timestamp used as the selection time for NEWLY-selected\n * or CHANGED capabilities (see `previousSection` for the sticky-reuse\n * rule). Caller controls it so multi-env writes share one\n * deterministic timestamp (matches the pattern from\n * `materializeSaasProviderRuntimeArtifacts`).\n */\n generatedAt: string;\n /**\n * Optional `InfraProvider → InfraProviderModule` lookup. When\n * present, each capability's `planContributionDigest` is computed\n * from `module.plan(planningContext)` (richer — captures\n * provider-version drift) instead of from the authored entry\n * (Slice 2.5b). Slice 2.5c-1 of `infra-provider-planner.md`.\n *\n * The CLI-side caller in `provider-runtime-sync.service.ts`\n * builds this from `@wildo-ai/platform-infra-providers`'s\n * `buildInfraProviderModuleMap()`. Apps-manager-side callers\n * (none today) would do the same.\n *\n * **Partial coverage**: a missing entry for a resolved provider\n * falls back to the authored-entry digest — no fail-closed. This\n * lets the catalog grow incrementally (Slice 5 stateless modules\n * still pending) without blocking lockfile materialization.\n */\n moduleMap?: ReadonlyMap<InfraProvider, InfraProviderModule>;\n /**\n * The previous lockfile's `sections.infra` (when present). Threaded\n * so `providerSelectedAt` is STICKY: a capability whose resolved\n * `provider` is unchanged retains its prior `providerSelectedAt`\n * instead of being re-stamped with `generatedAt`. Only a newly-\n * selected capability or a provider CHANGE stamps a fresh\n * `generatedAt`.\n *\n * **Why this exists**: `generatedAt` is the lockfile's volatile\n * generation timestamp — it is bumped by EVERY lockfile write,\n * including writes by unrelated subsystems via `withLockfileMutate`.\n * Deriving `providerSelectedAt` directly from it made the field\n * drift on every unrelated write, producing phantom\n * `wildo lock check` failures even when no infra selection changed.\n * Both callers — the `wildo config sync` writer and the\n * `wildo lock check` drift-checker — MUST pass the same previous\n * section so their projections agree.\n */\n previousSection?: SaasLockfileInfraSection;\n}\n\n/**\n * Project authored infra envs into the lockfile `sections.infra`\n * shape. Returns `undefined` when there are no envs to record (so\n * the lockfile writer can skip emitting the section entirely\n * instead of writing an empty `{ environments: {} }`).\n */\nexport function materializeInfraSection(\n options: MaterializeInfraSectionOptions,\n): SaasLockfileInfraSection | undefined {\n if (options.envs.length === 0) return undefined;\n\n const environments: SaasLockfileInfraSection['environments'] = {};\n let recordedAny = false;\n\n for (const env of options.envs) {\n const capabilities = projectBackingServicesToCapabilities(\n env.backingServices,\n options.generatedAt,\n env.envName,\n options.moduleMap,\n options.previousSection?.environments[env.envName],\n );\n if (Object.keys(capabilities).length === 0) continue;\n environments[env.envName] = { capabilities };\n recordedAny = true;\n }\n\n return recordedAny ? { environments } : undefined;\n}\n\nfunction projectBackingServicesToCapabilities(\n backingServices: BackingServicesEnvConfig | undefined,\n generatedAt: string,\n envName: string,\n moduleMap: ReadonlyMap<InfraProvider, InfraProviderModule> | undefined,\n previousEnv: SaasLockfileInfraEnvironment | undefined,\n): SaasLockfileInfraEnvironment['capabilities'] {\n const capabilities: SaasLockfileInfraEnvironment['capabilities'] = {};\n if (!backingServices) return capabilities;\n\n // Iterate via `Object.values(BackingServiceKind)` (Slice 4.A.2 / M7)\n // — avoids an unsafe `kindKey as BackingServiceKind` cast on\n // `Object.entries`'s string keys. `BackingServicesEnvConfigSchema`\n // is `.strict()` so unknown keys can't reach this code path; this\n // tightening just removes the dead defensive guard that came with\n // the cast.\n for (const kind of Object.values(BackingServiceKind)) {\n const entry = backingServices[kind];\n if (!entry) continue;\n const capability = BackingServiceKindToInfraCapability[kind];\n\n // Some kinds carry an additional `provider` brand (e.g. S3 = minio | aws);\n // others don't. The cast lifts to a permissive shape since\n // `BackingServiceEnvConfig` is a discriminated union and the brand only\n // exists on some variants.\n const providerBrand = (entry as BackingServiceEnvConfig & { provider?: string }).provider;\n const provider = resolveInfraProvider(kind, entry.source, providerBrand);\n if (!provider) {\n // Two kinds (METRICS / BACKUP) have no concrete\n // `InfraProvider` catalog entry yet (Slice 1.b). Skip them in\n // the lockfile until the first concrete provider for each is\n // authored — recording an entry without a provider would lie.\n continue;\n }\n\n // Slice 2.5c-1: prefer module.plan() digest when the catalog\n // exposes a module for this provider. Falls back to the\n // authored-entry digest for uncovered providers (Slice 5\n // stateless modules pending) so partial coverage doesn't\n // break materialization.\n const planContributionDigest =\n computeModulePlanDigest(provider, kind, entry, generatedAt, envName, moduleMap)\n ?? computeAuthoredEntryDigest(entry);\n\n // `providerSelectedAt` is STICKY — only a provider's first\n // selection (or re-selection after a change) is a meaningful moment.\n // Reuse the prior timestamp when the resolved provider is unchanged\n // so an unrelated `generatedAt` bump never perturbs it (the root\n // cause of phantom `wildo lock check` infra drift). A newly-added\n // capability or a provider change stamps the fresh `generatedAt`.\n const previousEntry = previousEnv?.capabilities[capability];\n const providerSelectedAt =\n previousEntry && previousEntry.provider === provider\n ? previousEntry.providerSelectedAt\n : generatedAt;\n\n capabilities[capability] = {\n provider,\n providerSelectedAt,\n planContributionDigest,\n };\n }\n return capabilities;\n}\n\n/**\n * Stable digest of an authored `BackingServiceEnvConfig` entry.\n * Uses `stableJsonStringify` (recursive sorted-keys serialization)\n * via `stableSha256Digest` so the digest is insensitive to property-\n * order shuffles at ANY nesting level — not just top-level. This\n * matters for entries with nested objects like\n * `MongoBackingService.options: {retryWrites, w, authSource}` where\n * editor saves frequently reorder the nested keys.\n *\n * Slice 4.A.1 / H2 fix: previously this used `JSON.stringify(entry,\n * Object.keys(entry).sort())` which only sorted top-level keys.\n */\nfunction computeAuthoredEntryDigest(entry: BackingServiceEnvConfig): string {\n return stableSha256Digest(entry);\n}\n\n/**\n * Slice 2.5c-1: compute the digest by invoking the module's\n * `plan()` and hashing its contribution. Returns `undefined` when\n * the module map is missing OR doesn't cover the provider — caller\n * falls back to `computeAuthoredEntryDigest`.\n *\n * **Why include the authored entry IN the planning context**: the\n * module may use authored fields (e.g., a future opt-in flag in\n * `RabbitBackingService`) to vary its contribution. Threading the\n * entry through `config` keeps the digest sensitive to authored\n * drift even when the digest source is `module.plan()`.\n *\n * **Why ignore `generatedAt` in the digest**: the timestamp is the\n * `providerSelectedAt` field, NOT part of plan-contribution\n * identity. Using it would make every `wildo lock` run produce a\n * different digest — defeats drift detection. We don't pass it to\n * `module.plan()`; we pass it through the surrounding shape only.\n */\nfunction computeModulePlanDigest(\n provider: InfraProvider,\n kind: BackingServiceKind,\n entry: BackingServiceEnvConfig,\n _generatedAt: string,\n envName: string,\n moduleMap: ReadonlyMap<InfraProvider, InfraProviderModule> | undefined,\n): string | undefined {\n if (!moduleMap) return undefined;\n const module = moduleMap.get(provider);\n if (!module) return undefined;\n const planningContext: InfraProviderPlanningContext = {\n environment: envName,\n runtime: 'unknown', // Caller doesn't expose runtime per env at this layer.\n backingServiceKey: kind,\n config: entry,\n };\n const contribution = module.plan(planningContext);\n return stableSha256Digest(contribution);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"materialize-infra-section.js","sourceRoot":"","sources":["../../../src/lockfile/materialize-infra-section.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,EACL,kBAAkB,EAClB,mCAAmC,EACnC,oBAAoB,GAGrB,MAAM,mDAAmD,CAAC;AAC3D,OAAO,EAAE,wCAAwC,EAAE,MAAM,sDAAsD,CAAC;AAUhH,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAwEtD;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CACrC,OAAuC;IAEvC,IAAI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;;;;;;;;;;;;;GAiBG;AACH,SAAS,uBAAuB,CAC9B,QAAuB,EACvB,IAAwB,EACxB,KAA8B,EAC9B,YAAoB,EACpB,OAAe,EACf,SAAsE;IAEtE,IAAI,CAAC,SAAS;QAAE,OAAO,SAAS,CAAC;IACjC,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACvC,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAC9B,MAAM,eAAe,GAAiC;QACpD,WAAW,EAAE,OAAO;QACpB,OAAO,EAAE,SAAS,EAAE,uDAAuD;QAC3E,iBAAiB,EAAE,IAAI;QACvB,MAAM,EAAE,KAAK;KACd,CAAC;IACF,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAClD,OAAO,kBAAkB,CAAC,YAAY,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["/**\n * `materializeInfraSection` — pure function that projects authored\n * `wildo.infra.<envName>.config.ts` files into the\n * `sections.infra` slice of `wildo-saas.lock.json` (Slice 2.5b of\n * `infra-provider-planner.md`).\n *\n * Lives in `platform-config-lib` (no runtime, no DI, no I/O — pure\n * projection). The CLI-side caller is responsible for loading the\n * authored configs from disk via\n * `loadInfraEnvConfig` (this package; the CLI's `loadAuthoredInfraEnvConfig` delegates to it) and passing\n * the parsed `backingServices` slice plus the env name.\n *\n * **Slice 2.5c-1 (2026-05-10)**: when the caller supplies an optional\n * `moduleMap` of `InfraProvider → InfraProviderModule`, the digest\n * is computed from `module.plan(planningContext)` instead of from\n * the authored entry. This captures **provider-version drift**\n * (e.g., a module change to plumbing port, secret env vars,\n * per-app blob paths) on top of authored-config drift. When the\n * map is omitted, behavior matches Slice 2.5b — backward-compatible.\n * When the map IS supplied but doesn't contain a module for the\n * resolved `InfraProvider`, the materializer falls back to the\n * authored-entry digest for that capability. After #1693 that can only\n * happen for a provider the catalogue declares servable WITHOUT a module\n * (`OPERATOR_CREDENTIALED_INFRA_PROVIDERS`, empty since #1696 gave\n * `IMMUDB_SELF` its module): every other module-less provider is refused\n * before any digest is computed.\n *\n * **#1693 (2026-09-26)**: the materializer REFUSES any declaration the\n * platform cannot serve — one that resolves to no `InfraProvider`, or to\n * one outside the `servableProviders` set the caller must supply. It used\n * to skip the first silently and hash the second, so the lockfile either\n * omitted a declared kind or recorded a selection nothing executes. Both\n * of its callers (`wildo config sync`, `wildo lock check`) reach the one\n * check here, so the two projections cannot disagree about what is\n * refused. See `backing-service-servability.ts`.\n *\n * **Slice 4.A.1 / H2 fix (2026-05-07)**: digest computation uses\n * `stableSha256Digest` (recursive sorted-keys serialization via\n * `canonical-json.ts`) so nested-object property reorders don't\n * spuriously trigger drift.\n */\n\nimport {\n BackingServiceKind,\n BackingServiceKindToInfraCapability,\n resolveInfraProvider,\n type BackingServiceEnvConfig,\n type BackingServicesEnvConfig,\n} from '../project-config/shared/backing-services.schemas';\nimport { assertBackingServiceDeclarationsServable } from '../project-config/shared/backing-service-servability';\nimport type {\n InfraProvider,\n InfraProviderModule,\n InfraProviderPlanningContext,\n} from '../project-config/shared/infra-providers.schemas';\nimport type {\n SaasLockfileInfraEnvironment,\n SaasLockfileInfraSection,\n} from './wildo-saas-lock.shared.schemas';\nimport { stableSha256Digest } from './canonical-json';\n\n/**\n * Per-env input for the materializer. The caller has already loaded\n * the authored `wildo.infra.<envName>.config.ts` and parsed it via\n * `defineInfraEnvConfig`; we only consume the `backingServices`\n * slice (the only authored surface that maps to `InfraCapability`\n * selections).\n */\nexport interface InfraEnvSelectionInput {\n envName: string;\n backingServices: BackingServicesEnvConfig | undefined;\n}\n\nexport interface MaterializeInfraSectionOptions {\n envs: ReadonlyArray<InfraEnvSelectionInput>;\n /**\n * ISO-8601 timestamp used as the selection time for NEWLY-selected\n * or CHANGED capabilities (see `previousSection` for the sticky-reuse\n * rule). Caller controls it so multi-env writes share one\n * deterministic timestamp (matches the pattern from\n * `materializeSaasProviderRuntimeArtifacts`).\n */\n generatedAt: string;\n /**\n * Optional `InfraProvider → InfraProviderModule` lookup. When\n * present, each capability's `planContributionDigest` is computed\n * from `module.plan(planningContext)` (richer — captures\n * provider-version drift) instead of from the authored entry\n * (Slice 2.5b). Slice 2.5c-1 of `infra-provider-planner.md`.\n *\n * The CLI-side caller in `provider-runtime-sync.service.ts`\n * builds this from `@wildo-ai/platform-infra-providers`'s\n * `buildInfraProviderModuleMap()`. Apps-manager-side callers\n * (none today) would do the same.\n *\n * **Module-less providers**: a resolved provider with no entry here\n * falls back to the authored-entry digest. Only a provider in\n * `servableProviders` can reach that point, so the fallback covers\n * exactly the catalogue's explicit module-less exemptions.\n */\n moduleMap?: ReadonlyMap<InfraProvider, InfraProviderModule>;\n /**\n * The providers the platform can actually SERVE — from\n * `collectServableInfraProviders()` in `@wildo-ai/platform-infra-providers`.\n * REQUIRED, not optional: a caller that could omit it would be a\n * projection that skips the refusal, and the whole point is that\n * `wildo config sync` and `wildo lock check` refuse the same\n * declarations (#1693).\n */\n servableProviders: ReadonlySet<InfraProvider>;\n /**\n * The previous lockfile's `sections.infra` (when present). Threaded\n * so `providerSelectedAt` is STICKY: a capability whose resolved\n * `provider` is unchanged retains its prior `providerSelectedAt`\n * instead of being re-stamped with `generatedAt`. Only a newly-\n * selected capability or a provider CHANGE stamps a fresh\n * `generatedAt`.\n *\n * **Why this exists**: `generatedAt` is the lockfile's volatile\n * generation timestamp — it is bumped by EVERY lockfile write,\n * including writes by unrelated subsystems via `withLockfileMutate`.\n * Deriving `providerSelectedAt` directly from it made the field\n * drift on every unrelated write, producing phantom\n * `wildo lock check` failures even when no infra selection changed.\n * Both callers — the `wildo config sync` writer and the\n * `wildo lock check` drift-checker — MUST pass the same previous\n * section so their projections agree.\n */\n previousSection?: SaasLockfileInfraSection;\n}\n\n/**\n * Project authored infra envs into the lockfile `sections.infra`\n * shape. Returns `undefined` when there are no envs to record (so\n * the lockfile writer can skip emitting the section entirely\n * instead of writing an empty `{ environments: {} }`).\n */\nexport function materializeInfraSection(\n options: MaterializeInfraSectionOptions,\n): SaasLockfileInfraSection | undefined {\n if (options.envs.length === 0) return undefined;\n\n // Refuse every unservable declaration, across every environment, before projecting any of them.\n assertBackingServiceDeclarationsServable({ envs: options.envs, servableProviders: options.servableProviders });\n\n const environments: SaasLockfileInfraSection['environments'] = {};\n let recordedAny = false;\n\n for (const env of options.envs) {\n const capabilities = projectBackingServicesToCapabilities(\n env.backingServices,\n options.generatedAt,\n env.envName,\n options.moduleMap,\n options.previousSection?.environments[env.envName],\n );\n if (Object.keys(capabilities).length === 0) continue;\n environments[env.envName] = { capabilities };\n recordedAny = true;\n }\n\n return recordedAny ? { environments } : undefined;\n}\n\nfunction projectBackingServicesToCapabilities(\n backingServices: BackingServicesEnvConfig | undefined,\n generatedAt: string,\n envName: string,\n moduleMap: ReadonlyMap<InfraProvider, InfraProviderModule> | undefined,\n previousEnv: SaasLockfileInfraEnvironment | undefined,\n): SaasLockfileInfraEnvironment['capabilities'] {\n const capabilities: SaasLockfileInfraEnvironment['capabilities'] = {};\n if (!backingServices) return capabilities;\n\n // Iterate via `Object.values(BackingServiceKind)` (Slice 4.A.2 / M7)\n // — avoids an unsafe `kindKey as BackingServiceKind` cast on\n // `Object.entries`'s string keys. `BackingServicesEnvConfigSchema`\n // is `.strict()` so unknown keys can't reach this code path; this\n // tightening just removes the dead defensive guard that came with\n // the cast.\n for (const kind of Object.values(BackingServiceKind)) {\n const entry = backingServices[kind];\n if (!entry) continue;\n const capability = BackingServiceKindToInfraCapability[kind];\n\n // Some kinds carry an additional `provider` brand (e.g. S3 = minio | aws);\n // others don't. The cast lifts to a permissive shape since\n // `BackingServiceEnvConfig` is a discriminated union and the brand only\n // exists on some variants.\n const providerBrand = (entry as BackingServiceEnvConfig & { provider?: string }).provider;\n const provider = resolveInfraProvider(kind, entry.source, providerBrand);\n if (!provider) {\n // Unreachable: `assertBackingServiceDeclarationsServable` has already refused every declaration\n // that resolves to no provider. Kept as a throw rather than a `continue`, because a silent skip\n // here is precisely the defect that assertion closed (#1693).\n throw new Error(`backingServices.${kind} in environment '${envName}' resolved to no provider after the servability check.`);\n }\n\n // Slice 2.5c-1: prefer module.plan() digest when the catalog\n // exposes a module for this provider. Falls back to the\n // authored-entry digest only for a servable provider the catalogue\n // serves without a module (the operator-credentialed exemptions).\n const planContributionDigest =\n computeModulePlanDigest(provider, kind, entry, generatedAt, envName, moduleMap)\n ?? computeAuthoredEntryDigest(entry);\n\n // `providerSelectedAt` is STICKY — only a provider's first\n // selection (or re-selection after a change) is a meaningful moment.\n // Reuse the prior timestamp when the resolved provider is unchanged\n // so an unrelated `generatedAt` bump never perturbs it (the root\n // cause of phantom `wildo lock check` infra drift). A newly-added\n // capability or a provider change stamps the fresh `generatedAt`.\n const previousEntry = previousEnv?.capabilities[capability];\n const providerSelectedAt =\n previousEntry && previousEntry.provider === provider\n ? previousEntry.providerSelectedAt\n : generatedAt;\n\n capabilities[capability] = {\n provider,\n providerSelectedAt,\n planContributionDigest,\n };\n }\n return capabilities;\n}\n\n/**\n * Stable digest of an authored `BackingServiceEnvConfig` entry.\n * Uses `stableJsonStringify` (recursive sorted-keys serialization)\n * via `stableSha256Digest` so the digest is insensitive to property-\n * order shuffles at ANY nesting level — not just top-level. This\n * matters for entries with nested objects like\n * `MongoBackingService.options: {retryWrites, w, authSource}` where\n * editor saves frequently reorder the nested keys.\n *\n * Slice 4.A.1 / H2 fix: previously this used `JSON.stringify(entry,\n * Object.keys(entry).sort())` which only sorted top-level keys.\n */\nfunction computeAuthoredEntryDigest(entry: BackingServiceEnvConfig): string {\n return stableSha256Digest(entry);\n}\n\n/**\n * Slice 2.5c-1: compute the digest by invoking the module's\n * `plan()` and hashing its contribution. Returns `undefined` when\n * the module map is missing OR doesn't cover the provider — caller\n * falls back to `computeAuthoredEntryDigest`.\n *\n * **Why include the authored entry IN the planning context**: the\n * module may use authored fields (e.g., a future opt-in flag in\n * `RabbitBackingService`) to vary its contribution. Threading the\n * entry through `config` keeps the digest sensitive to authored\n * drift even when the digest source is `module.plan()`.\n *\n * **Why ignore `generatedAt` in the digest**: the timestamp is the\n * `providerSelectedAt` field, NOT part of plan-contribution\n * identity. Using it would make every `wildo lock` run produce a\n * different digest — defeats drift detection. We don't pass it to\n * `module.plan()`; we pass it through the surrounding shape only.\n */\nfunction computeModulePlanDigest(\n provider: InfraProvider,\n kind: BackingServiceKind,\n entry: BackingServiceEnvConfig,\n _generatedAt: string,\n envName: string,\n moduleMap: ReadonlyMap<InfraProvider, InfraProviderModule> | undefined,\n): string | undefined {\n if (!moduleMap) return undefined;\n const module = moduleMap.get(provider);\n if (!module) return undefined;\n const planningContext: InfraProviderPlanningContext = {\n environment: envName,\n runtime: 'unknown', // Caller doesn't expose runtime per env at this layer.\n backingServiceKey: kind,\n config: entry,\n };\n const contribution = module.plan(planningContext);\n return stableSha256Digest(contribution);\n}\n"]}
|