opencode-metis 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/plugin.cjs +16 -15
- package/dist/worker.cjs +3 -3
- package/package.json +1 -1
package/dist/worker.cjs
CHANGED
|
@@ -51,9 +51,9 @@ ${r}`}var oE="claude-haiku-4-5-20251001",iE=15e3,aE="https://api.anthropic.com/v
|
|
|
51
51
|
(memory_session_id, project, text, type, title,
|
|
52
52
|
facts, narrative, concepts, files_read, files_modified,
|
|
53
53
|
prompt_number, tags, created_at, created_at_epoch)
|
|
54
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,[e.memorySessionId,e.project,r,c,n,JSON.stringify(o),s,JSON.stringify(i),JSON.stringify(e.filesRead??[]),JSON.stringify(e.filesModified??[]),e.promptNumber??null,JSON.stringify(a),l,d]);let f=this.db.query("SELECT last_insert_rowid() AS id").get();if(!f)throw new Error("ObservationWriter: failed to retrieve inserted row ID");let m=e.rawToolOutput!==void 0&&!e.skipAiCompression,p={sessionDbId:e.sessionDbId,contentSessionId:e.contentSessionId,messageType:"observation"};m&&(p.observationId=f.id,e.rawToolName!==void 0&&(p.rawToolName=e.rawToolName),e.rawToolInput!==void 0&&(p.rawToolInput=e.rawToolInput),e.rawToolOutput!==void 0&&(p.rawToolOutput=e.rawToolOutput));let h=this.pendingQueue.enqueue(p),g=this.getById(f.id);if(!g)throw new Error(`ObservationWriter: inserted observation ${f.id} not found`);return this.pendingQueue.markProcessed(h),this.vectorSync.syncObservation(g).catch(()=>{}),g}delete(e){this.db.run("DELETE FROM observations WHERE id = ?",[e])}bulkDelete(e){if(e.length===0)return 0;let r=e.map(()=>"?").join(", "),s=this.db.query(`SELECT COUNT(*) AS count FROM observations WHERE id IN (${r})`).get(...e)?.count??0;return s>0&&this.db.run(`DELETE FROM observations WHERE id IN (${r})`,e),s}getById(e){let r=this.db.query("SELECT * FROM observations WHERE id = ?").get(e);return r!==null?Pm(r):null}updateWithCompressed(e,r){this.db.run(`UPDATE observations
|
|
54
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,[e.memorySessionId,e.project,r,c,n,JSON.stringify(o),s,JSON.stringify(i),JSON.stringify(e.filesRead??[]),JSON.stringify(e.filesModified??[]),e.promptNumber??null,JSON.stringify(a),l,d]);let f=this.db.query("SELECT last_insert_rowid() AS id").get();if(!f)throw new Error("ObservationWriter: failed to retrieve inserted row ID");let m=e.rawToolOutput!==void 0&&!e.skipAiCompression,p={sessionDbId:e.sessionDbId,contentSessionId:e.contentSessionId,messageType:"observation"};m&&(p.observationId=f.id,e.rawToolName!==void 0&&(p.rawToolName=e.rawToolName),e.rawToolInput!==void 0&&(p.rawToolInput=e.rawToolInput),e.rawToolOutput!==void 0&&(p.rawToolOutput=e.rawToolOutput));let h=this.pendingQueue.enqueue(p),g=this.getById(f.id);if(!g)throw new Error(`ObservationWriter: inserted observation ${f.id} not found`);return this.pendingQueue.markProcessed(h),m||this.vectorSync.syncObservation(g).catch(()=>{}),g}delete(e){this.db.run("DELETE FROM observations WHERE id = ?",[e])}bulkDelete(e){if(e.length===0)return 0;let r=e.map(()=>"?").join(", "),s=this.db.query(`SELECT COUNT(*) AS count FROM observations WHERE id IN (${r})`).get(...e)?.count??0;return s>0&&this.db.run(`DELETE FROM observations WHERE id IN (${r})`,e),s}getById(e){let r=this.db.query("SELECT * FROM observations WHERE id = ?").get(e);return r!==null?Pm(r):null}updateWithCompressed(e,r){this.db.run(`UPDATE observations
|
|
55
55
|
SET title=?, narrative=?, facts=?, concepts=?, type=?, ai_compressed=1
|
|
56
|
-
WHERE id=?`,[r.title,r.narrative,JSON.stringify(r.facts),JSON.stringify(r.concepts),r.type,e]),r.filesTouched.length>0&&this.db.run("UPDATE observations SET files_modified=? WHERE id=?",[JSON.stringify(r.filesTouched),e])}getBySession(e,r){return(r!==void 0?this.db.query(`SELECT * FROM observations
|
|
56
|
+
WHERE id=?`,[r.title,r.narrative,JSON.stringify(r.facts),JSON.stringify(r.concepts),r.type,e]),r.filesTouched.length>0&&this.db.run("UPDATE observations SET files_modified=? WHERE id=?",[JSON.stringify(r.filesTouched),e]);let n=this.getById(e);n!==null&&this.vectorSync.syncObservation(n).catch(()=>{})}getBySession(e,r){return(r!==void 0?this.db.query(`SELECT * FROM observations
|
|
57
57
|
WHERE memory_session_id = ?
|
|
58
58
|
ORDER BY created_at_epoch DESC, id DESC
|
|
59
59
|
LIMIT ?`).all(e,r):this.db.query(`SELECT * FROM observations
|
|
@@ -84,7 +84,7 @@ ${r}`}var oE="claude-haiku-4-5-20251001",iE=15e3,aE="https://api.anthropic.com/v
|
|
|
84
84
|
SET status='pending', retry_count = retry_count + 1
|
|
85
85
|
WHERE id=?`,[e])}markProcessed(e){this.db.run("DELETE FROM pending_messages WHERE id=?",[e])}markFailed(e){let r=Math.floor(Date.now()/1e3);this.db.run(`UPDATE pending_messages
|
|
86
86
|
SET status='failed', retry_count = retry_count + 1, failed_at_epoch=?
|
|
87
|
-
WHERE id=?`,[r,e])}recover(){return this.db.run("UPDATE pending_messages SET status='pending' WHERE status='processing'").changes}purgeFailed(e=6048e5){let r=Math.floor((Date.now()-e)/1e3);return this.db.run("DELETE FROM pending_messages WHERE status='failed' AND failed_at_epoch <= ?",[r]).changes}getPendingCount(){return this.db.query("SELECT COUNT(*) AS count FROM pending_messages WHERE status='pending'").get()?.count??0}getFailedItems(){return this.db.query("SELECT * FROM pending_messages WHERE status='failed' ORDER BY created_at_epoch ASC, id ASC").all().map(su)}};function Im(t){return t.query("SELECT changes() as changes").get()?.changes??0}function xE(t){let e=t.query("SELECT page_count, page_size FROM pragma_page_count(), pragma_page_size()").get();return e===null?0:e.page_count*e.page_size}var Di=class{constructor(e,r){this.db=e;this.vectorSync=r}purgeByAge(e){let r=Math.floor(Date.now()/1e3)-e*86400;this.db.run("DELETE FROM observations WHERE created_at_epoch < ?",[r]);let
|
|
87
|
+
WHERE id=?`,[r,e])}recover(){return this.db.run("UPDATE pending_messages SET status='pending' WHERE status='processing'").changes}purgeFailed(e=6048e5){let r=Math.floor((Date.now()-e)/1e3);return this.db.run("DELETE FROM pending_messages WHERE status='failed' AND failed_at_epoch <= ?",[r]).changes}getPendingCount(){return this.db.query("SELECT COUNT(*) AS count FROM pending_messages WHERE status='pending'").get()?.count??0}getFailedItems(){return this.db.query("SELECT * FROM pending_messages WHERE status='failed' ORDER BY created_at_epoch ASC, id ASC").all().map(su)}};function Im(t){return t.query("SELECT changes() as changes").get()?.changes??0}function xE(t){let e=t.query("SELECT page_count, page_size FROM pragma_page_count(), pragma_page_size()").get();return e===null?0:e.page_count*e.page_size}var Di=class{constructor(e,r){this.db=e;this.vectorSync=r}purgeByAge(e){let r=Math.floor(Date.now()/1e3)-e*86400,n=this.db.query("SELECT DISTINCT project FROM observations WHERE created_at_epoch < ?").all(r).map(o=>o.project);this.db.run("DELETE FROM observations WHERE created_at_epoch < ?",[r]);let s=Im(this.db);if(s>0)for(let o of n)this.vectorSync?.vacuum(o).catch(()=>{});return{deleted:s}}purgeByProject(e){this.db.run("DELETE FROM observations WHERE project = ?",[e]);let r=Im(this.db);return r>0&&this.vectorSync?.vacuum(e).catch(()=>{}),{deleted:r}}vacuum(){this.db.run("VACUUM")}getStats(){let r=this.db.query("SELECT COUNT(*) as count FROM observations").get()?.count??0,s=this.db.query("SELECT created_at FROM observations ORDER BY created_at_epoch ASC LIMIT 1").get()?.created_at??null,o=xE(this.db);return{observationCount:r,oldestObservation:s,dbSizeBytes:o}}};var gr=class{async syncObservation(e){}async syncSummary(e){}async query(e,r,n,s,o){return[]}async vacuum(e){}async backfill(e,r){}};var ou=20,Nm=5,Om=90,zm=400;function Dn(t){if(t===null||t==="")return[];try{let e=JSON.parse(t);return Array.isArray(e)?e:[]}catch{return[]}}function TE(t){return{id:t.id,memorySessionId:t.memory_session_id,project:t.project,text:t.text,type:t.type,title:t.title,subtitle:t.subtitle,facts:Dn(t.facts),narrative:t.narrative,concepts:Dn(t.concepts),filesRead:Dn(t.files_read),filesModified:Dn(t.files_modified),promptNumber:t.prompt_number,discoveryTokens:t.discovery_tokens,tags:Dn(t.tags),createdAt:t.created_at,createdAtEpoch:t.created_at_epoch}}function Cm(t){let e=t.type,r=t.title??"(untitled)",n=t.narrative??"",s=Dn(t.files_modified),o=n.length>200?`${n.slice(0,200)}...`:n,i=s.length>0?` Files: ${s.slice(0,3).join(", ")}`:"",a=`${e}: ${r}. ${o}.${i}`;return a.length>zm?a.slice(0,zm):a}function qi(t,e=null){return{id:t.id,title:t.title??"(untitled)",type:t.type,project:t.project,summary:Cm(t),createdAt:t.created_at,relevanceScore:e}}function kE(t){return t instanceof gr}var Li=class{constructor(e,r){this.db=e;this.vectorSync=r}async search(e){let r=e.query;if(r===void 0||r===""||r==="*")return this.searchFilterOnly(e);if(!kE(this.vectorSync)){let s=await this.searchSemantic_internal(r,e);if(s.results.length>0)return s}return this.searchFallback(r,e)}async searchSemantic(e){let r=await this.vectorSync.query([],"",void 0,Om,e);if(r.length===0)return[];let n=r.map(i=>i.observationId),s=new Map(r.map(i=>[i.observationId,i.score]));return this.fetchRowsByIds(n).map(i=>qi(i,s.get(i.id)??null))}timeline(e){let{anchor:r,depthBefore:n=Nm,depthAfter:s=Nm}=e,o=this.resolveAnchorId(r);if(o===null)return{entries:[]};let i=this.db.query("SELECT id, created_at_epoch FROM observations WHERE id = ?").get(o);if(i===null)return{entries:[]};let a=this.db.query("SELECT * FROM observations WHERE created_at_epoch < ? ORDER BY created_at_epoch DESC LIMIT ?").all(i.created_at_epoch,n),c=this.db.query("SELECT * FROM observations WHERE created_at_epoch > ? ORDER BY created_at_epoch ASC LIMIT ?").all(i.created_at_epoch,s),u=this.db.query("SELECT * FROM observations WHERE id = ?").get(o);return u===null?{entries:[]}:{entries:[...a.reverse(),u,...c].map(f=>({id:f.id,type:f.type,title:f.title,summary:Cm(f),createdAt:f.created_at,isAnchor:f.id===o}))}}batchFetch(e){return e.length===0?[]:this.fetchRowsByIds(e).map(TE)}searchFilterOnly(e){let r=e.limit??ou,n=[],s=[];e.type!==void 0&&(n.push("type = ?"),s.push(e.type)),e.project!==void 0&&(n.push("project = ?"),s.push(e.project)),e.dateStart!==void 0&&(n.push("created_at >= ?"),s.push(e.dateStart)),e.dateEnd!==void 0&&(n.push("created_at <= ?"),s.push(e.dateEnd));let o=n.length>0?`WHERE ${n.join(" AND ")}`:"",i=`SELECT * FROM observations ${o} ORDER BY created_at_epoch DESC LIMIT ?`;s.push(r);let a=this.db.query(i).all(...s),c=this.db.query(`SELECT COUNT(*) as count FROM observations ${o}`).get(...s.slice(0,-1));return{results:a.map(u=>qi(u)),total:c?.count??0,mode:"FILTER_ONLY"}}async searchSemantic_internal(e,r){let n=r.limit??ou,s=await this.vectorSync.query([],r.project??"",n,Om,e);if(s.length===0)return{results:[],total:0,mode:"SEMANTIC"};let o=s.map(u=>u.observationId),i=new Map(s.map(u=>[u.observationId,u.score])),c=this.fetchRowsByIds(o).map(u=>qi(u,i.get(u.id)??null));return{results:c,total:c.length,mode:"SEMANTIC"}}searchFallback(e,r){let n=r.limit??ou;try{let s=this.db.query(`SELECT o.* FROM observations o
|
|
88
88
|
INNER JOIN observations_fts fts ON o.id = fts.rowid
|
|
89
89
|
WHERE observations_fts MATCH ?
|
|
90
90
|
ORDER BY o.created_at_epoch DESC
|