mirror of
https://github.com/lukaszraczylo/harness-sync.git
synced 2026-10-14 00:57:49 +00:00
feat: sync rules across all harnesses + agents to opencode/kilo
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).
This commit is contained in:
@@ -5,12 +5,23 @@ import (
|
||||
|
||||
"github.com/lukaszraczylo/harness-sync/internal/adapter"
|
||||
"github.com/lukaszraczylo/harness-sync/internal/adapter/common"
|
||||
"github.com/lukaszraczylo/harness-sync/internal/canonical"
|
||||
)
|
||||
|
||||
func importFrom(home string) (*adapter.ImportResult, error) {
|
||||
base := filepath.Join(home, ".config", "opencode")
|
||||
res := &adapter.ImportResult{}
|
||||
|
||||
agents, err := common.ImportMarkdownTree(filepath.Join(base, "agents"), "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, a := range agents {
|
||||
res.Agents = append(res.Agents, canonical.Agent{
|
||||
Name: a.Name, Description: a.Description, Body: a.Body, Path: a.Path,
|
||||
})
|
||||
}
|
||||
|
||||
cfgBody, err := common.ReadIfExists(filepath.Join(base, "opencode.jsonc"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -37,6 +37,8 @@ func (a *Adapter) Capabilities() adapter.HarnessCapabilities {
|
||||
ManagesModels: true,
|
||||
ManagesMCP: true,
|
||||
ManagesSkills: true,
|
||||
ManagesAgents: true,
|
||||
ManagesRules: true,
|
||||
ManagesInstructions: true,
|
||||
HasBuiltInSub: false,
|
||||
}
|
||||
@@ -62,6 +64,12 @@ func (a *Adapter) Render(b *canonical.Bundle) (*adapter.FileSet, error) {
|
||||
Kind: adapter.SymlinkDir,
|
||||
SymlinkTarget: filepath.Join(b.Root, "skills"),
|
||||
})
|
||||
// opencode reads markdown subagents from ~/.config/opencode/agents/<name>.md
|
||||
fs.Add(adapter.File{
|
||||
Dest: filepath.Join(base, "agents"),
|
||||
Kind: adapter.SymlinkDir,
|
||||
SymlinkTarget: filepath.Join(b.Root, "agents"),
|
||||
})
|
||||
|
||||
cfgPath := filepath.Join(base, "opencode.jsonc")
|
||||
existing, err := common.ReadExistingFile(cfgPath)
|
||||
@@ -104,14 +112,12 @@ func (a *Adapter) Render(b *canonical.Bundle) (*adapter.FileSet, error) {
|
||||
Content: merged,
|
||||
})
|
||||
|
||||
instructions := b.Instructions.Global
|
||||
if override, ok := b.Instructions.PerHarness[name]; ok && override != "" {
|
||||
instructions = override
|
||||
}
|
||||
// opencode has no native rules directory; rule content reaches it only via
|
||||
// the global AGENTS.md instructions file, so fold the rules in here.
|
||||
fs.Add(adapter.File{
|
||||
Dest: filepath.Join(base, "AGENTS.md"),
|
||||
Kind: adapter.RenderedFile,
|
||||
Content: []byte(instructions),
|
||||
Content: []byte(b.InstructionTextWithRules(name)),
|
||||
})
|
||||
|
||||
return fs, nil
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package opencode
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/lukaszraczylo/harness-sync/internal/adapter"
|
||||
"github.com/lukaszraczylo/harness-sync/internal/canonical"
|
||||
)
|
||||
|
||||
func TestOpencodeRendersAgentsSymlinkAndFoldsRules(t *testing.T) {
|
||||
home := t.TempDir()
|
||||
ad := New(WithHome(home))
|
||||
b := &canonical.Bundle{
|
||||
Root: "/canon",
|
||||
Instructions: canonical.Instructions{Global: "# global"},
|
||||
Rules: []canonical.Rule{{Name: "go", Body: "# Go\n\ngofmt always"}},
|
||||
}
|
||||
fs, err := ad.Render(b)
|
||||
require.NoError(t, err)
|
||||
|
||||
seen := map[string]adapter.File{}
|
||||
fs.ForEach(func(f adapter.File) { seen[f.Dest] = f })
|
||||
|
||||
agentsDest := filepath.Join(home, ".config", "opencode", "agents")
|
||||
assert.Equal(t, adapter.SymlinkDir, seen[agentsDest].Kind)
|
||||
assert.Equal(t, "/canon/agents", seen[agentsDest].SymlinkTarget)
|
||||
|
||||
agentsMD := filepath.Join(home, ".config", "opencode", "AGENTS.md")
|
||||
assert.Equal(t, adapter.RenderedFile, seen[agentsMD].Kind)
|
||||
body := string(seen[agentsMD].Content)
|
||||
assert.Contains(t, body, "# global")
|
||||
assert.Contains(t, body, "gofmt always")
|
||||
}
|
||||
|
||||
func TestOpencodeImportsAgents(t *testing.T) {
|
||||
home := t.TempDir()
|
||||
agentsDir := filepath.Join(home, ".config", "opencode", "agents")
|
||||
require.NoError(t, os.MkdirAll(agentsDir, 0o750))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(agentsDir, "review.md"),
|
||||
[]byte("---\nname: review\ndescription: d\n---\nbody"), 0o600))
|
||||
|
||||
ad := New(WithHome(home))
|
||||
res, err := ad.Import(home)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res.Agents, 1)
|
||||
assert.Equal(t, "review", res.Agents[0].Name)
|
||||
}
|
||||
Reference in New Issue
Block a user