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
+135
View File
@@ -0,0 +1,135 @@
// Package goose is the Goose (Block/square) harness adapter.
//
// Goose uses ~/.config/goose/config.yaml with a flat top-level structure.
// MCP-equivalent servers go under "extensions" (not "mcp").
// Model is split into GOOSE_PROVIDER + GOOSE_MODEL.
//
// Custom provider files (~/.config/goose/custom_providers/<name>.yaml) are
// out of v1 scope. If a gateway URL is configured we set GOOSE_PROVIDER to
// signal the intent; the user must hand-write the custom_providers file.
package goose
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 = "goose"
// Adapter implements adapter.Adapter for the Goose 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/goose/ exists.
func (a *Adapter) Detect() bool {
_, err := os.Stat(filepath.Join(a.home, ".config", "goose"))
return err == nil
}
// Render produces the FileSet that applies the canonical bundle to goose.
// config.yaml is MERGED; only GOOSE_PROVIDER, GOOSE_MODEL, and the
// managed extension entries are overlaid.
func (a *Adapter) Render(b *canonical.Bundle) (*adapter.FileSet, error) {
fs := adapter.NewFileSet()
cfgPath := filepath.Join(a.home, ".config", "goose", "config.yaml")
existing, _ := os.ReadFile(cfgPath)
provider, model := splitProviderModel(b.Profile.Gateway.DefaultModel)
if b.Profile.Gateway.URL != "" {
// Custom gateway: signal with provider name. User must create
// ~/.config/goose/custom_providers/harness-sync.yaml manually.
provider = "harness-sync"
}
overlay := map[string]any{
"GOOSE_PROVIDER": provider,
"GOOSE_MODEL": model,
}
if len(b.MCP.Servers) > 0 {
extensions := buildExtensions(b.MCP.Servers)
overlay["extensions"] = extensions
}
merged, err := common.MergeYAMLKeys(existing, overlay)
if err != nil {
return nil, err
}
fs.Add(adapter.File{
Dest: cfgPath,
Kind: adapter.RenderedFile,
Content: merged,
})
return fs, nil
}
// buildExtensions converts canonical MCP servers to goose extension entries.
func buildExtensions(servers []canonical.MCPServer) map[string]any {
out := map[string]any{}
for _, s := range servers {
e := map[string]any{
"enabled": true,
"type": "stdio",
}
if s.Command != "" {
e["cmd"] = s.Command
}
args := s.Args
if args == nil {
args = []string{}
}
e["args"] = args
if len(s.Env) > 0 {
e["env"] = s.Env
}
out[s.Name] = e
}
return out
}
// splitProviderModel splits "provider/model" into its parts.
// If no slash, provider is "anthropic" and the whole string is the model.
func splitProviderModel(s string) (string, string) {
if idx := strings.IndexByte(s, '/'); idx >= 0 {
return s[:idx], s[idx+1:]
}
return "anthropic", s
}
// Import reads goose config from home and returns a canonical ImportResult.
func (a *Adapter) Import(home string) (*adapter.ImportResult, error) {
return importFrom(home)
}
+145
View File
@@ -0,0 +1,145 @@
package goose
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
"github.com/lukaszraczylo/harness-sync/internal/adapter"
"github.com/lukaszraczylo/harness-sync/internal/canonical"
)
func bundle() *canonical.Bundle {
return &canonical.Bundle{
Root: "/canon",
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 TestGooseRenderProducesExpectedTargets(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", "goose", "config.yaml")
require.Contains(t, seen, cfgDest)
assert.Equal(t, adapter.RenderedFile, seen[cfgDest].Kind)
var parsed map[string]any
require.NoError(t, yaml.Unmarshal(seen[cfgDest].Content, &parsed))
assert.Equal(t, "anthropic", parsed["GOOSE_PROVIDER"])
assert.Equal(t, "claude-sonnet-4-6", parsed["GOOSE_MODEL"])
assert.Contains(t, parsed, "extensions")
exts := parsed["extensions"].(map[string]any)
fp := exts["filepuff"].(map[string]any)
assert.Equal(t, "stdio", fp["type"])
assert.Equal(t, "/bin/filepuff", fp["cmd"])
}
func TestGooseRenderMergesExistingKeys(t *testing.T) {
home := t.TempDir()
base := filepath.Join(home, ".config", "goose")
require.NoError(t, os.MkdirAll(base, 0o750))
require.NoError(t, os.WriteFile(filepath.Join(base, "config.yaml"),
[]byte("GOOSE_TEMPERATURE: \"0.7\"\nGOOSE_PROVIDER: old\n"), 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 })
var parsed map[string]any
require.NoError(t, yaml.Unmarshal(seen[filepath.Join(base, "config.yaml")].Content, &parsed))
// Existing unrelated key preserved.
assert.Equal(t, "0.7", parsed["GOOSE_TEMPERATURE"])
// Provider updated.
assert.Equal(t, "anthropic", parsed["GOOSE_PROVIDER"])
}
func TestGooseRenderGatewayURL(t *testing.T) {
home := t.TempDir()
ad := New(WithHome(home))
b := &canonical.Bundle{
Profile: canonical.Profile{
Gateway: canonical.Gateway{URL: "https://gw", 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(home, ".config", "goose", "config.yaml")
var parsed map[string]any
require.NoError(t, yaml.Unmarshal(seen[cfgDest].Content, &parsed))
// Custom gateway → provider is "harness-sync" (user must write custom_providers file).
assert.Equal(t, "harness-sync", parsed["GOOSE_PROVIDER"])
}
func TestGooseImport(t *testing.T) {
home := t.TempDir()
base := filepath.Join(home, ".config", "goose")
require.NoError(t, os.MkdirAll(base, 0o750))
cfg := map[string]any{
"GOOSE_PROVIDER": "anthropic",
"GOOSE_MODEL": "claude-sonnet-4-6",
"extensions": map[string]any{
"filepuff": map[string]any{
"type": "stdio",
"cmd": "/bin/filepuff",
"args": []string{"--serve"},
"enabled": true,
},
},
}
body, err := yaml.Marshal(cfg)
require.NoError(t, err)
require.NoError(t, os.WriteFile(filepath.Join(base, "config.yaml"), 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 TestGooseImportMissing(t *testing.T) {
ad := New(WithHome(t.TempDir()))
res, err := ad.Import(t.TempDir())
require.NoError(t, err)
assert.NotNil(t, res)
assert.Empty(t, res.MCP)
}
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)
})
}
+67
View File
@@ -0,0 +1,67 @@
package goose
import (
"os"
"path/filepath"
"gopkg.in/yaml.v3"
"github.com/lukaszraczylo/harness-sync/internal/adapter"
"github.com/lukaszraczylo/harness-sync/internal/canonical"
)
func importFrom(home string) (*adapter.ImportResult, error) {
cfgPath := filepath.Join(home, ".config", "goose", "config.yaml")
body, err := os.ReadFile(cfgPath)
if os.IsNotExist(err) {
return &adapter.ImportResult{}, nil
}
if err != nil {
return nil, err
}
var raw map[string]any
if err := yaml.Unmarshal(body, &raw); err != nil {
return &adapter.ImportResult{}, nil
}
res := &adapter.ImportResult{}
// Reconstruct MCP servers from extensions entries with type: stdio.
if exts, ok := raw["extensions"]; ok {
if extMap, ok := exts.(map[string]any); ok {
for name, v := range extMap {
entry, ok := v.(map[string]any)
if !ok {
continue
}
t, _ := entry["type"].(string)
if t != "stdio" {
continue
}
s := canonical.MCPServer{Name: name}
if cmd, ok := entry["cmd"].(string); ok {
s.Command = cmd
}
if args, ok := entry["args"].([]any); ok {
for _, a := range args {
if str, ok := a.(string); ok {
s.Args = append(s.Args, str)
}
}
}
if envRaw, ok := entry["env"].(map[string]any); ok {
s.Env = make(map[string]string, len(envRaw))
for k, val := range envRaw {
if str, ok := val.(string); ok {
s.Env[k] = str
}
}
}
res.MCP = append(res.MCP, s)
}
}
}
return res, nil
}