@@ -4,6 +4,7 @@ import { InstanceState } from "@/effect"
44import { MCP } from "@/mcp"
55import { Project } from "@/project"
66import { ToolRegistry } from "@/tool"
7+ import { Worktree } from "@/worktree"
78import { Effect , Layer , Option , Schema } from "effect"
89import { HttpApi , HttpApiBuilder , HttpApiEndpoint , HttpApiGroup , OpenApi } from "effect/unstable/httpapi"
910import { Authorization } from "./auth"
@@ -36,6 +37,7 @@ export const ExperimentalPaths = {
3637 consoleOrgs : "/experimental/console/orgs" ,
3738 toolIDs : "/experimental/tool/ids" ,
3839 worktree : "/experimental/worktree" ,
40+ worktreeReset : "/experimental/worktree/reset" ,
3941 resource : "/experimental/resource" ,
4042} as const
4143
@@ -80,6 +82,36 @@ export const ExperimentalApi = HttpApi.make("experimental")
8082 description : "List all sandbox worktrees for the current project." ,
8183 } ) ,
8284 ) ,
85+ HttpApiEndpoint . post ( "worktreeCreate" , ExperimentalPaths . worktree , {
86+ payload : Schema . optional ( Worktree . CreateInput ) ,
87+ success : Worktree . Info ,
88+ } ) . annotateMerge (
89+ OpenApi . annotations ( {
90+ identifier : "worktree.create" ,
91+ summary : "Create worktree" ,
92+ description : "Create a new git worktree for the current project and run any configured startup scripts." ,
93+ } ) ,
94+ ) ,
95+ HttpApiEndpoint . delete ( "worktreeRemove" , ExperimentalPaths . worktree , {
96+ payload : Worktree . RemoveInput ,
97+ success : Schema . Boolean ,
98+ } ) . annotateMerge (
99+ OpenApi . annotations ( {
100+ identifier : "worktree.remove" ,
101+ summary : "Remove worktree" ,
102+ description : "Remove a git worktree and delete its branch." ,
103+ } ) ,
104+ ) ,
105+ HttpApiEndpoint . post ( "worktreeReset" , ExperimentalPaths . worktreeReset , {
106+ payload : Worktree . ResetInput ,
107+ success : Schema . Boolean ,
108+ } ) . annotateMerge (
109+ OpenApi . annotations ( {
110+ identifier : "worktree.reset" ,
111+ summary : "Reset worktree" ,
112+ description : "Reset a worktree branch to the primary default branch." ,
113+ } ) ,
114+ ) ,
83115 HttpApiEndpoint . get ( "resource" , ExperimentalPaths . resource , {
84116 success : Schema . Record ( Schema . String , MCP . Resource ) ,
85117 } ) . annotateMerge (
@@ -113,6 +145,7 @@ export const experimentalHandlers = Layer.unwrap(
113145 const mcp = yield * MCP . Service
114146 const project = yield * Project . Service
115147 const registry = yield * ToolRegistry . Service
148+ const worktreeSvc = yield * Worktree . Service
116149
117150 const getConsole = Effect . fn ( "ExperimentalHttpApi.console" ) ( function * ( ) {
118151 const [ state , groups ] = yield * Effect . all (
@@ -159,6 +192,28 @@ export const experimentalHandlers = Layer.unwrap(
159192 return yield * project . sandboxes ( ctx . project . id )
160193 } )
161194
195+ const worktreeCreate = Effect . fn ( "ExperimentalHttpApi.worktreeCreate" ) ( function * ( ctx : {
196+ payload : Worktree . CreateInput | undefined
197+ } ) {
198+ return yield * worktreeSvc . create ( ctx . payload )
199+ } )
200+
201+ const worktreeRemove = Effect . fn ( "ExperimentalHttpApi.worktreeRemove" ) ( function * ( input : {
202+ payload : Worktree . RemoveInput
203+ } ) {
204+ const ctx = yield * InstanceState . context
205+ yield * worktreeSvc . remove ( input . payload )
206+ yield * project . removeSandbox ( ctx . project . id , input . payload . directory )
207+ return true
208+ } )
209+
210+ const worktreeReset = Effect . fn ( "ExperimentalHttpApi.worktreeReset" ) ( function * ( ctx : {
211+ payload : Worktree . ResetInput
212+ } ) {
213+ yield * worktreeSvc . reset ( ctx . payload )
214+ return true
215+ } )
216+
162217 const resource = Effect . fn ( "ExperimentalHttpApi.resource" ) ( function * ( ) {
163218 return yield * mcp . resources ( )
164219 } )
@@ -169,6 +224,9 @@ export const experimentalHandlers = Layer.unwrap(
169224 . handle ( "consoleOrgs" , listConsoleOrgs )
170225 . handle ( "toolIDs" , toolIDs )
171226 . handle ( "worktree" , worktree )
227+ . handle ( "worktreeCreate" , worktreeCreate )
228+ . handle ( "worktreeRemove" , worktreeRemove )
229+ . handle ( "worktreeReset" , worktreeReset )
172230 . handle ( "resource" , resource ) ,
173231 )
174232 } ) ,
@@ -178,4 +236,5 @@ export const experimentalHandlers = Layer.unwrap(
178236 Layer . provide ( MCP . defaultLayer ) ,
179237 Layer . provide ( Project . defaultLayer ) ,
180238 Layer . provide ( ToolRegistry . defaultLayer ) ,
239+ Layer . provide ( Worktree . defaultLayer ) ,
181240)
0 commit comments