mirror of
https://github.com/lukaszraczylo/harness-sync.git
synced 2026-10-13 00:48:30 +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:
+25
-3
@@ -93,6 +93,7 @@ func runImport(cmd *cobra.Command, reg *adapter.Registry, root, home string, pic
|
||||
}
|
||||
seenSkills := map[string]bool{}
|
||||
seenAgents := map[string]bool{}
|
||||
seenRules := map[string]bool{}
|
||||
seenMCP := map[string]bool{}
|
||||
var instructions []string
|
||||
|
||||
@@ -121,6 +122,14 @@ func runImport(cmd *cobra.Command, reg *adapter.Registry, root, home string, pic
|
||||
seenAgents[key] = true
|
||||
bundle.Agents = append(bundle.Agents, a)
|
||||
}
|
||||
for _, r := range res.Rules {
|
||||
key := r.Name + "|" + r.Body
|
||||
if seenRules[key] {
|
||||
continue
|
||||
}
|
||||
seenRules[key] = true
|
||||
bundle.Rules = append(bundle.Rules, r)
|
||||
}
|
||||
for _, m := range res.MCP {
|
||||
if seenMCP[m.Name] {
|
||||
continue
|
||||
@@ -153,8 +162,8 @@ func runImport(cmd *cobra.Command, reg *adapter.Registry, root, home string, pic
|
||||
return err
|
||||
}
|
||||
_, _ = fmt.Fprintf(cmd.OutOrStdout(),
|
||||
"imported from %v into %s\n skills: %d\n agents: %d\n mcp servers: %d\n instructions: %d source(s)\n",
|
||||
picked, root, len(bundle.Skills), len(bundle.Agents), len(bundle.MCP.Servers), len(instructions),
|
||||
"imported from %v into %s\n skills: %d\n agents: %d\n rules: %d\n mcp servers: %d\n instructions: %d source(s)\n",
|
||||
picked, root, len(bundle.Skills), len(bundle.Agents), len(bundle.Rules), len(bundle.MCP.Servers), len(instructions),
|
||||
)
|
||||
return nil
|
||||
}
|
||||
@@ -172,7 +181,7 @@ const importedProfileBody = "# harness-sync profile \xe2\x80\x94 generated by in
|
||||
"models: []\n"
|
||||
|
||||
func writeCanonical(root string, b *canonical.Bundle, picked []string) error {
|
||||
for _, sub := range []string{"profiles", "skills", "agents", "instructions"} {
|
||||
for _, sub := range []string{"profiles", "skills", "agents", "rules", "instructions"} {
|
||||
if err := os.MkdirAll(filepath.Join(root, sub), 0o750); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -233,6 +242,19 @@ func writeCanonical(root string, b *canonical.Bundle, picked []string) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, r := range b.Rules {
|
||||
rel := r.Path
|
||||
if rel == "" {
|
||||
rel = safeFilename(r.Name) + ".md"
|
||||
}
|
||||
path := filepath.Join(root, "rules", rel)
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o750); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.WriteFile(path, []byte(r.Body), 0o600); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if b.Instructions.Global != "" {
|
||||
if err := os.WriteFile(filepath.Join(root, "instructions", "global.md"),
|
||||
[]byte(b.Instructions.Global), 0o600); err != nil {
|
||||
|
||||
@@ -53,6 +53,34 @@ func TestInitImportWritesCanonical(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestInitImportsRules(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
home := t.TempDir()
|
||||
|
||||
reg := adapter.NewRegistry()
|
||||
reg.Register(&importableAdapter{
|
||||
name: "stub",
|
||||
res: &adapter.ImportResult{
|
||||
Rules: []canonical.Rule{
|
||||
{Name: "go", Body: "# Go\n\ngofmt", Path: "go.md"},
|
||||
{Name: "py", Body: "# Py\n\ntypes", Path: "py.md"},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
cmd := NewInit(reg)
|
||||
cmd.SetArgs([]string{"--root", root, "--home", home, "--from", "stub", "--no-prompt"})
|
||||
require.NoError(t, cmd.Execute())
|
||||
|
||||
assert.FileExists(t, filepath.Join(root, "rules", "go.md"))
|
||||
assert.FileExists(t, filepath.Join(root, "rules", "py.md"))
|
||||
|
||||
// Round-trips back through the loader.
|
||||
b, err := canonical.Load(root)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, b.Rules, 2)
|
||||
}
|
||||
|
||||
func makeStubReg() *adapter.Registry {
|
||||
reg := adapter.NewRegistry()
|
||||
reg.Register(&importableAdapter{
|
||||
|
||||
Reference in New Issue
Block a user