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
6 changes: 4 additions & 2 deletions .agents/scripts/agent-test-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ 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; }

Choose a reason for hiding this comment

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

medium

This sed_inplace function is duplicated across multiple scripts in this PR (agent-test-helper.sh, privacy-filter-helper.sh, quality-fix.sh, security-helper.sh, supervisor-helper.sh). To improve maintainability and adhere to the DRY (Don't Repeat Yourself) principle, consider having these scripts source shared-constants.sh to use the canonical function defined there. This would centralize the logic and make future updates easier.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Acknowledged but intentionally deferred. These scripts are standalone (none source shared-constants.sh). Adding a source dependency to each would be a larger refactor with its own risks (path resolution, circular sourcing, etc.). The inline one-liner is self-contained and grep-able. A future refactor to consolidate via sourcing is tracked but not in scope for this bugfix PR.


#######################################
# Ensure workspace directories exist
#######################################
Expand Down Expand Up @@ -864,8 +867,7 @@ TEMPLATE
# Replace placeholder with actual name
local safe_name
safe_name="${name//[^a-zA-Z0-9_-]/-}"
sed -i '' "s/SUITE_NAME/${safe_name}/" "$suite_file" 2>/dev/null || \
sed -i "s/SUITE_NAME/${safe_name}/" "$suite_file"
sed_inplace "s/SUITE_NAME/${safe_name}/" "$suite_file"

log_pass "Created test suite: $suite_file"
log_info "Edit the file to add your test cases, then run:"
Expand Down
9 changes: 4 additions & 5 deletions .agents/scripts/privacy-filter-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ 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"
echo -e "${PURPLE}$message${NC}"
Expand Down Expand Up @@ -370,11 +373,7 @@ apply_redactions() {
cp "$file" "${file}.privacy-backup"

# Apply redaction
if [[ "$(uname)" == "Darwin" ]]; then
sed -i '' -E "s/$pattern/[REDACTED]/g" "$file"
else
sed -i -E "s/$pattern/[REDACTED]/g" "$file"
fi
sed_inplace -E "s/$pattern/[REDACTED]/g" "$file"

print_success "Redacted: $file"
changes=$((changes + 1))
Expand Down
7 changes: 5 additions & 2 deletions .agents/scripts/quality-fix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ 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 Expand Up @@ -102,7 +105,7 @@ fix_return_statements() {

if [[ ! $last_line =~ return[[:space:]]+[01] ]]; then
# Remove the closing brace and add return statement
sed -i '' '$ d' "$temp_file"
sed_inplace '$ d' "$temp_file"
echo " return 0" >> "$temp_file"
echo "}" >> "$temp_file"
((fixed_functions++))
Expand Down Expand Up @@ -153,7 +156,7 @@ fix_positional_parameters() {
}' "$file" > "$temp_file"

# Replace direct positional parameter usage in case statements
sed -i '' 's/\$_arg1/$command/g; s/\$2/$account_name/g; s/\$3/$target/g; s/\$4/$options/g' "$temp_file"
sed_inplace 's/\$_arg1/$command/g; s/\$2/$account_name/g; s/\$3/$target/g; s/\$4/$options/g' "$temp_file"

if ! diff -q "$file" "$temp_file" > /dev/null; then
mv "$temp_file" "$file"
Expand Down
9 changes: 6 additions & 3 deletions .agents/scripts/security-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ 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}"
echo "╔═══════════════════════════════════════════════════════════╗"
Expand Down Expand Up @@ -418,9 +421,9 @@ update_scan_results_log() {
scan_timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")

# Update the "Latest Full Scan" date
sed -i '' "s/^\*\*Date\*\*: .*/**Date**: ${scan_timestamp}/" "$results_file" 2>/dev/null || true
sed -i '' "s/^\*\*Skills scanned\*\*: .*/**Skills scanned**: ${skills_scanned}/" "$results_file" 2>/dev/null || true
sed -i '' "s/^\*\*Safe\*\*: .*/**Safe**: ${safe_count}/" "$results_file" 2>/dev/null || true
sed_inplace "s/^\*\*Date\*\*: .*/**Date**: ${scan_timestamp}/" "$results_file" 2>/dev/null || true
sed_inplace "s/^\*\*Skills scanned\*\*: .*/**Skills scanned**: ${skills_scanned}/" "$results_file" 2>/dev/null || true
sed_inplace "s/^\*\*Safe\*\*: .*/**Safe**: ${safe_count}/" "$results_file" 2>/dev/null || true

# Append to scan history table
local history_row="| ${scan_date} | ${skills_scanned} | ${safe_count} | ${critical_count} | ${high_count} | ${medium_count} | ${notes} |"
Expand Down
16 changes: 16 additions & 0 deletions .agents/scripts/shared-constants.sh
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,22 @@ validate_command_exists() {
return 0
}

# =============================================================================
# Portable sed -i wrapper (macOS vs GNU/Linux)
# macOS sed requires -i '' while GNU sed requires -i (no argument)
# Usage: sed_inplace 'pattern' file
# sed_inplace -E 'pattern' file
# =============================================================================

sed_inplace() {
if [[ "$(uname)" == "Darwin" ]]; then
sed -i '' "$@"
else
sed -i "$@"
fi
return $?
}

# =============================================================================
# Export all constants for use in other scripts
# =============================================================================
Expand Down
15 changes: 11 additions & 4 deletions .agents/scripts/speech-to-speech-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,11 @@ cmd_setup() {
"$venv_dir/bin/pip" install -r "${S2S_DIR}/${req_file}"
fi

# Download NLTK data
# Download NLTK data (suppress progress output, keep errors visible)
print_info "Downloading NLTK data..."
"$venv_dir/bin/python" -c "import nltk; nltk.download('punkt_tab'); nltk.download('averaged_perceptron_tagger_eng')" >/dev/null
if ! "$venv_dir/bin/python" -c "import nltk; nltk.download('punkt_tab'); nltk.download('averaged_perceptron_tagger_eng')" >/dev/null; then
print_warning "NLTK data download failed (non-fatal, some TTS engines may not work)"
fi

print_success "Setup complete. Run: speech-to-speech-helper.sh start"
return 0
Expand Down Expand Up @@ -366,9 +368,14 @@ cmd_stop() {
if kill -0 "$pid" 2>/dev/null; then
print_info "Stopping pipeline (PID $pid)..."
kill "$pid"
sleep 2
# Wait up to 5 seconds for graceful shutdown
local wait_count=0
while kill -0 "$pid" 2>/dev/null && [[ $wait_count -lt 10 ]]; do
sleep 0.5
wait_count=$((wait_count + 1))
done
if kill -0 "$pid" 2>/dev/null; then
print_warning "Force killing..."
print_warning "Force killing (did not exit after 5s)..."
kill -9 "$pid" 2>/dev/null || true
fi
print_success "Pipeline stopped"
Expand Down
16 changes: 6 additions & 10 deletions .agents/scripts/supervisor-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ log_success() { echo -e "${GREEN}[SUPERVISOR]${NC} $*"; }
log_warn() { echo -e "${YELLOW}[SUPERVISOR]${NC} $*"; }
log_error() { echo -e "${RED}[SUPERVISOR]${NC} $*" >&2; }

# 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
# Returns integer count on stdout
Expand Down Expand Up @@ -3788,11 +3791,7 @@ update_todo_on_complete() {
# Use sed to match the line and transform it
local sed_pattern="s/^([[:space:]]*- )\[ \] (${task_id} .*)$/\1[x] \2 completed:${today}/"

if [[ "$(uname)" == "Darwin" ]]; then
sed -i '' -E "$sed_pattern" "$todo_file"
else
sed -i -E "$sed_pattern" "$todo_file"
fi
sed_inplace -E "$sed_pattern" "$todo_file"

# Verify the change was made
if ! grep -qE "^[[:space:]]*- \[x\] ${task_id} " "$todo_file"; then
Expand Down Expand Up @@ -3881,14 +3880,11 @@ update_todo_on_blocked() {
if echo "$next_line" | grep -qE "^[[:space:]]*- Notes:"; then
# Append to existing Notes line
local append_text=" BLOCKED: ${safe_reason}"
if [[ "$(uname)" == "Darwin" ]]; then
sed -i '' "${next_line_num}s/$/${append_text}/" "$todo_file"
else
sed -i "${next_line_num}s/$/${append_text}/" "$todo_file"
fi
sed_inplace "${next_line_num}s/$/${append_text}/" "$todo_file"
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"
Expand Down
4 changes: 2 additions & 2 deletions .agents/scripts/version-manager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -714,10 +714,10 @@ auto_mark_tasks_complete() {
# Check if line already has completed: field
if grep -E "$sed_unchecked_pattern" "$todo_file" | grep -q "completed:"; then
# Just change checkbox
sed -i '' "s/^\\([[:space:]]*\\)- \\[ \\] \\(${escaped_id}[[:space:]]\\)/\\1- [x] \\2/" "$todo_file"
sed_inplace "s/^\\([[:space:]]*\\)- \\[ \\] \\(${escaped_id}[[:space:]]\\)/\\1- [x] \\2/" "$todo_file"
else
# Change checkbox and add completed: timestamp
sed -i '' "s/^\\([[:space:]]*\\)- \\[ \\] \\(${escaped_id}[[:space:]].*\\)\$/\\1- [x] \\2 completed:$today_short/" "$todo_file"
sed_inplace "s/^\\([[:space:]]*\\)- \\[ \\] \\(${escaped_id}[[:space:]].*\\)\$/\\1- [x] \\2 completed:$today_short/" "$todo_file"
fi

count=$((count + 1))
Expand Down
Loading