Documentation
¶
Overview ¶
Package platform provides PID file management and daemon process detection.
WritePID, ReadPID, and RemovePID handle lock file I/O for the daemon's PID file. IsRunning delegates to the platform-specific isProcessRunning implementation. CheckDaemonRunning combines PID file reading with liveness checking and automatically cleans up stale PID files from crashed daemons.
Package platform provides Unix process detection using a signal 0 probe.
On Unix systems, os.FindProcess always succeeds regardless of whether the process exists. The actual liveness check is performed by sending signal 0 via syscall.Signal(0), which returns nil only if the process is alive and the caller has permission to signal it.
Package platform provides cross-platform directory path resolution for the OpenCron's runtime configuration layout.
BaseDir returns the root configuration directory (with a test override mechanism). Derived paths include SchedulesDir, PromptsDir, LogsDir, SummaryDir, DataDir, DBPath, PIDFile, AgentsDir, AgentsFile, SkillsDir, ProjectsDir, and ProjectDir. EnsureDirs creates all required directories on first run. The actual default base directory is resolved by platform-specific implementations of defaultBaseDir.
Package platform provides the default base directory resolution for Linux and other Unix-like systems.
The configuration directory is determined by XDG_CONFIG_HOME if set, otherwise it falls back to ~/.opencrons.
Package platform provides JSON-based settings persistence via settings.json.
The Settings struct holds all application configuration: Debug and SetupComplete flags, Provider (AI provider ID), Messenger (Telegram bot token and allowed users), Chat (default model and effort level), and DaemonMode. LoadSettings and SaveSettings handle file I/O with sensible defaults for missing files. Convenience functions IsDebugEnabled, SetDebug, IsSetupComplete, GetMessengerConfig, and GetChatConfig provide targeted access with default value fallbacks.
Index ¶
- func AgentsDir() string
- func AgentsFile() string
- func BaseDir() string
- func CheckDaemonRunning() (int, bool)
- func DBPath() string
- func DataDir() string
- func EnsureDirs() error
- func EnsureProviderSymlinks() error
- func EnsureSymlink(target, linkPath string) error
- func IsDebugEnabled() bool
- func IsRunning(pid int) bool
- func IsSetupComplete() bool
- func LogsDir() string
- func MigrateFromV1Layout() error
- func PIDFile() string
- func ProjectDir(jobName string) string
- func ProjectsDir() string
- func PromptsDir() string
- func ProviderMapping(providerID string) (dirAlias, fileAlias string)
- func ReadPID() (int, error)
- func RemovePID() error
- func SaveSettings(s Settings) error
- func SchedulesDir() string
- func SetBaseDir(dir string)
- func SetDebug(enabled bool) error
- func SkillsDir() string
- func SummaryDir() string
- func WritePID() error
- type ChatSettings
- type MessengerSettings
- type ProviderSettings
- type Settings
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AgentsDir ¶
func AgentsDir() string
AgentsDir returns the path to the canonical .agents/ directory.
func AgentsFile ¶
func AgentsFile() string
AgentsFile returns the path to the canonical AGENTS.md file.
func CheckDaemonRunning ¶
CheckDaemonRunning returns the PID if the daemon is already running, 0 otherwise.
func EnsureDirs ¶
func EnsureDirs() error
EnsureDirs creates all required directories if they don't exist. It also runs the V1 migration and creates provider-specific symlinks.
func EnsureProviderSymlinks ¶
func EnsureProviderSymlinks() error
EnsureProviderSymlinks reads the provider ID from settings and creates provider-specific symlinks at the BaseDir root. For example, with "anthropic" it creates .claude/ → .agents/ and CLAUDE.md → AGENTS.md.
func EnsureSymlink ¶
EnsureSymlink creates a symlink at linkPath pointing to target, idempotently. If the link already exists and points to the correct target, it's a no-op. If it exists but points elsewhere (or is a regular file/dir), it's removed and recreated. Also handles hardlinks (Windows fallback) by checking inode identity.
func IsDebugEnabled ¶
func IsDebugEnabled() bool
IsDebugEnabled returns whether debug logging is on.
func IsSetupComplete ¶
func IsSetupComplete() bool
IsSetupComplete returns whether the first-run setup has been completed.
func LogsDir ¶
func LogsDir() string
LogsDir returns the path to the logs directory (stdout/stderr capture).
func MigrateFromV1Layout ¶
func MigrateFromV1Layout() error
MigrateFromV1Layout migrates the old workspace/ directory layout to the new canonical .agents/ + AGENTS.md layout at the BaseDir root.
V1 layout: BaseDir/workspace/.claude/ + BaseDir/workspace/CLAUDE.md V2 layout: BaseDir/.agents/ + BaseDir/AGENTS.md (with provider symlinks)
This is a no-op if the old workspace/ doesn't exist or .agents/ already exists.
func ProjectDir ¶
ProjectDir returns the path to a specific job's project directory. Reserved for future use — not yet created by EnsureDirs.
func ProjectsDir ¶
func ProjectsDir() string
ProjectsDir returns the path to the projects directory (per-job workspace data). Reserved for future use — not yet created by EnsureDirs.
func ProviderMapping ¶
ProviderMapping returns the provider-specific directory alias and file alias for a given provider ID. These are used to create symlinks from the canonical .agents/ and AGENTS.md to provider-specific names (e.g., .claude/ and CLAUDE.md). Returns empty strings for unknown providers (no symlinks created).
func SchedulesDir ¶
func SchedulesDir() string
SchedulesDir returns the path to the schedules directory.
func SetBaseDir ¶
func SetBaseDir(dir string)
SetBaseDir overrides the default base directory (for testing).
func SkillsDir ¶
func SkillsDir() string
SkillsDir returns the path to the skills directory inside .agents/.
func SummaryDir ¶
func SummaryDir() string
SummaryDir returns the path to the summary directory (execution summaries).
Types ¶
type ChatSettings ¶
type ChatSettings struct {
Model string `json:"model"` // "sonnet" | "opus" | "haiku"
Effort string `json:"effort"` // "low" | "medium" | "high" | "max"
}
ChatSettings holds default chat configuration.
func GetChatConfig ¶
func GetChatConfig() *ChatSettings
GetChatConfig returns the chat settings with defaults applied.
type MessengerSettings ¶
type MessengerSettings struct {
Type string `json:"type"` // "telegram" | ""
BotToken string `json:"bot_token"`
AllowedUsers map[string]bool `json:"allowed_users,omitempty"`
}
MessengerSettings holds messenger platform configuration.
func GetMessengerConfig ¶
func GetMessengerConfig() *MessengerSettings
GetMessengerConfig returns the messenger settings, or nil if not configured.
type ProviderSettings ¶
type ProviderSettings struct {
ID string `json:"id"` // "anthropic"
}
ProviderSettings holds AI provider configuration.
type Settings ¶
type Settings struct {
Debug bool `json:"debug"`
SetupComplete bool `json:"setup_complete"`
Provider *ProviderSettings `json:"provider,omitempty"`
Messenger *MessengerSettings `json:"messenger,omitempty"`
Chat *ChatSettings `json:"chat,omitempty"`
DaemonMode string `json:"daemon_mode,omitempty"`
}
Settings holds persisted application settings.
func LoadSettings ¶
func LoadSettings() Settings
LoadSettings reads settings from disk. Returns defaults if file doesn't exist.