@@ -27,25 +27,32 @@ const ALLOWED_TLON_COMMANDS = new Set([
2727/**
2828 * Find the tlon binary from the skill package
2929 */
30+ let cachedTlonBinary : string | undefined ;
31+
3032function findTlonBinary ( ) : string {
33+ if ( cachedTlonBinary ) {
34+ return cachedTlonBinary ;
35+ }
3136 // Check in node_modules/.bin
3237 const skillBin = join ( __dirname , "node_modules" , ".bin" , "tlon" ) ;
33- console . log ( `[tlon] Checking for binary at: ${ skillBin } , exists: ${ existsSync ( skillBin ) } ` ) ;
34- if ( existsSync ( skillBin ) ) return skillBin ;
38+ if ( existsSync ( skillBin ) ) {
39+ cachedTlonBinary = skillBin ;
40+ return skillBin ;
41+ }
3542
3643 // Check for platform-specific binary directly
3744 const platform = process . platform ;
3845 const arch = process . arch ;
3946 const platformPkg = `@tloncorp/tlon-skill-${ platform } -${ arch } ` ;
4047 const platformBin = join ( __dirname , "node_modules" , platformPkg , "tlon" ) ;
41- console . log (
42- `[tlon] Checking for platform binary at: ${ platformBin } , exists: ${ existsSync ( platformBin ) } ` ,
43- ) ;
44- if ( existsSync ( platformBin ) ) return platformBin ;
48+ if ( existsSync ( platformBin ) ) {
49+ cachedTlonBinary = platformBin ;
50+ return platformBin ;
51+ }
4552
4653 // Fallback to PATH
47- console . log ( `[tlon] Falling back to PATH lookup for ' tlon'` ) ;
48- return "tlon" ;
54+ cachedTlonBinary = " tlon" ;
55+ return cachedTlonBinary ;
4956}
5057
5158/**
@@ -132,9 +139,7 @@ const plugin = {
132139 setTlonRuntime ( api . runtime ) ;
133140 api . registerChannel ( { plugin : tlonPlugin } ) ;
134141
135- // Register the tlon tool
136- const tlonBinary = findTlonBinary ( ) ;
137- api . logger . info ( `[tlon] Registering tlon tool, binary: ${ tlonBinary } ` ) ;
142+ api . logger . debug ?.( "[tlon] Registering tlon tool" ) ;
138143 api . registerTool ( {
139144 name : "tlon" ,
140145 label : "Tlon CLI" ,
@@ -156,6 +161,7 @@ const plugin = {
156161 async execute ( _id : string , params : { command : string } ) {
157162 try {
158163 const args = shellSplit ( params . command ) ;
164+ const tlonBinary = findTlonBinary ( ) ;
159165
160166 // Validate first argument is a whitelisted tlon subcommand
161167 const subcommand = args [ 0 ] ;
0 commit comments