Resolving the current policy for queue, applying the updates in order:

- Update 1: base_delay=100, exponential=true, max_attempts=3, retryable_codes=[429,500].
- Update 2: cancel_wins=false, dedup_key="key", fifo_ties=false, priority_high_first=false.
- Update 3: dead_order="id", delay_cap=150.
- Update 4: cancel_wins=true, priority_high_first=true.
- Update 5: dedup_key="id", fifo_ties=true, stale_after=2000, stale_inclusive=false.
- Update 6: stale_after=1000, stale_inclusive=true.

Final policy: base_delay=100, exponential=true, max_attempts=3, retryable_codes=[429,500], cancel_wins=true, dedup_key="id", fifo_ties=true, priority_high_first=true, dead_order="id", delay_cap=150, stale_after=1000, stale_inclusive=true.

Implementation notes:
- Payload shape: `{now, jobs}`. I assume `now` is a top-level integer.
- Dedup keeps the last job per dedup_key value, with its original index.
- Survivors are processed in original index order.

{"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 = {base_delay:100,exponential:true,max_attempts:3,retryable_codes:[429,500],cancel_wins:true,dedup_key:'id',fifo_ties:true,priority_high_first:true,dead_order:'id',delay_cap:150,stale_after:1000,stale_inclusive:true};\n", "helpers.ts": "export function cmp(a: any, b: any): number { return a < b ? -1 : a > b ? 1 : 0; }\n", "core.ts": "import {cmp} from './helpers.ts';\nexport function run(payload: any, policy: any): any {\n  const now = payload.now;\n  const jobs: any[] = payload.jobs || [];\n  const last = new Map<any, number>();\n  jobs.forEach((j, i) => { last.set(j[policy.dedup_key], i); });\n  const sel: {j: any, i: number}[] = [];\n  jobs.forEach((j, i) => { if (last.get(j[policy.dedup_key]) === i) sel.push({j, i}); });\n  const ready: any[] = [], waiting: any[] = [], dead: any[] = [], cancelled: any[] = [];\n  for (const s of sel) {\n    const j = s.j;\n    const code = j.last_code || 0;\n    const retryable = policy.retryable_codes.includes(j.last_code);\n    if (j.cancelled && (policy.cancel_wins || !retryable)) { cancelled.push(s); continue; }\n    const age = now - j.created;\n    const stale = policy.stale_inclusive ? age >= policy.stale_after : age > policy.stale_after;\n    if (stale || j.attempt >= policy.max_attempts || (code !== 0 && !retryable)) { dead.push(s); continue; }\n    let due = j.due;\n    if (retryable && j.failed_at !== undefined && j.failed_at !== null) {\n      const mult = policy.exponential ? Math.pow(2, Math.max(0, j.attempt - 1)) : 1;\n      const d = Math.min(policy.base_delay * mult, policy.delay_cap);\n      due = Math.max(due === undefined || due === null ? 0 : due, j.failed_at + d);\n    }\n    if (due > now) waiting.push({s, at: due}); else ready.push(s);\n  }\n  ready.sort((a, b) => {\n    let c = cmp(a.j.priority, b.j.priority);\n    if (policy.priority_high_first) c = -c;\n    if (c) return c;\n    c = cmp(a.j.created, b.j.created);\n    if (!policy.fifo_ties) c = -c;\n    if (c) return c;\n    return a.i - b.i;\n  });\n  if (policy.dead_order === 'id') dead.sort((a, b) => cmp(a.j.id, b.j.id) || a.i - b.i);\n  else dead.sort((a, b) => a.i - b.i);\n  waiting.sort((a, b) => a.s.i - b.s.i);\n  cancelled.sort((a, b) => a.i - b.i);\n  return {\n    ready: ready.map(s => s.j.id),\n    waiting: waiting.map(w => ({id: w.s.j.id, at: w.at})),\n    dead: dead.map(s => s.j.id),\n    cancelled: cancelled.map(s => s.j.id)\n  };\n}\n"}}