Files
codex/agentydragon/tasks/launch-commit-agent.sh
Rai (Michael Pokorny) 44bf98533b wip
2025-06-25 01:43:20 -07:00

70 lines
2.1 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# launch-commit-agent.sh
#
# Launch the non-interactive Codex Commit agent for a given task worktree,
# using the prompt in prompts/commit.md and the task's Markdown file.
#
# Usage: launch-commit-agent.sh <task-slug|NN> [<task-slug|NN>...]
set -euo pipefail
# Allocate a temporary file to capture the agent's commit message
last_message_file="$(mktemp)"
trap 'rm -f "$last_message_file"' EXIT
# Usage: one or more task IDs or slugs
if [ "$#" -lt 1 ]; then
echo "Usage: $0 <task-slug|NN> [<task-slug|NN>...]" >&2
exit 1
fi
# Locate repository and tasks directory; commit prompt is constant
repo_root=$(git rev-parse --show-toplevel)
tasks_dir="$repo_root/agentydragon/tasks"
prompt_file="$repo_root/agentydragon/prompts/commit.md"
for input in "$@"; do
# Resolve numeric ID to full slug if needed
if [[ "$input" =~ ^[0-9]{2}$ ]]; then
matches=("$tasks_dir/${input}-"*.md)
if [ "${#matches[@]}" -eq 1 ]; then
task_slug="$(basename "${matches[0]}" .md)"
echo "Resolved task ID '$input' to slug '$task_slug'"
else
echo "Error: expected exactly one task file matching '${input}-*.md', found ${#matches[@]}" >&2
exit 1
fi
else
task_slug="$input"
fi
# Paths for worktree and task file
worktrees_dir="$tasks_dir/.worktrees"
worktree_path="$worktrees_dir/$task_slug"
task_file="$tasks_dir/$task_slug.md"
# Preconditions
if [ ! -d "$worktree_path" ]; then
echo "Error: worktree for '$task_slug' not found; run create-task-worktree.sh first" >&2
exit 1
fi
if [ ! -f "$prompt_file" ]; then
echo "Error: commit prompt not found at $prompt_file" >&2
exit 1
fi
if [ ! -f "$task_file" ]; then
echo "Error: task file not found at $task_file" >&2
exit 1
fi
# Perform commit in the task worktree
echo "--- Processing task $task_slug ---"
cd "$worktree_path"
cmd=(codex --full-auto exec --output-last-message "$last_message_file")
echo "Running: ${cmd[*]}"
# Write the agent's final message to file, then commit using that file
"${cmd[@]}" "$(<"$prompt_file")"$'\n\n'"$(<"$task_file")"
git add -u
git commit -F "$last_message_file"
done