Merge pull request '@senior: One comment per agent run' (#39) from ai/issue-38 into main
Reviewed-on: ffaerber/agents#39
This commit was merged in pull request #39.
This commit is contained in:
@@ -39,7 +39,6 @@ if [ "$MODE" != "pr" ]; then
|
|||||||
# Visible comment: the reply text, or a sensible line if the agent only emitted a marker.
|
# Visible comment: the reply text, or a sensible line if the agent only emitted a marker.
|
||||||
msg="$reply"
|
msg="$reply"
|
||||||
case "$msg" in ""|"_(Made changes"*) msg=$([ -n "$target" ] && echo "Handing off to @$target." || echo "_(no further comment)_") ;; esac
|
case "$msg" in ""|"_(Made changes"*) msg=$([ -n "$target" ] && echo "Handing off to @$target." || echo "_(no further comment)_") ;; esac
|
||||||
post "$(printf '🤖 **@%s**\n\n%s' "$NAME" "$msg")"
|
|
||||||
# Close the issue if the agent flagged it (maintainer said it's not needed / duplicate).
|
# Close the issue if the agent flagged it (maintainer said it's not needed / duplicate).
|
||||||
if grep -qiE '^[[:space:]]*CLOSE_ISSUE[[:space:]]*$' /tmp/agent_out.md; then
|
if grep -qiE '^[[:space:]]*CLOSE_ISSUE[[:space:]]*$' /tmp/agent_out.md; then
|
||||||
echo "closing issue #$NUM"
|
echo "closing issue #$NUM"
|
||||||
@@ -48,6 +47,9 @@ if [ "$MODE" != "pr" ]; then
|
|||||||
fi
|
fi
|
||||||
# BREAKDOWN: from a BEGIN_SUBTASKS block, create a milestone + one sub-issue per line
|
# BREAKDOWN: from a BEGIN_SUBTASKS block, create a milestone + one sub-issue per line
|
||||||
# (linked to this issue). Sub-issues are NOT auto-started — maintainer mentions agents later.
|
# (linked to this issue). Sub-issues are NOT auto-started — maintainer mentions agents later.
|
||||||
|
# Process subtasks first so we can append the created-issues list to the SAME comment as
|
||||||
|
# the reply (issue #38 — one comment per run).
|
||||||
|
subtext=""
|
||||||
if grep -qiE '^[[:space:]]*BEGIN_SUBTASKS' /tmp/agent_out.md; then
|
if grep -qiE '^[[:space:]]*BEGIN_SUBTASKS' /tmp/agent_out.md; then
|
||||||
block=$(awk '/^[[:space:]]*BEGIN_SUBTASKS/{f=1;next} /^[[:space:]]*END_SUBTASKS/{f=0} f' /tmp/agent_out.md)
|
block=$(awk '/^[[:space:]]*BEGIN_SUBTASKS/{f=1;next} /^[[:space:]]*END_SUBTASKS/{f=0} f' /tmp/agent_out.md)
|
||||||
ms=$(printf '%s\n' "$block" | sed -nE 's/^[[:space:]]*milestone:[[:space:]]*//Ip' | head -1)
|
ms=$(printf '%s\n' "$block" | sed -nE 's/^[[:space:]]*milestone:[[:space:]]*//Ip' | head -1)
|
||||||
@@ -75,8 +77,9 @@ if [ "$MODE" != "pr" ]; then
|
|||||||
echo "created sub-issue #${n:-?}: $title"
|
echo "created sub-issue #${n:-?}: $title"
|
||||||
[ -n "$n" ] && links="$links\n- #$n — $title"
|
[ -n "$n" ] && links="$links\n- #$n — $title"
|
||||||
done < /tmp/subtasks.txt
|
done < /tmp/subtasks.txt
|
||||||
post "$(printf '🤖 **@%s** — created sub-issues%s (mention an agent on each when ready):%b' "$NAME" "${ms:+ under milestone **$ms**}" "$links")"
|
subtext=$(printf '\n\n---\n🤖 **@%s** — created sub-issues%s (mention an agent on each when ready):%b' "$NAME" "${ms:+ under milestone **$ms**}" "$links")
|
||||||
fi
|
fi
|
||||||
|
post "$(printf '🤖 **@%s**\n\n%s%s' "$NAME" "$msg" "$subtext")"
|
||||||
# Auto-delegate: if the plan names a teammate, trigger them via AGENT_TOKEN (a PAT, so it
|
# Auto-delegate: if the plan names a teammate, trigger them via AGENT_TOKEN (a PAT, so it
|
||||||
# fires a new workflow run — the built-in token cannot). Never targets @pm or self, so the
|
# fires a new workflow run — the built-in token cannot). Never targets @pm or self, so the
|
||||||
# chain always terminates at a dev. The '🤖' guard on the trigger stops status-comment loops.
|
# chain always terminates at a dev. The '🤖' guard on the trigger stops status-comment loops.
|
||||||
@@ -123,6 +126,16 @@ git fetch -q origin 2>/dev/null || true
|
|||||||
prbody=$(printf '%s\n\n---\nResolves #%s · 🤖 @%s' "$prdesc" "$NUM" "$NAME")
|
prbody=$(printf '%s\n\n---\nResolves #%s · 🤖 @%s' "$prdesc" "$NUM" "$NAME")
|
||||||
owner=${GITHUB_REPOSITORY%%/*}
|
owner=${GITHUB_REPOSITORY%%/*}
|
||||||
|
|
||||||
|
# Post the agent's activity trail (tool calls + reasoning) inline in the same comment so
|
||||||
|
# each run produces exactly ONE comment (issue #38). Computed once here so every dev-agent
|
||||||
|
# exit path (no-changes, PR-open-failed, normal) appends it to the single reply comment.
|
||||||
|
activity=""
|
||||||
|
if [ -s /tmp/activity_log.md ]; then
|
||||||
|
entries=$(wc -l < /tmp/activity_log.md 2>/dev/null || echo 0)
|
||||||
|
log=$(cat /tmp/activity_log.md)
|
||||||
|
activity=$(printf '\n\n---\n🤖 **@%s** — activity log (%s entries):\n<details>\n<summary>tool calls & reasoning</summary>\n\n%s\n\n</details>' "$NAME" "$entries" "$log")
|
||||||
|
fi
|
||||||
|
|
||||||
# One PR per run: publish ONLY this run's own branch ($BRANCH), never sibling
|
# One PR per run: publish ONLY this run's own branch ($BRANCH), never sibling
|
||||||
# ai/issue-N-* branches. This removes the multi-PR ambiguity that left the
|
# ai/issue-N-* branches. This removes the multi-PR ambiguity that left the
|
||||||
# activity log stranded on the triggering issue instead of the PR thread.
|
# activity log stranded on the triggering issue instead of the PR thread.
|
||||||
@@ -130,7 +143,7 @@ br="$BRANCH"
|
|||||||
ahead=$(git rev-list --count "origin/main..origin/$br" 2>/dev/null || echo 0)
|
ahead=$(git rev-list --count "origin/main..origin/$br" 2>/dev/null || echo 0)
|
||||||
if [ "${ahead:-0}" -eq 0 ]; then
|
if [ "${ahead:-0}" -eq 0 ]; then
|
||||||
# No changes on this branch — a plan / questions / analysis only.
|
# No changes on this branch — a plan / questions / analysis only.
|
||||||
post "$(printf '🤖 **@%s**\n\n%s' "$NAME" "$reply")"
|
post "$(printf '🤖 **@%s**\n\n%s%s' "$NAME" "$reply" "$activity")"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -148,7 +161,7 @@ if [ -z "$url" ]; then
|
|||||||
url=$(printf '%s' "$resp" | jq -r '.html_url // empty' 2>/dev/null)
|
url=$(printf '%s' "$resp" | jq -r '.html_url // empty' 2>/dev/null)
|
||||||
prnum=$(printf '%s' "$resp" | jq -r '.number // empty' 2>/dev/null)
|
prnum=$(printf '%s' "$resp" | jq -r '.number // empty' 2>/dev/null)
|
||||||
fi
|
fi
|
||||||
[ -z "$url" ] && { echo "PR open/lookup failed for $br — posting reply on issue instead"; post "$(printf '🤖 **@%s**\n\n%s' "$NAME" "$reply")"; exit 0; }
|
[ -z "$url" ] && { echo "PR open/lookup failed for $br — posting reply on issue instead"; post "$(printf '🤖 **@%s**\n\n%s%s' "$NAME" "$reply" "$activity")"; exit 0; }
|
||||||
|
|
||||||
# Posts to the PR thread when we have a PR number, else to the origin issue ($NUM).
|
# Posts to the PR thread when we have a PR number, else to the origin issue ($NUM).
|
||||||
prpost() {
|
prpost() {
|
||||||
@@ -160,17 +173,8 @@ prpost() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if [ "$NEW" = "true" ]; then
|
if [ "$NEW" = "true" ]; then
|
||||||
prpost "$prnum" "$(printf '🤖 **@%s** — ✅ PR ready for review — @ffaerber please review & merge:\n- %s' "$NAME" "$url")"
|
prpost "$prnum" "$(printf '🤖 **@%s** — ✅ PR ready for review — @ffaerber please review & merge:\n- %s%s' "$NAME" "$url" "$activity")"
|
||||||
else
|
else
|
||||||
# Resume (comment is on a PR thread): include the write-up here too.
|
# Resume (comment is on a PR thread): include the write-up here too.
|
||||||
prpost "$prnum" "$(printf '🤖 **@%s** — updated branch/PR:\n- %s\n\n%s' "$NAME" "$url" "$prdesc")"
|
prpost "$prnum" "$(printf '🤖 **@%s** — updated branch/PR:\n- %s\n\n%s%s' "$NAME" "$url" "$prdesc" "$activity")"
|
||||||
fi
|
|
||||||
|
|
||||||
# Post the agent's activity trail (tool calls + reasoning) as a separate comment so
|
|
||||||
# it is visible on the PR thread. Additive — kept here even when nothing changed, so a
|
|
||||||
# follow-up run (re-trigger) can see what this run did via the fetched issue thread.
|
|
||||||
if [ -s /tmp/activity_log.md ]; then
|
|
||||||
entries=$(wc -l < /tmp/activity_log.md 2>/dev/null || echo 0)
|
|
||||||
log=$(cat /tmp/activity_log.md)
|
|
||||||
prpost "$prnum" "$(printf '🤖 **@%s** — activity log (%s entries):\n<details>\n<summary>tool calls & reasoning</summary>\n\n%s\n\n</details>' "$NAME" "$entries" "$log")"
|
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user