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
3 changes: 1 addition & 2 deletions .agents/scripts/agent-test-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit
# shellcheck disable=SC2034
readonly SCRIPT_DIR
source "$SCRIPT_DIR/shared-constants.sh" 2>/dev/null || true
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Soft-sourcing shared-constants.sh but hard-depending on sed_inplace at line 869.

The 2>/dev/null || true pattern means sourcing silently succeeds even if the file is missing. However, cmd_create() at line 869 calls sed_inplace, which will fail with an opaque "command not found" error under set -euo pipefail. This applies to several other scripts in this PR that follow the same pattern (quality-fix.sh, auto-version-bump.sh, coderabbit-cli.sh, readme-helper.sh, security-helper.sh).

Consider adding a guard after sourcing:

Proposed fix
 source "$SCRIPT_DIR/shared-constants.sh" 2>/dev/null || true
+if ! declare -f sed_inplace >/dev/null 2>&1; then
+    echo "ERROR: shared-constants.sh failed to load (sed_inplace unavailable)" >&2
+    exit 1
+fi

Alternatively, keep the source mandatory (remove || true) for scripts that cannot function without the shared utilities. As per coding guidelines, automation scripts should focus on reliability, robustness, and clear logging/feedback.

🤖 Prompt for AI Agents
In @.agents/scripts/agent-test-helper.sh at line 53, The script soft-sources
shared-constants.sh but later unconditionally calls sed_inplace in cmd_create,
which leads to a cryptic "command not found" under set -euo pipefail if the file
is missing; to fix, after the existing source "$SCRIPT_DIR/shared-constants.sh"
2>/dev/null || true add an explicit guard that verifies required symbols (e.g.,
test for the sed_inplace function/variable and any other utilities used by
cmd_create) and exit with a clear error message if missing, or change the source
to be mandatory (remove the "|| true") for scripts that cannot run without
shared-constants.sh; update cmd_create references to rely on that guard so
failures surface with a descriptive log rather than an opaque shell error.

