Compare commits
12
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
729a14f8bd | ||
|
|
d3c8f116f1 | ||
|
|
658c10fc35 | ||
|
|
649cd4ea9b | ||
|
|
509b10ac57 | ||
|
|
4ed96dcdf2 | ||
|
|
767a3341fd | ||
|
|
9a3ca95f9e | ||
|
|
f0f1152545 | ||
|
|
13148ea68c | ||
|
|
d0a4de9682 | ||
|
|
cafd36eae1 |
@@ -1,6 +1,9 @@
|
||||
name: ai-agent
|
||||
# Thin caller so the agents work on THIS repo too (their own workflow). Same shared logic.
|
||||
# New issues opened by ffaerber auto-start @pm; @mention an agent in a comment to route on replies.
|
||||
run-name: ai-agent · #${{ github.event.issue.number }}
|
||||
# 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
|
||||
# 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.
|
||||
on:
|
||||
issue_comment:
|
||||
types: [created]
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"pm": {"model":"ollama-cloud/gemma4:cloud","vision":true, "mode":"comment","skills":["gitea-api"],"desc":"Product manager — research, plan, ask clarifying questions, and decide which dev should do the work. Comments only; never edits files."},
|
||||
"junior": {"model":"ollama-cloud/kimi-k2.7-code:cloud","vision":false,"mode":"pr", "skills":[],"desc":"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": {"model":"ollama-cloud/glm-5.2:cloud","vision":false,"mode":"pr", "skills":["gitea-api","node1-ssh"],"desc":"Senior dev — complex, multi-file implementation (GLM-5.2 via Ollama Cloud, text-only)."},
|
||||
"lead": {"model":"anthropic/claude-opus-4-8","vision":true, "mode":"pr", "skills":["gitea-api","node1-ssh"],"desc":"Tech lead — the hardest problems, architecture, and final calls."},
|
||||
"qa": {"model":"ollama-cloud/minimax-m3:cloud","vision":true, "mode":"comment","skills":["gitea-api"],"desc":"QA — verifies things work. Drives a headless browser (Playwright) to open a URL/web app, click through it, screenshot, and report bugs or confirm behavior. Comments findings; opens no PRs."}
|
||||
}
|
||||
@@ -28,10 +28,16 @@ SKILLS="${SKILLS:-[]}"
|
||||
PERM=$(jq -nc --argjson s "$SKILLS" '
|
||||
{skill: ( {"*":"deny"} + (reduce $s[] as $k ({}; . + {($k):"allow"})) )}')
|
||||
# Two ollama providers: local self-hosted (ornith) + Ollama Cloud (gemma4/kimi-k2.7-code/glm-5.2/minimax-m3).
|
||||
jq -n --argjson mcp "$MCP" --argjson perm "$PERM" --arg url "$OLLAMA_URL" --arg ckey "$OLLAMA_CLOUD_API_KEY" '{
|
||||
# The ollama-cloud `models:` map is DERIVED from agents.json (the single source of truth, shared with
|
||||
# route.sh) so every model an agent is routed to is always declared in the provider config. Only the
|
||||
# `ollama-cloud/` provider prefix models participate — e.g. `anthropic/claude-opus-4-8` (@lead) is a
|
||||
# built-in provider and `ornith:35b` is local-only, neither belongs here. See issue #31.
|
||||
AGENTS_JSON="${SCRIPTS:-$(dirname -- "$0")}/agents.json"
|
||||
CLOUD_MODELS=$(jq -r '[.[] | .model | select(startswith("ollama-cloud/")) | sub("^ollama-cloud/";"")] | map({(.):{}}) | add // {}' "$AGENTS_JSON")
|
||||
jq -n --argjson mcp "$MCP" --argjson perm "$PERM" --argjson cloud "$CLOUD_MODELS" --arg url "$OLLAMA_URL" --arg ckey "$OLLAMA_CLOUD_API_KEY" '{
|
||||
provider: {
|
||||
ollama: {npm:"@ai-sdk/openai-compatible", options:{baseURL:($url+"/v1")}, models:{"ornith:35b":{}}},
|
||||
"ollama-cloud": {npm:"@ai-sdk/openai-compatible", options:{baseURL:"https://ollama.com/v1", apiKey:$ckey}, models:{"glm-5.2:cloud":{},"gemma4:cloud":{},"kimi-k2.7-code:cloud":{},"minimax-m3:cloud":{}}}
|
||||
"ollama-cloud": {npm:"@ai-sdk/openai-compatible", options:{baseURL:"https://ollama.com/v1", apiKey:$ckey}, models:$cloud}
|
||||
},
|
||||
permission: $perm,
|
||||
mcp: $mcp
|
||||
|
||||
@@ -39,7 +39,6 @@ if [ "$MODE" != "pr" ]; then
|
||||
# Visible comment: the reply text, or a sensible line if the agent only emitted a marker.
|
||||
msg="$reply"
|
||||
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).
|
||||
if grep -qiE '^[[:space:]]*CLOSE_ISSUE[[:space:]]*$' /tmp/agent_out.md; then
|
||||
echo "closing issue #$NUM"
|
||||
@@ -48,6 +47,9 @@ if [ "$MODE" != "pr" ]; then
|
||||
fi
|
||||
# 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.
|
||||
# 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
|
||||
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)
|
||||
@@ -75,8 +77,9 @@ if [ "$MODE" != "pr" ]; then
|
||||
echo "created sub-issue #${n:-?}: $title"
|
||||
[ -n "$n" ] && links="$links\n- #$n — $title"
|
||||
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
|
||||
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
|
||||
# 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.
|
||||
@@ -123,6 +126,16 @@ git fetch -q origin 2>/dev/null || true
|
||||
prbody=$(printf '%s\n\n---\nResolves #%s · 🤖 @%s' "$prdesc" "$NUM" "$NAME")
|
||||
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
|
||||
# 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.
|
||||
@@ -130,7 +143,7 @@ br="$BRANCH"
|
||||
ahead=$(git rev-list --count "origin/main..origin/$br" 2>/dev/null || echo 0)
|
||||
if [ "${ahead:-0}" -eq 0 ]; then
|
||||
# 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
|
||||
fi
|
||||
|
||||
@@ -148,7 +161,7 @@ if [ -z "$url" ]; then
|
||||
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**\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).
|
||||
prpost() {
|
||||
@@ -160,17 +173,8 @@ prpost() {
|
||||
}
|
||||
|
||||
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
|
||||
# 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")"
|
||||
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")"
|
||||
prpost "$prnum" "$(printf '🤖 **@%s** — updated branch/PR:\n- %s\n\n%s%s' "$NAME" "$url" "$prdesc" "$activity")"
|
||||
fi
|
||||
|
||||
@@ -10,21 +10,18 @@
|
||||
set -eu
|
||||
|
||||
# --- agent registry: model + capabilities + mode + role + skills ---
|
||||
# The registry is the SINGLE SOURCE OF TRUTH, kept in agents.json next to this
|
||||
# script. install-opencode.sh derives its ollama-cloud provider `models:` map
|
||||
# from the same file, so an agent's model can never be missing from the provider
|
||||
# config — drift is impossible by construction. See issue #31.
|
||||
# `skills` is the allow-list of opencode Skills each agent may load. It scopes the
|
||||
# `permission.skill` block written into opencode.json (see install-opencode.sh) so an agent only
|
||||
# ever sees (and can load) the skills relevant to its role. Skills NOT listed here are hidden from
|
||||
# that agent entirely — not even the one-line summary appears in its <available_skills>, so the
|
||||
# full API/how-to detail never reaches an agent that shouldn't act on it. A teammate can still learn
|
||||
# *that* another agent has a capability from the roster and ask them to use it.
|
||||
cat > /tmp/agents.json <<'JSON'
|
||||
{
|
||||
"pm": {"model":"ollama-cloud/gemma4:cloud","vision":true, "mode":"comment","skills":["gitea-api"],"desc":"Product manager — research, plan, ask clarifying questions, and decide which dev should do the work. Comments only; never edits files."},
|
||||
"junior": {"model":"ollama-cloud/kimi-k2.7-code:cloud","vision":false,"mode":"pr", "skills":[],"desc":"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": {"model":"ollama-cloud/glm-5.2:cloud","vision":false,"mode":"pr", "skills":["gitea-api","node1-ssh"],"desc":"Senior dev — complex, multi-file implementation (GLM-5.2 via Ollama Cloud, text-only)."},
|
||||
"lead": {"model":"anthropic/claude-opus-4-8","vision":true, "mode":"pr", "skills":["gitea-api","node1-ssh"],"desc":"Tech lead — the hardest problems, architecture, and final calls."},
|
||||
"qa": {"model":"ollama-cloud/minimax-m3:cloud","vision":true, "mode":"comment","skills":["gitea-api"],"desc":"QA — verifies things work. Drives a headless browser (Playwright) to open a URL/web app, click through it, screenshot, and report bugs or confirm behavior. Comments findings; opens no PRs."}
|
||||
}
|
||||
JSON
|
||||
AGENTS_JSON="${SCRIPTS:-$(dirname -- "$0")}/agents.json"
|
||||
cp "$AGENTS_JSON" /tmp/agents.json
|
||||
# On a new issue, @pm auto-assesses. On a comment, route by the @mention.
|
||||
# A comment event has a comment id (CID); an issue-opened event does not. (event_name is unreliable
|
||||
# here — see agent.yml: this reusable workflow sees it as 'workflow_call'.)
|
||||
|
||||
@@ -10,7 +10,10 @@ set -u
|
||||
[ -z "$CMT" ] && CMT="(a new issue was just opened — assess it)"
|
||||
THREAD=$(cat /tmp/thread.md 2>/dev/null); [ -z "$THREAD" ] && THREAD="(no prior comments)"
|
||||
DESC=$(jq -r --arg a "$NAME" '.[$a].desc' /tmp/agents.json)
|
||||
ROSTER=$(jq -r 'to_entries | map("- @\(.key): \(.value.desc) (vision: \(.value.vision))") | join("\n")' /tmp/agents.json)
|
||||
# Include each teammate's skills so an agent (esp. @pm) can route by capability — e.g. only
|
||||
# @senior/@lead hold node1-ssh, so a node1 task must not go to @junior. Skill *names* only; the
|
||||
# scoped how-to detail stays hidden per the permission.skill allow-list.
|
||||
ROSTER=$(jq -r 'to_entries | map("- @\(.key): \(.value.desc) (vision: \(.value.vision); skills: \(.value.skills | if length>0 then join(", ") else "none" end))") | join("\n")' /tmp/agents.json)
|
||||
if [ "$VISION" = "true" ]; then CAP="You CAN read images attached to the issue."; else CAP="You CANNOT read images — you are a text-only model."; fi
|
||||
NOTE=""
|
||||
if [ "$VISION" != "true" ] && [ "${HAS_IMAGES:-0}" -gt 0 ]; then
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
.env
|
||||
.agents-workflow/
|
||||
|
||||
@@ -29,10 +29,18 @@ detail out of agents that shouldn't act on it while still letting them know the
|
||||
|
||||
## Use it in a repo
|
||||
|
||||
Add `.gitea/workflows/ai-agent.yml` to the consuming repo:
|
||||
**The standard caller is one file, identical in every repo.** Copy this repo's own
|
||||
[`.gitea/workflows/ai-agent.yml`](.gitea/workflows/ai-agent.yml) verbatim into the consuming repo —
|
||||
it is the source of truth, and `agents` itself uses the same file:
|
||||
|
||||
```yaml
|
||||
name: ai-agent
|
||||
run-name: ai-agent · #${{ github.event.issue.number }}
|
||||
# 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
|
||||
# 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.
|
||||
# `run-name` titles each run by the triggering issue (e.g. "ai-agent · #42") in the Actions list.
|
||||
on:
|
||||
issue_comment:
|
||||
types: [created]
|
||||
@@ -44,7 +52,9 @@ jobs:
|
||||
secrets: inherit
|
||||
```
|
||||
|
||||
That's the whole per-repo footprint. All the logic (agent registry, routing, delegation,
|
||||
That's the whole per-repo footprint, and it's the minimum a caller can be: the `on:` triggers must
|
||||
live in each repo (a reusable workflow can't declare its callers' triggers) and the `jobs.agent`
|
||||
wrapper is mandatory for `workflow_call`. Everything else (agent registry, routing, delegation,
|
||||
reactions, PR/issue plumbing) lives here in `agent.yml`.
|
||||
|
||||
## Repo layout
|
||||
|
||||
Reference in New Issue
Block a user