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).
75 lines
1.9 KiB
Go
75 lines
1.9 KiB
Go
package claudecode
|
|
|
|
import (
|
|
"path/filepath"
|
|
|
|
"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, ".claude")
|
|
res := &adapter.ImportResult{}
|
|
|
|
skills, err := common.ImportMarkdownTree(filepath.Join(base, "skills"), "SKILL.md")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
for _, s := range skills {
|
|
res.Skills = append(res.Skills, canonical.Skill{
|
|
Name: s.Name, Description: s.Description, Body: s.Body, Path: s.Path,
|
|
})
|
|
}
|
|
|
|
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,
|
|
})
|
|
}
|
|
|
|
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
|
|
}
|
|
res.Instructions = body
|
|
|
|
// Claude Code stores MCP servers across several files. Read all known
|
|
// locations and dedupe by name; ~/.claude.json is the live source so
|
|
// its entries win on conflict.
|
|
mcpSources := []string{
|
|
filepath.Join(home, ".claude.json"),
|
|
filepath.Join(base, "mcp_servers.json"),
|
|
filepath.Join(base, "settings.json"),
|
|
}
|
|
seen := map[string]bool{}
|
|
for _, p := range mcpSources {
|
|
servers, err := common.ImportMCPFromJSONFile(p, "mcpServers")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
for _, s := range servers {
|
|
if seen[s.Name] {
|
|
continue
|
|
}
|
|
seen[s.Name] = true
|
|
res.MCP = append(res.MCP, s)
|
|
}
|
|
}
|
|
return res, nil
|
|
}
|