agent-afk 2.15.0 → 2.15.1

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/dist/cli.mjs +3 -3
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -1845,8 +1845,8 @@ ${a}
1845
1845
  `):[],r=this.spinner?d.meta(`${Rp[this.spinner.frameIndex]} ${this.spinner.verb}...`)+wv(this.spinner.startedAt):null,o=Math.max(1,(this.stdout.rows??24)-1),s=(r?1:0)+1,i=Math.max(0,o-s),a=n.length>i?n.slice(-i):n,l=[];l.push(...a),r&&l.push(r),l.push(t),this.logUpdate(l.join(`
1846
1846
  `))}resetState(){this.overlay="",this.input=F.seed(""),this.queued=!1,this.canceled=!1,this.backgrounded=!1,this.resizeUnsub&&(this.resizeUnsub(),this.resizeUnsub=null)}applyEdit(t){return t===this.input?!1:(this.input=t,this.queued=!1,this.repaint(),!0)}dispatchKey(t,n){if(!this.armed)return;if(n?.name==="escape"||n?.ctrl&&n?.name==="c"){if(this.canceled)return;this.canceled=!0,this.input.buffer.length>0&&!this.queued&&(this.queued=!0,this.repaint()),this.onCancel&&this.onCancel();return}if(n?.name==="return"){this.input.buffer.length>0&&!this.queued&&(this.queued=!0,this.repaint());return}if(n?.name==="backspace"){let s=F.backspace(this.input);s!==this.input?this.applyEdit(s):this.queued&&(this.queued=!1,this.repaint());return}if(n?.name==="left"){this.applyEdit(F.moveLeft(this.input));return}if(n?.name==="right"){this.applyEdit(F.moveRight(this.input));return}if(n?.name==="home"){this.applyEdit(F.moveHome(this.input));return}if(n?.name==="end"){this.applyEdit(F.moveEnd(this.input));return}if(n?.name==="delete"){this.applyEdit(F.deleteForward(this.input));return}if(n?.ctrl&&n?.name==="b"){if(this.backgrounded)return;this.backgrounded=!0,this.onBackground&&this.onBackground();return}let r=["up","down","tab","pageup","pagedown"];if(n?.name&&r.includes(n.name)||n?.ctrl||n?.meta)return;let o=typeof t=="string"&&t.length===1&&t>=" "?t:typeof n?.sequence=="string"&&n.sequence.length===1&&n.sequence>=" "?n.sequence:null;o!==null&&this.applyEdit(F.insert(this.input,o))}};var Sv=d.success("\u2713"),vv=d.error("\u2717");function Pn(e){return e?vv:Sv}var Ho=3,Ip=2,Mp=3;function $p(e){switch(yo(e)){case"read":return"Reading\u2026";case"write":return"Writing\u2026";case"web":return"Fetching\u2026";case"shell":return"Running\u2026";default:return"Running\u2026"}}function Wi(e){return e.replace(/\/(?:[^/\s,)]+\/){2,}([^/\s,)]+)/g,"$1")}function Tv(e){let t=/^(\s*[("]?\s*)cd\s+\S+\s+&&\s+(?!cd\s)(.+)$/.exec(e);return t?(t[1]??"")+(t[2]??""):e}function xv(e,t){if(!e)return null;try{switch(e){case"memory_search":{let n=JSON.parse(t);if(!Array.isArray(n))return null;let r=n.length;if(r===0)return"no results";let o=0,s=0;for(let l of n)if(l&&typeof l=="object"){let c=l.type;c==="fact"?o++:c==="procedure"&&s++}let i=`${r} result${r===1?"":"s"}`;if(o+s!==r)return i;let a=[];return o>0&&a.push(`${o} fact${o===1?"":"s"}`),s>0&&a.push(`${s} procedure${s===1?"":"s"}`),a.length===0?i:a.length===1?`${i} (${a[0]})`:`${i} (${a.join(", ")})`}case"memory_update":{let n=JSON.parse(t);if(!n||typeof n!="object")return null;let r=n;return r.target==="hot"&&r.saved===!0?"hot memory saved":r.action==="remove"?r.removed===!0?"fact removed":"fact not found":r.action==="set"&&typeof r.id=="number"?`fact #${r.id} set`:r.action==="supersede"&&typeof r.id=="number"&&typeof r.supersedes=="number"?`fact #${r.id} supersedes #${r.supersedes}`:null}case"procedure_write":{let n=JSON.parse(t);if(!n||typeof n!="object")return null;let r=n;return typeof r.name=="string"&&r.written===!0?`wrote procedure '${r.name}'`:null}default:return null}}catch{return null}}function Ev(e,t){if(e==="bash"||e==="Bash")return Tv(t);if(e==="compose"||e==="Compose"){let n=t.trim().replace(/^\((.*)\)$/s,"$1");try{let r=JSON.parse(n);if(r&&typeof r=="object"){let o=Array.isArray(r.nodes)?r.nodes.length:void 0,s=Array.isArray(r.edges)?r.edges.length:0;if(o!==void 0){let i=`${o} node${o===1?"":"s"}`,a=s>0?`, ${s} edge${s===1?"":"s"}`:"";return`(${i}${a})`}}}catch{}}return t}function Op(e){return e.replace(/[\r\n]+/g," ")}function Dt(e,t){let n=/^([A-Za-z_][A-Za-z0-9_]*)(.*)$/s.exec(e);if(n){let r=n[1],o=Wi(Ev(r,n[2]??"")),s=yo(r),{color:i,glyph:a}=Tn(r),l=ld(s),c=l?` [${l}]`:"";if(t!==void 0){let u=(a+" ").length+r.length+c.length,m=Math.max(1,t-u);o=ue(o,m)}o=Op(o);let p=i(a+" ")+i.bold(r)+d.toolArg(o);return l?p+d.dim(c):p}return d.tool("\u25CF ")+d.toolArg(e)}function Cv(e,t){return e?e==="grep"||e==="Grep"?t===1?"match":"matches":e==="glob"||e==="Glob"?t===1?"path":"paths":t===1?"line":"lines":t===1?"line":"lines"}function Qt(e,t,n=60,r){let o=e.isError?d.error:d.dim,s=t??process.env.HOME??"___NOHOME___";if(e.persistedPath){let a=e.persistedPath.startsWith(s)?"~"+e.persistedPath.slice(s.length):e.persistedPath;return o(`saved \u2192 ${a}`)}if(e.lineCount!==void 0&&e.lineCount>1)return o(`${e.lineCount} ${Cv(r,e.lineCount)}`);if(!e.isError){let a=xv(r,e.content);if(a!==null)return o(a)}let i=e.content.length>n?e.content.slice(0,n-3)+"\u2026":e.content;return o(Op(i))}function _e(e,t){return ue(e,t)}function Lp(e,t){if(!e||!e.trim())return[];let n=d.dim("\u2502 "),r=Math.max(1,J()-t.length-2-2),o=[];for(let s of e.split(`
