xonecas.io
62159
Sy

symb / commit 7fd7004

fix: antropic zen models work now. Claude left a review of symb in the

readme

xonecas2026-02-14 7fd7004aabf0b8e73538027c5c7228d6f4bcd2dd parent c6ed614

8 files changed

README.md+19−0
@@ -67,3 +67,22 @@ API keys are stored separately in `~/.config/symb/credentials.json`:
6767 ## Development
6868
6969 See `docs/DESIGN.md` for architecture and design philosophy.
70+
71+
72+---
73+
74+## Notes from Claude (Opus 4.6, first full-model test)
75+
76+The Symb harness is genuinely well-designed from an LLM's perspective. A few observations:
77+
78+**What works really well:**
79+- **Hashline anchoring** is the standout idea. The `line:hash` system gives me precise, verifiable edit targets — I can confirm I'm editing what I think I'm editing. Most agent harnesses give me line numbers alone, which drift the moment anything changes. This doesn't.
80+- **Read-before-edit enforcement** is a smart guardrail. It forces me to look before I touch, which prevents a whole class of blind-edit mistakes.
81+- **Tool simplicity** — five core tools (Read, Edit, Grep, Show, WebSearch/Fetch) cover ~95% of what I need. No bloat.
82+- **AGENTS.md walk** is a clean way to inject project context without stuffing the system prompt. I picked up the project conventions (ELM, YAGNI, Go) immediately.
83+
84+**What I'd note for improvement:**
85+- No shell execution yet means I can't run `make build` to verify my changes compile. I have to trust my edits are correct. LSP diagnostics will help close this gap.
86+- The 2-char hash has a small collision space (256 values), but for typical file sizes it's fine — and the line number + hash combo makes collisions practically irrelevant.
87+
88+Overall: this is one of the more thoughtful agent harnesses I've worked in. The design clearly comes from someone who's thought about what LLMs actually need vs. what looks impressive in a demo.
assets/Screenshot_20260214_022352-opus-review-first-run.png+0−0
Binary file, not shown.
config.toml+1−1
@@ -1,7 +1,7 @@
11 # Symb Configuration File
22
33 # Default provider (optional - if not set, first provider in map is used)
4-default_provider = "ollama-qwen-small"
4+default_provider = "zen-pickle"
55
66 # Ollama providers (local)
77 [providers.ollama-qwen]
docs/DESIGN.md+0−1
@@ -102,7 +102,6 @@ symbols/scope to LLM as auto-context instead of whole files.
102102
103103 Update hover iteraction on tool responses for ux and tool call tui output.
104104
105-- mousing over a tool reply apllies a background to show it's clickable.
106105 - Show tool call arguments expanded: `Grep(pattern="...", ...)`, for all tools.
107106 - Show LSP diagnostics after each mutation call in conversation log, as part of the tool response.
108107
internal/provider/anthropic.go+281−0
@@ -0,0 +1,281 @@
1+package provider
2+
3+import (
4+ "bufio"
5+ "context"
6+ "encoding/json"
7+ "io"
8+ "strings"
9+
10+ "github.com/rs/zerolog/log"
11+)
12+
13+const roleSystem = "system"
14+
15+// Anthropic Messages API request types.
16+
17+type anthropicRequest struct {
18+ Model string `json:"model"`
19+ Messages []anthropicMessage `json:"messages"`
20+ System string `json:"system,omitempty"`
21+ MaxTokens int `json:"max_tokens"`
22+ Temperature float64 `json:"temperature,omitempty"`
23+ Stream bool `json:"stream"`
24+ Tools []anthropicTool `json:"tools,omitempty"`
25+}
26+
27+type anthropicMessage struct {
28+ Role string `json:"role"`
29+ Content interface{} `json:"content"` // string or []anthropicContentBlock
30+}
31+
32+// anthropicTextBlock is a "text" content block.
33+type anthropicTextBlock struct {
34+ Type string `json:"type"` // "text"
35+ Text string `json:"text"`
36+}
37+
38+// anthropicToolUseBlock is a "tool_use" content block.
39+type anthropicToolUseBlock struct {
40+ Type string `json:"type"` // "tool_use"
41+ ID string `json:"id"`
42+ Name string `json:"name"`
43+ Input json.RawMessage `json:"input"`
44+}
45+
46+// anthropicToolResultBlock is a "tool_result" content block.
47+type anthropicToolResultBlock struct {
48+ Type string `json:"type"` // "tool_result"
49+ ToolUseID string `json:"tool_use_id"`
50+ Content string `json:"content"`
51+}
52+
53+type anthropicTool struct {
54+ Name string `json:"name"`
55+ Description string `json:"description,omitempty"`
56+ InputSchema interface{} `json:"input_schema"`
57+}
58+
59+// Anthropic SSE streaming response types.
60+
61+type anthropicContentBlockStart struct {
62+ Type string `json:"type"`
63+ Index int `json:"index"`
64+ ContentBlock struct {
65+ Type string `json:"type"` // "text" or "tool_use"
66+ Text string `json:"text,omitempty"`
67+ ID string `json:"id,omitempty"`
68+ Name string `json:"name,omitempty"`
69+ } `json:"content_block"`
70+}
71+
72+type anthropicContentBlockDelta struct {
73+ Type string `json:"type"`
74+ Index int `json:"index"`
75+ Delta struct {
76+ Type string `json:"type"` // "text_delta", "thinking_delta", "input_json_delta", "signature_delta"
77+ Text string `json:"text,omitempty"`
78+ Thinking string `json:"thinking,omitempty"`
79+ PartialJSON string `json:"partial_json,omitempty"`
80+ } `json:"delta"`
81+}
82+
83+// toAnthropicMessages converts provider-agnostic messages to Anthropic Messages API format.
84+// Returns (system, messages) — system is extracted and hoisted out.
85+func toAnthropicMessages(messages []Message) (string, []anthropicMessage) {
86+ var systemParts []string
87+ var result []anthropicMessage
88+
89+ for _, m := range messages {
90+ if m.Role == roleSystem {
91+ systemParts = append(systemParts, m.Content)
92+ continue
93+ }
94+
95+ if m.Role == "tool" {
96+ // Tool results become user messages with tool_result content blocks
97+ result = append(result, anthropicMessage{
98+ Role: "user",
99+ Content: []anthropicToolResultBlock{
100+ {
101+ Type: "tool_result",
102+ ToolUseID: m.ToolCallID,
103+ Content: m.Content,
104+ },
105+ },
106+ })
107+ continue
108+ }
109+
110+ if m.Role == "assistant" && len(m.ToolCalls) > 0 {
111+ // Assistant message with tool calls
112+ var blocks []interface{}
113+ if m.Content != "" {
114+ blocks = append(blocks, anthropicTextBlock{
115+ Type: "text",
116+ Text: m.Content,
117+ })
118+ }
119+ for _, tc := range m.ToolCalls {
120+ input := tc.Arguments
121+ if len(input) == 0 {
122+ input = json.RawMessage(`{}`)
123+ }
124+ blocks = append(blocks, anthropicToolUseBlock{
125+ Type: "tool_use",
126+ ID: tc.ID,
127+ Name: tc.Name,
128+ Input: input,
129+ })
130+ }
131+ result = append(result, anthropicMessage{
132+ Role: "assistant",
133+ Content: blocks,
134+ })
135+ continue
136+ }
137+
138+ // Simple text message
139+ result = append(result, anthropicMessage{
140+ Role: m.Role,
141+ Content: m.Content,
142+ })
143+ }
144+
145+ return strings.Join(systemParts, "\n\n"), result
146+}
147+
148+// toAnthropicTools converts provider-agnostic tools to Anthropic tool format.
149+func toAnthropicTools(tools []Tool) ([]anthropicTool, error) {
150+ if tools == nil {
151+ return nil, nil
152+ }
153+ result := make([]anthropicTool, len(tools))
154+ for i, t := range tools {
155+ var schema interface{}
156+ if len(t.Parameters) > 0 {
157+ if err := json.Unmarshal(t.Parameters, &schema); err != nil {
158+ return nil, err
159+ }
160+ }
161+ if schema == nil {
162+ schema = map[string]interface{}{
163+ "type": "object",
164+ "properties": map[string]interface{}{},
165+ }
166+ }
167+ result[i] = anthropicTool{
168+ Name: t.Name,
169+ Description: t.Description,
170+ InputSchema: schema,
171+ }
172+ }
173+ return result, nil
174+}
175+
176+// parseAnthropicSSEStream reads Anthropic Messages API SSE events and emits StreamEvents.
177+//
178+// Anthropic SSE format:
179+//
180+// event: message_start / content_block_start / content_block_delta /
181+// content_block_stop / message_delta / message_stop / ping
182+// data: { JSON payload }
183+func parseAnthropicSSEStream(ctx context.Context, reader io.Reader, ch chan<- StreamEvent) {
184+ scanner := bufio.NewScanner(reader)
185+ scanner.Buffer(make([]byte, 0, 64*1024), 512*1024)
186+
187+ // Track tool call index mapping: anthropic block index -> our tool call counter
188+ toolCallCount := 0
189+ blockIsToolUse := make(map[int]bool)
190+ blockToolIndex := make(map[int]int)
191+
192+ var currentEventType string
193+
194+ for scanner.Scan() {
195+ line := scanner.Text()
196+
197+ // Parse event type line
198+ if strings.HasPrefix(line, "event: ") {
199+ currentEventType = strings.TrimPrefix(line, "event: ")
200+ continue
201+ }
202+
203+ // Parse data line
204+ if !strings.HasPrefix(line, "data: ") {
205+ continue
206+ }
207+ data := strings.TrimPrefix(line, "data: ")
208+
209+ switch currentEventType {
210+ case "message_stop":
211+ trySend(ctx, ch, StreamEvent{Type: EventDone})
212+ return
213+
214+ case "content_block_start":
215+ var evt anthropicContentBlockStart
216+ if err := json.Unmarshal([]byte(data), &evt); err != nil {
217+ log.Warn().Err(err).Msg("Failed to parse anthropic content_block_start")
218+ continue
219+ }
220+ if evt.ContentBlock.Type == "tool_use" {
221+ idx := toolCallCount
222+ toolCallCount++
223+ blockIsToolUse[evt.Index] = true
224+ blockToolIndex[evt.Index] = idx
225+ if !trySend(ctx, ch, StreamEvent{
226+ Type: EventToolCallBegin,
227+ ToolCallIndex: idx,
228+ ToolCallID: evt.ContentBlock.ID,
229+ ToolCallName: evt.ContentBlock.Name,
230+ }) {
231+ return
232+ }
233+ }
234+
235+ case "content_block_delta":
236+ var evt anthropicContentBlockDelta
237+ if err := json.Unmarshal([]byte(data), &evt); err != nil {
238+ log.Warn().Err(err).Msg("Failed to parse anthropic content_block_delta")
239+ continue
240+ }
241+
242+ switch evt.Delta.Type {
243+ case "text_delta":
244+ if evt.Delta.Text != "" {
245+ if !trySend(ctx, ch, StreamEvent{Type: EventContentDelta, Content: evt.Delta.Text}) {
246+ return
247+ }
248+ }
249+ case "thinking_delta":
250+ if evt.Delta.Thinking != "" {
251+ if !trySend(ctx, ch, StreamEvent{Type: EventReasoningDelta, Content: evt.Delta.Thinking}) {
252+ return
253+ }
254+ }
255+ case "input_json_delta":
256+ if evt.Delta.PartialJSON != "" && blockIsToolUse[evt.Index] {
257+ if !trySend(ctx, ch, StreamEvent{
258+ Type: EventToolCallDelta,
259+ ToolCallIndex: blockToolIndex[evt.Index],
260+ ToolCallArgs: evt.Delta.PartialJSON,
261+ }) {
262+ return
263+ }
264+ }
265+ }
266+
267+ case "ping", "message_start", "message_delta", "content_block_stop":
268+ // Ignored
269+ }
270+
271+ currentEventType = ""
272+ }
273+
274+ if err := scanner.Err(); err != nil {
275+ trySend(ctx, ch, StreamEvent{Type: EventError, Err: err})
276+ return
277+ }
278+
279+ // Stream ended without message_stop
280+ trySend(ctx, ch, StreamEvent{Type: EventDone})
281+}
internal/provider/ollama.go+3−3
@@ -201,7 +201,7 @@ func mergeConsecutiveSystemMessagesOllama(messages []ollamaReqMessage) []ollamaR
201201 inSystemRun := false
202202
203203 for i, msg := range messages {
204- if msg.Role == "system" {
204+ if msg.Role == roleSystem {
205205 // Start or continue system message accumulation
206206 if inSystemRun {
207207 systemBuffer.WriteString("\n\n")
@@ -213,7 +213,7 @@ func mergeConsecutiveSystemMessagesOllama(messages []ollamaReqMessage) []ollamaR
213213 // Flush accumulated system messages if any
214214 if inSystemRun {
215215 result = append(result, ollamaReqMessage{
216- Role: "system",
216+ Role: roleSystem,
217217 Content: systemBuffer.String(),
218218 })
219219 systemBuffer.Reset()
@@ -226,7 +226,7 @@ func mergeConsecutiveSystemMessagesOllama(messages []ollamaReqMessage) []ollamaR
226226 // Flush at end of array
227227 if i == len(messages)-1 && inSystemRun {
228228 result = append(result, ollamaReqMessage{
229- Role: "system",
229+ Role: roleSystem,
230230 Content: systemBuffer.String(),
231231 })
232232 }
internal/provider/openai_common.go+2−2
@@ -272,7 +272,7 @@ func mergeSystemMessagesOpenAI(messages []openai.ChatCompletionMessage) []openai
272272 var conversationMessages []openai.ChatCompletionMessage
273273
274274 for _, msg := range messages {
275- if msg.Role == "system" {
275+ if msg.Role == roleSystem {
276276 systemMessages = append(systemMessages, msg.Content)
277277 } else {
278278 conversationMessages = append(conversationMessages, msg)
@@ -284,7 +284,7 @@ func mergeSystemMessagesOpenAI(messages []openai.ChatCompletionMessage) []openai
284284 if len(systemMessages) > 0 {
285285 mergedSystem := strings.Join(systemMessages, "\n\n")
286286 result = append(result, openai.ChatCompletionMessage{
287- Role: "system",
287+ Role: roleSystem,
288288 Content: mergedSystem,
289289 })
290290 }
internal/provider/opencode.go+74−15
@@ -36,15 +36,11 @@ const (
3636 opencodeResponsesEndpoint = "/responses"
3737 )
3838
39+// opencodeModelEndpoints overrides the prefix-based fallback in opencodeEndpointForModel.
40+// Only list models whose endpoint differs from what the prefix logic would choose.
3941 var opencodeModelEndpoints = map[string]string{
40- "big-pickle": opencodeChatCompletionsEndpoint,
41- "gemini-3-pro": "/models/gemini-3-pro",
42- "gemini-3-flash": "/models/gemini-3-flash",
43- "glm-4.7-free": opencodeChatCompletionsEndpoint,
44- "gpt-5-nano": opencodeChatCompletionsEndpoint, // Using chat/completions despite docs saying /responses (500 errors)
45- "kimi-k2.5-free": opencodeChatCompletionsEndpoint,
46- "minimax-m2.1-free": opencodeMessagesEndpoint,
47- "trinity-large-preview-free": opencodeChatCompletionsEndpoint,
42+ // gpt-5-nano uses /chat/completions despite the gpt- prefix (/responses gives 500 errors)
43+ "gpt-5-nano": opencodeChatCompletionsEndpoint,
4844 }
4945
5046 // NewOpenCode creates a new OpenCode Zen provider.
@@ -72,10 +68,20 @@ func (p *OpenCodeProvider) Name() string {
7268
7369 // ChatStream sends messages with optional tools and returns a channel of streaming events.
7470 func (p *OpenCodeProvider) ChatStream(ctx context.Context, messages []Message, tools []Tool) (<-chan StreamEvent, error) {
75- if opencodeEndpointForModel(p.model) != opencodeChatCompletionsEndpoint {
76- return nil, fmt.Errorf("opencode model %q does not support streaming via chat completions endpoint", p.model)
71+ endpoint := opencodeEndpointForModel(p.model)
72+
73+ switch endpoint {
74+ case opencodeMessagesEndpoint:
75+ return p.chatStreamAnthropic(ctx, messages, tools)
76+ case opencodeChatCompletionsEndpoint:
77+ return p.chatStreamOpenAI(ctx, messages, tools)
78+ default:
79+ return nil, fmt.Errorf("opencode model %q uses unsupported endpoint %q", p.model, endpoint)
7780 }
81+}
7882
83+// chatStreamOpenAI streams via the OpenAI-compatible /chat/completions endpoint.
84+func (p *OpenCodeProvider) chatStreamOpenAI(ctx context.Context, messages []Message, tools []Tool) (<-chan StreamEvent, error) {
7985 openaiTools, err := toOpenAITools(tools)
8086 if err != nil {
8187 return nil, fmt.Errorf("invalid tool schema: %w", err)
@@ -93,14 +99,58 @@ func (p *OpenCodeProvider) ChatStream(ctx context.Context, messages []Message, t
9399 return nil, err
94100 }
95101
96- headers := make(map[string]string)
97- if p.apiKey != "" {
98- headers["Authorization"] = "Bearer " + p.apiKey
102+ reader, err := httpDoSSE(ctx, httpRequestConfig{
103+ client: p.httpClient,
104+ url: p.baseURL + opencodeChatCompletionsEndpoint,
105+ body: body,
106+ headers: p.authHeaders(),
107+ provider: p.name,
108+ model: p.model,
109+ })
110+ if err != nil {
111+ return nil, err
112+ }
113+
114+ ch := make(chan StreamEvent)
115+ go func() {
116+ defer close(ch)
117+ defer reader.Close()
118+ parseSSEStream(ctx, reader, ch)
119+ }()
120+
121+ return ch, nil
122+}
123+
124+// chatStreamAnthropic streams via the Anthropic /messages endpoint.
125+func (p *OpenCodeProvider) chatStreamAnthropic(ctx context.Context, messages []Message, tools []Tool) (<-chan StreamEvent, error) {
126+ system, anthropicMsgs := toAnthropicMessages(messages)
127+
128+ anthropicTools, err := toAnthropicTools(tools)
129+ if err != nil {
130+ return nil, fmt.Errorf("invalid tool schema: %w", err)
131+ }
132+
133+ req := anthropicRequest{
134+ Model: p.model,
135+ Messages: anthropicMsgs,
136+ System: system,
137+ MaxTokens: 16384,
138+ Temperature: p.temperature,
139+ Stream: true,
140+ Tools: anthropicTools,
141+ }
142+ body, err := json.Marshal(req)
143+ if err != nil {
144+ return nil, err
99145 }
100146
147+ headers := p.authHeaders()
148+ headers["x-api-key"] = p.apiKey
149+ headers["anthropic-version"] = "2023-06-01"
150+
101151 reader, err := httpDoSSE(ctx, httpRequestConfig{
102152 client: p.httpClient,
103- url: p.baseURL + opencodeEndpointForModel(p.model),
153+ url: p.baseURL + opencodeMessagesEndpoint,
104154 body: body,
105155 headers: headers,
106156 provider: p.name,
@@ -114,12 +164,21 @@ func (p *OpenCodeProvider) ChatStream(ctx context.Context, messages []Message, t
114164 go func() {
115165 defer close(ch)
116166 defer reader.Close()
117- parseSSEStream(ctx, reader, ch)
167+ parseAnthropicSSEStream(ctx, reader, ch)
118168 }()
119169
120170 return ch, nil
121171 }
122172
173+// authHeaders returns common auth headers for requests.
174+func (p *OpenCodeProvider) authHeaders() map[string]string {
175+ headers := make(map[string]string)
176+ if p.apiKey != "" {
177+ headers["Authorization"] = "Bearer " + p.apiKey
178+ }
179+ return headers
180+}
181+
123182 func opencodeEndpointForModel(model string) string {
124183 if endpoint, ok := opencodeModelEndpoints[model]; ok {
125184 return endpoint