herm-tui 1.0.0-dev.10 → 1.0.0-dev.11

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.
Files changed (2) hide show
  1. package/index.js +3 -3
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -4125,7 +4125,7 @@ Usage:
4125
4125
  herm --no-splash skip the launch splash
4126
4126
  herm -v, --version print version
4127
4127
  herm -h, --help show this help
4128
- `;var TIERS=["block","slick","tiny"],pickFont=(innerW)=>TIERS.find((f)=>measureText({text:"HERM",font:f}).width<=innerW)??"tiny",clip=(s,w2)=>[...s].length<=w2?s:[...s].slice(0,Math.max(1,w2-1)).join("")+"\u2026";function Splash(p){let theme=useTheme().theme,ref=import_react93.useRef(null),[box,setBox]=import_react93.useState({w:0,h:0}),renderer=useRenderer();import_react93.useEffect(()=>{let cb=async()=>{let r=ref.current;if(!r)return;setBox((b2)=>b2.w===r.width&&b2.h===r.height?b2:{w:r.width,h:r.height})};return renderer.setFrameCallback(cb),()=>renderer.removeFrameCallback(cb)},[renderer]);let{lines:lines2,inner}=import_react93.useMemo(()=>frame(box.w,box.h),[box.w,box.h]),font=import_react93.useMemo(()=>pickFont(inner.w),[inner.w]),[tip2,setTip]=import_react93.useState(()=>randomTip()),behind=p.info?.behind,sub2=[`v${VERSION}`,p.info?`hermes ${p.info.agentVersion??"?"}`:"\u2026",behind==null?null:behind===0?"up to date":`${behind} behind`,p.info?.model].filter(Boolean).join(" \xB7 "),prompt=p.last&&!p.composing,title=p.last?.title?.trim()||p.last?.id;return $jsxs("box",{ref,position:"absolute",left:0,top:0,right:0,bottom:0,zIndex:50,backgroundColor:theme.background,children:[lines2.map((l,i)=>$jsx("box",{position:"absolute",top:i,left:0,height:1,children:$jsx("text",{fg:theme.accent,children:l})},i)),lines2.length>0&&$jsxs("box",{position:"absolute",left:inner.x,top:inner.y,width:inner.w,height:inner.h,flexDirection:"column",alignItems:"center",justifyContent:"center",children:[$jsx("box",{children:$jsx("ascii-font",{text:"HERM",font,color:[theme.accent,theme.textMuted],selectable:!1})}),$jsx("box",{height:1,children:$jsx("text",{fg:theme.textMuted,children:clip(sub2,inner.w)})}),p.news?$jsx("box",{height:1,children:$jsx("text",{fg:theme.textMuted,children:clip(`\u203A ${p.news}`,inner.w)})}):null,$jsx("box",{height:2}),p.loading?$jsx("text",{fg:theme.textMuted,children:$jsx("span",{fg:theme.accent,children:"Loading\u2026"})}):prompt?$jsxs($Fragment2,{children:[$jsxs("text",{fg:theme.textMuted,children:["continue ",$jsxs("span",{fg:theme.text,children:['"',clip(title??"",Math.max(8,inner.w-14)),'"']})," ?"]}),$jsxs("text",{fg:theme.textMuted,children:[$jsx("span",{fg:theme.accent,children:"[enter]"})," yes \xB7 type to start fresh"]})]}):$jsxs("text",{fg:theme.textMuted,children:[$jsx("span",{fg:theme.accent,children:"[enter]"})," to send"]}),inner.h>=14?$jsx("box",{position:"absolute",bottom:0,left:0,right:0,flexDirection:"column",alignItems:"center",onMouseDown:()=>setTip((t2)=>randomTip(t2)),children:$jsx("text",{wrapMode:"word",children:splitTip(clip(tip2,inner.w*2)).map((s,i)=>$jsx("span",{fg:s.hl?theme.accent:theme.textMuted,children:s.t},i))})}):null]})]})}init_sessions_db();var import_react95=__toESM(require_react_production(),1);function openAlert(dialog,title,body2){dialog.replace($jsx(Alert,{title,body:body2,onClose:()=>dialog.clear()}))}var Alert=(props)=>{let theme=useTheme().theme,keys=useKeys(),[copied,setCopied]=import_react95.useState(!1),doCopy=()=>{copy(props.body),setCopied(!0),setTimeout(()=>setCopied(!1),900)};return useKeyboard((key2)=>{if(keys.match("dialog.cancel",key2)||keys.match("dialog.accept",key2))props.onClose();if(keys.match("dialog.copy",key2))doCopy()}),$jsxs("box",{flexDirection:"column",width:84,maxHeight:28,border:["left"],borderColor:theme.info,customBorderChars:LEFT_BAR,backgroundColor:theme.backgroundPanel,paddingLeft:2,paddingRight:2,paddingY:1,gap:1,children:[$jsx("box",{height:1,children:$jsxs("text",{children:[$jsx("span",{fg:theme.info,children:"\u25C8 "}),$jsx("span",{fg:theme.text,children:props.title})]})}),$jsx("scrollbox",{scrollY:!0,flexGrow:1,children:$jsx("text",{fg:theme.text,wrapMode:"word",children:props.body})}),$jsxs("box",{height:1,flexDirection:"row",children:[$jsx("box",{flexShrink:0,children:$jsx("text",{fg:theme.textMuted,children:`${keys.print("dialog.cancel")} close \xB7 ${keys.print("dialog.copy")} `})}),$jsx("box",{flexShrink:0,onMouseDown:(e)=>{e.stopPropagation(),doCopy()},children:$jsx("text",{fg:copied?theme.success:theme.textMuted,children:$jsx("u",{children:copied?"copied":"copy"})})})]})]})};function openMessage(dialog,m2,ops){let text2=m2.parts.filter((p)=>p.type==="text").map((p)=>p.content).join("");dialog.replace($jsx(DialogSelect,{title:"Message Actions",options:[{title:"Copy",value:"copy",description:"message text to clipboard"},{title:"Rewind here",value:"rewind",description:"undo back to this turn (destructive)"},{title:"Fork here",value:"fork",description:"branch a new session at this point"}],onSelect:(o)=>{if(dialog.clear(),o.value==="copy")return void copy(text2);if(o.value==="rewind")return ops.rewind(m2);if(o.value==="fork")return ops.fork(m2)}}))}var LOCAL_NAMES=new Set(["clear","new","theme","help","keys","logs","eikon","title","rollback","save","history","status","usage","profile","steer","reload","reload-mcp","chafa","splash","goal","skin","resume","branch","compress","undo","retry","model","quit","copy","paste","image","background","voice","mouse","redraw","queue","compact","setup"]),LOCAL_COMMANDS=[{name:"clear",description:"Clear chat messages",category:"Client",aliases:[],argsHint:"",subcommands:[],source:"local",target:"local"},{name:"new",description:"Start a new session",category:"Client",aliases:["reset"],argsHint:"",subcommands:[],source:"local",target:"local"},{name:"theme",description:"Switch color theme",category:"Client",aliases:[],argsHint:"",subcommands:[],source:"local",target:"local"},{name:"help",description:"Show keyboard shortcuts",category:"Client",aliases:[],argsHint:"",subcommands:[],source:"local",target:"local"},{name:"keys",description:"Rebind keyboard shortcuts",category:"Client",aliases:[],argsHint:"",subcommands:[],source:"local",target:"local"},{name:"logs",description:"Show gateway stderr log",category:"Client",aliases:[],argsHint:"",subcommands:[],source:"local",target:"local"},{name:"eikon",description:"Pick sidebar avatar",category:"Client",aliases:[],argsHint:"",subcommands:[],source:"local",target:"local"},{name:"title",description:"Set session title",category:"Client",aliases:[],argsHint:"[text]",subcommands:[],source:"local",target:"local"},{name:"rollback",description:"Browse & restore checkpoints",category:"Client",aliases:[],argsHint:"",subcommands:[],source:"local",target:"local"},{name:"history",description:"Server-side transcript viewer",category:"Info",aliases:[],argsHint:"",subcommands:[],source:"local",target:"local"},{name:"status",description:"Version, model, paths",category:"Info",aliases:[],argsHint:"",subcommands:[],source:"local",target:"local"},{name:"usage",description:"Tokens, context fill, cost",category:"Info",aliases:[],argsHint:"",subcommands:[],source:"local",target:"local"},{name:"profile",description:"Active profile details",category:"Info",aliases:[],argsHint:"",subcommands:[],source:"local",target:"local"},{name:"steer",description:"Inject a note mid-turn (no interrupt)",category:"Session",aliases:[],argsHint:"[text]",subcommands:[],source:"local",target:"local"},{name:"reload-mcp",description:"Restart MCP servers & rediscover tools",category:"Session",aliases:[],argsHint:"[now|always]",subcommands:["now","always"],source:"local",target:"local"},{name:"reload",description:"Hot-reload ~/.hermes/.env (API keys)",category:"Session",aliases:[],argsHint:"",subcommands:[],source:"local",target:"local"},{name:"chafa",description:"Render image via chafa (demo)",category:"Client",aliases:[],argsHint:"<path>",subcommands:[],source:"local",target:"local"},{name:"splash",description:"Show the launch splash",category:"Client",aliases:[],argsHint:"",subcommands:[],source:"local",target:"local"},{name:"goal",description:"Set/control the session goal",category:"Session",aliases:[],argsHint:"[text|done|pause|resume|clear|status]",subcommands:["done","pause","resume","clear","status"],source:"local",target:"local"},{name:"skin",description:"Switch Hermes skin (+ theme + eikon)",category:"Client",aliases:[],argsHint:"[name]",subcommands:[...SKINS],source:"local",target:"local"}];function resolve7(list,name){let q4=name.toLowerCase();for(let c of list)if(c.name.toLowerCase()===q4||c.aliases.some((a)=>a.toLowerCase()===q4))return{hit:c};let hits=new Set;for(let c of list)for(let n of[c.name,...c.aliases])if(n.toLowerCase().startsWith(q4)){hits.add(c);break}if(hits.size===1)return{hit:[...hits][0]};if(hits.size===0)return{miss:!0};return{ambiguous:[...hits].map((c)=>`/${c.name}`).sort()}}function matchSub(list,input){let m2=input.match(/^\/(\w+)\s+(\S*)$/);if(!m2)return null;let name=m2[1],sub2=m2[2],cmd=list.find((c)=>c.name===name||c.aliases.includes(name));if(!cmd||cmd.subcommands.length===0)return null;let q4=sub2.toLowerCase(),matches=cmd.subcommands.filter((s)=>s.toLowerCase().startsWith(q4));if(matches.length===0)return null;return matches.map((s)=>({...cmd,name:`${cmd.name} ${s}`,description:`${cmd.name} \u2192 ${s}`,argsHint:"",subcommands:[]}))}var CATEGORY_ORDER=["Client","Session","Configuration","Config","Tools & Skills","Skills","Plugins","MCP","Info","Exit"];function sort(list){let idx3=(c)=>{let i=CATEGORY_ORDER.indexOf(c);return i<0?999:i};return[...list].sort((a,b2)=>{let ca=idx3(a.category)-idx3(b2.category);return ca!==0?ca:a.name.localeCompare(b2.name)})}var import_react97=__toESM(require_react_production(),1);var bare=(s)=>s[0]==="/"?s.slice(1):s;function useSlashCommands(){let gw=useGateway(),ready=useGatewayReady(),[cmds,setCmds]=import_react97.useState(LOCAL_COMMANDS),fetch2=import_react97.useCallback(async()=>{let res=await gw.request("commands.catalog").catch(()=>null);if(!res){setCmds(LOCAL_COMMANDS);return}let cat=new Map;for(let g of res.categories??[])for(let[n]of g.pairs??[])cat.set(bare(n),g.name);let alias=new Map;for(let[a,c]of Object.entries(res.canon??{})){let k2=bare(c),v2=bare(a);if(k2===v2)continue;(alias.get(k2)??alias.set(k2,[]).get(k2)).push(v2)}let sub2=new Map(Object.entries(res.sub??{}).map(([k2,v2])=>[bare(k2),v2])),local=new Map(LOCAL_COMMANDS.map((c)=>[c.name,c])),remote=(res.pairs??[]).map(([raw,desc])=>{let name=bare(raw),l=local.get(name);return{name,description:desc,category:cat.get(name)??(name.includes(":")?"Skills":"Command"),aliases:alias.get(name)??[],argsHint:l?.argsHint??"",subcommands:sub2.get(name)??l?.subcommands??[],source:"command",target:LOCAL_NAMES.has(name)?"local":"gateway"}}),seen=new Set(remote.map((c)=>c.name)),locals=LOCAL_COMMANDS.filter((c)=>!seen.has(c.name));setCmds(sort([...locals,...remote]))},[gw]);return import_react97.useEffect(()=>{if(ready)fetch2()},[ready,fetch2]),{cmds,refresh:fetch2}}var import_react103=__toESM(require_react_production(),1);var winDrive=(s,off=0)=>s.length>=off+3&&/[A-Za-z]/.test(s[off])&&s[off+1]===":"&&(s[off+2]==="\\"||s[off+2]==="/");function looksLikePath(s){let t2=s.trim();if(!t2||t2.includes(`
4128
+ `;var TIERS=["block","slick","tiny"],pickFont=(innerW)=>TIERS.find((f)=>measureText({text:"HERM",font:f}).width<=innerW)??"tiny",clip=(s,w2)=>[...s].length<=w2?s:[...s].slice(0,Math.max(1,w2-1)).join("")+"\u2026";function Splash(p){let theme=useTheme().theme,ref=import_react93.useRef(null),[box,setBox]=import_react93.useState({w:0,h:0}),renderer=useRenderer();import_react93.useEffect(()=>{let cb=async()=>{let r=ref.current;if(!r)return;setBox((b2)=>b2.w===r.width&&b2.h===r.height?b2:{w:r.width,h:r.height})};return renderer.setFrameCallback(cb),()=>renderer.removeFrameCallback(cb)},[renderer]);let{lines:lines2,inner}=import_react93.useMemo(()=>frame(box.w,box.h),[box.w,box.h]),font=import_react93.useMemo(()=>pickFont(inner.w),[inner.w]),[tip2,setTip]=import_react93.useState(()=>randomTip()),behind=p.info?.behind,sub2=[`v${VERSION}`,p.info?`hermes ${p.info.agentVersion??"?"}`:"\u2026",behind==null?null:behind===0?"up to date":`${behind} behind`,p.info?.model].filter(Boolean).join(" \xB7 "),prompt=p.last&&!p.composing,title=p.last?.title?.trim()||p.last?.id;return $jsxs("box",{ref,position:"absolute",left:0,top:0,right:0,bottom:0,zIndex:50,backgroundColor:theme.background,children:[lines2.map((l,i)=>$jsx("box",{position:"absolute",top:i,left:0,height:1,children:$jsx("text",{fg:theme.accent,children:l})},i)),lines2.length>0&&$jsxs("box",{position:"absolute",left:inner.x,top:inner.y,width:inner.w,height:inner.h,flexDirection:"column",alignItems:"center",justifyContent:"center",children:[$jsx("box",{children:$jsx("ascii-font",{text:"HERM",font,color:[theme.accent,theme.textMuted],selectable:!1})}),$jsx("box",{height:1,children:$jsx("text",{fg:theme.textMuted,children:clip(sub2,inner.w)})}),p.news?$jsx("box",{height:1,children:$jsx("text",{fg:theme.textMuted,children:clip(`\u203A ${p.news}`,inner.w)})}):null,$jsx("box",{height:2}),p.loading?$jsx("text",{fg:theme.textMuted,children:$jsx("span",{fg:theme.accent,children:"Loading\u2026"})}):prompt?$jsxs($Fragment2,{children:[$jsxs("text",{fg:theme.textMuted,children:["continue ",$jsxs("span",{fg:theme.text,children:['"',clip(title??"",Math.max(8,inner.w-14)),'"']})," ?"]}),$jsxs("text",{fg:theme.textMuted,children:[$jsx("span",{fg:theme.accent,children:"[enter]"})," yes \xB7 type to start fresh"]})]}):$jsxs("text",{fg:theme.textMuted,children:[$jsx("span",{fg:theme.accent,children:"[enter]"})," to send"]}),inner.h>=14?$jsx("box",{position:"absolute",bottom:0,left:0,right:0,flexDirection:"column",alignItems:"center",onMouseDown:()=>setTip((t2)=>randomTip(t2)),children:$jsx("text",{wrapMode:"word",children:splitTip(clip(tip2,inner.w*2)).map((s,i)=>$jsx("span",{fg:s.hl?theme.accent:theme.textMuted,children:s.t},i))})}):null]})]})}init_sessions_db();var import_react95=__toESM(require_react_production(),1);function openAlert(dialog,title,body2){dialog.replace($jsx(Alert,{title,body:body2,onClose:()=>dialog.clear()}))}var Alert=(props)=>{let theme=useTheme().theme,keys=useKeys(),[copied,setCopied]=import_react95.useState(!1),doCopy=()=>{copy(props.body),setCopied(!0),setTimeout(()=>setCopied(!1),900)};return useKeyboard((key2)=>{if(keys.match("dialog.cancel",key2)||keys.match("dialog.accept",key2))props.onClose();if(keys.match("dialog.copy",key2))doCopy()}),$jsxs("box",{flexDirection:"column",width:84,maxHeight:28,border:["left"],borderColor:theme.info,customBorderChars:LEFT_BAR,backgroundColor:theme.backgroundPanel,paddingLeft:2,paddingRight:2,paddingY:1,gap:1,children:[$jsx("box",{height:1,children:$jsxs("text",{children:[$jsx("span",{fg:theme.info,children:"\u25C8 "}),$jsx("span",{fg:theme.text,children:props.title})]})}),$jsx("scrollbox",{scrollY:!0,flexGrow:1,children:$jsx("text",{fg:theme.text,wrapMode:"word",children:props.body})}),$jsxs("box",{height:1,flexDirection:"row",children:[$jsx("box",{flexShrink:0,children:$jsx("text",{fg:theme.textMuted,children:`${keys.print("dialog.cancel")} close \xB7 ${keys.print("dialog.copy")} `})}),$jsx("box",{flexShrink:0,onMouseDown:(e)=>{e.stopPropagation(),doCopy()},children:$jsx("text",{fg:copied?theme.success:theme.textMuted,children:$jsx("u",{children:copied?"copied":"copy"})})})]})]})};function openMessage(dialog,m2,ops){let text2=m2.parts.filter((p)=>p.type==="text").map((p)=>p.content).join("");dialog.replace($jsx(DialogSelect,{title:"Message Actions",options:[{title:"Copy",value:"copy",description:"message text to clipboard"},{title:"Rewind here",value:"rewind",description:"undo back to this turn (destructive)"},{title:"Fork here",value:"fork",description:"branch a new session at this point"}],onSelect:(o)=>{if(dialog.clear(),o.value==="copy")return void copy(text2);if(o.value==="rewind")return ops.rewind(m2);if(o.value==="fork")return ops.fork(m2)}}))}var LOCAL_NAMES=new Set(["clear","new","theme","help","keys","logs","eikon","title","rollback","save","history","status","usage","profile","steer","reload","reload-mcp","chafa","splash","skin","resume","branch","compress","undo","retry","model","quit","copy","paste","image","background","voice","mouse","redraw","queue","compact","setup"]),LOCAL_COMMANDS=[{name:"clear",description:"Clear chat messages",category:"Client",aliases:[],argsHint:"",subcommands:[],source:"local",target:"local"},{name:"new",description:"Start a new session",category:"Client",aliases:["reset"],argsHint:"",subcommands:[],source:"local",target:"local"},{name:"theme",description:"Switch color theme",category:"Client",aliases:[],argsHint:"",subcommands:[],source:"local",target:"local"},{name:"help",description:"Show keyboard shortcuts",category:"Client",aliases:[],argsHint:"",subcommands:[],source:"local",target:"local"},{name:"keys",description:"Rebind keyboard shortcuts",category:"Client",aliases:[],argsHint:"",subcommands:[],source:"local",target:"local"},{name:"logs",description:"Show gateway stderr log",category:"Client",aliases:[],argsHint:"",subcommands:[],source:"local",target:"local"},{name:"eikon",description:"Pick sidebar avatar",category:"Client",aliases:[],argsHint:"",subcommands:[],source:"local",target:"local"},{name:"title",description:"Set session title",category:"Client",aliases:[],argsHint:"[text]",subcommands:[],source:"local",target:"local"},{name:"rollback",description:"Browse & restore checkpoints",category:"Client",aliases:[],argsHint:"",subcommands:[],source:"local",target:"local"},{name:"history",description:"Server-side transcript viewer",category:"Info",aliases:[],argsHint:"",subcommands:[],source:"local",target:"local"},{name:"status",description:"Version, model, paths",category:"Info",aliases:[],argsHint:"",subcommands:[],source:"local",target:"local"},{name:"usage",description:"Tokens, context fill, cost",category:"Info",aliases:[],argsHint:"",subcommands:[],source:"local",target:"local"},{name:"profile",description:"Active profile details",category:"Info",aliases:[],argsHint:"",subcommands:[],source:"local",target:"local"},{name:"steer",description:"Inject a note mid-turn (no interrupt)",category:"Session",aliases:[],argsHint:"[text]",subcommands:[],source:"local",target:"local"},{name:"reload-mcp",description:"Restart MCP servers & rediscover tools",category:"Session",aliases:[],argsHint:"[now|always]",subcommands:["now","always"],source:"local",target:"local"},{name:"reload",description:"Hot-reload ~/.hermes/.env (API keys)",category:"Session",aliases:[],argsHint:"",subcommands:[],source:"local",target:"local"},{name:"chafa",description:"Render image via chafa (demo)",category:"Client",aliases:[],argsHint:"<path>",subcommands:[],source:"local",target:"local"},{name:"splash",description:"Show the launch splash",category:"Client",aliases:[],argsHint:"",subcommands:[],source:"local",target:"local"},{name:"goal",description:"Set/control the session goal",category:"Session",aliases:[],argsHint:"[text|done|pause|resume|clear|status]",subcommands:["done","pause","resume","clear","status"],source:"command",target:"gateway"},{name:"skin",description:"Switch Hermes skin (+ theme + eikon)",category:"Client",aliases:[],argsHint:"[name]",subcommands:[...SKINS],source:"local",target:"local"}];function resolve7(list,name){let q4=name.toLowerCase();for(let c of list)if(c.name.toLowerCase()===q4||c.aliases.some((a)=>a.toLowerCase()===q4))return{hit:c};let hits=new Set;for(let c of list)for(let n of[c.name,...c.aliases])if(n.toLowerCase().startsWith(q4)){hits.add(c);break}if(hits.size===1)return{hit:[...hits][0]};if(hits.size===0)return{miss:!0};return{ambiguous:[...hits].map((c)=>`/${c.name}`).sort()}}function matchSub(list,input){let m2=input.match(/^\/(\w+)\s+(\S*)$/);if(!m2)return null;let name=m2[1],sub2=m2[2],cmd=list.find((c)=>c.name===name||c.aliases.includes(name));if(!cmd||cmd.subcommands.length===0)return null;let q4=sub2.toLowerCase(),matches=cmd.subcommands.filter((s)=>s.toLowerCase().startsWith(q4));if(matches.length===0)return null;return matches.map((s)=>({...cmd,name:`${cmd.name} ${s}`,description:`${cmd.name} \u2192 ${s}`,argsHint:"",subcommands:[]}))}var CATEGORY_ORDER=["Client","Session","Configuration","Config","Tools & Skills","Skills","Plugins","MCP","Info","Exit"];function sort(list){let idx3=(c)=>{let i=CATEGORY_ORDER.indexOf(c);return i<0?999:i};return[...list].sort((a,b2)=>{let ca=idx3(a.category)-idx3(b2.category);return ca!==0?ca:a.name.localeCompare(b2.name)})}var import_react97=__toESM(require_react_production(),1);var bare=(s)=>s[0]==="/"?s.slice(1):s;function useSlashCommands(){let gw=useGateway(),ready=useGatewayReady(),[cmds,setCmds]=import_react97.useState(LOCAL_COMMANDS),fetch2=import_react97.useCallback(async()=>{let res=await gw.request("commands.catalog").catch(()=>null);if(!res){setCmds(LOCAL_COMMANDS);return}let cat=new Map;for(let g of res.categories??[])for(let[n]of g.pairs??[])cat.set(bare(n),g.name);let alias=new Map;for(let[a,c]of Object.entries(res.canon??{})){let k2=bare(c),v2=bare(a);if(k2===v2)continue;(alias.get(k2)??alias.set(k2,[]).get(k2)).push(v2)}let sub2=new Map(Object.entries(res.sub??{}).map(([k2,v2])=>[bare(k2),v2])),local=new Map(LOCAL_COMMANDS.map((c)=>[c.name,c])),remote=(res.pairs??[]).map(([raw,desc])=>{let name=bare(raw),l=local.get(name);return{name,description:desc,category:cat.get(name)??(name.includes(":")?"Skills":"Command"),aliases:alias.get(name)??[],argsHint:l?.argsHint??"",subcommands:sub2.get(name)??l?.subcommands??[],source:"command",target:LOCAL_NAMES.has(name)?"local":"gateway"}}),seen=new Set(remote.map((c)=>c.name)),locals=LOCAL_COMMANDS.filter((c)=>!seen.has(c.name));setCmds(sort([...locals,...remote]))},[gw]);return import_react97.useEffect(()=>{if(ready)fetch2()},[ready,fetch2]),{cmds,refresh:fetch2}}var import_react103=__toESM(require_react_production(),1);var winDrive=(s,off=0)=>s.length>=off+3&&/[A-Za-z]/.test(s[off])&&s[off+1]===":"&&(s[off+2]==="\\"||s[off+2]==="/");function looksLikePath(s){let t2=s.trim();if(!t2||t2.includes(`
4129
4129
  `))return!1;if(t2.startsWith("file://"))return!0;if(t2.startsWith("/")||t2.startsWith("~")||t2.startsWith("./")||t2.startsWith("../"))return!0;if(winDrive(t2))return!0;let q4=t2[0];if(q4==='"'||q4==="'"){let inner=t2[1];if(inner==="/"||inner==="~")return!0;if(winDrive(t2,1))return!0}return!1}var import_react98=__toESM(require_react_production(),1);var SEP=new Set(["-","_","/"," ","."]);function boundary(hay,i){if(i===0)return!0;let prev=hay[i-1];if(SEP.has(prev))return!0;if(prev===prev.toLowerCase()&&hay[i]!==hay[i].toLowerCase())return!0;return!1}function score(needle,hay){if(!needle)return 0;let n=needle.toLowerCase(),h2=hay.toLowerCase(),pts=0,from2=0,prev=-2;for(let i=0;i<n.length;i++){let at=h2.indexOf(n[i],from2);if(at<0)return 0;if(pts+=1,at===0)pts+=8;if(at===prev+1)pts+=5;if(at!==prev+1&&boundary(hay,at))pts+=4;pts-=(at-(prev<0?0:prev+1))*0.1,prev=at,from2=at+1}if(h2.startsWith(n))pts+=100;return pts-hay.length*0.01}function best(q4,cmd){return cmd.aliases.reduce((m2,a)=>Math.max(m2,score(q4,a)),score(q4,cmd.name))}function rank(list,q4){if(!q4)return[...list];return list.map((cmd)=>({cmd,s:best(q4,cmd)})).filter((r)=>r.s>0).sort((a,b2)=>b2.s-a.s).map((r)=>r.cmd)}function useSlashPopover(input,cmds){let[cursor,setCursor]=import_react98.useState(0),popover=import_react98.useMemo(()=>{let subs2=matchSub(cmds,input);if(subs2)return subs2;let m2=input.match(/^\/(\S*)$/);return m2?rank(cmds,m2[1]):null},[input,cmds]);import_react98.useEffect(()=>{setCursor((c)=>c===0?c:0)},[input]);let ghost=import_react98.useMemo(()=>{if(!popover||popover.length===0)return"";let best2=popover[Math.min(cursor,popover.length-1)];if(!best2||best2.name.includes(" "))return"";let m2=input.match(/^\/(\S*)$/);if(!m2)return"";let typed=m2[1];if(typed.length<2)return"";if(!best2.name.toLowerCase().startsWith(typed.toLowerCase()))return"";return best2.name.slice(typed.length)},[input,popover,cursor]),open2=popover!==null&&popover.length>0;return{popover,cursor,setCursor,ghost,open:open2}}var import_react99=__toESM(require_react_production(),1);var KEYWORDS=[{text:"@diff",display:"@diff",meta:"working-tree diff"},{text:"@staged",display:"@staged",meta:"staged changes"},{text:"@git:1",display:"@git:1",meta:"last 1 commit"},{text:"@git:3",display:"@git:3",meta:"last 3 commits"},{text:"@git:5",display:"@git:5",meta:"last 5 commits"},{text:"@url:",display:"@url:<\u2026>",meta:"fetch a URL"},{text:"@folder:",display:"@folder:<path>",meta:"recurse directory"}];function match2(word){let q4=word.toLowerCase();return KEYWORDS.filter((k2)=>k2.text.toLowerCase().startsWith(q4)&&k2.text!==word)}function atWordAt(input){if(input.startsWith("/"))return null;let end=input.length,i=end;while(i>0&&!/\s/.test(input[i-1]))i--;if(i>=end||input[i]!=="@")return null;return{word:input.slice(i,end),start:i}}function useAtRefPopover(input){let gw=useGateway(),ready=useGatewayReady(),[items,setItems]=import_react99.useState([]),[cursor,setCursor]=import_react99.useState(0),seq=import_react99.useRef(0),dismissed=import_react99.useRef(null),spot=atWordAt(input);return import_react99.useEffect(()=>{if(!spot||!ready){setItems([]),setCursor(0);return}if(dismissed.current===spot.word)return;dismissed.current=null;let me2=++seq.current,fixed=match2(spot.word),t2=setTimeout(()=>{gw.request("complete.path",{word:spot.word}).then((r)=>{if(seq.current!==me2)return;let seen=new Set(fixed.map((k2)=>k2.text));setItems([...fixed,...(r.items??[]).filter((i)=>!seen.has(i.text))]),setCursor(0)}).catch(()=>{if(seq.current===me2)setItems(fixed),setCursor(0)})},120);return()=>clearTimeout(t2)},[spot?.word,ready,gw]),{open:spot!==null&&items.length>0,items,cursor,setCursor,accept:(src2,idx3=cursor)=>{let at=atWordAt(src2),it=items[idx3];if(!at||!it)return null;let trail2=it.text.endsWith(":")||it.text.endsWith("/")?"":" ";return src2.slice(0,at.start)+it.text+trail2+src2.slice(at.start+at.word.length)},dismiss:()=>{seq.current++,dismissed.current=spot?.word??null,setItems([])}}}var import_react100=__toESM(require_react_production(),1);import{join as join14}from"path";import{existsSync as existsSync16,mkdirSync as mkdirSync3,readFileSync as readFileSync9,appendFileSync,writeFileSync as writeFileSync3}from"fs";var MAX=500,file=()=>join14(configDir(),"history");function load3(){let FILE2=file();if(!existsSync16(FILE2))return[];return readFileSync9(FILE2,"utf-8").split(`
