File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -69,8 +69,6 @@ const opencode = await createOpencode({
6969 } ,
7070} ) ;
7171
72- process . once ( "beforeExit" , ( ) => opencode . server . close ( ) ) ;
73-
7472const sessionCache = new Map < string , string > ( ) ;
7573
7674export const models : string [ ] = [
@@ -261,6 +259,9 @@ const opencodeAgent: AgentDefinition = {
261259
262260 return { command : displayCommand , actions, usage } ;
263261 } ,
262+ cleanup ( ) {
263+ opencode . server . close ( ) ;
264+ } ,
264265} ;
265266
266267export default opencodeAgent ;
Original file line number Diff line number Diff line change @@ -595,7 +595,16 @@ main()
595595 }
596596 process . exitCode = 1 ;
597597 } )
598- . finally ( process . exit ) ;
598+ . finally ( async ( ) => {
599+ // Cleanup all loaded agents
600+ const agents = await listAgents ( ) ;
601+ for ( const agent of agents ) {
602+ if ( agent . definition . cleanup ) {
603+ await agent . definition . cleanup ( ) ;
604+ }
605+ }
606+ process . exit ( ) ;
607+ } ) ;
599608
600609function cleanupRepository ( tempDir : string , entry : DatasetEval ) : void {
601610 try {
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ export interface AgentDefinition {
2020 cwd : string ,
2121 options ?: AgentRunOptions ,
2222 ) => Promise < AgentRunResult > ;
23+ cleanup ?: ( ) => void | Promise < void > ;
2324}
2425
2526export interface AgentRunResult {
You can’t perform that action at this time.
0 commit comments