LoadFromFile loads hook configuration from a JSON settings file. The file should contain a "hooks" key at the top level.
(path string)
| 34 | // LoadFromFile loads hook configuration from a JSON settings file. |
| 35 | // The file should contain a "hooks" key at the top level. |
| 36 | func (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 |