mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
feat(config): Add support for env var configuration (#896)
* feat(config): Add support for env var configuration This commit introduces support for two environment variables, allowing users to override the default paths for picoclaw's home directory and configuration file. - `PICOCLAW_CONFIG`: Directly specifies the path to the `config.json` file. This is initialised first, takes precedence over the hardcoded path, and is ideal for containerized deployments or custom config management. - `PICOCLAW_HOME`: Overrides the root directory for all picoclaw data, (except the config) (e.g., `~/.picoclaw`). This is useful for portable installations or placing data in non-standard locations. This change provides greater flexibility for running picoclaw in various environments without being tied to the default home directory structure. * `README.md` updated explain PICOCLAW_CONFIG and PICOCLAW_HOME * docs: translate environment variables section to multiple languages --------- Co-authored-by: picoclaw <picoclaw@sipeed.com>
This commit is contained in:
@@ -575,6 +575,31 @@ Connectez PicoClaw au Réseau Social d'Agents simplement en envoyant un seul mes
|
||||
|
||||
Fichier de configuration : `~/.picoclaw/config.json`
|
||||
|
||||
### Variables d'Environnement
|
||||
|
||||
Vous pouvez remplacer les chemins par défaut à l'aide de variables d'environnement. Ceci est utile pour les installations portables, les déploiements conteneurisés ou l'exécution de picoclaw en tant que service système. Ces variables sont indépendantes et contrôlent différents chemins.
|
||||
|
||||
| Variable | Description | Chemin par Défaut |
|
||||
|-------------------|-----------------------------------------------------------------------------------------------------------------------------------------|---------------------------|
|
||||
| `PICOCLAW_CONFIG` | Remplace le chemin du fichier de configuration. Cela indique directement à picoclaw quel `config.json` charger, en ignorant tous les autres emplacements. | `~/.picoclaw/config.json` |
|
||||
| `PICOCLAW_HOME` | Remplace le répertoire racine des données picoclaw. Cela modifie l'emplacement par défaut du `workspace` et des autres répertoires de données. | `~/.picoclaw` |
|
||||
|
||||
**Exemples :**
|
||||
|
||||
```bash
|
||||
# Exécuter picoclaw en utilisant un fichier de configuration spécifique
|
||||
# Le chemin du workspace sera lu à partir de ce fichier de configuration
|
||||
PICOCLAW_CONFIG=/etc/picoclaw/production.json picoclaw gateway
|
||||
|
||||
# Exécuter picoclaw avec toutes ses données stockées dans /opt/picoclaw
|
||||
# La configuration sera chargée à partir du fichier par défaut ~/.picoclaw/config.json
|
||||
# Le workspace sera créé dans /opt/picoclaw/workspace
|
||||
PICOCLAW_HOME=/opt/picoclaw picoclaw agent
|
||||
|
||||
# Utiliser les deux pour une configuration entièrement personnalisée
|
||||
PICOCLAW_HOME=/srv/picoclaw PICOCLAW_CONFIG=/srv/picoclaw/main.json picoclaw gateway
|
||||
```
|
||||
|
||||
### Structure du Workspace
|
||||
|
||||
PicoClaw stocke les données dans votre workspace configuré (par défaut : `~/.picoclaw/workspace`) :
|
||||
|
||||
@@ -536,6 +536,31 @@ picoclaw gateway
|
||||
|
||||
設定ファイル: `~/.picoclaw/config.json`
|
||||
|
||||
### 環境変数
|
||||
|
||||
環境変数を使用してデフォルトのパスを上書きできます。これは、ポータブルインストール、コンテナ化されたデプロイメント、または picoclaw をシステムサービスとして実行する場合に便利です。これらの変数は独立しており、異なるパスを制御します。
|
||||
|
||||
| 変数 | 説明 | デフォルトパス |
|
||||
|-------------------|-----------------------------------------------------------------------------------------------------------------------------------------|---------------------------|
|
||||
| `PICOCLAW_CONFIG` | 設定ファイルへのパスを上書きします。これにより、picoclaw は他のすべての場所を無視して、指定された `config.json` をロードします。 | `~/.picoclaw/config.json` |
|
||||
| `PICOCLAW_HOME` | picoclaw データのルートディレクトリを上書きします。これにより、`workspace` やその他のデータディレクトリのデフォルトの場所が変更されます。 | `~/.picoclaw` |
|
||||
|
||||
**例:**
|
||||
|
||||
```bash
|
||||
# 特定の設定ファイルを使用して picoclaw を実行する
|
||||
# ワークスペースのパスはその設定ファイル内から読み込まれます
|
||||
PICOCLAW_CONFIG=/etc/picoclaw/production.json picoclaw gateway
|
||||
|
||||
# すべてのデータを /opt/picoclaw に保存して picoclaw を実行する
|
||||
# 設定はデフォルトの ~/.picoclaw/config.json からロードされます
|
||||
# ワークスペースは /opt/picoclaw/workspace に作成されます
|
||||
PICOCLAW_HOME=/opt/picoclaw picoclaw agent
|
||||
|
||||
# 両方を使用して完全にカスタマイズされたセットアップを行う
|
||||
PICOCLAW_HOME=/srv/picoclaw PICOCLAW_CONFIG=/srv/picoclaw/main.json picoclaw gateway
|
||||
```
|
||||
|
||||
### ワークスペース構成
|
||||
|
||||
PicoClaw は設定されたワークスペース(デフォルト: `~/.picoclaw/workspace`)にデータを保存します:
|
||||
|
||||
@@ -643,6 +643,31 @@ Connect Picoclaw to the Agent Social Network simply by sending a single message
|
||||
|
||||
Config file: `~/.picoclaw/config.json`
|
||||
|
||||
### Environment Variables
|
||||
|
||||
You can override default paths using environment variables. This is useful for portable installations, containerized deployments, or running picoclaw as a system service. These variables are independent and control different paths.
|
||||
|
||||
| Variable | Description | Default Path |
|
||||
|-------------------|-----------------------------------------------------------------------------------------------------------------------------------------|---------------------------|
|
||||
| `PICOCLAW_CONFIG` | Overrides the path to the configuration file. This directly tells picoclaw which `config.json` to load, ignoring all other locations. | `~/.picoclaw/config.json` |
|
||||
| `PICOCLAW_HOME` | Overrides the root directory for picoclaw data. This changes the default location of the `workspace` and other data directories. | `~/.picoclaw` |
|
||||
|
||||
**Examples:**
|
||||
|
||||
```bash
|
||||
# Run picoclaw using a specific config file
|
||||
# The workspace path will be read from within that config file
|
||||
PICOCLAW_CONFIG=/etc/picoclaw/production.json picoclaw gateway
|
||||
|
||||
# Run picoclaw with all its data stored in /opt/picoclaw
|
||||
# Config will be loaded from the default ~/.picoclaw/config.json
|
||||
# Workspace will be created at /opt/picoclaw/workspace
|
||||
PICOCLAW_HOME=/opt/picoclaw picoclaw agent
|
||||
|
||||
# Use both for a fully customized setup
|
||||
PICOCLAW_HOME=/srv/picoclaw PICOCLAW_CONFIG=/srv/picoclaw/main.json picoclaw gateway
|
||||
```
|
||||
|
||||
### Workspace Layout
|
||||
|
||||
PicoClaw stores data in your configured workspace (default: `~/.picoclaw/workspace`):
|
||||
|
||||
@@ -571,6 +571,31 @@ Conecte o PicoClaw a Rede Social de Agentes simplesmente enviando uma única men
|
||||
|
||||
Arquivo de configuração: `~/.picoclaw/config.json`
|
||||
|
||||
### Variáveis de Ambiente
|
||||
|
||||
Você pode substituir os caminhos padrão usando variáveis de ambiente. Isso é útil para instalações portáteis, implantações em contêineres ou para executar o picoclaw como um serviço do sistema. Essas variáveis são independentes e controlam caminhos diferentes.
|
||||
|
||||
| Variável | Descrição | Caminho Padrão |
|
||||
|-------------------|-----------------------------------------------------------------------------------------------------------------------------------------|---------------------------|
|
||||
| `PICOCLAW_CONFIG` | Substitui o caminho para o arquivo de configuração. Isso informa diretamente ao picoclaw qual `config.json` carregar, ignorando todos os outros locais. | `~/.picoclaw/config.json` |
|
||||
| `PICOCLAW_HOME` | Substitui o diretório raiz dos dados do picoclaw. Isso altera o local padrão do `workspace` e de outros diretórios de dados. | `~/.picoclaw` |
|
||||
|
||||
**Exemplos:**
|
||||
|
||||
```bash
|
||||
# Executar o picoclaw usando um arquivo de configuração específico
|
||||
# O caminho do workspace será lido de dentro desse arquivo de configuração
|
||||
PICOCLAW_CONFIG=/etc/picoclaw/production.json picoclaw gateway
|
||||
|
||||
# Executar o picoclaw com todos os seus dados armazenados em /opt/picoclaw
|
||||
# A configuração será carregada do ~/.picoclaw/config.json padrão
|
||||
# O workspace será criado em /opt/picoclaw/workspace
|
||||
PICOCLAW_HOME=/opt/picoclaw picoclaw agent
|
||||
|
||||
# Use ambos para uma configuração totalmente personalizada
|
||||
PICOCLAW_HOME=/srv/picoclaw PICOCLAW_CONFIG=/srv/picoclaw/main.json picoclaw gateway
|
||||
```
|
||||
|
||||
### Estrutura do Workspace
|
||||
|
||||
O PicoClaw armazena dados no workspace configurado (padrão: `~/.picoclaw/workspace`):
|
||||
|
||||
@@ -543,6 +543,31 @@ Kết nối PicoClaw với Mạng xã hội Agent chỉ bằng cách gửi một
|
||||
|
||||
File cấu hình: `~/.picoclaw/config.json`
|
||||
|
||||
### Biến môi trường
|
||||
|
||||
Bạn có thể ghi đè các đường dẫn mặc định bằng cách sử dụng các biến môi trường. Điều này hữu ích cho việc cài đặt di động, triển khai container hóa hoặc chạy picoclaw như một dịch vụ hệ thống. Các biến này độc lập và kiểm soát các đường dẫn khác nhau.
|
||||
|
||||
| Biến | Mô tả | Đường dẫn mặc định |
|
||||
|-------------------|-----------------------------------------------------------------------------------------------------------------------------------------|---------------------------|
|
||||
| `PICOCLAW_CONFIG` | Ghi đè đường dẫn đến file cấu hình. Điều này trực tiếp yêu cầu picoclaw tải file `config.json` nào, bỏ qua tất cả các vị trí khác. | `~/.picoclaw/config.json` |
|
||||
| `PICOCLAW_HOME` | Ghi đè thư mục gốc cho dữ liệu picoclaw. Điều này thay đổi vị trí mặc định của `workspace` và các thư mục dữ liệu khác. | `~/.picoclaw` |
|
||||
|
||||
**Ví dụ:**
|
||||
|
||||
```bash
|
||||
# Chạy picoclaw bằng một file cấu hình cụ thể
|
||||
# Đường dẫn workspace sẽ được đọc từ trong file cấu hình đó
|
||||
PICOCLAW_CONFIG=/etc/picoclaw/production.json picoclaw gateway
|
||||
|
||||
# Chạy picoclaw với tất cả dữ liệu được lưu trữ trong /opt/picoclaw
|
||||
# Cấu hình sẽ được tải từ ~/.picoclaw/config.json mặc định
|
||||
# Workspace sẽ được tạo tại /opt/picoclaw/workspace
|
||||
PICOCLAW_HOME=/opt/picoclaw picoclaw agent
|
||||
|
||||
# Sử dụng cả hai để có thiết lập tùy chỉnh hoàn toàn
|
||||
PICOCLAW_HOME=/srv/picoclaw PICOCLAW_CONFIG=/srv/picoclaw/main.json picoclaw gateway
|
||||
```
|
||||
|
||||
### Cấu trúc Workspace
|
||||
|
||||
PicoClaw lưu trữ dữ liệu trong workspace đã cấu hình (mặc định: `~/.picoclaw/workspace`):
|
||||
|
||||
@@ -317,6 +317,31 @@ PicoClaw 支持多种聊天平台,使您的 Agent 能够连接到任何地方
|
||||
|
||||
配置文件路径: `~/.picoclaw/config.json`
|
||||
|
||||
### 环境变量
|
||||
|
||||
你可以使用环境变量覆盖默认路径。这对于便携安装、容器化部署或将 picoclaw 作为系统服务运行非常有用。这些变量是独立的,控制不同的路径。
|
||||
|
||||
| 变量 | 描述 | 默认路径 |
|
||||
|-------------------|-----------------------------------------------------------------------------------------------------------------------------------------|---------------------------|
|
||||
| `PICOCLAW_CONFIG` | 覆盖配置文件的路径。这直接告诉 picoclaw 加载哪个 `config.json`,忽略所有其他位置。 | `~/.picoclaw/config.json` |
|
||||
| `PICOCLAW_HOME` | 覆盖 picoclaw 数据根目录。这会更改 `workspace` 和其他数据目录的默认位置。 | `~/.picoclaw` |
|
||||
|
||||
**示例:**
|
||||
|
||||
```bash
|
||||
# 使用特定的配置文件运行 picoclaw
|
||||
# 工作区路径将从该配置文件中读取
|
||||
PICOCLAW_CONFIG=/etc/picoclaw/production.json picoclaw gateway
|
||||
|
||||
# 在 /opt/picoclaw 中存储所有数据运行 picoclaw
|
||||
# 配置将从默认的 ~/.picoclaw/config.json 加载
|
||||
# 工作区将在 /opt/picoclaw/workspace 创建
|
||||
PICOCLAW_HOME=/opt/picoclaw picoclaw agent
|
||||
|
||||
# 同时使用两者进行完全自定义设置
|
||||
PICOCLAW_HOME=/srv/picoclaw PICOCLAW_CONFIG=/srv/picoclaw/main.json picoclaw gateway
|
||||
```
|
||||
|
||||
### 工作区布局 (Workspace Layout)
|
||||
|
||||
PicoClaw 将数据存储在您配置的工作区中(默认:`~/.picoclaw/workspace`):
|
||||
|
||||
@@ -19,6 +19,9 @@ var (
|
||||
)
|
||||
|
||||
func GetConfigPath() string {
|
||||
if configPath := os.Getenv("PICOCLAW_CONFIG"); configPath != "" {
|
||||
return configPath
|
||||
}
|
||||
home, _ := os.UserHomeDir()
|
||||
return filepath.Join(home, ".picoclaw", "config.json")
|
||||
}
|
||||
|
||||
@@ -95,3 +95,13 @@ func TestGetConfigPath_Windows(t *testing.T) {
|
||||
func TestGetVersion(t *testing.T) {
|
||||
assert.Equal(t, "dev", GetVersion())
|
||||
}
|
||||
|
||||
func TestGetConfigPath_WithEnv(t *testing.T) {
|
||||
t.Setenv("PICOCLAW_CONFIG", "/tmp/custom/config.json")
|
||||
t.Setenv("HOME", "/tmp/home") // Also set home to ensure env is preferred
|
||||
|
||||
got := GetConfigPath()
|
||||
want := "/tmp/custom/config.json"
|
||||
|
||||
assert.Equal(t, want, got)
|
||||
}
|
||||
|
||||
@@ -442,3 +442,28 @@ func TestDefaultConfig_DMScope(t *testing.T) {
|
||||
t.Errorf("Session.DMScope = %q, want 'per-channel-peer'", cfg.Session.DMScope)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDefaultConfig_WorkspacePath_Default(t *testing.T) {
|
||||
// Unset to ensure we test the default
|
||||
t.Setenv("PICOCLAW_HOME", "")
|
||||
// Set a known home for consistent test results
|
||||
t.Setenv("HOME", "/tmp/home")
|
||||
|
||||
cfg := DefaultConfig()
|
||||
want := filepath.Join("/tmp/home", ".picoclaw", "workspace")
|
||||
|
||||
if cfg.Agents.Defaults.Workspace != want {
|
||||
t.Errorf("Default workspace path = %q, want %q", cfg.Agents.Defaults.Workspace, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDefaultConfig_WorkspacePath_WithPicoclawHome(t *testing.T) {
|
||||
t.Setenv("PICOCLAW_HOME", "/custom/picoclaw/home")
|
||||
|
||||
cfg := DefaultConfig()
|
||||
want := "/custom/picoclaw/home/workspace"
|
||||
|
||||
if cfg.Agents.Defaults.Workspace != want {
|
||||
t.Errorf("Workspace path with PICOCLAW_HOME = %q, want %q", cfg.Agents.Defaults.Workspace, want)
|
||||
}
|
||||
}
|
||||
|
||||
+17
-1
@@ -5,12 +5,28 @@
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// DefaultConfig returns the default configuration for PicoClaw.
|
||||
func DefaultConfig() *Config {
|
||||
// Determine the base path for the workspace.
|
||||
// Priority: $PICOCLAW_HOME > ~/.picoclaw
|
||||
var homePath string
|
||||
if picoclawHome := os.Getenv("PICOCLAW_HOME"); picoclawHome != "" {
|
||||
homePath = picoclawHome
|
||||
} else {
|
||||
userHome, _ := os.UserHomeDir()
|
||||
homePath = filepath.Join(userHome, ".picoclaw")
|
||||
}
|
||||
workspacePath := filepath.Join(homePath, "workspace")
|
||||
|
||||
return &Config{
|
||||
Agents: AgentsConfig{
|
||||
Defaults: AgentDefaults{
|
||||
Workspace: "~/.picoclaw/workspace",
|
||||
Workspace: workspacePath,
|
||||
RestrictToWorkspace: true,
|
||||
Provider: "",
|
||||
Model: "",
|
||||
|
||||
Reference in New Issue
Block a user