mirror of
https://github.com/open-jarvis/OpenJarvis.git
synced 2026-07-28 05:12:26 +00:00
Adds an `OpenCodeAgent` (registry key `opencode`) that delegates coding tasks to opencode (https://opencode.ai, MIT) while keeping inference local-first: OpenJarvis's engine backs opencode via an OpenAI-compatible provider. How it works: - Derives an OpenAI-compatible base URL from the engine (e.g. Ollama/vLLM at `<host>/v1`) and writes an `opencode.json` registering it as an `@ai-sdk/openai-compatible` provider (`openjarvis/<model>`). - Spawns a headless `opencode serve` (loopback, random port), waits for `/global/health`, then drives a session: `POST /session` → `POST /session/{id}/message` with `model={providerID,modelID}` + agent (`build`/`plan`) → parses message `parts` (text → content, tool → tool_results) into an `AgentResult`. `close()` disposes the server. - opencode is an external binary (not bundled); `run()` returns a clear, actionable error when it's missing, mirroring ClaudeCodeAgent's degradation. Verified end-to-end against the real opencode binary wired to a stub OpenAI-compatible engine: opencode called the local endpoint and the agent parsed the response (content/finish/model) correctly. Unit tests cover part parsing, base-URL derivation, provider-config writing (incl. merge), binary detection, graceful degradation, and run() parsing with a mocked client — 15 passed, ruff clean. Registered via the standard try/except import in agents/__init__.py; documented in docs/user-guide/agents.md. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>