readonly AIDEVOPS_DIR="${HOME}/.aidevops"
readonly WORKSPACE_DIR="${AIDEVOPS_DIR}/.agent-workspace"
readonly TEST_DIR="${WORKSPACE_DIR}/agent-tests"
Expand Down Expand Up @@ -99,8 +100,6 @@ log_fail() { echo -e "${RED}[FAIL]${NC} $*"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
log_header() { echo -e "${PURPLE}${BOLD}$*${NC}"; }

# Cross-platform sed in-place edit (macOS vs GNU/Linux)
sed_inplace() { if [[ "$(uname)" == "Darwin" ]]; then sed -i '' "$@"; else sed -i "$@"; fi; }

#######################################
# Ensure workspace directories exist
Expand Down
14 changes: 3 additions & 11 deletions .agents/scripts/auto-version-bump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,9 @@ print_success() { local msg="$1"; echo -e "${GREEN}[SUCCESS]${NC} $msg"; return
print_warning() { local msg="$1"; echo -e "${YELLOW}[WARNING]${NC} $msg"; return 0; }
print_error() { local msg="$1"; echo -e "${RED}[ERROR]${NC} $msg" >&2; return 0; }

# Cross-platform sed in-place edit (works on macOS and Linux)
sed_inplace() {
local pattern="$1"
local file="$2"
if [[ "$(uname)" == "Darwin" ]]; then
sed -i '' "$pattern" "$file"
else
sed -i "$pattern" "$file"
fi
return $?
}
# Source shared constants (provides sed_inplace and other utilities)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit
source "$SCRIPT_DIR/shared-constants.sh" 2>/dev/null || true

# Repository root directory
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" || exit
Expand Down
10 changes: 6 additions & 4 deletions .agents/scripts/coderabbit-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
# Version: 1.2.0
# License: MIT

# Source shared constants (provides sed_inplace and other utilities)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit
source "$SCRIPT_DIR/shared-constants.sh" 2>/dev/null || true

# Colors for output
readonly GREEN='\033[0;32m'
readonly BLUE='\033[0;34m'
Expand Down Expand Up @@ -131,18 +135,16 @@ apply_coderabbit_fixes() {
print_info "Applying markdown formatting fixes..."

# Fix heading spacing (add blank line after headings)
sed -i.tmp '/^#.*$/{
sed_inplace '/^#.*$/{
N
/\n$/!s/$/\n/
}' "$file"

# Fix list spacing (ensure blank lines around lists)
sed -i.tmp '/^[[:space:]]*[-*+][[:space:]]/{
sed_inplace '/^[[:space:]]*[-*+][[:space:]]/{
i\

}' "$file"

rm -f "$file.tmp"
print_success "Applied markdown formatting fixes"
fi

Expand Down
30 changes: 17 additions & 13 deletions .agents/scripts/comprehensive-quality-fix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
# Comprehensive script to fix remaining SonarCloud issues
# Targets: S7679 (positional parameters), S7682 (return statements), S1192 (string literals)

# Source shared constants (provides sed_inplace and other utilities)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit
source "$SCRIPT_DIR/shared-constants.sh" 2>/dev/null || true
Comment on lines +7 to +9
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Silent failure if shared-constants.sh fails to load leaves sed_inplace/sed_append_after undefined.

The 2>/dev/null || true suppresses all errors, so if the source fails, the script continues but every subsequent sed_inplace / sed_append_after call will error out with "command not found." Consider adding a guard or at least a warning:

Proposed fix
 # Source shared constants (provides sed_inplace and other utilities)
 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit
-source "$SCRIPT_DIR/shared-constants.sh" 2>/dev/null || true
+source "$SCRIPT_DIR/shared-constants.sh" 2>/dev/null || {
+    echo "⚠️  shared-constants.sh not found; sed_inplace/sed_append_after unavailable" >&2
+    exit 1
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Source shared constants (provides sed_inplace and other utilities)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit
source "$SCRIPT_DIR/shared-constants.sh" 2>/dev/null || true
# Source shared constants (provides sed_inplace and other utilities)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit
source "$SCRIPT_DIR/shared-constants.sh" 2>/dev/null || {
echo "⚠️ shared-constants.sh not found; sed_inplace/sed_append_after unavailable" >&2
exit 1
}
🤖 Prompt for AI Agents
In @.agents/scripts/comprehensive-quality-fix.sh around lines 7 - 9, The script
silently ignores failures sourcing shared-constants.sh leaving helpers like
sed_inplace and sed_append_after undefined; change the sourcing to explicitly
check the file and abort (or at least warn) if it cannot be loaded: ensure
SCRIPT_DIR is computed, verify "$SCRIPT_DIR/shared-constants.sh" exists and is
readable, source it without redirecting errors (or capture and handle failure),
then confirm required symbols (e.g., sed_inplace, sed_append_after) are
available and call process exit with a clear error message if they are missing
so subsequent commands don't fail with "command not found."


cd providers || exit

echo "🚀 Starting comprehensive quality fix..."
Expand All @@ -14,7 +18,7 @@ fix_misplaced_returns() {
echo "Fixing misplaced returns in $file..."

# Remove return statements that are not at the end of functions
sed -i '/^ return 0$/d' "$file"
sed_inplace '/^ return 0$/d' "$file"

# Add return statements to function endings that need them
# This is a more targeted approach based on SonarCloud line numbers
Expand All @@ -29,20 +33,20 @@ replace_string_literals() {
case "$file" in
"mainwp-helper.sh")
# Replace remaining "Site ID is required" occurrences
sed -i 's/"Site ID is required"/"$ERROR_SITE_ID_REQUIRED"/g' "$file"
sed -i 's/"At least one site ID is required"/"$ERROR_AT_LEAST_ONE_SITE_ID"/g' "$file"
sed_inplace 's/"Site ID is required"/"$ERROR_SITE_ID_REQUIRED"/g' "$file"
sed_inplace 's/"At least one site ID is required"/"$ERROR_AT_LEAST_ONE_SITE_ID"/g' "$file"
;;
"code-audit-helper.sh")
# Already done in previous commit
;;
"dns-helper.sh")
# Replace remaining cloudflare occurrences in case statements
sed -i "s/\"namecheap\"/\"\$PROVIDER_NAMECHEAP\"/g" "$file"
sed -i "s/\"route53\"/\"\$PROVIDER_ROUTE53\"/g" "$file"
sed_inplace "s/\"namecheap\"/\"\$PROVIDER_NAMECHEAP\"/g" "$file"
sed_inplace "s/\"route53\"/\"\$PROVIDER_ROUTE53\"/g" "$file"
;;
"git-platforms-helper.sh")
# Replace remaining platform occurrences
sed -i "s/\"gitea\"/\"\$PLATFORM_GITEA\"/g" "$file"
sed_inplace "s/\"gitea\"/\"\$PLATFORM_GITEA\"/g" "$file"
;;
*)
echo "No string literal replacements needed for $file"
Expand All @@ -61,22 +65,22 @@ add_missing_returns() {
case "$file" in
"closte-helper.sh")
# Lines 134, 249
sed -i '133a\ return 0' "$file"
sed -i '248a\ return 0' "$file"
sed_append_after 133 ' return 0' "$file"
sed_append_after 248 ' return 0' "$file"
;;
"cloudron-helper.sh")
# Lines 74, 202
sed -i '73a\ return 0' "$file"
sed -i '201a\ return 0' "$file"
sed_append_after 73 ' return 0' "$file"
sed_append_after 201 ' return 0' "$file"
;;
"coolify-helper.sh")
# Line 236
sed -i '235a\ return 0' "$file"
sed_append_after 235 ' return 0' "$file"
;;
"dns-helper.sh")
# Lines 95, 259
sed -i '94a\ return 0' "$file"
sed -i '258a\ return 0' "$file"
sed_append_after 94 ' return 0' "$file"
sed_append_after 258 ' return 0' "$file"
;;
Comment on lines 66 to 84
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Sequential sed_append_after calls with hardcoded line numbers produce off-by-one errors after the first insertion.

