Author SHA1 Message Date
OpenCode Bot 97eac21658 OpenCode (big-pickle): opencode-issue-11 2026-07-06 07:04:39 +00:00
OpenCode Bot 45073d59fd OpenCode: piano di lavoro (opencode-issue-11) 2026-07-06 06:59:35 +00:00
maria 0e3ef69847 Merge pull request 'PR Automatica OpenCode: opencode-issue-9' (#10) from opencode-issue-9 into main
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 5s
Reviewed-on: #10
closes #9
2026-07-06 06:56:03 +00:00
maria 36b2a228e4 Update .gitea/workflows/opencode.yml
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3s
2026-07-06 06:55:24 +00:00
maria c3532e0ae1 Update .gitea/workflows/opencode.yml
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s
2026-07-06 06:54:07 +00:00
OpenCode Bot 7de27f79fe OpenCode (big-pickle): opencode-issue-9 2026-07-06 06:16:28 +00:00
maria 54c9d985c7 Merge pull request 'PR Automatica OpenCode: opencode-issue-7' (#8) from opencode-issue-7 into main
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3s
Reviewed-on: #8
closes #7
2026-07-05 16:58:34 +00:00
5 changed files with 934 additions and 79 deletions
+174 -23
View File
@@ -20,9 +20,10 @@ jobs:
(github.event_name == 'issues' &&
(contains(github.event.issue.body, '/oc') || contains(github.event.issue.body, '/opencode'))) ||
(github.event_name != 'issues' &&
github.event.comment.user.login != 'opencode-bot' &&
(contains(github.event.comment.body, '/oc') || contains(github.event.comment.body, '/opencode')))
runs-on: ubuntu-latest
timeout-minutes: 20
timeout-minutes: 40
env:
GITEA_API_URL: "https://gitea.maribit.it"
@@ -39,6 +40,11 @@ jobs:
ISSUE_TITLE: ${{ github.event.issue.title }}
ISSUE_BODY: ${{ github.event.issue.body }}
RUN_NUMBER: ${{ github.run_number }}
# --- OpenCode ---
OPENCODE_ZEN_API_KEY: ${{ secrets.OPENCODE_ZEN_API_KEY }}
OPENCODE_API_BASE: https://opencode.ai
OPENCODE_MODEL: opencode/big-pickle
MAX_ITERATIONS: "4"
steps:
- name: Verifica autorizzazione utente
@@ -52,8 +58,8 @@ jobs:
exit 1
fi
# Feedback immediato: 👀 sul commento (o sulla issue) che ha invocato l'agente.
# Le reazioni NON generano eventi issue_comment -> nessun doppio run.
# Feedback immediato: 👀 sul commento (o sulla issue). Le reazioni NON generano
# eventi issue_comment -> nessun doppio run.
- name: Reagisci al comando (👀)
id: react
run: |
@@ -83,6 +89,31 @@ jobs:
curl -fsSL https://opencode.ai/install | bash
echo "$HOME/.opencode/bin" >> "$GITHUB_PATH"
# Agent "reviewer" read-only: legge ed esegue i test (bash), MAI edita.
# Creato solo nel runner ed escluso dai commit, così non sporca il repo.
- name: Configura agent reviewer (read-only)
run: |
mkdir -p .opencode/agents
cat > .opencode/agents/reviewer.md <<'EOF'
---
description: Revisore read-only che verifica gli acceptance criteria eseguendo i test, senza modificare il codice.
mode: primary
permission:
edit: deny
webfetch: deny
bash: allow
tools:
write: false
edit: false
bash: true
---
Sei un revisore di codice rigoroso in SOLA LETTURA.
Non modificare mai i file: puoi solo leggere il codice ed eseguire comandi
di verifica (build, lint, test). Stabilisci se ogni Acceptance Criterion
del piano è oggettivamente soddisfatto sul codice attuale.
EOF
grep -qxF '.opencode/' .git/info/exclude 2>/dev/null || echo '.opencode/' >> .git/info/exclude
- name: Determina contesto (issue / PR / manuale) e branch di lavoro
id: ctx
run: |
@@ -101,7 +132,6 @@ jobs:
PR_NUMBER="$PR_NUMBER_FROM_EVENT"
BRANCH_NAME="$PR_HEAD_REF_FROM_EVENT"
else
# issue / issue_comment: la chiave "pull_request" c'è sempre ma vale null per le issue.
ISSUE_JSON=$(curl -s -H "Authorization: token $GITEA_TOKEN" "$API/issues/$ISSUE_NUMBER")
if [ "$(echo "$ISSUE_JSON" | jq -r '.pull_request // empty')" != "" ]; then
IS_PR=true
@@ -120,9 +150,13 @@ jobs:
exit 1
fi
# Chiave univoca per il file di piano (branch con '/' -> '-').
PLAN_KEY=$(printf '%s' "$BRANCH_NAME" | tr '/' '-')
echo "is_pr=$IS_PR" >> "$GITHUB_OUTPUT"
echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
echo "branch_name=$BRANCH_NAME" >> "$GITHUB_OUTPUT"
echo "plan_key=$PLAN_KEY" >> "$GITHUB_OUTPUT"
if [ "$IS_PR" = "true" ]; then
git fetch origin "$BRANCH_NAME"
@@ -152,46 +186,163 @@ jobs:
CLEAN_PROMPT=$(printf '%s' "$COMMENT_BODY" | sed -e 's|/opencode||g' -e 's|/oc||g')
printf '%s' "$CLEAN_PROMPT" > /tmp/clean_prompt.txt
- name: Esegui OpenCode
env:
OPENCODE_ZEN_API_KEY: ${{ secrets.OPENCODE_ZEN_API_KEY }}
OPENCODE_API_BASE: https://opencode.ai
OPENCODE_MODEL: opencode/big-pickle
- name: "Fase 1 — Plan (analisi read-only)"
if: steps.ctx.outputs.is_pr != 'true'
run: |
CLEAN_PROMPT=$(cat /tmp/clean_prompt.txt)
CONTEXT=$(cat /tmp/context.txt 2>/dev/null || true)
opencode run \
--model "$OPENCODE_MODEL" \
"Contesto della Issue/PR: $ISSUE_TITLE - $ISSUE_BODY
mkdir -p issue_plans
PLAN_FILE="issue_plans/${{ steps.ctx.outputs.plan_key }}.md"
opencode run --agent plan --model "$OPENCODE_MODEL" \
"Sei in modalità PLAN (SOLA LETTURA): NON modificare alcun file.
Analizza il codebase e la richiesta, poi produci un piano di lavoro in Markdown
con questa struttura ESATTA:
# Piano
## Obiettivo
## Task
(elenco numerato di task atomici; per ciascuno i file coinvolti)
## Acceptance Criteria
(checklist '- [ ] ...' di criteri oggettivi e verificabili)
## Verifica
(come testare: comandi da lanciare, cosa controllare)
Richiesta ($COMMENT_AUTHOR): $CLEAN_PROMPT
Contesto: $ISSUE_TITLE - $ISSUE_BODY
$CONTEXT
Richiesta specifica dell'utente ($COMMENT_AUTHOR): $CLEAN_PROMPT
Restituisci SOLO il documento Markdown del piano." | tee "$PLAN_FILE"
Se stai lavorando su una PR già aperta, applica solo le modifiche richieste dal feedback di review, senza riscrivere lavoro già approvato."
cp "$PLAN_FILE" /tmp/plan.md
git add "$PLAN_FILE"
git commit -m "OpenCode: piano di lavoro (${{ steps.ctx.outputs.plan_key }})" || echo "Nessun piano da committare."
- name: "Fase 2 — Build & Review loop"
run: |
CLEAN_PROMPT=$(cat /tmp/clean_prompt.txt)
CONTEXT=$(cat /tmp/context.txt 2>/dev/null || true)
PLAN=""; [ -f /tmp/plan.md ] && PLAN="$(cat /tmp/plan.md)"
REVIEW_FEEDBACK="(prima iterazione: nessun feedback)"
for i in $(seq 1 "$MAX_ITERATIONS"); do
echo "::group::Iterazione $i — BUILD"
opencode run --agent build --auto --model "$OPENCODE_MODEL" \
"Sei in modalità BUILD. Implementa il piano completando TUTTI i task e
soddisfacendo TUTTI gli Acceptance Criteria. Applica le modifiche ai file.
=== PIANO ===
${PLAN:-Nessun piano formale. Richiesta: $CLEAN_PROMPT}
=== CONTESTO (diff/commenti PR, se presente) ===
$CONTEXT
=== FEEDBACK DELLA REVIEW PRECEDENTE (correggi SOLO questi punti) ===
$REVIEW_FEEDBACK"
echo "::endgroup::"
echo "::group::Iterazione $i — REVIEW"
opencode run --agent reviewer --auto --model "$OPENCODE_MODEL" \
"Verifica sul codice ATTUALE se OGNI Acceptance Criterion del piano è
soddisfatto. Puoi eseguire build/lint/test ma NON modificare i file.
=== PIANO ===
${PLAN:-Richiesta originale: $CLEAN_PROMPT}
Scrivi come ULTIMA riga ESATTAMENTE una di queste:
- 'VERDICT: PASS' se tutti i criteri sono soddisfatti
- 'VERDICT: FAIL' altrimenti, seguita da un elenco puntato dei criteri NON
soddisfatti e di cosa manca." | tee /tmp/review.txt
echo "::endgroup::"
if grep -q 'VERDICT: PASS' /tmp/review.txt; then
echo "✅ Acceptance criteria soddisfatti all'iterazione $i."
exit 0
fi
REVIEW_FEEDBACK="$(cat /tmp/review.txt)"
echo "⚠️ Criteri non ancora soddisfatti: procedo con l'iterazione $((i+1))."
done
echo "Raggiunto il tetto di $MAX_ITERATIONS iterazioni senza PASS completo:"
echo "le modifiche parziali verranno comunque pushate per revisione umana."
- name: Pusha modifiche e apri/aggiorna la PR
id: push
run: |
API="$GITEA_API_URL/api/v1/repos/$REPO_FULL_NAME"
BRANCH_NAME="${{ steps.ctx.outputs.branch_name }}"
if [ -z "$(git status --porcelain)" ]; then
echo "Nessuna modifica rilevata da OpenCode."
git add .
git commit -m "OpenCode (big-pickle): $BRANCH_NAME" || echo "Niente di nuovo da committare oltre al loop."
if git diff --quiet origin/main..HEAD 2>/dev/null; then
echo "Nessuna modifica rispetto a main: niente da pushare."
echo "pr_number=" >> "$GITHUB_OUTPUT"
exit 0
fi
git add .
git commit -m "OpenCode (big-pickle): $BRANCH_NAME"
git push origin "$BRANCH_NAME"
if [ "${{ steps.ctx.outputs.is_pr }}" != "true" ]; then
curl -s -X POST "$API/pulls" \
if [ "${{ steps.ctx.outputs.is_pr }}" = "true" ]; then
PR_NUMBER="${{ steps.ctx.outputs.pr_number }}"
else
RESP=$(curl -s -X POST "$API/pulls" \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"base\":\"main\",\"head\":\"$BRANCH_NAME\",\"title\":\"PR Automatica OpenCode: $BRANCH_NAME\",\"body\":\"Generata da big-pickle su richiesta di @$COMMENT_AUTHOR.\"}"
-d "{\"base\":\"main\",\"head\":\"$BRANCH_NAME\",\"title\":\"PR Automatica OpenCode: $BRANCH_NAME\",\"body\":\"Generata da big-pickle su richiesta di @$COMMENT_AUTHOR. Piano: issue_plans/${{ steps.ctx.outputs.plan_key }}.md\"}")
PR_NUMBER=$(echo "$RESP" | jq -r '.number // empty')
# Se la PR per questo branch esiste già, recuperane il numero.
if [ -z "$PR_NUMBER" ]; then
PR_NUMBER=$(curl -s -H "Authorization: token $GITEA_TOKEN" "$API/pulls?state=open&limit=50" \
| jq -r --arg b "$BRANCH_NAME" '.[] | select(.head.ref==$b) | .number' | head -n1)
fi
fi
echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
# Passo finale: la review dell'agente viene postata come REVIEW sulla PR
# (event COMMENT: evita i vincoli sul self-approve del proprio branch).
- name: Posta la review sulla PR
if: always()
continue-on-error: true
run: |
API="$GITEA_API_URL/api/v1/repos/$REPO_FULL_NAME"
PR_NUMBER="${{ steps.push.outputs.pr_number }}"
[ -z "$PR_NUMBER" ] && PR_NUMBER="${{ steps.ctx.outputs.pr_number }}"
if [ -z "$PR_NUMBER" ] || [ ! -s /tmp/review.txt ]; then
echo "Nessuna PR o nessuna review da postare."
exit 0
fi
# Il verdetto guida lo stato nativo della review.
if grep -q 'VERDICT: PASS' /tmp/review.txt; then
EVENT="APPROVE"
else
EVENT="REQUEST_CHANGES"
fi
BODY=$(jq -Rs . < /tmp/review.txt) # encoding JSON-safe del testo review
post_review() {
curl -s -o /tmp/review_resp.json -w '%{http_code}' \
-X POST "$API/pulls/$PR_NUMBER/reviews" \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"body\":$BODY,\"event\":\"$1\"}"
}
CODE=$(post_review "$EVENT")
echo "Review '$EVENT' -> HTTP $CODE"
# Gitea rifiuta APPROVE/REQUEST_CHANGES sulla PR di cui il bot è autore:
# in quel caso ripiega su un commento di review (event=COMMENT).
if [ "$CODE" -ge 300 ]; then
echo "Fallback a event=COMMENT (probabile self-review su PR del bot). Risposta:"
cat /tmp/review_resp.json 2>/dev/null || true
echo
CODE=$(post_review "COMMENT")
echo "Review 'COMMENT' -> HTTP $CODE"
fi
# Stato finale via reazione (niente commenti -> niente self-trigger).
- name: Reazione finale 🚀
if: success() && steps.react.outputs.path != ''
continue-on-error: true
@@ -202,7 +353,7 @@ jobs:
-H "Content-Type: application/json" \
-d '{"content":"rocket"}' >/dev/null || true
- name: Reazione finale 😕 (fallimento)
- name: Reazione in caso di errore 😕
if: failure() && steps.react.outputs.path != ''
continue-on-error: true
run: |
+97
View File
@@ -0,0 +1,97 @@
name: Publish Docker Image
on:
workflow_dispatch:
inputs:
proxy_mode:
description: 'Proxy mode (nginx o traefik)'
required: true
default: 'nginx'
type: choice
options:
- nginx
- traefik
push:
tags:
- 'v*'
env:
IMAGE_NAME: ${{ gitea.repository }}
IMAGE_TAG: ${{ gitea.ref_name }}
# Registry (default Docker Hub, cambia con un secret se usi un registry privato)
REGISTRY: ${{ secrets.DOCKER_REGISTRY || 'docker.io' }}
# Modalità proxy
PROXY_MODE: ${{ inputs.proxy_mode || 'nginx' }}
# Container name sulla VPS
CONTAINER_NAME: test-app
# Porta host per modalità nginx
HOST_PORT: ${{ secrets.HOST_PORT || '8080' }}
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
- name: Deploy to VPS via SSH
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.VPS_SSH_KEY }}
port: ${{ secrets.VPS_PORT || '22' }}
envs: IMAGE_NAME,IMAGE_TAG,REGISTRY,PROXY_MODE,CONTAINER_NAME,HOST_PORT
script: |
set -e
FULL_IMAGE="$REGISTRY/$IMAGE_NAME:$IMAGE_TAG"
echo "=== Pull immagine ==="
echo "$DOCKER_PASSWORD" | docker login "$REGISTRY" -u "$DOCKER_USERNAME" --password-stdin 2>/dev/null || true
docker pull "$FULL_IMAGE"
echo "=== Ferma e rimuovi container esistente ==="
docker stop "$CONTAINER_NAME" 2>/dev/null || true
docker rm "$CONTAINER_NAME" 2>/dev/null || true
echo "=== Avvia container (proxy: $PROXY_MODE) ==="
if [ "$PROXY_MODE" = "traefik" ]; then
docker run -d \
--name "$CONTAINER_NAME" \
--network traefik \
--label "traefik.enable=true" \
--label "traefik.http.routers.$CONTAINER_NAME.rule=Host(\`${{ secrets.DOMAIN }}\`)" \
--label "traefik.http.services.$CONTAINER_NAME.loadbalancer.server.port=80" \
"$FULL_IMAGE"
else
docker run -d \
--name "$CONTAINER_NAME" \
-p "$HOST_PORT:80" \
"$FULL_IMAGE"
fi
echo "=== Pulizia ==="
docker image prune -f
echo "=== Deploy completato ==="
echo "Immagine: $FULL_IMAGE"
echo "Proxy: $PROXY_MODE"
+7
View File
@@ -0,0 +1,7 @@
FROM nginx:stable-alpine
COPY index.html /usr/share/nginx/html/index.html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
+618 -56
View File
@@ -3,10 +3,12 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Prova</title>
<title>OpenCode Gitea Integration — Test Repository</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js" defer></script>
<script src="https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.min.js" defer></script>
<style>
* {
margin: 0;
@@ -14,73 +16,95 @@
box-sizing: border-box;
}
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 1rem;
html {
scroll-behavior: smooth;
}
.card {
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
background-attachment: fixed;
min-height: 100vh;
padding: 2rem 1rem;
color: #1a1a2e;
}
/* Navigation */
nav {
max-width: 900px;
margin: 0 auto 2rem;
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(10px);
border-radius: 16px;
padding: 1rem 2rem;
display: flex;
flex-wrap: wrap;
gap: 0.5rem 1.5rem;
justify-content: center;
box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}
nav a {
color: #667eea;
text-decoration: none;
font-weight: 600;
font-size: 0.9rem;
padding: 0.3rem 0;
border-bottom: 2px solid transparent;
transition: border-color 0.2s, color 0.2s;
}
nav a:hover {
border-bottom-color: #667eea;
color: #764ba2;
}
/* Main container */
.container {
max-width: 900px;
margin: 0 auto;
}
/* Hero */
.hero {
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(10px);
border-radius: 24px;
padding: 3rem 3.5rem;
max-width: 480px;
width: 100%;
padding: 3rem;
text-align: center;
box-shadow:
0 20px 60px rgba(0, 0, 0, 0.15),
0 1px 3px rgba(0, 0, 0, 0.08);
transition: transform 0.3s ease, box-shadow 0.3s ease;
margin-bottom: 2rem;
box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
.card:hover {
transform: translateY(-4px);
box-shadow:
0 30px 80px rgba(0, 0, 0, 0.2),
0 1px 3px rgba(0, 0, 0, 0.08);
}
.icon {
width: 72px;
height: 72px;
.hero .icon {
width: 80px;
height: 80px;
margin: 0 auto 1.5rem;
background: linear-gradient(135deg, #667eea, #764ba2);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 2rem;
font-size: 2.2rem;
}
h1 {
font-size: 1.75rem;
.hero h1 {
font-size: 2rem;
font-weight: 700;
color: #1a1a2e;
margin-bottom: 0.75rem;
letter-spacing: -0.02em;
}
p {
font-size: 1rem;
line-height: 1.6;
.hero p {
font-size: 1.05rem;
line-height: 1.7;
color: #555;
margin-bottom: 2rem;
max-width: 600px;
margin: 0 auto;
}
.divider {
width: 48px;
height: 4px;
margin: 0 auto 2rem;
background: linear-gradient(90deg, #667eea, #764ba2);
border-radius: 2px;
}
.badge {
.hero .badge {
display: inline-block;
padding: 0.4rem 1.2rem;
background: linear-gradient(135deg, #667eea, #764ba2);
@@ -88,27 +112,565 @@
border-radius: 100px;
font-size: 0.8rem;
font-weight: 600;
letter-spacing: 0.02em;
margin-top: 1.2rem;
}
@media (max-width: 480px) {
.card {
padding: 2rem 1.5rem;
border-radius: 16px;
/* Sections */
.section {
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(10px);
border-radius: 24px;
padding: 2.5rem 3rem;
margin-bottom: 2rem;
box-shadow: 0 10px 40px rgba(0,0,0,0.1);
}
.section h2 {
font-size: 1.6rem;
font-weight: 700;
color: #1a1a2e;
margin-bottom: 1.5rem;
letter-spacing: -0.01em;
display: flex;
align-items: center;
gap: 0.6rem;
}
.section h2::after {
content: '';
flex: 1;
height: 3px;
background: linear-gradient(90deg, #667eea, transparent);
border-radius: 2px;
margin-left: 0.5rem;
}
.section h3 {
font-size: 1.2rem;
font-weight: 600;
color: #333;
margin: 1.5rem 0 0.8rem;
}
.section p, .section li {
font-size: 1rem;
line-height: 1.7;
color: #555;
}
.section p {
margin-bottom: 1rem;
}
.section ul, .section ol {
padding-left: 1.5rem;
margin-bottom: 1rem;
}
.section li {
margin-bottom: 0.4rem;
}
.section strong {
color: #333;
}
.section code {
background: #f0f0f5;
padding: 0.15rem 0.4rem;
border-radius: 4px;
font-size: 0.88rem;
color: #764ba2;
}
.section pre {
background: #f5f5fa;
padding: 1rem 1.2rem;
border-radius: 10px;
overflow-x: auto;
margin-bottom: 1rem;
border: 1px solid #e8e8ee;
}
.section pre code {
background: none;
padding: 0;
color: #333;
}
/* Mermaid containers */
.mermaid-container {
background: #fff;
border: 2px solid #e8e8ee;
border-radius: 12px;
padding: 1.5rem;
margin: 1.5rem 0;
overflow-x: auto;
}
.mermaid-container .mermaid {
text-align: center;
}
/* Tables */
.section table {
width: 100%;
border-collapse: collapse;
margin: 1rem 0 1.5rem;
font-size: 0.95rem;
}
.section th {
background: linear-gradient(135deg, #667eea, #764ba2);
color: #fff;
padding: 0.7rem 1rem;
text-align: left;
font-weight: 600;
}
.section th:first-child {
border-radius: 8px 0 0 0;
}
.section th:last-child {
border-radius: 0 8px 0 0;
}
.section td {
padding: 0.6rem 1rem;
border-bottom: 1px solid #eee;
color: #555;
}
.section tr:last-child td {
border-bottom: none;
}
.section td:first-child {
font-weight: 600;
color: #333;
}
/* Step list */
.step-list {
list-style: none;
padding: 0;
counter-reset: step;
}
.step-list li {
counter-increment: step;
padding: 1rem 1rem 1rem 3.5rem;
position: relative;
background: #f8f8ff;
border-radius: 12px;
margin-bottom: 0.8rem;
border-left: 4px solid #667eea;
}
.step-list li::before {
content: counter(step);
position: absolute;
left: 0.8rem;
top: 1rem;
width: 28px;
height: 28px;
background: linear-gradient(135deg, #667eea, #764ba2);
color: #fff;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 0.8rem;
font-weight: 700;
}
.step-list li strong {
display: block;
font-size: 1.05rem;
margin-bottom: 0.25rem;
}
.step-list li p {
margin: 0;
}
/* Markdown rendered content */
.md-content h1, .md-content h2, .md-content h3 {
margin-top: 1.2rem;
}
.md-content ul, .md-content ol {
padding-left: 1.5rem;
margin-bottom: 1rem;
}
.md-content code {
background: #f0f0f5;
padding: 0.15rem 0.4rem;
border-radius: 4px;
font-size: 0.88rem;
}
.md-content pre {
background: #f5f5fa;
padding: 1rem;
border-radius: 10px;
overflow-x: auto;
margin-bottom: 1rem;
}
/* Divider */
.divider {
width: 48px;
height: 4px;
margin: 0 auto 1.5rem;
background: linear-gradient(90deg, #667eea, #764ba2);
border-radius: 2px;
}
.section-divider {
width: 60px;
height: 4px;
margin: 0 0 1.5rem;
background: linear-gradient(90deg, #667eea, #764ba2);
border-radius: 2px;
}
/* Responsive */
@media (max-width: 640px) {
body {
padding: 1rem 0.75rem;
}
h1 {
font-size: 1.4rem;
.hero {
padding: 2rem 1.5rem;
}
.hero h1 {
font-size: 1.5rem;
}
.section {
padding: 1.5rem 1.2rem;
}
.section h2 {
font-size: 1.3rem;
}
nav {
padding: 0.8rem 1rem;
gap: 0.4rem 1rem;
}
nav a {
font-size: 0.8rem;
}
.step-list li {
padding: 0.8rem 0.8rem 0.8rem 3rem;
}
.section th, .section td {
padding: 0.5rem 0.7rem;
font-size: 0.85rem;
}
}
</style>
</head>
<body>
<div class="card">
<div class="icon"></div>
<nav>
<a href="#intento">Repo Intent</a>
<a href="#workflow">Workflow opencode.yml</a>
<a href="#trigger">Trigger &amp; Eventi</a>
<a href="#sicurezza">Autorizzazione &amp; Sicurezza</a>
</nav>
<div class="container">
<!-- Hero -->
<div class="hero">
<div class="icon">&#9889;</div>
<div class="divider"></div>
<h1>Pagina di prova</h1>
<p>Questa è una pagina HTML di test realizzata con cura per un aspetto più elegante e moderno.</p>
<span class="badge">HTML &nbsp;·&nbsp; CSS &nbsp;·&nbsp; Design</span>
<h1>OpenCode &times; Gitea Actions</h1>
<p>Repository di test per l'integrazione tra Gitea Actions e agenti AI OpenCode. Automazione agentica su eventi di issue, PR, commenti e dispatch manuale.</p>
<span class="badge">Gitea Actions &nbsp;&middot;&nbsp; OpenCode &nbsp;&middot;&nbsp; AI Agents</span>
</div>
<!-- Sezione 1: Repo Intent -->
<section class="section" id="intento">
<h2>Repo Intent</h2>
<div class="section-divider"></div>
<div class="md-content" data-md>
Questo repository è un banco di prova per l'**automazione agentica** tramite [OpenCode](https://opencode.ai) su eventi di Gitea, utilizzando le **Gitea Actions** come runtime di esecuzione.
L'obiettivo è verificare il ciclo completo:
1. Un evento (push, issue aperta, commento su issue o PR, esecuzione manuale) triggera un workflow.
2. Un agente AI analizza la richiesta, produce un piano, lo implementa, lo verifica e apre una Pull Request.
3. Il tutto avviene in modo **autonomo**, con sole reazioni (👀, 🚀, 😕) come feedback — senza commenti che genererebbero loop infiniti.
### Workflow presenti
| Workflow | File | Descrizione |
|---|---|---|
| **Gitea Actions Demo** | `.gitea/workflows/demo.yml` | Workflow dimostrativo su push: mostra le variabili d'ambiente Gitea ed elenca i file. Puramente educativo. |
| **OpenCode Gitea Integration** | `.gitea/workflows/opencode.yml` | Automazione agentica completa: pianifica, implementa e revisiona codice su eventi issue/PR/commento/manuale. |
| **Publish Docker Image** | `.gitea/workflows/publish.yml` | Build e push di un'immagine Docker su tag `v*` o dispatch manuale, con deploy su VPS via SSH. |
</div>
</section>
<!-- Sezione 2: Workflow opencode.yml -->
<section class="section" id="workflow">
<h2>Workflow <code>opencode.yml</code> per filo e per segno</h2>
<div class="section-divider"></div>
<p>Il cuore del repository. Ecco ogni passo del workflow, nell'ordine esatto in cui viene eseguito.</p>
<ol class="step-list">
<li>
<strong>Verifica autorizzazione utente</strong>
<p>Controlla che l'autore dell'evento sia nella whitelist (<code>maria</code>, <code>nicola</code>). Le esecuzioni manuali (<code>workflow_dispatch</code>) saltano questo controllo. Se l'utente non è autorizzato, il job viene interrotto con errore.</p>
</li>
<li>
<strong>Reagisci al comando (👀)</strong>
<p>Aggiunge una reazione "eyes" all'issue o al commento che ha triggerato il workflow. Le reazioni non generano eventi <code>issue_comment</code>, quindi non c'è rischio di auto-trigger o loop infiniti.</p>
</li>
<li>
<strong>Checkout repository</strong>
<p>Clona il repository con <code>fetch-depth: 0</code> (storia completa) tramite <code>actions/checkout@v4</code>.</p>
</li>
<li>
<strong>Installazione OpenCode CLI</strong>
<p>Scarica e installa la CLI di OpenCode via <code>curl -fsSL https://opencode.ai/install | bash</code>. Aggiunge <code>$HOME/.opencode/bin</code> al <code>PATH</code>.</p>
</li>
<li>
<strong>Configura agent reviewer (read-only)</strong>
<p>Crea un agente <code>reviewer</code> con permessi di sola lettura: può solo leggere file ed eseguire comandi (build, lint, test). Non può mai modificare il codice. Il file viene escluso dal tracker tramite <code>.git/info/exclude</code>.</p>
</li>
<li>
<strong>Determina contesto (issue / PR / manuale) e branch di lavoro</strong>
<p>Analizza il tipo di evento:</p>
<ul>
<li><strong>PR</strong> — fa il fetch e checkout del branch della PR.</li>
<li><strong>Issue</strong> — crea un branch <code>opencode-issue-&lt;N&gt;</code> a partire da <code>main</code>.</li>
<li><strong>Manuale</strong> — crea un branch <code>opencode-manual-&lt;run_number&gt;</code>.</li>
</ul>
<p>Genera anche una <code>plan_key</code> univoca per salvare il file di piano.</p>
</li>
<li>
<strong>Raccogli contesto aggiuntivo (diff + commenti, se PR)</strong>
<p>Se si tratta di una Pull Request, scarica il <strong>diff</strong> della PR e i <strong>commenti recenti</strong> per fornire contesto completo all'agente AI.</p>
</li>
<li>
<strong>Pulisci il comando dal trigger</strong>
<p>Rimuove i marcatori <code>/oc</code> e <code>/opencode</code> dal corpo del messaggio, lasciando solo le istruzioni utente da passare all'agente.</p>
</li>
<li>
<strong>Fase 1 — Plan (analisi read-only)</strong>
<p>Eseguita solo per issue (non PR). L'agente <code>plan</code> analizza il codebase e la richiesta, poi produce un piano di lavoro in Markdown con struttura standard (Obiettivo, Task, Acceptance Criteria, Verifica). Il piano viene salvato in <code>issue_plans/</code> e committato.</p>
</li>
<li>
<strong>Fase 2 — Build &amp; Review loop</strong>
<p>Il cuore dell'automazione: un loop che alterna <strong>Build</strong> (implementazione) e <strong>Review</strong> (verifica), fino a <code>$MAX_ITERATIONS</code> (4).</p>
<ul>
<li><strong>BUILD</strong> — L'agente <code>build</code> implementa il piano, modificando i file necessari.</li>
<li><strong>REVIEW</strong> — L'agente <code>reviewer</code> (read-only) verifica se ogni Acceptance Criterion è soddisfatto e produce un <strong>VERDICT</strong>: <code>PASS</code> (loop termina) o <code>FAIL</code> (loop continua col feedback).</li>
</ul>
<p>Se dopo 4 iterazioni il PASS non è raggiunto, le modifiche parziali vengono comunque pushate per revisione umana.</p>
</li>
<li>
<strong>Pusha modifiche e apri/aggiorna la PR</strong>
<p>Commatta e pusha le modifiche sul branch di lavoro. Se si lavora su un'issue (non PR), apre automaticamente una Pull Request verso <code>main</code>. Se la PR esiste già, ne recupera il numero.</p>
</li>
<li>
<strong>Posta la review sulla PR</strong>
<p>Se esiste una PR, posta la review finale dell'agente usando l'API di Gitea. Se il verdetto è <code>PASS</code>, la review è di tipo <code>APPROVE</code>; altrimenti <code>REQUEST_CHANGES</code>. Se Gitea rifiuta (self-review del bot), ripiega su <code>COMMENT</code>.</p>
</li>
<li>
<strong>Reazione finale 🚀 / 😕</strong>
<p>Se il workflow termina con <code>success()</code>, aggiunge una reazione <strong>🚀</strong> all'elemento trigger. In caso di <code>failure()</code>, aggiunge <strong>😕</strong> (confused).</p>
</li>
</ol>
<h3>Diagramma di flusso generale</h3>
<div class="mermaid-container">
<pre class="mermaid">
flowchart LR
A[Evento Trigger] --> B{Autorizzato?}
B -- No --> X[❌ Interrompi]
B -- Sì --> C[👀 Reazione eyes]
C --> D[📦 Checkout]
D --> E[⬇️ Installa OpenCode]
E --> F[🔧 Configura reviewer]
F --> G{Contesto?}
G -- PR --> H1[Fetch & checkout PR]
G -- Issue --> H2[Branch opencode-issue-N]
G -- Manuale --> H3[Branch opencode-manual-RUN]
H1 & H2 & H3 --> I[📋 Raccogli contesto]
I --> J[🧹 Pulisci comando]
J --> K{È issue?}
K -- Sì --> L[📝 Fase Plan]
L --> M
K -- No --> M[🔄 Build & Review loop]
M --> N{VERDICT PASS?}
N -- Sì --> O[✅ Push & PR]
N -- No --> P{Iterazioni &lt; MAX?}
P -- Sì --> M
P -- No --> O
O --> Q[📬 Posta review]
Q --> R[🚀 Reazione finale]
</pre>
</div>
<h3>Diagramma di sequenza Gitea → Runner → OpenCode</h3>
<div class="mermaid-container">
<pre class="mermaid">
sequenceDiagram
participant U as Utente
participant G as Gitea
participant R as Gitea Runner
participant O as OpenCode CLI
participant A as Agenti AI
U->>G: Apre issue/commenta con /oc
G->>R: Triggera workflow
R->>R: Verifica autorizzazione
R->>G: 👀 Reazione eyes
R->>R: Checkout & installa CLI
R->>O: opencode run --agent plan
O->>A: Analisi codebase
A-->>O: Piano Markdown
O-->>R: Piano salvato
loop Build & Review (max 4)
R->>O: opencode run --agent build
O->>A: Implementa piano
A-->>O: Modifiche ai file
O-->>R: Codice modificato
R->>O: opencode run --agent reviewer
O->>A: Verifica criteri
A-->>O: VERDICT PASS/FAIL
O-->>R: Risultato review
alt PASS
R->>R: Esce dal loop
else FAIL
R->>R: Continua iterazione
end
end
R->>G: Push modifiche & PR
R->>G: 🚀 Reazione finale
</pre>
</div>
<h3>Diagramma del loop Build/Review con criterio di uscita VERDICT</h3>
<div class="mermaid-container">
<pre class="mermaid">
flowchart TD
START([🔄 Inizio loop]) --> BUILD[👷 Fase BUILD<br/>Agente implementa il piano]
BUILD --> REVIEW[🔍 Fase REVIEW<br/>Agente verifica criteri]
REVIEW --> DECIDE{VERDICT?}
DECIDE -- PASS ✅ --> EXIT([🏁 Esci dal loop<br/>✅ Successo])
DECIDE -- FAIL ❌ --> CHECK{Iterazioni &lt; MAX?}
CHECK -- Sì --> FEEDBACK[💬 Feedback: criteri insoddisfatti]
FEEDBACK --> BUILD
CHECK -- No --> MAXOUT([⚠️ Raggiunto tetto MAX<br/>Pusha modifiche parziali])
</pre>
</div>
</section>
<!-- Sezione 3: Trigger ed Eventi -->
<section class="section" id="trigger">
<h2>Trigger ed Eventi</h2>
<div class="section-divider"></div>
<div class="md-content" data-md>
Il workflow `opencode.yml` si attiva sui seguenti eventi di Gitea:
| Evento | Tipo | Descrizione | Trigger per `/oc` |
|---|---|---|---|
| `issues` | `opened` | Apertura di una nuova issue | Il corpo della issue contiene `/oc` o `/opencode` |
| `issue_comment` | `created` | Nuovo commento su una issue | Il commento contiene `/oc` o `/opencode` |
| `pull_request_review_comment` | `created` | Nuovo commento su una PR | Il commento contiene `/oc` o `/opencode` |
| `workflow_dispatch` | manuale | Esecuzione manuale da UI/API | Sempre attivo (campo `prompt` richiesto) |
### Filtri di attivazione
Oltre al contenuto del messaggio, il workflow verifica che:
- L'autore **non** sia `opencode-bot` (evita auto-trigger)
- L'autore sia nella **whitelist** (tranne per esecuzione manuale)
- Il corpo del messaggio contenga `/oc` o `/opencode` (tranne per dispatch manuale)
</div>
</section>
<!-- Sezione 4: Autorizzazione e Sicurezza -->
<section class="section" id="sicurezza">
<h2>Autorizzazione e Sicurezza</h2>
<div class="section-divider"></div>
<div class="md-content" data-md>
### Whitelist utenti
Solo gli utenti autorizzati possono invocare l'agente AI:
- `maria`
- `nicola`
Per le esecuzioni manuali (`workflow_dispatch`) il controllo è bypassato.
### Blocco auto-trigger
I commenti pubblicati da `opencode-bot` vengono ignorati: il workflow non risponde ai propri stessi messaggi, prevenendo loop infiniti.
### Reazioni (non commenti)
Il workflow interagisce con issue e PR esclusivamente tramite **reazioni** (👀, 🚀, 😕). Le reazioni non generano eventi `issue_comment`, quindi non possono innescare nuove esecuzioni del workflow.
### Secret utilizzati
| Secret | Descrizione |
|---|---|
| `BOT_GITEA_TOKEN` | Token di accesso per l'API di Gitea (operazioni CRUD su repo, issue, PR) |
| `OPENCODE_ZEN_API_KEY` | API key per il provider OpenAI-compatible di OpenCode |
</div>
</section>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Render Markdown via marked.js
document.querySelectorAll('[data-md]').forEach(function(el) {
if (typeof marked !== 'undefined') {
el.innerHTML = marked.parse(el.textContent);
}
});
// Initialize Mermaid
if (typeof mermaid !== 'undefined') {
mermaid.initialize({
startOnLoad: false,
theme: 'default',
themeVariables: {
primaryColor: '#667eea',
secondaryColor: '#764ba2',
tertiaryColor: '#f0f0ff',
primaryTextColor: '#333',
lineColor: '#667eea'
},
flowchart: {
useMaxWidth: true,
htmlLabels: true
},
sequence: {
useMaxWidth: true,
showSequenceNumbers: false
}
});
mermaid.run({ nodes: document.querySelectorAll('.mermaid') });
}
});
</script>
</body>
</html>
+38
View File
@@ -0,0 +1,38 @@
Ecco il piano:
# Piano
## Obiettivo
Trasformare `index.html` da pagina statica "Pagina di prova" in una documentazione interattiva che spiega l'intento del repo (test di Gitea Actions + automazione agentica OpenCode) e l'intera pipeline `opencode.yml` usando Markdown e diagrammi Mermaid renderizzati a runtime via CDN.
## Task
1. **Riscrivere `index.html` — struttura HTML** — Aggiungere sezioni: repo intent, demo workflow (cenno), pipeline opencode.yml (dettaglio). Includere via CDN `marked.js` per Markdown e `mermaid.js` per diagrammi.
2. **Sezione "Repo Intent"** — Spiegare che il repo testa Gitea Actions e agenti AI OpenCode su eventi (push, issues, PR, commenti, manuale). Eventuale riferimento ai 3 workflow (demo, opencode, publish).
3. **Sezione "Workflow opencode.yml per filo e per segno"** — Spiegare ogni step del workflow (autorizzazione, reazione 👀, checkout, installazione OpenCode, determinazione contesto, raccolta contesto, pulizia comando, fase plan, fase build/review loop, push/PR, review finale, reazione 🚀/😕). Integrare **diagrammi Mermaid**:
- Diagramma a blocchi/flusso generale del workflow (flowchart LR)
- Diagramma di sequenza Gitea → Runner → OpenCode
- Diagramma del loop Build/Review con criterio di uscita VERDICT
4. **Sezione "Trigger ed Eventi"** — Tabella riassuntiva eventi e descrizione.
5. **Sezione "Autorizzazione e Sicurezza"** — Whitelist utenti, blocco auto-trigger (opencode-bot), uso di secret.
6. **Stile e layout** — Mantenere coerenza con palette viola attuale. Aggiungere navigazione interna (anchor link), scroll fluido. Le sezioni con diagrammi Mermaid hanno container con sfondo bianco e bordo per rendering corretto.
File coinvolti:
- `index.html` (sostituzione completa contenuto)
## Acceptance Criteria
- [ ] `index.html` carica `marked.js` e `mermaid.js` da CDN
- [ ] `index.html` spiega chiaramente l'intento del repository (test Gitea Actions + automazione agentica OpenCode)
- [ ] `index.html` spiega ogni step della pipeline `opencode.yml` in ordine, con descrizione testuale chiara
- [ ] Almeno 3 diagrammi Mermaid integrati (flusso generale, sequenza, loop build/review)
- [ ] I diagrammi Mermaid sono renderizzati correttamente (non mostrano il codice sorgente)
- [ ] Contenuto Markdown nelle sezioni è renderizzato correttamente via `marked.js`
- [ ] Pagina responsive, navigabile (sezioni con id, scroll fluido)
- [ ] Mantiene palette gradient viola come tema visivo
- [ ] Non ci sono errori in console (JS) a caricamento avvenuto
## Verifica
1. Aprire `index.html` in un browser (o via `npx serve .`)
2. Verificare che i diagrammi Mermaid vengano renderizzati (non mostrati come testo)
3. Verificare che il testo Markdown sia formattato correttamente
4. Verificare che tutte le sezioni siano leggibili e complete
5. Controllare la console del browser per eventuali errori JS