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:
@@ -0,0 +1,118 @@
|
||||
// Package cagent is the cagent harness adapter.
|
||||
//
|
||||
// cagent is per-run (no persistent agent state). v1 renders a starter
|
||||
// ~/.config/cagent/default.yaml with a single default agent pointing at the
|
||||
// gateway. Import always returns an empty result.
|
||||
package cagent
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/lukaszraczylo/harness-sync/internal/adapter"
|
||||
"github.com/lukaszraczylo/harness-sync/internal/canonical"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
const name = "cagent"
|
||||
|
||||
// Adapter implements adapter.Adapter for the cagent 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/cagent/ exists.
|
||||
func (a *Adapter) Detect() bool {
|
||||
_, err := os.Stat(filepath.Join(a.home, ".config", "cagent"))
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// Render produces a starter default.yaml for cagent.
|
||||
func (a *Adapter) Render(b *canonical.Bundle) (*adapter.FileSet, error) {
|
||||
fs := adapter.NewFileSet()
|
||||
cfgPath := filepath.Join(a.home, ".config", "cagent", "default.yaml")
|
||||
|
||||
instructions := b.Instructions.Global
|
||||
if override, ok := b.Instructions.PerHarness[name]; ok && override != "" {
|
||||
instructions = override
|
||||
}
|
||||
|
||||
mcps := map[string]any{}
|
||||
for _, s := range b.MCP.Servers {
|
||||
e := map[string]any{}
|
||||
if s.Command != "" {
|
||||
e["command"] = s.Command
|
||||
}
|
||||
args := s.Args
|
||||
if args == nil {
|
||||
args = []string{}
|
||||
}
|
||||
e["args"] = args
|
||||
mcps[s.Name] = e
|
||||
}
|
||||
|
||||
cfg := map[string]any{
|
||||
"version": 8,
|
||||
"metadata": map[string]any{
|
||||
"name": "harness-sync",
|
||||
},
|
||||
"agents": map[string]any{
|
||||
"default": map[string]any{
|
||||
"model": "gateway/" + b.Profile.Gateway.DefaultModel,
|
||||
"instruction": instructions,
|
||||
},
|
||||
},
|
||||
"models": map[string]any{
|
||||
"gateway": map[string]any{
|
||||
"provider": "openai", // cagent gateway via openai-compat
|
||||
"base_url": b.Profile.Gateway.URL,
|
||||
},
|
||||
},
|
||||
}
|
||||
if len(mcps) > 0 {
|
||||
cfg["mcps"] = mcps
|
||||
}
|
||||
|
||||
body, err := yaml.Marshal(cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fs.Add(adapter.File{
|
||||
Dest: cfgPath,
|
||||
Kind: adapter.RenderedFile,
|
||||
Content: body,
|
||||
})
|
||||
|
||||
return fs, nil
|
||||
}
|
||||
|
||||
// Import returns an empty result — cagent has no persistent state to import.
|
||||
func (a *Adapter) Import(home string) (*adapter.ImportResult, error) {
|
||||
return &adapter.ImportResult{}, nil
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package cagent
|
||||
|
||||
import (
|
||||
"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{
|
||||
URL: "https://gw",
|
||||
DefaultModel: "claude-sonnet-4-6",
|
||||
},
|
||||
},
|
||||
Instructions: canonical.Instructions{Global: "# global instruction"},
|
||||
MCP: canonical.MCPRegistry{Servers: []canonical.MCPServer{
|
||||
{Name: "filepuff", Command: "/bin/filepuff", Args: []string{"--serve"}},
|
||||
}},
|
||||
}
|
||||
}
|
||||
|
||||
func TestCagentRenderProducesExpectedTargets(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", "cagent", "default.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, 8, parsed["version"])
|
||||
|
||||
agents := parsed["agents"].(map[string]any)
|
||||
def := agents["default"].(map[string]any)
|
||||
assert.Equal(t, "gateway/claude-sonnet-4-6", def["model"])
|
||||
assert.Contains(t, def["instruction"], "# global instruction")
|
||||
|
||||
models := parsed["models"].(map[string]any)
|
||||
gw := models["gateway"].(map[string]any)
|
||||
assert.Equal(t, "openai", gw["provider"])
|
||||
assert.Equal(t, "https://gw", gw["base_url"])
|
||||
|
||||
mcps := parsed["mcps"].(map[string]any)
|
||||
fp := mcps["filepuff"].(map[string]any)
|
||||
assert.Equal(t, "/bin/filepuff", fp["command"])
|
||||
}
|
||||
|
||||
func TestCagentRenderNoMCP(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", "cagent", "default.yaml")
|
||||
var parsed map[string]any
|
||||
require.NoError(t, yaml.Unmarshal(seen[cfgDest].Content, &parsed))
|
||||
assert.NotContains(t, parsed, "mcps")
|
||||
}
|
||||
|
||||
func TestCagentImportReturnsEmpty(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)
|
||||
assert.Empty(t, res.Skills)
|
||||
assert.Empty(t, res.Agents)
|
||||
}
|
||||
|
||||
func TestCagentDetect(t *testing.T) {
|
||||
home := t.TempDir()
|
||||
ad := New(WithHome(home))
|
||||
assert.False(t, ad.Detect())
|
||||
}
|
||||
Reference in New Issue
Block a user