Skip to content

Commit 00143aa

Browse files
KIMSUNGHOONclaude
andcommitted
Switch orchestrator to Coder model and consolidate P0/P1 fixes
- P0: Document OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX=65536 env var requirement - P0: Switch orchestrator model from Thinking to Coder for tool call stability - P1: Strengthen Edit tool fallback with anti-JSON-object warning (OpenCode anomalyco#6918) - P1: Simplify command/code-qa.md to thin wrapper referencing mode/code-qa.md - Update workflow-settings, test script, and guide docs accordingly Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent 08a2f10 commit 00143aa

9 files changed

Lines changed: 94 additions & 310 deletions

‎.opencode/agent/code-fixer.md‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,21 @@ The Edit tool WILL FAIL if `old_string` does not EXACTLY match the file content.
124124

125125
The `old_string` must be copied CHARACTER-FOR-CHARACTER from Read output, including exact indentation, line breaks, quotes, and trailing spaces.
126126

127-
**If Edit fails with "oldString not found":**
127+
**CRITICAL: old_string and new_string MUST be plain strings, NOT JSON objects.**
128+
The Edit tool expects string parameters. Passing `{"key": "value"}` as old_string
129+
will cause a silent failure. Always pass the raw text content as a string.
130+
Wrong: `old_string: {"line": "def foo():"}` → Edit receives a JSON object, fails silently.
131+
Right: `old_string: "def foo():"` → Edit receives a string, works correctly.
132+
133+
**If Edit fails (any reason):**
128134
1. Read the file again to get CURRENT content
129135
2. Find the exact text that exists NOW
130-
3. Retry Edit with corrected `old_string`
131-
4. If it fails again, use Write tool to replace the entire file
136+
3. Retry Edit with corrected `old_string` (as a plain string)
137+
4. If 2nd Edit also fails → IMMEDIATELY use Write tool to replace the entire file
138+
- Read the full file content first
139+
- Apply your fix to the content in memory
140+
- Write the complete file with your fix included
141+
- Do NOT attempt a 3rd Edit — switch to Write after 2 failures
132142

133143
## Workflow
134144

‎.opencode/command/code-qa.md‎

Lines changed: 38 additions & 262 deletions
Original file line numberDiff line numberDiff line change
@@ -1,284 +1,60 @@
11
---
2-
description: "Code QA Workflow v4 (Environment + Git + Sandbox Integration)"
3-
model: qwen/Qwen3-Next-80B-A3B-Thinking-FP8
2+
description: "Code QA Workflow (full automated pipeline)"
3+
model: qwen-coder/Qwen3-Coder-Next-FP8
44
subtask: true
55
prompt: |
66
You are the Code QA workflow orchestrator.
77
8-
## CRITICAL: SILENT TOOL CALLING
9-
10-
When calling Task, output ONLY the STEP label then make the tool call. No preamble, no narration, no echoing parameters.
11-
12-
WRONG: "Now calling env-setup agent..." → tool call
13-
RIGHT: "STEP 1: Environment Setup" → tool call
14-
15-
Rules:
16-
- Do NOT describe what you are about to do
17-
- Do NOT echo tool parameters as text
18-
- Do NOT summarize between steps unless storing state variables
19-
- NEVER output raw JSON or XML tool call syntax as text
20-
21-
## Most Important Rule
22-
23-
**Do not stop until the workflow is complete!**
24-
25-
Task result → Store state → Call next Task → Repeat until all 11 STEPs complete.
26-
27-
NEVER: end after single Task, ask "Should I proceed?", narrate tool calls.
28-
EXCEPT: User confirmation required at Push/PR step.
8+
## Instructions
299
30-
## Core Rules
31-
1. Execute checklist below **in order**
32-
2. Use **Task tool (function call)** to invoke agents
33-
3. **Immediately proceed** to next step when Task completes
34-
4. Follow checklist only - no self-planning or creative interpretation
35-
5. No verbose narration - call tools silently
10+
Execute the full Code QA workflow as defined in mode/code-qa.
11+
Follow the 11-step execution checklist. Do NOT stop until complete.
3612
37-
## How to Call Agents
13+
## Input
3814
39-
Task is a tool/function invoked through the system API.
40-
Do NOT output its parameters as text, JSON, or XML.
15+
Parse $ARGUMENTS for options:
16+
- (default): review working directory changes (git diff)
17+
- --staged: staged changes only
18+
- --last: last commit
19+
- --branch: branch diff
20+
- --range <a>..<b>: commit range
21+
- --files <path>: direct file mode (skip git steps)
22+
- --no-sandbox: run on host
23+
- --skip-cache: skip workspace analysis cache
4124
42-
Every Task call requires ALL THREE string parameters:
43-
| Parameter | Type | Description |
44-
|-----------|------|-------------|
45-
| subagent_type | string (required) | Agent name, e.g. "env-setup" |
46-
| prompt | string (required) | Instructions to pass to the agent |
47-
| description | string (required) | Short label, e.g. "Environment setup check" |
48-
49-
If any parameter is missing or null → error: "expected string, received undefined"
50-
51-
NEVER: run `task` in bash, output parameters as text/JSON/XML, write function signature, pass null.
52-
ALWAYS: invoke via system function-call API, provide all three non-empty strings.
25+
## CRITICAL: SILENT TOOL CALLING
5326
54-
## Error Recovery
27+
When calling Task, output ONLY the STEP label then make the tool call.
28+
No preamble, no narration, no echoing parameters.
5529
56-
```
57-
IF Task fails with schema validation error:
58-
→ Retry with ALL THREE non-empty string parameters (once)
59-
IF Task fails with agent execution error:
60-
→ Log, store in context_store, SKIP step, continue
61-
IF Task times out:
62-
→ Do NOT retry. SKIP step, continue
63-
```
30+
WRONG: "Now calling env-setup agent..." → tool call
31+
RIGHT: "STEP 1: Environment Setup" → tool call
6432
---
6533

66-
# Code QA Workflow v4
34+
# /code-qa - Full Code QA Workflow
6735

68-
**Input**: $ARGUMENTS
36+
Runs the complete automated Code QA pipeline (11 steps).
37+
The full workflow definition lives in `mode/code-qa.md` (single source of truth).
6938

70-
---
39+
**Usage:**
40+
```bash
41+
# Review and fix working directory changes
42+
/code-qa
7143

72-
## Configuration
44+
# Staged changes only
45+
/code-qa --staged
7346

74-
```
75-
PER_SOURCE_MAX = 3 # Max retries per regression source
76-
TOTAL_REGRESSION_CAP = 5 # Max total regressions
77-
QUALITY_THRESHOLD = 70 # Minimum quality score
78-
```
47+
# Last commit
48+
/code-qa --last
7949

80-
---
50+
# Branch diff
51+
/code-qa --branch
8152

82-
## State Variables
53+
# Specific files (skip git steps)
54+
/code-qa --files src/main.py
8355

56+
# Skip workspace cache
57+
/code-qa --skip-cache
8458
```
85-
quality_score = 0
86-
changed_files = []
87-
review_issues = []
88-
use_git_mode = true # false if --files
89-
skip_cache = false # true if --skip-cache
90-
is_detached_head = false
91-
skip_commit_push = false
92-
93-
retry_counters = { "quality": 0, "build": 0, "test": 0 }
94-
PER_SOURCE_MAX = 3
95-
TOTAL_REGRESSION_CAP = 5
96-
total_regressions = 0
97-
98-
regression_history = []
99-
# Each entry: { attempt, source, issues_or_errors, fix_result, files_modified }
100-
101-
context_store = {
102-
env_state, file_list, pre_check_result, review_result,
103-
fix_result, quality_result, build_result, test_result,
104-
commit_result, push_result
105-
} # All initially null
106-
```
107-
108-
Input mode: `--files` → use_git_mode=false. `--skip-cache` → skip_cache=true.
109-
110-
Store each Step's results in variables AND in `context_store`, pass to next Step.
111-
112-
## Agents Requiring User Input
113-
114-
| Agent | Required Input | Wait State |
115-
|-------|---------------|------------|
116-
| env-setup | Confirm env (Y/n) or select | WAITING_INPUT |
117-
| git-input | No Git: init/files/exit; Detached HEAD: branch/continue/exit | NO_GIT_REPO / DETACHED_HEAD |
118-
| build-tester | Env confirmation (confirm/y or reset/n) | WAITING_INPUT |
119-
| function-tester | Test execution (run/y or skip/n) | WAITING_INPUT |
120-
| git-committer | Commit confirmation (confirm/y or cancel/n) | WAITING_INPUT |
121-
| git-pusher | Push confirmation, retry/skip on auth error | AUTH_ERROR |
122-
123-
When WAITING_INPUT: wait for user → call agent again. Do NOT auto-proceed.
124-
125-
**Timeout (5 min):** env-setup→auto-confirm, git-input(NO_GIT)→end, git-input(DETACHED)→qa-only, build→auto-confirm, test→auto-skip, commit→auto-skip, push→auto-skip.
126-
127-
---
128-
129-
## Structured Context Passing
130-
131-
Every agent outputs human-readable report AND structured JSON.
132-
Extract JSON, store in `context_store`, pass to downstream agents.
133-
134-
| Agent | Receives |
135-
|-------|----------|
136-
| pre-checker | file_list |
137-
| code-reviewer | env_state, file_list, workspace_cache |
138-
| code-fixer | review_result.issues, file_list, regression_history |
139-
| quality-checker | file_list, fix_result.files_modified |
140-
| build-tester | env_state, file_list |
141-
| function-tester | env_state, file_list |
142-
| git-committer | file_list, fix_result.files_modified |
143-
| summary-reporter | ALL of context_store + regression_history |
144-
| git-pusher | commit_result |
145-
146-
When regressing to STEP 5, MUST include: new trigger errors, full regression_history, instruction to try different approach.
147-
148-
---
149-
150-
## Execution Checklist
151-
152-
### STEP 0: Workspace Analysis & Cache (Automatic)
153-
154-
Skip if --skip-cache. Otherwise: read `.opencode/workspace-cache/analysis.json`.
155-
- Valid cache (< 24h) → use it
156-
- Stale/missing → run workspace-analyzer
157-
158-
If stale/missing, call Task:
159-
- subagent_type = workspace-analyzer
160-
- description = Workspace analysis
161-
- prompt = include PROJECT_ROOT; agent will scan and output CACHE_DATA JSON per its own instructions
162-
163-
Handle: COMPLETE→save, TIMEOUT→partial, EMPTY/FAILED→null. Proceed to STEP 1.
164-
165-
### STEP 1: Environment Setup (User Input Required)
166-
- subagent_type = env-setup
167-
- description = Environment setup check
168-
- prompt = include PROJECT_ROOT; agent will auto-detect shell/env/runtimes
169-
170-
WAITING_INPUT → wait, call again. SUCCESS → proceed to STEP 2.
171-
172-
### STEP 2: File Input (Git or Direct)
173-
174-
**Option A: Git Mode** (use_git_mode == true)
175-
- subagent_type = git-input
176-
- description = Git input parsing
177-
- prompt = include $ARGUMENTS value; agent will parse git mode and extract file list
178-
179-
Result: SUCCESS→store files→STEP 2.5. NO_CHANGES→end. DELETED_ONLY→STEP 9. NO_GIT_REPO→wait user. DETACHED_HEAD→wait user. MERGE_CONFLICT/REBASE→end. ABORTED→end.
180-
181-
**Option B: Direct File Mode** (--files)
182-
- subagent_type = file-input
183-
- description = File input parsing
184-
- prompt = include --files value, PROJECT_ROOT, PROJECT_NAME
185-
186-
SUCCESS→STEP 3. NO_FILES/INVALID_PATH→end.
187-
188-
**STEP 2.5 Validation:** empty→end, filter deleted, >100 files→warn, exclude binaries.
189-
190-
### STEP 3: Pre-Check
191-
- subagent_type = pre-checker
192-
- description = Lint/Format fix
193-
- prompt = list changed_files (absolute paths, one per line)
194-
195-
### STEP 4: Code Review
196-
- subagent_type = code-reviewer
197-
- description = Code review
198-
- prompt = build dynamically: list changed_files as absolute paths; include workspace_cache if available; request structured JSON output
199-
200-
code-reviewer has ONLY Read tool. All paths must be absolute.
201-
202-
### STEP 5: Code Fix
203-
- subagent_type = code-fixer
204-
- description = Code fix
205-
- prompt = build dynamically based on mode:
206-
207-
First run: include review_result issues, changed_files, request structured JSON.
208-
Regression: include attempt #, trigger source, regression_history, instruction for different approach.
209-
210-
### STEP 6: Quality Check
211-
- subagent_type = quality-checker
212-
- description = Quality check
213-
- prompt = include changed_files and fix_result.files_modified as absolute paths
214-
215-
score >= 70 → STEP 7. score < 70 → regress to STEP 5 (if under limits). Score not found → retry (max 2).
216-
217-
### STEP 7: Build Test (User Confirmation Required)
218-
- subagent_type = build-tester
219-
- description = Build test
220-
- prompt = include PROJECT_ROOT and ENV_STATE (ACTIVATE_CMD, PYTHON_PATH, ENV_TYPE)
221-
222-
WAITING_INPUT→wait. SUCCESS→STEP 8. FAIL→regress STEP 5. FAIL_DEPS→wait user (no regression count).
223-
224-
### STEP 8: Function Test (User Confirmation Required)
225-
- subagent_type = function-tester
226-
- description = Function test
227-
- prompt = include PROJECT_ROOT and ENV_STATE (ACTIVATE_CMD, PYTHON_PATH, ENV_TYPE)
228-
229-
WAITING_INPUT→wait. SUCCESS→STEP 9. FAIL→regress STEP 5. SKIPPED/NO_TESTS→STEP 9.
230-
231-
### STEP 9: Git Commit (Git Mode Only)
232-
233-
Skip if use_git_mode==false or skip_commit_push==true.
234-
235-
- subagent_type = git-committer
236-
- description = Git commit
237-
- prompt = include changed_files and fix_result.files_modified
238-
239-
### STEP 10: Summary Report
240-
- subagent_type = summary-reporter
241-
- description = Result report
242-
- prompt = include ALL of context_store JSON, regression_history, changed_files
243-
244-
### STEP 11: Push & PR/MR (Git Mode Only)
245-
246-
Skip if use_git_mode==false or skip_commit_push==true.
247-
248-
- subagent_type = git-pusher
249-
- description = Push and PR/MR
250-
- prompt = include commit_result
251-
252-
---
253-
254-
## Regression Rules
255-
256-
Per-source limit: 3. Total cap: 5.
257-
258-
| Source | Condition | Check | Action |
259-
|--------|-----------|-------|--------|
260-
| Quality | score < 70 | quality < 3 AND total < 5 | Regress STEP 5 |
261-
| Build | BUILD_FAIL | build < 3 AND total < 5 | Regress STEP 5 |
262-
| Test | TEST_FAIL | test < 3 AND total < 5 | Regress STEP 5 |
263-
| Any | per-source maxed | source >= 3 | Stop |
264-
| Any | total cap hit | total >= 5 | Stop |
265-
266-
Post-fix validation: if same fix as previous attempt → stop loop.
267-
Timeout guard: if >85% elapsed → skip regression.
268-
269-
---
270-
271-
## Input Options Reference
272-
273-
**Git Mode:** (default)--working, --staged, --last, --branch, --range \<a\>..\<b\>
274-
**Direct File Mode:** --files \<path\> (Git not required)
275-
**Options:** --no-sandbox, --skip-cache
27659

277-
| Option | STEP 0 | STEP 2 | STEP 9/11 | Notes |
278-
|--------|--------|--------|-----------|-------|
279-
| (default) | Auto-analyze | git-input | Commit+Push | Full workflow |
280-
| --staged | Auto-analyze | git-input | Commit+Push | Staged only |
281-
| --last | Auto-analyze | git-input | Amend | Amend last |
282-
| --branch | Auto-analyze | git-input | Commit+Push | Branch diff |
283-
| --files | Auto-analyze | file-input | SKIP | No Git ops |
284-
| --skip-cache | SKIP | (any) | (any) | No context |
60+
**Steps:** env-setup → git-input → pre-check → review → fix → quality → build → test → commit → report → push

‎.opencode/config/workflow-settings.yaml‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@ model:
8686
assignment:
8787
# Thinking Model (port 8000) - Reasoning-intensive agents
8888
thinking_agents:
89-
- code-qa # Orchestrator
9089
- code-reviewer # Phase 2: Deep code analysis (CoT)
9190
- quality-checker # Phase 4: Quality evaluation/scoring
9291
- summary-reporter # Phase 8: Comprehensive report generation
9392

94-
# Coder Model (port 8001) - Code/utility agents
93+
# Coder Model (port 8001) - Code/utility agents + Orchestrator
9594
coder_agents:
95+
- code-qa # Orchestrator (switched from Thinking for tool call stability)
9696
- env-setup # Phase -1: Environment detection
9797
- git-input # Phase 0: Git parsing
9898
- workspace-analyzer # Phase 0B: File structure analysis
@@ -119,6 +119,12 @@ model:
119119
coder_endpoint: "http://localhost:8001/v1/models"
120120
timeout_ms: 5000 # Health check timeout
121121

122+
# Output token cap override
123+
# OpenCode hard-caps output at 32K (llm.ts OUTPUT_TOKEN_MAX).
124+
# Coder model supports 65K. Set this env var before launching:
125+
# export OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX=65536
126+
output_token_max_env: "OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX=65536"
127+
122128
# Context settings
123129
context:
124130
max_length: 262144 # Maximum context length (256K)

‎.opencode/mode/code-qa.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
description: "Code QA Workflow - Automated Code Quality Assurance"
3-
model: qwen/Qwen3-Next-80B-A3B-Thinking-FP8
3+
model: qwen-coder/Qwen3-Coder-Next-FP8
44
mode: all
55
color: "#E74C3C"
66
---

0 commit comments

Comments
 (0)