const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./bXAQrK7j.js","./DrKWWDpL.js","./DIQmuJJZ.js","./D7w7HllH.js","./DB5ifLM-.js","./DYP3EJMY.js"])))=>i.map(i=>d[i]);
import"./DrKWWDpL.js";import{n as e,t}from"./DsQIgu-4.js";import{t as n}from"./DYP3EJMY.js";import"./DVQI6VOy.js";import{a as r,r as i}from"./bG-fsHMS.js";import"./BVC3q6GM.js";import{a,s as o}from"./Cx_-1PHK2.js";import"./Dn7LRnjg2.js";import"./BVDTFQLg.js";import{k as s}from"./DRa3KiKE.js";import{n as c,t as l}from"./CvFbqtf9.js";import{t as u}from"./ByGkWwzP2.js";import"./C0bVU7gr2.js";import"./DmLgVuva2.js";n();async function d(e,t){try{await i(t);let n=r();return n?l(n.prepare(`SELECT
         substr(from_id, 6) as task_id,
         'Task ' || substr(from_id, 6) as label,
         weight,
         edge_type
       FROM brain_page_edges
       WHERE to_id = ?
         AND edge_type = ?
       ORDER BY weight DESC`),e,u.TASK_TOUCHES_SYMBOL).map(e=>({taskId:e.task_id,label:e.label,weight:e.weight,matchStrategy:`git-log-file-match`})):[]}catch(t){return s({code:`W_TASKS_BRIDGE_FAILED`,message:`getTasksForSymbol failed for ${e}`,severity:`warn`,context:{bridge:`tasks`,operation:`getTasksForSymbol`,symbolId:e,error:t instanceof Error?t.message:String(t)}}),[]}}e();function f(e){switch(e){case`critical`:return`CRITICAL`;case`high`:return`HIGH`;case`medium`:return`MEDIUM`;case`low`:return`LOW`;default:return`NONE`}}function p(e){let t=[`NONE`,`LOW`,`MEDIUM`,`HIGH`,`CRITICAL`],n=0;for(let r of e){let e=t.indexOf(r);e>n&&(n=e)}return t[n]??`NONE`}async function m(e,n){let s={symbolId:e,structural:{directCallers:0,likelyAffected:0,mayNeedTesting:0,totalAffected:0,riskLevel:`NONE`},openTasks:[],brainRiskNotes:[],mergedRiskScore:`NONE`,narrative:`No impact data available for symbol '${e}'.`},m=e;try{await a();let t=o();if(t){let n=c(t.prepare(`SELECT id, kind, name, file_path, label, community_id
           FROM nexus_nodes WHERE id = ? LIMIT 1`),e);n||=c(t.prepare(`SELECT id, kind, name, file_path, label, community_id
             FROM nexus_nodes
             WHERE LOWER(name) = LOWER(?) AND kind NOT IN ('community', 'process', 'folder')
             LIMIT 1`),e),n&&(m=n.id)}}catch(e){console.warn(`[living-brain] reasonImpactOfChange nexus resolve failed:`,e instanceof Error?e.message:String(e))}try{await a();let e=o();if(e){let{analyzeImpact:n}=await t(async()=>{let{analyzeImpact:e}=await import(`./bXAQrK7j.js`);return{analyzeImpact:e}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),r=l(e.prepare(`SELECT id, name, kind, file_path, label, is_exported FROM nexus_nodes LIMIT 50000`)),i=l(e.prepare(`SELECT id, source_id, target_id, type, confidence FROM nexus_relations LIMIT 200000`)),a=r.map(e=>({id:e.id,name:e.name??e.label,kind:e.kind,filePath:e.file_path??``,startLine:0,endLine:0,language:`unknown`,exported:e.is_exported===1})),o=i.map(e=>({source:e.source_id,target:e.target_id,type:e.type,confidence:e.confidence??1})),c;try{c=n(m,a,o)}catch{c={target:m,riskLevel:`low`,summary:``,affectedByDepth:{depth1_willBreak:[],depth2_likelyAffected:[],depth3_mayNeedTesting:[]},totalAffected:0}}s.structural={directCallers:c.affectedByDepth.depth1_willBreak.length,likelyAffected:c.affectedByDepth.depth2_likelyAffected.length,mayNeedTesting:c.affectedByDepth.depth3_mayNeedTesting.length,totalAffected:c.totalAffected,riskLevel:f(c.riskLevel)}}}catch(e){console.warn(`[living-brain] reasonImpactOfChange structural analysis failed:`,e instanceof Error?e.message:String(e))}try{s.openTasks=(await d(m,n)).map(e=>({taskId:e.taskId,label:e.label,weight:e.weight}))}catch(e){console.warn(`[living-brain] reasonImpactOfChange open-tasks lookup failed:`,e instanceof Error?e.message:String(e))}try{await i(n);let e=r();if(e){let t=[u.CODE_REFERENCE,u.DOCUMENTS,u.MENTIONS,u.AFFECTS],n=t.map(()=>`?`).join(`, `),r=l(e.prepare(`SELECT from_id, to_id, edge_type, weight
           FROM brain_page_edges
           WHERE to_id = ? AND edge_type IN (${n})
           LIMIT 50`),m,...t),i=l(e.prepare(`SELECT from_id, to_id, edge_type, weight
           FROM brain_page_edges
           WHERE from_id = ? AND edge_type = ?
           LIMIT 50`),m,u.AFFECTS),a=new Set,o=(t,n)=>{for(let r of t){let t=n?r.from_id:r.to_id;if(a.has(t))continue;a.add(t);let i=c(e.prepare(`SELECT id, node_type, label, quality_score
               FROM brain_page_nodes WHERE id = ? LIMIT 1`),t);if(i){let e={nodeId:i.id,nodeType:i.node_type,label:i.label,edgeType:r.edge_type,weight:r.weight};s.brainRiskNotes.push(e)}}};o(r,!0),o(i,!1)}}catch(e){console.warn(`[living-brain] reasonImpactOfChange brain risk notes failed:`,e instanceof Error?e.message:String(e))}let h=[s.structural.riskLevel];s.openTasks.length>=5?h.push(`HIGH`):s.openTasks.length>=2?h.push(`MEDIUM`):s.openTasks.length>=1&&h.push(`LOW`),s.brainRiskNotes.filter(e=>e.weight>=.8).length>=3&&h.push(`MEDIUM`),s.mergedRiskScore=p(h);let g=e===m?`'${e}'`:`'${e}' (${m})`,_=s.structural.directCallers,v=s.structural.likelyAffected,y=s.openTasks.length,b=s.brainRiskNotes.length;return s.narrative=`Changing ${g} will break ${_} direct caller${_===1?``:`s`} (d=1)`+(v>0?`, likely affect ${v} at d=2`:``)+(y>0?`, and is referenced in ${y} open task${y===1?``:`s`}`:``)+(b>0?` and ${b} BRAIN risk note${b===1?``:`s`}`:``)+`. Merged risk: ${s.mergedRiskScore}.`,s}export{m as reasonImpactOfChange};