agent-afk 3.27.3 → 3.27.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli.mjs +2 -2
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -2006,7 +2006,7 @@ ${d}`}function Md(e,t){let n=vb[t.status];e.out.line(` ${n} ${m.bold(t.jobId)}
2006
2006
  `;return new Promise(r=>{let o=Gb("osascript",["-e",n],{stdio:["ignore","pipe","pipe"]}),s="",i="";o.stdout?.on("data",a=>{s+=a.toString("utf8")}),o.stderr?.on("data",a=>{i+=a.toString("utf8")}),o.on("error",()=>r({ok:!1,exitCode:null,stderr:i})),o.on("close",a=>{r({ok:a===0&&s.trim()==="ok",exitCode:a,stderr:i})})})}function t$(e){return'"'+e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')+'"'}function n$(e){return e.length>=8&&e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71?"image/png":e.length>=3&&e[0]===255&&e[1]===216&&e[2]===255?"image/jpeg":e.length>=4&&e[0]===71&&e[1]===73&&e[2]===70&&e[3]===56?"image/gif":e.length>=12&&e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80?"image/webp":null}var Vb=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],s$=5e3;function i$(e){let t=Date.now()-e;if(t<s$)return"";let n=Math.floor(t/1e3);if(n<60)return m.dim(` ${n}s`);let r=Math.floor(n/60),o=n%60;return m.dim(` ${r}m${o.toString().padStart(2,"0")}s`)}function a$(e,t){let n=" \u{1F4A1} ",r=Math.max(8,t-n.length-1),o=e.length>r?e.slice(0,r-1)+"\u2026":e;return m.dim(n+o)}var zr=class e{stdout;stdin;onCancel;onBackground;onShiftTab;promptTextFn;history;autocompleteState;formatInputBuffer;scrollRegion;captureMode;onSubmit;attachments=[];pasting=!1;pasteStartBufferLen=0;clipboardInFlight=!1;clipboardFailureMsg=null;inputMode="streaming";armed=!1;canceled=!1;backgrounded=!1;wasRaw=!1;logUpdate=null;firstArm=!0;overlay="";input=G.seed("");queued=!1;handleKeypress=null;resizeUnsub=null;spinner=null;spinnerInterval=null;committing=!1;static MAX_DROPDOWN_ROWS=6;constructor(t){this.stdout=t.stdout,this.stdin=t.stdin,this.onCancel=t.onCancel,this.onBackground=t.onBackground,this.onShiftTab=t.onShiftTab;let n=t.promptText;if(typeof n=="function")this.promptTextFn=n;else if(typeof n=="string")this.promptTextFn=()=>n;else{let r=" "+m.dim("\u23AF")+" ";this.promptTextFn=()=>r}this.history=t.history,this.autocompleteState=t.autocompleteState,this.formatInputBuffer=t.formatInputBuffer,this.scrollRegion=t.scrollRegion,this.captureMode=t.captureMode??!1,this.onSubmit=t.onSubmit}isArmed(){return this.armed}setOnSubmit(t){this.onSubmit=t??void 0}setOnCancel(t){this.onCancel=t??void 0}getOnCancel(){return this.onCancel}setOnBackground(t){this.onBackground=t??void 0}setOnShiftTab(t){this.onShiftTab=t??void 0}setInputMode(t){let n=this.inputMode;if(this.inputMode=t,n==="idle"&&t==="streaming"){this.canceled=!1,this.backgrounded=!1,this.autocompleteState?.reset(),this.repaint();return}if(t==="idle"&&this.queued&&this.onSubmit){let r=this.input.buffer,o=[...this.attachments],s=this.onSubmit;this.queued=!1,this.input=G.seed(""),this.attachments=[],this.repaint(),s({text:r,attachments:o});return}n!==t&&this.repaint()}getInputMode(){return this.inputMode}async arm(){if(this.armed)throw new Error("TerminalCompositor: arm() called while already armed");if(!(!this.stdout.isTTY||!this.stdin.isTTY)){this.logUpdate||(this.logUpdate=o$(this.stdout)),this.wasRaw=this.stdin.isRaw??!1;try{this.stdin.setRawMode(!0)}catch{this.logUpdate=null,this.wasRaw=!1;return}try{this.stdout.write("\x1B[?2004h")}catch{}this.stdin.resume(),r$(this.stdin),this.handleKeypress=(t,n)=>this.dispatchKey(t,n),this.stdin.on("keypress",this.handleKeypress),this.resizeUnsub=Ge.subscribe(()=>{this.armed&&(this.anchor(),this.repaint())}),this.armed=!0,this.canceled=!1,this.firstArm?this.firstArm=!1:this.anchor(),this.repaint()}}anchor(){if(!this.stdout.isTTY)return;let t=this.stdout.rows,n=typeof t=="number"&&t>0?t:24,r=Math.max(1,n-1);try{this.stdout.write(`\x1B[${r};1H`)}catch{}}disarm(){if(this.spinnerInterval&&(clearInterval(this.spinnerInterval),this.spinnerInterval=null),this.spinner=null,!this.armed){this.resetState();return}if(this.handleKeypress&&(this.stdin.removeListener("keypress",this.handleKeypress),this.handleKeypress=null),this.resizeUnsub&&(this.resizeUnsub(),this.resizeUnsub=null),this.logUpdate)try{this.logUpdate.clear(),this.logUpdate.done()}catch{}if(this.stdout.isTTY&&this.stdin.isTTY){try{this.stdout.write("\x1B[?2004l")}catch{}try{this.stdin.setRawMode(this.wasRaw)}catch{}}this.armed=!1,this.resetState()}setOverlay(t){t!==this.overlay&&(this.overlay=t,this.repaint())}setSpinner(t){if(!this.stdout.isTTY)return;if(!t.enabled){this.spinnerInterval&&(clearInterval(this.spinnerInterval),this.spinnerInterval=null),this.spinner&&(this.spinner=null,this.repaint());return}if(this.captureMode||this.spinner)return;let n=t.rotateVerbEveryMs??3500,r=Date.now();this.spinner={frameIndex:0,verb:Ud(),nextVerbRotateAt:r+n,startedAt:r,tipPool:Fb(),currentTip:null},this.spinnerInterval=setInterval(()=>this.tickSpinner(n),80),this.repaint()}tickSpinner(t){if(!this.spinner)return;this.spinner.frameIndex=(this.spinner.frameIndex+1)%Vb.length;let n=Date.now();n>=this.spinner.nextVerbRotateAt&&(this.spinner.verb=Ud(),this.spinner.nextVerbRotateAt=n+t),this.spinner.currentTip=Nb(this.spinner.tipPool,{startedAt:this.spinner.startedAt,now:n}),this.repaint()}commitAbove(t){let n=r=>{this.scrollRegion?this.scrollRegion.withFullScrollRegion(r):r()};if(!this.armed||!this.logUpdate){n(()=>{this.stdout.write(t+`
2007
2007
  `)});return}this.committing=!0;try{this.logUpdate.clear(),n(()=>{this.stdout.write(t+`
2008
2008
  `)})}finally{this.committing=!1}this.repaint()}getBuffer(){return{text:this.input.buffer,queued:this.queued}}getAttachments(){return[...this.attachments]}renderInputLine(){let t=this.queued?" "+m.dim("[queued]"):"",n=this.input.buffer.slice(0,this.input.cursor),r=wo(this.input.buffer,this.input.cursor),o=this.input.cursor<this.input.buffer.length?this.input.buffer.slice(this.input.cursor,r):" ",s=this.input.cursor<this.input.buffer.length?this.input.buffer.slice(r):"",i=this.formatInputBuffer?.(n)??n,a=this.formatInputBuffer?.(s)??s,l=m.user.inverse(o);return this.promptTextFn()+i+l+a+t}updateAutocomplete(){let t=this.autocompleteState;if(!t)return;t.trigger=ts(this.input.buffer,this.input.cursor);let n=`${this.input.cursor}:${this.input.buffer}`;t.suppressedSignature!==null&&t.suppressedSignature!==n&&(t.suppressedSignature=null),t.trigger&&t.suppressedSignature===null?(t.trigger.kind==="slash"?t.candidates=ka(t.trigger.query).slice(0,12):t.trigger.kind==="file"?t.candidates=wa(t.trigger.query).slice(0,12):t.candidates=ns(t.trigger.command,t.trigger.query),t.dropdownOpen=t.candidates.length>0):(t.dropdownOpen=!1,t.candidates=[]),t.selectedIndex>=t.candidates.length&&(t.selectedIndex=Math.max(0,t.candidates.length-1)),t.viewportStart>t.selectedIndex&&(t.viewportStart=t.selectedIndex),t.selectedIndex>=t.viewportStart+e.MAX_DROPDOWN_ROWS&&(t.viewportStart=t.selectedIndex-e.MAX_DROPDOWN_ROWS+1)}renderDropdownRows(){let t=this.autocompleteState;if(!t?.dropdownOpen)return[];let n=this.stdout.columns||80;if(n<=40)return[];let r=Math.min(n-4,60),o=Math.min(t.candidates.length-t.viewportStart,e.MAX_DROPDOWN_ROWS),s=[];for(let i=0;i<o;i++){let a=t.viewportStart+i,l=t.candidates[a];if(!l)continue;let c=ba(l,a===t.selectedIndex,r,t.trigger?.kind),d=Ce(c).length,u=Math.max(0,Math.ceil(d/n)-1);s.push(c);for(let p=0;p<u;p++)s.push("")}return s}repaint(){if(!this.armed||!this.logUpdate||this.committing)return;let t=this.renderInputLine(),n=this.overlay?this.overlay.split(`
2009
- `):[],r=this.spinner?m.meta(`${Vb[this.spinner.frameIndex]} ${this.spinner.verb}...`)+i$(this.spinner.startedAt):null,o=this.spinner?.currentTip?a$(this.spinner.currentTip.text,this.stdout.columns??80):null,s=null;this.attachments.length>0?s=Sa(this.attachments):this.clipboardFailureMsg!==null&&(s=m.dim(this.clipboardFailureMsg),this.clipboardFailureMsg=null);let i=this.renderDropdownRows(),a=Math.max(1,(this.stdout.rows??24)-1),l=(r?1:0)+(o?1:0)+(s?1:0)+1+i.length,c=Math.max(0,a-l),d=n.length>c?n.slice(-c):n,u=[];u.push(...d),r&&u.push(r),o&&u.push(o),s&&u.push(s),u.push(t),u.push(...i),this.logUpdate(u.join(`
2009
+ `):[],r=this.spinner?m.meta(`${Vb[this.spinner.frameIndex]} ${this.spinner.verb}...`)+i$(this.spinner.startedAt):null,o=this.spinner?.currentTip?a$(this.spinner.currentTip.text,this.stdout.columns??80):null,s=null;this.attachments.length>0?s=Sa(this.attachments):this.clipboardFailureMsg!==null&&(s=m.dim(this.clipboardFailureMsg),this.clipboardFailureMsg=null);let i=this.renderDropdownRows(),a=!!r||!!o||!!s,c=a||n.length>0?1:0,d=Math.max(1,(this.stdout.rows??24)-1),u=(r?1:0)+(o?1:0)+(s?1:0)+c+1+i.length,p=Math.max(0,d-u),f=n.length>p?n.slice(-p):n,g=a||f.length>0,h=[];h.push(...f),r&&h.push(r),o&&h.push(o),s&&h.push(s),g&&h.push(""),h.push(t),h.push(...i),this.logUpdate(h.join(`
2010
2010
  `))}resetState(){this.overlay="",this.input=G.seed(""),this.queued=!1,this.canceled=!1,this.backgrounded=!1,this.attachments=[],this.pasting=!1,this.pasteStartBufferLen=0,this.clipboardFailureMsg=null,this.autocompleteState?.reset(),this.resizeUnsub&&(this.resizeUnsub(),this.resizeUnsub=null)}applyEdit(t){return t===this.input?!1:(this.input=t,this.queued=!1,this.updateAutocomplete(),this.pasting||this.repaint(),!0)}applyDropdownSelection(){let t=this.autocompleteState;if(!t?.dropdownOpen||t.candidates.length===0)return!1;let n=t.candidates[t.selectedIndex];if(!n)return!1;let r=this.input.buffer.slice(0,this.input.cursor),o=this.input.buffer.slice(this.input.cursor),s,i;if(t.trigger?.kind==="slash"){let l=/\/[A-Za-z_-]*$/.exec(r);s=l?r.length-l[0].length:this.input.cursor,i=n.value+(o.startsWith(" ")?"":" ")}else if(t.trigger?.kind==="flag"){let l=/--[a-z0-9-]*$/.exec(r);s=l?r.length-l[0].length:this.input.cursor,i=n.value+(o.startsWith(" ")?"":" ")}else{let l=r.search(/[^\s]*$/);s=l>=0?l:this.input.cursor,i=n.value}let a=G.replaceRange(this.input,{start:s,end:this.input.cursor},i);return a===this.input?!1:(this.input=a,t.dropdownOpen=!1,t.candidates=[],t.viewportStart=0,t.selectedIndex=0,this.queued=!1,this.updateAutocomplete(),this.repaint(),!0)}dispatchKey(t,n){if(!this.armed)return;let r=this.autocompleteState,o=n?.sequence??"";if(o==="\x1B[200~"){this.pasting=!0,this.pasteStartBufferLen=this.input.buffer.length;return}if(o==="\x1B[201~"){this.pasting=!1;let a=l=>{this.clipboardInFlight||(this.clipboardInFlight=!0,Qn().then(c=>{c?(this.clipboardFailureMsg=null,this.attachments.push(c),this.repaint()):l==="flag-missing"&&(this.clipboardFailureMsg="[clipboard: no image found]",this.repaint())}).catch(()=>{}).finally(()=>{this.clipboardInFlight=!1}))};this.input.buffer.length===this.pasteStartBufferLen?a("flag-missing"):(this.repaint(),a("silent"));return}if(n?.name==="escape"){if(r?.dropdownOpen){r.suppressedSignature=`${this.input.cursor}:${this.input.buffer}`,r.dropdownOpen=!1,r.candidates=[],this.repaint();return}if(this.inputMode==="idle"||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?.ctrl&&n?.name==="c"){if(this.inputMode==="idle"){this.onCancel&&this.onCancel();return}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?.ctrl&&n?.name==="v"){this.clipboardInFlight||(this.clipboardInFlight=!0,Qn().then(a=>{a?(this.clipboardFailureMsg=null,this.attachments.push(a)):this.clipboardFailureMsg="[clipboard: no image found]",this.repaint()}).catch(()=>{}).finally(()=>{this.clipboardInFlight=!1}));return}if(n?.ctrl&&n?.name==="p"||n?.name==="up"){if(r?.dropdownOpen){r.selectedIndex>0&&(r.selectedIndex--,r.selectedIndex<r.viewportStart&&(r.viewportStart=r.selectedIndex),this.repaint());return}if(this.history){let a=this.history.back(this.input.buffer);a!==null&&this.applyEdit(G.seed(a))}return}if(n?.ctrl&&n?.name==="n"||n?.name==="down"){if(r?.dropdownOpen){r.selectedIndex<r.candidates.length-1&&(r.selectedIndex++,r.selectedIndex>=r.viewportStart+e.MAX_DROPDOWN_ROWS&&(r.viewportStart=r.selectedIndex-e.MAX_DROPDOWN_ROWS+1),this.repaint());return}if(this.history){let a=this.history.forward();a!==null&&this.applyEdit(G.seed(a))}return}if(n?.name==="return"){let a=n?.shift===!0||o==="\x1B[13;2u",l=n?.meta===!0;if(a||l){this.history?.resetRecall(),this.applyEdit(G.insert(this.input,`
2011
2011
  `));return}if(this.pasting){this.input=G.insert(this.input,`
2012
2012
  `),this.queued=!1;return}let c=this.autocompleteState;if(c?.dropdownOpen){let d=c.trigger?.kind,u=this.applyDropdownSelection();if(d!=="slash"||!u)return}if(this.input.buffer.length===0&&this.attachments.length===0)return;if(this.inputMode==="idle"&&this.onSubmit){let d=this.input.buffer,u=[...this.attachments],p=this.onSubmit;this.queued=!1,this.input=G.seed(""),this.attachments=[],this.autocompleteState?.reset(),this.repaint(),p({text:d,attachments:u});return}this.queued||(this.queued=!0,this.repaint());return}if(n?.name==="backspace"){let a=G.backspace(this.input);a!==this.input?(this.history?.resetRecall(),this.applyEdit(a)):this.queued?(this.queued=!1,this.repaint()):this.attachments.length>0&&(this.attachments.pop(),this.repaint());return}if(n?.name==="left"){this.applyEdit(G.moveLeft(this.input));return}if(n?.name==="right"){this.applyEdit(G.moveRight(this.input));return}if(n?.name==="home"){this.applyEdit(G.moveHome(this.input));return}if(n?.name==="end"){this.applyEdit(G.moveEnd(this.input));return}if(n?.name==="delete"){this.history?.resetRecall(),this.applyEdit(G.deleteForward(this.input));return}if(n?.ctrl&&n?.name==="b"){if(this.inputMode==="idle"||this.backgrounded)return;this.backgrounded=!0,this.onBackground&&this.onBackground();return}if(n?.name==="tab"&&n?.shift){this.onShiftTab&&this.onShiftTab();return}if(n?.name==="tab"){this.applyDropdownSelection();return}let s=["tab","pageup","pagedown"];if(n?.name&&s.includes(n.name)||n?.ctrl||n?.meta)return;let i=typeof t=="string"&&t.length===1&&t>=" "?t:typeof n?.sequence=="string"&&n.sequence.length===1&&n.sequence>=" "?n.sequence:null;i!==null&&(this.history?.resetRecall(),this.applyEdit(G.insert(this.input,i)))}};import l$ from"chalk";var c$=/(?<=\s|^)(\/[A-Za-z][\w:-]*)(?=\s|$)/g,d$=/(?<=\s|^)(@[\w./-]*)(?=\s|$)/g;function Zn(e,t){return l$.level===0?e:e.replace(c$,r=>{let o=r.slice(1);return t.has(o)?m.brand(r):m.meta(r)}).replace(d$,r=>m.fileRef(r))}K();var u$=m.success("\u2713"),p$=m.error("\u2717");function qr(e){return e?p$:u$}var va=3,Yb=2,Xb=3;function Qb(e){switch(Kn(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 Ta(e){return e.replace(/\/(?:[^/\s,)]+\/){2,}([^/\s,)]+)/g,"$1")}function m$(e){let t=/^(\s*[("]?\s*)cd\s+\S+\s+&&\s+(?!cd\s)(.+)$/.exec(e);return t?(t[1]??"")+(t[2]??""):e}function f$(e,t){if(e==="bash"||e==="Bash")return m$(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 g$(e){return e.replace(/[\r\n]+/g," ")}var h$={"(":")","{":"}","[":"]"};function y$(e,t,n="\u2026"){let r=e.charAt(0),o=h$[r];return!(o&&e.endsWith(o)&&e.length>=2)||z(e)<=t?ce(e,t,n):t<3?t>=2?r+o:ce(e,t,n):ce(e,t-1,n)+o}function vn(e,t){let n=/^([A-Za-z_][A-Za-z0-9_]*)(.*)$/s.exec(e);if(n){let r=n[1],o=Ta(f$(r,n[2]??"")),s=Kn(r),{color:i,glyph:a}=Lr(r),l=fd(s),c=l?` [${l}]`:"";if(t!==void 0){let u=(a+" ").length+r.length+c.length,p=Math.max(1,t-u);o=y$(o,p)}o=g$(o);let d=i(a+" ")+i.bold(r)+m.toolArg(o);return l?d+m.dim(c):d}return m.chrome("\u25CF ")+m.toolArg(e)}function b$(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 er(e,t,n=60,r){let o=e.isError?m.error:m.dim,s=t??E.HOME??"___NOHOME___";if(e.display!==void 0&&!e.isError)return o(e.display);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} ${b$(r,e.lineCount)}`);let i=e.content.length>n?e.content.slice(0,n-3)+"\u2026":e.content;return o(kt(i))}var k$=8,Wd=30;function w$(){let e=E.AFK_DIFF_LINES;if(e===void 0)return Wd;let t=e.trim();if(!/^\d+$/.test(t))return Wd;let n=Number.parseInt(t,10);return Number.isFinite(n)?n:Wd}function S$(){let e=E.AFK_SHOW_DIFFS;if(e===void 0)return!1;let t=e.trim().toLowerCase();return t==="0"||t==="false"||t==="no"||t==="off"}function v$(e){let t=m.diffAdd(`+${e.addedLines}`),n=m.diffRemove(`-${e.removedLines}`),r=e.hunks.length,o=m.dim(`across ${r} hunk${r===1?"":"s"}`);return`${t} ${n} ${o}`}var T$=/[\x00-\x08\x0B-\x1F\x7F-\x9F]/g,Zb=/[\x00-\x1F\x7F-\x9F]/g;function kt(e){return Ce(e).replace(Zb," ").replace(/ {2,}/g," ").trim()}function ek(e){return Ce(e).replace(Zb," ")}function E$(e){let t=Ce(e.text).replace(T$,"");return e.kind==="+"?m.diffAdd("+ "+t):e.kind==="-"?m.diffRemove("- "+t):m.dim(" "+t)}var Kd=new WeakMap;function tr(e,t,n){if(S$())return[];if(e.hunks.length===0)return[];let r=t==="overlay"?k$:w$(),o=t+"|"+n+"|"+r,s=Kd.get(e);if(s!==void 0){let f=s.get(o);if(f!==void 0)return f}let i=[];i.push(n+v$(e));let a=[];for(let f of e.hunks){let g=`@@ -${f.oldStart},${f.oldLines} +${f.newStart},${f.newLines} @@`;a.push({kind:"header",text:m.diffHunk(g)});for(let h of f.lines)a.push({kind:"body",text:E$(h)})}if(r===0){for(let f of a)i.push(n+f.text);return Hd(e,o,i),i}let l=0;for(let f of a)f.kind==="body"&&l++;if(l<=r){for(let f of a)i.push(n+f.text);return Hd(e,o,i),i}let c=0;for(let f of a)f.kind==="header"?i.push(n+f.text):c<r&&(i.push(n+f.text),c++);let d=l-r,u=`line${d===1?"":"s"}`,p=t==="flush"?" (set AFK_DIFF_LINES=0 to expand)":"";return i.push(n+m.dim(`\u2026 +${d} more diff ${u}${p}`)),Hd(e,o,i),i}function Hd(e,t,n){let r=Kd.get(e);r===void 0&&(r=new Map,Kd.set(e,r)),r.set(t,n)}K();function _e(e,t){return ce(e,t)}var Gd=Object.freeze({spine:"\u2502 ",spineClosed:" ",lead:" ",turnRoot:"\u25C9 ",midConnector:"\u251C\u2500 ",lastConnector:"\u2570\u2500 ",textPrefix:"\u2502 "}),x$=Object.freeze({spine:"| ",spineClosed:" ",lead:" ",turnRoot:"o ",midConnector:"+- ",lastConnector:"\\- ",textPrefix:"| "});function Tn(){let e=E.AGENT_AFK_ASCII;return e&&/^(1|true|yes)$/i.test(e)?x$:Gd}function Ea(e,t){let n="";for(let r of e)n+=r?t.spineClosed:t.spine;return n+=t.spine,n}function zd(e,t){let n="";for(let r=0;r<e.length;r+=2){let o=e.slice(r,r+2);n+=o===t.spine?m.dim(o):o}return n}function rk(e,t,n){if(!e||!e.trim())return[];let r=m.dim(n.textPrefix),o=Math.max(1,ne()-t.length-2-2),s=zd(t,n),i=[];for(let a of e.split(`
@@ -2123,7 +2123,7 @@ _ended: ${new Date().toISOString()}_
2123
2123
  `)}function lF(e){let t=[],n=(r,o)=>{o&&o.trim().length>0&&t.push({label:r,value:o.trim()})};switch(e.kind){case"done":n("done",e.whatWasDone),n("evidence",e.evidence),n("deferred",e.deferred);break;case"blocked":n("blocks",e.whatBlocks),n("unblock",e.unblockCondition),n("progress",e.alreadyDone);break;case"asking":n("question",e.question),n("resolves",e.assumption),n("after",e.followup);break;case"interrupted":n("was doing",e.whatWasInProgress),n("saved at",e.stateLocation),n("resume",e.resumeRequires);break}return t}function tS(e,t,n){let r=[];n&&n.trim().length>0&&r.push({type:"text",text:n}),e&&r.push({type:"text",text:e});for(let o of t)r.push({type:"image",source:{type:"base64",media_type:o.mediaType,data:o.bytes.toString("base64")}});return r}async function nS(e,t,n,r,o="summary",s,i,a){let l=Kb(e.text,e.attachments);r.setInFlight(!0);let c="",d=!1,u=!1,p=!1,f=!1,g,h=!1,b=[],y=new Map,k=e.text.startsWith("/")?e.text.split(/[\s:]/)[0]?.slice(1):void 0,T=r.getCompositor?r.getCompositor():null,x=()=>new Vr({out:Xr(s),thinkingMode:o,...k?{activeSkillName:k}:{},onCancel:()=>{t.interrupt().catch(A=>{ze()&&console.error(" "+m.error("session.interrupt() failed:"),A)})},...i?{onBackground:()=>{h=!0}}:{},...a?.history?{history:a.history}:{},...a?.autocompleteState?{autocompleteState:a.autocompleteState}:{},...a?.promptText!==void 0?{promptText:a.promptText}:{},...r.scrollRegion?{scrollRegion:r.scrollRegion}:{},...T?{compositor:T}:{}}),S=x(),v=async()=>{if(!p){p=!0;try{await S.dispose()}catch{}}},R=async()=>{await S.arm();let A=S.getCompositor();if(s&&A){let O=A;s.fn=C=>O.commitAbove(C)}r.setActiveCompositor?.(A),r.rearmStatus?.()};try{T?T.commitAbove(""):console.log(),await R(),i&&r.setBackgroundHandler&&r.setBackgroundHandler(()=>{h=!0});let A=e.attachments.length===0?e.text:tS(e.text,e.attachments),O=t.sendMessageStream(A);if(await on((I,P)=>{S.process(I,P)},async()=>{for await(let I of O){if(h&&i){let P=k??e.text.slice(0,40),D=i.register(P),F=la(D,i);ca(O,c,l,D,i,F,n,r.onTurnComplete,t.abortSignal),await v(),(s??{fn:console.log}).fn(m.dim(` \u2192 backgrounded as ${D.id}: ${D.label}`)),r.setInFlight(!1),r.rearmStatus?.();return}if(I.type==="chunk"&&I.chunk.type==="content"?(c+=I.chunk.content,d=!0):I.type==="message"&&!d&&(c=I.message.content),I.type==="chunk"&&I.chunk.type==="tool_use_detail"){let P=I.chunk,D={toolName:P.toolName,toolUseId:P.toolUseId,input:P.toolInput};y.set(P.toolUseId,D),b.push(D)}else if(I.type==="chunk"&&I.chunk.type==="tool_result"){let P=I.chunk,D=y.get(P.toolUseId);D&&(D.result=P.content,D.isError=P.isError,y.delete(P.toolUseId))}if(I.type==="paused"){await v(),(s??{fn:console.log}).fn(fm({reason:I.reason,...I.resetsAt!==void 0?{resetsAt:I.resetsAt}:{},...I.accountId!==void 0?{accountId:I.accountId}:{},...I.autoResume!==void 0?{autoResume:I.autoResume}:{}}));continue}if(I.type==="resumed"){let P=I.hotSwapped&&I.accountId?`\u25B6 Resumed on ${I.accountId}`:"\u25B6 Resumed";c="",d=!1,b.length=0,y.clear(),f=!1,g=void 0,u=!1,h=!1,S=x(),p=!1,await R(),(s??{fn:console.log}).fn(m.success(P));continue}if(I.type==="error"){await v(),yr(hr(I.error)),u=!0;continue}S.process(I),I.type==="done"&&(f=!0,g=I.metadata)}}),await v(),f){Gn(n,l,c,g,b),r.onTurnComplete&&await r.onTurnComplete(l,c).catch(()=>{});let I=D=>{s?s.fn(D):console.log(D)};(d||b.length>0)&&I(`
2124
2124
  `);let P=Zw(c);if(P&&(I(eS(P)),I(""),r.onTerminalState))try{r.onTerminalState(P)}catch{}if(cF(g,n,I),r.onAfterTurn){let D=r.onAfterTurn();D instanceof Promise&&await D.catch(()=>{})}}}catch(A){await v(),u||yr(hr(A))}finally{await v(),s&&(s.fn=A=>console.log(A)),r.setActiveCompositor?.(null),r.setBackgroundHandler?.(null),r.setInFlight(!1),r.rearmStatus?.()}}function cF(e,t,n=console.log){if(!e)return;let r=[];e.durationMs&&r.push(ie(e.durationMs)),e.totalCostUsd!==void 0&&r.push(je(e.totalCostUsd));let o=Number(e.usage?.input_tokens??0),s=Number(e.usage?.output_tokens??0);o+s>0&&r.push(Z(o+s)+" tok"),r.length>0&&n(m.dim(" \u25E6 "+r.join(" \xB7 ")));let i=vd(t),a=et(t.model);if(i>=1){let l=Math.round((i-1)*a),c=Math.round(a/1e3);console.log(m.error(` context OVER ${c}k tok by ~${Z(l)} tok \u2014 model output may be silently truncated`))}else if(i>.5){let l=i>.8?m.error:m.warning;n(l(` context ${Math.round(i*100)}% used of ${Z(a)}`))}n("")}function rS(e={}){let t=e.load??sa,n=e.onResize??(i=>Ge.subscribe(i)),r="",o,s=n(()=>{r=""});return{renderIfChanged(i){let a=i??"unbound",l=t(a),c=ab(l);return a===o&&c===r?[]:(o=a,r=c,c===""?[]:ia(l))},invalidate(){r=""},dispose(){try{s()}catch{}}}}var Ru={done:{glyph:"\u2713",color:m.success,label:"done"},blocked:{glyph:"\u2298",color:m.error,label:"blocked"},asking:{glyph:"?",color:m.warning,label:"asking"},interrupted:{glyph:"\u23F8",color:m.meta,label:"interrupted"}};function oS(e={}){let t=Math.max(2,e.capacity??8),n=[];return{push(r){n.push(r.kind),n.length>t&&(n=n.slice(n.length-t))},reset(){n=[]},entries(){return n},render(){if(n.length===0)return null;let r=m.dim(" ledger "),o=m.dim(" \xB7 "),s=n.map(d=>{let u=Ru[d];return u.color(`${u.glyph} ${u.label}`)}),i=m.dim(` (${n.length} turn${n.length===1?"":"s"})`),a=r+s.join(o)+i,l=Math.max(20,ne()-2);if(z(a)<=l)return a;let c=r+n.map(d=>Ru[d].color(Ru[d].glyph)).join(m.dim(" "))+i;return ce(c,l)}}}var Cu=["\u25D0","\u25D1","\u25D2","\u25D3"],ul=class{stream;manager;registry;throttleMs;started=!1;lastRepaint=0;spinnerIndex=0;spinnerInterval=null;resizeUnsub=null;updateHandler=null;registryStartedHandler=null;registrySettledHandler=null;rowCount=0;onRowCountChange;constructor(t,n,r={}){this.manager=t,this.registry=n,this.stream=r.stream??process.stdout,this.throttleMs=r.throttleMs??200}setRowCountChangeHandler(t){this.onRowCountChange=t}start(){this.started||(this.started=!0,this.updateHandler=()=>this.scheduleRepaint(),this.manager.on("update",this.updateHandler),this.manager.on("complete",this.updateHandler),this.registry&&(this.registryStartedHandler=t=>{this.scheduleRepaint()},this.registrySettledHandler=t=>{this.scheduleRepaint()},this.registry.on("started",this.registryStartedHandler),this.registry.on("settled",this.registrySettledHandler)),this.resizeUnsub=Ge.subscribe(()=>this.repaint()),this.spinnerInterval=setInterval(()=>{this.spinnerIndex=(this.spinnerIndex+1)%Cu.length,this.rowCount>0&&this.repaint()},Math.max(this.throttleMs,50)))}stop(){this.started&&(this.started=!1,this.updateHandler&&(this.manager.removeListener("update",this.updateHandler),this.manager.removeListener("complete",this.updateHandler),this.updateHandler=null),this.registry&&(this.registryStartedHandler&&(this.registry.off("started",this.registryStartedHandler),this.registryStartedHandler=null),this.registrySettledHandler&&(this.registry.off("settled",this.registrySettledHandler),this.registrySettledHandler=null)),this.resizeUnsub&&(this.resizeUnsub(),this.resizeUnsub=null),this.spinnerInterval&&(clearInterval(this.spinnerInterval),this.spinnerInterval=null),this.rowCount>0&&(this.clearRows(),this.rowCount=0,this.onRowCountChange?.(0)))}scheduleRepaint(){Date.now()-this.lastRepaint<this.throttleMs||this.repaint()}repaint(){if(!this.started||!this.stream.isTTY)return;this.lastRepaint=Date.now();let t=[...this.manager.running().map(s=>({kind:"turn",task:s})),...(this.registry?.list()??[]).filter(s=>s.status==="running").map(s=>({kind:"subagent",job:s}))],n=this.stream.rows??24,r=Math.max(0,Math.min(t.length,n-1));if(r!==this.rowCount&&(this.rowCount>0&&this.clearRows(),this.rowCount=r,this.onRowCountChange?.(r)),r===0)return;let o=Math.max(1,n-r);this.stream.write("\x1B[s");for(let s=0;s<r;s++){let i=t[s],a=o+s;this.stream.write(`\x1B[${a};1H`),this.stream.write("\x1B[2K"),this.stream.write(this.formatItemLine(i))}this.stream.write("\x1B[u")}clearRows(){if(!this.stream.isTTY)return;let t=this.stream.rows??24,n=Math.min(this.rowCount,t-1),r=Math.max(1,t-n);this.stream.write("\x1B[s");for(let o=0;o<n;o++)this.stream.write(`\x1B[${r+o};1H`),this.stream.write("\x1B[2K");this.stream.write("\x1B[u")}formatItemLine(t){return t.kind==="turn"?this.formatTaskLine(t.task):this.formatJobLine(t.job)}formatTaskLine(t){let n=Math.max(4,(this.stream.columns??80)-2),r=m.brand(Cu[this.spinnerIndex]),o=m.dim(t.id),s=m.bold(t.label),i=[r,o,s];t.progressDescription&&i.push(m.dim(t.progressDescription));let a=[];t.stats.toolUses>0&&a.push(`${t.stats.toolUses} tool${t.stats.toolUses===1?"":"s"}`),t.stats.tokens>0&&a.push(`${Z(t.stats.tokens)} tok`);let l=Date.now()-t.startedAt;return a.push(ie(l)),a.length>0&&i.push(m.dim(a.join(" \xB7 "))),ce(" "+i.join(" "),n)}formatJobLine(t){let n=Math.max(4,(this.stream.columns??80)-2),r=m.brand(Cu[this.spinnerIndex]),o=m.dim(t.jobId),s=m.bold(t.label||t.jobId),i=[r,o,s],a=Date.now()-t.startedAt;return i.push(m.dim(ie(a))),ce(" "+i.join(" "),n)}};function pl(e,t){let n=m.brand("afk")+m.dim(` (${e})`),r=t?m.warning(" \u25CF plan"):"";return n+r+m.dim(" \u203A ")}async function sS(e,t,n,r){let o=null,s=[];e.session.current.waitForInitialization().then(async p=>{ze()&&(o=ta(p)),await Fa(e.session.current),ze()&&(s=Xk())}).catch(()=>{});let i=await Jw(),a=new dl({rl:e.rl,history:i,statusLine:e.statusLine}),l,c,d,u;try{await a.armCompositor({promptFn:()=>pl(e.stats.model,e.stats.planMode),onCancel:r,onShiftTab:()=>{let h=e.slashCtx;h.stats.planMode&&h.stats.pendingPlanExit?(h.stats.pendingPlanExit=!1,bt(h,!1,{closureSummarySkipped:!0}).catch(()=>{})):bt(h).catch(()=>{}),e.statusLine.rearm()},scrollRegion:e.statusLine}),e.replRenderer.setCompositor(a.getCompositor()),e.slashCtx.getCompositor=()=>a.getCompositor(),c=rS();let p=oS();e.clearVerdictLedger=()=>p.reset(),d=new aa,bb(d),Eb(d),Rb(d),xb(e.backgroundRegistry),u=new ul(d,e.backgroundRegistry),u.setRowCountChangeHandler(h=>{e.statusLine.setExtraRows(h)}),u.start();let f=50,g=[];for(d.on("complete",h=>{g.length>=f&&g.shift(),g.push(h)});;){if(o&&(e.replRenderer.writeLine(o),e.replRenderer.writeLine(""),o=null),s.length>0){for(let v of s)e.replRenderer.writeLine(v);e.replRenderer.writeLine(""),s=[]}for(;g.length>0;){let v=g.shift(),R=v.status==="succeeded"?"\u2713":"\u2717",A=[];if(v.resultText){let C=v.resultText.trim().split(`
2125
2125
  `)[0]?.slice(0,80)??"";C&&A.push(C)}v.error&&A.push(v.error.message);let O=[v.stats.toolUses>0?`${v.stats.toolUses} tools`:"",v.stats.tokens>0?`${Math.round(v.stats.tokens/1e3)}k tok`:"",v.stats.durationMs>0?`${Math.round(v.stats.durationMs/1e3)}s`:""].filter(Boolean).join(" \xB7 ");O&&A.push(O),e.replRenderer.writeLine(en({kind:v.status==="succeeded"?"checkpoint":"diagnosis",title:`${R} ${v.id} ${v.label}`,body:A})),e.replRenderer.writeLine("")}let h=c.renderIfChanged(e.stats.sessionId);if(h.length>0){for(let v of h)e.replRenderer.writeLine(v);e.replRenderer.writeLine("")}let b=p.render();b&&e.replRenderer.writeLine(b);let y,k;if(l!==void 0){let v=l;l=void 0;let R=pl(e.stats.model,e.stats.planMode),A=Jn({buffer:v.text,promptText:R,isTTY:!!process.stdout.isTTY,attachmentSummary:Gr([...v.attachments])});e.replRenderer.writeLine(A),y=v.text.trim(),k=v.attachments}else{let v=await a.readLine({promptFn:()=>pl(e.stats.model,e.stats.planMode),onSigint:r,onShiftTab:()=>{let R=e.slashCtx;R.stats.planMode&&R.stats.pendingPlanExit?(R.stats.pendingPlanExit=!1,bt(R,!1,{closureSummarySkipped:!0}).catch(()=>{})):bt(R).catch(()=>{}),e.statusLine.rearm()}});y=v.text.trim(),k=v.attachments}if(!y&&k.length===0)continue;let T=!1;if(y.startsWith("/")){let v=await jy(y,e.slashCtx,k);if(v.handled){if(v.result==="exit"){e.rl.close();return}if((y==="/clear"||y.startsWith("/clear "))&&(await t.rotateOnClear(),e.replRenderer.writeLine(m.dim(` transcript: ${t.path()}`)),p.reset()),v.result!==null&&typeof v.result=="object"&&"kind"in v.result&&v.result.kind==="submit"){l={text:v.result.message,attachments:k??[]},e.statusLine.rearm();continue}e.statusLine.rearm();continue}T=!0}i.push(y);let x=y;if(T){let v=Sd(y);if(v){let R=v.name.replace(/^\//,"").split(":").pop()??"";if(R&&ru(R)){let A={skillName:R,rawArgs:v.args,source:"plugin",capabilities:{compose:!0,subagents:!0}},O=e.session.current.sessionId,C=as(O),I=Date.now();H(`[afk trace] preflight.start commandName=${R}`);let P=!1,D=await is(A,{cwd:e.stats.cwd??process.cwd(),artifactDir:C},F=>{ze()&&e.replRenderer.writeLine(m.warning(`\u26A0 preflight(${R}) failed: `)+(F instanceof Error?F.message:String(F)))});P=D!==null,H(`[afk trace] preflight.end commandName=${R} durationMs=${Date.now()-I} success=${P}`),x=iu(D?.manifestBlock,y)}}}let S;if(e.firstTurnHook&&e.stats.totalTurns===0){let v=e.firstTurnHook;e.firstTurnHook=void 0,S=Promise.resolve().then(()=>v(y)).catch(R=>{e.completionWriter.fn(m.warning("\u26A0 ")+"first-turn hook failed: "+(R instanceof Error?R.message:String(R)))})}await nS({text:x,attachments:k},e.session.current,e.stats,{setInFlight(v){n.turnInFlight=v},async onTurnComplete(v,R){await t.appendTurn(v,R)},async onAfterTurn(){await e.contextSampler.onTurn(e.stats.totalTurns),await Qy(e.slashCtx),e.statusLine.rearm()},rearmStatus:()=>e.statusLine.rearm(),onTerminalState:v=>p.push(v),setActiveCompositor:v=>{n.activeCompositor=v},scrollRegion:e.statusLine,getCompositor:()=>a.getCompositor(),setBackgroundHandler:v=>a.setBackgroundHandler(v)},e.options.thinkingUi,e.completionWriter,d,a.toRunTurnRefs(pl(e.stats.model,e.stats.planMode))),S!==void 0&&await S}}finally{if(d!==void 0)for(let p of d.running())d.cancel(p.id);u?.stop(),c?.dispose(),await a.dispose()}}import{execFile as dF}from"node:child_process";import{dirname as uF,isAbsolute as pF,resolve as mF}from"node:path";import{promisify as fF}from"node:util";var iS=fF(dF),gF=3e3,hF=new Set(["empty","orphaned-dir","orphaned-registration","dead-owner"]);async function yF(){let t=(await iS("git",["rev-parse","--git-common-dir"])).stdout.trim();if(!t)throw new Error("Not in a git repository.");let n=pF(t)?t:mF(process.cwd(),t);return uF(n)}async function aS(e){if(e?.disabled)return{ran:!1,removedCount:0,skippedReason:"disabled"};let t;try{t=await yF()}catch{return{ran:!1,removedCount:0,skippedReason:"not-in-repo"}}let n,r=new Promise(o=>{n=setTimeout(()=>o("timeout"),gF)});try{let o=Mt({execFile:iS,repoRoot:t,dryRun:!1,scope:"interactive",bypassSoftLaunch:!0}),s=await Promise.race([o,r]);if(s==="timeout")return{ran:!1,removedCount:0,skippedReason:"timeout"};let i=s;return i.warnings.some(c=>c.toLowerCase().includes("contested"))?{ran:!1,removedCount:0,skippedReason:"lock-contested"}:{ran:!0,removedCount:i.candidates.filter(c=>hF.has(c.verdict)&&i.removed.includes(c.path)).length}}catch{return{ran:!1,removedCount:0,skippedReason:"error"}}finally{n&&clearTimeout(n)}}import{promises as bF}from"node:fs";import{dirname as kF,join as wF}from"node:path";import{randomBytes as SF}from"node:crypto";var vF=["Generate a 2-4 word kebab-case slug describing this work request.","Rules:","- ASCII lowercase letters and digits only, separated by single hyphens","- 2 to 4 hyphen-separated words","- Maximum 30 characters total","- No prefix, no quotes, no punctuation other than hyphens","- Output ONLY the slug \u2014 no explanation, no preamble","Examples: fix-cleanup-race, add-telegram-allowlist, refactor-prompt-loader, debug-flaky-test"].join(`
2126
- `),lS=/^[a-z0-9]+(-[a-z0-9]+){1,3}$/,_u=30,TF=1024,EF=8e3,xF="haiku";async function AF(e,t){let n=e.trim();if(n.length===0)return t.onSkip?.("empty-message"),null;if(n.startsWith("/"))return t.onSkip?.("slash-command"),null;let r=IF(n,TF),o=new AbortController,s=setTimeout(()=>o.abort(),t.timeoutMs??EF),i=t.signal?PF([t.signal,o.signal]):o.signal,a;try{t.slugGenerator?a=await t.slugGenerator(r,i):a=await el({token:t.token,model:t.model??xF,system:vF,user:r,maxTokens:32,signal:i})}catch(u){let p=u instanceof Error?u.message:String(u);return t.onSkip?.("slug-generator-error",p.slice(0,200)),null}finally{clearTimeout(s)}let l=RF(a);if(l===null)return t.onSkip?.("invalid-slug-output",a.slice(0,60)),null;let c=kF(t.worktreePath);return await CF(l,c)}function RF(e){let t=e.trim().toLowerCase();if(t.length===0)return null;if(lS.test(t)&&t.length<=_u)return t;let n=t.replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"");if(n.length===0)return null;let r=n.split("-").filter(s=>s.length>0).slice(0,4);if(r.length<2)return null;let o=r[0];for(let s=1;s<r.length;s++){let i=`${o}-${r[s]}`;if(i.length>_u)break;o=i}return lS.test(o)?o:null}async function CF(e,t){if(!await _F(wF(t,e)))return e;let n=SF(2).toString("hex");return`${e.split("-").slice(0,3).join("-").slice(0,_u-5)}-${n}`}async function _F(e){try{return await bF.access(e),!0}catch{return!1}}function IF(e,t){let n=Buffer.from(e,"utf8");if(n.length<=t)return e;let r=t;for(;r>0&&n[r]!==void 0&&(n[r]&192)===128;)r--;return n.slice(0,r).toString("utf8")}function PF(e){let t=AbortSignal.any;if(typeof t=="function")return t.call(AbortSignal,e);let n=new AbortController;for(let r of e){if(r.aborted)return n.abort(r.reason),n.signal;r.addEventListener("abort",()=>n.abort(r.reason),{once:!0})}return n.signal}async function dS(e){let t,n,r=await AF(e.message,{token:e.token,...e.model!==void 0?{model:e.model}:{},...e.timeoutMs!==void 0?{timeoutMs:e.timeoutMs}:{},worktreePath:e.handle.path,...e.signal!==void 0?{signal:e.signal}:{},...e.slugGenerator!==void 0?{slugGenerator:e.slugGenerator}:{},onSkip:(i,a)=>{t=i,n=a}});if(r===null)return{status:"skipped",reason:t??"unknown",...n!==void 0?{detail:n}:{}};let s=await(e.renameFn??Og)(e.handle,r,e.branchPrefix!==void 0?{branchPrefix:e.branchPrefix}:void 0);return s.ok?(e.session&&e.session.setCwd(s.newPath),cS(s.newPath),{status:"renamed",oldPath:s.oldPath,newPath:s.newPath,oldBranch:s.oldBranch,newBranch:s.newBranch}):(s.partial==="branch"&&(e.session&&e.session.setCwd(e.handle.path),cS(e.handle.path)),{status:"failed",reason:s.reason,...s.partial!==void 0?{partial:s.partial}:{}})}function cS(e){try{process.chdir(e)}catch{}}N();import{spawn as uS}from"child_process";import{existsSync as LF,mkdirSync as FF,readFileSync as pS,unlinkSync as NF,writeFileSync as UF}from"fs";import{get as jF}from"https";import{join as mS}from"path";import{readFileSync as MF}from"fs";import{dirname as $F,join as OF}from"path";import{fileURLToPath as DF}from"url";function zt(){try{return"3.27.3"}catch{}try{let e=$F(DF(import.meta.url));for(let t of["../../package.json","../package.json"])try{let n=JSON.parse(MF(OF(e,t),"utf-8"));if(typeof n.version=="string")return n.version}catch{}}catch{}return"0.0.0-unknown"}K();var BF=64*1024,WF=1440*60*1e3,HF="update-check.json",KF="pending-update.json";function fS(){return mS(Ds(),HF)}function Iu(){return mS(Ds(),KF)}function gS(){let e=Ds();LF(e)||FF(e,{recursive:!0})}function GF(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 zF(){try{let e=pS(fS(),"utf-8"),t=JSON.parse(e);if(typeof t.latestVersion=="string"&&typeof t.checkedAt=="number")return t}catch{}return null}function qF(){try{gS();let e=`
2126
+ `),lS=/^[a-z0-9]+(-[a-z0-9]+){1,3}$/,_u=30,TF=1024,EF=8e3,xF="haiku";async function AF(e,t){let n=e.trim();if(n.length===0)return t.onSkip?.("empty-message"),null;if(n.startsWith("/"))return t.onSkip?.("slash-command"),null;let r=IF(n,TF),o=new AbortController,s=setTimeout(()=>o.abort(),t.timeoutMs??EF),i=t.signal?PF([t.signal,o.signal]):o.signal,a;try{t.slugGenerator?a=await t.slugGenerator(r,i):a=await el({token:t.token,model:t.model??xF,system:vF,user:r,maxTokens:32,signal:i})}catch(u){let p=u instanceof Error?u.message:String(u);return t.onSkip?.("slug-generator-error",p.slice(0,200)),null}finally{clearTimeout(s)}let l=RF(a);if(l===null)return t.onSkip?.("invalid-slug-output",a.slice(0,60)),null;let c=kF(t.worktreePath);return await CF(l,c)}function RF(e){let t=e.trim().toLowerCase();if(t.length===0)return null;if(lS.test(t)&&t.length<=_u)return t;let n=t.replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"");if(n.length===0)return null;let r=n.split("-").filter(s=>s.length>0).slice(0,4);if(r.length<2)return null;let o=r[0];for(let s=1;s<r.length;s++){let i=`${o}-${r[s]}`;if(i.length>_u)break;o=i}return lS.test(o)?o:null}async function CF(e,t){if(!await _F(wF(t,e)))return e;let n=SF(2).toString("hex");return`${e.split("-").slice(0,3).join("-").slice(0,_u-5)}-${n}`}async function _F(e){try{return await bF.access(e),!0}catch{return!1}}function IF(e,t){let n=Buffer.from(e,"utf8");if(n.length<=t)return e;let r=t;for(;r>0&&n[r]!==void 0&&(n[r]&192)===128;)r--;return n.slice(0,r).toString("utf8")}function PF(e){let t=AbortSignal.any;if(typeof t=="function")return t.call(AbortSignal,e);let n=new AbortController;for(let r of e){if(r.aborted)return n.abort(r.reason),n.signal;r.addEventListener("abort",()=>n.abort(r.reason),{once:!0})}return n.signal}async function dS(e){let t,n,r=await AF(e.message,{token:e.token,...e.model!==void 0?{model:e.model}:{},...e.timeoutMs!==void 0?{timeoutMs:e.timeoutMs}:{},worktreePath:e.handle.path,...e.signal!==void 0?{signal:e.signal}:{},...e.slugGenerator!==void 0?{slugGenerator:e.slugGenerator}:{},onSkip:(i,a)=>{t=i,n=a}});if(r===null)return{status:"skipped",reason:t??"unknown",...n!==void 0?{detail:n}:{}};let s=await(e.renameFn??Og)(e.handle,r,e.branchPrefix!==void 0?{branchPrefix:e.branchPrefix}:void 0);return s.ok?(e.session&&e.session.setCwd(s.newPath),cS(s.newPath),{status:"renamed",oldPath:s.oldPath,newPath:s.newPath,oldBranch:s.oldBranch,newBranch:s.newBranch}):(s.partial==="branch"&&(e.session&&e.session.setCwd(e.handle.path),cS(e.handle.path)),{status:"failed",reason:s.reason,...s.partial!==void 0?{partial:s.partial}:{}})}function cS(e){try{process.chdir(e)}catch{}}N();import{spawn as uS}from"child_process";import{existsSync as LF,mkdirSync as FF,readFileSync as pS,unlinkSync as NF,writeFileSync as UF}from"fs";import{get as jF}from"https";import{join as mS}from"path";import{readFileSync as MF}from"fs";import{dirname as $F,join as OF}from"path";import{fileURLToPath as DF}from"url";function zt(){try{return"3.27.4"}catch{}try{let e=$F(DF(import.meta.url));for(let t of["../../package.json","../package.json"])try{let n=JSON.parse(MF(OF(e,t),"utf-8"));if(typeof n.version=="string")return n.version}catch{}}catch{}return"0.0.0-unknown"}K();var BF=64*1024,WF=1440*60*1e3,HF="update-check.json",KF="pending-update.json";function fS(){return mS(Ds(),HF)}function Iu(){return mS(Ds(),KF)}function gS(){let e=Ds();LF(e)||FF(e,{recursive:!0})}function GF(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 zF(){try{let e=pS(fS(),"utf-8"),t=JSON.parse(e);if(typeof t.latestVersion=="string"&&typeof t.checkedAt=="number")return t}catch{}return null}function qF(){try{gS();let e=`
2127
2127
  const https = require('https');
2128
2128
  const fs = require('fs');
2129
2129
  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": "3.27.3",
3
+ "version": "3.27.4",
4
4
  "description": "CLI tool for interacting with AI agents via multiple interfaces",
5
5
  "main": "dist/index.mjs",
6
6
  "type": "module",