11import { Account } from "@/account/account"
22import { Config } from "@/config"
3+ import { InstanceState } from "@/effect"
34import { MCP } from "@/mcp"
5+ import { Project } from "@/project"
46import { ToolRegistry } from "@/tool"
57import { Effect , Layer , Option , Schema } from "effect"
68import { HttpApi , HttpApiBuilder , HttpApiEndpoint , HttpApiGroup , OpenApi } from "effect/unstable/httpapi"
@@ -27,10 +29,13 @@ const ConsoleOrgList = Schema.Struct({
2729
2830const ToolIDs = Schema . Array ( Schema . String ) . annotate ( { identifier : "ToolIDs" } )
2931
32+ const WorktreeList = Schema . Array ( Schema . String ) . annotate ( { identifier : "WorktreeList" } )
33+
3034export const ExperimentalPaths = {
3135 console : "/experimental/console" ,
3236 consoleOrgs : "/experimental/console/orgs" ,
3337 toolIDs : "/experimental/tool/ids" ,
38+ worktree : "/experimental/worktree" ,
3439 resource : "/experimental/resource" ,
3540} as const
3641
@@ -66,6 +71,15 @@ export const ExperimentalApi = HttpApi.make("experimental")
6671 "Get a list of all available tool IDs, including both built-in tools and dynamically registered tools." ,
6772 } ) ,
6873 ) ,
74+ HttpApiEndpoint . get ( "worktree" , ExperimentalPaths . worktree , {
75+ success : WorktreeList ,
76+ } ) . annotateMerge (
77+ OpenApi . annotations ( {
78+ identifier : "worktree.list" ,
79+ summary : "List worktrees" ,
80+ description : "List all sandbox worktrees for the current project." ,
81+ } ) ,
82+ ) ,
6983 HttpApiEndpoint . get ( "resource" , ExperimentalPaths . resource , {
7084 success : Schema . Record ( Schema . String , MCP . Resource ) ,
7185 } ) . annotateMerge (
@@ -97,6 +111,7 @@ export const experimentalHandlers = Layer.unwrap(
97111 const account = yield * Account . Service
98112 const config = yield * Config . Service
99113 const mcp = yield * MCP . Service
114+ const project = yield * Project . Service
100115 const registry = yield * ToolRegistry . Service
101116
102117 const getConsole = Effect . fn ( "ExperimentalHttpApi.console" ) ( function * ( ) {
@@ -139,6 +154,11 @@ export const experimentalHandlers = Layer.unwrap(
139154 return yield * registry . ids ( )
140155 } )
141156
157+ const worktree = Effect . fn ( "ExperimentalHttpApi.worktree" ) ( function * ( ) {
158+ const ctx = yield * InstanceState . context
159+ return yield * project . sandboxes ( ctx . project . id )
160+ } )
161+
142162 const resource = Effect . fn ( "ExperimentalHttpApi.resource" ) ( function * ( ) {
143163 return yield * mcp . resources ( )
144164 } )
@@ -148,12 +168,14 @@ export const experimentalHandlers = Layer.unwrap(
148168 . handle ( "console" , getConsole )
149169 . handle ( "consoleOrgs" , listConsoleOrgs )
150170 . handle ( "toolIDs" , toolIDs )
171+ . handle ( "worktree" , worktree )
151172 . handle ( "resource" , resource ) ,
152173 )
153174 } ) ,
154175) . pipe (
155176 Layer . provide ( Account . defaultLayer ) ,
156177 Layer . provide ( Config . defaultLayer ) ,
157178 Layer . provide ( MCP . defaultLayer ) ,
179+ Layer . provide ( Project . defaultLayer ) ,
158180 Layer . provide ( ToolRegistry . defaultLayer ) ,
159181)
0 commit comments