mirror of
https://github.com/lukaszraczylo/harness-sync.git
synced 2026-10-17 01:17:35 +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:
@@ -0,0 +1,34 @@
|
||||
package common
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
// MergeJSONKeys reads existing JSON/JSONC body, overlays the given top-level
|
||||
// keys (replacing values for listed keys, preserving every other key), and
|
||||
// returns the merged JSON. If existing is empty or invalid JSON the function
|
||||
// returns just the overlay encoded fresh (2-space indent + trailing \n).
|
||||
// An overlay value of nil deletes the key from the base.
|
||||
func MergeJSONKeys(existing []byte, overlay map[string]any) ([]byte, error) {
|
||||
base := map[string]any{}
|
||||
if len(existing) > 0 {
|
||||
// Try plain JSON first (avoids mangling URL strings that contain //).
|
||||
// Only fall back to comment-stripping for JSONC content.
|
||||
if err := json.Unmarshal(existing, &base); err != nil {
|
||||
clean := StripJSONComments(string(existing))
|
||||
if err2 := json.Unmarshal([]byte(clean), &base); err2 != nil {
|
||||
base = map[string]any{}
|
||||
}
|
||||
}
|
||||
}
|
||||
for k, v := range overlay {
|
||||
if v == nil {
|
||||
delete(base, k)
|
||||
continue
|
||||
}
|
||||
base[k] = v
|
||||
}
|
||||
out, err := json.MarshalIndent(base, "", " ")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return append(out, '\n'), nil
|
||||
}
|
||||
Reference in New Issue
Block a user