4130
4130
  `).filter(Boolean).map((l)=>l.replace(/\0/g,`
4131
4131
  `)).slice(-MAX).reverse()}function enc2(s){return s.replace(/\n/g,"\x00")}function useInputHistory(input,setInput){let hist=import_react100.useRef(null);if(hist.current===null)hist.current=load3();let[,bump]=import_react100.useState(0),idx3=import_react100.useRef(-1),stash=import_react100.useRef(""),push2=import_react100.useCallback((msg)=>{idx3.current=-1,stash.current="";let h2=hist.current;if(msg===h2[0])return;h2.unshift(msg);let DIR=configDir(),FILE2=file();if(!existsSync16(DIR))mkdirSync3(DIR,{recursive:!0});if(h2.length>MAX)h2.length=MAX,writeFileSync3(FILE2,[...h2].reverse().map(enc2).join(`
@@ -4142,9 +4142,9 @@ Usage:
4142
4142
  *[interrupted]*`,usage:p?.usage};return{kind:"message.complete",text:p?.text??void 0,usage:p?.usage}}case"tool.start":return{kind:"tool.start",id:ev.payload.tool_id,name:ev.payload.name??"unknown",preview:ev.payload.context};case"tool.progress":return{kind:"tool.progress",name:ev.payload.name,preview:ev.payload.preview};case"tool.generating":return{kind:"tool.generating",name:ev.payload.name};case"tool.complete":return{kind:"tool.complete",id:ev.payload.tool_id,summary:ev.payload.summary,error:ev.payload.error,inline_diff:ev.payload.inline_diff};case"thinking.delta":return side.onStatus?.(ev.payload?.text??""),null;case"reasoning.delta":case"reasoning.available":{let text2=ev.payload?.text;if(!text2)return null;return{kind:"thinking",text:text2,final:ev.type==="reasoning.available"}}case"subagent.start":case"subagent.thinking":case"subagent.tool":case"subagent.progress":case"subagent.complete":{let sub2=ev.type.slice(9);return record(sub2,ev.payload),{kind:"subagent",event:sub2,payload:ev.payload}}case"error":return{kind:"error",text:ev.payload?.message??"Unknown error"};case"clarify.request":return{kind:"prompt",id:ev.payload.request_id,req:{variant:"clarify",...ev.payload}};case"approval.request":return{kind:"prompt",id:`approval-${pid()}`,req:{variant:"approval",...ev.payload}};case"sudo.request":return{kind:"prompt",id:ev.payload.request_id,req:{variant:"sudo",...ev.payload}};case"secret.request":return{kind:"prompt",id:ev.payload.request_id,req:{variant:"secret",...ev.payload}};case"background.complete":return side.onBackground?.(ev.payload.task_id,ev.payload.text),null;case"review.summary":{let text2=String(ev.payload?.text??"").trim();if(!text2)return null;return{kind:"system",text:text2}}case"btw.complete":return side.onBtw?.(ev.payload.text),null;case"gateway.stderr":{let line3=ev.payload.line;if(/error|fail|traceback|exception|\b[45]\d\d\b|refused|denied|unauthori/i.test(line3))return{kind:"system",text:line3.slice(0,200)};return null}case"skin.changed":return side.onSkin?.(ev.payload),null;case"gateway.start_timeout":return{kind:"error",text:`gateway startup timed out (${ev.payload?.python??"python"} @ ${ev.payload?.cwd??"?"})`};case"gateway.protocol_error":return{kind:"system",text:`protocol error: ${ev.payload?.preview??"?"}`};case"browser.progress":{let text2=ev.payload?.message??"";if(!text2)return null;return ev.payload?.level==="error"?{kind:"error",text:text2}:{kind:"system",text:`\xB7 ${text2}`}}case"status.update":{let kind=ev.payload?.kind,text2=ev.payload?.text??"";if(side.onStatus?.(text2),!kind||kind==="status")return null;return{kind:"system",text:text2}}}return null}var import_react104=__toESM(require_react_production(),1);init_sessions_db();function useSession(){let gw=useGateway(),resume=import_react104.useCallback(async(sid)=>{let res=await gw.request("session.resume",{session_id:sid}),id=res.session_id;gw.setSession(id),set("lastSessionId",res.resumed??sid);let messages=res.messages?.length?transcriptToMessages(res.messages):[];return{id,messages}},[gw]),create=import_react104.useCallback(async()=>{let res=await gw.request("session.create",{});return gw.setSession(res.session_id),res.session_id},[gw]),boot2=import_react104.useCallback(async(launch)=>{let fresh=async(note)=>({id:await create(),messages:[],note});if(launch.mode==="resume"){let target=launch.sid??lastReal()?.id;if(!target)return fresh("no prior session to resume \u2014 starting fresh");try{return await resume(target)}catch{return fresh(`resume ${target} failed \u2014 starting fresh`)}}let last3=get("lastSessionId");if(last3&&byId(last3)?.message_count===0)try{return await resume(last3)}catch{}return fresh()},[create,resume]),interrupt=import_react104.useCallback(async()=>{try{await gw.request("session.interrupt")}catch{}},[gw]),branch2=import_react104.useCallback(async(name)=>{try{return(await gw.request("session.branch",name?{name}:{})).session_id??null}catch{return null}},[gw]),compress=import_react104.useCallback(async()=>{try{return await gw.request("session.compress")}catch{return null}},[gw]),undo=import_react104.useCallback(async()=>{try{await gw.request("session.undo")}catch{}},[gw]);return import_react104.useMemo(()=>({boot:boot2,create,resume,interrupt,branch:branch2,compress,undo}),[boot2,create,resume,interrupt,branch2,compress,undo])}var import_react106=__toESM(require_react_production(),1);import{tmpdir}from"os";import{join as join15}from"path";import{rm}from"fs/promises";async function editInEditor(renderer,seed){let cmd=process.env.VISUAL||process.env.EDITOR;if(!cmd)return;let path7=join15(tmpdir(),`herm-${Date.now()}.md`);await Bun.write(path7,seed),renderer.suspend(),renderer.currentRenderBuffer.clear();let parts2=cmd.split(" ");await Bun.spawn([...parts2,path7],{stdin:"inherit",stdout:"inherit",stderr:"inherit"}).exited;let text2=await Bun.file(path7).text().catch(()=>"");if(rm(path7,{force:!0}).catch(()=>{}),renderer.isDestroyed)return text2.trim()||void 0;return renderer.currentRenderBuffer.clear(),renderer.resume(),renderer.requestRender(),text2.trim()||void 0}function redraw(renderer){resolveRenderLib().clearTerminal(renderer.rendererPtr),renderer.currentRenderBuffer.clear(RGBA.fromValues(0,0,0,0)),renderer.requestRender()}var INTERRUPT_MS=5000,DOUBLE_TAB_MS=400;function useAppKeys(o){let renderer=useRenderer(),keys=useKeys(),lastEsc=import_react106.useRef(0),lastTab=import_react106.useRef(0),regionFor=(t2)=>t2===o.chatTab?"input":"content";import_react106.useEffect(()=>{let found=conflicts(keys.table).filter((c)=>!(c.a==="session.interrupt"&&c.b==="dialog.cancel")).filter((c)=>!(c.a==="app.exit"&&c.b==="input.clear"));if(found.length===0)return;let first=found[0];o.onNotice(`Keybinding conflict: ${print([first.chord])} \u2192 ${first.a} and ${first.b}`+(found.length>1?` (+${found.length-1} more)`:""))},[keys.table]),useKeyboard((key2)=>{let c=o.composer.current;if(keys.match("input.clear",key2)&&c&&!c.isEmpty()){c.set(""),key2.stopPropagation();return}if(keys.match("app.exit",key2))return o.onQuit();if(keys.match("app.suspend",key2)){renderer.suspend(),process.kill(process.pid,"SIGTSTP"),process.once("SIGCONT",()=>renderer.resume());return}if(keys.match("app.redraw",key2)){redraw(renderer),key2.stopPropagation();return}if(keys.match("app.sidebar",key2)){o.onToggleSidebar();return}if(o.dialogOpen())return;if(keys.match("queue.flush",key2)&&o.streaming&&o.queued>0){o.onFlushQueue(),key2.stopPropagation();return}if(o.onPromptKey&&!keys.leader&&!key2.ctrl&&!key2.meta&&key2.eventType!=="release"){if(o.onPromptKey(key2)){key2.stopPropagation();return}}if(keys.match("editor.open",key2)&&!o.streaming){let seed=c?.value()??"";editInEditor(renderer,seed).then((out)=>{if(out===void 0){if(!process.env.VISUAL&&!process.env.EDITOR)o.onNotice("Set $EDITOR or $VISUAL to use the external editor");return}c?.set(out),o.setFocusRegion("input")});return}if(keys.match("tab.prev",key2)){o.setTab((t2)=>{let n=Math.max(0,t2-1);return o.setFocusRegion(regionFor(n)),n});return}if(keys.match("tab.next",key2)){o.setTab((t2)=>{let n=Math.min(o.tabMax,t2+1);return o.setFocusRegion(regionFor(n)),n});return}if(keys.leader&&!key2.ctrl&&!key2.meta&&!key2.shift&&key2.eventType!=="release"){let n={"1":0,"2":1,"3":2,"4":3,"5":4,"6":5,"7":6,"8":7,"9":8,"0":9,"-":10}[key2.name];if(n!==void 0&&n<=o.tabMax){o.setTab(()=>{return o.setFocusRegion(regionFor(n)),n}),key2.stopPropagation();return}}if(c?.popOpen()){if(key2.name==="escape")return c.popCancel();if(key2.name==="up"){c.popNav(-1),key2.stopPropagation();return}if(key2.name==="down"){c.popNav(1),key2.stopPropagation();return}if(key2.name==="tab")return c.popAccept();return}if(keys.match("focus.cycle",key2)&&!o.streaming){if(o.tab===o.chatTab){o.setFocusRegion((r)=>r==="input"?"content":"input");return}if(o.focusRegion==="input"){o.setFocusRegion("content");return}let now=Date.now();if(now-lastTab.current<DOUBLE_TAB_MS)o.setFocusRegion("input"),lastTab.current=0,key2.stopPropagation();else lastTab.current=now;return}if(keys.match("session.interrupt",key2)){if(!o.streaming&&o.onEscape?.())return;if(o.streaming){let now=Date.now();if(now-lastEsc.current<INTERRUPT_MS){o.onInterrupt(),lastEsc.current=0;return}lastEsc.current=now,o.onInterruptNotice();return}if(o.tab===o.chatTab&&o.focusRegion==="content")o.setFocusRegion("input");return}if(keys.match("reply.copy",key2))return o.onCopyLast();if(keys.match("clipboard.attach",key2)){o.onAttachClipboard(),key2.stopPropagation();return}if(o.focusRegion==="input"&&!o.streaming){if(key2.name==="up")return void c?.historyUp();if(key2.name==="down")return void c?.historyDown();if(key2.name==="backspace"&&!key2.ctrl&&!key2.meta&&c?.isEmpty()&&o.onDetachLast()){key2.stopPropagation();return}}if(o.tab===o.chatTab&&o.focusRegion==="content"&&!o.streaming&&!key2.ctrl&&!key2.meta&&key2.eventType!=="release"){if(key2.name.length===1&&key2.name!==" "){let ch=key2.shift&&/[a-z]/.test(key2.name)?key2.name.toUpperCase():key2.name;o.setFocusRegion("input"),c?.insert(ch),key2.stopPropagation()}}})}import{writeSync}from"fs";var done=!1;function quit(renderer,sid,title){if(done)process.exit(0);if(done=!0,renderer.destroy(),process.stdout.isTTY&&sid){let t2=title?` \u2014 ${title.slice(0,60)}`:"";writeSync(1,`
