Compare commits
12
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0a06c813bc | ||
|
|
c4fb117b93 | ||
|
|
eeae1fdaaa | ||
|
|
7abbbb1b8d | ||
|
|
95bc254640 | ||
|
|
75a2493dee | ||
|
|
53ac2b7ba8 | ||
|
|
4b73d0b8e9 | ||
|
|
b587a7d9a7 | ||
|
|
ef43d69309 | ||
|
|
63d9147cd7 | ||
|
|
e9df9d6bdd |
+61
-19
@@ -5,12 +5,20 @@ name: agent
|
||||
on:
|
||||
workflow_call:
|
||||
|
||||
# Pinned opencode version — used to install it and to key the CI cache below.
|
||||
env:
|
||||
OPENCODE_VERSION: "1.17.13"
|
||||
|
||||
jobs:
|
||||
|
||||
agent:
|
||||
# One run at a time PER ISSUE: two quick comments on the same issue would otherwise race —
|
||||
# both checking out ai/issue-N, pushing (non-fast-forward loss) and double-posting. Queued
|
||||
# runs wait (no cancel) so every trigger is still processed, just serially.
|
||||
# KNOWN CAVEAT: a run triggered on the PR thread groups under the PR number, not the origin
|
||||
# issue (that mapping is only resolved later, in route.sh) — so an issue-thread run and a
|
||||
# PR-thread run for the SAME work item can overlap. Accepted: they post to different threads,
|
||||
# and the branch is only mutated by dev runs, which resume serially per thread.
|
||||
concurrency:
|
||||
group: ai-agent-${{ github.repository }}-${{ github.event.issue.number }}
|
||||
cancel-in-progress: false
|
||||
@@ -40,17 +48,6 @@ jobs:
|
||||
# job must never hold the single runner slot for hours.
|
||||
timeout-minutes: 45
|
||||
steps:
|
||||
- name: Acknowledge with 👀
|
||||
env:
|
||||
GT: ${{ secrets.GITEA_TOKEN }}
|
||||
CID: ${{ github.event.comment.id }}
|
||||
NUM: ${{ github.event.issue.number }}
|
||||
run: |
|
||||
B="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}/issues"
|
||||
if [ -n "$CID" ]; then R="$B/comments/$CID/reactions"; else R="$B/$NUM/reactions"; fi
|
||||
curl -sS -X POST -H "Authorization: token $GT" -H "Content-Type: application/json" \
|
||||
"$R" -d '{"content":"eyes"}' -w '\nreact -> HTTP %{http_code}\n' || true
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
@@ -115,7 +112,39 @@ jobs:
|
||||
TOKEN_INTERN: ${{ secrets.TOKEN_INTERN }}
|
||||
run: bash "$SCRIPTS/route.sh"
|
||||
|
||||
- name: Acknowledge with 👀 (as the routed agent)
|
||||
if: steps.prep.outputs.mode != 'skip'
|
||||
env:
|
||||
SELF_TOKEN: ${{ steps.prep.outputs.name == 'pm' && secrets.TOKEN_PM || steps.prep.outputs.name == 'junior' && secrets.TOKEN_JUNIOR || steps.prep.outputs.name == 'senior' && secrets.TOKEN_SENIOR || steps.prep.outputs.name == 'lead' && secrets.TOKEN_LEAD || steps.prep.outputs.name == 'qa' && secrets.TOKEN_QA || steps.prep.outputs.name == 'ops' && secrets.TOKEN_OPS || steps.prep.outputs.name == 'intern' && secrets.TOKEN_INTERN || '' }}
|
||||
CID: ${{ github.event.comment.id }}
|
||||
NUM: ${{ github.event.issue.number }}
|
||||
run: |
|
||||
[ -n "$SELF_TOKEN" ] || { echo "no agent token — skipping 👀"; exit 0; }
|
||||
B="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}/issues"
|
||||
if [ -n "$CID" ]; then R="$B/comments/$CID/reactions"; else R="$B/$NUM/reactions"; fi
|
||||
curl -sS -X POST -H "Authorization: token $SELF_TOKEN" -H "Content-Type: application/json" \
|
||||
"$R" -d '{"content":"eyes"}' -w '\nreact -> HTTP %{http_code}\n' || true
|
||||
|
||||
- name: Cache opencode CLI
|
||||
if: steps.prep.outputs.mode != 'skip'
|
||||
continue-on-error: true # a cache backend hiccup must never fail an agent run
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.opencode
|
||||
key: opencode-${{ runner.os }}-${{ env.OPENCODE_VERSION }}
|
||||
|
||||
- name: Cache Playwright browsers + npm (browser agents only)
|
||||
if: steps.prep.outputs.mode != 'skip' && (steps.prep.outputs.name == 'senior' || steps.prep.outputs.name == 'lead' || steps.prep.outputs.name == 'qa')
|
||||
continue-on-error: true
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.cache/ms-playwright
|
||||
~/.npm
|
||||
key: playwright-npm-${{ runner.os }}-v1
|
||||
|
||||
- name: Install opencode + provider config (+ Playwright MCP for browser agents)
|
||||
if: steps.prep.outputs.mode != 'skip'
|
||||
env:
|
||||
SCRIPTS: ${{ runner.temp }}/agents-scripts
|
||||
OLLAMA_URL: ${{ secrets.OLLAMA_URL }}
|
||||
@@ -125,6 +154,7 @@ jobs:
|
||||
run: bash "$SCRIPTS/install-opencode.sh"
|
||||
|
||||
- name: Install caller-provided skills (from the caller repo's .gitea/agent-skills/)
|
||||
if: steps.prep.outputs.mode != 'skip'
|
||||
# Framework skill-plugin hook. A consuming repo can ship its OWN opencode skills under
|
||||
# `.gitea/agent-skills/<name>/` (SKILL.md + skill.json + optional setup.sh) — e.g. homelab's
|
||||
# "ssh into the deploy host" skill. This installs the ones allowed for the running agent, so
|
||||
@@ -139,6 +169,7 @@ jobs:
|
||||
run: bash "$SCRIPTS/install-caller-skills.sh"
|
||||
|
||||
- name: Set up `gitea-api` skill (let agents read/write issues, PRs, Actions across repos)
|
||||
if: steps.prep.outputs.mode != 'skip'
|
||||
# Emits an opencode Skill file. The skill uses SELF_TOKEN — the running agent's OWN token
|
||||
# (e.g. TOKEN_PM for @pm), injected into the Run-agent step below — so each agent talks to
|
||||
# Gitea as itself. This step only writes the doc; permission.skill scopes who may load it.
|
||||
@@ -147,6 +178,7 @@ jobs:
|
||||
run: bash "$SCRIPTS/skill-gitea-api.sh"
|
||||
|
||||
- name: Set up `gitea-admin` skill (@ops only — administer the Gitea instance)
|
||||
if: steps.prep.outputs.mode != 'skip'
|
||||
# Instance administration (orgs/users/repos/labels/secrets/scoped tokens). The SKILL.md is
|
||||
# written ONLY for @ops (skill-gitea-admin.sh gates on NAME) and permission.skill also denies
|
||||
# it to every other agent. It uses SELF_TOKEN (which for @ops is TOKEN_OPS), injected into the
|
||||
@@ -157,6 +189,7 @@ jobs:
|
||||
run: bash "$SCRIPTS/skill-gitea-admin.sh"
|
||||
|
||||
- name: Inspect / fetch image attachments (download only for vision agents)
|
||||
if: steps.prep.outputs.mode != 'skip'
|
||||
id: imgs
|
||||
env:
|
||||
SCRIPTS: ${{ runner.temp }}/agents-scripts
|
||||
@@ -166,6 +199,7 @@ jobs:
|
||||
run: bash "$SCRIPTS/fetch-images.sh"
|
||||
|
||||
- name: Fetch the full issue thread (shared memory)
|
||||
if: steps.prep.outputs.mode != 'skip'
|
||||
env:
|
||||
SCRIPTS: ${{ runner.temp }}/agents-scripts
|
||||
GT: ${{ secrets.GITEA_TOKEN }}
|
||||
@@ -173,6 +207,7 @@ jobs:
|
||||
run: bash "$SCRIPTS/fetch-thread.sh"
|
||||
|
||||
- name: Run agent
|
||||
if: steps.prep.outputs.mode != 'skip'
|
||||
id: run
|
||||
env:
|
||||
SCRIPTS: ${{ runner.temp }}/agents-scripts
|
||||
@@ -187,6 +222,7 @@ jobs:
|
||||
MODEL: ${{ steps.prep.outputs.model }}
|
||||
VISION: ${{ steps.prep.outputs.vision }}
|
||||
MODE: ${{ steps.prep.outputs.mode }}
|
||||
WORKMODE: ${{ steps.prep.outputs.workmode }} # build | discuss (devs consulted in-thread)
|
||||
HAS_IMAGES: ${{ steps.imgs.outputs.has_images }}
|
||||
BRANCH: ${{ steps.prep.outputs.branch }}
|
||||
AUTOPILOT: ${{ steps.prep.outputs.autopilot }} # 'true' when the issue carries the `autopilot` label
|
||||
@@ -198,6 +234,7 @@ jobs:
|
||||
run: bash "$SCRIPTS/run-agent.sh"
|
||||
|
||||
- name: Build run report (tool calls + input/output tokens + $ cost) from the event stream
|
||||
if: steps.prep.outputs.mode != 'skip'
|
||||
id: log
|
||||
env:
|
||||
SCRIPTS: ${{ runner.temp }}/agents-scripts
|
||||
@@ -206,6 +243,7 @@ jobs:
|
||||
run: bash "$SCRIPTS/build-activity-log.sh"
|
||||
|
||||
- name: Publish — PR (dev agents) or comment (pm), always reply in the issue
|
||||
if: steps.prep.outputs.mode != 'skip'
|
||||
env:
|
||||
SCRIPTS: ${{ runner.temp }}/agents-scripts
|
||||
GT: ${{ secrets.GITEA_TOKEN }}
|
||||
@@ -218,6 +256,7 @@ jobs:
|
||||
TOKEN_INTERN: ${{ secrets.TOKEN_INTERN }}
|
||||
NAME: ${{ steps.prep.outputs.name }}
|
||||
MODE: ${{ steps.prep.outputs.mode }}
|
||||
WORKMODE: ${{ steps.prep.outputs.workmode }}
|
||||
NUM: ${{ github.event.issue.number }}
|
||||
TITLE: ${{ github.event.issue.title }}
|
||||
BRANCH: ${{ steps.prep.outputs.branch }}
|
||||
@@ -232,7 +271,7 @@ jobs:
|
||||
# This best-effort step opens a PR for the pushed branch so nothing is silently lost. Runs from
|
||||
# $SCRIPTS (outside the workspace) so it works even if the tree was mangled by the agent.
|
||||
- name: Rescue — open a PR for pushed work if the run failed
|
||||
if: failure()
|
||||
if: failure() && steps.prep.outputs.mode != 'skip'
|
||||
env:
|
||||
SCRIPTS: ${{ runner.temp }}/agents-scripts
|
||||
GT: ${{ secrets.GITEA_TOKEN }}
|
||||
@@ -251,24 +290,27 @@ jobs:
|
||||
run: bash "$SCRIPTS/rescue-pr.sh" || true
|
||||
|
||||
- name: Mark done with 🚀 (remove 👀)
|
||||
if: steps.prep.outputs.mode != 'skip'
|
||||
env:
|
||||
GT: ${{ secrets.GITEA_TOKEN }}
|
||||
SELF_TOKEN: ${{ steps.prep.outputs.name == 'pm' && secrets.TOKEN_PM || steps.prep.outputs.name == 'junior' && secrets.TOKEN_JUNIOR || steps.prep.outputs.name == 'senior' && secrets.TOKEN_SENIOR || steps.prep.outputs.name == 'lead' && secrets.TOKEN_LEAD || steps.prep.outputs.name == 'qa' && secrets.TOKEN_QA || steps.prep.outputs.name == 'ops' && secrets.TOKEN_OPS || steps.prep.outputs.name == 'intern' && secrets.TOKEN_INTERN || '' }}
|
||||
CID: ${{ github.event.comment.id }}
|
||||
NUM: ${{ github.event.issue.number }}
|
||||
run: |
|
||||
[ -n "$SELF_TOKEN" ] || exit 0
|
||||
B="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}/issues"
|
||||
if [ -n "$CID" ]; then R="$B/comments/$CID/reactions"; else R="$B/$NUM/reactions"; fi
|
||||
curl -sS -X DELETE -H "Authorization: token $GT" -H "Content-Type: application/json" "$R" -d '{"content":"eyes"}' || true
|
||||
curl -sS -X POST -H "Authorization: token $GT" -H "Content-Type: application/json" "$R" -d '{"content":"rocket"}' -w '\nreact -> HTTP %{http_code}\n' || true
|
||||
curl -sS -X DELETE -H "Authorization: token $SELF_TOKEN" -H "Content-Type: application/json" "$R" -d '{"content":"eyes"}' || true
|
||||
curl -sS -X POST -H "Authorization: token $SELF_TOKEN" -H "Content-Type: application/json" "$R" -d '{"content":"rocket"}' -w '\nreact -> HTTP %{http_code}\n' || true
|
||||
|
||||
- name: Mark failed with 😕 (remove 👀)
|
||||
if: failure()
|
||||
if: failure() && steps.prep.outputs.mode != 'skip'
|
||||
env:
|
||||
GT: ${{ secrets.GITEA_TOKEN }}
|
||||
SELF_TOKEN: ${{ steps.prep.outputs.name == 'pm' && secrets.TOKEN_PM || steps.prep.outputs.name == 'junior' && secrets.TOKEN_JUNIOR || steps.prep.outputs.name == 'senior' && secrets.TOKEN_SENIOR || steps.prep.outputs.name == 'lead' && secrets.TOKEN_LEAD || steps.prep.outputs.name == 'qa' && secrets.TOKEN_QA || steps.prep.outputs.name == 'ops' && secrets.TOKEN_OPS || steps.prep.outputs.name == 'intern' && secrets.TOKEN_INTERN || '' }}
|
||||
CID: ${{ github.event.comment.id }}
|
||||
NUM: ${{ github.event.issue.number }}
|
||||
run: |
|
||||
[ -n "$SELF_TOKEN" ] || exit 0
|
||||
B="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}/issues"
|
||||
if [ -n "$CID" ]; then R="$B/comments/$CID/reactions"; else R="$B/$NUM/reactions"; fi
|
||||
curl -sS -X DELETE -H "Authorization: token $GT" -H "Content-Type: application/json" "$R" -d '{"content":"eyes"}' || true
|
||||
curl -sS -X POST -H "Authorization: token $GT" -H "Content-Type: application/json" "$R" -d '{"content":"confused"}' -w '\nreact -> HTTP %{http_code}\n' || true
|
||||
curl -sS -X DELETE -H "Authorization: token $SELF_TOKEN" -H "Content-Type: application/json" "$R" -d '{"content":"eyes"}' || true
|
||||
curl -sS -X POST -H "Authorization: token $SELF_TOKEN" -H "Content-Type: application/json" "$R" -d '{"content":"confused"}' -w '\nreact -> HTTP %{http_code}\n' || true
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"pm": {
|
||||
"model": "ollama-cloud/gemma4:cloud",
|
||||
"model": "ollama-cloud/minimax-m3:cloud",
|
||||
"vision": true,
|
||||
"mode": "comment",
|
||||
"skills": [
|
||||
|
||||
@@ -4,14 +4,31 @@
|
||||
# to its real author (@pm/@qa/@junior/…). Strip the hidden `<!-- 🤖 … -->` loop-prevention marker
|
||||
# from bodies — it's plumbing, not conversation, and would just waste prompt tokens.
|
||||
#
|
||||
# PAGINATION: Gitea returns comments ASCENDING and `limit` caps a single page — a bare ?limit=100
|
||||
# used to keep the OLDEST 100 comments and silently drop the newest (the exact opposite of what an
|
||||
# agent needs on a long thread). Fetch all pages (up to 10 = 500 comments) and keep the LAST 100.
|
||||
#
|
||||
# Required env (provided by the workflow step): GT NUM GITHUB_SERVER_URL GITHUB_REPOSITORY
|
||||
set -eu
|
||||
|
||||
API="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
|
||||
curl -sS -H "Authorization: token $GT" "$API/issues/$NUM/comments?limit=100" 2>/dev/null \
|
||||
| jq -r '.[] |
|
||||
( if (.user.login == "ffaerber") then "@ffaerber (the maintainer)"
|
||||
else "@" + .user.login end ) as $who |
|
||||
"### comment by \($who):\n\(.body | gsub("\\s*<!-- 🤖 agent reply — do not trigger -->"; ""))\n"' \
|
||||
> /tmp/thread.md 2>/dev/null || true
|
||||
echo "thread comments fetched: $(grep -c '^### comment by ' /tmp/thread.md 2>/dev/null || echo 0)"
|
||||
: > /tmp/thread_pages.json
|
||||
for page in $(seq 1 10); do
|
||||
pg=$(curl -sS -H "Authorization: token $GT" "$API/issues/$NUM/comments?limit=50&page=$page" 2>/dev/null) || pg='[]'
|
||||
n=$(printf '%s' "$pg" | jq 'if type=="array" then length else 0 end' 2>/dev/null || echo 0)
|
||||
[ "${n:-0}" -gt 0 ] && printf '%s\n' "$pg" >> /tmp/thread_pages.json
|
||||
[ "${n:-0}" -lt 50 ] && break
|
||||
done
|
||||
jq -rs '
|
||||
add // [] | .[-100:] | .[] |
|
||||
( if (.user.login == "ffaerber") then "@ffaerber (the maintainer)"
|
||||
else "@" + .user.login end ) as $who |
|
||||
"### comment by \($who):\n\(.body | gsub("\\s*<!-- 🤖 agent reply — do not trigger -->"; ""))\n"' \
|
||||
/tmp/thread_pages.json > /tmp/thread.md 2>/dev/null || : > /tmp/thread.md
|
||||
echo "thread comments fetched: $(grep -c '^### comment by ' /tmp/thread.md 2>/dev/null || echo 0) (newest 100 kept)"
|
||||
|
||||
# Record the newest comment id on the thread BEFORE the agent runs. publish.sh compares against
|
||||
# it to detect an agent that self-posted its reply mid-run (via the gitea-api skill, despite the
|
||||
# prompt telling it not to) and skips the duplicate framework reply. Ids are monotonic — no dates.
|
||||
jq -rs '[ (add // [])[].id ] | max // 0' /tmp/thread_pages.json > /tmp/thread_max_cid 2>/dev/null || echo 0 > /tmp/thread_max_cid
|
||||
echo "pre-run newest comment id: $(cat /tmp/thread_max_cid)"
|
||||
|
||||
@@ -9,7 +9,14 @@ set -eu
|
||||
# --format json event schema that build-activity-log.sh parses) breaks every agent in every repo
|
||||
# at once. Bump deliberately by changing this default (or set OPENCODE_VERSION in the step env).
|
||||
OPENCODE_VERSION="${OPENCODE_VERSION:-1.17.13}"
|
||||
curl -fsSL https://opencode.ai/install | bash -s -- --version "$OPENCODE_VERSION"
|
||||
# Skip the download when a cache hit already restored the pinned binary (see the Cache
|
||||
# opencode CLI step in agent.yml). The installer always re-fetches otherwise.
|
||||
OC_BIN="$HOME/.opencode/bin/opencode"
|
||||
if [ -x "$OC_BIN" ] && "$OC_BIN" --version 2>/dev/null | grep -qF "$OPENCODE_VERSION"; then
|
||||
echo "opencode $OPENCODE_VERSION already present (cache hit) — skipping install"
|
||||
else
|
||||
curl -fsSL https://opencode.ai/install | bash -s -- --version "$OPENCODE_VERSION"
|
||||
fi
|
||||
echo "$HOME/.opencode/bin" >> "$GITHUB_PATH"
|
||||
mkdir -p ~/.config/opencode
|
||||
# Playwright browser MCP only for agents that need to drive a web app
|
||||
|
||||
@@ -44,8 +44,14 @@ trig() { if [ -z "$TTOK" ]; then echo "no trigger token — cannot fire on #$1";
|
||||
# Origin issue for this run (route.sh resolves it from the branch on PR threads), and a resolver for
|
||||
# the open PR built from its branch (ai/issue-<issue>). Lets @pm/@qa cross between the issue and PR.
|
||||
ISSN="${ISSNUM:-$NUM}"
|
||||
resolve_pr() { curl -sS "${hdr[@]}" "$API/pulls?state=open&limit=50" \
|
||||
| jq -r --arg br "ai/issue-$ISSN" 'if type=="array" then (map(select(.head.ref==$br))|.[0].number // empty) else empty end' 2>/dev/null; }
|
||||
# All OPEN PRs belonging to this issue, oldest→newest. Matches ai/issue-N AND the ai/issue-N-<slug>
|
||||
# split branches AGENTS.md tells devs to use — an exact-only match silently stalled the flow on
|
||||
# slugged branches (DELEGATE:@qa found "no open PR"; autopilot MERGE_PR couldn't merge).
|
||||
resolve_prs() { curl -sS "${hdr[@]}" "$API/pulls?state=open&limit=50" \
|
||||
| jq -r --arg br "ai/issue-$ISSN" 'if type=="array" then
|
||||
([ .[] | select(.head.ref==$br or (.head.ref|startswith($br+"-"))) | .number ] | sort | join(" "))
|
||||
else "" end' 2>/dev/null; }
|
||||
resolve_pr() { resolve_prs | awk '{print $NF}'; } # newest open PR (empty if none)
|
||||
# Remove the 'autopilot' label from an issue by resolving its ID first (Gitea's DELETE label
|
||||
# endpoint is by ID, not name). Arg $1 = issue number. Used as the autopilot kill switch.
|
||||
del_autopilot_label() {
|
||||
@@ -67,6 +73,7 @@ reply=$(awk '
|
||||
/^[[:space:]]*BEGIN_SUBTASKS/{s=1}
|
||||
/^[[:space:]]*BEGIN_PR_DESCRIPTION/{p=1}
|
||||
/^[[:space:]]*DELEGATE:[[:space:]]*@/{next}
|
||||
/^[[:space:]]*ASK:[[:space:]]*@/{next}
|
||||
/^[[:space:]]*CLOSE_ISSUE[[:space:]]*$/{next}
|
||||
/^[[:space:]]*MERGE_PR[[:space:]]*$/{next}
|
||||
/^[[:space:]]*RETRO[[:space:]]*$/{next}
|
||||
@@ -188,15 +195,43 @@ if [ "$MODE" != "pr" ]; then
|
||||
done < /tmp/subtasks.txt
|
||||
subtext=$(printf '\n\n---\nCreated sub-issues%s (mention an agent on each when ready):%b' "${ms:+ under milestone **$ms**}" "$links")
|
||||
fi
|
||||
post "$(printf '%s%s%s' "$msg" "$subtext" "$activity")"
|
||||
# DEDUP GUARD (issue: @pm double-posts its report). Prompt-level "do not self-post" is ignored
|
||||
# by some models, so enforce it here: if the agent ALREADY posted a comment on this thread
|
||||
# during the run (any comment by $NAME newer than the pre-run newest id from fetch-thread.sh),
|
||||
# its self-post IS the reply — skip the duplicate framework comment. Markers (CLOSE_ISSUE,
|
||||
# DELEGATE, MERGE_PR, subtasks) were already processed above and are unaffected.
|
||||
# FAIL OPEN: if the pre-run marker is missing (fetch-thread hiccup), pre_cid=0 would make the
|
||||
# agent's comments from PREVIOUS runs count as self-posts and wrongly suppress the reply.
|
||||
# Without the marker, skip the guard and post normally.
|
||||
pre_cid=$(cat /tmp/thread_max_cid 2>/dev/null || echo "")
|
||||
selfposts=0
|
||||
if [ -n "$pre_cid" ]; then
|
||||
: > /tmp/all_comments.json
|
||||
for pg in $(seq 1 10); do
|
||||
cpg=$(curl -sS "${hdr[@]}" "$API/issues/$NUM/comments?limit=50&page=$pg" 2>/dev/null) || cpg='[]'
|
||||
cn=$(printf '%s' "$cpg" | jq 'if type=="array" then length else 0 end' 2>/dev/null || echo 0)
|
||||
[ "${cn:-0}" -gt 0 ] && printf '%s\n' "$cpg" >> /tmp/all_comments.json
|
||||
[ "${cn:-0}" -lt 50 ] && break
|
||||
done
|
||||
selfposts=$(jq -rs --arg n "$NAME" --argjson c "${pre_cid:-0}" '[ (add // [])[] | select(.user.login==$n) | select(.id > $c) ] | length' /tmp/all_comments.json 2>/dev/null || echo 0)
|
||||
fi
|
||||
if [ "${selfposts:-0}" -gt 0 ]; then
|
||||
echo "agent @$NAME already posted ${selfposts} comment(s) on #$NUM during this run — skipping duplicate framework reply"
|
||||
else
|
||||
post "$(printf '%s%s%s' "$msg" "$subtext" "$activity")"
|
||||
fi
|
||||
|
||||
# --- @pm autopilot merge: @pm is the ONLY agent that merges, and ONLY under the autopilot label ---
|
||||
# (@qa never merges — it approves and hands back here.) Merge with the PAT (TTOK), not the built-in
|
||||
# token, so the push to main fires the deploy. TOKEN_PM must carry write:repository.
|
||||
if [ "$NAME" = "pm" ] && [ "$AUTOPILOT" = "true" ] && grep -qiE '^[[:space:]]*MERGE_PR[[:space:]]*$' /tmp/agent_out.md; then
|
||||
PRN=$(resolve_pr)
|
||||
PRS=$(resolve_prs); PRN=${PRS##* }; CNT=$(echo "$PRS" | wc -w)
|
||||
if [ -z "$PRN" ]; then
|
||||
echo "MERGE_PR but no open PR found for issue #$ISSN"
|
||||
elif [ "$CNT" -gt 1 ]; then
|
||||
# Split-PR work: auto-merging just one of several open PRs is half a change deployed.
|
||||
del_autopilot_label "$ISSN"
|
||||
post_to "$ISSN" "⚠️ This issue has $CNT open PRs (#${PRS// /, #}) — autopilot only merges single-PR work. Removed the autopilot label; @ffaerber please review and merge them in order."
|
||||
else
|
||||
echo "@pm autopilot: merging PR #$PRN (issue #$ISSN)"
|
||||
mc=$(curl -sS -o /tmp/merge_resp.txt -w '%{http_code}' -X POST \
|
||||
@@ -221,7 +256,7 @@ if [ "$MODE" != "pr" ]; then
|
||||
# pm → qa → merge), and run-agent.sh injects LEARNINGS.md into every future prompt — closing the loop.
|
||||
if [ "$NAME" = "pm" ] && grep -qiE '^[[:space:]]*RETRO[[:space:]]*$' /tmp/agent_out.md; then
|
||||
PRN=$(curl -sS "${hdr[@]}" "$API/pulls?state=all&limit=50" \
|
||||
| jq -r --arg br "ai/issue-$ISSN" 'if type=="array" then ([.[]|select(.head.ref==$br)] | sort_by(.number) | last | .number // empty) else empty end' 2>/dev/null)
|
||||
| jq -r --arg br "ai/issue-$ISSN" 'if type=="array" then ([.[]|select(.head.ref==$br or (.head.ref|startswith($br+"-")))] | sort_by(.number) | last | .number // empty) else empty end' 2>/dev/null)
|
||||
rbody=$(printf 'Retrospective for issue #%s%s.\n\nRead the FULL issue thread%s using the gitea-api skill (issue comments%s and the PR diff). Identify what went wrong, slow, or needed human correction — missed wiring, review misses, bounced rounds, unclear delegation, missing context.\n\nThen APPEND the distilled learnings to `LEARNINGS.md` at the repo root (create it with a short header if missing). Rules for entries:\n- 3 to 6 bullets max, each ONE line: `symptom -> rule for next time`.\n- Concrete and checkable (name the file/step/marker), not generic advice.\n- Do not repeat an existing bullet; refine it instead.\n- Do not rewrite unrelated parts of the file.\n\nThese learnings are injected into every future agent prompt, so quality over quantity.' \
|
||||
"$ISSN" "${PRN:+ / PR #$PRN}" "${PRN:+ and PR #$PRN thread}" "${PRN:+, PR comments}")
|
||||
rnum=$(curl -sS -X POST "${hdr[@]}" "$API/issues" \
|
||||
@@ -236,14 +271,28 @@ if [ "$MODE" != "pr" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# --- @pm ASK: consult a dev in the thread WITHOUT starting a build ---
|
||||
# 'ASK: @<dev> <question>' fires the dev in DISCUSSION mode (route.sh: the trigger below does not
|
||||
# match any build phrase, so the dev replies in-thread — no branch, no PR). @pm gathers input this
|
||||
# way, then DELEGATEs when enough is known.
|
||||
ask_line=$(grep -oiE '^[[:space:]]*ASK:[[:space:]]*@(junior|senior|lead|intern)[[:space:]]+.*$' /tmp/agent_out.md 2>/dev/null | head -1)
|
||||
if [ "$NAME" = "pm" ] && [ -n "$ask_line" ]; then
|
||||
ask_dev=$(printf '%s' "$ask_line" | grep -oiE '@(junior|senior|lead|intern)' | head -1 | tr -d '@' | tr '[:upper:]' '[:lower:]')
|
||||
ask_q=$(printf '%s' "$ask_line" | sed -E 's/^[[:space:]]*ASK:[[:space:]]*@[A-Za-z]+[[:space:]]+//')
|
||||
trig "$ISSN" "@$ask_dev $ask_q — this is a discussion: reply in this thread with your assessment; do not start any work."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# --- @pm delegation: hand the build to a dev, or hand the finished PR to @qa for review ---
|
||||
# Only an explicit 'DELEGATE: @<agent>' line acts (never a prose mention). Fires via the PAT (TTOK)
|
||||
# so a new run starts; the built-in token cannot. Everything posts on the ISSUE — @pm never touches
|
||||
# the PR. Chain terminates: normal → @pm tells the creator (no marker); autopilot → @pm merges above.
|
||||
if [ -n "$target" ] && [ "$target" != "$NAME" ]; then
|
||||
if [ "$target" = "qa" ]; then
|
||||
PRN=$(resolve_pr)
|
||||
if [ -n "$PRN" ]; then
|
||||
PRS=$(resolve_prs); PRN=${PRS##* }; CNT=$(echo "$PRS" | wc -w)
|
||||
if [ -n "$PRN" ] && [ "$CNT" -gt 1 ]; then
|
||||
trig "$ISSN" "@qa please review the $CNT open PRs for issue #$ISSN (#${PRS// /, #}) — put your recommendations on each PR; approve only when ALL are good."
|
||||
elif [ -n "$PRN" ]; then
|
||||
trig "$ISSN" "@qa please review PR #$PRN for issue #$ISSN — put your recommendations on the PR, or approve."
|
||||
else
|
||||
echo "DELEGATE:@qa but no open PR yet for issue #$ISSN — not firing"
|
||||
@@ -257,6 +306,15 @@ if [ "$MODE" != "pr" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# --- dev DISCUSSION mode: consulted for expertise, no build (route.sh workmode=discuss) ---
|
||||
# The reply is a comment on the thread — discard any stray file edits, skip ALL git/PR machinery.
|
||||
if [ "${WORKMODE:-build}" = "discuss" ]; then
|
||||
git checkout -- . 2>/dev/null || true
|
||||
git clean -fd 2>/dev/null || true
|
||||
post "$(printf '%s%s' "$reply" "$activity")"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Scrub the runtime scripts checkout (.agents-workflow) from the tree so it never lands in a
|
||||
# commit/PR and never confuses the git ops below (issue #33). The scripts we run live outside the
|
||||
# workspace ($SCRIPTS -> runner.temp), so removing this in-tree copy is always safe. Handle every
|
||||
@@ -276,7 +334,14 @@ if [ -n "$(git status --porcelain)" ]; then
|
||||
git add -A
|
||||
git commit -m "@$NAME: issue #$NUM"
|
||||
fi
|
||||
git push origin "HEAD:$BRANCH" || true
|
||||
if git push origin "HEAD:$BRANCH"; then
|
||||
:
|
||||
else
|
||||
status=$?
|
||||
echo "git push failed for $BRANCH (exit $status)"
|
||||
post "$(printf '⚠️ Push to branch `%s` failed (git exit %s). The PR will not open until the push succeeds. Please check the Actions log.%s' "$BRANCH" "$status" "$activity")"
|
||||
exit 0
|
||||
fi
|
||||
git fetch -q origin 2>/dev/null || true
|
||||
|
||||
prbody=$(printf '%s\n\n---\nResolves #%s' "$prdesc" "$NUM")
|
||||
@@ -302,14 +367,21 @@ url=$(printf '%s' "$resp" | jq -r '.html_url // empty' 2>/dev/null)
|
||||
prnum=$(printf '%s' "$resp" | jq -r '.number // empty' 2>/dev/null)
|
||||
if [ -z "$url" ]; then
|
||||
title="@$NAME: $TITLE"
|
||||
resp=$(curl -sS -X POST "${hdr[@]}" "$API/pulls" \
|
||||
resp_body=/tmp/pr_create_resp.json
|
||||
http_status=$(curl -sS -o "$resp_body" -w '%{http_code}' -X POST "${hdr[@]}" "$API/pulls" \
|
||||
-d "$(jq -nc --arg t "$title" --arg h "$br" --arg b "$prbody" \
|
||||
'{title:$t, head:$h, base:"main", body:$b}')")
|
||||
echo "PR create ($br): $resp"
|
||||
resp=$(cat "$resp_body" 2>/dev/null || true)
|
||||
echo "PR create ($br): HTTP $http_status — $resp"
|
||||
url=$(printf '%s' "$resp" | jq -r '.html_url // empty' 2>/dev/null)
|
||||
prnum=$(printf '%s' "$resp" | jq -r '.number // empty' 2>/dev/null)
|
||||
fi
|
||||
[ -z "$url" ] && { echo "PR open/lookup failed for $br — posting reply on issue instead"; post "$(printf '%s%s' "$reply" "$activity")"; exit 0; }
|
||||
if [ -z "$url" ]; then
|
||||
err_msg=$(printf '%s' "$resp" | jq -r 'if type=="object" and .message then .message else "(no error message in response)" end' 2>/dev/null)
|
||||
echo "PR open/lookup failed for $br — HTTP $http_status — response: $resp"
|
||||
post "$(printf '⚠️ Failed to open PR for branch `%s`.\n\nHTTP status: %s\nGitea message: %s%s' "$br" "$http_status" "$err_msg" "$activity")"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Posts to the PR thread when we have a PR number, else to the origin issue ($NUM).
|
||||
prpost() {
|
||||
|
||||
@@ -31,19 +31,47 @@ name=""
|
||||
# load-bearing for the flow's trigger comments: "@pm — @qa approved …" must route to @pm (pm is
|
||||
# checked first), while "@junior please address @qa's review …" must route to the dev (devs are
|
||||
# checked before qa). If you add an agent or reword a trigger in publish.sh, re-check this order.
|
||||
# WORD-BOUNDARY match, not substring: "@internal" or "x@internet.com" must NOT route to @intern
|
||||
# (the workflow gate can only do contains(), so this is where its false positives get filtered).
|
||||
for a in pm junior senior lead qa ops intern; do
|
||||
case "$scan" in *"@$a"*) name=$a; break;; esac
|
||||
if printf '%s' "$scan" | grep -qE "(^|[^[:alnum:]_])@$a([^[:alnum:]_-]|\$)"; then name=$a; break; fi
|
||||
done
|
||||
if [ -z "$name" ]; then
|
||||
if [ -z "$CID" ]; then name=pm; else echo "no known agent mentioned"; exit 1; fi
|
||||
if [ -z "$CID" ]; then
|
||||
name=pm
|
||||
else
|
||||
# Not an agent task (e.g. the gate's contains() matched "@internal"). Skip GRACEFULLY: emit
|
||||
# mode=skip so every later step no-ops — a red run for a non-agent comment is just noise.
|
||||
echo "no known agent mentioned (word-boundary) — skipping run"
|
||||
{ echo "name=none"; echo "model=none"; echo "vision=false"; echo "mode=skip"; echo "skills=[]";
|
||||
echo "branch=main"; echo "new=false"; echo "autopilot=false"; echo "issnum=$NUM"; } >> "$GITHUB_OUTPUT"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
model=$(jq -r --arg a "$name" '.[$a].model' /tmp/agents.json)
|
||||
vision=$(jq -r --arg a "$name" '.[$a].vision' /tmp/agents.json)
|
||||
mode=$(jq -r --arg a "$name" '.[$a].mode' /tmp/agents.json)
|
||||
# Compact JSON array of the skills this agent may load (scopes permission.skill in install-opencode.sh).
|
||||
skills=$(jq -c --arg a "$name" '.[$a].skills // []' /tmp/agents.json)
|
||||
echo "Routing to @$name (model=$model vision=$vision mode=$mode skills=$skills)"
|
||||
{ echo "name=$name"; echo "model=$model"; echo "vision=$vision"; echo "mode=$mode"; echo "skills=$skills"; } >> "$GITHUB_OUTPUT"
|
||||
|
||||
# --- WORKMODE for dev (mode=pr) agents: build vs DISCUSS. ---
|
||||
# Mentioning a dev is a CONVERSATION by default — it replies in the thread without creating a
|
||||
# branch or PR. Actual building starts ONLY on the explicit signals:
|
||||
# - a comment on a PR thread (resuming existing work), or
|
||||
# - the pm delegation template ".. please proceed with issue .." (also usable by a human), or
|
||||
# - the qa bounce template ".. please address my review ..".
|
||||
# This lets @pm (via its ASK marker) and the maintainer consult devs to gather information first,
|
||||
# and explicitly start the build later — see publish.sh / run-agent.sh.
|
||||
workmode=build
|
||||
if [ "$mode" = "pr" ] && [ -z "$IS_PR" ]; then
|
||||
if printf '%s' "$scan" | grep -qiE 'please (proceed with issue|address my review)'; then
|
||||
workmode=build
|
||||
else
|
||||
workmode=discuss
|
||||
fi
|
||||
fi
|
||||
echo "Routing to @$name (model=$model vision=$vision mode=$mode workmode=$workmode skills=$skills)"
|
||||
{ echo "name=$name"; echo "model=$model"; echo "vision=$vision"; echo "mode=$mode"; echo "workmode=$workmode"; echo "skills=$skills"; } >> "$GITHUB_OUTPUT"
|
||||
|
||||
# Act as the agent's own Gitea user when its token is set; else the built-in bot.
|
||||
case "$name" in
|
||||
@@ -56,7 +84,10 @@ git config user.email "$name@ffaerber.duckdns.org"
|
||||
API="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
|
||||
hdr=(-H "Authorization: token $TOK" -H "Content-Type: application/json")
|
||||
branch_ref=""
|
||||
if [ -n "$IS_PR" ]; then # comment on a PR -> resume its branch
|
||||
if [ "$workmode" = "discuss" ]; then # conversation only — no branch, no PR machinery
|
||||
echo "discussion mode — staying on main, no branch prep"
|
||||
{ echo "branch=main"; echo "new=false"; } >> "$GITHUB_OUTPUT"
|
||||
elif [ -n "$IS_PR" ]; then # comment on a PR -> resume its branch
|
||||
ref=$(curl -s -H "Authorization: token $GT" "$API/pulls/$NUM" | jq -r .head.ref)
|
||||
branch_ref="$ref"
|
||||
git fetch origin "$ref" && git checkout "$ref"
|
||||
|
||||
@@ -54,7 +54,11 @@ if [ "$MODE" = "comment" ]; then
|
||||
|
||||
If anything is unclear or needs a decision at any phase, START your reply with '@ffaerber', ask
|
||||
specific questions, and do NOT emit a marker. Mentioning a teammate in prose does NOT act — only a
|
||||
DELEGATE line does.
|
||||
marker line does.
|
||||
ASK — to CONSULT a dev before (or instead of) planning, end your reply with EXACTLY one line:
|
||||
'ASK: @<dev> <one concrete question>'. The dev replies in this thread WITHOUT starting any work —
|
||||
use it to gather feasibility/effort/approach input, then present your plan (and later DELEGATE)
|
||||
once you know enough. One ASK per reply; never ASK and DELEGATE in the same reply.
|
||||
RETRO — when the maintainer asks for a retrospective on this issue (e.g. 'run a retro',
|
||||
'@pm retro'), briefly acknowledge and end your reply with EXACTLY one line: 'RETRO'. The
|
||||
automation opens a retro issue (read this issue + its PR, distill learnings into LEARNINGS.md)
|
||||
@@ -97,6 +101,15 @@ if [ "$MODE" = "comment" ]; then
|
||||
decision). Hands back to @ffaerber.
|
||||
Emit AT MOST one marker, and only after you have actually verified."
|
||||
fi
|
||||
elif [ "${WORKMODE:-build}" = "discuss" ]; then
|
||||
# A dev agent consulted for its EXPERTISE — conversation only, no build. Building starts later,
|
||||
# explicitly ('please proceed with issue …'). See route.sh workmode.
|
||||
ACTION="You are being CONSULTED in this thread — this is a DISCUSSION, not a build task. Answer the
|
||||
question you were asked: read whatever files/logs you need (read-only), give your assessment,
|
||||
approach, effort estimate, risks, or answer — concise and concrete. Your reply becomes a comment.
|
||||
Do NOT modify files, do NOT commit or push, do NOT create branches, do NOT open PRs. Do not
|
||||
emit any marker. When the team has enough information, @pm (or the maintainer) will explicitly
|
||||
tell a dev to start building."
|
||||
else
|
||||
ACTION="You start on git branch '${BRANCH}', with git and push credentials already configured.
|
||||
FIRST read AGENTS.md at the repo root and FOLLOW IT EXACTLY — it defines the golden rules,
|
||||
@@ -109,8 +122,18 @@ fi
|
||||
# TEAM LEARNINGS — distilled from past retros (see the RETRO flow in publish.sh). Lives at the
|
||||
# CALLER repo root as LEARNINGS.md, maintained by retro PRs. Injected into EVERY agent's prompt
|
||||
# (capped) so past mistakes actually change future behavior — this is the feedback loop.
|
||||
# Cap is LINE-aware and keeps the NEWEST entries: retros append at the bottom, so a byte-cap from
|
||||
# the top would silently drop the latest lessons first (and cut mid-bullet).
|
||||
LEARN=""
|
||||
[ -s LEARNINGS.md ] && LEARN=$(head -c 4000 LEARNINGS.md)
|
||||
if [ -s LEARNINGS.md ]; then
|
||||
if [ "$(wc -l < LEARNINGS.md)" -gt 80 ]; then
|
||||
LEARN=$(printf '%s\n_(older learnings truncated — full list in LEARNINGS.md)_\n%s' \
|
||||
"$(head -n 3 LEARNINGS.md)" "$(tail -n 70 LEARNINGS.md)")
|
||||
else
|
||||
LEARN=$(cat LEARNINGS.md)
|
||||
fi
|
||||
LEARN=$(printf '%s' "$LEARN" | head -c 8000)
|
||||
fi
|
||||
[ -n "$LEARN" ] && LEARN="
|
||||
TEAM LEARNINGS (distilled from past retros in this repo — APPLY them; they exist because a
|
||||
previous task went wrong without them):
|
||||
@@ -126,6 +149,12 @@ ${LEARN}
|
||||
shown by Gitea. Do NOT begin your reply with your own name, an '@${NAME}' header, or a '🤖/🔨 @you'
|
||||
line; just write the content directly.
|
||||
|
||||
Do NOT use the gitea-api skill to post your reply, report, or any comment on THIS thread
|
||||
yourself. The automation already posts your reply exactly once — self-posting it too is what
|
||||
creates the duplicate comments you must avoid. On this thread, use gitea-api only to READ, or to
|
||||
take an explicit action you were asked for (add/remove a label, close the issue, merge the PR).
|
||||
Your report or answer IS your reply text — write it as your reply; do not post it via the API.
|
||||
|
||||
TEAM ROSTER (who does what — hand off if a task isn't yours):
|
||||
${ROSTER}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ Shared **AI dev-team** workflow for Gitea Actions, reusable across repos. It giv
|
||||
|
||||
| Agent | Model | Vision | Mode | Skills | Role |
|
||||
|-------|-------|:------:|------|--------|------|
|
||||
| `@pm` | `ollama-cloud/gemma4:cloud` | yes | comment | `gitea-api` | Product manager & orchestrator — plans, picks the dev, hands finished PRs to `@qa`, reports back to the issue creator (autopilot: merges approved PRs itself). Issue thread only; never edits files, never reads the PR diff. |
|
||||
| `@pm` | `ollama-cloud/minimax-m3:cloud` | yes | comment | `gitea-api` | Product manager & orchestrator — plans, picks the dev, hands finished PRs to `@qa`, reports back to the issue creator (autopilot: merges approved PRs itself). Issue thread only; never edits files, never reads the PR diff. |
|
||||
| `@junior` | `ollama-cloud/kimi-k2.7-code:cloud` | no | pr | — | Junior dev — small, low-risk changes (mostly YAML/compose/config). Text-only, cannot read images. Defers complex or image tasks to `@senior` or `@lead`. |
|
||||
| `@senior` | `ollama-cloud/glm-5.2:cloud` | no | pr | `gitea-api` | Senior dev — complex, multi-file implementation (GLM-5.2 via Ollama Cloud, text-only). |
|
||||
| `@lead` | `anthropic/claude-opus-4-8` | yes | pr | `gitea-api` | Tech lead — the hardest problems, architecture, and final calls. |
|
||||
@@ -36,6 +36,15 @@ deploy-host SSH skill, live in the consuming repo under `.gitea/agent-skills/`
|
||||
`@pm` is the only agent that ever merges, and only under the `autopilot` label (its kill switch:
|
||||
remove the label mid-flight and the next step reverts to human control).
|
||||
|
||||
### Discussion vs building
|
||||
|
||||
Mentioning a dev agent is a **conversation by default**: it reads what it needs and replies in the
|
||||
thread — no branch, no PR. `@pm` can consult devs the same way with an `ASK: @<dev> <question>`
|
||||
marker (gather feasibility/effort input before planning). **Building starts only on the explicit
|
||||
signals**: `@pm`'s delegation (*"please proceed with issue …"* — a human can write the same phrase
|
||||
to start a build directly), a `@qa` bounce (*"please address my review …"*), or any comment on the
|
||||
PR thread itself (resuming existing work).
|
||||
|
||||
### Retros — the learning loop
|
||||
|
||||
Ask `@pm` for a retrospective on any issue (e.g. **"@pm run a retro"**, typically when merging). The
|
||||
|
||||
Reference in New Issue
Block a user