config

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 5 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var HomeDirHook = os.UserHomeDir

HomeDirHook is used to determine the user's home directory. It can be overridden in tests to redirect config files.

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 GetProjectWorkspaceKey

func GetProjectWorkspaceKey() ([]byte, error)

GetProjectWorkspaceKey returns the workspace key for the current project directory.

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). Defaults to 1 (keychain) if not set.

func GetWorkspaceKey

func GetWorkspaceKey(workspaceID string) ([]byte, error)

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

func InitProjectConfig() error

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 SaveGlobalConfig

func SaveGlobalConfig(config *GlobalConfig) error

SaveGlobalConfig writes ~/.agentsecrets/config.json

func SaveProjectConfig

func SaveProjectConfig(config *ProjectConfig) error

SaveProjectConfig writes .agentsecrets/project.json in the current directory.

func SaveTokens

func SaveTokens(tokens *TokenConfig) error

SaveTokens writes ~/.agentsecrets/token.json

func SetEmail

func SetEmail(email string) error

SetEmail stores the user's email in global config.

func SetSelectedWorkspaceID

func SetSelectedWorkspaceID(id string) error

SetSelectedWorkspaceID sets the selected workspace for new project creation.

func SetStorageMode

func SetStorageMode(mode int) error

SetStorageMode updates the storage mode in the global config.

func StoreTokens

func StoreTokens(accessToken, refreshToken, expiresAt string) error

StoreTokens saves authentication tokens.

func StoreWorkspaceCache

func StoreWorkspaceCache(workspaces map[string]WorkspaceCacheEntry) error

StoreWorkspaceCache saves decrypted workspace keys to global config.

Types

type GlobalConfig

type GlobalConfig struct {
	Email               string                         `json:"email,omitempty"`
	SelectedWorkspaceID string                         `json:"selected_workspace_id,omitempty"`
	Workspaces          map[string]WorkspaceCacheEntry `json:"workspaces,omitempty"`
	StorageMode         int                            `json:"storage_mode,omitempty"` // 1 = keychain (default), 2 = env_file
}

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

func GetPaths

func GetPaths() (*Paths, error)

GetPaths returns the standard config paths based on the user's home directory.

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"`
}

ProjectConfig represents ./.agentsecrets/project.json

func LoadProjectConfig

func LoadProjectConfig() (*ProjectConfig, error)

LoadProjectConfig reads .agentsecrets/project.json from the current directory.

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

Jump to

Keyboard shortcuts

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