{"version":3,"file":"gates.mjs","names":[],"sources":["../../../../../../../ai/src/team/gates.ts"],"sourcesContent":["import type { EvaluateContext, EvaluateResult } from \"../contracts/supervisor/evaluate-context.type\";\n\n/**\n * Build the `\"quality\"` gate — a review-then-fix `evaluate` callback.\n *\n * After each iteration's intents settle and merge into supervisor\n * `state`, the gate reads `state[gateKey]`. If truthy the run\n * terminates (`{ satisfied: true }`); otherwise it re-dispatches the\n * fixer with the reviewer feedback (`state[feedbackKey]`) threaded into\n * the next iteration's composed input. No termination or re-dispatch\n * code is written here — it leans entirely on the shipped\n * {@link EvaluateResult} semantics.\n *\n * @param gateKey - State key holding the reviewer verdict. Default `\"approved\"`.\n * @param fixerRole - Member key the gate reassigns to on rejection. Default `\"fixer\"`.\n * @param feedbackKey - State key holding reviewer feedback. Default `\"notes\"`.\n */\nexport function buildQualityGate<TState>(\n  gateKey = \"approved\",\n  fixerRole = \"fixer\",\n  feedbackKey = \"notes\",\n): (ctx: EvaluateContext<TState>) => EvaluateResult {\n  return (ctx) => {\n    const state = ctx.state as Record<string, unknown>;\n\n    if (state[gateKey]) {\n      return { satisfied: true };\n    }\n\n    return { reassignTo: fixerRole, feedback: String(state[feedbackKey] ?? \"\") };\n  };\n}\n\n/**\n * Build the `\"verify\"` gate — a test-then-fix `evaluate` callback.\n *\n * Identical in shape to {@link buildQualityGate} but keyed on the\n * tester's pass/fail slice (`state[gateKey]`, default `\"passed\"`)\n * rather than a subjective reviewer score. On failure it re-dispatches\n * the fixer; there is no feedback channel for the pass/fail signal, so\n * none is threaded forward.\n *\n * @param gateKey - State key holding the pass/fail verdict. Default `\"passed\"`.\n * @param fixerRole - Member key the gate reassigns to on failure. Default `\"fixer\"`.\n */\nexport function buildVerifyGate<TState>(\n  gateKey = \"passed\",\n  fixerRole = \"fixer\",\n): (ctx: EvaluateContext<TState>) => EvaluateResult {\n  return (ctx) => {\n    const state = ctx.state as Record<string, unknown>;\n\n    if (state[gateKey]) {\n      return { satisfied: true };\n    }\n\n    return { reassignTo: fixerRole };\n  };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,SAAgB,iBACd,UAAU,YACV,YAAY,SACZ,cAAc,SACoC;CAClD,QAAQ,QAAQ;EACd,MAAM,QAAQ,IAAI;EAElB,IAAI,MAAM,UACR,OAAO,EAAE,WAAW,KAAK;EAG3B,OAAO;GAAE,YAAY;GAAW,UAAU,OAAO,MAAM,gBAAgB,EAAE;EAAE;CAC7E;AACF;;;;;;;;;;;;;AAcA,SAAgB,gBACd,UAAU,UACV,YAAY,SACsC;CAClD,QAAQ,QAAQ;EAGd,IAFc,IAAI,MAER,UACR,OAAO,EAAE,WAAW,KAAK;EAG3B,OAAO,EAAE,YAAY,UAAU;CACjC;AACF"}