Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
90a82e8
feat(ai): ai add installs bundled skills via skills.sh (global scope)
tturkowski Sep 9, 2026
245e4c3
feat(ai): ai add installs bundled skills via skills.sh (global + proj…
tturkowski Sep 9, 2026
57d7c3f
feat(ai): ai add installs git-delivered skills (resolve latest releas…
tturkowski Sep 10, 2026
6cdaab1
feat(ai): gate git-skill installs on the owner compatibility check
tturkowski Sep 10, 2026
f8aae02
feat(ai): ai remove uninstalls CLI-recorded skills via skills.sh
tturkowski Sep 10, 2026
efcb822
refactor(ai): rename client->agent, drop issue-id comments, testify s…
tturkowski Sep 10, 2026
0c2cfa1
refactor(ai): clearer error when a git skill is installed globally
tturkowski Sep 10, 2026
94b3422
docs(ai): add manual test plan for ai add/remove
tturkowski Sep 10, 2026
b4cb6f5
manual testing instructions + script
tturkowski Sep 10, 2026
9a55ea4
feat(ai): expose the ai command group in --help
tturkowski Sep 10, 2026
46783f7
docs(ai): ai command group is no longer hidden
tturkowski Sep 10, 2026
04d450d
fix(ai): address review — skills op in errors, bounded download, getw…
tturkowski Sep 10, 2026
be7a31e
feat(ai): ai remove trusts recorded state; warn on failed state write
tturkowski Sep 10, 2026
6ad1913
fix(ai): warn when an installed skill cannot be recorded
tturkowski Sep 10, 2026
e0558d8
docs(ai): align manual test sandbox and harden the runner
tturkowski Sep 10, 2026
1a2be69
Merge branch 'main' into feat/ai-add-remove
tturkowski Sep 10, 2026
3845de9
Merge branch 'main' into feat/ai-add-remove
tturkowski Sep 11, 2026
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
4 changes: 0 additions & 4 deletions cmd/ai/ai.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import (
var aiRootCmd = &cobra.Command{
Use: "ai",
Short: "Discover Shopware AI integrations",
// Hidden until the feature is complete (install/MCP land in #1336/#1337).
// The commands still work when invoked; they are only kept out of --help so
// incremental merges do not advertise a half-finished command group.
Hidden: true,
}

// Register adds the ai command group to the root command.
Expand Down
218 changes: 218 additions & 0 deletions cmd/ai/ai_add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
package ai

import (
"encoding/json"
"errors"
"fmt"
"io"
"os"
"strings"

"github.com/spf13/cobra"

"github.com/shopware/shopware-cli/internal/ai/directory"
"github.com/shopware/shopware-cli/internal/ai/state"
)

// The CLI hardcodes no agent names: which agents exist is skills.sh's business,
// so a new one it supports works without a CLI change.

// addResult is the machine-readable shape of `ai add` (--format json).
type addResult struct {
Name string `json:"name"`
Agent string `json:"agent"`
Scope state.Scope `json:"scope"`
RequestedTag string `json:"requestedTag"`
ResolvedRevision string `json:"resolvedRevision"`
DryRun bool `json:"dryRun"`
Command []string `json:"command"`
}

var aiAddCmd = &cobra.Command{
Use: "add <name>[@<tag>]",
Short: "Install a Shopware AI integration into an AI agent",
Args: cobra.ExactArgs(1),
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
format, err := resolveFormat(cmd)
if err != nil {
return err
}

name, tag := splitNameTag(args[0])
agent, _ := cmd.Flags().GetString("agent")
global, _ := cmd.Flags().GetBool("global")
dryRun, _ := cmd.Flags().GetBool("dry-run")

entry, ok := directory.Load().Get(name)
if !ok {
return fmt.Errorf("unknown integration %q (see `shopware-cli ai list`)", name)
}

// Skills only for now (MCP arrives later). The agent value is passed
// straight to skills.sh.
if entry.Type != directory.TypeSkill {
return fmt.Errorf("installing %q is not supported yet (only skills for now)", name)
}
// A git skill's compatibility check runs against a project, so there is
// nothing to check for a global install.
if entry.Delivery.Kind == directory.DeliveryGit && global {
return fmt.Errorf("%q must be installed into a project, not globally: it checks compatibility against that project (omit --global)", entry.Name)
}
if agent == "" {
return errors.New("specify the target agent with --agent (e.g. --agent claude-code)")
}

// State lives where the config lives: a --global install and its state
// go to the user config dir; a project install and its state go to the
// current directory, matching where skills.sh writes the agent config.
scope := state.ScopeGlobal
readState := state.Read
saveState := state.Save
if !global {
root, err := os.Getwd()
if err != nil {
return err
}
scope = state.ScopeProject
readState = func() (state.File, error) { return state.ReadProject(root) }
saveState = func(f state.File) error { return state.SaveProject(root, f) }
}

// Resolve the source repo and the ref to install. A bundled skill's
// version follows the CLI; a git skill uses the explicit tag or the
// latest stable release from its repository.
var source, ref string
switch entry.Delivery.Kind {
case directory.DeliveryBundled:
ref = tag
if ref == "" {
ref = cmd.Root().Version
}
source = "shopware/shopware-cli"
case directory.DeliveryGit:
ref = tag
if ref == "" {
if ref, err = resolveLatestTag(cmd.Context(), entry.Delivery.Repository); err != nil {
return err
}
}
source = ownerRepo(entry.Delivery.Repository)
default:
return fmt.Errorf("unsupported delivery %q", entry.Delivery.Kind)
}
if ref != "" {
source += "@" + ref
}

// skills.sh must never prompt: this command already supplies the skill,
// agent and scope, so its confirmation prompts are always skipped.
argv := skillsAddArgs(source, entry.Name, agent, global, true)

result := addResult{
Name: entry.Name,
Agent: agent,
Scope: scope,
RequestedTag: tag,
ResolvedRevision: ref,
DryRun: dryRun,
Command: argv,
}

if dryRun {
return writeAddResult(cmd.OutOrStdout(), format, result)
}

current, err := readState()
if err != nil {
return err
}

// Idempotent: the same integration, agent, scope and revision is a no-op.
if !isInstalled(current, result) {
// A git skill declares an owner-maintained compatibility check; run
// it against the project before installing anything.
if entry.Delivery.Kind == directory.DeliveryGit && entry.Compatibility != nil {
projectDir, err := os.Getwd()
if err != nil {
return err
}
if err := runCompatCheck(cmd.Context(), ownerRepo(entry.Delivery.Repository), entry.Name, ref, projectDir, cmd.ErrOrStderr()); err != nil {
return err
}
}

if err := runSkills(cmd.Context(), argv, cmd.ErrOrStderr()); err != nil {
return err
}

next := state.Upsert(current, state.InstalledEntry{
Name: result.Name,
Agent: result.Agent,
Scope: result.Scope,
RequestedTag: result.RequestedTag,
ResolvedRevision: result.ResolvedRevision,
})
if err := saveState(next); err != nil {
_, _ = fmt.Fprintf(cmd.ErrOrStderr(), "warning: %s was installed but could not be recorded (%v); re-run `ai add` to record it\n", result.Name, err)
return err
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
}

return writeAddResult(cmd.OutOrStdout(), format, result)
},
}

// splitNameTag splits "name@tag" into its parts; a missing tag yields "".
func splitNameTag(s string) (name, tag string) {
if i := strings.IndexByte(s, '@'); i >= 0 {
return s[:i], s[i+1:]
}

return s, ""
}

// isInstalled reports whether the state already records this exact install.
func isInstalled(f state.File, r addResult) bool {
for _, e := range f.Installed {
if e.Name == r.Name && e.Agent == r.Agent && e.Scope == r.Scope && e.ResolvedRevision == r.ResolvedRevision {
return true
}
}

return false
}

func writeAddResult(w io.Writer, format string, r addResult) error {
if format == formatJSON {
out, err := json.Marshal(r)
if err != nil {
return err
}
_, err = fmt.Fprintln(w, string(out))

return err
}

if r.DryRun {
_, err := fmt.Fprintf(w, "[dry-run] would install %s for %s (%s):\n %s\n", r.Name, r.Agent, r.Scope, strings.Join(r.Command, " "))

return err
}

rev := ""
if r.ResolvedRevision != "" {
rev = " @" + r.ResolvedRevision
}
_, err := fmt.Fprintf(w, "Installed %s for %s (%s)%s\n", r.Name, r.Agent, r.Scope, rev)

return err
}

func init() {
aiRootCmd.AddCommand(aiAddCmd)
aiAddCmd.Flags().String("agent", "", "Target AI agent (e.g. claude-code)")
aiAddCmd.Flags().Bool("global", false, "Install at user level instead of the current project")
aiAddCmd.Flags().Bool("dry-run", false, "Show what would be installed without changing anything")
addFormatFlag(aiAddCmd)
}
Loading
Loading