From 897da56c44638a0b45148231db7d9cb9a8993c4f Mon Sep 17 00:00:00 2001 From: Josh Gratton Date: Mon, 22 Jun 2026 14:31:27 -0400 Subject: [PATCH] Inline service shapes into Context.Service declarations Per the app's service-definition convention (flagged by macroscope), inline the standalone *Shape interfaces into their Context.Service type arguments and drop the separate types: - DesktopWslBackendShape -> DesktopWslBackend - DesktopWslEnvironmentShape -> DesktopWslEnvironment - DesktopBackendOutputLogFactoryShape -> DesktopBackendOutputLogFactory - DesktopBackendPoolShape -> DesktopBackendPool Internal and test references updated to X["Service"] (and ["Service"]["register"] / ["unregister"]). Pure type-level move; tags, members, and runtime behavior are unchanged. Desktop typecheck clean; affected tests pass. --- apps/desktop/src/app/DesktopObservability.ts | 8 +-- .../src/backend/DesktopBackendManager.test.ts | 2 +- .../src/backend/DesktopBackendPool.test.ts | 2 +- .../desktop/src/backend/DesktopBackendPool.ts | 66 +++++++++---------- .../DesktopLocalEnvironmentAuth.test.ts | 2 +- apps/desktop/src/wsl/DesktopWslBackend.ts | 29 ++++---- apps/desktop/src/wsl/DesktopWslEnvironment.ts | 50 +++++++------- 7 files changed, 76 insertions(+), 83 deletions(-) diff --git a/apps/desktop/src/app/DesktopObservability.ts b/apps/desktop/src/app/DesktopObservability.ts index 2247b76a6a..42451e45de 100644 --- a/apps/desktop/src/app/DesktopObservability.ts +++ b/apps/desktop/src/app/DesktopObservability.ts @@ -51,13 +51,11 @@ export interface DesktopBackendOutputLogShape { // `forInstance` calls (e.g. during a backend restart that re-resolves // services) reuse the same rotating writer rather than racing each other // on the same file. -export interface DesktopBackendOutputLogFactoryShape { - readonly forInstance: (id: string) => Effect.Effect; -} - export class DesktopBackendOutputLogFactory extends Context.Service< DesktopBackendOutputLogFactory, - DesktopBackendOutputLogFactoryShape + { + readonly forInstance: (id: string) => Effect.Effect; + } >()("@t3tools/desktop/app/DesktopObservability/DesktopBackendOutputLogFactory") {} const textEncoder = new TextEncoder(); diff --git a/apps/desktop/src/backend/DesktopBackendManager.test.ts b/apps/desktop/src/backend/DesktopBackendManager.test.ts index ae76e24042..931029989a 100644 --- a/apps/desktop/src/backend/DesktopBackendManager.test.ts +++ b/apps/desktop/src/backend/DesktopBackendManager.test.ts @@ -132,7 +132,7 @@ function makeTestInstance(input: MakeInstanceInput) { input.httpClientLayer ?? healthyHttpClientLayer, Layer.succeed(DesktopObservability.DesktopBackendOutputLogFactory, { forInstance: () => Effect.succeed(stubLog), - } satisfies DesktopObservability.DesktopBackendOutputLogFactoryShape), + } satisfies DesktopObservability.DesktopBackendOutputLogFactory["Service"]), ); const instance = DesktopBackendManager.makeBackendInstance({ diff --git a/apps/desktop/src/backend/DesktopBackendPool.test.ts b/apps/desktop/src/backend/DesktopBackendPool.test.ts index ef070e306c..5e6a3f5164 100644 --- a/apps/desktop/src/backend/DesktopBackendPool.test.ts +++ b/apps/desktop/src/backend/DesktopBackendPool.test.ts @@ -59,7 +59,7 @@ function makePoolLayer( writeSessionBoundary: () => Effect.void, writeOutputChunk: () => Effect.void, } satisfies DesktopObservability.DesktopBackendOutputLogShape), - } satisfies DesktopObservability.DesktopBackendOutputLogFactoryShape), + } satisfies DesktopObservability.DesktopBackendOutputLogFactory["Service"]), Layer.succeed(DesktopBackendConfiguration.DesktopBackendConfiguration, { resolvePrimary: Effect.die("unexpected primary config resolve"), resolvePrimaryLabel: Ref.get(labelRef), diff --git a/apps/desktop/src/backend/DesktopBackendPool.ts b/apps/desktop/src/backend/DesktopBackendPool.ts index 668e404d7a..6011491d70 100644 --- a/apps/desktop/src/backend/DesktopBackendPool.ts +++ b/apps/desktop/src/backend/DesktopBackendPool.ts @@ -134,40 +134,38 @@ export class DesktopBackendPoolCannotUnregisterPrimaryError extends Schema.Tagge } } -export interface DesktopBackendPoolShape { - // Look up a registered instance. None when no backend with that id is - // currently registered (e.g. WSL backend disabled). - readonly get: (id: BackendInstanceId) => Effect.Effect>; - // Snapshot of all currently-registered instances. Order is unspecified; - // callers that need a canonical "primary first" view should sort by id. - readonly list: Effect.Effect; - // Convenience accessor for the always-registered primary instance. - // Currently equivalent to `get(PRIMARY_INSTANCE_ID)` unwrapped, but - // exposed as a typed effect so consumers don't have to handle the - // Option for the case that's guaranteed to be present. - readonly primary: Effect.Effect; - // Build a fresh DesktopBackendInstance from `spec` and add it to the - // registry. The pool owns the instance's scope: unregister(id) or pool - // teardown closes it and runs the instance's auto-stop finalizer. The - // returned instance has not been started — callers decide when to - // start it (and can call start more than once if a retry-after-failure - // story makes sense for them). - readonly register: ( - spec: BackendInstanceSpec, - ) => Effect.Effect; - // Stop the named instance and remove it from the registry. Closing the - // instance's scope triggers its auto-stop finalizer; the registry is - // updated atomically with the scope close so subsequent get(id) calls - // observe the unregister before the underlying child process has fully - // exited. - readonly unregister: ( - id: BackendInstanceId, - ) => Effect.Effect; -} - export class DesktopBackendPool extends Context.Service< DesktopBackendPool, - DesktopBackendPoolShape + { + // Look up a registered instance. None when no backend with that id is + // currently registered (e.g. WSL backend disabled). + readonly get: (id: BackendInstanceId) => Effect.Effect>; + // Snapshot of all currently-registered instances. Order is unspecified; + // callers that need a canonical "primary first" view should sort by id. + readonly list: Effect.Effect; + // Convenience accessor for the always-registered primary instance. + // Currently equivalent to `get(PRIMARY_INSTANCE_ID)` unwrapped, but + // exposed as a typed effect so consumers don't have to handle the + // Option for the case that's guaranteed to be present. + readonly primary: Effect.Effect; + // Build a fresh DesktopBackendInstance from `spec` and add it to the + // registry. The pool owns the instance's scope: unregister(id) or pool + // teardown closes it and runs the instance's auto-stop finalizer. The + // returned instance has not been started — callers decide when to + // start it (and can call start more than once if a retry-after-failure + // story makes sense for them). + readonly register: ( + spec: BackendInstanceSpec, + ) => Effect.Effect; + // Stop the named instance and remove it from the registry. Closing the + // instance's scope triggers its auto-stop finalizer; the registry is + // updated atomically with the scope close so subsequent get(id) calls + // observe the unregister before the underlying child process has fully + // exited. + readonly unregister: ( + id: BackendInstanceId, + ) => Effect.Effect; + } >()("@t3tools/desktop/backend/DesktopBackendPool") {} // Services required by makeBackendInstance — exported so caller @@ -278,7 +276,7 @@ export const layer = Layer.effect( ]), ); - const register: DesktopBackendPoolShape["register"] = (spec) => + const register: DesktopBackendPool["Service"]["register"] = (spec) => SynchronizedRef.modifyEffect(instancesRef, (current) => { if (current.has(spec.id)) { return Effect.fail(new DesktopBackendPoolInstanceAlreadyRegisteredError({ id: spec.id })); @@ -298,7 +296,7 @@ export const layer = Layer.effect( }); }); - const unregister: DesktopBackendPoolShape["unregister"] = (id) => + const unregister: DesktopBackendPool["Service"]["unregister"] = (id) => Effect.gen(function* () { if (id === DesktopBackendManager.PRIMARY_INSTANCE_ID) { return yield* new DesktopBackendPoolCannotUnregisterPrimaryError(); diff --git a/apps/desktop/src/backend/DesktopLocalEnvironmentAuth.test.ts b/apps/desktop/src/backend/DesktopLocalEnvironmentAuth.test.ts index 35a160cd2b..e7a58baef1 100644 --- a/apps/desktop/src/backend/DesktopLocalEnvironmentAuth.test.ts +++ b/apps/desktop/src/backend/DesktopLocalEnvironmentAuth.test.ts @@ -63,7 +63,7 @@ describe("DesktopLocalEnvironmentAuth", () => { currentConfig: Effect.succeed(Option.some(config)), }, ]), - } as unknown as DesktopBackendPool.DesktopBackendPoolShape); + } as unknown as DesktopBackendPool.DesktopBackendPool["Service"]); const testLayer = DesktopLocalEnvironmentAuth.layer.pipe( Layer.provide(Layer.mergeAll(poolLayer, httpClientLayer)), ); diff --git a/apps/desktop/src/wsl/DesktopWslBackend.ts b/apps/desktop/src/wsl/DesktopWslBackend.ts index 4c88d4035e..3fa2273a45 100644 --- a/apps/desktop/src/wsl/DesktopWslBackend.ts +++ b/apps/desktop/src/wsl/DesktopWslBackend.ts @@ -45,21 +45,20 @@ export const WSL_INSTANCE_ID_PREFIX = "wsl:"; const WSL_DEFAULT_DISTRO_ID = `${WSL_INSTANCE_ID_PREFIX}default`; const MAX_TCP_PORT = 65_535; -export interface DesktopWslBackendShape { - // Bring the pool in line with the current persisted WSL settings. - // Idempotent. Never fails (errors are logged); callers can chain it - // after persisting settings without an error-handling dance. - readonly reconcile: Effect.Effect; - // Reason the dual-mode WSL secondary last failed preflight (no node, wrong - // version, missing build tools), or None. Read by the getWslState IPC so - // Connections settings can show it inline. None in wsl-only mode (that path - // surfaces via a dialog + Windows fallback). - readonly lastPreflightError: Effect.Effect>; -} - -export class DesktopWslBackend extends Context.Service()( - "@t3tools/desktop/wsl/DesktopWslBackend", -) {} +export class DesktopWslBackend extends Context.Service< + DesktopWslBackend, + { + // Bring the pool in line with the current persisted WSL settings. + // Idempotent. Never fails (errors are logged); callers can chain it + // after persisting settings without an error-handling dance. + readonly reconcile: Effect.Effect; + // Reason the dual-mode WSL secondary last failed preflight (no node, wrong + // version, missing build tools), or None. Read by the getWslState IPC so + // Connections settings can show it inline. None in wsl-only mode (that path + // surfaces via a dialog + Windows fallback). + readonly lastPreflightError: Effect.Effect>; + } +>()("@t3tools/desktop/wsl/DesktopWslBackend") {} const { logInfo: logWslBackendInfo, logWarning: logWslBackendWarning } = DesktopObservability.makeComponentLogger("desktop-wsl-backend"); diff --git a/apps/desktop/src/wsl/DesktopWslEnvironment.ts b/apps/desktop/src/wsl/DesktopWslEnvironment.ts index 4463b13e4d..d282bd531f 100644 --- a/apps/desktop/src/wsl/DesktopWslEnvironment.ts +++ b/apps/desktop/src/wsl/DesktopWslEnvironment.ts @@ -32,34 +32,32 @@ export type EnsureWslNodePtyResult = | { readonly ok: true; readonly nodePath: string } | { readonly ok: false; readonly reason: string }; -export interface DesktopWslEnvironmentShape { - readonly isAvailable: Effect.Effect; - readonly listDistros: Effect.Effect; - readonly preWarm: (distro: string | null) => Effect.Effect; - readonly windowsToWslPath: ( - distro: string | null, - windowsPath: string, - ) => Effect.Effect>; - // Resolves the user's Linux home dir inside the chosen distro (e.g. - // "/home/josh"). Used by the folder picker to expand `~` correctly. - readonly getUserHome: (distro: string | null) => Effect.Effect>; - // Resolves the WSL distro's IPv4 address on the WSL vEthernet adapter - // (e.g. "172.x.x.x"). The orchestrator uses this for the WSL backend's - // httpBaseUrl so the renderer can reach it without relying on wslhost's - // localhost→WSL automatic forwarding, which is flaky in practice - // (the backend can be listening for 30+ seconds before wslhost starts - // forwarding 127.0.0.1:port to WSL-side localhost). - readonly getDistroIp: (distro: string | null) => Effect.Effect>; - readonly ensureNodePty: ( - distro: string | null, - windowsRepoRoot: string, - options?: EnsureWslNodePtyOptions, - ) => Effect.Effect; -} - export class DesktopWslEnvironment extends Context.Service< DesktopWslEnvironment, - DesktopWslEnvironmentShape + { + readonly isAvailable: Effect.Effect; + readonly listDistros: Effect.Effect; + readonly preWarm: (distro: string | null) => Effect.Effect; + readonly windowsToWslPath: ( + distro: string | null, + windowsPath: string, + ) => Effect.Effect>; + // Resolves the user's Linux home dir inside the chosen distro (e.g. + // "/home/josh"). Used by the folder picker to expand `~` correctly. + readonly getUserHome: (distro: string | null) => Effect.Effect>; + // Resolves the WSL distro's IPv4 address on the WSL vEthernet adapter + // (e.g. "172.x.x.x"). The orchestrator uses this for the WSL backend's + // httpBaseUrl so the renderer can reach it without relying on wslhost's + // localhost→WSL automatic forwarding, which is flaky in practice + // (the backend can be listening for 30+ seconds before wslhost starts + // forwarding 127.0.0.1:port to WSL-side localhost). + readonly getDistroIp: (distro: string | null) => Effect.Effect>; + readonly ensureNodePty: ( + distro: string | null, + windowsRepoRoot: string, + options?: EnsureWslNodePtyOptions, + ) => Effect.Effect; + } >()("@t3tools/desktop/wsl/DesktopWslEnvironment") {} const buildDistroArgs = (distro: string | null): ReadonlyArray =>