Documentation
¶
Overview ¶
Package config manages all configuration files for AgentSecrets.
This mirrors the Python SecretsCLI's config.py and parts of credentials.py.
File layout:
~/.agentsecrets/ ├── config.json # User email, workspace cache, selected workspace └── token.json # JWT access/refresh tokens ./.agentsecrets/ └── project.json # Project binding for current directory
Note: Private key is stored in OS keychain (see pkg/keyring), not in files.
Index ¶
- Variables
- func ClearProjectConfig() error
- func ClearSession() error
- func GetAccessToken() string
- func GetEmail() string
- func GetProjectRoot() (string, error)
- func GetProjectWorkspaceKey() ([]byte, error)
- func GetSelectedEnvironment() string
- func GetSelectedProjectID() string
- func GetSelectedWorkspaceID() string
- func GetStorageMode() int
- func GetWorkspaceKey(workspaceID string) ([]byte, error)
- func GlobalConfigExists() bool
- func InitGlobalConfig() error
- func InitProjectConfig(storageMode int) error
- func IsAuthenticated() bool
- func IsValidEnvironment(env string) bool
- func ResolveEnvironment() string
- func ResolveEnvironmentWithSource() (string, string)
- func SaveGlobalConfig(config *GlobalConfig) error
- func SaveProjectConfig(config *ProjectConfig) error
- func SaveTokens(tokens *TokenConfig) error
- func SetEmail(email string) error
- func SetProjectStorageMode(mode int) error
- func SetSelectedEnvironment(env string) error
- func SetSelectedProjectID(id string) error
- func SetSelectedWorkspaceID(id string) error
- func SetStorageMode(mode int) error
- func StoreTokens(accessToken, refreshToken, expiresAt string) error
- func StoreWorkspaceCache(workspaces map[string]WorkspaceCacheEntry) error
- type CheckResult
- type GitHubRelease
- type GlobalConfig
- type Paths
- type ProjectConfig
- type TokenConfig
- type WorkspaceCacheEntry
Constants ¶
This section is empty.
Variables ¶
var HomeDirHook = os.UserHomeDir
HomeDirHook is used to determine the user's home directory. It can be overridden in tests to redirect config files.
var ValidEnvironments = []string{"development", "staging", "production"}
ValidEnvironments is the list of valid environment names.
Functions ¶
func ClearProjectConfig ¶
func ClearProjectConfig() error
ClearProjectConfig resets the local .agentsecrets/project.json file.
func ClearSession ¶
func ClearSession() error
ClearSession removes all stored credentials (logout). Does NOT clear project.json.
func GetAccessToken ¶
func GetAccessToken() string
GetAccessToken returns the current access token, or empty string.
func GetEmail ¶
func GetEmail() string
GetEmail returns the stored user email, or empty string if not logged in.
func GetProjectRoot ¶ added in v1.1.2
GetProjectRoot walks up the directory tree from the current working directory. It returns the absolute or relative path to the nearest directory containing '.agentsecrets/project.json'. If none is found before reaching the filesystem root, it returns an empty string.
func GetProjectWorkspaceKey ¶
GetProjectWorkspaceKey returns the workspace key for the current project directory.
func GetSelectedEnvironment ¶ added in v1.1.2
func GetSelectedEnvironment() string
GetSelectedEnvironment returns the globally selected environment.
func GetSelectedProjectID ¶ added in v1.1.2
func GetSelectedProjectID() string
GetSelectedProjectID returns the globally selected project ID.
func GetSelectedWorkspaceID ¶
func GetSelectedWorkspaceID() string
GetSelectedWorkspaceID returns the selected workspace for new project creation.
func GetStorageMode ¶
func GetStorageMode() int
GetStorageMode returns the configured storage mode (1: keychain, 2: env_file). Resolution order: 1. AGENTSECRETS_STORAGE_MODE environment variable 2. .agentsecrets/project.json storage_mode 3. ~/.agentsecrets/config.json default_storage_mode 4. Default to 1 (keychain)
func GetWorkspaceKey ¶
GetWorkspaceKey returns the decrypted workspace key for a given workspace ID.
func GlobalConfigExists ¶
func GlobalConfigExists() bool
GlobalConfigExists returns true if ~/.agentsecrets/config.json already exists.
func InitGlobalConfig ¶
func InitGlobalConfig() error
InitGlobalConfig creates the ~/.agentsecrets/ directory and default config files.
func InitProjectConfig ¶
InitProjectConfig creates .agentsecrets/project.json in the current directory.
func IsAuthenticated ¶
func IsAuthenticated() bool
IsAuthenticated checks if the user has a valid session (token + email present).
func IsValidEnvironment ¶ added in v1.1.2
IsValidEnvironment returns true if the given string is a valid environment name.
func ResolveEnvironment ¶ added in v1.1.2
func ResolveEnvironment() string
ResolveEnvironment returns the active environment for the current context. Resolution order: 1. AGENTSECRETS_ENV environment variable 2. .agentsecrets/project.json environment field (walk up from cwd) 3. ~/.agentsecrets/config.json selected_environment 4. "development" (hardcoded default)
func ResolveEnvironmentWithSource ¶ added in v1.1.2
ResolveEnvironmentWithSource returns the active environment and its source. Sources: "AGENTSECRETS_ENV", "project.json", "global config", "default"
func SaveGlobalConfig ¶
func SaveGlobalConfig(config *GlobalConfig) error
SaveGlobalConfig writes ~/.agentsecrets/config.json
func SaveProjectConfig ¶
func SaveProjectConfig(config *ProjectConfig) error
SaveProjectConfig writes .agentsecrets/project.json to the nearest project root.
func SaveTokens ¶
func SaveTokens(tokens *TokenConfig) error
SaveTokens writes ~/.agentsecrets/token.json
func SetProjectStorageMode ¶ added in v1.1.2
SetProjectStorageMode updates the storage mode in the local project config.
func SetSelectedEnvironment ¶ added in v1.1.2
SetSelectedEnvironment sets the globally selected environment.
func SetSelectedProjectID ¶ added in v1.1.2
SetSelectedProjectID sets the globally selected project ID.
func SetSelectedWorkspaceID ¶
SetSelectedWorkspaceID sets the selected workspace for new project creation.
func SetStorageMode ¶
SetStorageMode updates the default storage mode in the global config.
func StoreTokens ¶
StoreTokens saves authentication tokens.
func StoreWorkspaceCache ¶
func StoreWorkspaceCache(workspaces map[string]WorkspaceCacheEntry) error
StoreWorkspaceCache saves decrypted workspace keys to global config.
Types ¶
type CheckResult ¶ added in v1.1.2
CheckResult represents the outcome of an update check
func CheckForUpdates ¶ added in v1.1.2
func CheckForUpdates(currentVersion string) (*CheckResult, error)
CheckForUpdates checks GitHub for a newer version of the CLI. It only performs the check if more than 24 hours have passed since the last one. Returns a CheckResult if a newer version is found, or nil if no check was performed or no update was found.
type GitHubRelease ¶ added in v1.1.2
type GitHubRelease struct {
TagName string `json:"tag_name"`
}
GitHubRelease represents the structure of a GitHub release from the API
type GlobalConfig ¶
type GlobalConfig struct {
Email string `json:"email,omitempty"`
SelectedWorkspaceID string `json:"selected_workspace_id,omitempty"`
SelectedProjectID string `json:"selected_project_id,omitempty"`
SelectedEnvironment string `json:"selected_environment,omitempty"` // "development", "staging", "production"
Workspaces map[string]WorkspaceCacheEntry `json:"workspaces,omitempty"`
PasswordHash string `json:"password_hash,omitempty"` // Added for local password verification
DefaultStorageMode int `json:"default_storage_mode"` // 1 = keychain (default), 2 = env_file
LastUpdateCheck int64 `json:"last_update_check,omitempty"`
LatestVersion string `json:"latest_version,omitempty"`
}
GlobalConfig represents ~/.agentsecrets/config.json
func LoadGlobalConfig ¶
func LoadGlobalConfig() (*GlobalConfig, error)
LoadGlobalConfig reads ~/.agentsecrets/config.json
type Paths ¶
type Paths struct {
GlobalDir string // ~/.agentsecrets/
ConfigFile string // ~/.agentsecrets/config.json
TokenFile string // ~/.agentsecrets/token.json
}
Paths returns the standard config file paths
type ProjectConfig ¶
type ProjectConfig struct {
ProjectID string `json:"project_id"`
ProjectName string `json:"project_name"`
Description string `json:"description"`
Environment string `json:"environment"` // "development", "staging", "production"
WorkspaceID string `json:"workspace_id"`
WorkspaceName string `json:"workspace_name"`
LastPull string `json:"last_pull"`
LastPush string `json:"last_push"`
StorageMode int `json:"storage_mode"`
}
ProjectConfig represents ./.agentsecrets/project.json
func LoadProjectConfig ¶
func LoadProjectConfig() (*ProjectConfig, error)
LoadProjectConfig reads .agentsecrets/project.json from the nearest project root.
type TokenConfig ¶
type TokenConfig struct {
AccessToken string `json:"access_token,omitempty"`
RefreshToken string `json:"refresh_token,omitempty"`
ExpiresAt string `json:"expires_at,omitempty"`
}
TokenConfig represents ~/.agentsecrets/token.json
func LoadTokens ¶
func LoadTokens() (*TokenConfig, error)
LoadTokens reads ~/.agentsecrets/token.json
type WorkspaceCacheEntry ¶
type WorkspaceCacheEntry struct {
Name string `json:"name"`
Key string `json:"key"` // Base64-encoded decrypted workspace key
Role string `json:"role"` // "owner", "admin", "member"
Type string `json:"type"` // "personal", "shared"
}
WorkspaceCacheEntry is a cached workspace with its decrypted key