Each sed_append_after inserts a line, shifting all subsequent line numbers by +1. The second call in each case block still uses the original line number, so it targets the wrong line.

For example in closte-helper.sh (comment says "Lines 134, 249"):

  • sed_append_after 133 inserts after line 133 → file grows by 1 line.
  • sed_append_after 248 now targets what was originally line 247, not 249.

Fix by either processing insertions bottom-up (highest line number first) or incrementing subsequent targets:

Proposed fix (bottom-up ordering)
         "closte-helper.sh")
             # Lines 134, 249
-            sed_append_after 133 '    return 0' "$file"
-            sed_append_after 248 '    return 0' "$file"
+            sed_append_after 248 '    return 0' "$file"
+            sed_append_after 133 '    return 0' "$file"
             ;;
         "cloudron-helper.sh")
             # Lines 74, 202
-            sed_append_after 73 '    return 0' "$file"
-            sed_append_after 201 '    return 0' "$file"
+            sed_append_after 201 '    return 0' "$file"
+            sed_append_after 73 '    return 0' "$file"
             ;;
...
         "dns-helper.sh")
             # Lines 95, 259
-            sed_append_after 94 '    return 0' "$file"
-            sed_append_after 258 '    return 0' "$file"
+            sed_append_after 258 '    return 0' "$file"
+            sed_append_after 94 '    return 0' "$file"
             ;;

By inserting at the later line first, earlier line numbers remain stable.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"closte-helper.sh")
# Lines 134, 249
sed -i '133a\ return 0' "$file"
sed -i '248a\ return 0' "$file"
sed_append_after 133 ' return 0' "$file"
sed_append_after 248 ' return 0' "$file"
;;
"cloudron-helper.sh")
# Lines 74, 202
sed -i '73a\ return 0' "$file"
sed -i '201a\ return 0' "$file"
sed_append_after 73 ' return 0' "$file"
sed_append_after 201 ' return 0' "$file"
;;
"coolify-helper.sh")
# Line 236
sed -i '235a\ return 0' "$file"
sed_append_after 235 ' return 0' "$file"
;;
"dns-helper.sh")
# Lines 95, 259
sed -i '94a\ return 0' "$file"
sed -i '258a\ return 0' "$file"
sed_append_after 94 ' return 0' "$file"
sed_append_after 258 ' return 0' "$file"
;;
"closte-helper.sh")
# Lines 134, 249
sed_append_after 248 ' return 0' "$file"
sed_append_after 133 ' return 0' "$file"
;;
"cloudron-helper.sh")
# Lines 74, 202
sed_append_after 201 ' return 0' "$file"
sed_append_after 73 ' return 0' "$file"
;;
"coolify-helper.sh")
# Line 236
sed_append_after 235 ' return 0' "$file"
;;
"dns-helper.sh")
# Lines 95, 259
sed_append_after 258 ' return 0' "$file"
sed_append_after 94 ' return 0' "$file"
;;
🤖 Prompt for AI Agents
In @.agents/scripts/comprehensive-quality-fix.sh around lines 66 - 84, The
sed_append_after calls use hardcoded line numbers and are executed top-down
which shifts subsequent targets; update each case block (e.g., the
"closte-helper.sh", "cloudron-helper.sh", "coolify-helper.sh", "dns-helper.sh"
blocks) to perform insertions bottom-up by ordering sed_append_after calls from
highest to lowest line number or by collecting target lines into an array and
sorting it descending before calling sed_append_after (ensuring the function
name sed_append_after remains unchanged and only the call order/loop logic is
changed).


*)
Expand Down
6 changes: 5 additions & 1 deletion .agents/scripts/mass-fix-returns.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
# Mass fix script to add return statements to all functions that need them
# Based on SonarCloud S7682 analysis

# Source shared constants (provides sed_inplace, sed_append_after)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit
source "$SCRIPT_DIR/shared-constants.sh" 2>/dev/null || true

cd providers || exit

