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
36 changes: 19 additions & 17 deletions .agents/scripts/supervisor-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2595,29 +2595,30 @@ build_dispatch_cmd() {
$memory_context"
fi

# Use NUL-delimited output so multi-line prompts stay as single arguments
if [[ "$ai_cli" == "opencode" ]]; then
echo "opencode"
echo "run"
echo "--format"
echo "json"
printf '%s\0' "opencode"
printf '%s\0' "run"
printf '%s\0' "--format"
printf '%s\0' "json"
if [[ -n "$model" ]]; then
echo "-m"
echo "$model"
printf '%s\0' "-m"
printf '%s\0' "$model"
fi
echo "--title"
echo "$task_id"
echo "$prompt"
printf '%s\0' "--title"
printf '%s\0' "$task_id"
printf '%s\0' "$prompt"
else
# claude CLI
echo "claude"
echo "-p"
echo "$prompt"
printf '%s\0' "claude"
printf '%s\0' "-p"
printf '%s\0' "$prompt"
if [[ -n "$model" ]]; then
echo "--model"
echo "$model"
printf '%s\0' "--model"
printf '%s\0' "$model"
fi
echo "--output-format"
echo "json"
printf '%s\0' "--output-format"
printf '%s\0' "json"
fi
Comment on lines 2599 to 2622

Choose a reason for hiding this comment

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

medium

This block contains a number of repetitive printf calls. To improve readability and maintainability, you can build an array of command parts first and then print all elements at once with a single printf call. This approach reduces code duplication.

Suggested change
if [[ "$ai_cli" == "opencode" ]]; then
echo "opencode"
echo "run"
echo "--format"
echo "json"
printf '%s\0' "opencode"
printf '%s\0' "run"
printf '%s\0' "--format"
printf '%s\0' "json"
if [[ -n "$model" ]]; then
echo "-m"
echo "$model"
printf '%s\0' "-m"
printf '%s\0' "$model"
fi
echo "--title"
echo "$task_id"
echo "$prompt"
printf '%s\0' "--title"
printf '%s\0' "$task_id"
printf '%s\0' "$prompt"
else
# claude CLI
echo "claude"
echo "-p"
echo "$prompt"
printf '%s\0' "claude"
printf '%s\0' "-p"
printf '%s\0' "$prompt"
if [[ -n "$model" ]]; then
echo "--model"
echo "$model"
printf '%s\0' "--model"
printf '%s\0' "$model"
fi
echo "--output-format"
echo "json"
printf '%s\0' "--output-format"
printf '%s\0' "json"
fi
local -a cmd_parts=()
if [[ "$ai_cli" == "opencode" ]]; then
cmd_parts+=("opencode" "run" "--format" "json")
if [[ -n "$model" ]]; then
cmd_parts+=("-m" "$model")
fi
cmd_parts+=("--title" "$task_id" "$prompt")
else
# claude CLI
cmd_parts+=("claude" "-p" "$prompt")
if [[ -n "$model" ]]; then
cmd_parts+=("--model" "$model")
fi
cmd_parts+=("--output-format" "json")
fi
printf '%s\0' "${cmd_parts[@]}"
References
  1. The style guide recommends using bash arrays for dynamic command construction. While the original rule is to avoid eval, applying the same principle of using arrays here improves code clarity and maintainability. (link)


return 0
Expand Down Expand Up @@ -3101,8 +3102,9 @@ cmd_dispatch() {
log_info "Log: $log_file"

# Build and execute dispatch command
# Use NUL-delimited read to preserve multi-line prompts as single arguments
local -a cmd_parts=()
while IFS= read -r part; do
while IFS= read -r -d '' part; do
cmd_parts+=("$part")
done < <(build_dispatch_cmd "$task_id" "$worktree_path" "$log_file" "$ai_cli" "$memory_context" "$tmodel" "$tdesc")
Comment on lines 3106 to 3109

Choose a reason for hiding this comment

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

medium

The while read loop for populating the cmd_parts array is functional, but a more concise and idiomatic approach in modern bash is to use mapfile (also known as readarray). It's designed for this exact purpose of reading stream data into an array, making the code shorter and more efficient.

Suggested change
local -a cmd_parts=()
while IFS= read -r part; do
while IFS= read -r -d '' part; do
cmd_parts+=("$part")
done < <(build_dispatch_cmd "$task_id" "$worktree_path" "$log_file" "$ai_cli" "$memory_context" "$tmodel" "$tdesc")
local -a cmd_parts
mapfile -d '' -t cmd_parts < <(build_dispatch_cmd "$task_id" "$worktree_path" "$log_file" "$ai_cli" "$memory_context" "$tmodel" "$tdesc")
References
  1. Using mapfile or readarray is a modern bash best practice for reading command output or file content directly into an array, replacing more verbose while read loops.


Expand Down
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Tasks with no open blockers - ready to work on. Use `/ready` to refresh this lis
- Notes: PR #642 merged. Added `--headless` flag to full-loop for autonomous worker operation.

- [ ] t175 Fix `ambiguous_skipped_ai` evaluation — add better heuristic signals #bug #supervisor ~1h (ai:40m) ref:GH#644 assignee:marcusquinn started:2026-02-08T19:38:50Z logged:2026-02-08
- Notes: Recurring evaluation outcome across batches. Evaluator can't determine success/failure, skips AI eval, defaults to retry. Add heuristics: check for commits on branch, check for uncommitted changes in worktree.
- Notes: Recurring evaluation outcome across batches. Evaluator can't determine success/failure, skips AI eval, defaults to retry. Add heuristics: check for commits on branch, check for uncommitted changes in worktree. BLOCKED: Re-prompt dispatch failed: ambiguous_skipped_ai

- [ ] t176 Add uncertainty guidance to worker dispatch prompt #feature #supervisor ~30m (ai:20m) ref:GH#645 assignee:marcusquinn started:2026-02-08T19:38:55Z logged:2026-02-08
- Notes: Workers don't know when to make autonomous decisions vs flag uncertainty. Add decision framework to dispatch prompt for headless workers.
Expand Down
Loading