4143
4143
  continue herm --resume ${sid}${t2}
4144
4144
 
4145
- `)}process.exit(0)}init_sessions_db();init_hermes_analytics();function rehome(newHome){process.env.HERMES_HOME=newHome,setHome2(newHome),setHome(newHome),cache2.clear(),resetKanban(),reload(),home2.reset()}var import_react107=__toESM(require_react_production(),1);var Countdown=(p)=>{let theme=useTheme().theme,[n,setN]=import_react107.useState(p.seconds);import_react107.useEffect(()=>{if(n<=0){p.onFire();return}let t2=setTimeout(()=>setN((v2)=>v2-1),1000);return()=>clearTimeout(t2)},[n,p.onFire]),useKeyboard(()=>p.onCancel());let bar3="\u2588".repeat(n)+"\u2591".repeat(Math.max(0,p.seconds-n));return $jsxs("box",{flexDirection:"column",width:58,children:[$jsx("box",{height:1,children:$jsx("text",{fg:theme.warning,children:$jsx("strong",{children:p.title})})}),$jsx("box",{height:1}),$jsx("box",{minHeight:1,children:$jsx("text",{wrapMode:"word",children:p.body})}),$jsx("box",{height:1}),$jsx("box",{height:1,children:$jsxs("text",{fg:theme.warning,children:[bar3," ",n,"s"]})}),$jsx("box",{height:1,children:$jsx("text",{fg:theme.textMuted,children:p.action})}),$jsx("box",{height:1}),$jsx("box",{height:1,children:$jsx("text",{fg:theme.textMuted,children:"press any key to cancel"})})]})};function openCountdown(dialog,opts){return new Promise((resolve4)=>{dialog.replace($jsx(Countdown,{...opts,onFire:()=>{dialog.clear(),resolve4(!0)},onCancel:()=>{dialog.clear(),resolve4(!1)}}),()=>resolve4(!1))})}var SECONDS=10,SUSPEND=process.platform==="darwin"?"pmset sleepnow":"systemctl suspend",VERBS2=new Set(["status","pause","resume","clear","stop","done"]),ANSI3=/\x1b\[[0-9;]*m/g,run=(cmd)=>Bun.spawn(["sh","-c",cmd],{stdout:"ignore",stderr:"ignore"}),fired=new Map;function makeGoalHook(gw,dialog,toast){let act=(goal)=>{let pref=(get("onGoalDone")??"toast").trim(),head=goal.length>60?goal.slice(0,57)+"\u2026":goal;if(toast.show({variant:"success",title:"Goal complete",message:head,duration:8000}),pref==="toast")return;let cmd=pref==="suspend"?SUSPEND:pref;openCountdown(dialog,{title:"Goal complete \u2014 "+(pref==="suspend"?"suspending":"running hook"),body:head,action:`\u2192 ${cmd}`,seconds:SECONDS}).then((ok)=>{if(ok)run(cmd)})};return{check:(sid)=>{if(!sid)return;io.goalState(sid).then((s)=>{if(!s||s.status!=="done")return;if(fired.get(sid)===s.goal)return;fired.set(sid,s.goal),act(s.goal)}).catch(()=>{})},cmd:async(arg)=>{let trimmed=arg.trim(),first=trimmed.split(/\s+/,1)[0]?.toLowerCase()??"",kick=trimmed&&!VERBS2.has(first)?trimmed:null;return{line:((await gw.request("slash.exec",{command:`/goal${trimmed?" "+trimmed:""}`})).output??"").replace(ANSI3,"").trim()||"ok",kick}}}}var App=(props)=>$jsx(ThemeProvider,{initial:props.initialTheme,children:$jsx(GatewayProvider,{client:props.gateway,children:$jsx(ToastProvider,{children:$jsx(KeysProvider,{children:$jsx(DialogProvider,{children:$jsx(CommandProvider,{children:$jsx(AppInner,{launch:props.launch??{mode:"new"}})})})})})})}),AppInner=({launch:launch0})=>{let gw=useGateway(),gwRestart=useGatewayRestart(),dialog=useDialog(),themeCtx=useTheme(),cmd=useCommand(),toast=useToast(),renderer=useRenderer(),session=useSession(),dims=useTerminalDimensions(),goalHook=import_react110.useMemo(()=>makeGoalHook(gw,dialog,toast),[gw,dialog,toast]),[turn,dispatch]=import_react110.useReducer(turnReducer,initialTurn),[ready,setReady]=import_react110.useState(!1),[sid,setSid]=import_react110.useState(""),sidRef=import_react110.useRef(sid);sidRef.current=sid;let[tab,setTab]=import_react110.useState(CHAT_TAB),[hideSidebar,setHideSidebar]=import_react110.useState(!1),[usage,setUsage]=import_react110.useState(void 0),[info2,setInfo]=import_react110.useState(null),[title,setTitle]=import_react110.useState(""),[focusRegion,setFocusRegion]=import_react110.useState("input"),goToTab=import_react110.useCallback((t2)=>{setTab(t2),setFocusRegion(t2===CHAT_TAB?"input":"content")},[]),[status,setStatus]=import_react110.useState(""),[eikon,setEikon]=import_react110.useState(void 0),[queue,setQueue]=import_react110.useState([]),launchRef=import_react110.useRef(launch0),launch=launchRef.current,[splash,setSplash]=import_react110.useState(launch.splash!==!1),[switching,setSwitching]=import_react110.useState(!1),summoned=import_react110.useRef(!1),[composing,setComposing]=import_react110.useState(!1),splashLast=import_react110.useMemo(()=>launch.mode==="new"?lastReal():void 0,[launch.mode]),news=import_react110.useMemo(()=>readChangelog()?.headline,[]),[attachments,setAttachments]=import_react110.useState([]),[cloudH,setCloudH]=import_react110.useState(CLOUD_MIN),[pick,setPick]=import_react110.useState(void 0),[skin,setSkin]=import_react110.useState(()=>deriveSkin(void 0)),inflight=import_react110.useRef(!1),interrupted=import_react110.useRef(!1),sessionStart=import_react110.useRef(Date.now()),composer2=import_react110.useRef(null),promptRef=import_react110.useRef(null),{cmds}=useSlashCommands(),cmdsRef=import_react110.useRef(cmds);cmdsRef.current=cmds;let[errorPulse,setErrorPulse]=import_react110.useState(!1),agentState=errorPulse?"error":turn.toolActive?"working":turn.streaming&&turn.hasContent?"speaking":turn.streaming?"thinking":composing?"listening":"idle",onAvatarHold=import_react110.useCallback((s)=>{if(s==="error")setErrorPulse(!1)},[]),prompt=pending(turn.messages),cloudAuto=turn.streaming&&!turn.hasContent&&!prompt,[force,setForce]=import_react110.useState(void 0),cloud=!prompt&&(force??cloudAuto),prevStream=import_react110.useRef(turn.streaming);import_react110.useEffect(()=>{if(!prevStream.current&&turn.streaming)setForce(void 0),setPick(void 0);prevStream.current=turn.streaming},[turn.streaming]);let onPick=import_react110.useCallback((m2)=>{setPick((p)=>{if(m2&&p&&m2.id===p.id){setForce(!1);return}return setForce(!!m2),m2})},[]),onAvatar=import_react110.useCallback(()=>{let next2=!cloud;if(!next2)setPick(void 0);setForce(next2)},[cloud]),closeCloud=import_react110.useCallback(()=>{setForce(!1),setPick(void 0)},[]),onEnqueue=import_react110.useCallback((t2)=>setQueue((q4)=>[...q4,t2]),[]),onAttach=import_react110.useCallback((r)=>setAttachments((a)=>[...a,r]),[]),reset=import_react110.useCallback(()=>{interrupted.current=!1,dispatch({kind:"reset"}),setUsage(void 0),setReady(!1),setStatus(""),setTitle(""),setAttachments([])},[]),newSession=import_react110.useCallback(async()=>{reset(),summoned.current=!0,setSplash(!0);try{setSid(await session.create()),sessionStart.current=Date.now()}catch{}},[reset,session]),switchSession=import_react110.useCallback(async(target)=>{reset(),summoned.current=!0,setSplash(!0),setSwitching(!0),goToTab(CHAT_TAB);try{let res=await session.resume(target);if(setSid(res.id),sessionStart.current=Date.now(),res.messages.length)dispatch({kind:"load",messages:res.messages});setSplash(!1),summoned.current=!1}catch(err){dispatch({kind:"system",text:`Failed to resume: ${err instanceof Error?err.message:String(err)}`}),setSplash(!1),summoned.current=!1}finally{setSwitching(!1)}},[reset,session,goToTab]),switchProfile=import_react110.useCallback((newHome,name)=>{rehome(newHome),reset(),gw.setSession(""),setSid(""),setInfo(null),setSkin(deriveSkin(void 0)),summoned.current=!0,setSplash(!0),launchRef.current={mode:"new",splash:!0},toast.show({variant:"info",message:`Switching to '${name}'\u2026`}),goToTab(CHAT_TAB),gwRestart()},[reset,goToTab,gwRestart,toast,gw]),runCompress=import_react110.useCallback(async()=>{toast.show({variant:"info",message:"Compressing session\u2026"});let r=await session.compress();if(!r||!r.summary)return;let s=r.summary;if(s.noop){toast.show({variant:"info",message:s.headline??`No changes \xB7 ~${r.before_tokens??0} tokens`});return}let lines2=[s.headline,s.token_line,s.note].filter(Boolean).join(`
4145
+ `)}process.exit(0)}init_sessions_db();init_hermes_analytics();function rehome(newHome){process.env.HERMES_HOME=newHome,setHome2(newHome),setHome(newHome),cache2.clear(),resetKanban(),reload(),home2.reset()}var import_react107=__toESM(require_react_production(),1);var Countdown=(p)=>{let theme=useTheme().theme,[n,setN]=import_react107.useState(p.seconds);import_react107.useEffect(()=>{if(n<=0){p.onFire();return}let t2=setTimeout(()=>setN((v2)=>v2-1),1000);return()=>clearTimeout(t2)},[n,p.onFire]),useKeyboard(()=>p.onCancel());let bar3="\u2588".repeat(n)+"\u2591".repeat(Math.max(0,p.seconds-n));return $jsxs("box",{flexDirection:"column",width:58,children:[$jsx("box",{height:1,children:$jsx("text",{fg:theme.warning,children:$jsx("strong",{children:p.title})})}),$jsx("box",{height:1}),$jsx("box",{minHeight:1,children:$jsx("text",{wrapMode:"word",children:p.body})}),$jsx("box",{height:1}),$jsx("box",{height:1,children:$jsxs("text",{fg:theme.warning,children:[bar3," ",n,"s"]})}),$jsx("box",{height:1,children:$jsx("text",{fg:theme.textMuted,children:p.action})}),$jsx("box",{height:1}),$jsx("box",{height:1,children:$jsx("text",{fg:theme.textMuted,children:"press any key to cancel"})})]})};function openCountdown(dialog,opts){return new Promise((resolve4)=>{dialog.replace($jsx(Countdown,{...opts,onFire:()=>{dialog.clear(),resolve4(!0)},onCancel:()=>{dialog.clear(),resolve4(!1)}}),()=>resolve4(!1))})}var SECONDS=10,SUSPEND=process.platform==="darwin"?"pmset sleepnow":"systemctl suspend",run=(cmd)=>Bun.spawn(["sh","-c",cmd],{stdout:"ignore",stderr:"ignore"}),fired=new Map;function makeGoalHook(dialog,toast){let act=(goal)=>{let pref=(get("onGoalDone")??"toast").trim(),head=goal.length>60?goal.slice(0,57)+"\u2026":goal;if(toast.show({variant:"success",title:"Goal complete",message:head,duration:8000}),pref==="toast")return;let cmd=pref==="suspend"?SUSPEND:pref;openCountdown(dialog,{title:"Goal complete \u2014 "+(pref==="suspend"?"suspending":"running hook"),body:head,action:`\u2192 ${cmd}`,seconds:SECONDS}).then((ok)=>{if(ok)run(cmd)})};return{check:(sid)=>{if(!sid)return;io.goalState(sid).then((s)=>{if(!s||s.status!=="done")return;if(fired.get(sid)===s.goal)return;fired.set(sid,s.goal),act(s.goal)}).catch(()=>{})}}}var App=(props)=>$jsx(ThemeProvider,{initial:props.initialTheme,children:$jsx(GatewayProvider,{client:props.gateway,children:$jsx(ToastProvider,{children:$jsx(KeysProvider,{children:$jsx(DialogProvider,{children:$jsx(CommandProvider,{children:$jsx(AppInner,{launch:props.launch??{mode:"new"}})})})})})})}),AppInner=({launch:launch0})=>{let gw=useGateway(),gwRestart=useGatewayRestart(),dialog=useDialog(),themeCtx=useTheme(),cmd=useCommand(),toast=useToast(),renderer=useRenderer(),session=useSession(),dims=useTerminalDimensions(),goalHook=import_react110.useMemo(()=>makeGoalHook(dialog,toast),[dialog,toast]),[turn,dispatch]=import_react110.useReducer(turnReducer,initialTurn),[ready,setReady]=import_react110.useState(!1),[sid,setSid]=import_react110.useState(""),sidRef=import_react110.useRef(sid);sidRef.current=sid;let[tab,setTab]=import_react110.useState(CHAT_TAB),[hideSidebar,setHideSidebar]=import_react110.useState(!1),[usage,setUsage]=import_react110.useState(void 0),[info2,setInfo]=import_react110.useState(null),[title,setTitle]=import_react110.useState(""),[focusRegion,setFocusRegion]=import_react110.useState("input"),goToTab=import_react110.useCallback((t2)=>{setTab(t2),setFocusRegion(t2===CHAT_TAB?"input":"content")},[]),[status,setStatus]=import_react110.useState(""),[eikon,setEikon]=import_react110.useState(void 0),[queue,setQueue]=import_react110.useState([]),launchRef=import_react110.useRef(launch0),launch=launchRef.current,[splash,setSplash]=import_react110.useState(launch.splash!==!1),[switching,setSwitching]=import_react110.useState(!1),summoned=import_react110.useRef(!1),[composing,setComposing]=import_react110.useState(!1),splashLast=import_react110.useMemo(()=>launch.mode==="new"?lastReal():void 0,[launch.mode]),news=import_react110.useMemo(()=>readChangelog()?.headline,[]),[attachments,setAttachments]=import_react110.useState([]),[cloudH,setCloudH]=import_react110.useState(CLOUD_MIN),[pick,setPick]=import_react110.useState(void 0),[skin,setSkin]=import_react110.useState(()=>deriveSkin(void 0)),inflight=import_react110.useRef(!1),interrupted=import_react110.useRef(!1),sessionStart=import_react110.useRef(Date.now()),composer2=import_react110.useRef(null),promptRef=import_react110.useRef(null),{cmds}=useSlashCommands(),cmdsRef=import_react110.useRef(cmds);cmdsRef.current=cmds;let[errorPulse,setErrorPulse]=import_react110.useState(!1),agentState=errorPulse?"error":turn.toolActive?"working":turn.streaming&&turn.hasContent?"speaking":turn.streaming?"thinking":composing?"listening":"idle",onAvatarHold=import_react110.useCallback((s)=>{if(s==="error")setErrorPulse(!1)},[]),prompt=pending(turn.messages),cloudAuto=turn.streaming&&!turn.hasContent&&!prompt,[force,setForce]=import_react110.useState(void 0),cloud=!prompt&&(force??cloudAuto),prevStream=import_react110.useRef(turn.streaming);import_react110.useEffect(()=>{if(!prevStream.current&&turn.streaming)setForce(void 0),setPick(void 0);prevStream.current=turn.streaming},[turn.streaming]);let onPick=import_react110.useCallback((m2)=>{setPick((p)=>{if(m2&&p&&m2.id===p.id){setForce(!1);return}return setForce(!!m2),m2})},[]),onAvatar=import_react110.useCallback(()=>{let next2=!cloud;if(!next2)setPick(void 0);setForce(next2)},[cloud]),closeCloud=import_react110.useCallback(()=>{setForce(!1),setPick(void 0)},[]),onEnqueue=import_react110.useCallback((t2)=>setQueue((q4)=>[...q4,t2]),[]),onAttach=import_react110.useCallback((r)=>setAttachments((a)=>[...a,r]),[]),reset=import_react110.useCallback(()=>{interrupted.current=!1,dispatch({kind:"reset"}),setUsage(void 0),setReady(!1),setStatus(""),setTitle(""),setAttachments([])},[]),newSession=import_react110.useCallback(async()=>{reset(),summoned.current=!0,setSplash(!0);try{setSid(await session.create()),sessionStart.current=Date.now()}catch{}},[reset,session]),switchSession=import_react110.useCallback(async(target)=>{reset(),summoned.current=!0,setSplash(!0),setSwitching(!0),goToTab(CHAT_TAB);try{let res=await session.resume(target);if(setSid(res.id),sessionStart.current=Date.now(),res.messages.length)dispatch({kind:"load",messages:res.messages});setSplash(!1),summoned.current=!1}catch(err){dispatch({kind:"system",text:`Failed to resume: ${err instanceof Error?err.message:String(err)}`}),setSplash(!1),summoned.current=!1}finally{setSwitching(!1)}},[reset,session,goToTab]),switchProfile=import_react110.useCallback((newHome,name)=>{rehome(newHome),reset(),gw.setSession(""),setSid(""),setInfo(null),setSkin(deriveSkin(void 0)),summoned.current=!0,setSplash(!0),launchRef.current={mode:"new",splash:!0},toast.show({variant:"info",message:`Switching to '${name}'\u2026`}),goToTab(CHAT_TAB),gwRestart()},[reset,goToTab,gwRestart,toast,gw]),runCompress=import_react110.useCallback(async()=>{toast.show({variant:"info",message:"Compressing session\u2026"});let r=await session.compress();if(!r||!r.summary)return;let s=r.summary;if(s.noop){toast.show({variant:"info",message:s.headline??`No changes \xB7 ~${r.before_tokens??0} tokens`});return}let lines2=[s.headline,s.token_line,s.note].filter(Boolean).join(`
4146
4146
  `);if(lines2)dispatch({kind:"system",text:lines2});toast.show({variant:"success",message:s.headline??`Compressed ${r.before_messages??0}\u2192${r.after_messages??0} messages`})},[session,toast,dispatch]),loadEikon=import_react110.useCallback((path7)=>{Bun.file(path7).text().then((t2)=>setEikon(parseEikon(t2))).catch(()=>{})},[]),eikonPath=usePref("eikonPath");import_react110.useEffect(()=>{let p=eikonPath||bundledEikonPath(skin.skin?.name);if(p)loadEikon(p);else setEikon(void 0)},[eikonPath,skin.skin?.name,loadEikon]);let pickEikon=import_react110.useCallback(()=>{openEikonPicker(dialog,(path7)=>set("eikonPath",path7))},[dialog]),applyTitle=import_react110.useCallback((t2)=>{gw.request("session.title",{title:t2}).then((r)=>{setTitle(r.title),dispatch({kind:"system",text:`Title: ${r.title}`})}).catch((e)=>toast.show({variant:"error",message:e.message}))},[gw,toast]),editTitle=import_react110.useCallback(()=>{openTextPrompt(dialog,{title:"Session Title",initial:title}).then((v2)=>{if(v2)applyTitle(v2)})},[dialog,title,applyTitle]),turnsFrom=(m2)=>{let at=turn.messages.findIndex((x2)=>x2.id===m2.id);return at<0?0:turn.messages.slice(at).filter((x2)=>x2.role==="user").length},rewind=import_react110.useCallback(async(m2)=>{if(turn.streaming)return;let n=turnsFrom(m2);if(n===0)return;let text2=m2.parts.filter((p)=>p.type==="text").map((p)=>p.content).join("");for(let i=0;i<n;i++)await gw.request("session.undo").catch(()=>{});let r=await gw.request("session.history").catch(()=>null),at=turn.messages.findIndex((x2)=>x2.id===m2.id);dispatch({kind:"load",messages:r?transcriptToMessages(r.messages??[]):turn.messages.slice(0,at)}),composer2.current?.set(text2),setFocusRegion("input")},[turn.streaming,turn.messages,gw]),fork=import_react110.useCallback(async(m2)=>{if(turn.streaming)return;let n=turnsFrom(m2),text2=m2.parts.filter((p)=>p.type==="text").map((p)=>p.content).join(""),res=await gw.request("session.branch",{}).catch((e)=>{return toast.show({variant:"error",message:`branch failed: ${e.message}`}),null});if(!res?.session_id)return;for(let i=0;i<n;i++)await gw.request("session.undo",{session_id:res.session_id}).catch(()=>{});await switchSession(res.session_id),composer2.current?.set(text2),setFocusRegion("input"),toast.show({variant:"success",message:`forked \u2192 ${res.title??res.session_id}`})},[turn.streaming,turn.messages,gw,toast,switchSession]),msgMenu=import_react110.useCallback((m2)=>{if(turn.streaming)return;openMessage(dialog,m2,{rewind,fork})},[turn.streaming,dialog,rewind,fork]),attachClipboard=import_react110.useCallback(()=>{gw.request("clipboard.paste").then((r)=>r.attached?setAttachments((a)=>[...a,r]):toast.show({variant:"info",message:r.message??"No image in clipboard"})).catch((e)=>toast.show({variant:"error",message:e.message}))},[gw,toast]),sendRef=import_react110.useRef(()=>{}),slash=import_react110.useCallback((c,arg="")=>{if(c.target==="local")switch(c.name){case"clear":dispatch({kind:"reset"});return;case"new":newSession();return;case"theme":openThemePicker(dialog,themeCtx);return;case"help":dialog.replace($jsx(HelpDialog,{}));return;case"keys":openKeys(dialog);return;case"logs":openLogs(dialog);return;case"eikon":pickEikon();return;case"title":arg?applyTitle(arg):editTitle();return;case"rollback":openRollback(dialog,gw,toast);return;case"history":openHistory(dialog,gw);return;case"status":openStatus(dialog,info2,sid);return;case"usage":openUsage(dialog,gw);return;case"profile":openProfile(dialog);return;case"chafa":if(!arg.trim()){toast.show({variant:"info",message:"usage: /chafa <path>"});return}openChafa(dialog,arg.trim());return;case"splash":summoned.current=!0,setSplash(!0);return;case"skin":{let name=arg.trim();if(!name){dispatch({kind:"system",text:`skin: ${skin.skin?.name??"\u2014"}
