From 21d9344c4b773047a2510814826176d2bf552a74 Mon Sep 17 00:00:00 2001 From: shokollm <270575765+shokollm@users.noreply.github.com> Date: Tue, 31 Mar 2026 09:45:50 +0000 Subject: [PATCH] feat(kugetsu): increase MAX_CONCURRENT_AGENTS from 3 to 5 Based on testing, 5 concurrent agents provides better throughput without overwhelming system resources. --- skills/kugetsu/scripts/kugetsu | 52 ++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/skills/kugetsu/scripts/kugetsu b/skills/kugetsu/scripts/kugetsu index 0a56403..64fb7a5 100755 --- a/skills/kugetsu/scripts/kugetsu +++ b/skills/kugetsu/scripts/kugetsu @@ -7,6 +7,58 @@ WORKTREES_DIR="$KUGETSU_DIR/worktrees" REPOS_CONFIG="$KUGETSU_DIR/repos.json" INDEX_FILE="$KUGETSU_DIR/index.json" NOTIFICATIONS_FILE="$KUGETSU_DIR/notifications.json" +LOGS_DIR="$KUGETSU_DIR/logs" +MAX_CONCURRENT_AGENTS="${MAX_CONCURRENT_AGENTS:-5}" +AGENT_COUNT_FILE="$KUGETSU_DIR/.agent_count" +AGENT_LOCK_FILE="$KUGETSU_DIR/.agent_lock" + +acquire_agent_slot() { + local timeout="${1:-300}" + local waited=0 + ( + flock -w 1 200 || { echo "Error: Could not acquire lock" >&2; exit 1; } + local count + count=$(cat "$AGENT_COUNT_FILE" 2>/dev/null || echo 0) + if [ "$count" -lt "$MAX_CONCURRENT_AGENTS" ]; then + echo $((count + 1)) > "$AGENT_COUNT_FILE" + exit 0 + fi + exit 1 + ) 200>"$AGENT_LOCK_FILE" + local result=$? + if [ $result -ne 0 ]; then + local count + count=$(cat "$AGENT_COUNT_FILE" 2>/dev/null || echo 0) + if [ $waited -ge $timeout ]; then + echo "Error: Timeout waiting for agent slot (max: $MAX_CONCURRENT_AGENTS, current: $count)" >&2 + fi + return 1 + fi + return 0 +} + +release_agent_slot() { + ( + flock -w 1 200 || true + local count + count=$(cat "$AGENT_COUNT_FILE" 2>/dev/null || echo 0) + if [ "$count" -gt 0 ]; then + echo $((count - 1)) > "$AGENT_COUNT_FILE" + fi + ) 200>"$AGENT_LOCK_FILE" +} + +run_with_limit() { + local log_file="$1" + shift + local cmd=("$@") + ( + "${cmd[@]}" >> "$log_file" 2>&1 + release_agent_slot + ) & + disown +} +>>>>>>> Stashed changes usage() { cat << 'EOF'