Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ execute() {
log_info "installed ${BINDIR}/${binexe}"
done
rm -rf "${tmpdir}"
"${BINDIR}/auth0" ai skills post-install-hook || true
}
get_binaries() {
case "$PLATFORM" in
Expand Down
7 changes: 7 additions & 0 deletions internal/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ func buildRootCmd(cli *cli) *cobra.Command {
prepareInteractivity(cmd)
cli.configureRenderer()

if cmd.CommandPath() != "auth0 ai skills post-install-hook" && !skillsSentinelExists() {
fmt.Fprintln(os.Stdout, skillsInstallTip)
writeSkillsSentinel()
}

if !commandRequiresAuthentication(cmd.CommandPath()) {
return nil
}
Expand Down Expand Up @@ -121,6 +126,7 @@ func commandRequiresAuthentication(invokedCommandName string) bool {
"auth0 logout",
"auth0 tenants use",
"auth0 tenants list",
"auth0 ai skills post-install-hook",
}

for _, cmd := range commandsWithNoAuthRequired {
Expand Down Expand Up @@ -175,6 +181,7 @@ func addSubCommands(rootCmd *cobra.Command, cli *cli) {
rootCmd.AddCommand(networkACLCmd(cli))
rootCmd.AddCommand(tenantSettingsCmd(cli))
rootCmd.AddCommand(tokenExchangeCmd(cli))
rootCmd.AddCommand(aiCmd(cli))

// Keep completion at the bottom.
rootCmd.AddCommand(completionCmd(cli))
Expand Down
229 changes: 229 additions & 0 deletions internal/cli/skills.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
package cli

import (
"fmt"
"os"
"path/filepath"
"time"

"github.com/AlecAivazis/survey/v2"
"github.com/spf13/cobra"

"github.com/auth0/auth0-cli/internal/ansi"
"github.com/auth0/auth0-cli/internal/iostream"

"github.com/auth0/auth0-cli/internal/ai/skills"
)

const (
skillsSentinelPath = ".config/auth0/agents/.post-install-ran"
skillsInstallTip = "Run 'auth0 ai skills install' any time to set up Auth0 skills for your AI assistant."

skillsPluginRepo = "https://github.com/auth0/agent-skills"
skillsPluginRef = "main"
)

func pluginTargetDir() (string, error) {
home, err := os.UserHomeDir()
if err != nil {
return "", err
}
return filepath.Join(home, ".config", "auth0", "agents", "plugins", "auth0"), nil
}

func globalLockPath(targetDir string) string {
return filepath.Join(targetDir, "skills-lock.json")
}

func skillsSentinel() string {
home, _ := os.UserHomeDir()
return filepath.Join(home, skillsSentinelPath)
}

func writeSkillsSentinel() {
sentinel := skillsSentinel()
_ = os.MkdirAll(filepath.Dir(sentinel), 0o755)
_ = os.WriteFile(sentinel, []byte{}, 0o644)
}

func skillsSentinelExists() bool {
_, err := os.Stat(skillsSentinel())
return err == nil
}

func aiCmd(cli *cli) *cobra.Command {
cmd := &cobra.Command{
Use: "ai",
Short: "Manage Auth0 AI capabilities",
Long: "Manage Auth0 AI capabilities including skills for your AI coding assistants.",
}

cmd.AddCommand(aiSkillsCmd(cli))

return cmd
}

func aiSkillsCmd(cli *cli) *cobra.Command {
cmd := &cobra.Command{
Use: "skills",
Short: "Manage Auth0 AI skills for coding assistants",
Long: "Manage Auth0 AI skills that provide Auth0-specific guidance to your AI coding assistants.",
}

cmd.AddCommand(postInstallHookCmd(cli))

return cmd
}

func postInstallHookCmd(cli *cli) *cobra.Command {
return &cobra.Command{
Use: "post-install-hook",
Hidden: true,
Short: "Run post-install setup for Auth0 AI skills",
RunE: func(cmd *cobra.Command, args []string) error {
if skillsSentinelExists() {
return nil
}

if !iostream.IsInputTerminal() || !iostream.IsOutputTerminal() {
fmt.Fprintln(os.Stdout, skillsInstallTip)
writeSkillsSentinel()
return nil
}

const (
choiceAuto = "Auto — Detect installed AI agents and install all skills globally"
choiceManual = "Manual — Choose which skills, agents, and scope to configure"
choiceSkip = "Skip — I will run 'auth0 ai skills install' later"
)

fmt.Fprintln(os.Stdout, "\nAuth0 AI skills add Auth0-specific guidance to your AI coding assistant.")
fmt.Fprintln(os.Stdout, "")

var choice string
prompt := &survey.Select{
Message: "How would you like to install them?",
Options: []string{choiceAuto, choiceManual, choiceSkip},
Default: choiceAuto,
}

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

writeSkillsSentinel()

switch choice {
case choiceAuto:
return runInstallFast(cli)
case choiceManual:
return runInstallInteractive(cli)
default:
fmt.Fprintln(os.Stdout, skillsInstallTip)
}

return nil
},
}
}

// runInstallFast detects all installed AI agents and installs all available Auth0
// skills globally into each one. Equivalent to `auth0 ai skills install --fast`.
func runInstallFast(_ *cli) error {
targetDir, err := pluginTargetDir()
if err != nil {
return fmt.Errorf("resolve plugin directory: %w", err)
}

lockPath := globalLockPath(targetDir)

// Download (or skip if already up-to-date).
var commitSHA string
if err := ansi.Waiting(func() error {
commitSHA, err = downloadSkillsIfNeeded(targetDir, lockPath)
return err
}); err != nil {
return fmt.Errorf("download Auth0 skills: %w", err)
}

// List skills that were downloaded.
skillsDir := filepath.Join(targetDir, "skills")
available, err := skills.ListAvailableSkills(skillsDir)
if err != nil || len(available) == 0 {
return fmt.Errorf("no skills found in %s", skillsDir)
}

skillNames := make([]string, len(available))
for i, s := range available {
skillNames[i] = s.Name
}

// Install into every detected agent.
agents := skills.FastPriorityAgents()
var installedAgents []string

for _, agent := range agents {
agentSkillsDir, resolveErr := agent.ResolvedGlobalSkillsDir()
if resolveErr != nil {
continue
}
for _, skillName := range skillNames {
sourceSkillDir := filepath.Join(skillsDir, skillName)
if linkErr := skills.CreateSkillLink(sourceSkillDir, agentSkillsDir, skillName, false); linkErr != nil {
fmt.Fprintf(os.Stderr, "warning: could not install skill %q for %s: %v\n", skillName, agent.DisplayName, linkErr)
}
}
installedAgents = append(installedAgents, agent.ID)
}

// Write the global lock file.
now := time.Now()
lock := &skills.Lock{
Repo: skillsPluginRepo,
Ref: skillsPluginRef,
CommitSHA: commitSHA,
InstalledAt: now,
UpdatedAt: now,
LastCheckedAt: now,
Skills: skillNames,
Agents: installedAgents,
Scope: skills.ScopeGlobal,
}
if writeErr := skills.WriteLock(lockPath, lock); writeErr != nil {
fmt.Fprintf(os.Stderr, "warning: could not write lock file: %v\n", writeErr)
}

fmt.Fprintf(os.Stdout, "\nInstalled %d Auth0 skill(s) for %d agent(s).\n", len(skillNames), len(installedAgents))
for _, s := range available {
fmt.Fprintf(os.Stdout, " - %s\n", s.Name)
}

return nil
}

// downloadSkillsIfNeeded downloads the skills plugin if the lock file is absent or
// records a different commit SHA than the remote. Returns the commit SHA in use.
func downloadSkillsIfNeeded(targetDir, lockPath string) (string, error) {
lock, err := skills.ReadLock(lockPath)
if err != nil {
return "", fmt.Errorf("read lock file: %w", err)
}

if lock != nil && lock.CommitSHA != "" {
// Already installed — reuse the cached SHA.
return lock.CommitSHA, nil
}

return skills.DownloadPlugin(targetDir, skillsPluginRef)
}

// runInstallInteractive runs the full interactive install flow.
// Skills install customization coming soon.
func runInstallInteractive(_ *cli) error {
fmt.Fprintln(os.Stdout, "Skills install customization coming soon.")
fmt.Fprintln(os.Stdout, skillsInstallTip)
return nil
}
Loading