feat: opencode.config_dir — каталог с агентами (OPENCODE_CONFIG_DIR)
All checks were successful
CI / test (push) Successful in 43s
CI / build-and-package (amd64, darwin) (push) Successful in 40s
CI / build-and-package (amd64, linux) (push) Successful in 39s
CI / build-and-package (amd64, windows) (push) Successful in 41s
CI / build-and-package (arm64, darwin) (push) Successful in 42s
CI / build-and-package (arm64, linux) (push) Successful in 41s
All checks were successful
CI / test (push) Successful in 43s
CI / build-and-package (amd64, darwin) (push) Successful in 40s
CI / build-and-package (amd64, linux) (push) Successful in 39s
CI / build-and-package (amd64, windows) (push) Successful in 41s
CI / build-and-package (arm64, darwin) (push) Successful in 42s
CI / build-and-package (arm64, linux) (push) Successful in 41s
This commit is contained in:
@@ -9,6 +9,8 @@ telegram:
|
|||||||
# Всё ниже — опционально, показаны дефолты:
|
# Всё ниже — опционально, показаны дефолты:
|
||||||
# opencode:
|
# opencode:
|
||||||
# bin: "opencode"
|
# bin: "opencode"
|
||||||
|
# config: "/путь/к/opencode.json" # файл-конфиг модели (OPENCODE_CONFIG)
|
||||||
|
# config_dir: "./agents" # каталог с агентами (OPENCODE_CONFIG_DIR)
|
||||||
# hard_timeout: "20m"
|
# hard_timeout: "20m"
|
||||||
# idle_timeout: "2m"
|
# idle_timeout: "2m"
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ func New(configPath string) (*App, error) {
|
|||||||
Bin: cfg.OpenCode.Bin,
|
Bin: cfg.OpenCode.Bin,
|
||||||
DBPath: cfg.OpenCode.DBPath,
|
DBPath: cfg.OpenCode.DBPath,
|
||||||
Config: cfg.OpenCode.Config,
|
Config: cfg.OpenCode.Config,
|
||||||
|
ConfigDir: cfg.OpenCode.ConfigDir,
|
||||||
IdleTimeout: cfg.OpenCode.IdleTimeout.Duration(),
|
IdleTimeout: cfg.OpenCode.IdleTimeout.Duration(),
|
||||||
HardTimeout: cfg.OpenCode.HardTimeout.Duration(),
|
HardTimeout: cfg.OpenCode.HardTimeout.Duration(),
|
||||||
PollInterval: cfg.OpenCode.PollMs.Duration(),
|
PollInterval: cfg.OpenCode.PollMs.Duration(),
|
||||||
|
|||||||
@@ -80,6 +80,34 @@ telegram:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLoad_OpenCodeConfigDir(t *testing.T) {
|
||||||
|
t.Setenv("TG_TOKEN", "tok")
|
||||||
|
t.Setenv("TG_CHAT_ID", "42")
|
||||||
|
|
||||||
|
// без config_dir — пусто
|
||||||
|
yaml := `telegram:
|
||||||
|
token: "${TG_TOKEN}"
|
||||||
|
chat_id: "${TG_CHAT_ID}"
|
||||||
|
`
|
||||||
|
cfg, err := Load(writeCfg(t, yaml))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Load: %v", err)
|
||||||
|
}
|
||||||
|
if cfg.OpenCode.ConfigDir != "" {
|
||||||
|
t.Errorf("config_dir = %q, want пусто", cfg.OpenCode.ConfigDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
// через env OPENCODE_CONFIG_DIR
|
||||||
|
t.Setenv("OPENCODE_CONFIG_DIR", "/opt/agents")
|
||||||
|
cfg, err = Load(writeCfg(t, yaml))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Load: %v", err)
|
||||||
|
}
|
||||||
|
if cfg.OpenCode.ConfigDir != "/opt/agents" {
|
||||||
|
t.Errorf("config_dir = %q, want /opt/agents", cfg.OpenCode.ConfigDir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestLoad_EnvOverride(t *testing.T) {
|
func TestLoad_EnvOverride(t *testing.T) {
|
||||||
t.Setenv("TG_TOKEN", "tok")
|
t.Setenv("TG_TOKEN", "tok")
|
||||||
t.Setenv("TG_CHAT_ID", "42")
|
t.Setenv("TG_CHAT_ID", "42")
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ type OpenCodeCfg struct {
|
|||||||
Bin string `yaml:"bin" default:"opencode"`
|
Bin string `yaml:"bin" default:"opencode"`
|
||||||
DBPath string `yaml:"db_path" default:""`
|
DBPath string `yaml:"db_path" default:""`
|
||||||
Config string `yaml:"config" env:"OPENCODE_CONFIG"`
|
Config string `yaml:"config" env:"OPENCODE_CONFIG"`
|
||||||
|
ConfigDir string `yaml:"config_dir" env:"OPENCODE_CONFIG_DIR"`
|
||||||
HardTimeout Duration `yaml:"hard_timeout" default:"20m"`
|
HardTimeout Duration `yaml:"hard_timeout" default:"20m"`
|
||||||
IdleTimeout Duration `yaml:"idle_timeout" default:"2m"`
|
IdleTimeout Duration `yaml:"idle_timeout" default:"2m"`
|
||||||
PollMs Duration `yaml:"poll_ms" default:"2s"`
|
PollMs Duration `yaml:"poll_ms" default:"2s"`
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ type Runner struct {
|
|||||||
Bin string // путь к opencode (по умолчанию "opencode")
|
Bin string // путь к opencode (по умолчанию "opencode")
|
||||||
DBPath string // путь к opencode.db (idle-детекция активности)
|
DBPath string // путь к opencode.db (idle-детекция активности)
|
||||||
Config string // путь к opencode.json (OPENCODE_CONFIG)
|
Config string // путь к opencode.json (OPENCODE_CONFIG)
|
||||||
|
ConfigDir string // путь к каталогу с агентами (OPENCODE_CONFIG_DIR)
|
||||||
IdleTimeout time.Duration // нет новых сообщений в БД → зависание
|
IdleTimeout time.Duration // нет новых сообщений в БД → зависание
|
||||||
HardTimeout time.Duration // общий лимит на запуск
|
HardTimeout time.Duration // общий лимит на запуск
|
||||||
PollInterval time.Duration
|
PollInterval time.Duration
|
||||||
@@ -120,6 +121,9 @@ func (r *Runner) Run(ctx context.Context, prompt, cwd, agent, sessionID string)
|
|||||||
if r.Config != "" {
|
if r.Config != "" {
|
||||||
env = append(env, "OPENCODE_CONFIG="+r.Config)
|
env = append(env, "OPENCODE_CONFIG="+r.Config)
|
||||||
}
|
}
|
||||||
|
if r.ConfigDir != "" {
|
||||||
|
env = append(env, "OPENCODE_CONFIG_DIR="+r.ConfigDir)
|
||||||
|
}
|
||||||
|
|
||||||
proc := exec.CommandContext(ctx, cmd[0], cmd[1:]...)
|
proc := exec.CommandContext(ctx, cmd[0], cmd[1:]...)
|
||||||
proc.Env = env
|
proc.Env = env
|
||||||
|
|||||||
Reference in New Issue
Block a user