InjectLocalMetadata adds local-source tracking metadata to frontmatter. sourcePath is the absolute path to the source skill directory.
(content string, sourcePath string)
| 100 | // InjectLocalMetadata adds local-source tracking metadata to frontmatter. |
| 101 | // sourcePath is the absolute path to the source skill directory. |
| 102 | func InjectLocalMetadata(content string, sourcePath string) (string, error) { |
| 103 | result, err := Parse(content) |
| 104 | if err != nil { |
| 105 | return "", err |
| 106 | } |
| 107 | |
| 108 | if result.RawYAML == nil { |
| 109 | result.RawYAML = make(map[string]interface{}) |
| 110 | } |
| 111 | |
| 112 | meta, _ := result.RawYAML["metadata"].(map[string]interface{}) |
| 113 | if meta == nil { |
| 114 | meta = make(map[string]interface{}) |
| 115 | } |
| 116 | delete(meta, "github-owner") |
| 117 | delete(meta, "github-repo") |
| 118 | delete(meta, "github-ref") |
| 119 | delete(meta, "github-sha") |
| 120 | delete(meta, "github-tree-sha") |
| 121 | delete(meta, "github-pinned") |
| 122 | delete(meta, "github-path") |
| 123 | meta["local-path"] = sourcePath |
| 124 | result.RawYAML["metadata"] = meta |
| 125 | |
| 126 | return Serialize(result.RawYAML, result.Body) |
| 127 | } |
| 128 | |
| 129 | // Serialize writes a frontmatter map and body back to a SKILL.md string. |
| 130 | func Serialize(frontmatter map[string]interface{}, body string) (string, error) { |