@fmdzc/cli-ai 3.0.2 → 3.0.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/LICENSE +15 -15
- package/README.md +171 -169
- package/dist/cli.js +13 -13
- package/dist/index.js +14 -14
- package/package.json +7 -3
- package/scripts/tag.js +120 -0
- package/scripts/uninstall.js +332 -332
- package/scripts/version.js +52 -0
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{render as
|
|
2
|
-
`,"Get one at: ",N(J,{color:"blue",children:"https://console.anthropic.com/settings/keys"})]})}),N($,{children:N(J,{color:"green",children:"Press Enter to continue..."})})]});let y=o??c;return n==="input"?le($,{flexDirection:"column",paddingY:1,children:[N($,{marginBottom:1,children:N(J,{bold:!0,children:"Enter your Anthropic API key:"})}),y&&N($,{marginBottom:1,children:le(J,{color:"red",children:["\u26A0 ",y]})}),le($,{children:[N(J,{dimColor:!0,children:"> "}),N(Hn,{placeholder:"sk-ant-...",onChange:a,onSubmit:m})]}),N($,{marginTop:1,children:N(J,{dimColor:!0,children:"Your key will be stored securely in your system keyring."})})]}):n==="saving"?N($,{flexDirection:"column",paddingY:1,children:N($,{children:N(J,{color:"yellow",children:"\u23F3 Saving API key..."})})}):le($,{flexDirection:"column",paddingY:1,children:[N($,{children:N(J,{color:"green",children:"\u2713 API key saved successfully!"})}),N($,{marginTop:1,children:le(J,{children:["Starting ",Ce,"..."]})})]})}import{Box as Ze,Text as Et}from"ink";import{jsx as Ke,jsxs as oo}from"react/jsx-runtime";function no({lines:e,command:t}){return oo(Ze,{flexDirection:"column",marginY:1,children:[Ke(Ze,{marginBottom:1,children:oo(Et,{dimColor:!0,children:["$ ",t]})}),Ke(Ze,{flexDirection:"column",children:e.map((o,n)=>{let i=o.startsWith("[ERR]");return Ke(Et,{color:i?"red":void 0,children:i?o.slice(6):o},n)})}),Ke(Ze,{marginTop:1,children:Ke(Et,{color:"yellow",children:"\u23F3 Running..."})})]})}import{Box as Ae,Text as we}from"ink";import{Box as Fn,Text as ce}from"ink";import{Fragment as $n,jsx as Ie,jsxs as et}from"react/jsx-runtime";function vt({command:e,index:t,isSelected:o}){return et(Fn,{children:[Ie(ce,{color:o?"cyan":"gray",bold:o,children:o?"> ":" "}),et(ce,{color:o?"cyan":"blue",bold:o,children:["[",t+1,"]"]}),Ie(ce,{children:" "}),et(ce,{color:o?"white":"gray",bold:o,children:["/",e.name]}),Ie(ce,{children:" "}),Ie(ce,{dimColor:!o,children:e.description}),e.shortcut?et($n,{children:[Ie(ce,{children:" "}),Ie(ce,{dimColor:!0,color:"yellow",children:e.shortcut})]}):null]})}import{jsx as te,jsxs as ro}from"react/jsx-runtime";function bt({query:e,filteredCommands:t,selectedIndex:o,visible:n}){return n?ro(Ae,{flexDirection:"column",borderStyle:"round",borderColor:"blue",paddingX:1,marginTop:1,children:[ro(Ae,{children:[te(we,{color:"blue",bold:!0,children:"/"}),te(we,{color:"white",children:e}),te(we,{color:"cyan",children:"_"})]}),te(Ae,{marginY:0,children:te(we,{dimColor:!0,children:"\u2500".repeat(50)})}),t.length>0?te(Ae,{flexDirection:"column",children:t.slice(0,9).map((i,s)=>te(vt,{command:i,index:s,isSelected:s===o},i.name))}):te(Ae,{children:te(we,{dimColor:!0,children:"No matching commands"})}),te(Ae,{marginTop:1,children:te(we,{dimColor:!0,children:"[Enter] Select [1-9] Quick select [Esc] Close"})})]}):null}import{Box as ue,Text as Te}from"ink";import Us from"chalk";function Yn(e){let t=[],o=e.split(/(\s+)/);for(let n of o)if(n){if(/^\s+$/.test(n)){t.push({type:"default",value:n});continue}if(/^[|><&;]+$/.test(n)||n==="&&"||n==="||"){t.push({type:"pipe",value:n});continue}if(/^-{1,2}[\w-]+=?/.test(n)){t.push({type:"flag",value:n});continue}if(/^\$[\w{}]+/.test(n)){t.push({type:"variable",value:n});continue}if(/^["'].*["']$/.test(n)){t.push({type:"string",value:n});continue}if(n.includes("/")||n.includes("\\")){t.push({type:"path",value:n});continue}if(eo.includes(n.toLowerCase())){t.push({type:"keyword",value:n});continue}t.push({type:"default",value:n})}return t}function so(e){return Yn(e).map(o=>{switch(o.type){case"keyword":return{text:o.value,color:"cyan",bold:!0};case"flag":return{text:o.value,color:"yellow"};case"string":return{text:o.value,color:"green"};case"pipe":return{text:o.value,color:"magenta"};case"path":return{text:o.value,color:"blue"};case"variable":return{text:o.value,color:"cyan"};default:return{text:o.value}}})}import{jsx as X,jsxs as Ue}from"react/jsx-runtime";function io({command:e}){let t=so(e);return X(Te,{children:t.map((o,n)=>X(Te,{color:o.color,bold:o.bold,children:o.text},n))})}function ao({proposal:e,showExplanation:t=!1}){return Ue(ue,{flexDirection:"column",children:[X(ue,{borderStyle:"round",borderColor:"gray",paddingX:2,paddingY:1,children:X(io,{command:e.command})}),t&&e.explanation&&X(ue,{marginTop:1,paddingX:1,children:X(Te,{dimColor:!0,children:e.explanation})})]})}function Gn({command:e,index:t,selected:o=!1}){return Ue(ue,{children:[Ue(Te,{color:o?"cyan":"blue",bold:o,children:["[",t+1,"]"]}),X(Te,{children:" "}),X(io,{command:e})]})}function lo({proposals:e,selectedIndex:t=-1}){return Ue(ue,{flexDirection:"column",marginY:1,children:[X(ue,{marginBottom:1,children:X(Te,{bold:!0,children:"Alternative commands:"})}),e.map((o,n)=>X(ue,{marginBottom:1,children:X(Gn,{command:o.command,index:n,selected:n===t})},n)),X(ue,{marginTop:1,children:Ue(Te,{dimColor:!0,children:["Press 1-",e.length," to select, or [5] Cancel"]})})]})}import{Box as He,Text as oe}from"ink";import{Fragment as jn,jsx as se,jsxs as Se}from"react/jsx-runtime";function Pt({hasApiKey:e,storageMethod:t,storageDescription:o,isSecure:n,maskedKey:i,isSectionActive:s,focusedIndex:a}){return Se(He,{flexDirection:"column",children:[Se(He,{children:[se(oe,{dimColor:!0,children:"Status: "}),se(oe,{color:e?"green":"red",children:e?"Configured":"Not configured"}),e?Se(jn,{children:[se(oe,{dimColor:!0,children:" ("}),se(oe,{color:n?"green":"yellow",children:o}),se(oe,{dimColor:!0,children:")"})]}):null]}),i?Se(He,{children:[se(oe,{dimColor:!0,children:"Key: "}),se(oe,{color:"gray",children:i})]}):null,Se(He,{marginTop:1,children:[se(oe,{color:s&&a===0?"cyan":"gray",bold:s&&a===0,children:s&&a===0?"> ":" "}),Se(oe,{color:s&&a===0?"cyan":"blue",children:["[",e?"Change API Key":"Set API Key","]"]})]}),e?Se(He,{children:[se(oe,{color:s&&a===1?"cyan":"gray",bold:s&&a===1,children:s&&a===1?"> ":" "}),se(oe,{color:s&&a===1?"red":"gray",children:"[Remove API Key]"})]}):null]})}import{Box as ie,Text as Ee}from"ink";import{Box as tt,Text as It}from"ink";import{jsx as Fe,jsxs as co}from"react/jsx-runtime";function Re({title:e,isActive:t,children:o}){return co(tt,{flexDirection:"column",marginBottom:1,children:[co(tt,{children:[Fe(It,{color:t?"cyan":"white",bold:!0,children:e}),t?Fe(It,{color:"cyan",children:" *"}):null]}),Fe(tt,{children:Fe(It,{dimColor:!0,children:"\u2500".repeat(50)})}),Fe(tt,{flexDirection:"column",paddingLeft:0,children:o})]})}import{Box as uo,Text as $e}from"ink";import{Fragment as qn,jsx as Oe,jsxs as po}from"react/jsx-runtime";function At({options:e,selectedValue:t,focusedIndex:o,isSectionActive:n}){return Oe(uo,{flexDirection:"column",children:e.map((i,s)=>{let a=i.id===t,c=n&&s===o;return po(uo,{children:[Oe($e,{color:c?"cyan":"gray",bold:c,children:c?"> ":" "}),Oe($e,{color:a?"green":c?"white":"gray",children:a?"(*) ":"( ) "}),Oe($e,{color:c?"white":"gray",bold:a,children:i.name}),i.description?po(qn,{children:[Oe($e,{dimColor:!0,children:" - "}),Oe($e,{dimColor:!0,children:i.description})]}):null]},i.id)})})}import{Box as Xn,Text as ot}from"ink";import{jsx as nt,jsxs as Wn}from"react/jsx-runtime";function Be({label:e,value:t,isSelected:o}){return Wn(Xn,{children:[nt(ot,{color:o?"cyan":"gray",bold:o,children:o?"> ":" "}),nt(ot,{color:t?"green":"gray",children:t?"[x]":"[ ]"}),nt(ot,{children:" "}),nt(ot,{color:o?"white":"gray",children:e})]})}import{jsx as K,jsxs as pe}from"react/jsx-runtime";var mo=["api-key","model","toggles","about"];function wt({visible:e,activeSection:t,sectionItemIndex:o,config:n,hasApiKey:i,storageInfo:s,maskedKey:a,toggles:c}){if(!e)return null;let g=mo.indexOf(t);return pe(ie,{flexDirection:"column",borderStyle:"round",borderColor:"blue",paddingX:2,paddingY:1,children:[pe(ie,{justifyContent:"space-between",marginBottom:1,children:[K(ie,{children:K(Ee,{color:"cyan",bold:!0,children:"Settings"})}),K(ie,{children:K(Ee,{dimColor:!0,children:"[Esc] Close [Tab] Section [Enter] Select"})})]}),K(Re,{title:"API Key",isActive:t==="api-key",children:K(Pt,{hasApiKey:i,storageMethod:s.method,storageDescription:s.description,isSecure:s.secure,maskedKey:a,isSectionActive:t==="api-key",focusedIndex:o})}),K(Re,{title:"Model",isActive:t==="model",children:K(At,{options:gt,selectedValue:n.model,focusedIndex:o,isSectionActive:t==="model"})}),pe(Re,{title:"Options",isActive:t==="toggles",children:[K(Be,{label:"Context (pass history to AI)",value:c.contextEnabled,isSelected:t==="toggles"&&o===0}),K(Be,{label:"Show explanations",value:c.showExplanations,isSelected:t==="toggles"&&o===1}),K(Be,{label:"Syntax highlighting",value:c.syntaxHighlighting,isSelected:t==="toggles"&&o===2}),K(Be,{label:"Simple mode",value:c.simpleMode,isSelected:t==="toggles"&&o===3})]}),K(Re,{title:"About",isActive:t==="about",children:pe(ie,{flexDirection:"column",children:[pe(ie,{children:[K(Ee,{dimColor:!0,children:"Version: "}),pe(Ee,{children:["CLI AI v",ee]})]}),pe(ie,{children:[K(Ee,{dimColor:!0,children:"Storage: "}),K(Ee,{color:s.secure?"green":"yellow",children:s.description})]})]})}),K(ie,{marginTop:1,justifyContent:"center",children:mo.map((m,y)=>K(ie,{marginX:1,children:pe(Ee,{color:y===g?"cyan":"gray",children:[y===g?"[":" ",y+1,y===g?"]":" "]})},m))})]})}import{Box as D,Text as Y}from"ink";import{jsx as P,jsxs as W}from"react/jsx-runtime";var Qn=[{key:"/",description:"Open command palette"},{key:"Enter",description:"Submit query"},{key:"Ctrl+D",description:"Exit (when input is empty)"},{key:"O",description:"Toggle output expansion (when input is empty)"}],Vn=[{key:"1 / Enter",description:"Execute command"},{key:"2",description:"Copy to clipboard"},{key:"3",description:"Edit command"},{key:"4",description:"Show alternatives"},{key:"5 / Esc",description:"Cancel"},{key:"?",description:"Explain command"},{key:"O",description:"Toggle output"}],zn=[{key:"Up/Down",description:"Navigate commands"},{key:"Enter",description:"Select command"},{key:"Esc",description:"Close palette"},{key:"1-9",description:"Quick select"}],Jn=[{key:"Tab",description:"Next section"},{key:"Shift+Tab",description:"Previous section"},{key:"Up/Down",description:"Navigate items"},{key:"Enter/Space",description:"Toggle/Select"},{key:"Esc",description:"Close panel"}];function rt({title:e,shortcuts:t}){return W(D,{flexDirection:"column",marginBottom:1,children:[P(Y,{color:"yellow",bold:!0,children:e}),t.map(o=>W(D,{children:[P(D,{width:16,children:P(Y,{color:"cyan",children:o.key})}),P(Y,{dimColor:!0,children:o.description})]},o.key))]})}function Rt({visible:e}){return e?W(D,{flexDirection:"column",borderStyle:"round",borderColor:"blue",paddingX:2,paddingY:1,children:[W(D,{justifyContent:"space-between",marginBottom:1,children:[P(D,{children:W(Y,{color:"cyan",bold:!0,children:["Help - ",Ce," v",ee]})}),P(D,{children:P(Y,{dimColor:!0,children:"[Esc] Close"})})]}),P(D,{marginBottom:1,children:P(Y,{children:"Natural language to shell command translator. Describe what you want in plain English and get executable commands."})}),W(D,{children:[W(D,{flexDirection:"column",marginRight:4,children:[P(rt,{title:"Input Mode",shortcuts:Qn}),P(rt,{title:"Command Palette",shortcuts:zn})]}),W(D,{flexDirection:"column",children:[P(rt,{title:"Proposal Mode",shortcuts:Vn}),P(rt,{title:"Config Panel",shortcuts:Jn})]})]}),W(D,{flexDirection:"column",marginTop:1,children:[P(Y,{color:"yellow",bold:!0,children:"Available Commands"}),W(D,{children:[P(D,{width:16,children:P(Y,{color:"cyan",children:"/config"})}),P(Y,{dimColor:!0,children:"Open settings panel"})]}),W(D,{children:[P(D,{width:16,children:P(Y,{color:"cyan",children:"/help"})}),P(Y,{dimColor:!0,children:"Show this help"})]}),W(D,{children:[P(D,{width:16,children:P(Y,{color:"cyan",children:"/clear"})}),P(Y,{dimColor:!0,children:"Clear command history"})]}),W(D,{children:[P(D,{width:16,children:P(Y,{color:"cyan",children:"/exit"})}),P(Y,{dimColor:!0,children:"Exit application"})]})]})]}):null}import{Box as st,Text as Ge}from"ink";import{Text as Zn}from"ink";import Ye from"chalk";import{useMemo as fo}from"react";import{jsx as tr}from"react/jsx-runtime";var Ot=Ye.inverse(" ");function go({value:e,cursorOffset:t,placeholder:o="",isDisabled:n=!1}){let i=fo(()=>n?o?Ye.dim(o):"":o&&o.length>0?Ye.inverse(o[0])+Ye.dim(o.slice(1)):Ot,[n,o]),s=fo(()=>{if(n)return e;let a=0,c=e.length>0?"":Ot;for(let g of e)c+=a===t?Ye.inverse(g):g,a++;return e.length>0&&t===e.length&&(c+=Ot),c},[n,e,t]);return tr(Zn,{children:e.length>0?s:i})}var er={value:"",cursorOffset:0};function xo(e=""){return{value:e,cursorOffset:e.length}}function yo(e,t){switch(t.type){case"insert":return{value:e.value.slice(0,e.cursorOffset)+t.text+e.value.slice(e.cursorOffset),cursorOffset:e.cursorOffset+t.text.length};case"delete":{if(e.cursorOffset===0)return e;let o=e.cursorOffset-1;return{value:e.value.slice(0,o)+e.value.slice(o+1),cursorOffset:o}}case"move-left":return{...e,cursorOffset:Math.max(0,e.cursorOffset-1)};case"move-right":return{...e,cursorOffset:Math.min(e.value.length,e.cursorOffset+1)};case"clear":return er;case"set":return{value:t.value,cursorOffset:t.value.length};default:return e}}import{jsx as Ne,jsxs as it}from"react/jsx-runtime";function Co({textState:e,placeholder:t="Describe what you want to do...",disabled:o=!1,hasHistory:n=!1,visible:i=!0}){return i?o?it(st,{children:[Ne(Ge,{dimColor:!0,children:"> "}),Ne(Ge,{dimColor:!0,children:e.value||"..."})]}):it(st,{flexDirection:"column",children:[it(st,{children:[Ne(Ge,{color:"green",bold:!0,children:"> "}),Ne(go,{value:e.value,cursorOffset:e.cursorOffset,placeholder:t,isDisabled:o})]}),n&&Ne(st,{marginTop:1,children:it(Ge,{dimColor:!0,children:[Ne(Ge,{color:"blue",children:"[O]"})," Toggle output"]})})]}):null}import{Box as je,Text as ne}from"ink";import{jsx as de,jsxs as me}from"react/jsx-runtime";var or=[{key:"1",label:"Execute"},{key:"2",label:"Copy"},{key:"3",label:"Edit"},{key:"4",label:"Alternatives"},{key:"5",label:"Cancel"}];function ho({focusedIndex:e,showExplain:t=!0,visible:o=!0}){return o?me(je,{flexDirection:"column",marginTop:1,children:[de(je,{flexDirection:"row",gap:1,children:or.map((n,i)=>{let s=i===e;return me(je,{children:[me(ne,{color:s?"cyan":"blue",bold:s,inverse:s,children:["[",n.key,"]"]}),me(ne,{color:s?"cyan":void 0,bold:s,children:[" ",n.label]})]},n.key)})}),t&&de(je,{marginTop:1,children:me(ne,{dimColor:!0,children:[de(ne,{color:"blue",children:"[?]"})," Explain"," ",de(ne,{color:"blue",children:"[O]"})," Toggle output"," ",de(ne,{dimColor:!0,children:"| \u2190\u2192 Navigate, Enter Select"})]})})]}):null}function To({count:e,focusedIndex:t,visible:o=!0}){return o?de(je,{children:me(ne,{dimColor:!0,children:["Press ",me(ne,{color:"blue",children:["1-",e]})," or ",de(ne,{color:"blue",children:"\u2191\u2193"})," to select,"," ",de(ne,{color:"blue",children:"[5]"})," Cancel",t>=0&&me(ne,{color:"cyan",children:[" (focused: ",t+1,")"]})]})}):null}import{Box as Bt,Text as nr}from"ink";import{Spinner as rr}from"@inkjs/ui";import{jsx as Nt,jsxs as So}from"react/jsx-runtime";function Dt({query:e,label:t="Thinking..."}){return So(Bt,{flexDirection:"column",marginY:1,children:[Nt(Bt,{children:Nt(rr,{label:t})}),e&&Nt(Bt,{marginTop:1,children:So(nr,{dimColor:!0,children:["Query: ",e]})})]})}import{Box as Q,Text as H}from"ink";import{homedir as sr,userInfo as ir}from"os";import{jsx as U,jsxs as Z}from"react/jsx-runtime";var ar=[" \u256D\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256E "," \u2502 \u25B6 _ \u2502 "," \u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256F "];function Eo({shell:e,cwd:t,model:o}){let n=ir().username||"user",i=t.replace(sr(),"~"),s=o||"claude-sonnet-4-5";return Z(Q,{flexDirection:"column",borderStyle:"round",borderColor:"cyan",paddingX:2,paddingY:1,marginBottom:1,children:[Z(Q,{marginBottom:1,children:[U(H,{color:"cyan",bold:!0,children:Ce}),Z(H,{dimColor:!0,children:[" v",ee]})]}),Z(Q,{children:[Z(Q,{flexDirection:"column",marginRight:4,children:[Z(Q,{marginBottom:1,children:[U(H,{children:"Welcome, "}),U(H,{color:"yellow",bold:!0,children:n}),U(H,{children:"!"})]}),U(Q,{flexDirection:"column",children:ar.map((a,c)=>U(H,{color:"cyan",children:a},c))}),Z(Q,{marginTop:1,flexDirection:"column",children:[Z(Q,{children:[U(H,{dimColor:!0,children:"Shell: "}),U(H,{color:"green",children:e})]}),Z(Q,{children:[U(H,{dimColor:!0,children:"Path: "}),U(H,{children:i})]})]})]}),Z(Q,{flexDirection:"column",borderStyle:"single",borderColor:"gray",borderLeft:!0,borderRight:!1,borderTop:!1,borderBottom:!1,paddingLeft:2,children:[U(Q,{marginBottom:1,children:U(H,{color:"yellow",bold:!0,children:"Quick Start"})}),Z(Q,{flexDirection:"column",children:[U(H,{dimColor:!0,children:"Describe what you want in natural language:"}),U(H,{color:"gray",italic:!0,children:' "list all files modified today"'}),U(H,{color:"gray",italic:!0,children:' "find large files over 100MB"'}),U(H,{color:"gray",italic:!0,children:' "show git status"'})]}),Z(Q,{marginTop:1,flexDirection:"column",children:[U(H,{dimColor:!0,children:"Model: "}),U(H,{color:"magenta",children:s.split("-").slice(0,2).join(" ")})]})]})]})]})}import{useCallback as pt,useRef as Mo,useState as Rr}from"react";import{readdirSync as lr,statSync as cr}from"fs";import{join as ur,relative as pr}from"path";var mr=new Set(["node_modules",".git",".next","dist","build","__pycache__",".venv","venv",".idea",".vscode","coverage",".cache",".npm",".yarn",".pnpm",".turbo",".nuxt",".output","target","vendor",".angular",".svelte-kit"]),dr=new Set([".DS_Store","Thumbs.db",".gitignore",".npmrc",".yarnrc","pnpm-lock.yaml","package-lock.json","yarn.lock"]),fr=3,gr=20;function vo(e,t=0){if(t>=fr)return[];try{let o=lr(e),n=[],i=0;for(let s of o){if(i>=gr){n.push({name:`... (${o.length-i} more)`,isDirectory:!1});break}if(s.startsWith(".")&&!s.startsWith(".env")||dr.has(s))continue;let a=ur(e,s);try{if(cr(a).isDirectory()){if(mr.has(s))continue;let g=vo(a,t+1);n.push({name:s,isDirectory:!0,children:g.length>0?g:void 0})}else n.push({name:s,isDirectory:!1});i++}catch{continue}}return n}catch{return[]}}function bo(e,t=""){let o=[];return e.forEach((n,i)=>{let s=i===e.length-1,a=s?"\u2514\u2500\u2500 ":"\u251C\u2500\u2500 ",c=s?" ":"\u2502 ";n.isDirectory?(o.push(`${t}${a}${n.name}/`),n.children&&n.children.length>0&&o.push(bo(n.children,`${t}${c}`))):o.push(`${t}${a}${n.name}`)}),o.join(`
|
|
3
|
-
`)}function
|
|
4
|
-
${
|
|
1
|
+
var Hn=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,o)=>(typeof require<"u"?require:t)[o]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});import{render as Wr}from"ink";var yt=[{id:"claude-sonnet-4-5",name:"Claude Sonnet 4.5",description:"Fast and capable"},{id:"claude-opus-4-5",name:"Claude Opus 4.5",description:"Most capable"},{id:"claude-haiku-4-5",name:"Claude Haiku 4.5",description:"Fastest"}];function Ct(e,t){let o=e.toLowerCase(),n=t.toLowerCase();if(n.startsWith(o))return 100+(100-n.length);if(n.includes(o))return 50+(50-n.indexOf(o));let i=0,s=0;for(let a=0;a<n.length&&s<o.length;a++)n[a]===o[s]&&(i+=10,s++);return s===o.length?i:0}function Fn(e,t){let o=Ct(e,t.name),n=Ct(e,t.description),i=(t.aliases??[]).map(s=>Ct(e,s));return Math.max(o,n,...i)}function Xt(){let e=[],t=new Map;function o(){t.clear();for(let n of e){t.set(n.name.toLowerCase(),n);for(let i of n.aliases??[])t.set(i.toLowerCase(),n)}}return{get commands(){return e},get(n){return t.get(n.toLowerCase())},filter(n){return n?e.map(s=>({cmd:s,score:Fn(n,s)})).filter(({score:s})=>s>0).sort((s,a)=>a.score-s.score).map(({cmd:s})=>s):[...e]},register(n){t.get(n.name.toLowerCase())||(e.push(n),o())}}}var z=Xt();var ht={name:"clear",description:"Clear conversation history",category:"session",aliases:["cls"],execute:()=>({type:"navigate",to:"clear"}),isAvailable:e=>e==="input"};var Tt={name:"config",description:"Open settings and configuration panel",category:"settings",aliases:["settings","preferences","prefs"],shortcut:"Ctrl+,",execute:()=>({type:"panel",panel:"config"}),isAvailable:e=>e==="input"};var St={name:"exit",description:"Exit the application",category:"session",aliases:["quit","q"],execute:()=>({type:"exit"}),isAvailable:()=>!0};var Et={name:"help",description:"Show help and keyboard shortcuts",category:"help",aliases:["h","?"],execute:()=>({type:"panel",panel:"help"}),isAvailable:()=>!0};z.register(Tt);z.register(Et);z.register(ht);z.register(St);var ee="3.0.4",Ce="CLI AI",Wt="cli-ai",Qt="anthropic",Vt=".cli_ai_assistant",_e="claude-sonnet-4-5",he={model:_e,maxHistoryEntries:5,maxOutputLines:10,maxAlternatives:3,contextEnabled:!0},zt=500,Jt=10,Zt=["rm -rf","sudo rm","chmod 777","mkfs","dd if=","> /dev/","format","del /f","rmdir /s","DROP TABLE","DELETE FROM","--no-preserve-root",":(){:|:&};:","| sh","| bash","curl | bash","wget | bash","eval","sudo su","passwd","chown -R","> /etc/","fdisk","wipefs","shred"],eo=["rm ","mv ","cp ","sudo ","npm install","pnpm install","yarn add","pip install","brew install","apt install","apt-get install","pacman -S","chmod ","chown ","git push","git reset","git rebase","docker ","kubectl ","systemctl ","service ","kill ","pkill "],to=["sudo","rm","git","npm","pnpm","yarn","docker","kubectl","pip","python","node","npx","cd","ls","cat","grep","find","mkdir","touch","mv","cp","echo","curl","wget","ssh","scp"],Je=500,Me={maxAttempts:3,baseDelayMs:1e3,maxDelayMs:5e3};import{Box as $,Text as J,useInput as $n}from"ink";import{useState as vt}from"react";import{TextInput as Yn}from"@inkjs/ui";import{jsx as N,jsxs as le}from"react/jsx-runtime";function oo({onComplete:e,onError:t,error:o}){let[n,i]=vt("welcome"),[s,a]=vt(""),[c,g]=vt(null);$n((d,u)=>{n==="welcome"&&(u.return||d===" ")&&i("input")},{isActive:n==="welcome"});let m=d=>{let u=d.trim();if(!u){g("API key cannot be empty");return}if(!u.startsWith("sk-ant-")){g('Invalid key format. Anthropic API keys start with "sk-ant-"');return}if(u.length<20){g("API key seems too short");return}g(null),i("saving"),e(u)};if(n==="welcome")return le($,{flexDirection:"column",paddingY:1,children:[N($,{marginBottom:1,children:le(J,{bold:!0,color:"cyan",children:[Ce," v",ee]})}),N($,{marginBottom:1,children:N(J,{children:"Welcome! This tool translates natural language into shell commands."})}),N($,{marginBottom:1,children:le(J,{dimColor:!0,children:["To get started, you'll need an Anthropic API key.",`
|
|
2
|
+
`,"Get one at: ",N(J,{color:"blue",children:"https://console.anthropic.com/settings/keys"})]})}),N($,{children:N(J,{color:"green",children:"Press Enter to continue..."})})]});let y=o??c;return n==="input"?le($,{flexDirection:"column",paddingY:1,children:[N($,{marginBottom:1,children:N(J,{bold:!0,children:"Enter your Anthropic API key:"})}),y&&N($,{marginBottom:1,children:le(J,{color:"red",children:["\u26A0 ",y]})}),le($,{children:[N(J,{dimColor:!0,children:"> "}),N(Yn,{placeholder:"sk-ant-...",onChange:a,onSubmit:m})]}),N($,{marginTop:1,children:N(J,{color:"yellow",children:"\u{1F512} Your key is stored securely on this machine using your system's credential manager (never sent anywhere except Anthropic's API)."})})]}):n==="saving"?N($,{flexDirection:"column",paddingY:1,children:N($,{children:N(J,{color:"yellow",children:"\u23F3 Saving API key..."})})}):le($,{flexDirection:"column",paddingY:1,children:[N($,{children:N(J,{color:"green",children:"\u2713 API key saved successfully!"})}),N($,{marginTop:1,children:le(J,{children:["Starting ",Ce,"..."]})})]})}import{Box as Ze,Text as bt}from"ink";import{jsx as Ke,jsxs as no}from"react/jsx-runtime";function ro({lines:e,command:t}){return no(Ze,{flexDirection:"column",marginY:1,children:[Ke(Ze,{marginBottom:1,children:no(bt,{dimColor:!0,children:["$ ",t]})}),Ke(Ze,{flexDirection:"column",children:e.map((o,n)=>{let i=o.startsWith("[ERR]");return Ke(bt,{color:i?"red":void 0,children:i?o.slice(6):o},n)})}),Ke(Ze,{marginTop:1,children:Ke(bt,{color:"yellow",children:"\u23F3 Running..."})})]})}import{Box as Ae,Text as we}from"ink";import{Box as Gn,Text as ce}from"ink";import{Fragment as jn,jsx as Ie,jsxs as et}from"react/jsx-runtime";function Pt({command:e,index:t,isSelected:o}){return et(Gn,{children:[Ie(ce,{color:o?"cyan":"gray",bold:o,children:o?"> ":" "}),et(ce,{color:o?"cyan":"blue",bold:o,children:["[",t+1,"]"]}),Ie(ce,{children:" "}),et(ce,{color:o?"white":"gray",bold:o,children:["/",e.name]}),Ie(ce,{children:" "}),Ie(ce,{dimColor:!o,children:e.description}),e.shortcut?et(jn,{children:[Ie(ce,{children:" "}),Ie(ce,{dimColor:!0,color:"yellow",children:e.shortcut})]}):null]})}import{jsx as te,jsxs as so}from"react/jsx-runtime";function It({query:e,filteredCommands:t,selectedIndex:o,visible:n}){return n?so(Ae,{flexDirection:"column",borderStyle:"round",borderColor:"blue",paddingX:1,marginTop:1,children:[so(Ae,{children:[te(we,{color:"blue",bold:!0,children:"/"}),te(we,{color:"white",children:e}),te(we,{color:"cyan",children:"_"})]}),te(Ae,{marginY:0,children:te(we,{dimColor:!0,children:"\u2500".repeat(50)})}),t.length>0?te(Ae,{flexDirection:"column",children:t.slice(0,9).map((i,s)=>te(Pt,{command:i,index:s,isSelected:s===o},i.name))}):te(Ae,{children:te(we,{dimColor:!0,children:"No matching commands"})}),te(Ae,{marginTop:1,children:te(we,{dimColor:!0,children:"[Enter] Select [1-9] Quick select [Esc] Close"})})]}):null}import{Box as ue,Text as Te}from"ink";import Ys from"chalk";function qn(e){let t=[],o=e.split(/(\s+)/);for(let n of o)if(n){if(/^\s+$/.test(n)){t.push({type:"default",value:n});continue}if(/^[|><&;]+$/.test(n)||n==="&&"||n==="||"){t.push({type:"pipe",value:n});continue}if(/^-{1,2}[\w-]+=?/.test(n)){t.push({type:"flag",value:n});continue}if(/^\$[\w{}]+/.test(n)){t.push({type:"variable",value:n});continue}if(/^["'].*["']$/.test(n)){t.push({type:"string",value:n});continue}if(n.includes("/")||n.includes("\\")){t.push({type:"path",value:n});continue}if(to.includes(n.toLowerCase())){t.push({type:"keyword",value:n});continue}t.push({type:"default",value:n})}return t}function io(e){return qn(e).map(o=>{switch(o.type){case"keyword":return{text:o.value,color:"cyan",bold:!0};case"flag":return{text:o.value,color:"yellow"};case"string":return{text:o.value,color:"green"};case"pipe":return{text:o.value,color:"magenta"};case"path":return{text:o.value,color:"blue"};case"variable":return{text:o.value,color:"cyan"};default:return{text:o.value}}})}import{jsx as X,jsxs as Ue}from"react/jsx-runtime";function ao({command:e}){let t=io(e);return X(Te,{children:t.map((o,n)=>X(Te,{color:o.color,bold:o.bold,children:o.text},n))})}function lo({proposal:e,showExplanation:t=!1}){return Ue(ue,{flexDirection:"column",children:[X(ue,{borderStyle:"round",borderColor:"gray",paddingX:2,paddingY:1,children:X(ao,{command:e.command})}),t&&e.explanation&&X(ue,{marginTop:1,paddingX:1,children:X(Te,{dimColor:!0,children:e.explanation})})]})}function Xn({command:e,index:t,selected:o=!1}){return Ue(ue,{children:[Ue(Te,{color:o?"cyan":"blue",bold:o,children:["[",t+1,"]"]}),X(Te,{children:" "}),X(ao,{command:e})]})}function co({proposals:e,selectedIndex:t=-1}){return Ue(ue,{flexDirection:"column",marginY:1,children:[X(ue,{marginBottom:1,children:X(Te,{bold:!0,children:"Alternative commands:"})}),e.map((o,n)=>X(ue,{marginBottom:1,children:X(Xn,{command:o.command,index:n,selected:n===t})},n)),X(ue,{marginTop:1,children:Ue(Te,{dimColor:!0,children:["Press 1-",e.length," to select, or [5] Cancel"]})})]})}import{Box as He,Text as oe}from"ink";import{Fragment as Wn,jsx as se,jsxs as Se}from"react/jsx-runtime";function At({hasApiKey:e,storageMethod:t,storageDescription:o,isSecure:n,maskedKey:i,isSectionActive:s,focusedIndex:a}){return Se(He,{flexDirection:"column",children:[Se(He,{children:[se(oe,{dimColor:!0,children:"Status: "}),se(oe,{color:e?"green":"red",children:e?"Configured":"Not configured"}),e?Se(Wn,{children:[se(oe,{dimColor:!0,children:" ("}),se(oe,{color:n?"green":"yellow",children:o}),se(oe,{dimColor:!0,children:")"})]}):null]}),i?Se(He,{children:[se(oe,{dimColor:!0,children:"Key: "}),se(oe,{color:"gray",children:i})]}):null,Se(He,{marginTop:1,children:[se(oe,{color:s&&a===0?"cyan":"gray",bold:s&&a===0,children:s&&a===0?"> ":" "}),Se(oe,{color:s&&a===0?"cyan":"blue",children:["[",e?"Change API Key":"Set API Key","]"]})]}),e?Se(He,{children:[se(oe,{color:s&&a===1?"cyan":"gray",bold:s&&a===1,children:s&&a===1?"> ":" "}),se(oe,{color:s&&a===1?"red":"gray",children:"[Remove API Key]"})]}):null]})}import{Box as ie,Text as Ee}from"ink";import{Box as tt,Text as wt}from"ink";import{jsx as Fe,jsxs as uo}from"react/jsx-runtime";function Re({title:e,isActive:t,children:o}){return uo(tt,{flexDirection:"column",marginBottom:1,children:[uo(tt,{children:[Fe(wt,{color:t?"cyan":"white",bold:!0,children:e}),t?Fe(wt,{color:"cyan",children:" *"}):null]}),Fe(tt,{children:Fe(wt,{dimColor:!0,children:"\u2500".repeat(50)})}),Fe(tt,{flexDirection:"column",paddingLeft:0,children:o})]})}import{Box as po,Text as $e}from"ink";import{Fragment as Qn,jsx as Oe,jsxs as mo}from"react/jsx-runtime";function Rt({options:e,selectedValue:t,focusedIndex:o,isSectionActive:n}){return Oe(po,{flexDirection:"column",children:e.map((i,s)=>{let a=i.id===t,c=n&&s===o;return mo(po,{children:[Oe($e,{color:c?"cyan":"gray",bold:c,children:c?"> ":" "}),Oe($e,{color:a?"green":c?"white":"gray",children:a?"(*) ":"( ) "}),Oe($e,{color:c?"white":"gray",bold:a,children:i.name}),i.description?mo(Qn,{children:[Oe($e,{dimColor:!0,children:" - "}),Oe($e,{dimColor:!0,children:i.description})]}):null]},i.id)})})}import{Box as Vn,Text as ot}from"ink";import{jsx as nt,jsxs as zn}from"react/jsx-runtime";function Be({label:e,value:t,isSelected:o}){return zn(Vn,{children:[nt(ot,{color:o?"cyan":"gray",bold:o,children:o?"> ":" "}),nt(ot,{color:t?"green":"gray",children:t?"[x]":"[ ]"}),nt(ot,{children:" "}),nt(ot,{color:o?"white":"gray",children:e})]})}import{jsx as K,jsxs as pe}from"react/jsx-runtime";var fo=["api-key","model","toggles","about"];function Ot({visible:e,activeSection:t,sectionItemIndex:o,config:n,hasApiKey:i,storageInfo:s,maskedKey:a,toggles:c}){if(!e)return null;let g=fo.indexOf(t);return pe(ie,{flexDirection:"column",borderStyle:"round",borderColor:"blue",paddingX:2,paddingY:1,children:[pe(ie,{justifyContent:"space-between",marginBottom:1,children:[K(ie,{children:K(Ee,{color:"cyan",bold:!0,children:"Settings"})}),K(ie,{children:K(Ee,{dimColor:!0,children:"[Esc] Close [Tab] Section [Enter] Select"})})]}),K(Re,{title:"API Key",isActive:t==="api-key",children:K(At,{hasApiKey:i,storageMethod:s.method,storageDescription:s.description,isSecure:s.secure,maskedKey:a,isSectionActive:t==="api-key",focusedIndex:o})}),K(Re,{title:"Model",isActive:t==="model",children:K(Rt,{options:yt,selectedValue:n.model,focusedIndex:o,isSectionActive:t==="model"})}),pe(Re,{title:"Options",isActive:t==="toggles",children:[K(Be,{label:"Context (pass history to AI)",value:c.contextEnabled,isSelected:t==="toggles"&&o===0}),K(Be,{label:"Show explanations",value:c.showExplanations,isSelected:t==="toggles"&&o===1}),K(Be,{label:"Syntax highlighting",value:c.syntaxHighlighting,isSelected:t==="toggles"&&o===2}),K(Be,{label:"Simple mode",value:c.simpleMode,isSelected:t==="toggles"&&o===3})]}),K(Re,{title:"About",isActive:t==="about",children:pe(ie,{flexDirection:"column",children:[pe(ie,{children:[K(Ee,{dimColor:!0,children:"Version: "}),pe(Ee,{children:["CLI AI v",ee]})]}),pe(ie,{children:[K(Ee,{dimColor:!0,children:"Storage: "}),K(Ee,{color:s.secure?"green":"yellow",children:s.description})]})]})}),K(ie,{marginTop:1,justifyContent:"center",children:fo.map((m,y)=>K(ie,{marginX:1,children:pe(Ee,{color:y===g?"cyan":"gray",children:[y===g?"[":" ",y+1,y===g?"]":" "]})},m))})]})}import{Box as D,Text as Y}from"ink";import{jsx as P,jsxs as W}from"react/jsx-runtime";var Jn=[{key:"/",description:"Open command palette"},{key:"Enter",description:"Submit query"},{key:"Ctrl+D",description:"Exit (when input is empty)"},{key:"O",description:"Toggle output expansion (when input is empty)"}],Zn=[{key:"1 / Enter",description:"Execute command"},{key:"2",description:"Copy to clipboard"},{key:"3",description:"Edit command"},{key:"4",description:"Show alternatives"},{key:"5 / Esc",description:"Cancel"},{key:"?",description:"Explain command"},{key:"O",description:"Toggle output"}],er=[{key:"Up/Down",description:"Navigate commands"},{key:"Enter",description:"Select command"},{key:"Esc",description:"Close palette"},{key:"1-9",description:"Quick select"}],tr=[{key:"Tab",description:"Next section"},{key:"Shift+Tab",description:"Previous section"},{key:"Up/Down",description:"Navigate items"},{key:"Enter/Space",description:"Toggle/Select"},{key:"Esc",description:"Close panel"}];function rt({title:e,shortcuts:t}){return W(D,{flexDirection:"column",marginBottom:1,children:[P(Y,{color:"yellow",bold:!0,children:e}),t.map(o=>W(D,{children:[P(D,{width:16,children:P(Y,{color:"cyan",children:o.key})}),P(Y,{dimColor:!0,children:o.description})]},o.key))]})}function Bt({visible:e}){return e?W(D,{flexDirection:"column",borderStyle:"round",borderColor:"blue",paddingX:2,paddingY:1,children:[W(D,{justifyContent:"space-between",marginBottom:1,children:[P(D,{children:W(Y,{color:"cyan",bold:!0,children:["Help - ",Ce," v",ee]})}),P(D,{children:P(Y,{dimColor:!0,children:"[Esc] Close"})})]}),P(D,{marginBottom:1,children:P(Y,{children:"Natural language to shell command translator. Describe what you want in plain English and get executable commands."})}),W(D,{children:[W(D,{flexDirection:"column",marginRight:4,children:[P(rt,{title:"Input Mode",shortcuts:Jn}),P(rt,{title:"Command Palette",shortcuts:er})]}),W(D,{flexDirection:"column",children:[P(rt,{title:"Proposal Mode",shortcuts:Zn}),P(rt,{title:"Config Panel",shortcuts:tr})]})]}),W(D,{flexDirection:"column",marginTop:1,children:[P(Y,{color:"yellow",bold:!0,children:"Available Commands"}),W(D,{children:[P(D,{width:16,children:P(Y,{color:"cyan",children:"/config"})}),P(Y,{dimColor:!0,children:"Open settings panel"})]}),W(D,{children:[P(D,{width:16,children:P(Y,{color:"cyan",children:"/help"})}),P(Y,{dimColor:!0,children:"Show this help"})]}),W(D,{children:[P(D,{width:16,children:P(Y,{color:"cyan",children:"/clear"})}),P(Y,{dimColor:!0,children:"Clear command history"})]}),W(D,{children:[P(D,{width:16,children:P(Y,{color:"cyan",children:"/exit"})}),P(Y,{dimColor:!0,children:"Exit application"})]})]})]}):null}import{Box as st,Text as Ge}from"ink";import{Text as or}from"ink";import Ye from"chalk";import{useMemo as go}from"react";import{jsx as rr}from"react/jsx-runtime";var Nt=Ye.inverse(" ");function xo({value:e,cursorOffset:t,placeholder:o="",isDisabled:n=!1}){let i=go(()=>n?o?Ye.dim(o):"":o&&o.length>0?Ye.inverse(o[0])+Ye.dim(o.slice(1)):Nt,[n,o]),s=go(()=>{if(n)return e;let a=0,c=e.length>0?"":Nt;for(let g of e)c+=a===t?Ye.inverse(g):g,a++;return e.length>0&&t===e.length&&(c+=Nt),c},[n,e,t]);return rr(or,{children:e.length>0?s:i})}var nr={value:"",cursorOffset:0};function yo(e=""){return{value:e,cursorOffset:e.length}}function Co(e,t){switch(t.type){case"insert":return{value:e.value.slice(0,e.cursorOffset)+t.text+e.value.slice(e.cursorOffset),cursorOffset:e.cursorOffset+t.text.length};case"delete":{if(e.cursorOffset===0)return e;let o=e.cursorOffset-1;return{value:e.value.slice(0,o)+e.value.slice(o+1),cursorOffset:o}}case"move-left":return{...e,cursorOffset:Math.max(0,e.cursorOffset-1)};case"move-right":return{...e,cursorOffset:Math.min(e.value.length,e.cursorOffset+1)};case"clear":return nr;case"set":return{value:t.value,cursorOffset:t.value.length};default:return e}}import{jsx as Ne,jsxs as it}from"react/jsx-runtime";function ho({textState:e,placeholder:t="Describe what you want to do...",disabled:o=!1,hasHistory:n=!1,visible:i=!0}){return i?o?it(st,{children:[Ne(Ge,{dimColor:!0,children:"> "}),Ne(Ge,{dimColor:!0,children:e.value||"..."})]}):it(st,{flexDirection:"column",children:[it(st,{children:[Ne(Ge,{color:"green",bold:!0,children:"> "}),Ne(xo,{value:e.value,cursorOffset:e.cursorOffset,placeholder:t,isDisabled:o})]}),n&&Ne(st,{marginTop:1,children:it(Ge,{dimColor:!0,children:[Ne(Ge,{color:"blue",children:"[O]"})," Toggle output"]})})]}):null}import{Box as je,Text as ne}from"ink";import{jsx as de,jsxs as me}from"react/jsx-runtime";var sr=[{key:"1",label:"Execute"},{key:"2",label:"Copy"},{key:"3",label:"Edit"},{key:"4",label:"Alternatives"},{key:"5",label:"Cancel"}];function To({focusedIndex:e,showExplain:t=!0,visible:o=!0}){return o?me(je,{flexDirection:"column",marginTop:1,children:[de(je,{flexDirection:"row",gap:1,children:sr.map((n,i)=>{let s=i===e;return me(je,{children:[me(ne,{color:s?"cyan":"blue",bold:s,inverse:s,children:["[",n.key,"]"]}),me(ne,{color:s?"cyan":void 0,bold:s,children:[" ",n.label]})]},n.key)})}),t&&de(je,{marginTop:1,children:me(ne,{dimColor:!0,children:[de(ne,{color:"blue",children:"[?]"})," Explain"," ",de(ne,{color:"blue",children:"[O]"})," Toggle output"," ",de(ne,{dimColor:!0,children:"| \u2190\u2192 Navigate, Enter Select"})]})})]}):null}function So({count:e,focusedIndex:t,visible:o=!0}){return o?de(je,{children:me(ne,{dimColor:!0,children:["Press ",me(ne,{color:"blue",children:["1-",e]})," or ",de(ne,{color:"blue",children:"\u2191\u2193"})," to select,"," ",de(ne,{color:"blue",children:"[5]"})," Cancel",t>=0&&me(ne,{color:"cyan",children:[" (focused: ",t+1,")"]})]})}):null}import{Box as Dt,Text as ir}from"ink";import{Spinner as ar}from"@inkjs/ui";import{jsx as Lt,jsxs as Eo}from"react/jsx-runtime";function kt({query:e,label:t="Thinking..."}){return Eo(Dt,{flexDirection:"column",marginY:1,children:[Lt(Dt,{children:Lt(ar,{label:t})}),e&&Lt(Dt,{marginTop:1,children:Eo(ir,{dimColor:!0,children:["Query: ",e]})})]})}import{Box as Q,Text as H}from"ink";import{homedir as lr,userInfo as cr}from"os";import{jsx as U,jsxs as Z}from"react/jsx-runtime";var ur=[" \u256D\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256E "," \u2502 \u25B6 _ \u2502 "," \u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256F "];function vo({shell:e,cwd:t,model:o}){let n=cr().username||"user",i=t.replace(lr(),"~"),s=o||"claude-sonnet-4-5";return Z(Q,{flexDirection:"column",borderStyle:"round",borderColor:"cyan",paddingX:2,paddingY:1,marginBottom:1,children:[Z(Q,{marginBottom:1,children:[U(H,{color:"cyan",bold:!0,children:Ce}),Z(H,{dimColor:!0,children:[" v",ee]})]}),Z(Q,{children:[Z(Q,{flexDirection:"column",marginRight:4,children:[Z(Q,{marginBottom:1,children:[U(H,{children:"Welcome, "}),U(H,{color:"yellow",bold:!0,children:n}),U(H,{children:"!"})]}),U(Q,{flexDirection:"column",children:ur.map((a,c)=>U(H,{color:"cyan",children:a},c))}),Z(Q,{marginTop:1,flexDirection:"column",children:[Z(Q,{children:[U(H,{dimColor:!0,children:"Shell: "}),U(H,{color:"green",children:e})]}),Z(Q,{children:[U(H,{dimColor:!0,children:"Path: "}),U(H,{children:i})]})]})]}),Z(Q,{flexDirection:"column",borderStyle:"single",borderColor:"gray",borderLeft:!0,borderRight:!1,borderTop:!1,borderBottom:!1,paddingLeft:2,children:[U(Q,{marginBottom:1,children:U(H,{color:"yellow",bold:!0,children:"Quick Start"})}),Z(Q,{flexDirection:"column",children:[U(H,{dimColor:!0,children:"Describe what you want in natural language:"}),U(H,{color:"gray",italic:!0,children:' "list all files modified today"'}),U(H,{color:"gray",italic:!0,children:' "find large files over 100MB"'}),U(H,{color:"gray",italic:!0,children:' "show git status"'})]}),Z(Q,{marginTop:1,flexDirection:"column",children:[U(H,{dimColor:!0,children:"Model: "}),U(H,{color:"magenta",children:s.split("-").slice(0,2).join(" ")})]})]})]})]})}import{useCallback as dt,useRef as Uo,useState as Nr}from"react";import{readdirSync as pr,statSync as mr}from"fs";import{join as dr,relative as fr}from"path";var gr=new Set(["node_modules",".git",".next","dist","build","__pycache__",".venv","venv",".idea",".vscode","coverage",".cache",".npm",".yarn",".pnpm",".turbo",".nuxt",".output","target","vendor",".angular",".svelte-kit"]),xr=new Set([".DS_Store","Thumbs.db",".gitignore",".npmrc",".yarnrc","pnpm-lock.yaml","package-lock.json","yarn.lock"]),yr=3,Cr=20;function bo(e,t=0){if(t>=yr)return[];try{let o=pr(e),n=[],i=0;for(let s of o){if(i>=Cr){n.push({name:`... (${o.length-i} more)`,isDirectory:!1});break}if(s.startsWith(".")&&!s.startsWith(".env")||xr.has(s))continue;let a=dr(e,s);try{if(mr(a).isDirectory()){if(gr.has(s))continue;let g=bo(a,t+1);n.push({name:s,isDirectory:!0,children:g.length>0?g:void 0})}else n.push({name:s,isDirectory:!1});i++}catch{continue}}return n}catch{return[]}}function Po(e,t=""){let o=[];return e.forEach((n,i)=>{let s=i===e.length-1,a=s?"\u2514\u2500\u2500 ":"\u251C\u2500\u2500 ",c=s?" ":"\u2502 ";n.isDirectory?(o.push(`${t}${a}${n.name}/`),n.children&&n.children.length>0&&o.push(Po(n.children,`${t}${c}`))):o.push(`${t}${a}${n.name}`)}),o.join(`
|
|
3
|
+
`)}function Io(e){let t=bo(e);return t.length===0?"(empty or inaccessible directory)":`${fr(process.cwd(),e)||"."}/
|
|
4
|
+
${Po(t)}`}function hr(e){let t=e.toLowerCase();for(let o of Zt)if(t.includes(o.toLowerCase()))return"high";for(let o of eo)if(t.includes(o.toLowerCase()))return"medium";return"low"}function _t(e,t){let o=hr(t),n={low:0,medium:1,high:2};return n[e]>=n[o]?e:o}import ct from"conf";import{createHash as Tr}from"crypto";import{existsSync as Ro,unlinkSync as Ao}from"fs";import{hostname as Sr,userInfo as Er}from"os";import{homedir as vr}from"os";import{join as Oo}from"path";var br="cli-ai-v3-encryption-key";function Pr(){let e=`${Sr()}-${Er().username}-cli-ai-v3-salt`;return Tr("sha256").update(e).digest("hex").slice(0,32)}var Xe=Oo(vr(),Vt),ut=Oo(Xe,"config.json");function Ir(){if(!Ro(ut))return null;try{let e=new ct({projectName:"cli-ai",cwd:Xe,encryptionKey:br}),t=e.get("apiKey"),o=e.get("config");if(t||o)return{apiKey:t,config:o}}catch{}return null}function Ar(){let e=Pr(),t=Ir();if(t){try{Ao(ut)}catch{}let o=new ct({projectName:"cli-ai",cwd:Xe,encryptionKey:e});return t.apiKey&&o.set("apiKey",t.apiKey),t.config&&o.set("config",t.config),o}try{return new ct({projectName:"cli-ai",cwd:Xe,encryptionKey:e})}catch{try{Ro(ut)&&Ao(ut)}catch{}return new ct({projectName:"cli-ai",cwd:Xe,encryptionKey:e})}}var fe=Ar(),at=null,wo=!1,qe=null,lt=null;function wr(){if(wo)return at;wo=!0;try{return at=Hn("@napi-rs/keyring"),at}catch{return at=null,null}}function pt(){if(lt===!1)return null;if(qe===null){let e=wr();if(!e)return lt=!1,null;try{qe=new e.Entry(Wt,Qt),qe.getPassword(),lt=!0}catch{return lt=!1,qe=null,null}}return qe}function ge(){let e=process.env.ANTHROPIC_API_KEY;if(e)return e;let t=pt();if(t)try{let o=t.getPassword();if(o)return o}catch{}return fe.get("apiKey")??null}function mt(e){try{let t=pt();if(t)try{return t.setPassword(e),fe.delete("apiKey"),{success:!0,data:void 0}}catch{}return fe.set("apiKey",e),{success:!0,data:void 0}}catch(t){return{success:!1,error:t instanceof Error?t:new Error(String(t))}}}function Bo(){try{let e=pt();if(e)try{e.deleteCredential()}catch{}return fe.delete("apiKey"),{success:!0,data:void 0}}catch(e){return{success:!1,error:e instanceof Error?e:new Error(String(e))}}}function Mt(){let e=ge();return e!==null&&e.length>0}function De(){let e=fe.get("config")??{};return{...he,...e}}function We(e){let t=fe.get("config")??{};fe.set("config",{...t,...e})}function No(e){return e.startsWith("sk-ant-")&&e.length>20}function Do(){if(process.env.ANTHROPIC_API_KEY)return{method:"env",secure:!1,description:"Environment variable (visible to other processes)"};let e=pt();if(e)try{if(e.getPassword())return{method:"keyring",secure:!0,description:"System keyring (OS-protected)"}}catch{}return fe.get("apiKey")?{method:"encrypted-file",secure:!1,description:"Encrypted file (machine-specific key)"}:{method:"none",secure:!1,description:"Not configured"}}import Kt from"@anthropic-ai/sdk";function Lo(e){return`You are a CLI command generator for ${e}.
|
|
5
5
|
You translate natural language requests into shell commands.
|
|
6
6
|
|
|
7
7
|
IMPORTANT: Output ONLY valid JSON, no markdown, no explanation text.
|
|
@@ -17,28 +17,28 @@ Rules:
|
|
|
17
17
|
2. Use appropriate flags for the target shell
|
|
18
18
|
3. Prefer safe alternatives when possible
|
|
19
19
|
4. For destructive operations, include safety flags (-i for interactive, etc.)
|
|
20
|
-
5. Never include placeholder values - ask for specifics if needed`}function
|
|
20
|
+
5. Never include placeholder values - ask for specifics if needed`}function Rr(e,t){if(!e||e.length<=t)return e;let o=e.slice(0,t),n=o.lastIndexOf(`
|
|
21
21
|
`);return n>t*.5?o.slice(0,n)+`
|
|
22
|
-
... (truncated)`:o+"... (truncated)"}function
|
|
22
|
+
... (truncated)`:o+"... (truncated)"}function ko(e,t){let o=[];if(o.push(`Current directory: ${t.cwd}`),o.push(`
|
|
23
23
|
Directory structure:
|
|
24
24
|
${t.directoryTree}`),t.history.length>0){o.push(`
|
|
25
|
-
Conversation context (recent queries and results):`);let n=t.history.slice(-
|
|
26
|
-
Query: "${i.query}"`),o.push(`Command: ${i.command}`),i.exitCode!==void 0&&o.push(`Exit code: ${i.exitCode}`),i.output){let s=
|
|
25
|
+
Conversation context (recent queries and results):`);let n=t.history.slice(-Jt);for(let i of n)if(o.push(`
|
|
26
|
+
Query: "${i.query}"`),o.push(`Command: ${i.command}`),i.exitCode!==void 0&&o.push(`Exit code: ${i.exitCode}`),i.output){let s=Rr(i.output,zt);o.push(`Output:
|
|
27
27
|
${s}`)}}return o.push(`
|
|
28
28
|
User request: ${e}`),o.join(`
|
|
29
|
-
`)}function
|
|
29
|
+
`)}function Or(e){let t=e.match(/\{[\s\S]*\}/);if(!t)throw new Error("No JSON found in AI response");let o=JSON.parse(t[0]);if(!o.command||typeof o.command!="string")throw new Error("Invalid response: missing command");let n=o.risk,i=n&&["low","medium","high"].includes(n)?n:"medium";return{command:o.command.trim(),risk:_t(i,o.command)}}function Br(e){return new Promise(t=>setTimeout(t,e))}async function _o(e,t){let o=ge();if(!o)return{success:!1,error:new Error("No API key configured")};let n=new Kt({apiKey:o}),i=process.env.AI_MODEL??_e;for(let s=0;s<Me.maxAttempts;s++)try{let c=(await n.messages.create({model:i,max_tokens:Je,system:Lo(t.shell),messages:[{role:"user",content:ko(e,t)}]})).content.find(m=>m.type==="text");if(!c||c.type!=="text")throw new Error("No text content in AI response");return{success:!0,data:Or(c.text)}}catch(a){if(s===Me.maxAttempts-1)return{success:!1,error:a instanceof Error?a:new Error(String(a))};let g=Math.min(Me.baseDelayMs*Math.pow(2,s),Me.maxDelayMs);await Br(g)}return{success:!1,error:new Error("Unexpected error in AI request")}}async function Mo(e,t,o,n=3){let i=ge();if(!i)return{success:!1,error:new Error("No API key configured")};let s=new Kt({apiKey:i}),a=process.env.AI_MODEL??_e,c=`${ko(e,t)}
|
|
30
30
|
|
|
31
31
|
Generate ${n} ALTERNATIVE commands (different approaches).
|
|
32
32
|
Exclude: ${o}
|
|
33
33
|
|
|
34
|
-
Output JSON array: [{ "command": "...", "risk": "low|medium|high" }, ...]`;try{let m=(await s.messages.create({model:a,max_tokens:Je*2,system:
|
|
35
|
-
${e}`}]})).content.find(a=>a.type==="text");if(!s||s.type!=="text")throw new Error("No text content in AI response");return{success:!0,data:s.text.trim()}}catch(i){return{success:!1,error:i instanceof Error?i:new Error(String(i))}}}function
|
|
34
|
+
Output JSON array: [{ "command": "...", "risk": "low|medium|high" }, ...]`;try{let m=(await s.messages.create({model:a,max_tokens:Je*2,system:Lo(t.shell),messages:[{role:"user",content:c}]})).content.find(p=>p.type==="text");if(!m||m.type!=="text")throw new Error("No text content in AI response");let y=m.text.match(/\[[\s\S]*\]/);if(!y)throw new Error("No JSON array found in AI response");return{success:!0,data:JSON.parse(y[0]).filter(p=>p.command&&typeof p.command=="string").map(p=>{let r=p.risk,v=r&&["low","medium","high"].includes(r)?r:"medium";return{command:p.command.trim(),risk:_t(v,p.command)}})}}catch(g){return{success:!1,error:g instanceof Error?g:new Error(String(g))}}}async function Ko(e){let t=ge();if(!t)return{success:!1,error:new Error("No API key configured")};let o=new Kt({apiKey:t}),n=process.env.AI_MODEL??_e;try{let s=(await o.messages.create({model:n,max_tokens:Je,messages:[{role:"user",content:`Explain this command briefly (2-3 sentences max):
|
|
35
|
+
${e}`}]})).content.find(a=>a.type==="text");if(!s||s.type!=="text")throw new Error("No text content in AI response");return{success:!0,data:s.text.trim()}}catch(i){return{success:!1,error:i instanceof Error?i:new Error(String(i))}}}function Ut(e,t=[]){let o=process.cwd();return{shell:e,cwd:o,platform:process.platform,directoryTree:Io(o),history:t}}function Ho({shell:e,history:t=[],contextEnabled:o=!0}){let[n,i]=Nr({isLoading:!1,error:null,lastProposal:null}),s=Uo(t);s.current=t;let a=Uo(o);a.current=o;let c=dt(async d=>{i(u=>({...u,isLoading:!0,error:null}));try{let u=a.current?s.current:[],p=Ut(e,u),r=await _o(d,p);return r.success?i(v=>({...v,isLoading:!1,lastProposal:r.data})):i(v=>({...v,isLoading:!1,error:r.error})),r}catch(u){let p=u instanceof Error?u:new Error(String(u));return i(r=>({...r,isLoading:!1,error:p})),{success:!1,error:p}}},[e]),g=dt(async(d,u)=>{i(p=>({...p,isLoading:!0,error:null}));try{let p=a.current?s.current:[],r=Ut(e,p),v=await Mo(d,r,u);return i(S=>({...S,isLoading:!1})),v.success||i(S=>({...S,error:v.error})),v}catch(p){let r=p instanceof Error?p:new Error(String(p));return i(v=>({...v,isLoading:!1,error:r})),{success:!1,error:r}}},[e]),m=dt(async d=>{i(u=>({...u,isLoading:!0,error:null}));try{let u=await Ko(d);return i(p=>({...p,isLoading:!1})),u.success||i(p=>({...p,error:u.error})),u}catch(u){let p=u instanceof Error?u:new Error(String(u));return i(r=>({...r,isLoading:!1,error:p})),{success:!1,error:p}}},[]),y=dt(()=>{i(d=>({...d,error:null}))},[]);return{...n,generate:c,getAlternatives:g,explain:m,clearError:y}}import{useCallback as xe,useMemo as Dr,useState as Fo}from"react";function $o({sessionStatus:e,config:t,updateConfig:o,onOpenConfig:n,onOpenHelp:i,onClearHistory:s,onExit:a}){let[c,g]=Fo(""),[m,y]=Fo(0),d=Dr(()=>z.filter(c).filter(F=>!F.isAvailable||F.isAvailable(e)),[c,e]),u=xe(T=>{g(T),y(0)},[]),p=xe(()=>{y(T=>d.length===0?0:(T-1+d.length)%d.length)},[d.length]),r=xe(()=>{y(T=>d.length===0?0:(T+1)%d.length)},[d.length]),v=xe(()=>({sessionStatus:e,config:t,updateConfig:o,exit:a}),[e,t,o,a]),S=xe(T=>{switch(T.type){case"panel":T.panel==="config"?n():T.panel==="help"&&i();break;case"navigate":T.to==="clear"&&s();break;case"exit":a();break}return T},[n,i,s,a]),V=xe(()=>{if(d.length===0)return null;let T=d[m];if(!T)return null;let F=v(),j=T.execute(F);return j instanceof Promise?(j.then(S),null):S(j)},[d,m,v,S]),L=xe(T=>{let F=z.get(T);if(!F||F.isAvailable&&!F.isAvailable(e))return null;let j=v(),re=F.execute(j);return re instanceof Promise?(re.then(S),null):S(re)},[e,v,S]),G=xe(()=>{g(""),y(0)},[]);return{query:c,setQuery:u,filteredCommands:d,focusedIndex:m,focusUp:p,focusDown:r,executeSelected:V,executeCommand:L,reset:G}}import{useCallback as Ht,useEffect as Lr,useState as kr}from"react";function Yo(){let[e,t]=kr({isLoading:!0,hasKey:!1,config:De(),error:null});Lr(()=>{try{let s=Mt();t(a=>({...a,isLoading:!1,hasKey:s,error:null}))}catch(s){t(a=>({...a,isLoading:!1,error:s instanceof Error?s.message:"Failed to check API key"}))}},[]);let o=Ht(s=>{if(!No(s))return t(a=>({...a,error:'Invalid API key format. Key should start with "sk-ant-"'})),!1;try{let a=mt(s);return a.success?(t(c=>({...c,hasKey:!0,error:null})),!0):(t(c=>({...c,error:a.error.message})),!1)}catch(a){return t(c=>({...c,error:a instanceof Error?a.message:"Failed to save API key"})),!1}},[]),n=Ht(s=>{We(s),t(a=>({...a,config:{...a.config,...s}}))},[]),i=Ht(()=>{try{let s=Mt();t(a=>({...a,hasKey:s,error:null}))}catch(s){t(a=>({...a,error:s instanceof Error?s.message:"Failed to check API key"}))}},[]);return{...e,saveKey:o,updateConfig:n,refreshKeyStatus:i}}import{execa as _r}from"execa";import{useCallback as qo,useRef as Mr,useState as Kr}from"react";function Go(){if(process.platform==="win32")return process.env.MSYSTEM||process.env.MINGW_PREFIX?"bash":process.env.PSModulePath?.includes("PowerShell\\7")?"pwsh":process.env.PSModulePath?"powershell":"cmd";let e=process.env.SHELL??"/bin/bash";return e.includes("zsh")?"zsh":e.includes("fish")?"fish":"bash"}function jo(e,t){switch(e){case"powershell":return{cmd:"powershell",args:["-Command",t]};case"pwsh":return{cmd:"pwsh",args:["-Command",t]};case"cmd":return{cmd:"cmd",args:["/c",t]};default:return{cmd:e,args:["-c",t]}}}function Xo({shell:e,maxOutputLines:t=he.maxOutputLines,onOutput:o,onComplete:n}){let[i,s]=Kr({isExecuting:!1,liveOutput:[],error:null}),a=Mr(null),c=qo(async m=>{s({isExecuting:!0,liveOutput:[],error:null});let{cmd:y,args:d}=jo(e,m);try{let u=_r(y,d,{reject:!1,all:!0,buffer:!0});a.current=u;let p=[];u.stdout&&u.stdout.on("data",S=>{let V=S.toString().split(`
|
|
36
36
|
`).filter(Boolean);for(let L of V)p.push(L),o?.(L,!1),s(G=>({...G,liveOutput:[...G.liveOutput,L].slice(-t)}))}),u.stderr&&u.stderr.on("data",S=>{let V=S.toString().split(`
|
|
37
|
-
`).filter(Boolean);for(let L of V){let G=`[ERR] ${L}`;p.push(G),o?.(L,!0),s(T=>({...T,liveOutput:[...T.liveOutput,G].slice(-t)}))}});let r=await u;a.current=null;let v={command:m,stdout:r.stdout??"",stderr:r.stderr??"",exitCode:r.exitCode??0};return s(S=>({...S,isExecuting:!1})),n?.(v),{success:!0,data:v}}catch(u){a.current=null;let p=u instanceof Error?u:new Error(String(u));s(v=>({...v,isExecuting:!1,error:p}));let r={command:m,stdout:"",stderr:p.message,exitCode:1};return n?.(r),{success:!1,error:p}}},[e,t,o,n]),g=Go(()=>{a.current&&(a.current.kill("SIGINT"),a.current=null,s(m=>({...m,isExecuting:!1,liveOutput:[...m.liveOutput,"[Interrupted]"]})))},[]);return{...i,execute:c,kill:g}}import{useInput as _r}from"ink";import{useCallback as qo,useReducer as Mr,useRef as Xo,useState as Qe}from"react";function Wo({mode:e,menuCallbacks:t,selectionCallbacks:o,textCallbacks:n,paletteCallbacks:i,configCallbacks:s,helpCallbacks:a,initialTextValue:c="",paletteQuery:g=""}){let[m,y]=Mr(yo,xo(c)),[d,u]=Qe(0),[p,r]=Qe(0),[v,S]=Qe(0),[V,L]=Qe(0),[G,T]=Qe(0),F=Xo(c);F.current!==c&&(F.current=c,y({type:"set",value:c}));let j=Xo(e);j.current!==e&&(e==="menu"?u(0):e==="selection"?r(0):e==="palette"?S(0):e==="config"&&(L(0),T(0)),j.current=e);let re=qo(()=>{y({type:"clear"})},[]),R=qo(b=>{y({type:"set",value:b})},[]);return _r((b,f)=>{if(e!=="disabled"){if(e==="text"&&n){if(f.ctrl&&!f.meta&&b==="d"){m.value.trim()===""&&process.exit(130);return}if(f.return){let h=m.value.trim();(h.toLowerCase()==="exit"||h.toLowerCase()==="quit")&&process.exit(0),h&&(n.onSubmit(h),y({type:"clear"}));return}if(b.toLowerCase()==="o"&&m.value.trim()===""&&n.onToggleOutput&&n.hasHistory){n.onToggleOutput();return}if(n.hasInlinePalette&&n.onNavigateInlinePalette){if(f.upArrow){n.onNavigateInlinePalette("up");return}if(f.downArrow){n.onNavigateInlinePalette("down");return}}if(f.leftArrow){y({type:"move-left"});return}if(f.rightArrow){y({type:"move-right"});return}if(f.backspace||f.delete){y({type:"delete"});let h=m.value.slice(0,m.cursorOffset-1)+m.value.slice(m.cursorOffset);n.onTextChange?.(h);return}if(f.escape){n.hasInlinePalette&&n.onCloseInlinePalette&&(n.onCloseInlinePalette(),y({type:"clear"}));return}if(f.ctrl||f.meta||f.tab)return;if(b&&b.length>0){y({type:"insert",text:b});let h=m.value.slice(0,m.cursorOffset)+b+m.value.slice(m.cursorOffset);n.onTextChange?.(h)}return}if(e==="menu"&&t){if(f.leftArrow){u(h=>(h-1+5)%5);return}if(f.rightArrow){u(h=>(h+1)%5);return}if(f.return){switch(["execute","copy","edit","alternatives","cancel"][d]){case"execute":t.onExecute();break;case"copy":t.onCopy();break;case"edit":t.onEdit();break;case"alternatives":t.onAlternatives();break;case"cancel":t.onCancel();break}return}if(b>="1"&&b<="5"){let h=parseInt(b,10)-1;switch(["execute","copy","edit","alternatives","cancel"][h]){case"execute":t.onExecute();break;case"copy":t.onCopy();break;case"edit":t.onEdit();break;case"alternatives":t.onAlternatives();break;case"cancel":t.onCancel();break}return}if(b==="?"){t.onExplain();return}if(b.toLowerCase()==="o"){t.onToggle();return}if(f.escape){t.onCancel();return}return}if(e==="selection"&&o){let h=o.count;if(f.upArrow){r(A=>(A-1+h)%h);return}if(f.downArrow){r(A=>(A+1)%h);return}if(f.return){o.onSelect(p);return}let k=parseInt(b,10);if(k>=1&&k<=h){o.onSelect(k-1);return}if(b==="5"||b.toLowerCase()==="c"||f.escape){o.onCancel();return}return}if(e==="palette"&&i){let h=i.filteredCount;if(f.upArrow){S(A=>h===0?0:(A-1+h)%h),i.onNavigate("up");return}if(f.downArrow){S(A=>h===0?0:(A+1)%h),i.onNavigate("down");return}if(f.return){i.onSelect();return}if(f.escape){i.onClose();return}if((f.backspace||f.delete)&&g===""){i.onClose();return}if(f.backspace||f.delete){let A=g.slice(0,-1);i.onQueryChange(A),S(0);return}if(f.ctrl||f.meta||f.tab)return;let k=parseInt(b,10);if(k>=1&&k<=9&&k<=h){S(k-1),i.onSelect();return}if(b&&b.length>0){let A=g+b;i.onQueryChange(A),S(0)}return}if(e==="config"&&s){let h=s.sectionCount,k=s.itemCount;if(f.tab&&!f.shift){L(A=>(A+1)%h),T(0),s.onNavigateSection("next");return}if(f.tab&&f.shift){L(A=>(A-1+h)%h),T(0),s.onNavigateSection("prev");return}if(f.upArrow){T(A=>k===0?0:(A-1+k)%k),s.onNavigateItem("up");return}if(f.downArrow){T(A=>k===0?0:(A+1)%k),s.onNavigateItem("down");return}if(f.return||b===" "){s.onToggle();return}if(f.escape){s.onClose();return}return}if(e==="help"&&a){if(f.escape){a.onClose();return}return}}},{isActive:e!=="disabled"}),{textState:m,dispatchText:y,clearText:re,setText:R,menuFocusIndex:d,selectionFocusIndex:p,paletteFocusIndex:v,configSectionIndex:V,configItemIndex:G}}import{useCallback as O,useReducer as Kr}from"react";var Ur={state:{status:"setup"},history:[],currentQuery:"",editingCommand:null,outputExpanded:!1,error:null};function Hr(e,t){switch(t.type){case"SETUP_COMPLETE":return{...e,state:{status:"input"},error:null};case"SUBMIT":return{...e,state:{status:"loading",query:t.query},currentQuery:t.query,editingCommand:null,error:null};case"AI_RESPONSE":return{...e,state:{status:"proposal",proposal:t.proposal},error:null};case"AI_ALTERNATIVES":return{...e,state:{status:"alternatives",proposals:t.proposals,originalQuery:e.currentQuery},error:null};case"AI_ERROR":return{...e,state:{status:"input"},error:t.error.message};case"EXECUTE":{let o=e.state;return o.status!=="proposal"?e:{...e,state:{status:"executing",command:o.proposal.command},error:null}}case"EXECUTE_EDITED":return{...e,state:{status:"executing",command:t.command},editingCommand:null,error:null};case"EXEC_DONE":{let o=[...e.history,{query:e.currentQuery,command:t.result.command,output:t.result.stdout||t.result.stderr,exitCode:t.result.exitCode}].slice(-he.maxHistoryEntries);return{...e,state:{status:"input"},history:o,outputExpanded:!1,error:null}}case"COPY":return{...e,state:{status:"input"},error:null};case"EDIT":return{...e,state:{status:"input"},editingCommand:t.command,error:null};case"CANCEL":return{...e,state:{status:"input"},editingCommand:null,error:null};case"TOGGLE_OUTPUT":return e.history.length===0?e:{...e,outputExpanded:!e.outputExpanded};case"OPEN_PALETTE":return{...e,state:{status:"palette",query:"",filteredCommands:[]},error:null};case"UPDATE_PALETTE":return{...e,state:{status:"palette",query:t.query,filteredCommands:t.filteredCommands}};case"CLOSE_PALETTE":return{...e,state:{status:"input"},error:null};case"OPEN_CONFIG":return{...e,state:{status:"config",section:"api-key"},error:null};case"UPDATE_CONFIG_SECTION":return{...e,state:{status:"config",section:t.section}};case"CLOSE_CONFIG":return{...e,state:{status:"input"},error:null};case"OPEN_HELP":return{...e,state:{status:"help"},error:null};case"CLOSE_HELP":return{...e,state:{status:"input"},error:null};case"CLEAR_HISTORY":return{...e,state:{status:"input"},history:[],outputExpanded:!1,error:null};default:return e}}function Qo(){let[e,t]=Kr(Hr,Ur),o=O(R=>{t({type:"SUBMIT",query:R})},[]),n=O(R=>{t({type:"AI_RESPONSE",proposal:R})},[]),i=O(R=>{t({type:"AI_ALTERNATIVES",proposals:R})},[]),s=O(R=>{t({type:"AI_ERROR",error:R})},[]),a=O(()=>{t({type:"EXECUTE"})},[]),c=O(R=>{t({type:"EXECUTE_EDITED",command:R})},[]),g=O(R=>{t({type:"EXEC_DONE",result:R})},[]),m=O(()=>{t({type:"COPY"})},[]),y=O(R=>{t({type:"EDIT",command:R})},[]),d=O(()=>{t({type:"CANCEL"})},[]),u=O(()=>{t({type:"TOGGLE_OUTPUT"})},[]),p=O(()=>{t({type:"SETUP_COMPLETE"})},[]),r=O(()=>{t({type:"EDIT",command:""})},[]),v=O(()=>{t({type:"OPEN_PALETTE"})},[]),S=O((R,b)=>{t({type:"UPDATE_PALETTE",query:R,filteredCommands:b})},[]),V=O(()=>{t({type:"CLOSE_PALETTE"})},[]),L=O(()=>{t({type:"OPEN_CONFIG"})},[]),G=O(R=>{t({type:"UPDATE_CONFIG_SECTION",section:R})},[]),T=O(()=>{t({type:"CLOSE_CONFIG"})},[]),F=O(()=>{t({type:"OPEN_HELP"})},[]),j=O(()=>{t({type:"CLOSE_HELP"})},[]),re=O(()=>{t({type:"CLEAR_HISTORY"})},[]);return{store:e,dispatch:t,submitQuery:o,handleAIResponse:n,handleAIAlternatives:i,handleAIError:s,execute:a,executeEdited:c,markExecutionDone:g,copy:m,edit:y,cancel:d,toggleOutput:u,completeSetup:p,clearEditingCommand:r,openPalette:v,updatePalette:S,closePalette:V,openConfig:L,updateConfigSection:G,closeConfig:T,openHelp:F,closeHelp:j,clearHistory:re}}import Fr from"clipboardy";async function Vo(e){try{return await Fr.write(e),{success:!0,data:{success:!0,message:"Copied to clipboard"}}}catch(t){return{success:!1,error:t instanceof Error?t:new Error("Failed to copy to clipboard")}}}import{Box as w,Static as $r,Text as I,useApp as Yr}from"ink";import{useCallback as _,useEffect as zo,useMemo as Le,useState as ye}from"react";import{Fragment as Gr,jsx as x,jsxs as B}from"react/jsx-runtime";function Jo(){let{exit:e}=Yr(),t=$o(),[o,n]=ye(null),[i,s]=ye(null),[a,c]=ye([]),[g,m]=ye(0),{isLoading:y,hasKey:d,error:u,refreshKeyStatus:p}=Fo(),{store:r,submitQuery:v,handleAIResponse:S,handleAIAlternatives:V,handleAIError:L,execute:G,executeEdited:T,markExecutionDone:F,copy:j,edit:re,cancel:R,toggleOutput:b,completeSetup:f,openPalette:h,updatePalette:k,closePalette:A,openConfig:Zo,updateConfigSection:Ht,closeConfig:ke,openHelp:en,closeHelp:tn,clearHistory:on}=Qo(),[ve,mt]=ye(0),[be,nn]=ye(()=>De().model),[dt,rn]=ye(()=>({contextEnabled:De().contextEnabled,showExplanations:!0,syntaxHighlighting:!0,simpleMode:!1})),[sn,Ft]=ye(!1),an=Le(()=>Bo(),[d]),ln=Le(()=>{let l=ge();return l?l.length<=12?"***":`${l.slice(0,7)}...${l.slice(-4)}`:null},[d]),$t=Le(()=>({model:be,contextEnabled:dt.contextEnabled,maxHistoryEntries:5,maxOutputLines:10,maxAlternatives:3}),[be]),q=Ho({sessionStatus:r.state.status,config:$t,updateConfig:()=>{},onOpenConfig:Zo,onOpenHelp:en,onClearHistory:on,onExit:()=>e()}),cn=Le(()=>{let l=[{id:"header",type:"header"}];return r.history.slice(0,-1).forEach((E,M)=>{l.push({id:`history-${M}`,type:"history",entry:E})}),l},[r.history]),ae=r.history.length>0?r.history[r.history.length-1]:null,{generate:Yt,getAlternatives:Gt,explain:jt,isLoading:Pe}=Ko({shell:t,history:r.history,contextEnabled:dt.contextEnabled}),{execute:Ve,kill:zr,isExecuting:ft,liveOutput:un}=jo({shell:t,onComplete:F}),pn=Le(()=>y||!d||r.state.status==="setup"||r.state.status==="loading"||r.state.status==="executing"||ft?"disabled":r.state.status==="palette"?"palette":r.state.status==="config"?"config":r.state.status==="help"?"help":r.state.status==="proposal"?Pe?"disabled":"menu":r.state.status==="alternatives"?Pe?"disabled":"selection":r.state.status==="input"?"text":"disabled",[y,d,r.state.status,ft,Pe]),mn=_(l=>{ut(l).success&&(p(),Ft(!1),f())},[p,f]);zo(()=>{!y&&d&&r.state.status==="setup"&&f()},[y,d,r.state.status,f]),zo(()=>{let l=De().model;be!==l&&We({model:be})},[be]);let dn=_(l=>{if(l.startsWith("/")){let C=l.slice(1),E=z.filter(C);c(E),m(0)}else c([]),m(0)},[]),fn=_(async l=>{if(l.startsWith("/")){let E=l.slice(1).trim();if(a.length>0){let M=a[g];if(M&&q.executeCommand(M.name)){c([]),m(0);return}}if(E&&q.executeCommand(E)){c([]),m(0);return}c([]),m(0);return}if(c([]),m(0),r.editingCommand){T(l),await Ve(l);return}v(l),s(null);let C=await Yt(l);C.success?S(C.data):L(C.error)},[r.editingCommand,v,Yt,S,L,T,Ve,q,a,g]),gn=_(async()=>{r.state.status==="proposal"&&(G(),await Ve(r.state.proposal.command))},[r.state,G,Ve]),xn=_(async()=>{if(r.state.status!=="proposal")return;(await Vo(r.state.proposal.command)).success?(n("\u2713 Copied to clipboard"),setTimeout(()=>n(null),2e3)):(n("\u2717 Failed to copy"),setTimeout(()=>n(null),2e3)),j()},[r.state,j]),yn=_(()=>{r.state.status==="proposal"&&re(r.state.proposal.command)},[r.state,re]),Cn=_(async()=>{if(r.state.status!=="proposal")return;let l=await Gt(r.currentQuery,r.state.proposal.command);l.success?V(l.data):L(l.error)},[r.state,r.currentQuery,Gt,V,L]),hn=_(()=>{R(),s(null)},[R]),Tn=_(async()=>{if(r.state.status!=="proposal")return;let l=await jt(r.state.proposal.command);l.success&&s(l.data)},[r.state,jt]),Sn=_(()=>{b()},[b]),En=_(l=>{if(r.state.status!=="alternatives")return;let C=r.state.proposals[l];C&&S(C)},[r.state,S]),vn=_(l=>{let C=z.filter(l);q.setQuery(l),k(l,C)},[q,k]),bn=_(()=>{q.executeSelected()&&(A(),q.reset())},[q,A]),Pn=_(l=>{l==="up"?q.focusUp():q.focusDown()},[q]),In=_(()=>{A(),q.reset()},[A,q]),An=_(l=>{let C=["api-key","model","toggles","about"];if(r.state.status!=="config")return;let E=C.indexOf(r.state.section),M;l==="next"?M=(E+1)%C.length:M=(E-1+C.length)%C.length,Ht(C[M]),mt(0)},[r.state,Ht]),wn=_(l=>{let C={"api-key":d?2:1,model:3,toggles:4,about:0};if(r.state.status!=="config")return;let E=C[r.state.section];E!==0&&mt(M=>l==="up"?(M-1+E)%E:(M+1)%E)},[r.state,d]),Rn=_(()=>{if(r.state.status==="config"){if(r.state.section==="toggles"){rn(l=>{let E=["contextEnabled","showExplanations","syntaxHighlighting","simpleMode"][ve];if(E){let M=!l[E];return E==="contextEnabled"&&We({contextEnabled:M}),{...l,[E]:M}}return l});return}if(r.state.section==="model"){let C=["claude-sonnet-4-5","claude-opus-4-5","claude-haiku-4-5"][ve];C&&nn(C);return}if(r.state.section==="api-key"){ve===0?(ke(),Ft(!0)):ve===1&&d&&Ro().success&&(p(),ke());return}}},[r.state,ve,ke,d,p]),On=_(()=>{ke(),mt(0)},[ke]),Bn=r.state.status==="palette"?r.state.query:"",Nn=Le(()=>r.state.status!=="config"?0:{"api-key":d?2:1,model:3,toggles:4,about:0}[r.state.section],[r.state,d]),{textState:Dn,clearText:Jr,setText:Zr,menuFocusIndex:Ln,selectionFocusIndex:kn,paletteFocusIndex:_n,configSectionIndex:es}=Wo({mode:pn,initialTextValue:r.editingCommand??"",paletteQuery:Bn,menuCallbacks:{onExecute:gn,onCopy:xn,onEdit:yn,onAlternatives:Cn,onCancel:hn,onExplain:Tn,onToggle:Sn},selectionCallbacks:{onSelect:En,onCancel:R,count:r.state.status==="alternatives"?r.state.proposals.length:1},textCallbacks:{onSubmit:fn,onToggleOutput:b,onTextChange:dn,onNavigateInlinePalette:l=>{m(C=>{let E=a.length;return E===0?0:l==="up"?(C-1+E)%E:(C+1)%E})},onCloseInlinePalette:()=>{c([]),m(0)},hasInlinePalette:a.length>0,hasHistory:r.history.length>0},paletteCallbacks:{onQueryChange:vn,onSelect:bn,onNavigate:Pn,onClose:In,filteredCount:r.state.status==="palette"?r.state.filteredCommands.length:0},configCallbacks:{onNavigateSection:An,onNavigateItem:wn,onToggle:Rn,onClose:On,sectionCount:4,itemCount:Nn},helpCallbacks:{onClose:tn}});return y?x(w,{flexDirection:"column",paddingY:1,children:x(I,{dimColor:!0,children:"Loading configuration..."})}):sn||!d&&r.state.status==="setup"?x(to,{onComplete:mn,error:u}):B(w,{flexDirection:"column",children:[x($r,{items:cn,children:l=>l.type==="header"?x(Eo,{shell:t,cwd:process.cwd(),model:be},l.id):l.type==="history"?B(w,{flexDirection:"column",marginBottom:1,children:[B(w,{children:[x(I,{color:"cyan",bold:!0,children:"\u276F "}),x(I,{color:"cyan",children:l.entry.query})]}),B(w,{marginLeft:2,flexDirection:"column",children:[B(w,{children:[B(I,{dimColor:!0,children:["$ ",l.entry.command," "]}),x(I,{color:l.entry.exitCode===0?"green":"red",children:l.entry.exitCode===0?"\u2713":`\u2717 ${l.entry.exitCode}`})]}),l.entry.output&&B(w,{flexDirection:"column",children:[l.entry.output.split(`
|
|
37
|
+
`).filter(Boolean);for(let L of V){let G=`[ERR] ${L}`;p.push(G),o?.(L,!0),s(T=>({...T,liveOutput:[...T.liveOutput,G].slice(-t)}))}});let r=await u;a.current=null;let v={command:m,stdout:r.stdout??"",stderr:r.stderr??"",exitCode:r.exitCode??0};return s(S=>({...S,isExecuting:!1})),n?.(v),{success:!0,data:v}}catch(u){a.current=null;let p=u instanceof Error?u:new Error(String(u));s(v=>({...v,isExecuting:!1,error:p}));let r={command:m,stdout:"",stderr:p.message,exitCode:1};return n?.(r),{success:!1,error:p}}},[e,t,o,n]),g=qo(()=>{a.current&&(a.current.kill("SIGINT"),a.current=null,s(m=>({...m,isExecuting:!1,liveOutput:[...m.liveOutput,"[Interrupted]"]})))},[]);return{...i,execute:c,kill:g}}import{useInput as Ur}from"ink";import{useCallback as Wo,useReducer as Hr,useRef as Qo,useState as Qe}from"react";function Vo({mode:e,menuCallbacks:t,selectionCallbacks:o,textCallbacks:n,paletteCallbacks:i,configCallbacks:s,helpCallbacks:a,initialTextValue:c="",paletteQuery:g=""}){let[m,y]=Hr(Co,yo(c)),[d,u]=Qe(0),[p,r]=Qe(0),[v,S]=Qe(0),[V,L]=Qe(0),[G,T]=Qe(0),F=Qo(c);F.current!==c&&(F.current=c,y({type:"set",value:c}));let j=Qo(e);j.current!==e&&(e==="menu"?u(0):e==="selection"?r(0):e==="palette"?S(0):e==="config"&&(L(0),T(0)),j.current=e);let re=Wo(()=>{y({type:"clear"})},[]),R=Wo(b=>{y({type:"set",value:b})},[]);return Ur((b,f)=>{if(e!=="disabled"){if(e==="text"&&n){if(f.ctrl&&!f.meta&&b==="d"){m.value.trim()===""&&process.exit(130);return}if(f.return){let h=m.value.trim();(h.toLowerCase()==="exit"||h.toLowerCase()==="quit")&&process.exit(0),h&&(n.onSubmit(h),y({type:"clear"}));return}if(b.toLowerCase()==="o"&&m.value.trim()===""&&n.onToggleOutput&&n.hasHistory){n.onToggleOutput();return}if(n.hasInlinePalette&&n.onNavigateInlinePalette){if(f.upArrow){n.onNavigateInlinePalette("up");return}if(f.downArrow){n.onNavigateInlinePalette("down");return}}if(f.leftArrow){y({type:"move-left"});return}if(f.rightArrow){y({type:"move-right"});return}if(f.backspace||f.delete){y({type:"delete"});let h=m.value.slice(0,m.cursorOffset-1)+m.value.slice(m.cursorOffset);n.onTextChange?.(h);return}if(f.escape){n.hasInlinePalette&&n.onCloseInlinePalette&&(n.onCloseInlinePalette(),y({type:"clear"}));return}if(f.ctrl||f.meta||f.tab)return;if(b&&b.length>0){y({type:"insert",text:b});let h=m.value.slice(0,m.cursorOffset)+b+m.value.slice(m.cursorOffset);n.onTextChange?.(h)}return}if(e==="menu"&&t){if(f.leftArrow){u(h=>(h-1+5)%5);return}if(f.rightArrow){u(h=>(h+1)%5);return}if(f.return){switch(["execute","copy","edit","alternatives","cancel"][d]){case"execute":t.onExecute();break;case"copy":t.onCopy();break;case"edit":t.onEdit();break;case"alternatives":t.onAlternatives();break;case"cancel":t.onCancel();break}return}if(b>="1"&&b<="5"){let h=parseInt(b,10)-1;switch(["execute","copy","edit","alternatives","cancel"][h]){case"execute":t.onExecute();break;case"copy":t.onCopy();break;case"edit":t.onEdit();break;case"alternatives":t.onAlternatives();break;case"cancel":t.onCancel();break}return}if(b==="?"){t.onExplain();return}if(b.toLowerCase()==="o"){t.onToggle();return}if(f.escape){t.onCancel();return}return}if(e==="selection"&&o){let h=o.count;if(f.upArrow){r(A=>(A-1+h)%h);return}if(f.downArrow){r(A=>(A+1)%h);return}if(f.return){o.onSelect(p);return}let k=parseInt(b,10);if(k>=1&&k<=h){o.onSelect(k-1);return}if(b==="5"||b.toLowerCase()==="c"||f.escape){o.onCancel();return}return}if(e==="palette"&&i){let h=i.filteredCount;if(f.upArrow){S(A=>h===0?0:(A-1+h)%h),i.onNavigate("up");return}if(f.downArrow){S(A=>h===0?0:(A+1)%h),i.onNavigate("down");return}if(f.return){i.onSelect();return}if(f.escape){i.onClose();return}if((f.backspace||f.delete)&&g===""){i.onClose();return}if(f.backspace||f.delete){let A=g.slice(0,-1);i.onQueryChange(A),S(0);return}if(f.ctrl||f.meta||f.tab)return;let k=parseInt(b,10);if(k>=1&&k<=9&&k<=h){S(k-1),i.onSelect();return}if(b&&b.length>0){let A=g+b;i.onQueryChange(A),S(0)}return}if(e==="config"&&s){let h=s.sectionCount,k=s.itemCount;if(f.tab&&!f.shift){L(A=>(A+1)%h),T(0),s.onNavigateSection("next");return}if(f.tab&&f.shift){L(A=>(A-1+h)%h),T(0),s.onNavigateSection("prev");return}if(f.upArrow){T(A=>k===0?0:(A-1+k)%k),s.onNavigateItem("up");return}if(f.downArrow){T(A=>k===0?0:(A+1)%k),s.onNavigateItem("down");return}if(f.return||b===" "){s.onToggle();return}if(f.escape){s.onClose();return}return}if(e==="help"&&a){if(f.escape){a.onClose();return}return}}},{isActive:e!=="disabled"}),{textState:m,dispatchText:y,clearText:re,setText:R,menuFocusIndex:d,selectionFocusIndex:p,paletteFocusIndex:v,configSectionIndex:V,configItemIndex:G}}import{useCallback as O,useReducer as Fr}from"react";var $r={state:{status:"setup"},history:[],currentQuery:"",editingCommand:null,outputExpanded:!1,error:null};function Yr(e,t){switch(t.type){case"SETUP_COMPLETE":return{...e,state:{status:"input"},error:null};case"SUBMIT":return{...e,state:{status:"loading",query:t.query},currentQuery:t.query,editingCommand:null,error:null};case"AI_RESPONSE":return{...e,state:{status:"proposal",proposal:t.proposal},error:null};case"AI_ALTERNATIVES":return{...e,state:{status:"alternatives",proposals:t.proposals,originalQuery:e.currentQuery},error:null};case"AI_ERROR":return{...e,state:{status:"input"},error:t.error.message};case"EXECUTE":{let o=e.state;return o.status!=="proposal"?e:{...e,state:{status:"executing",command:o.proposal.command},error:null}}case"EXECUTE_EDITED":return{...e,state:{status:"executing",command:t.command},editingCommand:null,error:null};case"EXEC_DONE":{let o=[...e.history,{query:e.currentQuery,command:t.result.command,output:t.result.stdout||t.result.stderr,exitCode:t.result.exitCode}].slice(-he.maxHistoryEntries);return{...e,state:{status:"input"},history:o,outputExpanded:!1,error:null}}case"COPY":return{...e,state:{status:"input"},error:null};case"EDIT":return{...e,state:{status:"input"},editingCommand:t.command,error:null};case"CANCEL":return{...e,state:{status:"input"},editingCommand:null,error:null};case"TOGGLE_OUTPUT":return e.history.length===0?e:{...e,outputExpanded:!e.outputExpanded};case"OPEN_PALETTE":return{...e,state:{status:"palette",query:"",filteredCommands:[]},error:null};case"UPDATE_PALETTE":return{...e,state:{status:"palette",query:t.query,filteredCommands:t.filteredCommands}};case"CLOSE_PALETTE":return{...e,state:{status:"input"},error:null};case"OPEN_CONFIG":return{...e,state:{status:"config",section:"api-key"},error:null};case"UPDATE_CONFIG_SECTION":return{...e,state:{status:"config",section:t.section}};case"CLOSE_CONFIG":return{...e,state:{status:"input"},error:null};case"OPEN_HELP":return{...e,state:{status:"help"},error:null};case"CLOSE_HELP":return{...e,state:{status:"input"},error:null};case"CLEAR_HISTORY":return{...e,state:{status:"input"},history:[],outputExpanded:!1,error:null};default:return e}}function zo(){let[e,t]=Fr(Yr,$r),o=O(R=>{t({type:"SUBMIT",query:R})},[]),n=O(R=>{t({type:"AI_RESPONSE",proposal:R})},[]),i=O(R=>{t({type:"AI_ALTERNATIVES",proposals:R})},[]),s=O(R=>{t({type:"AI_ERROR",error:R})},[]),a=O(()=>{t({type:"EXECUTE"})},[]),c=O(R=>{t({type:"EXECUTE_EDITED",command:R})},[]),g=O(R=>{t({type:"EXEC_DONE",result:R})},[]),m=O(()=>{t({type:"COPY"})},[]),y=O(R=>{t({type:"EDIT",command:R})},[]),d=O(()=>{t({type:"CANCEL"})},[]),u=O(()=>{t({type:"TOGGLE_OUTPUT"})},[]),p=O(()=>{t({type:"SETUP_COMPLETE"})},[]),r=O(()=>{t({type:"EDIT",command:""})},[]),v=O(()=>{t({type:"OPEN_PALETTE"})},[]),S=O((R,b)=>{t({type:"UPDATE_PALETTE",query:R,filteredCommands:b})},[]),V=O(()=>{t({type:"CLOSE_PALETTE"})},[]),L=O(()=>{t({type:"OPEN_CONFIG"})},[]),G=O(R=>{t({type:"UPDATE_CONFIG_SECTION",section:R})},[]),T=O(()=>{t({type:"CLOSE_CONFIG"})},[]),F=O(()=>{t({type:"OPEN_HELP"})},[]),j=O(()=>{t({type:"CLOSE_HELP"})},[]),re=O(()=>{t({type:"CLEAR_HISTORY"})},[]);return{store:e,dispatch:t,submitQuery:o,handleAIResponse:n,handleAIAlternatives:i,handleAIError:s,execute:a,executeEdited:c,markExecutionDone:g,copy:m,edit:y,cancel:d,toggleOutput:u,completeSetup:p,clearEditingCommand:r,openPalette:v,updatePalette:S,closePalette:V,openConfig:L,updateConfigSection:G,closeConfig:T,openHelp:F,closeHelp:j,clearHistory:re}}import Gr from"clipboardy";async function Jo(e){try{return await Gr.write(e),{success:!0,data:{success:!0,message:"Copied to clipboard"}}}catch(t){return{success:!1,error:t instanceof Error?t:new Error("Failed to copy to clipboard")}}}import{Box as w,Static as jr,Text as I,useApp as qr}from"ink";import{useCallback as _,useEffect as Zo,useMemo as Le,useState as ye}from"react";import{Fragment as Xr,jsx as x,jsxs as B}from"react/jsx-runtime";function en(){let{exit:e}=qr(),t=Go(),[o,n]=ye(null),[i,s]=ye(null),[a,c]=ye([]),[g,m]=ye(0),{isLoading:y,hasKey:d,error:u,refreshKeyStatus:p}=Yo(),{store:r,submitQuery:v,handleAIResponse:S,handleAIAlternatives:V,handleAIError:L,execute:G,executeEdited:T,markExecutionDone:F,copy:j,edit:re,cancel:R,toggleOutput:b,completeSetup:f,openPalette:h,updatePalette:k,closePalette:A,openConfig:tn,updateConfigSection:Ft,closeConfig:ke,openHelp:on,closeHelp:nn,clearHistory:rn}=zo(),[ve,ft]=ye(0),[be,sn]=ye(()=>De().model),[gt,an]=ye(()=>({contextEnabled:De().contextEnabled,showExplanations:!0,syntaxHighlighting:!0,simpleMode:!1})),[ln,$t]=ye(!1),cn=Le(()=>Do(),[d]),un=Le(()=>{let l=ge();return l?l.length<=12?"***":`${l.slice(0,7)}...${l.slice(-4)}`:null},[d]),Yt=Le(()=>({model:be,contextEnabled:gt.contextEnabled,maxHistoryEntries:5,maxOutputLines:10,maxAlternatives:3}),[be]),q=$o({sessionStatus:r.state.status,config:Yt,updateConfig:()=>{},onOpenConfig:tn,onOpenHelp:on,onClearHistory:rn,onExit:()=>e()}),pn=Le(()=>{let l=[{id:"header",type:"header"}];return r.history.slice(0,-1).forEach((E,M)=>{l.push({id:`history-${M}`,type:"history",entry:E})}),l},[r.history]),ae=r.history.length>0?r.history[r.history.length-1]:null,{generate:Gt,getAlternatives:jt,explain:qt,isLoading:Pe}=Ho({shell:t,history:r.history,contextEnabled:gt.contextEnabled}),{execute:Ve,kill:es,isExecuting:xt,liveOutput:mn}=Xo({shell:t,onComplete:F}),dn=Le(()=>y||!d||r.state.status==="setup"||r.state.status==="loading"||r.state.status==="executing"||xt?"disabled":r.state.status==="palette"?"palette":r.state.status==="config"?"config":r.state.status==="help"?"help":r.state.status==="proposal"?Pe?"disabled":"menu":r.state.status==="alternatives"?Pe?"disabled":"selection":r.state.status==="input"?"text":"disabled",[y,d,r.state.status,xt,Pe]),fn=_(l=>{mt(l).success&&(p(),$t(!1),f())},[p,f]);Zo(()=>{!y&&d&&r.state.status==="setup"&&f()},[y,d,r.state.status,f]),Zo(()=>{let l=De().model;be!==l&&We({model:be})},[be]);let gn=_(l=>{if(l.startsWith("/")){let C=l.slice(1),E=z.filter(C);c(E),m(0)}else c([]),m(0)},[]),xn=_(async l=>{if(l.startsWith("/")){let E=l.slice(1).trim();if(a.length>0){let M=a[g];if(M&&q.executeCommand(M.name)){c([]),m(0);return}}if(E&&q.executeCommand(E)){c([]),m(0);return}c([]),m(0);return}if(c([]),m(0),r.editingCommand){T(l),await Ve(l);return}v(l),s(null);let C=await Gt(l);C.success?S(C.data):L(C.error)},[r.editingCommand,v,Gt,S,L,T,Ve,q,a,g]),yn=_(async()=>{r.state.status==="proposal"&&(G(),await Ve(r.state.proposal.command))},[r.state,G,Ve]),Cn=_(async()=>{if(r.state.status!=="proposal")return;(await Jo(r.state.proposal.command)).success?(n("\u2713 Copied to clipboard"),setTimeout(()=>n(null),2e3)):(n("\u2717 Failed to copy"),setTimeout(()=>n(null),2e3)),j()},[r.state,j]),hn=_(()=>{r.state.status==="proposal"&&re(r.state.proposal.command)},[r.state,re]),Tn=_(async()=>{if(r.state.status!=="proposal")return;let l=await jt(r.currentQuery,r.state.proposal.command);l.success?V(l.data):L(l.error)},[r.state,r.currentQuery,jt,V,L]),Sn=_(()=>{R(),s(null)},[R]),En=_(async()=>{if(r.state.status!=="proposal")return;let l=await qt(r.state.proposal.command);l.success&&s(l.data)},[r.state,qt]),vn=_(()=>{b()},[b]),bn=_(l=>{if(r.state.status!=="alternatives")return;let C=r.state.proposals[l];C&&S(C)},[r.state,S]),Pn=_(l=>{let C=z.filter(l);q.setQuery(l),k(l,C)},[q,k]),In=_(()=>{q.executeSelected()&&(A(),q.reset())},[q,A]),An=_(l=>{l==="up"?q.focusUp():q.focusDown()},[q]),wn=_(()=>{A(),q.reset()},[A,q]),Rn=_(l=>{let C=["api-key","model","toggles","about"];if(r.state.status!=="config")return;let E=C.indexOf(r.state.section),M;l==="next"?M=(E+1)%C.length:M=(E-1+C.length)%C.length,Ft(C[M]),ft(0)},[r.state,Ft]),On=_(l=>{let C={"api-key":d?2:1,model:3,toggles:4,about:0};if(r.state.status!=="config")return;let E=C[r.state.section];E!==0&&ft(M=>l==="up"?(M-1+E)%E:(M+1)%E)},[r.state,d]),Bn=_(()=>{if(r.state.status==="config"){if(r.state.section==="toggles"){an(l=>{let E=["contextEnabled","showExplanations","syntaxHighlighting","simpleMode"][ve];if(E){let M=!l[E];return E==="contextEnabled"&&We({contextEnabled:M}),{...l,[E]:M}}return l});return}if(r.state.section==="model"){let C=["claude-sonnet-4-5","claude-opus-4-5","claude-haiku-4-5"][ve];C&&sn(C);return}if(r.state.section==="api-key"){ve===0?(ke(),$t(!0)):ve===1&&d&&Bo().success&&(p(),ke());return}}},[r.state,ve,ke,d,p]),Nn=_(()=>{ke(),ft(0)},[ke]),Dn=r.state.status==="palette"?r.state.query:"",Ln=Le(()=>r.state.status!=="config"?0:{"api-key":d?2:1,model:3,toggles:4,about:0}[r.state.section],[r.state,d]),{textState:kn,clearText:ts,setText:os,menuFocusIndex:_n,selectionFocusIndex:Mn,paletteFocusIndex:Kn,configSectionIndex:ns}=Vo({mode:dn,initialTextValue:r.editingCommand??"",paletteQuery:Dn,menuCallbacks:{onExecute:yn,onCopy:Cn,onEdit:hn,onAlternatives:Tn,onCancel:Sn,onExplain:En,onToggle:vn},selectionCallbacks:{onSelect:bn,onCancel:R,count:r.state.status==="alternatives"?r.state.proposals.length:1},textCallbacks:{onSubmit:xn,onToggleOutput:b,onTextChange:gn,onNavigateInlinePalette:l=>{m(C=>{let E=a.length;return E===0?0:l==="up"?(C-1+E)%E:(C+1)%E})},onCloseInlinePalette:()=>{c([]),m(0)},hasInlinePalette:a.length>0,hasHistory:r.history.length>0},paletteCallbacks:{onQueryChange:Pn,onSelect:In,onNavigate:An,onClose:wn,filteredCount:r.state.status==="palette"?r.state.filteredCommands.length:0},configCallbacks:{onNavigateSection:Rn,onNavigateItem:On,onToggle:Bn,onClose:Nn,sectionCount:4,itemCount:Ln},helpCallbacks:{onClose:nn}});return y?x(w,{flexDirection:"column",paddingY:1,children:x(I,{dimColor:!0,children:"Loading configuration..."})}):ln||!d&&r.state.status==="setup"?x(oo,{onComplete:fn,error:u}):B(w,{flexDirection:"column",children:[x(jr,{items:pn,children:l=>l.type==="header"?x(vo,{shell:t,cwd:process.cwd(),model:be},l.id):l.type==="history"?B(w,{flexDirection:"column",marginBottom:1,children:[B(w,{children:[x(I,{color:"cyan",bold:!0,children:"\u276F "}),x(I,{color:"cyan",children:l.entry.query})]}),B(w,{marginLeft:2,flexDirection:"column",children:[B(w,{children:[B(I,{dimColor:!0,children:["$ ",l.entry.command," "]}),x(I,{color:l.entry.exitCode===0?"green":"red",children:l.entry.exitCode===0?"\u2713":`\u2717 ${l.entry.exitCode}`})]}),l.entry.output&&B(w,{flexDirection:"column",children:[l.entry.output.split(`
|
|
38
38
|
`).slice(0,10).map((C,E)=>x(I,{children:C},E)),l.entry.output.split(`
|
|
39
39
|
`).length>10&&B(I,{dimColor:!0,children:["... (",l.entry.output.split(`
|
|
40
40
|
`).length-10," more lines)"]})]})]}),x(w,{marginTop:1,children:x(I,{dimColor:!0,children:"\u2500".repeat(50)})})]},l.id):null}),ae&&B(w,{flexDirection:"column",marginBottom:1,children:[B(w,{children:[x(I,{color:"cyan",bold:!0,children:"\u276F "}),x(I,{color:"cyan",children:ae.query})]}),B(w,{marginLeft:2,flexDirection:"column",children:[B(w,{children:[B(I,{dimColor:!0,children:["$ ",ae.command," "]}),x(I,{color:ae.exitCode===0?"green":"red",children:ae.exitCode===0?"\u2713":`\u2717 ${ae.exitCode}`})]}),ae.output&&x(w,{flexDirection:"column",children:(()=>{let l=ae.output.split(`
|
|
41
|
-
`).filter(ze=>ze.length>0),C=r.outputExpanded?500:10,E=l.slice(0,C),M=l.length-E.length;return B(
|
|
41
|
+
`).filter(ze=>ze.length>0),C=r.outputExpanded?500:10,E=l.slice(0,C),M=l.length-E.length;return B(Xr,{children:[E.map((ze,Un)=>x(I,{children:ze},Un)),M>0&&B(w,{children:[B(I,{dimColor:!0,children:["... (",M," more lines, press "]}),x(I,{color:"blue",children:"[O]"}),x(I,{dimColor:!0,children:" to expand)"})]})]})})()})]}),x(w,{marginTop:1,children:x(I,{dimColor:!0,children:"\u2500".repeat(50)})})]}),r.error&&x(w,{marginY:1,children:B(I,{color:"red",children:["Error: ",r.error]})}),o&&x(w,{marginY:1,children:x(I,{color:"green",children:o})}),r.state.status==="loading"&&x(kt,{query:r.state.query}),r.state.status==="proposal"&&B(w,{flexDirection:"column",marginY:1,children:[x(lo,{proposal:r.state.proposal,showExplanation:!!i}),i&&x(w,{marginTop:1,paddingX:1,children:x(I,{dimColor:!0,children:i})})]}),r.state.status==="proposal"&&Pe&&x(kt,{label:"Generating alternatives..."}),x(To,{focusedIndex:_n,visible:r.state.status==="proposal"&&!Pe}),r.state.status==="alternatives"&&x(w,{flexDirection:"column",marginY:1,children:x(co,{proposals:r.state.proposals})}),x(So,{count:r.state.status==="alternatives"?r.state.proposals.length:0,focusedIndex:Mn,visible:r.state.status==="alternatives"&&!Pe}),(r.state.status==="executing"||xt)&&x(ro,{lines:mn,command:r.state.status==="executing"?r.state.command:""}),x(It,{query:r.state.status==="palette"?r.state.query:"",filteredCommands:r.state.status==="palette"?r.state.filteredCommands:[],selectedIndex:Kn,visible:r.state.status==="palette"}),x(Ot,{visible:r.state.status==="config",activeSection:r.state.status==="config"?r.state.section:"api-key",sectionItemIndex:ve,config:Yt,hasApiKey:d,storageInfo:cn,maskedKey:un,toggles:gt}),x(Bt,{visible:r.state.status==="help"}),x(ho,{textState:kn,placeholder:"Describe what you want to do... (type / for commands)",hasHistory:r.history.length>0,visible:r.state.status==="input"}),r.state.status==="input"&&a.length>0&&B(w,{flexDirection:"column",marginLeft:2,marginTop:0,children:[x(w,{marginBottom:0,children:x(I,{dimColor:!0,children:"\u2500".repeat(50)})}),a.slice(0,5).map((l,C)=>B(w,{children:[x(I,{color:C===g?"cyan":"gray",bold:C===g,children:C===g?"> ":" "}),B(I,{color:C===g?"cyan":"blue",bold:C===g,children:["/",l.name]}),x(I,{children:" "}),x(I,{dimColor:C!==g,children:l.description})]},l.name)),x(w,{marginTop:0,children:x(I,{dimColor:!0,children:"[Enter] Select [Up/Down] Navigate [Esc] Cancel"})})]})]})}import{jsx as Zr}from"react/jsx-runtime";var Qr="\x1Bc",Vr="\x1B]0;CLI AI\x07";function zr(){console.log(`
|
|
42
42
|
CLI AI v${ee} - Natural language to shell commands
|
|
43
43
|
|
|
44
44
|
Usage:
|
|
@@ -62,4 +62,4 @@ Session Controls:
|
|
|
62
62
|
Escape Cancel current action
|
|
63
63
|
exit, quit Exit the session
|
|
64
64
|
Ctrl+D Exit (empty input)
|
|
65
|
-
`)}async function
|
|
65
|
+
`)}async function Jr(){let e=process.argv.slice(2);(e.includes("--help")||e.includes("-h"))&&(zr(),process.exit(0)),(e.includes("--version")||e.includes("-v"))&&(console.log(`CLI AI v${ee}`),process.exit(0)),process.stdout.write(Qr+Vr);let{waitUntilExit:t}=Wr(Zr(en,{}));process.on("SIGINT",()=>{}),process.on("SIGTERM",()=>{process.exit(0)}),await t()}Jr().catch(e=>{console.error("Fatal error:",e),process.exit(1)});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fmdzc/cli-ai",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4",
|
|
4
4
|
"description": "CLI AI Assistant v3 - Natural language to shell commands with persistent REPL session",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -39,7 +39,10 @@
|
|
|
39
39
|
"link:global": "pnpm build && pnpm link --global",
|
|
40
40
|
"unlink:global": "pnpm unlink --global",
|
|
41
41
|
"uninstall": "node scripts/uninstall.js",
|
|
42
|
-
"uninstall:force": "node scripts/uninstall.js --force"
|
|
42
|
+
"uninstall:force": "node scripts/uninstall.js --force",
|
|
43
|
+
"version:set": "node scripts/version.js",
|
|
44
|
+
"tag": "node scripts/tag.js",
|
|
45
|
+
"tag:repush": "node scripts/tag.js --repush"
|
|
43
46
|
},
|
|
44
47
|
"keywords": [
|
|
45
48
|
"cli",
|
|
@@ -63,7 +66,8 @@
|
|
|
63
66
|
"url": "https://github.com/fmdz387/cli-ai/issues"
|
|
64
67
|
},
|
|
65
68
|
"publishConfig": {
|
|
66
|
-
"access": "public"
|
|
69
|
+
"access": "public",
|
|
70
|
+
"provenance": true
|
|
67
71
|
},
|
|
68
72
|
"contributors": [
|
|
69
73
|
{
|
package/scripts/tag.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { execSync } from 'node:child_process';
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
|
|
7
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const ROOT_DIR = join(__dirname, '..');
|
|
9
|
+
|
|
10
|
+
function git(args, options = {}) {
|
|
11
|
+
const cmd = `git ${args}`;
|
|
12
|
+
try {
|
|
13
|
+
return execSync(cmd, {
|
|
14
|
+
cwd: ROOT_DIR,
|
|
15
|
+
encoding: 'utf8',
|
|
16
|
+
stdio: options.silent ? 'pipe' : 'inherit',
|
|
17
|
+
...options,
|
|
18
|
+
});
|
|
19
|
+
} catch (error) {
|
|
20
|
+
if (options.ignoreError) return null;
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getPackageTag() {
|
|
26
|
+
const pkgPath = join(ROOT_DIR, 'package.json');
|
|
27
|
+
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
|
|
28
|
+
return `v${pkg.version}`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function createTag(tag) {
|
|
32
|
+
const version = tag.slice(1);
|
|
33
|
+
console.log(`Creating tag ${tag}...`);
|
|
34
|
+
|
|
35
|
+
git(`tag -a ${tag} -m "Release ${version}"`);
|
|
36
|
+
console.log(`✓ Tag ${tag} created locally`);
|
|
37
|
+
|
|
38
|
+
console.log(`Pushing tag ${tag} to origin...`);
|
|
39
|
+
git(`push origin ${tag}`);
|
|
40
|
+
console.log(`✓ Tag ${tag} pushed to origin`);
|
|
41
|
+
|
|
42
|
+
return tag;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function repushTag(tag) {
|
|
46
|
+
console.log(`Re-pushing tag ${tag}...`);
|
|
47
|
+
|
|
48
|
+
console.log(`Deleting local tag ${tag}...`);
|
|
49
|
+
git(`tag -d ${tag}`, { ignoreError: true, silent: true });
|
|
50
|
+
console.log(`✓ Local tag deleted (or didn't exist)`);
|
|
51
|
+
|
|
52
|
+
console.log(`Deleting remote tag ${tag}...`);
|
|
53
|
+
git(`push origin --delete ${tag}`, { ignoreError: true, silent: true });
|
|
54
|
+
console.log(`✓ Remote tag deleted (or didn't exist)`);
|
|
55
|
+
|
|
56
|
+
return createTag(tag);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function showUsage() {
|
|
60
|
+
console.log(`
|
|
61
|
+
Usage: node scripts/tag.js [options] [tag]
|
|
62
|
+
|
|
63
|
+
Creates and pushes a git tag for the specified version.
|
|
64
|
+
If no tag is provided, uses the version from package.json.
|
|
65
|
+
|
|
66
|
+
Options:
|
|
67
|
+
--repush, --force Delete existing tag (local & remote) before creating
|
|
68
|
+
--help, -h Show this help message
|
|
69
|
+
|
|
70
|
+
Examples:
|
|
71
|
+
node scripts/tag.js # Tag current package.json version
|
|
72
|
+
node scripts/tag.js v3.0.5 # Tag specific version
|
|
73
|
+
node scripts/tag.js --repush # Re-push current version tag
|
|
74
|
+
node scripts/tag.js --force v3.0.5 # Re-push specific version tag
|
|
75
|
+
`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function main() {
|
|
79
|
+
const args = process.argv.slice(2);
|
|
80
|
+
|
|
81
|
+
// Parse arguments
|
|
82
|
+
let repush = false;
|
|
83
|
+
let tag = null;
|
|
84
|
+
|
|
85
|
+
for (const arg of args) {
|
|
86
|
+
if (arg === '--help' || arg === '-h') {
|
|
87
|
+
showUsage();
|
|
88
|
+
process.exit(0);
|
|
89
|
+
} else if (arg === '--repush' || arg === '--force') {
|
|
90
|
+
repush = true;
|
|
91
|
+
} else if (!arg.startsWith('-')) {
|
|
92
|
+
tag = arg;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Use package.json version if not specified
|
|
97
|
+
if (!tag) {
|
|
98
|
+
tag = getPackageTag();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Validate tag format (vX.X.X with optional prerelease/build metadata)
|
|
102
|
+
if (!/^v\d+\.\d+\.\d+(-[\w.]+)?(\+[\w.]+)?$/.test(tag)) {
|
|
103
|
+
console.error(`Invalid tag format: ${tag}`);
|
|
104
|
+
console.error(`Expected format: vX.X.X (e.g., v3.0.5)`);
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
console.log(`\nTag: ${tag}`);
|
|
109
|
+
console.log(`Mode: ${repush ? 're-push (delete + create)' : 'create new'}\n`);
|
|
110
|
+
|
|
111
|
+
try {
|
|
112
|
+
const result = repush ? repushTag(tag) : createTag(tag);
|
|
113
|
+
console.log(`\n✓ Successfully ${repush ? 're-pushed' : 'created'} tag ${result}`);
|
|
114
|
+
} catch (error) {
|
|
115
|
+
console.error(`\n✗ Failed to ${repush ? 're-push' : 'create'} tag:`, error.message);
|
|
116
|
+
process.exit(1);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
main();
|