Skip to content

Commit 89e5dc5

Browse files
committed
docs: document system cron execution mode and usage guide
- Rewrite loop-engineering.md with all 3 execution modes: 1. System cron + headless (primary, for TKE internal API) 2. GitHub Actions (optional, gated by CODEBUDDY_ENABLED var) 3. Interactive session (ad-hoc) - Add install/trigger/log/uninstall instructions - Update daily schedule table (01:00-05:00 Beijing time) - Update CODEBUDDY.md maintenance section with cron usage - Update 'how to add a new loop' checklist for cron-based flow
1 parent 666aa6a commit 89e5dc5

2 files changed

Lines changed: 136 additions & 56 deletions

File tree

.codebuddy/CODEBUDDY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ go list -u -m all
6767

6868
本项目采用 Loop Engineering 理念进行自动化维护。循环配置位于 `.codebuddy/`,总体设计见 [loop-engineering.md](./loop-engineering.md)
6969

70+
**运行方式**:通过系统 cron + `codebuddy -p`(headless)每天凌晨自动运行,无需保持会话。安装:`.codebuddy/scripts/install-cron.sh`,手动触发:`.codebuddy/scripts/run-loop.sh <类型>`,日志:`/tmp/loop-logs/`
71+
7072
- 所有循环状态持久化到 `STATE.md`(项目根目录),不依赖模型上下文记忆
7173
- 每个循环遵循五阶段:Discover → Plan → Execute → Verify → Iterate
7274
- 实现与验证分离:不同 agent 负责修复和审查

.codebuddy/loop-engineering.md

Lines changed: 134 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,75 +9,152 @@ This project uses Loop Engineering for automated maintenance. Core idea: shift f
99
| Prompt | How to ask | Each agent's system prompt |
1010
| Context | What AI sees | `CODEBUDDY.md`, `STATE.md` |
1111
| Harness | AI work environment | skills (project knowledge), allowed-tools (permission constraints) |
12-
| Loop | What to do after each step | GitHub Actions triggers, agent five-phase iteration |
12+
| Loop | What to do after each step | System cron + `codebuddy -p` (headless), or GitHub Actions |
13+
14+
## Execution Mode
15+
16+
This project supports two execution modes. **System cron is the primary mode** for environments where the CodeBuddy API is only reachable from an internal network (e.g. TKE private deployment).
17+
18+
### Mode 1: System Cron + Headless (Primary)
19+
20+
Each loop runs as a system cron job that invokes `codebuddy -p` (headless mode). Every run is a fresh, isolated session that reads `STATE.md` for context, executes the loop, and writes back `STATE.md`.
21+
22+
**Advantages:**
23+
- No expiration — runs permanently, no need to re-create
24+
- No need to keep a session open
25+
- Each run is isolated (fresh context, no drift)
26+
- Works with TKE internal API (runs locally)
27+
28+
**Install:**
29+
```bash
30+
cd /data/git/req
31+
.codebuddy/scripts/install-cron.sh
32+
```
33+
34+
**Uninstall:**
35+
```bash
36+
.codebuddy/scripts/install-cron.sh --remove
37+
```
38+
39+
**Manual trigger:**
40+
```bash
41+
.codebuddy/scripts/run-loop.sh <loop-type>
42+
# loop-type: ci-fix | issue-triage | pr-review | dependency-upgrade | upstream-sync
43+
```
44+
45+
**View logs:**
46+
```bash
47+
ls /tmp/loop-logs/
48+
cat /tmp/loop-logs/ci-fix-*.log
49+
```
50+
51+
**Schedule (daily, Beijing time, staggered to avoid API rate limits):**
52+
53+
| Time | Loop | Script |
54+
|------|------|--------|
55+
| 01:00 | upstream-sync | `run-loop.sh upstream-sync` |
56+
| 02:00 | dependency-upgrade | `run-loop.sh dependency-upgrade` |
57+
| 03:00 | ci-fix | `run-loop.sh ci-fix` |
58+
| 04:00 | issue-triage | `run-loop.sh issue-triage` |
59+
| 05:00 | pr-review | `run-loop.sh pr-review` |
60+
61+
**Run flow:**
62+
```
63+
system cron (daily, e.g. 03:00)
64+
→ run-loop.sh ci-fix
65+
→ git pull --ff-only origin master # sync latest
66+
→ codebuddy -p -y "..." # headless session
67+
→ read STATE.md # get last state
68+
→ execute loop logic (via agent) # discover → plan → execute → verify
69+
→ write STATE.md # persist state
70+
→ git push # push state changes
71+
→ 10 min timeout protection
72+
→ log to /tmp/loop-logs/
73+
```
74+
75+
### Mode 2: GitHub Actions (Optional, for public API)
76+
77+
For environments with a public CodeBuddy API endpoint. Gated behind `CODEBUDDY_ENABLED` repo variable (default: off).
78+
79+
**Enable:**
80+
```bash
81+
# Set repo variable
82+
gh variable set CODEBUDDY_ENABLED -R imroc/req -b "true"
83+
# Set API key secret
84+
gh secret set CODEBUDDY_API_KEY -R imroc/req
85+
```
86+
87+
**Disable:**
88+
```bash
89+
gh variable set CODEBUDDY_ENABLED -R imroc/req -b "false"
90+
```
91+
92+
Workflows are in `.github/workflows/*-loop.yml`.
93+
94+
### Mode 3: Interactive Session (For Ad-hoc Use)
95+
96+
You can also trigger loops directly in an interactive CodeBuddy session:
97+
98+
```
99+
> Use the ci-fixer agent to check for failed CI runs
100+
> Use the issue-triager agent to triage recent issues
101+
> Use the pr-reviewer agent to review PR #485
102+
> Use the dependency-upgrader agent to upgrade dependencies
103+
> Use the upstream-tracker agent to check upstream changes
104+
```
105+
106+
Slash commands (session-level, expire in 3 days):
107+
- `/start-loops` — create all 5 loops as session cron jobs
108+
- `/stop-loops` — delete all session cron jobs
109+
- `/loop-status` — show loop status and last run results
13110

