@promptctl/cc-candybar 1.131.0 → 1.132.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.mjs +32 -32
  2. package/package.json +5 -5
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{createRequire as e}from"node:module";import t from"node:process";import{json as n}from"node:stream/consumers";import r,{createReadStream as i,existsSync as a,realpathSync as o,statSync as s,watch as c}from"node:fs";import l,{basename as u,dirname as d,isAbsolute as f,join as p,sep as m}from"node:path";import h,{homedir as g}from"node:os";import{spawn as _,spawnSync as v}from"node:child_process";import{inspect as y,parseArgs as b,types as x}from"node:util";import S from"node:net";import C from"node:v8";import{URL as ee,URLSearchParams as te,fileURLToPath as ne,pathToFileURL as re}from"node:url";import ie,{createHash as ae,randomUUID as w}from"node:crypto";import{open as T,readFile as oe,readdir as se,stat as ce}from"node:fs/promises";import{clearInterval as le,setInterval as ue}from"node:timers";import{get as E}from"node:https";import{setTimeout as de}from"node:timers/promises";import{createInterface as fe}from"node:readline";var pe=Object.create,me=Object.defineProperty,he=Object.getOwnPropertyDescriptor,ge=Object.getOwnPropertyNames,_e=Object.getPrototypeOf,ve=Object.prototype.hasOwnProperty,ye=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),be=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=ge(t),a=0,o=i.length,s;a<o;a++)s=i[a],!ve.call(e,s)&&s!==n&&me(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=he(t,s))||r.enumerable});return e},xe=(e,t,n)=>(n=e==null?{}:pe(_e(e)),be(t||!e||!e.__esModule?me(n,`default`,{value:e,enumerable:!0}):n,e));function D(e,...t){process.env.CC_CANDYBAR_DEBUG&&console.error(`[DEBUG] ${e}`,...t)}function Se(e,t){return x.isNativeError(e)?e.code===`ENOENT`&&t!==void 0&&!a(t)?`working directory does not exist: ${t}`:e.message:String(e)}const Ce={"click.pbcopy":1e3,"click.open":1e3,"doctor.tmux":1e3,"claude-input.type":1e3},we=new Map;function Te(e){let t=Ce[e];if(t===void 0)return{allowed:!0};let n=we.get(e);if(n===void 0)return{allowed:!0};let r=Date.now()-n;return r>=t?{allowed:!0}:{allowed:!1,minIntervalMs:t,sinceLastMs:r}}function Ee(e){we.set(e,Date.now())}function De(e){return e.env??process.env}function Oe(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 ${n}ms ago`}}let ke=null;function Ae(e){ke=e}function je(e,t){try{process.kill(-e,t)}catch(e){if(e.code!==`ESRCH`)throw e}}async function O(e){if(e.signal?.aborted)return{ok:!1,reason:`aborted`,stdout:``,stderr:``,exitCode:null,signal:null};let t=Te(e.category);if(!t.allowed)return Oe(e.category,t.minIntervalMs,t.sinceLastMs);Ee(e.category);let n=Date.now();return ke?.onStart(e.category),new Promise(t=>{let r;try{r=_(e.bin,e.args??[],{cwd:e.cwd,env:De(e),stdio:[`pipe`,`pipe`,`pipe`],detached:!0})}catch(r){ke?.onEnd(e.category,Date.now()-n),t({ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:Se(r,e.cwd)});return}let i=``,a=``,o=!1,s=null,c=null,l=null,u=()=>m(`aborted`),d=t=>{o||(o=!0,s&&clearTimeout(s),c&&clearTimeout(c),e.signal?.removeEventListener(`abort`,u),ke?.onEnd(e.category,Date.now()-n),t())},f=e=>d(()=>t(e)),p=(e,t)=>{try{je(e,t)}catch(e){f({ok:!1,reason:`signal-refused`,stdout:i,stderr:a,exitCode:null,signal:null,error:e instanceof Error?e.message:String(e)})}},m=t=>{l=t,s&&clearTimeout(s),e.signal?.removeEventListener(`abort`,u);let n=r.pid;n!==void 0&&(c=setTimeout(()=>p(n,`SIGKILL`),250),p(n,`SIGTERM`))};r.stdout?.on(`data`,e=>{i+=e.toString(`utf8`)}),r.stderr?.on(`data`,e=>{a+=e.toString(`utf8`)}),r.on(`error`,t=>{f({ok:!1,reason:`spawn-error`,stdout:i,stderr:a,exitCode:null,signal:null,error:Se(t,e.cwd)})}),r.on(`close`,(e,t)=>{if(l!==null){f({ok:!1,reason:l,stdout:i,stderr:a,exitCode:e,signal:t});return}if(e===0){f({ok:!0,stdout:i,stderr:a,exitCode:e});return}f({ok:!1,reason:t?`signal`:`non-zero`,stdout:i,stderr:a,exitCode:e,signal:t})}),e.timeoutMs&&e.timeoutMs>0&&(s=setTimeout(()=>m(`timeout`),e.timeoutMs)),e.signal?.addEventListener(`abort`,u,{once:!0}),e.stdinInput!==void 0&&r.stdin?r.stdin.end(e.stdinInput):r.stdin&&r.stdin.end()})}function Me(e){let t=Te(e.category);if(!t.allowed)return Oe(e.category,t.minIntervalMs,t.sinceLastMs);Ee(e.category);let n=Date.now();ke?.onStart(e.category);let r=[`pipe`,`pipe`,`pipe`];try{let t=v(e.bin,e.args??[],{cwd:e.cwd,env:De(e),input:e.stdinInput,timeout:e.timeoutMs&&e.timeoutMs>0?e.timeoutMs:void 0,stdio:r,encoding:`utf8`});ke?.onEnd(e.category,Date.now()-n);let i=typeof t.stdout==`string`?t.stdout:``,a=typeof t.stderr==`string`?t.stderr:``;if(t.error)return{ok:!1,reason:t.error.code===`ETIMEDOUT`?`timeout`:`spawn-error`,stdout:i,stderr:a,exitCode:null,signal:t.signal??null,error:Se(t.error,e.cwd)};if(t.status===0)return{ok:!0,stdout:i,stderr:a,exitCode:t.status};let o=e.timeoutMs!==void 0&&e.timeoutMs>0;return{ok:!1,reason:t.signal?o&&t.signal===`SIGTERM`?`timeout`:`signal`:`non-zero`,stdout:i,stderr:a,exitCode:t.status,signal:t.signal??null}}catch(t){return ke?.onEnd(e.category,Date.now()-n),{ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:Se(t,e.cwd)}}}function Ne(e){let t=Te(e.category);if(!t.allowed)return Oe(e.category,t.minIntervalMs,t.sinceLastMs);Ee(e.category);let n=Date.now();ke?.onStart(e.category);let r=Pe(e);return ke?.onEnd(e.category,Date.now()-n),r}function Pe(e){let t;try{t=_(e.bin,e.args??[],{cwd:e.cwd,env:De(e),detached:!0,stdio:`ignore`})}catch(t){return{ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:Se(t,e.cwd)}}return t.once(`error`,()=>{}),t.pid===void 0?{ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:`spawn(${e.bin}): no pid (binary not found or unexecutable)`}:(t.unref(),{ok:!0,stdout:``,stderr:``,exitCode:null})}function Fe(e,t,n){let i=`${e}.tmp`,a=n??r.statSync(e,{throwIfNoEntry:!1})?.mode;try{r.writeFileSync(i,t,a===void 0?{}:{mode:a}),r.renameSync(i,e)}catch(e){throw r.rmSync(i,{force:!0}),e}}function Ie(e,t){let n=e[t];return n&&n.length>0?n:void 0}function Le(e=process.env){let t=Ie(e,`XDG_STATE_HOME`)??l.join(h.homedir(),`.local`,`state`);return l.join(t,`cc-candybar`)}function Re(){let e=Ie(process.env,`XDG_CACHE_HOME`)??l.join(h.homedir(),`.cache`);return l.join(e,`cc-candybar`)}function ze(){return Le()}function Be(){return process.env.CC_CANDYBAR_SOCKET||Ve()}function Ve(){let e=h.userInfo().uid;return l.join(`/tmp`,`cc-candybar-${e}`,`socket`)}function He(e){r.mkdirSync(e,{recursive:!0,mode:448});let t=r.lstatSync(e);if(t.isSymbolicLink())throw Error(`directory is a symlink: ${e}`);if(!t.isDirectory())throw Error(`not a directory: ${e}`);let n=h.userInfo().uid;if(typeof n==`number`&&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 Ue(e){He(l.dirname(e));for(let t of[e,We(e)])try{if(r.lstatSync(t).isSymbolicLink())throw Error(`path is a symlink: ${t}`)}catch(e){if(e.code!==`ENOENT`)throw e}}function We(e){return`${e}.lease`}function Ge(){return We(Be())}function Ke(){return l.join(Le(),`session-state.json`)}function qe(){return l.join(Le(),`settings-history.json`)}function Je(){let e=process.env.CC_CANDYBAR_DAEMON_REGISTRY_DIR;if(e)return e;let t=h.userInfo().uid;return l.join(`/tmp`,`cc-candybar-${t}`,`daemons`)}function Ye(){return l.join(Le(),`spawn.lock`)}function Xe(){return l.join(Le(),`spawn.cooldown`)}function Ze(){return l.join(Le(),`spawn.backoff`)}function Qe(){return l.join(Le(),`diagnostics`)}function $e(e=process.env){return l.join(Le(e),`daemon.log`)}const et=[`MEMENTO_CONFIG_HOME`,`XDG_CONFIG_HOME`];function tt(e,t){return Object.fromEntries(et.flatMap(n=>{let r=e[n]??``;return r===``?[]:[[n,l.resolve(t,r)]]}))}const nt=Object.keys({termCols:!0,termRows:!0,ssh:!0,tmux:!0,configEnv:!0,claudeConfigDir:!0,mementoEnv:!0});function rt(e){let t=ut(e.termCols),n=ut(e.termRows),r=dt(e.ssh),i=ct(e.tmux),a=st(e.configEnv),o=st(e.claudeConfigDir),s=ot(e.mementoEnv);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&&{mementoEnv:s}}}function it(e,t){return nt.filter(n=>e[n]!==void 0&&t[n]===void 0).map(t=>({hint:t,sent:e[t]}))}function at(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).`}function ot(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=e,n=et.filter(e=>t[e]!==void 0);return n.every(e=>st(t[e])!==void 0)?Object.fromEntries(n.map(e=>[e,t[e]])):void 0}function st(e){return typeof e==`string`&&l.isAbsolute(e)?e:void 0}function ct(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 lt=1e4;function ut(e){if(typeof e!=`number`||!Number.isFinite(e))return;let t=Math.floor(e);if(!(t<=0))return t>lt?lt:t}function dt(e){return typeof e==`boolean`?e:void 0}function ft(e){return typeof e==`string`&&e!==``&&e.length<=64?e:null}var pt=class extends Error{constructor(e){super(e),this.name=`ProtocolError`}};function mt(e){let t=Buffer.from(JSON.stringify(e),`utf8`),n=Buffer.alloc(4);return n.writeUInt32BE(t.length,0),Buffer.concat([n,t])}function ht(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 pt(`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 pt(e instanceof Error?e.message:String(e));e instanceof Error&&(n.cause=e),t(n);return}}}}function gt(e,t,n){return new Promise((r,i)=>{let a=!1,o=t=>{if(!a){a=!0,clearTimeout(s),e.removeAllListeners();try{t()}catch{}}},s=setTimeout(()=>{o(()=>{e.destroy(),i(Error(`TIMEOUT`))})},n),c=ht(e=>o(()=>r(e)),e=>o(()=>i(e)));e.on(`data`,c),e.on(`error`,e=>o(()=>i(e))),e.on(`close`,()=>o(()=>i(Error(`socket closed before response`)))),e.write(mt(t))})}async function _t(e,t,n){let r=null;try{r=await St(Be(),t.connectMs);let i=await gt(r,{v:3,...e},t.budgetMs);return bt(e.kind,i,n)}catch(e){return xt(e)}finally{r&&r.destroy()}}function vt(e,t){return typeof e==`string`?e:t}function yt(e){return typeof e==`number`&&Number.isInteger(e)&&e>=0?e:0}function bt(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=vt(r.error,`(no error message)`);switch(r.code){case`VERSION_MISMATCH`:return{kind:`permanent`,cause:`version_mismatch`,clientV:3,daemonV:yt(r.daemonV)};case`TIMEOUT`:return{kind:`transient`,cause:`timeout`,message:i};case`BAD_REQUEST`:return{kind:`permanent`,cause:`bad_request`,message:i};case`RENDER_FAILED`:return{kind:`permanent`,cause:`render_failed`,message:i};default:return{kind:`permanent`,cause:`malformed_response`,message:`unknown error code: ${String(r.code)}`}}}function xt(e){if(e instanceof pt||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 t===`CONNECT_TIMEOUT`||t===`TIMEOUT`?{kind:`transient`,cause:`timeout`,message:t}:t.includes(`ECONNREFUSED`)||t.includes(`ENOENT`)||t.includes(`ENOTSOCK`)?{kind:`transient`,cause:`unreachable`,message:t}:{kind:`transient`,cause:`io_error`,message:t}}function St(e,t){return new Promise((n,r)=>{let i=S.createConnection({path:e}),a=setTimeout(()=>{i.destroy(),r(Error(`CONNECT_TIMEOUT`))},t);i.once(`connect`,()=>{clearTimeout(a),n(i)}),i.once(`error`,e=>{clearTimeout(a),r(e)})})}function Ct(e){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`malformed_response`:return`daemon error (${e.cause}): ${e.message}`}}const wt=`1.131.0`,Tt={connectMs:50,budgetMs:150},Et={connectMs:50,budgetMs:200};function Dt(e){let t=e.output;return typeof t==`string`?t:void 0}function Ot(e,t,n,r){return _t({kind:`render`,hookData:e,args:t,cwd:n,...r},Tt,Dt)}function kt(e,t){return _t({kind:`click`,verb:e,value:t,clientVersion:wt},Et,Dt)}let At=null;function jt(e){if(At!==null)return At;r.mkdirSync(l.dirname(e),{recursive:!0});try{At=r.statSync(e).size}catch{At=0}return At}function Mt(e){for(let t=2;t>=1;t--){let n=`${e}.${t}`,i=`${e}.${t+1}`;try{r.renameSync(n,i)}catch{}}try{r.renameSync(e,`${e}.1`)}catch{}At=0}const Nt=(e,t)=>D(t);function k(e,t){let n=`${new Date().toISOString()} [${e}] ${t}\n`;try{let e=$e(),t=jt(e);r.appendFileSync(e,n),At=t+Buffer.byteLength(n,`utf8`),At>=5242880&&Mt(e)}catch(e){At=null;try{process.stderr.write(`${n}cc-candybar: daemon.log unwritable: ${e.message}\n`)}catch{}}}function Pt(e){let t=[];for(let n of e){let e=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(`
2
+ import{createRequire as e}from"node:module";import t from"node:process";import{json as n}from"node:stream/consumers";import r,{createReadStream as i,existsSync as a,realpathSync as o,statSync as s,watch as c}from"node:fs";import l,{basename as u,dirname as d,isAbsolute as f,join as p,sep as m}from"node:path";import h,{homedir as g}from"node:os";import{spawn as _,spawnSync as v}from"node:child_process";import{inspect as y,parseArgs as b,types as x}from"node:util";import S from"node:net";import C from"node:v8";import{URL as ee,URLSearchParams as te,fileURLToPath as ne,pathToFileURL as re}from"node:url";import ie,{createHash as ae,randomUUID as w}from"node:crypto";import{open as T,readFile as oe,readdir as se,stat as ce}from"node:fs/promises";import{clearInterval as le,setInterval as ue}from"node:timers";import{get as E}from"node:https";import{setTimeout as de}from"node:timers/promises";import{createInterface as fe}from"node:readline";var pe=Object.create,me=Object.defineProperty,he=Object.getOwnPropertyDescriptor,ge=Object.getOwnPropertyNames,_e=Object.getPrototypeOf,ve=Object.prototype.hasOwnProperty,ye=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),be=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=ge(t),a=0,o=i.length,s;a<o;a++)s=i[a],!ve.call(e,s)&&s!==n&&me(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=he(t,s))||r.enumerable});return e},xe=(e,t,n)=>(n=e==null?{}:pe(_e(e)),be(t||!e||!e.__esModule?me(n,`default`,{value:e,enumerable:!0}):n,e));function D(e,...t){process.env.CC_CANDYBAR_DEBUG&&console.error(`[DEBUG] ${e}`,...t)}function Se(e,t){return x.isNativeError(e)?e.code===`ENOENT`&&t!==void 0&&!a(t)?`working directory does not exist: ${t}`:e.message:String(e)}const Ce={"click.pbcopy":1e3,"click.open":1e3,"doctor.tmux":1e3,"claude-input.type":1e3},we=new Map;function Te(e){let t=Ce[e];if(t===void 0)return{allowed:!0};let n=we.get(e);if(n===void 0)return{allowed:!0};let r=Date.now()-n;return r>=t?{allowed:!0}:{allowed:!1,minIntervalMs:t,sinceLastMs:r}}function Ee(e){we.set(e,Date.now())}function De(e){return e.env??process.env}function Oe(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 ${n}ms ago`}}let ke=null;function Ae(e){ke=e}function je(e,t){try{process.kill(-e,t)}catch(e){if(e.code!==`ESRCH`)throw e}}async function O(e){if(e.signal?.aborted)return{ok:!1,reason:`aborted`,stdout:``,stderr:``,exitCode:null,signal:null};let t=Te(e.category);if(!t.allowed)return Oe(e.category,t.minIntervalMs,t.sinceLastMs);Ee(e.category);let n=Date.now();return ke?.onStart(e.category),new Promise(t=>{let r;try{r=_(e.bin,e.args??[],{cwd:e.cwd,env:De(e),stdio:[`pipe`,`pipe`,`pipe`],detached:!0})}catch(r){ke?.onEnd(e.category,Date.now()-n),t({ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:Se(r,e.cwd)});return}let i=``,a=``,o=!1,s=null,c=null,l=null,u=()=>m(`aborted`),d=t=>{o||(o=!0,s&&clearTimeout(s),c&&clearTimeout(c),e.signal?.removeEventListener(`abort`,u),ke?.onEnd(e.category,Date.now()-n),t())},f=e=>d(()=>t(e)),p=(e,t)=>{try{je(e,t)}catch(e){f({ok:!1,reason:`signal-refused`,stdout:i,stderr:a,exitCode:null,signal:null,error:e instanceof Error?e.message:String(e)})}},m=t=>{l=t,s&&clearTimeout(s),e.signal?.removeEventListener(`abort`,u);let n=r.pid;n!==void 0&&(c=setTimeout(()=>p(n,`SIGKILL`),250),p(n,`SIGTERM`))};r.stdout?.on(`data`,e=>{i+=e.toString(`utf8`)}),r.stderr?.on(`data`,e=>{a+=e.toString(`utf8`)}),r.on(`error`,t=>{f({ok:!1,reason:`spawn-error`,stdout:i,stderr:a,exitCode:null,signal:null,error:Se(t,e.cwd)})}),r.on(`close`,(e,t)=>{if(l!==null){f({ok:!1,reason:l,stdout:i,stderr:a,exitCode:e,signal:t});return}if(e===0){f({ok:!0,stdout:i,stderr:a,exitCode:e});return}f({ok:!1,reason:t?`signal`:`non-zero`,stdout:i,stderr:a,exitCode:e,signal:t})}),e.timeoutMs&&e.timeoutMs>0&&(s=setTimeout(()=>m(`timeout`),e.timeoutMs)),e.signal?.addEventListener(`abort`,u,{once:!0}),e.stdinInput!==void 0&&r.stdin?r.stdin.end(e.stdinInput):r.stdin&&r.stdin.end()})}function Me(e){let t=Te(e.category);if(!t.allowed)return Oe(e.category,t.minIntervalMs,t.sinceLastMs);Ee(e.category);let n=Date.now();ke?.onStart(e.category);let r=[`pipe`,`pipe`,`pipe`];try{let t=v(e.bin,e.args??[],{cwd:e.cwd,env:De(e),input:e.stdinInput,timeout:e.timeoutMs&&e.timeoutMs>0?e.timeoutMs:void 0,stdio:r,encoding:`utf8`});ke?.onEnd(e.category,Date.now()-n);let i=typeof t.stdout==`string`?t.stdout:``,a=typeof t.stderr==`string`?t.stderr:``;if(t.error)return{ok:!1,reason:t.error.code===`ETIMEDOUT`?`timeout`:`spawn-error`,stdout:i,stderr:a,exitCode:null,signal:t.signal??null,error:Se(t.error,e.cwd)};if(t.status===0)return{ok:!0,stdout:i,stderr:a,exitCode:t.status};let o=e.timeoutMs!==void 0&&e.timeoutMs>0;return{ok:!1,reason:t.signal?o&&t.signal===`SIGTERM`?`timeout`:`signal`:`non-zero`,stdout:i,stderr:a,exitCode:t.status,signal:t.signal??null}}catch(t){return ke?.onEnd(e.category,Date.now()-n),{ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:Se(t,e.cwd)}}}function Ne(e){let t=Te(e.category);if(!t.allowed)return Oe(e.category,t.minIntervalMs,t.sinceLastMs);Ee(e.category);let n=Date.now();ke?.onStart(e.category);let r=Pe(e);return ke?.onEnd(e.category,Date.now()-n),r}function Pe(e){let t;try{t=_(e.bin,e.args??[],{cwd:e.cwd,env:De(e),detached:!0,stdio:`ignore`})}catch(t){return{ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:Se(t,e.cwd)}}return t.once(`error`,()=>{}),t.pid===void 0?{ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:`spawn(${e.bin}): no pid (binary not found or unexecutable)`}:(t.unref(),{ok:!0,stdout:``,stderr:``,exitCode:null})}function Fe(e,t,n){let i=`${e}.tmp`,a=n??r.statSync(e,{throwIfNoEntry:!1})?.mode;try{r.writeFileSync(i,t,a===void 0?{}:{mode:a}),r.renameSync(i,e)}catch(e){throw r.rmSync(i,{force:!0}),e}}function Ie(e,t){let n=e[t];return n&&n.length>0?n:void 0}function Le(e=process.env){let t=Ie(e,`XDG_STATE_HOME`)??l.join(h.homedir(),`.local`,`state`);return l.join(t,`cc-candybar`)}function Re(){let e=Ie(process.env,`XDG_CACHE_HOME`)??l.join(h.homedir(),`.cache`);return l.join(e,`cc-candybar`)}function ze(){return Le()}function Be(){return process.env.CC_CANDYBAR_SOCKET||Ve()}function Ve(){let e=h.userInfo().uid;return l.join(`/tmp`,`cc-candybar-${e}`,`socket`)}function He(e){r.mkdirSync(e,{recursive:!0,mode:448});let t=r.lstatSync(e);if(t.isSymbolicLink())throw Error(`directory is a symlink: ${e}`);if(!t.isDirectory())throw Error(`not a directory: ${e}`);let n=h.userInfo().uid;if(typeof n==`number`&&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 Ue(e){He(l.dirname(e));for(let t of[e,We(e)])try{if(r.lstatSync(t).isSymbolicLink())throw Error(`path is a symlink: ${t}`)}catch(e){if(e.code!==`ENOENT`)throw e}}function We(e){return`${e}.lease`}function Ge(){return We(Be())}function Ke(){return l.join(Le(),`session-state.json`)}function qe(){return l.join(Le(),`settings-history.json`)}function Je(){let e=process.env.CC_CANDYBAR_DAEMON_REGISTRY_DIR;if(e)return e;let t=h.userInfo().uid;return l.join(`/tmp`,`cc-candybar-${t}`,`daemons`)}function Ye(){return l.join(Le(),`spawn.lock`)}function Xe(){return l.join(Le(),`spawn.cooldown`)}function Ze(){return l.join(Le(),`spawn.backoff`)}function Qe(){return l.join(Le(),`diagnostics`)}function $e(e=process.env){return l.join(Le(e),`daemon.log`)}const et=[`MEMENTO_CONFIG_HOME`,`XDG_CONFIG_HOME`];function tt(e,t){return Object.fromEntries(et.flatMap(n=>{let r=e[n]??``;return r===``?[]:[[n,l.resolve(t,r)]]}))}const nt=Object.keys({termCols:!0,termRows:!0,ssh:!0,tmux:!0,configEnv:!0,claudeConfigDir:!0,mementoEnv:!0});function rt(e){let t=ut(e.termCols),n=ut(e.termRows),r=dt(e.ssh),i=ct(e.tmux),a=st(e.configEnv),o=st(e.claudeConfigDir),s=ot(e.mementoEnv);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&&{mementoEnv:s}}}function it(e,t){return nt.filter(n=>e[n]!==void 0&&t[n]===void 0).map(t=>({hint:t,sent:e[t]}))}function at(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).`}function ot(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=e,n=et.filter(e=>t[e]!==void 0);return n.every(e=>st(t[e])!==void 0)?Object.fromEntries(n.map(e=>[e,t[e]])):void 0}function st(e){return typeof e==`string`&&l.isAbsolute(e)?e:void 0}function ct(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 lt=1e4;function ut(e){if(typeof e!=`number`||!Number.isFinite(e))return;let t=Math.floor(e);if(!(t<=0))return t>lt?lt:t}function dt(e){return typeof e==`boolean`?e:void 0}function ft(e){return typeof e==`string`&&e!==``&&e.length<=64?e:null}var pt=class extends Error{constructor(e){super(e),this.name=`ProtocolError`}};function mt(e){let t=Buffer.from(JSON.stringify(e),`utf8`),n=Buffer.alloc(4);return n.writeUInt32BE(t.length,0),Buffer.concat([n,t])}function ht(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 pt(`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 pt(e instanceof Error?e.message:String(e));e instanceof Error&&(n.cause=e),t(n);return}}}}function gt(e,t,n){return new Promise((r,i)=>{let a=!1,o=t=>{if(!a){a=!0,clearTimeout(s),e.removeAllListeners();try{t()}catch{}}},s=setTimeout(()=>{o(()=>{e.destroy(),i(Error(`TIMEOUT`))})},n),c=ht(e=>o(()=>r(e)),e=>o(()=>i(e)));e.on(`data`,c),e.on(`error`,e=>o(()=>i(e))),e.on(`close`,()=>o(()=>i(Error(`socket closed before response`)))),e.write(mt(t))})}async function _t(e,t,n){let r=null;try{r=await St(Be(),t.connectMs);let i=await gt(r,{v:3,...e},t.budgetMs);return bt(e.kind,i,n)}catch(e){return xt(e)}finally{r&&r.destroy()}}function vt(e,t){return typeof e==`string`?e:t}function yt(e){return typeof e==`number`&&Number.isInteger(e)&&e>=0?e:0}function bt(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=vt(r.error,`(no error message)`);switch(r.code){case`VERSION_MISMATCH`:return{kind:`permanent`,cause:`version_mismatch`,clientV:3,daemonV:yt(r.daemonV)};case`TIMEOUT`:return{kind:`transient`,cause:`timeout`,message:i};case`BAD_REQUEST`:return{kind:`permanent`,cause:`bad_request`,message:i};case`RENDER_FAILED`:return{kind:`permanent`,cause:`render_failed`,message:i};default:return{kind:`permanent`,cause:`malformed_response`,message:`unknown error code: ${String(r.code)}`}}}function xt(e){if(e instanceof pt||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 t===`CONNECT_TIMEOUT`||t===`TIMEOUT`?{kind:`transient`,cause:`timeout`,message:t}:t.includes(`ECONNREFUSED`)||t.includes(`ENOENT`)||t.includes(`ENOTSOCK`)?{kind:`transient`,cause:`unreachable`,message:t}:{kind:`transient`,cause:`io_error`,message:t}}function St(e,t){return new Promise((n,r)=>{let i=S.createConnection({path:e}),a=setTimeout(()=>{i.destroy(),r(Error(`CONNECT_TIMEOUT`))},t);i.once(`connect`,()=>{clearTimeout(a),n(i)}),i.once(`error`,e=>{clearTimeout(a),r(e)})})}function Ct(e){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`malformed_response`:return`daemon error (${e.cause}): ${e.message}`}}const wt=`1.132.0`,Tt={connectMs:50,budgetMs:150},Et={connectMs:50,budgetMs:200};function Dt(e){let t=e.output;return typeof t==`string`?t:void 0}function Ot(e,t,n,r){return _t({kind:`render`,hookData:e,args:t,cwd:n,...r},Tt,Dt)}function kt(e,t){return _t({kind:`click`,verb:e,value:t,clientVersion:wt},Et,Dt)}let At=null;function jt(e){if(At!==null)return At;r.mkdirSync(l.dirname(e),{recursive:!0});try{At=r.statSync(e).size}catch{At=0}return At}function Mt(e){for(let t=2;t>=1;t--){let n=`${e}.${t}`,i=`${e}.${t+1}`;try{r.renameSync(n,i)}catch{}}try{r.renameSync(e,`${e}.1`)}catch{}At=0}const Nt=(e,t)=>D(t);function k(e,t){let n=`${new Date().toISOString()} [${e}] ${t}\n`;try{let e=$e(),t=jt(e);r.appendFileSync(e,n),At=t+Buffer.byteLength(n,`utf8`),At>=5242880&&Mt(e)}catch(e){At=null;try{process.stderr.write(`${n}cc-candybar: daemon.log unwritable: ${e.message}\n`)}catch{}}}function Pt(e){let t=[];for(let n of e){let e=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(`
3
3
  `)}function Ft(e,t){return e===`darwin`?[A(`footprint`,[`-p`,String(t)]),A(`vmmap`,[`--summary`,String(t)])]:e===`linux`?[It(`/proc/self/smaps_rollup`),It(`/proc/self/status`)]:[]}function A(e,t){return{name:`${e} ${t.join(` `)}`,read:()=>{let n=Me({bin:e,args:[...t],timeoutMs:5e3,category:`limits.memory-report`});return n.ok?n.stdout.trim().length>0?{kind:`text`,text:n.stdout}:{kind:`unavailable`,reason:`exited 0 but printed nothing`}:{kind:`unavailable`,reason:`${n.reason}${n.error===void 0?``:`: ${n.error}`}${j(n.stderr)}`}}}}function It(e){return{name:e,read:()=>{try{let t=r.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}}}}}function j(e){let t=e.split(`
4
4
  `).map(e=>e.trim()).find(e=>e.length>0);return t===void 0?``:` (${t})`}const Lt=`CC_CANDYBAR_RSS_LIMIT_MB`;function Rt(e){let t=e[Lt];if(t===void 0)return 512;let n=/^\d+$/.test(t)?Number(t):NaN;if(!Number.isSafeInteger(n)||n<=0)throw Error(`${Lt} must be a positive integer (MB), got ${JSON.stringify(t)}`);return n}function zt(e){return Rt(e)*2}const Bt=1024*1024;function Vt(e){return Rt(e)*Bt}const Ht={memoryReport:{prefix:`memory-`,suffix:`.txt`},heapSnapshot:{prefix:`heap-`,suffix:`.heapsnapshot`}};function Ut(e,t,n){let{prefix:r,suffix:i}=Ht[t];return l.join(e,`${r}${n}${i}`)}function Wt(e){for(let t of Object.keys(Ht)){let{prefix:n,suffix:r}=Ht[t];if(e.startsWith(n)&&e.endsWith(r))return t}return null}function Gt(e){let t=e.rssLimitBytes??512*Bt,n=e.snapshotsKeep??3,r=!1;function i(){if(r)return!0;let{rss:i,heapTotal:a}=e.memoryBytes();if(i<=t)return!1;r=!0,e.log(`warn`,`RSS ${i} > limit ${t} (v8 heap ${a}); recording memory then shutting down`);let o=`${new Date(e.now()).toISOString().replace(/[:.]/g,`-`)}-${e.pid}`;return Kt(e.log,`memory report`,()=>{let t=Ut(e.snapshotDir,`memoryReport`,o);e.writeMemoryReport(t,e.captureMemoryReport()),e.log(`info`,`memory report written: ${t}`)}),Kt(e.log,`heap snapshot`,()=>{let t=Ut(e.snapshotDir,`heapSnapshot`,o);e.log(`info`,`heap snapshot written: ${e.writeHeapSnapshot(t)}`)}),Kt(e.log,`artifact rotation`,()=>{Jt(e.listArtifacts(),n,e.removeFile)}),e.shutdown(0),!0}function a(){let{rss:n,heapTotal:r}=e.memoryBytes();return n>t*.75?`rss ${n} approaching limit ${t} (v8 heap ${r})`:null}function o(e=6e4){let t=setInterval(()=>{i()},e);return t.unref(),{disarm:()=>clearInterval(t)}}return{checkRss:i,describeNextRestart:a,arm:o}}function Kt(e,t,n){try{n()}catch(n){e(`warn`,`${t} failed: ${n.message}`)}}function qt(e){let t=e.slice(e.lastIndexOf(`/`)+1),n=Wt(t);if(n===null)return t;let{prefix:r,suffix:i}=Ht[n];return t.slice(r.length,t.length-i.length)}function Jt(e,t,n){let r=new Map;for(let t of e){let e=qt(t),n=r.get(e);n===void 0?r.set(e,[t]):n.push(t)}let i=[...r.keys()].sort((e,t)=>t.localeCompare(e));for(let e of i.slice(t))for(let t of r.get(e)??[])try{n(t)}catch{}}function Yt(e,t,n={}){let i=ze();return{now:()=>Date.now(),pid:process.pid,snapshotDir:i,log:k,memoryBytes:()=>{let e=process.memoryUsage();return{rss:e.rss,heapTotal:e.heapTotal}},captureMemoryReport:()=>Pt(Ft(process.platform,process.pid)),writeMemoryReport:(e,t)=>r.writeFileSync(e,t,{mode:384}),writeHeapSnapshot:e=>C.writeHeapSnapshot(e),listArtifacts:()=>{try{return r.readdirSync(i).filter(e=>Wt(e)!==null).map(e=>l.join(i,e))}catch{return[]}},removeFile:e=>r.unlinkSync(e),shutdown:t,startedAtMs:e,...n}}function Xt(e={}){if(fn()!==null)return;let n=e.spawn??pn,r=ln();if(r.kind===`contended`){let e=Qt();e!==null&&e>2e3&&(t.stderr.write(`cc-candybar: spawn-lock held ${e}ms (likely crashed holder) — spawning unlocked\n`),Zt(n));return}if(r.kind===`error`){t.stderr.write(`cc-candybar: spawn-lock unavailable (${r.reason}) — spawning unlocked\n`),Zt(n);return}try{Zt(n)}finally{dn()}}function Zt(e){an()&&$t(e)}function Qt(){try{let e=r.statSync(Ye());return Date.now()-e.mtimeMs}catch{return null}}function $t(e){try{e()||t.stderr.write(`cc-candybar: daemon spawn returned false (unable to resolve script path?)
5
5
  `)}catch(e){t.stderr.write(`cc-candybar: daemon spawn failed: ${e.message}\n`)}}function en(e,t){return e===null?{kind:`allow`}:e<-1e4?{kind:`allow-future-garbage`,futureMs:-e}:e<t?{kind:`deny`}:{kind:`allow`}}function tn(e){return Math.min(3e3*2**Math.min(Math.max(e,0),5),6e4)}function nn(e){try{let t=r.readFileSync(e,`utf8`).trim(),n=Number(t);return!Number.isInteger(n)||n<0?0:Math.min(n,5)}catch{return 0}}function rn(e,n){try{r.mkdirSync(l.dirname(e),{recursive:!0}),r.writeFileSync(e,String(n),{mode:384})}catch(e){t.stderr.write(`cc-candybar: could not record spawn.backoff: ${e.message}\n`)}}function M(){try{r.unlinkSync(Ze())}catch(e){e.code!==`ENOENT`&&t.stderr.write(`cc-candybar: could not reset spawn.backoff: ${e.message}\n`)}}function an(){let e=Xe(),n=Ze(),r=nn(n),i=en(on(e),tn(r));return i.kind===`deny`?!1:(i.kind===`allow-future-garbage`&&t.stderr.write(`cc-candybar: spawn.cooldown mtime is ${i.futureMs}ms in the future — ignoring and spawning\n`),sn(e),rn(n,Math.min(r+1,5)),!0)}function on(e){try{return Date.now()-r.statSync(e).mtimeMs}catch{return null}}function sn(e){try{r.mkdirSync(l.dirname(e),{recursive:!0}),r.writeFileSync(e,`${t.pid} ${Date.now()}\n`,{mode:384})}catch(e){t.stderr.write(`cc-candybar: could not record spawn.cooldown: ${e.message}\n`)}}let cn=null;function ln(){let e=Ye();for(let n=0;n<2;n++){try{let n=r.openSync(e,`wx`,384);try{r.writeSync(n,JSON.stringify({pid:t.pid,ts:Date.now()}))}catch{}return cn={fd:n,path:e},{kind:`held`}}catch(t){let n=t.code;if(n!==`EEXIST`)return{kind:`error`,reason:`openSync(${e}): ${n??t.message}`}}if(!un(e))return{kind:`contended`};try{r.unlinkSync(e)}catch(e){if(e.code!==`ENOENT`)return{kind:`error`,reason:`unlink stale spawn.lock: ${e.message}`}}}return{kind:`contended`}}function un(e){try{let t=r.statSync(e);return Date.now()-t.mtimeMs>1e4}catch{return!0}}function dn(){if(!cn)return;let{fd:e,path:t}=cn;cn=null;try{r.closeSync(e)}catch{}try{r.unlinkSync(t)}catch{}}function fn(){try{return r.mkdirSync(ze(),{recursive:!0}),null}catch(e){return`mkdir ${ze()}: ${e.message}`}}function pn(){let e=t.execPath,n=t.argv[1];return n?Ne({bin:e,args:[`--max-old-space-size=${zt(t.env)}`,n,`daemon`],category:`daemon-spawn`}).ok:!1}const mn=`cc-candybar`,hn=`dispatch`,gn=`set-state`,N=`step-state`,_n=`copy`,vn=`open-vscode`,yn=`toolbar-toggle`,bn=`show-config-error`,xn=`show-config-warning`,Sn=`set-config`,Cn=`step-config`,wn=`save`,P=`save-preset`,Tn=`save-theme-default`,En=`delete-preset`,Dn=`reset-config`,On=`apply-layout-op`,kn=`undo`,An=`redo`,jn=`back`,Mn=`rewind`,Nn=`apply-update`,Pn=`doctor-run`,Fn=`doctor-fix`,In=`doctor-probe`,Ln=`ceiling`,Rn=`slash`;function F(e){return e.map(encodeURIComponent).join(`/`)}function zn(e){return e.length===0?[]:e.split(`/`).map(decodeURIComponent)}function I(e){return`${mn}://${hn}/${e.map(e=>`e=${encodeURIComponent(`${e.verb}/${F(e.args)}`)}`).join(`&`)}`}function Bn(e){return new te(e).getAll(`e`).map(Wn)}const Vn=new Set([gn,Dn]);function Hn(e){return e.reduce((e,t)=>{let n=e.at(-1),r=n&&Un(n,t);return r?[...e.slice(0,-1),r]:[...e,t]},[])}function Un(e,t){if(e.verb!==t.verb||!Vn.has(e.verb))return;let[n,r]=[Wn(e.value),Wn(t.value)];return n.verb===r.verb?{verb:e.verb,value:`${n.verb}/${n.value}/${r.value}`}:void 0}function Wn(e){let t=e.indexOf(`/`);return t===-1?{verb:e,value:``}:{verb:e.slice(0,t),value:e.slice(t+1)}}const L=`closed`,Gn=`🍫`;function Kn(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 qn(e,t,n,r){let i=Kn(e,t.length,n);if(i!==void 0)throw Error(i);return t.length===1?t[0]:t[r]}function Jn(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}function Yn(e,t,n,r,i){return{kind:`segment`,name:e,opens:{ref:t,body:n,placement:r},...i!==void 0&&{when:i}}}function Xn(e,...t){return`{{ and ${[e,...t].map(Zn).join(` `)} }}`}function Zn(e){return`(eq .${e.variable} "${Jn(e.member)}")`}function Qn(e,t,n){return`{{ ${$n(e,er(t),er(n))} }}`}function $n(e,t,n){return`action "${e}" ${t} ${n}`}function er(e){return`"${Jn(e)}"`}function tr(e,t){return{kind:`state`,key:e,default:t}}function nr(e,t){return{set:e,cycle:[L,t]}}const rr=/^[A-Za-z0-9_./,:@%+-][A-Za-z0-9_./,:@%+=-]*$/;function ir(e){return`'${e.replaceAll(`'`,`'\\''`)}'`}function ar(e){return rr.test(e)?e:ir(e)}var or=ye(((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]/})),sr=ye(((e,t)=>{let n=or();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)}}})),cr=ye(((e,t)=>{let n=sr(),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(),re[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===`
@@ -53,7 +53,7 @@ import{createRequire as e}from"node:module";import t from"node:process";import{j
53
53
  `))throw Error(`renderStripCells: rich-js strip output did not end its last line`);return s.slice(0,-1)}function Om(e){return Math.min(20,e??20)}const km={heading:`ERROR`,glyph:`⚠`,colors:qd},Am={heading:`WARNING`,glyph:`⚠`,colors:Jd},jm={heading:`UPDATE`,glyph:`⬆`,colors:Jd};function Mm(e,t){return{text:Hd(e),link:t}}function Nm(e,t,n){let[r,...i]=[Pm(e,km,bn),t,Pm(n,Am,xn)].flat();return r===void 0?null:{channels:[r,...i]}}function Pm(e,t,n){let r=I([{verb:n,args:[e]}]),[i,...a]=e.split(/\r\n|\r|\n/).map(e=>Mm(e,r)).filter(e=>e.text!==``).map(e=>[e]);return i===void 0?[]:[{severity:t,message:e,lines:[i,...a]}]}function Fm(e){return e.channels.map(e=>`${e.severity.heading}\n${e.message}\n`).join(`
54
54
  `)}function Im(e,t,n,r){if(t===null)return e;let i=Lm(r),a=t.channels.flatMap(e=>Rm(e,i)),o=n.failedConfigFile!==null||a.length>r.rowCap,s=a.slice(0,r.rowCap-Number(o)),c=o?[zm(t,n,a.length-s.length,i)]:[],l=[...s,...c].join(`
55
55
  `);return e?`${l}\n${e}`:l}function Lm(e){return{endcaps:`plain`,separator:``,width:e.width,wrap:!0,padding:0,charset:`unicode`,colorCompatibility:e.colorCompatibility}}function Rm(e,t){let n=new G({bgcolor:e.severity.colors.bg,color:e.severity.colors.fg}),r=co(Math.max(2,t.width-1)),i=(e,t)=>new q(`${e} `,{style:t,end:``,overflow:`ignore`});return e.lines.flatMap((a,o)=>Dm([i(o===0?e.severity.glyph:` `,n.withLink(a[0].link)),...a.flatMap(e=>{let t=n.withLink(e.link);return e.text.split(` `).flatMap(e=>mo(e,r)).map(e=>i(e,t))})],t).split(`
56
- `))}function zm(e,t,n,r){let{colors:i}=e.channels[0].severity,{fullText:a,failedConfigFile:o}=t,s=new G({bgcolor:i.bg,color:i.fg}),c=(e,t)=>new q(e,{style:t,end:``,overflow:`ignore`}),l=n>0?[c(`${n} more rows · `,s),a.kind===`file`?c(`open full text`,s.withLink(re(a.path).href)):c(`full text unavailable: ${Hd(a.reason)}`,s)]:[],u=o===null?[]:[c(`${l.length>0?` · `:``}open `,s),c(Hd(o),s.withLink(re(o).href))],d=[c(`↳ `,s),...l,...u.slice(0,-1)],f=d.reduce((e,t)=>e+t.cellLength,0),p=u.slice(-1).map(e=>e.truncate(Math.max(1,r.width-f),{mode:`middle`})),m=q.fromFragments([...d,...p]).truncate(r.width);return m.overflow=`ignore`,Dm([m],r)}const Bm=e=>!e.startsWith(`.`)&&!e.endsWith(`~`);function Vm(e,t){return t.isSymbolicLink()?Buffer.from(r.readlinkSync(e)):r.readFileSync(e)}function Hm(e,t){return r.readdirSync(t).filter(Bm).sort().flatMap(n=>{let i=l.join(t,n),a=r.lstatSync(i,{throwIfNoEntry:!1});return a===void 0?[]:a.isDirectory()?Hm(e,i):[[l.relative(e,i).split(l.sep).join(`/`),Vm(i,a)]]})}function Um(e){let t=ie.createHash(`sha256`);for(let[n,r]of Hm(e,e))t.update(n).update(`\0`).update(r).update(`\0`);return t.digest(`hex`)}const Wm=e=>e.slice(0,7);function Gm(e){return l.dirname(l.dirname(e))}function Km(){return{version:wt,digest:`4403324d4363a3f0dff73df8f6fb3c0e69e7dd8cb4e3d166c45a674b41d6c03e`}}function qm(e){let t=JSON.parse(r.readFileSync(l.join(e,`package.json`),`utf8`)),n=typeof t==`object`&&t?t.version:void 0;if(typeof n!=`string`)throw Error(`${l.join(e,`package.json`)} has no version string`);return n}function Jm(e,t){try{let n=Gm(ne(e)),i=l.join(n,`src`);if(!r.existsSync(i))return{kind:`not-source-checkout`};let a=t(),o=Um(i);return o===a.digest?{kind:`current`,root:n,stamp:a}:{kind:`stale`,root:n,source:{version:qm(n),digest:o},running:a}}catch(e){return{kind:`unchecked`,reason:e.message}}}var J=class extends Error{constructor(e){super(e),this.name=`BadVerbArgs`}};const Ym=new Map;function Xm(e){let t=Qm(e);if(t===null)throw Error(`Palette "${e}" did not resolve in the theme registry — allowed names and the registry are inconsistent`);return t}function Zm(e,t){return e===`bar`?t:Xm(e)}function Qm(e){let t=Ym.get(e);if(t!==void 0)return t;let n=Sc(e);return n===null?null:(Ym.set(e,n),n)}function $m(e,t){return eh(e,`${t.hueShift} ${t.chromaScale} ${t.lightnessScale} ${t.lightnessShift}`,()=>Pc(e,t))}const eh=Yd();function th(e){let t=Qm(e);return t===null?null:{kind:`decided`,name:e,value:t}}function nh(e,t,n){let r=th(e);return r===null?(n(Tp(t,`palette`,`"${e}" names no installed theme${sp(e)}`)),ih()):r}function rh(e,t,n){return _p(e,t,n,ih(),th)}function ih(){return{kind:`decided`,name:cp,value:Xm(cp)}}const ah=[`vertical`,`horizontal`],oh={vertical:`row`,horizontal:`cell`};function sh(e){return e.id??e.name}function ch(e){return[...dh(e)].flatMap(e=>e.kind===`segment`?[sh(e)]:[])}function lh(e,t){if(!t.has(e))return e;let n=2;for(;t.has(`${e}-${n}`);)n++;return`${e}-${n}`}function uh(e,t){return e.opens===void 0?e:{...e,opens:{...e.opens,body:t(e.opens.body)}}}function*dh(e){yield e;for(let t of hh(e))yield*dh(t)}const fh=(e,t)=>`${e}.children[${t}]`,ph=e=>`${e}.opens.body`;function*mh(e,t){if(yield[e,t],e.kind===`container`)for(let[n,r]of e.children.entries())yield*mh(r,fh(t,n));else e.opens!==void 0&&(yield*mh(e.opens.body,ph(t)))}function hh(e){return e.kind===`container`?e.children:e.opens===void 0?[]:[e.opens.body]}const gh=[`shade`,`variation`,`style`];function _h(e){return e===void 0||`text`in e?`text`:`regex`in e?`regex`:`json`}const vh=[`ttl`,`watch_file`,`depends_on`,`key`,`never`];function yh(e){return e.kind===`file`||e.kind===`shell`||e.kind===`template`}const bh=[`branch`,`sha`,`dirty`,`ahead`,`behind`,`stash`],xh=`theme`,Sh=`effect`,Ch=[xh,Sh];function wh(e){return{...e.settings,[xh]:{label:xh,domain:`theme`,default:e.palette??`bar`},[Sh]:{label:Sh,domain:Dp,default:`bar`}}}function Th(e){let t=e?.domain;return typeof t==`object`&&`min`in t?t:void 0}function Eh(e,t){return Object.entries(e).flatMap(([n,r])=>{let i=Th(r)?.atLeast;if(i===void 0)return[];let a=t[n],o=t[i];return a>=o?[]:[{setting:n,message:`"${n}" (${a}) is below "${i}" (${o}) — ${r.label} must be at least ${e[i].label}`}]})}function Dh(e,t){let{domain:n}=e;return n===`bool`?typeof t==`boolean`:n===`theme`?typeof t==`string`&&pp(t):`min`in n?typeof t==`number`&&Number.isInteger(t)&&t>=n.min&&t<=n.max:typeof t==`string`&&n.includes(t)}function Oh(e){return String(e)}function kh(e,t){let{domain:n}=e;if(typeof n==`object`&&`min`in n)return Qp(t,n)??void 0;let r=n===`bool`?t===`true`?!0:t===`false`?!1:t:t;return Dh(e,r)?r:void 0}function Ah(e,t,n,r){let i=e.settings?.[t]??n.default,a=e.drafts?.[t],o=a===void 0?null:r(a);return(o===null?void 0:kh(n,o))??i}function jh(e){let{domain:t}=e;return t===`bool`?`true or false`:t===`theme`?`"bar" (the bar's own theme) or an installed theme name`:`min`in t?`an integer from ${t.min} to ${t.max}`:`one of ${t.map(e=>JSON.stringify(e)).join(`, `)}`}const Mh=[`left`,`center`,`right`],Nh=[`right`,`left`,`middle`],Ph=/^[A-Za-z_][A-Za-z0-9_]*$/;function Fh(e){return`#${e+1}`}const Ih={rows:{}};function Lh(e){return`rows`in e}function Rh(e){return Object.fromEntries(e.map((e,t)=>[Fh(t),e]))}function zh(e){if(e.kind===`container`&&e.direction===`vertical`){let{kind:t,direction:n,children:r,...i}=e;return{...i,rows:Rh(r)}}let{when:t,...n}=e;return{...t!==void 0&&{when:t},rows:Rh([n])}}function Bh(e){let{rows:t,...n}=e;return{kind:`container`,direction:`vertical`,children:Object.values(t),...n}}function Vh(e){return Lh(e)?Bh(e):e}function*Hh(e,t){if(!Lh(e)){yield*mh(e,t);return}yield[Bh(e),t];for(let[n,r]of Object.entries(e.rows))yield*mh(r,`${t}.rows.${n}`)}function Uh(e,t){return Lh(e)?{...t,...e,rows:{...t.rows,...e.rows}}:zh(e)}function Wh(e){if(!Lh(e))return!0;let{rows:t,...n}=e;return Object.values(n).some(e=>e!==void 0)||Object.keys(t).length>0}const Gh=`default`,Kh={};function qh(e){return[...new Set([Gh,...Object.keys(e)])]}function Jh(e,t,n){return mp(void 0,e,t,Gh,n)}function Yh(e,t){let n={[Gh]:Kh,...e}[t];if(n===void 0)throw Error(`Preset "${t}" is not declared in this config — effectivePresetName collapses unknown names to "${Gh}", which always resolves; a miss here means a raw name reached this function without going through that resolution`);return n}function Xh(e,t){let n=Yh(e.presets,t).root??Ih;return{node:Bh(Uh(n,e.root)),path:Wh(n)?`presets.${t}.root`:`root`}}function Zh(e,t){return{...e.globals,...Yh(e.presets,t).globals}}const Qh=new Map;function $h(e,t,n){Qh.set(e,{permanent:!0,resolve:t,paletteOf:n})}$h(`themes`,()=>up(),e=>Xm(e));const eg=`placementThemes`;$h(eg,dp,(e,t)=>Zm(e,t.palette)),$h(`endcaps`,()=>jp),$h(`variations`,()=>Vp),$h(`shades`,()=>Wp),$h(`charsets`,()=>Ip),$h(`colorCompatibilities`,()=>zp);function tg(e){return new Map([[`styles`,{members:Object.keys(e.styles),paletteOf:(t,n)=>$m(n.basePalette,e.styles[t])}],[`presets`,{members:qh(e.presets)}]])}function ng(e){return[...new Set([...Qh.keys(),...e.keys()])]}function rg(e,t){if(typeof e!=`string`)return{members:e};let n=t.get(e);if(n)return n;let r=Qh.get(e);if(r)return{members:r.resolve(),paletteOf:r.paletteOf};throw Error(ag(e,t))}const ig=new Map([[`looks`,`styles`],[`progressions`,`variations`]]);function ag(e,t){let n=ig.get(e);return`unknown option domain "${e}"${n===void 0?``:` — it was renamed "${n}"; write from: "${n}"`} (have: ${ng(t).join(`, `)})`}const og=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`[^`]*`/g;function*sg(e){let t=e.indexOf(`{{`);for(;t!==-1;){let n=``,r=t+2;for(;r<e.length&&!e.startsWith(`}}`,r);){if(e.startsWith(`/*`,r)){let t=e.indexOf(`*/`,r+2);r=t===-1?e.length:t+2;continue}let t=r,i=e[r];if(r+=1,i===`"`||i===`'`||i==="`"){for(;r<e.length&&e[r]!==i;)r+=e[r]===`\\`&&i!=="`"?2:1;r+=1}n+=e.slice(t,r)}if(r>=e.length)return;yield n,t=e.indexOf(`{{`,r+2)}}const cg=`[A-Za-z_]\\w*(?:\\.[A-Za-z_]\\w*)*`,lg=RegExp(`^(?:(\\$)(?:\\.(${cg}))?|\\.(${cg})?)(?=[\\s)]|$)`);function ug(e,t,n){let r=lg.exec(e.trimStart());if(r===null)return null;let[i,a]=r[1]===void 0?[t,r[3]]:[n,r[2]];return i===null?null:a===void 0?i:`${i}${a}.`}const dg=/^(\w+)\b\s*([\s\S]*)$/;function*fg(e,t){let n=[t];for(let r of sg(e)){let e=r.replace(/^-(?=\s)/,``).trim(),[,i=``,a=``]=dg.exec(e)??[],o=n[n.length-1],s=n.length>1?n[n.length-2]:o;if(i===`end`){n.length>1&&n.pop();continue}if(i===`else`){yield{code:e,dot:s};let r=/^with\b([\s\S]*)$/.exec(a);n[n.length-1]=r===null?s:ug(r[1],s,t);continue}yield{code:e,dot:o},i===`if`&&n.push(o),i===`with`&&n.push(ug(a,o,t)),(i===`range`||i===`define`||i===`block`)&&n.push(null)}}const pg=/(?<![.$])\btemplate\s+$/;function*mg(e,t,n){let r=0;for(let i of[...e.matchAll(og)]){let a=i.index+i[0].length;pg.test(e.slice(r,i.index))&&(yield{name:i[0].slice(1,-1),at:ug(e.slice(a),t,n)}),r=a}}function*hg(e,t){let n=new Set;function*r(e,i,a,o){for(let{code:s,dot:c}of[...fg(e,i)]){yield{code:s,dot:c,root:i,via:a};for(let e of[...mg(s,c,i)]){let i=Object.hasOwn(t,e.name)?t[e.name]:void 0,a=`${e.name}\0${e.at??`\0`}`;i===void 0||o.has(e.name)||n.has(a)||(n.add(a),yield*r(i,e.at,e.name,new Set([...o,e.name])))}}}yield*r(e,``,null,new Set)}const gg=RegExp(`(?<![A-Za-z0-9_)$])(\\$?)\\.(${cg})`,`g`);function*_g({code:e,dot:t,root:n}){let r=e.replace(og,``);for(let e of[...r.matchAll(gg)]){let r=e[1]===`$`?n:t;r!==null&&(yield`${r}${e[2]}`)}}function vg(e,t){let n=new Map;for(let r of hg(e,t))for(let e of _g(r))n.has(e)||n.set(e,r.via);return n}const yg=/(?<![.$])\b(action|picker|menu|carousel|swatches|swatch|themePreview)\s+$/,bg={action:1,picker:2,menu:1,carousel:2,swatch:1,swatches:2,themePreview:1};function*xg(e){let t=0,n=0,r=0,i=`action`;for(let a of[...e.matchAll(og)]){let o=e.slice(t,a.index),s=yg.exec(o);if(s!==null)n=bg[s[1]],r=0,i=s[1]===`action`?`action`:`options`;else for(let e of o)e===`(`&&r++,e===`)`&&r--,(r<0||e===`|`&&r===0)&&(n=0);n>0&&r===0&&(yield{name:a[0].slice(1,-1),site:i},n--),t=a.index+a[0].length}}function Sg(e,t){let n=new Map;for(let{code:r,via:i}of hg(e,t))for(let{name:e,site:t}of xg(r)){let r=`${e}\0${i??`\0`}`;n.has(r)||n.set(r,{name:e,site:t,via:i})}return[...n.values()]}function Cg(e,t){return new Set([...wg(e,t)].filter(e=>Object.hasOwn(t,e)))}function wg(e,t){let n=new Set;for(let{code:r,dot:i,root:a}of hg(e,t))for(let{name:e}of mg(r,i,a))n.add(e);return n}function Tg(e,t){if(t.names.has(e))return!0;let n=`${e}.`;for(let e of t.names)if(e.startsWith(n))return!0;for(let n of t.documents)if(e.startsWith(`${n}.`))return!0;return!1}function Eg(e){let t=new Set,n=new Set,r=(e,r)=>{t.add(e),Dg(r)&&n.add(e)};for(let[t,n]of Object.entries(e.variables))r(t,n);for(let[t,n]of Object.entries(e.segments))for(let[e,i]of Object.entries(n.vars??{}))r(`${t}.${e}`,i);return{names:t,documents:n,helpers:e.helpers}}function Dg(e){return e.kind===`dropped`||(e.kind===`shell`||e.kind===`file`)&&_h(e.parse)===`json`}function Og(e){let t=l.basename(e),n=l.dirname(e);for(;;){let r=kg(n);if(r!==null)return{dir:r,name:t,leaf:n===l.dirname(e)};t=l.basename(n),n=l.dirname(n)}}function kg(e){try{return r.statSync(e).isDirectory()?r.realpathSync(e):null}catch{return null}}var Ag=ye((e=>{function t(e){var t=[...arguments].slice(1);throw Error(typeof e==`number`?`[MobX] minified error nr: `+e+(t.length?` `+t.map(String).join(`,`):``)+`. Find the full error at: https://github.com/mobxjs/mobx/blob/main/packages/mobx/src/errors.ts`:`[MobX] `+e)}function n(){return typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:rn}function r(){un||t(`Proxy not available`)}function i(e){var t=!1;return function(){if(!t)return t=!0,e.apply(this,arguments)}}function a(e){return typeof e==`function`}function o(e){switch(typeof e){case`string`:case`symbol`:case`number`:return!0}return!1}function s(e){return typeof e==`object`&&!!e}function c(e){if(!s(e))return!1;var t=Object.getPrototypeOf(e);if(t==null)return!0;var n=Object.hasOwnProperty.call(t,`constructor`)&&t.constructor;return typeof n==`function`&&n.toString()===dn}function l(e){var t=e?.constructor;return!!t&&(t.name===`GeneratorFunction`||t.displayName===`GeneratorFunction`)}function u(e,t,n){on(e,t,{enumerable:!1,writable:!0,configurable:!0,value:n})}function d(e,t,n){on(e,t,{enumerable:!1,writable:!1,configurable:!0,value:n})}function f(e,t){var n=`isMobX`+e;return t.prototype[n]=!0,function(e){return s(e)&&!0===e[n]}}function p(e){return e!=null&&Object.prototype.toString.call(e)===`[object Map]`}function m(e){return e!=null&&Object.prototype.toString.call(e)===`[object Set]`}function h(e){return e===null?null:typeof e==`object`?``+e:e}function g(e,t){return sn.hasOwnProperty.call(e,t)}function _(e,t){return!!(e&t)}function v(e,t,n){return n?e|=t:e&=~t,e}function y(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function b(e,t,n){if(re())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,t);var i=new(e.bind.apply(e,r));return n&&ie(i,n.prototype),i}function x(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,ae(r.key),r)}}function S(e,t,n){return t&&x(e.prototype,t),n&&x(e,n),Object.defineProperty(e,`prototype`,{writable:!1}),e}function C(e,t){var n=typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if(typeof e==`string`)return y(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?y(e,t):void 0}}(e))||t&&e&&typeof e.length==`number`){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw TypeError(`Invalid attempt to iterate non-iterable instance.
56
+ `))}function zm(e,t,n,r){let{colors:i}=e.channels[0].severity,{fullText:a,failedConfigFile:o}=t,s=new G({bgcolor:i.bg,color:i.fg}),c=(e,t)=>new q(e,{style:t,end:``,overflow:`ignore`}),l=n>0?[c(`${n} more rows · `,s),a.kind===`file`?c(`open full text`,s.withLink(re(a.path).href)):c(`full text unavailable: ${Hd(a.reason)}`,s)]:[],u=o===null?[]:[c(`${l.length>0?` · `:``}open `,s),c(Hd(o),s.withLink(re(o).href))],d=[c(`↳ `,s),...l,...u.slice(0,-1)],f=d.reduce((e,t)=>e+t.cellLength,0),p=u.slice(-1).map(e=>e.truncate(Math.max(1,r.width-f),{mode:`middle`})),m=q.fromFragments([...d,...p]).truncate(r.width);return m.overflow=`ignore`,Dm([m],r)}const Bm=e=>!e.startsWith(`.`)&&!e.endsWith(`~`);function Vm(e,t){return t.isSymbolicLink()?Buffer.from(r.readlinkSync(e)):r.readFileSync(e)}function Hm(e,t){return r.readdirSync(t).filter(Bm).sort().flatMap(n=>{let i=l.join(t,n),a=r.lstatSync(i,{throwIfNoEntry:!1});return a===void 0?[]:a.isDirectory()?Hm(e,i):[[l.relative(e,i).split(l.sep).join(`/`),Vm(i,a)]]})}function Um(e){let t=ie.createHash(`sha256`);for(let[n,r]of Hm(e,e))t.update(n).update(`\0`).update(r).update(`\0`);return t.digest(`hex`)}const Wm=e=>e.slice(0,7);function Gm(e){return l.dirname(l.dirname(e))}function Km(){return{version:wt,digest:`2941d27c49ca155d5e06371252702f03e72b58a6ce2b927c620bfb8c5e8b40c2`}}function qm(e){let t=JSON.parse(r.readFileSync(l.join(e,`package.json`),`utf8`)),n=typeof t==`object`&&t?t.version:void 0;if(typeof n!=`string`)throw Error(`${l.join(e,`package.json`)} has no version string`);return n}function Jm(e,t){try{let n=Gm(ne(e)),i=l.join(n,`src`);if(!r.existsSync(i))return{kind:`not-source-checkout`};let a=t(),o=Um(i);return o===a.digest?{kind:`current`,root:n,stamp:a}:{kind:`stale`,root:n,source:{version:qm(n),digest:o},running:a}}catch(e){return{kind:`unchecked`,reason:e.message}}}var J=class extends Error{constructor(e){super(e),this.name=`BadVerbArgs`}};const Ym=new Map;function Xm(e){let t=Qm(e);if(t===null)throw Error(`Palette "${e}" did not resolve in the theme registry — allowed names and the registry are inconsistent`);return t}function Zm(e,t){return e===`bar`?t:Xm(e)}function Qm(e){let t=Ym.get(e);if(t!==void 0)return t;let n=Sc(e);return n===null?null:(Ym.set(e,n),n)}function $m(e,t){return eh(e,`${t.hueShift} ${t.chromaScale} ${t.lightnessScale} ${t.lightnessShift}`,()=>Pc(e,t))}const eh=Yd();function th(e){let t=Qm(e);return t===null?null:{kind:`decided`,name:e,value:t}}function nh(e,t,n){let r=th(e);return r===null?(n(Tp(t,`palette`,`"${e}" names no installed theme${sp(e)}`)),ih()):r}function rh(e,t,n){return _p(e,t,n,ih(),th)}function ih(){return{kind:`decided`,name:cp,value:Xm(cp)}}const ah=[`vertical`,`horizontal`],oh={vertical:`row`,horizontal:`cell`};function sh(e){return e.id??e.name}function ch(e){return[...dh(e)].flatMap(e=>e.kind===`segment`?[sh(e)]:[])}function lh(e,t){if(!t.has(e))return e;let n=2;for(;t.has(`${e}-${n}`);)n++;return`${e}-${n}`}function uh(e,t){return e.opens===void 0?e:{...e,opens:{...e.opens,body:t(e.opens.body)}}}function*dh(e){yield e;for(let t of hh(e))yield*dh(t)}const fh=(e,t)=>`${e}.children[${t}]`,ph=e=>`${e}.opens.body`;function*mh(e,t){if(yield[e,t],e.kind===`container`)for(let[n,r]of e.children.entries())yield*mh(r,fh(t,n));else e.opens!==void 0&&(yield*mh(e.opens.body,ph(t)))}function hh(e){return e.kind===`container`?e.children:e.opens===void 0?[]:[e.opens.body]}const gh=[`shade`,`variation`,`style`];function _h(e){return e===void 0||`text`in e?`text`:`regex`in e?`regex`:`json`}const vh=[`ttl`,`watch_file`,`depends_on`,`key`,`never`];function yh(e){return e.kind===`file`||e.kind===`shell`||e.kind===`template`}const bh=[`branch`,`sha`,`dirty`,`ahead`,`behind`,`stash`],xh=`theme`,Sh=`effect`,Ch=[xh,Sh];function wh(e){return{...e.settings,[xh]:{label:xh,domain:`theme`,default:e.palette??`bar`},[Sh]:{label:Sh,domain:Dp,default:`bar`}}}function Th(e){let t=e?.domain;return typeof t==`object`&&`min`in t?t:void 0}function Eh(e,t){return Object.entries(e).flatMap(([n,r])=>{let i=Th(r)?.atLeast;if(i===void 0)return[];let a=t[n],o=t[i];return a>=o?[]:[{setting:n,message:`"${n}" (${a}) is below "${i}" (${o}) — ${r.label} must be at least ${e[i].label}`}]})}function Dh(e,t){let{domain:n}=e;return n===`bool`?typeof t==`boolean`:n===`theme`?typeof t==`string`&&pp(t):`min`in n?typeof t==`number`&&Number.isInteger(t)&&t>=n.min&&t<=n.max:typeof t==`string`&&n.includes(t)}function Oh(e){return String(e)}function kh(e,t){let{domain:n}=e;if(typeof n==`object`&&`min`in n)return Qp(t,n)??void 0;let r=n===`bool`?t===`true`?!0:t===`false`?!1:t:t;return Dh(e,r)?r:void 0}function Ah(e,t,n,r){let i=e.settings?.[t]??n.default,a=e.drafts?.[t],o=a===void 0?null:r(a);return(o===null?void 0:kh(n,o))??i}function jh(e){let{domain:t}=e;return t===`bool`?`true or false`:t===`theme`?`"bar" (the bar's own theme) or an installed theme name`:`min`in t?`an integer from ${t.min} to ${t.max}`:`one of ${t.map(e=>JSON.stringify(e)).join(`, `)}`}const Mh=[`left`,`center`,`right`],Nh=[`right`,`left`,`middle`],Ph=/^[A-Za-z_][A-Za-z0-9_]*$/;function Fh(e){return`#${e+1}`}const Ih={rows:{}};function Lh(e){return`rows`in e}function Rh(e){return Object.fromEntries(e.map((e,t)=>[Fh(t),e]))}function zh(e){if(e.kind===`container`&&e.direction===`vertical`){let{kind:t,direction:n,children:r,...i}=e;return{...i,rows:Rh(r)}}let{when:t,...n}=e;return{...t!==void 0&&{when:t},rows:Rh([n])}}function Bh(e){let{rows:t,...n}=e;return{kind:`container`,direction:`vertical`,children:Object.values(t),...n}}function Vh(e){return Lh(e)?Bh(e):e}function*Hh(e,t){if(!Lh(e)){yield*mh(e,t);return}yield[Bh(e),t];for(let[n,r]of Object.entries(e.rows))yield*mh(r,`${t}.rows.${n}`)}function Uh(e,t){return Lh(e)?{...t,...e,rows:{...t.rows,...e.rows}}:zh(e)}function Wh(e){if(!Lh(e))return!0;let{rows:t,...n}=e;return Object.values(n).some(e=>e!==void 0)||Object.keys(t).length>0}const Gh=`default`,Kh={};function qh(e){return[...new Set([Gh,...Object.keys(e)])]}function Jh(e,t,n){return mp(void 0,e,t,Gh,n)}function Yh(e,t){let n={[Gh]:Kh,...e}[t];if(n===void 0)throw Error(`Preset "${t}" is not declared in this config — effectivePresetName collapses unknown names to "${Gh}", which always resolves; a miss here means a raw name reached this function without going through that resolution`);return n}function Xh(e,t){let n=Yh(e.presets,t).root??Ih;return{node:Bh(Uh(n,e.root)),path:Wh(n)?`presets.${t}.root`:`root`}}function Zh(e,t){return{...e.globals,...Yh(e.presets,t).globals}}const Qh=new Map;function $h(e,t,n){Qh.set(e,{permanent:!0,resolve:t,paletteOf:n})}$h(`themes`,()=>up(),e=>Xm(e));const eg=`placementThemes`;$h(eg,dp,(e,t)=>Zm(e,t.palette)),$h(`endcaps`,()=>jp),$h(`variations`,()=>Vp),$h(`shades`,()=>Wp),$h(`charsets`,()=>Ip),$h(`colorCompatibilities`,()=>zp);function tg(e){return new Map([[`styles`,{members:Object.keys(e.styles),paletteOf:(t,n)=>$m(n.basePalette,e.styles[t])}],[`presets`,{members:qh(e.presets)}]])}function ng(e){return[...new Set([...Qh.keys(),...e.keys()])]}function rg(e,t){if(typeof e!=`string`)return{members:e};let n=t.get(e);if(n)return n;let r=Qh.get(e);if(r)return{members:r.resolve(),paletteOf:r.paletteOf};throw Error(ag(e,t))}const ig=new Map([[`looks`,`styles`],[`progressions`,`variations`]]);function ag(e,t){let n=ig.get(e);return`unknown option domain "${e}"${n===void 0?``:` — it was renamed "${n}"; write from: "${n}"`} (have: ${ng(t).join(`, `)})`}const og=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`[^`]*`/g;function*sg(e){let t=e.indexOf(`{{`);for(;t!==-1;){let n=``,r=t+2;for(;r<e.length&&!e.startsWith(`}}`,r);){if(e.startsWith(`/*`,r)){let t=e.indexOf(`*/`,r+2);r=t===-1?e.length:t+2;continue}let t=r,i=e[r];if(r+=1,i===`"`||i===`'`||i==="`"){for(;r<e.length&&e[r]!==i;)r+=e[r]===`\\`&&i!=="`"?2:1;r+=1}n+=e.slice(t,r)}if(r>=e.length)return;yield n,t=e.indexOf(`{{`,r+2)}}const cg=`[A-Za-z_]\\w*(?:\\.[A-Za-z_]\\w*)*`,lg=RegExp(`^(?:(\\$)(?:\\.(${cg}))?|\\.(${cg})?)(?=[\\s)]|$)`);function ug(e,t,n){let r=lg.exec(e.trimStart());if(r===null)return null;let[i,a]=r[1]===void 0?[t,r[3]]:[n,r[2]];return i===null?null:a===void 0?i:`${i}${a}.`}const dg=/^(\w+)\b\s*([\s\S]*)$/;function*fg(e,t){let n=[t];for(let r of sg(e)){let e=r.replace(/^-(?=\s)/,``).trim(),[,i=``,a=``]=dg.exec(e)??[],o=n[n.length-1],s=n.length>1?n[n.length-2]:o;if(i===`end`){n.length>1&&n.pop();continue}if(i===`else`){yield{code:e,dot:s};let r=/^with\b([\s\S]*)$/.exec(a);n[n.length-1]=r===null?s:ug(r[1],s,t);continue}yield{code:e,dot:o},i===`if`&&n.push(o),i===`with`&&n.push(ug(a,o,t)),(i===`range`||i===`define`||i===`block`)&&n.push(null)}}const pg=/(?<![.$])\btemplate\s+$/;function*mg(e,t,n){let r=0;for(let i of[...e.matchAll(og)]){let a=i.index+i[0].length;pg.test(e.slice(r,i.index))&&(yield{name:i[0].slice(1,-1),at:ug(e.slice(a),t,n)}),r=a}}function*hg(e,t){let n=new Set;function*r(e,i,a,o){for(let{code:s,dot:c}of[...fg(e,i)]){yield{code:s,dot:c,root:i,via:a};for(let e of[...mg(s,c,i)]){let i=Object.hasOwn(t,e.name)?t[e.name]:void 0,a=`${e.name}\0${e.at??`\0`}`;i===void 0||o.has(e.name)||n.has(a)||(n.add(a),yield*r(i,e.at,e.name,new Set([...o,e.name])))}}}yield*r(e,``,null,new Set)}const gg=RegExp(`(?<![A-Za-z0-9_)$])(\\$?)\\.(${cg})`,`g`);function*_g({code:e,dot:t,root:n}){let r=e.replace(og,``);for(let e of[...r.matchAll(gg)]){let r=e[1]===`$`?n:t;r!==null&&(yield`${r}${e[2]}`)}}function vg(e,t){let n=new Map;for(let r of hg(e,t))for(let e of _g(r))n.has(e)||n.set(e,r.via);return n}const yg=/(?<![.$])\b(action|picker|menu|carousel|swatches|swatch|themePreview)\s+$/,bg={action:1,picker:2,menu:1,carousel:2,swatch:1,swatches:2,themePreview:1};function*xg(e){let t=0,n=0,r=0,i=`action`;for(let a of[...e.matchAll(og)]){let o=e.slice(t,a.index),s=yg.exec(o);if(s!==null)n=bg[s[1]],r=0,i=s[1]===`action`?`action`:`options`;else for(let e of o)e===`(`&&r++,e===`)`&&r--,(r<0||e===`|`&&r===0)&&(n=0);n>0&&r===0&&(yield{name:a[0].slice(1,-1),site:i},n--),t=a.index+a[0].length}}function Sg(e,t){let n=new Map;for(let{code:r,via:i}of hg(e,t))for(let{name:e,site:t}of xg(r)){let r=`${e}\0${i??`\0`}`;n.has(r)||n.set(r,{name:e,site:t,via:i})}return[...n.values()]}function Cg(e,t){return new Set([...wg(e,t)].filter(e=>Object.hasOwn(t,e)))}function wg(e,t){let n=new Set;for(let{code:r,dot:i,root:a}of hg(e,t))for(let{name:e}of mg(r,i,a))n.add(e);return n}function Tg(e,t){if(t.names.has(e))return!0;let n=`${e}.`;for(let e of t.names)if(e.startsWith(n))return!0;for(let n of t.documents)if(e.startsWith(`${n}.`))return!0;return!1}function Eg(e){let t=new Set,n=new Set,r=(e,r)=>{t.add(e),Dg(r)&&n.add(e)};for(let[t,n]of Object.entries(e.variables))r(t,n);for(let[t,n]of Object.entries(e.segments))for(let[e,i]of Object.entries(n.vars??{}))r(`${t}.${e}`,i);return{names:t,documents:n,helpers:e.helpers}}function Dg(e){return e.kind===`dropped`||(e.kind===`shell`||e.kind===`file`)&&_h(e.parse)===`json`}function Og(e){let t=l.basename(e),n=l.dirname(e);for(;;){let r=kg(n);if(r!==null)return{dir:r,name:t,leaf:n===l.dirname(e)};t=l.basename(n),n=l.dirname(n)}}function kg(e){try{return r.statSync(e).isDirectory()?r.realpathSync(e):null}catch{return null}}var Ag=ye((e=>{function t(e){var t=[...arguments].slice(1);throw Error(typeof e==`number`?`[MobX] minified error nr: `+e+(t.length?` `+t.map(String).join(`,`):``)+`. Find the full error at: https://github.com/mobxjs/mobx/blob/main/packages/mobx/src/errors.ts`:`[MobX] `+e)}function n(){return typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:rn}function r(){un||t(`Proxy not available`)}function i(e){var t=!1;return function(){if(!t)return t=!0,e.apply(this,arguments)}}function a(e){return typeof e==`function`}function o(e){switch(typeof e){case`string`:case`symbol`:case`number`:return!0}return!1}function s(e){return typeof e==`object`&&!!e}function c(e){if(!s(e))return!1;var t=Object.getPrototypeOf(e);if(t==null)return!0;var n=Object.hasOwnProperty.call(t,`constructor`)&&t.constructor;return typeof n==`function`&&n.toString()===dn}function l(e){var t=e?.constructor;return!!t&&(t.name===`GeneratorFunction`||t.displayName===`GeneratorFunction`)}function u(e,t,n){on(e,t,{enumerable:!1,writable:!0,configurable:!0,value:n})}function d(e,t,n){on(e,t,{enumerable:!1,writable:!1,configurable:!0,value:n})}function f(e,t){var n=`isMobX`+e;return t.prototype[n]=!0,function(e){return s(e)&&!0===e[n]}}function p(e){return e!=null&&Object.prototype.toString.call(e)===`[object Map]`}function m(e){return e!=null&&Object.prototype.toString.call(e)===`[object Set]`}function h(e){return e===null?null:typeof e==`object`?``+e:e}function g(e,t){return sn.hasOwnProperty.call(e,t)}function _(e,t){return!!(e&t)}function v(e,t,n){return n?e|=t:e&=~t,e}function y(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function b(e,t,n){if(re())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,t);var i=new(e.bind.apply(e,r));return n&&ie(i,n.prototype),i}function x(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,ae(r.key),r)}}function S(e,t,n){return t&&x(e.prototype,t),n&&x(e,n),Object.defineProperty(e,`prototype`,{writable:!1}),e}function C(e,t){var n=typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if(typeof e==`string`)return y(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?y(e,t):void 0}}(e))||t&&e&&typeof e.length==`number`){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw TypeError(`Invalid attempt to iterate non-iterable instance.
57
57
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function ee(){return(ee=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(null,arguments)}function te(e){return(te=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function ne(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,ie(e,t)}function re(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch{}return(re=function(){return!!e})()}function ie(e,t){return(ie=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}function ae(e){var t=function(e){if(typeof e!=`object`||!e)return e;var t=e[Symbol.toPrimitive];if(t!==void 0){var n=t.call(e,`string`);if(typeof n!=`object`)return n;throw TypeError(`@@toPrimitive must return a primitive value.`)}return String(e)}(e);return typeof t==`symbol`?t:t+``}function w(e){var t=typeof Map==`function`?new Map:void 0;return(w=function(e){function n(){return b(e,arguments,te(this).constructor)}if(e===null||!function(e){try{return Function.toString.call(e).indexOf(`[native code]`)!==-1}catch{return typeof e==`function`}}(e))return e;if(typeof e!=`function`)throw TypeError(`Super expression must either be null or a function`);if(t!==void 0){if(t.has(e))return t.get(e);t.set(e,n)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),ie(n,e)})(e)}function T(e){return Object.assign((function(t,n){if(se(n))return e.t(t,n);oe(t,n,e)}),e)}function oe(e,t,n){g(e,gn)||u(e,gn,ee({},e[gn])),function(e){return e.i===`override`}(n)||(e[gn][t]=n)}function se(e){return typeof e==`object`&&typeof e.kind==`string`}function ce(e,t,n){t===void 0&&(t=fn),n===void 0&&(n=fn);var r=new _n(e);return t!==fn&&dt(r,t),n!==fn&&ft(r,n),r}function le(e,t,n){return xt(e)?e:Array.isArray(e)?On.array(e,{name:n}):c(e)?On.object(e,void 0,{name:n}):p(e)?On.map(e,{name:n}):m(e)?On.set(e,{name:n}):typeof e!=`function`||ct(e)||vt(e)?e:l(e)?ar(e):$n(n,e)}function ue(e){return e}function E(e,t){return{i:e,u:t,o:de,s:fe,t:pe}}function de(e,t,n,r){var i;return(i=this.u)!=null&&i.bound?this.s(e,t,n,!1)===null?0:1:r===e.h?this.s(e,t,n,!1)===null?0:2:ct(n.value)?1:(on(r,t,me(e,this,t,n,!1)),2)}function fe(e,t,n,r){var i=me(e,this,t,n);return e.l(t,i,r)}function pe(e,n){var r,i=n.kind,a=n.name,o=n.addInitializer,s=this,c=function(e){var t;return Ne(s.u?.name??a.toString(),e,(t=s.u?.autoAction)!=null&&t)};return i==`field`?function(e){var t,n=e;return ct(n)||(n=c(n)),(t=s.u)!=null&&t.bound&&((n=n.bind(this)).isMobxAction=!0),n}:i==`method`?(ct(e)||(e=c(e)),(r=this.u)!=null&&r.bound&&o((function(){var e=this[a].bind(this);e.isMobxAction=!0,this[a]=e})),e):void t(`Cannot apply '`+s.i+`' to '`+String(a)+`' (kind: `+i+`):
58
58
  '`+s.i+`' can only be used on properties with a function value.`)}function me(e,t,n,r,i){var a,o,s;i===void 0&&(i=L.safeDescriptors);var c=r.value;return(a=t.u)!=null&&a.bound&&(c=c.bind(e.v??e.h)),{value:Ne(t.u?.name??n.toString(),c,(o=t.u?.autoAction)!=null&&o,(s=t.u)!=null&&s.bound?e.v??e.h:void 0),configurable:!i||e.p,enumerable:!1,writable:!i}}function he(e,t){return{i:e,u:t,o:ge,s:_e,t:ve}}function ge(e,t,n,r){var i;return r===e.h?this.s(e,t,n,!1)===null?0:2:(i=this.u)!=null&&i.bound&&(!g(e.h,t)||!vt(e.h[t]))&&this.s(e,t,n,!1)===null?0:vt(n.value)?1:(on(r,t,ye(e,0,0,n,!1,!1)),2)}function _e(e,t,n,r){var i=ye(e,0,0,n,this.u?.bound);return e.l(t,i,r)}function ve(e,t){var n,r=t.name,i=t.addInitializer;return vt(e)||(e=ar(e)),(n=this.u)!=null&&n.bound&&i((function(){var e=this[r].bind(this);e.isMobXFlow=!0,this[r]=e})),e}function ye(e,t,n,r,i,a){a===void 0&&(a=L.safeDescriptors);var o=r.value;return vt(o)||(o=ar(o)),i&&((o=o.bind(e.v??e.h)).isMobXFlow=!0),{value:o,configurable:!a||e.p,enumerable:!1,writable:!a}}function be(e,t){return{i:e,u:t,o:xe,s:D,t:Se}}function xe(e,t,n){return this.s(e,t,n,!1)===null?0:1}function D(e,t,n,r){return e.m(t,ee({},this.u,{get:n.get,set:n.set}),r)}function Se(e,t){var n=this,r=t.name;return(0,t.addInitializer)((function(){var t=Vt(this)[N],i=ee({},n.u,{get:e,context:this});i.name||=`ObservableObject.`+r.toString(),t.j.set(r,new Rn(i))})),function(){return this[N].O(r)}}function Ce(e,t){return{i:e,u:t,o:we,s:Te,t:Ee}}function we(e,t,n){return this.s(e,t,n,!1)===null?0:1}function Te(e,t,n,r){return e.g(t,n.value,this.u?.enhancer??le,r)}function Ee(e,t){function n(e,t){var n=Vt(e)[N],i=new In(t,r.u?.enhancer??le,`ObservableObject.`+a.toString(),!1);n.j.set(a,i),o.add(e)}var r=this,i=t.kind,a=t.name,o=new WeakSet;if(i==`accessor`)return{get:function(){return o.has(this)||n(this,e.get.call(this)),this[N].O(a)},set:function(e){return o.has(this)||n(this,e),this[N].S(a,e)},init:function(e){return o.has(this)||n(this,e),e}}}function De(e){return{i:`true`,u:e,o:Oe,s:ke,t:Ae}}function Oe(e,t,n,r){var i,a,o;if(n.get)return jn.o(e,t,n,r);if(n.set){var s=ct(n.set)?n.set:Ne(t.toString(),n.set);return r===e.h?e.l(t,{configurable:!L.safeDescriptors||e.p,set:s})===null?0:2:(on(r,t,{configurable:!0,set:s}),2)}if(r!==e.h&&typeof n.value==`function`)return l(n.value)?((o=this.u)!=null&&o.autoBind?ar.bound:ar).o(e,t,n,r):((a=this.u)!=null&&a.autoBind?$n.bound:$n).o(e,t,n,r);var c=!1===this.u?.deep?On.ref:On;return typeof n.value==`function`&&(i=this.u)!=null&&i.autoBind&&(n.value=n.value.bind(e.v??e.h)),c.o(e,t,n,r)}function ke(e,t,n,r){var i;return n.get?jn.s(e,t,n,r):n.set?e.l(t,{configurable:!L.safeDescriptors||e.p,set:Ne(t.toString(),n.set)},r):(typeof n.value==`function`&&(i=this.u)!=null&&i.autoBind&&(n.value=n.value.bind(e.v??e.h)),(!1===this.u?.deep?On.ref:On).s(e,t,n,r))}function Ae(){t(`'`+this.i+`' cannot be used as a decorator`)}function je(e){return e||Sn}function O(e){return!0===e.deep?le:!1===e.deep?ue:(t=e.defaultDecorator)&&(n=(r=t.u)?.enhancer)!=null?n:le;var t,n,r}function Me(e,t,n){return se(t)?Cn.t(e,t):o(t)?void oe(e,t,Cn):xt(e)?e:c(e)?On.object(e,t,n):Array.isArray(e)?On.array(e,t):p(e)?On.map(e,t):m(e)?On.set(e,t):typeof e==`object`&&e?e:On.box(e,t)}function Ne(e,t,n,r){function i(){return Pe(0,n,t,r||this,arguments)}return n===void 0&&(n=!1),i.isMobxAction=!0,i.toString=function(){return t.toString()},Pn&&(Fn.value=e,on(i,`name`,Fn)),i}function Pe(e,t,n,r,i){var a=Fe(0,t);try{return n.apply(r,i)}catch(e){throw a._=e,e}finally{Ie(a)}}function Fe(e,t){var n=L.trackingDerivation,r=!t||!n;$e();var i=L.allowStateChanges;r&&(Ge(),i=Re(!0));var a={A:r,k:n,M:i,V:qe(!0),R:!1,N:0,T:Nn++,C:Mn};return Mn=a.T,a}function Ie(e){Mn!==e.T&&t(30),Mn=e.C,e._!==void 0&&(L.suppressReactionErrors=!0),ze(e.M),Je(e.V),et(),e.A&&Ke(e.k),L.suppressReactionErrors=!1}function Le(e,t){var n=Re(e);try{return t()}finally{ze(n)}}function Re(e){var t=L.allowStateChanges;return L.allowStateChanges=e,t}function ze(e){L.allowStateChanges=e}function Be(e){return e instanceof Bn}function Ve(e){switch(e.I){case F.L:return!1;case F.P:case F.K:return!0;case F.B:for(var t=qe(!0),n=Ge(),r=e.D,i=r.length,a=0;a<i;a++){var o=r[a];if(I(o)){if(L.disableErrorBoundaries)o.get();else try{o.get()}catch{return Ke(n),Je(t),!0}if(e.I===F.K)return Ke(n),Je(t),!0}}return Ye(e),Ke(n),Je(t),!1}}function He(e,t,n){var r=qe(!0);Ye(e),e.W=Array(e.q===0?100:e.D.length),e.G=0,e.q=++L.runId;var i,a=L.trackingDerivation;if(L.trackingDerivation=e,L.inBatch++,!0===L.disableErrorBoundaries)i=t.call(n);else try{i=t.call(n)}catch(e){i=new Bn(e)}return L.inBatch--,L.trackingDerivation=a,function(e){for(var t=e.D,n=e.D=e.W,r=F.L,i=0,a=e.G,o=0;o<a;o++){var s=n[o];s.diffValue===0&&(s.diffValue=1,i!==o&&(n[i]=s),i++),s.I>r&&(r=s.I)}for(n.length=i,e.W=null,a=t.length;a--;){var c=t[a];c.diffValue===0&&Ze(c,e),c.diffValue=0}for(;i--;){var l=n[i];l.diffValue===1&&(l.diffValue=0,Xe(l,e))}r!==F.L&&(e.I=r,e.H())}(e),Je(r),i}function Ue(e){var t=e.D;e.D=[];for(var n=t.length;n--;)Ze(t[n],e);e.I=F.P}function We(e){var t=Ge();try{return e()}finally{Ke(t)}}function Ge(){var e=L.trackingDerivation;return L.trackingDerivation=null,e}function Ke(e){L.trackingDerivation=e}function qe(e){var t=L.allowStateReads;return L.allowStateReads=e,t}function Je(e){L.allowStateReads=e}function Ye(e){if(e.I!==F.L){e.I=F.L;for(var t=e.D,n=t.length;n--;)t[n].U=F.L}}function Xe(e,t){e.F.add(t),e.U>t.I&&(e.U=t.I)}function Ze(e,t){e.F.delete(t),e.F.size===0&&Qe(e)}function Qe(e){!1===e.isPendingUnobservation&&(e.isPendingUnobservation=!0,L.pendingUnobservations.push(e))}function $e(){L.inBatch++}function et(){if(--L.inBatch==0){rt();for(var e=L.pendingUnobservations,t=0;t<e.length;t++){var n=e[t];n.isPendingUnobservation=!1,n.F.size===0&&(n.isBeingObserved&&(n.isBeingObserved=!1,n.onBUO()),n instanceof Rn&&n.X())}L.pendingUnobservations=[]}}function tt(e){var t=L.trackingDerivation;return t===null?(e.F.size===0&&L.inBatch>0&&Qe(e),!1):(t.q!==e.$&&(e.$=t.q,t.W[t.G++]=e,!e.isBeingObserved&&L.trackingContext&&(e.isBeingObserved=!0,e.onBO())),e.isBeingObserved)}function nt(e){e.U!==F.K&&(e.U=F.K,e.F.forEach((function(e){e.I===F.L&&e.H(),e.I=F.K})))}function rt(){L.inBatch>0||L.isRunningReactions||Kn(it)}function it(){L.isRunningReactions=!0;for(var e=L.pendingReactions,t=0;e.length>0;){++t==100&&(console.error(`[mobx] cycle in reaction: `+e[0]),e.splice(0));for(var n=e.splice(0),r=0,i=n.length;r<i;r++)n[r].J()}L.isRunningReactions=!1}function at(){return console.warn(`[mobx.spy] Is a no-op in production builds`),function(){}}function ot(e){return function(t,n){return a(t)?Ne(t.name||`<unnamed action>`,t,e):a(n)?Ne(t,n,e):se(n)?(e?Xn:Jn).t(t,n):o(n)?oe(t,n,e?Xn:Jn):o(t)?T(E(e?`autoAction`:`action`,{name:t,autoAction:e})):void 0}}function st(e){return Pe(0,!1,e,this,void 0)}function ct(e){return a(e)&&!0===e.isMobxAction}function lt(e,t){function n(){e(i)}var r;t===void 0&&(t=ln);var i,a=t?.name??`Autorun`;if(t.scheduler||t.delay){var o=ut(t),s=!1;i=new Gn(a,(function(){s||(s=!0,o((function(){s=!1,i.isDisposed||i.track(n)})))}),t.onError,t.requiresObservable)}else i=new Gn(a,(function(){this.track(n)}),t.onError,t.requiresObservable);return(r=t)!=null&&(r=r.signal)!=null&&r.aborted||i.Y(),i.Z(t?.signal)}function ut(e){return e.scheduler?e.scheduler:e.delay?function(t){return setTimeout(t,e.delay)}:er}function dt(e,t,n){return pt(`onBO`,e,t,n)}function ft(e,t,n){return pt(`onBUO`,e,t,n)}function pt(e,t,n,r){var i=typeof r==`function`?Yt(t,n):Yt(t),o=a(r)?r:n,s=e+`L`;return i[s]?i[s].add(o):i[s]=new Set([o]),function(){var e=i[s];e&&(e.delete(o),e.size===0&&delete i[s])}}function mt(e,t,n,r){var i=hn(t);return Qt((function(){var t=Vt(e,r)[N];mn(i).forEach((function(e){t.s(e,i[e],!n||!(e in n)||n[e])}))})),e}function ht(e){var t,n={name:e.tt};return e.D&&e.D.length>0&&(n.dependencies=(t=e.D,Array.from(new Set(t))).map(ht)),n}function gt(e){var t={name:e.tt};return function(e){return e.F&&e.F.size>0}(e)&&(t.observers=Array.from(function(e){return e.F}(e)).map(gt)),t}function _t(e){a(e.cancel)&&e.cancel()}function vt(e){return!0===e?.isMobXFlow}function yt(e,t){return t===void 0?I(e):!1===Ut(e)||!e[N].j.has(t)?!1:I(Yt(e,t))}function bt(e,t){return!!e&&(t===void 0?Ut(e)||!!e[N]||vn(e)||qn(e)||I(e):!!Ut(e)&&e[N].j.has(t))}function xt(e){return bt(e)}function St(e){return Ut(e)?e[N].nt():vr(e)||xr(e)?Array.from(e.keys()):Rt(e)?e.map((function(e,t){return t})):void t(5)}function Ct(e,n){return Ut(e)?e[N].it(n):vr(e)||xr(e)?e.has(n):Rt(e)?n>=0&&n<e.length:void t(10)}function wt(e){if(Ut(e))return e[N].rt();t(38)}function Tt(e,t,n){return e.set(t,n),n}function Et(e,t){t===void 0&&(t=void 0),$e();try{return e.apply(t)}finally{et()}}function Dt(e,t,n){var r;if(typeof n.timeout==`number`){var i=Error(`WHEN_TIMEOUT`);r=setTimeout((function(){if(!o[N].isDisposed){if(o(),!n.onError)throw i;n.onError(i)}}),n.timeout)}n.name=`When`;var a=Ne(`When-effect`,t),o=lt((function(t){Le(!1,e)&&(t.dispose(),r&&clearTimeout(r),a())}),n);return o}function Ot(e,t){var n,r,i;if(t!=null&&(n=t.signal)!=null&&n.aborted)return Object.assign(Promise.reject(Error(`WHEN_ABORTED`)),{cancel:function(){return null}});var a=new Promise((function(n,a){var o,s=Dt(e,n,ee({},t,{onError:a}));r=function(){s(),a(Error(`WHEN_CANCELLED`))},i=function(){s(),a(Error(`WHEN_ABORTED`))},t==null||(o=t.signal)==null||o.addEventListener==null||o.addEventListener(`abort`,i)})).finally((function(){var e;return t==null||(e=t.signal)==null||e.removeEventListener==null?void 0:e.removeEventListener(`abort`,i)}));return a.cancel=r,a}function kt(e){return e[N]}function At(e){return e.et!==void 0&&e.et.length>0}function jt(e,t){var n=e.et||=[];return n.push(t),i((function(){var e=n.indexOf(t);e!==-1&&n.splice(e,1)}))}function Mt(e,n){var r=Ge();try{for(var i=[].concat(e.et||[]),a=0,o=i.length;a<o&&((n=i[a](n))&&!n.type&&t(14),n);a++);return n}finally{Ke(r)}}function Nt(e){return e.ut!==void 0&&e.ut.length>0}function k(e,t){var n=e.ut||=[];return n.push(t),i((function(){var e=n.indexOf(t);e!==-1&&n.splice(e,1)}))}function Pt(e,t){var n=Ge(),r=e.ut;if(r){for(var i=0,a=(r=r.slice()).length;i<a;i++)r[i](t);Ke(n)}}function Ft(e,t,n,i){return n===void 0&&(n=`ObservableArray`),i===void 0&&(i=!1),r(),Qt((function(){var r=new ur(n,t,i,!1);d(r.j,N,r);var a=new Proxy(r.j,lr);return r.v=a,e&&e.length&&r.ot(0,0,e),a}))}function A(e,t){typeof Array.prototype[e]==`function`&&(dr[e]=t(e))}function It(e){return function(){var t=this[N];t.st.reportObserved();var n=t.ft(t.j);return n[e].apply(n,arguments)}}function j(e){return function(t,n){var r=this,i=this[N];return i.st.reportObserved(),i.ft(i.j)[e]((function(e,i){return t.call(n,e,i,r)}))}}function Lt(e){return function(){var t=this,n=this[N];n.st.reportObserved();var r=n.ft(n.j),i=arguments[0];return arguments[0]=function(e,n,r){return i(e,n,r,t)},r[e].apply(r,arguments)}}function Rt(e){return s(e)&&mr(e[N])}function zt(e){return e[Symbol.toStringTag]=`MapIterator`,tn(e)}function Bt(e){return e[Symbol.toStringTag]=`SetIterator`,tn(e)}function Vt(e,t){if(g(e,N))return e;var n=t?.name??`ObservableObject`;return u(e,N,new Cr(e,new Map,String(n),function(e){return e?e.defaultDecorator??De(e):void 0}(t))),e}function Ht(e){return Sr[e]||(Sr[e]={get:function(){return this[N].O(e)},set:function(t){return this[N].S(e,t)}})}function Ut(e){return!!s(e)&&wr(e[N])}function Wt(e,t,n){var r;(r=e.h[gn])==null||delete r[n]}function Gt(e){return{enumerable:!1,configurable:!0,get:function(){return this[N].ct(e)},set:function(t){this[N].ht(e,t)}}}function Kt(e){on(kr.prototype,``+e,Gt(e))}function qt(e){if(e>Dr){for(var t=Dr;t<e+100;t++)Kt(t);Dr=e}}function Jt(e,t,n){return new kr(e,t,n)}function Yt(e,n){if(typeof e==`object`&&e){if(Rt(e))return n!==void 0&&t(23),e[N].st;if(xr(e))return e.st;if(vr(e)){if(n===void 0)return e.lt;var r=e.vt.get(n)||e.dt.get(n);return r||t(25,n,Zt(e)),r}if(Ut(e)){if(!n)return t(26);var i=e[N].j.get(n);return i||t(27,n,Zt(e)),i}if(vn(e)||I(e)||qn(e))return e}else if(a(e)&&qn(e[N]))return e[N];t(28)}function Xt(e,n){return e||t(29),n===void 0?vn(e)||I(e)||qn(e)||vr(e)||xr(e)?e:e[N]?e[N]:void t(24,e):Xt(Yt(e,n))}function Zt(e,t){var n;if(t!==void 0)n=Yt(e,t);else{if(ct(e))return e.name;n=Ut(e)||vr(e)||xr(e)?Xt(e):Yt(e)}return n.tt}function Qt(e){var t=Ge(),n=Re(!0);$e();try{return e()}finally{et(),ze(n),Ke(t)}}function $t(e,t,n){return n===void 0&&(n=-1),function e(t,n,r,i,o){if(t===n)return t!==0||1/t==1/n;if(t==null||n==null)return!1;if(t!=t)return n!=n;var s=typeof t;if(s!==`function`&&s!==`object`&&typeof n!=`object`)return!1;var c=Ar.call(t);if(c!==Ar.call(n))return!1;switch(c){case`[object RegExp]`:case`[object String]`:return``+t==``+n;case`[object Number]`:return+t==+t?+t==0?1/t==1/n:+t==+n:+n!=+n;case`[object Date]`:case`[object Boolean]`:return+t==+n;case`[object Symbol]`:return typeof Symbol<`u`&&Symbol.valueOf.call(t)===Symbol.valueOf.call(n);case`[object Map]`:case`[object Set]`:r>=0&&r++}t=en(t),n=en(n);var l=c===`[object Array]`;if(!l){if(typeof t!=`object`||typeof n!=`object`)return!1;var u=t.constructor,d=n.constructor;if(u!==d&&!(a(u)&&u instanceof u&&a(d)&&d instanceof d)&&`constructor`in t&&`constructor`in n)return!1}if(r===0)return!1;r<0&&(r=-1),o||=[];for(var f=(i||=[]).length;f--;)if(i[f]===t)return o[f]===n;if(i.push(t),o.push(n),l){if((f=t.length)!==n.length)return!1;for(;f--;)if(!e(t[f],n[f],r-1,i,o))return!1}else{var p=Object.keys(t),m=p.length;if(Object.keys(n).length!==m)return!1;for(var h=0;h<m;h++){var _=p[h];if(!g(n,_)||!e(t[_],n[_],r-1,i,o))return!1}}return i.pop(),o.pop(),!0}(e,t,n)}function en(e){return Rt(e)?e.slice():p(e)||vr(e)||m(e)||xr(e)?Array.from(e.entries()):e}function tn(e){return e[Symbol.iterator]=nn,Object.assign(Object.create(jr),e)}function nn(){return this}Object.defineProperty(e,`__esModule`,{value:!0});var rn={},M=Object.assign,an=Object.getOwnPropertyDescriptor,on=Object.defineProperty,sn=Object.prototype,cn=[];Object.freeze(cn);var ln={};Object.freeze(ln);var un=typeof Proxy<`u`,dn=Object.toString(),fn=function(){},pn=Object.getOwnPropertySymbols!==void 0,mn=typeof Reflect<`u`&&Reflect.ownKeys?Reflect.ownKeys:pn?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Object.getOwnPropertyNames,hn=Object.getOwnPropertyDescriptors||function(e){var t={};return mn(e).forEach((function(n){t[n]=an(e,n)})),t},gn=Symbol(`mobx-stored-annotations`),N=Symbol(`mobx administration`),_n=function(){function e(e){e===void 0&&(e=`Atom`),this.tt=void 0,this.bt=0,this.F=new Set,this.$=0,this.U=F.P,this.onBOL=void 0,this.onBUOL=void 0,this.tt=e}var t=e.prototype;return t.onBO=function(){this.onBOL&&this.onBOL.forEach((function(e){return e()}))},t.onBUO=function(){this.onBUOL&&this.onBUOL.forEach((function(e){return e()}))},t.reportObserved=function(){return tt(this)},t.reportChanged=function(){$e(),nt(this),et()},t.toString=function(){return this.tt},S(e,[{key:`isBeingObserved`,get:function(){return _(this.bt,e.pt)},set:function(t){this.bt=v(this.bt,e.pt,t)}},{key:`isPendingUnobservation`,get:function(){return _(this.bt,e.yt)},set:function(t){this.bt=v(this.bt,e.yt,t)}},{key:`diffValue`,get:function(){return+!!_(this.bt,e.wt)},set:function(t){this.bt=v(this.bt,e.wt,t===1)}}])}();_n.pt=1,_n.yt=2,_n.wt=4;var vn=f(`Atom`,_n),yn={identity:function(e,t){return e===t},structural:function(e,t){return $t(e,t)},default:function(e,t){return Object.is?Object.is(e,t):e===t?e!==0||1/e==1/t:e!=e&&t!=t},shallow:function(e,t){return $t(e,t,1)}},bn=T({i:`override`,o:function(){return 0},s:function(){t(`'`+this.i+`' can only be used with 'makeObservable'`)},t:function(){console.warn(`'`+this.i+`' cannot be used with decorators - this is a no-op`)}}),xn=De(),Sn={deep:!0,name:void 0,defaultDecorator:void 0,proxy:!0};Object.freeze(Sn);var Cn=Ce(`observable`),wn=Ce(`observable.ref`,{enhancer:ue}),P=Ce(`observable.shallow`,{enhancer:function(e,t,n){return e==null||Ut(e)||Rt(e)||vr(e)||xr(e)?e:Array.isArray(e)?On.array(e,{name:n,deep:!1}):c(e)?On.object(e,void 0,{name:n,deep:!1}):p(e)?On.map(e,{name:n,deep:!1}):m(e)?On.set(e,{name:n,deep:!1}):void 0}}),Tn=Ce(`observable.struct`,{enhancer:function(e,t){return $t(e,t)?t:e}}),En=T(Cn);M(Me,En);var Dn,On=M(Me,{box:function(e,t){var n=je(t);return new In(e,O(n),n.name,!0,n.equals)},array:function(e,t){var n=je(t);return(!1===L.useProxies||!1===n.proxy?Jt:Ft)(e,O(n),n.name)},map:function(e,t){var n=je(t);return new _r(e,O(n),n.name)},set:function(e,t){var n=je(t);return new br(e,O(n),n.name)},object:function(e,t,n){return Qt((function(){return mt(!1===L.useProxies||!1===n?.proxy?Vt({},n):function(e,t){var n;return r(),(n=(e=Vt(e,t))[N]).v??(n.v=new Proxy(e,or))}({},n),e,t)}))},ref:T(wn),shallow:T(P),deep:En,struct:T(Tn)}),kn=be(`computed`),An=be(`computed.struct`,{equals:yn.structural}),jn=function(e,t){if(se(t))return kn.t(e,t);if(o(t))return oe(e,t,kn);if(c(e))return T(be(`computed`,e));var n=c(t)?t:{};return n.get=e,n.name||=e.name||``,new Rn(n)};Object.assign(jn,kn),jn.struct=T(An);var Mn=0,Nn=1,Pn=(Dn=an((function(){}),`name`)?.configurable)!=null&&Dn,Fn={value:`action`,configurable:!0,writable:!1,enumerable:!1},In=function(e){function t(t,n,r,i,a){var o;return r===void 0&&(r=`ObservableValue`),a===void 0&&(a=yn.default),(o=e.call(this,r)||this).enhancer=void 0,o.tt=void 0,o.equals=void 0,o.jt=!1,o.et=void 0,o.ut=void 0,o.Ot=void 0,o.dehancer=void 0,o.enhancer=n,o.tt=r,o.equals=a,o.Ot=n(t,void 0,r),o}ne(t,e);var n=t.prototype;return n.dehanceValue=function(e){return this.dehancer===void 0?e:this.dehancer(e)},n.set=function(e){(e=this.xt(e))!==L.UNCHANGED&&this.gt(e)},n.xt=function(e){if(At(this)){var t=Mt(this,{object:this,type:cr,newValue:e});if(!t)return L.UNCHANGED;e=t.newValue}return e=this.enhancer(e,this.Ot,this.tt),this.equals(this.Ot,e)?L.UNCHANGED:e},n.gt=function(e){var t=this.Ot;this.Ot=e,this.reportChanged(),Nt(this)&&Pt(this,{type:cr,object:this,newValue:e,oldValue:t})},n.get=function(){return this.reportObserved(),this.dehanceValue(this.Ot)},n.St=function(e){return jt(this,e)},n._t=function(e,t){return t&&e({observableKind:`value`,debugObjectName:this.tt,object:this,type:cr,newValue:this.Ot,oldValue:void 0}),k(this,e)},n.raw=function(){return this.Ot},n.toJSON=function(){return this.get()},n.toString=function(){return this.tt+`[`+this.Ot+`]`},n.valueOf=function(){return h(this.get())},n[Symbol.toPrimitive]=function(){return this.valueOf()},t}(_n),Ln=f(`ObservableValue`,In),Rn=function(){function e(e){this.I=F.P,this.D=[],this.W=null,this.F=new Set,this.q=0,this.$=0,this.U=F.L,this.G=0,this.Ot=new Bn(null),this.tt=void 0,this.At=void 0,this.bt=0,this.derivation=void 0,this.kt=void 0,this.Mt=zn.NONE,this.Et=void 0,this.Vt=void 0,this.Rt=void 0,this.Nt=void 0,this.onBOL=void 0,this.onBUOL=void 0,e.get||t(31),this.derivation=e.get,this.tt=e.name||`ComputedValue`,e.set&&(this.kt=Ne(`ComputedValue-setter`,e.set)),this.Vt=e.equals||(e.compareStructural||e.struct?yn.structural:yn.default),this.Et=e.context,this.Rt=e.requiresReaction,this.Nt=!!e.keepAlive}var n=e.prototype;return n.H=function(){(function(e){e.U===F.L&&(e.U=F.B,e.F.forEach((function(e){e.I===F.L&&(e.I=F.B,e.H())})))})(this)},n.onBO=function(){this.onBOL&&this.onBOL.forEach((function(e){return e()}))},n.onBUO=function(){this.onBUOL&&this.onBUOL.forEach((function(e){return e()}))},n.get=function(){if(this.isComputing&&t(32,this.tt,this.derivation),L.inBatch!==0||this.F.size!==0||this.Nt){if(tt(this),Ve(this)){var e=L.trackingContext;this.Nt&&!e&&(L.trackingContext=this),this.trackAndCompute()&&function(e){e.U!==F.K&&(e.U=F.K,e.F.forEach((function(t){t.I===F.B?t.I=F.K:t.I===F.L&&(e.U=F.L)})))}(this),L.trackingContext=e}}else Ve(this)&&(this.Tt(),$e(),this.Ot=this.Ct(!1),et());var n=this.Ot;if(Be(n))throw n.cause;return n},n.set=function(e){if(this.kt){this.isRunningSetter&&t(33,this.tt),this.isRunningSetter=!0;try{this.kt.call(this.Et,e)}finally{this.isRunningSetter=!1}}else t(34,this.tt)},n.trackAndCompute=function(){var e=this.Ot,t=this.I===F.P,n=this.Ct(!0),r=t||Be(e)||Be(n)||!this.Vt(e,n);return r&&(this.Ot=n),r},n.Ct=function(e){this.isComputing=!0;var t,n=Re(!1);if(e)t=He(this,this.derivation,this.Et);else if(!0===L.disableErrorBoundaries)t=this.derivation.call(this.Et);else try{t=this.derivation.call(this.Et)}catch(e){t=new Bn(e)}return ze(n),this.isComputing=!1,t},n.X=function(){this.Nt||(Ue(this),this.Ot=void 0)},n._t=function(e,t){var n=this,r=!0,i=void 0;return lt((function(){var a=n.get();if(!r||t){var o=Ge();e({observableKind:`computed`,debugObjectName:n.tt,type:cr,object:n,newValue:a,oldValue:i}),Ke(o)}r=!1,i=a}))},n.Tt=function(){},n.toString=function(){return this.tt+`[`+this.derivation.toString()+`]`},n.valueOf=function(){return h(this.get())},n[Symbol.toPrimitive]=function(){return this.valueOf()},S(e,[{key:`isComputing`,get:function(){return _(this.bt,e.It)},set:function(t){this.bt=v(this.bt,e.It,t)}},{key:`isRunningSetter`,get:function(){return _(this.bt,e.Lt)},set:function(t){this.bt=v(this.bt,e.Lt,t)}},{key:`isBeingObserved`,get:function(){return _(this.bt,e.pt)},set:function(t){this.bt=v(this.bt,e.pt,t)}},{key:`isPendingUnobservation`,get:function(){return _(this.bt,e.yt)},set:function(t){this.bt=v(this.bt,e.yt,t)}},{key:`diffValue`,get:function(){return+!!_(this.bt,e.wt)},set:function(t){this.bt=v(this.bt,e.wt,t===1)}}])}();Rn.It=1,Rn.Lt=2,Rn.pt=4,Rn.yt=8,Rn.wt=16;var F,zn,I=f(`ComputedValue`,Rn);(function(e){e[e.P=-1]=`NOT_TRACKING_`,e[e.L=0]=`UP_TO_DATE_`,e[e.B=1]=`POSSIBLY_STALE_`,e[e.K=2]=`STALE_`})(F||={}),function(e){e[e.NONE=0]=`NONE`,e[e.LOG=1]=`LOG`,e[e.BREAK=2]=`BREAK`}(zn||={});var Bn=function(e){this.cause=void 0,this.cause=e},Vn=[`mobxGuid`,`spyListeners`,`enforceActions`,`computedRequiresReaction`,`reactionRequiresObservable`,`observableRequiresReaction`,`allowStateReads`,`disableErrorBoundaries`,`runId`,`UNCHANGED`,`useProxies`],Hn=function(){this.version=6,this.UNCHANGED={},this.trackingDerivation=null,this.trackingContext=null,this.runId=0,this.mobxGuid=0,this.inBatch=0,this.pendingUnobservations=[],this.pendingReactions=[],this.isRunningReactions=!1,this.allowStateChanges=!1,this.allowStateReads=!0,this.enforceActions=!0,this.spyListeners=[],this.globalReactionErrorHandlers=[],this.computedRequiresReaction=!1,this.reactionRequiresObservable=!1,this.observableRequiresReaction=!1,this.disableErrorBoundaries=!1,this.suppressReactionErrors=!1,this.useProxies=!0,this.verifyProxies=!1,this.safeDescriptors=!0},Un=!0,Wn=!1,L=function(){var e=n();return e.__mobxInstanceCount>0&&!e.__mobxGlobals&&(Un=!1),e.__mobxGlobals&&e.__mobxGlobals.version!==new Hn().version&&(Un=!1),Un?e.__mobxGlobals?(e.__mobxInstanceCount+=1,e.__mobxGlobals.UNCHANGED||(e.__mobxGlobals.UNCHANGED={}),e.__mobxGlobals):(e.__mobxInstanceCount=1,e.__mobxGlobals=new Hn):(setTimeout((function(){Wn||t(35)}),1),new Hn)}(),Gn=function(){function e(e,t,n,r){e===void 0&&(e=`Reaction`),this.tt=void 0,this.Pt=void 0,this.Kt=void 0,this.Bt=void 0,this.D=[],this.W=[],this.I=F.P,this.q=0,this.G=0,this.bt=0,this.Mt=zn.NONE,this.tt=e,this.Pt=t,this.Kt=n,this.Bt=r}var t=e.prototype;return t.H=function(){this.Y()},t.Y=function(){this.isScheduled||(this.isScheduled=!0,L.pendingReactions.push(this),rt())},t.J=function(){if(!this.isDisposed){$e(),this.isScheduled=!1;var e=L.trackingContext;if(L.trackingContext=this,Ve(this)){this.isTrackPending=!0;try{this.Pt()}catch(e){this.Dt(e)}}L.trackingContext=e,et()}},t.track=function(e){if(!this.isDisposed){$e(),this.isRunning=!0;var t=L.trackingContext;L.trackingContext=this;var n=He(this,e,void 0);L.trackingContext=t,this.isRunning=!1,this.isTrackPending=!1,this.isDisposed&&Ue(this),Be(n)&&this.Dt(n.cause),et()}},t.Dt=function(e){var t=this;if(this.Kt)this.Kt(e,this);else{if(L.disableErrorBoundaries)throw e;L.suppressReactionErrors||console.error(`[mobx] uncaught error in '`+this+`'`,e),L.globalReactionErrorHandlers.forEach((function(n){return n(e,t)}))}},t.dispose=function(){this.isDisposed||(this.isDisposed=!0,this.isRunning||($e(),Ue(this),et()))},t.Z=function(e){var t=this,n=function n(){t.dispose(),e==null||e.removeEventListener==null||e.removeEventListener(`abort`,n)};return e==null||e.addEventListener==null||e.addEventListener(`abort`,n),n[N]=this,`dispose`in Symbol&&typeof Symbol.dispose==`symbol`&&(n[Symbol.dispose]=n),n},t.toString=function(){return`Reaction[`+this.tt+`]`},t.trace=function(){},S(e,[{key:`isDisposed`,get:function(){return _(this.bt,e.Wt)},set:function(t){this.bt=v(this.bt,e.Wt,t)}},{key:`isScheduled`,get:function(){return _(this.bt,e.qt)},set:function(t){this.bt=v(this.bt,e.qt,t)}},{key:`isTrackPending`,get:function(){return _(this.bt,e.Gt)},set:function(t){this.bt=v(this.bt,e.Gt,t)}},{key:`isRunning`,get:function(){return _(this.bt,e.Ht)},set:function(t){this.bt=v(this.bt,e.Ht,t)}},{key:`diffValue`,get:function(){return+!!_(this.bt,e.wt)},set:function(t){this.bt=v(this.bt,e.wt,t===1)}}])}();Gn.Wt=1,Gn.qt=2,Gn.Gt=4,Gn.Ht=8,Gn.wt=16;var Kn=function(e){return e()},qn=f(`Reaction`,Gn),Jn=E(`action`),Yn=E(`action.bound`,{bound:!0}),Xn=E(`autoAction`,{autoAction:!0}),Zn=E(`autoAction.bound`,{autoAction:!0,bound:!0}),Qn=ot(!1);Object.assign(Qn,Jn);var $n=ot(!0);Object.assign($n,Xn),Qn.bound=T(Yn),$n.bound=T(Zn);var er=function(e){return e()},tr=0,nr=function(e){function t(){var n;return n=e.call(this,`FLOW_CANCELLED`)||this,Object.setPrototypeOf(n,(this instanceof t?this.constructor:void 0).prototype),n.name=`FlowCancellationError`,n}return ne(t,e),t.prototype.toString=function(){return`Error: `+this.message},t}(w(Error)),rr=he(`flow`),ir=he(`flow.bound`,{bound:!0}),ar=Object.assign((function(e,t){if(se(t))return rr.t(e,t);if(o(t))return oe(e,t,rr);var n=e,r=n.name||`<unnamed flow>`,i=function(){var e,t=this,i=arguments,o=++tr,s=Qn(r+` - runid: `+o+` - init`,n).apply(t,i),c=void 0,l=new Promise((function(t,n){function i(e){var t;c=void 0;try{t=Qn(r+` - runid: `+o+` - yield `+ d++,s.next).call(s,e)}catch(e){return n(e)}u(t)}function l(e){var t;c=void 0;try{t=Qn(r+` - runid: `+o+` - yield `+ d++,s.throw).call(s,e)}catch(e){return n(e)}u(t)}function u(e){if(!a(e?.then))return e.done?t(e.value):(c=Promise.resolve(e.value)).then(i,l);e.then(u,n)}var d=0;e=n,i(void 0)}));return l.cancel=Qn(r+` - runid: `+o+` - cancel`,(function(){try{c&&_t(c);var t=s.return(void 0),n=Promise.resolve(t.value);n.then(fn,fn),_t(n),e(new nr)}catch(t){e(t)}})),l};return i.isMobXFlow=!0,i}),rr);ar.bound=T(ir);var or={has:function(e,t){return kt(e).it(t)},get:function(e,t){return kt(e).ct(t)},set:function(e,t,n){var r;return!!o(t)&&((r=kt(e).ht(t,n,!0))==null||r)},deleteProperty:function(e,t){var n;return!!o(t)&&((n=kt(e).Ut(t,!0))==null||n)},defineProperty:function(e,t,n){var r;return(r=kt(e).l(t,n))==null||r},ownKeys:function(e){return kt(e).rt()},preventExtensions:function(){t(13)}},sr=Symbol(`mobx-keys`),cr=`update`,lr={get:function(e,t){var n=e[N];return t===N?n:t===`length`?n.Ft():typeof t!=`string`||isNaN(t)?g(dr,t)?dr[t]:e[t]:n.ct(parseInt(t))},set:function(e,t,n){var r=e[N];return t===`length`&&r.Xt(n),typeof t==`symbol`||isNaN(t)?e[t]=n:r.ht(parseInt(t),n),!0},preventExtensions:function(){t(15)}},ur=function(){function e(e,t,n,r){e===void 0&&(e=`ObservableArray`),this.zt=void 0,this.$t=void 0,this.st=void 0,this.j=[],this.et=void 0,this.ut=void 0,this.Jt=void 0,this.dehancer=void 0,this.v=void 0,this.Yt=0,this.zt=n,this.$t=r,this.st=new _n(e),this.Jt=function(e,n){return t(e,n,`ObservableArray[..]`)}}var n=e.prototype;return n.Qt=function(e){return this.dehancer===void 0?e:this.dehancer(e)},n.ft=function(e){return this.dehancer!==void 0&&e.length>0?e.map(this.dehancer):e},n.St=function(e){return jt(this,e)},n._t=function(e,t){return t===void 0&&(t=!1),t&&e({observableKind:`array`,object:this.v,debugObjectName:this.st.tt,type:`splice`,index:0,added:this.j.slice(),addedCount:this.j.length,removed:[],removedCount:0}),k(this,e)},n.Ft=function(){return this.st.reportObserved(),this.j.length},n.Xt=function(e){(typeof e!=`number`||isNaN(e)||e<0)&&t(`Out of range: `+e);var n=this.j.length;if(e!==n)if(e>n){for(var r=Array(e-n),i=0;i<e-n;i++)r[i]=void 0;this.ot(n,0,r)}else this.ot(e,n-e)},n.Zt=function(e,n){e!==this.Yt&&t(16),this.Yt+=n,this.$t&&n>0&&qt(e+n+1)},n.ot=function(e,t,n){var r=this,i=this.j.length;if(e===void 0?e=0:e>i?e=i:e<0&&(e=Math.max(0,i+e)),t=arguments.length===1?i-e:t==null?0:Math.max(0,Math.min(t,i-e)),n===void 0&&(n=cn),At(this)){var a=Mt(this,{object:this.v,type:`splice`,index:e,removedCount:t,added:n});if(!a)return cn;t=a.removedCount,n=a.added}if(n=n.length===0?n:n.map((function(e){return r.Jt(e,void 0)})),this.$t){var o=n.length-t;this.Zt(i,o)}var s=this.tn(e,t,n);return t===0&&n.length===0||this.nn(e,n,s),this.ft(s)},n.tn=function(e,t,n){var r;if(n.length<1e4)return(r=this.j).splice.apply(r,[e,t].concat(n));var i=this.j.slice(e,e+t),a=this.j.slice(e+t);this.j.length+=n.length-t;for(var o=0;o<n.length;o++)this.j[e+o]=n[o];for(var s=0;s<a.length;s++)this.j[e+n.length+s]=a[s];return i},n.in=function(e,t,n){var r=!this.zt&&!1,i=Nt(this),a=i||r?{observableKind:`array`,object:this.v,type:cr,debugObjectName:this.st.tt,index:e,newValue:t,oldValue:n}:null;this.st.reportChanged(),i&&Pt(this,a)},n.nn=function(e,t,n){var r=!this.zt&&!1,i=Nt(this),a=i||r?{observableKind:`array`,object:this.v,debugObjectName:this.st.tt,type:`splice`,index:e,removed:n,added:t,removedCount:n.length,addedCount:t.length}:null;this.st.reportChanged(),i&&Pt(this,a)},n.ct=function(e){if(!(this.$t&&e>=this.j.length))return this.st.reportObserved(),this.Qt(this.j[e]);console.warn(`[mobx] Out of bounds read: `+e)},n.ht=function(e,n){var r=this.j;if(this.$t&&e>r.length&&t(17,e,r.length),e<r.length){var i=r[e];if(At(this)){var a=Mt(this,{type:cr,object:this.v,index:e,newValue:n});if(!a)return;n=a.newValue}(n=this.Jt(n,i))!==i&&(r[e]=n,this.in(e,n,i))}else{for(var o=Array(e+1-r.length),s=0;s<o.length-1;s++)o[s]=void 0;o[o.length-1]=n,this.ot(r.length,0,o)}},e}(),dr={clear:function(){return this.splice(0)},replace:function(e){var t=this[N];return t.ot(0,t.j.length,e)},toJSON:function(){return this.slice()},splice:function(e,t){var n=[...arguments].slice(2),r=this[N];switch(arguments.length){case 0:return[];case 1:return r.ot(e);case 2:return r.ot(e,t)}return r.ot(e,t,n)},spliceWithArray:function(e,t,n){return this[N].ot(e,t,n)},push:function(){for(var e=this[N],t=arguments.length,n=Array(t),r=0;r<t;r++)n[r]=arguments[r];return e.ot(e.j.length,0,n),e.j.length},pop:function(){return this.splice(Math.max(this[N].j.length-1,0),1)[0]},shift:function(){return this.splice(0,1)[0]},unshift:function(){for(var e=this[N],t=arguments.length,n=Array(t),r=0;r<t;r++)n[r]=arguments[r];return e.ot(0,0,n),e.j.length},reverse:function(){return L.trackingDerivation&&t(37,`reverse`),this.replace(this.slice().reverse()),this},sort:function(){L.trackingDerivation&&t(37,`sort`);var e=this.slice();return e.sort.apply(e,arguments),this.replace(e),this},remove:function(e){var t=this[N],n=t.ft(t.j).indexOf(e);return n>-1&&(this.splice(n,1),!0)}};A(`at`,It),A(`concat`,It),A(`flat`,It),A(`includes`,It),A(`indexOf`,It),A(`join`,It),A(`lastIndexOf`,It),A(`slice`,It),A(`toString`,It),A(`toLocaleString`,It),A(`toSorted`,It),A(`toSpliced`,It),A(`with`,It),A(`every`,j),A(`filter`,j),A(`find`,j),A(`findIndex`,j),A(`findLast`,j),A(`findLastIndex`,j),A(`flatMap`,j),A(`forEach`,j),A(`map`,j),A(`some`,j),A(`toReversed`,j),A(`reduce`,Lt),A(`reduceRight`,Lt);var fr,pr,mr=f(`ObservableArrayAdministration`,ur),hr={},gr=`add`,_r=function(){function e(e,n,r){var i=this;n===void 0&&(n=le),r===void 0&&(r=`ObservableMap`),this.Jt=void 0,this.tt=void 0,this[N]=hr,this.vt=void 0,this.dt=void 0,this.lt=void 0,this.et=void 0,this.ut=void 0,this.dehancer=void 0,this.Jt=n,this.tt=r,a(Map)||t(18),Qt((function(){i.lt=ce(`ObservableMap.keys()`),i.vt=new Map,i.dt=new Map,e&&i.merge(e)}))}var n=e.prototype;return n.it=function(e){return this.vt.has(e)},n.has=function(e){var t=this;if(!L.trackingDerivation)return this.it(e);var n=this.dt.get(e);if(!n){var r=n=new In(this.it(e),ue,`ObservableMap.key?`,!1);this.dt.set(e,r),ft(r,(function(){return t.dt.delete(e)}))}return n.get()},n.set=function(e,t){var n=this.it(e);if(At(this)){var r=Mt(this,{type:n?cr:gr,object:this,newValue:t,name:e});if(!r)return this;t=r.newValue}return n?this.rn(e,t):this.en(e,t),this},n.delete=function(e){var t=this;if(At(this)&&!Mt(this,{type:`delete`,object:this,name:e}))return!1;if(this.it(e)){var n=Nt(this),r=n?{observableKind:`map`,debugObjectName:this.tt,type:`delete`,object:this,oldValue:this.vt.get(e).Ot,name:e}:null;return Et((function(){var n;t.lt.reportChanged(),(n=t.dt.get(e))==null||n.gt(!1),t.vt.get(e).gt(void 0),t.vt.delete(e)})),n&&Pt(this,r),!0}return!1},n.rn=function(e,t){var n=this.vt.get(e);if((t=n.xt(t))!==L.UNCHANGED){var r=Nt(this),i=r?{observableKind:`map`,debugObjectName:this.tt,type:cr,object:this,oldValue:n.Ot,name:e,newValue:t}:null;n.gt(t),r&&Pt(this,i)}},n.en=function(e,t){var n=this;Et((function(){var r,i=new In(t,n.Jt,`ObservableMap.key`,!1);n.vt.set(e,i),t=i.Ot,(r=n.dt.get(e))==null||r.gt(!0),n.lt.reportChanged()}));var r=Nt(this);r&&Pt(this,r?{observableKind:`map`,debugObjectName:this.tt,type:gr,object:this,name:e,newValue:t}:null)},n.get=function(e){return this.has(e)?this.Qt(this.vt.get(e).get()):this.Qt(void 0)},n.Qt=function(e){return this.dehancer===void 0?e:this.dehancer(e)},n.keys=function(){return this.lt.reportObserved(),this.vt.keys()},n.values=function(){var e=this,t=this.keys();return zt({next:function(){var n=t.next(),r=n.done;return{done:r,value:r?void 0:e.get(n.value)}}})},n.entries=function(){var e=this,t=this.keys();return zt({next:function(){var n=t.next(),r=n.done,i=n.value;return{done:r,value:r?void 0:[i,e.get(i)]}}})},n[Symbol.iterator]=function(){return this.entries()},n.forEach=function(e,t){for(var n,r=C(this);!(n=r()).done;){var i=n.value;e.call(t,i[1],i[0],this)}},n.merge=function(e){var n=this;return vr(e)&&(e=new Map(e)),Et((function(){var r,i;c(e)?function(e){var t=Object.keys(e);if(!pn)return t;var n=Object.getOwnPropertySymbols(e);return n.length?[].concat(t,n.filter((function(t){return sn.propertyIsEnumerable.call(e,t)}))):t}(e).forEach((function(t){return n.set(t,e[t])})):Array.isArray(e)?e.forEach((function(e){return n.set(e[0],e[1])})):p(e)?(r=Object.getPrototypeOf(e),i=Object.getPrototypeOf(r),Object.getPrototypeOf(i)!==null&&t(19,e),e.forEach((function(e,t){return n.set(t,e)}))):e!=null&&t(20,e)})),this},n.clear=function(){var e=this;Et((function(){We((function(){for(var t,n=C(e.keys());!(t=n()).done;)e.delete(t.value)}))}))},n.replace=function(e){var n=this;return Et((function(){for(var r,i=function(e){if(p(e)||vr(e))return e;if(Array.isArray(e))return new Map(e);if(c(e)){var n=new Map;for(var r in e)n.set(r,e[r]);return n}return t(21,e)}(e),a=new Map,o=!1,s=C(n.vt.keys());!(r=s()).done;){var l=r.value;if(!i.has(l))if(n.delete(l))o=!0;else{var u=n.vt.get(l);a.set(l,u)}}for(var d,f=C(i.entries());!(d=f()).done;){var m=d.value,h=m[0],g=m[1],_=n.vt.has(h);if(n.set(h,g),n.vt.has(h)){var v=n.vt.get(h);a.set(h,v),_||(o=!0)}}if(!o)if(n.vt.size!==a.size)n.lt.reportChanged();else for(var y=n.vt.keys(),b=a.keys(),x=y.next(),S=b.next();!x.done;){if(x.value!==S.value){n.lt.reportChanged();break}x=y.next(),S=b.next()}n.vt=a})),this},n.toString=function(){return`[object ObservableMap]`},n.toJSON=function(){return Array.from(this)},n._t=function(e){return k(this,e)},n.St=function(e){return jt(this,e)},S(e,[{key:`size`,get:function(){return this.lt.reportObserved(),this.vt.size}},{key:Symbol.toStringTag,get:function(){return`Map`}}])}(),vr=f(`ObservableMap`,_r),yr={},br=function(){function e(e,n,r){var i=this;n===void 0&&(n=le),r===void 0&&(r=`ObservableSet`),this.tt=void 0,this[N]=yr,this.vt=new Set,this.st=void 0,this.ut=void 0,this.et=void 0,this.dehancer=void 0,this.Jt=void 0,this.tt=r,a(Set)||t(22),this.Jt=function(e,t){return n(e,t,r)},Qt((function(){i.st=ce(i.tt),e&&i.replace(e)}))}var n=e.prototype;return n.Qt=function(e){return this.dehancer===void 0?e:this.dehancer(e)},n.clear=function(){var e=this;Et((function(){We((function(){for(var t,n=C(e.vt.values());!(t=n()).done;)e.delete(t.value)}))}))},n.forEach=function(e,t){for(var n,r=C(this);!(n=r()).done;){var i=n.value;e.call(t,i,i,this)}},n.add=function(e){var t=this;if(At(this)){var n=Mt(this,{type:gr,object:this,newValue:e});if(!n)return this;e=n.newValue}if(!this.has(e)){Et((function(){t.vt.add(t.Jt(e,void 0)),t.st.reportChanged()}));var r=Nt(this);r&&Pt(this,r?{observableKind:`set`,debugObjectName:this.tt,type:gr,object:this,newValue:e}:null)}return this},n.delete=function(e){var t=this;if(At(this)&&!Mt(this,{type:`delete`,object:this,oldValue:e}))return!1;if(this.has(e)){var n=Nt(this),r=n?{observableKind:`set`,debugObjectName:this.tt,type:`delete`,object:this,oldValue:e}:null;return Et((function(){t.st.reportChanged(),t.vt.delete(e)})),n&&Pt(this,r),!0}return!1},n.has=function(e){return this.st.reportObserved(),this.vt.has(this.Qt(e))},n.entries=function(){var e=this.values();return Bt({next:function(){var t=e.next(),n=t.value,r=t.done;return r?{value:void 0,done:r}:{value:[n,n],done:r}}})},n.keys=function(){return this.values()},n.values=function(){this.st.reportObserved();var e=this,t=this.vt.values();return Bt({next:function(){var n=t.next(),r=n.done;return r?{value:void 0,done:r}:{value:e.Qt(n.value),done:r}}})},n.intersection=function(e){return m(e)&&!xr(e)?e.intersection(this):new Set(this).intersection(e)},n.union=function(e){return m(e)&&!xr(e)?e.union(this):new Set(this).union(e)},n.difference=function(e){return new Set(this).difference(e)},n.symmetricDifference=function(e){return m(e)&&!xr(e)?e.symmetricDifference(this):new Set(this).symmetricDifference(e)},n.isSubsetOf=function(e){return new Set(this).isSubsetOf(e)},n.isSupersetOf=function(e){return new Set(this).isSupersetOf(e)},n.isDisjointFrom=function(e){return m(e)&&!xr(e)?e.isDisjointFrom(this):new Set(this).isDisjointFrom(e)},n.replace=function(e){var n=this;return xr(e)&&(e=new Set(e)),Et((function(){Array.isArray(e)||m(e)?(n.clear(),e.forEach((function(e){return n.add(e)}))):e!=null&&t(`Cannot initialize set from `+e)})),this},n._t=function(e){return k(this,e)},n.St=function(e){return jt(this,e)},n.toJSON=function(){return Array.from(this)},n.toString=function(){return`[object ObservableSet]`},n[Symbol.iterator]=function(){return this.values()},S(e,[{key:`size`,get:function(){return this.st.reportObserved(),this.vt.size}},{key:Symbol.toStringTag,get:function(){return`Set`}}])}(),xr=f(`ObservableSet`,br),Sr=Object.create(null),Cr=function(){function e(e,t,n,r){t===void 0&&(t=new Map),r===void 0&&(r=xn),this.h=void 0,this.j=void 0,this.tt=void 0,this.un=void 0,this.lt=void 0,this.ut=void 0,this.et=void 0,this.v=void 0,this.p=void 0,this.on=void 0,this.sn=void 0,this.h=e,this.j=t,this.tt=n,this.un=r,this.lt=new _n(`ObservableObject.keys`),this.p=c(this.h)}var n=e.prototype;return n.O=function(e){return this.j.get(e).get()},n.S=function(e,t){var n=this.j.get(e);if(n instanceof Rn)return n.set(t),!0;if(At(this)){var r=Mt(this,{type:cr,object:this.v||this.h,name:e,newValue:t});if(!r)return null;t=r.newValue}if((t=n.xt(t))!==L.UNCHANGED){var i=Nt(this),a=i?{type:cr,observableKind:`object`,debugObjectName:this.tt,object:this.v||this.h,oldValue:n.Ot,name:e,newValue:t}:null;n.gt(t),i&&Pt(this,a)}return!0},n.ct=function(e){return L.trackingDerivation&&!g(this.h,e)&&this.it(e),this.h[e]},n.ht=function(e,t,n){return n===void 0&&(n=!1),g(this.h,e)?this.j.has(e)?this.S(e,t):n?Reflect.set(this.h,e,t):(this.h[e]=t,!0):this.s(e,{value:t,enumerable:!0,writable:!0,configurable:!0},this.un,n)},n.it=function(e){if(!L.trackingDerivation)return e in this.h;this.sn||=new Map;var t=this.sn.get(e);return t||(t=new In(e in this.h,ue,`ObservableObject.key?`,!1),this.sn.set(e,t)),t.get()},n.o=function(e,n){if(!0===n&&(n=this.un),!1!==n){if(!(e in this.h)){var r;if((r=this.h[gn])!=null&&r[e])return;t(1,n.i,this.tt+`.`+e.toString())}for(var i=this.h;i&&i!==sn;){var a=an(i,e);if(a){var o=n.o(this,e,a,i);if(o===0)return;if(o===1)break}i=Object.getPrototypeOf(i)}Wt(this,0,e)}},n.s=function(e,t,n,r){if(r===void 0&&(r=!1),!0===n&&(n=this.un),!1===n)return this.l(e,t,r);var i=n.s(this,e,t,r);return i&&Wt(this,0,e),i},n.l=function(e,t,n){n===void 0&&(n=!1);try{$e();var r=this.Ut(e);if(!r)return r;if(At(this)){var i=Mt(this,{object:this.v||this.h,name:e,type:gr,newValue:t.value});if(!i)return null;var a=i.newValue;t.value!==a&&(t=ee({},t,{value:a}))}if(n){if(!Reflect.defineProperty(this.h,e,t))return!1}else on(this.h,e,t);this.fn(e,t.value)}finally{et()}return!0},n.g=function(e,t,n,r){r===void 0&&(r=!1);try{$e();var i=this.Ut(e);if(!i)return i;if(At(this)){var a=Mt(this,{object:this.v||this.h,name:e,type:gr,newValue:t});if(!a)return null;t=a.newValue}var o=Ht(e),s={configurable:!L.safeDescriptors||this.p,enumerable:!0,get:o.get,set:o.set};if(r){if(!Reflect.defineProperty(this.h,e,s))return!1}else on(this.h,e,s);var c=new In(t,n,`ObservableObject.key`,!1);this.j.set(e,c),this.fn(e,c.Ot)}finally{et()}return!0},n.m=function(e,t,n){n===void 0&&(n=!1);try{$e();var r=this.Ut(e);if(!r)return r;if(At(this)&&!Mt(this,{object:this.v||this.h,name:e,type:gr,newValue:void 0}))return null;t.name||=`ObservableObject.key`,t.context=this.v||this.h;var i=Ht(e),a={configurable:!L.safeDescriptors||this.p,enumerable:!1,get:i.get,set:i.set};if(n){if(!Reflect.defineProperty(this.h,e,a))return!1}else on(this.h,e,a);this.j.set(e,new Rn(t)),this.fn(e,void 0)}finally{et()}return!0},n.Ut=function(e,t){if(t===void 0&&(t=!1),!g(this.h,e))return!0;if(At(this)&&!Mt(this,{object:this.v||this.h,name:e,type:`remove`}))return null;try{var n;$e();var r=Nt(this),i=this.j.get(e),a=void 0;if(!i&&r&&(a=an(this.h,e)?.value),t){if(!Reflect.deleteProperty(this.h,e))return!1}else delete this.h[e];i&&(this.j.delete(e),i instanceof In&&(a=i.Ot),nt(i)),this.lt.reportChanged(),(n=this.sn)==null||(n=n.get(e))==null||n.set(e in this.h),r&&r&&Pt(this,{type:`remove`,observableKind:`object`,object:this.v||this.h,debugObjectName:this.tt,oldValue:a,name:e})}finally{et()}return!0},n._t=function(e){return k(this,e)},n.St=function(e){return jt(this,e)},n.fn=function(e,t){var n,r=Nt(this);r&&r&&Pt(this,r?{type:gr,observableKind:`object`,debugObjectName:this.tt,object:this.v||this.h,name:e,newValue:t}:null),(n=this.sn)==null||(n=n.get(e))==null||n.set(!0),this.lt.reportChanged()},n.rt=function(){return this.lt.reportObserved(),mn(this.h)},n.nt=function(){return this.lt.reportObserved(),Object.keys(this.h)},e}(),wr=f(`ObservableObjectAdministration`,Cr),Tr=Gt(0),Er=function(){var e=!1,t={};return Object.defineProperty(t,`0`,{set:function(){e=!0}}),Object.create(t)[0]=1,!1===e}(),Dr=0,Or=function(){};fr=Or,pr=Array.prototype,Object.setPrototypeOf?Object.setPrototypeOf(fr.prototype,pr):fr.prototype.__proto__===void 0?fr.prototype=pr:fr.prototype.__proto__=pr;var kr=function(e){function t(t,n,r,i){var a;return r===void 0&&(r=`ObservableArray`),i===void 0&&(i=!1),a=e.call(this)||this,Qt((function(){var e=new ur(r,n,i,!0);e.v=a,d(a,N,e),t&&t.length&&a.spliceWithArray(0,0,t),Er&&Object.defineProperty(a,`0`,Tr)})),a}ne(t,e);var n=t.prototype;return n.concat=function(){this[N].st.reportObserved();var e=[...arguments];return Array.prototype.concat.apply(this.slice(),e.map((function(e){return Rt(e)?e.slice():e})))},n[Symbol.iterator]=function(){var e=this,t=0;return tn({next:function(){return t<e.length?{value:e[t++],done:!1}:{done:!0,value:void 0}}})},S(t,[{key:`length`,get:function(){return this[N].Ft()},set:function(e){this[N].Xt(e)}},{key:Symbol.toStringTag,get:function(){return`Array`}}])}(Or);Object.entries(dr).forEach((function(e){var t=e[0];t!==`concat`&&u(kr.prototype,t,e[1])})),qt(1e3);var Ar=sn.toString,jr=n().Iterator?.prototype||{};[`Symbol`,`Map`,`Set`].forEach((function(e){n()[e]===void 0&&t(`MobX requires global '`+e+`' to be available or polyfilled`)})),typeof __MOBX_DEVTOOLS_GLOBAL_HOOK__==`object`&&__MOBX_DEVTOOLS_GLOBAL_HOOK__.injectMobx({spy:at,extras:{getDebugName:Zt},$mobx:N}),e.$mobx=N,e.FlowCancellationError=nr,e.ObservableMap=_r,e.ObservableSet=br,e.Reaction=Gn,e._allowStateChanges=Le,e._allowStateChangesInsideComputed=st,e._allowStateReadsEnd=Je,e._allowStateReadsStart=qe,e._autoAction=$n,e._endAction=Ie,e._getAdministration=Xt,e._getGlobalState=function(){return L},e._interceptReads=function(e,t,n){var r;return vr(e)||Rt(e)||Ln(e)?r=Xt(e):Ut(e)&&(r=Xt(e,t)),r.dehancer=typeof t==`function`?t:n,function(){r.dehancer=void 0}},e._isComputingDerivation=function(){return L.trackingDerivation!==null},e._resetGlobalState=function(){var e=new Hn;for(var t in e)Vn.indexOf(t)===-1&&(L[t]=e[t]);L.allowStateChanges=!L.enforceActions},e._startAction=Fe,e.action=Qn,e.autorun=lt,e.comparer=yn,e.computed=jn,e.configure=function(e){!0===e.isolateGlobalState&&function(){if((L.pendingReactions.length||L.inBatch||L.isRunningReactions)&&t(36),Wn=!0,Un){var e=n();--e.__mobxInstanceCount==0&&(e.__mobxGlobals=void 0),L=new Hn}}();var r,i,a=e.useProxies,o=e.enforceActions;if(a!==void 0&&(L.useProxies=a===`always`||a!==`never`&&typeof Proxy<`u`),a===`ifavailable`&&(L.verifyProxies=!0),o!==void 0){var s=o===`always`?`always`:o===`observed`;L.enforceActions=s,L.allowStateChanges=!0!==s&&s!==`always`}[`computedRequiresReaction`,`reactionRequiresObservable`,`observableRequiresReaction`,`disableErrorBoundaries`,`safeDescriptors`].forEach((function(t){t in e&&(L[t]=!!e[t])})),L.allowStateReads=!L.observableRequiresReaction,e.reactionScheduler&&(r=e.reactionScheduler,i=Kn,Kn=function(e){return r((function(){return i(e)}))})},e.createAtom=ce,e.defineProperty=function(e,n,r){if(Ut(e))return e[N].l(n,r);t(39)},e.entries=function(e){return Ut(e)?St(e).map((function(t){return[t,e[t]]})):vr(e)?St(e).map((function(t){return[t,e.get(t)]})):xr(e)?Array.from(e.entries()):Rt(e)?e.map((function(e,t){return[t,e]})):void t(7)},e.extendObservable=mt,e.flow=ar,e.flowResult=function(e){return e},e.get=function(e,n){if(Ct(e,n))return Ut(e)?e[N].ct(n):vr(e)?e.get(n):Rt(e)?e[n]:void t(11)},e.getAtom=Yt,e.getDebugName=Zt,e.getDependencyTree=function(e,t){return ht(Yt(e,t))},e.getObserverTree=function(e,t){return gt(Yt(e,t))},e.has=Ct,e.intercept=function(e,t,n){return a(n)?function(e,t,n){return Xt(e,t).St(n)}(e,t,n):function(e,t){return Xt(e).St(t)}(e,t)},e.isAction=ct,e.isBoxedObservable=Ln,e.isComputed=function(e){return yt(e)},e.isComputedProp=function(e,t){return yt(e,t)},e.isFlow=vt,e.isFlowCancellationError=function(e){return e instanceof nr},e.isObservable=xt,e.isObservableArray=Rt,e.isObservableMap=vr,e.isObservableObject=Ut,e.isObservableProp=function(e,t){return bt(e,t)},e.isObservableSet=xr,e.keys=St,e.makeAutoObservable=function(e,t,n){return c(e)?mt(e,e,t,n):(Qt((function(){var r=Vt(e,n)[N];if(!e[sr]){var i=Object.getPrototypeOf(e),a=new Set([].concat(mn(e),mn(i)));a.delete(`constructor`),a.delete(N),u(i,sr,a)}e[sr].forEach((function(e){return r.o(e,!t||!(e in t)||t[e])}))})),e)},e.makeObservable=function(e,t,n){return Qt((function(){var r=Vt(e,n)[N];t??=function(e){return g(e,gn)||u(e,gn,ee({},e[gn])),e[gn]}(e),mn(t).forEach((function(e){return r.o(e,t[e])}))})),e},e.observable=On,e.observe=function(e,t,n,r){return a(n)?function(e,t,n,r){return Xt(e,t)._t(n,r)}(e,t,n,r):function(e,t,n){return Xt(e)._t(t,n)}(e,t,n)},e.onBecomeObserved=dt,e.onBecomeUnobserved=ft,e.onReactionError=function(e){return L.globalReactionErrorHandlers.push(e),function(){var t=L.globalReactionErrorHandlers.indexOf(e);t>=0&&L.globalReactionErrorHandlers.splice(t,1)}},e.override=bn,e.ownKeys=wt,e.reaction=function(e,t,n){function r(){if(p=!1,!h.isDisposed){var t=!1,r=s;h.track((function(){var n=Le(!1,(function(){return e(h)}));t=f||!m(s,n),s=n})),(f&&n.fireImmediately||!f&&t)&&l(s,r,h),f=!1}}var i;n===void 0&&(n=ln);var a,o,s,c=n.name??`Reaction`,l=Qn(c,n.onError?(a=n.onError,o=t,function(){try{return o.apply(this,arguments)}catch(e){a.call(this,e)}}):t),u=!n.scheduler&&!n.delay,d=ut(n),f=!0,p=!1,m=n.compareStructural?yn.structural:n.equals||yn.default,h=new Gn(c,(function(){f||u?r():p||(p=!0,d(r))}),n.onError,n.requiresObservable);return(i=n)!=null&&(i=i.signal)!=null&&i.aborted||h.Y(),h.Z(n?.signal)},e.remove=function(e,n){Ut(e)?e[N].Ut(n):vr(e)||xr(e)?e.delete(n):Rt(e)?(typeof n!=`number`&&(n=parseInt(n,10)),e.splice(n,1)):t(9)},e.runInAction=st,e.set=function e(n,r,i){if(arguments.length!==2||xr(n))Ut(n)?n[N].ht(r,i):vr(n)?n.set(r,i):xr(n)?n.add(r):Rt(n)?(typeof r!=`number`&&(r=parseInt(r,10)),r<0&&t(`Invalid index: '`+r+`'`),$e(),r>=n.length&&(n.length=r+1),n[r]=i,et()):t(8);else{$e();var a=r;try{for(var o in a)e(n,o,a[o])}finally{et()}}},e.spy=at,e.toJS=function(e){return function e(t,n){if(typeof t!=`object`||!t||t instanceof Date||!xt(t))return t;if(Ln(t)||I(t))return e(t.get(),n);if(n.has(t))return n.get(t);if(Rt(t)){var r=Tt(n,t,Array(t.length));return t.forEach((function(t,i){r[i]=e(t,n)})),r}if(xr(t)){var i=Tt(n,t,new Set);return t.forEach((function(t){i.add(e(t,n))})),i}if(vr(t)){var a=Tt(n,t,new Map);return t.forEach((function(t,r){a.set(r,e(t,n))})),a}var o=Tt(n,t,{});return wt(t).forEach((function(r){sn.propertyIsEnumerable.call(t,r)&&(o[r]=e(t[r],n))})),o}(e,new Map)},e.trace=function(){},e.transaction=Et,e.untracked=We,e.values=function(e){return Ut(e)?St(e).map((function(t){return e[t]})):vr(e)?St(e).map((function(t){return e.get(t)})):xr(e)?Array.from(e.values()):Rt(e)?e.slice():void t(6)},e.when=function(e,t,n){return arguments.length===1||t&&typeof t==`object`?Ot(e,t):Dt(e,t,n||{})}})),jg=ye((e=>{Object.defineProperty(e,`__esModule`,{value:!0});var t={0:`Invalid value for configuration 'enforceActions', expected 'never', 'always' or 'observed'`,1:function(e,t){return`Cannot apply '`+e+`' to '`+t.toString()+`': Field not found.`},5:`'keys()' can only be used on observable objects, arrays, sets and maps`,6:`'values()' can only be used on observable objects, arrays, sets and maps`,7:`'entries()' can only be used on observable objects, arrays and maps`,8:`'set()' can only be used on observable objects, arrays and maps`,9:`'remove()' can only be used on observable objects, arrays and maps`,10:`'has()' can only be used on observable objects, arrays and maps`,11:`'get()' can only be used on observable objects, arrays and maps`,12:`Invalid annotation`,13:`Dynamic observable objects cannot be frozen. If you're passing observables to 3rd party component/function that calls Object.freeze, pass copy instead: toJS(observable)`,14:`Intercept handlers should return nothing or a change object`,15:`Observable arrays cannot be frozen. If you're passing observables to 3rd party component/function that calls Object.freeze, pass copy instead: toJS(observable)`,16:`Modification exception: the internal structure of an observable array was changed.`,17:function(e,t){return`[mobx.array] Index out of bounds, `+e+` is larger than `+t},18:`mobx.map requires Map polyfill for the current browser. Check babel-polyfill or core-js/es6/map.js`,19:function(e){return`Cannot initialize from classes that inherit from Map: `+e.constructor.name},20:function(e){return`Cannot initialize map from `+e},21:function(e){return`Cannot convert to map from '`+e+`'`},22:`mobx.set requires Set polyfill for the current browser. Check babel-polyfill or core-js/es6/set.js`,23:`It is not possible to get index atoms from arrays`,24:function(e){return`Cannot obtain administration from `+e},25:function(e,t){return`the entry '`+e+`' does not exist in the observable map '`+t+`'`},26:`please specify a property`,27:function(e,t){return`no observable property '`+e.toString()+`' found on the observable object '`+t+`'`},28:function(e){return`Cannot obtain atom from `+e},29:`Expecting some object`,30:`invalid action stack. did you forget to finish an action?`,31:`missing option for computed: get`,32:function(e,t){return`Cycle detected in computation `+e+`: `+t},33:function(e){return`The setter of computed value '`+e+`' is trying to update itself. Did you intend to update an _observable_ value, instead of the computed property?`},34:function(e){return`[ComputedValue '`+e+`'] It is not possible to assign a new value to a computed value.`},35:"There are multiple, different versions of MobX active. Make sure MobX is loaded only once or use `configure({ isolateGlobalState: true })`",36:`isolateGlobalState should be called before MobX is running any reactions`,37:function(e){return"[mobx] `observableArray."+e+"()` mutates the array in-place, which is not allowed inside a derivation. Use `array.slice()."+e+"()` instead"},38:`'ownKeys()' can only be used on observable objects`,39:`'defineProperty()' can only be used on observable objects`};function n(e){var n=[...arguments].slice(1),r=typeof e==`string`?e:t[e];throw typeof r==`function`&&(r=r.apply(null,n)),Error(`[MobX] `+r)}var r={};function i(){return typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:r}var a=Object.assign,o=Object.getOwnPropertyDescriptor,s=Object.defineProperty,c=Object.prototype,l=[];Object.freeze(l);var u={};Object.freeze(u);var d=typeof Proxy<`u`,f=Object.toString();function p(){d||n("`Proxy` objects are not available in the current environment. Please configure MobX to enable a fallback implementation.`")}function m(e){P.verifyProxies&&n(`MobX is currently configured to be able to run in ES5 mode, but in ES5 MobX won't be able to `+e)}function h(){return++P.mobxGuid}function g(e){var t=!1;return function(){if(!t)return t=!0,e.apply(this,arguments)}}var _=function(){};function v(e){return typeof e==`function`}function y(e){switch(typeof e){case`string`:case`symbol`:case`number`:return!0}return!1}function b(e){return typeof e==`object`&&!!e}function x(e){if(!b(e))return!1;var t=Object.getPrototypeOf(e);if(t==null)return!0;var n=Object.hasOwnProperty.call(t,`constructor`)&&t.constructor;return typeof n==`function`&&n.toString()===f}function S(e){var t=e?.constructor;return t?t.name===`GeneratorFunction`||t.displayName===`GeneratorFunction`:!1}function C(e,t,n){s(e,t,{enumerable:!1,writable:!0,configurable:!0,value:n})}function ee(e,t,n){s(e,t,{enumerable:!1,writable:!1,configurable:!0,value:n})}function te(e,t){var n=`isMobX`+e;return t.prototype[n]=!0,function(e){return b(e)&&e[n]===!0}}function ne(e){return e!=null&&Object.prototype.toString.call(e)===`[object Map]`}function re(e){return Object.getPrototypeOf(Object.getPrototypeOf(Object.getPrototypeOf(e)))===null}function ie(e){return e!=null&&Object.prototype.toString.call(e)===`[object Set]`}var ae=Object.getOwnPropertySymbols!==void 0;function w(e){var t=Object.keys(e);if(!ae)return t;var n=Object.getOwnPropertySymbols(e);return n.length?[].concat(t,n.filter(function(t){return c.propertyIsEnumerable.call(e,t)})):t}var T=typeof Reflect<`u`&&Reflect.ownKeys?Reflect.ownKeys:ae?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Object.getOwnPropertyNames;function oe(e){return typeof e==`string`?e:typeof e==`symbol`?e.toString():new String(e).toString()}function se(e){return e===null?null:typeof e==`object`?``+e:e}function ce(e,t){return c.hasOwnProperty.call(e,t)}var le=Object.getOwnPropertyDescriptors||function(e){var t={};return T(e).forEach(function(n){t[n]=o(e,n)}),t};function ue(e,t){return!!(e&t)}function E(e,t,n){return n?e|=t:e&=~t,e}function de(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function fe(e,t,n){if(be())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,t);var i=new(e.bind.apply(e,r));return n&&xe(i,n.prototype),i}function pe(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,Se(r.key),r)}}function me(e,t,n){return t&&pe(e.prototype,t),n&&pe(e,n),Object.defineProperty(e,`prototype`,{writable:!1}),e}function he(e,t){var n=typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=Ce(e))||t&&e&&typeof e.length==`number`){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw TypeError(`Invalid attempt to iterate non-iterable instance.
59
59
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function ge(){return ge=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},ge.apply(null,arguments)}function _e(e){return _e=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},_e(e)}function ve(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,xe(e,t)}function ye(e){try{return Function.toString.call(e).indexOf(`[native code]`)!==-1}catch{return typeof e==`function`}}function be(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(be=function(){return!!e})()}function xe(e,t){return xe=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},xe(e,t)}function D(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Se(e){var t=D(e,`string`);return typeof t==`symbol`?t:t+``}function Ce(e,t){if(e){if(typeof e==`string`)return de(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?de(e,t):void 0}}function we(e){var t=typeof Map==`function`?new Map:void 0;return we=function(e){if(e===null||!ye(e))return e;if(typeof e!=`function`)throw TypeError(`Super expression must either be null or a function`);if(t!==void 0){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return fe(e,arguments,_e(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),xe(n,e)},we(e)}var Te=Symbol(`mobx-stored-annotations`);function Ee(e){function t(t,n){if(Ae(n))return e.decorate_20223_(t,n);De(t,n,e)}return Object.assign(t,e)}function De(e,t,r){ce(e,Te)||C(e,Te,ge({},e[Te])),Ke(r)&&!ce(e[Te],t)&&n(`'`+(e.constructor.name+`.prototype.`+t.toString())+`' is decorated with 'override', but no such decorated member was found on prototype.`),Oe(e,r,t),Ke(r)||(e[Te][t]=r)}function Oe(e,t,r){if(!Ke(t)&&ce(e[Te],r)){var i=e.constructor.name+`.prototype.`+r.toString(),a=e[Te][r].annotationType_,o=t.annotationType_;n(`Cannot apply '@`+o+`' to '`+i+`':`+(`
@@ -97,7 +97,7 @@ Use 'override' annotation for methods overridden by subclass.`)}}var oa=fa(0),sa
97
97
  `).map(e=>n+e).join(`
98
98
  `)}function eS(e){let t=new TextEncoder;return e.split(/\s+/).filter(e=>e.length>0).map(e=>String.fromCharCode(...t.encode(e).slice(0,1))).join(``)}function tS(e,t){let n=[];for(let e of t){if(typeof e==`object`&&e)throw Ub(`join`,2,`list of strings/primitives`,`list element of type ${nS(e)}`);n.push(String(e))}return n.join(e)}function nS(e){return Array.isArray(e)?`array`:e instanceof Map?`Map`:e instanceof Set?`Set`:`object`}function rS(e){return Kx(e,`-`)}function iS(e){return e.toLowerCase()}function aS(e,t){return`\n${$x(e,t)}`}function oS(e){return e.replace(/\s+/g,``)}function sS(e,t,n){return n===1?e:t}function cS(...e){return e.map(e=>`"${e}"`).join(` `)}function lS(e){return e.replace(/[\\.+*?()|[\]{}^$]/g,`\\$&`)}function uS(e,t){return t.repeat(Math.max(0,e))}function dS(e,t,n){return jx(e,n).join(t)}function fS(e){return Kx(e,`_`)}function pS(e,t){let n=jx(e,t),r={};for(let e=0;e<n.length;e++)r[`_${e}`]=n[e];return r}function mS(e,t){return jx(e,t)}function hS(e,t,n){let r=gS(n,e,t),i={};for(let e=0;e<r.length;e++)i[`_${e}`]=r[e]??``;return i}function gS(e,t,n){if(n===0)return[];let r=jx(t,e);if(n<0||r.length<=n)return r;let i=r.slice(0,n-1),a=r.slice(n-1).join(t);return[...i,a]}function _S(...e){return e.map(e=>`'${e}'`).join(` `)}function vS(e,t,n){let r=Ax(n),i=t<0||t>r.length?r.length:t,a=Math.min(Math.max(0,e),i);return r.slice(a,i).join(``)}function yS(e){let t=``;for(let n of e)bS(n)?t+=n.toLowerCase():xS(n)?t+=n.toUpperCase():t+=n;return t}function bS(e){return e!==e.toLowerCase()&&e===e.toUpperCase()}function xS(e){return e!==e.toUpperCase()&&e===e.toLowerCase()}function SS(e){return e.replace(/\b([a-zA-Z])/g,e=>e.toUpperCase())}function CS(e){return e.trim()}function wS(e,t){if(e.length===0)return t;let n=new Set(Ax(e)),r=Ax(t),i=0;for(;i<r.length&&n.has(r[i]);)i+=1;let a=r.length;for(;a>i&&n.has(r[a-1]);)--a;return r.slice(i,a).join(``)}function TS(e,t){return t.startsWith(e)?t.slice(e.length):t}function ES(e,t){return t.endsWith(e)?t.slice(0,t.length-e.length):t}function DS(e,t){let n=Ax(t);if(e<0){let r=-e;return r>=n.length?t:n.slice(n.length-r).join(``)}return e>=n.length?t:n.slice(0,e).join(``)}function OS(e){return e.replace(/\b([A-Z])/g,e=>e.toLowerCase())}function kS(e){return e.toUpperCase()}function AS(e,t){return jS(e,`
99
99
  `,t)}function jS(e,t,n){if(e<=0)return n;let r=[];for(let t of n.split(`
100
- `)){let n=``;for(let i of t.split(/\s+/))i.length!==0&&(n.length===0?n=i:n.length+1+i.length<=e?n+=` ${i}`:(r.push(n),n=i));n.length>0&&r.push(n)}return r.join(t)}function MS(e,t,n){return jS(e,t,n)}function NS(){return{abbrev:{fn:(e,t)=>Mx(e,t),argTypes:[`int`,`string`],arity:{kind:`exact`}},abbrevboth:{fn:(e,t,n)=>Nx(e,t,n),argTypes:[`int`,`int`,`string`],arity:{kind:`exact`}},camelcase:{fn:e=>Jx(e),argTypes:[`string`],arity:{kind:`exact`},returnType:`string`},cat:{fn:(...e)=>Yx(...e),argTypes:[`string`],arity:{kind:`variadic`}},contains:{fn:(e,t)=>Xx(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},hasPrefix:{fn:(e,t)=>Zx(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},hasSuffix:{fn:(e,t)=>Qx(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},indent:{fn:(e,t)=>$x(e,t),argTypes:[`int`,`string`],arity:{kind:`exact`}},initials:{fn:e=>eS(e),argTypes:[`string`],arity:{kind:`exact`}},join:{fn:(e,t)=>tS(e,t),argTypes:[`string`,`list`],arity:{kind:`exact`}},kebabcase:{fn:e=>rS(e),argTypes:[`string`],arity:{kind:`exact`},returnType:`string`},lower:{fn:e=>iS(e),argTypes:[`string`],arity:{kind:`exact`}},nindent:{fn:(e,t)=>aS(e,t),argTypes:[`int`,`string`],arity:{kind:`exact`}},nospace:{fn:e=>oS(e),argTypes:[`string`],arity:{kind:`exact`},returnType:`string`},plural:{fn:(e,t,n)=>sS(e,t,n),argTypes:[`string`,`string`,`int`],arity:{kind:`exact`},returnType:`string`},quote:{fn:(...e)=>cS(...e),argTypes:[`string`],arity:{kind:`variadic`}},regexQuoteMeta:{fn:e=>lS(e),argTypes:[`string`],arity:{kind:`exact`},returnType:`string`},repeat:{fn:(e,t)=>uS(e,t),argTypes:[`int`,`string`],arity:{kind:`exact`}},replace:{fn:(e,t,n)=>dS(e,t,n),argTypes:[`string`,`string`,`string`],arity:{kind:`exact`}},snakecase:{fn:e=>fS(e),argTypes:[`string`],arity:{kind:`exact`},returnType:`string`},split:{fn:(e,t)=>pS(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},splitList:{fn:(e,t)=>mS(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},splitn:{fn:(e,t,n)=>hS(e,t,n),argTypes:[`string`,`int`,`string`],arity:{kind:`exact`},returnType:`dict`},squote:{fn:(...e)=>_S(...e),argTypes:[`string`],arity:{kind:`variadic`}},substr:{fn:(e,t,n)=>vS(e,t,n),argTypes:[`int`,`int`,`string`],arity:{kind:`exact`}},swapcase:{fn:e=>yS(e),argTypes:[`string`],arity:{kind:`exact`},returnType:`string`},title:{fn:e=>SS(e),argTypes:[`string`],arity:{kind:`exact`}},trim:{fn:e=>CS(e),argTypes:[`string`],arity:{kind:`exact`}},trimAll:{fn:(e,t)=>wS(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},trimPrefix:{fn:(e,t)=>TS(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},trimSuffix:{fn:(e,t)=>ES(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},trunc:{fn:(e,t)=>DS(e,t),argTypes:[`int`,`string`],arity:{kind:`exact`}},untitle:{fn:e=>OS(e),argTypes:[`string`],arity:{kind:`exact`}},upper:{fn:e=>kS(e),argTypes:[`string`],arity:{kind:`exact`}},wrap:{fn:(e,t)=>AS(e,t),argTypes:[`int`,`string`],arity:{kind:`exact`}},wrapWith:{fn:(e,t,n)=>MS(e,t,n),argTypes:[`int`,`string`,`string`],arity:{kind:`exact`}}}}function PS(e,t){if(!(e instanceof q))throw TypeError(`template function expected a RichText fragment, got ${typeof e==`object`?Object.prototype.toString.call(e):typeof e}`);let n=e.copy();return n.style=$c(e.style,t),n}function FS(e){return{fn:(t=>PS(t,e)),argTypes:[`liftable`],arity:{kind:`exact`},returnType:`T`}}function IS(e){return{fn:((t,n)=>PS(n,new G({[e]:W.parse(t)}))),argTypes:[`string`,`liftable`],arity:{kind:`exact`},returnType:`T`}}function LS(e,t){return new G({[e]:t})}function RS(){let e={};for(let t of Kc)e[t]=FS(LS(t,!0)),e[`not_${t}`]=FS(LS(t,!1));for(let[t,n]of Object.entries(Jc))e[t]=FS(LS(n,!0));return e}const zS={fn:((e,t)=>PS(t,G.parse(e))),argTypes:[`string`,`liftable`],arity:{kind:`exact`},returnType:`T`},BS={fn:((e,t)=>PS(t,new G({link:e}))),argTypes:[`string`,`liftable`],arity:{kind:`exact`},returnType:`T`};function VS(){return{fg:IS(`color`),bg:IS(`bgcolor`),...RS(),link:BS,style:zS}}function HS(e,t){let n;try{n=ds(e.trim())}catch(n){throw n instanceof Yo?TypeError(`${t} expected a color (#RRGGBB or #RRGGBBAA), got ${JSON.stringify(e)} — to use a palette name here, wrap it: ${t} (color ${JSON.stringify(e)}) …`,{cause:n}):n}return US(n,t,JSON.stringify(e))}function US(e,t,n){if(e.alpha===0)throw RangeError(`${t} got ${n}, which is fully transparent: it draws no colour of its own, so there is nothing to compute with — use the colour of the surface it sits on, e.g. (color "background")`);return e}function WS(e,t){return{fn:t,argTypes:e,arity:{kind:`exact`},returnType:`string`}}function GS(e,t,n,r){let i=r===void 0||e>=r.min&&e<=r.max;if(!Number.isFinite(e)||!i){let i=r===void 0?`a finite number`:`within ${r.min}..${r.max} (${r.note})`;throw RangeError(`${t}'s ${n} must be ${i}, got ${e}`)}return e}const KS=WS([`string`,`int`],((e,t)=>Ys(HS(e,`darken`),t).hex)),qS=WS([`string`,`int`],((e,t)=>Ys(HS(e,`lighten`),-t).hex)),JS={min:0,max:100,note:`0 = from, 100 = toward`},YS=WS([`string`,`string`,`float`],((e,t,n)=>fs(HS(e,`mix`),HS(t,`mix`),GS(n,`mix`,`percentage`,JS)/100).hex)),XS={min:1,max:21,note:`4.5 = AA body text, 3 = AA large text`},ZS=WS([`string`],(e=>Zs(HS(e,`contrastOn`)).hex)),QS={depth:U.TRUECOLOR},$S=e=>WS([`string`,`string`,`float`],((t,n,r)=>{let{depth:i,terminal:a}=e();return Qs(HS(t,`readableOn`),HS(n,`readableOn`),GS(r,`readableOn`,`ratio`,XS),i,void 0,a).hex})),eC={hueShift:`shiftHue`,chromaScale:`scaleChroma`,lightnessScale:`scaleLightness`,lightnessShift:`shiftLightness`};function tC(){let e={};for(let[t,n]of Object.entries(eC)){let r=t;e[n]=WS([`string`,`float`],((e,t)=>{let i={...As,[r]:GS(t,n,`amount`)};return Vs.fromRgba(HS(e,n)).applyKey(i).toRgba().hex}))}return e}function nC(e=()=>QS){return{darken:KS,lighten:qS,mix:YS,contrastOn:ZS,readableOn:$S(e),...tC()}}function rC(e,t){if(e.length%2!=0)throw RangeError(`ramp's last stop (position ${String(e[e.length-1])}) has no color — stops are <position> <color> pairs`);let n=[];for(let r=0;r<e.length;r+=2)n.push({at:e[r],color:US(Us(t,e[r+1]),`ramp`,JSON.stringify(e[r+1]))});return n}function iC(e){return{color:{fn:(t=>Us(e(),t).hex),argTypes:[`string`],arity:{kind:`exact`},returnType:`string`},ramp:{fn:((t,n,...r)=>new Fc(Vc(n),rC(r,e())).at(t).hex),argTypes:[`float`,`string`],arity:{kind:`alternating`,minimum:4},returnType:`string`}}}function aC(e){return{...VS(),...nC(e)}}new G({color:`red`,dim:!0});const oC=/^(?:(?:global|apac|au|eu|us|us-east-\d|us-west-\d|eu-west-\d|eu-central-\d)\.)?(?:anthropic\.|azure_ai\/|bedrock\/|vertex_ai\/)?claude-(?:(?<family>opus|sonnet|haiku)-(?<newMajor>\d+)(?:-(?<newMinor>\d))?|(?<oldMajor>\d+)(?:-(?<oldMinor>\d))?-(?<oldFamily>opus|sonnet|haiku))(?:[-@]\d{8})?(?:-v\d+:\d+)?(?:-latest)?$/i,sC=/^(?<family>opus|sonnet|haiku)\s+(?<major>\d+)(?:\.(?<minor>\d))?$/i;function cC(e){if(!e)return`Claude`;let t=e.trim().replace(/\s*\([^)]*\)\s*$/,``).replace(/\s*\[[^\]]*\]\s*$/,``).trim(),n=t.match(oC);if(n?.groups){let{family:e,newMajor:t,newMinor:r,oldMajor:i,oldMinor:a,oldFamily:o}=n.groups,s=e||o,c=t||i,l=r||a;if(s&&c)return`${s.charAt(0).toUpperCase()+s.slice(1).toLowerCase()} ${l?`${c}.${l}`:c}`}let r=t.match(sC);if(r?.groups){let e=r.groups.family,t=r.groups.major,n=r.groups.minor;return`${e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()} ${n?`${t}.${n}`:t}`}return t||e}function lC(e){let t=e.match(sC);if(!t?.groups)return e;let n=t.groups.family,r=t.groups.major,i=t.groups.minor;return`${n.charAt(0).toUpperCase()}${i?`${r}.${i}`:r}`}function uC(e){let t=e.split(`/`),n=t.length-1;return t.map((e,t)=>{if(t===n)return e;let r=e.match(/^\.*./);return r?r[0]:e}).join(`/`)}function dC(e){return e.toLocaleString()}function fC(e){if(e.length===0)throw Error(`a cascade needs at least one stop, e.g. "0:calm"`);let t=[];for(let[n,r]of e.entries()){let e=r.indexOf(`:`),i=e<0?NaN:Number(r.slice(0,e));if(!Number.isFinite(i))throw Error(`cascade stop ${n} ("${r}") must be "<position>:<result>", e.g. "80:hot" — the position must be a number`);let a=t[n-1];if(a!==void 0&&i<a.at)throw Error(`cascade stops must be in ascending position order; stop ${n} at ${i} follows stop ${n-1} at ${a.at}`);t.push({at:i,text:r.slice(e+1)})}return t}function pC(e,t){if(!Number.isFinite(e))throw Error(`a cascade needs a finite value, got ${e}`);let n=-1;for(;n+1<t.length&&t[n+1].at<=e;)n++;return(n<0?t[0]:t[n]).text}const mC=[`▁`,`▂`,`▃`,`▄`,`▅`,`▆`,`▇`,`█`],hC=mC.length;function gC(e,t){let n=t===void 0?e:t<=0?[]:e.slice(-t);if(n.length===0)return``;let r=n[0],i=n[0];for(let e of n)e<r&&(r=e),e>i&&(i=e);let a=i-r,o=``;for(let e of n){let t=a===0?0:Math.round((e-r)/a*(hC-1));o+=mC[t]}return o}function _C(e){let t=[];for(let n of e.split(`,`)){let e=n.trim();if(e===``)continue;let r=Number(e);if(!Number.isFinite(r))throw TypeError(`sparkline: non-numeric series element ${JSON.stringify(n)}`);t.push(r)}return t}function vC(e,t,n){if(n.length!==0)throw Error(`${e}: takes at most ${t.length} optional argument${t.length===1?``:`s`} (${t.join(`, `)}), got ${t.length+n.length}`)}const yC=up(),bC=[...jp];function xC(){return{basename:{fn:e=>u(e),argTypes:[`string`],arity:{kind:`exact`}},dirname:{fn:e=>d(e),argTypes:[`string`],arity:{kind:`exact`}},abbreviatePath:{fn:e=>uC(e),argTypes:[`string`],arity:{kind:`exact`}},int:{fn:e=>Math.trunc(Ig(e)),argTypes:[`value`],arity:{kind:`exact`}},string:{fn:e=>Fg(e),argTypes:[`value`],arity:{kind:`exact`}},bool:{fn:e=>Lg(e),argTypes:[`value`],arity:{kind:`exact`}},urlEncode:{fn:e=>encodeURIComponent(e),argTypes:[`string`],arity:{kind:`exact`}},themes:{fn:()=>yC,argTypes:[],arity:{kind:`exact`}},endcaps:{fn:()=>bC,argTypes:[],arity:{kind:`exact`}},sparkline:{fn:(e,t,...n)=>(vC(`sparkline`,[`width`],n),gC(_C(e),t)),argTypes:[`string`,`int`],arity:{kind:`variadic`}},cascade:{fn:(e,...t)=>pC(e,fC(t)),argTypes:[`float`,`string`],arity:{kind:`variadic`}}}}function SC(e){return{minutesUntilReset:{fn:t=>Math.round(Math.max(0,t*1e3-e().getTime())/6e4),argTypes:[`int`],arity:{kind:`exact`}},formatInteger:{fn:e=>dC(e),argTypes:[`int`],arity:{kind:`exact`}},round:{fn:e=>Math.round(e),argTypes:[`float`],arity:{kind:`exact`}},formatModelName:{fn:e=>cC(e),argTypes:[`string`],arity:{kind:`exact`}},shortenModelName:{fn:e=>lC(e),argTypes:[`string`],arity:{kind:`exact`}}}}function CC(e){let{clock:t,drawnAt:n,extraFuncs:r}=e;return Av({fromString:e=>new q(e),toString:e=>e.plain,isT:e=>e instanceof q,clock:t,missingKey:`error`,funcs:{...yb(),...NS(),...sx(),...kx(),...db(t),...ty(),...Fb(),...Nb(),...aC(n&&(()=>({depth:n()}))),...xC(),...SC(t),...r??{}}})}function wC(e){return TC(e,new Set(e.names()),``)}function TC(e,t,n){return new Proxy(Object.create(null),{has(e,r){if(typeof r!=`string`)return!1;let i=n?`${n}.${r}`:r;if(t.has(i))return!0;let a=`${i}.`;for(let e of t)if(e.startsWith(a))return!0;return!1},get(r,i){if(typeof i!=`string`)return;let a=n?`${n}.${i}`:i;if(t.has(a))return e.getKind(a)===`document`?DC(a,e.readDocument(a)):e.read(a);let o=`${a}.`;for(let n of t)if(n.startsWith(o))return TC(e,t,a)}})}function EC(e,t){return new Proxy(e,{has:(e,t)=>t===`settings`||Reflect.has(e,t),get:(e,n)=>n===`settings`?t:Reflect.get(e,n)})}function DC(e,t){switch(t.kind){case`ok`:return t.value;case`absent`:throw Error(`variable "${e}" has no value yet: its source has not completed a scan`);case`failed`:throw Error(`variable "${e}": ${t.reason}`)}}function OC(e){return r.existsSync(l.join(e,`.git`))}function kC(e){let t=l.resolve(e);for(;;){if(OC(t))return t;let e=l.dirname(t);if(e===t)return;t=e}}function AC(e){let t=kC(e);return t===void 0?{root:l.resolve(e),git:!1}:{root:t,git:!0}}function jC(e,t){return e.kind===`absent`?R(`none`):e.kind===`failed`?e:t.kind===`failed`?t:R(t.kind===`ok`?`tracked`:`gone`)}function MC(e,t){return e.kind!==`ok`||e.value.state===`open`||t.kind===`ok`&&t.value===e.value.head?e:z}const NC={OPEN:`open`,MERGED:`merged`,CLOSED:`closed`},PC={opened:`open`,locked:`open`,merged:`merged`,closed:`closed`};function FC(e,t,n){return Object.hasOwn(t,n)?R(t[n]):B(`${e}: unknown state ${JSON.stringify(n)}`)}function IC(e,t,n){return t.ok?R(t.stdout):t.reason===`non-zero`&&n===`absent`||t.reason===`non-zero`&&n===t.exitCode?z:B(`${e}: ${[t.reason,t.exitCode==null?null:`exit ${t.exitCode}`,t.error??LC(t.stderr)].filter(Boolean).join(`, `)}`)}function LC(e){return e.trim().split(`
100
+ `)){let n=``;for(let i of t.split(/\s+/))i.length!==0&&(n.length===0?n=i:n.length+1+i.length<=e?n+=` ${i}`:(r.push(n),n=i));n.length>0&&r.push(n)}return r.join(t)}function MS(e,t,n){return jS(e,t,n)}function NS(){return{abbrev:{fn:(e,t)=>Mx(e,t),argTypes:[`int`,`string`],arity:{kind:`exact`}},abbrevboth:{fn:(e,t,n)=>Nx(e,t,n),argTypes:[`int`,`int`,`string`],arity:{kind:`exact`}},camelcase:{fn:e=>Jx(e),argTypes:[`string`],arity:{kind:`exact`},returnType:`string`},cat:{fn:(...e)=>Yx(...e),argTypes:[`string`],arity:{kind:`variadic`}},contains:{fn:(e,t)=>Xx(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},hasPrefix:{fn:(e,t)=>Zx(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},hasSuffix:{fn:(e,t)=>Qx(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},indent:{fn:(e,t)=>$x(e,t),argTypes:[`int`,`string`],arity:{kind:`exact`}},initials:{fn:e=>eS(e),argTypes:[`string`],arity:{kind:`exact`}},join:{fn:(e,t)=>tS(e,t),argTypes:[`string`,`list`],arity:{kind:`exact`}},kebabcase:{fn:e=>rS(e),argTypes:[`string`],arity:{kind:`exact`},returnType:`string`},lower:{fn:e=>iS(e),argTypes:[`string`],arity:{kind:`exact`}},nindent:{fn:(e,t)=>aS(e,t),argTypes:[`int`,`string`],arity:{kind:`exact`}},nospace:{fn:e=>oS(e),argTypes:[`string`],arity:{kind:`exact`},returnType:`string`},plural:{fn:(e,t,n)=>sS(e,t,n),argTypes:[`string`,`string`,`int`],arity:{kind:`exact`},returnType:`string`},quote:{fn:(...e)=>cS(...e),argTypes:[`string`],arity:{kind:`variadic`}},regexQuoteMeta:{fn:e=>lS(e),argTypes:[`string`],arity:{kind:`exact`},returnType:`string`},repeat:{fn:(e,t)=>uS(e,t),argTypes:[`int`,`string`],arity:{kind:`exact`}},replace:{fn:(e,t,n)=>dS(e,t,n),argTypes:[`string`,`string`,`string`],arity:{kind:`exact`}},snakecase:{fn:e=>fS(e),argTypes:[`string`],arity:{kind:`exact`},returnType:`string`},split:{fn:(e,t)=>pS(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},splitList:{fn:(e,t)=>mS(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},splitn:{fn:(e,t,n)=>hS(e,t,n),argTypes:[`string`,`int`,`string`],arity:{kind:`exact`},returnType:`dict`},squote:{fn:(...e)=>_S(...e),argTypes:[`string`],arity:{kind:`variadic`}},substr:{fn:(e,t,n)=>vS(e,t,n),argTypes:[`int`,`int`,`string`],arity:{kind:`exact`}},swapcase:{fn:e=>yS(e),argTypes:[`string`],arity:{kind:`exact`},returnType:`string`},title:{fn:e=>SS(e),argTypes:[`string`],arity:{kind:`exact`}},trim:{fn:e=>CS(e),argTypes:[`string`],arity:{kind:`exact`}},trimAll:{fn:(e,t)=>wS(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},trimPrefix:{fn:(e,t)=>TS(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},trimSuffix:{fn:(e,t)=>ES(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},trunc:{fn:(e,t)=>DS(e,t),argTypes:[`int`,`string`],arity:{kind:`exact`}},untitle:{fn:e=>OS(e),argTypes:[`string`],arity:{kind:`exact`}},upper:{fn:e=>kS(e),argTypes:[`string`],arity:{kind:`exact`}},wrap:{fn:(e,t)=>AS(e,t),argTypes:[`int`,`string`],arity:{kind:`exact`}},wrapWith:{fn:(e,t,n)=>MS(e,t,n),argTypes:[`int`,`string`,`string`],arity:{kind:`exact`}}}}function PS(e,t){if(!(e instanceof q))throw TypeError(`template function expected a RichText fragment, got ${typeof e==`object`?Object.prototype.toString.call(e):typeof e}`);let n=e.copy();return n.style=$c(e.style,t),n}function FS(e){return{fn:(t=>PS(t,e)),argTypes:[`liftable`],arity:{kind:`exact`},returnType:`T`}}function IS(e){return{fn:((t,n)=>PS(n,new G({[e]:W.parse(t)}))),argTypes:[`string`,`liftable`],arity:{kind:`exact`},returnType:`T`}}function LS(e,t){return new G({[e]:t})}function RS(){let e={};for(let t of Kc)e[t]=FS(LS(t,!0)),e[`not_${t}`]=FS(LS(t,!1));for(let[t,n]of Object.entries(Jc))e[t]=FS(LS(n,!0));return e}const zS={fn:((e,t)=>PS(t,G.parse(e))),argTypes:[`string`,`liftable`],arity:{kind:`exact`},returnType:`T`},BS={fn:((e,t)=>PS(t,new G({link:e}))),argTypes:[`string`,`liftable`],arity:{kind:`exact`},returnType:`T`};function VS(){return{fg:IS(`color`),bg:IS(`bgcolor`),...RS(),link:BS,style:zS}}function HS(e,t){let n;try{n=ds(e.trim())}catch(n){throw n instanceof Yo?TypeError(`${t} expected a color (#RRGGBB or #RRGGBBAA), got ${JSON.stringify(e)} — to use a palette name here, wrap it: ${t} (color ${JSON.stringify(e)}) …`,{cause:n}):n}return US(n,t,JSON.stringify(e))}function US(e,t,n){if(e.alpha===0)throw RangeError(`${t} got ${n}, which is fully transparent: it draws no colour of its own, so there is nothing to compute with — use the colour of the surface it sits on, e.g. (color "background")`);return e}function WS(e,t){return{fn:t,argTypes:e,arity:{kind:`exact`},returnType:`string`}}function GS(e,t,n,r){let i=r===void 0||e>=r.min&&e<=r.max;if(!Number.isFinite(e)||!i){let i=r===void 0?`a finite number`:`within ${r.min}..${r.max} (${r.note})`;throw RangeError(`${t}'s ${n} must be ${i}, got ${e}`)}return e}const KS=WS([`string`,`int`],((e,t)=>Ys(HS(e,`darken`),t).hex)),qS=WS([`string`,`int`],((e,t)=>Ys(HS(e,`lighten`),-t).hex)),JS={min:0,max:100,note:`0 = from, 100 = toward`},YS=WS([`string`,`string`,`float`],((e,t,n)=>fs(HS(e,`mix`),HS(t,`mix`),GS(n,`mix`,`percentage`,JS)/100).hex)),XS={min:1,max:21,note:`4.5 = AA body text, 3 = AA large text`},ZS=WS([`string`],(e=>Zs(HS(e,`contrastOn`)).hex)),QS={depth:U.TRUECOLOR},$S=e=>WS([`string`,`string`,`float`],((t,n,r)=>{let{depth:i,terminal:a}=e();return Qs(HS(t,`readableOn`),HS(n,`readableOn`),GS(r,`readableOn`,`ratio`,XS),i,void 0,a).hex})),eC={hueShift:`shiftHue`,chromaScale:`scaleChroma`,lightnessScale:`scaleLightness`,lightnessShift:`shiftLightness`};function tC(){let e={};for(let[t,n]of Object.entries(eC)){let r=t;e[n]=WS([`string`,`float`],((e,t)=>{let i={...As,[r]:GS(t,n,`amount`)};return Vs.fromRgba(HS(e,n)).applyKey(i).toRgba().hex}))}return e}function nC(e=()=>QS){return{darken:KS,lighten:qS,mix:YS,contrastOn:ZS,readableOn:$S(e),...tC()}}function rC(e,t){if(e.length%2!=0)throw RangeError(`ramp's last stop (position ${String(e[e.length-1])}) has no color — stops are <position> <color> pairs`);let n=[];for(let r=0;r<e.length;r+=2)n.push({at:e[r],color:US(Us(t,e[r+1]),`ramp`,JSON.stringify(e[r+1]))});return n}function iC(e){return{color:{fn:(t=>Us(e(),t).hex),argTypes:[`string`],arity:{kind:`exact`},returnType:`string`},ramp:{fn:((t,n,...r)=>new Fc(Vc(n),rC(r,e())).at(t).hex),argTypes:[`float`,`string`],arity:{kind:`alternating`,minimum:4},returnType:`string`}}}function aC(e){return{...VS(),...nC(e)}}new G({color:`red`,dim:!0});const oC=/^(?:(?:global|apac|au|eu|us|us-east-\d|us-west-\d|eu-west-\d|eu-central-\d)\.)?(?:anthropic\.|azure_ai\/|bedrock\/|vertex_ai\/)?claude-(?:(?<family>opus|sonnet|haiku)-(?<newMajor>\d+)(?:-(?<newMinor>\d))?|(?<oldMajor>\d+)(?:-(?<oldMinor>\d))?-(?<oldFamily>opus|sonnet|haiku))(?:[-@]\d{8})?(?:-v\d+:\d+)?(?:-latest)?$/i,sC=/^(?<family>opus|sonnet|haiku)\s+(?<major>\d+)(?:\.(?<minor>\d))?$/i;function cC(e){if(!e)return`Claude`;let t=e.trim().replace(/\s*\([^)]*\)\s*$/,``).replace(/\s*\[[^\]]*\]\s*$/,``).trim(),n=t.match(oC);if(n?.groups){let{family:e,newMajor:t,newMinor:r,oldMajor:i,oldMinor:a,oldFamily:o}=n.groups,s=e||o,c=t||i,l=r||a;if(s&&c)return`${s.charAt(0).toUpperCase()+s.slice(1).toLowerCase()} ${l?`${c}.${l}`:c}`}let r=t.match(sC);if(r?.groups){let e=r.groups.family,t=r.groups.major,n=r.groups.minor;return`${e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()} ${n?`${t}.${n}`:t}`}return t||e}function lC(e){let t=e.match(sC);if(!t?.groups)return e;let n=t.groups.family,r=t.groups.major,i=t.groups.minor;return`${n.charAt(0).toUpperCase()}${i?`${r}.${i}`:r}`}function uC(e){let t=e.split(`/`),n=t.length-1;return t.map((e,t)=>{if(t===n)return e;let r=e.match(/^\.*./);return r?r[0]:e}).join(`/`)}function dC(e){return e.toLocaleString()}function fC(e){if(e.length===0)throw Error(`a cascade needs at least one stop, e.g. "0:calm"`);let t=[];for(let[n,r]of e.entries()){let e=r.indexOf(`:`),i=e<0?NaN:Number(r.slice(0,e));if(!Number.isFinite(i))throw Error(`cascade stop ${n} ("${r}") must be "<position>:<result>", e.g. "80:hot" — the position must be a number`);let a=t[n-1];if(a!==void 0&&i<a.at)throw Error(`cascade stops must be in ascending position order; stop ${n} at ${i} follows stop ${n-1} at ${a.at}`);t.push({at:i,text:r.slice(e+1)})}return t}function pC(e,t){if(!Number.isFinite(e))throw Error(`a cascade needs a finite value, got ${e}`);let n=-1;for(;n+1<t.length&&t[n+1].at<=e;)n++;return(n<0?t[0]:t[n]).text}const mC=[`▁`,`▂`,`▃`,`▄`,`▅`,`▆`,`▇`,`█`],hC=mC.length;function gC(e,t){let n=t===void 0?e:t<=0?[]:e.slice(-t);if(n.length===0)return``;let r=n[0],i=n[0];for(let e of n)e<r&&(r=e),e>i&&(i=e);let a=i-r,o=``;for(let e of n){let t=a===0?0:Math.round((e-r)/a*(hC-1));o+=mC[t]}return o}function _C(e){let t=[];for(let n of e.split(`,`)){let e=n.trim();if(e===``)continue;let r=Number(e);if(!Number.isFinite(r))throw TypeError(`sparkline: non-numeric series element ${JSON.stringify(n)}`);t.push(r)}return t}function vC(e,t,n){if(n.length!==0)throw Error(`${e}: takes at most ${t.length} optional argument${t.length===1?``:`s`} (${t.join(`, `)}), got ${t.length+n.length}`)}const yC=up(),bC=[...jp];function xC(){return{basename:{fn:e=>u(e),argTypes:[`string`],arity:{kind:`exact`}},dirname:{fn:e=>d(e),argTypes:[`string`],arity:{kind:`exact`}},abbreviatePath:{fn:e=>uC(e),argTypes:[`string`],arity:{kind:`exact`}},int:{fn:e=>Math.trunc(Ig(e)),argTypes:[`value`],arity:{kind:`exact`}},string:{fn:e=>Fg(e),argTypes:[`value`],arity:{kind:`exact`}},bool:{fn:e=>Lg(e),argTypes:[`value`],arity:{kind:`exact`}},urlEncode:{fn:e=>encodeURIComponent(e),argTypes:[`string`],arity:{kind:`exact`}},themes:{fn:()=>yC,argTypes:[],arity:{kind:`exact`}},endcaps:{fn:()=>bC,argTypes:[],arity:{kind:`exact`}},sparkline:{fn:(e,t,...n)=>(vC(`sparkline`,[`width`],n),gC(_C(e),t)),argTypes:[`string`,`int`],arity:{kind:`variadic`}},cascade:{fn:(e,...t)=>pC(e,fC(t)),argTypes:[`float`,`string`],arity:{kind:`variadic`}}}}function SC(e){return{minutesUntilReset:{fn:t=>Math.round(Math.max(0,t*1e3-e().getTime())/6e4),argTypes:[`int`],arity:{kind:`exact`}},formatInteger:{fn:e=>dC(e),argTypes:[`int`],arity:{kind:`exact`}},round:{fn:e=>Math.round(e),argTypes:[`float`],arity:{kind:`exact`}},formatModelName:{fn:e=>cC(e),argTypes:[`string`],arity:{kind:`exact`}},shortenModelName:{fn:e=>lC(e),argTypes:[`string`],arity:{kind:`exact`}}}}function CC(e){let{clock:t,drawnAt:n,extraFuncs:r}=e;return Av({fromString:e=>new q(e),toString:e=>e.plain,isT:e=>e instanceof q,clock:t,missingKey:`error`,funcs:{...yb(),...NS(),...sx(),...kx(),...db(t),...ty(),...Fb(),...Nb(),...aC(n&&(()=>({depth:n()}))),...xC(),...SC(t),...r??{}}})}function wC(e){return TC(e,new Set(e.names()),``)}function TC(e,t,n){return new Proxy(Object.create(null),{has(e,r){if(typeof r!=`string`)return!1;let i=n?`${n}.${r}`:r;if(t.has(i))return!0;let a=`${i}.`;for(let e of t)if(e.startsWith(a))return!0;return!1},get(r,i){if(typeof i!=`string`)return;let a=n?`${n}.${i}`:i;if(t.has(a))return e.getKind(a)===`document`?DC(a,e.readDocument(a)):e.read(a);let o=`${a}.`;for(let n of t)if(n.startsWith(o))return TC(e,t,a)}})}function EC(e,t){return new Proxy(e,{has:(e,t)=>t===`settings`||Reflect.has(e,t),get:(e,n)=>n===`settings`?t:Reflect.get(e,n)})}function DC(e,t){switch(t.kind){case`ok`:return t.value;case`absent`:throw Error(`variable "${e}" has no value yet: its source has not completed a scan`);case`failed`:throw Error(`variable "${e}": ${t.reason}`)}}function OC(e){return r.existsSync(l.join(e,`.git`))}function kC(e){let t=l.resolve(e);for(;;){if(OC(t))return t;let e=l.dirname(t);if(e===t)return;t=e}}function AC(e){let t=kC(e);return t===void 0?{root:l.resolve(e),git:!1}:{root:t,git:!0}}function jC(e,t){return e.kind===`absent`?R(`none`):e.kind===`failed`?e:t.kind===`failed`?t:R(t.kind===`ok`?`tracked`:`gone`)}function MC(e,t){return e.kind!==`ok`||e.value.state===`open`?e:t.kind===`failed`?B(`HEAD: ${t.reason}`):t.kind===`ok`&&t.value===e.value.head?e:{kind:`earlier`,value:e.value}}const NC={OPEN:`open`,MERGED:`merged`,CLOSED:`closed`},PC={opened:`open`,locked:`open`,merged:`merged`,closed:`closed`};function FC(e,t,n){return Object.hasOwn(t,n)?R(t[n]):B(`${e}: unknown state ${JSON.stringify(n)}`)}function IC(e,t,n){return t.ok?R(t.stdout):t.reason===`non-zero`&&n===`absent`||t.reason===`non-zero`&&n===t.exitCode?z:B(`${e}: ${[t.reason,t.exitCode==null?null:`exit ${t.exitCode}`,t.error??LC(t.stderr)].filter(Boolean).join(`, `)}`)}function LC(e){return e.trim().split(`
101
101
  `,1)[0]??``}function RC(e,t){if(e.kind!==`ok`)return e;let n=t(e.value);return n===null?z:R(n)}function zC(e){if(e.kind!==`ok`)return e;let t=e.value.trim();return t?R(t):z}const BC=/^[A-Za-z]:[\\/]/;function VC(e){let t=e.trim();if(BC.test(t))return null;let n=t.match(/^(?:[^@/]+@)?(\[[^\]]+\]):(.*)$/)??t.match(/^(?:[^@/:]+@)?([^/:]+):(?!\/\/)(.*)$/),r=n?`ssh://${n[1]}/${n[2].replace(/^\/+/,``)}`:t,i;try{i=new URL(r)}catch{return null}return{scheme:i.protocol.replace(/:$/,``),host:i.hostname.toLowerCase(),port:i.port,path:i.pathname.replace(/^\/+/,``).replace(/\/+$/,``)}}function HC(e){return VC(e)?.host||null}function UC(e){let t=HC(e);return t?t===`github.com`||t.endsWith(`.github.com`)?`github`:/(^|\.)gitlab\./.test(t)?`gitlab`:null:null}function WC(e){let t=new Map;for(let n of e.split(`
102
102
  `)){let e=n.match(/^remote\.(.+)\.url\s+(\S.*)$/);if(!e)continue;let r=t.get(e[1])??[];r.push(e[2].trim()),t.set(e[1],r)}return[...t].map(([e,t])=>({name:e,urls:t}))}function GC(e){return e.urls.find(e=>XC(e)!==null)??e.urls[0]??null}function KC(e){return e.find(e=>e.name===`origin`)??e[0]??null}function qC(e){let t=KC(e);return t?GC(t):null}function JC(e){let t=KC(e);return t?t.urls.find(e=>UC(e)!==null)??GC(t):null}function YC(e){let t=(VC(e)?.path??e.replace(/[\\/]+$/,``)).split(`/`);return(t[t.length-1]??``).replace(/\.git$/,``)||null}function XC(e){let t=VC(e);if(!t)return null;let n=t.scheme===`https`?{scheme:`https`,port:t.port}:t.scheme===`http`?{scheme:`http`,port:t.port}:t.scheme===`ssh`||t.scheme===`git`?{scheme:`https`,port:``}:null;if(!n||!t.host)return null;let r=t.path.replace(/\.git$/,``);if(!r)return null;let i=n.port?`${t.host}:${n.port}`:t.host;return`${n.scheme}://${i}/${r}`}function ZC(e){let t=qC(e);return t===null?null:XC(t)}function QC(e,t,n,r){return t.ok?r(t.stdout):t.reason===`spawn-error`&&/ENOENT/i.test(t.error??``)||t.reason===`non-zero`&&n.test(t.stderr)?z:B(`${e}: ${[t.reason,t.exitCode==null?null:`exit ${t.exitCode}`,t.error??LC(t.stderr)].filter(Boolean).join(`, `)}`)}function $C(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ew(e){let t=`detached`,n=z,r=z,i=z,a=0,o=0,s=0,c=0;for(let l of e.split(`
103
103
  `)){if(!l)continue;if(l.startsWith(`# `)){let e=l.slice(2);if(e.startsWith(`branch.oid `)){let t=e.slice(11).trim();n=t===`(initial)`?z:R(t)}else if(e.startsWith(`branch.head `)){let n=e.slice(12).trim();t=n===`(detached)`?`detached`:n}else if(e.startsWith(`branch.upstream `))r=R(e.slice(16).trim());else if(e.startsWith(`branch.ab `)){let t=e.slice(10).trim().match(/^\+(\d+)\s+-(\d+)$/);t&&(i=R({ahead:parseInt(t[1],10),behind:parseInt(t[2],10)}))}continue}let e=l[0];if(e===`1`||e===`2`){let e=l.slice(2,4);e[0]!==`.`&&a++,e[1]!==`.`&&o++}else e===`u`?c++:e===`?`&&s++}let l=`clean`;return c>0?l=`conflicts`:(a||o||s)&&(l=`dirty`),{branch:t,status:l,aheadBehind:i,oid:n,upstream:r,workingTree:{staged:a,unstaged:o,untracked:s,conflicts:c}}}function tw(e){let t;try{t=JSON.parse(e)}catch(e){return B(`gh pr view: unparseable JSON (${e instanceof Error?e.message:String(e)})`)}if(!$C(t))return B(`gh pr view: JSON is not an object`);let{number:n,state:r,url:i,headRefOid:a}=t;if(typeof n!=`number`||typeof r!=`string`||typeof i!=`string`||typeof a!=`string`)return B(`gh pr view: missing number/state/url/headRefOid`);let o=FC(`gh pr view`,NC,r);return o.kind===`ok`?R({number:n,state:o.value,url:i,head:a}):o}function nw(e){let t;try{t=JSON.parse(e)}catch(e){return B(`glab mr view: unparseable JSON (${e instanceof Error?e.message:String(e)})`)}if(!$C(t))return B(`glab mr view: JSON is not an object`);let n=t.iid,r=t.state,i=t.web_url,a=t.sha;if(typeof n!=`number`||typeof r!=`string`||typeof i!=`string`||typeof a!=`string`)return B(`glab mr view: missing iid/state/web_url/sha`);let o=FC(`glab mr view`,PC,r);return o.kind===`ok`?R({number:n,state:o.value,url:i,head:a}):o}function rw(e){try{let t=r.statSync(e);return{key:`${t.dev}:${t.ino}`,stamp:`${t.mtimeMs}:${t.size}`}}catch{return null}}var iw=class{isGitRepo(e){return OC(e)}async execGitAsync(e,t){return O({bin:`git`,args:[...e],cwd:t.cwd,env:{...process.env,GIT_OPTIONAL_LOCKS:`0`},timeoutMs:t.timeout,category:`git`})}async resolveEffectiveGitDir(e,t){return this.isWorktree(e)?R(e):t&&this.isGitRepo(t)?R(t):this.isGitRepo(e)?R(e):this.findGitRoot(e)}async findGitRoot(e){let t=kC(e);return t===void 0?z:R(t)}async getGitInfo(e,t={},n){try{return await this.computeGitInfo(e,t,n)}catch(e){return B(`git: ${e instanceof Error?e.message:String(e)}`)}}async computeGitInfo(e,t={},n){let r,i=this.isWorktree(e);if(i)r=e;else if(n&&this.isGitRepo(n))r=n;else if(this.isGitRepo(e))r=e;else{let t=await this.findGitRoot(e);if(t.kind!==`ok`)return t;r=t.value}let a=await this.getCoreAsync(r);if(a.kind!==`ok`)return a;let o={branch:a.value.branch,status:a.value.status,aheadBehind:a.value.aheadBehind,head:a.value.oid};t.showWorkingTree&&(o.workingTree=a.value.workingTree),t.showSha&&(o.sha=RC(a.value.oid,e=>e.slice(0,7))),t.showUpstream&&(o.upstream=a.value.upstream),t.showTag&&(o.tag=await this.getNearestTagAsync(r)),t.showTimeSinceCommit&&(o.committedAt=await this.committedAt(r,a.value.oid)),t.showStashCount&&(o.stashCount=this.getStashCount(r));let s=t.showRepoName||t.showRepoUrl?await this.getRemotesAsync(r):void 0;return s!==void 0&&t.showRepoName&&(o.repoName=RC(s,e=>this.repoNameFrom(e,r)),o.isWorktree=i),s!==void 0&&t.showRepoUrl&&(o.repoUrl=RC(s,ZC)),t.showOperation&&(o.operation=this.getOngoingOperation(r)),R(o)}resolveGitDir(e){let t=l.join(e,`.git`);try{if(r.existsSync(t)&&r.statSync(t).isFile()){let n=r.readFileSync(t,`utf-8`).match(/^gitdir:\s*(.+)$/m);if(n?.[1])return l.resolve(e,n[1].trim())}}catch{}return t}getOngoingOperation(e){try{let t=this.resolveGitDir(e);return r.existsSync(l.join(t,`MERGE_HEAD`))?R(`MERGE`):r.existsSync(l.join(t,`CHERRY_PICK_HEAD`))?R(`CHERRY-PICK`):r.existsSync(l.join(t,`REVERT_HEAD`))?R(`REVERT`):r.existsSync(l.join(t,`BISECT_LOG`))?R(`BISECT`):r.existsSync(l.join(t,`rebase-merge`))||r.existsSync(l.join(t,`rebase-apply`))?R(`REBASE`):z}catch(e){return B(`git operation probe: ${e instanceof Error?e.message:String(e)}`)}}async getNearestTagAsync(e){return zC(IC(`git describe --tags`,await this.execGitAsync([`describe`,`--tags`,`--abbrev=0`],{cwd:e,timeout:2e3}),`absent`))}async committedAt(e,t){return t.kind===`ok`?this.commitTimestampMs(e,t.value):t}commitTimes=new Map;async commitTimestampMs(e,t){let n=this.commitTimes.get(t);if(n!==void 0)return this.commitTimes.delete(t),this.commitTimes.set(t,n),n;let r=this.readCommitTimestampMs(e,t);for(this.commitTimes.set(t,r),r.then(e=>{e.kind!==`ok`&&this.commitTimes.get(t)===r&&this.commitTimes.delete(t)},()=>{this.commitTimes.get(t)===r&&this.commitTimes.delete(t)});this.commitTimes.size>256;){let e=this.commitTimes.keys().next().value;if(e===void 0)break;this.commitTimes.delete(e)}return r}async readCommitTimestampMs(e,t){let n=zC(IC(`git log -1`,await this.execGitAsync([`log`,`-1`,`--format=%ct`,t,`--`],{cwd:e,timeout:2e3}),`absent`));if(n.kind!==`ok`)return n;let r=parseInt(n.value,10)*1e3;return Number.isNaN(r)?B(`git log -1: unparseable timestamp "${n.value}"`):R(r)}resolveCommonGitDir(e){let t=this.resolveGitDir(e);try{let e=r.readFileSync(l.join(t,`commondir`),`utf-8`).trim();if(e)return l.resolve(t,e)}catch{}return t}getStashCount(e){let t=l.join(this.resolveCommonGitDir(e),`logs`,`refs`,`stash`),n;try{n=r.readFileSync(t,`utf-8`)}catch(e){return e.code===`ENOENT`?R(0):B(`git stash reflog ${t}: ${e instanceof Error?e.message:String(e)}`)}let i=n.trim();return R(i?i.split(`
@@ -190,42 +190,42 @@ ceiling = in_force(directory, anchored(sys.argv[3]))
190
190
  layer = ceiling_in(directory / CONFIG_NAME)
191
191
  print(json.dumps({"ceiling": "off" if ceiling == math.inf else ceiling,
192
192
  "session": layer.text if layer else None}))
193
- `,l.join(e,`lib`),t.sessionId,t.cwd],env:ZF(t),timeoutMs:3e3,category:`memento.read`});return n.ok?$F(n.stdout):B(QF(n))}function tI(e,t,n){let r=Me({bin:l.join(e,qF),args:n.kind===`set`?[`set`,`session`,n.to]:[`clear`,`session`],env:ZF(t),timeoutMs:5e3,category:`memento.move`});if(!r.ok)throw Error(QF(r))}function nI(){return{locate:e=>XF(ii(e.claudeConfigDir),e.projectDir),read:eI,move:tI}}function rI(e,t,n){let r=n===void 0?``:`CLAUDE_CONFIG_DIR=${ar(n)} `,i=e.added_dirs.map(e=>` --add-dir ${ar(e)}`).join(``);return`cd ${ar(e.project_dir)} && ${r}claude --resume ${ar(t)}${i}`}function iI(e,t,n){let r=Jh(t(`preset`),e.globals.preset,e.presets),i=Zh(e,r),a=t(`edit.mode`)===`arrange`?e.editGlobals:{},o=rh(a.palette,t(`theme`),i.palette),s=AF(i,kF(o,e.themeDefaults));return{preset:r,presetCustomized:n(r),theme:o,style:Sp(a.style,t(`style`),s.style,e.styles),effect:Ap(a.effect,t(`effect`),s.effect),endcaps:Fp(a.endcaps,t(`endcaps`),s.endcaps),variation:Up(a.variation,t(`variation`),s.variation),shade:Kp(a.shade,t(`shade`),s.shade),separator:a.default_separator??s.default_separator,autoWrap:em(a.autoWrap,t(`autoWrap`),s.autoWrap),padding:rm(a.padding,t(`padding`),s.padding),charset:a.charset??s.charset??`unicode`,updateNotice:tm(a.updateNotice,t(`updateNotice`),s.updateNotice),transitions:nm(a.transitions,t(`transitions`),s.transitions),colorCompatibility:a.colorCompatibility??s.colorCompatibility??`truecolor`}}function aI(e,t){return{endcaps:e.endcaps,separator:e.separator,colorCompatibility:e.colorCompatibility,wrap:e.autoWrap,padding:e.padding,charset:e.charset,width:t}}function oI(e){return{theme:e.theme,style:e.style,effect:e.effect,preset:e.preset,variation:e.variation,shade:e.shade,transitions:e.transitions}}function sI(e){return{preset:{effective:e.preset,customized:e.presetCustomized,bundled:DF(e.preset)},endcaps:{effective:e.endcaps},variation:{effective:e.variation},shade:{effective:e.shade},charset:{effective:e.charset},colorCompatibility:{effective:e.colorCompatibility},autoWrap:{effective:e.autoWrap},padding:{effective:e.padding},updateNotice:{effective:e.updateNotice},transitions:{effective:e.transitions}}}const cI=10*1e3;function lI(e,t,n,r){let i=n-(t*1e3-r);if(i<3e5||e<=0)return;let a=e/i,o=(100-e)/a;return Math.max(0,Math.round(o/6e4))}function uI(e,t){if(!(t<60))return e*3600/t}function dI(e,t,n,r){let i=r-t;if(i<50||i>cI)return;let a=n-e;if(!(a<=0))return a*1e3/i}function fI(e){let{prev:t,cur:n}=e;if(t===void 0)return;let r=dI(t.input,t.atMs,n.input,n.atMs),i=dI(t.output,t.atMs,n.output,n.atMs),a=dI(t.total,t.atMs,n.total,n.atMs);if(!(r===void 0&&i===void 0&&a===void 0))return{...r!==void 0&&{input:r},...i!==void 0&&{output:i},...a!==void 0&&{total:a}}}function pI(e){let{samples:t}=e,n=[];for(let e=1;e<t.length;e++){let r=t[e-1],i=t[e],a=i.atMs-r.atMs;if(a<50||a>cI)continue;let o=dI(r.total,r.atMs,i.total,i.atMs);n.push(o??0)}if(n.length!==0)return n.join(`,`)}function mI(e){let t=e.indexOf(`.`);return t<0?e:e.slice(0,t)}function hI(e){let t=[],n=(e,n)=>{try{let e=n();return e===``?void 0:e}catch(n){t.push(`host.${e}: ${String(n)}`);return}},r=n(`name`,()=>mI(h.hostname())),i=n(`user`,()=>h.userInfo().username);return{host:{...r!==void 0&&{name:r},...i!==void 0&&{user:i},...e.ssh!==void 0&&{ssh:e.ssh}},failures:t}}function gI(e,t){let n=new Map;for(let[t,r]of Object.entries(e.variables))n.set(t,r);for(let[t,r]of Object.entries(e.segments))if(r.vars)for(let[e,i]of Object.entries(r.vars))n.set(`${t}.${e}`,i);let r=[],i=new Set,a=t=>vg(t,e.helpers).keys(),o=Zh(e,t);for(let e of hp){let t=o[e];if(gp(t))for(let e of a(t))r.push(e)}for(let n of dh(Xh(e,t).node)){if(n.when)for(let e of a(n.when))r.push(e);if(n.kind!==`segment`)continue;let t=e.segments[n.name];if(t){for(let e of[t.template,t.when,t.bg,t.fg])if(e)for(let t of a(e))r.push(t)}}let s=new Set;for(;r.length>0;){let e=r.pop();for(let t of vI(n,e)){if(i.has(t))continue;i.add(t);let e=n.get(t);if(e){if(e.kind===`input`)s.add(e.path);else if(e.kind===`template`)for(let t of a(e.template))r.push(t)}}}return s}function _I(e){let t=new Map;return n=>{let r=t.get(n);if(r!==void 0)return r;let i=gI(e,n);return t.set(n,i),i}}function vI(e,t){let n=t;for(;n.length>0;){if(e.has(n))return[n];let t=n.lastIndexOf(`.`);if(t<0)break;n=n.slice(0,t)}let r=`${t}.`,i=[];for(let t of e.keys())t.startsWith(r)&&i.push(t);return i}function yI(e,t){for(let n of e)if(n===t||n.startsWith(t+`.`))return!0;return!1}function bI(e){let t=t=>e.has(t),n=t(`git.staged`)||t(`git.unstaged`)||t(`git.untracked`)||t(`git.conflicts`);return{...t(`git.sha`)&&{showSha:!0},...n&&{showWorkingTree:!0},...t(`git.stash`)&&{showStashCount:!0},...(t(`git.upstream`)||t(`git.tracking`))&&{showUpstream:!0},...t(`git.repoName`)&&{showRepoName:!0},...t(`git.repoUrl`)&&{showRepoUrl:!0},...t(`git.operation`)&&{showOperation:!0},...t(`git.timeSinceCommit`)&&{showTimeSinceCommit:!0},...(t(`git.prNumber`)||t(`git.prState`)||t(`git.prUrl`)||t(`git.prError`))&&{showPullRequest:!0}}}async function xI(e,t,n,r,i,a,o,{configPath:s,...c}){let l=e=>yI(i,e),u=yw(t).getTime(),d=o.tmux??null,f=(e,t,n)=>t?n().catch(t=>B(`${e}: ${String(t)}`)):Promise.resolve(z),[p,m,h,g,_,v,y,b,x,S,C]=await Promise.all([f(`git`,l(`git`),()=>n.gitProvider.getGitInfo(r??e.workspace?.current_dir,bI(i),e.workspace?.project_dir)),f(`session`,l(`session.cost`)||l(`session.tokens`)||l(`burn`),()=>n.usageStore.getUsageInfo(e.session_id,e)),f(`today`,l(`today`),()=>n.usageStore.getTodayInfo(e,o.claudeConfigDir,t)),f(`context`,l(`context`)||l(`autocompact`),()=>n.contextProvider.getContextInfo(e)),f(`metrics`,l(`metrics`)||l(`burn`),()=>n.metricsProvider.getMetricsInfo(e.session_id,e)),f(`activity`,l(`activity`),()=>n.activityProvider.getActivityInfo(e.session_id,e)),f(`tmux`,l(`tmux.session`),()=>d===null?Promise.resolve(z):n.tmuxService.getSessionName(d)),f(`cache`,l(`cache`),()=>HF(e.transcript_path)),f(`speed`,l(`speed`),()=>n.usageStore.observeSpeed(e.session_id,e.transcript_path,u)),f(`memento`,l(`memento`),()=>n.mementoProvider.getCeiling(GF({sessionId:e.session_id,projectDir:e.workspace?.project_dir??``,cwd:r??e.workspace?.current_dir??``},o))),f(`autocompact`,l(`autocompact`),()=>Promise.resolve(n.autoCompact(ri(ni(o.claudeConfigDir)))))]),ee=[],te=e=>{if(e.kind===`failed`){ee.push(e.reason);return}return e.kind===`ok`?e.value:void 0},ne=kI(p,u);ee.push(...ne.failures);let re=hI(o);ee.push(...re.failures);let ie=te(m),ae=te(h),w=te(g),T=te(_),oe=te(v),se=te(y),ce=te(b),le=wI(S);S.kind===`failed`&&ee.push(`memento: ${S.reason}`);let ue=SI(C,w?.maxTokens);C.kind===`failed`&&ee.push(`autocompact: ${C.reason}`);for(let e of ee)n.log(`warn`,`provider fetch failed: ${e}`);let E=e.rate_limits?.five_hour,de=e.rate_limits?.seven_day,fe=E?lI(E.used_percentage,E.resets_at,18e6,u):void 0,pe=de?lI(de.used_percentage,de.resets_at,6048e5,u):void 0,me=ie?.session.cost,he=T?.sessionDuration,ge=l(`burn`)&&me!=null&&he!=null?uI(me,he):void 0,_e=te(x),ve=_e===void 0?void 0:fI(_e),ye=_e===void 0?void 0:pI(_e),be=ve!==void 0||ye!==void 0?{...ve,...ye!==void 0&&{history:ye}}:void 0,xe=OI(process.env.HOME??process.env.USERPROFILE),D=e.workspace?{...e.workspace,current_dir:OI(e.workspace.current_dir)??``,project_dir:OI(e.workspace.project_dir)??``,added_dirs:(e.workspace.added_dirs??[]).map(e=>OI(e)??e)}:e.workspace,Se=ie===void 0?void 0:DI({cost:ie.session.cost,tokens:ie.session.tokens}),Ce=ae===void 0?void 0:{cost:ae.cost,tokens:ae.tokens},we=T===void 0?void 0:DI({lastResponseTime:T.lastResponseTime,responseTime:T.responseTime,sessionDuration:T.sessionDuration,messageCount:T.messageCount,nonPrompts:T.nonPrompts,linesAdded:T.linesAdded,linesRemoved:T.linesRemoved}),Te=oe===void 0?void 0:TI(oe);return{...e,...D!==void 0&&{workspace:D},...xe!==void 0&&{home:xe},...ne.git!==void 0&&{git:ne.git},...d!==null&&{tmux:{pane:d.pane,...se!==void 0&&{session:se}}},host:re.host,...sI(a),history:n.history(e.session_id),navigation:{back:n.navigation(e.session_id)},...c,...s!==null&&{configPath:s},resumeCommand:rI(D,e.session_id,o.claudeConfigDir),...Se!==void 0&&{session:Se},...Ce!==void 0&&{today:Ce},...ge!==void 0&&{burn:{costPerHour:ge}},...be!==void 0&&{speed:be},...l(`block`)&&E!==void 0&&{block:{nativeUtilization:E.used_percentage,resetsAt:E.resets_at,...fe!==void 0&&{etaMinutes:fe}}},...de!==void 0&&{weekly:{percentage:de.used_percentage,resetsAt:de.resets_at,...pe!==void 0&&{etaMinutes:pe}}},...ce!==void 0&&{cache:{expiresAt:ce}},...w!==void 0&&{context:{totalTokens:w.totalTokens,contextLeft:w.contextLeftPercentage}},...we!==void 0&&{metrics:we},...Te!==void 0&&{activity:Te},...le!==void 0&&{memento:le},...ue!==void 0&&{autocompact:ue}}}function SI(e,t){switch(e.kind){case`absent`:return;case`failed`:return{error:e.reason};case`ok`:return nO(e.value,t)}}const CI=e=>e.trim().split(`
194
- `).at(-1).trim();function wI(e){switch(e.kind){case`absent`:return;case`failed`:return{error:CI(e.reason)};case`ok`:{let{ceiling:t,session:n}=e.value;return{ceiling:t===`off`?0:t,off:t===`off`,session:n??``}}}}function TI(e){let t=e.todos.findIndex(e=>e.active),n=e.todos.length===0?void 0:{total:e.todos.length,completed:e.todos.filter(e=>e.done).length,...t>=0&&{position:t+1,active:e.todos[t].text}},r=EI(e.running),i=EI(e.done),a=r===void 0&&i===void 0?void 0:{...r!==void 0&&{running:r},...i!==void 0&&{done:i}};if(!(e.command===null&&n===void 0&&a===void 0))return{...e.command!==null&&{command:e.command},...n!==void 0&&{todo:n},...a!==void 0&&{tool:a}}}function EI(e){return e.length===0?void 0:e.map(e=>`${e.name}:${e.count}`).join(`,`)}function DI(e){let t={},n=!1;for(let r of Object.keys(e)){let i=e[r];i!=null&&(t[r]=i,n=!0)}return n?t:void 0}function OI(e){return e===void 0||e.length===0||l.sep!==`\\`?e:e.replace(/\\/g,`/`)}function kI(e,t){if(e.kind===`absent`)return{failures:[]};if(e.kind===`failed`)return{failures:[e.reason]};let n=e.value,r=[],i=(e,t)=>{if(!(t===void 0||t.kind===`absent`)){if(t.kind===`failed`){r.push(`git.${e}: ${t.reason}`);return}return t.value}},a=i(`aheadBehind`,n.aheadBehind),o=i(`sha`,n.sha),s=i(`operation`,n.operation),c=i(`timeSinceCommit`,n.committedAt),l=c===void 0?void 0:Math.floor((t-c)/1e3),u=i(`stash`,n.stashCount),d=i(`upstream`,n.upstream),f=n.upstream===void 0?void 0:i(`tracking`,jC(n.upstream,n.aheadBehind)),p=i(`repoName`,n.repoName),m=i(`repoUrl`,n.repoUrl),h=n.pullRequest===void 0?void 0:MC(n.pullRequest,n.head),g={};return h?.kind===`ok`?(g.prNumber=h.value.number,g.prState=h.value.state,g.prUrl=h.value.url):h?.kind===`failed`&&(r.push(`git.pr: ${h.reason}`),g.prError=h.reason),{git:{branch:n.branch,status:n.status,...a!==void 0&&{ahead:a.ahead,behind:a.behind},...n.workingTree!==void 0&&{staged:n.workingTree.staged,unstaged:n.workingTree.unstaged,untracked:n.workingTree.untracked,conflicts:n.workingTree.conflicts},...o!==void 0&&{sha:o},...s!==void 0&&{operation:s},...l!==void 0&&{timeSinceCommit:l},...u!==void 0&&{stash:u},...d!==void 0&&{upstream:d},...f!==void 0&&{tracking:f},...p!==void 0&&{repoName:p},...m!==void 0&&{repoUrl:m},...g},failures:r}}const AI={theme:e=>e.theme.kind===`decided`?e.theme.name:null,preset:e=>e.preset,style:e=>e.style.kind===`decided`?e.style.name:null,effect:e=>e.effect.kind===`decided`?e.effect.name:null,endcaps:e=>e.endcaps,variation:e=>e.variation,shade:e=>e.shade,transitions:e=>e.transitions?qp:Jp,autoWrap:e=>e.autoWrap?qp:Jp,padding:e=>String(e.padding),updateNotice:e=>e.updateNotice?qp:Jp},jI=Object.entries(pa),MI=new Set(ma.map(e=>e.sessionKey)),NI=()=>!1;function PI(e,t){return iI(e,e=>MI.has(e)?t(e):null,NI)}const FI=[`preset`,`theme`];function II(e,t,n){let r=new Set(FI.slice(0,n).map(e=>pa[e].sessionKey));return iI(e,e=>r.has(e)?t(e):null,NI)}function LI(e,t){let n=Array.from({length:FI.length+1},(n,r)=>II(e,t,r));return e=>{let t=FI.indexOf(e);return n[t===-1?FI.length:t]}}function RI(e,t,n,r){return e.flatMap(([e,i])=>{let a=AI[e](t);return a===null||a===AI[e](n(e))?[]:[{...i,value:a,target:r(i)}]})}function zI(e,t,n){return AI[n](PI(e,t))}function BI(e,t){let n=PI(e,t);return RI(jI,n,LI(e,t),t=>VI(e,n.preset,t.configKey))}function VI(e,t,n){return n in(Yh(e.presets,t).globals??{})?HE(t,n):n}function HI(e,t,n){let r=Jh(t(pa.preset.sessionKey),e.globals.preset,e.presets),i=UE(n);return{key:i?.scope===`globals`?VI(e,r,i.field):n,globals:Zh(e,r)}}function UI(e,t){let{preset:n}=PI(e,t);return KI(e,n).flatMap(({id:e,setting:r,key:i,decl:a,saved:o})=>{let s=t(i),c=s===null?void 0:kh(a,s);return c===void 0||Oh(c)===Oh(o)?[]:[{preset:n,id:e,setting:r,key:i,value:c}]})}function WI(e,t,n){let r=new Map(n.map(e=>[e.key,e.value]));return qh(e.presets).flatMap(n=>{let i=KI(e,n);return[...new Set(i.filter(e=>r.has(e.key)).map(e=>e.id))].flatMap(e=>{let n=i.filter(t=>t.id===e);return Eh(Object.fromEntries(n.map(e=>[e.setting,e.decl])),Object.fromEntries(n.map(e=>{let n=r.get(e.key)??t(e.key),i=n===null?void 0:kh(e.decl,n);return[e.setting,i??e.saved]}))).map(({message:t})=>`placement "${e}": ${t}`)})})}const GI=new WeakMap;function KI(e,t){let n=GI.get(e)??new Map;GI.set(e,n);let r=n.get(t);if(r!==void 0)return r;let i=[...dh(Xh(e,t).node)].flatMap(t=>t.kind!==`segment`||t.drafts===void 0?[]:Object.entries(t.drafts).map(([n,{id:r,key:i}])=>{let a=wh(e.segments[t.name])[n];return{id:r,setting:n,key:i,decl:a,saved:t.settings?.[n]??a.default}})),a=[...new Map(i.map(e=>[e.key,e])).values()];return n.set(t,a),a}function qI(e,t){let n=PI(e,t);return{from:n.preset,globals:Yh(e.presets,n.preset).globals??{},picks:RI(jI.filter(([e])=>e!==`preset`),n,LI(e,t),e=>e.configKey),placements:UI(e,t)}}function JI(e,t){return iI({...e,globals:{palette:t},presets:{}},()=>null,NI)}function YI(e,t){let n=PI(e,t),r=AI.theme(n);if(r===null)return{kind:`rule`};let i=JI(e,r),a=Zh(e,n.preset),o=Object.fromEntries(gh.map(e=>[e,AI[e](a[e]===void 0?n:i)]));return{kind:`look`,theme:r,look:o,differs:gh.some(e=>o[e]!==AI[e](i))}}function XI(e){return{sessionKeys:ma.filter(t=>t.configKey===e).map(e=>e.sessionKey),fileKeys:[e,...xE(e)?EF.map(t=>HE(t,e)):[],...VE(e)?up().map(t=>BE(t,e)):[]]}}function ZI(e){return new Set(ma.map(e=>e.configKey).filter(t=>XI(t).fileKeys.some(t=>eL(e,$I(t)))))}function QI(e,t,n){let r=BI(e,n),i=new Set(r.map(e=>e.configKey)),a=ya(e=>i.has(pa[e].configKey)||t.has(pa[e].configKey)),o=YI(e,n);return{unsaved:r.length+UI(e,n).length,resettable:a,themeDefault:o.kind===`look`&&o.differs?{differs:!0,theme:o.theme}:{differs:!1}}}function $I(e){let t=UE(e);if(t===null||t.scope===`preset-root`)throw Error(`reset layer "${e}" is not a value path`);return WE(t)}function eL(e,t){let[n,...r]=t;return n===void 0?e!==void 0:typeof e==`object`&&!!e&&eL(e[n],r)}const tL=up(),nL=new Set(tL),rL=new Set(jp),iL=e=>e?nL.has(e)?{ok:!0,value:e}:{ok:!1,reason:`unknown theme "${e}" (have: ${tL.join(`, `)})`}:{ok:!1,reason:`theme name is required`},aL=e=>e?rL.has(e)?{ok:!0,value:e}:{ok:!1,reason:`unknown endcaps "${e}" (have: ${jp.join(`, `)})`}:{ok:!1,reason:`endcaps name is required`},oL=new Set([`1`,`true`]),sL=new Set([`0`,`false`]),cL={endcaps:aL,theme:iL,"toolbar-expanded":e=>oL.has(e)?{ok:!0,value:`1`}:sL.has(e)?{ok:!0,value:``}:{ok:!1,reason:`expected boolean-ish (1, 0, true, false), got "${e}"`}},lL=AA(cL,`state`,gL);function uL(e,t){return lL.register(e,t)}function dL(e){return lL.gateFor(e)}function fL(e,t){return`set`in e?`to`in e?[{key:e.set,spec:{kind:`allow-list`,allowed:[e.to]}}]:`from`in e?[{key:e.set,spec:{kind:`allow-list`,allowed:rg(e.from,t).members}}]:`int`in e?[{key:e.set,spec:{kind:`int`}}]:`cycle`in e?[{key:e.set,spec:{kind:`allow-list`,allowed:e.cycle}}]:[{key:e.set,spec:{kind:`range`,min:e.min,max:e.max}}]:[]}function pL(e){return e.filter(e=>e.spec.kind!==`allow-list`||!Object.hasOwn(cL,e.key))}function mL(e,t,n){let r=ba.get(n);if(r!==void 0)return zI(e,t,r);let i=Object.values(e.variables).find(e=>e.kind===`state`&&e.key===n);return i?.kind===`state`?i.default??null:null}function hL(e){let t=$k(e);return pL(Object.values(e.actions).flatMap(e=>fL(e,t)))}function gL(e){return OA(hL(e))}const _L=`update.dismissed`,vL=`updateNotice`,yL=pa.updateNotice.sessionKey;function bL(e){return e.kind===`source`?e.newer.digest:fi(e.newer)}const xL=e=>`${e.version} [${Wm(e.digest)}]`;function SL(e){switch(e.kind){case`source`:return{headline:`Newer source`,newer:xL(e.newer),running:xL(e.running),act:`rebuild`,busy:`rebuilding…`,command:{bin:`pnpm`,args:[`build`],cwd:e.root}};case`release`:return{headline:`Newer release`,newer:fi(e.newer),running:fi(e.running),act:`upgrade`,busy:`upgrading…`,command:{bin:`pnpm`,args:[`dlx`,`${mi}@${fi(e.newer)}`,`install`]}}}}const CL={kind:`idle`},wL={kind:`running`};function TL(e,t,n){if(e===null)return[];let r=bL(e);if(!n.enabled||n.dismissed===r)return[];let i=SL(e),a=`${i.headline}: ${i.newer}. You're on ${i.running}.`,o=t.kind===`failed`&&t.identity===r?[`${i.act} failed: ${t.reason}`]:[],s=[a,...o].join(`
195
- `),c=I([{verb:xn,args:[s]}]),l=t.kind===`running`?Mm(`[${i.busy}]`,c):Mm(`[${i.act}]`,I([{verb:Nn,args:[n.sessionId]}]));return[{severity:jm,message:s,lines:[[Mm(a,c),l,Mm(`[dismiss]`,I([{verb:gn,args:[n.sessionId,_L,r]}])),Mm(`[disable]`,I([{verb:Sn,args:[n.sessionId,vL,`false`]},{verb:gn,args:[n.sessionId,yL,`false`]}]))],...o.map(e=>[Mm(e,c)])]}]}function EL(e,t){return e.kind===`stale`?{kind:`source`,root:e.root,newer:e.source,running:e.running}:e.kind===`not-source-checkout`&&t!==null&&t.kind===`stale`?{kind:`release`,newer:t.latest,running:t.installed}:null}function DL(e){switch(e.kind){case`current`:return[`info`,`build: current ${xL(e.stamp)}`];case`stale`:return[`info`,`build: stale — source ${xL(e.source)}, running ${xL(e.running)}`];case`not-source-checkout`:return[`info`,`build: not a source checkout`];case`unchecked`:return[`warn`,`build: unchecked: ${e.reason}`]}}function OL(e){switch(e.kind){case`current`:return[`info`,`release: current ${fi(e.installed)}`];case`stale`:return[`info`,`release: stale — latest ${fi(e.latest)}, running ${fi(e.installed)}`];case`ahead`:return[`info`,`release: ahead — running ${fi(e.installed)}, latest ${fi(e.latest)}`];case`unchecked`:return[`warn`,`release: unchecked: ${e.reason}`]}}function kL(e){let t=null;return([n,r])=>{r!==t&&(t=r,e(n,r))}}const AL=e=>e.split(/\r?\n/).map(e=>e.trim()).filter(e=>e!==``).at(-1);function jL(e){let t=e.exitCode===null?``:` (exit ${e.exitCode})`,n=AL(e.stderr)??e.error??AL(e.stdout)??`no output`;return`${e.reason}${t}: ${n}`}function ML(){let e=[MA(vL,[`false`]),uL(yL,[`false`]),uL(_L,[])];return()=>e.forEach(e=>e())}function NL(e){let{entryUrl:t,intervalMs:n,releaseIntervalMs:r,registryUrl:i,fetchImpl:a,onApplied:o,log:s}=e,c={kind:`unchecked`,reason:`not sampled yet`},l=null,u=CL,d=null,f=kL(s),p=kL(s),m=()=>EL(c,l);function h(){let e=m(),t=e===null?null:bL(e);(d===null?null:d.identity)!==t&&(d?.dispose(),d=t===null?null:{identity:t,dispose:uL(_L,[t])})}function g(){c=Jm(t,Km),f(DL(c)),h()}async function _(){l=gi(wt,await hi(mi,a,i)),p(OL(l)),h()}return{arm(){ML(),g(),setInterval(g,n).unref(),c.kind===`not-source-checkout`&&(_(),setInterval(()=>void _(),r).unref())},notice:e=>TL(m(),u,e),act(){let e=m();if(e===null)throw new J(`apply-update: nothing newer is known to apply`);let t=SL(e);if(u.kind===`running`)throw new J(`apply-update: already ${t.busy}`);u=wL,s(`info`,`apply-update: ${t.act} — ${t.command.bin} ${t.command.args?.join(` `)??``}`),O({...t.command,category:`update.apply`,timeoutMs:6e5}).then(n=>{if(n.ok){u=CL,s(`info`,`apply-update: ${t.act} succeeded`),g(),o();return}let r=jL(n);u={kind:`failed`,identity:bL(e),reason:r},s(`error`,`apply-update: ${t.act} failed: ${r}`)})}}}var PL=class{static CACHE_DIR=Re();static USAGE_CACHE_DIR=l.join(this.CACHE_DIR,`usage`);static LOCKS_DIR=l.join(this.CACHE_DIR,`locks`);static isLocked(e){let t=l.join(this.LOCKS_DIR,e);if(!r.existsSync(t))return!1;try{let n=r.readFileSync(t,`utf-8`),i=parseInt(n.trim(),10);if(isNaN(i))return D(`Invalid PID in lock file ${e}, removing stale lock`),r.unlinkSync(t),!1;try{return process.kill(i,0),!0}catch(n){return n.code===`ESRCH`?(D(`Removing stale lock file ${e} for dead process ${i}`),r.unlinkSync(t),!1):(D(`Error checking process ${i} for lock ${e}:`,n),!0)}}catch(t){return D(`Error reading lock file ${e}:`,t),!0}}static async acquireLock(e,t=5e3){await this.ensureCacheDirectories();let n=l.join(this.LOCKS_DIR,e),i=Date.now(),a=String(process.pid);for(;Date.now()-i<t;)try{return await r.promises.writeFile(n,a,{flag:`wx`}),D(`Lock acquired for ${e}`),!0}catch(e){if(e.code===`EEXIST`)await de(50);else throw e}return D(`Failed to acquire lock for ${e} within ${t}ms`),!1}static async releaseLock(e){let t=l.join(this.LOCKS_DIR,e);try{await r.promises.unlink(t),D(`Lock released for ${e}`)}catch(t){t.code!==`ENOENT`&&D(`Error releasing lock for ${e}:`,t)}}static async ensureCacheDirectories(){try{await Promise.all([r.promises.mkdir(this.CACHE_DIR,{recursive:!0}),r.promises.mkdir(this.USAGE_CACHE_DIR,{recursive:!0}),r.promises.mkdir(this.LOCKS_DIR,{recursive:!0})])}catch(e){D(`Failed to create cache directories:`,e)}}static createProjectHash(e){return ae(`md5`).update(e).digest(`hex`).substring(0,8)}static async getUsageCache(e,t){await this.ensureCacheDirectories();let n=l.join(this.USAGE_CACHE_DIR,`${e}.json`),i=`${e}.usage.lock`;for(let a=0;a<3;a++){if(this.isLocked(i)){D(`Cache for ${e} is locked, waiting...`),await de(75);continue}try{let i=await r.promises.readFile(n,`utf-8`),a=JSON.parse(i);return!t||a.timestamp>=t?(D(`[CACHE-HIT] ${e} disk cache: found`),this.deserializeDates(a.data)):(D(`${e} cache outdated: cache=${a.timestamp}, latest=${t}`),null)}catch(t){if(t.code===`ENOENT`)return D(`No shared ${e} usage cache found`),null;D(`Attempt ${a+1} failed to read ${e} cache: ${t.message}. Retrying...`),await de(75)}}return D(`Failed to read ${e} cache after 3 attempts.`),null}static deserializeDates(e){return Array.isArray(e)?e.map(e=>({...e,timestamp:new Date(e.timestamp)})):e}static async setUsageCache(e,t,n){let i=`${e}.usage.lock`;if(!await this.acquireLock(i)){D(`Could not acquire lock to set usage cache for ${e}`);return}try{await this.ensureCacheDirectories();let i=l.join(this.USAGE_CACHE_DIR,`${e}.json`),a=JSON.stringify({data:t,timestamp:n||Date.now()});await r.promises.writeFile(i,a,`utf-8`),D(`[CACHE-SET] ${e} disk cache stored`)}catch(t){D(`Failed to save ${e} usage cache:`,t)}finally{await this.releaseLock(i)}}};const FL={"claude-haiku-4-5-20251001":{name:`Claude Haiku 4.5`,input:1,output:5,cache_write_5m:1.25,cache_write_1h:2,cache_read:.1},"claude-haiku-4-5":{name:`Claude Haiku 4.5`,input:1,output:5,cache_write_5m:1.25,cache_write_1h:2,cache_read:.1},"claude-opus-4-20250514":{name:`Claude Opus 4`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-opus-4-1":{name:`Claude Opus 4.1`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-opus-4-1-20250805":{name:`Claude Opus 4.1`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-sonnet-4-20250514":{name:`Claude Sonnet 4`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-4-opus-20250514":{name:`Claude 4 Opus`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-4-sonnet-20250514":{name:`Claude 4 Sonnet`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-sonnet-4-5":{name:`Claude Sonnet 4.5`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-sonnet-4-5-20250929":{name:`Claude Sonnet 4.5`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-opus-4-5":{name:`Claude Opus 4.5`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-opus-4-5-20251101":{name:`Claude Opus 4.5`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-opus-4-6":{name:`Claude Opus 4.6`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-opus-4-6-20260205":{name:`Claude Opus 4.6`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-sonnet-4-6":{name:`Claude Sonnet 4.6`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3}};var IL=class{static executionCache=null;static modelPricingCache=new Map;static GITHUB_PRICING_URL=`https://raw.githubusercontent.com/promptctl/cc-candybar/main/pricing.json`;static async loadDiskCache(){let e=Date.now()-1440*60*1e3;return await PL.getUsageCache(`pricing`,e)}static async saveDiskCache(e){await PL.setUsageCache(`pricing`,e)}static async fetchPricingData(){return new Promise(e=>{let t=new ee(this.GITHUB_PRICING_URL),n=E({hostname:t.hostname,path:t.pathname,headers:{"User-Agent":`cc-candybar`,"Cache-Control":`no-cache`},timeout:5e3},t=>{if(t.statusCode!==200){D(`HTTP ${t.statusCode}: ${t.statusMessage}`),e(null);return}let r=``,i=0;t.on(`data`,t=>{if(i+=t.length,i>1048576){D(`Response too large`),n.destroy(),e(null);return}r+=t}),t.on(`end`,()=>{try{let t=JSON.parse(r),n=t._meta,i={};for(let[e,n]of Object.entries(t))e!==`_meta`&&(i[e]=n);this.validatePricingData(i)?(D(`Fetched fresh pricing from GitHub for ${Object.keys(i).length} models`),D(`Pricing last updated: ${n?.updated||`unknown`}`),e(i)):(D(`Invalid pricing data structure`),e(null))}catch(t){D(`Failed to parse JSON:`,t),e(null)}}),t.on(`error`,t=>{D(`Response error:`,t),e(null)})});n.on(`error`,t=>{D(`Request error:`,t),e(null)}),n.on(`timeout`,()=>{D(`Request timeout`),n.destroy(),e(null)}),n.end()})}static async getCurrentPricing(){if(this.executionCache!==null)return D(`[CACHE-HIT] Pricing execution cache: ${Object.keys(this.executionCache).length} models`),this.executionCache;let e=await this.loadDiskCache();if(e)return D(`[CACHE-HIT] Pricing disk cache: ${Object.keys(e).length} models`),this.executionCache=e,D(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(e).length} models`),e;let t=await this.fetchPricingData();return t?(await this.saveDiskCache(t),D(`[CACHE-SET] Pricing disk cache stored: ${Object.keys(t).length} models`),this.executionCache=t,D(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(t).length} models`),t):(D(`[CACHE-FALLBACK] Using offline pricing data: ${Object.keys(FL).length} models`),this.executionCache=FL,D(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(FL).length} models`),FL)}static validatePricingData(e){if(!e||typeof e!=`object`)return!1;for(let[,t]of Object.entries(e)){if(!t||typeof t!=`object`)return!1;let e=t;if(typeof e.input!=`number`||typeof e.output!=`number`||typeof e.cache_read!=`number`)return!1}return!0}static async getModelPricing(e){if(this.modelPricingCache.has(e))return D(`[CACHE-HIT] Model pricing cache: ${e}`),this.modelPricingCache.get(e);let t=await this.getCurrentPricing(),n;return n=t[e]?t[e]:this.fuzzyMatchModel(e,t),this.modelPricingCache.set(e,n),D(`[CACHE-SET] Model pricing cache: ${e}`),n}static fuzzyMatchModel(e,t){let n=e.toLowerCase();for(let[e,r]of Object.entries(t))if(e.toLowerCase()===n)return r;for(let{pattern:e,fallback:r}of[{pattern:[`opus-4-6`,`claude-opus-4-6`],fallback:`claude-opus-4-6-20260205`},{pattern:[`opus-4-5`,`claude-opus-4-5`],fallback:`claude-opus-4-5-20251101`},{pattern:[`opus-4-1`,`claude-opus-4-1`],fallback:`claude-opus-4-1-20250805`},{pattern:[`opus-4`,`claude-opus-4`],fallback:`claude-opus-4-20250514`},{pattern:[`sonnet-4-6`,`sonnet-4.6`,`claude-sonnet-4-6`],fallback:`claude-sonnet-4-6`},{pattern:[`sonnet-4.5`,`4-5-sonnet`,`sonnet-4-5`],fallback:`claude-sonnet-4-5-20250929`},{pattern:[`sonnet-4`,`claude-sonnet-4`],fallback:`claude-sonnet-4-20250514`},{pattern:[`haiku-4.5`,`4-5-haiku`,`haiku-4-5`],fallback:`claude-haiku-4-5-20251001`},{pattern:[`haiku`],fallback:`claude-haiku-4-5-20251001`},{pattern:[`opus`],fallback:`claude-opus-4-20250514`},{pattern:[`sonnet`],fallback:`claude-sonnet-4-5-20250929`}])if(e.some(e=>n.includes(e))&&t[r])return t[r];return t[`claude-sonnet-4-5-20250929`]||{name:`${e} (Unknown Model)`,input:3,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3,output:15}}static async calculateCostForEntry(e){let t=e.message?.usage;if(!t)return 0;let n=this.extractModelId(e),r=await this.getModelPricing(n),i=t.input_tokens||0,a=t.output_tokens||0,o=t.cache_creation_input_tokens||0,s=t.cache_read_input_tokens||0,c=i/1e6*r.input,l=a/1e6*r.output,u=s/1e6*r.cache_read,d=o/1e6*r.cache_write_5m;return c+l+d+u}static extractModelId(e){if(e.model&&typeof e.model==`string`)return e.model;let t=e.message;if(t?.model){let e=t.model;if(typeof e==`string`)return e;let n=e;return(typeof n?.id==`string`?n.id:null)||`claude-sonnet-4-5-20250929`}return e.model_id&&typeof e.model_id==`string`?e.model_id:`claude-sonnet-4-5-20250929`}};const LL=/<command-name>\s*([^<\s][^<]*?)\s*<\/command-name>/;function RL(e){if(typeof e==`string`)return LL.exec(e)?.[1]}function zL(e){let t=e?.todos;if(!Array.isArray(t))return;let n=[];for(let e of t){if(typeof e!=`object`||!e)continue;let{content:t,activeForm:r,status:i}=e,a=i===`in_progress`,o=a&&typeof r==`string`?r:t;typeof o==`string`&&n.push({text:o,active:a,done:i===`completed`})}return n}function BL(e){return typeof e==`string`?e:Array.isArray(e)?e.find(e=>typeof e==`object`&&!!e&&e.type===`text`&&typeof e.text==`string`)?.text??``:``}function VL(e,t){let n=e.message?.content,r=[],i=[],a;if(Array.isArray(n))for(let e of n){if(typeof e!=`object`||!e)continue;let t=e;switch(t.type){case`tool_use`:{let{id:e,name:n}=t;if(typeof e!=`string`||typeof n!=`string`)break;r.push({id:e,name:n}),n===`TodoWrite`&&(a=zL(t.input)??a);break}case`tool_result`:{let e=t.tool_use_id;typeof e==`string`&&i.push(e);break}default:break}}let o=t===`prompt`?RL(BL(n)):void 0;if(!(r.length===0&&i.length===0&&a===void 0&&o===void 0))return{...r.length>0&&{started:r},...i.length>0&&{finished:i},...a!==void 0&&{todos:a},...o!==void 0&&{command:o}}}function HL(e){if(e!==void 0)return[e];let t=g();return[p(t,`.config`,`claude`),p(t,`.claude`)].filter(e=>a(e))}async function UL(e){let t=[];for(let n of e){let e=p(n,`projects`);if(a(e))try{let n=await FF(e,{withFileTypes:!0});for(let r of n)if(r.isDirectory()){let n=p(e,r.name);t.push(n)}}catch(t){D(`Failed to read projects directory ${e}:`,t)}}return t}async function WL(e,t,n){let r=[],i=p(t,e,`subagents`);try{let t=(await FF(i)).filter(e=>e.startsWith(`agent-`)&&e.endsWith(`.jsonl`));for(let a of t){let t=p(i,a);if(n?.has(t)){r.push(t);continue}try{let n=(await IF(t,`utf-8`)).split(`
196
- `)[0];n&&JSON.parse(n).sessionId===e&&r.push(t)}catch{D(`Failed to check agent file ${t}`)}}}catch(e){D(`Failed to read subagents directory ${i}:`,e)}return r}function GL(e){let t=e.message;if((e.type||t?.role||t?.type)!==`user`)return;if(qL(t)===`tool_result`)return`tool-result`;let n=typeof e.origin==`object`&&e.origin!==null?e.origin.kind:void 0;if(n!==void 0&&n!==`human`)return`turn`;let r=BL(t?.content).trimStart();return r.startsWith(`[Request interrupted by user`)?`interrupt`:e.isMeta===!0||e.isCompactSummary===!0||KL.test(r)?`claude-code`:`prompt`}const KL=/^<(?:command-name|local-command-std(?:out|err)|bash-(?:input|stdout|stderr))>/;function qL(e){let t=e?.content;return Array.isArray(t)&&typeof t[0]==`object`&&t[0]?t[0].type:void 0}const JL=new Map;async function YL(e){try{let t=await LF(e),n=t.size,r=JL.get(e);if(r&&r.mtime===t.mtimeMs&&r.size===n)return D(`[parse-cache] hit ${e}`),JL.delete(e),JL.set(e,r),r.entries;let i;return n>1048576?(D(`Using streaming parser for large file ${e} (${Math.round(n/1024)}KB)`),i=await eR(e)):i=await QL(e),D(`Parsed ${i.length} entries from ${e}`),n>5242880?i:(JL.delete(e),JL.size>=16&&JL.delete(JL.keys().next().value),JL.set(e,{mtime:t.mtimeMs,size:n,entries:i}),i)}catch(t){if(t.code===`ENOENT`)return D(`Transcript not present yet: ${e}`),[];throw t}}function XL(e){if(!e.timestamp)return null;let t=e.message,n=t?.usage,r=GL(e);return{timestamp:new Date(e.timestamp),type:typeof e.type==`string`?e.type:void 0,message:t?{id:typeof t.id==`string`?t.id:void 0,model:typeof t.model==`string`?t.model:void 0,usage:n,role:typeof t.role==`string`?t.role:void 0,type:typeof t.type==`string`?t.type:void 0}:void 0,costUSD:typeof e.costUSD==`number`?e.costUSD:void 0,isSidechain:e.isSidechain===!0,userEntry:r,activity:VL(e,r),raw:{model:typeof e.model==`string`?e.model:void 0,message:t?{id:typeof t.id==`string`?t.id:void 0,model:typeof t.model==`string`?t.model:void 0,usage:n}:void 0,requestId:typeof e.requestId==`string`?e.requestId:void 0}}}function ZL(e){let t=[];for(let n of e.split(`
197
- `))if(n.trim())try{let e=XL(JSON.parse(n));e&&t.push(e)}catch(e){D(`Failed to parse JSONL line: ${e}`);continue}return t}async function QL(e){return ZL(await IF(e,`utf-8`))}async function $L(e,t){let n=await RF(e,t===void 0?void 0:{offset:t.offset,ino:t.ino});if(n.kind!==`ok`)return n;let{buf:r,start:i,stamp:a,ino:o,reset:s}=n.value,c=r.lastIndexOf(10);return R(c<0?{entries:[],cursor:{offset:i,stamp:a,ino:o},reset:s}:{entries:ZL(r.subarray(0,c+1).toString(`utf-8`)),cursor:{offset:i+c+1,stamp:a,ino:o},reset:s})}async function eR(e){return new Promise((t,n)=>{let r=[],a=i(e,{encoding:`utf8`}),o=fe({input:a,crlfDelay:1/0});o.on(`line`,e=>{let t=e.trim();if(t)try{let e=XL(JSON.parse(t));e&&r.push(e)}catch(e){D(`Failed to parse JSONL line: ${e}`)}}),o.on(`close`,()=>{t(r)}),o.on(`error`,t=>{D(`Streaming parser error for ${e}:`,t),n(t)}),a.on(`error`,t=>{D(`File stream error for ${e}:`,t),n(t)})})}var tR=class{inflight=new Map;run(e,t){return this.inflight.get(e)??this.start(e,t)}start(e,t){let n=t();this.inflight.set(e,n);let r=()=>{this.inflight.get(e)===n&&this.inflight.delete(e)};return n.then(r,r),n}get size(){return this.inflight.size}};function nR(e,t){let n=e?e.input+e.cacheCreation+e.cacheRead:0,r=e?e.output:0;return{input:n,output:r,total:n+r,atMs:t}}const rR=new Map,iR={cost:0,input:0,output:0,cacheCreation:0,cacheRead:0},aR={cost:null,calculatedCost:null,officialCost:null,tokens:null,tokenBreakdown:null};function oR(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function sR(){let e=new Date;return e.setHours(0,0,0,0),e.setDate(e.getDate()-1),e.getTime()}function cR(){return{input:0,output:0,cacheCreation:0,cacheRead:0}}async function lR(e,t,n,r){let i=oR(new Date(sR())),a=e&&!t?e:void 0,o=a?.entries??0,s=a?.cost??0,c=a?{...a.breakdown}:cR(),l=new Map;if(a)for(let[e,t]of a.days)e>=i&&l.set(e,{...t});for(let e of n){let t=e.message?.usage;if(!t)continue;o++;let n=e.costUSD??await IL.calculateCostForEntry(e.raw);s+=n,c.input+=t.input_tokens||0,c.output+=t.output_tokens||0,c.cacheCreation+=t.cache_creation_input_tokens||0,c.cacheRead+=t.cache_read_input_tokens||0;let r=oR(new Date(e.timestamp));if(r<i)continue;let a=l.get(r)??{...iR};a.cost+=n,a.input+=t.input_tokens||0,a.output+=t.output_tokens||0,a.cacheCreation+=t.cache_creation_input_tokens||0,a.cacheRead+=t.cache_read_input_tokens||0,l.set(r,a)}return{cursor:r,entries:o,cost:s,breakdown:c,days:l}}function uR(e){let t=0,n=0,r=cR(),i=new Map;for(let a of e.values()){t+=a.entries,n+=a.cost,r.input+=a.breakdown.input,r.output+=a.breakdown.output,r.cacheCreation+=a.breakdown.cacheCreation,r.cacheRead+=a.breakdown.cacheRead;for(let[e,t]of a.days){let n=i.get(e)??{...iR};n.cost+=t.cost,n.input+=t.input,n.output+=t.output,n.cacheCreation+=t.cacheCreation,n.cacheRead+=t.cacheRead,i.set(e,n)}}if(t===0)return{sessionInfo:aR,days:i};let a=r.input+r.output+r.cacheCreation+r.cacheRead;return{sessionInfo:{cost:n,calculatedCost:n,officialCost:null,tokens:a,tokenBreakdown:r},days:i}}async function dR(e,t,n){let r=0,i=async()=>{for(;r<e.length;){let t=e[r++];await n(t)}},a=Math.min(t,e.length);await Promise.all(Array.from({length:a},i))}var fR=class{sessions=new Map;flight=new tR;seeded=new Map;seededDay=``;rescanIntervalMs;speedFlight=new tR;staleAgeMs;log;renderTally={hits:0,misses:0};sweeps=0;scans={seed:0,rescan:0};sweepTimer=null;constructor(e={}){this.log=e.logger??Nt,this.staleAgeMs=e.staleAgeMs??864e5,this.rescanIntervalMs=e.rescanIntervalMs??6e4;let t=e.sweepIntervalMs??3e5;t>0&&(this.sweepTimer=setInterval(()=>this.sweepStale(),t),this.sweepTimer.unref())}getStats(){return{size:this.sessions.size,hits:this.renderTally.hits,misses:this.renderTally.misses,sweeps:this.sweeps,seeds:this.scans.seed,rescans:this.scans.rescan}}async getUsageInfo(e,t){let n=await this.ingest(e,t?.transcript_path,this.renderTally);if(n.kind===`failed`)return n;let r=n.kind===`ok`?n.value.sessionInfo:aR,i=t?.cost?.total_cost_usd??null;return R({session:{...r,cost:i??r.cost,officialCost:i}})}async getTodayInfo(e,t,n){let r=oR(yw(n)),i=HL(t);try{await this.ensureSeeded(r,i,n*1e3)}catch(e){return B(`usage seed: ${e instanceof Error?e.message:String(e)}`)}let a=await this.ingest(e?.session_id??``,e?.transcript_path,this.renderTally);if(a.kind===`failed`)return a;let o=i.map(e=>p(e,`projects`)+m),s={...iR},c=!1;for(let[t,{record:n}]of this.sessions){let i=n?.transcriptPath??``,a=t===e?.session_id||o.some(e=>i.startsWith(e))?n?.days??rR:rR;c||=a.has(r);let l=a.get(r)??iR;s.cost+=l.cost,s.input+=l.input,s.output+=l.output,s.cacheCreation+=l.cacheCreation,s.cacheRead+=l.cacheRead}return c?R({cost:s.cost,tokens:s.input+s.output+s.cacheCreation+s.cacheRead,tokenBreakdown:{input:s.input,output:s.output,cacheCreation:s.cacheCreation,cacheRead:s.cacheRead},date:r}):z}async observeSpeed(e,t,n){if(!e)return z;let r=jF(t);return this.speedFlight.run(`${e}:${r}`,async()=>{let i=await this.ingest(e,t,this.renderTally,r);if(i.kind===`failed`)return i;let a=nR(i.kind===`ok`?i.value.sessionInfo.tokenBreakdown:null,n),{ring:o}=this.hold(e),s;for(let e of o)e.atMs<a.atMs&&(s===void 0||e.atMs>s.atMs)&&(s=e);return o.push(a),o.sort((e,t)=>e.atMs-t.atMs),o.length>64&&o.shift(),R({...s!==void 0&&{prev:s},cur:a,samples:[...o]})})}async ingest(e,t,n,r){if(!e)return z;let i=r??jF(t),a=this.see(e)?.record;if(a&&i!==``&&a.transcriptStamp===i)return n.hits++,R(a);if(!t)return a?R(a):z;n.misses++;let o;try{o=await this.flight.run(`${e}:${i}`,async()=>{let n=this.sessions.get(e)?.record;return{prior:n,outcome:await this.refold(e,t,n)}})}catch(t){return B(`usage refold (${e}): ${t instanceof Error?t.message:String(t)}`)}let{prior:s,outcome:c}=o;if(c.kind!==`ok`)return c;let l={files:c.value.files,sessionInfo:c.value.sessionInfo,days:c.value.days,transcriptStamp:c.value.mainStamp,transcriptPath:t};return this.sessions.get(e)?.record===s&&(this.hold(e).record=l),R(l)}see(e){let t=this.sessions.get(e);return t&&(t.lastSeenAt=Date.now()),t}hold(e){let t=this.see(e);if(t)return t;let n={lastSeenAt:Date.now(),record:void 0,ring:[]};return this.sessions.set(e,n),n}async refold(e,t,n){let r=await WL(e,d(t),n===void 0?void 0:new Set(n.files.keys())),i=new Map,a=``;for(let e of[t,...r]){let r=n?.files.get(e),o=await $L(e,r?.cursor);if(o.kind===`failed`)return o;if(o.kind===`absent`){r&&i.set(e,r);continue}let{entries:s,cursor:c,reset:l}=o.value;i.set(e,await lR(r,l,s,c)),e===t&&(a=c.stamp)}return R({files:i,...uR(i),mainStamp:a})}ensureSeeded(e,t,n){this.seededDay!==e&&(this.seeded.clear(),this.seededDay=e);let r=t.join(`\0`),i=this.seeded.get(r);if(!i){let e=this.seed(t,`seed`),i={done:e,scanning:e,startedAtMs:n};return this.seeded.set(r,i),this.settle(r,i,e),e}return i.scanning===void 0&&n-i.startedAtMs>=this.rescanIntervalMs&&(i.startedAtMs=n,i.scanning=this.seed(t,`rescan`),this.settle(r,i,i.scanning)),i.done}settle(e,t,n){n.then(()=>{t.scanning=void 0},n=>{this.log(`warn`,`usageStore scan: ${n instanceof Error?n.message:String(n)}`),this.seeded.get(e)===t&&this.seeded.delete(e)})}async scanned(){await Promise.allSettled([...this.seeded.values()].map(e=>e.scanning))}async seed(e,t){let n=Date.now(),r=sR(),i=await UL(e),a=[];for(let e of i){let t;try{t=await FF(e)}catch{continue}for(let n of t){if(!n.endsWith(`.jsonl`))continue;let t=p(e,n),i;try{i=await LF(t)}catch{continue}i.mtimeMs<r||a.push({sessionId:n.slice(0,-6),path:t,stamp:MF(i)})}}let o={hits:0,misses:0};await dR(a,8,async e=>{let n=await this.ingest(e.sessionId,e.path,o,e.stamp);n.kind===`failed`&&this.log(`warn`,`usageStore ${t}: ${n.reason}`)}),this.log(`info`,`usageStore ${t} sessions=${a.length} read=${o.misses} dirs=${e.join(`,`)} ms=${Date.now()-n}`),this.scans[t]++}sweepStale(){let e=Date.now(),t=0,n=0,r=0;for(let[i,{lastSeenAt:a,record:o}]of this.sessions)if(!(e-a<=this.staleAgeMs)){if(o?.days.has(this.seededDay)){n++;continue}this.sessions.delete(i),t++,o===void 0&&r++}return t>0&&this.sweeps++,(t>0||n>0)&&this.log(`info`,`usageStore sweep dropped=${t} noRecord=${r} held=${n}`),t}close(){this.sweepTimer&&=(clearInterval(this.sweepTimer),null),this.sessions.clear(),this.seeded.clear()}},pR=class{thresholds={LOW:50,MEDIUM:80};getContextUsageThresholds(){return this.thresholds}ratioPercentages(e,t){let n=Math.min(100,Math.max(0,Math.round(e/t*100)));return{percentage:n,contextLeftPercentage:Math.max(0,100-n)}}calculateContextFromHookData(e){let t=e.context_window;if(!t?.current_usage)return D(`No current_usage in hook data, falling back to transcript parsing`),null;let n=t.current_usage,r=t.context_window_size,i=(n.input_tokens||0)+(n.cache_creation_input_tokens||0)+(n.cache_read_input_tokens||0);D(`Native current_usage: input=${n.input_tokens}, cache_create=${n.cache_creation_input_tokens}, cache_read=${n.cache_read_input_tokens}, total=${i} (limit: ${r})`);let a=this.ratioPercentages(i,r);return{totalTokens:i,maxTokens:r,percentage:t.used_percentage==null?a.percentage:Math.round(t.used_percentage),contextLeftPercentage:t.remaining_percentage==null?a.contextLeftPercentage:Math.round(t.remaining_percentage)}}async calculateContextTokensFromTranscript(e,t){try{D(`Calculating context tokens from transcript: ${e}`);let n=await YL(e);if(n.length===0)return D(`No entries in transcript`),z;let r=null;for(let e=n.length-1;e>=0;e--){let t=n[e];if(t&&t.message?.usage?.input_tokens&&t.isSidechain!==!0){r=t,D(`Context segment: Found most recent entry at ${t.timestamp.toISOString()}, stopping search`);break}}if(r?.message?.usage){let e=r.message.usage,n=(e.input_tokens||0)+(e.cache_read_input_tokens||0)+(e.cache_creation_input_tokens||0);return D(`Most recent main chain context: ${n} tokens (limit: ${t})`),R({totalTokens:n,maxTokens:t,...this.ratioPercentages(n,t)})}return D(`No main chain entries with usage data found`),z}catch(e){return B(`context transcript: ${e instanceof Error?e.message:String(e)}`)}}async getContextInfo(e){let t=this.calculateContextFromHookData(e);if(t)return R(t);let n=e.context_window?.context_window_size??2e5;return this.calculateContextTokensFromTranscript(e.transcript_path,n)}},mR=class{states=new Map;constructor(e,t,n=256){this.empty=e,this.step=t,this.maxSessions=n}async read(e,t){let n=this.states.get(e),r=jF(t);if(n&&r!==``&&n.cursor.stamp===r)return this.touch(e,n),{kind:`ok`,value:n.value};let i=await $L(t,n?.cursor);if(i.kind===`failed`)return i;if(i.kind===`absent`)return{kind:`ok`,value:n?.value??this.empty};let{entries:a,cursor:o,reset:s}=i.value,c=s||n===void 0?this.empty:n.value;for(let e of a)c=this.step(c,e);for(this.touch(e,{cursor:o,value:c});this.states.size>this.maxSessions;){let e=this.states.keys().next().value;if(e===void 0)break;this.states.delete(e)}return{kind:`ok`,value:c}}touch(e,t){this.states.delete(e),this.states.set(e,t)}};const hR={messageCount:0,nonPrompts:0,recent:[]},gR=new Set([`turn`,`interrupt`,`claude-code`]);function _R(e,t){if(t.isSidechain)return e;let n=[...e.recent,t];return{messageCount:e.messageCount+ +(t.userEntry===`prompt`),nonPrompts:e.nonPrompts+ +!!gR.has(t.userEntry),recent:n.length>20?n.slice(-20):n}}function vR(e){let t=null,n=null;for(let r of e){let e=r.type||r.message?.role||r.message?.type;if(r.userEntry===`prompt`||r.userEntry===`turn`)t=r.timestamp;else if(e===`assistant`&&t){let e=(r.timestamp.getTime()-t.getTime())/1e3;e>.1&&e<300&&(n=e)}}return n}var yR=class{fold=new mR(hR,_R);async getMetricsInfo(e,t){if(D(`Getting metrics from hook data for session: ${e}`),!t.cost)return z;let n=await this.fold.read(e,t.transcript_path);return n.kind===`failed`?B(`metrics (${e}): ${n.reason}`):R({responseTime:t.cost.total_api_duration_ms/1e3,lastResponseTime:vR(n.value.recent),sessionDuration:t.cost.total_duration_ms/1e3,messageCount:n.value.messageCount,nonPrompts:n.value.nonPrompts,linesAdded:t.cost.total_lines_added,linesRemoved:t.cost.total_lines_removed})}};const bR={command:null,todos:[],pending:[],done:[]};function xR(e,t){let n=e.findIndex(e=>e.name===t);return n<0?[...e,{name:t,count:1}]:e.map((e,t)=>t===n?{name:e.name,count:e.count+1}:e)}function SR(e,t){switch(t.userEntry){case`prompt`:return{...e,command:t.activity?.command??null,pending:[],done:[]};case`interrupt`:return{...e,pending:[]};case`turn`:case`tool-result`:case`claude-code`:case void 0:return e}}function CR(e,t){if(t.isSidechain)return e;let n=SR(e,t),r=t.activity;if(r===void 0)return n;let i=n.pending,a=n.done;r.started!==void 0&&(i=[...i,...r.started]);for(let e of r.finished??[]){let t=i.findIndex(t=>t.id===e);t<0||(a=xR(a,i[t].name),i=[...i.slice(0,t),...i.slice(t+1)])}return{...n,pending:i,done:a,todos:r.todos??n.todos}}function wR(e){return{command:e.command,todos:e.todos,running:e.pending.reduce((e,t)=>xR(e,t.name),[]),done:e.done}}var TR=class{fold=new mR(bR,CR);async getActivityInfo(e,t){let n=await this.fold.read(e,t.transcript_path);return n.kind===`failed`?B(`activity (${e}): ${n.reason}`):R(wR(n.value))}};function ER(e,t,n,r){return{bin:`tmux`,args:[`-S`,e.socket,...n],timeoutMs:2e3,category:t,stdinInput:r}}function DR(e,t){if(e.ok)return{kind:`ok`,stdout:e.stdout};if(e.reason===`rate-limited`)return{kind:`rate-limited`,reason:e.error??`rate-limited`};let n=e.error??[e.reason,e.stderr.trim()].filter(e=>e!==``).join(`: `);return{kind:`failed`,reason:`tmux ${t[0]} failed (${n})`}}function OR(e,t,n,r){return DR(Me(ER(e,t,n,r)),n)}async function kR(e,t,n){return DR(await O(ER(e,t,n)),n)}const AR=e=>`${e.socket}\n${e.pane}`;var jR=class{names=new Map;asking=new tR;constructor(e=Date.now){this.now=e}getSessionName(e){let t=AR(e),n=this.names.get(t);if(n&&this.now()-n.at<3e4)return Promise.resolve(n.outcome);let r=this.asking.run(t,()=>this.ask(t,e));return n?Promise.resolve(n.outcome):r}async ask(e,t){D(`Getting tmux session name for pane ${t.pane} on ${t.socket}`);let n=await kR(t,`tmux`,[`display-message`,`-p`,`-t`,t.pane,`#S`]),r=n.kind===`ok`?n.stdout.trim():``,i=n.kind===`ok`?r?R(r):z:B(n.reason);for(this.names.delete(e),this.names.set(e,{outcome:i,at:this.now()});this.names.size>64;)this.names.delete(this.names.keys().next().value);return i}};const MR=e=>JSON.stringify([e.sessionId,e.projectDir,e.cwd,e.claudeConfigDir,e.env===void 0?null:et.map(t=>e.env?.[t]??null)]);var NR=class{readings=new Map;inFlight=new Map;constructor(e,t=Date.now){this.edge=e,this.now=t}getCeiling(e){let t=MR(e),n=this.readings.get(t);if(n&&this.now()-n.at<1e4)return Promise.resolve(n.outcome);let r=this.inFlight.get(t)??this.fetch(t,e);return n?Promise.resolve(n.outcome):r}fetch(e,t){let n=this.edge.locate(t),r=(n.kind===`ok`?this.edge.read(n.value,t):Promise.resolve(n)).then(t=>{if(this.inFlight.get(e)!==r)return t;for(this.readings.delete(e),this.readings.set(e,{outcome:t,at:this.now()});this.readings.size>64;)this.readings.delete(this.readings.keys().next().value);return t}).finally(()=>{this.inFlight.get(e)===r&&this.inFlight.delete(e)});return this.inFlight.set(e,r),r}move(e,t){let n=this.edge.locate(e);if(n.kind!==`ok`)throw Error(n.kind===`failed`?n.reason:`memento is not installed or not enabled for this project`);let r=MR(e);try{this.edge.move(n.value,e,t)}finally{this.readings.delete(r),this.inFlight.delete(r),this.fetch(r,e)}}};function PR(e){return{gitProvider:new pw({watchers:e.watchers,logger:e.logger}),usageStore:new fR({logger:e.logger}),contextProvider:new pR,metricsProvider:new yR,activityProvider:new TR,tmuxService:new jR,mementoProvider:new NR(nI()),autoCompact:tO,log:e.logger}}function FR(e,t){return e===void 0?!0:e.evaluate(t).map(e=>e.plain).join(``)!==`false`}const IR={kind:`hidden`},LR={kind:`shown`};function RR(e,t){try{return FR(e,t)?LR:IR}catch(e){return{kind:`failed`,message:e instanceof Error?e.message:String(e)}}}function zR(e,t){let n=q.fromFragments(e);return n.end=``,n.overflow=`ignore`,t!==void 0&&!t.isNull&&(n.style=t),n}function BR(e,t,n){e.cellLength>t?e.truncate(t,{mode:n.truncate,marker:`…`}):e.cellLength<t&&e.align(n.justify,t)}function VR({lead:e,text:t,trail:n}){return[...e===void 0?[]:[e],t,...n===void 0?[]:[n]]}function HR({text:e,placement:t,lead:n,trail:r}){return{text:UR(e),placement:t,...n!==void 0&&{lead:UR(n)},...r!==void 0&&{trail:UR(r)}}}function UR(e){let t=e.blankCopy(e.plain);t.style=am(e.style).clearMetaAndLinks();for(let{start:n,end:r,style:i}of e.spans)t.stylize(am(i).clearMetaAndLinks(),n,r);return t}function WR(e){let t=VR(e);if(t.length===1)return e.text;let n=zR(t);return n.style=e.text.style,n}function GR(e,t){let{width:n,justify:r,truncate:i,baseStyle:a,padding:o,placement:s,lead:c=[],trail:l=[]}=t;if(e.length===0)return[];let u=zR(e,a).pad(o),d=new q(` `.repeat(o)),f={placement:s,...c.length>0&&{lead:zR([d,...c],a)},...l.length>0&&{trail:zR([...l,d],a)}};if(n===`auto`)return[{text:u,...f}];let p={justify:r,truncate:i};return n===`fill`?[{text:u,fill:p,...f}]:(BR(u,n,p),[{text:u,...f}])}function KR(e,t){let n=()=>e.map(e=>({owner:WR(e),placement:e.placement})),r=[];if(e.forEach(({fill:e},t)=>{e!==void 0&&r.push({at:t,how:e})}),r.length===0||!Number.isFinite(t.width))return n();let i=Dm(e.map(WR),t).split(`
198
- `);if(i.length>1)return n();let a=Math.max(0,t.width-_m(i[0]??``)),o=Math.floor(a/r.length),s=a-o*r.length;return r.forEach(({at:t,how:n},i)=>{let a=o+(i===r.length-1?s:0),{text:c}=e[t];BR(c,c.cellLength+a,n)}),n()}function qR(e,t){let n=[],r=[],i=()=>{if(!r.length)return;let e=JR(r,t);e.plain.length>0&&n.push(e),r=[]};for(let a of e){let e={frag:a,style:am(a.style)};if(e.style.link){i();let r=JR([e],t);r.plain.length>0&&n.push(r)}else r.push(e)}return i(),n}function JR(e,t){let n=t!==void 0&&!t.isNull?t:void 0,r=e.map(e=>YR(e.frag,n?n.add(e.style):e.style)),i=q.fromFragments(r);return i.end=``,i.overflow=`ignore`,r.length===1?i.style=r[0].style:n!==void 0&&(i.style=n),i}function YR(e,t){let n=e.copy();return n.style=t,n}function XR(e,t){if(e.look===void 0)throw Error(`${t} read the render's look before any render resolved one`);return e.look}function ZR(e,t,n,r){let i=new Map,a=Object.entries(t);for(let[t,o]of[...a.filter(([,e])=>!(`do`in e)),...a.filter(([,e])=>`do`in e)])i.set(t,QR(e,t,o,n,r,i));return i}function QR(e,t,n,r,i,a){if(`set`in n){let e=r.get(n.set)??n.set;if(`to`in n)return{kind:`set-literal`,key:n.set,value:n.to,stateVar:e};if(`from`in n){let t=rg(n.from,i);return{kind:`set-option`,key:n.set,stateVar:e,options:[...t.members],paletteOf:t.paletteOf,library:t.library}}return`int`in n?{kind:`set-int`,key:n.set,stateVar:e}:`cycle`in n?{kind:`set-cycle`,key:n.set,stateVar:e,members:n.cycle}:{kind:`set-bounded`,key:n.set,by:n.by}}if(`persist`in n){let e=_a.get(n.persist)??n.persist;if(`to`in n)return{kind:`persist-literal`,key:n.persist,value:n.to,stateVar:e};if(`from`in n){let t=rg(n.from,i);return{kind:`persist-option`,key:n.persist,stateVar:e,options:[...t.members],paletteOf:t.paletteOf,library:t.library}}if(`cycle`in n)return{kind:`persist-cycle`,key:n.persist,stateVar:e,members:n.cycle};if(`removeSegment`in n)return{kind:`layout-op`,key:n.persist,op:{op:`remove`,target:n.removeSegment}};if(`insertSegment`in n)return{kind:`layout-op`,key:n.persist,op:{op:`insert`,segment:n.insertSegment,anchor:n.anchor,relation:n.relation}};if(`insertSegmentFrom`in n){let e=rg(n.insertSegmentFrom,i);return{kind:`layout-op-option`,key:n.persist,anchor:n.anchor,relation:n.relation,options:[...e.members],paletteOf:e.paletteOf,library:e.library}}return{kind:`persist-bounded`,key:n.persist,by:n.by}}if(`copy`in n)return{kind:`copy`,text:tz(e,n.copy,t)};if(`open`in n)return{kind:`open`,target:tz(e,n.open,t)};if(`reset`in n)return{kind:`reset`,key:n.reset};if(`doctor`in n)return n.doctor===`run`?{kind:`doctor-run`}:{kind:`doctor-fix`,check:n.check};if(`ceiling`in n)return{kind:`ceiling`,args:FM(n)};if(`slash`in n)return{kind:`slash`,line:n.slash};if(`undo`in n)return{kind:`undo`};if(`redo`in n)return{kind:`redo`};if(`back`in n)return{kind:`back`};if(`rewind`in n)return{kind:`rewind`};if(`save`in n)return{kind:`save`};if(`preset`in n)return n.preset===`save`?{kind:`preset-save`}:{kind:`preset-delete`,name:tz(e,n.name,t)};if(`themeDefault`in n)return{kind:`theme-default-save`};let[o,...s]=n.do.map(e=>{let n=a.get(e);if(n===void 0)throw Error(`action "${t}" fires "${e}", which is not declared in this config`);return n});return{kind:`do`,head:o,rest:s}}function $R(e){return e.kind===`do`?$R(e.head):e}function ez(e){switch($R(e).kind){case`set-option`:case`set-int`:case`persist-option`:case`layout-op-option`:return!0;case`set-literal`:case`set-bounded`:case`set-cycle`:case`copy`:case`open`:case`persist-literal`:case`persist-bounded`:case`persist-cycle`:case`reset`:case`layout-op`:case`undo`:case`redo`:case`back`:case`rewind`:case`save`:case`preset-save`:case`preset-delete`:case`theme-default-save`:case`doctor-run`:case`doctor-fix`:case`ceiling`:case`slash`:case`do`:return!1}}function tz(e,t,n){try{return e(t)}catch(e){throw Error(`Template parse error in actions.${n}: ${e.message}`,{cause:e})}}function nz(e,t){return e.has(t)?Fg(e.read(t)):``}function rz(e,t){return e.evaluate(t).map(e=>e.plain).join(``)}function iz(e,t,n,r){let i=new q(e,{style:G.combine([r,new G({link:t,bold:n})])});return i.overflow=`ignore`,i.end=``,i}function az(e,t,n=!1){let r=new G({link:t,bold:n?!0:void 0}),i=new q(e.plain,{style:G.combine([am(e.style),r])});for(let t of e.spans)i.stylize(G.combine([am(t.style),r]),t.start,t.end);return i.overflow=`ignore`,i.end=``,i}function oz(e,t){return Math.max(e.members.indexOf(nz(t,e.stateVar)),0)}function sz(e,t,n,r,i){switch(e.kind){case`set-literal`:{let t=nz(r,e.stateVar);return{effects:[{verb:gn,args:[i,e.key,e.value]}],active:t===e.value}}case`set-option`:{let a=n??t,o=nz(r,e.stateVar);return{effects:[{verb:gn,args:[i,e.key,a]}],active:o===a}}case`set-int`:{let a=n??t,o=nz(r,e.stateVar);return{effects:[{verb:gn,args:[i,e.key,a]}],active:o===a}}case`set-cycle`:{let t=e.members[(oz(e,r)+1)%e.members.length];return{effects:[{verb:gn,args:[i,e.key,t]}],active:!1}}case`set-bounded`:return{effects:[{verb:N,args:[i,e.key,String(e.by)]}],active:!1};case`copy`:return{effects:[{verb:_n,args:[rz(e.text,wC(r))]}],active:!1};case`open`:return{effects:[{verb:vn,args:[rz(e.target,wC(r))]}],active:!1};case`persist-literal`:{let t=nz(r,e.stateVar);return{effects:[{verb:Sn,args:[i,e.key,e.value]}],active:t===e.value}}case`persist-option`:{let a=n??t,o=nz(r,e.stateVar);return{effects:[{verb:Sn,args:[i,e.key,a]}],active:o===a}}case`persist-cycle`:{let t=e.members[(oz(e,r)+1)%e.members.length];return{effects:[{verb:Sn,args:[i,e.key,t]}],active:!1}}case`persist-bounded`:return{effects:[{verb:Cn,args:[i,e.key,String(e.by)]}],active:!1};case`reset`:return{effects:[{verb:Dn,args:[i,e.key]}],active:!1};case`undo`:return{effects:[{verb:kn,args:[i]}],active:!1};case`redo`:return{effects:[{verb:An,args:[i]}],active:!1};case`back`:return{effects:[{verb:jn,args:[i]}],active:!1};case`rewind`:return{effects:[{verb:Mn,args:[i]}],active:!1};case`save`:return{effects:[{verb:wn,args:[i]}],active:!1};case`preset-save`:return{effects:[{verb:P,args:[i]}],active:!1};case`theme-default-save`:return{effects:[{verb:Tn,args:[i]}],active:!1};case`preset-delete`:return{effects:[{verb:En,args:[i,rz(e.name,wC(r))]}],active:!1};case`doctor-run`:return{effects:[{verb:Pn,args:[i]}],active:!1};case`doctor-fix`:return{effects:[{verb:Fn,args:[i,e.check]}],active:!1};case`ceiling`:return{effects:[{verb:Ln,args:[i,...e.args]}],active:!1};case`slash`:return{effects:[{verb:Rn,args:[i,e.line]}],active:!1};case`layout-op`:return{effects:[{verb:On,args:[i,e.key,vA(e.op)]}],active:!1};case`do`:{let a=sz(e.head,t,n,r,i);return{effects:[...a.effects,...e.rest.flatMap(e=>sz(e,t,void 0,r,i).effects)],active:a.active}}case`layout-op-option`:{let r={op:`insert`,segment:n??t,anchor:e.anchor,relation:e.relation};return{effects:[{verb:On,args:[i,e.key,vA(r)]}],active:!1}}}}function cz(e,t,n,r){if(n.length===0)throw Error(`action "${e}" needs a display (the clickable text)`);if(t.kind===`set-cycle`||t.kind===`persist-cycle`)return{display:qn(`action "${e}"`,n,t.members.length,oz(t,r)),boundValue:void 0};if(n.length>2)throw Error(`action "${e}" takes a display and an optional bound value, got ${n.length} arguments (per-state displays are a cycle action's form)`);return{display:n[0],boundValue:n[1]?.plain}}function lz(e,t,n){let r=n.compiled.get(e);if(!r)throw Error(`action "${e}" is not declared in this config`);let i=n.store,{display:a,boundValue:o}=cz(e,$R(r),t,i),s=nz(i,`session.id`),{effects:c,active:l}=sz(r,a.plain,o,i,s);return az(a,I(c),l)}function uz(e){return{action:{fn:(t,...n)=>lz(t,n,e),argTypes:[`string`,`liftable`],arity:{kind:`variadic`},returnType:`T`}}}function dz(e,t){return iz(`✕`,I([{verb:gn,args:[nz(e,`session.id`),t,L]}]),!1)}function fz(e,t,n){return new G({bgcolor:W.fromRgba(t),color:W.fromRgba(Pf(e,t,n))})}function pz({tint:e,text:t}){return new G({bgcolor:W.fromRgba(e),color:W.fromRgba(t)})}function mz(e,t,n){return new G({color:W.fromRgba(Qs(wf(e,`warning`),t,Nf,n))})}function hz(e,t,n){return G.combine([fz(e,t,n),mz(e,t,n)])}function gz(e,t,n){return fz(e.palette,tp(e.palette,e.disclosure,[t],n),n)}function _z(e){let t=W.fromRgba(wf(e,`background`)),n=q.fromFragments(Xd.map(n=>new q(`▀`,{style:new G({color:W.fromRgba(wf(e,n)),bgcolor:t})})));return n.overflow=`ignore`,n.end=``,n}const vz=(e,t)=>{let n=typeof e==`string`?new q(e,{style:t}):e;return n.overflow=`ignore`,n.end=``,n},yz=e=>new G({bold:e});function bz(e,t,n,r,i,a){if(r===void 0)return(n,r,a,o)=>vz(a,G.combine([gz(e,{...n,distribution:t},i),yz(o)]));let o=fz(e.palette,a,i);return(e,t,i,a)=>xz(i,G.combine([o,yz(a)]),r(t,n))}const xz=(e,t,n)=>vz(q.fromFragments([vz(e,t),vz(` `,t),_z(n)]));function Sz(e,t){return t===void 0?(e,t,n)=>vz(n):(n,r,i)=>xz(i,void 0,t(r,e))}function Cz(e,t,n,r,i){let a=fz(e.palette,i,r);return(e,r,i,o)=>vz(q.fromFragments([vz(o?`[`:` `,a),_z(n(r,t)),vz(o?`]`:` `,a)]))}function wz(e,t,n){let r=t.map(t=>({label:t.label,indices:e.flatMap((e,n)=>e.group===t.id?[n]:[])})).filter(e=>e.indices.length>0);if(r.reduce((e,t)=>e+t.indices.length,0)!==e.length){let n=new Set(t.map(e=>e.id)),r=e.flatMap((e,t)=>n.has(e.group)?[]:[`#${t} (group "${e.group}")`]);throw Error(`library: ${r.join(`, `)} name a group the domain does not list (${[...n].join(`, `)})`)}return n?r.flatMap(e=>Tz(e.indices,8).map(t=>[{label:e.label,indices:t}])):[r]}function Tz(e,t){return Array.from({length:Math.ceil(e.length/t)},(n,r)=>e.slice(r*t,(r+1)*t))}function Ez(e,t){return new q(e).truncate(t,{marker:`…`}).plain}function Dz(e){return{current:null,drawnAt:e}}function Oz(e,t,n,r,i,a,o){let s={segName:t,placementId:n,palette:r,disclosure:i,tint:a,text:o,bg:void 0,drops:[]};return e.current=s,s}function kz(e,t){let n=e.current;if(n===null)throw Error(`${t} is only available inside a segment's templates — there is no active segment here. Segment-scoped functions cannot be used in variable declarations or layout-node "when" predicates, which are evaluated outside any segment.`);return n}function Az(e){return new q(e).cellLength}function jz(e){return Math.max(1,e.width-e.chromeCols-2*e.padding)}function Mz(e){return Math.max(1,jz(e)-(Az(`✕`)+2*e.padding+e.seamCols))}function Nz(e,t,n){if(!Number.isFinite(t))return e.length>0?[e.map((e,t)=>t)]:[];let r=Math.max(1,t-n),i=[],a=[],o=0;for(let t=0;t<e.length;t++){let n=e[t];a.length===0?(a=[t],o=n):o+1+n<=r?(a.push(t),o+=1+n):(i.push(a),a=[t],o=n)}return a.length>0&&i.push(a),i}function Pz(e,t,n){let r=Az(`←`)+1+Az(`→`)+1,i=Nz(e,t,n);return(i.length>1?Nz(e,t,n+r):i).map(e=>[{label:``,indices:e}])}function Fz(e,t){let n=[];for(let t of e)n.length>0&&n.push(new q(` `)),n.push(t);let r=q.fromFragments(n);return r.overflow=t?`ignore`:void 0,r.end=``,r}function Iz(e,t,n,r,i){let a=e.compiled.get(t);if(!a||a.kind!==n)throw Error(`${i} references action "${t}" which must be ${r}, got ${a?`a ${a.kind} action`:`no such action`}`);return a}function Lz(e,t,n){let r=e.compiled.get(t),i=r&&$R(r);if(!i||i.kind!==`set-option`&&i.kind!==`persist-option`&&i.kind!==`layout-op-option`)throw Error(`${n} references action "${t}" which must be a set-option, persist-option, or layout-op-option action ({ set, from }, { persist, from }, or { persist, insertSegmentFrom, anchor, relation }), got ${i?`a ${i.kind} action`:`no such action`}`);return i}function Rz(e,t,n,r,i,a,o,s,c=[]){let l=a.compiled.get(e),u=a.store,d=nz(u,`session.id`),f=`stateVar`in t?nz(u,t.stateVar):void 0,p=(e,n)=>{let r=t.options[e];return o({index:e,count:t.options.length},r,n,r===f)},m=i?r.kind===`led`?Mz(a):jz(a):1/0,h=(r.kind===`led`?0:Az(`✕`)+1)+c.reduce((e,t)=>e+Az(t.glyph)+1,0),g=t.library&&{groups:t.library.groups,entries:t.options.map(t.library.entry)},_=g===void 0?t.options.map((e,t)=>p(t,e)):[],v=g===void 0?Pz(_.map(e=>e.cellLength),m,h):wz(g.entries,g.groups,i),y=parseInt(nz(u,n.stateVar),10),b=e=>Math.max(0,v.findIndex(t=>t.some(t=>t.indices.includes(e)))),x=b(f===void 0?-1:t.options.indexOf(f)),S=Number.isInteger(y)?y<0?x:Math.min(y,v.length-1):0,C=v[S]??[],ee=e=>I([{verb:gn,args:[d,n.key,String(e)]}]),te=r.kind===`led`?[]:[{verb:gn,args:[d,...r.writes.flatMap(([e,t])=>[e,t])]}],ne=r.kind===`own`&&r.onPick?te:[],re=e=>I([...sz(l,e,e,u,d).effects,...ne]),ie=(e,n)=>az(e,re(t.options[n])),ae=r.kind===`led`?[]:[iz(`✕`,I(te),!1,s)];ae.push(...c.map(({glyph:e,option:r})=>iz(e,I([...sz(l,r,r,u,d).effects,{verb:gn,args:[d,n.key,String(b(t.options.indexOf(r)))]}]),!1))),S>0&&ae.push(iz(`←`,ee(S-1),!1));let w=S<v.length-1?[iz(`→`,ee(S+1),!1)]:[];if(g===void 0){let e=C.flatMap(e=>e.indices);return[Fz([...ae,...e.map(e=>ie(_[e],e)),...w],i)]}let T=new G({bold:!0}),oe=v.length>1?` ${S+1}/${v.length}`:``,se=C.length===1?[new q(`${C[0].label}${oe}`,{style:T})]:[],ce=[Fz([...ae,...se,...w],i)];for(let e of C){C.length>1&&ce.push(Fz([new q(e.label,{style:T})],i));let n=Math.max(...e.indices.map(e=>Az(t.options[e])));for(let r of e.indices){let e=t.options[r],a=g.entries[r].description,o=a===void 0?void 0:Hd(a),s=` `.repeat(n-Az(e)+2),c=o===void 0?e:`${e}${s}${o}`;ce.push(Fz([ie(p(r,Ez(c,m)),r)],i))}}return ce}function zz(e,t){return{picker:{fn:(n,r,i,a,o,...s)=>{vC(`picker "${n}"`,[`closeOnPick`,`paged`,`inBody`],s);let c=Iz(e,r,`set-int`,`an int action ({ set, int: true })`,`picker`);if(o===!0&&i===!0)throw Error(`{{ picker "${n}" … }} sets both closeOnPick and inBody; a picker in a body is closed by the body's ✕, so it has no close to fold into a pick`);let l=Lz(e,n,`picker`);if(l.library!==void 0)throw Error(`{{ picker "${n}" … }} ranges a catalogue domain, which lays out as one row per member; a catalogue renders in a {{ menu }} body`);let u=kz(t,`{{ picker }}`);if(u.bg===void 0)throw Error(`{{ picker }} is not available while segments.${u.segName}'s own "bg:" is being evaluated — a picker is drawn on that background`);let[d]=Rz(n,l,{key:c.key,stateVar:c.stateVar},o===!0?{kind:`led`}:{kind:`own`,writes:[[c.key,`-1`]],onPick:i===!0},a===!0,e,bz(u,ff(void 0),XR(e,`{{ picker }}`),l.paletteOf,t.drawnAt(),u.bg),mz(u.palette,u.bg,t.drawnAt()));return d},argTypes:[`string`,`string`,`bool`],arity:{kind:`variadic`},returnType:`T`}}}function Bz(e,t){let n=e.length,r=Math.max(e.indexOf(t),0);return e=>((r+e)%n+n)%n}function Vz(e,t,n,r,i){let a=Math.min(Math.floor((t-1)/2),i),o=n,s=0;for(;s<a;){let t=o+e(-(s+1))+1+e(s+1)+1;if(t>r)break;o=t,s+=1}return s}function Hz(e,t,n,r,i,a){if(!(`stateVar`in t))throw Error(`carousel references action "${e}", which inserts a segment and holds no current value to centre on — a carousel needs a { set, from } or { persist, from } action`);let o=n.store;if(!o.has(t.stateVar))throw Error(`carousel references action "${e}", whose key "${t.stateVar}" no variable reads back, so there is no current value to centre on — declare { kind: "state", key: "${t.stateVar}" } among the variables`);let s=n.compiled.get(e),c=nz(o,`session.id`),{options:l}=t,u=l.length;if(u===0)return Fz([],!0);let d=nz(o,t.stateVar),f=Bz(l,d),p=e=>l[f(e)],m=new Map,h=e=>{let t=m.get(e);if(t!==void 0)return t;let n=I(sz(s,p(e),p(e),o,c).effects);return m.set(e,n),n},g=e=>r({index:f(e),count:u},p(e),p(e),p(e)===d),_=new Map,v=e=>{let t=_.get(e);if(t!==void 0)return t;let n=az(g(e),h(e));return _.set(e,n),n},y=a===void 0?v(0):az(Sz(XR(n,`{{ carousel }}`),t.paletteOf)({index:f(0),count:u},p(0),p(0),!1),I(sz(n.compiled.get(a),p(0),void 0,o,c).effects)),b=Vz(e=>v(e).cellLength,u,Az(`◀`)+1+y.cellLength+1+Az(`▶`),Mz(n),i),x=e=>Array.from({length:b},(t,n)=>v(e*(n+1)));return Fz([...x(-1).reverse(),iz(`◀`,h(-1),!1),y,iz(`▶`,h(1),!1),...x(1)],!0)}function Uz(e,t){return{carousel:{fn:(n,...r)=>{let[i,a,...o]=r;if(vC(`carousel "${n}"`,[`neighbours`,`centre`],o),i!==void 0&&!(Number.isInteger(i)&&i>=0))throw Error(`carousel "${n}": neighbours must be a whole number ≥ 0 (0 shows only ◀ CURRENT ▶), got ${String(i)}`);if(a!==void 0&&!(typeof a==`string`&&e.compiled.has(a)))throw Error(`carousel "${n}": centre must name a declared action, got ${JSON.stringify(a)}`);if(a!==void 0&&ez(e.compiled.get(a)))throw Error(`carousel "${n}": centre "${a}" writes a value the template binds, and the centre binds none — name an action that writes a fixed value, a cycle, or a do of them`);let s=i??1/0,c=Lz(e,n,`carousel`),l=kz(t,`{{ carousel }}`);if(l.bg===void 0)throw Error(`{{ carousel }} is not available while segments.${l.segName}'s own "bg:" is being evaluated — a carousel is drawn on that background`);return Hz(n,c,e,bz(l,ff(void 0),XR(e,`{{ carousel }}`),c.paletteOf,t.drawnAt(),l.bg),s,a)},argTypes:[`string`,`value`],arity:{kind:`variadic`},returnType:`T`}}}function Wz(e,t,n){let r=Lz(e,t,n);if(!(`stateVar`in r))throw Error(`${n} references action "${t}", which inserts a segment and holds no current value — a ${n} needs a { set, from } or { persist, from } action`);if(r.paletteOf===void 0)throw Error(`${n} references action "${t}", whose options are not colour-valued — a swatch draws the palette an option puts in force, as the "themes", "placementThemes" and "styles" domains do`);return r}function Gz(e,t,n){let r=Math.imul(e^e>>>16,73244475);return r=Math.imul(r^r>>>16,73244475),r^=r>>>16,(n+1+(r>>>0)%Math.max(t-1,1))%t}function Kz(e,t,n,r){let i=Wz(e,t,n),a=r??nz(e.store,i.stateVar);if(!i.options.includes(a))throw Error(`${n} "${t}": "${a}" is not one of its options, so it has no palette to draw`);return i.paletteOf(a,XR(e,`{{ ${n} }}`))}function qz(e,t,n){return{swatch:{fn:(t,...n)=>{let[r,...i]=n;if(vC(`swatch "${t}"`,[`option`],i),r!==void 0&&typeof r!=`string`)throw Error(`swatch "${t}": option must be text, got ${JSON.stringify(r)}`);return _z(Kz(e,t,`swatch`,r))},argTypes:[`string`,`value`],arity:{kind:`variadic`},returnType:`T`},swatches:{fn:(r,i)=>{let a=Wz(e,r,`swatches`),o=Iz(e,i,`set-int`,`an int action ({ set, int: true })`,`swatches`),s=kz(t,`{{ swatches }}`);if(s.bg===void 0)throw Error(`{{ swatches }} is not available while segments.${s.segName}'s own "bg:" is being evaluated — a swatch row is drawn on that background`);let c=t.drawnAt(),{options:l}=a,u=l.length,[d]=Rz(r,a,{key:o.key,stateVar:o.stateVar},{kind:`led`},!0,e,Cz(s,XR(e,`{{ swatches }}`),a.paletteOf,c,s.bg),mz(s.palette,s.bg,c),u===0?[]:(()=>{let t=Bz(l,nz(e.store,a.stateVar));return[{glyph:`◀`,option:l[t(-1)]},{glyph:`?`,option:l[Gz(n().getTime(),u,t(0))]},{glyph:`▶`,option:l[t(1)]}]})());return d},argTypes:[`string`,`string`],arity:{kind:`exact`},returnType:`T`}}}const Jz=[`~/code`,`main`,`opus`,`42%`,`5m`,`$1.20`];function Yz(e,t,n,r){let i=Kf(e,n,r),a=(t,n)=>({text:t,colour:n,ink:Pf(e,n,r)});return[[sf(t).map((n,i)=>{let a=Tf(e,n);return{text:Jz[i%Jz.length],colour:a,ink:t.shade.text(e,n.hue,a,r)}})],[[a(`▾ open`,i.state),a(`menu`,i.plane)],[a(`warn`,wf(e,`warning`)),a(`error`,wf(e,`error`))]]]}function Xz(e,t){let n=e.flatMap((e,t)=>e.map(({text:e,colour:n,ink:r},i)=>({gap:t>0&&i===0?` `:``,cell:new q(` ${e} `,{style:pz({tint:n,text:r})})}))),r=[],i=0;for(let{gap:e,cell:a}of n){if(i+=e.length+a.cellLength,i>t)break;e!==``&&r.push(new q(e)),r.push(a)}return r}function Zz(e,t,n,r,i){let a=Yz(e,t,n,r).map(e=>Xz(e,i)),o=q.fromFragments(a.flatMap((e,t)=>t===0?e:[new q(`
199
- `),...e]));return o.overflow=`ignore`,o.end=``,o}function Qz(e,t){return{themePreview:{fn:(...n)=>{let[r,...i]=n;if(vC(`themePreview`,[`applyAction`],i),r!==void 0&&typeof r!=`string`)throw Error(`themePreview: applyAction must name a declared action, got ${JSON.stringify(r)}`);let{palette:a,decor:o}=XR(e,`{{ themePreview }}`);return Zz(r===void 0?a:Kz(e,r,`themePreview`),o,{...kz(t,`{{ themePreview }}`).disclosure,depth:0},t.drawnAt(),Mz(e))},argTypes:[`value`],arity:{kind:`variadic`},returnType:`T`}}}const $z=e=>e.slice(e.lastIndexOf(`.`)+1),eB=(e,t)=>{let n=new q($z(e));return n.truncate(t,{marker:`…`}),n.plain};function tB(e,t){let n=e.map(e=>e.map(({name:e})=>Az($z(e)))),r=e=>n.every(n=>n.reduce((t,n)=>t+Math.min(n,e)+2,0)<=t),i=Math.max(1,...n.flat());for(;i>1&&!r(i);)--i;return i}function nB(e,t,n,r){let i=tB(e,r),a=e.map(e=>{let a=[],o=0;for(let{name:s,address:c,palette:l}of e){let e=new q(` ${eB(s,i)} `,{style:pz(ap(l,{kind:`bar`,decor:t,address:c},n))});if(o+=e.cellLength,o>r)break;a.push(e)}return a}),o=q.fromFragments(a.flatMap((e,t)=>t===0?e:[new q(`
200
- `),...e]));return o.overflow=`ignore`,o.end=``,o}function rB(e,t){return{layoutPreview:{fn:()=>nB(e.layout(),XR(e,`{{ layoutPreview }}`).decor,t.drawnAt(),Mz(e)),argTypes:[],arity:{kind:`exact`},returnType:`T`}}}function iB(e,t,n,r){let i=kz(r.activeSegment,`{{ menu }}`),a=r.action,o=sT(i.placementId,e,n.key),s=uT(o),c=oT(e),l=nz(a.store,o)===c,u=nz(a.store,`session.id`),d=l?L:c,f=iz(qn(`{{ menu "${e}" }}`,t,2,+!!l),I([{verb:gn,args:[u,o,d,s,`0`]}]),!1);return i.drops.push(...l?(()=>{let t=r.activeSegment.drawnAt(),c=Kf(i.palette,i.disclosure,t).plane,l=Lz(a,e,`menu`);return Rz(e,l,{key:s,stateVar:s},{kind:`own`,writes:[[o,L],[s,`0`]],onPick:n.closeOnPick},n.paged,a,bz(i,n.distribution,XR(a,`{{ menu }}`),l.paletteOf,t,c),mz(i.palette,c,t))})():[]),f}const aB=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function oB(e,t){let n=t[t.length-1],r=aB(n)?n:void 0,i=r===void 0?t:t.slice(0,-1),a=i.findIndex(e=>typeof e!=`string`);if(a!==-1)throw Error(`{{ menu "${e}" }} display #${a+1} is not text (${JSON.stringify(i[a])}) — a menu binds its trigger text, then an optional trailing (dict …) of options`);return{displays:i,options:mT(r??{})}}function sB(e){return{menu:{fn:(t,...n)=>{let{displays:r,options:i}=oB(t,n);return iB(t,r,i,e)},argTypes:[`string`,`value`],arity:{kind:`variadic`},returnType:`T`}}}function cB(e){let{value:t,max:n,width:r,filled:i,empty:a,colourAt:o}=e,s=lB(t,n,r),c=[];for(let e=0;e<r;e++){let t=e<s,l=t&&o!==void 0?o(e*n/r):void 0;c.push(new q(t?i:a,{style:l===void 0?void 0:new G({color:l})}))}let l=q.fromFragments(c);return l.end=``,l.overflow=`ignore`,l}function lB(e,t,n){return!Number.isFinite(e)||!Number.isFinite(t)||t<=0?0:Math.min(n,Math.max(0,Math.round(e/t*n)))}function uB(e){let t={fn:(()=>{let t=kz(e,`{{ bgOf }}`);if(t.bg===void 0)throw Error(`{{ bgOf }} is not available while segments.${t.segName}'s own "bg:" is being evaluated — the background is what that template computes. Reach for a palette color there instead, e.g. bg: '{{ darken (color "surface") 1 }}'.`);return t.bg.hex}),argTypes:[],arity:{kind:`exact`},returnType:`string`},n={fn:(()=>kz(e,`{{ tint }}`).tint.hex),argTypes:[],arity:{kind:`exact`},returnType:`string`},r={fn:((t,n)=>{let{palette:r}=kz(e,`{{ keptOn }}`),i=Us(r,t),a=Us(r,n),o=Fo(ec(i,U.TRUECOLOR),ec(a,U.TRUECOLOR)),s=Math.min(Nf,Math.max(o,3));return($s(i,e.drawnAt(),(e,t)=>Fo(e,t(a))>=s)??i).hex}),argTypes:[`string`,`string`],arity:{kind:`exact`},returnType:`string`},i=iC(()=>kz(e,`{{ color }} / {{ ramp }} / {{ gauge }}`).palette),a={fn:((e,t,n,r,a,o,...s)=>{let c=o===void 0?void 0:[o,...dB(s)];return cB({value:e,max:t,width:n,filled:r,empty:a,colourAt:c===void 0?void 0:e=>String(i.ramp.fn(e,...c))})}),argTypes:[`float`,`float`,`int`,`string`,`string`,`string`],arity:{kind:`variadic`},returnType:`T`};return{...i,bgOf:t,tint:n,keptOn:r,gauge:a}}function dB(e){return e.flatMap(e=>{let t=e.indexOf(`:`),n=t<0?NaN:Number(e.slice(0,t));if(!Number.isFinite(n))throw Error(`{{ gauge }} stop "${e}" must be "<position>:<colour>", e.g. "80:error" or "80:#ff0000"`);return[n,e.slice(t+1)]})}function fB(e){let t=[],n=[];for(let r of e){if(!r.contains(`
193
+ `,l.join(e,`lib`),t.sessionId,t.cwd],env:ZF(t),timeoutMs:3e3,category:`memento.read`});return n.ok?$F(n.stdout):B(QF(n))}function tI(e,t,n){let r=Me({bin:l.join(e,qF),args:n.kind===`set`?[`set`,`session`,n.to]:[`clear`,`session`],env:ZF(t),timeoutMs:5e3,category:`memento.move`});if(!r.ok)throw Error(QF(r))}function nI(){return{locate:e=>XF(ii(e.claudeConfigDir),e.projectDir),read:eI,move:tI}}function rI(e,t,n){let r=n===void 0?``:`CLAUDE_CONFIG_DIR=${ar(n)} `,i=e.added_dirs.map(e=>` --add-dir ${ar(e)}`).join(``);return`cd ${ar(e.project_dir)} && ${r}claude --resume ${ar(t)}${i}`}function iI(e,t,n){let r=Jh(t(`preset`),e.globals.preset,e.presets),i=Zh(e,r),a=t(`edit.mode`)===`arrange`?e.editGlobals:{},o=rh(a.palette,t(`theme`),i.palette),s=AF(i,kF(o,e.themeDefaults));return{preset:r,presetCustomized:n(r),theme:o,style:Sp(a.style,t(`style`),s.style,e.styles),effect:Ap(a.effect,t(`effect`),s.effect),endcaps:Fp(a.endcaps,t(`endcaps`),s.endcaps),variation:Up(a.variation,t(`variation`),s.variation),shade:Kp(a.shade,t(`shade`),s.shade),separator:a.default_separator??s.default_separator,autoWrap:em(a.autoWrap,t(`autoWrap`),s.autoWrap),padding:rm(a.padding,t(`padding`),s.padding),charset:a.charset??s.charset??`unicode`,updateNotice:tm(a.updateNotice,t(`updateNotice`),s.updateNotice),transitions:nm(a.transitions,t(`transitions`),s.transitions),colorCompatibility:a.colorCompatibility??s.colorCompatibility??`truecolor`}}function aI(e,t){return{endcaps:e.endcaps,separator:e.separator,colorCompatibility:e.colorCompatibility,wrap:e.autoWrap,padding:e.padding,charset:e.charset,width:t}}function oI(e){return{theme:e.theme,style:e.style,effect:e.effect,preset:e.preset,variation:e.variation,shade:e.shade,transitions:e.transitions}}function sI(e){return{preset:{effective:e.preset,customized:e.presetCustomized,bundled:DF(e.preset)},endcaps:{effective:e.endcaps},variation:{effective:e.variation},shade:{effective:e.shade},charset:{effective:e.charset},colorCompatibility:{effective:e.colorCompatibility},autoWrap:{effective:e.autoWrap},padding:{effective:e.padding},updateNotice:{effective:e.updateNotice},transitions:{effective:e.transitions}}}const cI={prNumber:!0,prState:!0,prUrl:!0,prError:!0,prEarlier:!0};function lI(e){return e?.prState===void 0?e?.prError===void 0?e?.prEarlier===void 0?`-`:`earlier-${e.prEarlier}`:`failed`:e.prState}const uI=10*1e3;function dI(e,t,n,r){let i=n-(t*1e3-r);if(i<3e5||e<=0)return;let a=e/i,o=(100-e)/a;return Math.max(0,Math.round(o/6e4))}function fI(e,t){if(!(t<60))return e*3600/t}function pI(e,t,n,r){let i=r-t;if(i<50||i>uI)return;let a=n-e;if(!(a<=0))return a*1e3/i}function mI(e){let{prev:t,cur:n}=e;if(t===void 0)return;let r=pI(t.input,t.atMs,n.input,n.atMs),i=pI(t.output,t.atMs,n.output,n.atMs),a=pI(t.total,t.atMs,n.total,n.atMs);if(!(r===void 0&&i===void 0&&a===void 0))return{...r!==void 0&&{input:r},...i!==void 0&&{output:i},...a!==void 0&&{total:a}}}function hI(e){let{samples:t}=e,n=[];for(let e=1;e<t.length;e++){let r=t[e-1],i=t[e],a=i.atMs-r.atMs;if(a<50||a>uI)continue;let o=pI(r.total,r.atMs,i.total,i.atMs);n.push(o??0)}if(n.length!==0)return n.join(`,`)}function gI(e){let t=e.indexOf(`.`);return t<0?e:e.slice(0,t)}function _I(e){let t=[],n=(e,n)=>{try{let e=n();return e===``?void 0:e}catch(n){t.push(`host.${e}: ${String(n)}`);return}},r=n(`name`,()=>gI(h.hostname())),i=n(`user`,()=>h.userInfo().username);return{host:{...r!==void 0&&{name:r},...i!==void 0&&{user:i},...e.ssh!==void 0&&{ssh:e.ssh}},failures:t}}function vI(e,t){let n=new Map;for(let[t,r]of Object.entries(e.variables))n.set(t,r);for(let[t,r]of Object.entries(e.segments))if(r.vars)for(let[e,i]of Object.entries(r.vars))n.set(`${t}.${e}`,i);let r=[],i=new Set,a=t=>vg(t,e.helpers).keys(),o=Zh(e,t);for(let e of hp){let t=o[e];if(gp(t))for(let e of a(t))r.push(e)}for(let n of dh(Xh(e,t).node)){if(n.when)for(let e of a(n.when))r.push(e);if(n.kind!==`segment`)continue;let t=e.segments[n.name];if(t){for(let e of[t.template,t.when,t.bg,t.fg])if(e)for(let t of a(e))r.push(t)}}let s=new Set;for(;r.length>0;){let e=r.pop();for(let t of bI(n,e)){if(i.has(t))continue;i.add(t);let e=n.get(t);if(e){if(e.kind===`input`)s.add(e.path);else if(e.kind===`template`)for(let t of a(e.template))r.push(t)}}}return s}function yI(e){let t=new Map;return n=>{let r=t.get(n);if(r!==void 0)return r;let i=vI(e,n);return t.set(n,i),i}}function bI(e,t){let n=t;for(;n.length>0;){if(e.has(n))return[n];let t=n.lastIndexOf(`.`);if(t<0)break;n=n.slice(0,t)}let r=`${t}.`,i=[];for(let t of e.keys())t.startsWith(r)&&i.push(t);return i}function xI(e,t){for(let n of e)if(n===t||n.startsWith(t+`.`))return!0;return!1}function SI(e){let t=t=>e.has(t),n=t(`git.staged`)||t(`git.unstaged`)||t(`git.untracked`)||t(`git.conflicts`);return{...t(`git.sha`)&&{showSha:!0},...n&&{showWorkingTree:!0},...t(`git.stash`)&&{showStashCount:!0},...(t(`git.upstream`)||t(`git.tracking`))&&{showUpstream:!0},...t(`git.repoName`)&&{showRepoName:!0},...t(`git.repoUrl`)&&{showRepoUrl:!0},...t(`git.operation`)&&{showOperation:!0},...t(`git.timeSinceCommit`)&&{showTimeSinceCommit:!0},...Object.keys(cI).some(e=>t(`git.${e}`))&&{showPullRequest:!0}}}async function CI(e,t,n,r,i,a,o,{configPath:s,...c}){let l=e=>xI(i,e),u=yw(t).getTime(),d=o.tmux??null,f=(e,t,n)=>t?n().catch(t=>B(`${e}: ${String(t)}`)):Promise.resolve(z),[p,m,h,g,_,v,y,b,x,S,C]=await Promise.all([f(`git`,l(`git`),()=>n.gitProvider.getGitInfo(r??e.workspace?.current_dir,SI(i),e.workspace?.project_dir)),f(`session`,l(`session.cost`)||l(`session.tokens`)||l(`burn`),()=>n.usageStore.getUsageInfo(e.session_id,e)),f(`today`,l(`today`),()=>n.usageStore.getTodayInfo(e,o.claudeConfigDir,t)),f(`context`,l(`context`)||l(`autocompact`),()=>n.contextProvider.getContextInfo(e)),f(`metrics`,l(`metrics`)||l(`burn`),()=>n.metricsProvider.getMetricsInfo(e.session_id,e)),f(`activity`,l(`activity`),()=>n.activityProvider.getActivityInfo(e.session_id,e)),f(`tmux`,l(`tmux.session`),()=>d===null?Promise.resolve(z):n.tmuxService.getSessionName(d)),f(`cache`,l(`cache`),()=>HF(e.transcript_path)),f(`speed`,l(`speed`),()=>n.usageStore.observeSpeed(e.session_id,e.transcript_path,u)),f(`memento`,l(`memento`),()=>n.mementoProvider.getCeiling(GF({sessionId:e.session_id,projectDir:e.workspace?.project_dir??``,cwd:r??e.workspace?.current_dir??``},o))),f(`autocompact`,l(`autocompact`),()=>Promise.resolve(n.autoCompact(ri(ni(o.claudeConfigDir)))))]),ee=[],te=e=>{if(e.kind===`failed`){ee.push(e.reason);return}return e.kind===`ok`?e.value:void 0},ne=jI(p,u);ee.push(...ne.failures);let re=_I(o);ee.push(...re.failures);let ie=te(m),ae=te(h),w=te(g),T=te(_),oe=te(v),se=te(y),ce=te(b),le=EI(S);S.kind===`failed`&&ee.push(`memento: ${S.reason}`);let ue=wI(C,w?.maxTokens);C.kind===`failed`&&ee.push(`autocompact: ${C.reason}`);for(let e of ee)n.log(`warn`,`provider fetch failed: ${e}`);let E=e.rate_limits?.five_hour,de=e.rate_limits?.seven_day,fe=E?dI(E.used_percentage,E.resets_at,18e6,u):void 0,pe=de?dI(de.used_percentage,de.resets_at,6048e5,u):void 0,me=ie?.session.cost,he=T?.sessionDuration,ge=l(`burn`)&&me!=null&&he!=null?fI(me,he):void 0,_e=te(x),ve=_e===void 0?void 0:mI(_e),ye=_e===void 0?void 0:hI(_e),be=ve!==void 0||ye!==void 0?{...ve,...ye!==void 0&&{history:ye}}:void 0,xe=AI(process.env.HOME??process.env.USERPROFILE),D=e.workspace?{...e.workspace,current_dir:AI(e.workspace.current_dir)??``,project_dir:AI(e.workspace.project_dir)??``,added_dirs:(e.workspace.added_dirs??[]).map(e=>AI(e)??e)}:e.workspace,Se=ie===void 0?void 0:kI({cost:ie.session.cost,tokens:ie.session.tokens}),Ce=ae===void 0?void 0:{cost:ae.cost,tokens:ae.tokens},we=T===void 0?void 0:kI({lastResponseTime:T.lastResponseTime,responseTime:T.responseTime,sessionDuration:T.sessionDuration,messageCount:T.messageCount,nonPrompts:T.nonPrompts,linesAdded:T.linesAdded,linesRemoved:T.linesRemoved}),Te=oe===void 0?void 0:DI(oe);return{...e,...D!==void 0&&{workspace:D},...xe!==void 0&&{home:xe},...ne.git!==void 0&&{git:ne.git},...d!==null&&{tmux:{pane:d.pane,...se!==void 0&&{session:se}}},host:re.host,...sI(a),history:n.history(e.session_id),navigation:{back:n.navigation(e.session_id)},...c,...s!==null&&{configPath:s},resumeCommand:rI(D,e.session_id,o.claudeConfigDir),...Se!==void 0&&{session:Se},...Ce!==void 0&&{today:Ce},...ge!==void 0&&{burn:{costPerHour:ge}},...be!==void 0&&{speed:be},...l(`block`)&&E!==void 0&&{block:{nativeUtilization:E.used_percentage,resetsAt:E.resets_at,...fe!==void 0&&{etaMinutes:fe}}},...de!==void 0&&{weekly:{percentage:de.used_percentage,resetsAt:de.resets_at,...pe!==void 0&&{etaMinutes:pe}}},...ce!==void 0&&{cache:{expiresAt:ce}},...w!==void 0&&{context:{totalTokens:w.totalTokens,contextLeft:w.contextLeftPercentage}},...we!==void 0&&{metrics:we},...Te!==void 0&&{activity:Te},...le!==void 0&&{memento:le},...ue!==void 0&&{autocompact:ue}}}function wI(e,t){switch(e.kind){case`absent`:return;case`failed`:return{error:e.reason};case`ok`:return nO(e.value,t)}}const TI=e=>e.trim().split(`
194
+ `).at(-1).trim();function EI(e){switch(e.kind){case`absent`:return;case`failed`:return{error:TI(e.reason)};case`ok`:{let{ceiling:t,session:n}=e.value;return{ceiling:t===`off`?0:t,off:t===`off`,session:n??``}}}}function DI(e){let t=e.todos.findIndex(e=>e.active),n=e.todos.length===0?void 0:{total:e.todos.length,completed:e.todos.filter(e=>e.done).length,...t>=0&&{position:t+1,active:e.todos[t].text}},r=OI(e.running),i=OI(e.done),a=r===void 0&&i===void 0?void 0:{...r!==void 0&&{running:r},...i!==void 0&&{done:i}};if(!(e.command===null&&n===void 0&&a===void 0))return{...e.command!==null&&{command:e.command},...n!==void 0&&{todo:n},...a!==void 0&&{tool:a}}}function OI(e){return e.length===0?void 0:e.map(e=>`${e.name}:${e.count}`).join(`,`)}function kI(e){let t={},n=!1;for(let r of Object.keys(e)){let i=e[r];i!=null&&(t[r]=i,n=!0)}return n?t:void 0}function AI(e){return e===void 0||e.length===0||l.sep!==`\\`?e:e.replace(/\\/g,`/`)}function jI(e,t){if(e.kind===`absent`)return{failures:[]};if(e.kind===`failed`)return{failures:[e.reason]};let n=e.value,r=[],i=(e,t)=>{if(!(t===void 0||t.kind===`absent`)){if(t.kind===`failed`){r.push(`git.${e}: ${t.reason}`);return}return t.value}},a=i(`aheadBehind`,n.aheadBehind),o=i(`sha`,n.sha),s=i(`operation`,n.operation),c=i(`timeSinceCommit`,n.committedAt),l=c===void 0?void 0:Math.floor((t-c)/1e3),u=i(`stash`,n.stashCount),d=i(`upstream`,n.upstream),f=n.upstream===void 0?void 0:i(`tracking`,jC(n.upstream,n.aheadBehind)),p=i(`repoName`,n.repoName),m=i(`repoUrl`,n.repoUrl),h=n.pullRequest===void 0?void 0:MC(n.pullRequest,n.head),g={};switch(h?.kind){case`ok`:g={prNumber:h.value.number,prState:h.value.state,prUrl:h.value.url};break;case`failed`:r.push(`git.pr: ${h.reason}`),g={prError:h.reason};break;case`earlier`:g={prEarlier:h.value.state};break;case`absent`:case void 0:break}return{git:{branch:n.branch,status:n.status,...a!==void 0&&{ahead:a.ahead,behind:a.behind},...n.workingTree!==void 0&&{staged:n.workingTree.staged,unstaged:n.workingTree.unstaged,untracked:n.workingTree.untracked,conflicts:n.workingTree.conflicts},...o!==void 0&&{sha:o},...s!==void 0&&{operation:s},...l!==void 0&&{timeSinceCommit:l},...u!==void 0&&{stash:u},...d!==void 0&&{upstream:d},...f!==void 0&&{tracking:f},...p!==void 0&&{repoName:p},...m!==void 0&&{repoUrl:m},...g},failures:r}}const MI={theme:e=>e.theme.kind===`decided`?e.theme.name:null,preset:e=>e.preset,style:e=>e.style.kind===`decided`?e.style.name:null,effect:e=>e.effect.kind===`decided`?e.effect.name:null,endcaps:e=>e.endcaps,variation:e=>e.variation,shade:e=>e.shade,transitions:e=>e.transitions?qp:Jp,autoWrap:e=>e.autoWrap?qp:Jp,padding:e=>String(e.padding),updateNotice:e=>e.updateNotice?qp:Jp},NI=Object.entries(pa),PI=new Set(ma.map(e=>e.sessionKey)),FI=()=>!1;function II(e,t){return iI(e,e=>PI.has(e)?t(e):null,FI)}const LI=[`preset`,`theme`];function RI(e,t,n){let r=new Set(LI.slice(0,n).map(e=>pa[e].sessionKey));return iI(e,e=>r.has(e)?t(e):null,FI)}function zI(e,t){let n=Array.from({length:LI.length+1},(n,r)=>RI(e,t,r));return e=>{let t=LI.indexOf(e);return n[t===-1?LI.length:t]}}function BI(e,t,n,r){return e.flatMap(([e,i])=>{let a=MI[e](t);return a===null||a===MI[e](n(e))?[]:[{...i,value:a,target:r(i)}]})}function VI(e,t,n){return MI[n](II(e,t))}function HI(e,t){let n=II(e,t);return BI(NI,n,zI(e,t),t=>UI(e,n.preset,t.configKey))}function UI(e,t,n){return n in(Yh(e.presets,t).globals??{})?HE(t,n):n}function WI(e,t,n){let r=Jh(t(pa.preset.sessionKey),e.globals.preset,e.presets),i=UE(n);return{key:i?.scope===`globals`?UI(e,r,i.field):n,globals:Zh(e,r)}}function GI(e,t){let{preset:n}=II(e,t);return JI(e,n).flatMap(({id:e,setting:r,key:i,decl:a,saved:o})=>{let s=t(i),c=s===null?void 0:kh(a,s);return c===void 0||Oh(c)===Oh(o)?[]:[{preset:n,id:e,setting:r,key:i,value:c}]})}function KI(e,t,n){let r=new Map(n.map(e=>[e.key,e.value]));return qh(e.presets).flatMap(n=>{let i=JI(e,n);return[...new Set(i.filter(e=>r.has(e.key)).map(e=>e.id))].flatMap(e=>{let n=i.filter(t=>t.id===e);return Eh(Object.fromEntries(n.map(e=>[e.setting,e.decl])),Object.fromEntries(n.map(e=>{let n=r.get(e.key)??t(e.key),i=n===null?void 0:kh(e.decl,n);return[e.setting,i??e.saved]}))).map(({message:t})=>`placement "${e}": ${t}`)})})}const qI=new WeakMap;function JI(e,t){let n=qI.get(e)??new Map;qI.set(e,n);let r=n.get(t);if(r!==void 0)return r;let i=[...dh(Xh(e,t).node)].flatMap(t=>t.kind!==`segment`||t.drafts===void 0?[]:Object.entries(t.drafts).map(([n,{id:r,key:i}])=>{let a=wh(e.segments[t.name])[n];return{id:r,setting:n,key:i,decl:a,saved:t.settings?.[n]??a.default}})),a=[...new Map(i.map(e=>[e.key,e])).values()];return n.set(t,a),a}function YI(e,t){let n=II(e,t);return{from:n.preset,globals:Yh(e.presets,n.preset).globals??{},picks:BI(NI.filter(([e])=>e!==`preset`),n,zI(e,t),e=>e.configKey),placements:GI(e,t)}}function XI(e,t){return iI({...e,globals:{palette:t},presets:{}},()=>null,FI)}function ZI(e,t){let n=II(e,t),r=MI.theme(n);if(r===null)return{kind:`rule`};let i=XI(e,r),a=Zh(e,n.preset),o=Object.fromEntries(gh.map(e=>[e,MI[e](a[e]===void 0?n:i)]));return{kind:`look`,theme:r,look:o,differs:gh.some(e=>o[e]!==MI[e](i))}}function QI(e){return{sessionKeys:ma.filter(t=>t.configKey===e).map(e=>e.sessionKey),fileKeys:[e,...xE(e)?EF.map(t=>HE(t,e)):[],...VE(e)?up().map(t=>BE(t,e)):[]]}}function $I(e){return new Set(ma.map(e=>e.configKey).filter(t=>QI(t).fileKeys.some(t=>nL(e,tL(t)))))}function eL(e,t,n){let r=HI(e,n),i=new Set(r.map(e=>e.configKey)),a=ya(e=>i.has(pa[e].configKey)||t.has(pa[e].configKey)),o=ZI(e,n);return{unsaved:r.length+GI(e,n).length,resettable:a,themeDefault:o.kind===`look`&&o.differs?{differs:!0,theme:o.theme}:{differs:!1}}}function tL(e){let t=UE(e);if(t===null||t.scope===`preset-root`)throw Error(`reset layer "${e}" is not a value path`);return WE(t)}function nL(e,t){let[n,...r]=t;return n===void 0?e!==void 0:typeof e==`object`&&!!e&&nL(e[n],r)}const rL=up(),iL=new Set(rL),aL=new Set(jp),oL=e=>e?iL.has(e)?{ok:!0,value:e}:{ok:!1,reason:`unknown theme "${e}" (have: ${rL.join(`, `)})`}:{ok:!1,reason:`theme name is required`},sL=e=>e?aL.has(e)?{ok:!0,value:e}:{ok:!1,reason:`unknown endcaps "${e}" (have: ${jp.join(`, `)})`}:{ok:!1,reason:`endcaps name is required`},cL=new Set([`1`,`true`]),lL=new Set([`0`,`false`]),uL={endcaps:sL,theme:oL,"toolbar-expanded":e=>cL.has(e)?{ok:!0,value:`1`}:lL.has(e)?{ok:!0,value:``}:{ok:!1,reason:`expected boolean-ish (1, 0, true, false), got "${e}"`}},dL=AA(uL,`state`,vL);function fL(e,t){return dL.register(e,t)}function pL(e){return dL.gateFor(e)}function mL(e,t){return`set`in e?`to`in e?[{key:e.set,spec:{kind:`allow-list`,allowed:[e.to]}}]:`from`in e?[{key:e.set,spec:{kind:`allow-list`,allowed:rg(e.from,t).members}}]:`int`in e?[{key:e.set,spec:{kind:`int`}}]:`cycle`in e?[{key:e.set,spec:{kind:`allow-list`,allowed:e.cycle}}]:[{key:e.set,spec:{kind:`range`,min:e.min,max:e.max}}]:[]}function hL(e){return e.filter(e=>e.spec.kind!==`allow-list`||!Object.hasOwn(uL,e.key))}function gL(e,t,n){let r=ba.get(n);if(r!==void 0)return VI(e,t,r);let i=Object.values(e.variables).find(e=>e.kind===`state`&&e.key===n);return i?.kind===`state`?i.default??null:null}function _L(e){let t=$k(e);return hL(Object.values(e.actions).flatMap(e=>mL(e,t)))}function vL(e){return OA(_L(e))}const yL=`update.dismissed`,bL=`updateNotice`,xL=pa.updateNotice.sessionKey;function SL(e){return e.kind===`source`?e.newer.digest:fi(e.newer)}const CL=e=>`${e.version} [${Wm(e.digest)}]`;function wL(e){switch(e.kind){case`source`:return{headline:`Newer source`,newer:CL(e.newer),running:CL(e.running),act:`rebuild`,busy:`rebuilding…`,command:{bin:`pnpm`,args:[`build`],cwd:e.root}};case`release`:return{headline:`Newer release`,newer:fi(e.newer),running:fi(e.running),act:`upgrade`,busy:`upgrading…`,command:{bin:`pnpm`,args:[`dlx`,`${mi}@${fi(e.newer)}`,`install`]}}}}const TL={kind:`idle`},EL={kind:`running`};function DL(e,t,n){if(e===null)return[];let r=SL(e);if(!n.enabled||n.dismissed===r)return[];let i=wL(e),a=`${i.headline}: ${i.newer}. You're on ${i.running}.`,o=t.kind===`failed`&&t.identity===r?[`${i.act} failed: ${t.reason}`]:[],s=[a,...o].join(`
195
+ `),c=I([{verb:xn,args:[s]}]),l=t.kind===`running`?Mm(`[${i.busy}]`,c):Mm(`[${i.act}]`,I([{verb:Nn,args:[n.sessionId]}]));return[{severity:jm,message:s,lines:[[Mm(a,c),l,Mm(`[dismiss]`,I([{verb:gn,args:[n.sessionId,yL,r]}])),Mm(`[disable]`,I([{verb:Sn,args:[n.sessionId,bL,`false`]},{verb:gn,args:[n.sessionId,xL,`false`]}]))],...o.map(e=>[Mm(e,c)])]}]}function OL(e,t){return e.kind===`stale`?{kind:`source`,root:e.root,newer:e.source,running:e.running}:e.kind===`not-source-checkout`&&t!==null&&t.kind===`stale`?{kind:`release`,newer:t.latest,running:t.installed}:null}function kL(e){switch(e.kind){case`current`:return[`info`,`build: current ${CL(e.stamp)}`];case`stale`:return[`info`,`build: stale — source ${CL(e.source)}, running ${CL(e.running)}`];case`not-source-checkout`:return[`info`,`build: not a source checkout`];case`unchecked`:return[`warn`,`build: unchecked: ${e.reason}`]}}function AL(e){switch(e.kind){case`current`:return[`info`,`release: current ${fi(e.installed)}`];case`stale`:return[`info`,`release: stale — latest ${fi(e.latest)}, running ${fi(e.installed)}`];case`ahead`:return[`info`,`release: ahead — running ${fi(e.installed)}, latest ${fi(e.latest)}`];case`unchecked`:return[`warn`,`release: unchecked: ${e.reason}`]}}function jL(e){let t=null;return([n,r])=>{r!==t&&(t=r,e(n,r))}}const ML=e=>e.split(/\r?\n/).map(e=>e.trim()).filter(e=>e!==``).at(-1);function NL(e){let t=e.exitCode===null?``:` (exit ${e.exitCode})`,n=ML(e.stderr)??e.error??ML(e.stdout)??`no output`;return`${e.reason}${t}: ${n}`}function PL(){let e=[MA(bL,[`false`]),fL(xL,[`false`]),fL(yL,[])];return()=>e.forEach(e=>e())}function FL(e){let{entryUrl:t,intervalMs:n,releaseIntervalMs:r,registryUrl:i,fetchImpl:a,onApplied:o,log:s}=e,c={kind:`unchecked`,reason:`not sampled yet`},l=null,u=TL,d=null,f=jL(s),p=jL(s),m=()=>OL(c,l);function h(){let e=m(),t=e===null?null:SL(e);(d===null?null:d.identity)!==t&&(d?.dispose(),d=t===null?null:{identity:t,dispose:fL(yL,[t])})}function g(){c=Jm(t,Km),f(kL(c)),h()}async function _(){l=gi(wt,await hi(mi,a,i)),p(AL(l)),h()}return{arm(){PL(),g(),setInterval(g,n).unref(),c.kind===`not-source-checkout`&&(_(),setInterval(()=>void _(),r).unref())},notice:e=>DL(m(),u,e),act(){let e=m();if(e===null)throw new J(`apply-update: nothing newer is known to apply`);let t=wL(e);if(u.kind===`running`)throw new J(`apply-update: already ${t.busy}`);u=EL,s(`info`,`apply-update: ${t.act} — ${t.command.bin} ${t.command.args?.join(` `)??``}`),O({...t.command,category:`update.apply`,timeoutMs:6e5}).then(n=>{if(n.ok){u=TL,s(`info`,`apply-update: ${t.act} succeeded`),g(),o();return}let r=NL(n);u={kind:`failed`,identity:SL(e),reason:r},s(`error`,`apply-update: ${t.act} failed: ${r}`)})}}}var IL=class{static CACHE_DIR=Re();static USAGE_CACHE_DIR=l.join(this.CACHE_DIR,`usage`);static LOCKS_DIR=l.join(this.CACHE_DIR,`locks`);static isLocked(e){let t=l.join(this.LOCKS_DIR,e);if(!r.existsSync(t))return!1;try{let n=r.readFileSync(t,`utf-8`),i=parseInt(n.trim(),10);if(isNaN(i))return D(`Invalid PID in lock file ${e}, removing stale lock`),r.unlinkSync(t),!1;try{return process.kill(i,0),!0}catch(n){return n.code===`ESRCH`?(D(`Removing stale lock file ${e} for dead process ${i}`),r.unlinkSync(t),!1):(D(`Error checking process ${i} for lock ${e}:`,n),!0)}}catch(t){return D(`Error reading lock file ${e}:`,t),!0}}static async acquireLock(e,t=5e3){await this.ensureCacheDirectories();let n=l.join(this.LOCKS_DIR,e),i=Date.now(),a=String(process.pid);for(;Date.now()-i<t;)try{return await r.promises.writeFile(n,a,{flag:`wx`}),D(`Lock acquired for ${e}`),!0}catch(e){if(e.code===`EEXIST`)await de(50);else throw e}return D(`Failed to acquire lock for ${e} within ${t}ms`),!1}static async releaseLock(e){let t=l.join(this.LOCKS_DIR,e);try{await r.promises.unlink(t),D(`Lock released for ${e}`)}catch(t){t.code!==`ENOENT`&&D(`Error releasing lock for ${e}:`,t)}}static async ensureCacheDirectories(){try{await Promise.all([r.promises.mkdir(this.CACHE_DIR,{recursive:!0}),r.promises.mkdir(this.USAGE_CACHE_DIR,{recursive:!0}),r.promises.mkdir(this.LOCKS_DIR,{recursive:!0})])}catch(e){D(`Failed to create cache directories:`,e)}}static createProjectHash(e){return ae(`md5`).update(e).digest(`hex`).substring(0,8)}static async getUsageCache(e,t){await this.ensureCacheDirectories();let n=l.join(this.USAGE_CACHE_DIR,`${e}.json`),i=`${e}.usage.lock`;for(let a=0;a<3;a++){if(this.isLocked(i)){D(`Cache for ${e} is locked, waiting...`),await de(75);continue}try{let i=await r.promises.readFile(n,`utf-8`),a=JSON.parse(i);return!t||a.timestamp>=t?(D(`[CACHE-HIT] ${e} disk cache: found`),this.deserializeDates(a.data)):(D(`${e} cache outdated: cache=${a.timestamp}, latest=${t}`),null)}catch(t){if(t.code===`ENOENT`)return D(`No shared ${e} usage cache found`),null;D(`Attempt ${a+1} failed to read ${e} cache: ${t.message}. Retrying...`),await de(75)}}return D(`Failed to read ${e} cache after 3 attempts.`),null}static deserializeDates(e){return Array.isArray(e)?e.map(e=>({...e,timestamp:new Date(e.timestamp)})):e}static async setUsageCache(e,t,n){let i=`${e}.usage.lock`;if(!await this.acquireLock(i)){D(`Could not acquire lock to set usage cache for ${e}`);return}try{await this.ensureCacheDirectories();let i=l.join(this.USAGE_CACHE_DIR,`${e}.json`),a=JSON.stringify({data:t,timestamp:n||Date.now()});await r.promises.writeFile(i,a,`utf-8`),D(`[CACHE-SET] ${e} disk cache stored`)}catch(t){D(`Failed to save ${e} usage cache:`,t)}finally{await this.releaseLock(i)}}};const LL={"claude-haiku-4-5-20251001":{name:`Claude Haiku 4.5`,input:1,output:5,cache_write_5m:1.25,cache_write_1h:2,cache_read:.1},"claude-haiku-4-5":{name:`Claude Haiku 4.5`,input:1,output:5,cache_write_5m:1.25,cache_write_1h:2,cache_read:.1},"claude-opus-4-20250514":{name:`Claude Opus 4`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-opus-4-1":{name:`Claude Opus 4.1`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-opus-4-1-20250805":{name:`Claude Opus 4.1`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-sonnet-4-20250514":{name:`Claude Sonnet 4`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-4-opus-20250514":{name:`Claude 4 Opus`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-4-sonnet-20250514":{name:`Claude 4 Sonnet`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-sonnet-4-5":{name:`Claude Sonnet 4.5`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-sonnet-4-5-20250929":{name:`Claude Sonnet 4.5`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-opus-4-5":{name:`Claude Opus 4.5`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-opus-4-5-20251101":{name:`Claude Opus 4.5`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-opus-4-6":{name:`Claude Opus 4.6`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-opus-4-6-20260205":{name:`Claude Opus 4.6`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-sonnet-4-6":{name:`Claude Sonnet 4.6`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3}};var RL=class{static executionCache=null;static modelPricingCache=new Map;static GITHUB_PRICING_URL=`https://raw.githubusercontent.com/promptctl/cc-candybar/main/pricing.json`;static async loadDiskCache(){let e=Date.now()-1440*60*1e3;return await IL.getUsageCache(`pricing`,e)}static async saveDiskCache(e){await IL.setUsageCache(`pricing`,e)}static async fetchPricingData(){return new Promise(e=>{let t=new ee(this.GITHUB_PRICING_URL),n=E({hostname:t.hostname,path:t.pathname,headers:{"User-Agent":`cc-candybar`,"Cache-Control":`no-cache`},timeout:5e3},t=>{if(t.statusCode!==200){D(`HTTP ${t.statusCode}: ${t.statusMessage}`),e(null);return}let r=``,i=0;t.on(`data`,t=>{if(i+=t.length,i>1048576){D(`Response too large`),n.destroy(),e(null);return}r+=t}),t.on(`end`,()=>{try{let t=JSON.parse(r),n=t._meta,i={};for(let[e,n]of Object.entries(t))e!==`_meta`&&(i[e]=n);this.validatePricingData(i)?(D(`Fetched fresh pricing from GitHub for ${Object.keys(i).length} models`),D(`Pricing last updated: ${n?.updated||`unknown`}`),e(i)):(D(`Invalid pricing data structure`),e(null))}catch(t){D(`Failed to parse JSON:`,t),e(null)}}),t.on(`error`,t=>{D(`Response error:`,t),e(null)})});n.on(`error`,t=>{D(`Request error:`,t),e(null)}),n.on(`timeout`,()=>{D(`Request timeout`),n.destroy(),e(null)}),n.end()})}static async getCurrentPricing(){if(this.executionCache!==null)return D(`[CACHE-HIT] Pricing execution cache: ${Object.keys(this.executionCache).length} models`),this.executionCache;let e=await this.loadDiskCache();if(e)return D(`[CACHE-HIT] Pricing disk cache: ${Object.keys(e).length} models`),this.executionCache=e,D(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(e).length} models`),e;let t=await this.fetchPricingData();return t?(await this.saveDiskCache(t),D(`[CACHE-SET] Pricing disk cache stored: ${Object.keys(t).length} models`),this.executionCache=t,D(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(t).length} models`),t):(D(`[CACHE-FALLBACK] Using offline pricing data: ${Object.keys(LL).length} models`),this.executionCache=LL,D(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(LL).length} models`),LL)}static validatePricingData(e){if(!e||typeof e!=`object`)return!1;for(let[,t]of Object.entries(e)){if(!t||typeof t!=`object`)return!1;let e=t;if(typeof e.input!=`number`||typeof e.output!=`number`||typeof e.cache_read!=`number`)return!1}return!0}static async getModelPricing(e){if(this.modelPricingCache.has(e))return D(`[CACHE-HIT] Model pricing cache: ${e}`),this.modelPricingCache.get(e);let t=await this.getCurrentPricing(),n;return n=t[e]?t[e]:this.fuzzyMatchModel(e,t),this.modelPricingCache.set(e,n),D(`[CACHE-SET] Model pricing cache: ${e}`),n}static fuzzyMatchModel(e,t){let n=e.toLowerCase();for(let[e,r]of Object.entries(t))if(e.toLowerCase()===n)return r;for(let{pattern:e,fallback:r}of[{pattern:[`opus-4-6`,`claude-opus-4-6`],fallback:`claude-opus-4-6-20260205`},{pattern:[`opus-4-5`,`claude-opus-4-5`],fallback:`claude-opus-4-5-20251101`},{pattern:[`opus-4-1`,`claude-opus-4-1`],fallback:`claude-opus-4-1-20250805`},{pattern:[`opus-4`,`claude-opus-4`],fallback:`claude-opus-4-20250514`},{pattern:[`sonnet-4-6`,`sonnet-4.6`,`claude-sonnet-4-6`],fallback:`claude-sonnet-4-6`},{pattern:[`sonnet-4.5`,`4-5-sonnet`,`sonnet-4-5`],fallback:`claude-sonnet-4-5-20250929`},{pattern:[`sonnet-4`,`claude-sonnet-4`],fallback:`claude-sonnet-4-20250514`},{pattern:[`haiku-4.5`,`4-5-haiku`,`haiku-4-5`],fallback:`claude-haiku-4-5-20251001`},{pattern:[`haiku`],fallback:`claude-haiku-4-5-20251001`},{pattern:[`opus`],fallback:`claude-opus-4-20250514`},{pattern:[`sonnet`],fallback:`claude-sonnet-4-5-20250929`}])if(e.some(e=>n.includes(e))&&t[r])return t[r];return t[`claude-sonnet-4-5-20250929`]||{name:`${e} (Unknown Model)`,input:3,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3,output:15}}static async calculateCostForEntry(e){let t=e.message?.usage;if(!t)return 0;let n=this.extractModelId(e),r=await this.getModelPricing(n),i=t.input_tokens||0,a=t.output_tokens||0,o=t.cache_creation_input_tokens||0,s=t.cache_read_input_tokens||0,c=i/1e6*r.input,l=a/1e6*r.output,u=s/1e6*r.cache_read,d=o/1e6*r.cache_write_5m;return c+l+d+u}static extractModelId(e){if(e.model&&typeof e.model==`string`)return e.model;let t=e.message;if(t?.model){let e=t.model;if(typeof e==`string`)return e;let n=e;return(typeof n?.id==`string`?n.id:null)||`claude-sonnet-4-5-20250929`}return e.model_id&&typeof e.model_id==`string`?e.model_id:`claude-sonnet-4-5-20250929`}};const zL=/<command-name>\s*([^<\s][^<]*?)\s*<\/command-name>/;function BL(e){if(typeof e==`string`)return zL.exec(e)?.[1]}function VL(e){let t=e?.todos;if(!Array.isArray(t))return;let n=[];for(let e of t){if(typeof e!=`object`||!e)continue;let{content:t,activeForm:r,status:i}=e,a=i===`in_progress`,o=a&&typeof r==`string`?r:t;typeof o==`string`&&n.push({text:o,active:a,done:i===`completed`})}return n}function HL(e){return typeof e==`string`?e:Array.isArray(e)?e.find(e=>typeof e==`object`&&!!e&&e.type===`text`&&typeof e.text==`string`)?.text??``:``}function UL(e,t){let n=e.message?.content,r=[],i=[],a;if(Array.isArray(n))for(let e of n){if(typeof e!=`object`||!e)continue;let t=e;switch(t.type){case`tool_use`:{let{id:e,name:n}=t;if(typeof e!=`string`||typeof n!=`string`)break;r.push({id:e,name:n}),n===`TodoWrite`&&(a=VL(t.input)??a);break}case`tool_result`:{let e=t.tool_use_id;typeof e==`string`&&i.push(e);break}default:break}}let o=t===`prompt`?BL(HL(n)):void 0;if(!(r.length===0&&i.length===0&&a===void 0&&o===void 0))return{...r.length>0&&{started:r},...i.length>0&&{finished:i},...a!==void 0&&{todos:a},...o!==void 0&&{command:o}}}function WL(e){if(e!==void 0)return[e];let t=g();return[p(t,`.config`,`claude`),p(t,`.claude`)].filter(e=>a(e))}async function GL(e){let t=[];for(let n of e){let e=p(n,`projects`);if(a(e))try{let n=await FF(e,{withFileTypes:!0});for(let r of n)if(r.isDirectory()){let n=p(e,r.name);t.push(n)}}catch(t){D(`Failed to read projects directory ${e}:`,t)}}return t}async function KL(e,t,n){let r=[],i=p(t,e,`subagents`);try{let t=(await FF(i)).filter(e=>e.startsWith(`agent-`)&&e.endsWith(`.jsonl`));for(let a of t){let t=p(i,a);if(n?.has(t)){r.push(t);continue}try{let n=(await IF(t,`utf-8`)).split(`
196
+ `)[0];n&&JSON.parse(n).sessionId===e&&r.push(t)}catch{D(`Failed to check agent file ${t}`)}}}catch(e){D(`Failed to read subagents directory ${i}:`,e)}return r}function qL(e){let t=e.message;if((e.type||t?.role||t?.type)!==`user`)return;if(YL(t)===`tool_result`)return`tool-result`;let n=typeof e.origin==`object`&&e.origin!==null?e.origin.kind:void 0;if(n!==void 0&&n!==`human`)return`turn`;let r=HL(t?.content).trimStart();return r.startsWith(`[Request interrupted by user`)?`interrupt`:e.isMeta===!0||e.isCompactSummary===!0||JL.test(r)?`claude-code`:`prompt`}const JL=/^<(?:command-name|local-command-std(?:out|err)|bash-(?:input|stdout|stderr))>/;function YL(e){let t=e?.content;return Array.isArray(t)&&typeof t[0]==`object`&&t[0]?t[0].type:void 0}const XL=new Map;async function ZL(e){try{let t=await LF(e),n=t.size,r=XL.get(e);if(r&&r.mtime===t.mtimeMs&&r.size===n)return D(`[parse-cache] hit ${e}`),XL.delete(e),XL.set(e,r),r.entries;let i;return n>1048576?(D(`Using streaming parser for large file ${e} (${Math.round(n/1024)}KB)`),i=await nR(e)):i=await eR(e),D(`Parsed ${i.length} entries from ${e}`),n>5242880?i:(XL.delete(e),XL.size>=16&&XL.delete(XL.keys().next().value),XL.set(e,{mtime:t.mtimeMs,size:n,entries:i}),i)}catch(t){if(t.code===`ENOENT`)return D(`Transcript not present yet: ${e}`),[];throw t}}function QL(e){if(!e.timestamp)return null;let t=e.message,n=t?.usage,r=qL(e);return{timestamp:new Date(e.timestamp),type:typeof e.type==`string`?e.type:void 0,message:t?{id:typeof t.id==`string`?t.id:void 0,model:typeof t.model==`string`?t.model:void 0,usage:n,role:typeof t.role==`string`?t.role:void 0,type:typeof t.type==`string`?t.type:void 0}:void 0,costUSD:typeof e.costUSD==`number`?e.costUSD:void 0,isSidechain:e.isSidechain===!0,userEntry:r,activity:UL(e,r),raw:{model:typeof e.model==`string`?e.model:void 0,message:t?{id:typeof t.id==`string`?t.id:void 0,model:typeof t.model==`string`?t.model:void 0,usage:n}:void 0,requestId:typeof e.requestId==`string`?e.requestId:void 0}}}function $L(e){let t=[];for(let n of e.split(`
197
+ `))if(n.trim())try{let e=QL(JSON.parse(n));e&&t.push(e)}catch(e){D(`Failed to parse JSONL line: ${e}`);continue}return t}async function eR(e){return $L(await IF(e,`utf-8`))}async function tR(e,t){let n=await RF(e,t===void 0?void 0:{offset:t.offset,ino:t.ino});if(n.kind!==`ok`)return n;let{buf:r,start:i,stamp:a,ino:o,reset:s}=n.value,c=r.lastIndexOf(10);return R(c<0?{entries:[],cursor:{offset:i,stamp:a,ino:o},reset:s}:{entries:$L(r.subarray(0,c+1).toString(`utf-8`)),cursor:{offset:i+c+1,stamp:a,ino:o},reset:s})}async function nR(e){return new Promise((t,n)=>{let r=[],a=i(e,{encoding:`utf8`}),o=fe({input:a,crlfDelay:1/0});o.on(`line`,e=>{let t=e.trim();if(t)try{let e=QL(JSON.parse(t));e&&r.push(e)}catch(e){D(`Failed to parse JSONL line: ${e}`)}}),o.on(`close`,()=>{t(r)}),o.on(`error`,t=>{D(`Streaming parser error for ${e}:`,t),n(t)}),a.on(`error`,t=>{D(`File stream error for ${e}:`,t),n(t)})})}var rR=class{inflight=new Map;run(e,t){return this.inflight.get(e)??this.start(e,t)}start(e,t){let n=t();this.inflight.set(e,n);let r=()=>{this.inflight.get(e)===n&&this.inflight.delete(e)};return n.then(r,r),n}get size(){return this.inflight.size}};function iR(e,t){let n=e?e.input+e.cacheCreation+e.cacheRead:0,r=e?e.output:0;return{input:n,output:r,total:n+r,atMs:t}}const aR=new Map,oR={cost:0,input:0,output:0,cacheCreation:0,cacheRead:0},sR={cost:null,calculatedCost:null,officialCost:null,tokens:null,tokenBreakdown:null};function cR(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function lR(){let e=new Date;return e.setHours(0,0,0,0),e.setDate(e.getDate()-1),e.getTime()}function uR(){return{input:0,output:0,cacheCreation:0,cacheRead:0}}async function dR(e,t,n,r){let i=cR(new Date(lR())),a=e&&!t?e:void 0,o=a?.entries??0,s=a?.cost??0,c=a?{...a.breakdown}:uR(),l=new Map;if(a)for(let[e,t]of a.days)e>=i&&l.set(e,{...t});for(let e of n){let t=e.message?.usage;if(!t)continue;o++;let n=e.costUSD??await RL.calculateCostForEntry(e.raw);s+=n,c.input+=t.input_tokens||0,c.output+=t.output_tokens||0,c.cacheCreation+=t.cache_creation_input_tokens||0,c.cacheRead+=t.cache_read_input_tokens||0;let r=cR(new Date(e.timestamp));if(r<i)continue;let a=l.get(r)??{...oR};a.cost+=n,a.input+=t.input_tokens||0,a.output+=t.output_tokens||0,a.cacheCreation+=t.cache_creation_input_tokens||0,a.cacheRead+=t.cache_read_input_tokens||0,l.set(r,a)}return{cursor:r,entries:o,cost:s,breakdown:c,days:l}}function fR(e){let t=0,n=0,r=uR(),i=new Map;for(let a of e.values()){t+=a.entries,n+=a.cost,r.input+=a.breakdown.input,r.output+=a.breakdown.output,r.cacheCreation+=a.breakdown.cacheCreation,r.cacheRead+=a.breakdown.cacheRead;for(let[e,t]of a.days){let n=i.get(e)??{...oR};n.cost+=t.cost,n.input+=t.input,n.output+=t.output,n.cacheCreation+=t.cacheCreation,n.cacheRead+=t.cacheRead,i.set(e,n)}}if(t===0)return{sessionInfo:sR,days:i};let a=r.input+r.output+r.cacheCreation+r.cacheRead;return{sessionInfo:{cost:n,calculatedCost:n,officialCost:null,tokens:a,tokenBreakdown:r},days:i}}async function pR(e,t,n){let r=0,i=async()=>{for(;r<e.length;){let t=e[r++];await n(t)}},a=Math.min(t,e.length);await Promise.all(Array.from({length:a},i))}var mR=class{sessions=new Map;flight=new rR;seeded=new Map;seededDay=``;rescanIntervalMs;speedFlight=new rR;staleAgeMs;log;renderTally={hits:0,misses:0};sweeps=0;scans={seed:0,rescan:0};sweepTimer=null;constructor(e={}){this.log=e.logger??Nt,this.staleAgeMs=e.staleAgeMs??864e5,this.rescanIntervalMs=e.rescanIntervalMs??6e4;let t=e.sweepIntervalMs??3e5;t>0&&(this.sweepTimer=setInterval(()=>this.sweepStale(),t),this.sweepTimer.unref())}getStats(){return{size:this.sessions.size,hits:this.renderTally.hits,misses:this.renderTally.misses,sweeps:this.sweeps,seeds:this.scans.seed,rescans:this.scans.rescan}}async getUsageInfo(e,t){let n=await this.ingest(e,t?.transcript_path,this.renderTally);if(n.kind===`failed`)return n;let r=n.kind===`ok`?n.value.sessionInfo:sR,i=t?.cost?.total_cost_usd??null;return R({session:{...r,cost:i??r.cost,officialCost:i}})}async getTodayInfo(e,t,n){let r=cR(yw(n)),i=WL(t);try{await this.ensureSeeded(r,i,n*1e3)}catch(e){return B(`usage seed: ${e instanceof Error?e.message:String(e)}`)}let a=await this.ingest(e?.session_id??``,e?.transcript_path,this.renderTally);if(a.kind===`failed`)return a;let o=i.map(e=>p(e,`projects`)+m),s={...oR},c=!1;for(let[t,{record:n}]of this.sessions){let i=n?.transcriptPath??``,a=t===e?.session_id||o.some(e=>i.startsWith(e))?n?.days??aR:aR;c||=a.has(r);let l=a.get(r)??oR;s.cost+=l.cost,s.input+=l.input,s.output+=l.output,s.cacheCreation+=l.cacheCreation,s.cacheRead+=l.cacheRead}return c?R({cost:s.cost,tokens:s.input+s.output+s.cacheCreation+s.cacheRead,tokenBreakdown:{input:s.input,output:s.output,cacheCreation:s.cacheCreation,cacheRead:s.cacheRead},date:r}):z}async observeSpeed(e,t,n){if(!e)return z;let r=jF(t);return this.speedFlight.run(`${e}:${r}`,async()=>{let i=await this.ingest(e,t,this.renderTally,r);if(i.kind===`failed`)return i;let a=iR(i.kind===`ok`?i.value.sessionInfo.tokenBreakdown:null,n),{ring:o}=this.hold(e),s;for(let e of o)e.atMs<a.atMs&&(s===void 0||e.atMs>s.atMs)&&(s=e);return o.push(a),o.sort((e,t)=>e.atMs-t.atMs),o.length>64&&o.shift(),R({...s!==void 0&&{prev:s},cur:a,samples:[...o]})})}async ingest(e,t,n,r){if(!e)return z;let i=r??jF(t),a=this.see(e)?.record;if(a&&i!==``&&a.transcriptStamp===i)return n.hits++,R(a);if(!t)return a?R(a):z;n.misses++;let o;try{o=await this.flight.run(`${e}:${i}`,async()=>{let n=this.sessions.get(e)?.record;return{prior:n,outcome:await this.refold(e,t,n)}})}catch(t){return B(`usage refold (${e}): ${t instanceof Error?t.message:String(t)}`)}let{prior:s,outcome:c}=o;if(c.kind!==`ok`)return c;let l={files:c.value.files,sessionInfo:c.value.sessionInfo,days:c.value.days,transcriptStamp:c.value.mainStamp,transcriptPath:t};return this.sessions.get(e)?.record===s&&(this.hold(e).record=l),R(l)}see(e){let t=this.sessions.get(e);return t&&(t.lastSeenAt=Date.now()),t}hold(e){let t=this.see(e);if(t)return t;let n={lastSeenAt:Date.now(),record:void 0,ring:[]};return this.sessions.set(e,n),n}async refold(e,t,n){let r=await KL(e,d(t),n===void 0?void 0:new Set(n.files.keys())),i=new Map,a=``;for(let e of[t,...r]){let r=n?.files.get(e),o=await tR(e,r?.cursor);if(o.kind===`failed`)return o;if(o.kind===`absent`){r&&i.set(e,r);continue}let{entries:s,cursor:c,reset:l}=o.value;i.set(e,await dR(r,l,s,c)),e===t&&(a=c.stamp)}return R({files:i,...fR(i),mainStamp:a})}ensureSeeded(e,t,n){this.seededDay!==e&&(this.seeded.clear(),this.seededDay=e);let r=t.join(`\0`),i=this.seeded.get(r);if(!i){let e=this.seed(t,`seed`),i={done:e,scanning:e,startedAtMs:n};return this.seeded.set(r,i),this.settle(r,i,e),e}return i.scanning===void 0&&n-i.startedAtMs>=this.rescanIntervalMs&&(i.startedAtMs=n,i.scanning=this.seed(t,`rescan`),this.settle(r,i,i.scanning)),i.done}settle(e,t,n){n.then(()=>{t.scanning=void 0},n=>{this.log(`warn`,`usageStore scan: ${n instanceof Error?n.message:String(n)}`),this.seeded.get(e)===t&&this.seeded.delete(e)})}async scanned(){await Promise.allSettled([...this.seeded.values()].map(e=>e.scanning))}async seed(e,t){let n=Date.now(),r=lR(),i=await GL(e),a=[];for(let e of i){let t;try{t=await FF(e)}catch{continue}for(let n of t){if(!n.endsWith(`.jsonl`))continue;let t=p(e,n),i;try{i=await LF(t)}catch{continue}i.mtimeMs<r||a.push({sessionId:n.slice(0,-6),path:t,stamp:MF(i)})}}let o={hits:0,misses:0};await pR(a,8,async e=>{let n=await this.ingest(e.sessionId,e.path,o,e.stamp);n.kind===`failed`&&this.log(`warn`,`usageStore ${t}: ${n.reason}`)}),this.log(`info`,`usageStore ${t} sessions=${a.length} read=${o.misses} dirs=${e.join(`,`)} ms=${Date.now()-n}`),this.scans[t]++}sweepStale(){let e=Date.now(),t=0,n=0,r=0;for(let[i,{lastSeenAt:a,record:o}]of this.sessions)if(!(e-a<=this.staleAgeMs)){if(o?.days.has(this.seededDay)){n++;continue}this.sessions.delete(i),t++,o===void 0&&r++}return t>0&&this.sweeps++,(t>0||n>0)&&this.log(`info`,`usageStore sweep dropped=${t} noRecord=${r} held=${n}`),t}close(){this.sweepTimer&&=(clearInterval(this.sweepTimer),null),this.sessions.clear(),this.seeded.clear()}},hR=class{thresholds={LOW:50,MEDIUM:80};getContextUsageThresholds(){return this.thresholds}ratioPercentages(e,t){let n=Math.min(100,Math.max(0,Math.round(e/t*100)));return{percentage:n,contextLeftPercentage:Math.max(0,100-n)}}calculateContextFromHookData(e){let t=e.context_window;if(!t?.current_usage)return D(`No current_usage in hook data, falling back to transcript parsing`),null;let n=t.current_usage,r=t.context_window_size,i=(n.input_tokens||0)+(n.cache_creation_input_tokens||0)+(n.cache_read_input_tokens||0);D(`Native current_usage: input=${n.input_tokens}, cache_create=${n.cache_creation_input_tokens}, cache_read=${n.cache_read_input_tokens}, total=${i} (limit: ${r})`);let a=this.ratioPercentages(i,r);return{totalTokens:i,maxTokens:r,percentage:t.used_percentage==null?a.percentage:Math.round(t.used_percentage),contextLeftPercentage:t.remaining_percentage==null?a.contextLeftPercentage:Math.round(t.remaining_percentage)}}async calculateContextTokensFromTranscript(e,t){try{D(`Calculating context tokens from transcript: ${e}`);let n=await ZL(e);if(n.length===0)return D(`No entries in transcript`),z;let r=null;for(let e=n.length-1;e>=0;e--){let t=n[e];if(t&&t.message?.usage?.input_tokens&&t.isSidechain!==!0){r=t,D(`Context segment: Found most recent entry at ${t.timestamp.toISOString()}, stopping search`);break}}if(r?.message?.usage){let e=r.message.usage,n=(e.input_tokens||0)+(e.cache_read_input_tokens||0)+(e.cache_creation_input_tokens||0);return D(`Most recent main chain context: ${n} tokens (limit: ${t})`),R({totalTokens:n,maxTokens:t,...this.ratioPercentages(n,t)})}return D(`No main chain entries with usage data found`),z}catch(e){return B(`context transcript: ${e instanceof Error?e.message:String(e)}`)}}async getContextInfo(e){let t=this.calculateContextFromHookData(e);if(t)return R(t);let n=e.context_window?.context_window_size??2e5;return this.calculateContextTokensFromTranscript(e.transcript_path,n)}},gR=class{states=new Map;constructor(e,t,n=256){this.empty=e,this.step=t,this.maxSessions=n}async read(e,t){let n=this.states.get(e),r=jF(t);if(n&&r!==``&&n.cursor.stamp===r)return this.touch(e,n),{kind:`ok`,value:n.value};let i=await tR(t,n?.cursor);if(i.kind===`failed`)return i;if(i.kind===`absent`)return{kind:`ok`,value:n?.value??this.empty};let{entries:a,cursor:o,reset:s}=i.value,c=s||n===void 0?this.empty:n.value;for(let e of a)c=this.step(c,e);for(this.touch(e,{cursor:o,value:c});this.states.size>this.maxSessions;){let e=this.states.keys().next().value;if(e===void 0)break;this.states.delete(e)}return{kind:`ok`,value:c}}touch(e,t){this.states.delete(e),this.states.set(e,t)}};const _R={messageCount:0,nonPrompts:0,recent:[]},vR=new Set([`turn`,`interrupt`,`claude-code`]);function yR(e,t){if(t.isSidechain)return e;let n=[...e.recent,t];return{messageCount:e.messageCount+ +(t.userEntry===`prompt`),nonPrompts:e.nonPrompts+ +!!vR.has(t.userEntry),recent:n.length>20?n.slice(-20):n}}function bR(e){let t=null,n=null;for(let r of e){let e=r.type||r.message?.role||r.message?.type;if(r.userEntry===`prompt`||r.userEntry===`turn`)t=r.timestamp;else if(e===`assistant`&&t){let e=(r.timestamp.getTime()-t.getTime())/1e3;e>.1&&e<300&&(n=e)}}return n}var xR=class{fold=new gR(_R,yR);async getMetricsInfo(e,t){if(D(`Getting metrics from hook data for session: ${e}`),!t.cost)return z;let n=await this.fold.read(e,t.transcript_path);return n.kind===`failed`?B(`metrics (${e}): ${n.reason}`):R({responseTime:t.cost.total_api_duration_ms/1e3,lastResponseTime:bR(n.value.recent),sessionDuration:t.cost.total_duration_ms/1e3,messageCount:n.value.messageCount,nonPrompts:n.value.nonPrompts,linesAdded:t.cost.total_lines_added,linesRemoved:t.cost.total_lines_removed})}};const SR={command:null,todos:[],pending:[],done:[]};function CR(e,t){let n=e.findIndex(e=>e.name===t);return n<0?[...e,{name:t,count:1}]:e.map((e,t)=>t===n?{name:e.name,count:e.count+1}:e)}function wR(e,t){switch(t.userEntry){case`prompt`:return{...e,command:t.activity?.command??null,pending:[],done:[]};case`interrupt`:return{...e,pending:[]};case`turn`:case`tool-result`:case`claude-code`:case void 0:return e}}function TR(e,t){if(t.isSidechain)return e;let n=wR(e,t),r=t.activity;if(r===void 0)return n;let i=n.pending,a=n.done;r.started!==void 0&&(i=[...i,...r.started]);for(let e of r.finished??[]){let t=i.findIndex(t=>t.id===e);t<0||(a=CR(a,i[t].name),i=[...i.slice(0,t),...i.slice(t+1)])}return{...n,pending:i,done:a,todos:r.todos??n.todos}}function ER(e){return{command:e.command,todos:e.todos,running:e.pending.reduce((e,t)=>CR(e,t.name),[]),done:e.done}}var DR=class{fold=new gR(SR,TR);async getActivityInfo(e,t){let n=await this.fold.read(e,t.transcript_path);return n.kind===`failed`?B(`activity (${e}): ${n.reason}`):R(ER(n.value))}};function OR(e,t,n,r){return{bin:`tmux`,args:[`-S`,e.socket,...n],timeoutMs:2e3,category:t,stdinInput:r}}function kR(e,t){if(e.ok)return{kind:`ok`,stdout:e.stdout};if(e.reason===`rate-limited`)return{kind:`rate-limited`,reason:e.error??`rate-limited`};let n=e.error??[e.reason,e.stderr.trim()].filter(e=>e!==``).join(`: `);return{kind:`failed`,reason:`tmux ${t[0]} failed (${n})`}}function AR(e,t,n,r){return kR(Me(OR(e,t,n,r)),n)}async function jR(e,t,n){return kR(await O(OR(e,t,n)),n)}const MR=e=>`${e.socket}\n${e.pane}`;var NR=class{names=new Map;asking=new rR;constructor(e=Date.now){this.now=e}getSessionName(e){let t=MR(e),n=this.names.get(t);if(n&&this.now()-n.at<3e4)return Promise.resolve(n.outcome);let r=this.asking.run(t,()=>this.ask(t,e));return n?Promise.resolve(n.outcome):r}async ask(e,t){D(`Getting tmux session name for pane ${t.pane} on ${t.socket}`);let n=await jR(t,`tmux`,[`display-message`,`-p`,`-t`,t.pane,`#S`]),r=n.kind===`ok`?n.stdout.trim():``,i=n.kind===`ok`?r?R(r):z:B(n.reason);for(this.names.delete(e),this.names.set(e,{outcome:i,at:this.now()});this.names.size>64;)this.names.delete(this.names.keys().next().value);return i}};const PR=e=>JSON.stringify([e.sessionId,e.projectDir,e.cwd,e.claudeConfigDir,e.env===void 0?null:et.map(t=>e.env?.[t]??null)]);var FR=class{readings=new Map;inFlight=new Map;constructor(e,t=Date.now){this.edge=e,this.now=t}getCeiling(e){let t=PR(e),n=this.readings.get(t);if(n&&this.now()-n.at<1e4)return Promise.resolve(n.outcome);let r=this.inFlight.get(t)??this.fetch(t,e);return n?Promise.resolve(n.outcome):r}fetch(e,t){let n=this.edge.locate(t),r=(n.kind===`ok`?this.edge.read(n.value,t):Promise.resolve(n)).then(t=>{if(this.inFlight.get(e)!==r)return t;for(this.readings.delete(e),this.readings.set(e,{outcome:t,at:this.now()});this.readings.size>64;)this.readings.delete(this.readings.keys().next().value);return t}).finally(()=>{this.inFlight.get(e)===r&&this.inFlight.delete(e)});return this.inFlight.set(e,r),r}move(e,t){let n=this.edge.locate(e);if(n.kind!==`ok`)throw Error(n.kind===`failed`?n.reason:`memento is not installed or not enabled for this project`);let r=PR(e);try{this.edge.move(n.value,e,t)}finally{this.readings.delete(r),this.inFlight.delete(r),this.fetch(r,e)}}};function IR(e){return{gitProvider:new pw({watchers:e.watchers,logger:e.logger}),usageStore:new mR({logger:e.logger}),contextProvider:new hR,metricsProvider:new xR,activityProvider:new DR,tmuxService:new NR,mementoProvider:new FR(nI()),autoCompact:tO,log:e.logger}}function LR(e,t){return e===void 0?!0:e.evaluate(t).map(e=>e.plain).join(``)!==`false`}const RR={kind:`hidden`},zR={kind:`shown`};function BR(e,t){try{return LR(e,t)?zR:RR}catch(e){return{kind:`failed`,message:e instanceof Error?e.message:String(e)}}}function VR(e,t){let n=q.fromFragments(e);return n.end=``,n.overflow=`ignore`,t!==void 0&&!t.isNull&&(n.style=t),n}function HR(e,t,n){e.cellLength>t?e.truncate(t,{mode:n.truncate,marker:`…`}):e.cellLength<t&&e.align(n.justify,t)}function UR({lead:e,text:t,trail:n}){return[...e===void 0?[]:[e],t,...n===void 0?[]:[n]]}function WR({text:e,placement:t,lead:n,trail:r}){return{text:GR(e),placement:t,...n!==void 0&&{lead:GR(n)},...r!==void 0&&{trail:GR(r)}}}function GR(e){let t=e.blankCopy(e.plain);t.style=am(e.style).clearMetaAndLinks();for(let{start:n,end:r,style:i}of e.spans)t.stylize(am(i).clearMetaAndLinks(),n,r);return t}function KR(e){let t=UR(e);if(t.length===1)return e.text;let n=VR(t);return n.style=e.text.style,n}function qR(e,t){let{width:n,justify:r,truncate:i,baseStyle:a,padding:o,placement:s,lead:c=[],trail:l=[]}=t;if(e.length===0)return[];let u=VR(e,a).pad(o),d=new q(` `.repeat(o)),f={placement:s,...c.length>0&&{lead:VR([d,...c],a)},...l.length>0&&{trail:VR([...l,d],a)}};if(n===`auto`)return[{text:u,...f}];let p={justify:r,truncate:i};return n===`fill`?[{text:u,fill:p,...f}]:(HR(u,n,p),[{text:u,...f}])}function JR(e,t){let n=()=>e.map(e=>({owner:KR(e),placement:e.placement})),r=[];if(e.forEach(({fill:e},t)=>{e!==void 0&&r.push({at:t,how:e})}),r.length===0||!Number.isFinite(t.width))return n();let i=Dm(e.map(KR),t).split(`
198
+ `);if(i.length>1)return n();let a=Math.max(0,t.width-_m(i[0]??``)),o=Math.floor(a/r.length),s=a-o*r.length;return r.forEach(({at:t,how:n},i)=>{let a=o+(i===r.length-1?s:0),{text:c}=e[t];HR(c,c.cellLength+a,n)}),n()}function YR(e,t){let n=[],r=[],i=()=>{if(!r.length)return;let e=XR(r,t);e.plain.length>0&&n.push(e),r=[]};for(let a of e){let e={frag:a,style:am(a.style)};if(e.style.link){i();let r=XR([e],t);r.plain.length>0&&n.push(r)}else r.push(e)}return i(),n}function XR(e,t){let n=t!==void 0&&!t.isNull?t:void 0,r=e.map(e=>ZR(e.frag,n?n.add(e.style):e.style)),i=q.fromFragments(r);return i.end=``,i.overflow=`ignore`,r.length===1?i.style=r[0].style:n!==void 0&&(i.style=n),i}function ZR(e,t){let n=e.copy();return n.style=t,n}function QR(e,t){if(e.look===void 0)throw Error(`${t} read the render's look before any render resolved one`);return e.look}function $R(e,t,n,r){let i=new Map,a=Object.entries(t);for(let[t,o]of[...a.filter(([,e])=>!(`do`in e)),...a.filter(([,e])=>`do`in e)])i.set(t,ez(e,t,o,n,r,i));return i}function ez(e,t,n,r,i,a){if(`set`in n){let e=r.get(n.set)??n.set;if(`to`in n)return{kind:`set-literal`,key:n.set,value:n.to,stateVar:e};if(`from`in n){let t=rg(n.from,i);return{kind:`set-option`,key:n.set,stateVar:e,options:[...t.members],paletteOf:t.paletteOf,library:t.library}}return`int`in n?{kind:`set-int`,key:n.set,stateVar:e}:`cycle`in n?{kind:`set-cycle`,key:n.set,stateVar:e,members:n.cycle}:{kind:`set-bounded`,key:n.set,by:n.by}}if(`persist`in n){let e=_a.get(n.persist)??n.persist;if(`to`in n)return{kind:`persist-literal`,key:n.persist,value:n.to,stateVar:e};if(`from`in n){let t=rg(n.from,i);return{kind:`persist-option`,key:n.persist,stateVar:e,options:[...t.members],paletteOf:t.paletteOf,library:t.library}}if(`cycle`in n)return{kind:`persist-cycle`,key:n.persist,stateVar:e,members:n.cycle};if(`removeSegment`in n)return{kind:`layout-op`,key:n.persist,op:{op:`remove`,target:n.removeSegment}};if(`insertSegment`in n)return{kind:`layout-op`,key:n.persist,op:{op:`insert`,segment:n.insertSegment,anchor:n.anchor,relation:n.relation}};if(`insertSegmentFrom`in n){let e=rg(n.insertSegmentFrom,i);return{kind:`layout-op-option`,key:n.persist,anchor:n.anchor,relation:n.relation,options:[...e.members],paletteOf:e.paletteOf,library:e.library}}return{kind:`persist-bounded`,key:n.persist,by:n.by}}if(`copy`in n)return{kind:`copy`,text:rz(e,n.copy,t)};if(`open`in n)return{kind:`open`,target:rz(e,n.open,t)};if(`reset`in n)return{kind:`reset`,key:n.reset};if(`doctor`in n)return n.doctor===`run`?{kind:`doctor-run`}:{kind:`doctor-fix`,check:n.check};if(`ceiling`in n)return{kind:`ceiling`,args:FM(n)};if(`slash`in n)return{kind:`slash`,line:n.slash};if(`undo`in n)return{kind:`undo`};if(`redo`in n)return{kind:`redo`};if(`back`in n)return{kind:`back`};if(`rewind`in n)return{kind:`rewind`};if(`save`in n)return{kind:`save`};if(`preset`in n)return n.preset===`save`?{kind:`preset-save`}:{kind:`preset-delete`,name:rz(e,n.name,t)};if(`themeDefault`in n)return{kind:`theme-default-save`};let[o,...s]=n.do.map(e=>{let n=a.get(e);if(n===void 0)throw Error(`action "${t}" fires "${e}", which is not declared in this config`);return n});return{kind:`do`,head:o,rest:s}}function tz(e){return e.kind===`do`?tz(e.head):e}function nz(e){switch(tz(e).kind){case`set-option`:case`set-int`:case`persist-option`:case`layout-op-option`:return!0;case`set-literal`:case`set-bounded`:case`set-cycle`:case`copy`:case`open`:case`persist-literal`:case`persist-bounded`:case`persist-cycle`:case`reset`:case`layout-op`:case`undo`:case`redo`:case`back`:case`rewind`:case`save`:case`preset-save`:case`preset-delete`:case`theme-default-save`:case`doctor-run`:case`doctor-fix`:case`ceiling`:case`slash`:case`do`:return!1}}function rz(e,t,n){try{return e(t)}catch(e){throw Error(`Template parse error in actions.${n}: ${e.message}`,{cause:e})}}function iz(e,t){return e.has(t)?Fg(e.read(t)):``}function az(e,t){return e.evaluate(t).map(e=>e.plain).join(``)}function oz(e,t,n,r){let i=new q(e,{style:G.combine([r,new G({link:t,bold:n})])});return i.overflow=`ignore`,i.end=``,i}function sz(e,t,n=!1){let r=new G({link:t,bold:n?!0:void 0}),i=new q(e.plain,{style:G.combine([am(e.style),r])});for(let t of e.spans)i.stylize(G.combine([am(t.style),r]),t.start,t.end);return i.overflow=`ignore`,i.end=``,i}function cz(e,t){return Math.max(e.members.indexOf(iz(t,e.stateVar)),0)}function lz(e,t,n,r,i){switch(e.kind){case`set-literal`:{let t=iz(r,e.stateVar);return{effects:[{verb:gn,args:[i,e.key,e.value]}],active:t===e.value}}case`set-option`:{let a=n??t,o=iz(r,e.stateVar);return{effects:[{verb:gn,args:[i,e.key,a]}],active:o===a}}case`set-int`:{let a=n??t,o=iz(r,e.stateVar);return{effects:[{verb:gn,args:[i,e.key,a]}],active:o===a}}case`set-cycle`:{let t=e.members[(cz(e,r)+1)%e.members.length];return{effects:[{verb:gn,args:[i,e.key,t]}],active:!1}}case`set-bounded`:return{effects:[{verb:N,args:[i,e.key,String(e.by)]}],active:!1};case`copy`:return{effects:[{verb:_n,args:[az(e.text,wC(r))]}],active:!1};case`open`:return{effects:[{verb:vn,args:[az(e.target,wC(r))]}],active:!1};case`persist-literal`:{let t=iz(r,e.stateVar);return{effects:[{verb:Sn,args:[i,e.key,e.value]}],active:t===e.value}}case`persist-option`:{let a=n??t,o=iz(r,e.stateVar);return{effects:[{verb:Sn,args:[i,e.key,a]}],active:o===a}}case`persist-cycle`:{let t=e.members[(cz(e,r)+1)%e.members.length];return{effects:[{verb:Sn,args:[i,e.key,t]}],active:!1}}case`persist-bounded`:return{effects:[{verb:Cn,args:[i,e.key,String(e.by)]}],active:!1};case`reset`:return{effects:[{verb:Dn,args:[i,e.key]}],active:!1};case`undo`:return{effects:[{verb:kn,args:[i]}],active:!1};case`redo`:return{effects:[{verb:An,args:[i]}],active:!1};case`back`:return{effects:[{verb:jn,args:[i]}],active:!1};case`rewind`:return{effects:[{verb:Mn,args:[i]}],active:!1};case`save`:return{effects:[{verb:wn,args:[i]}],active:!1};case`preset-save`:return{effects:[{verb:P,args:[i]}],active:!1};case`theme-default-save`:return{effects:[{verb:Tn,args:[i]}],active:!1};case`preset-delete`:return{effects:[{verb:En,args:[i,az(e.name,wC(r))]}],active:!1};case`doctor-run`:return{effects:[{verb:Pn,args:[i]}],active:!1};case`doctor-fix`:return{effects:[{verb:Fn,args:[i,e.check]}],active:!1};case`ceiling`:return{effects:[{verb:Ln,args:[i,...e.args]}],active:!1};case`slash`:return{effects:[{verb:Rn,args:[i,e.line]}],active:!1};case`layout-op`:return{effects:[{verb:On,args:[i,e.key,vA(e.op)]}],active:!1};case`do`:{let a=lz(e.head,t,n,r,i);return{effects:[...a.effects,...e.rest.flatMap(e=>lz(e,t,void 0,r,i).effects)],active:a.active}}case`layout-op-option`:{let r={op:`insert`,segment:n??t,anchor:e.anchor,relation:e.relation};return{effects:[{verb:On,args:[i,e.key,vA(r)]}],active:!1}}}}function uz(e,t,n,r){if(n.length===0)throw Error(`action "${e}" needs a display (the clickable text)`);if(t.kind===`set-cycle`||t.kind===`persist-cycle`)return{display:qn(`action "${e}"`,n,t.members.length,cz(t,r)),boundValue:void 0};if(n.length>2)throw Error(`action "${e}" takes a display and an optional bound value, got ${n.length} arguments (per-state displays are a cycle action's form)`);return{display:n[0],boundValue:n[1]?.plain}}function dz(e,t,n){let r=n.compiled.get(e);if(!r)throw Error(`action "${e}" is not declared in this config`);let i=n.store,{display:a,boundValue:o}=uz(e,tz(r),t,i),s=iz(i,`session.id`),{effects:c,active:l}=lz(r,a.plain,o,i,s);return sz(a,I(c),l)}function fz(e){return{action:{fn:(t,...n)=>dz(t,n,e),argTypes:[`string`,`liftable`],arity:{kind:`variadic`},returnType:`T`}}}function pz(e,t){return oz(`✕`,I([{verb:gn,args:[iz(e,`session.id`),t,L]}]),!1)}function mz(e,t,n){return new G({bgcolor:W.fromRgba(t),color:W.fromRgba(Pf(e,t,n))})}function hz({tint:e,text:t}){return new G({bgcolor:W.fromRgba(e),color:W.fromRgba(t)})}function gz(e,t,n){return new G({color:W.fromRgba(Qs(wf(e,`warning`),t,Nf,n))})}function _z(e,t,n){return G.combine([mz(e,t,n),gz(e,t,n)])}function vz(e,t,n){return mz(e.palette,tp(e.palette,e.disclosure,[t],n),n)}function yz(e){let t=W.fromRgba(wf(e,`background`)),n=q.fromFragments(Xd.map(n=>new q(`▀`,{style:new G({color:W.fromRgba(wf(e,n)),bgcolor:t})})));return n.overflow=`ignore`,n.end=``,n}const bz=(e,t)=>{let n=typeof e==`string`?new q(e,{style:t}):e;return n.overflow=`ignore`,n.end=``,n},xz=e=>new G({bold:e});function Sz(e,t,n,r,i,a){if(r===void 0)return(n,r,a,o)=>bz(a,G.combine([vz(e,{...n,distribution:t},i),xz(o)]));let o=mz(e.palette,a,i);return(e,t,i,a)=>Cz(i,G.combine([o,xz(a)]),r(t,n))}const Cz=(e,t,n)=>bz(q.fromFragments([bz(e,t),bz(` `,t),yz(n)]));function wz(e,t){return t===void 0?(e,t,n)=>bz(n):(n,r,i)=>Cz(i,void 0,t(r,e))}function Tz(e,t,n,r,i){let a=mz(e.palette,i,r);return(e,r,i,o)=>bz(q.fromFragments([bz(o?`[`:` `,a),yz(n(r,t)),bz(o?`]`:` `,a)]))}function Ez(e,t,n){let r=t.map(t=>({label:t.label,indices:e.flatMap((e,n)=>e.group===t.id?[n]:[])})).filter(e=>e.indices.length>0);if(r.reduce((e,t)=>e+t.indices.length,0)!==e.length){let n=new Set(t.map(e=>e.id)),r=e.flatMap((e,t)=>n.has(e.group)?[]:[`#${t} (group "${e.group}")`]);throw Error(`library: ${r.join(`, `)} name a group the domain does not list (${[...n].join(`, `)})`)}return n?r.flatMap(e=>Dz(e.indices,8).map(t=>[{label:e.label,indices:t}])):[r]}function Dz(e,t){return Array.from({length:Math.ceil(e.length/t)},(n,r)=>e.slice(r*t,(r+1)*t))}function Oz(e,t){return new q(e).truncate(t,{marker:`…`}).plain}function kz(e){return{current:null,drawnAt:e}}function Az(e,t,n,r,i,a,o){let s={segName:t,placementId:n,palette:r,disclosure:i,tint:a,text:o,bg:void 0,drops:[]};return e.current=s,s}function jz(e,t){let n=e.current;if(n===null)throw Error(`${t} is only available inside a segment's templates — there is no active segment here. Segment-scoped functions cannot be used in variable declarations or layout-node "when" predicates, which are evaluated outside any segment.`);return n}function Mz(e){return new q(e).cellLength}function Nz(e){return Math.max(1,e.width-e.chromeCols-2*e.padding)}function Pz(e){return Math.max(1,Nz(e)-(Mz(`✕`)+2*e.padding+e.seamCols))}function Fz(e,t,n){if(!Number.isFinite(t))return e.length>0?[e.map((e,t)=>t)]:[];let r=Math.max(1,t-n),i=[],a=[],o=0;for(let t=0;t<e.length;t++){let n=e[t];a.length===0?(a=[t],o=n):o+1+n<=r?(a.push(t),o+=1+n):(i.push(a),a=[t],o=n)}return a.length>0&&i.push(a),i}function Iz(e,t,n){let r=Mz(`←`)+1+Mz(`→`)+1,i=Fz(e,t,n);return(i.length>1?Fz(e,t,n+r):i).map(e=>[{label:``,indices:e}])}function Lz(e,t){let n=[];for(let t of e)n.length>0&&n.push(new q(` `)),n.push(t);let r=q.fromFragments(n);return r.overflow=t?`ignore`:void 0,r.end=``,r}function Rz(e,t,n,r,i){let a=e.compiled.get(t);if(!a||a.kind!==n)throw Error(`${i} references action "${t}" which must be ${r}, got ${a?`a ${a.kind} action`:`no such action`}`);return a}function zz(e,t,n){let r=e.compiled.get(t),i=r&&tz(r);if(!i||i.kind!==`set-option`&&i.kind!==`persist-option`&&i.kind!==`layout-op-option`)throw Error(`${n} references action "${t}" which must be a set-option, persist-option, or layout-op-option action ({ set, from }, { persist, from }, or { persist, insertSegmentFrom, anchor, relation }), got ${i?`a ${i.kind} action`:`no such action`}`);return i}function Bz(e,t,n,r,i,a,o,s,c=[]){let l=a.compiled.get(e),u=a.store,d=iz(u,`session.id`),f=`stateVar`in t?iz(u,t.stateVar):void 0,p=(e,n)=>{let r=t.options[e];return o({index:e,count:t.options.length},r,n,r===f)},m=i?r.kind===`led`?Pz(a):Nz(a):1/0,h=(r.kind===`led`?0:Mz(`✕`)+1)+c.reduce((e,t)=>e+Mz(t.glyph)+1,0),g=t.library&&{groups:t.library.groups,entries:t.options.map(t.library.entry)},_=g===void 0?t.options.map((e,t)=>p(t,e)):[],v=g===void 0?Iz(_.map(e=>e.cellLength),m,h):Ez(g.entries,g.groups,i),y=parseInt(iz(u,n.stateVar),10),b=e=>Math.max(0,v.findIndex(t=>t.some(t=>t.indices.includes(e)))),x=b(f===void 0?-1:t.options.indexOf(f)),S=Number.isInteger(y)?y<0?x:Math.min(y,v.length-1):0,C=v[S]??[],ee=e=>I([{verb:gn,args:[d,n.key,String(e)]}]),te=r.kind===`led`?[]:[{verb:gn,args:[d,...r.writes.flatMap(([e,t])=>[e,t])]}],ne=r.kind===`own`&&r.onPick?te:[],re=e=>I([...lz(l,e,e,u,d).effects,...ne]),ie=(e,n)=>sz(e,re(t.options[n])),ae=r.kind===`led`?[]:[oz(`✕`,I(te),!1,s)];ae.push(...c.map(({glyph:e,option:r})=>oz(e,I([...lz(l,r,r,u,d).effects,{verb:gn,args:[d,n.key,String(b(t.options.indexOf(r)))]}]),!1))),S>0&&ae.push(oz(`←`,ee(S-1),!1));let w=S<v.length-1?[oz(`→`,ee(S+1),!1)]:[];if(g===void 0){let e=C.flatMap(e=>e.indices);return[Lz([...ae,...e.map(e=>ie(_[e],e)),...w],i)]}let T=new G({bold:!0}),oe=v.length>1?` ${S+1}/${v.length}`:``,se=C.length===1?[new q(`${C[0].label}${oe}`,{style:T})]:[],ce=[Lz([...ae,...se,...w],i)];for(let e of C){C.length>1&&ce.push(Lz([new q(e.label,{style:T})],i));let n=Math.max(...e.indices.map(e=>Mz(t.options[e])));for(let r of e.indices){let e=t.options[r],a=g.entries[r].description,o=a===void 0?void 0:Hd(a),s=` `.repeat(n-Mz(e)+2),c=o===void 0?e:`${e}${s}${o}`;ce.push(Lz([ie(p(r,Oz(c,m)),r)],i))}}return ce}function Vz(e,t){return{picker:{fn:(n,r,i,a,o,...s)=>{vC(`picker "${n}"`,[`closeOnPick`,`paged`,`inBody`],s);let c=Rz(e,r,`set-int`,`an int action ({ set, int: true })`,`picker`);if(o===!0&&i===!0)throw Error(`{{ picker "${n}" … }} sets both closeOnPick and inBody; a picker in a body is closed by the body's ✕, so it has no close to fold into a pick`);let l=zz(e,n,`picker`);if(l.library!==void 0)throw Error(`{{ picker "${n}" … }} ranges a catalogue domain, which lays out as one row per member; a catalogue renders in a {{ menu }} body`);let u=jz(t,`{{ picker }}`);if(u.bg===void 0)throw Error(`{{ picker }} is not available while segments.${u.segName}'s own "bg:" is being evaluated — a picker is drawn on that background`);let[d]=Bz(n,l,{key:c.key,stateVar:c.stateVar},o===!0?{kind:`led`}:{kind:`own`,writes:[[c.key,`-1`]],onPick:i===!0},a===!0,e,Sz(u,ff(void 0),QR(e,`{{ picker }}`),l.paletteOf,t.drawnAt(),u.bg),gz(u.palette,u.bg,t.drawnAt()));return d},argTypes:[`string`,`string`,`bool`],arity:{kind:`variadic`},returnType:`T`}}}function Hz(e,t){let n=e.length,r=Math.max(e.indexOf(t),0);return e=>((r+e)%n+n)%n}function Uz(e,t,n,r,i){let a=Math.min(Math.floor((t-1)/2),i),o=n,s=0;for(;s<a;){let t=o+e(-(s+1))+1+e(s+1)+1;if(t>r)break;o=t,s+=1}return s}function Wz(e,t,n,r,i,a){if(!(`stateVar`in t))throw Error(`carousel references action "${e}", which inserts a segment and holds no current value to centre on — a carousel needs a { set, from } or { persist, from } action`);let o=n.store;if(!o.has(t.stateVar))throw Error(`carousel references action "${e}", whose key "${t.stateVar}" no variable reads back, so there is no current value to centre on — declare { kind: "state", key: "${t.stateVar}" } among the variables`);let s=n.compiled.get(e),c=iz(o,`session.id`),{options:l}=t,u=l.length;if(u===0)return Lz([],!0);let d=iz(o,t.stateVar),f=Hz(l,d),p=e=>l[f(e)],m=new Map,h=e=>{let t=m.get(e);if(t!==void 0)return t;let n=I(lz(s,p(e),p(e),o,c).effects);return m.set(e,n),n},g=e=>r({index:f(e),count:u},p(e),p(e),p(e)===d),_=new Map,v=e=>{let t=_.get(e);if(t!==void 0)return t;let n=sz(g(e),h(e));return _.set(e,n),n},y=a===void 0?v(0):sz(wz(QR(n,`{{ carousel }}`),t.paletteOf)({index:f(0),count:u},p(0),p(0),!1),I(lz(n.compiled.get(a),p(0),void 0,o,c).effects)),b=Uz(e=>v(e).cellLength,u,Mz(`◀`)+1+y.cellLength+1+Mz(`▶`),Pz(n),i),x=e=>Array.from({length:b},(t,n)=>v(e*(n+1)));return Lz([...x(-1).reverse(),oz(`◀`,h(-1),!1),y,oz(`▶`,h(1),!1),...x(1)],!0)}function Gz(e,t){return{carousel:{fn:(n,...r)=>{let[i,a,...o]=r;if(vC(`carousel "${n}"`,[`neighbours`,`centre`],o),i!==void 0&&!(Number.isInteger(i)&&i>=0))throw Error(`carousel "${n}": neighbours must be a whole number ≥ 0 (0 shows only ◀ CURRENT ▶), got ${String(i)}`);if(a!==void 0&&!(typeof a==`string`&&e.compiled.has(a)))throw Error(`carousel "${n}": centre must name a declared action, got ${JSON.stringify(a)}`);if(a!==void 0&&nz(e.compiled.get(a)))throw Error(`carousel "${n}": centre "${a}" writes a value the template binds, and the centre binds none — name an action that writes a fixed value, a cycle, or a do of them`);let s=i??1/0,c=zz(e,n,`carousel`),l=jz(t,`{{ carousel }}`);if(l.bg===void 0)throw Error(`{{ carousel }} is not available while segments.${l.segName}'s own "bg:" is being evaluated — a carousel is drawn on that background`);return Wz(n,c,e,Sz(l,ff(void 0),QR(e,`{{ carousel }}`),c.paletteOf,t.drawnAt(),l.bg),s,a)},argTypes:[`string`,`value`],arity:{kind:`variadic`},returnType:`T`}}}function Kz(e,t,n){let r=zz(e,t,n);if(!(`stateVar`in r))throw Error(`${n} references action "${t}", which inserts a segment and holds no current value — a ${n} needs a { set, from } or { persist, from } action`);if(r.paletteOf===void 0)throw Error(`${n} references action "${t}", whose options are not colour-valued — a swatch draws the palette an option puts in force, as the "themes", "placementThemes" and "styles" domains do`);return r}function qz(e,t,n){let r=Math.imul(e^e>>>16,73244475);return r=Math.imul(r^r>>>16,73244475),r^=r>>>16,(n+1+(r>>>0)%Math.max(t-1,1))%t}function Jz(e,t,n,r){let i=Kz(e,t,n),a=r??iz(e.store,i.stateVar);if(!i.options.includes(a))throw Error(`${n} "${t}": "${a}" is not one of its options, so it has no palette to draw`);return i.paletteOf(a,QR(e,`{{ ${n} }}`))}function Yz(e,t,n){return{swatch:{fn:(t,...n)=>{let[r,...i]=n;if(vC(`swatch "${t}"`,[`option`],i),r!==void 0&&typeof r!=`string`)throw Error(`swatch "${t}": option must be text, got ${JSON.stringify(r)}`);return yz(Jz(e,t,`swatch`,r))},argTypes:[`string`,`value`],arity:{kind:`variadic`},returnType:`T`},swatches:{fn:(r,i)=>{let a=Kz(e,r,`swatches`),o=Rz(e,i,`set-int`,`an int action ({ set, int: true })`,`swatches`),s=jz(t,`{{ swatches }}`);if(s.bg===void 0)throw Error(`{{ swatches }} is not available while segments.${s.segName}'s own "bg:" is being evaluated — a swatch row is drawn on that background`);let c=t.drawnAt(),{options:l}=a,u=l.length,[d]=Bz(r,a,{key:o.key,stateVar:o.stateVar},{kind:`led`},!0,e,Tz(s,QR(e,`{{ swatches }}`),a.paletteOf,c,s.bg),gz(s.palette,s.bg,c),u===0?[]:(()=>{let t=Hz(l,iz(e.store,a.stateVar));return[{glyph:`◀`,option:l[t(-1)]},{glyph:`?`,option:l[qz(n().getTime(),u,t(0))]},{glyph:`▶`,option:l[t(1)]}]})());return d},argTypes:[`string`,`string`],arity:{kind:`exact`},returnType:`T`}}}const Xz=[`~/code`,`main`,`opus`,`42%`,`5m`,`$1.20`];function Zz(e,t,n,r){let i=Kf(e,n,r),a=(t,n)=>({text:t,colour:n,ink:Pf(e,n,r)});return[[sf(t).map((n,i)=>{let a=Tf(e,n);return{text:Xz[i%Xz.length],colour:a,ink:t.shade.text(e,n.hue,a,r)}})],[[a(`▾ open`,i.state),a(`menu`,i.plane)],[a(`warn`,wf(e,`warning`)),a(`error`,wf(e,`error`))]]]}function Qz(e,t){let n=e.flatMap((e,t)=>e.map(({text:e,colour:n,ink:r},i)=>({gap:t>0&&i===0?` `:``,cell:new q(` ${e} `,{style:hz({tint:n,text:r})})}))),r=[],i=0;for(let{gap:e,cell:a}of n){if(i+=e.length+a.cellLength,i>t)break;e!==``&&r.push(new q(e)),r.push(a)}return r}function $z(e,t,n,r,i){let a=Zz(e,t,n,r).map(e=>Qz(e,i)),o=q.fromFragments(a.flatMap((e,t)=>t===0?e:[new q(`
199
+ `),...e]));return o.overflow=`ignore`,o.end=``,o}function eB(e,t){return{themePreview:{fn:(...n)=>{let[r,...i]=n;if(vC(`themePreview`,[`applyAction`],i),r!==void 0&&typeof r!=`string`)throw Error(`themePreview: applyAction must name a declared action, got ${JSON.stringify(r)}`);let{palette:a,decor:o}=QR(e,`{{ themePreview }}`);return $z(r===void 0?a:Jz(e,r,`themePreview`),o,{...jz(t,`{{ themePreview }}`).disclosure,depth:0},t.drawnAt(),Pz(e))},argTypes:[`value`],arity:{kind:`variadic`},returnType:`T`}}}const tB=e=>e.slice(e.lastIndexOf(`.`)+1),nB=(e,t)=>{let n=new q(tB(e));return n.truncate(t,{marker:`…`}),n.plain};function rB(e,t){let n=e.map(e=>e.map(({name:e})=>Mz(tB(e)))),r=e=>n.every(n=>n.reduce((t,n)=>t+Math.min(n,e)+2,0)<=t),i=Math.max(1,...n.flat());for(;i>1&&!r(i);)--i;return i}function iB(e,t,n,r){let i=rB(e,r),a=e.map(e=>{let a=[],o=0;for(let{name:s,address:c,palette:l}of e){let e=new q(` ${nB(s,i)} `,{style:hz(ap(l,{kind:`bar`,decor:t,address:c},n))});if(o+=e.cellLength,o>r)break;a.push(e)}return a}),o=q.fromFragments(a.flatMap((e,t)=>t===0?e:[new q(`
200
+ `),...e]));return o.overflow=`ignore`,o.end=``,o}function aB(e,t){return{layoutPreview:{fn:()=>iB(e.layout(),QR(e,`{{ layoutPreview }}`).decor,t.drawnAt(),Pz(e)),argTypes:[],arity:{kind:`exact`},returnType:`T`}}}function oB(e,t,n,r){let i=jz(r.activeSegment,`{{ menu }}`),a=r.action,o=sT(i.placementId,e,n.key),s=uT(o),c=oT(e),l=iz(a.store,o)===c,u=iz(a.store,`session.id`),d=l?L:c,f=oz(qn(`{{ menu "${e}" }}`,t,2,+!!l),I([{verb:gn,args:[u,o,d,s,`0`]}]),!1);return i.drops.push(...l?(()=>{let t=r.activeSegment.drawnAt(),c=Kf(i.palette,i.disclosure,t).plane,l=zz(a,e,`menu`);return Bz(e,l,{key:s,stateVar:s},{kind:`own`,writes:[[o,L],[s,`0`]],onPick:n.closeOnPick},n.paged,a,Sz(i,n.distribution,QR(a,`{{ menu }}`),l.paletteOf,t,c),gz(i.palette,c,t))})():[]),f}const sB=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function cB(e,t){let n=t[t.length-1],r=sB(n)?n:void 0,i=r===void 0?t:t.slice(0,-1),a=i.findIndex(e=>typeof e!=`string`);if(a!==-1)throw Error(`{{ menu "${e}" }} display #${a+1} is not text (${JSON.stringify(i[a])}) — a menu binds its trigger text, then an optional trailing (dict …) of options`);return{displays:i,options:mT(r??{})}}function lB(e){return{menu:{fn:(t,...n)=>{let{displays:r,options:i}=cB(t,n);return oB(t,r,i,e)},argTypes:[`string`,`value`],arity:{kind:`variadic`},returnType:`T`}}}function uB(e){let{value:t,max:n,width:r,filled:i,empty:a,colourAt:o}=e,s=dB(t,n,r),c=[];for(let e=0;e<r;e++){let t=e<s,l=t&&o!==void 0?o(e*n/r):void 0;c.push(new q(t?i:a,{style:l===void 0?void 0:new G({color:l})}))}let l=q.fromFragments(c);return l.end=``,l.overflow=`ignore`,l}function dB(e,t,n){return!Number.isFinite(e)||!Number.isFinite(t)||t<=0?0:Math.min(n,Math.max(0,Math.round(e/t*n)))}function fB(e){let t={fn:(()=>{let t=jz(e,`{{ bgOf }}`);if(t.bg===void 0)throw Error(`{{ bgOf }} is not available while segments.${t.segName}'s own "bg:" is being evaluated — the background is what that template computes. Reach for a palette color there instead, e.g. bg: '{{ darken (color "surface") 1 }}'.`);return t.bg.hex}),argTypes:[],arity:{kind:`exact`},returnType:`string`},n={fn:(()=>jz(e,`{{ tint }}`).tint.hex),argTypes:[],arity:{kind:`exact`},returnType:`string`},r={fn:((t,n)=>{let{palette:r}=jz(e,`{{ keptOn }}`),i=Us(r,t),a=Us(r,n),o=Fo(ec(i,U.TRUECOLOR),ec(a,U.TRUECOLOR)),s=Math.min(Nf,Math.max(o,3));return($s(i,e.drawnAt(),(e,t)=>Fo(e,t(a))>=s)??i).hex}),argTypes:[`string`,`string`],arity:{kind:`exact`},returnType:`string`},i=iC(()=>jz(e,`{{ color }} / {{ ramp }} / {{ gauge }}`).palette),a={fn:((e,t,n,r,a,o,...s)=>{let c=o===void 0?void 0:[o,...pB(s)];return uB({value:e,max:t,width:n,filled:r,empty:a,colourAt:c===void 0?void 0:e=>String(i.ramp.fn(e,...c))})}),argTypes:[`float`,`float`,`int`,`string`,`string`,`string`],arity:{kind:`variadic`},returnType:`T`};return{...i,bgOf:t,tint:n,keptOn:r,gauge:a}}function pB(e){return e.flatMap(e=>{let t=e.indexOf(`:`),n=t<0?NaN:Number(e.slice(0,t));if(!Number.isFinite(n))throw Error(`{{ gauge }} stop "${e}" must be "<position>:<colour>", e.g. "80:error" or "80:#ff0000"`);return[n,e.slice(t+1)]})}function mB(e){let t=[],n=[];for(let r of e){if(!r.contains(`
201
201
  `)){n.push(r);continue}let e=r.split(`
202
- `);n.push(e[0]);for(let r=1;r<e.length;r++)t.push(n),n=[e[r]]}return t.push(n),t}function pB(e){let t=new Map;return e.map(e=>{let n=`${e.place}.${e.band}`,r=t.get(n)??0;return t.set(n,r+1),{line:e,row:`${n}#${r}`}})}function mB(e,t){let n=[],r=[],i;for(let a of t)(a.band===`own`?n:r).push(a),i??=a.cells.find(t=>t.placement.id===e)?.placement.ground;return{drawing:i===void 0?null:{own:r.length===0?n:[],ground:i},deeper:r}}function hB(e){return{...e,cells:e.cells.map(HR)}}function gB(e,t){let n=t.flatMap(e=>e.filter(e=>e.place===`above`)),r=t.map(e=>e.filter(e=>e.place===`flow`));return[...n,..._B(e,r)]}function _B(e,t){switch(e){case`vertical`:return t.flatMap(e=>e);case`horizontal`:return t.reduce((e,t)=>Math.max(e,t.length),0)===0?[]:[{cells:t.flatMap(e=>e[0]?.cells??[]),band:`own`,place:`flow`},...t.flatMap(e=>e.slice(1))]}}function vB(e,t){let n=(e,r)=>t(e)?e.kind===`segment`?[{cells:[{name:e.name,address:r,settings:e.settings}],band:`own`,place:`flow`}]:gB(e.direction,e.children.map((t,i)=>n(t,[...r,yB(e,i)]))):[];return n(e,[]).map(e=>[...e.cells])}function yB(e,t){return{index:t,count:e.children.length,distribution:e.distribution,axis:oh[e.direction]}}const bB={compile(e,t){return{kind:`container`,direction:e.direction,when:t.when,distribution:ff(e.distribution),children:e.children.map((e,n)=>t.compileChild(e,fh(t.path,n)))}},render(e,t){return t.gate.kind===`failed`&&t.gate.report(),gB(e.direction,e.children.map((n,r)=>t.renderChild(n,t.gate.kind===`shown`,yB(e,r))))}},xB={drop:e=>e.place,above:()=>`above`},SB={drop:(e,t)=>({lead:t(),stays:e}),above:e=>({lead:e.slice(0,1).flatMap(e=>e.cells),stays:e.slice(1)})},CB={compile(e,t){return{kind:`segment`,when:t.when,name:e.name,id:sh(e),settings:t.placementSettings(e),...e.opens!==void 0&&{opens:{open:t.parse(Xn(e.opens.ref),`opens`),body:t.compileChild(e.opens.body,ph(t.path)),key:e.opens.ref.key,placement:e.opens.placement}},...e.lead!==void 0&&{lead:t.parse(e.lead,`lead`)},...e.trail!==void 0&&{trail:t.parse(e.trail,`trail`)}}},render:(e,t)=>t.placed(e.id,wB(e,t))};function wB(e,t){let n=t.lookupSegment(e.name);if(!n)throw Error(`Layout segment "${e.name}" has no matching segment`);let{seg:r,compiled:i}=n;if(t.gate.kind===`hidden`)return[];let a=EC(t.scope,e.settings);if(t.gate.kind===`failed`)return TB(e,a,t,t.gate.message);try{if(!FR(i.when,a))return[];let n=Zm(e.settings.theme,t.palette),o={id:e.id,effect:e.settings.effect,ground:pD(n)},s=e.opens!==void 0&&FR(e.opens.open,t.scope),{styles:c,fragments:l,lead:u,trail:d,drops:f,open:p}=t.evaluateSegment(e,a,n,t.region,{bg:i.bg,fg:i.fg,body:i.template,lead:e.lead,trail:e.trail},s),m=p?c.trigger:c.closed,h={width:r.width??`auto`,justify:r.justify??`left`,truncate:r.truncate??`right`,baseStyle:m,padding:t.padding,placement:o},g=e.opens,_=g===void 0?[]:t.renderBody(g.body,s,c.disclosure).map(e=>({...e,place:xB[g.placement](e)})),v=fB(qR(l,m)).map((e,t)=>({cells:GR(e,{...h,lead:t===0?qR(u,m):[],trail:t===0?qR(d,m):[]}),band:`own`,place:`flow`})),y=f.map(e=>({cells:GR(qR([e],c.band),{...h,baseStyle:c.band}),band:`deeper`,place:`flow`})),b=(e,t,n)=>GR(qR([e],t),{...h,width:`auto`,baseStyle:t,padding:n}),x=_.findIndex(e=>e.band===`own`),{lead:S,stays:C}=g!==void 0&&x!==-1?SB[g.placement](v,()=>b(t.closeDisclosure(g.key),c.close,t.padding)):{lead:[],stays:v},ee=S.flatMap(e=>b(new q(` `.repeat(VR(e).reduce((e,t)=>e+t.cellLength,0))),c.trigger,0)),te=(e,t)=>e.band===`own`?t===x?S:ee:[],ne=_.map((e,t)=>({cells:[...te(e,t),...e.cells],band:`deeper`,place:e.place})),re=[...C,...y];return t.perSegmentSink!==void 0&&t.perSegmentSink.set(e.id,[...re.flatMap(e=>e.cells),..._.flatMap(te)].flatMap(VR)),[...re,...ne]}catch(n){return TB(e,a,t,n.message??String(n))}}function TB(e,t,n,r){n.onSegmentError?.(e.id,r);let i=r.replace(/\s*\n\s*/g,` `);return[{cells:GR([new q(`⚠ ${e.id}: ${i}`,{end:``})],{width:`auto`,justify:`left`,truncate:`right`,padding:0,placement:{id:e.id,effect:`bar`,ground:pD(n.palette)},lead:EB(e.lead,e,t,n),trail:EB(e.trail,e,t,n)}),band:`own`,place:`flow`}]}function EB(e,t,n,r){if(e===void 0)return[];try{return r.evaluateSegment(t,n,r.palette,r.region,{bg:void 0,fg:void 0,body:e,lead:void 0,trail:void 0},!1).fragments}catch(e){return r.onSegmentError?.(t.id,e.message??String(e)),[]}}const DB={container:bB,segment:CB};function OB(e){return DB[e]}function kB(e){if(`ttl`in e)return{kind:`ttl`,durationMs:xw(e.ttl)};if(`watch_file`in e)return{kind:`watch_file`,path:e.watch_file};if(`depends_on`in e)return{kind:`depends_on`,varNames:e.depends_on};if(`key`in e)return{kind:`key`,template:e.key};if(`never`in e)return{kind:`never`};throw Error(`Unknown CacheDecl discriminator — loader invariant violated: ${JSON.stringify(e)}`)}function AB(e,t){switch(_h(e)){case`json`:return{kind:`json`,default:t};case`regex`:return{kind:`regex`,regex:new RegExp(e.regex),default:t};case`text`:return{kind:`text`,default:t}}}function jB(e,t,n,r){switch(n.kind){case`literal`:e.declareLiteral(t,n.value);break;case`dropped`:e.declareFailedDocument(t,n.reason);break;case`input`:e.declareInput(t,n.path,n.type??`string`,n.default);break;case`env`:e.declareEnv(t,n.name,n.default);break;case`file`:e.declareFile(t,n.path,{readMode:n.readMode,cache:kB(n.cache),parse:AB(n.parse,n.default)});break;case`shell`:e.declareShell(t,n.command,{cwd:r,cache:kB(n.cache),parse:AB(n.parse,n.default)});break;case`template`:e.declareTemplate(t,n.template,{varDefault:n.default});break;case`time`:e.declareTime(t,{format:n.layout,varDefault:n.default});break;case`git`:e.declareGit(t,{field:n.field,cwd:r,varDefault:n.default});break;case`state`:e.declareState(t,{key:n.key,...n.default!==void 0&&{varDefault:n.default}});break}}function MB(e,t){let n=f_.EMPTY;for(let[r,i]of Object.entries(t))try{n=e.parse(`{{ define "${r}" }}${i}{{ end }}`,n).defines()}catch(e){throw Error(`Template parse error in helpers.${r}: ${e.message}`,{cause:e})}return n}const NB=(e,t,n,r,i)=>{let a=AF(t,kF(n,e.themeDefaults));return{variation:of[r??Up(void 0,null,a.variation)],shade:rf[i??Kp(void 0,null,a.shade)]}};function PB(e,t,n){let r=n.cwd,i={store:t.variableStore,compiled:new Map,chromeCols:Tm({endcaps:`powerline`,charset:Rp}),width:80,padding:1,seamCols:Em({endcaps:`powerline`,charset:Rp}),layout:()=>[],look:void 0},a=Dz(t.drawnAt),o={action:i,activeSegment:a},s=Object.keys(e.styles),c=qh(e.presets),l=$k(e),u=CC({extraFuncs:{...uz(i),...zz(i,a),...Uz(i,a),...Qz(i,a),...qz(i,a,t.now),...rB(i,a),...sB(o),...uB(a),styles:{fn:()=>s,argTypes:[],arity:{kind:`exact`}},presets:{fn:()=>c,argTypes:[],arity:{kind:`exact`}}},clock:t.now,drawnAt:t.drawnAt}),d=MB(u,e.helpers),f=e=>u.parse(e,d),p=new Map,m=e=>{let t=p.get(e);if(t!==void 0)return t;let n=f(e);return p.set(e,n),n},h=new Map;for(let[t,n]of va)n in e.variables&&h.set(t,n);for(let[t,n]of Object.entries(e.variables))n.kind===`state`&&!h.has(n.key)&&h.set(n.key,t);for(let[t,n]of Object.entries(e.segments))if(n.vars)for(let[e,r]of Object.entries(n.vars))r.kind===`state`&&!h.has(r.key)&&h.set(r.key,`${t}.${e}`);i.compiled=ZR(f,e.actions,h,l);let g=[];for(let[n,i]of Object.entries(e.variables))try{jB(t,n,i,r)}catch(e){g.push(`Variable "${n}": ${e.message??String(e)}`)}for(let[n,i]of Object.entries(e.segments))if(i.vars)for(let[e,a]of Object.entries(i.vars))try{jB(t,`${n}.${e}`,a,r)}catch(t){g.push(`Variable "${n}.${e}": ${t.message??String(t)}`)}let _=Object.create(null);for(let[t,n]of Object.entries(e.segments)){let e=(e,n,r=f)=>{try{return r(e)}catch(e){throw Error(`Template parse error in segments.${t}.${n}: ${e.message}`,{cause:e})}};_[t]={when:n.when===void 0?void 0:e(n.when,`when`,m),template:e(n.template,`template`),bg:n.bg===void 0?void 0:e(n.bg,`bg`),fg:n.fg===void 0?void 0:e(n.fg,`fg`)}}let v=(e,t,n)=>{try{return m(e)}catch(e){throw Error(`Template parse error in ${t}.${n}: ${e.message}`,{cause:e})}},y=t.variableStore,b=t=>{let n=wh(e.segments[t.name]),r=Object.create(null);for(let[e,i]of Object.entries(n))Object.defineProperty(r,e,{enumerable:!0,get:()=>Ah(t,e,i,e=>String(y.read(e.variable)))});return Object.freeze(r)},x=(e,t)=>{let n={path:t,when:e.when===void 0?void 0:v(e.when,t,`when`),parse:(e,n)=>v(e,t,n),compileChild:x,placementSettings:b};return OB(e.kind).compile(e,n)},S=new Map;for(let t of c){let{node:n,path:r}=Xh(e,t);S.set(t,x(n,r))}let C=new Map(hp.map(e=>[e,new Map])),ee=[[`globals`,e.globals],...Object.entries(e.presets).map(([e,t])=>[`presets.${e}.globals`,t.globals??{}])];for(let[e,t]of ee)for(let n of hp){let r=t[n];if(!gp(r))continue;let i=`${e}.${n}`,a=C.get(n),o=a.get(r);a.set(r,o===void 0?{where:i,template:FB(f,i,r)}:{where:`${o.where}, ${i}`,template:o.template})}return{segments:_,roots:S,activeSegment:a,menuRuntime:o,globalExpressions:C,loadWarnings:g}}function FB(e,t,n){try{return e(n)}catch(e){throw Error(`${t} is not a valid template: ${e instanceof Error?e.message:String(e)}`)}}function IB(e,t,n){let r=e.globalExpressions.get(t).get(n);if(r===void 0)throw Error(`the ${t} rule ${JSON.stringify(n)} reached the render but no compiled template exists — registerDslConfig and the resolution disagree about isExpression`);return r}function LB(e,t,n,r){try{return t.template.evaluate(n).map(e=>e.plain).join(``)}catch(n){return r({kind:`rule`,slot:e,message:Tp(t.where,e,`the rule failed — ${n instanceof Error?n.message:String(n)}`)}),wp[e]}}function RB(e,t){return e.kind===`decided`?e.name:wp[t]}function zB(e){return e.kind===`container`?e.children.flatMap(zB):[...e.name.startsWith(`edit.`)?[]:[e.id],...e.opens===void 0?[]:zB(e.opens.body)]}function BB(e,t,n,r,i,a,o,s,c){let{perSegmentSink:l,onSegmentError:u,onRenderWarning:d}=s??{},f=e=>d?.(e),p=new Set;r.renderAt(a),r.drawAt(Bp(o.colorCompatibility));let{preset:m=Gh}=c??{},h=Zh(e,m),g=c?.style??xp(`none`,e.styles),_=c?.theme??rh(void 0,null,h.palette),v=NB(e,h,_,c?.variation,c?.shade),y=c?.effect??Ap(void 0,null,h.effect),b=(e,t,n)=>({...i,term:{cols:o.width},theme:{effective:e},style:{effective:t},effect:{effective:n}});r.applyInput(b(RB(_,`palette`),RB(g,`style`),RB(y,`effect`))),t.menuRuntime.action.chromeCols=Tm(o),t.menuRuntime.action.padding=o.padding,t.menuRuntime.action.width=o.width,t.menuRuntime.action.seamCols=Em(o);let x=wC(n),S=vp(_,e=>{let n=IB(t,`palette`,e);return nh(LB(`palette`,n,x,f),n.where,e=>f({kind:`rule`,slot:`palette`,message:e}))}),C=vp(g,n=>xp(LB(`style`,IB(t,`style`,n),x,f),e.styles)),ee=vp(y,e=>kp(LB(`effect`,IB(t,`effect`,e),x,f)));(S!==_||C!==g||ee!==y)&&r.applyInput(b(S.name,C.name,ee.name));let te=S.value,ne=$m(te,C.value);t.menuRuntime.action.look={basePalette:te,palette:ne,decor:v};let re=(c?.effects??new hm(``)).motion(ee.value,a,{transitions:c?.transitions??nm(void 0,null,h.transitions),source:{config:t,preset:m,revision:r.stateRevision(),width:o.width},returned:mB,hold:hB});l?.clear();let ie=n=>{let r=e.segments[n],i=t.segments[n];return r!==void 0&&i!==void 0?{seg:r,compiled:i}:void 0},ae=(e,n,i,a,o,s)=>{try{let c=r.drawnAt(),{tint:l,text:u,disclosure:d}=ap(i,a,c),f=Oz(t.activeSegment,e.name,e.id,i,d,l,u),m=hD(f,c,o.bg,o.fg,n),h=()=>Kf(i,d,c);s&&(f.bg=h().state);let g=o.body.evaluate(n),_=f.drops.length>0||s;if(_){let e=h();f.bg=e.state;for(let t of e.shortfalls)p.add(t)}let v=o.lead?.evaluate(n)??[],y=o.trail?.evaluate(n)??[];return{styles:{closed:m,get trigger(){return fz(i,h().state,c)},get band(){return fz(i,h().plane,c)},get close(){return hz(i,h().state,c)},disclosure:d},fragments:g,lead:v,trail:y,drops:f.drops,open:_}}finally{t.activeSegment.current=null}},w=(e,t,r)=>{let i=t?RR(e.when,x):IR,a=i.kind===`failed`?{...i,report:()=>{let t=`when over ${zB(e).join(`, `)||`no placement`}`;f({kind:`when`,where:t,error:i.message,message:`${t}: ${i.message} — what it gates is hidden`})}}:i,s={scope:x,palette:ne,gate:a,padding:o.padding,region:r,perSegmentSink:l,onSegmentError:u,evaluateSegment:ae,lookupSegment:ie,renderChild:(e,t,n)=>w(e,t,rp(r,n)),renderBody:(e,t,n)=>w(e,a.kind===`shown`&&t,ip(n)),closeDisclosure:e=>dz(n,e),placed:re.placed};return OB(e.kind).render(e,s)},T=t.roots.get(m);if(T===void 0)throw Error(`Preset "${m}" has no compiled layout — registerDslConfig compiles one per declared preset and effectivePresetName collapses unknown names to "${Gh}"; a miss here is merge/policy drift (have: ${[...t.roots.keys()].join(`, `)})`);let oe=e=>{let n=RR(e.when,x);if(e.kind===`container`)return n.kind===`shown`;if(uA(e.name)===void 0)return!1;if(n.kind!==`shown`)return n.kind===`failed`;try{return FR(t.segments[e.name].when,EC(x,e.settings))}catch{return!0}};t.menuRuntime.action.layout=()=>vB(T,oe).map(e=>e.flatMap(({name:e,address:t,settings:n})=>{let r=uA(e);return r===void 0?[]:[{name:r,address:t,palette:Zm(n.theme,ne)}]}));let se=pB(w(T,!0,np(v))).map(({line:e,row:t})=>{let n=KR(e.cells,o);return Dm(n.map(e=>e.owner),o,re.row(t,n))}).join(`
203
- `);re.drawn();for(let e of p)f({kind:`band-floor`,message:e});return se}function*VB(e){yield*Object.entries(e.variables??{});for(let[t,n]of Object.entries(e.segments??{}))for(let[e,r]of Object.entries(n.vars??{}))yield[`${t}.${e}`,r]}function*HB(e){for(let t of Object.values(e.segments))for(let e of[t.template,t.bg,t.fg,t.when])e!==void 0&&(yield e);for(let t of qh(e.presets)){for(let n of dh(Xh(e,t).node))n.when!==void 0&&(yield n.when);let n=Zh(e,t);for(let e of hp){let t=n[e];gp(t)&&(yield t)}}for(let[,t]of VB(e))t.kind===`template`&&(yield t.template),yh(t)&&t.cache&&`key`in t.cache&&(yield t.cache.key);for(let t of Object.values(e.actions))`copy`in t&&(yield t.copy),`open`in t&&(yield t.open),`preset`in t&&t.preset===`delete`&&(yield t.name)}function UB(e,t){return e===t||t.startsWith(`${e}.`)||e.startsWith(`${t}.`)}function WB(e,t){let n=new Set,r=new Set,i=new Set;for(let e of HB(t)){for(let r of vg(e,t.helpers).keys())n.add(r);for(let{name:n}of Sg(e,t.helpers))r.add(n);for(let n of Cg(e,t.helpers))i.add(n)}for(let[,e]of VB(t))if(yh(e)&&e.cache&&`depends_on`in e.cache)for(let t of e.cache.depends_on)n.add(t);let a=new Set(r);for(let e of r){let n=t.actions[e];if(n!==void 0&&`do`in n)for(let e of n.do)a.add(e)}let o=new Set,s=new Set;for(let e of a){let n=t.actions[e];if(n!==void 0&&(`set`in n&&o.add(n.set),`insertSegment`in n&&s.add(n.insertSegment),`insertSegmentFrom`in n&&Array.isArray(n.insertSegmentFrom)))for(let e of n.insertSegmentFrom)s.add(e)}for(let e of qh(t.presets))for(let n of dh(Xh(t,e).node))n.kind===`segment`&&s.add(n.name);let c=(e,t)=>[...n].some(t=>UB(t,e))||t.kind===`state`&&o.has(t.key),l=e=>[...e].filter(e=>!rT(e)),u=(e,t,n)=>l(t).filter(e=>!n(e)).map(t=>({kind:e,name:t})),d=new Map(VB(e));return[...u(`variable`,d.keys(),e=>c(e,d.get(e))),...u(`action`,Object.keys(e.actions??{}),e=>a.has(e)),...u(`helper`,Object.keys(e.helpers??{}),e=>i.has(e)),...u(`segment`,Object.keys(e.segments??{}),e=>s.has(e))]}var GB=class{kind=`box`;cell;lastChangedAt;constructor(e,t,n){this.name=e,this.type=t,ZB(e,t,n,`initial value`),this.cell=Mg.observable.box(n,{deep:!1}),this.lastChangedAt=Date.now()}read(){return this.cell.get()}set(e){ZB(this.name,this.type,e,`set value`),!Object.is(this.cell.get(),e)&&(this.cell.set(e),this.lastChangedAt=Date.now())}lastUpdatedMs(){return this.lastChangedAt}},KB=class{kind=`computed`;cell;constructor(e,t,n){this.name=e,this.type=t,this.cell=(0,Mg.computed)(()=>{let e=n();return ZB(this.name,this.type,e,`computed result`),e},{keepAlive:!0})}read(){return this.cell.get()}lastUpdatedMs(){return null}},qB=class{kind=`document`;cell;lastChangedAt;constructor(e,t){this.name=e,this.cell=Mg.observable.box(XB(t),{deep:!1}),this.lastChangedAt=Date.now()}read(){return this.cell.get()}set(e){let t=XB(e);YB(this.cell.get(),t)||(this.cell.set(t),this.lastChangedAt=Date.now())}lastUpdatedMs(){return this.lastChangedAt}};function JB(e){return JSON.stringify(e)}function YB(e,t){return JB(e)===JB(t)}function XB(e){return e.kind===`ok`?{kind:`ok`,value:Ng(e.value)}:e}function ZB(e,t,n,r){let i=Pg(n);if(i!==t)throw TypeError(`Variable "${e}": ${r} type ${i} does not match declared type ${t}`)}var QB=class{nodes=new Map;defineBox(e,t,n){this.assertNotDefined(e),this.nodes.set(e,new GB(e,t,n))}defineDocument(e,t){this.assertNotDefined(e),this.nodes.set(e,new qB(e,t))}defineComputed(e,t,n){this.assertNotDefined(e);let r=e=>this.read(e);this.nodes.set(e,new KB(e,t,()=>n(r)))}read(e){return this.requireVar(e).read()}readDocument(e){let t=this.requireNode(e);if(t.kind!==`document`)throw TypeError(`Variable "${e}" is a ${t.kind}, not a document`);return t.read()}setDocument(e,t){let n=this.requireNode(e);if(n.kind!==`document`)throw TypeError(`Variable "${e}" is a ${n.kind}, not a document (use defineDocument to create one)`);(0,Mg.runInAction)(()=>n.set(t))}setBox(e,t){let n=this.requireNode(e);if(n.kind!==`box`)throw TypeError(`Variable "${e}" is a ${n.kind}, not a box (use defineBox to create a settable variable)`);(0,Mg.runInAction)(()=>n.set(t))}runInAction(e){(0,Mg.runInAction)(e)}has(e){return this.nodes.has(e)}getType(e){return this.requireVar(e).type}getKind(e){return this.requireNode(e).kind}changeKey(e){let t=this.requireNode(e);if(t.kind===`document`)return JB(t.read());try{return String(t.read())}catch(e){return`failed:${e instanceof Error?e.message:String(e)}`}}getNode(e){let t=this.requireNode(e);return t.kind===`document`?{name:t.name,kind:t.kind,read:()=>t.read(),lastUpdatedMs:()=>t.lastUpdatedMs()}:{name:t.name,type:t.type,kind:t.kind,read:()=>t.read(),lastUpdatedMs:()=>t.lastUpdatedMs()}}names(){return[...this.nodes.keys()]}requireNode(e){let t=this.nodes.get(e);if(!t)throw ReferenceError(`Unknown variable "${e}"`);return t}requireVar(e){let t=this.requireNode(e);if(t.kind===`document`)throw TypeError(`Variable "${e}" is a document; read its fields by path (.${e}.<field>)`);return t}assertNotDefined(e){if(this.nodes.has(e))throw Error(`Variable "${e}" is already declared`)}};function $B(e,{plugins:t,config:n}){let{checkout:r,loaded:i,dropped:a,unreached:o}=t,s=r===null?`-`:`${r.git?`git`:`dir`}:${r.root}`,c=e=>{let t=gP(e),r=t===void 0?void 0:n.variables[vP(t)];return r?.kind===`file`?r.path:`none`};return`config load ${e.join(` < `)||`<default>`}: plugins loaded=${i.length} dropped=${a.length} unplaced=${o.length} checkout=${s}`+i.map(e=>` +${e} data=${c(e)}`).join(``)+a.map(e=>` -${e.path} (${e.reason})`).join(``)+o.map(e=>` ~${e.path} (${e.reason})`).join(``)}function eV(e,t,n){return e+`\0`+t+`\0`+(n??``)}function tV(e,t){return new Set(qh(e.presets).filter(n=>Xh(e,n).path===`root`?t.root!==void 0:t.presets?.[n]?.root!==void 0))}function nV(e,t){let n=new Map,{roots:r,loaded:i,dropped:a,unreached:o}=e.state.plugins;for(let t of[...HP(e.projectDir,e.cwd,e.configFile),...r,...i,...[...a,...o].map(e=>e.path)]){let{dir:e,name:r}=Og(t),i=n.has(e)?n.get(e):new Set;i?.add(r),n.set(e,i)}for(let e of r){let{dir:t,name:r,leaf:i}=Og(l.join(e,`_`));i&&r===`_`&&n.set(t,null)}return{files:t,dirs:[...n.entries()].sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>t===null?{path:e}:{path:e,filenames:[...t].sort()})}}function rV(e){return e.filter(Boolean).join(`
204
- `)||null}function iV(e,t,n,r,i=()=>{}){let{layers:a,config:o,installed:s}=nF(t.layers,TF,{entered:i,warned:e=>n.push(...e)},{projectDir:t.projectDir,cwd:e});i(a.length===1?a[0].path:null);let c=a.at(-1)?.config??TF,l=a.find(e=>e.path===t.home)?.raw??{},u=new QB,d=new Hw(u,o.globals.default_empty_value??``,r.gitService,r.sessionState),f;try{f=PB(o,d,{cwd:e}),n.push(...f.loadWarnings),dL(o),NA(o)}catch(e){throw d.dispose(),e}return{config:o,store:u,registry:d,compiled:f,neededInputPaths:_I(o),lastRenderCellsBySegment:new Map,authoredRoots:tV(c,l),fileHeldSettings:ZI(l),unused:[...new Map(a.flatMap(e=>WB(e.raw,c)).map(e=>[`${e.kind}:${e.name}`,e])).values()],plugins:{checkout:s.checkout,roots:s.roots,loaded:[...s.rendering.values()],dropped:[...s.dropped,...a.flatMap(e=>e.plugins.dropped)],unreached:s.unreached,reached:s.reached,rendering:s.rendering}}}function aV(e,t,n,r){let i=WP(e,t,n),a={layers:i.kind===`chain`?i.layers:[],home:i.home,projectDir:e},o=[YP(e,t),qP(i)],s,c=null;try{s=iV(t,a,o,r,e=>{c=e})}catch(e){return e instanceof Jw&&o.push(...e.warnings),{layers:a.layers,home:a.home,failedFile:c,warning:rV(o),state:null,error:e instanceof Jw||e instanceof Error?e.message:String(e)}}return{layers:a.layers,home:a.home,warning:rV(o),state:s,error:null}}function oV(e,t,n){return iV(e,{layers:[],home:``,projectDir:t},[],n)}var sV=class{entries=new Map;deps;maxEntries;observers;constructor(e,t={}){this.deps=e,this.maxEntries=t.maxEntries??256,this.observers=t.observers??{}}getOrCreate(e,t,n){let r=eV(e,t,n),i=this.entries.get(r);if(i)return this.entries.delete(r),this.entries.set(r,i),i;let a=aV(e,t,n,this.deps);a.state!==null&&k(`info`,$B(a.layers,a.state));let o={projectDir:e,cwd:t,configFile:n,configLayers:[],configHome:``,failedFile:null,lastError:a.error,lastWarning:a.warning,state:a.state??oV(t,e,this.deps),watcher:null,watcherKey:null};if(this.entries.set(r,o),this.entries.size>this.maxEntries){let e=this.entries.entries().next().value;if(e!==void 0){let[t,n]=e;n.state.registry.dispose(),n.watcher?.release(),this.entries.delete(t)}}return this.refreshWatcher(o,a),this.observers.onReload?.(o),o}reload(e,t,n){this.reloadInto(this.getOrCreate(e,t,n))}reloadInto(e){let t=aV(e.projectDir,e.cwd,e.configFile,this.deps);e.lastWarning=t.warning,e.lastError=t.error,t.state!==null&&(k(`info`,$B(t.layers,t.state)),e.state.registry.dispose(),e.state=t.state),this.refreshWatcher(e,t),this.observers.onReload?.(e)}refreshWatcher(e,t){e.configLayers=t.layers,e.configHome=t.home,e.failedFile=t.error===null?null:t.failedFile;let n=nV(e,t.layers),r=`config:${e.projectDir}:${e.cwd}:${e.configFile??``}:${JSON.stringify(n)}`;e.watcher!==null&&e.watcherKey===r||(e.watcher?.release(),e.watcherKey=r,e.watcher=this.deps.watchers.acquire(r,n,()=>this.onConfigChanged(e)))}onConfigChanged(e){k(`info`,`config change detected for entry projectDir=${e.projectDir} cwd=${e.cwd}`),this.reloadInto(e)}get size(){return this.entries.size}firstState(){return this.entries.values().next().value?.state??null}};const cV=16384;var lV=class{startedAt=new Date;requestsTotal=0;requestsErrored=0;requestsTimedOut=0;inFlight=0;watchersOpened=0;watchersClosed=0;watchersEvicted=0;subprocessTotal=0;subprocessInFlight=0;subprocessCount=new Map;subprocessHistogram=new Map;subprocessHistogramRotator=new Map;rollingTimestamps=[];rollingHead=0;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)}};recordRollingNow(){let e=Date.now();if(this.rollingTimestamps.length<cV){this.rollingTimestamps.push(e);return}this.rollingTimestamps[this.rollingHead]=e,this.rollingHead=(this.rollingHead+1)%cV}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=Date.now()-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,p50DurationMs:r,p99DurationMs:i}}snapshot(e){let t=process.memoryUsage();return{pid:process.pid,version:wt,protocolVersion:3,startedAt:this.startedAt.toISOString(),uptimeSec:Math.floor((Date.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},gitCache:e.gitCache,usageCache:e.usageCache,renderCache:{size:e.renderCacheSize},effectCache:e.effectCache,watchers:{active:e.watchersActive,opened:this.watchersOpened,closed:this.watchersClosed,evicted:this.watchersEvicted},subprocesses:this.snapshotSubprocesses(),nextRestartReason:e.nextRestartReason??null,handlerProbes:e.handlerProbes}}};function uV(e,t,n){let r=(r,i,a)=>{let o=i.filter(t).map(t=>({key:t,before:e.get(r,t)}));a();for(let{key:t,before:i}of o)n(r,t,i,e.get(r,t))};return{get:(t,n)=>e.get(t,n),revision:t=>e.revision(t),set:(t,n,i)=>r(t,[n],()=>e.set(t,n,i)),setBatch:(t,n)=>r(t,n.map(e=>e.key),()=>e.setBatch(t,n)),clear:(t,n)=>r(t,[n],()=>e.clear(t,n))}}const dV={load:()=>({}),save:()=>{},flush:()=>{}};var fV=class{sessions;storage;head=0;atom=(0,Mg.createAtom)(`SessionState`);constructor(e=dV,t=256){this.maxSessions=t,this.storage=e,this.sessions=new Map,this.hydrateFromStorage()}useStorage(e){this.storage=e,this.hydrateFromStorage()}hydrateFromStorage(){this.sessions=new Map(Object.entries(this.storage.load()).map(([e,t])=>[e,{values:new Map(Object.entries(t)),revision:++this.head}])),this.evictOldest(),this.persist()}get(e,t){this.atom.reportObserved();let n=this.sessions.get(e);return n?(this.touch(e,n),n.values.get(t)??null):null}revision(e){return this.atom.reportObserved(),this.sessions.get(e)?.revision??0}set(e,t,n){this.setBatch(e,[{key:t,value:n}])}setBatch(e,t){t.length!==0&&(0,Mg.runInAction)(()=>{let n=this.sessions.get(e)??{values:new Map,revision:0};t.some(({key:e,value:t})=>n.values.get(e)!==t)&&(n.revision=++this.head);for(let{key:e,value:r}of t)n.values.set(e,r);this.touch(e,n),this.evictOldest(),this.persist(),this.atom.reportChanged()})}clear(e,t){(0,Mg.runInAction)(()=>{let n=this.sessions.get(e);n&&(n.values.delete(t)&&(n.revision=++this.head),n.values.size===0?this.sessions.delete(e):this.touch(e,n)),this.persist(),this.atom.reportChanged()})}prune(e){(0,Mg.runInAction)(()=>{for(let t of this.sessions.keys())e.has(t)||this.sessions.delete(t);this.persist(),this.atom.reportChanged()})}touch(e,t){this.sessions.delete(e),this.sessions.set(e,t)}evictOldest(){let e=this.sessions.size-this.maxSessions;if(!(e<=0)){for(let t of this.sessions.keys())if(this.sessions.delete(t),--e===0)break}}flush(){this.storage.flush()}persist(){this.storage.save(this.serialize())}serialize(){let e=Object.create(null);for(let[t,{values:n}]of this.sessions)e[t]=Object.fromEntries(n);return e}};function pV(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 mV=class{timer=null;pending=null;constructor(e,t=500,n=Nt){this.filePath=e,this.debounceMs=t,this.logger=n}load(){let e;try{e=r.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 pV(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.timer&&(this.timer=setTimeout(()=>this.flush(),this.debounceMs),this.timer.unref())}flush(){if(this.timer&&=(clearTimeout(this.timer),null),this.pending===null)return;let e=this.pending;try{r.mkdirSync(l.dirname(this.filePath),{recursive:!0});let t=`${this.filePath}.tmp`;r.writeFileSync(t,JSON.stringify(e),{mode:384}),r.chmodSync(t,384),r.renameSync(t,this.filePath),this.pending=null}catch(e){this.logger(`warn`,`session-state save failed: ${e.message}`)}}};const hV={default_empty_value:`string`,default_separator:`string`,palette:`string`,style:`string`,effect:`string`,preset:`string`,endcaps:`string`,variation:`string`,shade:`string`,autoWrap:`boolean`,padding:`number`,charset:`string`,updateNotice:`boolean`,transitions:`boolean`,colorCompatibility:`string`,menuGlyph:`string`},gV=new Set([`1`,`true`]),_V=new Set([`0`,`false`,``]);function vV(e,t){let n=UV(e),r=n.scope===`segment-palette`?`string`:hV[n.field];if(r===`string`)return JSON.stringify(t);if(r===`number`){let n=Number(t);if(!Number.isFinite(n))throw Error(`persistValueText: "${e}" expects a number, got "${t}"`);return String(n)}if(gV.has(t))return`true`;if(_V.has(t))return`false`;throw Error(`persistValueText: "${e}" expects boolean-ish (1, 0, true, false), got "${t}"`)}function yV(e){try{return r.readFileSync(e,`utf8`)}catch(e){if(e.code===`ENOENT`)return null;throw e}}function bV(e,t,n){try{if(t===null){r.rmSync(e,{force:!0});return}r.mkdirSync(l.dirname(e),{recursive:!0}),Fe(e,t)}catch(t){let r=`config write failed (${e}): ${t.message}`;throw n(`error`,r),Error(r)}}function xV(e){return/^\s*$/.test(e)?null:_r(e)}function SV(e,t){return e!==null&&yr(e,t)!==void 0}function CV(e){if(e.kind===`segment`)return e.when===void 0?e.name:{seg:e.name,when:e.when};if(e.kind===`container`){let{kind:t,direction:n,children:r,...i}=e;return{[n===`horizontal`?`h`:`v`]:r.map(CV),...i}}return e}function wV(e){if(!Lh(e))return CV(e);let{rows:t,...n}=e;return{rows:Object.fromEntries(Object.entries(t).map(([e,t])=>[e,CV(t)])),...n}}const TV=CF,EV=TV.segments,DV=TV.presets,OV=TV.root;function kV(e,t,n,r){if(!SV(e,t)&&n===void 0)throw new J(`cannot edit ${r}: neither the config file nor the bundled default declares ${t.join(`.`)}`)}function AV(e,t){let n=WE(t);return t.scope===`segment-palette`&&kV(e,[`segments`,t.segment],EV[t.segment],n.join(`.`)),n}function jV(e){return _r(Dr(e))}function MV(){return Object.entries(OV.rows).map(([e,t])=>{let n=CV(t);return{path:[`root`],fragment:jV({rows:{[e]:n}}),unit:{path:[`root`,`rows`,e],value:n}}})}function NV(e,t){let n=e===null?void 0:yr(e,t);return n===void 0?null:{path:t,fragment:n,unit:null}}function PV(e,t){if(t===void 0)return null;let n=wV(t);return{path:e,fragment:jV(n),unit:{path:e,value:n}}}function FV(e,t){let n=[`presets`,t],r=[...n,`root`],i=DV[t];kV(e,n,i,r.join(`.`));let a=NV(e,r)??PV(r,i?.root);return a!==null&&Jr(a.fragment)?a:null}function IV(e,t){let n=qr(t.fragment);return n===null?new Map([[`#`,{path:t.path,unit:t.unit,node:t.fragment}]]):new Map([...e,...n.map(e=>[e.key,{path:[...t.path,`rows`,e.key],unit:t.unit,node:e.value}])])}function LV(e,t){return[...MV(),NV(e,[`root`]),FV(e,t)].filter(e=>e!==null).reduce(IV,new Map)}function RV(e,t,n){for(let{node:r,...i}of LV(e,t).values())if(Xr(r,n))return i;throw new J(`${zV(e,t).join(`.`)} holds no placement "${n}" — the bar you clicked is stale (it reloads on the next render), or the action names a placement the layout never held`)}function zV(e,t){return FV(e,t)?.path??[`root`]}function BV(e,t){return t.scope===`preset-root`?zV(e,t.preset):WE(t)}function VV(e,{unit:t}){return t===null?e:Vr(e,t.path,Dr(t.value),Tr)}function HV(e){let t=UE(e);if(t===null)throw Error(`"${e}" is not a valid persist target`);return t}function UV(e){let t=HV(e);if(t.scope===`preset-root`)throw Error(`"${e}" names a layout, not a value`);return t}function WV(e,t,n,r,i){i(t,n,tH(t,r)),bV(t.path,r,e.logger),e.record(t.path,n,r)}function GV(e,t,n){let r=JV(e,t,n);if(r.length>0)throw new J(`refused: ${e.above.join(`, `)} sets ${r.join(`, `)} over ${e.path}, so this click would change nothing on the bar — edit it there`)}const KV=()=>{};function qV(e,t){try{return t()}catch(t){throw!(t instanceof J)||e.above.length===0?t:new J(`${t.message} — or it is declared by ${e.above.join(`, `)}, which the bar does not edit`)}}function JV(e,t,n){let r=YV(e,t);if(r===null)return[];let i=new Set($V(QV(r),QV(n)));return $V(ZV(e,r),ZV(e,n)).filter(e=>!i.has(e))}function YV(e,t){try{return XV(e,t)}catch(e){if(e instanceof Jw)return null;throw e}}function XV(e,t){return nF(t===null?e.above:[e.path,...e.above],TF,{entered:()=>{},warned:()=>{}},{projectDir:e.projectDir,cwd:e.cwd},n=>n===e.path&&t!==null?t:r.readFileSync(n,`utf8`))}function ZV(e,t){let[n]=t.layers;return n?.path===e.path?n.config:t.base}function QV(e){return e.layers.at(-1)?.config??e.base}function $V(e,t,n=``){return!eH(e)||!eH(t)?JSON.stringify(e)===JSON.stringify(t)?[]:[n]:[...new Set([...Object.keys(e),...Object.keys(t)])].flatMap(r=>$V(e[r],t[r],n===``?r:`${n}.${r}`))}function eH(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function tH(e,t){try{return XV(e,t)}catch(e){throw e instanceof Jw?new J(`refused: the config file would not load after this click — ${e.message}`):e}}function nH(e,t){let n=UV(t),r=xV(yV(e)??``),i=r===null?void 0:yr(r,WE(n));return i!==void 0&&`value`in i?i.value:void 0}function rH(e,t,n){iH(e,t,n,[])}function iH(e,t,n,r){let i=yV(t.path),a=n.reduce((e,[t,n])=>Vr(e,AV(xV(e),UV(t)),vV(t,n),Tr),i??``);WV(e,t,i,qV(t,()=>aH(a,t.path,r,e=>e)),GV)}function aH(e,t,n,r){return n.reduce((e,{preset:n,id:i,setting:a,value:o})=>{let s=r(e,n,i),c=RV(xV(s),n,i),l=ei(VV(s,c),c.path,i,a,Dr(o));if(l===null)throw new J(`${c.path.join(`.`)} in ${t} has no placement "${i}" — the bar you clicked is stale (it reloads on the next render)`);return l},e)}function oH(e,t,n){let r=xV(e),i=[`presets`,t,`root`];for(let[a,{path:o,unit:s,node:c}]of LV(r,t)){if(!Xr(c,n))continue;if(i.every((e,t)=>o[t]===e))return e;let l=s===null?xr(e,c):Dr(s.value);if(a!==`#`)return Vr(e,[...i,`rows`,a],l,Tr);if(FV(r,t)!==null)throw new J(`cannot give preset "${t}" its own copy of ${o.join(`.`)}: it already stages rows of its own over that tree`);return Vr(e,i,l,Tr)}return e}function sH(e,t){return Ur(e,t,t[0]===`presets`&&t.length>2&&!DF(t[1])?2:0)}function cH(e,t,n){let r=n.map(HV),i=yV(t.path);if(i===null)return;let a=r.reduce((e,t)=>sH(e,BV(xV(e),t)),i);a!==i&&WV(e,t,i,a,KV)}function lH(e){let t=e===null?void 0:yr(e,[`presets`]);return t?.kind===`object`?t.entries.map(e=>e.key):[]}function uH(e,t){let n=new Set([...EF,...lH(e),...t.above.flatMap(e=>Object.keys(ur.default.parse(r.readFileSync(e,`utf8`)).presets??{}))].map(qw));return Array.from({length:n.size+1},(e,t)=>`custom-${t+1}`).find(e=>!n.has(qw(e)))}function dH(e,t,n,r,i,a){let o=yV(t.path),s=xV(o??``),c=uH(s,t),l=[`presets`,c],u=qV(t,()=>FV(s,n)),d=[...u===null?[]:[[[...l,`root`],u.unit===null?xr(o??``,u.fragment):Dr(u.unit.value)]],...Object.keys(r).length===0?[]:[[[...l,`globals`],Dr(r)]]],f=i.map(([e,t])=>{let n=HE(c,e);return[AV(s,UV(n)),vV(n,t)]}),p=[...d,...f].reduce((e,[t,n])=>Vr(e,t,n,Tr),Vr(o??``,l,`{}`,Tr));return WV(e,t,o,qV(t,()=>aH(p,t.path,a.map(e=>({...e,preset:c})),oH)),GV),c}function fH(e,t,n,r){let i=yV(t.path);WV(e,t,i,Vr(i??``,[`themeDefaults`,n],Dr(r),Tr),GV)}function pH(e,t,n){if(DF(n))throw new J(`cannot delete preset "${n}": it is bundled — reset its settings instead`);let r=[`presets`,n],i=yV(t.path),a=xV(i??``);if(i===null||a===null||yr(a,r)===void 0)throw new J(`cannot delete preset "${n}": ${t.path} declares no ${r.join(`.`)} — the bar you clicked is stale; it reloads on the next render`);let o=yr(a,[`globals`,`preset`]);WV(e,t,i,[r,...o?.kind===`string`&&o.value===n?[[`globals`,`preset`]]:[]].reduce((e,t)=>sH(e,t),i),KV)}function mH(e,t,n,r){let i=HV(n);if(i.scope!==`preset-root`)throw Error(`"${n}" is not a "presets.<name>.root" target`);let a=yV(t.path),o=r.op===`remove`?r.target:r.anchor,s=qV(t,()=>RV(xV(a??``),i.preset,o)),c=VV(a??``,s),{after:l,placed:u}=hH(c,s.path,r,()=>{let e=tH(t,c).config;return qh(e.presets).map(t=>Xh(e,t).node)});if(l===null)throw new J(`${s.path.join(`.`)} in ${t.path} has no placement "${o}" — the bar you clicked is stale (it reloads on the next render), or the action names a placement the layout never held`);return WV(e,t,a,l,GV),u}function hH(e,t,n,r){switch(n.op){case`remove`:return{after:Qr(e,t,n.target),placed:null};case`insert`:{let i=bA(n.segment,n.anchor,r());return{after:$r(e,t,i,n.anchor,n.relation),placed:i}}}}const gH={load:()=>({}),save:()=>{}},_H=new Set(ma.map(e=>e.sessionKey)),vH=e=>_H.has(e)||e.startsWith(tD),yH=8*1024*1024,bH={past:[],future:[]},xH=e=>e.kind===`session`?`session:${e.key}`:`file:${e.file}`;var SH=class{state=new Map;constructor(e,t,n=gH){this.sessionState=e,this.logger=t,this.storage=n,this.state=new Map(Object.entries(n.load()))}useStorage(e){this.storage=e,this.state=new Map(Object.entries(e.load()))}depth(e){let{past:t,future:n,savepoint:r}=this.state.get(e)??bH;return{undo:t.length,redo:n.length,sinceEdit:r?.net.length??0}}history(e){return this.state.get(e)??bH}begin(){let e=new Map,t=(t,n)=>{let r=e.get(t)??new Map,i=r.get(xH(n));r.set(xH(n),i===void 0?n:{...n,before:i.before}),e.set(t,r)},n=new Map;return{sessionState:uV(this.sessionState,e=>vH(e)||e===`edit.mode`,(e,r,i,a)=>{if(r===`edit.mode`){let t=n.get(e);n.set(e,{before:t===void 0?i:t.before,after:a});return}t(e,{kind:`session`,key:r,before:i,after:a})}),file:(e,n,r,i)=>t(e,{kind:`file`,file:n,before:r,after:i}),commit:()=>{let t=new Map(e),r=new Map(n);e.clear(),n.clear();for(let e of new Set([...t.keys(),...r.keys()])){let n=[...t.get(e)?.values()??[]].filter(e=>e.before!==e.after),i=this.history(e),a=n.length===0?i:AH(i,n),o=r.get(e),s=o===void 0?a:PH(a,o);s!==i&&this.put(e,s)}}}}undo(e){let t=this.history(e),n=t.past.at(-1);if(n===void 0)throw new J(`undo: nothing to undo`);return this.apply(e,n,`before`,`undo`,MH(t,n)),n}rewind(e){let t=this.history(e),{savepoint:n}=t;if(n===void 0)throw new J(`rewind: edit mode has no savepoint — nothing to cancel`);let r=n.net.filter(t=>this.read(e,t)!==t.after),i=new Set(r.map(xH)),a=n.net.filter(e=>!i.has(xH(e))),o=TH(FH(NH(t,n),i));if(this.apply(e,a,`before`,`rewind`,{past:o,future:[],savepoint:{at:o.length,net:[],below:[]}}),r.length>0)throw new J(`rewind: ${r.map(LH).join(`, `)} changed since edit mode opened — kept as it is; everything else edit mode changed was put back`);return a}redo(e){let t=this.history(e),{past:n,future:r}=t,i=r.at(-1);if(i===void 0)throw new J(`redo: nothing to redo`);let a=[...n,i],o=TH(a);return this.apply(e,i,`after`,`redo`,{past:o,future:r.slice(0,-1),...DH(t.savepoint,a.length-o.length,i)}),i}apply(e,t,n,r,i){let a=n===`before`?`after`:`before`,o=t.filter(t=>this.read(e,t)!==t[a]);if(o.length>0){let t=new Set(o.map(xH)),{past:n,future:i,savepoint:a}=this.history(e);throw this.put(e,{past:FH(n,t),future:FH(i,t),...a!==void 0&&{savepoint:{at:FH([...n,...[...i].reverse()].slice(0,a.at),t).length,net:a.net.filter(e=>!t.has(xH(e))),below:FH(a.below,t)}}}),new J(`${r}: ${o.map(LH).join(`, `)} changed since that edit — refusing to overwrite it; this session's undo history no longer steps it`)}let s=[];try{for(let r of t)this.write(e,r,r[n]),s.push(r);this.put(e,i)}catch(t){try{for(let t of s.reverse())this.write(e,t,t[a])}catch(e){throw Error(`${t.message}; and putting the step back failed, so it is half-applied: ${e.message}`)}throw t}}read(e,t){return t.kind===`session`?this.sessionState.get(e,t.key):yV(t.file)}write(e,t,n){t.kind===`file`?bV(t.file,n,this.logger):n===null?this.sessionState.clear(e,t.key):this.sessionState.set(e,t.key,n)}put(e,t){let n=new Map(this.state);for(n.delete(e),(t.past.length>0||t.future.length>0||t.savepoint!==void 0)&&n.set(e,t);n.size>32||CH(n)>yH;){let[e,t]=n.entries().next().value;n.size>1?n.delete(e):t.past.length+t.future.length>0?n.set(e,wH(t)):(this.logger(`warn`,`settings-history: edit mode's changes for session ${e} exceed ${yH} bytes; cancel is no longer available`),n.delete(e))}this.storage.save(Object.fromEntries(n)),this.state=n}};function CH(e){let t=0;for(let{past:n,future:r,savepoint:i}of e.values())for(let e of[...n,...r,...i===void 0?[]:[i.net,...i.below]])for(let n of e)t+=(n.before?.length??0)+(n.after?.length??0);return t}function wH({past:e,future:t,savepoint:n}){return e.length>0?{past:e.slice(1),future:t,...DH(n,1,[])}:{past:e,future:t.slice(1),...DH(n,0,[])}}function TH(e){return e.slice(-50)}const EH=e=>e===rD.member;function DH(e,t,n){return e===void 0?{}:{savepoint:{at:Math.max(0,e.at-t),net:OH(e.net,n),below:e.below}}}function OH(e,t){let n=new Map(e.map(e=>[xH(e),e]));for(let e of t){let t=n.get(xH(e));n.set(xH(e),t===void 0?e:{...t,after:e.after})}return[...n.values()].filter(e=>e.before!==e.after)}const kH=e=>e.map(e=>({...e,before:e.after,after:e.before}));function AH(e,t){let n=[...e.past,t],r=TH(n),{savepoint:i}=e,a=i===void 0?0:Math.max(0,i.at-e.past.length);return{past:r,future:[],...DH(i&&{at:Math.min(i.at,e.past.length),net:i.net,below:[...jH(e.future,a),...i.below]},n.length-r.length,t)}}function jH(e,t){let n=Math.min(t,e.length);return e.slice(e.length-n).reverse()}function MH(e,t){return{past:e.past.slice(0,-1),future:TH([...e.future,t]),...DH(e.savepoint,0,kH(t))}}function NH(e,t){let{past:n,future:r}=e,i=n.slice(0,t.at);return[...i,...jH(r,t.at-i.length),...t.below]}function PH(e,t){if(EH(t.after)&&!EH(t.before))return{...e,savepoint:{at:e.past.length,net:[],below:[]}};if(!EH(t.after)&&EH(t.before)){let{past:t,future:n}=e;return{past:t,future:n}}return e}function FH(e,t){return e.map(e=>e.filter(e=>!t.has(xH(e)))).filter(e=>e.length>0)}function IH(e){return e.map(LH).join(`, `)}function LH(e){return e.kind===`session`?`session setting "${e.key}"`:e.file}function RH(e){if(typeof e!=`object`||!e)return!1;let t=e,n=e=>e===null||typeof e==`string`;return(t.kind===`session`&&typeof t.key==`string`||t.kind===`file`&&typeof t.file==`string`)&&n(t.before)&&n(t.after)}function zH(e){return Array.isArray(e)&&e.every(e=>Array.isArray(e)&&e.every(RH))}function BH(e){if(typeof e!=`object`||!e)return!1;let t=e;return Number.isInteger(t.at)&&t.at>=0&&Array.isArray(t.net)&&t.net.every(RH)&&zH(t.below)}function VH(e){if(typeof e!=`object`||!e)return!1;let t=e;return zH(t.past)&&zH(t.future)&&(t.savepoint===void 0||BH(t.savepoint))}function HH(e,t){let n=e=>e.kind===`file`||vH(e.key)?!0:(t.add(e.key),!1),r=e=>e.map(e=>e.filter(n)).filter(e=>e.length>0),{savepoint:i}=e,a=r(e.past),o=r(e.future);return i===void 0?{past:a,future:o}:{past:a,future:o,savepoint:{at:r(e.past.slice(0,i.at)).length,net:i.net.filter(n),below:r(i.below)}}}function UH(e,t){return{load:()=>{let n;try{n=r.readFileSync(e,`utf8`)}catch(e){let n=e.code;return n!==`ENOENT`&&t(`warn`,`settings-history read failed (${n}); starting empty`),{}}try{let e=JSON.parse(n);if(typeof e==`object`&&e&&!Array.isArray(e)&&Object.values(e).every(VH)){let n=new Set,r=Object.fromEntries(Object.entries(e).map(([e,t])=>[e,HH(t,n)]));return n.size>0&&t(`warn`,`settings-history load: dropped the changes to ${[...n].map(e=>`"${e}"`).join(`, `)}, no longer a setting`),r}}catch{}return t(`warn`,`settings-history load: unexpected shape, starting empty`),{}},save:n=>{try{r.mkdirSync(l.dirname(e),{recursive:!0}),Fe(e,JSON.stringify(n),384)}catch(e){let n=`settings-history write failed — the change landed but is not undoable: ${e.message}`;throw t(`error`,n),Error(n)}}}}const WH=e=>!vH(e)&&!WD(e)&&e!==`update.dismissed`;var GH=class{past=new Map;depth(e,t,n){return this.restorable(e,t,n).length}restorable(e,t,n){let r=new Map,i=n=>r.has(n)?r.get(n):t.get(e,n),a=[];for(let t of[...this.past.get(e)??[]].reverse())if(t.every(e=>i(e.key)===e.after&&(e.before===null||n.validate(e.key,e.before).ok))){a.unshift(t);for(let e of t)r.set(e.key,e.before)}return a}begin(e){let t=new Map;return{sessionState:uV(e,WH,(e,n,r,i)=>{let a=t.get(e)??new Map,o=a.get(n);a.set(n,{key:n,before:o?o.before:r,after:i}),t.set(e,a)}),commit:()=>{for(let[e,n]of t){let t=[...n.values()].filter(e=>e.before!==e.after);t.length>0&&this.push(e,t)}t.clear()}}}back(e,t,n){let r=this.past.get(e)??[],i=this.restorable(e,t,n),a=i.at(-1),o=r.length-i.length;if(a===void 0)throw this.put(e,i),new J(`back: nothing to go back to${o>0?` (${o} step(s) over a view since gone, discarded)`:``}`);return(0,Mg.runInAction)(()=>{let n=a.flatMap(({key:e,before:t})=>t===null?[]:[{key:e,value:t}]);n.length>0&&t.setBatch(e,n);for(let{key:n,before:r}of a)r===null&&t.clear(e,n)}),this.put(e,i.slice(0,-1)),{step:a,discarded:o}}push(e,t){let n=this.past.get(e)??[];this.put(e,[...n,t].slice(-20))}put(e,t){for(this.past.delete(e),t.length>0&&this.past.set(e,t);this.past.size>32;)this.past.delete(this.past.keys().next().value)}};function KH(e){let t=OR(e,`doctor.tmux`,[`display`,`-p`,`-t`,e.pane,`#{client_termfeatures}`]);return t.kind===`ok`?{kind:`ok`,value:t.stdout.trim().split(`,`).filter(e=>e!==``)}:{kind:`failed`,reason:t.reason}}function qH(e){return{probeTmux:KH,loadConfig:e}}function JH(e){let t={layers:e.layers,warnings:e.warning===null?[]:e.warning.split(`
205
- `)};return e.error===null?{...t,kind:`loaded`,unused:e.unused}:{...t,kind:`failed`,error:e.error}}function YH(e){let{env:t,statusLine:n}=oi(e);if(t!==void 0&&!si(t))throw Error(`cannot read ${e}: \`env\` is not an object`);return{path:e,env:t??{},statusLine:n===void 0?{kind:`absent`}:si(n)?{kind:`present`,refreshInterval:n.refreshInterval}:{kind:`not-an-object`,value:n}}}function XH(e,t){return t===void 0?{kind:`unreported`}:t===null?{kind:`outside`}:{kind:`inside`,hint:t,termfeatures:e.probeTmux(t)}}function ZH(e){return{kind:`arrived`,handler:e,bar:wt}}function QH(e,t,n){let r=new Map;for(let i of dh(Xh(e,t).node)){if(i.kind!==`segment`)continue;let t=wh(e.segments[i.name])[Sh],a=Ah(i,Sh,t,e=>n(e.key));a===`bar`||a===`none`||r.set(i.drafts?.effect?.id??sh(i),a)}return[...r].map(([e,t])=>({placement:e,effect:t}))}function $H(e,t,n,r){let i=e.loadConfig(n),a=iI(i.config,r,()=>!1);return{tmux:XH(e,t.tmux),config:JH(i),effect:a.effect,placementEffects:QH(i.config,a.preset,r),transitions:a.transitions,claudeSettings:YH(ri(ni(t.claudeConfigDir)))}}function eU(e,t){let n=t.claudeSettings.path;switch(e.kind){case`claude-settings`:{let i=Vr(ai(n),e.path,JSON.stringify(e.value),Er);return r.mkdirSync(l.dirname(n),{recursive:!0}),Fe(n,i),{...t,claudeSettings:YH(n)}}default:return e.kind}}const tU={connectMs:200,budgetMs:500};async function nU(e){let n=e.includes(`--json`),r=await rU();if(r.kind!==`ok`&&(t.stderr.write(`daemon-stats: ${Ct(r)}\n`),t.exit(1)),n){t.stdout.write(JSON.stringify(r.value,null,2)+`
206
- `);return}t.stdout.write(sU(r.value))}function rU(){return _t({kind:`stats`},tU,e=>`stats`in e?e.stats:void 0)}function iU(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/1024/1024).toFixed(1)}MB`}function aU(e,t){let n=e+t;return n===0?`n/a`:`${(e/n*100).toFixed(1)}%`}function oU(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 sU(e){let t=[];t.push(`cc-candybar daemon stats`),t.push(``),t.push(`process`),t.push(` pid ${e.pid}`),t.push(` version ${e.version}`),t.push(` protocol ${e.protocolVersion}`),t.push(` startedAt ${e.startedAt}`),t.push(` uptime ${oU(e.uptimeSec)}`),t.push(` rss ${iU(e.rssBytes)}`),t.push(` heapUsed ${iU(e.heapUsedBytes)}`),t.push(` heapTotal ${iU(e.heapTotalBytes)}`),t.push(` external ${iU(e.externalBytes)}`),t.push(` arrayBuffers ${iU(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(``),t.push(`gitCache`),t.push(` size ${e.gitCache.size}`),t.push(` hit rate ${aU(e.gitCache.hits,e.gitCache.misses)} (${e.gitCache.hits} / ${e.gitCache.hits+e.gitCache.misses})`),t.push(` invalidations ${e.gitCache.invalidations}`),t.push(``),t.push(`usageCache`),t.push(` size ${e.usageCache.size}`),t.push(` hit rate ${aU(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(`renderCache`),t.push(` size ${e.renderCache.size}`),t.push(``),t.push(`effectCache`),t.push(` sessions ${e.effectCache.sessions}`),t.push(` effects ${e.effectCache.effects}`),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(` evicted ${e.watchers.evicted}`),t.push(``),t.push(`subprocesses`),t.push(` total ${e.subprocesses.total}`),t.push(` inFlight ${e.subprocesses.inFlight}`),t.push(` lastMinute ${e.subprocesses.lastMinute}`);let n=Object.entries(e.subprocesses.byCategory),r=n.reduce((e,[t])=>Math.max(e,t.length),13);for(let[i,a]of n){let n=e.subprocesses.p50DurationMs[i],o=e.subprocesses.p99DurationMs[i],s=n!==void 0&&o!==void 0?` (p50 ${n}ms · p99 ${o}ms)`:``;t.push(` ${i.padEnd(r)} ${a}${s}`)}return e.nextRestartReason&&(t.push(``),t.push(`nextRestart ${e.nextRestartReason}`)),t.join(`
202
+ `);n.push(e[0]);for(let r=1;r<e.length;r++)t.push(n),n=[e[r]]}return t.push(n),t}function hB(e){let t=new Map;return e.map(e=>{let n=`${e.place}.${e.band}`,r=t.get(n)??0;return t.set(n,r+1),{line:e,row:`${n}#${r}`}})}function gB(e,t){let n=[],r=[],i;for(let a of t)(a.band===`own`?n:r).push(a),i??=a.cells.find(t=>t.placement.id===e)?.placement.ground;return{drawing:i===void 0?null:{own:r.length===0?n:[],ground:i},deeper:r}}function _B(e){return{...e,cells:e.cells.map(WR)}}function vB(e,t){let n=t.flatMap(e=>e.filter(e=>e.place===`above`)),r=t.map(e=>e.filter(e=>e.place===`flow`));return[...n,...yB(e,r)]}function yB(e,t){switch(e){case`vertical`:return t.flatMap(e=>e);case`horizontal`:return t.reduce((e,t)=>Math.max(e,t.length),0)===0?[]:[{cells:t.flatMap(e=>e[0]?.cells??[]),band:`own`,place:`flow`},...t.flatMap(e=>e.slice(1))]}}function bB(e,t){let n=(e,r)=>t(e)?e.kind===`segment`?[{cells:[{name:e.name,address:r,settings:e.settings}],band:`own`,place:`flow`}]:vB(e.direction,e.children.map((t,i)=>n(t,[...r,xB(e,i)]))):[];return n(e,[]).map(e=>[...e.cells])}function xB(e,t){return{index:t,count:e.children.length,distribution:e.distribution,axis:oh[e.direction]}}const SB={compile(e,t){return{kind:`container`,direction:e.direction,when:t.when,distribution:ff(e.distribution),children:e.children.map((e,n)=>t.compileChild(e,fh(t.path,n)))}},render(e,t){return t.gate.kind===`failed`&&t.gate.report(),vB(e.direction,e.children.map((n,r)=>t.renderChild(n,t.gate.kind===`shown`,xB(e,r))))}},CB={drop:e=>e.place,above:()=>`above`},wB={drop:(e,t)=>({lead:t(),stays:e}),above:e=>({lead:e.slice(0,1).flatMap(e=>e.cells),stays:e.slice(1)})},TB={compile(e,t){return{kind:`segment`,when:t.when,name:e.name,id:sh(e),settings:t.placementSettings(e),...e.opens!==void 0&&{opens:{open:t.parse(Xn(e.opens.ref),`opens`),body:t.compileChild(e.opens.body,ph(t.path)),key:e.opens.ref.key,placement:e.opens.placement}},...e.lead!==void 0&&{lead:t.parse(e.lead,`lead`)},...e.trail!==void 0&&{trail:t.parse(e.trail,`trail`)}}},render:(e,t)=>t.placed(e.id,EB(e,t))};function EB(e,t){let n=t.lookupSegment(e.name);if(!n)throw Error(`Layout segment "${e.name}" has no matching segment`);let{seg:r,compiled:i}=n;if(t.gate.kind===`hidden`)return[];let a=EC(t.scope,e.settings);if(t.gate.kind===`failed`)return DB(e,a,t,t.gate.message);try{if(!LR(i.when,a))return[];let n=Zm(e.settings.theme,t.palette),o={id:e.id,effect:e.settings.effect,ground:pD(n)},s=e.opens!==void 0&&LR(e.opens.open,t.scope),{styles:c,fragments:l,lead:u,trail:d,drops:f,open:p}=t.evaluateSegment(e,a,n,t.region,{bg:i.bg,fg:i.fg,body:i.template,lead:e.lead,trail:e.trail},s),m=p?c.trigger:c.closed,h={width:r.width??`auto`,justify:r.justify??`left`,truncate:r.truncate??`right`,baseStyle:m,padding:t.padding,placement:o},g=e.opens,_=g===void 0?[]:t.renderBody(g.body,s,c.disclosure).map(e=>({...e,place:CB[g.placement](e)})),v=mB(YR(l,m)).map((e,t)=>({cells:qR(e,{...h,lead:t===0?YR(u,m):[],trail:t===0?YR(d,m):[]}),band:`own`,place:`flow`})),y=f.map(e=>({cells:qR(YR([e],c.band),{...h,baseStyle:c.band}),band:`deeper`,place:`flow`})),b=(e,t,n)=>qR(YR([e],t),{...h,width:`auto`,baseStyle:t,padding:n}),x=_.findIndex(e=>e.band===`own`),{lead:S,stays:C}=g!==void 0&&x!==-1?wB[g.placement](v,()=>b(t.closeDisclosure(g.key),c.close,t.padding)):{lead:[],stays:v},ee=S.flatMap(e=>b(new q(` `.repeat(UR(e).reduce((e,t)=>e+t.cellLength,0))),c.trigger,0)),te=(e,t)=>e.band===`own`?t===x?S:ee:[],ne=_.map((e,t)=>({cells:[...te(e,t),...e.cells],band:`deeper`,place:e.place})),re=[...C,...y];return t.perSegmentSink!==void 0&&t.perSegmentSink.set(e.id,[...re.flatMap(e=>e.cells),..._.flatMap(te)].flatMap(UR)),[...re,...ne]}catch(n){return DB(e,a,t,n.message??String(n))}}function DB(e,t,n,r){n.onSegmentError?.(e.id,r);let i=r.replace(/\s*\n\s*/g,` `);return[{cells:qR([new q(`⚠ ${e.id}: ${i}`,{end:``})],{width:`auto`,justify:`left`,truncate:`right`,padding:0,placement:{id:e.id,effect:`bar`,ground:pD(n.palette)},lead:OB(e.lead,e,t,n),trail:OB(e.trail,e,t,n)}),band:`own`,place:`flow`}]}function OB(e,t,n,r){if(e===void 0)return[];try{return r.evaluateSegment(t,n,r.palette,r.region,{bg:void 0,fg:void 0,body:e,lead:void 0,trail:void 0},!1).fragments}catch(e){return r.onSegmentError?.(t.id,e.message??String(e)),[]}}const kB={container:SB,segment:TB};function AB(e){return kB[e]}function jB(e){if(`ttl`in e)return{kind:`ttl`,durationMs:xw(e.ttl)};if(`watch_file`in e)return{kind:`watch_file`,path:e.watch_file};if(`depends_on`in e)return{kind:`depends_on`,varNames:e.depends_on};if(`key`in e)return{kind:`key`,template:e.key};if(`never`in e)return{kind:`never`};throw Error(`Unknown CacheDecl discriminator — loader invariant violated: ${JSON.stringify(e)}`)}function MB(e,t){switch(_h(e)){case`json`:return{kind:`json`,default:t};case`regex`:return{kind:`regex`,regex:new RegExp(e.regex),default:t};case`text`:return{kind:`text`,default:t}}}function NB(e,t,n,r){switch(n.kind){case`literal`:e.declareLiteral(t,n.value);break;case`dropped`:e.declareFailedDocument(t,n.reason);break;case`input`:e.declareInput(t,n.path,n.type??`string`,n.default);break;case`env`:e.declareEnv(t,n.name,n.default);break;case`file`:e.declareFile(t,n.path,{readMode:n.readMode,cache:jB(n.cache),parse:MB(n.parse,n.default)});break;case`shell`:e.declareShell(t,n.command,{cwd:r,cache:jB(n.cache),parse:MB(n.parse,n.default)});break;case`template`:e.declareTemplate(t,n.template,{varDefault:n.default});break;case`time`:e.declareTime(t,{format:n.layout,varDefault:n.default});break;case`git`:e.declareGit(t,{field:n.field,cwd:r,varDefault:n.default});break;case`state`:e.declareState(t,{key:n.key,...n.default!==void 0&&{varDefault:n.default}});break}}function PB(e,t){let n=f_.EMPTY;for(let[r,i]of Object.entries(t))try{n=e.parse(`{{ define "${r}" }}${i}{{ end }}`,n).defines()}catch(e){throw Error(`Template parse error in helpers.${r}: ${e.message}`,{cause:e})}return n}const FB=(e,t,n,r,i)=>{let a=AF(t,kF(n,e.themeDefaults));return{variation:of[r??Up(void 0,null,a.variation)],shade:rf[i??Kp(void 0,null,a.shade)]}};function IB(e,t,n){let r=n.cwd,i={store:t.variableStore,compiled:new Map,chromeCols:Tm({endcaps:`powerline`,charset:Rp}),width:80,padding:1,seamCols:Em({endcaps:`powerline`,charset:Rp}),layout:()=>[],look:void 0},a=kz(t.drawnAt),o={action:i,activeSegment:a},s=Object.keys(e.styles),c=qh(e.presets),l=$k(e),u=CC({extraFuncs:{...fz(i),...Vz(i,a),...Gz(i,a),...eB(i,a),...Yz(i,a,t.now),...aB(i,a),...lB(o),...fB(a),styles:{fn:()=>s,argTypes:[],arity:{kind:`exact`}},presets:{fn:()=>c,argTypes:[],arity:{kind:`exact`}}},clock:t.now,drawnAt:t.drawnAt}),d=PB(u,e.helpers),f=e=>u.parse(e,d),p=new Map,m=e=>{let t=p.get(e);if(t!==void 0)return t;let n=f(e);return p.set(e,n),n},h=new Map;for(let[t,n]of va)n in e.variables&&h.set(t,n);for(let[t,n]of Object.entries(e.variables))n.kind===`state`&&!h.has(n.key)&&h.set(n.key,t);for(let[t,n]of Object.entries(e.segments))if(n.vars)for(let[e,r]of Object.entries(n.vars))r.kind===`state`&&!h.has(r.key)&&h.set(r.key,`${t}.${e}`);i.compiled=$R(f,e.actions,h,l);let g=[];for(let[n,i]of Object.entries(e.variables))try{NB(t,n,i,r)}catch(e){g.push(`Variable "${n}": ${e.message??String(e)}`)}for(let[n,i]of Object.entries(e.segments))if(i.vars)for(let[e,a]of Object.entries(i.vars))try{NB(t,`${n}.${e}`,a,r)}catch(t){g.push(`Variable "${n}.${e}": ${t.message??String(t)}`)}let _=Object.create(null);for(let[t,n]of Object.entries(e.segments)){let e=(e,n,r=f)=>{try{return r(e)}catch(e){throw Error(`Template parse error in segments.${t}.${n}: ${e.message}`,{cause:e})}};_[t]={when:n.when===void 0?void 0:e(n.when,`when`,m),template:e(n.template,`template`),bg:n.bg===void 0?void 0:e(n.bg,`bg`),fg:n.fg===void 0?void 0:e(n.fg,`fg`)}}let v=(e,t,n)=>{try{return m(e)}catch(e){throw Error(`Template parse error in ${t}.${n}: ${e.message}`,{cause:e})}},y=t.variableStore,b=t=>{let n=wh(e.segments[t.name]),r=Object.create(null);for(let[e,i]of Object.entries(n))Object.defineProperty(r,e,{enumerable:!0,get:()=>Ah(t,e,i,e=>String(y.read(e.variable)))});return Object.freeze(r)},x=(e,t)=>{let n={path:t,when:e.when===void 0?void 0:v(e.when,t,`when`),parse:(e,n)=>v(e,t,n),compileChild:x,placementSettings:b};return AB(e.kind).compile(e,n)},S=new Map;for(let t of c){let{node:n,path:r}=Xh(e,t);S.set(t,x(n,r))}let C=new Map(hp.map(e=>[e,new Map])),ee=[[`globals`,e.globals],...Object.entries(e.presets).map(([e,t])=>[`presets.${e}.globals`,t.globals??{}])];for(let[e,t]of ee)for(let n of hp){let r=t[n];if(!gp(r))continue;let i=`${e}.${n}`,a=C.get(n),o=a.get(r);a.set(r,o===void 0?{where:i,template:LB(f,i,r)}:{where:`${o.where}, ${i}`,template:o.template})}return{segments:_,roots:S,activeSegment:a,menuRuntime:o,globalExpressions:C,loadWarnings:g}}function LB(e,t,n){try{return e(n)}catch(e){throw Error(`${t} is not a valid template: ${e instanceof Error?e.message:String(e)}`)}}function RB(e,t,n){let r=e.globalExpressions.get(t).get(n);if(r===void 0)throw Error(`the ${t} rule ${JSON.stringify(n)} reached the render but no compiled template exists — registerDslConfig and the resolution disagree about isExpression`);return r}function zB(e,t,n,r){try{return t.template.evaluate(n).map(e=>e.plain).join(``)}catch(n){return r({kind:`rule`,slot:e,message:Tp(t.where,e,`the rule failed — ${n instanceof Error?n.message:String(n)}`)}),wp[e]}}function BB(e,t){return e.kind===`decided`?e.name:wp[t]}function VB(e){return e.kind===`container`?e.children.flatMap(VB):[...e.name.startsWith(`edit.`)?[]:[e.id],...e.opens===void 0?[]:VB(e.opens.body)]}function HB(e,t,n,r,i,a,o,s,c){let{perSegmentSink:l,onSegmentError:u,onRenderWarning:d}=s??{},f=e=>d?.(e),p=new Set;r.renderAt(a),r.drawAt(Bp(o.colorCompatibility));let{preset:m=Gh}=c??{},h=Zh(e,m),g=c?.style??xp(`none`,e.styles),_=c?.theme??rh(void 0,null,h.palette),v=FB(e,h,_,c?.variation,c?.shade),y=c?.effect??Ap(void 0,null,h.effect),b=(e,t,n)=>({...i,term:{cols:o.width},theme:{effective:e},style:{effective:t},effect:{effective:n}});r.applyInput(b(BB(_,`palette`),BB(g,`style`),BB(y,`effect`))),t.menuRuntime.action.chromeCols=Tm(o),t.menuRuntime.action.padding=o.padding,t.menuRuntime.action.width=o.width,t.menuRuntime.action.seamCols=Em(o);let x=wC(n),S=vp(_,e=>{let n=RB(t,`palette`,e);return nh(zB(`palette`,n,x,f),n.where,e=>f({kind:`rule`,slot:`palette`,message:e}))}),C=vp(g,n=>xp(zB(`style`,RB(t,`style`,n),x,f),e.styles)),ee=vp(y,e=>kp(zB(`effect`,RB(t,`effect`,e),x,f)));(S!==_||C!==g||ee!==y)&&r.applyInput(b(S.name,C.name,ee.name));let te=S.value,ne=$m(te,C.value);t.menuRuntime.action.look={basePalette:te,palette:ne,decor:v};let re=(c?.effects??new hm(``)).motion(ee.value,a,{transitions:c?.transitions??nm(void 0,null,h.transitions),source:{config:t,preset:m,revision:r.stateRevision(),width:o.width},returned:gB,hold:_B});l?.clear();let ie=n=>{let r=e.segments[n],i=t.segments[n];return r!==void 0&&i!==void 0?{seg:r,compiled:i}:void 0},ae=(e,n,i,a,o,s)=>{try{let c=r.drawnAt(),{tint:l,text:u,disclosure:d}=ap(i,a,c),f=Az(t.activeSegment,e.name,e.id,i,d,l,u),m=hD(f,c,o.bg,o.fg,n),h=()=>Kf(i,d,c);s&&(f.bg=h().state);let g=o.body.evaluate(n),_=f.drops.length>0||s;if(_){let e=h();f.bg=e.state;for(let t of e.shortfalls)p.add(t)}let v=o.lead?.evaluate(n)??[],y=o.trail?.evaluate(n)??[];return{styles:{closed:m,get trigger(){return mz(i,h().state,c)},get band(){return mz(i,h().plane,c)},get close(){return _z(i,h().state,c)},disclosure:d},fragments:g,lead:v,trail:y,drops:f.drops,open:_}}finally{t.activeSegment.current=null}},w=(e,t,r)=>{let i=t?BR(e.when,x):RR,a=i.kind===`failed`?{...i,report:()=>{let t=`when over ${VB(e).join(`, `)||`no placement`}`;f({kind:`when`,where:t,error:i.message,message:`${t}: ${i.message} — what it gates is hidden`})}}:i,s={scope:x,palette:ne,gate:a,padding:o.padding,region:r,perSegmentSink:l,onSegmentError:u,evaluateSegment:ae,lookupSegment:ie,renderChild:(e,t,n)=>w(e,t,rp(r,n)),renderBody:(e,t,n)=>w(e,a.kind===`shown`&&t,ip(n)),closeDisclosure:e=>pz(n,e),placed:re.placed};return AB(e.kind).render(e,s)},T=t.roots.get(m);if(T===void 0)throw Error(`Preset "${m}" has no compiled layout — registerDslConfig compiles one per declared preset and effectivePresetName collapses unknown names to "${Gh}"; a miss here is merge/policy drift (have: ${[...t.roots.keys()].join(`, `)})`);let oe=e=>{let n=BR(e.when,x);if(e.kind===`container`)return n.kind===`shown`;if(uA(e.name)===void 0)return!1;if(n.kind!==`shown`)return n.kind===`failed`;try{return LR(t.segments[e.name].when,EC(x,e.settings))}catch{return!0}};t.menuRuntime.action.layout=()=>bB(T,oe).map(e=>e.flatMap(({name:e,address:t,settings:n})=>{let r=uA(e);return r===void 0?[]:[{name:r,address:t,palette:Zm(n.theme,ne)}]}));let se=hB(w(T,!0,np(v))).map(({line:e,row:t})=>{let n=JR(e.cells,o);return Dm(n.map(e=>e.owner),o,re.row(t,n))}).join(`
203
+ `);re.drawn();for(let e of p)f({kind:`band-floor`,message:e});return se}function*UB(e){yield*Object.entries(e.variables??{});for(let[t,n]of Object.entries(e.segments??{}))for(let[e,r]of Object.entries(n.vars??{}))yield[`${t}.${e}`,r]}function*WB(e){for(let t of Object.values(e.segments))for(let e of[t.template,t.bg,t.fg,t.when])e!==void 0&&(yield e);for(let t of qh(e.presets)){for(let n of dh(Xh(e,t).node))n.when!==void 0&&(yield n.when);let n=Zh(e,t);for(let e of hp){let t=n[e];gp(t)&&(yield t)}}for(let[,t]of UB(e))t.kind===`template`&&(yield t.template),yh(t)&&t.cache&&`key`in t.cache&&(yield t.cache.key);for(let t of Object.values(e.actions))`copy`in t&&(yield t.copy),`open`in t&&(yield t.open),`preset`in t&&t.preset===`delete`&&(yield t.name)}function GB(e,t){return e===t||t.startsWith(`${e}.`)||e.startsWith(`${t}.`)}function KB(e,t){let n=new Set,r=new Set,i=new Set;for(let e of WB(t)){for(let r of vg(e,t.helpers).keys())n.add(r);for(let{name:n}of Sg(e,t.helpers))r.add(n);for(let n of Cg(e,t.helpers))i.add(n)}for(let[,e]of UB(t))if(yh(e)&&e.cache&&`depends_on`in e.cache)for(let t of e.cache.depends_on)n.add(t);let a=new Set(r);for(let e of r){let n=t.actions[e];if(n!==void 0&&`do`in n)for(let e of n.do)a.add(e)}let o=new Set,s=new Set;for(let e of a){let n=t.actions[e];if(n!==void 0&&(`set`in n&&o.add(n.set),`insertSegment`in n&&s.add(n.insertSegment),`insertSegmentFrom`in n&&Array.isArray(n.insertSegmentFrom)))for(let e of n.insertSegmentFrom)s.add(e)}for(let e of qh(t.presets))for(let n of dh(Xh(t,e).node))n.kind===`segment`&&s.add(n.name);let c=(e,t)=>[...n].some(t=>GB(t,e))||t.kind===`state`&&o.has(t.key),l=e=>[...e].filter(e=>!rT(e)),u=(e,t,n)=>l(t).filter(e=>!n(e)).map(t=>({kind:e,name:t})),d=new Map(UB(e));return[...u(`variable`,d.keys(),e=>c(e,d.get(e))),...u(`action`,Object.keys(e.actions??{}),e=>a.has(e)),...u(`helper`,Object.keys(e.helpers??{}),e=>i.has(e)),...u(`segment`,Object.keys(e.segments??{}),e=>s.has(e))]}var qB=class{kind=`box`;cell;lastChangedAt;constructor(e,t,n){this.name=e,this.type=t,$B(e,t,n,`initial value`),this.cell=Mg.observable.box(n,{deep:!1}),this.lastChangedAt=Date.now()}read(){return this.cell.get()}set(e){$B(this.name,this.type,e,`set value`),!Object.is(this.cell.get(),e)&&(this.cell.set(e),this.lastChangedAt=Date.now())}lastUpdatedMs(){return this.lastChangedAt}},JB=class{kind=`computed`;cell;constructor(e,t,n){this.name=e,this.type=t,this.cell=(0,Mg.computed)(()=>{let e=n();return $B(this.name,this.type,e,`computed result`),e},{keepAlive:!0})}read(){return this.cell.get()}lastUpdatedMs(){return null}},YB=class{kind=`document`;cell;lastChangedAt;constructor(e,t){this.name=e,this.cell=Mg.observable.box(QB(t),{deep:!1}),this.lastChangedAt=Date.now()}read(){return this.cell.get()}set(e){let t=QB(e);ZB(this.cell.get(),t)||(this.cell.set(t),this.lastChangedAt=Date.now())}lastUpdatedMs(){return this.lastChangedAt}};function XB(e){return JSON.stringify(e)}function ZB(e,t){return XB(e)===XB(t)}function QB(e){return e.kind===`ok`?{kind:`ok`,value:Ng(e.value)}:e}function $B(e,t,n,r){let i=Pg(n);if(i!==t)throw TypeError(`Variable "${e}": ${r} type ${i} does not match declared type ${t}`)}var eV=class{nodes=new Map;defineBox(e,t,n){this.assertNotDefined(e),this.nodes.set(e,new qB(e,t,n))}defineDocument(e,t){this.assertNotDefined(e),this.nodes.set(e,new YB(e,t))}defineComputed(e,t,n){this.assertNotDefined(e);let r=e=>this.read(e);this.nodes.set(e,new JB(e,t,()=>n(r)))}read(e){return this.requireVar(e).read()}readDocument(e){let t=this.requireNode(e);if(t.kind!==`document`)throw TypeError(`Variable "${e}" is a ${t.kind}, not a document`);return t.read()}setDocument(e,t){let n=this.requireNode(e);if(n.kind!==`document`)throw TypeError(`Variable "${e}" is a ${n.kind}, not a document (use defineDocument to create one)`);(0,Mg.runInAction)(()=>n.set(t))}setBox(e,t){let n=this.requireNode(e);if(n.kind!==`box`)throw TypeError(`Variable "${e}" is a ${n.kind}, not a box (use defineBox to create a settable variable)`);(0,Mg.runInAction)(()=>n.set(t))}runInAction(e){(0,Mg.runInAction)(e)}has(e){return this.nodes.has(e)}getType(e){return this.requireVar(e).type}getKind(e){return this.requireNode(e).kind}changeKey(e){let t=this.requireNode(e);if(t.kind===`document`)return XB(t.read());try{return String(t.read())}catch(e){return`failed:${e instanceof Error?e.message:String(e)}`}}getNode(e){let t=this.requireNode(e);return t.kind===`document`?{name:t.name,kind:t.kind,read:()=>t.read(),lastUpdatedMs:()=>t.lastUpdatedMs()}:{name:t.name,type:t.type,kind:t.kind,read:()=>t.read(),lastUpdatedMs:()=>t.lastUpdatedMs()}}names(){return[...this.nodes.keys()]}requireNode(e){let t=this.nodes.get(e);if(!t)throw ReferenceError(`Unknown variable "${e}"`);return t}requireVar(e){let t=this.requireNode(e);if(t.kind===`document`)throw TypeError(`Variable "${e}" is a document; read its fields by path (.${e}.<field>)`);return t}assertNotDefined(e){if(this.nodes.has(e))throw Error(`Variable "${e}" is already declared`)}};function tV(e,{plugins:t,config:n}){let{checkout:r,loaded:i,dropped:a,unreached:o}=t,s=r===null?`-`:`${r.git?`git`:`dir`}:${r.root}`,c=e=>{let t=gP(e),r=t===void 0?void 0:n.variables[vP(t)];return r?.kind===`file`?r.path:`none`};return`config load ${e.join(` < `)||`<default>`}: plugins loaded=${i.length} dropped=${a.length} unplaced=${o.length} checkout=${s}`+i.map(e=>` +${e} data=${c(e)}`).join(``)+a.map(e=>` -${e.path} (${e.reason})`).join(``)+o.map(e=>` ~${e.path} (${e.reason})`).join(``)}function nV(e,t,n){return e+`\0`+t+`\0`+(n??``)}function rV(e,t){return new Set(qh(e.presets).filter(n=>Xh(e,n).path===`root`?t.root!==void 0:t.presets?.[n]?.root!==void 0))}function iV(e,t){let n=new Map,{roots:r,loaded:i,dropped:a,unreached:o}=e.state.plugins;for(let t of[...HP(e.projectDir,e.cwd,e.configFile),...r,...i,...[...a,...o].map(e=>e.path)]){let{dir:e,name:r}=Og(t),i=n.has(e)?n.get(e):new Set;i?.add(r),n.set(e,i)}for(let e of r){let{dir:t,name:r,leaf:i}=Og(l.join(e,`_`));i&&r===`_`&&n.set(t,null)}return{files:t,dirs:[...n.entries()].sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>t===null?{path:e}:{path:e,filenames:[...t].sort()})}}function aV(e){return e.filter(Boolean).join(`
204
+ `)||null}function oV(e,t,n,r,i=()=>{}){let{layers:a,config:o,installed:s}=nF(t.layers,TF,{entered:i,warned:e=>n.push(...e)},{projectDir:t.projectDir,cwd:e});i(a.length===1?a[0].path:null);let c=a.at(-1)?.config??TF,l=a.find(e=>e.path===t.home)?.raw??{},u=new eV,d=new Hw(u,o.globals.default_empty_value??``,r.gitService,r.sessionState),f;try{f=IB(o,d,{cwd:e}),n.push(...f.loadWarnings),pL(o),NA(o)}catch(e){throw d.dispose(),e}return{config:o,store:u,registry:d,compiled:f,neededInputPaths:yI(o),lastRenderCellsBySegment:new Map,authoredRoots:rV(c,l),fileHeldSettings:$I(l),unused:[...new Map(a.flatMap(e=>KB(e.raw,c)).map(e=>[`${e.kind}:${e.name}`,e])).values()],plugins:{checkout:s.checkout,roots:s.roots,loaded:[...s.rendering.values()],dropped:[...s.dropped,...a.flatMap(e=>e.plugins.dropped)],unreached:s.unreached,reached:s.reached,rendering:s.rendering}}}function sV(e,t,n,r){let i=WP(e,t,n),a={layers:i.kind===`chain`?i.layers:[],home:i.home,projectDir:e},o=[YP(e,t),qP(i)],s,c=null;try{s=oV(t,a,o,r,e=>{c=e})}catch(e){return e instanceof Jw&&o.push(...e.warnings),{layers:a.layers,home:a.home,failedFile:c,warning:aV(o),state:null,error:e instanceof Jw||e instanceof Error?e.message:String(e)}}return{layers:a.layers,home:a.home,warning:aV(o),state:s,error:null}}function cV(e,t,n){return oV(e,{layers:[],home:``,projectDir:t},[],n)}var lV=class{entries=new Map;deps;maxEntries;observers;constructor(e,t={}){this.deps=e,this.maxEntries=t.maxEntries??256,this.observers=t.observers??{}}getOrCreate(e,t,n){let r=nV(e,t,n),i=this.entries.get(r);if(i)return this.entries.delete(r),this.entries.set(r,i),i;let a=sV(e,t,n,this.deps);a.state!==null&&k(`info`,tV(a.layers,a.state));let o={projectDir:e,cwd:t,configFile:n,configLayers:[],configHome:``,failedFile:null,lastError:a.error,lastWarning:a.warning,state:a.state??cV(t,e,this.deps),watcher:null,watcherKey:null};if(this.entries.set(r,o),this.entries.size>this.maxEntries){let e=this.entries.entries().next().value;if(e!==void 0){let[t,n]=e;n.state.registry.dispose(),n.watcher?.release(),this.entries.delete(t)}}return this.refreshWatcher(o,a),this.observers.onReload?.(o),o}reload(e,t,n){this.reloadInto(this.getOrCreate(e,t,n))}reloadInto(e){let t=sV(e.projectDir,e.cwd,e.configFile,this.deps);e.lastWarning=t.warning,e.lastError=t.error,t.state!==null&&(k(`info`,tV(t.layers,t.state)),e.state.registry.dispose(),e.state=t.state),this.refreshWatcher(e,t),this.observers.onReload?.(e)}refreshWatcher(e,t){e.configLayers=t.layers,e.configHome=t.home,e.failedFile=t.error===null?null:t.failedFile;let n=iV(e,t.layers),r=`config:${e.projectDir}:${e.cwd}:${e.configFile??``}:${JSON.stringify(n)}`;e.watcher!==null&&e.watcherKey===r||(e.watcher?.release(),e.watcherKey=r,e.watcher=this.deps.watchers.acquire(r,n,()=>this.onConfigChanged(e)))}onConfigChanged(e){k(`info`,`config change detected for entry projectDir=${e.projectDir} cwd=${e.cwd}`),this.reloadInto(e)}get size(){return this.entries.size}firstState(){return this.entries.values().next().value?.state??null}};const uV=16384;var dV=class{startedAt=new Date;requestsTotal=0;requestsErrored=0;requestsTimedOut=0;inFlight=0;watchersOpened=0;watchersClosed=0;watchersEvicted=0;subprocessTotal=0;subprocessInFlight=0;subprocessCount=new Map;subprocessHistogram=new Map;subprocessHistogramRotator=new Map;rollingTimestamps=[];rollingHead=0;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)}};recordRollingNow(){let e=Date.now();if(this.rollingTimestamps.length<uV){this.rollingTimestamps.push(e);return}this.rollingTimestamps[this.rollingHead]=e,this.rollingHead=(this.rollingHead+1)%uV}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=Date.now()-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,p50DurationMs:r,p99DurationMs:i}}snapshot(e){let t=process.memoryUsage();return{pid:process.pid,version:wt,protocolVersion:3,startedAt:this.startedAt.toISOString(),uptimeSec:Math.floor((Date.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},gitCache:e.gitCache,usageCache:e.usageCache,renderCache:{size:e.renderCacheSize},effectCache:e.effectCache,watchers:{active:e.watchersActive,opened:this.watchersOpened,closed:this.watchersClosed,evicted:this.watchersEvicted},subprocesses:this.snapshotSubprocesses(),nextRestartReason:e.nextRestartReason??null,handlerProbes:e.handlerProbes}}};function fV(e,t,n){let r=(r,i,a)=>{let o=i.filter(t).map(t=>({key:t,before:e.get(r,t)}));a();for(let{key:t,before:i}of o)n(r,t,i,e.get(r,t))};return{get:(t,n)=>e.get(t,n),revision:t=>e.revision(t),set:(t,n,i)=>r(t,[n],()=>e.set(t,n,i)),setBatch:(t,n)=>r(t,n.map(e=>e.key),()=>e.setBatch(t,n)),clear:(t,n)=>r(t,[n],()=>e.clear(t,n))}}const pV={load:()=>({}),save:()=>{},flush:()=>{}};var mV=class{sessions;storage;head=0;atom=(0,Mg.createAtom)(`SessionState`);constructor(e=pV,t=256){this.maxSessions=t,this.storage=e,this.sessions=new Map,this.hydrateFromStorage()}useStorage(e){this.storage=e,this.hydrateFromStorage()}hydrateFromStorage(){this.sessions=new Map(Object.entries(this.storage.load()).map(([e,t])=>[e,{values:new Map(Object.entries(t)),revision:++this.head}])),this.evictOldest(),this.persist()}get(e,t){this.atom.reportObserved();let n=this.sessions.get(e);return n?(this.touch(e,n),n.values.get(t)??null):null}revision(e){return this.atom.reportObserved(),this.sessions.get(e)?.revision??0}set(e,t,n){this.setBatch(e,[{key:t,value:n}])}setBatch(e,t){t.length!==0&&(0,Mg.runInAction)(()=>{let n=this.sessions.get(e)??{values:new Map,revision:0};t.some(({key:e,value:t})=>n.values.get(e)!==t)&&(n.revision=++this.head);for(let{key:e,value:r}of t)n.values.set(e,r);this.touch(e,n),this.evictOldest(),this.persist(),this.atom.reportChanged()})}clear(e,t){(0,Mg.runInAction)(()=>{let n=this.sessions.get(e);n&&(n.values.delete(t)&&(n.revision=++this.head),n.values.size===0?this.sessions.delete(e):this.touch(e,n)),this.persist(),this.atom.reportChanged()})}prune(e){(0,Mg.runInAction)(()=>{for(let t of this.sessions.keys())e.has(t)||this.sessions.delete(t);this.persist(),this.atom.reportChanged()})}touch(e,t){this.sessions.delete(e),this.sessions.set(e,t)}evictOldest(){let e=this.sessions.size-this.maxSessions;if(!(e<=0)){for(let t of this.sessions.keys())if(this.sessions.delete(t),--e===0)break}}flush(){this.storage.flush()}persist(){this.storage.save(this.serialize())}serialize(){let e=Object.create(null);for(let[t,{values:n}]of this.sessions)e[t]=Object.fromEntries(n);return e}};function hV(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 gV=class{timer=null;pending=null;constructor(e,t=500,n=Nt){this.filePath=e,this.debounceMs=t,this.logger=n}load(){let e;try{e=r.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 hV(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.timer&&(this.timer=setTimeout(()=>this.flush(),this.debounceMs),this.timer.unref())}flush(){if(this.timer&&=(clearTimeout(this.timer),null),this.pending===null)return;let e=this.pending;try{r.mkdirSync(l.dirname(this.filePath),{recursive:!0});let t=`${this.filePath}.tmp`;r.writeFileSync(t,JSON.stringify(e),{mode:384}),r.chmodSync(t,384),r.renameSync(t,this.filePath),this.pending=null}catch(e){this.logger(`warn`,`session-state save failed: ${e.message}`)}}};const _V={default_empty_value:`string`,default_separator:`string`,palette:`string`,style:`string`,effect:`string`,preset:`string`,endcaps:`string`,variation:`string`,shade:`string`,autoWrap:`boolean`,padding:`number`,charset:`string`,updateNotice:`boolean`,transitions:`boolean`,colorCompatibility:`string`,menuGlyph:`string`},vV=new Set([`1`,`true`]),yV=new Set([`0`,`false`,``]);function bV(e,t){let n=GV(e),r=n.scope===`segment-palette`?`string`:_V[n.field];if(r===`string`)return JSON.stringify(t);if(r===`number`){let n=Number(t);if(!Number.isFinite(n))throw Error(`persistValueText: "${e}" expects a number, got "${t}"`);return String(n)}if(vV.has(t))return`true`;if(yV.has(t))return`false`;throw Error(`persistValueText: "${e}" expects boolean-ish (1, 0, true, false), got "${t}"`)}function xV(e){try{return r.readFileSync(e,`utf8`)}catch(e){if(e.code===`ENOENT`)return null;throw e}}function SV(e,t,n){try{if(t===null){r.rmSync(e,{force:!0});return}r.mkdirSync(l.dirname(e),{recursive:!0}),Fe(e,t)}catch(t){let r=`config write failed (${e}): ${t.message}`;throw n(`error`,r),Error(r)}}function CV(e){return/^\s*$/.test(e)?null:_r(e)}function wV(e,t){return e!==null&&yr(e,t)!==void 0}function TV(e){if(e.kind===`segment`)return e.when===void 0?e.name:{seg:e.name,when:e.when};if(e.kind===`container`){let{kind:t,direction:n,children:r,...i}=e;return{[n===`horizontal`?`h`:`v`]:r.map(TV),...i}}return e}function EV(e){if(!Lh(e))return TV(e);let{rows:t,...n}=e;return{rows:Object.fromEntries(Object.entries(t).map(([e,t])=>[e,TV(t)])),...n}}const DV=CF,OV=DV.segments,kV=DV.presets,AV=DV.root;function jV(e,t,n,r){if(!wV(e,t)&&n===void 0)throw new J(`cannot edit ${r}: neither the config file nor the bundled default declares ${t.join(`.`)}`)}function MV(e,t){let n=WE(t);return t.scope===`segment-palette`&&jV(e,[`segments`,t.segment],OV[t.segment],n.join(`.`)),n}function NV(e){return _r(Dr(e))}function PV(){return Object.entries(AV.rows).map(([e,t])=>{let n=TV(t);return{path:[`root`],fragment:NV({rows:{[e]:n}}),unit:{path:[`root`,`rows`,e],value:n}}})}function FV(e,t){let n=e===null?void 0:yr(e,t);return n===void 0?null:{path:t,fragment:n,unit:null}}function IV(e,t){if(t===void 0)return null;let n=EV(t);return{path:e,fragment:NV(n),unit:{path:e,value:n}}}function LV(e,t){let n=[`presets`,t],r=[...n,`root`],i=kV[t];jV(e,n,i,r.join(`.`));let a=FV(e,r)??IV(r,i?.root);return a!==null&&Jr(a.fragment)?a:null}function RV(e,t){let n=qr(t.fragment);return n===null?new Map([[`#`,{path:t.path,unit:t.unit,node:t.fragment}]]):new Map([...e,...n.map(e=>[e.key,{path:[...t.path,`rows`,e.key],unit:t.unit,node:e.value}])])}function zV(e,t){return[...PV(),FV(e,[`root`]),LV(e,t)].filter(e=>e!==null).reduce(RV,new Map)}function BV(e,t,n){for(let{node:r,...i}of zV(e,t).values())if(Xr(r,n))return i;throw new J(`${VV(e,t).join(`.`)} holds no placement "${n}" — the bar you clicked is stale (it reloads on the next render), or the action names a placement the layout never held`)}function VV(e,t){return LV(e,t)?.path??[`root`]}function HV(e,t){return t.scope===`preset-root`?VV(e,t.preset):WE(t)}function UV(e,{unit:t}){return t===null?e:Vr(e,t.path,Dr(t.value),Tr)}function WV(e){let t=UE(e);if(t===null)throw Error(`"${e}" is not a valid persist target`);return t}function GV(e){let t=WV(e);if(t.scope===`preset-root`)throw Error(`"${e}" names a layout, not a value`);return t}function KV(e,t,n,r,i){i(t,n,rH(t,r)),SV(t.path,r,e.logger),e.record(t.path,n,r)}function qV(e,t,n){let r=XV(e,t,n);if(r.length>0)throw new J(`refused: ${e.above.join(`, `)} sets ${r.join(`, `)} over ${e.path}, so this click would change nothing on the bar — edit it there`)}const JV=()=>{};function YV(e,t){try{return t()}catch(t){throw!(t instanceof J)||e.above.length===0?t:new J(`${t.message} — or it is declared by ${e.above.join(`, `)}, which the bar does not edit`)}}function XV(e,t,n){let r=ZV(e,t);if(r===null)return[];let i=new Set(tH(eH(r),eH(n)));return tH($V(e,r),$V(e,n)).filter(e=>!i.has(e))}function ZV(e,t){try{return QV(e,t)}catch(e){if(e instanceof Jw)return null;throw e}}function QV(e,t){return nF(t===null?e.above:[e.path,...e.above],TF,{entered:()=>{},warned:()=>{}},{projectDir:e.projectDir,cwd:e.cwd},n=>n===e.path&&t!==null?t:r.readFileSync(n,`utf8`))}function $V(e,t){let[n]=t.layers;return n?.path===e.path?n.config:t.base}function eH(e){return e.layers.at(-1)?.config??e.base}function tH(e,t,n=``){return!nH(e)||!nH(t)?JSON.stringify(e)===JSON.stringify(t)?[]:[n]:[...new Set([...Object.keys(e),...Object.keys(t)])].flatMap(r=>tH(e[r],t[r],n===``?r:`${n}.${r}`))}function nH(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function rH(e,t){try{return QV(e,t)}catch(e){throw e instanceof Jw?new J(`refused: the config file would not load after this click — ${e.message}`):e}}function iH(e,t){let n=GV(t),r=CV(xV(e)??``),i=r===null?void 0:yr(r,WE(n));return i!==void 0&&`value`in i?i.value:void 0}function aH(e,t,n){oH(e,t,n,[])}function oH(e,t,n,r){let i=xV(t.path),a=n.reduce((e,[t,n])=>Vr(e,MV(CV(e),GV(t)),bV(t,n),Tr),i??``);KV(e,t,i,YV(t,()=>sH(a,t.path,r,e=>e)),qV)}function sH(e,t,n,r){return n.reduce((e,{preset:n,id:i,setting:a,value:o})=>{let s=r(e,n,i),c=BV(CV(s),n,i),l=ei(UV(s,c),c.path,i,a,Dr(o));if(l===null)throw new J(`${c.path.join(`.`)} in ${t} has no placement "${i}" — the bar you clicked is stale (it reloads on the next render)`);return l},e)}function cH(e,t,n){let r=CV(e),i=[`presets`,t,`root`];for(let[a,{path:o,unit:s,node:c}]of zV(r,t)){if(!Xr(c,n))continue;if(i.every((e,t)=>o[t]===e))return e;let l=s===null?xr(e,c):Dr(s.value);if(a!==`#`)return Vr(e,[...i,`rows`,a],l,Tr);if(LV(r,t)!==null)throw new J(`cannot give preset "${t}" its own copy of ${o.join(`.`)}: it already stages rows of its own over that tree`);return Vr(e,i,l,Tr)}return e}function lH(e,t){return Ur(e,t,t[0]===`presets`&&t.length>2&&!DF(t[1])?2:0)}function uH(e,t,n){let r=n.map(WV),i=xV(t.path);if(i===null)return;let a=r.reduce((e,t)=>lH(e,HV(CV(e),t)),i);a!==i&&KV(e,t,i,a,JV)}function dH(e){let t=e===null?void 0:yr(e,[`presets`]);return t?.kind===`object`?t.entries.map(e=>e.key):[]}function fH(e,t){let n=new Set([...EF,...dH(e),...t.above.flatMap(e=>Object.keys(ur.default.parse(r.readFileSync(e,`utf8`)).presets??{}))].map(qw));return Array.from({length:n.size+1},(e,t)=>`custom-${t+1}`).find(e=>!n.has(qw(e)))}function pH(e,t,n,r,i,a){let o=xV(t.path),s=CV(o??``),c=fH(s,t),l=[`presets`,c],u=YV(t,()=>LV(s,n)),d=[...u===null?[]:[[[...l,`root`],u.unit===null?xr(o??``,u.fragment):Dr(u.unit.value)]],...Object.keys(r).length===0?[]:[[[...l,`globals`],Dr(r)]]],f=i.map(([e,t])=>{let n=HE(c,e);return[MV(s,GV(n)),bV(n,t)]}),p=[...d,...f].reduce((e,[t,n])=>Vr(e,t,n,Tr),Vr(o??``,l,`{}`,Tr));return KV(e,t,o,YV(t,()=>sH(p,t.path,a.map(e=>({...e,preset:c})),cH)),qV),c}function mH(e,t,n,r){let i=xV(t.path);KV(e,t,i,Vr(i??``,[`themeDefaults`,n],Dr(r),Tr),qV)}function hH(e,t,n){if(DF(n))throw new J(`cannot delete preset "${n}": it is bundled — reset its settings instead`);let r=[`presets`,n],i=xV(t.path),a=CV(i??``);if(i===null||a===null||yr(a,r)===void 0)throw new J(`cannot delete preset "${n}": ${t.path} declares no ${r.join(`.`)} — the bar you clicked is stale; it reloads on the next render`);let o=yr(a,[`globals`,`preset`]);KV(e,t,i,[r,...o?.kind===`string`&&o.value===n?[[`globals`,`preset`]]:[]].reduce((e,t)=>lH(e,t),i),JV)}function gH(e,t,n,r){let i=WV(n);if(i.scope!==`preset-root`)throw Error(`"${n}" is not a "presets.<name>.root" target`);let a=xV(t.path),o=r.op===`remove`?r.target:r.anchor,s=YV(t,()=>BV(CV(a??``),i.preset,o)),c=UV(a??``,s),{after:l,placed:u}=_H(c,s.path,r,()=>{let e=rH(t,c).config;return qh(e.presets).map(t=>Xh(e,t).node)});if(l===null)throw new J(`${s.path.join(`.`)} in ${t.path} has no placement "${o}" — the bar you clicked is stale (it reloads on the next render), or the action names a placement the layout never held`);return KV(e,t,a,l,qV),u}function _H(e,t,n,r){switch(n.op){case`remove`:return{after:Qr(e,t,n.target),placed:null};case`insert`:{let i=bA(n.segment,n.anchor,r());return{after:$r(e,t,i,n.anchor,n.relation),placed:i}}}}const vH={load:()=>({}),save:()=>{}},yH=new Set(ma.map(e=>e.sessionKey)),bH=e=>yH.has(e)||e.startsWith(tD),xH=8*1024*1024,SH={past:[],future:[]},CH=e=>e.kind===`session`?`session:${e.key}`:`file:${e.file}`;var wH=class{state=new Map;constructor(e,t,n=vH){this.sessionState=e,this.logger=t,this.storage=n,this.state=new Map(Object.entries(n.load()))}useStorage(e){this.storage=e,this.state=new Map(Object.entries(e.load()))}depth(e){let{past:t,future:n,savepoint:r}=this.state.get(e)??SH;return{undo:t.length,redo:n.length,sinceEdit:r?.net.length??0}}history(e){return this.state.get(e)??SH}begin(){let e=new Map,t=(t,n)=>{let r=e.get(t)??new Map,i=r.get(CH(n));r.set(CH(n),i===void 0?n:{...n,before:i.before}),e.set(t,r)},n=new Map;return{sessionState:fV(this.sessionState,e=>bH(e)||e===`edit.mode`,(e,r,i,a)=>{if(r===`edit.mode`){let t=n.get(e);n.set(e,{before:t===void 0?i:t.before,after:a});return}t(e,{kind:`session`,key:r,before:i,after:a})}),file:(e,n,r,i)=>t(e,{kind:`file`,file:n,before:r,after:i}),commit:()=>{let t=new Map(e),r=new Map(n);e.clear(),n.clear();for(let e of new Set([...t.keys(),...r.keys()])){let n=[...t.get(e)?.values()??[]].filter(e=>e.before!==e.after),i=this.history(e),a=n.length===0?i:MH(i,n),o=r.get(e),s=o===void 0?a:IH(a,o);s!==i&&this.put(e,s)}}}}undo(e){let t=this.history(e),n=t.past.at(-1);if(n===void 0)throw new J(`undo: nothing to undo`);return this.apply(e,n,`before`,`undo`,PH(t,n)),n}rewind(e){let t=this.history(e),{savepoint:n}=t;if(n===void 0)throw new J(`rewind: edit mode has no savepoint — nothing to cancel`);let r=n.net.filter(t=>this.read(e,t)!==t.after),i=new Set(r.map(CH)),a=n.net.filter(e=>!i.has(CH(e))),o=DH(LH(FH(t,n),i));if(this.apply(e,a,`before`,`rewind`,{past:o,future:[],savepoint:{at:o.length,net:[],below:[]}}),r.length>0)throw new J(`rewind: ${r.map(zH).join(`, `)} changed since edit mode opened — kept as it is; everything else edit mode changed was put back`);return a}redo(e){let t=this.history(e),{past:n,future:r}=t,i=r.at(-1);if(i===void 0)throw new J(`redo: nothing to redo`);let a=[...n,i],o=DH(a);return this.apply(e,i,`after`,`redo`,{past:o,future:r.slice(0,-1),...kH(t.savepoint,a.length-o.length,i)}),i}apply(e,t,n,r,i){let a=n===`before`?`after`:`before`,o=t.filter(t=>this.read(e,t)!==t[a]);if(o.length>0){let t=new Set(o.map(CH)),{past:n,future:i,savepoint:a}=this.history(e);throw this.put(e,{past:LH(n,t),future:LH(i,t),...a!==void 0&&{savepoint:{at:LH([...n,...[...i].reverse()].slice(0,a.at),t).length,net:a.net.filter(e=>!t.has(CH(e))),below:LH(a.below,t)}}}),new J(`${r}: ${o.map(zH).join(`, `)} changed since that edit — refusing to overwrite it; this session's undo history no longer steps it`)}let s=[];try{for(let r of t)this.write(e,r,r[n]),s.push(r);this.put(e,i)}catch(t){try{for(let t of s.reverse())this.write(e,t,t[a])}catch(e){throw Error(`${t.message}; and putting the step back failed, so it is half-applied: ${e.message}`)}throw t}}read(e,t){return t.kind===`session`?this.sessionState.get(e,t.key):xV(t.file)}write(e,t,n){t.kind===`file`?SV(t.file,n,this.logger):n===null?this.sessionState.clear(e,t.key):this.sessionState.set(e,t.key,n)}put(e,t){let n=new Map(this.state);for(n.delete(e),(t.past.length>0||t.future.length>0||t.savepoint!==void 0)&&n.set(e,t);n.size>32||TH(n)>xH;){let[e,t]=n.entries().next().value;n.size>1?n.delete(e):t.past.length+t.future.length>0?n.set(e,EH(t)):(this.logger(`warn`,`settings-history: edit mode's changes for session ${e} exceed ${xH} bytes; cancel is no longer available`),n.delete(e))}this.storage.save(Object.fromEntries(n)),this.state=n}};function TH(e){let t=0;for(let{past:n,future:r,savepoint:i}of e.values())for(let e of[...n,...r,...i===void 0?[]:[i.net,...i.below]])for(let n of e)t+=(n.before?.length??0)+(n.after?.length??0);return t}function EH({past:e,future:t,savepoint:n}){return e.length>0?{past:e.slice(1),future:t,...kH(n,1,[])}:{past:e,future:t.slice(1),...kH(n,0,[])}}function DH(e){return e.slice(-50)}const OH=e=>e===rD.member;function kH(e,t,n){return e===void 0?{}:{savepoint:{at:Math.max(0,e.at-t),net:AH(e.net,n),below:e.below}}}function AH(e,t){let n=new Map(e.map(e=>[CH(e),e]));for(let e of t){let t=n.get(CH(e));n.set(CH(e),t===void 0?e:{...t,after:e.after})}return[...n.values()].filter(e=>e.before!==e.after)}const jH=e=>e.map(e=>({...e,before:e.after,after:e.before}));function MH(e,t){let n=[...e.past,t],r=DH(n),{savepoint:i}=e,a=i===void 0?0:Math.max(0,i.at-e.past.length);return{past:r,future:[],...kH(i&&{at:Math.min(i.at,e.past.length),net:i.net,below:[...NH(e.future,a),...i.below]},n.length-r.length,t)}}function NH(e,t){let n=Math.min(t,e.length);return e.slice(e.length-n).reverse()}function PH(e,t){return{past:e.past.slice(0,-1),future:DH([...e.future,t]),...kH(e.savepoint,0,jH(t))}}function FH(e,t){let{past:n,future:r}=e,i=n.slice(0,t.at);return[...i,...NH(r,t.at-i.length),...t.below]}function IH(e,t){if(OH(t.after)&&!OH(t.before))return{...e,savepoint:{at:e.past.length,net:[],below:[]}};if(!OH(t.after)&&OH(t.before)){let{past:t,future:n}=e;return{past:t,future:n}}return e}function LH(e,t){return e.map(e=>e.filter(e=>!t.has(CH(e)))).filter(e=>e.length>0)}function RH(e){return e.map(zH).join(`, `)}function zH(e){return e.kind===`session`?`session setting "${e.key}"`:e.file}function BH(e){if(typeof e!=`object`||!e)return!1;let t=e,n=e=>e===null||typeof e==`string`;return(t.kind===`session`&&typeof t.key==`string`||t.kind===`file`&&typeof t.file==`string`)&&n(t.before)&&n(t.after)}function VH(e){return Array.isArray(e)&&e.every(e=>Array.isArray(e)&&e.every(BH))}function HH(e){if(typeof e!=`object`||!e)return!1;let t=e;return Number.isInteger(t.at)&&t.at>=0&&Array.isArray(t.net)&&t.net.every(BH)&&VH(t.below)}function UH(e){if(typeof e!=`object`||!e)return!1;let t=e;return VH(t.past)&&VH(t.future)&&(t.savepoint===void 0||HH(t.savepoint))}function WH(e,t){let n=e=>e.kind===`file`||bH(e.key)?!0:(t.add(e.key),!1),r=e=>e.map(e=>e.filter(n)).filter(e=>e.length>0),{savepoint:i}=e,a=r(e.past),o=r(e.future);return i===void 0?{past:a,future:o}:{past:a,future:o,savepoint:{at:r(e.past.slice(0,i.at)).length,net:i.net.filter(n),below:r(i.below)}}}function GH(e,t){return{load:()=>{let n;try{n=r.readFileSync(e,`utf8`)}catch(e){let n=e.code;return n!==`ENOENT`&&t(`warn`,`settings-history read failed (${n}); starting empty`),{}}try{let e=JSON.parse(n);if(typeof e==`object`&&e&&!Array.isArray(e)&&Object.values(e).every(UH)){let n=new Set,r=Object.fromEntries(Object.entries(e).map(([e,t])=>[e,WH(t,n)]));return n.size>0&&t(`warn`,`settings-history load: dropped the changes to ${[...n].map(e=>`"${e}"`).join(`, `)}, no longer a setting`),r}}catch{}return t(`warn`,`settings-history load: unexpected shape, starting empty`),{}},save:n=>{try{r.mkdirSync(l.dirname(e),{recursive:!0}),Fe(e,JSON.stringify(n),384)}catch(e){let n=`settings-history write failed — the change landed but is not undoable: ${e.message}`;throw t(`error`,n),Error(n)}}}}const KH=e=>!bH(e)&&!WD(e)&&e!==`update.dismissed`;var qH=class{past=new Map;depth(e,t,n){return this.restorable(e,t,n).length}restorable(e,t,n){let r=new Map,i=n=>r.has(n)?r.get(n):t.get(e,n),a=[];for(let t of[...this.past.get(e)??[]].reverse())if(t.every(e=>i(e.key)===e.after&&(e.before===null||n.validate(e.key,e.before).ok))){a.unshift(t);for(let e of t)r.set(e.key,e.before)}return a}begin(e){let t=new Map;return{sessionState:fV(e,KH,(e,n,r,i)=>{let a=t.get(e)??new Map,o=a.get(n);a.set(n,{key:n,before:o?o.before:r,after:i}),t.set(e,a)}),commit:()=>{for(let[e,n]of t){let t=[...n.values()].filter(e=>e.before!==e.after);t.length>0&&this.push(e,t)}t.clear()}}}back(e,t,n){let r=this.past.get(e)??[],i=this.restorable(e,t,n),a=i.at(-1),o=r.length-i.length;if(a===void 0)throw this.put(e,i),new J(`back: nothing to go back to${o>0?` (${o} step(s) over a view since gone, discarded)`:``}`);return(0,Mg.runInAction)(()=>{let n=a.flatMap(({key:e,before:t})=>t===null?[]:[{key:e,value:t}]);n.length>0&&t.setBatch(e,n);for(let{key:n,before:r}of a)r===null&&t.clear(e,n)}),this.put(e,i.slice(0,-1)),{step:a,discarded:o}}push(e,t){let n=this.past.get(e)??[];this.put(e,[...n,t].slice(-20))}put(e,t){for(this.past.delete(e),t.length>0&&this.past.set(e,t);this.past.size>32;)this.past.delete(this.past.keys().next().value)}};function JH(e){let t=AR(e,`doctor.tmux`,[`display`,`-p`,`-t`,e.pane,`#{client_termfeatures}`]);return t.kind===`ok`?{kind:`ok`,value:t.stdout.trim().split(`,`).filter(e=>e!==``)}:{kind:`failed`,reason:t.reason}}function YH(e){return{probeTmux:JH,loadConfig:e}}function XH(e){let t={layers:e.layers,warnings:e.warning===null?[]:e.warning.split(`
205
+ `)};return e.error===null?{...t,kind:`loaded`,unused:e.unused}:{...t,kind:`failed`,error:e.error}}function ZH(e){let{env:t,statusLine:n}=oi(e);if(t!==void 0&&!si(t))throw Error(`cannot read ${e}: \`env\` is not an object`);return{path:e,env:t??{},statusLine:n===void 0?{kind:`absent`}:si(n)?{kind:`present`,refreshInterval:n.refreshInterval}:{kind:`not-an-object`,value:n}}}function QH(e,t){return t===void 0?{kind:`unreported`}:t===null?{kind:`outside`}:{kind:`inside`,hint:t,termfeatures:e.probeTmux(t)}}function $H(e){return{kind:`arrived`,handler:e,bar:wt}}function eU(e,t,n){let r=new Map;for(let i of dh(Xh(e,t).node)){if(i.kind!==`segment`)continue;let t=wh(e.segments[i.name])[Sh],a=Ah(i,Sh,t,e=>n(e.key));a===`bar`||a===`none`||r.set(i.drafts?.effect?.id??sh(i),a)}return[...r].map(([e,t])=>({placement:e,effect:t}))}function tU(e,t,n,r){let i=e.loadConfig(n),a=iI(i.config,r,()=>!1);return{tmux:QH(e,t.tmux),config:XH(i),effect:a.effect,placementEffects:eU(i.config,a.preset,r),transitions:a.transitions,claudeSettings:ZH(ri(ni(t.claudeConfigDir)))}}function nU(e,t){let n=t.claudeSettings.path;switch(e.kind){case`claude-settings`:{let i=Vr(ai(n),e.path,JSON.stringify(e.value),Er);return r.mkdirSync(l.dirname(n),{recursive:!0}),Fe(n,i),{...t,claudeSettings:ZH(n)}}default:return e.kind}}const rU={connectMs:200,budgetMs:500};async function iU(e){let n=e.includes(`--json`),r=await aU();if(r.kind!==`ok`&&(t.stderr.write(`daemon-stats: ${Ct(r)}\n`),t.exit(1)),n){t.stdout.write(JSON.stringify(r.value,null,2)+`
206
+ `);return}t.stdout.write(lU(r.value))}function aU(){return _t({kind:`stats`},rU,e=>`stats`in e?e.stats:void 0)}function oU(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/1024/1024).toFixed(1)}MB`}function sU(e,t){let n=e+t;return n===0?`n/a`:`${(e/n*100).toFixed(1)}%`}function cU(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 lU(e){let t=[];t.push(`cc-candybar daemon stats`),t.push(``),t.push(`process`),t.push(` pid ${e.pid}`),t.push(` version ${e.version}`),t.push(` protocol ${e.protocolVersion}`),t.push(` startedAt ${e.startedAt}`),t.push(` uptime ${cU(e.uptimeSec)}`),t.push(` rss ${oU(e.rssBytes)}`),t.push(` heapUsed ${oU(e.heapUsedBytes)}`),t.push(` heapTotal ${oU(e.heapTotalBytes)}`),t.push(` external ${oU(e.externalBytes)}`),t.push(` arrayBuffers ${oU(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(``),t.push(`gitCache`),t.push(` size ${e.gitCache.size}`),t.push(` hit rate ${sU(e.gitCache.hits,e.gitCache.misses)} (${e.gitCache.hits} / ${e.gitCache.hits+e.gitCache.misses})`),t.push(` invalidations ${e.gitCache.invalidations}`),t.push(``),t.push(`usageCache`),t.push(` size ${e.usageCache.size}`),t.push(` hit rate ${sU(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(`renderCache`),t.push(` size ${e.renderCache.size}`),t.push(``),t.push(`effectCache`),t.push(` sessions ${e.effectCache.sessions}`),t.push(` effects ${e.effectCache.effects}`),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(` evicted ${e.watchers.evicted}`),t.push(``),t.push(`subprocesses`),t.push(` total ${e.subprocesses.total}`),t.push(` inFlight ${e.subprocesses.inFlight}`),t.push(` lastMinute ${e.subprocesses.lastMinute}`);let n=Object.entries(e.subprocesses.byCategory),r=n.reduce((e,[t])=>Math.max(e,t.length),13);for(let[i,a]of n){let n=e.subprocesses.p50DurationMs[i],o=e.subprocesses.p99DurationMs[i],s=n!==void 0&&o!==void 0?` (p50 ${n}ms · p99 ${o}ms)`:``;t.push(` ${i.padEnd(r)} ${a}${s}`)}return e.nextRestartReason&&(t.push(``),t.push(`nextRestart ${e.nextRestartReason}`)),t.join(`
207
207
  `)+`
208
- `}const cU=e=>({kind:`ok`,value:e}),lU=e=>({kind:`failed`,reason:e});var uU=class{arrivals=[];arrive(e){this.arrivals=[...this.arrivals,e].slice(-16)}list(){return this.arrivals}};const dU=/^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$/;function fU(e){return dU.test(e)?e:null}function pU(e){let t=e.opener();if(t.kind===`failed`)return t;if(t.value===null)return cU(null);let n=t.value,r=e.script(n);if(r.kind===`failed`)return cU({app:n,missing:lU(`its script could not be read (${r.reason})`)});let i=Oi(r.value);return cU({app:n,missing:i===null?lU("its script is not one `cc-candybar install` wrote"):cU([i.node,i.script].filter(t=>!e.exists(t)))})}async function mU(e,t){let n=e.now()+5e3;for(;e.now()<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`,handler:r.handler,bar:n.value.version}}return null}async function hU(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} (CC_CANDYBAR_SOCKET); the URL handler delivers links 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=e.open(`${mn}://${In}/${n}`);return(r===null?await mU(e,n):null)??{kind:`lost`,unopened:r,opener:pU(e)}}function gU(e,t,n){let r=Me({bin:t,args:[...n],category:e,timeoutMs:5e3});return r.ok?cU(r.stdout):lU(r.stderr.trim()||r.error||r.reason)}const _U=`ObjC.import("AppKit");var u = $.NSWorkspace.sharedWorkspace.URLForApplicationToOpenURL($.NSURL.URLWithString("${mn}://probe"));u.isNil() ? "" : u.path.js`;async function vU(){let e=await rU();if(e.kind!==`ok`)return lU(Ct(e).split(`
209
- `).join(` — `));let{version:t,handlerProbes:n}=e.value;return Array.isArray(n)?cU({version:t,arrivals:n}):lU(`the running daemon (${t}) predates this check`)}function yU(){return{platform:process.platform,sockets:{own:Be(),handler:Ve()},now:Date.now,nonce:w,daemon:vU,open:e=>{let t=gU(`doctor.open`,`/usr/bin/open`,[`-g`,e]);return t.kind===`ok`?null:t.reason},pause:()=>new Promise(e=>setTimeout(e,100)),opener:()=>{let e=gU(`doctor.launch-services`,`/usr/bin/osascript`,[`-l`,`JavaScript`,`-e`,_U]);if(e.kind===`failed`)return e;let t=e.value.trim();return cU(t===``?null:t)},script:e=>gU(`doctor.osadecompile`,`/usr/bin/osadecompile`,[ki(e)]),exists:r.existsSync}}const bU=/^─{20,}/,xU=/^❯(\s|$)/,SU=/›\s*stashed$/;function CU(e){if(e.inMode)return{kind:`in-mode`};let t=e.screen.map(e=>e.trimEnd()),n=t.flatMap((e,t)=>bU.test(e)?[t]:[]).at(-2);return n===void 0||!xU.test(t[n+1]??``)?{kind:`no-prompt`}:SU.test(t[n-1]??``)?{kind:`stashed`}:{kind:`ready`}}const wU={"in-mode":`the Claude Code pane is in tmux copy mode — leave it (q) and click again`,stashed:`Claude Code is holding a stashed prompt (ctrl+s) — restore or send it, then click again`,"no-prompt":`Claude Code is not at its prompt (a dialog or picker is open) — close it and click again`};function TU(e,t,n){if(t===void 0)return{kind:`refused`,reason:`this session's statusline client reports no tmux facts (it predates this daemon) — rebuild or reinstall cc-candybar`};if(t===null)return{kind:`refused`,reason:`this Claude Code is not running inside tmux — the bar can only type into a tmux pane`};let r=CU(e.read(t));if(r.kind!==`ready`)return{kind:`refused`,reason:wU[r.kind]};let i=e.type(t,n);return i.kind===`typed`?{kind:`typed`,pane:t.pane}:i}const EU=`cc-candybar-slash`;function DU(e,t,n,r){let i=OR(e,t,n,r);if(i.kind===`failed`)throw Error(i.reason);return i}function OU(e){let t=DU(e,`claude-input.read`,[`display`,`-p`,`-t`,e.pane,`#{pane_in_mode}`,`;`,`capture-pane`,`-p`,`-t`,e.pane]);if(t.kind===`rate-limited`)throw Error(t.reason);let[n=``,...r]=t.stdout.split(`
210
- `);return{inMode:n!==`0`,screen:r}}function kU(e,t){let n=DU(e,`claude-input.type`,[`load-buffer`,`-b`,EU,`-`,`;`,`send-keys`,`-t`,e.pane,`C-s`,`;`,`paste-buffer`,`-p`,`-d`,`-b`,EU,`-t`,e.pane,`;`,`send-keys`,`-t`,e.pane,`Enter`],t);return n.kind===`ok`?{kind:`typed`}:{kind:`refused`,reason:`cc-candybar typed a command moments ago — click again in a second (${n.reason})`}}function AU(){return{read:OU,type:kU}}function jU(e){if(!e)throw new J(`session id is required`);if(e.includes(`/`)||e.includes(`..`))throw new J(`invalid session id "${e}"`);return e}function MU(e){return NU(()=>decodeURIComponent(e))}function NU(e){try{return e()}catch(e){throw e instanceof URIError?new J(`malformed wire encoding: ${e.message}`):e}}function PU(e,t){let n=Me({bin:`/usr/bin/pbcopy`,stdinInput:e,category:`click.pbcopy`});if(!n.ok){if(n.reason===`rate-limited`){t.dlog(`warn`,`click.pbcopy rate-limited: ${n.error??``}`);return}throw Error(`pbcopy failed (${n.reason}, exit ${n.exitCode??`null`})`)}}const FU=(e,t)=>PU(MU(e),t),IU=(e,t)=>{let n=Me({bin:`/usr/bin/open`,args:[`-a`,`Visual Studio Code`,MU(e)],category:`click.open`});if(!n.ok){if(n.reason===`rate-limited`){t.dlog(`warn`,`click.open rate-limited: ${n.error??``}`);return}throw Error(`open -a "Visual Studio Code" failed (${n.reason}, exit ${n.exitCode??`null`})`)}},LU=(e,t)=>PU(MU(e),t),RU=(e,t)=>PU(MU(e),t),zU=(e,t)=>{let n=jU(MU(e));t.navigating.get(n,`toolbar-expanded`)?t.navigating.clear(n,`toolbar-expanded`):t.navigating.set(n,`toolbar-expanded`,`1`)},BU=(e,t)=>{let[n=``,...r]=NU(()=>zn(e)),i=jU(n),a=dL(QU(t,i));if(r.length===0)throw new J(`set-state: <key>/<value> is required (have keys: ${a.listKeys().join(`, `)})`);if(r.length%2!=0)throw new J(`set-state: expected even-count <key>/<value> pairs, got ${r.length} segment(s) after session id (have keys: ${a.listKeys().join(`, `)})`);let o=[];for(let e=0;e<r.length;e+=2){let t=r[e],n=r[e+1];if(!t)throw new J(`set-state: empty key at pair ${e/2+1} (expected <sessionId>/<key>/<value>[/<key>/<value>...] segments)`);let i=a.validate(t,n);if(!i.ok)throw new J(`set-state: pair ${e/2+1}: ${i.reason}`);o.push({key:t,value:i.value})}WU(t,i,`set-state`,o),t.navigating.setBatch(i,o);let s=o.map(e=>`${e.key}=${e.value}`).join(` `);t.dlog(`info`,`set-state: ${s} (session=${i})`)},VU=/^-?\d+$/;function HU(e,t,n,r){let i=e+t;return i>r?e===r?n:r:i<n?e===n?r:n:i}const UU=(e,t)=>{let[n=``,r=``,i=``]=NU(()=>zn(e)),a=jU(n);if(!r)throw new J(`step-state: <key> is required (shape: <sessionId>/<key>/<by>)`);if(!VU.test(i))throw new J(`step-state: delta must be an integer, got "${i}"`);let o=parseInt(i,10),s=QU(t,a),c=dL(s),l=c.rangeParamsFor(r);if(!l)throw new J(`step-state: key "${r}" is not a bounded (range) state key (have keys: ${c.listKeys().join(`, `)})`);let u=t.sessionState.get(a,r),d=u&&VU.test(u)?GU(l,parseInt(u,10)):KU(`step-state`,r,l,mL(s,e=>t.sessionState.get(a,e),r)),f=HU(d,o,l.min,l.max),p=c.validate(r,String(f));if(!p.ok)throw new J(`step-state: ${p.reason}`);WU(t,a,`step-state`,[{key:r,value:p.value}]),t.navigating.set(a,r,p.value),t.dlog(`info`,`step-state: ${r} ${d}→${p.value} (by ${o}, session=${a})`)};function WU(e,t,n,r){let i=r.filter(e=>e.key.startsWith(tD));if(i.length===0)return;let a=WI(QU(e,t),n=>e.sessionState.get(t,n),i);if(a.length>0)throw new J(`${n}: refused — ${a.join(`; `)}`)}function GU(e,t){return Math.max(e.min,Math.min(e.max,t))}function KU(e,t,n,r){if(r===null)return n.min;if(!VU.test(r))throw new J(`${e}: "${t}" shows ${JSON.stringify(r)} before any click, not an integer to step`);return GU(n,parseInt(r,10))}const qU=`render-origin`;function JU(e){return JSON.stringify(e)}function YU(e){let t;try{t=JSON.parse(e)}catch{throw new J(`render origin is not JSON: ${e}`)}if(typeof t!=`object`||!t)throw new J(`render origin is not an object: ${e}`);let{projectDir:n,cwd:r,configFile:i}=t;if(typeof n!=`string`||typeof r!=`string`||i!==null&&typeof i!=`string`)throw new J(`render origin has the wrong shape: ${e}`);return{projectDir:n,cwd:r,configFile:i}}function XU(e,t){let n=e.sessionState.get(t,qU);if(n===null)throw new J(`session ${t} has not rendered yet — no config to act on`);return YU(n)}function ZU(e,t,n){let r=e.sessionState.get(t,qU);if(r===null)return;let i=YU(r),{path:a}=$U(i);n.some(e=>e.kind===`file`&&e.file===a)&&e.reloadConfig(i)}function QU(e,t){return e.configFor(XU(e,t))}function $U(e){return KP(e.projectDir,e.cwd,e.configFile??void 0)}function eW(e,t){return{record:(n,r,i)=>e.journal.file(t,n,r,i),logger:e.dlog}}const tW=(e,t)=>{let[n=``,r=``,i=``]=NU(()=>zn(e)),a=jU(n),o=XU(t,a),s=t.configFor(o),c=NA(s);if(!r)throw new J(`set-config: <key>/<value> is required (have keys: ${c.listKeys().join(`, `)})`);let l=c.validate(r,i);if(!l.ok)throw new J(`set-config: ${l.reason}`);let u=$U(o),d=HI(s,e=>t.sessionState.get(a,e),r);rH(eW(t,a),u,[[d.key,l.value]]),t.reloadConfig(o),t.dlog(`info`,`set-config: ${d.key}=${l.value} → ${u.path} (session=${a})`)},nW=(e,t)=>{let[n=``,r=``,i=``]=NU(()=>zn(e)),a=jU(n);if(!r)throw new J(`step-config: <key> is required (shape: <sessionId>/<key>/<by>)`);if(!VU.test(i))throw new J(`step-config: delta must be an integer, got "${i}"`);let o=parseInt(i,10),s=XU(t,a),c=t.configFor(s),l=NA(c),u=l.rangeParamsFor(r);if(!u)throw new J(`step-config: key "${r}" is not a bounded (range) config key (have keys: ${l.listKeys().join(`, `)})`);let d=$U(s),f=HI(c,e=>t.sessionState.get(a,e),r),p=nH(d.path,f.key),m=typeof p==`number`?GU(u,p):KU(`step-config`,r,u,FA(f.globals,r)),h=HU(m,o,u.min,u.max),g=l.validate(r,String(h));if(!g.ok)throw new J(`step-config: ${g.reason}`);rH(eW(t,a),d,[[f.key,g.value]]),t.reloadConfig(s),t.dlog(`info`,`step-config: ${f.key} ${m}→${g.value} (by ${o}) → ${d.path} (session=${a})`)},rW=(e,t)=>{let[n=``]=NU(()=>zn(e)),r=jU(n),i=XU(t,r),a=t.configFor(i),o=e=>t.sessionState.get(r,e),s=BI(a,o),c=UI(a,o);if(s.length+c.length===0){t.dlog(`info`,`save: nothing unsaved (session=${r})`);return}let l=dL(a),u=s.map(e=>{let t=l.validate(e.sessionKey,e.value);if(!t.ok)throw new J(`save: ${t.reason}`);return[e.target,t.value]});aW(`save`,l,c);let d=$U(i);iH(eW(t,r),d,u,c),t.reloadConfig(i);for(let e of[...s.map(e=>e.sessionKey),...c.map(e=>e.key)])t.sessionState.clear(r,e);t.dlog(`info`,`save: ${[...u.map(([e,t])=>`${e}=${t}`),...c.map(iW)].join(` `)} → ${d.path} (session=${r})`)},iW=e=>`${e.preset}/${e.id}.settings.${e.setting}=${Oh(e.value)}`;function aW(e,t,n){for(let r of n){let n=t.validate(r.key,Oh(r.value));if(!n.ok)throw new J(`${e}: ${n.reason}`)}}const oW=(e,t)=>{let[n=``]=NU(()=>zn(e)),r=jU(n),i=XU(t,r),a=t.configFor(i),o=qI(a,e=>t.sessionState.get(r,e)),s=dL(a),c=o.picks.map(e=>{let t=s.validate(e.sessionKey,e.value);if(!t.ok)throw new J(`save-preset: ${t.reason}`);return[e.configKey,t.value]});aW(`save-preset`,s,o.placements);let l=$U(i),u=dH(eW(t,r),l,o.from,o.globals,c,o.placements);t.reloadConfig(i);for(let e of[...ma.map(e=>e.sessionKey),...o.placements.map(e=>e.key)])t.sessionState.clear(r,e);t.sessionState.set(r,pa.preset.sessionKey,u),t.dlog(`info`,`save-preset: ${[`${u} from=${o.from}`,...c.map(([e,t])=>`${e}=${t}`),...o.placements.map(iW)].join(` `)} → ${l.path} (session=${r})`)},sW=(e,t)=>{let[n=``]=NU(()=>zn(e)),r=jU(n),i=XU(t,r),a=YI(t.configFor(i),e=>t.sessionState.get(r,e));if(a.kind===`rule`)throw new J(`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 o=$U(i);fH(eW(t,r),o,a.theme,a.look),t.reloadConfig(i);let s=new Set(BI(t.configFor(i),e=>t.sessionState.get(r,e)).map(e=>e.sessionKey)),c=gh.map(e=>pa[e].sessionKey).filter(e=>!s.has(e));for(let e of c)t.sessionState.clear(r,e);t.dlog(`info`,`save-theme-default: ${a.theme} ${gh.map(e=>`${e}=${a.look[e]}`).join(` `)} → ${o.path} (session=${r})`)},cW=(e,t)=>{let[n=``,r=``]=NU(()=>zn(e)),i=jU(n);if(!r)throw new J(`delete-preset: <name> is required (shape: <sessionId>/<name>)`);let a=XU(t,i),o=$U(a);pH(eW(t,i),o,r),t.reloadConfig(a);let s=pa.preset.sessionKey;t.sessionState.get(i,s)===r&&t.sessionState.clear(i,s),t.dlog(`info`,`delete-preset: ${r} ← ${o.path} (session=${i})`)},lW=(e,t)=>{let[n=``,...r]=NU(()=>zn(e)),i=jU(n),a=XU(t,i),o=NA(t.configFor(a)).listKeys(),s=r.length===0?[``]:r.filter(e=>!o.includes(e));if(s.length>0)throw new J(`reset-config: unknown config key "${s.join(`", "`)}" (have: ${o.join(`, `)})`);let c=$U(a),l=r.map(XI),u=l.flatMap(e=>e.fileKeys),d=l.flatMap(e=>e.sessionKeys);cH(eW(t,i),c,u),t.reloadConfig(a);for(let e of d)t.sessionState.clear(i,e);t.dlog(`info`,`reset-config: ${[...u,...d.map(e=>`session:${e}`)].join(` `)} ← ${c.path} (session=${i})`)};function uW(e,t){let n=(e,t)=>[...dh(Xh(e,t).node)].filter(e=>e.kind===`segment`),r=new Set(qh(t.presets).flatMap(e=>n(t,e).map(t=>nD(qw(e),sh(t)))));return qh(e.presets).flatMap(t=>n(e,t).map(e=>({member:nD(qw(t),sh(e)),node:e})).filter(({member:e})=>!r.has(e)))}function dW(e,t){return e.flatMap(({member:e,node:n})=>[...Object.values(n.drafts??{}).map(e=>e.key),...e===t?[XE]:[]])}const fW=(e,t)=>{let[n=``,r=``,i=``]=NU(()=>zn(e)),a=jU(n),o=XU(t,a),s=t.configFor(o),c=NA(s);if(!r)throw new J(`apply-layout-op: <key>/<op> is required (have: ${c.listKeys().join(`, `)})`);let l=c.validate(r,i);if(!l.ok)throw new J(`apply-layout-op: ${l.reason}`);let u=yA(l.value);if(u===null)throw new J(`apply-layout-op: "${l.value}" is not a layout op token`);let d=$U(o),f=mH(eW(t,a),d,r,u);t.reloadConfig(o);let p=dW(uW(s,t.configFor(o)),t.sessionState.get(a,XE)).filter(e=>t.sessionState.get(a,e)!==null);for(let e of p)t.sessionState.clear(a,e);t.dlog(`info`,`apply-layout-op: ${r} ${l.value} → ${d.path} placed=${JSON.stringify(f)} released=${JSON.stringify(p)} (session=${a})`)},pW=(e,t)=>{let[n=``]=NU(()=>zn(e)),r=jU(n);t.journal.commit();let i=t.history.undo(r);ZU(t,r,i),t.dlog(`info`,`undo: restored ${IH(i)} (session=${r})`)},mW=(e,t)=>{let n=jU(MU(e)),{step:r,discarded:i}=t.navigation.back(n,t.sessionState,dL(QU(t,n))),a=r.map(e=>`${e.key}=${e.before??`∅`}`).join(` `);t.dlog(`info`,`back: ${a} discarded=${i} (session=${n})`)},hW=(e,t)=>{let n=jU(MU(e));t.journal.commit();let r=t.history.rewind(n);ZU(t,n,r),t.dlog(`info`,`rewind: put back ${IH(r)||`nothing`} as edit mode found it (session=${n})`)},gW=(e,t)=>{let[n=``]=NU(()=>zn(e)),r=jU(n);t.journal.commit();let i=t.history.redo(r);ZU(t,r,i),t.dlog(`info`,`redo: re-applied ${IH(i)} (session=${r})`)},_W=(e,t)=>{jU(MU(e)),t.applyUpdate()},vW=`client-hints`;function yW(e,t){let n=e.sessionState.get(t,vW);if(n===null)throw new J(`session ${t} has not rendered yet — no client facts are recorded for it`);let r;try{r=JSON.parse(n)}catch{throw new J(`client hints record is not JSON: ${n}`)}if(typeof r!=`object`||!r)throw new J(`client hints record is not an object: ${n}`);return rt(r)}function bW(e,t,n){let r=ND(n);e.sessionState.setBatch(t,RD(r)),e.dlog(`info`,`doctor: ${r.map(e=>`${e.check.name}=${e.verdict.ok?`ok`:`failed(${1+(e.verdict.more?.length??0)})`}`).join(` `)} (session=${t})`)}function xW(e,t){return{...$H(e.doctor,yW(e,t),XU(e,t),n=>e.sessionState.get(t,n)),urlHandler:ZH(e.clientVersion)}}const SW=(e,t)=>{let n=jU(MU(e));bW(t,n,xW(t,n))},CW=(e,t)=>{let n=fU(MU(e));if(n===null)throw new J(`doctor-probe: the value is not a probe nonce`);t.probes.arrive({nonce:n,handler:t.clientVersion}),t.dlog(`info`,`doctor-probe: arrived nonce=${n} handler=${t.clientVersion??`unreported`}`)},wW=(e,t)=>{let[n=``,r=``]=NU(()=>zn(e)),i=jU(n),a=PD(r);if(a===void 0)throw new J(`doctor-fix: unknown check "${r}"`);let o=xW(t,i),s=a.probe(o);if(s.ok||s.fix===void 0)throw new J(`doctor-fix: ${a.label} — ${s.ok?`nothing to fix`:s.reason}`);let c=eU(s.fix,o);t.dlog(`info`,`doctor-fix: ${a.name} → ${s.fix.kind} ${s.fix.path.join(`.`)}=${JSON.stringify(s.fix.value)} (session=${i})`),bW(t,i,c)},TW=(e,t)=>{let[n=``,...r]=NU(()=>zn(e)),i=jU(n),a=XU(t,i),o=Object.values(t.configFor(a).actions).filter(e=>`ceiling`in e).find(e=>{let t=FM(e);return t.length===r.length&&t.every((e,t)=>e===r[t])});if(o===void 0)throw new J(`ceiling: "${r.join(` `)}" is not a move this config declares`);let s=o.ceiling===`set`?{kind:`set`,to:o.to}:{kind:`clear`},c=GF({sessionId:i,projectDir:a.projectDir,cwd:a.cwd},yW(t,i));t.memento.move(c,s),t.dlog(`info`,`ceiling: ${r.join(` `)} (session=${i} claudeConfigDir=${c.claudeConfigDir})`)},EW=(e,t)=>{let[n=``,r=``]=NU(()=>zn(e)),i=jU(n),a=Object.values(t.configFor(XU(t,i)).actions).filter(e=>`slash`in e),o=a.find(e=>e.slash===r);if(o===void 0)throw new J(`${JSON.stringify(r)} is not a command this config declares (it declares: ${[...new Set(a.map(e=>e.slash))].join(`, `)||`none`})`);let s=TU(t.claudeInput,yW(t,i).tmux,o.slash);if(s.kind===`refused`)throw t.dlog(`warn`,`slash: ${r} refused — ${s.reason} (session=${i})`),new J(`${r} was not typed: ${s.reason}`);t.dlog(`info`,`slash: typed ${r} into ${s.pane} (session=${i})`)},DW=`config-override`,OW=new Map([[_n,FU],[`load-config`,(e,t)=>{let n=e.indexOf(`/`);if(n===-1)throw new J(`load-config: expected <sessionId>/<path> (missing separator)`);let r=jU(NU(()=>decodeURIComponent(e.slice(0,n)))),i=NU(()=>decodeURIComponent(e.slice(n+1))).trim();if(i!==``){if(!i.startsWith(`/`))throw new J(`load-config: path must be absolute, got "${i}"`);if(!/\.(json5?|json)$/.test(i))throw new J(`load-config: path must end with .json5 or .json, got "${i}"`)}i===``?(t.sessionState.clear(r,DW),t.dlog(`info`,`load-config: override cleared (session=${r})`)):(t.sessionState.set(r,DW,i),t.dlog(`info`,`load-config: ${i} (session=${r})`))}],[vn,IU],[gn,BU],[N,UU],[Sn,tW],[Cn,nW],[Dn,lW],[wn,rW],[P,oW],[Tn,sW],[En,cW],[On,fW],[kn,pW],[An,gW],[jn,mW],[Mn,hW],[bn,LU],[xn,RU],[yn,zU],[Nn,_W],[Pn,SW],[Fn,wW],[In,CW],[Ln,TW],[Rn,EW]]),kW=new Set([gn,N,Sn,Cn,Dn,wn,P,Tn,En,On,kn,An,jn,Mn,yn,Nn,Pn,Fn,Ln,Rn]),AW=(e,t)=>{let n=[],r=!1,i=null;for(let{verb:a,value:o}of Hn(Bn(e))){if(!i&&kW.has(a)){let e=zn(o);e.length>0&&e[0]&&(i=e[0])}let e=OW.get(a);if(!e){n.push(`unknown effect verb "${a}"`);continue}try{e(o,t)}catch(e){e instanceof J||(r=!0),n.push(`${a}: ${e instanceof Error?e.message:String(e)}`)}}if(n.length>0){i&&t.sessionState.set(i,`click.error`,n.join(`
211
- `));let e=`dispatch: ${n.join(`; `)}`;throw r?Error(e):new J(e)}};function jW(e){return(t,n)=>{let r=n.history.begin(),i=n.navigation.begin(r.sessionState),a=[];try{e(t,{...n,sessionState:r.sessionState,journal:r,navigating:i.sessionState})}catch(e){a.push(e)}i.commit();try{r.commit()}catch(e){a.push(e)}if(a.length===1)throw a[0];if(a.length>1)throw Error(a.map(e=>String(e.message??e)).join(`; `))}}const MW=new Map([...OW,[hn,AW]].map(([e,t])=>[e,jW(t)]));Object.freeze([...MW.keys()]);const NW=new Set([`hook_event_name`,`session_id`,`session_name`,`transcript_path`,`cwd`,`model`,`workspace`,`version`,`output_style`,`cost`,`context_window`,`exceeds_200k_tokens`,`effort`,`thinking`,`rate_limits`,`vim`,`agent`,`worktree`]),PW=[[`session_id`,`string`],[`transcript_path`,`string`],[`cwd`,`string`],[`model`,`object`],[`model.id`,`string`],[`model.display_name`,`string`],[`workspace`,`object`],[`workspace.current_dir`,`string`],[`workspace.project_dir`,`string`]],FW=[[`workspace.added_dirs`,`string-list`]];function IW(e){let t={missingRequired:[],typeMismatches:[],unknownTopLevelFields:[]},n=typeof e==`object`&&e&&!Array.isArray(e)?e:{};for(let[e,r]of PW){let i=zW(n,e);if(i==null)t.missingRequired.push(e);else{let n=LW(i);n!==r&&t.typeMismatches.push({path:e,expected:r,got:n})}}for(let[e,r]of FW){let i=zW(n,e),a=i===void 0?r:RW(i);a!==r&&t.typeMismatches.push({path:e,expected:r,got:a})}for(let e of Object.keys(n))NW.has(e)||t.unknownTopLevelFields.push(e);return{data:e,report:t}}function LW(e){return Array.isArray(e)?`array`:typeof e==`string`&&!e.isWellFormed()?`ill-formed string`:typeof e}function RW(e){return Array.isArray(e)&&e.every(e=>LW(e)===`string`)?`string-list`:LW(e)}function zW(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n||Array.isArray(n))return;n=n[e]}return n}function BW(e,t){switch(e){case`vars`:return{what:e,vars:VW(t)};case`segments`:return{what:e,segments:KW(t)};case`config`:return{what:e,config:XW(t)}}}function VW(e){if(e===null)return[];let{store:t,registry:n,config:r}=e,i=WW(r),a=t.names().sort(),o=[];for(let e of a){let r=t.getNode(e),a=HW(r),s=n.getLastError(e);o.push({name:e,source:i.get(e)??null,...a,lastError:s===void 0?null:{timestampMs:s.timestamp,message:s.message},ageMs:UW(r.lastUpdatedMs())})}return o}function HW(e){if(e.kind!==`document`)try{return{type:e.type,value:e.read()}}catch(t){return{type:e.type,value:t instanceof Error?t.message:String(t)}}let t=e.read();switch(t.kind){case`ok`:return{type:`document`,value:JSON.stringify(t.value)};case`absent`:return{type:`document`,value:`(not yet scanned)`};case`failed`:return{type:`document`,value:t.reason}}}function UW(e){return e===null?null:Math.max(0,Date.now()-e)}function WW(e){let t=new Map;for(let[n,r]of Object.entries(e.variables))t.set(n,GW(r));for(let[n,r]of Object.entries(e.segments))if(r.vars)for(let[e,i]of Object.entries(r.vars))t.set(`${n}.${e}`,GW(i));return t}function GW(e){return e.kind}function KW(e){if(e===null)return[];let{store:t,config:n,lastRenderBySegment:r}=e,i=new Set(t.names()),a=JW(n),o=qW(n),s=[];for(let e of a){let t=n.segments[e];t&&s.push({name:e,description:t.description??null,template:t.template,referencedVars:YW(t.template,n.helpers,i),placements:(o.get(e)??[]).map(e=>({id:e,lastRender:r.get(e)??null}))})}return s}function qW(e){let t=new Map;for(let n of qh(e.presets))for(let r of dh(Xh(e,n).node)){if(r.kind!==`segment`)continue;let e=t.get(r.name)??[],n=sh(r);e.includes(n)||t.set(r.name,[...e,n])}return t}function JW(e){let t=[],n=new Set;for(let r of dh(Bh(e.root)))r.kind===`segment`&&e.segments[r.name]&&!n.has(r.name)&&(t.push(r.name),n.add(r.name));for(let r of Object.keys(e.segments))n.has(r)||(t.push(r),n.add(r));return t}function YW(e,t,n){let r=new Set;for(let i of vg(e,t).keys()){if(n.has(i)){r.add(i);continue}let e=i.split(`.`);for(;e.length>1;){e.pop();let t=e.join(`.`);if(n.has(t)){r.add(t);break}}}return Array.from(r).sort()}function XW(e){return e===null?null:e.config}const ZW=[`vars`,`segments`,`config`];function QW(e){return typeof e==`string`&&ZW.includes(e)}function $W(e){return Math.max(1,e-2)}var eG=class{written=new Map;constructor(e){this.dir=e}pathFor(e){return l.join(this.dir,`${encodeURIComponent(e)}.txt`)}sync(e,t){let n=this.pathFor(e);if(t===(this.written.get(e)??null))return null;try{return t===null?(r.rmSync(n,{force:!0}),this.written.delete(e)):(r.mkdirSync(this.dir,{recursive:!0,mode:448}),r.writeFileSync(n,t,{mode:384}),this.written.set(e,t)),null}catch(e){return`${n}: ${e.message}`}}reset(){this.written.clear();try{return r.rmSync(this.dir,{recursive:!0,force:!0}),null}catch(e){return`${this.dir}: ${e.message}`}}};function tG(e,t){for(let n of Object.entries(t))e.push(n)}const nG={ok:`info`,"bad-request":`warn`,threw:`error`};function rG(e){switch(e.kind){case`ok`:return[];case`bad-request`:return[[`problems`,e.problems.join(`; `)]];case`threw`:return[[`error`,y(e.error)]]}}const iG=/^[^\s"=\\]+$/,aG=e=>iG.test(e)?e:JSON.stringify(e);function oG(e,t,n){let r=[...e,[`took`,`${n}ms`],[`outcome`,t.kind],...rG(t)];return{level:nG[t.kind],line:`render${r.map(([e,t])=>` ${e}=${aG(t)}`).join(``)}`}}const sG=new lV,cG=new uU;Ae(sG.launchStats);const lG=new ow({counters:sG,logger:k}),uG=PR({watchers:lG,logger:k}),{gitProvider:dG,usageStore:fG,mementoProvider:pG}=uG,mG=new fV,hG=new SH(mG,k),gG=new GH,_G=new gm,vG=new eG(Qe()),yG=new sV({gitService:dG,sessionState:mG,watchers:lG},{observers:{onReload:e=>k(`info`,`config loaded projectDir=${e.projectDir} cwd=${e.cwd} files=${e.configLayers.join(` < `)||`<bundled default>`} error=${e.lastError===null?`none`:JSON.stringify(e.lastError)} warning=${e.lastWarning===null?`none`:JSON.stringify(e.lastWarning)}`)}}),bG=60*1e3;function xG(){let e=import.meta.url,n=[];e.startsWith(`file://`)&&n.push(ne(e)),t.argv[1]&&n.push(t.argv[1]);let i=new Map;for(let e of n)try{i.set(e,r.statSync(e).mtimeMs)}catch{}let a=null,o=()=>{for(let[e,t]of i)try{if(r.statSync(e).mtimeMs!==t){k(`info`,`binary mtime changed (${e}); shutting down`),a&&clearInterval(a),LG(0);return}}catch(e){k(`warn`,`bin stat failed: ${e.message}`)}};return{arm(){i.size!==0&&(a=setInterval(o,bG),a.unref())},checkNow:o}}const SG=xG(),CG=NL({entryUrl:import.meta.url,intervalMs:bG,releaseIntervalMs:216e5,registryUrl:t.env.CC_CANDYBAR_REGISTRY_URL??`https://registry.npmjs.org`,fetchImpl:fetch,onApplied:()=>SG.checkNow(),log:k});let wG=null,TG=null,EG=0;function DG(){t.on(`uncaughtException`,e=>{k(`error`,`uncaughtException: ${e.stack||e.message}`),LG(1)}),t.on(`unhandledRejection`,e=>{k(`error`,`unhandledRejection: ${String(e)}`),LG(1)});for(let e of[`SIGINT`,`SIGTERM`,`SIGHUP`])t.on(e,()=>{k(`info`,`received ${e}, shutting down`),LG(0)});try{EG=Vt(t.env)}catch(e){k(`error`,`refusing to boot: ${e.message}`),LG(1);return}wG=ea(t.pid);let e=ua(fa(wG));if(!e.decision.allow){k(`warn`,`fork-bomb breaker: ${e.decision.reason}; refusing to boot`),LG(1);return}TG=e.registryPath,r.mkdirSync(ze(),{recursive:!0}),Ue(Be()),mG.useStorage(new mV(Ke(),500,k)),hG.useStorage(UH(qe(),k)),ra({anchor:na(t.env),isAlive:ia,onOrphaned:e=>{k(`info`,`parent watchdog: ${e}; shutting down`),LG(0)}}),OG(S.createServer({allowHalfOpen:!1},e=>{RG(e)}),Be(),!1)}function OG(e,n,r){e.removeAllListeners(`error`),e.removeAllListeners(`listening`),e.once(`error`,i=>{if(i.code!==`EADDRINUSE`){k(`error`,`server error: ${i.message}`),LG(1);return}if(r){k(`info`,`lost rebind race; another daemon is alive — exiting`),t.exit(0);return}kG(e,n)}),e.listen(n,()=>AG(n))}function kG(e,n){let i=Wi(Gi(We(n)),(e,t)=>$i(e,t,{readStartTime:Qi,pidAlive:ia}));if(i.kind===`attach-and-exit`){k(`info`,`EADDRINUSE: ${i.reason} — exiting`),t.exit(0);return}k(`warn`,`EADDRINUSE: ${i.reason} — unlinking stale socket and rebinding`);try{r.unlinkSync(n)}catch(e){if(e.code!==`ENOENT`){k(`error`,`cannot unlink stale socket ${n}: ${e.message}`),LG(1);return}}OG(e,n,!0)}function AG(e){let n=Ji(e);if(n.kind!==`present`){k(`warn`,`no ownable socket at bind callback (${n.kind}); exiting`),LG(0);return}PG(e);try{r.chmodSync(e,384)}catch(e){k(`warn`,`chmod socket failed: ${e.message}`)}k(`info`,`daemon up: pid=${t.pid} v=3 sock=${e} heapCap=${Math.round(C.getHeapStatistics().heap_size_limit/1048576)}MB rssLimit=${Math.round(EG/1048576)}MB`),M();let i=vG.reset();i!==null&&k(`warn`,`diagnostic dump wipe failed: ${i}`),SG.arm(),CG.arm(),NG(),jG(e,n.identity)}function jG(e,n){Zi({bound:n,myPid:t.pid,readIdentity:()=>Ji(e),readLease:()=>Gi(We(e)),shutdown:e=>LG(e),log:k}).arm()}let MG=null;function NG(){MG=Gt(Yt(sG.startedAt.getTime(),e=>LG(e),{rssLimitBytes:EG})),MG.arm()}function PG(e){let n=Ki(We(e),{pid:t.pid,version:3,binPath:t.argv[1],startTime:wG});n!==null&&k(`warn`,`lease write failed: ${n}`)}let FG=0,IG=!1;function LG(e){if(!IG){IG=!0,setTimeout(()=>t.kill(t.pid,`SIGKILL`),500);try{dG.close()}catch(e){k(`warn`,`gitService close failed: ${e.message}`)}try{fG.close()}catch(e){k(`warn`,`usageStore close failed: ${e.message}`)}try{lG.closeAll()}catch(e){k(`warn`,`watcherRegistry close failed: ${e.message}`)}try{mG.flush()}catch(e){k(`warn`,`sessionState flush failed: ${e.message}`)}qi(Ge(),t.pid),TG!==null&&da(TG,t.pid,ca,e=>r.unlinkSync(e)),t.exit(e)}}function RG(e){FG++,sG.inFlight=FG;let t=!1,n=(n,r)=>{if(t){r!==null&&k(`warn`,`exit-after-flush dropped: an earlier responder settled this socket`);return}t=!0;let i=r===null?void 0:()=>LG(r);try{e.end(mt(n),i)}catch(e){k(`warn`,`response write failed: ${e.message}`),i?.()}},r=!1,i=setTimeout(()=>{r=!0,sG.requestsTimedOut++,n({ok:!1,error:`request exceeded 200ms`,code:`TIMEOUT`,daemonV:3},null)},200),a=ht(e=>{VG(e,()=>r).then(e=>n(e.resp,e.exitAfterFlush)).catch(e=>{k(`error`,`handler threw: ${y(e)}`),n(BG(e),null)})},e=>{k(`warn`,`frame parse failed: ${e.message}`),n({ok:!1,error:e.message,code:`BAD_REQUEST`,daemonV:3},null)});e.on(`data`,a),e.on(`error`,e=>{k(`warn`,`socket error: ${e.message}`)}),e.on(`close`,()=>{clearTimeout(i),FG=Math.max(0,FG-1),sG.inFlight=FG})}const zG=e=>({resp:e,exitAfterFlush:null}),BG=e=>({ok:!1,error:e instanceof Error?e.message:y(e),code:`RENDER_FAILED`,daemonV:3});async function VG(e,t){if(!e||typeof e!=`object`||typeof e.v!=`number`)return zG({ok:!1,error:`malformed request`,code:`BAD_REQUEST`,daemonV:3});if(e.v!==3)return e.v>3?k(`info`,`version mismatch: client=${e.v} > daemon=3; binary likely upgraded — exiting after the response flushes`):k(`info`,`version mismatch: client=${e.v} < daemon=3; client is stale — staying up`),{resp:{ok:!1,error:`protocol v${e.v} not supported (daemon at v3)`,code:`VERSION_MISMATCH`,daemonV:3},exitAfterFlush:e.v>3?0:null};if(e.kind===`shutdown`)return{resp:{ok:!0,output:``},exitAfterFlush:0};if(e.kind===`stats`)return zG({ok:!0,stats:sG.snapshot({gitCache:dG.getStats(),usageCache:fG.getStats(),renderCacheSize:yG.size,effectCache:_G.getStats(),watchersActive:lG.size(),nextRestartReason:MG?.describeNextRestart()??null,handlerProbes:cG.list()})});if(e.kind===`render`){sG.requestsTotal++;let n=new Date,r=vw(n),i=n.getTime(),a=[],o=await YG(e,r,a).catch(e=>({outcome:{kind:`threw`,error:e},resp:BG(e)}));o.outcome.kind!==`ok`&&sG.requestsErrored++,tG(a,{timedOut:t()?`Y`:`N`});let{level:s,line:c}=oG(a,o.outcome,Date.now()-i);return k(s,c),zG(o.resp)}if(e.kind===`click`)return zG(JG(e.verb,e.value,ft(e.clientVersion)));if(e.kind===`debug`){if(!QW(e.what))return zG({ok:!1,error:`unknown debug 'what': ${String(e.what)} (have: ${ZW.join(`, `)})`,code:`BAD_REQUEST`,daemonV:3});let t=yG.firstState(),n=t===null?null:{store:t.store,registry:t.registry,config:t.config,compiled:t.compiled,lastRenderBySegment:e.what===`segments`?KG(t.lastRenderCellsBySegment,t.config.globals.charset??`unicode`,t.config.globals.colorCompatibility??`truecolor`):GG};return zG({ok:!0,debug:BW(e.what,n)})}return zG({ok:!1,error:`unknown kind`,code:`BAD_REQUEST`,daemonV:3})}function HG(e,t){let{values:n,tokens:r}=b({args:e.slice(1),options:{config:{type:`string`}},strict:!1,tokens:!0,allowPositionals:!0}),i=[...new Set((r??[]).filter(e=>e.kind===`option`&&e.name!==`config`).map(e=>`--${e.name}`))];return{configFile:dP(t,n.config),unknownFlagsError:i.length>0?`Unknown flags: ${i.join(`, `)}`:null}}const UG={sessionState:mG,dlog:k,applyUpdate:()=>CG.act(),doctor:qH(e=>{let t=[e.projectDir,e.cwd,e.configFile??void 0];yG.reload(...t);let n=yG.getOrCreate(...t);return{layers:n.configLayers,error:n.lastError,warning:n.lastWarning,unused:n.state.unused,config:n.state.config}}),probes:cG,memento:pG,claudeInput:AU(),history:hG,navigation:gG,configFor:e=>yG.getOrCreate(e.projectDir,e.cwd,e.configFile??void 0).state.config,reloadConfig:e=>yG.reload(e.projectDir,e.cwd,e.configFile??void 0)};UG.reloadConfig;const WG={endcaps:`powerline`,colorCompatibility:`truecolor`,wrap:!0,padding:1,charset:Rp,width:1/0},GG=new Map;function KG(e,t,n){let r=new Map;for(let[i,a]of e)r.set(i,Dm(a,{...WG,charset:t,colorCompatibility:n}));return r}const qG={...uG,history:e=>hG.depth(e)};function JG(e,t,n){let r=MW.get(e);if(!r)return{ok:!1,error:`unknown click verb: ${e}`,code:`BAD_REQUEST`,daemonV:3};try{return r(t,{...UG,clientVersion:n}),{ok:!0,output:``}}catch(e){let t=e instanceof J?`BAD_REQUEST`:`RENDER_FAILED`;return{ok:!1,error:String(e instanceof Error?e.message:e),code:t,daemonV:3}}}async function YG(e,t,n){let{report:r}=IW(e.hookData);for(let e of r.unknownTopLevelFields)k(`info`,`schema: unknown field '${e}' — Anthropic may have added it`);let i=[];for(let e of r.missingRequired)i.push(`missing required field '${e}'`);for(let{path:e,expected:t,got:n}of r.typeMismatches)i.push(`field '${e}' expected ${t}, got ${n}`);if(f(e.cwd)||i.push(`request 'cwd' is not an absolute path: "${e.cwd}"`),i.length>0)return{outcome:{kind:`bad-request`,problems:i},resp:{ok:!1,error:`malformed hookData: ${i.join(`; `)}`,code:`BAD_REQUEST`,daemonV:3}};tG(n,{sid:e.hookData.session_id,at:t.toFixed(3)});let a=e.hookData.workspace.project_dir,{configFile:o,unknownFlagsError:s}=HG(e.args,e.cwd),c=e.hookData.session_id,l=rt(e),u=it(e,l),d=at(u);tG(n,{termCols:String(l.termCols??`?`),termRows:String(l.termRows??`?`),refused:u.map(e=>e.hint).join(`,`)||`-`});let p=JSON.stringify(l);mG.get(c,`client-hints`)!==p&&mG.set(c,vW,p);let m=mG.get(c,`config-override`)??o??l.configEnv,h=yG.getOrCreate(a,e.cwd,m),g=JU({projectDir:a,cwd:e.cwd,configFile:m??null});mG.get(c,`render-origin`)!==g&&mG.set(c,qU,g);let _=l.termCols,v=$W(_??120),y=Om(l.termRows);tG(n,{width:String(v)});let{authoredRoots:b}=h.state,x=t=>mG.get(e.hookData.session_id,t),S=iI(h.state.config,x,e=>b.has(e)),C=await xI(e.hookData,t,{...qG,navigation:e=>gG.depth(e,mG,dL(h.state.config))},e.cwd,h.state.neededInputPaths(S.preset),S,l,{...QI(h.state.config,h.state.fileHeldSettings,x),configPath:h.configLayers.includes(h.configHome)?h.configHome:null});tG(n,{prompts:String(C.metrics?.messageCount??`-`),nonPrompts:String(C.metrics?.nonPrompts??`-`),pr:C.git?.prState??(C.git?.prError===void 0?`-`:`failed`)});let ee=[],te=aI(S,v),ne=_G.of(c),re=BB(h.state.config,h.state.compiled,h.state.store,h.state.registry,C,t,te,{perSegmentSink:h.state.lastRenderCellsBySegment,onRenderWarning:e=>ee.push(e)},{...oI(S),effects:ne}),ie=mG.get(e.hookData.session_id,`click.error`);ie&&mG.clear(e.hookData.session_id,`click.error`);let ae=[s,d,h.lastError,ie].filter(Boolean).join(`
212
- `),w=CG.notice({sessionId:c,dismissed:mG.get(c,_L),enabled:S.updateNotice}),T=h.lastError===null?null:h.failedFile,oe=[...h.lastWarning===null?[]:[{kind:`load`,message:h.lastWarning}],...ee],se=Nm(ae,w,oe.map(e=>e.message).join(`
213
- `)),ce=vG.sync(c,se===null?null:Fm(se));ce!==null&&k(`warn`,`diagnostic dump failed: ${ce}`);let le=Im(re,se,{fullText:ce===null?{kind:`file`,path:vG.pathFor(c)}:{kind:`unavailable`,reason:ce},failedConfigFile:T},{width:v,rowCap:y,colorCompatibility:S.colorCompatibility}),ue=dG.getStats(),E=fG.getStats(),de=ne.lastFrame(),fe=de.own.map(e=>`${e.placement}:${e.effect}@${e.t.toFixed(3)}`).join(`,`)||`-`,pe=e=>e.map(e=>`${e.placement}@${e.t.toFixed(3)}`).join(`,`)||`-`,me=oe.map(e=>{switch(e.kind){case`rule`:return`rule:${e.slot}`;case`load`:case`band-floor`:case`when`:return e.kind}}).join(`,`)||`-`;return tG(n,{git:`${ue.size}/${ue.hits}h/${ue.misses}m`,usage:`${E.size}/${E.hits}h/${E.misses}m`,effect:de.effect,effectT:de.t.toFixed(3),effectRows:`${de.made}made/${de.reused}reused`,effectOwn:fe,fadeBasis:de.basis,stateRev:String(de.revision),fades:pe(de.fades),leaves:pe(de.leaves),err:ae?`Y`:`N`,upd:String(w.length),warn:me}),{outcome:{kind:`ok`},resp:{ok:!0,output:le+`
214
- `}}}const XG={connectMs:200,budgetMs:500};async function ZG(e,n){let r=n.includes(`--json`),i=await QG(e);if(i.kind!==`ok`&&(t.stderr.write(`${e}: ${Ct(i)}\n`),t.exit(1)),r){t.stdout.write(JSON.stringify(i.value,null,2)+`
215
- `);return}t.stdout.write($G(i.value))}function QG(e){return _t({kind:`debug`,what:e},XG,e=>`debug`in e?e.debug:void 0)}function $G(e){switch(e.what){case`vars`:return eK(e.vars);case`segments`:return tK(e.segments);case`config`:return nK(e.config);default:return e}}function eK(e){if(e.length===0)return`no variables (DSL not active)
216
- `;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?``:` ${iK(a.ageMs)}`,o=a.lastError?` ✗ ${a.lastError.message}`:``;t.push(` ${a.name.padEnd(n)} ${(a.source??`—`).padEnd(r)} ${a.type.padEnd(i)} ${rK(a.value)}${e}${o}`)}return t.join(`
208
+ `}const uU=e=>({kind:`ok`,value:e}),dU=e=>({kind:`failed`,reason:e});var fU=class{arrivals=[];arrive(e){this.arrivals=[...this.arrivals,e].slice(-16)}list(){return this.arrivals}};const pU=/^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$/;function mU(e){return pU.test(e)?e:null}function hU(e){let t=e.opener();if(t.kind===`failed`)return t;if(t.value===null)return uU(null);let n=t.value,r=e.script(n);if(r.kind===`failed`)return uU({app:n,missing:dU(`its script could not be read (${r.reason})`)});let i=Oi(r.value);return uU({app:n,missing:i===null?dU("its script is not one `cc-candybar install` wrote"):uU([i.node,i.script].filter(t=>!e.exists(t)))})}async function gU(e,t){let n=e.now()+5e3;for(;e.now()<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`,handler:r.handler,bar:n.value.version}}return null}async function _U(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} (CC_CANDYBAR_SOCKET); the URL handler delivers links 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=e.open(`${mn}://${In}/${n}`);return(r===null?await gU(e,n):null)??{kind:`lost`,unopened:r,opener:hU(e)}}function vU(e,t,n){let r=Me({bin:t,args:[...n],category:e,timeoutMs:5e3});return r.ok?uU(r.stdout):dU(r.stderr.trim()||r.error||r.reason)}const yU=`ObjC.import("AppKit");var u = $.NSWorkspace.sharedWorkspace.URLForApplicationToOpenURL($.NSURL.URLWithString("${mn}://probe"));u.isNil() ? "" : u.path.js`;async function bU(){let e=await aU();if(e.kind!==`ok`)return dU(Ct(e).split(`
209
+ `).join(` — `));let{version:t,handlerProbes:n}=e.value;return Array.isArray(n)?uU({version:t,arrivals:n}):dU(`the running daemon (${t}) predates this check`)}function xU(){return{platform:process.platform,sockets:{own:Be(),handler:Ve()},now:Date.now,nonce:w,daemon:bU,open:e=>{let t=vU(`doctor.open`,`/usr/bin/open`,[`-g`,e]);return t.kind===`ok`?null:t.reason},pause:()=>new Promise(e=>setTimeout(e,100)),opener:()=>{let e=vU(`doctor.launch-services`,`/usr/bin/osascript`,[`-l`,`JavaScript`,`-e`,yU]);if(e.kind===`failed`)return e;let t=e.value.trim();return uU(t===``?null:t)},script:e=>vU(`doctor.osadecompile`,`/usr/bin/osadecompile`,[ki(e)]),exists:r.existsSync}}const SU=/^─{20,}/,CU=/^❯(\s|$)/,wU=/›\s*stashed$/;function TU(e){if(e.inMode)return{kind:`in-mode`};let t=e.screen.map(e=>e.trimEnd()),n=t.flatMap((e,t)=>SU.test(e)?[t]:[]).at(-2);return n===void 0||!CU.test(t[n+1]??``)?{kind:`no-prompt`}:wU.test(t[n-1]??``)?{kind:`stashed`}:{kind:`ready`}}const EU={"in-mode":`the Claude Code pane is in tmux copy mode — leave it (q) and click again`,stashed:`Claude Code is holding a stashed prompt (ctrl+s) — restore or send it, then click again`,"no-prompt":`Claude Code is not at its prompt (a dialog or picker is open) — close it and click again`};function DU(e,t,n){if(t===void 0)return{kind:`refused`,reason:`this session's statusline client reports no tmux facts (it predates this daemon) — rebuild or reinstall cc-candybar`};if(t===null)return{kind:`refused`,reason:`this Claude Code is not running inside tmux — the bar can only type into a tmux pane`};let r=TU(e.read(t));if(r.kind!==`ready`)return{kind:`refused`,reason:EU[r.kind]};let i=e.type(t,n);return i.kind===`typed`?{kind:`typed`,pane:t.pane}:i}const OU=`cc-candybar-slash`;function kU(e,t,n,r){let i=AR(e,t,n,r);if(i.kind===`failed`)throw Error(i.reason);return i}function AU(e){let t=kU(e,`claude-input.read`,[`display`,`-p`,`-t`,e.pane,`#{pane_in_mode}`,`;`,`capture-pane`,`-p`,`-t`,e.pane]);if(t.kind===`rate-limited`)throw Error(t.reason);let[n=``,...r]=t.stdout.split(`
210
+ `);return{inMode:n!==`0`,screen:r}}function jU(e,t){let n=kU(e,`claude-input.type`,[`load-buffer`,`-b`,OU,`-`,`;`,`send-keys`,`-t`,e.pane,`C-s`,`;`,`paste-buffer`,`-p`,`-d`,`-b`,OU,`-t`,e.pane,`;`,`send-keys`,`-t`,e.pane,`Enter`],t);return n.kind===`ok`?{kind:`typed`}:{kind:`refused`,reason:`cc-candybar typed a command moments ago — click again in a second (${n.reason})`}}function MU(){return{read:AU,type:jU}}function NU(e){if(!e)throw new J(`session id is required`);if(e.includes(`/`)||e.includes(`..`))throw new J(`invalid session id "${e}"`);return e}function PU(e){return FU(()=>decodeURIComponent(e))}function FU(e){try{return e()}catch(e){throw e instanceof URIError?new J(`malformed wire encoding: ${e.message}`):e}}function IU(e,t){let n=Me({bin:`/usr/bin/pbcopy`,stdinInput:e,category:`click.pbcopy`});if(!n.ok){if(n.reason===`rate-limited`){t.dlog(`warn`,`click.pbcopy rate-limited: ${n.error??``}`);return}throw Error(`pbcopy failed (${n.reason}, exit ${n.exitCode??`null`})`)}}const LU=(e,t)=>IU(PU(e),t),RU=(e,t)=>{let n=Me({bin:`/usr/bin/open`,args:[`-a`,`Visual Studio Code`,PU(e)],category:`click.open`});if(!n.ok){if(n.reason===`rate-limited`){t.dlog(`warn`,`click.open rate-limited: ${n.error??``}`);return}throw Error(`open -a "Visual Studio Code" failed (${n.reason}, exit ${n.exitCode??`null`})`)}},zU=(e,t)=>IU(PU(e),t),BU=(e,t)=>IU(PU(e),t),VU=(e,t)=>{let n=NU(PU(e));t.navigating.get(n,`toolbar-expanded`)?t.navigating.clear(n,`toolbar-expanded`):t.navigating.set(n,`toolbar-expanded`,`1`)},HU=(e,t)=>{let[n=``,...r]=FU(()=>zn(e)),i=NU(n),a=pL(eW(t,i));if(r.length===0)throw new J(`set-state: <key>/<value> is required (have keys: ${a.listKeys().join(`, `)})`);if(r.length%2!=0)throw new J(`set-state: expected even-count <key>/<value> pairs, got ${r.length} segment(s) after session id (have keys: ${a.listKeys().join(`, `)})`);let o=[];for(let e=0;e<r.length;e+=2){let t=r[e],n=r[e+1];if(!t)throw new J(`set-state: empty key at pair ${e/2+1} (expected <sessionId>/<key>/<value>[/<key>/<value>...] segments)`);let i=a.validate(t,n);if(!i.ok)throw new J(`set-state: pair ${e/2+1}: ${i.reason}`);o.push({key:t,value:i.value})}KU(t,i,`set-state`,o),t.navigating.setBatch(i,o);let s=o.map(e=>`${e.key}=${e.value}`).join(` `);t.dlog(`info`,`set-state: ${s} (session=${i})`)},UU=/^-?\d+$/;function WU(e,t,n,r){let i=e+t;return i>r?e===r?n:r:i<n?e===n?r:n:i}const GU=(e,t)=>{let[n=``,r=``,i=``]=FU(()=>zn(e)),a=NU(n);if(!r)throw new J(`step-state: <key> is required (shape: <sessionId>/<key>/<by>)`);if(!UU.test(i))throw new J(`step-state: delta must be an integer, got "${i}"`);let o=parseInt(i,10),s=eW(t,a),c=pL(s),l=c.rangeParamsFor(r);if(!l)throw new J(`step-state: key "${r}" is not a bounded (range) state key (have keys: ${c.listKeys().join(`, `)})`);let u=t.sessionState.get(a,r),d=u&&UU.test(u)?qU(l,parseInt(u,10)):JU(`step-state`,r,l,gL(s,e=>t.sessionState.get(a,e),r)),f=WU(d,o,l.min,l.max),p=c.validate(r,String(f));if(!p.ok)throw new J(`step-state: ${p.reason}`);KU(t,a,`step-state`,[{key:r,value:p.value}]),t.navigating.set(a,r,p.value),t.dlog(`info`,`step-state: ${r} ${d}→${p.value} (by ${o}, session=${a})`)};function KU(e,t,n,r){let i=r.filter(e=>e.key.startsWith(tD));if(i.length===0)return;let a=KI(eW(e,t),n=>e.sessionState.get(t,n),i);if(a.length>0)throw new J(`${n}: refused — ${a.join(`; `)}`)}function qU(e,t){return Math.max(e.min,Math.min(e.max,t))}function JU(e,t,n,r){if(r===null)return n.min;if(!UU.test(r))throw new J(`${e}: "${t}" shows ${JSON.stringify(r)} before any click, not an integer to step`);return qU(n,parseInt(r,10))}const YU=`render-origin`;function XU(e){return JSON.stringify(e)}function ZU(e){let t;try{t=JSON.parse(e)}catch{throw new J(`render origin is not JSON: ${e}`)}if(typeof t!=`object`||!t)throw new J(`render origin is not an object: ${e}`);let{projectDir:n,cwd:r,configFile:i}=t;if(typeof n!=`string`||typeof r!=`string`||i!==null&&typeof i!=`string`)throw new J(`render origin has the wrong shape: ${e}`);return{projectDir:n,cwd:r,configFile:i}}function QU(e,t){let n=e.sessionState.get(t,YU);if(n===null)throw new J(`session ${t} has not rendered yet — no config to act on`);return ZU(n)}function $U(e,t,n){let r=e.sessionState.get(t,YU);if(r===null)return;let i=ZU(r),{path:a}=tW(i);n.some(e=>e.kind===`file`&&e.file===a)&&e.reloadConfig(i)}function eW(e,t){return e.configFor(QU(e,t))}function tW(e){return KP(e.projectDir,e.cwd,e.configFile??void 0)}function nW(e,t){return{record:(n,r,i)=>e.journal.file(t,n,r,i),logger:e.dlog}}const rW=(e,t)=>{let[n=``,r=``,i=``]=FU(()=>zn(e)),a=NU(n),o=QU(t,a),s=t.configFor(o),c=NA(s);if(!r)throw new J(`set-config: <key>/<value> is required (have keys: ${c.listKeys().join(`, `)})`);let l=c.validate(r,i);if(!l.ok)throw new J(`set-config: ${l.reason}`);let u=tW(o),d=WI(s,e=>t.sessionState.get(a,e),r);aH(nW(t,a),u,[[d.key,l.value]]),t.reloadConfig(o),t.dlog(`info`,`set-config: ${d.key}=${l.value} → ${u.path} (session=${a})`)},iW=(e,t)=>{let[n=``,r=``,i=``]=FU(()=>zn(e)),a=NU(n);if(!r)throw new J(`step-config: <key> is required (shape: <sessionId>/<key>/<by>)`);if(!UU.test(i))throw new J(`step-config: delta must be an integer, got "${i}"`);let o=parseInt(i,10),s=QU(t,a),c=t.configFor(s),l=NA(c),u=l.rangeParamsFor(r);if(!u)throw new J(`step-config: key "${r}" is not a bounded (range) config key (have keys: ${l.listKeys().join(`, `)})`);let d=tW(s),f=WI(c,e=>t.sessionState.get(a,e),r),p=iH(d.path,f.key),m=typeof p==`number`?qU(u,p):JU(`step-config`,r,u,FA(f.globals,r)),h=WU(m,o,u.min,u.max),g=l.validate(r,String(h));if(!g.ok)throw new J(`step-config: ${g.reason}`);aH(nW(t,a),d,[[f.key,g.value]]),t.reloadConfig(s),t.dlog(`info`,`step-config: ${f.key} ${m}→${g.value} (by ${o}) → ${d.path} (session=${a})`)},aW=(e,t)=>{let[n=``]=FU(()=>zn(e)),r=NU(n),i=QU(t,r),a=t.configFor(i),o=e=>t.sessionState.get(r,e),s=HI(a,o),c=GI(a,o);if(s.length+c.length===0){t.dlog(`info`,`save: nothing unsaved (session=${r})`);return}let l=pL(a),u=s.map(e=>{let t=l.validate(e.sessionKey,e.value);if(!t.ok)throw new J(`save: ${t.reason}`);return[e.target,t.value]});sW(`save`,l,c);let d=tW(i);oH(nW(t,r),d,u,c),t.reloadConfig(i);for(let e of[...s.map(e=>e.sessionKey),...c.map(e=>e.key)])t.sessionState.clear(r,e);t.dlog(`info`,`save: ${[...u.map(([e,t])=>`${e}=${t}`),...c.map(oW)].join(` `)} → ${d.path} (session=${r})`)},oW=e=>`${e.preset}/${e.id}.settings.${e.setting}=${Oh(e.value)}`;function sW(e,t,n){for(let r of n){let n=t.validate(r.key,Oh(r.value));if(!n.ok)throw new J(`${e}: ${n.reason}`)}}const cW=(e,t)=>{let[n=``]=FU(()=>zn(e)),r=NU(n),i=QU(t,r),a=t.configFor(i),o=YI(a,e=>t.sessionState.get(r,e)),s=pL(a),c=o.picks.map(e=>{let t=s.validate(e.sessionKey,e.value);if(!t.ok)throw new J(`save-preset: ${t.reason}`);return[e.configKey,t.value]});sW(`save-preset`,s,o.placements);let l=tW(i),u=pH(nW(t,r),l,o.from,o.globals,c,o.placements);t.reloadConfig(i);for(let e of[...ma.map(e=>e.sessionKey),...o.placements.map(e=>e.key)])t.sessionState.clear(r,e);t.sessionState.set(r,pa.preset.sessionKey,u),t.dlog(`info`,`save-preset: ${[`${u} from=${o.from}`,...c.map(([e,t])=>`${e}=${t}`),...o.placements.map(oW)].join(` `)} → ${l.path} (session=${r})`)},lW=(e,t)=>{let[n=``]=FU(()=>zn(e)),r=NU(n),i=QU(t,r),a=ZI(t.configFor(i),e=>t.sessionState.get(r,e));if(a.kind===`rule`)throw new J(`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 o=tW(i);mH(nW(t,r),o,a.theme,a.look),t.reloadConfig(i);let s=new Set(HI(t.configFor(i),e=>t.sessionState.get(r,e)).map(e=>e.sessionKey)),c=gh.map(e=>pa[e].sessionKey).filter(e=>!s.has(e));for(let e of c)t.sessionState.clear(r,e);t.dlog(`info`,`save-theme-default: ${a.theme} ${gh.map(e=>`${e}=${a.look[e]}`).join(` `)} → ${o.path} (session=${r})`)},uW=(e,t)=>{let[n=``,r=``]=FU(()=>zn(e)),i=NU(n);if(!r)throw new J(`delete-preset: <name> is required (shape: <sessionId>/<name>)`);let a=QU(t,i),o=tW(a);hH(nW(t,i),o,r),t.reloadConfig(a);let s=pa.preset.sessionKey;t.sessionState.get(i,s)===r&&t.sessionState.clear(i,s),t.dlog(`info`,`delete-preset: ${r} ← ${o.path} (session=${i})`)},dW=(e,t)=>{let[n=``,...r]=FU(()=>zn(e)),i=NU(n),a=QU(t,i),o=NA(t.configFor(a)).listKeys(),s=r.length===0?[``]:r.filter(e=>!o.includes(e));if(s.length>0)throw new J(`reset-config: unknown config key "${s.join(`", "`)}" (have: ${o.join(`, `)})`);let c=tW(a),l=r.map(QI),u=l.flatMap(e=>e.fileKeys),d=l.flatMap(e=>e.sessionKeys);uH(nW(t,i),c,u),t.reloadConfig(a);for(let e of d)t.sessionState.clear(i,e);t.dlog(`info`,`reset-config: ${[...u,...d.map(e=>`session:${e}`)].join(` `)} ← ${c.path} (session=${i})`)};function fW(e,t){let n=(e,t)=>[...dh(Xh(e,t).node)].filter(e=>e.kind===`segment`),r=new Set(qh(t.presets).flatMap(e=>n(t,e).map(t=>nD(qw(e),sh(t)))));return qh(e.presets).flatMap(t=>n(e,t).map(e=>({member:nD(qw(t),sh(e)),node:e})).filter(({member:e})=>!r.has(e)))}function pW(e,t){return e.flatMap(({member:e,node:n})=>[...Object.values(n.drafts??{}).map(e=>e.key),...e===t?[XE]:[]])}const mW=(e,t)=>{let[n=``,r=``,i=``]=FU(()=>zn(e)),a=NU(n),o=QU(t,a),s=t.configFor(o),c=NA(s);if(!r)throw new J(`apply-layout-op: <key>/<op> is required (have: ${c.listKeys().join(`, `)})`);let l=c.validate(r,i);if(!l.ok)throw new J(`apply-layout-op: ${l.reason}`);let u=yA(l.value);if(u===null)throw new J(`apply-layout-op: "${l.value}" is not a layout op token`);let d=tW(o),f=gH(nW(t,a),d,r,u);t.reloadConfig(o);let p=pW(fW(s,t.configFor(o)),t.sessionState.get(a,XE)).filter(e=>t.sessionState.get(a,e)!==null);for(let e of p)t.sessionState.clear(a,e);t.dlog(`info`,`apply-layout-op: ${r} ${l.value} → ${d.path} placed=${JSON.stringify(f)} released=${JSON.stringify(p)} (session=${a})`)},hW=(e,t)=>{let[n=``]=FU(()=>zn(e)),r=NU(n);t.journal.commit();let i=t.history.undo(r);$U(t,r,i),t.dlog(`info`,`undo: restored ${RH(i)} (session=${r})`)},gW=(e,t)=>{let n=NU(PU(e)),{step:r,discarded:i}=t.navigation.back(n,t.sessionState,pL(eW(t,n))),a=r.map(e=>`${e.key}=${e.before??`∅`}`).join(` `);t.dlog(`info`,`back: ${a} discarded=${i} (session=${n})`)},_W=(e,t)=>{let n=NU(PU(e));t.journal.commit();let r=t.history.rewind(n);$U(t,n,r),t.dlog(`info`,`rewind: put back ${RH(r)||`nothing`} as edit mode found it (session=${n})`)},vW=(e,t)=>{let[n=``]=FU(()=>zn(e)),r=NU(n);t.journal.commit();let i=t.history.redo(r);$U(t,r,i),t.dlog(`info`,`redo: re-applied ${RH(i)} (session=${r})`)},yW=(e,t)=>{NU(PU(e)),t.applyUpdate()},bW=`client-hints`;function xW(e,t){let n=e.sessionState.get(t,bW);if(n===null)throw new J(`session ${t} has not rendered yet — no client facts are recorded for it`);let r;try{r=JSON.parse(n)}catch{throw new J(`client hints record is not JSON: ${n}`)}if(typeof r!=`object`||!r)throw new J(`client hints record is not an object: ${n}`);return rt(r)}function SW(e,t,n){let r=ND(n);e.sessionState.setBatch(t,RD(r)),e.dlog(`info`,`doctor: ${r.map(e=>`${e.check.name}=${e.verdict.ok?`ok`:`failed(${1+(e.verdict.more?.length??0)})`}`).join(` `)} (session=${t})`)}function CW(e,t){return{...tU(e.doctor,xW(e,t),QU(e,t),n=>e.sessionState.get(t,n)),urlHandler:$H(e.clientVersion)}}const wW=(e,t)=>{let n=NU(PU(e));SW(t,n,CW(t,n))},TW=(e,t)=>{let n=mU(PU(e));if(n===null)throw new J(`doctor-probe: the value is not a probe nonce`);t.probes.arrive({nonce:n,handler:t.clientVersion}),t.dlog(`info`,`doctor-probe: arrived nonce=${n} handler=${t.clientVersion??`unreported`}`)},EW=(e,t)=>{let[n=``,r=``]=FU(()=>zn(e)),i=NU(n),a=PD(r);if(a===void 0)throw new J(`doctor-fix: unknown check "${r}"`);let o=CW(t,i),s=a.probe(o);if(s.ok||s.fix===void 0)throw new J(`doctor-fix: ${a.label} — ${s.ok?`nothing to fix`:s.reason}`);let c=nU(s.fix,o);t.dlog(`info`,`doctor-fix: ${a.name} → ${s.fix.kind} ${s.fix.path.join(`.`)}=${JSON.stringify(s.fix.value)} (session=${i})`),SW(t,i,c)},DW=(e,t)=>{let[n=``,...r]=FU(()=>zn(e)),i=NU(n),a=QU(t,i),o=Object.values(t.configFor(a).actions).filter(e=>`ceiling`in e).find(e=>{let t=FM(e);return t.length===r.length&&t.every((e,t)=>e===r[t])});if(o===void 0)throw new J(`ceiling: "${r.join(` `)}" is not a move this config declares`);let s=o.ceiling===`set`?{kind:`set`,to:o.to}:{kind:`clear`},c=GF({sessionId:i,projectDir:a.projectDir,cwd:a.cwd},xW(t,i));t.memento.move(c,s),t.dlog(`info`,`ceiling: ${r.join(` `)} (session=${i} claudeConfigDir=${c.claudeConfigDir})`)},OW=(e,t)=>{let[n=``,r=``]=FU(()=>zn(e)),i=NU(n),a=Object.values(t.configFor(QU(t,i)).actions).filter(e=>`slash`in e),o=a.find(e=>e.slash===r);if(o===void 0)throw new J(`${JSON.stringify(r)} is not a command this config declares (it declares: ${[...new Set(a.map(e=>e.slash))].join(`, `)||`none`})`);let s=DU(t.claudeInput,xW(t,i).tmux,o.slash);if(s.kind===`refused`)throw t.dlog(`warn`,`slash: ${r} refused — ${s.reason} (session=${i})`),new J(`${r} was not typed: ${s.reason}`);t.dlog(`info`,`slash: typed ${r} into ${s.pane} (session=${i})`)},kW=`config-override`,AW=new Map([[_n,LU],[`load-config`,(e,t)=>{let n=e.indexOf(`/`);if(n===-1)throw new J(`load-config: expected <sessionId>/<path> (missing separator)`);let r=NU(FU(()=>decodeURIComponent(e.slice(0,n)))),i=FU(()=>decodeURIComponent(e.slice(n+1))).trim();if(i!==``){if(!i.startsWith(`/`))throw new J(`load-config: path must be absolute, got "${i}"`);if(!/\.(json5?|json)$/.test(i))throw new J(`load-config: path must end with .json5 or .json, got "${i}"`)}i===``?(t.sessionState.clear(r,kW),t.dlog(`info`,`load-config: override cleared (session=${r})`)):(t.sessionState.set(r,kW,i),t.dlog(`info`,`load-config: ${i} (session=${r})`))}],[vn,RU],[gn,HU],[N,GU],[Sn,rW],[Cn,iW],[Dn,dW],[wn,aW],[P,cW],[Tn,lW],[En,uW],[On,mW],[kn,hW],[An,vW],[jn,gW],[Mn,_W],[bn,zU],[xn,BU],[yn,VU],[Nn,yW],[Pn,wW],[Fn,EW],[In,TW],[Ln,DW],[Rn,OW]]),jW=new Set([gn,N,Sn,Cn,Dn,wn,P,Tn,En,On,kn,An,jn,Mn,yn,Nn,Pn,Fn,Ln,Rn]),MW=(e,t)=>{let n=[],r=!1,i=null;for(let{verb:a,value:o}of Hn(Bn(e))){if(!i&&jW.has(a)){let e=zn(o);e.length>0&&e[0]&&(i=e[0])}let e=AW.get(a);if(!e){n.push(`unknown effect verb "${a}"`);continue}try{e(o,t)}catch(e){e instanceof J||(r=!0),n.push(`${a}: ${e instanceof Error?e.message:String(e)}`)}}if(n.length>0){i&&t.sessionState.set(i,`click.error`,n.join(`
211
+ `));let e=`dispatch: ${n.join(`; `)}`;throw r?Error(e):new J(e)}};function NW(e){return(t,n)=>{let r=n.history.begin(),i=n.navigation.begin(r.sessionState),a=[];try{e(t,{...n,sessionState:r.sessionState,journal:r,navigating:i.sessionState})}catch(e){a.push(e)}i.commit();try{r.commit()}catch(e){a.push(e)}if(a.length===1)throw a[0];if(a.length>1)throw Error(a.map(e=>String(e.message??e)).join(`; `))}}const PW=new Map([...AW,[hn,MW]].map(([e,t])=>[e,NW(t)]));Object.freeze([...PW.keys()]);const FW=new Set([`hook_event_name`,`session_id`,`session_name`,`transcript_path`,`cwd`,`model`,`workspace`,`version`,`output_style`,`cost`,`context_window`,`exceeds_200k_tokens`,`effort`,`thinking`,`rate_limits`,`vim`,`agent`,`worktree`]),IW=[[`session_id`,`string`],[`transcript_path`,`string`],[`cwd`,`string`],[`model`,`object`],[`model.id`,`string`],[`model.display_name`,`string`],[`workspace`,`object`],[`workspace.current_dir`,`string`],[`workspace.project_dir`,`string`]],LW=[[`workspace.added_dirs`,`string-list`]];function RW(e){let t={missingRequired:[],typeMismatches:[],unknownTopLevelFields:[]},n=typeof e==`object`&&e&&!Array.isArray(e)?e:{};for(let[e,r]of IW){let i=VW(n,e);if(i==null)t.missingRequired.push(e);else{let n=zW(i);n!==r&&t.typeMismatches.push({path:e,expected:r,got:n})}}for(let[e,r]of LW){let i=VW(n,e),a=i===void 0?r:BW(i);a!==r&&t.typeMismatches.push({path:e,expected:r,got:a})}for(let e of Object.keys(n))FW.has(e)||t.unknownTopLevelFields.push(e);return{data:e,report:t}}function zW(e){return Array.isArray(e)?`array`:typeof e==`string`&&!e.isWellFormed()?`ill-formed string`:typeof e}function BW(e){return Array.isArray(e)&&e.every(e=>zW(e)===`string`)?`string-list`:zW(e)}function VW(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n||Array.isArray(n))return;n=n[e]}return n}function HW(e,t){switch(e){case`vars`:return{what:e,vars:UW(t)};case`segments`:return{what:e,segments:JW(t)};case`config`:return{what:e,config:QW(t)}}}function UW(e){if(e===null)return[];let{store:t,registry:n,config:r}=e,i=KW(r),a=t.names().sort(),o=[];for(let e of a){let r=t.getNode(e),a=WW(r),s=n.getLastError(e);o.push({name:e,source:i.get(e)??null,...a,lastError:s===void 0?null:{timestampMs:s.timestamp,message:s.message},ageMs:GW(r.lastUpdatedMs())})}return o}function WW(e){if(e.kind!==`document`)try{return{type:e.type,value:e.read()}}catch(t){return{type:e.type,value:t instanceof Error?t.message:String(t)}}let t=e.read();switch(t.kind){case`ok`:return{type:`document`,value:JSON.stringify(t.value)};case`absent`:return{type:`document`,value:`(not yet scanned)`};case`failed`:return{type:`document`,value:t.reason}}}function GW(e){return e===null?null:Math.max(0,Date.now()-e)}function KW(e){let t=new Map;for(let[n,r]of Object.entries(e.variables))t.set(n,qW(r));for(let[n,r]of Object.entries(e.segments))if(r.vars)for(let[e,i]of Object.entries(r.vars))t.set(`${n}.${e}`,qW(i));return t}function qW(e){return e.kind}function JW(e){if(e===null)return[];let{store:t,config:n,lastRenderBySegment:r}=e,i=new Set(t.names()),a=XW(n),o=YW(n),s=[];for(let e of a){let t=n.segments[e];t&&s.push({name:e,description:t.description??null,template:t.template,referencedVars:ZW(t.template,n.helpers,i),placements:(o.get(e)??[]).map(e=>({id:e,lastRender:r.get(e)??null}))})}return s}function YW(e){let t=new Map;for(let n of qh(e.presets))for(let r of dh(Xh(e,n).node)){if(r.kind!==`segment`)continue;let e=t.get(r.name)??[],n=sh(r);e.includes(n)||t.set(r.name,[...e,n])}return t}function XW(e){let t=[],n=new Set;for(let r of dh(Bh(e.root)))r.kind===`segment`&&e.segments[r.name]&&!n.has(r.name)&&(t.push(r.name),n.add(r.name));for(let r of Object.keys(e.segments))n.has(r)||(t.push(r),n.add(r));return t}function ZW(e,t,n){let r=new Set;for(let i of vg(e,t).keys()){if(n.has(i)){r.add(i);continue}let e=i.split(`.`);for(;e.length>1;){e.pop();let t=e.join(`.`);if(n.has(t)){r.add(t);break}}}return Array.from(r).sort()}function QW(e){return e===null?null:e.config}const $W=[`vars`,`segments`,`config`];function eG(e){return typeof e==`string`&&$W.includes(e)}function tG(e){return Math.max(1,e-2)}var nG=class{written=new Map;constructor(e){this.dir=e}pathFor(e){return l.join(this.dir,`${encodeURIComponent(e)}.txt`)}sync(e,t){let n=this.pathFor(e);if(t===(this.written.get(e)??null))return null;try{return t===null?(r.rmSync(n,{force:!0}),this.written.delete(e)):(r.mkdirSync(this.dir,{recursive:!0,mode:448}),r.writeFileSync(n,t,{mode:384}),this.written.set(e,t)),null}catch(e){return`${n}: ${e.message}`}}reset(){this.written.clear();try{return r.rmSync(this.dir,{recursive:!0,force:!0}),null}catch(e){return`${this.dir}: ${e.message}`}}};function rG(e,t){for(let n of Object.entries(t))e.push(n)}const iG={ok:`info`,"bad-request":`warn`,threw:`error`};function aG(e){switch(e.kind){case`ok`:return[];case`bad-request`:return[[`problems`,e.problems.join(`; `)]];case`threw`:return[[`error`,y(e.error)]]}}const oG=/^[^\s"=\\]+$/,sG=e=>oG.test(e)?e:JSON.stringify(e);function cG(e,t,n){let r=[...e,[`took`,`${n}ms`],[`outcome`,t.kind],...aG(t)];return{level:iG[t.kind],line:`render${r.map(([e,t])=>` ${e}=${sG(t)}`).join(``)}`}}const lG=new dV,uG=new fU;Ae(lG.launchStats);const dG=new ow({counters:lG,logger:k}),fG=IR({watchers:dG,logger:k}),{gitProvider:pG,usageStore:mG,mementoProvider:hG}=fG,gG=new mV,_G=new wH(gG,k),vG=new qH,yG=new gm,bG=new nG(Qe()),xG=new lV({gitService:pG,sessionState:gG,watchers:dG},{observers:{onReload:e=>k(`info`,`config loaded projectDir=${e.projectDir} cwd=${e.cwd} files=${e.configLayers.join(` < `)||`<bundled default>`} error=${e.lastError===null?`none`:JSON.stringify(e.lastError)} warning=${e.lastWarning===null?`none`:JSON.stringify(e.lastWarning)}`)}}),SG=60*1e3;function CG(){let e=import.meta.url,n=[];e.startsWith(`file://`)&&n.push(ne(e)),t.argv[1]&&n.push(t.argv[1]);let i=new Map;for(let e of n)try{i.set(e,r.statSync(e).mtimeMs)}catch{}let a=null,o=()=>{for(let[e,t]of i)try{if(r.statSync(e).mtimeMs!==t){k(`info`,`binary mtime changed (${e}); shutting down`),a&&clearInterval(a),zG(0);return}}catch(e){k(`warn`,`bin stat failed: ${e.message}`)}};return{arm(){i.size!==0&&(a=setInterval(o,SG),a.unref())},checkNow:o}}const wG=CG(),TG=FL({entryUrl:import.meta.url,intervalMs:SG,releaseIntervalMs:216e5,registryUrl:t.env.CC_CANDYBAR_REGISTRY_URL??`https://registry.npmjs.org`,fetchImpl:fetch,onApplied:()=>wG.checkNow(),log:k});let EG=null,DG=null,OG=0;function kG(){t.on(`uncaughtException`,e=>{k(`error`,`uncaughtException: ${e.stack||e.message}`),zG(1)}),t.on(`unhandledRejection`,e=>{k(`error`,`unhandledRejection: ${String(e)}`),zG(1)});for(let e of[`SIGINT`,`SIGTERM`,`SIGHUP`])t.on(e,()=>{k(`info`,`received ${e}, shutting down`),zG(0)});try{OG=Vt(t.env)}catch(e){k(`error`,`refusing to boot: ${e.message}`),zG(1);return}EG=ea(t.pid);let e=ua(fa(EG));if(!e.decision.allow){k(`warn`,`fork-bomb breaker: ${e.decision.reason}; refusing to boot`),zG(1);return}DG=e.registryPath,r.mkdirSync(ze(),{recursive:!0}),Ue(Be()),gG.useStorage(new gV(Ke(),500,k)),_G.useStorage(GH(qe(),k)),ra({anchor:na(t.env),isAlive:ia,onOrphaned:e=>{k(`info`,`parent watchdog: ${e}; shutting down`),zG(0)}}),AG(S.createServer({allowHalfOpen:!1},e=>{BG(e)}),Be(),!1)}function AG(e,n,r){e.removeAllListeners(`error`),e.removeAllListeners(`listening`),e.once(`error`,i=>{if(i.code!==`EADDRINUSE`){k(`error`,`server error: ${i.message}`),zG(1);return}if(r){k(`info`,`lost rebind race; another daemon is alive — exiting`),t.exit(0);return}jG(e,n)}),e.listen(n,()=>MG(n))}function jG(e,n){let i=Wi(Gi(We(n)),(e,t)=>$i(e,t,{readStartTime:Qi,pidAlive:ia}));if(i.kind===`attach-and-exit`){k(`info`,`EADDRINUSE: ${i.reason} — exiting`),t.exit(0);return}k(`warn`,`EADDRINUSE: ${i.reason} — unlinking stale socket and rebinding`);try{r.unlinkSync(n)}catch(e){if(e.code!==`ENOENT`){k(`error`,`cannot unlink stale socket ${n}: ${e.message}`),zG(1);return}}AG(e,n,!0)}function MG(e){let n=Ji(e);if(n.kind!==`present`){k(`warn`,`no ownable socket at bind callback (${n.kind}); exiting`),zG(0);return}IG(e);try{r.chmodSync(e,384)}catch(e){k(`warn`,`chmod socket failed: ${e.message}`)}k(`info`,`daemon up: pid=${t.pid} v=3 sock=${e} heapCap=${Math.round(C.getHeapStatistics().heap_size_limit/1048576)}MB rssLimit=${Math.round(OG/1048576)}MB`),M();let i=bG.reset();i!==null&&k(`warn`,`diagnostic dump wipe failed: ${i}`),wG.arm(),TG.arm(),FG(),NG(e,n.identity)}function NG(e,n){Zi({bound:n,myPid:t.pid,readIdentity:()=>Ji(e),readLease:()=>Gi(We(e)),shutdown:e=>zG(e),log:k}).arm()}let PG=null;function FG(){PG=Gt(Yt(lG.startedAt.getTime(),e=>zG(e),{rssLimitBytes:OG})),PG.arm()}function IG(e){let n=Ki(We(e),{pid:t.pid,version:3,binPath:t.argv[1],startTime:EG});n!==null&&k(`warn`,`lease write failed: ${n}`)}let LG=0,RG=!1;function zG(e){if(!RG){RG=!0,setTimeout(()=>t.kill(t.pid,`SIGKILL`),500);try{pG.close()}catch(e){k(`warn`,`gitService close failed: ${e.message}`)}try{mG.close()}catch(e){k(`warn`,`usageStore close failed: ${e.message}`)}try{dG.closeAll()}catch(e){k(`warn`,`watcherRegistry close failed: ${e.message}`)}try{gG.flush()}catch(e){k(`warn`,`sessionState flush failed: ${e.message}`)}qi(Ge(),t.pid),DG!==null&&da(DG,t.pid,ca,e=>r.unlinkSync(e)),t.exit(e)}}function BG(e){LG++,lG.inFlight=LG;let t=!1,n=(n,r)=>{if(t){r!==null&&k(`warn`,`exit-after-flush dropped: an earlier responder settled this socket`);return}t=!0;let i=r===null?void 0:()=>zG(r);try{e.end(mt(n),i)}catch(e){k(`warn`,`response write failed: ${e.message}`),i?.()}},r=!1,i=setTimeout(()=>{r=!0,lG.requestsTimedOut++,n({ok:!1,error:`request exceeded 200ms`,code:`TIMEOUT`,daemonV:3},null)},200),a=ht(e=>{UG(e,()=>r).then(e=>n(e.resp,e.exitAfterFlush)).catch(e=>{k(`error`,`handler threw: ${y(e)}`),n(HG(e),null)})},e=>{k(`warn`,`frame parse failed: ${e.message}`),n({ok:!1,error:e.message,code:`BAD_REQUEST`,daemonV:3},null)});e.on(`data`,a),e.on(`error`,e=>{k(`warn`,`socket error: ${e.message}`)}),e.on(`close`,()=>{clearTimeout(i),LG=Math.max(0,LG-1),lG.inFlight=LG})}const VG=e=>({resp:e,exitAfterFlush:null}),HG=e=>({ok:!1,error:e instanceof Error?e.message:y(e),code:`RENDER_FAILED`,daemonV:3});async function UG(e,t){if(!e||typeof e!=`object`||typeof e.v!=`number`)return VG({ok:!1,error:`malformed request`,code:`BAD_REQUEST`,daemonV:3});if(e.v!==3)return e.v>3?k(`info`,`version mismatch: client=${e.v} > daemon=3; binary likely upgraded — exiting after the response flushes`):k(`info`,`version mismatch: client=${e.v} < daemon=3; client is stale — staying up`),{resp:{ok:!1,error:`protocol v${e.v} not supported (daemon at v3)`,code:`VERSION_MISMATCH`,daemonV:3},exitAfterFlush:e.v>3?0:null};if(e.kind===`shutdown`)return{resp:{ok:!0,output:``},exitAfterFlush:0};if(e.kind===`stats`)return VG({ok:!0,stats:lG.snapshot({gitCache:pG.getStats(),usageCache:mG.getStats(),renderCacheSize:xG.size,effectCache:yG.getStats(),watchersActive:dG.size(),nextRestartReason:PG?.describeNextRestart()??null,handlerProbes:uG.list()})});if(e.kind===`render`){lG.requestsTotal++;let n=new Date,r=vw(n),i=n.getTime(),a=[],o=await ZG(e,r,a).catch(e=>({outcome:{kind:`threw`,error:e},resp:HG(e)}));o.outcome.kind!==`ok`&&lG.requestsErrored++,rG(a,{timedOut:t()?`Y`:`N`});let{level:s,line:c}=cG(a,o.outcome,Date.now()-i);return k(s,c),VG(o.resp)}if(e.kind===`click`)return VG(XG(e.verb,e.value,ft(e.clientVersion)));if(e.kind===`debug`){if(!eG(e.what))return VG({ok:!1,error:`unknown debug 'what': ${String(e.what)} (have: ${$W.join(`, `)})`,code:`BAD_REQUEST`,daemonV:3});let t=xG.firstState(),n=t===null?null:{store:t.store,registry:t.registry,config:t.config,compiled:t.compiled,lastRenderBySegment:e.what===`segments`?JG(t.lastRenderCellsBySegment,t.config.globals.charset??`unicode`,t.config.globals.colorCompatibility??`truecolor`):qG};return VG({ok:!0,debug:HW(e.what,n)})}return VG({ok:!1,error:`unknown kind`,code:`BAD_REQUEST`,daemonV:3})}function WG(e,t){let{values:n,tokens:r}=b({args:e.slice(1),options:{config:{type:`string`}},strict:!1,tokens:!0,allowPositionals:!0}),i=[...new Set((r??[]).filter(e=>e.kind===`option`&&e.name!==`config`).map(e=>`--${e.name}`))];return{configFile:dP(t,n.config),unknownFlagsError:i.length>0?`Unknown flags: ${i.join(`, `)}`:null}}const GG={sessionState:gG,dlog:k,applyUpdate:()=>TG.act(),doctor:YH(e=>{let t=[e.projectDir,e.cwd,e.configFile??void 0];xG.reload(...t);let n=xG.getOrCreate(...t);return{layers:n.configLayers,error:n.lastError,warning:n.lastWarning,unused:n.state.unused,config:n.state.config}}),probes:uG,memento:hG,claudeInput:MU(),history:_G,navigation:vG,configFor:e=>xG.getOrCreate(e.projectDir,e.cwd,e.configFile??void 0).state.config,reloadConfig:e=>xG.reload(e.projectDir,e.cwd,e.configFile??void 0)};GG.reloadConfig;const KG={endcaps:`powerline`,colorCompatibility:`truecolor`,wrap:!0,padding:1,charset:Rp,width:1/0},qG=new Map;function JG(e,t,n){let r=new Map;for(let[i,a]of e)r.set(i,Dm(a,{...KG,charset:t,colorCompatibility:n}));return r}const YG={...fG,history:e=>_G.depth(e)};function XG(e,t,n){let r=PW.get(e);if(!r)return{ok:!1,error:`unknown click verb: ${e}`,code:`BAD_REQUEST`,daemonV:3};try{return r(t,{...GG,clientVersion:n}),{ok:!0,output:``}}catch(e){let t=e instanceof J?`BAD_REQUEST`:`RENDER_FAILED`;return{ok:!1,error:String(e instanceof Error?e.message:e),code:t,daemonV:3}}}async function ZG(e,t,n){let{report:r}=RW(e.hookData);for(let e of r.unknownTopLevelFields)k(`info`,`schema: unknown field '${e}' — Anthropic may have added it`);let i=[];for(let e of r.missingRequired)i.push(`missing required field '${e}'`);for(let{path:e,expected:t,got:n}of r.typeMismatches)i.push(`field '${e}' expected ${t}, got ${n}`);if(f(e.cwd)||i.push(`request 'cwd' is not an absolute path: "${e.cwd}"`),i.length>0)return{outcome:{kind:`bad-request`,problems:i},resp:{ok:!1,error:`malformed hookData: ${i.join(`; `)}`,code:`BAD_REQUEST`,daemonV:3}};rG(n,{sid:e.hookData.session_id,at:t.toFixed(3)});let a=e.hookData.workspace.project_dir,{configFile:o,unknownFlagsError:s}=WG(e.args,e.cwd),c=e.hookData.session_id,l=rt(e),u=it(e,l),d=at(u);rG(n,{termCols:String(l.termCols??`?`),termRows:String(l.termRows??`?`),refused:u.map(e=>e.hint).join(`,`)||`-`});let p=JSON.stringify(l);gG.get(c,`client-hints`)!==p&&gG.set(c,bW,p);let m=gG.get(c,`config-override`)??o??l.configEnv,h=xG.getOrCreate(a,e.cwd,m),g=XU({projectDir:a,cwd:e.cwd,configFile:m??null});gG.get(c,`render-origin`)!==g&&gG.set(c,YU,g);let _=l.termCols,v=tG(_??120),y=Om(l.termRows);rG(n,{width:String(v)});let{authoredRoots:b}=h.state,x=t=>gG.get(e.hookData.session_id,t),S=iI(h.state.config,x,e=>b.has(e)),C=await CI(e.hookData,t,{...YG,navigation:e=>vG.depth(e,gG,pL(h.state.config))},e.cwd,h.state.neededInputPaths(S.preset),S,l,{...eL(h.state.config,h.state.fileHeldSettings,x),configPath:h.configLayers.includes(h.configHome)?h.configHome:null});rG(n,{prompts:String(C.metrics?.messageCount??`-`),nonPrompts:String(C.metrics?.nonPrompts??`-`),pr:lI(C.git)});let ee=[],te=aI(S,v),ne=yG.of(c),re=HB(h.state.config,h.state.compiled,h.state.store,h.state.registry,C,t,te,{perSegmentSink:h.state.lastRenderCellsBySegment,onRenderWarning:e=>ee.push(e)},{...oI(S),effects:ne}),ie=gG.get(e.hookData.session_id,`click.error`);ie&&gG.clear(e.hookData.session_id,`click.error`);let ae=[s,d,h.lastError,ie].filter(Boolean).join(`
212
+ `),w=TG.notice({sessionId:c,dismissed:gG.get(c,yL),enabled:S.updateNotice}),T=h.lastError===null?null:h.failedFile,oe=[...h.lastWarning===null?[]:[{kind:`load`,message:h.lastWarning}],...ee],se=Nm(ae,w,oe.map(e=>e.message).join(`
213
+ `)),ce=bG.sync(c,se===null?null:Fm(se));ce!==null&&k(`warn`,`diagnostic dump failed: ${ce}`);let le=Im(re,se,{fullText:ce===null?{kind:`file`,path:bG.pathFor(c)}:{kind:`unavailable`,reason:ce},failedConfigFile:T},{width:v,rowCap:y,colorCompatibility:S.colorCompatibility}),ue=pG.getStats(),E=mG.getStats(),de=ne.lastFrame(),fe=de.own.map(e=>`${e.placement}:${e.effect}@${e.t.toFixed(3)}`).join(`,`)||`-`,pe=e=>e.map(e=>`${e.placement}@${e.t.toFixed(3)}`).join(`,`)||`-`,me=oe.map(e=>{switch(e.kind){case`rule`:return`rule:${e.slot}`;case`load`:case`band-floor`:case`when`:return e.kind}}).join(`,`)||`-`;return rG(n,{git:`${ue.size}/${ue.hits}h/${ue.misses}m`,usage:`${E.size}/${E.hits}h/${E.misses}m`,effect:de.effect,effectT:de.t.toFixed(3),effectRows:`${de.made}made/${de.reused}reused`,effectOwn:fe,fadeBasis:de.basis,stateRev:String(de.revision),fades:pe(de.fades),leaves:pe(de.leaves),err:ae?`Y`:`N`,upd:String(w.length),warn:me}),{outcome:{kind:`ok`},resp:{ok:!0,output:le+`
214
+ `}}}const QG={connectMs:200,budgetMs:500};async function $G(e,n){let r=n.includes(`--json`),i=await eK(e);if(i.kind!==`ok`&&(t.stderr.write(`${e}: ${Ct(i)}\n`),t.exit(1)),r){t.stdout.write(JSON.stringify(i.value,null,2)+`
215
+ `);return}t.stdout.write(tK(i.value))}function eK(e){return _t({kind:`debug`,what:e},QG,e=>`debug`in e?e.debug:void 0)}function tK(e){switch(e.what){case`vars`:return nK(e.vars);case`segments`:return rK(e.segments);case`config`:return iK(e.config);default:return e}}function nK(e){if(e.length===0)return`no variables (DSL not active)
216
+ `;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?``:` ${oK(a.ageMs)}`,o=a.lastError?` ✗ ${a.lastError.message}`:``;t.push(` ${a.name.padEnd(n)} ${(a.source??`—`).padEnd(r)} ${a.type.padEnd(i)} ${aK(a.value)}${e}${o}`)}return t.join(`
217
217
  `)+`
218
- `}function tK(e){if(e.length===0)return`no segments (DSL not active)
218
+ `}function rK(e){if(e.length===0)return`no segments (DSL not active)
219
219
  `;let t=[`segments (${e.length})`,``];for(let n of e){t.push(` ${n.name}`),n.description!==null&&t.push(` shows ${n.description}`),t.push(` template ${n.template}`),n.referencedVars.length>0&&t.push(` vars ${n.referencedVars.join(`, `)}`);for(let{id:e,lastRender:r}of n.placements)r!==null&&t.push(` last ${e}: ${r}`)}return t.join(`
220
220
  `)+`
221
- `}function nK(e){return e===null?`config: DSL not active
221
+ `}function iK(e){return e===null?`config: DSL not active
222
222
  `:JSON.stringify(e,null,2)+`
223
- `}function rK(e){let t=typeof e==`string`?e:JSON.stringify(e);return t.length>60?t.slice(0,57)+`…`:t}function iK(e){return e<1e3?`${e}ms`:e<6e4?`${(e/1e3).toFixed(1)}s`:`${Math.floor(e/6e4)}m`}function aK(){let e=sK();return e===null?null:r.readFileSync(e,`utf-8`)}function oK(){let e;try{e=aK()}catch(e){t.stderr.write(`schema: cannot read bundled schema: ${e instanceof Error?e.message:String(e)}\n`),t.exit(2)}e===null&&(t.stderr.write("schema: bundled schema not found (expected schema/cc-candybar.schema.json). Run `pnpm gen:schema` from a source checkout.\n"),t.exit(2)),t.stdout.write(e),t.exit(0)}function sK(){let e=l.join(`schema`,`cc-candybar.schema.json`),n=t.argv[1];if(n===void 0)return null;let i=l.dirname(l.resolve(n));for(;;){let t=l.join(i,e);if(r.existsSync(t))return t;let n=l.dirname(i);if(n===i)return null;i=n}}function cK(e,t){return dP(t,e.CC_CANDYBAR_CONFIG)}const lK=5e3;function uK(e,t,n){let r=`/home/tester`,i=Math.floor(n),a=`test0a1b-2c3d-4e5f-6a7b-8c9d0e1f2a3b`,o={current_dir:`${r}/code/cc-candybar/src`,project_dir:`${r}/code/cc-candybar`,added_dirs:[]};return{hook_event_name:`Status`,session_id:a,version:`1.15.0`,home:r,cwd:`${r}/code/cc-candybar/src`,transcript_path:`${r}/.claude/projects/x/test.jsonl`,model:{id:`claude-opus-4-8`,display_name:`Opus 4.8`},workspace:o,git:{repoName:`cc-candybar`,repoUrl:`https://github.com/promptctl/cc-candybar`,branch:`main`,sha:`abc1234`,ahead:2,behind:1,staged:3,unstaged:2,untracked:1,conflicts:0,upstream:`origin/main`,tracking:`tracked`,stash:1,status:`dirty`,operation:`rebase`,timeSinceCommit:780},session:{cost:.39,tokens:241400},today:{cost:12.5,tokens:34e5},context:{totalTokens:48487,contextLeft:24},metrics:{lastResponseTime:8.2,responseTime:4.2,sessionDuration:930,messageCount:8,linesAdded:512,linesRemoved:88},block:{nativeUtilization:63,resetsAt:i+2*3600},weekly:{percentage:21,resetsAt:i+5*86400},cache:{expiresAt:i+900},tmux:{pane:`%0`,session:`work`},host:{name:`tester-box`,user:`tester`,ssh:!0},autocompact:nO(4e5,1e6),...sI(e),history:{undo:1,redo:1,sinceEdit:1},navigation:{back:1},unsaved:1,resettable:ya(()=>!0),themeDefault:{differs:!0,theme:`<theme>`},resumeCommand:rI(o,a,void 0),configPath:t??`${r}/.config/cc-candybar/config.json5`}}function dK(e,t){let n=WP(e,e),r=qP(n);return r!==null&&t.push(r),n.kind===`chain`?n.layers:[]}async function fK(e,n=t.cwd()){let i=[],a=dP(n,e)??null,o=a===null?dK(n,i):[a];if(a!==null){let e;try{e=r.statSync(a,{throwIfNoEntry:!1})}catch(e){return{kind:`unreadable`,path:a,message:e instanceof Error?e.message:String(e)}}if(e!==void 0&&!e.isFile())return{kind:`unreadable`,path:a,message:`not a file`}}let s=YP(n,n);s!==null&&i.push(s);try{return{kind:`clean`,layers:o,warnings:i,rendered:await hK(o,n,i)}}catch(e){let t=e;return typeof t==`object`&&t&&typeof t.code==`string`&&typeof t.path==`string`&&o.includes(t.path)&&typeof t.message==`string`?{kind:`unreadable`,path:t.path,message:t.message}:(e instanceof Jw&&i.push(...e.warnings),{kind:`fatal`,layers:o,message:e instanceof Jw||e instanceof Error?e.message:String(e),warnings:i})}}async function pK(e,t,n){let r=nF(e,TF,{entered:()=>{},warned:e=>n.push(...e)},{projectDir:t,cwd:t}),{config:i}=r,a=new QB,o=new Hw(a,i.globals.default_empty_value??``,void 0,new fV);try{let s=PB(i,o,{cwd:t});n.push(...s.loadWarnings);let c=await o.settled(lK);return c.length>0&&n.push(`source${c.length===1?``:`s`} still running after ${lK} ms, rendered with fallback values: ${c.join(`, `)}`),{layers:e,droppedPlugins:[...r.installed.dropped,...r.layers.flatMap(e=>e.plugins.dropped)],config:i,compiled:s,store:a,registry:o}}catch(e){throw o.dispose(),e}}function mK({layers:e,config:t,compiled:n,store:r,registry:i},a,o,s){let c=new Map,l=new Set;return{rendered:BB(t,n,r,i,uK(a,e.at(-1)??null,s),s,aI(a,o),{onSegmentError:(e,t)=>c.set(`segment "${e}"`,t),onRenderWarning:e=>{switch(e.kind){case`rule`:c.set(`${e.slot} rule`,e.message);return;case`when`:c.set(e.where,e.error);return;case`band-floor`:l.add(e.message);return;default:}}},oI(a)),failures:c,advisories:l}}async function hK(e,t,n){let r=await pK(e,t,n),{config:i}=r,a=vw(new Date);try{let e=ML();try{dL(i),NA(i)}finally{e()}let t=Jh(null,i.globals.preset,i.presets),o=(e,t)=>{let n=iI(i,t=>t===`preset`?e:null,()=>t),o;try{o=mK(r,n,200,a)}catch(e){o={failures:new Map([[`render`,e instanceof Error?e.message:String(e)]]),advisories:new Set}}return{preset:e,customized:t,...o}},s=o(t,!1),c=[s,o(t,!0),...qh(i.presets).filter(e=>e!==t).flatMap(e=>[o(e,!1),o(e,!0)])],l=e=>{let n=new Map;for(let t of c)for(let r of e(t)){let e=n.get(r)??new Map;e.set(t.preset,(e.get(t.preset)??new Set).add(t.customized)),n.set(r,e)}return[...n].map(([e,n])=>n.get(t)?.has(!1)?e:`${e} (under ${[...n].map(([e,n])=>[...e===t?[]:[`preset "${e}"`],...n.has(!1)?[]:[`.preset.customized = true`]].join(`, `)).join(`; `)})`)};n.push(...l(e=>e.advisories));let u=l(e=>[...e.failures].map(([e,t])=>`${e}: ${t}`)),d=s.rendered,f=r.droppedPlugins.length,p=[...f>0?[`${f} plugin${f===1?``:`s`} did not load (named in the warnings)`]:[],...u.length>0||d===void 0?[`config renders with ${u.length} render error${u.length===1?``:`s`} (the daemon would show them on the bar):\n`+u.map(e=>` ${e}`).join(`
223
+ `}function aK(e){let t=typeof e==`string`?e:JSON.stringify(e);return t.length>60?t.slice(0,57)+`…`:t}function oK(e){return e<1e3?`${e}ms`:e<6e4?`${(e/1e3).toFixed(1)}s`:`${Math.floor(e/6e4)}m`}function sK(){let e=lK();return e===null?null:r.readFileSync(e,`utf-8`)}function cK(){let e;try{e=sK()}catch(e){t.stderr.write(`schema: cannot read bundled schema: ${e instanceof Error?e.message:String(e)}\n`),t.exit(2)}e===null&&(t.stderr.write("schema: bundled schema not found (expected schema/cc-candybar.schema.json). Run `pnpm gen:schema` from a source checkout.\n"),t.exit(2)),t.stdout.write(e),t.exit(0)}function lK(){let e=l.join(`schema`,`cc-candybar.schema.json`),n=t.argv[1];if(n===void 0)return null;let i=l.dirname(l.resolve(n));for(;;){let t=l.join(i,e);if(r.existsSync(t))return t;let n=l.dirname(i);if(n===i)return null;i=n}}function uK(e,t){return dP(t,e.CC_CANDYBAR_CONFIG)}const dK=5e3;function fK(e,t,n){let r=`/home/tester`,i=Math.floor(n),a=`test0a1b-2c3d-4e5f-6a7b-8c9d0e1f2a3b`,o={current_dir:`${r}/code/cc-candybar/src`,project_dir:`${r}/code/cc-candybar`,added_dirs:[]};return{hook_event_name:`Status`,session_id:a,version:`1.15.0`,home:r,cwd:`${r}/code/cc-candybar/src`,transcript_path:`${r}/.claude/projects/x/test.jsonl`,model:{id:`claude-opus-4-8`,display_name:`Opus 4.8`},workspace:o,git:{repoName:`cc-candybar`,repoUrl:`https://github.com/promptctl/cc-candybar`,branch:`main`,sha:`abc1234`,ahead:2,behind:1,staged:3,unstaged:2,untracked:1,conflicts:0,upstream:`origin/main`,tracking:`tracked`,stash:1,status:`dirty`,operation:`rebase`,timeSinceCommit:780},session:{cost:.39,tokens:241400},today:{cost:12.5,tokens:34e5},context:{totalTokens:48487,contextLeft:24},metrics:{lastResponseTime:8.2,responseTime:4.2,sessionDuration:930,messageCount:8,linesAdded:512,linesRemoved:88},block:{nativeUtilization:63,resetsAt:i+2*3600},weekly:{percentage:21,resetsAt:i+5*86400},cache:{expiresAt:i+900},tmux:{pane:`%0`,session:`work`},host:{name:`tester-box`,user:`tester`,ssh:!0},autocompact:nO(4e5,1e6),...sI(e),history:{undo:1,redo:1,sinceEdit:1},navigation:{back:1},unsaved:1,resettable:ya(()=>!0),themeDefault:{differs:!0,theme:`<theme>`},resumeCommand:rI(o,a,void 0),configPath:t??`${r}/.config/cc-candybar/config.json5`}}function pK(e,t){let n=WP(e,e),r=qP(n);return r!==null&&t.push(r),n.kind===`chain`?n.layers:[]}async function mK(e,n=t.cwd()){let i=[],a=dP(n,e)??null,o=a===null?pK(n,i):[a];if(a!==null){let e;try{e=r.statSync(a,{throwIfNoEntry:!1})}catch(e){return{kind:`unreadable`,path:a,message:e instanceof Error?e.message:String(e)}}if(e!==void 0&&!e.isFile())return{kind:`unreadable`,path:a,message:`not a file`}}let s=YP(n,n);s!==null&&i.push(s);try{return{kind:`clean`,layers:o,warnings:i,rendered:await _K(o,n,i)}}catch(e){let t=e;return typeof t==`object`&&t&&typeof t.code==`string`&&typeof t.path==`string`&&o.includes(t.path)&&typeof t.message==`string`?{kind:`unreadable`,path:t.path,message:t.message}:(e instanceof Jw&&i.push(...e.warnings),{kind:`fatal`,layers:o,message:e instanceof Jw||e instanceof Error?e.message:String(e),warnings:i})}}async function hK(e,t,n){let r=nF(e,TF,{entered:()=>{},warned:e=>n.push(...e)},{projectDir:t,cwd:t}),{config:i}=r,a=new eV,o=new Hw(a,i.globals.default_empty_value??``,void 0,new mV);try{let s=IB(i,o,{cwd:t});n.push(...s.loadWarnings);let c=await o.settled(dK);return c.length>0&&n.push(`source${c.length===1?``:`s`} still running after ${dK} ms, rendered with fallback values: ${c.join(`, `)}`),{layers:e,droppedPlugins:[...r.installed.dropped,...r.layers.flatMap(e=>e.plugins.dropped)],config:i,compiled:s,store:a,registry:o}}catch(e){throw o.dispose(),e}}function gK({layers:e,config:t,compiled:n,store:r,registry:i},a,o,s){let c=new Map,l=new Set;return{rendered:HB(t,n,r,i,fK(a,e.at(-1)??null,s),s,aI(a,o),{onSegmentError:(e,t)=>c.set(`segment "${e}"`,t),onRenderWarning:e=>{switch(e.kind){case`rule`:c.set(`${e.slot} rule`,e.message);return;case`when`:c.set(e.where,e.error);return;case`band-floor`:l.add(e.message);return;default:}}},oI(a)),failures:c,advisories:l}}async function _K(e,t,n){let r=await hK(e,t,n),{config:i}=r,a=vw(new Date);try{let e=PL();try{pL(i),NA(i)}finally{e()}let t=Jh(null,i.globals.preset,i.presets),o=(e,t)=>{let n=iI(i,t=>t===`preset`?e:null,()=>t),o;try{o=gK(r,n,200,a)}catch(e){o={failures:new Map([[`render`,e instanceof Error?e.message:String(e)]]),advisories:new Set}}return{preset:e,customized:t,...o}},s=o(t,!1),c=[s,o(t,!0),...qh(i.presets).filter(e=>e!==t).flatMap(e=>[o(e,!1),o(e,!0)])],l=e=>{let n=new Map;for(let t of c)for(let r of e(t)){let e=n.get(r)??new Map;e.set(t.preset,(e.get(t.preset)??new Set).add(t.customized)),n.set(r,e)}return[...n].map(([e,n])=>n.get(t)?.has(!1)?e:`${e} (under ${[...n].map(([e,n])=>[...e===t?[]:[`preset "${e}"`],...n.has(!1)?[]:[`.preset.customized = true`]].join(`, `)).join(`; `)})`)};n.push(...l(e=>e.advisories));let u=l(e=>[...e.failures].map(([e,t])=>`${e}: ${t}`)),d=s.rendered,f=r.droppedPlugins.length,p=[...f>0?[`${f} plugin${f===1?``:`s`} did not load (named in the warnings)`]:[],...u.length>0||d===void 0?[`config renders with ${u.length} render error${u.length===1?``:`s`} (the daemon would show them on the bar):\n`+u.map(e=>` ${e}`).join(`
224
224
  `)]:[]];if(p.length>0||d===void 0)throw Error(p.join(`
225
- `));return d}finally{r.registry.dispose()}}function gK(e){return e.map(e=>`warning: ${e}\n`).join(``)}function _K(e,t=!1){switch(e.kind){case`clean`:return{stdout:`✓ ${e.layers.join(` < `)||`bundled default (no config file found)`}: config OK${e.warnings.length>0?` (${e.warnings.length} warning${e.warnings.length===1?``:`s`})`:``}\n`+(t?`${e.rendered}\n`:``),stderr:gK(e.warnings),code:0};case`fatal`:return{stdout:``,stderr:gK(e.warnings)+`✗ ${e.layers.join(` < `)||`<default>`}\n${e.message}\n`,code:1};case`unreadable`:return{stdout:``,stderr:`check: cannot read ${e.path}: ${e.message}\n`,code:2}}}const vK=`--render`,yK=`Usage: cc-candybar check [${vK}] [config-file]\n`;function bK(e){let t=e.filter(e=>e.startsWith(`--`)),n=e.filter(e=>!e.startsWith(`--`)),r=t.filter(e=>e!==vK);return r.length>0?{kind:`usage`,message:`check: unknown option ${r.join(` `)}\n${yK}`}:n.length>1||n[0]===``?{kind:`usage`,message:`check: expected at most one non-empty path\n${yK}`}:{kind:`run`,target:n[0],render:t.includes(vK)}}async function xK(e){let n=bK(e),r=n.kind===`usage`?{stdout:``,stderr:n.message,code:2}:_K(await fK(n.target??cK(t.env,t.cwd())),n.render);t.stdout.write(r.stdout),t.stderr.write(r.stderr),t.exit(r.code)}const SK=`${Gd}${Wd}`;function CK(e){return`${SK}⚠ cc-candybar: ${wK(e)}\n`}function wK(e){switch(e.cause){case`version_mismatch`:{let t=e.daemonV===0?`unknown`:`v${e.daemonV}`;return`protocol mismatch (client v${e.clientV} ≠ daemon ${t})`}case`bad_request`:return`daemon rejected request: ${Ud(e.message,60)}`;case`render_failed`:return`render failed: ${Ud(e.message,60)}`;case`malformed_response`:return`malformed daemon response: ${Ud(e.message,60)}`}}function TK(e){switch(e.kind){case`ok`:return{output:e.value,kick:!1,debug:null};case`transient`:return{output:`
226
- `,kick:!0,debug:`daemon unavailable (transient: ${e.cause}: ${e.message}) — kicking daemon`};case`permanent`:return{output:CK(e),kick:!1,debug:`daemon refused request (permanent: ${e.cause}) — not kicking`}}}function EK(e,t){if(e!==void 0&&/^\+?\d+$/.test(e)){let t=Number(e);if(t>0&&t<=4294967295)return t}if(t&&t>0)return t}const DK=[`SSH_CONNECTION`,`SSH_CLIENT`,`SSH_TTY`];function OK(e,t,n){return{termCols:EK(e.COLUMNS,n.columns),termRows:EK(e.LINES,n.rows),ssh:DK.some(t=>(e[t]??``)!==``),tmux:wD(e),configEnv:cK(e,t),claudeConfigDir:ti(e,t),mementoEnv:tt(e,t)}}const kK=` (fix: click the settings menu (${Gn} by default) › 🧰 tools › 🩺 doctor, then [fix] on the bar)`;function AK({check:e,verdict:t}){return t.ok?`✓ ${e.label}\n`:`✗ ${e.label} — ${t.reason}${t.fix===void 0?``:kK}\n`+(t.more??[]).map(e=>` ${e}\n`).join(``)}function jK(e){let t={sessionState:new fV},n=aV(e.projectDir,e.cwd,e.configFile??void 0,t),r=n.state??oV(e.cwd,e.projectDir,t);return r.registry.dispose(),{layers:n.layers,error:n.error,warning:n.warning,unused:r.unused,config:r.config}}async function MK(e,t,n,r,i=void 0){let a;try{a={...$H(e,{tmux:wD(n),claudeConfigDir:ti(n,r)},{projectDir:r,cwd:r,configFile:dP(r,i)??cK(n,r)??null},()=>null),urlHandler:await hU(t)}}catch(e){return{stdout:``,stderr:`doctor: ${e instanceof Error?e.message:String(e)}\n`,code:2}}let o=ND(a);return{stdout:o.map(AK).join(``),stderr:``,code:+!o.every(e=>e.verdict.ok)}}async function NK(e){(e.length>1||e[0]===``||e[0]?.startsWith(`--`))&&(t.stderr.write(`doctor: expected at most one config file
225
+ `));return d}finally{r.registry.dispose()}}function vK(e){return e.map(e=>`warning: ${e}\n`).join(``)}function yK(e,t=!1){switch(e.kind){case`clean`:return{stdout:`✓ ${e.layers.join(` < `)||`bundled default (no config file found)`}: config OK${e.warnings.length>0?` (${e.warnings.length} warning${e.warnings.length===1?``:`s`})`:``}\n`+(t?`${e.rendered}\n`:``),stderr:vK(e.warnings),code:0};case`fatal`:return{stdout:``,stderr:vK(e.warnings)+`✗ ${e.layers.join(` < `)||`<default>`}\n${e.message}\n`,code:1};case`unreadable`:return{stdout:``,stderr:`check: cannot read ${e.path}: ${e.message}\n`,code:2}}}const bK=`--render`,xK=`Usage: cc-candybar check [${bK}] [config-file]\n`;function SK(e){let t=e.filter(e=>e.startsWith(`--`)),n=e.filter(e=>!e.startsWith(`--`)),r=t.filter(e=>e!==bK);return r.length>0?{kind:`usage`,message:`check: unknown option ${r.join(` `)}\n${xK}`}:n.length>1||n[0]===``?{kind:`usage`,message:`check: expected at most one non-empty path\n${xK}`}:{kind:`run`,target:n[0],render:t.includes(bK)}}async function CK(e){let n=SK(e),r=n.kind===`usage`?{stdout:``,stderr:n.message,code:2}:yK(await mK(n.target??uK(t.env,t.cwd())),n.render);t.stdout.write(r.stdout),t.stderr.write(r.stderr),t.exit(r.code)}const wK=`${Gd}${Wd}`;function TK(e){return`${wK}⚠ cc-candybar: ${EK(e)}\n`}function EK(e){switch(e.cause){case`version_mismatch`:{let t=e.daemonV===0?`unknown`:`v${e.daemonV}`;return`protocol mismatch (client v${e.clientV} ≠ daemon ${t})`}case`bad_request`:return`daemon rejected request: ${Ud(e.message,60)}`;case`render_failed`:return`render failed: ${Ud(e.message,60)}`;case`malformed_response`:return`malformed daemon response: ${Ud(e.message,60)}`}}function DK(e){switch(e.kind){case`ok`:return{output:e.value,kick:!1,debug:null};case`transient`:return{output:`
226
+ `,kick:!0,debug:`daemon unavailable (transient: ${e.cause}: ${e.message}) — kicking daemon`};case`permanent`:return{output:TK(e),kick:!1,debug:`daemon refused request (permanent: ${e.cause}) — not kicking`}}}function OK(e,t){if(e!==void 0&&/^\+?\d+$/.test(e)){let t=Number(e);if(t>0&&t<=4294967295)return t}if(t&&t>0)return t}const kK=[`SSH_CONNECTION`,`SSH_CLIENT`,`SSH_TTY`];function AK(e,t,n){return{termCols:OK(e.COLUMNS,n.columns),termRows:OK(e.LINES,n.rows),ssh:kK.some(t=>(e[t]??``)!==``),tmux:wD(e),configEnv:uK(e,t),claudeConfigDir:ti(e,t),mementoEnv:tt(e,t)}}const jK=` (fix: click the settings menu (${Gn} by default) › 🧰 tools › 🩺 doctor, then [fix] on the bar)`;function MK({check:e,verdict:t}){return t.ok?`✓ ${e.label}\n`:`✗ ${e.label} — ${t.reason}${t.fix===void 0?``:jK}\n`+(t.more??[]).map(e=>` ${e}\n`).join(``)}function NK(e){let t={sessionState:new mV},n=sV(e.projectDir,e.cwd,e.configFile??void 0,t),r=n.state??cV(e.cwd,e.projectDir,t);return r.registry.dispose(),{layers:n.layers,error:n.error,warning:n.warning,unused:r.unused,config:r.config}}async function PK(e,t,n,r,i=void 0){let a;try{a={...tU(e,{tmux:wD(n),claudeConfigDir:ti(n,r)},{projectDir:r,cwd:r,configFile:dP(r,i)??uK(n,r)??null},()=>null),urlHandler:await _U(t)}}catch(e){return{stdout:``,stderr:`doctor: ${e instanceof Error?e.message:String(e)}\n`,code:2}}let o=ND(a);return{stdout:o.map(MK).join(``),stderr:``,code:+!o.every(e=>e.verdict.ok)}}async function FK(e){(e.length>1||e[0]===``||e[0]?.startsWith(`--`))&&(t.stderr.write(`doctor: expected at most one config file
227
227
  Usage: cc-candybar doctor [config-file]
228
- `),t.exit(2));let n=t.cwd(),r=await MK(qH(jK),yU(),t.env,n,e[0]);t.stdout.write(r.stdout),t.stderr.write(r.stderr),t.exit(r.code)}const PK=e=>e.some(e=>t.argv.includes(e));function FK(){console.log(xD)}async function IK(){try{PK(yD.help)&&(FK(),t.exit(0)),PK(yD.version)&&(console.log(`cc-candybar ${wt}`),t.exit(0));let e=t.argv[2];if(e===`install`&&(await Hi(t.argv.slice(3)),t.exit(0)),e===`install-url-handler`&&(Li(),t.exit(0)),e===`url-handle`){await zi(t.argv[3]);return}if(e===`daemon`){DG();return}if(e===`daemon-stats`&&(await nU(t.argv.slice(3)),t.exit(0)),e===`check`||e===`lint`){await xK(t.argv.slice(3));return}if(e===`schema`){oK();return}if(e===`doctor`){await NK(t.argv.slice(3));return}QW(e)&&(await ZG(e,t.argv.slice(3)),t.exit(0)),t.stdin.isTTY===!0&&(console.error(`Error: This tool requires input from Claude Code
228
+ `),t.exit(2));let n=t.cwd(),r=await PK(YH(NK),xU(),t.env,n,e[0]);t.stdout.write(r.stdout),t.stderr.write(r.stderr),t.exit(r.code)}const IK=e=>e.some(e=>t.argv.includes(e));function LK(){console.log(xD)}async function RK(){try{IK(yD.help)&&(LK(),t.exit(0)),IK(yD.version)&&(console.log(`cc-candybar ${wt}`),t.exit(0));let e=t.argv[2];if(e===`install`&&(await Hi(t.argv.slice(3)),t.exit(0)),e===`install-url-handler`&&(Li(),t.exit(0)),e===`url-handle`){await zi(t.argv[3]);return}if(e===`daemon`){kG();return}if(e===`daemon-stats`&&(await iU(t.argv.slice(3)),t.exit(0)),e===`check`||e===`lint`){await CK(t.argv.slice(3));return}if(e===`schema`){cK();return}if(e===`doctor`){await FK(t.argv.slice(3));return}eG(e)&&(await $G(e,t.argv.slice(3)),t.exit(0)),t.stdin.isTTY===!0&&(console.error(`Error: This tool requires input from Claude Code
229
229
 
230
230
  cc-candybar is designed to be used as a Claude Code statusLine command.
231
231
  It reads hook data from stdin and outputs formatted statusline.
@@ -241,4 +241,4 @@ Add to ~/.claude/settings.json:
241
241
  Run with --help for more options.
242
242
 
243
243
  To test output manually:
244
- echo '{"session_id":"test-session","workspace":{"project_dir":"/path/to/project"},"model":{"id":"claude-sonnet-4-5","display_name":"Claude"}}' | cc-candybar`),t.exit(1)),D(`Working directory: ${t.cwd()}`),D(`Process args:`,t.argv);let r=await n(t.stdin);D(`Received hook data:`,JSON.stringify(r,null,2)),r||(console.error(`Error: No input data received from stdin`),FK(),t.exit(1));let i=TK(await Ot(r,t.argv,t.cwd(),OK(t.env,t.cwd(),t.stderr)));i.debug!==null&&D(i.debug),i.kick&&Xt(),t.stdout.write(i.output),t.exit(0)}catch(e){let n=e instanceof Error?e.message:String(e);console.error(`Error generating statusline:`,n),t.exit(1)}}IK();export{};
244
+ echo '{"session_id":"test-session","workspace":{"project_dir":"/path/to/project"},"model":{"id":"claude-sonnet-4-5","display_name":"Claude"}}' | cc-candybar`),t.exit(1)),D(`Working directory: ${t.cwd()}`),D(`Process args:`,t.argv);let r=await n(t.stdin);D(`Received hook data:`,JSON.stringify(r,null,2)),r||(console.error(`Error: No input data received from stdin`),LK(),t.exit(1));let i=DK(await Ot(r,t.argv,t.cwd(),AK(t.env,t.cwd(),t.stderr)));i.debug!==null&&D(i.debug),i.kick&&Xt(),t.stdout.write(i.output),t.exit(0)}catch(e){let n=e instanceof Error?e.message:String(e);console.error(`Error generating statusline:`,n),t.exit(1)}}RK();export{};