@cdoing/opentuicli 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,48 @@
1
+ var vo=Object.defineProperty;var rt=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(n,t)=>(typeof require<"u"?require:n)[t]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var W=(e,n)=>()=>(e&&(n=e(e=0)),n);var ko=(e,n)=>{for(var t in n)vo(e,t,{get:n[t],enumerable:!0})};import{RGBA as kt,rgbToHex as Do,SyntaxStyle as Co}from"@opentui/core";import{createContext as To,useContext as Mo,useState as Ke,useEffect as $o,useRef as st,useMemo as Ao}from"react";import{jsx as Bo}from"@opentui/react/jsx-runtime";function q(e){return kt.fromHex(e)}function _(e){return{text:q(e.text),textMuted:q(e.textMuted),textDim:q(e.textDim),primary:q(e.primary),secondary:q(e.secondary),success:q(e.success),error:q(e.error),warning:q(e.warning),info:q(e.info),border:q(e.border),borderFocused:q(e.primary),bg:q(e.bg),bgSubtle:q(e.bgSubtle),userText:q(e.success),assistantText:q(e.text),systemText:q(e.warning),toolText:q(e.textMuted),toolRunning:q(e.warning),toolDone:q(e.success),toolError:q(e.error),diffAdd:q(e.diffAdd||e.success),diffRemove:q(e.diffRemove||e.error),diffHunk:q(e.info)}}function Ut(){return Object.keys(Te).sort((e,n)=>e==="default"?-1:n==="default"?1:e.localeCompare(n))}function Se(e,n){let t=Te[e]||Te.default;return n==="light"?t.light:t.dark}function Po(e,n,t){let[o,s,r]=[e,n,t].map(i=>{let u=i/255;return u<=.03928?u/12.92:Math.pow((u+.055)/1.055,2.4)});return .2126*o+.7152*s+.0722*r}function Ro(){return new Promise(e=>{if(!process.stdin.isTTY||!process.stdout.isTTY){e(null);return}let n=setTimeout(()=>{s(),e(null)},500),t="",o=i=>{t+=i.toString();let u=t.match(/\x1b\]11;rgb:([0-9a-fA-F]{2,4})\/([0-9a-fA-F]{2,4})\/([0-9a-fA-F]{2,4})/);if(u){s();let c=b=>b.length<=2?parseInt(b,16):Math.round(parseInt(b,16)/65535*255);e({r:c(u[1]),g:c(u[2]),b:c(u[3])})}},s=()=>{clearTimeout(n),process.stdin.removeListener("data",o),r===!1&&process.stdin.setRawMode(!1)},r=process.stdin.isRaw;try{process.stdin.setRawMode(!0)}catch{e(null);return}process.stdin.on("data",o),process.stdout.write("\x1B]11;?\x07")})}function Io(){let e=process.env.COLORFGBG;if(e){let n=e.split(";");if(parseInt(n[n.length-1]||"0",10)>8)return"light"}return"dark"}async function Ft(){if(Ue)return Ue;let e=await Ro();return e?Ue=Po(e.r,e.g,e.b)>.5?"light":"dark":Ue=Io(),Ue}function Oe(e){if(!process.stdout.isTTY)return;let n=Do(e);process.stdout.write(`\x1B]11;${n}\x07`)}function it(){process.stdout.isTTY&&process.stdout.write("\x1B]111;\x07")}function Oo(e){return Co.fromStyles({default:{fg:e.text},"markup.heading.1":{fg:e.primary,bold:!0},"markup.heading.2":{fg:e.primary,bold:!0},"markup.heading.3":{fg:e.info,bold:!0},"markup.heading.4":{fg:e.info,bold:!0},"markup.heading.5":{fg:e.info},"markup.heading.6":{fg:e.info},"markup.bold":{bold:!0},"markup.italic":{italic:!0},"markup.list":{fg:e.warning},"markup.link":{fg:e.info,underline:!0},"markup.raw":{fg:e.warning},"markup.quote":{fg:e.textMuted,italic:!0},keyword:{fg:e.secondary,bold:!0},"keyword.control":{fg:e.secondary,bold:!0},"keyword.operator":{fg:e.secondary},string:{fg:e.success},"string.quoted":{fg:e.success},comment:{fg:e.textDim,italic:!0},"comment.line":{fg:e.textDim,italic:!0},"comment.block":{fg:e.textDim,italic:!0},constant:{fg:e.warning},"constant.numeric":{fg:e.warning},number:{fg:e.warning},variable:{fg:e.text},"variable.parameter":{fg:e.text},function:{fg:e.info},"entity.name.function":{fg:e.info},"support.function":{fg:e.info},type:{fg:e.primary},"entity.name.type":{fg:e.primary},"support.type":{fg:e.primary},operator:{fg:e.textMuted},punctuation:{fg:e.textMuted}})}function Ht(e){let n=e.mode==="light"?"light":e.mode==="auto"&&e.detectedMode||"dark",t=e.themeId||"default",[o,s]=Ke(t),[r,i]=Ke(n),[u,c]=Ke(Se(t,n)),[b,f]=Ke(e.syncTerminalBg??!1),[A,R]=Ke(null),d=st(b);d.current=b;let w=st(A);w.current=A;let D=st(r);D.current=r;let T=st(o);T.current=o;let h=M=>{d.current&&(w.current?Oe(kt.fromHex(w.current)):Oe(M.bg))},v=M=>{s(M),T.current=M;let l=Se(M,D.current);c(l),h(l)},B=M=>{i(M),D.current=M;let l=Se(T.current,M);c(l),h(l)},E=M=>{R(M),w.current=M,d.current&&Oe(M?kt.fromHex(M):Se(T.current,D.current).bg)},C=M=>{if(f(M),d.current=M,M){let l=Se(T.current,D.current);h(l)}else it()};$o(()=>{if(d.current){let M=Se(t,n);h(M)}return()=>{d.current&&it()}},[]);let $=Ao(()=>Oo(u),[u]);return Bo(Wt.Provider,{value:{theme:u,themeId:o,mode:r,syntaxStyle:$,customBg:A,setThemeId:v,setMode:B,setCustomBg:E,syncTerminalBg:b,setSyncTerminalBg:C},children:e.children})}function O(){let e=Mo(Wt);if(!e)throw new Error("useTheme must be used within ThemeProvider");return e}var Te,Ue,Wt,V=W(()=>{"use strict";Te={default:{name:"Default",dark:_({bg:"#000000",bgSubtle:"#111111",text:"#e5e7eb",textMuted:"#9ca3af",textDim:"#6b7280",primary:"#06b6d4",secondary:"#8b5cf6",success:"#22c55e",error:"#ef4444",warning:"#eab308",info:"#3b82f6",border:"#374151"}),light:_({bg:"#ffffff",bgSubtle:"#f3f4f6",text:"#1f2937",textMuted:"#6b7280",textDim:"#9ca3af",primary:"#0891b2",secondary:"#7c3aed",success:"#16a34a",error:"#dc2626",warning:"#ca8a04",info:"#2563eb",border:"#d1d5db"})},catppuccin:{name:"Catppuccin",dark:_({bg:"#1e1e2e",bgSubtle:"#313244",text:"#cdd6f4",textMuted:"#a6adc8",textDim:"#6c7086",primary:"#89b4fa",secondary:"#cba6f7",success:"#a6e3a1",error:"#f38ba8",warning:"#f9e2af",info:"#74c7ec",border:"#45475a"}),light:_({bg:"#eff1f5",bgSubtle:"#e6e9ef",text:"#4c4f69",textMuted:"#6c6f85",textDim:"#9ca0b0",primary:"#1e66f5",secondary:"#8839ef",success:"#40a02b",error:"#d20f39",warning:"#df8e1d",info:"#04a5e5",border:"#ccd0da"})},dracula:{name:"Dracula",dark:_({bg:"#282a36",bgSubtle:"#44475a",text:"#f8f8f2",textMuted:"#6272a4",textDim:"#44475a",primary:"#bd93f9",secondary:"#ff79c6",success:"#50fa7b",error:"#ff5555",warning:"#f1fa8c",info:"#8be9fd",border:"#44475a"}),light:_({bg:"#f8f8f2",bgSubtle:"#e6e6e6",text:"#282a36",textMuted:"#6272a4",textDim:"#999999",primary:"#7c3aed",secondary:"#d946ef",success:"#16a34a",error:"#dc2626",warning:"#ca8a04",info:"#0891b2",border:"#d1d5db"})},nord:{name:"Nord",dark:_({bg:"#2e3440",bgSubtle:"#3b4252",text:"#eceff4",textMuted:"#d8dee9",textDim:"#4c566a",primary:"#88c0d0",secondary:"#b48ead",success:"#a3be8c",error:"#bf616a",warning:"#ebcb8b",info:"#81a1c1",border:"#434c5e"}),light:_({bg:"#eceff4",bgSubtle:"#e5e9f0",text:"#2e3440",textMuted:"#4c566a",textDim:"#7b88a1",primary:"#5e81ac",secondary:"#b48ead",success:"#a3be8c",error:"#bf616a",warning:"#ebcb8b",info:"#81a1c1",border:"#d8dee9"})},tokyonight:{name:"Tokyo Night",dark:_({bg:"#1a1b26",bgSubtle:"#24283b",text:"#c0caf5",textMuted:"#a9b1d6",textDim:"#565f89",primary:"#7aa2f7",secondary:"#bb9af7",success:"#9ece6a",error:"#f7768e",warning:"#e0af68",info:"#7dcfff",border:"#3b4261"}),light:_({bg:"#d5d6db",bgSubtle:"#cbccd1",text:"#343b58",textMuted:"#565a6e",textDim:"#9699a3",primary:"#34548a",secondary:"#5a4a78",success:"#485e30",error:"#8c4351",warning:"#8f5e15",info:"#0f4b6e",border:"#b4b5b9"})},gruvbox:{name:"Gruvbox",dark:_({bg:"#282828",bgSubtle:"#3c3836",text:"#ebdbb2",textMuted:"#a89984",textDim:"#665c54",primary:"#fabd2f",secondary:"#d3869b",success:"#b8bb26",error:"#fb4934",warning:"#fe8019",info:"#83a598",border:"#504945"}),light:_({bg:"#fbf1c7",bgSubtle:"#f2e5bc",text:"#3c3836",textMuted:"#7c6f64",textDim:"#a89984",primary:"#b57614",secondary:"#8f3f71",success:"#79740e",error:"#9d0006",warning:"#af3a03",info:"#427b58",border:"#d5c4a1"})},rosepine:{name:"Ros\xE9 Pine",dark:_({bg:"#191724",bgSubtle:"#1f1d2e",text:"#e0def4",textMuted:"#908caa",textDim:"#6e6a86",primary:"#c4a7e7",secondary:"#ebbcba",success:"#31748f",error:"#eb6f92",warning:"#f6c177",info:"#9ccfd8",border:"#26233a"}),light:_({bg:"#faf4ed",bgSubtle:"#f2e9e1",text:"#575279",textMuted:"#797593",textDim:"#9893a5",primary:"#907aa9",secondary:"#d7827e",success:"#286983",error:"#b4637a",warning:"#ea9d34",info:"#56949f",border:"#dfdad9"})},monokai:{name:"Monokai",dark:_({bg:"#272822",bgSubtle:"#3e3d32",text:"#f8f8f2",textMuted:"#75715e",textDim:"#49483e",primary:"#66d9ef",secondary:"#ae81ff",success:"#a6e22e",error:"#f92672",warning:"#e6db74",info:"#66d9ef",border:"#49483e"}),light:_({bg:"#fafafa",bgSubtle:"#f0f0f0",text:"#272822",textMuted:"#75715e",textDim:"#b0b0b0",primary:"#0096d1",secondary:"#7c3aed",success:"#629e25",error:"#c4265e",warning:"#b5a21d",info:"#0096d1",border:"#d0d0d0"})},solarized:{name:"Solarized",dark:_({bg:"#002b36",bgSubtle:"#073642",text:"#839496",textMuted:"#657b83",textDim:"#586e75",primary:"#268bd2",secondary:"#6c71c4",success:"#859900",error:"#dc322f",warning:"#b58900",info:"#2aa198",border:"#073642"}),light:_({bg:"#fdf6e3",bgSubtle:"#eee8d5",text:"#657b83",textMuted:"#839496",textDim:"#93a1a1",primary:"#268bd2",secondary:"#6c71c4",success:"#859900",error:"#dc322f",warning:"#b58900",info:"#2aa198",border:"#eee8d5"})},amoled:{name:"AMOLED",dark:_({bg:"#000000",bgSubtle:"#0a0a0a",text:"#ffffff",textMuted:"#888888",textDim:"#555555",primary:"#00e5ff",secondary:"#e040fb",success:"#00e676",error:"#ff1744",warning:"#ffea00",info:"#40c4ff",border:"#222222"}),light:_({bg:"#ffffff",bgSubtle:"#f5f5f5",text:"#000000",textMuted:"#666666",textDim:"#aaaaaa",primary:"#0097a7",secondary:"#7b1fa2",success:"#2e7d32",error:"#c62828",warning:"#f9a825",info:"#0277bd",border:"#e0e0e0"})},github:{name:"GitHub",dark:_({bg:"#0d1117",bgSubtle:"#161b22",text:"#e6edf3",textMuted:"#8b949e",textDim:"#484f58",primary:"#58a6ff",secondary:"#bc8cff",success:"#3fb950",error:"#f85149",warning:"#d29922",info:"#58a6ff",border:"#30363d"}),light:_({bg:"#ffffff",bgSubtle:"#f6f8fa",text:"#1f2328",textMuted:"#656d76",textDim:"#8c959f",primary:"#0969da",secondary:"#8250df",success:"#1a7f37",error:"#cf222e",warning:"#9a6700",info:"#0969da",border:"#d0d7de"})},material:{name:"Material",dark:_({bg:"#263238",bgSubtle:"#37474f",text:"#eeffff",textMuted:"#b0bec5",textDim:"#546e7a",primary:"#82aaff",secondary:"#c792ea",success:"#c3e88d",error:"#ff5370",warning:"#ffcb6b",info:"#89ddff",border:"#37474f"}),light:_({bg:"#fafafa",bgSubtle:"#eeeeee",text:"#90a4ae",textMuted:"#546e7a",textDim:"#b0bec5",primary:"#6182b8",secondary:"#7c4dff",success:"#91b859",error:"#e53935",warning:"#f76d47",info:"#39adb5",border:"#d0d0d0"})},synthwave:{name:"Synthwave '84",dark:_({bg:"#262335",bgSubtle:"#34294f",text:"#ffffff",textMuted:"#bbbbbb",textDim:"#6d5da0",primary:"#ff7edb",secondary:"#36f9f6",success:"#72f1b8",error:"#fe4450",warning:"#fede5d",info:"#36f9f6",border:"#495495"}),light:_({bg:"#f5f0ff",bgSubtle:"#e8e0f0",text:"#262335",textMuted:"#6d5da0",textDim:"#a090c0",primary:"#b03090",secondary:"#108888",success:"#308050",error:"#c03030",warning:"#a08000",info:"#207080",border:"#d0c8e0"})},everforest:{name:"Everforest",dark:_({bg:"#2d353b",bgSubtle:"#343f44",text:"#d3c6aa",textMuted:"#859289",textDim:"#5c6a72",primary:"#a7c080",secondary:"#d699b6",success:"#a7c080",error:"#e67e80",warning:"#dbbc7f",info:"#7fbbb3",border:"#475258"}),light:_({bg:"#fdf6e3",bgSubtle:"#f3efda",text:"#5c6a72",textMuted:"#829181",textDim:"#a6b0a0",primary:"#8da101",secondary:"#df69ba",success:"#8da101",error:"#f85552",warning:"#dfa000",info:"#35a77c",border:"#e0dcc7"})},cobalt2:{name:"Cobalt2",dark:_({bg:"#193549",bgSubtle:"#1f4662",text:"#ffffff",textMuted:"#8db0cc",textDim:"#4d7ea0",primary:"#ffc600",secondary:"#ff9d00",success:"#3ad900",error:"#ff628c",warning:"#ffc600",info:"#80fcff",border:"#2a5a7a"}),light:_({bg:"#ffffff",bgSubtle:"#f0f0f0",text:"#193549",textMuted:"#4d7ea0",textDim:"#8db0cc",primary:"#b88d00",secondary:"#cc7a00",success:"#2ba600",error:"#cc4e70",warning:"#b88d00",info:"#0090a0",border:"#d0d0d0"})}};Ue=null;Wt=To(void 0)});import{createContext as Lo,useContext as Eo}from"react";import{jsx as No}from"@opentui/react/jsx-runtime";function Vt(e){return No(qt.Provider,{value:e.value,children:e.children})}function at(){let e=Eo(qt);if(!e)throw new Error("useSDK must be used within SDKProvider");return e}var qt,ct=W(()=>{"use strict";qt=Lo(void 0)});import{createContext as jo,useContext as _o,useState as Go,useEffect as Ko,useCallback as Yt,useRef as Xt}from"react";import{jsx as lt,jsxs as Jt}from"@opentui/react/jsx-runtime";function Fo(e,n){switch(e){case"info":return n.info;case"success":return n.success;case"warning":return n.warning;case"error":return n.error}}function Zt(e){let{theme:n}=O(),[t,o]=Go([]),s=Xt(0),r=Xt(new Map),i=Yt(c=>{o(f=>f.filter(A=>A.id!==c));let b=r.current.get(c);b&&(clearTimeout(b),r.current.delete(c))},[]),u=Yt((c,b,f)=>{let A=++s.current,R=f??Wo,d={id:A,type:c,message:b,duration:R};o(D=>{let T=[...D,d];if(T.length>zt){let h=T.splice(0,T.length-zt);for(let v of h){let B=r.current.get(v.id);B&&(clearTimeout(B),r.current.delete(v.id))}}return T});let w=setTimeout(()=>{i(A)},R);r.current.set(A,w)},[i]);return Ko(()=>()=>{for(let c of r.current.values())clearTimeout(c);r.current.clear()},[]),Jt(Qt.Provider,{value:{toast:u},children:[e.children,t.length>0&&lt("box",{flexDirection:"column",alignItems:"flex-end",children:t.map(c=>{let b=Fo(c.type,n),f=Uo[c.type];return Jt("box",{height:1,flexDirection:"row",justifyContent:"flex-end",children:[lt("text",{fg:b,children:` ${f} `}),lt("text",{fg:n.text,children:c.message}),lt("text",{fg:n.textDim,children:" "})]},c.id)})})]})}function en(){let e=_o(Qt);if(!e)throw new Error("useToast must be used within ToastProvider");return e}var Uo,Qt,Wo,zt,Dt=W(()=>{"use strict";V();Uo={info:"\u2139",success:"\u2713",warning:"\u26A0",error:"\u2717"};Qt=jo(void 0),Wo=3e3,zt=3});import*as Me from"fs";import*as Fe from"path";function We(e,n){if(!e)return[];if(e.startsWith("/"))return tn.filter(o=>o.name.startsWith(e)).map(o=>({text:o.name,description:o.description,type:"command"}));if(e.startsWith("@")||e.includes(" @")){let o=e.lastIndexOf("@"),s=e.substring(o),r=[];for(let i of nn)i.trigger.startsWith(s)&&r.push({text:i.trigger,description:i.description,type:"mention"});if(s==="@"||s.startsWith("@file ")||s.startsWith("@f")){let i=s.startsWith("@file ")?s.substring(6):"",u=Yo(n,i);for(let c of u.slice(0,10))r.push({text:`@file ${c}`,description:"",type:"file"})}return r}let t=e.split(" ");if(t.length>=1){let o=t[0],s=Ho[o];if(s&&t.length<=2){let r=t[1]||"";return s.filter(i=>i.startsWith(r)).map(i=>({text:`${o} ${i}`,description:"",type:"subcommand"}))}}if(t.length>=2){let o=qo(e,n);if(o.length>0){let s=t.slice(0,-1).join(" ")+" ";return o.map(r=>({text:s+r,description:r.endsWith("/")?"directory":"file",type:"file"}))}}return[]}function on(e,n){if(!e)return"";if(e.startsWith("/")){let o=tn.find(s=>s.name.startsWith(e)&&s.name!==e);return o?o.name.substring(e.length):""}let t=e.lastIndexOf("@");if(t>=0&&t===e.length-e.substring(t).length){let o=e.substring(t),s=nn.find(r=>r.trigger.startsWith(o)&&r.trigger!==o);return s?s.trigger.substring(o.length):""}return""}function qo(e,n){let t=["cd","ls","cat","head","tail","less","more","vim","nano","code","open","rm","cp","mv","mkdir","touch","chmod"],o=e.split(" ");if(o.length<2)return[];let s=o[0];if(!t.includes(s))return[];let r=o[o.length-1]||"";return Vo(n,r)}function Vo(e,n){try{let t=n.includes("/")?Fe.resolve(e,n.substring(0,n.lastIndexOf("/")+1)):e,o=n.includes("/")?n.substring(n.lastIndexOf("/")+1):n;if(!Me.existsSync(t)||!Me.statSync(t).isDirectory())return[];let s=Me.readdirSync(t,{withFileTypes:!0}),r=n.includes("/")?n.substring(0,n.lastIndexOf("/")+1):"";return s.filter(i=>!i.name.startsWith(".")||n.startsWith(".")).filter(i=>i.name.toLowerCase().startsWith(o.toLowerCase())).sort((i,u)=>i.isDirectory()!==u.isDirectory()?i.isDirectory()?-1:1:i.name.localeCompare(u.name)).slice(0,20).map(i=>r+i.name+(i.isDirectory()?"/":""))}catch{return[]}}function Yo(e,n){let t=[],o=n.toLowerCase(),s=new Set(["node_modules",".git","dist","build","__pycache__",".cache","coverage"]),r=(i,u,c)=>{if(!(c>3||t.length>=15))try{let b=Me.readdirSync(Fe.join(e,i),{withFileTypes:!0});for(let f of b){if(f.name.startsWith(".")||s.has(f.name))continue;if(t.length>=15)break;let A=u?`${u}/${f.name}`:f.name;f.isDirectory()?((!n||A.toLowerCase().includes(o))&&t.push(A+"/"),r(Fe.join(i,f.name),A,c+1)):(!n||A.toLowerCase().includes(o))&&t.push(A)}}catch{}};return r("","",0),t}var tn,nn,Ho,rn=W(()=>{"use strict";tn=[{name:"/help",description:"Show available commands"},{name:"/clear",description:"Clear chat history"},{name:"/new",description:"Start new conversation"},{name:"/model",description:"Show/change model"},{name:"/provider",description:"Show/change provider"},{name:"/mode",description:"Cycle permission mode"},{name:"/usage",description:"Show token usage & cost"},{name:"/compact",description:"Compress context"},{name:"/config",description:"Show/set configuration"},{name:"/dir",description:"Change working directory"},{name:"/history",description:"Browse past sessions"},{name:"/ls",description:"List conversations"},{name:"/resume",description:"Resume conversation by ID"},{name:"/view",description:"View a conversation"},{name:"/fork",description:"Fork current conversation"},{name:"/delete",description:"Delete a conversation"},{name:"/plan",description:"Toggle plan mode"},{name:"/tasks",description:"Show active tasks"},{name:"/memory",description:"Show agent memory"},{name:"/permissions",description:"Show permission rules"},{name:"/hooks",description:"Show configured hooks"},{name:"/rules",description:"Show project rules"},{name:"/mcp",description:"MCP server management"},{name:"/context",description:"Show context providers"},{name:"/effort",description:"Set effort level"},{name:"/theme",description:"Switch theme"},{name:"/bg",description:"Run in background"},{name:"/jobs",description:"Show background jobs"},{name:"/login",description:"OAuth login"},{name:"/logout",description:"OAuth logout"},{name:"/setup",description:"Run setup wizard"},{name:"/doctor",description:"Check system health"},{name:"/init",description:"Initialize project config"},{name:"/exit",description:"Quit the TUI"},{name:"/quit",description:"Quit the TUI"},{name:"/btw",description:"Ask without adding to history"},{name:"/auth-status",description:"Show authentication status"},{name:"/queue",description:"Show message queue"}],nn=[{trigger:"@terminal",description:"Recent terminal output"},{trigger:"@url",description:"Fetch URL content"},{trigger:"@tree",description:"Project file tree"},{trigger:"@codebase",description:"Full codebase context"},{trigger:"@clip",description:"Clipboard content"},{trigger:"@file",description:"Include a file"}],Ho={npm:["install","run","test","start","build","init","publish","uninstall","update","ls","audit","ci"],yarn:["install","add","remove","run","build","test","start","dev","upgrade","info","why"],pnpm:["install","add","remove","run","build","test","dev","update","store"],bun:["install","add","remove","run","build","test","dev","init","create"],git:["status","add","commit","push","pull","fetch","checkout","branch","merge","rebase","log","diff","stash","reset","clone","remote","tag","cherry-pick","bisect","show","blame","reflog"],docker:["build","run","exec","ps","images","pull","push","stop","rm","logs","compose"],python:["-m","-c","--version","manage.py"],python3:["-m","-c","--version","manage.py"],pip:["install","uninstall","freeze","list","show"],cargo:["build","run","test","check","clippy","fmt","new","init","add","publish"],go:["build","run","test","get","mod","fmt","vet","install","generate"],make:["build","test","clean","install","all"],kubectl:["get","describe","apply","delete","logs","exec","port-forward","scale"],gh:["pr","issue","repo","run","release","api","auth","browse"],turbo:["build","dev","test","lint","run"],npx:["tsc","ts-node","eslint","prettier","jest","vitest","playwright"]}});import{TextAttributes as sn}from"@opentui/core";import{useState as dt,useRef as an,useMemo as cn}from"react";import{useKeyboard as Xo}from"@opentui/react";import{execSync as Ve}from"child_process";import{Fragment as Qo,jsx as te,jsxs as qe}from"@opentui/react/jsx-runtime";function zo(){try{if(process.platform==="darwin")return Ve("pbpaste",{encoding:"utf-8"});try{return Ve("xclip -selection clipboard -o",{encoding:"utf-8"})}catch{return Ve("xsel --clipboard --output",{encoding:"utf-8"})}}catch{return""}}function Jo(){if(process.platform!=="darwin")return null;try{if(Ve(`osascript -e 'clipboard info' 2>/dev/null | grep -q "TIFF\\|PNG\\|JPEG" && echo "yes" || echo "no"`,{encoding:"utf-8",timeout:1e3}).trim()!=="yes")return null;let n=Ve("osascript -e 'set theImage to the clipboard as \xABclass PNGf\xBB' -e 'return theImage' 2>/dev/null | base64",{encoding:"utf-8",timeout:3e3,maxBuffer:20*1024*1024}).trim();if(n&&n.length>100)return{data:n,mimeType:"image/png"}}catch{}return null}function ut(e){let{theme:n}=O(),t=n,[o,s]=dt(""),[r,i]=dt([]),[u,c]=dt(0),[b,f]=dt(!1),A=an(o);A.current=o;let R=an(0),d=cn(()=>{if(!o)return[];let C=We(o,e.workingDir);return C.length>0&&C[0].type==="file"?[{text:o,description:"submit as typed",type:"file"},...C]:C},[o,e.workingDir]),w=cn(()=>b&&d.length>0?"":on(o,e.workingDir),[o,e.workingDir,b,d.length]),D=b&&d.length>0;Xo(C=>{if(D){if(C.name==="up"){c($=>$<=0?d.length-1:$-1);return}if(C.name==="down"){c($=>$>=d.length-1?0:$+1);return}if(C.name==="return"){let $=d[u];if($){let M=$.text.trim();M&&(e.onSubmit(M,r.length>0?[...r]:void 0),s(""),i([])),f(!1),c(0)}return}if(C.name==="escape"){f(!1);return}if(C.name==="tab"){let $=d[u];$&&(s($.text+" "),f(!1),c(0));return}}if(w&&(C.name==="tab"||C.name==="right")){s($=>$+w);return}if(C.ctrl&&C.name==="v"){let $=Jo();if($){R.current+=1,i(l=>[...l,$]),s(l=>l+`[Image #${R.current}] `);return}let M=zo().trim();if(M){let l=M.split(`
2
+ `)[0]||"";s(z=>z+l)}return}if(C.ctrl&&C.name==="u"){s(""),i([]),f(!1);return}if(C.ctrl&&C.name==="w"){s($=>$.replace(/\S+\s*$/,""));return}if(C.name==="return"&&!C.shift){let $=A.current.trim();($||r.length>0)&&(e.onSubmit($||"Describe this image.",r.length>0?[...r]:void 0),s(""),i([]),f(!1));return}if(C.name==="backspace"){s($=>{let M=$.slice(0,-1);return M.startsWith("/")||M.includes("@")||We(M,e.workingDir).length>0?(f(!0),c(0)):f(!1),M});return}if(C.name==="escape"){f(!1);return}if(C.name==="space"){s($=>{let M=$+" ";return $.startsWith("/")?f(!1):We(M,e.workingDir).length>0&&(f(!0),c(0)),M});return}C.name&&C.name.length===1&&!C.ctrl&&!C.meta&&s($=>{let M=$+C.name;return(M.startsWith("/")||M.includes("@")||We(M,e.workingDir).length>0)&&(f(!0),c(0)),M})});let T=o.startsWith("/"),h=Math.max(0,Math.min(u-Math.floor(He/2),d.length-He)),v=d.slice(h,h+He),B=h>0,E=h+He<d.length;return qe("box",{flexDirection:"column",flexShrink:0,children:[D&&qe("box",{flexDirection:"column",paddingX:1,children:[B&&te("box",{children:te("text",{fg:t.textDim,children:` \u25B2 ${h} more`})}),v.map((C,$)=>{let l=h+$===u,z=C.type==="command"?t.warning:C.type==="mention"?t.info:C.type==="file"?t.success:t.textMuted;return qe("box",{flexDirection:"row",children:[te("text",{fg:l?t.primary:z,attributes:l?sn.BOLD:void 0,children:l?" \u276F ":" "}),te("text",{fg:l?t.text:z,children:C.text}),C.description?te("text",{fg:t.textDim,children:` ${C.description}`}):null]},C.text)}),E&&te("box",{children:te("text",{fg:t.textDim,children:` \u25BC ${d.length-h-He} more`})})]}),r.length>0&&te("box",{height:1,paddingX:1,children:te("text",{fg:t.primary,children:` \u{1F5BC} ${r.length} image${r.length>1?"s":""} attached`})}),qe("box",{height:3,borderStyle:"single",borderColor:t.borderFocused,flexDirection:"row",alignItems:"center",paddingX:1,children:[te("text",{fg:T?t.warning:t.primary,attributes:sn.BOLD,children:T?" / ":" > "}),o?qe(Qo,{children:[te("text",{fg:t.text,children:o}),w?te("text",{fg:t.textDim,children:w}):te("text",{fg:t.primary,children:"\u258A"})]}):te("text",{fg:t.textDim,children:e.placeholder||"Type a message... (^V paste, / commands, @ context, Tab accept)"})]})]})}var He,Ct=W(()=>{"use strict";V();rn();He=6});import{TextAttributes as ln}from"@opentui/core";import{useTerminalDimensions as Zo}from"@opentui/react";import{jsx as le,jsxs as dn}from"@opentui/react/jsx-runtime";function un(e){let{theme:n}=O(),t=n,o=Zo(),s=o.width||80,r=o.height||24,i=()=>{let T=process.env.HOME||"",h=e.workingDir;return T&&h.startsWith(T)?"~"+h.slice(T.length):h},u="Multi-provider AI coding assistant",c="v0.1.1",b=s<60||r<20,f=!b&&(s<80||r<30),A=b?null:f?tr:er,R=[["Provider",e.provider],["Model",e.model],["Theme",e.themeId],["Directory",i()]],d=Math.max(...R.map(([T])=>T.length)),w=[{key:"Enter",label:"Send message / start session",id:"start"},{key:"Ctrl+P",label:"Switch model",id:"model"},{key:"Ctrl+T",label:"Change theme",id:"theme"},{key:"Ctrl+N",label:"New session",id:"new"},{key:"Ctrl+S",label:"Browse sessions",id:"sessions"},{key:"Ctrl+X",label:"Command palette",id:"commands"},{key:"/setup",label:"Setup wizard",id:"setup"},{key:"Ctrl+C",label:"Quit",id:"quit"}],D=Math.max(...w.map(T=>T.key.length));return dn("box",{flexDirection:"column",flexGrow:1,flexShrink:1,overflow:"hidden",children:[dn("box",{flexDirection:"column",alignItems:"center",justifyContent:"center",flexGrow:1,children:[A&&A.map((T,h)=>le("text",{fg:t.primary,attributes:ln.BOLD,children:T},`logo-${h}`)),le("text",{fg:t.textDim,children:u}),le("text",{fg:t.textMuted,children:c}),le("text",{children:""}),R.map(([T,h],v)=>{let B=`${T.padStart(d)} ${h}`;return le("text",{fg:t.textDim,children:B},`info-${v}`)}),le("text",{children:""}),le("text",{fg:t.primary,attributes:ln.BOLD,children:"Actions"}),w.map((T,h)=>{let v=`${T.key.padStart(D)} ${T.label}`;return le("text",{fg:t.textMuted,children:v},`act-${h}`)}),le("text",{children:""}),le("text",{fg:t.textDim,children:"Powered by @opentui/react + @cdoing/ai"})]}),e.onSubmit&&le(ut,{onSubmit:e.onSubmit,workingDir:e.workingDir,placeholder:"Start typing to begin a session... (/ commands, @ context)"})]})}var er,tr,mn=W(()=>{"use strict";V();Ct();er=[" \u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 ","\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D ","\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2554\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2588\u2557","\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551","\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D"," \u255A\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D "],tr=["\u250C\u2500\u2510\u250C\u2510 \u250C\u2500\u2510\u252C\u250C\u2510\u250C\u250C\u2500\u2510","\u2502 \u2502\u2502\u2502 \u2502\u2502\u2502\u2502\u2502\u2502\u2502\u2502 \u252C","\u2514\u2500\u2518\u2514\u2518\u2514\u2500\u2518\u2514\u2500\u2518\u2518\u2514\u2518\u2514\u2500\u2518"]});import{TextAttributes as Be}from"@opentui/core";import{Fragment as sr,jsx as j,jsxs as ve}from"@opentui/react/jsx-runtime";function $e(e){return e.replace(/`([^`]+)`/g,"$1").replace(/\*\*([^*]+)\*\*/g,"$1").replace(/(?<!\w)\*([^*]+)\*(?!\w)/g,"$1")}function fn(e){let n=e.theme,{syntaxStyle:t}=O(),o=e.text.split(`
3
+ `),s=[],r=0;for(;r<o.length;){let i=o[r];if(i.startsWith("```")){let b=[i];for(r++;r<o.length;){if(b.push(o[r]),o[r].startsWith("```")){r++;break}r++}let f=b.join(`
4
+ `);s.push(j("box",{marginY:0,children:j("markdown",{syntaxStyle:t,streaming:!1,content:f,conceal:!0})},`code-${r}`));continue}if(i.startsWith("### ")){s.push(j("text",{fg:n.info,attributes:Be.BOLD,children:` \u25B8 ${$e(i.slice(4))}`},r)),r++;continue}if(i.startsWith("## ")){s.push(j("text",{fg:n.primary,attributes:Be.BOLD,children:` \u25B8\u25B8 ${$e(i.slice(3))}`},r)),r++;continue}if(i.startsWith("# ")){s.push(j("text",{fg:n.primary,attributes:Be.BOLD,children:`\u25B8\u25B8\u25B8 ${$e(i.slice(2))}`},r)),r++;continue}if(/^---+$/.test(i)||/^===+$/.test(i)||/^\*\*\*+$/.test(i)){s.push(j("text",{fg:n.textDim,children:"\u2500".repeat(40)},r)),r++;continue}let u=i.match(/^(\s*)[-*] (.*)/);if(u){let b=u[1]||"",f=$e(u[2]);s.push(j("text",{children:`${b}\u25CF ${f}`},r)),r++;continue}let c=i.match(/^(\s*)(\d+)\. (.*)/);if(c){let b=$e(c[3]);s.push(j("text",{children:`${c[1]}${c[2]}. ${b}`},r)),r++;continue}if(i.startsWith("> ")){s.push(j("text",{fg:n.textMuted,children:`\u2502 ${$e(i.slice(2))}`},r)),r++;continue}if(!i.trim()){s.push(j("text",{children:" "},r)),r++;continue}s.push(j("text",{children:$e(i)},r)),r++}return j("box",{flexDirection:"column",children:s})}function Tt(e){let n=new Date(e),t=n.getHours(),o=n.getMinutes(),s=t>=12?"PM":"AM";return t=t%12||12,`${t}:${o.toString().padStart(2,"0")} ${s}`}function gn(e){let{theme:n}=O(),t=n;return ve(sr,{children:[e.messages.length===0&&!e.isStreaming&&j("box",{paddingX:2,paddingY:1,children:j("text",{fg:t.textMuted,children:"Type a message to start chatting. Use / for commands, @ for context."})}),e.messages.map(o=>o.role==="user"?ve("box",{paddingX:1,paddingY:0,flexDirection:"row",children:[j("text",{fg:t.userText,attributes:Be.BOLD,children:"\u276F "}),j("text",{fg:t.userText,flexGrow:1,children:o.content}),e.showTimestamps&&o.timestamp&&j("text",{fg:t.textDim,children:` ${Tt(o.timestamp)}`})]},o.id):o.role==="assistant"?ve("box",{paddingLeft:1,marginTop:1,flexShrink:0,flexDirection:"column",children:[ve("box",{flexDirection:"row",children:[j("text",{fg:t.primary,attributes:Be.BOLD,children:"\u25C6 "}),e.showTimestamps&&o.timestamp&&j("text",{fg:t.textDim,children:` ${Tt(o.timestamp)}`})]}),j("box",{paddingLeft:2,children:j(fn,{text:o.content.trim(),theme:t})})]},o.id):o.role==="system"?ve("box",{paddingX:1,flexDirection:"row",children:[j("text",{fg:t.systemText,flexGrow:1,children:`\u26A1 ${o.content}`}),e.showTimestamps&&o.timestamp&&j("text",{fg:t.textDim,children:` ${Tt(o.timestamp)}`})]},o.id):o.role==="tool"?j(or,{name:o.toolName||"unknown",content:o.content,status:o.toolStatus||(o.isError?"error":"done")},o.id):null),e.isStreaming&&ve("box",{paddingLeft:1,marginTop:1,flexShrink:0,flexDirection:"column",children:[ve("box",{flexDirection:"row",children:[j("text",{fg:t.primary,attributes:Be.BOLD,children:"\u25C6 "}),j("text",{fg:t.primary,children:"\u258A"})]}),(e.streamingText||"").trim()&&j("box",{paddingLeft:2,children:j(fn,{text:(e.streamingText||"").trim(),theme:t})})]})]})}function or(e){let{theme:n}=O(),t=n,o=nr[e.name]||"\u2699\uFE0F",s=(()=>{switch(e.status){case"running":return"\u23F3";case"done":return"\u2713";case"error":return"\u2717"}})(),r=(()=>{switch(e.status){case"running":return t.toolRunning;case"done":return t.toolDone;case"error":return t.toolError}})(),i={file_read:"Read",file_write:"Write",file_edit:"Edit",multi_edit:"MultiEdit",shell_exec:"Bash",glob_search:"Search files",grep_search:"Search code",web_fetch:"Fetch",sub_agent:"Agent",list_dir:"List dir",codebase_search:"Codebase search"}[e.name]||e.name.replace(/_/g," ");return ve("box",{paddingX:2,children:[j("text",{fg:r,children:`${s} `}),j("text",{fg:t.toolText,children:`${o} ${i}`}),e.content&&j("text",{fg:t.textDim,children:` \u2014 ${rr(e.content,60)}`})]})}function rr(e,n){let t=e.split(`
5
+ `)[0]||"";return t.length>n?t.substring(0,n)+"\u2026":t}var nr,xn=W(()=>{"use strict";V();nr={file_read:"\u{1F4D6}",file_write:"\u270F\uFE0F",file_edit:"\u{1F527}",multi_edit:"\u{1F527}",shell_exec:"\u{1F4BB}",file_run:"\u25B6",glob_search:"\u{1F50D}",grep_search:"\u{1F50E}",codebase_search:"\u{1F50E}",web_fetch:"\u{1F310}",web_search:"\u{1F52E}",sub_agent:"\u{1F916}",todo:"\u{1F4CB}",list_dir:"\u{1F4C1}",view_diff:"\u{1F4CA}",view_repo_map:"\u{1F5FA}\uFE0F",code_verify:"\u2705",system_info:"\u2139\uFE0F",ast_edit:"\u{1F333}",notebook_edit:"\u{1F4D3}"}});import{TextAttributes as pn}from"@opentui/core";import{useState as ir}from"react";import{useKeyboard as ar}from"@opentui/react";import{jsx as Le,jsxs as cr}from"@opentui/react/jsx-runtime";function hn(e){let{theme:n}=O(),t=n,[o,s]=ir(0);return ar(r=>{r.name==="up"||r.name==="k"?s(i=>Math.max(0,i-1)):r.name==="down"||r.name==="j"?s(i=>Math.min(Mt.length-1,i+1)):r.name==="return"?e.onDecision(Mt[o].value):r.name==="1"?e.onDecision("allow"):r.name==="2"?e.onDecision("always"):r.name==="3"&&e.onDecision("deny")}),cr("box",{borderStyle:"single",borderColor:t.warning,paddingX:1,paddingY:0,flexDirection:"column",children:[Le("text",{fg:t.warning,attributes:pn.BOLD,children:"\u{1F510} Permission Required"}),Le("text",{fg:t.text,children:` ${e.toolName}: ${e.message}`}),Le("text",{fg:t.textDim,children:""}),Mt.map((r,i)=>Le("box",{children:Le("text",{fg:o===i?t.primary:t.textMuted,attributes:o===i?pn.BOLD:void 0,children:` ${o===i?"\u276F":" "} [${r.key}] ${r.label}`})},r.key)),Le("text",{fg:t.textDim,children:`
6
+ \u2191\u2193 Navigate Enter Select 1-3 Quick pick`})]})}var Mt,bn=W(()=>{"use strict";V();Mt=[{key:"1",label:"Allow once",value:"allow"},{key:"2",label:"Always allow",value:"always"},{key:"3",label:"Deny",value:"deny"}]});import{useState as lr,useEffect as dr}from"react";import{jsx as wn,jsxs as ur}from"@opentui/react/jsx-runtime";function Sn(e){let{theme:n}=O(),t=n,[o,s]=lr(0);return dr(()=>{let r=setInterval(()=>{s(i=>(i+1)%yn.length)},80);return()=>clearInterval(r)},[]),ur("box",{paddingX:1,height:1,flexDirection:"row",children:[wn("text",{fg:t.primary,children:yn[o]}),wn("text",{fg:t.textMuted,children:` ${e.label||"Thinking..."}`})]})}var yn,vn=W(()=>{"use strict";V();yn=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"]});function mt(e){process.stdout.isTTY&&process.stdout.write(`\x1B]0;${e}\x07`)}function kn(){process.stdout.isTTY&&process.stdout.write("\x1B]0;\x07")}var $t=W(()=>{"use strict"});import*as J from"fs";import*as Ee from"path";import*as Dn from"os";function Ne(){J.existsSync(pe)||J.mkdirSync(pe,{recursive:!0})}function Cn(){let e=Date.now().toString(36),n=Math.random().toString(36).slice(2,6);return`${e}-${n}`}function mr(e){let n=e.replace(/\n/g," ").trim();return n.length>60?n.substring(0,57)+"...":n}function At(e,n){return Ne(),{id:Cn(),title:"New conversation",createdAt:Date.now(),updatedAt:Date.now(),provider:e,model:n,messages:[]}}function Tn(e,n,t,o){e.messages.push({role:n,content:t,timestamp:Date.now(),toolName:o}),e.updatedAt=Date.now(),n==="user"&&e.title==="New conversation"&&(e.title=mr(t)),Mn(e)}function Mn(e){Ne();let n=Ee.join(pe,`${e.id}.json`);J.writeFileSync(n,JSON.stringify(e,null,2),"utf-8")}function Ye(e){Ne();let t=J.readdirSync(pe).filter(s=>s.endsWith(".json")).find(s=>s.startsWith(e)||s.replace(".json","")===e);if(!t)return null;let o=Ee.join(pe,t);try{return JSON.parse(J.readFileSync(o,"utf-8"))}catch{return null}}function Ae(){Ne();let e=J.readdirSync(pe).filter(t=>t.endsWith(".json")),n=[];for(let t of e)try{let o=JSON.parse(J.readFileSync(Ee.join(pe,t),"utf-8"));n.push(o)}catch{}return n.sort((t,o)=>o.updatedAt-t.updatedAt)}function ft(e){Ne();let t=J.readdirSync(pe).filter(o=>o.endsWith(".json")).find(o=>o.startsWith(e)||o.replace(".json","")===e);return t?(J.unlinkSync(Ee.join(pe,t)),!0):!1}function gt(e){let n=typeof e=="string"?Ye(e):e;if(!n)return null;Ne();let t={...n,id:Cn(),title:`Fork of: ${n.title}`,createdAt:Date.now(),updatedAt:Date.now(),messages:n.messages.map(o=>({...o}))};return Mn(t),t}function xt(e){let n=Date.now()-e,t=Math.floor(n/1e3);if(t<60)return"just now";let o=Math.floor(t/60);if(o<60)return`${o}m ago`;let s=Math.floor(o/60);if(s<24)return`${s}h ago`;let r=Math.floor(s/24);return r<30?`${r}d ago`:new Date(e).toLocaleDateString()}var pe,Pt=W(()=>{"use strict";pe=Ee.join(Dn.homedir(),".cdoing","conversations")});import{ContextProviderRegistry as fr,TerminalContextProvider as gr,UrlContextProvider as xr,TreeContextProvider as pr,CodebaseContextProvider as hr,ClipboardContextProvider as br,FileIncludeContextProvider as yr}from"@cdoing/core";function $n(){return he||(he=new fr,Xe=new gr,he.register(Xe),he.register(new xr),he.register(new pr),he.register(new hr),he.register(new br),he.register(new yr)),he}function An(e){$n(),Xe&&typeof Xe.push=="function"&&Xe.push(e)}async function Rn(e,n){let t=$n(),o=e,s=[];for(let r of Pn){let i=o.indexOf(r);if(i===-1)continue;let u=o.substring(i+r.length),c=u.search(/\s@|\n|$/),b=u.substring(0,c===-1?u.length:c).trim(),f=r+(b?" "+b:"");o=o.replace(f,"").trim();let A=r.substring(1),R=t.get(A);if(R)try{let d=await R.resolve(b,{workingDir:n});d&&s.push(`--- ${r} ---
7
+ ${d}`)}catch{}}return s.length>0&&(o=o+`
8
+
9
+ `+s.join(`
10
+
11
+ `)),o}function In(e){return Pn.some(n=>e.includes(n))}var he,Xe,Pn,On=W(()=>{"use strict";he=null,Xe=null;Pn=["@terminal","@url","@tree","@codebase","@clip","@file"]});import{useState as Pe,useRef as be,useEffect as wr}from"react";import{TextAttributes as Bn}from"@opentui/core";import{useKeyboard as Sr}from"@opentui/react";import*as N from"fs";import*as X from"path";import*as Rt from"os";import{execSync as vr}from"child_process";import{jsx as de,jsxs as It}from"@opentui/react/jsx-runtime";function Dr(e){let n=e.trim(),t=n.split(/\s+/)[0].toLowerCase();return kr.has(t)?n:null}function Cr(e){let{theme:n}=O(),t=n,[o,s]=Pe(0),r=[{label:"Interrupt \u2014 stop current response and send new message",action:e.onInterrupt},{label:"Queue \u2014 wait for current response, then send",action:e.onQueue},{label:"Cancel \u2014 discard new message",action:e.onCancel}];Sr(u=>{if(u.name==="escape"){e.onCancel();return}if(u.name==="up"||u.name==="k"){s(c=>Math.max(0,c-1));return}if(u.name==="down"||u.name==="j"){s(c=>Math.min(r.length-1,c+1));return}if(u.name==="return"){r[o].action();return}if(u.sequence==="1"||u.sequence==="i"){e.onInterrupt();return}if(u.sequence==="2"||u.sequence==="q"){e.onQueue();return}if(u.sequence==="3"){e.onCancel();return}});let i=e.message.length>50?e.message.slice(0,47)+"...":e.message;return It("box",{flexDirection:"column",flexShrink:0,paddingX:1,children:[de("text",{fg:t.warning,attributes:Bn.BOLD,children:" Agent is streaming. What to do with your message?"}),de("text",{fg:t.textDim,children:` "${i}"`}),de("text",{children:""}),r.map((u,c)=>de("text",{fg:c===o?t.primary:t.textMuted,attributes:c===o?Bn.BOLD:void 0,children:` ${c===o?"\u276F":" "} ${c+1}. ${u.label}`},c)),de("text",{fg:t.textDim,children:" \u2191\u2193 Navigate Enter Select i/q/Esc Quick keys"})]})}function Ln(e){let n=at(),{setMode:t}=O(),{toast:o}=en();mt("cdoing - session");let[s,r]=Pe([]),[i,u]=Pe(""),c=be(i);c.current=i;let[b,f]=Pe(!1),[A,R]=Pe(),[d,w]=Pe(null),[D,T]=Pe(null),h=be([]),v=be(0),B=be(0),E=be(0),C=be(null),$=be([]),M=be(0);C.current||(C.current=At(n.provider,n.model));let l=(x,y,g)=>{let a={id:`msg-${++E.current}`,role:x,content:y,timestamp:Date.now(),...g};return r(m=>[...m,a]),C.current&&(x==="user"||x==="assistant")&&Tn(C.current,x,y),a.id},z=(x,y)=>{r(g=>g.map(a=>a.id===x?{...a,...y}:a))},ee=()=>{try{let x=X.join(Rt.homedir(),".cdoing","config.json");if(N.existsSync(x))return JSON.parse(N.readFileSync(x,"utf-8"))}catch{}return{}},ne=(x,y)=>{let g=X.join(Rt.homedir(),".cdoing"),a=X.join(g,"config.json"),m={};try{N.existsSync(a)&&(m=JSON.parse(N.readFileSync(a,"utf-8")))}catch{}m[x]=y,N.existsSync(g)||N.mkdirSync(g,{recursive:!0}),N.writeFileSync(a,JSON.stringify(m,null,2),"utf-8")},se=()=>{try{let x=X.join(n.workingDir,".cdoing","settings.json");if(N.existsSync(x))return JSON.parse(N.readFileSync(x,"utf-8"));let y=X.join(n.workingDir,".claude","settings.json");if(N.existsSync(y))return JSON.parse(N.readFileSync(y,"utf-8"))}catch{}return{}},ce=x=>{let y={id:`bg-${++M.current}`,prompt:x,status:"running",startedAt:Date.now()};$.current=[...$.current,y],l("system",`Background job ${y.id} started: ${x.substring(0,60)}${x.length>60?"...":""}`);let g="",a={onToken:m=>{g+=m},onToolCall:()=>{},onToolResult:()=>{},onComplete:()=>{y.status="done",y.result=g.trim(),y.completedAt=Date.now(),$.current=[...$.current],l("system",`Background job ${y.id} completed. Use /jobs ${y.id} to see results.`)},onError:m=>{y.status="error",y.error=m.message,y.completedAt=Date.now(),$.current=[...$.current],l("system",`Background job ${y.id} failed: ${m.message}`)}};n.agent.run(x,a).catch(m=>{y.status="error",y.error=m instanceof Error?m.message:String(m),y.completedAt=Date.now()})},me=x=>{let[y,...g]=x.split(" "),a=g.join(" ").trim();switch(y){case"/clear":r([]),n.agent.clearHistory(),l("system","Chat cleared."),o("success","Chat cleared");break;case"/new":r([]),n.agent.clearHistory(),v.current=0,B.current=0,e.onTokens(0,0),e.onContextPercent(0),C.current=At(n.provider,n.model),l("system","New conversation started."),o("success","New conversation started");break;case"/model":{a&&n.rebuildAgent?(n.rebuildAgent(n.provider,a),l("system",`Model switched to: ${a}`),o("info",`Model: ${a}`)):a?(l("system","Model switching not available."),o("warning","Model switching not available")):l("system",`Current model: ${n.model}`);break}case"/provider":{if(a&&n.rebuildAgent){let{getDefaultModel:m}=rt("@cdoing/ai"),p=m(a)||n.model;n.rebuildAgent(a,p),l("system",`Provider switched to: ${a} (model: ${p})`),o("info",`Provider: ${a} (${p})`)}else a?(l("system","Provider switching not available."),o("warning","Provider switching not available")):l("system",`Current provider: ${n.provider}`);break}case"/mode":{let m=n.permissionManager?.mode||"ask";l("system",`Permission mode: ${m}
12
+ Available: ask, auto-edit, auto`);break}case"/dir":{if(a){let m=X.resolve(n.workingDir,a);N.existsSync(m)&&N.statSync(m).isDirectory()?(n.setWorkingDir&&n.setWorkingDir(m),l("system",`Working directory changed to: ${m}`)):l("system",`Directory not found: ${m}`)}else l("system",`Working directory: ${n.workingDir}`);break}case"/config":{if(a.startsWith("set ")){let m=a.substring(4).trim().split(/\s+/);if(m.length>=2){let[p,...S]=m,k=S.join(" ");if(p==="api-key"){let F=ee();F.apiKeys||(F.apiKeys={}),F.apiKeys[n.provider]=k,ne("apiKeys",F.apiKeys),l("system",`API key saved for ${n.provider}.`)}else p==="api-key-helper"?(ne("apiKeyHelper",k),l("system",`API key helper set to: ${k}`)):(ne(p,k),l("system",`Config ${p} set to: ${k}`))}else l("system","Usage: /config set <key> <value>")}else if(a==="show"||!a){let m=ee(),p=Object.entries(m).filter(([S])=>S!=="apiKeys").map(([S,k])=>` ${S}: ${typeof k=="object"?JSON.stringify(k):k}`);l("system",p.length>0?`Configuration:
13
+ `+p.join(`
14
+ `):"No configuration found. Run /setup to configure.")}else l("system","Usage: /config [show | set <key> <value>]");break}case"/theme":{a&&["dark","light"].includes(a)?(t(a),l("system",`Theme mode switched to: ${a}`),o("success",`Mode: ${a}`)):(l("system","Usage: /theme dark | light (or Ctrl+T for theme picker)"),o("warning","Usage: /theme dark | light"));break}case"/compact":n.agent.compressContext?(n.agent.compressContext(),l("system","Context compressed."),o("success","Context compressed")):(l("system","Context compression not available."),o("warning","Context compression not available"));break;case"/effort":{let m=["low","medium","high","max"];a&&m.includes(a)?(l("system",`Effort level set to: ${a}`),o("info",`Effort: ${a}`)):l("system",`Usage: /effort <${m.join("|")}>`);break}case"/plan":{a==="on"?l("system","Plan mode enabled. Agent will propose a plan before executing."):a==="off"?l("system","Plan mode disabled."):a==="show"?l("system","No active plan."):a==="approve"?l("system","No plan to approve."):a==="reject"?l("system","No plan to reject."):l("system","Usage: /plan <on|off|show|approve|reject>");break}case"/permissions":{let m=se(),p=m?.allow||[],S=m?.deny||[],k=["Permission rules:"];S.length>0&&k.push(" Deny: "+S.join(", ")),p.length>0&&k.push(" Allow: "+p.join(", ")),S.length===0&&p.length===0&&k.push(" No custom rules configured."),l("system",k.join(`
15
+ `));break}case"/hooks":{try{let m=X.join(n.workingDir,".cdoing","hooks.json");if(N.existsSync(m)){let p=JSON.parse(N.readFileSync(m,"utf-8")),S=Object.keys(p);l("system",S.length>0?`Configured hooks:
16
+ `+S.map(k=>` ${k}: ${JSON.stringify(p[k])}`).join(`
17
+ `):"No hooks configured.")}else l("system","No hooks file found (.cdoing/hooks.json).")}catch{l("system","No hooks configured.")}break}case"/rules":{try{let m=X.join(n.workingDir,".cdoing","rules");if(N.existsSync(m)){let p=N.readdirSync(m).filter(S=>S.endsWith(".md"));l("system",p.length>0?`Project rules:
18
+ `+p.map(S=>` ${S}`).join(`
19
+ `):"No rules found in .cdoing/rules/.")}else l("system","No rules directory found (.cdoing/rules/).")}catch{l("system","No rules configured.")}break}case"/memory":l("system","Memory store: not yet implemented in TUI. Coming soon.");break;case"/tasks":l("system","Task list: not yet implemented in TUI. Coming soon.");break;case"/context":l("system",["Context providers (use @ to invoke):"," @terminal \u2014 Recent terminal output"," @url \u2014 Fetch URL content"," @tree \u2014 Project file tree"," @codebase \u2014 Full codebase context"," @clip \u2014 Clipboard content"," @file \u2014 Include a file"].join(`
20
+ `));break;case"/mcp":l("system","MCP server management: not yet implemented in TUI. Coming soon.");break;case"/history":case"/ls":{let m=Ae().slice(0,20);if(m.length>0){let p=m.map(S=>{let k=S.id.substring(0,12),F=xt(S.updatedAt),re=S.messages.filter(xe=>xe.role==="user").length;return` ${k} ${F.padEnd(10)} (${re} msgs) ${S.title}`});l("system",`Conversations:
21
+ `+p.join(`
22
+ `)+`
23
+
24
+ Use /resume <id> to continue. Ctrl+S for interactive browser.`)}else l("system","No saved conversations found.");break}case"/resume":{if(!a){l("system","Usage: /resume <conversation-id>");break}let m=Ye(a);if(!m){l("system",`Conversation not found: ${a}`);break}C.current=m,r([]),n.agent.clearHistory(),v.current=0,B.current=0;for(let p of m.messages)if(p.role==="user"||p.role==="assistant"){let S={id:`msg-${++E.current}`,role:p.role,content:p.content,timestamp:p.timestamp};r(k=>[...k,S])}l("system",`Resumed conversation: ${m.title}`);break}case"/view":{if(!a){l("system","Usage: /view <conversation-id>");break}let m=Ye(a);if(!m){l("system",`Conversation not found: ${a}`);break}let p=m.messages.filter(S=>S.role!=="tool").slice(-20).map(S=>{let k=S.role==="user"?"\u276F":"\u25C6",F=S.content.length>100?S.content.substring(0,97)+"...":S.content;return` ${k} ${F.replace(/\n/g," ")}`});l("system",`Conversation: ${m.title}
25
+
26
+ ${p.join(`
27
+ `)}`);break}case"/fork":{let m=a?Ye(a):C.current;if(!m){l("system",a?`Conversation not found: ${a}`:"No active conversation to fork.");break}let p=gt(m);p?l("system",`Forked conversation: ${p.id.substring(0,12)} \u2014 "${p.title}"`):l("system","Failed to fork conversation.");break}case"/delete":{if(!a){l("system","Usage: /delete <conversation-id>");break}ft(a)?l("system",`Conversation deleted: ${a}`):l("system",`Conversation not found: ${a}`);break}case"/bg":{if(!a){l("system","Usage: /bg <prompt>");break}ce(a);break}case"/jobs":{let m=$.current;if(a){let p=m.find(S=>S.id===a);if(p){let S=p.completedAt?`${((p.completedAt-p.startedAt)/1e3).toFixed(1)}s`:`${((Date.now()-p.startedAt)/1e3).toFixed(1)}s (running)`,k=p.result?p.result.length>500?p.result.substring(0,497)+"...":p.result:p.error||"(no output)";l("system",`Job ${p.id} [${p.status}] (${S}):
28
+ Prompt: ${p.prompt}
29
+ Result: ${k}`)}else l("system",`Job not found: ${a}`)}else if(m.length>0){let p=m.map(S=>` ${S.status==="running"?"\u23F3":S.status==="done"?"\u2713":"\u2717"} ${S.id} ${S.status} ${S.prompt.substring(0,50)}${S.prompt.length>50?"...":""}`);l("system",`Background jobs:
30
+ `+p.join(`
31
+ `))}else l("system","No background jobs.");break}case"/btw":{if(!a){l("system","Usage: /btw <question>");break}let m={id:`msg-${++E.current}`,role:"user",content:`(btw) ${a}`,timestamp:Date.now()};r(k=>[...k,m]),f(!0),u(""),e.onStatus("Processing...");let p="",S={onToken:k=>{p+=k,u(F=>F+k)},onToolCall:()=>{},onToolResult:()=>{},onComplete:()=>{if(p.trim()){let k={id:`msg-${++E.current}`,role:"assistant",content:p.trim(),timestamp:Date.now()};r(F=>[...F,k]),u("")}f(!1),e.onStatus("Ready")},onError:k=>{l("system",`Error: ${k.message}`),f(!1),e.onStatus("Error")}};n.agent.run(a,S).catch(k=>{l("system",`Error: ${k instanceof Error?k.message:String(k)}`),f(!1),e.onStatus("Error")});break}case"/login":case"/setup":e.onOpenDialog?e.onOpenDialog("setup"):l("system","Setup wizard: configure via ~/.cdoing/config.json or run the base CLI with --login.");break;case"/logout":{try{let{fullLogout:m}=rt("@cdoing/core"),p=m(n.provider);n.agent.invalidate(),l("system",p)}catch{l("system","OAuth logout not available.")}break}case"/auth-status":{let m=ee(),p=["Authentication Status:",""];if(p.push("Stored API keys:"),m.apiKeys&&Object.keys(m.apiKeys).length>0)for(let[F,re]of Object.entries(m.apiKeys)){let xe=String(re),vt=xe.slice(0,8)+"..."+xe.slice(-4);p.push(` \u2713 ${F}: ${vt}`)}else p.push(" None");p.push(""),p.push("Environment variables:");let S=[["ANTHROPIC_API_KEY",process.env.ANTHROPIC_API_KEY],["OPENAI_API_KEY",process.env.OPENAI_API_KEY],["GOOGLE_API_KEY",process.env.GOOGLE_API_KEY]],k=!1;for(let[F,re]of S)if(re){k=!0;let xe=re.slice(0,8)+"..."+re.slice(-4);p.push(` \u2713 ${F}: ${xe}`)}k||p.push(" None"),l("system",p.join(`
32
+ `));break}case"/doctor":{let m=["System health check:"],p=ee(),S=process.env[`${n.provider.toUpperCase()}_API_KEY`];m.push(` Provider: ${n.provider} ${p.apiKeys?.[n.provider]||S?"\u2713 API key found":"\u2717 No API key"}`),m.push(` Model: ${n.model}`),m.push(` Working dir: ${n.workingDir} ${N.existsSync(n.workingDir)?"\u2713":"\u2717"}`);let k=N.existsSync(X.join(n.workingDir,".cdoing")),F=N.existsSync(X.join(n.workingDir,".claude"));m.push(` Project config: ${k?".cdoing/ \u2713":F?".claude/ \u2713":"\u2717 none"}`),m.push(` Node: ${process.version}`),m.push(` Platform: ${process.platform} ${process.arch}`);let re=Ae();m.push(` Conversations: ${re.length} saved`);let xe=$.current.filter(vt=>vt.status==="running");xe.length>0&&m.push(` Background jobs: ${xe.length} running`),l("system",m.join(`
33
+ `));break}case"/init":{let m=X.join(n.workingDir,".cdoing");if(N.existsSync(m))l("system","Project already initialized (.cdoing/ exists).");else try{N.mkdirSync(m,{recursive:!0}),N.mkdirSync(X.join(m,"rules"),{recursive:!0}),N.writeFileSync(X.join(m,"config.md"),`# Project Configuration
34
+
35
+ Describe your project here for the AI assistant.
36
+ `,"utf-8"),l("system","Project initialized. Created .cdoing/ with config.md and rules/.")}catch(p){l("system",`Failed to initialize: ${p instanceof Error?p.message:String(p)}`)}break}case"/queue":l("system","Message queue is empty.");break;case"/help":l("system",["Available commands:",""," Session"," /clear Clear chat history"," /new Start new conversation"," /compact Compress context window"," /btw <question> Ask without adding to history",""," Configuration"," /model [name] Show/change model"," /provider [name] Show/change provider"," /mode Show permission mode"," /dir [path] Show/change working directory"," /config Show configuration"," /config set k v Set a config value"," /theme <mode> Switch theme (dark/light/auto)"," /effort <level> Set effort (low/medium/high/max)"," /plan <on|off> Toggle plan mode",""," History"," /history, /ls List saved conversations"," /resume <id> Resume conversation"," /view <id> View conversation messages"," /fork [id] Fork current/specified conversation"," /delete <id> Delete conversation",""," Background"," /bg <prompt> Run prompt in background"," /jobs [id] List/inspect background jobs",""," System"," /permissions Show permission rules"," /hooks Show configured hooks"," /rules Show project rules"," /context Show context providers"," /mcp MCP server management"," /doctor System health check"," /usage Show token usage"," /auth-status Show authentication status",""," /setup Run setup wizard"," /login Open setup wizard"," /logout Clear OAuth tokens"," /init Initialize project config"," /exit Quit","","Keyboard shortcuts:"," Ctrl+V Paste text or image"," Ctrl+U Clear input line"," Ctrl+W Delete last word"," Ctrl+N New session"," Ctrl+P Model picker"," Ctrl+S Session browser"," Tab/\u2192 Accept autocomplete"," \u2191/\u2193 Navigate suggestions"," Escape Close dropdown","","Shell: prefix with ! or type commands directly (ls, git, npm, etc.)","Context: use @terminal, @url, @tree, @codebase, @clip, @file in messages"].join(`
37
+ `));break;case"/usage":l("system",`Tokens: ${v.current.toLocaleString()}\u2192${B.current.toLocaleString()} (${(v.current+B.current).toLocaleString()} total)`);break;case"/exit":case"/quit":process.exit(0);break;default:l("system",`Unknown command: ${y}. Type /help for available commands.`),o("error",`Unknown command: ${y}`)}},fe=x=>{l("user",`!${x}`);let y="",g="";try{y=vr(x,{cwd:n.workingDir,env:{...process.env},encoding:"utf-8",timeout:12e4,maxBuffer:10*1024*1024})}catch(m){m.stdout&&(y=String(m.stdout)),m.stderr&&(g=String(m.stderr)),m.status!==void 0&&m.status!==0?g+=`
38
+ [exited with code ${m.status}]`:!m.stdout&&!m.stderr&&m.message&&(g=m.message)}let a=(y+(g?`
39
+ ${g}`:"")).trim();l("system",`$ ${x}
40
+ ${a||"(no output)"}`),An(`$ ${x}
41
+ ${a}`)},P=(x,y)=>{let g=c.current.trim();n.agent.interrupt(g),g&&(l("assistant",g+`
42
+
43
+ *(interrupted)*`),u("")),f(!1),e.onStatus("Ready"),R(void 0),e.onActiveTool(void 0),T(null),setTimeout(()=>{ie(x,y)},100)},L=x=>{h.current.push(x),l("system",`\u{1F4EC} Queued message (${h.current.length} in queue)`),T(null)},G=()=>{if(h.current.length>0){let x=h.current.shift();setTimeout(()=>ie(x),100)}},U=async(x,y)=>{if(x.startsWith("/")){me(x);return}let g=x.startsWith("!")?x.slice(1).trim():Dr(x);if(g){let a=g.trim().split(/\s+/);if(a[0]==="cd"){let m=a.slice(1).join(" ")||process.env.HOME||"/",p=X.resolve(n.workingDir,m);N.existsSync(p)&&N.statSync(p).isDirectory()?(n.setWorkingDir&&n.setWorkingDir(p),l("system",`Working directory changed to: ${p}`)):l("system",`cd: no such directory: ${p}`);return}fe(g);return}if(b){T({text:x,images:y});return}await ie(x,y)},oe=be(!1);wr(()=>{e.initialMessage&&!oe.current&&(oe.current=!0,U(e.initialMessage.text,e.initialMessage.images))},[]);let ie=async(x,y)=>{let g=x;if(In(x))try{g=await Rn(x,n.workingDir)}catch{}l("user",x+(y&&y.length>0?` [${y.length} image${y.length>1?"s":""}]`:"")),f(!0),u(""),e.onStatus("Processing...");let a,m=0,p={onToken:S=>{u(k=>k+S)},onToolCall:(S,k)=>{let F=c.current.trim();F&&(l("assistant",F),u(""));let re=k?.description||"";a=l("tool",re,{toolName:S,toolStatus:"running"}),R(S),e.onActiveTool(S)},onToolResult:(S,k,F)=>{if(a){let re=k.length>80?k.substring(0,77)+"...":k;z(a,{content:re,toolStatus:F?"error":"done",isError:F}),a=void 0}R(void 0),e.onActiveTool(void 0)},onComplete:()=>{let S=c.current.trim();S&&(l("assistant",S),u("")),f(!1),e.onStatus("Ready"),R(void 0),e.onActiveTool(void 0),e.onTokens(v.current,B.current),G()},onError:S=>{let k=c.current.trim();k&&(l("assistant",k),u("")),l("system",`Error: ${S.message}`),o("error",S.message),f(!1),e.onStatus("Error"),R(void 0),e.onActiveTool(void 0)},onUsage:S=>{m+=S.inputTokens,v.current+=S.inputTokens,B.current+=S.outputTokens,e.onTokens(v.current,B.current);let k=Math.min(100,m/2e5*100);e.onContextPercent(k)}};try{await n.agent.run(g,p,y)}catch(S){let k=S instanceof Error?S.message:String(S);l("system",`Error: ${k}`),o("error",k),f(!1),e.onStatus("Error")}};return It("box",{flexDirection:"column",flexGrow:1,paddingLeft:2,paddingRight:2,paddingTop:1,paddingBottom:1,gap:1,children:[de("scrollbox",{stickyScroll:!0,stickyStart:"bottom",flexGrow:1,scrollY:!0,children:de(gn,{messages:s,streamingText:i,isStreaming:b})}),It("box",{flexDirection:"column",flexShrink:0,children:[d&&de(hn,{toolName:d.toolName,message:d.message,onDecision:x=>{d.resolve(x),w(null)}}),D&&de(Cr,{message:D.text,onInterrupt:()=>P(D.text,D.images),onQueue:()=>L(D.text),onCancel:()=>T(null)}),b&&!i&&!D&&de(Sn,{label:A||"Thinking..."}),de(ut,{onSubmit:U,disabled:!1,placeholder:b?"Type to interrupt or queue...":void 0,workingDir:n.workingDir})]})]})}var kr,En=W(()=>{"use strict";xn();Ct();bn();vn();ct();V();Dt();$t();Pt();On();kr=new Set(["ls","ll","la","pwd","cd","mkdir","rmdir","rm","cp","mv","cat","head","tail","touch","echo","env","git","npm","yarn","pnpm","npx","node","ts-node","python","python3","pip","pip3","docker","docker-compose","grep","find","which","whereis","curl","wget","chmod","chown","ln","ps","kill","df","du","open","code","vim","vi","nano","less","more","man","top","htop"])});import{TextAttributes as Tr}from"@opentui/core";import{Fragment as pt,jsx as Q,jsxs as Re}from"@opentui/react/jsx-runtime";function Nn(e){let{theme:n}=O(),t=n,o=process.env.HOME||"",s=o&&e.workingDir.startsWith(o)?"~"+e.workingDir.slice(o.length):e.workingDir,r=e.tokens?` ${e.tokens.input.toLocaleString()}\u2192${e.tokens.output.toLocaleString()}`:"",i=e.contextPercent?Math.round(e.contextPercent):0,u=i>0?` ctx:${i}%`:"";return Re("box",{height:1,flexDirection:"row",justifyContent:"space-between",children:[Re("box",{flexDirection:"row",children:[Q("text",{fg:t.primary,attributes:Tr.BOLD,children:` ${e.provider}`}),Q("text",{fg:t.textMuted,children:`/${e.model}`}),Q("text",{fg:t.textDim,children:" \u2502 "}),Q("text",{fg:t.warning,children:e.mode}),r&&Re(pt,{children:[Q("text",{fg:t.textDim,children:" \u2502"}),Q("text",{fg:t.textMuted,children:r})]}),u&&Re(pt,{children:[Q("text",{fg:t.textDim,children:" \u2502"}),Q("text",{fg:i>75?t.warning:t.textMuted,children:u})]}),e.activeTool&&Re(pt,{children:[Q("text",{fg:t.textDim,children:" \u2502 "}),Q("text",{fg:t.toolRunning,children:`\u23F3 ${e.activeTool}`})]}),e.isProcessing&&!e.activeTool&&Re(pt,{children:[Q("text",{fg:t.textDim,children:" \u2502 "}),Q("text",{fg:t.primary,children:"thinking..."})]})]}),Re("box",{flexDirection:"row",children:[Q("text",{fg:t.textDim,children:s}),Q("text",{fg:t.textDim,children:" \u2502 "}),Q("text",{fg:t.textMuted,children:"^N:New ^P:Model ^C:Quit"})]})]})}var jn=W(()=>{"use strict";V()});import{TextAttributes as Mr}from"@opentui/core";import{jsx as ze,jsxs as $r}from"@opentui/react/jsx-runtime";function _n(e){let{theme:n}=O(),t=n,o=e.tokens?e.tokens.input.toLocaleString():"0",s=e.tokens?e.tokens.output.toLocaleString():"0",r=e.contextPercent?Math.round(e.contextPercent):0,i=r>75?t.error:r>50?t.warning:t.success,u=e.status==="Error"?t.error:e.status==="Processing..."?t.warning:t.success,c=` \u25C6 ${e.title||"Session"} \u2502 ${e.provider}/${e.model} \u2502 ${o}\u2192${s} tokens`;return $r("box",{height:1,flexDirection:"row",children:[ze("text",{fg:t.primary,attributes:Mr.BOLD,children:c}),ze("text",{fg:t.border,children:" \u2502 "}),ze("text",{fg:i,children:`${r}%`}),ze("box",{flexGrow:1}),ze("text",{fg:u,children:`${e.status} `})]})}var Gn=W(()=>{"use strict";V()});import{jsx as Ot,jsxs as Ar}from"@opentui/react/jsx-runtime";function Kn(e){let{theme:n}=O(),t=n,o=process.env.HOME||"",s=o&&e.workingDir.startsWith(o)?"~"+e.workingDir.slice(o.length):e.workingDir;return Ar("box",{height:1,flexDirection:"row",children:[Ot("text",{fg:t.textDim,children:` ${s}`}),Ot("box",{flexGrow:1}),Ot("text",{fg:t.textMuted,children:"^N:New ^P:Model ^T:Theme ^S:Sessions ^B:Sidebar "})]})}var Un=W(()=>{"use strict";V()});import{TextAttributes as Pr}from"@opentui/core";import{jsx as ht,jsxs as Ir}from"@opentui/react/jsx-runtime";function Je(e,n){return e.length>n?e.slice(0,n-1)+"\u2026":e}function Rr(e,n){let t=Math.round(e/100*n);return"\u2588".repeat(t)+"\u2591".repeat(n-t)}function Fn(e){let{theme:n}=O(),t=n,o=process.env.HOME||"",s=o&&e.workingDir.startsWith(o)?"~"+e.workingDir.slice(o.length):e.workingDir,r=e.contextPercent?Math.round(e.contextPercent):0,i=r>75?t.error:r>50?t.warning:t.success,u=e.tokens?e.tokens.input.toLocaleString():"0",c=e.tokens?e.tokens.output.toLocaleString():"0",b=e.status==="Error"?t.error:e.status==="Processing..."?t.warning:t.success,f=[],A=()=>f.push({text:"\u2502",fg:t.border}),R=D=>{f.push({text:`\u2502 ${D}`,fg:t.primary,bold:!0})},d=(D,T,h)=>{let v=D?`\u2502 ${D.padEnd(10)} ${Je(T,je-14)}`:`\u2502 ${Je(T,je-4)}`;f.push({text:v,fg:h||t.text})},w=(D,T)=>{f.push({text:`\u2502 ${D.padEnd(10)} ${T}`,fg:t.textDim})};if(R("Session"),d("",e.sessionTitle||"New Session"),d("Dir",Je(s,je-14)),d("Provider",e.provider),d("Model",e.model),e.themeId&&d("Theme",e.themeId),A(),R("Context"),d("Input",`${u} tokens`),d("Output",`${c} tokens`),f.push({text:`\u2502 ${Rr(r,16)} ${r}%`,fg:i}),A(),R("Activity"),f.push({text:`\u2502 Status ${e.status}`,fg:b}),e.activeTool&&f.push({text:`\u2502 Tool ${Je(e.activeTool,je-14)}`,fg:t.toolRunning}),A(),e.modifiedFiles&&e.modifiedFiles.length>0){R(`Files (${e.modifiedFiles.length})`);for(let D of e.modifiedFiles.slice(0,6)){let T=D.path.split("/").pop()||D.path,h=(D.additions>0?` +${D.additions}`:"")+(D.deletions>0?` -${D.deletions}`:"");f.push({text:`\u2502 ${Je(T,je-12)}${h}`,fg:t.text})}e.modifiedFiles.length>6&&f.push({text:`\u2502 \u2026 ${e.modifiedFiles.length-6} more`,fg:t.textDim}),A()}return R("Shortcuts"),w("Ctrl+B","Sidebar"),w("Ctrl+N","New session"),w("Ctrl+P","Model"),w("Ctrl+T","Theme"),w("Ctrl+S","Sessions"),w("Ctrl+X","Commands"),w("F1","Help"),ht("box",{width:je+2,flexDirection:"column",children:Ir("box",{flexDirection:"column",flexGrow:1,children:[f.map((D,T)=>ht("text",{fg:D.fg,attributes:D.bold?Pr.BOLD:void 0,children:D.text},T)),ht("box",{flexGrow:1,children:ht("text",{fg:t.border,children:"\u2502"})})]})})}var je,Wn=W(()=>{"use strict";V();je=34});import{TextAttributes as Hn}from"@opentui/core";import{useState as Or}from"react";import{useKeyboard as Br}from"@opentui/react";import{jsx as Ie,jsxs as qn}from"@opentui/react/jsx-runtime";function Vn(e){let{theme:n}=O(),t=n,o=Lr[e.provider]||[],[s,r]=Or(Math.max(0,o.findIndex(i=>i.id===e.currentModel)));return Br(i=>{if(i.name==="escape"||i.ctrl&&i.name==="c")e.onClose();else if(i.name==="up"||i.name==="k")r(u=>Math.max(0,u-1));else if(i.name==="down"||i.name==="j")r(u=>Math.min(o.length-1,u+1));else if(i.name==="return"){let u=o[s];u&&e.onSelect(u.id)}}),qn("box",{borderStyle:"double",borderColor:t.primary,paddingX:1,paddingY:1,flexDirection:"column",position:"absolute",top:"30%",left:"20%",width:"60%",children:[Ie("text",{fg:t.primary,attributes:Hn.BOLD,children:" Select Model"}),Ie("text",{fg:t.textDim,children:` Provider: ${e.provider}`}),Ie("text",{fg:t.textDim,children:""}),o.map((i,u)=>qn("box",{children:[Ie("text",{fg:u===s?t.primary:t.text,attributes:u===s?Hn.BOLD:void 0,children:` ${u===s?"\u276F":" "} ${i.name}`}),Ie("text",{fg:t.textDim,children:i.hint?` ${i.hint}`:""}),Ie("text",{fg:i.id===e.currentModel?t.success:t.textDim,children:i.id===e.currentModel?" \u25CF":""})]},i.id)),Ie("text",{fg:t.textDim,children:`
44
+ \u2191\u2193 Navigate Enter Select Esc Close`})]})}var Lr,Yn=W(()=>{"use strict";V();Lr={anthropic:[{id:"claude-sonnet-4-6",name:"Claude Sonnet 4.6",hint:"fast & smart"},{id:"claude-opus-4-6",name:"Claude Opus 4.6",hint:"most capable"},{id:"claude-haiku-4-5",name:"Claude Haiku 4.5",hint:"fastest"}],openai:[{id:"gpt-4o",name:"GPT-4o",hint:"recommended"},{id:"gpt-4o-mini",name:"GPT-4o mini",hint:"fastest"},{id:"o3",name:"o3",hint:"reasoning"}],google:[{id:"gemini-2.0-flash",name:"Gemini 2.0 Flash",hint:"fast"},{id:"gemini-2.5-pro",name:"Gemini 2.5 Pro",hint:"most capable"}]}});import{TextAttributes as bt}from"@opentui/core";import{useState as Xn,useMemo as zn}from"react";import{useKeyboard as Er}from"@opentui/react";import{jsx as ae,jsxs as Bt}from"@opentui/react/jsx-runtime";function Jn(e,n){if(!e)return!0;let t=n.toLowerCase(),o=e.toLowerCase(),s=0;for(let r=0;r<t.length&&s<o.length;r++)t[r]===o[s]&&s++;return s===o.length}function Qn(e){let{theme:n}=O(),t=n,[o,s]=Xn(""),[r,i]=Xn(0),u=zn(()=>Nr.filter(d=>Jn(o,d.label)||Jn(o,d.category)),[o]),c=zn(()=>{let d=new Map;for(let w of u){let D=d.get(w.category);D?D.push(w):d.set(w.category,[w])}return d},[u]),b=u,f=Math.min(r,Math.max(0,b.length-1));Er(d=>{if(d.name==="escape"){e.onClose();return}if(d.name==="return"){let w=b[f];w&&e.onSelect(w.id);return}if(d.name==="up"||d.name==="k"&&!o){i(w=>Math.max(0,w-1));return}if(d.name==="down"||d.name==="j"&&!o){i(w=>Math.min(b.length-1,w+1));return}if(d.name==="backspace"){s(w=>w.slice(0,-1)),i(0);return}d.sequence&&d.sequence.length===1&&!d.ctrl&&!d.meta&&(s(w=>w+d.sequence),i(0))});let A=0,R=[];for(let[d,w]of c){R.push(ae("text",{fg:t.secondary,attributes:bt.BOLD,children:` ${d}`},`cat-${d}`));for(let D of w){let T=A===f,h=D.shortcut?` ${D.shortcut}`:"";R.push(Bt("box",{flexDirection:"row",children:[ae("text",{fg:T?t.primary:t.text,attributes:T?bt.BOLD:void 0,children:` ${T?">":" "} ${D.label}`}),ae("text",{fg:t.textDim,children:h})]},D.id)),A++}R.push(ae("text",{fg:t.textDim,children:""},`spacer-${d}`))}return Bt("box",{borderStyle:"double",borderColor:t.primary,paddingX:1,paddingY:1,flexDirection:"column",position:"absolute",top:"15%",left:"15%",width:"70%",children:[ae("text",{fg:t.primary,attributes:bt.BOLD,children:" Command Palette"}),ae("text",{fg:t.textDim,children:""}),Bt("box",{flexDirection:"row",children:[ae("text",{fg:t.textMuted,children:" > "}),ae("text",{fg:t.text,children:o||""}),ae("text",{fg:t.primary,attributes:bt.BOLD,children:"_"})]}),ae("text",{fg:t.textDim,children:""}),b.length>0?R:ae("text",{fg:t.textDim,children:" No matching commands"}),ae("text",{fg:t.textDim,children:" \u2191\u2193/jk Navigate Enter Select Esc Close"})]})}var Nr,Zn=W(()=>{"use strict";V();Nr=[{id:"session:new",label:"New Session",shortcut:"Ctrl+N",category:"Session"},{id:"session:browse",label:"Browse Sessions",shortcut:"Ctrl+S",category:"Session"},{id:"session:clear",label:"Clear History",shortcut:"",category:"Session"},{id:"model:switch",label:"Switch Model",shortcut:"Ctrl+P",category:"Model"},{id:"theme:picker",label:"Browse Themes",shortcut:"Ctrl+T",category:"Appearance"},{id:"theme:dark",label:"Dark Mode",shortcut:"",category:"Appearance"},{id:"theme:light",label:"Light Mode",shortcut:"",category:"Appearance"},{id:"display:sidebar",label:"Toggle Sidebar",shortcut:"Ctrl+B",category:"Appearance"},{id:"system:status",label:"System Status",shortcut:"",category:"System"},{id:"system:help",label:"Help",shortcut:"F1",category:"System"},{id:"system:doctor",label:"Doctor",shortcut:"",category:"System"},{id:"system:setup",label:"Setup Wizard",shortcut:"",category:"System"},{id:"system:exit",label:"Exit",shortcut:"Ctrl+C",category:"System"}]});import{TextAttributes as eo}from"@opentui/core";import{useState as jr}from"react";import{useKeyboard as _r}from"@opentui/react";import{jsx as ye,jsxs as to}from"@opentui/react/jsx-runtime";function Fr(){let e=[];e.push({type:"header",text:"Keyboard Shortcuts"}),e.push({type:"blank"});for(let n of Gr)e.push({type:"entry",key:n.key,description:n.description});e.push({type:"blank"}),e.push({type:"header",text:"Slash Commands"}),e.push({type:"blank"});for(let n of Kr)e.push({type:"entry",key:n.key,description:n.description});e.push({type:"blank"}),e.push({type:"header",text:"@Mentions"}),e.push({type:"blank"});for(let n of Ur)e.push({type:"entry",key:n.key,description:n.description});return e}function no(e){let{theme:n}=O(),t=n,[o,s]=jr(0),r=Math.max(0,yt.length-Qe);_r(c=>{if(c.name==="escape"||c.name==="q"){e.onClose();return}if(c.name==="up"||c.name==="k"){s(b=>Math.max(0,b-1));return}if(c.name==="down"||c.name==="j"){s(b=>Math.min(r,b+1));return}if(c.name==="pageup"){s(b=>Math.max(0,b-Qe));return}if(c.name==="pagedown"){s(b=>Math.min(r,b+Qe));return}if(c.name==="home"){s(0);return}if(c.name==="end"){s(r);return}});let i=yt.slice(o,o+Qe),u=20;return to("box",{borderStyle:"double",borderColor:t.primary,paddingX:2,paddingY:1,flexDirection:"column",position:"absolute",top:"10%",left:"15%",width:"70%",height:"80%",children:[ye("text",{fg:t.primary,attributes:eo.BOLD,children:" Help"}),ye("text",{fg:t.textDim,children:""}),i.map((c,b)=>{if(c.type==="blank")return ye("text",{fg:t.textDim,children:""},`line-${o+b}`);if(c.type==="header")return ye("text",{fg:t.primary,attributes:eo.BOLD,children:` ${c.text}`},`line-${o+b}`);let f=(c.key||"").padEnd(u);return to("box",{flexDirection:"row",children:[ye("text",{fg:t.secondary,children:` ${f}`}),ye("text",{fg:t.textMuted,children:c.description||""})]},`line-${o+b}`)}),ye("text",{fg:t.textDim,children:""}),ye("text",{fg:t.textDim,children:` ${o>0?"...":" "} ${o+1}-${Math.min(o+Qe,yt.length)} of ${yt.length} ${o<r?"...":" "}`}),ye("text",{fg:t.textDim,children:" Up/Down/j/k Scroll PgUp/PgDn Page Esc/q Close"})]})}var Gr,Kr,Ur,yt,Qe,oo=W(()=>{"use strict";V();Gr=[{key:"Ctrl+N",description:"New session"},{key:"Ctrl+P",description:"Switch model"},{key:"Ctrl+S",description:"Browse sessions"},{key:"Ctrl+X",description:"Command palette"},{key:"F1",description:"Show this help"},{key:"Ctrl+V",description:"Paste text or image"},{key:"Ctrl+U",description:"Clear input line"},{key:"Ctrl+W",description:"Delete last word"},{key:"Tab / ->",description:"Accept autocomplete"},{key:"Up / Down",description:"Navigate suggestions"},{key:"Escape",description:"Close dialog / dropdown"},{key:"Ctrl+C",description:"Quit"}],Kr=[{key:"/help",description:"Show help"},{key:"/clear",description:"Clear chat history"},{key:"/new",description:"Start new conversation"},{key:"/compact",description:"Compress context window"},{key:"/btw <question>",description:"Ask without adding to history"},{key:"/model [name]",description:"Show/change model"},{key:"/provider [name]",description:"Show/change provider"},{key:"/mode",description:"Show permission mode"},{key:"/dir [path]",description:"Show/change working directory"},{key:"/config",description:"Show configuration"},{key:"/config set k v",description:"Set a config value"},{key:"/theme <mode>",description:"Switch theme (dark/light/auto)"},{key:"/effort <level>",description:"Set effort level"},{key:"/plan <on|off>",description:"Toggle plan mode"},{key:"/history",description:"List saved conversations"},{key:"/resume <id>",description:"Resume conversation"},{key:"/view <id>",description:"View conversation messages"},{key:"/fork [id]",description:"Fork conversation"},{key:"/delete <id>",description:"Delete conversation"},{key:"/bg <prompt>",description:"Run prompt in background"},{key:"/jobs [id]",description:"List/inspect background jobs"},{key:"/permissions",description:"Show permission rules"},{key:"/hooks",description:"Show configured hooks"},{key:"/rules",description:"Show project rules"},{key:"/context",description:"Show context providers"},{key:"/mcp",description:"MCP server management"},{key:"/doctor",description:"System health check"},{key:"/usage",description:"Show token usage"},{key:"/auth-status",description:"Show authentication status"},{key:"/setup",description:"Run setup wizard"},{key:"/login",description:"Open setup wizard"},{key:"/logout",description:"Clear OAuth tokens"},{key:"/init",description:"Initialize project config"},{key:"/exit",description:"Quit"}],Ur=[{key:"@terminal",description:"Recent terminal output"},{key:"@url",description:"Fetch URL content"},{key:"@tree",description:"Directory tree"},{key:"@codebase",description:"Search codebase"},{key:"@clip",description:"Clipboard contents"},{key:"@file",description:"Include file"}];yt=Fr(),Qe=15});import{TextAttributes as ke}from"@opentui/core";import{useState as Ze,useMemo as Wr}from"react";import{useKeyboard as Hr,useTerminalDimensions as qr}from"@opentui/react";import{Fragment as Vr,jsx as H,jsxs as _e}from"@opentui/react/jsx-runtime";function ro(e){let{theme:n,themeId:t,mode:o,customBg:s,setThemeId:r,setMode:i,setCustomBg:u}=O(),c=n,b=qr(),f=t,A=o,R=s,d=Ut(),[w,D]=Ze("mode"),[T,h]=Ze(o==="dark"?0:1),[v,B]=Ze(s||""),[E,C]=Ze(""),[$,M]=Ze(Math.max(0,d.indexOf(t))),l=Wr(()=>{if(!E)return d;let P=E.toLowerCase();return d.filter(L=>{let G=Te[L];return L.toLowerCase().includes(P)||G.name.toLowerCase().includes(P)})},[E,d]),z=Math.min($,Math.max(0,l.length-1)),ee=Math.max(5,Math.min(l.length,(b.height||24)-18)),ne=Math.max(0,z-ee+3),se=l.slice(ne,ne+ee),ce=[{id:"dark",label:"Dark Mode"},{id:"light",label:"Light Mode"}],me=()=>{D(P=>{let L=Lt.indexOf(P);return Lt[(L+1)%Lt.length]})},fe=P=>/^#[0-9a-fA-F]{6}$/.test(P);return Hr(P=>{if(P.name==="escape"){r(f),i(A),u(R),e.onClose();return}if(P.name==="tab"){me();return}if(w==="mode"){if(P.name==="up"||P.name==="k"){h(L=>Math.max(0,L-1));return}if(P.name==="down"||P.name==="j"){h(L=>Math.min(ce.length-1,L+1));return}if(P.name==="return"){i(ce[T].id),me();return}return}if(w==="custombg"){if(P.name==="return"){v===""||v==="none"?u(null):fe(v)&&u(v),me();return}if(P.name==="backspace"){B(L=>L.slice(0,-1));return}if(P.sequence&&P.sequence.length===1&&!P.ctrl&&!P.meta){B(L=>{let G=L+P.sequence;return fe(G)&&u(G),G});return}return}if(P.name==="return"){e.onClose();return}if(P.name==="up"||P.name==="k"&&!E){M(L=>{let G=Math.max(0,L-1),U=l[G];return U&&r(U),G});return}if(P.name==="down"||P.name==="j"&&!E){M(L=>{let G=Math.min(l.length-1,L+1),U=l[G];return U&&r(U),G});return}if(P.name==="backspace"){C(L=>L.slice(0,-1)),M(0);return}P.sequence&&P.sequence.length===1&&!P.ctrl&&!P.meta&&(C(L=>{let G=L+P.sequence,U=G.toLowerCase(),oe=d.find(ie=>{let x=Te[ie];return ie.toLowerCase().includes(U)||x.name.toLowerCase().includes(U)});return oe&&r(oe),G}),M(0))}),_e("box",{borderStyle:"double",borderColor:c.primary,paddingX:1,paddingY:1,flexDirection:"column",position:"absolute",top:"10%",left:"20%",width:"60%",children:[H("text",{fg:c.primary,attributes:ke.BOLD,children:" Themes"}),H("text",{fg:c.textDim,children:` Mode: ${o} \u2022 ${l.length} themes${s?` \u2022 BG: ${s}`:""}`}),H("text",{children:""}),H("text",{fg:w==="mode"?c.primary:c.textDim,attributes:w==="mode"?ke.BOLD:void 0,children:" Appearance"}),ce.map((P,L)=>{let G=w==="mode"&&L===T,U=P.id===o;return _e("box",{flexDirection:"row",children:[H("text",{fg:G?c.primary:c.text,attributes:G?ke.BOLD:void 0,children:` ${G?">":" "} ${P.label}`}),U&&H("text",{fg:c.success,children:" *"})]},P.id)}),H("text",{children:""}),H("text",{fg:w==="custombg"?c.primary:c.textDim,attributes:w==="custombg"?ke.BOLD:void 0,children:" Custom Background"}),_e("box",{flexDirection:"row",children:[H("text",{fg:c.textMuted,children:" Hex: "}),w==="custombg"?_e(Vr,{children:[H("text",{fg:fe(v)?c.success:c.text,children:v||""}),H("text",{fg:c.primary,attributes:ke.BOLD,children:"_"})]}):H("text",{fg:s?c.success:c.textDim,children:s||"(theme default)"})]}),w==="custombg"&&H("text",{fg:c.textDim,children:" Type #rrggbb hex, empty to clear. Enter to apply."}),H("text",{children:""}),H("text",{fg:w==="themes"?c.primary:c.textDim,attributes:w==="themes"?ke.BOLD:void 0,children:" Color Themes"}),w==="themes"&&_e("box",{flexDirection:"row",children:[H("text",{fg:c.textMuted,children:" > "}),H("text",{fg:c.text,children:E||""}),H("text",{fg:c.primary,attributes:ke.BOLD,children:"_"})]}),se.length>0?se.map(P=>{let L=Te[P],G=l.indexOf(P),U=w==="themes"&&G===z,oe=P===t;return _e("box",{flexDirection:"row",children:[H("text",{fg:U?c.primary:c.text,attributes:U?ke.BOLD:void 0,children:` ${U?">":" "} ${L.name}`}),H("text",{fg:c.textDim,children:` ${P}`}),oe&&H("text",{fg:c.success,children:" *"})]},P)}):H("text",{fg:c.textDim,children:" No matching themes"}),l.length>ee&&H("text",{fg:c.textDim,children:` ... ${l.length-ee} more`}),H("text",{children:""}),H("text",{fg:c.textDim,children:" Tab Switch section Up/Down Navigate Enter Select Esc Cancel"})]})}var Lt,so=W(()=>{"use strict";V();Lt=["mode","custombg","themes"]});import{TextAttributes as et}from"@opentui/core";import{useState as tt,useMemo as Yr}from"react";import{useKeyboard as Xr,useTerminalDimensions as zr}from"@opentui/react";import{jsx as Y,jsxs as nt}from"@opentui/react/jsx-runtime";function io(e){let{theme:n}=O(),t=n,o=zr(),[s,r]=tt(()=>Ae()),[i,u]=tt(0),[c,b]=tt(!1),[f,A]=tt(!1),[R,d]=tt(0),w=Math.max(5,Math.floor((o.height||20)-10)),D=Yr(()=>i<w?0:i-w+1,[i,w]),T=s.slice(D,D+w);if(Xr(h=>{if(f){if(h.name==="escape"||h.name==="q")A(!1),d(0);else if(h.name==="up"||h.name==="k")d(v=>Math.max(0,v-1));else if(h.name==="down"||h.name==="j"){let v=s[i];if(v){let B=v.messages.filter(E=>E.role!=="tool");d(E=>Math.min(B.length-1,E+1))}}else if(h.name==="return"){let v=s[i];v&&e.onResume(v)}return}if(c){if(h.name==="y"){let v=s[i];if(v){ft(v.id);let B=Ae();r(B),u(E=>Math.min(E,B.length-1))}b(!1)}else b(!1);return}if(h.name==="escape"||h.name==="q")e.onClose();else if(h.name==="up"||h.name==="k")u(v=>Math.max(0,v-1));else if(h.name==="down"||h.name==="j")u(v=>Math.min(s.length-1,v+1));else if(h.name==="return"){let v=s[i];v&&e.onResume(v)}else if(h.name==="d")s.length>0&&b(!0);else if(h.name==="f"){let v=s[i];v&&gt(v)&&r(Ae())}else h.name==="v"&&s.length>0&&(A(!0),d(0))}),s.length===0)return nt("box",{borderStyle:"single",borderColor:t.primary,paddingX:2,paddingY:1,flexDirection:"column",flexGrow:1,children:[Y("text",{fg:t.primary,attributes:et.BOLD,children:"Sessions"}),Y("text",{fg:t.textDim,children:`
45
+ No saved conversations.
46
+ `}),Y("text",{fg:t.textMuted,children:"Esc Close"})]});if(f){let h=s[i],v=h?h.messages.filter(C=>C.role!=="tool"):[],B=v.slice(R,R+w),E=v.length;return nt("box",{borderStyle:"single",borderColor:t.primary,paddingX:1,paddingY:0,flexDirection:"column",flexGrow:1,children:[Y("text",{fg:t.primary,attributes:et.BOLD,children:`Viewing: ${h?.title||"Untitled"}`}),Y("text",{fg:t.textDim,children:`${R+1}\u2013${Math.min(R+w,E)} of ${E} messages`}),Y("text",{children:""}),B.map((C,$)=>{let M=C.role==="user"?"\u276F":"\u25C6",l=C.role==="user"?t.success:t.text,z=C.content.length>120?C.content.substring(0,117)+"...":C.content;return Y("text",{fg:l,children:` ${M} ${z.replace(/\n/g," ")}`},`view-${R+$}`)}),Y("text",{children:""}),Y("text",{fg:t.textMuted,children:" \u2191\u2193 Scroll Enter Resume Esc Back"})]})}return nt("box",{borderStyle:"single",borderColor:t.primary,paddingX:1,paddingY:0,flexDirection:"column",flexGrow:1,children:[Y("text",{fg:t.primary,attributes:et.BOLD,children:"Sessions"}),Y("text",{fg:t.textDim,children:`${s.length} conversation${s.length!==1?"s":""}`}),Y("text",{children:""}),T.map((h,v)=>{let E=D+v===i,C=xt(h.updatedAt),$=h.messages.filter(l=>l.role==="user").length,M=h.title.length>40?h.title.substring(0,37)+"...":h.title;return nt("box",{flexDirection:"row",children:[Y("text",{fg:E?t.primary:t.textMuted,attributes:E?et.BOLD:void 0,children:` ${E?"\u276F":" "} ${M}`}),Y("text",{fg:t.textDim,children:` ${C} (${$} msgs)`})]},h.id)}),c&&nt("box",{children:[Y("text",{children:""}),Y("text",{fg:t.warning,attributes:et.BOLD,children:` Delete "${s[i]?.title}"? (y/n)`})]}),Y("text",{children:""}),Y("text",{fg:t.textMuted,children:" \u2191\u2193 Navigate Enter Resume v View d Delete f Fork Esc Close"})]})}var ao=W(()=>{"use strict";V();Pt()});import*as we from"fs";import*as Nt from"path";import*as lo from"os";import{execSync as Jr}from"child_process";import{TextAttributes as ge}from"@opentui/core";import{useState as Z,useRef as Qr,useEffect as Zr}from"react";import{useKeyboard as es}from"@opentui/react";import{Fragment as ss,jsx as I,jsxs as De}from"@opentui/react/jsx-runtime";function rs(e){try{let n=process.platform==="darwin"?`open "${e}"`:process.platform==="win32"?`start "" "${e}"`:`xdg-open "${e}"`;Jr(n,{stdio:"ignore",timeout:3e3})}catch{}}function uo(e){let{theme:n}=O(),t=n,[o,s]=Z("provider"),[r,i]=Z(0),[u,c]=Z(0),[b,f]=Z(0),[A,R]=Z("apikey"),[d,w]=Z("anthropic"),[D,T]=Z(""),[h,v]=Z(""),[B,E]=Z(!1),[C,$]=Z(""),[M,l]=Z(""),[z,ee]=Z(""),[ne,se]=Z(""),[ce,me]=Z(!1),[fe,P]=Z(""),L=Qr(!1),G=wt[r],U=A==="oauth"?ns:ts[d]||[];Zr(()=>{if(o==="oauth-paste")try{let{generateOAuthUrl:g}=rt("@cdoing/core"),{url:a,codeVerifier:m}=g(d);l(a),ee(m),se(""),P(""),rs(a)}catch{P("OAuth not available. Install @cdoing/core with OAuth support.")}},[o,d]),es(g=>{if(g.name==="escape"){o==="oauth-paste"||o==="oauth-exchanging"?(s("model"),P("")):o==="apikey"?(s("model"),$("")):o==="model"?s(d==="anthropic"?"auth-method":"provider"):o==="auth-method"?s("provider"):e.onClose();return}if(o==="provider"){if(g.name==="up"||g.name==="k")i(a=>Math.max(0,a-1));else if(g.name==="down"||g.name==="j")i(a=>Math.min(wt.length-1,a+1));else if(g.name==="return"){let a=wt[r];w(a.id),f(0),a.id==="anthropic"?(c(0),s("auth-method")):(R("apikey"),s("model"))}return}if(o==="auth-method"){if(g.name==="up"||g.name==="k")c(a=>Math.max(0,a-1));else if(g.name==="down"||g.name==="j")c(a=>Math.min(Et.length-1,a+1));else if(g.name==="return"){let a=Et[u].id;R(a),f(0),s("model")}return}if(o==="model"){if(g.name==="up"||g.name==="k")f(a=>Math.max(0,a-1));else if(g.name==="down"||g.name==="j")f(a=>Math.min(U.length-1,a+1));else if(g.name==="return"){let a=U[b];T(a.id),d==="ollama"?oe(d,a.id,void 0):A==="oauth"?(L.current=!1,s("oauth-paste")):(s("apikey"),v(""),$(""))}return}if(o==="apikey"){if(g.name==="return"){if(!h.trim()){$("API key cannot be empty");return}oe(d,D,h.trim())}else g.ctrl&&g.name==="s"?E(a=>!a):g.name==="backspace"?(v(a=>a.slice(0,-1)),$("")):g.ctrl&&g.name==="u"?(v(""),$("")):g.sequence&&g.sequence.length===1&&!g.ctrl&&!g.meta&&(v(a=>a+g.sequence),$(""));return}if(o==="oauth-paste"){if(g.name==="return"){let a=ne.trim();if(!a||L.current)return;L.current=!0,s("oauth-exchanging");try{let{exchangeOAuthCode:m}=rt("@cdoing/core");m(a,z,d).then(p=>{oe(d,D,void 0),e.onComplete({provider:d,model:D,oauthToken:p.access_token})}).catch(p=>{L.current=!1,P(p.message),s("oauth-paste")})}catch{L.current=!1,P("OAuth exchange failed"),s("oauth-paste")}return}g.ctrl&&g.name==="s"?me(a=>!a):g.name==="backspace"?(se(a=>a.slice(0,-1)),P("")):g.ctrl&&g.name==="u"?(se(""),P("")):g.sequence&&g.sequence.length===1&&!g.ctrl&&!g.meta&&(se(a=>a+g.sequence),P(""));return}});let oe=(g,a,m)=>{let p=Nt.join(lo.homedir(),".cdoing"),S=Nt.join(p,"config.json"),k={};try{we.existsSync(S)&&(k=JSON.parse(we.readFileSync(S,"utf-8")))}catch{}k.provider=g,k.model=a,m&&(k.apiKeys||(k.apiKeys={}),k.apiKeys[g]=m),we.existsSync(p)||we.mkdirSync(p,{recursive:!0}),we.writeFileSync(S,JSON.stringify(k,null,2),"utf-8"),e.onComplete({provider:g,model:a,apiKey:m})},ie=d==="anthropic",x=ie?4:d==="ollama"?2:3,y=g=>{switch(g){case"provider":return`1/${x}`;case"auth-method":return"2/4";case"model":return ie?"3/4":d==="ollama"?"2/2":"2/3";case"apikey":return ie?"4/4":"3/3";case"oauth-paste":return"4/4";case"oauth-exchanging":return"4/4";default:return""}};return De("box",{borderStyle:"single",borderColor:t.primary,paddingX:2,paddingY:1,flexDirection:"column",flexGrow:1,children:[I("text",{fg:t.primary,attributes:ge.BOLD,children:"Setup Wizard"}),I("text",{children:""}),o==="provider"&&De("box",{flexDirection:"column",children:[I("text",{fg:t.text,attributes:ge.BOLD,children:`Step ${y("provider")}: Select Provider`}),I("text",{children:""}),wt.map((g,a)=>I("text",{fg:r===a?t.primary:t.textMuted,attributes:r===a?ge.BOLD:void 0,children:` ${r===a?">":" "} ${g.name} ${r===a?g.hint:""}`},g.id)),I("text",{children:""}),I("text",{fg:t.textMuted,children:" Up/Down Navigate Enter Select Esc Cancel"})]}),o==="auth-method"&&De("box",{flexDirection:"column",children:[I("text",{fg:t.text,attributes:ge.BOLD,children:`Step ${y("auth-method")}: How do you want to authenticate?`}),I("text",{children:""}),Et.map((g,a)=>I("text",{fg:u===a?t.primary:t.textMuted,attributes:u===a?ge.BOLD:void 0,children:` ${u===a?">":" "} ${g.name} ${u===a?g.hint:""}`},g.id)),I("text",{children:""}),I("text",{fg:t.textMuted,children:" Up/Down Navigate Enter Select Esc Back"})]}),o==="model"&&De("box",{flexDirection:"column",children:[I("text",{fg:t.text,attributes:ge.BOLD,children:A==="oauth"?`Step ${y("model")}: Select Model (OAuth supports Haiku only)`:`Step ${y("model")}: Select Model (${G.name})`}),I("text",{children:""}),U.map((g,a)=>I("text",{fg:b===a?t.primary:t.textMuted,attributes:b===a?ge.BOLD:void 0,children:` ${b===a?">":" "} ${g.name}${g.hint?` ${g.hint}`:""}`},g.id)),I("text",{children:""}),I("text",{fg:t.textMuted,children:" Up/Down Navigate Enter Select Esc Back"})]}),o==="apikey"&&De("box",{flexDirection:"column",children:[I("text",{fg:t.text,attributes:ge.BOLD,children:`Step ${y("apikey")}: Enter API Key`}),I("text",{children:""}),I("text",{fg:t.textDim,children:` Provider: ${d} Model: ${D}`}),co[d]&&I("text",{fg:t.textDim,children:` Get a key: ${co[d]}`}),I("text",{fg:t.textDim,children:` Environment variable: ${os[d]||"N/A"}`}),I("text",{children:""}),I("text",{fg:t.text,children:` > ${B?h:h.replace(/./g,"*")}|`}),C&&I("text",{fg:t.error,children:`
47
+ ${C}`}),I("text",{children:""}),I("text",{fg:t.textMuted,children:" Enter Save Ctrl+S Toggle visibility Ctrl+U Clear Esc Back"})]}),o==="oauth-paste"&&De("box",{flexDirection:"column",children:[I("text",{fg:t.text,attributes:ge.BOLD,children:`Step ${y("oauth-paste")}: OAuth Login`}),I("text",{children:""}),I("text",{fg:t.text,children:" 1. Browser opening to Claude login..."}),M?I("text",{fg:t.textDim,children:` If it didn't open: ${M.substring(0,70)}...`}):null,I("text",{fg:t.text,children:" 2. Approve -> you'll land on a page with a code in the URL"}),I("text",{fg:t.text,children:" 3. Copy the code= value from the URL and paste below"}),fe?De(ss,{children:[I("text",{children:""}),I("text",{fg:t.error,children:` Error: ${fe}`})]}):null,I("text",{children:""}),I("text",{fg:t.text,children:` Code: ${ce?ne:ne.replace(/./g,"*")}|`}),I("text",{children:""}),I("text",{fg:t.textMuted,children:" Paste code then Enter Ctrl+S Toggle visible Esc Cancel"})]}),o==="oauth-exchanging"&&De("box",{flexDirection:"column",children:[I("text",{fg:t.text,attributes:ge.BOLD,children:`Step ${y("oauth-exchanging")}: OAuth Login`}),I("text",{children:""}),I("text",{fg:t.warning,children:" Exchanging code for tokens..."})]})]})}var wt,Et,ts,ns,os,co,mo=W(()=>{"use strict";V();wt=[{id:"anthropic",name:"Anthropic (Claude)",hint:"Claude Sonnet, Opus, Haiku"},{id:"openai",name:"OpenAI",hint:"GPT-4o, o3"},{id:"google",name:"Google AI",hint:"Gemini 2.0 Flash, 2.5 Pro"},{id:"ollama",name:"Ollama (Local)",hint:"No API key needed"}],Et=[{id:"apikey",name:"API Key",hint:"all models available - console.anthropic.com"},{id:"oauth",name:"OAuth",hint:"Claude Pro/Max - opens browser"}],ts={anthropic:[{id:"claude-sonnet-4-6",name:"Claude Sonnet 4.6",hint:"recommended - fast & smart"},{id:"claude-opus-4-6",name:"Claude Opus 4.6",hint:"most capable"},{id:"claude-haiku-4-5-20251001",name:"Claude Haiku 4.5",hint:"fastest"}],openai:[{id:"gpt-4o",name:"GPT-4o",hint:"recommended"},{id:"gpt-4o-mini",name:"GPT-4o mini",hint:"fastest"},{id:"o3",name:"o3",hint:"reasoning"}],google:[{id:"gemini-2.0-flash",name:"Gemini 2.0 Flash",hint:"recommended"},{id:"gemini-2.5-pro",name:"Gemini 2.5 Pro",hint:"most capable"}],ollama:[{id:"llama3.1",name:"Llama 3.1",hint:"general purpose"},{id:"codellama",name:"Code Llama",hint:"code-focused"},{id:"mistral",name:"Mistral",hint:"fast & capable"}]},ns=[{id:"claude-haiku-4-5",name:"Claude Haiku 4.5",hint:"only model supported with OAuth"}],os={anthropic:"ANTHROPIC_API_KEY",openai:"OPENAI_API_KEY",google:"GOOGLE_API_KEY"},co={anthropic:"https://console.anthropic.com/settings/keys",openai:"https://platform.openai.com/api-keys",google:"https://aistudio.google.com/apikey"}});import{TextAttributes as fo}from"@opentui/core";import{useState as is}from"react";import{useKeyboard as as,useTerminalDimensions as cs}from"@opentui/react";import{jsx as Ce,jsxs as go}from"@opentui/react/jsx-runtime";function xo(e){let{theme:n}=O(),t=n,o=at(),s=cs(),[r,i]=is(0),u=o.registry.getAll?o.registry.getAll():[],c=Array.isArray(u)?u.map(d=>d.definition?.name||d.name||"unknown"):[],b=[{title:"Provider",rows:[["Provider",o.provider],["Model",o.model],["Directory",o.workingDir]]},{title:"System",rows:[["Node",process.version],["Platform",`${process.platform} ${process.arch}`],["Terminal",process.env.TERM_PROGRAM||process.env.TERM||"unknown"],["Shell",process.env.SHELL||"unknown"]]},{title:`Tools (${c.length})`,rows:c.slice(0,20).map(d=>["\u2022",d])}],f=[];for(let d of b){f.push({type:"header",text:d.title});for(let[w,D]of d.rows)f.push({type:"row",text:w,value:D});f.push({type:"row",text:"",value:""})}let A=Math.max(5,(s.height||24)-10);as(d=>{(d.name==="escape"||d.name==="q")&&e.onClose(),(d.name==="up"||d.name==="k")&&i(w=>Math.max(0,w-1)),(d.name==="down"||d.name==="j")&&i(w=>Math.min(f.length-A,w+1))});let R=f.slice(r,r+A);return go("box",{borderStyle:"double",borderColor:t.primary,paddingX:1,paddingY:1,flexDirection:"column",position:"absolute",top:"10%",left:"15%",width:"70%",children:[Ce("text",{fg:t.primary,attributes:fo.BOLD,children:" System Status"}),Ce("text",{children:""}),R.map((d,w)=>d.type==="header"?Ce("text",{fg:t.secondary,attributes:fo.BOLD,children:` ${d.text}`},`h-${w}`):!d.text&&!d.value?Ce("text",{children:""},`s-${w}`):go("box",{flexDirection:"row",children:[Ce("text",{fg:t.textMuted,children:` ${d.text}`}),d.value&&Ce("text",{fg:t.text,children:` ${d.value}`})]},`r-${w}`)),Ce("text",{children:""}),Ce("text",{fg:t.textDim,children:" \u2191\u2193 Scroll Esc Close"})]})}var po=W(()=>{"use strict";V();ct()});var yo={};ko(yo,{startTUI:()=>ys});import*as Ge from"fs";import*as Gt from"path";import*as Kt from"os";import{createRoot as ls,useKeyboard as ds,useTerminalDimensions as us}from"@opentui/react";import{createCliRenderer as ms,TextAttributes as fs}from"@opentui/core";import{useState as ue,useRef as ot,useCallback as St}from"react";import{ToolRegistry as gs,PermissionManager as xs,PermissionMode as jt,registerAllTools as ps}from"@cdoing/core";import{AgentRunner as ho,getDefaultModel as hs,getApiKeyEnvVar as bo}from"@cdoing/ai";import{jsx as K,jsxs as _t}from"@opentui/react/jsx-runtime";function bs(e){let n=us(),{theme:t,themeId:o,setMode:s,setThemeId:r}=O(),i=t,[u,c]=ue(e.options.prompt?"session":"home"),[b,f]=ue("none"),[A,R]=ue("Ready"),[d,w]=ue(e.options.provider),[D,T]=ue(e.options.model||hs(e.options.provider)||"default"),[h,v]=ue(e.options.workingDir),[B,E]=ue(),[C,$]=ue(0),[M,l]=ue(),[z,ee]=ue(!0),ne=ot(e.agent),se=ot(e.registry),ce=ot(e.permissionManager),me=ot(null),fe=ot(null),[P,L]=ue(null),G=St((x,y)=>new Promise(g=>{fe.current=g,L({toolName:x,message:y})}),[]);ce.current.setPromptFn(async(x,y)=>{let g=await G(x,y);return g==="always"?"allow":g});let U=St((x,y,g)=>{let a=g;if(g===void 0){let S=bo(x);if(process.env[S])a=process.env[S];else try{let k=Gt.join(Kt.homedir(),".cdoing","config.json");Ge.existsSync(k)&&(a=JSON.parse(Ge.readFileSync(k,"utf-8")).apiKeys?.[x])}catch{}}let m={provider:x,model:y,apiKey:a||void 0,baseURL:e.options.baseUrl||void 0,temperature:0,maxTokens:8096},p=new ho(m,se.current,ce.current);ne.current=p,w(x),T(y)},[e.options.baseUrl]),oe=St(x=>{v(x)},[]);ds(x=>{if(!(b!=="none"&&x.name!=="escape")){if(x.ctrl&&x.name==="c"){let y=globalThis.__cdoingCleanup;y?y():process.exit(0)}x.ctrl&&x.name==="n"&&(c("session"),R("Ready")),x.ctrl&&x.name==="p"&&f(y=>y==="model"?"none":"model"),x.ctrl&&x.name==="s"&&f(y=>y==="sessions"?"none":"sessions"),x.ctrl&&x.name==="b"&&ee(y=>!y),x.ctrl&&x.name==="t"&&f(y=>y==="theme"?"none":"theme"),x.ctrl&&x.name==="x"&&f(y=>y==="command"?"none":"command"),x.name==="f1"&&f(y=>y==="help"?"none":"help"),x.name==="escape"&&f("none")}},{});let ie=St(x=>{c("session"),f("none"),R("Ready")},[]);return _t("box",{width:n.width,height:n.height,flexDirection:"column",children:[_t("box",{height:1,flexDirection:"row",paddingX:1,flexShrink:0,children:[K("text",{fg:i.primary,attributes:fs.BOLD,children:"cdoing"}),K("text",{fg:i.border,children:" \u2502 "}),K("text",{fg:i.textMuted,children:D}),K("text",{fg:i.border,children:" \u2502 "}),K("text",{fg:A==="Error"?i.error:A==="Processing..."?i.warning:i.success,children:A})]}),u==="session"&&K(_n,{title:"Session",provider:d,model:D,tokens:B,contextPercent:C,status:A}),K("box",{height:1,flexShrink:0,children:K("text",{fg:i.border,children:"\u2500".repeat(Math.max(n.width,40))})}),_t("box",{flexDirection:"row",flexGrow:1,children:[K(Vt,{value:{agent:ne.current,registry:se.current,permissionManager:ce.current,workingDir:h,provider:d,model:D,requestPermission:G,rebuildAgent:U,setWorkingDir:oe},children:K("box",{flexGrow:1,flexDirection:"column",children:b==="sessions"?K(io,{onResume:ie,onClose:()=>f("none")}):b==="setup"?K(uo,{onComplete:x=>{U(x.provider,x.model,x.apiKey),f("none")},onClose:()=>f("none")}):u==="home"?K(un,{provider:d,model:D,workingDir:h,themeId:o,onSubmit:(x,y)=>{me.current={text:x,images:y},c("session")}}):K(Ln,{onStatus:R,onTokens:(x,y)=>E({input:x,output:y}),onActiveTool:l,onContextPercent:$,onOpenDialog:x=>f(x),initialMessage:me.current})})}),z&&K(Fn,{provider:d,model:D,workingDir:h,tokens:B,contextPercent:C,activeTool:M,status:A,themeId:o})]}),K("box",{height:1,flexShrink:0,children:K("text",{fg:i.border,children:"\u2500".repeat(Math.max(n.width,40))})}),u==="session"?K(Kn,{workingDir:h,isProcessing:A==="Processing..."}):K(Nn,{provider:d,model:D,mode:e.options.mode,workingDir:h,tokens:B,contextPercent:C,activeTool:M,isProcessing:A==="Processing..."}),b==="model"&&K(Vn,{provider:d,currentModel:D,onSelect:x=>{U(d,x),f("none")},onClose:()=>f("none")}),b==="command"&&K(Qn,{onSelect:x=>{switch(f("none"),x){case"session:new":c("session"),R("Ready");break;case"session:browse":f("sessions");break;case"session:clear":c("session"),R("Ready");break;case"model:switch":f("model");break;case"theme:dark":s("dark");break;case"theme:light":s("light");break;case"theme:picker":f("theme");break;case"display:sidebar":ee(y=>!y);break;case"display:timestamps":case"display:thinking":break;case"system:status":f("status");break;case"system:help":f("help");break;case"system:doctor":R("Doctor");break;case"system:setup":f("setup");break;case"system:exit":{let y=globalThis.__cdoingCleanup;y?y():process.exit(0);break}}},onClose:()=>f("none")}),b==="help"&&K(no,{onClose:()=>f("none")}),b==="theme"&&K(ro,{onClose:()=>f("none")}),b==="status"&&K(xo,{onClose:()=>f("none")})]})}async function ys(e){let n=new gs,t=e.mode==="auto"?jt.BYPASS:e.mode==="auto-edit"?jt.ACCEPT_EDITS:jt.DEFAULT,o=new xs(t,e.workingDir);o.setPromptFn(async(h,v)=>"allow"),await ps(n,{workingDir:e.workingDir,permissionManager:o});let s=e.apiKey,r=e.provider,i=e.model,u=e.baseUrl;if(!s){let h=Gt.join(Kt.homedir(),".cdoing","config.json"),v={};try{Ge.existsSync(h)&&(v=JSON.parse(Ge.readFileSync(h,"utf-8")))}catch{}r==="anthropic"&&v.provider&&(r=v.provider),!i&&v.model&&(i=v.model),!u&&v.baseUrl&&(u=v.baseUrl);let B=bo(r);process.env[B]?s=process.env[B]:v.apiKeys?.[r]&&(s=v.apiKeys[r])}let c={provider:r,model:i||void 0,apiKey:s||void 0,baseURL:u||void 0,temperature:0,maxTokens:8096},b=new ho(c,n,o),f;e.theme==="auto"&&(f=await Ft());let A=e.theme==="light"?"light":e.theme==="auto"&&f||"dark",R=Se("default",A);Oe(R.bg),console.clear(),mt("cdoing");let d=await ms({useMouse:!0,exitOnCtrlC:!1}),w=ls(d);w.render(K(Ht,{mode:e.theme,detectedMode:f,syncTerminalBg:!0,children:K(Zt,{children:K(bs,{options:{...e,provider:r,model:i||void 0},agent:b,registry:n,permissionManager:o})})}));let D=!1,T=()=>{if(!D){D=!0;try{w.unmount()}catch{}try{d.destroy()}catch{}kn(),it(),process.exit(0)}};process.on("SIGINT",T),process.on("SIGTERM",T),globalThis.__cdoingCleanup=T,await new Promise(()=>{})}var wo=W(()=>{"use strict";V();ct();Dt();mn();En();jn();Gn();Un();Wn();Yn();Zn();oo();so();ao();mo();po();$t()});import{Command as ws}from"commander";import{getDefaultModel as Ss}from"@cdoing/ai";var So=new ws;So.name("cdoing-tui").description("OpenTUI-based terminal interface for cdoing agent").version("0.1.0").option("-m, --model <model>","Model name").option("-p, --provider <provider>","AI provider","anthropic").option("--api-key <key>","API key").option("--base-url <url>","Base URL for custom providers").option("-d, --dir <directory>","Working directory",process.cwd()).option("--mode <mode>","Permission mode: ask, auto-edit, auto","ask").option("-r, --resume <id>","Resume conversation by ID").option("-c, --continue","Continue most recent conversation").option("--theme <theme>","Theme: dark, light, auto","dark").argument("[prompt]","Initial prompt").action(async(e,n)=>{let{startTUI:t}=await Promise.resolve().then(()=>(wo(),yo));await t({prompt:e,provider:n.provider,model:n.model||Ss(n.provider),apiKey:n.apiKey,baseUrl:n.baseUrl,workingDir:n.dir,mode:n.mode,resume:n.resume,continue:n.continue,theme:n.theme})});So.parse();
48
+ //# sourceMappingURL=index.js.map