const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./Dm1HkpJd2.js","./Ouh6Dj2I2.js","./DsQIgu-4.js","./DrKWWDpL.js","./yX3I--Np.js","./DiIbXgam.js","./DOqzs8kl2.js","./DYP3EJMY.js","./DTkg6Mnx.js","./DIQmuJJZ.js","./D7w7HllH.js","./DB5ifLM-.js","./BSkUUZJr2.js","./kwfd020K.js","./CxlOpib82.js","./BDDiPmhF.js","./BYJC6_MM.js","./CX8DOZuw2.js","./BMGkukPk.js","./DoOTPDI-.js","./DO4myGf_.js","./ByMOJ7vP.js","./Dkl5tdOm2.js","./b2R8Ad-3.js","./Od6vz3AQ.js","./CMdgFTSd.js","./CvWN0JfP.js","./CGiEzQvk.js","./6qfzuuhO.js","./C7FdbtRT.js","./BPr73Pj8.js","./COfTZUNn.js","./D2jkj_HI.js","./CzgNarYu.js","./Blw0ugqW2.js","./CiotqGya.js","./CBuincfO.js","./NC6fXeo_.js","./DXsj0Ygw.js","./Cjus22ap.js"])))=>i.map(i=>d[i]);
import{n as e,t}from"./DsQIgu-4.js";import{Cn as n,In as r,Sn as i,kt as a,vt as o}from"./D7w7HllH.js";e();var s=.85,c=.92,l=.5,u=.85,d=.4,f=500,p=15e3,m=n({are_duplicate:a(),confidence:i().min(0).max(1),distinction:r().nullable(),suggestion:o([`merge`,`keep-both`,`block-new`])});function h(e){return e.toLowerCase().replace(/[^\w\s-]/g,` `).replace(/\s+/g,` `).trim()}function g(e){let t=new Set;if(e.length<3)return e.length>0&&t.add(e.padEnd(3,` `)),t;for(let n=0;n<=e.length-3;n++)t.add(e.slice(n,n+3));return t}function _(e,t){if(e.size===0&&t.size===0)return 0;let n=0;for(let r of e)t.has(r)&&n++;let r=e.size+t.size-n;return r===0?0:n/r}function v(e,t){return h(`${e} ${e} ${t}`)}function y(e,t,n,r){let i=v(e,t),a=v(n,r);return i===a?1:_(g(i),g(a))}function b(e){let t=new Set;for(let n of e)t.add(n);for(let n=0;n<e.length-1;n++)t.add(`${e[n]} ${e[n+1]}`);return t}function x(e){return h(e).split(/\s+/).filter(e=>e.length>0)}function S(e,t,n){let r=x(e),i=x(t),a=n.flatMap(e=>x(e));return b([...r,...r,...i,...a])}function C(e,t,n,r,i,a){return _(S(e,t,n),S(r,i,a))}async function w(e,n){try{let{isEmbeddingAvailable:r,embedText:i}=await t(async()=>{let{isEmbeddingAvailable:e,embedText:t}=await import(`./Dm1HkpJd2.js`);return{isEmbeddingAvailable:e,embedText:t}},__vite__mapDeps([0,1,2,3]),import.meta.url);if(!r())return null;let[a,o]=await Promise.all([i(e),i(n)]);if(!a||!o||a.length!==o.length)return null;let s=0,c=0,l=0;for(let e=0;e<a.length;e++)s+=(a[e]??0)*(o[e]??0),c+=(a[e]??0)**2,l+=(o[e]??0)**2;let u=Math.sqrt(c)*Math.sqrt(l);return u===0?null:Math.max(0,Math.min(1,s/u))}catch{return null}}function T(){return[`You are a task-management assistant determining whether two software tasks are semantic duplicates.`,`Respond ONLY with valid JSON matching this schema:`,`{ "are_duplicate": boolean, "confidence": number (0-1), "distinction": string|null, "suggestion": "merge"|"keep-both"|"block-new" }`,``,`Rules:`,`- are_duplicate=true when both tasks describe the SAME work deliverable (even if worded differently)`,`- are_duplicate=false when they target different deliverables, different scopes, or different problem domains`,`- distinction must be non-null when are_duplicate=false (explain what makes them different)`,`- suggestion: "merge"=consolidate into one task, "keep-both"=distinct tasks worth tracking separately, "block-new"=new task is redundant`,`- Do NOT add any explanation outside the JSON object.`].join(`
`)}function E(e,t,n,r,i){return[`Task A (NEW — being added now):`,`  Title: ${e}`,`  Description: ${t||`(no description provided)`}`,``,`Task B (EXISTING — ${i}):`,`  Title: ${n}`,`  Description: ${r||`(no description)`}`,``,`Are these the same task (semantic duplicate)? Respond with JSON only.`].join(`
`)}async function D(e,n,r,i){try{let{authHeadersFromSealed:a}=await t(async()=>{let{authHeadersFromSealed:e}=await import(`./yX3I--Np.js`);return{authHeadersFromSealed:e}},__vite__mapDeps([4,5,3,6,7,8,9,10,11,12,13,14,15,16,17,2,18,19,20,21]),import.meta.url),{resolveLLMForRole:o}=await t(async()=>{let{resolveLLMForRole:e}=await import(`./Dkl5tdOm2.js`);return{resolveLLMForRole:e}},__vite__mapDeps([22,12,3,13,9,10,11,7,14,15,16,17,2,6,23,24,25,8,26,5,18,19,20,21]),import.meta.url),s=await o(`consolidation`,{projectRoot:i});if(!s.sealedCredential||!s.credential)return null;let c=T(),l=E(e,n,r.title,r.description??``,r.id),u={transport:s.provider,model:s.model,apiKey:(await s.sealedCredential.fetch()).value,extraHeaders:s.credential.authType===`oauth`?await a(s.sealedCredential,s.credential.authType):void 0},{cleoLlmCall:d}=await t(async()=>{let{cleoLlmCall:e}=await import(`./CGiEzQvk.js`);return{cleoLlmCall:e}},__vite__mapDeps([27,3,2,28,24,25,29,30,31,32,33,34,35,36,8,7,10,11,26,37,38,20,6,21,16,17,9,14,19,39,5,12,13,15,18]),import.meta.url),f=d({modelConfig:u,prompt:l,maxTokens:256,jsonMode:!0,temperature:0,enableRetry:!1,messages:[{role:`system`,content:c}]}),h=new Promise(e=>{setTimeout(()=>e(null),p)}),g=await Promise.race([f,h]);if(!g)return null;let _=typeof g==`object`&&g&&`content`in g?g.content:null;if(!_)return null;let v;if(typeof _==`string`)try{v=JSON.parse(_)}catch{let e=/\{[\s\S]*\}/.exec(_);if(!e)return null;try{v=JSON.parse(e[0])}catch{return null}}else if(typeof _==`object`)v=_;else return null;let y=m.safeParse(v);return y.success?y.data:null}catch{return null}}async function O(e,n,r,i,a){let o=i??[],{tasks:s}=await r.queryTasks({status:[`pending`,`active`,`blocked`],limit:f});if(s.length===0)return{maxScore:0,candidates:[],shouldReject:!1,shouldWarn:!1,tier:`bm25`};let p=v(e,n),m=await(async()=>{try{let{isEmbeddingAvailable:e}=await t(async()=>{let{isEmbeddingAvailable:e}=await import(`./Dm1HkpJd2.js`);return{isEmbeddingAvailable:e}},__vite__mapDeps([0,1,2,3]),import.meta.url);return e()}catch{return!1}})(),h=[],g=[];for(let t of s){if(t.title===e&&(t.description??``)===n)continue;let r=v(t.title,t.description??``),i;i=m?await w(p,r)??y(e,n,t.title,t.description??``):y(e,n,t.title,t.description??``),i>=.92?g.push({id:t.id,title:t.title,score:i}):i>=l&&(h.push({task:t,bm25Score:i}),i>=.85&&g.push({id:t.id,title:t.title,score:i}))}if(g.some(e=>e.score>=.92)){let e=g.filter(e=>e.score>=c).sort((e,t)=>t.score-e.score).slice(0,3);return{maxScore:e[0]?.score??0,candidates:e,shouldReject:!0,shouldWarn:!1,tier:`bm25`}}let _=[],b=[];for(let{task:t,bm25Score:r}of h){let r=C(e,n,o,t.title,t.description??``,t.labels??[]);r>=u?b.push({id:t.id,title:t.title,score:r}):r>=d&&_.push({task:t,jaccardScore:r})}if(b.length>0){let e=b.sort((e,t)=>t.score-e.score).slice(0,3);return{maxScore:e[0]?.score??0,candidates:e,shouldReject:!0,shouldWarn:!1,tier:`jaccard`}}if(_.length>0){_.sort((e,t)=>t.jaccardScore-e.jaccardScore);let t=_[0],r=await D(e,n,{id:t.task.id,title:t.task.title,score:t.jaccardScore,description:t.task.description??``},a);if(r!==null){if(r.are_duplicate){let e={id:t.task.id,title:t.task.title,score:r.confidence};return{maxScore:r.confidence,candidates:[e],shouldReject:!0,shouldWarn:!1,tier:`llm`}}return{maxScore:t.jaccardScore,candidates:[],shouldReject:!1,shouldWarn:!1,tier:`llm`}}let i=h.find(e=>e.task.id===t.task.id)?.bm25Score??t.jaccardScore;if(i>=.85)return{maxScore:i,candidates:[{id:t.task.id,title:t.task.title,score:i}],shouldReject:!1,shouldWarn:!0,tier:`bm25`}}let x=g.filter(e=>e.score>=.85&&e.score<.92).sort((e,t)=>t.score-e.score).slice(0,3);return x.length>0?{maxScore:x[0]?.score??0,candidates:x,shouldReject:!1,shouldWarn:!0,tier:`bm25`}:{maxScore:0,candidates:[],shouldReject:!1,shouldWarn:!1,tier:`bm25`}}function k(e){return e.map(e=>`  • ${e.id}: "${e.title}" (similarity: ${(e.score*100).toFixed(0)}%)`).join(`
`)}function A(e){return`[BRAIN duplicate-check] Similar active tasks found (score >= ${Math.round(s*100)}%):\n`+k(e)+`
Use --force-duplicate to bypass this warning if the task is intentionally different.`}function j(e){return`[BRAIN duplicate-check] Task creation REJECTED — very similar active tasks found (score >= ${Math.round(c*100)}%):\n`+k(e)+`
Run with --force-duplicate to bypass (audited to .cleo/audit/duplicate-bypass.jsonl).`}export{j as buildRejectMessage,A as buildWarnMessage,O as checkDuplicates};