Skip to content

Add WSL invocation support to zoekt-manager.js for Windows #27

@Joxx0r

Description

@Joxx0r

Problem

On Windows, Zoekt binaries cannot be compiled natively (unix.Umask undefined in Go build). Zoekt only works reliably inside WSL2. The embark-claude-code installer (v0.5.3+) now installs Zoekt exclusively via WSL on Windows and generates config.json with zoekt.wsl: true.

However, zoekt-manager.js currently spawns Zoekt binaries directly via child_process.spawn(), which doesn't work for WSL-installed binaries when the Node.js service runs on Windows.

Required Changes

When config.zoekt.wsl is true, the zoekt-manager should:

1. Constructor

Add this.wslMode = config.wsl || false; property.

2. _findBinaries()

Detect WSL binaries:

if (this.wslMode) {
  try {
    const wslPath = execSync('wsl -d Ubuntu -- which zoekt-index', { encoding: 'utf-8' }).trim();
    if (wslPath) {
      this.zoektIndexPath = wslPath;
      this.zoektWebPath = wslPath.replace('zoekt-index', 'zoekt-webserver');
      return true;
    }
  } catch {}
}

3. _spawn(binaryPath, args)

Wrap invocations through WSL with Windows→WSL path conversion:

_spawn(binaryPath, args) {
  if (this.wslMode) {
    const wslArgs = args.map(a => this._toWslPath(a));
    return spawn('wsl', ['-d', 'Ubuntu', '--', binaryPath, ...wslArgs], {
      stdio: ['ignore', 'pipe', 'pipe']
    });
  }
  return spawn(binaryPath, args, { stdio: ['ignore', 'pipe', 'pipe'] });
}

_toWslPath(p) {
  const m = p.match(/^([A-Za-z]):\(.*)$/);
  if (m) return `/mnt/${m[1].toLowerCase()}/${m[2].replace(/\/g, '/')}`;
  return p;
}

4. _killStaleWebservers()

Use WSL-wrapped pkill:

if (this.wslMode) {
  execSync('wsl -d Ubuntu -- pkill -9 -f zoekt-webserver 2>/dev/null', { stdio: 'ignore', timeout: 5000 });
}

5. HTTP health checks

No change needed — http://127.0.0.1:6070 works across the WSL2/Windows boundary.

Context

  • The embark-claude-code installer generates zoekt.wsl: true in config.json when running on Windows
  • The Node.js service runs on Windows, Zoekt processes run inside WSL
  • Mirror and index directories are on the Windows filesystem, accessible from WSL at /mnt/c/...
  • Path conversion (C:\foo\bar/mnt/c/foo/bar) is critical for -index and -listen arguments

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions