feat: cross-tool user identity via MAGNET_USER_ID / X-Magnet-User-ID - #1
Merged
Merged
Conversation
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.
Summary
chat_completionsnow readsX-Magnet-User-IDheader first; falls back tox-session-idwhen absent. The resolved value is used asraw_user_idbefore project-scoped hashing._default_user_id(read fromMAGNET_USER_IDenv var) in__init__. Added_resolve_user_id()helper. All public methods (add,async_add,search,get_all,delete_all,get_profile,get_injection,force_reflect,get_pending_signals,get_recommended_model) now acceptuser_id: str | None = Noneand resolve it via the helper.get_recommended_model(get_profile(project_id, user_id)→get_profile(user_id, project_id)).Usage
SDK:
export MAGNET_USER_ID=alice@company.comProxy:
Same user profile is recognized across Claude Code, Cursor, Codex — any tool that sets the same identifier.
Test plan
add()withoutuser_idwithMAGNET_USER_IDset — profile stored under correct tenantadd()withoutMAGNET_USER_IDand withoutuser_id— raisesValueErrorX-Magnet-User-IDheader — same hash as a request with that value asx-session-idX-Magnet-User-ID— falls back tox-session-idas before🤖 Generated with Claude Code