@@ -2,6 +2,7 @@ package cmd
22
33import (
44 "fmt"
5+ "os"
56 "spark/internal/agent"
67 "spark/internal/tui"
78
@@ -11,6 +12,8 @@ import (
1112
1213var profileType string
1314var profileProject string
15+ var profileGlobal bool
16+ var profileForce bool
1417
1518var agentProfileCmd = & cobra.Command {
1619 Use : "profile" ,
@@ -53,7 +56,12 @@ var agentProfileListCmd = &cobra.Command{
5356var agentProfileAddCmd = & cobra.Command {
5457 Use : "add <name>" ,
5558 Short : "Add a new agent profile" ,
56- Args : cobra .ExactArgs (1 ),
59+ Long : `Add a new agent profile. Use --force to overwrite an existing profile.
60+
61+ Examples:
62+ spark agent profile add my-glm --type glm
63+ spark agent profile add my-glm --type glm --force` ,
64+ Args : cobra .ExactArgs (1 ),
5765 RunE : func (cmd * cobra.Command , args []string ) error {
5866 name := args [0 ]
5967
@@ -63,6 +71,12 @@ var agentProfileAddCmd = &cobra.Command{
6371
6472 agentType := agent .AgentType (profileType )
6573
74+ if profileForce {
75+ if err := agentManager .DeleteProfile (name ); err != nil && ! os .IsNotExist (err ) {
76+ return fmt .Errorf ("failed to remove existing profile: %w" , err )
77+ }
78+ }
79+
6680 pterm .Info .Printf ("Creating profile '%s' for agent '%s'...\n " , name , agentType )
6781 if err := agentManager .AddProfile (name , agentType ); err != nil {
6882 return fmt .Errorf ("failed to create profile: %w" , err )
@@ -147,33 +161,61 @@ var agentProfileEditCmd = &cobra.Command{
147161
148162var agentUseCmd = & cobra.Command {
149163 Use : "use <profile-name>" ,
150- Short : "Apply a profile to the current project" ,
151- Args : cobra .ExactArgs (1 ),
164+ Short : "Apply a profile to the current project or system-wide" ,
165+ Long : `Apply a profile to the current project or system-wide.
166+
167+ By default, the profile is applied to the current project directory.
168+ Use --global (-g) to apply the profile to your home directory (system level).
169+
170+ Examples:
171+ spark agent use my-glm # Apply to current project
172+ spark agent use my-glm --global # Apply to home directory (system level)
173+ spark agent use my-glm -d /path # Apply to a specific project directory` ,
174+ Args : cobra .ExactArgs (1 ),
152175 RunE : func (cmd * cobra.Command , args []string ) error {
153176 name := args [0 ]
154177
155178 projectDir := profileProject
156- if projectDir == "" {
179+ if profileGlobal {
180+ homeDir , err := os .UserHomeDir ()
181+ if err != nil {
182+ return fmt .Errorf ("failed to get home directory: %w" , err )
183+ }
184+ projectDir = homeDir
185+ } else if projectDir == "" {
157186 projectDir = "."
158187 }
159188
160- pterm .Info .Printf ("Applying profile '%s' to project at '%s'...\n " , name , projectDir )
189+ scope := "project"
190+ if profileGlobal {
191+ scope = "system (global)"
192+ }
193+ pterm .Info .Printf ("Applying profile '%s' to %s at '%s'...\n " , name , scope , projectDir )
161194
162195 if err := agentManager .ApplyProfile (name , projectDir ); err != nil {
163196 return fmt .Errorf ("failed to apply profile: %w" , err )
164197 }
165198
166- pterm .Success .Println ("Profile applied successfully!" )
199+ pterm .Success .Printf ("Profile applied successfully to %s! \n " , scope )
167200 return nil
168201 },
169202}
170203
171204var agentCurrentCmd = & cobra.Command {
172205 Use : "current" ,
173- Short : "Show the current applied profile in the project" ,
206+ Short : "Show the current applied profile in the project or system-wide" ,
207+ Long : `Show the current applied profile in the project or system-wide.
208+
209+ Use --global (-g) to check the profile at system level (home directory).` ,
174210 RunE : func (cmd * cobra.Command , args []string ) error {
175211 projectDir := profileProject
176- if projectDir == "" {
212+ if profileGlobal {
213+ homeDir , err := os .UserHomeDir ()
214+ if err != nil {
215+ return fmt .Errorf ("failed to get home directory: %w" , err )
216+ }
217+ projectDir = homeDir
218+ } else if projectDir == "" {
177219 projectDir = "."
178220 }
179221
@@ -183,7 +225,11 @@ var agentCurrentCmd = &cobra.Command{
183225 }
184226
185227 if current == "" {
186- pterm .Warning .Println ("No agent profile is currently applied to this project." )
228+ scope := "this project"
229+ if profileGlobal {
230+ scope = "system (global)"
231+ }
232+ pterm .Warning .Printf ("No agent profile is currently applied to %s.\n " , scope )
187233 pterm .Info .Println ("Use 'spark agent use <profile-name>' to apply one." )
188234 return nil
189235 }
@@ -204,7 +250,10 @@ func init() {
204250 agentProfileCmd .AddCommand (agentProfileEditCmd )
205251
206252 agentProfileAddCmd .Flags ().StringVarP (& profileType , "type" , "t" , "" , "Agent type (e.g. claude-code, glm)" )
253+ agentProfileAddCmd .Flags ().BoolVarP (& profileForce , "force" , "f" , false , "Overwrite existing profile" )
207254
208- agentUseCmd .Flags ().StringVarP (& profileProject , "project" , "p" , "." , "Project directory path" )
209- agentCurrentCmd .Flags ().StringVarP (& profileProject , "project" , "p" , "." , "Project directory path" )
255+ agentUseCmd .Flags ().StringVarP (& profileProject , "project" , "d" , "." , "Project directory path" )
256+ agentUseCmd .Flags ().BoolVarP (& profileGlobal , "global" , "g" , false , "Apply to home directory (system level)" )
257+ agentCurrentCmd .Flags ().StringVarP (& profileProject , "project" , "d" , "." , "Project directory path" )
258+ agentCurrentCmd .Flags ().BoolVarP (& profileGlobal , "global" , "g" , false , "Check system-level profile" )
210259}
0 commit comments