@@ -22,7 +22,7 @@ import type {
2222 TaskItem ,
2323 WorkerItem ,
2424} from "$lib/api/types" ;
25- import { executeOpPlane } from "$lib/server/api/console-api " ;
25+ import { executeOpPlane } from "$lib/server/domain/commands/op-plane " ;
2626import { listDashboards } from "$lib/server/domain/dashboard/store" ;
2727import { consumeOpRateLimit } from "$lib/server/domain/op-rate-limit" ;
2828import { currentPrincipal } from "$lib/server/domain/principal" ;
@@ -37,6 +37,7 @@ import {
3737 readTasks as readTasksCore ,
3838} from "$lib/server/domain/reads/tracker-reads" ;
3939import { ConsoleDomain } from "$lib/server/domain/service" ;
40+ import { readTerminalAccess as readTerminalAccessCore } from "$lib/server/domain/terminal/service" ;
4041import { Effect } from "effect" ;
4142import { Command , Query } from "svelte-effect-runtime" ;
4243
@@ -108,7 +109,8 @@ export const readPlaneRemote = Query("unchecked", (plane: ReadPlane) =>
108109 zookie : principal . zookie ,
109110 } satisfies Me ;
110111 if ( plane === "health" )
111- return yield * Effect . tryPromise ( async ( ) => {
112+ // The bus-health probe is a single scoped lake read; a fault is a defect, not a caller error.
113+ return yield * Effect . promise ( async ( ) => {
112114 const rows = await services . db . admin < { bus_heartbeat_at : string | null } [ ] > `
113115 select max(received_at)::text as bus_heartbeat_at
114116 from events where type = 'console.bus.health'` ;
@@ -120,33 +122,31 @@ export const readPlaneRemote = Query("unchecked", (plane: ReadPlane) =>
120122 } ;
121123 } ) ;
122124 if ( plane === "roster" ) {
123- const result = yield * Effect . tryPromise ( ( ) =>
124- readRosterCore ( services . db . app , services . tracker , principal . scopes ) ,
125- ) ;
126- return { ...result , items : result . items . map ( ( item ) => flattenRosterItem ( item as never ) ) } ;
125+ const result = yield * readRosterCore ( services . db . app , services . tracker , principal . scopes ) ;
126+ return { ...result , items : result . items . map ( ( item ) => flattenRosterItem ( item ) ) } ;
127127 }
128- if ( plane === "executors" )
129- return yield * Effect . tryPromise ( ( ) => readExecutorsCore ( services . db . app , principal . scopes ) ) ;
128+ if ( plane === "executors" ) return yield * readExecutorsCore ( services . db . app , principal . scopes ) ;
130129 if ( plane === "tasks" || plane === "leases" ) {
131130 if ( ! services . tracker )
132131 return yield * Effect . die ( new Error ( "Tracker read adapter is unavailable" ) ) ;
133- return plane === "tasks"
132+ return yield * plane === "tasks"
134133 ? readTasksCore ( services . tracker , principal . scopes )
135134 : readLeasesCore ( services . tracker , principal . scopes ) ;
136135 }
137136 if ( plane === "dashboards" )
138- return yield * Effect . tryPromise ( ( ) =>
137+ // The canonical plane reads dashboards with a fixed limit and no cursor, so the only modeled
138+ // DashboardError (a bad cursor) is unreachable here — treat it as a defect, keeping this
139+ // shared read's channel empty for every consumer.
140+ return yield * Effect . orDie (
139141 listDashboards ( services . db . app , principal . scopes , services . cursorSecret , { limit : 100 } ) ,
140142 ) ;
141143 if ( plane === "catalog" )
142- return yield * Effect . tryPromise ( ( ) =>
143- readEntity ( services . db . app , principal . scopes , "registry" , { limit : 1_000 } ) ,
144- ) ;
144+ return yield * readEntity ( services . db . app , principal . scopes , "registry" , { limit : 1_000 } ) ;
145145 const kind = projectedKinds [ plane ] ;
146146 if ( kind === "attention" ) {
147- const envelope = yield * Effect . tryPromise ( ( ) =>
148- readTypedEntity ( services . db . app , principal . scopes , kind , { limit : 1_000 } ) ,
149- ) ;
147+ const envelope = yield * readTypedEntity ( services . db . app , principal . scopes , kind , {
148+ limit : 1_000 ,
149+ } ) ;
150150 // Attention items carry an operating lane; a caller only sees items for lanes it holds.
151151 return {
152152 ...envelope ,
@@ -158,11 +158,9 @@ export const readPlaneRemote = Query("unchecked", (plane: ReadPlane) =>
158158 } ;
159159 }
160160
161- return yield * Effect . tryPromise ( ( ) =>
162- kind === "subscription"
163- ? readTypedEntity ( services . db . app , principal . scopes , kind , { limit : 1_000 } )
164- : readEntity ( services . db . app , principal . scopes , kind , { limit : 1_000 } ) ,
165- ) ;
161+ return yield * kind === "subscription"
162+ ? readTypedEntity ( services . db . app , principal . scopes , kind , { limit : 1_000 } )
163+ : readEntity ( services . db . app , principal . scopes , kind , { limit : 1_000 } ) ;
166164 } ) ,
167165) ;
168166
@@ -171,9 +169,16 @@ export const runStructuredQuery = Query("unchecked", (request: StructuredQuery)
171169 const domain = yield * ConsoleDomain ;
172170 const services = yield * domain . services ;
173171 const principal = yield * currentPrincipal ;
174- return yield * Effect . tryPromise ( ( ) =>
175- runStructured ( services . db . app , principal . scopes , request ) ,
176- ) ;
172+ return yield * runStructured ( services . db . app , principal . scopes , request ) ;
173+ } ) ,
174+ ) ;
175+
176+ export const readTerminalAccessRemote = Query (
177+ Effect . gen ( function * ( ) {
178+ const domain = yield * ConsoleDomain ;
179+ const services = yield * domain . services ;
180+ const principal = yield * currentPrincipal ;
181+ return yield * readTerminalAccessCore ( services , principal ) ;
177182 } ) ,
178183) ;
179184
@@ -203,25 +208,26 @@ export const executeNamedOp = Command(
203208 retryable : true ,
204209 } ,
205210 } satisfies OpResult ;
206- // The one authoritative command plane: catalog lookup, arg validation, authz, proposal
207- // posture, audit intent/outcome, and internal adapters — identical to POST /api/v1/op.
208- const { body } = yield * Effect . tryPromise ( ( ) =>
209- executeOpPlane (
210- services ,
211- services . monitor ,
212- {
213- schema_version : 1 ,
214- id : input . id ?? crypto . randomUUID ( ) ,
215- op : input . op ,
216- args : input . args ,
217- ...( input . reason !== undefined ? { reason : input . reason } : { } ) ,
218- ...( input . task_id !== undefined ? { task_id : input . task_id } : { } ) ,
219- dry_run : input . dry_run ?? false ,
220- } ,
221- principal ,
222- ) ,
211+ // The one authoritative command plane, composed in process from the domain: catalog lookup,
212+ // arg validation, authz, proposal posture, audit intent/outcome, and internal adapters —
213+ // identical to POST /api/v1/op, which now runs the SAME domain effect at its HTTP edge.
214+ const { body } = yield * executeOpPlane (
215+ services ,
216+ services . monitor ,
217+ {
218+ schema_version : 1 ,
219+ id : input . id ?? crypto . randomUUID ( ) ,
220+ op : input . op ,
221+ args : input . args ,
222+ ...( input . reason !== undefined ? { reason : input . reason } : { } ) ,
223+ ...( input . task_id !== undefined ? { task_id : input . task_id } : { } ) ,
224+ dry_run : input . dry_run ?? false ,
225+ } ,
226+ principal ,
223227 ) ;
224- return body as unknown as OpResult ;
228+ // The command plane returns the loosely-typed HTTP op envelope; narrow it to its documented
229+ // OpResult shape (a genuine, unavoidable narrowing of the shared envelope, not a mock cast).
230+ return body as OpResult ;
225231 } ) ,
226232) ;
227233
0 commit comments