feat(opencode): add plan mode, reasoning effort, and status telemetry (#688)

* feat(opencode): support plan mode

* feat(opencode): support reasoning effort

* feat(opencode): surface context usage in web

Bridge OpenCode ACP usage updates into the existing token-count pipeline so the web status bar can show live context and cache information without a separate UI path.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(opencode): restrict plan mode to remote, rollback reasoning effort on failure

- Block local OpenCode plan startup (tools not enforced in local path)
- Allow remote OpenCode plan only (ACP permission handler denies tools)
- Guard web /permission-mode endpoint for local OpenCode plan sessions
- Rollback session reasoning effort when OpenCode rejects set_config_option
- Wire rollback callback through opencodeLoop to runOpencode closure
- Add tests: local plan rejected, remote plan allowed, web guard, effort rollback

* fix(web): auto-retry OpenCode models query to populate model selector without refresh

- Retry early failures (RPC may still be registering on new sessions)
- Poll briefly until availableModels is non-empty
- Stop polling once model options are discovered
- Add tests for retry/poll/stop policy

* fix(opencode): cap model discovery polling

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
SSU-WEI HUANG
2026-05-27 11:17:24 +08:00
committed by GitHub
co-authored by Cursor
parent d5a67b717c
commit 6f2bb7d32b
43 changed files with 1263 additions and 68 deletions
@@ -26,6 +26,13 @@ describe('parseRemoteAgentCommandOptions', () => {
], OPENCODE_PERMISSION_MODES).permissionMode).toBe('default')
})
it('accepts OpenCode plan permission mode', () => {
expect(parseRemoteAgentCommandOptions([
'--permission-mode',
'plan'
], OPENCODE_PERMISSION_MODES).permissionMode).toBe('plan')
})
it('keeps current unknown-arg behavior by ignoring unrecognized flags', () => {
expect(parseRemoteAgentCommandOptions([
'--unknown',
@@ -49,8 +56,16 @@ describe('parseRemoteAgentCommandOptions', () => {
], GEMINI_PERMISSION_MODES)).toThrow('Invalid --permission-mode value')
})
it('parses model reasoning effort', () => {
expect(parseRemoteAgentCommandOptions([
'--model-reasoning-effort',
'high'
], OPENCODE_PERMISSION_MODES).modelReasoningEffort).toBe('high')
})
it('requires values for resume and model flags', () => {
expect(() => parseRemoteAgentCommandOptions(['--resume'], OPENCODE_PERMISSION_MODES)).toThrow('Missing --resume value')
expect(() => parseRemoteAgentCommandOptions(['--model'], OPENCODE_PERMISSION_MODES)).toThrow('Missing --model value')
expect(() => parseRemoteAgentCommandOptions(['--model-reasoning-effort'], OPENCODE_PERMISSION_MODES)).toThrow('Missing --model-reasoning-effort value')
})
})