<# .SYNOPSIS One scan run, suitable for Task Scheduler or manual use. .DESCRIPTION Wraps scan_deepseek.py so that a scheduled run needs no interactive input: the GitHub token comes from a file outside the repo, results go to a dated log, and the state file makes every run a delta (only new findings are called out). The scanner never touches the DeepSeek API. It reads public GitHub data only. .PARAMETER Out Output directory. Default: .\out next to this script. .PARAMETER TokenFile File holding the GitHub token. Default: ~\.gh\deepseek-leakscan.token .PARAMETER MaxPages Search pages per query (100 results each). .EXAMPLE .\run_scan.ps1 .\run_scan.ps1 -MaxPages 5 -MinScore 6 #> [CmdletBinding()] param( [string]$Out = '', [string]$TokenFile = '', [int]$MaxPages = 3, [int]$MinScore = 5, [switch]$NewOnly ) $ErrorActionPreference = 'Stop' # $PSScriptRoot is not populated while [CmdletBinding()] binds parameters, so # defaults are resolved here instead. if (-not $Out) { $Out = Join-Path $PSScriptRoot 'out' } if (-not $TokenFile) { $TokenFile = Join-Path $env:USERPROFILE '.gh\deepseek-leakscan.token' } $scanner = Join-Path $PSScriptRoot 'scan_deepseek.py' $logDir = Join-Path $Out 'logs' New-Item -ItemType Directory -Force -Path $logDir | Out-Null $log = Join-Path $logDir ("scan-{0:yyyyMMdd-HHmmss}.log" -f (Get-Date)) function Write-Log([string]$Message) { $line = "[{0:yyyy-MM-dd HH:mm:ss}] {1}" -f (Get-Date), $Message Write-Host $line Add-Content -Path $log -Value $line -Encoding utf8 } # --- prerequisites --------------------------------------------------------- if (-not (Test-Path $scanner)) { Write-Log 'FATAL: scan_deepseek.py not found next to run_scan.ps1' exit 2 } if (-not (Test-Path $TokenFile)) { Write-Log "FATAL: token file not found: $TokenFile" Write-Log 'Create it once, outside any repository, and restrict it:' Write-Log ' New-Item -ItemType Directory -Force "$env:USERPROFILE\.gh" | Out-Null' Write-Log ' "github_pat_..." | Set-Content -NoNewline "$env:USERPROFILE\.gh\deepseek-leakscan.token"' Write-Log ' icacls "$env:USERPROFILE\.gh\deepseek-leakscan.token" /inheritance:r /grant:r "$($env:USERNAME):(R)"' exit 2 } $python = $null foreach ($name in @('python', 'python3', 'py')) { $cmd = Get-Command $name -ErrorAction SilentlyContinue if ($cmd) { $python = $cmd.Source; break } } if (-not $python) { $found = Get-ChildItem "$env:LOCALAPPDATA\Programs\Python\Python*\python.exe" -ErrorAction SilentlyContinue | Sort-Object FullName -Descending | Select-Object -First 1 if ($found) { $python = $found.FullName } } if (-not $python) { Write-Log 'FATAL: python not found (PATH, or %LOCALAPPDATA%\Programs\Python)' exit 2 } # --- run ------------------------------------------------------------------- $scanArgs = @( $scanner, '--out', $Out, '--token-file', $TokenFile, '--state', (Join-Path $Out 'state.json'), '--max-pages', $MaxPages, '--min-score', $MinScore, '--resolve-contacts' ) if ($NewOnly) { $scanArgs += '--new-only' } Write-Log "python : $python" Write-Log "output : $Out" Write-Log "max pages : $MaxPages min score : $MinScore new-only : $([bool]$NewOnly)" Write-Log 'starting scan' & $python @scanArgs 2>&1 | ForEach-Object { Write-Host $_ Add-Content -Path $log -Value $_ -Encoding utf8 } $code = $LASTEXITCODE if ($code -eq 0) { $report = Join-Path $Out 'report.md' if (Test-Path $report) { $text = Get-Content $report -Raw if ($text -match 'Candidates: \*\*(\d+)\*\* in \*\*(\d+)\*\*') { Write-Log ('done: {0} candidate(s) in {1} repo(s)' -f $Matches[1], $Matches[2]) } else { Write-Log 'done' } Write-Log "report: $report" } } else { Write-Log "scan exited with code $code" } Write-Log "log: $log" exit $code