MCPcopy
hub / github.com/cli/cli / InjectLocalMetadata

Function InjectLocalMetadata

internal/skills/frontmatter/frontmatter.go:102–127  ·  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

100// InjectLocalMetadata adds local-source tracking metadata to frontmatter.
101// sourcePath is the absolute path to the source skill directory.
102func 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.
130func Serialize(frontmatter map[string]interface{}, 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