mirror of
https://github.com/lukaszraczylo/harness-sync.git
synced 2026-10-14 00:57:49 +00:00
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:
@@ -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 = "claude-code"
|
||||
@@ -51,6 +50,9 @@ func (a *Adapter) Detect() bool {
|
||||
}
|
||||
|
||||
// Render produces the FileSet that applies the canonical bundle to claude-code.
|
||||
// settings.json is MERGED into any existing file so user-managed keys
|
||||
// settings.json is MERGED into any existing file so user-managed keys
|
||||
// (hooks, permissions, env, …) are preserved.
|
||||
func (a *Adapter) Render(b *canonical.Bundle) (*adapter.FileSet, error) {
|
||||
fs := adapter.NewFileSet()
|
||||
base := filepath.Join(a.home, ".claude")
|
||||
@@ -76,25 +78,24 @@ func (a *Adapter) Render(b *canonical.Bundle) (*adapter.FileSet, error) {
|
||||
Content: []byte(instructions),
|
||||
})
|
||||
|
||||
settings, err := renderSettings(b)
|
||||
settingsPath := filepath.Join(base, "settings.json")
|
||||
existing, _ := os.ReadFile(settingsPath)
|
||||
overlay := map[string]any{
|
||||
"mcpServers": common.BuildMCPMapStyled(&b.MCP, common.MCPClaudeStyle),
|
||||
}
|
||||
merged, err := common.MergeJSONKeys(existing, overlay)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fs.Add(adapter.File{
|
||||
Dest: filepath.Join(base, "settings.json"),
|
||||
Dest: settingsPath,
|
||||
Kind: adapter.RenderedFile,
|
||||
Content: settings,
|
||||
Content: merged,
|
||||
})
|
||||
|
||||
return fs, nil
|
||||
}
|
||||
|
||||
func renderSettings(b *canonical.Bundle) ([]byte, error) {
|
||||
return render.JSON(map[string]any{
|
||||
"mcpServers": common.BuildMCPMap(&b.MCP),
|
||||
})
|
||||
}
|
||||
|
||||
// Import reads claude-code config from home and returns a canonical ImportResult.
|
||||
func (a *Adapter) Import(home string) (*adapter.ImportResult, error) {
|
||||
return importFrom(home)
|
||||
|
||||
@@ -48,6 +48,48 @@ func TestRenderProducesExpectedTargets(t *testing.T) {
|
||||
assert.Contains(t, settingsBody, "filepuff")
|
||||
assert.Contains(t, settingsBody, "/bin/filepuff")
|
||||
}
|
||||
func TestRenderMergesExistingSettings(t *testing.T) {
|
||||
home := t.TempDir()
|
||||
base := filepath.Join(home, ".claude")
|
||||
require.NoError(t, os.MkdirAll(base, 0o750))
|
||||
|
||||
// Existing settings.json with user-managed keys.
|
||||
existing := map[string]any{
|
||||
"hooks": map[string]any{"preToolUse": []string{"/bin/hook"}},
|
||||
"permissions": map[string]any{"allow": []string{"Bash"}},
|
||||
"env": map[string]any{"ANTHROPIC_DEFAULT_MODEL": "opus"},
|
||||
}
|
||||
body, _ := json.Marshal(existing)
|
||||
require.NoError(t, os.WriteFile(filepath.Join(base, "settings.json"), body, 0o600))
|
||||
|
||||
ad := New(WithHome(home))
|
||||
b := &canonical.Bundle{
|
||||
Root: "/canon",
|
||||
MCP: canonical.MCPRegistry{Servers: []canonical.MCPServer{
|
||||
{Name: "filepuff", Command: "/bin/filepuff"},
|
||||
}},
|
||||
}
|
||||
fs, err := ad.Render(b)
|
||||
require.NoError(t, err)
|
||||
|
||||
seen := map[string]adapter.File{}
|
||||
fs.ForEach(func(f adapter.File) { seen[f.Dest] = f })
|
||||
|
||||
settingsDest := filepath.Join(base, "settings.json")
|
||||
var parsed map[string]any
|
||||
require.NoError(t, json.Unmarshal(seen[settingsDest].Content, &parsed))
|
||||
|
||||
// User keys preserved.
|
||||
assert.Contains(t, parsed, "hooks")
|
||||
assert.Contains(t, parsed, "permissions")
|
||||
assert.Contains(t, parsed, "env")
|
||||
// MCP updated.
|
||||
mcp := parsed["mcpServers"].(map[string]any)
|
||||
assert.Contains(t, mcp, "filepuff")
|
||||
// MCP entries must NOT have a "type" field (claude-code style).
|
||||
fp := mcp["filepuff"].(map[string]any)
|
||||
assert.NotContains(t, fp, "type")
|
||||
}
|
||||
|
||||
func TestImport(t *testing.T) {
|
||||
home := t.TempDir()
|
||||
|
||||
Reference in New Issue
Block a user