vole-agent 0.1.5 → 0.1.7

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/app.js CHANGED
@@ -1,34 +1,34 @@
1
1
  #!/usr/bin/env node
2
- import{a as ie,d as $,h as le}from"./chunk-QGVGG7HC.js";import{useState as T,useEffect as ve,useCallback as I,useMemo as pe,useRef as Se}from"react";import{render as Ie,Box as a,Text as o,useInput as N,useApp as Ae,useAnimation as ke,useStdout as Re,Static as Ee}from"ink";import Me from"ink-text-input";import{readFile as _e}from"fs/promises";import{join as De}from"path";import{marked as Ve}from"marked";import{useRef as ze}from"react";import{Text as we}from"ink";import p from"chalk";import{marked as ce}from"marked";var ae=!1;function de(){ae||(ae=!0,ce.use({tokenizer:{del(){}}}))}function y(n,u=0,m=!1){switch(n.type){case"heading":{let s=(n.tokens??[]).map(i=>y(i)).join("");return n.depth===1?p.bold.underline(s)+`
2
+ import{a as le,d as W,h as ae}from"./chunk-ABKAA7HK.js";import{useState as T,useEffect as Se,useCallback as I,useMemo as fe,useRef as Ie}from"react";import{render as Ae,Box as c,Text as o,useInput as O,useApp as ke,useAnimation as Re,useStdout as Ee,Static as Me}from"ink";import _e from"ink-text-input";import{readFile as De,stat as Pe}from"fs/promises";import{dirname as je,join as U}from"path";import{marked as ze}from"marked";import{useRef as Ze}from"react";import{Text as Be}from"ink";import p from"chalk";import{marked as de}from"marked";var ce=!1;function ue(){ce||(ce=!0,de.use({tokenizer:{del(){}}}))}function y(e,l=0,d=!1){switch(e.type){case"heading":{let s=(e.tokens??[]).map(i=>y(i)).join("");return e.depth===1?p.bold.underline(s)+`
3
3
 
4
- `:n.depth===2?p.bold(s)+`
4
+ `:e.depth===2?p.bold(s)+`
5
5
 
6
6
  `:p.bold(p.dim(s))+`
7
7
 
8
- `}case"paragraph":return(n.tokens??[]).map(i=>y(i)).join("")+`
8
+ `}case"paragraph":return(e.tokens??[]).map(i=>y(i)).join("")+`
9
9
 
10
- `;case"strong":{let s=(n.tokens??[]).map(i=>y(i)).join("");return p.bold(s)}case"em":{let s=(n.tokens??[]).map(i=>y(i)).join("");return p.italic(s)}case"del":{let s=(n.tokens??[]).map(i=>y(i)).join("");return p.strikethrough(s)}case"codespan":return p.yellow(n.text);case"code":{let i=n.text.split(`
11
- `).map(c=>" "+p.yellow(c)).join(`
12
- `);return p.dim("```"+(n.lang??""))+`
10
+ `;case"strong":{let s=(e.tokens??[]).map(i=>y(i)).join("");return p.bold(s)}case"em":{let s=(e.tokens??[]).map(i=>y(i)).join("");return p.italic(s)}case"del":{let s=(e.tokens??[]).map(i=>y(i)).join("");return p.strikethrough(s)}case"codespan":return p.yellow(e.text);case"code":{let i=e.text.split(`
11
+ `).map(u=>" "+p.yellow(u)).join(`
12
+ `);return p.dim("```"+(e.lang??""))+`
13
13
  `+i+`
14
14
  `+p.dim("```")+`
15
15
 
16
- `}case"blockquote":return(n.tokens??[]).map(i=>y(i)).join("").trim().split(`
16
+ `}case"blockquote":return(e.tokens??[]).map(i=>y(i)).join("").trim().split(`
17
17
  `).map(i=>p.dim("\u2502 ")+p.italic(i)).join(`
18
18
  `)+`
19
19
 
20
- `;case"list":return(n.items??[]).map((i,c)=>{let g=n.ordered?p.bold(`${c+1}.`)+" ":p.bold("\u2022")+" ",C=" ".repeat(u),f=(i.tokens??[]).map(b=>b.type==="list"?`
21
- `+y(b,u+1):y(b,u)).join("").trim();return C+g+f}).join(`
20
+ `;case"list":return(e.items??[]).map((i,u)=>{let g=e.ordered?p.bold(`${u+1}.`)+" ":p.bold("\u2022")+" ",C=" ".repeat(l),f=(i.tokens??[]).map(b=>b.type==="list"?`
21
+ `+y(b,l+1):y(b,l)).join("").trim();return C+g+f}).join(`
22
22
  `)+`
23
23
 
24
24
  `;case"hr":return p.dim("\u2500".repeat(40))+`
25
25
 
26
- `;case"link":{let s=(n.tokens??[]).map(i=>y(i)).join("")||n.text;return n.href&&n.href!==s?s+p.dim(` (${n.href})`):s}case"image":return p.dim(`[image: ${n.text}]`);case"html":return n.text.replace(/<[^>]+>/g,"");case"text":return(n.tokens??[]).map(i=>y(i)).join("")||n.text;case"space":return`
27
- `;case"escape":return n.text;case"table":{let s=p.dim(" | "),i=(n.header??[]).map(C=>p.bold((C.tokens??[]).map(f=>y(f)).join(""))).join(s),c=p.dim("\u2500".repeat(Math.max(i.length-s.length*((n.header?.length??1)-1),20))),g=(n.rows??[]).map(C=>C.map(f=>(f.tokens??[]).map(b=>y(b)).join("")).join(s));return[i,c,...g].join(`
26
+ `;case"link":{let s=(e.tokens??[]).map(i=>y(i)).join("")||e.text;return e.href&&e.href!==s?s+p.dim(` (${e.href})`):s}case"image":return p.dim(`[image: ${e.text}]`);case"html":return e.text.replace(/<[^>]+>/g,"");case"text":return(e.tokens??[]).map(i=>y(i)).join("")||e.text;case"space":return`
27
+ `;case"escape":return e.text;case"table":{let s=p.dim(" | "),i=(e.header??[]).map(C=>p.bold((C.tokens??[]).map(f=>y(f)).join(""))).join(s),u=p.dim("\u2500".repeat(Math.max(i.length-s.length*((e.header?.length??1)-1),20))),g=(e.rows??[]).map(C=>C.map(f=>(f.tokens??[]).map(b=>y(b)).join("")).join(s));return[i,u,...g].join(`
28
28
  `)+`
29
29
 
30
- `}default:{let s=n;return s.text??s.raw??""}}}function ue(n){return de(),ce.lexer(n).map(m=>y(m)).join("").trimEnd()}import{Fragment as en,jsx as Be,jsxs as nn}from"react/jsx-runtime";function me({children:n}){return Be(we,{children:ue(n)})}import{jsx as e,jsxs as d}from"react/jsx-runtime";var X=[{command:"/help",description:"Show available commands"},{command:"/resume",description:"Resume a previous session"},{command:"/trace",description:"Show recent trace events"},{command:"/config",description:"Show redacted configuration"},{command:"/skills",description:"List loaded skills"},{command:"/clear",description:"Clear screen and reset context"},{command:"/exit",description:"Leave chat"}],A="#d9ff33";function U({label:n}){let{frame:u}=ke({interval:80}),m=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];return d(o,{color:"yellow",children:[m[u%m.length]," ",n]})}function je({model:n,sessionId:u}){return e(a,{flexDirection:"column",marginBottom:1,gap:1,children:d(a,{flexDirection:"row",gap:3,alignItems:"flex-start",children:[d(a,{flexDirection:"column",children:[e(o,{color:A,children:" (\\_/)"}),e(o,{color:A,children:" (\u2022\u1D65\u2022)"}),e(o,{color:A,children:" /> \\"})]}),d(a,{flexDirection:"column",gap:1,children:[d(a,{flexDirection:"row",gap:1,children:[e(o,{color:A,bold:!0,children:"vole"}),e(o,{dimColor:!0,children:"\u2014 a capable coding and general-purpose agent"})]}),d(a,{flexDirection:"row",gap:2,children:[d(a,{flexDirection:"row",gap:1,children:[e(o,{dimColor:!0,children:"model"}),e(o,{children:n})]}),e(o,{dimColor:!0,children:"\xB7"}),d(a,{flexDirection:"row",gap:1,children:[e(o,{dimColor:!0,children:"session"}),e(o,{color:"blueBright",children:u.slice(-8)})]})]}),e(o,{dimColor:!0,children:"Type /help for commands \xB7 /exit to leave"})]})]})})}function Le({model:n,sessionId:u}){return d(a,{marginBottom:1,flexDirection:"row",gap:2,alignItems:"center",children:[e(o,{color:A,bold:!0,children:"vole"}),e(o,{dimColor:!0,children:"\xB7"}),e(o,{dimColor:!0,children:n}),e(o,{dimColor:!0,children:"\xB7"}),e(o,{color:"blueBright",children:u.slice(-8)}),e(o,{dimColor:!0,children:"\xB7 /help"})]})}function Pe({sessions:n,selectedIndex:u,onSelect:m,onCancel:s}){return N((i,c)=>{if(c.escape){s();return}if(c.return&&n[u]!==void 0){m(n[u]);return}}),n.length===0?d(a,{flexDirection:"column",marginBottom:1,children:[e(o,{dimColor:!0,children:"No previous sessions found."}),e(o,{dimColor:!0,children:"Esc cancel"})]}):d(a,{flexDirection:"column",marginBottom:1,children:[e(o,{dimColor:!0,bold:!0,children:"Resume session \u2191\u2193 navigate \xB7 Enter select \xB7 Esc cancel"}),n.map((i,c)=>{let g=i.title??i.id.slice(-12),C=i.updatedAt.slice(0,16).replace("T"," "),f=c===u;return d(a,{gap:2,children:[f?e(o,{color:A,bold:!0,children:" \u25B6"}):e(o,{dimColor:!0,children:" "}),e(o,{...f?{}:{dimColor:!0},children:C}),f?e(o,{color:A,children:g}):e(o,{children:g})]},i.id)})]})}function Ne({text:n}){return d(a,{marginBottom:1,flexDirection:"column",children:[e(o,{color:"green",bold:!0,children:"Assistant"}),d(a,{paddingLeft:2,children:[e(o,{children:n}),e(o,{color:"blueBright",children:"\u258A"})]})]})}function Oe({toolName:n,input:u}){let m=u!==void 0?(()=>{try{let s=JSON.stringify(u);return s.length>60?s.slice(0,57)+"\u2026":s}catch{return""}})():"";return d(a,{marginBottom:1,flexDirection:"column",children:[e(U,{label:`${n}`}),m!==""&&e(a,{paddingLeft:2,children:e(o,{dimColor:!0,children:m})})]})}function He({todos:n}){if(n.length===0)return null;let u=n.filter(m=>m.status==="completed").length;return d(a,{flexDirection:"column",marginBottom:1,borderStyle:"single",borderColor:"gray",paddingX:1,children:[e(o,{dimColor:!0,bold:!0,children:`Todo ${u}/${n.length}`}),n.map((m,s)=>{let i=m.status==="completed"?"\u2713":m.status==="in_progress"?"\u203A":"\xB7",c=m.status==="completed"?"green":m.status==="in_progress"?"yellow":void 0;return d(a,{children:[c!==void 0?d(o,{color:c,children:[i," "]}):d(o,{children:[i," "]}),e(o,{dimColor:m.status==="completed",children:m.content})]},s)})]})}function $e({request:n,onApprove:u,onDeny:m}){N(c=>{c==="y"||c==="Y"?u():m()});let s=(()=>{try{let c=JSON.stringify(n.call.input,null,2),g=c.split(`
30
+ `}default:{let s=e;return s.text??s.raw??""}}}function me(e){return ue(),de.lexer(e).map(d=>y(d)).join("").trimEnd()}import{Fragment as on,jsx as ve,jsxs as rn}from"react/jsx-runtime";function pe({children:e}){return ve(Be,{children:me(e)})}import{jsx as n,jsxs as m}from"react/jsx-runtime";var X=[{command:"/help",description:"Show available commands"},{command:"/resume",description:"Resume a previous session"},{command:"/trace",description:"Show recent trace events"},{command:"/config",description:"Show redacted configuration"},{command:"/skills",description:"List loaded skills"},{command:"/clear",description:"Clear screen and reset context"},{command:"/exit",description:"Leave chat"}],A="#d9ff33";function z({label:e}){let{frame:l}=Re({interval:80}),d=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];return m(o,{color:"yellow",children:[d[l%d.length]," ",e]})}function Le({model:e,sessionId:l}){return n(c,{flexDirection:"column",marginBottom:1,gap:1,children:m(c,{flexDirection:"row",gap:3,alignItems:"flex-start",children:[m(c,{flexDirection:"column",children:[n(o,{color:A,children:" (\\_/)"}),n(o,{color:A,children:" (\u2022\u1D65\u2022)"}),n(o,{color:A,children:" /> \\"})]}),m(c,{flexDirection:"column",gap:1,children:[m(c,{flexDirection:"row",gap:1,children:[n(o,{color:A,bold:!0,children:"vole"}),n(o,{dimColor:!0,children:"\u2014 a capable coding and general-purpose agent"})]}),m(c,{flexDirection:"row",gap:2,children:[m(c,{flexDirection:"row",gap:1,children:[n(o,{dimColor:!0,children:"model"}),n(o,{children:e})]}),n(o,{dimColor:!0,children:"\xB7"}),m(c,{flexDirection:"row",gap:1,children:[n(o,{dimColor:!0,children:"session"}),n(o,{color:"blueBright",children:l.slice(-8)})]})]}),n(o,{dimColor:!0,children:"Type /help for commands \xB7 /exit to leave"})]})]})})}function Ne({model:e,sessionId:l}){return m(c,{marginBottom:1,flexDirection:"row",gap:2,alignItems:"center",children:[n(o,{color:A,bold:!0,children:"vole"}),n(o,{dimColor:!0,children:"\xB7"}),n(o,{dimColor:!0,children:e}),n(o,{dimColor:!0,children:"\xB7"}),n(o,{color:"blueBright",children:l.slice(-8)}),n(o,{dimColor:!0,children:"\xB7 /help"})]})}function Oe({sessions:e,selectedIndex:l,onSelect:d,onCancel:s}){return O((i,u)=>{if(u.escape){s();return}if(u.return&&e[l]!==void 0){d(e[l]);return}}),e.length===0?m(c,{flexDirection:"column",marginBottom:1,children:[n(o,{dimColor:!0,children:"No previous sessions found."}),n(o,{dimColor:!0,children:"Esc cancel"})]}):m(c,{flexDirection:"column",marginBottom:1,children:[n(o,{dimColor:!0,bold:!0,children:"Resume session \u2191\u2193 navigate \xB7 Enter select \xB7 Esc cancel"}),e.map((i,u)=>{let g=i.title??i.id.slice(-12),C=i.updatedAt.slice(0,16).replace("T"," "),f=u===l;return m(c,{gap:2,children:[f?n(o,{color:A,bold:!0,children:" \u25B6"}):n(o,{dimColor:!0,children:" "}),n(o,{...f?{}:{dimColor:!0},children:C}),f?n(o,{color:A,children:g}):n(o,{children:g})]},i.id)})]})}function He({text:e}){return m(c,{marginBottom:1,flexDirection:"column",children:[n(o,{color:"green",bold:!0,children:"Assistant"}),m(c,{paddingLeft:2,children:[n(o,{children:e}),n(o,{color:"blueBright",children:"\u258A"})]})]})}function $e({toolName:e,input:l}){let d=l!==void 0?(()=>{try{let s=JSON.stringify(l);return s.length>60?s.slice(0,57)+"\u2026":s}catch{return""}})():"";return m(c,{marginBottom:1,flexDirection:"column",children:[n(z,{label:`${e}`}),d!==""&&n(c,{paddingLeft:2,children:n(o,{dimColor:!0,children:d})})]})}function We({todos:e}){if(e.length===0)return null;let l=e.filter(d=>d.status==="completed").length;return m(c,{flexDirection:"column",marginBottom:1,borderStyle:"single",borderColor:"gray",paddingX:1,children:[n(o,{dimColor:!0,bold:!0,children:`Todo ${l}/${e.length}`}),e.map((d,s)=>{let i=d.status==="completed"?"\u2713":d.status==="in_progress"?"\u203A":"\xB7",u=d.status==="completed"?"green":d.status==="in_progress"?"yellow":void 0;return m(c,{children:[u!==void 0?m(o,{color:u,children:[i," "]}):m(o,{children:[i," "]}),n(o,{dimColor:d.status==="completed",children:d.content})]},s)})]})}function qe({request:e,onApprove:l,onDeny:d}){O(u=>{u==="y"||u==="Y"?l():d()});let s=(()=>{try{let u=JSON.stringify(e.call.input,null,2),g=u.split(`
31
31
  `);return g.length>6?g.slice(0,6).join(`
32
32
  `)+`
33
- \u2026`:c}catch{return""}})(),i=n.decision.risk==="high"?"red":n.decision.risk==="medium"?"yellow":"green";return d(a,{flexDirection:"column",borderStyle:"round",borderColor:"yellow",paddingX:1,marginBottom:1,children:[e(o,{bold:!0,color:"yellow",children:"\u26A0 Approval Required"}),d(a,{gap:1,children:[e(o,{dimColor:!0,children:"Tool:"}),e(o,{bold:!0,children:n.call.name}),e(o,{dimColor:!0,children:"\xB7"}),e(o,{dimColor:!0,children:"Risk:"}),e(o,{color:i,bold:!0,children:n.decision.risk})]}),s!==""&&d(a,{flexDirection:"column",marginTop:1,marginBottom:1,children:[e(o,{dimColor:!0,children:"Input:"}),e(a,{paddingLeft:2,children:e(o,{dimColor:!0,children:s})})]}),e(o,{dimColor:!0,children:n.decision.reason}),e(a,{marginTop:1,children:e(o,{color:"yellow",children:" y approve any other key deny"})})]})}function We({suggestions:n,selectedIndex:u}){return n.length===0?null:d(a,{flexDirection:"column",marginBottom:1,paddingLeft:2,children:[n.map((m,s)=>d(a,{gap:2,children:[s===u?e(o,{color:"cyan",bold:!0,children:m.command}):e(o,{dimColor:!0,children:m.command}),e(o,{dimColor:!0,children:m.description})]},m.command)),e(o,{dimColor:!0,children:"Tab \xB7 complete \u2191\u2193 \xB7 select"})]})}function qe({config:n,cliOptions:u,sessionId:m}){let{exit:s}=Ae(),{write:i}=Re(),[c,g]=T(null),[C,f]=T(null),[b,W]=T(m),[z,v]=T([]),[k,R]=T(""),[w,G]=T(!1),[q,ge]=T([]),[j,E]=T(-1),[xe,Te]=T(""),[F,L]=T(0),[J,M]=T(""),[O,S]=T(null),[he,K]=T([]),[_,P]=T(null),[B,H]=T(null),Y=pe(()=>k.startsWith("/")?k==="/"?X:X.filter(t=>t.command.startsWith(k)&&t.command!==k):[],[k]),Q=Y.length>0,D=pe(()=>({resolve:t=>new Promise(r=>{H({request:t,resolve:l=>{H(null),r(l)}})})}),[]);ve(()=>{$.createConfigured(n,u,{approvalResolver:D,preferStreaming:!0,...m!==void 0?{sessionId:m}:{}}).then(t=>{g(t),W(t.sessionId)}).catch(t=>{f(t instanceof Error?t.message:"Failed to create session.")})},[n,u,D,m]);let Z=I(async()=>{c?.close(),g(null),v([]),M(""),S(null),K([]),H(null);try{let t=await $.createConfigured(n,u,{approvalResolver:D,preferStreaming:!0});g(t),W(t.sessionId)}catch(t){f(t instanceof Error?t.message:"Failed to reset session.")}},[c,n,u,D]),ee=I(async t=>{P(null),c?.close(),g(null),v([]),M(""),S(null),K([]),H(null);try{let r=await $.createConfigured(n,u,{approvalResolver:D,preferStreaming:!0,sessionId:t.id}),x=(await r.loadMessages()).flatMap(h=>h.role==="user"&&h.content?[{role:"user",content:h.content}]:h.role==="assistant"&&h.content?[{role:"assistant",content:h.content}]:[]);v(x),g(r),W(r.sessionId)}catch(r){f(r instanceof Error?r.message:"Failed to resume session.")}},[c,n,u,D]),ne=I(t=>{if(t.type==="token_delta")M(r=>r+t.delta);else if(t.type==="tool_started")S({name:t.toolName});else if(t.type==="tool_call_requested")S({name:t.call.name,input:t.call.input});else if(t.type==="tool_completed"){if(S(null),t.toolName==="update_todos")return;let r=le(t.result);v(l=>[...l,{role:"tool_result",toolName:t.toolName,content:r,ok:!0}])}else t.type==="tool_failed"?(S(null),v(r=>[...r,{role:"tool_result",toolName:t.toolName,content:t.error.message,ok:!1}])):t.type==="todos_updated"?K([...t.todos]):t.type==="run_failed"&&v(r=>[...r,{role:"error",content:t.error.message}])},[]),V=Se(null),te=I(async t=>{if(c===null||w||t.trim()==="")return;let r=t.trim();if(n.secrets.apiKey===void 0){v(x=>[...x,{role:"user",content:r},{role:"error",content:'No API key configured. Add one to ~/.vole/config.json (e.g. {"apiKey": "sk-..."}) or set VOLE_API_KEY / ANTHROPIC_API_KEY / OPENROUTER_API_KEY in your shell.'}]);return}let l=new AbortController;V.current=l,v(x=>[...x,{role:"user",content:r}]),G(!0),M(""),S(null);try{let x=await c.sendMessage(r,{onEvent:ne,signal:l.signal});M(""),S(null),x.assistantText!==""&&!l.signal.aborted&&v(h=>[...h,{role:"assistant",content:x.assistantText}])}finally{V.current=null,G(!1)}},[c,w,ne]),oe=I(async t=>{if(c===null)return;if(t==="/resume"){let x=(await c.listSessions({limit:20})).filter(h=>h.id!==c.sessionId);P({sessions:x,selectedIndex:0});return}if(t==="/clear"){i("\x1B[2J\x1B[H"),Z();return}let r=await c.runSlashCommand(t);v(l=>[...l,{role:"slash_result",command:t,lines:r}])},[c,i,Z,ee]),ye=I(t=>{if(t.includes(" ")){let r=t.replace(/\t/g,""),l=r.startsWith("/")?X.filter(h=>h.command.startsWith(r)&&h.command!==r):[],x=l[F]??l[0];R(x!==void 0?x.command:r),L(0),E(-1)}else R(t),L(0),E(-1),Te(t)},[F]);N((t,r)=>{if(_!==null){r.upArrow?P(l=>l&&{...l,selectedIndex:Math.max(0,l.selectedIndex-1)}):r.downArrow&&P(l=>l&&{...l,selectedIndex:Math.min(l.sessions.length-1,l.selectedIndex+1)});return}if(r.upArrow){if(Q)L(l=>Math.max(0,l-1));else if(j<q.length-1){let l=j+1;E(l),R(q[l]??"")}}else if(r.downArrow)if(Q)L(l=>Math.min(Y.length-1,l+1));else if(j>0){let l=j-1;E(l),R(q[l]??"")}else j===0&&(E(-1),R(xe))},{isActive:!w&&B===null}),N((t,r)=>{r.escape&&(V.current?.abort(),M(""),S(null))},{isActive:w}),N((t,r)=>{r.ctrl&&t==="c"&&s()},{isActive:!0});let Ce=I(t=>{if(w||B!==null)return;let r=t.trim();if(r!==""){if(R(""),E(-1),L(0),r==="/exit"){s();return}if(r.startsWith("/")){oe(r);return}ge(l=>l[0]===r?l:[r,...l.slice(0,49)]),te(r)}},[w,B,te,s,oe]);if(C!==null)return d(a,{flexDirection:"column",padding:1,children:[e(o,{color:"red",bold:!0,children:"Error"}),e(o,{children:C})]});if(c===null)return e(a,{padding:1,children:e(U,{label:"Starting Vole\u2026"})});let re=b??"\u2026",se=`${n.model.provider}/${n.model.model}`,be=z.length>0||J!==""||O!==null||w;return d(a,{flexDirection:"column",children:[be?e(Le,{model:se,sessionId:re}):e(je,{model:se,sessionId:re}),e(Ee,{items:z,children:(t,r)=>t.role==="user"?d(a,{marginBottom:1,children:[e(o,{color:"cyan",bold:!0,children:"You "}),e(o,{children:t.content})]},r):t.role==="tool_result"?d(a,{flexDirection:"column",marginBottom:1,paddingLeft:2,children:[d(a,{gap:1,children:[e(o,{color:t.ok?"green":"red",children:t.ok?"\u2713":"\u2717"}),e(o,{dimColor:!0,bold:!0,children:t.toolName})]}),e(a,{paddingLeft:2,children:d(o,{dimColor:!0,children:[t.content.slice(0,200),t.content.length>200?" \u2026":""]})})]},r):t.role==="error"?d(a,{marginBottom:1,borderStyle:"single",borderColor:"red",paddingX:1,children:[e(o,{color:"red",bold:!0,children:"\u2717 "}),e(o,{color:"red",children:t.content})]},r):t.role==="slash_result"?d(a,{flexDirection:"column",marginBottom:1,paddingLeft:2,children:[e(o,{color:"blue",dimColor:!0,children:t.command}),t.lines.map((l,x)=>e(o,{dimColor:!0,children:l},x))]},r):d(a,{flexDirection:"column",marginBottom:1,children:[e(o,{color:"green",bold:!0,children:"Assistant"}),e(a,{paddingLeft:2,flexDirection:"column",children:e(me,{children:t.content})})]},r)}),J!==""&&e(Ne,{text:J}),O!==null&&e(Oe,{toolName:O.name,input:O.input}),e(He,{todos:he}),B!==null&&e($e,{request:B.request,onApprove:()=>B.resolve({approved:!0,reason:"Approved from CLI."}),onDeny:()=>B.resolve({approved:!1,reason:"Denied from CLI."})}),_!==null&&e(Pe,{sessions:_.sessions,selectedIndex:_.selectedIndex,onSelect:t=>{ee(t)},onCancel:()=>P(null)}),!w&&B===null&&_===null&&e(We,{suggestions:Y,selectedIndex:F}),!w&&B===null&&_===null&&d(a,{gap:1,children:[e(o,{color:"cyan",bold:!0,children:"\u203A"}),e(Me,{value:k,onChange:ye,onSubmit:Ce,focus:B===null&&!w})]}),w&&B===null&&d(a,{gap:2,children:[e(U,{label:"Thinking\u2026"}),e(o,{dimColor:!0,children:"Esc to stop"})]})]})}async function fe(n){try{return JSON.parse(await _e(n,"utf8"))}catch{return}}async function fn({args:n,env:u,sessionsDirectory:m}){let s;try{let f=u.HOME??process.env.HOME,b={env:u};f!==void 0&&(b.userConfig=await fe(De(f,".vole","config.json"))),b.projectConfig=await fe("vole.config.json"),s=ie(b)}catch(f){process.stderr.write(`Configuration error: ${f instanceof Error?f.message:String(f)}
34
- `),process.exitCode=1;return}let i=n.indexOf("--session"),c=i!==-1&&n[i+1]!==void 0?n[i+1]:void 0,g={env:u,...m!==void 0?{sessionsDirectory:m}:{}},{waitUntilExit:C}=Ie(e(qe,{config:s,cliOptions:g,...c!==void 0?{sessionId:c}:{}}));await C()}export{fn as runInkChat};
33
+ \u2026`:u}catch{return""}})(),i=e.decision.risk==="high"?"red":e.decision.risk==="medium"?"yellow":"green";return m(c,{flexDirection:"column",borderStyle:"round",borderColor:"yellow",paddingX:1,marginBottom:1,children:[n(o,{bold:!0,color:"yellow",children:"\u26A0 Approval Required"}),m(c,{gap:1,children:[n(o,{dimColor:!0,children:"Tool:"}),n(o,{bold:!0,children:e.call.name}),n(o,{dimColor:!0,children:"\xB7"}),n(o,{dimColor:!0,children:"Risk:"}),n(o,{color:i,bold:!0,children:e.decision.risk})]}),s!==""&&m(c,{flexDirection:"column",marginTop:1,marginBottom:1,children:[n(o,{dimColor:!0,children:"Input:"}),n(c,{paddingLeft:2,children:n(o,{dimColor:!0,children:s})})]}),n(o,{dimColor:!0,children:e.decision.reason}),n(c,{marginTop:1,children:n(o,{color:"yellow",children:" y approve any other key deny"})})]})}function Fe({suggestions:e,selectedIndex:l}){return e.length===0?null:m(c,{flexDirection:"column",marginBottom:1,paddingLeft:2,children:[e.map((d,s)=>m(c,{gap:2,children:[s===l?n(o,{color:"cyan",bold:!0,children:d.command}):n(o,{dimColor:!0,children:d.command}),n(o,{dimColor:!0,children:d.description})]},d.command)),n(o,{dimColor:!0,children:"Tab \xB7 complete \u2191\u2193 \xB7 select"})]})}function Je({config:e,cliOptions:l,sessionId:d}){let{exit:s}=ke(),{write:i}=Ee(),[u,g]=T(null),[C,f]=T(null),[b,k]=T(d),[G,v]=T([]),[R,E]=T(""),[w,Q]=T(!1),[q,xe]=T([]),[j,M]=T(-1),[Te,he]=T(""),[F,L]=T(0),[J,_]=T(""),[H,S]=T(null),[ye,K]=T([]),[D,N]=T(null),[B,$]=T(null),Y=fe(()=>R.startsWith("/")?R==="/"?X:X.filter(t=>t.command.startsWith(R)&&t.command!==R):[],[R]),Z=Y.length>0,P=fe(()=>({resolve:t=>new Promise(r=>{$({request:t,resolve:a=>{$(null),r(a)}})})}),[]);Se(()=>{W.createConfigured(e,l,{approvalResolver:P,preferStreaming:!0,...d!==void 0?{sessionId:d}:{}}).then(t=>{g(t),k(t.sessionId)}).catch(t=>{f(t instanceof Error?t.message:"Failed to create session.")})},[e,l,P,d]);let ee=I(async()=>{u?.close(),g(null),v([]),_(""),S(null),K([]),$(null);try{let t=await W.createConfigured(e,l,{approvalResolver:P,preferStreaming:!0});g(t),k(t.sessionId)}catch(t){f(t instanceof Error?t.message:"Failed to reset session.")}},[u,e,l,P]),ne=I(async t=>{N(null),u?.close(),g(null),v([]),_(""),S(null),K([]),$(null);try{let r=await W.createConfigured(e,l,{approvalResolver:P,preferStreaming:!0,sessionId:t.id}),x=(await r.loadMessages()).flatMap(h=>h.role==="user"&&h.content?[{role:"user",content:h.content}]:h.role==="assistant"&&h.content?[{role:"assistant",content:h.content}]:[]);v(x),g(r),k(r.sessionId)}catch(r){f(r instanceof Error?r.message:"Failed to resume session.")}},[u,e,l,P]),te=I(t=>{if(t.type==="token_delta")_(r=>r+t.delta);else if(t.type==="tool_started")S({name:t.toolName});else if(t.type==="tool_call_requested")S({name:t.call.name,input:t.call.input});else if(t.type==="tool_completed"){if(S(null),t.toolName==="update_todos")return;let r=ae(t.result);v(a=>[...a,{role:"tool_result",toolName:t.toolName,content:r,ok:!0}])}else t.type==="tool_failed"?(S(null),v(r=>[...r,{role:"tool_result",toolName:t.toolName,content:t.error.message,ok:!1}])):t.type==="todos_updated"?K([...t.todos]):t.type==="run_failed"&&v(r=>[...r,{role:"error",content:t.error.message}])},[]),V=Ie(null),oe=I(async t=>{if(u===null||w||t.trim()==="")return;let r=t.trim();if(e.secrets.apiKey===void 0){v(x=>[...x,{role:"user",content:r},{role:"error",content:'No API key configured. Add one to ~/.vole/config.json (e.g. {"apiKey": "sk-..."}) or set VOLE_API_KEY / ANTHROPIC_API_KEY / OPENROUTER_API_KEY in your shell.'}]);return}let a=new AbortController;V.current=a,v(x=>[...x,{role:"user",content:r}]),Q(!0),_(""),S(null);try{let x=await u.sendMessage(r,{onEvent:te,signal:a.signal});_(""),S(null),x.assistantText!==""&&!a.signal.aborted&&v(h=>[...h,{role:"assistant",content:x.assistantText}])}finally{V.current=null,Q(!1)}},[u,w,te]),re=I(async t=>{if(u===null)return;if(t==="/resume"){let x=(await u.listSessions({limit:20})).filter(h=>h.id!==u.sessionId);N({sessions:x,selectedIndex:0});return}if(t==="/clear"){i("\x1B[2J\x1B[H"),ee();return}let r=await u.runSlashCommand(t);v(a=>[...a,{role:"slash_result",command:t,lines:r}])},[u,i,ee,ne]),Ce=I(t=>{if(t.includes(" ")){let r=t.replace(/\t/g,""),a=r.startsWith("/")?X.filter(h=>h.command.startsWith(r)&&h.command!==r):[],x=a[F]??a[0];E(x!==void 0?x.command:r),L(0),M(-1)}else E(t),L(0),M(-1),he(t)},[F]);O((t,r)=>{if(D!==null){r.upArrow?N(a=>a&&{...a,selectedIndex:Math.max(0,a.selectedIndex-1)}):r.downArrow&&N(a=>a&&{...a,selectedIndex:Math.min(a.sessions.length-1,a.selectedIndex+1)});return}if(r.upArrow){if(Z)L(a=>Math.max(0,a-1));else if(j<q.length-1){let a=j+1;M(a),E(q[a]??"")}}else if(r.downArrow)if(Z)L(a=>Math.min(Y.length-1,a+1));else if(j>0){let a=j-1;M(a),E(q[a]??"")}else j===0&&(M(-1),E(Te))},{isActive:!w&&B===null}),O((t,r)=>{r.escape&&(V.current?.abort(),_(""),S(null))},{isActive:w}),O((t,r)=>{r.ctrl&&t==="c"&&s()},{isActive:!0});let be=I(t=>{if(w||B!==null)return;let r=t.trim();if(r!==""){if(E(""),M(-1),L(0),r==="/exit"){s();return}if(r.startsWith("/")){re(r);return}xe(a=>a[0]===r?a:[r,...a.slice(0,49)]),oe(r)}},[w,B,oe,s,re]);if(C!==null)return m(c,{flexDirection:"column",padding:1,children:[n(o,{color:"red",bold:!0,children:"Error"}),n(o,{children:C})]});if(u===null)return n(c,{padding:1,children:n(z,{label:"Starting Vole\u2026"})});let se=b??"\u2026",ie=`${e.model.provider}/${e.model.model}`,we=G.length>0||J!==""||H!==null||w;return m(c,{flexDirection:"column",children:[we?n(Ne,{model:ie,sessionId:se}):n(Le,{model:ie,sessionId:se}),n(Me,{items:G,children:(t,r)=>t.role==="user"?m(c,{marginBottom:1,children:[n(o,{color:"cyan",bold:!0,children:"You "}),n(o,{children:t.content})]},r):t.role==="tool_result"?m(c,{flexDirection:"column",marginBottom:1,paddingLeft:2,children:[m(c,{gap:1,children:[n(o,{color:t.ok?"green":"red",children:t.ok?"\u2713":"\u2717"}),n(o,{dimColor:!0,bold:!0,children:t.toolName})]}),n(c,{paddingLeft:2,children:m(o,{dimColor:!0,children:[t.content.slice(0,200),t.content.length>200?" \u2026":""]})})]},r):t.role==="error"?m(c,{marginBottom:1,borderStyle:"single",borderColor:"red",paddingX:1,children:[n(o,{color:"red",bold:!0,children:"\u2717 "}),n(o,{color:"red",children:t.content})]},r):t.role==="slash_result"?m(c,{flexDirection:"column",marginBottom:1,paddingLeft:2,children:[n(o,{color:"blue",dimColor:!0,children:t.command}),t.lines.map((a,x)=>n(o,{dimColor:!0,children:a},x))]},r):m(c,{flexDirection:"column",marginBottom:1,children:[n(o,{color:"green",bold:!0,children:"Assistant"}),n(c,{paddingLeft:2,flexDirection:"column",children:n(pe,{children:t.content})})]},r)}),J!==""&&n(He,{text:J}),H!==null&&n($e,{toolName:H.name,input:H.input}),n(We,{todos:ye}),B!==null&&n(qe,{request:B.request,onApprove:()=>B.resolve({approved:!0,reason:"Approved from CLI."}),onDeny:()=>B.resolve({approved:!1,reason:"Denied from CLI."})}),D!==null&&n(Oe,{sessions:D.sessions,selectedIndex:D.selectedIndex,onSelect:t=>{ne(t)},onCancel:()=>N(null)}),!w&&B===null&&D===null&&n(Fe,{suggestions:Y,selectedIndex:F}),!w&&B===null&&D===null&&m(c,{gap:1,children:[n(o,{color:"cyan",bold:!0,children:"\u203A"}),n(_e,{value:R,onChange:Ce,onSubmit:be,focus:B===null&&!w})]}),w&&B===null&&m(c,{gap:2,children:[n(z,{label:"Thinking\u2026"}),n(o,{dimColor:!0,children:"Esc to stop"})]})]})}async function ge(e){try{return JSON.parse(await De(e,"utf8"))}catch{return}}async function Ke(e=process.cwd()){let l=e;for(;;){try{return await Pe(U(l,".git")),l}catch{}let d=je(l);if(d===l)return;l=d}}async function Tn({args:e,env:l,sessionsDirectory:d}){let s;try{let f=l.HOME??process.env.HOME,b={env:l};if(f!==void 0&&(b.userConfig=await ge(U(f,".vole","config.json"))),b.projectConfig=await ge("vole.config.json"),s=le(b),s.sessions.directory==="~/.vole/sessions"){let k=await Ke();k!==void 0&&(s.sessions.directory=U(k,".vole","sessions"))}}catch(f){process.stderr.write(`Configuration error: ${f instanceof Error?f.message:String(f)}
34
+ `),process.exitCode=1;return}let i=e.indexOf("--session"),u=i!==-1&&e[i+1]!==void 0?e[i+1]:void 0,g={env:l,...d!==void 0?{sessionsDirectory:d}:{}},{waitUntilExit:C}=Ae(n(Je,{config:s,cliOptions:g,...u!==void 0?{sessionId:u}:{}}));await C()}export{Tn as runInkChat};