4147
- ${SKINS.join(" ")}`});return}if(!SKINS.includes(name)){toast.show({variant:"error",message:`unknown skin: ${name}`});return}gw.request("config.set",{key:"skin",value:name}).then((r)=>{if(r.warning)toast.show({variant:"warning",message:r.warning});if(themeCtx.has(name))themeCtx.set(name);set("eikonPath",void 0),dispatch({kind:"system",text:`skin \u2192 ${name}`})}).catch((e)=>toast.show({variant:"error",message:e.message}));return}case"goal":{goalHook.cmd(arg).then((r)=>{if(dispatch({kind:"system",text:r.line}),r.kick)sendRef.current(r.kick)}).catch((e)=>toast.show({variant:"error",message:e.message}));return}case"resume":if(arg){switchSession(arg);return}goToTab(TAB_SLASH.sessions);return;case"branch":session.branch(arg||void 0).then((id)=>id?void switchSession(id):toast.show({variant:"error",message:"branch failed"}));return;case"compress":runCompress();return;case"undo":session.undo().then(()=>gw.request("session.history").then((r)=>dispatch({kind:"load",messages:transcriptToMessages(r.messages??[])})).catch(()=>{}));return;case"retry":{let last3=[...turn.messages].reverse().find((m2)=>m2.role==="user");if(!last3){toast.show({variant:"info",message:"nothing to retry"});return}rewind(last3).then(()=>sendRef.current(text(last3)));return}case"model":if(!arg){openModelPicker(dialog,gw);return}gw.request("config.set",{key:"model",value:arg}).then((r)=>{if(r.warning)toast.show({variant:"warning",message:r.warning});dispatch({kind:"system",text:`model \u2192 ${r.value??arg}`})}).catch((e)=>toast.show({variant:"error",message:e.message}));return;case"quit":quit(renderer,sid,title);return;case"queue":if(!arg){dispatch({kind:"system",text:`${queue.length} queued`});return}setQueue((q4)=>[...q4,arg]);return;case"copy":{let all=turn.messages.filter((m3)=>m3.role==="assistant"),n=arg?Math.min(Math.max(1,parseInt(arg,10)||0),all.length):all.length,m2=all[n-1];if(!m2){toast.show({variant:"info",message:"nothing to copy"});return}let body2=text(m2);copy(body2),toast.show({variant:"success",message:`copied ${body2.length} chars`});return}case"paste":attachClipboard();return;case"image":if(!arg){toast.show({variant:"info",message:"usage: /image <path>"});return}gw.request("image.attach",{path:arg}).then((r)=>r.attached?setAttachments((a)=>[...a,r]):toast.show({variant:"warning",message:r.message??"attach failed"})).catch((e)=>toast.show({variant:"error",message:e.message}));return;case"background":if(!arg){toast.show({variant:"info",message:"usage: /background <prompt>"});return}gw.request("prompt.background",{text:arg}).then((r)=>toast.show(r.task_id?{variant:"success",message:`background ${r.task_id} started`}:{variant:"error",message:"background start failed"})).catch((e)=>toast.show({variant:"error",message:e.message}));return;case"voice":gw.request("voice.toggle",{action:(arg||"status").toLowerCase()}).then((r)=>dispatch({kind:"system",text:`voice ${r.enabled?"on":"off"}${r.tts?" \xB7 tts on":""}`})).catch((e)=>toast.show({variant:"error",message:e.message}));return;case"mouse":{let want=arg==="on"?!0:arg==="off"?!1:!renderer.useMouse;renderer.useMouse=want,set("mouse",want),toast.show({variant:"info",message:`mouse ${want?"on":"off"}`});return}case"redraw":redraw(renderer);return;case"compact":case"setup":dispatch({kind:"system",text:`/${c.name} is an Ink-TUI command and has no effect in herm`});return;case"steer":{let fire=(text2)=>gw.request("session.steer",{text:text2}).then((r)=>toast.show(r.accepted?{variant:"success",message:"Queued \u2014 lands on next tool result"}:{variant:"info",message:"No turn running; send as a normal message"})).catch((e)=>toast.show({variant:"error",message:e.message}));if(arg){fire(arg);return}openTextPrompt(dialog,{title:"Steer",label:"Note to inject on next tool result"}).then((text2)=>{if(text2)fire(text2)});return}case"reload-mcp":{let a=arg.trim().toLowerCase(),skip=a==="now"||a==="once"||a==="approve"||a==="yes"||a==="always",fire=(always)=>gw.request("reload.mcp",{confirm:!0,always}).then((r)=>r.status==="confirm_required"?toast.show({variant:"warning",message:r.message??"reload requires confirmation"}):toast.show({variant:"success",message:always?"MCP servers reloaded \xB7 future /reload-mcp runs silently":"MCP servers reloaded"})).catch((e)=>toast.show({variant:"error",message:e.message}));if(skip){fire(a==="always");return}openConfirm(dialog,{title:"Reload MCP servers?",body:"Rebuilds the MCP tool set. Invalidates the prompt cache, so the next message re-sends full input tokens.",yes:"reload",danger:!0}).then((ok)=>{if(ok)fire(!1)});return}case"reload":gw.request("reload.env",{}).then((r)=>{let n=Number(r.updated??0);toast.show({variant:"success",message:`Reloaded .env (${n} var${n===1?"":"s"} updated) \xB7 /new to apply`})}).catch((e)=>toast.show({variant:"error",message:e.message}));return;case"save":gw.request("session.save").then((r)=>toast.show({variant:"success",message:`Saved \u2192 ${r.file}`})).catch((e)=>toast.show({variant:"error",message:e.message}));return}if(c.target!=="gateway"||!ready)return;let jump=TAB_SLASH[c.name];if(jump!==void 0&&!arg){goToTab(jump);return}let full=`/${c.name}${arg?" "+arg:""}`;if(turn.streaming){setQueue((q4)=>[...q4,full]);return}dispatch({kind:"user",text:full}),gw.request("slash.exec",{command:full}).then((res)=>{if(res?.warning)dispatch({kind:"system",text:`\u26A0 ${res.warning}`});if(res?.output)dispatch({kind:"system",text:res.output})}).catch(()=>{gw.request("command.dispatch",{name:c.name,arg}).then((d2)=>{if(d2.type==="exec"||d2.type==="plugin")return dispatch({kind:"system",text:d2.output||"(no output)"});if(d2.type==="alias"&&d2.target)return void sendRef.current(`/${d2.target}${arg?" "+arg:""}`);if((d2.type==="skill"||d2.type==="send")&&d2.message){if(d2.type==="skill")dispatch({kind:"system",text:`\u26A1 loading skill: ${d2.name??c.name}`});return void sendRef.current(d2.message)}dispatch({kind:"system",text:`/${c.name}: unknown`})}).catch((e)=>dispatch({kind:"system",text:`error: ${e.message}`}))})},[ready,turn.streaming,turn.messages,dialog,themeCtx,newSession,gw,pickEikon,editTitle,applyTitle,toast,info2,sid,title,switchSession,session,runCompress,rewind,renderer,attachClipboard,goToTab,queue.length,goalHook,skin]),send=import_react110.useCallback(async(raw)=>{let m2=raw.match(/^\/(\S+)(?:\s+([\s\S]*))?$/);if(m2){let[,name,arg=""]=m2,r=resolve7(cmdsRef.current,name);if("hit"in r)return slash(r.hit,arg.trim());if("ambiguous"in r){let head=r.ambiguous.slice(0,6).join(", ");return dispatch({kind:"system",text:`ambiguous: /${name} \u2192 ${head}${r.ambiguous.length>6?", \u2026":""}`})}}let text2=raw;if(hasInterp(raw))setStatus("interpolating\u2026"),text2=await interpolate(gw,raw),setStatus("");interrupted.current=!1;let withMedia=attachments.length?[...attachments.flatMap((a)=>a.path?[`MEDIA:${a.path}`]:[]),text2].filter(Boolean).join(`
4147
+ ${SKINS.join(" ")}`});return}if(!SKINS.includes(name)){toast.show({variant:"error",message:`unknown skin: ${name}`});return}gw.request("config.set",{key:"skin",value:name}).then((r)=>{if(r.warning)toast.show({variant:"warning",message:r.warning});if(themeCtx.has(name))themeCtx.set(name);set("eikonPath",void 0),dispatch({kind:"system",text:`skin \u2192 ${name}`})}).catch((e)=>toast.show({variant:"error",message:e.message}));return}case"resume":if(arg){switchSession(arg);return}goToTab(TAB_SLASH.sessions);return;case"branch":session.branch(arg||void 0).then((id)=>id?void switchSession(id):toast.show({variant:"error",message:"branch failed"}));return;case"compress":runCompress();return;case"undo":session.undo().then(()=>gw.request("session.history").then((r)=>dispatch({kind:"load",messages:transcriptToMessages(r.messages??[])})).catch(()=>{}));return;case"retry":{let last3=[...turn.messages].reverse().find((m2)=>m2.role==="user");if(!last3){toast.show({variant:"info",message:"nothing to retry"});return}rewind(last3).then(()=>sendRef.current(text(last3)));return}case"model":if(!arg){openModelPicker(dialog,gw);return}gw.request("config.set",{key:"model",value:arg}).then((r)=>{if(r.warning)toast.show({variant:"warning",message:r.warning});dispatch({kind:"system",text:`model \u2192 ${r.value??arg}`})}).catch((e)=>toast.show({variant:"error",message:e.message}));return;case"quit":quit(renderer,sid,title);return;case"queue":if(!arg){dispatch({kind:"system",text:`${queue.length} queued`});return}setQueue((q4)=>[...q4,arg]);return;case"copy":{let all=turn.messages.filter((m3)=>m3.role==="assistant"),n=arg?Math.min(Math.max(1,parseInt(arg,10)||0),all.length):all.length,m2=all[n-1];if(!m2){toast.show({variant:"info",message:"nothing to copy"});return}let body2=text(m2);copy(body2),toast.show({variant:"success",message:`copied ${body2.length} chars`});return}case"paste":attachClipboard();return;case"image":if(!arg){toast.show({variant:"info",message:"usage: /image <path>"});return}gw.request("image.attach",{path:arg}).then((r)=>r.attached?setAttachments((a)=>[...a,r]):toast.show({variant:"warning",message:r.message??"attach failed"})).catch((e)=>toast.show({variant:"error",message:e.message}));return;case"background":if(!arg){toast.show({variant:"info",message:"usage: /background <prompt>"});return}gw.request("prompt.background",{text:arg}).then((r)=>toast.show(r.task_id?{variant:"success",message:`background ${r.task_id} started`}:{variant:"error",message:"background start failed"})).catch((e)=>toast.show({variant:"error",message:e.message}));return;case"voice":gw.request("voice.toggle",{action:(arg||"status").toLowerCase()}).then((r)=>dispatch({kind:"system",text:`voice ${r.enabled?"on":"off"}${r.tts?" \xB7 tts on":""}`})).catch((e)=>toast.show({variant:"error",message:e.message}));return;case"mouse":{let want=arg==="on"?!0:arg==="off"?!1:!renderer.useMouse;renderer.useMouse=want,set("mouse",want),toast.show({variant:"info",message:`mouse ${want?"on":"off"}`});return}case"redraw":redraw(renderer);return;case"compact":case"setup":dispatch({kind:"system",text:`/${c.name} is an Ink-TUI command and has no effect in herm`});return;case"steer":{let fire=(text2)=>gw.request("session.steer",{text:text2}).then((r)=>toast.show(r.accepted?{variant:"success",message:"Queued \u2014 lands on next tool result"}:{variant:"info",message:"No turn running; send as a normal message"})).catch((e)=>toast.show({variant:"error",message:e.message}));if(arg){fire(arg);return}openTextPrompt(dialog,{title:"Steer",label:"Note to inject on next tool result"}).then((text2)=>{if(text2)fire(text2)});return}case"reload-mcp":{let a=arg.trim().toLowerCase(),skip=a==="now"||a==="once"||a==="approve"||a==="yes"||a==="always",fire=(always)=>gw.request("reload.mcp",{confirm:!0,always}).then((r)=>r.status==="confirm_required"?toast.show({variant:"warning",message:r.message??"reload requires confirmation"}):toast.show({variant:"success",message:always?"MCP servers reloaded \xB7 future /reload-mcp runs silently":"MCP servers reloaded"})).catch((e)=>toast.show({variant:"error",message:e.message}));if(skip){fire(a==="always");return}openConfirm(dialog,{title:"Reload MCP servers?",body:"Rebuilds the MCP tool set. Invalidates the prompt cache, so the next message re-sends full input tokens.",yes:"reload",danger:!0}).then((ok)=>{if(ok)fire(!1)});return}case"reload":gw.request("reload.env",{}).then((r)=>{let n=Number(r.updated??0);toast.show({variant:"success",message:`Reloaded .env (${n} var${n===1?"":"s"} updated) \xB7 /new to apply`})}).catch((e)=>toast.show({variant:"error",message:e.message}));return;case"save":gw.request("session.save").then((r)=>toast.show({variant:"success",message:`Saved \u2192 ${r.file}`})).catch((e)=>toast.show({variant:"error",message:e.message}));return}if(c.target!=="gateway"||!ready)return;let jump=TAB_SLASH[c.name];if(jump!==void 0&&!arg){goToTab(jump);return}let full=`/${c.name}${arg?" "+arg:""}`;if(turn.streaming){setQueue((q4)=>[...q4,full]);return}dispatch({kind:"user",text:full}),gw.request("slash.exec",{command:full}).then((res)=>{if(res?.warning)dispatch({kind:"system",text:`\u26A0 ${res.warning}`});if(res?.output)dispatch({kind:"system",text:res.output})}).catch(()=>{gw.request("command.dispatch",{name:c.name,arg}).then((d2)=>{if(d2.notice)dispatch({kind:"system",text:d2.notice});if(d2.type==="exec"||d2.type==="plugin")return dispatch({kind:"system",text:d2.output||"(no output)"});if(d2.type==="alias"&&d2.target)return void sendRef.current(`/${d2.target}${arg?" "+arg:""}`);if((d2.type==="skill"||d2.type==="send")&&d2.message){if(d2.type==="skill")dispatch({kind:"system",text:`\u26A1 loading skill: ${d2.name??c.name}`});return void sendRef.current(d2.message)}dispatch({kind:"system",text:`/${c.name}: unknown`})}).catch((e)=>dispatch({kind:"system",text:`error: ${e.message}`}))})},[ready,turn.streaming,turn.messages,dialog,themeCtx,newSession,gw,pickEikon,editTitle,applyTitle,toast,info2,sid,title,switchSession,session,runCompress,rewind,renderer,attachClipboard,goToTab,queue.length,goalHook,skin]),send=import_react110.useCallback(async(raw)=>{let m2=raw.match(/^\/(\S+)(?:\s+([\s\S]*))?$/);if(m2){let[,name,arg=""]=m2,r=resolve7(cmdsRef.current,name);if("hit"in r)return slash(r.hit,arg.trim());if("ambiguous"in r){let head=r.ambiguous.slice(0,6).join(", ");return dispatch({kind:"system",text:`ambiguous: /${name} \u2192 ${head}${r.ambiguous.length>6?", \u2026":""}`})}}let text2=raw;if(hasInterp(raw))setStatus("interpolating\u2026"),text2=await interpolate(gw,raw),setStatus("");interrupted.current=!1;let withMedia=attachments.length?[...attachments.flatMap((a)=>a.path?[`MEDIA:${a.path}`]:[]),text2].filter(Boolean).join(`
4148
4148
  `):text2;dispatch({kind:"user",text:withMedia}),setAttachments([]),gw.request("prompt.submit",{text:text2}).catch(()=>{inflight.current=!1}),setTab(CHAT_TAB)},[gw,slash,attachments]);sendRef.current=send;let onSend=import_react110.useCallback((raw)=>{return setSplash(!1),send(raw)},[send]),onEmptyEnter=import_react110.useCallback(()=>{if(!splash||summoned.current||!splashLast||composing)return!1;return setSplash(!1),switchSession(splashLast.id),!0},[splash,splashLast,composing,switchSession]);import_react110.useEffect(()=>{if(turn.streaming)inflight.current=!1},[turn.streaming]),import_react110.useEffect(()=>{if(turn.streaming||inflight.current||!ready||queue.length===0)return;let[head,...rest]=queue;inflight.current=!0,setQueue(rest),send(head)},[turn.streaming,ready,queue,send]);let dequeue=import_react110.useCallback((i)=>{let item=queue[i];if(item===void 0)return;setQueue((q4)=>q4.filter((_2,j2)=>j2!==i)),composer2.current?.set(item),setFocusRegion("input")},[queue]),copyLast=import_react110.useCallback(()=>{for(let i=turn.messages.length-1;i>=0;i--){let m2=turn.messages[i];if(m2.role!=="assistant")continue;let text2=m2.parts.filter((p)=>p.type==="text").map((p)=>p.content).join("");if(!text2)continue;return process.stdout.write(`\x1B]52;c;${Buffer.from(text2).toString("base64")}\x07`),!0}return!1},[turn.messages]),deltas=import_react110.useRef({text:"",think:"",timer:null}),flush2=import_react110.useCallback(()=>{let d2=deltas.current;if(d2.timer)clearTimeout(d2.timer),d2.timer=null;if(d2.think)dispatch({kind:"thinking",text:d2.think,final:!1}),d2.think="";if(d2.text)dispatch({kind:"message.delta",chunk:d2.text}),d2.text=""},[]),STREAM_EVENTS=import_react110.useRef(new Set(["message.start","message.delta","reasoning.delta","reasoning.available","thinking.delta","tool.start","tool.progress","tool.generating"])).current,handle2=import_react110.useCallback((ev)=>{if(interrupted.current){if(STREAM_EVENTS.has(ev.type))return;if(ev.type==="status.update"&&ev.payload?.kind==="lifecycle")return}let action=mapEvent(ev,{onReady:()=>{session.boot(launchRef.current).then((r)=>{if(setSid(r.id),sessionStart.current=Date.now(),r.messages.length)dispatch({kind:"load",messages:r.messages});if(r.note)toast.show({variant:"info",message:r.note})})},onSessionInfo:(si)=>{if(setInfo(si),setReady(!0),si.session_id)setSid(si.session_id);let bad=(si.mcp_servers??[]).filter((s)=>!s.connected);if(bad.length)dispatch({kind:"system",text:`MCP: ${bad.length} server(s) failed to connect \u2014 ${bad.map((s)=>s.name+(s.error?` (${s.error})`:"")).join(", ")}`});gw.request("session.title").then((r)=>{if(setTitle(r.title??""),r.session_key)set("lastSessionId",r.session_key)}).catch(()=>{})},onUsage:(u3)=>setUsage(u3),onTurnComplete:()=>{setStatus(""),flush(gw,sidRef.current),goalHook.check(sidRef.current)},onBackground:(tid,text2)=>{let head=text2.split(`
