const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./BlapV1mo.js","./bG-fsHMS.js","./DrKWWDpL.js","./DsQIgu-4.js","./DTkg6Mnx.js","./DYP3EJMY.js","./DeO5NWhN.js","./DgZn9uJn.js","./CbGRcr-D.js","./CudpqN6Z.js","./CX8DOZuw2.js","./DOqzs8kl2.js","./DIQmuJJZ.js","./D7w7HllH.js","./DB5ifLM-.js","./CxlOpib82.js","./Czb-RtcG.js","./C0nwgWmB.js","./D-eE9s2f.js","./CWxOfblT.js","./DlZwu-Y7.js","./Bx6JGXX0.js","./o6gedrVd.js","./Dg_1c8FK2.js","./-TjUTcZv2.js","./2yUiEINB.js","./CvFbqtf9.js","./CG84LPq-.js","./2PQNgpBd.js","./DsanjglN.js","./BmWTAsFW.js","./B5XQZRTz.js","./CVwAhlPZ.js","./BVC3q6GM.js","./B8PRMiR2.js","./BDDiPmhF.js","./BYJC6_MM.js","./Cx_-1PHK2.js","./B_DA9RKE2.js","./DOPTvi6T.js","./CvaH7m0y.js","./O2P-f9sv.js","./BQ9wXJVQ2.js","./OnYyYdSr2.js","./ImGf_A8f.js","./Dn7LRnjg2.js","./g1JRWaWn.js","./CMdgFTSd.js","./DfVstSkc.js","./BSkUUZJr2.js","./kwfd020K.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,Tt as a,vt as o}from"./D7w7HllH.js";import"./BSkUUZJr2.js";import{n as s}from"./b2R8Ad-3.js";import{i as c,n as l}from"./DFB29SWc.js";e();var u=n({memories:a(n({type:o([`decision`,`pattern`,`learning`,`constraint`,`correction`]),content:r().min(1).max(500),importance:i().min(0).max(1),entities:a(r()).max(20),justification:r().min(1).max(200)})).max(20)}),d=`You are extracting durable knowledge from a coding session transcript.
Extract ONLY high-value items. Reject noise (greetings, meta-commentary, transient state).

For each extraction provide:
- type: decision|pattern|learning|constraint|correction
- content: the knowledge itself (<=500 chars, declarative form)
- importance: 0.0-1.0 (only >=0.6 will be stored)
- entities: code symbols, files, concepts mentioned
- justification: why this is worth remembering (<=200 chars)

Type definitions:
- decision: architectural or design choice with rationale ("We chose X because Y")
- pattern: recurring approach that works ("When X, do Y because Z")
- learning: factual knowledge gained ("X depends on Y via Z")
- constraint: rule/limitation discovered ("X must always Y")
- correction: anti-pattern to avoid ("Avoid X because Y; use Z instead")

Rules:
- Capture the WHY, not just the WHAT
- If nothing of durable value exists in the transcript, return an empty array
- Prefer fewer high-quality extractions over many low-quality ones
- Ignore: tool output noise, routine status messages, file reads without a finding
- Maximum 7 extractions per call`;function f(e,t,n){return`Session ID: ${e}

Transcript:
${t}

Extract up to ${n} high-value memories. Return empty array if nothing valuable.`}function p(e,t){if(e.length<=t)return e;let n=Math.floor(t/2)-64,r=e.slice(0,n),i=e.slice(-n);return`${r}\n\n[... ${e.length-t} chars omitted ...]\n\n${i}`}async function m(e,n,r){if(r.type===`decision`){let n=await l(e,r.content,`brain_decisions`);if(n.matched){let{getBrainNativeDb:r,getBrainDb:i}=await t(async()=>{let{getBrainNativeDb:e,getBrainDb:t}=await import(`./BlapV1mo.js`);return{getBrainNativeDb:e,getBrainDb:t}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]),import.meta.url);return i(e).then(()=>{r()?.prepare(`UPDATE brain_decisions SET citation_count = citation_count + 1 WHERE id = ?`).run(n.id)}).catch(()=>void 0),`merged`}let{storeDecision:i}=await t(async()=>{let{storeDecision:e}=await import(`./Bx6JGXX0.js`);return{storeDecision:e}},__vite__mapDeps([21,22,2,3,12,13,14,5,23,4,1,6,7,8,9,10,11,15,16,17,18,19,20,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45]),import.meta.url);try{let{decisionText:t,rationale:n}=h(r.content);return await i(e,{type:`technical`,decision:t,rationale:n,confidence:g(r.importance)}),`stored`}catch{return`rejected`}}let i=r.type===`constraint`?Math.max(r.importance,.8):r.importance,a;a=r.type===`correction`||r.type===`pattern`?{text:r.content,title:`${r.type===`correction`?`Correction`:`Pattern`}: ${r.content.slice(0,80)}`,memoryType:`procedural`,tier:`medium`,confidence:i,source:`transcript`,sourceSessionId:n,sourceConfidence:`agent`}:{text:r.content,title:`${r.type===`constraint`?`Constraint`:`Learning`}: ${r.content.slice(0,80)}`,memoryType:`semantic`,tier:`medium`,confidence:i,source:`transcript`,sourceSessionId:n,sourceConfidence:`agent`};try{let t=await c(e,a);return t.action===`stored`?`stored`:t.action===`merged`?`merged`:`rejected`}catch{return`rejected`}}function h(e){let t=e.toLowerCase().indexOf(` because `);return t===-1?{decisionText:e.trim(),rationale:`See justification`}:{decisionText:e.slice(0,t).trim(),rationale:e.slice(t+1).trim()}}function g(e){return e>=.8?`high`:e>=.6?`medium`:`low`}async function _(e){let t=await s(`extraction`,{projectRoot:e});return t?{client:t.client,model:t.model}:null}async function v(e){try{return(await t(()=>import(`./g1JRWaWn.js`),__vite__mapDeps([46,47,14,2]),import.meta.url)).zodOutputFormat(e)}catch{return null}}async function y(e){let n={extractedCount:0,storedCount:0,mergedCount:0,rejectedCount:0,warnings:[]},{projectRoot:r,sessionId:i,transcript:a}=e;if(typeof a!=`string`||a.trim().length===0)return n;let{loadConfig:o}=await t(async()=>{let{loadConfig:e}=await import(`./DfVstSkc.js`);return{loadConfig:e}},__vite__mapDeps([48,49,2,50,12,13,14,5,15,35,36,10,3,11]),import.meta.url),s;try{s=await o(r)}catch{n.warnings.push(`config load failed, using defaults`),s=void 0}let c=s?.brain?.llmExtraction;if(!(c?.enabled??!0))return n.warnings.push(`llmExtraction.enabled=false`),n;let l=c?.minImportance??.6,h=c?.maxExtractions??7,g=c?.maxTranscriptChars??6e4,y=e.client?null:await _(r),x=e.client??y?.client??null;if(!x)return n.warnings.push(`No Anthropic API key found (checked ANTHROPIC_API_KEY env and ~/.claude/.credentials.json) — extraction skipped`),n;let S=c?.model??y?.model??`claude-haiku-4-5-20251001`,C=f(i,p(a,g),h),w=[];try{let e=await v(u);w=e?(await x.messages.parse({model:S,max_tokens:4096,system:d,messages:[{role:`user`,content:C}],output_config:{format:e}})).parsed_output?.memories??[]:await b(x,S,C)}catch(e){let t=e instanceof Error?e.message:String(e);return n.warnings.push(`extraction call failed: ${t}`),n}n.extractedCount=w.length;for(let e of w){if(e.importance<l){n.rejectedCount+=1;continue}try{let t=await m(r,i,e);t===`stored`?n.storedCount+=1:t===`merged`?n.mergedCount+=1:n.rejectedCount+=1}catch(e){let t=e instanceof Error?e.message:String(e);n.warnings.push(`store failed: ${t}`),n.rejectedCount+=1}}return n}async function b(e,t,n){let r=x(await e.messages.create({model:t,max_tokens:4096,system:`${d}\n\nReturn ONLY a JSON object of shape {"memories": [...]} with no prose.`,messages:[{role:`user`,content:n}]}));if(!r)return[];let i=S(r);if(!i)return[];let a=u.safeParse(i);return a.success?a.data.memories:[]}function x(e){let t=e?.content;return Array.isArray(t)?t.filter(e=>e?.type===`text`&&typeof e.text==`string`).map(e=>e.text??``).join(``):``}function S(e){let t=e.trim();try{return JSON.parse(t)}catch{}let n=t.indexOf(`{`),r=t.lastIndexOf(`}`);if(n===-1||r===-1||r<n)return null;try{return JSON.parse(t.slice(n,r+1))}catch{return null}}export{y as extractFromTranscript};