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:
Jesse_Chen
2026-10-13 13:17:16 +08:00
co-authored by Claude Opus 5.5
parent 358a41fe52
commit 05f8800531
11 changed files with 194 additions and 33 deletions
+10 -11
View File
@@ -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 ;;
+18 -7
View File
@@ -4,18 +4,25 @@
# BOM-less scripts as ANSI); Chinese label names arrive as arguments.
# gitea.ps1 whoami
# gitea.ps1 issues <label1,label2> open issues carrying ALL labels, oldest first (JSON)
# gitea.ps1 issue <N> number, title, body (body only if written by the owner)
# gitea.ps1 issue <N> number, title, body (body only if written by a trusted account)
# gitea.ps1 labels <N> label names, one per line
# gitea.ps1 add-label <N> <name>
# gitea.ps1 remove-label <N> <name>
# gitea.ps1 comments <N> owner's comments only (JSON: created_at, body)
# gitea.ps1 comments <N> trusted accounts' comments only (JSON: author, created_at, body)
# gitea.ps1 comment <N> <file> post a UTF-8 file as a comment
param([Parameter(Mandatory = $true)][string]$Cmd, [string]$A1, [string]$A2)
# gitea.ps1 create-pr <branch> <title> <bodyfile> open a PR from <branch> into the repo's default branch; prints its number
# gitea.ps1 pr-for-branch <branch> open PR number for <branch> (empty if none)
# -Repo selects the repository (default root/Jyotisha), e.g. -Repo root/copse.
param([Parameter(Mandatory = $true)][string]$Cmd, [string]$A1, [string]$A2, [string]$A3, [string]$Repo = 'root/Jyotisha')
$ErrorActionPreference = 'Stop'
[Console]::OutputEncoding = [Text.Encoding]::UTF8
$Utf8 = New-Object Text.UTF8Encoding $false
$Base = 'https://git.copse.top/api/v1'
$Api = "$Base/repos/root/Jyotisha"
if ($Repo -notmatch '^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$') { throw "bad -Repo: $Repo" }
$Api = "$Base/repos/$Repo"
# Accounts whose issue text and comments are trusted: the product owner and the two agents.
$Trusted = @('jesse', 'claude-agent', 'grok-agent')
if ($env:GITEA_TRUSTED_USERS) { $Trusted = $env:GITEA_TRUSTED_USERS -split ',' }
$Token = ([IO.File]::ReadAllText((Join-Path $HOME '.config\jyotisha-agent\gitea-token'))).Trim()
function Call([string]$Method, [string]$Url, $Body = $null) {
@@ -35,12 +42,16 @@ switch ($Cmd) {
'whoami' { Owner }
'issues' { Json @(@(Call GET "$Api/issues?state=open&type=issues&limit=50&labels=$([uri]::EscapeDataString($A1))") |
Sort-Object created_at | ForEach-Object { [ordered]@{ number = $_.number; title = $_.title; labels = @($_.labels | ForEach-Object { $_.name }) } }) }
'issue' { $o = Owner; $i = Call GET "$Api/issues/$A1"
Json ([ordered]@{ number = $i.number; title = $i.title; body = $(if ($i.user.login -eq $o) { $i.body } else { '' }) }) }
'issue' { $i = Call GET "$Api/issues/$A1"
Json ([ordered]@{ number = $i.number; title = $i.title; body = $(if ($Trusted -contains $i.user.login) { $i.body } else { '' }) }) }
'labels' { @(Call GET "$Api/issues/$A1/labels") | ForEach-Object { $_.name } }
'add-label' { Call POST "$Api/issues/$A1/labels" @{ labels = @($A2) } | Out-Null; "added $A2" }
'remove-label' { $id = LabelId $A2; if ($id -and (@(Call GET "$Api/issues/$A1/labels") | Where-Object { $_.id -eq $id })) { Call DELETE "$Api/issues/$A1/labels/$id" | Out-Null }; "removed $A2" }
'comments' { $o = Owner; Json @(@(Call GET "$Api/issues/$A1/comments") | Where-Object { $_.user.login -eq $o } | ForEach-Object { [ordered]@{ created_at = $_.created_at; body = $_.body } }) }
'comments' { Json @(@(Call GET "$Api/issues/$A1/comments") | Where-Object { $Trusted -contains $_.user.login } | ForEach-Object { [ordered]@{ author = $_.user.login; created_at = $_.created_at; body = $_.body } }) }
'comment' { Call POST "$Api/issues/$A1/comments" @{ body = [IO.File]::ReadAllText($A2, [Text.Encoding]::UTF8) } | Out-Null; "commented on #$A1" }
'create-pr' { if ($A1 -notmatch '^codex/') { throw 'PR head must be a codex/* branch' }
$base = (Call GET $Api).default_branch
(Call POST "$Api/pulls" @{ head = $A1; base = $base; title = $A2; body = [IO.File]::ReadAllText($A3, [Text.Encoding]::UTF8) }).number }
'pr-for-branch' { (@(Call GET "$Api/pulls?state=open&limit=50") | Where-Object { $_.head.ref -eq $A1 } | Select-Object -First 1).number }
default { throw "unknown command: $Cmd" }
}
+18 -5
View File
@@ -8,6 +8,10 @@ GITEA_URL="${GITEA_URL:-https://git.copse.top}"
GITEA_REPO="${GITEA_REPO:-root/Jyotisha}"
TOKEN_FILE="${JYOTISHA_AGENT_TOKEN_FILE:-$HOME/.config/jyotisha-agent/gitea-token}"
API="$GITEA_URL/api/v1/repos/$GITEA_REPO"
# Accounts whose issue text and comments are trusted: the product owner and the two agents.
# Everyone else's text is dropped before it reaches a model.
TRUSTED="${GITEA_TRUSTED_USERS:-jesse,claude-agent,grok-agent}"
_trusted_jq='($t | split(",")) as $ok | ($ok | index($u)) != null'
_token() {
[[ -r "$TOKEN_FILE" ]] || { echo "gitea.sh: token file missing: $TOKEN_FILE" >&2; exit 2; }
@@ -51,8 +55,8 @@ case "$cmd" in
issues) # issues LABEL — open issues carrying LABEL, oldest first, as JSON array
_call GET "/issues?state=open&type=issues&limit=50&labels=$(jq -rn --arg l "$1" '$l|@uri')" \
| jq -c 'sort_by(.created_at)' ;;
issue) # issue N
_call GET "/issues/$1" ;;
issue) # issue N — body blanked unless written by a trusted account
_call GET "/issues/$1" | jq --arg t "$TRUSTED" '. as $i | .user.login as $u | if ('"$_trusted_jq"') then $i else ($i | .body = "(非可信账号创建的 issue,正文已忽略)") end' ;;
labels) # labels N — label names on issue N, one per line
_call GET "/issues/$1/labels" | jq -r '.[].name' ;;
add-label) # add-label N NAME
@@ -60,15 +64,24 @@ case "$cmd" in
remove-label) # remove-label N NAME (no-op when absent)
id="$("$0" label-id "$2")"
[[ -n "$id" ]] && _call DELETE "/issues/$1/labels/$id" >/dev/null || true ;;
comments) # comments N — JSON array
_call GET "/issues/$1/comments" ;;
comments) # comments N — JSON array, trusted accounts only
_call GET "/issues/$1/comments" | jq --arg t "$TRUSTED" '[.[] | .user.login as $u | select('"$_trusted_jq"')]' ;;
comment) # comment N FILE — post FILE's content as a comment
_call POST "/issues/$1/comments" "$(jq -Rsc '{body:.}' < "$2")" >/dev/null ;;
create-issue) # create-issue TITLE FILE — prints the new issue number
_call POST "/issues" "$(jq -Rsc --arg t "$1" '{title:$t, body:.}' < "$2")" | jq -r .number ;;
close) # close N
_call PATCH "/issues/$1" '{"state":"closed"}' >/dev/null ;;
pr) # pr N — number, state, head ref/sha, base, mergeable, merged, merge commit
_call GET "/pulls/$1" | jq '{number, state, title, head: .head.ref, head_sha: .head.sha, base: .base.ref, mergeable, merged, merge_commit_sha, author: .user.login}' ;;
pr-for-branch) # pr-for-branch BRANCH — open PR number whose head is BRANCH (empty if none)
_call GET "/pulls?state=open&limit=50" | jq -r --arg b "$1" '[.[] | select(.head.ref == $b)][0].number // empty' ;;
merge-pr) # merge-pr N HEAD_SHA — merge commit; Gitea refuses if the head moved past HEAD_SHA
_call POST "/pulls/$1/merge" "$(jq -nc --arg s "$2" '{Do:"merge", head_commit_id:$s}')" >/dev/null
"$0" pr "$1" | jq -r '"merged=\(.merged) merge_commit=\(.merge_commit_sha)"' ;;
runs) # runs SHA — Actions runs for a commit (workflow path, status, conclusion)
_call GET "/actions/runs?head_sha=$1&limit=20" | jq -c '[.workflow_runs[]? | {id, run_number, path, status, conclusion}]' ;;
*)
echo "usage: gitea.sh whoami|label-id|ensure-label|issues|issue|labels|add-label|remove-label|comments|comment|create-issue|close" >&2
echo "usage: gitea.sh whoami|label-id|ensure-label|issues|issue|labels|add-label|remove-label|comments|comment|create-issue|close|pr|pr-for-branch|merge-pr|runs (repo: GITEA_REPO, default root/Jyotisha)" >&2
exit 64 ;;
esac
+2 -3
View File
@@ -21,7 +21,6 @@ flock -w 3600 9 || { log "tick lock busy for an hour, skipping tonight"; exit 0;
RUN_DIR="$STATE_DIR/runs/nightly-$(date -u +%Y%m%dT%H%M%SZ)"
mkdir -p "$RUN_DIR"
OWNER="$("$GITEA" whoami)"
today="$(TZ=Asia/Shanghai date +%F)"
git -C "$REPO_DIR" fetch -q origin --prune
@@ -34,8 +33,8 @@ since="$(TZ=Asia/Shanghai date -d "$today 00:00" -u +%FT%TZ)"
"$GITEA" issues "agent/试点" > "$RUN_DIR/open.json" || echo '[]' > "$RUN_DIR/open.json"
jq -n '[]' > "$RUN_DIR/comments.json"
for n in $(jq -r '.[].number' "$RUN_DIR/open.json"); do
"$GITEA" comments "$n" | jq --arg o "$OWNER" --arg s "$since" --argjson n "$n" \
'[.[] | select(.user.login == $o and .created_at >= $s and (.body | startswith("<!-- agent:"))) | {issue: $n, created_at, body}]' \
"$GITEA" comments "$n" | jq --arg s "$since" --argjson n "$n" \
'[.[] | select(.created_at >= $s and (.body | startswith("<!-- agent:"))) | {issue: $n, created_at, body}]' \
> "$RUN_DIR/c.json"
jq -s 'add' "$RUN_DIR/comments.json" "$RUN_DIR/c.json" > "$RUN_DIR/m.json" && mv "$RUN_DIR/m.json" "$RUN_DIR/comments.json"
done
+45
View File
@@ -0,0 +1,45 @@
# copse 接入 agent 循环的规则
产品负责人 2026-10-13 决定:Java 测试以 Grok 的结果为准;循环里允许数据库迁移但必须过严格检查;Claude 验收通过后自动合并 PR。通用流程与护栏见 `docs/agents/agent-loop-playbook.md`(Jyotisha 仓库)。本文件只写 copse 不同的地方,两侧 `/loop` 每轮都先读它。
## 仓库事实
- Gitea `root/copse`,**私有**;默认分支 `main`。工具调用一律带仓库参数:Linux `GITEA_REPO=root/copse ~/.local/share/jyotisha-agent/bin/gitea.sh ...`;Windows `gitea.ps1 ... -Repo root/copse`。
- 合进 `main` 会触发 `copse-test.yml`,自动发布到 test 环境(k3s)。**生产发布(`yudao-k3s-prod`)永远由产品负责人手动触发**,循环不碰。
- 项目规则:仓库根 `AGENTS.md`(Flyway 迁移约定、新模型完整生命周期准则、禁止的架构回退)、`tests/AGENTS.md`(契约测试约定)。每单开工前读与本单相关的章节。
- 技术栈:JDK 21 + Maven 多模块(`yudao-*`)、前端 `yudao-ui/draw2video-admin`、`yudao-ui/draw2video-client`(pnpm)、根目录 `tests/` 的 Python 契约测试、`script/db/check_migrations.py`。
## 一单怎么走(与 Jyotisha 的差别)
1. **Claude 规划**:从 `origin/main` 建分支 `codex/<主题>-<YYYYMMDD>`,第一个提交是任务书 `docs/tasks/TASK-<主题>-<YYYYMMDD>.md`,推这个分支(不开 PR、不推 main)。评论首行:`<!-- agent:claude plan brief=<任务书> branch=<分支> base=<origin/main sha> -->`。
2. **Grok 执行**:在该分支上实现、自测、推送;分支还没有 PR 就开一个(`gitea.ps1 create-pr <分支> <标题> <正文文件> -Repo root/copse`,标题用 copse 现有的 `fix(模块): 中文说明` 风格)。评论首行:`<!-- agent:grok report branch=<分支> sha=<远端 head> pr=<PR 号> -->`。
3. **Claude 验收**:只验回报的 SHA,并核对 PR 的 head 就是它、`mergeable` 为真。通过就合并(下文「合并」),评论首行 `<!-- agent:claude review sha=<head> verdict=pass pr=<号> merge=<合并提交 40 位> -->`,标签换 `agent/部署中`。不通过:把修复单 `docs/tasks/TASK-<主题>-fix-<YYYYMMDD>.md` 作为新提交推到**同一分支**,评论 `<!-- agent:claude review sha=<head> verdict=fail brief=<修复单> branch=<分支> -->`,标签换回 `agent/待执行`。
4. **部署核对**:`gitea.sh runs <合并提交>` 里 `copse-test.yml` 为 `success` → `agent/待真机` 并 @jesse;`failure` → `agent/需拍板`,评论写 run 号;超过 3 小时仍未完成 → `agent/需拍板`。
## 测试分工
| 检查 | Grok(Windows)必跑并在回报里贴命令与数字 | Claude(Linux,无 JDK)验收 |
| --- | --- | --- |
| Java 编译与模块测试 `mvn --no-transfer-progress -pl <改到的模块> -am test` | **必跑,以 Grok 为准** | 跑不了:核对 Grok 贴的命令覆盖了所有改到的模块、测试数与失败数;没贴或覆盖不全即 `fail` |
| 相关 Python 契约测试 `python -m pytest tests/<相关文件> -q` | 必跑 | 复验;另外 grep 改到的文件路径,找出按源码断言的契约测试一起跑 |
| 迁移检查(改了任何迁移 SQL 时)`python script/db/check_migrations.py --release-base origin/main` | 必跑 | **必须复验通过** |
| 前端(改了 `yudao-ui/**` 时)该应用目录下 `pnpm lint` 与 `pnpm build` | 必跑 | 依赖装得上就复验,装不上记环境缺口 |
## 数据库迁移(允许,但严格)
- 只能**新增**迁移文件,命名 `VYYYYMMDDNNNN__description.sql`,同库版本号唯一,按根 `AGENTS.md`「Flyway Feature 迁移约定」与「标准流程」做完(含 verify SQL)。
- 任何已存在的迁移文件被修改、删除、改名:直接 `fail`(Claude 用 `git diff --name-status origin/main...<sha>` 核对,迁移目录下只允许 `A`)。
- `check_migrations.py` 不过:`fail`。
- 合并前再基于最新 `origin/main` 确认没有同库版本号冲突;有冲突要求 Grok 重新编号(尚未进 test 的才能改号)。
## 合并
```
GITEA_REPO=root/copse ~/.local/share/jyotisha-agent/bin/gitea.sh merge-pr <PR 号> <验收过的 40 位 SHA>
```
`head_commit_id` 锁住验收过的提交:验收期间分支又被推了新提交,Gitea 会拒绝合并,此时不重试,留言后下一轮重验。合并后读 `merge_commit` 填进评论标记。
## 不进循环(遇到就 `agent/需拍板`)
生产发布与 `yudao-k3s-prod`、`.gitea/workflows/**`、k3s 生产清单、密钥与渠道凭据、计费单价与销售报价(会直接影响收入)、删除或退役模块。
@@ -0,0 +1,51 @@
{
"_comment": "copse variant of tools/agent-loop/grok-permissions.json (same rules, plus Maven, pnpm, Python contract tests and the migration checker). Gitea calls only through gitea.ps1 with -Repo root/copse.",
"mode": "dontAsk",
"allow": [
"Read",
"Edit",
"Write",
"Glob",
"Grep",
"Bash(git status:*)",
"Bash(git log:*)",
"Bash(git show:*)",
"Bash(git diff:*)",
"Bash(git add:*)",
"Bash(git commit:*)",
"Bash(git rev-parse:*)",
"Bash(git ls-remote:*)",
"Bash(git ls-files:*)",
"Bash(git grep:*)",
"Bash(git fetch:*)",
"Bash(git checkout:*)",
"Bash(git push origin HEAD:refs/heads/codex/*)",
"Bash(powershell -NoProfile -ExecutionPolicy Bypass -File C:\\Users\\74082\\.jyotisha-agent\\bin\\gitea.ps1:*)",
"Bash(docker info:*)",
"Bash(mvn --no-transfer-progress:*)",
"Bash(mvn -q:*)",
"Bash(pnpm install:*)",
"Bash(pnpm lint:*)",
"Bash(pnpm build:*)",
"Bash(pnpm run:*)",
"Bash(python -m pytest:*)",
"Bash(python script/db/check_migrations.py:*)"
],
"deny": [
"Bash(git push --force:*)",
"Bash(git push -f:*)",
"Bash(git push --no-verify:*)",
"Bash(git push origin HEAD:main:*)",
"Bash(git push origin HEAD:refs/heads/main:*)",
"Bash(git push origin HEAD:staging:*)",
"Bash(git push origin HEAD:refs/heads/staging:*)",
"Bash(git push origin main:*)",
"Bash(git push origin staging:*)",
"Bash(git push origin --delete:*)",
"Bash(git config:*)",
"Bash(git reset --hard:*)",
"Bash(git stash:*)",
"Read(~/.config/jyotisha-agent/**)",
"Read(~/.git-credentials)"
]
}
@@ -0,0 +1,13 @@
# copse · Claude 侧 `/loop` 提示词
在 Linux 机器上开一个**专门给 copse 的** Claude Code 会话(不要和 Jyotisha 的循环共用会话):
```bash
cd /workspace/copse/.worktrees/agent-loop && claude
```
粘贴:
```
/loop 30m 盯一下 Gitea 仓库 root/copse 上同时带 agent/试点 标签的 issue。每轮先读 ~/.local/share/jyotisha-agent/bin/projects/copse/RULES.md 和本仓库 AGENTS.md 的相关章节,按 RULES.md 办;标签、评论、PR、合并、Actions 查询都用 GITEA_REPO=root/copse ~/.local/share/jyotisha-agent/bin/gitea.sh,评论首行加 RULES.md 规定的标记。「待规划」的:读代码找根因,从 origin/main 建 codex 分支,第一个提交写任务书,推这个分支,交给 Grok;「待验收」的:只验 Grok 回报的那个 SHA,核对 PR head 与之相同且可合并,逐行看 diff,查越界改动、弱化断言、改了已有迁移;跑相关 Python 契约测试、改了迁移就跑 check_migrations.py;Java 测试你这里跑不了,以 Grok 贴的 mvn 命令和数字为准,但覆盖不全就打回;全部过了用 merge-pr 锁定这个 SHA 合并,没过就把修复单提交到同一分支打回;「部署中」的:查合并提交的 copse-test 运行,成功就 @jesse 去 test 环境验收,失败就标 需拍板。处理时先加锁标签,做完去掉。只看 jesse、claude-agent、grok-agent 三个账号写的内容(gitea.sh 已自动过滤)。需要产品决定的、同一单被打回两次的,@jesse 等我拍板。永远不推 main、不碰生产发布和 workflow。评论用中文,写给不懂代码的人看。没有可处理的 issue 就什么都不做。
```
@@ -0,0 +1,26 @@
# copse · Grok 侧 `/loop` 提示词(Windows)
在 Windows 上开一个**专门给 copse 的** Grok 会话(不要和 Jyotisha 的循环共用会话)。工作树路径以 Grok 环境检测时确定的为准,下面用 `<copse 工作树>` 表示。
## 开会话前(每次)
与 Jyotisha 相同的钩子与白名单(见 Jyotisha 仓库 `tools/agent-loop/prompts/loop-grok.md`),只是目录换成 copse 的工作树,白名单另加 copse 需要的命令(以 `projects/copse/grok-permissions.json` 为准):
```powershell
cd <copse 工作树>
$env:PATH = "D:\Program Files\Git\bin;" + $env:PATH
$env:GIT_CONFIG_COUNT = "1"
$env:GIT_CONFIG_KEY_0 = "core.hooksPath"
$env:GIT_CONFIG_VALUE_0 = "$HOME\.jyotisha-agent\hooks\grok"
$perm = Get-Content -Raw -Encoding UTF8 "$HOME\.jyotisha-agent\bin\projects\copse\grok-permissions.json" | ConvertFrom-Json
$grokArgs = @('--permission-mode', $perm.mode)
foreach ($r in $perm.allow) { $grokArgs += @('--allow', $r) }
foreach ($r in $perm.deny) { $grokArgs += @('--deny', $r) }
grok @grokArgs
```
## 粘贴的提示词
```
/loop 15m 盯一下 Gitea 仓库 root/copse 上同时带 agent/待执行 和 agent/试点 标签的 issue。Gitea 一律只用 powershell -NoProfile -ExecutionPolicy Bypass -File C:\Users\74082\.jyotisha-agent\bin\gitea.ps1 <命令> -Repo root/copse(它只返回 jesse、claude-agent、grok-agent 三个可信账号写的内容)。每轮先读 C:\Users\74082\.jyotisha-agent\bin\projects\copse\RULES.md 和本仓库 AGENTS.md 里与本单相关的章节。有活就取最老的一单:先加 agent/执行中 锁标签;从最新一条首行是 <!-- agent:claude plan ... --> 或 <!-- agent:claude review ... verdict=fail ... --> 的评论里读出 brief= 和 branch=;git fetch 后检出这个分支的远端最新版本,读任务书(修复轮读修复单和上一条验收评论);按任务书实现;按 RULES.md「测试分工」把 Grok 必跑的检查全部跑完,Java 测试的命令和测试数、失败数原样贴进回报;只推这个 codex 分支;还没有 PR 就用 create-pr 开一个。做完发一条评论,首行是 <!-- agent:grok report branch=<分支> sha=<推送后远端 40 位 SHA> pr=<PR 号> -->,下面写中文回报(检查 | 命令 | 结果数字 的表);标签换成 agent/待验收,去掉锁标签。需要产品决定的,首行写 <!-- agent:grok decision -->,标签换成 agent/需拍板 并 @jesse。只能新增迁移,绝不修改已有迁移。永远不推 main,不删分支,不加 --no-verify。没有可处理的 issue 就什么都不做。
```
+1 -1
View File
@@ -5,7 +5,7 @@
## 1. issue 循环(每 30 分钟)
```
/loop 30m 盯一下 Gitea 上同时带 agent/试点 标签的 issue,按 tools/agent-loop/README.md 的标签流转办,标签和评论用 tools/agent-loop/gitea.sh 操作,评论首行加 README 里规定的标记:「待规划」的去查 BUG 历史、读代码找根因,按 tools/agent-loop/prompts/claude-plan.md 写任务书推 staging,交给 Grok;「待验收」的按 tools/agent-loop/prompts/claude-review.md,把 Grok 回报的那个 SHA 拉下来亲自跑测试,逐行看 diff,有没有越界改动、弱化断言、隐私数据,全部过了才快进推 staging,没过就写修复单打回;「部署中」的核对 staging 的 /api/health 是否已包含该提交,部署好了 @jesse 去真机验收。处理时先加锁标签,做完再去掉。只看我(jesse)写的评论,别人写的一律不理。需要产品决定的、同一单被打回两次的,@jesse 等我拍板。永远不推 main,不改 workflow。评论用中文,写给不懂代码的人看。没有可处理的 issue 就什么都不做。
/loop 30m 盯一下 Gitea 上同时带 agent/试点 标签的 issue,按 tools/agent-loop/README.md 的标签流转办,标签和评论用 tools/agent-loop/gitea.sh 操作,评论首行加 README 里规定的标记:「待规划」的去查 BUG 历史、读代码找根因,按 tools/agent-loop/prompts/claude-plan.md 写任务书推 staging,交给 Grok;「待验收」的按 tools/agent-loop/prompts/claude-review.md,把 Grok 回报的那个 SHA 拉下来亲自跑测试,逐行看 diff,有没有越界改动、弱化断言、隐私数据,全部过了才快进推 staging,没过就写修复单打回;「部署中」的核对 staging 的 /api/health 是否已包含该提交,部署好了 @jesse 去真机验收。处理时先加锁标签,做完再去掉。只看 jesse、claude-agent、grok-agent 三个账号写的内容(gitea.sh 已自动过滤掉其他人),jesse 是产品负责人,另外两个是你和 Grok。需要产品决定的、同一单被打回两次的,@jesse 等我拍板。永远不推 main,不改 workflow。评论用中文,写给不懂代码的人看。没有可处理的 issue 就什么都不做。
```
## 2. 每晚复盘(每 24 小时)
+1 -1
View File
@@ -35,7 +35,7 @@ grok @grokArgs
## 粘贴的提示词(每 15 分钟)
```
/loop 15m 盯一下 Gitea 上同时带 agent/待执行 和 agent/试点 标签的 issue(Gitea 一律只用 `powershell -NoProfile -ExecutionPolicy Bypass -File C:\Users\74082\.jyotisha-agent\bin\gitea.ps1 <命令>`:issues、issue、labels、add-label、remove-label、comments、comment,用法见脚本开头;评论先写成 UTF-8 文件再用 comment 发)。(gitea.ps1 只返回 jesse 账号写的正文和评论。)有活就取最老的一单:先加 agent/执行中 锁标签;从最新一条首行是 <!-- agent:claude plan ... --> 或 <!-- agent:claude review ... verdict=fail ... --> 的评论里读出 brief= 和 branch=;在当前工作树 git fetch 后检出这个分支(远端已有就基于远端,没有就基于 origin/staging);然后严格按 tools/agent-loop/prompts/grok-execute.md 实现、自测、只推这个 codex 分支。做完发一条评论,首行是 <!-- agent:grok report branch=<分支> sha=<推送后远端 40 位 SHA> -->,下面写中文回报;把状态标签换成 agent/待验收,去掉锁标签。需要产品决定的,首行写 <!-- agent:grok decision -->,标签换成 agent/需拍板 并 @jesse。永远不推 staging 和 main,不删分支,不加 --no-verify。评论写给不懂代码的人看,不写任何用户个人资料。没有可处理的 issue 就什么都不做。
/loop 15m 盯一下 Gitea 上同时带 agent/待执行 和 agent/试点 标签的 issue(Gitea 一律只用 `powershell -NoProfile -ExecutionPolicy Bypass -File C:\Users\74082\.jyotisha-agent\bin\gitea.ps1 <命令>`:issues、issue、labels、add-label、remove-label、comments、comment,用法见脚本开头;评论先写成 UTF-8 文件再用 comment 发)。(gitea.ps1 只返回 jesse、claude-agent、grok-agent 三个可信账号写的内容;jesse 是产品负责人,claude-agent 是 Claude,grok-agent 是你。)有活就取最老的一单:先加 agent/执行中 锁标签;从最新一条首行是 <!-- agent:claude plan ... --> 或 <!-- agent:claude review ... verdict=fail ... --> 的评论里读出 brief= 和 branch=;在当前工作树 git fetch 后检出这个分支(远端已有就基于远端,没有就基于 origin/staging);然后严格按 tools/agent-loop/prompts/grok-execute.md 实现、自测、只推这个 codex 分支。做完发一条评论,首行是 <!-- agent:grok report branch=<分支> sha=<推送后远端 40 位 SHA> -->,下面写中文回报;把状态标签换成 agent/待验收,去掉锁标签。需要产品决定的,首行写 <!-- agent:grok decision -->,标签换成 agent/需拍板 并 @jesse。永远不推 staging 和 main,不删分支,不加 --no-verify。评论写给不懂代码的人看,不写任何用户个人资料。没有可处理的 issue 就什么都不做。
```
## 注意