prjct-cli 2.23.3 → 2.23.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/CHANGELOG.md +11 -0
- package/dist/bin/prjct-core.mjs +215 -215
- package/dist/daemon/entry.mjs +178 -178
- package/dist/mcp/server.mjs +1 -1
- package/package.json +1 -1
package/dist/mcp/server.mjs
CHANGED
|
@@ -548,7 +548,7 @@ CREATE TABLE velocity_sprints (
|
|
|
548
548
|
NF { files[$0]++; if (!lastmod[$0]) lastmod[$0]=timestamp }
|
|
549
549
|
END { for (f in files) print files[f], lastmod[f], f }
|
|
550
550
|
'`,{cwd:r,maxBuffer:10485760}),s=Math.floor(Date.now()/1e3),n=e.trim().split(`
|
|
551
|
-
`).filter(Boolean);for(let i of n){let o=i.match(/^(\d+)\s+(\d+)\s+(.+)$/);if(o){let a=parseInt(o[1],10),u=parseInt(o[2],10),p=o[3],m=Math.floor((s-u)/86400);t.set(p,{commits:a,daysAgo:m})}}}catch{}return t}function ko(r,t,e,s){let n=[],i=0,o=0,a=0,u=0,p=0,m=r.toLowerCase(),d=m.split("/").join(" ").split(/[^a-z0-9]+/);for(let A of t){m.includes(A)&&(i+=.3,n.push(`keyword:${A}`));for(let V of d)if(V.includes(A)||A.includes(V)){i+=.15;break}}i=Math.min(1,i);for(let[A,V]of Object.entries(ln))for(let Qt of V)if(m.includes(Qt)&&t.some(Zt=>V.includes(Zt)||Zt.includes(A)||A.includes(Zt))){o+=.4,n.push(`domain:${A}`);break}o=Math.min(1,o);let f=e.get(r);f&&(f.daysAgo<=1?(a=1,n.push("recent:1d")):f.daysAgo<=3?(a=.8,n.push("recent:3d")):f.daysAgo<=7?(a=.6,n.push("recent:1w")):f.daysAgo<=30&&(a=.3,n.push("recent:1m")),f.commits>=5&&(a=Math.min(1,a+.2)));let T=qt.basename(r).toLowerCase();if((T.includes("index")||T.includes("main")||T.includes("app")||T.includes("entry"))&&(u=.5,n.push("import:0")),(m.includes("/core/")||m.includes("/shared/")||m.includes("/lib/"))&&(u=Math.max(u,.3),n.some(A=>A.startsWith("import:"))||n.push("import:1")),s){let A=s.get(r);A!==void 0&&(p=(A+1)/2,A>0?n.push("history:boosted"):A<0&&n.push("history:penalized"))}let z=s&&s.size>0?i*.54+o*.18+a*.13+u*.05+p*.1:i*.6+o*.2+a*.15+u*.05;return{path:r,score:Math.min(1,z),reasons:[...new Set(n)]}}function Eo(r){let t=r.toLowerCase();return t.includes(".test.")||t.includes(".spec.")||t.includes("__tests__")||t.includes("__mocks__")||t.includes("/tests/")||t.includes("/test/")||t.endsWith("_test.go")||t.endsWith("_test.py")}var qe=k(()=>{"use strict";Z();nt();gn();c(Gt,"findRelevantFiles");c(ho,"extractKeywords");c(yo,"getAllCodeFiles");c(To,"getGitRecency");c(ko,"scoreFile");c(Eo,"isTestFile")});var Ye,wn,bn=k(()=>{"use strict";Tt();Bt();j();Ye=class{static{c(this,"MemoryService")}async log(t,e,s,n){try{let i=await H.getProjectId(t);if(!i)return;y.appendEvent(i,`memory.${e}`,{...s,author:n})}catch(i){console.error(`Memory log error: ${i instanceof Error?i.message:String(i)}`)}}async getRecent(t,e=100){try{let s=await H.getProjectId(t);return s?y.query(s,"SELECT type, data, timestamp FROM events WHERE type LIKE 'memory.%' ORDER BY id DESC LIMIT ?",e).reverse().map(i=>{let o=JSON.parse(i.data),{author:a,...u}=o;return{timestamp:i.timestamp,action:i.type.replace("memory.",""),data:u,author:a}}):[]}catch(s){return console.error(`Memory read error: ${s instanceof Error?s.message:String(s)}`),[]}}async search(t,e,s=50){let n=await this.getRecent(t,1e3),i=e.toLowerCase();return n.filter(o=>{let a=o.action.toLowerCase().includes(i),u=JSON.stringify(o.data).toLowerCase().includes(i);return a||u}).slice(-s)}async getByAction(t,e,s=50){try{let n=await H.getProjectId(t);return n?y.query(n,"SELECT type, data, timestamp FROM events WHERE type = ? ORDER BY id DESC LIMIT ?",`memory.${e}`,s).reverse().map(o=>{let a=JSON.parse(o.data),{author:u,...p}=a;return{timestamp:o.timestamp,action:o.type.replace("memory.",""),data:p,author:u}}):[]}catch(n){return console.error(`Memory read error: ${n instanceof Error?n.message:String(n)}`),[]}}async clear(t){try{let e=await H.getProjectId(t);if(!e)return;y.run(e,"DELETE FROM events WHERE type LIKE 'memory.%'")}catch(e){console.error(`Memory clear error: ${e instanceof Error?e.message:String(e)}`)}}async getRecentEvents(t,e=100){try{return y.query(t,"SELECT type, data, timestamp FROM events WHERE type LIKE 'memory.%' ORDER BY id DESC LIMIT ?",e).reverse().map(n=>{let i=JSON.parse(n.data);return{timestamp:n.timestamp,action:n.type.replace("memory.",""),...i}})}catch(s){return console.error(`Memory read error: ${s instanceof Error?s.message:String(s)}`),[]}}async capEntries(t){try{let s=y.get(t,"SELECT COUNT(*) as cnt FROM events WHERE type LIKE 'memory.%'")?.cnt??0;if(s<=wt.MEMORY_MAX_ENTRIES)return 0;let n=s-wt.MEMORY_MAX_ENTRIES,i=y.query(t,"SELECT id, type, data, timestamp FROM events WHERE type LIKE 'memory.%' ORDER BY id ASC LIMIT ?",n);ct.archiveMany(t,i.map((a,u)=>({entityType:"memory_entry",entityId:`memory-${a.timestamp||u}`,entityData:{type:a.type,data:JSON.parse(a.data),timestamp:a.timestamp},summary:a.type.replace("memory.",""),reason:"overflow"})));let o=i[i.length-1]?.id;return o!==void 0&&y.run(t,"DELETE FROM events WHERE type LIKE 'memory.%' AND id <= ?",o),n}catch(e){return console.error(`Memory cap error: ${e instanceof Error?e.message:String(e)}`),0}}},wn=new Ye});var _n,Je,bt,ap,vn=k(()=>{"use strict";_n="memory.",Je="remember.",bt=`${_n}${Je}`,ap=`${_n}task.tagged`});function An(r,t){try{return JSON.parse(r)}catch{return t}}function ze(r){let t=r.type.slice(bt.length),e=An(r.data,{});return{id:`mem_${r.id}`,type:t,content:e.content??"",tags:e.tags??{},rememberedAt:r.timestamp,source:e.source,provenance:e.provenance??"declared"}}function xn(r){let t=r.data?An(r.data,{}):{},e=t.tags??{};return r.type&&(e.type=r.type),{id:`ship_${r.id}`,type:"shipped",content:r.name,tags:e,rememberedAt:r.shipped_at,source:t.taskId,provenance:"extracted"}}function Mo(r,t){let e=t.toLowerCase();if(r.content.toLowerCase().includes(e))return!0;for(let s of Object.values(r.tags))if(s.toLowerCase().includes(e))return!0;return!1}function jo(r,t){for(let[e,s]of Object.entries(t))if(r.tags[e]!==s)return!1;return!0}function Fo(r){let t=new Set,e=[];for(let s of r){let n=s.tags.key;if(!n){e.push(s);continue}let i=`${s.type}::${n}`;t.has(i)||(t.add(i),e.push(s))}return e}function Uo(r){return r.replace(/[[\]|]/g,"").replace(/\s+/g," ").trim()}function Pn(r,t){return r.replace(/\[\[(mem[_-]\d+)\]\]/gi,"$1").replace(/\bmem[_-](\d+)\b/g,(e,s)=>{let n=`mem_${s}`,i=t?.idTypeIndex?.get(n),o=t?.idTitleIndex?.get(n),a=o?Uo(o):n;return i&&t?.perEntryTypes?.has(i)?`[[${
|
|
551
|
+
`).filter(Boolean);for(let i of n){let o=i.match(/^(\d+)\s+(\d+)\s+(.+)$/);if(o){let a=parseInt(o[1],10),u=parseInt(o[2],10),p=o[3],m=Math.floor((s-u)/86400);t.set(p,{commits:a,daysAgo:m})}}}catch{}return t}function ko(r,t,e,s){let n=[],i=0,o=0,a=0,u=0,p=0,m=r.toLowerCase(),d=m.split("/").join(" ").split(/[^a-z0-9]+/);for(let A of t){m.includes(A)&&(i+=.3,n.push(`keyword:${A}`));for(let V of d)if(V.includes(A)||A.includes(V)){i+=.15;break}}i=Math.min(1,i);for(let[A,V]of Object.entries(ln))for(let Qt of V)if(m.includes(Qt)&&t.some(Zt=>V.includes(Zt)||Zt.includes(A)||A.includes(Zt))){o+=.4,n.push(`domain:${A}`);break}o=Math.min(1,o);let f=e.get(r);f&&(f.daysAgo<=1?(a=1,n.push("recent:1d")):f.daysAgo<=3?(a=.8,n.push("recent:3d")):f.daysAgo<=7?(a=.6,n.push("recent:1w")):f.daysAgo<=30&&(a=.3,n.push("recent:1m")),f.commits>=5&&(a=Math.min(1,a+.2)));let T=qt.basename(r).toLowerCase();if((T.includes("index")||T.includes("main")||T.includes("app")||T.includes("entry"))&&(u=.5,n.push("import:0")),(m.includes("/core/")||m.includes("/shared/")||m.includes("/lib/"))&&(u=Math.max(u,.3),n.some(A=>A.startsWith("import:"))||n.push("import:1")),s){let A=s.get(r);A!==void 0&&(p=(A+1)/2,A>0?n.push("history:boosted"):A<0&&n.push("history:penalized"))}let z=s&&s.size>0?i*.54+o*.18+a*.13+u*.05+p*.1:i*.6+o*.2+a*.15+u*.05;return{path:r,score:Math.min(1,z),reasons:[...new Set(n)]}}function Eo(r){let t=r.toLowerCase();return t.includes(".test.")||t.includes(".spec.")||t.includes("__tests__")||t.includes("__mocks__")||t.includes("/tests/")||t.includes("/test/")||t.endsWith("_test.go")||t.endsWith("_test.py")}var qe=k(()=>{"use strict";Z();nt();gn();c(Gt,"findRelevantFiles");c(ho,"extractKeywords");c(yo,"getAllCodeFiles");c(To,"getGitRecency");c(ko,"scoreFile");c(Eo,"isTestFile")});var Ye,wn,bn=k(()=>{"use strict";Tt();Bt();j();Ye=class{static{c(this,"MemoryService")}async log(t,e,s,n){try{let i=await H.getProjectId(t);if(!i)return;y.appendEvent(i,`memory.${e}`,{...s,author:n})}catch(i){console.error(`Memory log error: ${i instanceof Error?i.message:String(i)}`)}}async getRecent(t,e=100){try{let s=await H.getProjectId(t);return s?y.query(s,"SELECT type, data, timestamp FROM events WHERE type LIKE 'memory.%' ORDER BY id DESC LIMIT ?",e).reverse().map(i=>{let o=JSON.parse(i.data),{author:a,...u}=o;return{timestamp:i.timestamp,action:i.type.replace("memory.",""),data:u,author:a}}):[]}catch(s){return console.error(`Memory read error: ${s instanceof Error?s.message:String(s)}`),[]}}async search(t,e,s=50){let n=await this.getRecent(t,1e3),i=e.toLowerCase();return n.filter(o=>{let a=o.action.toLowerCase().includes(i),u=JSON.stringify(o.data).toLowerCase().includes(i);return a||u}).slice(-s)}async getByAction(t,e,s=50){try{let n=await H.getProjectId(t);return n?y.query(n,"SELECT type, data, timestamp FROM events WHERE type = ? ORDER BY id DESC LIMIT ?",`memory.${e}`,s).reverse().map(o=>{let a=JSON.parse(o.data),{author:u,...p}=a;return{timestamp:o.timestamp,action:o.type.replace("memory.",""),data:p,author:u}}):[]}catch(n){return console.error(`Memory read error: ${n instanceof Error?n.message:String(n)}`),[]}}async clear(t){try{let e=await H.getProjectId(t);if(!e)return;y.run(e,"DELETE FROM events WHERE type LIKE 'memory.%'")}catch(e){console.error(`Memory clear error: ${e instanceof Error?e.message:String(e)}`)}}async getRecentEvents(t,e=100){try{return y.query(t,"SELECT type, data, timestamp FROM events WHERE type LIKE 'memory.%' ORDER BY id DESC LIMIT ?",e).reverse().map(n=>{let i=JSON.parse(n.data);return{timestamp:n.timestamp,action:n.type.replace("memory.",""),...i}})}catch(s){return console.error(`Memory read error: ${s instanceof Error?s.message:String(s)}`),[]}}async capEntries(t){try{let s=y.get(t,"SELECT COUNT(*) as cnt FROM events WHERE type LIKE 'memory.%'")?.cnt??0;if(s<=wt.MEMORY_MAX_ENTRIES)return 0;let n=s-wt.MEMORY_MAX_ENTRIES,i=y.query(t,"SELECT id, type, data, timestamp FROM events WHERE type LIKE 'memory.%' ORDER BY id ASC LIMIT ?",n);ct.archiveMany(t,i.map((a,u)=>({entityType:"memory_entry",entityId:`memory-${a.timestamp||u}`,entityData:{type:a.type,data:JSON.parse(a.data),timestamp:a.timestamp},summary:a.type.replace("memory.",""),reason:"overflow"})));let o=i[i.length-1]?.id;return o!==void 0&&y.run(t,"DELETE FROM events WHERE type LIKE 'memory.%' AND id <= ?",o),n}catch(e){return console.error(`Memory cap error: ${e instanceof Error?e.message:String(e)}`),0}}},wn=new Ye});var _n,Je,bt,ap,vn=k(()=>{"use strict";_n="memory.",Je="remember.",bt=`${_n}${Je}`,ap=`${_n}task.tagged`});function An(r,t){try{return JSON.parse(r)}catch{return t}}function ze(r){let t=r.type.slice(bt.length),e=An(r.data,{});return{id:`mem_${r.id}`,type:t,content:e.content??"",tags:e.tags??{},rememberedAt:r.timestamp,source:e.source,provenance:e.provenance??"declared"}}function xn(r){let t=r.data?An(r.data,{}):{},e=t.tags??{};return r.type&&(e.type=r.type),{id:`ship_${r.id}`,type:"shipped",content:r.name,tags:e,rememberedAt:r.shipped_at,source:t.taskId,provenance:"extracted"}}function Mo(r,t){let e=t.toLowerCase();if(r.content.toLowerCase().includes(e))return!0;for(let s of Object.values(r.tags))if(s.toLowerCase().includes(e))return!0;return!1}function jo(r,t){for(let[e,s]of Object.entries(t))if(r.tags[e]!==s)return!1;return!0}function Fo(r){let t=new Set,e=[];for(let s of r){let n=s.tags.key;if(!n){e.push(s);continue}let i=`${s.type}::${n}`;t.has(i)||(t.add(i),e.push(s))}return e}function Uo(r){return r.replace(/[[\]|]/g,"").replace(/\s+/g," ").trim()}function Pn(r,t){return r.replace(/\[\[(mem[_-]\d+)\]\]/gi,"$1").replace(/\bmem[_-](\d+)\b/g,(e,s)=>{let n=`mem_${s}`,i=t?.idTypeIndex?.get(n),o=t?.idTitleIndex?.get(n),a=t?.idSlugIndex?.get(n),u=o?Uo(o):n;return a&&i&&t?.perEntryTypes?.has(i)?`[[${a}|${u}]]`:i?`[[${i}#^mem-${s}|${u}]]`:o?`[[${n}|${u}]]`:`\`${n}\``})}function _t(r,t){if(r.length===0)return"> No matching memory entries.";let e=new Map;for(let u of r){let p=e.get(u.type)??[];p.push(u),e.set(u.type,p)}let s=["decision","learning","anti-pattern","gotcha","pattern","fact","inbox","todo","idea","insight","question","source","person","shipped"],n=[],i={declared:"DECL",extracted:"EXTR",inferred:"INFR",ambiguous:"AMBG"},o=c((u,p)=>{if(p.length!==0){n.push(`### ${u.toUpperCase()}`);for(let m of p){let d=Object.entries(m.tags).map(([V,Qt])=>`${V}=${Qt}`).join(" "),f=i[m.provenance],T=t?.vault?Pn(m.content,t):m.content,M=d?` _(${t?.vault?Pn(d,t):d})_`:"",z=m.id.replace(/^mem[_-]/,""),A=t?.vault?` ^mem-${z}`:"";n.push(`- \`${f}\` [${m.id} \xB7 ${m.type}] ${T}${M}${A}`)}n.push("")}},"renderGroup"),a=new Set;for(let u of s){let p=e.get(u);!p||p.length===0||(o(u,p),a.add(u))}for(let[u,p]of e)a.has(u)||o(u,p);return n.join(`
|
|
552
552
|
`).trim()}var Rn,Do,Lo,Oo,O,dt=k(()=>{"use strict";bn();j();vn();Rn=["fact","decision","learning","gotcha","pattern","anti-pattern","shipped","inbox","todo","idea","insight","question","source","person","spec"],Do=25,Lo=4,Oo=100;c(An,"safeJson");c(ze,"rowToEntry");c(xn,"shippedRowToEntry");c(Mo,"matchesTopic");c(jo,"matchesTags");c(Fo,"dedupeLatestByKey");O={async remember(r,t){await wn.log(r,`${Je}${t.type}`,{content:t.content,tags:t.tags??{},source:t.source,provenance:t.provenance??"declared"});try{let{default:e}=await Promise.resolve().then(()=>(Tt(),hr)),n=(await e.readConfig(r))?.projectId;if(!n)return;let{publishCRUD:i}=await Promise.resolve().then(()=>(St(),Ir)),o=t.tags?.spec_id??t.tags?.task_id??t.tags?.id??t.source??`mem-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;await i({projectId:n,entityType:"memories",entityId:o,eventType:"upsert",data:{id:o,type:t.type,content:t.content,tags:t.tags??{},source:t.source??null,provenance:t.provenance??"declared",rememberedAt:new Date().toISOString()}})}catch{}},recall(r,t={}){let e=t.limit??Do,s=Math.max(e*Lo,Oo),n=y.query(r,"SELECT id, type, data, timestamp FROM events WHERE type LIKE ? ORDER BY id DESC LIMIT ?",`${bt}%`,s),i=y.query(r,"SELECT id, name, type, shipped_at, data FROM shipped_features ORDER BY shipped_at DESC LIMIT ?",s),o=[...n.map(ze),...i.map(xn)];if(t.types&&t.types.length>0){let a=new Set(t.types);o=o.filter(u=>a.has(u.type))}return t.tags&&(o=o.filter(a=>jo(a,t.tags??{}))),t.topic&&(o=o.filter(a=>Mo(a,t.topic))),o.sort((a,u)=>u.rememberedAt.localeCompare(a.rememberedAt)),t.dedupeByKey!==!1&&(o=Fo(o)),o.slice(0,e)},getById(r,t){let e=String(t).trim().match(/^(?:mem[_-])?(\d+)$/i);if(!e)return null;let s=Number(e[1]);try{let n=y.get(r,"SELECT id, type, data, timestamp FROM events WHERE id = ? AND type LIKE ?",s,`${bt}%`);return n?ze(n):null}catch{return null}},allEntriesForIndex(r){try{let t=y.query(r,"SELECT id, type, data, timestamp FROM events WHERE type LIKE ? ORDER BY id DESC",`${bt}%`),e=y.query(r,"SELECT id, name, type, shipped_at, data FROM shipped_features ORDER BY shipped_at DESC");return[...t.map(ze),...e.map(xn)]}catch{return[]}},similar(r,t,e=10){let s=t.toLowerCase().split(/[^a-z0-9]+/).filter(o=>o.length>3);return s.length===0?[]:O.recall(r,{limit:200}).map(o=>{let a=`${o.content} ${Object.values(o.tags).join(" ")}`.toLowerCase(),u=s.reduce((p,m)=>a.includes(m)?p+1:p,0);return{entry:o,hits:u}}).filter(o=>o.hits>0).sort((o,a)=>a.hits-o.hits).slice(0,e).map(o=>o.entry)}};c(Uo,"linkLabel");c(Pn,"linkifyMemRefs");c(_t,"formatMemoryMd")});function jn(r){return[...r].sort((t,e)=>{let s=Mn[t.section]-Mn[e.section];return s!==0?s:On[t.priority]-On[e.priority]})}var On,Mn,Fn=k(()=>{"use strict";On={critical:0,high:1,medium:2,low:3},Mn={active:0,previously_active:1,backlog:2};c(jn,"sortBySectionAndPriority")});var Ve,vt,Qe=k(()=>{"use strict";Et();$t();Fn();C();Bt();Be();Ve=class extends ut{static{c(this,"QueueStorage")}constructor(){super("queue.json",_r)}getDefault(){return{tasks:[],lastUpdated:""}}getEventType(t){return`queue.${t}d`}async getTasks(t){return(await this.read(t)).tasks}async getActiveTasks(t){return(await this.read(t)).tasks.filter(s=>s.section==="active"&&!s.completed)}async getBacklog(t){return(await this.read(t)).tasks.filter(s=>s.section==="backlog"&&!s.completed)}async getNextTask(t){let e=await this.getActiveTasks(t);return jn(e)[0]||null}async addTask(t,e){let s={...e,id:q(),createdAt:g(),completed:!1};return await this.update(t,n=>({tasks:[...n.tasks,s],lastUpdated:g()})),await this.publishEvent(t,"queue.task_added",{taskId:s.id,description:s.description,priority:s.priority,section:s.section}),s}async addTasks(t,e){let s=g(),n=e.map(i=>({...i,id:q(),createdAt:s,completed:!1}));return await this.update(t,i=>({tasks:[...i.tasks,...n],lastUpdated:s})),await this.publishEvent(t,"queue.tasks_added",{count:n.length,tasks:n.map(i=>({id:i.id,description:i.description}))}),n}async removeTask(t,e){await this.update(t,s=>({tasks:s.tasks.filter(n=>n.id!==e),lastUpdated:g()})),await this.publishEvent(t,"queue.task_removed",{taskId:e})}async deleteByFeatureId(t,e){let s=0;return await this.update(t,n=>{let i=n.tasks.length,o=n.tasks.filter(a=>a.featureId!==e);return s=i-o.length,{tasks:o,lastUpdated:g()}}),s>0&&await this.publishEvent(t,"queue.tasks_removed_by_feature",{featureId:e,count:s}),s}async completeTask(t,e){let s=null;if(await this.update(t,n=>({tasks:n.tasks.map(o=>o.id===e?(s={...o,completed:!0,completedAt:g()},s):o),lastUpdated:g()})),s){let n=s;await this.publishEvent(t,"queue.task_completed",{taskId:e,description:n.description,completedAt:n.completedAt})}return s}async moveToSection(t,e,s){await this.update(t,n=>({tasks:n.tasks.map(i=>i.id===e?{...i,section:s}:i),lastUpdated:g()}))}async setPriority(t,e,s){await this.update(t,n=>({tasks:n.tasks.map(i=>i.id===e?{...i,priority:s}:i),lastUpdated:g()}))}async getTask(t,e){return(await this.read(t)).tasks.find(n=>n.id===e)||null}async updateTask(t,e,s){let n=null;return await this.update(t,i=>({tasks:i.tasks.map(o=>o.id===e?(n={...o,...s},n):o),lastUpdated:g()})),n&&await this.publishEvent(t,"queue.task_updated",{taskId:e}),n}async clearCompleted(t){let s=(await this.read(t)).tasks.filter(n=>n.completed).length;return await this.update(t,n=>({tasks:n.tasks.filter(i=>!i.completed),lastUpdated:g()})),s}async removeStaleCompleted(t){let e=await this.read(t),s=ms(wt.QUEUE_COMPLETED_DAYS),n=e.tasks.filter(o=>o.completed&&o.completedAt&&new Date(o.completedAt)<s);if(n.length===0)return 0;ct.archiveMany(t,n.map(o=>({entityType:"queue_task",entityId:o.id,entityData:o,summary:o.description,reason:"age"})));let i=new Set(n.map(o=>o.id));return await this.update(t,o=>({tasks:o.tasks.filter(a=>!i.has(a.id)),lastUpdated:g()})),await this.publishEvent(t,"queue.stale_removed",{count:n.length}),n.length}},vt=new Ve});import{z as b}from"zod";var mt,es,ts,Xo,Y,Jt=k(()=>{"use strict";mt=["draft","reviewed","in_progress","shipped","archived"],es=["strategic","architecture","design"],ts=b.object({verdict:b.enum(["pass","fail"]),notes:b.string(),ts:b.string()}),Xo=b.object({risk:b.string().min(1),mitigation:b.string().min(1)}),Y=b.object({goal:b.string().min(1),eli10:b.string().default(""),stakes:b.string().default(""),acceptance_criteria:b.array(b.string().min(1)).default([]),scope:b.array(b.string()).default([]),out_of_scope:b.array(b.string()).default([]),risks:b.array(Xo).default([]),test_plan:b.array(b.string()).default([]),reviews:b.object({strategic:ts.optional(),architecture:ts.optional(),design:ts.optional()}).optional(),linked_tasks:b.array(b.string()).default([]),notes:b.string().default(""),tasks_created_at:b.string().nullable().default(null)})});var ss,x,zt=k(()=>{"use strict";Et();Jt();C();j();ss=class{static{c(this,"SpecStorage")}nextUpdatedAt(t,e){let s=g(),i=y.get(t,"SELECT updated_at FROM specs WHERE id = ?",e)?.updated_at;return!i||s>i?s:new Date(new Date(i).getTime()+1).toISOString()}create(t,e){let s=q(),n=g(),i=Y.parse(e.content);return y.run(t,`INSERT INTO specs (id, title, status, content, tags, created_at, updated_at)
|
|
553
553
|
VALUES (?, ?, 'draft', ?, ?, ?, ?)`,s,e.title,JSON.stringify(i),e.tags?JSON.stringify(e.tags):null,n,n),{id:s,title:e.title,status:"draft",content:i,tags:e.tags??{},createdAt:n,updatedAt:n,shippedAt:null,shippedPr:null,shippedSha:null,archivedAt:null}}get(t,e){let s=y.get(t,"SELECT * FROM specs WHERE id = ?",e);return s?this.rowToSpec(s):null}list(t,e={}){let s="SELECT * FROM specs WHERE 1=1",n=[];return e.status&&(s+=" AND status = ?",n.push(e.status)),!e.includeArchived&&!e.status&&(s+=" AND status != 'archived'"),s+=" ORDER BY created_at DESC",y.query(t,s,...n).map(o=>this.rowToSpec(o))}search(t,e){let s=`%${e}%`;return y.query(t,"SELECT * FROM specs WHERE title LIKE ? OR content LIKE ? ORDER BY created_at DESC",s,s).map(i=>this.rowToSpec(i))}updateContent(t,e,s){let n=Y.parse(s),i=this.nextUpdatedAt(t,e);return y.run(t,"UPDATE specs SET content = ?, updated_at = ? WHERE id = ?",JSON.stringify(n),i,e),this.get(t,e)}casUpdate(t,e,s,n){let i=Y.parse(s),o=this.nextUpdatedAt(t,e);return y.run(t,"UPDATE specs SET content = ?, updated_at = ? WHERE id = ? AND updated_at = ?",JSON.stringify(i),o,e,n).changes===1}setStatus(t,e,s){if(!mt.includes(s))throw new Error(`invalid spec status: ${s}`);let n=this.nextUpdatedAt(t,e),i=[],o=[s,n];s==="shipped"&&(i.push("shipped_at = ?"),o.push(n)),s==="archived"&&(i.push("archived_at = ?"),o.push(n));let a=["status = ?","updated_at = ?",...i].join(", ");return o.push(e),y.run(t,`UPDATE specs SET ${a} WHERE id = ?`,...o),this.get(t,e)}setShippedPr(t,e,s){return y.run(t,"UPDATE specs SET shipped_pr = ?, updated_at = ? WHERE id = ?",s,this.nextUpdatedAt(t,e),e),this.get(t,e)}setShippedSha(t,e,s){return y.run(t,"UPDATE specs SET shipped_sha = ?, updated_at = ? WHERE id = ?",s,this.nextUpdatedAt(t,e),e),this.get(t,e)}linkTask(t,e,s){let n=this.get(t,e);if(!n)return null;if(n.content.linked_tasks.includes(s))return n;let i={...n.content,linked_tasks:[...n.content.linked_tasks,s]};return this.updateContent(t,e,i)}delete(t,e){return this.get(t,e)?(y.run(t,"DELETE FROM specs WHERE id = ?",e),!0):!1}count(t){let e=y.query(t,"SELECT status, COUNT(*) AS n FROM specs GROUP BY status"),s={total:0,draft:0,shipped:0};for(let n of e)s.total+=n.n,n.status==="draft"&&(s.draft=n.n),n.status==="shipped"&&(s.shipped=n.n);return s}rowToSpec(t){return{id:t.id,title:t.title,status:mt.includes(t.status)?t.status:"draft",content:Y.parse(JSON.parse(t.content)),tags:t.tags?JSON.parse(t.tags):{},createdAt:t.created_at,updatedAt:t.updated_at,shippedAt:t.shipped_at,shippedPr:t.shipped_pr,shippedSha:t.shipped_sha,archivedAt:t.archived_at}}},x=new ss});var Xn={};Q(Xn,{inferSpecContext:()=>Ho,warnNoContextMatch:()=>Yo});async function Ho(r,t,e){let[s,n]=await Promise.all([Gt(r,e,{maxFiles:$n*4,minScore:Bo}).catch(()=>({files:[]})),Promise.resolve(O.recall(t,{topic:r,limit:Wo})).catch(()=>[])]),i=qo(s.files.map(u=>u.path),$n);return i.length===0&&n.length===0?{notesBlock:"",paths:[],memoryHits:0,empty:!0}:{notesBlock:Go(r,i,n),paths:i,memoryHits:n.length,empty:!1}}function qo(r,t){let e=new Set,s=[];for(let n of r){let i=n.split("/").slice(0,2).join("/");if(!e.has(i)&&(e.add(i),s.push(n),s.length>=t))break}return s}function Go(r,t,e){let s=[];if(s.push("<!-- auto-context:tentative -->"),s.push("## Existing context (auto-inferred)"),s.push(""),s.push(`_Inferred from title "${r}". Validate before audit \u2014 entries tagged tentative._`),s.push(""),t.length>0){s.push("### Likely paths");for(let n of t)s.push(`- \`${n}\``);s.push("")}if(e.length>0){s.push("### Relevant prior memory");for(let n of e){let i=n.content.length>140?`${n.content.slice(0,137)}\u2026`:n.content,o=Object.entries(n.tags).map(([a,u])=>`${a}:${u}`).join(" ");s.push(`- **${n.type}**${o?` _(${o})_`:""} \u2014 ${i}`)}s.push("")}return s.push("<!-- /auto-context -->"),s.join(`
|
|
554
554
|
`)}function Yo(r,t){let e={level:"warn",code:"no_context_match",message:`No codebase or memory context matched "${r}"`,suggestion:t??"Fill spec.notes manually or run with `--skip-context` next time."};process.stderr.write(`${JSON.stringify(e)}
|