@@ -50,32 +50,40 @@ const plugin: Plugin = (async (ctx) => {
5050 logger ,
5151 config
5252 ) ,
53- tool : ( config . strategies . discardTool . enabled || config . strategies . extractTool . enabled ) ? {
54- discard : createDiscardTool ( {
55- client : ctx . client ,
56- state,
57- logger,
58- config,
59- workingDirectory : ctx . directory
53+ tool : {
54+ ...( config . strategies . discardTool . enabled && {
55+ discard : createDiscardTool ( {
56+ client : ctx . client ,
57+ state,
58+ logger,
59+ config,
60+ workingDirectory : ctx . directory
61+ } ) ,
6062 } ) ,
61- extract : createExtractTool ( {
62- client : ctx . client ,
63- state,
64- logger,
65- config,
66- workingDirectory : ctx . directory
63+ ...( config . strategies . extractTool . enabled && {
64+ extract : createExtractTool ( {
65+ client : ctx . client ,
66+ state,
67+ logger,
68+ config,
69+ workingDirectory : ctx . directory
70+ } ) ,
6771 } ) ,
68- } : undefined ,
72+ } ,
6973 config : async ( opencodeConfig ) => {
70- // Add discard and extract to primary_tools by mutating the opencode config
74+ // Add enabled tools to primary_tools by mutating the opencode config
7175 // This works because config is cached and passed by reference
72- if ( config . strategies . discardTool . enabled || config . strategies . extractTool . enabled ) {
76+ const toolsToAdd : string [ ] = [ ]
77+ if ( config . strategies . discardTool . enabled ) toolsToAdd . push ( "discard" )
78+ if ( config . strategies . extractTool . enabled ) toolsToAdd . push ( "extract" )
79+
80+ if ( toolsToAdd . length > 0 ) {
7381 const existingPrimaryTools = opencodeConfig . experimental ?. primary_tools ?? [ ]
7482 opencodeConfig . experimental = {
7583 ...opencodeConfig . experimental ,
76- primary_tools : [ ...existingPrimaryTools , "discard" , "extract" ] ,
84+ primary_tools : [ ...existingPrimaryTools , ... toolsToAdd ] ,
7785 }
78- logger . info ( " Added 'discard' and 'extract' to experimental.primary_tools via config mutation" )
86+ logger . info ( ` Added ${ toolsToAdd . map ( t => `' ${ t } '` ) . join ( " and " ) } to experimental.primary_tools via config mutation` )
7987 }
8088 } ,
8189 event : createEventHandler ( ctx . client , config , state , logger , ctx . directory ) ,
0 commit comments