agentGuard function
The gate that denies target under scope, or null when it is allowed
(gate 5). write says whether the call writes it.
Implementation
AgentScopeGate? agentGuard(
AgentScope scope,
AgentGuardTarget target, {
required bool write,
}) {
if (target.excluded) return AgentScopeGate.excluded;
if (write && !scope.allowWrite) return AgentScopeGate.write;
if (!scope.admitsKind(target.kind)) return AgentScopeGate.kind;
final ids = scope.allowedIds;
if (ids != null) {
final id = target.id;
final parentId = target.parentId;
final admitted = id != null
? ids.contains(id)
: parentId != null && ids.contains(parentId);
if (!admitted) return AgentScopeGate.id;
}
return null;
}