opencode-rgr-loop (0.2.0)
Installation
registry=npm install opencode-rgr-loop@0.2.0"opencode-rgr-loop": "0.2.0"About this package
opencode-rgr-loop
Deterministic red-green-refactor orchestration for opencode.
This plugin is built around an event-sourced control plane. Agents generate and review work, but deterministic plugin code owns state transitions. Orchestration-critical role outputs are accepted only through typed rgr_submit_* tools; assistant response text is not parsed as authoritative state.
Usage
{
"$schema": "https://opencode.ai/config.json",
"plugin": [
[
"opencode-rgr-loop",
{
"classification": {
"test": { "paths": ["**/*.test.ts", "**/*.spec.ts", "tests/**"] },
"production": { "paths": ["src/**"], "exclude": ["**/*.test.ts", "**/*.spec.ts"] },
"nonBehavioral": { "paths": ["README.md", "docs/**", "*.config.ts"] },
"protected": { "paths": [".env", ".env.*", "**/*.key", "**/*.pem"] },
"allowUnknown": false
}
}
]
]
}
The plugin exposes these user-facing tools:
rgr_loop: runs a deterministic RGR workflow from a BDD-style behavioral specification.rgr_initialize: writes project-localbuildandescape-hatchagents without clobbering existing files.
The plugin also registers subagent-facing submission tools:
rgr_submit_planrgr_submit_plan_reviewrgr_submit_test_authoredrgr_submit_test_reviewrgr_submit_implementation_resultrgr_submit_implementation_reviewrgr_submit_final_review
Each submission tool validates its arguments before orchestration consumes the result. Invalid shapes are rejected instead of normalized.
Typed submission workflow
Every RGR phase result is delivered through its matching typed rgr_submit_* tool submission; rgr_loop does not fall back to parsing assistant response text for orchestration-critical state.
For documentation-only clarification requests, the dogfood RGR run still uses the typed rgr_submit_* workflow end-to-end: RED authors one focused documentation check, GREEN makes only the minimal documentation or documentation-focused test adjustment needed, review phases submit typed approvals or vetoes, and the run is not committed by the loop.
The typed submissions are:
rgr_submit_planrgr_submit_plan_reviewrgr_submit_test_authoredrgr_submit_test_reviewrgr_submit_implementation_resultrgr_submit_implementation_reviewrgr_submit_final_review
rgr_loop
rgr_loop accepts:
bddSpec: a BDD-style behavioral specification.finalReviewers: optional opencode agent names that must approve after implementation review.
The workflow is:
- Planner submits scenarios with
rgr_submit_plan. - Plan reviewer approves or vetoes with
rgr_submit_plan_review. - RED test author writes exactly one failing test and submits with
rgr_submit_test_authored. - Test reviewer approves or vetoes with
rgr_submit_test_review. - GREEN implementer makes the smallest production change and submits with
rgr_submit_implementation_result. - Implementation reviewer approves or vetoes with
rgr_submit_implementation_review. - Optional final reviewers approve or veto with
rgr_submit_final_review.
Multiple planned scenarios are executed serially. RunCompleted is recorded only after the final planned scenario and all configured final reviewers have approved.
rgr_initialize
rgr_initialize creates project-local agents:
.opencode/agent/build.md: RGR-first implementation agent that triesrgr_loopbefore falling back to disciplined direct edits..opencode/agent/escape-hatch.md: direct implementation agent for intentionally bypassing the RGR-first workflow.
Restart opencode after changing plugin source, generated agents, or opencode config. For dogfooding plugin changes without restarting an existing chat, run a fresh process such as:
opencode run --agent build "Use rgr_loop for: Given ... When ... Then ..."
Each opencode run process loads the current plugin source and can be used as the RGR dogfood attempt while an existing session handles fallback edits if needed.
Event logs
Event logs are local artifacts and should be ignored by consuming projects:
.opencode/rgr-loop/
Notes
- Submission storage is process-local and one-shot: each typed submission is consumed once by the orchestrator for the child session that submitted it.
- Event logs are append-only JSONL files under
.opencode/rgr-loop/runs/. - File classification controls edit-policy grants for RED test authoring and GREEN implementation phases.
Dependencies
Dependencies
| ID | Version |
|---|---|
| zod | latest |
Peer dependencies
| ID | Version |
|---|---|
| @opencode-ai/plugin | 1.15.6 |