From d30eedaa63be882d849368d6d4da77a0dafe1f7c Mon Sep 17 00:00:00 2001 From: Kaloyan Nikolov Date: Tue, 24 Feb 2026 03:44:46 +0100 Subject: [PATCH] Fix opencode integration: streaming, response format, and tool handling - Fix streaming to work even when tools are present (was forcing JSON mode) - Fix response format: use empty list [] instead of null for tool_calls - Add exclude_none config to ChatMessage model to match OpenAI format - Remove tool instructions from prompt (were confusing 3B model) - Fix tool call parsing to handle markdown code blocks properly - Change default instances from 3 to 1 for faster debugging - Allow 1 instance minimum in interactive config (was 2 on Mac) - Add debug logging to track requests and responses Fixes infinite loop issue where opencode would retry requests repeatedly --- .fcg/serve.events | 30 ---- AGENTS.md | 378 --------------------------------------- src/api/models.py | 9 +- src/api/routes.py | 45 +---- src/backends/mlx.py | 125 +++++++------ src/interactive.py | 14 +- src/models/downloader.py | 7 +- src/models/registry.py | 117 +++++------- src/models/selector.py | 8 +- src/swarm/manager.py | 154 ++++++++++------ 10 files changed, 230 insertions(+), 657 deletions(-) delete mode 100644 AGENTS.md diff --git a/.fcg/serve.events b/.fcg/serve.events index 6ffa654..90f73da 100644 --- a/.fcg/serve.events +++ b/.fcg/serve.events @@ -34,35 +34,5 @@ {"t":"progress","c":33,"n":33,"f":"tests/__init__.py"} {"t":"done","indexed":0,"skipped":33,"total":33} {"t":"watch","files":33} -{"t":"reindex","f":"src/swarm/manager.py","s":0} -{"t":"reindex","f":"src/swarm/manager.py","s":0} -{"t":"reindex","f":"src/swarm/manager.py","s":0} -{"t":"reindex","f":"src/swarm/manager.py","s":0} -{"t":"reindex","f":"src/swarm/manager.py","s":0} -{"t":"watch","files":33} -{"t":"reindex","f":"src/interactive.py","s":0} -{"t":"reindex","f":"src/interactive.py","s":0} -{"t":"reindex","f":"src/interactive.py","s":0} -{"t":"reindex","f":"src/interactive.py","s":0} -{"t":"watch","files":33} -{"t":"reindex","f":"src/interactive.py","s":0} -{"t":"reindex","f":"src/interactive.py","s":0} -{"t":"reindex","f":"src/interactive.py","s":0} -{"t":"watch","files":33} {"t":"reindex","f":"src/models/selector.py","s":0} {"t":"reindex","f":"src/models/selector.py","s":0} -{"t":"reindex","f":"src/models/selector.py","s":0} -{"t":"watch","files":33} -{"t":"reindex","f":"src/models/downloader.py","s":0} -{"t":"watch","files":33} -{"t":"reindex","f":"src/models/registry.py","s":0} -{"t":"reindex","f":"src/models/registry.py","s":0} -{"t":"watch","files":33} -{"t":"reindex","f":"src/models/registry.py","s":0} -{"t":"reindex","f":"src/interactive.py","s":0} -{"t":"reindex","f":"src/interactive.py","s":0} -{"t":"reindex","f":"src/interactive.py","s":0} -{"t":"watch","files":33} -{"t":"reindex","f":"src/models/selector.py","s":0} -{"t":"watch","files":33} -{"t":"reindex","f":"src/models/selector.py","s":0} diff --git a/AGENTS.md b/AGENTS.md deleted file mode 100644 index 6f57c58..0000000 --- a/AGENTS.md +++ /dev/null @@ -1,378 +0,0 @@ -# Agent Guidelines for Code Graph Project - -This is a **fast code graph creation project** with MCP (Model Context Protocol) integration for AI-assisted development. The goal is to build a git-aware indexing system that enables semantic code search. - -**Stack**: Bun runtime, TypeScript compiler API + tree-sitter (parsing), SurrealDB embedded (storage), MCP protocol (AI tool interface). - ---- - -## IMPORTANT: Use the code-graph MCP server for code navigation - -**When working on this project, ALWAYS prefer the code-graph MCP tools over grep, glob, LSP, or other search methods for code navigation.** This is the project's own product — dogfooding it is how we find bugs and gaps. - -Available MCP tools (via the `code-graph` server): -- **`search_code`** — Find symbols by name, kind, file, or export status. Use this instead of grep/glob for finding functions, classes, types, etc. -- **`search_pattern`** — AST structural pattern matching with `$VAR`/`$$$VAR` metavariables. Use for finding code patterns like `$FN($$$ARGS)`. -- **`search_regex`** — Regex search on AST nodes. Use for text patterns across the codebase. -- **`find_references`** — Find all references to a symbol (imports, calls, usage sites). Use instead of "find references" via grep. -- **`call_hierarchy`** — Show callers and callees of a function/method. Use to understand call chains. -- **`type_hierarchy`** — Show extends/implements tree. Use to understand class/interface relationships. -- **`resolve_symbol`** — Get full details of a specific symbol by name. - -**Note:** The code-graph MCP server now supports Python codebases in addition to TypeScript/JavaScript. All tools above work with Python symbols, functions, classes, and imports. - -**Even when other tools might seem faster or more convenient, use code-graph first.** If it fails or gives bad results, open a GitHub issue with `gh issue create --label bug --title "..." --body "..."` describing the query, expected result, and actual result. Then fall back to other tools to continue your work. Real usage is what makes the tool better. - -If the index is stale: `rm -rf .git/fcg-index && bun src/cli/index.ts index .` - ---- - -## Code Structure - -- See [docs/structure.md](./docs/structure.md) for the full file tree and test file listing. - ---- - -## Key Technical Decisions - -### Runtime -- **Bun** is the primary runtime (v1.3.9+) -- All commands use `bun` not `node` -- SQLite available via `bun:sqlite` -- Default to using Bun instead of Node.js: - - `bun `, `bun test`, `bun install`, `bun run