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
@@ -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 就什么都不做。
|
||||
```
|
||||
Reference in New Issue
Block a user