Skip to content

Commit 13c3861

Browse files
committed
disable agent
1 parent 414e8ff commit 13c3861

7 files changed

Lines changed: 153 additions & 27 deletions

File tree

AGENTS.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
2. **Mono-repo 创建** - 将多个仓库整合为一个带有子模块的 Mono 仓库
1111
3. **子模块同步** - 同步 Mono 仓库中的所有子模块
1212
4. **Git 用户配置** - 配置仓库的 Git 用户信息
13-
5. **AI Agent 配置管理** - 管理多种 AI Agent(Claude Code、Codex、Kimi、GLM)的配置文件
14-
6. **任务管理** - 任务分发、同步和 GitHub 仓库创建
15-
7. **Gitcode 远程管理** - 为仓库添加 Gitcode 远程地址
13+
5. **任务管理** - 任务分发、同步和 GitHub 仓库创建
14+
6. **Gitcode 远程管理** - 为仓库添加 Gitcode 远程地址
15+
7. ~~**AI Agent 配置管理** - 管理多种 AI Agent(Claude Code、Codex、Kimi、GLM)的配置文件~~ (已禁用,待重新设计)
1616

1717
## 技术栈
1818

@@ -268,7 +268,9 @@ spark:
268268

269269
**跨平台支持**: Mac、Linux、Windows
270270

271-
### AI Agent 管理
271+
### AI Agent 管理 (已禁用)
272+
273+
> ⚠️ 此功能当前已禁用,命令入口已关闭(`cmd/agent.go` 中 `rootCmd.AddCommand(agentCmd)` 已注释)。待后续重新设计后再启用。
272274

273275
#### `spark agent`
274276
管理多种 AI Agent 的配置文件。

cmd/agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,5 +204,5 @@ func init() {
204204
agentCmd.AddCommand(agentEditCmd)
205205
agentCmd.AddCommand(agentResetCmd)
206206

207-
rootCmd.AddCommand(agentCmd)
207+
// rootCmd.AddCommand(agentCmd)
208208
}

cmd/agent_profile.go

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"fmt"
5+
"os"
56
"spark/internal/agent"
67
"spark/internal/tui"
78

