platform

package
v0.1.0-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2026 License: MIT Imports: 9 Imported by: 0

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

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 BaseDir

func BaseDir() string

BaseDir returns the root configuration directory.

func CheckDaemonRunning

func CheckDaemonRunning() (int, bool)

CheckDaemonRunning returns the PID if the daemon is already running, 0 otherwise.

func DBPath

func DBPath() string

DBPath returns the full path to the SQLite database file.

func DataDir

func DataDir() string

DataDir returns the path to the data directory (SQLite DB).

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() 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(target, linkPath string) error

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 IsRunning

func IsRunning(pid int) bool

IsRunning checks if a process with the given PID is running.

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 PIDFile

func PIDFile() string

PIDFile returns the path to the PID file.

func ProjectDir

func ProjectDir(jobName string) string

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 PromptsDir

func PromptsDir() string

PromptsDir returns the path to the prompts directory.

func ProviderMapping

func ProviderMapping(providerID string) (dirAlias, fileAlias string)

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 ReadPID

func ReadPID() (int, error)

ReadPID reads the PID from the PID file.

func RemovePID

func RemovePID() error

RemovePID removes the PID file.

func SaveSettings

func SaveSettings(s Settings) error

SaveSettings writes settings to disk.

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 SetDebug

func SetDebug(enabled bool) error

SetDebug enables or disables debug logging.

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).

func WritePID

func WritePID() error

WritePID writes the current process ID to the PID file.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL