About 57 handlers decoded request bodies with no size limit, and the few
that had one each picked their own. They now go through decodeJSON with a
1 MiB default; handlers that need more keep their larger limit. An
oversized body gets 413 instead of whatever the handler returned for bad
JSON (MCP and plugin requests used to answer 400). Every other decode
error keeps the handler's existing status and message.
Addresses P1 and P2 from code review on the RWMutex commit:
P1 — Stream handlers now snapshot config under RLock before streaming:
- handleDiffStream: clone Targets map to prevent concurrent map panic
- handleCheckStream, handleAuditStream: snapshot source/projectRoot
- handleUpdateStream: snapshot source (per-item Lock already correct)
P2 — All read handlers now use narrow snapshot instead of defer RUnlock:
- RLock → copy needed fields to locals → RUnlock → do work with locals
- Prevents slow I/O (git fetch, version check, audit scan) from blocking
the auto-reload middleware's exclusive Lock on concurrent requests
Other changes:
- computeTargetDiff takes source parameter (no more s.cfg.Source access)
- Add cloneTargets() helper for safe map copying
- Add writeOpsLogTo/writeAuditLogTo for lock-free oplog writes
The save+reload+error-handling pattern was repeated 8 times across
handler_targets.go (3), handler_extras.go (2), and handler_hub_saved.go
(3). Extract into a single saveAndReloadConfig() method on Server.
One call site in handler_extras.go (extras create) retains separate
save/reload calls because it does MkdirAll between them.
Hub sources are now saved in config.yaml (both global and project),
replacing the Web UI's localStorage-based approach. This allows CLI
and UI to share the same hub list.
- Add HubConfig/HubEntry types and helper methods (resolve, add, remove)
- Add CLI subcommands: hub add/list/remove/default
- Search --hub now resolves saved labels (e.g. --hub team)
- Add REST API endpoints for hub CRUD (GET/PUT/POST/DELETE /api/hub/saved)
- Migrate SearchPage from localStorage to server API calls