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).
124 lines
3.2 KiB
Go
124 lines
3.2 KiB
Go
// 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/adapter/common"
|
|
"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 {
|
|
*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 cagent harness-sync manages.
|
|
func (a *Adapter) Capabilities() adapter.HarnessCapabilities {
|
|
return adapter.HarnessCapabilities{
|
|
ManagesProviders: true,
|
|
ManagesModels: true,
|
|
ManagesMCP: true,
|
|
ManagesSkills: false,
|
|
ManagesRules: true,
|
|
ManagesInstructions: true,
|
|
HasBuiltInSub: false,
|
|
}
|
|
}
|
|
|
|
// 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")
|
|
|
|
// cagent has no rules concept; the per-agent instruction (system prompt) is
|
|
// the only sink, so fold rules into it.
|
|
instructions := b.InstructionTextWithRules(name)
|
|
|
|
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
|
|
}
|
|
|
|
provKey := common.GatewayProviderKey(b.Profile.Gateway.URL)
|
|
// inline model shorthand: "providerID/modelID"
|
|
modelRef := common.KiloModelString(&b.Profile)
|
|
|
|
cfg := map[string]any{
|
|
"version": 8,
|
|
"metadata": map[string]any{
|
|
"name": "harness-sync",
|
|
},
|
|
"agents": map[string]any{
|
|
"default": map[string]any{
|
|
"model": modelRef,
|
|
"instruction": instructions,
|
|
},
|
|
},
|
|
"providers": common.ProvidersAsCagentMap(&b.Profile),
|
|
"models": map[string]any{
|
|
provKey: map[string]any{
|
|
"provider": provKey,
|
|
"model": b.Profile.Gateway.DefaultModel,
|
|
},
|
|
},
|
|
}
|
|
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
|
|
}
|