mirror of
https://github.com/lukaszraczylo/harness-sync.git
synced 2026-10-18 01:17:50 +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:
@@ -0,0 +1,47 @@
|
||||
package canonical
|
||||
|
||||
import "strings"
|
||||
|
||||
// InstructionText returns the instruction body a harness should receive: the
|
||||
// per-harness override when one is set, otherwise the global instructions.
|
||||
func (b *Bundle) InstructionText(harness string) string {
|
||||
if override, ok := b.Instructions.PerHarness[harness]; ok && override != "" {
|
||||
return override
|
||||
}
|
||||
return b.Instructions.Global
|
||||
}
|
||||
|
||||
// InstructionTextWithRules returns InstructionText for the harness with every
|
||||
// canonical rule body folded in. Harnesses without a native rules directory
|
||||
// (everything except claude-code/kilo) only receive rule content this way —
|
||||
// via their global instructions file. Rule frontmatter is stripped so the
|
||||
// folded output stays clean; bodies are joined in load order (deterministic).
|
||||
func (b *Bundle) InstructionTextWithRules(harness string) string {
|
||||
base := b.InstructionText(harness)
|
||||
var sb strings.Builder
|
||||
sb.WriteString(base)
|
||||
for _, r := range b.Rules {
|
||||
body := strings.TrimSpace(stripFrontmatter(r.Body))
|
||||
if body == "" {
|
||||
continue
|
||||
}
|
||||
if sb.Len() > 0 {
|
||||
sb.WriteString("\n\n")
|
||||
}
|
||||
sb.WriteString(body)
|
||||
}
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
// stripFrontmatter removes a leading YAML frontmatter block ("---\n…\n---") so
|
||||
// folding a rule into a plain instructions file does not leak its metadata.
|
||||
func stripFrontmatter(s string) string {
|
||||
if !strings.HasPrefix(s, "---\n") {
|
||||
return s
|
||||
}
|
||||
end := strings.Index(s[4:], "\n---")
|
||||
if end == -1 {
|
||||
return s
|
||||
}
|
||||
return strings.TrimPrefix(s[4+end+len("\n---"):], "\n")
|
||||
}
|
||||
Reference in New Issue
Block a user