From 092317ea56208c8538b206a0e9b0e001b65d1a62 Mon Sep 17 00:00:00 2001 From: alexheifetz Date: Tue, 17 Jun 2025 14:48:10 -0400 Subject: [PATCH 1/2] Polishing of startup scripts. --- scripts/mcp_server.cmd | 12 ++--------- scripts/mcp_server.sh | 7 +++---- scripts/shell.cmd | 9 ++++++++ scripts/shell.sh | 6 ++++++ scripts/shell_docker.cmd | 12 ++--------- scripts/shell_docker.ps1 | 28 ------------------------- scripts/shell_docker.sh | 6 ++++++ scripts/support/agent.bat | 24 +++++++++++++++++++++ scripts/support/agent.sh | 35 +++++++++++++++++++++++++++++++ scripts/support/check_env.ps1 | 39 ----------------------------------- 10 files changed, 87 insertions(+), 91 deletions(-) create mode 100644 scripts/shell.cmd create mode 100644 scripts/shell.sh delete mode 100644 scripts/shell_docker.ps1 create mode 100644 scripts/shell_docker.sh create mode 100644 scripts/support/agent.bat create mode 100644 scripts/support/agent.sh delete mode 100644 scripts/support/check_env.ps1 diff --git a/scripts/mcp_server.cmd b/scripts/mcp_server.cmd index 88ae6dd..aa15519 100644 --- a/scripts/mcp_server.cmd +++ b/scripts/mcp_server.cmd @@ -1,17 +1,9 @@ @echo off setlocal -call .\support\check_env.bat - -if errorlevel 1 ( - echo Environment check failed. Exiting... - exit /b 1 -) - -cd .. - +set AGENT_APPLICATION=.. set SPRING_PROFILES_ACTIVE=web,severance -cmd /c mvn -P agent-examples-kotlin -Dmaven.test.skip=true spring-boot:run +call .\support\agent.bat endlocal \ No newline at end of file diff --git a/scripts/mcp_server.sh b/scripts/mcp_server.sh index 4304277..4170cae 100755 --- a/scripts/mcp_server.sh +++ b/scripts/mcp_server.sh @@ -1,7 +1,6 @@ #!/usr/bin/env bash -./support/check_env.sh - -cd .. +export AGENT_APPLICATION=.. export SPRING_PROFILES_ACTIVE=web,severance -mvn -P agent-examples-kotlin -Dmaven.test.skip=true spring-boot:run + +./support/agent.sh diff --git a/scripts/shell.cmd b/scripts/shell.cmd new file mode 100644 index 0000000..632b7c4 --- /dev/null +++ b/scripts/shell.cmd @@ -0,0 +1,9 @@ +@echo off +setlocal + +set AGENT_APPLICATION=.. +set SPRING_PROFILES_ACTIVE=shell,severance + +call .\support\agent.bat + +endlocal \ No newline at end of file diff --git a/scripts/shell.sh b/scripts/shell.sh new file mode 100644 index 0000000..fb849fd --- /dev/null +++ b/scripts/shell.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +export AGENT_APPLICATION=.. +export SPRING_PROFILES_ACTIVE=shell,severance + +./support/agent.sh diff --git a/scripts/shell_docker.cmd b/scripts/shell_docker.cmd index f957f91..5120e1f 100644 --- a/scripts/shell_docker.cmd +++ b/scripts/shell_docker.cmd @@ -1,17 +1,9 @@ @echo off setlocal -call .\support\check_env.bat - -if errorlevel 1 ( - echo Environment check failed. Exiting... - exit /b 1 -) - -cd .. - +set AGENT_APPLICATION=.. set SPRING_PROFILES_ACTIVE=shell,starwars,docker-desktop -cmd /c mvn -P agent-examples-kotlin -Dmaven.test.skip=true spring-boot:run +call .\support\agent.bat endlocal \ No newline at end of file diff --git a/scripts/shell_docker.ps1 b/scripts/shell_docker.ps1 deleted file mode 100644 index 471542f..0000000 --- a/scripts/shell_docker.ps1 +++ /dev/null @@ -1,28 +0,0 @@ -# Save current location and environment -Push-Location -$originalProfiles = $env:SPRING_PROFILES_ACTIVE - -try { - # Run environment check - Write-Host "Running environment check..." -ForegroundColor Cyan - & .\support\check_env.ps1 - - if ($LASTEXITCODE -ne 0) { - Write-Host "Environment check failed. Exiting..." -ForegroundColor Red - exit 1 - } - - # Change to parent directory - Set-Location .. - - # Set Spring profiles - $env:SPRING_PROFILES_ACTIVE = "shell,starwars,docker-desktop" - - # Run Maven in subprocess - cmd /c "mvn -Dmaven.test.skip=true spring-boot:run" -} -finally { - # Restore original environment and location - $env:SPRING_PROFILES_ACTIVE = $originalProfiles - Pop-Location -} \ No newline at end of file diff --git a/scripts/shell_docker.sh b/scripts/shell_docker.sh new file mode 100644 index 0000000..f3d5b46 --- /dev/null +++ b/scripts/shell_docker.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +export AGENT_APPLICATION=.. +export SPRING_PROFILES_ACTIVE=shell,starwars,docker-desktop + +./support/agent.sh diff --git a/scripts/support/agent.bat b/scripts/support/agent.bat new file mode 100644 index 0000000..9d1e00c --- /dev/null +++ b/scripts/support/agent.bat @@ -0,0 +1,24 @@ +@echo off +setlocal + +set SCRIPT_DIR=%~dp0 +set ENV_SCRIPT=%SCRIPT_DIR%check_env.bat + +call %SCRIPT_DIR%\check_env.bat + +if errorlevel 1 ( + echo Environment check failed. Exiting... + exit /b 1 +) + +if not defined AGENT_APPLICATION ( + echo ERROR: AGENT_APPLICATION environment variable is NOT set + echo Please set it like: set AGENT_APPLICATION=path\to\your\project + exit /b 1 +) + +set POM_FILE=%AGENT_APPLICATION%\pom.xml + +mvn -U -f %POM_FILE% -Dmaven.test.skip=true spring-boot:run + +endlocal \ No newline at end of file diff --git a/scripts/support/agent.sh b/scripts/support/agent.sh new file mode 100644 index 0000000..128a016 --- /dev/null +++ b/scripts/support/agent.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Get the directory where this script is located +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +ENV_SCRIPT="$SCRIPT_DIR/check_env.sh" + +# Call the environment check script +if [ -f "$ENV_SCRIPT" ]; then + source "$ENV_SCRIPT" + if [ $? -ne 0 ]; then + echo "Environment check failed. Exiting..." + exit 1 + fi +else + echo "Warning: Environment check script not found at $ENV_SCRIPT" +fi + +# Check if AGENT_APPLICATION environment variable is set +if [ -z "$AGENT_APPLICATION" ]; then + echo "ERROR: AGENT_APPLICATION environment variable is NOT set" + echo "Please set it like: export AGENT_APPLICATION=/path/to/your/project" + exit 1 +fi + +# Set the POM file path +POM_FILE="$AGENT_APPLICATION/pom.xml" + +# Check if the POM file exists +if [ ! -f "$POM_FILE" ]; then + echo "ERROR: POM file not found at $POM_FILE" + exit 1 +fi + +# Run Maven Spring Boot application +mvn -U -f "$POM_FILE" -Dmaven.test.skip=true spring-boot:run diff --git a/scripts/support/check_env.ps1 b/scripts/support/check_env.ps1 deleted file mode 100644 index 02a71d2..0000000 --- a/scripts/support/check_env.ps1 +++ /dev/null @@ -1,39 +0,0 @@ -# Check environment variables -Write-Host "Checking environment variables..." -ForegroundColor Cyan - -$openaiKeyMissing = $false -$anthropicKeyMissing = $false - -# Check OPENAI_API_KEY -if (-not $env:OPENAI_API_KEY) { - Write-Host "OPENAI_API_KEY environment variable is not set" -ForegroundColor Yellow - Write-Host "OpenAI models will not be available" - Write-Host "Get an API key at https://platform.openai.com/api-keys" - Write-Host "Please set it with: `$env:OPENAI_API_KEY='your_api_key'" -ForegroundColor Green - $openaiKeyMissing = $true -} else { - Write-Host "OPENAI_API_KEY set: OpenAI models are available" -ForegroundColor Green -} - -# Check ANTHROPIC_API_KEY -if (-not $env:ANTHROPIC_API_KEY) { - Write-Host "ANTHROPIC_API_KEY environment variable is not set" -ForegroundColor Yellow - Write-Host "Claude models will not be available" - Write-Host "Get an API key at https://www.anthropic.com/api" - Write-Host "Please set it with: `$env:ANTHROPIC_API_KEY='your_api_key'" -ForegroundColor Green - $anthropicKeyMissing = $true -} else { - Write-Host "ANTHROPIC_API_KEY set: Claude models are available" -ForegroundColor Green -} - -# Check if at least one API key is present -if ($openaiKeyMissing -and $anthropicKeyMissing) { - Write-Host "ERROR: Both OPENAI_API_KEY and ANTHROPIC_API_KEY are missing." -ForegroundColor Red - Write-Host "At least one API key is required to use language models." -ForegroundColor Red - Write-Host "Please set at least one of these keys before running the application." -ForegroundColor Red - exit 1 -} - -Write-Host "Environment check completed successfully." -ForegroundColor Green - -exit 0 # Explicitly exit with success code \ No newline at end of file From d398c823630a9aded3422f7b9066314912d0b5fb Mon Sep 17 00:00:00 2001 From: alexheifetz Date: Tue, 17 Jun 2025 16:06:28 -0400 Subject: [PATCH 2/2] Move shell startup to the scripts folder. --- shell.cmd | 16 ---------------- shell.ps1 | 26 -------------------------- shell.sh | 6 ------ 3 files changed, 48 deletions(-) delete mode 100644 shell.cmd delete mode 100644 shell.ps1 delete mode 100755 shell.sh diff --git a/shell.cmd b/shell.cmd deleted file mode 100644 index bdba8a8..0000000 --- a/shell.cmd +++ /dev/null @@ -1,16 +0,0 @@ -@echo off -setlocal - -call .\scripts\support\check_env.bat - -if errorlevel 1 ( - echo Environment check failed. Exiting... - exit /b 1 -) - - -set SPRING_PROFILES_ACTIVE=shell,severance - -cmd /c mvn -P agent-examples-kotlin -Dmaven.test.skip=true spring-boot:run - -endlocal \ No newline at end of file diff --git a/shell.ps1 b/shell.ps1 deleted file mode 100644 index f0f3493..0000000 --- a/shell.ps1 +++ /dev/null @@ -1,26 +0,0 @@ -# Save current location and environment -Push-Location -$originalProfiles = $env:SPRING_PROFILES_ACTIVE - -try { - # Run environment check - Write-Host "Running environment check..." -ForegroundColor Cyan - & .\scripts\support\check_env.ps1 - - if ($LASTEXITCODE -ne 0) { - Write-Host "Environment check failed. Exiting..." -ForegroundColor Red - exit 1 - } - - - # Set Spring profiles - $env:SPRING_PROFILES_ACTIVE = "shell,severance" - - # Run Maven in subprocess - cmd /c "mvn -P agent-examples-kotlin -Dmaven.test.skip=true spring-boot:run" -} -finally { - # Restore original environment and location - $env:SPRING_PROFILES_ACTIVE = $originalProfiles - Pop-Location -} \ No newline at end of file diff --git a/shell.sh b/shell.sh deleted file mode 100755 index 3296376..0000000 --- a/shell.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -./scripts/support/check_env.sh - -export SPRING_PROFILES_ACTIVE=shell,starwars -mvn -P agent-examples-kotlin -Dmaven.test.skip=true spring-boot:run