StaticInstanceBuild a concise Markdown governance summary to inject into the agent's system prompt so the agent knows the user's personalized name, onboarding state, coordination posture, channel modes, and active narrowing rules.
Clear all cached policies (or a single (agentId, userId) pair across all or one provider).
OptionalagentId: stringOptionaluserId: stringOptionalprovider: IMetadataProviderCompare a proposed MJAIAgentUserPolicyEntity against baseline (or conservative self-onboarding
defaults when baseline === null) and return a list of human-readable policy-widening violations.
Used when an agent invokes Configure Agent User Policy on its own behalf so a prompt-injected
agent can narrow or personalize its policy during onboarding, but can NEVER loosen approval gates,
drop/weaken entity/action rules, unpause itself, or escalate channel/coordination modes.
Evaluate whether an agent running as contextUser may execute actionName with params.
Evaluate whether a user's CalendarChannelMode permits reading or mutating calendar events.
Evaluate whether a user's EmailChannelMode permits reading, drafting, or sending email.
Evaluate whether an agent running as contextUser may perform operation on entityName.
Enforces:
contextUser's MJ EntityPermission ceiling (hard ceiling — never widened)policy.Status & policy.DefaultDataAccessModeEntityAccessRules CRUD narrowingtimeWindows + outsideWindowBehavior)whereClause validated via SQLExpressionValidator + recordConditionExpression)deniedFields, readOnlyFields, requireApprovalFields)Returns the ID of the agent currently executing an action in this async call tree, if any.
Backed by AsyncLocalStorage on the server so concurrent agent turns and concurrent human
saves never bleed across async execution contexts.
Synchronously retrieve a cached policy for (agentId, userId) if loaded.
Optionalprovider: IMetadataProviderThe Global Object Store is a place to store global objects that need to be shared across the application. Depending on the execution environment, this could be the window object in a browser, or the global object in a node environment, or something else in other contexts. The key here is that in some cases static variables are not truly shared because it is possible that a given class might have copies of its code in multiple paths in a deployed application. This approach ensures that no matter how many code copies might exist, there is only one instance of the object in question by using the Global Object Store.
Load the active/configured MJAIAgentUserPolicyEntity for (agentId, userId).
Returns null when no policy row has been created yet or when lookup fails.
Prefer ResolvePolicyForAgentAndUser in authorization paths so lookup errors fail closed.
Applies one MJGlobal event to the cache. Public so the behaviour can be driven directly in tests.
Registers an async-local store (e.g. new AsyncLocalStorage<string>() from node:async_hooks)
used to track the active executing agent ID across async call trees without process-global bleed.
Load the active/configured MJAIAgentUserPolicyEntity for (agentId, userId) with an
explicit tri-state outcome (found | none | error).
Security-critical callers MUST check status === 'error' and fail closed rather than
treating a database or RunView failure as "no narrowing policy configured".
Optionaloptions: ResolvePolicyLookupOptionsExecutes fn inside an async-local executing-agent context so entity subclasses
(such as MJAIAgentUserPolicyEntityServer) can enforce self-only and non-widening rules
without interfering with concurrent human saves or sibling agent runs.
Put or update a policy entity in the in-memory cache.
Optionalprovider: IMetadataProviderCapture an immutable snapshot of permission-bearing fields on a policy entity before in-place mutation so DetectAgentPolicyWidening can compare against the baseline.
Reconstructs the pre-save AgentPolicyBaselineSnapshot of an existing (IsSaved === true)
policy entity from its EntityField.OldValue entries so entity-level Validate() / Save()
hooks can detect policy widening even after fields have already been mutated in memory.
Protected StaticgetReturns the singleton instance of the class. If the instance does not exist, it is created and stored in the Global Object Store. If className is provided it will be used as part of the key in the Global Object Store, otherwise the actual class name will be used. NOTE: the class name used by default is the lowest level of the object hierarchy, so if you have a class that extends another class, the lowest level class name will be used.
OptionalclassName: string
Singleton engine that loads and evaluates
MJ: AI Agent User Policiesrecords.