@@ -9,6 +9,7 @@ import * as InstanceState from "@/effect/instance-state"
99import { Effect , Layer , Schema } from "effect"
1010import { HttpApi , HttpApiBuilder , HttpApiEndpoint , HttpApiGroup , OpenApi } from "effect/unstable/httpapi"
1111import { Authorization } from "./auth"
12+ import { markInstanceForDisposal } from "./lifecycle"
1213
1314const PathInfo = Schema . Struct ( {
1415 home : Schema . String ,
@@ -23,6 +24,7 @@ const VcsDiffQuery = Schema.Struct({
2324} )
2425
2526export const InstancePaths = {
27+ dispose : "/instance/dispose" ,
2628 path : "/path" ,
2729 vcs : "/vcs" ,
2830 vcsDiff : "/vcs/diff" ,
@@ -37,6 +39,15 @@ export const InstanceApi = HttpApi.make("instance")
3739 . add (
3840 HttpApiGroup . make ( "instance" )
3941 . add (
42+ HttpApiEndpoint . post ( "dispose" , InstancePaths . dispose , {
43+ success : Schema . Boolean ,
44+ } ) . annotateMerge (
45+ OpenApi . annotations ( {
46+ identifier : "instance.dispose" ,
47+ summary : "Dispose instance" ,
48+ description : "Clean up and dispose the current OpenCode instance, releasing all resources." ,
49+ } ) ,
50+ ) ,
4051 HttpApiEndpoint . get ( "path" , InstancePaths . path , {
4152 success : PathInfo ,
4253 } ) . annotateMerge (
@@ -138,6 +149,11 @@ export const instanceHandlers = Layer.unwrap(
138149 const skill = yield * Skill . Service
139150 const vcs = yield * Vcs . Service
140151
152+ const dispose = Effect . fn ( "InstanceHttpApi.dispose" ) ( function * ( ) {
153+ yield * markInstanceForDisposal ( yield * InstanceState . context )
154+ return true
155+ } )
156+
141157 const getPath = Effect . fn ( "InstanceHttpApi.path" ) ( function * ( ) {
142158 const ctx = yield * InstanceState . context
143159 return {
@@ -180,6 +196,7 @@ export const instanceHandlers = Layer.unwrap(
180196
181197 return HttpApiBuilder . group ( InstanceApi , "instance" , ( handlers ) =>
182198 handlers
199+ . handle ( "dispose" , dispose )
183200 . handle ( "path" , getPath )
184201 . handle ( "vcs" , getVcs )
185202 . handle ( "vcsDiff" , getVcsDiff )
0 commit comments