feat: add CI/CD workflows, persistent chat, shell completions, and testing
- Add Gitea CI workflow for testing, linting, and building
- Add release workflow for multi-platform builds and GitHub releases
- Implement persistent chat history with JSON storage
- Add shell completion generation for bash, zsh, fish, powershell
- Introduce custom error types and logging system
- Add interfaces for git and AI client for better testability
- Enhance config with temperature and timeout settings
- Add comprehensive unit tests for config, errors, git, grok, and logger
- Update README with installation, features, and development instructions
- Make model flag persistent across commands
- Add context timeouts to API requests
2026-03-01 12:17:22 +00:00
|
|
|
package logger
|
|
|
|
|
|
|
|
|
|
import (
|
2026-03-01 12:35:21 +00:00
|
|
|
"context"
|
|
|
|
|
"io"
|
|
|
|
|
"log/slog"
|
feat: add CI/CD workflows, persistent chat, shell completions, and testing
- Add Gitea CI workflow for testing, linting, and building
- Add release workflow for multi-platform builds and GitHub releases
- Implement persistent chat history with JSON storage
- Add shell completion generation for bash, zsh, fish, powershell
- Introduce custom error types and logging system
- Add interfaces for git and AI client for better testability
- Enhance config with temperature and timeout settings
- Add comprehensive unit tests for config, errors, git, grok, and logger
- Update README with installation, features, and development instructions
- Make model flag persistent across commands
- Add context timeouts to API requests
2026-03-01 12:17:22 +00:00
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
2026-03-01 12:35:21 +00:00
|
|
|
logger *slog.Logger
|
|
|
|
|
level = new(slog.LevelVar) // Allows dynamic level changes
|
feat: add CI/CD workflows, persistent chat, shell completions, and testing
- Add Gitea CI workflow for testing, linting, and building
- Add release workflow for multi-platform builds and GitHub releases
- Implement persistent chat history with JSON storage
- Add shell completion generation for bash, zsh, fish, powershell
- Introduce custom error types and logging system
- Add interfaces for git and AI client for better testability
- Enhance config with temperature and timeout settings
- Add comprehensive unit tests for config, errors, git, grok, and logger
- Update README with installation, features, and development instructions
- Make model flag persistent across commands
- Add context timeouts to API requests
2026-03-01 12:17:22 +00:00
|
|
|
)
|
|
|
|
|
|
2026-03-01 12:35:21 +00:00
|
|
|
// Init initializes the logger with the specified log level
|
|
|
|
|
func Init(logLevel string) error {
|
feat: add CI/CD workflows, persistent chat, shell completions, and testing
- Add Gitea CI workflow for testing, linting, and building
- Add release workflow for multi-platform builds and GitHub releases
- Implement persistent chat history with JSON storage
- Add shell completion generation for bash, zsh, fish, powershell
- Introduce custom error types and logging system
- Add interfaces for git and AI client for better testability
- Enhance config with temperature and timeout settings
- Add comprehensive unit tests for config, errors, git, grok, and logger
- Update README with installation, features, and development instructions
- Make model flag persistent across commands
- Add context timeouts to API requests
2026-03-01 12:17:22 +00:00
|
|
|
home, err := os.UserHomeDir()
|
|
|
|
|
if err != nil {
|
|
|
|
|
home = "."
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logDir := filepath.Join(home, ".config", "grokkit")
|
chore(lint): enhance golangci configuration and add security annotations
- Expand .golangci.yml with more linters (bodyclose, errcheck, etc.), settings for govet, revive, gocritic, gosec
- Add // nolint:gosec comments for intentional file operations and subprocesses
- Change file write permissions from 0644 to 0600 for better security
- Refactor loops, error handling, and test parallelism with t.Parallel()
- Minor fixes: ignore unused args, use errors.Is, adjust mkdir permissions to 0750
2026-03-04 20:00:32 +00:00
|
|
|
if err := os.MkdirAll(logDir, 0750); err != nil {
|
2026-03-01 12:35:21 +00:00
|
|
|
return err
|
feat: add CI/CD workflows, persistent chat, shell completions, and testing
- Add Gitea CI workflow for testing, linting, and building
- Add release workflow for multi-platform builds and GitHub releases
- Implement persistent chat history with JSON storage
- Add shell completion generation for bash, zsh, fish, powershell
- Introduce custom error types and logging system
- Add interfaces for git and AI client for better testability
- Enhance config with temperature and timeout settings
- Add comprehensive unit tests for config, errors, git, grok, and logger
- Update README with installation, features, and development instructions
- Make model flag persistent across commands
- Add context timeouts to API requests
2026-03-01 12:17:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logFile := filepath.Join(logDir, "grokkit.log")
|
chore(lint): enhance golangci configuration and add security annotations
- Expand .golangci.yml with more linters (bodyclose, errcheck, etc.), settings for govet, revive, gocritic, gosec
- Add // nolint:gosec comments for intentional file operations and subprocesses
- Change file write permissions from 0644 to 0600 for better security
- Refactor loops, error handling, and test parallelism with t.Parallel()
- Minor fixes: ignore unused args, use errors.Is, adjust mkdir permissions to 0750
2026-03-04 20:00:32 +00:00
|
|
|
file, err := os.OpenFile(logFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600)
|
feat: add CI/CD workflows, persistent chat, shell completions, and testing
- Add Gitea CI workflow for testing, linting, and building
- Add release workflow for multi-platform builds and GitHub releases
- Implement persistent chat history with JSON storage
- Add shell completion generation for bash, zsh, fish, powershell
- Introduce custom error types and logging system
- Add interfaces for git and AI client for better testability
- Enhance config with temperature and timeout settings
- Add comprehensive unit tests for config, errors, git, grok, and logger
- Update README with installation, features, and development instructions
- Make model flag persistent across commands
- Add context timeouts to API requests
2026-03-01 12:17:22 +00:00
|
|
|
if err != nil {
|
2026-03-01 12:35:21 +00:00
|
|
|
return err
|
feat: add CI/CD workflows, persistent chat, shell completions, and testing
- Add Gitea CI workflow for testing, linting, and building
- Add release workflow for multi-platform builds and GitHub releases
- Implement persistent chat history with JSON storage
- Add shell completion generation for bash, zsh, fish, powershell
- Introduce custom error types and logging system
- Add interfaces for git and AI client for better testability
- Enhance config with temperature and timeout settings
- Add comprehensive unit tests for config, errors, git, grok, and logger
- Update README with installation, features, and development instructions
- Make model flag persistent across commands
- Add context timeouts to API requests
2026-03-01 12:17:22 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-01 12:35:21 +00:00
|
|
|
// Parse log level
|
|
|
|
|
switch logLevel {
|
|
|
|
|
case "debug":
|
|
|
|
|
level.Set(slog.LevelDebug)
|
|
|
|
|
case "info":
|
|
|
|
|
level.Set(slog.LevelInfo)
|
|
|
|
|
case "warn":
|
|
|
|
|
level.Set(slog.LevelWarn)
|
|
|
|
|
case "error":
|
|
|
|
|
level.Set(slog.LevelError)
|
|
|
|
|
default:
|
|
|
|
|
level.Set(slog.LevelInfo)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create multi-writer for both file and stderr (if debug)
|
|
|
|
|
var w io.Writer = file
|
|
|
|
|
if logLevel == "debug" {
|
|
|
|
|
w = io.MultiWriter(file, os.Stderr)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Use JSON handler for structured logging
|
|
|
|
|
handler := slog.NewJSONHandler(w, &slog.HandlerOptions{
|
|
|
|
|
Level: level,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
logger = slog.New(handler)
|
|
|
|
|
slog.SetDefault(logger)
|
feat: add CI/CD workflows, persistent chat, shell completions, and testing
- Add Gitea CI workflow for testing, linting, and building
- Add release workflow for multi-platform builds and GitHub releases
- Implement persistent chat history with JSON storage
- Add shell completion generation for bash, zsh, fish, powershell
- Introduce custom error types and logging system
- Add interfaces for git and AI client for better testability
- Enhance config with temperature and timeout settings
- Add comprehensive unit tests for config, errors, git, grok, and logger
- Update README with installation, features, and development instructions
- Make model flag persistent across commands
- Add context timeouts to API requests
2026-03-01 12:17:22 +00:00
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-01 12:35:21 +00:00
|
|
|
// SetLevel changes the log level dynamically
|
|
|
|
|
func SetLevel(logLevel string) {
|
|
|
|
|
switch logLevel {
|
|
|
|
|
case "debug":
|
|
|
|
|
level.Set(slog.LevelDebug)
|
|
|
|
|
case "info":
|
|
|
|
|
level.Set(slog.LevelInfo)
|
|
|
|
|
case "warn":
|
|
|
|
|
level.Set(slog.LevelWarn)
|
|
|
|
|
case "error":
|
|
|
|
|
level.Set(slog.LevelError)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Debug logs at debug level with structured fields
|
|
|
|
|
func Debug(msg string, args ...any) {
|
|
|
|
|
if logger != nil {
|
|
|
|
|
logger.Debug(msg, args...)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Info logs at info level with structured fields
|
|
|
|
|
func Info(msg string, args ...any) {
|
|
|
|
|
if logger != nil {
|
|
|
|
|
logger.Info(msg, args...)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Warn logs at warn level with structured fields
|
|
|
|
|
func Warn(msg string, args ...any) {
|
|
|
|
|
if logger != nil {
|
|
|
|
|
logger.Warn(msg, args...)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Error logs at error level with structured fields
|
|
|
|
|
func Error(msg string, args ...any) {
|
|
|
|
|
if logger != nil {
|
|
|
|
|
logger.Error(msg, args...)
|
feat: add CI/CD workflows, persistent chat, shell completions, and testing
- Add Gitea CI workflow for testing, linting, and building
- Add release workflow for multi-platform builds and GitHub releases
- Implement persistent chat history with JSON storage
- Add shell completion generation for bash, zsh, fish, powershell
- Introduce custom error types and logging system
- Add interfaces for git and AI client for better testability
- Enhance config with temperature and timeout settings
- Add comprehensive unit tests for config, errors, git, grok, and logger
- Update README with installation, features, and development instructions
- Make model flag persistent across commands
- Add context timeouts to API requests
2026-03-01 12:17:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-01 12:35:21 +00:00
|
|
|
// With returns a logger with additional context fields
|
|
|
|
|
func With(args ...any) *slog.Logger {
|
|
|
|
|
if logger != nil {
|
|
|
|
|
return logger.With(args...)
|
feat: add CI/CD workflows, persistent chat, shell completions, and testing
- Add Gitea CI workflow for testing, linting, and building
- Add release workflow for multi-platform builds and GitHub releases
- Implement persistent chat history with JSON storage
- Add shell completion generation for bash, zsh, fish, powershell
- Introduce custom error types and logging system
- Add interfaces for git and AI client for better testability
- Enhance config with temperature and timeout settings
- Add comprehensive unit tests for config, errors, git, grok, and logger
- Update README with installation, features, and development instructions
- Make model flag persistent across commands
- Add context timeouts to API requests
2026-03-01 12:17:22 +00:00
|
|
|
}
|
2026-03-01 12:35:21 +00:00
|
|
|
return slog.Default()
|
feat: add CI/CD workflows, persistent chat, shell completions, and testing
- Add Gitea CI workflow for testing, linting, and building
- Add release workflow for multi-platform builds and GitHub releases
- Implement persistent chat history with JSON storage
- Add shell completion generation for bash, zsh, fish, powershell
- Introduce custom error types and logging system
- Add interfaces for git and AI client for better testability
- Enhance config with temperature and timeout settings
- Add comprehensive unit tests for config, errors, git, grok, and logger
- Update README with installation, features, and development instructions
- Make model flag persistent across commands
- Add context timeouts to API requests
2026-03-01 12:17:22 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-01 12:35:21 +00:00
|
|
|
// WithContext returns a logger with values from context
|
|
|
|
|
func WithContext(ctx context.Context) *slog.Logger {
|
|
|
|
|
if logger != nil {
|
|
|
|
|
return logger.With(slog.Any("context", ctx))
|
feat: add CI/CD workflows, persistent chat, shell completions, and testing
- Add Gitea CI workflow for testing, linting, and building
- Add release workflow for multi-platform builds and GitHub releases
- Implement persistent chat history with JSON storage
- Add shell completion generation for bash, zsh, fish, powershell
- Introduce custom error types and logging system
- Add interfaces for git and AI client for better testability
- Enhance config with temperature and timeout settings
- Add comprehensive unit tests for config, errors, git, grok, and logger
- Update README with installation, features, and development instructions
- Make model flag persistent across commands
- Add context timeouts to API requests
2026-03-01 12:17:22 +00:00
|
|
|
}
|
2026-03-01 12:35:21 +00:00
|
|
|
return slog.Default()
|
feat: add CI/CD workflows, persistent chat, shell completions, and testing
- Add Gitea CI workflow for testing, linting, and building
- Add release workflow for multi-platform builds and GitHub releases
- Implement persistent chat history with JSON storage
- Add shell completion generation for bash, zsh, fish, powershell
- Introduce custom error types and logging system
- Add interfaces for git and AI client for better testability
- Enhance config with temperature and timeout settings
- Add comprehensive unit tests for config, errors, git, grok, and logger
- Update README with installation, features, and development instructions
- Make model flag persistent across commands
- Add context timeouts to API requests
2026-03-01 12:17:22 +00:00
|
|
|
}
|