Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
81882ee3ec | ||
|
|
1987ba792d | ||
|
|
a1ff1b9881 | ||
|
|
d803ee7cf5 | ||
|
|
1d248bc675 | ||
|
|
1fd32f0ff6 | ||
|
|
e9fad6bfad | ||
|
|
729a14f8bd | ||
|
|
d3c8f116f1 |
@@ -1,4 +1,5 @@
|
|||||||
name: ai-agent
|
name: ai-agent
|
||||||
|
run-name: "ai-agent · #${{ github.event.issue.number }}" # quotes required: bare # starts a YAML comment
|
||||||
# Standard caller for the shared AI-agent workflow (ffaerber/agents). Copy this file VERBATIM into
|
# Standard caller for the shared AI-agent workflow (ffaerber/agents). Copy this file VERBATIM into
|
||||||
# any repo that should get the agents — it is identical in every repo. All logic + scripts live in
|
# any repo that should get the agents — it is identical in every repo. All logic + scripts live in
|
||||||
# agents/.gitea/workflows/; scripts are fetched from @main at run time. The `jobs.agent` wrapper is
|
# agents/.gitea/workflows/; scripts are fetched from @main at run time. The `jobs.agent` wrapper is
|
||||||
|
|||||||
@@ -13,7 +13,13 @@ jq -r '
|
|||||||
def trunc(n): if length > n then (.[0:n] + "…") else . end;
|
def trunc(n): if length > n then (.[0:n] + "…") else . end;
|
||||||
select(.type=="tool_use" or .type=="text") |
|
select(.type=="tool_use" or .type=="text") |
|
||||||
if .type=="text" then
|
if .type=="text" then
|
||||||
"💬 " + ((.part.text // "") | trunc(4000))
|
# Drop the PR-description block from the reasoning trail — it is already published verbatim as
|
||||||
|
# the PR description, so repeating it here is redundant noise. Skip a text part that is nothing
|
||||||
|
# but that block (would otherwise be an empty "💬 " entry).
|
||||||
|
((.part.text // "")
|
||||||
|
| gsub("BEGIN_PR_DESCRIPTION.*?END_PR_DESCRIPTION"; ""; "m")
|
||||||
|
| gsub("\\A[[:space:]]+|[[:space:]]+\\z"; "")) as $t |
|
||||||
|
if $t == "" then empty else "💬 " + ($t | trunc(4000)) end
|
||||||
else
|
else
|
||||||
(.part.tool // "?") as $t |
|
(.part.tool // "?") as $t |
|
||||||
((.part.state.title // (.part.state.input | tojson | trunc(160)) // "")) as $title |
|
((.part.state.title // (.part.state.input | tojson | trunc(160)) // "")) as $title |
|
||||||
|
|||||||
@@ -18,14 +18,25 @@ hdr=(-H "Authorization: token $TOK" -H "Content-Type: application/json")
|
|||||||
post() { curl -sS -w 'comment -> HTTP %{http_code}\n' -X POST "${hdr[@]}" \
|
post() { curl -sS -w 'comment -> HTTP %{http_code}\n' -X POST "${hdr[@]}" \
|
||||||
"$API/issues/$NUM/comments" -d "$(jq -nc --arg b "$1" '{body:$b}')"; }
|
"$API/issues/$NUM/comments" -d "$(jq -nc --arg b "$1" '{body:$b}')"; }
|
||||||
|
|
||||||
# drop machine-readable markers (DELEGATE / CLOSE_ISSUE / the BEGIN_SUBTASKS..END_SUBTASKS block)
|
# drop machine-readable markers: DELEGATE / CLOSE_ISSUE, and the BEGIN_SUBTASKS..END_SUBTASKS and
|
||||||
|
# BEGIN_PR_DESCRIPTION..END_PR_DESCRIPTION blocks (the PR description is published separately).
|
||||||
reply=$(awk '
|
reply=$(awk '
|
||||||
/^[[:space:]]*BEGIN_SUBTASKS/{s=1}
|
/^[[:space:]]*BEGIN_SUBTASKS/{s=1}
|
||||||
|
/^[[:space:]]*BEGIN_PR_DESCRIPTION/{p=1}
|
||||||
/^[[:space:]]*DELEGATE:[[:space:]]*@/{next}
|
/^[[:space:]]*DELEGATE:[[:space:]]*@/{next}
|
||||||
/^[[:space:]]*CLOSE_ISSUE[[:space:]]*$/{next}
|
/^[[:space:]]*CLOSE_ISSUE[[:space:]]*$/{next}
|
||||||
s{ if(/^[[:space:]]*END_SUBTASKS/){s=0}; next }
|
s{ if(/^[[:space:]]*END_SUBTASKS/){s=0}; next }
|
||||||
|
p{ if(/^[[:space:]]*END_PR_DESCRIPTION/){p=0}; next }
|
||||||
{print}
|
{print}
|
||||||
' /tmp/agent_out.md 2>/dev/null)
|
' /tmp/agent_out.md 2>/dev/null)
|
||||||
|
# Strip a leading self-header the model sometimes emits ("🤖 **@pm**" on its own line) so we don't
|
||||||
|
# double it when we prepend our own. Removes a leading run of such header lines and blank lines.
|
||||||
|
reply=$(printf '%s' "$reply" | awk '
|
||||||
|
BEGIN{s=1}
|
||||||
|
s && /^[^A-Za-z0-9]*\*\*@[A-Za-z]+\*\*[[:space:]]*$/ {next}
|
||||||
|
s && /^[[:space:]]*$/ {next}
|
||||||
|
{s=0; print}
|
||||||
|
')
|
||||||
[ -z "$reply" ] && reply="_(Made changes without a text summary — see the diff below.)_"
|
[ -z "$reply" ] && reply="_(Made changes without a text summary — see the diff below.)_"
|
||||||
# Prefer the agent's clean delimited PR description; fall back to the whole reply.
|
# Prefer the agent's clean delimited PR description; fall back to the whole reply.
|
||||||
prdesc=$(awk '/BEGIN_PR_DESCRIPTION/{f=1;next} /END_PR_DESCRIPTION/{f=0} f' /tmp/agent_out.md)
|
prdesc=$(awk '/BEGIN_PR_DESCRIPTION/{f=1;next} /END_PR_DESCRIPTION/{f=0} f' /tmp/agent_out.md)
|
||||||
@@ -133,7 +144,7 @@ activity=""
|
|||||||
if [ -s /tmp/activity_log.md ]; then
|
if [ -s /tmp/activity_log.md ]; then
|
||||||
entries=$(wc -l < /tmp/activity_log.md 2>/dev/null || echo 0)
|
entries=$(wc -l < /tmp/activity_log.md 2>/dev/null || echo 0)
|
||||||
log=$(cat /tmp/activity_log.md)
|
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")
|
activity=$(printf '\n\n<details>\n<summary>🔧 activity — %s tool calls & reasoning</summary>\n\n%s\n\n</details>' "$entries" "$log")
|
||||||
fi
|
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
|
||||||
@@ -175,6 +186,7 @@ prpost() {
|
|||||||
if [ "$NEW" = "true" ]; then
|
if [ "$NEW" = "true" ]; then
|
||||||
prpost "$prnum" "$(printf '🤖 **@%s** — ✅ PR ready for review — @ffaerber please review & merge:\n- %s%s' "$NAME" "$url" "$activity")"
|
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: just link the PR — its body and the diff already carry the description, so we don't
|
||||||
prpost "$prnum" "$(printf '🤖 **@%s** — updated branch/PR:\n- %s\n\n%s%s' "$NAME" "$url" "$prdesc" "$activity")"
|
# repeat the full write-up in the comment (the reasoning trail below shows what this run did).
|
||||||
|
prpost "$prnum" "$(printf '🤖 **@%s** — pushed an update to the PR:\n- %s%s' "$NAME" "$url" "$activity")"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -55,7 +55,13 @@ if [ -n "$IS_PR" ]; then # comment on a PR -> resume its bra
|
|||||||
ref=$(curl -s -H "Authorization: token $GT" "$API/pulls/$NUM" | jq -r .head.ref)
|
ref=$(curl -s -H "Authorization: token $GT" "$API/pulls/$NUM" | jq -r .head.ref)
|
||||||
git fetch origin "$ref" && git checkout "$ref"
|
git fetch origin "$ref" && git checkout "$ref"
|
||||||
{ echo "branch=$ref"; echo "new=false"; } >> "$GITHUB_OUTPUT"
|
{ echo "branch=$ref"; echo "new=false"; } >> "$GITHUB_OUTPUT"
|
||||||
else # comment on an issue -> new branch
|
elif git ls-remote --exit-code --heads origin "ai/issue-$NUM" >/dev/null 2>&1; then
|
||||||
|
# comment on an issue whose branch ALREADY exists (a prior run / open PR) -> RESUME it, so new
|
||||||
|
# commits fast-forward onto the same branch and update its PR. Branching fresh from main here would
|
||||||
|
# be rejected on push as non-fast-forward and the new work would be silently lost (see issue #17).
|
||||||
|
git fetch origin "ai/issue-$NUM" && git checkout "ai/issue-$NUM"
|
||||||
|
{ echo "branch=ai/issue-$NUM"; echo "new=false"; } >> "$GITHUB_OUTPUT"
|
||||||
|
else # comment on an issue, no branch yet -> new branch
|
||||||
git checkout -b "ai/issue-$NUM"
|
git checkout -b "ai/issue-$NUM"
|
||||||
{ echo "branch=ai/issue-$NUM"; echo "new=true"; } >> "$GITHUB_OUTPUT"
|
{ echo "branch=ai/issue-$NUM"; echo "new=true"; } >> "$GITHUB_OUTPUT"
|
||||||
# For dev agents, publish the branch immediately and tell the maintainer where to watch.
|
# For dev agents, publish the branch immediately and tell the maintainer where to watch.
|
||||||
|
|||||||
@@ -35,10 +35,12 @@ it is the source of truth, and `agents` itself uses the same file:
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
name: ai-agent
|
name: ai-agent
|
||||||
|
run-name: "ai-agent · #${{ github.event.issue.number }}" # quotes required: bare # starts a YAML comment
|
||||||
# Standard caller for the shared AI-agent workflow (ffaerber/agents). Copy this file VERBATIM into
|
# Standard caller for the shared AI-agent workflow (ffaerber/agents). Copy this file VERBATIM into
|
||||||
# any repo that should get the agents — it is identical in every repo. All logic + scripts live in
|
# any repo that should get the agents — it is identical in every repo. All logic + scripts live in
|
||||||
# agents/.gitea/workflows/; scripts are fetched from @main at run time. The `jobs.agent` wrapper is
|
# agents/.gitea/workflows/; scripts are fetched from @main at run time. The `jobs.agent` wrapper is
|
||||||
# required: a reusable (workflow_call) workflow can only be invoked from a caller job, not top-level.
|
# required: a reusable (workflow_call) workflow can only be invoked from a caller job, not top-level.
|
||||||
|
# `run-name` titles each run by the triggering issue (e.g. "ai-agent · #42") in the Actions list.
|
||||||
on:
|
on:
|
||||||
issue_comment:
|
issue_comment:
|
||||||
types: [created]
|
types: [created]
|
||||||
|
|||||||
Reference in New Issue
Block a user