Skip to content

Latest commit

 

History

History
432 lines (297 loc) · 9.81 KB

File metadata and controls

432 lines (297 loc) · 9.81 KB

Windows Setup Guide

This guide covers setting up Code Scanner on Windows.

Python Installation

Option 1: Microsoft Store (Recommended for beginners)

  1. Open Microsoft Store
  2. Search for "Python 3.12"
  3. Click "Install"
  4. Open PowerShell and verify: python --version

Option 2: python.org Installer

  1. Download from python.org
  2. Run the installer
  3. Important: Check "Add Python to PATH" during installation
  4. Complete installation

Verify Installation

Open PowerShell or Command Prompt:

python --version   # Should be 3.10 or higher
pip --version

UV Installation

Open PowerShell as Administrator:

# Install UV
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

# Restart PowerShell, then verify
uv --version

Git Installation

If Git isn't already installed:

  1. Download from git-scm.com
  2. Run the installer
  3. Use default options (Git Bash is recommended)

Verify installation:

git --version

Universal Ctags Installation

Universal Ctags is required for symbol indexing, which enables AI tools to efficiently navigate your codebase.

Option 1: Using Chocolatey (Recommended)

If you have Chocolatey installed:

# Open PowerShell as Administrator
choco install universal-ctags

# Verify installation
ctags --version

Option 2: Using Scoop

If you have Scoop installed:

scoop install universal-ctags
ctags --version

Option 3: Manual Installation

  1. Download from Universal Ctags GitHub releases
  2. Extract to a folder (e.g., C:\Program Files\ctags)
  3. Add the folder to your PATH:
    • Open System Properties → Advanced → Environment Variables
    • Edit PATH and add the ctags folder
  4. Restart PowerShell and verify: ctags --version

Note: Make sure it shows "Universal Ctags" (not "Exuberant Ctags").

Ripgrep Installation

Ripgrep is required for fast code search across the repository.

Option 1: Using Chocolatey (Recommended)

# Open PowerShell as Administrator
choco install ripgrep

# Verify installation
rg --version

Option 2: Using Scoop

scoop install ripgrep
rg --version

Option 3: Using Winget

winget install BurntSushi.ripgrep
rg --version

Option 4: Manual Installation

  1. Download from ripgrep GitHub releases
  2. Extract to a folder (e.g., C:\Program Files\ripgrep)
  3. Add the folder to your PATH
  4. Restart PowerShell and verify: rg --version

Code Scanner Installation

Open PowerShell or Git Bash:

# Clone the repository
git clone https://github.com/ubego/Code-Scanner.git
cd code-scanner

# Install dependencies with UV
uv sync

# Verify installation
uv run code-scanner --help

LLM Backend Setup

Choose one of the following backends:

Option 1: Ollama

Ollama now supports Windows natively.

  1. Download from ollama.ai/download
  2. Run the installer
  3. Ollama starts automatically

Open PowerShell:

# Pull a model
ollama pull qwen3:4b

# Verify it's working
ollama list

# Test the API
curl http://localhost:11434/api/tags
# Or with PowerShell:
Invoke-WebRequest http://localhost:11434/api/tags

Configuration for Ollama:

Copy a language-specific example (e.g., sample_configs/python-config.toml) and update the [llm] section:

[llm]
backend = "ollama"
host = "localhost"
port = 11434
model = "qwen3:4b"
timeout = 120
context_limit = 16384  # Required

Option 2: LM Studio

LM Studio provides a user-friendly Windows application.

  1. Download from lmstudio.ai
  2. Run the installer
  3. Launch LM Studio

In LM Studio:

  1. Search for "qwen2.5-coder-7b-instruct"
  2. Download the model
  3. Load the model
  4. Go to "Local Server" tab (click the "<->" icon)
  5. Set "Context Length" to at least 16384 in the right sidebar
  6. Click "Start Server" (default port: 1234)

Configuration for LM Studio:

Copy a language-specific example (e.g., sample_configs/python-config.toml) and update the [llm] section:

[llm]
backend = "lm-studio"
host = "localhost"
port = 1234
timeout = 120
context_limit = 16384  # Required

Running Code Scanner

Using PowerShell

# Navigate to your project
cd C:\path\to\your\project

# Create code_scanner_config.toml (copy from examples)
Copy-Item C:\path\to\code-scanner\examples\python-config.toml code_scanner_config.toml

# Edit code_scanner_config.toml with your preferred editor
notepad code_scanner_config.toml

# Run the scanner (runs continuously until Ctrl+C)
uv run code-scanner

Using Git Bash

# Navigate to your project
cd /c/path/to/your/project

# Create code_scanner_config.toml
cp /c/path/to/code-scanner/sample_configs/python-config.toml code_scanner_config.toml

