mirror of
https://github.com/lukaszraczylo/harness-sync.git
synced 2026-10-12 00:45:22 +00:00
Add Rule as a first-class canonical kind (rules/<name>.md, loaded like agents) and propagate it the way each harness actually loads it: - claude-code: native ~/.claude/rules directory symlink (preserves rule path-scoping frontmatter); rules NOT folded into CLAUDE.md. - opencode/kilo/zed/crush: fold rule bodies into the global AGENTS.md always-on instructions file (frontmatter stripped). crush has no global instructions file, so register the absolute AGENTS.md path in options.context_paths (defaults are re-prepended at load, so nothing is clobbered). - goose: fold into ~/.config/goose/.goosehints. - cagent: fold into the per-agent instruction. Also: - Wire markdown agents to opencode (~/.config/opencode/agents) and fix the kilo agents symlink: plural ~/.config/kilo/agents (singular "agent" is a silent no-op on current Kilo CLI). - Add ManagesAgents/ManagesRules to HarnessCapabilities + ImportResult.Rules; claude-code/opencode import rules/agents round-trip. - Centralize instruction selection in Bundle.InstructionText / InstructionTextWithRules (replaces per-adapter override duplication). - init scaffolds + imports rules; README capability matrix gains Agents/Rules columns with native-vs-folded footnotes. Grounded each harness's sink against official docs + config source this session. Gate: gofmt, go vet, go test -race ./..., golangci-lint (0), govulncheck (clean).
167 lines
4.7 KiB
Go
167 lines
4.7 KiB
Go
// 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.
|
|
//
|
|
// When a gateway URL is configured we:
|
|
// - Write ~/.config/goose/custom_providers/<providerName>.json
|
|
// - Set GOOSE_PROVIDER to <providerName> in config.yaml
|
|
package goose
|
|
|
|
import (
|
|
"fmt"
|
|
"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 {
|
|
*adapter.Base
|
|
}
|
|
|
|
// WithHome overrides the home directory used to resolve target paths.
|
|
func WithHome(h string) adapter.BaseOption { return func(b *adapter.Base) { b.Home = h } }
|
|
|
|
// New returns a new Adapter with the given options applied.
|
|
func New(opts ...adapter.BaseOption) *Adapter {
|
|
return &Adapter{Base: adapter.NewBase(opts...)}
|
|
}
|
|
|
|
// Name returns the harness identifier.
|
|
func (a *Adapter) Name() string { return name }
|
|
|
|
// Capabilities declares what goose harness-sync manages.
|
|
func (a *Adapter) Capabilities() adapter.HarnessCapabilities {
|
|
return adapter.HarnessCapabilities{
|
|
ManagesProviders: true,
|
|
ManagesModels: true,
|
|
ManagesMCP: true,
|
|
ManagesSkills: true,
|
|
ManagesRules: true,
|
|
ManagesInstructions: true,
|
|
HasBuiltInSub: false,
|
|
}
|
|
}
|
|
|
|
// 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.
|
|
// When Gateway.URL is set, a custom_providers/<providerName>.json file is
|
|
// also added to the FileSet so goose can load the provider on first run.
|
|
func (a *Adapter) Render(b *canonical.Bundle) (*adapter.FileSet, error) {
|
|
fs := adapter.NewFileSet()
|
|
cfgPath := filepath.Join(a.Home, ".config", "goose", "config.yaml")
|
|
|
|
// goose reads skills from ~/.agents/skills/<name>/SKILL.md (open Agent Skills spec)
|
|
fs.Add(adapter.File{
|
|
Dest: filepath.Join(a.Home, ".agents", "skills"),
|
|
Kind: adapter.SymlinkDir,
|
|
SymlinkTarget: filepath.Join(b.Root, "skills"),
|
|
})
|
|
|
|
existing, err := common.ReadExistingFile(cfgPath)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("read %s: %w", cfgPath, err)
|
|
}
|
|
|
|
provider, model := splitProviderModel(b.Profile.Gateway.DefaultModel)
|
|
if b.Profile.Gateway.URL != "" {
|
|
// Emit the custom provider JSON file.
|
|
body, providerName := common.GooseCustomProviderFile(&b.Profile)
|
|
if body != nil {
|
|
cpDir := filepath.Join(a.Home, ".config", "goose", "custom_providers")
|
|
fs.Add(adapter.File{
|
|
Dest: filepath.Join(cpDir, providerName+".json"),
|
|
Kind: adapter.RenderedFile,
|
|
Content: body,
|
|
})
|
|
provider = providerName
|
|
}
|
|
}
|
|
|
|
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,
|
|
})
|
|
|
|
// goose has no native rules directory; ~/.config/goose/.goosehints is the
|
|
// global hints file applied to every session, so fold rules into it.
|
|
if hints := b.InstructionTextWithRules(name); hints != "" {
|
|
fs.Add(adapter.File{
|
|
Dest: filepath.Join(a.Home, ".config", "goose", ".goosehints"),
|
|
Kind: adapter.RenderedFile,
|
|
Content: []byte(hints),
|
|
})
|
|
}
|
|
|
|
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 p, m, ok := strings.Cut(s, "/"); ok {
|
|
return p, m
|
|
}
|
|
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)
|
|
}
|