fix(adapters): ground native schemas, merge-not-replace, add goose/cagent/zed

- common/mcp.go: MCPStyle enum + BuildMCPMapStyled for claude/crush/opencode/zed dialects
- common/jsonmerge.go: MergeJSONKeys (JSON-first, JSONC fallback) preserves user keys;
  fix: try plain json.Unmarshal before StripJSONComments to avoid mangling URLs with //
- common/yamlmerge.go: MergeYAMLKeys for YAML configs (goose)
- common/blocks.go: add ProvidersAsMap for opencode map-shaped provider key
- claudecode: merge settings.json (preserves hooks/permissions/env); MCPClaudeStyle (no type field)
- crush: fix mcp key (was mcpServers); MCPCrushStyle entries include type field; merge crush.json; fix import key mcp
- kilo: drop providers key (kilo has none); MCPOpencodeStyle (local/remote); merge kilo.json
- opencode: fix provider (singular map) + model (not default_model); MCPOpencodeStyle; merge jsonc; fix import key mcp
- goose: new adapter — YAML merge, extensions map, splitProviderModel, import reconstructs MCP from extensions
- cagent: new adapter — renders starter default.yaml, import returns empty
- zed: new adapter — merge settings.json, context_servers (MCPZedStyle) + agent.default_model
- docs: append Grounded harness schemas section to design spec
This commit is contained in:
2026-05-23 03:23:02 +01:00
parent a18cb1a4b7
commit 63bd976f4b
25 changed files with 1557 additions and 58 deletions
+19
View File
@@ -0,0 +1,19 @@
package zed
import (
"path/filepath"
"github.com/lukaszraczylo/harness-sync/internal/adapter"
"github.com/lukaszraczylo/harness-sync/internal/adapter/common"
)
func importFrom(home string) (*adapter.ImportResult, error) {
cfgPath := filepath.Join(home, ".config", "zed", "settings.json")
// context_servers entries use source:"custom" for stdio; the MCP command
// field maps directly to canonical MCPServer.Command.
servers, err := common.ImportMCPFromJSONFile(cfgPath, "context_servers")
if err != nil {
return nil, err
}
return &adapter.ImportResult{MCP: servers}, nil
}
+102
View File
@@ -0,0 +1,102 @@
// Package zed is the Zed editor harness adapter.
//
// Zed uses ~/.config/zed/settings.json with many user-managed keys.
// We MERGE only "agent" and "context_servers"; all other keys are preserved.
// MCP servers become context_servers entries with source: "custom".
package zed
import (
"os"
"path/filepath"
"strings"
"github.com/lukaszraczylo/harness-sync/internal/adapter"
"github.com/lukaszraczylo/harness-sync/internal/adapter/common"
"github.com/lukaszraczylo/harness-sync/internal/canonical"
)
const name = "zed"
// Adapter implements adapter.Adapter for the Zed harness.
type Adapter struct{ home string }
// Option configures an Adapter.
type Option func(*Adapter)
// WithHome overrides the home directory (defaults to os.UserHomeDir).
func WithHome(h string) Option { return func(a *Adapter) { a.home = h } }
// New returns a new Adapter with the given options applied.
func New(opts ...Option) *Adapter {
a := &Adapter{home: defaultHome()}
for _, o := range opts {
o(a)
}
return a
}
func defaultHome() string {
h, err := os.UserHomeDir()
if err != nil {
return ""
}
return h
}
// Name returns the harness identifier.
func (a *Adapter) Name() string { return name }
// Detect returns true when ~/.config/zed/ exists.
func (a *Adapter) Detect() bool {
_, err := os.Stat(filepath.Join(a.home, ".config", "zed"))
return err == nil
}
// Render produces the FileSet that applies the canonical bundle to Zed.
// settings.json is MERGED to preserve all user-managed Zed configuration.
// Only "agent" (default_model) and "context_servers" (MCP) are overlaid.
func (a *Adapter) Render(b *canonical.Bundle) (*adapter.FileSet, error) {
fs := adapter.NewFileSet()
cfgPath := filepath.Join(a.home, ".config", "zed", "settings.json")
existing, _ := os.ReadFile(cfgPath)
overlay := map[string]any{
"context_servers": common.BuildMCPMapStyled(&b.MCP, common.MCPZedStyle),
}
if dm := b.Profile.Gateway.DefaultModel; dm != "" {
provider, model := splitProviderModel(dm)
overlay["agent"] = map[string]any{
"default_model": map[string]any{
"provider": provider,
"model": model,
},
}
}
merged, err := common.MergeJSONKeys(existing, overlay)
if err != nil {
return nil, err
}
fs.Add(adapter.File{
Dest: cfgPath,
Kind: adapter.RenderedFile,
Content: merged,
})
return fs, nil
}
// Import reads context_servers from Zed settings.json back to MCP servers.
func (a *Adapter) Import(home string) (*adapter.ImportResult, error) {
return importFrom(home)
}
// splitProviderModel splits "provider/model" at the first slash.
// If no slash, provider is "anthropic".
func splitProviderModel(s string) (string, string) {
if idx := strings.IndexByte(s, '/'); idx >= 0 {
return s[:idx], s[idx+1:]
}
return "anthropic", s
}
+165
View File
@@ -0,0 +1,165 @@
package zed
import (
"encoding/json"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/lukaszraczylo/harness-sync/internal/adapter"
"github.com/lukaszraczylo/harness-sync/internal/canonical"
)
func bundle() *canonical.Bundle {
return &canonical.Bundle{
Profile: canonical.Profile{
Gateway: canonical.Gateway{DefaultModel: "anthropic/claude-sonnet-4-6"},
},
MCP: canonical.MCPRegistry{Servers: []canonical.MCPServer{
{Name: "filepuff", Command: "/bin/filepuff", Args: []string{"--serve"}},
}},
}
}
func TestZedRenderProducesExpectedTargets(t *testing.T) {
home := t.TempDir()
ad := New(WithHome(home))
fs, err := ad.Render(bundle())
require.NoError(t, err)
seen := map[string]adapter.File{}
fs.ForEach(func(f adapter.File) { seen[f.Dest] = f })
cfgDest := filepath.Join(home, ".config", "zed", "settings.json")
require.Contains(t, seen, cfgDest)
assert.Equal(t, adapter.RenderedFile, seen[cfgDest].Kind)
var parsed map[string]any
require.NoError(t, json.Unmarshal(seen[cfgDest].Content, &parsed))
// Agent default_model is an object.
agent := parsed["agent"].(map[string]any)
dm := agent["default_model"].(map[string]any)
assert.Equal(t, "anthropic", dm["provider"])
assert.Equal(t, "claude-sonnet-4-6", dm["model"])
// context_servers.
cs := parsed["context_servers"].(map[string]any)
fp := cs["filepuff"].(map[string]any)
assert.Equal(t, true, fp["enabled"])
assert.Equal(t, "custom", fp["source"])
assert.Equal(t, "/bin/filepuff", fp["command"])
}
func TestZedRenderMergesExistingKeys(t *testing.T) {
home := t.TempDir()
base := filepath.Join(home, ".config", "zed")
require.NoError(t, os.MkdirAll(base, 0o750))
// Existing settings with unrelated user config.
existing := map[string]any{
"theme": "One Dark",
"font_size": 16,
"vim_mode": true,
}
body, _ := json.Marshal(existing)
require.NoError(t, os.WriteFile(filepath.Join(base, "settings.json"), body, 0o600))
ad := New(WithHome(home))
fs, err := ad.Render(bundle())
require.NoError(t, err)
seen := map[string]adapter.File{}
fs.ForEach(func(f adapter.File) { seen[f.Dest] = f })
cfgDest := filepath.Join(base, "settings.json")
var parsed map[string]any
require.NoError(t, json.Unmarshal(seen[cfgDest].Content, &parsed))
// Unrelated keys preserved.
assert.Equal(t, "One Dark", parsed["theme"])
assert.Equal(t, float64(16), parsed["font_size"])
assert.Equal(t, true, parsed["vim_mode"])
// Managed keys present.
assert.Contains(t, parsed, "agent")
assert.Contains(t, parsed, "context_servers")
}
func TestZedRenderNoMCP(t *testing.T) {
home := t.TempDir()
ad := New(WithHome(home))
b := &canonical.Bundle{
Profile: canonical.Profile{
Gateway: canonical.Gateway{DefaultModel: "anthropic/sonnet"},
},
}
fs, err := ad.Render(b)
require.NoError(t, err)
seen := map[string]adapter.File{}
fs.ForEach(func(f adapter.File) { seen[f.Dest] = f })
cfgDest := filepath.Join(home, ".config", "zed", "settings.json")
var parsed map[string]any
require.NoError(t, json.Unmarshal(seen[cfgDest].Content, &parsed))
// context_servers key present but empty map.
cs, ok := parsed["context_servers"]
assert.True(t, ok)
assert.Empty(t, cs)
}
func TestZedImport(t *testing.T) {
home := t.TempDir()
base := filepath.Join(home, ".config", "zed")
require.NoError(t, os.MkdirAll(base, 0o750))
settings := map[string]any{
"context_servers": map[string]any{
"filepuff": map[string]any{
"enabled": true,
"source": "custom",
"command": "/bin/filepuff",
"args": []string{"--serve"},
},
},
}
body, _ := json.Marshal(settings)
require.NoError(t, os.WriteFile(filepath.Join(base, "settings.json"), body, 0o600))
ad := New(WithHome(home))
res, err := ad.Import(home)
require.NoError(t, err)
require.NotNil(t, res)
require.Len(t, res.MCP, 1)
assert.Equal(t, "filepuff", res.MCP[0].Name)
assert.Equal(t, "/bin/filepuff", res.MCP[0].Command)
}
func TestZedImportMissing(t *testing.T) {
ad := New(WithHome(t.TempDir()))
res, err := ad.Import(t.TempDir())
require.NoError(t, err)
assert.NotNil(t, res)
}
func TestZedDetect(t *testing.T) {
home := t.TempDir()
ad := New(WithHome(home))
assert.False(t, ad.Detect())
}
func TestSplitProviderModel(t *testing.T) {
t.Run("with slash", func(t *testing.T) {
p, m := splitProviderModel("anthropic/claude-sonnet-4-6")
assert.Equal(t, "anthropic", p)
assert.Equal(t, "claude-sonnet-4-6", m)
})
t.Run("no slash", func(t *testing.T) {
p, m := splitProviderModel("claude-sonnet")
assert.Equal(t, "anthropic", p)
assert.Equal(t, "claude-sonnet", m)
})
}