Current policy after all updates:
- deny_wins: true
- expiry_inclusive: true
- inherit_roles: true
- owner_bypass: true
- action_casefold: true
- group_union: true
- resource_scope: exact
- suspended_denies: true
- token_ttl: 100
- wildcard_action: true
- audit_denials: true
- default_allow: true

Implementation notes:
- The early returns (tenant, token, suspended, owner) all have matched=[]. Audit is [reason] on denied results when audit_denials is on. An owner allow is not a denial, so its audit is [].
- Grants are read as {role, action, scope, expires, effect}. The effect field is assumed to be "allow" or "deny", and anything other than "deny" is treated as allow.
- With no matching grants, the result is default_allow with reason "default".

```json
{"files":{"main.ts":"import {run} from './core.ts';\nimport {POLICY} from './policy.ts';\nexport function evaluate(payload: any): any { return run(payload, POLICY); }\n","policy.ts":"export const POLICY: any = {\n  deny_wins: true,\n  expiry_inclusive: true,\n  inherit_roles: true,\n  owner_bypass: true,\n  action_casefold: true,\n  group_union: true,\n  resource_scope: 'exact',\n  suspended_denies: true,\n  token_ttl: 100,\n  wildcard_action: true,\n  audit_denials: true,\n  default_allow: true\n};\n","helpers.ts":"export function lower(s: any): string { return String(s).replace(/[A-Z]/g, (c) => c.toLowerCase()); }\n","core.ts":"import {lower} from './helpers.ts';\n\nexport function run(payload: any, policy: any): any {\n  const subject = payload.subject || {};\n  const resource = payload.resource || {};\n  const fin = (allowed: boolean, reason: string, matched: number[]) => ({\n    allowed,\n    reason,\n    matched,\n    audit: !allowed && policy.audit_denials ? [reason] : []\n  });\n  if (subject.tenant !== resource.tenant) return fin(false, 'tenant', []);\n  if (payload.now - payload.issued_at > policy.token_ttl) return fin(false, 'token', []);\n  if (policy.suspended_denies && subject.suspended) return fin(false, 'suspended', []);\n  if (policy.owner_bypass && subject.owner) return fin(true, 'owner', []);\n  let list: string[] = (subject.roles || []).slice();\n  if (policy.group_union) list = list.concat(subject.groups || []);\n  const roles = new Set<string>(list);\n  if (policy.inherit_roles) {\n    const parents = payload.role_parents || {};\n    const stack = Array.from(roles);\n    while (stack.length) {\n      const r = stack.pop() as string;\n      const ps = parents[r];\n      if (!Array.isArray(ps)) continue;\n      for (const p of ps) {\n        if (!roles.has(p)) { roles.add(p); stack.push(p); }\n      }\n    }\n  }\n  const grants = payload.grants || [];\n  const matched: number[] = [];\n  let anyAllow = false;\n  let anyDeny = false;\n  const act = policy.action_casefold ? lower(payload.action) : String(payload.action);\n  for (let i = 0; i < grants.length; i++) {\n    const g = grants[i];\n    if (!roles.has(g.role)) continue;\n    const ga = policy.action_casefold ? lower(g.action) : String(g.action);\n    const actionOk = ga === act || (policy.wildcard_action && g.action === '*');\n    if (!actionOk) continue;\n    const scope = String(g.scope === undefined || g.scope === null ? '' : g.scope);\n    const rid = String(resource.id);\n    const scopeOk = policy.resource_scope === 'prefix' ? rid.startsWith(scope) : scope === rid;\n    if (!scopeOk) continue;\n    const e = g.expires;\n    const expOk = e === null || e === undefined || (policy.expiry_inclusive ? payload.now <= e : payload.now < e);\n    if (!expOk) continue;\n    matched.push(i);\n    if (g.effect === 'deny') anyDeny = true; else anyAllow = true;\n  }\n  if (matched.length === 0) return fin(!!policy.default_allow, 'default', []);\n  const allowed = policy.deny_wins ? anyAllow && !anyDeny : anyAllow;\n  return fin(allowed, 'grants', matched);\n}\n"}}
```