LoadSkillBody reads the full skill meta file for a discovered skill and lists the supporting files in its directory.
( ctx context.Context, conn workspacesdk.AgentConn, skill SkillMeta, metaFile string, )
| 129 | // LoadSkillBody reads the full skill meta file for a discovered |
| 130 | // skill and lists the supporting files in its directory. |
| 131 | func LoadSkillBody( |
| 132 | ctx context.Context, |
| 133 | conn workspacesdk.AgentConn, |
| 134 | skill SkillMeta, |
| 135 | metaFile string, |
| 136 | ) (SkillContent, error) { |
| 137 | metaPath := path.Join(skill.Dir, metaFile) |
| 138 | |
| 139 | reader, _, err := conn.ReadFile( |
| 140 | ctx, metaPath, 0, maxSkillMetaBytes+1, |
| 141 | ) |
| 142 | if err != nil { |
| 143 | return SkillContent{}, xerrors.Errorf( |
| 144 | "read skill body: %w", err, |
| 145 | ) |
| 146 | } |
| 147 | raw, err := io.ReadAll(io.LimitReader(reader, maxSkillMetaBytes+1)) |
| 148 | reader.Close() |
| 149 | if err != nil { |
| 150 | return SkillContent{}, xerrors.Errorf( |
| 151 | "read skill body bytes: %w", err, |
| 152 | ) |
| 153 | } |
| 154 | |
| 155 | if int64(len(raw)) > maxSkillMetaBytes { |
| 156 | raw = raw[:maxSkillMetaBytes] |
| 157 | } |
| 158 | |
| 159 | _, _, body, err := workspacesdk.ParseSkillFrontmatter(string(raw)) |
| 160 | if err != nil { |
| 161 | return SkillContent{}, xerrors.Errorf( |
| 162 | "parse skill frontmatter: %w", err, |
| 163 | ) |
| 164 | } |
| 165 | |
| 166 | // List supporting files so the model knows what it can |
| 167 | // request via read_skill_file. |
| 168 | lsResp, err := conn.LS(ctx, "", workspacesdk.LSRequest{ |
| 169 | Path: []string{skill.Dir}, |
| 170 | Relativity: workspacesdk.LSRelativityRoot, |
| 171 | }) |
| 172 | if err != nil { |
| 173 | return SkillContent{}, xerrors.Errorf( |
| 174 | "list skill directory: %w", err, |
| 175 | ) |
| 176 | } |
| 177 | |
| 178 | var files []string |
| 179 | for _, entry := range lsResp.Contents { |
| 180 | if entry.Name == metaFile { |
| 181 | continue |
| 182 | } |
| 183 | name := entry.Name |
| 184 | if entry.IsDir { |
| 185 | name += "/" |
| 186 | } |
| 187 | files = append(files, name) |
| 188 | } |