feat(scripts): add parallelization for convert.sh
Signed-off-by: CagesThrottleUs <manstein.felix@gmail.com>
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
# integration files after adding or modifying agents.
|
||||
#
|
||||
# Usage:
|
||||
# ./scripts/convert.sh [--tool <name>] [--out <dir>] [--help]
|
||||
# ./scripts/convert.sh [--tool <name>] [--out <dir>] [--parallel] [--jobs N] [--help]
|
||||
#
|
||||
# Tools:
|
||||
# antigravity — Antigravity skill files (~/.gemini/antigravity/skills/)
|
||||
@@ -22,6 +22,9 @@
|
||||
#
|
||||
# Output is written to integrations/<tool>/ 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<filled; i++ )); do printf "="; done
|
||||
if (( filled < width )); then printf ">"; (( empty-- )); fi
|
||||
for (( i=0; i<empty; i++ )); do printf " "; done
|
||||
printf "] %s/%s" "$current" "$total"
|
||||
[[ -t 1 ]] || printf "\n"
|
||||
}
|
||||
|
||||
# --- Paths ---
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
@@ -50,10 +67,18 @@ AGENT_DIRS=(
|
||||
|
||||
# --- Usage ---
|
||||
usage() {
|
||||
sed -n '3,22p' "$0" | sed 's/^# \{0,1\}//'
|
||||
sed -n '3,26p' "$0" | sed 's/^# \{0,1\}//'
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Default parallel job count (nproc on Linux; sysctl on macOS when nproc missing)
|
||||
parallel_jobs_default() {
|
||||
local n
|
||||
n=$(nproc 2>/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,11 +485,16 @@ 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 ;;
|
||||
--parallel) use_parallel=true; shift ;;
|
||||
--jobs) parallel_jobs="${2:?'--jobs requires a value'}"; shift 2 ;;
|
||||
--help|-h) usage ;;
|
||||
*) error "Unknown option: $1"; usage ;;
|
||||
esac
|
||||
@@ -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,13 +525,46 @@ main() {
|
||||
fi
|
||||
|
||||
local total=0
|
||||
|
||||
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
|
||||
header "Converting: $t"
|
||||
(( 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
|
||||
# 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'
|
||||
@@ -512,6 +578,7 @@ HEREDOC
|
||||
|
||||
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 ""
|
||||
if $use_parallel && [[ "$tool" == "all" ]]; then
|
||||
info "Done. $n_tools tools (parallel; total conversions not aggregated)."
|
||||
else
|
||||
info "Done. Total conversions: $total"
|
||||
fi
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
||||
Reference in New Issue
Block a user