runDaemonSubcommand handles the "daemon" subcommand. Standalone because the scheduler daemon does not need an LLMManager (it doesn't run agent tasks until a CLI attaches and delegates a bridge).
(args []string)
| 312 | // because the scheduler daemon does not need an LLMManager (it doesn't |
| 313 | // run agent tasks until a CLI attaches and delegates a bridge). |
| 314 | func runDaemonSubcommand(args []string) { |
| 315 | i18n.Init() |
| 316 | |
| 317 | envFilePath := os.Getenv("CHATCLI_DOTENV") |
| 318 | if envFilePath == "" { |
| 319 | envFilePath = ".env" |
| 320 | } else if expanded, err := utils.ExpandPath(envFilePath); err == nil { |
| 321 | envFilePath = expanded |
| 322 | } |
| 323 | _ = godotenv.Load(envFilePath) |
| 324 | theme.InitFromEnv() |
| 325 | |
| 326 | logger, err := utils.InitializeLogger() |
| 327 | if err != nil { |
| 328 | fmt.Fprintf(os.Stderr, "Failed to initialize logger: %v\n", err) |
| 329 | os.Exit(1) |
| 330 | } |
| 331 | defer func() { |
| 332 | if err := logger.Sync(); err != nil { |
| 333 | msg := err.Error() |
| 334 | if !strings.Contains(msg, "/dev/stdout") && |
| 335 | !strings.Contains(msg, "/dev/stderr") && |
| 336 | !strings.Contains(msg, "invalid argument") && |
| 337 | !strings.Contains(msg, "inappropriate ioctl") { |
| 338 | fmt.Fprintf(os.Stderr, "Error closing logger: %v\n", err) |
| 339 | } |
| 340 | } |
| 341 | }() |
| 342 | |
| 343 | config.InitGlobal(logger) |
| 344 | config.Global.Load() |
| 345 | utils.ApplyGlobalTLSTrust(logger) |
| 346 | |
| 347 | ctx, cancel := context.WithCancel(context.Background()) |
| 348 | defer cancel() |
| 349 | |
| 350 | if err := cmd.RunDaemon(ctx, args, logger); err != nil { |
| 351 | fmt.Fprintf(os.Stderr, "Error: %v\n", err) |
| 352 | os.Exit(1) |
| 353 | } |
| 354 | } |
no test coverage detected