const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./BYdpQP7_.js","./BcRT_Mkt.js","./DsQIgu-4.js","./DrKWWDpL.js"])))=>i.map(i=>d[i]);
import{s as e}from"./DrKWWDpL.js";import{n as t,t as n}from"./DsQIgu-4.js";import{t as r}from"./DYP3EJMY.js";import{a as i}from"./bG-fsHMS.js";var a=e(r(),1);t();var o=.75,s=.6;function c(){return`O-${(0,a.randomBytes)(4).toString(`hex`)}`}function l(){return`L-${(0,a.randomBytes)(4).toString(`hex`)}`}function u(){return`P-${(0,a.randomBytes)(4).toString(`hex`)}`}function d(){return`D-${(0,a.randomBytes)(4).toString(`hex`)}`}var f=class{name=`DeductionSpecialist`;async process(e,t,n){if(!t||e.length===0)return{specialist:this.name,created:0,skipped:!0,skipReason:`no LLM backend`};try{let t=0,r=new Date().toISOString();for(let i of e.slice(0,5)){if(!i.narrative&&!i.title)continue;let e=`[Deduction] From observation "${i.title??``}": ${(i.narrative??i.title??``).slice(0,300)}`,a=l();n.prepare(`INSERT INTO brain_learnings
               (id, insight, confidence, source, source_session_id,
                memory_tier, memory_type, created_at, provenance_class)
             VALUES (?, ?, 0.7, 'deduction-specialist', ?, 'short', 'semantic', ?, 'deriver-synthesized')`).run(a,e,i.sourceSessionId??null,r),t++}return{specialist:this.name,created:t,skipped:!1}}catch(e){let t=e instanceof Error?e.message:String(e);return{specialist:this.name,created:0,skipped:!0,skipReason:t}}}},p=class{name=`InductionSpecialist`;async process(e,t,n){if(!t||e.length<2)return{specialist:this.name,created:0,skipped:!0,skipReason:e.length<2?`insufficient observations`:`no LLM backend`};try{let t=new Date().toISOString(),r=e.slice(0,8).map(e=>e.title??``).filter(Boolean).join(`; `),i=`[Induction] Pattern from ${e.length} high-surprisal observations: ${r.slice(0,400)}`,a=u();return n.prepare(`INSERT INTO brain_patterns
             (id, pattern, context, frequency, impact, source,
              memory_tier, memory_type, created_at, provenance_class)
           VALUES (?, ?, ?, 1, 'medium', 'induction-specialist', 'short', 'procedural', ?, 'deriver-synthesized')`).run(a,i,`cluster of ${e.length} observations`,t),{specialist:this.name,created:1,skipped:!1}}catch(e){let t=e instanceof Error?e.message:String(e);return{specialist:this.name,created:0,skipped:!0,skipReason:t}}}},m=class{name=`UserPreferenceSpecialist`;async process(e,t,n){if(!t)return{specialist:this.name,created:0,skipped:!0,skipReason:`no LLM backend`};try{let t=0,r=new Date().toISOString(),i=e.filter(e=>(e.narrative??``).toLowerCase().includes(`prefer`)||(e.narrative??``).toLowerCase().includes(`like`)||(e.narrative??``).toLowerCase().includes(`always`)||(e.title??``).toLowerCase().includes(`prefer`));for(let e of i.slice(0,3)){let i=c(),a=`[UserPref] ${e.title??`preference signal`}`,s=`User preference signal extracted: ${(e.narrative??``).slice(0,200)}`;n.prepare(`INSERT INTO brain_observations
               (id, type, title, narrative, source_type, quality_score,
                memory_tier, memory_type, created_at, level,
                source_ids, provenance_class, peer_id, peer_scope)
             VALUES (?, 'fact', ?, ?, 'user-preference-specialist', ?,
                     'medium', 'semantic', ?, 'inductive', ?, 'deriver-synthesized', ?, 'project')`).run(i,a,s,o,r,JSON.stringify([e.id]),e.peerId),t++}return{specialist:this.name,created:t,skipped:!1}}catch(e){let t=e instanceof Error?e.message:String(e);return{specialist:this.name,created:0,skipped:!0,skipReason:t}}}},h=class{name=`DecisionSpecialist`;async process(e,t,n){if(!t)return{specialist:this.name,created:0,skipped:!0,skipReason:`no LLM backend`};try{let t=0,r=new Date().toISOString(),i=e.filter(e=>(e.narrative??``).toLowerCase().includes(`decided`)||(e.narrative??``).toLowerCase().includes(`chose`)||(e.narrative??``).toLowerCase().includes(`selected`)||e.type===`decision`);for(let e of i.slice(0,3)){let i=d(),a=`[Decision] ${e.title??`decision from observation`}`,o=(e.narrative??``).slice(0,500);n.prepare(`INSERT INTO brain_decisions
               (id, type, title, rationale, confidence, source_session_id,
                memory_tier, memory_type, created_at, provenance_class, peer_id, peer_scope)
             VALUES (?, 'architecture', ?, ?, 0.65, ?,
                     'short', 'semantic', ?, 'deriver-synthesized', ?, 'project')`).run(i,a,o,e.sourceSessionId??null,r,e.peerId),t++}return{specialist:this.name,created:t,skipped:!1}}catch(e){let t=e instanceof Error?e.message:String(e);return{specialist:this.name,created:0,skipped:!0,skipReason:t}}}},g=class{name=`CodePatternSpecialist`;async process(e,t,n){if(!t)return{specialist:this.name,created:0,skipped:!0,skipReason:`no LLM backend`};try{let t=new Date().toISOString(),r=e.filter(e=>e.type===`change`||(e.narrative??``).includes(`function`)||(e.narrative??``).includes(`class`)||(e.narrative??``).includes(`import`)||(e.title??``).toLowerCase().includes(`code`));if(r.length===0)return{specialist:this.name,created:0,skipped:!1};let i=u(),a=r.slice(0,6).map(e=>e.title??``).filter(Boolean).join(`; `),o=`[CodePattern] Code patterns from ${r.length} change observations: ${a.slice(0,350)}`;return n.prepare(`INSERT INTO brain_patterns
             (id, pattern, context, frequency, impact, source,
              memory_tier, memory_type, created_at, provenance_class)
           VALUES (?, ?, ?, ?, 'medium', 'code-pattern-specialist', 'short', 'procedural', ?, 'deriver-synthesized')`).run(i,o,`${r.length} code change observations`,r.length,t),{specialist:this.name,created:1,skipped:!1}}catch(e){let t=e instanceof Error?e.message:String(e);return{specialist:this.name,created:0,skipped:!0,skipReason:t}}}},_=class{name=`TaskOutcomeSpecialist`;async process(e,t,n){if(!t)return{specialist:this.name,created:0,skipped:!0,skipReason:`no LLM backend`};try{let t=0,r=new Date().toISOString(),i=e.filter(e=>(e.narrative??``).includes(`completed`)||(e.narrative??``).includes(`shipped`)||(e.narrative??``).includes(`task`)||(e.title??``).toLowerCase().includes(`T1`)||(e.title??``).toLowerCase().includes(`task`));for(let e of i.slice(0,3)){let i=c(),a=`[TaskOutcome] ${e.title??`task outcome`}`,s=`Task outcome synthesized from observation: ${(e.narrative??``).slice(0,300)}`;n.prepare(`INSERT INTO brain_observations
               (id, type, title, narrative, source_type, quality_score,
                memory_tier, memory_type, created_at, level,
                source_ids, provenance_class, peer_id, peer_scope)
             VALUES (?, 'task-outcome', ?, ?, 'task-outcome-specialist', ?,
                     'medium', 'episodic', ?, 'inductive', ?, 'deriver-synthesized', ?, 'project')`).run(i,a,s,o,r,JSON.stringify([e.id]),e.peerId),t++}return{specialist:this.name,created:t,skipped:!1}}catch(e){let t=e instanceof Error?e.message:String(e);return{specialist:this.name,created:0,skipped:!0,skipReason:t}}}},v=[new f,new p,new m,new h,new g,new _];async function y(e,t,r={}){let a={specialists:[],totalCreated:0,totalSkipped:0},o=r.db===void 0?i():r.db;if(!o){console.warn(`[specialists] No database available; all specialists skipped.`);for(let e of v)a.specialists.push({specialist:e.name,created:0,skipped:!0,skipReason:`no db`}),a.totalSkipped++;return a}let c=e;if(t!==null){let n=new Map(t.map(e=>[e.id,e.score]));c=e.filter(e=>(n.get(e.id)??.6)>=s)}if(c.length===0){for(let e of v)a.specialists.push({specialist:e.name,created:0,skipped:!0,skipReason:`no observations above threshold`}),a.totalSkipped++;return a}let l=!1;try{l=await(r.resolveLlm??(async()=>{let{resolveLlmBackend:e}=await n(async()=>{let{resolveLlmBackend:e}=await import(`./BYdpQP7_.js`);return{resolveLlmBackend:e}},__vite__mapDeps([0,1,2,3]),import.meta.url);return e(`warm`)}))()!==null}catch{l=!1}for(let e of v)try{let t=await e.process(c,l,o);a.specialists.push(t),a.totalCreated+=t.created,t.skipped&&a.totalSkipped++}catch(t){let n=t instanceof Error?t.message:String(t);a.specialists.push({specialist:e.name,created:0,skipped:!0,skipReason:`unexpected error: ${n}`}),a.totalSkipped++}return a}export{g as CodePatternSpecialist,h as DecisionSpecialist,f as DeductionSpecialist,p as InductionSpecialist,s as SPECIALIST_SURPRISAL_THRESHOLD,_ as TaskOutcomeSpecialist,m as UserPreferenceSpecialist,y as dispatchSpecialists};