Refactor DIFC/guard helper ownership to restore package boundaries#6749
Merged
Conversation
6 tasks
Copilot
AI
changed the title
[WIP] Refactor CLI layer to improve domain logic separation
Refactor DIFC/guard helper ownership to restore package boundaries
May 30, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors layering by relocating helpers to their proper domain packages: DIFC default-mode and sink-server-ID parsing move from internal/cmd into internal/difc; the policy→map conversion moves from internal/guard into internal/config (along with a config-local integrity-levels list); and ExtractErrorMessage (plus its log-cleanup regexes) moves out of rpc_helpers.go into a new log_cleanup.go within internal/logger. Tests are migrated alongside the code, and CLI sites are updated to call the new domain APIs.
Changes:
- Move DIFC defaults/parsing into
internal/difcand update CLI wiring; remove cmd-local wrappers. - Move policy marshaling into
internal/configasGuardPolicyToMapand add a config-localallowedGuardPolicyIntegrityLevelsto break the config→guard dependency. - Move
ExtractErrorMessageand its precompiled regexes intointernal/logger/log_cleanup.go.
Show a summary per file
| File | Description |
|---|---|
| internal/logger/rpc_helpers.go | Removes ExtractErrorMessage, regexes, and unused imports. |
| internal/logger/log_cleanup.go | New home for ExtractErrorMessage and log-cleanup regexes. |
| internal/guard/wasm_payload.go | Switches to config.GuardPolicyToMap. |
| internal/difc/sink_server_ids.go | Adds ParseSinkServerIDs with validation/dedup. |
| internal/difc/sink_server_ids_test.go | Tests for ParseSinkServerIDs. |
| internal/difc/evaluator.go | Adds DefaultEnforcementMode reading MCP_GATEWAY_GUARDS_MODE. |
| internal/difc/evaluator_test.go | Tests for DefaultEnforcementMode. |
| internal/config/guard_policy_validation.go | Uses local integrity-levels list instead of guard.AllowedIntegrityLevels. |
| internal/config/guard_policy_parse.go | Same: drops internal/guard import, uses local list. |
| internal/config/guard_policy_parse_test.go | Updates expectation to local list. |
| internal/config/guard_policy_marshal.go | Moves PolicyToMap here as GuardPolicyToMap. |
| internal/config/guard_policy_marshal_test.go | Test moved into config package. |
| internal/config/guard_policy_integrity_levels.go | New local integrity-levels list. |
| internal/cmd/root.go | Calls difc.ParseEnforcementMode/ParseSinkServerIDs directly. |
| internal/cmd/proxy.go | Same direct call to difc.ParseEnforcementMode. |
| internal/cmd/flags.go | Updates exception comment to reference difc.DefaultEnforcementMode(). |
| internal/cmd/flags_difc.go | Removes cmd-local helpers; uses difc.DefaultEnforcementMode(). |
| internal/cmd/flags_difc_test.go | Drops removed-helper tests; redirects sink-id test to difc.ParseSinkServerIDs. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 18/18 changed files
- Comments generated: 0
This was referenced May 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Static analysis flagged domain logic living in
internal/cmdand a guard-policy utility living ininternal/guard, creating avoidable layering leaks. This PR rehomes those functions into their domain packages and removes thin CLI indirection.DIFC defaults and parsing moved out of CLI
difc.DefaultEnforcementMode()anddifc.ParseSinkServerIDs(...).getDefaultDIFCMode,parseDIFCSinkServerIDs, and wrapper-only mode validator).Guard policy map marshaling moved to config
config.GuardPolicyToMap(...).guard.PolicyToMaphelper.Logger utility placement corrected
ExtractErrorMessageout ofrpc_helpers.gointolog_cleanup.goto align file semantics with function behavior.Dependency direction cleanup
internal/guardintointernal/config.