gomcp/internal/application/contextengine/config.go
DmitrL-dev 694e32be26 refactor: rename identity to syntrex, add root orchestration and CI/CD
- Rename Go module: sentinel-community/gomcp -> syntrex/gomcp (50+ files)
- Rename npm package: sentinel-dashboard -> syntrex-dashboard
- Update Cargo.toml repository URL to syntrex/syntrex
- Update all doc references from DmitrL-dev/AISecurity to syntrex
- Add root Makefile (build-all, test-all, lint-all, clean-all)
- Add MIT LICENSE
- Add .editorconfig (Go/Rust/TS/C cross-language)
- Add .github/workflows/ci.yml (Go + Rust + Dashboard)
- Add dashboard next.config.ts and .env.example
- Clean ARCHITECTURE.md: remove brain/immune/strike/micro-swarm, fix 61->67 engines
2026-03-11 15:30:49 +10:00

52 lines
1.3 KiB
Go

package contextengine
import (
"encoding/json"
"os"
ctxdomain "github.com/syntrex/gomcp/internal/domain/context"
)
// LoadConfig loads engine configuration from a JSON file.
// If the file does not exist, returns DefaultEngineConfig.
// If the file exists but is invalid, returns an error.
func LoadConfig(path string) (ctxdomain.EngineConfig, error) {
data, err := os.ReadFile(path)
if err != nil {
if os.IsNotExist(err) {
return ctxdomain.DefaultEngineConfig(), nil
}
return ctxdomain.EngineConfig{}, err
}
var cfg ctxdomain.EngineConfig
if err := json.Unmarshal(data, &cfg); err != nil {
return ctxdomain.EngineConfig{}, err
}
// Build skip set from deserialized SkipTools slice.
cfg.BuildSkipSet()
// If skip_tools was omitted in JSON, use defaults.
if cfg.SkipTools == nil {
cfg.SkipTools = ctxdomain.DefaultSkipTools()
cfg.BuildSkipSet()
}
if err := cfg.Validate(); err != nil {
return ctxdomain.EngineConfig{}, err
}
return cfg, nil
}
// SaveDefaultConfig writes the default configuration to a JSON file.
// Useful for bootstrapping .rlm/context.json.
func SaveDefaultConfig(path string) error {
cfg := ctxdomain.DefaultEngineConfig()
data, err := json.MarshalIndent(cfg, "", " ")
if err != nil {
return err
}
return os.WriteFile(path, data, 0o644)
}