Преглед на файлове

fix(multiplexer): restore tmux -V verification and fix findBinary logging

- Add optional verify parameter to shared findBinary (default false)
- Tmux adapter passes verify: true to restore pre-refactor safety check
- Fix log messages to use cmd variable instead of hardcoded 'which'
Michael Henke преди 1 месец
родител
ревизия
972efd4710
променени са 2 файла, в които са добавени 31 реда и са изтрити 3 реда
  1. 30 2
      src/multiplexer/shared.ts
  2. 1 1
      src/multiplexer/tmux/index.ts

+ 30 - 2
src/multiplexer/shared.ts

@@ -28,7 +28,10 @@ export function buildOpencodeAttachCommand(
   ].join(' ');
 }
 
-export async function findBinary(binaryName: string): Promise<string | null> {
+export async function findBinary(
+  binaryName: string,
+  options: { verify?: boolean } = {},
+): Promise<string | null> {
   const isWindows = process.platform === 'win32';
   const cmd = isWindows ? 'where' : 'which';
   const logPrefix = `[${binaryName}]`;
@@ -41,7 +44,7 @@ export async function findBinary(binaryName: string): Promise<string | null> {
 
     const exitCode = await proc.exited;
     if (exitCode !== 0) {
-      log(`${logPrefix} findBinary: 'which ${binaryName}' failed`, {
+      log(`${logPrefix} findBinary: '${cmd} ${binaryName}' failed`, {
         exitCode,
       });
       return null;
@@ -55,6 +58,31 @@ export async function findBinary(binaryName: string): Promise<string | null> {
     }
 
     log(`${logPrefix} findBinary: found`, { path });
+
+    // Verify the binary works if requested
+    if (options.verify) {
+      try {
+        const verifyProc = crossSpawn([path, '-V'], {
+          stdout: 'pipe',
+          stderr: 'pipe',
+        });
+        const verifyExitCode = await verifyProc.exited;
+        if (verifyExitCode !== 0) {
+          log(`${logPrefix} findBinary: verification failed for ${path}`);
+          return null;
+        }
+        const verifyStdout = await verifyProc.stdout();
+        log(`${logPrefix} findBinary: verified`, {
+          version: verifyStdout.trim(),
+        });
+      } catch (verifyErr) {
+        log(`${logPrefix} findBinary: verification exception`, {
+          error: String(verifyErr),
+        });
+        return null;
+      }
+    }
+
     return path;
   } catch (err) {
     log(`${logPrefix} findBinary: exception`, { error: String(err) });

+ 1 - 1
src/multiplexer/tmux/index.ts

@@ -31,7 +31,7 @@ export class TmuxMultiplexer implements Multiplexer {
       return this.binaryPath !== null;
     }
 
-    this.binaryPath = await findBinary('tmux');
+    this.binaryPath = await findBinary('tmux', { verify: true });
     this.hasChecked = true;
     return this.binaryPath !== null;
   }