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
+14 -15
View File
@@ -8,7 +8,6 @@ import (
"github.com/lukaszraczylo/harness-sync/internal/adapter"
"github.com/lukaszraczylo/harness-sync/internal/adapter/common"
"github.com/lukaszraczylo/harness-sync/internal/canonical"
"github.com/lukaszraczylo/harness-sync/internal/render"
)
const name = "crush"
@@ -49,6 +48,8 @@ func (a *Adapter) Detect() bool {
}
// Render produces the FileSet that applies the canonical bundle to crush.
// crush.json is MERGED so user-managed keys ($schema, lsp, options, permissions) are preserved.
// MCP key is "mcp" (not "mcpServers"); entries include a "type" field.
func (a *Adapter) Render(b *canonical.Bundle) (*adapter.FileSet, error) {
fs := adapter.NewFileSet()
base := filepath.Join(a.home, ".config", "crush")
@@ -59,30 +60,28 @@ func (a *Adapter) Render(b *canonical.Bundle) (*adapter.FileSet, error) {
SymlinkTarget: filepath.Join(b.Root, "skills"),
})
cfg, err := renderConfig(b)
cfgPath := filepath.Join(base, "crush.json")
existing, _ := os.ReadFile(cfgPath)
overlay := map[string]any{
"providers": common.BuildProviders(&b.Profile),
"default_model": b.Profile.Gateway.DefaultModel,
}
if mcp := common.BuildMCPMapStyled(&b.MCP, common.MCPCrushStyle); len(mcp) > 0 {
overlay["mcp"] = mcp
}
merged, err := common.MergeJSONKeys(existing, overlay)
if err != nil {
return nil, err
}
fs.Add(adapter.File{
Dest: filepath.Join(base, "crush.json"),
Dest: cfgPath,
Kind: adapter.RenderedFile,
Content: cfg,
Content: merged,
})
return fs, nil
}
func renderConfig(b *canonical.Bundle) ([]byte, error) {
out := map[string]any{
"providers": common.BuildProviders(&b.Profile),
"default_model": b.Profile.Gateway.DefaultModel,
}
if mcp := common.BuildMCPMap(&b.MCP); len(mcp) > 0 {
out["mcpServers"] = mcp
}
return render.JSON(out)
}
// Import reads crush config from home and returns a canonical ImportResult.
func (a *Adapter) Import(home string) (*adapter.ImportResult, error) {
return importFrom(home)
+63 -1
View File
@@ -40,9 +40,71 @@ func TestCrushRenderProducesExpectedTargets(t *testing.T) {
// Parse rendered JSON to verify structure.
var parsed map[string]any
require.NoError(t, json.Unmarshal(seen[cfgDest].Content, &parsed))
assert.NotNil(t, parsed) // at least it's valid JSON
assert.NotNil(t, parsed)
// Must use "default_model", not "model".
assert.Contains(t, parsed, "default_model")
// Must not write "mcpServers" — crush uses "mcp".
assert.NotContains(t, parsed, "mcpServers")
}
func TestCrushRenderMCPHasType(t *testing.T) {
home := t.TempDir()
ad := New(WithHome(home))
b := &canonical.Bundle{
Root: "/canon",
Profile: canonical.Profile{
Gateway: canonical.Gateway{DefaultModel: "sonnet"},
},
MCP: canonical.MCPRegistry{Servers: []canonical.MCPServer{
{Name: "fp", Command: "/bin/fp"},
}},
}
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", "crush", "crush.json")
var parsed map[string]any
require.NoError(t, json.Unmarshal(seen[cfgDest].Content, &parsed))
mcp := parsed["mcp"].(map[string]any)
fp := mcp["fp"].(map[string]any)
// Each MCP entry must have a "type" field.
assert.Equal(t, "stdio", fp["type"])
}
func TestCrushRenderMergesExistingKeys(t *testing.T) {
home := t.TempDir()
base := filepath.Join(home, ".config", "crush")
require.NoError(t, os.MkdirAll(base, 0o750))
existing := map[string]any{
"$schema": "https://crush.schema/v1",
"lsp": []string{"gopls"},
"permissions": map[string]any{"allow": []string{"Bash"}},
}
body, _ := json.Marshal(existing)
require.NoError(t, os.WriteFile(filepath.Join(base, "crush.json"), body, 0o600))
ad := New(WithHome(home))
b := &canonical.Bundle{
Profile: canonical.Profile{
Gateway: canonical.Gateway{DefaultModel: "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(base, "crush.json")
var parsed map[string]any
require.NoError(t, json.Unmarshal(seen[cfgDest].Content, &parsed))
// Unrelated user keys preserved.
assert.Equal(t, "https://crush.schema/v1", parsed["$schema"])
assert.Contains(t, parsed, "lsp")
assert.Contains(t, parsed, "permissions")
}
func TestCrushImportRoundtrip(t *testing.T) {
home := t.TempDir()
base := filepath.Join(home, ".config", "crush")
+1 -1
View File
@@ -9,7 +9,7 @@ import (
func importFrom(home string) (*adapter.ImportResult, error) {
cfgPath := filepath.Join(home, ".config", "crush", "crush.json")
servers, err := common.ImportMCPFromJSONFile(cfgPath, "mcpServers")
servers, err := common.ImportMCPFromJSONFile(cfgPath, "mcp")
if err != nil {
return nil, err
}