Add Agent manager
Change-Id: Iaa68e9228165bd274f9c5be9d4320ef49a009ca8
diff --git a/server/cmd/commands/server.go b/server/cmd/commands/server.go
new file mode 100644
index 0000000..e0b6674
--- /dev/null
+++ b/server/cmd/commands/server.go
@@ -0,0 +1,70 @@
+package commands
+
+import (
+ "fmt"
+ "log/slog"
+ "os"
+ "os/signal"
+ "syscall"
+
+ "github.com/iomodo/staff/server"
+ "github.com/spf13/cobra"
+)
+
+var serverCmd = &cobra.Command{
+ Use: "server",
+ Short: "Start the Staff server with automatic agent startup",
+ Long: `Start the Staff server which automatically loads configuration from config.yaml
+and starts all configured agents to process tasks continuously.
+
+The server will:
+- Load agent configurations from config.yaml
+- Start all configured agents in the background
+- Continuously process assigned tasks
+- Create GitHub PRs for completed tasks
+- Run until manually stopped with Ctrl+C
+
+Example:
+ staff server # Start server with default config.yaml
+ staff server --config custom.yaml # Start server with custom config`,
+ RunE: runServer,
+}
+
+var configPath string
+
+func init() {
+ serverCmd.Flags().StringVarP(&configPath, "config", "c", "config.yaml", "Path to configuration file")
+ rootCmd.AddCommand(serverCmd)
+}
+
+func runServer(cmd *cobra.Command, args []string) error {
+ // Create logger
+ logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
+ Level: slog.LevelInfo,
+ }))
+
+ // Create server instance
+ srv, err := server.NewServer(logger, configPath)
+ if err != nil {
+ return fmt.Errorf("failed to create server: %w", err)
+ }
+
+ // Start server
+ if err := srv.Start(); err != nil {
+ return fmt.Errorf("failed to start server: %w", err)
+ }
+
+ // Setup graceful shutdown
+ sigChan := make(chan os.Signal, 1)
+ signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
+
+ logger.Info("Server is running. Press Ctrl+C to stop...")
+
+ // Wait for shutdown signal
+ <-sigChan
+
+ logger.Info("Shutdown signal received, stopping server...")
+ srv.Shutdown()
+
+ return nil
+}