1847
1847
  `)){let i=Z(s,r);for(let a of i.split(`
1848
- `))o.push(t+n+a)}return o}function Dp(e){return ut.has(e.toolName)?e.toolName+"::"+e.toolInput:e.toolName}function Pv(e){return ut.has(e)?Ip:Mp}function Np(e){return e.map((t,n)=>({sibling:t,connector:n===e.length-1?"\u2514 ":"\u251C "}))}function Fp(e,t){if(e.length<=t)return e;let n=e.slice(0,t),r=e.slice(t),o=_v(r);return[...n,{kind:"overflow",count:r.length,text:o}]}function Av(e,t){return t?[...e,{kind:"resultSummary",summary:t}]:e}function Up(e){if(e.length===0)return[];let t=new Map;for(let o of e){let s=Dp(o),i=t.get(s);i||(i=[],t.set(s,i)),i.push(o)}let n=[],r=new Set;for(let o of e){let s=Dp(o),i=t.get(s);i.length>=Pv(o.toolName)?r.has(s)||(n.push({kind:"group",toolName:o.toolName,label:ut.has(o.toolName)?o.toolInput:"",entries:i}),r.add(s)):n.push(o)}return n}function jp(e){let t=e.entries.length,n=e.entries.filter(a=>a.result),r=n.filter(a=>a.result.isError),o=n.length,s;if(r.length>0){let a=o-r.length,l=[];a>0&&l.push(`${a} ok`),l.push(`${r.length} error${r.length===1?"":"s"}`),s=l.join(", ")}else o===t?s=`${t} done`:o===0?s=`${t} running`:s=`${o}/${t} done`;return Dt(e.toolName+e.label)+d.dim(` \xD7${t} \u2014 ${s}`)}function _v(e){let t=new Map,n=0;for(let o of e)o.kind==="group"?(t.set(o.toolName,(t.get(o.toolName)??0)+o.entries.length),n+=o.entries.length):(t.set(o.toolName,(t.get(o.toolName)??0)+1),n+=1);if(n===0)return"";let r=[];for(let[o,s]of t)r.push(`${s} ${o}`);return`\u2026 +${n} (${r.join(", ")})`}function Hi(e,t,n,r,o=J()){let s=" ".repeat(n+1),i=e.filter(u=>u.kind==="text"),a=e.filter(u=>u.kind==="tool");for(let u of i)r.push(...Lp(u.text,s));let l=Up(a),c=Fp(l,Ho),p=Np(c);for(let{sibling:u,connector:m}of p){let f=d.dim(m);if(u.kind==="overflow")r.push(_e(s+f+d.dim(u.text),o));else if(u.kind==="group")r.push(_e(s+f+jp(u),o));else if(u.kind==="resultSummary")r.push(_e(s+f+d.dim(u.summary),o));else{let g=u,h=t.get(g.toolUseId);ut.has(g.toolName)&&h&&h.length>0?(r.push(_e(s+f+g.prefix,o)),g.thinkingTail&&r.push(s+" "+d.thinking("\u2307 "+g.thinkingTail)),Hi(h,t,n+1,r,o)):g.result?r.push(_e(s+f+g.prefix+d.dim(" \u2014 ")+Pn(g.result.isError)+" "+Qt(g.result,void 0,60,g.toolName),o)):(r.push(_e(s+f+g.prefix,o)),g.thinkingTail?r.push(s+" "+d.thinking("\u2307 "+g.thinkingTail)):r.push(_e(s+" "+d.dim($p(g.toolName)),o)))}}}function Bp(e,t,n,r,o,s=J()){let i=" ".repeat(n+1),a=[],l=e.filter(g=>g.kind==="text"),c=e.filter(g=>g.kind==="tool");for(let g of l)a.push(...Lp(g.text,i));let p=Up(c),u=Fp(p,Ho),m=Av(u,o),f=Np(m);for(let{sibling:g,connector:h}of f){let k=d.dim(h);if(g.kind==="overflow")a.push(_e(i+k+d.dim(g.text),s));else if(g.kind==="resultSummary")a.push(_e(i+k+d.dim(g.summary),s));else if(g.kind==="group")a.push(_e(i+k+jp(g),s));else{let y=g,v=t.get(y.toolUseId);ut.has(y.toolName)&&v&&v.length>0?(a.push(_e(i+k+y.prefix,s)),a.push(...Bp(v,t,n+1,r,void 0,s))):y.result?a.push(_e(i+k+y.prefix+d.dim(" \u2014 ")+Pn(y.result.isError)+" "+Qt(y.result,r,60,y.toolName),s)):a.push(_e(i+k+y.prefix,s))}}return a}function Ki(e,t,n,r){let o=t.filter(p=>p.kind==="tool"),i=o.filter(p=>p.result).reduce((p,u)=>p+(u.result.lineCount??0),0),a=[];o.length>Ho&&(a.push(`${o.length} tools`),i>0&&a.push(`${i} lines`));let l=a.length>0?" "+e.prefix+d.dim(" \u2014 "+a.join(" \xB7 ")):" "+e.prefix,c=Bp(t,n,1,r,e.agentResultSummary);return[l,...c].join(`
1849
- `)}function Gi(e,t,n){let r=[];for(let o of t){let s=e.get(o);if(s.length===1){let i=s[0];i.result?r.push(" "+i.prefix+d.dim(" \u2014 ")+Pn(i.result.isError)+" "+Qt(i.result,n,60,i.toolName)):r.push(" "+i.prefix)}else r.push(Rv(o,s,n))}return r}function Rv(e,t,n){let{color:r,glyph:o}=Tn(e),s=t.map(p=>Wi(p.toolInput).trim()),i=r(o+" ")+r.bold(e)+d.dim(` \xD7${t.length}`)+" "+d.toolArg(s.join(", ")),a=t.filter(p=>p.result),l=a.filter(p=>p.result.isError);if(l.length>0){let p=a.length-l.length,m=a.filter(g=>!g.result.isError).map(g=>g.result.lineCount).filter(g=>g!==void 0).reduce((g,h)=>g+h,0),f=[];return m>0&&f.push(`${m} lines`),p>0&&f.push(`${p} ok`),f.push(d.error(`${l.length} error${l.length>1?"s":""}`))," "+i+d.dim(" \u2014 ")+f.join(d.dim(", "))}let c=a.map(p=>p.result?.lineCount).filter(p=>p!==void 0);if(c.length===a.length&&c.length>0){if(c.every(m=>m===c[0]))return" "+i+d.dim(` \u2014 ${c[0]} lines each`);let u=c.reduce((m,f)=>m+f,0);return" "+i+d.dim(` \u2014 ${u} lines total`)}if(a.length>0){let p=a.map(u=>Qt(u.result,n,60,u.toolName));return" "+i+d.dim(" \u2014 ")+p.join(d.dim(", "))}return" "+i}var dr=class{entries=new Map;order=[];agentIdStack=[];addStart(t,n,r){let o=Dt(n+r),s=this.agentIdStack.at(-1)??void 0,i={kind:"tool",toolUseId:t,toolName:n,toolInput:r,prefix:o,...s!==void 0?{agentContext:s}:{}};this.entries.set(t,i),this.order.push(t),rr.has(n)&&this.agentIdStack.push(t)}addStartWithAgentContext(t,n,r,o,s){let i=this.entries.get(t);if(i?.kind==="tool"){i.toolInput=r,i.prefix=Dt(n+r,s),o!==void 0&&(i.agentContext=o);return}let a=Dt(n+r,s),l={kind:"tool",toolUseId:t,toolName:n,toolInput:r,prefix:a,...o!==void 0?{agentContext:o}:{}};this.entries.set(t,l),this.order.push(t)}mergeAgentLabel(t,n,r){let o=this.entries.get(t);if(o?.kind!=="tool"||!rr.has(o.toolName)||o.toolName==="Agent")return!1;let s=`(${n})`;return o.toolName="Agent",o.toolInput=s,o.prefix=Dt("Agent"+s,r),!0}setAgentContext(t,n){let r=this.entries.get(t);r?.kind==="tool"&&(n===void 0?delete r.agentContext:r.agentContext=n)}setAgentResultSummary(t,n){let r=this.entries.get(t);r?.kind==="tool"&&(r.agentResultSummary=n)}setThinkingTail(t,n){let r=this.entries.get(t);r?.kind==="tool"&&(n===void 0?delete r.thinkingTail:r.thinkingTail=n)}addResult(t,n){let r=this.entries.get(t);r?.kind==="tool"&&(r.result=n),this.agentIdStack.at(-1)===t&&this.agentIdStack.pop()}upsertTextChild(t,n,r){let o=this.entries.get(t);if(o?.kind==="text"){o.text=r,o.agentContext=n;return}let s={kind:"text",toolUseId:t,text:r,agentContext:n};this.entries.set(t,s),this.order.push(t)}removeTextChildrenUnder(t){let n=[];for(let[r,o]of this.entries)o.kind==="text"&&o.agentContext===t&&n.push(r);for(let r of n)this.entries.delete(r);if(n.length>0){let r=new Set(n);this.order=this.order.filter(o=>!r.has(o))}}hasPending(){return this.entries.size>0}hasEntry(t){return this.entries.get(t)?.kind==="tool"}getOverlay(){let t=this.buildChildMap(),n=[];for(let r of this.order){let o=this.entries.get(r);if(!o||o.kind!=="tool"||o.agentContext)continue;let s=t.get(o.toolUseId);ut.has(o.toolName)&&s&&s.length>0?(n.push(" "+o.prefix),o.thinkingTail&&n.push(" "+d.thinking("\u2307 "+o.thinkingTail)),Hi(s,t,1,n)):o.result?n.push(" "+o.prefix+d.dim(" \u2014 ")+Pn(o.result.isError)+" "+Qt(o.result,void 0,60,o.toolName)):(n.push(" "+o.prefix+d.dim(" \u2026")),o.thinkingTail&&n.push(" "+d.thinking("\u2307 "+o.thinkingTail)))}return n.join(`
1848
+ `))o.push(t+n+a)}return o}function Dp(e){return ut.has(e.toolName)?e.toolName+"::"+e.toolInput:e.toolName}function Pv(e){return ut.has(e)?Ip:Mp}function Np(e){return e.map((t,n)=>({sibling:t,connector:n===e.length-1?"\u2514 ":"\u251C "}))}function Fp(e,t){if(e.length<=t)return e;let n=e.slice(0,t),r=e.slice(t),o=_v(r);return[...n,{kind:"overflow",count:r.length,text:o}]}function Av(e,t){return t?[...e,{kind:"resultSummary",summary:t}]:e}function Up(e){if(e.length===0)return[];let t=new Map;for(let o of e){let s=Dp(o),i=t.get(s);i||(i=[],t.set(s,i)),i.push(o)}let n=[],r=new Set;for(let o of e){let s=Dp(o),i=t.get(s);i.length>=Pv(o.toolName)?r.has(s)||(n.push({kind:"group",toolName:o.toolName,label:ut.has(o.toolName)?o.toolInput:"",entries:i}),r.add(s)):n.push(o)}return n}function jp(e){let t=e.entries.length,n=e.entries.filter(a=>a.result),r=n.filter(a=>a.result.isError),o=n.length,s;if(r.length>0){let a=o-r.length,l=[];a>0&&l.push(`${a} ok`),l.push(`${r.length} error${r.length===1?"":"s"}`),s=l.join(", ")}else o===t?s=`${t} done`:o===0?s=`${t} running`:s=`${o}/${t} done`;return Dt(e.toolName+e.label)+d.dim(` \xD7${t} \u2014 ${s}`)}function _v(e){let t=new Map,n=0;for(let o of e)o.kind==="group"?(t.set(o.toolName,(t.get(o.toolName)??0)+o.entries.length),n+=o.entries.length):(t.set(o.toolName,(t.get(o.toolName)??0)+1),n+=1);if(n===0)return"";let r=[];for(let[o,s]of t)r.push(`${s} ${o}`);return`\u2026 +${n} (${r.join(", ")})`}function Hi(e,t,n,r,o=J()){let s=" ".repeat(n+1),i=e.filter(u=>u.kind==="text"),a=e.filter(u=>u.kind==="tool"),l=Up(a),c=Fp(l,Ho),p=Np(c);for(let{sibling:u,connector:m}of p){let f=d.dim(m);if(u.kind==="overflow")r.push(_e(s+f+d.dim(u.text),o));else if(u.kind==="group")r.push(_e(s+f+jp(u),o));else if(u.kind==="resultSummary")r.push(_e(s+f+d.dim(u.summary),o));else{let g=u,h=t.get(g.toolUseId);ut.has(g.toolName)&&h&&h.length>0?(r.push(_e(s+f+g.prefix,o)),Hi(h,t,n+1,r,o),g.thinkingTail&&r.push(s+" "+d.thinking("\u2307 "+g.thinkingTail))):g.result?r.push(_e(s+f+g.prefix+d.dim(" \u2014 ")+Pn(g.result.isError)+" "+Qt(g.result,void 0,60,g.toolName),o)):(r.push(_e(s+f+g.prefix,o)),g.thinkingTail?r.push(s+" "+d.thinking("\u2307 "+g.thinkingTail)):r.push(_e(s+" "+d.dim($p(g.toolName)),o)))}}for(let u of i)r.push(...Lp(u.text,s))}function Bp(e,t,n,r,o,s=J()){let i=" ".repeat(n+1),a=[],l=e.filter(g=>g.kind==="text"),c=e.filter(g=>g.kind==="tool"),p=Up(c),u=Fp(p,Ho),m=Av(u,o),f=Np(m);for(let{sibling:g,connector:h}of f){let k=d.dim(h);if(g.kind==="overflow")a.push(_e(i+k+d.dim(g.text),s));else if(g.kind==="resultSummary")a.push(_e(i+k+d.dim(g.summary),s));else if(g.kind==="group")a.push(_e(i+k+jp(g),s));else{let y=g,v=t.get(y.toolUseId);ut.has(y.toolName)&&v&&v.length>0?(a.push(_e(i+k+y.prefix,s)),a.push(...Bp(v,t,n+1,r,void 0,s))):y.result?a.push(_e(i+k+y.prefix+d.dim(" \u2014 ")+Pn(y.result.isError)+" "+Qt(y.result,r,60,y.toolName),s)):a.push(_e(i+k+y.prefix,s))}}for(let g of l)a.push(...Lp(g.text,i));return a}function Ki(e,t,n,r){let o=t.filter(p=>p.kind==="tool"),i=o.filter(p=>p.result).reduce((p,u)=>p+(u.result.lineCount??0),0),a=[];o.length>Ho&&(a.push(`${o.length} tools`),i>0&&a.push(`${i} lines`));let l=a.length>0?" "+e.prefix+d.dim(" \u2014 "+a.join(" \xB7 ")):" "+e.prefix,c=Bp(t,n,1,r,e.agentResultSummary);return[l,...c].join(`
1849
+ `)}function Gi(e,t,n){let r=[];for(let o of t){let s=e.get(o);if(s.length===1){let i=s[0];i.result?r.push(" "+i.prefix+d.dim(" \u2014 ")+Pn(i.result.isError)+" "+Qt(i.result,n,60,i.toolName)):r.push(" "+i.prefix)}else r.push(Rv(o,s,n))}return r}function Rv(e,t,n){let{color:r,glyph:o}=Tn(e),s=t.map(p=>Wi(p.toolInput).trim()),i=r(o+" ")+r.bold(e)+d.dim(` \xD7${t.length}`)+" "+d.toolArg(s.join(", ")),a=t.filter(p=>p.result),l=a.filter(p=>p.result.isError);if(l.length>0){let p=a.length-l.length,m=a.filter(g=>!g.result.isError).map(g=>g.result.lineCount).filter(g=>g!==void 0).reduce((g,h)=>g+h,0),f=[];return m>0&&f.push(`${m} lines`),p>0&&f.push(`${p} ok`),f.push(d.error(`${l.length} error${l.length>1?"s":""}`))," "+i+d.dim(" \u2014 ")+f.join(d.dim(", "))}let c=a.map(p=>p.result?.lineCount).filter(p=>p!==void 0);if(c.length===a.length&&c.length>0){if(c.every(m=>m===c[0]))return" "+i+d.dim(` \u2014 ${c[0]} lines each`);let u=c.reduce((m,f)=>m+f,0);return" "+i+d.dim(` \u2014 ${u} lines total`)}if(a.length>0){let p=a.map(u=>Qt(u.result,n,60,u.toolName));return" "+i+d.dim(" \u2014 ")+p.join(d.dim(", "))}return" "+i}var dr=class{entries=new Map;order=[];agentIdStack=[];addStart(t,n,r){let o=Dt(n+r),s=this.agentIdStack.at(-1)??void 0,i={kind:"tool",toolUseId:t,toolName:n,toolInput:r,prefix:o,...s!==void 0?{agentContext:s}:{}};this.entries.set(t,i),this.order.push(t),rr.has(n)&&this.agentIdStack.push(t)}addStartWithAgentContext(t,n,r,o,s){let i=this.entries.get(t);if(i?.kind==="tool"){i.toolInput=r,i.prefix=Dt(n+r,s),o!==void 0&&(i.agentContext=o);return}let a=Dt(n+r,s),l={kind:"tool",toolUseId:t,toolName:n,toolInput:r,prefix:a,...o!==void 0?{agentContext:o}:{}};this.entries.set(t,l),this.order.push(t)}mergeAgentLabel(t,n,r){let o=this.entries.get(t);if(o?.kind!=="tool"||!rr.has(o.toolName)||o.toolName==="Agent")return!1;let s=`(${n})`;return o.toolName="Agent",o.toolInput=s,o.prefix=Dt("Agent"+s,r),!0}setAgentContext(t,n){let r=this.entries.get(t);r?.kind==="tool"&&(n===void 0?delete r.agentContext:r.agentContext=n)}setAgentResultSummary(t,n){let r=this.entries.get(t);r?.kind==="tool"&&(r.agentResultSummary=n)}setThinkingTail(t,n){let r=this.entries.get(t);r?.kind==="tool"&&(n===void 0?delete r.thinkingTail:r.thinkingTail=n)}addResult(t,n){let r=this.entries.get(t);r?.kind==="tool"&&(r.result=n),this.agentIdStack.at(-1)===t&&this.agentIdStack.pop()}upsertTextChild(t,n,r){let o=this.entries.get(t);if(o?.kind==="text"){o.text=r,o.agentContext=n;return}let s={kind:"text",toolUseId:t,text:r,agentContext:n};this.entries.set(t,s),this.order.push(t)}removeTextChildrenUnder(t){let n=[];for(let[r,o]of this.entries)o.kind==="text"&&o.agentContext===t&&n.push(r);for(let r of n)this.entries.delete(r);if(n.length>0){let r=new Set(n);this.order=this.order.filter(o=>!r.has(o))}}hasPending(){return this.entries.size>0}hasEntry(t){return this.entries.get(t)?.kind==="tool"}getOverlay(){let t=this.buildChildMap(),n=[];for(let r of this.order){let o=this.entries.get(r);if(!o||o.kind!=="tool"||o.agentContext)continue;let s=t.get(o.toolUseId);ut.has(o.toolName)&&s&&s.length>0?(n.push(" "+o.prefix),Hi(s,t,1,n),o.thinkingTail&&n.push(" "+d.thinking("\u2307 "+o.thinkingTail))):o.result?n.push(" "+o.prefix+d.dim(" \u2014 ")+Pn(o.result.isError)+" "+Qt(o.result,void 0,60,o.toolName)):(n.push(" "+o.prefix+d.dim(" \u2026")),o.thinkingTail&&n.push(" "+d.thinking("\u2307 "+o.thinkingTail)))}return n.join(`
1850
1850
  `)}flushSource(t,n){let r=this.entries.get(t);if(!r||r.kind!=="tool")return[];let o=new Set([t]),s=[t];for(;s.length>0;){let c=s.shift();for(let[p,u]of this.entries){if(o.has(p))continue;(u.kind==="tool",u.agentContext)===c&&(o.add(p),u.kind==="tool"&&s.push(p))}}let i=new Map;for(let c of this.order){if(!o.has(c))continue;let p=this.entries.get(c);if(!p)continue;let u=(p.kind==="tool",p.agentContext);if(!u)continue;let m=i.get(u);m||(m=[],i.set(u,m)),m.push(p)}let a=i.get(r.toolUseId)??[],l=[Ki(r,a,i,n)];for(let c of o)this.entries.delete(c);return this.order=this.order.filter(c=>!o.has(c)),l}flush(t){if(this.entries.size===0)return[];let n=this.buildChildMap(),r=[];for(let a of this.order){let l=this.entries.get(a);!l||l.kind!=="tool"||l.agentContext||r.push(a)}let o=[],s=new Map,i=[];for(let a of r){let l=this.entries.get(a);if(!l||l.kind!=="tool")continue;let c=n.get(l.toolUseId);ut.has(l.toolName)&&c&&c.length>0?(o.push(...Gi(s,i,t)),s.clear(),i.length=0,o.push(Ki(l,c,n,t))):(s.has(l.toolName)||(s.set(l.toolName,[]),i.push(l.toolName)),s.get(l.toolName).push(l))}return o.push(...Gi(s,i,t)),this.entries.clear(),this.order=[],this.agentIdStack=[],o}buildChildMap(){let t=new Map;for(let n of this.order){let r=this.entries.get(n);if(!r)continue;let o=(r.kind==="tool",r.agentContext);if(!o)continue;let s=t.get(o);s||(s=[],t.set(o,s)),s.push(r)}return t}};var An=class{buffer="";startedAt=null;hasEmitted=!1;push(t){this.hasEmitted||(this.buffer+=t,this.startedAt||(this.startedAt=Date.now()))}isActive(){return!this.hasEmitted}hasBufferedContent(){return this.buffer.trim().length>0}peek(){return this.buffer}consume(){return this.hasEmitted=!0,this.buffer}collapse(){if(this.hasEmitted||!this.startedAt)return!this.startedAt&&!this.hasEmitted&&xe()&&console.error("[afk:thinking] collapse() short-circuited: no thinking chunks received this turn. Model may not support extended thinking, or API ignored the thinking parameter."),null;this.hasEmitted=!0;let t=Date.now()-this.startedAt,n=t<1e3?`${t}ms`:`${(t/1e3).toFixed(1)}s`,r=Math.ceil(this.buffer.length/4);return` ${d.thinking("\u25C6 thought for "+n+" \xB7 "+r+" tok")}`}inlineSummary(){if(!this.startedAt||!this.hasBufferedContent())return null;let t=Date.now()-this.startedAt,n=t<1e3?`${t}ms`:`${(t/1e3).toFixed(1)}s`,r=Math.ceil(this.buffer.length/4);return`thought ${n} \xB7 ${r} tok`}};var zi="__main__";function Hp(e){let t={startedAt:Date.now(),lastEventAt:Date.now(),stats:{tokens:0,toolUses:0},contentBuffer:"",done:!1,errored:!1,stalledTicks:0};return e!==void 0&&(t.agentType=e),t}function pr(e,t){return{type:"tool_result",toolUseId:"synthetic",content:e,isError:t}}function Kp(e){let t=["Done"],n=[];e.stats.toolUses&&n.push(`${e.stats.toolUses} tool${e.stats.toolUses===1?"":"s"}`),e.stats.tokens&&n.push(`${U(e.stats.tokens)} tok`);let r=e.responseMetadata?.durationMs;if(typeof r=="number"&&n.push(de(r)),n.length===0){let s=Date.now()-e.startedAt;s>0&&n.push(de(s))}let o=e.thinkingLane?.inlineSummary();return o&&n.push(o),n.length>0&&t.push(`(${n.join(" \xB7 ")})`),t.join(" ")}var Ko=class{out;throttleMs;indent;buffer="";committed="";throttleTimer=null;logUpdate=null;isTTY;flushing=!1;compositor;constructor(t){this.out=t?.out??process.stdout,this.throttleMs=t?.throttleMs??33,this.indent=t?.indent??" ",this.isTTY=this.out.isTTY??!1,this.compositor=t?.compositor??null,this.logUpdate=null}async initLogUpdate(){if(!(!this.isTTY||this.logUpdate!==null))try{let n=(await import("log-update")).default,r=(o=>{n(o)});r.clear=()=>n.clear(),this.logUpdate=r}catch{this.logUpdate=null}}hasMarkdownContent(t){return/[#*_\-\`>\[\|~]/.test(t)}findBlockBoundary(t){let n=t.indexOf(`
