Address CodeRabbit review: harden port parsing and shortcut creation

- install.ps1: wrap desktop shortcut creation in try/catch so a COM
  failure doesn't abort the whole installer (ErrorActionPreference=Stop)
- start.ps1: coerce dashboard.port to int on the Python side so a float
  value in settings.json doesn't crash the [int] cast
- start.sh: fail loudly with a clear error if no free port is found in
  20 attempts, instead of silently launching on an unverified port
This commit is contained in:
Claude 2026-07-05 21:49:19 +00:00
parent f22b44a000
commit 9c1cac130a
3 changed files with 20 additions and 9 deletions

View File

@ -78,14 +78,18 @@ if (-not (Test-Path .git)) {
$launcher = Join-Path $PSScriptRoot "Launch-Dashboard.bat"
$desktop = [Environment]::GetFolderPath("Desktop")
if ((Test-Path $launcher) -and (Test-Path $desktop)) {
$shortcutPath = Join-Path $desktop "Agentic OS Dashboard.lnk"
$shell = New-Object -ComObject WScript.Shell
$shortcut = $shell.CreateShortcut($shortcutPath)
$shortcut.TargetPath = $launcher
$shortcut.WorkingDirectory = $PSScriptRoot
$shortcut.Description = "Launch the Agentic OS dashboard"
$shortcut.Save()
Write-Host "Desktop shortcut created: $shortcutPath"
try {
$shortcutPath = Join-Path $desktop "Agentic OS Dashboard.lnk"
$shell = New-Object -ComObject WScript.Shell
$shortcut = $shell.CreateShortcut($shortcutPath)
$shortcut.TargetPath = $launcher
$shortcut.WorkingDirectory = $PSScriptRoot
$shortcut.Description = "Launch the Agentic OS dashboard"
$shortcut.Save()
Write-Host "Desktop shortcut created: $shortcutPath"
} catch {
Write-Warning "Could not create Desktop shortcut: $_"
}
}
Write-Host ""

View File

@ -36,7 +36,7 @@ $pythonArgs = @($python.Args)
& $pythonCommand @pythonArgs -m pip install -r requirements.txt --quiet
$configuredPort = & $pythonCommand @pythonArgs -c "import json; f=open('data/settings.json'); d=json.load(f); print(d.get('dashboard',{}).get('port',8080)); f.close()" 2>$null
$configuredPort = & $pythonCommand @pythonArgs -c "import json; f=open('data/settings.json'); d=json.load(f); print(int(d.get('dashboard',{}).get('port',8080))); f.close()" 2>$null
if (-not $configuredPort) { $configuredPort = "8080" }
$configuredPort = [int]$configuredPort

View File

@ -28,14 +28,21 @@ CONFIGURED_PORT=$($PYTHON -c "import json; f=open('data/settings.json'); d=json.
# Find a free port starting at CONFIGURED_PORT (in case it's already taken by another app)
PORT="$CONFIGURED_PORT"
FOUND=0
for _ in $(seq 1 20); do
if ! (exec 3<>"/dev/tcp/127.0.0.1/${PORT}") 2>/dev/null; then
FOUND=1
break
fi
exec 3>&- 2>/dev/null || true
PORT=$((PORT + 1))
done
if [ "$FOUND" -eq 0 ]; then
echo "ERROR: Could not find a free port after 20 attempts starting at ${CONFIGURED_PORT}."
exit 1
fi
if [ "$PORT" != "$CONFIGURED_PORT" ]; then
echo "WARNING: Port ${CONFIGURED_PORT} is already in use - using ${PORT} instead."
fi