Skip to content

refactor: unify Manager, remove globalManager singleton#110

Merged
cyyever merged 1 commit intomainfrom
refactor/unify-manager
Mar 20, 2026
Merged

refactor: unify Manager, remove globalManager singleton#110
cyyever merged 1 commit intomainfrom
refactor/unify-manager

Conversation

@cyyever
Copy link
Collaborator

@cyyever cyyever commented Mar 20, 2026

Summary

Merge the two build-tag-separated Manager implementations into one unified struct with functional options. Delete the libcrust stub. Remove all global manager state.

Before: manager.go (!libcrust, 296 lines) + manager_libcrust.go (libcrust, 25 lines) — two separate Manager structs behind build tags.

After: One manager.go (no build tag, 235 lines) + manager_init.go (!libcrust, daemon-only Init). Net -63 lines, 1 file deleted, 1 build tag removed.

Changes

  • Unified Manager with functional options: WithStorage, WithAPI, WithRetention, WithBuffering
  • http.Handler interface instead of *APIServer — gin never imported in Manager, mobile builds stay lightweight
  • SetAPI() method for circular deps (API server needs manager for plugin stats)
  • Deleted manager_libcrust.go stub
  • Removed globalManager, SetGlobalManager, GetGlobalManager, GetGlobalInterceptor
  • Rewrote tests to use NewManager() directly instead of global state

Build verification

  • go build . (CLI) — pass
  • CGO_ENABLED=0 go build -tags libcrust ./pkg/libcrust/ (mobile) — pass
  • go test -race -short ./... — all 30 packages pass

Test plan

  • All unit tests pass with race detector
  • All security E2E tests pass (full pipeline, mobile rules, interceptor)
  • CLI build succeeds
  • libcrust build succeeds (CGO_ENABLED=0)
  • Pre-commit hooks pass

Merge security/manager.go (!libcrust) and manager_libcrust.go (libcrust)
into one unified Manager with functional options:

- NewManager(interceptor, registry, blockMode, ...opts)
- WithStorage, WithAPI, WithRetention, WithBuffering options
- SetAPI() for circular deps (API server needs manager reference)

Manager uses http.Handler interface (not *APIServer) so gin is never
imported in the Manager file. Mobile/GUI builds stay lightweight.

Delete manager_libcrust.go stub. Move daemon-only Init() to
manager_init.go (!libcrust). Remove globalManager, SetGlobalManager,
GetGlobalManager, GetGlobalInterceptor.
@cyyever cyyever merged commit efe76e9 into main Mar 20, 2026
15 of 16 checks passed
@cyyever cyyever deleted the refactor/unify-manager branch March 20, 2026 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant