@promptctl/cc-candybar 1.211.1 → 1.211.2
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.mjs +4 -4
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import{createRequire as e}from"node:module";import t from"node:process";import{URL as n,URLSearchParams as r,fileURLToPath as i}from"node:url";import{json as a}from"node:stream/consumers";import o from"node:os";import s,{basename as c,dirname as l,isAbsolute as u,join as d,resolve as f,sep as p}from"node:path";import m,{appendFileSync as h,closeSync as g,constants as _,existsSync as v,fstatSync as y,linkSync as b,mkdtempSync as x,openSync as S,readFileSync as C,readSync as w,rmSync as T,statSync as E,unlinkSync as ee,writeFileSync as D}from"node:fs";import{StringDecoder as te}from"node:string_decoder";import{inspect as O,parseArgs as k,types as ne}from"node:util";import{clearImmediate as A,setImmediate as re}from"node:timers";import ie,{createHash as ae,createHmac as oe,randomBytes as se,randomUUID as ce,timingSafeEqual as le}from"node:crypto";import ue from"node:net";import{spawn as de,spawnSync as fe}from"node:child_process";import pe from"node:v8";import{open as me,readFile as he,readdir as ge,stat as _e}from"node:fs/promises";import{get as ve}from"node:https";import{WriteStream as ye}from"node:tty";import{createInterface as be}from"node:readline";var xe=Object.create,Se=Object.defineProperty,Ce=Object.getOwnPropertyDescriptor,we=Object.getOwnPropertyNames,Te=Object.getPrototypeOf,Ee=Object.prototype.hasOwnProperty,De=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),Oe=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=we(t),a=0,o=i.length,s;a<o;a++)s=i[a],!Ee.call(e,s)&&s!==n&&Se(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=Ce(t,s))||r.enumerable});return e},ke=(e,t,n)=>(n=e==null?{}:xe(Te(e)),Oe(t||!e||!e.__esModule?Se(n,`default`,{value:e,enumerable:!0}):n,e));let Ae=!1;const je=()=>Ae;function Me(e){Ae=e}function Ne(e){return je()?`[DEBUG] ${e()}\n`:``}function Pe(e,...t){je()&&console.error(`[DEBUG] ${e}`,...t)}function Fe(e){let t=null;return([n,r])=>{r!==t&&(t=r,e(n,r))}}const Ie=(e,t)=>Pe(t),Le=`main`,Re=`CC_CANDYBAR_HOME`,ze=`CC_CANDYBAR_NAME`,Be=`CC_CANDYBAR_RUNTIME_DIR`,Ve=/^[a-z0-9][a-z0-9-]*$/;function He(e,t){if(!Ve.test(e))throw Error(`${t} must be lowercase letters, digits and dashes, starting with a letter or digit, got ${JSON.stringify(e)}`);if(e.length>32)throw Error(`${t} must be at most 32 characters, got ${e.length}: ${JSON.stringify(e)}`);return e}function Ue(e){let t=He(e,ze);if(t===`main`)throw Error(`${ze} may not be ${JSON.stringify(Le)}: that is the main renderer's name, which is what an unset ${Re} and ${ze} mean`);return t}function We(e){return e===`main`?Le:He(e,`a link's renderer name`)}function Ge(e){return e===`main`?`socket`:`${e}.sock`}function Ke(e,t){let n=e[t];return n&&n.length>0?n:void 0}function qe(){let e=process.getuid();return s.join(`/tmp`,`cc-candybar-${e}`)}function Je(e){let t=Ke(e.env,Be);if(t===void 0)return qe();if(!s.isAbsolute(t))throw Error(`${Be} must be an absolute path, got ${JSON.stringify(t)}`);return t}function Ye(e){let{env:t}=e,n=Ke(t,Re),r=Ke(t,ze),i=Ke(t,`CC_CANDYBAR_SOCKET`)??null,a=Je(e);if(n!==void 0&&r!==void 0){if(!s.isAbsolute(n))throw Error(`${Re} must be an absolute path, got ${JSON.stringify(n)}`);if(i!==null)throw Error(`CC_CANDYBAR_SOCKET is set beside ${Re} and ${ze}: a named renderer's socket is its name's, so unset it`);return{kind:`named`,name:Ue(r),runtime:a,root:n}}if(n!==void 0||r!==void 0){let[e,t]=n===void 0?[ze,Re]:[Re,ze];throw Error(`${e} is set without ${t}: a renderer's home is both, or neither for the main renderer`)}return{kind:`main`,name:Le,runtime:a,roots:{state:Ke(t,`XDG_STATE_HOME`)??s.join(e.home,`.local`,`state`),cache:Ke(t,`XDG_CACHE_HOME`)??s.join(e.home,`.cache`),config:Ke(t,`XDG_CONFIG_HOME`)??s.join(e.home,`.config`)},legacySocket:i}}function Xe(e,t){return e+t}function Ze(e,t){return Math.round(t-e)}function Qe(e,t){return Ze(t,e.monotonic())}const $e={now:()=>Date.now(),monotonic:()=>performance.now(),bootTime:()=>Date.now()-o.uptime()*1e3,after:(e,t,n)=>{let r=setTimeout(t,e);return n?.unref&&r.unref(),()=>clearTimeout(r)},every:(e,t,n)=>{let r=setInterval(t,e);return n?.unref&&r.unref(),()=>clearInterval(r)},defer:e=>{let t=re(e);return()=>A(t)}};function et(e,t,n){return new Promise((r,i)=>{let a=()=>Object.assign(Error(`The operation was aborted`),{name:`AbortError`,code:`ABORT_ERR`,cause:n?.reason});if(n?.aborted){i(a());return}let o=()=>{s(),i(a())},s=e.after(t,()=>{n?.removeEventListener(`abort`,o),r()});n?.addEventListener(`abort`,o,{once:!0})})}function tt(e,t){let n=new AbortController;return e.after(t,()=>n.abort(new DOMException(`The operation was aborted due to timeout`,`TimeoutError`)),{unref:!0}),n.signal}function nt(e,t,n,r){return n<e.at+t?`held`:r===`request`&&!e.answered?`owed`:`over`}function rt(e,t){return!e.answered&&e.at===t.at&&e.text===t.text}const it=e=>e.getTime()/1e3,at=e=>Math.round(e*1e3),ot=e=>new Date(at(e)),st=e=>it(new Date(e.now()));function ct(e){return`${e}.${process.pid}.${ce()}.tmp`}function lt(e,t){return ne.isNativeError(e)?e.code===`ENOENT`&&t!==void 0&&!v(t)?`working directory does not exist: ${t}`:e.message:String(e)}const ut={"click.pbcopy":1e3,"click.open":1e3,"doctor.tmux":1e3,"doctor.font":1e3,"doctor.process":1e3,"claude-input.type":1e3};function dt(e,t,n){let r=ut[t];if(r===void 0)return{allowed:!0};let i=e.get(t);if(i===void 0)return{allowed:!0};let a=n-i;return a>=r?{allowed:!0}:{allowed:!1,minIntervalMs:r,sinceLastMs:a}}function ft(e,t){return{...e.inherited,...t.envOverlay}}function pt(e){switch(e.reason){case`non-zero`:return`exited with code ${e.exitCode}`;case`signal`:return`killed by ${e.signal??`a signal`}`;case`timeout`:case`output-limit`:case`rate-limited`:case`pipe-error`:case`spawn-error`:return e.error??e.reason;default:return e.error===void 0?e.reason:`${e.reason}: ${e.error}`}}const mt=e=>{let t=[];for(let n of e){if(t.length===200)return`${t.join(``)}…`;t.push(n)}return e};function ht(e,t){if(e.reason===`output-limit`||e.reason===`pipe-error`)return``;let n=t.trim(),r=n.search(/[\r\n]/);if(r===-1)return mt(n);let i=Math.max(n.lastIndexOf(`
|
|
3
3
|
`),n.lastIndexOf(`\r`))+1;return`${mt(n.slice(0,r).trim())} … ${mt(n.slice(i).trim())}`}function gt(e,t=``){let n=ht(e,e.stderr);return`${pt(e)}${t}${n===``?``:`: ${n}`}`}const _t=({reason:e})=>({ok:!1,reason:`aborted`,stdout:``,stderr:``,exitCode:null,signal:null,error:e instanceof Error?e.message:String(e)});function vt(e,t,n){return{ok:!1,reason:`rate-limited`,stdout:``,stderr:``,exitCode:null,signal:null,error:`rate-limited: ${e} min interval ${t}ms, last start ${Math.round(n)}ms ago`}}function yt(e,t){let n=t.finally(()=>e.ending.delete(n));return e.ending.add(n),n}function bt(e,t,n){let r=xt(e,t,n);return r===null?(e.lastStartAt.set(t,e.scope.clock.monotonic()),null):(e.scope.stats?.onRefused(t),r)}function xt(e,t,n){if(e.scope.signal.aborted)return _t(e.scope.signal);if(n?.aborted)return _t(n);let r=dt(e.lastStartAt,t,e.scope.clock.monotonic());return r.allowed?null:vt(t,r.minIntervalMs,r.sinceLastMs)}const St=`\$1 == "+" { live[\$2] = 1; next } \$1 == "-" { delete live[\$2]; next } END { for (g in live) groups = groups " -" g; if (groups != "") system("kill -TERM" groups " 2>/dev/null; sleep ${250/1e3}; kill -KILL" groups " 2>/dev/null") }`;function Ct(e,t){t!==e.fault&&(e.fault=t,e.scope.observeWarnings({kind:`lifeline`,fault:t}))}function wt(e,t,n){e.lifeline?.process===t&&(e.lifeline=null,t.ref(),Ct(e,n))}const Tt=e=>`programs launched now would outlive their launcher if it died: its launch lifeline ${e}, and the next launch starts another`,Et=e=>e===`cut`?`output cut at the ${Ft}-byte bound, so the program holding it now fails its writes`:`output failed to read`,Dt=`a launched program's pipe outlived its launch: `;function Ot(e,t,n){let r=e.pipeEvent,i=new Map(r===null||r.answered?[]:r.counts),a=`${t}\0${n}`;i.set(a,(i.get(a)??0)+1),e.pipeEvent={text:`${Dt}${[...i].map(([e,t])=>{let[n,r]=e.split(`\0`);return`${t}× ${r} ${Et(n)}`}).join(`; `)}`,at:e.scope.now(),answered:!1,counts:i},e.scope.observeWarnings({kind:`launch-pipes`,text:`${Dt}${n} ${Et(t)}`})}function kt(e,t){let n=e.pipeEvent;n===null||!rt(n,t)||(e.pipeEvent={...n,answered:!0})}function At(e,t,n){let r=e.pipeEvent,i=r===null?`over`:nt(r,60,t,n);return[...e.fault===null?[]:[{kind:`lifeline`,message:Tt(e.fault)}],...r===null||i===`over`?[]:[{kind:`launch-pipes`,message:r.text,event:r,hold:i}]]}function jt(e){let{stats:t,clock:n}=e.scope;t?.onStart(`lifeline`);let r=n.monotonic(),i;try{i=e.spawner.spawn(`awk`,[St],{stdio:[`pipe`,`ignore`,`ignore`],detached:!0})}catch(i){return t?.onEnd(`lifeline`,Qe(n,r)),Ct(e,`did not start: ${lt(i,void 0)}`),null}t?.onEnd(`lifeline`,Qe(n,r));let a=i.stdin;if(a==null)return i.once(`error`,t=>Ct(e,`did not start: ${t.message}`)),null;i.once(`spawn`,()=>{e.lifeline?.process===i&&Ct(e,null)}),i.once(`error`,t=>wt(e,i,`failed: ${t.message}`)),i.once(`exit`,(t,n)=>wt(e,i,`exited ${n??t}`)),a.on(`error`,t=>wt(e,i,`pipe failed: ${t.message}`)),yt(e,new Promise(e=>i.once(`close`,e))),i.unref(),a.unref();for(let t of e.liveGroups)a.write(`+ ${t}\n`);return{process:i,pipe:a}}function Mt(e,t){e.liveGroups.add(t),e.lifeline??=jt(e),e.lifeline?.pipe.write(`+ ${t}\n`)}function Nt(e,t){e.liveGroups.delete(t),e.lifeline?.pipe.write(`- ${t}\n`)}function Pt(e){let t=e.lifeline;e.lifeline=null,t?.process.ref(),t?.pipe.end()}const Ft=16*1024*1024,It=`output exceeded ${Ft} bytes`,Lt=e=>`timed out after ${e/1e3} s`;function Rt(e,t,n,r){let{stats:i}=e.scope,a=new te(`utf8`),o=``,s=0,c=0,l=r,u=`closed`;return n?.on(`error`,n=>{i?.onPipeError(t),l===null?Ot(e,`read-error`,t):l.failed(n)}),n?.on(`data`,r=>{if(l===null){if(c+=r.length,i?.onDrainRead(t,r.length),c<=16777216)return;u=`cut`,n.destroy(),Ot(e,`cut`,t);return}let d=Math.max(0,Ft-s);o+=a.write(r.subarray(0,d)),s+=r.length,s>16777216&&l.full()}),{take:()=>{if(l===null)return``;l=null;let e=o+a.end();return o=``,e},drain:()=>{n===null||n.destroyed||n.readableEnded||zt(e,t,n,()=>u)}}}function zt(e,t,n,r){let{stats:i}=e.scope;if(e.scope.signal.aborted){n.destroy();return}n.once(`close`,()=>{e.drains.delete(n),i?.onDrainClose(t,r())}),n.unref(),e.drains.add(n),i?.onDrainOpen(t)}const Bt=()=>`closed`;function Vt(e,t){e.on(`error`,()=>{}),e.end(t)}async function Ht(e,t){let{stats:n,clock:r}=e.scope,i=bt(e,t.category,t.signal);if(i!==null)return i;let a=r.monotonic();return n?.onStart(t.category),new Promise(i=>{let{spawner:o}=e,s;try{s=o.spawn(t.bin,t.args??[],{cwd:t.cwd,env:ft(e.scope,t),stdio:[`pipe`,`pipe`,`pipe`],detached:!0})}catch(e){n?.onEnd(t.category,Qe(r,a)),i({ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:lt(e,t.cwd)});return}let c=s.pid;c!==void 0&&Mt(e,c);let l=new Promise(e=>s.once(`exit`,e)),u=s.stdin;s.stdin=null;let d=null,f={full:()=>ee(`output-limit`),failed:e=>{d??=e.message,ee(`pipe-error`)}},p=Rt(e,t.category,s.stdout,f),m=Rt(e,t.category,s.stderr,f),h=()=>({stdout:p.take(),stderr:m.take()}),g=!1,_=null,v=null,y=null,b=null,x=()=>ee(`aborted`),S=()=>{t.signal?.removeEventListener(`abort`,x),e.inFlight.delete(x)},C=i=>{g||(g=!0,_?.(),v?.(),y?.(),S(),c!==void 0&&Nt(e,c),n?.onEnd(t.category,Qe(r,a)),s.off(`close`,te),s.off(`error`,D),p.drain(),m.drain(),u!==null&&!u.destroyed&&!u.writableFinished&&zt(e,t.category,u,Bt),i())},w=e=>C(()=>i(e)),T=(n,r)=>{try{o.signalGroup(n,r)}catch(n){e.unreaped.set(s,t.category),l.then(()=>e.unreaped.delete(s)),w({ok:!1,reason:`signal-refused`,...h(),exitCode:null,signal:null,error:n instanceof Error?n.message:String(n)})}},E=()=>te(s.exitCode,s.signalCode);if(c!==void 0){let e=t=>{if(!g){if(o.groupGone(c)){r.defer(E);return}y=r.after(t,()=>e(Math.min(t*2,1e3)))}};l.then(()=>r.defer(()=>e(25)))}let ee=e=>{if(b!==null)return;if((s.exitCode!==null||s.signalCode!==null)&&c!==void 0&&o.groupGone(c)){b=e===`timeout`?null:e,r.defer(E);return}b=e,_?.(),S();let t=s.pid;t!==void 0&&(v=r.after(250,()=>{T(t,`SIGKILL`),l.then(()=>r.defer(E))}),T(t,`SIGTERM`))},D=e=>{w({ok:!1,reason:`spawn-error`,...h(),exitCode:null,signal:null,error:lt(e,t.cwd)})};s.on(`error`,D);let te=(e,n)=>{if(b!==null){w({ok:!1,reason:b,...h(),exitCode:e,signal:n,...b===`timeout`?{error:Lt(t.timeoutMs??0)}:b===`output-limit`?{error:It}:b===`pipe-error`?{error:`a pipe failed to read: ${d}`}:{}});return}if(e===0){w({ok:!0,...h(),exitCode:e});return}w({ok:!1,reason:n?`signal`:`non-zero`,...h(),exitCode:e,signal:n})};s.on(`close`,te),t.timeoutMs&&t.timeoutMs>0&&(_=r.after(t.timeoutMs,()=>ee(`timeout`))),t.signal?.addEventListener(`abort`,x,{once:!0}),e.inFlight.add(x),u!==null&&Vt(u,t.stdinInput)})}function Ut(e,t){let{stats:n,clock:r}=e.scope,i=bt(e,t.category);if(i!==null)return i;let a=r.monotonic();n?.onStart(t.category);try{let i=e.spawner.spawnSync(t.bin,t.args??[],{cwd:t.cwd,env:ft(e.scope,t),input:t.stdinInput,timeout:t.timeoutMs&&t.timeoutMs>0?t.timeoutMs:void 0,stdio:[`pipe`,`pipe`,`pipe`],encoding:`utf8`});n?.onEnd(t.category,Qe(r,a));let o=typeof i.stdout==`string`?i.stdout:``,s=typeof i.stderr==`string`?i.stderr:``,c=i.error?.code;if(i.error&&c!==`EPIPE`&&c!==`ECONNRESET`){let e=c===`ETIMEDOUT`?`timeout`:`spawn-error`;return{ok:!1,reason:e,stdout:o,stderr:s,exitCode:null,signal:i.signal??null,error:e===`timeout`?Lt(t.timeoutMs??0):lt(i.error,t.cwd)}}return i.status===0?{ok:!0,stdout:o,stderr:s,exitCode:i.status}:{ok:!1,reason:i.signal?`signal`:`non-zero`,stdout:o,stderr:s,exitCode:i.status,signal:i.signal??null}}catch(e){return n?.onEnd(t.category,Qe(r,a)),{ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:lt(e,t.cwd)}}}function j(e,t){let{stats:n,clock:r}=e.scope,i=bt(e,t.category);if(i!==null)return i;let a=r.monotonic();n?.onStart(t.category);let o=Wt(e,t);return n?.onEnd(t.category,Qe(r,a)),o}function Wt(e,t){let n;try{n=e.spawner.spawn(t.bin,t.args??[],{cwd:t.cwd,env:ft(e.scope,t),detached:!0,stdio:`ignore`})}catch(e){return{ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:lt(e,t.cwd)}}return n.once(`error`,()=>{}),n.pid===void 0?{ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:`spawn(${t.bin}): no pid (binary not found or unexecutable)`}:(n.unref(),{ok:!0,stdout:``,stderr:``,exitCode:null})}const Gt=e=>e.kind===`exit`?`exit ${e.code}`:`timeout`;function Kt(e,t,n){let{stats:r,clock:i}=e.scope,a=bt(e,t.category);if(a!==null)return{ok:!1,reason:a.reason,error:a.error};let o=i.monotonic();r?.onStart(t.category);let s;try{s=e.spawner.spawn(`/bin/sh`,[`-c`,`out=$1 err=$2 status=$3; shift 3; read go || exit 0; "$@" >"$out" 2>"$err" </dev/null; echo "exit $?" >"$status.$$" && ln "$status.$$" "$status"; rm -f "$status.$$"`,`sh`,n.stdout,n.stderr,n.status,t.bin,...t.args??[]],{cwd:t.cwd,env:ft(e.scope,t),detached:!0,stdio:[`pipe`,`ignore`,`ignore`]})}catch(e){return r?.onEnd(t.category,Qe(i,o)),{ok:!1,reason:`spawn-error`,error:lt(e,t.cwd)}}r?.onEnd(t.category,Qe(i,o)),s.once(`error`,()=>{});let c=s.pid,l=s.stdin;return l.on(`error`,()=>{}),c===void 0?(l.destroy(),{ok:!1,reason:`spawn-error`,error:`spawn(/bin/sh): no pid (shell not found or unexecutable)`}):(s.unref(),l.unref(),{ok:!0,pid:c,release:()=>l.end(`go
|
|
4
|
-
`),withdraw:()=>l.end()})}function qt(e){let t;try{t=C(e,`utf8`).trim()}catch(e){if(e.code===`ENOENT`)return null;throw e}let n=/^exit (\d+)$/.exec(t);if(n)return{kind:`exit`,code:Number(n[1])};if(t===`timeout`)return{kind:`timeout`};throw Error(`${e}: not a job verdict: ${JSON.stringify(t)}`)}function Jt(e,t,n,r,i){let a=ct(r);try{D(a,`${Gt(i)}\n`)}catch(e){if(e.code===`ENOENT`)return{stands:!1,signalled:!1};throw e}let o=!0;try{b(a,r)}catch(e){if(e.code!==`EEXIST`)throw e;o=!1}finally{T(a,{force:!0})}let s=e.signalJob(n,`SIGTERM`);return s&&t.after(250,()=>e.signalJob(n,`SIGKILL`),{unref:!0}),{stands:o,signalled:s}}function Yt(e,t,n){return Xt(e,t,n).launcher}function M(e,t,n){let{launcher:r,state:i}=Xt(e,t,n);return{...r,launchSync:e=>Ut(i,e)}}function Xt(e,t,n){let r={clock:t,launch:e=>yt(i,Ht(i,e)),launchDetachedSync:e=>j(i,e),launchJobSync:(e,t)=>Kt(i,e,t),jobGroupAlive:e=>n.signalJob(e,0),endJob:(e,r,i)=>Jt(n,t,e,r,i),launcherWarnings:(e,t)=>At(i,e,t),answeredPipeEvent:e=>kt(i,e),settled:async()=>(await Promise.all(i.ending),{unreaped:[...i.unreaped.values()]}),__lifelineForTest:()=>{let e=i.lifeline;return{pid:e?.process.pid,cut:()=>{e?.pipe.end(),e&&wt(i,e.process,`cut by a test`)}}}},i={spawner:n,scope:{stats:null,observeWarnings:e=>{let t=e.kind===`launch-pipes`?e.text:e.fault===null?null:Tt(e.fault);t!==null&&process.emitWarning(t)},signal:new AbortController().signal,now:()=>it(new Date(t.now())),...e,clock:t},lastStartAt:new Map,inFlight:new Set,liveGroups:new Set,lifeline:null,fault:null,pipeEvent:null,ending:new Set,unreaped:new Map,drains:new Set};return i.scope.signal.addEventListener(`abort`,()=>{i.inFlight.forEach(e=>e()),i.drains.forEach(e=>e.destroy()),Pt(i)},{once:!0}),{launcher:r,state:i}}const Zt=/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [ 123]\d \d\d:\d\d:\d\d \d{4}$/,Qt=e=>typeof e==`string`&&Zt.test(e)?e:void 0,$t=2e3;async function en(e,t){return rn(await t(tn(e)))}const tn=(e,t=$t)=>({bin:`ps`,args:[`-o`,`lstart=`,`-p`,String(e)],category:`process-fingerprint`,timeoutMs:t,envOverlay:{LC_ALL:`C`,TZ:`UTC`}});function nn(e,t){if(t.kind===`unavailable`)return{pid:e,startTime:null,why:t.detail};let n=Qt(t.token);return n===void 0?{pid:e,startTime:null,why:`ps printed ${JSON.stringify(t.token)}, not a start in the form \`ps -o lstart=\` prints`}:{pid:e,startTime:n}}function rn(e){if(e.ok){let t=e.stdout.trim();return t.length>0?{kind:`start`,token:t}:{kind:`unavailable`,detail:`ps produced no start-time`}}return{kind:`unavailable`,detail:`ps ${pt(e)}`}}function an(e){return{alive:e=>{try{return process.kill(e,0),!0}catch(e){return e.code===`EPERM`}},startTime:t=>en(t,e.launch)}}async function on(e,t,n){if(t===null)return n.alive(e);let r=await n.startTime(e);switch(r.kind){case`start`:return r.token===t;case`unavailable`:return n.alive(e)}}async function sn(e,t){let n=await t(e);return n.kind===`start`?n.token:null}const cn=new Set([`ECONNREFUSED`,`ENOENT`,`ENOTSOCK`]),ln=e=>({cause:cn.has(e.code??``)?`unreachable`:`io_error`,message:e.message}),un={dial(e){let t=ue.createConnection({path:e}),n=!1;return{settled:new Promise(e=>{let r=r=>{t.off(`connect`,i),n=!0,e({ok:!1,failure:ln(r)})},i=()=>{t.off(`error`,r),n=!0,e({ok:!0,conn:t})};t.once(`error`,r),t.once(`connect`,i)}),abandon:()=>{n||(t.removeAllListeners(),t.destroy())}}}},dn=e=>e.isSymbolicLink()?`symlink`:e.isDirectory()?`directory`:e.isFile()?`file`:`other`,fn=e=>({kind:dn(e),size:Number(e.size),mtimeMs:Number(e.mtimeNs)/1e6,mode:Number(e.mode),dev:e.dev,ino:e.ino,birthtimeNs:e.birthtimeNs}),pn={watchReach:process.platform===`darwin`?`tree`:`directory`,statSync:e=>fn(m.statSync(e,{bigint:!0})),lstatSync:e=>fn(m.lstatSync(e,{bigint:!0})),readlinkSync:e=>m.readlinkSync(e),realpathSync:e=>m.realpathSync.native(e),mkdirSync:e=>void m.mkdirSync(e,{recursive:!0}),opendirSync:e=>m.opendirSync(e).closeSync(),readFileSync:e=>m.readFileSync(e,`utf8`),readdirSync:e=>m.readdirSync(e,{withFileTypes:!0}).map(e=>({name:e.name,kind:dn(e)})),writeFileSync:(e,t,{mode:n,flush:r})=>m.writeFileSync(e,t,{mode:n,flush:r}),renameSync:(e,t)=>m.renameSync(e,t),rmSync:e=>{try{m.rmSync(e,{force:!0})}catch(e){let t=e;throw t.code===`ERR_FS_EISDIR`&&(t.code=`EISDIR`),e}},stat:async e=>fn(await m.promises.stat(e,{bigint:!0})),readFile:e=>m.promises.readFile(e,`utf8`),writeFile:(e,t)=>m.promises.writeFile(e,t),readdir:async e=>(await m.promises.readdir(e,{withFileTypes:!0})).map(e=>({name:e.name,kind:dn(e)})),unlink:e=>m.promises.unlink(e),watch:(e,{recursive:t},n)=>{let r=m.watch(e,{persistent:!1,recursive:t},(e,t)=>n(e,t));return{close:()=>r.close(),onError:e=>void r.on(`error`,e)}}};function mn(e){try{return process.kill(e,0),!1}catch(e){return e.code===`EPERM`}}const hn={spawn:(e,t,n)=>de(e,t,n),spawnSync:(e,t,n)=>fe(e,t,n),signalGroup:(e,t)=>{try{process.kill(-e,t)}catch(t){let n=t.code;if(n!==`ESRCH`&&!(n===`EPERM`&&!mn(e)))throw t}},groupGone:e=>{try{return process.kill(-e,0),!1}catch(e){return e.code===`ESRCH`}},signalJob:(e,t)=>{try{return process.kill(-e,t),!0}catch(e){let t=e.code;if(t===`ESRCH`||t===`EPERM`)return!1;throw e}}},gn=(e,t)=>Yt(e,t,hn),_n=(e,t)=>M(e,t,hn);function vn(){let e=$e,t=_n({inherited:process.env},e),n={env:process.env,home:o.homedir(),tmp:o.tmpdir()};return{host:n,home:yn(n),launcher:t,clock:e,dialer:un,parent:e=>nn(process.ppid,rn(t.launchSync(tn(process.ppid,e)))),filesystem:pn}}function yn(e){try{return Ye(e)}catch(e){process.stderr.write(`cc-candybar: ${e instanceof Error?e.message:String(e)}\n`),process.exit(1)}}const bn=/^[A-Za-z0-9_./,:@%+-][A-Za-z0-9_./,:@%+=-]*$/;function xn(e){return`'${e.replaceAll(`'`,`'\\''`)}'`}function Sn(e){return bn.test(e)?e:xn(e)}function Cn(e){return`${e.dir===void 0?``:`cd ${Sn(e.dir)} && `}${e.env.map(([e,t])=>`${e}=${Sn(t)} `).join(``)}${[e.program,...e.args].map(Sn).join(` `)}`}const wn=`cc-extra`;function Tn(e){return s.join(s.dirname(e),wn,`src`,`bun-attach.js`)}function N(e){return s.join(s.dirname(e),`bun-graph.js`)}const En=`attach-preload.cjs`;function Dn(e){return s.join(s.dirname(e),En)}function On(e,t){return Cn({...t,env:[...t.env,[`BUN_OPTIONS`,`--preload ${e.replace(/[\\\s]/g,`\\$&`)}`]]})}const kn=e=>!e.startsWith(`.`)&&!e.endsWith(`~`);function An(e,t){return t.isSymbolicLink()?Buffer.from(m.readlinkSync(e)):m.readFileSync(e)}function jn(e,t,n=kn){return m.readdirSync(t).filter(n).sort().flatMap(n=>{let r=s.join(t,n),i=m.lstatSync(r,{throwIfNoEntry:!1});return i===void 0?[]:i.isDirectory()?jn(e,r):[[s.relative(e,r).split(s.sep).join(`/`),An(r,i)]]})}function Mn(e){let t=ie.createHash(`sha256`);for(let[n,r]of e)t.update(n).update(`\0`).update(r).update(`\0`);return t.digest(`hex`)}function Nn(e){return Mn(jn(e,e))}const Pn=[`Cargo.toml`,`Cargo.lock`,`src`];function Fn(e){return Mn(jn(e,e,e=>Pn.includes(e)))}const In=e=>e.slice(0,7),Ln=`1.211.1`;function Rn(e){let t=s.dirname(s.dirname(e));return m.existsSync(s.join(t,`src`))?t:null}function zn(e){if(e===null)throw Error("this bundle carries no source digest (build via `pnpm build`, which stamps it)");return{version:Ln,digest:e}}function Bn(){return`219828da25ec47946f0faa5bacca4cbcd382e85fbdbc932997be67ffd061a65a`}function Vn(e){let t=JSON.parse(m.readFileSync(s.join(e,`package.json`),`utf8`)),n=typeof t==`object`&&t?t.version:void 0;if(typeof n!=`string`)throw Error(`${s.join(e,`package.json`)} has no version string`);return n}function Hn(e,t){try{let n=Rn(i(e));if(n===null)return{kind:`not-source-checkout`};let r=t(),a=Nn(s.join(n,`src`));return a===r.digest?{kind:`current`,root:n,stamp:r}:{kind:`stale`,root:n,source:{version:Vn(n),digest:a},running:r}}catch(e){return{kind:`unchecked`,reason:e.message}}}function Un(e,t){try{return e.statSync(t).kind===`directory`?e.realpathSync(t):null}catch{return null}}function Wn(e,t){let n=Un(e,t),r=s.dirname(t);if(n!==null||r===t)return{dir:n??t,rest:[]};let i=Wn(e,r);return{dir:i.dir,rest:[...i.rest,s.basename(t)]}}function Gn(e,t){let{dir:n,rest:r}=Wn(e,t);return s.join(n,...r)}function Kn(e){return e.kind===`main`?s.join(e.roots.state,`cc-candybar`):s.join(e.root,`state`)}function qn(e){return e.kind===`main`?s.join(e.roots.cache,`cc-candybar`):s.join(e.root,`cache`)}function Jn(e){return e.kind===`main`?s.join(e.roots.config,`cc-candybar`):s.join(e.root,`config`)}function Yn(e){return Zn(e.kind===`main`?Jn(e):e.root)}const Xn=e=>Gn(pn,e);function Zn(e){return{dir:e,onDisk:Xn}}function Qn(e){return e.kind===`main`&&e.legacySocket!==null?e.legacySocket:s.join(e.runtime,Ge(e.name))}function $n(e){return s.join(qe(),Ge(e))}function er(e){return e.kind===`main`?{[Re]:``,[ze]:``,[Be]:e.runtime,XDG_STATE_HOME:e.roots.state,XDG_CACHE_HOME:e.roots.cache,XDG_CONFIG_HOME:e.roots.config,CC_CANDYBAR_SOCKET:e.legacySocket??``}:{[Re]:e.root,[ze]:e.name,[Be]:e.runtime,CC_CANDYBAR_SOCKET:``}}function tr(e){m.mkdirSync(e,{recursive:!0,mode:448});let t=m.lstatSync(e);if(t.isSymbolicLink())throw Error(`directory is a symlink: ${e}`);if(!t.isDirectory())throw Error(`not a directory: ${e}`);let n=process.getuid();if(t.uid!==n)throw Error(`directory is not owned by uid ${n}: ${e} (owner uid=${t.uid})`);if(t.mode&63)throw Error(`directory has unsafe permissions: ${e} (mode=${(t.mode&511).toString(8)}, expected 0700)`)}function nr(e){tr(s.dirname(e));for(let t of[e,rr(e)])try{if(m.lstatSync(t).isSymbolicLink())throw Error(`path is a symlink: ${t}`)}catch(e){if(e.code!==`ENOENT`)throw e}}function rr(e){return`${e}.lease`}function ir(e){return rr(Qn(e))}function ar(e){return s.join(Kn(e),`session-state.json`)}function or(e){return s.join(Kn(e),`settings-history.json`)}function sr(e){return e.env.CC_CANDYBAR_DAEMON_REGISTRY_DIR||s.join(qe(),`daemons`)}function cr(e){return s.join(Kn(e),`spawn.lock`)}function lr(e){return s.join(Kn(e),`spawn.cooldown`)}function ur(e){return s.join(Kn(e),`spawn.backoff`)}function dr(e){return s.join(Kn(e),`watch-probe`)}function fr(e){return s.join(Kn(e),`daemon.log`)}function pr(e){return s.join(Kn(e),`link-ids`)}function mr(e){return{socket:Qn(e),lease:ir(e),state:Kn(e),log:fr(e),sessionState:ar(e),settingsHistory:or(e),storedRoot:Yn(e),watchProbe:dr(e),spawnBackoff:ur(e),linkIds:pr(e)}}function hr(e){return Ke(e.env,`XDG_DATA_HOME`)??s.join(e.home,`.local`,`share`)}function gr(e,t){let{env:n}=e,r=`/usr/local/share:/usr/share`,i=process.platform===`darwin`?`${s.join(Ke(n,`HOMEBREW_PREFIX`)??`/opt/homebrew`,`share`)}:${r}`:r;return{homeDir:e.home,configDir:Jn(t),dataHome:hr(e),dataDirs:(Ke(n,`XDG_DATA_DIRS`)??i).split(`:`).filter(e=>e!==``)}}function _r(e,t){return vr(e,t).at(-1)}function vr(e,t){let{hops:n,stopped:r}=yr(e,t);if(r!==null)throw r;return n}function yr(e,t){let n=[t];try{for(let t=0;t<xr;t++){let t=br(e,n[n.length-1]);if(t===null)return{hops:n,stopped:null};n.push(t)}return{hops:n,stopped:Error(`${t}: more than ${xr} symbolic links`)}}catch(e){return{hops:n,stopped:e}}}function br(e,t){try{return e.lstatSync(t).kind===`symlink`?s.resolve(e.realpathSync(s.dirname(t)),e.readlinkSync(t)):null}catch(e){let{code:t}=e;if(t===`ENOENT`||t===`ENOTDIR`)return null;throw e}}const xr=40;function Sr(e,t,n,r){let i=_r(e,t);e.mkdirSync(s.dirname(i));let a=ct(i),o=r??wr(e,i);try{e.writeFileSync(a,n,{mode:o,flush:!0}),e.renameSync(a,i)}catch(t){throw e.rmSync(a),t}}function Cr(e,t,n){Sr(pn,e,t,n)}function wr(e,t){try{return e.statSync(t).mode}catch(e){if(e.code===`ENOENT`)return;throw e}}function Tr(e,t,n,r,i){let a=e.dial(t),o=!1;return new Promise(e=>{let t=r.after(n,()=>{o=!0,a.abandon(),e({ok:!1,failure:{cause:`timeout`}})},i);a.settled.then(n=>{t(),o&&n.ok&&n.conn.destroy(),e(n)})})}const Er=[`TERM_PROGRAM`,`TERM_PROGRAM_VERSION`,`TERM`,`ITERM_PROFILE`,`XDG_CONFIG_HOME`];function Dr(e){return Object.fromEntries(Er.flatMap(t=>{let n=e[t]??``;return n===``?[]:[[t,n]]}))}const Or=[`native`,`node`,`frames`];function kr(e,t){return{kind:e,bundle:t,source:null}}const Ar=[`ansi`,`frame`],jr=Object.keys({termCols:!0,termRows:!0,ssh:!0,tmux:!0,configEnv:!0,claudeConfigDir:!0,terminalEnv:!0,parent:!0,client:!0});function Mr(e){let t=Vr(e.termCols),n=Vr(e.termRows),r=Hr(e.ssh),i=zr(e.tmux),a=Rr(e.configEnv),o=Rr(e.claudeConfigDir),s=Lr(e.terminalEnv),c=Ur(e.parent),l=ti(e.client);return{...t!==void 0&&{termCols:t},...n!==void 0&&{termRows:n},...r!==void 0&&{ssh:r},...i!==void 0&&{tmux:i},...a!==void 0&&{configEnv:a},...o!==void 0&&{claudeConfigDir:o},...s!==void 0&&{terminalEnv:s},...c!==void 0&&{parent:c},...l!==void 0&&{client:l}}}function Nr(e,t){return jr.filter(n=>e[n]!==void 0&&t[n]===void 0).map(t=>({hint:t,sent:e[t]}))}function Pr(e){return e.length===0?null:`Client hints refused: ${e.map(({hint:e,sent:t})=>`${e}=${JSON.stringify(t)}`).join(`, `)} — is the statusline client older than the daemon? Reinstall it (\`cc-candybar install\`, or \`just install-rust\` in a checkout).`}const Fr={unknown:e=>`Unknown flags: ${e}`,"no-value":e=>`${e} names no file — the bar renders with no ${e}`,positional:e=>`Unexpected arguments: ${e}`};function Ir(e){let t=Object.keys(Fr).flatMap(t=>{let n=e.filter(e=>e.why===t).map(e=>e.arg);return n.length===0?[]:[Fr[t](n.join(`, `))]});return t.length===0?null:t.join(`
|
|
4
|
+
`),withdraw:()=>l.end()})}function qt(e){let t;try{t=C(e,`utf8`).trim()}catch(e){if(e.code===`ENOENT`)return null;throw e}let n=/^exit (\d+)$/.exec(t);if(n)return{kind:`exit`,code:Number(n[1])};if(t===`timeout`)return{kind:`timeout`};throw Error(`${e}: not a job verdict: ${JSON.stringify(t)}`)}function Jt(e,t,n,r,i){let a=ct(r);try{D(a,`${Gt(i)}\n`)}catch(e){if(e.code===`ENOENT`)return{stands:!1,signalled:!1};throw e}let o=!0;try{b(a,r)}catch(e){if(e.code!==`EEXIST`)throw e;o=!1}finally{T(a,{force:!0})}let s=e.signalJob(n,`SIGTERM`);return s&&t.after(250,()=>e.signalJob(n,`SIGKILL`),{unref:!0}),{stands:o,signalled:s}}function Yt(e,t,n){return Xt(e,t,n).launcher}function M(e,t,n){let{launcher:r,state:i}=Xt(e,t,n);return{...r,launchSync:e=>Ut(i,e)}}function Xt(e,t,n){let r={clock:t,launch:e=>yt(i,Ht(i,e)),launchDetachedSync:e=>j(i,e),launchJobSync:(e,t)=>Kt(i,e,t),jobGroupAlive:e=>n.signalJob(e,0),endJob:(e,r,i)=>Jt(n,t,e,r,i),launcherWarnings:(e,t)=>At(i,e,t),answeredPipeEvent:e=>kt(i,e),settled:async()=>(await Promise.all(i.ending),{unreaped:[...i.unreaped.values()]}),__lifelineForTest:()=>{let e=i.lifeline;return{pid:e?.process.pid,cut:()=>{e?.pipe.end(),e&&wt(i,e.process,`cut by a test`)}}}},i={spawner:n,scope:{stats:null,observeWarnings:e=>{let t=e.kind===`launch-pipes`?e.text:e.fault===null?null:Tt(e.fault);t!==null&&process.emitWarning(t)},signal:new AbortController().signal,now:()=>it(new Date(t.now())),...e,clock:t},lastStartAt:new Map,inFlight:new Set,liveGroups:new Set,lifeline:null,fault:null,pipeEvent:null,ending:new Set,unreaped:new Map,drains:new Set};return i.scope.signal.addEventListener(`abort`,()=>{i.inFlight.forEach(e=>e()),i.drains.forEach(e=>e.destroy()),Pt(i)},{once:!0}),{launcher:r,state:i}}const Zt=/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [ 123]\d \d\d:\d\d:\d\d \d{4}$/,Qt=e=>typeof e==`string`&&Zt.test(e)?e:void 0,$t=2e3;async function en(e,t){return rn(await t(tn(e)))}const tn=(e,t=$t)=>({bin:`ps`,args:[`-o`,`lstart=`,`-p`,String(e)],category:`process-fingerprint`,timeoutMs:t,envOverlay:{LC_ALL:`C`,TZ:`UTC`}});function nn(e,t){if(t.kind===`unavailable`)return{pid:e,startTime:null,why:t.detail};let n=Qt(t.token);return n===void 0?{pid:e,startTime:null,why:`ps printed ${JSON.stringify(t.token)}, not a start in the form \`ps -o lstart=\` prints`}:{pid:e,startTime:n}}function rn(e){if(e.ok){let t=e.stdout.trim();return t.length>0?{kind:`start`,token:t}:{kind:`unavailable`,detail:`ps produced no start-time`}}return{kind:`unavailable`,detail:`ps ${pt(e)}`}}function an(e){return{alive:e=>{try{return process.kill(e,0),!0}catch(e){return e.code===`EPERM`}},startTime:t=>en(t,e.launch)}}async function on(e,t,n){if(t===null)return n.alive(e);let r=await n.startTime(e);switch(r.kind){case`start`:return r.token===t;case`unavailable`:return n.alive(e)}}async function sn(e,t){let n=await t(e);return n.kind===`start`?n.token:null}const cn=new Set([`ECONNREFUSED`,`ENOENT`,`ENOTSOCK`]),ln=e=>({cause:cn.has(e.code??``)?`unreachable`:`io_error`,message:e.message}),un={dial(e){let t=ue.createConnection({path:e}),n=!1;return{settled:new Promise(e=>{let r=r=>{t.off(`connect`,i),n=!0,e({ok:!1,failure:ln(r)})},i=()=>{t.off(`error`,r),n=!0,e({ok:!0,conn:t})};t.once(`error`,r),t.once(`connect`,i)}),abandon:()=>{n||(t.removeAllListeners(),t.destroy())}}}},dn=e=>e.isSymbolicLink()?`symlink`:e.isDirectory()?`directory`:e.isFile()?`file`:`other`,fn=e=>({kind:dn(e),size:Number(e.size),mtimeMs:Number(e.mtimeNs)/1e6,mode:Number(e.mode),dev:e.dev,ino:e.ino,birthtimeNs:e.birthtimeNs}),pn={watchReach:process.platform===`darwin`?`tree`:`directory`,statSync:e=>fn(m.statSync(e,{bigint:!0})),lstatSync:e=>fn(m.lstatSync(e,{bigint:!0})),readlinkSync:e=>m.readlinkSync(e),realpathSync:e=>m.realpathSync.native(e),mkdirSync:e=>void m.mkdirSync(e,{recursive:!0}),opendirSync:e=>m.opendirSync(e).closeSync(),readFileSync:e=>m.readFileSync(e,`utf8`),readdirSync:e=>m.readdirSync(e,{withFileTypes:!0}).map(e=>({name:e.name,kind:dn(e)})),writeFileSync:(e,t,{mode:n,flush:r})=>m.writeFileSync(e,t,{mode:n,flush:r}),renameSync:(e,t)=>m.renameSync(e,t),rmSync:e=>{try{m.rmSync(e,{force:!0})}catch(e){let t=e;throw t.code===`ERR_FS_EISDIR`&&(t.code=`EISDIR`),e}},stat:async e=>fn(await m.promises.stat(e,{bigint:!0})),readFile:e=>m.promises.readFile(e,`utf8`),writeFile:(e,t)=>m.promises.writeFile(e,t),readdir:async e=>(await m.promises.readdir(e,{withFileTypes:!0})).map(e=>({name:e.name,kind:dn(e)})),unlink:e=>m.promises.unlink(e),watch:(e,{recursive:t},n)=>{let r=m.watch(e,{persistent:!1,recursive:t},(e,t)=>n(e,t));return{close:()=>r.close(),onError:e=>void r.on(`error`,e)}}};function mn(e){try{return process.kill(e,0),!1}catch(e){return e.code===`EPERM`}}const hn={spawn:(e,t,n)=>de(e,t,n),spawnSync:(e,t,n)=>fe(e,t,n),signalGroup:(e,t)=>{try{process.kill(-e,t)}catch(t){let n=t.code;if(n!==`ESRCH`&&!(n===`EPERM`&&!mn(e)))throw t}},groupGone:e=>{try{return process.kill(-e,0),!1}catch(e){return e.code===`ESRCH`}},signalJob:(e,t)=>{try{return process.kill(-e,t),!0}catch(e){let t=e.code;if(t===`ESRCH`||t===`EPERM`)return!1;throw e}}},gn=(e,t)=>Yt(e,t,hn),_n=(e,t)=>M(e,t,hn);function vn(){let e=$e,t=_n({inherited:process.env},e),n={env:process.env,home:o.homedir(),tmp:o.tmpdir()};return{host:n,home:yn(n),launcher:t,clock:e,dialer:un,parent:e=>nn(process.ppid,rn(t.launchSync(tn(process.ppid,e)))),filesystem:pn}}function yn(e){try{return Ye(e)}catch(e){process.stderr.write(`cc-candybar: ${e instanceof Error?e.message:String(e)}\n`),process.exit(1)}}const bn=/^[A-Za-z0-9_./,:@%+-][A-Za-z0-9_./,:@%+=-]*$/;function xn(e){return`'${e.replaceAll(`'`,`'\\''`)}'`}function Sn(e){return bn.test(e)?e:xn(e)}function Cn(e){return`${e.dir===void 0?``:`cd ${Sn(e.dir)} && `}${e.env.map(([e,t])=>`${e}=${Sn(t)} `).join(``)}${[e.program,...e.args].map(Sn).join(` `)}`}const wn=`cc-extra`;function Tn(e){return s.join(s.dirname(e),wn,`src`,`bun-attach.js`)}function N(e){return s.join(s.dirname(e),`bun-graph.js`)}const En=`attach-preload.cjs`;function Dn(e){return s.join(s.dirname(e),En)}function On(e,t){return Cn({...t,env:[...t.env,[`BUN_OPTIONS`,`--preload ${e.replace(/[\\\s]/g,`\\$&`)}`]]})}const kn=e=>!e.startsWith(`.`)&&!e.endsWith(`~`);function An(e,t){return t.isSymbolicLink()?Buffer.from(m.readlinkSync(e)):m.readFileSync(e)}function jn(e,t,n=kn){return m.readdirSync(t).filter(n).sort().flatMap(n=>{let r=s.join(t,n),i=m.lstatSync(r,{throwIfNoEntry:!1});return i===void 0?[]:i.isDirectory()?jn(e,r):[[s.relative(e,r).split(s.sep).join(`/`),An(r,i)]]})}function Mn(e){let t=ie.createHash(`sha256`);for(let[n,r]of e)t.update(n).update(`\0`).update(r).update(`\0`);return t.digest(`hex`)}function Nn(e){return Mn(jn(e,e))}const Pn=[`Cargo.toml`,`Cargo.lock`,`src`];function Fn(e){return Mn(jn(e,e,e=>Pn.includes(e)))}const In=e=>e.slice(0,7),Ln=`1.211.2`;function Rn(e){let t=s.dirname(s.dirname(e));return m.existsSync(s.join(t,`src`))?t:null}function zn(e){if(e===null)throw Error("this bundle carries no source digest (build via `pnpm build`, which stamps it)");return{version:Ln,digest:e}}function Bn(){return`0721e8e5de03421c7ac505ce8acb62cd662bccb3ccdab7687c154c24bc84a61c`}function Vn(e){let t=JSON.parse(m.readFileSync(s.join(e,`package.json`),`utf8`)),n=typeof t==`object`&&t?t.version:void 0;if(typeof n!=`string`)throw Error(`${s.join(e,`package.json`)} has no version string`);return n}function Hn(e,t){try{let n=Rn(i(e));if(n===null)return{kind:`not-source-checkout`};let r=t(),a=Nn(s.join(n,`src`));return a===r.digest?{kind:`current`,root:n,stamp:r}:{kind:`stale`,root:n,source:{version:Vn(n),digest:a},running:r}}catch(e){return{kind:`unchecked`,reason:e.message}}}function Un(e,t){try{return e.statSync(t).kind===`directory`?e.realpathSync(t):null}catch{return null}}function Wn(e,t){let n=Un(e,t),r=s.dirname(t);if(n!==null||r===t)return{dir:n??t,rest:[]};let i=Wn(e,r);return{dir:i.dir,rest:[...i.rest,s.basename(t)]}}function Gn(e,t){let{dir:n,rest:r}=Wn(e,t);return s.join(n,...r)}function Kn(e){return e.kind===`main`?s.join(e.roots.state,`cc-candybar`):s.join(e.root,`state`)}function qn(e){return e.kind===`main`?s.join(e.roots.cache,`cc-candybar`):s.join(e.root,`cache`)}function Jn(e){return e.kind===`main`?s.join(e.roots.config,`cc-candybar`):s.join(e.root,`config`)}function Yn(e){return Zn(e.kind===`main`?Jn(e):e.root)}const Xn=e=>Gn(pn,e);function Zn(e){return{dir:e,onDisk:Xn}}function Qn(e){return e.kind===`main`&&e.legacySocket!==null?e.legacySocket:s.join(e.runtime,Ge(e.name))}function $n(e){return s.join(qe(),Ge(e))}function er(e){return e.kind===`main`?{[Re]:``,[ze]:``,[Be]:e.runtime,XDG_STATE_HOME:e.roots.state,XDG_CACHE_HOME:e.roots.cache,XDG_CONFIG_HOME:e.roots.config,CC_CANDYBAR_SOCKET:e.legacySocket??``}:{[Re]:e.root,[ze]:e.name,[Be]:e.runtime,CC_CANDYBAR_SOCKET:``}}function tr(e){m.mkdirSync(e,{recursive:!0,mode:448});let t=m.lstatSync(e);if(t.isSymbolicLink())throw Error(`directory is a symlink: ${e}`);if(!t.isDirectory())throw Error(`not a directory: ${e}`);let n=process.getuid();if(t.uid!==n)throw Error(`directory is not owned by uid ${n}: ${e} (owner uid=${t.uid})`);if(t.mode&63)throw Error(`directory has unsafe permissions: ${e} (mode=${(t.mode&511).toString(8)}, expected 0700)`)}function nr(e){tr(s.dirname(e));for(let t of[e,rr(e)])try{if(m.lstatSync(t).isSymbolicLink())throw Error(`path is a symlink: ${t}`)}catch(e){if(e.code!==`ENOENT`)throw e}}function rr(e){return`${e}.lease`}function ir(e){return rr(Qn(e))}function ar(e){return s.join(Kn(e),`session-state.json`)}function or(e){return s.join(Kn(e),`settings-history.json`)}function sr(e){return e.env.CC_CANDYBAR_DAEMON_REGISTRY_DIR||s.join(qe(),`daemons`)}function cr(e){return s.join(Kn(e),`spawn.lock`)}function lr(e){return s.join(Kn(e),`spawn.cooldown`)}function ur(e){return s.join(Kn(e),`spawn.backoff`)}function dr(e){return s.join(Kn(e),`watch-probe`)}function fr(e){return s.join(Kn(e),`daemon.log`)}function pr(e){return s.join(Kn(e),`link-ids`)}function mr(e){return{socket:Qn(e),lease:ir(e),state:Kn(e),log:fr(e),sessionState:ar(e),settingsHistory:or(e),storedRoot:Yn(e),watchProbe:dr(e),spawnBackoff:ur(e),linkIds:pr(e)}}function hr(e){return Ke(e.env,`XDG_DATA_HOME`)??s.join(e.home,`.local`,`share`)}function gr(e,t){let{env:n}=e,r=`/usr/local/share:/usr/share`,i=process.platform===`darwin`?`${s.join(Ke(n,`HOMEBREW_PREFIX`)??`/opt/homebrew`,`share`)}:${r}`:r;return{homeDir:e.home,configDir:Jn(t),dataHome:hr(e),dataDirs:(Ke(n,`XDG_DATA_DIRS`)??i).split(`:`).filter(e=>e!==``)}}function _r(e,t){return vr(e,t).at(-1)}function vr(e,t){let{hops:n,stopped:r}=yr(e,t);if(r!==null)throw r;return n}function yr(e,t){let n=[t];try{for(let t=0;t<xr;t++){let t=br(e,n[n.length-1]);if(t===null)return{hops:n,stopped:null};n.push(t)}return{hops:n,stopped:Error(`${t}: more than ${xr} symbolic links`)}}catch(e){return{hops:n,stopped:e}}}function br(e,t){try{return e.lstatSync(t).kind===`symlink`?s.resolve(e.realpathSync(s.dirname(t)),e.readlinkSync(t)):null}catch(e){let{code:t}=e;if(t===`ENOENT`||t===`ENOTDIR`)return null;throw e}}const xr=40;function Sr(e,t,n,r){let i=_r(e,t);e.mkdirSync(s.dirname(i));let a=ct(i),o=r??wr(e,i);try{e.writeFileSync(a,n,{mode:o,flush:!0}),e.renameSync(a,i)}catch(t){throw e.rmSync(a),t}}function Cr(e,t,n){Sr(pn,e,t,n)}function wr(e,t){try{return e.statSync(t).mode}catch(e){if(e.code===`ENOENT`)return;throw e}}function Tr(e,t,n,r,i){let a=e.dial(t),o=!1;return new Promise(e=>{let t=r.after(n,()=>{o=!0,a.abandon(),e({ok:!1,failure:{cause:`timeout`}})},i);a.settled.then(n=>{t(),o&&n.ok&&n.conn.destroy(),e(n)})})}const Er=[`TERM_PROGRAM`,`TERM_PROGRAM_VERSION`,`TERM`,`ITERM_PROFILE`,`XDG_CONFIG_HOME`];function Dr(e){return Object.fromEntries(Er.flatMap(t=>{let n=e[t]??``;return n===``?[]:[[t,n]]}))}const Or=[`native`,`node`,`frames`];function kr(e,t){return{kind:e,bundle:t,source:null}}const Ar=[`ansi`,`frame`],jr=Object.keys({termCols:!0,termRows:!0,ssh:!0,tmux:!0,configEnv:!0,claudeConfigDir:!0,terminalEnv:!0,parent:!0,client:!0});function Mr(e){let t=Vr(e.termCols),n=Vr(e.termRows),r=Hr(e.ssh),i=zr(e.tmux),a=Rr(e.configEnv),o=Rr(e.claudeConfigDir),s=Lr(e.terminalEnv),c=Ur(e.parent),l=ti(e.client);return{...t!==void 0&&{termCols:t},...n!==void 0&&{termRows:n},...r!==void 0&&{ssh:r},...i!==void 0&&{tmux:i},...a!==void 0&&{configEnv:a},...o!==void 0&&{claudeConfigDir:o},...s!==void 0&&{terminalEnv:s},...c!==void 0&&{parent:c},...l!==void 0&&{client:l}}}function Nr(e,t){return jr.filter(n=>e[n]!==void 0&&t[n]===void 0).map(t=>({hint:t,sent:e[t]}))}function Pr(e){return e.length===0?null:`Client hints refused: ${e.map(({hint:e,sent:t})=>`${e}=${JSON.stringify(t)}`).join(`, `)} — is the statusline client older than the daemon? Reinstall it (\`cc-candybar install\`, or \`just install-rust\` in a checkout).`}const Fr={unknown:e=>`Unknown flags: ${e}`,"no-value":e=>`${e} names no file — the bar renders with no ${e}`,positional:e=>`Unexpected arguments: ${e}`};function Ir(e){let t=Object.keys(Fr).flatMap(t=>{let n=e.filter(e=>e.why===t).map(e=>e.arg);return n.length===0?[]:[Fr[t](n.join(`, `))]});return t.length===0?null:t.join(`
|
|
5
5
|
`)}function Lr(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=e,n=Er.filter(e=>t[e]!==void 0);return n.every(e=>typeof t[e]==`string`&&t[e]!==``)?Object.fromEntries(n.map(e=>[e,t[e]])):void 0}function Rr(e){return typeof e==`string`&&s.isAbsolute(e)?e:void 0}function zr(e){if(e===null)return null;if(typeof e!=`object`)return;let{socket:t,pane:n,truecolor:r}=e;if(!(typeof t!=`string`||t===``)&&!(typeof n!=`string`||n===``)&&!(r!==null&&(typeof r!=`string`||r===``)))return{socket:t,pane:n,truecolor:r}}const Br=1e4;function Vr(e){if(typeof e!=`number`||!Number.isFinite(e))return;let t=Math.floor(e);if(!(t<=0))return t>Br?Br:t}function Hr(e){return typeof e==`boolean`?e:void 0}function Ur(e){if(typeof e!=`object`||!e)return;let{pid:t,startTime:n,why:r}=e;if(!Number.isSafeInteger(t)||t<=0)return;if(n===null)return typeof r==`string`&&r!==``?{pid:t,startTime:null,why:r}:void 0;let i=Qt(n);return i===void 0?void 0:{pid:t,startTime:i}}const Wr=new Set([...[],1]);function Gr(e){return typeof e==`object`&&e&&e.kind===`url`?{kind:`url`,frame:e}:{kind:`request`,req:e}}const Kr=Math.floor((2**31-1)/1e3)-60;function qr(e){return typeof e==`number`&&e>0&&e<=Kr?{ok:!0,seconds:e}:{ok:!1,problem:`is not a span of seconds above 0 and at most ${Kr}`}}var Jr=class extends Error{constructor(e){super(e),this.name=`ProtocolError`}},Yr=class extends Error{constructor(e){super(e===`connect`?`CONNECT_TIMEOUT`:`TIMEOUT`),this.phase=e,this.name=`ClientTimeoutError`}};function Xr(e){return Zr(JSON.stringify(e))}function Zr(e){let t=Buffer.from(e,`utf8`),n=Buffer.alloc(4);return n.writeUInt32BE(t.length,0),Buffer.concat([n,t])}function Qr(e,t){let n=Buffer.alloc(0);return function(r){for(n=Buffer.concat([n,r]);n.length>=4;){let r=n.readUInt32BE(0);if(r>16777216){t(new Jr(`frame too large: ${r}`));return}if(n.length<4+r)return;let i=n.subarray(4,4+r);n=n.subarray(4+r);try{e(JSON.parse(i.toString(`utf8`)))}catch(e){let n=new Jr(e instanceof Error?e.message:String(e));e instanceof Error&&(n.cause=e),t(n);return}}}}function $r(e,t,n){let r=null,i=Qr(e=>void(r??={ok:!0,frame:e}),e=>void(r??={ok:!1,err:e})),a=o=>{i(o),r!==null&&(e.off(`data`,a),r.ok?t(r.frame):n(r.err))};e.on(`data`,a)}function ei(e,t,n,r){return new Promise((i,a)=>{let o=!1,s=t=>{if(!o){o=!0,c(),e.off(`data`,l),e.off(`error`,u),e.off(`close`,d);try{t()}catch{}}},c=r.after(n-r.now(),()=>{s(()=>{e.destroy(),a(new Yr(`deadline`))})}),l=Qr(e=>s(()=>i(e)),e=>s(()=>a(e))),u=e=>s(()=>a(e)),d=()=>s(()=>a(Error(`socket closed before response`)));e.on(`data`,l),e.on(`error`,u),e.on(`close`,d),e.write(Xr(t))})}function ti(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let{kind:t,bundle:n,source:r}=e,i=Rr(n);return Or.includes(t)&&i!==void 0&&(r===null||typeof r==`string`&&r!==``)?{kind:t,bundle:i,source:r}:void 0}async function ni(e,t,n,r){let i=await Tr(e.dialer,Qn(e.home),n.connectMs,e.clock);return i.ok?ii(i.conn,e.clock,t,n,r):ri(i.failure)}function ri(e){return e.cause===`timeout`?{kind:`busy`,phase:`connect`,message:new Yr(`connect`).message}:{kind:`transient`,cause:e.cause,message:e.message}}async function ii(e,t,n,r,i){try{let a=t.now()+r.budgetMs,o=n(a),s=await ei(e,{v:3,...o},a,t);return si(o.kind,s,i)}catch(e){return ci(e)}finally{e.destroy()}}function ai(e,t){return typeof e==`string`?e:t}function oi(e){return typeof e==`number`&&Number.isInteger(e)&&e>=0?e:0}function si(e,t,n){let r=t;if(r.ok===!0){let r=n(t);return r===void 0?{kind:`permanent`,cause:`malformed_response`,message:`ok response without payload for "${e}" request`}:{kind:`ok`,value:r}}let i=ai(r.error,`(no error message)`);switch(r.code){case`VERSION_MISMATCH`:return{kind:`permanent`,cause:`version_mismatch`,clientV:3,daemonV:oi(r.daemonV)};case`TIMEOUT`:return{kind:`busy`,phase:`deadline`,message:i};case`BAD_REQUEST`:return{kind:`permanent`,cause:`bad_request`,message:i};case`RENDER_FAILED`:return{kind:`permanent`,cause:`render_failed`,message:i};case`SWITCHED_OFF`:return{kind:`permanent`,cause:`switched_off`,message:i};default:return{kind:`permanent`,cause:`malformed_response`,message:`unknown error code: ${String(r.code)}`}}}function ci(e){if(e instanceof Jr||e instanceof SyntaxError)return{kind:`permanent`,cause:`malformed_response`,message:e instanceof Error?e.message:String(e)};let t=e instanceof Error?e.message:String(e);return e instanceof Yr?{kind:`busy`,phase:e.phase,message:t}:{kind:`transient`,cause:`io_error`,message:t}}function li(e){if(e.kind===`busy`)return`daemon busy (${e.message})`;if(e.kind===`transient`)return`daemon unavailable (${e.cause}: ${e.message})\nHint: daemon may not be running. Run \`cc-candybar\` once to spawn it.`;switch(e.cause){case`version_mismatch`:{let t=e.daemonV===0?`unknown`:`v${e.daemonV}`;return`daemon protocol mismatch (client v${e.clientV} ≠ daemon ${t})`}case`bad_request`:case`render_failed`:case`switched_off`:case`malformed_response`:return`daemon error (${e.cause}): ${e.message}`}}function ui(e){return e===void 0?{kind:`unstated`}:typeof e==`number`&&Number.isSafeInteger(e)&&e>0?{kind:`stated`,at:e}:{kind:`refused`,problem:`request 'deadline' is not epoch milliseconds: ${JSON.stringify(e)}`}}function di(e,t,n){let r=e.kind===`stated`?n.monoMs+(e.at-n.epochMs):t+150-50,i=Math.min(r,t+200);return Math.round(i-60-n.monoMs)}const fi={connectMs:50,budgetMs:150},pi={connectMs:50,budgetMs:350};function mi(e){let t=e.output;return typeof t==`string`?t:void 0}function hi(e){return si(`render`,e,mi)}function gi(e,t,n,r,i,a=fi){return ni(e,e=>({kind:`render`,hookData:t,args:n,cwd:r,deadline:e,...i}),a,mi)}function _i(e,t,n){return ni(e,()=>({kind:`pane-session`,socket:t,pane:n}),pi,e=>`paneSession`in e?e.paneSession:void 0)}function vi(e,t){return ni(e,()=>({kind:`click`,url:t}),pi,mi)}const yi=5e3;async function bi(e){let t=[];for(let n of e){let e=await n.read();if(e.kind===`text`)return`# memory report from: ${n.name}\n${e.text}`;t.push(`# ${n.name}: unavailable — ${e.reason}`)}return[`# memory report: no probe answered`,...t.length>0?t:[`# no probe is known for this platform`]].join(`
|
|
6
6
|
`)}const xi=`/usr/bin/footprint`;function Si(e,t,n){return t===`darwin`?[Ei(e,xi,[`-p`,String(n)]),Ei(e,`/usr/bin/vmmap`,[`--summary`,String(n)])]:t===`linux`?[Di(`/proc/self/smaps_rollup`),Di(`/proc/self/status`)]:[]}function Ci(e,t,n){return t===`darwin`?wi(n,t=>e.launch({bin:xi,args:t,timeoutMs:yi,category:`limits.charge`})):async e=>({kind:`charged`,measure:`rss`,bytes:e})}function wi(e,t){return async n=>{let r=await t([`-p`,String(e),`--noCategories`,`-f`,`bytes`]);if(!r.ok)return{kind:`stand-in`,bytes:n,unread:`footprint ${gt(r)}`};let i=Ti(r.stdout);return i===null?{kind:`stand-in`,bytes:n,unread:`footprint printed no phys_footprint line`}:{kind:`charged`,measure:`phys_footprint`,bytes:i}}}function Ti(e){let t=/^\s*phys_footprint:\s+(\d+) B\s*$/m.exec(e);return t===null?null:Number(t[1])}function Ei(e,t,n){return{name:`${t} ${n.join(` `)}`,read:async()=>{let r=await e.launch({bin:t,args:[...n],timeoutMs:yi,category:`limits.memory-report`});return r.ok?r.stdout.trim().length>0?{kind:`text`,text:r.stdout}:{kind:`unavailable`,reason:`exited 0 but printed nothing`}:{kind:`unavailable`,reason:gt(r)}}}}function Di(e){return{name:e,read:async()=>{try{let t=m.readFileSync(e,`utf8`);return t.trim().length>0?{kind:`text`,text:t}:{kind:`unavailable`,reason:`empty file`}}catch(e){return{kind:`unavailable`,reason:e.message}}}}}const Oi=`CC_CANDYBAR_RSS_LIMIT_MB`;function ki(e){let t=e[Oi];if(t===void 0)return 1024;let n=/^\d+$/.test(t)?Number(t):NaN;if(!Number.isSafeInteger(n)||n<=0)throw Error(`${Oi} must be a positive integer (MB), got ${JSON.stringify(t)}`);return n}function Ai(e){return ki(e)*2}const ji=1024*1024,Mi=e=>Math.round(e/ji);function Ni(e){return ki(e)*ji}const Pi={memoryReport:{prefix:`memory-`,suffix:`.txt`},heapSnapshot:{prefix:`heap-`,suffix:`.heapsnapshot`}};function Fi(e,t){return e>t}function Ii(e,t){if(e.kind===`charged`)return e;let n=t.kind===`unmeasured`?0:t.charge.kind===`charged`?t.rss-t.charge.bytes:t.charge.gap;return{...e,bytes:e.bytes-n,gap:n}}const Li=.75;function Ri(e,t){return e>t*Li}function zi(e,t,n){let{prefix:r,suffix:i}=Pi[t];return s.join(e,`${r}${n}${i}`)}function Bi(e){for(let t of Object.keys(Pi)){let{prefix:n,suffix:r}=Pi[t];if(e.startsWith(n)&&e.endsWith(r))return t}return null}function Vi(e){let t=e.limitBytes??1024*ji,n=e.snapshotsKeep??3,r=!1,i={kind:`unmeasured`},a=null,o=!1,s;function c(){return a??=l().finally(()=>{a=null}),a}async function l(){if(r)return!0;let{rss:a,heapTotal:s}=e.memoryBytes(),c=Ii(await e.memoryCharge(a),i),l={kind:`measured`,charge:c,rss:a,heapTotal:s};if(i=l,e.log(`info`,`memory ${Wi(l,t)}`),o||c.bytes<=t)return!1;r=!0,e.log(`warn`,`${Hi(c)} > limit ${Mi(t)} MB (rss ${Mi(a)} MB, v8 heap ${Mi(s)} MB); recording memory then shutting down`);let u=`${new Date(e.clock.now()).toISOString().replace(/[:.]/g,`-`)}-${e.pid}`;return await Gi(e.log,`memory report`,async()=>{let t=zi(e.snapshotDir,`memoryReport`,u),n=await e.captureMemoryReport();o||(e.writeMemoryReport(t,n),e.log(`info`,`memory report written: ${t}`))}),o?(e.log(`info`,`daemon closed during the breach: no snapshot, no exit`),!1):(await Gi(e.log,`heap snapshot`,()=>{e.writeLogNow();let t=zi(e.snapshotDir,`heapSnapshot`,u);e.log(`info`,`heap snapshot written: ${e.writeHeapSnapshot(t)}`)}),await Gi(e.log,`artifact rotation`,async()=>{for(let{artifacts:t}of Ki(e.listArtifacts()).slice(n))for(let n of Object.values(t))await Gi(e.log,`evicting ${n}`,()=>e.removeFile(n))}),e.shutdown(0),!0)}function u(){return i.kind===`measured`&&Ri(i.charge.bytes,t)?`${Hi(i.charge)} approaching limit ${Mi(t)} MB (v8 heap ${Mi(i.heapTotal)} MB)`:null}function d(){let n;try{n={kind:`ok`,value:Ki(e.listArtifacts())}}catch(e){n={kind:`failed`,reason:e.message}}return{pid:e.pid,memory:i,limit:t,postMortems:n}}function f(t=6e4){let n=async()=>{try{if(await c())return}catch(t){e.log(`warn`,`memory check failed: ${t.message}`)}o||(s=e.clock.after(t,()=>void n(),{unref:!0}))};n()}function p(){o=!0,s?.()}return{check:c,describeNextRestart:u,serving:d,arm:f,disarm:p}}function Hi(e){return e.kind===`charged`?`${e.measure} ${Mi(e.bytes)} MB`:`rss ${Mi(e.bytes+e.gap)} MB${e.gap===0?``:` less its last ${Mi(e.gap)} MB gap`} (standing in: ${e.unread})`}function Ui(e){return e.kind===`charged`?e.measure:`rss-stand-in`}function Wi({charge:e,rss:t,heapTotal:n},r){let i=e.kind===`stand-in`?` unread=${JSON.stringify(e.unread)} gap=${Mi(e.gap)}MB`:``;return`measure=${Ui(e)} charge=${Mi(e.bytes)}MB rss=${Mi(t)}MB heap=${Mi(n)}MB limit=${Mi(r)}MB${i}`}async function Gi(e,t,n){try{await n()}catch(n){e(`warn`,`${t} failed: ${n.message}`)}}function Ki(e){let t=new Map;for(let n of e){let e=s.basename(n),r=Bi(e);if(r===null)continue;let{prefix:i,suffix:a}=Pi[r],o=e.slice(i.length,e.length-a.length);t.set(o,{...t.get(o),[r]:n})}let n=Object.keys(Pi);return[...t].sort(([e],[t])=>Fi(e,t)?-1:1).map(([e,t])=>({identity:e,artifacts:Object.fromEntries(n.flatMap(e=>t[e]===void 0?[]:[[e,t[e]]]))}))}function qi(e,t,n,r={}){let i=n.snapshotDir;return{clock:n.clock,pid:process.pid,snapshotDir:i,log:n.log,memoryBytes:()=>{let e=process.memoryUsage();return{rss:e.rss,heapTotal:e.heapTotal}},memoryCharge:Ci(n.launcher,process.platform,process.pid),captureMemoryReport:()=>bi(Si(n.launcher,process.platform,process.pid)),writeMemoryReport:(e,t)=>m.writeFileSync(e,t,{mode:384}),writeHeapSnapshot:e=>pe.writeHeapSnapshot(e),writeLogNow:n.writeLogNow,listArtifacts:()=>{let e;try{e=m.readdirSync(i)}catch(e){if(e.code===`ENOENT`)return[];throw e}return e.filter(e=>Bi(e)!==null).map(e=>s.join(i,e))},removeFile:e=>m.unlinkSync(e),shutdown:t,startedAtMs:e,...r}}function Ji(e,n={}){let{home:r,clock:i}=e;if(ca(r)!==null)return;let a=n.spawn??(()=>ua(e)),o=aa(r,i);if(o.kind===`contended`){let e=Xi(r,i);e!==null&&e>2e3&&(t.stderr.write(`cc-candybar: spawn-lock held ${e}ms (likely crashed holder) — spawning unlocked\n`),Yi(r,i,a));return}if(o.kind===`error`){t.stderr.write(`cc-candybar: spawn-lock unavailable (${o.reason}) — spawning unlocked\n`),Yi(r,i,a);return}try{Yi(r,i,a)}finally{sa()}}function Yi(e,t,n){ta(e,t)&&Zi(n)}function Xi(e,t){try{let n=m.statSync(cr(e));return t.now()-n.mtimeMs}catch{return null}}function Zi(e){try{e()||t.stderr.write(`cc-candybar: daemon spawn returned false (unable to resolve script path?)
|
|
7
7
|
`)}catch(e){t.stderr.write(`cc-candybar: daemon spawn failed: ${e.message}\n`)}}function eee(e,t){return e===null?{kind:`allow`}:e<-1e4?{kind:`allow-future-garbage`,futureMs:-e}:e<t?{kind:`deny`}:{kind:`allow`}}function tee(e){return Math.min(3e3*2**Math.min(Math.max(e,0),5),6e4)}function Qi(e){try{let t=m.readFileSync(e,`utf8`).trim(),n=Number(t);return!Number.isInteger(n)||n<0?0:Math.min(n,5)}catch{return 0}}function $i(e,n){try{m.mkdirSync(s.dirname(e),{recursive:!0}),m.writeFileSync(e,String(n),{mode:384})}catch(e){t.stderr.write(`cc-candybar: could not record spawn.backoff: ${e.message}\n`)}}function ea(e){try{m.unlinkSync(e)}catch(e){e.code!==`ENOENT`&&t.stderr.write(`cc-candybar: could not reset spawn.backoff: ${e.message}\n`)}}function ta(e,n){let r=lr(e),i=ur(e),a=Qi(i),o=eee(na(r,n),tee(a));return o.kind===`deny`?!1:(o.kind===`allow-future-garbage`&&t.stderr.write(`cc-candybar: spawn.cooldown mtime is ${o.futureMs}ms in the future — ignoring and spawning\n`),ra(r,n),$i(i,Math.min(a+1,5)),!0)}function na(e,t){try{return t.now()-m.statSync(e).mtimeMs}catch{return null}}function ra(e,n){try{m.mkdirSync(s.dirname(e),{recursive:!0}),m.writeFileSync(e,`${t.pid} ${n.now()}\n`,{mode:384})}catch(e){t.stderr.write(`cc-candybar: could not record spawn.cooldown: ${e.message}\n`)}}let ia=null;function aa(e,n){let r=cr(e);for(let e=0;e<2;e++){try{let e=m.openSync(r,`wx`,384);try{m.writeSync(e,JSON.stringify({pid:t.pid,ts:n.now()}))}catch{}return ia={fd:e,path:r},{kind:`held`}}catch(e){let t=e.code;if(t!==`EEXIST`)return{kind:`error`,reason:`openSync(${r}): ${t??e.message}`}}if(!oa(r,n))return{kind:`contended`};try{m.unlinkSync(r)}catch(e){if(e.code!==`ENOENT`)return{kind:`error`,reason:`unlink stale spawn.lock: ${e.message}`}}}return{kind:`contended`}}function oa(e,t){try{let n=m.statSync(e);return t.now()-n.mtimeMs>1e4}catch{return!0}}function sa(){if(!ia)return;let{fd:e,path:t}=ia;ia=null;try{m.closeSync(e)}catch{}try{m.unlinkSync(t)}catch{}}function ca(e){try{return m.mkdirSync(Kn(e),{recursive:!0}),null}catch(t){return`mkdir ${Kn(e)}: ${t.message}`}}function la(e,t){return[`--max-old-space-size=${Ai(t)}`,e,`daemon`]}function ua({host:e,launcher:n}){let r=t.execPath,i=t.argv[1];return i?n.launchDetachedSync({bin:r,args:la(i,e.env),category:`daemon-spawn`}).ok:!1}const da=`cc-candybar`,fa=`CCCandybarURLHandler`,pa=e=>e.startsWith(`${da}://`),ma=`closed`,ha=`open`,ga=`🍫`;function _a(e,t,n){if(t===0)return`${e} needs a display (the clickable text)`;if(t!==1&&t!==n)return`${e} cycles ${n} members; bind one display per member (${n}) or one static display, got ${t}`}function va(e,t,n,r){let i=_a(e,t.length,n);if(i!==void 0)throw Error(i);return t.length===1?t[0]:t[r]}function ya(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}function ba(e,t,n,r,i){return{kind:`segment`,name:e,opens:{ref:t,body:n,placement:r},...i!==void 0&&{when:i}}}function xa(e,...t){return`{{ and ${[e,...t].map(Sa).join(` `)} }}`}function Sa(e){return`(eq .${e.variable} "${ya(e.member)}")`}function Ca(e,t,n){return`{{ ${wa(e,Ta(t),Ta(n))} }}`}function wa(e,t,n){return`action "${e}" ${t} ${n}`}function Ta(e){return`"${ya(e)}"`}function Ea(e,t){return{kind:`state`,key:e,default:t}}function Da(e,t){return{set:e,cycle:[ma,t]}}function Oa(e){if(!(`set`in e&&`cycle`in e))return;let[t,n,...r]=e.cycle;return t===`closed`&&n!==void 0&&r.length===0?{key:e.set,member:n}:void 0}var ka=De(((e,t)=>{t.exports.Space_Separator=/[\u1680\u2000-\u200A\u202F\u205F\u3000]/,t.exports.ID_Start=/[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE83\uDE86-\uDE89\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]/,t.exports.ID_Continue=/[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u08D4-\u08E1\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u09FC\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9-\u0AFF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C80-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D00-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D54-\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19D9\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1CD0-\u1CD2\u1CD4-\u1CF9\u1D00-\u1DF9\u1DFB-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE3E\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC00-\uDC4A\uDC50-\uDC59\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDE00-\uDE3E\uDE47\uDE50-\uDE83\uDE86-\uDE99\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC36\uDC38-\uDC40\uDC50-\uDC59\uDC72-\uDC8F\uDC92-\uDCA7\uDCA9-\uDCB6\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD36\uDD3A\uDD3C\uDD3D\uDD3F-\uDD47\uDD50-\uDD59]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD838[\uDC00-\uDC06\uDC08-\uDC18\uDC1B-\uDC21\uDC23\uDC24\uDC26-\uDC2A]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6\uDD00-\uDD4A\uDD50-\uDD59]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/})),Aa=De(((e,t)=>{let n=ka();t.exports={isSpaceSeparator(e){return typeof e==`string`&&n.Space_Separator.test(e)},isIdStartChar(e){return typeof e==`string`&&(e>=`a`&&e<=`z`||e>=`A`&&e<=`Z`||e===`$`||e===`_`||n.ID_Start.test(e))},isIdContinueChar(e){return typeof e==`string`&&(e>=`a`&&e<=`z`||e>=`A`&&e<=`Z`||e>=`0`&&e<=`9`||e===`$`||e===`_`||e===``||e===``||n.ID_Continue.test(e))},isDigit(e){return typeof e==`string`&&/[0-9]/.test(e)},isHexDigit(e){return typeof e==`string`&&/[0-9A-Fa-f]/.test(e)}}})),ja=De(((e,t)=>{let n=Aa(),r,i,a,o,s,c,l,u,d;t.exports=function(e,t){r=String(e),i=`start`,a=[],o=0,s=1,c=0,l=void 0,u=void 0,d=void 0;do l=v(),ee[i]();while(l.type!==`eof`);return typeof t==`function`?f({"":d},``,t):d};function f(e,t,n){let r=e[t];if(typeof r==`object`&&r)if(Array.isArray(r))for(let e=0;e<r.length;e++){let t=String(e),i=f(r,t,n);i===void 0?delete r[t]:Object.defineProperty(r,t,{value:i,writable:!0,enumerable:!0,configurable:!0})}else for(let e in r){let t=f(r,e,n);t===void 0?delete r[e]:Object.defineProperty(r,e,{value:t,writable:!0,enumerable:!0,configurable:!0})}return n.call(e,t,r)}let p,m,h,g,_;function v(){for(p=`default`,m=``,h=!1,g=1;;){_=y();let e=x[p]();if(e)return e}}function y(){if(r[o])return String.fromCodePoint(r.codePointAt(o))}function b(){let e=y();return e===`
|
|
@@ -490,7 +490,7 @@ function run(argv) {
|
|
|
490
490
|
`)+1,a=0,o=0;for(let e of n.slice(r,i).split(`
|
|
491
491
|
`)){let t=C2(e);t.kind!==`blank`&&(a++,t.kind===`unparsed`&&o++)}return{lines:a,unparsed:o,whole:t}}function R4(e){let t=Wo(e,IF+1);return t.kind===`ok`?P(L4(t.value.buf,t.value.fromStart)):t}function z4(e,t){if(t.kind===`failed`)return t;let n=new Map;for(let{path:e,answered:r}of t.value)n.set(e,r||(n.get(e)??!1));return{kind:`ok`,value:[...n].map(([t,n])=>({path:t,answered:n,read:e.transcript(t)}))}}const B4={github:{loginHost:()=>`github.com`,args:e=>[`auth`,`token`,`--hostname`,e],nonZero:`logged-out`},gitlab:{loginHost:e=>e,args:()=>[`--version`],nonZero:`failed`}};async function V4(e,t,n){if(vc(t,n)===void 0)return{kind:`ok`,value:null};let r=aW(await e.launch({bin:`git`,args:[...iW],cwd:n,envOverlay:{GIT_OPTIONAL_LOCKS:`0`},timeoutMs:2e3,category:`doctor.forge`}));if(r.kind===`failed`)return r;let i=uW(r.value);if(i===null)return{kind:`ok`,value:null};let a=rW(i);if(a===null)return{kind:`ok`,value:null};let o=QU[a],s=B4[a],c=s.loginHost(nW(i)),l=await e.launch({bin:o,args:[...s.args(c)],cwd:n,timeoutMs:2e3,category:`doctor.forge`});return H4(o,c,s.nonZero,l)}function H4(e,t,n,r){let i=n=>({kind:`ok`,value:{cli:e,host:t,status:n}});return r.ok?i(`ready`):$U(r)?i(`missing`):r.reason===`non-zero`&&n===`logged-out`?i({loggedOut:YU(r.stderr)}):{kind:`failed`,reason:JU(e,r)}}function U4(e,t){let n={layers:e.layers,target:t,warnings:e.warning===null?[]:e.warning.split(`
|
|
492
492
|
`),repos:e.repos};return e.error===null?{...n,kind:`loaded`,unused:e.unused}:{...n,kind:`failed`,error:e.error}}const W4=e=>x4(()=>uee(e));function G4(e,t){let n=e=>JSON.stringify([e.managedDir,e.projectDir,e.userFile]),r=n(e),i=[],a=new Map;for(let o of t){let t={managedDir:e.managedDir,projectDir:o.projectDir,userFile:Jo(o.claudeConfigDir)},s=n(t);if(s===r)i.push(o);else{let e=a.get(s)??{at:t,bars:[]};e.bars.push(o),a.set(s,e)}}let o=(e,t)=>({at:e,sources:W4(e),bars:t.map(({role:e,frame:t})=>({role:e,frame:t}))});return{origin:o(e,i),elsewhere:[...a.values()].map(({at:e,bars:t})=>o(e,t))}}async function K4(e,t){return t===void 0?{kind:`unreported`}:t===null?{kind:`outside`}:{kind:`inside`,hint:t,client:await e.probeTmux(t)}}function q4(e,t){switch(e.kind){case`unreported`:return{kind:`unreported`};case`outside`:return t===void 0?{kind:`unreported`}:{kind:`seen`,identified:ere(t),tmuxClient:null};case`inside`:{if(e.client.kind===`failed`)return{kind:`unasked`,reason:e.client.reason};let t=e.client.value;return t===null?{kind:`unasked`,reason:`tmux has no client attached to the pane's session`}:{kind:`seen`,identified:$ne(t),tmuxClient:t}}}}async function J4(e,t,n,r){if(t.kind!==`seen`)return t;let{identified:i,tmuxClient:a}=t,o=n.terminalEnv;if(i.kind!==`known`)return i;let{name:s,version:c}=i.terminal;if(Jne(s))return{kind:`bundling`,name:s,version:c};if(!Yne(s))return{kind:`unread`,name:s,version:c};let{ITERM_PROFILE:l,...u}=o??{},d=a===null?{kind:`ok`,value:n.ssh===!0}:await e.remoteLogin(a.pid);return{kind:`configured`,name:s,version:c,font:d.kind===`failed`?{kind:`failed`,reason:`whether the terminal is remote could not be asked: ${d.reason}`}:d.value?{kind:`failed`,reason:`the terminal is on the far side of a remote login, so its font is on the machine it runs on`}:await e.fontInUse({name:s,version:c},a===null?o??{}:u,r)}}function Y4(e){switch(e.via){case`link`:return{kind:`arrived`,delivery:e.delivery};case`tmux-status`:return{kind:`unprobed`,reason:"this run was asked from the tmux status line, whose clicks tmux runs rather than the URL handler — run `cc-candybar doctor` to probe the handler"}}}async function X4(e,t){let[n,...r]=e;return n===void 0?{kind:`unneeded`}:{kind:`needed`,segments:[n,...r],fact:await t()}}async function Z4(e,t,n,r){return{pullRequests:await X4(t.pullRequests,()=>e.forge(n.cwd)),rateLimits:await X4(t.rateLimits,()=>r)}}function Q4(e,t){let n=t.find(e=>e.role===`statusline`);return n===void 0?{kind:`failed`,reason:`the daemon holds no statusline render of session ${e} — none since it started, or dropped for newer sessions' renders, or only a frames display draws it, which reports no width — so no width a statusline client measured is known; run this again once the statusline has redrawn`}:{kind:`ok`,value:{columns:n.termCols,of:{kind:`session`,sessionId:e}}}}async function $4(e,t,n,r,i,a,o,s,c,l,u){let d=e.loadConfig(n),f=cJ(d.config,r,()=>!1),p=await K4(e,t.tmux),m=q4(p,t.terminalEnv),h=[...new Set([...zne(f),...vF(JSON.stringify(d.config))])].join(``),[g,_,v]=await Promise.all([h===``?{kind:`none`}:J4(e,m,t,h).then(e=>({kind:`glyphs`,glyphs:h,terminal:e})),e.daemons(),Z4(e,l2(d.config,f.preset),n,a)]);return{tmux:p,width:l,terminal:m,nerdFont:g,marks:u.marks,clicked:u.clicked,daemon:{serving:i,processes:_,read:u.postMortemsRead},config:U4(d,n.target),sighted:s,frames:c.kind===`failed`?c:{kind:`read`},data:v,transcripts:z4(e,o),claudeSettings:G4({managedDir:e.managedSettingsDir,projectDir:n.projectDir,userFile:Jo(qo(t.claudeConfigDir,e.home))},c.kind===`ok`?c.value:[])}}function e3(e,t,n){switch(t.kind){case`claude-settings`:{let e=t.file.path;Cr(e,ao(Zo(e),t.path,JSON.stringify(t.value),Ga));let r=e=>({...e,sources:W4(e.at)}),{origin:i,elsewhere:a}=n.claudeSettings;return{kind:`ok`,value:{...n,claudeSettings:{origin:r(i),elsewhere:a.map(r)}}}}case`post-mortems-read`:{let r=e.postMortemsRead.update(e=>e.through===null||Fi(t.through,e.through)?{through:t.through}:e);return r.kind===`failed`?r:{kind:`ok`,value:{...n,daemon:{...n.daemon,read:r}}}}default:return t}}const t3={entries:0,held:0,refreshes:{},failures:0,abandoned:0,lastMs:null},n3=16384;var r3=class e{startedAt;requestsTotal=0;requestsErrored=0;requestsTimedOut=0;inFlight=0;unknownHookFields=new Set;constructor(e){this.clock=e,this.startedAt=new Date(e.now())}firstSightOfUnknownHookField(e){let t=!this.unknownHookFields.has(e);return this.unknownHookFields.add(e),t}watchersOpened=0;watchersClosed=0;watchRefusals=0;watchErrors=0;dirWatchesOpened=0;dirWatchesClosed=0;subprocessTotal=0;subprocessInFlight=0;subprocessDraining=0;subprocessDrainedBytes=0;subprocessDrainsCut=0;subprocessPipeErrors=0;subprocessRefusals=new Map;subprocessCount=new Map;subprocessHistogram=new Map;subprocessHistogramRotator=new Map;rollingTimestamps=[];rollingHead=0;get subprocessRefused(){return this.subprocessRefusals}launchStats={onStart:e=>{this.subprocessTotal++,this.subprocessInFlight++,this.subprocessCount.set(e,(this.subprocessCount.get(e)??0)+1),this.recordRollingNow()},onEnd:(e,t)=>{this.subprocessInFlight=Math.max(0,this.subprocessInFlight-1),this.recordDuration(e,t)},onRefused:e=>{this.subprocessRefusals.set(e,(this.subprocessRefusals.get(e)??0)+1)},onDrainOpen:()=>{this.subprocessDraining++},onDrainRead:(e,t)=>{this.subprocessDrainedBytes+=t},onDrainClose:(e,t)=>{this.subprocessDraining--,t===`cut`&&this.subprocessDrainsCut++},onPipeError:()=>{this.subprocessPipeErrors++}};recordRollingNow(){let e=this.clock.monotonic();if(this.rollingTimestamps.length<n3){this.rollingTimestamps.push(e);return}this.rollingTimestamps[this.rollingHead]=e,this.rollingHead=(this.rollingHead+1)%n3}recordDuration(e,t){let n=this.subprocessHistogram.get(e);if(n||(n=[],this.subprocessHistogram.set(e,n)),n.length<16){n.push(t);return}let r=(this.subprocessHistogramRotator.get(e)??0)%16;n[r]=t,this.subprocessHistogramRotator.set(e,r+1)}snapshotSubprocesses(){let e=this.clock.monotonic()-6e4,t=0;for(let n of this.rollingTimestamps)n>=e&&t++;let n={};for(let[e,t]of this.subprocessCount)t>0&&(n[e]=t);let r={},i={};for(let[e,t]of this.subprocessHistogram){if(t.length===0)continue;let n=[...t].sort((e,t)=>e-t),a=Math.floor(n.length*.5),o=Math.min(n.length-1,Math.floor(n.length*.99)),s=n[a],c=n[o];s!==void 0&&(r[e]=s),c!==void 0&&(i[e]=c)}return{total:this.subprocessTotal,inFlight:this.subprocessInFlight,lastMinute:t,byCategory:n,refused:Object.fromEntries(this.subprocessRefused),draining:this.subprocessDraining,drainedBytes:this.subprocessDrainedBytes,drainsCut:this.subprocessDrainsCut,pipeErrors:this.subprocessPipeErrors,p50DurationMs:r,p99DurationMs:i}}static referenceSnapshot(){return new e({now:()=>0,monotonic:()=>0}).snapshot({gitCache:{size:0,held:0,hits:0,misses:0,changes:0,watchers:0},usageCache:{size:0,hits:0,misses:0,sweeps:0},sources:{records:[],homes:{daemon:0,configDir:0,repo:0,directory:0,session:0,view:0,pane:0},held:{git:0,tmux:0,host:0,today:0,pluginStorage:0},pluginStorage:{folders:0,faults:{unusable:0,refused:0,error:0},lost:0}},fileEvents:{delivery:{kind:`delivering`,unreported:[],missedSince:null},stalls:0,catchUps:0,probes:0,probeFailures:0},sourceRuns:{shell:t3,file:t3,watches:0},transcriptReads:{reads:0,bytes:0,longLines:0,largestLine:0},renderCache:{size:0,held:0,retired:0,compiles:0,views:0,pinned:0,retiredViews:0,accountedBytes:0,budgetBytes:0},effectCache:{sessions:0,effects:0},menuIdle:{sessions:0,armed:0},journalTurns:{gathers:0},runs:{started:0,failed:0,timedOut:0,refused:0,running:0,queued:0},sessionState:{sessions:0,observers:0,revision:0},frameFeeds:{feeds:0,subscribers:0,drawn:0,pushed:0,refused:0,lookups:0,found:0},tmuxStatus:{sessions:0,layouts:0,writes:0,failedWrites:0},linkIds:{minted:0,reused:0,evicted:0,reservations:0,faults:0},watchersActive:0,dirWatchesActive:0,dirsPolled:0,handlerProbes:[],clients:[],bundle:`/`,sourceDigest:null,daemon:{pid:0,memory:{kind:`unmeasured`},limit:0,postMortems:{kind:`ok`,value:[]}},doctorStores:{marks:{kind:`ok`,value:{}},clicked:{kind:`ok`,value:[]},postMortemsRead:{kind:`ok`,value:{through:null}}}})}snapshot(e){let t=process.memoryUsage();return{pid:process.pid,version:Ln,sourceDigest:e.sourceDigest,protocolVersion:3,startedAt:this.startedAt.toISOString(),uptimeSec:Math.floor((this.clock.now()-this.startedAt.getTime())/1e3),rssBytes:t.rss,heapUsedBytes:t.heapUsed,heapTotalBytes:t.heapTotal,externalBytes:t.external,arrayBuffersBytes:t.arrayBuffers,requests:{total:this.requestsTotal,errored:this.requestsErrored,timedOut:this.requestsTimedOut,inFlight:this.inFlight},unknownHookFields:[...this.unknownHookFields],gitCache:e.gitCache,usageCache:e.usageCache,sources:e.sources,fileEvents:e.fileEvents,sourceRuns:e.sourceRuns,transcriptReads:e.transcriptReads,renderCache:e.renderCache,effectCache:e.effectCache,menuIdle:e.menuIdle,journalTurns:e.journalTurns,runs:e.runs,sessionState:e.sessionState,frameFeeds:e.frameFeeds,tmuxStatus:e.tmuxStatus,linkIds:e.linkIds,watchers:{active:e.watchersActive,opened:this.watchersOpened,closed:this.watchersClosed,refused:this.watchRefusals,errors:this.watchErrors,dirs:{active:e.dirWatchesActive,opened:this.dirWatchesOpened,closed:this.dirWatchesClosed},polled:e.dirsPolled},subprocesses:this.snapshotSubprocesses(),nextRestartReason:e.nextRestartReason??null,handlerProbes:e.handlerProbes,clients:e.clients,bundle:e.bundle,daemon:e.daemon,doctorStores:e.doctorStores}}};const i3={connectMs:200,budgetMs:500};async function a3(e,t){return o3(await s3(e),t.includes(`--json`))}function o3(e,t){if(e.kind!==`ok`)return{stdout:``,stderr:`daemon-stats: ${li(e)}\n`,code:1};let n=t?JSON.stringify(e.value,null,2)+`
|
|
493
|
-
`:null,r=c3(e.value);return r===null?{stdout:n??y3(e.value),stderr:``,code:0}:{stdout:n??``,stderr:`daemon-stats: ${r}\n`,code:1}}function s3(e){return ni(e,()=>({kind:`stats`}),i3,e=>`stats`in e?e.stats:void 0)}function c3(e,t=f3){let n=r3.referenceSnapshot(),r=p3(Object.fromEntries(t.map(e=>[e,n[e]])),e);if(r.length===0)return null;let{theirs:i,mine:a}=u3(e);return`the daemon (${i}) reports no ${r.join(`, `)}; it is another build than this client (${a}), and restarts only when its own bundle changes`}function l3(e){return e.version===`1.211.
|
|
493
|
+
`:null,r=c3(e.value);return r===null?{stdout:n??y3(e.value),stderr:``,code:0}:{stdout:n??``,stderr:`daemon-stats: ${r}\n`,code:1}}function s3(e){return ni(e,()=>({kind:`stats`}),i3,e=>`stats`in e?e.stats:void 0)}function c3(e,t=f3){let n=r3.referenceSnapshot(),r=p3(Object.fromEntries(t.map(e=>[e,n[e]])),e);if(r.length===0)return null;let{theirs:i,mine:a}=u3(e);return`the daemon (${i}) reports no ${r.join(`, `)}; it is another build than this client (${a}), and restarts only when its own bundle changes`}function l3(e){return e.version===`1.211.2`&&d3(e)===Bn()?null:u3(e)}function u3(e){return{theirs:h3(e.version,d3(e)),mine:h3(Ln,Bn())}}const d3=e=>e.sourceDigest??null,f3=Object.keys(r3.referenceSnapshot());function p3(e,t,n=``){if(Array.isArray(e))return Array.isArray(t)?[]:[n||`<snapshot>`];if(!m3(e))return[];if(!m3(t))return[n||`<snapshot>`];if(`kind`in e)return[];let r=[];for(let i of Object.keys(e)){let a=n===``?i:`${n}.${i}`;i in t?r.push(...p3(e[i],t[i],a)):r.push(a)}return r}function m3(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function h3(e,t){return`${e} [${t===null?`no digest`:In(t)}]`}function g3(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/1024/1024).toFixed(1)}MB`}function _3(e,t){let n=e+t;return n===0?`n/a`:`${(e/n*100).toFixed(1)}%`}function v3(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m${e%60}s`:`${Math.floor(e/3600)}h${Math.floor(e%3600/60)}m`}function y3(e){let t=[];t.push(`cc-candybar daemon stats`),t.push(``),t.push(`process`),t.push(` pid ${e.pid}`),t.push(` build ${h3(e.version,e.sourceDigest)}`),t.push(` protocol ${e.protocolVersion}`),t.push(` startedAt ${e.startedAt}`),t.push(` uptime ${v3(e.uptimeSec)}`),t.push(` rss ${g3(e.rssBytes)}`),t.push(` heapUsed ${g3(e.heapUsedBytes)}`),t.push(` heapTotal ${g3(e.heapTotalBytes)}`),t.push(` external ${g3(e.externalBytes)}`),t.push(` arrayBuffers ${g3(e.arrayBuffersBytes)}`),t.push(``),t.push(`requests`),t.push(` total ${e.requests.total}`),t.push(` errored ${e.requests.errored}`),t.push(` timedOut ${e.requests.timedOut}`),t.push(` inFlight ${e.requests.inFlight}`),t.push(` unknownFields ${e.unknownHookFields.map(e=>JSON.stringify(e)).join(`, `)||`-`}`),t.push(``),t.push(`gitCache`),t.push(` size ${e.gitCache.size}`),t.push(` held ${e.gitCache.held}`),t.push(` hit rate ${_3(e.gitCache.hits,e.gitCache.misses)} (${e.gitCache.hits} / ${e.gitCache.hits+e.gitCache.misses})`),t.push(` changes ${e.gitCache.changes}`),t.push(``),t.push(`usageCache`),t.push(` size ${e.usageCache.size}`),t.push(` hit rate ${_3(e.usageCache.hits,e.usageCache.misses)} (${e.usageCache.hits} / ${e.usageCache.hits+e.usageCache.misses})`),t.push(` sweeps ${e.usageCache.sweeps}`),t.push(``),t.push(`sources`);for(let n of e.sources.records){let e=Object.entries(n.refreshes).map(([e,t])=>`${e}:${t}`).join(` `);t.push(` ${`${n.scope}/${n.name}`.padEnd(24)} failures=${n.failures} last=${n.lastMs===null?`-`:`${n.lastMs}ms`} refreshes ${e}`)}let n=Object.entries(e.sources.homes).map(([e,t])=>`${e}:${t}`).join(` `),r=Object.entries(e.sources.held).map(([e,t])=>`${e}:${t}`).join(` `);t.push(` homes ${n}`),t.push(` held ${r}`);let i=e.sources.pluginStorage,a=Object.entries(i.faults).map(([e,t])=>`${e}:${t}`).join(` `);t.push(` plugin storage folders=${i.folders} lost=${i.lost} faults ${a}`),t.push(` fileEvents ${Kc(e.fileEvents)}`);for(let n of[`shell`,`file`]){let r=e.sourceRuns[n];t.push(` runs.${n.padEnd(8)} entries=${r.entries} held=${r.held} failures=${r.failures} abandoned=${r.abandoned} last=${r.lastMs===null?`-`:`${r.lastMs}ms`}`)}t.push(` runs.watches ${e.sourceRuns.watches}`),t.push(``),t.push(`transcriptReads`),t.push(` reads ${e.transcriptReads.reads}`),t.push(` bytes ${g3(e.transcriptReads.bytes)}`),t.push(` long lines ${e.transcriptReads.longLines}`),t.push(` largest line ${g3(e.transcriptReads.largestLine)}`),t.push(``),t.push(`renderCache`),t.push(` size ${e.renderCache.size}`),t.push(` held ${e.renderCache.held}`),t.push(` retired ${e.renderCache.retired}`),t.push(` compiles ${e.renderCache.compiles}`),t.push(` views ${e.renderCache.views}`),t.push(` pinned ${e.renderCache.pinned}`),t.push(` retired views ${e.renderCache.retiredViews}`),t.push(` accounted ${g3(e.renderCache.accountedBytes)} / ${g3(e.renderCache.budgetBytes)}`),t.push(``),t.push(`effectCache`),t.push(` sessions ${e.effectCache.sessions}`),t.push(` effects ${e.effectCache.effects}`),t.push(``),t.push(`menuIdle`),t.push(` sessions ${e.menuIdle.sessions}`),t.push(` armed ${e.menuIdle.armed}`),t.push(``),t.push(`journalTurns`),t.push(` gathers ${e.journalTurns.gathers}`),t.push(``),t.push(`sessionState`),t.push(` sessions ${e.sessionState.sessions}`),t.push(` observers ${e.sessionState.observers}`),t.push(` revision ${e.sessionState.revision}`),t.push(``),t.push(`watchers`),t.push(` active ${e.watchers.active}`),t.push(` opened ${e.watchers.opened}`),t.push(` closed ${e.watchers.closed}`),t.push(` refused ${e.watchers.refused}`),t.push(` errors ${e.watchers.errors}`),t.push(` dirs ${e.watchers.dirs.active} open (${e.watchers.dirs.opened} opened, ${e.watchers.dirs.closed} closed)`,` polled ${e.watchers.polled} dirs`),t.push(``),t.push(`subprocesses`),t.push(` total ${e.subprocesses.total}`),t.push(` inFlight ${e.subprocesses.inFlight}`),t.push(` lastMinute ${e.subprocesses.lastMinute}`),t.push(` draining ${e.subprocesses.draining} (${e.subprocesses.drainedBytes} bytes dropped, ${e.subprocesses.drainsCut} cut)`),t.push(` pipeErrors ${e.subprocesses.pipeErrors}`);let o=Object.entries(e.subprocesses.byCategory),s=Object.entries(e.subprocesses.refused).map(([e,t])=>[`${e} refused`,t]),c=[...o,...s].reduce((e,[t])=>Math.max(e,t.length),13);for(let[n,r]of o){let i=e.subprocesses.p50DurationMs[n],a=e.subprocesses.p99DurationMs[n],o=i!==void 0&&a!==void 0?` (p50 ${i}ms · p99 ${a}ms)`:``;t.push(` ${n.padEnd(c)} ${r}${o}`)}for(let[e,n]of s)t.push(` ${e.padEnd(c)} ${n}`);return e.nextRestartReason&&(t.push(``),t.push(`nextRestart ${e.nextRestartReason}`)),t.join(`
|
|
494
494
|
`)+`
|
|
495
495
|
`}const b3=e=>({kind:`ok`,value:e}),x3=e=>({kind:`failed`,reason:e});var S3=class{arrivals=[];arrive(e){this.arrivals=[...this.arrivals,e].slice(-16)}list(){return this.arrivals}};const C3=/^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$/;function w3(e){return C3.test(e)?e:null}function T3(e,t){let n=e.opener(t);if(n.kind===`failed`)return n;if(n.value===null)return b3(null);let r=n.value;return b3({app:r,forwarder:e.exists(vs(r))})}async function E3(e,t){let n=e.monotonic()+5e3;for(;e.monotonic()<n;){await e.pause();let n=await e.daemon(),r=n.kind===`ok`?n.value.arrivals.find(e=>e.nonce===t):void 0;if(n.kind===`ok`&&r!==void 0)return{kind:`arrived`,delivery:r.delivery}}return null}async function D3(e){if(e.platform!==`darwin`)return{kind:`unsupported`};if(e.sockets.own!==e.sockets.handler)return{kind:`unprobed`,reason:`this shell's daemon is at ${e.sockets.own}; the URL handler delivers a link naming ${e.name} to ${e.sockets.handler}`};let t=await e.daemon();if(t.kind===`failed`)return{kind:`unprobed`,reason:`the daemon could not be asked whether a link arrives: ${t.reason}`};let n=e.nonce(),r=jte(e.name,n),i=e.open(r);return(i===null?await E3(e,n):null)??{kind:`lost`,unopened:i,opener:T3(e,r),otherBuild:t.value.otherBuild}}function O3(e,t,n,r){let i=e.launchSync({bin:n,args:[...r],category:t,timeoutMs:5e3});return i.ok?b3(i.stdout):x3(gt(i))}const k3=e=>`ObjC.import("AppKit");var u = $.NSWorkspace.sharedWorkspace.URLForApplicationToOpenURL($.NSURL.URLWithString(${JSON.stringify(e)}));u.isNil() ? "" : u.path.js`;async function A3(e){let t=await s3(e);if(t.kind!==`ok`)return x3(li(t).split(`
|
|
496
496
|
`).join(` — `));let n=c3(t.value,[`handlerProbes`]);if(n!==null)return x3(n);let r=[];for(let e of t.value.handlerProbes){let t=j3(e);if(t===null)return x3(`the daemon lists its probe arrivals without who delivered them, so it is from a build before the forwarder app — restart it to run the installed one`);r.push(t)}return b3({arrivals:r,otherBuild:l3(t.value)})}function j3(e){if(typeof e!=`object`||!e)return null;let{nonce:t,delivery:n}=e;if(typeof t!=`string`||typeof n!=`object`||!n)return null;let{kind:r,urlV:i}=n;return r===`cli`?{nonce:t,delivery:{kind:`cli`}}:r===`forwarder`&&typeof i==`number`?{nonce:t,delivery:{kind:`forwarder`,urlV:i}}:null}function M3(e,t){let{home:n,clock:r}=t;return{platform:process.platform,name:n.name,sockets:{own:Qn(n),handler:$n(n.name)},monotonic:()=>r.monotonic(),nonce:ce,daemon:()=>A3(t),open:t=>{let n=O3(e,`doctor.open`,`/usr/bin/open`,[`-g`,t]);return n.kind===`ok`?null:n.reason},pause:()=>et(r,100),opener:t=>{let n=O3(e,`doctor.launch-services`,`/usr/bin/osascript`,[`-l`,`JavaScript`,`-e`,k3(t)]);if(n.kind===`failed`)return n;let r=n.value.trim();return b3(r===``?null:r)},exists:m.existsSync}}const N3=5e3;function P3(e,t,n){if(e.reason===`rate-limited`){n(`warn`,gt(e));return}throw e.reason===`aborted`?new lc(t):Error(`${t} failed (${gt(e)})`)}async function F3(e,t,n,r,i,a){let o=x(s.join(a,`cc-candybar-handoff-`));try{let a={stdout:`/dev/null`,stderr:s.join(o,`stderr`),status:s.join(o,`status`)},c=e.launchJobSync(t,a);if(!c.ok){P3({...c,stdout:``,stderr:``,exitCode:null,signal:null},n,r);return}c.release();let l=e.clock.monotonic()+i;for(;;){let o=e.jobGroupAlive(c.pid),s=qt(a.status);if(s!==null){if(s.kind===`exit`&&s.code===0)return;P3(s.kind===`exit`?{ok:!1,reason:`non-zero`,stdout:``,stderr:C(a.stderr,`utf8`),exitCode:s.code,signal:null}:{ok:!1,reason:`timeout`,stdout:``,stderr:``,exitCode:null,signal:null},n,r);return}if(!o)throw Error(`${n} failed (lost): the opener ended with no verdict`);if(e.clock.monotonic()>=l){r(`info`,`${t.category} handed off at ${i}ms, pid ${c.pid}`);return}await et(e.clock,50)}}finally{T(o,{recursive:!0,force:!0,maxRetries:3})}}function I3(e,t){L3(t,{bin:`/usr/bin/pbcopy`,stdinInput:e,category:`click.pbcopy`},`pbcopy`)}function L3(e,t,n){e.effect({kind:`launch`,spec:t,what:n})}const R3=(e,[t=``],n)=>{I3(t,n)},z3=new Set([`request`,`feed`]);function B3(e){if(!z3.has(e))throw new L(`unknown renderer ${JSON.stringify(e)}`);return e}const V3=(e,t,n)=>{let[r=``,i=``]=t,a=n.diagnosticCopy(e,B3(r),i);if(a===void 0)throw new L(`that message is no longer listed in session ${e}'s diagnostics — open ⚠ again and copy from there`);I3(a,n)},H3=(e,[t=``],n)=>{L3(n,{bin:`/usr/bin/open`,args:[`-a`,`Visual Studio Code`,t],category:`click.open`},`open -a "Visual Studio Code"`)},U3=(e,t,n)=>{r6(n,n.navigating).get(e,`toolbar-expanded`)?n.navigating.clear(e,`toolbar-expanded`):n.navigating.set(e,`toolbar-expanded`,`1`)},W3=(e,t,n)=>{let r=n.gates.state.gateFor(n6(n,e));if(t.length===0)throw new L(`set-state: <key>/<value> is required (have keys: ${r.listKeys().join(`, `)})`);if(t.length%2!=0)throw new L(`set-state: expected even-count <key>/<value> pairs, got ${t.length} segment(s) after session id (have keys: ${r.listKeys().join(`, `)})`);let i=[];for(let e=0;e<t.length;e+=2){let n=t[e],a=t[e+1];if(!n)throw new L(`set-state: empty key at pair ${e/2+1} (expected <sessionId>/<key>/<value>[/<key>/<value>...] segments)`);let o=r.validate(n,a);if(!o.ok)throw new L(`set-state: pair ${e/2+1}: ${o.reason}`);i.push({key:n,value:o.value})}J3(n,e,`set-state`,i),n.navigating.setBatch(e,i);let a=i.map(e=>`${e.key}=${e.value}`).join(` `);n.log(`info`,`set-state: ${a} (session=${e})`)},G3=/^-?\d+$/;function K3(e,t,n,r){let i=e+t;return i>r?e===r?n:r:i<n?e===n?r:n:i}const q3=(e,t,n)=>{let[r=``,i=``]=t;if(!r)throw new L(`step-state: <key> is required (shape: <sessionId>/<key>/<by>)`);if(!G3.test(i))throw new L(`step-state: delta must be an integer, got "${i}"`);let a=parseInt(i,10),o=n6(n,e),s=n.gates.state.gateFor(o),c=s.rangeParamsFor(r);if(!c)throw new L(`step-state: key "${r}" is not a bounded (range) state key (have keys: ${s.listKeys().join(`, `)})`);let l=i6(n,e),u=l(r),d=u===null?X3(`step-state`,r,c,G$(o,l,r)):parseInt(u,10),f=K3(d,a,c.min,c.max),p=s.validate(r,String(f));if(!p.ok)throw new L(`step-state: ${p.reason}`);J3(n,e,`step-state`,[{key:r,value:p.value}]),n.navigating.set(e,r,p.value),n.log(`info`,`step-state: ${r} ${d}→${p.value} (by ${a}, session=${e})`)};function J3(e,t,n,r){let i=r.filter(e=>e.key.startsWith(eP));if(i.length===0)return;let a=P$(n6(e,t),i6(e,t),i);if(a.length>0)throw new L(`${n}: refused — ${a.join(`; `)}`)}function Y3(e,t){return Math.max(e.min,Math.min(e.max,t))}function X3(e,t,n,r){if(r===null)return n.min;if(!G3.test(r))throw new L(`${e}: "${t}" shows ${JSON.stringify(r)} before any click, not an integer to step`);return Y3(n,parseInt(r,10))}function Z3(e,t){return t===null?{source:`search`}:e===`argument`||e===`environment`?{source:e,path:t}:{source:`unknown`,path:t}}function Q3(e,t){let n;try{n=JSON.parse(e)}catch{throw new L(`render origin is not JSON: ${e}`)}if(typeof n!=`object`||!n)throw new L(`render origin is not an object: ${e}`);let{projectDir:r,cwd:i,configFile:a,source:o}=n;if(typeof r!=`string`||typeof i!=`string`||a===void 0)throw new L(`render origin has the wrong shape: ${e}`);let s;try{s=a===null?null:h0(t,a)}catch(e){throw e instanceof m0?new L(`render origin: ${e.message}`):e}return{projectDir:r,cwd:i,target:Z3(o,s)}}function $3(e,t){let n=e6(e,t);if(n===null)throw new L(`session ${t} has not rendered yet — no config to act on`);return n}function e6(e,t){let n=e.sessionState.get(t,p$);return n===null?null:Q3(n,e.storedRoot)}function t6(e,t,n){let r=e6(e,t);if(r===null)return;let{path:i}=s6(e,r);n.some(e=>e.kind===`file`&&e.file===i)&&e.reloadConfig(r)}function n6(e,t){return e.configFor($3(e,t))}function r6(e,t){return y$(t,t=>{let n=e6(e,t);return n===null?null:e.gates.state.gateFor(e.configFor(n))})}function i6(e,t){let n=r6(e,e.sessionState);return e=>n.get(t,e)}function a6(e,t){let n=e6(e,t);if(n===null)return null;let r=()=>e.lanes.of(n,t);return{sessionId:t,before:r(),read:r}}function o6(e,t){let n=e6(e,t);return n===null?q$:Z$(e.configFor(n))}function s6(e,t){return UH(e.filesystem,e.installedLayers,e.locations,ZH(e.filesystem,e.stateDir),t.projectDir,t.cwd,t.target.path)}function c6(e,t){return{record:(n,r,i)=>e.journal.file(t,n,r,i),logger:e.log}}const l6=(e,t,n)=>{let[r=``,i=``]=t,a=$3(n,e),o=n.configFor(a),s=n.gates.config.gateFor(o);if(!r)throw new L(`set-config: <key>/<value> is required (have keys: ${s.listKeys().join(`, `)})`);let c=s.validate(r,i);if(!c.ok)throw new L(`set-config: ${c.reason}`);let l=s6(n,a),u=M$(o,i6(n,e),r);W1(c6(n,e),l,[[u.key,c.value]]),n.reloadConfig(a),n.log(`info`,`set-config: ${u.key}=${c.value} → ${l.path} (session=${e})`)},u6=(e,t,n)=>{let[r=``,i=``]=t;if(!r)throw new L(`step-config: <key> is required (shape: <sessionId>/<key>/<by>)`);if(!G3.test(i))throw new L(`step-config: delta must be an integer, got "${i}"`);let a=parseInt(i,10),o=$3(n,e),s=n.configFor(o),c=n.gates.config.gateFor(s),l=c.rangeParamsFor(r);if(!l)throw new L(`step-config: key "${r}" is not a bounded (range) config key (have keys: ${c.listKeys().join(`, `)})`);let u=s6(n,o),d=M$(s,i6(n,e),r),f=U1(u,d.key),p=typeof f==`number`?Y3(l,f):X3(`step-config`,r,l,K$(d.globals,r)),m=K3(p,a,l.min,l.max),h=c.validate(r,String(m));if(!h.ok)throw new L(`step-config: ${h.reason}`);W1(c6(n,e),u,[[d.key,h.value]]),n.reloadConfig(o),n.log(`info`,`step-config: ${d.key} ${p}→${h.value} (by ${a}) → ${u.path} (session=${e})`)},d6=(e,t,n)=>{let r=$3(n,e),i=n.configFor(r),a=i6(n,e),o=A$(i,a),s=N$(i,a);if(o.length+s.length===0){n.log(`info`,`save: nothing unsaved (session=${e})`);return}let c=n.gates.state.gateFor(i),l=o.map(e=>{let t=c.validate(e.sessionKey,e.value);if(!t.ok)throw new L(`save: ${t.reason}`);return[e.target,t.value]});p6(`save`,c,s);let u=s6(n,r);G1(c6(n,e),u,l,s),n.reloadConfig(r);for(let t of[...o.map(e=>e.sessionKey),...s.map(e=>e.key)])n.sessionState.clear(e,t);n.log(`info`,`save: ${[...l.map(([e,t])=>`${e}=${t}`),...s.map(f6)].join(` `)} → ${u.path} (session=${e})`)},f6=e=>`${e.preset}/${e.id}.settings.${e.setting}=${Eb(e.value)}`;function p6(e,t,n){for(let r of n){let n=t.validate(r.key,Eb(r.value));if(!n.ok)throw new L(`${e}: ${n.reason}`)}}const m6=(e,t,n)=>{let r=$3(n,e),i=n.configFor(r),a=L$(i,i6(n,e)),o=n.gates.state.gateFor(i),s=a.picks.map(e=>{let t=o.validate(e.sessionKey,e.value);if(!t.ok)throw new L(`save-preset: ${t.reason}`);return[e.configKey,t.value]});p6(`save-preset`,o,a.placements);let c=s6(n,r),l=Q1(c6(n,e),c,a.from,a.globals,s,a.placements);n.reloadConfig(r);for(let t of[...Sx.map(e=>e.sessionKey),...a.placements.map(e=>e.key)])n.sessionState.clear(e,t);n.sessionState.set(e,bx.preset.sessionKey,l),n.log(`info`,`save-preset: ${[`${l} from=${a.from}`,...s.map(([e,t])=>`${e}=${t}`),...a.placements.map(f6)].join(` `)} → ${c.path} (session=${e})`)},h6=(e,t,n)=>{let r=$3(n,e),i=z$(n.configFor(r),i6(n,e));if(i.kind===`rule`)throw new L(`save-theme-default: the theme is chosen by a rule (globals.palette), so there is no name to save as a theme's default — pick one in the menu first`);let a=s6(n,r);$1(c6(n,e),a,i.theme,i.look),n.reloadConfig(r);let o=new Set(A$(n.configFor(r),t=>n.sessionState.get(e,t)).map(e=>e.sessionKey)),s=px.map(e=>bx[e].sessionKey).filter(e=>!o.has(e));for(let t of s)n.sessionState.clear(e,t);n.log(`info`,`save-theme-default: ${i.theme} ${px.map(e=>`${e}=${i.look[e]}`).join(` `)} → ${a.path} (session=${e})`)},g6=(e,t,n)=>{let[r=``]=t;if(!r)throw new L(`delete-preset: <name> is required (shape: <sessionId>/<name>)`);let i=$3(n,e),a=s6(n,i);e0(c6(n,e),a,r),n.reloadConfig(i);let o=bx.preset.sessionKey;n.sessionState.get(e,o)===r&&n.sessionState.clear(e,o),n.log(`info`,`delete-preset: ${r} ← ${a.path} (session=${e})`)},_6=(e,t,n)=>{let r=t,i=$3(n,e),a=n.gates.config.gateFor(n.configFor(i)).listKeys(),o=r.length===0?[``]:r.filter(e=>!a.includes(e));if(o.length>0)throw new L(`reset-config: unknown config key "${o.join(`", "`)}" (have: ${a.join(`, `)})`);let s=s6(n,i),c=r.map(B$),l=c.flatMap(e=>e.fileKeys),u=c.flatMap(e=>e.sessionKeys);Y1(c6(n,e),s,l),n.reloadConfig(i);for(let t of u)n.sessionState.clear(e,t);n.log(`info`,`reset-config: ${[...l,...u.map(e=>`session:${e}`)].join(` `)} ← ${s.path} (session=${e})`)};function v6(e,t){let n=(e,t)=>[...ob(aS(e,t).node)].filter(e=>e.kind===`segment`),r=new Set(nS(t.presets).flatMap(e=>n(t,e).map(t=>tP(MM(e),nb(t)))));return nS(e.presets).flatMap(t=>n(e,t).map(e=>({member:tP(MM(t),nb(e)),node:e})).filter(({member:e})=>!r.has(e)))}function y6(e,t){return e.flatMap(({member:e,node:n})=>[...Object.values(n.drafts??{}).map(e=>e.key),...e===t?[ZN]:[]])}const b6=(e,t,n)=>{let[r=``,i=``]=t,a=$3(n,e),o=n.configFor(a),s=n.gates.config.gateFor(o);if(!r)throw new L(`apply-layout-op: <key>/<op> is required (have: ${s.listKeys().join(`, `)})`);let c=s.validate(r,i);if(!c.ok)throw new L(`apply-layout-op: ${c.reason}`);let l=WR(c.value);if(l===null)throw new L(`apply-layout-op: "${c.value}" is not a layout op token`);let u=s6(n,a),d=t0(c6(n,e),u,r,l);n.reloadConfig(a);let f=y6(v6(o,n.configFor(a)),n.sessionState.get(e,ZN)).filter(t=>n.sessionState.get(e,t)!==null);for(let t of f)n.sessionState.clear(e,t);n.log(`info`,`apply-layout-op: ${r} ${c.value} → ${u.path} placed=${JSON.stringify(d)} released=${JSON.stringify(f)} (session=${e})`)},x6=(e,t,n)=>{n.journal.commit();let r=n.history.undo(e);n.journal.wrote(),t6(n,e,r),n.log(`info`,`undo: restored ${L0(r)} (session=${e})`)},S6=(e,t,n)=>{let{step:r,discarded:i}=n.navigation.back(e,n.sessionState,n.gates.state.gateFor(n6(n,e))),a=r.map(e=>`${e.key}=${e.before??`∅`}`).join(` `);n.log(`info`,`back: ${a} discarded=${i} (session=${e})`)},C6=(e,t,n)=>{n.journal.commit(),n.journal.wrote();let r=n.history.rewind(e);t6(n,e,r),n.log(`info`,`rewind: put back ${L0(r)||`nothing`} as edit mode found it (session=${e})`)},w6=(e,t,n)=>{n.journal.commit();let r=n.history.redo(e);n.journal.wrote(),t6(n,e,r),n.log(`info`,`redo: re-applied ${L0(r)} (session=${e})`)},T6=(e,t,n)=>{n.effect({kind:`apply-update`})};function E6(e,t){let n=e.sessionState.get(t,m$);if(n===null)throw new L(`session ${t} has not rendered yet — no client facts are recorded for it`);let r;try{r=JSON.parse(n)}catch{throw new L(`client hints record is not JSON: ${n}`)}if(typeof r!=`object`||!r)throw new L(`client hints record is not an object: ${n}`);return Mr(r)}function D6(e,t,n){let r=tI(n);e.sessionState.setBatch(t,Yre(r)),e.log(`info`,`doctor: ${r.map(e=>`${e.check.name}=${e.verdict.ok?`ok`:`failed(${1+(e.verdict.more?.length??0)})`}`).join(` `)} ${Ire(n.config)} ${qre(n.nerdFont,n.marks)} ${Lre(n.terminal,n.clicked)} ${Rre(n.terminal,n.width)} ${zre(n.install)} ${Vre(n.daemon)} ${Hre(n.data)} ${Kre(n.transcripts)} ${Ure(n.frames,n.claudeSettings)} ${Gre(n.claudeSettings.origin.sources)} (session=${t})`)}function O6(e,t,n){e.effect({kind:`doctor`,session:t,step:n,arrival:e.arrival})}function k6(e,t){let n=e=>{throw Error(`doctor: the gather ${e}; a gather writes nothing`)};return{get:(n,r)=>{let i=e.get(n,r);return t.set(JSON.stringify([n,r]),{what:r,value:i,again:e=>e.get(n,r)}),i},values:()=>n(`read every key; a gather reads keys by name`),revision:t=>e.revision(t),set:(e,t)=>n(`set ${t}`),setBatch:()=>n(`wrote a batch`),clear:(e,t)=>n(`cleared ${t}`)}}function A6(e,t,n){for(let{what:t,value:r,again:i}of n.reads)if(i(e.sessionState)!==r)return t;let r=e.doctor.loadConfig($3(e,t));return r.config===n.load.config&&r.error===n.load.error&&r.warning===n.load.warning&&j6(r.repos,n.load.repos)?null:`config`}const j6=(e,t)=>BP(e).join(`
|
|
@@ -506,9 +506,9 @@ function run(argv) {
|
|
|
506
506
|
`)){let[t,n,i]=e.trim().split(` `);t!==void 0&&n===`0`&&i!==void 0&&r.set(t,i)}return{sessionOf:n,shownBy:r}}var bse=class{servers=new Map;loop={kind:`idle`};constructor(e){this.deps=e}follow(){switch(this.loop.kind){case`idle`:this.deps.log(`info`,`visibility following`),this.ask();break;case`asking`:this.loop.following=!0;break;case`due`:break}return()=>this.stop()}stop(){switch(this.loop.kind){case`due`:this.loop.clear(),this.end();return;case`asking`:this.loop.following=!1;return;case`idle`:return}}ask(){let e={kind:`asking`,following:!0};this.loop=e,Promise.resolve().then(()=>this.refresh(this.deps.sockets())).catch(e=>this.deps.log(`error`,`visibility refresh threw: ${O(e)}`)).then(()=>{if(e.following){this.loop={kind:`due`,clear:this.deps.clock.after(this.deps.intervalMs,()=>this.ask(),{unref:!0})};return}this.end()})}end(){this.deps.log(`info`,`visibility stopped forgot=${this.servers.size}`),this.loop={kind:`idle`},this.servers.clear()}shown(e){if(e==null)return!0;let t=this.servers.get(e.socket);return t?.kind!==`asked`||t.shown.has(e.pane)}async refresh(e){for(let t of this.servers.keys())e.has(t)||this.servers.delete(t);let t=await Promise.all([...e].map(async e=>{let[t,n]=await Promise.all([this.deps.listPanes(e),this.deps.listClients(e)]);return[e,t.kind===`ok`?n.kind===`ok`?{kind:`asked`,shown:Q5(t.stdout,Z5(n.stdout)),status:yse(t.stdout,n.stdout)}:{kind:`unasked`,reason:n.reason}:{kind:`unasked`,reason:t.reason}]})),n=new Set;for(let[e,r]of t){let t=this.servers.get(e);this.servers.set(e,r),!xse(t,r)&&(n.add(e),this.deps.log(r.kind===`asked`?`info`:`warn`,r.kind===`asked`?`visibility socket=${JSON.stringify(e)} shown=${[...r.shown].join(`,`)||`-`}`:`visibility socket=${JSON.stringify(e)} unasked: ${r.reason} — its panes count as shown`))}for(let[e,n]of t)n.kind===`asked`&&this.deps.onAnswer(e,n.status);n.size>0&&this.deps.onChange(n)}};function xse(e,t){return e===void 0||e.kind!==t.kind?!1:e.kind===`unasked`||t.kind===`unasked`?!0:e.shown.size===t.shown.size&&[...e.shown].every(e=>t.shown.has(e))}function $5(e){return`"${e.replace(/[\\"$~]/g,e=>`\\${e}`)}"`}function e7(e){return e.map(e=>e.map(t7).join(` `)).join(` ; `)}const t7=e=>typeof e==`string`?$5(e):`{ ${e7(e.block)} }`;function Sse(e){return e.map(e=>e.map(t7).join(` `)).join(` \\; `)}const Cse={n:`
|
|
507
507
|
`,t:` `,r:`\r`,b:`\b`,a:`\x07`,v:`\v`,f:`\f`,0:`\0`},wse=(e,t)=>e.startsWith(`\\;`,t)&&(e[t+2]??` `)===` `;function n7(e){let t=0,n=n=>e[t]===n&&(e[t+1]??` `)===` `,r=()=>{let n=[],r=e=>{n.push(...Buffer.from(e,`utf8`))},i=null;for(;t<e.length;){let a=e[t];if(i===null&&(a===` `||a===`;`))break;if(a===i)i=null,t++;else if(i===null&&(a===`"`||a===`'`))i=a,t++;else if(a===`\\`&&t+1<e.length){let i=/^[0-7]{3}/.exec(e.slice(t+1,t+4)),a=e[t+1];i===null?(r(Cse[a]??a),t+=2):(n.push(parseInt(i[0],8)),t+=4)}else{let n=String.fromCodePoint(e.codePointAt(t));r(n),t+=n.length}}return Buffer.from(n).toString(`utf8`)},i=a=>{let o=[[]];for(;t<e.length;)if(e[t]===` `)t++;else if(e[t]===`;`||!a&&wse(e,t))o.push([]),t+=e[t]===`;`?1:2;else if(a&&n(`}`)){t++;break}else n(`{`)?(t++,o.at(-1).push({block:i(!0)})):o.at(-1).push(r());return o.filter(e=>e.length>0)};return i(!1)}const r7=[`-T`,`root`,`MouseDown1Status`],i7=`@cc-candybar-renderer`,a7=`@cc-candybar-click`;function Tse(e,t,n,r){return`${e} ${dC(t,aC,lC([n,r]))}`}const o7=`#{m:ccb*,#{mouse_status_range}}`;function Ese(e){let t=`run-shell -b ${$5(`#{${a7}}/#{s/%//:pane_id}/#{q:mouse_status_range}`)}`,n=`display-message ${$5(`cc-candybar: no renderer takes clicks on this row: the one that drew it is older than this binding`)}`;return[`bind-key`,...r7,`if-shell`,`-F`,o7,`if-shell -F ${$5(`#{${a7}}`)} ${$5(t)} ${$5(n)}`,...e===null?[]:[e7(e)]]}const Dse=/^bind-key\s+(?:-r\s+)?(?:-N\s+(?:"(?:[^"\\]|\\.)*"|\S+)\s+)?-T\s+root\s+MouseDown1Status\s+(.+)$/m;function s7(e){let[t,...n]=e;if(t===void 0||n.length>0||t[0]!==`if-shell`)return;let r=t.slice(1);for(;typeof r[0]==`string`&&r[0].startsWith(`-`);)r=r.slice(1);if(r[0]!==o7)return;let i=r[2],a=i===void 0?[]:typeof i==`string`?n7(i):i.block;return a.length>0?a:null}function c7(e){let t=Dse.exec(e)?.[1],n=t===void 0?null:n7(t),r=n!==null&&s7(n)!==void 0;for(;n!==null;){let e=s7(n);if(e===void 0)break;n=e}return{ours:r,user:n}}const l7=`#{S:#{?#{!=:#{${i7}},},1,}}`;function Ose(e){return[`if-shell`,`-F`,l7,`${e7([Ese(e)])} ; display-message -p ccb:bound`]}function kse(e){return[`if-shell`,`-F`,l7,`display-message -p ccb:held`,`${e===null?`unbind-key ${r7.join(` `)}`:`bind-key ${r7.join(` `)} ${Sse(e)}`} ; display-message -p ccb:restored`]}const u7=Yc.tmuxStatus.rows,d7=`@cc-candybar-status-prior`,f7=`@cc-candybar-status-wrote`,p7=Array.from({length:u7},(e,t)=>t),m7=e=>`@cc-candybar-row-${e}`,Ase=e=>`#[fill=terminal]#{${m7(e)}}`,h7=e=>`status-format[${e}]`;function jse(e){return e===0?`off`:e===1?`on`:String(e)}function g7(e){let t=e===`off`?0:e===`on`?1:/^[2-5]$/.test(e)?+e:NaN;if(Number.isNaN(t))throw Error(`tmux status is ${JSON.stringify(e)}`);return t}function Mse(e,t){if(e===null)return!1;let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(n=>e[Number(n)]===t[Number(n)])}function _7(e){return e.endsWith(`;`)?`${e.slice(0,-1)}\\;`:e}const v7={kind:`ok`,stdout:``};function y7(e){return e.flatMap((e,t)=>[...t===0?[]:[`;`],...e])}const b7=`ccb:separator`;function x7(e){return y7(e.flatMap((e,t)=>t===0?[e]:[[`display-message`,`-p`,b7],e]))}function S7(e,t){let n=e.split(`${b7}\n`);return n.length===t?n.map(e=>e.replace(/\n$/,``)):null}const C7=(e,t)=>[`show-options`,`-q`,`-v`,`-t`,e,t],Nse=e=>[`show-options`,`-g`,`-q`,`-v`,e],w7=e=>[[`show-options`,`-t`,e],C7(e,`status`),...p7.map(t=>C7(e,h7(t)))];function T7(e){let[t=``,n=``,...r]=e,i=t.split(`
|
|
508
508
|
`).map(e=>e.split(` `)[0]??``),a={};for(let e of p7)i.includes(h7(e))&&(a[e]=r[e]??``);let o=i.includes(`status-format`)||Object.keys(a).length>0;return{status:i.includes(`status`)?n:null,formats:o?a:null}}function E7(e,t){return[[`set-option`,`-u`,`-t`,e,`status-format`],...Object.entries(t??{}).map(([t,n])=>[`set-option`,`-t`,e,h7(Number(t)),_7(n)])]}const Pse=e=>[[`display-message`,`-p`,`-t`,e,`#{status}`],...w7(e),...p7.map(e=>Nse(h7(e))),C7(e,d7),C7(e,f7)];function D7(e,t,n){let r,i;try{r=JSON.parse(e),i=t===``?r.base:g7(t)}catch(e){return{kind:`theirs`,why:`${d7} does not read (${String(e)})`}}return r.owner===n?{kind:`ours`,prior:r,status:i}:{kind:`theirs`,why:`the daemon at ${JSON.stringify(r.owner)} draws it`}}const O7=(e,t)=>[[`set-option`,`-t`,e,i7,t.name],[`set-option`,`-t`,e,a7,t.click]];function Fse(e,t,n,r){let[i=``,...a]=t,o=T7(a.slice(0,2+u7)),s=a.slice(2+u7,2+2*u7),[c=``,l=``]=a.slice(2+2*u7);if(c!==``){let t=D7(c,l,n);return t.kind===`theirs`?t:{...t,commands:O7(e,r)}}let u=g7(i),d={};for(let e=0;e<u;e++){let t=o.formats===null?s[e]:o.formats[e];t!==void 0&&t!==``&&(d[e]=t)}let f={...d,...Object.fromEntries(Array.from({length:u7-u},(e,t)=>[u+t,Ase(t)]))},p={owner:n,base:u,status:o.status,formats:o.formats,wrote:f};return{kind:`lay-out`,prior:p,commands:[[`set-option`,`-t`,e,d7,JSON.stringify(p)],...O7(e,r),...E7(e,f)]}}const k7=e=>[...w7(e),C7(e,f7)];function A7(e,t,n){let r=T7(n.slice(0,2+u7)),i=n[2+u7]??``,a=[],o=[];if(Mse(r.formats,t.wrote))a.push(...E7(e,t.formats));else{o.push(`status-format`);for(let[n,i]of Object.entries(r.formats??{}))Number(n)>=t.base&&i===t.wrote[Number(n)]&&a.push([`set-option`,`-u`,`-t`,e,h7(+n)])}return i!==``&&(r.status===i?a.push(t.status===null?[`set-option`,`-u`,`-t`,e,`status`]:[`set-option`,`-t`,e,`status`,_7(t.status)]):o.push(`status`)),a.push(...p7.map(t=>[`set-option`,`-q`,`-u`,`-t`,e,m7(t)]),[`set-option`,`-q`,`-u`,`-t`,e,d7],[`set-option`,`-q`,`-u`,`-t`,e,f7],[`set-option`,`-q`,`-u`,`-t`,e,i7],[`set-option`,`-q`,`-u`,`-t`,e,a7]),{commands:a,kept:o}}const j7=[[`list-keys`,`-T`,`root`]];var Ise=class{held=new Map;servers=new Map;closed=!1;writes=0;failedWrites=0;constructor(e){this.deps=e}observe(e,t,n){if(this.closed)return;let r=this.held.get(e),i=n?t.kind===`runs`?t.tmux:r??null:null;if(r!==void 0&&(i===null||!Ac(r,i))&&this.release(r,`switched off or moved`),i===null||this.held.has(e))return;let a={sessionId:e,socket:i.socket,pane:i.pane,unsubscribe:null,frame:null};this.held.set(e,a),this.serverOf(i.socket),this.deps.log(`info`,`tmux-status: holding sid=${JSON.stringify(e)} pane=${i.pane} socket=${JSON.stringify(i.socket)}`),a.unsubscribe=this.deps.subscribe(e,{lane:`tmuxStatus`,frame:e=>{a.frame=e.value,this.reconcile(a.socket)},refused:t=>{this.held.get(e)===a&&this.release(a,`refused: ${t.error}`)},drawing:()=>this.draws(a)})}answered(e,t){if(this.closed)return;let n=this.serverOf(e);n.view=t;for(let n of[...this.held.values()])if(n.socket===e)if(!t.sessionOf.has(n.pane))this.release(n,`pane gone`);else{let e=this.deps.sessionInPane(n);e!==null&&e!==n.sessionId&&this.release(n,`pane taken by sid=${JSON.stringify(e)}`)}this.reconcile(e)}draws(e){let t=this.servers.get(e.socket),n=t?.view?.sessionOf.get(e.pane);return n!==void 0&&t.layouts.has(n)&&t.view.shownBy.get(n)===e.pane}restoreAll(e){this.closed=!0;for(let e of this.held.values())e.unsubscribe?.();this.held.clear();for(let[t,n]of this.servers){for(let[r,i]of[...n.layouts]){n.layouts.delete(r);let a=this.askSync(e,t,k7(r));if(a===null)continue;let o=A7(r,i.prior,a);this.writeSync(e,t,o.commands),this.saidRestored(t,r,o.kept)}if(n.binding===`none`)continue;n.binding=`none`;let r=this.askSync(e,t,j7);if(r===null)continue;let i=this.bindingRestore(t,r[0]??``);if(i===null)continue;let a=this.writeSync(e,t,[i.command]);this.saidBindingRestore(t,a,i.user)}}linkAt(e){let t=Lse(e),[n,r,i,a,...o]=t??[];if(t===null||n===void 0||r===void 0||i===void 0||a===void 0||o.length>0)return{kind:`refused`,reason:`${aC} needs <socket>/<mac>/<pane>/<range>, got ${JSON.stringify(e)}`};if(!this.deps.signer.verifyBinding(n,r))return{kind:`refused`,reason:`a status-line click on ${JSON.stringify(n)} whose mac is not this renderer's binding's`};let s=[...this.held.values()].find(e=>e.socket===n&&e.pane===`%${i}`)?.frame?.links,c=s!==void 0&&Object.hasOwn(s,a)?s[a]:void 0;return c===void 0?{kind:`refused`,reason:`pane %${i}'s status line draws no link ${a} now`}:{kind:`link`,url:c}}stats(){return{sessions:this.held.size,layouts:[...this.servers.values()].reduce((e,t)=>e+t.layouts.size,0),writes:this.writes,failedWrites:this.failedWrites}}async settled(){for(let e of this.servers.values())await e.running}serverOf(e){let t=this.servers.get(e);if(t!==void 0)return t;let n={view:null,adopted:!1,layouts:new Map,left:new Map,binding:`none`,running:null,again:!1,lastFailure:null};return this.servers.set(e,n),n}release(e,t){e.unsubscribe?.(),this.held.delete(e.sessionId),this.deps.log(`info`,`tmux-status: released sid=${JSON.stringify(e.sessionId)} pane=${e.pane} — ${t}`),this.reconcile(e.socket)}reconcile(e){let t=this.servers.get(e);if(!(t===void 0||this.closed)){if(t.running!==null){t.again=!0;return}t.running=(async()=>{try{do t.again=!1,await this.step(e,t);while(t.again&&!this.closed)}catch(t){this.deps.log(`warn`,`tmux-status: socket=${JSON.stringify(e)} reconcile threw: ${String(t)}`)}finally{t.running=null}})()}}async step(e,t){let n=t.view;if(n===null)return;t.adopted||(t.adopted=!0,await this.adopt(e,t));let r=new Map;for(let t of this.held.values()){if(t.socket!==e)continue;let i=n.sessionOf.get(t.pane);i!==void 0&&r.set(i,[...r.get(i)??[],t])}for(let i of new Set([...t.layouts.keys(),...t.left.keys(),...r.keys()])){if(this.closed)return;let a=r.get(i)??[],o=t.layouts.get(i);if(a.length===0){t.left.delete(i),o!==void 0&&await this.restore(e,t,i);continue}if(t.left.has(i))continue;let s=o??await this.install(e,t,i);if(s===null)continue;let c=a.find(e=>e.pane===n.shownBy.get(i))?.frame?.rows.slice(0,u7-s.prior.base)??[];await this.draw(e,i,s,c)}this.closed||(t.layouts.size>0?await this.installBinding(e,t):await this.restoreBinding(e,t))}async adopt(e,t){let n=await this.run(e,[`list-sessions`,`-F`,`#{session_id}\t#{${d7}}\t#{${f7}}`]);if(n.kind===`ok`){let r=this.marks(e),i=[];for(let a of n.stdout.split(`
|
|
509
|
-
`)){let[n,o,s=``]=a.split(` `);if(n===void 0||o===void 0||o===``)continue;let c=D7(o,s,this.deps.owner);c.kind===`ours`?(t.layouts.set(n,{prior:c.prior,rows:[],status:c.status}),i.push(...O7(n,r))):this.leave(e,t,n,c.why)}await this.write(e,i)}t.layouts.size>0&&(t.binding=`owed`,this.deps.log(`info`,`tmux-status: socket=${JSON.stringify(e)} took over layouts=${[...t.layouts.keys()].join(`,`)}`))}marks(e){return{name:this.deps.name,click:Tse(this.deps.handler,this.deps.name,e,this.deps.signer.signBinding(e))}}leave(e,t,n,r){t.left.set(n,r),this.deps.log(`warn`,`tmux-status: socket=${JSON.stringify(e)} session ${n} left as it is: ${r}`)}async install(e,t,n){let r=await this.ask(e,Pse(n));if(r===null||this.closed)return null;let i=Fse(n,r,this.deps.owner,this.marks(e));if(i.kind===`theirs`)return this.leave(e,t,n,i.why),null;let a={prior:i.prior,rows:[],status:i.kind===`ours`?i.status:i.prior.base};return t.layouts.set(n,a),await this.write(e,i.commands),this.deps.log(`info`,`tmux-status: socket=${JSON.stringify(e)} ${i.kind===`ours`?`took over`:`laid out`} renderer=${this.deps.name} session ${n} base=${i.prior.base} own=${[i.prior.status===null?[]:[`status`],i.prior.formats===null?[]:[`status-format`]].flat().join(`,`)||`-`}`),a}async draw(e,t,n,r){let i=n.prior.base+r.length,a=[];if(r.forEach((e,r)=>{n.rows[r]!==e&&a.push([`set-option`,`-t`,t,m7(r),e])}),i!==n.status){let e=jse(i);a.push([`set-option`,`-t`,t,`status`,e],[`set-option`,`-t`,t,f7,e])}(a.length===0||(await this.write(e,[[`if-shell`,`-F`,`-t`,t,`#{@cc-candybar-status-prior}`,e7(a)]])).kind===`ok`)&&(n.rows=r,n.status=i)}async restore(e,t,n){let r=t.layouts.get(n);if(r===void 0)return;t.layouts.delete(n);let i=await this.ask(e,k7(n));if(i===null)return;let a=A7(n,r.prior,i);await this.write(e,a.commands),this.saidRestored(e,n,a.kept)}saidRestored(e,t,n){this.deps.log(`info`,`tmux-status: socket=${JSON.stringify(e)} restored session ${t} kept=${n.join(`,`)||`-`}`)}async installBinding(e,t){if(t.binding===`bound`)return;let n=t.binding,r=await this.ask(e,j7);if(r===null||this.closed)return;let{user:i}=c7(r[0]??``);t.binding=`bound`;let a=await this.write(e,[Ose(i),[`set-option`,`-g`,`-q`,`-u`,`@cc-candybar-binding-prior`]]),o=a.kind===`ok`&&a.stdout.includes(`ccb:bound`);o||(t.binding=n);let s=o?`bound MouseDown1Status over ${M7(i)}`:a.kind===`ok`?`left MouseDown1Status unbound: no session names a renderer`:`MouseDown1Status not bound: ${a.reason}`;this.deps.log(`info`,`tmux-status: socket=${JSON.stringify(e)} ${s}`)}async restoreBinding(e,t){if(t.binding===`none`)return;t.binding=`none`;let n=await this.ask(e,j7);if(n===null)return;let r=this.bindingRestore(e,n[0]??``);if(r===null)return;let i=await this.write(e,[r.command]);this.saidBindingRestore(e,i,r.user)}bindingRestore(e,t){let n=c7(t);return n.ours?{command:kse(n.user),user:n.user}:(this.deps.log(`info`,`tmux-status: socket=${JSON.stringify(e)} left MouseDown1Status as it is: not a cc-candybar binding`),null)}saidBindingRestore(e,t,n){let r=t.kind===`ok`?t.stdout.includes(`ccb:restored`)?`restored MouseDown1Status to ${M7(n)}`:t.stdout.includes(`ccb:held`)?`left MouseDown1Status bound: a session still names a renderer`:`MouseDown1Status restore said neither way: ${JSON.stringify(t.stdout)}`:`MouseDown1Status not restored: ${t.reason}`;this.deps.log(`info`,`tmux-status: socket=${JSON.stringify(e)} ${r}`)}counted(e,t){let n=this.serverOf(e);return t.kind===`ok`?(n.lastFailure=null,t):(this.failedWrites++,n.lastFailure!==t.reason&&this.deps.log(`warn`,`tmux-status: socket=${JSON.stringify(e)} ${t.reason}`),n.lastFailure=t.reason,t)}async run(e,t){return this.counted(e,await this.deps.edge.run(e,t))}async ask(e,t){let n=await this.run(e,x7(t));return n.kind===`ok`?S7(n.stdout,t.length):null}askSync(e,t,n){let r=this.counted(t,e(t,x7(n)));return r.kind===`ok`?S7(r.stdout,n.length):null}async write(e,t){return t.length===0?v7:(this.writes++,this.run(e,y7(t)))}writeSync(e,t,n){return n.length===0?v7:(this.writes++,this.counted(t,e(t,y7(n))))}};const M7=e=>e===null?`unbound`:JSON.stringify(e7(e));function Lse(e){try{return Ate(e)}catch(e){if(e instanceof URIError)return null;throw e}}const $=e=>({arity:e,keep:!0}),N7=e=>({arity:e,keep:!1}),Rse={"--add-dir":$(`variadic`),"--agent":$(`one`),"--agents":$(`one`),"--allow-dangerously-skip-permissions":$(`none`),"--allowedTools":$(`variadic`),"--allowed-tools":$(`variadic`),"--append-system-prompt":$(`one`),"--autocompact":$(`one`),"--ax-screen-reader":$(`none`),"--bg":N7(`none`),"--background":N7(`none`),"--bare":$(`none`),"--betas":$(`variadic`),"--brief":$(`none`),"--chrome":$(`none`),"--cloud":N7(`optional`),"-c":N7(`none`),"--continue":N7(`none`),"--dangerously-skip-permissions":$(`none`),"-d":$(`optional`),"--debug":$(`optional`),"--debug-file":$(`one`),"--desktop":N7(`none`),"--disable-slash-commands":$(`none`),"--disallowedTools":$(`variadic`),"--disallowed-tools":$(`variadic`),"--effort":$(`one`),"--environment":N7(`one`),"--exclude-dynamic-system-prompt-sections":$(`none`),"--fallback-model":$(`one`),"--file":$(`variadic`),"--fork-session":N7(`none`),"--forward-subagent-text":$(`none`),"--from-pr":N7(`optional`),"-h":N7(`none`),"--help":N7(`none`),"--ide":$(`none`),"--include-hook-events":$(`none`),"--include-partial-messages":$(`none`),"--input-format":$(`one`),"--json-schema":$(`one`),"--max-budget-usd":$(`one`),"--mcp-config":$(`variadic`),"--model":$(`one`),"-n":$(`one`),"--name":$(`one`),"--no-chrome":$(`none`),"--no-session-persistence":$(`none`),"--output-format":$(`one`),"--permission-mode":$(`one`),"--permission-prompts":$(`one`),"--plugin-dir":$(`one`),"--plugin-url":$(`one`),"-p":N7(`none`),"--print":N7(`none`),"--prompt-suggestions":$(`optional`),"--remote-control":$(`optional`),"--remote-control-session-name-prefix":$(`one`),"--replay-user-messages":$(`none`),"--restricted":$(`none`),"-r":N7(`optional`),"--resume":N7(`optional`),"--safe-mode":$(`none`),"--session-id":N7(`one`),"--setting-sources":$(`one`),"--settings":$(`one`),"--strict-mcp-config":$(`none`),"--system-prompt":$(`one`),"--system-prompt-snapshot":$(`one`),"--teleport":N7(`optional`),"--tmux":N7(`none`),"--tools":$(`variadic`),"--verbose":$(`none`),"-v":N7(`none`),"--version":N7(`none`),"-w":N7(`optional`),"--worktree":N7(`optional`)},zse={resume:`--resume`,fresh:`--session-id`};function Bse(e){return[zse[e.kind],e.sessionId]}const P7=e=>e.startsWith(`-`)&&e!==`-`;function F7(e,t){let n=I7(t);return n===null?{dir:e??t,args:[]}:e!==null&&Vse(e,n.top)?{dir:e,args:[]}:{dir:e===null||I7(e)!==null?n.repo:e,args:[`--worktree`,n.name]}}const Vse=(e,t)=>e===t||e.startsWith(t+s.sep);function Hse(e){let t=[],n=e.slice(1),r=0;for(;r<n.length;){let e=n[r];if(r+=1,e===`--`)break;if(!P7(e))continue;let i=e.indexOf(`=`),a=i===-1?e:e.slice(0,i),o=Rse[a];if(o===void 0)return{kind:`refused`,reason:`Claude Code was started with ${a}, which cc-candybar does not know how to carry to a restart`};let s=i===-1?o.arity===`one`?n.slice(r,r+1):o.arity===`optional`?n.slice(r,r+1).filter(e=>!P7(e)):o.arity===`variadic`?Use(n.slice(r),e=>!P7(e)):[]:[];if(o.arity===`one`&&i===-1&&s.length===0)return{kind:`refused`,reason:`Claude Code was started with ${a} and no value after it`};r+=s.length,o.keep&&t.push(e,...s)}return{kind:`args`,args:t}}function I7(e){let t=e.split(s.sep),n=t.findLastIndex((e,n)=>e===`worktrees`&&t[n-1]===`.claude`&&n+1<t.length);return n===-1?null:{name:t[n+1].replaceAll(`+`,`/`),top:t.slice(0,n+2).join(s.sep),repo:t.slice(0,n-1).join(s.sep)||s.sep}}function Use(e,t){let n=e.findIndex(e=>!t(e));return n===-1?[...e]:e.slice(0,n)}const L7=`candybar-band@cc-candybar`,Wse=s.join(`bin`,`cc-candybar-native`),Gse=pI(`/reload-plugins`);function Kse(e,t,n){let r=e();if(r.kind===`gone`)throw Error(r.reason);let i=()=>{let t=e();if(t.kind===`gone`)return t;let n=i$(t.session.hints.tmux);return n.kind===`refused`?n:{kind:`in`,session:t.session,tmux:n.hint}},a=async e=>{let r=i();if(r.kind!==`in`)return r;let o=await t(r.tmux,async()=>{let t=i();return t.kind!==`in`||!Ac(t.tmux,r.tmux)?t:{kind:`held`,value:await e(t.session,t.tmux)}});return o.kind===`in`?(n(r.tmux,o.tmux),a(e)):o};return{session:r.session,inPane:a}}function R7(e,t){if(e.kind!==`held`)throw new L(t(e.reason));return e.value}const z7=e=>({kind:`done`,said:e});function B7(e){let t=i$(e.hints.tmux);if(t.kind===`refused`)throw new L(t.reason);return t.hint}const qse={band:{on:async(e,t,n)=>{let r=Rn(t.bundle);if(r===null)throw new L(`${Yc.band.label} runs the band mod from a cc-candybar source checkout, and this daemon runs ${t.bundle} — run the daemon from a checkout (mod/README.md)`);let i=s.join(r,Wse);if(!n.fileExists(i))throw new L(`the band mod starts ${i}, which is not built — run \`just install-rust\` in ${r}`);return{kind:`underway`,said:`installing ${L7} from ${r}`,finished:Jse(e,r,n)}},off:async()=>z7(`nothing to stop: the band mod ends its child once the lane is off`)},statusline:{on:async(e,t,n)=>{let r=B7(e.session),i=Tn(t.preload),a=[t.preload,i].find(e=>!n.fileExists(e));if(a!==void 0)throw new L(`${Yc.statusline.label} restarts Claude Code under the attach launcher, and ${a} is not there — run \`cc-candybar install\` (in a checkout, \`pnpm build\`)`);return{kind:`underway`,said:`restarting Claude Code in ${r.pane} under the attach launcher`,finished:e.inPane((e,r)=>Zse(e,r,{node:t.node[0],launcher:i,preload:t.preload},n)).then(e=>R7(e,e=>`Claude Code was not restarted under the attach launcher: ${e}`))}},off:async()=>z7(`nothing to stop: the attached statusline draws its command's output while the lane is off`)},pane:{on:async(e,t,n)=>R7(await e.inPane(async(e,r)=>{let i=await n.barPanes(r);return i.length>0?z7(`bar pane ${i.join(`, `)} already draws ${r.pane}'s bar`):z7(`opened bar pane ${await n.openBarPane(r,[...t.node,t.bundle,`bar-pane`,r.pane],er(t.home))} under ${r.pane}`)}),e=>`no bar pane was opened: ${e}`),off:async(e,t,n)=>{let r=await e.inPane(async(e,t)=>{let r=await n.barPanes(t);for(let e of r)await n.closePane(t,e);return z7(r.length===0?`no bar pane draws ${t.pane}'s bar`:`closed bar pane ${r.join(`, `)}`)});return r.kind===`refused`?z7(`no bar pane to close: ${r.reason}`):R7(r,e=>e)}},tmuxStatus:{on:async({session:e})=>z7(`the daemon draws ${B7(e).pane}'s bar in its status line`),off:async()=>z7(`nothing to stop: the daemon puts the status line back once the lane is off`)}};async function Jse(e,t,n){let{session:r}=e,i={sessionId:r.sessionId,projectDir:r.origin.projectDir,claudeConfigDir:r.hints.claudeConfigDir};await n.claude([`plugin`,`marketplace`,`add`,t],i),await n.claude([`plugin`,`install`,L7],i);let a=await e.inPane((e,t)=>a$(n.claudeInput,t,Gse)),o=a.kind===`held`?a.value:{kind:`refused`,reason:a.reason};if(o.kind===`refused`)throw Error(`the band mod is installed, but /reload-plugins was not typed: ${o.reason} — or type /reload-plugins yourself`);return`installed ${L7} from ${t} and typed /reload-plugins into ${o.pane}`}const Yse=new Set([Go,DP]);function Xse(e){return new Map(e.flatMap(e=>{let t=e.indexOf(`=`);return t>0?[[e.slice(0,t),e.slice(t+1)]]:[]}))}async function Zse(e,t,n,r){let i=await r.paneClaude(t);if(i.attached)return`left Claude Code in ${t.pane} running: it already runs under the attach launcher`;if(!i.fromShell)throw Error(`Claude Code is the first process of pane ${t.pane}, so nothing would be left in the pane to start it again under the attach launcher — start Claude Code from a shell in the pane`);let a=await r.moduleGraph(n.node,N(n.launcher),i.executable);if(!a.ok)throw Error(`Claude Code in ${t.pane} runs ${i.executable}, which the attach launcher cannot start (${a.reason}) — ${Yc.statusline.label} needs the native Claude Code install (\`claude install\`), so it was left running`);let o=await r.paneClaude(t);if(o.pid!==i.pid||o.startTime!==i.startTime)throw Error(`Claude Code in ${t.pane} is no longer the process the restart read (pid ${i.pid}, started ${i.startTime}; now pid ${o.pid}, started ${o.startTime}), so it was not restarted under the attach launcher`);let s=nce(await r.claudeInput.read(t));if(s!==null)throw Error(`Claude Code in ${t.pane} was left running: ${s} — then turn ${Yc.statusline.label} off and on again`);let c=Qse(e,r.presence(e.transcript));if(c!==null)throw Error(`Claude Code in ${t.pane} was left running: ${c}`);let l=Hse(i.argv);if(l.kind===`refused`)throw Error(`${l.reason} — restart it with that flag removed`);let u=Xse(i.env),d=u.get(`PATH`),f=r.launcherNode(d);if(f.kind===`refused`)throw Error(`Claude Code in ${t.pane} was left running, under the PATH it was started with: ${f.why}`);let p=r.onPath(`claude`,d)===i.executable?`claude`:i.executable,m=[...u].filter(([e])=>Yse.has(e)),h=(e,t)=>On(n.preload,{dir:e.dir,env:m,program:p,args:[...e.args,...l.args,...Bse(t)]}),g=r.heldSession({pid:i.pid,startTime:i.startTime,configDir:Ko(Object.fromEntries(u),i.cwd)});if(g.kind!==`holds`)throw Error(`Claude Code in ${t.pane} was left running: ${g.why}, so which session it runs is unknown`);if(g.sessionId!==e.sessionId)throw Error(`Claude Code in ${t.pane} now runs session ${g.sessionId}, not ${e.sessionId}, so it was not restarted under the attach launcher — turn ${Yc.statusline.label} off and on again from the bar in ${t.pane} to restart that one`);if(r.terminate(i.pid),!await r.exited(i.pid,15e3))throw Error(`Claude Code in ${t.pane} did not exit within ${15e3/1e3} s of SIGTERM, so it was not restarted under the attach launcher`);let _=(e,n)=>Error(`Claude Code in ${t.pane} exited, but ${e}, so it was not started again — start it with \`${n}\``),v=$se(e,r.presence(e.transcript)),y=v.kind===`unchecked`?{kind:`resume`,sessionId:e.sessionId}:v,b;try{b=await r.paneDir(t,i.parent)}catch(e){throw _(`the directory it was started in could not be read (${e.message})`,h(F7(null,i.cwd),y))}let x=h(F7(b,i.cwd),y);if(v.kind===`unchecked`)throw _(`whether session ${e.sessionId} has a conversation could not be seen (${v.error})`,x);try{await r.typeShellLine(t,x)}catch(e){throw _(`the line could not be typed into its pane (${e.message})`,x)}if(!await r.followed(e.sessionId,`statusline`,3e4))throw Error(`Claude Code in ${t.pane} did not come back attached within ${3e4/1e3} s of \`${x}\` — the pane says why`);return`restarted Claude Code in ${t.pane} under the attach launcher with \`${x}\`, ${ece[v.kind](e.sessionId)}, and its statusline follows lane B`}function Qse(e,t){return typeof t==`object`?`whether session ${e.sessionId} has a conversation could not be seen (${t.error})`:t===`present`||e.answered===`no`?null:e.answered===`yes`?`session ${e.sessionId} has a conversation but no transcript to resume it from (is session persistence off?), so a restart would lose it`:`this Claude Code does not say whether session ${e.sessionId} has a conversation, and it has no transcript to resume one from`}function $se(e,t){return typeof t==`object`?{kind:`unchecked`,error:t.error}:{kind:t===`present`?`resume`:`fresh`,sessionId:e.sessionId}}const ece={resume:e=>`resuming ${e}`,fresh:e=>`starting ${e} afresh, since it had no conversation yet`},tce={"in-mode":`its pane is in tmux copy mode — leave it (q)`,stashed:`it holds a stashed prompt (ctrl+s), which ending it would lose — restore or send it`,"no-prompt":`it is not at its prompt (a dialog or picker is open) — close it`};function nce(e){let t=$Q(e);return t.kind===`ready`?n$(e)?`it is in the middle of a turn, which ending it would end — wait until it is idle`:e$(e)?`its prompt holds a draft, which ending it would lose — send or clear it`:null:tce[t.kind]}var rce=class{owed=new Map;closed=!1;constructor(e){this.deps=e}clicked(e,t,n){let r=Xc.filter(e=>t[e]!==n[e]),i=this.take(e);for(let e of r)i.has(e)||i.set(e,t[e]);let a=e=>r.includes(e)?`click`:`owed`;if(this.deps.latest(e)!==null)return V7(e,i,n,a,this.deps.log);for(let[e,t]of i)t===n[e]&&i.delete(e);if(r.length>0){let t=[...i.keys()].map(e=>`${e} ${n[e]?`on`:`off`}`);this.deps.log(`info`,`lane: owed ${t.join(`,`)||`nothing`} (session=${e})`)}i.size>0&&this.owed.set(e,i);for(let[e,t]of this.owed){if(this.owed.size<=1024)break;this.owed.delete(e),this.deps.log(`warn`,`lane: owed dropped sid=${JSON.stringify(e)} lanes=${[...t.keys()].join(`,`)}`)}return[]}noted(e,t){return V7(e,this.take(e),t,()=>`owed`,this.deps.log)}take(e){let t=this.owed.get(e)??new Map;return this.owed.delete(e),t}async setup({sessionId:e,lane:t,on:n,by:r}){if(this.closed)throw new lc(`lane setup`);let i=`by=${r} (session=${e})`,a=e=>{let r=`lane: ${t} ${n?`on`:`off`}: ${e instanceof Error?e.message:String(e)}`;return this.deps.log(`warn`,`${r} ${i}`),cc(r)},o;try{o=await qse[t][n?`on`:`off`](Kse(()=>this.latestOf(e),this.paneOrder,(e,r)=>this.deps.log(`info`,`lane: ${t} ${n?`on`:`off`} — the session moved from ${e.pane} to ${r.pane} while its step waited for the pane, so it takes ${r.pane}'s order ${i}`)),this.deps.host,this.deps.edge)}catch(e){return a(e)}return this.deps.log(`info`,`lane: ${t} ${n?`on`:`off`} — ${o.said} ${i}`),o.kind===`done`?{kind:`ok`,said:o.said}:o.finished.then(e=>(this.deps.log(`info`,`lane: ${t} ${e} ${i}`),{kind:`ok`,said:e}),a)}paneOrder=(e,t)=>this.deps.paneOrder(e,()=>{if(this.closed)throw new lc(`lane setup`);return t()});latestOf(e){let t=this.deps.latest(e);return t===null?{kind:`gone`,reason:`this daemon no longer holds a request of session ${e}`}:{kind:`known`,session:t}}close(){this.closed=!0}};function V7(e,t,n,r,i){let a=[];for(let[o,s]of t)n[o]===s?i(`info`,`lane: ${o} ${s?`on`:`off`} — nothing owed: its switch is back where the lane is by=${r(o)} (session=${e})`):a.push({kind:`lane-setup`,sessionId:e,lane:o,on:n[o],by:r(o)});return a}const ice=[`request`,`feed`],H7=new WeakMap;let ace=0;const U7=e=>{let t=H7.get(e);if(t!==void 0)return t;let n=ace++;return H7.set(e,n),n};var oce=class{records=new Map;constructor(e=512){this.maxRecords=e}of(e,t){return this.records.get(W7(e,t))?.warnings??[]}ofSession(e,t,n){let r=U7(n.config),i=[];for(let n of ice){let a=this.records.get(W7(e,n)),o=n===t?this.of(e,t):a?.generation===r?a.warnings:[],s=i.map(e=>JSON.stringify(e));for(let e of o){let t=s.indexOf(JSON.stringify(e));t===-1?i.push(e):s.splice(t,1)}}return i}drawn(e,t,n,r){let i=this.of(e,t),a=W7(e,t);this.records.delete(a),this.records.set(a,{generation:U7(n.config),warnings:r});for(let e of this.records.keys()){if(this.records.size<=this.maxRecords)break;this.records.delete(e)}return JSON.stringify(i)!==JSON.stringify(r)}};const W7=(e,t)=>`${t}\0${e}`,sce={session:({session:e})=>[`session`,e],pane:({tmux:e})=>[`pane`,kc(e)],lane:({session:e,lane:t})=>[`lane`,e,t]};function cce(e){let t=sce[e.kind];return JSON.stringify(t(e))}var lce=class{gathers=new F8;effects=new F8;open=!0;holder=null;gathersInFlight=0;take(e,t){if(!this.open)throw new lc(e);if(this.holder!==null)throw Error(`journal: ${e} took a turn inside ${this.holder}'s`);this.holder=e;try{return t()}finally{this.holder=null}}inTurn(){return this.holder}async gathering(e){this.gathersInFlight++;try{return await this.gathers.run(`gathers`,()=>{if(!this.open)throw new lc(`doctor`);return e()})}finally{this.gathersInFlight--}}performing(e,t){return this.effects.run(cce(e),t)}getStats(){return{gathers:this.gathersInFlight}}close(){this.open=!1}},uce=class{sessions=new Map;disposed=!1;constructor(e){this.deps=e}clicked(e,t){let n=this.record(e,t);n.since=t,this.settle(e)}since(e,t){let n=this.record(e,t);return n.shown?n.since:void 0}drawn(e,t,n,r){let i=this.since(e,t),a=r(i);return this.observe(e,t,a.frame.rows.some(e=>e.kind===`menu`),n),{...a,idleSince:i}}observe(e,t,n,r){let i=this.record(e,t);t<i.drawnAt||(i.drawnAt=t,n&&!i.shown&&t>i.since&&(i.since=t),i.shown=n,i.timeoutS=r,this.settle(e))}getStats(){let e=0;for(let t of this.sessions.values())t.timer!==null&&e++;return{sessions:this.sessions.size,armed:e}}dispose(){this.disposed=!0;for(let e of this.sessions.values())this.disarm(e);this.sessions.clear()}record(e,t){let n=this.sessions.get(e)??{since:t,timeoutS:0,shown:!1,drawnAt:t,timer:null,closing:!1};this.sessions.delete(e),this.sessions.set(e,n);for(let[e,t]of this.sessions){if(this.sessions.size<=256)break;this.disarm(t),this.sessions.delete(e)}return n}settle(e){let t=this.sessions.get(e),n=t.shown&&!t.closing&&!this.disposed?ute(t.since,t.timeoutS):null;t.timer?.at!==n&&(this.disarm(t),n!==null&&(t.timer={at:n,clear:this.deps.clock.after(Math.max(0,(n-this.deps.now())*1e3),()=>this.fire(e),{unref:!0})}))}disarm(e){e.timer?.clear(),e.timer=null}fire(e){let t=this.sessions.get(e);t.timer=null;let n=this.deps.now(),r={idleS:n-t.since,timeoutS:t.timeoutS,stillIdle:()=>this.sessions.get(e)===t,closed:()=>{t.since=n,t.shown=!1}};t.closing=!0,this.deps.close(e,r).catch(t=>{r.closed(),this.deps.failed(e,t)}).finally(()=>{t.closing=!1,this.sessions.get(e)===t&&this.settle(e)})}};function dce(e){let{bundle:t,memoryLimitBytes:n,registryUrl:r,clock:i,exit:a,home:o,gates:s,host:c}=e,l=mr(o),u=gr(c,o),d=()=>it(new Date(i.now())),f=new AbortController,p=!1,m=(t,n)=>e.daemonLog.log(t,p?`after close: ${n}`:n),h=new r3(i),g=e.launcher({inherited:c.env,stats:h.launchStats,signal:f.signal,now:d,observeWarnings:_ce(m,()=>ue)}),_=e.probe(g),v=e.storage(m,e.filesystem),y=new lce,b=new o0(y,v.session),x=new C0(e.filesystem,b,m,v.history),S=Vi({...e.limits({startedAtMs:h.startedAt.getTime(),exit:a,launcher:g,log:m}),limitBytes:n}),C=new S3,w=new qne,T=e.doctorStores,E=new xj({filesystem:e.filesystem,clock:i,counters:h,logger:m}),ee=new Hj(m),D=new Hc({watchers:E,logger:m,clock:i}),te=new sM({launcher:g,clock:i,logger:m,ledger:ee,watchers:E,fileEvents:D}),O=Aoe({launcher:g,host:c,pricing:e.pricing({cacheRoot:qn(o),closing:f.signal,log:m}),watchers:E,fileEvents:D,clock:i,logger:m,ledger:ee}),{managedStorage:k}=O,ne=new Xoe,A=new bne,re=bce(()=>ye,{clock:i,now:d,log:m}),ie={to:o.name,signer:e.linkSigner},ae=xce({managedStorage:k,launcher:g,log:m,clock:i}),oe=e.heldSession(c.home),se=hce(()=>ye,y,{edge:e.laneEdge(g,e=>ue.following(e),f.signal,_,oe),host:{bundle:t.path,node:t.node,home:o,preload:_s(t.path,c)},log:m}),ce=gce(()=>ye,{launcher:g,heldSession:oe,home:o,owner:l.socket,bundle:t,signer:e.linkSigner,log:m}),le=_se({file:l.linkIds,clock:i,retryMs:PZ.still,log:m}),ue=pce(()=>ye,{render:(e,t,n)=>jQ(ye,e,t,n),visibility:mce(()=>ye,{launcher:g,clock:i,log:m}),linkIds:le,clock:i,instant:d,log:m}),de=new oce,fe=bae(),{cache:pe,recorder:me}=fce({clock:i,stateDir:l.state,locations:u,sessionState:b,watchers:E,log:m,links:ie,gates:s,providers:O,updateFact:fe,sourceRuns:te,history:x,navigation:ne,source:tse,budgetBytes:()=>Poe(n),wake:(e,t)=>ue.wake(e,t)});vce({fileEvents:D,watcherRegistry:E,renderCache:pe,frameFeeds:ue});let{binaryWatch:he,updateWatch:ge}=Sce({clock:i,launcher:g,probe:_,filesystem:e.filesystem,bundle:t,stateDir:l.state,registryUrl:r,fetch:e.fetch,gates:s,updateFact:fe,exit:a,log:m}),_e=new _$(y),ve={gates:s,sessionState:b,stateDir:l.state,filesystem:e.filesystem,installedLayers:pe.installedLayers,storedRoot:l.storedRoot,locations:u,journalTurns:y,log:m,launcher:g,now:d,doctor:e.doctorEdge(g,e=>{pe.reload(e,{kind:`doctor`});let t=pe.getOrCreate(e);return{layers:t.configLayers,error:t.lastError,warning:t.lastWarning,unused:t.state.unused,config:t.state.config,repos:t.repos}},c),doctorStores:T,probes:C,clients:w,mismatchRuns:_e,bundle:t.path,claudeInput:e.claudeInput(g),history:x,navigation:ne,links:ie,runs:ae,...Cce(()=>ye)},ye={home:c.home,storedRoot:l.storedRoot,tmp:c.tmp,heldSession:oe,launcher:g,log:m,clock:i,bundle:t.path,sourceDigest:t.digest,doctorStores:T,stats:h,handlerProbes:C,renderSightings:w,mismatchRuns:_e,watcherRegistry:E,refreshLedger:ee,fileEvents:D,payloadProviders:O,sessionState:b,rendererName:o.name,draw:yce(()=>ye),effectSessions:A,menuIdle:re,journalTurns:y,links:ie,runs:ae,sourceRuns:te,laneSetups:se,tmuxStatusLines:ce,frameFeeds:ue,linkIds:le,renderWarnings:de,renderCache:pe,recorder:me,updateWatch:ge,limits:S,verbCtx:ve};return{stats:h,launcher:g,log:m,memoryLimitBytes:n,clock:i,exit:a,handle:async(e,t,n,r)=>(f.signal.throwIfAborted(),Vie(ye,e,t,n,r)),reply:async(e,t,n,r)=>(f.signal.throwIfAborted(),x8(ye,e,t,n,r)),subscribe:(e,t)=>(f.signal.throwIfAborted(),ue.subscribe(e,t)),reloadConfig:e=>{f.signal.throwIfAborted(),ve.reloadConfig(e)},arm(){f.signal.throwIfAborted(),D.start(l.watchProbe),he.arm(),ge.arm(),S.arm()},close(e){return Tce({...ye,journalTurns:y,sessionState:b,closing:f,binaryWatch:he},e),p=!0,g.settled()}}}function fce(e){let{budgetBytes:t,wake:n,providers:r,updateFact:i,sourceRuns:a,history:o,navigation:s,source:c,...l}=e,{log:u,sessionState:d,gates:f}=l;return xQ(e=>new Joe({...l,storage:r.managedStorage,facts:$oe({providers:r,update:()=>i.get(),runs:a}),source:c({providers:r,sessionState:d,stateGates:f.state,history:e=>o.depth(e),navigation:(e,t)=>s.depth(e,d,f.state.gateFor(t))})},{budgetBytes:t,observers:{onReload:(e,t,r,i)=>{u(`info`,Roe(e,r,i));for(let e of t)n(e,`reload`)},onViewChanged:e=>n(e,`data`),...e}}),u)}function pce(e,t){let{visibility:n,linkIds:r,...i}=t;return new BZ({...i,shown:e=>n.shown(e.hints.tmux),watching:()=>n.follow(),refreshes:()=>e().refreshLedger.totals(),encoders:mse(r),watch:(t,n)=>(0,X.reaction)(()=>e().sessionState.revision(t),n),lanes:t=>NQ(e(),t),pin:t=>{let{renderCache:n}=e(),r=n.pin(t);return()=>{n.stopDrawing(t,`feed`),r()}},periods:PZ})}function mce(e,{launcher:t,clock:n,log:r}){return new bse({clock:n,listPanes:e=>oc(t,{socket:e},`frames.visibility`,[`list-panes`,`-a`,`-F`,Y5]),listClients:e=>oc(t,{socket:e},`frames.visibility`,[`list-clients`,`-F`,X5]),sockets:()=>new Set(e().frameFeeds.watched().flatMap(({req:e})=>G7(e))),onAnswer:(t,n)=>e().tmuxStatusLines.answered(t,n),onChange:t=>e().frameFeeds.wakeWhere(`visibility`,e=>G7(e).some(e=>t.has(e))),intervalMs:1e3,log:r})}function G7({hints:{tmux:e}}){return e==null?[]:[e.socket]}function hce(e,t,n){return new rce({...n,latest:t=>{let n=e().frameFeeds.latest(t);return n===null?null:GQ(n)},paneOrder:(e,n)=>t.performing({kind:`pane`,tmux:e},n)})}function gce(e,{launcher:t,heldSession:n,home:r,owner:i,bundle:a,signer:o,log:s}){return new Ise({edge:{run:(e,n)=>oc(t,{socket:e},`tmux-status`,n)},subscribe:(t,n)=>e().frameFeeds.subscribe(t,n),sessionInPane:t=>e().frameFeeds.newestWhere(sl(t,n)),handler:[...Object.entries(er(r)).map(([e,t])=>`${e}=${Sn(t)}`),...[...a.node,a.path].map(Sn),`url-handle`].join(` `),owner:i,name:r.name,signer:o,log:s})}function _ce(e,t){return n=>{n.kind===`launch-pipes`?e(`warn`,n.text):e(n.fault===null?`info`:`warn`,n.fault===null?`launch lifeline running again`:`launch lifeline ${n.fault}; the next launch starts another`),t().wakeWhere(`data`,()=>!0)}}function vce({fileEvents:e,watcherRegistry:t,renderCache:n,frameFeeds:r}){e.subscribe(e=>{switch(e.kind){case`period`:t.judge();return;case`caught-up`:n.reloadEvery({kind:`events-resumed`,since:e.since}),r.wakeWhere(`data`,()=>!0);return;case`moved`:r.wakeWhere(`data`,()=>!0);return}})}function yce(e){return(t,n,r,i)=>qQ(e(),t,n,r,i)}function bce(e,{clock:t,now:n,log:r}){return new uce({clock:t,now:n,close:async(t,n)=>{await u8({kind:`menu-idle`,session:t,idle:n},e())},failed:(e,t)=>p8(r,`menu-idle`,`session=${e}`,t)})}function xce({managedStorage:e,launcher:t,log:n,clock:r}){return new hc({supersede:(t,n)=>e.supersede(t,n),launch:t.launch,log:n,clock:r})}function Sce({clock:e,launcher:t,probe:n,filesystem:r,bundle:i,stateDir:a,registryUrl:o,fetch:s,gates:c,updateFact:l,exit:u,log:d}){let f=Sae({clock:e,targets:i.targets,intervalMs:K7,filesystem:r,held:()=>p.running(),exit:()=>u(0),log:d}),p=yae({fact:l,clock:e,launcher:t,probe:n,entryUrl:i.entryUrl,digest:i.digest,actsDir:tae(a,i.path),intervalMs:K7,releaseIntervalMs:wce,registryUrl:o,fetchImpl:s,gates:c,onApplied:()=>f.checkNow(),log:d});return{binaryWatch:f,updateWatch:p}}function Cce(e){return{clickLanded:t=>e().menuIdle.clicked(t,e().verbCtx.now()),applyUpdate:()=>e().updateWatch.act(),serving:()=>e().limits.serving(),configFor:t=>e().renderCache.getOrCreate(t).state.config,reloadConfig:t=>e().renderCache.reload(t,{kind:`write`}),sourcesFor:t=>e().renderCache.getOrCreate(t).state.sources,lanes:{of:(t,n)=>PQ(e(),t,n),clicked:(t,n,r)=>KQ(e(),t,n,r),arrived:t=>UQ(e(),t),setup:t=>e().laneSetups.setup(t)},diagnosticCopy:(t,n,r)=>e().renderCache.drawnCopy(t,n,r)}}const K7=60*1e3,wce=360*60*1e3;function Tce(e,t){let{journalTurns:n,tmuxStatusLines:r,closing:i,laneSetups:a,frameFeeds:o,linkIds:s,menuIdle:c,updateWatch:l,binaryWatch:u,limits:d,recorder:f,renderCache:p,payloadProviders:{gitProvider:m,usageStore:h,tmuxService:g,hostService:_,managedStorage:v},runs:y,sourceRuns:b,fileEvents:x,watcherRegistry:S,sessionState:C,log:w}=e,T=[[`journalTurns close`,()=>n.close()],[`tmuxStatusLines restore`,()=>r.restoreAll(t)],[`launches abort`,()=>i.abort(Error(`the daemon closed`))],[`laneSetups close`,()=>a.close()],[`frameFeeds close`,()=>o.close()],[`linkIds close`,()=>s.close()],[`menuIdle dispose`,()=>c.dispose()],[`updateWatch close`,()=>l.close()],[`binaryWatch close`,()=>u.close()],[`limits disarm`,()=>d.disarm()],[`recorder close`,()=>f.close()],[`renderCache close`,()=>p.close()],[`gitService close`,()=>m.close()],[`usageStore close`,()=>h.close()],[`tmuxService close`,()=>g.close()],[`hostService close`,()=>_.close()],[`runs close`,()=>y.close()],[`sourceRuns close`,()=>b.close()],[`managedStorage close`,()=>v.close()],[`fileEvents close`,()=>x.close()],[`watcherRegistry close`,()=>S.closeAll()],[`sessionState close`,()=>C.close()]];for(let[e,t]of T)try{t()}catch(t){w(`warn`,`${e} failed: ${t.message}`)}}function Ece(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;for(let t of Object.values(e)){if(typeof t!=`object`||!t||Array.isArray(t))return!1;for(let e of Object.values(t))if(typeof e!=`string`)return!1}return!0}var Dce=class{clearTimer=null;pending=null;writing=!1;generation=0;writingPath;constructor(e,t,n=500,r=Ie){this.filePath=e,this.clock=t,this.debounceMs=n,this.logger=r,this.writingPath=ct(e)}load(){let e;try{e=m.readFileSync(this.filePath,`utf8`)}catch(e){let t=e.code;return t!==`ENOENT`&&this.logger(`warn`,`session-state read failed (${t}); starting empty`),{}}try{let t=JSON.parse(e);return Ece(t)?t:(this.logger(`warn`,`session-state load: unexpected shape, starting empty`),{})}catch{return this.logger(`warn`,`session-state load: corrupt JSON, starting empty`),{}}}save(e){this.pending=e,this.schedule()}schedule(){this.clearTimer!==null||this.writing||(this.clearTimer=this.clock.after(this.debounceMs,()=>{this.clearTimer=null,this.write()},{unref:!0}))}async write(){let e=this.pending;if(e===null)return;let t=this.generation,n=this.clock.monotonic(),r=JSON.stringify(e),i=this.writingPath;this.writing=!0;let a=Qe(this.clock,n);try{await m.promises.mkdir(s.dirname(this.filePath),{recursive:!0});let o=await m.promises.open(i,`w`,384);try{await o.writeFile(r),await o.chmod(384),await o.datasync()}finally{await o.close()}let c=!1;if(t===this.generation)try{await m.promises.rename(i,this.filePath),c=!0}catch(e){if(e.code!==`ENOENT`||t===this.generation)throw e}if(t!==this.generation){c||await m.promises.rm(i,{force:!0}),this.logger(`info`,`session-state write superseded by a flush landed=${c} took=${Qe(this.clock,n)}ms held=${a}ms`);return}this.saved(r,e,n,a),this.pending===e&&(this.pending=null)}catch(e){this.logger(`warn`,`session-state save failed: ${e.message}`)}finally{this.writing=!1,this.pending!==null&&this.pending!==e&&this.schedule()}}flush(){if(this.clearTimer?.(),this.clearTimer=null,this.pending===null)return;let e=this.pending,t=this.clock.monotonic(),n=ct(this.filePath);try{m.mkdirSync(s.dirname(this.filePath),{recursive:!0});let r=JSON.stringify(e);m.writeFileSync(n,r,{mode:384}),m.chmodSync(n,384),m.rmSync(this.writingPath,{force:!0}),m.renameSync(n,this.filePath),this.generation++,this.saved(r,e,t,Qe(this.clock,t)),this.pending=null}catch(e){this.logger(`warn`,`session-state save failed: ${e.message}`);try{m.rmSync(n,{force:!0})}catch(e){this.logger(`warn`,`session-state staged file left: ${e.message}`)}}}saved(e,t,n,r){this.logger(`info`,`session-state saved bytes=${Buffer.byteLength(e)} sessions=${Object.keys(t).length} took=${Qe(this.clock,n)}ms held=${r}ms`)}};function Oce(e,t,n,r){return{session:new Dce(e.sessionState,n,500,t),history:G0(r,e.settingsHistory,e.storedRoot,t)}}function q7(e,t,n){for(let r of(t??``).split(s.delimiter)){if(!s.isAbsolute(r))continue;let t=s.join(r,e);if(n(t))return t}return null}function J7(e,t){try{return m.accessSync(e,t),m.statSync(e).isFile()}catch{return!1}}function kce(e){try{return m.realpathSync(e)}catch{return s.resolve(e)}}function Ace(e,t,n){let r=q7(`node`,e,t);return r===null?{kind:`refused`,why:"no `node` on PATH to run the attach launcher"}:s.basename(n(r))===`bun`?{kind:`refused`,why:`the \`node\` on PATH (${r}) is Bun; the attach launcher runs under Node`}:{kind:`node`,file:r}}const Y7=2e3;async function X7(e,t,n,r){let i=await oc(e,t,`lane.tmux`,n,r);if(i.kind!==`ok`)throw Error(i.reason);return i.stdout}function Z7(e,t){if(t.ok)return t.stdout;let n=ht(t,t.stdout);throw Error(`${e} failed (${gt(t)}${n===``?``:`: ${n}`})`)}function jce(e){try{let t=JSON.parse(e);if(typeof t==`object`&&t&&`ok`in t&&t.ok===!1&&`reason`in t&&typeof t.reason==`string`)return`detail`in t&&typeof t.detail==`string`?`${t.reason}: ${t.detail}`:t.reason}catch{}return null}const Mce=/(?:^|\s)bar-pane\s+["'\\]*(%\d+)["']*\s*$/;function Nce(e,t){return e.split(`
|
|
509
|
+
`)){let[n,o,s=``]=a.split(` `);if(n===void 0||o===void 0||o===``)continue;let c=D7(o,s,this.deps.owner);c.kind===`ours`?(t.layouts.set(n,{prior:c.prior,rows:[],status:c.status}),i.push(...O7(n,r))):this.leave(e,t,n,c.why)}await this.write(e,i)}t.layouts.size>0&&(t.binding=`owed`,this.deps.log(`info`,`tmux-status: socket=${JSON.stringify(e)} took over layouts=${[...t.layouts.keys()].join(`,`)}`))}marks(e){return{name:this.deps.name,click:Tse(this.deps.handler,this.deps.name,e,this.deps.signer.signBinding(e))}}leave(e,t,n,r){t.left.set(n,r),this.deps.log(`warn`,`tmux-status: socket=${JSON.stringify(e)} session ${n} left as it is: ${r}`)}async install(e,t,n){let r=await this.ask(e,Pse(n));if(r===null||this.closed)return null;let i=Fse(n,r,this.deps.owner,this.marks(e));if(i.kind===`theirs`)return this.leave(e,t,n,i.why),null;let a={prior:i.prior,rows:[],status:i.kind===`ours`?i.status:i.prior.base};return t.layouts.set(n,a),await this.write(e,i.commands),this.deps.log(`info`,`tmux-status: socket=${JSON.stringify(e)} ${i.kind===`ours`?`took over`:`laid out`} renderer=${this.deps.name} session ${n} base=${i.prior.base} own=${[i.prior.status===null?[]:[`status`],i.prior.formats===null?[]:[`status-format`]].flat().join(`,`)||`-`}`),a}async draw(e,t,n,r){let i=n.prior.base+r.length,a=[];if(r.forEach((e,r)=>{n.rows[r]!==e&&a.push([`set-option`,`-t`,t,m7(r),e])}),i!==n.status){let e=jse(i);a.push([`set-option`,`-t`,t,`status`,e],[`set-option`,`-t`,t,f7,e])}(a.length===0||(await this.write(e,[[`if-shell`,`-F`,`-t`,t,`#{@cc-candybar-status-prior}`,e7(a)]])).kind===`ok`)&&(n.rows=r,n.status=i)}async restore(e,t,n){let r=t.layouts.get(n);if(r===void 0)return;t.layouts.delete(n);let i=await this.ask(e,k7(n));if(i===null)return;let a=A7(n,r.prior,i);await this.write(e,a.commands),this.saidRestored(e,n,a.kept)}saidRestored(e,t,n){this.deps.log(`info`,`tmux-status: socket=${JSON.stringify(e)} restored session ${t} kept=${n.join(`,`)||`-`}`)}async installBinding(e,t){if(t.binding===`bound`)return;let n=t.binding,r=await this.ask(e,j7);if(r===null||this.closed)return;let{user:i}=c7(r[0]??``);t.binding=`bound`;let a=await this.write(e,[Ose(i),[`set-option`,`-g`,`-q`,`-u`,`@cc-candybar-binding-prior`]]),o=a.kind===`ok`&&a.stdout.includes(`ccb:bound`);o||(t.binding=n);let s=o?`bound MouseDown1Status over ${M7(i)}`:a.kind===`ok`?`left MouseDown1Status unbound: no session names a renderer`:`MouseDown1Status not bound: ${a.reason}`;this.deps.log(`info`,`tmux-status: socket=${JSON.stringify(e)} ${s}`)}async restoreBinding(e,t){if(t.binding===`none`)return;t.binding=`none`;let n=await this.ask(e,j7);if(n===null)return;let r=this.bindingRestore(e,n[0]??``);if(r===null)return;let i=await this.write(e,[r.command]);this.saidBindingRestore(e,i,r.user)}bindingRestore(e,t){let n=c7(t);return n.ours?{command:kse(n.user),user:n.user}:(this.deps.log(`info`,`tmux-status: socket=${JSON.stringify(e)} left MouseDown1Status as it is: not a cc-candybar binding`),null)}saidBindingRestore(e,t,n){let r=t.kind===`ok`?t.stdout.includes(`ccb:restored`)?`restored MouseDown1Status to ${M7(n)}`:t.stdout.includes(`ccb:held`)?`left MouseDown1Status bound: a session still names a renderer`:`MouseDown1Status restore said neither way: ${JSON.stringify(t.stdout)}`:`MouseDown1Status not restored: ${t.reason}`;this.deps.log(`info`,`tmux-status: socket=${JSON.stringify(e)} ${r}`)}counted(e,t){let n=this.serverOf(e);return t.kind===`ok`?(n.lastFailure=null,t):(this.failedWrites++,n.lastFailure!==t.reason&&this.deps.log(`warn`,`tmux-status: socket=${JSON.stringify(e)} ${t.reason}`),n.lastFailure=t.reason,t)}async run(e,t){return this.counted(e,await this.deps.edge.run(e,t))}async ask(e,t){let n=await this.run(e,x7(t));return n.kind===`ok`?S7(n.stdout,t.length):null}askSync(e,t,n){let r=this.counted(t,e(t,x7(n)));return r.kind===`ok`?S7(r.stdout,n.length):null}async write(e,t){return t.length===0?v7:(this.writes++,this.run(e,y7(t)))}writeSync(e,t,n){return n.length===0?v7:(this.writes++,this.counted(t,e(t,y7(n))))}};const M7=e=>e===null?`unbound`:JSON.stringify(e7(e));function Lse(e){try{return Ate(e)}catch(e){if(e instanceof URIError)return null;throw e}}const $=e=>({arity:e,keep:!0}),N7=e=>({arity:e,keep:!1}),Rse={"--add-dir":$(`variadic`),"--agent":$(`one`),"--agents":$(`one`),"--allow-dangerously-skip-permissions":$(`none`),"--allowedTools":$(`variadic`),"--allowed-tools":$(`variadic`),"--append-system-prompt":$(`one`),"--autocompact":$(`one`),"--ax-screen-reader":$(`none`),"--bg":N7(`none`),"--background":N7(`none`),"--bare":$(`none`),"--betas":$(`variadic`),"--brief":$(`none`),"--chrome":$(`none`),"--cloud":N7(`optional`),"-c":N7(`none`),"--continue":N7(`none`),"--dangerously-skip-permissions":$(`none`),"-d":$(`optional`),"--debug":$(`optional`),"--debug-file":$(`one`),"--desktop":N7(`none`),"--disable-slash-commands":$(`none`),"--disallowedTools":$(`variadic`),"--disallowed-tools":$(`variadic`),"--effort":$(`one`),"--environment":N7(`one`),"--exclude-dynamic-system-prompt-sections":$(`none`),"--fallback-model":$(`one`),"--file":$(`variadic`),"--fork-session":N7(`none`),"--forward-subagent-text":$(`none`),"--from-pr":N7(`optional`),"-h":N7(`none`),"--help":N7(`none`),"--ide":$(`none`),"--include-hook-events":$(`none`),"--include-partial-messages":$(`none`),"--input-format":$(`one`),"--json-schema":$(`one`),"--max-budget-usd":$(`one`),"--mcp-config":$(`variadic`),"--model":$(`one`),"-n":$(`one`),"--name":$(`one`),"--no-chrome":$(`none`),"--no-session-persistence":$(`none`),"--output-format":$(`one`),"--permission-mode":$(`one`),"--permission-prompts":$(`one`),"--plugin-dir":$(`one`),"--plugin-url":$(`one`),"-p":N7(`none`),"--print":N7(`none`),"--prompt-suggestions":$(`optional`),"--remote-control":$(`optional`),"--remote-control-session-name-prefix":$(`one`),"--replay-user-messages":$(`none`),"--restricted":$(`none`),"-r":N7(`optional`),"--resume":N7(`optional`),"--safe-mode":$(`none`),"--session-id":N7(`one`),"--setting-sources":$(`one`),"--settings":$(`one`),"--strict-mcp-config":$(`none`),"--system-prompt":$(`one`),"--system-prompt-snapshot":$(`one`),"--teleport":N7(`optional`),"--tmux":N7(`none`),"--tools":$(`variadic`),"--verbose":$(`none`),"-v":N7(`none`),"--version":N7(`none`),"-w":N7(`optional`),"--worktree":N7(`optional`)},zse={resume:`--resume`,fresh:`--session-id`};function Bse(e){return[zse[e.kind],e.sessionId]}const P7=e=>e.startsWith(`-`)&&e!==`-`;function F7(e,t){let n=I7(t);return n===null?{dir:e??t,args:[]}:e!==null&&Vse(e,n.top)?{dir:e,args:[]}:{dir:e===null||I7(e)!==null?n.repo:e,args:[`--worktree`,n.name]}}const Vse=(e,t)=>e===t||e.startsWith(t+s.sep);function Hse(e){let t=[],n=e.slice(1),r=0;for(;r<n.length;){let e=n[r];if(r+=1,e===`--`)break;if(!P7(e))continue;let i=e.indexOf(`=`),a=i===-1?e:e.slice(0,i),o=Rse[a];if(o===void 0)return{kind:`refused`,reason:`Claude Code was started with ${a}, which cc-candybar does not know how to carry to a restart`};let s=i===-1?o.arity===`one`?n.slice(r,r+1):o.arity===`optional`?n.slice(r,r+1).filter(e=>!P7(e)):o.arity===`variadic`?Use(n.slice(r),e=>!P7(e)):[]:[];if(o.arity===`one`&&i===-1&&s.length===0)return{kind:`refused`,reason:`Claude Code was started with ${a} and no value after it`};r+=s.length,o.keep&&t.push(e,...s)}return{kind:`args`,args:t}}function I7(e){let t=e.split(s.sep),n=t.findLastIndex((e,n)=>e===`worktrees`&&t[n-1]===`.claude`&&n+1<t.length);return n===-1?null:{name:t[n+1].replaceAll(`+`,`/`),top:t.slice(0,n+2).join(s.sep),repo:t.slice(0,n-1).join(s.sep)||s.sep}}function Use(e,t){let n=e.findIndex(e=>!t(e));return n===-1?[...e]:e.slice(0,n)}const L7=`candybar-band@cc-candybar`,Wse=s.join(`bin`,`cc-candybar-native`),Gse=pI(`/reload-plugins`);function Kse(e,t,n){let r=e();if(r.kind===`gone`)throw Error(r.reason);let i=()=>{let t=e();if(t.kind===`gone`)return t;let n=i$(t.session.hints.tmux);return n.kind===`refused`?n:{kind:`in`,session:t.session,tmux:n.hint}},a=async e=>{let r=i();if(r.kind!==`in`)return r;let o=await t(r.tmux,async()=>{let t=i();return t.kind!==`in`||!Ac(t.tmux,r.tmux)?t:{kind:`held`,value:await e(t.session,t.tmux)}});return o.kind===`in`?(n(r.tmux,o.tmux),a(e)):o};return{session:r.session,inPane:a}}function R7(e,t){if(e.kind!==`held`)throw new L(t(e.reason));return e.value}const z7=e=>({kind:`done`,said:e});function B7(e){let t=i$(e.hints.tmux);if(t.kind===`refused`)throw new L(t.reason);return t.hint}const qse={band:{on:async(e,t,n)=>{let r=Rn(t.bundle);if(r===null)throw new L(`${Yc.band.label} runs the band mod from a cc-candybar source checkout, and this daemon runs ${t.bundle} — run the daemon from a checkout (mod/README.md)`);let i=s.join(r,Wse);if(!n.fileExists(i))throw new L(`the band mod starts ${i}, which is not built — run \`just install-rust\` in ${r}`);return{kind:`underway`,said:`installing ${L7} from ${r}`,finished:Jse(e,r,n)}},off:async()=>z7(`nothing to stop: the band mod ends its child once the lane is off`)},statusline:{on:async(e,t,n)=>{let r=B7(e.session),i=Tn(t.preload),a=[t.preload,i].find(e=>!n.fileExists(e));if(a!==void 0)throw new L(`${Yc.statusline.label} restarts Claude Code under the attach launcher, and ${a} is not there — run \`cc-candybar install\` (in a checkout, \`pnpm build\`)`);return{kind:`underway`,said:`restarting Claude Code in ${r.pane} under the attach launcher`,finished:e.inPane((e,r)=>Zse(e,r,{node:t.node[0],launcher:i,preload:t.preload},n)).then(e=>R7(e,e=>`Claude Code was not restarted under the attach launcher: ${e}`))}},off:async()=>z7(`nothing to stop: the attached statusline draws its command's output while the lane is off`)},pane:{on:async(e,t,n)=>R7(await e.inPane(async(e,r)=>{let i=await n.barPanes(r);return i.length>0?z7(`bar pane ${i.join(`, `)} already draws ${r.pane}'s bar`):z7(`opened bar pane ${await n.openBarPane(r,[...t.node,t.bundle,`bar-pane`,r.pane],er(t.home))} under ${r.pane}`)}),e=>`no bar pane was opened: ${e}`),off:async(e,t,n)=>{let r=await e.inPane(async(e,t)=>{let r=await n.barPanes(t);for(let e of r)await n.closePane(t,e);return z7(r.length===0?`no bar pane draws ${t.pane}'s bar`:`closed bar pane ${r.join(`, `)}`)});return r.kind===`refused`?z7(`no bar pane to close: ${r.reason}`):R7(r,e=>e)}},tmuxStatus:{on:async({session:e})=>z7(`the daemon draws ${B7(e).pane}'s bar in its status line`),off:async()=>z7(`nothing to stop: the daemon puts the status line back once the lane is off`)}};async function Jse(e,t,n){let{session:r}=e,i={sessionId:r.sessionId,projectDir:r.origin.projectDir,claudeConfigDir:r.hints.claudeConfigDir};await n.claude([`plugin`,`marketplace`,`add`,t],i),await n.claude([`plugin`,`install`,L7],i);let a=await e.inPane((e,t)=>a$(n.claudeInput,t,Gse)),o=a.kind===`held`?a.value:{kind:`refused`,reason:a.reason};if(o.kind===`refused`)throw Error(`the band mod is installed, but /reload-plugins was not typed: ${o.reason} — or type /reload-plugins yourself`);return`installed ${L7} from ${t} and typed /reload-plugins into ${o.pane}`}const Yse=new Set([Go,DP]);function Xse(e){return new Map(e.flatMap(e=>{let t=e.indexOf(`=`);return t>0?[[e.slice(0,t),e.slice(t+1)]]:[]}))}async function Zse(e,t,n,r){let i=await r.paneClaude(t);if(i.attached)return`left Claude Code in ${t.pane} running: it already runs under the attach launcher`;if(!i.fromShell)throw Error(`Claude Code is the first process of pane ${t.pane}, so nothing would be left in the pane to start it again under the attach launcher — start Claude Code from a shell in the pane`);let a=await r.moduleGraph(n.node,N(n.launcher),i.executable);if(!a.ok)throw Error(`Claude Code in ${t.pane} runs ${i.executable}, which the attach launcher cannot start (${a.reason}) — ${Yc.statusline.label} needs the native Claude Code install (\`claude install\`), so it was left running`);let o=await r.paneClaude(t);if(o.pid!==i.pid||o.startTime!==i.startTime)throw Error(`Claude Code in ${t.pane} is no longer the process the restart read (pid ${i.pid}, started ${i.startTime}; now pid ${o.pid}, started ${o.startTime}), so it was not restarted under the attach launcher`);let s=nce(await r.claudeInput.read(t));if(s!==null)throw Error(`Claude Code in ${t.pane} was left running: ${s} — then turn ${Yc.statusline.label} off and on again`);let c=Qse(e,r.presence(e.transcript));if(c!==null)throw Error(`Claude Code in ${t.pane} was left running: ${c}`);let l=Hse(i.argv);if(l.kind===`refused`)throw Error(`${l.reason} — restart it with that flag removed`);let u=Xse(i.env),d=u.get(`PATH`),f=r.launcherNode(d);if(f.kind===`refused`)throw Error(`Claude Code in ${t.pane} was left running, under the PATH it was started with: ${f.why}`);let p=r.onPath(`claude`,d)===i.executable?`claude`:i.executable,m=[...u].filter(([e])=>Yse.has(e)),h=(e,t)=>On(n.preload,{dir:e.dir,env:m,program:p,args:[...e.args,...l.args,...Bse(t)]}),g=r.heldSession({pid:i.pid,startTime:i.startTime,configDir:Ko(Object.fromEntries(u),i.cwd)});if(g.kind!==`holds`)throw Error(`Claude Code in ${t.pane} was left running: ${g.why}, so which session it runs is unknown`);if(g.sessionId!==e.sessionId)throw Error(`Claude Code in ${t.pane} now runs session ${g.sessionId}, not ${e.sessionId}, so it was not restarted under the attach launcher — turn ${Yc.statusline.label} off and on again from the bar in ${t.pane} to restart that one`);if(r.terminate(i.pid),!await r.exited(i.pid,15e3))throw Error(`Claude Code in ${t.pane} did not exit within ${15e3/1e3} s of SIGTERM, so it was not restarted under the attach launcher`);let _=(e,n)=>Error(`Claude Code in ${t.pane} exited, but ${e}, so it was not started again — start it with \`${n}\``),v=$se(e,r.presence(e.transcript)),y=v.kind===`unchecked`?{kind:`resume`,sessionId:e.sessionId}:v,b;try{b=await r.paneDir(t,i.parent)}catch(e){throw _(`the directory it was started in could not be read (${e.message})`,h(F7(null,i.cwd),y))}let x=h(F7(b,i.cwd),y);if(v.kind===`unchecked`)throw _(`whether session ${e.sessionId} has a conversation could not be seen (${v.error})`,x);try{await r.typeShellLine(t,x)}catch(e){throw _(`the line could not be typed into its pane (${e.message})`,x)}if(!await r.followed(e.sessionId,`statusline`,3e4))throw Error(`Claude Code in ${t.pane} did not come back attached within ${3e4/1e3} s of \`${x}\` — the pane says why`);return`restarted Claude Code in ${t.pane} under the attach launcher with \`${x}\`, ${ece[v.kind](e.sessionId)}, and its statusline follows lane B`}function Qse(e,t){return typeof t==`object`?`whether session ${e.sessionId} has a conversation could not be seen (${t.error})`:t===`present`||e.answered===`no`?null:e.answered===`yes`?`session ${e.sessionId} has a conversation but no transcript to resume it from (is session persistence off?), so a restart would lose it`:`this Claude Code does not say whether session ${e.sessionId} has a conversation, and it has no transcript to resume one from`}function $se(e,t){return typeof t==`object`?{kind:`unchecked`,error:t.error}:{kind:t===`present`?`resume`:`fresh`,sessionId:e.sessionId}}const ece={resume:e=>`resuming ${e}`,fresh:e=>`starting ${e} afresh, since it had no conversation yet`},tce={"in-mode":`its pane is in tmux copy mode — leave it (q)`,stashed:`it holds a stashed prompt (ctrl+s), which ending it would lose — restore or send it`,"no-prompt":`it is not at its prompt (a dialog or picker is open) — close it`};function nce(e){let t=$Q(e);return t.kind===`ready`?n$(e)?`it is in the middle of a turn, which ending it would end — wait until it is idle`:e$(e)?`its prompt holds a draft, which ending it would lose — send or clear it`:null:tce[t.kind]}var rce=class{owed=new Map;closed=!1;constructor(e){this.deps=e}clicked(e,t,n){let r=Xc.filter(e=>t[e]!==n[e]),i=this.take(e);for(let e of r)i.has(e)||i.set(e,t[e]);let a=e=>r.includes(e)?`click`:`owed`;if(this.deps.latest(e)!==null)return V7(e,i,n,a,this.deps.log);for(let[e,t]of i)t===n[e]&&i.delete(e);if(r.length>0){let t=[...i.keys()].map(e=>`${e} ${n[e]?`on`:`off`}`);this.deps.log(`info`,`lane: owed ${t.join(`,`)||`nothing`} (session=${e})`)}i.size>0&&this.owed.set(e,i);for(let[e,t]of this.owed){if(this.owed.size<=1024)break;this.owed.delete(e),this.deps.log(`warn`,`lane: owed dropped sid=${JSON.stringify(e)} lanes=${[...t.keys()].join(`,`)}`)}return[]}noted(e,t){return V7(e,this.take(e),t,()=>`owed`,this.deps.log)}take(e){let t=this.owed.get(e)??new Map;return this.owed.delete(e),t}async setup({sessionId:e,lane:t,on:n,by:r}){if(this.closed)throw new lc(`lane setup`);let i=`by=${r} (session=${e})`,a=e=>{let r=`lane: ${t} ${n?`on`:`off`}: ${e instanceof Error?e.message:String(e)}`;return this.deps.log(`warn`,`${r} ${i}`),cc(r)},o;try{o=await qse[t][n?`on`:`off`](Kse(()=>this.latestOf(e),this.paneOrder,(e,r)=>this.deps.log(`info`,`lane: ${t} ${n?`on`:`off`} — the session moved from ${e.pane} to ${r.pane} while its step waited for the pane, so it takes ${r.pane}'s order ${i}`)),this.deps.host,this.deps.edge)}catch(e){return a(e)}return this.deps.log(`info`,`lane: ${t} ${n?`on`:`off`} — ${o.said} ${i}`),o.kind===`done`?{kind:`ok`,said:o.said}:o.finished.then(e=>(this.deps.log(`info`,`lane: ${t} ${e} ${i}`),{kind:`ok`,said:e}),a)}paneOrder=(e,t)=>this.deps.paneOrder(e,()=>{if(this.closed)throw new lc(`lane setup`);return t()});latestOf(e){let t=this.deps.latest(e);return t===null?{kind:`gone`,reason:`this daemon no longer holds a request of session ${e}`}:{kind:`known`,session:t}}close(){this.closed=!0}};function V7(e,t,n,r,i){let a=[];for(let[o,s]of t)n[o]===s?i(`info`,`lane: ${o} ${s?`on`:`off`} — nothing owed: its switch is back where the lane is by=${r(o)} (session=${e})`):a.push({kind:`lane-setup`,sessionId:e,lane:o,on:n[o],by:r(o)});return a}const ice=[`request`,`feed`],H7=new WeakMap;let ace=0;const U7=e=>{let t=H7.get(e);if(t!==void 0)return t;let n=ace++;return H7.set(e,n),n};var oce=class{records=new Map;constructor(e=512){this.maxRecords=e}of(e,t){return this.records.get(W7(e,t))?.warnings??[]}ofSession(e,t,n){let r=U7(n.config),i=[];for(let n of ice){let a=this.records.get(W7(e,n)),o=n===t?this.of(e,t):a?.generation===r?a.warnings:[],s=i.map(e=>JSON.stringify(e));for(let e of o){let t=s.indexOf(JSON.stringify(e));t===-1?i.push(e):s.splice(t,1)}}return i}drawn(e,t,n,r){let i=this.of(e,t),a=W7(e,t);this.records.delete(a),this.records.set(a,{generation:U7(n.config),warnings:r});for(let e of this.records.keys()){if(this.records.size<=this.maxRecords)break;this.records.delete(e)}return JSON.stringify(i)!==JSON.stringify(r)}};const W7=(e,t)=>`${t}\0${e}`,sce={session:({session:e})=>[`session`,e],pane:({tmux:e})=>[`pane`,kc(e)],lane:({session:e,lane:t})=>[`lane`,e,t]};function cce(e){let t=sce[e.kind];return JSON.stringify(t(e))}var lce=class{gathers=new F8;effects=new F8;open=!0;holder=null;gathersInFlight=0;take(e,t){if(!this.open)throw new lc(e);if(this.holder!==null)throw Error(`journal: ${e} took a turn inside ${this.holder}'s`);this.holder=e;try{return t()}finally{this.holder=null}}inTurn(){return this.holder}async gathering(e){this.gathersInFlight++;try{return await this.gathers.run(`gathers`,()=>{if(!this.open)throw new lc(`doctor`);return e()})}finally{this.gathersInFlight--}}performing(e,t){return this.effects.run(cce(e),t)}getStats(){return{gathers:this.gathersInFlight}}close(){this.open=!1}},uce=class{sessions=new Map;disposed=!1;constructor(e){this.deps=e}clicked(e,t){let n=this.record(e,t);n.since=t,this.settle(e)}since(e,t){let n=this.record(e,t);return n.shown?n.since:void 0}drawn(e,t,n,r){let i=this.since(e,t),a=r(i);return this.observe(e,t,a.frame.rows.some(e=>e.kind===`menu`),n),{...a,idleSince:i}}observe(e,t,n,r){let i=this.record(e,t);t<i.drawnAt||(i.drawnAt=t,n&&!i.shown&&t>i.since&&(i.since=t),i.shown=n,i.timeoutS=r,this.settle(e))}getStats(){let e=0;for(let t of this.sessions.values())t.timer!==null&&e++;return{sessions:this.sessions.size,armed:e}}dispose(){this.disposed=!0;for(let e of this.sessions.values())this.disarm(e);this.sessions.clear()}record(e,t){let n=this.sessions.get(e)??{since:t,timeoutS:0,shown:!1,drawnAt:t,timer:null,closing:!1};this.sessions.delete(e),this.sessions.set(e,n);for(let[e,t]of this.sessions){if(this.sessions.size<=256)break;this.disarm(t),this.sessions.delete(e)}return n}settle(e){let t=this.sessions.get(e),n=t.shown&&!t.closing&&!this.disposed?ute(t.since,t.timeoutS):null;t.timer?.at!==n&&(this.disarm(t),n!==null&&(t.timer={at:n,clear:this.deps.clock.after(Math.max(0,(n-this.deps.now())*1e3),()=>this.fire(e),{unref:!0})}))}disarm(e){e.timer?.clear(),e.timer=null}fire(e){let t=this.sessions.get(e);t.timer=null;let n=this.deps.now(),r={idleS:n-t.since,timeoutS:t.timeoutS,stillIdle:()=>this.sessions.get(e)===t,closed:()=>{t.since=n,t.shown=!1}};t.closing=!0,this.deps.close(e,r).catch(t=>{r.closed(),this.deps.failed(e,t)}).finally(()=>{t.closing=!1,this.sessions.get(e)===t&&this.settle(e)})}};function dce(e){let{bundle:t,memoryLimitBytes:n,registryUrl:r,clock:i,exit:a,home:o,gates:s,host:c}=e,l=mr(o),u=gr(c,o),d=()=>it(new Date(i.now())),f=new AbortController,p=!1,m=(t,n)=>e.daemonLog.log(t,p?`after close: ${n}`:n),h=new r3(i),g=e.launcher({inherited:c.env,stats:h.launchStats,signal:f.signal,now:d,observeWarnings:_ce(m,()=>ue)}),_=e.probe(g),v=e.storage(m,e.filesystem),y=new lce,b=new o0(y,v.session),x=new C0(e.filesystem,b,m,v.history),S=Vi({...e.limits({startedAtMs:h.startedAt.getTime(),exit:a,launcher:g,log:m}),limitBytes:n}),C=new S3,w=new qne,T=e.doctorStores(e.filesystem),E=new xj({filesystem:e.filesystem,clock:i,counters:h,logger:m}),ee=new Hj(m),D=new Hc({watchers:E,logger:m,clock:i}),te=new sM({launcher:g,clock:i,logger:m,ledger:ee,watchers:E,fileEvents:D}),O=Aoe({launcher:g,host:c,pricing:e.pricing({cacheRoot:qn(o),closing:f.signal,log:m}),watchers:E,fileEvents:D,clock:i,logger:m,ledger:ee}),{managedStorage:k}=O,ne=new Xoe,A=new bne,re=bce(()=>ye,{clock:i,now:d,log:m}),ie={to:o.name,signer:e.linkSigner},ae=xce({managedStorage:k,launcher:g,log:m,clock:i}),oe=e.heldSession(c.home),se=hce(()=>ye,y,{edge:e.laneEdge(g,e=>ue.following(e),f.signal,_,oe,e.filesystem),host:{bundle:t.path,node:t.node,home:o,preload:_s(t.path,c)},log:m}),ce=gce(()=>ye,{launcher:g,heldSession:oe,home:o,owner:l.socket,bundle:t,signer:e.linkSigner,log:m}),le=_se({file:l.linkIds,clock:i,retryMs:PZ.still,log:m}),ue=pce(()=>ye,{render:(e,t,n)=>jQ(ye,e,t,n),visibility:mce(()=>ye,{launcher:g,clock:i,log:m}),linkIds:le,clock:i,instant:d,log:m}),de=new oce,fe=bae(),{cache:pe,recorder:me}=fce({clock:i,stateDir:l.state,locations:u,sessionState:b,watchers:E,log:m,links:ie,gates:s,providers:O,updateFact:fe,sourceRuns:te,history:x,navigation:ne,source:tse,budgetBytes:()=>Poe(n),wake:(e,t)=>ue.wake(e,t)});vce({fileEvents:D,watcherRegistry:E,renderCache:pe,frameFeeds:ue});let{binaryWatch:he,updateWatch:ge}=Sce({clock:i,launcher:g,probe:_,filesystem:e.filesystem,bundle:t,stateDir:l.state,registryUrl:r,fetch:e.fetch,gates:s,updateFact:fe,exit:a,log:m}),_e=new _$(y),ve={gates:s,sessionState:b,stateDir:l.state,filesystem:e.filesystem,installedLayers:pe.installedLayers,storedRoot:l.storedRoot,locations:u,journalTurns:y,log:m,launcher:g,now:d,doctor:e.doctorEdge(g,e=>{pe.reload(e,{kind:`doctor`});let t=pe.getOrCreate(e);return{layers:t.configLayers,error:t.lastError,warning:t.lastWarning,unused:t.state.unused,config:t.state.config,repos:t.repos}},c,e.filesystem),doctorStores:T,probes:C,clients:w,mismatchRuns:_e,bundle:t.path,claudeInput:e.claudeInput(g),history:x,navigation:ne,links:ie,runs:ae,...Cce(()=>ye)},ye={home:c.home,storedRoot:l.storedRoot,tmp:c.tmp,heldSession:oe,launcher:g,log:m,clock:i,bundle:t.path,sourceDigest:t.digest,doctorStores:T,stats:h,handlerProbes:C,renderSightings:w,mismatchRuns:_e,watcherRegistry:E,refreshLedger:ee,fileEvents:D,payloadProviders:O,sessionState:b,rendererName:o.name,draw:yce(()=>ye),effectSessions:A,menuIdle:re,journalTurns:y,links:ie,runs:ae,sourceRuns:te,laneSetups:se,tmuxStatusLines:ce,frameFeeds:ue,linkIds:le,renderWarnings:de,renderCache:pe,recorder:me,updateWatch:ge,limits:S,verbCtx:ve};return{stats:h,launcher:g,log:m,memoryLimitBytes:n,clock:i,exit:a,handle:async(e,t,n,r)=>(f.signal.throwIfAborted(),Vie(ye,e,t,n,r)),reply:async(e,t,n,r)=>(f.signal.throwIfAborted(),x8(ye,e,t,n,r)),subscribe:(e,t)=>(f.signal.throwIfAborted(),ue.subscribe(e,t)),reloadConfig:e=>{f.signal.throwIfAborted(),ve.reloadConfig(e)},arm(){f.signal.throwIfAborted(),D.start(l.watchProbe),he.arm(),ge.arm(),S.arm()},close(e){return Tce({...ye,journalTurns:y,sessionState:b,closing:f,binaryWatch:he},e),p=!0,g.settled()}}}function fce(e){let{budgetBytes:t,wake:n,providers:r,updateFact:i,sourceRuns:a,history:o,navigation:s,source:c,...l}=e,{log:u,sessionState:d,gates:f}=l;return xQ(e=>new Joe({...l,storage:r.managedStorage,facts:$oe({providers:r,update:()=>i.get(),runs:a}),source:c({providers:r,sessionState:d,stateGates:f.state,history:e=>o.depth(e),navigation:(e,t)=>s.depth(e,d,f.state.gateFor(t))})},{budgetBytes:t,observers:{onReload:(e,t,r,i)=>{u(`info`,Roe(e,r,i));for(let e of t)n(e,`reload`)},onViewChanged:e=>n(e,`data`),...e}}),u)}function pce(e,t){let{visibility:n,linkIds:r,...i}=t;return new BZ({...i,shown:e=>n.shown(e.hints.tmux),watching:()=>n.follow(),refreshes:()=>e().refreshLedger.totals(),encoders:mse(r),watch:(t,n)=>(0,X.reaction)(()=>e().sessionState.revision(t),n),lanes:t=>NQ(e(),t),pin:t=>{let{renderCache:n}=e(),r=n.pin(t);return()=>{n.stopDrawing(t,`feed`),r()}},periods:PZ})}function mce(e,{launcher:t,clock:n,log:r}){return new bse({clock:n,listPanes:e=>oc(t,{socket:e},`frames.visibility`,[`list-panes`,`-a`,`-F`,Y5]),listClients:e=>oc(t,{socket:e},`frames.visibility`,[`list-clients`,`-F`,X5]),sockets:()=>new Set(e().frameFeeds.watched().flatMap(({req:e})=>G7(e))),onAnswer:(t,n)=>e().tmuxStatusLines.answered(t,n),onChange:t=>e().frameFeeds.wakeWhere(`visibility`,e=>G7(e).some(e=>t.has(e))),intervalMs:1e3,log:r})}function G7({hints:{tmux:e}}){return e==null?[]:[e.socket]}function hce(e,t,n){return new rce({...n,latest:t=>{let n=e().frameFeeds.latest(t);return n===null?null:GQ(n)},paneOrder:(e,n)=>t.performing({kind:`pane`,tmux:e},n)})}function gce(e,{launcher:t,heldSession:n,home:r,owner:i,bundle:a,signer:o,log:s}){return new Ise({edge:{run:(e,n)=>oc(t,{socket:e},`tmux-status`,n)},subscribe:(t,n)=>e().frameFeeds.subscribe(t,n),sessionInPane:t=>e().frameFeeds.newestWhere(sl(t,n)),handler:[...Object.entries(er(r)).map(([e,t])=>`${e}=${Sn(t)}`),...[...a.node,a.path].map(Sn),`url-handle`].join(` `),owner:i,name:r.name,signer:o,log:s})}function _ce(e,t){return n=>{n.kind===`launch-pipes`?e(`warn`,n.text):e(n.fault===null?`info`:`warn`,n.fault===null?`launch lifeline running again`:`launch lifeline ${n.fault}; the next launch starts another`),t().wakeWhere(`data`,()=>!0)}}function vce({fileEvents:e,watcherRegistry:t,renderCache:n,frameFeeds:r}){e.subscribe(e=>{switch(e.kind){case`period`:t.judge();return;case`caught-up`:n.reloadEvery({kind:`events-resumed`,since:e.since}),r.wakeWhere(`data`,()=>!0);return;case`moved`:r.wakeWhere(`data`,()=>!0);return}})}function yce(e){return(t,n,r,i)=>qQ(e(),t,n,r,i)}function bce(e,{clock:t,now:n,log:r}){return new uce({clock:t,now:n,close:async(t,n)=>{await u8({kind:`menu-idle`,session:t,idle:n},e())},failed:(e,t)=>p8(r,`menu-idle`,`session=${e}`,t)})}function xce({managedStorage:e,launcher:t,log:n,clock:r}){return new hc({supersede:(t,n)=>e.supersede(t,n),launch:t.launch,log:n,clock:r})}function Sce({clock:e,launcher:t,probe:n,filesystem:r,bundle:i,stateDir:a,registryUrl:o,fetch:s,gates:c,updateFact:l,exit:u,log:d}){let f=Sae({clock:e,targets:i.targets,intervalMs:K7,filesystem:r,held:()=>p.running(),exit:()=>u(0),log:d}),p=yae({fact:l,clock:e,launcher:t,probe:n,entryUrl:i.entryUrl,digest:i.digest,actsDir:tae(a,i.path),intervalMs:K7,releaseIntervalMs:wce,registryUrl:o,fetchImpl:s,gates:c,onApplied:()=>f.checkNow(),log:d});return{binaryWatch:f,updateWatch:p}}function Cce(e){return{clickLanded:t=>e().menuIdle.clicked(t,e().verbCtx.now()),applyUpdate:()=>e().updateWatch.act(),serving:()=>e().limits.serving(),configFor:t=>e().renderCache.getOrCreate(t).state.config,reloadConfig:t=>e().renderCache.reload(t,{kind:`write`}),sourcesFor:t=>e().renderCache.getOrCreate(t).state.sources,lanes:{of:(t,n)=>PQ(e(),t,n),clicked:(t,n,r)=>KQ(e(),t,n,r),arrived:t=>UQ(e(),t),setup:t=>e().laneSetups.setup(t)},diagnosticCopy:(t,n,r)=>e().renderCache.drawnCopy(t,n,r)}}const K7=60*1e3,wce=360*60*1e3;function Tce(e,t){let{journalTurns:n,tmuxStatusLines:r,closing:i,laneSetups:a,frameFeeds:o,linkIds:s,menuIdle:c,updateWatch:l,binaryWatch:u,limits:d,recorder:f,renderCache:p,payloadProviders:{gitProvider:m,usageStore:h,tmuxService:g,hostService:_,managedStorage:v},runs:y,sourceRuns:b,fileEvents:x,watcherRegistry:S,sessionState:C,log:w}=e,T=[[`journalTurns close`,()=>n.close()],[`tmuxStatusLines restore`,()=>r.restoreAll(t)],[`launches abort`,()=>i.abort(Error(`the daemon closed`))],[`laneSetups close`,()=>a.close()],[`frameFeeds close`,()=>o.close()],[`linkIds close`,()=>s.close()],[`menuIdle dispose`,()=>c.dispose()],[`updateWatch close`,()=>l.close()],[`binaryWatch close`,()=>u.close()],[`limits disarm`,()=>d.disarm()],[`recorder close`,()=>f.close()],[`renderCache close`,()=>p.close()],[`gitService close`,()=>m.close()],[`usageStore close`,()=>h.close()],[`tmuxService close`,()=>g.close()],[`hostService close`,()=>_.close()],[`runs close`,()=>y.close()],[`sourceRuns close`,()=>b.close()],[`managedStorage close`,()=>v.close()],[`fileEvents close`,()=>x.close()],[`watcherRegistry close`,()=>S.closeAll()],[`sessionState close`,()=>C.close()]];for(let[e,t]of T)try{t()}catch(t){w(`warn`,`${e} failed: ${t.message}`)}}function Ece(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;for(let t of Object.values(e)){if(typeof t!=`object`||!t||Array.isArray(t))return!1;for(let e of Object.values(t))if(typeof e!=`string`)return!1}return!0}var Dce=class{clearTimer=null;pending=null;writing=!1;generation=0;writingPath;constructor(e,t,n=500,r=Ie){this.filePath=e,this.clock=t,this.debounceMs=n,this.logger=r,this.writingPath=ct(e)}load(){let e;try{e=m.readFileSync(this.filePath,`utf8`)}catch(e){let t=e.code;return t!==`ENOENT`&&this.logger(`warn`,`session-state read failed (${t}); starting empty`),{}}try{let t=JSON.parse(e);return Ece(t)?t:(this.logger(`warn`,`session-state load: unexpected shape, starting empty`),{})}catch{return this.logger(`warn`,`session-state load: corrupt JSON, starting empty`),{}}}save(e){this.pending=e,this.schedule()}schedule(){this.clearTimer!==null||this.writing||(this.clearTimer=this.clock.after(this.debounceMs,()=>{this.clearTimer=null,this.write()},{unref:!0}))}async write(){let e=this.pending;if(e===null)return;let t=this.generation,n=this.clock.monotonic(),r=JSON.stringify(e),i=this.writingPath;this.writing=!0;let a=Qe(this.clock,n);try{await m.promises.mkdir(s.dirname(this.filePath),{recursive:!0});let o=await m.promises.open(i,`w`,384);try{await o.writeFile(r),await o.chmod(384),await o.datasync()}finally{await o.close()}let c=!1;if(t===this.generation)try{await m.promises.rename(i,this.filePath),c=!0}catch(e){if(e.code!==`ENOENT`||t===this.generation)throw e}if(t!==this.generation){c||await m.promises.rm(i,{force:!0}),this.logger(`info`,`session-state write superseded by a flush landed=${c} took=${Qe(this.clock,n)}ms held=${a}ms`);return}this.saved(r,e,n,a),this.pending===e&&(this.pending=null)}catch(e){this.logger(`warn`,`session-state save failed: ${e.message}`)}finally{this.writing=!1,this.pending!==null&&this.pending!==e&&this.schedule()}}flush(){if(this.clearTimer?.(),this.clearTimer=null,this.pending===null)return;let e=this.pending,t=this.clock.monotonic(),n=ct(this.filePath);try{m.mkdirSync(s.dirname(this.filePath),{recursive:!0});let r=JSON.stringify(e);m.writeFileSync(n,r,{mode:384}),m.chmodSync(n,384),m.rmSync(this.writingPath,{force:!0}),m.renameSync(n,this.filePath),this.generation++,this.saved(r,e,t,Qe(this.clock,t)),this.pending=null}catch(e){this.logger(`warn`,`session-state save failed: ${e.message}`);try{m.rmSync(n,{force:!0})}catch(e){this.logger(`warn`,`session-state staged file left: ${e.message}`)}}}saved(e,t,n,r){this.logger(`info`,`session-state saved bytes=${Buffer.byteLength(e)} sessions=${Object.keys(t).length} took=${Qe(this.clock,n)}ms held=${r}ms`)}};function Oce(e,t,n,r){return{session:new Dce(e.sessionState,n,500,t),history:G0(r,e.settingsHistory,e.storedRoot,t)}}function q7(e,t,n){for(let r of(t??``).split(s.delimiter)){if(!s.isAbsolute(r))continue;let t=s.join(r,e);if(n(t))return t}return null}function J7(e,t){try{return m.accessSync(e,t),m.statSync(e).isFile()}catch{return!1}}function kce(e){try{return m.realpathSync(e)}catch{return s.resolve(e)}}function Ace(e,t,n){let r=q7(`node`,e,t);return r===null?{kind:`refused`,why:"no `node` on PATH to run the attach launcher"}:s.basename(n(r))===`bun`?{kind:`refused`,why:`the \`node\` on PATH (${r}) is Bun; the attach launcher runs under Node`}:{kind:`node`,file:r}}const Y7=2e3;async function X7(e,t,n,r){let i=await oc(e,t,`lane.tmux`,n,r);if(i.kind!==`ok`)throw Error(i.reason);return i.stdout}function Z7(e,t){if(t.ok)return t.stdout;let n=ht(t,t.stdout);throw Error(`${e} failed (${gt(t)}${n===``?``:`: ${n}`})`)}function jce(e){try{let t=JSON.parse(e);if(typeof t==`object`&&t&&`ok`in t&&t.ok===!1&&`reason`in t&&typeof t.reason==`string`)return`detail`in t&&typeof t.detail==`string`?`${t.reason}: ${t.detail}`:t.reason}catch{}return null}const Mce=/(?:^|\s)bar-pane\s+["'\\]*(%\d+)["']*\s*$/;function Nce(e,t){return e.split(`
|
|
510
510
|
`).flatMap(e=>{let[n,...r]=e.trim().split(` `);return Mce.exec(r.join(` `))?.[1]===t?[n]:[]})}const Q7=/(^|\/)(cc-attach|bun-attach\.js)(\s|$)/;function Pce(e,t,n){for(let r of s2(o2(e),t)){if(r.command.split(` `).some(e=>Q7.test(e)))return!0;if(r.pid===n)return!1}return!1}const Fce=[`import ctypes, json, struct, sys`,`libc = ctypes.CDLL(None)`,`mib = (ctypes.c_int * 3)(1, 49, int(sys.argv[1]))`,`size = ctypes.c_size_t(0)`,`if libc.sysctl(mib, 3, None, ctypes.byref(size), None, 0) != 0: sys.exit('sysctl KERN_PROCARGS2 refused')`,`buf = ctypes.create_string_buffer(size.value)`,`if libc.sysctl(mib, 3, buf, ctypes.byref(size), None, 0) != 0: sys.exit('sysctl KERN_PROCARGS2 refused')`,`raw = buf.raw[:size.value]`,`argc = struct.unpack_from('i', raw)[0]`,`rest = raw[4:]`,`end = rest.index(b'\\0')`,`exe = rest[:end].decode('utf-8', 'surrogateescape')`,`rest = rest[end:].lstrip(b'\\0')`,`words = [w.decode('utf-8', 'surrogateescape') for w in rest.split(b'\\0')]`,`end = words.index('', argc) if '' in words[argc:] else len(words)`,`print(json.dumps({'executable': exe, 'argv': words[:argc], 'env': words[argc:end]}))`].join(`
|
|
511
|
-
`);async function Ice(e,t){if(process.platform===`linux`)return{executable:await m.promises.readlink(`/proc/${t}/exe`),argv:(await m.promises.readFile(`/proc/${t}/cmdline`,`utf8`)).split(`\0`).slice(0,-1),env:(await m.promises.readFile(`/proc/${t}/environ`,`utf8`)).split(`\0`).slice(0,-1)};let n=Z7(`reading process ${t}'s arguments`,await e.launch({bin:`python3`,args:[`-c`,Fce,String(t)],timeoutMs:5e3,category:`lane.process`}));return JSON.parse(n)}async function $7(e,t,n){return Z7(t,await e.launch({bin:`ps`,args:n,timeoutMs:2e3,category:`lane.process`}))}async function e9(e,t){let n=await oc(e,t,`lane.tmux`,[`display`,`-p`,`-t`,t.pane,`#{pane_pid} #{pane_current_path}`]);if(n.kind!==`ok`)throw Error(n.reason);let[r=``,i=``]=n.stdout.trimEnd().split(` `),a=(await $7(e,`asking pane ${t.pane}'s foreground job`,[`-o`,`tpgid=`,`-p`,r])).trim();return{panePid:Number(r),cwd:i,foreground:Number(a)}}async function Lce(e,t){let{panePid:n,cwd:r,foreground:i}=await e9(e,t),a=await $7(e,`listing processes`,[`-A`,`-o`,`pid=,ppid=,args=`]),o=await Ice(e,i),s=o2(a).get(i)?.ppid;if(s===void 0)throw Error(`pane ${t.pane}'s foreground job ${i} is gone`);let c=nn(i,await en(i,t=>e.launch(t)));if(c.startTime===null)throw Error(`the start of pane ${t.pane}'s foreground job ${i} could not be read (${c.why})`);return{pid:i,startTime:c.startTime,executable:await m.promises.realpath(o.executable),argv:o.argv,env:o.env,cwd:r,parent:s,fromShell:i!==n,attached:Pce(a,i,n)}}function Rce(e,t){let n=t9(e,t);return n.torn?t9(e,t).held:n.held}function t9(e,t){let n;try{n=m.readFileSync(e,`utf8`)}catch(t){return{torn:!1,held:t.code===`ENOENT`?{kind:`none`,why:`it keeps no session record at ${e} (update Claude Code with \`claude update\`: recent releases keep one)`}:{kind:`unread`,why:t.message}}}let r;try{r=JSON.parse(n)}catch(t){return{torn:!0,held:{kind:`unread`,why:`its session record ${e} is not JSON (${t.message})`}}}let{sessionId:i,procStart:a}=typeof r==`object`&&r?r:{},o=Qt(a);return{torn:!1,held:typeof i!=`string`||i===``?{kind:`unread`,why:`its session record ${e} names no session`}:a===void 0?{kind:`unread`,why:`its session record ${e} names no process start (update Claude Code with \`claude update\`: recent releases name one)`}:o===void 0?{kind:`unread`,why:`its session record ${e} names its process start as ${JSON.stringify(a)}, not in the form \`ps -o lstart=\` prints it`}:o===t.startTime?{kind:`holds`,sessionId:i}:{kind:`none`,why:`its session record ${e} was left by a Claude Code that has exited: the record names a process started ${o}, and pid ${t.pid} is a process started ${t.startTime}`}}}const zce=e=>t=>Rce(s.join(qo(t.configDir,e),`sessions`,`${t.pid}.json`),t);function Bce(e,t,n,r,i,a,o){let s=e=>et(r,e,n);return{claudeInput:u$(e),barPanes:async t=>Nce(await X7(e,t,[`list-panes`,`-a`,`-F`,`#{pane_id} #{pane_start_command}`]),t.pane),openBarPane:async(t,n,r)=>(await X7(e,t,[`split-window`,`-d`,`-v`,`-l`,`1`,`-t`,t.pane,`-P`,`-F`,`#{pane_id}`,...Object.entries(r).flatMap(([e,t])=>[`-e`,`${e}=${t}`]),...n])).trim(),closePane:async(t,n)=>void await X7(e,t,[`kill-pane`,`-t`,n]),claude:async(t,n)=>void Z7(`claude ${t.join(` `)}`,await e.launch({bin:`claude`,args:[...t],envOverlay:q0(n),timeoutMs:3e4,category:`lane.claude`})),fileExists:e=>gc(o,e)===`present`,presence:e=>gc(o,e),paneClaude:t=>Lce(e,t),heldSession:a,paneDir:async(t,n)=>{let i=r.monotonic()+Y7;for(;;){let a=await e9(e,t);if(a.foreground===n){if(a.cwd===``)throw Error(`tmux read no directory for pane ${t.pane}`);return a.cwd}if(r.monotonic()>i)throw Error(`the shell in pane ${t.pane} (pid ${n}) did not take its terminal back within ${Y7/1e3} s`);await s(100)}},launcherNode:e=>Ace(e,e=>J7(e,m.constants.X_OK),kce),onPath:(e,t)=>{let n=q7(e,t,e=>J7(e,m.constants.X_OK));return n===null?null:m.realpathSync(n)},followed:async(e,n,i)=>{let a=r.monotonic()+i;for(;!t(e).has(n);){if(r.monotonic()>a)return!1;await s(200)}return!0},moduleGraph:async(t,n,r)=>{let i=await e.launch({bin:t,args:[n,r],timeoutMs:2e4,category:`lane.process`}),a=!i.ok&&i.reason===`non-zero`?jce(i.stdout):null;return a===null?(Z7(`reading ${r}'s module graph`,i),{ok:!0}):{ok:!1,reason:a}},terminate:e=>{n.throwIfAborted();try{process.kill(e,`SIGTERM`)}catch(t){throw Error(`Claude Code (pid ${e}) could not be sent SIGTERM: ${t instanceof Error?t.message:String(t)}`)}},exited:async(e,t)=>{let n=r.monotonic()+t;for(;i.alive(e);){if(r.monotonic()>n)return!1;await s(100)}return!0},typeShellLine:async(t,n)=>void await X7(e,t,c$(t.pane,`cc-candybar-lane`,[]),n)}}const Vce=/^[0-9a-f]{64}$/;function n9(e,t){return oe(`sha256`,e).update(JSON.stringify(t)).digest()}const r9=e=>[e.sessionId,e.action,e.declaration,e.evaluated],i9=e=>[aC,e];function Hce(e){if(e.length!==32)throw Error(`a link key is 32 bytes, got ${e.length}`);let t=t=>n9(e,t).toString(`hex`),n=(t,n)=>Vce.test(n)&&le(Buffer.from(n,`hex`),n9(e,t));return{sign:e=>t(r9(e)),verify:(e,t)=>n(r9(e),t),signBinding:e=>t(i9(e)),verifyBinding:(e,t)=>n(i9(e),t)}}function a9(e){return s.join(e,`link.key`)}function o9(e){let t,n=()=>t??=Uce(e);return{sign:e=>n().sign(e),verify:(e,t)=>n().verify(e,t),signBinding:e=>n().signBinding(e),verifyBinding:(e,t)=>n().verifyBinding(e,t)}}function Uce(e){let t;try{t=m.readFileSync(e)}catch(n){if(n.code!==`ENOENT`)throw n;Wce(e),t=m.readFileSync(e)}if(t.length!==32)throw Error(`link key ${e} holds ${t.length} bytes, not 32: remove it and a new one is made (links drawn before then stop working)`);return Hce(t)}function Wce(e){m.mkdirSync(s.dirname(e),{recursive:!0});let t=ct(e);m.writeFileSync(t,se(32),{mode:384,flag:`wx`});try{m.linkSync(t,e)}catch(e){if(e.code!==`EEXIST`)throw e}finally{m.unlinkSync(t)}}function Gce(e,t,n){return{daemonLog:t,launcher:e=>gn(e,n),storage:(t,r)=>Oce(e,t,n,r),doctorStores:w4(pn,e.state),doctorEdge:(e,t,n)=>I4(e,t,n,pn),claudeInput:u$,probe:an,laneEdge:(e,t,r,i,a)=>Bce(e,t,r,n,i,a,pn),heldSession:zce,linkSigner:o9(a9(e.state)),limits:({startedAtMs:r,exit:i,launcher:a,log:o})=>qi(r,i,{launcher:a,log:o,clock:n,snapshotDir:e.state,writeLogNow:()=>t.writeNow()}),fetch,pricing:e=>Iae({...e,clock:n}),filesystem:pn}}function s9(e){let t=null;return e.on(`drain`,()=>{let n=t;t=null,n!==null&&e.write(n)}),n=>{if(e.writable){if(e.writableNeedDrain){t=n;return}e.write(n)}}}const Kce={kind:`awaiting`},c9=e=>e.kind===`awaiting`||e.kind===`answering`||e.kind===`unattended`&&!e.lapsed,l9=e=>e.kind!==`streaming`&&e.kind!==`closed`,u9=e=>e.kind===`answered`&&e.by===`backstop`||(e.kind===`unattended`||e.kind===`closed`)&&e.lapsed,qce=e=>e.kind===`closed`,d9=e=>({next:e,effects:[]}),f9=(e,t)=>({next:{kind:`answered`,by:e},effects:[{kind:`answer`,answer:t}]}),Jce=(e,t)=>{switch(t.kind){case`read`:return e.kind===`awaiting`?d9(t.waits?{kind:`answering`}:{kind:`unattended`,lapsed:!1}):e.kind===`answered`&&e.by===`backstop`&&!t.waits?d9({kind:`unattended`,lapsed:!0}):d9(e);case`unreadable`:return e.kind===`awaiting`?f9(`reply`,t.answer):d9(e);case`deadline`:if(e.kind===`awaiting`||e.kind===`answering`){let e=f9(`backstop`,t.answer);return{...e,effects:[{kind:`count-timeout`},...e.effects]}}return e.kind===`unattended`&&!e.lapsed?{next:{kind:`unattended`,lapsed:!0},effects:[{kind:`count-timeout`}]}:d9(e);case`reply`:return e.kind===`answering`||e.kind===`held`?f9(`reply`,t):e.kind===`answered`&&e.by===`backstop`||e.kind===`closed`&&e.lapsed?{next:e,effects:t.exitAfterFlush===null?[]:[{kind:`exit-dropped`}]}:e.kind===`closed`?{next:e,effects:t.exitAfterFlush===null?[]:[{kind:`exit`,code:t.exitAfterFlush}]}:d9(e);case`subscribe`:return e.kind===`answering`?{next:e,effects:[{kind:`attach`,sessionId:t.sessionId,lane:t.lane}]}:d9(e);case`subscribed`:return e.kind===`answering`?d9({kind:`streaming`,unsubscribe:t.unsubscribe}):{next:e,effects:[{kind:`unsubscribe`,unsubscribe:t.unsubscribe}]};case`held`:return e.kind===`answering`?{next:{kind:`held`},effects:[{kind:`start`,start:t.start}]}:d9(e);case`threw`:return e.kind===`answering`||e.kind===`held`?f9(`reply`,t.answer):d9(e);case`settled`:return e.kind===`unattended`?d9({kind:`closed`,lapsed:e.lapsed}):d9(e);case`close`:return e.kind===`unattended`||e.kind===`closed`?d9(e):e.kind===`streaming`?{next:{kind:`closed`,lapsed:!1},effects:[{kind:`unsubscribe`,unsubscribe:e.unsubscribe}]}:e.kind===`held`?{next:{kind:`closed`,lapsed:!1},effects:[{kind:`abort`}]}:d9({kind:`closed`,lapsed:u9(e)})}};function Yce(e,t){let{next:n,effects:r}=Jce(e,t);return{next:n,effects:[...[...c9(e)&&!c9(n)?[{kind:`clear-backstop`}]:[],...l9(e)&&!l9(n)?[{kind:`leave-in-flight`}]:[]],...r]}}function Xce(e,t){t.allowHalfOpen=!1;let n=e.clock.monotonic();e.stats.inFlight++;let r=Kce,i=e=>{let{next:t,effects:n}=Yce(r,e);r=t,n.forEach(o)},a=new AbortController,o=t=>{switch(t.kind){case`answer`:return s(t.answer);case`exit`:return e.exit(t.code);case`exit-dropped`:return e.log(`warn`,`exit-after-flush dropped: the client was already told TIMEOUT`);case`count-timeout`:e.stats.requestsTimedOut++;return;case`clear-backstop`:return l();case`leave-in-flight`:e.stats.inFlight--;return;case`attach`:return i({kind:`subscribed`,unsubscribe:u(t.sessionId,t.lane)});case`start`:return d(t.start);case`abort`:return a.abort();case`unsubscribe`:return t.unsubscribe()}},s=({resp:n,exitAfterFlush:r,delivered:i})=>{let a=r===null?void 0:()=>e.exit(r),[o,s]=c(n,i);try{t.end(o,e=>{e??s(),a?.()})}catch(t){e.log(`warn`,`response write failed: ${t.message}`),a?.()}},c=(t,n)=>{try{return[Xr(t),n]}catch(t){return e.log(`error`,`response encode failed: ${O(t)}`),[Xr(kQ(t)),OQ]}},l=e.clock.after(200,()=>i({kind:`deadline`,answer:v8({ok:!1,error:`request exceeded 200ms`,code:`TIMEOUT`,daemonV:3})})),u=(n,r)=>{let i=s9(t);return e.subscribe(n,{lane:r,frame:e=>i(Zr(e.json)),refused:e=>t.end(Xr(e)),drawing:()=>!0})},d=t=>{t(a.signal).then(e=>i(y8(e)),t=>{e.log(`error`,`held request threw: ${O(t)}`),i({kind:`threw`,answer:v8(kQ(t))})})};$r(t,t=>{new Promise(a=>{let o=Gr(t);i({kind:`read`,waits:o.kind===`request`}),a(e.handle(o,()=>u9(r),n,()=>qce(r)))}).then(i).catch(t=>{e.log(`error`,`handler threw: ${O(t)}`),i({kind:`threw`,answer:v8(kQ(t))})}).finally(()=>i({kind:`settled`}))},t=>{e.log(`warn`,`frame parse failed: ${t.message}`),i({kind:`unreadable`,answer:v8({ok:!1,error:t.message,code:`BAD_REQUEST`,daemonV:3})})}),t.on(`error`,t=>{e.log(`warn`,`socket error: ${t.message}`),i({kind:`close`})}),t.on(`close`,()=>i({kind:`close`}))}const p9=`CC_CANDYBAR_PARENT_PID`;function Zce(e){let t=e[p9];if(t===void 0)return{kind:`outlives-nobody`};let n=Number.parseInt(t,10);if(!Number.isInteger(n)||n<=0)throw Error(`${p9} must be a positive integer pid, got ${JSON.stringify(t)}`);return{kind:`anchored`,pid:n}}function Qce(e){if(e.anchor.kind===`outlives-nobody`)return{disarm:()=>{}};let{pid:t}=e.anchor;return{disarm:e.clock.every(e.intervalMs??250,()=>{e.probe.alive(t)||e.onOrphaned(`spawner pid ${t} gone`)},{unref:!0})}}let m9=null,h9=null,g9=null,_9=null;function v9(){if(_9===null)throw Error(`runDaemon has not started`);return _9}function y9(e,t){v9().log.log(e,t)}function $ce(){let e=i(import.meta.url);return{entryUrl:import.meta.url,digest:Bn(),path:e,node:[t.execPath,...t.execArgv],targets:[...new Set([e,...t.argv[1]?[t.argv[1]]:[]])]}}function ele(e){let n=mr(e.home);_9={world:e,paths:n,log:new nc(n.log,e.clock)},t.on(`uncaughtException`,e=>{y9(`error`,`uncaughtException: ${e.stack||e.message}`),C9(1)}),t.on(`unhandledRejection`,e=>{y9(`error`,`unhandledRejection: ${String(e)}`),C9(1)});for(let e of[`SIGINT`,`SIGTERM`,`SIGHUP`])t.on(e,()=>{y9(`info`,`received ${e}, shutting down`),C9(0)});tle().catch(b9)}function b9(e){y9(`error`,`refusing to boot: ${O(e)}`),C9(1)}async function tle(){let{world:e,paths:n,log:r}=v9(),{host:i,home:a}=e,o=Ni(i.env);a.kind===`main`&&a.legacySocket!==null&&y9(`warn`,`CC_CANDYBAR_SOCKET=${a.legacySocket} is honoured for one more release; a renderer is named by CC_CANDYBAR_HOME and CC_CANDYBAR_NAME instead`),m9=await sn(t.pid,an(e.launcher).startTime);let s=await Ks(Js(e,m9,sr(i),n.socket!==$n(Le)));if(!s.decision.allow){y9(`warn`,`fork-bomb breaker: ${s.decision.reason}; refusing to boot`),C9(1);return}h9=s.registryPath,m.mkdirSync(n.state,{recursive:!0}),nr(n.socket);let c=dce({...Gce(n,r,e.clock),bundle:$ce(),host:i,home:a,memoryLimitBytes:o,registryUrl:i.env.CC_CANDYBAR_REGISTRY_URL??`https://registry.npmjs.org`,clock:e.clock,gates:wz(),exit:C9});g9=c,Qce({clock:e.clock,anchor:Zce(i.env),probe:an(e.launcher),onOrphaned:e=>{y9(`info`,`parent watchdog: ${e}; shutting down`),C9(0)}}),x9(c,ue.createServer(e=>Xce(c,e)),n.socket,!1)}function x9(e,n,r,i){n.removeAllListeners(`error`),n.removeAllListeners(`listening`),n.once(`error`,a=>{if(a.code!==`EADDRINUSE`){y9(`error`,`server error: ${a.message}`),C9(1);return}if(i){y9(`info`,`lost rebind race; another daemon is alive — exiting`),t.exit(0);return}nle(e,n,r).catch(b9)}),n.listen(r,()=>rle(e,r))}async function nle(e,n,r){let i=await Ps(Fs(rr(r)),(t,n)=>on(t,n,an(e.launcher)));if(i.kind===`attach-and-exit`){y9(`info`,`EADDRINUSE: ${i.reason} — exiting`),t.exit(0);return}y9(`warn`,`EADDRINUSE: ${i.reason} — unlinking stale socket and rebinding`);try{m.unlinkSync(r)}catch(e){if(e.code!==`ENOENT`){y9(`error`,`cannot unlink stale socket ${r}: ${e.message}`),C9(1);return}}x9(e,n,r,!0)}function rle(e,n){let r=Rs(n);if(r.kind!==`present`){y9(`warn`,`no ownable socket at bind callback (${r.kind}); exiting`),C9(0);return}ale(n);try{m.chmodSync(n,384)}catch(e){y9(`warn`,`chmod socket failed: ${e.message}`)}y9(`info`,`daemon up: pid=${t.pid} v=3 sock=${n} heapCap=${Mi(pe.getHeapStatistics().heap_size_limit)}MB memoryLimit=${Mi(e.memoryLimitBytes)}MB`),ea(v9().paths.spawnBackoff),e.arm(),ile(n,r.identity)}function ile(e,n){Vs({bound:n,myPid:t.pid,readIdentity:()=>Rs(e),readLease:()=>Fs(rr(e)),shutdown:e=>C9(e),log:y9,clock:v9().world.clock}).arm()}function ale(e){let n=Is(rr(e),{pid:t.pid,version:3,binPath:t.argv[1],startTime:m9});n!==null&&y9(`warn`,`lease write failed: ${n}`)}const ole=e=>(t,n)=>ac(e,{socket:t},`tmux-status`,n);let S9=!1;function C9(e){S9||(S9=!0,v9().world.clock.after(500,()=>t.kill(t.pid,`SIGKILL`)),g9?.close(ole(v9().world.launcher)),Ls(v9().paths.lease,t.pid),h9!==null&&qs(h9,t.pid,Ws,e=>m.unlinkSync(e)),t.exit(e))}function sle(e,t){let n=[],r=10;for(let t=0;t<e.length;t++){let i=e[t];if(i===`--seconds`){let n=e[++t];if(n===void 0)return{ok:!1,problem:`--seconds needs a number after it`};let i=qr(Number(n));if(!i.ok)return{ok:!1,problem:`--seconds ${JSON.stringify(n)} ${i.problem}`};r=i.seconds}else if(i!==void 0&&!i.startsWith(`-`))n.push(i);else return{ok:!1,problem:`unexpected argument ${JSON.stringify(i)}`}}let[i,a,...o]=n;return i===void 0||a===void 0||o.length>0?{ok:!1,problem:`usage: cc-candybar record <session-id> <path> [--seconds N]`}:{ok:!0,args:{session:i,path:f(t,a),seconds:r}}}function cle(e,t){if(e.kind!==`ok`)return{stdout:``,stderr:`record: ${li(e)}\n`,code:1};let{path:n,lines:r,answers:i,frames:a,daemonClosed:o}=e.value,s=`the daemon closed before ${t}s ran out`;return i+a===0?{stdout:``,stderr:o?`record: ${n}: ${s}, and nothing had been drawn, so there is nothing to replay. No file was left.\n`:`record: ${n}: no request was answered and no lane drew a frame in ${t}s, so there is nothing to replay: the session was idle, or its bar is not drawn by this daemon. No file was left.\n`,code:1}:{stdout:`${n}: ${r} lines, ${i} answers, ${a} lane frames\n`,stderr:o?`record: ${s}: the file holds what came before.\n`:``,code:0}}async function lle(e,t,n){let r=sle(t,n);if(!r.ok)return{stdout:``,stderr:`record: ${r.problem}\n`,code:2};let{session:i,path:a,seconds:o}=r.args;return cle(await ni(e,()=>({kind:`record`,session:i,path:a,seconds:o}),{connectMs:200,budgetMs:o*1e3+2e3},e=>`recorded`in e?e.recorded:void 0),o)}const ule={connectMs:200,budgetMs:500};async function dle(e,t,n){return fle(t,await ple(e,t),n.includes(`--json`))}function fle(e,t,n){return t.kind===`ok`?{stdout:n?JSON.stringify(t.value,null,2)+`
|
|
511
|
+
`);async function Ice(e,t){if(process.platform===`linux`)return{executable:await m.promises.readlink(`/proc/${t}/exe`),argv:(await m.promises.readFile(`/proc/${t}/cmdline`,`utf8`)).split(`\0`).slice(0,-1),env:(await m.promises.readFile(`/proc/${t}/environ`,`utf8`)).split(`\0`).slice(0,-1)};let n=Z7(`reading process ${t}'s arguments`,await e.launch({bin:`python3`,args:[`-c`,Fce,String(t)],timeoutMs:5e3,category:`lane.process`}));return JSON.parse(n)}async function $7(e,t,n){return Z7(t,await e.launch({bin:`ps`,args:n,timeoutMs:2e3,category:`lane.process`}))}async function e9(e,t){let n=await oc(e,t,`lane.tmux`,[`display`,`-p`,`-t`,t.pane,`#{pane_pid} #{pane_current_path}`]);if(n.kind!==`ok`)throw Error(n.reason);let[r=``,i=``]=n.stdout.trimEnd().split(` `),a=(await $7(e,`asking pane ${t.pane}'s foreground job`,[`-o`,`tpgid=`,`-p`,r])).trim();return{panePid:Number(r),cwd:i,foreground:Number(a)}}async function Lce(e,t){let{panePid:n,cwd:r,foreground:i}=await e9(e,t),a=await $7(e,`listing processes`,[`-A`,`-o`,`pid=,ppid=,args=`]),o=await Ice(e,i),s=o2(a).get(i)?.ppid;if(s===void 0)throw Error(`pane ${t.pane}'s foreground job ${i} is gone`);let c=nn(i,await en(i,t=>e.launch(t)));if(c.startTime===null)throw Error(`the start of pane ${t.pane}'s foreground job ${i} could not be read (${c.why})`);return{pid:i,startTime:c.startTime,executable:await m.promises.realpath(o.executable),argv:o.argv,env:o.env,cwd:r,parent:s,fromShell:i!==n,attached:Pce(a,i,n)}}function Rce(e,t){let n=t9(e,t);return n.torn?t9(e,t).held:n.held}function t9(e,t){let n;try{n=m.readFileSync(e,`utf8`)}catch(t){return{torn:!1,held:t.code===`ENOENT`?{kind:`none`,why:`it keeps no session record at ${e} (update Claude Code with \`claude update\`: recent releases keep one)`}:{kind:`unread`,why:t.message}}}let r;try{r=JSON.parse(n)}catch(t){return{torn:!0,held:{kind:`unread`,why:`its session record ${e} is not JSON (${t.message})`}}}let{sessionId:i,procStart:a}=typeof r==`object`&&r?r:{},o=Qt(a);return{torn:!1,held:typeof i!=`string`||i===``?{kind:`unread`,why:`its session record ${e} names no session`}:a===void 0?{kind:`unread`,why:`its session record ${e} names no process start (update Claude Code with \`claude update\`: recent releases name one)`}:o===void 0?{kind:`unread`,why:`its session record ${e} names its process start as ${JSON.stringify(a)}, not in the form \`ps -o lstart=\` prints it`}:o===t.startTime?{kind:`holds`,sessionId:i}:{kind:`none`,why:`its session record ${e} was left by a Claude Code that has exited: the record names a process started ${o}, and pid ${t.pid} is a process started ${t.startTime}`}}}const zce=e=>t=>Rce(s.join(qo(t.configDir,e),`sessions`,`${t.pid}.json`),t);function Bce(e,t,n,r,i,a,o){let s=e=>et(r,e,n);return{claudeInput:u$(e),barPanes:async t=>Nce(await X7(e,t,[`list-panes`,`-a`,`-F`,`#{pane_id} #{pane_start_command}`]),t.pane),openBarPane:async(t,n,r)=>(await X7(e,t,[`split-window`,`-d`,`-v`,`-l`,`1`,`-t`,t.pane,`-P`,`-F`,`#{pane_id}`,...Object.entries(r).flatMap(([e,t])=>[`-e`,`${e}=${t}`]),...n])).trim(),closePane:async(t,n)=>void await X7(e,t,[`kill-pane`,`-t`,n]),claude:async(t,n)=>void Z7(`claude ${t.join(` `)}`,await e.launch({bin:`claude`,args:[...t],envOverlay:q0(n),timeoutMs:3e4,category:`lane.claude`})),fileExists:e=>gc(o,e)===`present`,presence:e=>gc(o,e),paneClaude:t=>Lce(e,t),heldSession:a,paneDir:async(t,n)=>{let i=r.monotonic()+Y7;for(;;){let a=await e9(e,t);if(a.foreground===n){if(a.cwd===``)throw Error(`tmux read no directory for pane ${t.pane}`);return a.cwd}if(r.monotonic()>i)throw Error(`the shell in pane ${t.pane} (pid ${n}) did not take its terminal back within ${Y7/1e3} s`);await s(100)}},launcherNode:e=>Ace(e,e=>J7(e,m.constants.X_OK),kce),onPath:(e,t)=>{let n=q7(e,t,e=>J7(e,m.constants.X_OK));return n===null?null:m.realpathSync(n)},followed:async(e,n,i)=>{let a=r.monotonic()+i;for(;!t(e).has(n);){if(r.monotonic()>a)return!1;await s(200)}return!0},moduleGraph:async(t,n,r)=>{let i=await e.launch({bin:t,args:[n,r],timeoutMs:2e4,category:`lane.process`}),a=!i.ok&&i.reason===`non-zero`?jce(i.stdout):null;return a===null?(Z7(`reading ${r}'s module graph`,i),{ok:!0}):{ok:!1,reason:a}},terminate:e=>{n.throwIfAborted();try{process.kill(e,`SIGTERM`)}catch(t){throw Error(`Claude Code (pid ${e}) could not be sent SIGTERM: ${t instanceof Error?t.message:String(t)}`)}},exited:async(e,t)=>{let n=r.monotonic()+t;for(;i.alive(e);){if(r.monotonic()>n)return!1;await s(100)}return!0},typeShellLine:async(t,n)=>void await X7(e,t,c$(t.pane,`cc-candybar-lane`,[]),n)}}const Vce=/^[0-9a-f]{64}$/;function n9(e,t){return oe(`sha256`,e).update(JSON.stringify(t)).digest()}const r9=e=>[e.sessionId,e.action,e.declaration,e.evaluated],i9=e=>[aC,e];function Hce(e){if(e.length!==32)throw Error(`a link key is 32 bytes, got ${e.length}`);let t=t=>n9(e,t).toString(`hex`),n=(t,n)=>Vce.test(n)&&le(Buffer.from(n,`hex`),n9(e,t));return{sign:e=>t(r9(e)),verify:(e,t)=>n(r9(e),t),signBinding:e=>t(i9(e)),verifyBinding:(e,t)=>n(i9(e),t)}}function a9(e){return s.join(e,`link.key`)}function o9(e){let t,n=()=>t??=Uce(e);return{sign:e=>n().sign(e),verify:(e,t)=>n().verify(e,t),signBinding:e=>n().signBinding(e),verifyBinding:(e,t)=>n().verifyBinding(e,t)}}function Uce(e){let t;try{t=m.readFileSync(e)}catch(n){if(n.code!==`ENOENT`)throw n;Wce(e),t=m.readFileSync(e)}if(t.length!==32)throw Error(`link key ${e} holds ${t.length} bytes, not 32: remove it and a new one is made (links drawn before then stop working)`);return Hce(t)}function Wce(e){m.mkdirSync(s.dirname(e),{recursive:!0});let t=ct(e);m.writeFileSync(t,se(32),{mode:384,flag:`wx`});try{m.linkSync(t,e)}catch(e){if(e.code!==`EEXIST`)throw e}finally{m.unlinkSync(t)}}function Gce(e,t,n){return{daemonLog:t,launcher:e=>gn(e,n),storage:(t,r)=>Oce(e,t,n,r),doctorStores:t=>w4(t,e.state),doctorEdge:I4,claudeInput:u$,probe:an,laneEdge:(e,t,r,i,a,o)=>Bce(e,t,r,n,i,a,o),heldSession:zce,linkSigner:o9(a9(e.state)),limits:({startedAtMs:r,exit:i,launcher:a,log:o})=>qi(r,i,{launcher:a,log:o,clock:n,snapshotDir:e.state,writeLogNow:()=>t.writeNow()}),fetch,pricing:e=>Iae({...e,clock:n}),filesystem:pn}}function s9(e){let t=null;return e.on(`drain`,()=>{let n=t;t=null,n!==null&&e.write(n)}),n=>{if(e.writable){if(e.writableNeedDrain){t=n;return}e.write(n)}}}const Kce={kind:`awaiting`},c9=e=>e.kind===`awaiting`||e.kind===`answering`||e.kind===`unattended`&&!e.lapsed,l9=e=>e.kind!==`streaming`&&e.kind!==`closed`,u9=e=>e.kind===`answered`&&e.by===`backstop`||(e.kind===`unattended`||e.kind===`closed`)&&e.lapsed,qce=e=>e.kind===`closed`,d9=e=>({next:e,effects:[]}),f9=(e,t)=>({next:{kind:`answered`,by:e},effects:[{kind:`answer`,answer:t}]}),Jce=(e,t)=>{switch(t.kind){case`read`:return e.kind===`awaiting`?d9(t.waits?{kind:`answering`}:{kind:`unattended`,lapsed:!1}):e.kind===`answered`&&e.by===`backstop`&&!t.waits?d9({kind:`unattended`,lapsed:!0}):d9(e);case`unreadable`:return e.kind===`awaiting`?f9(`reply`,t.answer):d9(e);case`deadline`:if(e.kind===`awaiting`||e.kind===`answering`){let e=f9(`backstop`,t.answer);return{...e,effects:[{kind:`count-timeout`},...e.effects]}}return e.kind===`unattended`&&!e.lapsed?{next:{kind:`unattended`,lapsed:!0},effects:[{kind:`count-timeout`}]}:d9(e);case`reply`:return e.kind===`answering`||e.kind===`held`?f9(`reply`,t):e.kind===`answered`&&e.by===`backstop`||e.kind===`closed`&&e.lapsed?{next:e,effects:t.exitAfterFlush===null?[]:[{kind:`exit-dropped`}]}:e.kind===`closed`?{next:e,effects:t.exitAfterFlush===null?[]:[{kind:`exit`,code:t.exitAfterFlush}]}:d9(e);case`subscribe`:return e.kind===`answering`?{next:e,effects:[{kind:`attach`,sessionId:t.sessionId,lane:t.lane}]}:d9(e);case`subscribed`:return e.kind===`answering`?d9({kind:`streaming`,unsubscribe:t.unsubscribe}):{next:e,effects:[{kind:`unsubscribe`,unsubscribe:t.unsubscribe}]};case`held`:return e.kind===`answering`?{next:{kind:`held`},effects:[{kind:`start`,start:t.start}]}:d9(e);case`threw`:return e.kind===`answering`||e.kind===`held`?f9(`reply`,t.answer):d9(e);case`settled`:return e.kind===`unattended`?d9({kind:`closed`,lapsed:e.lapsed}):d9(e);case`close`:return e.kind===`unattended`||e.kind===`closed`?d9(e):e.kind===`streaming`?{next:{kind:`closed`,lapsed:!1},effects:[{kind:`unsubscribe`,unsubscribe:e.unsubscribe}]}:e.kind===`held`?{next:{kind:`closed`,lapsed:!1},effects:[{kind:`abort`}]}:d9({kind:`closed`,lapsed:u9(e)})}};function Yce(e,t){let{next:n,effects:r}=Jce(e,t);return{next:n,effects:[...[...c9(e)&&!c9(n)?[{kind:`clear-backstop`}]:[],...l9(e)&&!l9(n)?[{kind:`leave-in-flight`}]:[]],...r]}}function Xce(e,t){t.allowHalfOpen=!1;let n=e.clock.monotonic();e.stats.inFlight++;let r=Kce,i=e=>{let{next:t,effects:n}=Yce(r,e);r=t,n.forEach(o)},a=new AbortController,o=t=>{switch(t.kind){case`answer`:return s(t.answer);case`exit`:return e.exit(t.code);case`exit-dropped`:return e.log(`warn`,`exit-after-flush dropped: the client was already told TIMEOUT`);case`count-timeout`:e.stats.requestsTimedOut++;return;case`clear-backstop`:return l();case`leave-in-flight`:e.stats.inFlight--;return;case`attach`:return i({kind:`subscribed`,unsubscribe:u(t.sessionId,t.lane)});case`start`:return d(t.start);case`abort`:return a.abort();case`unsubscribe`:return t.unsubscribe()}},s=({resp:n,exitAfterFlush:r,delivered:i})=>{let a=r===null?void 0:()=>e.exit(r),[o,s]=c(n,i);try{t.end(o,e=>{e??s(),a?.()})}catch(t){e.log(`warn`,`response write failed: ${t.message}`),a?.()}},c=(t,n)=>{try{return[Xr(t),n]}catch(t){return e.log(`error`,`response encode failed: ${O(t)}`),[Xr(kQ(t)),OQ]}},l=e.clock.after(200,()=>i({kind:`deadline`,answer:v8({ok:!1,error:`request exceeded 200ms`,code:`TIMEOUT`,daemonV:3})})),u=(n,r)=>{let i=s9(t);return e.subscribe(n,{lane:r,frame:e=>i(Zr(e.json)),refused:e=>t.end(Xr(e)),drawing:()=>!0})},d=t=>{t(a.signal).then(e=>i(y8(e)),t=>{e.log(`error`,`held request threw: ${O(t)}`),i({kind:`threw`,answer:v8(kQ(t))})})};$r(t,t=>{new Promise(a=>{let o=Gr(t);i({kind:`read`,waits:o.kind===`request`}),a(e.handle(o,()=>u9(r),n,()=>qce(r)))}).then(i).catch(t=>{e.log(`error`,`handler threw: ${O(t)}`),i({kind:`threw`,answer:v8(kQ(t))})}).finally(()=>i({kind:`settled`}))},t=>{e.log(`warn`,`frame parse failed: ${t.message}`),i({kind:`unreadable`,answer:v8({ok:!1,error:t.message,code:`BAD_REQUEST`,daemonV:3})})}),t.on(`error`,t=>{e.log(`warn`,`socket error: ${t.message}`),i({kind:`close`})}),t.on(`close`,()=>i({kind:`close`}))}const p9=`CC_CANDYBAR_PARENT_PID`;function Zce(e){let t=e[p9];if(t===void 0)return{kind:`outlives-nobody`};let n=Number.parseInt(t,10);if(!Number.isInteger(n)||n<=0)throw Error(`${p9} must be a positive integer pid, got ${JSON.stringify(t)}`);return{kind:`anchored`,pid:n}}function Qce(e){if(e.anchor.kind===`outlives-nobody`)return{disarm:()=>{}};let{pid:t}=e.anchor;return{disarm:e.clock.every(e.intervalMs??250,()=>{e.probe.alive(t)||e.onOrphaned(`spawner pid ${t} gone`)},{unref:!0})}}let m9=null,h9=null,g9=null,_9=null;function v9(){if(_9===null)throw Error(`runDaemon has not started`);return _9}function y9(e,t){v9().log.log(e,t)}function $ce(){let e=i(import.meta.url);return{entryUrl:import.meta.url,digest:Bn(),path:e,node:[t.execPath,...t.execArgv],targets:[...new Set([e,...t.argv[1]?[t.argv[1]]:[]])]}}function ele(e){let n=mr(e.home);_9={world:e,paths:n,log:new nc(n.log,e.clock)},t.on(`uncaughtException`,e=>{y9(`error`,`uncaughtException: ${e.stack||e.message}`),C9(1)}),t.on(`unhandledRejection`,e=>{y9(`error`,`unhandledRejection: ${String(e)}`),C9(1)});for(let e of[`SIGINT`,`SIGTERM`,`SIGHUP`])t.on(e,()=>{y9(`info`,`received ${e}, shutting down`),C9(0)});tle().catch(b9)}function b9(e){y9(`error`,`refusing to boot: ${O(e)}`),C9(1)}async function tle(){let{world:e,paths:n,log:r}=v9(),{host:i,home:a}=e,o=Ni(i.env);a.kind===`main`&&a.legacySocket!==null&&y9(`warn`,`CC_CANDYBAR_SOCKET=${a.legacySocket} is honoured for one more release; a renderer is named by CC_CANDYBAR_HOME and CC_CANDYBAR_NAME instead`),m9=await sn(t.pid,an(e.launcher).startTime);let s=await Ks(Js(e,m9,sr(i),n.socket!==$n(Le)));if(!s.decision.allow){y9(`warn`,`fork-bomb breaker: ${s.decision.reason}; refusing to boot`),C9(1);return}h9=s.registryPath,m.mkdirSync(n.state,{recursive:!0}),nr(n.socket);let c=dce({...Gce(n,r,e.clock),bundle:$ce(),host:i,home:a,memoryLimitBytes:o,registryUrl:i.env.CC_CANDYBAR_REGISTRY_URL??`https://registry.npmjs.org`,clock:e.clock,gates:wz(),exit:C9});g9=c,Qce({clock:e.clock,anchor:Zce(i.env),probe:an(e.launcher),onOrphaned:e=>{y9(`info`,`parent watchdog: ${e}; shutting down`),C9(0)}}),x9(c,ue.createServer(e=>Xce(c,e)),n.socket,!1)}function x9(e,n,r,i){n.removeAllListeners(`error`),n.removeAllListeners(`listening`),n.once(`error`,a=>{if(a.code!==`EADDRINUSE`){y9(`error`,`server error: ${a.message}`),C9(1);return}if(i){y9(`info`,`lost rebind race; another daemon is alive — exiting`),t.exit(0);return}nle(e,n,r).catch(b9)}),n.listen(r,()=>rle(e,r))}async function nle(e,n,r){let i=await Ps(Fs(rr(r)),(t,n)=>on(t,n,an(e.launcher)));if(i.kind===`attach-and-exit`){y9(`info`,`EADDRINUSE: ${i.reason} — exiting`),t.exit(0);return}y9(`warn`,`EADDRINUSE: ${i.reason} — unlinking stale socket and rebinding`);try{m.unlinkSync(r)}catch(e){if(e.code!==`ENOENT`){y9(`error`,`cannot unlink stale socket ${r}: ${e.message}`),C9(1);return}}x9(e,n,r,!0)}function rle(e,n){let r=Rs(n);if(r.kind!==`present`){y9(`warn`,`no ownable socket at bind callback (${r.kind}); exiting`),C9(0);return}ale(n);try{m.chmodSync(n,384)}catch(e){y9(`warn`,`chmod socket failed: ${e.message}`)}y9(`info`,`daemon up: pid=${t.pid} v=3 sock=${n} heapCap=${Mi(pe.getHeapStatistics().heap_size_limit)}MB memoryLimit=${Mi(e.memoryLimitBytes)}MB`),ea(v9().paths.spawnBackoff),e.arm(),ile(n,r.identity)}function ile(e,n){Vs({bound:n,myPid:t.pid,readIdentity:()=>Rs(e),readLease:()=>Fs(rr(e)),shutdown:e=>C9(e),log:y9,clock:v9().world.clock}).arm()}function ale(e){let n=Is(rr(e),{pid:t.pid,version:3,binPath:t.argv[1],startTime:m9});n!==null&&y9(`warn`,`lease write failed: ${n}`)}const ole=e=>(t,n)=>ac(e,{socket:t},`tmux-status`,n);let S9=!1;function C9(e){S9||(S9=!0,v9().world.clock.after(500,()=>t.kill(t.pid,`SIGKILL`)),g9?.close(ole(v9().world.launcher)),Ls(v9().paths.lease,t.pid),h9!==null&&qs(h9,t.pid,Ws,e=>m.unlinkSync(e)),t.exit(e))}function sle(e,t){let n=[],r=10;for(let t=0;t<e.length;t++){let i=e[t];if(i===`--seconds`){let n=e[++t];if(n===void 0)return{ok:!1,problem:`--seconds needs a number after it`};let i=qr(Number(n));if(!i.ok)return{ok:!1,problem:`--seconds ${JSON.stringify(n)} ${i.problem}`};r=i.seconds}else if(i!==void 0&&!i.startsWith(`-`))n.push(i);else return{ok:!1,problem:`unexpected argument ${JSON.stringify(i)}`}}let[i,a,...o]=n;return i===void 0||a===void 0||o.length>0?{ok:!1,problem:`usage: cc-candybar record <session-id> <path> [--seconds N]`}:{ok:!0,args:{session:i,path:f(t,a),seconds:r}}}function cle(e,t){if(e.kind!==`ok`)return{stdout:``,stderr:`record: ${li(e)}\n`,code:1};let{path:n,lines:r,answers:i,frames:a,daemonClosed:o}=e.value,s=`the daemon closed before ${t}s ran out`;return i+a===0?{stdout:``,stderr:o?`record: ${n}: ${s}, and nothing had been drawn, so there is nothing to replay. No file was left.\n`:`record: ${n}: no request was answered and no lane drew a frame in ${t}s, so there is nothing to replay: the session was idle, or its bar is not drawn by this daemon. No file was left.\n`,code:1}:{stdout:`${n}: ${r} lines, ${i} answers, ${a} lane frames\n`,stderr:o?`record: ${s}: the file holds what came before.\n`:``,code:0}}async function lle(e,t,n){let r=sle(t,n);if(!r.ok)return{stdout:``,stderr:`record: ${r.problem}\n`,code:2};let{session:i,path:a,seconds:o}=r.args;return cle(await ni(e,()=>({kind:`record`,session:i,path:a,seconds:o}),{connectMs:200,budgetMs:o*1e3+2e3},e=>`recorded`in e?e.recorded:void 0),o)}const ule={connectMs:200,budgetMs:500};async function dle(e,t,n){return fle(t,await ple(e,t),n.includes(`--json`))}function fle(e,t,n){return t.kind===`ok`?{stdout:n?JSON.stringify(t.value,null,2)+`
|
|
512
512
|
`:mle(t.value),stderr:``,code:0}:{stdout:``,stderr:`${e}: ${li(t)}\n`,code:1}}function ple(e,t){return ni(e,()=>({kind:`debug`,what:t}),ule,e=>`debug`in e?e.debug:void 0)}function mle(e){switch(e.what){case`vars`:return hle(e.vars);case`segments`:return gle(e.segments);case`config`:return _le(e.config);default:return e}}function hle(e){if(e.length===0)return`no variables (DSL not active)
|
|
513
513
|
`;let t=[`variables (${e.length})`,``],n=e.reduce((e,t)=>Math.max(e,t.name.length),4),r=e.reduce((e,t)=>Math.max(e,(t.source??`—`).length),6),i=e.reduce((e,t)=>Math.max(e,t.type.length),4);for(let a of e){let e=a.ageMs===null?``:` ${yle(a.ageMs)}`,o=a.lastError?` ✗ ${a.lastError.message}`:``;t.push(` ${a.name.padEnd(n)} ${(a.source??`—`).padEnd(r)} ${a.type.padEnd(i)} ${vle(a.value)}${e}${o}`)}return t.join(`
|
|
514
514
|
`)+`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptctl/cc-candybar",
|
|
3
|
-
"version": "1.211.
|
|
3
|
+
"version": "1.211.2",
|
|
4
4
|
"description": "Statusline renderer for Claude Code — a JSON5-configurable DSL with daemon-cached data sources, byte-clean palette-aware composition, and OSC8 click verbs.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.mjs",
|
|
@@ -110,9 +110,9 @@
|
|
|
110
110
|
"yaml": "^2.9.1"
|
|
111
111
|
},
|
|
112
112
|
"optionalDependencies": {
|
|
113
|
-
"@promptctl/cc-candybar-darwin-arm64": "1.211.
|
|
114
|
-
"@promptctl/cc-candybar-darwin-x64": "1.211.
|
|
115
|
-
"@promptctl/cc-candybar-linux-arm64": "1.211.
|
|
116
|
-
"@promptctl/cc-candybar-linux-x64": "1.211.
|
|
113
|
+
"@promptctl/cc-candybar-darwin-arm64": "1.211.2",
|
|
114
|
+
"@promptctl/cc-candybar-darwin-x64": "1.211.2",
|
|
115
|
+
"@promptctl/cc-candybar-linux-arm64": "1.211.2",
|
|
116
|
+
"@promptctl/cc-candybar-linux-x64": "1.211.2"
|
|
117
117
|
}
|
|
118
118
|
}
|