chorus-codes 0.8.11 → 0.8.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/app-path-routes-manifest.json +2 -2
  3. package/.next/build-manifest.json +2 -2
  4. package/.next/prerender-manifest.json +3 -3
  5. package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  6. package/.next/server/app/_global-error.html +1 -1
  7. package/.next/server/app/_global-error.rsc +1 -1
  8. package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  9. package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  10. package/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  11. package/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  12. package/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  13. package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  14. package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  15. package/.next/server/app/_not-found.html +1 -1
  16. package/.next/server/app/_not-found.rsc +1 -1
  17. package/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  18. package/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  19. package/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  20. package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  21. package/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  22. package/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  23. package/.next/server/app/connect/page.js +1 -1
  24. package/.next/server/app/connect/page_client-reference-manifest.js +1 -1
  25. package/.next/server/app/demo/[scenario]/page_client-reference-manifest.js +1 -1
  26. package/.next/server/app/new/page.js +1 -1
  27. package/.next/server/app/new/page_client-reference-manifest.js +1 -1
  28. package/.next/server/app/new.html +1 -1
  29. package/.next/server/app/new.rsc +2 -2
  30. package/.next/server/app/new.segments/_full.segment.rsc +2 -2
  31. package/.next/server/app/new.segments/_head.segment.rsc +1 -1
  32. package/.next/server/app/new.segments/_index.segment.rsc +1 -1
  33. package/.next/server/app/new.segments/_tree.segment.rsc +1 -1
  34. package/.next/server/app/new.segments/new/__PAGE__.segment.rsc +2 -2
  35. package/.next/server/app/new.segments/new.segment.rsc +1 -1
  36. package/.next/server/app/onboarding/page.js +1 -1
  37. package/.next/server/app/onboarding/page_client-reference-manifest.js +1 -1
  38. package/.next/server/app/onboarding.html +1 -1
  39. package/.next/server/app/onboarding.rsc +2 -2
  40. package/.next/server/app/onboarding.segments/_full.segment.rsc +2 -2
  41. package/.next/server/app/onboarding.segments/_head.segment.rsc +1 -1
  42. package/.next/server/app/onboarding.segments/_index.segment.rsc +1 -1
  43. package/.next/server/app/onboarding.segments/_tree.segment.rsc +1 -1
  44. package/.next/server/app/onboarding.segments/onboarding/__PAGE__.segment.rsc +2 -2
  45. package/.next/server/app/onboarding.segments/onboarding.segment.rsc +1 -1
  46. package/.next/server/app/page.js +1 -1
  47. package/.next/server/app/page_client-reference-manifest.js +1 -1
  48. package/.next/server/app/personas/page_client-reference-manifest.js +1 -1
  49. package/.next/server/app/personas.html +1 -1
  50. package/.next/server/app/personas.rsc +2 -2
  51. package/.next/server/app/personas.segments/_full.segment.rsc +2 -2
  52. package/.next/server/app/personas.segments/_head.segment.rsc +1 -1
  53. package/.next/server/app/personas.segments/_index.segment.rsc +1 -1
  54. package/.next/server/app/personas.segments/_tree.segment.rsc +1 -1
  55. package/.next/server/app/personas.segments/personas/__PAGE__.segment.rsc +2 -2
  56. package/.next/server/app/personas.segments/personas.segment.rsc +1 -1
  57. package/.next/server/app/runs/[runId]/page_client-reference-manifest.js +1 -1
  58. package/.next/server/app/runs/page_client-reference-manifest.js +1 -1
  59. package/.next/server/app/settings/page_client-reference-manifest.js +1 -1
  60. package/.next/server/app/settings/permissions/page_client-reference-manifest.js +1 -1
  61. package/.next/server/app/settings.html +1 -1
  62. package/.next/server/app/settings.rsc +1 -1
  63. package/.next/server/app/settings.segments/_full.segment.rsc +1 -1
  64. package/.next/server/app/settings.segments/_head.segment.rsc +1 -1
  65. package/.next/server/app/settings.segments/_index.segment.rsc +1 -1
  66. package/.next/server/app/settings.segments/_tree.segment.rsc +1 -1
  67. package/.next/server/app/settings.segments/settings/__PAGE__.segment.rsc +1 -1
  68. package/.next/server/app/settings.segments/settings.segment.rsc +1 -1
  69. package/.next/server/app/templates/page.js +1 -1
  70. package/.next/server/app/templates/page_client-reference-manifest.js +1 -1
  71. package/.next/server/app/templates.html +1 -1
  72. package/.next/server/app/templates.rsc +2 -2
  73. package/.next/server/app/templates.segments/_full.segment.rsc +2 -2
  74. package/.next/server/app/templates.segments/_head.segment.rsc +1 -1
  75. package/.next/server/app/templates.segments/_index.segment.rsc +1 -1
  76. package/.next/server/app/templates.segments/_tree.segment.rsc +1 -1
  77. package/.next/server/app/templates.segments/templates/__PAGE__.segment.rsc +2 -2
  78. package/.next/server/app/templates.segments/templates.segment.rsc +1 -1
  79. package/.next/server/app-paths-manifest.json +2 -2
  80. package/.next/server/chunks/429.js +1 -1
  81. package/.next/server/chunks/597.js +1 -1
  82. package/.next/server/middleware-build-manifest.js +1 -1
  83. package/.next/server/pages/404.html +1 -1
  84. package/.next/server/pages/500.html +1 -1
  85. package/.next/server/server-reference-manifest.json +1 -1
  86. package/.next/static/chunks/{744-2b89d96d64610581.js → 744-73bacac02ba407ef.js} +1 -1
  87. package/.next/static/chunks/977-4887f24e0062c91d.js +1 -0
  88. package/.next/static/chunks/app/connect/page-ffca0d7a439c908e.js +1 -0
  89. package/.next/static/chunks/app/new/page-9d62ec50108c7961.js +1 -0
  90. package/.next/static/chunks/app/onboarding/{page-8794913af4e5d34c.js → page-4be5a1d944e32672.js} +1 -1
  91. package/.next/static/chunks/app/page-ad539065ba9128bb.js +1 -0
  92. package/.next/static/chunks/app/templates/page-67b63a2565d8de09.js +1 -0
  93. package/.next/trace +20 -20
  94. package/.next/trace-build +1 -1
  95. package/dist/daemon/agents/gemini.js +6 -4
  96. package/dist/daemon/agents/gemini.js.map +1 -1
  97. package/dist/daemon/runner/reviewer-driver.js +10 -31
  98. package/dist/daemon/runner/reviewer-driver.js.map +1 -1
  99. package/dist/lib/lineage-maps.js +7 -4
  100. package/dist/lib/lineage-maps.js.map +1 -1
  101. package/package.json +1 -1
  102. package/.next/static/chunks/977-e49df4d223b9e655.js +0 -1
  103. package/.next/static/chunks/app/connect/page-052be1ded639feb8.js +0 -1
  104. package/.next/static/chunks/app/new/page-2211cfc5ff439235.js +0 -1
  105. package/.next/static/chunks/app/page-f18ee044fb5c3f79.js +0 -1
  106. package/.next/static/chunks/app/templates/page-e6ce9f999d32c417.js +0 -1
  107. /package/.next/static/{rGBhTeiq5kxABJt7JbBEK → wxarGtmcGlWCzKSSy_MgS}/_buildManifest.js +0 -0
  108. /package/.next/static/{rGBhTeiq5kxABJt7JbBEK → wxarGtmcGlWCzKSSy_MgS}/_ssgManifest.js +0 -0