14111
## Implemented Loops
15112

16-
### 1. Dependency Upgrade Loop (closed-loop)
17-
- **Trigger**: Weekly Monday 03:00 UTC, or manual
113+
### 1. Upstream Sync Tracking (daily 01:00)
114+
- **Goal**: Track Go stdlib net/http, golang.org/x/net/http2, and quic-go upstream changes
115+
- **Five phases**: Discover (check baselines) → Fetch upstream changes → Identify affected files → Generate report → Open issue if needed
116+
- **Stop conditions**: Report generated for all 3 sources / Critical change found
117+
- **Files**: `skills/upstream-sync/SKILL.md`, `agents/upstream-tracker.md`
118+
- **Note**: Only tracks and reports. Sync of modified code is manual human work.
119+
120+
### 2. Dependency Upgrade (daily 02:00)
18121
- **Goal**: Safely upgrade all upgradable Go dependencies (non-modified-code only)
19122
- **Five phases**: Discover (`go list -u`) → Risk-classify → Upgrade → Test → Rollback-retry
20123
- **Stop conditions**: All deps processed / 3 consecutive test failures / 5 iterations max
21-
- **Files**:
22-
- skill: `skills/dependency-upgrade/SKILL.md`
23-
- agent: `agents/dependency-upgrader.md`
24-
- workflow: `.github/workflows/dependency-upgrade-loop.yml`
124+
- **Files**: `skills/dependency-upgrade/SKILL.md`, `agents/dependency-upgrader.md`
25125
- **Separation**: dependency-upgrader executes → code-reviewer reviews → PR only after approval
26126

27-
### 2. CI Fix Loop (closed-loop)
28-
- **Trigger**: On CI workflow failure, or manual
127+
### 3. CI Fix (daily 03:00)
29128
- **Goal**: Auto-fix fixable CI failures
30129
- **Five phases**: Discover (`gh run list`) → Classify (ci-triage) → Fix (ci-fix) → Local verify → Retry
31130
- **Stop conditions**: All fixable failures resolved / 3 fix attempts / No failed CI runs
32-
- **Files**:
33-
- skills: `skills/ci-triage/SKILL.md`, `skills/ci-fix/SKILL.md`
34-
- agents: `agents/ci-fixer.md`, `agents/code-reviewer.md`
35-
- workflow: `.github/workflows/ci-fix-loop.yml`
131+
- **Files**: `skills/ci-triage/SKILL.md`, `skills/ci-fix/SKILL.md`, `agents/ci-fixer.md`, `agents/code-reviewer.md`
36132
- **Separation**: ci-fixer fixes → code-reviewer reviews → PR only after approval
37133

38-
### 3. Issue Triage Loop (closed-loop)
39-
- **Trigger**: On new issue, or daily 04:00 UTC batch
134+
### 4. Issue Triage (daily 04:00)
40135
- **Goal**: Classify, label, and respond to issues; flag quic-go/modified-code issues for caution
41136
- **Five phases**: Discover (untriaged issues) → Classify → Apply labels → Post response → Verify
42137
- **Stop conditions**: All recent issues triaged / 10 issues processed / Needs human judgment
43-
- **Files**:
44-
- skill: `skills/issue-triage/SKILL.md`
45-
- agent: `agents/issue-triager.md`
46-
- workflow: `.github/workflows/issue-triage-loop.yml`
138+
- **Files**: `skills/issue-triage/SKILL.md`, `agents/issue-triager.md`
47139
- **Special**: quic-go issues get `quic-go` label and modified-code caveat note
48140

