import{n as e,s as t,u as n}from"./envUtils-BWeoiL4Y.js";import{Ct as r,cn as i,ot as a}from"./state-sIHsFpDu.js";import{E as o,O as s,Q as c,X as l,Y as u,Z as d,_ as f,h as p,l as m,p as h}from"./debug-otxXY3j-.js";import{m as g}from"./sessionStoragePortable-CJUZrbIq.js";import{i as _}from"./path-BE28AJwZ.js";import{basename as v,dirname as y,join as b}from"path";import{appendFile as x,rename as S}from"fs/promises";i(),l(),d(),m(),t(),f(),_(),o();var C={filePath:null,timestamp:0};function w(){if(C.filePath!==null)return C.filePath;if(process.env.USER_TYPE!==`ant`||!n(process.env.CLAUDE_CODE_TERMINAL_RECORDING))return null;let t=b(b(e(),`projects`),g(a()));return C.timestamp=Date.now(),C.filePath=b(t,`${r()}-${C.timestamp}.cast`),C.filePath}async function T(){let t=C.filePath;if(!t||C.timestamp===0)return;let n=b(b(b(e(),`projects`),g(a())),`${r()}-${C.timestamp}.cast`);if(t===n)return;await E?.flush();let i=v(t),o=v(n);try{await S(t,n),C.filePath=n,h(`[asciicast] Renamed recording: ${i} → ${o}`)}catch{h(`[asciicast] Failed to rename recording from ${i} to ${o}`)}}var E=null;function D(){return{cols:process.stdout.columns||80,rows:process.stdout.rows||24}}function O(){let e=w();if(!e)return;let{cols:t,rows:n}=D(),r=performance.now(),i=s({version:2,width:t,height:n,timestamp:Math.floor(Date.now()/1e3),env:{SHELL:process.env.SHELL||``,TERM:process.env.TERM||``}});try{p().mkdirSync(y(e))}catch{}p().appendFileSync(e,i+`
`,{mode:384});let a=Promise.resolve(),o=u({writeFn(e){let t=C.filePath;t&&(a=a.then(()=>x(t,e)).catch(()=>{}))},flushIntervalMs:500,maxBufferSize:50,maxBufferBytes:10*1024*1024}),l=process.stdout.write.bind(process.stdout);process.stdout.write=function(e,t,n){let i=(performance.now()-r)/1e3,a=typeof e==`string`?e:Buffer.from(e).toString(`utf-8`);return o.write(s([i,`o`,a])+`
`),typeof t==`function`?l(e,t):l(e,t,n)};function d(){let e=(performance.now()-r)/1e3,{cols:t,rows:n}=D();o.write(s([e,`r`,`${t}x${n}`])+`
`)}process.stdout.on(`resize`,d),E={async flush(){o.flush(),await a},async dispose(){o.dispose(),await a,process.stdout.removeListener(`resize`,d),process.stdout.write=l}},c(async()=>{await E?.dispose(),E=null}),h(`[asciicast] Recording to ${e}`)}export{O as n,T as r,w as t};