@@ -51,16 +51,21 @@ import { Worktree } from "@/worktree"
5151import { RuntimeFlags } from "@/effect/runtime-flags"
5252import { MoveSession } from "@opencode-ai/core/control-plane/move-session"
5353import { Database } from "@opencode-ai/core/database/database"
54+ import { AppNodeBuilderV1 } from "@/effect/app-node-builder-v1"
5455import { LayerNode } from "@opencode-ai/core/effect/layer-node"
55- import { httpClient } from "@opencode-ai/core/effect/layer -node-platform"
56+ import { httpClient } from "@opencode-ai/core/effect/app -node-platform"
5657import { EventV2 } from "@opencode-ai/core/event"
5758import { ModelsDev } from "@opencode-ai/core/models-dev"
5859import { Npm } from "@opencode-ai/core/npm"
60+ import { PermissionSaved } from "@opencode-ai/core/permission/saved"
5961import { ProjectV2 } from "@opencode-ai/core/project"
6062import { ProjectCopy } from "@opencode-ai/core/project/copy"
6163import { PtyTicket } from "@opencode-ai/core/pty/ticket"
6264import { Ripgrep } from "@opencode-ai/core/ripgrep"
6365import { SessionProjector } from "@opencode-ai/core/session/projector"
66+ import { SessionV2 } from "@opencode-ai/core/session"
67+ import { SessionExecution } from "@opencode-ai/core/session/execution"
68+ import * as SessionExecutionLocal from "@opencode-ai/core/session/execution/local"
6469import { lazy } from "@/util/lazy"
6570import { CorsConfig , isAllowedCorsOrigin , type CorsOptions } from "@opencode-ai/server/cors"
6671import { serveUIEffect } from "@/server/shared/ui"
@@ -95,6 +100,10 @@ import { sessionHandlers } from "./handlers/session"
95100import { syncHandlers } from "./handlers/sync"
96101import { tuiHandlers } from "./handlers/tui"
97102import { handlers } from "@opencode-ai/server/handlers"
103+ import { buildLocationServiceMap , LocationServiceMap } from "@opencode-ai/core/location-services"
104+ import { layer as locationLayer } from "@opencode-ai/server/location"
105+ import { sessionLocationLayer } from "@opencode-ai/server/middleware/session-location"
106+ import { PtyEnvironment } from "@opencode-ai/server/pty-environment"
98107import { schemaErrorLayer as v2SchemaErrorLayer } from "@opencode-ai/server/middleware/schema-error"
99108import { workspaceHandlers } from "./handlers/workspace"
100109import { instanceContextLayer } from "./middleware/instance-context"
@@ -124,10 +133,10 @@ const cors = (corsOptions?: CorsOptions) =>
124133// - ptyConnectApiRoutes: typed WebSocket upgrade route with ticket-aware auth.
125134// - instanceApiRoutes: remaining typed instance routes.
126135// - uiRoute: raw catch-all fallback; auth is router middleware so public static assets can bypass it.
127- const authOnlyRouterLayer = authorizationRouterMiddleware . layer . pipe ( Layer . provide ( ServerAuth . Config . defaultLayer ) )
128- const httpApiAuthLayer = authorizationLayer . pipe ( Layer . provide ( ServerAuth . Config . defaultLayer ) )
129- const ptyConnectHttpApiAuthLayer = ptyConnectAuthorizationLayer . pipe ( Layer . provide ( ServerAuth . Config . defaultLayer ) )
130- const serverHttpApiAuthLayer = serverAuthorizationLayer . pipe ( Layer . provide ( ServerAuth . Config . defaultLayer ) )
136+ const authOnlyRouterLayer = authorizationRouterMiddleware . layer . pipe ( Layer . provide ( ServerAuth . Config . layer ) )
137+ const httpApiAuthLayer = authorizationLayer . pipe ( Layer . provide ( ServerAuth . Config . layer ) )
138+ const ptyConnectHttpApiAuthLayer = ptyConnectAuthorizationLayer . pipe ( Layer . provide ( ServerAuth . Config . layer ) )
139+ const serverHttpApiAuthLayer = serverAuthorizationLayer . pipe ( Layer . provide ( ServerAuth . Config . layer ) )
131140const workspaceRoutingLive = workspaceRoutingLayer . pipe ( Layer . provide ( Socket . layerWebSocketConstructorGlobal ) )
132141const rootApiRoutes = HttpApiBuilder . layer ( RootHttpApi ) . pipe (
133142 Layer . provide ( [ controlHandlers , controlPlaneHandlers , globalHandlers ] ) ,
@@ -221,6 +230,7 @@ const app = LayerNode.group([
221230 Discovery . node ,
222231 Question . node ,
223232 Permission . node ,
233+ PermissionSaved . node ,
224234 Todo . node ,
225235 Session . node ,
226236 SessionProjector . node ,
@@ -261,6 +271,8 @@ const app = LayerNode.group([
261271export function createRoutes (
262272 corsOptions ?: CorsOptions ,
263273) : Layer . Layer < never , EffectConfig . ConfigError , RouteRequirements > {
274+ const locationServiceMapV2 = buildLocationServiceMap ( )
275+
264276 return Layer . mergeAll (
265277 rootApiRoutes ,
266278 eventApiRoutes ,
@@ -276,12 +288,27 @@ export function createRoutes(
276288 corsVaryFix ,
277289 fenceLayer ,
278290 cors ( corsOptions ) ,
279- MoveSession . defaultLayer ,
291+ AppNodeBuilderV1 . build ( MoveSession . node , [ [ LocationServiceMap . node , locationServiceMapV2 ] ] ) ,
280292 HttpServer . layerServices ,
281293 ] ) ,
282- Layer . provide ( LayerNode . buildLayer ( app ) ) ,
283294 Layer . provide ( Layer . succeed ( CorsConfig ) ( corsOptions ) ) ,
284- Layer . provide ( Observability . layer ) ,
295+ Layer . provide ( sessionLocationLayer ) ,
296+ Layer . provide ( locationLayer ) ,
297+ Layer . provide ( PtyEnvironment . layer ) ,
298+ Layer . provide (
299+ AppNodeBuilderV1 . build ( SessionV2 . node , [
300+ [ LocationServiceMap . node , locationServiceMapV2 ] ,
301+ [ SessionExecution . node , SessionExecutionLocal . node ] ,
302+ ] ) ,
303+ ) ,
304+ Layer . provide ( locationServiceMapV2 ) ,
305+
306+ Layer . provide ( AppNodeBuilderV1 . build ( app ) ) ,
307+ // Must stay last: layers provided later in this pipe build beneath earlier ones,
308+ // so Observability must come after every service graph. Otherwise eagerly forked
309+ // fibers (e.g. the ModelsDev background refresh) capture Effect's default stdout
310+ // logger and corrupt the TUI (#34730).
311+ Layer . provideMerge ( Observability . layer ) ,
285312 )
286313}
287314
0 commit comments