@promptctl/cc-candybar 1.169.1 → 1.170.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.
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{URL as n,URLSearchParams as r,fileURLToPath as i}from"node:url";import{json as a}from"node:stream/consumers";import o,{basename as s,dirname as c,isAbsolute as l,join as u,sep as d}from"node:path";import f,{closeSync as p,constants as m,existsSync as h,fstatSync as g,linkSync as _,openSync as v,readFileSync as y,readSync as b,rmSync as ee,statSync as x,writeFileSync as S}from"node:fs";import te,{createHash as C,createHmac as ne,randomBytes as re,randomUUID as ie,timingSafeEqual as ae}from"node:crypto";import w,{homedir as oe}from"node:os";import{spawn as se,spawnSync as T}from"node:child_process";import{inspect as ce,parseArgs as le,types as ue}from"node:util";import de from"node:net";import fe from"node:v8";import{open as pe,readFile as me,readdir as he,stat as ge}from"node:fs/promises";import{clearInterval as _e,setImmediate as ve,setInterval as ye}from"node:timers";import{get as be}from"node:https";import{setTimeout as xe}from"node:timers/promises";import{WriteStream as Se}from"node:tty";import{createInterface as Ce}from"node:readline";var we=Object.create,Te=Object.defineProperty,Ee=Object.getOwnPropertyDescriptor,De=Object.getOwnPropertyNames,Oe=Object.getPrototypeOf,ke=Object.prototype.hasOwnProperty,Ae=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),je=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=De(t),a=0,o=i.length,s;a<o;a++)s=i[a],!ke.call(e,s)&&s!==n&&Te(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=Ee(t,s))||r.enumerable});return e},Me=(e,t,n)=>(n=e==null?{}:we(Oe(e)),je(t||!e||!e.__esModule?Te(n,`default`,{value:e,enumerable:!0}):n,e));const Ne=()=>!!process.env.CC_CANDYBAR_DEBUG;function Pe(e){return Ne()?`[DEBUG] ${e()}\n`:``}function E(e,...t){Ne()&&console.error(`[DEBUG] ${e}`,...t)}function Fe(e){let t=null;return([n,r])=>{r!==t&&(t=r,e(n,r))}}const Ie=(e,t)=>E(t),Le=/^[A-Za-z0-9_./,:@%+-][A-Za-z0-9_./,:@%+=-]*$/;function Re(e){return`'${e.replaceAll(`'`,`'\\''`)}'`}function ze(e){return Le.test(e)?e:Re(e)}function Be(e){return`${e.dir===void 0?``:`cd ${ze(e.dir)} && `}${e.env.map(([e,t])=>`${e}=${ze(t)} `).join(``)}${[e.program,...e.args].map(ze).join(` `)}`}const Ve=`cc-extra`;function He(e){return o.join(o.dirname(e),Ve,`src`,`bun-attach.js`)}function Ue(e){return o.join(o.dirname(e),`bun-graph.js`)}const We=`attach-preload.cjs`;function Ge(e){return o.join(o.dirname(e),We)}function Ke(e,t){return Be({...t,env:[...t.env,[`BUN_OPTIONS`,`--preload ${e.replace(/[\\\s]/g,`\\$&`)}`]]})}const qe=e=>!e.startsWith(`.`)&&!e.endsWith(`~`);function Je(e,t){return t.isSymbolicLink()?Buffer.from(f.readlinkSync(e)):f.readFileSync(e)}function Ye(e,t,n=qe){return f.readdirSync(t).filter(n).sort().flatMap(n=>{let r=o.join(t,n),i=f.lstatSync(r,{throwIfNoEntry:!1});return i===void 0?[]:i.isDirectory()?Ye(e,r):[[o.relative(e,r).split(o.sep).join(`/`),Je(r,i)]]})}function Xe(e){let t=te.createHash(`sha256`);for(let[n,r]of e)t.update(n).update(`\0`).update(r).update(`\0`);return t.digest(`hex`)}function Ze(e){return Xe(Ye(e,e))}const Qe=[`Cargo.toml`,`Cargo.lock`,`src`];function $e(e){return Xe(Ye(e,e,e=>Qe.includes(e)))}const et=e=>e.slice(0,7),tt=`1.169.1`;function nt(e){let t=o.dirname(o.dirname(e));return f.existsSync(o.join(t,`src`))?t:null}function rt(){let e=it();if(e===null)throw Error("this bundle carries no source digest (build via `pnpm build`, which stamps it)");return{version:tt,digest:e}}function it(){return`773b198113960dae71a863b83cd4de9d4111caa8d0f5889c11b33cac2f687f4c`}function at(e){let t=JSON.parse(f.readFileSync(o.join(e,`package.json`),`utf8`)),n=typeof t==`object`&&t?t.version:void 0;if(typeof n!=`string`)throw Error(`${o.join(e,`package.json`)} has no version string`);return n}function ot(e,t){try{let n=nt(i(e));if(n===null)return{kind:`not-source-checkout`};let r=t(),a=Ze(o.join(n,`src`));return a===r.digest?{kind:`current`,root:n,stamp:r}:{kind:`stale`,root:n,source:{version:at(n),digest:a},running:r}}catch(e){return{kind:`unchecked`,reason:e.message}}}function st(e,t){return ue.isNativeError(e)?e.code===`ENOENT`&&t!==void 0&&!h(t)?`working directory does not exist: ${t}`:e.message:String(e)}const ct={"click.pbcopy":1e3,"click.open":1e3,"doctor.tmux":1e3,"doctor.font":1e3,"doctor.process":1e3,"claude-input.type":1e3},lt=new Map;function ut(e){let t=ct[e];if(t===void 0)return{allowed:!0};let n=lt.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 dt(e){lt.set(e,Date.now())}function ft(e){return e.env??process.env}function pt(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 D=null;function mt(e){D=e}let ht=()=>Ct().forEach(e=>process.emitWarning(e.message));function gt(e){ht=e}const _t=`\$1 == "+" { live[\$2] = 1; next } \$1 == "-" { delete live[\$2]; next } END { for (g in live) groups = groups " -" g; if (groups != "") system("kill -TERM" groups " 2>/dev/null; sleep ${250/1e3}; kill -KILL" groups " 2>/dev/null") }`,vt=new Set;let yt=null,bt=null;function xt(e){e!==bt&&(bt=e,ht(e))}function St(e,t){yt?.process===e&&(yt=null,xt(t))}function Ct(){return bt===null?[]:[{kind:`lifeline`,message:`programs launched now would outlive their launcher if it died: its launch lifeline ${bt}, and the next launch starts another`}]}function wt(){D?.onStart(`lifeline`);let e=Date.now(),t;try{t=se(`awk`,[_t],{stdio:[`pipe`,`ignore`,`ignore`],detached:!0})}catch(t){return D?.onEnd(`lifeline`,Date.now()-e),xt(`did not start: ${st(t,void 0)}`),null}D?.onEnd(`lifeline`,Date.now()-e);let n=t.stdin;t.once(`spawn`,()=>{yt?.process===t&&xt(null)}),t.once(`error`,e=>St(t,`failed: ${e.message}`)),t.once(`exit`,(e,n)=>St(t,`exited ${n??e}`)),n.on(`error`,e=>St(t,`pipe failed: ${e.message}`)),t.unref(),n.unref();for(let e of vt)n.write(`+ ${e}\n`);return{process:t,pipe:n}}function Tt(e){vt.add(e),yt??=wt(),yt?.pipe.write(`+ ${e}\n`)}function Et(e){vt.delete(e),yt?.pipe.write(`- ${e}\n`)}function Dt(e,t){try{process.kill(-e,t)}catch(e){if(e.code!==`ESRCH`)throw e}}async function Ot(e){if(e.signal?.aborted)return{ok:!1,reason:`aborted`,stdout:``,stderr:``,exitCode:null,signal:null};let t=ut(e.category);if(!t.allowed)return pt(e.category,t.minIntervalMs,t.sinceLastMs);dt(e.category);let n=Date.now();return D?.onStart(e.category),new Promise(t=>{let r;try{r=se(e.bin,e.args??[],{cwd:e.cwd,env:ft(e),stdio:[`pipe`,`pipe`,`pipe`],detached:!0})}catch(r){D?.onEnd(e.category,Date.now()-n),t({ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:st(r,e.cwd)});return}let i=r.pid;i!==void 0&&Tt(i);let a=``,o=``,s=!1,c=null,l=null,u=null,d=()=>h(`aborted`),f=t=>{s||(s=!0,c&&clearTimeout(c),l&&clearTimeout(l),e.signal?.removeEventListener(`abort`,d),i!==void 0&&Et(i),D?.onEnd(e.category,Date.now()-n),t())},p=e=>f(()=>t(e)),m=(e,t)=>{try{Dt(e,t)}catch(e){p({ok:!1,reason:`signal-refused`,stdout:a,stderr:o,exitCode:null,signal:null,error:e instanceof Error?e.message:String(e)})}},h=t=>{u=t,c&&clearTimeout(c),e.signal?.removeEventListener(`abort`,d);let n=r.pid;n!==void 0&&(l=setTimeout(()=>m(n,`SIGKILL`),250),m(n,`SIGTERM`))};r.stdout?.on(`data`,e=>{a+=e.toString(`utf8`)}),r.stderr?.on(`data`,e=>{o+=e.toString(`utf8`)}),r.on(`error`,t=>{p({ok:!1,reason:`spawn-error`,stdout:a,stderr:o,exitCode:null,signal:null,error:st(t,e.cwd)})}),r.on(`close`,(e,t)=>{if(u!==null){p({ok:!1,reason:u,stdout:a,stderr:o,exitCode:e,signal:t});return}if(e===0){p({ok:!0,stdout:a,stderr:o,exitCode:e});return}p({ok:!1,reason:t?`signal`:`non-zero`,stdout:a,stderr:o,exitCode:e,signal:t})}),e.timeoutMs&&e.timeoutMs>0&&(c=setTimeout(()=>h(`timeout`),e.timeoutMs)),e.signal?.addEventListener(`abort`,d,{once:!0}),e.stdinInput!==void 0&&r.stdin?r.stdin.end(e.stdinInput):r.stdin&&r.stdin.end()})}function kt(e){let t=ut(e.category);if(!t.allowed)return pt(e.category,t.minIntervalMs,t.sinceLastMs);dt(e.category);let n=Date.now();D?.onStart(e.category);let r=[`pipe`,`pipe`,`pipe`];try{let t=T(e.bin,e.args??[],{cwd:e.cwd,env:ft(e),input:e.stdinInput,timeout:e.timeoutMs&&e.timeoutMs>0?e.timeoutMs:void 0,stdio:r,encoding:`utf8`});D?.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:st(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 D?.onEnd(e.category,Date.now()-n),{ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:st(t,e.cwd)}}}function At(e){let t=ut(e.category);if(!t.allowed)return pt(e.category,t.minIntervalMs,t.sinceLastMs);dt(e.category);let n=Date.now();D?.onStart(e.category);let r=jt(e);return D?.onEnd(e.category,Date.now()-n),r}function jt(e){let t;try{t=se(e.bin,e.args??[],{cwd:e.cwd,env:ft(e),detached:!0,stdio:`ignore`})}catch(t){return{ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:st(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})}const Mt=e=>e.kind===`exit`?`exit ${e.code}`:`timeout`;function Nt(e,t){dt(e.category);let n=Date.now();D?.onStart(e.category);let r;try{r=se(`/bin/sh`,[`-c`,`out=$1 err=$2 status=$3; shift 3; read go || exit 0; "$@" >"$out" 2>"$err" </dev/null; echo "exit $?" >"$status.$$" && ln "$status.$$" "$status"; rm -f "$status.$$"`,`sh`,t.stdout,t.stderr,t.status,e.bin,...e.args??[]],{cwd:e.cwd,env:ft(e),detached:!0,stdio:[`pipe`,`ignore`,`ignore`]})}catch(t){return D?.onEnd(e.category,Date.now()-n),{ok:!1,error:st(t,e.cwd)}}D?.onEnd(e.category,Date.now()-n),r.once(`error`,()=>{});let i=r.pid,a=r.stdin;return a.on(`error`,()=>{}),i===void 0?(a.destroy(),{ok:!1,error:`spawn(/bin/sh): no pid (shell not found or unexecutable)`}):(r.unref(),a.unref(),{ok:!0,pid:i,release:()=>a.end(`go
2
+ import{createRequire as e}from"node:module";import t from"node:process";import{URL as n,URLSearchParams as r,fileURLToPath as i}from"node:url";import{json as a}from"node:stream/consumers";import o,{basename as s,dirname as c,isAbsolute as l,join as u,sep as d}from"node:path";import f,{closeSync as p,constants as m,existsSync as h,fstatSync as g,linkSync as _,openSync as v,readFileSync as y,readSync as b,rmSync as ee,statSync as x,writeFileSync as S}from"node:fs";import te,{createHash as C,createHmac as ne,randomBytes as re,randomUUID as ie,timingSafeEqual as ae}from"node:crypto";import w,{homedir as oe}from"node:os";import{spawn as se,spawnSync as T}from"node:child_process";import{inspect as ce,parseArgs as le,types as ue}from"node:util";import de from"node:net";import fe from"node:v8";import{open as pe,readFile as me,readdir as he,stat as ge}from"node:fs/promises";import{clearInterval as _e,setImmediate as ve,setInterval as ye}from"node:timers";import{get as be}from"node:https";import{setTimeout as xe}from"node:timers/promises";import{WriteStream as Se}from"node:tty";import{createInterface as Ce}from"node:readline";var we=Object.create,Te=Object.defineProperty,Ee=Object.getOwnPropertyDescriptor,De=Object.getOwnPropertyNames,Oe=Object.getPrototypeOf,ke=Object.prototype.hasOwnProperty,Ae=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),je=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=De(t),a=0,o=i.length,s;a<o;a++)s=i[a],!ke.call(e,s)&&s!==n&&Te(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=Ee(t,s))||r.enumerable});return e},Me=(e,t,n)=>(n=e==null?{}:we(Oe(e)),je(t||!e||!e.__esModule?Te(n,`default`,{value:e,enumerable:!0}):n,e));const Ne=()=>!!process.env.CC_CANDYBAR_DEBUG;function Pe(e){return Ne()?`[DEBUG] ${e()}\n`:``}function E(e,...t){Ne()&&console.error(`[DEBUG] ${e}`,...t)}function Fe(e){let t=null;return([n,r])=>{r!==t&&(t=r,e(n,r))}}const Ie=(e,t)=>E(t),Le=/^[A-Za-z0-9_./,:@%+-][A-Za-z0-9_./,:@%+=-]*$/;function Re(e){return`'${e.replaceAll(`'`,`'\\''`)}'`}function ze(e){return Le.test(e)?e:Re(e)}function Be(e){return`${e.dir===void 0?``:`cd ${ze(e.dir)} && `}${e.env.map(([e,t])=>`${e}=${ze(t)} `).join(``)}${[e.program,...e.args].map(ze).join(` `)}`}const Ve=`cc-extra`;function He(e){return o.join(o.dirname(e),Ve,`src`,`bun-attach.js`)}function Ue(e){return o.join(o.dirname(e),`bun-graph.js`)}const We=`attach-preload.cjs`;function Ge(e){return o.join(o.dirname(e),We)}function Ke(e,t){return Be({...t,env:[...t.env,[`BUN_OPTIONS`,`--preload ${e.replace(/[\\\s]/g,`\\$&`)}`]]})}const qe=e=>!e.startsWith(`.`)&&!e.endsWith(`~`);function Je(e,t){return t.isSymbolicLink()?Buffer.from(f.readlinkSync(e)):f.readFileSync(e)}function Ye(e,t,n=qe){return f.readdirSync(t).filter(n).sort().flatMap(n=>{let r=o.join(t,n),i=f.lstatSync(r,{throwIfNoEntry:!1});return i===void 0?[]:i.isDirectory()?Ye(e,r):[[o.relative(e,r).split(o.sep).join(`/`),Je(r,i)]]})}function Xe(e){let t=te.createHash(`sha256`);for(let[n,r]of e)t.update(n).update(`\0`).update(r).update(`\0`);return t.digest(`hex`)}function Ze(e){return Xe(Ye(e,e))}const Qe=[`Cargo.toml`,`Cargo.lock`,`src`];function $e(e){return Xe(Ye(e,e,e=>Qe.includes(e)))}const et=e=>e.slice(0,7),tt=`1.170.0`;function nt(e){let t=o.dirname(o.dirname(e));return f.existsSync(o.join(t,`src`))?t:null}function rt(){let e=it();if(e===null)throw Error("this bundle carries no source digest (build via `pnpm build`, which stamps it)");return{version:tt,digest:e}}function it(){return`16fe0e86cd8d47058b052c2c45900e151fcafe597203e7afa019928013fedb4b`}function at(e){let t=JSON.parse(f.readFileSync(o.join(e,`package.json`),`utf8`)),n=typeof t==`object`&&t?t.version:void 0;if(typeof n!=`string`)throw Error(`${o.join(e,`package.json`)} has no version string`);return n}function ot(e,t){try{let n=nt(i(e));if(n===null)return{kind:`not-source-checkout`};let r=t(),a=Ze(o.join(n,`src`));return a===r.digest?{kind:`current`,root:n,stamp:r}:{kind:`stale`,root:n,source:{version:at(n),digest:a},running:r}}catch(e){return{kind:`unchecked`,reason:e.message}}}function st(e,t){return ue.isNativeError(e)?e.code===`ENOENT`&&t!==void 0&&!h(t)?`working directory does not exist: ${t}`:e.message:String(e)}const ct={"click.pbcopy":1e3,"click.open":1e3,"doctor.tmux":1e3,"doctor.font":1e3,"doctor.process":1e3,"claude-input.type":1e3},lt=new Map;function ut(e){let t=ct[e];if(t===void 0)return{allowed:!0};let n=lt.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 dt(e){lt.set(e,Date.now())}function ft(e){return e.env??process.env}function pt(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 D=null;function mt(e){D=e}let ht=()=>Ct().forEach(e=>process.emitWarning(e.message));function gt(e){ht=e}const _t=`\$1 == "+" { live[\$2] = 1; next } \$1 == "-" { delete live[\$2]; next } END { for (g in live) groups = groups " -" g; if (groups != "") system("kill -TERM" groups " 2>/dev/null; sleep ${250/1e3}; kill -KILL" groups " 2>/dev/null") }`,vt=new Set;let yt=null,bt=null;function xt(e){e!==bt&&(bt=e,ht(e))}function St(e,t){yt?.process===e&&(yt=null,xt(t))}function Ct(){return bt===null?[]:[{kind:`lifeline`,message:`programs launched now would outlive their launcher if it died: its launch lifeline ${bt}, and the next launch starts another`}]}function wt(){D?.onStart(`lifeline`);let e=Date.now(),t;try{t=se(`awk`,[_t],{stdio:[`pipe`,`ignore`,`ignore`],detached:!0})}catch(t){return D?.onEnd(`lifeline`,Date.now()-e),xt(`did not start: ${st(t,void 0)}`),null}D?.onEnd(`lifeline`,Date.now()-e);let n=t.stdin;t.once(`spawn`,()=>{yt?.process===t&&xt(null)}),t.once(`error`,e=>St(t,`failed: ${e.message}`)),t.once(`exit`,(e,n)=>St(t,`exited ${n??e}`)),n.on(`error`,e=>St(t,`pipe failed: ${e.message}`)),t.unref(),n.unref();for(let e of vt)n.write(`+ ${e}\n`);return{process:t,pipe:n}}function Tt(e){vt.add(e),yt??=wt(),yt?.pipe.write(`+ ${e}\n`)}function Et(e){vt.delete(e),yt?.pipe.write(`- ${e}\n`)}function Dt(e,t){try{process.kill(-e,t)}catch(e){if(e.code!==`ESRCH`)throw e}}async function Ot(e){if(e.signal?.aborted)return{ok:!1,reason:`aborted`,stdout:``,stderr:``,exitCode:null,signal:null};let t=ut(e.category);if(!t.allowed)return pt(e.category,t.minIntervalMs,t.sinceLastMs);dt(e.category);let n=Date.now();return D?.onStart(e.category),new Promise(t=>{let r;try{r=se(e.bin,e.args??[],{cwd:e.cwd,env:ft(e),stdio:[`pipe`,`pipe`,`pipe`],detached:!0})}catch(r){D?.onEnd(e.category,Date.now()-n),t({ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:st(r,e.cwd)});return}let i=r.pid;i!==void 0&&Tt(i);let a=``,o=``,s=!1,c=null,l=null,u=null,d=()=>h(`aborted`),f=t=>{s||(s=!0,c&&clearTimeout(c),l&&clearTimeout(l),e.signal?.removeEventListener(`abort`,d),i!==void 0&&Et(i),D?.onEnd(e.category,Date.now()-n),t())},p=e=>f(()=>t(e)),m=(e,t)=>{try{Dt(e,t)}catch(e){p({ok:!1,reason:`signal-refused`,stdout:a,stderr:o,exitCode:null,signal:null,error:e instanceof Error?e.message:String(e)})}},h=t=>{u=t,c&&clearTimeout(c),e.signal?.removeEventListener(`abort`,d);let n=r.pid;n!==void 0&&(l=setTimeout(()=>m(n,`SIGKILL`),250),m(n,`SIGTERM`))};r.stdout?.on(`data`,e=>{a+=e.toString(`utf8`)}),r.stderr?.on(`data`,e=>{o+=e.toString(`utf8`)}),r.on(`error`,t=>{p({ok:!1,reason:`spawn-error`,stdout:a,stderr:o,exitCode:null,signal:null,error:st(t,e.cwd)})}),r.on(`close`,(e,t)=>{if(u!==null){p({ok:!1,reason:u,stdout:a,stderr:o,exitCode:e,signal:t});return}if(e===0){p({ok:!0,stdout:a,stderr:o,exitCode:e});return}p({ok:!1,reason:t?`signal`:`non-zero`,stdout:a,stderr:o,exitCode:e,signal:t})}),e.timeoutMs&&e.timeoutMs>0&&(c=setTimeout(()=>h(`timeout`),e.timeoutMs)),e.signal?.addEventListener(`abort`,d,{once:!0}),e.stdinInput!==void 0&&r.stdin?r.stdin.end(e.stdinInput):r.stdin&&r.stdin.end()})}function kt(e){let t=ut(e.category);if(!t.allowed)return pt(e.category,t.minIntervalMs,t.sinceLastMs);dt(e.category);let n=Date.now();D?.onStart(e.category);let r=[`pipe`,`pipe`,`pipe`];try{let t=T(e.bin,e.args??[],{cwd:e.cwd,env:ft(e),input:e.stdinInput,timeout:e.timeoutMs&&e.timeoutMs>0?e.timeoutMs:void 0,stdio:r,encoding:`utf8`});D?.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:st(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 D?.onEnd(e.category,Date.now()-n),{ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:st(t,e.cwd)}}}function At(e){let t=ut(e.category);if(!t.allowed)return pt(e.category,t.minIntervalMs,t.sinceLastMs);dt(e.category);let n=Date.now();D?.onStart(e.category);let r=jt(e);return D?.onEnd(e.category,Date.now()-n),r}function jt(e){let t;try{t=se(e.bin,e.args??[],{cwd:e.cwd,env:ft(e),detached:!0,stdio:`ignore`})}catch(t){return{ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:st(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})}const Mt=e=>e.kind===`exit`?`exit ${e.code}`:`timeout`;function Nt(e,t){dt(e.category);let n=Date.now();D?.onStart(e.category);let r;try{r=se(`/bin/sh`,[`-c`,`out=$1 err=$2 status=$3; shift 3; read go || exit 0; "$@" >"$out" 2>"$err" </dev/null; echo "exit $?" >"$status.$$" && ln "$status.$$" "$status"; rm -f "$status.$$"`,`sh`,t.stdout,t.stderr,t.status,e.bin,...e.args??[]],{cwd:e.cwd,env:ft(e),detached:!0,stdio:[`pipe`,`ignore`,`ignore`]})}catch(t){return D?.onEnd(e.category,Date.now()-n),{ok:!1,error:st(t,e.cwd)}}D?.onEnd(e.category,Date.now()-n),r.once(`error`,()=>{});let i=r.pid,a=r.stdin;return a.on(`error`,()=>{}),i===void 0?(a.destroy(),{ok:!1,error:`spawn(/bin/sh): no pid (shell not found or unexecutable)`}):(r.unref(),a.unref(),{ok:!0,pid:i,release:()=>a.end(`go
3
3
  `),withdraw:()=>a.end()})}function Pt(e){let t;try{t=y(e,`utf8`).trim()}catch(e){if(e.code===`ENOENT`)return null;throw e}let n=/^exit (\d+)$/.exec(t);if(n)return{kind:`exit`,code:Number(n[1])};if(t===`timeout`)return{kind:`timeout`};throw Error(`${e}: not a job verdict: ${JSON.stringify(t)}`)}function Ft(e){try{return process.kill(-e,0),!0}catch(e){let t=e.code;if(t===`ESRCH`||t===`EPERM`)return!1;throw e}}function It(e,t,n){let r=`${t}.${process.pid}`;try{S(r,`${Mt(n)}\n`)}catch(e){if(e.code===`ENOENT`)return!1;throw e}let i=!0;try{_(r,t)}catch(e){if(e.code!==`EEXIST`)throw e;i=!1}finally{ee(r,{force:!0})}return Dt(e,`SIGTERM`),setTimeout(()=>Dt(e,`SIGKILL`),250).unref(),i}function Lt(e,t,n){let r=Rt(e);f.mkdirSync(o.dirname(r),{recursive:!0});let i=`${r}.tmp`,a=n??f.statSync(r,{throwIfNoEntry:!1})?.mode;try{f.writeFileSync(i,t,a===void 0?{}:{mode:a}),f.renameSync(i,r)}catch(e){throw f.rmSync(i,{force:!0}),e}}function Rt(e){return zt(e).at(-1)}function zt(e){let{hops:t,stopped:n}=Bt(e);if(n!==null)throw n;return t}function Bt(e){let t=[e];try{for(let e=0;e<Ht;e++){let e=Vt(t[t.length-1]);if(e===null)return{hops:t,stopped:null};t.push(e)}return{hops:t,stopped:Error(`${e}: more than ${Ht} symbolic links`)}}catch(e){return{hops:t,stopped:e}}}function Vt(e){try{return f.lstatSync(e).isSymbolicLink()?o.resolve(f.realpathSync(o.dirname(e)),f.readlinkSync(e)):null}catch(e){let{code:t}=e;if(t===`ENOENT`||t===`ENOTDIR`)return null;throw e}}const Ht=40;function Ut(e,t){let n=e[t];return n&&n.length>0?n:void 0}function Wt(e=process.env){let t=Ut(e,`XDG_STATE_HOME`)??o.join(w.homedir(),`.local`,`state`);return o.join(t,`cc-candybar`)}function Gt(){let e=Ut(process.env,`XDG_CACHE_HOME`)??o.join(w.homedir(),`.cache`);return o.join(e,`cc-candybar`)}function Kt(){return Wt()}function O(){return process.env.CC_CANDYBAR_SOCKET||qt()}function qt(){let e=w.userInfo().uid;return o.join(`/tmp`,`cc-candybar-${e}`,`socket`)}function Jt(e){f.mkdirSync(e,{recursive:!0,mode:448});let t=f.lstatSync(e);if(t.isSymbolicLink())throw Error(`directory is a symlink: ${e}`);if(!t.isDirectory())throw Error(`not a directory: ${e}`);let n=w.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 Yt(e){Jt(o.dirname(e));for(let t of[e,Xt(e)])try{if(f.lstatSync(t).isSymbolicLink())throw Error(`path is a symlink: ${t}`)}catch(e){if(e.code!==`ENOENT`)throw e}}function Xt(e){return`${e}.lease`}function Zt(){return Xt(O())}function Qt(e=process.env){return o.join(Wt(e),`session-state.json`)}function k(){return o.join(Wt(),`settings-history.json`)}function $t(){let e=process.env.CC_CANDYBAR_DAEMON_REGISTRY_DIR;if(e)return e;let t=w.userInfo().uid;return o.join(`/tmp`,`cc-candybar-${t}`,`daemons`)}function en(){return o.join(Wt(),`spawn.lock`)}function tn(){return o.join(Wt(),`spawn.cooldown`)}function nn(){return o.join(Wt(),`spawn.backoff`)}function rn(){return o.join(Wt(),`watch-probe`)}function an(e=process.env){return o.join(Wt(e),`daemon.log`)}const on=[`TERM_PROGRAM`,`TERM_PROGRAM_VERSION`,`TERM`,`ITERM_PROFILE`,`XDG_CONFIG_HOME`];function sn(e){return Object.fromEntries(on.flatMap(t=>{let n=e[t]??``;return n===``?[]:[[t,n]]}))}const cn=[`native`,`node`,`frames`];function ln(e,t){return{kind:e,bundle:t,source:null}}const un=Object.keys({termCols:!0,termRows:!0,ssh:!0,tmux:!0,configEnv:!0,claudeConfigDir:!0,terminalEnv:!0,client:!0});function dn(e){let t=bn(e.termCols),n=bn(e.termRows),r=xn(e.ssh),i=vn(e.tmux),a=_n(e.configEnv),o=_n(e.claudeConfigDir),s=gn(e.terminalEnv),c=On(e.client);return{...t!==void 0&&{termCols:t},...n!==void 0&&{termRows:n},...r!==void 0&&{ssh:r},...i!==void 0&&{tmux:i},...a!==void 0&&{configEnv:a},...o!==void 0&&{claudeConfigDir:o},...s!==void 0&&{terminalEnv:s},...c!==void 0&&{client:c}}}function fn(e,t){return un.filter(n=>e[n]!==void 0&&t[n]===void 0).map(t=>({hint:t,sent:e[t]}))}function pn(e){return e.length===0?null:`Client hints refused: ${e.map(({hint:e,sent:t})=>`${e}=${JSON.stringify(t)}`).join(`, `)} — is the statusline client older than the daemon? Reinstall it (\`cc-candybar install\`, or \`just install-rust\` in a checkout).`}const mn={unknown:e=>`Unknown flags: ${e}`,"no-value":e=>`${e} names no file — the bar renders with no ${e}`,positional:e=>`Unexpected arguments: ${e}`};function hn(e){let t=Object.keys(mn).flatMap(t=>{let n=e.filter(e=>e.why===t).map(e=>e.arg);return n.length===0?[]:[mn[t](n.join(`, `))]});return t.length===0?null:t.join(`
4
4
  `)}function gn(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=e,n=on.filter(e=>t[e]!==void 0);return n.every(e=>typeof t[e]==`string`&&t[e]!==``)?Object.fromEntries(n.map(e=>[e,t[e]])):void 0}function _n(e){return typeof e==`string`&&o.isAbsolute(e)?e:void 0}function vn(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 yn=1e4;function bn(e){if(typeof e!=`number`||!Number.isFinite(e))return;let t=Math.floor(e);if(!(t<=0))return t>yn?yn:t}function xn(e){return typeof e==`boolean`?e:void 0}function Sn(e){return typeof e==`string`&&e!==``&&e.length<=64?e:null}var Cn=class extends Error{constructor(e){super(e),this.name=`ProtocolError`}};function wn(e){return Tn(JSON.stringify(e))}function Tn(e){let t=Buffer.from(e,`utf8`),n=Buffer.alloc(4);return n.writeUInt32BE(t.length,0),Buffer.concat([n,t])}function En(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 Cn(`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 Cn(e instanceof Error?e.message:String(e));e instanceof Error&&(n.cause=e),t(n);return}}}}function Dn(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-Date.now()),c=En(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(wn(t))})}function On(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let{kind:t,bundle:n,source:r}=e,i=_n(n);return cn.includes(t)&&i!==void 0&&(r===null||typeof r==`string`&&r!==``)?{kind:t,bundle:i,source:r}:void 0}async function A(e,t,n){let r=null;try{r=await Nn(O(),t.connectMs);let i=Date.now()+t.budgetMs,a=e(i),o=await Dn(r,{v:3,...a},i);return jn(a.kind,o,n)}catch(e){return Mn(e)}finally{r&&r.destroy()}}function kn(e,t){return typeof e==`string`?e:t}function An(e){return typeof e==`number`&&Number.isInteger(e)&&e>=0?e:0}function jn(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=kn(r.error,`(no error message)`);switch(r.code){case`VERSION_MISMATCH`:return{kind:`permanent`,cause:`version_mismatch`,clientV:3,daemonV:An(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};case`SWITCHED_OFF`:return{kind:`permanent`,cause:`switched_off`,message:i};default:return{kind:`permanent`,cause:`malformed_response`,message:`unknown error code: ${String(r.code)}`}}}function Mn(e){if(e instanceof Cn||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 Nn(e,t){return new Promise((n,r)=>{let i=de.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 Pn(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`switched_off`:case`malformed_response`:return`daemon error (${e.cause}): ${e.message}`}}const Fn={connectMs:50,budgetMs:150},In={connectMs:50,budgetMs:200};function Ln(e){let t=e.output;return typeof t==`string`?t:void 0}function Rn(e){return jn(`render`,e,Ln)}function zn(e,t,n,r){return A(i=>({kind:`render`,hookData:e,args:t,cwd:n,deadline:i,...r}),Fn,Ln)}function Bn(e,t){return A(()=>({kind:`pane-session`,socket:e,pane:t}),In,e=>`paneSession`in e?e.paneSession:void 0)}function Vn(e,t){return A(()=>({kind:`click`,verb:e,value:t,clientVersion:tt}),In,Ln)}let Hn=null;function Un(){if(Hn!==null){try{f.closeSync(Hn.fd)}catch{}Hn=null}}async function Wn(e){let t=await f.promises.stat(e).catch(()=>null);if(Hn!==null&&Hn.path===e&&t!==null&&Hn.id===Gn(t))return{held:Hn,size:t.size};Un(),await f.promises.mkdir(o.dirname(e),{recursive:!0});let n=await new Promise((t,n)=>f.open(e,`a`,(e,r)=>e===null?t(r):n(e))),r=await new Promise((e,t)=>f.fstat(n,(n,r)=>n===null?e(r):t(n)));return Hn={path:e,fd:n,id:Gn(r)},{held:Hn,size:r.size}}function Gn(e){return`${e.dev}:${e.ino}`}function Kn(e,t){return new Promise((n,r)=>f.write(e,t,(e,t)=>e===null?n(t):r(e)))}async function qn(e){for(let t=2;t>=1;t--)await f.promises.rename(`${e}.${t}`,`${e}.${t+1}`).catch(()=>{});await f.promises.rename(e,`${e}.1`).catch(()=>{})}let Jn=[],Yn=0,Xn=0,Zn=0,Qn=null,$n=!1;const er=[];let tr=!1,nr=!1;function rr(e,t){return`${new Date().toISOString()} [${e}] ${t}\n`}function j(e,t){let n=rr(e,t);if(nr||(nr=!0,process.on(`exit`,()=>{tr=!0,ur(!0,cr)})),Jn.push(n),Yn+=Buffer.byteLength(n),Yn>4194304){let e=0;for(;Yn>4194304/2&&e<Jn.length-1;){let t=Buffer.byteLength(Jn[e]);Yn-=t,Zn+=t,e++}Jn.splice(0,e),Xn+=e}tr?ur(!0,cr):$n||ar()}function ir(){ur(!1,lr)}async function ar(){$n=!0;try{for(;Jn.length>0;){let e=or();Qn={bytes:Buffer.from(e),state:{kind:`taken`}};try{await sr(an(),Qn)}catch(t){Un(),Qn.state.kind!==`landed`&&fr(e,t)}finally{Qn=null}}}finally{$n=!1;for(let e of er.splice(0))e()}}function or(){let e=(Xn===0?``:rr(`warn`,`log: ${Xn} earlier line(s) dropped (${Zn} bytes): more than 4194304 bytes were waiting for the disk`))+Jn.join(``);return Jn=[],Yn=0,Xn=0,Zn=0,e}async function sr(e,t){let{held:n,size:r}=await Wn(e);if(t.state.kind===`landed`)return;let{bytes:i}=t,a=r+i.length;t.state={kind:`issued`,fd:n.fd,endsAt:a};for(let e=0;e<i.length;){let t=await Kn(n.fd,i.subarray(e));if(t===0)throw Error(`the disk took 0 bytes of a write`);e+=t}if(t.state={kind:`landed`},a>=5242880){Un();let e=await f.promises.stat(n.path).catch(()=>null);e!==null&&Gn(e)===n.id&&await qn(n.path)}}const cr=1e3,lr=2e3;function ur(e,t){let n=Qn,r=Buffer.alloc(0);n!==null&&n.state.kind===`taken`&&(r=n.bytes,n.state={kind:`landed`});let i=null;if(n!==null&&n.state.kind===`issued`){let{fd:a,endsAt:o}=n.state;try{let s=dr(a,o,t);s<o&&e?(r=n.bytes.subarray(Math.max(0,s-(o-n.bytes.length))),n.state={kind:`landed`}):s<o&&(i={fd:a,endsAt:o})}catch(t){e&&(r=n.bytes,n.state={kind:`landed`}),fr(n.bytes.toString(),t)}}if(r.length===0&&Jn.length===0)return;let a=Buffer.concat([r,Buffer.from(or())]);try{let e=an();f.mkdirSync(o.dirname(e),{recursive:!0}),f.appendFileSync(e,a),i!==null&&n!==null&&Gn(f.fstatSync(i.fd))===Gn(f.statSync(e))&&(n.state={kind:`issued`,fd:i.fd,endsAt:i.endsAt+a.length})}catch(e){fr(a.toString(),e)}}function dr(e,t,n){let r=performance.now()+n,i=new Int32Array(new SharedArrayBuffer(4));for(;;){let{size:n}=f.fstatSync(e);if(n>=t||performance.now()>=r)return n;Atomics.wait(i,0,0,1)}}function fr(e,t){try{process.stderr.write(`${e}cc-candybar: daemon.log unwritable: ${t.message}\n`)}catch{}}const pr=5e3;function mr(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(`
5
5
  `)}const hr=`/usr/bin/footprint`;function gr(e,t){return e===`darwin`?[br(hr,[`-p`,String(t)]),br(`/usr/bin/vmmap`,[`--summary`,String(t)])]:e===`linux`?[xr(`/proc/self/smaps_rollup`),xr(`/proc/self/status`)]:[]}function _r(e,t){return e===`darwin`?vr(t,e=>Ot({bin:hr,args:e,timeoutMs:pr,category:`limits.charge`})):async e=>({kind:`charged`,measure:`rss`,bytes:e})}function vr(e,t){return async n=>{let r=await t([`-p`,String(e),`--noCategories`,`-f`,`bytes`]);if(!r.ok)return{kind:`stand-in`,bytes:n,unread:`footprint ${r.reason}${r.error===void 0?``:`: ${r.error}`}${Sr(r.stderr)}`};let i=yr(r.stdout);return i===null?{kind:`stand-in`,bytes:n,unread:`footprint printed no phys_footprint line`}:{kind:`charged`,measure:`phys_footprint`,bytes:i}}}function yr(e){let t=/^\s*phys_footprint:\s+(\d+) B\s*$/m.exec(e);return t===null?null:Number(t[1])}function br(e,t){return{name:`${e} ${t.join(` `)}`,read:()=>{let n=kt({bin:e,args:[...t],timeoutMs:pr,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}`}${Sr(n.stderr)}`}}}}function xr(e){return{name:e,read:()=>{try{let t=f.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 Sr(e){let t=e.split(`
@@ -56,7 +56,7 @@ import{createRequire as e}from"node:module";import t from"node:process";import{U
56
56
 
57
57
  `)}},Ry=class extends Error{constructor(e){super(e.map(e=>e.message).join(`
58
58
  `)),this.errors=e,this.name=`DroppedPlacements`}};function G(e,t){return zy(e)(t)}function zy(e){let t,n=()=>(t??={node:By(e)},t.node);return t=>Vy(e,n,t)}function By(e){try{return ha(e)}catch(e){if(e instanceof la)return;throw e}}function Vy(e,t,n){let r=n.some(e=>/^\d+$/.test(e))?Hy(e,t(),n):void 0;if(r!==void 0)return r;let i=0,a;for(let t of n){if(t===``||/^\d+$/.test(t))continue;let n=Uy(e,i,t);if(n===-1)return a===void 0?void 0:Wy(e,a);i=n,a=n}return a===void 0?void 0:Wy(e,a)}function Hy(e,t,n){if(t===void 0)return;let r=t,i,a=!1;for(let e of n){let t=r.kind===`array`&&/^\d+$/.test(e),n=r.kind===`array`?t?r.elements[Number(e)]:void 0:ga(r,e)?.value;if(n===void 0)break;a||=t,r=n,i=n}return i===void 0||!a?void 0:Wy(e,i.span.start)}function Uy(e,t,n){let r=n.replace(/[\\^$.*+?()[\]{}|]/g,`\\$&`),i=RegExp(`(?:["']${r}["']|\\b${r}\\b)\\s*:`,`g`);i.lastIndex=t;let a=i.exec(e);return a?a.index:-1}function Wy(e,t){let n=1;for(let r=0;r<t&&r<e.length;r++)e.charCodeAt(r)===10&&n++;return n}function Gy(e,t){try{return ha(t),null}catch(n){if(!(n instanceof la))throw n;return`${e}:${Wy(t,n.offset)}: ${n.reason} — the settings menu cannot edit this file until it is fixed`}}function Ky(e,t){if(t.length===0)return`${e}: invalid config (no details)`;let n=[`Invalid config in ${e} (${t.length} issue${t.length===1?``:`s`}):`];for(let e of t){let t=[];e.line!==void 0&&t.push(`line ${e.line}${e.col===void 0?``:`:${e.col}`}`),e.path&&t.push(e.path);let r=t.length>0?`[${t.join(` • `)}] `:``;n.push(` ${r}${e.message}`)}return n.join(`
59
- `)}function qy(e,t,n,r){let i=n[r];return typeof i==`string`?i:(e.issues.push({path:`${t}.${r}`,message:`${t}.${r} must be a string, got ${$y(i)}`,line:G(e.source,[...t.split(`.`),r])}),null)}function Jy(e,t,n,r){let i=n.default;if(i!==void 0){if(!(r===`string`&&typeof i==`string`||r===`number`&&typeof i==`number`||r===`boolean`&&typeof i==`boolean`)){e.issues.push({path:`${t}.default`,message:`default must be a ${r}, got ${$y(i)}`,line:G(e.source,[...t.split(`.`),`default`])});return}return i}}function Yy(e,t,n,r){let i=n[r];if(i!==void 0){if(typeof i!=`string`){e.issues.push({path:`${t}.${r}`,message:`${t}.${r} must be a string, got ${$y(i)}`,line:G(e.source,[...t.split(`.`),r])});return}return i}}function Xy(e,t,n){let r=Yy(e,t,n,`palette`);if(r!==void 0){if(!e.allowedPalettes.has(r)){e.issues.push({path:`${t}.palette`,message:`Unknown palette "${r}"${yv(r)}. Expected one of: ${[...e.allowedPalettes].sort().join(`, `)}`,line:G(e.source,[...t.split(`.`),`palette`])});return}return r}}function Zy(e,t,n,r,i){let a=n[r];if(a!==void 0){if(typeof a!=`string`||!i.includes(a)){e.issues.push({path:`${t}.${r}`,message:`${t}.${r} must be one of: ${i.join(`, `)}; got ${K(a)}`,line:G(e.source,[...t.split(`.`),r])});return}return a}}function Qy(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function $y(e){return e===null?`null`:Array.isArray(e)?`array`:typeof e}function K(e){return typeof e==`string`?JSON.stringify(e):e===void 0?`undefined`:String(e)}function eb(e,t,n,r){return Qy(r)?(rb(e,n,r,t.noun,new Set(Object.keys(t.fields)),tb(e,t.removed??{},n,r)),nb(e,t.fields,n,r)):(e.issues.push({path:n,message:`${n} must be an object, got ${$y(r)}`,line:G(e.source,n.split(`.`))}),null)}function tb(e,t,n,r){let i=Object.entries(t).filter(([e])=>r[e]!==void 0);for(let[t,r]of i)ib(e,`${n}.${t}`,`${n}.${t} was removed: ${r}`);return new Set(i.map(([e])=>`${n}.${e}`))}function nb(e,t,n,r){let i=t,a={},o=!0;for(let[t,s]of Object.entries(i)){let i=s.parse(e,n,t,r);i===void 0?s.required&&(o=!1):a[t]=i}return o?a:null}const bee=new Set;function rb(e,t,n,r,i,a=bee){for(let o of Object.keys(n))!i.has(o)&&!a.has(`${t}.${o}`)&&e.issues.push({path:`${t}.${o}`,message:`Unknown ${r} "${o}". Expected one of: ${[...i].join(`, `)}`,line:G(e.source,[...t.split(`.`),o])})}function ib(e,t,n){return e.issues.push({path:t,message:n,line:G(e.source,t.split(`.`))}),null}function ab(e,t,n,r){if(!Qy(r))return e.issues.push({path:n,message:`${t.noun} must be an object, got ${$y(r)}`,line:G(e.source,n.split(`.`))}),null;let i=t.arms,a=Object.keys(i),o=Object.keys(r).filter(e=>e in i),s=Object.keys(r).filter(e=>!(e in i));for(let r of s)e.issues.push({path:`${n}.${r}`,message:`Unknown ${t.noun} key "${r}". Expected exactly one of: ${a.join(`, `)}`,line:G(e.source,[...n.split(`.`),r])});if(o.length===0)return e.issues.push({path:n,message:`${t.noun} must declare exactly one of: ${a.join(`, `)}`,line:G(e.source,n.split(`.`))}),null;if(o.length>1)return e.issues.push({path:n,message:`${t.noun} must declare exactly one of: ${a.join(`, `)} (found: ${o.join(`, `)})`,line:G(e.source,n.split(`.`))}),null;let c=o[0];return i[c].parse(e,`${n}.${c}`,r[c])}function xee(e,t,n,r){if(!Qy(r))return e.issues.push({path:n,message:`${n} must be an object, got ${$y(r)}`,line:G(e.source,n.split(`.`))}),null;let i=r[t.tag];if(typeof i!=`string`)return e.issues.push({path:`${n}.${t.tag}`,message:`${n}.${t.tag} must be a string, got ${$y(i)}`,line:G(e.source,n.split(`.`))}),null;let a=t.arms;if(!Object.hasOwn(a,i)){let o=Object.hasOwn(t.retired,i)?t.retired[i](r):`Unknown ${t.noun} "${i}". Expected one of: ${Object.keys(a).join(`, `)}`;return e.issues.push({path:`${n}.${t.tag}`,message:o,line:G(e.source,[...n.split(`.`),t.tag])}),null}let o=a[i],s=e.issues.length,c=o.parse(e,n,r),l=new Set(e.issues.slice(s).map(e=>e.path));return rb(e,n,r,`${i} ${t.memberNoun} key`,o.keys,l),c}function See(e,t,n){return{json:Oee(pb(n),e,t),keys:new Set([e,...Object.keys(n)])}}function ob(e){return(...t)=>e()(...t)}function Cee(e,...t){return(n,r,i)=>{let a=e(n,r,i);if(a===null)return null;for(let e of t){if(e.ok(a))continue;let{field:t,message:i}=e.issue(a),o=t===``?r:`${r}.${t}`;return n.issues.push({path:o,message:i,line:G(n.source,o.split(`.`))}),null}return a}}function sb(){return{required:!1,json:{type:`string`},parse:(e,t,n,r)=>Yy(e,t,r,n)}}function cb(){return{required:!1,json:{type:`boolean`},parse:(e,t,n,r)=>{let i=r[n];if(i!==void 0){if(typeof i!=`boolean`){e.issues.push({path:`${t}.${n}`,message:`${n} must be a boolean, got ${$y(i)}`,line:G(e.source,[n])});return}return i}}}}function wee(e){let{min:t,max:n}=e;return{required:!1,json:{type:`integer`,minimum:t,maximum:n},parse:(e,r,i,a)=>{let o=a[i];if(o!==void 0){if(typeof o!=`number`||!Number.isInteger(o)||o<t||o>n){e.issues.push({path:`${r}.${i}`,message:`${i} must be an integer between ${t} and ${n}, got ${K(o)}`,line:G(e.source,[i])});return}return o}}}}function lb(e={}){let{min:t}=e;return{required:!1,json:{type:`number`,...t!==void 0&&{minimum:t}},parse:(e,n,r,i)=>{let a=i[r];if(a!==void 0){if(typeof a!=`number`||!Number.isFinite(a)||t!==void 0&&a<t){let i=t===void 0?`a finite number`:`a finite number >= ${t}`;e.issues.push({path:`${n}.${r}`,message:`${r} must be ${i}, got ${K(a)}`,line:G(e.source,[r])});return}return a}}}}function Tee(){return{required:!1,json:{type:`string`},parse:(e,t,n,r)=>Xy(e,t,r)}}function ub(){return{required:!0,json:{type:`string`},parse:(e,t,n,r)=>qy(e,t,r,n)??void 0}}function db(e,t){return l(t)?null:`${e} must be an absolute path (\`~\` and relative paths are not expanded), got ${JSON.stringify(t)}`}function Eee(){return{required:!0,json:{type:`string`,pattern:`^/`},parse:(e,t,n,r)=>{let i=qy(e,t,r,n);if(i===null)return;let a=db(`${t}.${n}`,i);return a===null?i:ib(e,`${t}.${n}`,a)??void 0}}}function fb(e){return{required:!1,json:{enum:[...e]},parse:(t,n,r,i)=>Zy(t,n,i,r,e)}}function pb(e,t={closed:!0}){let n=e,r={},i=[];for(let[e,t]of Object.entries(n))r[e]=t.json,t.required&&i.push(e);return{type:`object`,properties:r,...i.length>0&&{required:i},...t.closed&&{additionalProperties:!1}}}function Dee(e){return pb(e.fields)}function Oee(e,t,n){let r=e,i={[t]:{const:n},...r.properties},a=[t,...r.required??[]];return{...r,properties:i,required:a}}function kee(e){let t=e.arms;return{anyOf:Object.values(t).map(e=>e.json)}}function mb(e){let t=e.arms;return{anyOf:Object.entries(t).map(([e,t])=>({type:`object`,properties:{[e]:t.json},required:[e],additionalProperties:!1}))}}const Aee=[`claude`,`tmux`],hb=`ne .tmux.pane ""`,gb={band:{switch:{setting:`experimentalBand`,on:!0,inTmux:!1},label:`🧪 band (A)`,handsOff:!0,rows:null},statusline:{switch:{setting:`experimentalStatusline`,on:!0,inTmux:!1},label:`🧪 statusline (B)`,handsOff:!1,rows:null},pane:{switch:{setting:`experimentalPane`,on:!0,inTmux:!1},label:`🧪 tmux pane (C)`,handsOff:!0,rows:null},tmuxStatus:{switch:{setting:`renderer`,on:`tmux`,inTmux:!0},label:`tmux status line`,handsOff:!0,rows:5}},_b=Object.keys(gb),jee=_b.filter(e=>gb[e].switch.on===!0),vb={by:`request`},yb=e=>`drawing.${e}`,bb={subscribers:0,fps:0,shown:!0},xb=(e,t)=>`feeds.${e}.${t}`;function Sb(e){return Object.fromEntries(_b.map(t=>[t,e(t)]))}const Mee=Sb(()=>bb);function Cb(e){return typeof e==`string`&&Object.hasOwn(gb,e)?e:null}const wb=(e,t)=>Array.from({length:e*2},(e,n)=>({lit:n%2==0,seconds:t})),Tb=[...wb(3,1),...wb(3,.25)],Nee=Tb.reduce((e,{seconds:t})=>e+t,0),Pee={min:10,max:600,step:5},Eb=(e,t)=>e+t,Db=e=>e-Nee,Ob=(e,t,{previews:n=[],trials:r=[],shown:i=`true`}={})=>({label:e,place:t,previews:n,trials:r,shown:i}),kb=(e,t,n)=>({spec:fb(e),domain:{from:e},parse:t=>e.includes(t)?t:null,...t!==void 0&&{optionDomain:{name:t,members:e,...n!==void 0&&{library:n}}}}),Ab={spec:cb(),domain:`bool`,parse:ny},jb=e=>({spec:wee(e),domain:e,parse:t=>ry(t,e)});function Mb(e,t,n,r={}){return{kind:`session`,...kb(e,r.optionDomain,r.library),floor:t,control:n,themeDefault:r.themeDefault??!1}}function Nb(e,t){return{kind:`session`,...Ab,floor:e,control:t,themeDefault:!1}}function Pb(e,t,n){return{kind:`session`,...jb(e),floor:t,control:n,themeDefault:!1}}function Fb(e,t,n,r,i={}){return{kind:`selection`,sessionKey:e,spec:t,domain:n,control:r,themeDefault:i.themeDefault??!1}}const Ib=e=>({kind:`text`,spec:e}),Lb={required:!1,json:{enum:[...qv]},parse:(e,t,n,r)=>{if(r[n]===`auto`){e.issues.push({path:`${t}.${n}`,message:`${t}.${n}: "auto" is not supported — the render daemon runs detached, so terminal detection would read the daemon's environment, not your terminal's. Pick an explicit depth: ${qv.join(`, `)}`,line:G(e.source,[...t.split(`.`),n])});return}return Zy(e,t,r,n,qv)}},Rb={required:!1,json:{type:`string`},parse:(e,t,n,r)=>{let i=Yy(e,t,r,n);return Ov(i)?i:Xy(e,t,r)}},Fee={required:!1,json:{anyOf:[{enum:[...Lv]},{type:`string`,pattern:`\\{\\{`}]},parse:(e,t,n,r)=>{let i=r[n];return typeof i==`string`&&Ov(i)?i:Zy(e,t,r,n,Lv)}},zb=/^[^\r\n]*\S[^\r\n]*$/u,Bb=RegExp(`^(?:✖|✕)[\\uFE0E\\uFE0F]?$`,`u`),Vb={required:!1,json:{type:`string`,pattern:zb.source,not:{pattern:Bb.source}},parse:(e,t,n,r)=>{let i=Yy(e,t,r,n);if(i===void 0||zb.test(i)&&!Bb.test(i))return i;e.issues.push({path:`${t}.${n}`,message:`${t}.${n}: must be one line of visible text other than a close glyph ("✖", "✕") — the settings menu needs a glyph to click`,line:G(e.source,[...t.split(`.`),n])})}},Hb=Object.fromEntries(jee.map(e=>[gb[e].switch.setting,Nb(!1,Ob(gb[e].label,`toggles`))])),Ub={claude:`Claude Code's status line`,tmux:`the tmux status line, while this pane is shown`},Wb={groups:[{id:`renderer`,label:`draw the bar in`}],entry:e=>({group:`renderer`,description:Ub[e]})},Gb={palette:Fb(`theme`,Rb,{themes:`themes`},Ob(`🎨 theme`,`door`)),preset:Fb(`preset`,sb(),{from:`presets`},Ob(`▦`,`door`,{previews:[`layout`,`presetDelete`]})),style:Fb(`style`,sb(),{from:`styles`},Ob(`◐`,`gear`,{previews:[`palette`]}),{themeDefault:!0}),effect:Fb(`effect`,Fee,{from:Lv},Ob(`✨`,`look`)),endcaps:Mb(Wv,`powerline`,Ob(`✦`,`look`),{optionDomain:`endcaps`}),variation:Mb(Xv,`accent`,Ob(`🎼`,`gear`,{previews:[`layout`],trials:__}),{optionDomain:`variations`,themeDefault:!0}),shade:Mb(Zv,`middle`,Ob(`🔆`,`gear`,{previews:[`layout`],trials:o_}),{optionDomain:`shades`,themeDefault:!0}),transitions:Nb(!1,Ob(`fade in/out`,`look`)),animationSpeed:Mb(zv,`1x`,Ob(`speed`,`look`)),autoWrap:Nb(!0,Ob(`wrap`,`config`)),padding:Pb({...ty,step:1},1,Ob(`padding`,`config`)),updateNotice:Nb(!0,Ob(`update notice`,`config`)),menuTimeout:Pb(Pee,30,Ob(`menu timeout`,`config`)),renderer:Mb(Aee,`claude`,Ob(`renderer`,`config`,{shown:hb}),{optionDomain:`renderers`,library:Wb}),...Hb,colorCompatibility:{kind:`config`,...kb(qv,`colorCompatibilities`),spec:Lb,floor:`truecolor`},default_empty_value:Ib(sb()),default_separator:Ib(sb()),menuGlyph:Ib(Vb)},Kb=Object.entries(Gb),qb=Kb.filter(([,e])=>e.kind===`session`||e.kind===`config`).map(([e])=>e),Jb=Kb.filter(([,e])=>e.kind===`session`||e.kind===`selection`).map(([e])=>e),Yb=Kb.filter(([,e])=>(e.kind===`session`||e.kind===`selection`)&&e.themeDefault).map(([e])=>e),Xb=Kb.flatMap(([,e])=>`optionDomain`in e&&e.optionDomain!==void 0?[e.optionDomain]:[]);function Zb(e){return Gb[e]}const Qb=e=>Zb(e).floor;function $b(e){let t=Gb[e];if(t.kind===`text`)return`string`;let{domain:n}=t;return n===`bool`?`boolean`:typeof n==`object`&&`min`in n?`number`:`string`}const ex=e=>`${e}.effective`,tx=e=>{let t=Gb[e];return t.kind===`selection`?t.sessionKey:e},nx=Object.fromEntries(Jb.map(e=>{let t=tx(e);return[t,{configKey:e,sessionKey:t,effectiveVar:ex(t),...Gb[e].control}]})),rx=Object.keys(nx),ix=Object.values(nx),ax=qb.filter(e=>Gb[e].kind===`config`).map(e=>({configKey:e,effectiveVar:ex(e)})),ox=new Set(ax.map(e=>e.configKey)),sx=new Map([...ix,...ax].map(e=>[e.configKey,e.effectiveVar])),cx=new Map(ix.map(e=>[e.sessionKey,e.effectiveVar]));function lx(e){return Object.fromEntries(rx.map(t=>[t,e(t)]))}const ux=new Map(rx.map(e=>[nx[e].sessionKey,e]));function dx(e){return e.replace(/[^A-Za-z0-9]+/g,`_`)}const fx=[`plugins`,`repo`];function px({scope:e,name:t}){return`${e}.${t}`}function mx(e){return t=>t===e||t.startsWith(`${e}.`)}const hx=`self`;function gx(e){return fx.find(t=>e===t||e.startsWith(`${t}.`))}function _x(e,t){let n=gx(e);if(n===void 0||n===e)return``;let r=fx.filter(e=>e!==n).map(t=>`${t}${e.slice(n.length)}`).find(t);return r===void 0?``:` ("${r}" is declared: a repository's own plugins are named under repo., installed ones under plugins., and a name in one is never looked up in the other)`}const vx=`groups.`,yx=`menus.`,bx=`menupages.`,xx=`edit.`,q=`candybar.`,Sx=[vx,yx,bx,xx,q];function Cx(e){return Sx.some(t=>e.startsWith(t))}function wx(e){let t=dx(e);return Sx.find(e=>t.startsWith(dx(e)))}function Tx(e,t,n,r){for(let i of[`variables`,`actions`,`segments`])for(let a of Object.keys(t[i]??{}))a.startsWith(n)&&e.issues.push({path:`${i}.${a}`,message:`"${a}" is in the reserved "${n}" namespace (synthesized by ${r}) — rename it`,line:G(e.source,[`root`])})}function Ex(e,t,n){for(let r of[`variables`,`actions`,`helpers`,`segments`])for(let i of Object.keys(t[r]??{})){let t=gx(i);t!==void 0&&(r!==`variables`&&i===t||r===`segments`&&n.has(i)||e.issues.push({path:`${r}.${i}`,message:`"${i}" is in "${t}", the namespace plugins own (each declares its names there from its own definition) — rename it`,line:G(e.source,[r,i])}))}for(let[r,i]of Object.entries(t.segments??{}))for(let t of Object.keys(i.vars??{})){let i=`${r}.${t}`,a=gx(i);a===void 0||n.has(r)||e.issues.push({path:`segments.${r}.vars.${t}`,message:`segment "${r}"'s var "${t}" is named "${i}", in "${a}", the namespace plugins own — rename the var or the segment`,line:G(e.source,[`segments`,r,`vars`,t])})}}const Dx=`${q}menu`,Ox=`open`,kx={variable:Dx,key:Dx,member:Ox},Ax=`${q}diagnostics`,jx=[[0,31],[127,159],[8234,8238],[8294,8303]];function Mx(e){return jx.some(([t,n])=>e>=t&&e<=n)}function Nx(e){let t=``;for(let n of e)t+=Mx(n.codePointAt(0)??0)?` `:n;return t.replace(/\s+/g,` `).trim()}function Px(e,t){let n=Nx(e),r=``,i=0;for(let e of n){if(i===t)return r.replace(/.$/u,`…`);r+=e,i++}return r}const Fx=`\x1B[38;2;255;255;255m`,Ix=`\x1B[48;2;200;40;40m`,Lx=`\x1B[0m`;function Rx(e){let t=/;2;(\d+);(\d+);(\d+)m$/.exec(e);if(t===null)throw Error(`diagnostic-style: not a 24-bit SGR: ${e}`);return`#`+t.slice(1,4).map(e=>Number(e).toString(16).padStart(2,`0`)).join(``)}const zx={fg:Rx(Fx),bg:Rx(Ix)},Bx={fg:Rx(`\x1B[38;2;0;0;0m`),bg:Rx(`\x1B[48;2;220;160;40m`)},Vx=new zd({"strip.separator":`default`,"strip.rail":`default`});function Hx(e){return Vx.resolve(e)}const Ux={kind:`still`},Wx=e=>If.at(e.timeline,e.wall),Gx=Symbol(`bar`);function Kx(e){return e.name!==Pv}function qx(e){return t=>U.map(U.all(e.map(({timeline:e,effect:n})=>If.run(e,n(t)))),e=>(t,n)=>e.reduce((e,t)=>t(e,n),t))}const Jx=Uu;function Yx(e,t){let n=new kl(t,Jx.foregroundColor,Jx.ansiColors,Jx.palette);return t=>e({...t,theme:n})}function Xx(e,t){return n=>Ym(()=>e(n),...t)(n)}function Zx(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619)>>>0;return t/4294967296}const Qx=4096;function $x(e,t,n){let r=(n,{terminal:r})=>({...n,bg:r.bg?n.bg:e,fg:r.fg?n.fg:r.bg?e:t}),i=e=>e,a=Tb.reduceRight((e,{lit:t,seconds:n})=>U.sequence(U.constant(t?r:i),n,e),U.constant(i)),o=U.sequence(U.constant(i),n,a);return()=>o}var eS=class{inForce=null;anchor=If.play(0);placements=new Map;made=new Map;passages=null;frame={effect:Pv,t:0,speed:1,made:0,reused:0,own:[],basis:`off`,revision:0,fades:[],leaves:[]};constructor(e){this.key=e}lastFrame(){return this.frame}get heldCount(){let e=this.passages?.size??0;return[...this.made.values()].reduce((e,t)=>e+t.size,e)}clockAt(e,t){return{wall:e,timeline:If.withRate(this.anchor,e,t)}}motion(e,t,n,r=null){let i=Wx(t),a=e=>If.seek(t.timeline,t.wall,e),o=this.inForce?.name===e?this.inForce:{name:e,since:i},s={scope:Gx,name:e,t:i-o.since},c=this.placements,l=new Map,u=this.made,d=new Map,f=[],{last:p}=n,m=this.passages,h=n.transitions?m!==null&&p!==null?`compared`:`fresh`:`off`,g=h===`compared`?e=>{let t=p.placements.get(e);return t?.kind===`drew`?{drawing:t.drawing,passage:m.get(e)??null}:void 0}:null,_=new Set,v=new Map,y=[],b=[],ee={effect:e,t:s.t,speed:t.timeline.rate,made:0,reused:0,own:f,basis:h,revision:n.source.revision,fades:y,leaves:b},x=(e,t,{ground:n})=>{let r=fg.transitions[e]({z:Zx(`${this.key}@${t}`)*Qx});return{name:e,since:i,done:e=>r.done(e),effect:Yx(r.effect,n)}},S=({since:e,done:t})=>t(i-e),te=(e,t,n)=>({drawing:t,passage:g===null?null:n===void 0||n.passage?.name===`dissolve`?x(`fade`,e,t):n.passage!==null&&!S(n.passage)?n.passage:null}),C=(e,t)=>{if(t===void 0||t.drawing.opened||t.drawing.own.length===0)return;if(t.passage?.name===`dissolve`)return S(t.passage)?void 0:t;let r={...t.drawing,own:t.drawing.own.map(n.hold)};return{drawing:r,passage:x(`dissolve`,e,r)}},ne=(e,t)=>{if(_.has(e))throw Error(`placement "${e}" was reached twice in one frame`);_.add(e);let r=g?.(e),{drawing:a,deeper:o}=n.returned(e,t),s=a===null?C(e,r):te(e,a,r);return s===void 0?t:(s.passage!==null&&(v.set(e,s.passage),(s.passage.name===`fade`?y:b).push({placement:e,t:i-s.passage.since})),a===null?[...s.drawing.own,...o]:t)},re=(e,t)=>{let n=l.get(e)??c.get(e),r=n?.name===t?n:{name:t,since:i},a=i-r.since;return l.has(e)||(l.set(e,r),f.push({placement:e,effect:t,t:a})),{scope:e,name:t,t:a}},ie=(e,t)=>{let n=d.get(e)??new Map;d.set(e,n);let r=n.get(t.scope);if(r!==void 0)return r.effect;let i=u.get(e)?.get(t.scope),a=i?.name===t.name,o=Zx(t.scope===Gx?e:`${e}@${t.scope}`),s=a?i.effect:fg.loops[t.name]({z:o*Qx});return ee[a?`reused`:`made`]++,n.set(t.scope,{name:t.name,effect:s}),s},ae=e=>{let t=new Map;for(let{owner:n,placement:r}of e){let e=r.effect===`bar`?s:re(r.id,r.effect),i=t.get(e.scope);i===void 0?t.set(e.scope,{...e,owners:[n]}):i.owners.push(n)}return[...t.values()]},w=e=>{let t=new Map;for(let{owner:n,placement:r}of e){let e=t.get(r.id);e===void 0?t.set(r.id,[n]):e.push(n)}return[...t].flatMap(([e,t])=>{let n=v.get(e)??null;return n===null?[]:[{timeline:a(i-n.since),effect:Ym(n.effect,...t)}]})},oe=r===null?[]:[{timeline:If.play(r.idleSince),effect:$x(r.fill,r.text,Db(r.timeoutS))}],se=e=>e===`menu`?oe:[];return{placed:h===`off`?(e,t)=>t:ne,row:(e,n,r)=>{let i=(r.some(e=>e.placement.effect!==`bar`)?ae(r):[{...s,owners:void 0}]).filter(Kx),o=w(r),c=se(n);if(i.length===0&&o.length===0&&c.length===0)return Ux;let l=`${this.key}#${e}`;return{kind:`moving`,time:t.wall,wrap:e=>new zm(e,qx([...i.map(e=>{let t=ie(l,e);return{timeline:a(e.t),effect:e.owners===void 0?t:Xx(t,e.owners)}}),...o,...c]),{key:l,theme:Jx})}},drawn:()=>{this.anchor=t.timeline,this.inForce=o,this.placements=l,this.made=d,this.passages=h===`off`?null:v,this.frame=ee}}}},tS=class{sessions=new Map;constructor(e=256){this.maxSessions=e}of(e){let t=this.sessions.get(e)??new eS(e);this.sessions.delete(e),this.sessions.set(e,t);for(let e of this.sessions.keys()){if(this.sessions.size<=this.maxSessions)break;this.sessions.delete(e)}return t}getStats(){let e=0;for(let t of this.sessions.values())e+=t.heldCount;return{sessions:this.sessions.size,effects:e}}};function nS(e,t){let n=sl(t.colorSystem),{time:r}=t,i=1/0,a=[...df(e,{maxWidth:t.width??80,isTerminal:!1,asciiOnly:!1,theme:Vx,colorSystem:n.colorSystem,...r===void 0?{}:{frame:{time:r,host:{frameTime:r}}},onStyleError:e=>{throw e},onHold:({nextChange:e})=>{i=Math.min(i,e)}})];return{text:Cm(a,n),nextChange:Math.min(H.nextChange(a),i)}}const rS=new Map;function iS(e){let t=rS.get(e);if(t!==void 0)return t;let n=t=>({seam:t.seam.map(t=>`cap`in t?t:{...t,glyph:e})}),{seam:r,caps:i}=Sm.plain,a=new Kp({glyph:n(r.glyph),ascii:r.ascii},i);return rS.set(e,a),a}function aS(e,t){return e===`plain`&&t!==void 0?iS(t):Sm[e]}const oS=new Map;function sS(e){let t=JSON.stringify([e.endcaps,e.separator??null]),n=oS.get(t);if(n!==void 0)return n;let r=aS(e.endcaps,e.separator),i=e=>new W(`x`,{end:``,overflow:`ignore`,style:new V({bgcolor:e})}),a=e=>new W(nS(new hp(e,r),{colorSystem:null}).text.replace(/\n$/,``)).cellLength,o=a([i(`#101010`)]),s={chrome:o-1,seam:a([i(`#101010`),i(`#202020`)])-o-1};return oS.set(t,s),s}function cS(e){return sS(e).chrome}function lS(e){return sS(e).seam}const uS=/[\u{E000}-\u{F8FF}\u{F0000}-\u{FFFFD}\u{100000}-\u{10FFFD}]/gu;function dS(e){return[...new Set(e.match(uS)??[])].join(``)}function fS(e){let t=aS(e.endcaps,e.separator),n=e=>new W(`x`,{end:``,style:new V({bgcolor:e})});return dS(nS(new hp([n(`#101010`),n(`#202020`)],t),{colorSystem:null}).text)}function pS(e,t,n=Ux){if(e.length===0)return{text:``,nextChange:1/0};let r=aS(t.endcaps,t.separator),i=t.wrap&&Number.isFinite(t.width),a={colorSystem:t.colorCompatibility,...i?{width:t.width}:{}},o=i?new Gg([...e],{joiner:r}):new hp([...e],r),s=n.kind===`still`?nS(o,a):nS(n.wrap(o),{...a,time:n.time});if(!s.text.endsWith(`
59
+ `)}function qy(e,t,n,r){let i=n[r];return typeof i==`string`?i:(e.issues.push({path:`${t}.${r}`,message:`${t}.${r} must be a string, got ${$y(i)}`,line:G(e.source,[...t.split(`.`),r])}),null)}function Jy(e,t,n,r){let i=n.default;if(i!==void 0){if(!(r===`string`&&typeof i==`string`||r===`number`&&typeof i==`number`||r===`boolean`&&typeof i==`boolean`)){e.issues.push({path:`${t}.default`,message:`default must be a ${r}, got ${$y(i)}`,line:G(e.source,[...t.split(`.`),`default`])});return}return i}}function Yy(e,t,n,r){let i=n[r];if(i!==void 0){if(typeof i!=`string`){e.issues.push({path:`${t}.${r}`,message:`${t}.${r} must be a string, got ${$y(i)}`,line:G(e.source,[...t.split(`.`),r])});return}return i}}function Xy(e,t,n){let r=Yy(e,t,n,`palette`);if(r!==void 0){if(!e.allowedPalettes.has(r)){e.issues.push({path:`${t}.palette`,message:`Unknown palette "${r}"${yv(r)}. Expected one of: ${[...e.allowedPalettes].sort().join(`, `)}`,line:G(e.source,[...t.split(`.`),`palette`])});return}return r}}function Zy(e,t,n,r,i){let a=n[r];if(a!==void 0){if(typeof a!=`string`||!i.includes(a)){e.issues.push({path:`${t}.${r}`,message:`${t}.${r} must be one of: ${i.join(`, `)}; got ${K(a)}`,line:G(e.source,[...t.split(`.`),r])});return}return a}}function Qy(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function $y(e){return e===null?`null`:Array.isArray(e)?`array`:typeof e}function K(e){return typeof e==`string`?JSON.stringify(e):e===void 0?`undefined`:String(e)}function eb(e,t,n,r){return Qy(r)?(rb(e,n,r,t.noun,new Set(Object.keys(t.fields)),tb(e,t.removed??{},n,r)),nb(e,t.fields,n,r)):(e.issues.push({path:n,message:`${n} must be an object, got ${$y(r)}`,line:G(e.source,n.split(`.`))}),null)}function tb(e,t,n,r){let i=Object.entries(t).filter(([e])=>r[e]!==void 0);for(let[t,r]of i)ib(e,`${n}.${t}`,`${n}.${t} was removed: ${r}`);return new Set(i.map(([e])=>`${n}.${e}`))}function nb(e,t,n,r){let i=t,a={},o=!0;for(let[t,s]of Object.entries(i)){let i=s.parse(e,n,t,r);i===void 0?s.required&&(o=!1):a[t]=i}return o?a:null}const bee=new Set;function rb(e,t,n,r,i,a=bee){for(let o of Object.keys(n))!i.has(o)&&!a.has(`${t}.${o}`)&&e.issues.push({path:`${t}.${o}`,message:`Unknown ${r} "${o}". Expected one of: ${[...i].join(`, `)}`,line:G(e.source,[...t.split(`.`),o])})}function ib(e,t,n){return e.issues.push({path:t,message:n,line:G(e.source,t.split(`.`))}),null}function ab(e,t,n,r){if(!Qy(r))return e.issues.push({path:n,message:`${t.noun} must be an object, got ${$y(r)}`,line:G(e.source,n.split(`.`))}),null;let i=t.arms,a=Object.keys(i),o=Object.keys(r).filter(e=>e in i),s=Object.keys(r).filter(e=>!(e in i));for(let r of s)e.issues.push({path:`${n}.${r}`,message:`Unknown ${t.noun} key "${r}". Expected exactly one of: ${a.join(`, `)}`,line:G(e.source,[...n.split(`.`),r])});if(o.length===0)return e.issues.push({path:n,message:`${t.noun} must declare exactly one of: ${a.join(`, `)}`,line:G(e.source,n.split(`.`))}),null;if(o.length>1)return e.issues.push({path:n,message:`${t.noun} must declare exactly one of: ${a.join(`, `)} (found: ${o.join(`, `)})`,line:G(e.source,n.split(`.`))}),null;let c=o[0];return i[c].parse(e,`${n}.${c}`,r[c])}function xee(e,t,n,r){if(!Qy(r))return e.issues.push({path:n,message:`${n} must be an object, got ${$y(r)}`,line:G(e.source,n.split(`.`))}),null;let i=r[t.tag];if(typeof i!=`string`)return e.issues.push({path:`${n}.${t.tag}`,message:`${n}.${t.tag} must be a string, got ${$y(i)}`,line:G(e.source,n.split(`.`))}),null;let a=t.arms;if(!Object.hasOwn(a,i)){let o=Object.hasOwn(t.retired,i)?t.retired[i](r):`Unknown ${t.noun} "${i}". Expected one of: ${Object.keys(a).join(`, `)}`;return e.issues.push({path:`${n}.${t.tag}`,message:o,line:G(e.source,[...n.split(`.`),t.tag])}),null}let o=a[i],s=e.issues.length,c=o.parse(e,n,r),l=new Set(e.issues.slice(s).map(e=>e.path));return rb(e,n,r,`${i} ${t.memberNoun} key`,o.keys,l),c}function See(e,t,n){return{json:Oee(pb(n),e,t),keys:new Set([e,...Object.keys(n)])}}function ob(e){return(...t)=>e()(...t)}function Cee(e,...t){return(n,r,i)=>{let a=e(n,r,i);if(a===null)return null;for(let e of t){if(e.ok(a))continue;let{field:t,message:i}=e.issue(a),o=t===``?r:`${r}.${t}`;return n.issues.push({path:o,message:i,line:G(n.source,o.split(`.`))}),null}return a}}function sb(){return{required:!1,json:{type:`string`},parse:(e,t,n,r)=>Yy(e,t,r,n)}}function cb(){return{required:!1,json:{type:`boolean`},parse:(e,t,n,r)=>{let i=r[n];if(i!==void 0){if(typeof i!=`boolean`){e.issues.push({path:`${t}.${n}`,message:`${n} must be a boolean, got ${$y(i)}`,line:G(e.source,[n])});return}return i}}}}function wee(e){let{min:t,max:n}=e;return{required:!1,json:{type:`integer`,minimum:t,maximum:n},parse:(e,r,i,a)=>{let o=a[i];if(o!==void 0){if(typeof o!=`number`||!Number.isInteger(o)||o<t||o>n){e.issues.push({path:`${r}.${i}`,message:`${i} must be an integer between ${t} and ${n}, got ${K(o)}`,line:G(e.source,[i])});return}return o}}}}function lb(e={}){let{min:t}=e;return{required:!1,json:{type:`number`,...t!==void 0&&{minimum:t}},parse:(e,n,r,i)=>{let a=i[r];if(a!==void 0){if(typeof a!=`number`||!Number.isFinite(a)||t!==void 0&&a<t){let i=t===void 0?`a finite number`:`a finite number >= ${t}`;e.issues.push({path:`${n}.${r}`,message:`${r} must be ${i}, got ${K(a)}`,line:G(e.source,[r])});return}return a}}}}function Tee(){return{required:!1,json:{type:`string`},parse:(e,t,n,r)=>Xy(e,t,r)}}function ub(){return{required:!0,json:{type:`string`},parse:(e,t,n,r)=>qy(e,t,r,n)??void 0}}function db(e,t){return l(t)?null:`${e} must be an absolute path (\`~\` and relative paths are not expanded), got ${JSON.stringify(t)}`}function Eee(){return{required:!0,json:{type:`string`,pattern:`^/`},parse:(e,t,n,r)=>{let i=qy(e,t,r,n);if(i===null)return;let a=db(`${t}.${n}`,i);return a===null?i:ib(e,`${t}.${n}`,a)??void 0}}}function fb(e){return{required:!1,json:{enum:[...e]},parse:(t,n,r,i)=>Zy(t,n,i,r,e)}}function pb(e,t={closed:!0}){let n=e,r={},i=[];for(let[e,t]of Object.entries(n))r[e]=t.json,t.required&&i.push(e);return{type:`object`,properties:r,...i.length>0&&{required:i},...t.closed&&{additionalProperties:!1}}}function Dee(e){return pb(e.fields)}function Oee(e,t,n){let r=e,i={[t]:{const:n},...r.properties},a=[t,...r.required??[]];return{...r,properties:i,required:a}}function kee(e){let t=e.arms;return{anyOf:Object.values(t).map(e=>e.json)}}function mb(e){let t=e.arms;return{anyOf:Object.entries(t).map(([e,t])=>({type:`object`,properties:{[e]:t.json},required:[e],additionalProperties:!1}))}}const Aee=[`claude`,`tmux`],hb=`ne .tmux.pane ""`,gb={band:{switch:{setting:`experimentalBand`,on:!0,inTmux:!1},label:`🧪 band (A)`,handsOff:!0,rows:null},statusline:{switch:{setting:`experimentalStatusline`,on:!0,inTmux:!1},label:`🧪 statusline (B)`,handsOff:!1,rows:null},pane:{switch:{setting:`experimentalPane`,on:!0,inTmux:!1},label:`🧪 tmux pane (C)`,handsOff:!0,rows:null},tmuxStatus:{switch:{setting:`renderer`,on:`tmux`,inTmux:!0},label:`tmux status line`,handsOff:!0,rows:5}},_b=Object.keys(gb),jee=_b.filter(e=>gb[e].switch.on===!0),vb={by:`request`},yb=e=>`drawing.${e}`,bb={subscribers:0,fps:0,shown:!0},xb=(e,t)=>`feeds.${e}.${t}`;function Sb(e){return Object.fromEntries(_b.map(t=>[t,e(t)]))}const Mee=Sb(()=>bb);function Cb(e){return typeof e==`string`&&Object.hasOwn(gb,e)?e:null}const wb=(e,t)=>Array.from({length:e*2},(e,n)=>({lit:n%2==0,seconds:t})),Tb=[...wb(3,1),...wb(3,.25)],Nee=Tb.reduce((e,{seconds:t})=>e+t,0),Pee={min:15,max:600,step:15},Eb=(e,t)=>e+t,Db=e=>e-Nee,Ob=(e,t,{previews:n=[],trials:r=[],shown:i=`true`}={})=>({label:e,place:t,previews:n,trials:r,shown:i}),kb=(e,t,n)=>({spec:fb(e),domain:{from:e},parse:t=>e.includes(t)?t:null,...t!==void 0&&{optionDomain:{name:t,members:e,...n!==void 0&&{library:n}}}}),Ab={spec:cb(),domain:`bool`,parse:ny},jb=e=>({spec:wee(e),domain:e,parse:t=>ry(t,e)});function Mb(e,t,n,r={}){return{kind:`session`,...kb(e,r.optionDomain,r.library),floor:t,control:n,themeDefault:r.themeDefault??!1}}function Nb(e,t){return{kind:`session`,...Ab,floor:e,control:t,themeDefault:!1}}function Pb(e,t,n){return{kind:`session`,...jb(e),floor:t,control:n,themeDefault:!1}}function Fb(e,t,n,r,i={}){return{kind:`selection`,sessionKey:e,spec:t,domain:n,control:r,themeDefault:i.themeDefault??!1}}const Ib=e=>({kind:`text`,spec:e}),Lb={required:!1,json:{enum:[...qv]},parse:(e,t,n,r)=>{if(r[n]===`auto`){e.issues.push({path:`${t}.${n}`,message:`${t}.${n}: "auto" is not supported — the render daemon runs detached, so terminal detection would read the daemon's environment, not your terminal's. Pick an explicit depth: ${qv.join(`, `)}`,line:G(e.source,[...t.split(`.`),n])});return}return Zy(e,t,r,n,qv)}},Rb={required:!1,json:{type:`string`},parse:(e,t,n,r)=>{let i=Yy(e,t,r,n);return Ov(i)?i:Xy(e,t,r)}},Fee={required:!1,json:{anyOf:[{enum:[...Lv]},{type:`string`,pattern:`\\{\\{`}]},parse:(e,t,n,r)=>{let i=r[n];return typeof i==`string`&&Ov(i)?i:Zy(e,t,r,n,Lv)}},zb=/^[^\r\n]*\S[^\r\n]*$/u,Bb=RegExp(`^(?:✖|✕)[\\uFE0E\\uFE0F]?$`,`u`),Vb={required:!1,json:{type:`string`,pattern:zb.source,not:{pattern:Bb.source}},parse:(e,t,n,r)=>{let i=Yy(e,t,r,n);if(i===void 0||zb.test(i)&&!Bb.test(i))return i;e.issues.push({path:`${t}.${n}`,message:`${t}.${n}: must be one line of visible text other than a close glyph ("✖", "✕") — the settings menu needs a glyph to click`,line:G(e.source,[...t.split(`.`),n])})}},Hb=Object.fromEntries(jee.map(e=>[gb[e].switch.setting,Nb(!1,Ob(gb[e].label,`toggles`))])),Ub={claude:`Claude Code's status line`,tmux:`the tmux status line, while this pane is shown`},Wb={groups:[{id:`renderer`,label:`draw the bar in`}],entry:e=>({group:`renderer`,description:Ub[e]})},Gb={palette:Fb(`theme`,Rb,{themes:`themes`},Ob(`🎨 theme`,`door`)),preset:Fb(`preset`,sb(),{from:`presets`},Ob(`▦`,`door`,{previews:[`layout`,`presetDelete`]})),style:Fb(`style`,sb(),{from:`styles`},Ob(`◐`,`gear`,{previews:[`palette`]}),{themeDefault:!0}),effect:Fb(`effect`,Fee,{from:Lv},Ob(`✨`,`look`)),endcaps:Mb(Wv,`powerline`,Ob(`✦`,`look`),{optionDomain:`endcaps`}),variation:Mb(Xv,`accent`,Ob(`🎼`,`gear`,{previews:[`layout`],trials:__}),{optionDomain:`variations`,themeDefault:!0}),shade:Mb(Zv,`middle`,Ob(`🔆`,`gear`,{previews:[`layout`],trials:o_}),{optionDomain:`shades`,themeDefault:!0}),transitions:Nb(!1,Ob(`fade in/out`,`look`)),animationSpeed:Mb(zv,`1x`,Ob(`speed`,`look`)),autoWrap:Nb(!0,Ob(`wrap`,`config`)),padding:Pb({...ty,step:1},1,Ob(`padding`,`config`)),updateNotice:Nb(!0,Ob(`update notice`,`config`)),menuTimeout:Pb(Pee,120,Ob(`menu timeout`,`config`)),renderer:Mb(Aee,`claude`,Ob(`renderer`,`config`,{shown:hb}),{optionDomain:`renderers`,library:Wb}),...Hb,colorCompatibility:{kind:`config`,...kb(qv,`colorCompatibilities`),spec:Lb,floor:`truecolor`},default_empty_value:Ib(sb()),default_separator:Ib(sb()),menuGlyph:Ib(Vb)},Kb=Object.entries(Gb),qb=Kb.filter(([,e])=>e.kind===`session`||e.kind===`config`).map(([e])=>e),Jb=Kb.filter(([,e])=>e.kind===`session`||e.kind===`selection`).map(([e])=>e),Yb=Kb.filter(([,e])=>(e.kind===`session`||e.kind===`selection`)&&e.themeDefault).map(([e])=>e),Xb=Kb.flatMap(([,e])=>`optionDomain`in e&&e.optionDomain!==void 0?[e.optionDomain]:[]);function Zb(e){return Gb[e]}const Qb=e=>Zb(e).floor;function $b(e){let t=Gb[e];if(t.kind===`text`)return`string`;let{domain:n}=t;return n===`bool`?`boolean`:typeof n==`object`&&`min`in n?`number`:`string`}const ex=e=>`${e}.effective`,tx=e=>{let t=Gb[e];return t.kind===`selection`?t.sessionKey:e},nx=Object.fromEntries(Jb.map(e=>{let t=tx(e);return[t,{configKey:e,sessionKey:t,effectiveVar:ex(t),...Gb[e].control}]})),rx=Object.keys(nx),ix=Object.values(nx),ax=qb.filter(e=>Gb[e].kind===`config`).map(e=>({configKey:e,effectiveVar:ex(e)})),ox=new Set(ax.map(e=>e.configKey)),sx=new Map([...ix,...ax].map(e=>[e.configKey,e.effectiveVar])),cx=new Map(ix.map(e=>[e.sessionKey,e.effectiveVar]));function lx(e){return Object.fromEntries(rx.map(t=>[t,e(t)]))}const ux=new Map(rx.map(e=>[nx[e].sessionKey,e]));function dx(e){return e.replace(/[^A-Za-z0-9]+/g,`_`)}const fx=[`plugins`,`repo`];function px({scope:e,name:t}){return`${e}.${t}`}function mx(e){return t=>t===e||t.startsWith(`${e}.`)}const hx=`self`;function gx(e){return fx.find(t=>e===t||e.startsWith(`${t}.`))}function _x(e,t){let n=gx(e);if(n===void 0||n===e)return``;let r=fx.filter(e=>e!==n).map(t=>`${t}${e.slice(n.length)}`).find(t);return r===void 0?``:` ("${r}" is declared: a repository's own plugins are named under repo., installed ones under plugins., and a name in one is never looked up in the other)`}const vx=`groups.`,yx=`menus.`,bx=`menupages.`,xx=`edit.`,q=`candybar.`,Sx=[vx,yx,bx,xx,q];function Cx(e){return Sx.some(t=>e.startsWith(t))}function wx(e){let t=dx(e);return Sx.find(e=>t.startsWith(dx(e)))}function Tx(e,t,n,r){for(let i of[`variables`,`actions`,`segments`])for(let a of Object.keys(t[i]??{}))a.startsWith(n)&&e.issues.push({path:`${i}.${a}`,message:`"${a}" is in the reserved "${n}" namespace (synthesized by ${r}) — rename it`,line:G(e.source,[`root`])})}function Ex(e,t,n){for(let r of[`variables`,`actions`,`helpers`,`segments`])for(let i of Object.keys(t[r]??{})){let t=gx(i);t!==void 0&&(r!==`variables`&&i===t||r===`segments`&&n.has(i)||e.issues.push({path:`${r}.${i}`,message:`"${i}" is in "${t}", the namespace plugins own (each declares its names there from its own definition) — rename it`,line:G(e.source,[r,i])}))}for(let[r,i]of Object.entries(t.segments??{}))for(let t of Object.keys(i.vars??{})){let i=`${r}.${t}`,a=gx(i);a===void 0||n.has(r)||e.issues.push({path:`segments.${r}.vars.${t}`,message:`segment "${r}"'s var "${t}" is named "${i}", in "${a}", the namespace plugins own — rename the var or the segment`,line:G(e.source,[`segments`,r,`vars`,t])})}}const Dx=`${q}menu`,Ox=`open`,kx={variable:Dx,key:Dx,member:Ox},Ax=`${q}diagnostics`,jx=[[0,31],[127,159],[8234,8238],[8294,8303]];function Mx(e){return jx.some(([t,n])=>e>=t&&e<=n)}function Nx(e){let t=``;for(let n of e)t+=Mx(n.codePointAt(0)??0)?` `:n;return t.replace(/\s+/g,` `).trim()}function Px(e,t){let n=Nx(e),r=``,i=0;for(let e of n){if(i===t)return r.replace(/.$/u,`…`);r+=e,i++}return r}const Fx=`\x1B[38;2;255;255;255m`,Ix=`\x1B[48;2;200;40;40m`,Lx=`\x1B[0m`;function Rx(e){let t=/;2;(\d+);(\d+);(\d+)m$/.exec(e);if(t===null)throw Error(`diagnostic-style: not a 24-bit SGR: ${e}`);return`#`+t.slice(1,4).map(e=>Number(e).toString(16).padStart(2,`0`)).join(``)}const zx={fg:Rx(Fx),bg:Rx(Ix)},Bx={fg:Rx(`\x1B[38;2;0;0;0m`),bg:Rx(`\x1B[48;2;220;160;40m`)},Vx=new zd({"strip.separator":`default`,"strip.rail":`default`});function Hx(e){return Vx.resolve(e)}const Ux={kind:`still`},Wx=e=>If.at(e.timeline,e.wall),Gx=Symbol(`bar`);function Kx(e){return e.name!==Pv}function qx(e){return t=>U.map(U.all(e.map(({timeline:e,effect:n})=>If.run(e,n(t)))),e=>(t,n)=>e.reduce((e,t)=>t(e,n),t))}const Jx=Uu;function Yx(e,t){let n=new kl(t,Jx.foregroundColor,Jx.ansiColors,Jx.palette);return t=>e({...t,theme:n})}function Xx(e,t){return n=>Ym(()=>e(n),...t)(n)}function Zx(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619)>>>0;return t/4294967296}const Qx=4096;function $x(e,t,n){let r=(n,{terminal:r})=>({...n,bg:r.bg?n.bg:e,fg:r.fg?n.fg:r.bg?e:t}),i=e=>e,a=Tb.reduceRight((e,{lit:t,seconds:n})=>U.sequence(U.constant(t?r:i),n,e),U.constant(i)),o=U.sequence(U.constant(i),n,a);return()=>o}var eS=class{inForce=null;anchor=If.play(0);placements=new Map;made=new Map;passages=null;frame={effect:Pv,t:0,speed:1,made:0,reused:0,own:[],basis:`off`,revision:0,fades:[],leaves:[]};constructor(e){this.key=e}lastFrame(){return this.frame}get heldCount(){let e=this.passages?.size??0;return[...this.made.values()].reduce((e,t)=>e+t.size,e)}clockAt(e,t){return{wall:e,timeline:If.withRate(this.anchor,e,t)}}motion(e,t,n,r=null){let i=Wx(t),a=e=>If.seek(t.timeline,t.wall,e),o=this.inForce?.name===e?this.inForce:{name:e,since:i},s={scope:Gx,name:e,t:i-o.since},c=this.placements,l=new Map,u=this.made,d=new Map,f=[],{last:p}=n,m=this.passages,h=n.transitions?m!==null&&p!==null?`compared`:`fresh`:`off`,g=h===`compared`?e=>{let t=p.placements.get(e);return t?.kind===`drew`?{drawing:t.drawing,passage:m.get(e)??null}:void 0}:null,_=new Set,v=new Map,y=[],b=[],ee={effect:e,t:s.t,speed:t.timeline.rate,made:0,reused:0,own:f,basis:h,revision:n.source.revision,fades:y,leaves:b},x=(e,t,{ground:n})=>{let r=fg.transitions[e]({z:Zx(`${this.key}@${t}`)*Qx});return{name:e,since:i,done:e=>r.done(e),effect:Yx(r.effect,n)}},S=({since:e,done:t})=>t(i-e),te=(e,t,n)=>({drawing:t,passage:g===null?null:n===void 0||n.passage?.name===`dissolve`?x(`fade`,e,t):n.passage!==null&&!S(n.passage)?n.passage:null}),C=(e,t)=>{if(t===void 0||t.drawing.opened||t.drawing.own.length===0)return;if(t.passage?.name===`dissolve`)return S(t.passage)?void 0:t;let r={...t.drawing,own:t.drawing.own.map(n.hold)};return{drawing:r,passage:x(`dissolve`,e,r)}},ne=(e,t)=>{if(_.has(e))throw Error(`placement "${e}" was reached twice in one frame`);_.add(e);let r=g?.(e),{drawing:a,deeper:o}=n.returned(e,t),s=a===null?C(e,r):te(e,a,r);return s===void 0?t:(s.passage!==null&&(v.set(e,s.passage),(s.passage.name===`fade`?y:b).push({placement:e,t:i-s.passage.since})),a===null?[...s.drawing.own,...o]:t)},re=(e,t)=>{let n=l.get(e)??c.get(e),r=n?.name===t?n:{name:t,since:i},a=i-r.since;return l.has(e)||(l.set(e,r),f.push({placement:e,effect:t,t:a})),{scope:e,name:t,t:a}},ie=(e,t)=>{let n=d.get(e)??new Map;d.set(e,n);let r=n.get(t.scope);if(r!==void 0)return r.effect;let i=u.get(e)?.get(t.scope),a=i?.name===t.name,o=Zx(t.scope===Gx?e:`${e}@${t.scope}`),s=a?i.effect:fg.loops[t.name]({z:o*Qx});return ee[a?`reused`:`made`]++,n.set(t.scope,{name:t.name,effect:s}),s},ae=e=>{let t=new Map;for(let{owner:n,placement:r}of e){let e=r.effect===`bar`?s:re(r.id,r.effect),i=t.get(e.scope);i===void 0?t.set(e.scope,{...e,owners:[n]}):i.owners.push(n)}return[...t.values()]},w=e=>{let t=new Map;for(let{owner:n,placement:r}of e){let e=t.get(r.id);e===void 0?t.set(r.id,[n]):e.push(n)}return[...t].flatMap(([e,t])=>{let n=v.get(e)??null;return n===null?[]:[{timeline:a(i-n.since),effect:Ym(n.effect,...t)}]})},oe=r===null?[]:[{timeline:If.play(r.idleSince),effect:$x(r.fill,r.text,Db(r.timeoutS))}],se=e=>e===`menu`?oe:[];return{placed:h===`off`?(e,t)=>t:ne,row:(e,n,r)=>{let i=(r.some(e=>e.placement.effect!==`bar`)?ae(r):[{...s,owners:void 0}]).filter(Kx),o=w(r),c=se(n);if(i.length===0&&o.length===0&&c.length===0)return Ux;let l=`${this.key}#${e}`;return{kind:`moving`,time:t.wall,wrap:e=>new zm(e,qx([...i.map(e=>{let t=ie(l,e);return{timeline:a(e.t),effect:e.owners===void 0?t:Xx(t,e.owners)}}),...o,...c]),{key:l,theme:Jx})}},drawn:()=>{this.anchor=t.timeline,this.inForce=o,this.placements=l,this.made=d,this.passages=h===`off`?null:v,this.frame=ee}}}},tS=class{sessions=new Map;constructor(e=256){this.maxSessions=e}of(e){let t=this.sessions.get(e)??new eS(e);this.sessions.delete(e),this.sessions.set(e,t);for(let e of this.sessions.keys()){if(this.sessions.size<=this.maxSessions)break;this.sessions.delete(e)}return t}getStats(){let e=0;for(let t of this.sessions.values())e+=t.heldCount;return{sessions:this.sessions.size,effects:e}}};function nS(e,t){let n=sl(t.colorSystem),{time:r}=t,i=1/0,a=[...df(e,{maxWidth:t.width??80,isTerminal:!1,asciiOnly:!1,theme:Vx,colorSystem:n.colorSystem,...r===void 0?{}:{frame:{time:r,host:{frameTime:r}}},onStyleError:e=>{throw e},onHold:({nextChange:e})=>{i=Math.min(i,e)}})];return{text:Cm(a,n),nextChange:Math.min(H.nextChange(a),i)}}const rS=new Map;function iS(e){let t=rS.get(e);if(t!==void 0)return t;let n=t=>({seam:t.seam.map(t=>`cap`in t?t:{...t,glyph:e})}),{seam:r,caps:i}=Sm.plain,a=new Kp({glyph:n(r.glyph),ascii:r.ascii},i);return rS.set(e,a),a}function aS(e,t){return e===`plain`&&t!==void 0?iS(t):Sm[e]}const oS=new Map;function sS(e){let t=JSON.stringify([e.endcaps,e.separator??null]),n=oS.get(t);if(n!==void 0)return n;let r=aS(e.endcaps,e.separator),i=e=>new W(`x`,{end:``,overflow:`ignore`,style:new V({bgcolor:e})}),a=e=>new W(nS(new hp(e,r),{colorSystem:null}).text.replace(/\n$/,``)).cellLength,o=a([i(`#101010`)]),s={chrome:o-1,seam:a([i(`#101010`),i(`#202020`)])-o-1};return oS.set(t,s),s}function cS(e){return sS(e).chrome}function lS(e){return sS(e).seam}const uS=/[\u{E000}-\u{F8FF}\u{F0000}-\u{FFFFD}\u{100000}-\u{10FFFD}]/gu;function dS(e){return[...new Set(e.match(uS)??[])].join(``)}function fS(e){let t=aS(e.endcaps,e.separator),n=e=>new W(`x`,{end:``,style:new V({bgcolor:e})});return dS(nS(new hp([n(`#101010`),n(`#202020`)],t),{colorSystem:null}).text)}function pS(e,t,n=Ux){if(e.length===0)return{text:``,nextChange:1/0};let r=aS(t.endcaps,t.separator),i=t.wrap&&Number.isFinite(t.width),a={colorSystem:t.colorCompatibility,...i?{width:t.width}:{}},o=i?new Gg([...e],{joiner:r}):new hp([...e],r),s=n.kind===`still`?nS(o,a):nS(n.wrap(o),{...a,time:n.time});if(!s.text.endsWith(`
60
60
  `))throw Error(`drawStripCells: rich-js strip output did not end its last line`);return{text:s.text.slice(0,-1),nextChange:s.nextChange}}function mS(e,t){return pS(e,t).text}const hS={level:`error`,glyph:`⚠`,colors:zx},gS={level:`warning`,glyph:`⚠`,colors:Bx},_S={level:`warning`,glyph:`⬆`,colors:Bx},vS={level:`warning`,glyph:`🔒`,colors:Bx},yS={level:`warning`,glyph:`🧪`,colors:Bx};function bS(e,t){return{text:Nx(e),link:t}}function xS(e,t,n,r,i){let a=new Set,o=(e,t)=>{let n=SS(e,t);for(let e of n)a.add(e);return n},s=[...n.flatMap(e=>o(e,hS)),...r,...i.flatMap(e=>o(e,gS))],c=CS(s);return s.map((n,r)=>a.has(n)?{...n,lines:[[bS(n.lines[0][0].text,wS(e,t,c[r]))],...n.lines.slice(1)]}:n)}function SS({about:e,text:t,copy:n},r){let[i,...a]=t.split(/\r\n|\r|\n/).map(e=>bS(e,null)).filter(e=>e.text!==``).map(e=>[e]);return i===void 0?[]:[{severity:r,about:e,message:t,copy:n,lines:[i,...a]}]}function CS(e){return ES(e).map(e=>String(e*TS+1))}function wS(e,t,n){return Ri([{verb:Pi,args:[e,t,n]}])}function Iee(e){return e.length===0?null:e.some(e=>e.severity.level===`error`)?`error`:`warning`}const TS=4096;function Lee(e){let t=C(`sha256`).update(`${e.severity.level}\0${e.severity.glyph}\0${e.about}`).digest(`hex`);return Number.parseInt(t.slice(0,9),16)%2**32}function ES(e){let t=new Map;return e.map(e=>{let n=Lee(e),r=t.get(n)??0;return t.set(n,r+1),n*256+Math.min(r,255)})}function DS(e,t,n){return String(ES(e)[t]*TS+n+1)}const OS={error:zx,warning:Bx};function kS(e){let t=Iee(e),n=e.length,r=OS[t??`warning`];return{label:t===null?``:`⚠ ${n>9?`9+`:n}`,fg:r.fg,bg:r.bg,open:e.length===0?AS:DS(e,0,0)}}const AS=`0`;function jS(e,t){let n=Number(e)-1,r=ES(t).indexOf(Math.floor(n/TS));return e===null||r===-1?null:{index:r+1,page:n%TS}}function MS(e,t){return Math.min(20,e??20,...t)}function NS(e,t,n,r,i){let{index:a}=t,o=e[a-1],s=IS(i),c=RS(o,s,[]),l=new V({bgcolor:o.severity.colors.bg,color:o.severity.colors.fg}),u=e=>FS(n,e),d=(e,t)=>LS(e,t===null?l:l.withLink(t)),f=(t,n)=>n===null?d(` `,null):d(t,u(DS(e,n.index-1,n.page))),p=(t,i)=>{let o=i>0?{index:a,page:i-1}:a>1?{index:a-1,page:0}:null,c=i<t-1?{index:a,page:i+1}:a<e.length?{index:a+1,page:0}:null,l=e.length>1||t>1,p=t>1?`[${a}/${e.length} ${i+1}/${t}]`:`[${a}/${e.length}]`;return mS([d(`✕`,u(`0`)),...l?[f(`‹`,o)]:[],d(p,null),...l?[f(`›`,c)]:[],d(`⧉ copy`,wS(n,r,DS(e,a-1,0)))],s)},m=1;for(;;){let e=Math.max(1,i.rows-m),n=Math.min(TS,Math.ceil(c.length/e)),r=Math.min(t.page,n-1),a=p(n,r),o=a.split(`
61
61
  `).length;if(o>m){m=o;continue}let l=c.slice(r*e,(r+1)*e),u=c.length-(r+1)*e;return[a,...r===n-1&&u>0?[...l.slice(0,-1),mS([d(`… ${u+1} more rows: ⧉ copy has them all`,null)],{...s,wrap:!1})]:l].join(`
62
62
  `)}}function PS(e,t,n,r){let{label:i,fg:a,bg:o,open:s}=kS(t),c=i===``?[]:[LS(i,new V({bgcolor:o,color:a}).withLink(FS(n,s)))];return RS(e,IS(r),c).join(`
@@ -179,7 +179,7 @@ Config tooling:
179
179
  running daemon; none spawn one.)
180
180
 
181
181
  `,MP=`readableOn (mix (color "foreground") (bgOf) 60) (bgOf) 3`,NP=[`moves`,`can-move`,`still`];function PP(e){let t=e.context_window?.current_usage;return t===null?`no`:t===void 0?`unknown`:`yes`}const FP=[`carried`,`missing`,`unanswered`];function IP(e){let t=e.rate_limits;return t?.five_hour!=null||t?.seven_day!=null?`carried`:PP(e)===`no`?`unanswered`:`missing`}function LP(e){return{path:e.transcript_path,answered:PP(e)===`yes`}}const RP=[...NP,`failed`,`drawing`],zP=[`statusline`,`frames`],BP=e=>e?.kind===`frames`?`frames`:`statusline`;var VP=class{seen=new Map;see(e,t,n,r){let i=BP(t.client),a=JSON.stringify([e,i]),o=this.seen.get(a);o!==void 0&&o.order>r||(this.seen.delete(a),this.seen.set(a,{sessionId:e,said:{...t,role:i},at:n,order:r}),this.seen.size>64&&this.seen.delete(this.seen.keys().next().value))}list(e){return[...this.seen.values()].map(({sessionId:t,said:n,at:r})=>({...n,sessionId:t,ago:e-r}))}ofSession(e,t){return this.list(t).filter(t=>t.sessionId===e)}};const HP={kitty:{label:`kitty`,xtversion:`kitty`,program:null,programVersion:!0,term:`xterm-kitty`,links:{since:`0.19.0`},glyphs:{kind:`bundled`,since:`0.36.0`}},wezterm:{label:`WezTerm`,xtversion:`WezTerm`,program:`WezTerm`,programVersion:!0,term:`wezterm`,links:{since:null},glyphs:{kind:`bundled`,since:`20230712`}},ghostty:{label:`Ghostty`,xtversion:`ghostty`,program:`ghostty`,programVersion:!0,term:`xterm-ghostty`,links:{since:null},glyphs:{kind:`bundled`,since:null}},iterm2:{label:`iTerm2`,xtversion:`iTerm2`,program:`iTerm.app`,programVersion:!0,term:null,links:{since:`3.1`},glyphs:{kind:`configured`}},alacritty:{label:`Alacritty`,xtversion:`alacritty`,program:null,programVersion:!0,term:`alacritty`,links:{since:`0.11.0`},glyphs:{kind:`configured`}},"apple-terminal":{label:`Terminal`,xtversion:null,program:`Apple_Terminal`,programVersion:!0,term:null,links:null,glyphs:{kind:`unread`}},vscode:{label:`VS Code`,xtversion:null,program:`vscode`,programVersion:!1,term:null,links:{since:`1.72`},glyphs:{kind:`unread`}}},UP=e=>HP[e];function WP(e){return UP(e).glyphs.kind===`bundled`}function GP(e){return UP(e).glyphs.kind===`configured`}const KP=e=>UP(e).label,qP=[{since:`3.5.0`,from:57504,to:57507},{since:`3.5.0`,from:57520,to:57554},{since:`3.5.0`,from:57556,to:57556},{since:`3.5.6`,from:57558,to:57559}];function JP(e,t){let n=t.codePointAt(0);return qP.some(({since:t,from:r,to:i})=>r<=n&&n<=i&&e!==null&&ZP(e,t)===!0)}const YP=Object.keys(HP);function XP(e){let t=/^\d+(?:\.\d+)*/.exec(e);return t===null?null:t[0].split(`.`).map(Number)}function ZP(e,t){let n=XP(e),r=XP(t);if(n===null)return null;for(let e=0;e<Math.max(n.length,r.length);e++){let t=n[e]??0,i=r[e]??0;if(t!==i)return t>i}return!0}function QP(e){for(let t of YP){let n=UP(t).xtversion;if(n!==null&&e.toLowerCase().startsWith(n.toLowerCase())){let r=e.slice(n.length).replace(/^[\s(]+/,``);return{name:t,version:/^[^\s)]+/.exec(r)?.[0]??null}}}return null}function $P(e){let t=YP.find(t=>UP(t).term===e);return t===void 0?null:{name:t,version:null}}function eF(e){let t=QP(e.termtype)??$P(e.termname);if(t!==null)return{kind:`known`,terminal:t};let n=/^[^\s(]*/.exec(e.termtype)[0];return n===``?{kind:`unnamed`,term:e.termname}:{kind:`unknown`,called:n}}function tF(e){let t=e.TERM_PROGRAM,n=YP.find(e=>UP(e).program===t),r=n===void 0?$P(e.TERM):{name:n,version:UP(n).programVersion?e.TERM_PROGRAM_VERSION??null:null};return r===null?t===void 0||t===`tmux`?{kind:`unnamed`,term:e.TERM??``}:{kind:`unknown`,called:t}:{kind:`known`,terminal:r}}function nF(e){switch(e.kind){case`known`:return KP(e.terminal.name);case`unknown`:return e.called;case`unnamed`:return e.term||null}}function rF(e){switch(e.kind){case`known`:return KP(e.terminal.name);case`unknown`:return e.called;case`unnamed`:return e.term||`this terminal`}}function iF({name:e,version:t}){let n=UP(e).links;if(n===null)return{kind:`none`};if(n.since===null)return{kind:`draws`};if(t===null)return{kind:`unsaid`,since:n.since};let r=ZP(t,n.since);return r===null?{kind:`unsaid`,since:n.since}:r?{kind:`draws`}:{kind:`older`,since:n.since,version:t}}const aF=YP.filter(e=>UP(e).links!==null).map(KP).join(`, `);function oF(e){if(e.kind===`failed`)return{kind:`unread`,reason:e.reason};let t=e.value.flatMap(({scope:e,path:t,settings:n})=>`statusLine`in n?[{from:{scope:e,path:t},line:n.statusLine}]:[]),n=t[0];if(n===void 0)return{kind:`absent`,read:e.value.map(e=>e.path)};if(!No(n.line))return{kind:`not-an-object`,value:n.line,from:n.from};for(let{from:e,line:r}of t){if(e.scope!==n.from.scope||!No(r))break;if(`refreshInterval`in r)return{kind:`present`,refreshInterval:r.refreshInterval,from:e}}return{kind:`present`,refreshInterval:void 0,from:n.from}}function sF(e,t){if(e.kind===`failed`)return e;let n=e.value.find(e=>Object.hasOwn(e.env,t));return{kind:`ok`,value:n===void 0?{kind:`unset`}:{kind:`set`,value:n.env[t],from:{scope:n.scope,path:n.path}}}}const Kee=[`managed`,`project`],qee=e=>!Kee.includes(e.scope),Jee={managed:()=>null,"project-local":e=>({scope:`project-local`,path:e}),project:(e,t)=>({scope:`project-local`,path:Ao(t.projectDir)}),user:e=>({scope:`user`,path:e})},cF=[`drawn`,`boxes`],lF=1024*1024,uF=e=>e.kind===`session`?`session ${e.sessionId}'s statusline client`:`this command's terminal`;function Yee(e){switch(e.kind){case`claude-settings`:return`${e.kind} ${e.path.join(`.`)}=${JSON.stringify(e.value)} file=${JSON.stringify(e.file.path)} scope=${e.file.scope}`;case`post-mortems-read`:return`${e.kind} through=${e.through}`}}function dF(e){let[t,...n]=e;return t===void 0?{ok:!0}:{ok:!1,reason:t,more:n}}const fF=Ds.truecolor;function pF(e,t){switch(e.kind){case`unreported`:return{ok:!1,reason:"the client reported no tmux facts — re-run `cc-candybar install` to stage a current client"};case`outside`:return{ok:!0};case`inside`:return e.client.kind===`failed`?{ok:!1,reason:`tmux could not be asked: ${e.client.reason}`}:e.client.value===null?{ok:!0}:t(e.client.value,e.hint)}}const Xee={name:`tmuxTruecolor`,label:`tmux truecolor`,takesMark:!1,probe:({tmux:e,claudeSettings:{origin:t}})=>pF(e,(e,n)=>{if(!e.features.includes(`RGB`)||n.truecolor!==null)return{ok:!0};let r=sF(t.sources,fF);if(r.kind===`failed`)return{ok:!1,reason:r.reason};let i=r.value;if(i.kind===`set`&&typeof i.value==`string`&&i.value!==``)return{ok:!1,reason:`${fF} is set in ${i.from.path} — restart Claude Code to apply`};let a=`Claude Code renders the bar in 256 colours inside tmux`,o=e=>({ok:!1,reason:a,fix:{kind:`claude-settings`,file:e,path:[`env`,fF],value:`1`}});if(i.kind===`unset`)return o({scope:`user`,path:t.at.userFile});let s=Jee[i.from.scope](i.from.path,t.at);return s===null?{ok:!1,reason:`${a} — the value that counts is in managed settings, ${i.from.path}: set ${fF} to "1" there`}:o(s)})},Zee={name:`utf8`,label:`UTF-8`,takesMark:!1,probe:({tmux:e})=>pF(e,e=>e.utf8?{ok:!0}:{ok:!1,reason:"tmux draws this terminal without UTF-8, so every glyph on the bar arrives as `_` — attach with `tmux -u`, or set a UTF-8 LC_ALL/LC_CTYPE/LANG in the shell that runs tmux"})},Qee={name:`termWidth`,label:`terminal width`,takesMark:!1,probe:({width:e})=>e.kind===`failed`?{ok:!1,reason:e.reason}:e.value.columns===null?{ok:!1,reason:`${uF(e.value.of)} measured no width (no COLUMNS, and no terminal to ask — or the daemon refused the width sent, which the bar's diagnostics name), so the bar is laid out as if the terminal were 120 columns wide`}:{ok:!0,note:`${e.value.columns} columns, as ${uF(e.value.of)} measured`}},$ee={variable:`is never read`,action:`is never clicked`,helper:`is never called`,segment:`is in no preset`},ete={name:`config`,label:`config`,takesMark:!1,probe:({config:e})=>{switch(e.kind){case`failed`:{let[t=`the config failed to load`,...n]=[...e.error.split(`
182
- `).map(e=>e.trim()).filter(e=>e!==``),...e.warnings];return{ok:!1,reason:t,more:n}}case`loaded`:return dF([...e.warnings,...e.unused.map(({kind:e,name:t})=>`${e} "${t}" ${$ee[e]}`)])}}},mF="re-run `cc-candybar install`";function tte(e){if(e.kind===`failed`)return[`Launch Services could not be asked which app opens cc-candybar:// — ${e.reason}`];if(e.value===null)return[`no app is registered for cc-candybar:// — ${mF}`];let{app:t,missing:n}=e.value;return n.kind===`failed`?[`${t} opens cc-candybar://, but ${n.reason} — ${mF}`]:n.value.map(e=>`${e} is missing, and ${t} runs it — ${mF}`)}const nte={name:`urlHandler`,label:`URL handler`,takesMark:!1,probe:({urlHandler:e})=>{switch(e.kind){case`unsupported`:return{ok:!0};case`unprobed`:return{ok:!1,reason:e.reason};case`arrived`:return e.handler===e.bar?{ok:!0}:{ok:!1,reason:e.handler===null?`the URL handler does not report its version, so it is older than the bar (${e.bar}) — ${mF}`:`the URL handler runs cc-candybar ${e.handler}; the bar runs ${e.bar} — ${mF}`};case`lost`:return dF([...tte(e.opener),e.unopened===null?`a cc-candybar:// link was opened and did not arrive at the daemon`:`a cc-candybar:// link could not be opened — ${e.unopened}`])}}};function hF({bundle:e,checkout:t},n){return{bundle:n.bundle.kind===`failed`?{kind:`unresolved`,reason:n.bundle.reason}:n.bundle.value===e?{kind:`same`}:{kind:`other`,path:n.bundle.value},source:n.client!==`native`||t===null?{kind:`uncompared`}:t.rustSource.kind===`failed`?{kind:`unreadable`,root:t.root,reason:t.rustSource.reason}:n.source===null?{kind:`unstamped`}:n.source===t.rustSource.value?{kind:`same`}:{kind:`other`,root:t.root}}}function gF(e,t){return t===`frames`?`run \`node ${e.bundle} frames --lane <${_b.join(`|`)}>\``:e.checkout===null?mF:`run \`just install-rust\` and point the statusLine command at ${e.checkout.root}/bin/cc-candybar-native`}function rte(e,t,n){let{checkout:r}=e;if(n.kind===`unreported`)return[`the bar is drawn by a statusline client too old to say what it is — ${gF(e,`native`)}`];let{bundle:i,source:a}=hF(e,n);switch(i.kind){case`unresolved`:return[`the statusline client's bundle cannot be resolved: ${i.reason}`];case`other`:return[`the statusline client runs ${i.path}, not the daemon's ${e.bundle} — ${gF(e,n.client)}`];case`same`:break}if(n.client===`node`&&(t||r!==null))return[`the bar is drawn by the Node fallback, which starts node on every render — ${gF(e,`native`)}`];switch(a.kind){case`uncompared`:case`same`:return[];case`unreadable`:return[`${a.root}/rust-client could not be read: ${a.reason}`];case`unstamped`:return["the native client carries no source stamp, so which source it was built from is unknown — run `just install-rust`"];case`other`:return[`the native client was built from other source than ${a.root}/rust-client holds — run \`just install-rust\``]}}const _F=e=>{let t=`restarted since the bar was drawn, or has served 64 newer sessions`;return e.kind===`clicked`?`this daemon holds no render of this bar (it ${t})`:`this daemon holds no render of session ${e.sessionId}'s bar (its statusLine does not run cc-candybar — a \`claude -p\` session draws none — or the daemon ${t}; unset CLAUDE_CODE_SESSION_ID to judge every bar drawn recently)`},ite={name:`install`,label:`install`,takesMark:!1,probe:({install:e,sighted:t})=>{if(e.kind===`failed`)return{ok:!1,reason:`the daemon could not be asked which clients draw the bar: ${e.reason}`};let{daemon:n,nativeShipped:r,clients:i}=e.value;return i.length===0?{ok:!1,reason:t.kind===`recent`?`no statusline client has drawn a bar for this daemon in the last ${300/60} minutes — run the doctor again once the bar has redrawn; if it never does, the statusLine command does not run cc-candybar`:`${_F(t)}, so which client draws it is unknown — run the doctor again once the bar has redrawn`}:dF([...new Set(i.flatMap(e=>rte(n,r,e)))])}};function vF({postMortems:e},t){return e.kind===`ok`&&t.kind===`ok`?e.value.filter(e=>t.value.through===null||Ar(e.identity,t.value.through)):[]}function yF(e,t){return e.kind===`failed`?t:t.filter(t=>t.pid!==e.value.pid)}const ate={name:`daemon`,label:`daemon`,takesMark:!1,probe:({daemon:{serving:e,processes:t,read:n}})=>{let r=t.kind===`failed`?[`the process table could not be read: ${t.reason}`]:[],i=t.kind===`ok`?yF(e,t.value):[];if(e.kind===`failed`){let t=i.length>0?` — daemon ${i.map(e=>e.pid).join(`, `)} running`:``;return dF([`${e.reason}${t}`,...r])}let{pid:a,memory:o,limit:s,postMortems:c}=e.value,l=vF(e.value,n),u=dF([...l.map(e=>`the daemon ran out of memory and restarted (${e.identity}) — post-mortem: ${Object.values(e.artifacts).join(`, `)}`),...c.kind===`failed`?[`the daemon's post-mortems could not be listed: ${c.reason}`]:[],...n.kind===`failed`&&!(c.kind===`ok`&&c.value.length===0)?[`which post-mortems were read could not be read: ${n.reason}`]:[],...r,...i.map(e=>`daemon ${e.pid} (started ${e.started}, rss ${Dr(e.rss)} MB${e.ppid===1?``:`, child of ${e.ppid}`}) runs beside the one serving the bar (${a}) — \`kill ${e.pid}\``),...o.kind===`measured`&&o.charge.kind===`stand-in`?[`the daemon could not read what macOS charges it (${o.charge.unread}), so its memory limit judges ${o.charge.gap===0?`RSS, which counts pages macOS has reclaimed`:`RSS less the ${Dr(o.charge.gap)} MB it last ran over that charge, an estimate`}`]:[],...o.kind===`measured`&&Nr(o.charge.bytes,s)?[`the daemon holds ${Lr(o.charge)} of its ${Dr(s)} MB limit — at the limit it records a post-mortem and restarts`]:[]]);if(u.ok&&o.kind===`unmeasured`)return{ok:!0,note:`the daemon has not measured its memory yet`};let d=l[0];return u.ok||d===void 0?u:{...u,fix:{kind:`post-mortems-read`,through:d.identity}}}},bF=`click 🩺 doctor in the bar's settings menu: if it runs, links work`;function ote(e,t){let n=nF(e);return t.kind===`ok`&&n!==null&&t.value.includes(n)?{kind:`draws`}:e.kind===`known`?iF(e.terminal):{kind:`unknown`}}function ste({identified:e,tmuxClient:t},n){let r=rF(e),i=ote(e,n),a=nF(e)===null?bF:`${bF}, and the doctor remembers it for this terminal`,o=(()=>{switch(i.kind){case`draws`:return[];case`none`:return[`${r} draws no links (OSC 8), so nothing on the bar can be clicked — run Claude Code in a terminal that draws them: ${aF}`];case`older`:return[`${r} ${i.version} draws no links (OSC 8 came in ${i.since}) — update ${r}`];case`unsaid`:return[`${r} draws links (OSC 8) since ${i.since}, and did not say which release this is — ${a}`];case`unknown`:return[`the doctor does not know whether ${r} draws links (OSC 8) — ${a}`]}})(),s=n.kind===`failed`&&i.kind!==`draws`?[`the terminals a doctor click came back from could not be read: ${n.reason}`]:[],c=i.kind===`none`||t===null||t.features.includes(`hyperlinks`)?[]:[`tmux does not pass links through to ${r} — add \`set -as terminal-features ",${t.termname}:hyperlinks"\` to tmux.conf, then detach and reattach (tmux 3.4 or later)`];return[...o,...s,...c]}const cte={name:`links`,label:`links`,takesMark:!1,probe:({sighted:e,terminal:t,clicked:n})=>{if(e.kind===`clicked`&&e.via===`link`)return{ok:!0};switch(t.kind){case`unreported`:return{ok:!1,reason:"the client reported no terminal — re-run `cc-candybar install` to stage a current client"};case`unasked`:return{ok:!1,reason:`tmux could not be asked which terminal is attached: ${t.reason}`};case`seen`:return dF(ste(t,n))}}},xF=e=>e.filter(e=>e.role===`statusline`),lte={name:`effectRefresh`,label:`effect refresh`,takesMark:!1,probe:({frames:e,claudeSettings:{origin:t,elsewhere:n},sighted:r})=>{let i=[t,...n].flatMap(({sources:e,bars:t})=>dte(e,ute(t))??[]),[a]=i;if(a===void 0)return e.kind===`failed`?{ok:!1,reason:e.reason}:SF(r.kind===`recent`?`no session has drawn a statusline for this daemon in the last ${300/60} minutes`:_F(r));let[o,...s]=i.flatMap(e=>e.ok?[]:[e]);if(o===void 0)return a;let c=[...new Set(s.map(e=>e.reason))].filter(e=>e!==o.reason);return c.length===0?o:{...o,more:c}}},ute=e=>{let t=xF(e).map(e=>e.frame);return t.includes(`moves`)?{kind:`moving`,wearing:`the bar moves (an effect, a fade, an animated segment, or an open menu counting down to its close)`}:t.includes(`can-move`)?{kind:`moving`,wearing:`the bar can start moving (an open menu, which flashes and closes on its own, a globals.effect rule, placements that fade in and out, or a placement with an effect of its own that is not drawn now)`}:t.includes(`still`)?{kind:`still`}:t.includes(`drawing`)?{kind:`unknown`,unseen:`the bar's latest render has not finished`}:t.length>0?{kind:`unknown`,unseen:`the bar's recent renders failed`}:e.length>0?{kind:`unknown`,unseen:"only a `cc-candybar frames` display has drawn this bar, not Claude Code's statusline"}:{kind:`none`}},SF=e=>({ok:!1,reason:`${e}, so whether it moves is unknown — run the doctor again once the bar has redrawn`});function dte(e,t){let n=oF(e);if(n.kind===`present`&&n.refreshInterval===1)return{ok:!0,note:`statusLine.refreshInterval is 1 in ${n.from.path}`};switch(t.kind){case`none`:return null;case`still`:return{ok:!0};case`unknown`:return SF(t.unseen);case`moving`:break}let{wearing:r}=t;switch(n.kind){case`unread`:return{ok:!1,reason:`${r}, and Claude Code's settings could not be read: ${n.reason}`};case`absent`:return{ok:!1,reason:`${r}, and no settings file Claude Code reads here sets a statusLine (read: ${n.read.join(`, `)||`none`}) — the one that runs the bar comes from --settings, MDM or server-managed settings, which the doctor cannot read; set "refreshInterval": 1 beside its command there`};case`not-an-object`:return{ok:!1,reason:`${r}, and ${n.from.path} sets statusLine to ${JSON.stringify(n.value)}, not a statusLine object — ${n.from.scope===`user`?"re-run `cc-candybar install` to write one":`replace it there with the statusLine object that runs cc-candybar`}`};case`present`:{let{from:e,refreshInterval:t}=n,i=t===void 0?`its statusLine sets no refreshInterval, so Claude Code redraws it only on events`:typeof t==`number`&&t>1?`its statusLine redraws it only every ${t} s`:`its statusLine.refreshInterval is ${JSON.stringify(t)}, not a number of seconds Claude Code accepts (its minimum is 1)`;return qee(e)?{ok:!1,reason:`${r}, but ${i} (statusLine from ${e.path})`,fix:{kind:`claude-settings`,file:e,path:[`statusLine`,`refreshInterval`],value:1}}:{ok:!1,reason:`${r}, but ${i} — its statusLine is in ${e.scope===`managed`?`managed settings`:`the project's shared settings`}, ${e.path}: set "refreshInterval": 1 there`}}}}const CF=e=>[...e].map(e=>`U+${e.codePointAt(0).toString(16).toUpperCase()}`).join(` `);function fte(e){switch(e.kind){case`unreported`:case`unasked`:return`this terminal`;case`unknown`:case`unnamed`:return rF(e);case`bundling`:case`unread`:case`configured`:return[KP(e.name),e.version].filter(e=>e!==null).join(` `)}}function pte(e){switch(e.kind){case`unreported`:case`unasked`:return null;case`unknown`:case`unnamed`:return nF(e);case`bundling`:case`unread`:return KP(e.name);case`configured`:{let t=KP(e.name);return e.font.kind===`ok`?`${t} with ${e.font.value.font} (${e.font.value.from})`:`${t}, its font unread: ${e.font.reason}`}}}function wF(e){let t=pte(e.terminal);return t===null?void 0:{glyphs:e.glyphs,id:`${t}|${CF(e.glyphs)}`}}const mte={name:`nerdFont`,label:`Nerd Font`,takesMark:!0,probe:({nerdFont:e,marks:t})=>{if(e.kind===`none`)return{ok:!0};let n=wF(e),r=e=>t.kind===`failed`&&n!==void 0?{ok:!1,reason:e,more:[`the mark book could not be read: ${t.reason}`]}:{ok:!1,reason:e,...n!==void 0&&{sighting:n}},i=e.terminal,a=fte(i);switch(n===void 0||t.kind===`failed`?null:t.value.nerdFont?.[n.id]??null){case`drawn`:return{ok:!0};case`boxes`:return r(`${a} draws ${CF(e.glyphs)} as boxes — set a Nerd Font as its font`);case null:break}switch(i.kind){case`unreported`:return r("the client reported no terminal — re-run `cc-candybar install` to stage a current client");case`unasked`:return r(`tmux could not be asked which terminal is attached: ${i.reason}`);case`unknown`:case`unnamed`:case`unread`:return r(`the doctor cannot read ${a}'s font`);case`bundling`:{let e=HP[i.name].glyphs.since;if(e===null)return{ok:!0};let t=i.version===null?null:ZP(i.version,e);if(t===!0)return{ok:!0};let n=KP(i.name);return r(t===null?`${n} ships Nerd Font symbols since ${e}, and did not say which release this is`:`${a} ships no Nerd Font symbols (they came in ${e}) — update ${n}, or set a Nerd Font as its font`)}case`configured`:{if(i.font.kind===`failed`)return r(`the doctor cannot read ${a}'s font: ${i.font.reason}`);let{font:e,from:t,lacks:n}=i.font.value;return n===null?r(`${a} is set to ${e} (${t}), which is not installed — install it or set a Nerd Font`):n.length===0?{ok:!0}:r(`${a} draws with ${e} (${t}), which has no ${CF(n)} — set a Nerd Font as its font`)}}}};function TF(e){return e.join(`, `)}function EF(e){return`or set missingData: "ignore" on ${TF(e)}`}function hte(e){if(e.kind===`unneeded`)return[];let{segments:t,fact:n}=e;if(n.kind===`failed`)return[`${TF(t)}: whether the forge CLI is ready could not be asked: ${n.reason}`];if(n.value===null)return[];let{cli:r,host:i,status:a}=n.value;return a===`ready`?[]:a===`missing`?[`${TF(t)}: ${r} is not installed, so no pull request is ever shown — install it, ${EF(t)}`]:[`${TF(t)}: ${r} is not logged in to ${i} (${a.loggedOut}) — run \`${r} auth login --hostname ${i}\`, ${EF(t)}`]}function gte(e,t){if(e.kind===`unneeded`)return[];let{segments:n,fact:r}=e;return r.kind===`failed`?[`${TF(n)}: ${r.reason}`]:r.value.length===0?[t.kind===`recent`?`${TF(n)}: no session of this Claude Code has drawn a bar for this daemon in the last ${300/60} minutes, so whether it sends rate_limits is unseen — run the doctor again once the bar has redrawn`:`${TF(n)}: ${_F(t)}, so whether Claude Code sends rate_limits is unseen — run the doctor again once the bar has redrawn`]:r.value.includes(`missing`)&&!r.value.includes(`carried`)?[`${TF(n)}: Claude Code sent no rate_limits — it sends them only to Claude.ai subscription sessions; on any other account, set missingData: "ignore" on ${TF(n)}`]:[]}const _te={name:`segmentData`,label:`segment data`,takesMark:!1,probe:({data:e,sighted:t})=>dF([...hte(e.pullRequests),...gte(e.rateLimits,t)])};function vte({path:e,answered:t,read:n}){switch(n.kind){case`absent`:return t?[`the transcript ${e} does not exist, though Claude Code has answered in its session — the bar's session cost, metrics and activity read nothing`]:[];case`failed`:return[`the transcript ${e} cannot be read: ${n.reason}`];case`ok`:{let{lines:t,unparsed:r,whole:i}=n.value;return r===0?[]:[`${r} of the ${t} lines ${i?`in`:`in the last ${lF/1024/1024} MiB of`} the transcript ${e} are not JSON objects — the bar skips them, so what it counts from them is missing`]}}}const DF=[ete,ite,ate,nte,cte,Xee,Zee,Qee,lte,mte,_te,{name:`sessionData`,label:`session data`,takesMark:!1,probe:({transcripts:e,sighted:t})=>e.kind===`failed`?{ok:!1,reason:e.reason}:e.value.length===0?{ok:!1,reason:t.kind===`recent`?`no session has drawn a bar for this daemon in the last ${300/60} minutes, so no transcript was named — run the doctor again once the bar has redrawn`:`${_F(t)}, so which transcript it reads is unknown — run the doctor again once the bar has redrawn`}:dF(e.value.flatMap(vte))}],yte=DF.filter(e=>e.takesMark);function OF(e){return DF.map(t=>({check:t,verdict:t.probe(e)}))}function kF(e){return DF.find(t=>t.name===e)}const bte=`${q}doctor.`;function AF(e){let t=`${bte}${e}.`;return{verdict:`${t}verdict`,reason:`${t}reason`,fixable:`${t}fixable`,sighting:`${t}sighting`}}function xte(e,t){let n=e.kind===`seen`?e.tmuxClient:null,r=e.kind===`seen`?nF(e.identified):null,i=t.kind===`failed`?`unread`:r===null?`-`:t.value.includes(r)?`yes`:`no`;return`tmuxLinks=${n===null?`-`:n.features.includes(`hyperlinks`)?`yes`:`no`} clicked=${i}`}function Ste(e,t){let n=e.kind===`seen`?e.tmuxClient:null;return`cols=${t.kind===`failed`?`failed widthOf=-`:`${t.value.columns??`-`} widthOf=${t.value.of.kind}`} clientUtf8=${n===null?`-`:n.utf8?`yes`:`no`}`}function Cte(e){if(e.kind===`failed`)return`clients=unasked`;let{daemon:t,clients:n}=e.value;return`clients=${n.map(e=>{if(e.kind===`unreported`)return`unreported/-/-`;let{bundle:n,source:r}=hF(t,e);return`${e.client}/${n.kind}/${r.kind===`uncompared`?`-`:r.kind}`}).join(`,`)||`-`}`}const wte=e=>`${e>=0?`+`:``}${Dr(e)}`;function Tte({serving:e,processes:t,read:n}){let r=t.kind===`failed`?`daemons=unread others=-`:`daemons=${t.value.length} others=${yF(e,t.value).map(e=>e.pid).join(`,`)||`-`}`;if(e.kind===`failed`)return`${r} memory=unasked postMortems=unasked`;let{memory:i,limit:a,postMortems:o}=e.value,s=o.kind===`failed`||n.kind===`failed`?`unread`:`${vF(e.value,n).length}/${o.value.length}`;return`${r} memory=${i.kind===`unmeasured`?`unmeasured`:`${Rr(i.charge)}${i.charge.kind===`stand-in`?`(${wte(-i.charge.gap)})`:``}:${Dr(i.charge.bytes)}`}/${Dr(a)} postMortems=${s}`}function Ete(e){return`data=pr:${(()=>{if(e.pullRequests.kind===`unneeded`)return`-`;let t=e.pullRequests.fact;if(t.kind===`failed`)return`failed`;if(t.value===null)return`no-forge`;let{status:n}=t.value;return typeof n==`string`?n:`logged-out`})()},rateLimits:${(()=>{if(e.rateLimits.kind===`unneeded`)return`-`;let t=e.rateLimits.fact;if(t.kind===`failed`)return`failed`;let n=e=>t.value.filter(t=>t===e).length;return`${n(`carried`)}/${n(`missing`)}/${n(`unanswered`)}`})()}`}function Dte(e,{origin:t,elsewhere:n}){let r=[t,...n],i=r.map(({sources:e})=>Ote(e)).join(`,`);if(e.kind===`failed`)return`frames=failed chains=${I(i)}`;let a=xF(r.flatMap(e=>e.bars));return`frames=${RP.map(e=>a.filter(t=>t.frame===e).length).join(`/`)} chains=${I(i)}`}function Ote(e){let t=oF(e);switch(t.kind){case`unread`:return`failed`;case`absent`:case`not-an-object`:return t.kind;case`present`:return`${t.from.scope}:${t.refreshInterval===void 0?`-`:JSON.stringify(t.refreshInterval)}`}}function kte(e){let t=sF(e,fF);return t.kind===`failed`?`truecolorEnv=failed`:t.value.kind===`unset`?`truecolorEnv=unset`:`truecolorEnv=${I(`${t.value.from.scope}:${JSON.stringify(t.value.value)}`)}`}function Ate(e){if(e.kind===`failed`)return`transcripts=failed`;let t=t=>e.value.filter(e=>e.read.kind===t).length,n=e.value.reduce((e,t)=>e+(t.read.kind===`ok`?t.read.value.unparsed:0),0);return`transcripts=${t(`ok`)}/${t(`absent`)}/${t(`failed`)} unparsed=${n}`}function jte(e,t){if(e.kind===`none`)return`glyphs=- terminal=- font=- mark=-`;let{glyphs:n,terminal:r}=e,i=[...n].map(e=>e.codePointAt(0).toString(16)),a=(()=>{switch(r.kind){case`unreported`:case`unasked`:return r.kind;case`unknown`:return`unknown:${JSON.stringify(r.called)}`;case`unnamed`:return`unnamed:${JSON.stringify(r.term)}`;case`bundling`:case`unread`:case`configured`:return`${r.name}@${r.version??`-`}`}})(),o=(()=>{if(r.kind!==`configured`)return`-`;if(r.font.kind===`failed`)return`failed`;let{font:e,lacks:t}=r.font.value;return`${JSON.stringify(e)}:${t===null?`not-installed`:`lacks${t.length}`}`})(),s=wF(e),c=t.kind===`failed`?`unread`:s===void 0?`-`:t.value.nerdFont?.[s.id]??`-`;return`glyphs=${i.join(`,`)} terminal=${a} font=${o} mark=${c}`}function jF(e,t=[]){return t.length===0?e:`${e} (+${t.length} more — run \`cc-candybar doctor\`)`}function MF(e){return e.flatMap(({check:e,verdict:t})=>{let n=AF(e.name);return t.ok?[{key:n.verdict,value:`ok`},{key:n.reason,value:t.note??``},{key:n.fixable,value:$v},{key:n.sighting,value:``}]:[{key:n.verdict,value:`failed`},{key:n.reason,value:jF(t.reason,t.more)},{key:n.fixable,value:t.fix===void 0?$v:Qv},{key:n.sighting,value:t.sighting?.glyphs??``}]})}const NF={copySession:{copy:`{{ .session.id }}`},copyResume:{copy:`{{ .resume_command }}`},openProject:{open:`{{ .project_dir }}`},openTranscript:{open:`{{ .transcript_path }}`},openConfig:{open:`{{ .config_path }}`}};function PF(e){let t=t=>`${e}${t}`;return{template:`{{ action "${t(`copySession`)}" "⎘ id" }}{{ if ne .resume_command "" }} {{ action "${t(`copyResume`)}" "⎘ resume" }}{{ end }} {{ action "${t(`openProject`)}" "↗ proj" }} {{ action "${t(`openTranscript`)}" "↗ log" }}{{ if ne .git.repoUrl "" }} {{ link .git.repoUrl "↗ repo" }}{{ end }}{{ if ne .config_path "" }} {{ action "${t(`openConfig`)}" "↗ config" }}{{ end }}`,actions:Object.fromEntries(Object.entries(NF).map(([t,n])=>[`${e}${t}`,n]))}}const FF=`armed`,IF=`disarmed`,LF=`.armed`,RF=e=>e.endsWith(LF);function zF(e,t,n){let r=[...new Set(n.map(e=>e.when))].filter(e=>e!==`true`),i=t=>r.length===0?e:`${e}.${t}`,a={};for(let e=0;e<2**r.length;e++)a[i(e)]={do:[t,...n.filter(t=>t.when===`true`||e&1<<r.indexOf(t.when)).map(e=>e.action)]};let o=(e,t)=>e===r.length?`"${i(t)}"`:`(ternary ${o(e+1,t|1<<e)} ${o(e+1,t)} (${r[e]}))`;return{link:o(0,0),actions:a}}function BF(e,t,n){let r=`${e}${LF}`,i=`${e}.arm`,a=`${e}.disarm`,o=`(eq .${e} "${FF}")`,s=zF(e,a,n);return{template:`{{ if ${o} }}{{ action ${s.link} "${t.confirm}" }} {{ action "${a}" "✕" }}{{ else }}{{ action "${i}" "${t.arm}" }}{{ end }}`,actions:{[i]:{set:r,to:FF},[a]:{set:r,to:IF},...s.actions},armed:o,variables:{[e]:{kind:`state`,key:r,default:IF}},disarm:a}}const VF=RegExp(`^/[^\\s\\x00-\\x1f\\x7f-\\x9f/][^\\x00-\\x1f\\x7f-\\x9f]*$`);function HF(e){return typeof e==`string`&&VF.test(e)?{kind:`line`,line:e}:{kind:`refused`,reason:`a slash command is "/" then its name, e.g. "/compact" or "/model opus", on one line with no control characters, got ${JSON.stringify(e)}`}}function UF(e){let t=HF(e);if(t.kind===`refused`)throw Error(t.reason);return t.line}const WF=[`/compact`,`/model`],GF=`/clear`;function KF(e){let t=t=>`${e}${t.slice(1)}`,n=`${e}clear.slash`,r=BF(`${e}clear`,{arm:GF,confirm:`${GF} ✓ confirm`},[{action:n,when:`true`}]);return{template:WF.map(e=>`{{ action "${t(e)}" "${e}" }} `).join(``)+r.template,when:`{{ ${hb} }}`,actions:{...Object.fromEntries(WF.map(e=>[t(e),{slash:UF(e)}])),...r.actions,[n]:{slash:UF(GF)}},variables:r.variables,disarm:r.disarm}}const qF=Array.from({length:10},(e,t)=>(t+1)*1e5),JF=qF[0],YF=qF[qF.length-1];function XF(e){let t;try{t=Do(e)}catch(e){return F(e instanceof Error?e.message:String(e))}let n=t.autoCompactWindow;return n===void 0?N(`auto`):typeof n==`number`&&Number.isInteger(n)&&n>=JF&&n<=YF?N(n):F(`${e}: autoCompactWindow is ${JSON.stringify(n)}, not a window /autocompact accepts (${JF}–${YF} tokens)`)}function ZF(e,t){let n=Math.min(t??YF,YF),r=e===`auto`?n:Math.min(e,n);return{window:e===`auto`?0:e,applied:e===`auto`?0:r,lower:qF.filter(e=>e<r).at(-1)??0,higher:qF.find(e=>e>r&&e<=n)??0}}function QF(e,t){return{template:`{{ if ne .autocompact.error "" }}⇲ ⚠ {{ .autocompact.error }}{{ else }}⇲ {{ if eq .autocompact.window 0 }}auto{{ else }}${t(`.autocompact.applied`)}{{ end }}{{ if ${hb} }}{{ if gt .autocompact.lower 0 }} {{ action (printf "${e}%d" .autocompact.lower) "−" }}{{ end }}{{ if gt .autocompact.higher 0 }} {{ action (printf "${e}%d" .autocompact.higher) "+" }}{{ end }}{{ if gt .autocompact.window 0 }} {{ action "${e}auto" "↺" }}{{ end }}{{ end }}{{ end }}`,bg:`{{ if ne .autocompact.error "" }}{{ color "error" }}{{ else }}{{ tint }}{{ end }}`,when:`{{ or (ge .autocompact.window 0) (ne .autocompact.error "") }}`,actions:{[`${e}auto`]:{slash:UF(`/autocompact auto`)},...Object.fromEntries(qF.map(t=>[`${e}${t}`,{slash:UF(`/autocompact ${t}`)}]))}}}const $F=e=>`{{ if ge ${e} 1000000 }}{{ printf "%.1f" (divf ${e} 1000000) }}M{{ else if ge ${e} 1000 }}{{ printf "%.1f" (divf ${e} 1000) }}K{{ else }}{{ ${e} }}{{ end }}`,eI=`${q}edit`,tI=`${q}toolbar`,nI=PF(q),rI=`${q}commands`,iI=KF(`${rI}.`),aI=`${q}autocompact`,oI=QF(`${aI}.`,$F),sI=e=>({kind:`segment`,name:e}),cI=`${q}tab`,lI=e=>`${cI}.${e}`,uI=e=>`${lI(e)}.toggle`,dI=e=>({variable:cI,key:cI,member:e}),fI=`${q}save`,pI=`${q}preset.save`,mI=`${q}preset.delete`,hI=e=>`${q}${e}`,gI=e=>`${q}apply.${e}`,_I=e=>`${q}reset.${e}`,vI=`${q}themeDefault.save`,yI=`${q}themeDefault.differs`,bI=`${q}themeDefault.theme`,xI={when:`{{ .${yI} }}`,template:`{{ action "${vI}" (printf "⤓ default for %s" .${bI}) }} {{ swatch "${gI(`theme`)}" .${bI} }}`},SI=`${q}resetAll`,CI=`${Dx}.toggle`,wI=`${q}undo`,TI=`${q}back`,EI=`${TI}.step`,DI=`${q}navigation.back`,OI=TI,kI={template:`{{ if gt .${DI} 0 }}{{ action "${TI}" "◁" }}{{ else }}{{ fg (${MP}) "◁" }}{{ end }}`},AI=`${q}redo`,jI=`${q}doctor`,MI=`${jI}.run`,NI=e=>`${jI}.fix.${e}`,PI=(e,t)=>`${jI}.mark.${e}.${t}`,FI=e=>`${jI}.${e}`,II={drawn:`[✓ shapes]`,boxes:`[✗ boxes]`},LI=qM(`${q}pickers`),RI=e=>`${q}${e}`,zI=e=>`${RI(e)}.toggle`,BI=e=>fN(e)?qM(`${q}${e}Pickers`):LI,VI=e=>{let t=BI(dN[lN[e].beside]);return{variable:t,key:t,member:e}},HI={layout:{template:`{{ layoutPreview }}`},palette:{template:`{{ themePreview }}`},presetDelete:{when:`{{ not .preset.bundled }}`,template:`{{ action "${mI}" (printf "🚮 delete %s" .${nx.preset.effectiveVar}) }}`}},UI=(e,t)=>`${q}list.${e}.${t}`,WI=e=>`${q}resettable.${e}`,GI=e=>e.length===0?`false`:`(or ${e.map(e=>`(and (${e.shown}) .${WI(e.name)})`).join(` `)})`,KI=_b.map(e=>[gb[e].switch.setting,e]),qI={variables:{},actions:{},segments:{}},JI=Object.fromEntries(KI.map(([e,t])=>[e,_P(`${q}help.${e}`,AP[t],[],qI)])),YI=[`⠋`,`⠙`,`⠹`,`⠸`,`⠼`,`⠴`,`⠦`,`⠧`,`⠇`,`⠏`],XI=e=>{let t=t=>`.${xb(e,t)}`,n=YI.map(e=>`${1/30} "${e}"`).join(` `);return`{{ if eq .${nx[gb[e].switch.setting].effectiveVar} ${JSON.stringify(gb[e].switch.on)} }} {{ if ${t(`subscribers`)} }}{{ realtimeFrames ${n} }} {{ ${t(`fps`)} }} fps{{ if not ${t(`shown`)} }} · off screen{{ end }}{{ else }}no subscriber{{ end }}{{ end }}`},ZI=`{{ if .diagnostics.label }} {{ bg .diagnostics.bg (fg .diagnostics.fg (action "${Ax}" .diagnostics.label .diagnostics.open)) }}{{ end }}`,QI=`${q}fps`,$I=`{{ if eq .${yb(`by`)} "feed" }}{{ printf "%3s" (printf "≤%d" (int .${yb(`fps`)})) }} fps{{ else }}${`polled`.padStart(7)}{{ end }}`,eL=Object.fromEntries(KI.map(([e,t])=>[e,XI(t)])),tL=e=>uN.filter(t=>lN[t].beside===e),nL=(e,t,n)=>{if(typeof t==`object`&&`from`in t&&typeof t.from!=`string`)return{from:t.from.filter(e=>!n.includes(e))};if(n.length>0)throw Error(`setting "${e}" names trials, but its control does not range a list of members to leave them out of`);return t},rL=(e,t,n,r,i)=>{let a=nx[e];return{...a,name:e,id:t,place:n,control:aN({label:a.label,domain:r},a.sessionKey,a.effectiveVar,gI(t),BI(n)),beneath:a.previews.map(e=>HI[e]),...i}},iL=Object.keys(nx).map(e=>rL(e,e,dN[e],nL(e,yN(nx[e].configKey),nx[e].trials),{help:[JI[e]].filter(e=>e!==void 0),submenus:tL(e)})),aL=Object.keys(nx).filter(e=>nx[e].trials.length>0).map(e=>rL(e,`${e}.trials`,`trials`,{from:nx[e].trials},{help:[],submenus:[]})),oL=[...iL,...aL],sL=e=>oL.filter(t=>t.place===e),cL=e=>oL.filter(t=>pN(t.place,e)),lL=e=>t=>`(print ${ea(t)} (ternary ${ea(` •`)} "" ${GI(cL(e))}))`,uL=e=>sL(e).flatMap(e=>[SL(e),...e.help,...e.submenus.map(e=>Yi(RI(e),VI(e),kL(e),`drop`))].map(t=>({...t,when:`{{ ${e.shown} }}`})));new Set(iL.flatMap(e=>[e.sessionKey,e.configKey]));const dL=BF(SI,{arm:`⟲`,confirm:`⟲ reset all?`},iL.map(e=>({action:_I(e.name),when:e.shown}))),fL=[`unsaved`,`history.undo`,`history.redo`],pL=e=>`${q}${e}`,mL=pL(`unsaved`),hL=(e,t)=>({body:t,shown:`(gt .${pL(e)} 0)`}),gL=[hL(`unsaved`,`{{ action "${fI}" (printf "💾 save %d" .${mL}) }}`),hL(`history.undo`,`{{ action "${wI}" "↶" }}`),hL(`history.redo`,`{{ action "${AI}" "↷" }}`),{body:dL.template,shown:`(or ${GI(iL)} ${dL.armed})`}],_L={when:`{{ or ${gL.map(e=>e.shown).join(` `)} }}`,template:`{{ $sep := "" }}`+gL.map(e=>`{{ if ${e.shown} }}{{ $sep }}${e.body}{{ $sep = " " }}{{ end }}`).join(``)},vL=[{step:dL,place:`door`},{step:iI,place:`session`}],yL=e=>e.map(e=>e.step.disarm),bL=yL(vL),xL=yL(vL.filter(e=>e.place!==`door`));function SL(e){let t=hI(e.id);return e.control.kind===`inline`?sI(t):Yi(t,e.control.list.ref,{kind:`container`,direction:`vertical`,children:[...e.control.list.rows,...e.beneath].map((t,n)=>sI(UI(e.id,n)))},`drop`)}function CL(e){return e===Dx}function wL(e){let t=sI(Dx);if(e.kind===`container`&&e.direction===`vertical`){let[n,...r]=e.children;return e.when===void 0&&n!==void 0?{...e,children:[wL(n),...r]}:{kind:`container`,direction:`vertical`,children:[t,e]}}if(e.kind===`segment`)return{kind:`container`,direction:`horizontal`,children:[t,e]};if(e.when===void 0)return{...e,children:[t,...e.children]};let{when:n,children:r,...i}=e;return{...i,children:[t,{kind:`container`,direction:i.direction,when:n,children:r}]}}function TL(e){return EL(e)>0?e:wL(e)}function EL(e){let t=0;for(let n of uy(e))n.kind===`segment`&&CL(n.name)&&(t+=1);return t}function DL(e,t=!1){let n=t||e.when!==void 0;return e.kind===`segment`?n&&CL(e.name)||e.opens!==void 0&&DL(e.opens.body,!0):e.children.some(e=>DL(e,n))}const OL={door:{direction:`horizontal`,content:[sI(OI)],after:[sI(eI),sI(fI)]},session:{direction:`vertical`,content:[sI(tI),{kind:`container`,direction:`horizontal`,children:[sI(rI),sI(aI)]}],after:[]},look:{direction:`horizontal`,content:[],after:[]},layout:{direction:`horizontal`,content:[sI(pI)],after:[]},config:{direction:`horizontal`,content:[],after:[]},tools:{direction:`vertical`,content:[sI(jI),...DF.map(e=>sI(FI(e.name)))],after:[]},gear:{direction:`horizontal`,content:[],after:[sI(vI)]},toggles:{direction:`horizontal`,content:[],after:[]},trials:{direction:`horizontal`,content:[],after:[]}};function kL(e){let{direction:t,content:n,after:r}=OL[e];return{kind:`container`,direction:t,children:[...n,...uL(e),...r]}}function AL(e){return e.kind===`segment`?CL(e.name)?{kind:`container`,direction:`horizontal`,children:[Yi(e.name,kx,ML,`above`),sI(QI)]}:e:NL(e)}function jL(){return{kind:`container`,direction:`vertical`,children:[kL(`door`),{kind:`container`,direction:`horizontal`,children:sN.map(({member:e})=>Yi(lI(e),dI(e),kL(e),`drop`))}]}}const ML=jL();function NL(e){return{...e,children:e.children.map(e=>AL(e))}}function PL(e){let t={variables:{[Dx]:ta(Dx,Wi),[Ax]:{kind:`state`,key:Ax,default:`0`}},actions:{[CI]:na(Dx,Ox),[Ax]:{set:Ax,int:!0},[Dx]:{do:[CI,...bL]},[MI]:{doctor:`run`},...nI.actions,...iI.actions,...oI.actions,[fI]:{save:!0},[wI]:{undo:!0},[EI]:{back:!0},[TI]:{do:[EI,...bL]},[AI]:{redo:!0},[pI]:{preset:`save`},[vI]:{themeDefault:`save`},[mI]:{preset:`delete`,name:`{{ .${nx.preset.effectiveVar} }}`}},segments:{[Dx]:{template:`{{ $door := ${$i(Dx,ea(e),ea(`✖`))} }}{{ if ${Zi(kx)} }}{{ fg (keptOn (roleTextOn "error" (bgOf)) (bgOf)) $door }}{{ else }}{{ $door }}{{ end }}`+ZI},[QI]:{template:$I},[tI]:{template:nI.template},[rI]:{template:iI.template,when:iI.when},[aI]:{template:oI.template,bg:oI.bg,when:oI.when},[OI]:kI,[fI]:_L,[vI]:xI,[pI]:{template:`{{ action "${pI}" "+ preset" }}`},[jI]:{template:`{{ action "${MI}" "🩺 doctor" }}`},[eI]:{template:`{{ action "${oP}" "✎ arrange" "✎ done" }}`}}};t.variables[yI]={kind:`input`,path:`themeDefault.differs`,type:`boolean`,default:!1},t.variables[bI]={kind:`input`,path:`themeDefault.theme`,type:`string`,default:``},t.variables[DI]={kind:`input`,path:`navigation.back`,type:`number`,default:0};for(let e of fL)t.variables[pL(e)]={kind:`input`,path:e,type:`number`,default:0};t.variables[cI]=ta(cI,`session`);for(let{member:e,label:n}of sN){t.actions[uI(e)]=na(cI,e),t.actions[lI(e)]={do:[uI(e),...xL]};let r=lL(e);t.segments[lI(e)]={template:`{{ ${$i(lI(e),r(n),r(`▾ ${n}`))} }}`}}return Object.assign(t.variables,iI.variables,dL.variables),IL(t),FL(t),t}function FL(e){for(let t of DF){let n=AF(t.name),r=NI(t.name);for(let t of Object.values(n))e.variables[t]={kind:`state`,key:t,default:``};e.actions[r]={doctor:`fix`,check:t.name};let i=t.takesMark?cF:[];for(let n of i)e.actions[PI(t.name,n)]={doctor:`mark`,check:t.name,mark:n};let a=i.map(e=>` {{ action "${PI(t.name,e)}" "${II[e]}" }}`).join(``);e.segments[FI(t.name)]={when:`{{ ne .${n.verdict} "" }}`,template:`{{ if eq .${n.verdict} "ok" }}✓ ${t.label}{{ if ne .${n.reason} "" }} — {{ .${n.reason} }}{{ end }}{{ else }}✗ ${t.label} — {{ .${n.reason} }}{{ if eq .${n.fixable} "${Qv}" }} {{ action "${r}" "[fix]" }}{{ end }}`+(a===``?``:`{{ if ne .${n.sighting} "" }} {{ .${n.sighting} }}${a}{{ end }}`)+`{{ end }}`}}}function IL(e){for(let t of oL){Object.assign(e.actions,t.control.actions);let n=_I(t.name);e.actions[n]={reset:t.configKey},e.variables[WI(t.name)]={kind:`input`,path:`resettable.${t.name}`,type:`boolean`,default:!1};let r=`{{ if .${WI(t.name)} }} {{ action "${n}" "↺" }}{{ end }}`;Object.assign(e.variables,t.control.variables),e.segments[hI(t.id)]={template:`${t.control.template}${eL[t.name]??``}${r}`},t.control.kind===`picker`&&[...t.control.list.rows.map(e=>({template:e})),...t.beneath].forEach((n,r)=>{e.segments[UI(t.id,r)]=n})}Object.assign(e.actions,dL.actions),Object.assign(e.variables,qI.variables),Object.assign(e.actions,qI.actions),Object.assign(e.segments,qI.segments);for(let t of uN){let n=VI(t);e.actions[zI(t)]=na(n.key,n.member),e.segments[RI(t)]={template:`{{ action "${zI(t)}" ${lL(t)(lN[t].trigger)} }}`}}}function LL(e){let{variables:t,actions:n}=hP();Object.assign(e.variables,t),Object.assign(e.actions,n)}function RL(e){let t=PL(e.globals.menuGlyph??`🍫`);LL(t);let n={...e.presets},r=[];for(let t of mC(e.presets)){let{node:i}=_C(e,t),a=AL(TL(i));r.push(a),n[t]={...gC(e.presets,t),root:a}}let i=WM(t,r,e);return{...e,variables:{...i,...e.variables,...t.variables},actions:{...e.actions,...t.actions},segments:{...e.segments,...t.segments},presets:n}}const zL=`${xx}live`,BL=[`☐ live`,`☑ live`],VL=`${xx}done`,HL=`${xx}cancel`,UL=`${xx}rewind`,WL=`${xx}changes`,GL=`(gt .${WL} 0)`,KL=`(or ${GL} (gt .${mL} 0))`,qL={variable:zL,key:zL,member:`open`};function JL(e){return`${xx}configuring.p${e}`}function YL(e){return`and ${Zi(uP)} (not ${Zi(qL)}) (ne .${JL(e)} "true")`}function XL(e){return{kind:`template`,template:`{{ or ${e.map(e=>`(eq .${aP} "${Ji(e)}")`).join(` `)} false }}`}}function ZL(e,t,n){return`{{ if ${YL(e)} }}${t}{{ else }}${n}{{ end }}`}const QL=`{{ and ${Zi(uP)} .preset.customized }}`,$L=Cx;function eR(e){return new Map([...wC(e),...nR(e)])}const tR=`${xx}addable`;function nR(e){return new Map([[tR,{members:Object.keys(e.segments).filter(e=>!$L(e)),library:{groups:tP.map(e=>({id:e,label:nP[e]})),entry:t=>{let n=e.segments[t];return{group:n.group??`other`,...n.description!==void 0&&{description:n.description}}}}}]])}function rR(e,t,n){return n.segments[e]={template:t,when:dP,bg:yP},{kind:`segment`,name:e}}function iR(e,t,n){let r=`${xx}${e.presetIdent}.remove.${t}`;return e.artifacts.actions[r]={persist:e.rootKey,removeSegment:n},`{{ fg (${`readableOn (color "error") (bgOf) ${J_}`}) (action "${r}" "✖") }}`}function aR(e){return`{{ if ${Zi(uP)} }}${e}{{ end }}`}function oR(e,t){return e.reduce((e,t)=>`{{ if and ${Zi(uP)} ${Zi(t)} }}true{{ else }}${e}{{ end }}`,t)}function sR(e){return e.flatMap(e=>[...uy(e)].flatMap(e=>e.kind===`segment`&&e.opens?.ref.key===`edit.configure`?[e.opens.ref]:[]))}function cR(e,t,n){return`${cP}${e}.${t}.${n}`}function lR(e,t,n,r){let i=oy(n),a=`${xx}${e.presetIdent}`,o=lP(e.presetIdent,i);e.configured.push(o);let s=`${a}.configure.${t}`,c=qM(s),l=`${s}.fold`;e.artifacts.actions[l]={set:c,to:Wi},e.artifacts.actions[s]={do:[`${s}.open`,l]},e.artifacts.actions[`${s}.open`]={set:aP,to:o};let u={},d=Object.entries(r).map(([r,o])=>{let s=cR(e.presetIdent,i,r),l=`${cP}p${e.presetIdent}.d${t}.${r}`;e.artifacts.variables[l]={kind:`state`,key:s,default:Ay(n.settings?.[r]??o.default)},u[r]={id:i,key:s,variable:l};let d=`${a}.setting.${t}.${r}`,f=aN(rN(o),s,l,d,c);if(Object.assign(e.artifacts.actions,f.actions),Object.assign(e.artifacts.variables,f.variables),f.kind===`inline`)return e.artifacts.segments[d]={template:f.template},{kind:`segment`,name:d};e.artifacts.segments[d]={template:f.template};let p=f.list.rows.map((t,n)=>{let r=`${d}.list.${n}`;return e.artifacts.segments[r]={template:t},{kind:`segment`,name:r}});return Yi(d,f.list.ref,{kind:`container`,direction:`vertical`,children:p},`drop`)});return{term:`{{ action "${s}" "${TP}" }}`,ref:{variable:aP,key:aP,member:o},body:{kind:`container`,direction:`vertical`,children:d},drafts:u}}const uR=`${xx}label:`;function dR(e){if(e.startsWith(uR)){let t=e.slice(uR.length);return t.slice(t.indexOf(`:`)+1)}return e.startsWith(`edit.`)?void 0:e}function fR(e,t,n,r){let i=oy(e),a=pR(n,i,e,t,i),o=Object.fromEntries(Ty.flatMap(t=>{let n=e.settings?.[t];return n===void 0?[]:[[t,n]]}));return{...Yi(a,r.ref,r.body,`drop`,oR([r.ref],`{{ ${YL(n.presetIdent)} }}`)),...Object.keys(o).length>0&&{settings:o},drafts:Object.fromEntries(Ty.map(e=>[e,r.drafts[e]]))}}function pR(e,t,n,r,i){let a=`${uR}${t}:${n.name}`;return e.artifacts.segments[a]={template:`{{ "${Ji(i)}" }}`,...r.palette!==void 0&&{palette:r.palette}},a}function mR(e,t,n,r){let i=oy(e),a=n?[_R(r,String(r.posCounter.n++),i,`before`)]:[],o=String(r.posCounter.n++),s=_R(r,o,i,`after`),c=iR(r,o,i),l=r.segments[e.name],u=lR(r,o,e,Ey(l)),d=aR(c),f=aR(u.term);return[...a.map(e=>rR(e.host,e.template,r.artifacts)),{...fR(e,l,r,u),lead:d,trail:f},{...t,when:ZL(r.presetIdent,`false`,e.when??`true`),lead:d,trail:f,drafts:u.drafts},rR(s.host,s.template,r.artifacts)]}function hR(e){return o.join(o.basename(o.dirname(e)),o.basename(e))}function gR(e,t,n,r){let i=r.segments[e.name],a=oy(e);return[{kind:`segment`,name:pR(r,`${a}/${r.presetIdent}`,e,i,`${a} · ${hR(t.file)} ${t.entry}`),when:`{{ ${YL(r.presetIdent)} }}`},{...n,when:ZL(r.presetIdent,`false`,e.when??`true`)}]}function _R(e,t,n,r){let{presetIdent:i,artifacts:a}=e,o=`${xx}${i}.insert.${t}`,s=`${xx}${i}.insertSeg.${t}`;a.actions[o]={persist:e.rootKey,insertSegmentFrom:tR,anchor:n,relation:r};let c=GM(o),l=KM(s,o,void 0),u=YM(l),d=JM(l,c);return a.variables[l]={...ta(l,Wi),within:[uP]},a.variables[u]={kind:`state`,key:u,default:`0`},a.actions[d]=na(l,c),a.actions[u]={set:u,int:!0},{host:s,template:`{{ $m := menu "${o}" "✚" "✕" }}{{ if ${Zi({variable:l,key:l,member:c})} }}{{ $m }}{{ else }}{{ fg (${`readableOn (color "success") (bgOf) ${J_}`}) $m }}{{ end }}`}}function vR(e,t){let n=[],r=e.children.findIndex(e=>e.kind===`segment`&&!$L(e.name)&&e.insertedBy===void 0),i=e=>vR(e,t);for(let[a,o]of e.children.entries()){if(o.kind===`container`){n.push(i(o));continue}let s=ly(o,i);if($L(o.name)){n.push(s);continue}let c={kind:`container`,direction:`horizontal`,children:o.insertedBy===void 0?mR(o,s,a===r,t):gR(o,o.insertedBy,s,t),unit:!0};n.push(e.direction===`vertical`?{kind:`container`,direction:`horizontal`,children:[c]}:c)}return{...e,children:n,...e.when!==void 0&&{when:oR(sR(n),ZL(t.presetIdent,`true`,e.when))}}}function yR(e,t,n,r,i,a,o){let s=`${xx}${t}.resetLayout`,c=`${xx}${t}.customized`;return r.actions[s]={reset:n},r.segments[c]={template:`{{ action "${s}" "↺ reset layout" }}`,when:QL},{kind:`container`,direction:`vertical`,children:[{kind:`container`,direction:`horizontal`,children:[...i,{kind:`segment`,name:c},a]},bR(e,o)]}}function bR(e,t){if(e.kind===`segment`)return{kind:`container`,direction:`horizontal`,children:[e,t]};let n=e.children.at(-1);return e.direction===`vertical`&&n!==void 0&&(n.kind===`segment`||n.when===void 0)?{...e,children:[...e.children.slice(0,-1),bR(n,t)]}:{...e,children:[...e.children,t]}}function xR(e,t,n,r,i,a){let{node:o}=_C(e,t),s={presetIdent:dx(t),rootKey:JN(t),segments:e.segments,artifacts:n,posCounter:{n:0},configured:[]},c=vR(o,s);return n.variables[JL(s.presetIdent)]=XL(s.configured),yR(c,s.presetIdent,s.rootKey,n,r,i,a)}function SR(e){let t={variables:{},actions:{},segments:{}},n=_P(`${xx}help`,kP,[uP],t);t.variables[zL]=ta(zL,Wi),t.actions[zL]=na(zL,qL.member),t.segments[zL]={template:Qi(zL,...BL),when:dP};let r={kind:`segment`,name:zL},i=n;t.variables[WL]={kind:`input`,path:`history.sinceEdit`,type:`number`,default:0},t.actions[VL]={do:[fI,oP]},t.segments[VL]={template:`{{ if ${KL} }}{{ action "${VL}" "✓ save" }}{{ else }}{{ action "${VL}" "✓ done" }}{{ end }}`,when:dP},t.actions[UL]={rewind:!0},t.actions[HL]={do:[UL,oP]},t.segments[HL]={template:`{{ action "${HL}" "↩ cancel" }}`,when:`{{ and ${Zi(uP)} ${GL} }}`};let a=[{kind:`segment`,name:VL},{kind:`segment`,name:HL}],o={...e.presets},s=[];for(let n of mC(e.presets)){let c=xR(e,n,t,a,r,i);s.push(c),o[n]={...gC(e.presets,n),root:c}}let c=WM(t,s,e);return{...e,variables:{...c,...e.variables,...t.variables},actions:{...e.actions,...t.actions},segments:{...e.segments,...t.segments},presets:o}}function CR(e){return e.op===`remove`?`remove:${e.target}`:`insert:${e.segment}:${e.anchor}:${e.relation}`}function wR(e){let t=e.split(`:`);return t[0]===`remove`&&t.length===2&&t[1]?{op:`remove`,target:t[1]}:t[0]===`insert`&&t.length===4&&t[1]&&t[2]&&(t[3]===`before`||t[3]===`after`)?{op:`insert`,segment:t[1],anchor:t[2],relation:t[3]}:null}function TR(e,t,n){let r=cy(e,new Set(n.map(sy).filter(e=>e.includes(t)).flat()));return r===e?{seg:e}:{seg:e,id:r}}const ER=/^-?\d+$/;function DR(e,t,n=`set-state`){let r=e.filter(e=>e.includes(`/`));if(r.length>0)throw Error(`makeAllowListValidator(${t}): values contain "/" — the ${n} wire shape splits values on "/" so slash-bearing options cannot be addressed. Offending values: ${r.join(`, `)}`);if(e.includes(``))throw Error(`makeAllowListValidator(${t}): empty string is not a writable option — the validator rejects empty input before the allow-list check, so an "" in the allowed list could be rendered but never delivered. Remove "" from the allowed list.`);let i=new Set(e),a=[...e];return e=>e?i.has(e)?{ok:!0,value:e}:{ok:!1,reason:`unknown ${t} "${e}" (have: ${a.join(`, `)})`}:{ok:!1,reason:`${t} value is required`}}function OR(e){return t=>{if(!t)return{ok:!1,reason:`${e} value is required`};if(!ER.test(t))return{ok:!1,reason:`${e} must be an integer, got "${t}"`};let n=t[0]===`-`,r=(n?t.slice(1):t).replace(/^0+/,``);return r===``?{ok:!0,value:`0`}:{ok:!0,value:n?`-${r}`:r}}}function kR(e,t,n){return r=>r?ER.test(r)?{ok:!0,value:String(Math.max(e,Math.min(t,parseInt(r,10))))}:{ok:!1,reason:`${n} must be an integer, got "${r}"`}:{ok:!1,reason:`${n} value is required`}}function AR(e,t,n=`state`){let r=t.filter(e=>e.kind===`range`),i=t.some(e=>e.kind===`int`),a=t.flatMap(e=>e.kind===`allow-list`?e.allowed:[]);if(r.length===0&&!i)return{kind:`allow-list`,allowed:[...new Set(a)]};let o=a.filter(e=>!ER.test(e));if(o.length>0)throw Error(`${n} action table: key "${e}" is an integer spec (a paged cursor or a bounded value) but a click writes non-integer value(s) to it (${o.join(`, `)}). A ${n} key has one key shape — point that click at a distinct key, or write an integer.`);if(i&&r.length>0)throw Error(`${n} action table: key "${e}" is declared as both a paged cursor (int) and a bounded value (range) — a ${n} key has one key shape. Use distinct keys.`);if(r.length>0){let t=Math.min(...r.map(e=>e.min)),i=Math.max(...r.map(e=>e.max)),o=a.filter(e=>{let n=parseInt(e,10);return n<t||n>i});if(o.length>0)throw Error(`${n} action table: key "${e}" is a bounded range [${t},${i}] but a click writes out-of-range value(s) to it (${o.join(`, `)}). The range gate would clamp them, storing a different value than the click renders — write an in-range integer, or point that click at a distinct key.`);return{kind:`range`,min:t,max:i}}return{kind:`int`}}function jR(e){return e===`config`?`set-config`:`set-state`}function MR(e,t,n){return t.kind===`int`?OR(`menu page "${e}"`):t.kind===`range`?kR(t.min,t.max,`${n} stepper "${e}"`):DR(t.allowed,`${n} "${e}"`,jR(n))}function NR(e,t=`state`){let n=new Map;for(let{key:t,spec:r}of e){let e=n.get(t);e?e.push(r):n.set(t,[r])}return[...n].map(([e,n])=>({key:e,spec:AR(e,n,t)}))}function PR(e,t,n,r){let i=new Map(Object.entries(e)),a=new Map,o=new Set(t.map(e=>e.key));for(let{key:e,spec:t}of n)if(o.has(e)&&t.kind!==`allow-list`)throw Error(`${r} gate: key "${e}" is written by the daemon's own links as one of a list of values, and cannot be declared as ${t.kind===`int`?`a paged cursor (int)`:`a bounded value (range)`}. Use a distinct key.`);let s=[...t.map(({key:e,allowed:t})=>({key:e,spec:{kind:`allow-list`,allowed:t}})),...n];for(let{key:t,spec:n}of NR(s,r)){if(!t)throw Error(`${r} gate: key is required`);if(t.includes(`/`))throw Error(`${r} gate: key "${t}" contains "/" — the wire shape splits on "/" so a slash-bearing key cannot be addressed. Use a slash-free key.`);if(Object.hasOwn(e,t))throw Error(`${r} gate: key "${t}" is a built-in ${r} key and cannot be re-claimed (built-in keys: ${Object.keys(e).join(`, `)})`);i.set(t,MR(t,n,r)),n.kind===`range`&&a.set(t,{min:n.min,max:n.max})}return{validate(e,t){let n=i.get(e);return n?n(t):{ok:!1,reason:`unknown ${r} key "${e}" (have: ${[...i.keys()].join(`, `)})`}},listKeys:()=>[...i.keys()],rangeParamsFor:e=>a.get(e)??null}}function FR(e,t,n){let r=[],i=0,a=new WeakMap;return{register(n,a){let o={key:n,allowed:a};PR(e,[o],[],t),r.push(o),i++;let s=!0;return()=>{s&&(s=!1,r.splice(r.indexOf(o),1),i++)}},gateFor(o){let s=a.get(o);if(s?.epoch===i)return s.gate;let c=PR(e,r,n(o),t);return a.set(o,{epoch:i,gate:c}),c}}}const IR=FR({},`config`,UR);function LR(e,t){return IR.register(e,t)}function RR(e){return IR.gateFor(e)}function zR(e,t){return`persist`in e?`to`in e?[{key:e.persist,spec:{kind:`allow-list`,allowed:[e.to]}}]:`from`in e?[{key:e.persist,spec:{kind:`allow-list`,allowed:EC(e.from,t).members}}]:`cycle`in e?[{key:e.persist,spec:{kind:`allow-list`,allowed:e.cycle}}]:`removeSegment`in e?[{key:e.persist,spec:{kind:`allow-list`,allowed:[CR({op:`remove`,target:e.removeSegment})]}}]:`insertSegment`in e?[{key:e.persist,spec:{kind:`allow-list`,allowed:[CR({op:`insert`,segment:e.insertSegment,anchor:e.anchor,relation:e.relation})]}}]:`insertSegmentFrom`in e?[{key:e.persist,spec:{kind:`allow-list`,allowed:EC(e.insertSegmentFrom,t).members.map(t=>CR({op:`insert`,segment:t,anchor:e.anchor,relation:e.relation}))}}]:[{key:e.persist,spec:{kind:`range`,min:e.min,max:e.max}}]:[]}function BR(e,t){let n=UN(e).get(t);return n===void 0?null:String(n)}function VR(e){let t=new Set;for(let n of Object.values(e.actions)){`reset`in n&&t.add(n.reset);let e=`persist`in n?QN(n.persist):null;e?.scope===`preset-root`&&t.add(JN(e.preset))}return[...t].map(e=>({key:e,spec:{kind:`allow-list`,allowed:[]}}))}function HR(e){let t=eR(e);return[...VR(e),...Object.values(e.actions).flatMap(e=>zR(e,t))]}function UR(e){return NR(HR(e),`config`)}function WR(e,t){return{globals:{...t.globals,...e.globals??{}},variables:{...t.variables,...e.variables??{}},segments:qR(t.segments,GR(t.segments,e.segments??{})),root:aC(e.root??QS,t.root),actions:{...t.actions,...e.actions??{}},styles:{...t.styles,...e.styles??{}},presets:qR(t.presets,KR(t.presets,e.presets??{})),themeDefaults:qR(t.themeDefaults,e.themeDefaults??{}),editGlobals:{...t.editGlobals,...e.editGlobals??{}},helpers:{...t.helpers,...e.helpers??{}}}}function GR(e,t){return Object.fromEntries(Object.entries(t).map(([t,n])=>[t,n.settings===void 0?n:{...n,settings:{...e[t]?.settings,...n.settings}}]))}function KR(e,t){return Object.fromEntries(Object.entries(t).map(([t,n])=>[t,n.globals===void 0?n:{...n,globals:{...e[t]?.globals,...n.globals}}]))}function qR(e,t){return{...e,...Object.fromEntries(Object.entries(t).map(([t,n])=>[t,{...e[t],...n}]))}}function JR(e,t,n,r){return n.cache===void 0?(e.issues.push({path:`${t}.cache`,message:`${r} variables must declare a cache policy (one of: ${gy.join(`, `)})`,line:G(e.source,t.split(`.`))}),null):ZR(e,`${t}.cache`,n.cache)}function YR(e){return{required:!0,json:QR(),parse:(t,n,r,i)=>JR(t,n,i,e)??void 0}}const XR={noun:`cache`,arms:{ttl:{json:{type:`string`},parse:(e,t,n)=>typeof n==`string`&&ez(n)?{ttl:n}:ib(e,t,`cache.ttl must be a duration string like "5s", "100ms", "2m", "1h"; got ${K(n)}`)},watch_file:{json:{type:`string`,pattern:`^/`},parse:(e,t,n)=>{if(typeof n!=`string`)return ib(e,t,`cache.watch_file must be a path string, got ${K(n)}`);let r=db(`cache.watch_file`,n);return r===null?{watch_file:n}:ib(e,t,r)}},depends_on:{json:{type:`array`,items:{type:`string`}},parse:(e,t,n)=>Array.isArray(n)&&n.every(e=>typeof e==`string`)?{depends_on:n}:ib(e,t,`cache.depends_on must be an array of variable-name strings, got ${K(n)}`)},key:{json:{type:`string`},parse:(e,t,n)=>typeof n==`string`&&n!==``?{key:n}:ib(e,t,`cache.key must be a non-empty template string, got ${K(n)}`)},never:{json:{const:!0},parse:(e,t,n)=>n===!0?{never:!0}:ib(e,t,`cache.never must be the literal boolean true, got ${K(n)}`)}}};function ZR(e,t,n){return ab(e,XR,t,n)}function QR(){return mb(XR)}const $R=/^(\d+(?:\.\d+)?)(ms|s|m|h)$/;function ez(e){return $R.test(e)}const tz=new Map([[`session.budget.amount`,{segment:`session`,setting:`budget`}],[`session.budget.warningThreshold`,{segment:`session`,setting:`warnAt`}],[`today.budget.amount`,{segment:`today`,setting:`budget`}],[`today.budget.warningThreshold`,{segment:`today`,setting:`warnAt`}],[`block.budget.heatThreshold`,{segment:`block`,setting:`warnAt`}],[`block.budget.warningThreshold`,{segment:`block`,setting:`errorAt`}],[`weekly.budget.heatThreshold`,{segment:`weekly`,setting:`warnAt`}],[`weekly.budget.warningThreshold`,{segment:`weekly`,setting:`errorAt`}],[`burn.eta.errorMinutes`,{segment:`burnrate`,setting:`errorWithin`}],[`burn.eta.warnMinutes`,{segment:`burnrate`,setting:`warnWithin`}]]);function nz(e){return`it became the "${e.setting}" setting of each "${e.segment}" placement — set it on the placement where a row places "${e.segment}" ({ seg: "${e.segment}", settings: { ${e.setting}: <value> } }), or redeclare segments.${e.segment}.settings.${e.setting} with the default every placement should start from`}function rz(e){let t=tz.get(e);return t===void 0?void 0:`variables.${e} is no longer read: ${nz(t)}`}function iz(e){let t=tz.get(e);return t===void 0?``:` — ".${e}" is no longer a variable: ${nz(t)}; a "${t.segment}" template reads it as ".settings.${t.setting}"`}const az=new Map([[`git.timeSinceCommit`,`the payload stores the commit's date as "git.committedAt" (epoch seconds), and the bundled template variable "git.timeSinceCommit" computes its age at the draw: drop this declaration`],[`block.etaMinutes`,`the bundled template variable "block.etaMinutes" computes it at the draw: drop this declaration`],[`weekly.etaMinutes`,`the bundled template variable "weekly.etaMinutes" computes it at the draw: drop this declaration`]]),oz=new Map([[`branch`,{read:`.git.branch`,declare:{kind:`input`,path:`git.branch`,default:``},note:`when HEAD is on no branch it reads "detached", where this kind read ""`}],[`sha`,{read:`.git.sha`,declare:{kind:`input`,path:`git.sha`,default:``}}],[`dirty`,{read:`(ne .git.status "clean")`,declare:{kind:`template`,template:`{{ ne .git.status "clean" }}`,type:`boolean`}}],...[`ahead`,`behind`,`stash`].map(e=>[e,{read:`.git.${e}`,declare:{kind:`input`,path:`git.${e}`,type:`number`,default:0}}])]);function sz(e){let t=e=>typeof e==`string`&&e.includes(`"`)&&!e.includes(`'`)?`'${e}'`:JSON.stringify(e);return`{ ${Object.entries(e).map(([e,n])=>`${e}: ${t(n)}`).join(`, `)} }`}function cz(e){let t=`kind "git" is retired: every git fact is an input over the payload's git lane, which the bundled default already declares — drop this declaration and`,n=typeof e.field==`string`?oz.get(e.field):void 0;if(n===void 0){let e=[...oz.values()].map(({read:e})=>e);return`${t} read whichever of ${e.slice(0,-1).join(`, `)} or ${e.at(-1)} it stood for, where it was read`}let r=n.note===void 0?``:` (${n.note})`;return`${t} read ${n.read} where it was read${r}, or declare ${sz(n.declare)} under a name of your own`}function lz(e,t,n){if(n===void 0)return{};if(!Qy(n))return e.issues.push({path:t,message:`${t} must be an object, got ${$y(n)}`,line:G(e.source,t.split(`.`))}),{};let r={};for(let[i,a]of Object.entries(n)){let n=xee(e,Nz,`${t}.${i}`,a);n!==null&&(r[i]=n)}return r}function uz(){return{required:!0,json:{type:[`string`,`number`,`boolean`]},parse:(e,t,n,r)=>{let i=r.value;if(typeof i!=`string`&&typeof i!=`number`&&typeof i!=`boolean`){e.issues.push({path:`${t}.value`,message:`literal value must be string|number|boolean, got ${$y(i)}`,line:G(e.source,t.split(`.`))});return}return i}}}function dz(){return{required:!1,json:{type:[`string`,`number`,`boolean`]},parse:(e,t,n,r)=>{let i=r.type;return Jy(e,t,r,i===`number`||i===`boolean`||i===`string`?i:`string`)}}}const fz={noun:`parse`,arms:{text:{json:{const:!0},parse:(e,t,n)=>n===!0?{text:!0}:ib(e,t,`parse.text must be the literal boolean true, got ${K(n)}`)},regex:{json:{type:`string`},parse:(e,t,n)=>typeof n==`string`?pz(e,t,n):ib(e,t,`parse.regex must be a pattern string, got ${K(n)}`)},json:{json:{const:!0},parse:(e,t,n)=>n===!0?{json:!0}:ib(e,t,`parse.json must be the literal boolean true, got ${K(n)}`)}}};function pz(e,t,n){let r;try{new RegExp(n),r=RegExp(`${n}|`).exec(``).length-1}catch(n){return ib(e,t,`parse.regex is not a valid regular expression: ${n.message}`)}return r>=1?{regex:n}:ib(e,t,`parse.regex must contain a capture group — its group 1 is the value; got ${JSON.stringify(n)}`)}function mz(){return{required:!1,json:mb(fz),parse:(e,t,n,r)=>(r.regex!==void 0&&e.issues.push({path:`${t}.regex`,message:`${t}.regex was retired; the regex is the parse step's regex arm now: parse: { regex: ${JSON.stringify(r.regex)} }`,line:G(e.source,[...t.split(`.`),`regex`])}),r.parse===void 0?void 0:ab(e,fz,`${t}.parse`,r.parse)??void 0)}}function hz(){return{required:!1,json:{type:[`string`,`number`,`boolean`,`array`,`object`],description:`The value published when the source fails: a string under the text/regex parse arms, any non-null JSON value under the json arm`},parse:(e,t,n,r)=>Qy(r.parse)&&`json`in r.parse?gz(e,t,r.default):Yy(e,t,r,`default`)}}function gz(e,t,n){if(n!==void 0)return _z(n)?n:ib(e,`${t}.default`,`${t}.default must be a JSON value (a json-parsed source's document), got ${K(n)}`)??void 0}function _z(e){return e!==null&&vz(e)}function vz(e){if(e===null)return!0;switch(typeof e){case`string`:case`boolean`:return!0;case`number`:return Number.isFinite(e);case`object`:{if(Array.isArray(e))return e.every(vz);let t=Object.getPrototypeOf(e);return(t===Object.prototype||t===null)&&Object.values(e).every(vz)}default:return!1}}const yz={value:uz(),default:sb()};function bz(){let e=ub();return{...e,parse:(t,n,r,i)=>{let a=e.parse(t,n,r,i),o=a===void 0?void 0:az.get(a);return o===void 0?a:ib(t,`${n}.${r}`,`${n}.${r} "${a}" is no longer in the payload: ${o}`)??void 0}}}const xz={path:bz(),type:fb([`string`,`number`,`boolean`]),default:dz()},Sz={name:ub(),default:sb()},Cz={path:Eee(),readMode:fb([`whole`,`first-line`]),parse:mz(),cache:YR(`file`),default:hz()},wz={command:ub(),parse:mz(),cache:YR(`shell`),default:hz()};function Tz(e){return{cache:`${e}, so it takes no cache policy — delete the key`}}const Ez={template:ub(),type:fb([`string`,`number`,`boolean`]),default:dz()},Dz=Tz(`a template variable recomputes whenever a variable it reads changes`),Oz={layout:ub(),default:sb()},kz=Tz(`a time variable reads the instant its render is drawn at`),Az={key:ub(),default:sb()},jz=`kind`;function Mz(e,t,n={}){return{...See(jz,e,t),parse:(r,i,a)=>{tb(r,n,i,a);let o=nb(r,t,i,a);return o===null?null:{kind:e,...o}}}}const Nz={tag:jz,noun:`source kind`,memberNoun:`variable`,arms:{literal:Mz(`literal`,yz),input:Mz(`input`,xz),env:Mz(`env`,Sz),file:Mz(`file`,Cz),shell:Mz(`shell`,wz),template:Mz(`template`,Ez,Dz),time:Mz(`time`,Oz,kz),state:Mz(`state`,Az)},retired:{git:cz}};function Pz(){return kee(Nz)}function Fz(){return{type:`object`,additionalProperties:Pz()}}const Iz=new Map([[`gitTaculous`,{kind:`built-in`,to:`gitaculous`}],[`git`,{kind:`built-in`,to:`gitaculous`}],[`settings.menu`,{kind:`built-in`,to:`candybar.menu`}],[`ticket`,{kind:`plugin`,to:`plugins.lit.ticket`,source:`promptctl/links-issue-tracker`}],[`ceiling`,{kind:`removed`}]]);function Lz(e){let t=Iz.get(e);if(t===void 0)return``;switch(t.kind){case`built-in`:return` (the built-in segment "${e}" was renamed to "${t.to}" — update this reference)`;case`plugin`:return` (the built-in segment "${e}" became "${t.to}", a segment of the plugin \`cc-candybar plugin install ${t.source}\` installs — update this reference)`;case`removed`:return` (the built-in segment "${e}" was removed: the program it showed draws it through a cc-candybar plugin of its own now — delete this reference, or place that plugin's segment)`}}const Rz=/^[A-Za-z_][A-Za-z0-9_]*$/,zz={pattern:Rz.source},Bz={anyOf:[{type:`boolean`},{type:`string`},{type:`integer`}]},Vz={type:`object`,additionalProperties:!1,required:[`label`,`domain`,`default`],properties:{label:{type:`string`,pattern:`^[^\\n\\r]+$`},domain:{anyOf:[{const:`bool`},{type:`array`,items:{type:`string`,pattern:`^[^/\\n\\r]+$`},minItems:1,uniqueItems:!0},{type:`object`,additionalProperties:!1,required:[`min`,`max`],properties:{min:{type:`integer`},max:{type:`integer`},step:{type:`integer`,minimum:1},atLeast:{type:`string`,...zz}}}]},default:Bz}},Hz=[`label`,`domain`,`default`],Uz=[`min`,`max`,`step`,`atLeast`];function Wz(e,t,n){e.issues.push({path:t,message:n,line:G(e.source,t.split(`.`))})}function Gz(e,t,n){if(n===`bool`)return`bool`;if(Array.isArray(n)){let r=n.filter(e=>typeof e==`string`);if(n.length===0||r.length!==n.length)return Wz(e,t,`a list domain must be a non-empty list of words, got ${JSON.stringify(n)}`);if(new Set(r).size!==r.length)return Wz(e,t,`a list domain names each word once, got ${JSON.stringify(n)}`);let i=r.filter(e=>e===``||e.includes(`/`)||/[\n\r]/.test(e));return i.length>0?Wz(e,t,`a list domain's words must be non-empty, slash-free, and newline-free — configure mode writes each on the set-state wire — got ${JSON.stringify(i)}`):r}if(Qy(n)){let{min:r,max:i,step:a=1,atLeast:o}=n;return Object.keys(n).filter(e=>!Uz.includes(e)).length===0&&Number.isInteger(r)&&Number.isInteger(i)&&r<=i&&Number.isInteger(a)&&a>=1&&(o===void 0||typeof o==`string`)?{min:r,max:i,step:a,...o!==void 0&&{atLeast:o}}:Wz(e,t,`a range domain is { min, max, step?, atLeast? } with integers min ≤ max, a whole step ≥ 1, and atLeast naming another range setting, got ${JSON.stringify(n)}`)}return Wz(e,t,`domain must be "bool", a list of words, or { min, max }, got ${K(n)}`)}function Kz(e,t,n){if(!Qy(n))return Wz(e,t,`${t} must be { label, domain, default }, got ${$y(n)}`);for(let r of Object.keys(n))Hz.includes(r)||Wz(e,`${t}.${r}`,`Unknown setting key "${r}". Expected one of: ${Hz.join(`, `)}`);let{label:r}=n,i=typeof r==`string`&&r.length>0&&!/[\n\r]/.test(r);i||Wz(e,`${t}.label`,`a setting needs a one-line, non-empty "label" — the name its control shows, spliced into a synthesized template string — got ${K(r)}`);let a=Gz(e,`${t}.domain`,n.domain);if(!i||a===void 0)return;let o={label:r,domain:a,default:n.default};return!qz(n.default)||!ky(o,n.default)?Wz(e,`${t}.default`,`default must be ${Ny(o)}, got ${K(n.default)}`):o}function qz(e){return typeof e==`boolean`||typeof e==`string`||typeof e==`number`}const Jz={theme:`its default for this segment is segments.<name>.palette, and a placement sets its own with settings: { ${Cy}: "<theme>" }`,effect:`a placement follows the bar's effect, or sets its own with settings: { effect: "<effect>" }`};function Yz(e){return Ty.includes(e)}function Xz(){return{required:!1,json:{type:`object`,propertyNames:{...zz,not:{enum:[...Ty]}},additionalProperties:Vz},parse:(e,t,n,r)=>{let i=r[n];if(i===void 0)return;let a=`${t}.${n}`;if(!Qy(i))return Wz(e,a,`${a} must be an object of name → { label, domain, default }, got ${$y(i)}`);let o=Object.create(null);for(let[t,n]of Object.entries(i)){if(!Rz.test(t)){Wz(e,`${a}.${t}`,`setting name "${t}" is read as .settings.${t} in a template, so it must be an identifier (letters, digits, _; not starting with a digit)`);continue}if(Yz(t)){Wz(e,`${a}.${t}`,`setting "${t}" is one every placement already has — ${Jz[t]}`);continue}let r=Kz(e,`${a}.${t}`,n);r!==void 0&&(o[t]=r)}return o}}}const Zz=Sx.map(e=>e.replace(/\./g,`\\.`)).join(`|`);function Qz(){return{required:!1,json:{type:`string`,minLength:1,pattern:`^(?!${Zz})[^:/]+$`},parse:(e,t,n,r)=>{let i=r[n];if(i!==void 0)return typeof i==`string`&&i.length>0&&!/[:/]/.test(i)&&!Cx(i)?i:Wz(e,`${t}.${n}`,`a placement "id" must be a non-empty string without "/" or ":", outside the reserved ${Sx.map(e=>`"${e}"`).join(`, `)} namespaces, got ${K(i)}`)}}}function $z(){return{required:!1,json:{type:`object`,propertyNames:zz,additionalProperties:Bz},parse:(e,t,n,r)=>{let i=r[n];if(i===void 0)return;let a=`${t}.${n}`;if(!Qy(i))return Wz(e,a,`a placement's "settings" must be an object of setting name → value, got ${$y(i)}`);let o=Object.create(null);for(let[t,n]of Object.entries(i))qz(n)?o[t]=n:Wz(e,`${a}.${t}`,`setting "${t}" must be a boolean, a word, or a number, got ${$y(n)}`);return o}}}function eB(e){return new Set(Object.keys(e.segments).filter(e=>!Cx(e)))}function tB(e,t,n){if(t===void 0)return{};if(!Qy(t))return e.issues.push({path:`segments`,message:`segments must be an object, got ${$y(t)}`,line:G(e.source,[`segments`])}),{};let r={};for(let[i,a]of Object.entries(t)){let t=eb(e,n.has(i)?sB:oB,`segments.${i}`,a);t!==null&&(r[i]=t)}return r}function nB(){return{required:!0,json:{type:`string`},parse:(e,t,n,r)=>r[n]===void 0?ib(e,`${t}.${n}`,`${t} declares no template — only a segment the bundled default declares may omit it (inheriting the bundled template); a segment of your own needs its own${Lz(t.slice(9))}`)??void 0:qy(e,t,r,n)??void 0}}function rB(){return{required:!1,json:{anyOf:[{const:`auto`},{const:`fill`},{type:`integer`,minimum:1}]},parse:(e,t,n,r)=>{let i=r[n];if(i!==void 0){if(i===`auto`)return`auto`;if(i===`fill`)return`fill`;if(typeof i==`number`&&Number.isInteger(i)&&i>0)return i;e.issues.push({path:`${t}.${n}`,message:`width must be "auto", "fill", or a positive integer, got ${K(i)}`,line:G(e.source,[...t.split(`.`),n])})}}}}function iB(){return{required:!1,json:Fz(),parse:(e,t,n,r)=>{let i=r[n];if(i!==void 0)return lz(e,`${t}.${n}`,i)}}}const aB={template:nB(),description:sb(),group:fb(eP),width:rB(),justify:fb(Py),truncate:fb(Fy),bg:sb(),fg:sb(),when:sb(),palette:Tee(),vars:iB(),settings:Xz(),missingData:fb(by)},oB={noun:`segment key`,fields:aB},sB={noun:`segment key`,fields:{...aB,template:sb()}},cB=`#/definitions/LayoutNode`,lB={kind:`container`,direction:`vertical`,children:[]};function uB(e){return{required:!0,json:{const:e},parse:()=>e}}function dB(){return{required:!0,json:{type:`string`},parse:(e,t,n,r)=>{let i=r[n];return typeof i==`string`&&i.length>0?i:(e.issues.push({path:`${t}.${n}`,message:`a segment node must have a non-empty "name" (a segment name), got ${K(i)}`,line:G(e.source,[`root`])}),``)}}}function fB(){return{required:!0,json:{enum:[...iy]},parse:(e,t,n,r)=>{let i=r[n];return typeof i==`string`&&iy.includes(i)?i:(e.issues.push({path:`${t}.${n}`,message:`a container "direction" must be one of: ${iy.join(`, `)} (got ${JSON.stringify(i)})`,line:G(e.source,[`root`])}),`vertical`)}}}function pB(e){return{required:!0,json:{type:`array`,items:{$ref:cB}},parse:(t,n,r,i)=>{let a=i[r];return Array.isArray(a)?a.map((i,a)=>e(t,`${n}.${r}[${a}]`,i)):(t.issues.push({path:`${n}.${r}`,message:`a container must have a "children" array of layout nodes, got ${$y(a)}`,line:G(t.source,[`root`])}),[])}}}const mB={noun:`layout-node key`,fields:{kind:uB(`segment`),name:dB(),when:sb(),id:Qz(),settings:$z()}},hB=()=>fb(k_),gB={noun:`layout-node key`,fields:{kind:uB(`container`),direction:fB(),children:pB(ob(()=>xB)),when:sb(),distribution:hB()}};function _B(){return{required:!0,json:{type:`string`},parse:(e,t,n,r)=>{let i=r[n];return typeof i==`string`&&i.length>0?i:(e.issues.push({path:`${t}.${n}`,message:`a "seg" node must have a non-empty segment name, got ${K(i)}`,line:G(e.source,[...t.split(`.`),n])}),``)}}}const vB={noun:`layout-node key`,fields:{seg:_B(),when:sb(),id:Qz(),settings:$z()}},yB={noun:`layout-node key`,fields:{h:pB(ob(()=>xB)),when:sb(),distribution:hB()}},bB={noun:`layout-node key`,fields:{v:pB(ob(()=>xB)),when:sb(),distribution:hB()}},xB=(e,t,n)=>{if(typeof n==`string`)return n.length===0?(e.issues.push({path:t,message:`a bare-string layout node must be a non-empty segment name`,line:G(e.source,[`root`])}),lB):{kind:`segment`,name:n};if(!Qy(n))return e.issues.push({path:t,message:`a layout node must be a string (segment name) or an object with "kind" / "seg" / "h" / "v", got ${$y(n)}`,line:G(e.source,[`root`])}),lB;if(n.kind===`container`)return eb(e,gB,t,n)??lB;if(n.kind===`segment`)return eb(e,mB,t,n)??lB;if(n.kind===`cells`)return e.issues.push({path:t,message:`kind: "cells" is no longer supported — use the h-arm spelling instead:
182
+ `).map(e=>e.trim()).filter(e=>e!==``),...e.warnings];return{ok:!1,reason:t,more:n}}case`loaded`:return dF([...e.warnings,...e.unused.map(({kind:e,name:t})=>`${e} "${t}" ${$ee[e]}`)])}}},mF="re-run `cc-candybar install`";function tte(e){if(e.kind===`failed`)return[`Launch Services could not be asked which app opens cc-candybar:// — ${e.reason}`];if(e.value===null)return[`no app is registered for cc-candybar:// — ${mF}`];let{app:t,missing:n}=e.value;return n.kind===`failed`?[`${t} opens cc-candybar://, but ${n.reason} — ${mF}`]:n.value.map(e=>`${e} is missing, and ${t} runs it — ${mF}`)}const nte={name:`urlHandler`,label:`URL handler`,takesMark:!1,probe:({urlHandler:e})=>{switch(e.kind){case`unsupported`:return{ok:!0};case`unprobed`:return{ok:!1,reason:e.reason};case`arrived`:return e.handler===e.bar?{ok:!0}:{ok:!1,reason:e.handler===null?`the URL handler does not report its version, so it is older than the bar (${e.bar}) — ${mF}`:`the URL handler runs cc-candybar ${e.handler}; the bar runs ${e.bar} — ${mF}`};case`lost`:return dF([...tte(e.opener),e.unopened===null?`a cc-candybar:// link was opened and did not arrive at the daemon`:`a cc-candybar:// link could not be opened — ${e.unopened}`])}}};function hF({bundle:e,checkout:t},n){return{bundle:n.bundle.kind===`failed`?{kind:`unresolved`,reason:n.bundle.reason}:n.bundle.value===e?{kind:`same`}:{kind:`other`,path:n.bundle.value},source:n.client!==`native`||t===null?{kind:`uncompared`}:t.rustSource.kind===`failed`?{kind:`unreadable`,root:t.root,reason:t.rustSource.reason}:n.source===null?{kind:`unstamped`}:n.source===t.rustSource.value?{kind:`same`}:{kind:`other`,root:t.root}}}function gF(e,t){return t===`frames`?`run \`node ${e.bundle} frames --lane <${_b.join(`|`)}>\``:e.checkout===null?mF:`run \`just install-rust\` and point the statusLine command at ${e.checkout.root}/bin/cc-candybar-native`}function rte(e,t,n){let{checkout:r}=e;if(n.kind===`unreported`)return[`the bar is drawn by a statusline client too old to say what it is — ${gF(e,`native`)}`];let{bundle:i,source:a}=hF(e,n);switch(i.kind){case`unresolved`:return[`the statusline client's bundle cannot be resolved: ${i.reason}`];case`other`:return[`the statusline client runs ${i.path}, not the daemon's ${e.bundle} — ${gF(e,n.client)}`];case`same`:break}if(n.client===`node`&&(t||r!==null))return[`the bar is drawn by the Node fallback, which starts node on every render — ${gF(e,`native`)}`];switch(a.kind){case`uncompared`:case`same`:return[];case`unreadable`:return[`${a.root}/rust-client could not be read: ${a.reason}`];case`unstamped`:return["the native client carries no source stamp, so which source it was built from is unknown — run `just install-rust`"];case`other`:return[`the native client was built from other source than ${a.root}/rust-client holds — run \`just install-rust\``]}}const _F=e=>{let t=`restarted since the bar was drawn, or has served 64 newer sessions`;return e.kind===`clicked`?`this daemon holds no render of this bar (it ${t})`:`this daemon holds no render of session ${e.sessionId}'s bar (its statusLine does not run cc-candybar — a \`claude -p\` session draws none — or the daemon ${t}; unset CLAUDE_CODE_SESSION_ID to judge every bar drawn recently)`},ite={name:`install`,label:`install`,takesMark:!1,probe:({install:e,sighted:t})=>{if(e.kind===`failed`)return{ok:!1,reason:`the daemon could not be asked which clients draw the bar: ${e.reason}`};let{daemon:n,nativeShipped:r,clients:i}=e.value;return i.length===0?{ok:!1,reason:t.kind===`recent`?`no statusline client has drawn a bar for this daemon in the last ${300/60} minutes — run the doctor again once the bar has redrawn; if it never does, the statusLine command does not run cc-candybar`:`${_F(t)}, so which client draws it is unknown — run the doctor again once the bar has redrawn`}:dF([...new Set(i.flatMap(e=>rte(n,r,e)))])}};function vF({postMortems:e},t){return e.kind===`ok`&&t.kind===`ok`?e.value.filter(e=>t.value.through===null||Ar(e.identity,t.value.through)):[]}function yF(e,t){return e.kind===`failed`?t:t.filter(t=>t.pid!==e.value.pid)}const ate={name:`daemon`,label:`daemon`,takesMark:!1,probe:({daemon:{serving:e,processes:t,read:n}})=>{let r=t.kind===`failed`?[`the process table could not be read: ${t.reason}`]:[],i=t.kind===`ok`?yF(e,t.value):[];if(e.kind===`failed`){let t=i.length>0?` — daemon ${i.map(e=>e.pid).join(`, `)} running`:``;return dF([`${e.reason}${t}`,...r])}let{pid:a,memory:o,limit:s,postMortems:c}=e.value,l=vF(e.value,n),u=dF([...l.map(e=>`the daemon ran out of memory and restarted (${e.identity}) — post-mortem: ${Object.values(e.artifacts).join(`, `)}`),...c.kind===`failed`?[`the daemon's post-mortems could not be listed: ${c.reason}`]:[],...n.kind===`failed`&&!(c.kind===`ok`&&c.value.length===0)?[`which post-mortems were read could not be read: ${n.reason}`]:[],...r,...i.map(e=>`daemon ${e.pid} (started ${e.started}, rss ${Dr(e.rss)} MB${e.ppid===1?``:`, child of ${e.ppid}`}) runs beside the one serving the bar (${a}) — \`kill ${e.pid}\``),...o.kind===`measured`&&o.charge.kind===`stand-in`?[`the daemon could not read what macOS charges it (${o.charge.unread}), so its memory limit judges ${o.charge.gap===0?`RSS, which counts pages macOS has reclaimed`:`RSS less the ${Dr(o.charge.gap)} MB it last ran over that charge, an estimate`}`]:[],...o.kind===`measured`&&Nr(o.charge.bytes,s)?[`the daemon holds ${Lr(o.charge)} of its ${Dr(s)} MB limit — at the limit it records a post-mortem and restarts`]:[]]);if(u.ok&&o.kind===`unmeasured`)return{ok:!0,note:`the daemon has not measured its memory yet`};let d=l[0];return u.ok||d===void 0?u:{...u,fix:{kind:`post-mortems-read`,through:d.identity}}}},bF=`click 🩺 doctor in the bar's settings menu: if it runs, links work`;function ote(e,t){let n=nF(e);return t.kind===`ok`&&n!==null&&t.value.includes(n)?{kind:`draws`}:e.kind===`known`?iF(e.terminal):{kind:`unknown`}}function ste({identified:e,tmuxClient:t},n){let r=rF(e),i=ote(e,n),a=nF(e)===null?bF:`${bF}, and the doctor remembers it for this terminal`,o=(()=>{switch(i.kind){case`draws`:return[];case`none`:return[`${r} draws no links (OSC 8), so nothing on the bar can be clicked — run Claude Code in a terminal that draws them: ${aF}`];case`older`:return[`${r} ${i.version} draws no links (OSC 8 came in ${i.since}) — update ${r}`];case`unsaid`:return[`${r} draws links (OSC 8) since ${i.since}, and did not say which release this is — ${a}`];case`unknown`:return[`the doctor does not know whether ${r} draws links (OSC 8) — ${a}`]}})(),s=n.kind===`failed`&&i.kind!==`draws`?[`the terminals a doctor click came back from could not be read: ${n.reason}`]:[],c=i.kind===`none`||t===null||t.features.includes(`hyperlinks`)?[]:[`tmux does not pass links through to ${r} — add \`set -as terminal-features ",${t.termname}:hyperlinks"\` to tmux.conf, then detach and reattach (tmux 3.4 or later)`];return[...o,...s,...c]}const cte={name:`links`,label:`links`,takesMark:!1,probe:({sighted:e,terminal:t,clicked:n})=>{if(e.kind===`clicked`&&e.via===`link`)return{ok:!0};switch(t.kind){case`unreported`:return{ok:!1,reason:"the client reported no terminal — re-run `cc-candybar install` to stage a current client"};case`unasked`:return{ok:!1,reason:`tmux could not be asked which terminal is attached: ${t.reason}`};case`seen`:return dF(ste(t,n))}}},xF=e=>e.filter(e=>e.role===`statusline`),lte={name:`effectRefresh`,label:`effect refresh`,takesMark:!1,probe:({frames:e,claudeSettings:{origin:t,elsewhere:n},sighted:r})=>{let i=[t,...n].flatMap(({sources:e,bars:t})=>dte(e,ute(t))??[]),[a]=i;if(a===void 0)return e.kind===`failed`?{ok:!1,reason:e.reason}:SF(r.kind===`recent`?`no session has drawn a statusline for this daemon in the last ${300/60} minutes`:_F(r));let[o,...s]=i.flatMap(e=>e.ok?[]:[e]);if(o===void 0)return a;let c=[...new Set(s.map(e=>e.reason))].filter(e=>e!==o.reason);return c.length===0?o:{...o,more:c}}},ute=e=>{let t=xF(e).map(e=>e.frame);return t.includes(`moves`)?{kind:`moving`,wearing:`the bar moves (an effect, a fade, an animated segment, or an open menu counting down to its close)`}:t.includes(`can-move`)?{kind:`moving`,wearing:`the bar can start moving (an open menu, which flashes and closes on its own, a globals.effect rule, placements that fade in and out, or a placement with an effect of its own that is not drawn now)`}:t.includes(`still`)?{kind:`still`}:t.includes(`drawing`)?{kind:`unknown`,unseen:`the bar's latest render has not finished`}:t.length>0?{kind:`unknown`,unseen:`the bar's recent renders failed`}:e.length>0?{kind:`unknown`,unseen:"only a `cc-candybar frames` display has drawn this bar, not Claude Code's statusline"}:{kind:`none`}},SF=e=>({ok:!1,reason:`${e}, so whether it moves is unknown — run the doctor again once the bar has redrawn`});function dte(e,t){let n=oF(e);if(n.kind===`present`&&n.refreshInterval===1)return{ok:!0,note:`statusLine.refreshInterval is 1 in ${n.from.path}`};switch(t.kind){case`none`:return null;case`still`:return{ok:!0};case`unknown`:return SF(t.unseen);case`moving`:break}let{wearing:r}=t;switch(n.kind){case`unread`:return{ok:!1,reason:`${r}, and Claude Code's settings could not be read: ${n.reason}`};case`absent`:return{ok:!1,reason:`${r}, and no settings file Claude Code reads here sets a statusLine (read: ${n.read.join(`, `)||`none`}) — the one that runs the bar comes from --settings, MDM or server-managed settings, which the doctor cannot read; set "refreshInterval": 1 beside its command there`};case`not-an-object`:return{ok:!1,reason:`${r}, and ${n.from.path} sets statusLine to ${JSON.stringify(n.value)}, not a statusLine object — ${n.from.scope===`user`?"re-run `cc-candybar install` to write one":`replace it there with the statusLine object that runs cc-candybar`}`};case`present`:{let{from:e,refreshInterval:t}=n,i=t===void 0?`its statusLine sets no refreshInterval, so Claude Code redraws it only on events`:typeof t==`number`&&t>1?`its statusLine redraws it only every ${t} s`:`its statusLine.refreshInterval is ${JSON.stringify(t)}, not a number of seconds Claude Code accepts (its minimum is 1)`;return qee(e)?{ok:!1,reason:`${r}, but ${i} (statusLine from ${e.path})`,fix:{kind:`claude-settings`,file:e,path:[`statusLine`,`refreshInterval`],value:1}}:{ok:!1,reason:`${r}, but ${i} — its statusLine is in ${e.scope===`managed`?`managed settings`:`the project's shared settings`}, ${e.path}: set "refreshInterval": 1 there`}}}}const CF=e=>[...e].map(e=>`U+${e.codePointAt(0).toString(16).toUpperCase()}`).join(` `);function fte(e){switch(e.kind){case`unreported`:case`unasked`:return`this terminal`;case`unknown`:case`unnamed`:return rF(e);case`bundling`:case`unread`:case`configured`:return[KP(e.name),e.version].filter(e=>e!==null).join(` `)}}function pte(e){switch(e.kind){case`unreported`:case`unasked`:return null;case`unknown`:case`unnamed`:return nF(e);case`bundling`:case`unread`:return KP(e.name);case`configured`:{let t=KP(e.name);return e.font.kind===`ok`?`${t} with ${e.font.value.font} (${e.font.value.from})`:`${t}, its font unread: ${e.font.reason}`}}}function wF(e){let t=pte(e.terminal);return t===null?void 0:{glyphs:e.glyphs,id:`${t}|${CF(e.glyphs)}`}}const mte={name:`nerdFont`,label:`Nerd Font`,takesMark:!0,probe:({nerdFont:e,marks:t})=>{if(e.kind===`none`)return{ok:!0};let n=wF(e),r=e=>t.kind===`failed`&&n!==void 0?{ok:!1,reason:e,more:[`the mark book could not be read: ${t.reason}`]}:{ok:!1,reason:e,...n!==void 0&&{sighting:n}},i=e.terminal,a=fte(i);switch(n===void 0||t.kind===`failed`?null:t.value.nerdFont?.[n.id]??null){case`drawn`:return{ok:!0};case`boxes`:return r(`${a} draws ${CF(e.glyphs)} as boxes — set a Nerd Font as its font`);case null:break}switch(i.kind){case`unreported`:return r("the client reported no terminal — re-run `cc-candybar install` to stage a current client");case`unasked`:return r(`tmux could not be asked which terminal is attached: ${i.reason}`);case`unknown`:case`unnamed`:case`unread`:return r(`the doctor cannot read ${a}'s font`);case`bundling`:{let e=HP[i.name].glyphs.since;if(e===null)return{ok:!0};let t=i.version===null?null:ZP(i.version,e);if(t===!0)return{ok:!0};let n=KP(i.name);return r(t===null?`${n} ships Nerd Font symbols since ${e}, and did not say which release this is`:`${a} ships no Nerd Font symbols (they came in ${e}) — update ${n}, or set a Nerd Font as its font`)}case`configured`:{if(i.font.kind===`failed`)return r(`the doctor cannot read ${a}'s font: ${i.font.reason}`);let{font:e,from:t,lacks:n}=i.font.value;return n===null?r(`${a} is set to ${e} (${t}), which is not installed — install it or set a Nerd Font`):n.length===0?{ok:!0}:r(`${a} draws with ${e} (${t}), which has no ${CF(n)} — set a Nerd Font as its font`)}}}};function TF(e){return e.join(`, `)}function EF(e){return`or set missingData: "ignore" on ${TF(e)}`}function hte(e){if(e.kind===`unneeded`)return[];let{segments:t,fact:n}=e;if(n.kind===`failed`)return[`${TF(t)}: whether the forge CLI is ready could not be asked: ${n.reason}`];if(n.value===null)return[];let{cli:r,host:i,status:a}=n.value;return a===`ready`?[]:a===`missing`?[`${TF(t)}: ${r} is not installed, so no pull request is ever shown — install it, ${EF(t)}`]:[`${TF(t)}: ${r} is not logged in to ${i} (${a.loggedOut}) — run \`${r} auth login --hostname ${i}\`, ${EF(t)}`]}function gte(e,t){if(e.kind===`unneeded`)return[];let{segments:n,fact:r}=e;return r.kind===`failed`?[`${TF(n)}: ${r.reason}`]:r.value.length===0?[t.kind===`recent`?`${TF(n)}: no session of this Claude Code has drawn a bar for this daemon in the last ${300/60} minutes, so whether it sends rate_limits is unseen — run the doctor again once the bar has redrawn`:`${TF(n)}: ${_F(t)}, so whether Claude Code sends rate_limits is unseen — run the doctor again once the bar has redrawn`]:r.value.includes(`missing`)&&!r.value.includes(`carried`)?[`${TF(n)}: Claude Code sent no rate_limits — it sends them only to Claude.ai subscription sessions; on any other account, set missingData: "ignore" on ${TF(n)}`]:[]}const _te={name:`segmentData`,label:`segment data`,takesMark:!1,probe:({data:e,sighted:t})=>dF([...hte(e.pullRequests),...gte(e.rateLimits,t)])};function vte({path:e,answered:t,read:n}){switch(n.kind){case`absent`:return t?[`the transcript ${e} does not exist, though Claude Code has answered in its session — the bar's session cost, metrics and activity read nothing`]:[];case`failed`:return[`the transcript ${e} cannot be read: ${n.reason}`];case`ok`:{let{lines:t,unparsed:r,whole:i}=n.value;return r===0?[]:[`${r} of the ${t} lines ${i?`in`:`in the last ${lF/1024/1024} MiB of`} the transcript ${e} are not JSON objects — the bar skips them, so what it counts from them is missing`]}}}const DF=[ete,ite,ate,nte,cte,Xee,Zee,Qee,lte,mte,_te,{name:`sessionData`,label:`session data`,takesMark:!1,probe:({transcripts:e,sighted:t})=>e.kind===`failed`?{ok:!1,reason:e.reason}:e.value.length===0?{ok:!1,reason:t.kind===`recent`?`no session has drawn a bar for this daemon in the last ${300/60} minutes, so no transcript was named — run the doctor again once the bar has redrawn`:`${_F(t)}, so which transcript it reads is unknown — run the doctor again once the bar has redrawn`}:dF(e.value.flatMap(vte))}],yte=DF.filter(e=>e.takesMark);function OF(e){return DF.map(t=>({check:t,verdict:t.probe(e)}))}function kF(e){return DF.find(t=>t.name===e)}const bte=`${q}doctor.`;function AF(e){let t=`${bte}${e}.`;return{verdict:`${t}verdict`,reason:`${t}reason`,fixable:`${t}fixable`,sighting:`${t}sighting`}}function xte(e,t){let n=e.kind===`seen`?e.tmuxClient:null,r=e.kind===`seen`?nF(e.identified):null,i=t.kind===`failed`?`unread`:r===null?`-`:t.value.includes(r)?`yes`:`no`;return`tmuxLinks=${n===null?`-`:n.features.includes(`hyperlinks`)?`yes`:`no`} clicked=${i}`}function Ste(e,t){let n=e.kind===`seen`?e.tmuxClient:null;return`cols=${t.kind===`failed`?`failed widthOf=-`:`${t.value.columns??`-`} widthOf=${t.value.of.kind}`} clientUtf8=${n===null?`-`:n.utf8?`yes`:`no`}`}function Cte(e){if(e.kind===`failed`)return`clients=unasked`;let{daemon:t,clients:n}=e.value;return`clients=${n.map(e=>{if(e.kind===`unreported`)return`unreported/-/-`;let{bundle:n,source:r}=hF(t,e);return`${e.client}/${n.kind}/${r.kind===`uncompared`?`-`:r.kind}`}).join(`,`)||`-`}`}const wte=e=>`${e>=0?`+`:``}${Dr(e)}`;function Tte({serving:e,processes:t,read:n}){let r=t.kind===`failed`?`daemons=unread others=-`:`daemons=${t.value.length} others=${yF(e,t.value).map(e=>e.pid).join(`,`)||`-`}`;if(e.kind===`failed`)return`${r} memory=unasked postMortems=unasked`;let{memory:i,limit:a,postMortems:o}=e.value,s=o.kind===`failed`||n.kind===`failed`?`unread`:`${vF(e.value,n).length}/${o.value.length}`;return`${r} memory=${i.kind===`unmeasured`?`unmeasured`:`${Rr(i.charge)}${i.charge.kind===`stand-in`?`(${wte(-i.charge.gap)})`:``}:${Dr(i.charge.bytes)}`}/${Dr(a)} postMortems=${s}`}function Ete(e){return`data=pr:${(()=>{if(e.pullRequests.kind===`unneeded`)return`-`;let t=e.pullRequests.fact;if(t.kind===`failed`)return`failed`;if(t.value===null)return`no-forge`;let{status:n}=t.value;return typeof n==`string`?n:`logged-out`})()},rateLimits:${(()=>{if(e.rateLimits.kind===`unneeded`)return`-`;let t=e.rateLimits.fact;if(t.kind===`failed`)return`failed`;let n=e=>t.value.filter(t=>t===e).length;return`${n(`carried`)}/${n(`missing`)}/${n(`unanswered`)}`})()}`}function Dte(e,{origin:t,elsewhere:n}){let r=[t,...n],i=r.map(({sources:e})=>Ote(e)).join(`,`);if(e.kind===`failed`)return`frames=failed chains=${I(i)}`;let a=xF(r.flatMap(e=>e.bars));return`frames=${RP.map(e=>a.filter(t=>t.frame===e).length).join(`/`)} chains=${I(i)}`}function Ote(e){let t=oF(e);switch(t.kind){case`unread`:return`failed`;case`absent`:case`not-an-object`:return t.kind;case`present`:return`${t.from.scope}:${t.refreshInterval===void 0?`-`:JSON.stringify(t.refreshInterval)}`}}function kte(e){let t=sF(e,fF);return t.kind===`failed`?`truecolorEnv=failed`:t.value.kind===`unset`?`truecolorEnv=unset`:`truecolorEnv=${I(`${t.value.from.scope}:${JSON.stringify(t.value.value)}`)}`}function Ate(e){if(e.kind===`failed`)return`transcripts=failed`;let t=t=>e.value.filter(e=>e.read.kind===t).length,n=e.value.reduce((e,t)=>e+(t.read.kind===`ok`?t.read.value.unparsed:0),0);return`transcripts=${t(`ok`)}/${t(`absent`)}/${t(`failed`)} unparsed=${n}`}function jte(e,t){if(e.kind===`none`)return`glyphs=- terminal=- font=- mark=-`;let{glyphs:n,terminal:r}=e,i=[...n].map(e=>e.codePointAt(0).toString(16)),a=(()=>{switch(r.kind){case`unreported`:case`unasked`:return r.kind;case`unknown`:return`unknown:${JSON.stringify(r.called)}`;case`unnamed`:return`unnamed:${JSON.stringify(r.term)}`;case`bundling`:case`unread`:case`configured`:return`${r.name}@${r.version??`-`}`}})(),o=(()=>{if(r.kind!==`configured`)return`-`;if(r.font.kind===`failed`)return`failed`;let{font:e,lacks:t}=r.font.value;return`${JSON.stringify(e)}:${t===null?`not-installed`:`lacks${t.length}`}`})(),s=wF(e),c=t.kind===`failed`?`unread`:s===void 0?`-`:t.value.nerdFont?.[s.id]??`-`;return`glyphs=${i.join(`,`)} terminal=${a} font=${o} mark=${c}`}function jF(e,t=[]){return t.length===0?e:`${e} (+${t.length} more — run \`cc-candybar doctor\`)`}function MF(e){return e.flatMap(({check:e,verdict:t})=>{let n=AF(e.name);return t.ok?[{key:n.verdict,value:`ok`},{key:n.reason,value:t.note??``},{key:n.fixable,value:$v},{key:n.sighting,value:``}]:[{key:n.verdict,value:`failed`},{key:n.reason,value:jF(t.reason,t.more)},{key:n.fixable,value:t.fix===void 0?$v:Qv},{key:n.sighting,value:t.sighting?.glyphs??``}]})}const NF={copySession:{copy:`{{ .session.id }}`},copyResume:{copy:`{{ .resume_command }}`},openProject:{open:`{{ .project_dir }}`},openTranscript:{open:`{{ .transcript_path }}`},openConfig:{open:`{{ .config_path }}`}};function PF(e){let t=t=>`${e}${t}`;return{template:`{{ action "${t(`copySession`)}" "⎘ id" }}{{ if ne .resume_command "" }} {{ action "${t(`copyResume`)}" "⎘ resume" }}{{ end }} {{ action "${t(`openProject`)}" "↗ proj" }} {{ action "${t(`openTranscript`)}" "↗ log" }}{{ if ne .git.repoUrl "" }} {{ link .git.repoUrl "↗ repo" }}{{ end }}{{ if ne .config_path "" }} {{ action "${t(`openConfig`)}" "↗ config" }}{{ end }}`,actions:Object.fromEntries(Object.entries(NF).map(([t,n])=>[`${e}${t}`,n]))}}const FF=`armed`,IF=`disarmed`,LF=`.armed`,RF=e=>e.endsWith(LF);function zF(e,t,n){let r=[...new Set(n.map(e=>e.when))].filter(e=>e!==`true`),i=t=>r.length===0?e:`${e}.${t}`,a={};for(let e=0;e<2**r.length;e++)a[i(e)]={do:[t,...n.filter(t=>t.when===`true`||e&1<<r.indexOf(t.when)).map(e=>e.action)]};let o=(e,t)=>e===r.length?`"${i(t)}"`:`(ternary ${o(e+1,t|1<<e)} ${o(e+1,t)} (${r[e]}))`;return{link:o(0,0),actions:a}}function BF(e,t,n){let r=`${e}${LF}`,i=`${e}.arm`,a=`${e}.disarm`,o=`(eq .${e} "${FF}")`,s=zF(e,a,n);return{template:`{{ if ${o} }}{{ action ${s.link} "${t.confirm}" }} {{ action "${a}" "✕" }}{{ else }}{{ action "${i}" "${t.arm}" }}{{ end }}`,actions:{[i]:{set:r,to:FF},[a]:{set:r,to:IF},...s.actions},armed:o,variables:{[e]:{kind:`state`,key:r,default:IF}},disarm:a}}const VF=RegExp(`^/[^\\s\\x00-\\x1f\\x7f-\\x9f/][^\\x00-\\x1f\\x7f-\\x9f]*$`);function HF(e){return typeof e==`string`&&VF.test(e)?{kind:`line`,line:e}:{kind:`refused`,reason:`a slash command is "/" then its name, e.g. "/compact" or "/model opus", on one line with no control characters, got ${JSON.stringify(e)}`}}function UF(e){let t=HF(e);if(t.kind===`refused`)throw Error(t.reason);return t.line}const WF=[`/compact`,`/model`],GF=`/clear`;function KF(e){let t=t=>`${e}${t.slice(1)}`,n=`${e}clear.slash`,r=BF(`${e}clear`,{arm:GF,confirm:`${GF} ✓ confirm`},[{action:n,when:`true`}]);return{template:WF.map(e=>`{{ action "${t(e)}" "${e}" }} `).join(``)+r.template,when:`{{ ${hb} }}`,actions:{...Object.fromEntries(WF.map(e=>[t(e),{slash:UF(e)}])),...r.actions,[n]:{slash:UF(GF)}},variables:r.variables,disarm:r.disarm}}const qF=Array.from({length:10},(e,t)=>(t+1)*1e5),JF=qF[0],YF=qF[qF.length-1];function XF(e){let t;try{t=Do(e)}catch(e){return F(e instanceof Error?e.message:String(e))}let n=t.autoCompactWindow;return n===void 0?N(`auto`):typeof n==`number`&&Number.isInteger(n)&&n>=JF&&n<=YF?N(n):F(`${e}: autoCompactWindow is ${JSON.stringify(n)}, not a window /autocompact accepts (${JF}–${YF} tokens)`)}function ZF(e,t){let n=Math.min(t??YF,YF),r=e===`auto`?n:Math.min(e,n);return{window:e===`auto`?0:e,applied:e===`auto`?0:r,lower:qF.filter(e=>e<r).at(-1)??0,higher:qF.find(e=>e>r&&e<=n)??0}}function QF(e,t){return{template:`{{ if ne .autocompact.error "" }}⇲ ⚠ {{ .autocompact.error }}{{ else }}⇲ {{ if eq .autocompact.window 0 }}auto{{ else }}${t(`.autocompact.applied`)}{{ end }}{{ if ${hb} }}{{ if gt .autocompact.lower 0 }} {{ action (printf "${e}%d" .autocompact.lower) "−" }}{{ end }}{{ if gt .autocompact.higher 0 }} {{ action (printf "${e}%d" .autocompact.higher) "+" }}{{ end }}{{ if gt .autocompact.window 0 }} {{ action "${e}auto" "↺" }}{{ end }}{{ end }}{{ end }}`,bg:`{{ if ne .autocompact.error "" }}{{ color "error" }}{{ else }}{{ tint }}{{ end }}`,when:`{{ or (ge .autocompact.window 0) (ne .autocompact.error "") }}`,actions:{[`${e}auto`]:{slash:UF(`/autocompact auto`)},...Object.fromEntries(qF.map(t=>[`${e}${t}`,{slash:UF(`/autocompact ${t}`)}]))}}}const $F=e=>`{{ if ge ${e} 1000000 }}{{ printf "%.1f" (divf ${e} 1000000) }}M{{ else if ge ${e} 1000 }}{{ printf "%.1f" (divf ${e} 1000) }}K{{ else }}{{ ${e} }}{{ end }}`,eI=`${q}edit`,tI=`${q}toolbar`,nI=PF(q),rI=`${q}commands`,iI=KF(`${rI}.`),aI=`${q}autocompact`,oI=QF(`${aI}.`,$F),sI=e=>({kind:`segment`,name:e}),cI=`${q}tab`,lI=e=>`${cI}.${e}`,uI=e=>`${lI(e)}.toggle`,dI=e=>({variable:cI,key:cI,member:e}),fI=`${q}save`,pI=`${q}preset.save`,mI=`${q}preset.delete`,hI=e=>`${q}${e}`,gI=e=>`${q}apply.${e}`,_I=e=>`${q}reset.${e}`,vI=`${q}themeDefault.save`,yI=`${q}themeDefault.differs`,bI=`${q}themeDefault.theme`,xI={when:`{{ .${yI} }}`,template:`{{ action "${vI}" (printf "⤓ default for %s" .${bI}) }} {{ swatch "${gI(`theme`)}" .${bI} }}`},SI=`${q}resetAll`,CI=`${Dx}.toggle`,wI=`${q}undo`,TI=`${q}back`,EI=`${TI}.step`,DI=`${q}navigation.back`,OI=TI,kI={template:`{{ if gt .${DI} 0 }}{{ action "${TI}" "◁" }}{{ else }}{{ fg (${MP}) "◁" }}{{ end }}`},AI=`${q}redo`,jI=`${q}doctor`,MI=`${jI}.run`,NI=e=>`${jI}.fix.${e}`,PI=(e,t)=>`${jI}.mark.${e}.${t}`,FI=e=>`${jI}.${e}`,II={drawn:`[✓ shapes]`,boxes:`[✗ boxes]`},LI=qM(`${q}pickers`),RI=e=>`${q}${e}`,zI=e=>`${RI(e)}.toggle`,BI=e=>fN(e)?qM(`${q}${e}Pickers`):LI,VI=e=>{let t=BI(dN[lN[e].beside]);return{variable:t,key:t,member:e}},HI={layout:{template:`{{ layoutPreview }}`},palette:{template:`{{ themePreview }}`},presetDelete:{when:`{{ not .preset.bundled }}`,template:`{{ action "${mI}" (printf "🚮 delete %s" .${nx.preset.effectiveVar}) }}`}},UI=(e,t)=>`${q}list.${e}.${t}`,WI=e=>`${q}resettable.${e}`,GI=e=>e.length===0?`false`:`(or ${e.map(e=>`(and (${e.shown}) .${WI(e.name)})`).join(` `)})`,KI=_b.map(e=>[gb[e].switch.setting,e]),qI={variables:{},actions:{},segments:{}},JI=Object.fromEntries(KI.map(([e,t])=>[e,_P(`${q}help.${e}`,AP[t],[],qI)])),YI=[`⠋`,`⠙`,`⠹`,`⠸`,`⠼`,`⠴`,`⠦`,`⠧`,`⠇`,`⠏`],XI=e=>{let t=t=>`.${xb(e,t)}`,n=YI.map(e=>`${1/30} "${e}"`).join(` `);return`{{ if eq .${nx[gb[e].switch.setting].effectiveVar} ${JSON.stringify(gb[e].switch.on)} }} {{ if ${t(`subscribers`)} }}{{ realtimeFrames ${n} }} {{ ${t(`fps`)} }} fps{{ if not ${t(`shown`)} }} · off screen{{ end }}{{ else }}no subscriber{{ end }}{{ end }}`},ZI=`{{ if .diagnostics.label }} {{ bg .diagnostics.bg (fg .diagnostics.fg (action "${Ax}" .diagnostics.label .diagnostics.open)) }}{{ end }}`,QI=`${q}fps`,$I=`{{ if eq .${yb(`by`)} "feed" }}{{ printf "%3s" (printf "≤%d" (int .${yb(`fps`)})) }} fps{{ else }}${`polled`.padStart(7)}{{ end }}`,eL=Object.fromEntries(KI.map(([e,t])=>[e,XI(t)])),tL=e=>uN.filter(t=>lN[t].beside===e),nL=(e,t,n)=>{if(typeof t==`object`&&`from`in t&&typeof t.from!=`string`)return{from:t.from.filter(e=>!n.includes(e))};if(n.length>0)throw Error(`setting "${e}" names trials, but its control does not range a list of members to leave them out of`);return t},rL=(e,t,n,r,i)=>{let a=nx[e];return{...a,name:e,id:t,place:n,control:aN({label:a.label,domain:r},a.sessionKey,a.effectiveVar,gI(t),BI(n)),beneath:a.previews.map(e=>HI[e]),...i}},iL=Object.keys(nx).map(e=>rL(e,e,dN[e],nL(e,yN(nx[e].configKey),nx[e].trials),{help:[JI[e]].filter(e=>e!==void 0),submenus:tL(e)})),aL=Object.keys(nx).filter(e=>nx[e].trials.length>0).map(e=>rL(e,`${e}.trials`,`trials`,{from:nx[e].trials},{help:[],submenus:[]})),oL=[...iL,...aL],sL=e=>oL.filter(t=>t.place===e),cL=e=>oL.filter(t=>pN(t.place,e)),lL=e=>t=>`(print ${ea(t)} (ternary ${ea(` •`)} "" ${GI(cL(e))}))`,uL=e=>sL(e).flatMap(e=>[SL(e),...e.help,...e.submenus.map(e=>Yi(RI(e),VI(e),kL(e),`drop`))].map(t=>({...t,when:`{{ ${e.shown} }}`})));new Set(iL.flatMap(e=>[e.sessionKey,e.configKey]));const dL=BF(SI,{arm:`⟲`,confirm:`⟲ reset all?`},iL.map(e=>({action:_I(e.name),when:e.shown}))),fL=[`unsaved`,`history.undo`,`history.redo`],pL=e=>`${q}${e}`,mL=pL(`unsaved`),hL=(e,t)=>({body:t,shown:`(gt .${pL(e)} 0)`}),gL=[hL(`unsaved`,`{{ action "${fI}" (printf "💾 save %d" .${mL}) }}`),hL(`history.undo`,`{{ action "${wI}" "↶" }}`),hL(`history.redo`,`{{ action "${AI}" "↷" }}`),{body:dL.template,shown:`(or ${GI(iL)} ${dL.armed})`}],_L={when:`{{ or ${gL.map(e=>e.shown).join(` `)} }}`,template:`{{ $sep := "" }}`+gL.map(e=>`{{ if ${e.shown} }}{{ $sep }}${e.body}{{ $sep = " " }}{{ end }}`).join(``)},vL=[{step:dL,place:`door`},{step:iI,place:`session`}],yL=e=>e.map(e=>e.step.disarm),bL=yL(vL),xL=yL(vL.filter(e=>e.place!==`door`));function SL(e){let t=hI(e.id);return e.control.kind===`inline`?sI(t):Yi(t,e.control.list.ref,{kind:`container`,direction:`vertical`,children:[...e.control.list.rows,...e.beneath].map((t,n)=>sI(UI(e.id,n)))},`drop`)}function CL(e){return e===Dx}function wL(e){let t=sI(Dx);if(e.kind===`container`&&e.direction===`vertical`){let[n,...r]=e.children;return e.when===void 0&&n!==void 0?{...e,children:[wL(n),...r]}:{kind:`container`,direction:`vertical`,children:[t,e]}}if(e.kind===`segment`)return{kind:`container`,direction:`horizontal`,children:[t,e]};if(e.when===void 0)return{...e,children:[t,...e.children]};let{when:n,children:r,...i}=e;return{...i,children:[t,{kind:`container`,direction:i.direction,when:n,children:r}]}}function TL(e){return EL(e)>0?e:wL(e)}function EL(e){let t=0;for(let n of uy(e))n.kind===`segment`&&CL(n.name)&&(t+=1);return t}function DL(e,t=!1){let n=t||e.when!==void 0;return e.kind===`segment`?n&&CL(e.name)||e.opens!==void 0&&DL(e.opens.body,!0):e.children.some(e=>DL(e,n))}const OL={door:{direction:`horizontal`,content:[sI(OI)],after:[sI(eI),sI(fI)]},session:{direction:`vertical`,content:[sI(tI),{kind:`container`,direction:`horizontal`,children:[sI(rI),sI(aI)]}],after:[]},look:{direction:`horizontal`,content:[],after:[]},layout:{direction:`horizontal`,content:[sI(pI)],after:[]},config:{direction:`horizontal`,content:[],after:[]},tools:{direction:`vertical`,content:[sI(jI),...DF.map(e=>sI(FI(e.name)))],after:[]},gear:{direction:`horizontal`,content:[],after:[sI(vI)]},toggles:{direction:`horizontal`,content:[],after:[]},trials:{direction:`horizontal`,content:[],after:[]}};function kL(e){let{direction:t,content:n,after:r}=OL[e];return{kind:`container`,direction:t,children:[...n,...uL(e),...r]}}function AL(e){return e.kind===`segment`?CL(e.name)?{kind:`container`,direction:`horizontal`,children:[Yi(e.name,kx,ML,`above`),sI(QI)]}:e:NL(e)}function jL(){return{kind:`container`,direction:`vertical`,children:[kL(`door`),{kind:`container`,direction:`horizontal`,children:sN.map(({member:e})=>Yi(lI(e),dI(e),kL(e),`drop`))}]}}const ML=jL();function NL(e){return{...e,children:e.children.map(e=>AL(e))}}function PL(e){let t={variables:{[Dx]:ta(Dx,Wi),[Ax]:{kind:`state`,key:Ax,default:`0`}},actions:{[CI]:na(Dx,Ox),[Ax]:{set:Ax,int:!0},[Dx]:{do:[CI,...bL]},[MI]:{doctor:`run`},...nI.actions,...iI.actions,...oI.actions,[fI]:{save:!0},[wI]:{undo:!0},[EI]:{back:!0},[TI]:{do:[EI,...bL]},[AI]:{redo:!0},[pI]:{preset:`save`},[vI]:{themeDefault:`save`},[mI]:{preset:`delete`,name:`{{ .${nx.preset.effectiveVar} }}`}},segments:{[Dx]:{template:`{{ $door := ${$i(Dx,ea(e),ea(`✖`))} }}{{ if ${Zi(kx)} }}{{ fg (keptOn (roleTextOn "error" (bgOf)) (bgOf)) $door }}{{ else }}{{ $door }}{{ end }}`+ZI},[QI]:{template:$I},[tI]:{template:nI.template},[rI]:{template:iI.template,when:iI.when},[aI]:{template:oI.template,bg:oI.bg,when:oI.when},[OI]:kI,[fI]:_L,[vI]:xI,[pI]:{template:`{{ action "${pI}" "+ preset" }}`},[jI]:{template:`{{ action "${MI}" "🩺 doctor" }}`},[eI]:{template:`{{ action "${oP}" "✎ arrange" "✎ done" }}`}}};t.variables[yI]={kind:`input`,path:`themeDefault.differs`,type:`boolean`,default:!1},t.variables[bI]={kind:`input`,path:`themeDefault.theme`,type:`string`,default:``},t.variables[DI]={kind:`input`,path:`navigation.back`,type:`number`,default:0};for(let e of fL)t.variables[pL(e)]={kind:`input`,path:e,type:`number`,default:0};t.variables[cI]=ta(cI,Wi);for(let{member:e,label:n}of sN){t.actions[uI(e)]=na(cI,e),t.actions[lI(e)]={do:[uI(e),...xL]};let r=lL(e);t.segments[lI(e)]={template:`{{ ${$i(lI(e),r(n),r(`▾ ${n}`))} }}`}}return Object.assign(t.variables,iI.variables,dL.variables),IL(t),FL(t),t}function FL(e){for(let t of DF){let n=AF(t.name),r=NI(t.name);for(let t of Object.values(n))e.variables[t]={kind:`state`,key:t,default:``};e.actions[r]={doctor:`fix`,check:t.name};let i=t.takesMark?cF:[];for(let n of i)e.actions[PI(t.name,n)]={doctor:`mark`,check:t.name,mark:n};let a=i.map(e=>` {{ action "${PI(t.name,e)}" "${II[e]}" }}`).join(``);e.segments[FI(t.name)]={when:`{{ ne .${n.verdict} "" }}`,template:`{{ if eq .${n.verdict} "ok" }}✓ ${t.label}{{ if ne .${n.reason} "" }} — {{ .${n.reason} }}{{ end }}{{ else }}✗ ${t.label} — {{ .${n.reason} }}{{ if eq .${n.fixable} "${Qv}" }} {{ action "${r}" "[fix]" }}{{ end }}`+(a===``?``:`{{ if ne .${n.sighting} "" }} {{ .${n.sighting} }}${a}{{ end }}`)+`{{ end }}`}}}function IL(e){for(let t of oL){Object.assign(e.actions,t.control.actions);let n=_I(t.name);e.actions[n]={reset:t.configKey},e.variables[WI(t.name)]={kind:`input`,path:`resettable.${t.name}`,type:`boolean`,default:!1};let r=`{{ if .${WI(t.name)} }} {{ action "${n}" "↺" }}{{ end }}`;Object.assign(e.variables,t.control.variables),e.segments[hI(t.id)]={template:`${t.control.template}${eL[t.name]??``}${r}`},t.control.kind===`picker`&&[...t.control.list.rows.map(e=>({template:e})),...t.beneath].forEach((n,r)=>{e.segments[UI(t.id,r)]=n})}Object.assign(e.actions,dL.actions),Object.assign(e.variables,qI.variables),Object.assign(e.actions,qI.actions),Object.assign(e.segments,qI.segments);for(let t of uN){let n=VI(t);e.actions[zI(t)]=na(n.key,n.member),e.segments[RI(t)]={template:`{{ action "${zI(t)}" ${lL(t)(lN[t].trigger)} }}`}}}function LL(e){let{variables:t,actions:n}=hP();Object.assign(e.variables,t),Object.assign(e.actions,n)}function RL(e){let t=PL(e.globals.menuGlyph??`🍫`);LL(t);let n={...e.presets},r=[];for(let t of mC(e.presets)){let{node:i}=_C(e,t),a=AL(TL(i));r.push(a),n[t]={...gC(e.presets,t),root:a}}let i=WM(t,r,e);return{...e,variables:{...i,...e.variables,...t.variables},actions:{...e.actions,...t.actions},segments:{...e.segments,...t.segments},presets:n}}const zL=`${xx}live`,BL=[`☐ live`,`☑ live`],VL=`${xx}done`,HL=`${xx}cancel`,UL=`${xx}rewind`,WL=`${xx}changes`,GL=`(gt .${WL} 0)`,KL=`(or ${GL} (gt .${mL} 0))`,qL={variable:zL,key:zL,member:`open`};function JL(e){return`${xx}configuring.p${e}`}function YL(e){return`and ${Zi(uP)} (not ${Zi(qL)}) (ne .${JL(e)} "true")`}function XL(e){return{kind:`template`,template:`{{ or ${e.map(e=>`(eq .${aP} "${Ji(e)}")`).join(` `)} false }}`}}function ZL(e,t,n){return`{{ if ${YL(e)} }}${t}{{ else }}${n}{{ end }}`}const QL=`{{ and ${Zi(uP)} .preset.customized }}`,$L=Cx;function eR(e){return new Map([...wC(e),...nR(e)])}const tR=`${xx}addable`;function nR(e){return new Map([[tR,{members:Object.keys(e.segments).filter(e=>!$L(e)),library:{groups:tP.map(e=>({id:e,label:nP[e]})),entry:t=>{let n=e.segments[t];return{group:n.group??`other`,...n.description!==void 0&&{description:n.description}}}}}]])}function rR(e,t,n){return n.segments[e]={template:t,when:dP,bg:yP},{kind:`segment`,name:e}}function iR(e,t,n){let r=`${xx}${e.presetIdent}.remove.${t}`;return e.artifacts.actions[r]={persist:e.rootKey,removeSegment:n},`{{ fg (${`readableOn (color "error") (bgOf) ${J_}`}) (action "${r}" "✖") }}`}function aR(e){return`{{ if ${Zi(uP)} }}${e}{{ end }}`}function oR(e,t){return e.reduce((e,t)=>`{{ if and ${Zi(uP)} ${Zi(t)} }}true{{ else }}${e}{{ end }}`,t)}function sR(e){return e.flatMap(e=>[...uy(e)].flatMap(e=>e.kind===`segment`&&e.opens?.ref.key===`edit.configure`?[e.opens.ref]:[]))}function cR(e,t,n){return`${cP}${e}.${t}.${n}`}function lR(e,t,n,r){let i=oy(n),a=`${xx}${e.presetIdent}`,o=lP(e.presetIdent,i);e.configured.push(o);let s=`${a}.configure.${t}`,c=qM(s),l=`${s}.fold`;e.artifacts.actions[l]={set:c,to:Wi},e.artifacts.actions[s]={do:[`${s}.open`,l]},e.artifacts.actions[`${s}.open`]={set:aP,to:o};let u={},d=Object.entries(r).map(([r,o])=>{let s=cR(e.presetIdent,i,r),l=`${cP}p${e.presetIdent}.d${t}.${r}`;e.artifacts.variables[l]={kind:`state`,key:s,default:Ay(n.settings?.[r]??o.default)},u[r]={id:i,key:s,variable:l};let d=`${a}.setting.${t}.${r}`,f=aN(rN(o),s,l,d,c);if(Object.assign(e.artifacts.actions,f.actions),Object.assign(e.artifacts.variables,f.variables),f.kind===`inline`)return e.artifacts.segments[d]={template:f.template},{kind:`segment`,name:d};e.artifacts.segments[d]={template:f.template};let p=f.list.rows.map((t,n)=>{let r=`${d}.list.${n}`;return e.artifacts.segments[r]={template:t},{kind:`segment`,name:r}});return Yi(d,f.list.ref,{kind:`container`,direction:`vertical`,children:p},`drop`)});return{term:`{{ action "${s}" "${TP}" }}`,ref:{variable:aP,key:aP,member:o},body:{kind:`container`,direction:`vertical`,children:d},drafts:u}}const uR=`${xx}label:`;function dR(e){if(e.startsWith(uR)){let t=e.slice(uR.length);return t.slice(t.indexOf(`:`)+1)}return e.startsWith(`edit.`)?void 0:e}function fR(e,t,n,r){let i=oy(e),a=pR(n,i,e,t,i),o=Object.fromEntries(Ty.flatMap(t=>{let n=e.settings?.[t];return n===void 0?[]:[[t,n]]}));return{...Yi(a,r.ref,r.body,`drop`,oR([r.ref],`{{ ${YL(n.presetIdent)} }}`)),...Object.keys(o).length>0&&{settings:o},drafts:Object.fromEntries(Ty.map(e=>[e,r.drafts[e]]))}}function pR(e,t,n,r,i){let a=`${uR}${t}:${n.name}`;return e.artifacts.segments[a]={template:`{{ "${Ji(i)}" }}`,...r.palette!==void 0&&{palette:r.palette}},a}function mR(e,t,n,r){let i=oy(e),a=n?[_R(r,String(r.posCounter.n++),i,`before`)]:[],o=String(r.posCounter.n++),s=_R(r,o,i,`after`),c=iR(r,o,i),l=r.segments[e.name],u=lR(r,o,e,Ey(l)),d=aR(c),f=aR(u.term);return[...a.map(e=>rR(e.host,e.template,r.artifacts)),{...fR(e,l,r,u),lead:d,trail:f},{...t,when:ZL(r.presetIdent,`false`,e.when??`true`),lead:d,trail:f,drafts:u.drafts},rR(s.host,s.template,r.artifacts)]}function hR(e){return o.join(o.basename(o.dirname(e)),o.basename(e))}function gR(e,t,n,r){let i=r.segments[e.name],a=oy(e);return[{kind:`segment`,name:pR(r,`${a}/${r.presetIdent}`,e,i,`${a} · ${hR(t.file)} ${t.entry}`),when:`{{ ${YL(r.presetIdent)} }}`},{...n,when:ZL(r.presetIdent,`false`,e.when??`true`)}]}function _R(e,t,n,r){let{presetIdent:i,artifacts:a}=e,o=`${xx}${i}.insert.${t}`,s=`${xx}${i}.insertSeg.${t}`;a.actions[o]={persist:e.rootKey,insertSegmentFrom:tR,anchor:n,relation:r};let c=GM(o),l=KM(s,o,void 0),u=YM(l),d=JM(l,c);return a.variables[l]={...ta(l,Wi),within:[uP]},a.variables[u]={kind:`state`,key:u,default:`0`},a.actions[d]=na(l,c),a.actions[u]={set:u,int:!0},{host:s,template:`{{ $m := menu "${o}" "✚" "✕" }}{{ if ${Zi({variable:l,key:l,member:c})} }}{{ $m }}{{ else }}{{ fg (${`readableOn (color "success") (bgOf) ${J_}`}) $m }}{{ end }}`}}function vR(e,t){let n=[],r=e.children.findIndex(e=>e.kind===`segment`&&!$L(e.name)&&e.insertedBy===void 0),i=e=>vR(e,t);for(let[a,o]of e.children.entries()){if(o.kind===`container`){n.push(i(o));continue}let s=ly(o,i);if($L(o.name)){n.push(s);continue}let c={kind:`container`,direction:`horizontal`,children:o.insertedBy===void 0?mR(o,s,a===r,t):gR(o,o.insertedBy,s,t),unit:!0};n.push(e.direction===`vertical`?{kind:`container`,direction:`horizontal`,children:[c]}:c)}return{...e,children:n,...e.when!==void 0&&{when:oR(sR(n),ZL(t.presetIdent,`true`,e.when))}}}function yR(e,t,n,r,i,a,o){let s=`${xx}${t}.resetLayout`,c=`${xx}${t}.customized`;return r.actions[s]={reset:n},r.segments[c]={template:`{{ action "${s}" "↺ reset layout" }}`,when:QL},{kind:`container`,direction:`vertical`,children:[{kind:`container`,direction:`horizontal`,children:[...i,{kind:`segment`,name:c},a]},bR(e,o)]}}function bR(e,t){if(e.kind===`segment`)return{kind:`container`,direction:`horizontal`,children:[e,t]};let n=e.children.at(-1);return e.direction===`vertical`&&n!==void 0&&(n.kind===`segment`||n.when===void 0)?{...e,children:[...e.children.slice(0,-1),bR(n,t)]}:{...e,children:[...e.children,t]}}function xR(e,t,n,r,i,a){let{node:o}=_C(e,t),s={presetIdent:dx(t),rootKey:JN(t),segments:e.segments,artifacts:n,posCounter:{n:0},configured:[]},c=vR(o,s);return n.variables[JL(s.presetIdent)]=XL(s.configured),yR(c,s.presetIdent,s.rootKey,n,r,i,a)}function SR(e){let t={variables:{},actions:{},segments:{}},n=_P(`${xx}help`,kP,[uP],t);t.variables[zL]=ta(zL,Wi),t.actions[zL]=na(zL,qL.member),t.segments[zL]={template:Qi(zL,...BL),when:dP};let r={kind:`segment`,name:zL},i=n;t.variables[WL]={kind:`input`,path:`history.sinceEdit`,type:`number`,default:0},t.actions[VL]={do:[fI,oP]},t.segments[VL]={template:`{{ if ${KL} }}{{ action "${VL}" "✓ save" }}{{ else }}{{ action "${VL}" "✓ done" }}{{ end }}`,when:dP},t.actions[UL]={rewind:!0},t.actions[HL]={do:[UL,oP]},t.segments[HL]={template:`{{ action "${HL}" "↩ cancel" }}`,when:`{{ and ${Zi(uP)} ${GL} }}`};let a=[{kind:`segment`,name:VL},{kind:`segment`,name:HL}],o={...e.presets},s=[];for(let n of mC(e.presets)){let c=xR(e,n,t,a,r,i);s.push(c),o[n]={...gC(e.presets,n),root:c}}let c=WM(t,s,e);return{...e,variables:{...c,...e.variables,...t.variables},actions:{...e.actions,...t.actions},segments:{...e.segments,...t.segments},presets:o}}function CR(e){return e.op===`remove`?`remove:${e.target}`:`insert:${e.segment}:${e.anchor}:${e.relation}`}function wR(e){let t=e.split(`:`);return t[0]===`remove`&&t.length===2&&t[1]?{op:`remove`,target:t[1]}:t[0]===`insert`&&t.length===4&&t[1]&&t[2]&&(t[3]===`before`||t[3]===`after`)?{op:`insert`,segment:t[1],anchor:t[2],relation:t[3]}:null}function TR(e,t,n){let r=cy(e,new Set(n.map(sy).filter(e=>e.includes(t)).flat()));return r===e?{seg:e}:{seg:e,id:r}}const ER=/^-?\d+$/;function DR(e,t,n=`set-state`){let r=e.filter(e=>e.includes(`/`));if(r.length>0)throw Error(`makeAllowListValidator(${t}): values contain "/" — the ${n} wire shape splits values on "/" so slash-bearing options cannot be addressed. Offending values: ${r.join(`, `)}`);if(e.includes(``))throw Error(`makeAllowListValidator(${t}): empty string is not a writable option — the validator rejects empty input before the allow-list check, so an "" in the allowed list could be rendered but never delivered. Remove "" from the allowed list.`);let i=new Set(e),a=[...e];return e=>e?i.has(e)?{ok:!0,value:e}:{ok:!1,reason:`unknown ${t} "${e}" (have: ${a.join(`, `)})`}:{ok:!1,reason:`${t} value is required`}}function OR(e){return t=>{if(!t)return{ok:!1,reason:`${e} value is required`};if(!ER.test(t))return{ok:!1,reason:`${e} must be an integer, got "${t}"`};let n=t[0]===`-`,r=(n?t.slice(1):t).replace(/^0+/,``);return r===``?{ok:!0,value:`0`}:{ok:!0,value:n?`-${r}`:r}}}function kR(e,t,n){return r=>r?ER.test(r)?{ok:!0,value:String(Math.max(e,Math.min(t,parseInt(r,10))))}:{ok:!1,reason:`${n} must be an integer, got "${r}"`}:{ok:!1,reason:`${n} value is required`}}function AR(e,t,n=`state`){let r=t.filter(e=>e.kind===`range`),i=t.some(e=>e.kind===`int`),a=t.flatMap(e=>e.kind===`allow-list`?e.allowed:[]);if(r.length===0&&!i)return{kind:`allow-list`,allowed:[...new Set(a)]};let o=a.filter(e=>!ER.test(e));if(o.length>0)throw Error(`${n} action table: key "${e}" is an integer spec (a paged cursor or a bounded value) but a click writes non-integer value(s) to it (${o.join(`, `)}). A ${n} key has one key shape — point that click at a distinct key, or write an integer.`);if(i&&r.length>0)throw Error(`${n} action table: key "${e}" is declared as both a paged cursor (int) and a bounded value (range) — a ${n} key has one key shape. Use distinct keys.`);if(r.length>0){let t=Math.min(...r.map(e=>e.min)),i=Math.max(...r.map(e=>e.max)),o=a.filter(e=>{let n=parseInt(e,10);return n<t||n>i});if(o.length>0)throw Error(`${n} action table: key "${e}" is a bounded range [${t},${i}] but a click writes out-of-range value(s) to it (${o.join(`, `)}). The range gate would clamp them, storing a different value than the click renders — write an in-range integer, or point that click at a distinct key.`);return{kind:`range`,min:t,max:i}}return{kind:`int`}}function jR(e){return e===`config`?`set-config`:`set-state`}function MR(e,t,n){return t.kind===`int`?OR(`menu page "${e}"`):t.kind===`range`?kR(t.min,t.max,`${n} stepper "${e}"`):DR(t.allowed,`${n} "${e}"`,jR(n))}function NR(e,t=`state`){let n=new Map;for(let{key:t,spec:r}of e){let e=n.get(t);e?e.push(r):n.set(t,[r])}return[...n].map(([e,n])=>({key:e,spec:AR(e,n,t)}))}function PR(e,t,n,r){let i=new Map(Object.entries(e)),a=new Map,o=new Set(t.map(e=>e.key));for(let{key:e,spec:t}of n)if(o.has(e)&&t.kind!==`allow-list`)throw Error(`${r} gate: key "${e}" is written by the daemon's own links as one of a list of values, and cannot be declared as ${t.kind===`int`?`a paged cursor (int)`:`a bounded value (range)`}. Use a distinct key.`);let s=[...t.map(({key:e,allowed:t})=>({key:e,spec:{kind:`allow-list`,allowed:t}})),...n];for(let{key:t,spec:n}of NR(s,r)){if(!t)throw Error(`${r} gate: key is required`);if(t.includes(`/`))throw Error(`${r} gate: key "${t}" contains "/" — the wire shape splits on "/" so a slash-bearing key cannot be addressed. Use a slash-free key.`);if(Object.hasOwn(e,t))throw Error(`${r} gate: key "${t}" is a built-in ${r} key and cannot be re-claimed (built-in keys: ${Object.keys(e).join(`, `)})`);i.set(t,MR(t,n,r)),n.kind===`range`&&a.set(t,{min:n.min,max:n.max})}return{validate(e,t){let n=i.get(e);return n?n(t):{ok:!1,reason:`unknown ${r} key "${e}" (have: ${[...i.keys()].join(`, `)})`}},listKeys:()=>[...i.keys()],rangeParamsFor:e=>a.get(e)??null}}function FR(e,t,n){let r=[],i=0,a=new WeakMap;return{register(n,a){let o={key:n,allowed:a};PR(e,[o],[],t),r.push(o),i++;let s=!0;return()=>{s&&(s=!1,r.splice(r.indexOf(o),1),i++)}},gateFor(o){let s=a.get(o);if(s?.epoch===i)return s.gate;let c=PR(e,r,n(o),t);return a.set(o,{epoch:i,gate:c}),c}}}const IR=FR({},`config`,UR);function LR(e,t){return IR.register(e,t)}function RR(e){return IR.gateFor(e)}function zR(e,t){return`persist`in e?`to`in e?[{key:e.persist,spec:{kind:`allow-list`,allowed:[e.to]}}]:`from`in e?[{key:e.persist,spec:{kind:`allow-list`,allowed:EC(e.from,t).members}}]:`cycle`in e?[{key:e.persist,spec:{kind:`allow-list`,allowed:e.cycle}}]:`removeSegment`in e?[{key:e.persist,spec:{kind:`allow-list`,allowed:[CR({op:`remove`,target:e.removeSegment})]}}]:`insertSegment`in e?[{key:e.persist,spec:{kind:`allow-list`,allowed:[CR({op:`insert`,segment:e.insertSegment,anchor:e.anchor,relation:e.relation})]}}]:`insertSegmentFrom`in e?[{key:e.persist,spec:{kind:`allow-list`,allowed:EC(e.insertSegmentFrom,t).members.map(t=>CR({op:`insert`,segment:t,anchor:e.anchor,relation:e.relation}))}}]:[{key:e.persist,spec:{kind:`range`,min:e.min,max:e.max}}]:[]}function BR(e,t){let n=UN(e).get(t);return n===void 0?null:String(n)}function VR(e){let t=new Set;for(let n of Object.values(e.actions)){`reset`in n&&t.add(n.reset);let e=`persist`in n?QN(n.persist):null;e?.scope===`preset-root`&&t.add(JN(e.preset))}return[...t].map(e=>({key:e,spec:{kind:`allow-list`,allowed:[]}}))}function HR(e){let t=eR(e);return[...VR(e),...Object.values(e.actions).flatMap(e=>zR(e,t))]}function UR(e){return NR(HR(e),`config`)}function WR(e,t){return{globals:{...t.globals,...e.globals??{}},variables:{...t.variables,...e.variables??{}},segments:qR(t.segments,GR(t.segments,e.segments??{})),root:aC(e.root??QS,t.root),actions:{...t.actions,...e.actions??{}},styles:{...t.styles,...e.styles??{}},presets:qR(t.presets,KR(t.presets,e.presets??{})),themeDefaults:qR(t.themeDefaults,e.themeDefaults??{}),editGlobals:{...t.editGlobals,...e.editGlobals??{}},helpers:{...t.helpers,...e.helpers??{}}}}function GR(e,t){return Object.fromEntries(Object.entries(t).map(([t,n])=>[t,n.settings===void 0?n:{...n,settings:{...e[t]?.settings,...n.settings}}]))}function KR(e,t){return Object.fromEntries(Object.entries(t).map(([t,n])=>[t,n.globals===void 0?n:{...n,globals:{...e[t]?.globals,...n.globals}}]))}function qR(e,t){return{...e,...Object.fromEntries(Object.entries(t).map(([t,n])=>[t,{...e[t],...n}]))}}function JR(e,t,n,r){return n.cache===void 0?(e.issues.push({path:`${t}.cache`,message:`${r} variables must declare a cache policy (one of: ${gy.join(`, `)})`,line:G(e.source,t.split(`.`))}),null):ZR(e,`${t}.cache`,n.cache)}function YR(e){return{required:!0,json:QR(),parse:(t,n,r,i)=>JR(t,n,i,e)??void 0}}const XR={noun:`cache`,arms:{ttl:{json:{type:`string`},parse:(e,t,n)=>typeof n==`string`&&ez(n)?{ttl:n}:ib(e,t,`cache.ttl must be a duration string like "5s", "100ms", "2m", "1h"; got ${K(n)}`)},watch_file:{json:{type:`string`,pattern:`^/`},parse:(e,t,n)=>{if(typeof n!=`string`)return ib(e,t,`cache.watch_file must be a path string, got ${K(n)}`);let r=db(`cache.watch_file`,n);return r===null?{watch_file:n}:ib(e,t,r)}},depends_on:{json:{type:`array`,items:{type:`string`}},parse:(e,t,n)=>Array.isArray(n)&&n.every(e=>typeof e==`string`)?{depends_on:n}:ib(e,t,`cache.depends_on must be an array of variable-name strings, got ${K(n)}`)},key:{json:{type:`string`},parse:(e,t,n)=>typeof n==`string`&&n!==``?{key:n}:ib(e,t,`cache.key must be a non-empty template string, got ${K(n)}`)},never:{json:{const:!0},parse:(e,t,n)=>n===!0?{never:!0}:ib(e,t,`cache.never must be the literal boolean true, got ${K(n)}`)}}};function ZR(e,t,n){return ab(e,XR,t,n)}function QR(){return mb(XR)}const $R=/^(\d+(?:\.\d+)?)(ms|s|m|h)$/;function ez(e){return $R.test(e)}const tz=new Map([[`session.budget.amount`,{segment:`session`,setting:`budget`}],[`session.budget.warningThreshold`,{segment:`session`,setting:`warnAt`}],[`today.budget.amount`,{segment:`today`,setting:`budget`}],[`today.budget.warningThreshold`,{segment:`today`,setting:`warnAt`}],[`block.budget.heatThreshold`,{segment:`block`,setting:`warnAt`}],[`block.budget.warningThreshold`,{segment:`block`,setting:`errorAt`}],[`weekly.budget.heatThreshold`,{segment:`weekly`,setting:`warnAt`}],[`weekly.budget.warningThreshold`,{segment:`weekly`,setting:`errorAt`}],[`burn.eta.errorMinutes`,{segment:`burnrate`,setting:`errorWithin`}],[`burn.eta.warnMinutes`,{segment:`burnrate`,setting:`warnWithin`}]]);function nz(e){return`it became the "${e.setting}" setting of each "${e.segment}" placement — set it on the placement where a row places "${e.segment}" ({ seg: "${e.segment}", settings: { ${e.setting}: <value> } }), or redeclare segments.${e.segment}.settings.${e.setting} with the default every placement should start from`}function rz(e){let t=tz.get(e);return t===void 0?void 0:`variables.${e} is no longer read: ${nz(t)}`}function iz(e){let t=tz.get(e);return t===void 0?``:` — ".${e}" is no longer a variable: ${nz(t)}; a "${t.segment}" template reads it as ".settings.${t.setting}"`}const az=new Map([[`git.timeSinceCommit`,`the payload stores the commit's date as "git.committedAt" (epoch seconds), and the bundled template variable "git.timeSinceCommit" computes its age at the draw: drop this declaration`],[`block.etaMinutes`,`the bundled template variable "block.etaMinutes" computes it at the draw: drop this declaration`],[`weekly.etaMinutes`,`the bundled template variable "weekly.etaMinutes" computes it at the draw: drop this declaration`]]),oz=new Map([[`branch`,{read:`.git.branch`,declare:{kind:`input`,path:`git.branch`,default:``},note:`when HEAD is on no branch it reads "detached", where this kind read ""`}],[`sha`,{read:`.git.sha`,declare:{kind:`input`,path:`git.sha`,default:``}}],[`dirty`,{read:`(ne .git.status "clean")`,declare:{kind:`template`,template:`{{ ne .git.status "clean" }}`,type:`boolean`}}],...[`ahead`,`behind`,`stash`].map(e=>[e,{read:`.git.${e}`,declare:{kind:`input`,path:`git.${e}`,type:`number`,default:0}}])]);function sz(e){let t=e=>typeof e==`string`&&e.includes(`"`)&&!e.includes(`'`)?`'${e}'`:JSON.stringify(e);return`{ ${Object.entries(e).map(([e,n])=>`${e}: ${t(n)}`).join(`, `)} }`}function cz(e){let t=`kind "git" is retired: every git fact is an input over the payload's git lane, which the bundled default already declares — drop this declaration and`,n=typeof e.field==`string`?oz.get(e.field):void 0;if(n===void 0){let e=[...oz.values()].map(({read:e})=>e);return`${t} read whichever of ${e.slice(0,-1).join(`, `)} or ${e.at(-1)} it stood for, where it was read`}let r=n.note===void 0?``:` (${n.note})`;return`${t} read ${n.read} where it was read${r}, or declare ${sz(n.declare)} under a name of your own`}function lz(e,t,n){if(n===void 0)return{};if(!Qy(n))return e.issues.push({path:t,message:`${t} must be an object, got ${$y(n)}`,line:G(e.source,t.split(`.`))}),{};let r={};for(let[i,a]of Object.entries(n)){let n=xee(e,Nz,`${t}.${i}`,a);n!==null&&(r[i]=n)}return r}function uz(){return{required:!0,json:{type:[`string`,`number`,`boolean`]},parse:(e,t,n,r)=>{let i=r.value;if(typeof i!=`string`&&typeof i!=`number`&&typeof i!=`boolean`){e.issues.push({path:`${t}.value`,message:`literal value must be string|number|boolean, got ${$y(i)}`,line:G(e.source,t.split(`.`))});return}return i}}}function dz(){return{required:!1,json:{type:[`string`,`number`,`boolean`]},parse:(e,t,n,r)=>{let i=r.type;return Jy(e,t,r,i===`number`||i===`boolean`||i===`string`?i:`string`)}}}const fz={noun:`parse`,arms:{text:{json:{const:!0},parse:(e,t,n)=>n===!0?{text:!0}:ib(e,t,`parse.text must be the literal boolean true, got ${K(n)}`)},regex:{json:{type:`string`},parse:(e,t,n)=>typeof n==`string`?pz(e,t,n):ib(e,t,`parse.regex must be a pattern string, got ${K(n)}`)},json:{json:{const:!0},parse:(e,t,n)=>n===!0?{json:!0}:ib(e,t,`parse.json must be the literal boolean true, got ${K(n)}`)}}};function pz(e,t,n){let r;try{new RegExp(n),r=RegExp(`${n}|`).exec(``).length-1}catch(n){return ib(e,t,`parse.regex is not a valid regular expression: ${n.message}`)}return r>=1?{regex:n}:ib(e,t,`parse.regex must contain a capture group — its group 1 is the value; got ${JSON.stringify(n)}`)}function mz(){return{required:!1,json:mb(fz),parse:(e,t,n,r)=>(r.regex!==void 0&&e.issues.push({path:`${t}.regex`,message:`${t}.regex was retired; the regex is the parse step's regex arm now: parse: { regex: ${JSON.stringify(r.regex)} }`,line:G(e.source,[...t.split(`.`),`regex`])}),r.parse===void 0?void 0:ab(e,fz,`${t}.parse`,r.parse)??void 0)}}function hz(){return{required:!1,json:{type:[`string`,`number`,`boolean`,`array`,`object`],description:`The value published when the source fails: a string under the text/regex parse arms, any non-null JSON value under the json arm`},parse:(e,t,n,r)=>Qy(r.parse)&&`json`in r.parse?gz(e,t,r.default):Yy(e,t,r,`default`)}}function gz(e,t,n){if(n!==void 0)return _z(n)?n:ib(e,`${t}.default`,`${t}.default must be a JSON value (a json-parsed source's document), got ${K(n)}`)??void 0}function _z(e){return e!==null&&vz(e)}function vz(e){if(e===null)return!0;switch(typeof e){case`string`:case`boolean`:return!0;case`number`:return Number.isFinite(e);case`object`:{if(Array.isArray(e))return e.every(vz);let t=Object.getPrototypeOf(e);return(t===Object.prototype||t===null)&&Object.values(e).every(vz)}default:return!1}}const yz={value:uz(),default:sb()};function bz(){let e=ub();return{...e,parse:(t,n,r,i)=>{let a=e.parse(t,n,r,i),o=a===void 0?void 0:az.get(a);return o===void 0?a:ib(t,`${n}.${r}`,`${n}.${r} "${a}" is no longer in the payload: ${o}`)??void 0}}}const xz={path:bz(),type:fb([`string`,`number`,`boolean`]),default:dz()},Sz={name:ub(),default:sb()},Cz={path:Eee(),readMode:fb([`whole`,`first-line`]),parse:mz(),cache:YR(`file`),default:hz()},wz={command:ub(),parse:mz(),cache:YR(`shell`),default:hz()};function Tz(e){return{cache:`${e}, so it takes no cache policy — delete the key`}}const Ez={template:ub(),type:fb([`string`,`number`,`boolean`]),default:dz()},Dz=Tz(`a template variable recomputes whenever a variable it reads changes`),Oz={layout:ub(),default:sb()},kz=Tz(`a time variable reads the instant its render is drawn at`),Az={key:ub(),default:sb()},jz=`kind`;function Mz(e,t,n={}){return{...See(jz,e,t),parse:(r,i,a)=>{tb(r,n,i,a);let o=nb(r,t,i,a);return o===null?null:{kind:e,...o}}}}const Nz={tag:jz,noun:`source kind`,memberNoun:`variable`,arms:{literal:Mz(`literal`,yz),input:Mz(`input`,xz),env:Mz(`env`,Sz),file:Mz(`file`,Cz),shell:Mz(`shell`,wz),template:Mz(`template`,Ez,Dz),time:Mz(`time`,Oz,kz),state:Mz(`state`,Az)},retired:{git:cz}};function Pz(){return kee(Nz)}function Fz(){return{type:`object`,additionalProperties:Pz()}}const Iz=new Map([[`gitTaculous`,{kind:`built-in`,to:`gitaculous`}],[`git`,{kind:`built-in`,to:`gitaculous`}],[`settings.menu`,{kind:`built-in`,to:`candybar.menu`}],[`ticket`,{kind:`plugin`,to:`plugins.lit.ticket`,source:`promptctl/links-issue-tracker`}],[`ceiling`,{kind:`removed`}]]);function Lz(e){let t=Iz.get(e);if(t===void 0)return``;switch(t.kind){case`built-in`:return` (the built-in segment "${e}" was renamed to "${t.to}" — update this reference)`;case`plugin`:return` (the built-in segment "${e}" became "${t.to}", a segment of the plugin \`cc-candybar plugin install ${t.source}\` installs — update this reference)`;case`removed`:return` (the built-in segment "${e}" was removed: the program it showed draws it through a cc-candybar plugin of its own now — delete this reference, or place that plugin's segment)`}}const Rz=/^[A-Za-z_][A-Za-z0-9_]*$/,zz={pattern:Rz.source},Bz={anyOf:[{type:`boolean`},{type:`string`},{type:`integer`}]},Vz={type:`object`,additionalProperties:!1,required:[`label`,`domain`,`default`],properties:{label:{type:`string`,pattern:`^[^\\n\\r]+$`},domain:{anyOf:[{const:`bool`},{type:`array`,items:{type:`string`,pattern:`^[^/\\n\\r]+$`},minItems:1,uniqueItems:!0},{type:`object`,additionalProperties:!1,required:[`min`,`max`],properties:{min:{type:`integer`},max:{type:`integer`},step:{type:`integer`,minimum:1},atLeast:{type:`string`,...zz}}}]},default:Bz}},Hz=[`label`,`domain`,`default`],Uz=[`min`,`max`,`step`,`atLeast`];function Wz(e,t,n){e.issues.push({path:t,message:n,line:G(e.source,t.split(`.`))})}function Gz(e,t,n){if(n===`bool`)return`bool`;if(Array.isArray(n)){let r=n.filter(e=>typeof e==`string`);if(n.length===0||r.length!==n.length)return Wz(e,t,`a list domain must be a non-empty list of words, got ${JSON.stringify(n)}`);if(new Set(r).size!==r.length)return Wz(e,t,`a list domain names each word once, got ${JSON.stringify(n)}`);let i=r.filter(e=>e===``||e.includes(`/`)||/[\n\r]/.test(e));return i.length>0?Wz(e,t,`a list domain's words must be non-empty, slash-free, and newline-free — configure mode writes each on the set-state wire — got ${JSON.stringify(i)}`):r}if(Qy(n)){let{min:r,max:i,step:a=1,atLeast:o}=n;return Object.keys(n).filter(e=>!Uz.includes(e)).length===0&&Number.isInteger(r)&&Number.isInteger(i)&&r<=i&&Number.isInteger(a)&&a>=1&&(o===void 0||typeof o==`string`)?{min:r,max:i,step:a,...o!==void 0&&{atLeast:o}}:Wz(e,t,`a range domain is { min, max, step?, atLeast? } with integers min ≤ max, a whole step ≥ 1, and atLeast naming another range setting, got ${JSON.stringify(n)}`)}return Wz(e,t,`domain must be "bool", a list of words, or { min, max }, got ${K(n)}`)}function Kz(e,t,n){if(!Qy(n))return Wz(e,t,`${t} must be { label, domain, default }, got ${$y(n)}`);for(let r of Object.keys(n))Hz.includes(r)||Wz(e,`${t}.${r}`,`Unknown setting key "${r}". Expected one of: ${Hz.join(`, `)}`);let{label:r}=n,i=typeof r==`string`&&r.length>0&&!/[\n\r]/.test(r);i||Wz(e,`${t}.label`,`a setting needs a one-line, non-empty "label" — the name its control shows, spliced into a synthesized template string — got ${K(r)}`);let a=Gz(e,`${t}.domain`,n.domain);if(!i||a===void 0)return;let o={label:r,domain:a,default:n.default};return!qz(n.default)||!ky(o,n.default)?Wz(e,`${t}.default`,`default must be ${Ny(o)}, got ${K(n.default)}`):o}function qz(e){return typeof e==`boolean`||typeof e==`string`||typeof e==`number`}const Jz={theme:`its default for this segment is segments.<name>.palette, and a placement sets its own with settings: { ${Cy}: "<theme>" }`,effect:`a placement follows the bar's effect, or sets its own with settings: { effect: "<effect>" }`};function Yz(e){return Ty.includes(e)}function Xz(){return{required:!1,json:{type:`object`,propertyNames:{...zz,not:{enum:[...Ty]}},additionalProperties:Vz},parse:(e,t,n,r)=>{let i=r[n];if(i===void 0)return;let a=`${t}.${n}`;if(!Qy(i))return Wz(e,a,`${a} must be an object of name → { label, domain, default }, got ${$y(i)}`);let o=Object.create(null);for(let[t,n]of Object.entries(i)){if(!Rz.test(t)){Wz(e,`${a}.${t}`,`setting name "${t}" is read as .settings.${t} in a template, so it must be an identifier (letters, digits, _; not starting with a digit)`);continue}if(Yz(t)){Wz(e,`${a}.${t}`,`setting "${t}" is one every placement already has — ${Jz[t]}`);continue}let r=Kz(e,`${a}.${t}`,n);r!==void 0&&(o[t]=r)}return o}}}const Zz=Sx.map(e=>e.replace(/\./g,`\\.`)).join(`|`);function Qz(){return{required:!1,json:{type:`string`,minLength:1,pattern:`^(?!${Zz})[^:/]+$`},parse:(e,t,n,r)=>{let i=r[n];if(i!==void 0)return typeof i==`string`&&i.length>0&&!/[:/]/.test(i)&&!Cx(i)?i:Wz(e,`${t}.${n}`,`a placement "id" must be a non-empty string without "/" or ":", outside the reserved ${Sx.map(e=>`"${e}"`).join(`, `)} namespaces, got ${K(i)}`)}}}function $z(){return{required:!1,json:{type:`object`,propertyNames:zz,additionalProperties:Bz},parse:(e,t,n,r)=>{let i=r[n];if(i===void 0)return;let a=`${t}.${n}`;if(!Qy(i))return Wz(e,a,`a placement's "settings" must be an object of setting name → value, got ${$y(i)}`);let o=Object.create(null);for(let[t,n]of Object.entries(i))qz(n)?o[t]=n:Wz(e,`${a}.${t}`,`setting "${t}" must be a boolean, a word, or a number, got ${$y(n)}`);return o}}}function eB(e){return new Set(Object.keys(e.segments).filter(e=>!Cx(e)))}function tB(e,t,n){if(t===void 0)return{};if(!Qy(t))return e.issues.push({path:`segments`,message:`segments must be an object, got ${$y(t)}`,line:G(e.source,[`segments`])}),{};let r={};for(let[i,a]of Object.entries(t)){let t=eb(e,n.has(i)?sB:oB,`segments.${i}`,a);t!==null&&(r[i]=t)}return r}function nB(){return{required:!0,json:{type:`string`},parse:(e,t,n,r)=>r[n]===void 0?ib(e,`${t}.${n}`,`${t} declares no template — only a segment the bundled default declares may omit it (inheriting the bundled template); a segment of your own needs its own${Lz(t.slice(9))}`)??void 0:qy(e,t,r,n)??void 0}}function rB(){return{required:!1,json:{anyOf:[{const:`auto`},{const:`fill`},{type:`integer`,minimum:1}]},parse:(e,t,n,r)=>{let i=r[n];if(i!==void 0){if(i===`auto`)return`auto`;if(i===`fill`)return`fill`;if(typeof i==`number`&&Number.isInteger(i)&&i>0)return i;e.issues.push({path:`${t}.${n}`,message:`width must be "auto", "fill", or a positive integer, got ${K(i)}`,line:G(e.source,[...t.split(`.`),n])})}}}}function iB(){return{required:!1,json:Fz(),parse:(e,t,n,r)=>{let i=r[n];if(i!==void 0)return lz(e,`${t}.${n}`,i)}}}const aB={template:nB(),description:sb(),group:fb(eP),width:rB(),justify:fb(Py),truncate:fb(Fy),bg:sb(),fg:sb(),when:sb(),palette:Tee(),vars:iB(),settings:Xz(),missingData:fb(by)},oB={noun:`segment key`,fields:aB},sB={noun:`segment key`,fields:{...aB,template:sb()}},cB=`#/definitions/LayoutNode`,lB={kind:`container`,direction:`vertical`,children:[]};function uB(e){return{required:!0,json:{const:e},parse:()=>e}}function dB(){return{required:!0,json:{type:`string`},parse:(e,t,n,r)=>{let i=r[n];return typeof i==`string`&&i.length>0?i:(e.issues.push({path:`${t}.${n}`,message:`a segment node must have a non-empty "name" (a segment name), got ${K(i)}`,line:G(e.source,[`root`])}),``)}}}function fB(){return{required:!0,json:{enum:[...iy]},parse:(e,t,n,r)=>{let i=r[n];return typeof i==`string`&&iy.includes(i)?i:(e.issues.push({path:`${t}.${n}`,message:`a container "direction" must be one of: ${iy.join(`, `)} (got ${JSON.stringify(i)})`,line:G(e.source,[`root`])}),`vertical`)}}}function pB(e){return{required:!0,json:{type:`array`,items:{$ref:cB}},parse:(t,n,r,i)=>{let a=i[r];return Array.isArray(a)?a.map((i,a)=>e(t,`${n}.${r}[${a}]`,i)):(t.issues.push({path:`${n}.${r}`,message:`a container must have a "children" array of layout nodes, got ${$y(a)}`,line:G(t.source,[`root`])}),[])}}}const mB={noun:`layout-node key`,fields:{kind:uB(`segment`),name:dB(),when:sb(),id:Qz(),settings:$z()}},hB=()=>fb(k_),gB={noun:`layout-node key`,fields:{kind:uB(`container`),direction:fB(),children:pB(ob(()=>xB)),when:sb(),distribution:hB()}};function _B(){return{required:!0,json:{type:`string`},parse:(e,t,n,r)=>{let i=r[n];return typeof i==`string`&&i.length>0?i:(e.issues.push({path:`${t}.${n}`,message:`a "seg" node must have a non-empty segment name, got ${K(i)}`,line:G(e.source,[...t.split(`.`),n])}),``)}}}const vB={noun:`layout-node key`,fields:{seg:_B(),when:sb(),id:Qz(),settings:$z()}},yB={noun:`layout-node key`,fields:{h:pB(ob(()=>xB)),when:sb(),distribution:hB()}},bB={noun:`layout-node key`,fields:{v:pB(ob(()=>xB)),when:sb(),distribution:hB()}},xB=(e,t,n)=>{if(typeof n==`string`)return n.length===0?(e.issues.push({path:t,message:`a bare-string layout node must be a non-empty segment name`,line:G(e.source,[`root`])}),lB):{kind:`segment`,name:n};if(!Qy(n))return e.issues.push({path:t,message:`a layout node must be a string (segment name) or an object with "kind" / "seg" / "h" / "v", got ${$y(n)}`,line:G(e.source,[`root`])}),lB;if(n.kind===`container`)return eb(e,gB,t,n)??lB;if(n.kind===`segment`)return eb(e,mB,t,n)??lB;if(n.kind===`cells`)return e.issues.push({path:t,message:`kind: "cells" is no longer supported — use the h-arm spelling instead:
183
183
  Old: { kind: "cells", segments: ["seg1", "seg2"] }
184
184
  New: { h: ["seg1", "seg2"] }`,line:G(e.source,[`root`])}),lB;if(n.kind===`group`){let r=eb(e,AB,t,n);return r===null?lB:(e.groups.push({name:r.name,label:r.label,...r.open!==void 0&&{open:r.open},...r.direction!==void 0&&{direction:r.direction},...r.key!==void 0&&{key:r.key},...r.bg!==void 0&&{bg:r.bg},...r.fg!==void 0&&{fg:r.fg},...r.when!==void 0&&{when:r.when},path:t}),MB(r))}let r=`h`in n,i=`v`in n,a=`seg`in n;if(+!!r+ +!!i+ +!!a>1){let r=[`seg`,`h`,`v`].filter(e=>e in n);return e.issues.push({path:t,message:`a layout node may have exactly one of "seg", "h", or "v" — got ${r.map(e=>`"${e}"`).join(` and `)} together`,line:G(e.source,[`root`])}),lB}if(a){let r=eb(e,vB,t,n);return r===null?lB:{kind:`segment`,name:r.seg,...r.when!==void 0&&{when:r.when},...r.id!==void 0&&{id:r.id},...r.settings!==void 0&&{settings:r.settings}}}if(r){let r=eb(e,yB,t,n);return r===null?lB:{kind:`container`,direction:`horizontal`,children:r.h,...r.when!==void 0&&{when:r.when},...r.distribution!==void 0&&{distribution:r.distribution}}}if(i){let r=eb(e,bB,t,n);return r===null?lB:{kind:`container`,direction:`vertical`,children:r.v,...r.when!==void 0&&{when:r.when},...r.distribution!==void 0&&{distribution:r.distribution}}}return e.issues.push({path:`${t}.kind`,message:`a layout node "kind" must be "container", "segment", or "group", or use the terse A-grammar: a bare string, or an object with "seg", "h", or "v" (got ${JSON.stringify(n.kind)})`,line:G(e.source,[`root`])}),lB};function SB(){return{required:!0,json:{type:`object`,propertyNames:{pattern:XS.source},additionalProperties:{$ref:cB}},parse:(e,t,n,r)=>{let i=r[n];if(!Qy(i))return e.issues.push({path:`${t}.${n}`,message:`"rows" must be an object of row name → layout node, got ${$y(i)}`,line:G(e.source,[...t.split(`.`),n])}),{};let a={};for(let[r,o]of Object.entries(i)){if(!XS.test(r)){e.issues.push({path:`${t}.${n}.${r}`,message:`row name "${r}" must be an identifier (letters, digits, _; not starting with a digit) — it names the row in the config file and merges by name over the bundled default's rows`,line:G(e.source,[...t.split(`.`),n,r])});continue}a[r]=xB(e,`${t}.${n}.${r}`,o)}return a}}}const CB={noun:`root key`,fields:{rows:SB(),when:sb(),distribution:hB()}};function wB(e,t,n){return Qy(n)&&`rows`in n?eb(e,CB,t,n)??{rows:{}}:xB(e,t,n)}const TB={noun:`insert key`,fields:{seg:_B(),id:Qz(),before:sb(),after:sb()}};function EB(e,t,n){return Array.isArray(t)?t.flatMap((t,r)=>{let i=`insert.${r}`,a=eb(e,TB,i,t);if(a===null)return[];let o=[`before`,`after`].filter(e=>a[e]!==void 0);if(o.length!==1)return e.issues.push({path:i,message:`an insert cell names exactly one of "before" or "after" (the placement id it sits beside), got ${o.length===0?`neither`:`both`}`,line:G(e.source,i.split(`.`))}),[];if(Cx(a.seg))return e.issues.push({path:`${i}.seg`,message:`an insert cell places a segment, and "${a.seg}" is the bar's own chrome — name a segment instead`,line:G(e.source,[...i.split(`.`),`seg`])}),[];let s=o[0],c=a[s];return Cx(c)?(e.issues.push({path:`${i}.${s}`,message:`an insert cell sits beside a placement, and "${c}" is the bar's own chrome — anchor on a placement id instead`,line:G(e.source,[...i.split(`.`),s])}),[]):[{seg:a.seg,...a.id!==void 0&&{id:a.id},anchor:c,relation:s,by:{file:n,entry:i}}]}):(e.issues.push({path:`insert`,message:`"insert" must be a list of cells like { seg: "name", after: "placement" }, got ${$y(t)}`,line:G(e.source,[`insert`])}),[])}function DB(){return{required:!0,json:{type:`string`,pattern:XS.source},parse:(e,t,n,r)=>{let i=r[n];if(typeof i!=`string`||!XS.test(i)||i===`closed`){e.issues.push({path:`${t}.${n}`,message:`a group "name" must be an identifier (letters, digits, _; not starting with a digit) and not the reserved "${Wi}", got ${K(i)}`,line:G(e.source,[`root`])});return}return i}}}function OB(){return{required:!1,json:{type:`string`,minLength:1},parse:(e,t,n,r)=>{let i=r[n];if(i!==void 0){if(typeof i!=`string`||i===``||i.includes(`/`)){e.issues.push({path:`${t}.${n}`,message:`a group "key" must be a non-empty, slash-free SessionState key, got ${K(i)}`,line:G(e.source,[`root`])});return}return i}}}}function kB(){return{required:!0,json:{type:`string`,pattern:`^[^\\n\\r]*$`},parse:(e,t,n,r)=>{let i=qy(e,t,r,n);if(i!==null){if(/[\n\r]/.test(i)){e.issues.push({path:`${t}.${n}`,message:`${t}.${n}: group label must not contain newlines`,line:G(e.source,[...t.split(`.`),n])});return}return i}}}}const AB={noun:`layout-node key`,fields:{kind:uB(`group`),name:DB(),label:kB(),open:cb(),direction:fb(iy),key:OB(),bg:sb(),fg:sb(),when:sb(),distribution:hB(),children:pB(ob(()=>xB))}};function jB(e){return e.key??`groups.`+e.name}function MB(e){let t=vx+e.name;return Yi(t,{variable:t,key:jB(e),member:e.name},{kind:`container`,direction:e.direction??`vertical`,children:e.children,...e.distribution!==void 0&&{distribution:e.distribution}},`drop`,e.when)}function NB(e,t,n){e.issues.push({path:t,message:n,line:G(e.source,[`root`])})}function PB(e,t){Tx(e,t,vx,`group nodes`);let n=e.groups;if(n.length===0)return;let r=new Set;for(let t of n)r.has(t.name)&&NB(e,t.path,`duplicate group name "${t.name}" — group names must be unique (they name the synthesized state var, action, and toggle segment)`),r.add(t.name);for(let t of n)for(let r of n)t!==r&&t.path.startsWith(`${r.path}.`)&&jB(t)===jB(r)&&NB(e,t.path,`group "${t.name}" shares key "${jB(t)}" with its ancestor group "${r.name}" — a shared key holds ONE open group, so an ancestor and a descendant cannot share one. Sibling accordions share a key; nested groups use distinct keys.`);let i=new Map;for(let t of n){let n=jB(t);if(i.has(n)||i.set(n,Wi),t.open===!0){let r=i.get(n);r!==`closed`&&NB(e,t.path,`groups "${r}" and "${t.name}" share key "${n}" and both declare open: true — a shared key holds one open group; pick one`),i.set(n,t.name)}}let a={},o={},s={};for(let e of n){let t=vx+e.name,r=jB(e),c=n.filter(t=>t!==e&&e.path.startsWith(t.path+`.`)).length,l=` `.repeat(c);a[t]=ta(r,i.get(r)),o[t]=na(r,e.name),s[t]={template:Qi(t,`${l}${e.label} ▸`,`${l}${e.label} ▾`),...e.bg!==void 0&&{bg:e.bg},...e.fg!==void 0&&{fg:e.fg}}}t.variables={...t.variables??{},...a},t.actions={...t.actions??{},...o},t.segments={...t.segments??{},...s}}const FB=`menu`,IB=`a menu binds its trigger text the way a cycle action binds a display — write {{ menu "applyTheme" "▸" "▾" }} (one per state) or {{ menu "insertHere" "+" }} (one static display for both), with the rare knobs in ONE trailing dict: {{ menu "applyTheme" "▸" "▾" (dict "closeOnPick" true "paged" false "key" "pickers") }} (defaults: closeOnPick false, paged true, no key). The renderer no longer appends ▸/▾ of its own (candybar-settings-ui-aok.4), and the older positional tail ("pageAction" closeOnPick paged "key") was removed — the page cursor is synthesized from the menu's identity`,LB=e=>e.kind===`call`&&e.name===`dict`,RB=e=>e.kind===`literal`&&typeof e.value!=`object`,zB=e=>Ki(``,e,2)===void 0;function BB(e){let t=e=>({kind:`issue`,message:e}),[n,...r]=e.argExprs;if(n===void 0)return t(`with no arguments — it takes an apply-action name and its trigger text (e.g. {{ menu "applyTheme" "▸" "▾" }})`);if(n.kind!==`literal`||typeof n.value!=`string`)return t(`whose apply action is not a string literal — a menu's identity is its apply-action name, which must be a literal so it can be gated at load (e.g. {{ menu "applyTheme" "▸" "▾" }})`);let i=r[r.length-1],a=i!==void 0&&LB(i)?i:void 0,o=a===void 0?r:r.slice(0,-1);if(o.some(LB))return t(`whose options (dict …) is not its last argument — ${IB}`);if(i!==void 0&&a===void 0&&!RB(i)&&zB(o.length-1))return t(`whose last argument is neither a literal nor a literal (dict …) — the renderer tells a display from the options dict by the value it evaluates to, so this call could be read as ${o.length} displays or as ${o.length-1} plus options, and both are legal. Make the options explicit as a trailing (dict …) — {{ menu "${n.value}" (printf "…") (printf "…") (dict) }} binds dynamic displays unambiguously — or bind the trigger text as literals`);let s=Ki(`whose trigger`,o.length,2);if(s!==void 0)return t(`${s} — ${IB}`);let c=a===void 0?{}:OO(a);if(c===null)return t(`whose options (dict …) is not fully literal — every option value must be a literal so the menu can be gated at load (a dynamic entry like (dict "key" .x) cannot)`);let l;try{l=$M(c)}catch(e){return t(`with invalid options — ${e.message}`)}let u=l.key;if(u!==void 0){let e=wx(u);if(e!==void 0)return t(`whose accordion key "${u}" lands in the reserved "${e}" namespace — a key is collapsed to an identifier (${JSON.stringify(u)} becomes "${qM(u)}"), so it would share one open-state key with the synthesized accordion that owns that namespace instead of grouping only your own menus. Name the group without the reserved prefix`)}return{kind:`ok`,apply:n.value,options:l}}function VB(e){let t=LE({fromString:e=>e});try{return t.parse(e).referencedCalls().filter(e=>e.name===FB).map(BB)}catch{return`parse-failed`}}function HB(e,t){let n=VB(e);return n===`parse-failed`?[]:n.flatMap(e=>e.kind===`ok`?[{key:KM(t,e.apply,e.options.key),member:GM(e.apply)}]:[])}function UB(e){let t=LE({fromString:e=>e});try{return t.parse(e).referencedFunctions().has(FB)}catch{return!1}}function WB(e,t,n){e.issues.push({path:t,message:n,line:G(e.source,[`root`])})}function GB(e,t){Tx(e,t,yx,`{{ menu }} helpers`),Tx(e,t,bx,`{{ menu }} helpers`);for(let[n,r]of Object.entries(t.helpers??{}))UB(r)&&e.issues.push({path:`helpers.${n}`,message:`helper "${n}" uses {{ menu }}, but a menu must live directly in a segment template — its identity is derived from the segment it sits in, which a shared helper does not have. Inline the {{ menu }} call into each segment that needs it.`,line:G(e.source,[`helpers`,n])});let n=t.segments??{};for(let[t,r]of Object.entries(n))for(let n of[`bg`,`fg`,`when`]){let i=r[n];typeof i==`string`&&UB(i)&&WB(e,`segments.${t}.${n}`,`segment "${t}" uses {{ menu }} in its "${n}" — a menu is only valid in a segment's "template" (its placement is published only there; "${n}" needs a ${n===`when`?`predicate`:`color`}). Move the {{ menu }} into the template.`)}if(t.root!==void 0)for(let n of uy(rC(t.root)))typeof n.when==`string`&&UB(n.when)&&WB(e,`root`,`a layout node's "when" predicate uses {{ menu }} — a menu is only valid in a segment's "template", not a node predicate. Move it into a segment.`);for(let[t,{template:r}]of Object.entries(n)){if(r===void 0||!UB(r))continue;let n=VB(r);if(n!==`parse-failed`)for(let r of n){let n=r.kind===`issue`?r.message:KB(r.apply);n!==void 0&&WB(e,`segments.${t}`,`segment "${t}" has a {{ menu }} ${n}.`)}}}function KB(e){if(e===``)return`with an empty apply-action name — an empty member aliases the absent-state sentinel ("") so the menu would render open before any click. Name the apply action`;if(GM(e)===`closed`)return`whose apply action is named "${Wi}", which collides with the menu's closed-state sentinel and leaves it unopenable. Rename the action`}function qB(e,t){let n={},r={},i=new Map,a=new Set,o=(e,n)=>{let r=`segments.${e}`;a.has(`${r}\0${n}`)||(a.add(`${r}\0${n}`),t.push({path:r,message:n}))};for(let t of mC(e.presets)){let a=new Map,s=new Map;for(let c of uy(_C(e,t).node)){if(c.kind!==`segment`)continue;let t=e.segments[c.name];if(t===void 0)continue;i.has(c.name)||i.set(c.name,VB(t.template));let l=i.get(c.name);if(l===`parse-failed`)continue;let u=oy(c);for(let[e,t]of l.entries()){if(t.kind===`issue`||KB(t.apply)!==void 0)continue;let{apply:i,options:l}=t,d=GM(i),f=KM(u,i,l.key),p=YM(f),m=l.key===void 0?`ind ${u} ${i}`:`key ${l.key}`,h=[f,p].find(e=>{let t=a.get(e);return t!==void 0&&t!==m});if(h!==void 0){o(c.name,`two {{ menu }} disclosures normalize to the same state key ("${h}") but were declared differently — distinct names that differ only by non-alphanumeric characters (e.g. "a-b" vs "a_b") collapse to one key and would silently share open-state. Rename so they don't collide.`);continue}a.set(f,m),a.set(p,m);let g=JM(f,d),_=`${c.name}\0${e}`,v=s.get(g);if(v!==void 0&&v!==_){o(c.name,`two {{ menu }} disclosures resolve to the same identity ("${g}") — ${l.key===void 0?`a segment cannot contain two menus over the same apply action "${i}"`:`menus sharing key "${l.key}" must have distinct apply actions`}.`);continue}s.set(g,_),r[g]=na(f,d),n[f]=ta(f,Wi),n[p]={kind:`state`,key:p,default:`0`},r[p]={set:p,int:!0}}}}return{...e,variables:{...e.variables,...n},actions:{...e.actions,...r}}}function JB(e,t,n){if(t===void 0)return{};if(!Qy(t))return Z(e,`actions`,`actions must be an object, got ${$y(t)}`),{};let r=Object.create(null);for(let[i,a]of Object.entries(t)){let t=YB(e,`actions.${i}`,a,n);t!==null&&(r[i]=t)}return r}function Z(e,t,n){e.issues.push({path:t,message:n,line:G(e.source,t.split(`.`))})}function YB(e,t,n,r){if(!Qy(n))return Z(e,t,`${t} must be an action object, got ${$y(n)}`),null;if(`persistWhen`in n)return Z(e,t,`${t}.persistWhen was removed: declare the \`set\` alone — a session pick is a draft until a \`{ save: true }\` action writes every unsaved setting to the config file`),null;let i=kC.filter(e=>e in n);return i.length===1?ZB(r)[i[0]](e,t,n):(Z(e,t,`action must declare exactly one of: ${kC.join(`, `)}${i.length>1?` (found: ${i.join(`, `)})`:``}`),null)}function XB(e){return o.isAbsolute(e)?{dir:o.dirname(e)}:{text:e}}const ZB=e=>({set:(e,t,n)=>NV(e,t,n,`set`,kV),persist:(e,t,n)=>NV(e,t,n,`persist`,AV),copy:QB(`copy`),open:QB(`open`),reset:$B,undo:tV(`undo`),redo:tV(`redo`),back:tV(`back`),rewind:tV(`rewind`),save:tV(`save`),preset:nV,themeDefault:rV,doctor:aV,slash:oV,run:lV(e),do:uV});function QB(e){return(t,n,r)=>{for(let i of Object.keys(r))i!==e&&Z(t,`${n}.${i}`,`Unknown key "${i}" on a ${e} action. Expected only: ${e}`);let i=qy(t,n,r,e);return i===null?null:{[e]:i}}}function $B(e,t,n){for(let r of Object.keys(n))r!==`reset`&&Z(e,`${t}.${r}`,`Unknown key "${r}" on a reset action. Expected only: reset`);let r=dV(e,t,`reset`,n,`reset key must be non-empty (the config globals field to clear)`,e=>`reset key "${e}" contains "/" — keys must be slash-free`);return r===null?null:{reset:r}}const eV={undo:`it steps the session's settings history`,redo:`it steps the session's settings history`,back:`it steps the session's navigation history`,rewind:`it steps the session's settings history back to where edit mode opened`,save:`it saves the session's unsaved settings`};function tV(e){return(t,n,r)=>{for(let i of Object.keys(r))i!==e&&Z(t,`${n}.${i}`,`Unknown key "${i}" on a ${e} action. Expected only: ${e}`);return r[e]===!0?{[e]:!0}:(Z(t,`${n}.${e}`,`${e} must be the literal true (it takes no key — ${eV[e]}), got ${K(r[e])}`),null)}}function nV(e,t,n){let r=n.preset,i=r===`save`?[`preset`]:[`preset`,`name`];for(let r of Object.keys(n))i.includes(r)||Z(e,`${t}.${r}`,`Unknown key "${r}" on a preset action. Expected only: ${i.join(`, `)}`);if(r!==`save`&&r!==`delete`)return Z(e,`${t}.preset`,`preset must be "save" or "delete", got ${K(r)}`),null;if(r===`save`)return{preset:`save`};let a=qy(e,t,n,`name`);return a===null?null:{preset:`delete`,name:a}}function rV(e,t,n){for(let r of Object.keys(n))r!==`themeDefault`&&Z(e,`${t}.${r}`,`Unknown key "${r}" on a themeDefault action. Expected only: themeDefault`);return n.themeDefault===`save`?{themeDefault:`save`}:(Z(e,`${t}.themeDefault`,`themeDefault must be "save" (it saves the look the session draws as the active theme's default), got ${K(n.themeDefault)}`),null)}const iV={run:[`doctor`],fix:[`doctor`,`check`],mark:[`doctor`,`check`,`mark`]};function aV(e,t,n){let r=n.doctor,i=typeof r==`string`&&Object.hasOwn(iV,r),a=i?iV[r]:[...new Set(Object.values(iV).flat())];for(let r of Object.keys(n))a.includes(r)||Z(e,`${t}.${r}`,`Unknown key "${r}" on a doctor action. Expected only: ${a.join(`, `)}`);if(!i)return Z(e,`${t}.doctor`,`doctor must be ${Object.keys(iV).map(e=>`"${e}"`).join(`, `)}, got ${K(r)}`),null;if(r===`run`)return{doctor:`run`};let o=n.check,s=r===`mark`?yte:DF;if(typeof o!=`string`||!s.some(e=>e.name===o))return Z(e,`${t}.check`,`doctor ${r} must name a check (have: ${s.map(e=>e.name).join(`, `)}), got ${K(o)}`),null;if(r===`fix`)return{doctor:`fix`,check:o};let c=n.mark;return cF.includes(c)?{doctor:`mark`,check:o,mark:c}:(Z(e,`${t}.mark`,`doctor mark must be ${cF.map(e=>`"${e}"`).join(` or `)}, got ${K(c)}`),null)}function oV(e,t,n){for(let r of Object.keys(n))r!==`slash`&&Z(e,`${t}.${r}`,`Unknown key "${r}" on a slash action. Expected only: slash`);let r=HF(n.slash);return r.kind===`refused`?(Z(e,`${t}.slash`,r.reason),null):{slash:r.line}}const sV=[`run`,`env`,`refreshes`],cV=/^[A-Za-z_][A-Za-z0-9_]*$/;function lV(e){return(t,n,r)=>{for(let e of Object.keys(r))sV.includes(e)||Z(t,`${n}.${e}`,`Unknown key "${e}" on a run action. Expected only: ${sV.join(`, `)}`);let i=t.issues.length,a=r.run;(!Array.isArray(a)||a.length===0||a.some(e=>typeof e!=`string`)||a[0]===``)&&Z(t,`${n}.run`,`run must list the program and its arguments, each a template string, the program first and not empty, got ${K(a)}`);let o=r.env??{};(!Qy(o)||Object.entries(o).some(([e,t])=>!cV.test(e)||typeof t!=`string`))&&Z(t,`${n}.env`,`env must map variable names (letters, digits and _, not starting with a digit) to template strings, got ${K(o)}`);let s=r.refreshes??[];return(!Array.isArray(s)||s.some(e=>typeof e!=`string`||e===``))&&Z(t,`${n}.refreshes`,`refreshes must list the names of the sources the program writes, got ${K(s)}`),`dir`in e||Z(t,`${n}.run`,`a run action runs in the directory of the file that declares it, and ${e.text} is no file`),t.issues.length>i||!(`dir`in e)?null:{run:a,env:o,refreshes:s,cwd:e.dir}}}cV.source;function uV(e,t,n){for(let r of Object.keys(n))r!==`do`&&Z(e,`${t}.${r}`,`Unknown key "${r}" on a do action. Expected only: do`);let r=n.do;return!Array.isArray(r)||r.length<2||r.some(e=>typeof e!=`string`||e===``)?(Z(e,`${t}.do`,`do must list at least two action names (the first is the click's face, the rest ride along in the same click), got ${K(r)}`),null):{do:r}}function dV(e,t,n,r,i,a){let o=qy(e,t,r,n);if(o===null)return null;let s=`${t}.${n}`;return o===``?(Z(e,s,i),null):o.includes(`/`)?(Z(e,s,a(o)),null):o}const fV={set:`the SessionState key to write`,persist:`the config globals field to write`};function pV(e,t,n,r){let i=fV[r],a=dV(e,t,r,n,`${r} key must be non-empty (${i})`,e=>`${r} key "${e}" contains "/" — keys must be slash-free`);return a===null?null:{[r]:a}}function mV(e){return e===`set`?`set-state`:`set-config`}const hV={to:PV(`set`)},gV={to:PV(`persist`)},_V={from:FV(`set`)},vV={from:FV(`persist`)},yV={min:BV(),max:BV(),by:BV()},bV={int:LV()},xV={cycle:IV(`set`)},SV={cycle:IV(`persist`)},CV={removeSegment:RV(`removeSegment`)},wV={insertSegment:RV(`insertSegment`),anchor:RV(`anchor`),relation:zV()},TV={insertSegmentFrom:FV(`persist`),anchor:RV(`anchor`),relation:zV()},EV={ok:e=>e.min<e.max,issue:e=>({field:`min`,message:`min (${e.min}) must be less than max (${e.max})`})},DV={ok:e=>e.by!==0,issue:()=>({field:`by`,message:`by must be a non-zero integer (the per-click increment; negative steps down)`})};function OV(e,t,n=[],r){let i=Object.keys(t),a=r??i,o=[e],s=(e,n,r)=>nb(e,t,n,r),c=pb(t);return{detect:a,allowed:[...o,...i],label:i.join(`/`),json:{type:`object`,properties:{...Object.fromEntries(o.map(e=>[e,{type:`string`}])),...c.properties},required:[...o,...c.required??[]],additionalProperties:!1},parse:n.length?Cee(s,...n):s}}const kV=[OV(`set`,hV),OV(`set`,_V),OV(`set`,yV,[EV,DV]),OV(`set`,bV),OV(`set`,xV)],AV=[OV(`persist`,gV),OV(`persist`,vV),OV(`persist`,yV,[EV,DV]),OV(`persist`,SV),OV(`persist`,CV),OV(`persist`,wV,[],[`insertSegment`]),OV(`persist`,TV,[],[`insertSegmentFrom`])];function jV(e){let t=[`"to" (a literal value)`,`"from" (an option domain — a registered domain name like "themes"/"endcaps"/"styles", or an inline array of literal values)`,`"min"/"max"/"by" (a bounded step)`];return e===`set`&&t.push(`"int" (an unbounded integer cursor)`),t.push(`"cycle" (an enumerated domain stepped in order)`),e===`persist`&&t.push(`"removeSegment" (remove a named segment from the layout)`,`"insertSegment"/"anchor"/"relation" (insert a named segment before/after an existing one)`,`"insertSegmentFrom"/"anchor"/"relation" (insert a segment PICKED from an option domain before/after an existing one)`),t}function MV(e){let t=jV(e),n=t[t.length-1];return`a ${e} action declares exactly one value source: ${t.length===1?n:`${t.slice(0,-1).join(`, `)}, or ${n}`}`}function NV(e,t,n,r,i){let a=pV(e,t,n,r),o=i.filter(e=>e.detect.some(e=>e in n));if(o.length!==1)return Z(e,t,`${MV(r)}${o.length>1?` — found: ${o.map(e=>e.label).join(`, `)}`:``}`),null;let s=o[0];for(let i of Object.keys(n))s.allowed.includes(i)||Z(e,`${t}.${i}`,`Unknown key "${i}" on this ${r} action. Expected one of: ${s.allowed.join(`, `)}`);let c=s.parse(e,t,n);return a===null||c===null?null:{...a,...c}}function PV(e){let t=mV(e);return{required:!0,json:{type:`string`},parse:(n,r,i,a)=>dV(n,r,i,a,`${e} value must be non-empty — an empty value cannot be delivered on the ${t} wire`,t=>`${e} value "${t}" contains "/" — ${e} values must be slash-free`)??void 0}}function FV(e){let t=mV(e);return{required:!0,json:{anyOf:[{type:`string`,minLength:1},{type:`array`,items:{type:`string`,minLength:1},minItems:1,uniqueItems:!0}]},parse:(n,r,i,a)=>{let o=a[i],s=`${r}.${i}`;if(typeof o==`string`){if(o===``){Z(n,s,`${i} must be a non-empty domain name`);return}return o}if(Array.isArray(o)&&o.every(e=>typeof e==`string`)){let r=o;if(r.length===0){Z(n,s,`${i} must name a domain (a non-empty string) or declare an inline domain (a non-empty array of values)`);return}if(r.some(e=>e===``)){Z(n,s,`${i} array members must be non-empty — an empty value cannot be delivered on the ${t} wire`);return}let a=r.filter(e=>e.includes(`/`));if(a.length>0){Z(n,s,`${i} array member(s) ${a.map(e=>`"${e}"`).join(`, `)} contain "/" — ${e} values must be slash-free`);return}if(new Set(r).size!==r.length){Z(n,s,`${i} array members must be unique — a duplicated value would render the same picker option twice`);return}return r}Z(n,s,`${i} must be a domain name (a string) or an inline domain (an array of strings), got ${K(o)}`)}}}function IV(e){let t=mV(e);return{required:!0,json:{type:`array`,items:{type:`string`,minLength:1},minItems:2,uniqueItems:!0},parse:(n,r,i,a)=>{let o=a[i],s=`${r}.${i}`;if(!Array.isArray(o)||o.some(e=>typeof e!=`string`)){Z(n,s,`cycle must be an array of strings (the enumerated values a click steps through), got ${$y(o)}`);return}let c=o;if(c.length<2){Z(n,s,`cycle needs at least two members (one member has no successor — use a literal "to")`);return}let l=c.some(e=>e===``),u=c.filter(e=>e.includes(`/`));if(l){Z(n,s,`cycle members must be non-empty — an empty value cannot be delivered on the ${t} wire`);return}if(u.length>0){Z(n,s,`cycle member(s) ${u.map(e=>`"${e}"`).join(`, `)} contain "/" — ${e} values must be slash-free`);return}if(new Set(c).size!==c.length){Z(n,s,`cycle members must be unique — the successor of a duplicated member is ambiguous`);return}return c}}}function LV(){return{required:!0,json:{const:!0},parse:(e,t,n,r)=>{if(r[n]!==!0){Z(e,`${t}.${n}`,`int must be the literal true (declares the key an unbounded integer cursor — a paged picker's page key), got ${K(r[n])}`);return}return!0}}}function RV(e){return{required:!0,json:{type:`string`},parse:(t,n,r,i)=>{let a=qy(t,n,i,r);if(a===null)return;let o=`${n}.${r}`;if(a===``){Z(t,o,`${e} must be non-empty (a segment name)`);return}if(a.includes(`/`)||a.includes(`:`)){Z(t,o,`${e} "${a}" contains "/" or ":" — segment names in a layout op must be free of both (the click wire's own delimiter and layout-ops.ts's op-token delimiter)`);return}return a}}}function zV(){return{required:!0,json:{enum:[`before`,`after`]},parse:(e,t,n,r)=>{let i=r[n];if(i!==`before`&&i!==`after`){Z(e,`${t}.${n}`,`relation must be "before" or "after", got ${K(i)}`);return}return i}}}function BV(){return{required:!0,json:{type:`integer`},parse:(e,t,n,r)=>{let i=r[n];if(typeof i!=`number`||!Number.isInteger(i)){Z(e,`${t}.${n}`,`${n} must be an integer, got ${K(i)}`);return}return i}}}function VV(e,t,n){return`${e}: "${t}" is an endcaps shape, not a style — endcaps were renamed from "style" to "endcaps"; write ${n}: "${t}"`}const HV={noun:`style key`,fields:{hueShift:lb(),chromaScale:lb({min:0}),lightnessScale:lb(),lightnessShift:lb()}};function UV(e,t){if(!Qy(t))return e.issues.push({path:`styles`,message:`styles must be an object mapping style names to adaptation objects, got ${$y(t)}`,line:G(e.source,[`styles`])}),{};let n={};for(let[r,i]of Object.entries(t)){if(r===``||r.includes(`/`)){e.issues.push({path:`styles.${r}`,message:`style name ${JSON.stringify(r)} must be non-empty and slash-free — a style picker writes the name on the set-state wire, which rejects empty values and splits on "/"`,line:G(e.source,[`styles`,r])});continue}if(Kv(r)){e.issues.push({path:`styles.${r}`,message:VV(`styles.${r}`,r,`globals.endcaps`),line:G(e.source,[`styles`,r])});continue}let t=eb(e,HV,`styles.${r}`,i);t!==null&&(n[r]={...Kl,...t})}return n}const WV={noun:`preset key`,fields:{root:{required:!1,json:{$ref:`#/definitions/RootFragment`},parse:(e,t,n,r)=>r[n]===void 0?void 0:wB(e,`${t}.${n}`,r[n])},globals:{required:!1,json:IN(),parse:(e,t,n,r)=>r[n]===void 0?void 0:FN(e,`${t}.${n}`,r[n])}}};function GV(e,t){if(!Qy(t))return e.issues.push({path:`presets`,message:`presets must be an object mapping preset names to config fragments, got ${$y(t)}`,line:G(e.source,[`presets`])}),{};let n={};for(let[r,i]of Object.entries(t)){if(r===``||r.includes(`/`)||/[\n\r]/.test(r)){e.issues.push({path:`presets.${r}`,message:`preset name ${JSON.stringify(r)} must be non-empty, slash-free, and newline-free — a preset picker writes the name on the set-state wire (which rejects empty values and splits on "/"), and edit mode splices it into a synthesized template string`,line:G(e.source,[`presets`,r])});continue}let t=eb(e,WV,`presets.${r}`,i);t!==null&&(n[r]=t)}return n}function KV(e,t){if(t===void 0)return{};if(!Qy(t))return e.issues.push({path:`helpers`,message:`helpers must be an object, got ${$y(t)}`,line:G(e.source,[`helpers`])}),{};let n=Object.create(null);for(let[r,i]of Object.entries(t)){if(typeof i!=`string`){e.issues.push({path:`helpers.${r}`,message:`helpers.${r} must be a string template body, got ${K(i)}`,line:G(e.source,[`helpers`,r])});continue}n[r]=i}return n}function qV(e,t){let n=[...t].map(([e,t])=>[mx(e),t]);return t=>{if(CL(t)||Object.hasOwn(e,t))return{kind:`declared`};let r=n.find(([e])=>e(t));if(r!==void 0)return{kind:`plugin`,definition:r[1]};let i=gx(t);return i!==void 0&&i!==t?{kind:`absent`}:{kind:`missing`}}}function JV(e){return e.kind===`plugin`||e.kind===`missing`}function YV(e,t,n){let r=new Map,i=(e,t)=>{r.set(e,[...r.get(e)??[],t])},a=e=>$S(e)?Object.values(e.rows):[e],o=[e.root,...Object.values(e.presets).flatMap(e=>e.root===void 0?[]:[e.root])];for(let e of o.flatMap(a))for(let t of uy(e))t.kind===`segment`&&i(oy(t),{seg:t.name});for(let e of t)i(e.id??e.seg,{seg:e.seg,anchor:e.anchor});let s=new Set,c=e=>n(e.seg).kind===`absent`||e.anchor!==void 0&&s.has(e.anchor);for(let e=!0;e;){e=!1;for(let[t,n]of r)!s.has(t)&&n.every(c)&&(s.add(t),e=!0)}return e=>s.has(e)}function XV(e){let t=0,n=qV(e.segments,new Map),r=e=>{let r=n(e).kind===`declared`;return r||(t+=1),r},i=e=>({...e,children:e.children.flatMap(e=>a(e))}),a=e=>e.kind===`container`?[i(e)]:r(e.name)?[ly(e,i)]:[],o=e=>a(e)[0]??ZV,s=e=>({...e,rows:Object.fromEntries(Object.entries(e.rows).map(([e,t])=>[e,o(t)]))}),c=e=>$S(e)?s(e):o(e),l=e=>e.root===void 0?e:{...e,root:c(e.root)},u={...e,root:s(e.root),presets:Object.fromEntries(Object.entries(e.presets).map(([e,t])=>[e,l(t)]))};return t===0?e:u}const ZV={kind:`container`,direction:`horizontal`,children:[]};function QV({names:e,helpers:t,actions:n}){let r=(e,t)=>{let i=Object.hasOwn(n,e)?n[e]:void 0;return i===void 0||t.has(e)?[]:(t.add(e),[...[...jC(i)].map(([,e])=>e),...`do`in i?i.do.flatMap(e=>r(e,t)):[]])},i=WC(e=>{let i=tw(e,t)?Object.keys(n):$C(e,t).map(e=>e.name),a=new Set;return[e,...i.flatMap(e=>r(e,a))]}),a=WC(n=>i(n).flatMap(n=>[...YC(n,t).keys()].map(t=>({path:t,reaches:uw(t,e)}))));return{ofTemplate:a,calls:WC(e=>new Set(i(e).flatMap(e=>[...rw(e,t)]))),ofVariable:t=>[...yy(t).flatMap(([e,t])=>a(t).map(t=>({...t,field:e}))),..._y(t)&&`depends_on`in t.cache?t.cache.depends_on.map(t=>({path:t,reaches:e.has(t)?[t]:[],field:`cache.depends_on`})):[]]}}function $V(e,t){switch(t.kind){case`input`:return t.path;case`source`:return e;default:return}}const eH=new WeakMap;function tH(e){let t=eH.get(e);return t===void 0&&(t=QV({names:new Set([...lw(e)].map(([e])=>e)),helpers:e.helpers,actions:e.actions}),eH.set(e,t)),t}function nH(e,t){for(let n of t.reads.calls(e))if(t.clock.has(n))return`calls "${n}"`;for(let{reaches:n}of t.reads.ofTemplate(e))for(let e of n){let n=t.projections.get(e);if(n!==void 0)return`reads "${e}", which ${n}`}return null}const rH=new WeakMap;function iH(e){let t=rH.get(e);return t===void 0&&(t=oH(e),rH.set(e,t)),t}function aH(e){return iH(e).projections}function oH(e){let t=new Map(lw(e)),n=new Map,r={reads:tH(e),projections:n,clock:Xj};for(let[e,r]of t){r.kind===`time`&&n.set(e,`is a time variable`);let t=$V(e,r),i=t===void 0?null:BM(t);i&&n.set(e,`reads the draw's "${i}" (${zM[i]})`)}let i=cH(e),a=new Map;for(let e=!0;e;){e=!1;for(let[i,a]of t){if(a.kind!==`template`||n.has(i))continue;let t=nH(a.template,r);t!==null&&(n.set(i,t),e=!0)}for(let t of Dv)if(!a.has(t))for(let n of i[t]){let i=nH(n,r);if(i!==null){a.set(t,i),e=!0;break}}for(let[r,i]of t){let t=$V(r,i);if(t===void 0||n.has(r))continue;let o=HM(t),s=o===void 0?void 0:a.get(o);s!==void 0&&(n.set(r,`reads the ${o} rule, which ${s}`),e=!0)}}return r}function sH(e){return[[[`globals`],e.globals],...Object.entries(e.presets??{}).map(([e,t])=>[[`presets`,e,`globals`],t.globals??{}])].flatMap(([e,t])=>Dv.flatMap(n=>{let r=t[n];return Ov(r)?[{at:[...e,n],slot:n,rule:r}]:[]}))}function cH(e){let t=sH(e),n=e=>t.flatMap(t=>t.slot===e?[t.rule]:[]);return{style:n(`style`),palette:n(`palette`),effect:n(`effect`)}}function lH(e,t){return nH(e,iH(t))}function uH(e){return t=>nH(t,e)!==null}const dH={nested:e=>`${e} sets "distribution" on a container inside a row — the row's own container places every cell along it, through any { h } or { v } nested in it, so this one would place nothing. Set it on the row (the outermost horizontal container), or, on the bar, on the root, which places the rows.`,bar:e=>`${e} sets "distribution" on a vertical container none of whose children is a segment or a horizontal container — a bar row's hue is placed by the innermost vertical container it stacks through, so it would place nothing. Set it on that container, or on the row whose children are the cells (the horizontal container).`,band:e=>`${e} sets "distribution" on a vertical container in a disclosure body — a body's items are placed along their rows, never by which row they sit on, so it would place nothing. Set it on the row whose children are the items (the horizontal container), or give a group \`direction: 'horizontal'\`.`};function fH(e,t){let n=new Map;for(let e of Object.keys(t)){let t=dx(e),r=n.get(t);r?r.push(e):n.set(t,[e])}for(let[t,r]of n)r.length<2||e.issues.push({path:`presets`,message:`preset names ${r.map(e=>JSON.stringify(e)).join(` and `)} both collapse to the same synthesis identifier "${t}" — edit mode's synthesized reset affordance would silently steal one preset's action for the other. Rename one.`,line:G(e.source,[`presets`])})}function pH(e,t){let n=[[`root`,e.root],...Object.entries(e.presets??{}).map(([e,t])=>[`presets.${e}.root`,t.root])];for(let[e,r]of n)if(r!==void 0){for(let[n,i]of iC(r,e))if(n.kind===`segment`&&n.name===t)return{layoutKey:e,path:i}}}const mH=(e,t,n,r)=>r.kind===`plugin`?`${e} entry "${t}" does not match any segment plugin "${px(r.definition)}" declares — the plugin loaded from ${r.definition.path} declares: ${hH(px(r.definition),n)}${gH(t,n)}`:`${e} entry "${t}" does not match any declared segment${gH(t,n)}`;function hH(e,t){let n=Object.keys(t).filter(mx(e)).sort();return n.length===0?`no segments`:n.map(e=>{let n=Object.keys(t[e].settings??{});return`${e} (${n.length===0?`no settings`:`settings: ${n.join(`, `)}`})`}).join(`, `)}function gH(e,t){return Lz(e)+_x(e,e=>Object.hasOwn(t,e))}function _H(e,t,n,r){let i=[[[`globals`],t.globals.style,`globals.endcaps`],[[`editGlobals`],t.editGlobals.style,`editGlobals.endcaps`],...Object.entries(t.presets).map(([e,t])=>[[`presets`,e,`globals`],t.globals?.style,`presets.${e}.globals.endcaps`]),...Object.entries(t.themeDefaults).map(([e,t])=>[[`themeDefaults`,e],t.style,`globals.endcaps`])];for(let[n,r,a]of i){if(r===void 0||Ov(r)||Object.prototype.hasOwnProperty.call(t.styles,r))continue;let i=`${n.join(`.`)}.style`;e.issues.push({path:i,message:Kv(r)?VV(i,r,a):`${i} "${r}" does not match any declared style (have: ${Object.keys(t.styles).join(`, `)})`,line:G(e.source,[...n,`style`])})}t.globals.preset!==void 0&&!Object.prototype.hasOwnProperty.call(t.presets,t.globals.preset)&&e.issues.push({path:`globals.preset`,message:`globals.preset "${t.globals.preset}" does not match any declared preset (have: ${Object.keys(t.presets).join(`, `)})`,line:G(e.source,[`globals`,`preset`])}),fH(e,t.presets);let a=fw(t);for(let t of a.names)t!==`settings`&&!t.startsWith(bH)||e.issues.push({path:`variables`,message:`variable "${t}" is named under "settings", which a segment's templates read as its placement's own settings (.settings.<name>) — rename it`,line:G(e.source,[`variables`,t])});let o=(t,n,i)=>{EL(t)>1&&e.issues.push({path:n,message:`${n} places the global settings menu anchor "${Dx}" ${EL(t)} times — it may appear at most once per layout (it is one disclosure, and one state key holds one open state). Remove all but the placement you want; removing every placement puts the menu at its default position.`,line:i}),DL(t)&&e.issues.push({path:n,message:`${n} places the global settings menu anchor "${Dx}" under a \`when\` or inside a disclosure body — the menu is visible under every condition, so its placement may not be gated. Move it to an ungated position, or remove it to put the menu at its default position.`,line:i});let a=s(t,`bar`);a!==void 0&&e.issues.push({path:n,message:dH[a](n),line:i});let o=new Map;for(let e of uy(t)){if(e.kind!==`segment`||r(e.name).kind!==`declared`)continue;let t=oy(e);o.set(t,[...o.get(t)??[],e])}for(let[t,r]of o){if(r.length<2)continue;let a=r[1].name,s=cy(a,new Set(o.keys()));e.issues.push({path:n,message:`${n} has ${r.length} placements with the id "${t}" — an id names one placement (its settings, its menus' open state, and edit mode all address it), so give each its own: { seg: "${a}", id: "${s}" }. A placement without an "id" takes its segment's name.`,line:i})}};function s(e,t){if(e.kind===`segment`||e.distribution===void 0)return;if(t===`nested`)return`nested`;let n=t===`bar`&&e.children.some(e=>e.kind===`segment`||ay[e.direction]===`cell`);return ay[e.direction]===`row`&&!n?t:void 0}let c=(e,t)=>e.kind===`segment`?`band`:ay[e.direction]===`cell`?`nested`:t,l=(e,t)=>e.kind===`container`?e.children.map((e,n)=>[e,dy(t,n)]):e.opens===void 0?[]:[[e.opens.body,fy(t)]];function*u(e,t){for(let[n,r]of e){let e=s(n,t);e!==void 0&&(yield[e,r]),yield*u(l(n,r),c(n,t))}}let d=new Set,f=(n,i)=>{let o=rC(n),s=$S(n)?Object.entries(n.rows).map(([e,t])=>[t,`${i}.rows.${e}`]):l(o,i);for(let[t,n]of u(s,c(o,`bar`)))e.issues.push({path:n,message:dH[t](n),line:G(e.source,n.split(`.`))});for(let[o,s]of iC(n,i)){let n=G(e.source,s.split(`.`));if(o.when!==void 0&&(IH(e,`${s}.when`,o.when,a,{line:n}),PH(e,`${s}.when`,o.when,n),FH(e,t,`${s}.when`,o.when,n)),o.kind!==`segment`)continue;if(CL(o.name)){(o.id!==void 0||o.settings!==void 0)&&e.issues.push({path:s,message:`${i} gives the global settings menu anchor "${Dx}" an id or settings — the anchor only marks where the menu goes, so place it as the bare name "${Dx}"`,line:n});continue}let c=r(o.name);JV(c)&&(d.add(o.name),e.unplaced.push({path:s,message:mH(i,o.name,t.segments,c),line:n})),OH(e,t,o,s,n)}};n.root!==void 0&&f(n.root,`root`);for(let[e,t]of Object.entries(n.presets??{}))t.root!==void 0&&f(t.root,`presets.${e}.root`);let p=new Map([[`root`,nC(t.root)]]);for(let e of mC(t.presets)){let{node:n,path:r}=_C(t,e);p.set(r,n)}for(let[t,n]of p)o(n,t,G(e.source,t.split(`.`)));for(let[n,i]of p)for(let[a]of py(i,n)){if(a.kind!==`segment`||d.has(a.name))continue;let i=r(a.name);JV(i)&&(d.add(a.name),e.inherited.push({name:a.name,path:n,message:mH(`${n} inherits from a config layer below whose`,a.name,t.segments,i),line:G(e.source,n.split(`.`))}))}UH(e,t,a,()=>!0)}const vH=[`removeSegment`,`insertSegment`,`insertSegmentFrom`];function yH(e,t,n,r,i,a,o){let s=`actions.${n}.${r}`,c=G(e.source,[`actions`,n,r]);if(!mC(t.presets).includes(a)){e.issues.push({path:s,message:`actions.${n}: "${i}" names preset "${a}" which is not declared (have: ${mC(t.presets).join(`, `)})`,line:c});return}if(r===`reset`)return;let l=`removeSegment`in o,u=`insertSegment`in o,d=`insertSegmentFrom`in o;if(!l&&!u&&!d){e.issues.push({path:s,message:`actions.${n}: "${i}" is a "presets.<name>.root" target and can only be paired with "removeSegment", "insertSegment", or "insertSegmentFrom" (not "to"/"from"/"cycle"/bounded — those have no meaning as a tree op)`,line:c});return}let f=(r,i)=>{Object.prototype.hasOwnProperty.call(t.segments,i)||e.issues.push({path:s,message:`actions.${n}: ${r} "${i}" is not a declared segment (have: ${Object.keys(t.segments).join(`, `)})${Lz(i)}`,line:c})},p=new Set(sy(_C(t,a).node)),m=(r,i)=>{!Iz.has(i)||p.has(i)||Object.prototype.hasOwnProperty.call(t.segments,i)||e.issues.push({path:s,message:`actions.${n}: ${r} "${i}" names no placement${Lz(i)}`,line:c})};`removeSegment`in o&&m(`removeSegment`,o.removeSegment),`insertSegment`in o&&f(`insertSegment`,o.insertSegment),(`insertSegment`in o||`insertSegmentFrom`in o)&&m(`anchor`,o.anchor)}const bH=`settings.`;function xH(e,t){return{...e,names:new Set([...e.names,...Object.keys(t).map(e=>bH+e)])}}function SH(e,t,n){let r=e=>`segments.${t}.settings.${e}`,i=(n,i)=>{e.issues.push({path:r(n),message:`${r(n)}: ${i}`,line:G(e.source,[`segments`,t,`settings`,n])})},a=TH(n);for(let{setting:e,message:t}of a)i(e,t);if(!(a.length>0))for(let{setting:e,message:t}of Oy(n,wH(n)))i(e,`the defaults do not stand together: ${t}`)}function CH(e){return TH(e).length>0||Oy(e,wH(e)).length>0}function wH(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.default]))}function TH(e){let t=t=>Dy(EH(e,t))?.atLeast;return Object.keys(e).flatMap(n=>{let r=t(n);if(r===void 0)return[];if(r===n||Dy(EH(e,r))===void 0)return[{setting:n,message:`atLeast "${r}" must name another range setting of this segment (its range settings: ${DH(e,n).join(`, `)||`none`})`}];let i=[n];for(let e=r;e!==void 0;e=t(e)){if(e===n)return i.every(e=>n<=e)?[{setting:n,message:`atLeast closes a cycle (${[...i,n].join(` ≥ `)}) — every setting on it could only ever equal the rest`}]:[];if(i.includes(e))return[];i.push(e)}return[]})}function EH(e,t){return Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}function DH(e,t){return Object.entries(e).filter(([e,n])=>e!==t&&Dy(n)!==void 0).map(([e])=>e)}function OH(e,t,n,r,i){let a=Object.prototype.hasOwnProperty.call(t.segments,n.name)?t.segments[n.name]:void 0;if(a===void 0)return;let o=Ey(a),s=`${r}: placement "${oy(n)}" of segment "${n.name}"`;for(let[t,a]of Object.entries(n.settings??{})){let c=Object.prototype.hasOwnProperty.call(o,t)?o[t]:void 0,l=c===void 0?`sets "${t}", which segment "${n.name}" does not declare (it has: ${Object.keys(o).join(`, `)})`:ky(c,a)?void 0:`sets "${t}" to ${JSON.stringify(a)}${c.domain===`theme`?yv(a):``}, but it must be ${Ny(c)}`;l!==void 0&&e.issues.push({path:r,message:`${s} ${l}`,line:i})}let c=Object.fromEntries(Object.entries(o).map(([e,t])=>[e,n.settings?.[e]??t.default]));if(!(!Object.entries(c).every(([e,t])=>ky(o[e],t))||CH(o)))for(let{message:t}of Oy(o,c))e.issues.push({path:r,message:`${s}: ${t}`,line:i})}function kH(e,t,n,r,i){for(let[a,o]of yy(n))IH(e,`${t}.${a}`,o,r,{segCtx:i})}function AH(e,t,n,r,i){if(!(!_y(n)||!(`depends_on`in n.cache)))for(let a=0;a<n.cache.depends_on.length;a++){let o=n.cache.depends_on[a];if(r.names.has(o))continue;let s=i===void 0?void 0:`${i}.${o}`,c=s!==void 0&&r.names.has(s)?` (segment-local vars are namespaced — write "${s}")`:``;e.issues.push({path:`${t}.cache.depends_on[${a}]`,message:`cache.depends_on references unknown variable "${o}"${c}`,line:G(e.source,[...t.split(`.`),`cache`,`depends_on`])})}}const jH=`it reads the instant a frame is drawn at, which changes every frame, and a cache policy re-runs its source when a stored value changes — re-run it on a period instead: cache: { ttl: "<duration>" }`;function MH(e,t,n,r){if(!_y(n))return;let i=n=>G(e.source,[...t.split(`.`),`cache`,n]);if(`key`in n.cache){let a=lH(n.cache.key,r);a!==null&&e.issues.push({path:`${t}.cache.key`,message:`cache.key ${a}: ${jH}`,line:i(`key`)})}if(`depends_on`in n.cache){let a=aH(r);n.cache.depends_on.forEach((n,r)=>{let o=a.get(n);o!==void 0&&e.issues.push({path:`${t}.cache.depends_on[${r}]`,message:`cache.depends_on names "${n}", which ${o}: ${jH}`,line:i(`depends_on`)})})}}function NH(e,t){let n=new Map(lw(t)),r=tH(t),i=(e,t)=>{for(let{path:n,reaches:r}of e){let e=Dv.find(e=>VM[e]===n||VM[e].startsWith(`${n}.`));if(e!==void 0)return`reads "${VM[e]}", the ${e}'s own name`;for(let e of r){let n=a(e,t);if(n!==null)return n}}return null},a=(e,t)=>{if(t.has(e))return null;t.add(e);let a=n.get(e),o=$V(e,a),s=o===void 0?void 0:HM(o);if(s!==void 0)return`reads "${e}", the ${s}'s own name`;for(let n of r.ofVariable(a)){let r=i([n],t);if(r!==null)return n.field===`template`?`reads "${e}", which ${r}`:`reads "${e}", whose ${n.field} ${r}`}return null};for(let{at:n,rule:a}of sH(t)){let t=i(r.ofTemplate(a),new Set);if(t===null)continue;let o=n.join(`.`);e.issues.push({path:o,message:`${o} ${t}: a rule decides that name, so it cannot read it — read the data the rule is about instead`,line:G(e.source,[...n])})}}function PH(e,t,n,r){try{rP.parse(n)}catch(n){e.issues.push({path:t,message:`Template parse error in ${t}: ${n.message}`,line:r})}}function FH(e,t,n,r,i){let a=n.slice(n.lastIndexOf(`.`)+1);for(let{name:o,site:s,via:c}of $C(r,t.helpers)){if(Object.prototype.hasOwnProperty.call(t.actions,o))continue;let r=s===`options`?` (in a picker, menu, carousel, swatch, swatches or themePreview)`:``;if(c!==null){LH(e,c,`Template references unknown action "${o}"${r}`);continue}e.issues.push({path:n,message:`${a} references unknown action "${o}"${r}`,line:i})}}function IH(e,t,n,r,i){for(let[a,o]of YC(n,r.helpers)){if(dw(a,r))continue;if(a.startsWith(bH)){let n=o===null?``:` through helper "${o}"`,r=a.slice(9),s=i?.segCtx===void 0||i.settings===void 0?`Template reads ".${a}"${n}, but only a segment's own templates have settings — call it from a segment that declares "${r}"`:`Template reads ".${a}"${n}, but segment "${i.segCtx}" has no setting "${r}" (it has: ${Object.keys(i.settings).join(`, `)}) — declare it under segments.${i.segCtx}.settings`;e.issues.push({path:t,message:s,line:i?.line??G(e.source,t.split(`.`))});continue}if(o!==null){LH(e,o,`Template references unknown variable ".${a}"${iz(a)}`);continue}let n=i?.segCtx===void 0?void 0:`${i.segCtx}.${a}`,s=n!==void 0&&dw(n,r)?` (segment-local vars are namespaced — write ".${n}")`:iz(a);e.issues.push({path:t,message:`Template references unknown variable ".${a}"${s}`,line:i?.line??G(e.source,t.split(`.`))})}}function LH(e,t,n){let r=`helpers.${t}`;e.issues.some(e=>e.path===r&&e.message===n)||e.issues.push({path:r,message:n,line:G(e.source,[`helpers`,t])})}function RH(e,t,n,r,i){let a=n.set,o=yN(nx[r].configKey),s=`${a} takes ${nN(o,i)}`;if(`min`in n&&(o===`bool`||!(`min`in o))){e.issues.push({path:`actions.${t}.min`,message:`actions.${t}: a stepper writes the integers from ${n.min} to ${n.max}, and ${a} is not an integer range; ${s}`,line:G(e.source,[`actions`,t,`min`])});return}let c=VH(n,i);if(c===BH){e.issues.push({path:`actions.${t}.int`,message:`actions.${t}.int: an int cursor writes whatever integer the template binds, and a click outside the ${a} domain would change nothing; ${s}`,line:G(e.source,[`actions`,t,`int`])});return}let l=c.filter(e=>!tN(o,e.value,i));if(l.length!==0){if(a===nx.style.sessionKey&&(`from`in n&&n.from===`endcaps`||c.every(e=>Kv(e.value)))){let r=nx.endcaps.sessionKey;e.issues.push(`to`in n?{path:`actions.${t}.to`,message:VV(`actions.${t}.to`,n.to,`set: "${r}", to`),line:G(e.source,[`actions`,t,`to`])}:{path:`actions.${t}.set`,message:`actions.${t}.set: "${a}" here writes only endcaps shapes, not styles — endcaps were renamed from "style" to "endcaps"; write set: "${r}"`,line:G(e.source,[`actions`,t,`set`])});return}for(let n of new Set(l.map(e=>e.field))){let r=l.filter(e=>e.field===n).map(e=>JSON.stringify(e.value)),i=r.length<=zH?r.join(`, `):`${r.slice(0,zH).join(`, `)} and ${r.length-zH} more`,o=`actions.${t}.${n}`;e.issues.push({path:o,message:`${o}: ${i} ${r.length===1?`is`:`are`} outside the ${a} domain — a click would write it and nothing would change; ${s}`,line:G(e.source,[`actions`,t,n])})}}}const zH=3,BH=Symbol(`any integer`);function VH(e,t){return`to`in e?[{field:`to`,value:e.to}]:`cycle`in e?e.cycle.map(e=>({field:`cycle`,value:e})):`from`in e?EC(e.from,t).members.map(e=>({field:`from`,value:e})):`min`in e?[{field:`min`,value:String(e.min)},{field:`max`,value:String(e.max)}]:BH}function HH(e,t){return Object.entries(e).filter(([e])=>t(e))}function UH(e,t,n,r){let i=eR(t),a=TC(i);for(let[n,o]of HH(t.actions,r)){let[t,r]=`from`in o?[`from`,o.from]:`insertSegmentFrom`in o?[`insertSegmentFrom`,o.insertSegmentFrom]:[null,null];if(t!==null&&typeof r==`string`&&!a.includes(r)){e.issues.push({path:`actions.${n}.${t}`,message:`actions.${n} ${t}: references ${OC(r,i)}`,line:G(e.source,[`actions`,n,t])});continue}if(!(`set`in o))continue;ox.has(o.set)&&e.issues.push({path:`actions.${n}.set`,message:`actions.${n} sets "${o.set}", which has no session pick — globals.${o.set} is set in the config file only, so a click would change nothing; write it with { persist: "${o.set}", … } instead`,line:G(e.source,[`actions`,n,`set`])});let s=ux.get(o.set);s!==void 0&&RH(e,n,o,s,i)}for(let[n,i]of HH(t.actions,r))`do`in i&&i.do.forEach((r,a)=>{let o=Object.prototype.hasOwnProperty.call(t.actions,r)?t.actions[r]:void 0,s=o===void 0?`references unknown action "${r}"`:`do`in o?`"${r}" is itself a do action — list its members here instead`:i.do.indexOf(r)===a?a>0&&NC(o)?`"${r}" takes its value from the template (from/int/insertSegmentFrom), so it can only be the first member — only the first is bound the region's display`:void 0:`"${r}" is listed twice — each member fires once per click`;s!==void 0&&e.issues.push({path:`actions.${n}.do`,message:`actions.${n} do: ${s}`,line:G(e.source,[`actions`,n,`do`])})});for(let[n,i]of HH(t.actions,r))if(`run`in i)for(let r of i.refreshes){let i=Object.hasOwn(t.variables,r)?t.variables[r]:void 0;i?.kind!==`source`&&e.issues.push({path:`actions.${n}.refreshes`,message:`actions.${n} refreshes "${r}", which ${i===void 0?`is not declared`:`is a ${i.kind} variable`}: a run refreshes only a declared source (by its full name, <scope>.<plugin>.<source> where the scope is plugins or repo; a plugin names its own sources bare)`,line:G(e.source,[`actions`,n,`refreshes`])})}for(let[n,i]of HH(t.actions,r)){let r=`persist`in i?i.persist:`reset`in i?i.reset:null;if(r===null)continue;let a=`persist`in i?`persist`:`reset`,o=QN(r);if(o===null){let t=BN(r);e.issues.push({path:`actions.${n}.${a}`,message:t===void 0?`actions.${n}: "${r}" is not a config globals field (have: ${VN().join(`, `)}), a "segments.<name>.palette" target, a "presets.<name>.globals.<field>" target, a "themeDefaults.<theme>.<shade|variation|style>" target, or a "presets.<name>.root" target`:`actions.${n}: the globals field "${r}" was removed: ${t}`,line:G(e.source,[`actions`,n,a])});continue}let s=vH.filter(e=>e in i);if(o.scope!==`preset-root`&&s.length>0){e.issues.push({path:`actions.${n}.${a}`,message:`actions.${n}: "${r}" is not a "presets.<name>.root" target — ${s.map(e=>`"${e}"`).join(`/`)} is a tree op and applies only to one`,line:G(e.source,[`actions`,n,a])});continue}if(o.scope===`preset-root`){yH(e,t,n,a,r,o.preset,i);continue}if(o.scope===`preset-globals`&&!mC(t.presets).includes(o.preset)){e.issues.push({path:`actions.${n}.${a}`,message:`actions.${n}: "${r}" names preset "${o.preset}" which is not declared (have: ${mC(t.presets).join(`, `)})`,line:G(e.source,[`actions`,n,a])});continue}if(o.scope===`theme-default`&&!e.allowedPalettes.has(o.theme)){e.issues.push({path:`actions.${n}.${a}`,message:`actions.${n}: "${r}" names theme "${o.theme}" which is not installed${yv(o.theme)} (have: ${[...e.allowedPalettes].sort().join(`, `)})`,line:G(e.source,[`actions`,n,a])});continue}if(o.scope===`segment-palette`){if(!Object.prototype.hasOwnProperty.call(t.segments,o.segment)){e.issues.push({path:`actions.${n}.${a}`,message:`actions.${n}: "${r}" names segment "${o.segment}" which is not declared (have segments: ${Object.keys(t.segments).join(`, `)})${Lz(o.segment)}`,line:G(e.source,[`actions`,n,a])});continue}`min`in i&&e.issues.push({path:`actions.${n}.${a}`,message:`actions.${n}: "${r}" is a segment palette target and cannot use a bounded stepper (min/max/by) — use "to", "from", or "cycle" instead`,line:G(e.source,[`actions`,n,a])})}}for(let[i,a]of HH(t.variables,r)){kH(e,`variables.${i}`,a,n);let t=rz(i);t!==void 0&&e.issues.push({path:`variables.${i}`,message:t,line:G(e.source,[`variables`,i])})}for(let[i,a]of HH(t.segments,r)){if(a.vars)for(let[t,r]of Object.entries(a.vars))kH(e,`segments.${i}.vars.${t}`,r,n,i);let r=Ey(a);SH(e,i,r);let o=xH(n,r);for(let n of[`template`,`bg`,`fg`,`when`]){let s=a[n];typeof s==`string`&&(IH(e,`segments.${i}.${n}`,s,o,{segCtx:i,settings:r}),FH(e,t,`segments.${i}.${n}`,s,G(e.source,[`segments`,i,n])))}}for(let[i,a]of HH(t.variables,r))AH(e,`variables.${i}`,a,n),MH(e,`variables.${i}`,a,t);NH(e,t);for(let[i,a]of HH(t.segments,r))if(a.vars)for(let[r,o]of Object.entries(a.vars))AH(e,`segments.${i}.vars.${r}`,o,n,i),MH(e,`segments.${i}.vars.${r}`,o,t)}function WH(e,t,n=()=>!0){let{graph:r,nodeInfo:i}=GH(t),a=new Map,o=[];for(let e of r.keys())a.set(e,0);for(let e of r.keys())if(!(!n(e)||a.get(e)!==0)&&s(e))return;function s(t){a.set(t,1),o.push(t);for(let c of r.get(t)??[]){if(!n(c))continue;let t=a.get(c);if(t===1){let t=o.indexOf(c),n=[...o.slice(t),c],r=n[0],a=i.get(r);return e.issues.push({path:a?.declarationPath??`variables.${r}`,message:`Dependency cycle: ${n.join(` → `)}`,line:G(e.source,a?.linePathParts??[`variables`,r])}),!0}if(t===0&&s(c))return!0}return a.set(t,2),o.pop(),!1}}function GH(e){let t=new Map,n=new Map,r=tH(e),i=(e,i,a)=>{t.set(e,{declarationPath:a.join(`.`),linePathParts:a}),n.set(e,new Set(r.ofVariable(i).flatMap(({reaches:e})=>e)))};for(let[t,n]of Object.entries(e.variables))i(t,n,[`variables`,t]);for(let[t,n]of Object.entries(e.segments))for(let[e,r]of Object.entries(n.vars??{}))i(`${t}.${e}`,r,[`segments`,t,`vars`,e]);return{graph:n,nodeInfo:t}}function KH(e,t,n){let r=new Map([...cw(t)].map(([e,,t])=>[e,t]));for(let[t,i]of r){let a=t.split(`.`);for(let o=1;o<a.length;o++){let s=a.slice(0,o).join(`.`),c=r.get(s);if(c===void 0||!(n.checked(t)||n.checked(s)))continue;let[l,u,d]=n.authored(t)?[t,s,i]:[s,t,c],f=n.authored(t)===n.authored(s)?`Rename one so neither name starts with the other.`:`"${u}" is declared outside this file (the bundled default, a plugin, or a control the bar builds), so rename "${l}".`;e.issues.push({path:d.join(`.`),message:`variable "${t}" is declared under the variable "${s}" — a read of ".${t}" would name both, "${t}" and a field of "${s}". ${f}`,line:G(e.source,[...d])})}}}function qH(e){return e===`~`||e.startsWith(`~/`)||e.startsWith(`~\\`)?w.homedir()+e.slice(1):e}function JH(e,t){return o.resolve(e,qH(t))}function YH(e,t){return typeof t==`string`&&t!==``?JH(e,t):void 0}function XH(e){return`plugin ${e.path} was not loaded: ${e.reason}`}const ZH=new Set([`data`,`sources`,`variables`,`segments`,`helpers`,`actions`]),QH=`plugin.json5`,$H=/^[a-z][a-z0-9_]*$/;function eU(e,t){let n=o.basename(o.dirname(e));return $H.test(n)?{path:e,scope:t,name:n}:{path:e,scope:t,name:void 0}}function tU(e){return`${e}.data`}function nU(e){return`${e}.json`}function rU(e){try{return{ok:!0,value:e()}}catch(e){return{ok:!1,reason:iU(e)}}}function iU(e){return e instanceof Iy?e.issues.map(e=>e.path===``||e.message.includes(e.path)?e.message:`${e.path}: ${e.message}`).join(`; `):e instanceof Error?e.message:String(e)}function aU(e,t,n){return e.map(e=>eU(JH(o.dirname(t),e),n))}function oU(e,t,n,r){let i=new Map;return e.reduce((e,n)=>{let a=n.path,s=n.name===void 0?void 0:px(n),c=(t,r)=>{let i=new Map(e.rendering);return s!==void 0&&r!==e.config&&i.delete(s),{...e,config:r,rendering:i,dropped:[...e.dropped,{...n,reason:t}]}};if(o.basename(a)!==`plugin.json5`){let t=`a plugin is a folder holding its ${QH}, and the folder's name is the plugin's: move this file to <dir>/<name>/${QH} and list that`;return c(t,s===void 0?e.config:cU(sU(e.config,s),s,{...n,reason:t}))}if(n.name===void 0||s===void 0)return c(`its folder "${o.basename(o.dirname(a))}" is not a plugin name (one matching ${$H}: it prefixes every name the plugin declares)`,e.config);let l=i.get(s);if(l!==void 0)return c(`plugin "${n.name}" is already listed, from ${l}`,e.config);i.set(s,a);let u=sU(e.config,s),d=rU(()=>{let i=f.readFileSync(a,`utf-8`),o=WR(mU(a,n,{source:i,json:ca.default.parse(i)},t),u);return kU(a,s,o),r(o,s,u!==e.config),o});if(d.ok)return{...e,config:d.value,loaded:[...e.loaded,n],rendering:new Map([...e.rendering,[s,n]])};let p={...n,reason:d.reason};return c(d.reason,cU(u,s,p))},{config:n.config,rendering:n.rendering,loaded:[],dropped:[]})}function sU(e,t){let n=mx(t),r=e=>Object.fromEntries(Object.entries(e).filter(([e])=>!n(e)));return[e.variables,e.segments,e.helpers,e.actions].some(e=>Object.keys(e).some(n))?{...e,variables:r(e.variables),segments:r(e.segments),helpers:r(e.helpers),actions:r(e.actions)}:e}function cU(e,t,n){return{...e,variables:{...e.variables,[t]:{kind:`dropped`,reason:XH(n),definition:n.path}}}}function lU(e){let t=Object.entries(e.variables).flatMap(([e,t])=>t.kind===`dropped`?[{ns:e,definition:t.definition,notice:t.reason}]:[]);return e=>t.find(({ns:t})=>mx(t)(e))}function uU(e,t){let n=lU(e.config),r=[...e.rendering.keys()].map(mx),i=[...t,...e.dropped].filter(e=>e.name===void 0);return e=>{let t=gx(e);if(t===void 0)return[];let a=n(e);return a===void 0?r.some(t=>t(e))?[]:i.filter(e=>e.scope===t).map(e=>({definition:e.path,notice:XH(e)})):[{definition:a.definition,notice:a.notice}]}}function dU(e,t,n){let r=mC(e.presets).flatMap(t=>[...uy(_C(e,t).node)]).flatMap(e=>e.kind===`segment`?[e]:[]),i=[...new Set([...r.map(e=>e.name),...n,...Object.keys(e.segments)])].map(e=>({name:e,cause:t(e)})).filter(({cause:e})=>e.length>0),a=Object.fromEntries(i.map(({name:e,cause:t})=>[e,fU(e,t.map(e=>e.notice),r.filter(t=>t.name===e))])),o=lU(e),s=Object.values(e.variables).some(e=>e.kind===`dropped`),c=s?Object.values(e.segments).flatMap(e=>vU.flatMap(t=>e[t]===void 0?[]:[e[t]])):[],l=s?Object.values(e.actions).flatMap(e=>`do`in e?[...e.do]:[]):[],u=(e,t)=>[...new Set(e)].flatMap(e=>{let n=e in t?void 0:o(e);return n===void 0?[]:[[e,n]]}),d=u([...c.flatMap(t=>$C(t,e.helpers).map(e=>e.name)),...l],e.actions),f=u(c.flatMap(t=>[...aw(t,e.helpers)]),e.helpers),p=Object.entries(e.actions).flatMap(([t,n])=>{if(!(`run`in n))return[];let r=new Map(u(n.refreshes,e.variables));return r.size===0?[]:[{name:t,action:{...n,refreshes:n.refreshes.filter(e=>!r.has(e))},causes:[...r.values()]}]}),m=new Set([...i.flatMap(({cause:e})=>e.map(e=>e.definition)),...[...d,...f].map(([,e])=>e.definition),...p.flatMap(({causes:e})=>e.map(e=>e.definition))]);return{config:{...e,segments:{...e.segments,...a},actions:{...e.actions,...Object.fromEntries(p.map(({name:e,action:t})=>[e,t])),...Object.fromEntries(d.map(([e,{ns:t}])=>[e,{copy:`{{ .${t} }}`}]))},helpers:{...e.helpers,...Object.fromEntries(f.map(([e,t])=>[e,`{{ fail ${JSON.stringify(t.notice)} }}`]))}},reached:m}}function fU(e,t,n){let r=`⚠ ${e}: ${t.join(`; `)}`,i=new Map;for(let e of n)for(let[t,n]of Object.entries(e.settings??{})){let e=i.get(t);i.set(t,e===void 0?[n]:[...e,n])}let a=Object.fromEntries([...i].map(([e,t])=>[e,pU(e,t)]));return{template:`{{ ${JSON.stringify(r)} }}`,bg:`error`,description:`stands in for a segment whose plugin did not load`,settings:a}}function pU(e,t){let[n]=t,r=t.filter(e=>typeof e==`number`);return typeof n==`boolean`?{label:e,domain:`bool`,default:n}:typeof n==`number`?{label:e,domain:{min:Math.min(...r),max:Math.max(...r),step:1},default:n}:{label:e,domain:[...new Set(t.map(String))],default:n}}function mU(e,t,{source:n,json:r},{checkout:i}){let a=px(t),s=[],c=()=>{throw new Iy(e,s)};if(!Qy(r))return s.push({path:``,message:`a plugin definition must be an object, got ${$y(r)}`}),c();for(let t of Object.keys(r))ZH.has(t)||s.push({path:t,message:t===`plugin`?`a plugin definition does not name itself: its name is its folder's ("${o.basename(o.dirname(e))}") — remove "plugin"`:`a plugin definition may not declare "${t}". Expected only: ${[...ZH].join(`, `)}`});let l=r.data===void 0?void 0:MU(r.data,e,i,s),u=r.sources===void 0?{}:OU(r.sources,e,s);if(s.length>0)return c();let d={source:n,issues:s,allowedPalettes:new Set(Sv()),groups:[],unplaced:[],inherited:[]},p=l===void 0?{}:lz(d,`data`,{[tU(a)]:{kind:`file`,path:l,parse:{json:!0},cache:{watch_file:l},default:{}}}),m=lz(d,`variables`,r.variables);for(let[e,t]of[[`variables`,Object.keys(m)],[`sources`,Object.keys(u)]])t.includes(`data`)&&s.push({path:`${e}.data`,message:`"data" names the plugin's data file (.${tU(a)}), declared by the definition's own "data" key: give this ${e===`sources`?`source`:`variable`} another name`});for(let e of Object.keys(u))Object.hasOwn(m,e)&&s.push({path:`sources.${e}`,message:`source "${e}" and variable "${e}" are one name (.${a}.${e}): give one of them another name`});let h={variables:{...p,...xU(a,u),...xU(a,Object.fromEntries(Object.entries(m).map(([e,t])=>[e,CU(a,t)])))},segments:xU(a,wU(a,tB(d,r.segments,new Set))),helpers:xU(a,KV(d,r.helpers)),actions:xU(a,TU(a,JB(d,r.actions,{dir:f.realpathSync(o.dirname(e))})))};s.push(...yU(h,t));let g=hU(a,h);for(let[e,t]of bU(g))try{rP.parse(t)}catch(t){s.push({path:e,message:`Template parse error in ${e}: ${t.message}`})}return s.length>0&&c(),g}function hU(e,t){let n=t=>sw(t,hx,e),r=t=>mx(`self`)(t)?`${e}${t.slice(4)}`:t,i=(e,t)=>Object.fromEntries(Object.entries(e??{}).map(([e,n])=>[e,t(n)]));return{...t,variables:i(t.variables,e=>gU(vy(e,n),r)),segments:i(t.segments,e=>({...e,...Object.fromEntries(vU.flatMap(t=>e[t]===void 0?[]:[[t,n(e[t])]])),...e.vars!==void 0&&{vars:i(e.vars,e=>gU(vy(e,n),r))}})),helpers:i(t.helpers,n),actions:i(t.actions,e=>_U(MC(e,n),r))}}function gU(e,t){return _y(e)&&`depends_on`in e.cache?{...e,cache:{depends_on:e.cache.depends_on.map(t)}}:e}function _U(e,t){let n=`segments.`,r={...e};`do`in e&&(r.do=e.do.map(e=>t(e,`do`)));for(let n of[`removeSegment`,`insertSegment`,`anchor`])n in e&&(r[n]=t(e[n],n));return`persist`in e&&e.persist.startsWith(n)&&(r.persist=n+t(e.persist.slice(9),`persist`)),r}const vU=[`template`,`bg`,`fg`,`when`];function yU(e,t){let n=e.helpers??{},r=fx.filter(e=>e!==t.scope).map(e=>({scope:e,ns:px({scope:e,name:t.name})})),i=new Map,a=(e,n,a)=>{let o=r.find(({ns:e})=>mx(e)(n));if(o===void 0)return;let s=a?`.`:``;i.set(`${e}\0${n}`,{path:e,message:`${e} names ${s}${n}, this plugin under "${o.scope}", but it loads as ${px(t)}: a plugin names itself without its scope — write ${s}${hx}${n.slice(o.ns.length)}`})},o=[...[...bU(e)].filter(([e])=>!e.startsWith(`helpers.`)),...Object.entries(n).map(([e,t])=>[`helpers.${e}`,t])];for(let[e,t]of o){for(let[r,i]of YC(t,n))i===null&&a(e,r,!0);for(let{name:r,via:i}of $C(t,n))i===null&&a(e,r,!1);for(let n of aw(t,{}))a(e,n,!1)}for(let[t,n]of Object.entries(e.actions??{}))_U(n,(e,n)=>(a(`actions.${t}.${n}`,e,!1),e));let s=[...Object.entries(e.variables??{}).map(([e,t])=>[`variables.${e}`,t]),...Object.entries(e.segments??{}).flatMap(([e,t])=>Object.entries(t.vars??{}).map(([t,n])=>[`segments.${e}.vars.${t}`,n]))];for(let[e,t]of s)if(_y(t)&&`depends_on`in t.cache)for(let n of t.cache.depends_on)a(`${e}.cache.depends_on`,n,!1);return[...i.values()]}function*bU(e){for(let[t,n]of Object.entries(e.variables??{}))for(let[e,r]of yy(n))yield[`variables.${t}.${e}`,r];for(let[t,n]of Object.entries(e.segments??{})){for(let e of vU){let r=n[e];r!==void 0&&(yield[`segments.${t}.${e}`,r])}for(let[e,r]of Object.entries(n.vars??{}))for(let[n,i]of yy(r))yield[`segments.${t}.vars.${e}.${n}`,i]}for(let[t,n]of Object.entries(e.helpers??{}))yield[`helpers.${t}`,`{{ define "${t}" }}${n}{{ end }}`];for(let[t,n]of Object.entries(e.actions??{}))for(let[e,r]of jC(n))yield[`actions.${t}.${e}`,r]}function xU(e,t){return Object.fromEntries(Object.entries(t).map(([t,n])=>[`${e}.${t}`,n]))}function SU(e,t){return`${e}.${t}`}function CU(e,t){return t.kind===`state`?{...t,key:SU(e,t.key)}:t}function wU(e,t){return Object.fromEntries(Object.entries(t).map(([t,n])=>[t,n.vars===void 0?n:{...n,vars:Object.fromEntries(Object.entries(n.vars).map(([t,n])=>[t,CU(e,n)]))}]))}function TU(e,t){return Object.fromEntries(Object.entries(t).map(([t,n])=>[t,`set`in n?{...n,set:SU(e,n.set)}:`run`in n?{...n,refreshes:n.refreshes.map(t=>SU(e,t))}:n]))}const EU=$H,DU={scope:`session`,refresh:{watch:!0},read:{file:{json:!0}}};function OU(e,t,n){if(!Qy(e))return n.push({path:`sources`,message:`"sources" must be an object of named sources, got ${$y(e)}`}),{};let r=o.join(f.realpathSync(o.dirname(t)),`session`),i=JSON.stringify(DU),a={};for(let[t,o]of Object.entries(e)){let e=`sources.${t}`;if(!EU.test(t)){n.push({path:e,message:`source name "${t}" is not one identifier (one matching ${EU}: it is the last segment of .<scope>.<plugin>.${t})`});continue}let s=jU(o,DU,e);for(let{field:e,is:t}of s)n.push({path:e,message:`${e} ${t}: what is built is a source ${i} — a session's JSON file in the plugin's managed storage, re-read when it changes`});s.length===0&&(a[t]={kind:`source`,storage:r})}return a}function kU(e,t,n){let r=Object.entries(n.variables).reduce((e,[t,n])=>{if(n.kind!==`source`)return e;let r=AU(n);return e.set(r,[...e.get(r)??[],t])},new Map),i=mx(t),a=[...r].filter(([,e])=>e.length>1&&e.some(i)).map(([e,n])=>({path:`sources.${n.find(i).slice(`${t}.`.length)}`,message:`sources ${n.map(e=>`.${e}`).join(` and `)} read the same file, ${e}: a session's file is one document, read by one source`}));if(a.length>0)throw new Iy(e,a)}function AU(e){return o.join(e.storage,nU(`<session id>`))}function jU(e,t,n){return!Qy(t)||!Qy(e)?JSON.stringify(e)===JSON.stringify(t)?[]:[{field:n,is:`is ${JSON.stringify(e)}`}]:[...new Set([...Object.keys(t),...Object.keys(e)])].flatMap(r=>{let i=`${n}.${r}`;return Object.hasOwn(t,r)?Object.hasOwn(e,r)?jU(e[r],t[r],i):[{field:i,is:`is missing`}]:[{field:i,is:`is not built`}]})}function MU(e,t,n,r){if(typeof e==`string`&&e!==``)return JH(o.dirname(t),e);if(Qy(e)&&Object.keys(e).length===1&&typeof e.checkout==`string`&&e.checkout!==``){let t=e.checkout;if(o.isAbsolute(t)||t.startsWith(`~`)||o.normalize(t).split(o.sep)[0]===`..`){r.push({path:`data.checkout`,message:`data.checkout "${t}" must be a path inside the checkout, relative to its root (like ".lit/statusline.json"): no absolute path, "~" or ".."`});return}if(n===null){r.push({path:`data.checkout`,message:`data is read from the session's checkout, and this load has no session`});return}return o.resolve(n.root,t)}if(Qy(e)&&`project`in e){r.push({path:`data.project`,message:`data: { project } is now data: { checkout }: the same path, relative to the root of the git checkout the session works in (a linked worktree is its own checkout)`});return}r.push({path:`data`,message:`"data" must be the path of the plugin's JSON data file relative to this definition, or { checkout: "<path>" } relative to the root of the session's checkout`})}function NU(e){let t=[...[...(process.env.XDG_DATA_DIRS||IU()).split(`:`).filter(e=>e!==``)].reverse().map(e=>o.join(e,`cc-candybar`,`plugins`)),PU()];return[...t.filter((e,n)=>t.lastIndexOf(e)===n).map(e=>({dir:e,scope:`plugins`})),...e===null?[]:[{dir:o.join(e,FU),scope:`repo`}]]}function PU(){let e=process.env.XDG_DATA_HOME||o.join(w.homedir(),`.local`,`share`);return o.join(e,`cc-candybar`,`plugins`)}const FU=o.join(`.cc-candybar`,`plugins`);function IU(){let e=`/usr/local/share:/usr/share`;return process.platform===`darwin`?`${o.join(process.env.HOMEBREW_PREFIX||`/opt/homebrew`,`share`)}:${e}`:e}function LU(e){let t=NU(e),n=new Map,r=[],i=[];for(let{dir:e,scope:a}of t){let t=RU(e);if(`error`in t){r.push(t);continue}for(let r of t.folders){let t=eU(o.join(e,r,QH),a),i=`${a}\0${r}`;n.delete(i),n.set(i,t)}for(let n of t.files)i.push({path:o.join(e,n),scope:a,name:void 0,reason:`a plugin is a folder holding its ${QH}: move this file to ${o.join(e,`<name>`,QH)}`})}return{roots:t.map(e=>e.dir),definitions:[...n.values()],unchecked:r,strays:i}}function RU(e){try{let t=f.readdirSync(e,{withFileTypes:!0}).filter(e=>!e.name.startsWith(`.`)).sort((e,t)=>e.name<t.name?-1:+(e.name>t.name)),n=t=>t.isDirectory()||zU(e,t);return{folders:t.filter(n).map(e=>e.name),files:t.filter(e=>!n(e)).map(e=>e.name)}}catch(t){return t.code===`ENOENT`?{folders:[],files:[]}:{path:e,error:t.message}}}function zU(e,t){if(!t.isSymbolicLink())return!1;try{return f.statSync(o.join(e,t.name)).isDirectory()}catch{return!0}}function BU(e){return f.existsSync(o.join(e,`.git`))}function VU(e){let t=o.resolve(e);for(;;){if(BU(t))return t;let e=o.dirname(t);if(e===t)return;t=e}}function HU(e){let t=VU(e);return t===void 0?{root:o.resolve(e),git:!1}:{root:t,git:!0}}function UU(e){try{return N(e())}catch(e){return e.code===`ENOENT`?P:F(e.message)}}const WU=e=>UU(()=>f.realpathSync.native(e)),GU=(e,t)=>t.kind===`absent`?`${e} is not there`:t.reason;function KU(e){let t=UU(()=>f.readFileSync(o.join(e,`.git`),`utf-8`));if(t.kind!==`ok`)return t;let n=t.value.match(/^gitdir:\s*(.+)$/m)?.[1]?.trim();return n===void 0?F(`${o.join(e,`.git`)} names no gitdir`):N(o.resolve(e,n))}function qU(e){let t=UU(()=>f.readFileSync(o.join(e,`commondir`),`utf-8`));if(t.kind!==`ok`)return t;let n=t.value.trim();return n===``?F(`${o.join(e,`commondir`)} is empty`):N(o.resolve(e,n))}const JU={kind:`unlinked`},YU=e=>({kind:`unproven`,reason:e});function XU(e){let t=VU(e);if(t===void 0)return JU;let n=o.join(t,`.git`),r=UU(()=>f.statSync(n));if(r.kind===`ok`&&r.value.isDirectory())return JU;let i=UU(()=>f.lstatSync(n));if(i.kind!==`ok`)return YU(GU(n,i));if(!i.value.isFile())return YU(`${n} is not a file`);let a=KU(t);if(a.kind!==`ok`)return YU(GU(n,a));let s=WU(a.value);if(s.kind!==`ok`)return YU(GU(a.value,s));let c=qU(s.value);if(c.kind===`absent`)return JU;if(c.kind===`failed`)return YU(c.reason);let l=WU(c.value);if(l.kind!==`ok`)return YU(GU(c.value,l));if(o.dirname(s.value)!==o.join(l.value,`worktrees`))return YU(`${s.value} is not a worktree of ${l.value}`);let u=o.join(s.value,`gitdir`),d=UU(()=>f.readFileSync(u,`utf-8`));if(d.kind!==`ok`)return YU(GU(u,d));let p=o.resolve(s.value,d.value.trim()),m=WU(o.dirname(p));if(o.basename(p)!==`.git`||m.kind!==`ok`||m.value!==t)return YU(`${s.value} is the worktree at ${p}, not ${t}`);let h=o.basename(l.value)===`.git`?o.dirname(l.value):l.value;return{kind:`linked`,main:o.join(h,o.relative(t,e))}}function ZU(e){try{return f.statSync(e,{throwIfNoEntry:!1})===void 0?`absent`:`present`}catch(t){return{path:e,error:t.message}}}const QU=[`approved`,`declined`];function $U(e){return e.link.kind===`linked`?e.link.main:e.dir}const eW=(e,t)=>Object.hasOwn(e,t)?e[t]:null;function tW(e,t){let n=$U(t);if(e.kind===`failed`)return{standing:`unread`,under:n};let r=eW(e.value,n),i=eW(e.value,t.dir);return r===null?i===null?{standing:`awaiting`,under:n}:{standing:i,under:t.dir}:{standing:i===null||i===r?r:`awaiting`,under:n}}function nW(e,t,n){let r=[...new Map([...t,...n?.ships?[n]:[]].map(e=>[e.dir,e])).values()],i=r.map(t=>({dir:t.dir,...tW(e,t)})),a=e=>i.filter(t=>t.standing===e),o=e=>[...new Set(a(e).map(e=>e.under))];return{plugins:n!==null&&tW(e,n).standing===`approved`?n.path:null,approved:a(`approved`).map(e=>e.dir),awaiting:o(`awaiting`),declined:o(`declined`),unproven:r.flatMap(e=>e.link.kind===`unproven`?[{dir:e.dir,reason:e.link.reason}]:[]),unread:e.kind===`failed`?e.reason:null}}function rW(e,t,n,r){if(e[t]===n&&r.length===0)return e;let i=Object.entries(e).filter(([e])=>!r.includes(e));return{...Object.fromEntries(i),[t]:n}}function iW(e){if(typeof e!=`object`||!e||Array.isArray(e))return{kind:`failed`,reason:`is not an object`};for(let[t,n]of Object.entries(e))if(!QU.includes(n))return{kind:`failed`,reason:`answers ${JSON.stringify(t)} ${JSON.stringify(n)}, not ${QU.join(` or `)}`};return{kind:`ok`,value:e}}function aW(e){return e.unread===null?null:`Repository config answers could not be read: ${e.unread} — no repository's config runs until they can be`}function oW(e){let t=aW(e);return[...t===null?[]:[t],...e.awaiting.map(e=>`awaiting approval: ${e} — its cc-candybar config runs once it is approved in the bar`),...e.declined.map(e=>`declined: ${e} — its cc-candybar config does not run`),...e.unproven.map(e=>`not proven a worktree: ${e.dir} — it answers for itself, because ${e.reason}`)]}const sW=[`json5`,`json`];function cW(e,t,n){if(n!==void 0)return[n];let r=t??process.cwd();return[...new Set([...e?sW.map(t=>o.join(e,`${lW}.${t}`)):[],...sW.map(e=>o.join(r,`${lW}.${e}`)),...sW.map(e=>`${uW()}.${e}`)])]}const lW=`.cc-candybar`;function uW(){let e=process.env.XDG_CONFIG_HOME??o.join(w.homedir(),`.config`);return o.join(e,`cc-candybar`,`config`)}function dW(e){return{path:e,scope:`plugins`}}function fW(e,t,n,r){let i=[],a=new Map;for(let e of cW(t,n,r)){let t=ZU(e);if(t===`absent`)continue;if(t!==`present`){i.push(t);continue}let n=f.realpathSync.native(o.dirname(e)),s=o.join(n,o.basename(e).replace(/\.(json5|json)$/,``));a.has(s)||a.set(s,{file:e,repo:r!==void 0||pW(e)?null:{dir:n,link:XU(n)}})}let s=[...a.values()],c=nW(e,s.flatMap(e=>e.repo===null?[]:[e.repo]),mW(t)),l=s.filter(e=>e.repo===null||c.approved.includes(e.repo.dir)).reverse().map(e=>({path:e.file,scope:e.repo===null?`plugins`:`repo`}));if(r===void 0)return{kind:`chain`,layers:l,home:hW(l),unchecked:i,repos:c};let[u]=i,d=r;return l.length>0?{kind:`chain`,layers:l,home:d,unchecked:i,repos:c}:u===void 0?{kind:`missing`,path:r,home:d,repos:c}:{kind:`unreadable`,...u,home:d,repos:c}}function pW(e){return sW.some(t=>e===`${uW()}.${t}`)}function mW(e){if(e===void 0||ZU(e)!==`present`)return null;let t=RU(o.join(e,FU)),n=f.realpathSync.native(e);return{dir:n,link:XU(n),path:e,ships:!(`error`in t)&&t.folders.length>0}}function hW(e){return e.find(e=>pW(e.path))?.path??`${uW()}.${sW[0]}`}function gW(e,t,n,r){let i=fW(e,t,n,r),a=i.kind===`chain`?i.layers:[];return{path:i.home,above:a.filter(e=>e.path!==i.home),repo:i.repos.plugins,cwd:n??null}}function _W(e){return vW(e).join(`
185
185
  `)||null}function vW(e){switch(e.kind){case`chain`:return e.unchecked.map(e=>`Config location could not be checked: ${e.path} — ${e.error}`);case`missing`:return[`Config file not found: ${e.path} — rendering the bundled default until it appears`];case`unreadable`:return[`Config file could not be read: ${e.path} — ${e.error} — rendering the bundled default until it can be`]}}function yW(e,t){let n=cW(e,t).filter(e=>ZU(e)===`present`),r=new Map;for(let e of n){let t=o.dirname(e),n=o.basename(e).replace(/\.(json5|json)$/,``),i=o.join(t,n);r.has(i)||r.set(i,[]),r.get(i).push(e)}let i=[...r.values()].filter(e=>e.length>1);return i.length===0?null:`config-extension collision: ${i.map(e=>{let[t,...n]=e;return`${t} shadows ${n.join(`, `)}`}).join(`; `)} — remove the duplicate`}function bW(e,t,n,r){return e===null?{...AW,config:WR(AW.raw,t)}:SW(e,f.readFileSync(e,`utf-8`),t,n,r)}const xW={scope:`plugins`,repo:null,checkout:null,beneath:{dropped:[],rendering:new Map}};function SW(e,t,n,r,i){let a=LW(e,t,i,(t,a)=>{let o=oU(aU(t,e,r.scope),r,{config:n,rendering:r.beneath.rendering},(t,n,r)=>OW(t,n,r,e,i)),s=uU(o,r.beneath.dropped);return{inherited:new Set([...eB(o.config),...a.filter(e=>s(e).length>0)]),layer:{plugins:o,owning:s}}}),{plugins:o,owning:s}=a.layer,c=dU(WR(a.raw,o.config),s,(a.raw.insert??[]).map(e=>e.seg));return{source:t,raw:a.raw,warnings:[...a.warnings,...o.dropped.map(XH)],plugins:{loaded:o.loaded,dropped:o.dropped,reached:c.reached,rendering:o.rendering},config:c.config}}const CW=new WeakMap;function wW(e,t,n,r){let i=JSON.stringify([[...r??[]].sort(),e.map(e=>[e.path,e.scope,EW(e.path)])]),a=CW.get(n)??new Map;CW.set(n,a);let o=JSON.stringify([t.repo,t.checkout?.root??null]),s=a.get(o);if(s?.key===i)return s.layer;let c=oU(e,t,{config:n,rendering:new Map},(e,t,n)=>OW(e,t,n,`<installed plugins>`,r));return a.set(o,{key:i,layer:c}),c}function TW(e,t,n){return oU(e,{repo:null,checkout:n},{config:t,rendering:new Map},(e,t,n)=>OW(e,t,n,`<plugin install>`,void 0)).dropped}function EW(e){try{let t=f.statSync(e);return`${t.ino}:${t.size}:${t.mtimeMs}`}catch(e){return e.code??`unreadable`}}function DW(e,t,n,r,i=e=>f.readFileSync(e,`utf-8`),a){let o={repo:r.repo,checkout:r.cwd===null?null:HU(r.cwd)},s=LU(o.repo),c=wW(s.definitions,o,t,a),l={...c,dropped:[...c.dropped,...s.strays]};n.warned(s.unchecked.map(e=>`Plugin folder could not be listed: ${e.path} — ${e.error}`));let u=l.config,d=[];for(let{path:t,scope:r}of e){let e=d.at(-1)?.plugins,s=SW(t,i(t),d.at(-1)?.config??u,{...o,scope:r,beneath:{dropped:[...l.dropped,...d.flatMap(e=>e.plugins.dropped)],rendering:e?.rendering??l.rendering}},a);n.warned(s.warnings),d.push({...s,path:t})}let p=new Set(d.flatMap(e=>[...e.plugins.reached])),m=e=>p.has(e.path),h=l.dropped.filter(m),g=l.dropped.filter(e=>!m(e));n.warned(h.map(XH));let _=d.at(-1)?.plugins.rendering??l.rendering,v={checkout:o.checkout,roots:s.roots,loaded:l.loaded,dropped:h,unreached:g,reached:p,rendering:_},y=d.at(-1),b=({warnings:e,...t})=>(n.warned(e),t);if(y===void 0)return{layers:d,base:u,installed:v,...b(jW(bW(null,u,xW),_,`<default>`,a))};try{return{layers:d,base:u,installed:v,...b(jW(y,_,y.path,a,d.slice(0,-1).reverse()))}}catch(e){for(let[e,t]of d.slice(0,-1).entries())jW(t,t.plugins.rendering,t.path,a,d.slice(0,e).reverse());throw e}}function OW(e,t,n,r,i){if(n){jW(kW(e),new Map,r,i);return}let a=mx(t),o=[],s={source:``,issues:o,allowedPalettes:new Set,groups:[],unplaced:[],inherited:[]};if(UH(s,e,fw(e),a),WH(s,e,a),KH(s,e,{checked:a,authored:a}),o.length>0)throw new Iy(r,o)}function kW(e){return{config:e,raw:{root:e.root,presets:e.presets},source:``}}const AW={raw:{},source:``,warnings:[],plugins:{loaded:[],dropped:[],reached:new Set,rendering:new Map}};function jW(e,t,n=`<config>`,r=new Set(Sv()),i=[]){let a=qV(e.config.segments,t),o=NW({...e,path:n},i,a),s=(t,s)=>{let c=vC(e.config,t,o.authored);return MW(e,n,r,i,c.config,a,o.dropped,[...c.notices,...s])};try{return s(o.cells,[])}catch(e){if(!(e instanceof Iy)||o.cells.length===0)throw e;let t=s([],[]),n=new Set(t.dropped.flatMap(e=>e.issues.map(e=>e.message))),{taken:r,refused:i}=o.cells.reduce((e,t)=>{try{return s([...e.taken,t],[]),{...e,taken:[...e.taken,t]}}catch(r){if(!(r instanceof Iy))throw r;let i=r.issues.filter(e=>!n.has(e.message)).map(e=>e.message).join(`; `);return{...e,refused:[...e.refused,yC(t,`${t.relation} "${t.anchor}", but the bar refuses it there: ${i}`)]}}},{taken:[],refused:[]});return s(r,i)}}function MW({raw:e,source:t},n,r,i,a,o,s,c){let l=[],u={source:t,issues:l,allowedPalettes:r,groups:[],unplaced:[],inherited:[]},d=()=>{if(l.length>0)throw new Iy(n,[...l,...u.unplaced,...u.inherited],c)};_H(u,a,e,o),WH(u,a),d();let f=FW(n,a.segments,u,o,i,s),p=qB(XV(a),l);d();let m=SR(RL(p)),h=new Set([...cw({variables:e.variables??{},segments:e.segments??{}})].map(([e])=>e));return KH(u,m,{checked:()=>!0,authored:e=>h.has(e)}),d(),{config:m,dropped:f,placed:a,warnings:c}}function NW(e,t,n){let r=[...t].reverse().concat(e),i=YV(e.config,r.flatMap(e=>e.raw.insert??[]),n),a=e=>!i(e.anchor),o=e=>n(e.seg).kind===`declared`,s=e=>JV(n(e.seg)),c=e=>(e.raw.insert??[]).filter(a);return{cells:r.flatMap(e=>c(e).filter(o)),authored:{root:r.some(e=>e.raw.root!==void 0),presets:new Set(r.flatMap(e=>Object.keys(e.raw.presets??{})))},dropped:r.flatMap(t=>{let r=zy(t.source);return(t.raw.insert??[]).filter(s).map(i=>({file:t.path,issue:{path:i.by.entry,message:mH(i.by.entry,i.seg,e.config.segments,n(i.seg)),line:r(i.by.entry.split(`.`))}}))})}}function PW(e){if(e.length>0)throw new Ry(e)}function FW(e,t,n,r,i,a){let o=new Map,s=(e,t)=>{o.set(e,[...o.get(e)??[],t])};for(let{file:e,issue:t}of a)s(e,t);for(let t of n.unplaced)s(e,t);for(let{name:a,...o}of n.inherited){let n=i.flatMap(e=>{let t=pH(e.raw,a);return t===void 0?[]:[{layer:e,...t}]})[0];n===void 0?s(e,o):s(n.layer.path,{path:n.path,message:mH(n.layoutKey,a,t,r(a)),line:G(n.layer.source,n.path.split(`.`))})}return[...o].map(([e,t])=>new Ly(e,t))}function IW(e,t,n=new Set(Sv()),r=RW){return LW(e,t,n,()=>({inherited:r,layer:null})).raw}function LW(e,t,n,r){let i=zW(e,t),a=Gy(e,t),o=a===null?[]:[a],s=[],c={source:t,issues:s,allowedPalettes:n??new Set(Sv()),groups:[],unplaced:[],inherited:[]};if(!Qy(i))throw new Iy(e,[{path:``,message:`Config root must be an object, got ${$y(i)}`}],o);let{inherited:l,layer:u}=r(i.plugins===void 0?[]:HW({...c,issues:[]},i.plugins)??[],Qy(i.segments)?Object.keys(i.segments):[]),d=BW(c,i,l,XB(e),e);if(s.length>0)throw new Iy(e,s,o);return{raw:d,warnings:o,layer:u}}const RW=new Set;function zW(e,t){try{return ca.default.parse(t)}catch(t){let n=t;throw new Iy(e,[{path:``,message:`JSON5 syntax error: ${n.message}`,line:n.lineNumber,col:n.columnNumber}])}}function BW(e,t,n,r,i){for(let n of Object.keys(t))VW.has(n)||e.issues.push({path:n,message:`Unknown top-level key "${n}". Expected one of: ${[...VW].join(`, `)}`,line:G(e.source,[n])});let a={};return t.globals!==void 0&&(a.globals=PN(e,`globals`,t.globals)),t.variables!==void 0&&(a.variables=lz(e,`variables`,t.variables)),t.segments!==void 0&&(a.segments=tB(e,t.segments,n)),t.layout!==void 0&&e.issues.push({path:`layout`,message:`"layout" is no longer supported — use "root" with the A-grammar instead.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptctl/cc-candybar",
3
- "version": "1.169.1",
3
+ "version": "1.170.0",
4
4
  "description": "Statusline renderer for Claude Code — a JSON5-configurable DSL with daemon-cached data sources, byte-clean palette-aware composition, and OSC8 click verbs.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.mjs",
@@ -102,9 +102,9 @@
102
102
  "typescript": "^5.0.0"
103
103
  },
104
104
  "optionalDependencies": {
105
- "@promptctl/cc-candybar-darwin-arm64": "1.169.1",
106
- "@promptctl/cc-candybar-darwin-x64": "1.169.1",
107
- "@promptctl/cc-candybar-linux-arm64": "1.169.1",
108
- "@promptctl/cc-candybar-linux-x64": "1.169.1"
105
+ "@promptctl/cc-candybar-darwin-arm64": "1.170.0",
106
+ "@promptctl/cc-candybar-darwin-x64": "1.170.0",
107
+ "@promptctl/cc-candybar-linux-arm64": "1.170.0",
108
+ "@promptctl/cc-candybar-linux-x64": "1.170.0"
109
109
  }
110
110
  }
@@ -110,7 +110,7 @@
110
110
  },
111
111
  "menuTimeout": {
112
112
  "type": "integer",
113
- "minimum": 10,
113
+ "minimum": 15,
114
114
  "maximum": 600
115
115
  },
116
116
  "renderer": {
@@ -1435,7 +1435,7 @@
1435
1435
  },
1436
1436
  "menuTimeout": {
1437
1437
  "type": "integer",
1438
- "minimum": 10,
1438
+ "minimum": 15,
1439
1439
  "maximum": 600
1440
1440
  },
1441
1441
  "renderer": {
@@ -1593,7 +1593,7 @@
1593
1593
  },
1594
1594
  "menuTimeout": {
1595
1595
  "type": "integer",
1596
- "minimum": 10,
1596
+ "minimum": 15,
1597
1597
  "maximum": 600
1598
1598
  },
1599
1599
  "renderer": {