blob: ace8904aa8e897ea3a3c1751a3f161699eb7636f [file] [log] [blame]
iomodo90de9152025-07-31 13:20:01 +04001package app
2
3import (
4 "fmt"
5 "log/slog"
6
7 "github.com/iomodo/staff/agent"
8 "github.com/iomodo/staff/config"
9 "github.com/iomodo/staff/git"
iomodo13a10fc2025-07-31 17:47:06 +040010 "github.com/iomodo/staff/tm"
iomodo90de9152025-07-31 13:20:01 +040011 "github.com/iomodo/staff/tm/git_tm"
12)
13
14// App type defines application global state
15type App struct {
iomodo13a10fc2025-07-31 17:47:06 +040016 logger *slog.Logger
17 config *config.Config
18 manager *agent.Manager
19 git git.GitInterface
20 taskManager tm.TaskManager
iomodo90de9152025-07-31 13:20:01 +040021}
22
23// NewApp creates new App
24func NewApp(config *config.Config, logger *slog.Logger) (*App, error) {
25 // Create task manager using config
26 gitInterface := git.New(config, logger)
27 taskManager := git_tm.NewGitTaskManager(gitInterface, config, logger)
28
29 manager, err := agent.NewManager(config, taskManager, logger)
30 if err != nil {
31 return nil, fmt.Errorf("failed to create agent manager: %w", err)
32 }
33
34 return &App{
iomodo13a10fc2025-07-31 17:47:06 +040035 logger: logger,
36 config: config,
37 manager: manager,
38 git: gitInterface,
39 taskManager: taskManager,
iomodo90de9152025-07-31 13:20:01 +040040 }, nil
41}
42
43func (a *App) Start() {
44 a.manager.StartAllAgents()
45}
46
47func (a *App) Stop() {
48 if a.manager != nil {
49 if err := a.manager.Close(); err != nil {
50 a.logger.Error("Error closing manager", slog.String("error", err.Error()))
51 }
52 }
53}