|
| 1 | +# Issue-Driven Ralph Loop Design |
| 2 | + |
| 3 | +## Problem Statement |
| 4 | + |
| 5 | +When users need to work through open issues (bugs, feature requests, etc.), the current workflow is: |
| 6 | +1. Manually read each issue |
| 7 | +2. Ask the agent to fix it |
| 8 | +3. Hope the agent does it right in one shot |
| 9 | +4. Manually update the issue with results |
| 10 | + |
| 11 | +This is fragile, opaque, and doesn't leverage the issue thread as a collaboration surface. The agent works silently, doesn't report progress, doesn't scan for human feedback, and doesn't track work back to the issue. |
| 12 | + |
| 13 | +## Concept: Issue Thread as Shared Memory |
| 14 | + |
| 15 | +The core insight from production usage is that **the issue thread should be the collaboration interface** between human and agent. Each ralph cycle: |
| 16 | + |
| 17 | +1. **Posts a structured status comment** to the issue thread (progress, blockers, task checklist) |
| 18 | +2. **Scans all thread comments** for new human input (feedback, corrections, approvals) |
| 19 | +3. **Responds substantively** to any human feedback found |
| 20 | +4. **Checkpoints state** so work survives crashes |
| 21 | + |
| 22 | +This transforms the issue tracker from a passive record into an active 2-way collaboration surface. The human can monitor and steer agent work asynchronously by commenting on the issue — no need to be in the same terminal session. |
| 23 | + |
| 24 | +## Prompt Fragment (Proven Effective) |
| 25 | + |
| 26 | +The following suffix has been used successfully in production: |
| 27 | + |
| 28 | +``` |
| 29 | +[RALPH LOOP ENFORCED per AIWG guide: Invoke /ralph or /ralph-external mode |
| 30 | +immediately with --completion "issue resolved: tests pass / PR ready / docs |
| 31 | +updated / all thread feedback addressed". Run full loop relentlessly until |
| 32 | +completion criteria met. EVERY cycle: 1. Post markdown status comment (prefix |
| 33 | +**RALPH CYCLE #N – [Progress/Blocked/Review Needed]**) summarizing actions, |
| 34 | +results, blockers, updated task list (markdown checklist/table, versioned). |
| 35 | +2. Scan ALL thread comments, replies, reactions for new input. 3. Respond |
| 36 | +substantively & immediately to any relevant feedback/questions/suggestions |
| 37 | +(acknowledge, incorporate, clarify, escalate if blocked). No silence—treat |
| 38 | +thread as shared memory. Checkpoint state if supported. Max 6-8 cycles per |
| 39 | +response; resume on next invocation. Prioritize fast 2-way human-AI collab |
| 40 | +over silent work. Begin Ralph Loop now.] |
| 41 | +``` |
| 42 | + |
| 43 | +## Proposed Feature: `/address-issues` Command |
| 44 | + |
| 45 | +### Usage |
| 46 | + |
| 47 | +```bash |
| 48 | +# Address specific issues |
| 49 | +/address-issues 17 18 19 |
| 50 | + |
| 51 | +# Address by filter |
| 52 | +/address-issues --filter "status:open label:bug assignee:me" |
| 53 | + |
| 54 | +# Address all open issues |
| 55 | +/address-issues --all-open |
| 56 | + |
| 57 | +# With options |
| 58 | +/address-issues 17 --max-cycles 8 --provider gitea --interactive |
| 59 | +``` |
| 60 | + |
| 61 | +### Behavior |
| 62 | + |
| 63 | +1. **Fetch issues** — Query the configured issue tracker (Gitea/GitHub/etc.) |
| 64 | +2. **For each issue**, spawn an issue-driven ralph loop: |
| 65 | + a. Read the issue body, comments, and labels |
| 66 | + b. Determine the work needed (bug fix, feature, docs, etc.) |
| 67 | + c. Begin ralph cycle loop: |
| 68 | + - **Cycle N**: Do work, post status comment to issue, scan for feedback |
| 69 | + - **If human commented**: Incorporate feedback, acknowledge in next comment |
| 70 | + - **If blocked**: Post blocker comment, move to next issue or wait |
| 71 | + - **If resolved**: Post completion summary, optionally close issue |
| 72 | +3. **Aggregate results** — Summary of all issues addressed |
| 73 | + |
| 74 | +### Cycle Status Comment Format |
| 75 | + |
| 76 | +Posted to the issue thread each cycle: |
| 77 | + |
| 78 | +```markdown |
| 79 | +**RALPH CYCLE #3 – Progress** |
| 80 | + |
| 81 | +### Actions This Cycle |
| 82 | +- Fixed null check in `validateToken()` (src/auth/token.ts:42) |
| 83 | +- Added regression test covering the reported edge case |
| 84 | +- Ran full test suite — 247 passed, 0 failed |
| 85 | + |
| 86 | +### Task Checklist |
| 87 | +- [x] Reproduce the bug |
| 88 | +- [x] Identify root cause |
| 89 | +- [x] Implement fix |
| 90 | +- [x] Add regression test |
| 91 | +- [ ] Update documentation |
| 92 | +- [ ] Final review |
| 93 | + |
| 94 | +### Blockers |
| 95 | +None |
| 96 | + |
| 97 | +### Next Steps |
| 98 | +Update API documentation to reflect the new validation behavior. |
| 99 | + |
| 100 | +--- |
| 101 | +*Automated by AIWG Ralph Loop — reply to this issue to provide feedback* |
| 102 | +``` |
| 103 | + |
| 104 | +### Thread Scanning Protocol |
| 105 | + |
| 106 | +Each cycle, the agent: |
| 107 | + |
| 108 | +1. **Fetches all comments** on the issue since the last cycle |
| 109 | +2. **Classifies each comment**: |
| 110 | + - Human feedback → incorporate into next cycle |
| 111 | + - Human question → answer in next status comment |
| 112 | + - Human approval → proceed / close |
| 113 | + - Human correction → adjust approach |
| 114 | + - Bot/automated → ignore |
| 115 | +3. **Acknowledges** all human input in the next status comment |
| 116 | + |
| 117 | +### Completion Criteria |
| 118 | + |
| 119 | +An issue is considered resolved when ALL of: |
| 120 | +- The fix/feature is implemented |
| 121 | +- Tests pass |
| 122 | +- Documentation updated (if needed) |
| 123 | +- All thread feedback addressed |
| 124 | +- No unresolved blocker comments |
| 125 | + |
| 126 | +### Multi-Issue Coordination |
| 127 | + |
| 128 | +When addressing multiple issues: |
| 129 | + |
| 130 | +| Strategy | When to Use | |
| 131 | +|----------|-------------| |
| 132 | +| Sequential | Default — address one at a time, safest | |
| 133 | +| Batched | Group related issues (same module/area) | |
| 134 | +| Parallel | Independent issues, respects context budget | |
| 135 | + |
| 136 | +Parallel execution respects `AIWG_CONTEXT_WINDOW` limits per the context-budget rule. |
| 137 | + |
| 138 | +## Integration Points |
| 139 | + |
| 140 | +### Existing Infrastructure Used |
| 141 | + |
| 142 | +| Component | How Used | |
| 143 | +|-----------|----------| |
| 144 | +| `ralph` / `ralph-external` | Core loop engine | |
| 145 | +| `issue-list` | Fetch issues by filter | |
| 146 | +| `issue-comment` | Post cycle status comments | |
| 147 | +| `issue-update` | Update issue status/labels | |
| 148 | +| `issue-close` | Close resolved issues | |
| 149 | +| `issue-sync` | Link commits to issues | |
| 150 | +| Gitea MCP tools | API access for issue operations | |
| 151 | + |
| 152 | +### New Components Needed |
| 153 | + |
| 154 | +| Component | Purpose | |
| 155 | +|-----------|---------| |
| 156 | +| `/address-issues` command | Entry point — parse args, fetch issues, orchestrate | |
| 157 | +| Issue-driven ralph skill | The cycle logic — work + post + scan + respond | |
| 158 | +| Thread scanner | Parse issue comments, classify, extract feedback | |
| 159 | +| Cycle comment template | Structured markdown for status comments | |
| 160 | + |
| 161 | +## Design Decisions |
| 162 | + |
| 163 | +### Why a command, not just a prompt fragment? |
| 164 | + |
| 165 | +The prompt fragment works but requires the user to paste ~200 tokens every time. A command: |
| 166 | +- Is invocable with `/address-issues 17` |
| 167 | +- Encodes the cycle protocol so agents follow it consistently |
| 168 | +- Configurable (max cycles, provider, interactive mode) |
| 169 | +- Discoverable via `/help` |
| 170 | + |
| 171 | +### Why post to the issue thread? |
| 172 | + |
| 173 | +- **Asynchronous collaboration** — human doesn't need to be in the terminal |
| 174 | +- **Audit trail** — all work is logged on the issue |
| 175 | +- **Remote steering** — human can redirect by commenting |
| 176 | +- **Visibility** — team can see what the agent is doing |
| 177 | +- **Persistence** — survives session crashes |
| 178 | + |
| 179 | +### Why scan for feedback? |
| 180 | + |
| 181 | +Without scanning, the agent works in a vacuum. The user's #1 complaint is "I told it something in the issue thread and it ignored me." Scanning makes the issue thread a true shared memory space. |
| 182 | + |
| 183 | +## Relationship to Existing Commands |
| 184 | + |
| 185 | +``` |
| 186 | +/address-issues 17 18 19 |
| 187 | + │ |
| 188 | + ├── For issue #17: |
| 189 | + │ ├── /issue-list (fetch details) |
| 190 | + │ ├── /ralph (execute work loop) |
| 191 | + │ │ ├── Cycle 1: analyze + implement |
| 192 | + │ │ │ └── /issue-comment #17 (post status) |
| 193 | + │ │ ├── Cycle 2: test + refine |
| 194 | + │ │ │ ├── scan thread for feedback |
| 195 | + │ │ │ └── /issue-comment #17 (post status) |
| 196 | + │ │ └── Cycle 3: docs + verify |
| 197 | + │ │ └── /issue-comment #17 (post completion) |
| 198 | + │ ├── /issue-sync (link commits) |
| 199 | + │ └── /issue-close #17 (if resolved) |
| 200 | + │ |
| 201 | + ├── For issue #18: (same pattern) |
| 202 | + └── For issue #19: (same pattern) |
| 203 | +``` |
| 204 | + |
| 205 | +## Open Questions |
| 206 | + |
| 207 | +1. **Max cycles per issue** — Default 6-8? Configurable? |
| 208 | +2. **Auto-close behavior** — Should resolved issues auto-close or require human approval? |
| 209 | +3. **Branch strategy** — One branch per issue? Single branch for batch? |
| 210 | +4. **PR creation** — Auto-create PR per issue or per batch? |
| 211 | +5. **Failure handling** — If one issue is stuck, skip to next or block? |
| 212 | +6. **Cost tracking** — Track token spend per issue? |
| 213 | + |
| 214 | +## References |
| 215 | + |
| 216 | +- @.claude/commands/ralph-external.md — External ralph loop command |
| 217 | +- @.claude/commands/ralph.md — Internal ralph loop command |
| 218 | +- @.claude/commands/issue-comment.md — Issue comment templates |
| 219 | +- @.claude/commands/issue-list.md — Issue listing and filtering |
| 220 | +- @.claude/commands/issue-sync.md — Commit-to-issue synchronization |
| 221 | +- @.claude/rules/context-budget.md — Parallel subagent limits |
| 222 | +- @tools/ralph-external/orchestrator.mjs — Ralph-external implementation |
0 commit comments