49-
### 4. PR Review Loop (closed-loop)
50-
- **Trigger**: On new PR or PR update
141+
### 5. PR Review (daily 05:00)
51142
- **Goal**: Review PRs with special caution for modified stdlib, quic-go, and HTTP/2 code
52143
- **Five phases**: Discover (open PRs) → Fetch diff → Review checklist → Post review → Verify
53144
- **Stop conditions**: All open PRs reviewed / 5 PRs reviewed / Needs human judgment
54-
- **Files**:
55-
- skill: `skills/pr-review/SKILL.md`
56-
- agent: `agents/pr-reviewer.md`
57-
- workflow: `.github/workflows/pr-review-loop.yml`
145+
- **Files**: `skills/pr-review/SKILL.md`, `agents/pr-reviewer.md`
58146
- **Special**: PRs touching `internal/http3/` never auto-approved; quic-go version compatibility required
59147

60-
### 5. Upstream Sync Tracking Loop (semi-closed-loop)
61-
- **Trigger**: Weekly Monday 02:00 UTC
62-
- **Goal**: Track Go stdlib net/http, golang.org/x/net/http2, and quic-go upstream changes; generate sync reports
63-
- **Five phases**: Discover (check baselines) → Fetch upstream changes → Identify affected files → Generate report → Open issue if needed
64-
- **Stop conditions**: Report generated for all 3 sources / Critical change found
65-
- **Files**:
66-
- skill: `skills/upstream-sync/SKILL.md`
67-
- agent: `agents/upstream-tracker.md`
68-
- workflow: `.github/workflows/upstream-sync-loop.yml`
69-
- **Note**: This loop only tracks and reports. Sync of modified code is manual human work — cannot `go get -u` modified code.
70-
71148
## State Management
72149

73-
`STATE.md` (project root) is the shared state file for all loops. This is the core Loop Engineering principle — **state is external, not in model context**.
150+
`STATE.md` (project root) is the shared state file for all loops. This is the core Loop Engineering principle — **state is external, not in model context**. Each cron run reads `STATE.md` at the start and writes back at the end.
74151

75152
## Cost Control
76153

77-
- Each loop has max iteration limits (dep upgrade 5, CI fix 3, issue triage 10, PR review 5)
78-
- Uses `model: inherit` to reuse main session model
79-
- Loops run only when needed (event-triggered or scheduled), not always-on
80-
- GitHub Actions provides execution environment, no extra service cost
154+
- Each loop runs once daily (not always-on), 10 min max per run
155+
- Staggered schedule (01:00–05:00) to avoid API rate limits
156+
- Headless mode (`-p`) uses minimal tokens per run
157+
- 30-day log retention (older logs auto-deleted)
81158

82159
## Autonomy Boundary
83160

@@ -88,16 +165,17 @@ This project uses Loop Engineering for automated maintenance. Core idea: shift f
88165

89166
## How to Add a New Loop
90167

91-
1. Create a skill directory and `SKILL.md` under `skills/` (encode project knowledge)
92-
2. Create an agent under `agents/` (define responsibilities, stop conditions, tool permissions)
93-
3. Create a trigger workflow under `.github/workflows/` (scheduled or event-triggered)
94-
4. Add a section to `STATE.md`
95-
5. Reuse `code-reviewer` agent for implementation/review separation
96-
6. Agents involving GitHub operations must declare `gh-cli` in `skills` field
97-
7. Agent safety constraints must include no-tag/no-release rule
98-
8. All skills must be project-level (under `.codebuddy/skills/`), never global
99-
9. Set explicit max iteration limits (turn limits) to prevent infinite loops
100-
10. All commit messages in English
168+
1. Create a skill directory and `SKILL.md` under `.codebuddy/skills/` (encode project knowledge)
169+
2. Create an agent under `.codebuddy/agents/` (define responsibilities, stop conditions, tool permissions)
170+
3. Add a case to `.codebuddy/scripts/run-loop.sh` with the loop's prompt and tools
171+
4. Add a cron entry in `.codebuddy/scripts/install-cron.sh`
172+
5. Add a section to `STATE.md`
173+
6. Reuse `code-reviewer` agent for implementation/review separation
174+
7. Agents involving GitHub operations must declare `gh-cli` in `skills` field
175+
8. Agent safety constraints must include no-tag/no-release rule
176+
9. All skills must be project-level (under `.codebuddy/skills/`), never global
177+
10. Set explicit max iteration limits (turn limits) to prevent infinite loops
178+
11. All commit messages in English
101179

102180
## Inner Loop vs Outer Loop
103181

@@ -119,8 +197,8 @@ Loop Engineering can accelerate "understanding debt" — the gap between the cod
119197

120198
## Future Expandable Loops
121199

122-
| Loop | Trigger | Value |
123-
|------|---------|-------|
124-
| Test coverage improvement | Scheduled | Find low-coverage files, add tests |
125-
| CHANGELOG generation | Tag/scheduled | Summarize changes, generate release notes |
126-
| Security scan | Scheduled | Check known vulnerable dependencies |
200+
| Loop | Value |
201+
|------|-------|
202+
| Test coverage improvement | Find low-coverage files, add tests |
203+
| CHANGELOG generation | Summarize changes, generate release notes |
204+
| Security scan | Check known vulnerable dependencies |

0 commit comments

Comments
 (0)