@wildo-ai/wildo-cli 1.1.14 → 1.1.16
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/src/commands/context/journey.command.d.ts.map +1 -1
- package/dist/src/commands/context/journey.command.js +12 -0
- package/dist/src/commands/context/journey.command.js.map +1 -1
- package/dist/src/commands/creation/drive.command.d.ts.map +1 -1
- package/dist/src/commands/creation/drive.command.js +2 -1
- package/dist/src/commands/creation/drive.command.js.map +1 -1
- package/dist/src/commands/generate/email-command.utils.d.ts +2 -0
- package/dist/src/commands/generate/email-command.utils.d.ts.map +1 -1
- package/dist/src/commands/generate/email-command.utils.js +5 -0
- package/dist/src/commands/generate/email-command.utils.js.map +1 -1
- package/dist/src/commands/init.command.d.ts.map +1 -1
- package/dist/src/commands/init.command.js +7 -2
- package/dist/src/commands/init.command.js.map +1 -1
- package/dist/src/commands/local/deregister.command.d.ts.map +1 -1
- package/dist/src/commands/local/deregister.command.js +4 -0
- package/dist/src/commands/local/deregister.command.js.map +1 -1
- package/dist/src/commands/local/dev.command.d.ts +50 -0
- package/dist/src/commands/local/dev.command.d.ts.map +1 -1
- package/dist/src/commands/local/dev.command.js +144 -1
- package/dist/src/commands/local/dev.command.js.map +1 -1
- package/dist/src/commands/local/jobs-command.utils.d.ts +24 -0
- package/dist/src/commands/local/jobs-command.utils.d.ts.map +1 -0
- package/dist/src/commands/local/jobs-command.utils.js +44 -0
- package/dist/src/commands/local/jobs-command.utils.js.map +1 -0
- package/dist/src/commands/local/jobs-run.command.d.ts +7 -0
- package/dist/src/commands/local/jobs-run.command.d.ts.map +1 -0
- package/dist/src/commands/local/jobs-run.command.js +92 -0
- package/dist/src/commands/local/jobs-run.command.js.map +1 -0
- package/dist/src/commands/local/jobs.command.d.ts +7 -0
- package/dist/src/commands/local/jobs.command.d.ts.map +1 -0
- package/dist/src/commands/local/jobs.command.js +59 -0
- package/dist/src/commands/local/jobs.command.js.map +1 -0
- package/dist/src/commands/local/tunnel.command.d.ts +84 -0
- package/dist/src/commands/local/tunnel.command.d.ts.map +1 -0
- package/dist/src/commands/local/tunnel.command.js +274 -0
- package/dist/src/commands/local/tunnel.command.js.map +1 -0
- package/dist/src/commands/providers/grant-export.command.d.ts +16 -0
- package/dist/src/commands/providers/grant-export.command.d.ts.map +1 -0
- package/dist/src/commands/providers/grant-export.command.js +78 -0
- package/dist/src/commands/providers/grant-export.command.js.map +1 -0
- package/dist/src/commands/providers/grant-import.command.d.ts +15 -0
- package/dist/src/commands/providers/grant-import.command.d.ts.map +1 -0
- package/dist/src/commands/providers/grant-import.command.js +78 -0
- package/dist/src/commands/providers/grant-import.command.js.map +1 -0
- package/dist/src/kernel/command-runner.d.ts.map +1 -1
- package/dist/src/kernel/command-runner.js +4 -6
- package/dist/src/kernel/command-runner.js.map +1 -1
- package/dist/src/kernel/hooks.d.ts.map +1 -1
- package/dist/src/kernel/hooks.js +2 -1
- package/dist/src/kernel/hooks.js.map +1 -1
- package/dist/src/kernel/json-document-output.d.ts +7 -0
- package/dist/src/kernel/json-document-output.d.ts.map +1 -1
- package/dist/src/kernel/json-document-output.js +8 -0
- package/dist/src/kernel/json-document-output.js.map +1 -1
- package/dist/src/kernel/types.d.ts +8 -0
- package/dist/src/kernel/types.d.ts.map +1 -1
- package/dist/src/kernel/types.js.map +1 -1
- package/dist/src/services/application/app-bootstrap.service.d.ts +65 -7
- package/dist/src/services/application/app-bootstrap.service.d.ts.map +1 -1
- package/dist/src/services/application/app-bootstrap.service.js +94 -15
- package/dist/src/services/application/app-bootstrap.service.js.map +1 -1
- package/dist/src/services/application/app-local-runtime-addresses.service.d.ts +1 -1
- package/dist/src/services/application/app-local-runtime-addresses.service.d.ts.map +1 -1
- package/dist/src/services/application/app-local-runtime-addresses.service.js.map +1 -1
- package/dist/src/services/application/app-runtime-targets.service.d.ts.map +1 -1
- package/dist/src/services/application/app-runtime-targets.service.js +16 -2
- package/dist/src/services/application/app-runtime-targets.service.js.map +1 -1
- package/dist/src/services/application/application-dependency-alignment.service.d.ts +20 -0
- package/dist/src/services/application/application-dependency-alignment.service.d.ts.map +1 -1
- package/dist/src/services/application/application-dependency-alignment.service.js +32 -2
- package/dist/src/services/application/application-dependency-alignment.service.js.map +1 -1
- package/dist/src/services/application/application-runtime-bootstrap.service.d.ts +13 -0
- package/dist/src/services/application/application-runtime-bootstrap.service.d.ts.map +1 -1
- package/dist/src/services/application/application-runtime-bootstrap.service.js +32 -0
- package/dist/src/services/application/application-runtime-bootstrap.service.js.map +1 -1
- package/dist/src/services/application/environment-provider-configurations.service.d.ts +7 -0
- package/dist/src/services/application/environment-provider-configurations.service.d.ts.map +1 -1
- package/dist/src/services/application/environment-provider-configurations.service.js +1 -1
- package/dist/src/services/application/environment-provider-configurations.service.js.map +1 -1
- package/dist/src/services/application/local-tunnel.service.d.ts +153 -0
- package/dist/src/services/application/local-tunnel.service.d.ts.map +1 -0
- package/dist/src/services/application/local-tunnel.service.js +295 -0
- package/dist/src/services/application/local-tunnel.service.js.map +1 -0
- package/dist/src/services/application/provider-runtime-sync.service.d.ts.map +1 -1
- package/dist/src/services/application/provider-runtime-sync.service.js +3 -0
- package/dist/src/services/application/provider-runtime-sync.service.js.map +1 -1
- package/dist/src/services/application/saas-skeleton.service.d.ts +7 -0
- package/dist/src/services/application/saas-skeleton.service.d.ts.map +1 -1
- package/dist/src/services/application/saas-skeleton.service.js +2 -0
- package/dist/src/services/application/saas-skeleton.service.js.map +1 -1
- package/dist/src/services/catalog/service-address-resolver.service.d.ts +7 -1
- package/dist/src/services/catalog/service-address-resolver.service.d.ts.map +1 -1
- package/dist/src/services/catalog/service-address-resolver.service.js +6 -3
- package/dist/src/services/catalog/service-address-resolver.service.js.map +1 -1
- package/dist/src/services/companion/companion-client.service.d.ts +17 -0
- package/dist/src/services/companion/companion-client.service.d.ts.map +1 -1
- package/dist/src/services/companion/companion-client.service.js +21 -0
- package/dist/src/services/companion/companion-client.service.js.map +1 -1
- package/dist/src/services/companion/creation-drive.service.d.ts +18 -0
- package/dist/src/services/companion/creation-drive.service.d.ts.map +1 -1
- package/dist/src/services/companion/creation-drive.service.js +70 -1
- package/dist/src/services/companion/creation-drive.service.js.map +1 -1
- package/dist/src/services/credentials/application-secrets.service.d.ts +6 -0
- package/dist/src/services/credentials/application-secrets.service.d.ts.map +1 -1
- package/dist/src/services/credentials/application-secrets.service.js +1 -1
- package/dist/src/services/credentials/application-secrets.service.js.map +1 -1
- package/dist/src/services/credentials/provider-env-vars.utils.d.ts.map +1 -1
- package/dist/src/services/credentials/provider-env-vars.utils.js +3 -1
- package/dist/src/services/credentials/provider-env-vars.utils.js.map +1 -1
- package/dist/src/services/credentials/secrets-writer.service.d.ts +11 -2
- package/dist/src/services/credentials/secrets-writer.service.d.ts.map +1 -1
- package/dist/src/services/credentials/secrets-writer.service.js +12 -3
- package/dist/src/services/credentials/secrets-writer.service.js.map +1 -1
- package/dist/src/services/deployment/ci-deploy-generator.service.d.ts.map +1 -1
- package/dist/src/services/deployment/ci-deploy-generator.service.js +3 -3
- package/dist/src/services/deployment/ci-deploy-generator.service.js.map +1 -1
- package/dist/src/services/deployment/docker/docker-compose-generator.service.d.ts +12 -3
- package/dist/src/services/deployment/docker/docker-compose-generator.service.d.ts.map +1 -1
- package/dist/src/services/deployment/docker/docker-compose-generator.service.js +40 -22
- package/dist/src/services/deployment/docker/docker-compose-generator.service.js.map +1 -1
- package/dist/src/services/deployment/framework-pod-network-membership.d.ts +6 -0
- package/dist/src/services/deployment/framework-pod-network-membership.d.ts.map +1 -1
- package/dist/src/services/deployment/framework-pod-network-membership.js +17 -3
- package/dist/src/services/deployment/framework-pod-network-membership.js.map +1 -1
- package/dist/src/services/deployment/k8s/k8s-manifest-generator.service.d.ts +4 -1
- package/dist/src/services/deployment/k8s/k8s-manifest-generator.service.d.ts.map +1 -1
- package/dist/src/services/deployment/k8s/k8s-manifest-generator.service.js +17 -7
- package/dist/src/services/deployment/k8s/k8s-manifest-generator.service.js.map +1 -1
- package/dist/src/services/deployment/k8s/k8s-manifest.schemas.d.ts +7 -0
- package/dist/src/services/deployment/k8s/k8s-manifest.schemas.d.ts.map +1 -1
- package/dist/src/services/deployment/k8s/k8s-manifest.schemas.js.map +1 -1
- package/dist/src/services/deployment/k8s/k8s-secrets-generator.service.d.ts.map +1 -1
- package/dist/src/services/deployment/k8s/k8s-secrets-generator.service.js +15 -9
- package/dist/src/services/deployment/k8s/k8s-secrets-generator.service.js.map +1 -1
- package/dist/src/services/deployment/k8s/kind-pod-host-gateway.d.ts +43 -0
- package/dist/src/services/deployment/k8s/kind-pod-host-gateway.d.ts.map +1 -0
- package/dist/src/services/deployment/k8s/kind-pod-host-gateway.js +12 -0
- package/dist/src/services/deployment/k8s/kind-pod-host-gateway.js.map +1 -0
- package/dist/src/services/deployment/k8s/off-cluster-backing-services.d.ts +3 -1
- package/dist/src/services/deployment/k8s/off-cluster-backing-services.d.ts.map +1 -1
- package/dist/src/services/deployment/k8s/off-cluster-backing-services.js.map +1 -1
- package/dist/src/services/deployment/local-dev-late-workspace-members.service.d.ts +163 -0
- package/dist/src/services/deployment/local-dev-late-workspace-members.service.d.ts.map +1 -0
- package/dist/src/services/deployment/local-dev-late-workspace-members.service.js +356 -0
- package/dist/src/services/deployment/local-dev-late-workspace-members.service.js.map +1 -0
- package/dist/src/services/environment/authored-infra-config.utils.d.ts +13 -3
- package/dist/src/services/environment/authored-infra-config.utils.d.ts.map +1 -1
- package/dist/src/services/environment/authored-infra-config.utils.js +24 -4
- package/dist/src/services/environment/authored-infra-config.utils.js.map +1 -1
- package/dist/src/services/environment/container-host-gateway-listen-host.d.ts +6 -0
- package/dist/src/services/environment/container-host-gateway-listen-host.d.ts.map +1 -1
- package/dist/src/services/environment/container-host-gateway-listen-host.js +6 -0
- package/dist/src/services/environment/container-host-gateway-listen-host.js.map +1 -1
- package/dist/src/services/environment/env-configuration-generator.service.d.ts +12 -0
- package/dist/src/services/environment/env-configuration-generator.service.d.ts.map +1 -1
- package/dist/src/services/environment/env-configuration-generator.service.js +37 -5
- package/dist/src/services/environment/env-configuration-generator.service.js.map +1 -1
- package/dist/src/services/environment/env-vars-builder.service.d.ts +2 -1
- package/dist/src/services/environment/env-vars-builder.service.d.ts.map +1 -1
- package/dist/src/services/environment/env-vars-builder.service.js +47 -32
- package/dist/src/services/environment/env-vars-builder.service.js.map +1 -1
- package/dist/src/services/environment/environment-lifecycle.service.d.ts +7 -4
- package/dist/src/services/environment/environment-lifecycle.service.d.ts.map +1 -1
- package/dist/src/services/environment/environment-lifecycle.service.js +14 -18
- package/dist/src/services/environment/environment-lifecycle.service.js.map +1 -1
- package/dist/src/services/environment/environment-setup.service.d.ts.map +1 -1
- package/dist/src/services/environment/environment-setup.service.js +17 -6
- package/dist/src/services/environment/environment-setup.service.js.map +1 -1
- package/dist/src/services/environment/environment.service.d.ts +4 -3
- package/dist/src/services/environment/environment.service.d.ts.map +1 -1
- package/dist/src/services/environment/environment.service.js +0 -1
- package/dist/src/services/environment/environment.service.js.map +1 -1
- package/dist/src/services/framework/framework-docker-publish.service.d.ts +55 -15
- package/dist/src/services/framework/framework-docker-publish.service.d.ts.map +1 -1
- package/dist/src/services/framework/framework-docker-publish.service.js +115 -25
- package/dist/src/services/framework/framework-docker-publish.service.js.map +1 -1
- package/dist/src/services/framework/package-install.service.d.ts +7 -0
- package/dist/src/services/framework/package-install.service.d.ts.map +1 -1
- package/dist/src/services/framework/package-install.service.js +8 -1
- package/dist/src/services/framework/package-install.service.js.map +1 -1
- package/dist/src/services/registry/application-provider-connection.service.d.ts +16 -1
- package/dist/src/services/registry/application-provider-connection.service.d.ts.map +1 -1
- package/dist/src/services/registry/application-provider-connection.service.js +23 -0
- package/dist/src/services/registry/application-provider-connection.service.js.map +1 -1
- package/dist/src/services/registry/provider-grant-transfer.service.d.ts +48 -0
- package/dist/src/services/registry/provider-grant-transfer.service.d.ts.map +1 -0
- package/dist/src/services/registry/provider-grant-transfer.service.js +144 -0
- package/dist/src/services/registry/provider-grant-transfer.service.js.map +1 -0
- package/dist/src/services/registry/provider-module-scaffold.service.d.ts.map +1 -1
- package/dist/src/services/registry/provider-module-scaffold.service.js +10 -3
- package/dist/src/services/registry/provider-module-scaffold.service.js.map +1 -1
- package/dist/src/services/security/csp-sync.service.d.ts.map +1 -1
- package/dist/src/services/security/csp-sync.service.js +21 -2
- package/dist/src/services/security/csp-sync.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +19 -19
- package/templates/infra/docker-compose/docker-compose.wildo-platform.yml.hbs +16 -7
- package/templates/infra/k8s/platform/platform-crontabs-batches-manager/deployment.yaml.hbs +13 -0
- package/templates/saas/i18n/email/system/remote-agent-task-updated/labels.en.ts +11 -0
- package/templates/saas/i18n/email/system/remote-agent-task-updated/template.tsx +56 -0
- package/templates/saas/i18n/engine/components/APP_LAYOUTS_AGENT_ACTIVITY_SETTINGS.en.ts +61 -0
- package/templates/saas/i18n/engine/components/APP_LAYOUTS_AGENT_ACTIVITY_SETTINGS.fr.ts +61 -0
- package/templates/saas/scenarios/add-technical-doc/files/technical-doc/docusaurus.config.ts.hbs +5 -4
- package/templates/saas/scenarios/add-technical-doc/files/technical-doc/package.json.hbs +1 -1
- package/templates/saas/scenarios/add-technical-doc/files/technical-doc/scripts/substitute-api-origin.mjs +97 -32
- package/templates/saas/scenarios/add-technical-doc/files/technical-doc/src/plugins/api-reference-pages.ts +7 -6
- package/templates/saas/skeleton/.wildo-saas/wildo-dev-companion/scripts/dev-supervised.sh +18 -4
- package/templates/saas/skeleton/frontend/nginx-config/default.conf.hbs +1 -1
- package/templates/saas/skeleton/frontend/src/generated/csp.generated.json.hbs +4 -4
- package/templates/saas/skeleton/infrastructure/local/wildo.infra.local.config.ts.hbs +2 -0
- package/wildo-framework.info.json +1 -1
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/** A workspace member that runs a `dev` script, as `pnpm -r run dev` would start it. */
|
|
2
|
+
export interface WorkspaceDevMember {
|
|
3
|
+
/** Its package name: what `pnpm --filter` selects. */
|
|
4
|
+
readonly name: string;
|
|
5
|
+
/** Its directory, application-relative. */
|
|
6
|
+
readonly directory: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Every workspace member (the root excluded) whose `package.json` declares a `dev` script: the set `pnpm -r run dev`
|
|
10
|
+
* starts. A member whose manifest does not parse, or that has no name, is left out, as pnpm cannot select it either.
|
|
11
|
+
*/
|
|
12
|
+
export declare function listWorkspaceDevMembers(appRoot: string): WorkspaceDevMember[];
|
|
13
|
+
/** What the stack knows between two looks: the members it runs, and the install it last acted on. */
|
|
14
|
+
export interface LateWorkspaceMemberState {
|
|
15
|
+
readonly started: ReadonlySet<string>;
|
|
16
|
+
/** When pnpm last finished an install in the application, as last seen (`node_modules/.modules.yaml`). */
|
|
17
|
+
readonly installedAtMs: number | null;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The members to start now, and the state to keep. Pure but for the reads, which a test replaces.
|
|
21
|
+
*
|
|
22
|
+
* Nothing starts while an install is IN FLIGHT (the member's dependencies are not there yet), and nothing is looked for
|
|
23
|
+
* until pnpm has finished an install since the last look: a member is added by an install, and listing the workspace on
|
|
24
|
+
* every tick would read every manifest every few seconds for nothing.
|
|
25
|
+
*/
|
|
26
|
+
export declare function decideLateWorkspaceMembers(appRoot: string, state: LateWorkspaceMemberState, reads?: {
|
|
27
|
+
readonly installedAtMs: (root: string) => number | null;
|
|
28
|
+
readonly installInFlight: (root: string) => boolean;
|
|
29
|
+
readonly members: (root: string) => readonly WorkspaceDevMember[];
|
|
30
|
+
}): {
|
|
31
|
+
readonly toStart: readonly WorkspaceDevMember[];
|
|
32
|
+
readonly state: LateWorkspaceMemberState;
|
|
33
|
+
};
|
|
34
|
+
/** Whether a dependency install is running in the application right now (the stack-event record, #3552). */
|
|
35
|
+
export declare function isDependencyInstallInFlight(appRoot: string): boolean;
|
|
36
|
+
/** The state at the stack's start: every member `pnpm -r run dev` is starting, and the install already on disk. */
|
|
37
|
+
export declare function initialLateWorkspaceMemberState(appRoot: string): LateWorkspaceMemberState;
|
|
38
|
+
/** How often the stack looks for a finished install. */
|
|
39
|
+
export declare const LATE_WORKSPACE_MEMBER_POLL_MS = 5000;
|
|
40
|
+
/**
|
|
41
|
+
* What the runtimes' env files are written from, out of a `wildo.saas.config.ts` (#3985): the WHOLE declaration. The
|
|
42
|
+
* runtime topology is the case measured — services, minions and workers become `APPLICATION_RUNTIME_ENDPOINTS`, and on
|
|
43
|
+
* reference run 43876218697 `add-website` declared a website at 14:51, the companion restarted at 16:52 and crash-looped on
|
|
44
|
+
* `frontendServices.<x> is declared but runtime.endPoints.<x> is missing` until the run ended. But the env writer also
|
|
45
|
+
* derives from providers, systems of record, data services and key management, so a hand-picked subset of fields would be
|
|
46
|
+
* a second list of what the writer reads, the kind that rots. Any change to the declaration therefore owes a regeneration,
|
|
47
|
+
* which is what restarting `wildo local dev` would do.
|
|
48
|
+
*
|
|
49
|
+
* A canonical string: keys sorted at every depth (an edit that only reorders is not a change), functions and cycles named
|
|
50
|
+
* rather than followed. It sees what is enumerable: a `Map`, a `Set` or a value kept on non-enumerable properties (a Zod
|
|
51
|
+
* schema) serialises without its contents, so a change held only there is not seen. A declaration is plain data today.
|
|
52
|
+
*/
|
|
53
|
+
export declare function declarationFingerprint(config: unknown): string;
|
|
54
|
+
/** The declaration the runtimes' env files were last written from, and the config file's state when it was read. */
|
|
55
|
+
export interface DeclarationState {
|
|
56
|
+
/** `null` when the starting read failed: the first declaration read later is then owed a regeneration. */
|
|
57
|
+
readonly fingerprint: string | null;
|
|
58
|
+
/** The config file's modification time at that read: an unchanged file is never re-read. */
|
|
59
|
+
readonly configModifiedAtMs: number | null;
|
|
60
|
+
}
|
|
61
|
+
/** The reads the reconcile pass makes, replaceable by a test. */
|
|
62
|
+
export interface WorkspaceReconcileReads {
|
|
63
|
+
readonly installInFlight: (root: string) => boolean;
|
|
64
|
+
readonly configModifiedAtMs: (root: string) => number | null;
|
|
65
|
+
readonly loadFingerprint: (root: string) => Promise<string | null>;
|
|
66
|
+
readonly installedAtMs: (root: string) => number | null;
|
|
67
|
+
readonly members: (root: string) => readonly WorkspaceDevMember[];
|
|
68
|
+
readonly now: () => number;
|
|
69
|
+
/**
|
|
70
|
+
* The application-relative directories of the declared RUNTIMES (services, minions, workers): the members that read a
|
|
71
|
+
* `.env` (#4019). `null` when the declaration cannot be read, and then every member is treated as one, as before.
|
|
72
|
+
* Absent, likewise.
|
|
73
|
+
*/
|
|
74
|
+
readonly runtimeDirectories?: (root: string) => Promise<ReadonlySet<string> | null>;
|
|
75
|
+
/** Whether a member's compiled output exists: every file its package `exports` names (#4019). Absent: always ready. */
|
|
76
|
+
readonly memberOutputReady?: (root: string, member: WorkspaceDevMember) => boolean;
|
|
77
|
+
}
|
|
78
|
+
/** After a failed regeneration, how long before the next attempt. */
|
|
79
|
+
export declare const ENV_REGENERATION_RETRY_MS = 60000;
|
|
80
|
+
/**
|
|
81
|
+
* How long a regeneration waits for a member started while it was owed to produce its compiled output (#4019). A provider
|
|
82
|
+
* facet's first compile takes seconds; past this, the regeneration is attempted anyway and its failure is reported.
|
|
83
|
+
*/
|
|
84
|
+
export declare const LATE_MEMBER_OUTPUT_WAIT_MS: number;
|
|
85
|
+
/** The declared runtimes' directories, from the declaration read fresh: services, minions and workers. */
|
|
86
|
+
export declare function declaredRuntimeDirectories(config: {
|
|
87
|
+
readonly services?: Record<string, {
|
|
88
|
+
readonly path: string;
|
|
89
|
+
}>;
|
|
90
|
+
readonly minions?: Record<string, {
|
|
91
|
+
readonly path: string;
|
|
92
|
+
}>;
|
|
93
|
+
readonly workers?: Record<string, {
|
|
94
|
+
readonly path: string;
|
|
95
|
+
}>;
|
|
96
|
+
}): ReadonlySet<string>;
|
|
97
|
+
/**
|
|
98
|
+
* Whether every file a member's package `exports` names exists: its compiled output, which a sync resolving the member's
|
|
99
|
+
* declared runtime export reads (a provider facet's `./app` → `./dist/app.js`). The `source` condition is not output, and
|
|
100
|
+
* a `require` target is a CommonJS build a dev watcher need not emit. A member with no readable manifest or no
|
|
101
|
+
* file-shaped export has nothing to wait for.
|
|
102
|
+
*/
|
|
103
|
+
export declare function memberCompiledOutputExists(appRoot: string, member: WorkspaceDevMember): boolean;
|
|
104
|
+
export declare const DEFAULT_WORKSPACE_RECONCILE_READS: WorkspaceReconcileReads;
|
|
105
|
+
/**
|
|
106
|
+
* One reconcile of the running stack with the workspace and the declaration (#3985, #3986), as `wildo local dev` runs it
|
|
107
|
+
* every few seconds. Single-flight; nothing at all while an install runs. In ORDER, because a member that is also a
|
|
108
|
+
* declared service needs a `.env` that knows it:
|
|
109
|
+
*
|
|
110
|
+
* 1. The declaration: when the config file changed and its fingerprint differs from what the env files were written from
|
|
111
|
+
* (or that is unknown), the env files are OWED, and `regenerate` (the startup bootstrap) runs. A failure keeps them
|
|
112
|
+
* owed and retries after {@link ENV_REGENERATION_RETRY_MS}. A declaration that does not load (an edit in progress)
|
|
113
|
+
* owes nothing yet and is read again on the next change.
|
|
114
|
+
* 2. The members. Each member a finished install brought gets its dev process, once. A member that is a declared
|
|
115
|
+
* RUNTIME (a service, a minion, a worker) reads a `.env`, so it starts only once no regeneration is owed. Any other
|
|
116
|
+
* member (a provider facet, a library) reads none and starts at once, even while one is owed (#4019).
|
|
117
|
+
* 3. A regeneration owed while such a member compiles WAITS for its output, up to {@link LATE_MEMBER_OUTPUT_WAIT_MS},
|
|
118
|
+
* and is attempted the moment the output exists rather than on the next retry.
|
|
119
|
+
*
|
|
120
|
+
* Why 2 and 3 (#4019): the regeneration resolves every frontend provider entry a scope binds, and an installed module's
|
|
121
|
+
* browser facet resolves only once compiled. On reference run 44052185141 the PostHog facet joined at 11:00 and the
|
|
122
|
+
* regeneration failed on "cannot resolve declared runtime export …/provider-posthog-frontend/app" 85 times, while it
|
|
123
|
+
* held back the very dev process that would have compiled the facet: until #4019, every member waited for a successful
|
|
124
|
+
* regeneration, which was the trade #3986 accepted and recorded. A member reading no `.env` never needed to wait.
|
|
125
|
+
*/
|
|
126
|
+
export declare function createWorkspaceReconciler(input: {
|
|
127
|
+
readonly appRoot: string;
|
|
128
|
+
/** Whether the env files can be regenerated at all (startup regenerates only with a framework path). */
|
|
129
|
+
readonly canRegenerate: boolean;
|
|
130
|
+
readonly regenerate: () => Promise<void>;
|
|
131
|
+
readonly startMember: (member: WorkspaceDevMember) => void;
|
|
132
|
+
readonly isStopping: () => boolean;
|
|
133
|
+
readonly reportRegenerationFailure: (error: unknown) => void;
|
|
134
|
+
readonly initial: {
|
|
135
|
+
readonly declaration: DeclarationState;
|
|
136
|
+
readonly members: LateWorkspaceMemberState;
|
|
137
|
+
};
|
|
138
|
+
readonly reads?: WorkspaceReconcileReads;
|
|
139
|
+
}): {
|
|
140
|
+
readonly reconcile: () => Promise<void>;
|
|
141
|
+
readonly regenerationOwed: () => boolean;
|
|
142
|
+
};
|
|
143
|
+
/** The declaration the stack started from: what its env files were written from moments ago. */
|
|
144
|
+
export declare function initialDeclarationState(appRoot: string, reads?: WorkspaceReconcileReads): Promise<DeclarationState>;
|
|
145
|
+
/**
|
|
146
|
+
* Regenerate the application's provider runtime artifacts after a declaration change (#3985), as `wildo config sync
|
|
147
|
+
* --domain config` writes them: the per-runtime provider lists, the generated provider modules, the CSP.
|
|
148
|
+
*
|
|
149
|
+
* The env files are not the only thing a declaration change leaves behind. Measured on reference run 43937787170: the
|
|
150
|
+
* foundation declared `email-preview` and `stripe` at 20:31, the backend's provider artifact still listed none (written by
|
|
151
|
+
* `wildo init` at 19:23), and the backend refused six times with "Required engine capabilities resolve no active provider:
|
|
152
|
+
* [BILLING, EMAIL_TRANSACTIONAL]" and paused, with the build about to start. The same class as Wonder Procurement's on
|
|
153
|
+
* 2026-10-07 (`findProviderRuntimeArtifactsBehindDeclaration`), which a restart repairs and a running stack never did.
|
|
154
|
+
*
|
|
155
|
+
* Run as a CHILD of this CLI: in this long-lived process the configuration loader's module cache still holds the
|
|
156
|
+
* declaration the stack started with, and a sync reading it would regenerate the very artifacts that are behind. Rejects
|
|
157
|
+
* when the child fails, so the reconcile keeps the regeneration owed and retries.
|
|
158
|
+
*/
|
|
159
|
+
export declare function syncProviderRuntimeArtifactsInChild(saasRoot: string, envName: string, run?: (file: string, args: readonly string[], options: {
|
|
160
|
+
cwd: string;
|
|
161
|
+
timeout: number;
|
|
162
|
+
}) => Promise<unknown>): Promise<void>;
|
|
163
|
+
//# sourceMappingURL=local-dev-late-workspace-members.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-dev-late-workspace-members.service.d.ts","sourceRoot":"","sources":["../../../../src/services/deployment/local-dev-late-workspace-members.service.ts"],"names":[],"mappings":"AA6BA,wFAAwF;AACxF,MAAM,WAAW,kBAAkB;IACjC,sDAAsD;IACtD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,2CAA2C;IAC3C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,kBAAkB,EAAE,CAiB7E;AAED,qGAAqG;AACrG,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACtC,0GAA0G;IAC1G,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CACvC;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,wBAAwB,EAC/B,KAAK,GAAE;IACL,QAAQ,CAAC,aAAa,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;IACxD,QAAQ,CAAC,eAAe,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;IACpD,QAAQ,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,SAAS,kBAAkB,EAAE,CAAC;CACvC,GAC5B;IA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CAAC;IAC3D,QAAQ,CAAC,UAAU,EAAE,MAAM,OAAO,CAAC;IACnC,QAAQ,CAAC,yBAAyB,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAC7D,QAAQ,CAAC,OAAO,EAAE;QAAE,QAAQ,CAAC,WAAW,EAAE,gBAAgB,CAAC;QAAC,QAAQ,CAAC,OAAO,EAAE,wBAAwB,CAAA;KAAE,CAAC;IACzG,QAAQ,CAAC,KAAK,CAAC,EAAE,uBAAuB,CAAC;CAC1C,GAAG;IAAE,QAAQ,CAAC,SAAS,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAAC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,OAAO,CAAA;CAAE,CAwExF;AAYD,gGAAgG;AAChG,wBAAsB,uBAAuB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,GAAE,uBAA2D,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAS5J;AAKD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,mCAAmC,CACvD,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,GAAG,GAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,KAAK,OAAO,CAAC,OAAO,CAAmB,GAC5H,OAAO,CAAC,IAAI,CAAC,CAOf"}
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The workspace members that JOIN an application while `wildo local dev` runs, and the dev process each one is owed (#3986).
|
|
3
|
+
*
|
|
4
|
+
* The development tree is `pnpm dev`, which runs `pnpm -r run dev`: one `dev` process for every workspace member that
|
|
5
|
+
* has the script, enumerated ONCE, when the stack starts. A member added later never gets one. The members that arrive
|
|
6
|
+
* that way are real and routine: `wildo registry add` installs a provider as `providers/<ref>/backend`, and `wildo compose`
|
|
7
|
+
* adds a website, a documentation site, a minion or a worker. Measured on reference run 43876218697: a coding run
|
|
8
|
+
* installed the Brevo provider at 16:41, its package was never compiled, and the backend, which depends on it, sat paused
|
|
9
|
+
* on `dependency-output-not-ready` for the rest of the run. A person routes around it by restarting `wildo local dev`; an
|
|
10
|
+
* unattended creation cannot.
|
|
11
|
+
*
|
|
12
|
+
* So the stack watches for a FINISHED INSTALL (a new member is usable only once its dependencies are), and starts the dev
|
|
13
|
+
* script of every member with one that it has not started yet. A member that is also a declared SERVICE needs its `.env`
|
|
14
|
+
* first: {@link decideRuntimeTopologyRegeneration} says when the declared topology changed, and the command rewrites
|
|
15
|
+
* every runtime's env files BEFORE it starts the new members (#3985). The decision is pure and lives here; the spawning stays in
|
|
16
|
+
* the command. A member that LEAVES is not stopped: its process exits on its own when its files go, and a restart of the
|
|
17
|
+
* stack reads the workspace afresh.
|
|
18
|
+
*/
|
|
19
|
+
import { execFile } from 'node:child_process';
|
|
20
|
+
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
21
|
+
import { join, normalize } from 'node:path';
|
|
22
|
+
import { promisify } from 'node:util';
|
|
23
|
+
import { loadSaasConfig } from '@wildo-ai/platform-config-lib';
|
|
24
|
+
import { LocalDevDependencyInstallPhase } from '@wildo-ai/platform-core-shared';
|
|
25
|
+
import { classifyDependencyInstall, readDependencyInstallRecord, readNodeModulesInstalledAtMs } from '@wildo-ai/platform-core-shared/dev-runtime';
|
|
26
|
+
import { expandWorkspaceMemberPatterns, readWorkspacePackagePatterns } from '../../services/application/application-dependency-alignment.service.js';
|
|
27
|
+
/**
|
|
28
|
+
* Every workspace member (the root excluded) whose `package.json` declares a `dev` script: the set `pnpm -r run dev`
|
|
29
|
+
* starts. A member whose manifest does not parse, or that has no name, is left out, as pnpm cannot select it either.
|
|
30
|
+
*/
|
|
31
|
+
export function listWorkspaceDevMembers(appRoot) {
|
|
32
|
+
const { members } = expandWorkspaceMemberPatterns(appRoot, readWorkspacePackagePatterns(join(appRoot, 'pnpm-workspace.yaml')));
|
|
33
|
+
const found = [];
|
|
34
|
+
for (const directory of members) {
|
|
35
|
+
if (directory === '.')
|
|
36
|
+
continue;
|
|
37
|
+
const manifestPath = join(appRoot, directory, 'package.json');
|
|
38
|
+
if (!existsSync(manifestPath))
|
|
39
|
+
continue;
|
|
40
|
+
try {
|
|
41
|
+
const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
|
42
|
+
if (typeof manifest.name === 'string' && manifest.name.length > 0 && typeof manifest.scripts?.dev === 'string') {
|
|
43
|
+
found.push({ name: manifest.name, directory });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// An unreadable manifest is one pnpm cannot run either.
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return found;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The members to start now, and the state to keep. Pure but for the reads, which a test replaces.
|
|
54
|
+
*
|
|
55
|
+
* Nothing starts while an install is IN FLIGHT (the member's dependencies are not there yet), and nothing is looked for
|
|
56
|
+
* until pnpm has finished an install since the last look: a member is added by an install, and listing the workspace on
|
|
57
|
+
* every tick would read every manifest every few seconds for nothing.
|
|
58
|
+
*/
|
|
59
|
+
export function decideLateWorkspaceMembers(appRoot, state, reads = DEFAULT_LATE_MEMBER_READS) {
|
|
60
|
+
if (reads.installInFlight(appRoot))
|
|
61
|
+
return { toStart: [], state };
|
|
62
|
+
const installedAtMs = reads.installedAtMs(appRoot);
|
|
63
|
+
if (installedAtMs === null || (state.installedAtMs !== null && installedAtMs <= state.installedAtMs))
|
|
64
|
+
return { toStart: [], state };
|
|
65
|
+
const toStart = reads.members(appRoot).filter((member) => !state.started.has(member.name));
|
|
66
|
+
return {
|
|
67
|
+
toStart,
|
|
68
|
+
state: { started: new Set([...state.started, ...toStart.map((member) => member.name)]), installedAtMs },
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** Whether a dependency install is running in the application right now (the stack-event record, #3552). */
|
|
72
|
+
export function isDependencyInstallInFlight(appRoot) {
|
|
73
|
+
return classifyDependencyInstall(readDependencyInstallRecord(appRoot), Date.now()).phase === LocalDevDependencyInstallPhase.IN_FLIGHT;
|
|
74
|
+
}
|
|
75
|
+
const DEFAULT_LATE_MEMBER_READS = {
|
|
76
|
+
installedAtMs: readNodeModulesInstalledAtMs,
|
|
77
|
+
installInFlight: isDependencyInstallInFlight,
|
|
78
|
+
members: listWorkspaceDevMembers,
|
|
79
|
+
};
|
|
80
|
+
/** The state at the stack's start: every member `pnpm -r run dev` is starting, and the install already on disk. */
|
|
81
|
+
export function initialLateWorkspaceMemberState(appRoot) {
|
|
82
|
+
return {
|
|
83
|
+
started: new Set(listWorkspaceDevMembers(appRoot).map((member) => member.name)),
|
|
84
|
+
installedAtMs: readNodeModulesInstalledAtMs(appRoot),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/** How often the stack looks for a finished install. */
|
|
88
|
+
export const LATE_WORKSPACE_MEMBER_POLL_MS = 5_000;
|
|
89
|
+
/**
|
|
90
|
+
* What the runtimes' env files are written from, out of a `wildo.saas.config.ts` (#3985): the WHOLE declaration. The
|
|
91
|
+
* runtime topology is the case measured — services, minions and workers become `APPLICATION_RUNTIME_ENDPOINTS`, and on
|
|
92
|
+
* reference run 43876218697 `add-website` declared a website at 14:51, the companion restarted at 16:52 and crash-looped on
|
|
93
|
+
* `frontendServices.<x> is declared but runtime.endPoints.<x> is missing` until the run ended. But the env writer also
|
|
94
|
+
* derives from providers, systems of record, data services and key management, so a hand-picked subset of fields would be
|
|
95
|
+
* a second list of what the writer reads, the kind that rots. Any change to the declaration therefore owes a regeneration,
|
|
96
|
+
* which is what restarting `wildo local dev` would do.
|
|
97
|
+
*
|
|
98
|
+
* A canonical string: keys sorted at every depth (an edit that only reorders is not a change), functions and cycles named
|
|
99
|
+
* rather than followed. It sees what is enumerable: a `Map`, a `Set` or a value kept on non-enumerable properties (a Zod
|
|
100
|
+
* schema) serialises without its contents, so a change held only there is not seen. A declaration is plain data today.
|
|
101
|
+
*/
|
|
102
|
+
export function declarationFingerprint(config) {
|
|
103
|
+
const seen = new WeakSet();
|
|
104
|
+
const canonical = (value) => {
|
|
105
|
+
if (typeof value === 'function')
|
|
106
|
+
return '[function]';
|
|
107
|
+
if (typeof value === 'bigint')
|
|
108
|
+
return value.toString();
|
|
109
|
+
if (value === null || typeof value !== 'object')
|
|
110
|
+
return value;
|
|
111
|
+
if (seen.has(value))
|
|
112
|
+
return '[circular]';
|
|
113
|
+
seen.add(value);
|
|
114
|
+
const result = Array.isArray(value)
|
|
115
|
+
? value.map(canonical)
|
|
116
|
+
: Object.fromEntries(Object.keys(value).sort().map((key) => [key, canonical(value[key])]));
|
|
117
|
+
seen.delete(value);
|
|
118
|
+
return result;
|
|
119
|
+
};
|
|
120
|
+
return JSON.stringify(canonical(config));
|
|
121
|
+
}
|
|
122
|
+
const SAAS_CONFIG_FILE = 'wildo.saas.config.ts';
|
|
123
|
+
/** After a failed regeneration, how long before the next attempt. */
|
|
124
|
+
export const ENV_REGENERATION_RETRY_MS = 60_000;
|
|
125
|
+
/**
|
|
126
|
+
* How long a regeneration waits for a member started while it was owed to produce its compiled output (#4019). A provider
|
|
127
|
+
* facet's first compile takes seconds; past this, the regeneration is attempted anyway and its failure is reported.
|
|
128
|
+
*/
|
|
129
|
+
export const LATE_MEMBER_OUTPUT_WAIT_MS = 5 * 60_000;
|
|
130
|
+
/** An application-relative directory, as the workspace lists a member and the declaration a runtime (`./frontend` → `frontend`). */
|
|
131
|
+
function applicationRelativeDirectory(path) {
|
|
132
|
+
return normalize(path).replace(/^\.\//u, '').replace(/\/+$/u, '');
|
|
133
|
+
}
|
|
134
|
+
/** The declared runtimes' directories, from the declaration read fresh: services, minions and workers. */
|
|
135
|
+
export function declaredRuntimeDirectories(config) {
|
|
136
|
+
return new Set([config.services, config.minions, config.workers]
|
|
137
|
+
.flatMap((owners) => Object.values(owners ?? {}))
|
|
138
|
+
.map((owner) => applicationRelativeDirectory(owner.path)));
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Whether every file a member's package `exports` names exists: its compiled output, which a sync resolving the member's
|
|
142
|
+
* declared runtime export reads (a provider facet's `./app` → `./dist/app.js`). The `source` condition is not output, and
|
|
143
|
+
* a `require` target is a CommonJS build a dev watcher need not emit. A member with no readable manifest or no
|
|
144
|
+
* file-shaped export has nothing to wait for.
|
|
145
|
+
*/
|
|
146
|
+
export function memberCompiledOutputExists(appRoot, member) {
|
|
147
|
+
const memberRoot = join(appRoot, member.directory);
|
|
148
|
+
let exportsField;
|
|
149
|
+
try {
|
|
150
|
+
exportsField = JSON.parse(readFileSync(join(memberRoot, 'package.json'), 'utf8')).exports;
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
const targets = [];
|
|
156
|
+
const collect = (value, condition) => {
|
|
157
|
+
if (typeof value === 'string') {
|
|
158
|
+
if (condition !== 'source' && condition !== 'require' && value.startsWith('./') && !value.includes('*'))
|
|
159
|
+
targets.push(value);
|
|
160
|
+
}
|
|
161
|
+
else if (Array.isArray(value)) {
|
|
162
|
+
for (const entry of value)
|
|
163
|
+
collect(entry, condition);
|
|
164
|
+
}
|
|
165
|
+
else if (value !== null && typeof value === 'object') {
|
|
166
|
+
for (const [key, entry] of Object.entries(value))
|
|
167
|
+
collect(entry, key.startsWith('.') ? condition : key);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
collect(exportsField);
|
|
171
|
+
return targets.every((target) => existsSync(join(memberRoot, target)));
|
|
172
|
+
}
|
|
173
|
+
export const DEFAULT_WORKSPACE_RECONCILE_READS = {
|
|
174
|
+
installInFlight: isDependencyInstallInFlight,
|
|
175
|
+
configModifiedAtMs: (root) => {
|
|
176
|
+
try {
|
|
177
|
+
return statSync(join(root, SAAS_CONFIG_FILE)).mtimeMs;
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
// Fresh: jiti's module cache is process-wide, and this process would otherwise read the declaration it started with.
|
|
184
|
+
loadFingerprint: async (root) => {
|
|
185
|
+
const config = await loadSaasConfig(join(root, SAAS_CONFIG_FILE), { freshModuleCache: true });
|
|
186
|
+
return config === null ? null : declarationFingerprint(config);
|
|
187
|
+
},
|
|
188
|
+
installedAtMs: readNodeModulesInstalledAtMs,
|
|
189
|
+
members: listWorkspaceDevMembers,
|
|
190
|
+
now: () => Date.now(),
|
|
191
|
+
runtimeDirectories: async (root) => {
|
|
192
|
+
try {
|
|
193
|
+
const config = await loadSaasConfig(join(root, SAAS_CONFIG_FILE), { freshModuleCache: true });
|
|
194
|
+
return config === null ? null : declaredRuntimeDirectories(config);
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
memberOutputReady: memberCompiledOutputExists,
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* One reconcile of the running stack with the workspace and the declaration (#3985, #3986), as `wildo local dev` runs it
|
|
204
|
+
* every few seconds. Single-flight; nothing at all while an install runs. In ORDER, because a member that is also a
|
|
205
|
+
* declared service needs a `.env` that knows it:
|
|
206
|
+
*
|
|
207
|
+
* 1. The declaration: when the config file changed and its fingerprint differs from what the env files were written from
|
|
208
|
+
* (or that is unknown), the env files are OWED, and `regenerate` (the startup bootstrap) runs. A failure keeps them
|
|
209
|
+
* owed and retries after {@link ENV_REGENERATION_RETRY_MS}. A declaration that does not load (an edit in progress)
|
|
210
|
+
* owes nothing yet and is read again on the next change.
|
|
211
|
+
* 2. The members. Each member a finished install brought gets its dev process, once. A member that is a declared
|
|
212
|
+
* RUNTIME (a service, a minion, a worker) reads a `.env`, so it starts only once no regeneration is owed. Any other
|
|
213
|
+
* member (a provider facet, a library) reads none and starts at once, even while one is owed (#4019).
|
|
214
|
+
* 3. A regeneration owed while such a member compiles WAITS for its output, up to {@link LATE_MEMBER_OUTPUT_WAIT_MS},
|
|
215
|
+
* and is attempted the moment the output exists rather than on the next retry.
|
|
216
|
+
*
|
|
217
|
+
* Why 2 and 3 (#4019): the regeneration resolves every frontend provider entry a scope binds, and an installed module's
|
|
218
|
+
* browser facet resolves only once compiled. On reference run 44052185141 the PostHog facet joined at 11:00 and the
|
|
219
|
+
* regeneration failed on "cannot resolve declared runtime export …/provider-posthog-frontend/app" 85 times, while it
|
|
220
|
+
* held back the very dev process that would have compiled the facet: until #4019, every member waited for a successful
|
|
221
|
+
* regeneration, which was the trade #3986 accepted and recorded. A member reading no `.env` never needed to wait.
|
|
222
|
+
*/
|
|
223
|
+
export function createWorkspaceReconciler(input) {
|
|
224
|
+
const reads = input.reads ?? DEFAULT_WORKSPACE_RECONCILE_READS;
|
|
225
|
+
let declaration = input.initial.declaration;
|
|
226
|
+
let members = input.initial.members;
|
|
227
|
+
let owed = null; // the fingerprint whose env files are owed
|
|
228
|
+
let retryAtMs = 0;
|
|
229
|
+
let running = false;
|
|
230
|
+
/** Members that read a `.env`, held until no regeneration is owed. */
|
|
231
|
+
let deferred = [];
|
|
232
|
+
/** Members started without waiting for the env files, whose compiled output a regeneration waits for, by start time. */
|
|
233
|
+
const awaitingOutput = new Map();
|
|
234
|
+
const startNow = (member) => {
|
|
235
|
+
input.startMember(member);
|
|
236
|
+
awaitingOutput.set(member.name, { member, startedAtMs: reads.now() });
|
|
237
|
+
};
|
|
238
|
+
const reconcile = async () => {
|
|
239
|
+
if (running || input.isStopping() || reads.installInFlight(input.appRoot))
|
|
240
|
+
return;
|
|
241
|
+
running = true;
|
|
242
|
+
try {
|
|
243
|
+
if (input.canRegenerate) {
|
|
244
|
+
const modifiedAtMs = reads.configModifiedAtMs(input.appRoot);
|
|
245
|
+
if (modifiedAtMs !== null && modifiedAtMs !== declaration.configModifiedAtMs) {
|
|
246
|
+
let fingerprint = null;
|
|
247
|
+
try {
|
|
248
|
+
fingerprint = await reads.loadFingerprint(input.appRoot);
|
|
249
|
+
}
|
|
250
|
+
catch {
|
|
251
|
+
fingerprint = null;
|
|
252
|
+
}
|
|
253
|
+
if (fingerprint !== null) {
|
|
254
|
+
if (fingerprint !== declaration.fingerprint)
|
|
255
|
+
owed = fingerprint;
|
|
256
|
+
declaration = { fingerprint, configModifiedAtMs: modifiedAtMs };
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
// The members a finished install brought. One that reads no `.env` starts at once; one that does waits for the env.
|
|
261
|
+
const decision = decideLateWorkspaceMembers(input.appRoot, members, reads);
|
|
262
|
+
members = decision.state;
|
|
263
|
+
if (decision.toStart.length > 0) {
|
|
264
|
+
const runtimeDirectories = input.canRegenerate ? await readRuntimeDirectories(reads, input.appRoot) : null;
|
|
265
|
+
for (const member of decision.toStart) {
|
|
266
|
+
if (runtimeDirectories !== null && !runtimeDirectories.has(applicationRelativeDirectory(member.directory)))
|
|
267
|
+
startNow(member);
|
|
268
|
+
else
|
|
269
|
+
deferred.push(member);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (input.canRegenerate) {
|
|
273
|
+
// Wait for what a member started without the env files compiles; the moment it is there, try at once.
|
|
274
|
+
if (awaitingOutput.size > 0) {
|
|
275
|
+
for (const [name, { member, startedAtMs }] of awaitingOutput) {
|
|
276
|
+
if ((reads.memberOutputReady?.(input.appRoot, member) ?? true) || reads.now() - startedAtMs >= LATE_MEMBER_OUTPUT_WAIT_MS)
|
|
277
|
+
awaitingOutput.delete(name);
|
|
278
|
+
}
|
|
279
|
+
if (awaitingOutput.size === 0)
|
|
280
|
+
retryAtMs = 0;
|
|
281
|
+
}
|
|
282
|
+
if (owed !== null && awaitingOutput.size === 0 && reads.now() >= retryAtMs) {
|
|
283
|
+
try {
|
|
284
|
+
await input.regenerate();
|
|
285
|
+
owed = null;
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
retryAtMs = reads.now() + ENV_REGENERATION_RETRY_MS;
|
|
289
|
+
input.reportRegenerationFailure(error);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
// The env files first: a member started now would read a `.env` that may not know it.
|
|
293
|
+
if (owed !== null || input.isStopping())
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
const ready = deferred;
|
|
297
|
+
deferred = [];
|
|
298
|
+
for (const member of ready)
|
|
299
|
+
input.startMember(member);
|
|
300
|
+
}
|
|
301
|
+
finally {
|
|
302
|
+
running = false;
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
return { reconcile, regenerationOwed: () => owed !== null };
|
|
306
|
+
}
|
|
307
|
+
/** The declared runtimes' directories, or `null` (every member then waits for the env files) when they cannot be read. */
|
|
308
|
+
async function readRuntimeDirectories(reads, appRoot) {
|
|
309
|
+
if (reads.runtimeDirectories === undefined)
|
|
310
|
+
return null;
|
|
311
|
+
try {
|
|
312
|
+
return await reads.runtimeDirectories(appRoot);
|
|
313
|
+
}
|
|
314
|
+
catch {
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
/** The declaration the stack started from: what its env files were written from moments ago. */
|
|
319
|
+
export async function initialDeclarationState(appRoot, reads = DEFAULT_WORKSPACE_RECONCILE_READS) {
|
|
320
|
+
const configModifiedAtMs = reads.configModifiedAtMs(appRoot);
|
|
321
|
+
try {
|
|
322
|
+
const fingerprint = await reads.loadFingerprint(appRoot);
|
|
323
|
+
return fingerprint === null ? { fingerprint: null, configModifiedAtMs: null } : { fingerprint, configModifiedAtMs };
|
|
324
|
+
}
|
|
325
|
+
catch {
|
|
326
|
+
// Unknown: the first declaration read later is owed a regeneration rather than taken as the baseline.
|
|
327
|
+
return { fingerprint: null, configModifiedAtMs: null };
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
/** Bound on the provider-artifact sync: it reads configuration and writes generated files, and must not hold the reconcile. */
|
|
331
|
+
const PROVIDER_ARTIFACT_SYNC_TIMEOUT_MS = 5 * 60 * 1000;
|
|
332
|
+
/**
|
|
333
|
+
* Regenerate the application's provider runtime artifacts after a declaration change (#3985), as `wildo config sync
|
|
334
|
+
* --domain config` writes them: the per-runtime provider lists, the generated provider modules, the CSP.
|
|
335
|
+
*
|
|
336
|
+
* The env files are not the only thing a declaration change leaves behind. Measured on reference run 43937787170: the
|
|
337
|
+
* foundation declared `email-preview` and `stripe` at 20:31, the backend's provider artifact still listed none (written by
|
|
338
|
+
* `wildo init` at 19:23), and the backend refused six times with "Required engine capabilities resolve no active provider:
|
|
339
|
+
* [BILLING, EMAIL_TRANSACTIONAL]" and paused, with the build about to start. The same class as Wonder Procurement's on
|
|
340
|
+
* 2026-10-07 (`findProviderRuntimeArtifactsBehindDeclaration`), which a restart repairs and a running stack never did.
|
|
341
|
+
*
|
|
342
|
+
* Run as a CHILD of this CLI: in this long-lived process the configuration loader's module cache still holds the
|
|
343
|
+
* declaration the stack started with, and a sync reading it would regenerate the very artifacts that are behind. Rejects
|
|
344
|
+
* when the child fails, so the reconcile keeps the regeneration owed and retries.
|
|
345
|
+
*/
|
|
346
|
+
export async function syncProviderRuntimeArtifactsInChild(saasRoot, envName, run = defaultRunChild) {
|
|
347
|
+
const cliEntry = process.argv[1];
|
|
348
|
+
if (cliEntry === undefined)
|
|
349
|
+
throw new Error('The wildo CLI entry point is unknown, so the provider artifacts cannot be regenerated.');
|
|
350
|
+
await run(process.execPath, [cliEntry, 'config', 'sync', '--domain', 'config', '--env', envName, '--non-interactive'], {
|
|
351
|
+
cwd: saasRoot,
|
|
352
|
+
timeout: PROVIDER_ARTIFACT_SYNC_TIMEOUT_MS,
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
const defaultRunChild = (file, args, options) => promisify(execFile)(file, [...args], { ...options, maxBuffer: 16 * 1024 * 1024 });
|
|
356
|
+
//# sourceMappingURL=local-dev-late-workspace-members.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-dev-late-workspace-members.service.js","sourceRoot":"","sources":["../../../../src/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AAC,EAAE;QACrH,GAAG,EAAE,QAAQ;QACb,OAAO,EAAE,iCAAiC;KAC3C,CAAC,CAAC;AACL,CAAC;AAED,MAAM,eAAe,GAAG,CAAC,IAAY,EAAE,IAAuB,EAAE,OAAyC,EAAoB,EAAE,CAC7H,SAAS,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI,EAAE,CAAC,CAAC","sourcesContent":["/**\n * The workspace members that JOIN an application while `wildo local dev` runs, and the dev process each one is owed (#3986).\n *\n * The development tree is `pnpm dev`, which runs `pnpm -r run dev`: one `dev` process for every workspace member that\n * has the script, enumerated ONCE, when the stack starts. A member added later never gets one. The members that arrive\n * that way are real and routine: `wildo registry add` installs a provider as `providers/<ref>/backend`, and `wildo compose`\n * adds a website, a documentation site, a minion or a worker. Measured on reference run 43876218697: a coding run\n * installed the Brevo provider at 16:41, its package was never compiled, and the backend, which depends on it, sat paused\n * on `dependency-output-not-ready` for the rest of the run. A person routes around it by restarting `wildo local dev`; an\n * unattended creation cannot.\n *\n * So the stack watches for a FINISHED INSTALL (a new member is usable only once its dependencies are), and starts the dev\n * script of every member with one that it has not started yet. A member that is also a declared SERVICE needs its `.env`\n * first: {@link decideRuntimeTopologyRegeneration} says when the declared topology changed, and the command rewrites\n * every runtime's env files BEFORE it starts the new members (#3985). The decision is pure and lives here; the spawning stays in\n * the command. A member that LEAVES is not stopped: its process exits on its own when its files go, and a restart of the\n * stack reads the workspace afresh.\n */\nimport { execFile } from 'node:child_process';\nimport { existsSync, readFileSync, statSync } from 'node:fs';\nimport { join, normalize } from 'node:path';\nimport { promisify } from 'node:util';\n\nimport { loadSaasConfig } from '@wildo-ai/platform-config-lib';\nimport { LocalDevDependencyInstallPhase } from '@wildo-ai/platform-core-shared';\nimport { classifyDependencyInstall, readDependencyInstallRecord, readNodeModulesInstalledAtMs } from '@wildo-ai/platform-core-shared/dev-runtime';\n\nimport { expandWorkspaceMemberPatterns, readWorkspacePackagePatterns } from '~wildo-cli/services/application/application-dependency-alignment.service';\n\n/** A workspace member that runs a `dev` script, as `pnpm -r run dev` would start it. */\nexport interface WorkspaceDevMember {\n /** Its package name: what `pnpm --filter` selects. */\n readonly name: string;\n /** Its directory, application-relative. */\n readonly directory: string;\n}\n\n/**\n * Every workspace member (the root excluded) whose `package.json` declares a `dev` script: the set `pnpm -r run dev`\n * starts. A member whose manifest does not parse, or that has no name, is left out, as pnpm cannot select it either.\n */\nexport function listWorkspaceDevMembers(appRoot: string): WorkspaceDevMember[] {\n const { members } = expandWorkspaceMemberPatterns(appRoot, readWorkspacePackagePatterns(join(appRoot, 'pnpm-workspace.yaml')));\n const found: WorkspaceDevMember[] = [];\n for (const directory of members) {\n if (directory === '.') continue;\n const manifestPath = join(appRoot, directory, 'package.json');\n if (!existsSync(manifestPath)) continue;\n try {\n const manifest = JSON.parse(readFileSync(manifestPath, 'utf8')) as { readonly name?: unknown; readonly scripts?: Record<string, unknown> };\n if (typeof manifest.name === 'string' && manifest.name.length > 0 && typeof manifest.scripts?.dev === 'string') {\n found.push({ name: manifest.name, directory });\n }\n } catch {\n // An unreadable manifest is one pnpm cannot run either.\n }\n }\n return found;\n}\n\n/** What the stack knows between two looks: the members it runs, and the install it last acted on. */\nexport interface LateWorkspaceMemberState {\n readonly started: ReadonlySet<string>;\n /** When pnpm last finished an install in the application, as last seen (`node_modules/.modules.yaml`). */\n readonly installedAtMs: number | null;\n}\n\n/**\n * The members to start now, and the state to keep. Pure but for the reads, which a test replaces.\n *\n * Nothing starts while an install is IN FLIGHT (the member's dependencies are not there yet), and nothing is looked for\n * until pnpm has finished an install since the last look: a member is added by an install, and listing the workspace on\n * every tick would read every manifest every few seconds for nothing.\n */\nexport function decideLateWorkspaceMembers(\n appRoot: string,\n state: LateWorkspaceMemberState,\n reads: {\n readonly installedAtMs: (root: string) => number | null;\n readonly installInFlight: (root: string) => boolean;\n readonly members: (root: string) => readonly WorkspaceDevMember[];\n } = DEFAULT_LATE_MEMBER_READS,\n): { readonly toStart: readonly WorkspaceDevMember[]; readonly state: LateWorkspaceMemberState } {\n if (reads.installInFlight(appRoot)) return { toStart: [], state };\n const installedAtMs = reads.installedAtMs(appRoot);\n if (installedAtMs === null || (state.installedAtMs !== null && installedAtMs <= state.installedAtMs)) return { toStart: [], state };\n const toStart = reads.members(appRoot).filter((member) => !state.started.has(member.name));\n return {\n toStart,\n state: { started: new Set([...state.started, ...toStart.map((member) => member.name)]), installedAtMs },\n };\n}\n\n/** Whether a dependency install is running in the application right now (the stack-event record, #3552). */\nexport function isDependencyInstallInFlight(appRoot: string): boolean {\n return classifyDependencyInstall(readDependencyInstallRecord(appRoot), Date.now()).phase === LocalDevDependencyInstallPhase.IN_FLIGHT;\n}\n\nconst DEFAULT_LATE_MEMBER_READS = {\n installedAtMs: readNodeModulesInstalledAtMs,\n installInFlight: isDependencyInstallInFlight,\n members: listWorkspaceDevMembers,\n} as const;\n\n/** The state at the stack's start: every member `pnpm -r run dev` is starting, and the install already on disk. */\nexport function initialLateWorkspaceMemberState(appRoot: string): LateWorkspaceMemberState {\n return {\n started: new Set(listWorkspaceDevMembers(appRoot).map((member) => member.name)),\n installedAtMs: readNodeModulesInstalledAtMs(appRoot),\n };\n}\n\n/** How often the stack looks for a finished install. */\nexport const LATE_WORKSPACE_MEMBER_POLL_MS = 5_000;\n\n/**\n * What the runtimes' env files are written from, out of a `wildo.saas.config.ts` (#3985): the WHOLE declaration. The\n * runtime topology is the case measured — services, minions and workers become `APPLICATION_RUNTIME_ENDPOINTS`, and on\n * reference run 43876218697 `add-website` declared a website at 14:51, the companion restarted at 16:52 and crash-looped on\n * `frontendServices.<x> is declared but runtime.endPoints.<x> is missing` until the run ended. But the env writer also\n * derives from providers, systems of record, data services and key management, so a hand-picked subset of fields would be\n * a second list of what the writer reads, the kind that rots. Any change to the declaration therefore owes a regeneration,\n * which is what restarting `wildo local dev` would do.\n *\n * A canonical string: keys sorted at every depth (an edit that only reorders is not a change), functions and cycles named\n * rather than followed. It sees what is enumerable: a `Map`, a `Set` or a value kept on non-enumerable properties (a Zod\n * schema) serialises without its contents, so a change held only there is not seen. A declaration is plain data today.\n */\nexport function declarationFingerprint(config: unknown): string {\n const seen = new WeakSet<object>();\n const canonical = (value: unknown): unknown => {\n if (typeof value === 'function') return '[function]';\n if (typeof value === 'bigint') return value.toString();\n if (value === null || typeof value !== 'object') return value;\n if (seen.has(value)) return '[circular]';\n seen.add(value);\n const result = Array.isArray(value)\n ? value.map(canonical)\n : Object.fromEntries(Object.keys(value as Record<string, unknown>).sort().map((key) => [key, canonical((value as Record<string, unknown>)[key])]));\n seen.delete(value);\n return result;\n };\n return JSON.stringify(canonical(config));\n}\n\n/** The declaration the runtimes' env files were last written from, and the config file's state when it was read. */\nexport interface DeclarationState {\n /** `null` when the starting read failed: the first declaration read later is then owed a regeneration. */\n readonly fingerprint: string | null;\n /** The config file's modification time at that read: an unchanged file is never re-read. */\n readonly configModifiedAtMs: number | null;\n}\n\n/** The reads the reconcile pass makes, replaceable by a test. */\nexport interface WorkspaceReconcileReads {\n readonly installInFlight: (root: string) => boolean;\n readonly configModifiedAtMs: (root: string) => number | null;\n readonly loadFingerprint: (root: string) => Promise<string | null>;\n readonly installedAtMs: (root: string) => number | null;\n readonly members: (root: string) => readonly WorkspaceDevMember[];\n readonly now: () => number;\n /**\n * The application-relative directories of the declared RUNTIMES (services, minions, workers): the members that read a\n * `.env` (#4019). `null` when the declaration cannot be read, and then every member is treated as one, as before.\n * Absent, likewise.\n */\n readonly runtimeDirectories?: (root: string) => Promise<ReadonlySet<string> | null>;\n /** Whether a member's compiled output exists: every file its package `exports` names (#4019). Absent: always ready. */\n readonly memberOutputReady?: (root: string, member: WorkspaceDevMember) => boolean;\n}\n\nconst SAAS_CONFIG_FILE = 'wildo.saas.config.ts';\n\n/** After a failed regeneration, how long before the next attempt. */\nexport const ENV_REGENERATION_RETRY_MS = 60_000;\n\n/**\n * How long a regeneration waits for a member started while it was owed to produce its compiled output (#4019). A provider\n * facet's first compile takes seconds; past this, the regeneration is attempted anyway and its failure is reported.\n */\nexport const LATE_MEMBER_OUTPUT_WAIT_MS = 5 * 60_000;\n\n/** An application-relative directory, as the workspace lists a member and the declaration a runtime (`./frontend` → `frontend`). */\nfunction applicationRelativeDirectory(path: string): string {\n return normalize(path).replace(/^\\.\\//u, '').replace(/\\/+$/u, '');\n}\n\n/** The declared runtimes' directories, from the declaration read fresh: services, minions and workers. */\nexport function declaredRuntimeDirectories(config: { readonly services?: Record<string, { readonly path: string }>; readonly minions?: Record<string, { readonly path: string }>; readonly workers?: Record<string, { readonly path: string }> }): ReadonlySet<string> {\n return new Set([config.services, config.minions, config.workers]\n .flatMap((owners) => Object.values(owners ?? {}))\n .map((owner) => applicationRelativeDirectory(owner.path)));\n}\n\n/**\n * Whether every file a member's package `exports` names exists: its compiled output, which a sync resolving the member's\n * declared runtime export reads (a provider facet's `./app` → `./dist/app.js`). The `source` condition is not output, and\n * a `require` target is a CommonJS build a dev watcher need not emit. A member with no readable manifest or no\n * file-shaped export has nothing to wait for.\n */\nexport function memberCompiledOutputExists(appRoot: string, member: WorkspaceDevMember): boolean {\n const memberRoot = join(appRoot, member.directory);\n let exportsField: unknown;\n try {\n exportsField = (JSON.parse(readFileSync(join(memberRoot, 'package.json'), 'utf8')) as { readonly exports?: unknown }).exports;\n } catch {\n return true;\n }\n const targets: string[] = [];\n const collect = (value: unknown, condition?: string): void => {\n if (typeof value === 'string') {\n if (condition !== 'source' && condition !== 'require' && value.startsWith('./') && !value.includes('*')) targets.push(value);\n } else if (Array.isArray(value)) {\n for (const entry of value) collect(entry, condition);\n } else if (value !== null && typeof value === 'object') {\n for (const [key, entry] of Object.entries(value)) collect(entry, key.startsWith('.') ? condition : key);\n }\n };\n collect(exportsField);\n return targets.every((target) => existsSync(join(memberRoot, target)));\n}\n\nexport const DEFAULT_WORKSPACE_RECONCILE_READS: WorkspaceReconcileReads = {\n installInFlight: isDependencyInstallInFlight,\n configModifiedAtMs: (root) => {\n try {\n return statSync(join(root, SAAS_CONFIG_FILE)).mtimeMs;\n } catch {\n return null;\n }\n },\n // Fresh: jiti's module cache is process-wide, and this process would otherwise read the declaration it started with.\n loadFingerprint: async (root) => {\n const config = await loadSaasConfig(join(root, SAAS_CONFIG_FILE), { freshModuleCache: true });\n return config === null ? null : declarationFingerprint(config);\n },\n installedAtMs: readNodeModulesInstalledAtMs,\n members: listWorkspaceDevMembers,\n now: () => Date.now(),\n runtimeDirectories: async (root) => {\n try {\n const config = await loadSaasConfig(join(root, SAAS_CONFIG_FILE), { freshModuleCache: true });\n return config === null ? null : declaredRuntimeDirectories(config);\n } catch {\n return null;\n }\n },\n memberOutputReady: memberCompiledOutputExists,\n};\n\n/**\n * One reconcile of the running stack with the workspace and the declaration (#3985, #3986), as `wildo local dev` runs it\n * every few seconds. Single-flight; nothing at all while an install runs. In ORDER, because a member that is also a\n * declared service needs a `.env` that knows it:\n *\n * 1. The declaration: when the config file changed and its fingerprint differs from what the env files were written from\n * (or that is unknown), the env files are OWED, and `regenerate` (the startup bootstrap) runs. A failure keeps them\n * owed and retries after {@link ENV_REGENERATION_RETRY_MS}. A declaration that does not load (an edit in progress)\n * owes nothing yet and is read again on the next change.\n * 2. The members. Each member a finished install brought gets its dev process, once. A member that is a declared\n * RUNTIME (a service, a minion, a worker) reads a `.env`, so it starts only once no regeneration is owed. Any other\n * member (a provider facet, a library) reads none and starts at once, even while one is owed (#4019).\n * 3. A regeneration owed while such a member compiles WAITS for its output, up to {@link LATE_MEMBER_OUTPUT_WAIT_MS},\n * and is attempted the moment the output exists rather than on the next retry.\n *\n * Why 2 and 3 (#4019): the regeneration resolves every frontend provider entry a scope binds, and an installed module's\n * browser facet resolves only once compiled. On reference run 44052185141 the PostHog facet joined at 11:00 and the\n * regeneration failed on \"cannot resolve declared runtime export …/provider-posthog-frontend/app\" 85 times, while it\n * held back the very dev process that would have compiled the facet: until #4019, every member waited for a successful\n * regeneration, which was the trade #3986 accepted and recorded. A member reading no `.env` never needed to wait.\n */\nexport function createWorkspaceReconciler(input: {\n readonly appRoot: string;\n /** Whether the env files can be regenerated at all (startup regenerates only with a framework path). */\n readonly canRegenerate: boolean;\n readonly regenerate: () => Promise<void>;\n readonly startMember: (member: WorkspaceDevMember) => void;\n readonly isStopping: () => boolean;\n readonly reportRegenerationFailure: (error: unknown) => void;\n readonly initial: { readonly declaration: DeclarationState; readonly members: LateWorkspaceMemberState };\n readonly reads?: WorkspaceReconcileReads;\n}): { readonly reconcile: () => Promise<void>; readonly regenerationOwed: () => boolean } {\n const reads = input.reads ?? DEFAULT_WORKSPACE_RECONCILE_READS;\n let declaration = input.initial.declaration;\n let members = input.initial.members;\n let owed: string | null = null; // the fingerprint whose env files are owed\n let retryAtMs = 0;\n let running = false;\n /** Members that read a `.env`, held until no regeneration is owed. */\n let deferred: WorkspaceDevMember[] = [];\n /** Members started without waiting for the env files, whose compiled output a regeneration waits for, by start time. */\n const awaitingOutput = new Map<string, { readonly member: WorkspaceDevMember; readonly startedAtMs: number }>();\n const startNow = (member: WorkspaceDevMember): void => {\n input.startMember(member);\n awaitingOutput.set(member.name, { member, startedAtMs: reads.now() });\n };\n const reconcile = async (): Promise<void> => {\n if (running || input.isStopping() || reads.installInFlight(input.appRoot)) return;\n running = true;\n try {\n if (input.canRegenerate) {\n const modifiedAtMs = reads.configModifiedAtMs(input.appRoot);\n if (modifiedAtMs !== null && modifiedAtMs !== declaration.configModifiedAtMs) {\n let fingerprint: string | null = null;\n try {\n fingerprint = await reads.loadFingerprint(input.appRoot);\n } catch {\n fingerprint = null;\n }\n if (fingerprint !== null) {\n if (fingerprint !== declaration.fingerprint) owed = fingerprint;\n declaration = { fingerprint, configModifiedAtMs: modifiedAtMs };\n }\n }\n }\n // The members a finished install brought. One that reads no `.env` starts at once; one that does waits for the env.\n const decision = decideLateWorkspaceMembers(input.appRoot, members, reads);\n members = decision.state;\n if (decision.toStart.length > 0) {\n const runtimeDirectories = input.canRegenerate ? await readRuntimeDirectories(reads, input.appRoot) : null;\n for (const member of decision.toStart) {\n if (runtimeDirectories !== null && !runtimeDirectories.has(applicationRelativeDirectory(member.directory))) startNow(member);\n else deferred.push(member);\n }\n }\n if (input.canRegenerate) {\n // Wait for what a member started without the env files compiles; the moment it is there, try at once.\n if (awaitingOutput.size > 0) {\n for (const [name, { member, startedAtMs }] of awaitingOutput) {\n if ((reads.memberOutputReady?.(input.appRoot, member) ?? true) || reads.now() - startedAtMs >= LATE_MEMBER_OUTPUT_WAIT_MS) awaitingOutput.delete(name);\n }\n if (awaitingOutput.size === 0) retryAtMs = 0;\n }\n if (owed !== null && awaitingOutput.size === 0 && reads.now() >= retryAtMs) {\n try {\n await input.regenerate();\n owed = null;\n } catch (error) {\n retryAtMs = reads.now() + ENV_REGENERATION_RETRY_MS;\n input.reportRegenerationFailure(error);\n }\n }\n // The env files first: a member started now would read a `.env` that may not know it.\n if (owed !== null || input.isStopping()) return;\n }\n const ready = deferred;\n deferred = [];\n for (const member of ready) input.startMember(member);\n } finally {\n running = false;\n }\n };\n return { reconcile, regenerationOwed: () => owed !== null };\n}\n\n/** The declared runtimes' directories, or `null` (every member then waits for the env files) when they cannot be read. */\nasync function readRuntimeDirectories(reads: WorkspaceReconcileReads, appRoot: string): Promise<ReadonlySet<string> | null> {\n if (reads.runtimeDirectories === undefined) return null;\n try {\n return await reads.runtimeDirectories(appRoot);\n } catch {\n return null;\n }\n}\n\n/** The declaration the stack started from: what its env files were written from moments ago. */\nexport async function initialDeclarationState(appRoot: string, reads: WorkspaceReconcileReads = DEFAULT_WORKSPACE_RECONCILE_READS): Promise<DeclarationState> {\n const configModifiedAtMs = reads.configModifiedAtMs(appRoot);\n try {\n const fingerprint = await reads.loadFingerprint(appRoot);\n return fingerprint === null ? { fingerprint: null, configModifiedAtMs: null } : { fingerprint, configModifiedAtMs };\n } catch {\n // Unknown: the first declaration read later is owed a regeneration rather than taken as the baseline.\n return { fingerprint: null, configModifiedAtMs: null };\n }\n}\n\n/** Bound on the provider-artifact sync: it reads configuration and writes generated files, and must not hold the reconcile. */\nconst PROVIDER_ARTIFACT_SYNC_TIMEOUT_MS = 5 * 60 * 1000;\n\n/**\n * Regenerate the application's provider runtime artifacts after a declaration change (#3985), as `wildo config sync\n * --domain config` writes them: the per-runtime provider lists, the generated provider modules, the CSP.\n *\n * The env files are not the only thing a declaration change leaves behind. Measured on reference run 43937787170: the\n * foundation declared `email-preview` and `stripe` at 20:31, the backend's provider artifact still listed none (written by\n * `wildo init` at 19:23), and the backend refused six times with \"Required engine capabilities resolve no active provider:\n * [BILLING, EMAIL_TRANSACTIONAL]\" and paused, with the build about to start. The same class as Wonder Procurement's on\n * 2026-10-07 (`findProviderRuntimeArtifactsBehindDeclaration`), which a restart repairs and a running stack never did.\n *\n * Run as a CHILD of this CLI: in this long-lived process the configuration loader's module cache still holds the\n * declaration the stack started with, and a sync reading it would regenerate the very artifacts that are behind. Rejects\n * when the child fails, so the reconcile keeps the regeneration owed and retries.\n */\nexport async function syncProviderRuntimeArtifactsInChild(\n saasRoot: string,\n envName: string,\n run: (file: string, args: readonly string[], options: { cwd: string; timeout: number }) => Promise<unknown> = defaultRunChild,\n): Promise<void> {\n const cliEntry = process.argv[1];\n if (cliEntry === undefined) throw new Error('The wildo CLI entry point is unknown, so the provider artifacts cannot be regenerated.');\n await run(process.execPath, [cliEntry, 'config', 'sync', '--domain', 'config', '--env', envName, '--non-interactive'], {\n cwd: saasRoot,\n timeout: PROVIDER_ARTIFACT_SYNC_TIMEOUT_MS,\n });\n}\n\nconst defaultRunChild = (file: string, args: readonly string[], options: { cwd: string; timeout: number }): Promise<unknown> =>\n promisify(execFile)(file, [...args], { ...options, maxBuffer: 16 * 1024 * 1024 });\n"]}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* keeps the runtime artifacts written by `local up` byte-identical to the
|
|
10
10
|
* ones `wildo config sync --domain manifest` would produce later.
|
|
11
11
|
*/
|
|
12
|
-
import { type WildoInfraEnvConfig } from '@wildo-ai/platform-config-lib';
|
|
12
|
+
import { type LoadConfigOptions, type WildoInfraEnvConfig } from '@wildo-ai/platform-config-lib';
|
|
13
13
|
import type { PlatformEnvConfigJson } from '../../services/credentials/credentials.schemas';
|
|
14
14
|
export interface LoadedAuthoredInfraEnvConfig {
|
|
15
15
|
path: string;
|
|
@@ -20,9 +20,19 @@ export declare function resolveAuthoredInfraConfigPath(saasRoot: string, envName
|
|
|
20
20
|
/**
|
|
21
21
|
* The shared loader (`loadInfraEnvConfig` in platform-config-lib), kept under the CLI's historical name and argument
|
|
22
22
|
* order so its importers and the test that mocks this module are unchanged. The dev companion reads the same file
|
|
23
|
-
* through the shared loader.
|
|
23
|
+
* through the shared loader. `options` is the shared loader's (fresh evaluation, module resolution); omitted, the
|
|
24
|
+
* file is evaluated once per process and the loader infers its resolution.
|
|
24
25
|
*/
|
|
25
|
-
export declare function loadAuthoredInfraEnvConfig(envName: string, saasRoot: string): Promise<LoadedAuthoredInfraEnvConfig | null>;
|
|
26
|
+
export declare function loadAuthoredInfraEnvConfig(envName: string, saasRoot: string, options?: Pick<LoadConfigOptions, 'freshModuleCache' | 'moduleResolution'>): Promise<LoadedAuthoredInfraEnvConfig | null>;
|
|
27
|
+
/**
|
|
28
|
+
* Whether the platform a HOST application owns runs a message broker, from its authored `local` descriptor (#2303
|
|
29
|
+
* slice D): `environmentServiceProfileRunsMessageBroker` of its `serviceProfile`. Read by `wildo init` before scaffolding
|
|
30
|
+
* a hosted application, whose descriptor must declare no RabbitMQ vhost on a host that runs no broker.
|
|
31
|
+
*
|
|
32
|
+
* A host with no readable `local` descriptor answers `true`, the broker every host ran before profiles existed: the
|
|
33
|
+
* scaffold keeps its previous shape, and the hosted resolution then names what is wrong with the host.
|
|
34
|
+
*/
|
|
35
|
+
export declare function readHostRunsMessageBroker(hostRoot: string): Promise<boolean>;
|
|
26
36
|
/** One authored environment: the directory name it lives under, and its loaded config. */
|
|
27
37
|
export interface LoadedNamedAuthoredInfraEnvConfig extends LoadedAuthoredInfraEnvConfig {
|
|
28
38
|
envName: string;
|