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:
2026-06-16 21:32:12 +01:00
parent 0892cb317e
commit f30c0f65a6
28 changed files with 705 additions and 37 deletions
+11 -5
View File
@@ -37,6 +37,8 @@ func (a *Adapter) Capabilities() adapter.HarnessCapabilities {
ManagesModels: false,
ManagesMCP: true,
ManagesSkills: true,
ManagesAgents: true,
ManagesRules: true,
ManagesInstructions: true,
HasBuiltInSub: true,
}
@@ -65,15 +67,19 @@ func (a *Adapter) Render(b *canonical.Bundle) (*adapter.FileSet, error) {
Kind: adapter.SymlinkDir,
SymlinkTarget: filepath.Join(b.Root, "agents"),
})
// Claude Code natively auto-loads ~/.claude/rules/*.md (memory feature), so
// rules are delivered as their own directory symlink — NOT folded into
// CLAUDE.md — preserving each rule's optional path-scoping frontmatter.
fs.Add(adapter.File{
Dest: filepath.Join(base, "rules"),
Kind: adapter.SymlinkDir,
SymlinkTarget: filepath.Join(b.Root, "rules"),
})
instructions := b.Instructions.Global
if override, ok := b.Instructions.PerHarness[name]; ok && override != "" {
instructions = override
}
fs.Add(adapter.File{
Dest: filepath.Join(base, "CLAUDE.md"),
Kind: adapter.RenderedFile,
Content: []byte(instructions),
Content: []byte(b.InstructionText(name)),
})
// Claude Code reads MCP servers from two files on disk:
+10
View File
@@ -32,6 +32,16 @@ func importFrom(home string) (*adapter.ImportResult, error) {
})
}
rules, err := common.ImportMarkdownTree(filepath.Join(base, "rules"), "")
if err != nil {
return nil, err
}
for _, r := range rules {
res.Rules = append(res.Rules, canonical.Rule{
Name: r.Name, Description: r.Description, Body: r.Body, Path: r.Path,
})
}
body, err := common.ReadIfExists(filepath.Join(base, "CLAUDE.md"))
if err != nil {
return nil, err
@@ -0,0 +1,47 @@
package claudecode
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 TestClaudeCodeRendersRulesSymlink(t *testing.T) {
home := t.TempDir()
ad := New(WithHome(home))
b := &canonical.Bundle{Root: "/canon"}
fs, err := ad.Render(b)
require.NoError(t, err)
seen := map[string]adapter.File{}
fs.ForEach(func(f adapter.File) { seen[f.Dest] = f })
rulesDest := filepath.Join(home, ".claude", "rules")
assert.Equal(t, adapter.SymlinkDir, seen[rulesDest].Kind)
assert.Equal(t, "/canon/rules", seen[rulesDest].SymlinkTarget)
// Rules are delivered natively as a directory — never folded into CLAUDE.md.
claudemd := string(seen[filepath.Join(home, ".claude", "CLAUDE.md")].Content)
assert.NotContains(t, claudemd, "/canon/rules")
}
func TestClaudeCodeImportsRules(t *testing.T) {
home := t.TempDir()
rulesDir := filepath.Join(home, ".claude", "rules")
require.NoError(t, os.MkdirAll(rulesDir, 0o750))
require.NoError(t, os.WriteFile(filepath.Join(rulesDir, "go.md"),
[]byte("# Go Rules\n\ngofmt always"), 0o600))
ad := New(WithHome(home))
res, err := ad.Import(home)
require.NoError(t, err)
require.Len(t, res.Rules, 1)
assert.Equal(t, "go", res.Rules[0].Name)
assert.Contains(t, res.Rules[0].Body, "gofmt always")
}