tools(agent-loop): copse onboarding, PR/merge/runs commands, trusted claude-agent/grok-agent accounts
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014Ad9rqAB8pXXvyzh7f4X8v
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
358a41fe52
commit
05f8800531
@@ -64,11 +64,10 @@ privacy_ok() {
|
||||
# Marker fields: <!-- agent:claude review sha=abc verdict=fail ... -->
|
||||
marker_field() { sed -nE "s/.* $1=([^ ]+).*/\1/p" <<<"$2"; }
|
||||
|
||||
# Only comments written by the owner account (the product owner and both agents
|
||||
# post as it) are read. Anyone else's comment is ignored, never passed to a model.
|
||||
OWNER="${AGENT_LOOP_OWNER:-$("$GITEA" whoami)}"
|
||||
[[ -n "$OWNER" && "$OWNER" != null ]] || { log "cannot resolve owner account"; exit 1; }
|
||||
comments_json() { "$GITEA" comments "$1" | jq --arg o "$OWNER" '[.[] | select(.user.login == $o)]'; }
|
||||
# gitea.sh returns only trusted accounts' text (jesse, claude-agent, grok-agent);
|
||||
# anyone else's comment never reaches a model.
|
||||
OWNER="${AGENT_LOOP_OWNER:-jesse}"
|
||||
comments_json() { "$GITEA" comments "$1"; }
|
||||
|
||||
# Bodies' first lines (markers) of agent comments, oldest first.
|
||||
markers() { comments_json "$1" | jq -r '.[].body | split("\n")[0] | select(startswith("<!-- agent:"))'; }
|
||||
@@ -91,7 +90,7 @@ prepare_worktree() {
|
||||
build_context() { # build_context N MODE OUT_JSON [EXTRA_JSON]
|
||||
local n="$1" mode="$2" out="$3" extra="${4:-null}"
|
||||
jq -n \
|
||||
--argjson issue "$("$GITEA" issue "$n" | jq --arg o "$OWNER" '{number, title, body: (if .user.login == $o then .body else "(非本人账号创建的 issue,正文已忽略)" end), created_at, labels: [.labels[].name]}')" \
|
||||
--argjson issue "$("$GITEA" issue "$n" | jq '{number, title, body, created_at, labels: [.labels[].name]}')" \
|
||||
--argjson comments "$(comments_json "$n" | jq '[.[] | {created_at, body}]')" \
|
||||
--arg mode "$mode" \
|
||||
--arg staging "$(git -C "$REPO_DIR" rev-parse origin/staging)" \
|
||||
@@ -123,7 +122,7 @@ fail_run() { # fail_run N STATE REASON — keep the state, count errors,
|
||||
errs="$(count_errors_since_progress "$n")"
|
||||
if (( errs >= MAX_ERRORS )); then
|
||||
set_state "$n" agent/需拍板
|
||||
post_text "$n" "<!-- agent:claude escalate -->" "@jesse 连续 $errs 轮自动处理失败,已停下等你决定。最近一次原因:$reason。日志在开发机 $LOG。"
|
||||
post_text "$n" "<!-- agent:claude escalate -->" "@$OWNER 连续 $errs 轮自动处理失败,已停下等你决定。最近一次原因:$reason。日志在开发机 $LOG。"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -149,7 +148,7 @@ for n in $("$GITEA" issues "agent/部署中,$PILOT_LABEL" | jq -r '.[].number');
|
||||
m="$(latest_marker "$n" 'agent:claude review')"
|
||||
want="$(marker_field staging "$m")"
|
||||
checklist="$(marker_field checklist "$m")"
|
||||
[[ -z "$want" ]] && { set_state "$n" agent/需拍板; post_text "$n" "<!-- agent:claude escalate -->" "@jesse 找不到验收记录里的 staging 提交号,无法核对部署,请人工看一下。"; continue; }
|
||||
[[ -z "$want" ]] && { set_state "$n" agent/需拍板; post_text "$n" "<!-- agent:claude escalate -->" "@$OWNER 找不到验收记录里的 staging 提交号,无法核对部署,请人工看一下。"; continue; }
|
||||
git -C "$REPO_DIR" fetch -q origin
|
||||
ok=0
|
||||
if [[ -n "$deployed" ]]; then
|
||||
@@ -162,7 +161,7 @@ for n in $("$GITEA" issues "agent/部署中,$PILOT_LABEL" | jq -r '.[].number');
|
||||
[[ -n "$checklist" && "$checklist" != "-" ]] && note="$note
|
||||
|
||||
请照真机清单走一遍:\`$checklist\`。没问题就关闭本 issue;有问题直接在下面写,并把标签改回 \`agent/待规划\`。"
|
||||
post_text "$n" "<!-- agent:claude deployed sha=$deployed -->" "@jesse $note"
|
||||
post_text "$n" "<!-- agent:claude deployed sha=$deployed -->" "@$OWNER $note"
|
||||
set_state "$n" agent/待真机
|
||||
log "issue #$n: deployed $deployed contains $want → 待真机"
|
||||
else
|
||||
@@ -170,7 +169,7 @@ for n in $("$GITEA" issues "agent/部署中,$PILOT_LABEL" | jq -r '.[].number');
|
||||
age_h=$(( ( $(date +%s) - $(date -d "$since" +%s) ) / 3600 ))
|
||||
if (( age_h >= DEPLOY_WAIT_HOURS )); then
|
||||
set_state "$n" agent/需拍板
|
||||
post_text "$n" "<!-- agent:claude escalate -->" "@jesse 推上 staging 已 ${age_h} 小时,部署仍未包含 ${want:0:9}(当前部署 ${deployed:0:9})。可能是门禁红了,请到 Gitea Actions 看一下。"
|
||||
post_text "$n" "<!-- agent:claude escalate -->" "@$OWNER 推上 staging 已 ${age_h} 小时,部署仍未包含 ${want:0:9}(当前部署 ${deployed:0:9})。可能是门禁红了,请到 Gitea Actions 看一下。"
|
||||
log "issue #$n: deploy wait exceeded"
|
||||
fi
|
||||
fi
|
||||
@@ -260,7 +259,7 @@ else
|
||||
post "$n" "<!-- agent:claude review sha=$sha verdict=fail brief=$fix branch=$branch -->" "$RUN_DIR/comment.md"
|
||||
if (( ${fails:-0} + 1 >= MAX_BOUNCES )); then
|
||||
set_state "$n" agent/需拍板
|
||||
post_text "$n" "<!-- agent:claude escalate -->" "@jesse 这一单已被验收打回 $(( ${fails:-0} + 1 )) 次,按规矩停下,等你决定是继续、改方向还是放弃。"
|
||||
post_text "$n" "<!-- agent:claude escalate -->" "@$OWNER 这一单已被验收打回 $(( ${fails:-0} + 1 )) 次,按规矩停下,等你决定是继续、改方向还是放弃。"
|
||||
else
|
||||
set_state "$n" agent/待执行
|
||||
fi ;;
|
||||
|
||||
Reference in New Issue
Block a user