Public/New-BykaCCSupervisorLauncher.ps1
|
function New-BykaCCSupervisorLauncher { <# .SYNOPSIS Generates a .bat launcher that starts BykaCCSupervisor in a minimized pwsh window. .DESCRIPTION Writes a Windows batch file at -Path that, when executed, launches `Start-BykaCCSupervisor -FallbackProjectDir <ProjectDir>` in a minimized PowerShell 7 window. Suitable for placement in the Windows Startup folder (shell:startup) for auto-launch at login. The generated .bat: - Requires PowerShell 7 (pwsh.exe). Fails loudly if missing. - Drops -NoExit so a clean exit closes the window. - Uses -Command to invoke the installed module (no -File path coupling). .PARAMETER Path Absolute path where the .bat will be written. Parent directory must exist. .PARAMETER ProjectDir Absolute path passed to Start-BykaCCSupervisor as -FallbackProjectDir. .EXAMPLE New-BykaCCSupervisorLauncher -Path "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Startup\Claude Code Channels.bat" -ProjectDir 'C:\Dev\byka' #> [CmdletBinding()] param( [Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$Path, [Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$ProjectDir ) $parent = Split-Path -Parent $Path if (-not (Test-Path $parent)) { throw "Parent directory does not exist: $parent" } # [G4] security F1 + code-reviewer T2-5: $ProjectDir is interpolated into a # PowerShell -Command string AND a cmd.exe `start` argument. Reject any # character that could break out of either context: # - quotes (', ", `) break the PowerShell single-quoted string # - cmd.exe metacharacters (;, &, |, ^, %, <, >) break the `start` line # or trigger env-var / pipeline expansion inside the .bat # Operators should pass a normal absolute path; anything weird gets rejected. if ($ProjectDir -match "['""``;&|^%<>]") { throw "ProjectDir contains a disallowed character: '$ProjectDir'. Use a plain absolute path without quotes / cmd-metacharacters." } $bat = @" @echo off :: Claude Code Channels - Telegram Bridge (auto-start at login) :: Generated by New-BykaCCSupervisorLauncher. :: Launches BykaCCSupervisor in a minimized PowerShell 7 (pwsh) window. set "PWSH_EXE=C:\Program Files\PowerShell\7\pwsh.exe" if not exist "%PWSH_EXE%" ( echo ERROR: PowerShell 7 not found at %PWSH_EXE% echo Install: winget install --id Microsoft.PowerShell --source winget pause exit /b 1 ) :: Probe for the BykaCCSupervisor module BEFORE launching minimized window. :: ([G4] code-reviewer T2-6 / qa F4: a missing module would otherwise flash :: an error in the minimized window which the operator never sees.) "%PWSH_EXE%" -NoLogo -NoProfile -Command "if (-not (Get-Module -ListAvailable BykaCCSupervisor)) { exit 1 }" >NUL 2>&1 if errorlevel 1 ( echo ERROR: BykaCCSupervisor module not installed. echo Install: pwsh -Command "Install-PSResource -Name BykaCCSupervisor -Repository PSGallery" pause exit /b 1 ) start "Claude Code Channels (pwsh 7)" /min "%PWSH_EXE%" -NoLogo -NoProfile -ExecutionPolicy Bypass -Command "Import-Module BykaCCSupervisor; Start-BykaCCSupervisor -FallbackProjectDir '$ProjectDir'" "@ [IO.File]::WriteAllText($Path, $bat) Write-Host "Wrote launcher: $Path" } |