From 9c1cac130a5dcfe10c556b5e4c13a49128fa829e Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 5 Jul 2026 21:49:19 +0000 Subject: [PATCH] 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 --- install.ps1 | 20 ++++++++++++-------- start.ps1 | 2 +- start.sh | 7 +++++++ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/install.ps1 b/install.ps1 index 0645188..a9bab85 100644 --- a/install.ps1 +++ b/install.ps1 @@ -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 "" diff --git a/start.ps1 b/start.ps1 index a30da8b..a6da799 100644 --- a/start.ps1 +++ b/start.ps1 @@ -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 diff --git a/start.sh b/start.sh index a143397..4dd584d 100755 --- a/start.sh +++ b/start.sh @@ -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