MCPcopy Create free account
hub / github.com/cli/cli / InjectLocalMetadata

Function InjectLocalMetadata

internal/skills/frontmatter/frontmatter.go:109–135  ·  view source on GitHub ↗

InjectLocalMetadata adds local-source tracking metadata to frontmatter. sourcePath is the absolute path to the source skill directory.

(content string, sourcePath string)

Source from the content-addressed store, hash-verified

107// InjectLocalMetadata adds local-source tracking metadata to frontmatter.
108// sourcePath is the absolute path to the source skill directory.
109func 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.
138func Serialize(frontmatter map[string]any, body string) (string, error) {

Callers 2

installLocalSkillFunction · 0.92
TestInjectLocalMetadataFunction · 0.85

Calls 2

ParseFunction · 0.85
SerializeFunction · 0.85

Tested by 1

TestInjectLocalMetadataFunction · 0.68