@@ -11,6 +12,8 @@ import (
1112

1213
var profileType string
1314
var profileProject string
15+
var profileGlobal bool
16+
var profileForce bool
1417

1518
var agentProfileCmd = &cobra.Command{
1619
Use: "profile",
@@ -53,7 +56,12 @@ var agentProfileListCmd = &cobra.Command{
5356
var 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

148162
var 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

171204
var 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
}

docs/usage/agent.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# spark agent — AI Agent 配置管理
1+
# spark agent — AI Agent 配置管理 (已禁用)
2+
3+
> ⚠️ 此功能当前已禁用,命令入口已关闭。待后续重新设计后再启用。
24
35
管理多种 AI Agent 的配置文件(Claude Code、Codex、Kimi、GLM)。
46

internal/agent/agent.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ const (
1818
)
1919

2020
type AgentConfig struct {
21-
Name AgentType
22-
DisplayName string
23-
ConfigFiles []string
21+
Name AgentType
22+
DisplayName string
23+
ConfigFiles []string
24+
DefaultTemplates []string
2425
}
2526

2627
var AgentConfigs = map[AgentType]AgentConfig{
@@ -32,20 +33,31 @@ var AgentConfigs = map[AgentType]AgentConfig{
3233
".claude/settings.json",
3334
".claude/settings.local.json",
3435
},
36+
DefaultTemplates: []string{
37+
"{}",
38+
"{\n \"permissions\": {\n \"allow\": [],\n \"deny\": []\n }\n}",
39+
"{\n \"permissions\": {\n \"allow\": [],\n \"deny\": []\n }\n}",
40+
},
3541
},
3642
AgentCodex: {
3743
Name: AgentCodex,
3844
DisplayName: "OpenAI Codex",
3945
ConfigFiles: []string{
4046
".codex/config.toml",
4147
},
48+
DefaultTemplates: []string{
49+
"# Codex configuration\n# model = \"codex-mini-latest\"\n",
50+
},
4251
},
4352
AgentKimi: {
4453
Name: AgentKimi,
4554
DisplayName: "Kimi CLI",
4655
ConfigFiles: []string{
4756
".kimi/config.toml",
4857
},
58+
DefaultTemplates: []string{
59+
"# Kimi CLI configuration\n# model = \"kimi-latest\"\n",
60+
},
4961
},
5062
AgentGLM: {
5163
Name: AgentGLM,
@@ -54,6 +66,10 @@ var AgentConfigs = map[AgentType]AgentConfig{
5466
".claude.json",
5567
".claude/settings.json",
5668
},
69+
DefaultTemplates: []string{
70+
"{}",
71+
"{\n \"permissions\": {\n \"allow\": [],\n \"deny\": []\n }\n}",
72+
},
5773
},
5874
}
5975

internal/agent/profile.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ func (m *Manager) GetProfilesDir() string {
2222
return filepath.Join(m.homeDir, ".spark", "profiles")
2323
}
2424

25+
func (m *Manager) DeleteProfile(name string) error {
26+
dir := filepath.Join(m.GetProfilesDir(), name)
27+
return os.RemoveAll(dir)
28+
}
29+
2530
func (m *Manager) ListProfiles() ([]Profile, error) {
2631
profilesDir := m.GetProfilesDir()
2732

@@ -105,14 +110,20 @@ func (m *Manager) AddProfile(name string, agent AgentType) error {
105110
return err
106111
}
107112

108-
// Try to copy from global config
109-
globalPath := configPaths[i]
110-
if content, err := os.ReadFile(globalPath); err == nil {
111-
os.WriteFile(targetPath, content, 0644)
112-
} else {
113-
// Create empty file
114-
os.WriteFile(targetPath, []byte{}, 0644)
113+
var content []byte
114+
if globalPath := configPaths[i]; globalPath != "" {
115+
if data, err := os.ReadFile(globalPath); err == nil && len(data) > 0 {
116+
content = data
117+
}
115118
}
119+
if len(content) == 0 && i < len(configDef.DefaultTemplates) {
120+
content = []byte(configDef.DefaultTemplates[i])
121+
}
122+
if len(content) == 0 {
123+
content = []byte{}
124+
}
125+
126+
os.WriteFile(targetPath, content, 0644)
116127
}
117128

118129
return nil

tasks/features/agent/agent.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Agent Task
2+
3+
## Bug Fix
4+
5+
fix bug when run command ```spark agent use GLM```
6+
7+
```
8+
spark agent use GLM
9+
panic: unable to redefine 'p' shorthand in "use" flagset: it's already used for "project" flag
10+
11+
goroutine 1 [running]:
12+
github.com/spf13/pflag.(*FlagSet).AddFlag(0x140001b8a00, 0x140001bcbe0)
13+
/Users/patrick/go/pkg/mod/github.com/spf13/pflag@v1.0.10/flag.go:904 +0x338
14+
github.com/spf13/cobra.(*Command).mergePersistentFlags.(*FlagSet).AddFlagSet.func2(0x140001bcbe0)
15+
/Users/patrick/go/pkg/mod/github.com/spf13/pflag@v1.0.10/flag.go:917 +0x40
16+
github.com/spf13/pflag.(*FlagSet).VisitAll(0x104cbd880?, 0x14000037af8)
17+
/Users/patrick/go/pkg/mod/github.com/spf13/pflag@v1.0.10/flag.go:320 +0xcc
18+
github.com/spf13/pflag.(*FlagSet).AddFlagSet(...)
19+
/Users/patrick/go/pkg/mod/github.com/spf13/pflag@v1.0.10/flag.go:915
20+
github.com/spf13/cobra.(*Command).mergePersistentFlags(0x104cbd880)å
21+
/Users/patrick/go/pkg/mod/github.com/spf13/cobra@v1.10.2/command.go:1901 +0x7c
22+
github.com/spf13/cobra.stripFlags({0x14000032ab0, 0x1, 0x1}, 0x104cbd880)
23+
/Users/patrick/go/pkg/mod/github.com/spf13/cobra@v1.10.2/command.go:678 +0x3c
24+
github.com/spf13/cobra.(*Command).Find.func1(0x104cbd880, {0x14000032ab0, 0x1, 0x1})
25+
/Users/patrick/go/pkg/mod/github.com/spf13/cobra@v1.10.2/command.go:761 +0x48
26+
github.com/spf13/cobra.(*Command).Find.func1(0x104cbbbc0, {0x140000770c0, 0x2, 0x2})
27+
/Users/patrick/go/pkg/mod/github.com/spf13/cobra@v1.10.2/command.go:769 +0xa4
28+
github.com/spf13/cobra.(*Command).Find.func1(0x104cbde40, {0x1400001e090, 0x3, 0x3})
29+
/Users/patrick/go/pkg/mod/github.com/spf13/cobra@v1.10.2/command.go:769 +0xa4
30+
github.com/spf13/cobra.(*Command).Find(0x104cbde40?, {0x1400001e090?, 0x1?, 0x2?})
31+
/Users/patrick/go/pkg/mod/github.com/spf13/cobra@v1.10.2/command.go:774 +0x3c
32+
github.com/spf13/cobra.(*Command).initCompleteCmd(0x104cbde40, {0x1400001e090, 0x3, 0x3})
33+
/Users/patrick/go/pkg/mod/github.com/spf13/cobra@v1.10.2/completions.go:297 +0x1e8
34+
github.com/spf13/cobra.(*Command).ExecuteC(0x104cbde40)
35+
/Users/patrick/go/pkg/mod/github.com/spf13/cobra@v1.10.2/command.go:1110 +0x154
36+
github.com/spf13/cobra.(*Command).Execute(...)
37+
/Users/patrick/go/pkg/mod/github.com/spf13/cobra@v1.10.2/command.go:1071
38+
spark/cmd.Execute()
39+
/Users/patrick/innate/spark-cli/cmd/root.go:29 +0x24
40+
main.main()
41+
/Users/patrick/innate/spark-cli/main.go:8 +0x1c
42+
```
43+
44+
After fix to verify:
45+
- run command ```spark agent use GLM```
46+
- ~/.claude/setting.json file is exsiting only to set the api key

0 commit comments

Comments
 (0)