@@ -15,9 +15,11 @@ import * as Log from "@opencode-ai/core/util/log"
1515import { lazy } from "../../util/lazy"
1616import { Config } from "@/config/config"
1717import { ConfigProjects } from "@/config/projects"
18+ import { Project } from "@/project/project"
1819import { errors } from "../error"
1920import { Event as ServerEvent } from "../event"
2021import { disposeAllInstancesAndEmitGlobalDisposed } from "../global-lifecycle"
22+ import { OpenedProjects } from "../shared/opened-projects"
2123
2224const log = Log . create ( { service : "server" } )
2325
@@ -219,8 +221,14 @@ export const GlobalRoutes = lazy(() =>
219221 } ,
220222 } ) ,
221223 async ( c ) => {
222- const cfg = await AppRuntime . runPromise ( Config . Service . use ( ( svc ) => svc . getGlobal ( ) ) )
223- return c . json ( cfg . projects ?? [ ] )
224+ const projects = await AppRuntime . runPromise (
225+ Effect . gen ( function * ( ) {
226+ const config = yield * Config . Service
227+ const project = yield * Project . Service
228+ return yield * OpenedProjects . list ( config , project )
229+ } ) ,
230+ )
231+ return c . json ( projects )
224232 } ,
225233 )
226234 . post (
@@ -244,17 +252,13 @@ export const GlobalRoutes = lazy(() =>
244252 async ( c ) => {
245253 const input = c . req . valid ( "json" )
246254 const next = await AppRuntime . runPromise (
247- Config . Service . use ( ( svc ) =>
248- Effect . gen ( function * ( ) {
249- const cfg = yield * svc . getGlobal ( )
250- const projects = cfg . projects ?? [ ]
251- if ( projects . some ( ( project ) => project . worktree === input . worktree ) ) return projects
252- const next = [ { worktree : input . worktree } , ...projects ]
253- yield * svc . updateGlobal ( { ...cfg , projects : next } )
254- yield * Effect . sync ( emitOpenedProjectsUpdated )
255- return next
256- } ) ,
257- ) ,
255+ Effect . gen ( function * ( ) {
256+ const config = yield * Config . Service
257+ const project = yield * Project . Service
258+ const next = yield * OpenedProjects . open ( config , project , input . worktree )
259+ yield * Effect . sync ( emitOpenedProjectsUpdated )
260+ return next
261+ } ) ,
258262 )
259263 return c . json ( next )
260264 } ,
@@ -280,15 +284,13 @@ export const GlobalRoutes = lazy(() =>
280284 async ( c ) => {
281285 const input = c . req . valid ( "json" )
282286 const next = await AppRuntime . runPromise (
283- Config . Service . use ( ( svc ) =>
284- Effect . gen ( function * ( ) {
285- const cfg = yield * svc . getGlobal ( )
286- const next = ( cfg . projects ?? [ ] ) . filter ( ( project ) => project . worktree !== input . worktree )
287- yield * svc . updateGlobal ( { ...cfg , projects : next } )
288- yield * Effect . sync ( emitOpenedProjectsUpdated )
289- return next
290- } ) ,
291- ) ,
287+ Effect . gen ( function * ( ) {
288+ const config = yield * Config . Service
289+ const project = yield * Project . Service
290+ const next = yield * OpenedProjects . close ( config , project , input . worktree )
291+ yield * Effect . sync ( emitOpenedProjectsUpdated )
292+ return next
293+ } ) ,
292294 )
293295 return c . json ( next )
294296 } ,
@@ -319,7 +321,6 @@ export const GlobalRoutes = lazy(() =>
319321 . object ( {
320322 color : z . string ( ) . optional ( ) ,
321323 override : z . string ( ) . optional ( ) ,
322- emoji : z . string ( ) . optional ( ) ,
323324 } )
324325 . optional ( ) ,
325326 commands : z
@@ -332,24 +333,13 @@ export const GlobalRoutes = lazy(() =>
332333 async ( c ) => {
333334 const input = c . req . valid ( "json" )
334335 const next = await AppRuntime . runPromise (
335- Config . Service . use ( ( svc ) =>
336- Effect . gen ( function * ( ) {
337- const cfg = yield * svc . getGlobal ( )
338- const projects = cfg . projects ?? [ ]
339- const next = projects . map ( ( project ) => {
340- if ( project . worktree !== input . worktree ) return project
341- return {
342- ...project ,
343- ...( input . name !== undefined ? { name : input . name } : { } ) ,
344- ...( input . icon !== undefined ? { icon : { ...project . icon , ...input . icon } } : { } ) ,
345- ...( input . commands !== undefined ? { commands : { ...project . commands , ...input . commands } } : { } ) ,
346- }
347- } )
348- yield * svc . updateGlobal ( { ...cfg , projects : next } )
349- yield * Effect . sync ( emitOpenedProjectsUpdated )
350- return next
351- } ) ,
352- ) ,
336+ Effect . gen ( function * ( ) {
337+ const config = yield * Config . Service
338+ const project = yield * Project . Service
339+ const next = yield * OpenedProjects . meta ( config , project , input )
340+ yield * Effect . sync ( emitOpenedProjectsUpdated )
341+ return next
342+ } ) ,
353343 )
354344 return c . json ( next )
355345 } ,
@@ -375,14 +365,13 @@ export const GlobalRoutes = lazy(() =>
375365 async ( c ) => {
376366 const input = c . req . valid ( "json" )
377367 const next = await AppRuntime . runPromise (
378- Config . Service . use ( ( svc ) =>
379- Effect . gen ( function * ( ) {
380- const cfg = yield * svc . getGlobal ( )
381- yield * svc . updateGlobal ( { ...cfg , projects : input . projects } )
382- yield * Effect . sync ( emitOpenedProjectsUpdated )
383- return input . projects
384- } ) ,
385- ) ,
368+ Effect . gen ( function * ( ) {
369+ const config = yield * Config . Service
370+ const project = yield * Project . Service
371+ const next = yield * OpenedProjects . reorder ( config , project , input . projects )
372+ yield * Effect . sync ( emitOpenedProjectsUpdated )
373+ return next
374+ } ) ,
386375 )
387376 return c . json ( next )
388377 } ,
0 commit comments