diff --git a/plugin/scripts/context-hook.js b/plugin/scripts/context-hook.js index ee447253..50263152 100755 --- a/plugin/scripts/context-hook.js +++ b/plugin/scripts/context-hook.js @@ -1,2 +1,2 @@ #!/usr/bin/env node -import L from"path";import{stdin as u}from"process";import{execSync as l}from"child_process";import N from"path";import{homedir as R}from"os";import{join as r,dirname as f,basename as x}from"path";import{homedir as T}from"os";import{fileURLToPath as g}from"url";function A(){return typeof __dirname<"u"?__dirname:f(g(import.meta.url))}var v=A(),n=process.env.CLAUDE_MEM_DATA_DIR||r(T(),".claude-mem"),E=process.env.CLAUDE_CONFIG_DIR||r(T(),".claude"),k=r(n,"archives"),b=r(n,"logs"),W=r(n,"trash"),F=r(n,"backups"),H=r(n,"settings.json"),X=r(n,"claude-mem.db"),B=r(n,"vector-db"),V=r(E,"settings.json"),j=r(E,"commands"),G=r(E,"CLAUDE.md");import{readFileSync as d,existsSync as M}from"fs";var C=["bugfix","feature","refactor","discovery","decision","change"],D=["how-it-works","why-it-exists","what-changed","problem-solution","gotcha","pattern","trade-off"];var p=C.join(","),S=D.join(",");var _=class{static DEFAULTS={CLAUDE_MEM_MODEL:"claude-haiku-4-5",CLAUDE_MEM_CONTEXT_OBSERVATIONS:"50",CLAUDE_MEM_WORKER_PORT:"37777",CLAUDE_MEM_CONTEXT_SHOW_READ_TOKENS:"true",CLAUDE_MEM_CONTEXT_SHOW_WORK_TOKENS:"true",CLAUDE_MEM_CONTEXT_SHOW_SAVINGS_AMOUNT:"true",CLAUDE_MEM_CONTEXT_SHOW_SAVINGS_PERCENT:"true",CLAUDE_MEM_CONTEXT_OBSERVATION_TYPES:p,CLAUDE_MEM_CONTEXT_OBSERVATION_CONCEPTS:S,CLAUDE_MEM_CONTEXT_FULL_COUNT:"5",CLAUDE_MEM_CONTEXT_FULL_FIELD:"narrative",CLAUDE_MEM_CONTEXT_SESSION_COUNT:"10",CLAUDE_MEM_CONTEXT_SHOW_LAST_SUMMARY:"true",CLAUDE_MEM_CONTEXT_SHOW_LAST_MESSAGE:"false"};static getAllDefaults(){return{...this.DEFAULTS}}static get(t){return process.env[t]||this.DEFAULTS[t]}static getInt(t){let o=this.get(t);return parseInt(o,10)}static getBool(t){return this.get(t)==="true"}static loadFromFile(t){if(!M(t))return this.getAllDefaults();let o=d(t,"utf-8"),i=JSON.parse(o).env||{},c={...this.DEFAULTS};for(let a of Object.keys(this.DEFAULTS))i[a]!==void 0&&(c[a]=i[a]);return c}};function m(){let e=N.join(R(),".claude-mem","settings.json"),t=_.loadFromFile(e);return parseInt(t.CLAUDE_MEM_WORKER_PORT,10)}async function U(e,t=1e4){let o=Date.now(),s=100;for(;Date.now()-o /dev/null 2>&1`,{timeout:1e3}),!0}catch{await new Promise(i=>setTimeout(i,s))}return!1}async function O(e){let t=e?.cwd??process.cwd(),o=t?L.basename(t):"unknown-project",s=m();if(!await U(s))throw new Error(`Worker service not available on port ${s} after 10s. Try: npm run worker:restart`);let c=`http://localhost:${s}/api/context/inject?project=${encodeURIComponent(o)}`;return l(`curl -s "${c}"`,{encoding:"utf-8",timeout:5e3}).trim()}var I=process.argv.includes("--colors");if(u.isTTY||I)O(void 0).then(e=>{console.log(e),process.exit(0)});else{let e="";u.on("data",t=>e+=t),u.on("end",async()=>{let t=e.trim()?JSON.parse(e):void 0,o=await O(t);console.log(JSON.stringify({hookSpecificOutput:{hookEventName:"SessionStart",additionalContext:o}})),process.exit(0)})} +import L from"path";import{stdin as u}from"process";import{execSync as l}from"child_process";import N from"path";import{homedir as R}from"os";import{join as r,dirname as f,basename as h}from"path";import{homedir as T}from"os";import{fileURLToPath as g}from"url";function A(){return typeof __dirname<"u"?__dirname:f(g(import.meta.url))}var v=A(),n=process.env.CLAUDE_MEM_DATA_DIR||r(T(),".claude-mem"),E=process.env.CLAUDE_CONFIG_DIR||r(T(),".claude"),k=r(n,"archives"),b=r(n,"logs"),W=r(n,"trash"),F=r(n,"backups"),H=r(n,"settings.json"),X=r(n,"claude-mem.db"),B=r(n,"vector-db"),V=r(E,"settings.json"),j=r(E,"commands"),G=r(E,"CLAUDE.md");import{readFileSync as d,existsSync as M}from"fs";var C=["bugfix","feature","refactor","discovery","decision","change"],D=["how-it-works","why-it-exists","what-changed","problem-solution","gotcha","pattern","trade-off"];var p=C.join(","),S=D.join(",");var _=class{static DEFAULTS={CLAUDE_MEM_MODEL:"claude-haiku-4-5",CLAUDE_MEM_CONTEXT_OBSERVATIONS:"50",CLAUDE_MEM_WORKER_PORT:"37777",CLAUDE_MEM_CONTEXT_SHOW_READ_TOKENS:"true",CLAUDE_MEM_CONTEXT_SHOW_WORK_TOKENS:"true",CLAUDE_MEM_CONTEXT_SHOW_SAVINGS_AMOUNT:"true",CLAUDE_MEM_CONTEXT_SHOW_SAVINGS_PERCENT:"true",CLAUDE_MEM_CONTEXT_OBSERVATION_TYPES:p,CLAUDE_MEM_CONTEXT_OBSERVATION_CONCEPTS:S,CLAUDE_MEM_CONTEXT_FULL_COUNT:"5",CLAUDE_MEM_CONTEXT_FULL_FIELD:"narrative",CLAUDE_MEM_CONTEXT_SESSION_COUNT:"10",CLAUDE_MEM_CONTEXT_SHOW_LAST_SUMMARY:"true",CLAUDE_MEM_CONTEXT_SHOW_LAST_MESSAGE:"false"};static getAllDefaults(){return{...this.DEFAULTS}}static get(t){return process.env[t]||this.DEFAULTS[t]}static getInt(t){let o=this.get(t);return parseInt(o,10)}static getBool(t){return this.get(t)==="true"}static loadFromFile(t){if(!M(t))return this.getAllDefaults();let o=d(t,"utf-8"),i=JSON.parse(o).env||{},c={...this.DEFAULTS};for(let a of Object.keys(this.DEFAULTS))i[a]!==void 0&&(c[a]=i[a]);return c}};function m(){let e=N.join(R(),".claude-mem","settings.json"),t=_.loadFromFile(e);return parseInt(t.CLAUDE_MEM_WORKER_PORT,10)}async function U(e,t=1e4){let o=Date.now(),s=100;for(;Date.now()-o /dev/null 2>&1`,{timeout:1e3}),!0}catch{await new Promise(i=>setTimeout(i,s))}return!1}async function O(e){let t=e?.cwd??process.cwd(),o=t?L.basename(t):"unknown-project",s=m();if(!await U(s))throw new Error(`Worker service not available on port ${s} after 10s. Try: npm run worker:restart`);let c=`http://127.0.0.1:${s}/api/context/inject?project=${encodeURIComponent(o)}`;return l(`curl -s "${c}"`,{encoding:"utf-8",timeout:5e3}).trim()}var I=process.argv.includes("--colors");if(u.isTTY||I)O(void 0).then(e=>{console.log(e),process.exit(0)});else{let e="";u.on("data",t=>e+=t),u.on("end",async()=>{let t=e.trim()?JSON.parse(e):void 0,o=await O(t);console.log(JSON.stringify({hookSpecificOutput:{hookEventName:"SessionStart",additionalContext:o}})),process.exit(0)})} diff --git a/plugin/scripts/worker-service.cjs b/plugin/scripts/worker-service.cjs index 2db8da3a..f723ae43 100755 --- a/plugin/scripts/worker-service.cjs +++ b/plugin/scripts/worker-service.cjs @@ -623,7 +623,7 @@ No previous sessions found for this project yet.`;let v=p.slice(0,r.sessionCount FROM user_prompts WHERE claude_session_id = ? ORDER BY prompt_number ASC - `).all(e)}close(){this.db.close()}};Jc();Tt();var iE=gt(require("path"),1),oE=gt(require("os"),1),el=class{client=null;connected=!1;project;collectionName;VECTOR_DB_DIR;BATCH_SIZE=100;constructor(e){this.project=e,this.collectionName=`cm__${e}`,this.VECTOR_DB_DIR=iE.default.join(oE.default.homedir(),".claude-mem","vector-db")}async ensureConnection(){if(!(this.connected&&this.client)){W.info("CHROMA_SYNC","Connecting to Chroma MCP server...",{project:this.project});try{let e=new kn({command:"uvx",args:["chroma-mcp","--client-type","persistent","--data-dir",this.VECTOR_DB_DIR],stderr:"ignore"});this.client=new Rn({name:"claude-mem-chroma-sync",version:"1.0.0"},{capabilities:{}}),await this.client.connect(e),this.connected=!0,W.info("CHROMA_SYNC","Connected to Chroma MCP server",{project:this.project})}catch(e){throw W.error("CHROMA_SYNC","Failed to connect to Chroma MCP server",{project:this.project},e),new Error(`Chroma connection failed: ${e instanceof Error?e.message:String(e)}`)}}}async ensureCollection(){if(await this.ensureConnection(),!this.client)throw new Error("Chroma client not initialized");try{await this.client.callTool({name:"chroma_get_collection_info",arguments:{collection_name:this.collectionName}}),W.debug("CHROMA_SYNC","Collection exists",{collection:this.collectionName})}catch{W.info("CHROMA_SYNC","Creating collection",{collection:this.collectionName});try{await this.client.callTool({name:"chroma_create_collection",arguments:{collection_name:this.collectionName,embedding_function_name:"default"}}),W.info("CHROMA_SYNC","Collection created",{collection:this.collectionName})}catch(r){throw W.error("CHROMA_SYNC","Failed to create collection",{collection:this.collectionName},r),new Error(`Collection creation failed: ${r instanceof Error?r.message:String(r)}`)}}}formatObservationDocs(e){let r=[],t=e.facts?JSON.parse(e.facts):[],s=e.concepts?JSON.parse(e.concepts):[],i=e.files_read?JSON.parse(e.files_read):[],n=e.files_modified?JSON.parse(e.files_modified):[],o={sqlite_id:e.id,doc_type:"observation",sdk_session_id:e.sdk_session_id,project:e.project,created_at_epoch:e.created_at_epoch,type:e.type||"discovery",title:e.title||"Untitled"};return e.subtitle&&(o.subtitle=e.subtitle),s.length>0&&(o.concepts=s.join(",")),i.length>0&&(o.files_read=i.join(",")),n.length>0&&(o.files_modified=n.join(",")),e.narrative&&r.push({id:`obs_${e.id}_narrative`,document:e.narrative,metadata:{...o,field_type:"narrative"}}),e.text&&r.push({id:`obs_${e.id}_text`,document:e.text,metadata:{...o,field_type:"text"}}),t.forEach((l,c)=>{r.push({id:`obs_${e.id}_fact_${c}`,document:l,metadata:{...o,field_type:"fact",fact_index:c}})}),r}formatSummaryDocs(e){let r=[],t={sqlite_id:e.id,doc_type:"session_summary",sdk_session_id:e.sdk_session_id,project:e.project,created_at_epoch:e.created_at_epoch,prompt_number:e.prompt_number||0};return e.request&&r.push({id:`summary_${e.id}_request`,document:e.request,metadata:{...t,field_type:"request"}}),e.investigated&&r.push({id:`summary_${e.id}_investigated`,document:e.investigated,metadata:{...t,field_type:"investigated"}}),e.learned&&r.push({id:`summary_${e.id}_learned`,document:e.learned,metadata:{...t,field_type:"learned"}}),e.completed&&r.push({id:`summary_${e.id}_completed`,document:e.completed,metadata:{...t,field_type:"completed"}}),e.next_steps&&r.push({id:`summary_${e.id}_next_steps`,document:e.next_steps,metadata:{...t,field_type:"next_steps"}}),e.notes&&r.push({id:`summary_${e.id}_notes`,document:e.notes,metadata:{...t,field_type:"notes"}}),r}async addDocuments(e){if(e.length!==0){if(await this.ensureCollection(),!this.client)throw new Error("Chroma client not initialized");try{await this.client.callTool({name:"chroma_add_documents",arguments:{collection_name:this.collectionName,documents:e.map(r=>r.document),ids:e.map(r=>r.id),metadatas:e.map(r=>r.metadata)}}),W.debug("CHROMA_SYNC","Documents added",{collection:this.collectionName,count:e.length})}catch(r){throw W.error("CHROMA_SYNC","Failed to add documents",{collection:this.collectionName,count:e.length},r),new Error(`Document add failed: ${r instanceof Error?r.message:String(r)}`)}}}async syncObservation(e,r,t,s,i,n,o=0){let l={id:e,sdk_session_id:r,project:t,text:null,type:s.type,title:s.title,subtitle:s.subtitle,facts:JSON.stringify(s.facts),narrative:s.narrative,concepts:JSON.stringify(s.concepts),files_read:JSON.stringify(s.files_read),files_modified:JSON.stringify(s.files_modified),prompt_number:i,discovery_tokens:o,created_at:new Date(n*1e3).toISOString(),created_at_epoch:n},c=this.formatObservationDocs(l);W.info("CHROMA_SYNC","Syncing observation",{observationId:e,documentCount:c.length,project:t}),await this.addDocuments(c)}async syncSummary(e,r,t,s,i,n,o=0){let l={id:e,sdk_session_id:r,project:t,request:s.request,investigated:s.investigated,learned:s.learned,completed:s.completed,next_steps:s.next_steps,notes:s.notes,prompt_number:i,discovery_tokens:o,created_at:new Date(n*1e3).toISOString(),created_at_epoch:n},c=this.formatSummaryDocs(l);W.info("CHROMA_SYNC","Syncing summary",{summaryId:e,documentCount:c.length,project:t}),await this.addDocuments(c)}formatUserPromptDoc(e){return{id:`prompt_${e.id}`,document:e.prompt_text,metadata:{sqlite_id:e.id,doc_type:"user_prompt",sdk_session_id:e.sdk_session_id,project:e.project,created_at_epoch:e.created_at_epoch,prompt_number:e.prompt_number}}}async syncUserPrompt(e,r,t,s,i,n){let o={id:e,claude_session_id:"",prompt_number:i,prompt_text:s,created_at:new Date(n*1e3).toISOString(),created_at_epoch:n,sdk_session_id:r,project:t},l=this.formatUserPromptDoc(o);W.info("CHROMA_SYNC","Syncing user prompt",{promptId:e,project:t}),await this.addDocuments([l])}async getExistingChromaIds(){if(await this.ensureConnection(),!this.client)throw new Error("Chroma client not initialized");let e=new Set,r=new Set,t=new Set,s=0,i=1e3;for(W.info("CHROMA_SYNC","Fetching existing Chroma document IDs...",{project:this.project});;)try{let o=(await this.client.callTool({name:"chroma_get_documents",arguments:{collection_name:this.collectionName,limit:i,offset:s,where:{project:this.project},include:["metadatas"]}})).content[0];if(o.type!=="text")throw new Error("Unexpected response type from chroma_get_documents");let c=JSON.parse(o.text).metadatas||[];if(c.length===0)break;for(let u of c)u.sqlite_id&&(u.doc_type==="observation"?e.add(u.sqlite_id):u.doc_type==="session_summary"?r.add(u.sqlite_id):u.doc_type==="user_prompt"&&t.add(u.sqlite_id));s+=i,W.debug("CHROMA_SYNC","Fetched batch of existing IDs",{project:this.project,offset:s,batchSize:c.length})}catch(n){throw W.error("CHROMA_SYNC","Failed to fetch existing IDs",{project:this.project},n),n}return W.info("CHROMA_SYNC","Existing IDs fetched",{project:this.project,observations:e.size,summaries:r.size,prompts:t.size}),{observations:e,summaries:r,prompts:t}}async ensureBackfilled(){W.info("CHROMA_SYNC","Starting smart backfill",{project:this.project}),await this.ensureCollection();let e=await this.getExistingChromaIds(),r=new Da;try{let t=Array.from(e.observations),s=t.length>0?`AND id NOT IN (${t.join(",")})`:"",i=r.db.prepare(` + `).all(e)}close(){this.db.close()}};Jc();Tt();var iE=gt(require("path"),1),oE=gt(require("os"),1),el=class{client=null;connected=!1;project;collectionName;VECTOR_DB_DIR;BATCH_SIZE=100;constructor(e){this.project=e,this.collectionName=`cm__${e}`,this.VECTOR_DB_DIR=iE.default.join(oE.default.homedir(),".claude-mem","vector-db")}async ensureConnection(){if(!(this.connected&&this.client)){W.info("CHROMA_SYNC","Connecting to Chroma MCP server...",{project:this.project});try{let e=process.env.CLAUDE_MEM_PYTHON_VERSION||"3.13",r=new kn({command:"uvx",args:["--python",e,"chroma-mcp","--client-type","persistent","--data-dir",this.VECTOR_DB_DIR],stderr:"ignore"});this.client=new Rn({name:"claude-mem-chroma-sync",version:"1.0.0"},{capabilities:{}}),await this.client.connect(r),this.connected=!0,W.info("CHROMA_SYNC","Connected to Chroma MCP server",{project:this.project})}catch(e){throw W.error("CHROMA_SYNC","Failed to connect to Chroma MCP server",{project:this.project},e),new Error(`Chroma connection failed: ${e instanceof Error?e.message:String(e)}`)}}}async ensureCollection(){if(await this.ensureConnection(),!this.client)throw new Error("Chroma client not initialized");try{await this.client.callTool({name:"chroma_get_collection_info",arguments:{collection_name:this.collectionName}}),W.debug("CHROMA_SYNC","Collection exists",{collection:this.collectionName})}catch{W.info("CHROMA_SYNC","Creating collection",{collection:this.collectionName});try{await this.client.callTool({name:"chroma_create_collection",arguments:{collection_name:this.collectionName,embedding_function_name:"default"}}),W.info("CHROMA_SYNC","Collection created",{collection:this.collectionName})}catch(r){throw W.error("CHROMA_SYNC","Failed to create collection",{collection:this.collectionName},r),new Error(`Collection creation failed: ${r instanceof Error?r.message:String(r)}`)}}}formatObservationDocs(e){let r=[],t=e.facts?JSON.parse(e.facts):[],s=e.concepts?JSON.parse(e.concepts):[],i=e.files_read?JSON.parse(e.files_read):[],n=e.files_modified?JSON.parse(e.files_modified):[],o={sqlite_id:e.id,doc_type:"observation",sdk_session_id:e.sdk_session_id,project:e.project,created_at_epoch:e.created_at_epoch,type:e.type||"discovery",title:e.title||"Untitled"};return e.subtitle&&(o.subtitle=e.subtitle),s.length>0&&(o.concepts=s.join(",")),i.length>0&&(o.files_read=i.join(",")),n.length>0&&(o.files_modified=n.join(",")),e.narrative&&r.push({id:`obs_${e.id}_narrative`,document:e.narrative,metadata:{...o,field_type:"narrative"}}),e.text&&r.push({id:`obs_${e.id}_text`,document:e.text,metadata:{...o,field_type:"text"}}),t.forEach((l,c)=>{r.push({id:`obs_${e.id}_fact_${c}`,document:l,metadata:{...o,field_type:"fact",fact_index:c}})}),r}formatSummaryDocs(e){let r=[],t={sqlite_id:e.id,doc_type:"session_summary",sdk_session_id:e.sdk_session_id,project:e.project,created_at_epoch:e.created_at_epoch,prompt_number:e.prompt_number||0};return e.request&&r.push({id:`summary_${e.id}_request`,document:e.request,metadata:{...t,field_type:"request"}}),e.investigated&&r.push({id:`summary_${e.id}_investigated`,document:e.investigated,metadata:{...t,field_type:"investigated"}}),e.learned&&r.push({id:`summary_${e.id}_learned`,document:e.learned,metadata:{...t,field_type:"learned"}}),e.completed&&r.push({id:`summary_${e.id}_completed`,document:e.completed,metadata:{...t,field_type:"completed"}}),e.next_steps&&r.push({id:`summary_${e.id}_next_steps`,document:e.next_steps,metadata:{...t,field_type:"next_steps"}}),e.notes&&r.push({id:`summary_${e.id}_notes`,document:e.notes,metadata:{...t,field_type:"notes"}}),r}async addDocuments(e){if(e.length!==0){if(await this.ensureCollection(),!this.client)throw new Error("Chroma client not initialized");try{await this.client.callTool({name:"chroma_add_documents",arguments:{collection_name:this.collectionName,documents:e.map(r=>r.document),ids:e.map(r=>r.id),metadatas:e.map(r=>r.metadata)}}),W.debug("CHROMA_SYNC","Documents added",{collection:this.collectionName,count:e.length})}catch(r){throw W.error("CHROMA_SYNC","Failed to add documents",{collection:this.collectionName,count:e.length},r),new Error(`Document add failed: ${r instanceof Error?r.message:String(r)}`)}}}async syncObservation(e,r,t,s,i,n,o=0){let l={id:e,sdk_session_id:r,project:t,text:null,type:s.type,title:s.title,subtitle:s.subtitle,facts:JSON.stringify(s.facts),narrative:s.narrative,concepts:JSON.stringify(s.concepts),files_read:JSON.stringify(s.files_read),files_modified:JSON.stringify(s.files_modified),prompt_number:i,discovery_tokens:o,created_at:new Date(n*1e3).toISOString(),created_at_epoch:n},c=this.formatObservationDocs(l);W.info("CHROMA_SYNC","Syncing observation",{observationId:e,documentCount:c.length,project:t}),await this.addDocuments(c)}async syncSummary(e,r,t,s,i,n,o=0){let l={id:e,sdk_session_id:r,project:t,request:s.request,investigated:s.investigated,learned:s.learned,completed:s.completed,next_steps:s.next_steps,notes:s.notes,prompt_number:i,discovery_tokens:o,created_at:new Date(n*1e3).toISOString(),created_at_epoch:n},c=this.formatSummaryDocs(l);W.info("CHROMA_SYNC","Syncing summary",{summaryId:e,documentCount:c.length,project:t}),await this.addDocuments(c)}formatUserPromptDoc(e){return{id:`prompt_${e.id}`,document:e.prompt_text,metadata:{sqlite_id:e.id,doc_type:"user_prompt",sdk_session_id:e.sdk_session_id,project:e.project,created_at_epoch:e.created_at_epoch,prompt_number:e.prompt_number}}}async syncUserPrompt(e,r,t,s,i,n){let o={id:e,claude_session_id:"",prompt_number:i,prompt_text:s,created_at:new Date(n*1e3).toISOString(),created_at_epoch:n,sdk_session_id:r,project:t},l=this.formatUserPromptDoc(o);W.info("CHROMA_SYNC","Syncing user prompt",{promptId:e,project:t}),await this.addDocuments([l])}async getExistingChromaIds(){if(await this.ensureConnection(),!this.client)throw new Error("Chroma client not initialized");let e=new Set,r=new Set,t=new Set,s=0,i=1e3;for(W.info("CHROMA_SYNC","Fetching existing Chroma document IDs...",{project:this.project});;)try{let o=(await this.client.callTool({name:"chroma_get_documents",arguments:{collection_name:this.collectionName,limit:i,offset:s,where:{project:this.project},include:["metadatas"]}})).content[0];if(o.type!=="text")throw new Error("Unexpected response type from chroma_get_documents");let c=JSON.parse(o.text).metadatas||[];if(c.length===0)break;for(let u of c)u.sqlite_id&&(u.doc_type==="observation"?e.add(u.sqlite_id):u.doc_type==="session_summary"?r.add(u.sqlite_id):u.doc_type==="user_prompt"&&t.add(u.sqlite_id));s+=i,W.debug("CHROMA_SYNC","Fetched batch of existing IDs",{project:this.project,offset:s,batchSize:c.length})}catch(n){throw W.error("CHROMA_SYNC","Failed to fetch existing IDs",{project:this.project},n),n}return W.info("CHROMA_SYNC","Existing IDs fetched",{project:this.project,observations:e.size,summaries:r.size,prompts:t.size}),{observations:e,summaries:r,prompts:t}}async ensureBackfilled(){W.info("CHROMA_SYNC","Starting smart backfill",{project:this.project}),await this.ensureCollection();let e=await this.getExistingChromaIds(),r=new Da;try{let t=Array.from(e.observations),s=t.length>0?`AND id NOT IN (${t.join(",")})`:"",i=r.db.prepare(` SELECT * FROM observations WHERE project = ? ${s} ORDER BY id ASC