Files
Willie ece7090b1b fix: write every YAML file with 2-space indentation
yaml.Marshal defaults to 4 spaces, and only the config package forced 2.
Saving a plugin re-encodes the whole config.yaml, so installing one
reindented a user's entire file; skill/agent frontmatter and
audit-rules.yaml were written with 4 spaces too.

Route all YAML writers (config, registry, plugins, MCP, frontmatter,
audit rules) through one utils.MarshalYAML so they cannot drift apart.
2026-09-21 16:54:13 +08:00

23 lines
482 B
Go

package utils
import (
"bytes"
"gopkg.in/yaml.v3"
)
// MarshalYAML marshals v with 2-space indentation (Go yaml default is 4).
// Every YAML file skillshare writes goes through it, so edits never reindent a user's file.
func MarshalYAML(v any) ([]byte, error) {
var buf bytes.Buffer
enc := yaml.NewEncoder(&buf)
enc.SetIndent(2)
if err := enc.Encode(v); err != nil {
return nil, err
}
if err := enc.Close(); err != nil {
return nil, err
}
return buf.Bytes(), nil
}