Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 36 additions & 24 deletions .agent/scripts/anti-detect-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ setup_rebrowser() {

# Check if playwright is installed
if ! command -v npx &>/dev/null; then
echo -e "${RED}Error: npx not found. Install Node.js first.${NC}"
echo -e "${RED}Error: npx not found. Install Node.js first.${NC}" >&2
return 1
fi

Expand All @@ -163,23 +163,23 @@ setup_rebrowser() {
validate_profile_name() {
local name="$1"
if [[ -z "$name" ]]; then
echo -e "${RED}Error: Profile name cannot be empty.${NC}"
echo -e "${RED}Error: Profile name cannot be empty.${NC}" >&2
return 1
fi
if [[ "$name" =~ [/\\] || "$name" == *..* ]]; then
echo -e "${RED}Error: Profile name cannot contain '/', '\\', or '..'.${NC}"
echo -e "${RED}Error: Profile name cannot contain '/', '\\', or '..'.${NC}" >&2
return 1
fi
if [[ "$name" == -* ]]; then
echo -e "${RED}Error: Profile name cannot start with '-'.${NC}"
echo -e "${RED}Error: Profile name cannot start with '-'.${NC}" >&2
return 1
fi
if ! [[ "$name" =~ ^[A-Za-z0-9._-]+$ ]]; then
echo -e "${RED}Error: Profile name must only contain letters, numbers, '.', '_', or '-'.${NC}"
echo -e "${RED}Error: Profile name must only contain letters, numbers, '.', '_', or '-'.${NC}" >&2
return 1
fi
if [[ ${#name} -gt 64 ]]; then
echo -e "${RED}Error: Profile name must be 64 characters or fewer.${NC}"
echo -e "${RED}Error: Profile name must be 64 characters or fewer.${NC}" >&2
return 1
fi
return 0
Expand All @@ -193,9 +193,11 @@ profile_create() {
local browser_type="firefox"
local notes=""

local arg
shift
while [[ $# -gt 0 ]]; do
case "$1" in
arg="$1"
case "$arg" in
--type) profile_type="$2"; shift 2 ;;
--proxy) proxy="$2"; shift 2 ;;
--os) target_os="$2"; shift 2 ;;
Expand All @@ -214,7 +216,7 @@ profile_create() {
local profile_dir="$PROFILES_DIR/$dir_type/$name"

if [[ -d "$profile_dir" ]]; then
echo -e "${RED}Error: Profile '$name' already exists.${NC}"
echo -e "${RED}Error: Profile '$name' already exists.${NC}" >&2
return 1
fi

Expand Down Expand Up @@ -296,7 +298,7 @@ profile_show() {
profile_dir=$(find_profile_dir "$name")

if [[ -z "$profile_dir" ]]; then
echo -e "${RED}Error: Profile '$name' not found.${NC}"
echo -e "${RED}Error: Profile '$name' not found.${NC}" >&2
return 1
fi

Expand Down Expand Up @@ -335,7 +337,7 @@ profile_delete() {
profile_dir=$(find_profile_dir "$name")

if [[ -z "$profile_dir" ]]; then
echo -e "${RED}Error: Profile '$name' not found.${NC}"
echo -e "${RED}Error: Profile '$name' not found.${NC}" >&2
return 1
fi

Expand All @@ -352,7 +354,7 @@ profile_clone() {
src_dir=$(find_profile_dir "$src")

if [[ -z "$src_dir" ]]; then
echo -e "${RED}Error: Source profile '$src' not found.${NC}"
echo -e "${RED}Error: Source profile '$src' not found.${NC}" >&2
return 1
fi

Expand All @@ -361,7 +363,7 @@ profile_clone() {
local dst_dir="$parent_dir/$dst"

if [[ -d "$dst_dir" ]]; then
echo -e "${RED}Error: Destination profile '$dst' already exists.${NC}"
echo -e "${RED}Error: Destination profile '$dst' already exists.${NC}" >&2
return 1
fi

Expand Down Expand Up @@ -404,12 +406,14 @@ profile_update() {
profile_dir=$(find_profile_dir "$name")

if [[ -z "$profile_dir" ]]; then
echo -e "${RED}Error: Profile '$name' not found.${NC}"
echo -e "${RED}Error: Profile '$name' not found.${NC}" >&2
return 1
fi

local arg
while [[ $# -gt 0 ]]; do
case "$1" in
arg="$1"
case "$arg" in
--proxy)
local proxy_json
proxy_json=$(parse_proxy_url "$2")
Expand Down Expand Up @@ -447,8 +451,10 @@ launch_browser() {
local disposable=""
local url=""

local arg
while [[ $# -gt 0 ]]; do
case "$1" in
arg="$1"
case "$arg" in
--profile) profile_name="$2"; shift 2 ;;
--engine) engine="$2"; shift 2 ;;
--headless) headless="true"; shift ;;
Expand All @@ -459,7 +465,7 @@ launch_browser() {
done

if [[ -z "$profile_name" && -z "$disposable" ]]; then
echo -e "${RED}Error: --profile <name> or --disposable required.${NC}"
echo -e "${RED}Error: --profile <name> or --disposable required.${NC}" >&2
return 1
fi

Expand Down Expand Up @@ -500,7 +506,7 @@ launch_camoufox() {

# shellcheck disable=SC1091
source "$VENV_DIR/bin/activate" 2>/dev/null || {
echo -e "${RED}Error: Camoufox venv not found. Run: anti-detect-helper.sh setup${NC}"
echo -e "${RED}Error: Camoufox venv not found. Run: anti-detect-helper.sh setup${NC}" >&2
return 1
}

Expand Down Expand Up @@ -687,9 +693,11 @@ test_detection() {
local profile_name=""
local engine="firefox"
local sites="browserscan,sannysoft"
local arg

while [[ $# -gt 0 ]]; do
case "$1" in
arg="$1"
case "$arg" in
--profile) profile_name="$2"; shift 2 ;;
--engine) engine="$2"; shift 2 ;;
--sites) sites="$2"; shift 2 ;;
Expand Down Expand Up @@ -799,9 +807,11 @@ warmup_profile() {
local profile_name="$1"
shift
local duration="30" # minutes
local arg

while [[ $# -gt 0 ]]; do
case "$1" in
arg="$1"
case "$arg" in
--duration)
duration="${2%m}" # Strip 'm' suffix
shift 2
Expand All @@ -814,15 +824,15 @@ warmup_profile() {
profile_dir=$(find_profile_dir "$profile_name")

if [[ -z "$profile_dir" ]]; then
echo -e "${RED}Error: Profile '$profile_name' not found.${NC}"
echo -e "${RED}Error: Profile '$profile_name' not found.${NC}" >&2
return 1
fi

echo -e "${BLUE}Warming up profile '$profile_name' for ${duration}m...${NC}"

# shellcheck disable=SC1091
source "$VENV_DIR/bin/activate" 2>/dev/null || {
echo -e "${RED}Error: Camoufox venv not found. Run: anti-detect-helper.sh setup${NC}"
echo -e "${RED}Error: Camoufox venv not found. Run: anti-detect-helper.sh setup${NC}" >&2
return 1
}

Expand Down Expand Up @@ -1047,9 +1057,11 @@ cookies_export() {
local profile_name="$1"
shift
local output=""
local arg

while [[ $# -gt 0 ]]; do
case "$1" in
arg="$1"
case "$arg" in
--output) output="$2"; shift 2 ;;
*) shift ;;
esac
Expand All @@ -1059,7 +1071,7 @@ cookies_export() {
profile_dir=$(find_profile_dir "$profile_name")

if [[ -z "$profile_dir" || ! -f "$profile_dir/storage-state.json" ]]; then
echo -e "${RED}Error: No saved state for profile '$profile_name'.${NC}"
echo -e "${RED}Error: No saved state for profile '$profile_name'.${NC}" >&2
return 1
fi

Expand Down Expand Up @@ -1099,7 +1111,7 @@ cookies_clear() {
profile_dir=$(find_profile_dir "$profile_name")

if [[ -z "$profile_dir" ]]; then
echo -e "${RED}Error: Profile '$profile_name' not found.${NC}"
echo -e "${RED}Error: Profile '$profile_name' not found.${NC}" >&2
return 1
fi

Expand Down
9 changes: 5 additions & 4 deletions .agent/scripts/cloudron-package-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ BLUE='\033[0;34m'
NC='\033[0m' # No Color

# Logging functions
log_info() { echo -e "${BLUE}[INFO]${NC} $*"; }
log_success() { echo -e "${GREEN}[OK]${NC} $*"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
log_error() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
log_info() { echo -e "${BLUE}[INFO]${NC} $*"; return 0; }
log_success() { echo -e "${GREEN}[OK]${NC} $*"; return 0; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $*"; return 0; }
log_error() { echo -e "${RED}[ERROR]${NC} $*" >&2; return 0; }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While adding an explicit return statement is good for clarity, an error logging function like log_error should ideally return a non-zero exit code (e.g., 1) to signal that an error has occurred. This allows for more robust error handling patterns in shell scripts, such as command || log_error 'message'. Returning 0 can mask failures in such chains.

Suggested change
log_error() { echo -e "${RED}[ERROR]${NC} $*" >&2; return 0; }
log_error() { echo -e "${RED}[ERROR]${NC} $*"; return 1; } >&2


# Check if cloudron CLI is installed
check_cloudron_cli() {
Expand Down Expand Up @@ -867,6 +867,7 @@ Documentation:
https://docs.cloudron.io/packaging/
https://forum.cloudron.io/category/96/app-packaging-development
HELP
return 0
}

# Main entry point
Expand Down
14 changes: 10 additions & 4 deletions .agent/scripts/log-issue-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ get_aidevops_version() {
else
echo "unknown"
fi
return 0
}

get_latest_version() {
curl --proto '=https' -fsSL \
"https://raw.githubusercontent.com/marcusquinn/aidevops/main/VERSION" \
2>/dev/null || echo "unknown"
return 0
}

detect_ai_assistant() {
Expand Down Expand Up @@ -69,6 +71,7 @@ detect_ai_assistant() {
*) echo "Unknown" ;;
esac
fi
return 0
}

get_install_method() {
Expand All @@ -87,6 +90,7 @@ get_install_method() {
else
echo "unknown ($aidevops_path)"
fi
return 0
}

get_git_context() {
Expand All @@ -100,6 +104,7 @@ get_git_context() {
branch="n/a"
fi
echo "$repo ($branch)"
return 0
}

gather_diagnostics() {
Expand Down Expand Up @@ -143,6 +148,7 @@ gather_diagnostics() {
- **Working repo**: $git_context
- **gh CLI**: $(gh --version 2>/dev/null | head -1 || echo "not installed")
EOF
return 0
}

# -----------------------------------------------------------------------------
Expand All @@ -151,14 +157,14 @@ EOF

check_gh_auth() {
if ! command -v gh &>/dev/null; then
echo "ERROR: GitHub CLI (gh) not installed"
echo "Install with: brew install gh (macOS) or apt install gh (Linux)"
echo "ERROR: GitHub CLI (gh) not installed" >&2
echo "Install with: brew install gh (macOS) or apt install gh (Linux)" >&2
return 1
fi

if ! gh auth status &>/dev/null; then
echo "ERROR: GitHub CLI not authenticated"
echo "Run: gh auth login"
echo "ERROR: GitHub CLI not authenticated" >&2
echo "Run: gh auth login" >&2
return 1
fi

Expand Down
Loading
Loading