4149
4149
  `)[0].slice(0,80);dispatch({kind:"system",text:`\u25F7 background task ${tid} complete \u2014 ${head}`}),toast.show({variant:"info",title:"Background task complete",message:head,duration:8000,action:{label:"view",run:()=>openAlert(dialog,`Background task ${tid}`,text2)}})},onBtw:(text2)=>{let head=text2.split(`
4150
4150
  `)[0].slice(0,80);dispatch({kind:"system",text:`\u25C8 btw \u2014 ${head}`}),toast.show({variant:"info",title:"btw",message:head,duration:8000,action:{label:"view",run:()=>openAlert(dialog,"btw",text2)}})},onStatus:(text2)=>setStatus(text2),onSkin:(s)=>setSkin(deriveSkin(s))});if(!action)return;let d2=deltas.current;if(action.kind==="message.delta"){if(d2.think)flush2();d2.text+=action.chunk,d2.timer??=setTimeout(flush2,16);return}if(action.kind==="thinking"&&!action.final){if(d2.text)flush2();d2.think+=action.text,d2.timer??=setTimeout(flush2,16);return}if(flush2(),action.kind==="error")setErrorPulse(!0);dispatch(action)},[session,dialog,toast,gw,flush2,goalHook]);useGatewayEvent(handle2),import_react110.useEffect(()=>cmd.register([{title:"Help",value:"help",action:"help.open",category:"General",onSelect:()=>dialog.replace($jsx(HelpDialog,{}))},{title:"Keybindings",value:"keys",description:"View & rebind shortcuts",category:"General",onSelect:()=>openKeys(dialog)},{title:"Gateway Logs",value:"logs",description:"Show gateway stderr",category:"General",onSelect:()=>openLogs(dialog)},{title:"Switch Theme",value:"theme",action:"theme.pick",category:"General",onSelect:()=>openThemePicker(dialog,themeCtx)},{title:"Switch Model",value:"model",action:"model.pick",category:"General",onSelect:()=>openModelPicker(dialog,gw)},{title:"Pick Avatar",value:"eikon",description:"Choose sidebar .eikon avatar",category:"General",onSelect:()=>pickEikon()},{title:"Rollback",value:"rollback",description:"Browse & restore checkpoints",category:"Session",onSelect:()=>openRollback(dialog,gw,toast)},{title:"History",value:"history",action:"session.timeline",category:"Session",onSelect:()=>openHistory(dialog,gw)},{title:"Status",value:"status",action:"status.open",category:"Info",onSelect:()=>openStatus(dialog,info2,sid)},{title:"Usage",value:"usage",description:"Tokens \xB7 context \xB7 cost",category:"Info",onSelect:()=>openUsage(dialog,gw)},{title:"Profile",value:"profile",description:"Active profile details",category:"Info",onSelect:()=>openProfile(dialog)},{title:"New Session",value:"new-session",action:"session.new",category:"Session",onSelect:()=>newSession()},{title:"Compress Session",value:"compress",action:"session.compress",category:"Session",onSelect:()=>runCompress()},{title:"Undo Last Turn",value:"undo",description:"Pop last user+assistant pair",category:"Session",onSelect:()=>session.undo()},{title:"Branch Session",value:"branch",description:"Fork the current conversation",category:"Session",onSelect:()=>session.branch()}]),[cmd,dialog,themeCtx,session,gw,toast,newSession,pickEikon,info2,sid,runCompress]);let doInterrupt=import_react110.useCallback(()=>{interrupted.current=!0;let d2=deltas.current;if(d2.timer)clearTimeout(d2.timer),d2.timer=null;d2.text="",d2.think="",session.interrupt()},[session]);useAppKeys({tab,tabMax:TAB_MAX,chatTab:CHAT_TAB,setTab,focusRegion,setFocusRegion,streaming:turn.streaming,dialogOpen:dialog.open,composer:composer2,onPromptKey:(k2)=>promptRef.current?.feed(k2)??!1,onEscape:()=>{if(!splash||!summoned.current)return!1;return setSplash(!1),summoned.current=!1,!0},onInterrupt:doInterrupt,queued:queue.length,onFlushQueue:doInterrupt,onQuit:()=>quit(renderer,sid,title),onInterruptNotice:()=>dispatch({kind:"interrupt.notice",text:"Press Escape again to interrupt"}),onCopyLast:()=>{copyLast()},onAttachClipboard:attachClipboard,onDetachLast:()=>{if(attachments.length===0)return!1;return setAttachments((a)=>a.slice(0,-1)),!0},onNotice:(text2)=>dispatch({kind:"system",text:text2}),onToggleSidebar:()=>setHideSidebar((v2)=>!v2)});let state2=import_react110.useRef({tab,ready,streaming:turn.streaming,messages:turn.messages,sid,focusRegion});state2.current={tab,ready,streaming:turn.streaming,messages:turn.messages,sid,focusRegion},import_react110.useEffect(()=>{if(!enabled2)return;setBridge({tab:()=>state2.current.tab,setTab,send:(msg)=>{if(!state2.current.ready||state2.current.streaming)return;dispatch({kind:"user",text:msg}),gw.request("prompt.submit",{text:msg}).catch(()=>{}),setTab(CHAT_TAB)},ready:()=>state2.current.ready,streaming:()=>state2.current.streaming,messages:()=>state2.current.messages.length,session:()=>state2.current.sid,input:()=>composer2.current?.value()??"",setInput:(v2)=>composer2.current?.set(v2),focusRegion:()=>state2.current.focusRegion,setFocusRegion,renderer:()=>renderer,logs:(n)=>gw.tail(n)})},[gw,renderer]);let contentFocused=focusRegion==="content"&&!turn.streaming,promptAnswer=import_react110.useCallback((id,label,ok)=>dispatch({kind:"prompt.answered",id,label,ok}),[]),promptWire=import_react110.useMemo(()=>({ref:promptRef,onAnswer:promptAnswer}),[promptAnswer]);import_react110.useEffect(()=>{if(prompt&&tab!==CHAT_TAB)setTab(CHAT_TAB)},[prompt?.id]);let content=()=>{let inner=(()=>{switch(tab){case 0:return $jsx(Chat,{messages:turn.messages,streaming:turn.streaming,prompt:promptWire,cloud,cloudH,pick,onResize:setCloudH,onPick,onClose:closeCloud,onRewind:msgMenu});case 1:return $jsx(Context,{description:TABS[tab].description,messages:turn.messages,sessionStart:sessionStart.current,info:info2??void 0,focused:contentFocused});case 2:return $jsx(Sessions,{onSwitch:switchSession,currentId:sid,focused:contentFocused});case 3:return $jsx(Agents,{focused:contentFocused,sessionId:sid,onSwitchProfile:switchProfile});case 4:return $jsx(Analytics,{focused:contentFocused});case 5:return $jsx(Skills,{focused:contentFocused});case 6:return $jsx(Cron,{focused:contentFocused});case 7:return $jsx(Toolsets,{focused:contentFocused});case 8:return $jsx(Config,{focused:contentFocused});case 9:return $jsx(Env,{focused:contentFocused});case 10:return $jsx(Memory,{focused:contentFocused});case 11:return $jsx(Kanban,{focused:contentFocused});default:return null}})(),name=TABS[tab]?.name??"unknown";return $jsx(import_react110.Profiler,{id:`tab:${name}`,onRender,children:inner})},theme=themeCtx.theme,onMouseUp=import_react110.useCallback(()=>copySelection(renderer),[renderer]),inputFocused=focusRegion==="input"&&!prompt;return $jsx(import_react110.Profiler,{id:"shell",onRender,children:$jsx(SkinProvider,{value:skin,children:$jsxs("box",{width:"100%",height:"100%",flexDirection:"column",backgroundColor:theme.background,onMouseUp,children:[$jsx(TabBar,{tabs:TABS,activeTab:tab,onTabChange:goToTab}),$jsxs("box",{flexGrow:1,flexDirection:"row",children:[$jsxs("box",{flexGrow:1,flexDirection:"column",children:[$jsxs("box",{flexGrow:1,position:"relative",children:[content(),splash&&tab===CHAT_TAB?$jsx(Splash,{info:info2?{agentVersion:info2.version,behind:info2.update_behind,model:info2.model}:void 0,last:summoned.current?void 0:splashLast?{id:splashLast.id,title:splashLast.title}:void 0,composing,news,loading:switching||!info2}):null]}),$jsx("box",{flexShrink:0,zIndex:1,children:$jsx(Composer,{ref:composer2,focused:inputFocused,ready,streaming:turn.streaming,status,queue,attachments,cmds,onSend,onSlash:slash,onAttach,onEnqueue,onDequeue:dequeue,onDirty:setComposing,onEmptyEnter})})]}),dims.width>=(tab===CHAT_TAB?120:140)&&!hideSidebar?$jsx(import_react110.Profiler,{id:"sidebar",onRender,children:$jsx(Sidebar,{agentState,info:info2,usage,eikon,profile:activeProfileName(),title,cloud:tab===0&&cloud,pulse:turn.streaming,onAvatar,onAvatarHold})}):null]})]})})})};init_perf();import{writeSync as writeSync2}from"fs";var TERMINAL_MODE_RESET="\x1B[0'z\x1B[0'{\x1B[?2029l\x1B[?1016l\x1B[?1015l\x1B[?1006l\x1B[?1005l\x1B[?1003l\x1B[?1002l\x1B[?1001l\x1B[?1000l\x1B[?9l\x1B[?1004l\x1B[?2004l\x1B[?1049l\x1B[<u\x1B[>4;0m\x1B[0m\x1B[?25h";function resetTerminalModes(stream=process.stdout){if(!stream.isTTY)return!1;let fd=typeof stream.fd==="number"?stream.fd:stream===process.stdout?1:void 0;if(fd!==void 0)try{return writeSync2(fd,TERMINAL_MODE_RESET),!0}catch{}try{return stream.write(TERMINAL_MODE_RESET),!0}catch{return!1}}var wired=!1;function installExitResetHooks(){if(wired)return;wired=!0,process.on("exit",()=>{resetTerminalModes()});let codes={SIGHUP:129,SIGINT:130,SIGTERM:143};for(let sig of["SIGINT","SIGTERM","SIGHUP"])process.on(sig,()=>{resetTerminalModes(),process.exit(codes[sig])});process.on("uncaughtException",(err)=>{resetTerminalModes(),console.error(err),process.exit(1)}),process.on("unhandledRejection",(reason)=>{resetTerminalModes(),console.error(reason),process.exit(1)})}boot("import-graph",Bun.nanoseconds()/1e6);var argv=Bun.argv.slice(2);if(argv.includes("--help")||argv.includes("-h"))process.stdout.write(HELP),process.exit(0);if(argv.includes("--version")||argv.includes("-v"))process.stdout.write(VERSION+`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "herm-tui",
3
- "version": "1.0.0-dev.10",
3
+ "version": "1.0.0-dev.11",
4
4
  "description": "A modern TUI for Hermes Agent",
5
5
  "license": "MIT",
6
6
  "repository": {