@sreetej510/pi-prompt-manager 0.3.2 → 0.3.6
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/index.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import{matchesKey as u,truncateToWidth as f}from"@earendil-works/pi-tui";var g=class{constructor(t,e,n,a){this.prompts=t;this.theme=n;this.done=a;this.selectedIndex=t.length>0?Math.max(0,Math.min(e,t.length-1)):0}selectedIndex;cache;handleInput(t){let e=this.prompts.length;if(u(t,"up")||t==="k"){e>0&&(this.selectedIndex=this.selectedIndex>0?this.selectedIndex-1:e-1,this.invalidate());return}if(u(t,"down")||t==="j"){e>0&&(this.selectedIndex=this.selectedIndex<e-1?this.selectedIndex+1:0,this.invalidate());return}if(u(t,"enter")&&e>0){this.done({action:"paste",index:this.selectedIndex});return}if((t==="e"||t==="E")&&e>0){this.done({action:"edit",index:this.selectedIndex});return}if((t==="d"||t==="D")&&e>0){this.done({action:"delete",index:this.selectedIndex});return}if(t==="a"||t==="A"){this.done({action:"add"});return}if(u(t,"escape")||u(t,"ctrl+c")){this.done({action:"close"});return}}render(t){if(this.cache?.w===t)return this.cache.lines;let e=this.theme,n=[],a=" Prompt Manager ",c=Math.max(0,t-a.length-3);if(n.push(f(e.fg("borderMuted","\u2500".repeat(3))+e.fg("accent",a)+e.fg("borderMuted","\u2500".repeat(c)),t)),n.push(""),this.prompts.length===0)n.push(f(` ${e.fg("dim","No prompts saved yet. Press [a] to add one.")}`,t));else{let r=Math.floor(5),o=Math.max(0,Math.min(this.selectedIndex-r,this.prompts.length-10)),p=Math.min(this.prompts.length,o+10);o>0&&n.push(f(` ${e.fg("dim",`\u2191 ${o} more above`)}`,t));for(let l=o;l<p;l++){let m=this.prompts[l];if(!m)continue;let v=l===this.selectedIndex,S=v?e.fg("accent","\u276F "):" ",b=v?e.fg("text",e.bold(m.name)):e.fg("muted",m.name),I=S+b;if(v&&m.content){let h=m.content.split(`
|
|
2
|
-
`)[0]?.trim()??"";if(h){let y=t-2-m.name.length-4;if(y>8){let $=h.length>y?`${h.slice(0,y-1)}\u2026`:h;I+=` ${e.fg("dim",$)}`}}}n.push(f(I,t))}p<this.prompts.length&&n.push(f(` ${e.fg("dim",`\u2193 ${this.prompts.length-p} more below`)}`,t))}n.push("");let i=this.prompts.length>0?"[\u2191\u2193/jk] navigate [Enter] paste [e] edit [d] delete [a] add [Esc] close":"[a] add a new prompt [Esc] close";return n.push(f(` ${e.fg("dim",i)}`,t)),n.push(""),this.cache={w:t,lines:n},n}invalidate(){this.cache=void 0}};import{mkdir as k,readFile as C,writeFile as L}from"node:fs/promises";import{dirname as D,join as j}from"node:path";import{getAgentDir as T}from"@earendil-works/pi-coding-agent";function P(){return j(T(),"prompt-manager.json")}async function x(){try{let s=await C(P(),"utf8"),t=JSON.parse(s);return Array.isArray(t.prompts)?t.prompts:[]}catch{return[]}}async function w(s){let t=P();await k(D(t),{recursive:!0}),await L(t,JSON.stringify({prompts:s},null,2),"utf8")}function A(){return Date.now().toString(36)+Math.random().toString(36).slice(2,7)}async function E(s,t){let e=t?.trim();if(!e){let i=await s.input("Prompt name:","e.g. Code Review Template");if(!i?.trim()){s.notify("Cancelled \u2014 no name given.","info");return}e=i.trim()}let n=await s.editor(`New prompt: ${e}`,"");if(!n?.trim()){s.notify("Cancelled \u2014 empty content not saved.","info");return}let a=await x(),c=a.findIndex(i=>i.name.toLowerCase()===e.toLowerCase());if(c>=0){if(!await s.confirm("Name already exists",`A prompt named "${e}" already exists. Overwrite it?`))return;let d=a[c];if(!d)return;a[c]={...d,content:n.trim(),updatedAt:Date.now()}}else{let i=Date.now();a.unshift({id:A(),name:e,content:n.trim(),createdAt:i,updatedAt:i})}await w(a),s.notify(`Prompt "${e}" saved.`,"info")}function M(s){s.registerCommand("prompt",{description:"Manage saved prompts \u2014 /prompt | /prompt add [name]",getArgumentCompletions:t=>{let n=[{value:"add",label:"add \u2014 create a new prompt"}].filter(a=>a.value.startsWith(t));return n.length>0?n:null},handler:async(t,e)=>{if(e.mode!=="tui"){e.ui.notify("/prompt requires interactive mode","error");return}let n=e.ui,a=t.trim().split(/\s+/).filter(Boolean),c=a[0]??"";if(c==="add"){let r=a.slice(1).join(" ")||void 0;await E(n,r);return}if(c!==""){n.notify("Usage: /prompt | /prompt add [name]","warning");return}let i=await x(),d=0;for(;;){let r=await n.custom((o,p,l,m)=>new g(i,d,p,m));if(!r||r.action==="close")break;if(r.action==="paste"){let o=i[r.index];o&&n.pasteToEditor(o.content);break}if(r.action==="add"){await E(n),i=await x();continue}if(r.action==="edit"){d=r.index;let o=i[r.index];if(!o)continue;let p=await n.editor(`Edit: ${o.name}`,o.content);p?.trim()&&(i[r.index]={...o,content:p.trim(),updatedAt:Date.now()},await w(i),n.notify(`"${o.name}" updated.`,"info"));continue}if(r.action==="delete"){d=r.index;let o=i[r.index];if(!o)continue;await n.confirm("Delete prompt",`Delete "${o.name}"? This cannot be undone.`)&&(i=i.filter((l,m)=>m!==r.index),d=Math.max(0,d-1),await w(i),n.notify(`"${o.name}" deleted.`,"info"))}}}})}function _(s){M(s)}export{_ as default};
|
|
2
|
+
`)[0]?.trim()??"";if(h){let y=t-2-m.name.length-4;if(y>8){let $=h.length>y?`${h.slice(0,y-1)}\u2026`:h;I+=` ${e.fg("dim",$)}`}}}n.push(f(I,t))}p<this.prompts.length&&n.push(f(` ${e.fg("dim",`\u2193 ${this.prompts.length-p} more below`)}`,t))}n.push("");let i=this.prompts.length>0?"[\u2191\u2193/jk] navigate [Enter] paste [e] edit [d] delete [a] add [Esc] close":"[a] add a new prompt [Esc] close";return n.push(f(` ${e.fg("dim",i)}`,t)),n.push(""),this.cache={w:t,lines:n},n}invalidate(){this.cache=void 0}};import{mkdir as k,readFile as C,writeFile as L}from"node:fs/promises";import{dirname as D,join as j}from"node:path";import{getAgentDir as T}from"@earendil-works/pi-coding-agent";function P(){return j(T(),"prompt-manager.json")}async function x(){try{let s=await C(P(),"utf8"),t=JSON.parse(s);return Array.isArray(t.prompts)?t.prompts:[]}catch{return[]}}async function w(s){let t=P();await k(D(t),{recursive:!0}),await L(t,JSON.stringify({prompts:s},null,2),"utf8")}function A(){return Date.now().toString(36)+Math.random().toString(36).slice(2,7)}async function E(s,t){let e=t?.trim();if(!e){let i=await s.input("Prompt name:","e.g. Code Review Template");if(!i?.trim()){s.notify("Cancelled \u2014 no name given.","info");return}e=i.trim()}let n=await s.editor(`New prompt: ${e}`,"");if(!n?.trim()){s.notify("Cancelled \u2014 empty content not saved.","info");return}let a=await x(),c=a.findIndex(i=>i.name.toLowerCase()===e.toLowerCase());if(c>=0){if(!await s.confirm("Name already exists",`A prompt named "${e}" already exists. Overwrite it?`))return;let d=a[c];if(!d)return;a[c]={...d,content:n.trim(),updatedAt:Date.now()}}else{let i=Date.now();a.unshift({id:A(),name:e,content:n.trim(),createdAt:i,updatedAt:i})}await w(a),s.notify(`Prompt "${e}" saved.`,"info")}function M(s){s.registerCommand("prompt",{description:"Manage saved prompts \u2014 /prompt | /prompt add [name]",getArgumentCompletions:t=>{let n=[{value:"add",label:"add \u2014 create a new prompt"}].filter(a=>a.value.startsWith(t));return n.length>0?n:null},handler:async(t,e)=>{if(e.mode!=="tui"){e.ui.notify("/prompt requires interactive mode","error");return}let n=e.ui,a=t.trim().split(/\s+/).filter(Boolean),c=a[0]??"";if(c==="add"){let r=a.slice(1).join(" ")||void 0;await E(n,r);return}if(c!==""){n.notify("Usage: /prompt | /prompt add [name]","warning");return}let i=await x(),d=0;for(;;){let r=await n.custom((o,p,l,m)=>new g(i,d,p,m));if(!r||r.action==="close")break;if(r.action==="paste"){let o=i[r.index];o&&(n.pasteToEditor(o.content),n.setStatus("prompt-manager-refresh",void 0));break}if(r.action==="add"){await E(n),i=await x();continue}if(r.action==="edit"){d=r.index;let o=i[r.index];if(!o)continue;let p=await n.editor(`Edit: ${o.name}`,o.content);p?.trim()&&(i[r.index]={...o,content:p.trim(),updatedAt:Date.now()},await w(i),n.notify(`"${o.name}" updated.`,"info"));continue}if(r.action==="delete"){d=r.index;let o=i[r.index];if(!o)continue;await n.confirm("Delete prompt",`Delete "${o.name}"? This cannot be undone.`)&&(i=i.filter((l,m)=>m!==r.index),d=Math.max(0,d-1),await w(i),n.notify(`"${o.name}" deleted.`,"info"))}}}})}function _(s){M(s)}export{_ as default};
|