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).
103 lines
2.9 KiB
Go
103 lines
2.9 KiB
Go
package canonical
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestInstructionText(t *testing.T) {
|
|
t.Run("global when no override", func(t *testing.T) {
|
|
t.Parallel()
|
|
b := Bundle{Instructions: Instructions{Global: "G"}}
|
|
assert.Equal(t, "G", b.InstructionText("zed"))
|
|
})
|
|
t.Run("per-harness override wins", func(t *testing.T) {
|
|
t.Parallel()
|
|
b := Bundle{Instructions: Instructions{Global: "G", PerHarness: map[string]string{"zed": "Z"}}}
|
|
assert.Equal(t, "Z", b.InstructionText("zed"))
|
|
})
|
|
t.Run("empty override falls back to global", func(t *testing.T) {
|
|
t.Parallel()
|
|
b := Bundle{Instructions: Instructions{Global: "G", PerHarness: map[string]string{"zed": ""}}}
|
|
assert.Equal(t, "G", b.InstructionText("zed"))
|
|
})
|
|
t.Run("empty everything", func(t *testing.T) {
|
|
t.Parallel()
|
|
b := Bundle{}
|
|
assert.Equal(t, "", b.InstructionText("zed"))
|
|
})
|
|
}
|
|
|
|
func TestInstructionTextWithRules(t *testing.T) {
|
|
t.Run("folds rules after global", func(t *testing.T) {
|
|
t.Parallel()
|
|
b := Bundle{
|
|
Instructions: Instructions{Global: "# Global"},
|
|
Rules: []Rule{
|
|
{Name: "a", Body: "# Rule A\n\nbe concise"},
|
|
{Name: "b", Body: "# Rule B\n\nbe safe"},
|
|
},
|
|
}
|
|
got := b.InstructionTextWithRules("opencode")
|
|
assert.Equal(t, "# Global\n\n# Rule A\n\nbe concise\n\n# Rule B\n\nbe safe", got)
|
|
})
|
|
|
|
t.Run("strips rule frontmatter", func(t *testing.T) {
|
|
t.Parallel()
|
|
b := Bundle{
|
|
Instructions: Instructions{Global: "G"},
|
|
Rules: []Rule{
|
|
{Name: "scoped", Body: "---\nname: scoped\npaths: \"**/*.go\"\n---\n# Go\n\ngofmt"},
|
|
},
|
|
}
|
|
got := b.InstructionTextWithRules("opencode")
|
|
assert.Equal(t, "G\n\n# Go\n\ngofmt", got)
|
|
assert.NotContains(t, got, "paths:")
|
|
assert.NotContains(t, got, "---")
|
|
})
|
|
|
|
t.Run("no rules returns plain instruction text", func(t *testing.T) {
|
|
t.Parallel()
|
|
b := Bundle{Instructions: Instructions{Global: "G"}}
|
|
assert.Equal(t, "G", b.InstructionTextWithRules("opencode"))
|
|
})
|
|
|
|
t.Run("empty global still emits rules", func(t *testing.T) {
|
|
t.Parallel()
|
|
b := Bundle{Rules: []Rule{{Name: "a", Body: "rule body"}}}
|
|
assert.Equal(t, "rule body", b.InstructionTextWithRules("opencode"))
|
|
})
|
|
|
|
t.Run("blank rule bodies are skipped", func(t *testing.T) {
|
|
t.Parallel()
|
|
b := Bundle{
|
|
Instructions: Instructions{Global: "G"},
|
|
Rules: []Rule{
|
|
{Name: "empty", Body: " \n "},
|
|
{Name: "real", Body: "keep"},
|
|
},
|
|
}
|
|
assert.Equal(t, "G\n\nkeep", b.InstructionTextWithRules("opencode"))
|
|
})
|
|
}
|
|
|
|
func TestStripFrontmatter(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
in string
|
|
want string
|
|
}{
|
|
{"no frontmatter", "# Title\nbody", "# Title\nbody"},
|
|
{"with frontmatter", "---\nname: x\n---\n# Title", "# Title"},
|
|
{"unterminated frontmatter left intact", "---\nname: x\nbody", "---\nname: x\nbody"},
|
|
{"empty", "", ""},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
assert.Equal(t, tt.want, stripFrontmatter(tt.in))
|
|
})
|
|
}
|
|
}
|