Skip to content

Commit 2709791

Browse files
committed
fix: post install hook code review agent fixes
1 parent a6751a7 commit 2709791

5 files changed

Lines changed: 40 additions & 30 deletions

File tree

.goreleaser.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ brews:
5252
(bash_completion/"auth0").write `#{bin}/auth0 completion bash`
5353
(fish_completion/"auth0.fish").write `#{bin}/auth0 completion fish`
5454
(zsh_completion/"_auth0").write `#{bin}/auth0 completion zsh`
55+
56+
system "#{bin}/auth0", "ai", "skills", "post-install-hook"
5557
caveats: "Thanks for installing the Auth0 CLI"
5658

5759
scoops:
@@ -68,4 +70,4 @@ scoops:
6870
description: Build, manage and test your Auth0 integrations from the command line
6971
license: MIT
7072
skip_upload: true
71-
post_install: ["Write-Host 'Thanks for installing the Auth0 CLI'"]
73+
post_install: ["Write-Host 'Thanks for installing the Auth0 CLI'", "& auth0 ai skills post-install-hook"]

internal/ai/skills/download.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ func checkGitVersion() error {
141141
return nil
142142
}
143143

144-
// fetchCommitSHA fetches the latest commit SHA for ref from the GitHub API.
145-
func fetchCommitSHA(ref string) (string, error) {
144+
// FetchCommitSHA fetches the latest commit SHA for ref from the GitHub API.
145+
func FetchCommitSHA(ref string) (string, error) {
146146
req, err := http.NewRequest(http.MethodGet, agentSkillsAPI+ref, nil)
147147
if err != nil {
148148
return "", err
@@ -274,7 +274,7 @@ func fetchToTempFile(url, pattern, label string) (*os.File, int64, error) {
274274

275275
// downloadViaTarGz fetches the commit SHA first, then downloads and extracts the tar.gz archive.
276276
func downloadViaTarGz(targetDir, ref string) (string, error) {
277-
sha, err := fetchCommitSHA(ref)
277+
sha, err := FetchCommitSHA(ref)
278278
if err != nil {
279279
return "", err
280280
}
@@ -299,7 +299,7 @@ func downloadViaTarGz(targetDir, ref string) (string, error) {
299299

300300
// downloadViaZip fetches the commit SHA first, then downloads and extracts the ZIP archive.
301301
func downloadViaZip(targetDir, ref string) (string, error) {
302-
sha, err := fetchCommitSHA(ref)
302+
sha, err := FetchCommitSHA(ref)
303303
if err != nil {
304304
return "", err
305305
}

internal/ai/skills/download_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ func TestFetchCommitSHA(t *testing.T) {
252252

253253
t.Run("returns SHA from valid response", func(t *testing.T) {
254254
setHTTPClient(t, shaResponse("abc123def456"))
255-
sha, err := fetchCommitSHA("main")
255+
sha, err := FetchCommitSHA("main")
256256
require.NoError(t, err)
257257
assert.Equal(t, "abc123def456", sha)
258258
})
@@ -261,14 +261,14 @@ func TestFetchCommitSHA(t *testing.T) {
261261
setHTTPClient(t, func(_ *http.Request) (*http.Response, error) {
262262
return &http.Response{StatusCode: http.StatusForbidden, Body: io.NopCloser(strings.NewReader(""))}, nil
263263
})
264-
_, err := fetchCommitSHA("main")
264+
_, err := FetchCommitSHA("main")
265265
require.Error(t, err)
266266
assert.Contains(t, err.Error(), "403")
267267
})
268268

269269
t.Run("returns error when SHA field is empty", func(t *testing.T) {
270270
setHTTPClient(t, shaResponse(""))
271-
_, err := fetchCommitSHA("main")
271+
_, err := FetchCommitSHA("main")
272272
require.Error(t, err)
273273
assert.Contains(t, err.Error(), "empty SHA")
274274
})
@@ -277,15 +277,15 @@ func TestFetchCommitSHA(t *testing.T) {
277277
setHTTPClient(t, func(_ *http.Request) (*http.Response, error) {
278278
return &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(strings.NewReader("not json"))}, nil
279279
})
280-
_, err := fetchCommitSHA("main")
280+
_, err := FetchCommitSHA("main")
281281
require.Error(t, err)
282282
})
283283

284284
t.Run("returns error on request failure", func(t *testing.T) {
285285
setHTTPClient(t, func(_ *http.Request) (*http.Response, error) {
286286
return nil, errors.New("network error")
287287
})
288-
_, err := fetchCommitSHA("main")
288+
_, err := FetchCommitSHA("main")
289289
require.Error(t, err)
290290
assert.Contains(t, err.Error(), "github API request failed")
291291
})
@@ -298,7 +298,7 @@ func TestFetchCommitSHA(t *testing.T) {
298298
body, _ := json.Marshal(map[string]string{"sha": "abc123"})
299299
return &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(bytes.NewReader(body))}, nil
300300
})
301-
_, err := fetchCommitSHA("main")
301+
_, err := FetchCommitSHA("main")
302302
require.NoError(t, err)
303303
assert.Equal(t, "Bearer test-token-xyz", capturedAuth)
304304
})
@@ -311,7 +311,7 @@ func TestFetchCommitSHA(t *testing.T) {
311311
body, _ := json.Marshal(map[string]string{"sha": "abc123"})
312312
return &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(bytes.NewReader(body))}, nil
313313
})
314-
_, err := fetchCommitSHA("main")
314+
_, err := FetchCommitSHA("main")
315315
require.NoError(t, err)
316316
assert.Empty(t, capturedAuth)
317317
})

