blob: e0b6674c7caae9ee44dc446bfa4344840b26fab0 [file] [log] [blame]
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
}