diff --git a/.agents/scripts/supervisor-helper.sh b/.agents/scripts/supervisor-helper.sh index 096352b03..2cdab53a5 100755 --- a/.agents/scripts/supervisor-helper.sh +++ b/.agents/scripts/supervisor-helper.sh @@ -10212,6 +10212,105 @@ cmd_pulse() { bash "$coderabbit_pulse_script" run --repo "$pulse_repo" --quiet 2>>"$SUPERVISOR_LOG" || true fi + # Phase 10b: Auto-create TODO tasks from quality findings (t299) + # Converts CodeRabbit and quality-sweep findings into actionable TODO tasks with #auto-dispatch. + # Self-throttles with 24h cooldown to avoid task spam. + local task_creation_cooldown=86400 # 24 hours in seconds + local task_creation_state_file="${SUPERVISOR_DIR}/last-task-creation.json" + local should_create_tasks=false + + # Check cooldown + if [[ -f "$task_creation_state_file" ]]; then + local last_run + last_run=$(jq -r '.timestamp // 0' "$task_creation_state_file" 2>/dev/null || echo "0") + local now + now=$(date +%s) + local age=$((now - last_run)) + + if [[ "$age" -ge "$task_creation_cooldown" ]]; then + should_create_tasks=true + log_verbose " Phase 10b: Task creation cooldown expired (${age}s >= ${task_creation_cooldown}s)" + else + local remaining=$((task_creation_cooldown - age)) + log_verbose " Phase 10b: Task creation cooldown active (${remaining}s remaining)" + fi + else + should_create_tasks=true + log_verbose " Phase 10b: First task creation run" + fi + + if [[ "$should_create_tasks" == "true" ]]; then + log_verbose " Phase 10b: Creating tasks from quality findings" + + # Get repo path for TODO.md + local pulse_repo="" + pulse_repo=$(db "$SUPERVISOR_DB" "SELECT DISTINCT repo FROM tasks LIMIT 1;" 2>/dev/null || echo "") + if [[ -z "$pulse_repo" ]]; then + pulse_repo="$(pwd)" + fi + + local todo_file="${pulse_repo}/TODO.md" + local tasks_created=false + + # Create tasks from CodeRabbit findings + local coderabbit_creator="${SCRIPT_DIR}/coderabbit-task-creator-helper.sh" + if [[ -x "$coderabbit_creator" ]]; then + log_verbose " Converting CodeRabbit findings to tasks..." + local coderabbit_output + coderabbit_output=$("$coderabbit_creator" create 2>>"$SUPERVISOR_LOG" || true) + + if [[ -n "$coderabbit_output" ]] && echo "$coderabbit_output" | grep -q "^- \[ \]"; then + # Append tasks to TODO.md + echo "" >> "$todo_file" + echo "$coderabbit_output" >> "$todo_file" + tasks_created=true + local task_count + task_count=$(echo "$coderabbit_output" | grep -c "^- \[ \]" || echo "0") + log_verbose " Created $task_count tasks from CodeRabbit findings" + fi + fi + + # Create tasks from quality-sweep findings (SonarCloud, Codacy) + local finding_to_task="${SCRIPT_DIR}/finding-to-task-helper.sh" + if [[ -x "$finding_to_task" ]]; then + log_verbose " Converting quality-sweep findings to tasks..." + local sweep_output + sweep_output=$("$finding_to_task" create --min-severity medium --limit 10 2>>"$SUPERVISOR_LOG" || true) + + if [[ -n "$sweep_output" ]] && echo "$sweep_output" | grep -q "^- \[ \]"; then + # Append tasks to TODO.md + echo "" >> "$todo_file" + echo "$sweep_output" >> "$todo_file" + tasks_created=true + local task_count + task_count=$(echo "$sweep_output" | grep -c "^- \[ \]" || echo "0") + log_verbose " Created $task_count tasks from quality-sweep findings" + fi + fi + + # Commit and push TODO.md if tasks were created + if [[ "$tasks_created" == "true" ]]; then + log_verbose " Committing and pushing TODO.md updates..." + ( + cd "$pulse_repo" || exit 1 + git add TODO.md 2>>"$SUPERVISOR_LOG" || true + git commit -m "chore: auto-create tasks from quality findings (t299)" 2>>"$SUPERVISOR_LOG" || true + git push 2>>"$SUPERVISOR_LOG" || true + ) + fi + + # Update cooldown state + mkdir -p "$SUPERVISOR_DIR" + cat > "$task_creation_state_file" << EOF +{ + "timestamp": $(date +%s), + "date": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")", + "tasks_created": $tasks_created +} +EOF + log_verbose " Phase 10b: Task creation complete" + fi + # Phase 11: Supervisor session memory monitoring + respawn (t264, t264.1) # OpenCode/Bun processes accumulate WebKit malloc dirty pages that are never # returned to the OS. Over long sessions, a single process can grow to 25GB+.