{"files":{"main.ts":"import { run } from './core.ts';\nimport { POLICY } from './policy.ts';\nexport function evaluate(payload: any): any { return run(payload, POLICY); }\n","core.ts":"import { deduplicate } from './helpers.ts';\n\nexport function run(payload: any, policy: any): any {\n  const ready: any[] = [];\n  const waiting: any[] = [];\n  const dead: any[] = [];\n  const cancelled: any[] = [];\n  const now = payload.now;\n\n  for (const entry of deduplicate(payload.jobs, policy.dedup_key)) {\n    const job = entry.job;\n    const retryable = policy.retryable_codes.includes(job.last_code);\n\n    if (job.cancelled && (policy.cancel_wins || !retryable)) {\n      cancelled.push(entry);\n      continue;\n    }\n\n    const age = now - job.created;\n    const stale = policy.stale_inclusive\n      ? age >= policy.stale_after\n      : age > policy.stale_after;\n    if (stale || job.attempt >= policy.max_attempts ||\n        (job.last_code !== 0 && !retryable)) {\n      dead.push(entry);\n      continue;\n    }\n\n    let due = job.due;\n    if (retryable) {\n      const factor = policy.exponential ? 2 ** Math.max(0, job.attempt - 1) : 1;\n      const delay = Math.min(policy.base_delay * factor, policy.delay_cap);\n      due = Math.max(due, job.failed_at + delay);\n    }\n\n    if (due > now) {\n      waiting.push({ ...entry, at: due });\n    } else {\n      ready.push(entry);\n    }\n  }\n\n  ready.sort((a, b) => {\n    const priority = policy.priority_high_first\n      ? b.job.priority - a.job.priority\n      : a.job.priority - b.job.priority;\n    const created = policy.fifo_ties\n      ? a.job.created - b.job.created\n      : b.job.created - a.job.created;\n    return priority || created || a.index - b.index;\n  });\n  dead.sort((a, b) => {\n    if (policy.dead_order === 'id') {\n      if (a.job.id < b.job.id) return -1;\n      if (a.job.id > b.job.id) return 1;\n    }\n    return a.index - b.index;\n  });\n  waiting.sort((a, b) => a.index - b.index);\n  cancelled.sort((a, b) => a.index - b.index);\n\n  return {\n    ready: ready.map(entry => entry.job.id),\n    waiting: waiting.map(entry => ({ id: entry.job.id, at: entry.at })),\n    dead: dead.map(entry => entry.job.id),\n    cancelled: cancelled.map(entry => entry.job.id)\n  };\n}\n","policy.ts":"export const POLICY: any = {\n  base_delay: 200,\n  exponential: false,\n  max_attempts: 4,\n  retryable_codes: [408, 503],\n  cancel_wins: false,\n  dedup_key: 'key',\n  fifo_ties: false,\n  priority_high_first: false,\n  dead_order: 'input',\n  delay_cap: 400,\n  stale_after: 2000,\n  stale_inclusive: false\n};\n","helpers.ts":"export function deduplicate(jobs: any[], field: string): { job: any; index: number }[] {\n  const selected = new Map<any, { job: any; index: number }>();\n  jobs.forEach((job, index) => {\n    selected.set(job[field], { job, index });\n  });\n  return Array.from(selected.values()).sort((a, b) => a.index - b.index);\n}\n"}}