1851
1851
 
1852
1852
  `);if(n!==-1)return n+2;let r=t.match(/\n[ \t]*```[ \t]*\n/);if(r&&r.index!==void 0)return r.index+r[0].length;let o=t.match(/```[a-z]*\n/);return o&&o.index!==void 0&&!t.slice(o.index+o[0].length).includes("\n```"),-1}applyIndent(t){return t.split(`
@@ -1950,7 +1950,7 @@ _ended: ${new Date().toISOString()}_
1950
1950
  `)&&(s+=`
1951
1951
  `),s+=`${n}
1952
1952
  `,await ma.writeFile(t,s,"utf8")}function lE(e,t,n){if(!ds(e))return new Error(`git worktree add failed: ${String(e)}`);let r=e.stderr??"",o=e.message??"",s=`${r}
1953
- ${o}`;return s.includes("already checked out")||s.includes("is already used by worktree")?new Error(`Branch '${t}' is already checked out in another worktree. Pick a different name.`):s.includes("already exists")?new Error(`Worktree path '${n}' already exists. Remove it or pick a different branch name.`):new Error(o||r||"git worktree add failed")}async function bf(e,t){let n=t?.execFile??nE,r=await iE(n),o=e===!0?oE():e;sE(o);let s=o.replaceAll("/","-"),i=fa(r,".afk-worktrees",s);await aE(r);try{await n("git",["-C",r,"worktree","add","-b",o,i])}catch(l){throw lE(l,o,i)}let a=async()=>{let l;try{l=await n("git",["-C",i,"status","--porcelain"])}catch(c){let p=ds(c)?c.message||c.stderr||"":String(c);console.warn(`Worktree cleanup: could not check status at ${i} (${p}). Skipping removal \u2014 manual cleanup may be needed.`);return}if(l.stdout.trim().length>0){console.log(`Worktree preserved at ${i} (branch: ${o}) \u2014 uncommitted changes.`);return}try{await n("git",["-C",r,"worktree","remove","--force",i])}catch(c){let p=ds(c)?c.message||c.stderr||"":String(c);console.warn(`Worktree cleanup: 'git worktree remove --force ${i}' failed (${p}). Manual removal may be needed.`);return}try{await n("git",["-C",r,"branch","-d",o])}catch(c){let p=ds(c)?c.message||c.stderr||"":String(c);console.warn(`Could not delete branch '${o}': ${p}`)}};try{let l="",c="";try{l=(await n("git",["-C",r,"rev-parse","HEAD"])).stdout.trim()}catch{}try{c=(await n("git",["-C",r,"symbolic-ref","--short","HEAD"])).stdout.trim()}catch{}let p={owner:"interactive",createdAt:new Date().toISOString(),baseSha:l,baseBranch:c};await ma.writeFile(fa(i,".afk-worktree-meta.json"),JSON.stringify(p,null,2),"utf-8")}catch{}return{path:i,branch:o,cleanup:a}}import{spawn as kf}from"child_process";import{existsSync as mE,mkdirSync as fE,readFileSync as wf,unlinkSync as gE,writeFileSync as hE}from"fs";import{get as yE}from"https";import{join as Sf}from"path";import{readFileSync as cE}from"fs";import{dirname as uE,join as dE}from"path";import{fileURLToPath as pE}from"url";function an(){try{return"2.15.0"}catch{}try{let e=uE(pE(import.meta.url));for(let t of["../../package.json","../package.json"])try{let n=JSON.parse(cE(dE(e,t),"utf-8"));if(typeof n.version=="string")return n.version}catch{}}catch{}return"0.0.0-unknown"}var bE=64*1024,kE=1440*60*1e3,wE="update-check.json",SE="pending-update.json";function vf(){return Sf(Tr(),wE)}function ga(){return Sf(Tr(),SE)}function Tf(){let e=Tr();mE(e)||fE(e,{recursive:!0})}function vE(e,t){let n=e.split(".").map(Number),r=t.split(".").map(Number),o=Math.max(n.length,r.length);for(let s=0;s<o;s++){let i=n[s]??0,a=r[s]??0;if(a>i)return!0;if(a<i)return!1}return!1}function TE(){try{let e=wf(vf(),"utf-8"),t=JSON.parse(e);if(typeof t.latestVersion=="string"&&typeof t.checkedAt=="number")return t}catch{}return null}function xE(){try{Tf();let e=`
1953
+ ${o}`;return s.includes("already checked out")||s.includes("is already used by worktree")?new Error(`Branch '${t}' is already checked out in another worktree. Pick a different name.`):s.includes("already exists")?new Error(`Worktree path '${n}' already exists. Remove it or pick a different branch name.`):new Error(o||r||"git worktree add failed")}async function bf(e,t){let n=t?.execFile??nE,r=await iE(n),o=e===!0?oE():e;sE(o);let s=o.replaceAll("/","-"),i=fa(r,".afk-worktrees",s);await aE(r);try{await n("git",["-C",r,"worktree","add","-b",o,i])}catch(l){throw lE(l,o,i)}let a=async()=>{let l;try{l=await n("git",["-C",i,"status","--porcelain"])}catch(c){let p=ds(c)?c.message||c.stderr||"":String(c);console.warn(`Worktree cleanup: could not check status at ${i} (${p}). Skipping removal \u2014 manual cleanup may be needed.`);return}if(l.stdout.trim().length>0){console.log(`Worktree preserved at ${i} (branch: ${o}) \u2014 uncommitted changes.`);return}try{await n("git",["-C",r,"worktree","remove","--force",i])}catch(c){let p=ds(c)?c.message||c.stderr||"":String(c);console.warn(`Worktree cleanup: 'git worktree remove --force ${i}' failed (${p}). Manual removal may be needed.`);return}try{await n("git",["-C",r,"branch","-d",o])}catch(c){let p=ds(c)?c.message||c.stderr||"":String(c);console.warn(`Could not delete branch '${o}': ${p}`)}};try{let l="",c="";try{l=(await n("git",["-C",r,"rev-parse","HEAD"])).stdout.trim()}catch{}try{c=(await n("git",["-C",r,"symbolic-ref","--short","HEAD"])).stdout.trim()}catch{}let p={owner:"interactive",createdAt:new Date().toISOString(),baseSha:l,baseBranch:c};await ma.writeFile(fa(i,".afk-worktree-meta.json"),JSON.stringify(p,null,2),"utf-8")}catch{}return{path:i,branch:o,cleanup:a}}import{spawn as kf}from"child_process";import{existsSync as mE,mkdirSync as fE,readFileSync as wf,unlinkSync as gE,writeFileSync as hE}from"fs";import{get as yE}from"https";import{join as Sf}from"path";import{readFileSync as cE}from"fs";import{dirname as uE,join as dE}from"path";import{fileURLToPath as pE}from"url";function an(){try{return"2.15.1"}catch{}try{let e=uE(pE(import.meta.url));for(let t of["../../package.json","../package.json"])try{let n=JSON.parse(cE(dE(e,t),"utf-8"));if(typeof n.version=="string")return n.version}catch{}}catch{}return"0.0.0-unknown"}var bE=64*1024,kE=1440*60*1e3,wE="update-check.json",SE="pending-update.json";function vf(){return Sf(Tr(),wE)}function ga(){return Sf(Tr(),SE)}function Tf(){let e=Tr();mE(e)||fE(e,{recursive:!0})}function vE(e,t){let n=e.split(".").map(Number),r=t.split(".").map(Number),o=Math.max(n.length,r.length);for(let s=0;s<o;s++){let i=n[s]??0,a=r[s]??0;if(a>i)return!0;if(a<i)return!1}return!1}function TE(){try{let e=wf(vf(),"utf-8"),t=JSON.parse(e);if(typeof t.latestVersion=="string"&&typeof t.checkedAt=="number")return t}catch{}return null}function xE(){try{Tf();let e=`
1954
1954
  const https = require('https');
1955
1955
  const fs = require('fs');
1956
1956
  const url = 'https://registry.npmjs.org/agent-afk/latest';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-afk",
3
- "version": "2.15.0",
3
+ "version": "2.15.1",
4
4
  "description": "CLI tool for interacting with AI agents via multiple interfaces",
5
5
  "main": "dist/index.mjs",
6
6
  "type": "module",