Skip to content

Commit ca88e01

Browse files
committed
feat: skills internal download and lock
1 parent 820c56b commit ca88e01

4 files changed

Lines changed: 20 additions & 22 deletions

File tree

internal/ai/skills/download.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const (
2020
agentSkillsAPI = "https://api.github.com/repos/auth0/agent-skills/commits/"
2121
pluginSubtreePath = "plugins/auth0"
2222
skillsHTTPTimeout = 60 * time.Second
23-
maxSkillsDownload = 100 * 1024 * 1024 // 100 MB
23+
maxSkillsDownload = 100 * 1024 * 1024 // 100 MB.
2424
)
2525

2626
var skillsHTTPClient = &http.Client{Timeout: skillsHTTPTimeout}
@@ -192,9 +192,7 @@ func downloadViaZip(targetDir, ref string) (string, error) {
192192
return fetchCommitSHA(ref)
193193
}
194194

195-
// extractTarGzSubtree reads a .tar.gz from r and copies entries whose name starts with
196-
// prefix into destDir (stripping the prefix from the output path).
197-
// extractEntry writes a single archive entry to destDir. isDir and mode describe the entry;
195+
// ExtractEntry writes a single archive entry to destDir. IsDir and mode describe the entry;
198196
// open returns a reader for its content (ignored when isDir is true). The name is checked
199197
// against prefix and any path-traversal attempt is rejected.
200198
func extractEntry(name string, isDir bool, mode os.FileMode, open func() (io.ReadCloser, error), prefix, destDir string) error {
@@ -260,7 +258,7 @@ func extractTarGzSubtree(r io.Reader, prefix, destDir string) error {
260258
// extractZipSubtree opens the ZIP at zipPath (with known size) and copies entries whose
261259
// name starts with prefix into destDir (stripping the prefix).
262260
func extractZipSubtree(zipPath string, size int64, prefix, destDir string) error {
263-
// zip.NewReader needs an io.ReaderAt, so we re-open the file.
261+
// Zip.NewReader needs an io.ReaderAt, so we re-open the file.
264262
f, err := os.Open(zipPath)
265263
if err != nil {
266264
return err

internal/ai/skills/download_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func assertFileContent(t *testing.T, path, want string) {
8080
assert.Equal(t, want, string(data))
8181
}
8282

83-
// --- extractEntry ---
83+
// --- extractEntry ---.
8484

8585
func TestExtractEntry(t *testing.T) {
8686
open := func(content string) func() (io.ReadCloser, error) {
@@ -137,7 +137,7 @@ func TestExtractEntry(t *testing.T) {
137137
})
138138
}
139139

140-
// --- extractTarGzSubtree ---
140+
// --- extractTarGzSubtree ---.
141141

142142
func TestExtractTarGzSubtree(t *testing.T) {
143143
const prefix = "repo-main/plugins/auth0/"
@@ -171,7 +171,7 @@ func TestExtractTarGzSubtree(t *testing.T) {
171171
})
172172
}
173173

174-
// --- extractZipSubtree ---
174+
// --- extractZipSubtree ---.
175175

176176
func TestExtractZipSubtree(t *testing.T) {
177177
const prefix = "repo-main/plugins/auth0/"
@@ -203,7 +203,7 @@ func TestExtractZipSubtree(t *testing.T) {
203203
})
204204
}
205205

206-
// --- mergeDir ---
206+
// --- mergeDir ---.
207207

208208
func TestMergeDir(t *testing.T) {
209209
t.Run("copies flat files", func(t *testing.T) {
@@ -230,7 +230,7 @@ func TestMergeDir(t *testing.T) {
230230
})
231231
}
232232

233-
// --- fetchToTempFile ---
233+
// --- fetchToTempFile ---.
234234

235235
func TestFetchToTempFile(t *testing.T) {
236236
t.Run("returns open seeked file and byte count on 200", func(t *testing.T) {
@@ -265,7 +265,7 @@ func TestFetchToTempFile(t *testing.T) {
265265
})
266266
}
267267

268-
// --- fetchCommitSHA ---
268+
// --- fetchCommitSHA ---.
269269

270270
func TestFetchCommitSHA(t *testing.T) {
271271
shaResponse := func(sha string) roundTripFunc {

internal/ai/skills/lock.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"time"
99
)
1010

11-
// SkillsLock records the installed state of the auth0 agent-skills plugin.
12-
type SkillsLock struct {
11+
// Lock records the installed state of the auth0 agent-skills plugin.
12+
type Lock struct {
1313
Repo string `json:"repo"`
1414
Ref string `json:"ref"`
1515
CommitSHA string `json:"commitSHA"`
@@ -18,27 +18,27 @@ type SkillsLock struct {
1818
LastCheckedAt time.Time `json:"lastCheckedAt"`
1919
Skills []string `json:"skills"`
2020
Agents []string `json:"agents"`
21-
Scope string `json:"scope"` // "global" or "local"
21+
Scope string `json:"scope"` // "global" or "local".
2222
}
2323

2424
// ReadLock reads the skills-lock.json at path. Returns nil, nil when the file does not exist.
25-
func ReadLock(path string) (*SkillsLock, error) {
25+
func ReadLock(path string) (*Lock, error) {
2626
data, err := os.ReadFile(path)
2727
if err != nil {
2828
if errors.Is(err, os.ErrNotExist) {
2929
return nil, nil
3030
}
3131
return nil, err
3232
}
33-
var lock SkillsLock
33+
var lock Lock
3434
if err := json.Unmarshal(data, &lock); err != nil {
3535
return nil, err
3636
}
3737
return &lock, nil
3838
}
3939

4040
// WriteLock serialises lock as JSON and writes it to path, creating parent directories as needed.
41-
func WriteLock(path string, lock *SkillsLock) error {
41+
func WriteLock(path string, lock *Lock) error {
4242
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
4343
return err
4444
}

internal/ai/skills/lock_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func TestWriteLock(t *testing.T) {
7474
dir := t.TempDir()
7575
path := filepath.Join(dir, "skills-lock.json")
7676

77-
lock := &SkillsLock{
77+
lock := &Lock{
7878
Repo: "https://github.com/auth0/agent-skills.git",
7979
Ref: "main",
8080
CommitSHA: "deadbeef",
@@ -102,7 +102,7 @@ func TestWriteLock(t *testing.T) {
102102
dir := t.TempDir()
103103
path := filepath.Join(dir, "nested", "deep", "skills-lock.json")
104104

105-
require.NoError(t, WriteLock(path, &SkillsLock{Scope: "global"}))
105+
require.NoError(t, WriteLock(path, &Lock{Scope: "global"}))
106106

107107
got, err := ReadLock(path)
108108
require.NoError(t, err)
@@ -114,8 +114,8 @@ func TestWriteLock(t *testing.T) {
114114
dir := t.TempDir()
115115
path := filepath.Join(dir, "skills-lock.json")
116116

117-
require.NoError(t, WriteLock(path, &SkillsLock{CommitSHA: "first"}))
118-
require.NoError(t, WriteLock(path, &SkillsLock{CommitSHA: "second"}))
117+
require.NoError(t, WriteLock(path, &Lock{CommitSHA: "first"}))
118+
require.NoError(t, WriteLock(path, &Lock{CommitSHA: "second"}))
119119

120120
got, err := ReadLock(path)
121121
require.NoError(t, err)
@@ -126,7 +126,7 @@ func TestWriteLock(t *testing.T) {
126126
dir := t.TempDir()
127127
path := filepath.Join(dir, "skills-lock.json")
128128

129-
original := &SkillsLock{
129+
original := &Lock{
130130
Repo: "https://github.com/auth0/agent-skills.git",
131131
Ref: "v1.2.3",
132132
CommitSHA: "cafebabe",

0 commit comments

Comments
 (0)