From 8256571b961ca950db4dee697b0732833cd3abcf Mon Sep 17 00:00:00 2001 From: CagesThrottleUs Date: Sat, 14 Mar 2026 10:59:12 +0530 Subject: [PATCH] feat(scripts): add parallelization for convert.sh Signed-off-by: CagesThrottleUs --- scripts/convert.sh | 111 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 91 insertions(+), 20 deletions(-) diff --git a/scripts/convert.sh b/scripts/convert.sh index 22aa46e..f2d5c5b 100755 --- a/scripts/convert.sh +++ b/scripts/convert.sh @@ -7,7 +7,7 @@ # integration files after adding or modifying agents. # # Usage: -# ./scripts/convert.sh [--tool ] [--out ] [--help] +# ./scripts/convert.sh [--tool ] [--out ] [--parallel] [--jobs N] [--help] # # Tools: # antigravity — Antigravity skill files (~/.gemini/antigravity/skills/) @@ -22,6 +22,9 @@ # # Output is written to integrations// relative to the repo root. # This script never touches user config dirs — see install.sh for that. +# +# --parallel When tool is 'all', run independent tools in parallel (output order may vary). +# --jobs N Max parallel jobs when using --parallel (default: nproc or 4). set -euo pipefail @@ -37,6 +40,20 @@ warn() { printf "${YELLOW}[!!]${RESET} %s\n" "$*"; } error() { printf "${RED}[ERR]${RESET} %s\n" "$*" >&2; } header() { echo -e "\n${BOLD}$*${RESET}"; } +# Progress bar: [=======> ] 3/8 (tqdm-style) +progress_bar() { + local current="$1" total="$2" width="${3:-20}" i filled empty + (( total > 0 )) || return + filled=$(( width * current / total )) + empty=$(( width - filled )) + printf "\r [" + for (( i=0; i"; (( empty-- )); fi + for (( i=0; i/dev/null) && [[ -n "$n" ]] && echo "$n" && return + n=$(sysctl -n hw.ncpu 2>/dev/null) && [[ -n "$n" ]] && echo "$n" && return + echo 4 +} + # --- Frontmatter helpers --- # Extract a single field value from YAML frontmatter block. @@ -460,13 +485,18 @@ run_conversions() { main() { local tool="all" + local use_parallel=false + local parallel_jobs + parallel_jobs="$(parallel_jobs_default)" while [[ $# -gt 0 ]]; do case "$1" in - --tool) tool="${2:?'--tool requires a value'}"; shift 2 ;; - --out) OUT_DIR="${2:?'--out requires a value'}"; shift 2 ;; - --help|-h) usage ;; - *) error "Unknown option: $1"; usage ;; + --tool) tool="${2:?'--tool requires a value'}"; shift 2 ;; + --out) OUT_DIR="${2:?'--out requires a value'}"; shift 2 ;; + --parallel) use_parallel=true; shift ;; + --jobs) parallel_jobs="${2:?'--jobs requires a value'}"; shift 2 ;; + --help|-h) usage ;; + *) error "Unknown option: $1"; usage ;; esac done @@ -483,6 +513,9 @@ main() { echo " Output: $OUT_DIR" echo " Tool: $tool" echo " Date: $TODAY" + if $use_parallel && [[ "$tool" == "all" ]]; then + info "Parallel mode: output buffered so each tool's output stays together." + fi local tools_to_run=() if [[ "$tool" == "all" ]]; then @@ -492,26 +525,60 @@ main() { fi local total=0 - for t in "${tools_to_run[@]}"; do - header "Converting: $t" - local count - count="$(run_conversions "$t")" - total=$(( total + count )) - # Gemini CLI also needs the extension manifest - if [[ "$t" == "gemini-cli" ]]; then - mkdir -p "$OUT_DIR/gemini-cli" - cat > "$OUT_DIR/gemini-cli/gemini-extension.json" <<'HEREDOC' + local n_tools=${#tools_to_run[@]} + + if $use_parallel && [[ "$tool" == "all" ]]; then + # Tools that write to separate dirs can run in parallel; buffer output so each tool's output stays together + local parallel_tools=(antigravity gemini-cli opencode cursor openclaw qwen) + local parallel_out_dir + parallel_out_dir="$(mktemp -d)" + info "Converting: ${#parallel_tools[@]}/${n_tools} tools in parallel (output buffered per tool)..." + export AGENCY_CONVERT_OUT_DIR="$parallel_out_dir" + export AGENCY_CONVERT_SCRIPT="$SCRIPT_DIR/convert.sh" + export AGENCY_CONVERT_OUT="$OUT_DIR" + printf '%s\n' "${parallel_tools[@]}" | xargs -P "$parallel_jobs" -I {} sh -c '"$AGENCY_CONVERT_SCRIPT" --tool "{}" --out "$AGENCY_CONVERT_OUT" > "$AGENCY_CONVERT_OUT_DIR/{}" 2>&1' + for t in "${parallel_tools[@]}"; do + [[ -f "$parallel_out_dir/$t" ]] && cat "$parallel_out_dir/$t" + done + rm -rf "$parallel_out_dir" + local idx=7 + for t in aider windsurf; do + progress_bar "$idx" "$n_tools" + printf "\n" + header "Converting: $t ($idx/$n_tools)" + local count + count="$(run_conversions "$t")" + total=$(( total + count )) + info "Converted $count agents for $t" + (( idx++ )) || true + done + else + local i=0 + for t in "${tools_to_run[@]}"; do + (( i++ )) || true + progress_bar "$i" "$n_tools" + printf "\n" + header "Converting: $t ($i/$n_tools)" + local count + count="$(run_conversions "$t")" + total=$(( total + count )) + + # Gemini CLI also needs the extension manifest (written by this process when --tool gemini-cli) + if [[ "$t" == "gemini-cli" ]]; then + mkdir -p "$OUT_DIR/gemini-cli" + cat > "$OUT_DIR/gemini-cli/gemini-extension.json" <<'HEREDOC' { "name": "agency-agents", "version": "1.0.0" } HEREDOC - info "Wrote gemini-extension.json" - fi + info "Wrote gemini-extension.json" + fi - info "Converted $count agents for $t" - done + info "Converted $count agents for $t" + done + fi # Write single-file outputs after accumulation if [[ "$tool" == "all" || "$tool" == "aider" ]]; then @@ -526,7 +593,11 @@ HEREDOC fi echo "" - info "Done. Total conversions: $total" + if $use_parallel && [[ "$tool" == "all" ]]; then + info "Done. $n_tools tools (parallel; total conversions not aggregated)." + else + info "Done. Total conversions: $total" + fi } main "$@"