bostrat-node 1.10.6 → 1.10.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/index.js +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -165,11 +165,11 @@ enumerable options.
|
|
|
165
165
|
`),o=fh(r);if(!o)return null;let s=o.map(a=>{let[i,...c]=a.label.split("\xB7");return{label:to(i),description:c.join("\xB7").trim()}});return{provider:"claude",box:t,multiSelect:!1,cursorIndex:Math.max(0,o.findIndex(a=>a.cursor)),setup:"login-method",promptId:`claude:setup:login-method:${s.map(a=>a.label).join("|")}`.slice(0,200),questions:[{question:"How do you want to sign in to Claude? A Claude subscription (Pro/Max/Team) uses your existing plan; a Console account bills API usage. Your login stays on this box \u2014 bostrat never sees it.",header:"Log in",multiSelect:!1,options:s}]}}function _L(e,t){let n=e[t].trim();for(let r=t+1;r<e.length;r++){let o=e[r].trim();if(!o||!EL.test(o)||mh.test(e[r]))break;n+=o}return n}function IL(e,t=""){let n=String(e);if(!mh.test(n)||os.test(n))return null;let r=n.replace(/\r/g,"").split(`
|
|
166
166
|
`),o="";for(let s=0;s<r.length;s++)if(/^\s*https:\/\//.test(r[s])){o=_L(r,s);break}return o?{provider:"claude",box:t,multiSelect:!1,cursorIndex:0,answerMode:"text",setup:"oauth",url:o,inputLabel:"Paste your sign-in code",promptId:"claude:setup:oauth",questions:[{question:"Open the sign-in link, approve access, then paste the code you're shown back here. The code goes straight to the Claude CLI on your box \u2014 bostrat relays the keystrokes and never stores it.",header:"Log in",multiSelect:!1,options:[]}]}:null}function RL(e,t=""){let n=String(e);if(!uh.test(n)||!$L.test(n)||os.test(n))return null;let s=([...n.replace(/\r/g,"").split(`
|
|
167
167
|
`)].reverse().find(a=>uh.test(a))||"OAuth error").trim();return{provider:"claude",box:t,multiSelect:!1,cursorIndex:0,setup:"oauth-error",promptId:`claude:setup:oauth-error:${s}`.slice(0,200),questions:[{question:`${s} \u2014 retry to get a fresh sign-in link.`,header:"Log in",multiSelect:!1,options:[{label:"Retry sign-in",description:"Mints a new sign-in link and code"}]}]}}function OL(e,t=""){let n=String(e);if(!Yv.test(n)||os.test(n))return null;let r=n.replace(/\r/g,"").split(`
|
|
168
|
-
`),o=fh(r);return
|
|
168
|
+
`),o=r.flatMap(a=>{let i=a.match(/^\s*(❯\s*)?(Yes, I trust this folder|No, exit)\s*$/);return i?[{cursor:!!i[1],label:i[2]}]:[]}),s=o.length===2&&new Set(o.map(a=>a.label)).size===2&&o.filter(a=>a.cursor).length===1?o:fh(r);return s?{provider:"claude",box:t,multiSelect:!1,cursorIndex:Math.max(0,s.findIndex(a=>a.cursor)),setup:"trust",promptId:`claude:setup:trust:${s.map(a=>a.label).join("|")}`.slice(0,200),questions:[{question:"Claude Code asks whether it can read, edit, and run files in this workspace. This box's workspace is bostrat-managed scratch space, so trusting it is safe.",header:"Folder trust",multiSelect:!1,options:s.map(a=>({label:to(a.label),description:""}))}]}:null}function ML(e,t=""){let n=String(e);if(os.test(n))return null;let r=n.replace(/\r/g,"").split(`
|
|
169
169
|
`),o=-1;for(let l=r.length-1;l>=0;l--)if(r[l].trim()!==""){o=l;break}if(o<0)return null;let s=r[o].match(Xv);if(!s)return null;let a=[];for(let l=o-1;l>=0&&a.length<3;l--){let u=r[l].trim();if(!u){if(a.length)break;continue}if(eo.test(r[l])||ph.test(u))break;a.unshift(u)}let i=s[1].trim();i&&a.push(i);let c=a.join(" ")||"Claude Code is waiting for you to continue.";return{provider:"claude",box:t,multiSelect:!1,cursorIndex:0,setup:"continue",promptId:`claude:setup:continue:${c}`.slice(0,200),questions:[{question:c,header:"Continue",multiSelect:!1,options:[{label:"Continue",description:""}]}]}}function CL(e){let t=-1;for(let r=e.length-1;r>=0;r--)if(dh.test(e[r])){t=r;break}if(t<0)return null;let n=-1;for(let r=t-1;r>=0;r--)if(/[☐☒]/.test(e[r])){n=r;break}return n<0?null:{headerLine:n,chatLine:t,optStart:n+1,optEnd:t}}function NL(e,t){let n=e.find(s=>/^type something\b/i.test(s.label));if(n)return n;if(e.length<2)return null;let r=e[e.length-1];if(od.test(r.label))return null;let o=null;for(let s=r.line+1;s<Math.min(t.length,r.line+3);s++){let a=t[s].replace(/^\s*❯/,"").trim();if(a){o=a;break}}return o&&(eo.test(o)||/^submit\b/i.test(o))?r:null}function PL(e,t=""){let n=String(e);if(!qv.test(n)||!dh.test(n))return null;let r=n.replace(/\r/g,"").split(`
|
|
170
170
|
`),o=CL(r);if(!o)return null;let{headerLine:s,chatLine:a,optStart:i,optEnd:c}=o,l=[],u=-1;for(let _=i;_<c;_++){let j=r[_].match(rs);j&&(u<0&&(u=_),l.push({line:_,cursor:!!j[1],checked:j[3]!=null&&j[3]!==" ",hasCheckbox:j[3]!=null,label:j[4].trim(),desc:""}))}if(!l.length)return null;for(let _ of l)for(let j=_.line+1;j<Math.min(r.length,_.line+4)&&!(rs.test(r[j])||eo.test(r[j]));j++){let G=r[j].trim();if(!(!G||hL(r[j])||od.test(G))){_.desc=mL(G);break}}let d=NL(l,r),p=l.filter(_=>_!==d&&!od.test(_.label));if(!p.length)return null;let f=p.some(_=>_.hasCheckbox),w=d?.cursor?p.length:Math.max(0,p.findIndex(_=>_.cursor)),h=d&&!od.test(d.label)?to(d.label):"",y=s>=0?s+1:0,k=[];for(let _=y;_<u;_++){let j=r[_].trim();j&&!eo.test(r[_])&&!/[☐☒]/.test(r[_])&&k.push(j)}let g=k.join(" ")||(s>=0?Wv(r[s]):"")||"The agent is asking a question",x=s>=0?wL(r[s],g):null,S=x?.currentTabLabel||(s>=0?Wv(r[s]):""),$=p.map(_=>({label:to(_.label),description:_.desc})),M=$.map(_=>_.label).join("|"),L=`claude:${x?`q${x.questionIndex+1}/${x.questionTotal}`:"q1/1"}:${S}:${g}:${M}`.slice(0,240),T=x?`claude:ask:${x.tabs.map(_=>_.label).join("|")}`.slice(0,240):L;return{provider:"claude",box:t,multiSelect:f,cursorIndex:w,promptId:L,groupId:T,...d?{custom:!0,customIndex:p.length,customText:h}:{},dismissable:!0,...x?{questionIndex:x.questionIndex,questionTotal:x.questionTotal,currentTabLabel:x.currentTabLabel,tabs:x.tabs}:{},questions:[{question:g,header:S,multiSelect:f,options:$}]}}function no(e,t){let n=String(t||"");return n?e==="claude"?qv.test(n)&&dh.test(n)||Gv.test(n)||lh.test(n)||Kv.test(n.trimEnd().split(`
|
|
171
171
|
`).pop()||"")?!0:os.test(n)?!1:Vv.test(n)&&zv.test(n)||Jv.test(n)||mh.test(n)||uh.test(n)||Yv.test(n)||Xv.test(n.trimEnd().split(`
|
|
172
|
-
`).pop()||""):e==="codex"&&/Sign in with ChatGPT|one-time code|Paste or type your API key|link to authenticate|Successfully logged in\.[\s\S]*Press Enter to continue\./i.test(n)?!0:e==="cursor"||e==="codex"?/\b(allow|approve|apply (this )?patch|run (this )?command|do you want to run|grant)\b/i.test(n):!1:!1}function Sn(e,t){return!e||!t?null:e.agent==="claude"?xL(t,e.name)||PL(t,e.name)||yL(t,e.name)||SL(t,e.name)||RL(t,e.name)||IL(t,e.name)||TL(t,e.name)||AL(t,e.name)||OL(t,e.name)||ML(t,e.name)||kL(t,e.name):e.agent==="cursor"||e.agent==="codex"?Ux(e.agent,t,e.name):null}async function Zv(e){if(!e)return null;let t=await zt(e.name).catch(()=>"");return Sn(e,t)}function hh(e,t){let n=Array.isArray(t?.[0])?t[0].filter(a=>Number.isInteger(a)&&a>=0):[],r=Number.isInteger(e?.cursorIndex)?e.cursorIndex:0,o=(a,i)=>{let c=i-a;return Array.from({length:Math.abs(c)},()=>c>0?"Down":"Up")},s=[];if(e?.multiSelect){let a=r;for(let i of[...n].sort((c,l)=>c-l))s.push(...o(a,i),"Enter"),a=i;s.push("Tab","Enter")}else{let a=n.length?n[0]:0;s.push(...o(r,a),"Enter")}return s}function Qv(e,t,n=""){let r=typeof n=="string"?n.trim():"";if(!r||!e?.custom)return{pre:hh(e,t).map(d=>({key:d})),text:"",post:[]};let o=Array.isArray(t?.[0])?t[0].filter(d=>Number.isInteger(d)&&d>=0):[],s=Number.isInteger(e.customIndex)?e.customIndex:e.questions?.[0]?.options?.length??0,a=Number.isInteger(e.cursorIndex)?e.cursorIndex:0,i=(d,p)=>{let f=p-d;return Array.from({length:Math.abs(f)},()=>({key:f>0?"Down":"Up"}))},c=[],l=a,u=typeof e.customText=="string"?e.customText.length:0;if(u>0&&a===s&&c.push(...Array.from({length:u+2},()=>({key:"BSpace"}))),e.multiSelect){for(let d of[...o].sort((p,f)=>p-f))c.push(...i(l,d),{key:"Enter"}),l=d;return c.push(...i(l,s)),{pre:c,text:r,post:[{key:"Down"},{key:"Enter"}]}}return c.push(...i(l,s)),{pre:c,text:r,post:[{key:"Enter"}]}}function eS(e,t){let n=Number.isInteger(e?.questionIndex)?e.questionIndex:0,o=(Number.isInteger(t)?t:n)-n;if(!o)return[];let s=o>0?"Tab":"BTab";return Array.from({length:Math.abs(o)},()=>s)}var qv,dh,rs,od,eo,ph,Gv,Kv,bL,lh,vL,os,Vv,zv,Jv,mh,EL,uh,$L,Yv,Xv,wh=q(()=>{dt();Uu();qv=/to navigate\b.*\bEsc to cancel|Enter to select\b/,dh=/Chat about this/i,rs=/^\s*(❯)?\s*(\d+)\.\s+(?:\[([ xX✔])\]\s+)?(.+?)\s*$/,od=/^(type something|chat about this|submit)\b/i,eo=/^[─—-]{6,}\s*$/,ph=/[\u2500-\u257F\u2550-\u256F┌┐└┘├┤│┬┴┼─✂]/;Gv=/^\s*Switch model\?\s*$/m;Kv=/^\s*Enter to confirm\s*·\s*Esc to cancel\s*$/,bL=/^\s*[─—▔-]{6,}\s*$/;lh=/Resume from summary/i,vL=/^\s*This session is\b/;os=/shift\+tab to cycle|⏵⏵ bypass permissions on|⏸ manual mode on/;Vv=/Choose the text style that looks best with your terminal/,zv=/Let's get started\./;Jv=/Select login method:/;mh=/Paste code here if prompted/,EL=/^[A-Za-z0-9%&=+._~#?/:\-]+$/;uh=/OAuth error:/,$L=/Press Enter to retry\./;Yv=/Quick safety check
|
|
172
|
+
`).pop()||""):e==="codex"&&/Sign in with ChatGPT|one-time code|Paste or type your API key|link to authenticate|Successfully logged in\.[\s\S]*Press Enter to continue\./i.test(n)?!0:e==="cursor"||e==="codex"?/\b(allow|approve|apply (this )?patch|run (this )?command|do you want to run|grant)\b/i.test(n):!1:!1}function Sn(e,t){return!e||!t?null:e.agent==="claude"?xL(t,e.name)||PL(t,e.name)||yL(t,e.name)||SL(t,e.name)||RL(t,e.name)||IL(t,e.name)||TL(t,e.name)||AL(t,e.name)||OL(t,e.name)||ML(t,e.name)||kL(t,e.name):e.agent==="cursor"||e.agent==="codex"?Ux(e.agent,t,e.name):null}async function Zv(e){if(!e)return null;let t=await zt(e.name).catch(()=>"");return Sn(e,t)}function hh(e,t){let n=Array.isArray(t?.[0])?t[0].filter(a=>Number.isInteger(a)&&a>=0):[],r=Number.isInteger(e?.cursorIndex)?e.cursorIndex:0,o=(a,i)=>{let c=i-a;return Array.from({length:Math.abs(c)},()=>c>0?"Down":"Up")},s=[];if(e?.multiSelect){let a=r;for(let i of[...n].sort((c,l)=>c-l))s.push(...o(a,i),"Enter"),a=i;s.push("Tab","Enter")}else{let a=n.length?n[0]:0;s.push(...o(r,a),"Enter")}return s}function Qv(e,t,n=""){let r=typeof n=="string"?n.trim():"";if(!r||!e?.custom)return{pre:hh(e,t).map(d=>({key:d})),text:"",post:[]};let o=Array.isArray(t?.[0])?t[0].filter(d=>Number.isInteger(d)&&d>=0):[],s=Number.isInteger(e.customIndex)?e.customIndex:e.questions?.[0]?.options?.length??0,a=Number.isInteger(e.cursorIndex)?e.cursorIndex:0,i=(d,p)=>{let f=p-d;return Array.from({length:Math.abs(f)},()=>({key:f>0?"Down":"Up"}))},c=[],l=a,u=typeof e.customText=="string"?e.customText.length:0;if(u>0&&a===s&&c.push(...Array.from({length:u+2},()=>({key:"BSpace"}))),e.multiSelect){for(let d of[...o].sort((p,f)=>p-f))c.push(...i(l,d),{key:"Enter"}),l=d;return c.push(...i(l,s)),{pre:c,text:r,post:[{key:"Down"},{key:"Enter"}]}}return c.push(...i(l,s)),{pre:c,text:r,post:[{key:"Enter"}]}}function eS(e,t){let n=Number.isInteger(e?.questionIndex)?e.questionIndex:0,o=(Number.isInteger(t)?t:n)-n;if(!o)return[];let s=o>0?"Tab":"BTab";return Array.from({length:Math.abs(o)},()=>s)}var qv,dh,rs,od,eo,ph,Gv,Kv,bL,lh,vL,os,Vv,zv,Jv,mh,EL,uh,$L,Yv,Xv,wh=q(()=>{dt();Uu();qv=/to navigate\b.*\bEsc to cancel|Enter to select\b/,dh=/Chat about this/i,rs=/^\s*(❯)?\s*(\d+)\.\s+(?:\[([ xX✔])\]\s+)?(.+?)\s*$/,od=/^(type something|chat about this|submit)\b/i,eo=/^[─—-]{6,}\s*$/,ph=/[\u2500-\u257F\u2550-\u256F┌┐└┘├┤│┬┴┼─✂]/;Gv=/^\s*Switch model\?\s*$/m;Kv=/^\s*Enter to confirm\s*·\s*Esc to cancel\s*$/,bL=/^\s*[─—▔-]{6,}\s*$/;lh=/Resume from summary/i,vL=/^\s*This session is\b/;os=/shift\+tab to cycle|⏵⏵ bypass permissions on|⏸ manual mode on/;Vv=/Choose the text style that looks best with your terminal/,zv=/Let's get started\./;Jv=/Select login method:/;mh=/Paste code here if prompted/,EL=/^[A-Za-z0-9%&=+._~#?/:\-]+$/;uh=/OAuth error:/,$L=/Press Enter to retry\./;Yv=/Quick safety check:\s+Is this a project you created or one you trust/;Xv=/^(.{0,60}?)Press\s+Enter\s+to\s+continue\s*[.…]{0,3}\s*$/});function sd(e,t,n){if(!e||!t)return null;for(let r of DL)if(r.provider===e.agent)try{if(r.match(t,n))return r}catch{}return null}function LL(e){let t=gh.get(e);return t||(t={sentAt:[],last:0,emitted:new Set},gh.set(e,t)),t}function rS(e,t,n=Date.now()){let r=LL(e);if(r.sentAt=r.sentAt.filter(s=>n-s<nS),r.sentAt.length>=tS)return{action:"give-up"};if(n-r.last<BL)return{action:"wait"};r.last=n,r.sentAt.push(n);let o=!r.emitted.has(t);return o&&r.emitted.add(t),{action:"send",first:o}}function oS(e,t=Date.now()){let n=gh.get(e);return n?n.sentAt.filter(r=>t-r<nS).length>=tS:!1}var DL,BL,tS,nS,gh,yh=q(()=>{DL=[{provider:"claude",id:"login-continue",match(e){return/^claude:setup:continue:/.test(e?.promptId||"")&&e?.setup==="continue"},keys:["Enter"],accept:!0,gate:"login-enter"},{provider:"codex",id:"login-continue",match(e){return e?.promptId==="codex:signin-complete"&&e?.setup==="continue"},keys:["Enter"],accept:!0,gate:"login-enter"},{provider:"claude",id:"fullscreen-upsell",match(e,t){let n=e?.questions?.[0],r=(n?.options||[]).map(s=>String(s.label||"").trim());if(r.length!==2||!/^Yes, try it$/.test(r[0])||!/^Not now$/.test(r[1]))return!1;let o=`${n?.question||""}
|
|
173
173
|
${String(t||"")}`;return/Try the new fullscreen renderer|Flicker-free output/i.test(o)},keys:["Escape"]}];BL=5e3,tS=5,nS=3600*1e3,gh=new Map});function ad(e,t,n){let{state:r,reason:o}=oc(t,n);if(r!=="unknown"){if(e){let a=Date.now();for(let[i,c]of wc)a-c.at>=sS()&&wc.delete(i);wc.set(e,{busy:r==="busy",at:a})}return r==="busy"}if(o!=="narrow"||!e)return!1;let s=wc.get(e);return s?Date.now()-s.at>=sS()?(wc.delete(e),!1):s.busy:!1}async function gc(e,t){let n={working:!1,prompted:!1};if(!e)return n;let r=await Ne(e,{lines:ze}).catch(()=>"");if(!ad(e,t,r))return zu(t,r)?{working:!0,prompted:!1}:n;if(no(t,r)){let o=await zt(e).catch(()=>r),s=Sn({name:e,agent:t},o);if(s)return!sd({name:e,agent:t},s,o)||oS(e)?{working:!1,prompted:!0}:{working:!1,prompted:!1}}return{working:!0,prompted:!1}}async function ss(e,t){return(await gc(e,t)).working}var sS,wc,xa=q(()=>{dt();ns();wh();yh();sS=()=>Number(process.env.BOSTRAT_NARROW_CARRY_MS)||9e4,wc=new Map});function KL(e){if(e.startsWith("{"))try{let t=JSON.parse(e);return{message:String(t?.message??""),taskId:t?.task_id?String(t.task_id):null}}catch{}return{message:e,taskId:null}}function zL(e){if(e.type==="queue-operation"&&e.operation==="enqueue")return aS.test(String(e.content||""))?String(e.content):null;if(e.type==="attachment"){let n=e.attachment;return n?.type==="queued_command"&&n.commandMode==="task-notification"&&typeof n.prompt=="string"?n.prompt:null}let t=e.message?.content;return typeof t=="string"&&aS.test(t)?t:null}async function iS(e,t={}){return(await lS(e,t)).launches}async function cS(e,t={}){let{launches:n,done:r}=await lS(e,t);return n.filter(o=>!r.has(o.id))}async function lS(e,{maxBytes:t=2097152,limit:n=100}={}){let r;try{r=await Lt(e,t)}catch{return{launches:[],done:new Set,stopped:new Map}}let o=new Map,s=new Set,a=new Set,i=new Map,c=new Map,l=new Map,u=new Map;for(let p of r.split(`
|
|
174
174
|
`)){let f=p.trim();if(!f||f[0]!=="{")continue;let w;try{w=JSON.parse(f)}catch{continue}if(w.isSidechain)continue;let h=zL(w);if(h){let g=h.match(VL)?.[1]?.trim();g&&a.add(g);continue}let y=w.message?.content;if(!Array.isArray(y))continue;let k=w.timestamp?Date.parse(w.timestamp):null;for(let g of y)if(!(!g||typeof g!="object")){if(g.type==="tool_use"&&g.id){if(g.name==="Agent"){let x=g.input||{};o.set(g.id,{id:g.id,kind:"agent",name:String(x.description||"").trim()||null,detail:String(x.subagent_type||"").trim()||null,ts:k,proven:!1})}else if(g.name==="Bash"){let x=String(g.input?.command||"").trim(),S={id:g.id,kind:"command",name:String(g.input?.description||"").trim()||(x?ma(x):null),detail:x?ma(x):null,ts:k,proven:g.input?.run_in_background===!0};S.proven?o.set(g.id,S):c.set(g.id,S)}else if(qL.has(g.name)){let x=g.input?.task_id??g.input?.shell_id??g.input?.bash_id;x&&u.set(g.id,{taskId:String(x),ts:k})}}else if(g.type==="tool_result"&&g.tool_use_id){let x=JL(g.content);if(jL.test(x)){s.add(g.tool_use_id);let D=x.match(WL)?.[1];D&&l.set(D,g.tool_use_id)}let S=x.match(HL)?.[1];S&&l.set(S,g.tool_use_id);let $=x.match(FL);if($){l.set($[1].trim(),g.tool_use_id);let D=c.get(g.tool_use_id);D&&(c.delete(g.tool_use_id),D.proven=!0,D.outputFile=x.match(UL)?.[1]?.replace(/\.$/,"")||null,o.set(D.id,D))}let M=u.get(g.tool_use_id);if(M){u.delete(g.tool_use_id);let{message:D,taskId:L}=KL(x);if(!g.is_error&&GL.test(D)){let T=l.get(M.taskId)??(L?l.get(L):void 0);T&&(a.add(T),i.set(T,k??M.ts??null))}}}}}let d=[];for(let p of o.values()){if(!p.proven&&!s.has(p.id))continue;let{proven:f,...w}=p;w.stoppedTs=i.has(p.id)?i.get(p.id):null,d.push(w)}return{launches:d.slice(-n),done:a,stopped:i}}var jL,FL,UL,HL,WL,qL,GL,aS,VL,JL,uS=q(()=>{vn();ha();jL=/^Async (?:agent|task) launched/i,FL=/^Command did not complete within its [^\n]*?moved to the background \(ID: ([^)]+)\)/i,UL=/Output is being written to:\s*(\S+)/i,HL=/^Command running in background with ID:\s*([^\s.]+)/i,WL=/\bagentId:\s*([A-Za-z0-9_-]+)/,qL=new Set(["TaskStop","KillShell"]),GL=/^Successfully (?:stopped|killed)\b/i;aS=/^\s*<task-notification>/i,VL=/<tool-use-id>([\s\S]*?)<\/tool-use-id>/i;JL=e=>{if(typeof e=="string")return e.trim();if(!Array.isArray(e))return"";let t=e.find(n=>n&&n.type==="text"&&typeof n.text=="string");return t?t.text.trim():""}});function ro(e,t){if(!e)return null;let n=String(e);if(t){let o=t.endsWith("/")?t:`${t}/`;if(n===t)return".";if(n.startsWith(o))return n.slice(o.length)||"."}let r=n.split("/").filter(Boolean);return n.startsWith("/")&&r.length>2?r.slice(-2).join("/"):n}function YL(e){let t=typeof e=="string"?e:String(e?.patch??e?.input??""),n=[];for(let r of t.matchAll(/^\*{3} (?:Update|Add|Delete) File: (.+)$/gm))n.push(r[1].trim());return n}function dS(e,t,n){switch(e){case"Shell":{let r=String(t?.command||"").trim();return r?{command:r,description:String(t?.description||"").trim()}:null}case"Read":{let r=t?.path;if(!r)return null;let o=Number(t?.offset)||null,s=o&&Number(t?.limit)?o+Number(t.limit)-1:null;return{command:An(`read ${ro(r,n)}${o?` (lines ${o}\u2013${s??"end"})`:""}`,140),description:o?`Read lines ${o}\u2013${s??"end"} of ${va(r)}`:`Read ${va(r)}`}}case"Grep":{let r=t?.pattern;if(!r)return null;let o=t?.path?ro(t.path,n):null,s=t?.glob?` --glob ${bh(t.glob)}`:"",a=An(String(r),40);return{command:An(`grep ${bh(r)}${o&&o!=="."?` ${o}`:""}${s}`,140),description:o&&o!=="."?`Search for \u201C${a}\u201D in ${o}`:`Search for \u201C${a}\u201D`}}case"Glob":{let r=t?.glob_pattern;if(!r)return null;let o=t?.target_directory?ro(t.target_directory,n):null;return{command:An(`glob ${bh(r)}${o&&o!=="."?` ${o}`:""}`,140),description:`Find files matching \u201C${An(String(r),40)}\u201D`}}case"StrReplace":return t?.path?{command:An(`edit ${ro(t.path,n)}`,140),description:`Edit ${va(t.path)}`}:null;case"Write":return t?.path?{command:An(`write ${ro(t.path,n)}`,140),description:`Write ${va(t.path)}`}:null;case"Delete":return t?.path?{command:An(`delete ${ro(t.path,n)}`,140),description:`Delete ${va(t.path)}`}:null;case"ReadLints":{let o=(Array.isArray(t?.paths)?t.paths:[]).map(s=>ro(s,n)).filter(Boolean);return{command:An(o.length?`lints ${o.join(" ")}`:"lints",140),description:"Check lints"}}case"ApplyPatch":{let r=YL(t);if(!r.length)return null;let o=r.length>1?` (+${r.length-1} more)`:"";return{command:An(`apply_patch ${ro(r[0],n)}${o}`,140),description:r.length>1?`Patch ${r.length} files`:`Patch ${va(r[0])}`}}case"Await":{let r=t?.shell_id??t?.task_id;return{command:An(`await ${r??"background output"}`,140),description:"Wait for a background command"}}default:return null}}var id,An,va,bh,pS=q(()=>{id=new Set(["Shell","Read","Grep","Glob","StrReplace","Write","ReadLints","Delete","ApplyPatch","Await"]),An=(e,t=88)=>e.length>t?`${e.slice(0,t).trimEnd()}\u2026`:e,va=e=>String(e).replace(/\/+$/,"").split("/").pop()||String(e);bh=e=>`"${String(e).replace(/"/g,'\\"')}"`});import yc from"node:fs";import XL from"node:fs/promises";import as from"node:path";import ZL from"node:os";import QL from"node:crypto";import ej from"node:zlib";function hS(e){let t=QL.createHash("md5").update(String(e)).digest("hex");return as.join(tj,t)}function wS(e){try{let t=JSON.parse(yc.readFileSync(as.join(e,"meta.json"),"utf8"));return{createdAtMs:Number(t.createdAtMs)||null,updatedAtMs:Number(t.updatedAtMs)||Number(t.createdAtMs)||null,hasConversation:t.hasConversation===!0}}catch{return null}}function nj(e){let t=hS(e),n;try{n=yc.readdirSync(t,{withFileTypes:!0}).filter(o=>o.isDirectory())}catch{return null}let r=null;for(let o of n){let s=as.join(t,o.name),a=as.join(s,"store.db");if(!yc.existsSync(a))continue;let i=wS(s);if(!i)continue;let c={id:o.name,dir:s,store:a,...i};(!r||c.hasConversation&&!r.hasConversation||c.hasConversation===r.hasConversation&&(c.updatedAtMs||0)>(r.updatedAtMs||0))&&(r=c)}return r}function cd(e,t){if(!e)return null;if(t){let n=as.join(hS(e),t),r=as.join(n,"store.db");if(yc.existsSync(r))return{id:t,dir:n,store:r,...wS(n)||{createdAtMs:null,updatedAtMs:null}}}return nj(e)}function fS(e,t){let n=e.prepare("SELECT data FROM blobs WHERE id = ?").get(t);return n?Buffer.from(n.data):null}function rj(e){if(!e)return null;let t=e;if(t.length>1&&t[0]===31&&t[1]===139)try{t=ej.gunzipSync(t)}catch{}try{return JSON.parse(t.toString("utf8"))}catch{return null}}function oj(e){let t=[],n=0,r=e.length,o=()=>{let s=0,a=0;for(;n<r;){let i=e[n++];if(s+=(i&127)*2**a,!(i&128))break;a+=7}return s};for(;n<r;){let s=o(),a=s>>>3,i=s&7;if(i===2){let c=o(),l=e.subarray(n,n+c);n+=c,a===1&&c===32&&t.push(l.toString("hex"))}else if(i===0)o();else if(i===5)n+=4;else if(i===1)n+=8;else break}return t}function sj(e,t){if(!Array.isArray(e))return[];let n=[];for(let r of e){if(!r||r.type!=="tool-call"||!id.has(r.toolName))continue;let o=dS(r.toolName,r.args,t);!o||!o.command||n.push({id:r.toolCallId||null,tool:r.toolName,command:o.command,description:o.description||""})}return n}async function kh(e,t){if(!mS)return Sa;let{DatabaseSync:n}=mS,r;try{r=new n(e,{readOnly:!0})}catch{return Sa}try{let o=r.prepare("SELECT value FROM meta WHERE key = '0'").get()||r.prepare("SELECT value FROM meta LIMIT 1").get();if(!o)return Sa;let s;try{s=JSON.parse(Buffer.from(String(o.value),"hex").toString("utf8"))}catch{return Sa}let a=s.lastUsedModel||null,i=s.latestRootBlobId?fS(r,s.latestRootBlobId):null;if(!i)return{...Sa,model:a};let c=[],l=[],u=[],d=null,p=[];for(let f of oj(i)){let w=rj(fS(r,f));if(!w)continue;let h=w.providerOptions?.cursor;if(h?.requestId&&p.push(h.requestId),h?.modelProviderMessageId&&p.push(h.modelProviderMessageId),w.role!=="assistant")continue;if(Array.isArray(w.content))for(let g of w.content){let x=g?.providerOptions?.cursor?.modelName;x&&(d=x)}l.push(...sj(w.content,t).map((g,x)=>({...g,id:g.id||`${f}:${x}`}))),u.push(...ij(w.content));let y=aj(w.content);if(!y)continue;let k=[...new Set(u)];u=[],c.push({id:f,text:y,tools:k.length?k:void 0,commands:l,model:d}),l=[]}return{turns:c,trailingCommands:l,model:a,requestIds:p}}catch{return Sa}finally{try{r.close()}catch{}}}function gS(e,t){let n=e.updatedAtMs;if(!n)try{n=Math.round(yc.statSync(e.store).mtimeMs)}catch{n=Date.now()}let r=e.createdAtMs;(!r||r>n)&&(r=n-t*1e3);let o=Math.max(0,n-r);return{end:n,tsAt:s=>Math.round(r+o*(s+1)/t)}}async function yS(e,t,{limit:n=80}={}){let r=cd(e,t);if(!r)return[];let{turns:o,model:s}=await kh(r.store,e);if(!o.length)return[];let a=o.slice(-n),{tsAt:i}=gS(r,a.length);return a.map((c,l)=>({role:"assistant",text:c.text,tools:c.tools,ts:i(l),model:c.model||s,sourceId:c.id}))}async function bS(e,t){let n=cd(e,t);if(!n)return null;let{turns:r,requestIds:o,model:s}=await kh(n.store,e);return{chatId:n.id,requestIds:o,models:[...new Set(r.map(a=>a.model).filter(Boolean))],configuredModel:s,updatedAtMs:n.updatedAtMs||null}}async function kS(e,t,{limit:n=80}={}){let r=cd(e,t);if(!r)return[];let{turns:o,trailingCommands:s}=await kh(r.store,e);if(!o.length&&!s.length)return[];let a=o.slice(-n),{end:i,tsAt:c}=gS(r,a.length||1),l=[];a.forEach((u,d)=>{for(let p of u.commands)l.push({...p,summary:Xr(p.command,p.description),ts:c(d)})});for(let u of s)l.push({...u,summary:Xr(u.command,u.description),ts:i+1});return l}async function xS(e,t){let n=cd(e,t);if(!n)return null;if(n.updatedAtMs)return n.updatedAtMs;try{return Math.round((await XL.stat(n.store)).mtimeMs)}catch{return null}}var tj,aj,ij,mS,Sa,xh=q(()=>{ha();pS();tj=process.env.BOSTRAT_CURSOR_CHATS||as.join(ZL.homedir(),".cursor","chats");aj=e=>typeof e=="string"?e.trim():Array.isArray(e)?e.filter(t=>t&&t.type==="text"&&typeof t.text=="string").map(t=>t.text).join(`
|
|
175
175
|
`).trim():"",ij=e=>Array.isArray(e)?e.filter(t=>t&&t.type==="tool-call"&&t.toolName).map(t=>t.toolName):[],mS=process.getBuiltinModule?.("node:sqlite"),Sa={turns:[],trailingCommands:[],model:null,requestIds:[]}});import cj from"node:fs/promises";function Th(e){return vS.set(e.agent,e),e}function oo(e){return vS.get(e)||lj}async function Eh(e,t={}){return(await oo(e.agent).readMessages(e,t)).map(ld(e))}async function SS(e,t={}){return(await oo(e.agent).readCommands(e,t)).map(ld(e))}async function AS(e,t={}){return(await oo(e.agent).readJobs(e,t)).map(ld(e))}async function ud(e,t={}){return(await oo(e.agent).readOpenJobs(e,t)).map(ld(e))}var Aa,vh,Sh,Ah,lj,vS,ld,dd=q(()=>{vn();ju();ha();uS();xh();Zo();Aa=class{constructor(t,n=new Set){this.agent=t,this.cliTools=n}async readMessages(){return[]}async readCommands(){return[]}async readJobs(){return[]}async readOpenJobs(){return[]}async updatedAt(){return null}},vh=class extends Aa{transcript(t){return!t?.cwd||!t?.sessionId?null:xn(t.cwd,t.sessionId)}async readMessages(t,n){let r=this.transcript(t);return r?Hm(r,n):[]}async readCommands(t,n){let r=this.transcript(t);return r?kx(r,n):[]}async readJobs(t,n){let r=this.transcript(t);return r?iS(r,n):[]}async readOpenJobs(t,n){let r=this.transcript(t);return r?cS(r,n):[]}async updatedAt(t){let n=this.transcript(t);if(!n)return null;try{return Math.round((await cj.stat(n)).mtimeMs)}catch{return null}}},Sh=class extends Aa{async readMessages(t,n){return yS(t.cwd,t.sessionId,n)}async readCommands(t,n){return kS(t.cwd,t.sessionId,n)}async updatedAt(t){return xS(t.cwd,t.sessionId)}},Ah=class extends Aa{sessionId(t){return t?.pinned?t.sessionId:null}async readMessages(t,n){return Ax(t.cwd,this.sessionId(t),n)}async readCommands(t,n){return Tx(t.cwd,this.sessionId(t),n)}async updatedAt(t){return Ex(t.cwd,this.sessionId(t))}},lj=new Aa("unknown"),vS=new Map;Th(new vh("claude",Bm));Th(new Sh("cursor",id));Th(new Ah("codex",ec));ld=e=>t=>({...t,box:e.name,agent:e.agent,boxRole:e.role})});function _h(e){if(!e)return"the current turn";let t=[];e.prompted?t.push("an unanswered prompt"):e.busy?t.push("the current turn"):e.unknown&&t.push("a pane too narrow to read"),e.awaitingBackground&&t.push("a background wait");let n=Array.isArray(e.jobs)?e.jobs:[];if(n.length){let r=n.slice(0,2).map(o=>o.name||o.id).filter(Boolean);t.push(`${n.length} background job${n.length===1?"":"s"}${r.length?` (${r.join(", ")}${n.length>r.length?", \u2026":""})`:""}`)}return t.length?t.join(" and "):"the current turn"}async function TS(e,{timeoutMs:t,reason:n=null,onWait:r=null,deps:o=null}={}){let s={...mj,...o||{}},a=e?.name,i=e?.agent||null;if(!a)throw new Error("awaitQuiescence: box.name is required");let c=Number(t)||uj(),l=dj(),u=s.now(),d=0,p=0,f=!1,w=null;for(;;){p++;let h=await s.capture(a),y=s.busyRead(i,h);if(y.reason==="blocked"){let g=new Error(`${i||"the agent"} in "${a}" is sitting at a login or trust gate \u2014 answer it in the terminal, then retry`);throw g.code="quiescence-blocked",g.detail={blocked:!0},g}if(w={busy:y.state==="busy",unknown:y.state==="unknown",awaitingBackground:s.awaitingBackground(i,h),prompted:!1,jobs:[]},w.busy){let g=await s.turnState(a,i).catch(()=>({prompted:!1}));w.prompted=g?.prompted===!0}if(!w.busy&&!w.unknown&&!w.awaitingBackground){let g=await s.openJobs(e).catch(()=>[]);w.jobs=(Array.isArray(g)?g:[]).map(x=>({id:x.id??null,name:x.name??null,kind:x.kind??null}))}let k=!w.busy&&!w.unknown&&!w.awaitingBackground&&!w.prompted&&w.jobs.length===0;if(d=k?d+1:0,d>=pj){let g=s.now()-u;return f&&te({flow:"quiescence",phase:"quiet",sessionName:a,agent:i,reason:n,waitedMs:g,reads:p}).catch(()=>{}),{waitedMs:g,reads:p,waited:f,detail:w}}if(!k&&!f&&(f=!0,te({flow:"quiescence",phase:"waiting",sessionName:a,agent:i,reason:n,detail:w}).catch(()=>{}),r&&await r(w)),s.now()-u>=c){let g=new Error(`waited ${Math.round(c/1e3)}s for ${_h(w)} in "${a}" to finish`);throw g.code="quiescence-timeout",g.detail=w,g.waitedMs=s.now()-u,te({flow:"quiescence",phase:"timeout",sessionName:a,agent:i,reason:n,waitedMs:g.waitedMs,reads:p,detail:w,error:g.message}).catch(()=>{}),g}await s.sleep(l)}}var uj,dj,pj,fj,mj,ES=q(()=>{dt();ns();xa();dd();bn();uj=()=>Number(process.env.BOSTRAT_QUIESCENCE_TIMEOUT_MS)||6e5,dj=()=>Number(process.env.BOSTRAT_QUIESCENCE_POLL_MS)||1500,pj=2,fj=e=>new Promise(t=>setTimeout(t,e)),mj={capture:e=>Ne(e,{lines:ze}),busyRead:oc,awaitingBackground:zu,turnState:gc,openJobs:ud,now:()=>Date.now(),sleep:fj}});import hj from"node:fs";import so from"node:fs/promises";import ao from"node:path";function PS(e){let t=Ko(String(e??"")),n=Buffer.byteLength(t,"utf8");return n<=_S?{content:t,bytes:n,truncated:!1}:{content:`${Buffer.from(t,"utf8").subarray(0,_S).toString("utf8").replace(/�+$/,"")}
|
package/package.json
CHANGED