# Run the scanner
uv run code-scanner

Using Command Prompt (cmd)

:: Navigate to your project
cd C:\path\to\your\project

:: Run the scanner
uv run code-scanner

GPU Acceleration

NVIDIA GPUs

LM Studio and Ollama can use NVIDIA GPUs for faster inference:

  1. Install NVIDIA CUDA Toolkit
  2. Install latest NVIDIA drivers
  3. In LM Studio, enable GPU acceleration in settings
  4. Ollama automatically uses CUDA if available

AMD GPUs

  • LM Studio supports AMD GPUs via ROCm
  • Ollama support for AMD is limited on Windows

Running as a Background Service

You can configure Code Scanner to start automatically on login using Windows Task Scheduler.

Prerequisites

  • Code Scanner installed and working via command line
  • LLM backend (Ollama or LM Studio) installed
  • PowerShell or Command Prompt with administrator access (for some operations)

Quick Setup

Run the autostart script by double-clicking or from Command Prompt:

scripts\autostart-windows.bat

The script will interactively guide you through:

  1. Project path - The directory to scan
  2. Config file path - Your code_scanner_config.toml location
  3. Test launch - Verifies the scanner works before registering
  4. Task Scheduler registration - Creates a login task

What the Script Does

  1. Detects legacy tasks and offers to remove them
  2. Validates paths for project and config file
  3. Test launches the scanner to verify configuration
  4. Creates wrapper script at %USERPROFILE%\.code-scanner\launch-wrapper.bat
  5. Creates scheduled task named "CodeScanner" via Task Scheduler
  6. Configures login trigger to start on user logon
  7. Includes 60-second delay to allow LLM backend startup

Managing the Service

REM Check status
schtasks /query /tn "CodeScanner"

REM Run manually
schtasks /run /tn "CodeScanner"

REM Stop
schtasks /end /tn "CodeScanner"

REM Remove completely
schtasks /delete /tn "CodeScanner" /f
del "%USERPROFILE%\.code-scanner\launch-wrapper.bat"

Using Task Scheduler GUI

You can also manage the task via the graphical interface:

  1. Press Win + R, type taskschd.msc, press Enter
  2. Find "CodeScanner" in the task list
  3. Right-click to Run, End, Disable, or Delete

Autostart Log Files

  • Scanner log: %USERPROFILE%\.code-scanner\code_scanner.log
  • Results: <project>\code_scanner_results.md

Autostart Troubleshooting

Task won't start:

  1. Check scanner log: type %USERPROFILE%\.code-scanner\code_scanner.log
  2. Verify config file path is correct
  3. Ensure LLM backend is running
  4. Open Task Scheduler and check the task's "History" tab

Lock file errors: Another instance may be running. Check with:

type %USERPROFILE%\.code-scanner\code_scanner.lock
tasklist | findstr code-scanner

Delete stale lock if needed:

del %USERPROFILE%\.code-scanner\code_scanner.lock

Permission issues: If the task fails to create, try running Command Prompt as Administrator:

  1. Right-click Command Prompt
  2. Select "Run as administrator"
  3. Navigate to the code-scanner directory
  4. Run the autostart script again

Troubleshooting

"python is not recognized"

Python isn't in your PATH. Either:

  • Reinstall Python with "Add to PATH" checked
  • Add Python manually to PATH:
    1. Search "Environment Variables" in Start
    2. Edit PATH
    3. Add Python installation directory (e.g., C:\Users\YourName\AppData\Local\Programs\Python\Python312)

"uv is not recognized"

Restart PowerShell after UV installation. If still not working:

# Check UV location
$env:USERPROFILE\.local\bin\uv.exe --version

# Add to PATH manually
$env:PATH += ";$env:USERPROFILE\.local\bin"

Firewall blocking connections

Windows Firewall may block LLM backends:

  1. Open Windows Security
  2. Firewall & network protection
  3. Allow an app through firewall
  4. Add LM Studio or Ollama

Antivirus interference

Some antivirus software may slow down or block the scanner:

  • Add code-scanner directory to exclusions
  • Add LM Studio/Ollama to exclusions

Long path issues

If you see path-related errors:

  1. Open Group Policy Editor (gpedit.msc)
  2. Navigate to: Computer Configuration > Administrative Templates > System > Filesystem
  3. Enable "Enable Win32 long paths"
  4. Restart your computer

PowerShell script execution policy

If you see "execution of scripts is disabled":

# Run as Administrator
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Connection refused errors

# Check if Ollama is running
Get-Process ollama

# Check if LM Studio server is running
Test-NetConnection -ComputerName localhost -Port 1234

# For Ollama
Test-NetConnection -ComputerName localhost -Port 11434