MCPcopy Index your code
hub / github.com/callstack/agent-device / applyRequestLockPolicy

Function applyRequestLockPolicy

src/daemon/request-lock-policy.ts:19–66  ·  view source on GitHub ↗
(
  req: DaemonRequest,
  existingSession?: SessionState,
)

Source from the content-addressed store, hash-verified

17type NormalizedLockPlatform = NonNullable<PlatformSelector>;
18
19export function applyRequestLockPolicy(
20 req: DaemonRequest,
21 existingSession?: SessionState,
22): DaemonRequest {
23 const lockPolicy = req.meta?.lockPolicy;
24 if (!lockPolicy) {
25 return req;
26 }
27
28 const nextFlags: CommandFlags = { ...(req.flags ?? {}) };
29 const canOverrideSelector = canOverrideLockPolicySelector(req.command);
30 const conflicts = canOverrideSelector
31 ? []
32 : existingSession
33 ? listSessionSelectorConflicts(existingSession, nextFlags)
34 : listFreshSessionConflicts(nextFlags, req.meta?.lockPlatform);
35 const lockPlatform = req.meta?.lockPlatform;
36
37 if (conflicts.length === 0) {
38 if (
39 shouldApplyLockPlatformDefault(canOverrideSelector, existingSession, nextFlags, lockPlatform)
40 ) {
41 nextFlags.platform = lockPlatform;
42 }
43 return {
44 ...req,
45 flags: nextFlags,
46 };
47 }
48
49 if (lockPolicy === 'strip') {
50 applyStripLockPolicy(nextFlags, conflicts, lockPlatform, existingSession);
51 return {
52 ...req,
53 flags: nextFlags,
54 };
55 }
56
57 throw new AppError(
58 'INVALID_ARGS',
59 buildLockPolicyConflictMessage(req, conflicts, existingSession),
60 {
61 session: req.session,
62 conflicts: conflicts.map(formatSessionSelectorConflict),
63 hint: buildLockPolicyConflictHint(req, existingSession),
64 },
65 );
66}
67
68function buildLockPolicyConflictMessage(
69 req: DaemonRequest,

Tested by

no test coverage detected