MCPcopy Create free account
hub / github.com/diillson/chatcli / LoadFromFile

Method LoadFromFile

cli/hooks/manager.go:36–66  ·  view source on GitHub ↗

LoadFromFile loads hook configuration from a JSON settings file. The file should contain a "hooks" key at the top level.

(path string)

Source from the content-addressed store, hash-verified

34// LoadFromFile loads hook configuration from a JSON settings file.
35// The file should contain a "hooks" key at the top level.
36func (m *Manager) LoadFromFile(path string) error {
37 data, err := os.ReadFile(path) //#nosec G304 -- path supplied by user/agent through validated tool surface (boundary check upstream)
38 if err != nil {
39 if os.IsNotExist(err) {
40 return nil // No config file is fine
41 }
42 return fmt.Errorf("reading hooks config: %w", err)
43 }
44
45 var config HooksConfig
46 if err := json.Unmarshal(data, &config); err != nil {
47 return fmt.Errorf("parsing hooks config: %w", err)
48 }
49
50 m.mu.Lock()
51 m.hooks = config.Hooks
52 m.mu.Unlock()
53
54 enabledCount := 0
55 for _, h := range config.Hooks {
56 if h.IsEnabled() {
57 enabledCount++
58 }
59 }
60
61 if enabledCount > 0 {
62 m.logger.Info("Hooks loaded", zap.Int("total", len(config.Hooks)), zap.Int("enabled", enabledCount))
63 }
64
65 return nil
66}
67
68// LoadFromSettings loads hooks from the chatcli settings hierarchy.
69// Checks: workspace/.chatcli/hooks.json > ~/.chatcli/hooks.json

Callers 3

TestManager_LoadFromFileFunction · 0.95
LoadFromSettingsMethod · 0.95

Implementers 2

MockTokenManagerllm/token/mock_token_manager.go
TokenManagerllm/token/token_manager.go

Calls 5

ErrorfMethod · 0.80
LockMethod · 0.80
UnlockMethod · 0.80
IsEnabledMethod · 0.80
InfoMethod · 0.65

Tested by 2

TestManager_LoadFromFileFunction · 0.76