Lines 157-197javascript
157 `)}}saveMemory(e){let t=dp("M"),r=(e.concepts[0]??"memory").slice(0,80);return this.stmts.insertEntry.run(t,"memory",r,e.content,"",null,0.5,null,JSON.stringify(e.concepts),JSON.stringify(e.files??[]),"","",Date.now()),Promise.resolve({id:t})}saveLesson(e){let t=e.confidence??0.5;if(t<Ke)throw Error("saveLesson rejected: confidence "+t+" < MIN_LESSON_CONFIDENCE "+Ke+" (low-value lesson spam guard)");if(e.dedupeKey!==void 0&&e.dedupeKey!==""){let n=this.stmts.dedupeLookup.get(e.dedupeKey);if(n)return Promise.resolve({id:n.id,deduped:!0})}let r=dp("L"),o=(e.content.split(`
158`)[0]??"lesson").slice(0,80);return this.stmts.insertEntry.run(r,"lesson",o,e.content,e.context,null,t,e.dedupeKey??null,JSON.stringify(e.tags??[]),JSON.stringify([]),"","",Date.now()),Promise.resolve({id:r})}purgeNoiseLessons(){let t="kind = 'lesson' AND confidence < "+Ke+` AND title LIKE 'Action "continue"%'`,o=this.db.prepare("SELECT COUNT(*) AS n FROM entries WHERE "+t).get()?.n??0;if(o>0)this.db.exec("DELETE FROM entries WHERE "+t);return o}expireUnusedLessons(e){let r=this.db.prepare("SELECT COUNT(*) AS n FROM entries WHERE kind = 'lesson' AND created_at < ? AND (last_used IS NULL OR las ...
159(Consolidated from ${n.length} similar lessons.)`,c,Date.now(),s.id);let p=i.slice(1).map((d)=>d.id),g=p.map(()=>"?").join(",");this.db.prepare(`DELETE FROM entries WHERE id IN (${g})`).run(...p),o+=p.length}return{groups:r,merged:o}}topLessons(e=3){let t=this.db.prepare("SELECT id, title, content, tags, files, confidence, advice FROM entries WHERE kind = 'lesson' AND confidence >= "+Ke+" ORDER BY confidence DESC, created_at DESC LIMIT ?").all(e);return Promise.resolve(t.map((r)=>({id:r.id,title:r.title,content:r.content,type:"lesson",concepts:zr(r.tags),confidence:r.confidence,files:zr(r.file ...
161 JOIN skills_fts f ON f.rowid = (SELECT rowid FROM skills WHERE id = s.id)
164 LIMIT ?`).all(...r,n);return Promise.resolve(i)}skillGet(e){let t=this.db.prepare(`SELECT s.id, s.name, s.description, s.repo_url, s.installs, s.skill_id, s.download_count, s.last_synced, s.content_hash
166 WHERE s.id = ?`).get(e);return Promise.resolve(t??null)}skillAddOrUpdate(e){let t=Date.now();return this.db.prepare(`
167 INSERT INTO skills (id, name, description, repo_url, installs, skill_id, download_count, last_synced, content_hash)
168 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
169 ON CONFLICT(id) DO UPDATE SET
170 name = excluded.name,
171 description = excluded.description,
172 repo_url = excluded.repo_url,
173 installs = excluded.installs,
174 skill_id = excluded.skill_id,
175 download_count = excluded.download_count,
176 last_synced = excluded.last_synced,
177 content_hash = excluded.content_hash
178 `).run(e.id,e.name,e.description,e.repo_url,e.installs??0,e.skill_id,e.download_count??0,e.last_synced??t,e.content_hash),Promise.resolve(e.id)}setSkillMaterializedAt(e,t){this.db.prepare("UPDATE skills SET last_materialized_at = ? WHERE id LIKE ? OR id = ?").run(t,`%/${e}`,e)}getSkillMaterializedAt(e){return this.db.prepare("SELECT last_materialized_at FROM skills WHERE id = ?").get(e)?.last_materialized_at??null}skillReplaceDeps(e,t){this.db.exec("BEGIN");try{this.db.prepare("DELETE FROM skill_deps WHERE skill_id = ?").run(e);let r=this.db.prepare("INSERT OR IGNORE INTO skill_deps (skill ...
179`)}var Gt=(e)=>(t,r,o,n)=>{let i=o?Object.assign(o,{async:!1}):{async:!1},s=
180`).filter((i)=>i),o=Math.min(...r.map((i)=>i.length-i.trimStart().length)),n=r.map((i)=>i.slice(o)).map((i)=>" ".repeat(this.indent*2)+i);for(let i of n)this.content.push(i)}compile(){let e=Function,t=this?.args,o=[...(this?.content??[""]).map((n)=>` ${n}`)];return new e(...t,o.join(`
181`))}}var pa={major:4,minor:1,patch:8};var M=f("$ZodType",(e,t)=>{var r;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=pa;let o=[...e._zod.def.checks??[]];if(e._zod.traits.has("$ZodCheck"))o.unshift(e);for(let n of o)for(let i of n._zod.onattach)i(e);if(o.length===0)(r=e._zod).deferred??(r.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let n=(s,a,l)=>{let c=gt(s),u;for(let p of a){if(p._zod.def.when){if(!p._zod.def.when(s))continue}else if(c)continue;let g=s.issues.length,d=p._zod.check(s);if(d instanceof Promise&&l?.async===!1)throw new We;if(u||d insta ...
182 if (${K}.issues.length) {
183 payload.issues = payload.issues.concat(${K}.issues.map(iss => ({
185 path: iss.path ? [${oe}, ...iss.path] : [${oe}]
190 if (${K}.value === undefined) {
191 if (${oe} in input) {
192 newResult[${oe}] = undefined;
195 newResult[${oe}] = ${K}.value;
Long lines were clipped for display.