internal/cli/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ func buildRootCmd(cli *cli) *cobra.Command {
8989
cli.configureRenderer()
9090

9191
if cmd.CommandPath() != "auth0 ai skills post-install-hook" && !skillsSentinelExists() {
92-
fmt.Fprintln(os.Stdout, skillsInstallTip)
93-
writeSkillsSentinel()
92+
fmt.Fprintln(os.Stderr, skillsInstallTip)
93+
// writeSkillsSentinel()
9494
}
9595

9696
if !commandRequiresAuthentication(cmd.CommandPath()) {

internal/cli/skills.go

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717

1818
const (
1919
skillsSentinelPath = ".config/auth0/agents/.post-install-ran"
20-
skillsInstallTip = "Run 'auth0 ai skills install' any time to set up Auth0 skills for your AI assistant."
20+
skillsInstallTip = "Tip: run 'auth0 ai skills install' to set up Auth0 skills for your AI assistant."
2121

2222
skillsPluginRepo = "https://github.com/auth0/agent-skills"
2323
skillsPluginRef = "main"
@@ -86,8 +86,8 @@ func postInstallHookCmd(cli *cli) *cobra.Command {
8686
}
8787

8888
if !iostream.IsInputTerminal() || !iostream.IsOutputTerminal() {
89-
fmt.Fprintln(os.Stdout, skillsInstallTip)
90-
writeSkillsSentinel()
89+
fmt.Fprintln(os.Stderr, skillsInstallTip)
90+
// writeSkillsSentinel()
9191
return nil
9292
}
9393

@@ -109,22 +109,26 @@ func postInstallHookCmd(cli *cli) *cobra.Command {
109109

110110
if err := survey.AskOne(prompt, &choice); err != nil {
111111
// User pressed Ctrl+C or closed the terminal — skip gracefully.
112-
fmt.Fprintln(os.Stdout, skillsInstallTip)
113-
writeSkillsSentinel()
112+
fmt.Fprintln(os.Stderr, skillsInstallTip)
113+
// writeSkillsSentinel()
114114
return nil
115115
}
116116

117-
writeSkillsSentinel()
118-
119117
switch choice {
120118
case choiceAuto:
121-
return runInstallFast(cli)
119+
if err := runInstallFast(cli); err != nil {
120+
return err
121+
}
122122
case choiceManual:
123-
return runInstallInteractive(cli)
123+
if err := runInstallInteractive(cli); err != nil {
124+
return err
125+
}
124126
default:
125-
fmt.Fprintln(os.Stdout, skillsInstallTip)
127+
fmt.Fprintln(os.Stderr, skillsInstallTip)
128+
return nil
126129
}
127130

131+
writeSkillsSentinel()
128132
return nil
129133
},
130134
}
@@ -205,16 +209,20 @@ func runInstallFast(_ *cli) error {
205209
}
206210

207211
// downloadSkillsIfNeeded downloads the skills plugin if the lock file is absent or
208-
// records a different commit SHA than the remote. Returns the commit SHA in use.
212+
// the local commit SHA differs from the remote HEAD of main. Returns the commit SHA in use.
209213
func downloadSkillsIfNeeded(targetDir, lockPath string) (string, error) {
214+
remoteSHA, err := skills.FetchCommitSHA(skillsPluginRef)
215+
if err != nil {
216+
return "", fmt.Errorf("fetch remote commit SHA: %w", err)
217+
}
218+
210219
lock, err := skills.ReadLock(lockPath)
211220
if err != nil {
212221
return "", fmt.Errorf("read lock file: %w", err)
213222
}
214223

215-
if lock != nil && lock.CommitSHA != "" {
216-
// Already installed — reuse the cached SHA.
217-
return lock.CommitSHA, nil
224+
if lock != nil && lock.CommitSHA == remoteSHA {
225+
return remoteSHA, nil
218226
}
219227

220228
return skills.DownloadPlugin(targetDir, skillsPluginRef)
@@ -223,7 +231,7 @@ func downloadSkillsIfNeeded(targetDir, lockPath string) (string, error) {
223231
// runInstallInteractive runs the full interactive install flow.
224232
// Skills install customization coming soon.
225233
func runInstallInteractive(_ *cli) error {
226-
fmt.Fprintln(os.Stdout, "Skills install customization coming soon.")
227-
fmt.Fprintln(os.Stdout, skillsInstallTip)
234+
fmt.Fprintln(os.Stderr, "Skills install customization coming soon.")
235+
fmt.Fprintln(os.Stderr, skillsInstallTip)
228236
return nil
229237
}

0 commit comments

Comments
 (0)