# Files and their function ending line numbers that need return statements
Expand Down Expand Up @@ -33,7 +37,7 @@ add_return_statement() {
if ! sed -n "${prev_line}p" "$file" | grep -q "return"; then
echo "Adding return statement to $file at line $line_num"
# Insert return statement before the closing brace
sed -i "${prev_line}a\\ return 0" "$file"
sed_append_after "$prev_line" ' return 0' "$file"
else
echo "Return statement already exists in $file at line $line_num"
fi
Expand Down
3 changes: 1 addition & 2 deletions .agents/scripts/privacy-filter-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ readonly NC='\033[0m' # No Color

# Configuration
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit
source "$SCRIPT_DIR/shared-constants.sh" 2>/dev/null || true
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Silent fallback when shared-constants.sh fails to source leaves sed_inplace undefined.

Line 375 calls sed_inplace in apply_redactions(). If sourcing fails (file missing, permission issue), sed_inplace will be undefined and the script will crash at runtime with a "command not found" error — which is opaque to the user. Given set -euo pipefail on line 20, the script will exit immediately with no helpful message.

Consider either removing || true (so sourcing failure is caught early), or adding a guard:

Proposed guard
 source "$SCRIPT_DIR/shared-constants.sh" 2>/dev/null || true
+if ! command -v sed_inplace &>/dev/null; then
+    sed_inplace() { if [[ "$(uname)" == "Darwin" ]]; then sed -i '' "$@"; else sed -i "$@"; fi; }
+fi

As per coding guidelines, .agents/scripts/*.sh scripts should focus on reliability, robustness, and error recovery mechanisms.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
source "$SCRIPT_DIR/shared-constants.sh" 2>/dev/null || true
source "$SCRIPT_DIR/shared-constants.sh" 2>/dev/null || true
if ! command -v sed_inplace &>/dev/null; then
sed_inplace() { if [[ "$(uname)" == "Darwin" ]]; then sed -i '' "$@"; else sed -i "$@"; fi; }
fi
🤖 Prompt for AI Agents
In @.agents/scripts/privacy-filter-helper.sh at line 33, The script silently
ignores failures when sourcing shared-constants.sh, which can leave the
sed_inplace function undefined and cause apply_redactions() to fail later;
remove the "|| true" fallback so sourcing errors surface, or add an explicit
guard after sourcing that checks for the sed_inplace symbol (e.g., test if the
function/command sed_inplace exists) and print a clear error and exit if
missing; ensure this guard references SCRIPT_DIR and shared-constants.sh so
maintainers can locate where the dependency is loaded and avoid the opaque
"command not found" failure under set -euo pipefail.

readonly AIDEVOPS_DIR="${HOME}/.aidevops"
readonly CONFIG_DIR="${AIDEVOPS_DIR}/config"
readonly PATTERNS_FILE="${CONFIG_DIR}/privacy-patterns.txt"
Expand Down Expand Up @@ -116,8 +117,6 @@ print_error() {
return 0
}

# Cross-platform sed in-place edit (macOS vs GNU/Linux)
sed_inplace() { if [[ "$(uname)" == "Darwin" ]]; then sed -i '' "$@"; else sed -i "$@"; fi; }

print_header() {
local message="$1"
Expand Down
6 changes: 4 additions & 2 deletions .agents/scripts/quality-fix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

set -euo pipefail

# Source shared constants if available
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit
source "$SCRIPT_DIR/shared-constants.sh" 2>/dev/null || true

# Color codes for output
readonly RED='\033[0;31m'
readonly GREEN='\033[0;32m'
Expand Down Expand Up @@ -42,8 +46,6 @@ print_info() {
return 0
}

# Cross-platform sed in-place edit (macOS vs GNU/Linux)
sed_inplace() { if [[ "$(uname)" == "Darwin" ]]; then sed -i '' "$@"; else sed -i "$@"; fi; }

backup_files() {
print_info "Creating backup of provider files..."
Expand Down
10 changes: 4 additions & 6 deletions .agents/scripts/readme-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set -euo pipefail

# Configuration
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit
source "$SCRIPT_DIR/shared-constants.sh" 2>/dev/null || true
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" || exit
AGENT_DIR="$REPO_ROOT/.agent"

Expand Down Expand Up @@ -222,16 +223,13 @@ update_readme_counts() {

# Update patterns
# ~N main agents or ~N domain agents
sed -i.tmp -E "s/~[0-9]+ (main|domain) agents/~$main_agents \1 agents/g" "$readme_file"
sed_inplace -E "s/~[0-9]+ (main|domain) agents/~$main_agents \1 agents/g" "$readme_file"

# N+ helper scripts
sed -i.tmp -E "s/[0-9]+\+ helper scripts/${approx_scripts}+ helper scripts/g" "$readme_file"
sed_inplace -E "s/[0-9]+\+ helper scripts/${approx_scripts}+ helper scripts/g" "$readme_file"

# N+ subagent markdown files
sed -i.tmp -E "s/[0-9]+\+ subagent/${approx_subagents}+ subagent/g" "$readme_file"

# Clean up temp files
rm -f "$readme_file.tmp"
sed_inplace -E "s/[0-9]+\+ subagent/${approx_subagents}+ subagent/g" "$readme_file"

print_success "Updated README counts"
print_info "Backup saved to $readme_file.bak"
Expand Down
3 changes: 1 addition & 2 deletions .agents/scripts/security-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit
export SCRIPT_DIR
readonly SCRIPT_DIR
source "$SCRIPT_DIR/shared-constants.sh" 2>/dev/null || true
readonly OUTPUT_DIR=".security-analysis"
readonly VERSION="1.0.0"
readonly SCAN_RESULTS_FILE=".agents/SKILL-SCAN-RESULTS.md"
Expand All @@ -22,8 +23,6 @@ readonly BLUE='\033[0;34m'
readonly CYAN='\033[0;36m'
readonly NC='\033[0m'

# Cross-platform sed in-place edit (macOS vs GNU/Linux)
sed_inplace() { if [[ "$(uname)" == "Darwin" ]]; then sed -i '' "$@"; else sed -i "$@"; fi; }

print_header() {
echo -e "${CYAN}"
Expand Down
17 changes: 17 additions & 0 deletions .agents/scripts/shared-constants.sh
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,23 @@ sed_inplace() {
return $?
}

# Portable sed append-after-line (macOS vs GNU/Linux)
# BSD sed 'a' requires a backslash-newline; GNU sed accepts inline text.
# Usage: sed_append_after <line_number> <text_to_insert> <file>
sed_append_after() {
local line_num="$1"
local text="$2"
local file="$3"
if [[ "$(uname)" == "Darwin" ]]; then
sed -i '' "${line_num} a\\
${text}
" "$file"
else
sed -i "${line_num}a\\${text}" "$file"
fi
return $?
}

# =============================================================================
# Stderr Logging Utilities
# =============================================================================
Expand Down
12 changes: 6 additions & 6 deletions .agents/scripts/sonarcloud-autofix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

set -euo pipefail

# Source shared constants (provides sed_inplace and other utilities)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit
source "$SCRIPT_DIR/shared-constants.sh" 2>/dev/null || true

# Colors for output
readonly RED='\033[0;31m'
readonly GREEN='\033[0;32m'
Expand Down Expand Up @@ -62,14 +66,12 @@ fix_positional_parameters() {
cp "$file" "$file.backup"

# Replace direct $1, $_arg2, etc. usage with local variable assignments
sed -i.tmp '
sed_inplace '
s/echo "\$1"/local param1="$1"; echo "$param1"/g
s/echo "\$_arg2"/local param2="$_arg2"; echo "$param2"/g
s/case "\$1"/local command="$1"; case "$command"/g
s/\[\[ "\$1"/local arg1="$1"; [[ "$arg1"/g
' "$file"

rm -f "$file.tmp"
print_success "Fixed positional parameters in $file"
return 0
}
Expand All @@ -83,7 +85,7 @@ fix_missing_default_case() {
cp "$file" "$file.backup"

# Add default case before esac if missing
sed -i.tmp '
sed_inplace '
/esac/ {
i\
*)\
Expand All @@ -92,8 +94,6 @@ fix_missing_default_case() {
;;
}
' "$file"

rm -f "$file.tmp"
print_success "Added default cases to $file"
return 0
}
Expand Down
11 changes: 2 additions & 9 deletions .agents/scripts/supervisor-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ unset _p
# Configuration - resolve relative to this script's location
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit
readonly SCRIPT_DIR
source "$SCRIPT_DIR/shared-constants.sh" 2>/dev/null || true
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Silent failure when sourcing a now-required dependency.

shared-constants.sh provides sed_inplace and sed_append_after, which are called later (lines 4227, 4303, 4392, 4396) with no local fallback. The 2>/dev/null || true will silently swallow a missing or broken source, leading to cryptic "command not found" errors deep in TODO.md update paths.

Consider at minimum logging a warning if the source fails, so debugging doesn't require tracing back from a sed wrapper that doesn't exist:

Suggested improvement
-source "$SCRIPT_DIR/shared-constants.sh" 2>/dev/null || true
+source "$SCRIPT_DIR/shared-constants.sh" 2>/dev/null || log_warn "shared-constants.sh not found; sed_inplace/sed_append_after unavailable"

Note: log_warn is defined on line 139, after this source line on 81. You'd need to either move the source below the log function definitions, or use a simpler echo >&2 fallback here.

As per coding guidelines, automation scripts should focus on "Clear logging and feedback" and "Error recovery mechanisms".

🤖 Prompt for AI Agents
In @.agents/scripts/supervisor-helper.sh at line 81, The script silently ignores
failure when sourcing shared-constants.sh (which defines sed_inplace and
sed_append_after) because of "2>/dev/null || true", causing later "command not
found" errors; remove the silent suppression and add an explicit warning if the
source fails (or move the source below the log_warn definition and use
log_warn), e.g., try sourcing shared-constants.sh without redirecting stderr and
on failure emit a clear message referencing shared-constants.sh and the missing
functions (sed_inplace, sed_append_after) and either exit or continue with a
documented fallback; ensure references to log_warn (or a temporary echo >&2
fallback placed before log_warn is defined) are used so the warning is visible.

readonly SUPERVISOR_DIR="${AIDEVOPS_SUPERVISOR_DIR:-$HOME/.aidevops/.agent-workspace/supervisor}"
readonly SUPERVISOR_DB="$SUPERVISOR_DIR/supervisor.db"
readonly MAIL_HELPER="${SCRIPT_DIR}/mail-helper.sh" # Used by pulse command (t128.2)
Expand Down Expand Up @@ -160,8 +161,6 @@ log_cmd() {
return $rc
}

# Cross-platform sed in-place edit (macOS vs GNU/Linux)
sed_inplace() { if [[ "$(uname)" == "Darwin" ]]; then sed -i '' "$@"; else sed -i "$@"; fi; }

#######################################
# Get the number of CPU cores on this system
Expand Down Expand Up @@ -4394,13 +4393,7 @@ update_todo_on_blocked() {
else
# Insert a new Notes line after the task
local notes_line="${indent} - Notes: BLOCKED by supervisor: ${safe_reason}"
# sed append syntax differs between BSD and GNU - sed_inplace can't abstract this
if [[ "$(uname)" == "Darwin" ]]; then
sed -i '' "${line_num}a\\
${notes_line}" "$todo_file"
else
sed -i "${line_num}a\\${notes_line}" "$todo_file"
fi
sed_append_after "$line_num" "$notes_line" "$todo_file"
fi

log_success "Updated TODO.md: $task_id marked blocked ($reason)"
Expand Down
11 changes: 7 additions & 4 deletions .agents/scripts/unstract-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

set -euo pipefail

# Source shared constants (provides sed_inplace and other utilities)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit
source "$SCRIPT_DIR/shared-constants.sh" 2>/dev/null || true

# Constants
readonly UNSTRACT_DIR="${HOME}/.aidevops/unstract"
readonly UNSTRACT_REPO="https://github.com/Zipstack/unstract.git"
Expand Down Expand Up @@ -88,7 +92,7 @@ do_install() {
local frontend_env="${UNSTRACT_DIR}/frontend/.env"
if [[ -f "$frontend_env" ]]; then
if grep -q "REACT_APP_ENABLE_POSTHOG" "$frontend_env"; then
sed -i.bak 's/REACT_APP_ENABLE_POSTHOG=.*/REACT_APP_ENABLE_POSTHOG=false/' "$frontend_env"
sed_inplace 's/REACT_APP_ENABLE_POSTHOG=.*/REACT_APP_ENABLE_POSTHOG=false/' "$frontend_env"
else
echo "REACT_APP_ENABLE_POSTHOG=false" >> "$frontend_env"
fi
Expand Down Expand Up @@ -237,9 +241,8 @@ do_uninstall() {

# Remove MCP env entries
if [[ -f "$CREDENTIALS_FILE" ]]; then
sed -i.bak '/UNSTRACT_API_KEY/d' "$CREDENTIALS_FILE"
sed -i.bak '/^export API_BASE_URL.*unstract/d' "$CREDENTIALS_FILE"
rm -f "${CREDENTIALS_FILE}.bak"
sed_inplace '/UNSTRACT_API_KEY/d' "$CREDENTIALS_FILE"
sed_inplace '/^export API_BASE_URL.*unstract/d' "$CREDENTIALS_FILE"
fi

print_success "Unstract uninstalled"
Expand Down
Loading
Loading