Skip to content

Commit 14d1017

Browse files
authored
Merge pull request #37 from ourines/feat/config-export
feat: config export/import + MCP notification monitor
2 parents cf702fa + 6bb953f commit 14d1017

29 files changed

Lines changed: 3369 additions & 74 deletions

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ The root command dynamically selects behavior:
4949
codes
5050
├── init [--yes]
5151
├── update / version
52+
├── doctor # Run system diagnostics
5253
├── start (alias: s) # Launch Claude in directory or project alias
5354
├── profile (alias: pf) # add / select / test / list / remove
5455
├── project (alias: p) # add [name] [path] / list / remove

cmd/codes/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func init() {
2626
rootCmd.AddCommand(commands.InitCmd)
2727
rootCmd.AddCommand(commands.UpdateCmd)
2828
rootCmd.AddCommand(commands.VersionCmd)
29+
rootCmd.AddCommand(commands.DoctorCmd)
2930
rootCmd.AddCommand(commands.StartCmd)
3031
rootCmd.AddCommand(commands.ProfileCmd)
3132
rootCmd.AddCommand(commands.ProjectCmd)
@@ -37,6 +38,8 @@ func init() {
3738
rootCmd.AddCommand(commands.AgentCmd)
3839
rootCmd.AddCommand(commands.TaskSimpleCmd)
3940
rootCmd.AddCommand(commands.WorkflowCmd)
41+
rootCmd.AddCommand(commands.NotifyCmd)
42+
rootCmd.AddCommand(commands.NotifyCmd)
4043

4144
// 设置默认运行时行为
4245
rootCmd.Run = func(cmd *cobra.Command, args []string) {

internal/agent/daemon.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,9 @@ func (d *Daemon) writeNotification(task *Task, status, detail string) {
473473
}); err != nil {
474474
d.logger.Printf("notification: desktop notify error: %v", err)
475475
}
476+
477+
// Send webhook notifications (if configured)
478+
d.sendWebhookNotifications(status, task)
476479
}
477480

478481
// truncate shortens a string to maxLen, adding "..." if truncated.
@@ -483,3 +486,45 @@ func truncate(s string, maxLen int) string {
483486
}
484487
return s[:maxLen-3] + "..."
485488
}
489+
490+
// sendWebhookNotifications sends notifications to all configured webhooks.
491+
func (d *Daemon) sendWebhookNotifications(status string, task *Task) {
492+
webhooks, err := config.ListWebhooks()
493+
if err != nil || len(webhooks) == 0 {
494+
return
495+
}
496+
497+
// Determine event type
498+
eventType := "task_completed"
499+
if status == "failed" {
500+
eventType = "task_failed"
501+
}
502+
503+
notification := notify.Notification{
504+
Title: fmt.Sprintf("codes: Task %s", status),
505+
Message: fmt.Sprintf("[%s] #%d %s", d.TeamName, task.ID, task.Subject),
506+
Sound: false, // webhooks don't use sound
507+
}
508+
509+
for _, webhook := range webhooks {
510+
// Check event filter
511+
if len(webhook.Events) > 0 {
512+
allowed := false
513+
for _, event := range webhook.Events {
514+
if event == eventType {
515+
allowed = true
516+
break
517+
}
518+
}
519+
if !allowed {
520+
continue
521+
}
522+
}
523+
524+
// Send notification
525+
notifier := notify.NewWebhookNotifier(webhook.URL, webhook.Format)
526+
if err := notifier.Send(notification); err != nil {
527+
d.logger.Printf("webhook notification error (%s): %v", webhook.URL, err)
528+
}
529+
}
530+
}

0 commit comments

Comments
 (0)