{
  "files": {
    "main.ts": "import { run } from './core.ts';\nimport { POLICY } from './policy.ts';\n\nexport function evaluate(payload: any): any {\n  return run(payload, POLICY);\n}\n",
    "core.ts": "import { selectLast, compareIds } from './helpers.ts';\n\nexport function run(payload: any, policy: any): any {\n  const selected = selectLast(payload.jobs, policy.dedup_key);\n  const ready: Array<{ job: any; index: number }> = [];\n  const waiting: Array<{ id: string; at: number }> = [];\n  const dead: Array<{ job: any; index: number }> = [];\n  const cancelled: string[] = [];\n  const now = payload.now;\n\n  for (const entry of selected) {\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(job.id);\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 || (job.last_code !== 0 && !retryable)) {\n      dead.push(entry);\n      continue;\n    }\n\n    let due = job.due;\n    if (retryable) {\n      const multiplier = policy.exponential\n        ? 2 ** Math.max(0, job.attempt - 1)\n        : 1;\n      const delay = Math.min(policy.base_delay * multiplier, policy.delay_cap);\n      due = Math.max(due, job.failed_at + delay);\n    }\n\n    if (due > now) {\n      waiting.push({ id: job.id, 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    if (priority !== 0) return priority;\n    const created = policy.fifo_ties\n      ? a.job.created - b.job.created\n      : b.job.created - a.job.created;\n    return created || a.index - b.index;\n  });\n\n  dead.sort((a, b) => policy.dead_order === 'id'\n    ? compareIds(a.job.id, b.job.id) || a.index - b.index\n    : a.index - b.index);\n\n  return {\n    ready: ready.map(entry => entry.job.id),\n    waiting,\n    dead: dead.map(entry => entry.job.id),\n    cancelled\n  };\n}\n",
    "policy.ts": "export const POLICY: any = {\n  base_delay: 100,\n  cancel_wins: true,\n  dead_order: 'id',\n  dedup_key: 'id',\n  delay_cap: 150,\n  exponential: true,\n  fifo_ties: true,\n  max_attempts: 3,\n  priority_high_first: true,\n  retryable_codes: [429, 500],\n  stale_after: 1000,\n  stale_inclusive: true\n};\n",
    "helpers.ts": "export function selectLast(jobs: any[], field: string): Array<{ job: any; index: number }> {\n  const entries = new Map<any, { job: any; index: number }>();\n  jobs.forEach((job, index) => {\n    entries.set(job[field], { job, index });\n  });\n  return Array.from(entries.values()).sort((a, b) => a.index - b.index);\n}\n\nexport function compareIds(a: string, b: string): number {\n  return a < b ? -1 : a > b ? 1 : 0;\n}\n"
  }
}