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