@@ -1 +0,0 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[814],{4538:(e,r,t)=>{"use strict";t.r(r),t.d(r,{default:()=>e5});var s=t(9442),a=t(6074),n=t(4052),o=t(3149),i=t(8420),d=t(4372),l=t(63),c=t(5702),u=t(6457),m=t(8191),x=t(9315),p=t(2865),h=t(6891),f=t(6458),g=t(4030),b=t(2956),v=t(1853),j=t(6185),y=t(599),w=t(2794);let N=w.ai().int().min(3e4).max(36e5).optional(),k=w.k5(["anthropic","openai","google","opencode","moonshot","openrouter","any"]),C=w.k5(["anthropic","openai","google","opencode","moonshot","openrouter"]),A=w.Ik({require:w.ai().int().min(0).default(1),crossLineage:w.zM().default(!0),candidates:w.YO(w.Ik({lineage:C,models:w.YO(w.Yj()).optional(),persona:w.Yj().optional()}))}),M=w.Ik({include:w.YO(w.Yj()).default([]),exclude:w.YO(w.Yj()).default([])}).default({include:[],exclude:[]}),S=w.Ik({maxRounds:w.ai().int().min(1).default(2),onDisagreement:w.k5(["continue","escalate","accept-doer"]).default("continue"),shareSessionAcrossRounds:w.zM().default(!0),shareSessionAcrossPhases:w.zM().default(!1)}).default({maxRounds:2,onDisagreement:"continue",shareSessionAcrossRounds:!0,shareSessionAcrossPhases:!1}),Y=w.Ik({id:w.Yj().min(1),kind:w.k5(["plan","spec","tests","implement","review","verify","divergence"]),title:w.Yj().min(1),description:w.Yj().optional(),doer:w.Ik({lineage:k,models:w.YO(w.Yj()).optional(),persona:w.Yj().optional()}),reviewer:A.optional(),inputs:M,iterate:S,timeoutMs:N}),L=w.Ik({id:w.Yj().min(1),kind:w.eu("review_only"),title:w.Yj().min(1),description:w.Yj().optional(),reviewer:A,artifact:w.Ik({label:w.Yj().min(1).default("Artifact to review"),hint:w.Yj().default("Paste a unified diff, a markdown draft, code, or any text blob."),maxBytes:w.ai().int().min(1).default(1048576)}).default({label:"Artifact to review",hint:"Paste a unified diff, a markdown draft, code, or any text blob.",maxBytes:1048576}),inputs:M,timeoutMs:N}),D=w.gM("kind",[Y.extend({kind:w.eu("plan")}),Y.extend({kind:w.eu("spec")}),Y.extend({kind:w.eu("tests")}),Y.extend({kind:w.eu("implement")}),Y.extend({kind:w.eu("review")}),Y.extend({kind:w.eu("verify")}),Y.extend({kind:w.eu("divergence")}),L]),R=w.Ik({id:w.Yj().min(1),name:w.Yj().min(1),description:w.Yj().min(1),author:w.Yj().default("chorus"),agreementThreshold:w.ai().min(0).max(1).default(.66),onThresholdMet:w.k5(["merge","ask","review"]).default("ask"),maxRounds:w.ai().int().min(1).default(3),yoloDefault:w.zM().default(!1),estimatedBaselineTokens:w.ai().int().min(0).optional(),phases:w.YO(D).min(1).refine(e=>{let r=e.filter(e=>"review_only"===e.kind).length;return 0===r||1===r&&1===e.length},{message:"review_only phases cannot be mixed with other phase kinds and only one is allowed (hybrid templates are out of scope)"}).refine(e=>{let r=e.map(e=>e.id);return new Set(r).size===r.length},{message:"phase ids must be unique"}),ship:w.Ik({enabled:w.zM().default(!1),baseBranch:w.Yj().optional(),branchPattern:w.Yj().default("chorus/{chatId}"),titleTemplate:w.Yj().default("chorus: {template} via #{chatId}")}).optional(),fallback:w.Ik({doer:w.YO(w.Ik({lineage:k,models:w.YO(w.Yj()).min(1),persona:w.Yj().optional()})).optional(),reviewer:w.YO(w.Ik({lineage:C,models:w.YO(w.Yj()).min(1),persona:w.Yj().optional()})).optional()}).optional()}),P=Object.freeze({valid:!0,issues:[]});var T=t(7362),$=t(8979),_=t(8821),E=t(4608),q=t(7978);let I={claude:"anthropic",codex:"openai",gemini:"google",opencode:"opencode",kimi:"moonshot",openrouter:"openrouter"},F={anthropic:"claude",openai:"codex",google:"gemini",opencode:"opencode",moonshot:"kimi",xai:"opencode"},O={claude:"claude-opus-4-7",codex:"gpt-5.5",gemini:"gemini-3.1-pro-preview",opencode:"kimi-k2.6",kimi:"kimi-k2.6",openrouter:""},z={id:"",name:"",description:"",author:"you",category:"review",phases:[{id:"review",name:"Review",description:"Three independent critiques.",kind:"review",gate:"ask-user",doer:{lineage:"claude",models:["claude-opus-4-7"]},reviewer:{require:3,crossLineage:!0,candidates:["codex","gemini","opencode"]},inputs:{include:[],exclude:[]},iterate:{max:3,onMax:"ask-user"},blindSpots:[],execution:"parallel",builtin:!1}],threshold:"unanimous",onThresholdMet:"ask-user",maxRounds:3,yoloDefault:!1,fallbackDoer:[],fallbackReviewer:[]},B=[{id:"review",label:"Review"},{id:"plan",label:"Plan"},{id:"debug",label:"Debug"},{id:"decide",label:"Decide"}],U=[{id:"unanimous",label:"Unanimous",hint:"All lineages must agree. Strictest — best for high-stakes reviews."},{id:"majority",label:"Majority",hint:"≥ ⅔ of lineages agree. Good default for code review."},{id:"any",label:"Any",hint:"≥1 lineage agrees. Useful for brainstorming where divergence is fine."}],V=[{id:"auto-finalize",label:"Auto-finalize"},{id:"ask-user",label:"Ask me"}],G=[{id:1,label:"Basics",icon:$.A},{id:2,label:"Phases",icon:_.A},{id:3,label:"Fallback",icon:E.A},{id:4,label:"Policy",icon:q.A}],W=["claude","codex","gemini","opencode","kimi","openrouter"];function K(e){return e.trim().toLowerCase().replace(/[^\w\s-]/g,"").replace(/\s+/g,"-").replace(/-+/g,"-")||"untitled"}function H(e){var r;return y.Ay.stringify({id:(r=e).id||K(r.name),name:r.name||"Untitled template",description:r.description||"Describe what this template is for.",author:r.author||"chorus",agreementThreshold:void 0!==r.customThreshold?r.customThreshold:function(e){switch(e){case"unanimous":return 1;case"majority":return .66;case"any":return .34}}(r.threshold),onThresholdMet:r.onThresholdMetRaw??("auto-finalize"===r.onThresholdMet?"merge":"ask"),maxRounds:r.maxRounds,yoloDefault:r.yoloDefault,phases:r.phases.map(e=>{let r="review_only"===e.kind,t=e.reviewer.candidates.length>0?{require:e.reviewer.require,crossLineage:e.reviewer.crossLineage,candidates:e.reviewer.candidates.flatMap(r=>{let t=(e.reviewer.candidateModels?.[r]??[]).map(e=>e.trim()).filter(e=>e.length>0),s=e.reviewer.candidatePersonas?.[r],a=I[r]??"anthropic";if(0===t.length){let e=O[r]??"claude-opus-4-7",t=s?.[""];return[{lineage:a,models:[e],...t?{persona:t}:{}}]}return t.map(e=>{let r=s?.[e];return{lineage:a,models:[e],...r?{persona:r}:{}}})})}:void 0;return r?{id:e.id,kind:e.kind,title:e.name,description:e.description,reviewer:t,inputs:{include:e.inputs.include,exclude:e.inputs.exclude},artifact:{label:e.artifact?.label??"Artifact to review",hint:e.artifact?.hint??"Paste a unified diff, a markdown draft, code, or any text blob.",maxBytes:e.artifact?.maxBytes??1048576}}:{id:e.id,kind:e.kind,title:e.name,description:e.description,doer:{lineage:I[e.doer.lineage]??"anthropic",models:e.doer.models.length>0?e.doer.models:[O[e.doer.lineage]??"claude-opus-4-7"],...e.doer.persona?{persona:e.doer.persona}:{}},reviewer:t,inputs:{include:e.inputs.include,exclude:e.inputs.exclude},iterate:{maxRounds:e.iterate.max,onDisagreement:"loopback"===e.iterate.onMax?"continue":"fail"===e.iterate.onMax?"accept-doer":"escalate",shareSessionAcrossRounds:!0,shareSessionAcrossPhases:!1}}}),...r.fallbackDoer.length>0||r.fallbackReviewer.length>0?{fallback:{...r.fallbackDoer.length>0?{doer:r.fallbackDoer.map(e=>({lineage:I[e.lineage]??"anthropic",models:[e.model],...e.persona?{persona:e.persona}:{}}))}:{},...r.fallbackReviewer.length>0?{reviewer:r.fallbackReviewer.map(e=>({lineage:I[e.lineage]??"anthropic",models:[e.model],...e.persona?{persona:e.persona}:{}}))}:{}}}:{}},{lineWidth:0})}var Z=t(6758),J=t(5483),Q=t(7847),X=t(1993),ee=t(52),er=t(2116),et=t(9410),es=t(9208),ea=t(7618),en=t(4579),eo=t(9812),ei=t(3734);let ed={review:ee.A,review_only:ee.A,plan:er.A,spec:p.A,tests:et.A,implement:es.A,verify:ea.A,pr:en.A,divergence:E.A,recon:eo.A},el=[{id:"plan",label:"Plan"},{id:"spec",label:"Spec / API"},{id:"tests",label:"Tests"},{id:"implement",label:"Implement"},{id:"verify",label:"Verify"},{id:"pr",label:"Open PR"},{id:"review",label:"Review"},{id:"review_only",label:"Review only (artifact)"},{id:"divergence",label:"Divergence"},{id:"recon",label:"Recon"}],ec=["claude","codex","gemini","opencode","kimi","openrouter"].map(e=>({id:e,label:ei.m_[e],dot:ei.r2[e].dot})),eu=ei.x0,em={anthropic:"claude",openai:"codex",google:"gemini",opencode:"opencode",moonshot:"kimi",xai:"opencode"};function ex(){let[e,r]=(0,a.useState)({byLineage:{},connectedLineages:new Set,loaded:!1});return(0,a.useEffect)(()=>{(0,Q.listVoices)({enabled:!0}).then(e=>{let t={},s=new Set;for(let r of e){if("openrouter"===r.provider){s.add("openrouter"),(t.openrouter??=[]).push(r.id);continue}let e=em[r.lineage];e&&(s.add(e),(t[e]??=[]).push(r.model_id)),r.provider.startsWith("opencode")&&"opencode"!==e&&(s.add("opencode"),(t.opencode??=[]).push(r.model_id))}for(let e of Object.keys(t))t[e]=Array.from(new Set(t[e]));r({byLineage:t,connectedLineages:s,loaded:!0})}).catch(()=>r({byLineage:{},connectedLineages:new Set,loaded:!0}))},[]),e}var ep=t(1304),eh=t(2379),ef=t(5445),eg=t(9707),eb=t(2471);function ev({children:e,onClick:r,disabled:t,title:a,className:n}){return(0,s.jsx)("button",{type:"button",disabled:t,onClick:e=>{e.stopPropagation(),r()},title:a,className:(0,T.cn)("grid h-6 w-6 place-items-center rounded text-muted-foreground transition hover:bg-accent hover:text-foreground disabled:cursor-not-allowed disabled:opacity-30",n),children:e})}function ej({label:e,children:r}){return(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"mb-1.5 block text-[10px] font-medium uppercase tracking-wider text-muted-foreground",children:e}),r]})}function ey({on:e,tone:r,onClick:t,children:a}){return(0,s.jsx)("button",{type:"button",onClick:t,className:(0,T.cn)("rounded-md border px-2 py-0.5 font-mono text-[10px] uppercase tracking-wider transition",{emerald:e?"border-emerald-500/40 bg-emerald-500/15 text-emerald-200":"border-border bg-card/40 text-muted-foreground hover:border-emerald-500/30",rose:e?"border-rose-500/40 bg-rose-500/15 text-rose-200":"border-border bg-card/40 text-muted-foreground hover:border-rose-500/30"}[r]),children:a})}function ew({value:e,personas:r,onChange:t,inline:a,ariaLabel:n}){let o="__none__",i=r.some(r=>r.id===e);return(0,s.jsxs)("select",{value:e??o,onChange:e=>{let r=e.target.value;t(r===o?void 0:r)},className:(0,T.cn)("h-7 rounded-md border border-border bg-background px-2 text-[11px] focus:border-primary/60 focus:outline-none",a?"w-32 shrink-0":"w-full"),"aria-label":n??"Persona",children:[(0,s.jsx)("option",{value:o,children:"(no persona)"}),r.map(e=>(0,s.jsx)("option",{value:e.id,children:e.label},e.id)),e&&!i&&(0,s.jsxs)("option",{value:e,children:[e," (missing)"]})]})}function eN({lineage:e,value:r,options:t,onChange:n,defaultModel:o}){let i="__custom__",d=!r||t.includes(r),[l,c]=(0,a.useState)(!1);if(l)return(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[(0,s.jsx)("input",{type:"text",value:r,onChange:e=>n(e.target.value),placeholder:o?`default: ${o}`:`${e} model id`,className:"h-7 flex-1 rounded-md border border-border bg-background px-2 font-mono text-[11px] text-foreground placeholder:text-muted-foreground/50 focus:border-primary/60 focus:outline-none",autoFocus:!0}),(0,s.jsx)("button",{type:"button",onClick:()=>c(!1),className:"h-7 rounded-md border border-border bg-card/40 px-2 text-[10px] text-muted-foreground hover:text-foreground",children:"done"})]});if(0===t.length)return(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsx)("input",{type:"text",value:r,onChange:e=>n(e.target.value),placeholder:o?`default: ${o}`:`${e} model id`,className:"h-7 w-full rounded-md border border-border bg-background px-2 font-mono text-[11px] text-foreground placeholder:text-muted-foreground/50 focus:border-primary/60 focus:outline-none"}),(0,s.jsxs)("p",{className:"text-[10px] text-amber-400/80",children:["No ",e," voices enabled. Configure in Connect to populate this dropdown."]})]});let u=d?t:[r,...t];return(0,s.jsxs)("select",{value:r,onChange:e=>{e.target.value===i?c(!0):n(e.target.value)},className:"h-7 w-full rounded-md border border-border bg-background px-2 font-mono text-[11px] text-foreground focus:border-primary/60 focus:outline-none",children:[!r&&(0,s.jsx)("option",{value:"",children:o?`default: ${o}`:"— pick a model —"}),u.map(e=>(0,s.jsxs)("option",{value:e,children:[e,t.includes(e)||r!==e?"":" (not enabled)"]},e)),(0,s.jsx)("option",{value:i,children:"+ custom (type a model id)…"})]})}function ek(e){let r=[];for(let t of e.candidates){let s=e.candidateModels?.[t],a=e.candidatePersonas?.[t];if(s&&0!==s.length)for(let e of s)r.push({lineage:t,model:e,...a?.[e]?{persona:a[e]}:{}});else r.push({lineage:t,model:"",...a?.[""]?{persona:a[""]}:{}})}return r}function eC({phase:e,connectedVoices:r,personas:t,onUpdate:a}){let n=ek(e.reviewer),o=ec.filter(e=>0===r.connectedLineages.size||r.connectedLineages.has(e.id));function i(r){a({reviewer:function(e,r){let t=[],s={},a={};for(let r of e)t.includes(r.lineage)||t.push(r.lineage),r.model&&(s[r.lineage]??=[]).push(r.model),r.persona&&((a[r.lineage]??={})[r.model]=r.persona);return{...r,candidates:t,candidateModels:s,...Object.keys(a).length>0?{candidatePersonas:a}:{candidatePersonas:void 0}}}(r,e.reviewer)})}function d(e,t){let s=n.map((r,s)=>s===e?{...r,...t}:r);if(t.lineage&&t.lineage!==n[e].lineage){let a=r.byLineage[t.lineage]??[];s[e].model=a[0]??eu[t.lineage]??""}i(s)}return(0,s.jsxs)("div",{className:"space-y-1.5",children:[0===n.length&&(0,s.jsx)("p",{className:"text-[11px] text-muted-foreground",children:"No reviewers yet. Click + add reviewer below."}),n.map((e,a)=>{let l=ec.find(r=>r.id===e.lineage);return(0,s.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,s.jsxs)("select",{value:e.lineage,onChange:e=>d(a,{lineage:e.target.value}),className:"h-7 w-32 shrink-0 rounded-md border border-border bg-background px-2 text-[11px] focus:border-primary/60 focus:outline-none","aria-label":"Reviewer lineage",children:[o.map(e=>(0,s.jsx)("option",{value:e.id,children:e.label},e.id)),!o.find(r=>r.id===e.lineage)&&(0,s.jsxs)("option",{value:e.lineage,children:[l?.label??e.lineage," (not connected)"]})]}),(0,s.jsx)("div",{className:"flex-1",children:(0,s.jsx)(eN,{lineage:e.lineage,value:e.model,options:r.byLineage[e.lineage]??[],defaultModel:eu[e.lineage],onChange:e=>d(a,{model:e})})}),(0,s.jsx)(ew,{value:e.persona,personas:t,onChange:e=>d(a,{persona:e}),inline:!0,ariaLabel:"Reviewer persona"}),(0,s.jsx)("button",{type:"button",onClick:()=>{i(n.filter((e,r)=>r!==a))},"aria-label":"Remove reviewer",className:"grid h-7 w-7 shrink-0 place-items-center rounded-md border border-border bg-card/40 text-muted-foreground hover:border-destructive/40 hover:text-destructive",children:(0,s.jsx)(h.A,{className:"h-3 w-3"})})]},a)}),(0,s.jsxs)("button",{type:"button",onClick:function(){let e=o[0]?.id??"claude",t=r.byLineage[e]??[],s=new Set(n.filter(r=>r.lineage===e).map(e=>e.model)),a=t.find(e=>!s.has(e))??eu[e]??"";i([...n,{lineage:e,model:a}])},className:"flex w-full items-center justify-center gap-1.5 rounded-md border border-dashed border-border bg-card/30 px-3 py-2 text-[11px] font-medium text-muted-foreground transition hover:border-primary/40 hover:bg-card/50 hover:text-foreground",children:[(0,s.jsx)(x.A,{className:"h-3 w-3"}),"Add another reviewer"]})]})}function eA({phase:e,onUpdate:r,connectedVoices:t,personas:a}){return(0,s.jsxs)(ej,{label:"Doer \xb7 the agent that writes this phase's output",children:[(0,s.jsx)("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-5",children:ec.filter(e=>0===t.connectedLineages.size||t.connectedLineages.has(e.id)).map(a=>(0,s.jsxs)("button",{type:"button",onClick:()=>{let e=(t.byLineage[a.id]??[])[0]??eu[a.id];r({doer:{lineage:a.id,models:e?[e]:[]}})},className:(0,T.cn)("flex items-center gap-1.5 rounded-md border px-2 py-1.5 text-left transition",e.doer.lineage===a.id?"border-primary/40 bg-primary/10":"border-border bg-card/40 hover:border-foreground/30"),children:[(0,s.jsx)("span",{className:(0,T.cn)("h-1.5 w-1.5 rounded-full",a.dot)}),(0,s.jsx)("span",{className:"text-xs",children:a.label}),e.doer.lineage===a.id&&(0,s.jsx)(eg.A,{className:"ml-auto h-3 w-3 text-primary"})]},a.id))}),(0,s.jsx)("div",{className:"mt-2",children:(0,s.jsx)(eN,{lineage:e.doer.lineage,value:e.doer.models[0]??"",options:t.byLineage[e.doer.lineage]??[],defaultModel:eu[e.doer.lineage],onChange:t=>r({doer:{...e.doer,models:t?[t]:[]}})})}),(0,s.jsxs)("div",{className:"mt-2",children:[(0,s.jsx)("label",{className:"mb-1 block text-[10px] text-muted-foreground",children:"Persona (optional \xb7 prepends a worldview to the doer's prompt)"}),(0,s.jsx)(ew,{value:e.doer.persona,personas:a,onChange:t=>r({doer:t?{...e.doer,persona:t}:(()=>{let{persona:r,...t}=e.doer;return t})()}),ariaLabel:"Doer persona"})]})]})}function eM({phase:e,onUpdate:r}){let t={label:e.artifact?.label??"Artifact to review",hint:e.artifact?.hint??"Paste a unified diff, a markdown draft, code, or any text blob.",maxBytes:e.artifact?.maxBytes??1048576};return(0,s.jsx)(ej,{label:"Artifact \xb7 what the user pastes when starting a chat",children:(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[10px] text-muted-foreground",children:"Label"}),(0,s.jsx)("input",{type:"text",value:t.label,onChange:e=>r({artifact:{...t,label:e.target.value}}),placeholder:"Artifact to review",className:"mt-1 h-7 w-full rounded-md border border-border bg-background px-2.5 text-[11px] placeholder:text-muted-foreground/60 focus:border-primary/60 focus:outline-none"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[10px] text-muted-foreground",children:"Placeholder hint"}),(0,s.jsx)("textarea",{value:e.artifact?.hint??"",onChange:e=>r({artifact:{...t,hint:e.target.value}}),placeholder:"Paste a unified diff, a markdown draft, code, or any text blob.",rows:2,className:"mt-1 w-full resize-none rounded-md border border-border bg-background px-2.5 py-1.5 text-[11px] placeholder:text-muted-foreground/60 focus:border-primary/60 focus:outline-none"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[10px] text-muted-foreground",children:"Max bytes (server-side cap)"}),(0,s.jsx)("input",{type:"number",min:1024,step:1024,value:t.maxBytes,onChange:e=>r({artifact:{...t,maxBytes:Math.max(1024,parseInt(e.target.value,10)||1048576)}}),className:"mt-1 h-7 w-full rounded-md border border-border bg-background px-2.5 font-mono text-[11px] focus:border-primary/60 focus:outline-none"}),(0,s.jsx)("p",{className:"mt-1 text-[10px] text-muted-foreground/80",children:"1 MiB = 1048576. Default if unset."})]})]})})}function eS({phase:e,onUpdate:r,connectedVoices:t,personas:a}){return(0,s.jsx)(ej,{label:"Reviewers \xb7 who gates this phase",children:(0,s.jsx)(eC,{phase:e,connectedVoices:t,personas:a,onUpdate:r})})}function eY({phase:e,onUpdate:r}){return(0,s.jsx)(ej,{label:"Approvals",children:(0,s.jsxs)("div",{className:"flex items-center gap-4 flex-wrap",children:[(0,s.jsxs)("label",{className:"flex items-center gap-2 text-[11px] text-muted-foreground",children:["Require:",(0,s.jsx)("input",{type:"number",min:0,max:Math.max(1,ek(e.reviewer).length),value:e.reviewer.require,onChange:t=>r({reviewer:{...e.reviewer,require:Math.max(0,parseInt(t.target.value,10)||0)}}),className:"h-6 w-12 rounded border border-border bg-background px-1.5 text-center font-mono text-[11px]"}),"approval",1===e.reviewer.require?"":"s"]}),"review_only"!==e.kind&&(0,s.jsxs)("label",{className:"flex items-center gap-2 text-[11px] text-muted-foreground",children:[(0,s.jsx)("input",{type:"checkbox",checked:e.reviewer.crossLineage,onChange:t=>r({reviewer:{...e.reviewer,crossLineage:t.target.checked}}),className:"accent-primary"}),"Cross-lineage required"]})]})})}function eL({phase:e,onUpdate:r}){return(0,s.jsx)(ej,{label:"Reviewer execution \xb7 how multiple reviewers interact",children:(0,s.jsxs)("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:[(0,s.jsxs)("button",{type:"button",onClick:()=>r({execution:"parallel"}),className:(0,T.cn)("rounded-md border px-3 py-2.5 text-left transition","parallel"===e.execution?"border-emerald-500/40 bg-emerald-500/5":"border-border bg-card/40 hover:border-foreground/30"),children:[(0,s.jsxs)("div",{className:"flex items-center gap-1.5 text-xs font-medium",children:["Parallel independent",(0,s.jsx)("span",{className:"font-mono text-[9px] uppercase text-emerald-300/80",children:"fast"})]}),(0,s.jsx)("p",{className:"mt-0.5 text-[10px] leading-snug text-muted-foreground",children:"All reviewers see the same pack, work in isolation, vote. Catches single-reviewer mistakes via consensus. Risk: shared blind spots pass anyway."})]}),(0,s.jsxs)("button",{type:"button",onClick:()=>r({execution:"sequential"}),className:(0,T.cn)("rounded-md border px-3 py-2.5 text-left transition","sequential"===e.execution?"border-amber-500/40 bg-amber-500/5":"border-border bg-card/40 hover:border-foreground/30"),children:[(0,s.jsxs)("div",{className:"flex items-center gap-1.5 text-xs font-medium",children:["Sequential hostile",(0,s.jsx)("span",{className:"font-mono text-[9px] uppercase text-amber-300/80",children:"thorough"})]}),(0,s.jsx)("p",{className:"mt-0.5 text-[10px] leading-snug text-muted-foreground",children:"Reviewers run in order. Each receives the already-hardened output and hunts what the prior reviewer missed. Slower; only works if the first reviewer's solution is sound."})]})]})})}function eD({phase:e,onUpdate:r,priorPhases:t}){return(0,s.jsxs)(ej,{label:"Inputs \xb7 which prior phases this doer can read",children:[(0,s.jsx)("div",{className:"space-y-1.5",children:t.map(t=>{let a=e.inputs.include.includes(t),n=e.inputs.exclude.includes(t),o=n?"exclude":a?"include":"none";return(0,s.jsxs)("div",{className:"flex items-center justify-between rounded-md border border-border bg-card/30 px-2.5 py-1.5",children:[(0,s.jsx)("code",{className:"font-mono text-[11px] text-foreground",children:t}),(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[(0,s.jsx)(ey,{on:"include"===o,tone:"emerald",onClick:()=>r({inputs:{include:a?e.inputs.include.filter(e=>e!==t):[...e.inputs.include,t],exclude:e.inputs.exclude.filter(e=>e!==t)}}),children:"include"}),(0,s.jsx)(ey,{on:"exclude"===o,tone:"rose",onClick:()=>r({inputs:{include:e.inputs.include.filter(e=>e!==t),exclude:n?e.inputs.exclude.filter(e=>e!==t):[...e.inputs.exclude,t]}}),children:"exclude (blind)"})]})]},t)})}),(0,s.jsxs)("p",{className:"mt-2 flex items-start gap-1.5 text-[10px] text-muted-foreground",children:[(0,s.jsx)(eb.A,{className:"mt-0.5 h-2.5 w-2.5 shrink-0 text-muted-foreground/60"}),(0,s.jsxs)("span",{children:[(0,s.jsx)("span",{className:"font-mono text-rose-300",children:"exclude"}),"prevents this doer from seeing that phase's output. Used for info asymmetry — e.g. the implementer shouldn't see the tests."]})]})]})}function eR({phase:e,onUpdate:r,priorPhases:t}){return(0,s.jsx)(ej,{label:"Iterate \xb7 what happens when reviewer rejects",children:(0,s.jsxs)("div",{className:"grid grid-cols-3 gap-2",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[10px] text-muted-foreground",children:"Max revise"}),(0,s.jsx)("input",{type:"number",min:1,max:10,value:e.iterate.max,onChange:t=>r({iterate:{...e.iterate,max:Math.max(1,parseInt(t.target.value,10)||1)}}),className:"mt-1 h-7 w-full rounded-md border border-border bg-background px-2 font-mono text-[11px]"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[10px] text-muted-foreground",children:"On max"}),(0,s.jsxs)("select",{value:e.iterate.onMax,onChange:t=>r({iterate:{...e.iterate,onMax:t.target.value}}),className:"mt-1 h-7 w-full rounded-md border border-border bg-background px-1.5 text-[11px]",children:[(0,s.jsx)("option",{value:"ask-user",children:"ask me"}),(0,s.jsx)("option",{value:"loopback",children:"loop back"}),(0,s.jsx)("option",{value:"fail",children:"fail"})]})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[10px] text-muted-foreground",children:"Loop back to"}),(0,s.jsxs)("select",{disabled:"loopback"!==e.iterate.onMax,value:e.iterate.loopbackTo??"",onChange:t=>r({iterate:{...e.iterate,loopbackTo:t.target.value||void 0}}),className:"mt-1 h-7 w-full rounded-md border border-border bg-background px-1.5 text-[11px] disabled:opacity-40",children:[(0,s.jsx)("option",{value:"",children:"—"}),t.map(e=>(0,s.jsx)("option",{value:e,children:e},e))]})]})]})})}function eP({phase:e,onUpdate:r}){return(0,s.jsx)(ej,{label:"Gate \xb7 what happens when this phase finishes",children:(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,s.jsxs)("button",{type:"button",onClick:()=>r({gate:"auto"}),className:(0,T.cn)("rounded-md border px-2.5 py-1.5 text-left transition","auto"===e.gate?"border-emerald-500/40 bg-emerald-500/10":"border-border bg-card/40 hover:border-foreground/30"),children:[(0,s.jsx)("div",{className:"text-xs font-medium",children:"Auto-proceed"}),(0,s.jsx)("div",{className:"text-[10px] text-muted-foreground",children:"Continue to next phase without asking."})]}),(0,s.jsxs)("button",{type:"button",onClick:()=>r({gate:"ask-user"}),className:(0,T.cn)("rounded-md border px-2.5 py-1.5 text-left transition","ask-user"===e.gate?"border-amber-500/40 bg-amber-500/10":"border-border bg-card/40 hover:border-foreground/30"),children:[(0,s.jsx)("div",{className:"text-xs font-medium",children:"Checkpoint (ask me)"}),(0,s.jsx)("div",{className:"text-[10px] text-muted-foreground",children:"Stop here, surface verdict, wait for click."})]})]})})}function eT({phase:e,index:r,total:t,allPhaseIds:n,connectedVoices:o,personas:d,onUpdate:l,onMoveUp:c,onMoveDown:u,onDelete:m}){let[x,p]=(0,a.useState)(0===r),h=ed[e.kind],f=n.slice(0,r);return(0,s.jsxs)("div",{className:"rounded-lg border border-border bg-card/40",children:[(0,s.jsxs)("button",{type:"button",onClick:()=>p(e=>!e),className:"flex w-full items-center gap-3 px-3 py-2.5 text-left",children:[(0,s.jsx)("span",{className:"font-mono text-[10px] text-muted-foreground/60",children:String(r+1).padStart(2,"0")}),(0,s.jsx)("span",{className:"grid h-7 w-7 shrink-0 place-items-center rounded-md bg-primary/15 text-primary",children:(0,s.jsx)(h,{className:"h-3.5 w-3.5"})}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"text-sm font-medium text-foreground truncate",children:e.name||"Untitled phase"}),(0,s.jsx)("span",{className:"font-mono text-[10px] uppercase text-muted-foreground/70",children:e.kind})]}),(0,s.jsx)(e$,{phase:e})]}),(0,s.jsxs)("div",{className:"flex shrink-0 items-center gap-0.5",children:[(0,s.jsx)(ev,{disabled:0===r,onClick:c,title:"Move up",children:(0,s.jsx)(ep.A,{className:"h-3 w-3"})}),(0,s.jsx)(ev,{disabled:r===t-1,onClick:u,title:"Move down",children:(0,s.jsx)(eh.A,{className:"h-3 w-3"})}),(0,s.jsx)(ev,{onClick:m,title:"Delete phase",className:"hover:text-rose-400",children:(0,s.jsx)(i.A,{className:"h-3 w-3"})}),(0,s.jsx)("span",{className:"ml-1 text-muted-foreground/60",children:x?(0,s.jsx)(ef.A,{className:"h-3.5 w-3.5"}):(0,s.jsx)(J.A,{className:"h-3.5 w-3.5"})})]})]}),x&&(0,s.jsxs)("div",{className:"space-y-4 border-t border-border bg-background/40 px-3 py-3",children:[(0,s.jsxs)("div",{className:"grid grid-cols-[1fr_140px] gap-2",children:[(0,s.jsx)(ej,{label:"Name",children:(0,s.jsx)("input",{type:"text",value:e.name,onChange:e=>l({name:e.target.value}),className:"h-8 w-full rounded-md border border-border bg-background px-2.5 text-xs text-foreground focus:border-primary/60 focus:outline-none"})}),(0,s.jsx)(ej,{label:"Kind",children:(0,s.jsx)("select",{value:e.kind,onChange:e=>l({kind:e.target.value}),className:"h-8 w-full rounded-md border border-border bg-background px-2 text-xs text-foreground focus:border-primary/60 focus:outline-none",children:el.map(e=>(0,s.jsx)("option",{value:e.id,children:e.label},e.id))})})]}),(0,s.jsx)(ej,{label:"Description",children:(0,s.jsx)("input",{type:"text",value:e.description,onChange:e=>l({description:e.target.value}),placeholder:"What this phase produces and why it exists.",className:"h-8 w-full rounded-md border border-border bg-background px-2.5 text-xs text-foreground placeholder:text-muted-foreground/60 focus:border-primary/60 focus:outline-none"})}),"review_only"!==e.kind&&(0,s.jsx)(eA,{phase:e,onUpdate:l,connectedVoices:o,personas:d}),"review_only"===e.kind&&(0,s.jsx)(eM,{phase:e,onUpdate:l}),(0,s.jsx)(eS,{phase:e,onUpdate:l,connectedVoices:o,personas:d}),(0,s.jsx)(eY,{phase:e,onUpdate:l}),(0,s.jsx)(eL,{phase:e,onUpdate:l}),f.length>0&&(0,s.jsx)(eD,{phase:e,onUpdate:l,priorPhases:f}),"review_only"!==e.kind&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(eR,{phase:e,onUpdate:l,priorPhases:f}),(0,s.jsx)(eP,{phase:e,onUpdate:l})]})]})]})}function e$({phase:e}){return(0,s.jsxs)("div",{className:"mt-0.5 flex flex-wrap items-center gap-1.5 text-[10px] text-muted-foreground",children:["review_only"!==e.kind&&(0,s.jsxs)("span",{className:"flex items-center gap-1",children:[(0,s.jsx)("span",{className:(0,T.cn)("h-1.5 w-1.5 rounded-full",ec.find(r=>r.id===e.doer.lineage)?.dot)}),"doer: ",e.doer.lineage]}),e.reviewer.candidates.length>0&&(0,s.jsxs)(s.Fragment,{children:["review_only"!==e.kind&&(0,s.jsx)("span",{className:"text-muted-foreground/40",children:"\xb7"}),(0,s.jsxs)("span",{className:"flex items-center gap-1",children:["reviewers:",e.reviewer.candidates.map(e=>(0,s.jsx)("span",{className:(0,T.cn)("h-1.5 w-1.5 rounded-full",ec.find(r=>r.id===e)?.dot),title:e},e))]})]}),e.reviewer.crossLineage&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"text-muted-foreground/40",children:"\xb7"}),(0,s.jsx)("span",{className:"text-amber-300/90 font-mono text-[9px] uppercase",children:"cross-lineage"})]}),(0,s.jsx)("span",{className:"text-muted-foreground/40",children:"\xb7"}),(0,s.jsx)("span",{className:(0,T.cn)("font-mono text-[9px] uppercase","sequential"===e.execution?"text-amber-300/90":"text-emerald-300/80"),title:"sequential"===e.execution?"Sequential hostile — reviewers chain":"Parallel independent — reviewers vote",children:"sequential"===e.execution?"sequential":"parallel"}),e.inputs.exclude.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"text-muted-foreground/40",children:"\xb7"}),(0,s.jsxs)("span",{className:"text-rose-300/90 font-mono text-[9px]",children:["blind-to: ",e.inputs.exclude.join(",")]})]})]})}function e_({phases:e,onChange:r}){let t=ex(),{personas:n}=function(){let[e,r]=(0,a.useState)({personas:[],loaded:!1});return(0,a.useEffect)(()=>{(0,X.UT)().then(e=>r({personas:e,loaded:!0})).catch(()=>r({personas:[],loaded:!0}))},[]),e}();function o(t,s){let a=t+s;if(a<0||a>=e.length)return;let n=[...e];[n[t],n[a]]=[n[a],n[t]],r(n)}let i=e.map(e=>e.id);return(0,s.jsxs)("div",{children:[(0,s.jsxs)("div",{className:"mb-2 flex items-center justify-between",children:[(0,s.jsxs)("span",{className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground",children:["Phases (",e.length,")"]}),(0,s.jsx)("span",{className:"text-[11px] text-muted-foreground/70",children:"Each phase has a doer + reviewer. Adversarial by default."})]}),(0,s.jsx)("div",{className:"space-y-2",children:e.map((a,d)=>(0,s.jsx)(eT,{phase:a,index:d,total:e.length,allPhaseIds:i,connectedVoices:t,personas:n,onUpdate:t=>{r(e.map((e,r)=>r===d?{...e,...t}:e))},onMoveUp:()=>o(d,-1),onMoveDown:()=>o(d,1),onDelete:()=>{r(e.filter((e,r)=>r!==d))}},a.id))}),(0,s.jsxs)("button",{type:"button",onClick:function(){var t;r([...e,(t=e.length,{id:`phase-${t+1}`,name:`Phase ${t+1}`,description:"",kind:"review",gate:"auto",doer:{lineage:"claude",models:["claude-opus-4-7"]},reviewer:{require:1,crossLineage:!0,candidates:["codex"]},inputs:{include:[],exclude:[]},iterate:{max:3,onMax:"ask-user"},blindSpots:[],execution:"sequential",builtin:!1})])},className:"mt-3 flex w-full items-center justify-center gap-1.5 rounded-md border border-dashed border-border bg-card/30 px-3 py-2.5 text-xs font-medium text-muted-foreground transition hover:border-primary/40 hover:bg-card/50 hover:text-foreground",children:[(0,s.jsx)(x.A,{className:"h-3.5 w-3.5"}),"Add phase"]})]})}function eE({active:e,onClick:r,disabled:t,children:a}){return(0,s.jsxs)("button",{type:"button",onClick:r,disabled:t,className:(0,T.cn)("relative flex items-center gap-1.5 rounded-t-md px-3 py-2.5 text-sm font-medium transition-colors",t?"cursor-not-allowed text-muted-foreground/50":e?"text-foreground":"text-muted-foreground hover:text-foreground"),children:[a,e&&!t&&(0,s.jsx)("span",{className:"absolute inset-x-0 -bottom-px h-0.5 bg-primary"})]})}function eq({label:e,htmlFor:r,hint:t,children:a}){return(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)("label",{htmlFor:r,className:"block text-[13px] font-medium text-foreground",children:e}),a,t&&(0,s.jsx)("p",{className:"text-[11px] leading-snug text-muted-foreground/80",children:t})]})}function eI({active:e,onClick:r,children:t}){return(0,s.jsx)("button",{type:"button",onClick:r,className:(0,T.cn)("h-8 rounded-md border px-3 text-xs font-medium transition",e?"border-primary/60 bg-primary/15 text-primary":"border-border bg-card text-muted-foreground hover:border-muted-foreground/30 hover:bg-accent/40 hover:text-foreground"),children:t})}function eF({form:e,setField:r,showErrors:t}){let a=t&&0===e.name.trim().length,n=t&&0===e.description.trim().length;return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(eq,{label:"Name *",htmlFor:"tpl-name",children:[(0,s.jsx)("input",{id:"tpl-name",value:e.name,onChange:e=>r("name",e.target.value),placeholder:"security-audit","aria-invalid":a,className:(0,T.cn)("h-10 w-full rounded-md border bg-background px-3 text-sm placeholder:text-muted-foreground/60 focus:outline-none focus:ring-2",a?"border-destructive/60 focus:border-destructive focus:ring-destructive/30":"border-border focus:border-primary/60 focus:ring-primary/20")}),a&&(0,s.jsx)("p",{className:"text-[11px] text-destructive",children:"Name is required."})]}),(0,s.jsxs)(eq,{label:"Description *",htmlFor:"tpl-desc",hint:"One sentence on when someone should reach for this template.",children:[(0,s.jsx)("textarea",{id:"tpl-desc",value:e.description,onChange:e=>r("description",e.target.value),placeholder:"Independent security audit from 3 model families…",rows:2,"aria-invalid":n,className:(0,T.cn)("w-full resize-none rounded-md border bg-background px-3 py-2 text-sm leading-relaxed placeholder:text-muted-foreground/60 focus:outline-none focus:ring-2",n?"border-destructive/60 focus:border-destructive focus:ring-destructive/30":"border-border focus:border-primary/60 focus:ring-primary/20")}),n&&(0,s.jsx)("p",{className:"text-[11px] text-destructive",children:"Description is required."})]}),(0,s.jsx)(eq,{label:"Category",children:(0,s.jsx)("div",{className:"flex flex-wrap gap-2",children:B.map(t=>(0,s.jsx)(eI,{active:t.id===e.category,onClick:()=>r("category",t.id),children:t.label},t.id))})})]})}function eO({form:e,setField:r}){let t=ex();return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"rounded-md border border-border bg-card/40 px-3 py-2 text-[11px] leading-relaxed text-muted-foreground",children:[(0,s.jsxs)("div",{className:"mb-1 flex items-center gap-1.5 text-foreground",children:[(0,s.jsx)(E.A,{className:"h-3 w-3"}),(0,s.jsx)("span",{className:"text-[12px] font-medium",children:"Template-level fallback chains"})]}),"Tried in order whenever a slot exhausts its own per-slot model chain. Cross-lineage swap supported — a codex slot can fall through to a claude or kimi entry. Strict",(0,s.jsx)("span",{className:"font-mono",children:" (lineage, model)"})," dedup keeps diversity: a fallback whose model already runs as another reviewer in this phase is skipped, so you never review the same code twice with the same voice. Order matters — list your most-preferred fallback first."]}),(0,s.jsx)(ez,{title:"Doer fallback",hint:"Engaged when the doer's primary + per-slot models all fail.",rows:e.fallbackDoer,onChange:e=>r("fallbackDoer",e),connectedVoices:t}),(0,s.jsx)(ez,{title:"Reviewer fallback",hint:"Engaged when any reviewer's primary + per-slot models all fail.",rows:e.fallbackReviewer,onChange:e=>r("fallbackReviewer",e),connectedVoices:t})]})}function ez({title:e,hint:r,rows:t,onChange:a,connectedVoices:n}){let o=(e,r)=>{a(t.map((t,s)=>s===e?{...t,...r}:t))};return(0,s.jsxs)("div",{className:"rounded-lg border border-border bg-card/40 p-4",children:[(0,s.jsxs)("div",{className:"mb-1 flex items-center justify-between",children:[(0,s.jsx)("h4",{className:"text-[13px] font-semibold tracking-tight",children:e}),(0,s.jsxs)("button",{type:"button",onClick:()=>{let e=W.find(e=>(n.byLineage[e]??[]).length>0)??"claude",r=n.byLineage[e]?.[0]??"";a([...t,{lineage:e,model:r}])},className:"inline-flex h-7 items-center gap-1 rounded-md border border-border bg-card px-2.5 text-[11px] font-medium text-muted-foreground transition hover:border-primary/40 hover:text-primary",children:[(0,s.jsx)(x.A,{className:"h-3 w-3"}),"Add fallback"]})]}),(0,s.jsx)("p",{className:"mb-3 text-[11px] leading-snug text-muted-foreground/80",children:r}),0===t.length?(0,s.jsx)("p",{className:"rounded-md border border-dashed border-border/60 bg-background/30 px-3 py-4 text-center text-[11px] text-muted-foreground",children:"None set — slot will fail its phase if the per-slot chain exhausts."}):(0,s.jsx)("ul",{className:"space-y-2",children:t.map((e,r)=>{let i=n.byLineage[e.lineage]??[],d=0===e.model.length||i.includes(e.model);return(0,s.jsxs)("li",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md border border-border bg-card font-mono text-[10px] text-muted-foreground",children:r+1}),(0,s.jsx)("select",{value:e.lineage,onChange:e=>{var s;let a,i;return s=e.target.value,a=n.byLineage[s]??[],i=t[r].model,void o(r,{lineage:s,model:a.includes(i)?i:a[0]??""})},className:"h-8 rounded-md border border-border bg-background px-2 text-xs text-foreground focus:border-primary/60 focus:outline-none focus:ring-1 focus:ring-primary/20",children:W.map(e=>(0,s.jsx)("option",{value:e,children:e},e))}),(0,s.jsxs)("select",{value:e.model,onChange:e=>o(r,{model:e.target.value}),className:"h-8 flex-1 rounded-md border border-border bg-background px-2 font-mono text-[11px] text-foreground focus:border-primary/60 focus:outline-none focus:ring-1 focus:ring-primary/20",children:[0===i.length&&(0,s.jsx)("option",{value:"",disabled:!0,children:n.loaded?`No ${e.lineage} models enabled — open Connect → ${e.lineage}`:"loading…"}),i.map(e=>(0,s.jsx)("option",{value:e,children:e},e)),!d&&e.model.length>0&&(0,s.jsxs)("option",{value:e.model,children:[e.model," (stored)"]})]}),(0,s.jsx)("button",{type:"button",onClick:()=>{a(t.filter((e,t)=>t!==r))},"aria-label":`Remove fallback ${r+1}`,className:"grid h-7 w-7 place-items-center rounded-md border border-border bg-card text-muted-foreground transition hover:border-destructive/40 hover:text-destructive",children:(0,s.jsx)(h.A,{className:"h-3 w-3"})})]},r)})})]})}function eB({form:e,setField:r}){return(0,s.jsxs)("div",{className:"rounded-lg border border-border bg-card/40 p-4",children:[(0,s.jsx)("h3",{className:"mb-3 text-[13px] font-semibold tracking-tight",children:"Across all phases"}),(0,s.jsxs)("div",{className:"mb-4",children:[(0,s.jsx)("div",{className:"mb-1.5 text-[11px] font-medium text-muted-foreground",children:"Agreement threshold (per review-style phase)"}),(0,s.jsx)("div",{className:"grid grid-cols-3 gap-2",children:U.map(t=>(0,s.jsx)("button",{type:"button",onClick:()=>r("threshold",t.id),className:(0,T.cn)("rounded-md border px-3 py-2 text-left transition",e.threshold===t.id?"border-primary/60 bg-primary/10 ring-1 ring-primary/40":"border-border bg-card hover:border-muted-foreground/30 hover:bg-accent/40"),children:(0,s.jsx)("div",{className:"text-xs font-medium",children:t.label})},t.id))}),(0,s.jsx)("p",{className:"mt-1.5 text-[11px] leading-snug text-muted-foreground/80",children:U.find(r=>r.id===e.threshold)?.hint})]}),(0,s.jsxs)("div",{className:"mb-4",children:[(0,s.jsx)("div",{className:"mb-1.5 text-[11px] font-medium text-muted-foreground",children:"When threshold is met"}),(0,s.jsx)("div",{className:"grid grid-cols-2 gap-2",children:V.map(t=>(0,s.jsx)("button",{type:"button",onClick:()=>r("onThresholdMet",t.id),className:(0,T.cn)("rounded-md border px-3 py-2 text-left transition",e.onThresholdMet===t.id?"border-primary/60 bg-primary/10 ring-1 ring-primary/40":"border-border bg-card hover:border-muted-foreground/30 hover:bg-accent/40"),children:(0,s.jsx)("div",{className:"text-xs font-medium",children:t.label})},t.id))})]}),(0,s.jsxs)("div",{className:"mb-4",children:[(0,s.jsxs)("div",{className:"mb-1.5 flex items-center justify-between",children:[(0,s.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground",children:"Max revise rounds (per phase)"}),(0,s.jsx)("span",{className:"font-mono text-xs text-foreground",children:e.maxRounds})]}),(0,s.jsx)("input",{type:"range",min:1,max:5,step:1,value:e.maxRounds,onChange:e=>r("maxRounds",parseInt(e.target.value,10)),className:"h-1 w-full cursor-pointer appearance-none rounded-full bg-muted accent-primary"})]}),(0,s.jsxs)("button",{type:"button",onClick:()=>r("yoloDefault",!e.yoloDefault),className:(0,T.cn)("flex w-full items-center justify-between rounded-md border px-3 py-2 text-left transition",e.yoloDefault?"border-rose-500/40 bg-rose-500/5":"border-border bg-card hover:border-foreground/30"),children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"text-xs font-medium text-foreground",children:"\uD83D\uDE80 Yolo by default"}),(0,s.jsx)("div",{className:"text-[10px] text-muted-foreground",children:"Auto-approve every gate. Only flip on for trusted templates or trivial fixes. Cost cap still enforced."})]}),(0,s.jsx)("span",{className:(0,T.cn)("flex h-5 w-9 shrink-0 items-center rounded-full border p-0.5 transition",e.yoloDefault?"border-rose-500/40 bg-rose-500/20":"border-border bg-card"),children:(0,s.jsx)("span",{className:(0,T.cn)("h-3.5 w-3.5 rounded-full transition-transform",e.yoloDefault?"translate-x-4 bg-rose-400":"bg-muted-foreground/50")})})]})]})}function eU(e,r){let t=[];if(1===e)r.name&&0!==r.name.trim().length?r.name.length>80&&t.push("Name is too long (max 80 chars)."):t.push("Name is required."),r.description&&0!==r.description.trim().length||t.push("Description is required — one line on when to use this template.");else if(2===e)for(let e of(0===r.phases.length&&t.push("At least one phase is required."),r.phases))e.id&&0!==e.id.trim().length||t.push(`Phase "${e.name||"(unnamed)"}" needs an id.`),"review_only"===e.kind||e.doer.lineage&&0!==e.doer.models.length||t.push(`Phase "${e.name||e.id}" needs a doer lineage + model.`),0===e.reviewer.candidates.length&&t.push(`Phase "${e.name||e.id}" needs at least one reviewer.`);return t}function eV({form:e,setField:r}){let[t,n]=(0,a.useState)(1),[o,i]=(0,a.useState)(!1),d=eU(t,e),l=0===d.length;return(0,s.jsxs)("div",{className:"flex h-full flex-col px-6 py-6",children:[(0,s.jsx)(eG,{currentStep:t,onJump:r=>{if(r<=t){i(!1),n(r);return}for(let s=t;s<r;s++)if(eU(s,e).length>0)return void i(!0);i(!1),n(r)},form:e}),(0,s.jsxs)("div",{className:"mt-6 flex-1 space-y-6",children:[1===t&&(0,s.jsx)(eF,{form:e,setField:r,showErrors:o}),2===t&&(0,s.jsx)(eW,{form:e,setField:r,showErrors:o}),3===t&&(0,s.jsx)(eO,{form:e,setField:r}),4===t&&(0,s.jsx)(eB,{form:e,setField:r})]}),o&&d.length>0&&(0,s.jsxs)("div",{className:"mt-6 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-[11px] text-destructive",children:[(0,s.jsx)("div",{className:"mb-1 font-medium",children:"Resolve these to continue:"}),(0,s.jsx)("ul",{className:"space-y-0.5 pl-4",children:d.map(e=>(0,s.jsx)("li",{className:"list-disc",children:e},e))})]}),(0,s.jsxs)("div",{className:"mt-6 flex items-center justify-between border-t border-border pt-4",children:[(0,s.jsxs)("button",{type:"button",onClick:()=>{i(!1),t>1&&n(t-1)},disabled:1===t,className:"inline-flex h-9 items-center gap-1.5 rounded-md border border-border bg-card px-3 text-sm font-medium text-muted-foreground transition hover:border-muted-foreground/30 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-40",children:[(0,s.jsx)(Z.A,{className:"h-3.5 w-3.5"}),"Back"]}),(0,s.jsxs)("span",{className:"text-[11px] text-muted-foreground",children:["Step ",t," of 4 \xb7 ",G[t-1].label]}),t<4?(0,s.jsxs)("button",{type:"button",onClick:()=>{l?(i(!1),t<4&&n(t+1)):i(!0)},className:(0,T.cn)("inline-flex h-9 items-center gap-1.5 rounded-md px-3 text-sm font-medium shadow-sm transition",l?"bg-primary text-primary-foreground hover:bg-primary/90":"bg-muted text-muted-foreground/60"),children:["Next",(0,s.jsx)(J.A,{className:"h-3.5 w-3.5"})]}):(0,s.jsxs)("span",{className:"text-[11px] text-emerald-300",children:[(0,s.jsx)(b.A,{className:"mr-1 inline-block h-3 w-3"}),"Save in the footer below"]})]})]})}function eG({currentStep:e,onJump:r,form:t}){return(0,s.jsx)("div",{className:"flex items-stretch gap-2",children:G.map(a=>{let n=a.icon,o=a.id===e,i=0===eU(a.id,t).length,d=a.id<e;return(0,s.jsxs)("button",{type:"button",onClick:()=>r(a.id),className:(0,T.cn)("flex flex-1 items-center gap-2 rounded-md border px-3 py-2 text-left transition",o?"border-primary/60 bg-primary/10":d&&!i?"border-destructive/40 bg-destructive/5":"border-border bg-card hover:border-muted-foreground/30"),children:[(0,s.jsx)("span",{className:(0,T.cn)("flex h-6 w-6 shrink-0 items-center justify-center rounded-full text-[10px] font-mono",o?"bg-primary text-primary-foreground":d&&i?"bg-emerald-500/20 text-emerald-300":d&&!i?"bg-destructive/20 text-destructive":"bg-muted text-muted-foreground"),children:d&&i?"✓":a.id}),(0,s.jsx)(n,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,s.jsx)("span",{className:"hidden text-xs font-medium sm:inline",children:a.label})]},a.id)})})}function eW({form:e,setField:r,showErrors:t}){let a=eU(2,e);return(0,s.jsxs)(s.Fragment,{children:[t&&a.length>0&&(0,s.jsx)("div",{className:"rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-[11px] text-destructive",children:a[0]}),(0,s.jsx)(e_,{phases:e.phases,onChange:e=>r("phases",e)})]})}function eK(e){return Array.isArray(e)?e.flatMap(e=>{let r=F[e.lineage??""]??"claude",t=(e.models??[]).filter(e=>"string"==typeof e&&e.trim().length>0);return 0===t.length?[]:t.map(t=>({lineage:r,model:t,...e.persona?{persona:e.persona}:{}}))}):[]}let eH=["plan","spec","tests","implement","review","verify","divergence","review_only"];function eZ(e,r){let t,s,a,n,o=[];try{t=y.Ay.parse(e)??{}}catch{return{form:{...z,id:r},formLossy:!0,lossyReasons:["YAML failed to parse — only YAML mode is available."]}}t.ship?.enabled&&o.push("Template has `ship.enabled: true` — form mode can't edit ship config.");let i=[];for(let e of t.phases??[]){let{phase:r,reasons:t}=function(e){let r=[];void 0!==e.timeoutMs&&r.push(`Phase ${e.id??"?"} has \`timeoutMs\` — not exposed in form mode.`);let t="review_only"===e.kind,s=t?"claude":F[e.doer?.lineage??""]??"claude",a={},n={},o=new Set,i=[],d=[];for(let r of e.reviewer?.candidates??[]){let e=F[r.lineage??""];if(!e)continue;o.has(e)||(o.add(e),i.push(e));let t=(r.models??[]).map(e=>(e??"").trim()).filter(e=>e.length>0),s=r.persona&&r.persona.trim().length>0?r.persona:void 0,l=r=>{if(!s)return;let t=n[e]??={},a=t[r];void 0!==a&&a!==s&&d.push(`${e}/${r||"(no model)"}: "${a}" vs "${s}"`),t[r]=s};if(0===t.length)l("");else for(let r of t)(a[e]??=[]).push(r),l(r)}d.length>0&&r.push(`Phase ${e.id??"?"} has overlapping reviewer candidates with conflicting personas (${d.join("; ")}) — form mode would silently last-write-wins; edit in YAML to disambiguate.`);let l=eH.includes(e.kind)?e.kind:"review";return e.kind&&!eH.includes(e.kind)&&r.push(`Phase ${e.id??"?"} has unknown kind \`${e.kind}\` — form mode would coerce it to \`review\`.`),{phase:{id:e.id??"phase",name:e.title??e.name??e.id??"Phase",description:e.description??"",kind:l,gate:"auto",doer:{lineage:s,models:e.doer?.models&&e.doer.models.length>0?e.doer.models:[O[s]??"claude-opus-4-7"],...e.doer?.persona&&e.doer.persona.trim().length>0?{persona:e.doer.persona.trim()}:{}},reviewer:{require:e.reviewer?.require??1,crossLineage:e.reviewer?.crossLineage??!0,candidates:i,candidateModels:a,...Object.keys(n).length>0?{candidatePersonas:n}:{}},inputs:{include:e.inputs?.include??[],exclude:e.inputs?.exclude??[]},iterate:{max:e.iterate?.maxRounds??2,onMax:(e.iterate?.onDisagreement??"continue")==="continue"?"loopback":e.iterate?.onDisagreement==="accept-doer"?"fail":"ask-user"},blindSpots:[],execution:"parallel",builtin:!1,...t&&e.artifact?{artifact:{label:e.artifact.label??"Artifact to review",hint:e.artifact.hint??"Paste a unified diff, a markdown draft, code, or any text blob.",maxBytes:e.artifact.maxBytes??1048576}}:t?{artifact:{label:"Artifact to review",hint:"Paste a unified diff, a markdown draft, code, or any text blob.",maxBytes:1048576}}:{}},reasons:r}}(e);i.push(r),o.push(...t)}if("number"==typeof t.agreementThreshold){var d;s=(d=t.agreementThreshold)>=.99?"unanimous":d>=.5?"majority":"any",new Set([1,.66,.34]).has(t.agreementThreshold)||(a=t.agreementThreshold,o.push(`Custom \`agreementThreshold: ${t.agreementThreshold}\` — form mode only offers 1.0 / 0.66 / 0.34 presets.`))}else s=t.agreementThreshold??"majority";let l="review"===t.onThresholdMet?"review":void 0;return"review"===l&&o.push("`onThresholdMet: review` — form mode only offers auto-finalize / ask-user."),{form:{id:t.id??r,name:t.name??"",description:t.description??"",author:t.author??"chorus",category:(n=(t.id??r).toLowerCase()).includes("bug")||n.includes("debug")||n.includes("diagnose")?"debug":n.includes("plan")||n.includes("architect")?"plan":n.includes("decide")||n.includes("decision")?"decide":"review",phases:i.length>0?i:z.phases,threshold:s,...void 0!==a?{customThreshold:a}:{},onThresholdMet:"merge"===t.onThresholdMet?"auto-finalize":"ask-user",...l?{onThresholdMetRaw:l}:{},maxRounds:t.maxRounds??3,yoloDefault:t.yoloDefault??!1,fallbackDoer:eK(t.fallback?.doer),fallbackReviewer:eK(t.fallback?.reviewer)},formLossy:o.length>0,lossyReasons:o}}function eJ({yaml:e,filename:r,issues:t,onChange:a}){return(0,s.jsxs)("div",{className:"flex h-full min-h-[400px] flex-col",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between border-b border-border bg-card/40 px-6 py-2.5",children:[(0,s.jsx)("span",{className:"font-mono text-[11px] text-muted-foreground",children:r}),(0,s.jsx)(eQ,{issues:t})]}),(0,s.jsx)("textarea",{value:e,onChange:e=>a(e.target.value),spellCheck:!1,className:"flex-1 resize-none border-0 bg-background px-6 py-4 font-mono text-[12px] leading-relaxed text-foreground focus:outline-none"}),t.length>0&&(0,s.jsx)("ul",{className:"border-t border-border bg-destructive/5 px-6 py-2.5 text-[11px] text-destructive",children:t.map((e,r)=>(0,s.jsxs)("li",{className:"flex items-start gap-1.5 leading-snug",children:[(0,s.jsx)(g.A,{className:"mt-[1px] h-3 w-3 shrink-0"}),(0,s.jsxs)("span",{children:[(0,s.jsx)("span",{className:"font-mono",children:e.path}),"number"==typeof e.line&&` (line ${e.line})`,": ",e.message]})]},r))})]})}function eQ({issues:e}){return 0===e.length?(0,s.jsxs)("span",{className:"flex items-center gap-1 rounded-md bg-emerald-500/10 px-1.5 py-0.5 text-[10px] font-medium text-emerald-400",children:[(0,s.jsx)(b.A,{className:"h-3 w-3"}),"Valid"]}):(0,s.jsxs)("span",{className:"flex items-center gap-1 rounded-md bg-destructive/10 px-1.5 py-0.5 text-[10px] font-medium text-destructive",children:[(0,s.jsx)(g.A,{className:"h-3 w-3"}),e.length," ",1===e.length?"issue":"issues"]})}function eX({editing:e,trigger:r,onSaved:t}){var i;let[d,l]=(0,a.useState)(!1),c=!!e,u=(0,a.useMemo)(()=>{if(!e)return{form:z,yaml:H(z),lossy:!1,reasons:[]};let r=eZ(e.yaml,e.id);return{form:r.form,yaml:e.yaml,lossy:r.formLossy,reasons:r.lossyReasons}},[e?.id,e?.yaml]),[m,w]=(0,a.useState)(u.form),[N,k]=(0,a.useState)(u.yaml),[C,A]=(0,a.useState)(!1),[M,S]=(0,a.useState)(!1),[Y,L]=(0,a.useState)(u.lossy?"yaml":"form"),[D,$]=(0,a.useState)(!1),[_,E]=(0,a.useState)(null),[q,I]=(0,a.useState)([]);(0,a.useEffect)(()=>{w(u.form),k(u.yaml),A(!1),S(!1),L(u.lossy?"yaml":"form"),E(null),I([])},[u]);let F=(0,a.useRef)(u);(0,a.useEffect)(()=>{F.current=u});let O=(i={yamlDirty:C,tab:Y,formDirty:M,yamlText:N,formYaml:H(m),initialYaml:u.yaml}).yamlDirty||"yaml"===i.tab?i.yamlText:i.formDirty?i.formYaml:i.initialYaml,B=(0,a.useMemo)(()=>(function(e){let r;if(0===e.trim().length)return{valid:!1,issues:[{path:"<yaml>",message:"Template YAML is empty."}]};try{r=y.Ay.parse(e)}catch(t){let e=t instanceof Error?t.message:String(t),r=t.linePos?.[0];return{valid:!1,issues:[{path:"<yaml>",message:e,...r?{line:r.line,col:r.col}:{}}]}}if(null==r)return{valid:!1,issues:[{path:"<yaml>",message:"Template YAML parsed to null — at minimum it must define id, name, and phases."}]};let t=R.safeParse(r);return t.success?P:{valid:!1,issues:t.error.issues.map(e=>({path:e.path.length>0?e.path.join("."):"<root>",message:e.message}))}})(O),[O]);function U(e){if("form"===e&&C){let e=eZ(N,m.id);if(e.formLossy)return;w(e.form),A(!1),S(!0)}L(e)}function V(){let e=F.current;w(e.form),k(e.yaml),A(!1),S(!1),L(e.lossy?"yaml":"form"),$(!1),E(null),I([])}function G(e){l(e),e||setTimeout(V,200)}async function W(){if(!B.valid||D)return;let r=c?e.id:m.id||K(m.name)||"untitled";$(!0),E(null),I([]);try{let e=await (0,j.AI)({id:r,yaml:O});t?.(e.id),G(!1)}catch(e){e instanceof j.$v?(E(e.message),I(e.details?.issues??[])):E(e instanceof Error?e.message:"Save failed (unknown error)")}finally{$(!1)}}let Z=B.valid&&!D,J=r??(0,s.jsxs)("button",{type:"button","aria-label":c?"Edit template":"New template",className:"inline-flex shrink-0 items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-sm font-medium text-primary-foreground shadow-sm transition hover:bg-primary/90",children:[c?(0,s.jsx)(n.A,{className:"h-4 w-4"}):(0,s.jsx)(x.A,{className:"h-4 w-4"}),(0,s.jsx)("span",{className:"hidden sm:inline",children:c?"Edit":"New template"})]});return(0,s.jsxs)(v.lG,{open:d,onOpenChange:G,children:[(0,s.jsx)(v.zM,{asChild:!0,children:J}),(0,s.jsxs)(v.Cf,{showCloseButton:!1,className:"flex max-h-[85vh] w-[min(96vw,720px)] flex-col gap-0 overflow-hidden border-border bg-card p-0 shadow-2xl sm:max-w-none",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3 border-b border-border px-6 py-4",children:[(0,s.jsx)("div",{className:"grid h-9 w-9 shrink-0 place-items-center rounded-md bg-primary/15 text-primary ring-1 ring-primary/20",children:(0,s.jsx)(p.A,{className:"h-4 w-4"})}),(0,s.jsxs)("div",{className:"flex-1",children:[(0,s.jsx)(v.L3,{className:"text-[15px] font-semibold leading-tight tracking-tight",children:c?`Edit template — ${e.name}`:"New template"}),(0,s.jsx)(v.rr,{className:"mt-0.5 text-xs text-muted-foreground",children:c?"Edit the YAML directly or use the form. Validation runs live.":"A reusable review workflow. Edit visually below or paste raw YAML."})]}),(0,s.jsx)("button",{type:"button",onClick:()=>G(!1),className:"grid h-7 w-7 place-items-center rounded-md text-muted-foreground transition hover:bg-accent hover:text-foreground","aria-label":"Close",children:(0,s.jsx)(h.A,{className:"h-4 w-4"})})]}),(0,s.jsx)("div",{className:"border-b border-border bg-card/40 px-6",children:(0,s.jsxs)("div",{className:"-mb-px flex items-center gap-1",children:[(0,s.jsxs)(eE,{active:"form"===Y,onClick:()=>!u.lossy&&U("form"),disabled:u.lossy,children:[(0,s.jsx)(f.A,{className:"h-3.5 w-3.5"}),"Form",u.lossy&&(0,s.jsx)("span",{className:"ml-1 rounded bg-muted px-1 text-[9px] font-medium text-muted-foreground",children:"YAML only"})]}),(0,s.jsxs)(eE,{active:"yaml"===Y,onClick:()=>U("yaml"),children:[(0,s.jsx)(p.A,{className:"h-3.5 w-3.5"}),"YAML",!B.valid&&"form"===Y&&(0,s.jsx)("span",{className:"ml-1 h-1.5 w-1.5 rounded-full bg-destructive"})]})]})}),(0,s.jsxs)("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[u.lossy&&"yaml"===Y&&(0,s.jsx)("div",{className:"border-b border-amber-500/30 bg-amber-500/5 px-6 py-2.5 text-[11px] text-amber-200",children:(0,s.jsxs)("div",{className:"flex items-start gap-2",children:[(0,s.jsx)(g.A,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),(0,s.jsxs)("div",{className:"flex-1",children:[(0,s.jsx)("div",{className:"font-medium",children:"Form editing disabled for this template"}),(0,s.jsx)("ul",{className:"mt-1 space-y-0.5 leading-snug",children:u.reasons.map((e,r)=>(0,s.jsxs)("li",{children:["\xb7 ",e]},r))})]})]})}),"form"===Y?(0,s.jsx)(eV,{form:m,setField:function(e,r){let t={...m,[e]:r};w(t),S(!0),C||k(H(t))}}):(0,s.jsx)(eJ,{yaml:N,filename:`${m.id||K(m.name)||"untitled"}.yaml`,issues:B.issues,onChange:e=>{k(e),A(!0)}})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-2 border-t border-border bg-card/40 px-6 py-3",children:[_&&(0,s.jsx)("div",{className:"rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-[11px] text-destructive",children:(0,s.jsxs)("div",{className:"flex items-start gap-1.5",children:[(0,s.jsx)(g.A,{className:"mt-0.5 h-3 w-3 shrink-0"}),(0,s.jsxs)("div",{className:"flex-1",children:[(0,s.jsx)("div",{className:"font-medium",children:"Save failed"}),(0,s.jsx)("div",{className:"mt-0.5 leading-snug",children:_}),q.length>0&&(0,s.jsx)("ul",{className:"mt-1 space-y-0.5",children:q.slice(0,5).map((e,r)=>(0,s.jsxs)("li",{children:[(0,s.jsx)("span",{className:"font-mono",children:e.path}),":"," ",e.message]},r))})]})]})}),(0,s.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,s.jsx)("div",{className:"flex items-center gap-1.5 text-[11px] text-muted-foreground",children:B.valid?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(b.A,{className:"h-3 w-3 text-emerald-400"}),(0,s.jsx)("span",{children:"Ready to save"})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(g.A,{className:"h-3 w-3 text-destructive/80"}),(0,s.jsxs)("span",{children:[B.issues.length," ",1===B.issues.length?"issue":"issues"," to resolve"]})]})}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("button",{type:"button",onClick:()=>G(!1),className:"h-9 rounded-md border border-border bg-card px-4 text-sm font-medium text-muted-foreground transition hover:border-muted-foreground/30 hover:text-foreground",children:"Cancel"}),(0,s.jsxs)("button",{type:"button",disabled:!Z,onClick:W,className:(0,T.cn)("inline-flex h-9 items-center gap-1.5 rounded-md px-4 text-sm font-medium shadow-sm transition",Z?"bg-primary text-primary-foreground hover:bg-primary/90":"cursor-not-allowed bg-muted text-muted-foreground/60 shadow-none"),children:[D&&(0,s.jsx)(o.A,{className:"h-3.5 w-3.5 animate-spin"}),D?"Saving…":c?"Save changes":"Save template"]})]})]})]})]})]})}let e0=Object.fromEntries(Object.entries(ei.r2).map(([e,r])=>[e,r.dot])),e1=[{id:"all",label:"All"},{id:"review",label:"Review"},{id:"plan",label:"Plan"},{id:"debug",label:"Debug"},{id:"decide",label:"Decide"}];function e5(){let[e,r]=(0,a.useState)([]),[t,x]=(0,a.useState)(null),[p,h]=(0,a.useState)("all"),[f,g]=(0,a.useState)(""),[b,v]=(0,a.useState)(null),[y,w]=(0,a.useState)(null),[N,k]=(0,a.useState)(null),C=(0,a.useCallback)(async e=>{try{let t=await (0,j.eG)();r(t),e&&t.find(r=>r.id===e)?g(e):t.length>0&&!f&&g(t[0].id)}catch(e){x(e instanceof j.$v?e.message:"Failed to load templates")}},[f]);async function A(e){if(!y&&"builtin"!==e.source){if(b!==e.id){v(e.id),k(null),setTimeout(()=>{v(r=>r===e.id?null:r)},8e3);return}w(e.id),k(null);try{await (0,j.I7)(e.id),v(null),f===e.id&&g(""),await C()}catch(e){k(e instanceof j.$v||e instanceof Error?e.message:"Delete failed (unknown error)"),v(null)}finally{w(null)}}}(0,a.useEffect)(()=>{C()},[]);let M="all"===p?e:e.filter(e=>e.category===p),S=e.find(e=>e.id===f)??e[0]??null;return t?(0,s.jsx)(d.G,{children:(0,s.jsx)("div",{className:"mx-auto w-full max-w-6xl px-4 py-6 sm:px-6 sm:py-8 md:px-8 md:py-10",children:(0,s.jsxs)("div",{className:"rounded-lg border border-destructive/50 bg-destructive/10 p-4",children:[(0,s.jsx)("p",{className:"text-sm text-destructive",children:"Error loading templates"}),(0,s.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:t})]})})}):(0,s.jsx)(d.G,{children:(0,s.jsxs)("div",{className:"mx-auto w-full max-w-6xl px-4 py-6 sm:px-6 sm:py-8 md:px-8 md:py-10",children:[(0,s.jsx)(u.z,{eyebrow:"Templates",title:"Reusable review workflows",subtitle:"Each template defines the driver, reviewers, prompts, and quorum rule for a kind of task. Fork, edit, share.",action:(0,s.jsx)(eX,{onSaved:e=>C(e)})}),N&&(0,s.jsx)("div",{className:"mb-4 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:N}),(0,s.jsx)("div",{className:"mb-4 flex items-center gap-1 border-b border-border",children:e1.map(e=>(0,s.jsxs)("button",{type:"button",onClick:()=>h(e.id),className:`relative px-3 py-2 text-sm transition ${e.id===p?"text-foreground":"text-muted-foreground hover:text-foreground"}`,children:[e.label,e.id===p&&(0,s.jsx)("span",{className:"absolute inset-x-3 bottom-0 h-0.5 bg-primary"})]},e.id))}),(0,s.jsxs)("div",{className:"grid grid-cols-1 gap-4 lg:grid-cols-[1fr_1fr]",children:[(0,s.jsx)("div",{className:"flex min-w-0 flex-col gap-2",children:M.map(e=>(0,s.jsxs)("div",{role:"button",tabIndex:0,onClick:()=>g(e.id),onKeyDown:r=>{("Enter"===r.key||" "===r.key)&&(r.preventDefault(),g(e.id))},className:`group relative cursor-pointer rounded-xl text-left transition focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/60 ${e.id===f?"ring-2 ring-primary/60 ring-offset-2 ring-offset-background":""}`,children:[(0,s.jsxs)(l.Zp,{className:"bg-card p-4 transition group-hover:border-muted-foreground/30",children:[(0,s.jsx)("div",{className:"flex items-start justify-between gap-3",children:(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsx)("span",{className:"text-sm font-semibold",children:e.name}),(0,s.jsx)(c.E,{variant:"outline",className:"border-border text-[10px] capitalize",children:e.category}),!1===e.isComplete&&(0,s.jsx)(c.E,{variant:"outline",className:"border-amber-500/40 bg-amber-500/10 font-mono text-[9px] uppercase text-amber-300",children:"needs setup"})]}),(0,s.jsx)("p",{className:"mt-1 text-xs text-muted-foreground line-clamp-2",children:!1===e.isComplete?"Some slots couldn't be filled from your installed CLIs. Edit the YAML to pick models for each slot.":e.description})]})}),e.phases[0]?.reviewer?.candidates.length?(0,s.jsxs)("div",{className:"mt-3 flex items-center gap-2 text-[11px] text-muted-foreground",children:[e.phases[0]?.kind!=="review_only"&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("span",{className:"flex items-center gap-1",children:[(0,s.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-amber-400"}),"doer"]}),(0,s.jsx)("span",{className:"text-muted-foreground/40",children:"→"})]}),(0,s.jsxs)("span",{className:"flex items-center gap-1",children:[e.phases[0]?.reviewer?.candidates.map(e=>(0,s.jsx)("span",{className:`h-1.5 w-1.5 rounded-full ${e0[e]}`,title:e},e)),(0,s.jsxs)("span",{children:[e.phases[0]?.reviewer?.candidates.length," ",e.phases[0]?.reviewer?.candidates.length===1?"reviewer":"reviewers"]})]}),e.phases.length>1&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"text-muted-foreground/40",children:"\xb7"}),(0,s.jsxs)("span",{className:"font-mono text-[10px]",children:[e.phases.length," phases"]})]})]}):null]}),(0,s.jsxs)("div",{className:`absolute bottom-3 right-3 flex items-center gap-1.5 transition ${e.id===f?"opacity-100":"opacity-0 group-hover:opacity-100 group-focus-within:opacity-100"}`,onClick:r=>{r.stopPropagation(),g(e.id)},onKeyDown:e=>e.stopPropagation(),children:[(0,s.jsx)(eX,{editing:e,onSaved:e=>C(e),trigger:(0,s.jsx)("button",{type:"button","aria-label":`Edit ${e.name}`,className:"grid h-7 w-7 place-items-center rounded-md border border-border bg-card text-muted-foreground transition hover:border-muted-foreground/40 hover:bg-accent/60 hover:text-foreground",children:(0,s.jsx)(n.A,{className:"h-3.5 w-3.5"})})}),"builtin"!==e.source&&(0,s.jsx)("button",{type:"button","aria-label":b===e.id?`Confirm delete ${e.name}`:`Delete ${e.name}`,title:b===e.id?"Click again to confirm":"Delete",disabled:y===e.id,onClick:()=>A(e),className:`grid h-7 w-7 place-items-center rounded-md border transition disabled:cursor-not-allowed disabled:opacity-50 ${b===e.id?"border-destructive bg-destructive/15 text-destructive":"border-border bg-card text-muted-foreground hover:border-destructive/50 hover:text-destructive"}`,children:y===e.id?(0,s.jsx)(o.A,{className:"h-3.5 w-3.5 animate-spin"}):(0,s.jsx)(i.A,{className:"h-3.5 w-3.5"})})]})]},e.id))}),S?(0,s.jsx)("div",{className:"lg:sticky lg:top-6 lg:max-h-[calc(100vh-10rem)] lg:h-[calc(100vh-10rem)]",children:(0,s.jsx)(m.N,{filename:`${S.id}.yaml`,charCount:S.yaml.length,maxHeightClassName:"h-full",footer:(0,s.jsxs)("span",{children:["by ",S.authorHandle]}),children:S.yaml})}):(0,s.jsx)(l.Zp,{className:"bg-card p-4 text-center text-muted-foreground",children:(0,s.jsx)("p",{children:"Select a template to view details"})})]})]})})}},9936:(e,r,t)=>{Promise.resolve().then(t.bind(t,4538))}},e=>{e.O(0,[116,720,15,641,344,744,506,128,358],()=>e(e.s=9936)),_N_E=e.O()}]);