Skip to content

Commit b995fdb

Browse files
committed
fix: eliminate all activate/init dead loops
- init: allow re-init with claim code whenever ClawAuth not active (regardless of API Key presence) - activate: on 401/invalid API Key, guide to init --claim-code instead of cryptic error - Both commands now always give a clear actionable next step
1 parent e5ad189 commit b995fdb

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

cmd/clawwork/main.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,23 +99,15 @@ func runInit(cmd *cobra.Command, _ []string) error {
9999

100100
scanner := bufio.NewScanner(os.Stdin)
101101

102-
// Existing agent: check if they can use activate or need to re-init
102+
// Existing agent: if already has ClawAuth, stop. Otherwise allow re-init.
103103
existingCfg, loadErr := config.Load()
104104
if loadErr == nil && existingCfg.Agent.Name != "" {
105-
hasClawAuth := existingCfg.Agent.PublicKey != "" && existingCfg.Agent.PrivateKey != ""
106-
hasApiKey := existingCfg.Agent.APIKey != ""
107-
if hasClawAuth {
105+
if existingCfg.Agent.PublicKey != "" && existingCfg.Agent.PrivateKey != "" {
108106
fmt.Printf(tr("Agent %s is already activated.\n", "Agent %s 已激活。\n"), existingCfg.Agent.Name)
109107
return nil
110108
}
111-
if hasApiKey {
112-
fmt.Printf(tr("Existing agent detected: %s\n", "检测到已有 Agent:%s\n"), existingCfg.Agent.Name)
113-
fmt.Println(tr("Run 'clawwork activate' to upgrade to ClawAuth.", "请运行 'clawwork activate' 升级到 ClawAuth。"))
114-
return nil
115-
}
116-
// No API Key and no ClawAuth — allow re-init with claim code
117-
fmt.Printf(tr("Agent %s found but no credentials. Re-initializing with claim code.\n",
118-
"检测到 Agent %s 但缺少凭证,使用认领码重新初始化。\n"), existingCfg.Agent.Name)
109+
fmt.Printf(tr("Agent %s found but ClawAuth not activated. Setting up with claim code.\n",
110+
"检测到 Agent %s 但 ClawAuth 未激活,使用认领码设置。\n"), existingCfg.Agent.Name)
119111
}
120112

121113
cfg := config.DefaultConfig()
@@ -1356,12 +1348,23 @@ func runActivate(_ *cobra.Command, _ []string) error {
13561348
}
13571349

13581350
if cfg.Agent.APIKey == "" {
1359-
return errors.New(tr("no API Key found in config. If you are a new user, run 'clawwork init --claim-code <code>' instead.", "配置中没有 API Key。新用户请运行 'clawwork init --claim-code <认领码>'。"))
1351+
fmt.Println(tr("No API Key in config. Use 'clawwork init --claim-code <code>' to activate.",
1352+
"配置中没有 API Key。请使用 'clawwork init --claim-code <认领码>' 激活。"))
1353+
fmt.Println(tr("Your owner can generate a claim code at https://work.clawplaza.ai/my-agent",
1354+
"Owner 可在 https://work.clawplaza.ai/my-agent 生成认领码"))
1355+
return nil
13601356
}
13611357

13621358
// Query activation cost from server
13631359
costInfo, err := queryActivationCost(cfg.Agent.APIKey)
13641360
if err != nil {
1361+
if strings.Contains(err.Error(), "401") || strings.Contains(err.Error(), "invalid") {
1362+
fmt.Println(tr("API Key is invalid or expired. Use 'clawwork init --claim-code <code>' instead.",
1363+
"API Key 无效或已过期。请使用 'clawwork init --claim-code <认领码>' 替代。"))
1364+
fmt.Println(tr("Your owner can generate a claim code at https://work.clawplaza.ai/my-agent",
1365+
"Owner 可在 https://work.clawplaza.ai/my-agent 生成认领码"))
1366+
return nil
1367+
}
13651368
return fmt.Errorf(tr("failed to query activation cost: %w", "查询激活费用失败:%w"), err)
13661369
}
13671370
if costInfo.Activated {

0 commit comments

Comments
 (0)