@promptctl/cc-candybar 1.147.1 → 1.147.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +82 -82
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{createRequire as e}from"node:module";import t from"node:process";import{URL as n,URLSearchParams as r,fileURLToPath as i,pathToFileURL as a}from"node:url";import{json as o}from"node:stream/consumers";import s,{closeSync as c,constants as l,createReadStream as u,existsSync as d,fstatSync as f,openSync as p,readSync as m,realpathSync as h,statSync as g,watch as _}from"node:fs";import v,{basename as y,dirname as b,isAbsolute as x,join as S,sep as C}from"node:path";import w,{homedir as ee}from"node:os";import{spawn as te,spawnSync as ne}from"node:child_process";import{inspect as T,parseArgs as re,types as E}from"node:util";import D from"node:net";import ie from"node:v8";import O,{createHash as ae,randomUUID as oe}from"node:crypto";import{open as se,readFile as ce,readdir as le,stat as ue}from"node:fs/promises";import{clearInterval as de,setImmediate as fe,setInterval as pe}from"node:timers";import{get as me}from"node:https";import{setTimeout as he}from"node:timers/promises";import{createInterface as ge}from"node:readline";import{WriteStream as _e}from"node:tty";var ve=Object.create,ye=Object.defineProperty,be=Object.getOwnPropertyDescriptor,xe=Object.getOwnPropertyNames,Se=Object.getPrototypeOf,Ce=Object.prototype.hasOwnProperty,we=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),Te=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=xe(t),a=0,o=i.length,s;a<o;a++)s=i[a],!Ce.call(e,s)&&s!==n&&ye(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=be(t,s))||r.enumerable});return e},Ee=(e,t,n)=>(n=e==null?{}:ve(Se(e)),Te(t||!e||!e.__esModule?ye(n,`default`,{value:e,enumerable:!0}):n,e));function k(e,...t){process.env.CC_CANDYBAR_DEBUG&&console.error(`[DEBUG] ${e}`,...t)}function De(e,t){return E.isNativeError(e)?e.code===`ENOENT`&&t!==void 0&&!d(t)?`working directory does not exist: ${t}`:e.message:String(e)}const Oe={"click.pbcopy":1e3,"click.open":1e3,"doctor.tmux":1e3,"doctor.font":1e3,"doctor.process":1e3,"claude-input.type":1e3},ke=new Map;function Ae(e){let t=Oe[e];if(t===void 0)return{allowed:!0};let n=ke.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 je(e){ke.set(e,Date.now())}function Me(e){return e.env??process.env}function Ne(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 Pe=null;function Fe(e){Pe=e}function Ie(e,t){try{process.kill(-e,t)}catch(e){if(e.code!==`ESRCH`)throw e}}async function Le(e){if(e.signal?.aborted)return{ok:!1,reason:`aborted`,stdout:``,stderr:``,exitCode:null,signal:null};let t=Ae(e.category);if(!t.allowed)return Ne(e.category,t.minIntervalMs,t.sinceLastMs);je(e.category);let n=Date.now();return Pe?.onStart(e.category),new Promise(t=>{let r;try{r=te(e.bin,e.args??[],{cwd:e.cwd,env:Me(e),stdio:[`pipe`,`pipe`,`pipe`],detached:!0})}catch(r){Pe?.onEnd(e.category,Date.now()-n),t({ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:De(r,e.cwd)});return}let i=``,a=``,o=!1,s=null,c=null,l=null,u=()=>m(`aborted`),d=t=>{o||(o=!0,s&&clearTimeout(s),c&&clearTimeout(c),e.signal?.removeEventListener(`abort`,u),Pe?.onEnd(e.category,Date.now()-n),t())},f=e=>d(()=>t(e)),p=(e,t)=>{try{Ie(e,t)}catch(e){f({ok:!1,reason:`signal-refused`,stdout:i,stderr:a,exitCode:null,signal:null,error:e instanceof Error?e.message:String(e)})}},m=t=>{l=t,s&&clearTimeout(s),e.signal?.removeEventListener(`abort`,u);let n=r.pid;n!==void 0&&(c=setTimeout(()=>p(n,`SIGKILL`),250),p(n,`SIGTERM`))};r.stdout?.on(`data`,e=>{i+=e.toString(`utf8`)}),r.stderr?.on(`data`,e=>{a+=e.toString(`utf8`)}),r.on(`error`,t=>{f({ok:!1,reason:`spawn-error`,stdout:i,stderr:a,exitCode:null,signal:null,error:De(t,e.cwd)})}),r.on(`close`,(e,t)=>{if(l!==null){f({ok:!1,reason:l,stdout:i,stderr:a,exitCode:e,signal:t});return}if(e===0){f({ok:!0,stdout:i,stderr:a,exitCode:e});return}f({ok:!1,reason:t?`signal`:`non-zero`,stdout:i,stderr:a,exitCode:e,signal:t})}),e.timeoutMs&&e.timeoutMs>0&&(s=setTimeout(()=>m(`timeout`),e.timeoutMs)),e.signal?.addEventListener(`abort`,u,{once:!0}),e.stdinInput!==void 0&&r.stdin?r.stdin.end(e.stdinInput):r.stdin&&r.stdin.end()})}function Re(e){let t=Ae(e.category);if(!t.allowed)return Ne(e.category,t.minIntervalMs,t.sinceLastMs);je(e.category);let n=Date.now();Pe?.onStart(e.category);let r=[`pipe`,`pipe`,`pipe`];try{let t=ne(e.bin,e.args??[],{cwd:e.cwd,env:Me(e),input:e.stdinInput,timeout:e.timeoutMs&&e.timeoutMs>0?e.timeoutMs:void 0,stdio:r,encoding:`utf8`});Pe?.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:De(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 Pe?.onEnd(e.category,Date.now()-n),{ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:De(t,e.cwd)}}}function ze(e){let t=Ae(e.category);if(!t.allowed)return Ne(e.category,t.minIntervalMs,t.sinceLastMs);je(e.category);let n=Date.now();Pe?.onStart(e.category);let r=Be(e);return Pe?.onEnd(e.category,Date.now()-n),r}function Be(e){let t;try{t=te(e.bin,e.args??[],{cwd:e.cwd,env:Me(e),detached:!0,stdio:`ignore`})}catch(t){return{ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:De(t,e.cwd)}}return t.once(`error`,()=>{}),t.pid===void 0?{ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:`spawn(${e.bin}): no pid (binary not found or unexecutable)`}:(t.unref(),{ok:!0,stdout:``,stderr:``,exitCode:null})}function Ve(e,t,n){let r=`${e}.tmp`,i=n??s.statSync(e,{throwIfNoEntry:!1})?.mode;try{s.writeFileSync(r,t,i===void 0?{}:{mode:i}),s.renameSync(r,e)}catch(e){throw s.rmSync(r,{force:!0}),e}}function He(e,t){let n=e[t];return n&&n.length>0?n:void 0}function Ue(e=process.env){let t=He(e,`XDG_STATE_HOME`)??v.join(w.homedir(),`.local`,`state`);return v.join(t,`cc-candybar`)}function We(){let e=He(process.env,`XDG_CACHE_HOME`)??v.join(w.homedir(),`.cache`);return v.join(e,`cc-candybar`)}function Ge(){return Ue()}function Ke(){return process.env.CC_CANDYBAR_SOCKET||qe()}function qe(){let e=w.userInfo().uid;return v.join(`/tmp`,`cc-candybar-${e}`,`socket`)}function Je(e){s.mkdirSync(e,{recursive:!0,mode:448});let t=s.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 Ye(e){Je(v.dirname(e));for(let t of[e,Xe(e)])try{if(s.lstatSync(t).isSymbolicLink())throw Error(`path is a symlink: ${t}`)}catch(e){if(e.code!==`ENOENT`)throw e}}function Xe(e){return`${e}.lease`}function Ze(){return Xe(Ke())}function Qe(){return v.join(Ue(),`session-state.json`)}function $e(){return v.join(Ue(),`settings-history.json`)}function et(){let e=process.env.CC_CANDYBAR_DAEMON_REGISTRY_DIR;if(e)return e;let t=w.userInfo().uid;return v.join(`/tmp`,`cc-candybar-${t}`,`daemons`)}function tt(){return v.join(Ue(),`spawn.lock`)}function nt(){return v.join(Ue(),`spawn.cooldown`)}function rt(){return v.join(Ue(),`spawn.backoff`)}function it(){return v.join(Ue(),`diagnostics`)}function at(e=process.env){return v.join(Ue(e),`daemon.log`)}const ot=[`MEMENTO_CONFIG_HOME`,`XDG_CONFIG_HOME`];function st(e,t){return Object.fromEntries(ot.flatMap(n=>{let r=e[n]??``;return r===``?[]:[[n,v.resolve(t,r)]]}))}const ct=[`TERM_PROGRAM`,`TERM_PROGRAM_VERSION`,`TERM`,`ITERM_PROFILE`,`XDG_CONFIG_HOME`];function lt(e){return Object.fromEntries(ct.flatMap(t=>{let n=e[t]??``;return n===``?[]:[[t,n]]}))}const ut=[`native`,`node`,`frames`];function A(e,t){return{kind:e,bundle:t,source:null}}const dt=Object.keys({termCols:!0,termRows:!0,ssh:!0,tmux:!0,configEnv:!0,claudeConfigDir:!0,mementoEnv:!0,terminalEnv:!0,client:!0});function ft(e){let t=yt(e.termCols),n=yt(e.termRows),r=bt(e.ssh),i=_t(e.tmux),a=gt(e.configEnv),o=gt(e.claudeConfigDir),s=j(e.mementoEnv),c=ht(e.terminalEnv),l=Dt(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&&{mementoEnv:s},...c!==void 0&&{terminalEnv:c},...l!==void 0&&{client:l}}}function pt(e,t){return dt.filter(n=>e[n]!==void 0&&t[n]===void 0).map(t=>({hint:t,sent:e[t]}))}function mt(e){return e.length===0?null:`Client hints refused: ${e.map(({hint:e,sent:t})=>`${e}=${JSON.stringify(t)}`).join(`, `)} — is the statusline client older than the daemon? Reinstall it (\`cc-candybar install\`, or \`just install-rust\` in a checkout).`}function j(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=e,n=ot.filter(e=>t[e]!==void 0);return n.every(e=>gt(t[e])!==void 0)?Object.fromEntries(n.map(e=>[e,t[e]])):void 0}function ht(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=e,n=ct.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 gt(e){return typeof e==`string`&&v.isAbsolute(e)?e:void 0}function _t(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 vt=1e4;function yt(e){if(typeof e!=`number`||!Number.isFinite(e))return;let t=Math.floor(e);if(!(t<=0))return t>vt?vt:t}function bt(e){return typeof e==`boolean`?e:void 0}function xt(e){return typeof e==`string`&&e!==``&&e.length<=64?e:null}var St=class extends Error{constructor(e){super(e),this.name=`ProtocolError`}};function Ct(e){return wt(JSON.stringify(e))}function wt(e){let t=Buffer.from(e,`utf8`),n=Buffer.alloc(4);return n.writeUInt32BE(t.length,0),Buffer.concat([n,t])}function Tt(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 St(`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 St(e instanceof Error?e.message:String(e));e instanceof Error&&(n.cause=e),t(n);return}}}}function Et(e,t,n){return new Promise((r,i)=>{let a=!1,o=t=>{if(!a){a=!0,clearTimeout(s),e.removeAllListeners();try{t()}catch{}}},s=setTimeout(()=>{o(()=>{e.destroy(),i(Error(`TIMEOUT`))})},n),c=Tt(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(Ct(t))})}function Dt(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let{kind:t,bundle:n,source:r}=e,i=gt(n);return ut.includes(t)&&i!==void 0&&(r===null||typeof r==`string`&&r!==``)?{kind:t,bundle:i,source:r}:void 0}async function Ot(e,t,n){let r=null;try{r=await Nt(Ke(),t.connectMs);let i=await Et(r,{v:3,...e},t.budgetMs);return jt(e.kind,i,n)}catch(e){return Mt(e)}finally{r&&r.destroy()}}function kt(e,t){return typeof e==`string`?e:t}function At(e){return typeof e==`number`&&Number.isInteger(e)&&e>=0?e:0}function jt(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=kt(r.error,`(no error message)`);switch(r.code){case`VERSION_MISMATCH`:return{kind:`permanent`,cause:`version_mismatch`,clientV:3,daemonV:At(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 Mt(e){if(e instanceof St||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 Nt(e,t){return new Promise((n,r)=>{let i=D.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 Pt(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 Ft=`1.147.1`,It={connectMs:50,budgetMs:150},Lt={connectMs:50,budgetMs:200};function Rt(e){let t=e.output;return typeof t==`string`?t:void 0}function zt(e){return jt(`render`,e,Rt)}function Bt(e,t,n,r){return Ot({kind:`render`,hookData:e,args:t,cwd:n,...r},It,Rt)}function Vt(e,t){return Ot({kind:`pane-session`,socket:e,pane:t},Lt,e=>`paneSession`in e?e.paneSession:void 0)}function Ht(e,t){return Ot({kind:`click`,verb:e,value:t,clientVersion:Ft},Lt,Rt)}let M=null;function Ut(e){if(M!==null)return M;s.mkdirSync(v.dirname(e),{recursive:!0});try{M=s.statSync(e).size}catch{M=0}return M}function Wt(e){for(let t=2;t>=1;t--){let n=`${e}.${t}`,r=`${e}.${t+1}`;try{s.renameSync(n,r)}catch{}}try{s.renameSync(e,`${e}.1`)}catch{}M=0}const Gt=(e,t)=>k(t);function N(e,t){let n=`${new Date().toISOString()} [${e}] ${t}\n`;try{let e=at(),t=Ut(e);s.appendFileSync(e,n),M=t+Buffer.byteLength(n,`utf8`),M>=5242880&&Wt(e)}catch(e){M=null;try{process.stderr.write(`${n}cc-candybar: daemon.log unwritable: ${e.message}\n`)}catch{}}}function Kt(e){let t=[];for(let n of e){let e=n.read();if(e.kind===`text`)return`# memory report from: ${n.name}\n${e.text}`;t.push(`# ${n.name}: unavailable — ${e.reason}`)}return[`# memory report: no probe answered`,...t.length>0?t:[`# no probe is known for this platform`]].join(`
|
|
2
|
+
import{createRequire as e}from"node:module";import t from"node:process";import{URL as n,URLSearchParams as r,fileURLToPath as i,pathToFileURL as a}from"node:url";import{json as o}from"node:stream/consumers";import s,{closeSync as c,constants as l,createReadStream as u,existsSync as d,fstatSync as f,openSync as p,readSync as m,realpathSync as h,statSync as g,watch as _}from"node:fs";import v,{basename as y,dirname as b,isAbsolute as x,join as S,sep as C}from"node:path";import w,{homedir as ee}from"node:os";import{spawn as te,spawnSync as ne}from"node:child_process";import{inspect as T,parseArgs as re,types as E}from"node:util";import D from"node:net";import ie from"node:v8";import O,{createHash as ae,randomUUID as oe}from"node:crypto";import{open as se,readFile as ce,readdir as le,stat as ue}from"node:fs/promises";import{clearInterval as de,setImmediate as fe,setInterval as pe}from"node:timers";import{get as me}from"node:https";import{setTimeout as he}from"node:timers/promises";import{createInterface as ge}from"node:readline";import{WriteStream as _e}from"node:tty";var ve=Object.create,ye=Object.defineProperty,be=Object.getOwnPropertyDescriptor,xe=Object.getOwnPropertyNames,Se=Object.getPrototypeOf,Ce=Object.prototype.hasOwnProperty,we=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),Te=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=xe(t),a=0,o=i.length,s;a<o;a++)s=i[a],!Ce.call(e,s)&&s!==n&&ye(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=be(t,s))||r.enumerable});return e},Ee=(e,t,n)=>(n=e==null?{}:ve(Se(e)),Te(t||!e||!e.__esModule?ye(n,`default`,{value:e,enumerable:!0}):n,e));function k(e,...t){process.env.CC_CANDYBAR_DEBUG&&console.error(`[DEBUG] ${e}`,...t)}function De(e,t){return E.isNativeError(e)?e.code===`ENOENT`&&t!==void 0&&!d(t)?`working directory does not exist: ${t}`:e.message:String(e)}const Oe={"click.pbcopy":1e3,"click.open":1e3,"doctor.tmux":1e3,"doctor.font":1e3,"doctor.process":1e3,"claude-input.type":1e3},ke=new Map;function Ae(e){let t=Oe[e];if(t===void 0)return{allowed:!0};let n=ke.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 je(e){ke.set(e,Date.now())}function Me(e){return e.env??process.env}function Ne(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 Pe=null;function Fe(e){Pe=e}function Ie(e,t){try{process.kill(-e,t)}catch(e){if(e.code!==`ESRCH`)throw e}}async function Le(e){if(e.signal?.aborted)return{ok:!1,reason:`aborted`,stdout:``,stderr:``,exitCode:null,signal:null};let t=Ae(e.category);if(!t.allowed)return Ne(e.category,t.minIntervalMs,t.sinceLastMs);je(e.category);let n=Date.now();return Pe?.onStart(e.category),new Promise(t=>{let r;try{r=te(e.bin,e.args??[],{cwd:e.cwd,env:Me(e),stdio:[`pipe`,`pipe`,`pipe`],detached:!0})}catch(r){Pe?.onEnd(e.category,Date.now()-n),t({ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:De(r,e.cwd)});return}let i=``,a=``,o=!1,s=null,c=null,l=null,u=()=>m(`aborted`),d=t=>{o||(o=!0,s&&clearTimeout(s),c&&clearTimeout(c),e.signal?.removeEventListener(`abort`,u),Pe?.onEnd(e.category,Date.now()-n),t())},f=e=>d(()=>t(e)),p=(e,t)=>{try{Ie(e,t)}catch(e){f({ok:!1,reason:`signal-refused`,stdout:i,stderr:a,exitCode:null,signal:null,error:e instanceof Error?e.message:String(e)})}},m=t=>{l=t,s&&clearTimeout(s),e.signal?.removeEventListener(`abort`,u);let n=r.pid;n!==void 0&&(c=setTimeout(()=>p(n,`SIGKILL`),250),p(n,`SIGTERM`))};r.stdout?.on(`data`,e=>{i+=e.toString(`utf8`)}),r.stderr?.on(`data`,e=>{a+=e.toString(`utf8`)}),r.on(`error`,t=>{f({ok:!1,reason:`spawn-error`,stdout:i,stderr:a,exitCode:null,signal:null,error:De(t,e.cwd)})}),r.on(`close`,(e,t)=>{if(l!==null){f({ok:!1,reason:l,stdout:i,stderr:a,exitCode:e,signal:t});return}if(e===0){f({ok:!0,stdout:i,stderr:a,exitCode:e});return}f({ok:!1,reason:t?`signal`:`non-zero`,stdout:i,stderr:a,exitCode:e,signal:t})}),e.timeoutMs&&e.timeoutMs>0&&(s=setTimeout(()=>m(`timeout`),e.timeoutMs)),e.signal?.addEventListener(`abort`,u,{once:!0}),e.stdinInput!==void 0&&r.stdin?r.stdin.end(e.stdinInput):r.stdin&&r.stdin.end()})}function Re(e){let t=Ae(e.category);if(!t.allowed)return Ne(e.category,t.minIntervalMs,t.sinceLastMs);je(e.category);let n=Date.now();Pe?.onStart(e.category);let r=[`pipe`,`pipe`,`pipe`];try{let t=ne(e.bin,e.args??[],{cwd:e.cwd,env:Me(e),input:e.stdinInput,timeout:e.timeoutMs&&e.timeoutMs>0?e.timeoutMs:void 0,stdio:r,encoding:`utf8`});Pe?.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:De(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 Pe?.onEnd(e.category,Date.now()-n),{ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:De(t,e.cwd)}}}function ze(e){let t=Ae(e.category);if(!t.allowed)return Ne(e.category,t.minIntervalMs,t.sinceLastMs);je(e.category);let n=Date.now();Pe?.onStart(e.category);let r=Be(e);return Pe?.onEnd(e.category,Date.now()-n),r}function Be(e){let t;try{t=te(e.bin,e.args??[],{cwd:e.cwd,env:Me(e),detached:!0,stdio:`ignore`})}catch(t){return{ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:De(t,e.cwd)}}return t.once(`error`,()=>{}),t.pid===void 0?{ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:`spawn(${e.bin}): no pid (binary not found or unexecutable)`}:(t.unref(),{ok:!0,stdout:``,stderr:``,exitCode:null})}function Ve(e,t,n){let r=`${e}.tmp`,i=n??s.statSync(e,{throwIfNoEntry:!1})?.mode;try{s.writeFileSync(r,t,i===void 0?{}:{mode:i}),s.renameSync(r,e)}catch(e){throw s.rmSync(r,{force:!0}),e}}function He(e,t){let n=e[t];return n&&n.length>0?n:void 0}function Ue(e=process.env){let t=He(e,`XDG_STATE_HOME`)??v.join(w.homedir(),`.local`,`state`);return v.join(t,`cc-candybar`)}function We(){let e=He(process.env,`XDG_CACHE_HOME`)??v.join(w.homedir(),`.cache`);return v.join(e,`cc-candybar`)}function Ge(){return Ue()}function Ke(){return process.env.CC_CANDYBAR_SOCKET||qe()}function qe(){let e=w.userInfo().uid;return v.join(`/tmp`,`cc-candybar-${e}`,`socket`)}function Je(e){s.mkdirSync(e,{recursive:!0,mode:448});let t=s.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 Ye(e){Je(v.dirname(e));for(let t of[e,Xe(e)])try{if(s.lstatSync(t).isSymbolicLink())throw Error(`path is a symlink: ${t}`)}catch(e){if(e.code!==`ENOENT`)throw e}}function Xe(e){return`${e}.lease`}function Ze(){return Xe(Ke())}function Qe(){return v.join(Ue(),`session-state.json`)}function $e(){return v.join(Ue(),`settings-history.json`)}function et(){let e=process.env.CC_CANDYBAR_DAEMON_REGISTRY_DIR;if(e)return e;let t=w.userInfo().uid;return v.join(`/tmp`,`cc-candybar-${t}`,`daemons`)}function tt(){return v.join(Ue(),`spawn.lock`)}function nt(){return v.join(Ue(),`spawn.cooldown`)}function rt(){return v.join(Ue(),`spawn.backoff`)}function it(){return v.join(Ue(),`diagnostics`)}function at(e=process.env){return v.join(Ue(e),`daemon.log`)}const ot=[`MEMENTO_CONFIG_HOME`,`XDG_CONFIG_HOME`];function st(e,t){return Object.fromEntries(ot.flatMap(n=>{let r=e[n]??``;return r===``?[]:[[n,v.resolve(t,r)]]}))}const ct=[`TERM_PROGRAM`,`TERM_PROGRAM_VERSION`,`TERM`,`ITERM_PROFILE`,`XDG_CONFIG_HOME`];function lt(e){return Object.fromEntries(ct.flatMap(t=>{let n=e[t]??``;return n===``?[]:[[t,n]]}))}const ut=[`native`,`node`,`frames`];function A(e,t){return{kind:e,bundle:t,source:null}}const dt=Object.keys({termCols:!0,termRows:!0,ssh:!0,tmux:!0,configEnv:!0,claudeConfigDir:!0,mementoEnv:!0,terminalEnv:!0,client:!0});function ft(e){let t=yt(e.termCols),n=yt(e.termRows),r=bt(e.ssh),i=_t(e.tmux),a=gt(e.configEnv),o=gt(e.claudeConfigDir),s=j(e.mementoEnv),c=ht(e.terminalEnv),l=Dt(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&&{mementoEnv:s},...c!==void 0&&{terminalEnv:c},...l!==void 0&&{client:l}}}function pt(e,t){return dt.filter(n=>e[n]!==void 0&&t[n]===void 0).map(t=>({hint:t,sent:e[t]}))}function mt(e){return e.length===0?null:`Client hints refused: ${e.map(({hint:e,sent:t})=>`${e}=${JSON.stringify(t)}`).join(`, `)} — is the statusline client older than the daemon? Reinstall it (\`cc-candybar install\`, or \`just install-rust\` in a checkout).`}function j(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=e,n=ot.filter(e=>t[e]!==void 0);return n.every(e=>gt(t[e])!==void 0)?Object.fromEntries(n.map(e=>[e,t[e]])):void 0}function ht(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=e,n=ct.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 gt(e){return typeof e==`string`&&v.isAbsolute(e)?e:void 0}function _t(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 vt=1e4;function yt(e){if(typeof e!=`number`||!Number.isFinite(e))return;let t=Math.floor(e);if(!(t<=0))return t>vt?vt:t}function bt(e){return typeof e==`boolean`?e:void 0}function xt(e){return typeof e==`string`&&e!==``&&e.length<=64?e:null}var St=class extends Error{constructor(e){super(e),this.name=`ProtocolError`}};function Ct(e){return wt(JSON.stringify(e))}function wt(e){let t=Buffer.from(e,`utf8`),n=Buffer.alloc(4);return n.writeUInt32BE(t.length,0),Buffer.concat([n,t])}function Tt(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 St(`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 St(e instanceof Error?e.message:String(e));e instanceof Error&&(n.cause=e),t(n);return}}}}function Et(e,t,n){return new Promise((r,i)=>{let a=!1,o=t=>{if(!a){a=!0,clearTimeout(s),e.removeAllListeners();try{t()}catch{}}},s=setTimeout(()=>{o(()=>{e.destroy(),i(Error(`TIMEOUT`))})},n),c=Tt(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(Ct(t))})}function Dt(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let{kind:t,bundle:n,source:r}=e,i=gt(n);return ut.includes(t)&&i!==void 0&&(r===null||typeof r==`string`&&r!==``)?{kind:t,bundle:i,source:r}:void 0}async function Ot(e,t,n){let r=null;try{r=await Nt(Ke(),t.connectMs);let i=await Et(r,{v:3,...e},t.budgetMs);return jt(e.kind,i,n)}catch(e){return Mt(e)}finally{r&&r.destroy()}}function kt(e,t){return typeof e==`string`?e:t}function At(e){return typeof e==`number`&&Number.isInteger(e)&&e>=0?e:0}function jt(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=kt(r.error,`(no error message)`);switch(r.code){case`VERSION_MISMATCH`:return{kind:`permanent`,cause:`version_mismatch`,clientV:3,daemonV:At(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 Mt(e){if(e instanceof St||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 Nt(e,t){return new Promise((n,r)=>{let i=D.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 Pt(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 Ft=`1.147.2`,It={connectMs:50,budgetMs:150},Lt={connectMs:50,budgetMs:200};function Rt(e){let t=e.output;return typeof t==`string`?t:void 0}function zt(e){return jt(`render`,e,Rt)}function Bt(e,t,n,r){return Ot({kind:`render`,hookData:e,args:t,cwd:n,...r},It,Rt)}function Vt(e,t){return Ot({kind:`pane-session`,socket:e,pane:t},Lt,e=>`paneSession`in e?e.paneSession:void 0)}function Ht(e,t){return Ot({kind:`click`,verb:e,value:t,clientVersion:Ft},Lt,Rt)}let M=null;function Ut(e){if(M!==null)return M;s.mkdirSync(v.dirname(e),{recursive:!0});try{M=s.statSync(e).size}catch{M=0}return M}function Wt(e){for(let t=2;t>=1;t--){let n=`${e}.${t}`,r=`${e}.${t+1}`;try{s.renameSync(n,r)}catch{}}try{s.renameSync(e,`${e}.1`)}catch{}M=0}const Gt=(e,t)=>k(t);function N(e,t){let n=`${new Date().toISOString()} [${e}] ${t}\n`;try{let e=at(),t=Ut(e);s.appendFileSync(e,n),M=t+Buffer.byteLength(n,`utf8`),M>=5242880&&Wt(e)}catch(e){M=null;try{process.stderr.write(`${n}cc-candybar: daemon.log unwritable: ${e.message}\n`)}catch{}}}function Kt(e){let t=[];for(let n of e){let e=n.read();if(e.kind===`text`)return`# memory report from: ${n.name}\n${e.text}`;t.push(`# ${n.name}: unavailable — ${e.reason}`)}return[`# memory report: no probe answered`,...t.length>0?t:[`# no probe is known for this platform`]].join(`
|
|
3
3
|
`)}function qt(e,t){return e===`darwin`?[P(`footprint`,[`-p`,String(t)]),P(`vmmap`,[`--summary`,String(t)])]:e===`linux`?[Jt(`/proc/self/smaps_rollup`),Jt(`/proc/self/status`)]:[]}function P(e,t){return{name:`${e} ${t.join(` `)}`,read:()=>{let n=Re({bin:e,args:[...t],timeoutMs:5e3,category:`limits.memory-report`});return n.ok?n.stdout.trim().length>0?{kind:`text`,text:n.stdout}:{kind:`unavailable`,reason:`exited 0 but printed nothing`}:{kind:`unavailable`,reason:`${n.reason}${n.error===void 0?``:`: ${n.error}`}${Yt(n.stderr)}`}}}}function Jt(e){return{name:e,read:()=>{try{let t=s.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 Yt(e){let t=e.split(`
|
|
4
4
|
`).map(e=>e.trim()).find(e=>e.length>0);return t===void 0?``:` (${t})`}const Xt=`CC_CANDYBAR_RSS_LIMIT_MB`;function Zt(e){let t=e[Xt];if(t===void 0)return 512;let n=/^\d+$/.test(t)?Number(t):NaN;if(!Number.isSafeInteger(n)||n<=0)throw Error(`${Xt} must be a positive integer (MB), got ${JSON.stringify(t)}`);return n}function Qt(e){return Zt(e)*2}const $t=1024*1024,en=e=>Math.round(e/$t);function tn(e){return Zt(e)*$t}const nn={memoryReport:{prefix:`memory-`,suffix:`.txt`},heapSnapshot:{prefix:`heap-`,suffix:`.heapsnapshot`}};function rn(e,t){return e>t}function an(e,t){return e>t*.75}function on(e,t,n){let{prefix:r,suffix:i}=nn[t];return v.join(e,`${r}${n}${i}`)}function sn(e){for(let t of Object.keys(nn)){let{prefix:n,suffix:r}=nn[t];if(e.startsWith(n)&&e.endsWith(r))return t}return null}function cn(e){let t=e.rssLimitBytes??512*$t,n=e.snapshotsKeep??3,r=!1;function i(){if(r)return!0;let{rss:i,heapTotal:a}=e.memoryBytes();if(i<=t)return!1;r=!0,e.log(`warn`,`RSS ${i} > limit ${t} (v8 heap ${a}); recording memory then shutting down`);let o=`${new Date(e.now()).toISOString().replace(/[:.]/g,`-`)}-${e.pid}`;return ln(e.log,`memory report`,()=>{let t=on(e.snapshotDir,`memoryReport`,o);e.writeMemoryReport(t,e.captureMemoryReport()),e.log(`info`,`memory report written: ${t}`)}),ln(e.log,`heap snapshot`,()=>{let t=on(e.snapshotDir,`heapSnapshot`,o);e.log(`info`,`heap snapshot written: ${e.writeHeapSnapshot(t)}`)}),ln(e.log,`artifact rotation`,()=>{for(let{artifacts:t}of un(e.listArtifacts()).slice(n))for(let n of Object.values(t))ln(e.log,`evicting ${n}`,()=>e.removeFile(n))}),e.shutdown(0),!0}function a(){let{rss:n,heapTotal:r}=e.memoryBytes();return an(n,t)?`rss ${n} approaching limit ${t} (v8 heap ${r})`:null}function o(){let{rss:n}=e.memoryBytes(),r;try{r={kind:`ok`,value:un(e.listArtifacts())}}catch(e){r={kind:`failed`,reason:e.message}}return{pid:e.pid,rss:n,rssLimit:t,postMortems:r}}function s(e=6e4){let t=setInterval(()=>{i()},e);return t.unref(),{disarm:()=>clearInterval(t)}}return{checkRss:i,describeNextRestart:a,serving:o,arm:s}}function ln(e,t,n){try{n()}catch(n){e(`warn`,`${t} failed: ${n.message}`)}}function un(e){let t=new Map;for(let n of e){let e=v.basename(n),r=sn(e);if(r===null)continue;let{prefix:i,suffix:a}=nn[r],o=e.slice(i.length,e.length-a.length);t.set(o,{...t.get(o),[r]:n})}let n=Object.keys(nn);return[...t].sort(([e],[t])=>rn(e,t)?-1:1).map(([e,t])=>({identity:e,artifacts:Object.fromEntries(n.flatMap(e=>t[e]===void 0?[]:[[e,t[e]]]))}))}function dn(e,t,n={}){let r=Ge();return{now:()=>Date.now(),pid:process.pid,snapshotDir:r,log:N,memoryBytes:()=>{let e=process.memoryUsage();return{rss:e.rss,heapTotal:e.heapTotal}},captureMemoryReport:()=>Kt(qt(process.platform,process.pid)),writeMemoryReport:(e,t)=>s.writeFileSync(e,t,{mode:384}),writeHeapSnapshot:e=>ie.writeHeapSnapshot(e),listArtifacts:()=>{let e;try{e=s.readdirSync(r)}catch(e){if(e.code===`ENOENT`)return[];throw e}return e.filter(e=>sn(e)!==null).map(e=>v.join(r,e))},removeFile:e=>s.unlinkSync(e),shutdown:t,startedAtMs:e,...n}}function fn(e={}){if(Dn()!==null)return;let n=e.spawn??On,r=wn();if(r.kind===`contended`){let e=mn();e!==null&&e>2e3&&(t.stderr.write(`cc-candybar: spawn-lock held ${e}ms (likely crashed holder) — spawning unlocked\n`),pn(n));return}if(r.kind===`error`){t.stderr.write(`cc-candybar: spawn-lock unavailable (${r.reason}) — spawning unlocked\n`),pn(n);return}try{pn(n)}finally{En()}}function pn(e){xn()&&hn(e)}function mn(){try{let e=s.statSync(tt());return Date.now()-e.mtimeMs}catch{return null}}function hn(e){try{e()||t.stderr.write(`cc-candybar: daemon spawn returned false (unable to resolve script path?)
|
|
5
5
|
`)}catch(e){t.stderr.write(`cc-candybar: daemon spawn failed: ${e.message}\n`)}}function gn(e,t){return e===null?{kind:`allow`}:e<-1e4?{kind:`allow-future-garbage`,futureMs:-e}:e<t?{kind:`deny`}:{kind:`allow`}}function _n(e){return Math.min(3e3*2**Math.min(Math.max(e,0),5),6e4)}function vn(e){try{let t=s.readFileSync(e,`utf8`).trim(),n=Number(t);return!Number.isInteger(n)||n<0?0:Math.min(n,5)}catch{return 0}}function yn(e,n){try{s.mkdirSync(v.dirname(e),{recursive:!0}),s.writeFileSync(e,String(n),{mode:384})}catch(e){t.stderr.write(`cc-candybar: could not record spawn.backoff: ${e.message}\n`)}}function bn(){try{s.unlinkSync(rt())}catch(e){e.code!==`ENOENT`&&t.stderr.write(`cc-candybar: could not reset spawn.backoff: ${e.message}\n`)}}function xn(){let e=nt(),n=rt(),r=vn(n),i=gn(Sn(e),_n(r));return i.kind===`deny`?!1:(i.kind===`allow-future-garbage`&&t.stderr.write(`cc-candybar: spawn.cooldown mtime is ${i.futureMs}ms in the future — ignoring and spawning\n`),Cn(e),yn(n,Math.min(r+1,5)),!0)}function Sn(e){try{return Date.now()-s.statSync(e).mtimeMs}catch{return null}}function Cn(e){try{s.mkdirSync(v.dirname(e),{recursive:!0}),s.writeFileSync(e,`${t.pid} ${Date.now()}\n`,{mode:384})}catch(e){t.stderr.write(`cc-candybar: could not record spawn.cooldown: ${e.message}\n`)}}let F=null;function wn(){let e=tt();for(let n=0;n<2;n++){try{let n=s.openSync(e,`wx`,384);try{s.writeSync(n,JSON.stringify({pid:t.pid,ts:Date.now()}))}catch{}return F={fd:n,path:e},{kind:`held`}}catch(t){let n=t.code;if(n!==`EEXIST`)return{kind:`error`,reason:`openSync(${e}): ${n??t.message}`}}if(!Tn(e))return{kind:`contended`};try{s.unlinkSync(e)}catch(e){if(e.code!==`ENOENT`)return{kind:`error`,reason:`unlink stale spawn.lock: ${e.message}`}}}return{kind:`contended`}}function Tn(e){try{let t=s.statSync(e);return Date.now()-t.mtimeMs>1e4}catch{return!0}}function En(){if(!F)return;let{fd:e,path:t}=F;F=null;try{s.closeSync(e)}catch{}try{s.unlinkSync(t)}catch{}}function Dn(){try{return s.mkdirSync(Ge(),{recursive:!0}),null}catch(e){return`mkdir ${Ge()}: ${e.message}`}}function On(){let e=t.execPath,n=t.argv[1];return n?ze({bin:e,args:[`--max-old-space-size=${Qt(t.env)}`,n,`daemon`],category:`daemon-spawn`}).ok:!1}const kn=`cc-candybar`,An=`dispatch`,jn=`set-state`,Mn=`step-state`,Nn=`copy`,Pn=`open-vscode`,Fn=`toolbar-toggle`,In=`show-config-error`,Ln=`show-config-warning`,Rn=`set-config`,zn=`step-config`,Bn=`save`,Vn=`save-preset`,Hn=`save-theme-default`,Un=`delete-preset`,Wn=`reset-config`,Gn=`apply-layout-op`,Kn=`undo`,qn=`redo`,Jn=`back`,Yn=`rewind`,Xn=`apply-update`,Zn=`doctor-run`,Qn=`doctor-fix`,$n=`doctor-mark`,er=`doctor-probe`,tr=`ceiling`,nr=`slash`;function rr(e){return e.map(encodeURIComponent).join(`/`)}function ir(e){return e.length===0?[]:e.split(`/`).map(decodeURIComponent)}function I(e){return`${kn}://${An}/${e.map(e=>`e=${encodeURIComponent(`${e.verb}/${rr(e.args)}`)}`).join(`&`)}`}function ar(e){return new r(e).getAll(`e`).map(lr)}const or=new Set([jn,Wn]);function sr(e){return e.reduce((e,t)=>{let n=e.at(-1),r=n&&cr(n,t);return r?[...e.slice(0,-1),r]:[...e,t]},[])}function cr(e,t){if(e.verb!==t.verb||!or.has(e.verb))return;let[n,r]=[lr(e.value),lr(t.value)];return n.verb===r.verb?{verb:e.verb,value:`${n.verb}/${n.value}/${r.value}`}:void 0}function lr(e){let t=e.indexOf(`/`);return t===-1?{verb:e,value:``}:{verb:e.slice(0,t),value:e.slice(t+1)}}const ur=`closed`,dr=`🍫`;function fr(e,t,n){if(t===0)return`${e} needs a display (the clickable text)`;if(t!==1&&t!==n)return`${e} cycles ${n} members; bind one display per member (${n}) or one static display, got ${t}`}function pr(e,t,n,r){let i=fr(e,t.length,n);if(i!==void 0)throw Error(i);return t.length===1?t[0]:t[r]}function mr(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}function hr(e,t,n,r,i){return{kind:`segment`,name:e,opens:{ref:t,body:n,placement:r},...i!==void 0&&{when:i}}}function gr(e,...t){return`{{ and ${[e,...t].map(_r).join(` `)} }}`}function _r(e){return`(eq .${e.variable} "${mr(e.member)}")`}function vr(e,t,n){return`{{ ${yr(e,br(t),br(n))} }}`}function yr(e,t,n){return`action "${e}" ${t} ${n}`}function br(e){return`"${mr(e)}"`}function xr(e,t){return{kind:`state`,key:e,default:t}}function Sr(e,t){return{set:e,cycle:[ur,t]}}const Cr=/^[A-Za-z0-9_./,:@%+-][A-Za-z0-9_./,:@%+=-]*$/;function wr(e){return`'${e.replaceAll(`'`,`'\\''`)}'`}function Tr(e){return Cr.test(e)?e:wr(e)}var Er=we(((e,t)=>{t.exports.Space_Separator=/[\u1680\u2000-\u200A\u202F\u205F\u3000]/,t.exports.ID_Start=/[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE83\uDE86-\uDE89\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]/,t.exports.ID_Continue=/[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u08D4-\u08E1\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u09FC\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9-\u0AFF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C80-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D00-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D54-\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19D9\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1CD0-\u1CD2\u1CD4-\u1CF9\u1D00-\u1DF9\u1DFB-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE3E\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC00-\uDC4A\uDC50-\uDC59\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDE00-\uDE3E\uDE47\uDE50-\uDE83\uDE86-\uDE99\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC36\uDC38-\uDC40\uDC50-\uDC59\uDC72-\uDC8F\uDC92-\uDCA7\uDCA9-\uDCB6\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD36\uDD3A\uDD3C\uDD3D\uDD3F-\uDD47\uDD50-\uDD59]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD838[\uDC00-\uDC06\uDC08-\uDC18\uDC1B-\uDC21\uDC23\uDC24\uDC26-\uDC2A]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6\uDD00-\uDD4A\uDD50-\uDD59]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/})),Dr=we(((e,t)=>{let n=Er();t.exports={isSpaceSeparator(e){return typeof e==`string`&&n.Space_Separator.test(e)},isIdStartChar(e){return typeof e==`string`&&(e>=`a`&&e<=`z`||e>=`A`&&e<=`Z`||e===`$`||e===`_`||n.ID_Start.test(e))},isIdContinueChar(e){return typeof e==`string`&&(e>=`a`&&e<=`z`||e>=`A`&&e<=`Z`||e>=`0`&&e<=`9`||e===`$`||e===`_`||e===``||e===``||n.ID_Continue.test(e))},isDigit(e){return typeof e==`string`&&/[0-9]/.test(e)},isHexDigit(e){return typeof e==`string`&&/[0-9A-Fa-f]/.test(e)}}})),Or=we(((e,t)=>{let n=Dr(),r,i,a,o,s,c,l,u,d;t.exports=function(e,t){r=String(e),i=`start`,a=[],o=0,s=1,c=0,l=void 0,u=void 0,d=void 0;do l=v(),ne[i]();while(l.type!==`eof`);return typeof t==`function`?f({"":d},``,t):d};function f(e,t,n){let r=e[t];if(typeof r==`object`&&r)if(Array.isArray(r))for(let e=0;e<r.length;e++){let t=String(e),i=f(r,t,n);i===void 0?delete r[t]:Object.defineProperty(r,t,{value:i,writable:!0,enumerable:!0,configurable:!0})}else for(let e in r){let t=f(r,e,n);t===void 0?delete r[e]:Object.defineProperty(r,e,{value:t,writable:!0,enumerable:!0,configurable:!0})}return n.call(e,t,r)}let p,m,h,g,_;function v(){for(p=`default`,m=``,h=!1,g=1;;){_=y();let e=x[p]();if(e)return e}}function y(){if(r[o])return String.fromCodePoint(r.codePointAt(o))}function b(){let e=y();return e===`
|
|
@@ -47,38 +47,38 @@ import{createRequire as e}from"node:module";import t from"node:process";import{U
|
|
|
47
47
|
`,this._tabSize=Co(t?.tabSize??8),this._noWrap=t?.noWrap??!1}get plain(){return this._text}set plain(e){let t=vu(e);this._text=t;let n=t.length;this._spans=this._spans.map(e=>e.end>n?new Ou(e.start,Math.min(e.end,n),e.style):e).filter(e=>e.start<n)}get length(){return this._text.length}get cellLength(){return io(wo(this._text,this._tabSize).text)}get hasContent(){return this._text.length>0}get style(){return this._style}set style(e){this._style=Cu(e)}get justify(){return this._justify}set justify(e){this._justify=e}get overflow(){return this._overflow}set overflow(e){this._overflow=e}get end(){return this._end}set end(e){this._end=e}get noWrap(){return this._noWrap}set noWrap(e){this._noWrap=e}get spans(){return this._spans}resolvedStyle(e){return Eu(e,this._style)}edgeStyle(e,t){let n=this.resolvedStyle(t);if(this._text.length===0)return n;let r=e===`left`?0:this._text.length-1,i=n;for(let e of this._spans)e.start<=r&&r<e.end&&(i=i.add(Eu(t,e.style)));return i}append(t,n){if(t instanceof e){if(n!==void 0)throw Error(`Style argument must not be provided when appending RichText`);let e=this._text.length;this._text+=t._text,this._addSpan(e,this._text.length,t._style);for(let n of t._spans)this._spans.push(n.move(e));return this}let r=vu(t),i=this._text.length;return this._text+=r,this._addSpan(i,this._text.length,n??``),this}contains(t){let n=t instanceof e?t._text:t;return this._text.includes(n)}at(t){let n=t<0?this._text.length+t:t;return this._text[n]===void 0?new e(``):this.slice(n,n+1)}slice(e,t){let n=this._text,r=n.length,i=e??0,a=t??r,o=i<0?Math.max(0,r+i):Math.min(i,r),s=a<0?Math.max(0,r+a):Math.min(a,r);if(o>=s)return this.blankCopy();let c=n.slice(o,s),l=this.blankCopy(c);for(let e of this._spans){let t=Math.max(e.start,o)-o,n=Math.min(e.end,s)-o;t<n&&l._spans.push(new Ou(t,n,e.style))}return l}_addSpan(e,t,n){let r=Cu(n);Tu(r)||this._spans.push(new Ou(e,t,r))}stylize(e,t,n){let r=this._text.length,i=t===void 0?0:t<0?r+t:t,a=n===void 0?r:n<0?r+n:n;if(i>=a||i>=r||a<=0)return this;let o=Math.max(0,i),s=Math.min(r,a);return this._addSpan(o,s,e),this}highlightRegex(e,t){let n=this._text,r=0,i=e.flags.includes(`g`)?e.flags:e.flags+`g`,a=new RegExp(e.source,i),o;for(;(o=a.exec(n))!==null;){if(o[0].length===0){a.lastIndex++;continue}if(o.groups){let e=0;for(let[t,n]of Object.entries(o.groups))if(n!==void 0){let r=o[0].indexOf(n,e);if(r>=0){let i=o.index+r;this._addSpan(i,i+n.length,t),e=r+n.length}}r++;continue}this._addSpan(o.index,o.index+o[0].length,t??``),r++}return r}highlightWords(e,t,n){let r=n?.caseSensitive!==!1,i=0;for(let n of e){if(n.length===0)continue;let e=n.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),a=r?`g`:`gi`,o=RegExp(`\\b${e}\\b`,a),s;for(;(s=o.exec(this._text))!==null;)this._addSpan(s.index,s.index+s[0].length,t),i++}return i}copy(){let t=new e(this._text,{style:this._style,justify:this._justify,overflow:this._overflow,end:this._end,tabSize:this._tabSize,noWrap:this._noWrap});return t._spans=this._spans.slice(),t}blankCopy(t){return new e(t??``,{style:this._style,justify:this._justify,overflow:this._overflow,end:this._end,tabSize:this._tabSize,noWrap:this._noWrap})}split(e){let t=e??`
|
|
48
48
|
`,n=this._text,r=[],i=0;for(;;){let e=n.indexOf(t,i);if(e===-1){r.push(this.slice(i));break}r.push(this.slice(i,e)),i=e+t.length}return r}divide(e){if(e.length===0)return[this.copy()];let t=[],n=0;for(let r of e)t.push(this.slice(n,r)),n=r;return t.push(this.slice(n)),t}rstrip(){let e=this._text.replace(/\s+$/,``);return e.length<this._text.length&&(this.plain=e),this}pad(e,t){let n=vu(t??` `).repeat(e);return this._spans=this._spans.map(e=>e.move(n.length)),this._text=n+this._text+n,this}expandTabs(){let e=wo(this._text,this._tabSize);return this._spans=this._spans.map(t=>new Ou(e.offsetOf(t.start),e.offsetOf(t.end),t.style)),this._text=e.text,this}padLeft(e,t){let n=vu(t??` `).repeat(e);return this._spans=this._spans.map(e=>e.move(n.length)),this._text=n+this._text,this}padRight(e,t){return this._text+=vu(t??` `).repeat(e),this}setLength(e){return this._text.length<e?this._text+=` `.repeat(e-this._text.length):this._text.length>e&&(this.plain=this._text.slice(0,e)),this}extendStyle(e){let t=this._text.length;return this._text+=` `.repeat(e),this._spans=this._spans.map(n=>n.end===t?n.extend(e):n),this}truncate(e,t){if(this.cellLength<=e)return this;this.expandTabs();let n=t?.mode??`right`,r=so(e),i=vo(vu(t?.marker??`…`),r),a=ao(r-io(i));if(n===`right`)return this._cropRightTo(a),i&&(this._text+=i),this;if(n===`left`)return this._cropLeftTo(a),i&&(this._spans=this._spans.map(e=>e.move(i.length)),this._text=i+this._text),this;let o=ao(Math.floor(a/2)),s=ao(a-o),c=vo(this._text,o).length,l=this._text.length-yo(this._text,s).length,u=this._text.slice(0,c),d=this._text.slice(l),f=c,p=l,m=i.length-(p-f),h=[];for(let e of this._spans)e.end<=f?h.push(e):e.start>=p?h.push(e.move(m)):(e.start<f&&h.push(new Ou(e.start,f,e.style)),e.end>p&&h.push(new Ou(p+m,e.end+m,e.style)));return this._text=u+i+d,this._spans=h,this}_cropRightTo(e){this.plain=vo(this._text,e)}_cropLeftTo(e){let t=this._text.length-yo(this._text,e).length,n=-t;this._spans=this._spans.map(e=>{if(!(e.end<=t))return new Ou(Math.max(0,e.start+n),e.end+n,e.style)}).filter(e=>e!==void 0),this._text=this._text.slice(t)}align(e,t){let n=this.cellLength;if(n>=t)return this;this.expandTabs();let r=t-n;switch(e){case`left`:this.padRight(r);break;case`right`:this.padLeft(r);break;case`center`:{let e=Math.floor(r/2),t=r-e;this.padLeft(e),this.padRight(t);break}}return this}removeSuffix(e){return this._text.endsWith(e)&&(this.plain=this._text.slice(0,-e.length)),this}appendTokens(e){for(let[t,n]of e)this.append(t,n);return this}static assemble(t,n){let r=new e(``,{style:n?.style});for(let n of t)if(typeof n==`string`)r.append(n);else if(n instanceof e)r.append(n);else{let[e,t]=n;r.append(e,t)}return r}static styled(t,n){let r=new e(t);return r.stylize(n),r}static fromFragments(t,n){let r=new e(``,{end:n?.end??``});for(let e of t)r.append(e);return r}*render(e){let t=wo(this._text,this._tabSize),n=this.resolvedStyle(e),{segments:r,covered:i}=this._buildSegments(t,n,e),a=ku(r,i);r.push(G.line());let o=G.splitLines(r),s=so($l(e,this).maxWidth),c=this._overflow??e.overflow??`fold`,l=this._noWrap||(e.noWrap??!1),u=c===`ignore`?so(1/0):s,d=l?so(1/0):u,f=c===`ignore`?void 0:this._justify??e.justify,p=ql(e,`…`,`.`);for(let e=0;e<o.length;e+=1){let t=o[e],r=a[e],i=e<o.length-1,l=su(bu(t),d,{fold:c===`fold`}),m=G.divide(t,l),h=this._justifyLines(m.map((e,t)=>({segments:[...this._fitLine(e,u,c,p)],free:e=>r(t===0?e:l[t-1]+e)})),s,n,f);for(let e=0;e<h.length;e+=1)yield*h[e],(e<h.length-1||i)&&(yield G.line())}this._end&&(yield new G(this._end))}measure(e){let t=wo(this._text,this._tabSize).text.split(`
|
|
49
49
|
`),n=t.reduce((e,t)=>Math.max(e,io(t)),0),r=t.flatMap(au),i=r.length>0?r.reduce((e,t)=>Math.max(e,t),0):n,a=so(e.maxWidth);return{minimum:Math.min(i,a),maximum:Math.min(n,a)}}_buildSegments({text:e,offsetOf:t},n,r){let i=n=>Math.max(0,Math.min(t(n),e.length)),a=new Set;for(let e of this._spans)a.add(i(e.start)),a.add(i(e.end));a.delete(0),a.delete(e.length);let o=[0,...[...a].sort((e,t)=>e-t),e.length],s=new Map(o.map((e,t)=>[e,t]).reverse()),c=o.slice(0,-1).map(()=>n),l=c.map(()=>!1);for(let e of this._spans){let t=i(e.end),n=Eu(r,e.style),a=s.get(i(e.start));for(let e=a;o[e]<t;e++)c[e]=c[e].add(n),l[e]=!0}return{segments:c.map((t,n)=>new G(e.slice(o[n],o[n+1]),t.isNull?void 0:t)),covered:l}}_justifyLines(e,t,n,r){return r===`full`?e.map(({segments:r},i)=>i===e.length-1?r:this._fillLine(r,t,n)):e.map(e=>[...this._justifyLine(e,t,n,r)])}*_justifyLine({segments:e,free:t},n,r,i){let a=r.isNull?void 0:r;switch(i){case`center`:case`right`:{let r=G.adjustLineLength(e,G.getLineLength(e)-xu(e),void 0,!1),o=Math.max(n-G.getLineLength(r),0),s=i===`center`?Math.floor(o/2):o;yield*Au(r,t,s,o-s,a);break}case`left`:yield*Au(e,t,0,Math.max(n-G.getLineLength(e),0),a);break;default:yield*e;break}}_fillLine(e,t,n){let r=bu(e),i=r.split(` `);r.endsWith(` `)&&i.pop();let a=i.length-1,o=Array(a).fill(1),s=i.reduce((e,t)=>e+io(t),0)+a;for(let e=0;s<t&&a>0;e=(e+1)%a)o[a-1-e]+=1,s+=1;let c=[],l=0;for(let e=0;e<i.length;e+=1)l+=io(i[e]),c.push(l),l+=1,e<a&&c.push(l);let u=G.divide(e,c),d=(e,t)=>e.filter(e=>e.hasText).at(t)?.style??n,f=[];for(let e=0;e<i.length;e+=1)if(f.push(...u[e*2]),e<a){let t=d(u[e*2],-1),r=d(u[e*2+2],0),i=t.equals(r)?t:n;f.push(new G(` `.repeat(o[e]),i.isNull?void 0:i))}return f}*_fitLine(e,t,n,r){let i=G.getLineLength(e);if(i-xu(e)<=t){yield*G.adjustLineLength(e,Math.min(i,t),void 0,!1);return}if(n===`ellipsis`&&t>0){yield*G.adjustLineLength(e,t-1,void 0,!1),yield new G(r);return}yield*G.adjustLineLength(e,t,void 0,!1)}};function ku(e,t){let n=[[]];return e.forEach((e,r)=>{e.text.split(`
|
|
50
|
-
`).forEach((e,i)=>{i>0&&n.push([]);let a=n.at(-1);a.push({end:(a.at(-1)?.end??0)+io(e),free:!t[r]})})}),n.map(e=>t=>{let n=0,r=e.length;for(;n<r;){let i=n+r>>1;e[i].end<=t?n=i+1:r=i}return e[n].free})}function*Au(e,t,n,r,i){if(n+r===0)return yield*e;let a=e.filter(e=>e.text!==``),o=e=>` `.repeat(e),s=G.getLineLength(a);if(s===0)return yield new G(o(n+r),i);let c=a.length-1,l=n>0&&a[0].cellLength>0&&t(0),u=r>0&&a[c].cellLength>0&&t(s-1),d=+!!l,f=u?c:c+1;if(d>f){yield new G(o(n)+a[0].text+o(r),i);return}n>0&&(yield new G(o(n)+(l?a[0].text:``),i)),yield*a.slice(d,f),r>0&&(yield new G((u?a[c].text:``)+o(r),i))}const ju=Object.freeze({name:`join`});var Mu=class{fg;bg;constructor(e,t){this.fg=e,this.bg=t}};function Nu(e,t){for(let n=e;n;n=n.inner){if(t.has(n.owner))return{fg:!0,bg:!0};if(n.owner instanceof Mu){let{fg:e,bg:r}=n.owner;return{fg:e!==null&&t.has(e),bg:r!==null&&t.has(r)}}}return{fg:!1,bg:!1}}function Pu(e,t,n,r){let i=e.join(t,n,r);return{render:e=>G.anchorLines([[...Zl(i,e)]],ju)[0]}}function Fu(e){return{render:t=>G.anchorLines([[...Zl(e,t)]],e)[0]}}var Iu=class{items;joiner;constructor(e,t){this.items=e,this.joiner=t}*render(e){let t=this.items;if(t.length===0)return;let n={...e,justify:void 0};yield*Zl(Pu(this.joiner,null,t[0],{index:0}),n);for(let e=0;e<t.length;e++){let r=t[e];yield*Zl(Fu(r),n);let i=e+1<t.length?t[e+1]:null;yield*Zl(Pu(this.joiner,r,i,{index:e+1}),n)}yield G.line()}contents(){return this.items}measure(e){let t=0;for(let n of Zl(this,e))t+=n.cellLength;return{minimum:t,maximum:t}}};const Lu=[`seam`,`divider`,`lead`,`tail`];function*Ru(e){yield e,`mix`in e&&(yield*Ru(e.mix[0]),yield*Ru(e.mix[1]))}const zu=e=>typeof e.glyph==`string`?[e.glyph]:e.glyph.oneOf,Bu=(e,t,n,r)=>{let i=zu(e);return i[Math.floor(parseInt(lu(`${t}:${n}:${r}`),16)/2**32*i.length)]},Vu=e=>io(zu(e)[0]??``),Hu=e=>e.reduce((e,t)=>e+Vu(t),0);function Uu(e,t,n){if(e===`ground`)return n(`mixes ground, whose colour is unknown`);let r=typeof e==`object`&&e?e:{};if((r.edge===`left`||r.edge===`right`)&&(r.part===`bg`||r.part===`fg`))return r.edge===t&&n(`names the ${t} neighbour, which this part is drawn without`),Object.freeze({edge:r.edge,part:r.part});if(typeof r.role==`string`)return Object.freeze({role:r.role});if(Array.isArray(r.mix)&&r.mix.length===3){let[e,i,a]=r.mix;return(typeof a!=`number`||!(a>=0&&a<=1))&&n(`mixes at ${String(a)}, outside 0..1`),Object.freeze({mix:Object.freeze([Uu(e,t,n),Uu(i,t,n),a])})}return n(`has a colour that is not a Paint: ${JSON.stringify(e)}`)}const Wu=(e,t,n)=>e===`ground`?e:Uu(e,t,n),Gu={seam:void 0,divider:void 0,lead:`left`,tail:`right`},Ku={seam:`seam`,divider:`seam`,lead:`caps`,tail:`caps`};function qu(e,t,n,r){let i=e.glyph,a=typeof i==`object`&&i?i.oneOf:void 0;typeof i!=`string`&&!(Array.isArray(a)&&a.every(e=>typeof e==`string`))&&r(`has a glyph that is neither a string nor a oneOf of strings: ${JSON.stringify(i)}`),e.fg===`ground`&&e.bg===`ground`&&r(`has ground on both sides`);let o=zu(e);return o.length===0&&r(`has an empty oneOf`),o.some(t=>io(t)!==Vu(e))&&r(`has oneOf members of different widths`),t===`ascii`&&!o.every(Kl)&&r(`is not ASCII`),Object.freeze({glyph:typeof e.glyph==`string`?e.glyph:Object.freeze({oneOf:Object.freeze([...o])}),fg:Wu(e.fg,Gu[n],r),bg:Wu(e.bg,Gu[n],r)})}function Ju(e,t,n,r){let i=e,a=Ku[n];if(typeof i?.[t]!=`object`||i[t]===null)throw Error(`${a}: has no ${t} form`);let o=i[t][n];if(!Array.isArray(o))throw Error(`${a}: ${t} ${n} is not a list of cells`);return Object.freeze(o.map((e,i)=>{let o=e=>{throw Error(`${a}: ${t} ${n}[${i}] ${e}`)};return typeof e==`object`&&e?r(e,o):o(`is not a cell`)}))}const Yu=(e,t)=>(n,r)=>qu(n,e,t,r),Xu=(e,t)=>(n,r)=>{if(!(`cap`in n))return qu(n,e,t,r);let{cap:i}=n;return Object.keys(n).length!==1&&r(`names a cap and draws cells of its own; a cell is one or the other`),i===`lead`||i===`tail`?Object.freeze({cap:i}):r(`names a cap that is neither lead nor tail: ${JSON.stringify(i)}`)},Zu=e=>[Hu(e.filter(e=>!(`cap`in e))),e.filter(e=>`cap`in e&&e.cap===`lead`).length,e.filter(e=>`cap`in e&&e.cap===`tail`).length];function Qu(e){let t=t=>{let n=Ju(e,t,`seam`,Xu(t,`seam`)),r=e[t].divider===e[t].seam?n:Ju(e,t,`divider`,Xu(t,`divider`)),[i,a]=[Zu(n),Zu(r)];if(i.some((e,t)=>e!==a[t]))throw Error(`seam: ${t} divider is not the width of the seam under every caps`);return Object.freeze({seam:n,divider:r})};return Object.freeze({glyph:t(`glyph`),ascii:t(`ascii`)})}function $u(e){let t=t=>Object.freeze({lead:Ju(e,t,`lead`,Yu(t,`lead`)),tail:Ju(e,t,`tail`,Yu(t,`tail`))});return Object.freeze({glyph:t(`glyph`),ascii:t(`ascii`)})}function ed(e,t){let n=e=>e.flatMap(e=>`cap`in e?t[e.cap]:[e]),r=n(e.seam);return{seam:r,divider:e.divider===e.seam?r:n(e.divider),lead:t.lead,tail:t.tail}}const td=(e,t)=>e.some(e=>[e.fg,e.bg].some(e=>e!==`ground`&&[...Ru(e)].some(e=>`edge`in e&&e.edge===t&&e.part===`bg`)));function nd(e){let t=[...e.seam,...e.divider];return{shape:e,reads:{seam:{left:td(t,`left`),right:td(t,`right`)},lead:td(e.lead,`right`),tail:td(e.tail,`left`)}}}function rd(e){return e!==void 0&&!e.isDefault?e:void 0}function id(e){return e.flattenAlpha(jo)}function ad(e,t){if(e.reverse)return!1;let{color:n,bgcolor:r}=e.drawnColors(t??V.TRUECOLOR);if(n===void 0||r===void 0)return!1;let i=n.fixedValue,a=r.fixedValue;return i!==void 0&&a!==void 0?Vs.fromRgba(i).deltaE(Vs.fromRgba(a))<.04:n.number===void 0?n.name===r.name:n.number===r.number}function od(e,t,n){if(`edge`in e){let n=t[e.edge];if(e.part===`fg`)return n?.color;let r=rd(n?.bgcolor);return r&&id(r)}if(`role`in e)return Jl(n,e.role).color;let[r,i,a]=e.mix,o=od(r,t,n),s=od(i,t,n);return o&&s&&H.blend(o,s,a)}function sd(e,t,n){return e.fg===`ground`?new U({color:e.bg===`ground`?void 0:od(e.bg,t,n),reverse:!0}):new U({color:od(e.fg,t,n),bgcolor:e.bg===`ground`?void 0:od(e.bg,t,n)})}const cd=e=>Lu.flatMap(t=>e[t].flatMap(zu)).join(``);var ld=class{seam;caps;_forms;constructor(e,t){this.seam=Qu(e),this.caps=$u(t),this._forms={glyph:nd(ed(this.seam.glyph,this.caps.glyph)),ascii:nd(ed(this.seam.ascii,this.caps.ascii))}}join(e,t,{index:n}){let r=this._forms;return{*render(i){let{shape:a,reads:o}=ql(i,r.glyph,r.ascii,e=>cd(e.shape)),s={left:e?.edgeStyle(`right`,i),right:t?.edgeStyle(`left`,i)},c=rd(s.left?.bgcolor),l=rd(s.right?.bgcolor),u=e!==null&&(!o.seam.left||c!==void 0),d=t!==null&&(!o.seam.right||l!==void 0),f=d&&(!o.lead||l!==void 0),p=u&&(!o.tail||c!==void 0),m={left:e,right:t},h=e=>e!==`ground`&&`edge`in e?m[e.edge]:null,g=e=>a[e].map((t,r)=>{let a=new Mu(h(t.fg),h(t.bg));return new G(Bu(t,e,n,r),sd(t,s,i).withAnchor({owner:a,row:0,col:0,inner:void 0}))});if(!u||!d){(f||p)&&(yield*g(f?`lead`:`tail`));return}let _=g(`seam`);yield*a.divider!==a.seam&&_.every(e=>e.style!==void 0&&ad(e.style,i.colorSystem))?g(`divider`):_}}}};const ud={edge:`left`,part:`bg`},dd={edge:`right`,part:`bg`},fd={edge:`left`,part:`fg`},pd={mix:[ud,dd,1/2]},md=`ground`,hd={cap:`lead`},gd={cap:`tail`},_d=(e,t)=>({glyph:e,ascii:t}),vd={glyph:``,thin:``,ascii:`>`,asciiThin:`>`},yd={glyph:``,thin:``,ascii:`/`,asciiThin:`/`},bd={glyph:``,thin:``,ascii:`\\`,asciiThin:`\\`},xd={glyph:``,thin:``,ascii:`}`,asciiThin:`}`},Sd={glyph:``,thin:``,ascii:`#`,asciiThin:`>`},Cd={glyph:``,thin:``,ascii:`]`,asciiThin:`>`},wd={glyph:``,thin:``,ascii:`)`,asciiThin:`)`},Td=(e,t)=>({seam:[{glyph:e,fg:ud,bg:dd}],divider:[{glyph:t,fg:fd,bg:ud}]}),Ed=e=>_d(Td(e.glyph,e.thin),Td(e.ascii,e.asciiThin));function Dd(e,t){let n=e=>({mix:[ud,dd,e]}),r={glyph:` `,fg:fd,bg:ud};return{seam:[{glyph:e,fg:ud,bg:n(1/3)},{glyph:e,fg:n(1/3),bg:n(2/3)},{glyph:e,fg:n(2/3),bg:dd}],divider:[r,{glyph:t,fg:fd,bg:ud},r]}}function Od(e){let t=[gd,...e,hd];return{seam:t,divider:t}}function kd(e,t){let n=[{glyph:e,fg:t,bg:pd}];return{seam:n,divider:n}}function Ad(e){return{seam:kd({oneOf:e},ud).seam,divider:[{glyph:{oneOf:e},fg:fd,bg:pd}]}}const jd=[{glyph:` | `,fg:{role:`strip.separator`},bg:md}],Md={seam:jd,divider:jd},Nd={glyph:` `,fg:fd,bg:md},Pd=e=>({glyph:e,fg:{role:`strip.rail`},bg:md}),Fd=Object.freeze({powerline:Qu(Ed(vd)),prism:Qu(_d(Dd(vd.glyph,vd.thin),Dd(vd.ascii,vd.asciiThin))),slant:Qu(Ed(yd)),backslant:Qu(Ed(bd)),flame:Qu(Ed(xd)),pixel:Qu(Ed(Sd)),ice:Qu(Ed(Cd)),bubble:Qu(Ed(wd)),capsule:Qu(_d(Od([Nd]),Od([Nd]))),wrapper:Qu(_d(Od([]),Od([]))),metro:Qu(_d(Od([Pd(`──`)]),Od([Pd(`--`)]))),stitch:Qu(_d(kd(`┊`,fd),kd(`:`,fd))),torn:Qu(_d(Ad([`▚▞`,`▞▚`,`▘▗`,`▝▖`,`▖▝`,`▗▘`]),Ad([`/\\`,`\\/`]))),plain:Qu(_d(Md,Md))}),Id=e=>_d({lead:[{glyph:e.glyph,fg:md,bg:dd}],tail:[{glyph:e.glyph,fg:ud,bg:md}]},{lead:[],tail:[{glyph:e.ascii,fg:ud,bg:md}]}),Ld=(e,t)=>({lead:[{glyph:e,fg:dd,bg:md}],tail:[{glyph:t,fg:ud,bg:md}]}),Rd={lead:[],tail:[]},zd=Object.freeze({powerline:$u(Id(vd)),slant:$u(Id(yd)),backslant:$u(Id(bd)),flame:$u(Id(xd)),pixel:$u(Id(Sd)),ice:$u(Id(Cd)),bubble:$u(Id(wd)),capsule:$u(_d(Ld(``,``),Ld(`(`,`)`))),wrapper:$u(_d(Ld(``,``),Ld(`<`,`>`))),flat:$u(_d(Rd,Rd))}),Bd=Object.freeze({powerline:new ld(Fd.powerline,zd.powerline),prism:new ld(Fd.prism,zd.powerline),slant:new ld(Fd.slant,zd.slant),backslant:new ld(Fd.backslant,zd.backslant),flame:new ld(Fd.flame,zd.flame),pixel:new ld(Fd.pixel,zd.pixel),ice:new ld(Fd.ice,zd.ice),bubble:new ld(Fd.bubble,zd.bubble),capsule:new ld(Fd.capsule,zd.capsule),wrapper:new ld(Fd.wrapper,zd.wrapper),metro:new ld(Fd.metro,zd.capsule),stitch:new ld(Fd.stitch,zd.flat),torn:new ld(Fd.torn,zd.flat),plain:new ld(Fd.plain,zd.flat)});function Vd(e,t){if(e.isControl)return``;let{text:n,style:r}=e;if(n.length===0||r===void 0)return n;let i=t.colorSystem===null?``:r.toSgrCodes(t.colorSystem),a=i.length>0?`\x1b[${i}m${n}\x1b[0m`:n,o=t.hyperlinks?r.link:void 0;return o===void 0?a:`${pu(o)}${a}]8;;\\`}function Hd(e,t){let n=[];for(let r of e)n.push(Vd(r,t));return n.join(``)}function Ud(e,t){let n=t?.width??80,r={};t?.env!==void 0&&(r.env=t.env),t?.isTTY!==void 0&&(r.isTTY=t.isTTY);let i=t?.colorSystem,a=Go(i===void 0?V.TRUECOLOR:i,r),o={colorSystem:t?.noColor?null:a.colorSystem,hyperlinks:t?.hyperlinks??a.hyperlinks};return Hd(Zl(e,{maxWidth:n,isTerminal:!1,asciiOnly:t?.asciiOnly??!1,theme:t?.theme,onStyleError:t?.onStyleError,highlight:t?.highlight,highlighter:t?.highlighter,colorSystem:o.colorSystem}),o)}const Wd=/\r|\x1b\[([0-9;:]*)m|\x1b\[([012]?)K|\x1b\[[0-?]*[ -/]*[@-~]|\x1b[\]P_^X][\s\S]*?(?:\x07|\x1b\\|\x9c|$)|\x1b[ -/]*[0-~]/g;function*Gd(e){let t=0;for(let n of e.matchAll(Wd))n.index>t&&(yield{kind:`text`,text:e.slice(t,n.index)}),n[0]===`\r`&&(yield{kind:`return`}),n[1]!==void 0&&(yield{kind:`sgr`,params:n[1]}),n[2]!==void 0&&(yield{kind:`erase`,mode:n[2]||`0`}),t=n.index+n[0].length;t<e.length&&(yield{kind:`text`,text:e.slice(t)})}function*Kd(e){let t=0;for(let n of gu(e))yield*Gd(e.slice(t,n.index)),yield{kind:`link`,uri:n.uri},t=n.index+n.length;yield*Gd(e.slice(t))}function qd(e){let t=new U(e);return e=>e.add(t)}function Jd(e){let t=e.next();return t.done?void 0:t.value}function Yd(e){let t=Jd(e);if(t===5){let t=Jd(e);return t===void 0?void 0:H.fromAnsi(t)}if(t===2){let[t,n,r]=[Jd(e),Jd(e),Jd(e)];return r===void 0?void 0:H.fromRgb(t,n,r)}}const Xd=new Map([[0,()=>W],...Tl.map(e=>[El[e],qd({[e]:!0})]),[22,qd({bold:!1,dim:!1})],[23,qd({italic:!1})],[24,qd({underline:!1,underline2:!1})],[25,qd({blink:!1,blink2:!1})],[27,qd({reverse:!1})],[28,qd({conceal:!1})],[29,qd({strike:!1})],[38,(e,t)=>e.add(new U({color:Yd(t)}))],[39,qd({color:H.default()})],[48,(e,t)=>e.add(new U({bgcolor:Yd(t)}))],[49,qd({bgcolor:H.default()})],[58,(e,t)=>(Yd(t),e)],[54,qd({frame:!1,encircle:!1})],[55,qd({overline:!1})],...Array.from({length:8},(e,t)=>[[30+t,qd({color:H.fromAnsi(t)})],[40+t,qd({bgcolor:H.fromAnsi(t)})],[90+t,qd({color:H.fromAnsi(t+8)})],[100+t,qd({bgcolor:H.fromAnsi(t+8)})]]).flat()]),Zd=e=>e;function Qd(e,t){let n=t.split(`;`).filter(e=>/^\d*$/.test(e)).map(e=>Math.min(255,Number(e))).values(),r=e;for(let e of n)r=(Xd.get(e)??Zd)(r,n);return r}const $d=[` `,W];function ef(e,t,n){n!==`0`&&e.fill($d,0,Math.min(t+1,e.length)),n!==`1`&&(e.length=Math.min(t,e.length))}var tf=class{sgr=W;link=void 0;decode(e){return(e.match(/[^\n]*\n|[^\n]+/g)??[]).map(e=>this.decodeLine(e.replace(/\r?\n$/,``)))}decodeLine(e){let t=[],n=0;for(let r of Kd(e))switch(r.kind){case`text`:{let e=this.sgr.withLink(this.link);for(let i of r.text)t[n++]=[i,e];break}case`return`:n=0;break;case`erase`:ef(t,n,r.mode);break;case`sgr`:this.sgr=Qd(this.sgr,r.params);break;case`link`:this.link=r.uri===``?void 0:r.uri;break}let r=[];for(let[e,n]of t){let t=r.at(-1);t?.[1].equals(n)?t[0]+=e:r.push([e,n])}return K.assemble(r)}};function nf(e){return e.end=``,e.plain=e.plain.replaceAll(`
|
|
51
|
-
`,` `),e.expandTabs()}var
|
|
50
|
+
`).forEach((e,i)=>{i>0&&n.push([]);let a=n.at(-1);a.push({end:(a.at(-1)?.end??0)+io(e),free:!t[r]})})}),n.map(e=>t=>{let n=0,r=e.length;for(;n<r;){let i=n+r>>1;e[i].end<=t?n=i+1:r=i}return e[n].free})}function*Au(e,t,n,r,i){if(n+r===0)return yield*e;let a=e.filter(e=>e.text!==``),o=e=>` `.repeat(e),s=G.getLineLength(a);if(s===0)return yield new G(o(n+r),i);let c=a.length-1,l=n>0&&a[0].cellLength>0&&t(0),u=r>0&&a[c].cellLength>0&&t(s-1),d=+!!l,f=u?c:c+1;if(d>f){yield new G(o(n)+a[0].text+o(r),i);return}n>0&&(yield new G(o(n)+(l?a[0].text:``),i)),yield*a.slice(d,f),r>0&&(yield new G((u?a[c].text:``)+o(r),i))}const ju=Object.freeze({name:`join`});var Mu=class{fg;bg;constructor(e,t){this.fg=e,this.bg=t}};function Nu(e,t){for(let n=e;n;n=n.inner){if(t.has(n.owner))return{fg:!0,bg:!0};if(n.owner instanceof Mu){let{fg:e,bg:r}=n.owner;return{fg:e!==null&&t.has(e),bg:r!==null&&t.has(r)}}}return{fg:!1,bg:!1}}function Pu(e,t,n,r){let i=e.join(t,n,r);return{render:e=>G.anchorLines([[...Zl(i,e)]],ju)[0]}}function Fu(e){return{render:t=>G.anchorLines([[...Zl(e,t)]],e)[0]}}var Iu=class{items;joiner;constructor(e,t){this.items=e,this.joiner=t}*render(e){let t=this.items;if(t.length===0)return;let n={...e,justify:void 0};yield*Zl(Pu(this.joiner,null,t[0],{index:0}),n);for(let e=0;e<t.length;e++){let r=t[e];yield*Zl(Fu(r),n);let i=e+1<t.length?t[e+1]:null;yield*Zl(Pu(this.joiner,r,i,{index:e+1}),n)}yield G.line()}contents(){return this.items}measure(e){let t=0;for(let n of Zl(this,e))t+=n.cellLength;return{minimum:t,maximum:t}}};const Lu=[`seam`,`divider`,`lead`,`tail`];function*Ru(e){yield e,`mix`in e&&(yield*Ru(e.mix[0]),yield*Ru(e.mix[1]))}const zu=e=>typeof e.glyph==`string`?[e.glyph]:e.glyph.oneOf,Bu=(e,t,n,r)=>{let i=zu(e);return i[Math.floor(parseInt(lu(`${t}:${n}:${r}`),16)/2**32*i.length)]},Vu=e=>io(zu(e)[0]??``),Hu=e=>e.reduce((e,t)=>e+Vu(t),0);function Uu(e,t,n){if(e===`ground`)return n(`mixes ground, whose colour is unknown`);let r=typeof e==`object`&&e?e:{};if((r.edge===`left`||r.edge===`right`)&&(r.part===`bg`||r.part===`fg`))return r.edge===t&&n(`names the ${t} neighbour, which this part is drawn without`),Object.freeze({edge:r.edge,part:r.part});if(typeof r.role==`string`)return Object.freeze({role:r.role});if(Array.isArray(r.mix)&&r.mix.length===3){let[e,i,a]=r.mix;return(typeof a!=`number`||!(a>=0&&a<=1))&&n(`mixes at ${String(a)}, outside 0..1`),Object.freeze({mix:Object.freeze([Uu(e,t,n),Uu(i,t,n),a])})}return n(`has a colour that is not a Paint: ${JSON.stringify(e)}`)}const Wu=(e,t,n)=>e===`ground`?e:Uu(e,t,n),Gu={seam:void 0,divider:void 0,lead:`left`,tail:`right`},Ku={seam:`seam`,divider:`seam`,lead:`caps`,tail:`caps`};function qu(e,t,n,r){let i=e.glyph,a=typeof i==`object`&&i?i.oneOf:void 0;typeof i!=`string`&&!(Array.isArray(a)&&a.every(e=>typeof e==`string`))&&r(`has a glyph that is neither a string nor a oneOf of strings: ${JSON.stringify(i)}`),e.fg===`ground`&&e.bg===`ground`&&r(`has ground on both sides`);let o=zu(e);return o.length===0&&r(`has an empty oneOf`),o.some(t=>io(t)!==Vu(e))&&r(`has oneOf members of different widths`),t===`ascii`&&!o.every(Kl)&&r(`is not ASCII`),Object.freeze({glyph:typeof e.glyph==`string`?e.glyph:Object.freeze({oneOf:Object.freeze([...o])}),fg:Wu(e.fg,Gu[n],r),bg:Wu(e.bg,Gu[n],r)})}function Ju(e,t,n,r){let i=e,a=Ku[n];if(typeof i?.[t]!=`object`||i[t]===null)throw Error(`${a}: has no ${t} form`);let o=i[t][n];if(!Array.isArray(o))throw Error(`${a}: ${t} ${n} is not a list of cells`);return Object.freeze(o.map((e,i)=>{let o=e=>{throw Error(`${a}: ${t} ${n}[${i}] ${e}`)};return typeof e==`object`&&e?r(e,o):o(`is not a cell`)}))}const Yu=(e,t)=>(n,r)=>qu(n,e,t,r),Xu=(e,t)=>(n,r)=>{if(!(`cap`in n))return qu(n,e,t,r);let{cap:i}=n;return Object.keys(n).length!==1&&r(`names a cap and draws cells of its own; a cell is one or the other`),i===`lead`||i===`tail`?Object.freeze({cap:i}):r(`names a cap that is neither lead nor tail: ${JSON.stringify(i)}`)},Zu=e=>[Hu(e.filter(e=>!(`cap`in e))),e.filter(e=>`cap`in e&&e.cap===`lead`).length,e.filter(e=>`cap`in e&&e.cap===`tail`).length];function Qu(e){let t=t=>{let n=Ju(e,t,`seam`,Xu(t,`seam`)),r=e[t].divider===e[t].seam?n:Ju(e,t,`divider`,Xu(t,`divider`)),[i,a]=[Zu(n),Zu(r)];if(i.some((e,t)=>e!==a[t]))throw Error(`seam: ${t} divider is not the width of the seam under every caps`);return Object.freeze({seam:n,divider:r})};return Object.freeze({glyph:t(`glyph`),ascii:t(`ascii`)})}function $u(e){let t=t=>Object.freeze({lead:Ju(e,t,`lead`,Yu(t,`lead`)),tail:Ju(e,t,`tail`,Yu(t,`tail`))});return Object.freeze({glyph:t(`glyph`),ascii:t(`ascii`)})}function ed(e,t){let n=e=>e.flatMap(e=>`cap`in e?t[e.cap]:[e]),r=n(e.seam);return{seam:r,divider:e.divider===e.seam?r:n(e.divider),lead:t.lead,tail:t.tail}}const td=(e,t)=>e.some(e=>[e.fg,e.bg].some(e=>e!==`ground`&&[...Ru(e)].some(e=>`edge`in e&&e.edge===t&&e.part===`bg`)));function nd(e){let t=[...e.seam,...e.divider];return{shape:e,reads:{seam:{left:td(t,`left`),right:td(t,`right`)},lead:td(e.lead,`right`),tail:td(e.tail,`left`)}}}function rd(e){return e!==void 0&&!e.isDefault?e:void 0}function id(e){return e.flattenAlpha(jo)}function ad(e,t){if(e.reverse)return!1;let{color:n,bgcolor:r}=e.drawnColors(t??V.TRUECOLOR);if(n===void 0||r===void 0)return!1;let i=n.fixedValue,a=r.fixedValue;return i!==void 0&&a!==void 0?Vs.fromRgba(i).deltaE(Vs.fromRgba(a))<.04:n.number===void 0?n.name===r.name:n.number===r.number}function od(e,t,n){if(`edge`in e){let n=t[e.edge];if(e.part===`fg`)return n?.color;let r=rd(n?.bgcolor);return r&&id(r)}if(`role`in e)return Jl(n,e.role).color;let[r,i,a]=e.mix,o=od(r,t,n),s=od(i,t,n);return o&&s&&H.blend(o,s,a)}function sd(e,t,n){return e.fg===`ground`?new U({color:e.bg===`ground`?void 0:od(e.bg,t,n),reverse:!0}):new U({color:od(e.fg,t,n),bgcolor:e.bg===`ground`?void 0:od(e.bg,t,n)})}const cd=e=>Lu.flatMap(t=>e[t].flatMap(zu)).join(``);var ld=class{seam;caps;_forms;constructor(e,t){this.seam=Qu(e),this.caps=$u(t),this._forms={glyph:nd(ed(this.seam.glyph,this.caps.glyph)),ascii:nd(ed(this.seam.ascii,this.caps.ascii))}}join(e,t,{index:n}){let r=this._forms;return{*render(i){let{shape:a,reads:o}=ql(i,r.glyph,r.ascii,e=>cd(e.shape)),s={left:e?.edgeStyle(`right`,i),right:t?.edgeStyle(`left`,i)},c=rd(s.left?.bgcolor),l=rd(s.right?.bgcolor),u=e!==null&&(!o.seam.left||c!==void 0),d=t!==null&&(!o.seam.right||l!==void 0),f=d&&(!o.lead||l!==void 0),p=u&&(!o.tail||c!==void 0),m={left:e,right:t},h=e=>e!==`ground`&&`edge`in e?m[e.edge]:null,g=e=>a[e].map((t,r)=>{let a=new Mu(h(t.fg),h(t.bg));return new G(Bu(t,e,n,r),sd(t,s,i).withAnchor({owner:a,row:0,col:0,inner:void 0}))});if(!u||!d){(f||p)&&(yield*g(f?`lead`:`tail`));return}let _=g(`seam`);yield*a.divider!==a.seam&&_.every(e=>e.style!==void 0&&ad(e.style,i.colorSystem))?g(`divider`):_}}}};const ud={edge:`left`,part:`bg`},dd={edge:`right`,part:`bg`},fd={edge:`left`,part:`fg`},pd={mix:[ud,dd,1/2]},md=`ground`,hd={cap:`lead`},gd={cap:`tail`},_d=(e,t)=>({glyph:e,ascii:t}),vd={glyph:``,thin:``,ascii:`>`,asciiThin:`>`},yd={glyph:``,thin:``,ascii:`/`,asciiThin:`/`},bd={glyph:``,thin:``,ascii:`\\`,asciiThin:`\\`},xd={glyph:``,thin:``,ascii:`}`,asciiThin:`}`},Sd={glyph:``,thin:``,ascii:`#`,asciiThin:`>`},Cd={glyph:``,thin:``,ascii:`]`,asciiThin:`>`},wd={glyph:``,thin:``,ascii:`)`,asciiThin:`)`},Td=(e,t)=>({seam:[{glyph:e,fg:ud,bg:dd}],divider:[{glyph:t,fg:fd,bg:ud}]}),Ed=e=>_d(Td(e.glyph,e.thin),Td(e.ascii,e.asciiThin));function Dd(e,t){let n=e=>({mix:[ud,dd,e]}),r={glyph:` `,fg:fd,bg:ud};return{seam:[{glyph:e,fg:ud,bg:n(1/3)},{glyph:e,fg:n(1/3),bg:n(2/3)},{glyph:e,fg:n(2/3),bg:dd}],divider:[r,{glyph:t,fg:fd,bg:ud},r]}}function Od(e){let t=[gd,...e,hd];return{seam:t,divider:t}}function kd(e,t){let n=[{glyph:e,fg:t,bg:pd}];return{seam:n,divider:n}}function Ad(e){return{seam:kd({oneOf:e},ud).seam,divider:[{glyph:{oneOf:e},fg:fd,bg:pd}]}}const jd=[{glyph:` | `,fg:{role:`strip.separator`},bg:md}],Md={seam:jd,divider:jd},Nd={glyph:` `,fg:fd,bg:md},Pd=e=>({glyph:e,fg:{role:`strip.rail`},bg:md}),Fd=Object.freeze({powerline:Qu(Ed(vd)),prism:Qu(_d(Dd(vd.glyph,vd.thin),Dd(vd.ascii,vd.asciiThin))),slant:Qu(Ed(yd)),backslant:Qu(Ed(bd)),flame:Qu(Ed(xd)),pixel:Qu(Ed(Sd)),ice:Qu(Ed(Cd)),bubble:Qu(Ed(wd)),capsule:Qu(_d(Od([Nd]),Od([Nd]))),wrapper:Qu(_d(Od([]),Od([]))),metro:Qu(_d(Od([Pd(`──`)]),Od([Pd(`--`)]))),stitch:Qu(_d(kd(`┊`,fd),kd(`:`,fd))),torn:Qu(_d(Ad([`▚▞`,`▞▚`,`▘▗`,`▝▖`,`▖▝`,`▗▘`]),Ad([`/\\`,`\\/`]))),plain:Qu(_d(Md,Md))}),Id=e=>_d({lead:[{glyph:e.glyph,fg:md,bg:dd}],tail:[{glyph:e.glyph,fg:ud,bg:md}]},{lead:[],tail:[{glyph:e.ascii,fg:ud,bg:md}]}),Ld=(e,t)=>({lead:[{glyph:e,fg:dd,bg:md}],tail:[{glyph:t,fg:ud,bg:md}]}),Rd={lead:[],tail:[]},zd=Object.freeze({powerline:$u(Id(vd)),slant:$u(Id(yd)),backslant:$u(Id(bd)),flame:$u(Id(xd)),pixel:$u(Id(Sd)),ice:$u(Id(Cd)),bubble:$u(Id(wd)),capsule:$u(_d(Ld(``,``),Ld(`(`,`)`))),wrapper:$u(_d(Ld(``,``),Ld(`<`,`>`))),flat:$u(_d(Rd,Rd))}),Bd=Object.freeze({powerline:new ld(Fd.powerline,zd.powerline),prism:new ld(Fd.prism,zd.powerline),slant:new ld(Fd.slant,zd.slant),backslant:new ld(Fd.backslant,zd.backslant),flame:new ld(Fd.flame,zd.flame),pixel:new ld(Fd.pixel,zd.pixel),ice:new ld(Fd.ice,zd.ice),bubble:new ld(Fd.bubble,zd.bubble),capsule:new ld(Fd.capsule,zd.capsule),wrapper:new ld(Fd.wrapper,zd.wrapper),metro:new ld(Fd.metro,zd.capsule),stitch:new ld(Fd.stitch,zd.flat),torn:new ld(Fd.torn,zd.flat),plain:new ld(Fd.plain,zd.flat)});function Vd(e,t){if(e.isControl)return``;let{text:n,style:r}=e;if(n.length===0||r===void 0)return n;let i=t.colorSystem===null?``:r.toSgrCodes(t.colorSystem),a=i.length>0?`\x1b[${i}m${n}\x1b[0m`:n,o=t.hyperlinks?r.link:void 0;return o===void 0?a:`${pu(o)}${a}]8;;\\`}function Hd(e,t){let n=[];for(let r of e)n.push(Vd(r,t));return n.join(``)}const Ud=/\r|\x1b\[([0-9;:]*)m|\x1b\[([012]?)K|\x1b\[[0-?]*[ -/]*[@-~]|\x1b[\]P_^X][\s\S]*?(?:\x07|\x1b\\|\x9c|$)|\x1b[ -/]*[0-~]/g;function*Wd(e){let t=0;for(let n of e.matchAll(Ud))n.index>t&&(yield{kind:`text`,text:e.slice(t,n.index)}),n[0]===`\r`&&(yield{kind:`return`}),n[1]!==void 0&&(yield{kind:`sgr`,params:n[1]}),n[2]!==void 0&&(yield{kind:`erase`,mode:n[2]||`0`}),t=n.index+n[0].length;t<e.length&&(yield{kind:`text`,text:e.slice(t)})}function*Gd(e){let t=0;for(let n of gu(e))yield*Wd(e.slice(t,n.index)),yield{kind:`link`,uri:n.uri},t=n.index+n.length;yield*Wd(e.slice(t))}function Kd(e){let t=new U(e);return e=>e.add(t)}function qd(e){let t=e.next();return t.done?void 0:t.value}function Jd(e){let t=qd(e);if(t===5){let t=qd(e);return t===void 0?void 0:H.fromAnsi(t)}if(t===2){let[t,n,r]=[qd(e),qd(e),qd(e)];return r===void 0?void 0:H.fromRgb(t,n,r)}}const Yd=new Map([[0,()=>W],...Tl.map(e=>[El[e],Kd({[e]:!0})]),[22,Kd({bold:!1,dim:!1})],[23,Kd({italic:!1})],[24,Kd({underline:!1,underline2:!1})],[25,Kd({blink:!1,blink2:!1})],[27,Kd({reverse:!1})],[28,Kd({conceal:!1})],[29,Kd({strike:!1})],[38,(e,t)=>e.add(new U({color:Jd(t)}))],[39,Kd({color:H.default()})],[48,(e,t)=>e.add(new U({bgcolor:Jd(t)}))],[49,Kd({bgcolor:H.default()})],[58,(e,t)=>(Jd(t),e)],[54,Kd({frame:!1,encircle:!1})],[55,Kd({overline:!1})],...Array.from({length:8},(e,t)=>[[30+t,Kd({color:H.fromAnsi(t)})],[40+t,Kd({bgcolor:H.fromAnsi(t)})],[90+t,Kd({color:H.fromAnsi(t+8)})],[100+t,Kd({bgcolor:H.fromAnsi(t+8)})]]).flat()]),Xd=e=>e;function Zd(e,t){let n=t.split(`;`).filter(e=>/^\d*$/.test(e)).map(e=>Math.min(255,Number(e))).values(),r=e;for(let e of n)r=(Yd.get(e)??Xd)(r,n);return r}const Qd=[` `,W];function $d(e,t,n){n!==`0`&&e.fill(Qd,0,Math.min(t+1,e.length)),n!==`1`&&(e.length=Math.min(t,e.length))}var ef=class{sgr=W;link=void 0;decode(e){return(e.match(/[^\n]*\n|[^\n]+/g)??[]).map(e=>this.decodeLine(e.replace(/\r?\n$/,``)))}decodeLine(e){let t=[],n=0;for(let r of Gd(e))switch(r.kind){case`text`:{let e=this.sgr.withLink(this.link);for(let i of r.text)t[n++]=[i,e];break}case`return`:n=0;break;case`erase`:$d(t,n,r.mode);break;case`sgr`:this.sgr=Zd(this.sgr,r.params);break;case`link`:this.link=r.uri===``?void 0:r.uri;break}let r=[];for(let[e,n]of t){let t=r.at(-1);t?.[1].equals(n)?t[0]+=e:r.push([e,n])}return K.assemble(r)}};function tf(e){return e.end=``,e.plain=e.plain.replaceAll(`
|
|
51
|
+
`,` `),e.expandTabs()}var nf=class{renderable;effect;t;key;theme;constructor(e,t,n){if(this.renderable=e,this.effect=t,!Number.isFinite(n.t))throw RangeError(`Effected needs a finite t, got ${n.t}`);this.t=n.t,this.key=n.key,this.theme=n.theme}render(e){let t=Zl(this.renderable,e);return e.colorSystem===null?t:this._moved(t,e)}*contents(){yield this.renderable}*_moved(e,t){let n=t.colorSystem??V.TRUECOLOR,r=af(e,n,this.theme),i=of(r),a=this.effect(cf(r,()=>i,n,this.theme));yield*G.applyStyle(this._recolored(i,a.at(this.t),n),new U({nextChange:a.nextChange(this.t)}))}*_recolored(e,t,n){for(let{segment:r,look:i,glyphs:a}of e){if(i===void 0){yield r;continue}let{style:e,wire:o,slots:s,pair:c}=i,{terminal:l}=c,u={fg:c.fg,bg:c.bg},d=[];for(let{glyph:e,cell:r}of a){let i=r===void 0?s:uf(t(u,{...r,seed:this.seed(r.row,r.col),terminal:l,reverse:c.reverse}),c.reverse),a=d[d.length-1],f=a!==void 0&&hf(a.colors,i)?a.drawn:this.respec(o,s,i,n);a!==void 0&&ff(a.drawn,f)?(a.text+=e,a.cells+=io(e),a.colors=i):d.push({text:e,cells:io(e),colors:i,drawn:f})}if(d.every(e=>ff(e.drawn,o))){yield r;continue}let f=0;for(let t of d){let n=e.shiftedBy(f),r=ff(t.drawn,o)?n:n.add(U.fromColor(t.drawn.color,t.drawn.bgcolor));yield new G(t.text,r),f+=t.cells}}}measure(e){return nu.get(e,this.renderable)}static shows(e,t,n,r){let i=uf(e,e.reverse),a=df(i,uf(t,e.reverse),n,r);return uf({fg:a.fg?.getTruecolor(r,!0)??i.fg,bg:a.bg?.getTruecolor(r,!1)??i.bg},e.reverse)}respec(e,t,n,r){let i=df(t,n,r,this.theme);return{color:i.fg??e.color,bgcolor:i.bg??e.bgcolor}}seed(e,t){return Number.parseInt(lu(`${this.key}:${e}:${t}`),16)/4294967296}};const rf=H.default();function af(e,t,n){return[...e].map(e=>{if(e.isControl)return{segment:e,look:void 0};let r=e.style??U.null(),i=r.drawnColors(t),a={fg:(i.color??rf).getTruecolor(n,!0),bg:(i.bgcolor??rf).getTruecolor(n,!1)},o=r.reverse===!0,s=uf({fg:i.color?.isDefault??!0,bg:i.bgcolor?.isDefault??!0},o);return{segment:e,look:{style:r,wire:i,slots:a,pair:{...uf(a,o),terminal:s,reverse:o}}}})}function of(e){let t=0,n=0;return e.map(({segment:e,look:r})=>{if(r===void 0)return{segment:e,look:r,glyphs:[]};let i=r.style.anchor,a=0;return{segment:e,look:r,glyphs:[...go(e.text)].map(e=>{let r=e===`
|
|
52
52
|
`?void 0:{row:t,col:n,anchor:i&&Cl(i,a)};return[t,n]=e===`
|
|
53
|
-
`?[t+1,0]:[t,n+io(e)],a+=io(e),{glyph:e,cell:r}})}})}function cf(e){return[e.underline,e.underline2,e.strike,e.overline,e.frame,e.encircle].some(e=>e===!0)}function lf(e,t,n,r){let i=r.backgroundColor.hex,a,o=()=>t().flatMap(({look:e,glyphs:t})=>{if(e===void 0)return[];let n=e.pair.bg.hex!==i||cf(e.style);return t.flatMap(({glyph:e,cell:t})=>t!==void 0&&(e.trim()!==``||n)?[t]:[])}),s=e.flatMap(({segment:e,look:t})=>t!==void 0&&e.text.trim()!==``&&!wl(t.style.anchor,ju)?[t.pair]:[]),c=[...new Map(s.map(e=>[`${e.fg.hex}/${e.bg.hex}/${e.terminal.fg}/${e.terminal.bg}/${e.reverse}`,e])).values()],l=e=>c.flatMap(t=>t.terminal[e]?[]:[t[e].hex]);return{cells:()=>a??=o(),pairs:c,colors:new Set([...l(`fg`),...l(`bg`)]),fills:new Set(l(`bg`)),depth:n,theme:r}}function uf(e,...t){let n=new Set(t),r=e=>Nu(e.anchor,n),i=({fg:e,bg:t})=>e||t,a=e=>({...e,cells:()=>e.cells().filter(e=>i(r(e)))});return t=>ml.map(e(a(t)),e=>(t,n)=>{let a=r(n);if(!i(a))return t;let o=e(t,n);return{fg:a.fg?o.fg:t.fg,bg:a.bg?o.bg:t.bg}})}function df(e,t){return t?{fg:e.bg,bg:e.fg}:e}function ff(e,t,n,r){let i=t.bg.compositeOver(jo),a=t.fg.compositeOver(i);return{fg:H.matchMove(e.fg,a,n,r,!0),bg:H.matchMove(e.bg,i,n,r,!1)}}function pf(e,t){return mf(e.color,t.color,!0)&&mf(e.bgcolor,t.bgcolor,!1)}function mf(e,t,n){return e===t||hf(e,n)===hf(t,n)}function hf(e,t){return e?.getAnsiCodes(t).join(`;`)??``}function gf(e,t){return _f(e.fg,t.fg)&&_f(e.bg,t.bg)}function _f(e,t){return e.red===t.red&&e.green===t.green&&e.blue===t.blue&&e.alpha===t.alpha}const vf=(()=>{let e=[151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,88,237,149,56,87,174,20,125,136,171,168,68,175,74,165,71,134,139,48,27,166,77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,102,143,54,65,25,63,161,1,216,80,73,209,76,132,187,208,89,18,169,200,196,135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226,250,124,123,5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,223,183,170,213,119,248,152,2,44,154,163,70,221,153,101,155,167,43,172,9,129,22,39,253,19,98,108,110,79,113,224,232,178,185,112,104,218,246,97,228,251,34,242,193,238,210,144,12,191,179,162,241,81,51,145,235,249,14,239,107,49,192,214,31,181,199,106,157,184,84,204,176,115,121,50,45,127,4,150,254,138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180];return[...e,...e]})(),yf=e=>e*e*e*(e*(e*6-15)+10),bf=(e,t,n)=>e+n*(t-e);function xf(e,t,n,r){let i=e&15,a=i<8?t:n,o=i<4?n:i===12||i===14?t:r;return(i&1?-a:a)+(i&2?-o:o)}function Sf(e,t,n){let r=Math.floor(e),i=Math.floor(t),a=Math.floor(n),o=r&255,s=i&255,c=a&255;e-=r,t-=i,n-=a;let l=yf(e),u=yf(t),d=yf(n),f=vf[o]+s,p=vf[f]+c,m=vf[f+1]+c,h=vf[o+1]+s,g=vf[h]+c,_=vf[h+1]+c;return bf(bf(bf(xf(vf[p],e,t,n),xf(vf[g],e-1,t,n),l),bf(xf(vf[m],e,t-1,n),xf(vf[_],e-1,t-1,n),l),u),bf(bf(xf(vf[p+1],e,t,n-1),xf(vf[g+1],e-1,t,n-1),l),bf(xf(vf[m+1],e,t-1,n-1),xf(vf[_+1],e-1,t-1,n-1),l),u),d)}function Cf(e,t,n,r){let i=0,a=1,o=0;for(let s=0;s<r;s++){let r=2**s;i+=a*Sf(e*r,t*r,n*r),o+=a,a/=2}return i/o}function wf(e,t){let n=Math.sin(e*12.9898+t*78.233)*43758.5453;return n-Math.floor(n)}function Tf(e,t,n){let r=Math.min(1,Math.max(0,(n-e)/(t-e)));return r*r*(3-2*r)}const Ef=Array.from({length:48},(e,t)=>(t+1)/48);function Df(e,t){return Math.min(No(e.fg,e.bg),4.5)-(t===V.TRUECOLOR?.01:0)}const Of=[`fg`,`bg`];function kf({pairs:e,depth:t,theme:n},r,i){let a=(e,t)=>e.terminal[t]?void 0:e[t].hex,o=new Map(e.flatMap(e=>Of.flatMap(t=>{let n=a(e,t);return n===void 0?[]:[[n,e[t]]]}))),s=new Map([...r].filter(e=>!o.has(e)).map(e=>[e,1])),c=e=>Vs.fromRgba(o.get(e)).l;for(let l of[...r].filter(e=>o.has(e)).sort((e,t)=>c(t)-c(e))){let r=e.flatMap(e=>{let t=Of.find(t=>a(e,t)===l);if(t===void 0)return[];let n=a(e,t===`fg`?`bg`:`fg`);return[[e,t,n===void 0?0:s.get(n)??0]]}),o=e=>r.every(([r,a,o])=>{let s=Df(r,t),c=(t,n)=>If(i,r[t],(t===a?e:o)*n);return Ef.every(e=>{let i=rf.shows(r,{fg:c(`fg`,e),bg:c(`bg`,e)},t,n);return No(i.fg,i.bg)>=s})}),[c,u]=o(1)?[1,1]:[0,1];for(let e=0;e<20&&u-c>.001;e++){let e=(c+u)/2;[c,u]=o(e)?[e,u]:[c,e]}s.set(l,c)}return s}function Af(e,t){let n=new WeakMap;return Pf(Nf(e,r=>{let i=t??r.colors,a=[jf(r),`|`,...i].join(` `),o=n.get(r.theme)??new Qa;return n.set(r.theme,o),o.get(a,()=>kf(r,i,e.touch))}))}function jf({depth:e,pairs:t}){return[e,...t.map(Mf)].join(` `)}function Mf({fg:e,bg:t,terminal:n,reverse:r}){return`${e.hex}/${t.hex}/${n.fg}/${n.bg}/${r}`}function Nf(e,t){return n=>{let r=t(n);return ml.continuous(t=>{let i=e.field(t,n);return({fg:t,bg:n},a)=>{let o=Math.round(Bf(i(a))*48)/48,s=(t,n)=>If(e.touch,t,(n?0:r.get(t.hex)??0)*o);return{fg:s(t,a.terminal.fg),bg:s(n,a.terminal.bg)}}})}}function Pf(e){return t=>Ff(t.depth)?ml.constant(e=>e):e(t)}function Ff(e){switch(e){case V.DEFAULT:case V.STANDARD:case V.WINDOWS:return!0;case V.EIGHT_BIT:case V.TRUECOLOR:return!1}}function If(e,t,n){return n===0?t:e(t,n)}function Lf(e){if(!(Number.isFinite(e.seconds)&&e.seconds>0))throw RangeError(`curve: seconds must be a positive number of seconds, got ${e.seconds}`);if(!(e.swing>=0&&e.swing<=1))throw RangeError(`curve: swing must be in [0, 1], got ${e.swing}`)}const Rf={shimmer:{seconds:109,ease:nl.linear,swing:.9},pulse:{seconds:43,ease:nl.linear,swing:.85},sparkle:{seconds:139,ease:nl.linear,swing:.95},wheel:{seconds:907,ease:nl.linear,swing:1},fade:{seconds:20,ease:nl[`ease-in-out`],swing:1},dissolve:{seconds:30,ease:nl[`ease-in-out`],swing:1}},zf={sun:new B(255,228,176),firefly:new B(222,245,140)},Bf=e=>Math.min(1,Math.max(0,e));function Vf(e,t,n){if(!(n>=0&&n<=1))throw RangeError(`blend: w must be in [0, 1]; got ${n}`);let r=Math.PI/180,i=(1-n)*e.c*Math.cos(e.h*r)+n*t.c*Math.cos(t.h*r),a=(1-n)*e.c*Math.sin(e.h*r)+n*t.c*Math.sin(t.h*r);return new Vs((1-n)*e.l+n*t.l,Math.hypot(i,a),Math.atan2(a,i)/r,e.alpha)}function Hf(e){let t=Vs.fromRgba(e);return(e,n)=>{let r=Vs.fromRgba(e);return Vf(r,new Vs(Math.max(r.l,t.l),t.c,t.h,t.alpha),n).toRgba()}}const Uf=(e,t)=>t*e[e.length-1][0];function Wf(e,t,n){let r=t/n,i=e.findIndex(([e])=>r<e);if(!(r>0)||i<0)return 0;let[a,o]=i===0?[0,0]:e[i-1],[s,c]=e[i];return n*(o+(c-o)*(1-Math.cos(Math.PI*(r-a)/(s-a)))/2)}function Gf(e,t,n){let r=Uf(e,n),i=t=>{let r=0;for(let i=0;i<24;i++)r+=Wf(e,(i+.5)/24*t,n);return r*t};return i(Math.min(Math.max(t,0),r))/i(r)}const Kf=[[.24,1],[.6,0]];function qf(e,t,n){Lf(e);let r=.9+.2*wf(n,3.1),i=t=>.1*Sf(t/(3*e.seconds),.5,.5+n),a=i(0);return{touch:Hf(t),field:t=>{let o=r*t/e.seconds+i(t)-a,s=Math.floor(o),c=.7+.3*Tf(-.5,.5,Sf(s*.37,2.1,n)),l=.5-.5*Math.cos(2*Math.PI*(o-s)),u=e.swing*e.ease(c*l);return()=>u}}}const Jf=e=>Math.abs(e)>=1?0:(1-e*e)**3;function Yf(e,t,n,r){Lf(e);let i=e.seconds,a=i/2,o=e=>Tf(-.4,.4,Sf(e/7,3.3,5.5+r)),s=.7,c=.51,l=.4,u=(e,n,u)=>{let d=o(e),f=(wf(e,7.5+r)<.35+.6*d)*(.3+.7*d*(.6+.4*wf(e,8.5+r))),p=i*u/80*(c+l*wf(e,5.5+r)),m=Bf((n-(e+s*wf(e,6.5+r))*a)/p);return{strength:f,centre:m*u-t+.06*u*Math.sin(Math.PI*m)*Sf(m,2.7,e+r)}},d=(e,t)=>{let n=s+(c+l)*i*t/80/a,r=Math.floor(e/a),o=[];for(let i=Math.max(0,Math.ceil(r-n));i<=r;i++)o.push(u(i,e,t));return o},f=(e,t,n)=>Math.exp(-((Sf(e,t,n)/.8)**2));return{touch:Hf(n),field:(n,i)=>{let[a,o]=tp(i.cells().map(e=>e.col)),s=d(n,o-a+1+2*t);return i=>{let o=0;for(let{strength:e,centre:n}of s)o=Math.max(o,e*Jf((i.col-a-n)/t));let c=i.row+r,l=.8*Sf(i.col*.05,c*.3+1.3,n*.02),u=(f(i.col*.21+l,c*.9,n*.022)*f(i.col*.33+9.1-l,c*.7,n*.018+4.2))**2;return e.swing*e.ease(o*(.1+.6*u))}}}}function Xf(e,t,n){Lf(e);let r=e.seconds,i=22.1,a=3.1,o=(e,t,i,a,o)=>{let s=e*4.9+t*31.7+.3+n,c=e+.5+.7*Sf(e*1.7+.2,.3+t*2.9,.5+n),l=i+wf(e+t*1013,.7+n)*r,u=Math.floor(l/r),d=wf(u,s+1)<.15?0:1,f=.5+.5*wf(u,s+2),p=wf(u,s+3)*(1-Uf(Kf,f)),m=l/r-u-p;return{x:a+c*8+5*(2*wf(u,s+4)-1)+5*f*(2*wf(u,s+5)-1)*Gf(Kf,m,f)+1.5*Sf(s,.1,i*.035),y:o+t*3+.6*Sf(s,2.2,i*.035),glow:d*Wf(Kf,m,f)}};return{touch:Hf(t),field:(t,n)=>{let r=n.cells(),[s,c]=tp(r.map(e=>e.col)),[l,u]=tp(r.map(e=>e.row)),d=e=>(e-s)/8-.5,f=e=>(e-l)/3,[p,m]=[Math.ceil(d(s-i)),Math.floor(d(c+i))],[h,g]=[Math.ceil(f(l-a)),Math.floor(f(u+a))],_=Array.from({length:g-h+1},(e,n)=>Array.from({length:m-p+1},(e,r)=>o(p+r,h+n,t,s,l)));return t=>{let n=0,[r,o]=[Math.max(p,Math.ceil(d(t.col-i))),Math.min(m,Math.floor(d(t.col+i)))],[s,c]=[Math.max(h,Math.ceil(f(t.row-a))),Math.min(g,Math.floor(f(t.row+a)))];for(let e=s;e<=c;e++)for(let i=r;i<=o;i++){let r=_[e-h][i-p];n=Math.max(n,r.glow*Jf(Math.hypot(t.col-r.x,2*(t.row-r.y))/5))}return e.swing*e.ease(n)}}}}function Zf(e,t){return n=>{let r=Vs.fromRgba(n.theme.backgroundColor);return ml.continuous(i=>{let a=e(i,n);return(e,n)=>{let i=t*(1-Bf(a(n)));if(i===0)return e;let o=Vf(Vs.fromRgba(e.bg),r,i);return{fg:Vf(Vs.fromRgba(e.fg),o,i).toRgba(),bg:o.toRgba()}}})}}function Qf(e){let t=new Map;return n=>{let r=`${n.row}:${n.col}`,i=t.get(r)??Bf(.5+1.1*Cf(n.col*.09+1.4*Sf(n.col*.035,n.row*.2+2.6,e+.5),n.row*.45,e,3));return t.set(r,i),i}}function $f(e,t){let n=t=>t>=e.seconds;return{effect:r=>{let i=t(r);return{at:e=>i.at(e),nextChange:e=>n(e)?1/0:i.nextChange(e),lastChange:t=>n(t)?e.seconds:i.lastChange(t)}},done:n}}function ep(e,t){let n=new Map,r=e=>`${e.row}:${e.col}`;return i=>{let[a,o]=tp(i.map(t)),s=(o>a?.55:0)*e.seconds,c=pl.once(0,e.seconds-s),l=e=>{let n=o>a?Bf((t(e)-a)/(o-a)):0;return{along:n,progress:e=>c(e-n*s)}};for(let e of i){let t=r(e);n.set(t,n.get(t)??l(e))}return e=>n.get(r(e))??l(e)}}function tp(e){let t=e[0]??0,n=t;for(let r of e)t=Math.min(t,r),n=Math.max(n,r);return[t,n]}function np(e,t){Lf(e);let n=ep(e,Qf(1.7+t));return $f(e,Zf((t,r)=>{let i=n(r.cells());return n=>e.ease(i(n).progress(t))},e.swing))}const rp={depth:.4,from:.5,to:.95,maskFrom:.35,maskTo:.75,late:.6};function ip(e,t){Lf(e);let n=Qf(9.3+t),r=ep(e,Qf(4.2+t)),{depth:i,from:a,to:o,maskFrom:s,maskTo:c,late:l}=rp;return $f(e,Zf((t,u)=>{let d=r(u.cells());return r=>{let{along:u,progress:f}=d(r),p=e.ease(f(t)),m=Bf((p-a)/(o-a)),h=i*Tf(s,c,n(r))*(1-l+l*u)*Math.sin(Math.PI*m)**2;return 1-p+h}},e.swing))}const ap=[211,337];function op(e,t){Lf(e);let n=e.seconds,r=e=>wf(Number.parseInt(e.slice(1),16)*1e-4,17.3+t),i=(e,n)=>Sf(n/ap[0],5.9+97*e,t)+.5*Sf(n/ap[1],2.3+89*e,t+7.1),a=(t,a)=>{let o=r(t);return 360*a/n+e.swing*180*((i(o,a)-i(o,0))/1.5)},o=new WeakMap;return Pf(e=>{let{colors:t,fills:n,depth:r,theme:i}=e,s=(e,n)=>!e&&t.has(n.hex),c=(e,t,r)=>n.has(e.hex)||!r?e.hex:t.hex,l=(e,t)=>`${e.hex} ${t}`,u=o.get(i)??new Qa;o.set(i,u);let d=u.get(jf(e),()=>fp(e.pairs,r,(e,t)=>{let n=t===`fg`?`bg`:`fg`;return s(e.terminal[t],e[t])?l(e[t],c(e[t],e[n],s(e.terminal[n],e[n]))):void 0})),f=hp(r,i);return ml.continuous(e=>{let t=new Map,n=(t,n)=>{let i=sp(t,a(n,e));return gp(i.looks,t,r===V.TRUECOLOR?i.either.map(pp):f,d.get(l(t,n))??lp)},i=(e,r)=>{let i=t.get(l(e,r))??n(e,r);return t.set(l(e,r),i),i};return(e,t)=>{let n={fg:s(t.terminal.fg,e.fg),bg:s(t.terminal.bg,e.bg)},r=(e,t,n,r)=>t?i(e,c(e,n,r)):e;return{fg:r(e.fg,n.fg,e.bg,n.bg),bg:r(e.bg,n.bg,e.fg,n.fg)}}})})}function sp(e,t){if(t===0)return{looks:e,either:[e]};let n=Vs.fromRgba(e),r=Mo(e),i=e=>new Vs(e,n.c,n.h+t,n.alpha).toRgba(),[a,o]=[0,1];for(let e=0;e<24;e++){let e=(a+o)/2;[a,o]=Mo(i(e))<r?[e,o]:[a,e]}return{looks:i(o),either:[i(a),i(o)]}}const cp=e=>Math.log(No(e,new B(0,0,0))),lp={lo:-1/0,hi:1/0},up={lo:1/0,hi:-1/0},dp=Math.log(1.031);function fp(e,t,n){let r=new Map;for(let i of e.filter(e=>Df(e,t)>1)){let e=(Math.log(No(i.fg,i.bg))-Math.log(Df(i,t)))/Of.filter(e=>n(i,e)!==void 0).length;for(let t of Of){let a=n(i,t);if(a===void 0)continue;let[o,s]=[cp(i[t]),cp(i[t===`fg`?`bg`:`fg`])],{lo:c,hi:l}=r.get(a)??lp;r.set(a,o>=s?{lo:Math.max(c,o-e),hi:l}:{lo:c,hi:Math.min(l,o+e)})}}return new Map([...r].map(([e,{lo:t,hi:n}])=>[e,n-t<dp?up:{lo:t,hi:n}]))}const pp=e=>({color:e,looks:Vs.fromRgba(e),stop:cp(e)}),mp=new WeakMap;function hp(e,t){let n=H.indexed(e,t),r=mp.get(n)??n.map(([,e])=>pp(e));return mp.set(n,r),r}function gp(e,t,n,{lo:r,hi:i}){return _p(e,[pp(t),...n.filter(({stop:e})=>e>=r&&e<=i)]).color}function _p(e,t){let n=Vs.fromRgba(e),r;for(let e of t){let t=n.deltaE(e.looks);(r===void 0||t<r[1])&&(r=[e,t])}return r?.[0]}const vp={loops:{shimmer:(e,t=Rf.shimmer)=>Af(Yf(t,24,zf.sun,e.z)),pulse:(e,t=Rf.pulse)=>Af(qf(t,zf.sun,e.z)),sparkle:(e,t=Rf.sparkle)=>Af(Xf(t,zf.firefly,e.z)),wheel:(e,t=Rf.wheel)=>op(t,e.z)},transitions:{fade:(e,t=Rf.fade)=>np(t,e.z),dissolve:(e,t=Rf.dissolve)=>ip(t,e.z)}};var yp=class{beat;width;_shown;constructor(e){this.beat=fl(e.map(e=>e.seconds));let t=e.map(e=>nf(e.text.copy())),n=t.map(e=>e.cellLength);this.width=Math.max(...n),this._shown=t.map((e,t)=>(e.noWrap=!0,e.overflow=`crop`,e.padRight(this.width-n[t])))}at(e){return this._shown[this.beat.at(e)].copy()}nextChange(e){return this.beat.nextChange(e)}lastChange(e){return this.beat.lastChange(e)}};function bp(e,t){return e.at(t).copy().stylize(new U({nextChange:e.nextChange(t)}))}function xp(e,t){let n=[...Zl(e,t)],r=0;for(let e of n)r+=e.cellLength;return{segments:n,width:r}}const Sp={segments:[],width:0},Cp={left:()=>0,justify:()=>0,center:e=>Math.floor(e/2),right:e=>e};function wp(e,t){return Cp[e](t)}function Tp(e,t,n,r){let i=Math.max(0,r-1),a=e===`justify`&&!t&&i>0&&n>0?n:0,o=i>0?Math.floor(a/i):0,s=a-o*i;return Array.from({length:i},(e,t)=>o+ +(t<s))}var Ep=class{items;joiner;gap;align;constructor(e,t){this.items=e,this.joiner=t?.joiner,this.gap=t?.gap??0,this.align=t?.align??`left`}contents(){return this.items}*render(e){let t=this.items;if(t.length===0)return;let n=Math.max(1,e.maxWidth),r=this.gap,i=this.joiner,a=t.map(t=>xp(Fu(t),e)),o=n=>i?xp(Pu(i,null,t[n],{index:n}),e):Sp,s=n=>i?xp(Pu(i,t[n],null,{index:n+1}),e):Sp,c=(n,r)=>i?xp(Pu(i,t[n],t[r],{index:r}),e):Sp,l=[],u=null,d=r>0?{segments:[new G(` `.repeat(r))],width:r}:Sp;for(let e=0;e<t.length;e++){let t=a[e];if(u===null){let n=o(e),r=s(e),i=n.width>0?[n,t]:[t],a=[i.length-1];u={blocks:i,width:n.width+t.width,lastIndex:e,itemBlockIndices:a},u.endCap=r;continue}let i=u.lastIndex,f=c(i,e),p=s(e),m=(r>0?r:0)+f.width+(r>0?r:0)+t.width;if(u.width+m+p.width<=n)r>0&&u.blocks.push(d),f.width>0&&u.blocks.push(f),r>0&&u.blocks.push(d),u.blocks.push(t),u.itemBlockIndices.push(u.blocks.length-1),u.width+=m,u.lastIndex=e,u.endCap=p;else{let n=u.endCap;n.width>0&&u.blocks.push(n),u.width+=n.width,l.push(u);let r=o(e),i=s(e),a=r.width>0?[r,t]:[t],c=[a.length-1];u={blocks:a,width:r.width+t.width,lastIndex:e,itemBlockIndices:c},u.endCap=i}}let f=u;{let e=f.endCap;e.width>0&&f.blocks.push(e),f.width+=e.width,l.push(f)}let p=this.align;for(let e=0;e<l.length;e++){let t=l[e],r=e===l.length-1,i=Math.max(0,n-t.width),a=wp(p,i),o=Tp(p,r,i,t.itemBlockIndices.length),s=new Map;t.itemBlockIndices.forEach((e,t)=>s.set(e,t)),a>0&&(yield new G(` `.repeat(a)));for(let e=0;e<t.blocks.length;e++){let n=s.get(e);if(n!==void 0&&n>0){let e=o[n-1];e>0&&(yield new G(` `.repeat(e)))}yield*t.blocks[e].segments}yield G.line()}}measure(e){let t=this.items;if(t.length===0)return{minimum:0,maximum:0};let n=0,r=0;for(let i=0;i<t.length;i++){let a=xp(t[i],e).width,o=this.joiner?xp(Pu(this.joiner,null,t[i],{index:i}),e).width:0,s=this.joiner?xp(Pu(this.joiner,t[i],null,{index:i+1}),e).width:0;n=Math.max(n,a+o+s),r+=a,i>0&&(r+=this.gap*2,this.joiner&&(r+=xp(Pu(this.joiner,t[i-1],t[i],{index:i}),e).width))}return this.joiner&&(r+=xp(Pu(this.joiner,null,t[0],{index:0}),e).width,r+=xp(Pu(this.joiner,t[t.length-1],null,{index:t.length}),e).width),{minimum:n,maximum:r}}};function Dp(e){return e<32||e>=127&&e<=159||e>=8234&&e<=8238||e>=8294&&e<=8303}function Op(e){let t=``;for(let n of e)t+=Dp(n.codePointAt(0)??0)?` `:n;return t.replace(/\s+/g,` `).trim()}function kp(e,t){let n=Op(e),r=``,i=0;for(let e of n){if(i===t)return r.replace(/.$/u,`…`);r+=e,i++}return r}const Ap=`\x1B[38;2;255;255;255m`,jp=`\x1B[48;2;200;40;40m`,Mp=`\x1B[0m`;function Np(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 Pp={fg:Np(Ap),bg:Np(jp)},Fp={fg:Np(`\x1B[38;2;0;0;0m`),bg:Np(`\x1B[48;2;220;160;40m`)},Ip=new Ml({"strip.separator":`default`,"strip.rail":`default`});function Lp(e){return Ip.resolve(e)}function Rp(){let e=new WeakMap;return(t,n,r)=>{let i=e.get(t);i===void 0&&(i=new Map,e.set(t,i));let a=i.get(n);if(a!==void 0)return a;let o=r();return i.set(n,o),o}}const zp=[`primary`,`secondary`,`accent`],Bp=[`darken-3`,`darken-2`,`darken-1`,`base`,`lighten-1`,`lighten-2`,`lighten-3`],Vp={"darken-3":`-darken-3`,"darken-2":`-darken-2`,"darken-1":`-darken-1`,base:``,"lighten-1":`-lighten-1`,"lighten-2":`-lighten-2`,"lighten-3":`-lighten-3`,muted:`-muted`},Hp=(e,t)=>`${e}${Vp[t]}`,Up=(e,t,n,r)=>Sm(e,n,r),Wp=(e,t,n,r)=>wm(e,fm(e,`text-${t}`),n,r),Gp=e=>({tones:[Bp[e],Bp[e+2],Bp[e+1]],text:Up}),Kp={muted:{tones:[`muted`],text:Wp},deepest:Gp(0),deeper:Gp(1),middle:Gp(2),brighter:Gp(3),brightest:Gp(4)},qp=1/0,Jp={accent:{hues:[`secondary`,`accent`],run:qp},duo:{hues:[`primary`,`secondary`],run:qp},mono:{hues:[`primary`],run:qp},alt:{hues:[`secondary`,`accent`],run:3}},Yp=e=>e.variation.hues.flatMap(t=>e.shade.tones.map(e=>({hue:t,shade:e}))),Xp=e=>{let t=0,n=.5;for(let r=e;r>0;r>>=1,n/=2)t+=n*(r&1);return t},Zp=[`van-der-corput`,`golden-angle`,`ends-interleaved`,`monotonic`,`uniform`],Qp=e=>typeof e==`string`&&Zp.includes(e),$p={"van-der-corput":Xp,"golden-angle":e=>e*.6180339887498949%1,"ends-interleaved":(e,t)=>((e%2==0?e/2:t-1-(e-1)/2)+.5)/t,monotonic:(e,t)=>(e+.5)/t,uniform:()=>.5},em=e=>$p[e??`van-der-corput`];function tm(e){let t=0,n=1;for(let{index:r,count:i,distribution:a}of e)t+=a(r,i)*n,n*=.37;return t%1}const nm=(e,t)=>Math.floor(e*t),rm=(e,t)=>Math.round(e*t)%t;function im(e){return e===void 0?0:e.distribution(e.index,e.count)}function am(e,t,n){let r=e[n(im(t),e.length)];if(r===void 0)throw Error(`vocabularySelect: empty vocabulary`);return r}function om(e){let t=e.findIndex(e=>e.axis===`cell`),n=t===-1?e:e.slice(0,t);return{row:n.at(-1),cell:e[n.length]}}const sm=(e,t)=>nm(im(t),e.hues.length);function cm(e,t){let{row:n,cell:r}=om(t);return lm(e,n,r)}function lm(e,t,n){let{hues:r,run:i}=e.variation,a=n===void 0?0:Math.floor(n.index/i),o=r[(sm(e.variation,t)+a)%r.length];if(o===void 0)throw Error(`decorEntryFor: empty variation`);return{hue:o,shade:am(e.shade.tones,n,rm)}}function um(e,t){let{row:n,cell:r}=om(t),i=r===void 0?[void 0]:Array.from({length:r.count},(e,t)=>({...r,index:t}));return[...new Map(i.map(t=>lm(e,n,t)).map(e=>[Hp(e.hue,e.shade),e])).values()].sort((e,t)=>zp.indexOf(e.hue)-zp.indexOf(t.hue)||dm.indexOf(e.shade)-dm.indexOf(t.shade))}const dm=[...Bp,`muted`];function fm(e,t){let n=e.get(t);if(n===void 0)throw Error(`palette "${e.name}" has no "${t}" role; decoration needs it`);return n}const pm=(e,t)=>fm(e,Hp(t.hue,t.shade)),mm=2.2,hm=(e,t)=>t.map(t=>pm(e,t)),gm=e=>t=>ec(t,e),_m=gm(V.TRUECOLOR);function vm(e,t,n,r){return ym(e,`${t}|${n.map(e=>e.hex).join(`+`)}|${r}`,()=>bm(e,t,n,r))}const ym=Rp();function bm(e,t,n,r){let i=n.map(_m),a=fm(e,t),o=new B(0,0,0),s=new B(255,255,255),c=(e,t)=>Vs.fromRgba(a).mixAxes(Vs.fromRgba(e),{l:t,c:0,h:0,alpha:0}).toRgba(),l=e=>Array.from({length:12},(t,n)=>c(e,(n+1)/12)),u=l(o),d=[a,...l(s).flatMap((e,t)=>[e,u[t]])],f=e=>{let t=gm(e),n=i.map(t);return e=>Math.min(1/0,...n.map(n=>No(t(e),n)))},p=f(V.TRUECOLOR),m=f(r),h=e=>$s(e,r,(e,t)=>i.every(n=>No(e,t(n))>=mm)),g=e=>p(e)>=2.2&&h(e)!==void 0,_=(e,t)=>{let n=n=>No(_m(n),e)-No(_m(n),t),r=n(a)<0?o:s,i=r===o?1:-1,[l,u]=[0,1];for(let e=0;e<40;e++){let e=(l+u)/2;i*n(c(r,e))>0?u=e:l=e}return[c(r,l),c(r,u)]},v=()=>{let e=[...i].sort((e,t)=>Mo(e)-Mo(t));return e.slice(1).flatMap((t,n)=>_(t,e[n]))},y=d.find(g)??[...d,...v()].reduce((e,t)=>m(t)>m(e)?t:e),b=h(y)??y,x=m(b);return{anchor:y,state:b,short:x>=2.2?null:x}}const xm=4.5;function Sm(e,t,n){return Cm(e,`${t.hex}|${n}`,()=>{let r=Zs(t);return wm(e,[`background`,`foreground`].map(t=>fm(e,t)).reduce((e,t)=>No(r,t)<No(r,e)?t:e),t,n)})}const Cm=Rp();function wm(e,t,n,r){return Tm(e,`${t.hex}|${n.hex}|${r}`,()=>Qs(t,n,xm,r))}const Tm=Rp();function Em(e,t,n){return t.depth===0?hm(e,t.ground):Dm(e,t,n)}const Dm=(e,t,n)=>t.depth===0?[]:[Rm(e,{...t,depth:t.depth-1},n).plane],Om=(e,{short:t},n)=>t===null?[]:[`theme "${e.name}": no open-trigger colour stands ${mm}:1 off every cell beside it — the nearest stands ${t.toFixed(2)}:1 as drawn at depth ${V[n]}; another shade or variation clears it`],km=(e,t,n)=>t>=Nm.triggerPlane?[]:[`theme "${e.name}": an open band's plane stands ΔE ${t.toFixed(3)} off the trigger that opened it as drawn at depth ${V[n]}, under the ${Nm.triggerPlane} that tells them apart; another style clears it`],Am={base:.42,perDepth:.14,cap:.75},jm={floor:.12,span:.8};function Mm(e,t){return zp[(zp.indexOf(e)+t)%zp.length]}const Nm={triggerPlane:.1,nestedPlane:.035};function Pm(e,t,n){return Fm(e,`${Im(t)}|${n}`,()=>{let r=vm(e,Mm(t.hue,t.depth),Em(e,t,n),n),{state:i}=r,a=Hm(e,t,i,n),o=$s(Rm(e,t,n).plane,n,(e,t)=>a.every(n=>n(e,t)));if(o===void 0)throw Error(`palette "${e.name}": the ${t.hue} band at depth ${t.depth} cannot keep its floors on the colours drawn at depth ${V[n]}`);let s=gm(n);return{state:i,plane:o,shortfalls:n===V.DEFAULT?[]:[...Om(e,r,n),...km(e,Lm(s(i),s(o)),n)]}})}const Fm=Rp(),Im=({hue:e,depth:t,ground:n})=>`${e}|${t}|${n.map(e=>Hp(e.hue,e.shade)).join(`+`)}`,Lm=(e,t)=>Vs.fromRgba(e).deltaE(Vs.fromRgba(t));function Rm(e,t,n){return zm(e,`${Im(t)}|${n}`,()=>Bm(e,t,n))}const zm=Rp();function Bm(e,t,n){let{anchor:r}=vm(e,Mm(t.hue,t.depth),Em(e,t,n),n),i=Math.min(Am.cap,Am.base+Am.perDepth*t.depth),a=(t,n)=>fs(r,fm(e,t),n),o=Dm(e,t,n),s=e=>Lm(_m(r),_m(e))>=Nm.triggerPlane&&o.every(t=>Lm(_m(t),_m(e))>=Nm.nestedPlane),c=a(`background`,i);return{state:r,plane:[c,a(`foreground`,i),a(`background`,Am.cap),a(`foreground`,Am.cap),...Vm.toSorted((e,t)=>Math.abs(e-i)-Math.abs(t-i)).flatMap(e=>[a(`background`,e),a(`foreground`,e)])].find(s)??c}}const Vm=Array.from({length:12},(e,t)=>(t+1)/12);function Hm(e,t,n,r){let{hue:i,depth:a,ground:o}=t,s=t=>Rm(e,{hue:i,depth:t,ground:o},r).state,c=t=>Rm(e,{hue:i,depth:t,ground:o},r).plane,l=c(a),u=(e,t)=>Lm(_m(l),_m(t))>=e?e:0,d=vm(e,Mm(i,a+1),Em(e,{hue:i,depth:a+1,ground:o},r),r),f=No(_m(l),_m(d.anchor))>=2.2?mm:0,p=(e,t)=>(n,r)=>Lm(n,r(e))>=t;return[p(n,u(Nm.triggerPlane,s(a))),(e,t)=>No(e,t(d.state))>=f,...a>0?[p(Pm(e,{hue:i,depth:a-1,ground:o},r).plane,u(Nm.nestedPlane,c(a-1)))]:[]]}function Um(e,t,n,r){let i=Pm(e,t,r),a=Rm(e,t,r),o=e=>fs(a.plane,a.state,e),s=jm.floor+jm.span*tm(n),c=jm.floor+jm.span/2,l=(e,t)=>e.hex!==t(i.plane).hex&&e.hex!==t(i.state).hex;for(let e=0;e<=12;e++){let t=$s(o(s+(c-s)*e/12),r,l);if(t!==void 0)return t}return o(s)}const Wm=e=>({kind:`bar`,decor:e,address:[]}),Gm=(e,t)=>({...e,address:[...e.address,t]}),Km=e=>({kind:`band`,band:e,address:[]});function qm(e,t,n){switch(t.kind){case`bar`:{let{decor:r,address:i}=t,a=cm(r,i),o=pm(e,a),s;return{tint:o,text:r.shade.text(e,a.hue,o,n),disclosure:{hue:`accent`,depth:0,get ground(){return s??=um(r,i)}}}}case`band`:{let{band:r,address:i}=t,a=Um(e,r,i,n);return{tint:a,text:Sm(e,a,n),disclosure:{...r,depth:r.depth+1}}}}}const Jm=new Map([[`dark`,`textual-dark`],[`light`,`textual-light`]]);function Ym(e){let t=typeof e==`string`?Jm.get(e):void 0;return t===void 0?``:` — "${e}" was retired; write "${t}", the same palette`}const Xm=`textual-dark`;function Zm(e,t,n,r,i){let a=t===null?null:i(t);return e??a??n??r}function Qm(){return xc()}function $m(){return[`bar`,...Qm()]}let eh;function th(e){return eh??=new Set($m()),eh.has(e)}function nh(e,t,n,r,i){let a=e=>Object.prototype.hasOwnProperty.call(i,e)?e:null;return Zm(e===void 0?null:a(e),t,a(n??r),r,a)}const rh=[`style`,`palette`,`effect`];function ih(e){return e!==void 0&&e.includes(`{{`)}function ah(e,t,n,r,i){let a=ih(n)?{kind:`expression`,source:n}:i(n??r.name);return Zm(e===void 0?null:i(e),t,a,r,i)}function oh(e,t){return e.kind===`decided`?e:t(e.source)}const sh=`none`;function ch(e,t){let n=t[e];return n===void 0?null:{kind:`decided`,name:e,value:n}}function lh(e,t){return ch(e,t)??ch(`none`,t)??{kind:`decided`,name:`none`,value:As}}function uh(e,t,n,r){return ah(e,t,n,lh(sh,r),e=>ch(e,r))}const dh=`none`,fh={style:sh,palette:Xm,effect:dh};function ph(e,t,n){return`${e} rendered "${fh[t]}": ${n}`}const mh=Object.freeze([dh,...Object.keys(vp.loops)]),hh=Object.freeze([`bar`,...mh]);function gh(e){let t=mh.find(t=>t===e);return t===void 0?null:{kind:`decided`,name:e,value:t}}function _h(e){return gh(e)??{kind:`decided`,name:`none`,value:`none`}}function vh(e,t,n){return ah(e,t,n,_h(dh),gh)}const yh=Object.freeze(Object.keys(Bd));function bh(e){return yh.includes(e)}const xh=[`powerline`,`capsule`,`plain`];function Sh(e){return xh.includes(e)}function Ch(e,t,n){return Zm(e,t,n,`powerline`,e=>bh(e)?e:null)}const wh=[`truecolor`,`256`,`ansi`,`none`];function Th(e){return Ko(e)??V.DEFAULT}const Eh=Object.keys(Jp);function Dh(e){return Eh.includes(e)}function Oh(e,t,n){return Zm(e,t,n,`accent`,e=>Dh(e)?e:null)}const kh=Object.keys(Kp);function Ah(e){return kh.includes(e)}function jh(e,t,n){return Zm(e,t,n,`middle`,e=>Ah(e)?e:null)}const Mh=`true`,Nh=`false`,Ph=[Mh,Nh],Fh={min:0,max:16};function Ih(e){return e===`true`?!0:e===`false`?!1:null}function Lh(e,t){let n=Number(e);return Number.isInteger(n)&&String(n)===e&&n>=t.min&&n<=t.max?n:null}function Rh(e){return Lh(e,Fh)}function zh(e,t,n){return Zm(e,t,n,!0,Ih)}function Bh(e,t,n){return Zm(e,t,n,!0,Ih)}function Vh(e,t,n){return Zm(e,t,n,!1,Ih)}function Hh(e,t,n){return Zm(e,t,n,1,Rh)}const Uh={kind:`still`};function Wh(e){return e.effect!==`none`||e.own.some(e=>e.effect!==`none`)||e.fades.length>0||e.leaves.length>0}const Gh=Symbol(`bar`);function Kh(e){return e.name!==dh}function qh(e,t){return n=>ml.map(ml.all(t.map(({t,effect:r})=>Sl.run(Sl.play(e-t),r(n)))),e=>(t,n)=>e.reduce((e,t)=>t(e,n),t))}const Jh=Ac;function Yh(e,t){let n=new ps(t,Jh.foregroundColor,Jh.ansiColors,Jh.palette);return t=>e({...t,theme:n})}function Xh(e,t){return n=>uf(()=>e(n),...t)(n)}function Zh(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 Qh=4096;var $h=class{inForce=null;placements=new Map;made=new Map;drawn=null;frame={effect:dh,t:0,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.drawn?.placements.values()??[]].filter(({passage:e})=>e!==null).length;return[...this.made.values()].reduce((e,t)=>e+t.size,e)}motion(e,t,n){let r=this.inForce?.name===e?this.inForce:{name:e,since:t},i={scope:Gh,name:e,t:t-r.since},a=this.placements,o=new Map,s=this.made,c=new Map,l=[],u=this.drawn,d=n.transitions?u!==null&&u.source.config===n.source.config&&u.source.preset===n.source.preset&&u.source.revision===n.source.revision&&u.source.width===n.source.width?`compared`:`fresh`:`off`,f=d===`compared`?u.placements:null,p=new Map,m=[],h=[],g={effect:e,t:i.t,made:0,reused:0,own:l,basis:d,revision:n.source.revision,fades:m,leaves:h},_=(e,n,{ground:r})=>{let i=vp.transitions[e]({z:Zh(`${this.key}@${n}`)*Qh});return{name:e,since:t,transition:{effect:Yh(i.effect,r),done:e=>i.done(e)}}},v=({since:e,transition:n})=>n.done(t-e),y=(e,t,n)=>({drawing:t,passage:f===null?null:n===void 0||n.passage?.name===`dissolve`?_(`fade`,e,t):n.passage!==null&&!v(n.passage)?n.passage:null}),b=(e,t)=>{if(t===void 0||t.drawing.own.length===0)return;if(t.passage?.name===`dissolve`)return v(t.passage)?void 0:t;let r={...t.drawing,own:t.drawing.own.map(n.hold)};return{drawing:r,passage:_(`dissolve`,e,r)}},x=(e,r)=>{if(p.has(e))throw Error(`placement "${e}" was reached twice in one frame`);let i=f?.get(e),{drawing:a,deeper:o}=n.returned(e,r),s=a===null?b(e,i):y(e,a,i);return s===void 0?r:(p.set(e,s),s.passage!==null&&(s.passage.name===`fade`?m:h).push({placement:e,t:t-s.passage.since}),a===null?[...s.drawing.own,...o]:r)},S=(e,n)=>{let r=o.get(e)??a.get(e),i=r?.name===n?r:{name:n,since:t},s=t-i.since;return o.has(e)||(o.set(e,i),l.push({placement:e,effect:n,t:s})),{scope:e,name:n,t:s}},C=(e,t)=>{let n=c.get(e)??new Map;c.set(e,n);let r=n.get(t.scope);if(r!==void 0)return r.effect;let i=s.get(e)?.get(t.scope),a=i?.name===t.name,o=Zh(t.scope===Gh?e:`${e}@${t.scope}`),l=a?i.effect:vp.loops[t.name]({z:o*Qh});return g[a?`reused`:`made`]++,n.set(t.scope,{name:t.name,effect:l}),l},w=e=>{let t=new Map;for(let{owner:n,placement:r}of e){let e=r.effect===`bar`?i:S(r.id,r.effect),a=t.get(e.scope);a===void 0?t.set(e.scope,{...e,owners:[n]}):a.owners.push(n)}return[...t.values()]},ee=e=>{let n=new Map;for(let{owner:t,placement:r}of e){let e=n.get(r.id);e===void 0?n.set(r.id,[t]):e.push(t)}return[...n].flatMap(([e,n])=>{let r=p.get(e)?.passage??null;return r===null?[]:[{t:t-r.since,effect:uf(r.transition.effect,...n)}]})};return{placed:d===`off`?(e,t)=>t:x,row:(e,t)=>{let n=(t.some(e=>e.placement.effect!==`bar`)?w(t):[{...i,owners:void 0}]).filter(Kh),r=ee(t);if(n.length===0&&r.length===0)return Uh;let a=`${this.key}#${e}`;return{kind:`moving`,wrap:e=>new rf(e,qh(i.t,[...n.map(e=>{let t=C(a,e);return{t:e.t,effect:e.owners===void 0?t:Xh(t,e.owners)}}),...r]),{t:i.t,key:a,theme:Jh})}},drawn:()=>{this.inForce=r,this.placements=o,this.made=c,this.drawn=d===`off`?null:{source:n.source,placements:p},this.frame=g}}}},eg=class{sessions=new Map;constructor(e=256){this.maxSessions=e}of(e){let t=this.sessions.get(e)??new $h(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 tg(e,t){return Ud(e,{...t,theme:Ip,onStyleError:e=>{throw e}})}const ng=new Map;function rg(e){let t=ng.get(e);if(t!==void 0)return t;let n=t=>{let n=t.seam.map(t=>`cap`in t?t:{...t,glyph:e});return{seam:n,divider:n}},{seam:r,caps:i}=Bd.plain,a=new ld({glyph:n(r.glyph),ascii:r.ascii},i);return ng.set(e,a),a}function ig(e,t){return e===`plain`&&t!==void 0?rg(t):Bd[e]}const ag=new Map;function og(e){let t=JSON.stringify([e.endcaps,e.separator??null]),n=ag.get(t);if(n!==void 0)return n;let r=ig(e.endcaps,e.separator),i=e=>new K(`x`,{end:``,overflow:`ignore`,style:new U({bgcolor:e})}),a=e=>new K(tg(new Iu(e,r),{colorSystem:null}).replace(/\n$/,``)).cellLength,o=a([i(`#101010`)]),s={chrome:o-1,seam:a([i(`#101010`),i(`#202020`)])-o-1};return ag.set(t,s),s}function sg(e){return og(e).chrome}function cg(e){return og(e).seam}const lg=/[\u{E000}-\u{F8FF}\u{F0000}-\u{FFFFD}\u{100000}-\u{10FFFD}]/gu;function ug(e){return[...new Set(e.match(lg)??[])].join(``)}function dg(e){let t=ig(e.endcaps,e.separator),n=e=>new K(`x`,{end:``,style:new U({bgcolor:e})});return ug(tg(new Iu([n(`#101010`),n(`#202020`),n(`#202020`)],t),{colorSystem:null}))}function fg(e,t,n=Uh){if(e.length===0)return``;let r=ig(t.endcaps,t.separator),i=t.wrap&&Number.isFinite(t.width),a={colorSystem:t.colorCompatibility,...i?{width:t.width}:{}},o=i?new Ep([...e],{joiner:r}):new Iu([...e],r),s=tg(n.kind===`still`?o:n.wrap(o),a);if(!s.endsWith(`
|
|
54
|
-
`))throw Error(`
|
|
55
|
-
`)}function
|
|
56
|
-
`);return e?`${l}\n${e}`:l}function
|
|
57
|
-
`))}function wg(e,t,n,r){let{colors:i}=e.channels[0].severity,{fullText:o,failedConfigFile:s}=t,c=new U({bgcolor:i.bg,color:i.fg}),l=(e,t)=>new K(e,{style:t,end:``,overflow:`ignore`}),u=n>0?[l(`${n} more rows · `,c),o.kind===`file`?l(`open full text`,c.withLink(a(o.path).href)):l(`full text unavailable: ${Op(o.reason)}`,c)]:[],d=s===null?[]:[l(`${u.length>0?` · `:``}open `,c),l(Op(s),c.withLink(a(s).href))],f=[l(`↳ `,c),...u,...d.slice(0,-1)],p=f.reduce((e,t)=>e+t.cellLength,0),m=d.slice(-1).map(e=>e.truncate(Math.max(1,r.width-p),{mode:`middle`})),h=K.fromFragments([...f,...m]).truncate(r.width);return h.overflow=`ignore`,fg([h],r)}const Tg=e=>!e.startsWith(`.`)&&!e.endsWith(`~`);function Eg(e,t){return t.isSymbolicLink()?Buffer.from(s.readlinkSync(e)):s.readFileSync(e)}function Dg(e,t,n=Tg){return s.readdirSync(t).filter(n).sort().flatMap(n=>{let r=v.join(t,n),i=s.lstatSync(r,{throwIfNoEntry:!1});return i===void 0?[]:i.isDirectory()?Dg(e,r):[[v.relative(e,r).split(v.sep).join(`/`),Eg(r,i)]]})}function Og(e){let t=O.createHash(`sha256`);for(let[n,r]of e)t.update(n).update(`\0`).update(r).update(`\0`);return t.digest(`hex`)}function kg(e){return Og(Dg(e,e))}const Ag=[`Cargo.toml`,`Cargo.lock`,`src`];function jg(e){return Og(Dg(e,e,e=>Ag.includes(e)))}const Mg=e=>e.slice(0,7);function Ng(e){let t=v.dirname(v.dirname(e));return s.existsSync(v.join(t,`src`))?t:null}function Pg(){let e=Fg();if(e===null)throw Error("this bundle carries no source digest (build via `pnpm build`, which stamps it)");return{version:Ft,digest:e}}function Fg(){return`f9d071398b5fc66b4b313b76e889211f9ddb1ae81d36c2e249ced8b39776fd21`}function Ig(e){let t=JSON.parse(s.readFileSync(v.join(e,`package.json`),`utf8`)),n=typeof t==`object`&&t?t.version:void 0;if(typeof n!=`string`)throw Error(`${v.join(e,`package.json`)} has no version string`);return n}function Lg(e,t){try{let n=Ng(i(e));if(n===null)return{kind:`not-source-checkout`};let r=t(),a=kg(v.join(n,`src`));return a===r.digest?{kind:`current`,root:n,stamp:r}:{kind:`stale`,root:n,source:{version:Ig(n),digest:a},running:r}}catch(e){return{kind:`unchecked`,reason:e.message}}}var q=class extends Error{constructor(e){super(e),this.name=`BadVerbArgs`}};const Rg=new Map;function zg(e){let t=Vg(e);if(t===null)throw Error(`Palette "${e}" did not resolve in the theme registry — allowed names and the registry are inconsistent`);return t}function Bg(e,t){return e===`bar`?t:zg(e)}function Vg(e){let t=Rg.get(e);if(t!==void 0)return t;let n=Sc(e);return n===null?null:(Rg.set(e,n),n)}function Hg(e,t){return Ug(e,`${t.hueShift} ${t.chromaScale} ${t.lightnessScale} ${t.lightnessShift}`,()=>Pc(e,t))}const Ug=Rp();function Wg(e){let t=Vg(e);return t===null?null:{kind:`decided`,name:e,value:t}}function Gg(e,t,n){let r=Wg(e);return r===null?(n(ph(t,`palette`,`"${e}" names no installed theme${Ym(e)}`)),qg()):r}function Kg(e,t,n){return ah(e,t,n,qg(),Wg)}function qg(){return{kind:`decided`,name:Xm,value:zg(Xm)}}const Jg=[`vertical`,`horizontal`],Yg={vertical:`row`,horizontal:`cell`};function Xg(e){return e.id??e.name}function Zg(e){return[...e_(e)].flatMap(e=>e.kind===`segment`?[Xg(e)]:[])}function Qg(e,t){if(!t.has(e))return e;let n=2;for(;t.has(`${e}-${n}`);)n++;return`${e}-${n}`}function $g(e,t){return e.opens===void 0?e:{...e,opens:{...e.opens,body:t(e.opens.body)}}}function*e_(e){yield e;for(let t of i_(e))yield*e_(t)}const t_=(e,t)=>`${e}.children[${t}]`,n_=e=>`${e}.opens.body`;function*r_(e,t){if(yield[e,t],e.kind===`container`)for(let[n,r]of e.children.entries())yield*r_(r,t_(t,n));else e.opens!==void 0&&(yield*r_(e.opens.body,n_(t)))}function i_(e){return e.kind===`container`?e.children:e.opens===void 0?[]:[e.opens.body]}const a_=[`shade`,`variation`,`style`];function o_(e){return e===void 0||`text`in e?`text`:`regex`in e?`regex`:`json`}const s_=[`ttl`,`watch_file`,`depends_on`,`key`,`never`];function c_(e){return e.kind===`file`||e.kind===`shell`}const l_=[`branch`,`sha`,`dirty`,`ahead`,`behind`,`stash`],u_=[`fail`,`ignore`];function d_(e){return e.missingData??`fail`}function*f_(e){for(let[t,n]of Object.entries(e.variables))n.kind===`state`&&(yield[t,n]);for(let[t,n]of Object.entries(e.segments))if(n.vars)for(let[e,r]of Object.entries(n.vars))r.kind===`state`&&(yield[`${t}.${e}`,r])}const p_=`theme`,m_=`effect`,h_=[p_,m_];function g_(e){return{...e.settings,[p_]:{label:p_,domain:`theme`,default:e.palette??`bar`},[m_]:{label:m_,domain:hh,default:`bar`}}}function __(e){let t=e?.domain;return typeof t==`object`&&`min`in t?t:void 0}function v_(e,t){return Object.entries(e).flatMap(([n,r])=>{let i=__(r)?.atLeast;if(i===void 0)return[];let a=t[n],o=t[i];return a>=o?[]:[{setting:n,message:`"${n}" (${a}) is below "${i}" (${o}) — ${r.label} must be at least ${e[i].label}`}]})}function y_(e,t){let{domain:n}=e;return n===`bool`?typeof t==`boolean`:n===`theme`?typeof t==`string`&&th(t):`min`in n?typeof t==`number`&&Number.isInteger(t)&&t>=n.min&&t<=n.max:typeof t==`string`&&n.includes(t)}function b_(e){return String(e)}function x_(e,t){let{domain:n}=e;if(typeof n==`object`&&`min`in n)return Lh(t,n)??void 0;let r=n===`bool`?t===`true`?!0:t===`false`?!1:t:t;return y_(e,r)?r:void 0}function S_(e,t,n,r){let i=e.settings?.[t]??n.default,a=e.drafts?.[t],o=a===void 0?null:r(a);return(o===null?void 0:x_(n,o))??i}function C_(e){let{domain:t}=e;return t===`bool`?`true or false`:t===`theme`?`"bar" (the bar's own theme) or an installed theme name`:`min`in t?`an integer from ${t.min} to ${t.max}`:`one of ${t.map(e=>JSON.stringify(e)).join(`, `)}`}const w_=[`left`,`center`,`right`],T_=[`right`,`left`,`middle`],E_=/^[A-Za-z_][A-Za-z0-9_]*$/;function D_(e){return`#${e+1}`}const O_={rows:{}};function k_(e){return`rows`in e}function A_(e){return Object.fromEntries(e.map((e,t)=>[D_(t),e]))}function j_(e){if(e.kind===`container`&&e.direction===`vertical`){let{kind:t,direction:n,children:r,...i}=e;return{...i,rows:A_(r)}}let{when:t,...n}=e;return{...t!==void 0&&{when:t},rows:A_([n])}}function M_(e){let{rows:t,...n}=e;return{kind:`container`,direction:`vertical`,children:Object.values(t),...n}}function N_(e){return k_(e)?M_(e):e}function*P_(e,t){if(!k_(e)){yield*r_(e,t);return}yield[M_(e),t];for(let[n,r]of Object.entries(e.rows))yield*r_(r,`${t}.rows.${n}`)}function F_(e,t){return k_(e)?{...t,...e,rows:{...t.rows,...e.rows}}:j_(e)}function I_(e){if(!k_(e))return!0;let{rows:t,...n}=e;return Object.values(n).some(e=>e!==void 0)||Object.keys(t).length>0}const L_=`default`,R_={};function z_(e){return[...new Set([L_,...Object.keys(e)])]}function B_(e,t,n){return nh(void 0,e,t,L_,n)}function V_(e,t){let n={[L_]:R_,...e}[t];if(n===void 0)throw Error(`Preset "${t}" is not declared in this config — effectivePresetName collapses unknown names to "${L_}", which always resolves; a miss here means a raw name reached this function without going through that resolution`);return n}function H_(e,t){let n=V_(e.presets,t).root??O_;return{node:M_(F_(n,e.root)),path:I_(n)?`presets.${t}.root`:`root`}}function U_(e,t){return{...e.globals,...V_(e.presets,t).globals}}const W_=new Map;function G_(e,t,n){W_.set(e,{permanent:!0,resolve:t,paletteOf:n})}G_(`themes`,()=>Qm(),e=>zg(e));const K_=`placementThemes`;G_(K_,$m,(e,t)=>Bg(e,t.palette)),G_(`endcaps`,()=>yh),G_(`variations`,()=>Eh),G_(`shades`,()=>kh),G_(`colorCompatibilities`,()=>wh);function q_(e){return new Map([[`styles`,{members:Object.keys(e.styles),paletteOf:(t,n)=>Hg(n.basePalette,e.styles[t])}],[`presets`,{members:z_(e.presets)}]])}function J_(e){return[...new Set([...W_.keys(),...e.keys()])]}function Y_(e,t){if(typeof e!=`string`)return{members:e};let n=t.get(e);if(n)return n;let r=W_.get(e);if(r)return{members:r.resolve(),paletteOf:r.paletteOf};throw Error(Z_(e,t))}const X_=new Map([[`looks`,`styles`],[`progressions`,`variations`]]);function Z_(e,t){let n=X_.get(e);return`unknown option domain "${e}"${n===void 0?``:` — it was renamed "${n}"; write from: "${n}"`} (have: ${J_(t).join(`, `)})`}const Q_=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`[^`]*`/g;function*$_(e){let t=e.indexOf(`{{`);for(;t!==-1;){let n=``,r=t+2;for(;r<e.length&&!e.startsWith(`}}`,r);){if(e.startsWith(`/*`,r)){let t=e.indexOf(`*/`,r+2);r=t===-1?e.length:t+2;continue}let t=r,i=e[r];if(r+=1,i===`"`||i===`'`||i==="`"){for(;r<e.length&&e[r]!==i;)r+=e[r]===`\\`&&i!=="`"?2:1;r+=1}n+=e.slice(t,r)}if(r>=e.length)return;yield n,t=e.indexOf(`{{`,r+2)}}const ev=`[A-Za-z_]\\w*(?:\\.[A-Za-z_]\\w*)*`,tv=RegExp(`^(?:(\\$)(?:\\.(${ev}))?|\\.(${ev})?)(?=[\\s)]|$)`);function nv(e,t,n){let r=tv.exec(e.trimStart());if(r===null)return null;let[i,a]=r[1]===void 0?[t,r[3]]:[n,r[2]];return i===null?null:a===void 0?i:`${i}${a}.`}const rv=/^(\w+)\b\s*([\s\S]*)$/;function*iv(e,t){let n=[t];for(let r of $_(e)){let e=r.replace(/^-(?=\s)/,``).trim(),[,i=``,a=``]=rv.exec(e)??[],o=n[n.length-1],s=n.length>1?n[n.length-2]:o;if(i===`end`){n.length>1&&n.pop();continue}if(i===`else`){yield{code:e,dot:s};let r=/^with\b([\s\S]*)$/.exec(a);n[n.length-1]=r===null?s:nv(r[1],s,t);continue}yield{code:e,dot:o},i===`if`&&n.push(o),i===`with`&&n.push(nv(a,o,t)),(i===`range`||i===`define`||i===`block`)&&n.push(null)}}const av=/(?<![.$])\btemplate\s+$/;function*ov(e,t,n){let r=0;for(let i of[...e.matchAll(Q_)]){let a=i.index+i[0].length;av.test(e.slice(r,i.index))&&(yield{name:i[0].slice(1,-1),at:nv(e.slice(a),t,n)}),r=a}}function*sv(e,t){let n=new Set;function*r(e,i,a,o){for(let{code:s,dot:c}of[...iv(e,i)]){yield{code:s,dot:c,root:i,via:a};for(let e of[...ov(s,c,i)]){let i=Object.hasOwn(t,e.name)?t[e.name]:void 0,a=`${e.name}\0${e.at??`\0`}`;i===void 0||o.has(e.name)||n.has(a)||(n.add(a),yield*r(i,e.at,e.name,new Set([...o,e.name])))}}}yield*r(e,``,null,new Set)}const cv=RegExp(`(?<![A-Za-z0-9_)$])(\\$?)\\.(${ev})`,`g`);function*lv({code:e,dot:t,root:n}){let r=e.replace(Q_,``);for(let e of[...r.matchAll(cv)]){let r=e[1]===`$`?n:t;r!==null&&(yield`${r}${e[2]}`)}}function uv(e,t){let n=new Map;for(let r of sv(e,t))for(let e of lv(r))n.has(e)||n.set(e,r.via);return n}const dv=/(?<![.$])\b(action|picker|menu|carousel|swatches|swatch|themePreview)\s+$/,fv={action:1,picker:2,menu:1,carousel:2,swatch:1,swatches:2,themePreview:1};function*pv(e){let t=0,n=0,r=0,i=`action`;for(let a of[...e.matchAll(Q_)]){let o=e.slice(t,a.index),s=dv.exec(o);if(s!==null)n=fv[s[1]],r=0,i=s[1]===`action`?`action`:`options`;else for(let e of o)e===`(`&&r++,e===`)`&&r--,(r<0||e===`|`&&r===0)&&(n=0);n>0&&r===0&&(yield{name:a[0].slice(1,-1),site:i},n--),t=a.index+a[0].length}}function mv(e,t){let n=new Map;for(let{code:r,via:i}of sv(e,t))for(let{name:e,site:t}of pv(r)){let r=`${e}\0${i??`\0`}`;n.has(r)||n.set(r,{name:e,site:t,via:i})}return[...n.values()]}function hv(e,t){return new Set([...gv(e,t)].filter(e=>Object.hasOwn(t,e)))}function gv(e,t){let n=new Set;for(let{code:r,dot:i,root:a}of sv(e,t))for(let{name:e}of ov(r,i,a))n.add(e);return n}function _v(e,t){if(t.names.has(e))return!0;let n=`${e}.`;for(let e of t.names)if(e.startsWith(n))return!0;for(let n of t.documents)if(e.startsWith(`${n}.`))return!0;return!1}function vv(e){let t=new Set,n=new Set,r=(e,r)=>{t.add(e),yv(r)&&n.add(e)};for(let[t,n]of Object.entries(e.variables))r(t,n);for(let[t,n]of Object.entries(e.segments))for(let[e,i]of Object.entries(n.vars??{}))r(`${t}.${e}`,i);return{names:t,documents:n,helpers:e.helpers}}function yv(e){return e.kind===`dropped`||(e.kind===`shell`||e.kind===`file`)&&o_(e.parse)===`json`}function bv(e){let t=v.basename(e),n=v.dirname(e);for(;;){let r=xv(n);if(r!==null)return{dir:r,name:t,leaf:n===v.dirname(e)};t=v.basename(n),n=v.dirname(n)}}function xv(e){try{return s.statSync(e).isDirectory()?s.realpathSync(e):null}catch{return null}}var Sv=we((e=>{function t(e,...t){throw Error(`[MobX] minified error nr: ${e}${t.length?` `+t.map(String).join(`,`):``}. See mobx.js.org/errors`)}function n(e){let t=!1;return function(){if(!t)return t=!0,e.apply(this,arguments)}}function r(e){return typeof e==`function`}function i(e){switch(typeof e){case`string`:case`symbol`:case`number`:return!0}return!1}function a(e){return typeof e==`object`&&!!e}function o(e){if(!a(e))return!1;let t=Object.getPrototypeOf(e);if(t==null)return!0;let n=p(t,`constructor`)&&t.constructor;return typeof n==`function`&&n.toString()===zt}function s(e){let t=e?.constructor;return!!t&&(t.name===`GeneratorFunction`||t.displayName===`GeneratorFunction`)}function c(e,t,n){Ft(e,t,{enumerable:!1,writable:!0,configurable:!0,value:n})}function l(e,t){let n=`isMobX`+e;return t.prototype[n]=!0,function(e){return a(e)&&!0===e[n]}}function u(e){return e!=null&&Object.prototype.toString.call(e)===`[object Map]`}function d(e){return e!=null&&Object.prototype.toString.call(e)===`[object Set]`}function f(e){return e===null?null:typeof e==`object`?``+e:e}function p(e,t){return It.hasOwnProperty.call(e,t)}function m(e,t){return!!(e&t)}function h(e,t,n){return n?e|=t:e&=~t,e}function g(e,t=Bt,n=Bt){let r=new Ut(e);return t!==Bt&&(r.onBOL=new Set([t])),n!==Bt&&(r.onBUOL=new Set([n])),r}function _(e,t){return Ot(e,t)}function v(e,t,n){return e===null||typeof e!=`object`&&typeof e!=`function`||$e(e)?e:Array.isArray(e)?an.array(e,{name:n}):o(e)?an.object(e,void 0,{name:n}):u(e)?an.map(e,{name:n}):d(e)?an.set(e,{name:n}):typeof e!=`function`||He(e)||Xe(e)?e:s(e)?Un(e):Fn(n,e)}function y(e){return e}function b(e,t){return{t:e,i:t,o:x,u:S}}function x(e,t,n,r){var i;return(i=this.i)!=null&&i.bound?this.u(e,t,n,!1)===null?0:1:r===e.h?this.u(e,t,n,!1)===null?0:2:He(n.value)?1:(Ft(r,t,w(e,this,t,n,!1)),2)}function S(e,t,n,r){let i=w(e,this,t,n);return e.l(t,i,r)}function C(e,n,r){let{kind:i,name:a,addInitializer:o}=r,s=e,c=e=>{var t;return _e(s.i?.name??a.toString(),e,(t=s.i?.autoAction)!=null&&t)};return i==`field`?function(e){var t;let n=e;return He(n)||(n=c(n)),(t=s.i)!=null&&t.bound&&(n=n.bind(this),n.isMobxAction=!0),n}:i==`method`?(He(n)||(n=c(n)),(l=s.i)!=null&&l.bound&&o(function(){let e=this,t=e[a].bind(e);t.isMobxAction=!0,e[a]=t}),n):void t(43,s.t,String(a),i);var l}function w(e,t,n,r,i=F.safeDescriptors){var a,o,s;let{value:c}=r;return(a=t.i)!=null&&a.bound&&(c=c.bind(e.v??e.h)),{value:_e(t.i?.name??n.toString(),c,(o=t.i?.autoAction)!=null&&o,(s=t.i)!=null&&s.bound?e.v??e.h:void 0),configurable:!i||e.p,enumerable:!1,writable:!i}}function ee(e,t){return{t:e,i:t,o:te,u:ne}}function te(e,t,n,r){var i;return r===e.h?this.u(e,t,n,!1)===null?0:2:(i=this.i)!=null&&i.bound&&(!p(e.h,t)||!Xe(e.h[t]))&&this.u(e,t,n,!1)===null?0:Xe(n.value)?1:(Ft(r,t,re(e,0,0,n,!1,!1)),2)}function ne(e,t,n,r){let i=re(e,0,0,n,this.i?.bound);return e.l(t,i,r)}function T(e,t,n){var r;let{name:i,addInitializer:a}=n;return Xe(t)||(t=Un(t)),(r=e.i)!=null&&r.bound&&a(function(){let e=this,t=e[i].bind(e);t.isMobXFlow=!0,e[i]=t}),t}function re(e,t,n,r,i,a=F.safeDescriptors){let{value:o}=r;return Xe(o)||(o=Un(o)),i&&(o=o.bind(e.v??e.h),o.isMobXFlow=!0),{value:o,configurable:!a||e.p,enumerable:!1,writable:!a}}function E(e,t){return{t:e,i:t,o:D,u:ie}}function D(e,t,n){return this.u(e,t,n,!1)===null?0:1}function ie(e,t,n,r){return e.m(t,Nt({},this.i,{get:n.get,set:n.set}),r)}function O(e,t,n){function r(e){let n=Nt({},i.i,{get:t,context:e});return n.name||=`ObservableObject.${a.toString()}`,new _n(n)}let i=e,{name:a,addInitializer:o}=n,s;return o(function(){let e=xt(this)[M],n=this,i=e.j.get(a);i instanceof _n&&i.derivation!==t&&e.j.delete(a),(e.O??=new Map).set(a,()=>r(n))}),function(){let e=this[M],n=e.j.get(a);if(n instanceof _n&&n.derivation!==t){let e=s?.get(this);return e||(e=r(this),(s??=new WeakMap).set(this,e)),e.get()}return e._(a)}}function ae(e,t){return{t:e,i:t,o:oe,u:se}}function oe(e,t,n){return this.u(e,t,n,!1)===null?0:1}function se(e,t,n,r){return e.S(t,n.value,this.i?.A??v,r)}function ce(e,t,n){function r(e,t){let n=xt(e)[M];return(n.V??=new Map).set(o,()=>new hn(t,i.i?.A??v,`ObservableObject.${o.toString()}`,!1)),n}let i=e,{kind:a,name:o}=n;if(a===`accessor`)return{get(){return(this[M]??r(this,t.get.call(this)))._(o)},set(e){return(this[M]??r(this,e)).M(o,e)},init(e){return r(this,e),e}}}function le(e){return{t:Kt,i:e,o:ue,u:de}}function ue(e,t,n,r){var i,a,o;if(n.get)return ln.o(e,t,n,r);if(n.set){let i=He(n.set)?n.set:_e(t.toString(),n.set);return r===e.h?e.l(t,{configurable:!F.safeDescriptors||e.p,set:i})===null?0:2:(Ft(r,t,{configurable:!0,set:i}),2)}if(r!==e.h&&typeof n.value==`function`)return s(n.value)?((o=this.i)!=null&&o.autoBind?Wn:Un).o(e,t,n,r):((a=this.i)!=null&&a.autoBind?Ln:Fn).o(e,t,n,r);let c=!1===this.i?.deep?en:an;return typeof n.value==`function`&&(i=this.i)!=null&&i.autoBind&&(n.value=n.value.bind(e.v??e.h)),c.o(e,t,n,r)}function de(e,t,n,r){var i;return n.get?ln.u(e,t,n,r):n.set?e.l(t,{configurable:!F.safeDescriptors||e.p,set:_e(t.toString(),n.set)},r):(typeof n.value==`function`&&(i=this.i)!=null&&i.autoBind&&(n.value=n.value.bind(e.v??e.h)),(!1===this.i?.deep?en:an).u(e,t,n,r))}function fe(e,t){return Nt(function(n,r){if(r&&typeof r.kind==`string`)return t(e,n,r)},e)}function pe(e){return e||Jt}function me(e){return fe(e,ce)}function he(e){return!0===e.deep?v:!1===e.deep?y:(t=e.defaultDecorator)&&(n=(r=t.i)?.A)!=null?n:v;var t,n,r}function ge(e){return fe(e,O)}function _e(e,t,n=!1,r){function i(){return ve(0,n,t,r||this,arguments)}return i.isMobxAction=!0,i.toString=()=>t.toString(),pn&&(mn.value=e,Ft(i,`name`,mn)),i}function ve(e,t,n,r,i){let a=ye(0,t);try{return n.apply(r,i)}catch(e){throw a.N=e,e}finally{be(a)}}function ye(e,t){let n=F.trackingDerivation,r=!t||!n;Me();let i=F.allowStateChanges;r&&k();let a={R:r,k:n,C:i,I:F.allowStateReads,P:!1,T:0,B:fn++,D:dn};return dn=a.B,a}function be(e){dn!==e.B&&t(30),dn=e.D,e.N!==void 0&&(F.suppressReactionErrors=!0),Ne(),e.R&&De(e.k),F.suppressReactionErrors=!1}function xe(e,t){let n=function(e){let t=F.allowStateChanges;return F.allowStateChanges=e,t}(e);try{return t()}finally{(function(e){F.allowStateChanges=e})(n)}}function Se(e){return e instanceof yn}function Ce(e){switch(e.K){case 0:return!1;case-1:case 2:return!0;case 1:{let t=k(),n=e.L,r=n.length;for(let i=0;i<r;i++){let r=n[i];if(vn(r)){if(F.disableErrorBoundaries)r.get();else try{r.get()}catch{return De(t),!0}if(e.K===2)return De(t),!0}}return Oe(e),De(t),!1}}}function we(e,t,n){Oe(e),e.$=Array(e.U===0?100:e.L.length),e.W=0,e.U=++F.runId;let r=F.trackingDerivation,i;if(F.trackingDerivation=e,F.inBatch++,!0===F.disableErrorBoundaries)i=t.call(n);else try{i=t.call(n)}catch(e){i=new yn(e)}return F.inBatch--,F.trackingDerivation=r,function(e){let t=e.L,n=e.L=e.$,r=0,i=0,a=e.W;for(let e=0;e<a;e++){let t=n[e];t.diffValue===0&&(t.diffValue=1,i!==e&&(n[i]=t),i++),t.K>r&&(r=t.K)}for(n.length=i,e.$=null,a=t.length;a--;){let n=t[a];n.diffValue===0&&Ae(n,e),n.diffValue=0}for(;i--;){let t=n[i];t.diffValue===1&&(t.diffValue=0,ke(t,e))}r!==0&&(e.K=r,e.q())}(e),i}function Te(e){let t=e.L;e.L=[];let n=t.length;for(;n--;)Ae(t[n],e);e.K=-1}function Ee(e){let t=k();try{return e()}finally{De(t)}}function k(){let e=F.trackingDerivation;return F.trackingDerivation=null,e}function De(e){F.trackingDerivation=e}function Oe(e){if(e.K===0)return;e.K=0;let t=e.L,n=t.length;for(;n--;)t[n].F=0}function ke(e,t){(e.H??=new Set).add(t),e.F>t.K&&(e.F=t.K)}function Ae(e,t){let n=e.H;n&&(n.delete(t),n.size===0&&je(e))}function je(e){!1===e.isPendingUnobservation&&(e.isPendingUnobservation=!0,F.pendingUnobservations.push(e))}function Me(){F.inBatch++}function Ne(){--F.inBatch===0&&(Le(),!F.isRunningUnobservations&&F.pendingUnobservations.length>0&&function(){F.isRunningUnobservations=!0;try{let e=F.pendingUnobservations;for(let t=0;t<e.length;t++){let n=e[t];n.isPendingUnobservation=!1,n.H&&n.H.size!==0||(n.H=null,n.isBeingObserved&&(n.isBeingObserved=!1,n.onBUO()),n instanceof _n&&n.G())}F.pendingUnobservations=[]}finally{F.isRunningUnobservations=!1}}())}function Pe(e){var t;e.isBeingObserved||(e.isBeingObserved=!0,e.onBO(),(t=e.L)==null||t.forEach(Pe))}function Fe(e){let t=F.trackingDerivation;return t===null?((!e.H||e.H.size===0)&&F.inBatch>0&&je(e),!1):(t.U!==e.J&&(e.J=t.U,t.$[t.W++]=e,!e.isBeingObserved&&F.trackingContext&&(e.isBeingObserved=!0,e.onBO())),e.isBeingObserved)}function Ie(e){var t;e.F!==2&&(e.F=2,(t=e.H)==null||t.forEach(e=>{e.K===0&&e.q(),e.K=2}))}function Le(){F.inBatch>0||F.isRunningReactions||En(Re)}function Re(){F.isRunningReactions=!0;let e=F.pendingReactions,t=0;for(;e.length>0;){++t===Tn&&(console.error(`[mobx] cycle in reaction: ${e[0]}`),e.splice(0));let n=e.splice(0);for(let e=0,t=n.length;e<t;e++)n[e].X()}F.isRunningReactions=!1}function ze(e){return fe(e,C)}function Be(e){return function(t,n){return n&&typeof n.kind==`string`?C(e?Mn:An,t,n):r(t)?_e(t.name||`<unnamed action>`,t,e):r(n)?_e(t,n,e):i(t)?ze(b(e?kn:On,{name:t,autoAction:e})):void 0}}function Ve(e){return ve(0,!1,e,this,void 0)}function He(e){return r(e)&&!0===e.isMobxAction}function Ue(e,t=Rt){function n(){e(a)}var r;let i=t?.name??`Autorun`,a;if(t.scheduler||t.delay){let e=We(t),r=!1;a=new wn(i,()=>{r||(r=!0,e(()=>{r=!1,a.isDisposed||a.track(n)}))},t.onError,t.requiresObservable)}else a=new wn(i,function(){this.track(n)},t.onError,t.requiresObservable);return t!=null&&(r=t.signal)!=null&&r.aborted||a.Y(),a.Z(t?.signal)}function We(e){return e.scheduler?e.scheduler:e.delay?t=>setTimeout(t,e.delay):Rn}function Ge(e,t,n,i){let a=typeof i==`function`?wt(t,n):wt(t),o=r(i)?i:n,s=`${e}L`;return a[s]?a[s].add(o):a[s]=new Set([o]),function(){let e=a[s];e&&(e.delete(o),e.size===0&&delete a[s])}}function Ke(e,t,n,r){let i=Ht(t);return Dt(()=>{let t=xt(e,r)[M];Vt(i).forEach(e=>{t.u(e,i[e],!n||!(e in n)||n[e])})}),e}function qe(e){let t={name:e.tt};var n;return e.L&&e.L.length>0&&(t.dependencies=(n=e.L,Array.from(new Set(n))).map(qe)),t}function Je(e){let t={name:e.tt};return function(e){return!!e.H&&e.H.size>0}(e)&&(t.observers=Array.from(function(e){return e.H??new Set}(e),Je)),t}function Ye(e){r(e.cancel)&&e.cancel()}function Xe(e){return!0===e?.isMobXFlow}function Ze(e,t){var n;if(t===void 0)return vn(e);if(!1===Ct(e))return!1;let r=e[M];return(n=r.O)!=null&&n.has(t)?!0:r.j.has(t)?vn(wt(e,t)):!1}function Qe(e,t){if(!e)return!1;if(t!==void 0){if(Ct(e)){var n,r;let i=e[M];return i.j.has(t)||!((n=i.O)==null||!n.has(t))||!((r=i.V)==null||!r.has(t))}return!1}return Ct(e)||!!e[M]||Wt(e)||Dn(e)||vn(e)}function $e(e){return Qe(e)}function et(e){return Ct(e)?e[M].nt():nr(e)||I(e)?Array.from(e.keys()):vt(e)?e.map((e,t)=>t):void t(5)}function tt(e,n){return Ct(e)?e[M].et(n):nr(e)||I(e)?e.has(n):vt(e)?n>=0&&n<e.length:void t(10)}function nt(e){if(Ct(e))return e[M].it();t(38)}function rt(e,t,n){if(vn(e)){let r,i=!0;return Ue(()=>{let a=e.get();if(!i||n){let n=k();t({observableKind:`computed`,debugObjectName:e.tt,type:Jn,object:e,newValue:a,oldValue:r}),De(n)}i=!1,r=a})}return n&&t({observableKind:`value`,debugObjectName:e.tt,object:e,type:Jn,newValue:e.rt,oldValue:void 0}),ft(e,t)}function it(e,t,n){return e.set(t,n),n}function at(e,t){if(typeof e!=`object`||!e||e instanceof Date||!$e(e))return e;if(gn(e)||vn(e))return at(e.get(),t);if(t.has(e))return t.get(e);if(vt(e)){let n=it(t,e,Array(e.length));return e.forEach((e,r)=>{n[r]=at(e,t)}),n}if(I(e)){let n=it(t,e,new Set);return e.forEach(e=>{n.add(at(e,t))}),n}if(nr(e)){let n=it(t,e,new Map);return e.forEach((e,r)=>{n.set(r,at(e,t))}),n}{let n=it(t,e,{});return nt(e).forEach(r=>{It.propertyIsEnumerable.call(e,r)&&(n[r]=at(e[r],t))}),n}}function ot(e,t){Me();try{return e.apply(t)}finally{Ne()}}function st(e,t,n){let r;if(typeof n.timeout==`number`){let e=Error(`WHEN_TIMEOUT`);r=setTimeout(()=>{if(!a[M].isDisposed){if(a(),!n.onError)throw e;n.onError(e)}},n.timeout)}n.name=`When`;let i=_e(`When-effect`,t);var a=Ue(t=>{xe(!1,e)&&(t.dispose(),r&&clearTimeout(r),i())},n);return a}function ct(e){return e[M]}function lt(e){return e.st!==void 0&&e.st.length>0}function ut(e,t){let r=e.st;return r?r.push(t):r=e.st=[t],n(()=>{let e=r.indexOf(t);e!==-1&&r.splice(e,1)})}function A(e,n){let r=k();try{let r=[...e.st||[]];for(let e=0,i=r.length;e<i&&((n=r[e](n))&&!n.type&&t(14),n);e++);return n}finally{De(r)}}function dt(e){return e.ot!==void 0&&e.ot.length>0}function ft(e,t){let r=e.ot;return r?r.push(t):r=e.ot=[t],n(()=>{let e=r.indexOf(t);e!==-1&&r.splice(e,1)})}function pt(e,t){let n=k(),r=e.ot;if(r){r=r.slice();for(let e=0,n=r.length;e<n;e++)r[e](t);De(n)}}function mt(e,n,r){if(!0===r&&(r=e.ut),!1===r)return;n in e.h||t(1,r.t,`${e.tt}.${n.toString()}`);let i=e.h;for(;i&&i!==It;){let t=Pt(i,n);if(t){let a=r.o(e,n,t,i);if(a===0)return;if(a===1)break}i=Object.getPrototypeOf(i)}}function j(e,t){typeof Array.prototype[e]==`function`&&(Zn[e]=t(e))}function ht(e){return function(){let t=this[M];t.ct.reportObserved();let n=t.ht(t.j);return n[e].apply(n,arguments)}}function gt(e){return function(t,n){let r=this[M];return r.ct.reportObserved(),r.ht(r.j)[e]((e,r)=>t.call(n,e,r,this))}}function _t(e){return function(){let t=this[M];t.ct.reportObserved();let n=t.ht(t.j),r=arguments[0];return arguments[0]=(e,t,n)=>r(e,t,n,this),n[e].apply(n,arguments)}}function vt(e){return a(e)&&Qn(e[M])}function yt(e){return e[Symbol.toStringTag]=`MapIterator`,jt(e)}function bt(e){return e[Symbol.toStringTag]=`SetIterator`,jt(e)}function xt(e,t){if(p(e,M))return e;let n=t?.name??`ObservableObject`;return c(e,M,new sr(e,new Map,String(n),function(e){return e?e.defaultDecorator??function(e){let t=!1!==e.deep,n=!!e.autoBind,r=!t|(n?2:0);return P[r]??(P[r]=le({deep:t,autoBind:n}))}(e):void 0}(t))),e}function St(e){return ar[e]||(ar[e]={get(){return this[M]._(e)},set(t){return this[M].M(e,t)}})}function Ct(e){return!!a(e)&&cr(e[M])}function wt(e,n){if(typeof e==`object`&&e){if(vt(e))return n!==void 0&&t(23),e[M].ct;if(I(e))return e.ct;if(nr(e)){if(n===void 0)return e.lt;let r=e.ft.get(n)||e.dt.get(n);return r||t(25,n,Et(e)),r}if(Ct(e)){if(!n)return t(26);let r=e[M],i=r.j.get(n)??r.vt(n)??r.bt(n);return i||t(27,n,Et(e)),i}if(Wt(e)||vn(e)||Dn(e))return e}else if(r(e)&&Dn(e[M]))return e[M];t(28)}function Tt(e,n){return e||t(29),n===void 0?Wt(e)||vn(e)||Dn(e)||nr(e)||I(e)?e:e[M]?e[M]:void t(24,e):Tt(wt(e,n))}function Et(e,t){let n;if(t!==void 0)n=wt(e,t);else{if(He(e))return e.name;n=Ct(e)||nr(e)||I(e)?Tt(e):wt(e)}return n.tt}function Dt(e){let t=k();Me();try{return e()}finally{Ne(),De(t)}}function Ot(e,t,n=-1){return kt(e,t,n)}function kt(e,t,n,i,a){if(e===t)return e!==0||1/e==1/t;if(e==null||t==null)return!1;if(e!=e)return t!=t;let o=typeof e;if(o!==`function`&&o!==`object`&&typeof t!=`object`)return!1;let s=lr.call(e);if(s!==lr.call(t))return!1;switch(s){case`[object RegExp]`:case`[object String]`:return``+e==``+t;case`[object Number]`:return+e==+e?+e==0?1/e==1/t:+e==+t:+t!=+t;case`[object Date]`:case`[object Boolean]`:return+e==+t;case`[object Symbol]`:return typeof Symbol<`u`&&Symbol.valueOf.call(e)===Symbol.valueOf.call(t);case`[object Map]`:case`[object Set]`:n>=0&&n++}e=At(e),t=At(t);let c=s===`[object Array]`;if(!c){if(typeof e!=`object`||typeof t!=`object`)return!1;let n=e.constructor,i=t.constructor;if(n!==i&&!(r(n)&&n instanceof n&&r(i)&&i instanceof i)&&`constructor`in e&&`constructor`in t)return!1}if(n===0)return!1;n<0&&(n=-1),a||=[];let l=(i||=[]).length;for(;l--;)if(i[l]===e)return a[l]===t;if(i.push(e),a.push(t),c){if(l=e.length,l!==t.length)return!1;for(;l--;)if(!kt(e[l],t[l],n-1,i,a))return!1}else{let r=Object.keys(e),o=r.length;if(Object.keys(t).length!==o)return!1;for(let s=0;s<o;s++){let o=r[s];if(!p(t,o)||!kt(e[o],t[o],n-1,i,a))return!1}}return i.pop(),a.pop(),!0}function At(e){return vt(e)?e.slice():u(e)||nr(e)||d(e)||I(e)?Array.from(e.entries()):e}function jt(e){return e[Symbol.iterator]=Mt,Nt(Object.create(ur),e)}function Mt(){return this}Object.defineProperty(e,`__esModule`,{value:!0});let Nt=Object.assign,Pt=Object.getOwnPropertyDescriptor,Ft=Object.defineProperty,It=Object.prototype,Lt=[];Object.freeze(Lt);let Rt={};Object.freeze(Rt);let zt=Object.toString(),Bt=()=>{},Vt=Reflect.ownKeys,Ht=Object.getOwnPropertyDescriptors,M=Symbol(`mobx administration`);var Ut=class{constructor(e=`Atom`){this.tt=void 0,this.yt=0,this.H=null,this.J=0,this.F=-1,this.onBOL=void 0,this.onBUOL=void 0,this.tt=e}get isBeingObserved(){return m(this.yt,1)}set isBeingObserved(e){this.yt=h(this.yt,1,e)}get isPendingUnobservation(){return m(this.yt,2)}set isPendingUnobservation(e){this.yt=h(this.yt,2,e)}get diffValue(){return+!!m(this.yt,4)}set diffValue(e){this.yt=h(this.yt,4,e===1)}onBO(){this.onBOL&&this.onBOL.forEach(e=>e())}onBUO(){this.onBUOL&&this.onBUOL.forEach(e=>e())}reportObserved(){return Fe(this)}reportChanged(){Me(),Ie(this),Ne()}toString(){return this.tt}};let Wt=l(`Atom`,Ut),Gt=Object.is,N={t:`override`,o:function(){return 0},u:function(){t(44,this.t)}},Kt=`true`,qt=le(),P=[qt],Jt={deep:!0,name:void 0,defaultDecorator:void 0};Object.freeze(Jt);let Yt=ae(`observable`),Xt=ae(`observable.ref`,{A:y}),Zt=ae(`observable.shallow`,{A:function(e,t,n){return e==null||Ct(e)||vt(e)||nr(e)||I(e)?e:Array.isArray(e)?an.array(e,{name:n,deep:!1}):o(e)?an.object(e,void 0,{name:n,deep:!1}):u(e)?an.map(e,{name:n,deep:!1}):d(e)?an.set(e,{name:n,deep:!1}):void 0}}),Qt=ae(`observable.struct`,{A:function(e,t){return Ot(e,t)?t:e}}),$t={box(e,t){let n=pe(t);return new hn(e,he(n),n.name,!0,n.equals)},array(e,t){let n=pe(t);return function(e,t,n=`ObservableArray`,r=!1){return Dt(()=>{let i=new Xn(n,t,r);Ft(i.j,M,{enumerable:!1,writable:!1,configurable:!0,value:i});let a=new Proxy(i.j,Yn);return i.v=a,e&&e.length&&i.wt(0,0,e),a})}(e,he(n),n.name)},map(e,t){let n=pe(t);return new tr(e,he(n),n.name)},set(e,t){let n=pe(t);return new ir(e,he(n),n.name)},object:(e,t,n)=>Dt(()=>Ke(function(e,t){var n;return(n=(e=xt(e,t))[M]).v??(n.v=new Proxy(e,Gn))}({},n),e,t))},en=me(Xt),tn=me(Zt),nn=me(Yt),rn=me(Qt);var an=Nt(function(e,t,n){return t&&typeof t.kind==`string`?ce(Yt,e,t):$e(e)?e:o(e)?an.object(e,t,n):Array.isArray(e)?an.array(e,t):u(e)?an.map(e,t):d(e)?an.set(e,t):typeof e==`object`&&e?e:an.box(e,t)},Yt,$t);let on=`computed`,sn=E(on),cn=ge(E(`computed.struct`,{equals:_})),ln=function(e,t){if(t&&typeof t.kind==`string`)return O(sn,e,t);if(o(e))return ge(E(on,e));let n=o(t)?t:{};return n.get=e,n.name||=e.name||``,new _n(n)};var un;Nt(ln,sn);let dn=0,fn=1,pn=(un=Pt(()=>{},`name`)?.configurable)!=null&&un,mn={value:`action`,configurable:!0,writable:!1,enumerable:!1};var hn=class extends Ut{constructor(e,t,n=`ObservableValue`,r=!0,i=Gt){super(n),this.A=void 0,this.tt=void 0,this.xt=void 0,this.gt=!1,this.st=void 0,this.ot=void 0,this.rt=void 0,this.dehancer=void 0,this.A=t,this.tt=n,this.xt=i,this.rt=t(e,void 0,n)}dehanceValue(e){return this.dehancer===void 0?e:this.dehancer(e)}set(e){(e=this.jt(e))!==F.UNCHANGED&&this.Ot(e)}jt(e){if(lt(this)){let t=A(this,{object:this,type:Jn,newValue:e});if(!t)return F.UNCHANGED;e=t.newValue}return e=this.A(e,this.rt,this.tt),this.xt(this.rt,e)?F.UNCHANGED:e}Ot(e){let t=this.rt;this.rt=e,this.reportChanged(),dt(this)&&pt(this,{type:Jn,object:this,newValue:e,oldValue:t})}get(){return this.reportObserved(),this.dehanceValue(this.rt)}raw(){return this.rt}toJSON(){return this.get()}toString(){return`${this.tt}[${this.rt}]`}valueOf(){return f(this.get())}[Symbol.toPrimitive](){return this.valueOf()}};let gn=l(`ObservableValue`,hn);var _n=class{constructor(e){this.K=-1,this.L=[],this.$=null,this.H=null,this.U=0,this.J=0,this.F=0,this.W=0,this.rt=new yn(null),this.tt=void 0,this._t=void 0,this.yt=0,this.derivation=void 0,this.St=void 0,this.At=void 0,this.xt=void 0,this.Vt=void 0,this.Mt=void 0,this.onBOL=void 0,this.onBUOL=void 0,e.get||t(31),this.derivation=e.get,this.tt=e.name||`ComputedValue`,e.set&&(this.St=_e(`ComputedValue-setter`,e.set)),this.xt=e.equals||Gt,this.At=e.context,this.Vt=e.requiresReaction,this.Mt=!!e.keepAlive}q(){(function(e){var t;e.F===0&&(e.F=1,(t=e.H)==null||t.forEach(e=>{e.K===0&&(e.K=1,e.q())}))})(this)}onBO(){this.onBOL&&this.onBOL.forEach(e=>e())}onBUO(){this.onBUOL&&this.onBUOL.forEach(e=>e())}get isComputing(){return m(this.yt,1)}set isComputing(e){this.yt=h(this.yt,1,e)}get isRunningSetter(){return m(this.yt,2)}set isRunningSetter(e){this.yt=h(this.yt,2,e)}get isBeingObserved(){return m(this.yt,4)}set isBeingObserved(e){this.yt=h(this.yt,4,e)}get isPendingUnobservation(){return m(this.yt,8)}set isPendingUnobservation(e){this.yt=h(this.yt,8,e)}get diffValue(){return+!!m(this.yt,16)}set diffValue(e){this.yt=h(this.yt,16,e===1)}get(){if(this.isComputing&&t(32,this.tt,this.derivation),F.inBatch!==0||this.H&&this.H.size!==0||this.Mt){let e=this.isBeingObserved;if(Fe(this),Ce(this)){let e=F.trackingContext;e||!this.Mt&&!this.isBeingObserved||(F.trackingContext=this),this.trackAndCompute()&&function(e){var t;e.F!==2&&(e.F=2,(t=e.H)==null||t.forEach(t=>{t.K===1?t.K=2:t.K===0&&(e.F=0)}))}(this),F.trackingContext=e}else !e&&this.isBeingObserved&&this.L.forEach(Pe)}else Ce(this)&&(this.Nt(),Me(),this.rt=this.Rt(!1),Ne());let e=this.rt;if(Se(e))throw e.cause;return e}set(e){if(this.St){this.isRunningSetter&&t(33,this.tt),this.isRunningSetter=!0;try{this.St.call(this.At,e)}finally{this.isRunningSetter=!1}}else t(34,this.tt)}trackAndCompute(){let e=this.rt,t=this.K===-1,n=this.Rt(!0),r=t||Se(e)||Se(n)||!this.xt(e,n);return r&&(this.rt=n),r}Rt(e){let t;if(this.isComputing=!0,e)t=we(this,this.derivation,this.At);else if(!0===F.disableErrorBoundaries)t=this.derivation.call(this.At);else try{t=this.derivation.call(this.At)}catch(e){t=new yn(e)}return this.isComputing=!1,t}G(){this.Mt||(Te(this),this.rt=void 0)}Nt(){}toString(){return`${this.tt}[${this.derivation.toString()}]`}valueOf(){return f(this.get())}[Symbol.toPrimitive](){return this.valueOf()}};let vn=l(`ComputedValue`,_n);var yn=class{constructor(e){this.cause=void 0,this.cause=e}};let bn=[`mobxGuid`,`spyListeners`,`enforceActions`,`computedRequiresReaction`,`reactionRequiresObservable`,`observableRequiresReaction`,`allowStateReads`,`disableErrorBoundaries`,`runId`,`UNCHANGED`];var xn=class{constructor(){this.version=7,this.UNCHANGED={},this.trackingDerivation=null,this.trackingContext=null,this.runId=0,this.mobxGuid=0,this.inBatch=0,this.pendingUnobservations=[],this.pendingReactions=[],this.isRunningReactions=!1,this.isRunningUnobservations=!1,this.allowStateChanges=!1,this.allowStateReads=!0,this.enforceActions=!0,this.spyListeners=[],this.globalReactionErrorHandlers=[],this.computedRequiresReaction=!1,this.reactionRequiresObservable=!1,this.observableRequiresReaction=!1,this.disableErrorBoundaries=!1,this.suppressReactionErrors=!1,this.safeDescriptors=!0}};let Sn=!0,Cn=!1,F=function(){let e=globalThis;return e.__mobxInstanceCount>0&&!e.__mobxGlobals&&(Sn=!1),e.__mobxGlobals&&e.__mobxGlobals.version!==7&&(Sn=!1),Sn?e.__mobxGlobals?(e.__mobxInstanceCount+=1,e.__mobxGlobals.UNCHANGED||(e.__mobxGlobals.UNCHANGED={}),e.__mobxGlobals):(e.__mobxInstanceCount=1,e.__mobxGlobals=new xn):(setTimeout(()=>{Cn||t(35)},1),new xn)}();var wn=class{constructor(e=`Reaction`,t,n,r){this.tt=void 0,this.Et=void 0,this.kt=void 0,this.Ct=void 0,this.L=[],this.$=[],this.K=-1,this.U=0,this.W=0,this.yt=0,this.It=void 0,this.tt=e,this.Et=t,this.kt=n,this.Ct=r}get isDisposed(){return m(this.yt,1)}set isDisposed(e){this.yt=h(this.yt,1,e)}get isScheduled(){return m(this.yt,2)}set isScheduled(e){this.yt=h(this.yt,2,e)}get isTrackPending(){return m(this.yt,4)}set isTrackPending(e){this.yt=h(this.yt,4,e)}get isRunning(){return m(this.yt,8)}set isRunning(e){this.yt=h(this.yt,8,e)}get diffValue(){return+!!m(this.yt,16)}set diffValue(e){this.yt=h(this.yt,16,e===1)}q(){this.Y()}Y(){this.isScheduled||(this.isScheduled=!0,F.pendingReactions.push(this),Le())}X(){if(!this.isDisposed){Me(),this.isScheduled=!1;let e=F.trackingContext;if(F.trackingContext=this,Ce(this)){this.isTrackPending=!0;try{this.Et()}catch(e){this.Pt(e)}}F.trackingContext=e,Ne()}}track(e){if(this.isDisposed)return;Me(),this.isRunning=!0;let t=F.trackingContext;F.trackingContext=this;let n=we(this,e,void 0);F.trackingContext=t,this.isRunning=!1,this.isTrackPending=!1,this.isDisposed&&Te(this),Se(n)&&this.Pt(n.cause),Ne()}Pt(e){if(this.kt)this.kt(e,this);else{if(F.disableErrorBoundaries)throw e;F.suppressReactionErrors||console.error(`[mobx] uncaught error in '${this}'`,e),F.globalReactionErrorHandlers.forEach(t=>t(e,this))}}dispose(){var e;this.isDisposed||(this.isDisposed=!0,(e=this.It)==null||e.call(this),this.isRunning||(Me(),Te(this),Ne()))}Z(e){let t=()=>this.dispose();return e!=null&&e.addEventListener&&!this.isDisposed&&(e.addEventListener(`abort`,t),this.It=()=>e.removeEventListener==null?void 0:e.removeEventListener(`abort`,t)),t[M]=this,`dispose`in Symbol&&typeof Symbol.dispose==`symbol`&&(t[Symbol.dispose]=t),t}toString(){return`Reaction[${this.tt}]`}};let Tn=100,En=e=>e(),Dn=l(`Reaction`,wn),On=`action`,kn=`autoAction`,An=b(On),jn=b(`action.bound`,{bound:!0}),Mn=b(kn,{autoAction:!0}),Nn=b(`autoAction.bound`,{autoAction:!0,bound:!0}),Pn=Be(!1);Nt(Pn,An);let Fn=Be(!0);Nt(Fn,Mn);let In=ze(jn),Ln=ze(Nn),Rn=e=>e(),zn=`always`;var Bn=class extends Error{constructor(){super(`FLOW_CANCELLED`),Object.setPrototypeOf(this,new.target.prototype),this.name=`FlowCancellationError`}toString(){return`Error: ${this.message}`}};let Vn=ee(`flow`),Hn=ee(`flow.bound`,{bound:!0}),Un=Nt(function(e,t){if(t&&typeof t.kind==`string`)return T(Vn,e,t);let n=e,i=n.name||`flow`,a=function(){let e=arguments,t=Pn(i,n).apply(this,e),a,o,s=new Promise(function(e,n){function s(e){let r;o=void 0;try{r=Pn(i,t.next).call(t,e)}catch(e){return n(e)}l(r)}function c(e){let r;o=void 0;try{r=Pn(i,t.throw).call(t,e)}catch(e){return n(e)}l(r)}function l(t){if(!r(t?.then))return t.done?e(t.value):(o=Promise.resolve(t.value),o.then(s,c));t.then(l,n)}a=n,s(void 0)});return s.cancel=Pn(i,function(){try{o&&Ye(o);let e=t.return(void 0),n=Promise.resolve(e.value);n.then(Bt,Bt),Ye(n),a(new Bn)}catch(e){a(e)}}),s};return a.isMobXFlow=!0,a},Vn),Wn=fe(Hn,T),Gn={has:(e,t)=>ct(e).et(t),get:(e,t)=>ct(e).Tt(t),set(e,t,n){var r;return!!i(t)&&((r=ct(e).Bt(t,n,!0))==null||r)},deleteProperty(e,t){var n;return!!i(t)&&((n=ct(e).Dt(t,!0))==null||n)},defineProperty(e,t,n){var r;return(r=ct(e).l(t,n))==null||r},ownKeys:e=>ct(e).it(),preventExtensions(e){t(13)}},Kn=Symbol(`mobx-keys`),qn=`splice`,Jn=`update`,Yn={get(e,t){let n=e[M];return t===M?n:t===`length`?n.Kt():typeof t!=`string`||isNaN(t)?p(Zn,t)?Zn[t]:e[t]:n.Tt(parseInt(t))},set(e,t,n){let r=e[M];return t===`length`?r.Lt(n):typeof t==`symbol`||isNaN(t)?e[t]=n:r.Bt(parseInt(t),n),!0},preventExtensions(){t(15)}};var Xn=class{constructor(e=`ObservableArray`,t,n){this.$t=void 0,this.ct=void 0,this.j=[],this.st=void 0,this.ot=void 0,this.A=void 0,this.dehancer=void 0,this.v=void 0,this.Ut=0,this.$t=n,this.ct=new Ut(e),this.A=(e,n)=>t(e,n,`ObservableArray[..]`)}Wt(e){return this.dehancer===void 0?e:this.dehancer(e)}ht(e){return this.dehancer!==void 0&&e.length>0?e.map(this.dehancer):e}Kt(){return this.ct.reportObserved(),this.j.length}Lt(e){(!Number.isInteger(e)||e<0)&&t(40,e);let n=this.j.length;if(e!==n)if(e>n){let t=Array.from({length:e-n});this.wt(n,0,t)}else this.wt(e,n-e)}zt(e,n){e!==this.Ut&&t(16),this.Ut+=n}wt(e,t,n){let r=this.j.length;if(e===void 0?e=0:e>r?e=r:e<0&&(e=Math.max(0,r+e)),t=arguments.length===1?r-e:t==null?0:Math.max(0,Math.min(t,r-e)),n===void 0&&(n=Lt),lt(this)){let r=A(this,{object:this.v,type:qn,index:e,removedCount:t,added:n});if(!r)return Lt;t=r.removedCount,n=r.added}n=n.length===0?n:n.map(e=>this.A(e,void 0));let i=this.qt(e,t,n);return t===0&&n.length===0||this.Ft(e,n,i),this.ht(i)}qt(e,t,n){if(n.length<1e4)return this.j.splice(e,t,...n);{let r=this.j.slice(e,e+t),i=this.j.slice(e+t);this.j.length+=n.length-t;for(let t=0;t<n.length;t++)this.j[e+t]=n[t];for(let t=0;t<i.length;t++)this.j[e+n.length+t]=i[t];return r}}Ht(e,t,n){let r=dt(this),i=r?{observableKind:`array`,object:this.v,type:Jn,debugObjectName:this.ct.tt,index:e,newValue:t,oldValue:n}:null;this.ct.reportChanged(),r&&pt(this,i)}Ft(e,t,n){let r=dt(this),i=r?{observableKind:`array`,object:this.v,debugObjectName:this.ct.tt,type:qn,index:e,removed:n,added:t,removedCount:n.length,addedCount:t.length}:null;this.ct.reportChanged(),r&&pt(this,i)}Tt(e){return this.ct.reportObserved(),this.Wt(this.j[e])}Bt(e,t){let n=this.j;if(e<n.length){let r=n[e];if(lt(this)){let n=A(this,{type:Jn,object:this.v,index:e,newValue:t});if(!n)return;t=n.newValue}(t=this.A(t,r))!==r&&(n[e]=t,this.Ht(e,t,r))}else{let r=Array.from({length:e+1-n.length});r[r.length-1]=t,this.wt(n.length,0,r)}}},Zn={clear(){return this.splice(0)},replace(e){let t=this[M];return t.wt(0,t.j.length,e)},toJSON(){return this.slice()},splice(e,t,...n){let r=this[M];switch(arguments.length){case 0:return[];case 1:return r.wt(e);case 2:return r.wt(e,t)}return r.wt(e,t,n)},spliceWithArray(e,t,n){return this[M].wt(e,t,n)},push(...e){let t=this[M];return t.wt(t.j.length,0,e),t.j.length},pop(){return this.splice(Math.max(this[M].j.length-1,0),1)[0]},shift(){return this.splice(0,1)[0]},unshift(...e){let t=this[M];return t.wt(0,0,e),t.j.length},reverse(){return F.trackingDerivation&&t(37,`reverse`),this.replace(this.slice().reverse()),this},sort(){F.trackingDerivation&&t(37,`sort`);let e=this.slice();return e.sort.apply(e,arguments),this.replace(e),this},remove(e){let t=this[M],n=t.ht(t.j).indexOf(e);return n>-1&&(this.splice(n,1),!0)}};j(`at`,ht),j(`concat`,ht),j(`flat`,ht),j(`includes`,ht),j(`indexOf`,ht),j(`join`,ht),j(`lastIndexOf`,ht),j(`slice`,ht),j(`toString`,ht),j(`toLocaleString`,ht),j(`toSorted`,ht),j(`toSpliced`,ht),j(`with`,ht),j(`every`,gt),j(`filter`,gt),j(`find`,gt),j(`findIndex`,gt),j(`findLast`,gt),j(`findLastIndex`,gt),j(`flatMap`,gt),j(`forEach`,gt),j(`map`,gt),j(`some`,gt),j(`toReversed`,gt),j(`reduce`,_t),j(`reduceRight`,_t);let Qn=l(`ObservableArrayAdministration`,Xn),$n={},er=`delete`;var tr=class{constructor(e,t=v,n=`ObservableMap`){this.A=void 0,this.tt=void 0,this[M]=$n,this.ft=void 0,this.dt=void 0,this.lt=void 0,this.st=void 0,this.ot=void 0,this.dehancer=void 0,this.A=t,this.tt=n,Dt(()=>{this.lt=g(`ObservableMap.keys()`),this.ft=new Map,this.dt=new Map,e&&this.merge(e)})}et(e){return this.ft.has(e)}has(e){if(!F.trackingDerivation)return this.et(e);let t=this.dt.get(e);if(!t){let n=t=new hn(this.et(e),y,`ObservableMap.key?`,!1);this.dt.set(e,n),n.onBUOL=new Set([()=>this.dt.delete(e)])}return t.get()}set(e,t){let n=this.et(e);if(lt(this)){let r=A(this,{type:n?Jn:`add`,object:this,newValue:t,name:e});if(!r)return this;t=r.newValue}return n?this.Gt(e,t):this.Jt(e,t),this}delete(e){if(lt(this)&&!A(this,{type:er,object:this,name:e}))return!1;if(this.et(e)){let t=dt(this),n=t?{observableKind:`map`,debugObjectName:this.tt,type:er,object:this,oldValue:this.ft.get(e).rt,name:e}:null;return ot(()=>{var t;this.lt.reportChanged(),(t=this.dt.get(e))==null||t.Ot(!1),this.ft.get(e).Ot(void 0),this.ft.delete(e)}),t&&pt(this,n),!0}return!1}Gt(e,t){let n=this.ft.get(e);if((t=n.jt(t))!==F.UNCHANGED){let r=dt(this),i=r?{observableKind:`map`,debugObjectName:this.tt,type:Jn,object:this,oldValue:n.rt,name:e,newValue:t}:null;n.Ot(t),r&&pt(this,i)}}Jt(e,t){ot(()=>{var n;let r=new hn(t,this.A,`ObservableMap.key`,!1);this.ft.set(e,r),t=r.rt,(n=this.dt.get(e))==null||n.Ot(!0),this.lt.reportChanged()});let n=dt(this);n&&pt(this,n?{observableKind:`map`,debugObjectName:this.tt,type:`add`,object:this,name:e,newValue:t}:null)}get(e){return this.has(e)?this.Wt(this.ft.get(e).get()):this.Wt(void 0)}getOrInsert(e,t){return this.has(e)||this.set(e,t),this.get(e)}getOrInsertComputed(e,t){return this.has(e)||this.set(e,t(e)),this.get(e)}Wt(e){return this.dehancer===void 0?e:this.dehancer(e)}keys(){return this.lt.reportObserved(),this.ft.keys()}values(){let e=this,t=this.keys();return yt({next(){let{done:n,value:r}=t.next();return{done:n,value:n?void 0:e.get(r)}}})}entries(){let e=this,t=this.keys();return yt({next(){let{done:n,value:r}=t.next();return{done:n,value:n?void 0:[r,e.get(r)]}}})}[Symbol.iterator](){return this.entries()}forEach(e,t){for(let[n,r]of this)e.call(t,r,n,this)}merge(e){return nr(e)&&(e=new Map(e)),ot(()=>{o(e)?function(e){let t=Object.keys(e),n=Object.getOwnPropertySymbols(e);return n.length?[...t,...n.filter(t=>It.propertyIsEnumerable.call(e,t))]:t}(e).forEach(t=>this.set(t,e[t])):Array.isArray(e)?e.forEach(([e,t])=>this.set(e,t)):u(e)?(function(e){return Object.getPrototypeOf(Object.getPrototypeOf(Object.getPrototypeOf(e)))===null}(e)||t(19,e),e.forEach((e,t)=>this.set(t,e))):e!=null&&t(20,e)}),this}clear(){ot(()=>{Ee(()=>{for(let e of this.keys())this.delete(e)})})}replace(e){return ot(()=>{let n=function(e){if(u(e)||nr(e))return e;if(Array.isArray(e))return new Map(e);if(o(e)){let t=new Map;for(let n in e)t.set(n,e[n]);return t}return t(21,e)}(e),r=new Map,i=!1;for(let e of this.ft.keys())if(!n.has(e))if(this.delete(e))i=!0;else{let t=this.ft.get(e);r.set(e,t)}for(let[e,t]of n.entries()){let n=this.ft.has(e);if(this.set(e,t),this.ft.has(e)){let t=this.ft.get(e);r.set(e,t),n||(i=!0)}}if(!i)if(this.ft.size!==r.size)this.lt.reportChanged();else{let e=this.ft.keys(),t=r.keys(),n=e.next(),i=t.next();for(;!n.done;){if(n.value!==i.value){this.lt.reportChanged();break}n=e.next(),i=t.next()}}this.ft=r}),this}get size(){return this.lt.reportObserved(),this.ft.size}toString(){return`[object ObservableMap]`}toJSON(){return Array.from(this)}get[Symbol.toStringTag](){return`Map`}},nr=l(`ObservableMap`,tr);let rr={};var ir=class{constructor(e,t=v,n=`ObservableSet`){this.tt=void 0,this[M]=rr,this.ft=new Set,this.ct=void 0,this.ot=void 0,this.st=void 0,this.dehancer=void 0,this.A=void 0,this.tt=n,this.A=(e,r)=>t(e,r,n),Dt(()=>{this.ct=g(this.tt),e&&this.replace(e)})}Wt(e){return this.dehancer===void 0?e:this.dehancer(e)}clear(){ot(()=>{Ee(()=>{for(let e of this.ft.values())this.delete(e)})})}forEach(e,t){for(let n of this)e.call(t,n,n,this)}get size(){return this.ct.reportObserved(),this.ft.size}add(e){if(lt(this)){let t=A(this,{type:`add`,object:this,newValue:e});if(!t)return this;e=t.newValue}if(!this.has(e)){ot(()=>{e=this.A(e,void 0),this.ft.add(e),this.ct.reportChanged()});let t=dt(this);t&&pt(this,t?{observableKind:`set`,debugObjectName:this.tt,type:`add`,object:this,newValue:e}:null)}return this}delete(e){if(lt(this)&&!A(this,{type:er,object:this,oldValue:e}))return!1;if(this.has(e)){let t=dt(this),n=t?{observableKind:`set`,debugObjectName:this.tt,type:er,object:this,oldValue:e}:null;return ot(()=>{this.ct.reportChanged(),this.ft.delete(e)}),t&&pt(this,n),!0}return!1}has(e){return this.ct.reportObserved(),this.ft.has(this.Wt(e))}entries(){let e=this.values();return bt({next(){let{value:t,done:n}=e.next();return n?{value:void 0,done:n}:{value:[t,t],done:n}}})}keys(){return this.values()}values(){this.ct.reportObserved();let e=this,t=this.ft.values();return bt({next(){let{value:n,done:r}=t.next();return r?{value:void 0,done:r}:{value:e.Wt(n),done:r}}})}intersection(e){return new Set(this).intersection(e)}union(e){return new Set(this).union(e)}difference(e){return new Set(this).difference(e)}symmetricDifference(e){return new Set(this).symmetricDifference(e)}isSubsetOf(e){return new Set(this).isSubsetOf(e)}isSupersetOf(e){return new Set(this).isSupersetOf(e)}isDisjointFrom(e){return new Set(this).isDisjointFrom(e)}replace(e){return I(e)&&(e=new Set(e)),Array.isArray(e)||d(e)?ot(()=>{let t=d(e)?e:new Set(e);if(t.size!==0)if(this.ft.size!==0){for(let e of this.ft.values())t.has(this.Wt(e))||this.delete(e);t.forEach(e=>this.add(e))}else t.forEach(e=>this.add(e));else this.clear()}):e!=null&&t(41,e),this}toJSON(){return Array.from(this)}toString(){return`[object ObservableSet]`}[Symbol.iterator](){return this.values()}get[Symbol.toStringTag](){return`Set`}},I=l(`ObservableSet`,ir);let ar=Object.create(null),or=`remove`;var sr=class{constructor(e,t=new Map,n,r=qt){this.h=void 0,this.j=void 0,this.tt=void 0,this.ut=void 0,this.lt=void 0,this.ot=void 0,this.st=void 0,this.v=void 0,this.p=void 0,this.Xt=void 0,this.Qt=void 0,this.O=void 0,this.V=void 0,this.h=e,this.j=t,this.tt=n,this.ut=r,this.lt=new Ut(`ObservableObject.keys`),this.p=o(this.h)}_(e){return(this.j.get(e)??this.vt(e)??this.bt(e)).get()}vt(e){let t=this.O?.get(e);if(!t)return;this.O.delete(e),this.O.size===0&&(this.O=void 0);let n=t();return this.j.set(e,n),n}bt(e){let t=this.V?.get(e);if(!t)return;this.V.delete(e),this.V.size===0&&(this.V=void 0);let n=t();return this.j.set(e,n),n}M(e,t){let n=this.j.get(e)??this.vt(e)??this.bt(e);if(n instanceof _n)return n.set(t),!0;if(lt(this)){let n=A(this,{type:Jn,object:this.v||this.h,name:e,newValue:t});if(!n)return null;t=n.newValue}if((t=n.jt(t))!==F.UNCHANGED){let r=dt(this),i=r?{type:Jn,observableKind:`object`,debugObjectName:this.tt,object:this.v||this.h,oldValue:n.rt,name:e,newValue:t}:null;n.Ot(t),r&&pt(this,i)}return!0}Tt(e){return F.trackingDerivation&&!p(this.h,e)&&this.et(e),this.h[e]}Bt(e,t,n=!1){return p(this.h,e)?this.j.has(e)?this.M(e,t):n?Reflect.set(this.h,e,t):(this.h[e]=t,!0):this.u(e,{value:t,enumerable:!0,writable:!0,configurable:!0},this.ut,n)}et(e){if(!F.trackingDerivation)return e in this.h;this.Qt||=new Map;let t=this.Qt.get(e);return t||(t=new hn(e in this.h,y,`ObservableObject.key?`,!1),this.Qt.set(e,t)),t.get()}u(e,t,n,r=!1){return!0===n&&(n=this.ut),!1===n?this.l(e,t,r):n.u(this,e,t,r)}l(e,t,n=!1){try{Me();let r=this.Dt(e);if(!r)return r;if(lt(this)){let n=A(this,{object:this.v||this.h,name:e,type:`add`,newValue:t.value});if(!n)return null;let{newValue:r}=n;t.value!==r&&(t=Nt({},t,{value:r}))}if(n){if(!Reflect.defineProperty(this.h,e,t))return!1}else Ft(this.h,e,t);this.Yt(e,t.value)}finally{Ne()}return!0}S(e,t,n,r=!1){try{Me();let i=this.Dt(e);if(!i)return i;if(lt(this)){let n=A(this,{object:this.v||this.h,name:e,type:`add`,newValue:t});if(!n)return null;t=n.newValue}let a=St(e),o={configurable:!F.safeDescriptors||this.p,enumerable:!0,get:a.get,set:a.set};if(r){if(!Reflect.defineProperty(this.h,e,o))return!1}else Ft(this.h,e,o);let s=new hn(t,n,`ObservableObject.key`,!1);this.j.set(e,s),this.Yt(e,s.rt)}finally{Ne()}return!0}m(e,t,n=!1){try{Me();let r=this.Dt(e);if(!r)return r;if(lt(this)&&!A(this,{object:this.v||this.h,name:e,type:`add`,newValue:void 0}))return null;t.name||=`ObservableObject.key`,t.context=this.v||this.h;let i=St(e),a={configurable:!F.safeDescriptors||this.p,enumerable:!1,get:i.get,set:i.set};if(n){if(!Reflect.defineProperty(this.h,e,a))return!1}else Ft(this.h,e,a);this.j.set(e,new _n(t)),this.Yt(e,void 0)}finally{Ne()}return!0}Dt(e,t=!1){if(!p(this.h,e))return!0;if(lt(this)&&!A(this,{object:this.v||this.h,name:e,type:or}))return null;try{var n;Me();let r=dt(this),i=this.j.get(e),a;if(i||!r||(a=Pt(this.h,e)?.value),t){if(!Reflect.deleteProperty(this.h,e))return!1}else delete this.h[e];i&&(this.j.delete(e),i instanceof hn&&(a=i.rt),Ie(i)),this.lt.reportChanged(),(n=this.Qt)==null||(n=n.get(e))==null||n.set(e in this.h),r&&r&&pt(this,{type:or,observableKind:`object`,object:this.v||this.h,debugObjectName:this.tt,oldValue:a,name:e})}finally{Ne()}return!0}Yt(e,t){var n;let r=dt(this);r&&r&&pt(this,r?{type:`add`,observableKind:`object`,debugObjectName:this.tt,object:this.v||this.h,name:e,newValue:t}:null),(n=this.Qt)==null||(n=n.get(e))==null||n.set(!0),this.lt.reportChanged()}it(){return this.lt.reportObserved(),Vt(this.h)}nt(){return this.lt.reportObserved(),Object.keys(this.h)}};let cr=l(`ObservableObjectAdministration`,sr),lr=It.toString,ur=globalThis.Iterator?.prototype||{};e.$mobx=M,e.FlowCancellationError=Bn,e.ObservableMap=tr,e.ObservableSet=ir,e.Reaction=wn,e._allowStateChanges=xe,e._allowStateChangesInsideComputed=Ve,e._allowStateReadsEnd=function(e){F.allowStateReads=e},e._allowStateReadsStart=function(e){let t=F.allowStateReads;return F.allowStateReads=e,t},e._autoAction=Fn,e._autoActionBound=Ln,e._endAction=be,e._getAdministration=Tt,e._getGlobalState=function(){return F},e._interceptReads=function(e,t,n){let r;return nr(e)||vt(e)||gn(e)?r=Tt(e):Ct(e)&&(r=Tt(e,t)),r.dehancer=typeof t==`function`?t:n,()=>{r.dehancer=void 0}},e._isComputingDerivation=function(){return F.trackingDerivation!==null},e._resetGlobalState=function(){let e=new xn;for(let t in e)bn.indexOf(t)===-1&&(F[t]=e[t]);F.allowStateChanges=!F.enforceActions},e._startAction=ye,e.action=Pn,e.actionBound=In,e.autorun=Ue,e.compareDefault=Gt,e.compareIdentity=function(e,t){return e===t},e.compareShallow=function(e,t){return Ot(e,t,1)},e.compareStructural=_,e.computed=ln,e.computedStruct=cn,e.configure=function(e){!0===e.isolateGlobalState&&function(){if((F.pendingReactions.length||F.inBatch||F.isRunningReactions)&&t(36),Cn=!0,Sn){let e=globalThis;--e.__mobxInstanceCount===0&&(e.__mobxGlobals=void 0),F=new xn}}();let{enforceActions:n}=e;if(n!==void 0){let e=n===zn?zn:n===`observed`;F.enforceActions=e,F.allowStateChanges=!0!==e&&e!==zn}[`computedRequiresReaction`,`reactionRequiresObservable`,`observableRequiresReaction`,`disableErrorBoundaries`,`safeDescriptors`].forEach(t=>{t in e&&(F[t]=!!e[t])}),F.allowStateReads=!F.observableRequiresReaction,e.reactionScheduler&&function(e){let t=En;En=n=>e(()=>t(n))}(e.reactionScheduler)},e.createAtom=g,e.defineProperty=function(e,n,r){if(Ct(e))return e[M].l(n,r);t(39)},e.entries=function(e){return Ct(e)?et(e).map(t=>[t,e[t]]):nr(e)?et(e).map(t=>[t,e.get(t)]):I(e)?Array.from(e.entries()):vt(e)?e.map((e,t)=>[t,e]):void t(7)},e.extendObservable=Ke,e.flow=Un,e.flowBound=Wn,e.flowResult=function(e){return e},e.get=function(e,n){if(tt(e,n))return Ct(e)?e[M].Tt(n):nr(e)?e.get(n):vt(e)?e[n]:void t(11)},e.getAtom=wt,e.getDebugName=Et,e.getDependencyTree=function(e,t){return qe(wt(e,t))},e.getObserverTree=function(e,t){return Je(wt(e,t))},e.has=tt,e.intercept=function(e,t,n){return r(n)?function(e,t,n){return ut(Tt(e,t),n)}(e,t,n):function(e,t){return ut(Tt(e),t)}(e,t)},e.isAction=He,e.isBoxedObservable=gn,e.isComputed=function(e){return Ze(e)},e.isComputedProp=function(e,t){return Ze(e,t)},e.isFlow=Xe,e.isFlowCancellationError=function(e){return e instanceof Bn},e.isObservable=$e,e.isObservableArray=vt,e.isObservableMap=nr,e.isObservableObject=Ct,e.isObservableProp=function(e,t){return Qe(e,t)},e.isObservableSet=I,e.keys=et,e.makeAutoObservable=function(e,t,n){return o(e)?Ke(e,e,t,n):(Dt(()=>{let r=xt(e,n)[M];if(!e[Kn]){let t=Object.getPrototypeOf(e),n=new Set([...Vt(e),...Vt(t)]);n.delete(`constructor`),n.delete(M),c(t,Kn,n)}e[Kn].forEach(e=>mt(r,e,!t||!(e in t)||t[e]))}),e)},e.makeObservable=function(e,t,n){return Dt(()=>{let r=xt(e,n)[M];Vt(t).forEach(e=>mt(r,e,t[e]))}),e},e.observable=an,e.observableDeep=nn,e.observableRef=en,e.observableShallow=tn,e.observableStruct=rn,e.observe=function(e,t,n,i){return r(n)?function(e,t,n,r){return rt(Tt(e,t),n,r)}(e,t,n,i):function(e,t,n){let r=Tt(e);if(vt(e))n&&t({observableKind:`array`,object:r.v,debugObjectName:r.ct.tt,type:`splice`,index:0,added:r.j.slice(),addedCount:r.j.length,removed:[],removedCount:0});else if(!nr(e)&&!I(e)&&!Ct(e))return rt(r,t,n);return ft(r,t)}(e,t,n)},e.onBecomeObserved=function(e,t,n){return Ge(`onBO`,e,t,n)},e.onBecomeUnobserved=function(e,t,n){return Ge(`onBUO`,e,t,n)},e.onReactionError=function(e){return F.globalReactionErrorHandlers.push(e),()=>{let t=F.globalReactionErrorHandlers.indexOf(e);t>=0&&F.globalReactionErrorHandlers.splice(t,1)}},e.override=N,e.ownKeys=nt,e.reaction=function(e,t,n=Rt){function r(){if(p=!1,h.isDisposed)return;let t=!1,r=d;h.track(()=>{let n=xe(!1,()=>e(h));t=f||!m(d,n),d=n}),(f&&n.fireImmediately||!f&&t)&&o(d,r,h),f=!1}var i;let a=n.name??`Reaction`,o=Pn(a,n.onError?(s=n.onError,c=t,function(){try{return c.apply(this,arguments)}catch(e){s.call(this,e)}}):t);var s,c;let l=!n.scheduler&&!n.delay,u=We(n),d,f=!0,p=!1,m=n.equals||Gt,h=new wn(a,()=>{f||l?r():p||(p=!0,u(r))},n.onError,n.requiresObservable);return n!=null&&(i=n.signal)!=null&&i.aborted||h.Y(),h.Z(n?.signal)},e.remove=function(e,n){Ct(e)?e[M].Dt(n):nr(e)||I(e)?e.delete(n):vt(e)?(typeof n!=`number`&&(n=parseInt(n,10)),e.splice(n,1)):t(9)},e.runInAction=Ve,e.set=function e(n,r,i){if(arguments.length===2&&!I(n)){Me();let t=r;try{for(let r in t)e(n,r,t[r])}finally{Ne()}return}Ct(n)?n[M].Bt(r,i):nr(n)?n.set(r,i):I(n)?n.add(r):vt(n)?(typeof r!=`number`&&(r=parseInt(r,10)),r<0&&t(42,r),Me(),r>=n.length&&(n.length=r+1),n[r]=i,Ne()):t(8)},e.spy=function(){return console.warn(`[mobx.spy] Is a no-op in production builds`),function(){}},e.toJS=function(e){return at(e,new Map)},e.transaction=ot,e.untracked=Ee,e.values=function(e){return Ct(e)?et(e).map(t=>e[t]):nr(e)?et(e).map(t=>e.get(t)):I(e)?Array.from(e.values()):vt(e)?e.slice():void t(6)},e.when=function(e,t,n){return arguments.length===1||t&&typeof t==`object`?function(e,t){var n;if(t!=null&&(n=t.signal)!=null&&n.aborted)return Nt(Promise.reject(Error(`WHEN_ABORTED`)),{cancel:()=>null});let r,i,a=new Promise((n,a)=>{var o;let s=st(e,n,Nt({},t,{onError:a}));r=()=>{s(),a(Error(`WHEN_CANCELLED`))},i=()=>{s(),a(Error(`WHEN_ABORTED`))},t==null||(o=t.signal)==null||o.addEventListener==null||o.addEventListener(`abort`,i)}).finally(()=>{var e;return t==null||(e=t.signal)==null||e.removeEventListener==null?void 0:e.removeEventListener(`abort`,i)});return a.cancel=r,a}(e,t):st(e,t,n||{})}})),Cv=we((e=>{Object.defineProperty(e,`__esModule`,{value:!0});let t={0:`Invalid value for configuration 'enforceActions', expected 'never', 'always' or 'observed'`,1(e,t){return`Cannot apply '${e}' to '${t.toString()}': Field not found.`},5:`'keys()' can only be used on observable objects, arrays, sets and maps`,6:`'values()' can only be used on observable objects, arrays, sets and maps`,7:`'entries()' can only be used on observable objects, arrays and maps`,8:`'set()' can only be used on observable objects, arrays and maps`,9:`'remove()' can only be used on observable objects, arrays and maps`,10:`'has()' can only be used on observable objects, arrays and maps`,11:`'get()' can only be used on observable objects, arrays and maps`,12:`Invalid annotation`,13:`Dynamic observable objects cannot be frozen. If you're passing observables to 3rd party component/function that calls Object.freeze, pass copy instead: toJS(observable)`,14:`Intercept handlers should return nothing or a change object`,15:`Observable arrays cannot be frozen. If you're passing observables to 3rd party component/function that calls Object.freeze, pass copy instead: toJS(observable)`,16:`Modification exception: the internal structure of an observable array was changed.`,19(e){return`Cannot initialize from classes that inherit from Map: `+e.constructor.name},20(e){return`Cannot initialize map from `+e},21(e){return`Cannot convert to map from '${e}'`},23:`It is not possible to get index atoms from arrays`,24(e){return`Cannot obtain administration from `+e},25(e,t){return`the entry '${e}' does not exist in the observable map '${t}'`},26:`please specify a property`,27(e,t){return`no observable property '${e.toString()}' found on the observable object '${t}'`},28(e){return`Cannot obtain atom from `+e},29:`Expecting some object`,30:`invalid action stack. did you forget to finish an action?`,31:`missing option for computed: get`,32(e,t){return`Cycle detected in computation ${e}: ${t}`},33(e){return`The setter of computed value '${e}' is trying to update itself. Did you intend to update an _observable_ value, instead of the computed property?`},34(e){return`[ComputedValue '${e}'] It is not possible to assign a new value to a computed value.`},35:"There are multiple, different versions of MobX active. Make sure MobX is loaded only once or use `configure({ isolateGlobalState: true })`",36:`isolateGlobalState should be called before MobX is running any reactions`,37(e){return`[mobx] \`observableArray.${e}()\` mutates the array in-place, which is not allowed inside a derivation. Use \`array.slice().${e}()\` instead`},38:`'ownKeys()' can only be used on observable objects`,39:`'defineProperty()' can only be used on observable objects`,40(e){return`Out of range: `+e},41(e){return`Cannot initialize set from `+e},42(e){return`Invalid index: '${e}'`},43(e,t,n){return`Cannot apply '${e}' to '${t}' (kind: ${n}):\n'${e}' can only be used on properties with a function value.`},44(e){return`'${e}' can only be used with 'makeObservable'`}};function n(e,...n){{let r=typeof e==`string`?e:t[e];throw typeof r==`function`&&(r=r.apply(null,n)),Error(`[MobX] ${r}`)}}let r=Object.assign,i=Object.getOwnPropertyDescriptor,a=Object.defineProperty,o=Object.prototype,s=[];Object.freeze(s);let c={};Object.freeze(c);let l=Object.toString();function u(){return++P.mobxGuid}function d(e){let t=!1;return function(){if(!t)return t=!0,e.apply(this,arguments)}}let f=()=>{};function p(e){return typeof e==`function`}function m(e){switch(typeof e){case`string`:case`symbol`:case`number`:return!0}return!1}function h(e){return typeof e==`object`&&!!e}function g(e){if(!h(e))return!1;let t=Object.getPrototypeOf(e);if(t==null)return!0;let n=T(t,`constructor`)&&t.constructor;return typeof n==`function`&&n.toString()===l}function _(e){let t=e?.constructor;return t?t.name===`GeneratorFunction`||t.displayName===`GeneratorFunction`:!1}function v(e,t,n){a(e,t,{enumerable:!1,writable:!0,configurable:!0,value:n})}function y(e,t,n){a(e,t,{enumerable:!1,writable:!1,configurable:!0,value:n})}function b(e,t){let n=`isMobX`+e;return t.prototype[n]=!0,function(e){return h(e)&&e[n]===!0}}function x(e){return e!=null&&Object.prototype.toString.call(e)===`[object Map]`}function S(e){return Object.getPrototypeOf(Object.getPrototypeOf(Object.getPrototypeOf(e)))===null}function C(e){return e!=null&&Object.prototype.toString.call(e)===`[object Set]`}function w(e){let t=Object.keys(e),n=Object.getOwnPropertySymbols(e);return n.length?[...t,...n.filter(t=>o.propertyIsEnumerable.call(e,t))]:t}let ee=Reflect.ownKeys;function te(e){return typeof e==`string`?e:typeof e==`symbol`?e.toString():new String(e).toString()}function ne(e){return e===null?null:typeof e==`object`?``+e:e}function T(e,t){return o.hasOwnProperty.call(e,t)}let re=Object.getOwnPropertyDescriptors;function E(e,t){return!!(e&t)}function D(e,t,n){return n?e|=t:e&=~t,e}function ie(e,t){t.includes(e.kind)||n(`The decorator applied to '${String(e.name)}' cannot be used on a ${e.kind} element`)}let O=Symbol(`mobx administration`);var ae=class{constructor(e=`Atom@`+u()){this.name_=void 0,this.flags_=0,this.observers_=null,this.lastAccessedBy_=0,this.lowestObserverState_=-1,this.onBOL=void 0,this.onBUOL=void 0,this.name_=e}get isBeingObserved(){return E(this.flags_,1)}set isBeingObserved(e){this.flags_=D(this.flags_,1,e)}get isPendingUnobservation(){return E(this.flags_,2)}set isPendingUnobservation(e){this.flags_=D(this.flags_,2,e)}get diffValue(){return+!!E(this.flags_,4)}set diffValue(e){this.flags_=D(this.flags_,4,e===1)}onBO(){this.onBOL&&this.onBOL.forEach(e=>e())}onBUO(){this.onBUOL&&this.onBUOL.forEach(e=>e())}reportObserved(){return sn(this)}reportChanged(){nn(),cn(this),rn()}toString(){return this.name_}};let oe=b(`Atom`,ae);function se(e,t=f,n=f){let r=new ae(e);return t!==f&&(r.onBOL=new Set([t])),n!==f&&(r.onBUOL=new Set([n])),r}function ce(e,t){return e===t}function le(e,t){return Mi(e,t)}function ue(e,t){return Mi(e,t,1)}let de=Object.is;function fe(e,t,n){return e===null||typeof e!=`object`&&typeof e!=`function`||vr(e)?e:Array.isArray(e)?A.array(e,{name:n}):g(e)?A.object(e,void 0,{name:n}):x(e)?A.map(e,{name:n}):C(e)?A.set(e,{name:n}):typeof e==`function`&&!Ln(e)&&!lr(e)?_(e)?ar(e):Nn(n,e):e}function pe(e,t,r){if(e==null||Di(e)||ui(e)||mi(e)||yi(e))return e;if(Array.isArray(e))return A.array(e,{name:r,deep:!1});if(g(e))return A.object(e,void 0,{name:r,deep:!1});if(x(e))return A.map(e,{name:r,deep:!1});if(C(e))return A.set(e,{name:r,deep:!1});n(`The shallow modifier / decorator can only used in combination with arrays, objects, maps and sets`)}function me(e){return e}function he(e,t){return vr(e)&&n(`observable.struct should not be used with observable values`),Mi(e,t)?t:e}let ge=`override`,_e={annotationType_:ge,make_:ye,extend_:be};function ve(e){return e.annotationType_===ge}function ye(e,t){return e.isPlainObject_&&n(`Cannot apply '${this.annotationType_}' to '${e.name_}.${t.toString()}':\n'${this.annotationType_}' cannot be used on plain objects.`),T(e.appliedAnnotations_,t)||n(`'${e.name_}.${t.toString()}' is annotated with '${this.annotationType_}', but no such annotated member was found on prototype.`),0}function be(e,t,r,i){n(44,this.annotationType_)}function xe(e,t){return{annotationType_:e,options_:t,make_:Se,extend_:Ce}}function Se(e,t,n,r){var i;return(i=this.options_)!=null&&i.bound?this.extend_(e,t,n,!1)===null?0:1:r===e.target_?this.extend_(e,t,n,!1)===null?0:2:Ln(n.value)?1:(a(r,t,Ee(e,this,t,n,!1)),2)}function Ce(e,t,n,r){let i=Ee(e,this,t,n);return e.defineProperty_(t,i,r)}function we(e,t,r){ie(r,[`method`,`field`]);let{kind:i,name:a,addInitializer:o}=r,s=e,c=e=>yt(s.options_?.name??a.toString(),e,s.options_?.autoAction??!1);if(i==`field`)return function(e){var t;let n=e;return Ln(n)||(n=c(n)),(t=s.options_)!=null&&t.bound&&(n=n.bind(this),n.isMobxAction=!0),n};if(i==`method`){var l;return Ln(t)||(t=c(t)),(l=s.options_)!=null&&l.bound&&o(function(){let e=this,t=e[a].bind(e);t.isMobxAction=!0,e[a]=t}),t}n(43,s.annotationType_,String(a),i)}function Te(e,{annotationType_:t},r,{value:i}){p(i)||n(`Cannot apply '${t}' to '${e.name_}.${r.toString()}':\n'${t}' can only be used on properties with a function value.`)}function Ee(e,t,n,r,i=P.safeDescriptors){var a,o;Te(e,t,n,r);let{value:s}=r;return(a=t.options_)!=null&&a.bound&&(s=s.bind(e.proxy_??e.target_)),{value:yt(t.options_?.name??n.toString(),s,t.options_?.autoAction??!1,(o=t.options_)!=null&&o.bound?e.proxy_??e.target_:void 0),configurable:i?e.isPlainObject_:!0,enumerable:!1,writable:!i}}function k(e,t){return{annotationType_:e,options_:t,make_:De,extend_:Oe}}function De(e,t,n,r){var i;return r===e.target_?this.extend_(e,t,n,!1)===null?0:2:(i=this.options_)!=null&&i.bound&&(!T(e.target_,t)||!lr(e.target_[t]))&&this.extend_(e,t,n,!1)===null?0:lr(n.value)?1:(a(r,t,je(e,this,t,n,!1,!1)),2)}function Oe(e,t,n,r){let i=je(e,this,t,n,this.options_?.bound);return e.defineProperty_(t,i,r)}function ke(e,t,n){var r;ie(n,[`method`]);let{name:i,addInitializer:a}=n;return lr(t)||(t=ar(t)),(r=e.options_)!=null&&r.bound&&a(function(){let e=this,t=e[i].bind(e);t.isMobXFlow=!0,e[i]=t}),t}function Ae(e,{annotationType_:t},r,{value:i}){p(i)||n(`Cannot apply '${t}' to '${e.name_}.${r.toString()}':\n'${t}' can only be used on properties with a generator function value.`)}function je(e,t,n,r,i,a=P.safeDescriptors){Ae(e,t,n,r);let{value:o}=r;return lr(o)||(o=ar(o)),i&&(o=o.bind(e.proxy_??e.target_),o.isMobXFlow=!0),{value:o,configurable:a?e.isPlainObject_:!0,enumerable:!1,writable:!a}}function Me(e,t){return{annotationType_:e,options_:t,make_:Ne,extend_:Pe}}function Ne(e,t,n){return this.extend_(e,t,n,!1)===null?0:1}function Pe(e,t,n,i){return Ie(e,this,t,n),e.defineComputedProperty_(t,r({},this.options_,{get:n.get,set:n.set}),i)}function Fe(e,t,n){ie(n,[`getter`]);let i=e,{name:a,addInitializer:o}=n,s;function c(e,n){let o=r({},i.options_,{get:t,context:e});return o.name||=`${n.name_}.${a.toString()}`,new Ot(o)}return o(function(){let e=wi(this)[O],n=this,r=e.values_.get(a);r instanceof Ot&&r.derivation!==t&&e.values_.delete(a),(e.lazyComputedKeys_??=new Map).set(a,()=>c(n,e))}),function(){let e=this[O],n=e.values_.get(a);if(n instanceof Ot&&n.derivation!==t){let t=s?.get(this);return t||(t=c(this,e),(s??=new WeakMap).set(this,t)),t.get()}return e.getObservablePropValue_(a)}}function Ie(e,{annotationType_:t},r,{get:i}){i||n(`Cannot apply '${t}' to '${e.name_}.${r.toString()}':\n'${t}' can only be used on getter(+setter) properties.`)}function Le(e,t){return{annotationType_:e,options_:t,make_:Re,extend_:ze}}function Re(e,t,n){return this.extend_(e,t,n,!1)===null?0:1}function ze(e,t,n,r){return Ve(e,this,t,n),e.defineObservableProperty_(t,n.value,this.options_?.enhancer_??fe,r)}function Be(e,t,r){if(r.kind===`field`)throw n(`Please use \`@observable accessor ${String(r.name)}\` instead of \`@observable ${String(r.name)}\``);ie(r,[`accessor`]);let i=e,{kind:a,name:o}=r;if(a!==`accessor`)return;function s(e,t){let n=wi(e)[O];return(n.lazyObservableKeys_??=new Map).set(o,()=>new Et(t,i.options_?.enhancer_??fe,`${n.name_}.${o.toString()}`,!1)),n}return{get(){return(this[O]??s(this,t.get.call(this))).getObservablePropValue_(o)},set(e){return(this[O]??s(this,e)).setObservablePropValue_(o,e)},init(e){return s(this,e),e}}}function Ve(e,{annotationType_:t},r,i){`value`in i||n(`Cannot apply '${t}' to '${e.name_}.${r.toString()}':\n'${t}' cannot be used on getter/setter properties`)}let He=Ue();function Ue(e){return{annotationType_:`true`,options_:e,make_:Ke,extend_:qe}}let We=[He];function Ge(e){let t=e.deep!==!1,n=!!e.autoBind,r=!t|(n?2:0);return We[r]??(We[r]=Ue({deep:t,autoBind:n}))}function Ke(e,t,n,r){var i;if(n.get)return j.make_(e,t,n,r);if(n.set){let i=Ln(n.set)?n.set:yt(t.toString(),n.set);return r===e.target_?e.defineProperty_(t,{configurable:P.safeDescriptors?e.isPlainObject_:!0,set:i})===null?0:2:(a(r,t,{configurable:!0,set:i}),2)}if(r!==e.target_&&typeof n.value==`function`){var o;if(_(n.value)){var s;return((s=this.options_)!=null&&s.autoBind?or:ar).make_(e,t,n,r)}return((o=this.options_)!=null&&o.autoBind?Fn:Nn).make_(e,t,n,r)}let c=this.options_?.deep===!1?st:A;return typeof n.value==`function`&&(i=this.options_)!=null&&i.autoBind&&(n.value=n.value.bind(e.proxy_??e.target_)),c.make_(e,t,n,r)}function qe(e,t,n,r){var i;return n.get?j.extend_(e,t,n,r):n.set?e.defineProperty_(t,{configurable:P.safeDescriptors?e.isPlainObject_:!0,set:yt(t.toString(),n.set)},r):(typeof n.value==`function`&&(i=this.options_)!=null&&i.autoBind&&(n.value=n.value.bind(e.proxy_??e.target_)),(this.options_?.deep===!1?st:A).extend_(e,t,n,r))}function Je(e,t){return r(function(r,i){if(i&&typeof i.kind==`string`)return t(e,r,i);n(`Invalid arguments for \`${e.annotationType_}\``)},e)}let Ye={deep:!0,name:void 0,defaultDecorator:void 0};Object.freeze(Ye);function Xe(e){return e||Ye}let Ze=Le(`observable`),Qe=Le(`observable.ref`,{enhancer_:me}),$e=Le(`observable.shallow`,{enhancer_:pe}),et=Le(`observable.struct`,{enhancer_:he});function tt(e){return Je(e,Be)}function nt(e){return e.deep===!0?fe:e.deep===!1?me:it(e.defaultDecorator)}function rt(e){return e?e.defaultDecorator??Ge(e):void 0}function it(e){return e?e.options_?.enhancer_??fe:fe}function at(e,t,n){return t&&typeof t.kind==`string`?Be(Ze,e,t):vr(e)?e:g(e)?A.object(e,t,n):Array.isArray(e)?A.array(e,t):x(e)?A.map(e,t):C(e)?A.set(e,t):typeof e==`object`&&e?e:A.box(e,t)}let ot={box(e,t){let n=Xe(t);return new Et(e,nt(n),n.name,!0,n.equals)},array(e,t){let n=Xe(t);return ri(e,nt(n),n.name)},map(e,t){let n=Xe(t);return new pi(e,nt(n),n.name)},set(e,t){let n=Xe(t);return new vi(e,nt(n),n.name)},object(e,t,n){return Ai(()=>Jn(Hr({},n),e,t))}},st=tt(Qe),ct=tt($e),lt=tt(Ze),ut=tt(et);var A=r(at,Ze,ot);let dt=`computed`;function ft(e){return Je(e,Fe)}let pt=Me(dt),mt=ft(Me(`computed.struct`,{equals:le})),j=function(e,t){if(t&&typeof t.kind==`string`)return Fe(pt,e,t);if(g(e))return ft(Me(dt,e));p(e)||n("First argument to `computed` should be an expression."),p(t)&&n("A setter as second argument is no longer supported, use `{ set: fn }` option instead");let r=g(t)?t:{};return r.get=e,r.name||=e.name||``,new Ot(r)};r(j,pt);let ht=0,gt=1,_t=i(()=>{},`name`)?.configurable??!1,vt={value:`action`,configurable:!0,writable:!1,enumerable:!1};function yt(e,t,r=!1,i){p(t)||n("`action` can only be invoked on functions"),(typeof e!=`string`||!e)&&n(`actions should have valid names, got: '${e}'`);function o(){return bt(e,r,t,i||this,arguments)}return o.isMobxAction=!0,o.toString=()=>t.toString(),_t&&(vt.value=e,a(o,`name`,vt)),o}function bt(e,t,n,r,i){let a=xt(e,t,r,i);try{return n.apply(r,i)}catch(e){throw a.error_=e,e}finally{St(a)}}function xt(e,t,n,r){let i=vn()&&!!e,a=0;i&&(a=Date.now(),bn({type:F,name:e,object:n,arguments:r?Array.from(r):s}));let o=P.trackingDerivation,c=!t||!o;nn();let l=P.allowStateChanges;c&&(Vt(),l=wt(!0));let u=P.allowStateReads;M(!0);let d={runAsAction_:c,prevDerivation_:o,prevAllowStateChanges_:l,prevAllowStateReads_:u,notifySpy_:i,startTime_:a,actionId_:gt++,parentActionId_:ht};return ht=d.actionId_,d}function St(e){ht!==e.actionId_&&n(30),ht=e.parentActionId_,e.error_!==void 0&&(P.suppressReactionErrors=!0),Tt(e.prevAllowStateChanges_),Ut(e.prevAllowStateReads_),rn(),e.runAsAction_&&Ht(e.prevDerivation_),e.notifySpy_&&Sn({time:Date.now()-e.startTime_}),P.suppressReactionErrors=!1}function Ct(e,t){let n=wt(e);try{return t()}finally{Tt(n)}}function wt(e){let t=P.allowStateChanges;return P.allowStateChanges=e,t}function Tt(e){P.allowStateChanges=e}var Et=class extends ae{constructor(e,t,n=`ObservableValue@`+u(),r=!0,i=de){super(n),this.enhancer_=void 0,this.name_=void 0,this.equals_=void 0,this.hasUnreportedChange_=!1,this.interceptors_=void 0,this.changeListeners_=void 0,this.value_=void 0,this.dehancer=void 0,this.enhancer_=t,this.name_=n,this.equals_=i,this.value_=t(e,void 0,n),r&&vn()&&yn({type:`create`,object:this,observableKind:`value`,debugObjectName:this.name_,newValue:this.value_})}dehanceValue(e){return this.dehancer===void 0?e:this.dehancer(e)}set(e){let t=this.value_;if(e=this.prepareNewValue_(e),e!==P.UNCHANGED){let n=vn();n&&bn({type:ei,object:this,observableKind:`value`,debugObjectName:this.name_,newValue:e,oldValue:t}),this.setNewValue_(e),n&&Sn()}}prepareNewValue_(e){if(Pt(this),Ur(this)){let t=Gr(this,{object:this,type:ei,newValue:e});if(!t)return P.UNCHANGED;e=t.newValue}return e=this.enhancer_(e,this.value_,this.name_),this.equals_(this.value_,e)?P.UNCHANGED:e}setNewValue_(e){let t=this.value_;this.value_=e,this.reportChanged(),Kr(this)&&Jr(this,{type:ei,object:this,newValue:e,oldValue:t})}get(){return this.reportObserved(),this.dehanceValue(this.value_)}raw(){return this.value_}toJSON(){return this.get()}toString(){return`${this.name_}[${this.value_}]`}valueOf(){return ne(this.get())}[Symbol.toPrimitive](){return this.valueOf()}};let Dt=b(`ObservableValue`,Et);var Ot=class{constructor(e){this.dependenciesState_=-1,this.observing_=[],this.newObserving_=null,this.observers_=null,this.runId_=0,this.lastAccessedBy_=0,this.lowestObserverState_=0,this.unboundDepsCount_=0,this.value_=new At(null),this.name_=void 0,this.triggeredBy_=void 0,this.flags_=0,this.derivation=void 0,this.setter_=void 0,this.scope_=void 0,this.equals_=void 0,this.requiresReaction_=void 0,this.keepAlive_=void 0,this.onBOL=void 0,this.onBUOL=void 0,e.get||n(31),this.derivation=e.get,this.name_=e.name||`ComputedValue@`+u(),e.set&&(this.setter_=yt(this.name_+`-setter`,e.set)),this.equals_=e.equals||de,this.scope_=e.context,this.requiresReaction_=e.requiresReaction,this.keepAlive_=!!e.keepAlive}onBecomeStale_(){un(this)}onBO(){this.onBOL&&this.onBOL.forEach(e=>e())}onBUO(){this.onBUOL&&this.onBUOL.forEach(e=>e())}get isComputing(){return E(this.flags_,1)}set isComputing(e){this.flags_=D(this.flags_,1,e)}get isRunningSetter(){return E(this.flags_,2)}set isRunningSetter(e){this.flags_=D(this.flags_,2,e)}get isBeingObserved(){return E(this.flags_,4)}set isBeingObserved(e){this.flags_=D(this.flags_,4,e)}get isPendingUnobservation(){return E(this.flags_,8)}set isPendingUnobservation(e){this.flags_=D(this.flags_,8,e)}get diffValue(){return+!!E(this.flags_,16)}set diffValue(e){this.flags_=D(this.flags_,16,e===1)}get(){if(this.isComputing&&n(32,this.name_,this.derivation),P.inBatch===0&&(!this.observers_||this.observers_.size===0)&&!this.keepAlive_)Mt(this)&&(this.warnAboutUntrackedRead_(),nn(),this.value_=this.computeValue_(!1),rn());else{let e=this.isBeingObserved;if(sn(this),Mt(this)){let e=P.trackingContext;!e&&(this.keepAlive_||this.isBeingObserved)&&(P.trackingContext=this),this.trackAndCompute()&&ln(this),P.trackingContext=e}else !e&&this.isBeingObserved&&this.observing_.forEach(on)}let e=this.value_;if(jt(e))throw e.cause;return e}set(e){if(this.setter_){this.isRunningSetter&&n(33,this.name_),this.isRunningSetter=!0;try{this.setter_.call(this.scope_,e)}finally{this.isRunningSetter=!1}}else n(34,this.name_)}trackAndCompute(){let e=this.value_,t=this.dependenciesState_===-1,n=this.computeValue_(!0),r=t||jt(e)||jt(n)||!this.equals_(e,n);return r&&(this.value_=n,vn()&&yn({observableKind:`computed`,debugObjectName:this.name_,object:this.scope_,type:`update`,oldValue:e,newValue:n})),r}computeValue_(e){this.isComputing=!0;let t=wt(!1),n;if(e)n=It(this,this.derivation,this.scope_);else if(P.disableErrorBoundaries===!0)n=this.derivation.call(this.scope_);else try{n=this.derivation.call(this.scope_)}catch(e){n=new At(e)}return Tt(t),this.isComputing=!1,n}suspend_(){this.keepAlive_||(zt(this),this.value_=void 0)}warnAboutUntrackedRead_(){(typeof this.requiresReaction_==`boolean`?this.requiresReaction_:P.computedRequiresReaction)&&console.warn(`[mobx] Computed value '${this.name_}' is being read outside a reactive context. Doing a full recompute.`)}toString(){return`${this.name_}[${this.derivation.toString()}]`}valueOf(){return ne(this.get())}[Symbol.toPrimitive](){return this.valueOf()}};let kt=b(`ComputedValue`,Ot);var At=class{constructor(e){this.cause=void 0,this.cause=e}};function jt(e){return e instanceof At}function Mt(e){switch(e.dependenciesState_){case 0:return!1;case-1:case 2:return!0;case 1:{let t=M(!0),n=Vt(),r=e.observing_,i=r.length;for(let a=0;a<i;a++){let i=r[a];if(kt(i)){if(P.disableErrorBoundaries)i.get();else try{i.get()}catch{return Ht(n),Ut(t),!0}if(e.dependenciesState_===2)return Ht(n),Ut(t),!0}}return Wt(e),Ht(n),Ut(t),!1}}}function Nt(){return P.trackingDerivation!==null}function Pt(e){let t=!!e.observers_&&e.observers_.size>0;!P.allowStateChanges&&(t||P.enforceActions===`always`)&&console.warn(`[MobX] `+(P.enforceActions?`Since strict-mode is enabled, changing (observed) observable values without using an action is not allowed. Tried to modify: `:`Side effects like changing state are not allowed at this point. Are you trying to modify state from, for example, a computed value or the render function of a React component? You can wrap side effects in 'runInAction' (or decorate functions with 'action') if needed. Tried to modify: `)+e.name_)}function Ft(e){!P.allowStateReads&&P.observableRequiresReaction&&console.warn(`[mobx] Observable '${e.name_}' being read outside a reactive context.`)}function It(e,t,n){let r=M(!0);Wt(e),e.newObserving_=Array(e.runId_===0?100:e.observing_.length),e.unboundDepsCount_=0,e.runId_=++P.runId;let i=P.trackingDerivation;P.trackingDerivation=e,P.inBatch++;let a;if(P.disableErrorBoundaries===!0)a=t.call(n);else try{a=t.call(n)}catch(e){a=new At(e)}return P.inBatch--,P.trackingDerivation=i,Rt(e),Lt(e),Ut(r),a}function Lt(e){e.observing_.length===0&&(typeof e.requiresObservable_==`boolean`?e.requiresObservable_:P.reactionRequiresObservable)&&console.warn(`[mobx] Derivation '${e.name_}' is created/updated without reading any observable value.`)}function Rt(e){let t=e.observing_,n=e.observing_=e.newObserving_,r=0,i=0,a=e.unboundDepsCount_;for(let e=0;e<a;e++){let t=n[e];t.diffValue===0&&(t.diffValue=1,i!==e&&(n[i]=t),i++),t.dependenciesState_>r&&(r=t.dependenciesState_)}for(n.length=i,e.newObserving_=null,a=t.length;a--;){let n=t[a];n.diffValue===0&&en(n,e),n.diffValue=0}for(;i--;){let t=n[i];t.diffValue===1&&(t.diffValue=0,$t(t,e))}r!==0&&(e.dependenciesState_=r,e.onBecomeStale_())}function zt(e){let t=e.observing_;e.observing_=[];let n=t.length;for(;n--;)en(t[n],e);e.dependenciesState_=-1}function Bt(e){let t=Vt();try{return e()}finally{Ht(t)}}function Vt(){let e=P.trackingDerivation;return P.trackingDerivation=null,e}function Ht(e){P.trackingDerivation=e}function M(e){let t=P.allowStateReads;return P.allowStateReads=e,t}function Ut(e){P.allowStateReads=e}function Wt(e){if(e.dependenciesState_===0)return;e.dependenciesState_=0;let t=e.observing_,n=t.length;for(;n--;)t[n].lowestObserverState_=0}let Gt=[`mobxGuid`,`spyListeners`,`enforceActions`,`computedRequiresReaction`,`reactionRequiresObservable`,`observableRequiresReaction`,`allowStateReads`,`disableErrorBoundaries`,`runId`,`UNCHANGED`];var N=class{constructor(){this.version=7,this.UNCHANGED={},this.trackingDerivation=null,this.trackingContext=null,this.runId=0,this.mobxGuid=0,this.inBatch=0,this.pendingUnobservations=[],this.pendingReactions=[],this.isRunningReactions=!1,this.isRunningUnobservations=!1,this.allowStateChanges=!1,this.allowStateReads=!0,this.enforceActions=!0,this.spyListeners=[],this.globalReactionErrorHandlers=[],this.computedRequiresReaction=!1,this.reactionRequiresObservable=!1,this.observableRequiresReaction=!1,this.disableErrorBoundaries=!1,this.suppressReactionErrors=!1,this.safeDescriptors=!0}};let Kt=!0,qt=!1,P=function(){let e=globalThis;return e.__mobxInstanceCount>0&&!e.__mobxGlobals&&(Kt=!1),e.__mobxGlobals&&e.__mobxGlobals.version!==7&&(Kt=!1),Kt?e.__mobxGlobals?(e.__mobxInstanceCount+=1,e.__mobxGlobals.UNCHANGED||(e.__mobxGlobals.UNCHANGED={}),e.__mobxGlobals):(e.__mobxInstanceCount=1,e.__mobxGlobals=new N):(setTimeout(()=>{qt||n(35)},1),new N)}();function Jt(){if((P.pendingReactions.length||P.inBatch||P.isRunningReactions)&&n(36),qt=!0,Kt){let e=globalThis;--e.__mobxInstanceCount===0&&(e.__mobxGlobals=void 0),P=new N}}function Yt(){return P}function Xt(){let e=new N;for(let t in e)Gt.indexOf(t)===-1&&(P[t]=e[t]);P.allowStateChanges=!P.enforceActions}function Zt(e){return!!e.observers_&&e.observers_.size>0}function Qt(e){return e.observers_??new Set}function $t(e,t){(e.observers_??=new Set).add(t),e.lowestObserverState_>t.dependenciesState_&&(e.lowestObserverState_=t.dependenciesState_)}function en(e,t){let n=e.observers_;n&&(n.delete(t),n.size===0&&tn(e))}function tn(e){e.isPendingUnobservation===!1&&(e.isPendingUnobservation=!0,P.pendingUnobservations.push(e))}function nn(){P.inBatch++}function rn(){--P.inBatch===0&&(mn(),!P.isRunningUnobservations&&P.pendingUnobservations.length>0&&an())}function an(){P.isRunningUnobservations=!0;try{let e=P.pendingUnobservations;for(let t=0;t<e.length;t++){let n=e[t];n.isPendingUnobservation=!1,(!n.observers_||n.observers_.size===0)&&(n.observers_=null,n.isBeingObserved&&(n.isBeingObserved=!1,n.onBUO()),n instanceof Ot&&n.suspend_())}P.pendingUnobservations=[]}finally{P.isRunningUnobservations=!1}}function on(e){var t;e.isBeingObserved||(e.isBeingObserved=!0,e.onBO(),(t=e.observing_)==null||t.forEach(on))}function sn(e){Ft(e);let t=P.trackingDerivation;return t===null?((!e.observers_||e.observers_.size===0)&&P.inBatch>0&&tn(e),!1):(t.runId_!==e.lastAccessedBy_&&(e.lastAccessedBy_=t.runId_,t.newObserving_[t.unboundDepsCount_++]=e,!e.isBeingObserved&&P.trackingContext&&(e.isBeingObserved=!0,e.onBO())),e.isBeingObserved)}function cn(e){var t;e.lowestObserverState_!==2&&(e.lowestObserverState_=2,(t=e.observers_)==null||t.forEach(e=>{e.dependenciesState_===0&&e.onBecomeStale_(),e.dependenciesState_=2}))}function ln(e){var t;e.lowestObserverState_!==2&&(e.lowestObserverState_=2,(t=e.observers_)==null||t.forEach(t=>{t.dependenciesState_===1?t.dependenciesState_=2:t.dependenciesState_===0&&(e.lowestObserverState_=0)}))}function un(e){var t;e.lowestObserverState_===0&&(e.lowestObserverState_=1,(t=e.observers_)==null||t.forEach(e=>{e.dependenciesState_===0&&(e.dependenciesState_=1,e.onBecomeStale_())}))}var dn=class{constructor(e=`Reaction@`+u(),t,n,r){this.name_=void 0,this.onInvalidate_=void 0,this.errorHandler_=void 0,this.requiresObservable_=void 0,this.observing_=[],this.newObserving_=[],this.dependenciesState_=-1,this.runId_=0,this.unboundDepsCount_=0,this.flags_=0,this.removeAbortListener_=void 0,this.name_=e,this.onInvalidate_=t,this.errorHandler_=n,this.requiresObservable_=r}get isDisposed(){return E(this.flags_,1)}set isDisposed(e){this.flags_=D(this.flags_,1,e)}get isScheduled(){return E(this.flags_,2)}set isScheduled(e){this.flags_=D(this.flags_,2,e)}get isTrackPending(){return E(this.flags_,4)}set isTrackPending(e){this.flags_=D(this.flags_,4,e)}get isRunning(){return E(this.flags_,8)}set isRunning(e){this.flags_=D(this.flags_,8,e)}get diffValue(){return+!!E(this.flags_,16)}set diffValue(e){this.flags_=D(this.flags_,16,e===1)}onBecomeStale_(){this.schedule_()}schedule_(){this.isScheduled||(this.isScheduled=!0,P.pendingReactions.push(this),mn())}runReaction_(){if(!this.isDisposed){nn(),this.isScheduled=!1;let e=P.trackingContext;if(P.trackingContext=this,Mt(this)){this.isTrackPending=!0;try{this.onInvalidate_(),this.isTrackPending&&vn()&&yn({name:this.name_,type:`scheduled-reaction`})}catch(e){this.reportExceptionInDerivation_(e)}}P.trackingContext=e,rn()}}track(e){if(this.isDisposed)return;nn();let t=vn(),n;t&&(n=Date.now(),bn({name:this.name_,type:`reaction`})),this.isRunning=!0;let r=P.trackingContext;P.trackingContext=this;let i=It(this,e,void 0);P.trackingContext=r,this.isRunning=!1,this.isTrackPending=!1,this.isDisposed&&zt(this),jt(i)&&this.reportExceptionInDerivation_(i.cause),t&&Sn({time:Date.now()-n}),rn()}reportExceptionInDerivation_(e){if(this.errorHandler_){this.errorHandler_(e,this);return}if(P.disableErrorBoundaries)throw e;let t=`[mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: '${this}'`;P.suppressReactionErrors?console.warn(`[mobx] (error in reaction '${this.name_}' suppressed, fix error of causing action below)`):console.error(t,e),vn()&&yn({type:`error`,name:this.name_,message:t,error:``+e}),P.globalReactionErrorHandlers.forEach(t=>t(e,this))}dispose(){if(!this.isDisposed){var e;this.isDisposed=!0,(e=this.removeAbortListener_)==null||e.call(this),this.isRunning||(nn(),zt(this),rn())}}getDisposer_(e){let t=()=>this.dispose();return e!=null&&e.addEventListener&&!this.isDisposed&&(e.addEventListener(`abort`,t),this.removeAbortListener_=()=>e.removeEventListener==null?void 0:e.removeEventListener(`abort`,t)),t[O]=this,`dispose`in Symbol&&typeof Symbol.dispose==`symbol`&&(t[Symbol.dispose]=t),t}toString(){return`Reaction[${this.name_}]`}};function fn(e){return P.globalReactionErrorHandlers.push(e),()=>{let t=P.globalReactionErrorHandlers.indexOf(e);t>=0&&P.globalReactionErrorHandlers.splice(t,1)}}let pn=e=>e();function mn(){P.inBatch>0||P.isRunningReactions||pn(hn)}function hn(){P.isRunningReactions=!0;let e=P.pendingReactions,t=0;for(;e.length>0;){++t===100&&(console.error(`Reaction doesn't converge to a stable state after 100 iterations. Probably there is a cycle in the reactive function: ${e[0]}`),e.splice(0));let n=e.splice(0);for(let e=0,t=n.length;e<t;e++)n[e].runReaction_()}P.isRunningReactions=!1}let gn=b(`Reaction`,dn);function _n(e){let t=pn;pn=n=>e(()=>t(n))}function vn(){return!!P.spyListeners.length}function yn(e){if(!P.spyListeners.length)return;let t=P.spyListeners;for(let n=0,r=t.length;n<r;n++)t[n](e)}function bn(e){yn(r({},e,{spyReportStart:!0}))}let xn={type:`report-end`,spyReportEnd:!0};function Sn(e){yn(e?r({},e,{type:`report-end`,spyReportEnd:!0}):xn)}function Cn(e){return P.spyListeners.push(e),d(()=>{P.spyListeners=P.spyListeners.filter(t=>t!==e)})}let F=`action`,wn=`autoAction`,Tn=`<unnamed action>`,En=xe(F),Dn=xe(`action.bound`,{bound:!0}),On=xe(wn,{autoAction:!0}),kn=xe(`autoAction.bound`,{autoAction:!0,bound:!0});function An(e){return Je(e,we)}function jn(e){return function(t,r){if(r&&typeof r.kind==`string`)return we(e?On:En,t,r);if(p(t))return yt(t.name||Tn,t,e);if(p(r))return yt(t,r,e);if(m(t))return An(xe(e?wn:F,{name:t,autoAction:e}));n("Invalid arguments for `action`")}}let Mn=jn(!1);r(Mn,En);let Nn=jn(!0);r(Nn,On);let Pn=An(Dn),Fn=An(kn);function In(e){return bt(e.name||Tn,!1,e,this,void 0)}function Ln(e){return p(e)&&e.isMobxAction===!0}function Rn(e,t=c){var r;p(e)||n(`Autorun expects a function as first argument`),Ln(e)&&n(`Autorun does not accept actions since actions are untrackable`);let i=t?.name??(e.name||`Autorun@`+u()),a=!t.scheduler&&!t.delay,o;if(a)o=new dn(i,function(){this.track(s)},t.onError,t.requiresObservable);else{let e=Bn(t),n=!1;o=new dn(i,()=>{n||(n=!0,e(()=>{n=!1,o.isDisposed||o.track(s)}))},t.onError,t.requiresObservable)}function s(){e(o)}return t!=null&&(r=t.signal)!=null&&r.aborted||o.schedule_(),o.getDisposer_(t?.signal)}let zn=e=>e();function Bn(e){return e.scheduler?e.scheduler:e.delay?t=>setTimeout(t,e.delay):zn}function Vn(e,t,r=c){var i;(!p(e)||!p(t))&&n(`First and second argument to reaction should be functions`),g(r)||n(`Third argument of reactions should be an object`);let a=r.name??`Reaction@`+u(),o=Mn(a,r.onError?Hn(r.onError,t):t),s=!r.scheduler&&!r.delay,l=Bn(r),d=!0,f=!1,m,h=r.equals||de,_=new dn(a,()=>{d||s?v():f||(f=!0,l(v))},r.onError,r.requiresObservable);function v(){if(f=!1,_.isDisposed)return;let t=!1,n=m;_.track(()=>{let n=Ct(!1,()=>e(_));t=d||!h(m,n),m=n}),(d&&r.fireImmediately||!d&&t)&&o(m,n,_),d=!1}return r!=null&&(i=r.signal)!=null&&i.aborted||_.schedule_(),_.getDisposer_(r?.signal)}function Hn(e,t){return function(){try{return t.apply(this,arguments)}catch(t){e.call(this,t)}}}function Un(e,t,n){return Gn(`onBO`,e,t,n)}function Wn(e,t,n){return Gn(`onBUO`,e,t,n)}function Gn(e,t,n,r){let i=typeof r==`function`?R(t,n):R(t),a=p(r)?r:n,o=`${e}L`;return i[o]?i[o].add(a):i[o]=new Set([a]),function(){let e=i[o];e&&(e.delete(a),e.size===0&&delete i[o])}}let Kn=`always`;function qn(e){e.isolateGlobalState===!0&&Jt();let{enforceActions:t}=e;if(t!==void 0){let e=t===Kn?Kn:t===`observed`;P.enforceActions=e,P.allowStateChanges=!(e===!0||e===Kn)}[`computedRequiresReaction`,`reactionRequiresObservable`,`observableRequiresReaction`,`disableErrorBoundaries`,`safeDescriptors`].forEach(t=>{t in e&&(P[t]=!!e[t])}),P.allowStateReads=!P.observableRequiresReaction,P.disableErrorBoundaries===!0&&console.warn("WARNING: Debug feature only. MobX will NOT recover from errors when `disableErrorBoundaries` is enabled."),e.reactionScheduler&&_n(e.reactionScheduler)}function Jn(e,t,r,i){arguments.length>4&&n(`'extendObservable' expected 2-4 arguments`),typeof e!=`object`&&n(`'extendObservable' expects an object as first argument`),mi(e)&&n(`'extendObservable' should not be used on maps, use map.merge instead`),g(t)||n(`'extendObservable' only accepts plain objects as second argument`),(vr(t)||vr(r))&&n(`Extending an object with another observable (object) is not supported`);let a=re(t);return Ai(()=>{let t=wi(e,i)[O];ee(a).forEach(e=>{t.extend_(e,a[e],r&&e in r?r[e]:!0)})}),e}function Yn(e,t){return Xn(R(e,t))}function Xn(e){let t={name:e.name_};return e.observing_&&e.observing_.length>0&&(t.dependencies=$n(e.observing_).map(Xn)),t}function Zn(e,t){return Qn(R(e,t))}function Qn(e){let t={name:e.name_};return Zt(e)&&(t.observers=Array.from(Qt(e),Qn)),t}function $n(e){return Array.from(new Set(e))}let er=0;var tr=class extends Error{constructor(){super(`FLOW_CANCELLED`),Object.setPrototypeOf(this,new.target.prototype),this.name=`FlowCancellationError`}toString(){return`Error: ${this.message}`}};function nr(e){return e instanceof tr}function rr(e){return Je(e,ke)}let ir=k(`flow`),I=k(`flow.bound`,{bound:!0}),ar=r(function(e,t){if(t&&typeof t.kind==`string`)return ke(ir,e,t);arguments.length!==1&&n(`Flow expects single argument with generator function`);let r=e,i=r.name||`<unnamed flow>`,a=function(){let e=this,t=arguments,n=++er,a=Mn(`${i} - runid: ${n} - init`,r).apply(e,t),o,s,c=new Promise(function(e,t){let r=0;o=t;function c(e){s=void 0;let o;try{o=Mn(`${i} - runid: ${n} - yield ${r++}`,a.next).call(a,e)}catch(e){return t(e)}u(o)}function l(e){s=void 0;let o;try{o=Mn(`${i} - runid: ${n} - yield ${r++}`,a.throw).call(a,e)}catch(e){return t(e)}u(o)}function u(n){if(p(n?.then)){n.then(u,t);return}return n.done?e(n.value):(s=Promise.resolve(n.value),s.then(c,l))}c(void 0)});return c.cancel=Mn(`${i} - runid: ${n} - cancel`,function(){try{s&&sr(s);let e=a.return(void 0),t=Promise.resolve(e.value);t.then(f,f),sr(t),o(new tr)}catch(e){o(e)}}),c};return a.isMobXFlow=!0,a},ir),or=rr(I);function sr(e){p(e.cancel)&&e.cancel()}function cr(e){return e}function lr(e){return e?.isMobXFlow===!0}function ur(e,t,r){let i;if(mi(e)||ui(e)||Dt(e))i=z(e);else if(Di(e)){if(!m(t))return n(`InterceptReads can only be used with a specific property, not with an object in general`);i=z(e,t)}else return n(`Expected observable map, object or array as first array`);return i.dehancer===void 0?(i.dehancer=typeof t==`function`?t:r,()=>{i.dehancer=void 0}):n(`An intercept reader was already established`)}function dr(e,t,n){return p(n)?pr(e,t,n):fr(e,t)}function fr(e,t){return Wr(z(e),t)}function pr(e,t,n){return Wr(z(e,t),n)}function mr(e,t){var n;if(t===void 0)return kt(e);if(Di(e)===!1)return!1;let r=e[O];return(n=r.lazyComputedKeys_)!=null&&n.has(t)?!0:r.values_.has(t)?kt(R(e,t)):!1}function hr(e){return arguments.length>1?n(`isComputed expects only 1 argument. Use isComputedProp to inspect the observability of a property`):mr(e)}function gr(e,t){return m(t)?mr(e,t):n(`isComputed expected a property name as second argument`)}function _r(e,t){if(!e)return!1;if(t!==void 0){if(mi(e)||ui(e))return n(`isObservable(object, propertyName) is not supported for arrays and maps. Use map.has or array.length instead.`);if(Di(e)){var r,i;let n=e[O];return n.values_.has(t)||!!((r=n.lazyComputedKeys_)!=null&&r.has(t))||!!((i=n.lazyObservableKeys_)!=null&&i.has(t))}return!1}return Di(e)||!!e[O]||oe(e)||gn(e)||kt(e)}function vr(e){return arguments.length!==1&&n(`isObservable expects only 1 argument. Use isObservableProp to inspect the observability of a property`),_r(e)}function yr(e,t){return m(t)?_r(e,t):n(`expected a property name as second argument`)}function br(e){if(Di(e))return e[O].keys_();if(mi(e)||yi(e))return Array.from(e.keys());if(ui(e))return e.map((e,t)=>t);n(5)}function xr(e){if(Di(e))return br(e).map(t=>e[t]);if(mi(e))return br(e).map(t=>e.get(t));if(yi(e))return Array.from(e.values());if(ui(e))return e.slice();n(6)}function Sr(e){if(Di(e))return br(e).map(t=>[t,e[t]]);if(mi(e))return br(e).map(t=>[t,e.get(t)]);if(yi(e))return Array.from(e.entries());if(ui(e))return e.map((e,t)=>[t,e]);n(7)}function Cr(e,t,r){if(arguments.length===2&&!yi(e)){nn();let n=t;try{for(let t in n)Cr(e,t,n[t])}finally{rn()}return}Di(e)?e[O].set_(t,r):mi(e)?e.set(t,r):yi(e)?e.add(t):ui(e)?(typeof t!=`number`&&(t=parseInt(t,10)),t<0&&n(42,t),nn(),t>=e.length&&(e.length=t+1),e[t]=r,rn()):n(8)}function wr(e,t){Di(e)?e[O].delete_(t):mi(e)||yi(e)?e.delete(t):ui(e)?(typeof t!=`number`&&(t=parseInt(t,10)),e.splice(t,1)):n(9)}function Tr(e,t){if(Di(e))return e[O].has_(t);if(mi(e)||yi(e))return e.has(t);if(ui(e))return t>=0&&t<e.length;n(10)}function Er(e,t){if(Tr(e,t)){if(Di(e))return e[O].get_(t);if(mi(e))return e.get(t);if(ui(e))return e[t];n(11)}}function Dr(e,t,r){if(Di(e))return e[O].defineProperty_(t,r);n(39)}function Or(e){if(Di(e))return e[O].ownKeys_();n(38)}function kr(e,t,n,r){return p(n)?jr(e,t,n,r):Ar(e,t,n)}function Ar(e,t,r){let i=z(e);if(ui(e))r&&t({observableKind:`array`,object:i.proxy_,debugObjectName:i.atom_.name_,type:`splice`,index:0,added:i.values_.slice(),addedCount:i.values_.length,removed:[],removedCount:0});else if(mi(e))r===!0&&n("`observe` doesn't support fireImmediately=true in combination with maps.");else if(yi(e))r===!0&&n("`observe` doesn't support fireImmediately=true in combination with sets.");else if(Di(e))r===!0&&n("`observe` doesn't support the fire immediately property for observable objects.");else return Mr(i,t,r);return qr(i,t)}function jr(e,t,n,r){return Mr(z(e,t),n,r)}function Mr(e,t,n){if(kt(e)){let r=!0,i;return Rn(()=>{let a=e.get();if(!r||n){let n=Vt();t({observableKind:`computed`,debugObjectName:e.name_,type:ei,object:e,newValue:a,oldValue:i}),Ht(n)}r=!1,i=a})}return n&&t({observableKind:`value`,debugObjectName:e.name_,object:e,type:ei,newValue:e.value_,oldValue:void 0}),qr(e,t)}function Nr(e,t,n){return e.set(t,n),n}function Pr(e,t){if(typeof e!=`object`||!e||e instanceof Date||!vr(e))return e;if(Dt(e)||kt(e))return Pr(e.get(),t);if(t.has(e))return t.get(e);if(ui(e)){let n=Nr(t,e,Array(e.length));return e.forEach((e,r)=>{n[r]=Pr(e,t)}),n}if(yi(e)){let n=Nr(t,e,new Set);return e.forEach(e=>{n.add(Pr(e,t))}),n}if(mi(e)){let n=Nr(t,e,new Map);return e.forEach((e,r)=>{n.set(r,Pr(e,t))}),n}else{let n=Nr(t,e,{});return Or(e).forEach(r=>{o.propertyIsEnumerable.call(e,r)&&(n[r]=Pr(e[r],t))}),n}}function Fr(e,t){return t&&n(`toJS no longer supports options`),Pr(e,new Map)}function Ir(e,t=void 0){nn();try{return e.apply(t)}finally{rn()}}function Lr(e,t,n){return arguments.length===1||t&&typeof t==`object`?zr(e,t):Rr(e,t,n||{})}function Rr(e,t,n){let r;if(typeof n.timeout==`number`){let e=Error(`WHEN_TIMEOUT`);r=setTimeout(()=>{if(!a[O].isDisposed)if(a(),n.onError)n.onError(e);else throw e},n.timeout)}n.name=n.name||`When@`+u();let i=yt(n.name+`-effect`,t);var a=Rn(t=>{Ct(!1,e)&&(t.dispose(),r&&clearTimeout(r),i())},n);return a}function zr(e,t){var i;if(t&&t.onError)return n(`the options 'onError' and 'promise' cannot be combined`);if(t!=null&&(i=t.signal)!=null&&i.aborted)return r(Promise.reject(Error(`WHEN_ABORTED`)),{cancel:()=>null});let a,o,s=new Promise((n,i)=>{var s;let c=Rr(e,n,r({},t,{onError:i}));a=()=>{c(),i(Error(`WHEN_CANCELLED`))},o=()=>{c(),i(Error(`WHEN_ABORTED`))},t==null||(s=t.signal)==null||s.addEventListener==null||s.addEventListener(`abort`,o)}).finally(()=>{var e;return t==null||(e=t.signal)==null||e.removeEventListener==null?void 0:e.removeEventListener(`abort`,o)});return s.cancel=a,s}function Br(e){return e[O]}let Vr={has(e,t){return Br(e).has_(t)},get(e,t){return Br(e).get_(t)},set(e,t,n){return m(t)?Br(e).set_(t,n,!0)??!0:!1},deleteProperty(e,t){return m(t)?Br(e).delete_(t,!0)??!0:!1},defineProperty(e,t,n){return Br(e).defineProperty_(t,n)??!0},ownKeys(e){return Br(e).ownKeys_()},preventExtensions(e){n(13)}};function Hr(e,t){var n;return e=wi(e,t),(n=e[O]).proxy_??(n.proxy_=new Proxy(e,Vr))}function Ur(e){return e.interceptors_!==void 0&&e.interceptors_.length>0}function Wr(e,t){let n=e.interceptors_;return n?n.push(t):n=e.interceptors_=[t],d(()=>{let e=n.indexOf(t);e!==-1&&n.splice(e,1)})}function Gr(e,t){let r=Vt();try{let r=[...e.interceptors_||[]];for(let e=0,i=r.length;e<i&&(t=r[e](t),t&&!t.type&&n(14),t);e++);return t}finally{Ht(r)}}function Kr(e){return e.changeListeners_!==void 0&&e.changeListeners_.length>0}function qr(e,t){let n=e.changeListeners_;return n?n.push(t):n=e.changeListeners_=[t],d(()=>{let e=n.indexOf(t);e!==-1&&n.splice(e,1)})}function Jr(e,t){let n=Vt(),r=e.changeListeners_;if(r){r=r.slice();for(let e=0,n=r.length;e<n;e++)r[e](t);Ht(n)}}function Yr(e,t,n){return Ai(()=>{let r=wi(e,n)[O];ee(t).forEach(e=>Qr(r,e,t[e]))}),e}let Xr=Symbol(`mobx-keys`);function Zr(e,t,r){return!g(e)&&!g(Object.getPrototypeOf(e))&&n(`'makeAutoObservable' can only be used for classes that don't have a superclass`),Di(e)&&n(`makeAutoObservable can only be used on objects not already made observable`),g(e)?Jn(e,e,t,r):(Ai(()=>{let n=wi(e,r)[O];if(!e[Xr]){let t=Object.getPrototypeOf(e),n=new Set([...ee(e),...ee(t)]);n.delete(`constructor`),n.delete(O),v(t,Xr,n)}e[Xr].forEach(e=>Qr(n,e,t&&e in t?t[e]:!0))}),e)}function Qr(e,t,r){if(r===!0&&(r=e.defaultAnnotation_),r===!1)return;L(e,r,t),t in e.target_||n(1,r.annotationType_,`${e.name_}.${t.toString()}`);let a=e.target_;for(;a&&a!==o;){let n=i(a,t);if(n){let i=r.make_(e,t,n,a);if(i===0)return;if(i===1)break}a=Object.getPrototypeOf(a)}Oi(e,r,t)}let $r=`splice`,ei=`update`,ti={get(e,t){let n=e[O];return t===O?n:t===`length`?n.getArrayLength_():typeof t==`string`&&!isNaN(t)?n.get_(parseInt(t)):T(ii,t)?ii[t]:e[t]},set(e,t,n){let r=e[O];return t===`length`?r.setArrayLength_(n):typeof t==`symbol`||isNaN(t)?e[t]=n:r.set_(parseInt(t),n),!0},preventExtensions(){n(15)}};var ni=class{constructor(e=`ObservableArray@`+u(),t,n){this.owned_=void 0,this.atom_=void 0,this.values_=[],this.interceptors_=void 0,this.changeListeners_=void 0,this.enhancer_=void 0,this.dehancer=void 0,this.proxy_=void 0,this.lastKnownLength_=0,this.owned_=n,this.atom_=new ae(e),this.enhancer_=(n,r)=>t(n,r,e+`[..]`)}dehanceValue_(e){return this.dehancer===void 0?e:this.dehancer(e)}dehanceValues_(e){return this.dehancer!==void 0&&e.length>0?e.map(this.dehancer):e}getArrayLength_(){return this.atom_.reportObserved(),this.values_.length}setArrayLength_(e){(!Number.isInteger(e)||e<0)&&n(40,e);let t=this.values_.length;if(e!==t)if(e>t){let n=Array.from({length:e-t});this.spliceWithArray_(t,0,n)}else this.spliceWithArray_(e,t-e)}updateArrayLength_(e,t){e!==this.lastKnownLength_&&n(16),this.lastKnownLength_+=t}spliceWithArray_(e,t,n){Pt(this.atom_);let r=this.values_.length;if(e===void 0?e=0:e>r?e=r:e<0&&(e=Math.max(0,r+e)),t=arguments.length===1?r-e:t==null?0:Math.max(0,Math.min(t,r-e)),n===void 0&&(n=s),Ur(this)){let r=Gr(this,{object:this.proxy_,type:$r,index:e,removedCount:t,added:n});if(!r)return s;t=r.removedCount,n=r.added}n=n.length===0?n:n.map(e=>this.enhancer_(e,void 0));{let e=n.length-t;this.updateArrayLength_(r,e)}let i=this.spliceItemsIntoValues_(e,t,n);return(t!==0||n.length!==0)&&this.notifyArraySplice_(e,n,i),this.dehanceValues_(i)}spliceItemsIntoValues_(e,t,n){if(n.length<1e4)return this.values_.splice(e,t,...n);{let r=this.values_.slice(e,e+t),i=this.values_.slice(e+t);this.values_.length+=n.length-t;for(let t=0;t<n.length;t++)this.values_[e+t]=n[t];for(let t=0;t<i.length;t++)this.values_[e+n.length+t]=i[t];return r}}notifyArrayChildUpdate_(e,t,n){let r=!this.owned_&&vn(),i=Kr(this),a=i||r?{observableKind:`array`,object:this.proxy_,type:ei,debugObjectName:this.atom_.name_,index:e,newValue:t,oldValue:n}:null;r&&bn(a),this.atom_.reportChanged(),i&&Jr(this,a),r&&Sn()}notifyArraySplice_(e,t,n){let r=!this.owned_&&vn(),i=Kr(this),a=i||r?{observableKind:`array`,object:this.proxy_,debugObjectName:this.atom_.name_,type:$r,index:e,removed:n,added:t,removedCount:n.length,addedCount:t.length}:null;r&&bn(a),this.atom_.reportChanged(),i&&Jr(this,a),r&&Sn()}get_(e){return this.atom_.reportObserved(),this.dehanceValue_(this.values_[e])}set_(e,t){let n=this.values_;if(e<n.length){Pt(this.atom_);let r=n[e];if(Ur(this)){let n=Gr(this,{type:ei,object:this.proxy_,index:e,newValue:t});if(!n)return;t=n.newValue}t=this.enhancer_(t,r),t!==r&&(n[e]=t,this.notifyArrayChildUpdate_(e,t,r))}else{let r=Array.from({length:e+1-n.length});r[r.length-1]=t,this.spliceWithArray_(n.length,0,r)}}};function ri(e,t,n=`ObservableArray@`+u(),r=!1){return Ai(()=>{let i=new ni(n,t,r);y(i.values_,O,i);let a=new Proxy(i.values_,ti);return i.proxy_=a,e&&e.length&&i.spliceWithArray_(0,0,e),a})}var ii={clear(){return this.splice(0)},replace(e){let t=this[O];return t.spliceWithArray_(0,t.values_.length,e)},toJSON(){return this.slice()},splice(e,t,...n){let r=this[O];switch(arguments.length){case 0:return[];case 1:return r.spliceWithArray_(e);case 2:return r.spliceWithArray_(e,t)}return r.spliceWithArray_(e,t,n)},spliceWithArray(e,t,n){return this[O].spliceWithArray_(e,t,n)},push(...e){let t=this[O];return t.spliceWithArray_(t.values_.length,0,e),t.values_.length},pop(){return this.splice(Math.max(this[O].values_.length-1,0),1)[0]},shift(){return this.splice(0,1)[0]},unshift(...e){let t=this[O];return t.spliceWithArray_(0,0,e),t.values_.length},reverse(){return P.trackingDerivation&&n(37,`reverse`),this.replace(this.slice().reverse()),this},sort(){P.trackingDerivation&&n(37,`sort`);let e=this.slice();return e.sort.apply(e,arguments),this.replace(e),this},remove(e){let t=this[O],n=t.dehanceValues_(t.values_).indexOf(e);return n>-1?(this.splice(n,1),!0):!1}};ai(`at`,oi),ai(`concat`,oi),ai(`flat`,oi),ai(`includes`,oi),ai(`indexOf`,oi),ai(`join`,oi),ai(`lastIndexOf`,oi),ai(`slice`,oi),ai(`toString`,oi),ai(`toLocaleString`,oi),ai(`toSorted`,oi),ai(`toSpliced`,oi),ai(`with`,oi),ai(`every`,si),ai(`filter`,si),ai(`find`,si),ai(`findIndex`,si),ai(`findLast`,si),ai(`findLastIndex`,si),ai(`flatMap`,si),ai(`forEach`,si),ai(`map`,si),ai(`some`,si),ai(`toReversed`,si),ai(`reduce`,ci),ai(`reduceRight`,ci);function ai(e,t){typeof Array.prototype[e]==`function`&&(ii[e]=t(e))}function oi(e){return function(){let t=this[O];t.atom_.reportObserved();let n=t.dehanceValues_(t.values_);return n[e].apply(n,arguments)}}function si(e){return function(t,n){let r=this[O];return r.atom_.reportObserved(),r.dehanceValues_(r.values_)[e]((e,r)=>t.call(n,e,r,this))}}function ci(e){return function(){let t=this[O];t.atom_.reportObserved();let n=t.dehanceValues_(t.values_),r=arguments[0];return arguments[0]=(e,t,n)=>r(e,t,n,this),n[e].apply(n,arguments)}}let li=b(`ObservableArrayAdministration`,ni);function ui(e){return h(e)&&li(e[O])}let di={},fi=`delete`;var pi=class{constructor(e,t=fe,n=`ObservableMap@`+u()){this.enhancer_=void 0,this.name_=void 0,this[O]=di,this.data_=void 0,this.hasMap_=void 0,this.keysAtom_=void 0,this.interceptors_=void 0,this.changeListeners_=void 0,this.dehancer=void 0,this.enhancer_=t,this.name_=n,Ai(()=>{this.keysAtom_=se(`${this.name_}.keys()`),this.data_=new Map,this.hasMap_=new Map,e&&this.merge(e)})}has_(e){return this.data_.has(e)}has(e){if(!P.trackingDerivation)return this.has_(e);let t=this.hasMap_.get(e);if(!t){let n=t=new Et(this.has_(e),me,`${this.name_}.${te(e)}?`,!1);this.hasMap_.set(e,n),n.onBUOL=new Set([()=>this.hasMap_.delete(e)])}return t.get()}set(e,t){let n=this.has_(e);if(Ur(this)){let r=Gr(this,{type:n?ei:`add`,object:this,newValue:t,name:e});if(!r)return this;t=r.newValue}return n?this.updateValue_(e,t):this.addValue_(e,t),this}delete(e){if(Pt(this.keysAtom_),Ur(this)&&!Gr(this,{type:fi,object:this,name:e}))return!1;if(this.has_(e)){let t=vn(),n=Kr(this),r=n||t?{observableKind:`map`,debugObjectName:this.name_,type:fi,object:this,oldValue:this.data_.get(e).value_,name:e}:null;return t&&bn(r),Ir(()=>{var t;this.keysAtom_.reportChanged(),(t=this.hasMap_.get(e))==null||t.setNewValue_(!1),this.data_.get(e).setNewValue_(void 0),this.data_.delete(e)}),n&&Jr(this,r),t&&Sn(),!0}return!1}updateValue_(e,t){let n=this.data_.get(e);if(t=n.prepareNewValue_(t),t!==P.UNCHANGED){let r=vn(),i=Kr(this),a=i||r?{observableKind:`map`,debugObjectName:this.name_,type:ei,object:this,oldValue:n.value_,name:e,newValue:t}:null;r&&bn(a),n.setNewValue_(t),i&&Jr(this,a),r&&Sn()}}addValue_(e,t){Pt(this.keysAtom_),Ir(()=>{var n;let r=new Et(t,this.enhancer_,`${this.name_}.${te(e)}`,!1);this.data_.set(e,r),t=r.value_,(n=this.hasMap_.get(e))==null||n.setNewValue_(!0),this.keysAtom_.reportChanged()});let n=vn(),r=Kr(this),i=r||n?{observableKind:`map`,debugObjectName:this.name_,type:`add`,object:this,name:e,newValue:t}:null;n&&bn(i),r&&Jr(this,i),n&&Sn()}get(e){return this.has(e)?this.dehanceValue_(this.data_.get(e).get()):this.dehanceValue_(void 0)}getOrInsert(e,t){return this.has(e)||this.set(e,t),this.get(e)}getOrInsertComputed(e,t){return this.has(e)||this.set(e,t(e)),this.get(e)}dehanceValue_(e){return this.dehancer===void 0?e:this.dehancer(e)}keys(){return this.keysAtom_.reportObserved(),this.data_.keys()}values(){let e=this,t=this.keys();return hi({next(){let{done:n,value:r}=t.next();return{done:n,value:n?void 0:e.get(r)}}})}entries(){let e=this,t=this.keys();return hi({next(){let{done:n,value:r}=t.next();return{done:n,value:n?void 0:[r,e.get(r)]}}})}[Symbol.iterator](){return this.entries()}forEach(e,t){for(let[n,r]of this)e.call(t,r,n,this)}merge(e){return mi(e)&&(e=new Map(e)),Ir(()=>{g(e)?w(e).forEach(t=>this.set(t,e[t])):Array.isArray(e)?e.forEach(([e,t])=>this.set(e,t)):x(e)?(S(e)||n(19,e),e.forEach((e,t)=>this.set(t,e))):e!=null&&n(20,e)}),this}clear(){Ir(()=>{Bt(()=>{for(let e of this.keys())this.delete(e)})})}replace(e){return Ir(()=>{let t=gi(e),n=new Map,r=!1;for(let e of this.data_.keys())if(!t.has(e))if(this.delete(e))r=!0;else{let t=this.data_.get(e);n.set(e,t)}for(let[e,i]of t.entries()){let t=this.data_.has(e);if(this.set(e,i),this.data_.has(e)){let i=this.data_.get(e);n.set(e,i),t||(r=!0)}}if(!r)if(this.data_.size!==n.size)this.keysAtom_.reportChanged();else{let e=this.data_.keys(),t=n.keys(),r=e.next(),i=t.next();for(;!r.done;){if(r.value!==i.value){this.keysAtom_.reportChanged();break}r=e.next(),i=t.next()}}this.data_=n}),this}get size(){return this.keysAtom_.reportObserved(),this.data_.size}toString(){return`[object ObservableMap]`}toJSON(){return Array.from(this)}get[Symbol.toStringTag](){return`Map`}},mi=b(`ObservableMap`,pi);function hi(e){return e[Symbol.toStringTag]=`MapIterator`,Ii(e)}function gi(e){if(x(e)||mi(e))return e;if(Array.isArray(e))return new Map(e);if(g(e)){let t=new Map;for(let n in e)t.set(n,e[n]);return t}else return n(21,e)}let _i={};var vi=class{constructor(e,t=fe,n=`ObservableSet@`+u()){this.name_=void 0,this[O]=_i,this.data_=new Set,this.atom_=void 0,this.changeListeners_=void 0,this.interceptors_=void 0,this.dehancer=void 0,this.enhancer_=void 0,this.name_=n,this.enhancer_=(e,r)=>t(e,r,n),Ai(()=>{this.atom_=se(this.name_),e&&this.replace(e)})}dehanceValue_(e){return this.dehancer===void 0?e:this.dehancer(e)}clear(){Ir(()=>{Bt(()=>{for(let e of this.data_.values())this.delete(e)})})}forEach(e,t){for(let n of this)e.call(t,n,n,this)}get size(){return this.atom_.reportObserved(),this.data_.size}add(e){if(Pt(this.atom_),Ur(this)){let t=Gr(this,{type:`add`,object:this,newValue:e});if(!t)return this;e=t.newValue}if(!this.has(e)){Ir(()=>{e=this.enhancer_(e,void 0),this.data_.add(e),this.atom_.reportChanged()});let t=vn(),n=Kr(this),r=n||t?{observableKind:`set`,debugObjectName:this.name_,type:`add`,object:this,newValue:e}:null;t&&bn(r),n&&Jr(this,r),t&&Sn()}return this}delete(e){if(Ur(this)&&!Gr(this,{type:fi,object:this,oldValue:e}))return!1;if(this.has(e)){let t=vn(),n=Kr(this),r=n||t?{observableKind:`set`,debugObjectName:this.name_,type:fi,object:this,oldValue:e}:null;return t&&bn(r),Ir(()=>{this.atom_.reportChanged(),this.data_.delete(e)}),n&&Jr(this,r),t&&Sn(),!0}return!1}has(e){return this.atom_.reportObserved(),this.data_.has(this.dehanceValue_(e))}entries(){let e=this.values();return bi({next(){let{value:t,done:n}=e.next();return n?{value:void 0,done:n}:{value:[t,t],done:n}}})}keys(){return this.values()}values(){this.atom_.reportObserved();let e=this,t=this.data_.values();return bi({next(){let{value:n,done:r}=t.next();return r?{value:void 0,done:r}:{value:e.dehanceValue_(n),done:r}}})}intersection(e){return new Set(this).intersection(e)}union(e){return new Set(this).union(e)}difference(e){return new Set(this).difference(e)}symmetricDifference(e){return new Set(this).symmetricDifference(e)}isSubsetOf(e){return new Set(this).isSubsetOf(e)}isSupersetOf(e){return new Set(this).isSupersetOf(e)}isDisjointFrom(e){return new Set(this).isDisjointFrom(e)}replace(e){return yi(e)&&(e=new Set(e)),Array.isArray(e)||C(e)?Ir(()=>{let t=C(e)?e:new Set(e);if(t.size===0){this.clear();return}if(this.data_.size===0){t.forEach(e=>this.add(e));return}for(let e of this.data_.values())t.has(this.dehanceValue_(e))||this.delete(e);t.forEach(e=>this.add(e))}):e!=null&&n(41,e),this}toJSON(){return Array.from(this)}toString(){return`[object ObservableSet]`}[Symbol.iterator](){return this.values()}get[Symbol.toStringTag](){return`Set`}},yi=b(`ObservableSet`,vi);function bi(e){return e[Symbol.toStringTag]=`SetIterator`,Ii(e)}let xi=Object.create(null),Si=`remove`;var Ci=class{constructor(e,t=new Map,r,i=He){this.target_=void 0,this.values_=void 0,this.name_=void 0,this.defaultAnnotation_=void 0,this.keysAtom_=void 0,this.changeListeners_=void 0,this.interceptors_=void 0,this.proxy_=void 0,this.isPlainObject_=void 0,this.appliedAnnotations_=void 0,this.pendingKeys_=void 0,this.lazyComputedKeys_=void 0,this.lazyObservableKeys_=void 0,this.target_=e,this.values_=t,this.name_=r,this.defaultAnnotation_=i,this.keysAtom_=new ae(`${this.name_}.keys`),this.isPlainObject_=g(this.target_),Ri(this.defaultAnnotation_)||n(`defaultAnnotation must be valid annotation`),this.appliedAnnotations_={}}getObservablePropValue_(e){return(this.values_.get(e)??this.materializeLazyComputed_(e)??this.materializeLazyObservable_(e)).get()}materializeLazyComputed_(e){let t=this.lazyComputedKeys_?.get(e);if(!t)return;this.lazyComputedKeys_.delete(e),this.lazyComputedKeys_.size===0&&(this.lazyComputedKeys_=void 0);let n=t();return this.values_.set(e,n),n}materializeLazyObservable_(e){let t=this.lazyObservableKeys_?.get(e);if(!t)return;this.lazyObservableKeys_.delete(e),this.lazyObservableKeys_.size===0&&(this.lazyObservableKeys_=void 0);let n=t();return this.values_.set(e,n),n}setObservablePropValue_(e,t){let n=this.values_.get(e)??this.materializeLazyComputed_(e)??this.materializeLazyObservable_(e);if(n instanceof Ot)return n.set(t),!0;if(Ur(this)){let n=Gr(this,{type:ei,object:this.proxy_||this.target_,name:e,newValue:t});if(!n)return null;t=n.newValue}if(t=n.prepareNewValue_(t),t!==P.UNCHANGED){let r=Kr(this),i=vn(),a=r||i?{type:ei,observableKind:`object`,debugObjectName:this.name_,object:this.proxy_||this.target_,oldValue:n.value_,name:e,newValue:t}:null;i&&bn(a),n.setNewValue_(t),r&&Jr(this,a),i&&Sn()}return!0}get_(e){return P.trackingDerivation&&!T(this.target_,e)&&this.has_(e),this.target_[e]}set_(e,t,n=!1){return T(this.target_,e)?this.values_.has(e)?this.setObservablePropValue_(e,t):n?Reflect.set(this.target_,e,t):(this.target_[e]=t,!0):this.extend_(e,{value:t,enumerable:!0,writable:!0,configurable:!0},this.defaultAnnotation_,n)}has_(e){if(!P.trackingDerivation)return e in this.target_;this.pendingKeys_||=new Map;let t=this.pendingKeys_.get(e);return t||(t=new Et(e in this.target_,me,`${this.name_}.${te(e)}?`,!1),this.pendingKeys_.set(e,t)),t.get()}extend_(e,t,n,r=!1){if(n===!0&&(n=this.defaultAnnotation_),n===!1)return this.defineProperty_(e,t,r);L(this,n,e);let i=n.extend_(this,e,t,r);return i&&Oi(this,n,e),i}defineProperty_(e,t,n=!1){Pt(this.keysAtom_);try{nn();let i=this.delete_(e);if(!i)return i;if(Ur(this)){let n=Gr(this,{object:this.proxy_||this.target_,name:e,type:`add`,newValue:t.value});if(!n)return null;let{newValue:i}=n;t.value!==i&&(t=r({},t,{value:i}))}if(n){if(!Reflect.defineProperty(this.target_,e,t))return!1}else a(this.target_,e,t);this.notifyPropertyAddition_(e,t.value)}finally{rn()}return!0}defineObservableProperty_(e,t,n,r=!1){Pt(this.keysAtom_);try{nn();let i=this.delete_(e);if(!i)return i;if(Ur(this)){let n=Gr(this,{object:this.proxy_||this.target_,name:e,type:`add`,newValue:t});if(!n)return null;t=n.newValue}let o=Ei(e),s={configurable:P.safeDescriptors?this.isPlainObject_:!0,enumerable:!0,get:o.get,set:o.set};if(r){if(!Reflect.defineProperty(this.target_,e,s))return!1}else a(this.target_,e,s);let c=new Et(t,n,`${this.name_}.${e.toString()}`,!1);this.values_.set(e,c),this.notifyPropertyAddition_(e,c.value_)}finally{rn()}return!0}defineComputedProperty_(e,t,n=!1){Pt(this.keysAtom_);try{nn();let r=this.delete_(e);if(!r)return r;if(Ur(this)&&!Gr(this,{object:this.proxy_||this.target_,name:e,type:`add`,newValue:void 0}))return null;t.name||=`${this.name_}.${e.toString()}`,t.context=this.proxy_||this.target_;let i=Ei(e),o={configurable:P.safeDescriptors?this.isPlainObject_:!0,enumerable:!1,get:i.get,set:i.set};if(n){if(!Reflect.defineProperty(this.target_,e,o))return!1}else a(this.target_,e,o);this.values_.set(e,new Ot(t)),this.notifyPropertyAddition_(e,void 0)}finally{rn()}return!0}delete_(e,t=!1){if(Pt(this.keysAtom_),!T(this.target_,e))return!0;if(Ur(this)&&!Gr(this,{object:this.proxy_||this.target_,name:e,type:Si}))return null;try{var n;nn();let r=Kr(this),a=vn(),o=this.values_.get(e),s;if(!o&&(r||a)&&(s=i(this.target_,e)?.value),t){if(!Reflect.deleteProperty(this.target_,e))return!1}else delete this.target_[e];if(delete this.appliedAnnotations_[e],o&&(this.values_.delete(e),o instanceof Et&&(s=o.value_),cn(o)),this.keysAtom_.reportChanged(),(n=this.pendingKeys_)==null||(n=n.get(e))==null||n.set(e in this.target_),r||a){let t={type:Si,observableKind:`object`,object:this.proxy_||this.target_,debugObjectName:this.name_,oldValue:s,name:e};a&&bn(t),r&&Jr(this,t),a&&Sn()}}finally{rn()}return!0}notifyPropertyAddition_(e,t){var n;let r=Kr(this),i=vn();if(r||i){let n=r||i?{type:`add`,observableKind:`object`,debugObjectName:this.name_,object:this.proxy_||this.target_,name:e,newValue:t}:null;i&&bn(n),r&&Jr(this,n),i&&Sn()}(n=this.pendingKeys_)==null||(n=n.get(e))==null||n.set(!0),this.keysAtom_.reportChanged()}ownKeys_(){return this.keysAtom_.reportObserved(),ee(this.target_)}keys_(){return this.keysAtom_.reportObserved(),Object.keys(this.target_)}};function wi(e,t){if(t&&Di(e)&&n(`Options can't be provided for already observable objects.`),T(e,O))return z(e)instanceof Ci||n(`Cannot convert '${ki(e)}' into observable object:\nThe target is already observable of different type.\nExtending builtins is not supported.`),e;Object.isExtensible(e)||n(`Cannot make the designated object observable; it is not extensible`);let r=t?.name??`${g(e)?`ObservableObject`:e.constructor.name}@${u()}`;return v(e,O,new Ci(e,new Map,String(r),rt(t))),e}let Ti=b(`ObservableObjectAdministration`,Ci);function Ei(e){return xi[e]||(xi[e]={get(){return this[O].getObservablePropValue_(e)},set(t){return this[O].setObservablePropValue_(e,t)}})}function Di(e){return h(e)?Ti(e[O]):!1}function Oi(e,t,n){e.appliedAnnotations_[n]=t}function L(e,t,r){if(Ri(t)||n(`Cannot annotate '${e.name_}.${r.toString()}': Invalid annotation.`),!ve(t)&&T(e.appliedAnnotations_,r)){let i=`${e.name_}.${r.toString()}`,a=e.appliedAnnotations_[r].annotationType_,o=t.annotationType_;n(`Cannot apply '${o}' to '${i}':\nThe field is already annotated with '${a}'.\nRe-annotating fields is not allowed.\nUse 'override' annotation for methods overridden by subclass.`)}}function R(e,t){if(typeof e==`object`&&e){if(ui(e))return t!==void 0&&n(23),e[O].atom_;if(yi(e))return e.atom_;if(mi(e)){if(t===void 0)return e.keysAtom_;let r=e.data_.get(t)||e.hasMap_.get(t);return r||n(25,t,ki(e)),r}if(Di(e)){if(!t)return n(26);let r=e[O],i=r.values_.get(t)??r.materializeLazyComputed_(t)??r.materializeLazyObservable_(t);return i||n(27,t,ki(e)),i}if(oe(e)||kt(e)||gn(e))return e}else if(p(e)&&gn(e[O]))return e[O];n(28)}function z(e,t){if(e||n(29),t!==void 0)return z(R(e,t));if(oe(e)||kt(e)||gn(e)||mi(e)||yi(e))return e;if(e[O])return e[O];n(24,e)}function ki(e,t){let n;if(t!==void 0)n=R(e,t);else if(Ln(e))return e.name;else n=Di(e)||mi(e)||yi(e)?z(e):R(e);return n.name_}function Ai(e){let t=Vt(),n=wt(!0);nn();try{return e()}finally{rn(),Tt(n),Ht(t)}}let ji=o.toString;function Mi(e,t,n=-1){return Ni(e,t,n)}function Ni(e,t,n,r,i){if(e===t)return e!==0||1/e==1/t;if(e==null||t==null)return!1;if(e!==e)return t!==t;let a=typeof e;if(a!==`function`&&a!==`object`&&typeof t!=`object`)return!1;let o=ji.call(e);if(o!==ji.call(t))return!1;switch(o){case`[object RegExp]`:case`[object String]`:return``+e==``+t;case`[object Number]`:return+e==+e?+e==0?1/e==1/t:+e==+t:+t!=+t;case`[object Date]`:case`[object Boolean]`:return+e==+t;case`[object Symbol]`:return typeof Symbol<`u`&&Symbol.valueOf.call(e)===Symbol.valueOf.call(t);case`[object Map]`:case`[object Set]`:n>=0&&n++;break}e=Pi(e),t=Pi(t);let s=o===`[object Array]`;if(!s){if(typeof e!=`object`||typeof t!=`object`)return!1;let n=e.constructor,r=t.constructor;if(n!==r&&!(p(n)&&n instanceof n&&p(r)&&r instanceof r)&&`constructor`in e&&`constructor`in t)return!1}if(n===0)return!1;n<0&&(n=-1),r||=[],i||=[];let c=r.length;for(;c--;)if(r[c]===e)return i[c]===t;if(r.push(e),i.push(t),s){if(c=e.length,c!==t.length)return!1;for(;c--;)if(!Ni(e[c],t[c],n-1,r,i))return!1}else{let a=Object.keys(e),o=a.length;if(Object.keys(t).length!==o)return!1;for(let s=0;s<o;s++){let o=a[s];if(!(T(t,o)&&Ni(e[o],t[o],n-1,r,i)))return!1}}return r.pop(),i.pop(),!0}function Pi(e){return ui(e)?e.slice():x(e)||mi(e)||C(e)||yi(e)?Array.from(e.entries()):e}let Fi=globalThis.Iterator?.prototype||{};function Ii(e){return e[Symbol.iterator]=Li,r(Object.create(Fi),e)}function Li(){return this}function Ri(e){return e instanceof Object&&typeof e.annotationType_==`string`&&p(e.make_)&&p(e.extend_)}{let e=globalThis;[`Symbol`,`Map`,`Set`,`Proxy`].forEach(t=>{e[t]===void 0&&n(`MobX requires global '${t}' to be available or polyfilled`)})}typeof __MOBX_DEVTOOLS_GLOBAL_HOOK__==`object`&&__MOBX_DEVTOOLS_GLOBAL_HOOK__.injectMobx({spy:Cn,extras:{getDebugName:ki},$mobx:O}),e.$mobx=O,e.FlowCancellationError=tr,e.ObservableMap=pi,e.ObservableSet=vi,e.Reaction=dn,e._allowStateChanges=Ct,e._allowStateChangesInsideComputed=In,e._allowStateReadsEnd=Ut,e._allowStateReadsStart=M,e._autoAction=Nn,e._autoActionBound=Fn,e._endAction=St,e._getAdministration=z,e._getGlobalState=Yt,e._interceptReads=ur,e._isComputingDerivation=Nt,e._resetGlobalState=Xt,e._startAction=xt,e.action=Mn,e.actionBound=Pn,e.autorun=Rn,e.compareDefault=de,e.compareIdentity=ce,e.compareShallow=ue,e.compareStructural=le,e.computed=j,e.computedStruct=mt,e.configure=qn,e.createAtom=se,e.defineProperty=Dr,e.entries=Sr,e.extendObservable=Jn,e.flow=ar,e.flowBound=or,e.flowResult=cr,e.get=Er,e.getAtom=R,e.getDebugName=ki,e.getDependencyTree=Yn,e.getObserverTree=Zn,e.has=Tr,e.intercept=dr,e.isAction=Ln,e.isBoxedObservable=Dt,e.isComputed=hr,e.isComputedProp=gr,e.isFlow=lr,e.isFlowCancellationError=nr,e.isObservable=vr,e.isObservableArray=ui,e.isObservableMap=mi,e.isObservableObject=Di,e.isObservableProp=yr,e.isObservableSet=yi,e.keys=br,e.makeAutoObservable=Zr,e.makeObservable=Yr,e.observable=A,e.observableDeep=lt,e.observableRef=st,e.observableShallow=ct,e.observableStruct=ut,e.observe=kr,e.onBecomeObserved=Un,e.onBecomeUnobserved=Wn,e.onReactionError=fn,e.override=_e,e.ownKeys=Or,e.reaction=Vn,e.remove=wr,e.runInAction=In,e.set=Cr,e.spy=Cn,e.toJS=Fr,e.transaction=Ir,e.untracked=Bt,e.values=xr,e.when=Lr})),wv=we(((e,t)=>{process.env.NODE_ENV===`production`?t.exports=Sv():t.exports=Cv()}))();function Tv(e){if(Array.isArray(e))return Object.freeze(e.map(Tv));if(typeof e==`object`&&e){let t=Object.create(null),n=Object.entries(e).sort(([e],[t])=>e<t?-1:+(e>t));for(let[e,r]of n)t[e]=Tv(r);return Object.freeze(t)}return e}function Ev(e){let t=typeof e;if(t===`string`||t===`number`||t===`boolean`)return t;throw TypeError(`Variable values must be string|number|boolean (got ${t})`)}function Dv(e){return typeof e==`string`?e:String(e)}function Ov(e){if(typeof e==`number`)return e;if(typeof e==`boolean`)return+!!e;let t=e.trim();if(t===``)throw TypeError(`Cannot cast empty string to number`);let n=Number(t);if(!Number.isFinite(n))throw TypeError(`Cannot cast ${JSON.stringify(e)} to number`);return n}function kv(e){if(typeof e==`boolean`)return e;if(typeof e==`number`){if(e===0||e===1)return e===1;throw TypeError(`Cannot cast number ${e} to bool (only 0 and 1 are accepted)`)}if(e===`true`)return!0;if(e===`false`)return!1;throw TypeError(`Cannot cast ${JSON.stringify(e)} to bool (expected "true" or "false")`)}var Av=class extends Error{constructor(e,t){super(t),this.variable=e}};function jv(e){return e instanceof Av||e instanceof Error&&e.cause!==void 0&&jv(e.cause)}var Mv=class extends Error{name=`TemplateError`;kind=`EvalError`;pos;source;constructor(e,t,n={}){super(e,{cause:n.cause}),this.pos=t,this.source=n.source}get sourceSnippet(){return this.source?Vv(this.source,this.pos):``}toString(){let e=`${this.name}: ${this.message}\n at line ${this.pos.line}, column ${this.pos.column}`,t=this.sourceSnippet;return t?`${e}\n\n${t}`:e}},Nv=class extends Mv{name=`ParseError`;kind=`ParseError`;expected;found;constructor(e,t,n={}){super(e,t,n),this.expected=n.expected,this.found=n.found}},Pv=class extends Mv{name=`EvalError`;kind=`EvalError`},Fv=class extends Pv{name=`FuncNotFoundError`;kind=`FuncNotFoundError`;funcName;suggestions;constructor(e,t,n={}){let r=Hv(e,n.available??[]),i=r.length===0?``:` (did you mean: ${r.join(`, `)}?)`;super(`function ${JSON.stringify(e)} is not registered${i}`,t,n),this.funcName=e,this.suggestions=r}},Iv=class extends Pv{name=`ArgCountError`;kind=`ArgCountError`;funcName;accepted;got;constructor(e,t,n,r,i={}){let a=t.minimum===t.maximum?`${t.minimum}`:`at least ${t.minimum}`;super(`wrong number of args for ${e}: want ${a} got ${n}`,r,i),this.funcName=e,this.accepted=t,this.got=n}},Lv=class extends Pv{name=`TypeMismatchError`;kind=`TypeMismatchError`;funcName;argIndex;expected;receivedSummary;constructor(e,t,n,r,i,a={}){super(`function ${JSON.stringify(e)} arg ${t}: expected ${n}, but a ${r} flowed in. Pass it through \`unstyled\` (or your engine's flatten function) to convert.`,i,a),this.funcName=e,this.argIndex=t,this.expected=n,this.receivedSummary=r}},Rv=class extends Lv{constructor(e,t,n,r,i={}){super(e,t,`integer`,String(n),r,i),this.message=Number.isInteger(Number(n))?`integer out of range: ${String(n)}`:`expected integer; found ${String(n)}`}},zv=class extends Pv{name=`MissingFieldError`;kind=`MissingFieldError`;path;constructor(e,t,n={}){super(`field "${e.join(`.`)}" not found on receiver`,t,n),this.path=e}},Bv=class extends Pv{name=`FailError`;kind=`FailError`;constructor(e,t={line:0,column:0,offset:0},n={}){super(e,t,n)}};function Vv(e,t){let n=e.split(`
|
|
53
|
+
`?[t+1,0]:[t,n+io(e)],a+=io(e),{glyph:e,cell:r}})}})}function sf(e){return[e.underline,e.underline2,e.strike,e.overline,e.frame,e.encircle].some(e=>e===!0)}function cf(e,t,n,r){let i=r.backgroundColor.hex,a,o=()=>t().flatMap(({look:e,glyphs:t})=>{if(e===void 0)return[];let n=e.pair.bg.hex!==i||sf(e.style);return t.flatMap(({glyph:e,cell:t})=>t!==void 0&&(e.trim()!==``||n)?[t]:[])}),s=e.flatMap(({segment:e,look:t})=>t!==void 0&&e.text.trim()!==``&&!wl(t.style.anchor,ju)?[t.pair]:[]),c=[...new Map(s.map(e=>[`${e.fg.hex}/${e.bg.hex}/${e.terminal.fg}/${e.terminal.bg}/${e.reverse}`,e])).values()],l=e=>c.flatMap(t=>t.terminal[e]?[]:[t[e].hex]);return{cells:()=>a??=o(),pairs:c,colors:new Set([...l(`fg`),...l(`bg`)]),fills:new Set(l(`bg`)),depth:n,theme:r}}function lf(e,...t){let n=new Set(t),r=e=>Nu(e.anchor,n),i=({fg:e,bg:t})=>e||t,a=e=>({...e,cells:()=>e.cells().filter(e=>i(r(e)))});return t=>ml.map(e(a(t)),e=>(t,n)=>{let a=r(n);if(!i(a))return t;let o=e(t,n);return{fg:a.fg?o.fg:t.fg,bg:a.bg?o.bg:t.bg}})}function uf(e,t){return t?{fg:e.bg,bg:e.fg}:e}function df(e,t,n,r){let i=t.bg.compositeOver(jo),a=t.fg.compositeOver(i);return{fg:H.matchMove(e.fg,a,n,r,!0),bg:H.matchMove(e.bg,i,n,r,!1)}}function ff(e,t){return pf(e.color,t.color,!0)&&pf(e.bgcolor,t.bgcolor,!1)}function pf(e,t,n){return e===t||mf(e,n)===mf(t,n)}function mf(e,t){return e?.getAnsiCodes(t).join(`;`)??``}function hf(e,t){return gf(e.fg,t.fg)&&gf(e.bg,t.bg)}function gf(e,t){return e.red===t.red&&e.green===t.green&&e.blue===t.blue&&e.alpha===t.alpha}const _f=(()=>{let e=[151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,88,237,149,56,87,174,20,125,136,171,168,68,175,74,165,71,134,139,48,27,166,77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,102,143,54,65,25,63,161,1,216,80,73,209,76,132,187,208,89,18,169,200,196,135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226,250,124,123,5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,223,183,170,213,119,248,152,2,44,154,163,70,221,153,101,155,167,43,172,9,129,22,39,253,19,98,108,110,79,113,224,232,178,185,112,104,218,246,97,228,251,34,242,193,238,210,144,12,191,179,162,241,81,51,145,235,249,14,239,107,49,192,214,31,181,199,106,157,184,84,204,176,115,121,50,45,127,4,150,254,138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180];return[...e,...e]})(),vf=e=>e*e*e*(e*(e*6-15)+10),yf=(e,t,n)=>e+n*(t-e);function bf(e,t,n,r){let i=e&15,a=i<8?t:n,o=i<4?n:i===12||i===14?t:r;return(i&1?-a:a)+(i&2?-o:o)}function xf(e,t,n){let r=Math.floor(e),i=Math.floor(t),a=Math.floor(n),o=r&255,s=i&255,c=a&255;e-=r,t-=i,n-=a;let l=vf(e),u=vf(t),d=vf(n),f=_f[o]+s,p=_f[f]+c,m=_f[f+1]+c,h=_f[o+1]+s,g=_f[h]+c,_=_f[h+1]+c;return yf(yf(yf(bf(_f[p],e,t,n),bf(_f[g],e-1,t,n),l),yf(bf(_f[m],e,t-1,n),bf(_f[_],e-1,t-1,n),l),u),yf(yf(bf(_f[p+1],e,t,n-1),bf(_f[g+1],e-1,t,n-1),l),yf(bf(_f[m+1],e,t-1,n-1),bf(_f[_+1],e-1,t-1,n-1),l),u),d)}function Sf(e,t,n,r){let i=0,a=1,o=0;for(let s=0;s<r;s++){let r=2**s;i+=a*xf(e*r,t*r,n*r),o+=a,a/=2}return i/o}function Cf(e,t){let n=Math.sin(e*12.9898+t*78.233)*43758.5453;return n-Math.floor(n)}function wf(e,t,n){let r=Math.min(1,Math.max(0,(n-e)/(t-e)));return r*r*(3-2*r)}const Tf=Array.from({length:48},(e,t)=>(t+1)/48);function Ef(e,t){return Math.min(No(e.fg,e.bg),4.5)-(t===V.TRUECOLOR?.01:0)}const Df=[`fg`,`bg`];function Of({pairs:e,depth:t,theme:n},r,i){let a=(e,t)=>e.terminal[t]?void 0:e[t].hex,o=new Map(e.flatMap(e=>Df.flatMap(t=>{let n=a(e,t);return n===void 0?[]:[[n,e[t]]]}))),s=new Map([...r].filter(e=>!o.has(e)).map(e=>[e,1])),c=e=>Vs.fromRgba(o.get(e)).l;for(let l of[...r].filter(e=>o.has(e)).sort((e,t)=>c(t)-c(e))){let r=e.flatMap(e=>{let t=Df.find(t=>a(e,t)===l);if(t===void 0)return[];let n=a(e,t===`fg`?`bg`:`fg`);return[[e,t,n===void 0?0:s.get(n)??0]]}),o=e=>r.every(([r,a,o])=>{let s=Ef(r,t),c=(t,n)=>Ff(i,r[t],(t===a?e:o)*n);return Tf.every(e=>{let i=nf.shows(r,{fg:c(`fg`,e),bg:c(`bg`,e)},t,n);return No(i.fg,i.bg)>=s})}),[c,u]=o(1)?[1,1]:[0,1];for(let e=0;e<20&&u-c>.001;e++){let e=(c+u)/2;[c,u]=o(e)?[e,u]:[c,e]}s.set(l,c)}return s}function kf(e,t){let n=new WeakMap;return Nf(Mf(e,r=>{let i=t??r.colors,a=[Af(r),`|`,...i].join(` `),o=n.get(r.theme)??new Qa;return n.set(r.theme,o),o.get(a,()=>Of(r,i,e.touch))}))}function Af({depth:e,pairs:t}){return[e,...t.map(jf)].join(` `)}function jf({fg:e,bg:t,terminal:n,reverse:r}){return`${e.hex}/${t.hex}/${n.fg}/${n.bg}/${r}`}function Mf(e,t){return n=>{let r=t(n);return ml.continuous(t=>{let i=e.field(t,n);return({fg:t,bg:n},a)=>{let o=Math.round(zf(i(a))*48)/48,s=(t,n)=>Ff(e.touch,t,(n?0:r.get(t.hex)??0)*o);return{fg:s(t,a.terminal.fg),bg:s(n,a.terminal.bg)}}})}}function Nf(e){return t=>Pf(t.depth)?ml.constant(e=>e):e(t)}function Pf(e){switch(e){case V.DEFAULT:case V.STANDARD:case V.WINDOWS:return!0;case V.EIGHT_BIT:case V.TRUECOLOR:return!1}}function Ff(e,t,n){return n===0?t:e(t,n)}function If(e){if(!(Number.isFinite(e.seconds)&&e.seconds>0))throw RangeError(`curve: seconds must be a positive number of seconds, got ${e.seconds}`);if(!(e.swing>=0&&e.swing<=1))throw RangeError(`curve: swing must be in [0, 1], got ${e.swing}`)}const Lf={shimmer:{seconds:109,ease:nl.linear,swing:.9},pulse:{seconds:43,ease:nl.linear,swing:.85},sparkle:{seconds:139,ease:nl.linear,swing:.95},wheel:{seconds:907,ease:nl.linear,swing:1},fade:{seconds:20,ease:nl[`ease-in-out`],swing:1},dissolve:{seconds:30,ease:nl[`ease-in-out`],swing:1}},Rf={sun:new B(255,228,176),firefly:new B(222,245,140)},zf=e=>Math.min(1,Math.max(0,e));function Bf(e,t,n){if(!(n>=0&&n<=1))throw RangeError(`blend: w must be in [0, 1]; got ${n}`);let r=Math.PI/180,i=(1-n)*e.c*Math.cos(e.h*r)+n*t.c*Math.cos(t.h*r),a=(1-n)*e.c*Math.sin(e.h*r)+n*t.c*Math.sin(t.h*r);return new Vs((1-n)*e.l+n*t.l,Math.hypot(i,a),Math.atan2(a,i)/r,e.alpha)}function Vf(e){let t=Vs.fromRgba(e);return(e,n)=>{let r=Vs.fromRgba(e);return Bf(r,new Vs(Math.max(r.l,t.l),t.c,t.h,t.alpha),n).toRgba()}}const Hf=(e,t)=>t*e[e.length-1][0];function Uf(e,t,n){let r=t/n,i=e.findIndex(([e])=>r<e);if(!(r>0)||i<0)return 0;let[a,o]=i===0?[0,0]:e[i-1],[s,c]=e[i];return n*(o+(c-o)*(1-Math.cos(Math.PI*(r-a)/(s-a)))/2)}function Wf(e,t,n){let r=Hf(e,n),i=t=>{let r=0;for(let i=0;i<24;i++)r+=Uf(e,(i+.5)/24*t,n);return r*t};return i(Math.min(Math.max(t,0),r))/i(r)}const Gf=[[.24,1],[.6,0]];function Kf(e,t,n){If(e);let r=.9+.2*Cf(n,3.1),i=t=>.1*xf(t/(3*e.seconds),.5,.5+n),a=i(0);return{touch:Vf(t),field:t=>{let o=r*t/e.seconds+i(t)-a,s=Math.floor(o),c=.7+.3*wf(-.5,.5,xf(s*.37,2.1,n)),l=.5-.5*Math.cos(2*Math.PI*(o-s)),u=e.swing*e.ease(c*l);return()=>u}}}const qf=e=>Math.abs(e)>=1?0:(1-e*e)**3;function Jf(e,t,n,r){If(e);let i=e.seconds,a=i/2,o=e=>wf(-.4,.4,xf(e/7,3.3,5.5+r)),s=.7,c=.51,l=.4,u=(e,n,u)=>{let d=o(e),f=(Cf(e,7.5+r)<.35+.6*d)*(.3+.7*d*(.6+.4*Cf(e,8.5+r))),p=i*u/80*(c+l*Cf(e,5.5+r)),m=zf((n-(e+s*Cf(e,6.5+r))*a)/p);return{strength:f,centre:m*u-t+.06*u*Math.sin(Math.PI*m)*xf(m,2.7,e+r)}},d=(e,t)=>{let n=s+(c+l)*i*t/80/a,r=Math.floor(e/a),o=[];for(let i=Math.max(0,Math.ceil(r-n));i<=r;i++)o.push(u(i,e,t));return o},f=(e,t,n)=>Math.exp(-((xf(e,t,n)/.8)**2));return{touch:Vf(n),field:(n,i)=>{let[a,o]=ep(i.cells().map(e=>e.col)),s=d(n,o-a+1+2*t);return i=>{let o=0;for(let{strength:e,centre:n}of s)o=Math.max(o,e*qf((i.col-a-n)/t));let c=i.row+r,l=.8*xf(i.col*.05,c*.3+1.3,n*.02),u=(f(i.col*.21+l,c*.9,n*.022)*f(i.col*.33+9.1-l,c*.7,n*.018+4.2))**2;return e.swing*e.ease(o*(.1+.6*u))}}}}function Yf(e,t,n){If(e);let r=e.seconds,i=22.1,a=3.1,o=(e,t,i,a,o)=>{let s=e*4.9+t*31.7+.3+n,c=e+.5+.7*xf(e*1.7+.2,.3+t*2.9,.5+n),l=i+Cf(e+t*1013,.7+n)*r,u=Math.floor(l/r),d=Cf(u,s+1)<.15?0:1,f=.5+.5*Cf(u,s+2),p=Cf(u,s+3)*(1-Hf(Gf,f)),m=l/r-u-p;return{x:a+c*8+5*(2*Cf(u,s+4)-1)+5*f*(2*Cf(u,s+5)-1)*Wf(Gf,m,f)+1.5*xf(s,.1,i*.035),y:o+t*3+.6*xf(s,2.2,i*.035),glow:d*Uf(Gf,m,f)}};return{touch:Vf(t),field:(t,n)=>{let r=n.cells(),[s,c]=ep(r.map(e=>e.col)),[l,u]=ep(r.map(e=>e.row)),d=e=>(e-s)/8-.5,f=e=>(e-l)/3,[p,m]=[Math.ceil(d(s-i)),Math.floor(d(c+i))],[h,g]=[Math.ceil(f(l-a)),Math.floor(f(u+a))],_=Array.from({length:g-h+1},(e,n)=>Array.from({length:m-p+1},(e,r)=>o(p+r,h+n,t,s,l)));return t=>{let n=0,[r,o]=[Math.max(p,Math.ceil(d(t.col-i))),Math.min(m,Math.floor(d(t.col+i)))],[s,c]=[Math.max(h,Math.ceil(f(t.row-a))),Math.min(g,Math.floor(f(t.row+a)))];for(let e=s;e<=c;e++)for(let i=r;i<=o;i++){let r=_[e-h][i-p];n=Math.max(n,r.glow*qf(Math.hypot(t.col-r.x,2*(t.row-r.y))/5))}return e.swing*e.ease(n)}}}}function Xf(e,t){return n=>{let r=Vs.fromRgba(n.theme.backgroundColor);return ml.continuous(i=>{let a=e(i,n);return(e,n)=>{let i=t*(1-zf(a(n)));if(i===0)return e;let o=Bf(Vs.fromRgba(e.bg),r,i);return{fg:Bf(Vs.fromRgba(e.fg),o,i).toRgba(),bg:o.toRgba()}}})}}function Zf(e){let t=new Map;return n=>{let r=`${n.row}:${n.col}`,i=t.get(r)??zf(.5+1.1*Sf(n.col*.09+1.4*xf(n.col*.035,n.row*.2+2.6,e+.5),n.row*.45,e,3));return t.set(r,i),i}}function Qf(e,t){let n=t=>t>=e.seconds;return{effect:r=>{let i=t(r);return{at:e=>i.at(e),nextChange:e=>n(e)?1/0:i.nextChange(e),lastChange:t=>n(t)?e.seconds:i.lastChange(t)}},done:n}}function $f(e,t){let n=new Map,r=e=>`${e.row}:${e.col}`;return i=>{let[a,o]=ep(i.map(t)),s=(o>a?.55:0)*e.seconds,c=pl.once(0,e.seconds-s),l=e=>{let n=o>a?zf((t(e)-a)/(o-a)):0;return{along:n,progress:e=>c(e-n*s)}};for(let e of i){let t=r(e);n.set(t,n.get(t)??l(e))}return e=>n.get(r(e))??l(e)}}function ep(e){let t=e[0]??0,n=t;for(let r of e)t=Math.min(t,r),n=Math.max(n,r);return[t,n]}function tp(e,t){If(e);let n=$f(e,Zf(1.7+t));return Qf(e,Xf((t,r)=>{let i=n(r.cells());return n=>e.ease(i(n).progress(t))},e.swing))}const np={depth:.4,from:.5,to:.95,maskFrom:.35,maskTo:.75,late:.6};function rp(e,t){If(e);let n=Zf(9.3+t),r=$f(e,Zf(4.2+t)),{depth:i,from:a,to:o,maskFrom:s,maskTo:c,late:l}=np;return Qf(e,Xf((t,u)=>{let d=r(u.cells());return r=>{let{along:u,progress:f}=d(r),p=e.ease(f(t)),m=zf((p-a)/(o-a)),h=i*wf(s,c,n(r))*(1-l+l*u)*Math.sin(Math.PI*m)**2;return 1-p+h}},e.swing))}const ip=[211,337];function ap(e,t){If(e);let n=e.seconds,r=e=>Cf(Number.parseInt(e.slice(1),16)*1e-4,17.3+t),i=(e,n)=>xf(n/ip[0],5.9+97*e,t)+.5*xf(n/ip[1],2.3+89*e,t+7.1),a=(t,a)=>{let o=r(t);return 360*a/n+e.swing*180*((i(o,a)-i(o,0))/1.5)},o=new WeakMap;return Nf(e=>{let{colors:t,fills:n,depth:r,theme:i}=e,s=(e,n)=>!e&&t.has(n.hex),c=(e,t,r)=>n.has(e.hex)||!r?e.hex:t.hex,l=(e,t)=>`${e.hex} ${t}`,u=o.get(i)??new Qa;o.set(i,u);let d=u.get(Af(e),()=>dp(e.pairs,r,(e,t)=>{let n=t===`fg`?`bg`:`fg`;return s(e.terminal[t],e[t])?l(e[t],c(e[t],e[n],s(e.terminal[n],e[n]))):void 0})),f=mp(r,i);return ml.continuous(e=>{let t=new Map,n=(t,n)=>{let i=op(t,a(n,e));return hp(i.looks,t,r===V.TRUECOLOR?i.either.map(fp):f,d.get(l(t,n))??cp)},i=(e,r)=>{let i=t.get(l(e,r))??n(e,r);return t.set(l(e,r),i),i};return(e,t)=>{let n={fg:s(t.terminal.fg,e.fg),bg:s(t.terminal.bg,e.bg)},r=(e,t,n,r)=>t?i(e,c(e,n,r)):e;return{fg:r(e.fg,n.fg,e.bg,n.bg),bg:r(e.bg,n.bg,e.fg,n.fg)}}})})}function op(e,t){if(t===0)return{looks:e,either:[e]};let n=Vs.fromRgba(e),r=Mo(e),i=e=>new Vs(e,n.c,n.h+t,n.alpha).toRgba(),[a,o]=[0,1];for(let e=0;e<24;e++){let e=(a+o)/2;[a,o]=Mo(i(e))<r?[e,o]:[a,e]}return{looks:i(o),either:[i(a),i(o)]}}const sp=e=>Math.log(No(e,new B(0,0,0))),cp={lo:-1/0,hi:1/0},lp={lo:1/0,hi:-1/0},up=Math.log(1.031);function dp(e,t,n){let r=new Map;for(let i of e.filter(e=>Ef(e,t)>1)){let e=(Math.log(No(i.fg,i.bg))-Math.log(Ef(i,t)))/Df.filter(e=>n(i,e)!==void 0).length;for(let t of Df){let a=n(i,t);if(a===void 0)continue;let[o,s]=[sp(i[t]),sp(i[t===`fg`?`bg`:`fg`])],{lo:c,hi:l}=r.get(a)??cp;r.set(a,o>=s?{lo:Math.max(c,o-e),hi:l}:{lo:c,hi:Math.min(l,o+e)})}}return new Map([...r].map(([e,{lo:t,hi:n}])=>[e,n-t<up?lp:{lo:t,hi:n}]))}const fp=e=>({color:e,looks:Vs.fromRgba(e),stop:sp(e)}),pp=new WeakMap;function mp(e,t){let n=H.indexed(e,t),r=pp.get(n)??n.map(([,e])=>fp(e));return pp.set(n,r),r}function hp(e,t,n,{lo:r,hi:i}){return gp(e,[fp(t),...n.filter(({stop:e})=>e>=r&&e<=i)]).color}function gp(e,t){let n=Vs.fromRgba(e),r;for(let e of t){let t=n.deltaE(e.looks);(r===void 0||t<r[1])&&(r=[e,t])}return r?.[0]}const _p={loops:{shimmer:(e,t=Lf.shimmer)=>kf(Jf(t,24,Rf.sun,e.z)),pulse:(e,t=Lf.pulse)=>kf(Kf(t,Rf.sun,e.z)),sparkle:(e,t=Lf.sparkle)=>kf(Yf(t,Rf.firefly,e.z)),wheel:(e,t=Lf.wheel)=>ap(t,e.z)},transitions:{fade:(e,t=Lf.fade)=>tp(t,e.z),dissolve:(e,t=Lf.dissolve)=>rp(t,e.z)}};var vp=class{beat;width;_shown;constructor(e){this.beat=fl(e.map(e=>e.seconds));let t=e.map(e=>tf(e.text.copy())),n=t.map(e=>e.cellLength);this.width=Math.max(...n),this._shown=t.map((e,t)=>(e.noWrap=!0,e.overflow=`crop`,e.padRight(this.width-n[t])))}at(e){return this._shown[this.beat.at(e)].copy()}nextChange(e){return this.beat.nextChange(e)}lastChange(e){return this.beat.lastChange(e)}};function yp(e,t){return e.at(t).copy().stylize(new U({nextChange:e.nextChange(t)}))}function bp(e,t){let n=[...Zl(e,t)],r=0;for(let e of n)r+=e.cellLength;return{segments:n,width:r}}const xp={segments:[],width:0},Sp={left:()=>0,justify:()=>0,center:e=>Math.floor(e/2),right:e=>e};function Cp(e,t){return Sp[e](t)}function wp(e,t,n,r){let i=Math.max(0,r-1),a=e===`justify`&&!t&&i>0&&n>0?n:0,o=i>0?Math.floor(a/i):0,s=a-o*i;return Array.from({length:i},(e,t)=>o+ +(t<s))}var Tp=class{items;joiner;gap;align;constructor(e,t){this.items=e,this.joiner=t?.joiner,this.gap=t?.gap??0,this.align=t?.align??`left`}contents(){return this.items}*render(e){let t=this.items;if(t.length===0)return;let n=Math.max(1,e.maxWidth),r=this.gap,i=this.joiner,a=t.map(t=>bp(Fu(t),e)),o=n=>i?bp(Pu(i,null,t[n],{index:n}),e):xp,s=n=>i?bp(Pu(i,t[n],null,{index:n+1}),e):xp,c=(n,r)=>i?bp(Pu(i,t[n],t[r],{index:r}),e):xp,l=[],u=null,d=r>0?{segments:[new G(` `.repeat(r))],width:r}:xp;for(let e=0;e<t.length;e++){let t=a[e];if(u===null){let n=o(e),r=s(e),i=n.width>0?[n,t]:[t],a=[i.length-1];u={blocks:i,width:n.width+t.width,lastIndex:e,itemBlockIndices:a},u.endCap=r;continue}let i=u.lastIndex,f=c(i,e),p=s(e),m=(r>0?r:0)+f.width+(r>0?r:0)+t.width;if(u.width+m+p.width<=n)r>0&&u.blocks.push(d),f.width>0&&u.blocks.push(f),r>0&&u.blocks.push(d),u.blocks.push(t),u.itemBlockIndices.push(u.blocks.length-1),u.width+=m,u.lastIndex=e,u.endCap=p;else{let n=u.endCap;n.width>0&&u.blocks.push(n),u.width+=n.width,l.push(u);let r=o(e),i=s(e),a=r.width>0?[r,t]:[t],c=[a.length-1];u={blocks:a,width:r.width+t.width,lastIndex:e,itemBlockIndices:c},u.endCap=i}}let f=u;{let e=f.endCap;e.width>0&&f.blocks.push(e),f.width+=e.width,l.push(f)}let p=this.align;for(let e=0;e<l.length;e++){let t=l[e],r=e===l.length-1,i=Math.max(0,n-t.width),a=Cp(p,i),o=wp(p,r,i,t.itemBlockIndices.length),s=new Map;t.itemBlockIndices.forEach((e,t)=>s.set(e,t)),a>0&&(yield new G(` `.repeat(a)));for(let e=0;e<t.blocks.length;e++){let n=s.get(e);if(n!==void 0&&n>0){let e=o[n-1];e>0&&(yield new G(` `.repeat(e)))}yield*t.blocks[e].segments}yield G.line()}}measure(e){let t=this.items;if(t.length===0)return{minimum:0,maximum:0};let n=0,r=0;for(let i=0;i<t.length;i++){let a=bp(t[i],e).width,o=this.joiner?bp(Pu(this.joiner,null,t[i],{index:i}),e).width:0,s=this.joiner?bp(Pu(this.joiner,t[i],null,{index:i+1}),e).width:0;n=Math.max(n,a+o+s),r+=a,i>0&&(r+=this.gap*2,this.joiner&&(r+=bp(Pu(this.joiner,t[i-1],t[i],{index:i}),e).width))}return this.joiner&&(r+=bp(Pu(this.joiner,null,t[0],{index:0}),e).width,r+=bp(Pu(this.joiner,t[t.length-1],null,{index:t.length}),e).width),{minimum:n,maximum:r}}};function Ep(e){return e<32||e>=127&&e<=159||e>=8234&&e<=8238||e>=8294&&e<=8303}function Dp(e){let t=``;for(let n of e)t+=Ep(n.codePointAt(0)??0)?` `:n;return t.replace(/\s+/g,` `).trim()}function Op(e,t){let n=Dp(e),r=``,i=0;for(let e of n){if(i===t)return r.replace(/.$/u,`…`);r+=e,i++}return r}const kp=`\x1B[38;2;255;255;255m`,Ap=`\x1B[48;2;200;40;40m`,jp=`\x1B[0m`;function Mp(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 Np={fg:Mp(kp),bg:Mp(Ap)},Pp={fg:Mp(`\x1B[38;2;0;0;0m`),bg:Mp(`\x1B[48;2;220;160;40m`)},Fp=new Ml({"strip.separator":`default`,"strip.rail":`default`});function Ip(e){return Fp.resolve(e)}function Lp(){let e=new WeakMap;return(t,n,r)=>{let i=e.get(t);i===void 0&&(i=new Map,e.set(t,i));let a=i.get(n);if(a!==void 0)return a;let o=r();return i.set(n,o),o}}const Rp=[`primary`,`secondary`,`accent`],zp=[`darken-3`,`darken-2`,`darken-1`,`base`,`lighten-1`,`lighten-2`,`lighten-3`],Bp={"darken-3":`-darken-3`,"darken-2":`-darken-2`,"darken-1":`-darken-1`,base:``,"lighten-1":`-lighten-1`,"lighten-2":`-lighten-2`,"lighten-3":`-lighten-3`,muted:`-muted`},Vp=(e,t)=>`${e}${Bp[t]}`,Hp=(e,t,n,r)=>xm(e,n,r),Up=(e,t,n,r)=>Cm(e,dm(e,`text-${t}`),n,r),Wp=e=>({tones:[zp[e],zp[e+2],zp[e+1]],text:Hp}),Gp={muted:{tones:[`muted`],text:Up},deepest:Wp(0),deeper:Wp(1),middle:Wp(2),brighter:Wp(3),brightest:Wp(4)},Kp=1/0,qp={accent:{hues:[`secondary`,`accent`],run:Kp},duo:{hues:[`primary`,`secondary`],run:Kp},mono:{hues:[`primary`],run:Kp},alt:{hues:[`secondary`,`accent`],run:3}},Jp=e=>e.variation.hues.flatMap(t=>e.shade.tones.map(e=>({hue:t,shade:e}))),Yp=e=>{let t=0,n=.5;for(let r=e;r>0;r>>=1,n/=2)t+=n*(r&1);return t},Xp=[`van-der-corput`,`golden-angle`,`ends-interleaved`,`monotonic`,`uniform`],Zp=e=>typeof e==`string`&&Xp.includes(e),Qp={"van-der-corput":Yp,"golden-angle":e=>e*.6180339887498949%1,"ends-interleaved":(e,t)=>((e%2==0?e/2:t-1-(e-1)/2)+.5)/t,monotonic:(e,t)=>(e+.5)/t,uniform:()=>.5},$p=e=>Qp[e??`van-der-corput`];function em(e){let t=0,n=1;for(let{index:r,count:i,distribution:a}of e)t+=a(r,i)*n,n*=.37;return t%1}const tm=(e,t)=>Math.floor(e*t),nm=(e,t)=>Math.round(e*t)%t;function rm(e){return e===void 0?0:e.distribution(e.index,e.count)}function im(e,t,n){let r=e[n(rm(t),e.length)];if(r===void 0)throw Error(`vocabularySelect: empty vocabulary`);return r}function am(e){let t=e.findIndex(e=>e.axis===`cell`),n=t===-1?e:e.slice(0,t);return{row:n.at(-1),cell:e[n.length]}}const om=(e,t)=>tm(rm(t),e.hues.length);function sm(e,t){let{row:n,cell:r}=am(t);return cm(e,n,r)}function cm(e,t,n){let{hues:r,run:i}=e.variation,a=n===void 0?0:Math.floor(n.index/i),o=r[(om(e.variation,t)+a)%r.length];if(o===void 0)throw Error(`decorEntryFor: empty variation`);return{hue:o,shade:im(e.shade.tones,n,nm)}}function lm(e,t){let{row:n,cell:r}=am(t),i=r===void 0?[void 0]:Array.from({length:r.count},(e,t)=>({...r,index:t}));return[...new Map(i.map(t=>cm(e,n,t)).map(e=>[Vp(e.hue,e.shade),e])).values()].sort((e,t)=>Rp.indexOf(e.hue)-Rp.indexOf(t.hue)||um.indexOf(e.shade)-um.indexOf(t.shade))}const um=[...zp,`muted`];function dm(e,t){let n=e.get(t);if(n===void 0)throw Error(`palette "${e.name}" has no "${t}" role; decoration needs it`);return n}const fm=(e,t)=>dm(e,Vp(t.hue,t.shade)),pm=2.2,mm=(e,t)=>t.map(t=>fm(e,t)),hm=e=>t=>ec(t,e),gm=hm(V.TRUECOLOR);function _m(e,t,n,r){return vm(e,`${t}|${n.map(e=>e.hex).join(`+`)}|${r}`,()=>ym(e,t,n,r))}const vm=Lp();function ym(e,t,n,r){let i=n.map(gm),a=dm(e,t),o=new B(0,0,0),s=new B(255,255,255),c=(e,t)=>Vs.fromRgba(a).mixAxes(Vs.fromRgba(e),{l:t,c:0,h:0,alpha:0}).toRgba(),l=e=>Array.from({length:12},(t,n)=>c(e,(n+1)/12)),u=l(o),d=[a,...l(s).flatMap((e,t)=>[e,u[t]])],f=e=>{let t=hm(e),n=i.map(t);return e=>Math.min(1/0,...n.map(n=>No(t(e),n)))},p=f(V.TRUECOLOR),m=f(r),h=e=>$s(e,r,(e,t)=>i.every(n=>No(e,t(n))>=pm)),g=e=>p(e)>=2.2&&h(e)!==void 0,_=(e,t)=>{let n=n=>No(gm(n),e)-No(gm(n),t),r=n(a)<0?o:s,i=r===o?1:-1,[l,u]=[0,1];for(let e=0;e<40;e++){let e=(l+u)/2;i*n(c(r,e))>0?u=e:l=e}return[c(r,l),c(r,u)]},v=()=>{let e=[...i].sort((e,t)=>Mo(e)-Mo(t));return e.slice(1).flatMap((t,n)=>_(t,e[n]))},y=d.find(g)??[...d,...v()].reduce((e,t)=>m(t)>m(e)?t:e),b=h(y)??y,x=m(b);return{anchor:y,state:b,short:x>=2.2?null:x}}const bm=4.5;function xm(e,t,n){return Sm(e,`${t.hex}|${n}`,()=>{let r=Zs(t);return Cm(e,[`background`,`foreground`].map(t=>dm(e,t)).reduce((e,t)=>No(r,t)<No(r,e)?t:e),t,n)})}const Sm=Lp();function Cm(e,t,n,r){return wm(e,`${t.hex}|${n.hex}|${r}`,()=>Qs(t,n,bm,r))}const wm=Lp();function Tm(e,t,n){return t.depth===0?mm(e,t.ground):Em(e,t,n)}const Em=(e,t,n)=>t.depth===0?[]:[Lm(e,{...t,depth:t.depth-1},n).plane],Dm=(e,{short:t},n)=>t===null?[]:[`theme "${e.name}": no open-trigger colour stands ${pm}:1 off every cell beside it — the nearest stands ${t.toFixed(2)}:1 as drawn at depth ${V[n]}; another shade or variation clears it`],Om=(e,t,n)=>t>=Mm.triggerPlane?[]:[`theme "${e.name}": an open band's plane stands ΔE ${t.toFixed(3)} off the trigger that opened it as drawn at depth ${V[n]}, under the ${Mm.triggerPlane} that tells them apart; another style clears it`],km={base:.42,perDepth:.14,cap:.75},Am={floor:.12,span:.8};function jm(e,t){return Rp[(Rp.indexOf(e)+t)%Rp.length]}const Mm={triggerPlane:.1,nestedPlane:.035};function Nm(e,t,n){return Pm(e,`${Fm(t)}|${n}`,()=>{let r=_m(e,jm(t.hue,t.depth),Tm(e,t,n),n),{state:i}=r,a=Vm(e,t,i,n),o=$s(Lm(e,t,n).plane,n,(e,t)=>a.every(n=>n(e,t)));if(o===void 0)throw Error(`palette "${e.name}": the ${t.hue} band at depth ${t.depth} cannot keep its floors on the colours drawn at depth ${V[n]}`);let s=hm(n);return{state:i,plane:o,shortfalls:n===V.DEFAULT?[]:[...Dm(e,r,n),...Om(e,Im(s(i),s(o)),n)]}})}const Pm=Lp(),Fm=({hue:e,depth:t,ground:n})=>`${e}|${t}|${n.map(e=>Vp(e.hue,e.shade)).join(`+`)}`,Im=(e,t)=>Vs.fromRgba(e).deltaE(Vs.fromRgba(t));function Lm(e,t,n){return Rm(e,`${Fm(t)}|${n}`,()=>zm(e,t,n))}const Rm=Lp();function zm(e,t,n){let{anchor:r}=_m(e,jm(t.hue,t.depth),Tm(e,t,n),n),i=Math.min(km.cap,km.base+km.perDepth*t.depth),a=(t,n)=>fs(r,dm(e,t),n),o=Em(e,t,n),s=e=>Im(gm(r),gm(e))>=Mm.triggerPlane&&o.every(t=>Im(gm(t),gm(e))>=Mm.nestedPlane),c=a(`background`,i);return{state:r,plane:[c,a(`foreground`,i),a(`background`,km.cap),a(`foreground`,km.cap),...Bm.toSorted((e,t)=>Math.abs(e-i)-Math.abs(t-i)).flatMap(e=>[a(`background`,e),a(`foreground`,e)])].find(s)??c}}const Bm=Array.from({length:12},(e,t)=>(t+1)/12);function Vm(e,t,n,r){let{hue:i,depth:a,ground:o}=t,s=t=>Lm(e,{hue:i,depth:t,ground:o},r).state,c=t=>Lm(e,{hue:i,depth:t,ground:o},r).plane,l=c(a),u=(e,t)=>Im(gm(l),gm(t))>=e?e:0,d=_m(e,jm(i,a+1),Tm(e,{hue:i,depth:a+1,ground:o},r),r),f=No(gm(l),gm(d.anchor))>=2.2?pm:0,p=(e,t)=>(n,r)=>Im(n,r(e))>=t;return[p(n,u(Mm.triggerPlane,s(a))),(e,t)=>No(e,t(d.state))>=f,...a>0?[p(Nm(e,{hue:i,depth:a-1,ground:o},r).plane,u(Mm.nestedPlane,c(a-1)))]:[]]}function Hm(e,t,n,r){let i=Nm(e,t,r),a=Lm(e,t,r),o=e=>fs(a.plane,a.state,e),s=Am.floor+Am.span*em(n),c=Am.floor+Am.span/2,l=(e,t)=>e.hex!==t(i.plane).hex&&e.hex!==t(i.state).hex;for(let e=0;e<=12;e++){let t=$s(o(s+(c-s)*e/12),r,l);if(t!==void 0)return t}return o(s)}const Um=e=>({kind:`bar`,decor:e,address:[]}),Wm=(e,t)=>({...e,address:[...e.address,t]}),Gm=e=>({kind:`band`,band:e,address:[]});function Km(e,t,n){switch(t.kind){case`bar`:{let{decor:r,address:i}=t,a=sm(r,i),o=fm(e,a),s;return{tint:o,text:r.shade.text(e,a.hue,o,n),disclosure:{hue:`accent`,depth:0,get ground(){return s??=lm(r,i)}}}}case`band`:{let{band:r,address:i}=t,a=Hm(e,r,i,n);return{tint:a,text:xm(e,a,n),disclosure:{...r,depth:r.depth+1}}}}}const qm=new Map([[`dark`,`textual-dark`],[`light`,`textual-light`]]);function Jm(e){let t=typeof e==`string`?qm.get(e):void 0;return t===void 0?``:` — "${e}" was retired; write "${t}", the same palette`}const Ym=`textual-dark`;function Xm(e,t,n,r,i){let a=t===null?null:i(t);return e??a??n??r}function Zm(){return xc()}function Qm(){return[`bar`,...Zm()]}let $m;function eh(e){return $m??=new Set(Qm()),$m.has(e)}function th(e,t,n,r,i){let a=e=>Object.prototype.hasOwnProperty.call(i,e)?e:null;return Xm(e===void 0?null:a(e),t,a(n??r),r,a)}const nh=[`style`,`palette`,`effect`];function rh(e){return e!==void 0&&e.includes(`{{`)}function ih(e,t,n,r,i){let a=rh(n)?{kind:`expression`,source:n}:i(n??r.name);return Xm(e===void 0?null:i(e),t,a,r,i)}function ah(e,t){return e.kind===`decided`?e:t(e.source)}const oh=`none`;function sh(e,t){let n=t[e];return n===void 0?null:{kind:`decided`,name:e,value:n}}function ch(e,t){return sh(e,t)??sh(`none`,t)??{kind:`decided`,name:`none`,value:As}}function lh(e,t,n,r){return ih(e,t,n,ch(oh,r),e=>sh(e,r))}const uh=`none`,dh={style:oh,palette:Ym,effect:uh};function fh(e,t,n){return`${e} rendered "${dh[t]}": ${n}`}const ph=Object.freeze([uh,...Object.keys(_p.loops)]),mh=Object.freeze([`bar`,...ph]);function hh(e){let t=ph.find(t=>t===e);return t===void 0?null:{kind:`decided`,name:e,value:t}}function gh(e){return hh(e)??{kind:`decided`,name:`none`,value:`none`}}function _h(e,t,n){return ih(e,t,n,gh(uh),hh)}const vh=Object.freeze(Object.keys(Bd));function yh(e){return vh.includes(e)}const bh=[`powerline`,`capsule`,`plain`];function xh(e){return bh.includes(e)}function Sh(e,t,n){return Xm(e,t,n,`powerline`,e=>yh(e)?e:null)}const Ch=[`truecolor`,`256`,`ansi`,`none`];function wh(e){return Ko(e)??V.DEFAULT}const Th=Object.keys(qp);function Eh(e){return Th.includes(e)}function Dh(e,t,n){return Xm(e,t,n,`accent`,e=>Eh(e)?e:null)}const Oh=Object.keys(Gp);function kh(e){return Oh.includes(e)}function Ah(e,t,n){return Xm(e,t,n,`middle`,e=>kh(e)?e:null)}const jh=`true`,Mh=`false`,Nh=[jh,Mh],Ph={min:0,max:16};function Fh(e){return e===`true`?!0:e===`false`?!1:null}function Ih(e,t){let n=Number(e);return Number.isInteger(n)&&String(n)===e&&n>=t.min&&n<=t.max?n:null}function Lh(e){return Ih(e,Ph)}function Rh(e,t,n){return Xm(e,t,n,!0,Fh)}function zh(e,t,n){return Xm(e,t,n,!0,Fh)}function Bh(e,t,n){return Xm(e,t,n,!1,Fh)}function Vh(e,t,n){return Xm(e,t,n,1,Lh)}const Hh={kind:`still`},Uh=Symbol(`bar`);function Wh(e){return e.name!==uh}function Gh(e,t){return n=>ml.map(ml.all(t.map(({t,effect:r})=>Sl.run(Sl.play(e-t),r(n)))),e=>(t,n)=>e.reduce((e,t)=>t(e,n),t))}const Kh=Ac;function qh(e,t){let n=new ps(t,Kh.foregroundColor,Kh.ansiColors,Kh.palette);return t=>e({...t,theme:n})}function Jh(e,t){return n=>lf(()=>e(n),...t)(n)}function Yh(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 Xh=4096;var Zh=class{inForce=null;placements=new Map;made=new Map;drawn=null;frame={effect:uh,t:0,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.drawn?.placements.values()??[]].filter(({passage:e})=>e!==null).length;return[...this.made.values()].reduce((e,t)=>e+t.size,e)}motion(e,t,n){let r=this.inForce?.name===e?this.inForce:{name:e,since:t},i={scope:Uh,name:e,t:t-r.since},a=this.placements,o=new Map,s=this.made,c=new Map,l=[],u=this.drawn,d=n.transitions?u!==null&&u.source.config===n.source.config&&u.source.preset===n.source.preset&&u.source.revision===n.source.revision&&u.source.width===n.source.width?`compared`:`fresh`:`off`,f=d===`compared`?u.placements:null,p=new Map,m=[],h=[],g={effect:e,t:i.t,made:0,reused:0,own:l,basis:d,revision:n.source.revision,fades:m,leaves:h},_=(e,n,{ground:r})=>{let i=_p.transitions[e]({z:Yh(`${this.key}@${n}`)*Xh});return{name:e,since:t,transition:{effect:qh(i.effect,r),done:e=>i.done(e)}}},v=({since:e,transition:n})=>n.done(t-e),y=(e,t,n)=>({drawing:t,passage:f===null?null:n===void 0||n.passage?.name===`dissolve`?_(`fade`,e,t):n.passage!==null&&!v(n.passage)?n.passage:null}),b=(e,t)=>{if(t===void 0||t.drawing.own.length===0)return;if(t.passage?.name===`dissolve`)return v(t.passage)?void 0:t;let r={...t.drawing,own:t.drawing.own.map(n.hold)};return{drawing:r,passage:_(`dissolve`,e,r)}},x=(e,r)=>{if(p.has(e))throw Error(`placement "${e}" was reached twice in one frame`);let i=f?.get(e),{drawing:a,deeper:o}=n.returned(e,r),s=a===null?b(e,i):y(e,a,i);return s===void 0?r:(p.set(e,s),s.passage!==null&&(s.passage.name===`fade`?m:h).push({placement:e,t:t-s.passage.since}),a===null?[...s.drawing.own,...o]:r)},S=(e,n)=>{let r=o.get(e)??a.get(e),i=r?.name===n?r:{name:n,since:t},s=t-i.since;return o.has(e)||(o.set(e,i),l.push({placement:e,effect:n,t:s})),{scope:e,name:n,t:s}},C=(e,t)=>{let n=c.get(e)??new Map;c.set(e,n);let r=n.get(t.scope);if(r!==void 0)return r.effect;let i=s.get(e)?.get(t.scope),a=i?.name===t.name,o=Yh(t.scope===Uh?e:`${e}@${t.scope}`),l=a?i.effect:_p.loops[t.name]({z:o*Xh});return g[a?`reused`:`made`]++,n.set(t.scope,{name:t.name,effect:l}),l},w=e=>{let t=new Map;for(let{owner:n,placement:r}of e){let e=r.effect===`bar`?i:S(r.id,r.effect),a=t.get(e.scope);a===void 0?t.set(e.scope,{...e,owners:[n]}):a.owners.push(n)}return[...t.values()]},ee=e=>{let n=new Map;for(let{owner:t,placement:r}of e){let e=n.get(r.id);e===void 0?n.set(r.id,[t]):e.push(t)}return[...n].flatMap(([e,n])=>{let r=p.get(e)?.passage??null;return r===null?[]:[{t:t-r.since,effect:lf(r.transition.effect,...n)}]})};return{placed:d===`off`?(e,t)=>t:x,row:(e,t)=>{let n=(t.some(e=>e.placement.effect!==`bar`)?w(t):[{...i,owners:void 0}]).filter(Wh),r=ee(t);if(n.length===0&&r.length===0)return Hh;let a=`${this.key}#${e}`;return{kind:`moving`,wrap:e=>new nf(e,Gh(i.t,[...n.map(e=>{let t=C(a,e);return{t:e.t,effect:e.owners===void 0?t:Jh(t,e.owners)}}),...r]),{t:i.t,key:a,theme:Kh})}},drawn:()=>{this.inForce=r,this.placements=o,this.made=c,this.drawn=d===`off`?null:{source:n.source,placements:p},this.frame=g}}}},Qh=class{sessions=new Map;constructor(e=256){this.maxSessions=e}of(e){let t=this.sessions.get(e)??new Zh(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 $h(e,t){let n=Go(t.colorSystem),r=[...Zl(e,{maxWidth:t.width??80,isTerminal:!1,asciiOnly:!1,theme:Fp,colorSystem:n.colorSystem,onStyleError:e=>{throw e}})];return{text:Hd(r,n),moves:Number.isFinite(G.nextChange(r))}}const eg=new Map;function tg(e){let t=eg.get(e);if(t!==void 0)return t;let n=t=>{let n=t.seam.map(t=>`cap`in t?t:{...t,glyph:e});return{seam:n,divider:n}},{seam:r,caps:i}=Bd.plain,a=new ld({glyph:n(r.glyph),ascii:r.ascii},i);return eg.set(e,a),a}function ng(e,t){return e===`plain`&&t!==void 0?tg(t):Bd[e]}const rg=new Map;function ig(e){let t=JSON.stringify([e.endcaps,e.separator??null]),n=rg.get(t);if(n!==void 0)return n;let r=ng(e.endcaps,e.separator),i=e=>new K(`x`,{end:``,overflow:`ignore`,style:new U({bgcolor:e})}),a=e=>new K($h(new Iu(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 rg.set(t,s),s}function ag(e){return ig(e).chrome}function og(e){return ig(e).seam}const sg=/[\u{E000}-\u{F8FF}\u{F0000}-\u{FFFFD}\u{100000}-\u{10FFFD}]/gu;function cg(e){return[...new Set(e.match(sg)??[])].join(``)}function lg(e){let t=ng(e.endcaps,e.separator),n=e=>new K(`x`,{end:``,style:new U({bgcolor:e})});return cg($h(new Iu([n(`#101010`),n(`#202020`),n(`#202020`)],t),{colorSystem:null}).text)}function ug(e,t,n=Hh){if(e.length===0)return{text:``,moves:!1};let r=ng(t.endcaps,t.separator),i=t.wrap&&Number.isFinite(t.width),a={colorSystem:t.colorCompatibility,...i?{width:t.width}:{}},o=i?new Tp([...e],{joiner:r}):new Iu([...e],r),s=$h(n.kind===`still`?o:n.wrap(o),a);if(!s.text.endsWith(`
|
|
54
|
+
`))throw Error(`drawStripCells: rich-js strip output did not end its last line`);return{text:s.text.slice(0,-1),moves:s.moves}}function dg(e,t){return ug(e,t).text}function fg(e){return Math.min(20,e??20)}const pg={heading:`ERROR`,glyph:`⚠`,colors:Np},mg={heading:`WARNING`,glyph:`⚠`,colors:Pp},hg={heading:`UPDATE`,glyph:`⬆`,colors:Pp};function gg(e,t){return{text:Dp(e),link:t}}function _g(e,t,n){let[r,...i]=[vg(e,pg,In),t,vg(n,mg,Ln)].flat();return r===void 0?null:{channels:[r,...i]}}function vg(e,t,n){let r=I([{verb:n,args:[e]}]),[i,...a]=e.split(/\r\n|\r|\n/).map(e=>gg(e,r)).filter(e=>e.text!==``).map(e=>[e]);return i===void 0?[]:[{severity:t,message:e,lines:[i,...a]}]}function yg(e){return e.channels.map(e=>`${e.severity.heading}\n${e.message}\n`).join(`
|
|
55
|
+
`)}function bg(e,t,n,r){if(t===null)return e;let i=xg(r),a=t.channels.flatMap(e=>Sg(e,i)),o=n.failedConfigFile!==null||a.length>r.rowCap,s=a.slice(0,r.rowCap-Number(o)),c=o?[Cg(t,n,a.length-s.length,i)]:[],l=[...s,...c].join(`
|
|
56
|
+
`);return e?`${l}\n${e}`:l}function xg(e){return{endcaps:`plain`,separator:``,width:e.width,wrap:!0,padding:0,colorCompatibility:e.colorCompatibility}}function Sg(e,t){let n=new U({bgcolor:e.severity.colors.bg,color:e.severity.colors.fg}),r=ao(Math.max(2,t.width-1)),i=(e,t)=>new K(`${e} `,{style:t,end:``,overflow:`ignore`});return e.lines.flatMap((a,o)=>dg([i(o===0?e.severity.glyph:` `,n.withLink(a[0].link)),...a.flatMap(e=>{let t=n.withLink(e.link);return e.text.split(` `).flatMap(e=>uo(e,r)).map(e=>i(e,t))})],t).split(`
|
|
57
|
+
`))}function Cg(e,t,n,r){let{colors:i}=e.channels[0].severity,{fullText:o,failedConfigFile:s}=t,c=new U({bgcolor:i.bg,color:i.fg}),l=(e,t)=>new K(e,{style:t,end:``,overflow:`ignore`}),u=n>0?[l(`${n} more rows · `,c),o.kind===`file`?l(`open full text`,c.withLink(a(o.path).href)):l(`full text unavailable: ${Dp(o.reason)}`,c)]:[],d=s===null?[]:[l(`${u.length>0?` · `:``}open `,c),l(Dp(s),c.withLink(a(s).href))],f=[l(`↳ `,c),...u,...d.slice(0,-1)],p=f.reduce((e,t)=>e+t.cellLength,0),m=d.slice(-1).map(e=>e.truncate(Math.max(1,r.width-p),{mode:`middle`})),h=K.fromFragments([...f,...m]).truncate(r.width);return h.overflow=`ignore`,dg([h],r)}const wg=e=>!e.startsWith(`.`)&&!e.endsWith(`~`);function Tg(e,t){return t.isSymbolicLink()?Buffer.from(s.readlinkSync(e)):s.readFileSync(e)}function Eg(e,t,n=wg){return s.readdirSync(t).filter(n).sort().flatMap(n=>{let r=v.join(t,n),i=s.lstatSync(r,{throwIfNoEntry:!1});return i===void 0?[]:i.isDirectory()?Eg(e,r):[[v.relative(e,r).split(v.sep).join(`/`),Tg(r,i)]]})}function Dg(e){let t=O.createHash(`sha256`);for(let[n,r]of e)t.update(n).update(`\0`).update(r).update(`\0`);return t.digest(`hex`)}function Og(e){return Dg(Eg(e,e))}const kg=[`Cargo.toml`,`Cargo.lock`,`src`];function Ag(e){return Dg(Eg(e,e,e=>kg.includes(e)))}const jg=e=>e.slice(0,7);function Mg(e){let t=v.dirname(v.dirname(e));return s.existsSync(v.join(t,`src`))?t:null}function Ng(){let e=Pg();if(e===null)throw Error("this bundle carries no source digest (build via `pnpm build`, which stamps it)");return{version:Ft,digest:e}}function Pg(){return`17f912957df3846a382ecf71f9fd84524dacc9505a85bd355211c3e4d9afff5e`}function Fg(e){let t=JSON.parse(s.readFileSync(v.join(e,`package.json`),`utf8`)),n=typeof t==`object`&&t?t.version:void 0;if(typeof n!=`string`)throw Error(`${v.join(e,`package.json`)} has no version string`);return n}function Ig(e,t){try{let n=Mg(i(e));if(n===null)return{kind:`not-source-checkout`};let r=t(),a=Og(v.join(n,`src`));return a===r.digest?{kind:`current`,root:n,stamp:r}:{kind:`stale`,root:n,source:{version:Fg(n),digest:a},running:r}}catch(e){return{kind:`unchecked`,reason:e.message}}}var q=class extends Error{constructor(e){super(e),this.name=`BadVerbArgs`}};const Lg=new Map;function Rg(e){let t=Bg(e);if(t===null)throw Error(`Palette "${e}" did not resolve in the theme registry — allowed names and the registry are inconsistent`);return t}function zg(e,t){return e===`bar`?t:Rg(e)}function Bg(e){let t=Lg.get(e);if(t!==void 0)return t;let n=Sc(e);return n===null?null:(Lg.set(e,n),n)}function Vg(e,t){return Hg(e,`${t.hueShift} ${t.chromaScale} ${t.lightnessScale} ${t.lightnessShift}`,()=>Pc(e,t))}const Hg=Lp();function Ug(e){let t=Bg(e);return t===null?null:{kind:`decided`,name:e,value:t}}function Wg(e,t,n){let r=Ug(e);return r===null?(n(fh(t,`palette`,`"${e}" names no installed theme${Jm(e)}`)),Kg()):r}function Gg(e,t,n){return ih(e,t,n,Kg(),Ug)}function Kg(){return{kind:`decided`,name:Ym,value:Rg(Ym)}}const qg=[`vertical`,`horizontal`],Jg={vertical:`row`,horizontal:`cell`};function Yg(e){return e.id??e.name}function Xg(e){return[...$g(e)].flatMap(e=>e.kind===`segment`?[Yg(e)]:[])}function Zg(e,t){if(!t.has(e))return e;let n=2;for(;t.has(`${e}-${n}`);)n++;return`${e}-${n}`}function Qg(e,t){return e.opens===void 0?e:{...e,opens:{...e.opens,body:t(e.opens.body)}}}function*$g(e){yield e;for(let t of r_(e))yield*$g(t)}const e_=(e,t)=>`${e}.children[${t}]`,t_=e=>`${e}.opens.body`;function*n_(e,t){if(yield[e,t],e.kind===`container`)for(let[n,r]of e.children.entries())yield*n_(r,e_(t,n));else e.opens!==void 0&&(yield*n_(e.opens.body,t_(t)))}function r_(e){return e.kind===`container`?e.children:e.opens===void 0?[]:[e.opens.body]}const i_=[`shade`,`variation`,`style`];function a_(e){return e===void 0||`text`in e?`text`:`regex`in e?`regex`:`json`}const o_=[`ttl`,`watch_file`,`depends_on`,`key`,`never`];function s_(e){return e.kind===`file`||e.kind===`shell`}const c_=[`branch`,`sha`,`dirty`,`ahead`,`behind`,`stash`],l_=[`fail`,`ignore`];function u_(e){return e.missingData??`fail`}function*d_(e){for(let[t,n]of Object.entries(e.variables))n.kind===`state`&&(yield[t,n]);for(let[t,n]of Object.entries(e.segments))if(n.vars)for(let[e,r]of Object.entries(n.vars))r.kind===`state`&&(yield[`${t}.${e}`,r])}const f_=`theme`,p_=`effect`,m_=[f_,p_];function h_(e){return{...e.settings,[f_]:{label:f_,domain:`theme`,default:e.palette??`bar`},[p_]:{label:p_,domain:mh,default:`bar`}}}function g_(e){let t=e?.domain;return typeof t==`object`&&`min`in t?t:void 0}function __(e,t){return Object.entries(e).flatMap(([n,r])=>{let i=g_(r)?.atLeast;if(i===void 0)return[];let a=t[n],o=t[i];return a>=o?[]:[{setting:n,message:`"${n}" (${a}) is below "${i}" (${o}) — ${r.label} must be at least ${e[i].label}`}]})}function v_(e,t){let{domain:n}=e;return n===`bool`?typeof t==`boolean`:n===`theme`?typeof t==`string`&&eh(t):`min`in n?typeof t==`number`&&Number.isInteger(t)&&t>=n.min&&t<=n.max:typeof t==`string`&&n.includes(t)}function y_(e){return String(e)}function b_(e,t){let{domain:n}=e;if(typeof n==`object`&&`min`in n)return Ih(t,n)??void 0;let r=n===`bool`?t===`true`?!0:t===`false`?!1:t:t;return v_(e,r)?r:void 0}function x_(e,t,n,r){let i=e.settings?.[t]??n.default,a=e.drafts?.[t],o=a===void 0?null:r(a);return(o===null?void 0:b_(n,o))??i}function S_(e){let{domain:t}=e;return t===`bool`?`true or false`:t===`theme`?`"bar" (the bar's own theme) or an installed theme name`:`min`in t?`an integer from ${t.min} to ${t.max}`:`one of ${t.map(e=>JSON.stringify(e)).join(`, `)}`}const C_=[`left`,`center`,`right`],w_=[`right`,`left`,`middle`],T_=/^[A-Za-z_][A-Za-z0-9_]*$/;function E_(e){return`#${e+1}`}const D_={rows:{}};function O_(e){return`rows`in e}function k_(e){return Object.fromEntries(e.map((e,t)=>[E_(t),e]))}function A_(e){if(e.kind===`container`&&e.direction===`vertical`){let{kind:t,direction:n,children:r,...i}=e;return{...i,rows:k_(r)}}let{when:t,...n}=e;return{...t!==void 0&&{when:t},rows:k_([n])}}function j_(e){let{rows:t,...n}=e;return{kind:`container`,direction:`vertical`,children:Object.values(t),...n}}function M_(e){return O_(e)?j_(e):e}function*N_(e,t){if(!O_(e)){yield*n_(e,t);return}yield[j_(e),t];for(let[n,r]of Object.entries(e.rows))yield*n_(r,`${t}.rows.${n}`)}function P_(e,t){return O_(e)?{...t,...e,rows:{...t.rows,...e.rows}}:A_(e)}function F_(e){if(!O_(e))return!0;let{rows:t,...n}=e;return Object.values(n).some(e=>e!==void 0)||Object.keys(t).length>0}const I_=`default`,L_={};function R_(e){return[...new Set([I_,...Object.keys(e)])]}function z_(e,t,n){return th(void 0,e,t,I_,n)}function B_(e,t){let n={[I_]:L_,...e}[t];if(n===void 0)throw Error(`Preset "${t}" is not declared in this config — effectivePresetName collapses unknown names to "${I_}", which always resolves; a miss here means a raw name reached this function without going through that resolution`);return n}function V_(e,t){let n=B_(e.presets,t).root??D_;return{node:j_(P_(n,e.root)),path:F_(n)?`presets.${t}.root`:`root`}}function H_(e,t){return{...e.globals,...B_(e.presets,t).globals}}const U_=new Map;function W_(e,t,n){U_.set(e,{permanent:!0,resolve:t,paletteOf:n})}W_(`themes`,()=>Zm(),e=>Rg(e));const G_=`placementThemes`;W_(G_,Qm,(e,t)=>zg(e,t.palette)),W_(`endcaps`,()=>vh),W_(`variations`,()=>Th),W_(`shades`,()=>Oh),W_(`colorCompatibilities`,()=>Ch);function K_(e){return new Map([[`styles`,{members:Object.keys(e.styles),paletteOf:(t,n)=>Vg(n.basePalette,e.styles[t])}],[`presets`,{members:R_(e.presets)}]])}function q_(e){return[...new Set([...U_.keys(),...e.keys()])]}function J_(e,t){if(typeof e!=`string`)return{members:e};let n=t.get(e);if(n)return n;let r=U_.get(e);if(r)return{members:r.resolve(),paletteOf:r.paletteOf};throw Error(X_(e,t))}const Y_=new Map([[`looks`,`styles`],[`progressions`,`variations`]]);function X_(e,t){let n=Y_.get(e);return`unknown option domain "${e}"${n===void 0?``:` — it was renamed "${n}"; write from: "${n}"`} (have: ${q_(t).join(`, `)})`}const Z_=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`[^`]*`/g;function*Q_(e){let t=e.indexOf(`{{`);for(;t!==-1;){let n=``,r=t+2;for(;r<e.length&&!e.startsWith(`}}`,r);){if(e.startsWith(`/*`,r)){let t=e.indexOf(`*/`,r+2);r=t===-1?e.length:t+2;continue}let t=r,i=e[r];if(r+=1,i===`"`||i===`'`||i==="`"){for(;r<e.length&&e[r]!==i;)r+=e[r]===`\\`&&i!=="`"?2:1;r+=1}n+=e.slice(t,r)}if(r>=e.length)return;yield n,t=e.indexOf(`{{`,r+2)}}const $_=`[A-Za-z_]\\w*(?:\\.[A-Za-z_]\\w*)*`,ev=RegExp(`^(?:(\\$)(?:\\.(${$_}))?|\\.(${$_})?)(?=[\\s)]|$)`);function tv(e,t,n){let r=ev.exec(e.trimStart());if(r===null)return null;let[i,a]=r[1]===void 0?[t,r[3]]:[n,r[2]];return i===null?null:a===void 0?i:`${i}${a}.`}const nv=/^(\w+)\b\s*([\s\S]*)$/;function*rv(e,t){let n=[t];for(let r of Q_(e)){let e=r.replace(/^-(?=\s)/,``).trim(),[,i=``,a=``]=nv.exec(e)??[],o=n[n.length-1],s=n.length>1?n[n.length-2]:o;if(i===`end`){n.length>1&&n.pop();continue}if(i===`else`){yield{code:e,dot:s};let r=/^with\b([\s\S]*)$/.exec(a);n[n.length-1]=r===null?s:tv(r[1],s,t);continue}yield{code:e,dot:o},i===`if`&&n.push(o),i===`with`&&n.push(tv(a,o,t)),(i===`range`||i===`define`||i===`block`)&&n.push(null)}}const iv=/(?<![.$])\btemplate\s+$/;function*av(e,t,n){let r=0;for(let i of[...e.matchAll(Z_)]){let a=i.index+i[0].length;iv.test(e.slice(r,i.index))&&(yield{name:i[0].slice(1,-1),at:tv(e.slice(a),t,n)}),r=a}}function*ov(e,t){let n=new Set;function*r(e,i,a,o){for(let{code:s,dot:c}of[...rv(e,i)]){yield{code:s,dot:c,root:i,via:a};for(let e of[...av(s,c,i)]){let i=Object.hasOwn(t,e.name)?t[e.name]:void 0,a=`${e.name}\0${e.at??`\0`}`;i===void 0||o.has(e.name)||n.has(a)||(n.add(a),yield*r(i,e.at,e.name,new Set([...o,e.name])))}}}yield*r(e,``,null,new Set)}const sv=RegExp(`(?<![A-Za-z0-9_)$])(\\$?)\\.(${$_})`,`g`);function*cv({code:e,dot:t,root:n}){let r=e.replace(Z_,``);for(let e of[...r.matchAll(sv)]){let r=e[1]===`$`?n:t;r!==null&&(yield`${r}${e[2]}`)}}function lv(e,t){let n=new Map;for(let r of ov(e,t))for(let e of cv(r))n.has(e)||n.set(e,r.via);return n}const uv=/(?<![.$])\b(action|picker|menu|carousel|swatches|swatch|themePreview)\s+$/,dv={action:1,picker:2,menu:1,carousel:2,swatch:1,swatches:2,themePreview:1};function*fv(e){let t=0,n=0,r=0,i=`action`;for(let a of[...e.matchAll(Z_)]){let o=e.slice(t,a.index),s=uv.exec(o);if(s!==null)n=dv[s[1]],r=0,i=s[1]===`action`?`action`:`options`;else for(let e of o)e===`(`&&r++,e===`)`&&r--,(r<0||e===`|`&&r===0)&&(n=0);n>0&&r===0&&(yield{name:a[0].slice(1,-1),site:i},n--),t=a.index+a[0].length}}function pv(e,t){let n=new Map;for(let{code:r,via:i}of ov(e,t))for(let{name:e,site:t}of fv(r)){let r=`${e}\0${i??`\0`}`;n.has(r)||n.set(r,{name:e,site:t,via:i})}return[...n.values()]}function mv(e,t){return new Set([...hv(e,t)].filter(e=>Object.hasOwn(t,e)))}function hv(e,t){let n=new Set;for(let{code:r,dot:i,root:a}of ov(e,t))for(let{name:e}of av(r,i,a))n.add(e);return n}function gv(e,t){if(t.names.has(e))return!0;let n=`${e}.`;for(let e of t.names)if(e.startsWith(n))return!0;for(let n of t.documents)if(e.startsWith(`${n}.`))return!0;return!1}function _v(e){let t=new Set,n=new Set,r=(e,r)=>{t.add(e),vv(r)&&n.add(e)};for(let[t,n]of Object.entries(e.variables))r(t,n);for(let[t,n]of Object.entries(e.segments))for(let[e,i]of Object.entries(n.vars??{}))r(`${t}.${e}`,i);return{names:t,documents:n,helpers:e.helpers}}function vv(e){return e.kind===`dropped`||(e.kind===`shell`||e.kind===`file`)&&a_(e.parse)===`json`}function yv(e){let t=v.basename(e),n=v.dirname(e);for(;;){let r=bv(n);if(r!==null)return{dir:r,name:t,leaf:n===v.dirname(e)};t=v.basename(n),n=v.dirname(n)}}function bv(e){try{return s.statSync(e).isDirectory()?s.realpathSync(e):null}catch{return null}}var xv=we((e=>{function t(e,...t){throw Error(`[MobX] minified error nr: ${e}${t.length?` `+t.map(String).join(`,`):``}. See mobx.js.org/errors`)}function n(e){let t=!1;return function(){if(!t)return t=!0,e.apply(this,arguments)}}function r(e){return typeof e==`function`}function i(e){switch(typeof e){case`string`:case`symbol`:case`number`:return!0}return!1}function a(e){return typeof e==`object`&&!!e}function o(e){if(!a(e))return!1;let t=Object.getPrototypeOf(e);if(t==null)return!0;let n=p(t,`constructor`)&&t.constructor;return typeof n==`function`&&n.toString()===zt}function s(e){let t=e?.constructor;return!!t&&(t.name===`GeneratorFunction`||t.displayName===`GeneratorFunction`)}function c(e,t,n){Ft(e,t,{enumerable:!1,writable:!0,configurable:!0,value:n})}function l(e,t){let n=`isMobX`+e;return t.prototype[n]=!0,function(e){return a(e)&&!0===e[n]}}function u(e){return e!=null&&Object.prototype.toString.call(e)===`[object Map]`}function d(e){return e!=null&&Object.prototype.toString.call(e)===`[object Set]`}function f(e){return e===null?null:typeof e==`object`?``+e:e}function p(e,t){return It.hasOwnProperty.call(e,t)}function m(e,t){return!!(e&t)}function h(e,t,n){return n?e|=t:e&=~t,e}function g(e,t=Bt,n=Bt){let r=new Ut(e);return t!==Bt&&(r.onBOL=new Set([t])),n!==Bt&&(r.onBUOL=new Set([n])),r}function _(e,t){return Ot(e,t)}function v(e,t,n){return e===null||typeof e!=`object`&&typeof e!=`function`||$e(e)?e:Array.isArray(e)?an.array(e,{name:n}):o(e)?an.object(e,void 0,{name:n}):u(e)?an.map(e,{name:n}):d(e)?an.set(e,{name:n}):typeof e!=`function`||He(e)||Xe(e)?e:s(e)?Un(e):Fn(n,e)}function y(e){return e}function b(e,t){return{t:e,i:t,o:x,u:S}}function x(e,t,n,r){var i;return(i=this.i)!=null&&i.bound?this.u(e,t,n,!1)===null?0:1:r===e.h?this.u(e,t,n,!1)===null?0:2:He(n.value)?1:(Ft(r,t,w(e,this,t,n,!1)),2)}function S(e,t,n,r){let i=w(e,this,t,n);return e.l(t,i,r)}function C(e,n,r){let{kind:i,name:a,addInitializer:o}=r,s=e,c=e=>{var t;return _e(s.i?.name??a.toString(),e,(t=s.i?.autoAction)!=null&&t)};return i==`field`?function(e){var t;let n=e;return He(n)||(n=c(n)),(t=s.i)!=null&&t.bound&&(n=n.bind(this),n.isMobxAction=!0),n}:i==`method`?(He(n)||(n=c(n)),(l=s.i)!=null&&l.bound&&o(function(){let e=this,t=e[a].bind(e);t.isMobxAction=!0,e[a]=t}),n):void t(43,s.t,String(a),i);var l}function w(e,t,n,r,i=F.safeDescriptors){var a,o,s;let{value:c}=r;return(a=t.i)!=null&&a.bound&&(c=c.bind(e.v??e.h)),{value:_e(t.i?.name??n.toString(),c,(o=t.i?.autoAction)!=null&&o,(s=t.i)!=null&&s.bound?e.v??e.h:void 0),configurable:!i||e.p,enumerable:!1,writable:!i}}function ee(e,t){return{t:e,i:t,o:te,u:ne}}function te(e,t,n,r){var i;return r===e.h?this.u(e,t,n,!1)===null?0:2:(i=this.i)!=null&&i.bound&&(!p(e.h,t)||!Xe(e.h[t]))&&this.u(e,t,n,!1)===null?0:Xe(n.value)?1:(Ft(r,t,re(e,0,0,n,!1,!1)),2)}function ne(e,t,n,r){let i=re(e,0,0,n,this.i?.bound);return e.l(t,i,r)}function T(e,t,n){var r;let{name:i,addInitializer:a}=n;return Xe(t)||(t=Un(t)),(r=e.i)!=null&&r.bound&&a(function(){let e=this,t=e[i].bind(e);t.isMobXFlow=!0,e[i]=t}),t}function re(e,t,n,r,i,a=F.safeDescriptors){let{value:o}=r;return Xe(o)||(o=Un(o)),i&&(o=o.bind(e.v??e.h),o.isMobXFlow=!0),{value:o,configurable:!a||e.p,enumerable:!1,writable:!a}}function E(e,t){return{t:e,i:t,o:D,u:ie}}function D(e,t,n){return this.u(e,t,n,!1)===null?0:1}function ie(e,t,n,r){return e.m(t,Nt({},this.i,{get:n.get,set:n.set}),r)}function O(e,t,n){function r(e){let n=Nt({},i.i,{get:t,context:e});return n.name||=`ObservableObject.${a.toString()}`,new _n(n)}let i=e,{name:a,addInitializer:o}=n,s;return o(function(){let e=xt(this)[M],n=this,i=e.j.get(a);i instanceof _n&&i.derivation!==t&&e.j.delete(a),(e.O??=new Map).set(a,()=>r(n))}),function(){let e=this[M],n=e.j.get(a);if(n instanceof _n&&n.derivation!==t){let e=s?.get(this);return e||(e=r(this),(s??=new WeakMap).set(this,e)),e.get()}return e._(a)}}function ae(e,t){return{t:e,i:t,o:oe,u:se}}function oe(e,t,n){return this.u(e,t,n,!1)===null?0:1}function se(e,t,n,r){return e.S(t,n.value,this.i?.A??v,r)}function ce(e,t,n){function r(e,t){let n=xt(e)[M];return(n.V??=new Map).set(o,()=>new hn(t,i.i?.A??v,`ObservableObject.${o.toString()}`,!1)),n}let i=e,{kind:a,name:o}=n;if(a===`accessor`)return{get(){return(this[M]??r(this,t.get.call(this)))._(o)},set(e){return(this[M]??r(this,e)).M(o,e)},init(e){return r(this,e),e}}}function le(e){return{t:Kt,i:e,o:ue,u:de}}function ue(e,t,n,r){var i,a,o;if(n.get)return ln.o(e,t,n,r);if(n.set){let i=He(n.set)?n.set:_e(t.toString(),n.set);return r===e.h?e.l(t,{configurable:!F.safeDescriptors||e.p,set:i})===null?0:2:(Ft(r,t,{configurable:!0,set:i}),2)}if(r!==e.h&&typeof n.value==`function`)return s(n.value)?((o=this.i)!=null&&o.autoBind?Wn:Un).o(e,t,n,r):((a=this.i)!=null&&a.autoBind?Ln:Fn).o(e,t,n,r);let c=!1===this.i?.deep?en:an;return typeof n.value==`function`&&(i=this.i)!=null&&i.autoBind&&(n.value=n.value.bind(e.v??e.h)),c.o(e,t,n,r)}function de(e,t,n,r){var i;return n.get?ln.u(e,t,n,r):n.set?e.l(t,{configurable:!F.safeDescriptors||e.p,set:_e(t.toString(),n.set)},r):(typeof n.value==`function`&&(i=this.i)!=null&&i.autoBind&&(n.value=n.value.bind(e.v??e.h)),(!1===this.i?.deep?en:an).u(e,t,n,r))}function fe(e,t){return Nt(function(n,r){if(r&&typeof r.kind==`string`)return t(e,n,r)},e)}function pe(e){return e||Jt}function me(e){return fe(e,ce)}function he(e){return!0===e.deep?v:!1===e.deep?y:(t=e.defaultDecorator)&&(n=(r=t.i)?.A)!=null?n:v;var t,n,r}function ge(e){return fe(e,O)}function _e(e,t,n=!1,r){function i(){return ve(0,n,t,r||this,arguments)}return i.isMobxAction=!0,i.toString=()=>t.toString(),pn&&(mn.value=e,Ft(i,`name`,mn)),i}function ve(e,t,n,r,i){let a=ye(0,t);try{return n.apply(r,i)}catch(e){throw a.N=e,e}finally{be(a)}}function ye(e,t){let n=F.trackingDerivation,r=!t||!n;Me();let i=F.allowStateChanges;r&&k();let a={R:r,k:n,C:i,I:F.allowStateReads,P:!1,T:0,B:fn++,D:dn};return dn=a.B,a}function be(e){dn!==e.B&&t(30),dn=e.D,e.N!==void 0&&(F.suppressReactionErrors=!0),Ne(),e.R&&De(e.k),F.suppressReactionErrors=!1}function xe(e,t){let n=function(e){let t=F.allowStateChanges;return F.allowStateChanges=e,t}(e);try{return t()}finally{(function(e){F.allowStateChanges=e})(n)}}function Se(e){return e instanceof yn}function Ce(e){switch(e.K){case 0:return!1;case-1:case 2:return!0;case 1:{let t=k(),n=e.L,r=n.length;for(let i=0;i<r;i++){let r=n[i];if(vn(r)){if(F.disableErrorBoundaries)r.get();else try{r.get()}catch{return De(t),!0}if(e.K===2)return De(t),!0}}return Oe(e),De(t),!1}}}function we(e,t,n){Oe(e),e.$=Array(e.U===0?100:e.L.length),e.W=0,e.U=++F.runId;let r=F.trackingDerivation,i;if(F.trackingDerivation=e,F.inBatch++,!0===F.disableErrorBoundaries)i=t.call(n);else try{i=t.call(n)}catch(e){i=new yn(e)}return F.inBatch--,F.trackingDerivation=r,function(e){let t=e.L,n=e.L=e.$,r=0,i=0,a=e.W;for(let e=0;e<a;e++){let t=n[e];t.diffValue===0&&(t.diffValue=1,i!==e&&(n[i]=t),i++),t.K>r&&(r=t.K)}for(n.length=i,e.$=null,a=t.length;a--;){let n=t[a];n.diffValue===0&&Ae(n,e),n.diffValue=0}for(;i--;){let t=n[i];t.diffValue===1&&(t.diffValue=0,ke(t,e))}r!==0&&(e.K=r,e.q())}(e),i}function Te(e){let t=e.L;e.L=[];let n=t.length;for(;n--;)Ae(t[n],e);e.K=-1}function Ee(e){let t=k();try{return e()}finally{De(t)}}function k(){let e=F.trackingDerivation;return F.trackingDerivation=null,e}function De(e){F.trackingDerivation=e}function Oe(e){if(e.K===0)return;e.K=0;let t=e.L,n=t.length;for(;n--;)t[n].F=0}function ke(e,t){(e.H??=new Set).add(t),e.F>t.K&&(e.F=t.K)}function Ae(e,t){let n=e.H;n&&(n.delete(t),n.size===0&&je(e))}function je(e){!1===e.isPendingUnobservation&&(e.isPendingUnobservation=!0,F.pendingUnobservations.push(e))}function Me(){F.inBatch++}function Ne(){--F.inBatch===0&&(Le(),!F.isRunningUnobservations&&F.pendingUnobservations.length>0&&function(){F.isRunningUnobservations=!0;try{let e=F.pendingUnobservations;for(let t=0;t<e.length;t++){let n=e[t];n.isPendingUnobservation=!1,n.H&&n.H.size!==0||(n.H=null,n.isBeingObserved&&(n.isBeingObserved=!1,n.onBUO()),n instanceof _n&&n.G())}F.pendingUnobservations=[]}finally{F.isRunningUnobservations=!1}}())}function Pe(e){var t;e.isBeingObserved||(e.isBeingObserved=!0,e.onBO(),(t=e.L)==null||t.forEach(Pe))}function Fe(e){let t=F.trackingDerivation;return t===null?((!e.H||e.H.size===0)&&F.inBatch>0&&je(e),!1):(t.U!==e.J&&(e.J=t.U,t.$[t.W++]=e,!e.isBeingObserved&&F.trackingContext&&(e.isBeingObserved=!0,e.onBO())),e.isBeingObserved)}function Ie(e){var t;e.F!==2&&(e.F=2,(t=e.H)==null||t.forEach(e=>{e.K===0&&e.q(),e.K=2}))}function Le(){F.inBatch>0||F.isRunningReactions||En(Re)}function Re(){F.isRunningReactions=!0;let e=F.pendingReactions,t=0;for(;e.length>0;){++t===Tn&&(console.error(`[mobx] cycle in reaction: ${e[0]}`),e.splice(0));let n=e.splice(0);for(let e=0,t=n.length;e<t;e++)n[e].X()}F.isRunningReactions=!1}function ze(e){return fe(e,C)}function Be(e){return function(t,n){return n&&typeof n.kind==`string`?C(e?Mn:An,t,n):r(t)?_e(t.name||`<unnamed action>`,t,e):r(n)?_e(t,n,e):i(t)?ze(b(e?kn:On,{name:t,autoAction:e})):void 0}}function Ve(e){return ve(0,!1,e,this,void 0)}function He(e){return r(e)&&!0===e.isMobxAction}function Ue(e,t=Rt){function n(){e(a)}var r;let i=t?.name??`Autorun`,a;if(t.scheduler||t.delay){let e=We(t),r=!1;a=new wn(i,()=>{r||(r=!0,e(()=>{r=!1,a.isDisposed||a.track(n)}))},t.onError,t.requiresObservable)}else a=new wn(i,function(){this.track(n)},t.onError,t.requiresObservable);return t!=null&&(r=t.signal)!=null&&r.aborted||a.Y(),a.Z(t?.signal)}function We(e){return e.scheduler?e.scheduler:e.delay?t=>setTimeout(t,e.delay):Rn}function Ge(e,t,n,i){let a=typeof i==`function`?wt(t,n):wt(t),o=r(i)?i:n,s=`${e}L`;return a[s]?a[s].add(o):a[s]=new Set([o]),function(){let e=a[s];e&&(e.delete(o),e.size===0&&delete a[s])}}function Ke(e,t,n,r){let i=Ht(t);return Dt(()=>{let t=xt(e,r)[M];Vt(i).forEach(e=>{t.u(e,i[e],!n||!(e in n)||n[e])})}),e}function qe(e){let t={name:e.tt};var n;return e.L&&e.L.length>0&&(t.dependencies=(n=e.L,Array.from(new Set(n))).map(qe)),t}function Je(e){let t={name:e.tt};return function(e){return!!e.H&&e.H.size>0}(e)&&(t.observers=Array.from(function(e){return e.H??new Set}(e),Je)),t}function Ye(e){r(e.cancel)&&e.cancel()}function Xe(e){return!0===e?.isMobXFlow}function Ze(e,t){var n;if(t===void 0)return vn(e);if(!1===Ct(e))return!1;let r=e[M];return(n=r.O)!=null&&n.has(t)?!0:r.j.has(t)?vn(wt(e,t)):!1}function Qe(e,t){if(!e)return!1;if(t!==void 0){if(Ct(e)){var n,r;let i=e[M];return i.j.has(t)||!((n=i.O)==null||!n.has(t))||!((r=i.V)==null||!r.has(t))}return!1}return Ct(e)||!!e[M]||Wt(e)||Dn(e)||vn(e)}function $e(e){return Qe(e)}function et(e){return Ct(e)?e[M].nt():nr(e)||I(e)?Array.from(e.keys()):vt(e)?e.map((e,t)=>t):void t(5)}function tt(e,n){return Ct(e)?e[M].et(n):nr(e)||I(e)?e.has(n):vt(e)?n>=0&&n<e.length:void t(10)}function nt(e){if(Ct(e))return e[M].it();t(38)}function rt(e,t,n){if(vn(e)){let r,i=!0;return Ue(()=>{let a=e.get();if(!i||n){let n=k();t({observableKind:`computed`,debugObjectName:e.tt,type:Jn,object:e,newValue:a,oldValue:r}),De(n)}i=!1,r=a})}return n&&t({observableKind:`value`,debugObjectName:e.tt,object:e,type:Jn,newValue:e.rt,oldValue:void 0}),ft(e,t)}function it(e,t,n){return e.set(t,n),n}function at(e,t){if(typeof e!=`object`||!e||e instanceof Date||!$e(e))return e;if(gn(e)||vn(e))return at(e.get(),t);if(t.has(e))return t.get(e);if(vt(e)){let n=it(t,e,Array(e.length));return e.forEach((e,r)=>{n[r]=at(e,t)}),n}if(I(e)){let n=it(t,e,new Set);return e.forEach(e=>{n.add(at(e,t))}),n}if(nr(e)){let n=it(t,e,new Map);return e.forEach((e,r)=>{n.set(r,at(e,t))}),n}{let n=it(t,e,{});return nt(e).forEach(r=>{It.propertyIsEnumerable.call(e,r)&&(n[r]=at(e[r],t))}),n}}function ot(e,t){Me();try{return e.apply(t)}finally{Ne()}}function st(e,t,n){let r;if(typeof n.timeout==`number`){let e=Error(`WHEN_TIMEOUT`);r=setTimeout(()=>{if(!a[M].isDisposed){if(a(),!n.onError)throw e;n.onError(e)}},n.timeout)}n.name=`When`;let i=_e(`When-effect`,t);var a=Ue(t=>{xe(!1,e)&&(t.dispose(),r&&clearTimeout(r),i())},n);return a}function ct(e){return e[M]}function lt(e){return e.st!==void 0&&e.st.length>0}function ut(e,t){let r=e.st;return r?r.push(t):r=e.st=[t],n(()=>{let e=r.indexOf(t);e!==-1&&r.splice(e,1)})}function A(e,n){let r=k();try{let r=[...e.st||[]];for(let e=0,i=r.length;e<i&&((n=r[e](n))&&!n.type&&t(14),n);e++);return n}finally{De(r)}}function dt(e){return e.ot!==void 0&&e.ot.length>0}function ft(e,t){let r=e.ot;return r?r.push(t):r=e.ot=[t],n(()=>{let e=r.indexOf(t);e!==-1&&r.splice(e,1)})}function pt(e,t){let n=k(),r=e.ot;if(r){r=r.slice();for(let e=0,n=r.length;e<n;e++)r[e](t);De(n)}}function mt(e,n,r){if(!0===r&&(r=e.ut),!1===r)return;n in e.h||t(1,r.t,`${e.tt}.${n.toString()}`);let i=e.h;for(;i&&i!==It;){let t=Pt(i,n);if(t){let a=r.o(e,n,t,i);if(a===0)return;if(a===1)break}i=Object.getPrototypeOf(i)}}function j(e,t){typeof Array.prototype[e]==`function`&&(Zn[e]=t(e))}function ht(e){return function(){let t=this[M];t.ct.reportObserved();let n=t.ht(t.j);return n[e].apply(n,arguments)}}function gt(e){return function(t,n){let r=this[M];return r.ct.reportObserved(),r.ht(r.j)[e]((e,r)=>t.call(n,e,r,this))}}function _t(e){return function(){let t=this[M];t.ct.reportObserved();let n=t.ht(t.j),r=arguments[0];return arguments[0]=(e,t,n)=>r(e,t,n,this),n[e].apply(n,arguments)}}function vt(e){return a(e)&&Qn(e[M])}function yt(e){return e[Symbol.toStringTag]=`MapIterator`,jt(e)}function bt(e){return e[Symbol.toStringTag]=`SetIterator`,jt(e)}function xt(e,t){if(p(e,M))return e;let n=t?.name??`ObservableObject`;return c(e,M,new sr(e,new Map,String(n),function(e){return e?e.defaultDecorator??function(e){let t=!1!==e.deep,n=!!e.autoBind,r=!t|(n?2:0);return P[r]??(P[r]=le({deep:t,autoBind:n}))}(e):void 0}(t))),e}function St(e){return ar[e]||(ar[e]={get(){return this[M]._(e)},set(t){return this[M].M(e,t)}})}function Ct(e){return!!a(e)&&cr(e[M])}function wt(e,n){if(typeof e==`object`&&e){if(vt(e))return n!==void 0&&t(23),e[M].ct;if(I(e))return e.ct;if(nr(e)){if(n===void 0)return e.lt;let r=e.ft.get(n)||e.dt.get(n);return r||t(25,n,Et(e)),r}if(Ct(e)){if(!n)return t(26);let r=e[M],i=r.j.get(n)??r.vt(n)??r.bt(n);return i||t(27,n,Et(e)),i}if(Wt(e)||vn(e)||Dn(e))return e}else if(r(e)&&Dn(e[M]))return e[M];t(28)}function Tt(e,n){return e||t(29),n===void 0?Wt(e)||vn(e)||Dn(e)||nr(e)||I(e)?e:e[M]?e[M]:void t(24,e):Tt(wt(e,n))}function Et(e,t){let n;if(t!==void 0)n=wt(e,t);else{if(He(e))return e.name;n=Ct(e)||nr(e)||I(e)?Tt(e):wt(e)}return n.tt}function Dt(e){let t=k();Me();try{return e()}finally{Ne(),De(t)}}function Ot(e,t,n=-1){return kt(e,t,n)}function kt(e,t,n,i,a){if(e===t)return e!==0||1/e==1/t;if(e==null||t==null)return!1;if(e!=e)return t!=t;let o=typeof e;if(o!==`function`&&o!==`object`&&typeof t!=`object`)return!1;let s=lr.call(e);if(s!==lr.call(t))return!1;switch(s){case`[object RegExp]`:case`[object String]`:return``+e==``+t;case`[object Number]`:return+e==+e?+e==0?1/e==1/t:+e==+t:+t!=+t;case`[object Date]`:case`[object Boolean]`:return+e==+t;case`[object Symbol]`:return typeof Symbol<`u`&&Symbol.valueOf.call(e)===Symbol.valueOf.call(t);case`[object Map]`:case`[object Set]`:n>=0&&n++}e=At(e),t=At(t);let c=s===`[object Array]`;if(!c){if(typeof e!=`object`||typeof t!=`object`)return!1;let n=e.constructor,i=t.constructor;if(n!==i&&!(r(n)&&n instanceof n&&r(i)&&i instanceof i)&&`constructor`in e&&`constructor`in t)return!1}if(n===0)return!1;n<0&&(n=-1),a||=[];let l=(i||=[]).length;for(;l--;)if(i[l]===e)return a[l]===t;if(i.push(e),a.push(t),c){if(l=e.length,l!==t.length)return!1;for(;l--;)if(!kt(e[l],t[l],n-1,i,a))return!1}else{let r=Object.keys(e),o=r.length;if(Object.keys(t).length!==o)return!1;for(let s=0;s<o;s++){let o=r[s];if(!p(t,o)||!kt(e[o],t[o],n-1,i,a))return!1}}return i.pop(),a.pop(),!0}function At(e){return vt(e)?e.slice():u(e)||nr(e)||d(e)||I(e)?Array.from(e.entries()):e}function jt(e){return e[Symbol.iterator]=Mt,Nt(Object.create(ur),e)}function Mt(){return this}Object.defineProperty(e,`__esModule`,{value:!0});let Nt=Object.assign,Pt=Object.getOwnPropertyDescriptor,Ft=Object.defineProperty,It=Object.prototype,Lt=[];Object.freeze(Lt);let Rt={};Object.freeze(Rt);let zt=Object.toString(),Bt=()=>{},Vt=Reflect.ownKeys,Ht=Object.getOwnPropertyDescriptors,M=Symbol(`mobx administration`);var Ut=class{constructor(e=`Atom`){this.tt=void 0,this.yt=0,this.H=null,this.J=0,this.F=-1,this.onBOL=void 0,this.onBUOL=void 0,this.tt=e}get isBeingObserved(){return m(this.yt,1)}set isBeingObserved(e){this.yt=h(this.yt,1,e)}get isPendingUnobservation(){return m(this.yt,2)}set isPendingUnobservation(e){this.yt=h(this.yt,2,e)}get diffValue(){return+!!m(this.yt,4)}set diffValue(e){this.yt=h(this.yt,4,e===1)}onBO(){this.onBOL&&this.onBOL.forEach(e=>e())}onBUO(){this.onBUOL&&this.onBUOL.forEach(e=>e())}reportObserved(){return Fe(this)}reportChanged(){Me(),Ie(this),Ne()}toString(){return this.tt}};let Wt=l(`Atom`,Ut),Gt=Object.is,N={t:`override`,o:function(){return 0},u:function(){t(44,this.t)}},Kt=`true`,qt=le(),P=[qt],Jt={deep:!0,name:void 0,defaultDecorator:void 0};Object.freeze(Jt);let Yt=ae(`observable`),Xt=ae(`observable.ref`,{A:y}),Zt=ae(`observable.shallow`,{A:function(e,t,n){return e==null||Ct(e)||vt(e)||nr(e)||I(e)?e:Array.isArray(e)?an.array(e,{name:n,deep:!1}):o(e)?an.object(e,void 0,{name:n,deep:!1}):u(e)?an.map(e,{name:n,deep:!1}):d(e)?an.set(e,{name:n,deep:!1}):void 0}}),Qt=ae(`observable.struct`,{A:function(e,t){return Ot(e,t)?t:e}}),$t={box(e,t){let n=pe(t);return new hn(e,he(n),n.name,!0,n.equals)},array(e,t){let n=pe(t);return function(e,t,n=`ObservableArray`,r=!1){return Dt(()=>{let i=new Xn(n,t,r);Ft(i.j,M,{enumerable:!1,writable:!1,configurable:!0,value:i});let a=new Proxy(i.j,Yn);return i.v=a,e&&e.length&&i.wt(0,0,e),a})}(e,he(n),n.name)},map(e,t){let n=pe(t);return new tr(e,he(n),n.name)},set(e,t){let n=pe(t);return new ir(e,he(n),n.name)},object:(e,t,n)=>Dt(()=>Ke(function(e,t){var n;return(n=(e=xt(e,t))[M]).v??(n.v=new Proxy(e,Gn))}({},n),e,t))},en=me(Xt),tn=me(Zt),nn=me(Yt),rn=me(Qt);var an=Nt(function(e,t,n){return t&&typeof t.kind==`string`?ce(Yt,e,t):$e(e)?e:o(e)?an.object(e,t,n):Array.isArray(e)?an.array(e,t):u(e)?an.map(e,t):d(e)?an.set(e,t):typeof e==`object`&&e?e:an.box(e,t)},Yt,$t);let on=`computed`,sn=E(on),cn=ge(E(`computed.struct`,{equals:_})),ln=function(e,t){if(t&&typeof t.kind==`string`)return O(sn,e,t);if(o(e))return ge(E(on,e));let n=o(t)?t:{};return n.get=e,n.name||=e.name||``,new _n(n)};var un;Nt(ln,sn);let dn=0,fn=1,pn=(un=Pt(()=>{},`name`)?.configurable)!=null&&un,mn={value:`action`,configurable:!0,writable:!1,enumerable:!1};var hn=class extends Ut{constructor(e,t,n=`ObservableValue`,r=!0,i=Gt){super(n),this.A=void 0,this.tt=void 0,this.xt=void 0,this.gt=!1,this.st=void 0,this.ot=void 0,this.rt=void 0,this.dehancer=void 0,this.A=t,this.tt=n,this.xt=i,this.rt=t(e,void 0,n)}dehanceValue(e){return this.dehancer===void 0?e:this.dehancer(e)}set(e){(e=this.jt(e))!==F.UNCHANGED&&this.Ot(e)}jt(e){if(lt(this)){let t=A(this,{object:this,type:Jn,newValue:e});if(!t)return F.UNCHANGED;e=t.newValue}return e=this.A(e,this.rt,this.tt),this.xt(this.rt,e)?F.UNCHANGED:e}Ot(e){let t=this.rt;this.rt=e,this.reportChanged(),dt(this)&&pt(this,{type:Jn,object:this,newValue:e,oldValue:t})}get(){return this.reportObserved(),this.dehanceValue(this.rt)}raw(){return this.rt}toJSON(){return this.get()}toString(){return`${this.tt}[${this.rt}]`}valueOf(){return f(this.get())}[Symbol.toPrimitive](){return this.valueOf()}};let gn=l(`ObservableValue`,hn);var _n=class{constructor(e){this.K=-1,this.L=[],this.$=null,this.H=null,this.U=0,this.J=0,this.F=0,this.W=0,this.rt=new yn(null),this.tt=void 0,this._t=void 0,this.yt=0,this.derivation=void 0,this.St=void 0,this.At=void 0,this.xt=void 0,this.Vt=void 0,this.Mt=void 0,this.onBOL=void 0,this.onBUOL=void 0,e.get||t(31),this.derivation=e.get,this.tt=e.name||`ComputedValue`,e.set&&(this.St=_e(`ComputedValue-setter`,e.set)),this.xt=e.equals||Gt,this.At=e.context,this.Vt=e.requiresReaction,this.Mt=!!e.keepAlive}q(){(function(e){var t;e.F===0&&(e.F=1,(t=e.H)==null||t.forEach(e=>{e.K===0&&(e.K=1,e.q())}))})(this)}onBO(){this.onBOL&&this.onBOL.forEach(e=>e())}onBUO(){this.onBUOL&&this.onBUOL.forEach(e=>e())}get isComputing(){return m(this.yt,1)}set isComputing(e){this.yt=h(this.yt,1,e)}get isRunningSetter(){return m(this.yt,2)}set isRunningSetter(e){this.yt=h(this.yt,2,e)}get isBeingObserved(){return m(this.yt,4)}set isBeingObserved(e){this.yt=h(this.yt,4,e)}get isPendingUnobservation(){return m(this.yt,8)}set isPendingUnobservation(e){this.yt=h(this.yt,8,e)}get diffValue(){return+!!m(this.yt,16)}set diffValue(e){this.yt=h(this.yt,16,e===1)}get(){if(this.isComputing&&t(32,this.tt,this.derivation),F.inBatch!==0||this.H&&this.H.size!==0||this.Mt){let e=this.isBeingObserved;if(Fe(this),Ce(this)){let e=F.trackingContext;e||!this.Mt&&!this.isBeingObserved||(F.trackingContext=this),this.trackAndCompute()&&function(e){var t;e.F!==2&&(e.F=2,(t=e.H)==null||t.forEach(t=>{t.K===1?t.K=2:t.K===0&&(e.F=0)}))}(this),F.trackingContext=e}else !e&&this.isBeingObserved&&this.L.forEach(Pe)}else Ce(this)&&(this.Nt(),Me(),this.rt=this.Rt(!1),Ne());let e=this.rt;if(Se(e))throw e.cause;return e}set(e){if(this.St){this.isRunningSetter&&t(33,this.tt),this.isRunningSetter=!0;try{this.St.call(this.At,e)}finally{this.isRunningSetter=!1}}else t(34,this.tt)}trackAndCompute(){let e=this.rt,t=this.K===-1,n=this.Rt(!0),r=t||Se(e)||Se(n)||!this.xt(e,n);return r&&(this.rt=n),r}Rt(e){let t;if(this.isComputing=!0,e)t=we(this,this.derivation,this.At);else if(!0===F.disableErrorBoundaries)t=this.derivation.call(this.At);else try{t=this.derivation.call(this.At)}catch(e){t=new yn(e)}return this.isComputing=!1,t}G(){this.Mt||(Te(this),this.rt=void 0)}Nt(){}toString(){return`${this.tt}[${this.derivation.toString()}]`}valueOf(){return f(this.get())}[Symbol.toPrimitive](){return this.valueOf()}};let vn=l(`ComputedValue`,_n);var yn=class{constructor(e){this.cause=void 0,this.cause=e}};let bn=[`mobxGuid`,`spyListeners`,`enforceActions`,`computedRequiresReaction`,`reactionRequiresObservable`,`observableRequiresReaction`,`allowStateReads`,`disableErrorBoundaries`,`runId`,`UNCHANGED`];var xn=class{constructor(){this.version=7,this.UNCHANGED={},this.trackingDerivation=null,this.trackingContext=null,this.runId=0,this.mobxGuid=0,this.inBatch=0,this.pendingUnobservations=[],this.pendingReactions=[],this.isRunningReactions=!1,this.isRunningUnobservations=!1,this.allowStateChanges=!1,this.allowStateReads=!0,this.enforceActions=!0,this.spyListeners=[],this.globalReactionErrorHandlers=[],this.computedRequiresReaction=!1,this.reactionRequiresObservable=!1,this.observableRequiresReaction=!1,this.disableErrorBoundaries=!1,this.suppressReactionErrors=!1,this.safeDescriptors=!0}};let Sn=!0,Cn=!1,F=function(){let e=globalThis;return e.__mobxInstanceCount>0&&!e.__mobxGlobals&&(Sn=!1),e.__mobxGlobals&&e.__mobxGlobals.version!==7&&(Sn=!1),Sn?e.__mobxGlobals?(e.__mobxInstanceCount+=1,e.__mobxGlobals.UNCHANGED||(e.__mobxGlobals.UNCHANGED={}),e.__mobxGlobals):(e.__mobxInstanceCount=1,e.__mobxGlobals=new xn):(setTimeout(()=>{Cn||t(35)},1),new xn)}();var wn=class{constructor(e=`Reaction`,t,n,r){this.tt=void 0,this.Et=void 0,this.kt=void 0,this.Ct=void 0,this.L=[],this.$=[],this.K=-1,this.U=0,this.W=0,this.yt=0,this.It=void 0,this.tt=e,this.Et=t,this.kt=n,this.Ct=r}get isDisposed(){return m(this.yt,1)}set isDisposed(e){this.yt=h(this.yt,1,e)}get isScheduled(){return m(this.yt,2)}set isScheduled(e){this.yt=h(this.yt,2,e)}get isTrackPending(){return m(this.yt,4)}set isTrackPending(e){this.yt=h(this.yt,4,e)}get isRunning(){return m(this.yt,8)}set isRunning(e){this.yt=h(this.yt,8,e)}get diffValue(){return+!!m(this.yt,16)}set diffValue(e){this.yt=h(this.yt,16,e===1)}q(){this.Y()}Y(){this.isScheduled||(this.isScheduled=!0,F.pendingReactions.push(this),Le())}X(){if(!this.isDisposed){Me(),this.isScheduled=!1;let e=F.trackingContext;if(F.trackingContext=this,Ce(this)){this.isTrackPending=!0;try{this.Et()}catch(e){this.Pt(e)}}F.trackingContext=e,Ne()}}track(e){if(this.isDisposed)return;Me(),this.isRunning=!0;let t=F.trackingContext;F.trackingContext=this;let n=we(this,e,void 0);F.trackingContext=t,this.isRunning=!1,this.isTrackPending=!1,this.isDisposed&&Te(this),Se(n)&&this.Pt(n.cause),Ne()}Pt(e){if(this.kt)this.kt(e,this);else{if(F.disableErrorBoundaries)throw e;F.suppressReactionErrors||console.error(`[mobx] uncaught error in '${this}'`,e),F.globalReactionErrorHandlers.forEach(t=>t(e,this))}}dispose(){var e;this.isDisposed||(this.isDisposed=!0,(e=this.It)==null||e.call(this),this.isRunning||(Me(),Te(this),Ne()))}Z(e){let t=()=>this.dispose();return e!=null&&e.addEventListener&&!this.isDisposed&&(e.addEventListener(`abort`,t),this.It=()=>e.removeEventListener==null?void 0:e.removeEventListener(`abort`,t)),t[M]=this,`dispose`in Symbol&&typeof Symbol.dispose==`symbol`&&(t[Symbol.dispose]=t),t}toString(){return`Reaction[${this.tt}]`}};let Tn=100,En=e=>e(),Dn=l(`Reaction`,wn),On=`action`,kn=`autoAction`,An=b(On),jn=b(`action.bound`,{bound:!0}),Mn=b(kn,{autoAction:!0}),Nn=b(`autoAction.bound`,{autoAction:!0,bound:!0}),Pn=Be(!1);Nt(Pn,An);let Fn=Be(!0);Nt(Fn,Mn);let In=ze(jn),Ln=ze(Nn),Rn=e=>e(),zn=`always`;var Bn=class extends Error{constructor(){super(`FLOW_CANCELLED`),Object.setPrototypeOf(this,new.target.prototype),this.name=`FlowCancellationError`}toString(){return`Error: ${this.message}`}};let Vn=ee(`flow`),Hn=ee(`flow.bound`,{bound:!0}),Un=Nt(function(e,t){if(t&&typeof t.kind==`string`)return T(Vn,e,t);let n=e,i=n.name||`flow`,a=function(){let e=arguments,t=Pn(i,n).apply(this,e),a,o,s=new Promise(function(e,n){function s(e){let r;o=void 0;try{r=Pn(i,t.next).call(t,e)}catch(e){return n(e)}l(r)}function c(e){let r;o=void 0;try{r=Pn(i,t.throw).call(t,e)}catch(e){return n(e)}l(r)}function l(t){if(!r(t?.then))return t.done?e(t.value):(o=Promise.resolve(t.value),o.then(s,c));t.then(l,n)}a=n,s(void 0)});return s.cancel=Pn(i,function(){try{o&&Ye(o);let e=t.return(void 0),n=Promise.resolve(e.value);n.then(Bt,Bt),Ye(n),a(new Bn)}catch(e){a(e)}}),s};return a.isMobXFlow=!0,a},Vn),Wn=fe(Hn,T),Gn={has:(e,t)=>ct(e).et(t),get:(e,t)=>ct(e).Tt(t),set(e,t,n){var r;return!!i(t)&&((r=ct(e).Bt(t,n,!0))==null||r)},deleteProperty(e,t){var n;return!!i(t)&&((n=ct(e).Dt(t,!0))==null||n)},defineProperty(e,t,n){var r;return(r=ct(e).l(t,n))==null||r},ownKeys:e=>ct(e).it(),preventExtensions(e){t(13)}},Kn=Symbol(`mobx-keys`),qn=`splice`,Jn=`update`,Yn={get(e,t){let n=e[M];return t===M?n:t===`length`?n.Kt():typeof t!=`string`||isNaN(t)?p(Zn,t)?Zn[t]:e[t]:n.Tt(parseInt(t))},set(e,t,n){let r=e[M];return t===`length`?r.Lt(n):typeof t==`symbol`||isNaN(t)?e[t]=n:r.Bt(parseInt(t),n),!0},preventExtensions(){t(15)}};var Xn=class{constructor(e=`ObservableArray`,t,n){this.$t=void 0,this.ct=void 0,this.j=[],this.st=void 0,this.ot=void 0,this.A=void 0,this.dehancer=void 0,this.v=void 0,this.Ut=0,this.$t=n,this.ct=new Ut(e),this.A=(e,n)=>t(e,n,`ObservableArray[..]`)}Wt(e){return this.dehancer===void 0?e:this.dehancer(e)}ht(e){return this.dehancer!==void 0&&e.length>0?e.map(this.dehancer):e}Kt(){return this.ct.reportObserved(),this.j.length}Lt(e){(!Number.isInteger(e)||e<0)&&t(40,e);let n=this.j.length;if(e!==n)if(e>n){let t=Array.from({length:e-n});this.wt(n,0,t)}else this.wt(e,n-e)}zt(e,n){e!==this.Ut&&t(16),this.Ut+=n}wt(e,t,n){let r=this.j.length;if(e===void 0?e=0:e>r?e=r:e<0&&(e=Math.max(0,r+e)),t=arguments.length===1?r-e:t==null?0:Math.max(0,Math.min(t,r-e)),n===void 0&&(n=Lt),lt(this)){let r=A(this,{object:this.v,type:qn,index:e,removedCount:t,added:n});if(!r)return Lt;t=r.removedCount,n=r.added}n=n.length===0?n:n.map(e=>this.A(e,void 0));let i=this.qt(e,t,n);return t===0&&n.length===0||this.Ft(e,n,i),this.ht(i)}qt(e,t,n){if(n.length<1e4)return this.j.splice(e,t,...n);{let r=this.j.slice(e,e+t),i=this.j.slice(e+t);this.j.length+=n.length-t;for(let t=0;t<n.length;t++)this.j[e+t]=n[t];for(let t=0;t<i.length;t++)this.j[e+n.length+t]=i[t];return r}}Ht(e,t,n){let r=dt(this),i=r?{observableKind:`array`,object:this.v,type:Jn,debugObjectName:this.ct.tt,index:e,newValue:t,oldValue:n}:null;this.ct.reportChanged(),r&&pt(this,i)}Ft(e,t,n){let r=dt(this),i=r?{observableKind:`array`,object:this.v,debugObjectName:this.ct.tt,type:qn,index:e,removed:n,added:t,removedCount:n.length,addedCount:t.length}:null;this.ct.reportChanged(),r&&pt(this,i)}Tt(e){return this.ct.reportObserved(),this.Wt(this.j[e])}Bt(e,t){let n=this.j;if(e<n.length){let r=n[e];if(lt(this)){let n=A(this,{type:Jn,object:this.v,index:e,newValue:t});if(!n)return;t=n.newValue}(t=this.A(t,r))!==r&&(n[e]=t,this.Ht(e,t,r))}else{let r=Array.from({length:e+1-n.length});r[r.length-1]=t,this.wt(n.length,0,r)}}},Zn={clear(){return this.splice(0)},replace(e){let t=this[M];return t.wt(0,t.j.length,e)},toJSON(){return this.slice()},splice(e,t,...n){let r=this[M];switch(arguments.length){case 0:return[];case 1:return r.wt(e);case 2:return r.wt(e,t)}return r.wt(e,t,n)},spliceWithArray(e,t,n){return this[M].wt(e,t,n)},push(...e){let t=this[M];return t.wt(t.j.length,0,e),t.j.length},pop(){return this.splice(Math.max(this[M].j.length-1,0),1)[0]},shift(){return this.splice(0,1)[0]},unshift(...e){let t=this[M];return t.wt(0,0,e),t.j.length},reverse(){return F.trackingDerivation&&t(37,`reverse`),this.replace(this.slice().reverse()),this},sort(){F.trackingDerivation&&t(37,`sort`);let e=this.slice();return e.sort.apply(e,arguments),this.replace(e),this},remove(e){let t=this[M],n=t.ht(t.j).indexOf(e);return n>-1&&(this.splice(n,1),!0)}};j(`at`,ht),j(`concat`,ht),j(`flat`,ht),j(`includes`,ht),j(`indexOf`,ht),j(`join`,ht),j(`lastIndexOf`,ht),j(`slice`,ht),j(`toString`,ht),j(`toLocaleString`,ht),j(`toSorted`,ht),j(`toSpliced`,ht),j(`with`,ht),j(`every`,gt),j(`filter`,gt),j(`find`,gt),j(`findIndex`,gt),j(`findLast`,gt),j(`findLastIndex`,gt),j(`flatMap`,gt),j(`forEach`,gt),j(`map`,gt),j(`some`,gt),j(`toReversed`,gt),j(`reduce`,_t),j(`reduceRight`,_t);let Qn=l(`ObservableArrayAdministration`,Xn),$n={},er=`delete`;var tr=class{constructor(e,t=v,n=`ObservableMap`){this.A=void 0,this.tt=void 0,this[M]=$n,this.ft=void 0,this.dt=void 0,this.lt=void 0,this.st=void 0,this.ot=void 0,this.dehancer=void 0,this.A=t,this.tt=n,Dt(()=>{this.lt=g(`ObservableMap.keys()`),this.ft=new Map,this.dt=new Map,e&&this.merge(e)})}et(e){return this.ft.has(e)}has(e){if(!F.trackingDerivation)return this.et(e);let t=this.dt.get(e);if(!t){let n=t=new hn(this.et(e),y,`ObservableMap.key?`,!1);this.dt.set(e,n),n.onBUOL=new Set([()=>this.dt.delete(e)])}return t.get()}set(e,t){let n=this.et(e);if(lt(this)){let r=A(this,{type:n?Jn:`add`,object:this,newValue:t,name:e});if(!r)return this;t=r.newValue}return n?this.Gt(e,t):this.Jt(e,t),this}delete(e){if(lt(this)&&!A(this,{type:er,object:this,name:e}))return!1;if(this.et(e)){let t=dt(this),n=t?{observableKind:`map`,debugObjectName:this.tt,type:er,object:this,oldValue:this.ft.get(e).rt,name:e}:null;return ot(()=>{var t;this.lt.reportChanged(),(t=this.dt.get(e))==null||t.Ot(!1),this.ft.get(e).Ot(void 0),this.ft.delete(e)}),t&&pt(this,n),!0}return!1}Gt(e,t){let n=this.ft.get(e);if((t=n.jt(t))!==F.UNCHANGED){let r=dt(this),i=r?{observableKind:`map`,debugObjectName:this.tt,type:Jn,object:this,oldValue:n.rt,name:e,newValue:t}:null;n.Ot(t),r&&pt(this,i)}}Jt(e,t){ot(()=>{var n;let r=new hn(t,this.A,`ObservableMap.key`,!1);this.ft.set(e,r),t=r.rt,(n=this.dt.get(e))==null||n.Ot(!0),this.lt.reportChanged()});let n=dt(this);n&&pt(this,n?{observableKind:`map`,debugObjectName:this.tt,type:`add`,object:this,name:e,newValue:t}:null)}get(e){return this.has(e)?this.Wt(this.ft.get(e).get()):this.Wt(void 0)}getOrInsert(e,t){return this.has(e)||this.set(e,t),this.get(e)}getOrInsertComputed(e,t){return this.has(e)||this.set(e,t(e)),this.get(e)}Wt(e){return this.dehancer===void 0?e:this.dehancer(e)}keys(){return this.lt.reportObserved(),this.ft.keys()}values(){let e=this,t=this.keys();return yt({next(){let{done:n,value:r}=t.next();return{done:n,value:n?void 0:e.get(r)}}})}entries(){let e=this,t=this.keys();return yt({next(){let{done:n,value:r}=t.next();return{done:n,value:n?void 0:[r,e.get(r)]}}})}[Symbol.iterator](){return this.entries()}forEach(e,t){for(let[n,r]of this)e.call(t,r,n,this)}merge(e){return nr(e)&&(e=new Map(e)),ot(()=>{o(e)?function(e){let t=Object.keys(e),n=Object.getOwnPropertySymbols(e);return n.length?[...t,...n.filter(t=>It.propertyIsEnumerable.call(e,t))]:t}(e).forEach(t=>this.set(t,e[t])):Array.isArray(e)?e.forEach(([e,t])=>this.set(e,t)):u(e)?(function(e){return Object.getPrototypeOf(Object.getPrototypeOf(Object.getPrototypeOf(e)))===null}(e)||t(19,e),e.forEach((e,t)=>this.set(t,e))):e!=null&&t(20,e)}),this}clear(){ot(()=>{Ee(()=>{for(let e of this.keys())this.delete(e)})})}replace(e){return ot(()=>{let n=function(e){if(u(e)||nr(e))return e;if(Array.isArray(e))return new Map(e);if(o(e)){let t=new Map;for(let n in e)t.set(n,e[n]);return t}return t(21,e)}(e),r=new Map,i=!1;for(let e of this.ft.keys())if(!n.has(e))if(this.delete(e))i=!0;else{let t=this.ft.get(e);r.set(e,t)}for(let[e,t]of n.entries()){let n=this.ft.has(e);if(this.set(e,t),this.ft.has(e)){let t=this.ft.get(e);r.set(e,t),n||(i=!0)}}if(!i)if(this.ft.size!==r.size)this.lt.reportChanged();else{let e=this.ft.keys(),t=r.keys(),n=e.next(),i=t.next();for(;!n.done;){if(n.value!==i.value){this.lt.reportChanged();break}n=e.next(),i=t.next()}}this.ft=r}),this}get size(){return this.lt.reportObserved(),this.ft.size}toString(){return`[object ObservableMap]`}toJSON(){return Array.from(this)}get[Symbol.toStringTag](){return`Map`}},nr=l(`ObservableMap`,tr);let rr={};var ir=class{constructor(e,t=v,n=`ObservableSet`){this.tt=void 0,this[M]=rr,this.ft=new Set,this.ct=void 0,this.ot=void 0,this.st=void 0,this.dehancer=void 0,this.A=void 0,this.tt=n,this.A=(e,r)=>t(e,r,n),Dt(()=>{this.ct=g(this.tt),e&&this.replace(e)})}Wt(e){return this.dehancer===void 0?e:this.dehancer(e)}clear(){ot(()=>{Ee(()=>{for(let e of this.ft.values())this.delete(e)})})}forEach(e,t){for(let n of this)e.call(t,n,n,this)}get size(){return this.ct.reportObserved(),this.ft.size}add(e){if(lt(this)){let t=A(this,{type:`add`,object:this,newValue:e});if(!t)return this;e=t.newValue}if(!this.has(e)){ot(()=>{e=this.A(e,void 0),this.ft.add(e),this.ct.reportChanged()});let t=dt(this);t&&pt(this,t?{observableKind:`set`,debugObjectName:this.tt,type:`add`,object:this,newValue:e}:null)}return this}delete(e){if(lt(this)&&!A(this,{type:er,object:this,oldValue:e}))return!1;if(this.has(e)){let t=dt(this),n=t?{observableKind:`set`,debugObjectName:this.tt,type:er,object:this,oldValue:e}:null;return ot(()=>{this.ct.reportChanged(),this.ft.delete(e)}),t&&pt(this,n),!0}return!1}has(e){return this.ct.reportObserved(),this.ft.has(this.Wt(e))}entries(){let e=this.values();return bt({next(){let{value:t,done:n}=e.next();return n?{value:void 0,done:n}:{value:[t,t],done:n}}})}keys(){return this.values()}values(){this.ct.reportObserved();let e=this,t=this.ft.values();return bt({next(){let{value:n,done:r}=t.next();return r?{value:void 0,done:r}:{value:e.Wt(n),done:r}}})}intersection(e){return new Set(this).intersection(e)}union(e){return new Set(this).union(e)}difference(e){return new Set(this).difference(e)}symmetricDifference(e){return new Set(this).symmetricDifference(e)}isSubsetOf(e){return new Set(this).isSubsetOf(e)}isSupersetOf(e){return new Set(this).isSupersetOf(e)}isDisjointFrom(e){return new Set(this).isDisjointFrom(e)}replace(e){return I(e)&&(e=new Set(e)),Array.isArray(e)||d(e)?ot(()=>{let t=d(e)?e:new Set(e);if(t.size!==0)if(this.ft.size!==0){for(let e of this.ft.values())t.has(this.Wt(e))||this.delete(e);t.forEach(e=>this.add(e))}else t.forEach(e=>this.add(e));else this.clear()}):e!=null&&t(41,e),this}toJSON(){return Array.from(this)}toString(){return`[object ObservableSet]`}[Symbol.iterator](){return this.values()}get[Symbol.toStringTag](){return`Set`}},I=l(`ObservableSet`,ir);let ar=Object.create(null),or=`remove`;var sr=class{constructor(e,t=new Map,n,r=qt){this.h=void 0,this.j=void 0,this.tt=void 0,this.ut=void 0,this.lt=void 0,this.ot=void 0,this.st=void 0,this.v=void 0,this.p=void 0,this.Xt=void 0,this.Qt=void 0,this.O=void 0,this.V=void 0,this.h=e,this.j=t,this.tt=n,this.ut=r,this.lt=new Ut(`ObservableObject.keys`),this.p=o(this.h)}_(e){return(this.j.get(e)??this.vt(e)??this.bt(e)).get()}vt(e){let t=this.O?.get(e);if(!t)return;this.O.delete(e),this.O.size===0&&(this.O=void 0);let n=t();return this.j.set(e,n),n}bt(e){let t=this.V?.get(e);if(!t)return;this.V.delete(e),this.V.size===0&&(this.V=void 0);let n=t();return this.j.set(e,n),n}M(e,t){let n=this.j.get(e)??this.vt(e)??this.bt(e);if(n instanceof _n)return n.set(t),!0;if(lt(this)){let n=A(this,{type:Jn,object:this.v||this.h,name:e,newValue:t});if(!n)return null;t=n.newValue}if((t=n.jt(t))!==F.UNCHANGED){let r=dt(this),i=r?{type:Jn,observableKind:`object`,debugObjectName:this.tt,object:this.v||this.h,oldValue:n.rt,name:e,newValue:t}:null;n.Ot(t),r&&pt(this,i)}return!0}Tt(e){return F.trackingDerivation&&!p(this.h,e)&&this.et(e),this.h[e]}Bt(e,t,n=!1){return p(this.h,e)?this.j.has(e)?this.M(e,t):n?Reflect.set(this.h,e,t):(this.h[e]=t,!0):this.u(e,{value:t,enumerable:!0,writable:!0,configurable:!0},this.ut,n)}et(e){if(!F.trackingDerivation)return e in this.h;this.Qt||=new Map;let t=this.Qt.get(e);return t||(t=new hn(e in this.h,y,`ObservableObject.key?`,!1),this.Qt.set(e,t)),t.get()}u(e,t,n,r=!1){return!0===n&&(n=this.ut),!1===n?this.l(e,t,r):n.u(this,e,t,r)}l(e,t,n=!1){try{Me();let r=this.Dt(e);if(!r)return r;if(lt(this)){let n=A(this,{object:this.v||this.h,name:e,type:`add`,newValue:t.value});if(!n)return null;let{newValue:r}=n;t.value!==r&&(t=Nt({},t,{value:r}))}if(n){if(!Reflect.defineProperty(this.h,e,t))return!1}else Ft(this.h,e,t);this.Yt(e,t.value)}finally{Ne()}return!0}S(e,t,n,r=!1){try{Me();let i=this.Dt(e);if(!i)return i;if(lt(this)){let n=A(this,{object:this.v||this.h,name:e,type:`add`,newValue:t});if(!n)return null;t=n.newValue}let a=St(e),o={configurable:!F.safeDescriptors||this.p,enumerable:!0,get:a.get,set:a.set};if(r){if(!Reflect.defineProperty(this.h,e,o))return!1}else Ft(this.h,e,o);let s=new hn(t,n,`ObservableObject.key`,!1);this.j.set(e,s),this.Yt(e,s.rt)}finally{Ne()}return!0}m(e,t,n=!1){try{Me();let r=this.Dt(e);if(!r)return r;if(lt(this)&&!A(this,{object:this.v||this.h,name:e,type:`add`,newValue:void 0}))return null;t.name||=`ObservableObject.key`,t.context=this.v||this.h;let i=St(e),a={configurable:!F.safeDescriptors||this.p,enumerable:!1,get:i.get,set:i.set};if(n){if(!Reflect.defineProperty(this.h,e,a))return!1}else Ft(this.h,e,a);this.j.set(e,new _n(t)),this.Yt(e,void 0)}finally{Ne()}return!0}Dt(e,t=!1){if(!p(this.h,e))return!0;if(lt(this)&&!A(this,{object:this.v||this.h,name:e,type:or}))return null;try{var n;Me();let r=dt(this),i=this.j.get(e),a;if(i||!r||(a=Pt(this.h,e)?.value),t){if(!Reflect.deleteProperty(this.h,e))return!1}else delete this.h[e];i&&(this.j.delete(e),i instanceof hn&&(a=i.rt),Ie(i)),this.lt.reportChanged(),(n=this.Qt)==null||(n=n.get(e))==null||n.set(e in this.h),r&&r&&pt(this,{type:or,observableKind:`object`,object:this.v||this.h,debugObjectName:this.tt,oldValue:a,name:e})}finally{Ne()}return!0}Yt(e,t){var n;let r=dt(this);r&&r&&pt(this,r?{type:`add`,observableKind:`object`,debugObjectName:this.tt,object:this.v||this.h,name:e,newValue:t}:null),(n=this.Qt)==null||(n=n.get(e))==null||n.set(!0),this.lt.reportChanged()}it(){return this.lt.reportObserved(),Vt(this.h)}nt(){return this.lt.reportObserved(),Object.keys(this.h)}};let cr=l(`ObservableObjectAdministration`,sr),lr=It.toString,ur=globalThis.Iterator?.prototype||{};e.$mobx=M,e.FlowCancellationError=Bn,e.ObservableMap=tr,e.ObservableSet=ir,e.Reaction=wn,e._allowStateChanges=xe,e._allowStateChangesInsideComputed=Ve,e._allowStateReadsEnd=function(e){F.allowStateReads=e},e._allowStateReadsStart=function(e){let t=F.allowStateReads;return F.allowStateReads=e,t},e._autoAction=Fn,e._autoActionBound=Ln,e._endAction=be,e._getAdministration=Tt,e._getGlobalState=function(){return F},e._interceptReads=function(e,t,n){let r;return nr(e)||vt(e)||gn(e)?r=Tt(e):Ct(e)&&(r=Tt(e,t)),r.dehancer=typeof t==`function`?t:n,()=>{r.dehancer=void 0}},e._isComputingDerivation=function(){return F.trackingDerivation!==null},e._resetGlobalState=function(){let e=new xn;for(let t in e)bn.indexOf(t)===-1&&(F[t]=e[t]);F.allowStateChanges=!F.enforceActions},e._startAction=ye,e.action=Pn,e.actionBound=In,e.autorun=Ue,e.compareDefault=Gt,e.compareIdentity=function(e,t){return e===t},e.compareShallow=function(e,t){return Ot(e,t,1)},e.compareStructural=_,e.computed=ln,e.computedStruct=cn,e.configure=function(e){!0===e.isolateGlobalState&&function(){if((F.pendingReactions.length||F.inBatch||F.isRunningReactions)&&t(36),Cn=!0,Sn){let e=globalThis;--e.__mobxInstanceCount===0&&(e.__mobxGlobals=void 0),F=new xn}}();let{enforceActions:n}=e;if(n!==void 0){let e=n===zn?zn:n===`observed`;F.enforceActions=e,F.allowStateChanges=!0!==e&&e!==zn}[`computedRequiresReaction`,`reactionRequiresObservable`,`observableRequiresReaction`,`disableErrorBoundaries`,`safeDescriptors`].forEach(t=>{t in e&&(F[t]=!!e[t])}),F.allowStateReads=!F.observableRequiresReaction,e.reactionScheduler&&function(e){let t=En;En=n=>e(()=>t(n))}(e.reactionScheduler)},e.createAtom=g,e.defineProperty=function(e,n,r){if(Ct(e))return e[M].l(n,r);t(39)},e.entries=function(e){return Ct(e)?et(e).map(t=>[t,e[t]]):nr(e)?et(e).map(t=>[t,e.get(t)]):I(e)?Array.from(e.entries()):vt(e)?e.map((e,t)=>[t,e]):void t(7)},e.extendObservable=Ke,e.flow=Un,e.flowBound=Wn,e.flowResult=function(e){return e},e.get=function(e,n){if(tt(e,n))return Ct(e)?e[M].Tt(n):nr(e)?e.get(n):vt(e)?e[n]:void t(11)},e.getAtom=wt,e.getDebugName=Et,e.getDependencyTree=function(e,t){return qe(wt(e,t))},e.getObserverTree=function(e,t){return Je(wt(e,t))},e.has=tt,e.intercept=function(e,t,n){return r(n)?function(e,t,n){return ut(Tt(e,t),n)}(e,t,n):function(e,t){return ut(Tt(e),t)}(e,t)},e.isAction=He,e.isBoxedObservable=gn,e.isComputed=function(e){return Ze(e)},e.isComputedProp=function(e,t){return Ze(e,t)},e.isFlow=Xe,e.isFlowCancellationError=function(e){return e instanceof Bn},e.isObservable=$e,e.isObservableArray=vt,e.isObservableMap=nr,e.isObservableObject=Ct,e.isObservableProp=function(e,t){return Qe(e,t)},e.isObservableSet=I,e.keys=et,e.makeAutoObservable=function(e,t,n){return o(e)?Ke(e,e,t,n):(Dt(()=>{let r=xt(e,n)[M];if(!e[Kn]){let t=Object.getPrototypeOf(e),n=new Set([...Vt(e),...Vt(t)]);n.delete(`constructor`),n.delete(M),c(t,Kn,n)}e[Kn].forEach(e=>mt(r,e,!t||!(e in t)||t[e]))}),e)},e.makeObservable=function(e,t,n){return Dt(()=>{let r=xt(e,n)[M];Vt(t).forEach(e=>mt(r,e,t[e]))}),e},e.observable=an,e.observableDeep=nn,e.observableRef=en,e.observableShallow=tn,e.observableStruct=rn,e.observe=function(e,t,n,i){return r(n)?function(e,t,n,r){return rt(Tt(e,t),n,r)}(e,t,n,i):function(e,t,n){let r=Tt(e);if(vt(e))n&&t({observableKind:`array`,object:r.v,debugObjectName:r.ct.tt,type:`splice`,index:0,added:r.j.slice(),addedCount:r.j.length,removed:[],removedCount:0});else if(!nr(e)&&!I(e)&&!Ct(e))return rt(r,t,n);return ft(r,t)}(e,t,n)},e.onBecomeObserved=function(e,t,n){return Ge(`onBO`,e,t,n)},e.onBecomeUnobserved=function(e,t,n){return Ge(`onBUO`,e,t,n)},e.onReactionError=function(e){return F.globalReactionErrorHandlers.push(e),()=>{let t=F.globalReactionErrorHandlers.indexOf(e);t>=0&&F.globalReactionErrorHandlers.splice(t,1)}},e.override=N,e.ownKeys=nt,e.reaction=function(e,t,n=Rt){function r(){if(p=!1,h.isDisposed)return;let t=!1,r=d;h.track(()=>{let n=xe(!1,()=>e(h));t=f||!m(d,n),d=n}),(f&&n.fireImmediately||!f&&t)&&o(d,r,h),f=!1}var i;let a=n.name??`Reaction`,o=Pn(a,n.onError?(s=n.onError,c=t,function(){try{return c.apply(this,arguments)}catch(e){s.call(this,e)}}):t);var s,c;let l=!n.scheduler&&!n.delay,u=We(n),d,f=!0,p=!1,m=n.equals||Gt,h=new wn(a,()=>{f||l?r():p||(p=!0,u(r))},n.onError,n.requiresObservable);return n!=null&&(i=n.signal)!=null&&i.aborted||h.Y(),h.Z(n?.signal)},e.remove=function(e,n){Ct(e)?e[M].Dt(n):nr(e)||I(e)?e.delete(n):vt(e)?(typeof n!=`number`&&(n=parseInt(n,10)),e.splice(n,1)):t(9)},e.runInAction=Ve,e.set=function e(n,r,i){if(arguments.length===2&&!I(n)){Me();let t=r;try{for(let r in t)e(n,r,t[r])}finally{Ne()}return}Ct(n)?n[M].Bt(r,i):nr(n)?n.set(r,i):I(n)?n.add(r):vt(n)?(typeof r!=`number`&&(r=parseInt(r,10)),r<0&&t(42,r),Me(),r>=n.length&&(n.length=r+1),n[r]=i,Ne()):t(8)},e.spy=function(){return console.warn(`[mobx.spy] Is a no-op in production builds`),function(){}},e.toJS=function(e){return at(e,new Map)},e.transaction=ot,e.untracked=Ee,e.values=function(e){return Ct(e)?et(e).map(t=>e[t]):nr(e)?et(e).map(t=>e.get(t)):I(e)?Array.from(e.values()):vt(e)?e.slice():void t(6)},e.when=function(e,t,n){return arguments.length===1||t&&typeof t==`object`?function(e,t){var n;if(t!=null&&(n=t.signal)!=null&&n.aborted)return Nt(Promise.reject(Error(`WHEN_ABORTED`)),{cancel:()=>null});let r,i,a=new Promise((n,a)=>{var o;let s=st(e,n,Nt({},t,{onError:a}));r=()=>{s(),a(Error(`WHEN_CANCELLED`))},i=()=>{s(),a(Error(`WHEN_ABORTED`))},t==null||(o=t.signal)==null||o.addEventListener==null||o.addEventListener(`abort`,i)}).finally(()=>{var e;return t==null||(e=t.signal)==null||e.removeEventListener==null?void 0:e.removeEventListener(`abort`,i)});return a.cancel=r,a}(e,t):st(e,t,n||{})}})),Sv=we((e=>{Object.defineProperty(e,`__esModule`,{value:!0});let t={0:`Invalid value for configuration 'enforceActions', expected 'never', 'always' or 'observed'`,1(e,t){return`Cannot apply '${e}' to '${t.toString()}': Field not found.`},5:`'keys()' can only be used on observable objects, arrays, sets and maps`,6:`'values()' can only be used on observable objects, arrays, sets and maps`,7:`'entries()' can only be used on observable objects, arrays and maps`,8:`'set()' can only be used on observable objects, arrays and maps`,9:`'remove()' can only be used on observable objects, arrays and maps`,10:`'has()' can only be used on observable objects, arrays and maps`,11:`'get()' can only be used on observable objects, arrays and maps`,12:`Invalid annotation`,13:`Dynamic observable objects cannot be frozen. If you're passing observables to 3rd party component/function that calls Object.freeze, pass copy instead: toJS(observable)`,14:`Intercept handlers should return nothing or a change object`,15:`Observable arrays cannot be frozen. If you're passing observables to 3rd party component/function that calls Object.freeze, pass copy instead: toJS(observable)`,16:`Modification exception: the internal structure of an observable array was changed.`,19(e){return`Cannot initialize from classes that inherit from Map: `+e.constructor.name},20(e){return`Cannot initialize map from `+e},21(e){return`Cannot convert to map from '${e}'`},23:`It is not possible to get index atoms from arrays`,24(e){return`Cannot obtain administration from `+e},25(e,t){return`the entry '${e}' does not exist in the observable map '${t}'`},26:`please specify a property`,27(e,t){return`no observable property '${e.toString()}' found on the observable object '${t}'`},28(e){return`Cannot obtain atom from `+e},29:`Expecting some object`,30:`invalid action stack. did you forget to finish an action?`,31:`missing option for computed: get`,32(e,t){return`Cycle detected in computation ${e}: ${t}`},33(e){return`The setter of computed value '${e}' is trying to update itself. Did you intend to update an _observable_ value, instead of the computed property?`},34(e){return`[ComputedValue '${e}'] It is not possible to assign a new value to a computed value.`},35:"There are multiple, different versions of MobX active. Make sure MobX is loaded only once or use `configure({ isolateGlobalState: true })`",36:`isolateGlobalState should be called before MobX is running any reactions`,37(e){return`[mobx] \`observableArray.${e}()\` mutates the array in-place, which is not allowed inside a derivation. Use \`array.slice().${e}()\` instead`},38:`'ownKeys()' can only be used on observable objects`,39:`'defineProperty()' can only be used on observable objects`,40(e){return`Out of range: `+e},41(e){return`Cannot initialize set from `+e},42(e){return`Invalid index: '${e}'`},43(e,t,n){return`Cannot apply '${e}' to '${t}' (kind: ${n}):\n'${e}' can only be used on properties with a function value.`},44(e){return`'${e}' can only be used with 'makeObservable'`}};function n(e,...n){{let r=typeof e==`string`?e:t[e];throw typeof r==`function`&&(r=r.apply(null,n)),Error(`[MobX] ${r}`)}}let r=Object.assign,i=Object.getOwnPropertyDescriptor,a=Object.defineProperty,o=Object.prototype,s=[];Object.freeze(s);let c={};Object.freeze(c);let l=Object.toString();function u(){return++P.mobxGuid}function d(e){let t=!1;return function(){if(!t)return t=!0,e.apply(this,arguments)}}let f=()=>{};function p(e){return typeof e==`function`}function m(e){switch(typeof e){case`string`:case`symbol`:case`number`:return!0}return!1}function h(e){return typeof e==`object`&&!!e}function g(e){if(!h(e))return!1;let t=Object.getPrototypeOf(e);if(t==null)return!0;let n=T(t,`constructor`)&&t.constructor;return typeof n==`function`&&n.toString()===l}function _(e){let t=e?.constructor;return t?t.name===`GeneratorFunction`||t.displayName===`GeneratorFunction`:!1}function v(e,t,n){a(e,t,{enumerable:!1,writable:!0,configurable:!0,value:n})}function y(e,t,n){a(e,t,{enumerable:!1,writable:!1,configurable:!0,value:n})}function b(e,t){let n=`isMobX`+e;return t.prototype[n]=!0,function(e){return h(e)&&e[n]===!0}}function x(e){return e!=null&&Object.prototype.toString.call(e)===`[object Map]`}function S(e){return Object.getPrototypeOf(Object.getPrototypeOf(Object.getPrototypeOf(e)))===null}function C(e){return e!=null&&Object.prototype.toString.call(e)===`[object Set]`}function w(e){let t=Object.keys(e),n=Object.getOwnPropertySymbols(e);return n.length?[...t,...n.filter(t=>o.propertyIsEnumerable.call(e,t))]:t}let ee=Reflect.ownKeys;function te(e){return typeof e==`string`?e:typeof e==`symbol`?e.toString():new String(e).toString()}function ne(e){return e===null?null:typeof e==`object`?``+e:e}function T(e,t){return o.hasOwnProperty.call(e,t)}let re=Object.getOwnPropertyDescriptors;function E(e,t){return!!(e&t)}function D(e,t,n){return n?e|=t:e&=~t,e}function ie(e,t){t.includes(e.kind)||n(`The decorator applied to '${String(e.name)}' cannot be used on a ${e.kind} element`)}let O=Symbol(`mobx administration`);var ae=class{constructor(e=`Atom@`+u()){this.name_=void 0,this.flags_=0,this.observers_=null,this.lastAccessedBy_=0,this.lowestObserverState_=-1,this.onBOL=void 0,this.onBUOL=void 0,this.name_=e}get isBeingObserved(){return E(this.flags_,1)}set isBeingObserved(e){this.flags_=D(this.flags_,1,e)}get isPendingUnobservation(){return E(this.flags_,2)}set isPendingUnobservation(e){this.flags_=D(this.flags_,2,e)}get diffValue(){return+!!E(this.flags_,4)}set diffValue(e){this.flags_=D(this.flags_,4,e===1)}onBO(){this.onBOL&&this.onBOL.forEach(e=>e())}onBUO(){this.onBUOL&&this.onBUOL.forEach(e=>e())}reportObserved(){return sn(this)}reportChanged(){nn(),cn(this),rn()}toString(){return this.name_}};let oe=b(`Atom`,ae);function se(e,t=f,n=f){let r=new ae(e);return t!==f&&(r.onBOL=new Set([t])),n!==f&&(r.onBUOL=new Set([n])),r}function ce(e,t){return e===t}function le(e,t){return Mi(e,t)}function ue(e,t){return Mi(e,t,1)}let de=Object.is;function fe(e,t,n){return e===null||typeof e!=`object`&&typeof e!=`function`||vr(e)?e:Array.isArray(e)?A.array(e,{name:n}):g(e)?A.object(e,void 0,{name:n}):x(e)?A.map(e,{name:n}):C(e)?A.set(e,{name:n}):typeof e==`function`&&!Ln(e)&&!lr(e)?_(e)?ar(e):Nn(n,e):e}function pe(e,t,r){if(e==null||Di(e)||ui(e)||mi(e)||yi(e))return e;if(Array.isArray(e))return A.array(e,{name:r,deep:!1});if(g(e))return A.object(e,void 0,{name:r,deep:!1});if(x(e))return A.map(e,{name:r,deep:!1});if(C(e))return A.set(e,{name:r,deep:!1});n(`The shallow modifier / decorator can only used in combination with arrays, objects, maps and sets`)}function me(e){return e}function he(e,t){return vr(e)&&n(`observable.struct should not be used with observable values`),Mi(e,t)?t:e}let ge=`override`,_e={annotationType_:ge,make_:ye,extend_:be};function ve(e){return e.annotationType_===ge}function ye(e,t){return e.isPlainObject_&&n(`Cannot apply '${this.annotationType_}' to '${e.name_}.${t.toString()}':\n'${this.annotationType_}' cannot be used on plain objects.`),T(e.appliedAnnotations_,t)||n(`'${e.name_}.${t.toString()}' is annotated with '${this.annotationType_}', but no such annotated member was found on prototype.`),0}function be(e,t,r,i){n(44,this.annotationType_)}function xe(e,t){return{annotationType_:e,options_:t,make_:Se,extend_:Ce}}function Se(e,t,n,r){var i;return(i=this.options_)!=null&&i.bound?this.extend_(e,t,n,!1)===null?0:1:r===e.target_?this.extend_(e,t,n,!1)===null?0:2:Ln(n.value)?1:(a(r,t,Ee(e,this,t,n,!1)),2)}function Ce(e,t,n,r){let i=Ee(e,this,t,n);return e.defineProperty_(t,i,r)}function we(e,t,r){ie(r,[`method`,`field`]);let{kind:i,name:a,addInitializer:o}=r,s=e,c=e=>yt(s.options_?.name??a.toString(),e,s.options_?.autoAction??!1);if(i==`field`)return function(e){var t;let n=e;return Ln(n)||(n=c(n)),(t=s.options_)!=null&&t.bound&&(n=n.bind(this),n.isMobxAction=!0),n};if(i==`method`){var l;return Ln(t)||(t=c(t)),(l=s.options_)!=null&&l.bound&&o(function(){let e=this,t=e[a].bind(e);t.isMobxAction=!0,e[a]=t}),t}n(43,s.annotationType_,String(a),i)}function Te(e,{annotationType_:t},r,{value:i}){p(i)||n(`Cannot apply '${t}' to '${e.name_}.${r.toString()}':\n'${t}' can only be used on properties with a function value.`)}function Ee(e,t,n,r,i=P.safeDescriptors){var a,o;Te(e,t,n,r);let{value:s}=r;return(a=t.options_)!=null&&a.bound&&(s=s.bind(e.proxy_??e.target_)),{value:yt(t.options_?.name??n.toString(),s,t.options_?.autoAction??!1,(o=t.options_)!=null&&o.bound?e.proxy_??e.target_:void 0),configurable:i?e.isPlainObject_:!0,enumerable:!1,writable:!i}}function k(e,t){return{annotationType_:e,options_:t,make_:De,extend_:Oe}}function De(e,t,n,r){var i;return r===e.target_?this.extend_(e,t,n,!1)===null?0:2:(i=this.options_)!=null&&i.bound&&(!T(e.target_,t)||!lr(e.target_[t]))&&this.extend_(e,t,n,!1)===null?0:lr(n.value)?1:(a(r,t,je(e,this,t,n,!1,!1)),2)}function Oe(e,t,n,r){let i=je(e,this,t,n,this.options_?.bound);return e.defineProperty_(t,i,r)}function ke(e,t,n){var r;ie(n,[`method`]);let{name:i,addInitializer:a}=n;return lr(t)||(t=ar(t)),(r=e.options_)!=null&&r.bound&&a(function(){let e=this,t=e[i].bind(e);t.isMobXFlow=!0,e[i]=t}),t}function Ae(e,{annotationType_:t},r,{value:i}){p(i)||n(`Cannot apply '${t}' to '${e.name_}.${r.toString()}':\n'${t}' can only be used on properties with a generator function value.`)}function je(e,t,n,r,i,a=P.safeDescriptors){Ae(e,t,n,r);let{value:o}=r;return lr(o)||(o=ar(o)),i&&(o=o.bind(e.proxy_??e.target_),o.isMobXFlow=!0),{value:o,configurable:a?e.isPlainObject_:!0,enumerable:!1,writable:!a}}function Me(e,t){return{annotationType_:e,options_:t,make_:Ne,extend_:Pe}}function Ne(e,t,n){return this.extend_(e,t,n,!1)===null?0:1}function Pe(e,t,n,i){return Ie(e,this,t,n),e.defineComputedProperty_(t,r({},this.options_,{get:n.get,set:n.set}),i)}function Fe(e,t,n){ie(n,[`getter`]);let i=e,{name:a,addInitializer:o}=n,s;function c(e,n){let o=r({},i.options_,{get:t,context:e});return o.name||=`${n.name_}.${a.toString()}`,new Ot(o)}return o(function(){let e=wi(this)[O],n=this,r=e.values_.get(a);r instanceof Ot&&r.derivation!==t&&e.values_.delete(a),(e.lazyComputedKeys_??=new Map).set(a,()=>c(n,e))}),function(){let e=this[O],n=e.values_.get(a);if(n instanceof Ot&&n.derivation!==t){let t=s?.get(this);return t||(t=c(this,e),(s??=new WeakMap).set(this,t)),t.get()}return e.getObservablePropValue_(a)}}function Ie(e,{annotationType_:t},r,{get:i}){i||n(`Cannot apply '${t}' to '${e.name_}.${r.toString()}':\n'${t}' can only be used on getter(+setter) properties.`)}function Le(e,t){return{annotationType_:e,options_:t,make_:Re,extend_:ze}}function Re(e,t,n){return this.extend_(e,t,n,!1)===null?0:1}function ze(e,t,n,r){return Ve(e,this,t,n),e.defineObservableProperty_(t,n.value,this.options_?.enhancer_??fe,r)}function Be(e,t,r){if(r.kind===`field`)throw n(`Please use \`@observable accessor ${String(r.name)}\` instead of \`@observable ${String(r.name)}\``);ie(r,[`accessor`]);let i=e,{kind:a,name:o}=r;if(a!==`accessor`)return;function s(e,t){let n=wi(e)[O];return(n.lazyObservableKeys_??=new Map).set(o,()=>new Et(t,i.options_?.enhancer_??fe,`${n.name_}.${o.toString()}`,!1)),n}return{get(){return(this[O]??s(this,t.get.call(this))).getObservablePropValue_(o)},set(e){return(this[O]??s(this,e)).setObservablePropValue_(o,e)},init(e){return s(this,e),e}}}function Ve(e,{annotationType_:t},r,i){`value`in i||n(`Cannot apply '${t}' to '${e.name_}.${r.toString()}':\n'${t}' cannot be used on getter/setter properties`)}let He=Ue();function Ue(e){return{annotationType_:`true`,options_:e,make_:Ke,extend_:qe}}let We=[He];function Ge(e){let t=e.deep!==!1,n=!!e.autoBind,r=!t|(n?2:0);return We[r]??(We[r]=Ue({deep:t,autoBind:n}))}function Ke(e,t,n,r){var i;if(n.get)return j.make_(e,t,n,r);if(n.set){let i=Ln(n.set)?n.set:yt(t.toString(),n.set);return r===e.target_?e.defineProperty_(t,{configurable:P.safeDescriptors?e.isPlainObject_:!0,set:i})===null?0:2:(a(r,t,{configurable:!0,set:i}),2)}if(r!==e.target_&&typeof n.value==`function`){var o;if(_(n.value)){var s;return((s=this.options_)!=null&&s.autoBind?or:ar).make_(e,t,n,r)}return((o=this.options_)!=null&&o.autoBind?Fn:Nn).make_(e,t,n,r)}let c=this.options_?.deep===!1?st:A;return typeof n.value==`function`&&(i=this.options_)!=null&&i.autoBind&&(n.value=n.value.bind(e.proxy_??e.target_)),c.make_(e,t,n,r)}function qe(e,t,n,r){var i;return n.get?j.extend_(e,t,n,r):n.set?e.defineProperty_(t,{configurable:P.safeDescriptors?e.isPlainObject_:!0,set:yt(t.toString(),n.set)},r):(typeof n.value==`function`&&(i=this.options_)!=null&&i.autoBind&&(n.value=n.value.bind(e.proxy_??e.target_)),(this.options_?.deep===!1?st:A).extend_(e,t,n,r))}function Je(e,t){return r(function(r,i){if(i&&typeof i.kind==`string`)return t(e,r,i);n(`Invalid arguments for \`${e.annotationType_}\``)},e)}let Ye={deep:!0,name:void 0,defaultDecorator:void 0};Object.freeze(Ye);function Xe(e){return e||Ye}let Ze=Le(`observable`),Qe=Le(`observable.ref`,{enhancer_:me}),$e=Le(`observable.shallow`,{enhancer_:pe}),et=Le(`observable.struct`,{enhancer_:he});function tt(e){return Je(e,Be)}function nt(e){return e.deep===!0?fe:e.deep===!1?me:it(e.defaultDecorator)}function rt(e){return e?e.defaultDecorator??Ge(e):void 0}function it(e){return e?e.options_?.enhancer_??fe:fe}function at(e,t,n){return t&&typeof t.kind==`string`?Be(Ze,e,t):vr(e)?e:g(e)?A.object(e,t,n):Array.isArray(e)?A.array(e,t):x(e)?A.map(e,t):C(e)?A.set(e,t):typeof e==`object`&&e?e:A.box(e,t)}let ot={box(e,t){let n=Xe(t);return new Et(e,nt(n),n.name,!0,n.equals)},array(e,t){let n=Xe(t);return ri(e,nt(n),n.name)},map(e,t){let n=Xe(t);return new pi(e,nt(n),n.name)},set(e,t){let n=Xe(t);return new vi(e,nt(n),n.name)},object(e,t,n){return Ai(()=>Jn(Hr({},n),e,t))}},st=tt(Qe),ct=tt($e),lt=tt(Ze),ut=tt(et);var A=r(at,Ze,ot);let dt=`computed`;function ft(e){return Je(e,Fe)}let pt=Me(dt),mt=ft(Me(`computed.struct`,{equals:le})),j=function(e,t){if(t&&typeof t.kind==`string`)return Fe(pt,e,t);if(g(e))return ft(Me(dt,e));p(e)||n("First argument to `computed` should be an expression."),p(t)&&n("A setter as second argument is no longer supported, use `{ set: fn }` option instead");let r=g(t)?t:{};return r.get=e,r.name||=e.name||``,new Ot(r)};r(j,pt);let ht=0,gt=1,_t=i(()=>{},`name`)?.configurable??!1,vt={value:`action`,configurable:!0,writable:!1,enumerable:!1};function yt(e,t,r=!1,i){p(t)||n("`action` can only be invoked on functions"),(typeof e!=`string`||!e)&&n(`actions should have valid names, got: '${e}'`);function o(){return bt(e,r,t,i||this,arguments)}return o.isMobxAction=!0,o.toString=()=>t.toString(),_t&&(vt.value=e,a(o,`name`,vt)),o}function bt(e,t,n,r,i){let a=xt(e,t,r,i);try{return n.apply(r,i)}catch(e){throw a.error_=e,e}finally{St(a)}}function xt(e,t,n,r){let i=vn()&&!!e,a=0;i&&(a=Date.now(),bn({type:F,name:e,object:n,arguments:r?Array.from(r):s}));let o=P.trackingDerivation,c=!t||!o;nn();let l=P.allowStateChanges;c&&(Vt(),l=wt(!0));let u=P.allowStateReads;M(!0);let d={runAsAction_:c,prevDerivation_:o,prevAllowStateChanges_:l,prevAllowStateReads_:u,notifySpy_:i,startTime_:a,actionId_:gt++,parentActionId_:ht};return ht=d.actionId_,d}function St(e){ht!==e.actionId_&&n(30),ht=e.parentActionId_,e.error_!==void 0&&(P.suppressReactionErrors=!0),Tt(e.prevAllowStateChanges_),Ut(e.prevAllowStateReads_),rn(),e.runAsAction_&&Ht(e.prevDerivation_),e.notifySpy_&&Sn({time:Date.now()-e.startTime_}),P.suppressReactionErrors=!1}function Ct(e,t){let n=wt(e);try{return t()}finally{Tt(n)}}function wt(e){let t=P.allowStateChanges;return P.allowStateChanges=e,t}function Tt(e){P.allowStateChanges=e}var Et=class extends ae{constructor(e,t,n=`ObservableValue@`+u(),r=!0,i=de){super(n),this.enhancer_=void 0,this.name_=void 0,this.equals_=void 0,this.hasUnreportedChange_=!1,this.interceptors_=void 0,this.changeListeners_=void 0,this.value_=void 0,this.dehancer=void 0,this.enhancer_=t,this.name_=n,this.equals_=i,this.value_=t(e,void 0,n),r&&vn()&&yn({type:`create`,object:this,observableKind:`value`,debugObjectName:this.name_,newValue:this.value_})}dehanceValue(e){return this.dehancer===void 0?e:this.dehancer(e)}set(e){let t=this.value_;if(e=this.prepareNewValue_(e),e!==P.UNCHANGED){let n=vn();n&&bn({type:ei,object:this,observableKind:`value`,debugObjectName:this.name_,newValue:e,oldValue:t}),this.setNewValue_(e),n&&Sn()}}prepareNewValue_(e){if(Pt(this),Ur(this)){let t=Gr(this,{object:this,type:ei,newValue:e});if(!t)return P.UNCHANGED;e=t.newValue}return e=this.enhancer_(e,this.value_,this.name_),this.equals_(this.value_,e)?P.UNCHANGED:e}setNewValue_(e){let t=this.value_;this.value_=e,this.reportChanged(),Kr(this)&&Jr(this,{type:ei,object:this,newValue:e,oldValue:t})}get(){return this.reportObserved(),this.dehanceValue(this.value_)}raw(){return this.value_}toJSON(){return this.get()}toString(){return`${this.name_}[${this.value_}]`}valueOf(){return ne(this.get())}[Symbol.toPrimitive](){return this.valueOf()}};let Dt=b(`ObservableValue`,Et);var Ot=class{constructor(e){this.dependenciesState_=-1,this.observing_=[],this.newObserving_=null,this.observers_=null,this.runId_=0,this.lastAccessedBy_=0,this.lowestObserverState_=0,this.unboundDepsCount_=0,this.value_=new At(null),this.name_=void 0,this.triggeredBy_=void 0,this.flags_=0,this.derivation=void 0,this.setter_=void 0,this.scope_=void 0,this.equals_=void 0,this.requiresReaction_=void 0,this.keepAlive_=void 0,this.onBOL=void 0,this.onBUOL=void 0,e.get||n(31),this.derivation=e.get,this.name_=e.name||`ComputedValue@`+u(),e.set&&(this.setter_=yt(this.name_+`-setter`,e.set)),this.equals_=e.equals||de,this.scope_=e.context,this.requiresReaction_=e.requiresReaction,this.keepAlive_=!!e.keepAlive}onBecomeStale_(){un(this)}onBO(){this.onBOL&&this.onBOL.forEach(e=>e())}onBUO(){this.onBUOL&&this.onBUOL.forEach(e=>e())}get isComputing(){return E(this.flags_,1)}set isComputing(e){this.flags_=D(this.flags_,1,e)}get isRunningSetter(){return E(this.flags_,2)}set isRunningSetter(e){this.flags_=D(this.flags_,2,e)}get isBeingObserved(){return E(this.flags_,4)}set isBeingObserved(e){this.flags_=D(this.flags_,4,e)}get isPendingUnobservation(){return E(this.flags_,8)}set isPendingUnobservation(e){this.flags_=D(this.flags_,8,e)}get diffValue(){return+!!E(this.flags_,16)}set diffValue(e){this.flags_=D(this.flags_,16,e===1)}get(){if(this.isComputing&&n(32,this.name_,this.derivation),P.inBatch===0&&(!this.observers_||this.observers_.size===0)&&!this.keepAlive_)Mt(this)&&(this.warnAboutUntrackedRead_(),nn(),this.value_=this.computeValue_(!1),rn());else{let e=this.isBeingObserved;if(sn(this),Mt(this)){let e=P.trackingContext;!e&&(this.keepAlive_||this.isBeingObserved)&&(P.trackingContext=this),this.trackAndCompute()&&ln(this),P.trackingContext=e}else !e&&this.isBeingObserved&&this.observing_.forEach(on)}let e=this.value_;if(jt(e))throw e.cause;return e}set(e){if(this.setter_){this.isRunningSetter&&n(33,this.name_),this.isRunningSetter=!0;try{this.setter_.call(this.scope_,e)}finally{this.isRunningSetter=!1}}else n(34,this.name_)}trackAndCompute(){let e=this.value_,t=this.dependenciesState_===-1,n=this.computeValue_(!0),r=t||jt(e)||jt(n)||!this.equals_(e,n);return r&&(this.value_=n,vn()&&yn({observableKind:`computed`,debugObjectName:this.name_,object:this.scope_,type:`update`,oldValue:e,newValue:n})),r}computeValue_(e){this.isComputing=!0;let t=wt(!1),n;if(e)n=It(this,this.derivation,this.scope_);else if(P.disableErrorBoundaries===!0)n=this.derivation.call(this.scope_);else try{n=this.derivation.call(this.scope_)}catch(e){n=new At(e)}return Tt(t),this.isComputing=!1,n}suspend_(){this.keepAlive_||(zt(this),this.value_=void 0)}warnAboutUntrackedRead_(){(typeof this.requiresReaction_==`boolean`?this.requiresReaction_:P.computedRequiresReaction)&&console.warn(`[mobx] Computed value '${this.name_}' is being read outside a reactive context. Doing a full recompute.`)}toString(){return`${this.name_}[${this.derivation.toString()}]`}valueOf(){return ne(this.get())}[Symbol.toPrimitive](){return this.valueOf()}};let kt=b(`ComputedValue`,Ot);var At=class{constructor(e){this.cause=void 0,this.cause=e}};function jt(e){return e instanceof At}function Mt(e){switch(e.dependenciesState_){case 0:return!1;case-1:case 2:return!0;case 1:{let t=M(!0),n=Vt(),r=e.observing_,i=r.length;for(let a=0;a<i;a++){let i=r[a];if(kt(i)){if(P.disableErrorBoundaries)i.get();else try{i.get()}catch{return Ht(n),Ut(t),!0}if(e.dependenciesState_===2)return Ht(n),Ut(t),!0}}return Wt(e),Ht(n),Ut(t),!1}}}function Nt(){return P.trackingDerivation!==null}function Pt(e){let t=!!e.observers_&&e.observers_.size>0;!P.allowStateChanges&&(t||P.enforceActions===`always`)&&console.warn(`[MobX] `+(P.enforceActions?`Since strict-mode is enabled, changing (observed) observable values without using an action is not allowed. Tried to modify: `:`Side effects like changing state are not allowed at this point. Are you trying to modify state from, for example, a computed value or the render function of a React component? You can wrap side effects in 'runInAction' (or decorate functions with 'action') if needed. Tried to modify: `)+e.name_)}function Ft(e){!P.allowStateReads&&P.observableRequiresReaction&&console.warn(`[mobx] Observable '${e.name_}' being read outside a reactive context.`)}function It(e,t,n){let r=M(!0);Wt(e),e.newObserving_=Array(e.runId_===0?100:e.observing_.length),e.unboundDepsCount_=0,e.runId_=++P.runId;let i=P.trackingDerivation;P.trackingDerivation=e,P.inBatch++;let a;if(P.disableErrorBoundaries===!0)a=t.call(n);else try{a=t.call(n)}catch(e){a=new At(e)}return P.inBatch--,P.trackingDerivation=i,Rt(e),Lt(e),Ut(r),a}function Lt(e){e.observing_.length===0&&(typeof e.requiresObservable_==`boolean`?e.requiresObservable_:P.reactionRequiresObservable)&&console.warn(`[mobx] Derivation '${e.name_}' is created/updated without reading any observable value.`)}function Rt(e){let t=e.observing_,n=e.observing_=e.newObserving_,r=0,i=0,a=e.unboundDepsCount_;for(let e=0;e<a;e++){let t=n[e];t.diffValue===0&&(t.diffValue=1,i!==e&&(n[i]=t),i++),t.dependenciesState_>r&&(r=t.dependenciesState_)}for(n.length=i,e.newObserving_=null,a=t.length;a--;){let n=t[a];n.diffValue===0&&en(n,e),n.diffValue=0}for(;i--;){let t=n[i];t.diffValue===1&&(t.diffValue=0,$t(t,e))}r!==0&&(e.dependenciesState_=r,e.onBecomeStale_())}function zt(e){let t=e.observing_;e.observing_=[];let n=t.length;for(;n--;)en(t[n],e);e.dependenciesState_=-1}function Bt(e){let t=Vt();try{return e()}finally{Ht(t)}}function Vt(){let e=P.trackingDerivation;return P.trackingDerivation=null,e}function Ht(e){P.trackingDerivation=e}function M(e){let t=P.allowStateReads;return P.allowStateReads=e,t}function Ut(e){P.allowStateReads=e}function Wt(e){if(e.dependenciesState_===0)return;e.dependenciesState_=0;let t=e.observing_,n=t.length;for(;n--;)t[n].lowestObserverState_=0}let Gt=[`mobxGuid`,`spyListeners`,`enforceActions`,`computedRequiresReaction`,`reactionRequiresObservable`,`observableRequiresReaction`,`allowStateReads`,`disableErrorBoundaries`,`runId`,`UNCHANGED`];var N=class{constructor(){this.version=7,this.UNCHANGED={},this.trackingDerivation=null,this.trackingContext=null,this.runId=0,this.mobxGuid=0,this.inBatch=0,this.pendingUnobservations=[],this.pendingReactions=[],this.isRunningReactions=!1,this.isRunningUnobservations=!1,this.allowStateChanges=!1,this.allowStateReads=!0,this.enforceActions=!0,this.spyListeners=[],this.globalReactionErrorHandlers=[],this.computedRequiresReaction=!1,this.reactionRequiresObservable=!1,this.observableRequiresReaction=!1,this.disableErrorBoundaries=!1,this.suppressReactionErrors=!1,this.safeDescriptors=!0}};let Kt=!0,qt=!1,P=function(){let e=globalThis;return e.__mobxInstanceCount>0&&!e.__mobxGlobals&&(Kt=!1),e.__mobxGlobals&&e.__mobxGlobals.version!==7&&(Kt=!1),Kt?e.__mobxGlobals?(e.__mobxInstanceCount+=1,e.__mobxGlobals.UNCHANGED||(e.__mobxGlobals.UNCHANGED={}),e.__mobxGlobals):(e.__mobxInstanceCount=1,e.__mobxGlobals=new N):(setTimeout(()=>{qt||n(35)},1),new N)}();function Jt(){if((P.pendingReactions.length||P.inBatch||P.isRunningReactions)&&n(36),qt=!0,Kt){let e=globalThis;--e.__mobxInstanceCount===0&&(e.__mobxGlobals=void 0),P=new N}}function Yt(){return P}function Xt(){let e=new N;for(let t in e)Gt.indexOf(t)===-1&&(P[t]=e[t]);P.allowStateChanges=!P.enforceActions}function Zt(e){return!!e.observers_&&e.observers_.size>0}function Qt(e){return e.observers_??new Set}function $t(e,t){(e.observers_??=new Set).add(t),e.lowestObserverState_>t.dependenciesState_&&(e.lowestObserverState_=t.dependenciesState_)}function en(e,t){let n=e.observers_;n&&(n.delete(t),n.size===0&&tn(e))}function tn(e){e.isPendingUnobservation===!1&&(e.isPendingUnobservation=!0,P.pendingUnobservations.push(e))}function nn(){P.inBatch++}function rn(){--P.inBatch===0&&(mn(),!P.isRunningUnobservations&&P.pendingUnobservations.length>0&&an())}function an(){P.isRunningUnobservations=!0;try{let e=P.pendingUnobservations;for(let t=0;t<e.length;t++){let n=e[t];n.isPendingUnobservation=!1,(!n.observers_||n.observers_.size===0)&&(n.observers_=null,n.isBeingObserved&&(n.isBeingObserved=!1,n.onBUO()),n instanceof Ot&&n.suspend_())}P.pendingUnobservations=[]}finally{P.isRunningUnobservations=!1}}function on(e){var t;e.isBeingObserved||(e.isBeingObserved=!0,e.onBO(),(t=e.observing_)==null||t.forEach(on))}function sn(e){Ft(e);let t=P.trackingDerivation;return t===null?((!e.observers_||e.observers_.size===0)&&P.inBatch>0&&tn(e),!1):(t.runId_!==e.lastAccessedBy_&&(e.lastAccessedBy_=t.runId_,t.newObserving_[t.unboundDepsCount_++]=e,!e.isBeingObserved&&P.trackingContext&&(e.isBeingObserved=!0,e.onBO())),e.isBeingObserved)}function cn(e){var t;e.lowestObserverState_!==2&&(e.lowestObserverState_=2,(t=e.observers_)==null||t.forEach(e=>{e.dependenciesState_===0&&e.onBecomeStale_(),e.dependenciesState_=2}))}function ln(e){var t;e.lowestObserverState_!==2&&(e.lowestObserverState_=2,(t=e.observers_)==null||t.forEach(t=>{t.dependenciesState_===1?t.dependenciesState_=2:t.dependenciesState_===0&&(e.lowestObserverState_=0)}))}function un(e){var t;e.lowestObserverState_===0&&(e.lowestObserverState_=1,(t=e.observers_)==null||t.forEach(e=>{e.dependenciesState_===0&&(e.dependenciesState_=1,e.onBecomeStale_())}))}var dn=class{constructor(e=`Reaction@`+u(),t,n,r){this.name_=void 0,this.onInvalidate_=void 0,this.errorHandler_=void 0,this.requiresObservable_=void 0,this.observing_=[],this.newObserving_=[],this.dependenciesState_=-1,this.runId_=0,this.unboundDepsCount_=0,this.flags_=0,this.removeAbortListener_=void 0,this.name_=e,this.onInvalidate_=t,this.errorHandler_=n,this.requiresObservable_=r}get isDisposed(){return E(this.flags_,1)}set isDisposed(e){this.flags_=D(this.flags_,1,e)}get isScheduled(){return E(this.flags_,2)}set isScheduled(e){this.flags_=D(this.flags_,2,e)}get isTrackPending(){return E(this.flags_,4)}set isTrackPending(e){this.flags_=D(this.flags_,4,e)}get isRunning(){return E(this.flags_,8)}set isRunning(e){this.flags_=D(this.flags_,8,e)}get diffValue(){return+!!E(this.flags_,16)}set diffValue(e){this.flags_=D(this.flags_,16,e===1)}onBecomeStale_(){this.schedule_()}schedule_(){this.isScheduled||(this.isScheduled=!0,P.pendingReactions.push(this),mn())}runReaction_(){if(!this.isDisposed){nn(),this.isScheduled=!1;let e=P.trackingContext;if(P.trackingContext=this,Mt(this)){this.isTrackPending=!0;try{this.onInvalidate_(),this.isTrackPending&&vn()&&yn({name:this.name_,type:`scheduled-reaction`})}catch(e){this.reportExceptionInDerivation_(e)}}P.trackingContext=e,rn()}}track(e){if(this.isDisposed)return;nn();let t=vn(),n;t&&(n=Date.now(),bn({name:this.name_,type:`reaction`})),this.isRunning=!0;let r=P.trackingContext;P.trackingContext=this;let i=It(this,e,void 0);P.trackingContext=r,this.isRunning=!1,this.isTrackPending=!1,this.isDisposed&&zt(this),jt(i)&&this.reportExceptionInDerivation_(i.cause),t&&Sn({time:Date.now()-n}),rn()}reportExceptionInDerivation_(e){if(this.errorHandler_){this.errorHandler_(e,this);return}if(P.disableErrorBoundaries)throw e;let t=`[mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: '${this}'`;P.suppressReactionErrors?console.warn(`[mobx] (error in reaction '${this.name_}' suppressed, fix error of causing action below)`):console.error(t,e),vn()&&yn({type:`error`,name:this.name_,message:t,error:``+e}),P.globalReactionErrorHandlers.forEach(t=>t(e,this))}dispose(){if(!this.isDisposed){var e;this.isDisposed=!0,(e=this.removeAbortListener_)==null||e.call(this),this.isRunning||(nn(),zt(this),rn())}}getDisposer_(e){let t=()=>this.dispose();return e!=null&&e.addEventListener&&!this.isDisposed&&(e.addEventListener(`abort`,t),this.removeAbortListener_=()=>e.removeEventListener==null?void 0:e.removeEventListener(`abort`,t)),t[O]=this,`dispose`in Symbol&&typeof Symbol.dispose==`symbol`&&(t[Symbol.dispose]=t),t}toString(){return`Reaction[${this.name_}]`}};function fn(e){return P.globalReactionErrorHandlers.push(e),()=>{let t=P.globalReactionErrorHandlers.indexOf(e);t>=0&&P.globalReactionErrorHandlers.splice(t,1)}}let pn=e=>e();function mn(){P.inBatch>0||P.isRunningReactions||pn(hn)}function hn(){P.isRunningReactions=!0;let e=P.pendingReactions,t=0;for(;e.length>0;){++t===100&&(console.error(`Reaction doesn't converge to a stable state after 100 iterations. Probably there is a cycle in the reactive function: ${e[0]}`),e.splice(0));let n=e.splice(0);for(let e=0,t=n.length;e<t;e++)n[e].runReaction_()}P.isRunningReactions=!1}let gn=b(`Reaction`,dn);function _n(e){let t=pn;pn=n=>e(()=>t(n))}function vn(){return!!P.spyListeners.length}function yn(e){if(!P.spyListeners.length)return;let t=P.spyListeners;for(let n=0,r=t.length;n<r;n++)t[n](e)}function bn(e){yn(r({},e,{spyReportStart:!0}))}let xn={type:`report-end`,spyReportEnd:!0};function Sn(e){yn(e?r({},e,{type:`report-end`,spyReportEnd:!0}):xn)}function Cn(e){return P.spyListeners.push(e),d(()=>{P.spyListeners=P.spyListeners.filter(t=>t!==e)})}let F=`action`,wn=`autoAction`,Tn=`<unnamed action>`,En=xe(F),Dn=xe(`action.bound`,{bound:!0}),On=xe(wn,{autoAction:!0}),kn=xe(`autoAction.bound`,{autoAction:!0,bound:!0});function An(e){return Je(e,we)}function jn(e){return function(t,r){if(r&&typeof r.kind==`string`)return we(e?On:En,t,r);if(p(t))return yt(t.name||Tn,t,e);if(p(r))return yt(t,r,e);if(m(t))return An(xe(e?wn:F,{name:t,autoAction:e}));n("Invalid arguments for `action`")}}let Mn=jn(!1);r(Mn,En);let Nn=jn(!0);r(Nn,On);let Pn=An(Dn),Fn=An(kn);function In(e){return bt(e.name||Tn,!1,e,this,void 0)}function Ln(e){return p(e)&&e.isMobxAction===!0}function Rn(e,t=c){var r;p(e)||n(`Autorun expects a function as first argument`),Ln(e)&&n(`Autorun does not accept actions since actions are untrackable`);let i=t?.name??(e.name||`Autorun@`+u()),a=!t.scheduler&&!t.delay,o;if(a)o=new dn(i,function(){this.track(s)},t.onError,t.requiresObservable);else{let e=Bn(t),n=!1;o=new dn(i,()=>{n||(n=!0,e(()=>{n=!1,o.isDisposed||o.track(s)}))},t.onError,t.requiresObservable)}function s(){e(o)}return t!=null&&(r=t.signal)!=null&&r.aborted||o.schedule_(),o.getDisposer_(t?.signal)}let zn=e=>e();function Bn(e){return e.scheduler?e.scheduler:e.delay?t=>setTimeout(t,e.delay):zn}function Vn(e,t,r=c){var i;(!p(e)||!p(t))&&n(`First and second argument to reaction should be functions`),g(r)||n(`Third argument of reactions should be an object`);let a=r.name??`Reaction@`+u(),o=Mn(a,r.onError?Hn(r.onError,t):t),s=!r.scheduler&&!r.delay,l=Bn(r),d=!0,f=!1,m,h=r.equals||de,_=new dn(a,()=>{d||s?v():f||(f=!0,l(v))},r.onError,r.requiresObservable);function v(){if(f=!1,_.isDisposed)return;let t=!1,n=m;_.track(()=>{let n=Ct(!1,()=>e(_));t=d||!h(m,n),m=n}),(d&&r.fireImmediately||!d&&t)&&o(m,n,_),d=!1}return r!=null&&(i=r.signal)!=null&&i.aborted||_.schedule_(),_.getDisposer_(r?.signal)}function Hn(e,t){return function(){try{return t.apply(this,arguments)}catch(t){e.call(this,t)}}}function Un(e,t,n){return Gn(`onBO`,e,t,n)}function Wn(e,t,n){return Gn(`onBUO`,e,t,n)}function Gn(e,t,n,r){let i=typeof r==`function`?R(t,n):R(t),a=p(r)?r:n,o=`${e}L`;return i[o]?i[o].add(a):i[o]=new Set([a]),function(){let e=i[o];e&&(e.delete(a),e.size===0&&delete i[o])}}let Kn=`always`;function qn(e){e.isolateGlobalState===!0&&Jt();let{enforceActions:t}=e;if(t!==void 0){let e=t===Kn?Kn:t===`observed`;P.enforceActions=e,P.allowStateChanges=!(e===!0||e===Kn)}[`computedRequiresReaction`,`reactionRequiresObservable`,`observableRequiresReaction`,`disableErrorBoundaries`,`safeDescriptors`].forEach(t=>{t in e&&(P[t]=!!e[t])}),P.allowStateReads=!P.observableRequiresReaction,P.disableErrorBoundaries===!0&&console.warn("WARNING: Debug feature only. MobX will NOT recover from errors when `disableErrorBoundaries` is enabled."),e.reactionScheduler&&_n(e.reactionScheduler)}function Jn(e,t,r,i){arguments.length>4&&n(`'extendObservable' expected 2-4 arguments`),typeof e!=`object`&&n(`'extendObservable' expects an object as first argument`),mi(e)&&n(`'extendObservable' should not be used on maps, use map.merge instead`),g(t)||n(`'extendObservable' only accepts plain objects as second argument`),(vr(t)||vr(r))&&n(`Extending an object with another observable (object) is not supported`);let a=re(t);return Ai(()=>{let t=wi(e,i)[O];ee(a).forEach(e=>{t.extend_(e,a[e],r&&e in r?r[e]:!0)})}),e}function Yn(e,t){return Xn(R(e,t))}function Xn(e){let t={name:e.name_};return e.observing_&&e.observing_.length>0&&(t.dependencies=$n(e.observing_).map(Xn)),t}function Zn(e,t){return Qn(R(e,t))}function Qn(e){let t={name:e.name_};return Zt(e)&&(t.observers=Array.from(Qt(e),Qn)),t}function $n(e){return Array.from(new Set(e))}let er=0;var tr=class extends Error{constructor(){super(`FLOW_CANCELLED`),Object.setPrototypeOf(this,new.target.prototype),this.name=`FlowCancellationError`}toString(){return`Error: ${this.message}`}};function nr(e){return e instanceof tr}function rr(e){return Je(e,ke)}let ir=k(`flow`),I=k(`flow.bound`,{bound:!0}),ar=r(function(e,t){if(t&&typeof t.kind==`string`)return ke(ir,e,t);arguments.length!==1&&n(`Flow expects single argument with generator function`);let r=e,i=r.name||`<unnamed flow>`,a=function(){let e=this,t=arguments,n=++er,a=Mn(`${i} - runid: ${n} - init`,r).apply(e,t),o,s,c=new Promise(function(e,t){let r=0;o=t;function c(e){s=void 0;let o;try{o=Mn(`${i} - runid: ${n} - yield ${r++}`,a.next).call(a,e)}catch(e){return t(e)}u(o)}function l(e){s=void 0;let o;try{o=Mn(`${i} - runid: ${n} - yield ${r++}`,a.throw).call(a,e)}catch(e){return t(e)}u(o)}function u(n){if(p(n?.then)){n.then(u,t);return}return n.done?e(n.value):(s=Promise.resolve(n.value),s.then(c,l))}c(void 0)});return c.cancel=Mn(`${i} - runid: ${n} - cancel`,function(){try{s&&sr(s);let e=a.return(void 0),t=Promise.resolve(e.value);t.then(f,f),sr(t),o(new tr)}catch(e){o(e)}}),c};return a.isMobXFlow=!0,a},ir),or=rr(I);function sr(e){p(e.cancel)&&e.cancel()}function cr(e){return e}function lr(e){return e?.isMobXFlow===!0}function ur(e,t,r){let i;if(mi(e)||ui(e)||Dt(e))i=z(e);else if(Di(e)){if(!m(t))return n(`InterceptReads can only be used with a specific property, not with an object in general`);i=z(e,t)}else return n(`Expected observable map, object or array as first array`);return i.dehancer===void 0?(i.dehancer=typeof t==`function`?t:r,()=>{i.dehancer=void 0}):n(`An intercept reader was already established`)}function dr(e,t,n){return p(n)?pr(e,t,n):fr(e,t)}function fr(e,t){return Wr(z(e),t)}function pr(e,t,n){return Wr(z(e,t),n)}function mr(e,t){var n;if(t===void 0)return kt(e);if(Di(e)===!1)return!1;let r=e[O];return(n=r.lazyComputedKeys_)!=null&&n.has(t)?!0:r.values_.has(t)?kt(R(e,t)):!1}function hr(e){return arguments.length>1?n(`isComputed expects only 1 argument. Use isComputedProp to inspect the observability of a property`):mr(e)}function gr(e,t){return m(t)?mr(e,t):n(`isComputed expected a property name as second argument`)}function _r(e,t){if(!e)return!1;if(t!==void 0){if(mi(e)||ui(e))return n(`isObservable(object, propertyName) is not supported for arrays and maps. Use map.has or array.length instead.`);if(Di(e)){var r,i;let n=e[O];return n.values_.has(t)||!!((r=n.lazyComputedKeys_)!=null&&r.has(t))||!!((i=n.lazyObservableKeys_)!=null&&i.has(t))}return!1}return Di(e)||!!e[O]||oe(e)||gn(e)||kt(e)}function vr(e){return arguments.length!==1&&n(`isObservable expects only 1 argument. Use isObservableProp to inspect the observability of a property`),_r(e)}function yr(e,t){return m(t)?_r(e,t):n(`expected a property name as second argument`)}function br(e){if(Di(e))return e[O].keys_();if(mi(e)||yi(e))return Array.from(e.keys());if(ui(e))return e.map((e,t)=>t);n(5)}function xr(e){if(Di(e))return br(e).map(t=>e[t]);if(mi(e))return br(e).map(t=>e.get(t));if(yi(e))return Array.from(e.values());if(ui(e))return e.slice();n(6)}function Sr(e){if(Di(e))return br(e).map(t=>[t,e[t]]);if(mi(e))return br(e).map(t=>[t,e.get(t)]);if(yi(e))return Array.from(e.entries());if(ui(e))return e.map((e,t)=>[t,e]);n(7)}function Cr(e,t,r){if(arguments.length===2&&!yi(e)){nn();let n=t;try{for(let t in n)Cr(e,t,n[t])}finally{rn()}return}Di(e)?e[O].set_(t,r):mi(e)?e.set(t,r):yi(e)?e.add(t):ui(e)?(typeof t!=`number`&&(t=parseInt(t,10)),t<0&&n(42,t),nn(),t>=e.length&&(e.length=t+1),e[t]=r,rn()):n(8)}function wr(e,t){Di(e)?e[O].delete_(t):mi(e)||yi(e)?e.delete(t):ui(e)?(typeof t!=`number`&&(t=parseInt(t,10)),e.splice(t,1)):n(9)}function Tr(e,t){if(Di(e))return e[O].has_(t);if(mi(e)||yi(e))return e.has(t);if(ui(e))return t>=0&&t<e.length;n(10)}function Er(e,t){if(Tr(e,t)){if(Di(e))return e[O].get_(t);if(mi(e))return e.get(t);if(ui(e))return e[t];n(11)}}function Dr(e,t,r){if(Di(e))return e[O].defineProperty_(t,r);n(39)}function Or(e){if(Di(e))return e[O].ownKeys_();n(38)}function kr(e,t,n,r){return p(n)?jr(e,t,n,r):Ar(e,t,n)}function Ar(e,t,r){let i=z(e);if(ui(e))r&&t({observableKind:`array`,object:i.proxy_,debugObjectName:i.atom_.name_,type:`splice`,index:0,added:i.values_.slice(),addedCount:i.values_.length,removed:[],removedCount:0});else if(mi(e))r===!0&&n("`observe` doesn't support fireImmediately=true in combination with maps.");else if(yi(e))r===!0&&n("`observe` doesn't support fireImmediately=true in combination with sets.");else if(Di(e))r===!0&&n("`observe` doesn't support the fire immediately property for observable objects.");else return Mr(i,t,r);return qr(i,t)}function jr(e,t,n,r){return Mr(z(e,t),n,r)}function Mr(e,t,n){if(kt(e)){let r=!0,i;return Rn(()=>{let a=e.get();if(!r||n){let n=Vt();t({observableKind:`computed`,debugObjectName:e.name_,type:ei,object:e,newValue:a,oldValue:i}),Ht(n)}r=!1,i=a})}return n&&t({observableKind:`value`,debugObjectName:e.name_,object:e,type:ei,newValue:e.value_,oldValue:void 0}),qr(e,t)}function Nr(e,t,n){return e.set(t,n),n}function Pr(e,t){if(typeof e!=`object`||!e||e instanceof Date||!vr(e))return e;if(Dt(e)||kt(e))return Pr(e.get(),t);if(t.has(e))return t.get(e);if(ui(e)){let n=Nr(t,e,Array(e.length));return e.forEach((e,r)=>{n[r]=Pr(e,t)}),n}if(yi(e)){let n=Nr(t,e,new Set);return e.forEach(e=>{n.add(Pr(e,t))}),n}if(mi(e)){let n=Nr(t,e,new Map);return e.forEach((e,r)=>{n.set(r,Pr(e,t))}),n}else{let n=Nr(t,e,{});return Or(e).forEach(r=>{o.propertyIsEnumerable.call(e,r)&&(n[r]=Pr(e[r],t))}),n}}function Fr(e,t){return t&&n(`toJS no longer supports options`),Pr(e,new Map)}function Ir(e,t=void 0){nn();try{return e.apply(t)}finally{rn()}}function Lr(e,t,n){return arguments.length===1||t&&typeof t==`object`?zr(e,t):Rr(e,t,n||{})}function Rr(e,t,n){let r;if(typeof n.timeout==`number`){let e=Error(`WHEN_TIMEOUT`);r=setTimeout(()=>{if(!a[O].isDisposed)if(a(),n.onError)n.onError(e);else throw e},n.timeout)}n.name=n.name||`When@`+u();let i=yt(n.name+`-effect`,t);var a=Rn(t=>{Ct(!1,e)&&(t.dispose(),r&&clearTimeout(r),i())},n);return a}function zr(e,t){var i;if(t&&t.onError)return n(`the options 'onError' and 'promise' cannot be combined`);if(t!=null&&(i=t.signal)!=null&&i.aborted)return r(Promise.reject(Error(`WHEN_ABORTED`)),{cancel:()=>null});let a,o,s=new Promise((n,i)=>{var s;let c=Rr(e,n,r({},t,{onError:i}));a=()=>{c(),i(Error(`WHEN_CANCELLED`))},o=()=>{c(),i(Error(`WHEN_ABORTED`))},t==null||(s=t.signal)==null||s.addEventListener==null||s.addEventListener(`abort`,o)}).finally(()=>{var e;return t==null||(e=t.signal)==null||e.removeEventListener==null?void 0:e.removeEventListener(`abort`,o)});return s.cancel=a,s}function Br(e){return e[O]}let Vr={has(e,t){return Br(e).has_(t)},get(e,t){return Br(e).get_(t)},set(e,t,n){return m(t)?Br(e).set_(t,n,!0)??!0:!1},deleteProperty(e,t){return m(t)?Br(e).delete_(t,!0)??!0:!1},defineProperty(e,t,n){return Br(e).defineProperty_(t,n)??!0},ownKeys(e){return Br(e).ownKeys_()},preventExtensions(e){n(13)}};function Hr(e,t){var n;return e=wi(e,t),(n=e[O]).proxy_??(n.proxy_=new Proxy(e,Vr))}function Ur(e){return e.interceptors_!==void 0&&e.interceptors_.length>0}function Wr(e,t){let n=e.interceptors_;return n?n.push(t):n=e.interceptors_=[t],d(()=>{let e=n.indexOf(t);e!==-1&&n.splice(e,1)})}function Gr(e,t){let r=Vt();try{let r=[...e.interceptors_||[]];for(let e=0,i=r.length;e<i&&(t=r[e](t),t&&!t.type&&n(14),t);e++);return t}finally{Ht(r)}}function Kr(e){return e.changeListeners_!==void 0&&e.changeListeners_.length>0}function qr(e,t){let n=e.changeListeners_;return n?n.push(t):n=e.changeListeners_=[t],d(()=>{let e=n.indexOf(t);e!==-1&&n.splice(e,1)})}function Jr(e,t){let n=Vt(),r=e.changeListeners_;if(r){r=r.slice();for(let e=0,n=r.length;e<n;e++)r[e](t);Ht(n)}}function Yr(e,t,n){return Ai(()=>{let r=wi(e,n)[O];ee(t).forEach(e=>Qr(r,e,t[e]))}),e}let Xr=Symbol(`mobx-keys`);function Zr(e,t,r){return!g(e)&&!g(Object.getPrototypeOf(e))&&n(`'makeAutoObservable' can only be used for classes that don't have a superclass`),Di(e)&&n(`makeAutoObservable can only be used on objects not already made observable`),g(e)?Jn(e,e,t,r):(Ai(()=>{let n=wi(e,r)[O];if(!e[Xr]){let t=Object.getPrototypeOf(e),n=new Set([...ee(e),...ee(t)]);n.delete(`constructor`),n.delete(O),v(t,Xr,n)}e[Xr].forEach(e=>Qr(n,e,t&&e in t?t[e]:!0))}),e)}function Qr(e,t,r){if(r===!0&&(r=e.defaultAnnotation_),r===!1)return;L(e,r,t),t in e.target_||n(1,r.annotationType_,`${e.name_}.${t.toString()}`);let a=e.target_;for(;a&&a!==o;){let n=i(a,t);if(n){let i=r.make_(e,t,n,a);if(i===0)return;if(i===1)break}a=Object.getPrototypeOf(a)}Oi(e,r,t)}let $r=`splice`,ei=`update`,ti={get(e,t){let n=e[O];return t===O?n:t===`length`?n.getArrayLength_():typeof t==`string`&&!isNaN(t)?n.get_(parseInt(t)):T(ii,t)?ii[t]:e[t]},set(e,t,n){let r=e[O];return t===`length`?r.setArrayLength_(n):typeof t==`symbol`||isNaN(t)?e[t]=n:r.set_(parseInt(t),n),!0},preventExtensions(){n(15)}};var ni=class{constructor(e=`ObservableArray@`+u(),t,n){this.owned_=void 0,this.atom_=void 0,this.values_=[],this.interceptors_=void 0,this.changeListeners_=void 0,this.enhancer_=void 0,this.dehancer=void 0,this.proxy_=void 0,this.lastKnownLength_=0,this.owned_=n,this.atom_=new ae(e),this.enhancer_=(n,r)=>t(n,r,e+`[..]`)}dehanceValue_(e){return this.dehancer===void 0?e:this.dehancer(e)}dehanceValues_(e){return this.dehancer!==void 0&&e.length>0?e.map(this.dehancer):e}getArrayLength_(){return this.atom_.reportObserved(),this.values_.length}setArrayLength_(e){(!Number.isInteger(e)||e<0)&&n(40,e);let t=this.values_.length;if(e!==t)if(e>t){let n=Array.from({length:e-t});this.spliceWithArray_(t,0,n)}else this.spliceWithArray_(e,t-e)}updateArrayLength_(e,t){e!==this.lastKnownLength_&&n(16),this.lastKnownLength_+=t}spliceWithArray_(e,t,n){Pt(this.atom_);let r=this.values_.length;if(e===void 0?e=0:e>r?e=r:e<0&&(e=Math.max(0,r+e)),t=arguments.length===1?r-e:t==null?0:Math.max(0,Math.min(t,r-e)),n===void 0&&(n=s),Ur(this)){let r=Gr(this,{object:this.proxy_,type:$r,index:e,removedCount:t,added:n});if(!r)return s;t=r.removedCount,n=r.added}n=n.length===0?n:n.map(e=>this.enhancer_(e,void 0));{let e=n.length-t;this.updateArrayLength_(r,e)}let i=this.spliceItemsIntoValues_(e,t,n);return(t!==0||n.length!==0)&&this.notifyArraySplice_(e,n,i),this.dehanceValues_(i)}spliceItemsIntoValues_(e,t,n){if(n.length<1e4)return this.values_.splice(e,t,...n);{let r=this.values_.slice(e,e+t),i=this.values_.slice(e+t);this.values_.length+=n.length-t;for(let t=0;t<n.length;t++)this.values_[e+t]=n[t];for(let t=0;t<i.length;t++)this.values_[e+n.length+t]=i[t];return r}}notifyArrayChildUpdate_(e,t,n){let r=!this.owned_&&vn(),i=Kr(this),a=i||r?{observableKind:`array`,object:this.proxy_,type:ei,debugObjectName:this.atom_.name_,index:e,newValue:t,oldValue:n}:null;r&&bn(a),this.atom_.reportChanged(),i&&Jr(this,a),r&&Sn()}notifyArraySplice_(e,t,n){let r=!this.owned_&&vn(),i=Kr(this),a=i||r?{observableKind:`array`,object:this.proxy_,debugObjectName:this.atom_.name_,type:$r,index:e,removed:n,added:t,removedCount:n.length,addedCount:t.length}:null;r&&bn(a),this.atom_.reportChanged(),i&&Jr(this,a),r&&Sn()}get_(e){return this.atom_.reportObserved(),this.dehanceValue_(this.values_[e])}set_(e,t){let n=this.values_;if(e<n.length){Pt(this.atom_);let r=n[e];if(Ur(this)){let n=Gr(this,{type:ei,object:this.proxy_,index:e,newValue:t});if(!n)return;t=n.newValue}t=this.enhancer_(t,r),t!==r&&(n[e]=t,this.notifyArrayChildUpdate_(e,t,r))}else{let r=Array.from({length:e+1-n.length});r[r.length-1]=t,this.spliceWithArray_(n.length,0,r)}}};function ri(e,t,n=`ObservableArray@`+u(),r=!1){return Ai(()=>{let i=new ni(n,t,r);y(i.values_,O,i);let a=new Proxy(i.values_,ti);return i.proxy_=a,e&&e.length&&i.spliceWithArray_(0,0,e),a})}var ii={clear(){return this.splice(0)},replace(e){let t=this[O];return t.spliceWithArray_(0,t.values_.length,e)},toJSON(){return this.slice()},splice(e,t,...n){let r=this[O];switch(arguments.length){case 0:return[];case 1:return r.spliceWithArray_(e);case 2:return r.spliceWithArray_(e,t)}return r.spliceWithArray_(e,t,n)},spliceWithArray(e,t,n){return this[O].spliceWithArray_(e,t,n)},push(...e){let t=this[O];return t.spliceWithArray_(t.values_.length,0,e),t.values_.length},pop(){return this.splice(Math.max(this[O].values_.length-1,0),1)[0]},shift(){return this.splice(0,1)[0]},unshift(...e){let t=this[O];return t.spliceWithArray_(0,0,e),t.values_.length},reverse(){return P.trackingDerivation&&n(37,`reverse`),this.replace(this.slice().reverse()),this},sort(){P.trackingDerivation&&n(37,`sort`);let e=this.slice();return e.sort.apply(e,arguments),this.replace(e),this},remove(e){let t=this[O],n=t.dehanceValues_(t.values_).indexOf(e);return n>-1?(this.splice(n,1),!0):!1}};ai(`at`,oi),ai(`concat`,oi),ai(`flat`,oi),ai(`includes`,oi),ai(`indexOf`,oi),ai(`join`,oi),ai(`lastIndexOf`,oi),ai(`slice`,oi),ai(`toString`,oi),ai(`toLocaleString`,oi),ai(`toSorted`,oi),ai(`toSpliced`,oi),ai(`with`,oi),ai(`every`,si),ai(`filter`,si),ai(`find`,si),ai(`findIndex`,si),ai(`findLast`,si),ai(`findLastIndex`,si),ai(`flatMap`,si),ai(`forEach`,si),ai(`map`,si),ai(`some`,si),ai(`toReversed`,si),ai(`reduce`,ci),ai(`reduceRight`,ci);function ai(e,t){typeof Array.prototype[e]==`function`&&(ii[e]=t(e))}function oi(e){return function(){let t=this[O];t.atom_.reportObserved();let n=t.dehanceValues_(t.values_);return n[e].apply(n,arguments)}}function si(e){return function(t,n){let r=this[O];return r.atom_.reportObserved(),r.dehanceValues_(r.values_)[e]((e,r)=>t.call(n,e,r,this))}}function ci(e){return function(){let t=this[O];t.atom_.reportObserved();let n=t.dehanceValues_(t.values_),r=arguments[0];return arguments[0]=(e,t,n)=>r(e,t,n,this),n[e].apply(n,arguments)}}let li=b(`ObservableArrayAdministration`,ni);function ui(e){return h(e)&&li(e[O])}let di={},fi=`delete`;var pi=class{constructor(e,t=fe,n=`ObservableMap@`+u()){this.enhancer_=void 0,this.name_=void 0,this[O]=di,this.data_=void 0,this.hasMap_=void 0,this.keysAtom_=void 0,this.interceptors_=void 0,this.changeListeners_=void 0,this.dehancer=void 0,this.enhancer_=t,this.name_=n,Ai(()=>{this.keysAtom_=se(`${this.name_}.keys()`),this.data_=new Map,this.hasMap_=new Map,e&&this.merge(e)})}has_(e){return this.data_.has(e)}has(e){if(!P.trackingDerivation)return this.has_(e);let t=this.hasMap_.get(e);if(!t){let n=t=new Et(this.has_(e),me,`${this.name_}.${te(e)}?`,!1);this.hasMap_.set(e,n),n.onBUOL=new Set([()=>this.hasMap_.delete(e)])}return t.get()}set(e,t){let n=this.has_(e);if(Ur(this)){let r=Gr(this,{type:n?ei:`add`,object:this,newValue:t,name:e});if(!r)return this;t=r.newValue}return n?this.updateValue_(e,t):this.addValue_(e,t),this}delete(e){if(Pt(this.keysAtom_),Ur(this)&&!Gr(this,{type:fi,object:this,name:e}))return!1;if(this.has_(e)){let t=vn(),n=Kr(this),r=n||t?{observableKind:`map`,debugObjectName:this.name_,type:fi,object:this,oldValue:this.data_.get(e).value_,name:e}:null;return t&&bn(r),Ir(()=>{var t;this.keysAtom_.reportChanged(),(t=this.hasMap_.get(e))==null||t.setNewValue_(!1),this.data_.get(e).setNewValue_(void 0),this.data_.delete(e)}),n&&Jr(this,r),t&&Sn(),!0}return!1}updateValue_(e,t){let n=this.data_.get(e);if(t=n.prepareNewValue_(t),t!==P.UNCHANGED){let r=vn(),i=Kr(this),a=i||r?{observableKind:`map`,debugObjectName:this.name_,type:ei,object:this,oldValue:n.value_,name:e,newValue:t}:null;r&&bn(a),n.setNewValue_(t),i&&Jr(this,a),r&&Sn()}}addValue_(e,t){Pt(this.keysAtom_),Ir(()=>{var n;let r=new Et(t,this.enhancer_,`${this.name_}.${te(e)}`,!1);this.data_.set(e,r),t=r.value_,(n=this.hasMap_.get(e))==null||n.setNewValue_(!0),this.keysAtom_.reportChanged()});let n=vn(),r=Kr(this),i=r||n?{observableKind:`map`,debugObjectName:this.name_,type:`add`,object:this,name:e,newValue:t}:null;n&&bn(i),r&&Jr(this,i),n&&Sn()}get(e){return this.has(e)?this.dehanceValue_(this.data_.get(e).get()):this.dehanceValue_(void 0)}getOrInsert(e,t){return this.has(e)||this.set(e,t),this.get(e)}getOrInsertComputed(e,t){return this.has(e)||this.set(e,t(e)),this.get(e)}dehanceValue_(e){return this.dehancer===void 0?e:this.dehancer(e)}keys(){return this.keysAtom_.reportObserved(),this.data_.keys()}values(){let e=this,t=this.keys();return hi({next(){let{done:n,value:r}=t.next();return{done:n,value:n?void 0:e.get(r)}}})}entries(){let e=this,t=this.keys();return hi({next(){let{done:n,value:r}=t.next();return{done:n,value:n?void 0:[r,e.get(r)]}}})}[Symbol.iterator](){return this.entries()}forEach(e,t){for(let[n,r]of this)e.call(t,r,n,this)}merge(e){return mi(e)&&(e=new Map(e)),Ir(()=>{g(e)?w(e).forEach(t=>this.set(t,e[t])):Array.isArray(e)?e.forEach(([e,t])=>this.set(e,t)):x(e)?(S(e)||n(19,e),e.forEach((e,t)=>this.set(t,e))):e!=null&&n(20,e)}),this}clear(){Ir(()=>{Bt(()=>{for(let e of this.keys())this.delete(e)})})}replace(e){return Ir(()=>{let t=gi(e),n=new Map,r=!1;for(let e of this.data_.keys())if(!t.has(e))if(this.delete(e))r=!0;else{let t=this.data_.get(e);n.set(e,t)}for(let[e,i]of t.entries()){let t=this.data_.has(e);if(this.set(e,i),this.data_.has(e)){let i=this.data_.get(e);n.set(e,i),t||(r=!0)}}if(!r)if(this.data_.size!==n.size)this.keysAtom_.reportChanged();else{let e=this.data_.keys(),t=n.keys(),r=e.next(),i=t.next();for(;!r.done;){if(r.value!==i.value){this.keysAtom_.reportChanged();break}r=e.next(),i=t.next()}}this.data_=n}),this}get size(){return this.keysAtom_.reportObserved(),this.data_.size}toString(){return`[object ObservableMap]`}toJSON(){return Array.from(this)}get[Symbol.toStringTag](){return`Map`}},mi=b(`ObservableMap`,pi);function hi(e){return e[Symbol.toStringTag]=`MapIterator`,Ii(e)}function gi(e){if(x(e)||mi(e))return e;if(Array.isArray(e))return new Map(e);if(g(e)){let t=new Map;for(let n in e)t.set(n,e[n]);return t}else return n(21,e)}let _i={};var vi=class{constructor(e,t=fe,n=`ObservableSet@`+u()){this.name_=void 0,this[O]=_i,this.data_=new Set,this.atom_=void 0,this.changeListeners_=void 0,this.interceptors_=void 0,this.dehancer=void 0,this.enhancer_=void 0,this.name_=n,this.enhancer_=(e,r)=>t(e,r,n),Ai(()=>{this.atom_=se(this.name_),e&&this.replace(e)})}dehanceValue_(e){return this.dehancer===void 0?e:this.dehancer(e)}clear(){Ir(()=>{Bt(()=>{for(let e of this.data_.values())this.delete(e)})})}forEach(e,t){for(let n of this)e.call(t,n,n,this)}get size(){return this.atom_.reportObserved(),this.data_.size}add(e){if(Pt(this.atom_),Ur(this)){let t=Gr(this,{type:`add`,object:this,newValue:e});if(!t)return this;e=t.newValue}if(!this.has(e)){Ir(()=>{e=this.enhancer_(e,void 0),this.data_.add(e),this.atom_.reportChanged()});let t=vn(),n=Kr(this),r=n||t?{observableKind:`set`,debugObjectName:this.name_,type:`add`,object:this,newValue:e}:null;t&&bn(r),n&&Jr(this,r),t&&Sn()}return this}delete(e){if(Ur(this)&&!Gr(this,{type:fi,object:this,oldValue:e}))return!1;if(this.has(e)){let t=vn(),n=Kr(this),r=n||t?{observableKind:`set`,debugObjectName:this.name_,type:fi,object:this,oldValue:e}:null;return t&&bn(r),Ir(()=>{this.atom_.reportChanged(),this.data_.delete(e)}),n&&Jr(this,r),t&&Sn(),!0}return!1}has(e){return this.atom_.reportObserved(),this.data_.has(this.dehanceValue_(e))}entries(){let e=this.values();return bi({next(){let{value:t,done:n}=e.next();return n?{value:void 0,done:n}:{value:[t,t],done:n}}})}keys(){return this.values()}values(){this.atom_.reportObserved();let e=this,t=this.data_.values();return bi({next(){let{value:n,done:r}=t.next();return r?{value:void 0,done:r}:{value:e.dehanceValue_(n),done:r}}})}intersection(e){return new Set(this).intersection(e)}union(e){return new Set(this).union(e)}difference(e){return new Set(this).difference(e)}symmetricDifference(e){return new Set(this).symmetricDifference(e)}isSubsetOf(e){return new Set(this).isSubsetOf(e)}isSupersetOf(e){return new Set(this).isSupersetOf(e)}isDisjointFrom(e){return new Set(this).isDisjointFrom(e)}replace(e){return yi(e)&&(e=new Set(e)),Array.isArray(e)||C(e)?Ir(()=>{let t=C(e)?e:new Set(e);if(t.size===0){this.clear();return}if(this.data_.size===0){t.forEach(e=>this.add(e));return}for(let e of this.data_.values())t.has(this.dehanceValue_(e))||this.delete(e);t.forEach(e=>this.add(e))}):e!=null&&n(41,e),this}toJSON(){return Array.from(this)}toString(){return`[object ObservableSet]`}[Symbol.iterator](){return this.values()}get[Symbol.toStringTag](){return`Set`}},yi=b(`ObservableSet`,vi);function bi(e){return e[Symbol.toStringTag]=`SetIterator`,Ii(e)}let xi=Object.create(null),Si=`remove`;var Ci=class{constructor(e,t=new Map,r,i=He){this.target_=void 0,this.values_=void 0,this.name_=void 0,this.defaultAnnotation_=void 0,this.keysAtom_=void 0,this.changeListeners_=void 0,this.interceptors_=void 0,this.proxy_=void 0,this.isPlainObject_=void 0,this.appliedAnnotations_=void 0,this.pendingKeys_=void 0,this.lazyComputedKeys_=void 0,this.lazyObservableKeys_=void 0,this.target_=e,this.values_=t,this.name_=r,this.defaultAnnotation_=i,this.keysAtom_=new ae(`${this.name_}.keys`),this.isPlainObject_=g(this.target_),Ri(this.defaultAnnotation_)||n(`defaultAnnotation must be valid annotation`),this.appliedAnnotations_={}}getObservablePropValue_(e){return(this.values_.get(e)??this.materializeLazyComputed_(e)??this.materializeLazyObservable_(e)).get()}materializeLazyComputed_(e){let t=this.lazyComputedKeys_?.get(e);if(!t)return;this.lazyComputedKeys_.delete(e),this.lazyComputedKeys_.size===0&&(this.lazyComputedKeys_=void 0);let n=t();return this.values_.set(e,n),n}materializeLazyObservable_(e){let t=this.lazyObservableKeys_?.get(e);if(!t)return;this.lazyObservableKeys_.delete(e),this.lazyObservableKeys_.size===0&&(this.lazyObservableKeys_=void 0);let n=t();return this.values_.set(e,n),n}setObservablePropValue_(e,t){let n=this.values_.get(e)??this.materializeLazyComputed_(e)??this.materializeLazyObservable_(e);if(n instanceof Ot)return n.set(t),!0;if(Ur(this)){let n=Gr(this,{type:ei,object:this.proxy_||this.target_,name:e,newValue:t});if(!n)return null;t=n.newValue}if(t=n.prepareNewValue_(t),t!==P.UNCHANGED){let r=Kr(this),i=vn(),a=r||i?{type:ei,observableKind:`object`,debugObjectName:this.name_,object:this.proxy_||this.target_,oldValue:n.value_,name:e,newValue:t}:null;i&&bn(a),n.setNewValue_(t),r&&Jr(this,a),i&&Sn()}return!0}get_(e){return P.trackingDerivation&&!T(this.target_,e)&&this.has_(e),this.target_[e]}set_(e,t,n=!1){return T(this.target_,e)?this.values_.has(e)?this.setObservablePropValue_(e,t):n?Reflect.set(this.target_,e,t):(this.target_[e]=t,!0):this.extend_(e,{value:t,enumerable:!0,writable:!0,configurable:!0},this.defaultAnnotation_,n)}has_(e){if(!P.trackingDerivation)return e in this.target_;this.pendingKeys_||=new Map;let t=this.pendingKeys_.get(e);return t||(t=new Et(e in this.target_,me,`${this.name_}.${te(e)}?`,!1),this.pendingKeys_.set(e,t)),t.get()}extend_(e,t,n,r=!1){if(n===!0&&(n=this.defaultAnnotation_),n===!1)return this.defineProperty_(e,t,r);L(this,n,e);let i=n.extend_(this,e,t,r);return i&&Oi(this,n,e),i}defineProperty_(e,t,n=!1){Pt(this.keysAtom_);try{nn();let i=this.delete_(e);if(!i)return i;if(Ur(this)){let n=Gr(this,{object:this.proxy_||this.target_,name:e,type:`add`,newValue:t.value});if(!n)return null;let{newValue:i}=n;t.value!==i&&(t=r({},t,{value:i}))}if(n){if(!Reflect.defineProperty(this.target_,e,t))return!1}else a(this.target_,e,t);this.notifyPropertyAddition_(e,t.value)}finally{rn()}return!0}defineObservableProperty_(e,t,n,r=!1){Pt(this.keysAtom_);try{nn();let i=this.delete_(e);if(!i)return i;if(Ur(this)){let n=Gr(this,{object:this.proxy_||this.target_,name:e,type:`add`,newValue:t});if(!n)return null;t=n.newValue}let o=Ei(e),s={configurable:P.safeDescriptors?this.isPlainObject_:!0,enumerable:!0,get:o.get,set:o.set};if(r){if(!Reflect.defineProperty(this.target_,e,s))return!1}else a(this.target_,e,s);let c=new Et(t,n,`${this.name_}.${e.toString()}`,!1);this.values_.set(e,c),this.notifyPropertyAddition_(e,c.value_)}finally{rn()}return!0}defineComputedProperty_(e,t,n=!1){Pt(this.keysAtom_);try{nn();let r=this.delete_(e);if(!r)return r;if(Ur(this)&&!Gr(this,{object:this.proxy_||this.target_,name:e,type:`add`,newValue:void 0}))return null;t.name||=`${this.name_}.${e.toString()}`,t.context=this.proxy_||this.target_;let i=Ei(e),o={configurable:P.safeDescriptors?this.isPlainObject_:!0,enumerable:!1,get:i.get,set:i.set};if(n){if(!Reflect.defineProperty(this.target_,e,o))return!1}else a(this.target_,e,o);this.values_.set(e,new Ot(t)),this.notifyPropertyAddition_(e,void 0)}finally{rn()}return!0}delete_(e,t=!1){if(Pt(this.keysAtom_),!T(this.target_,e))return!0;if(Ur(this)&&!Gr(this,{object:this.proxy_||this.target_,name:e,type:Si}))return null;try{var n;nn();let r=Kr(this),a=vn(),o=this.values_.get(e),s;if(!o&&(r||a)&&(s=i(this.target_,e)?.value),t){if(!Reflect.deleteProperty(this.target_,e))return!1}else delete this.target_[e];if(delete this.appliedAnnotations_[e],o&&(this.values_.delete(e),o instanceof Et&&(s=o.value_),cn(o)),this.keysAtom_.reportChanged(),(n=this.pendingKeys_)==null||(n=n.get(e))==null||n.set(e in this.target_),r||a){let t={type:Si,observableKind:`object`,object:this.proxy_||this.target_,debugObjectName:this.name_,oldValue:s,name:e};a&&bn(t),r&&Jr(this,t),a&&Sn()}}finally{rn()}return!0}notifyPropertyAddition_(e,t){var n;let r=Kr(this),i=vn();if(r||i){let n=r||i?{type:`add`,observableKind:`object`,debugObjectName:this.name_,object:this.proxy_||this.target_,name:e,newValue:t}:null;i&&bn(n),r&&Jr(this,n),i&&Sn()}(n=this.pendingKeys_)==null||(n=n.get(e))==null||n.set(!0),this.keysAtom_.reportChanged()}ownKeys_(){return this.keysAtom_.reportObserved(),ee(this.target_)}keys_(){return this.keysAtom_.reportObserved(),Object.keys(this.target_)}};function wi(e,t){if(t&&Di(e)&&n(`Options can't be provided for already observable objects.`),T(e,O))return z(e)instanceof Ci||n(`Cannot convert '${ki(e)}' into observable object:\nThe target is already observable of different type.\nExtending builtins is not supported.`),e;Object.isExtensible(e)||n(`Cannot make the designated object observable; it is not extensible`);let r=t?.name??`${g(e)?`ObservableObject`:e.constructor.name}@${u()}`;return v(e,O,new Ci(e,new Map,String(r),rt(t))),e}let Ti=b(`ObservableObjectAdministration`,Ci);function Ei(e){return xi[e]||(xi[e]={get(){return this[O].getObservablePropValue_(e)},set(t){return this[O].setObservablePropValue_(e,t)}})}function Di(e){return h(e)?Ti(e[O]):!1}function Oi(e,t,n){e.appliedAnnotations_[n]=t}function L(e,t,r){if(Ri(t)||n(`Cannot annotate '${e.name_}.${r.toString()}': Invalid annotation.`),!ve(t)&&T(e.appliedAnnotations_,r)){let i=`${e.name_}.${r.toString()}`,a=e.appliedAnnotations_[r].annotationType_,o=t.annotationType_;n(`Cannot apply '${o}' to '${i}':\nThe field is already annotated with '${a}'.\nRe-annotating fields is not allowed.\nUse 'override' annotation for methods overridden by subclass.`)}}function R(e,t){if(typeof e==`object`&&e){if(ui(e))return t!==void 0&&n(23),e[O].atom_;if(yi(e))return e.atom_;if(mi(e)){if(t===void 0)return e.keysAtom_;let r=e.data_.get(t)||e.hasMap_.get(t);return r||n(25,t,ki(e)),r}if(Di(e)){if(!t)return n(26);let r=e[O],i=r.values_.get(t)??r.materializeLazyComputed_(t)??r.materializeLazyObservable_(t);return i||n(27,t,ki(e)),i}if(oe(e)||kt(e)||gn(e))return e}else if(p(e)&&gn(e[O]))return e[O];n(28)}function z(e,t){if(e||n(29),t!==void 0)return z(R(e,t));if(oe(e)||kt(e)||gn(e)||mi(e)||yi(e))return e;if(e[O])return e[O];n(24,e)}function ki(e,t){let n;if(t!==void 0)n=R(e,t);else if(Ln(e))return e.name;else n=Di(e)||mi(e)||yi(e)?z(e):R(e);return n.name_}function Ai(e){let t=Vt(),n=wt(!0);nn();try{return e()}finally{rn(),Tt(n),Ht(t)}}let ji=o.toString;function Mi(e,t,n=-1){return Ni(e,t,n)}function Ni(e,t,n,r,i){if(e===t)return e!==0||1/e==1/t;if(e==null||t==null)return!1;if(e!==e)return t!==t;let a=typeof e;if(a!==`function`&&a!==`object`&&typeof t!=`object`)return!1;let o=ji.call(e);if(o!==ji.call(t))return!1;switch(o){case`[object RegExp]`:case`[object String]`:return``+e==``+t;case`[object Number]`:return+e==+e?+e==0?1/e==1/t:+e==+t:+t!=+t;case`[object Date]`:case`[object Boolean]`:return+e==+t;case`[object Symbol]`:return typeof Symbol<`u`&&Symbol.valueOf.call(e)===Symbol.valueOf.call(t);case`[object Map]`:case`[object Set]`:n>=0&&n++;break}e=Pi(e),t=Pi(t);let s=o===`[object Array]`;if(!s){if(typeof e!=`object`||typeof t!=`object`)return!1;let n=e.constructor,r=t.constructor;if(n!==r&&!(p(n)&&n instanceof n&&p(r)&&r instanceof r)&&`constructor`in e&&`constructor`in t)return!1}if(n===0)return!1;n<0&&(n=-1),r||=[],i||=[];let c=r.length;for(;c--;)if(r[c]===e)return i[c]===t;if(r.push(e),i.push(t),s){if(c=e.length,c!==t.length)return!1;for(;c--;)if(!Ni(e[c],t[c],n-1,r,i))return!1}else{let a=Object.keys(e),o=a.length;if(Object.keys(t).length!==o)return!1;for(let s=0;s<o;s++){let o=a[s];if(!(T(t,o)&&Ni(e[o],t[o],n-1,r,i)))return!1}}return r.pop(),i.pop(),!0}function Pi(e){return ui(e)?e.slice():x(e)||mi(e)||C(e)||yi(e)?Array.from(e.entries()):e}let Fi=globalThis.Iterator?.prototype||{};function Ii(e){return e[Symbol.iterator]=Li,r(Object.create(Fi),e)}function Li(){return this}function Ri(e){return e instanceof Object&&typeof e.annotationType_==`string`&&p(e.make_)&&p(e.extend_)}{let e=globalThis;[`Symbol`,`Map`,`Set`,`Proxy`].forEach(t=>{e[t]===void 0&&n(`MobX requires global '${t}' to be available or polyfilled`)})}typeof __MOBX_DEVTOOLS_GLOBAL_HOOK__==`object`&&__MOBX_DEVTOOLS_GLOBAL_HOOK__.injectMobx({spy:Cn,extras:{getDebugName:ki},$mobx:O}),e.$mobx=O,e.FlowCancellationError=tr,e.ObservableMap=pi,e.ObservableSet=vi,e.Reaction=dn,e._allowStateChanges=Ct,e._allowStateChangesInsideComputed=In,e._allowStateReadsEnd=Ut,e._allowStateReadsStart=M,e._autoAction=Nn,e._autoActionBound=Fn,e._endAction=St,e._getAdministration=z,e._getGlobalState=Yt,e._interceptReads=ur,e._isComputingDerivation=Nt,e._resetGlobalState=Xt,e._startAction=xt,e.action=Mn,e.actionBound=Pn,e.autorun=Rn,e.compareDefault=de,e.compareIdentity=ce,e.compareShallow=ue,e.compareStructural=le,e.computed=j,e.computedStruct=mt,e.configure=qn,e.createAtom=se,e.defineProperty=Dr,e.entries=Sr,e.extendObservable=Jn,e.flow=ar,e.flowBound=or,e.flowResult=cr,e.get=Er,e.getAtom=R,e.getDebugName=ki,e.getDependencyTree=Yn,e.getObserverTree=Zn,e.has=Tr,e.intercept=dr,e.isAction=Ln,e.isBoxedObservable=Dt,e.isComputed=hr,e.isComputedProp=gr,e.isFlow=lr,e.isFlowCancellationError=nr,e.isObservable=vr,e.isObservableArray=ui,e.isObservableMap=mi,e.isObservableObject=Di,e.isObservableProp=yr,e.isObservableSet=yi,e.keys=br,e.makeAutoObservable=Zr,e.makeObservable=Yr,e.observable=A,e.observableDeep=lt,e.observableRef=st,e.observableShallow=ct,e.observableStruct=ut,e.observe=kr,e.onBecomeObserved=Un,e.onBecomeUnobserved=Wn,e.onReactionError=fn,e.override=_e,e.ownKeys=Or,e.reaction=Vn,e.remove=wr,e.runInAction=In,e.set=Cr,e.spy=Cn,e.toJS=Fr,e.transaction=Ir,e.untracked=Bt,e.values=xr,e.when=Lr})),Cv=we(((e,t)=>{process.env.NODE_ENV===`production`?t.exports=xv():t.exports=Sv()}))();function wv(e){if(Array.isArray(e))return Object.freeze(e.map(wv));if(typeof e==`object`&&e){let t=Object.create(null),n=Object.entries(e).sort(([e],[t])=>e<t?-1:+(e>t));for(let[e,r]of n)t[e]=wv(r);return Object.freeze(t)}return e}function Tv(e){let t=typeof e;if(t===`string`||t===`number`||t===`boolean`)return t;throw TypeError(`Variable values must be string|number|boolean (got ${t})`)}function Ev(e){return typeof e==`string`?e:String(e)}function Dv(e){if(typeof e==`number`)return e;if(typeof e==`boolean`)return+!!e;let t=e.trim();if(t===``)throw TypeError(`Cannot cast empty string to number`);let n=Number(t);if(!Number.isFinite(n))throw TypeError(`Cannot cast ${JSON.stringify(e)} to number`);return n}function Ov(e){if(typeof e==`boolean`)return e;if(typeof e==`number`){if(e===0||e===1)return e===1;throw TypeError(`Cannot cast number ${e} to bool (only 0 and 1 are accepted)`)}if(e===`true`)return!0;if(e===`false`)return!1;throw TypeError(`Cannot cast ${JSON.stringify(e)} to bool (expected "true" or "false")`)}var kv=class extends Error{constructor(e,t){super(t),this.variable=e}};function Av(e){return e instanceof kv||e instanceof Error&&e.cause!==void 0&&Av(e.cause)}var jv=class extends Error{name=`TemplateError`;kind=`EvalError`;pos;source;constructor(e,t,n={}){super(e,{cause:n.cause}),this.pos=t,this.source=n.source}get sourceSnippet(){return this.source?Bv(this.source,this.pos):``}toString(){let e=`${this.name}: ${this.message}\n at line ${this.pos.line}, column ${this.pos.column}`,t=this.sourceSnippet;return t?`${e}\n\n${t}`:e}},Mv=class extends jv{name=`ParseError`;kind=`ParseError`;expected;found;constructor(e,t,n={}){super(e,t,n),this.expected=n.expected,this.found=n.found}},Nv=class extends jv{name=`EvalError`;kind=`EvalError`},Pv=class extends Nv{name=`FuncNotFoundError`;kind=`FuncNotFoundError`;funcName;suggestions;constructor(e,t,n={}){let r=Vv(e,n.available??[]),i=r.length===0?``:` (did you mean: ${r.join(`, `)}?)`;super(`function ${JSON.stringify(e)} is not registered${i}`,t,n),this.funcName=e,this.suggestions=r}},Fv=class extends Nv{name=`ArgCountError`;kind=`ArgCountError`;funcName;accepted;got;constructor(e,t,n,r,i={}){let a=t.minimum===t.maximum?`${t.minimum}`:`at least ${t.minimum}`;super(`wrong number of args for ${e}: want ${a} got ${n}`,r,i),this.funcName=e,this.accepted=t,this.got=n}},Iv=class extends Nv{name=`TypeMismatchError`;kind=`TypeMismatchError`;funcName;argIndex;expected;receivedSummary;constructor(e,t,n,r,i,a={}){super(`function ${JSON.stringify(e)} arg ${t}: expected ${n}, but a ${r} flowed in. Pass it through \`unstyled\` (or your engine's flatten function) to convert.`,i,a),this.funcName=e,this.argIndex=t,this.expected=n,this.receivedSummary=r}},Lv=class extends Iv{constructor(e,t,n,r,i={}){super(e,t,`integer`,String(n),r,i),this.message=Number.isInteger(Number(n))?`integer out of range: ${String(n)}`:`expected integer; found ${String(n)}`}},Rv=class extends Nv{name=`MissingFieldError`;kind=`MissingFieldError`;path;constructor(e,t,n={}){super(`field "${e.join(`.`)}" not found on receiver`,t,n),this.path=e}},zv=class extends Nv{name=`FailError`;kind=`FailError`;constructor(e,t={line:0,column:0,offset:0},n={}){super(e,t,n)}};function Bv(e,t){let n=e.split(`
|
|
58
58
|
`),r=t.line-1,i=[];if(r-1>=0&&r-1<n.length&&i.push({num:r,text:n[r-1]??``}),r>=0&&r<n.length&&i.push({num:r+1,text:n[r]??``}),r+1<n.length&&i.push({num:r+2,text:n[r+1]??``}),i.length===0)return``;let a=String(i[i.length-1]?.num??1).length,o=[];for(let e of i)if(o.push(` ${String(e.num).padStart(a,` `)} | ${e.text}`),e.num===t.line){let e=` ${` `.repeat(a)} | `,n=` `.repeat(Math.max(0,t.column-1));o.push(`${e}${n}^`)}return o.join(`
|
|
59
|
-
`)}function
|
|
59
|
+
`)}function Vv(e,t){if(t.length===0)return[];let n=t.map(t=>({name:t,dist:Hv(e,t)})).sort((e,t)=>e.dist-t.dist),r=Math.max(2,Math.floor(e.length/2));return n.filter(e=>e.dist<=r).slice(0,3).map(e=>e.name)}function Hv(e,t){if(e===t)return 0;let n=e.length,r=t.length;if(n===0)return r;if(r===0)return n;let i=Array(r+1),a=Array(r+1);for(let e=0;e<=r;e++)i[e]=e;for(let o=1;o<=n;o++){a[0]=o;for(let n=1;n<=r;n++){let r=e[o-1]===t[n-1]?0:1;a[n]=Math.min((a[n-1]??0)+1,(i[n]??0)+1,(i[n-1]??0)+r)}for(let e=0;e<=r;e++)i[e]=a[e]??0}return i[r]??0}function Uv(e){throw Error(`unhandled node kind: ${JSON.stringify(e)}`)}const Wv=new Map([[`if`,`If`],[`else`,`Else`],[`end`,`End`],[`range`,`Range`],[`with`,`With`],[`break`,`Break`],[`continue`,`Continue`],[`define`,`Define`],[`template`,`Template`],[`block`,`Block`],[`true`,`Bool`],[`false`,`Bool`],[`nil`,`Nil`]]),Gv={left:`{{`,right:`}}`};var Kv=class{src;leftDelim;rightDelim;offset=0;line=1;column=1;mode=`text`;pending;constructor(e,t=Gv){this.src=e,this.leftDelim=t.left,this.rightDelim=t.right}pos(){return{line:this.line,column:this.column,offset:this.offset}}err(e,t,n={}){return new Mv(e,t,{...n,source:this.src})}next(){if(this.pending){let e=this.pending;return this.pending=void 0,e}return this.read()}peek(){return this.pending||=this.read(),this.pending}read(){switch(this.mode){case`text`:return this.readText();case`action`:return this.readAction();case`done`:return this.makeToken(`EOF`,``,this.pos())}}readText(){if(this.offset>=this.src.length)return this.mode=`done`,this.makeToken(`EOF`,``,this.pos());let e=this.pos(),t=this.offset;for(;t<this.src.length&&!this.src.startsWith(this.leftDelim,t);)t+=1;let n=t<this.src.length&&this.src[t+this.leftDelim.length]===`-`,r=t;if(n)for(;r>this.offset&&qv(this.src[r-1]??``);)--r;if(r>this.offset){let t=this.src.slice(this.offset,r);return this.advanceTo(r),this.makeToken(`Text`,t,e)}return this.advanceTo(t),this.emitLeftDelim(n)}emitLeftDelim(e){let t=this.pos();if(this.advanceBy(this.leftDelim.length),e)for(this.advanceBy(1);qv(this.src[this.offset]??``);)this.advanceBy(1);return this.mode=`action`,this.src.startsWith(`/*`,this.offset)?this.readComment(t,e):this.makeToken(`LeftDelim`,e?`${this.leftDelim}-`:this.leftDelim,t,e?{trimLeft:!0}:{})}readComment(e,t){this.advanceBy(2);let n=this.offset,r=this.src.indexOf(`*/`,this.offset);if(r===-1)throw this.err(`unclosed comment`,e,{expected:`*/${this.rightDelim}`,found:`end of input`});this.advanceTo(r);let i=this.src.slice(n,r).trim();for(this.advanceBy(2);qv(this.src[this.offset]??``);)this.advanceBy(1);let a=!1;if(this.src[this.offset]===`-`&&(a=!0,this.advanceBy(1)),!this.src.startsWith(this.rightDelim,this.offset))throw this.err(`expected \`${this.rightDelim}\` to close comment`,this.pos(),{expected:this.rightDelim,found:this.src[this.offset]??`end of input`});if(this.advanceBy(this.rightDelim.length),a)for(;qv(this.src[this.offset]??``);)this.advanceBy(1);return this.mode=`text`,this.makeToken(`Comment`,i,e,{...t?{trimLeft:!0}:{},...a?{trimRight:!0}:{}})}readAction(){if(this.skipActionSpaces(),this.src.startsWith(`-${this.rightDelim}`,this.offset)){let e=this.pos();for(this.advanceBy(1+this.rightDelim.length),this.mode=`text`;qv(this.src[this.offset]??``);)this.advanceBy(1);return this.makeToken(`RightDelim`,`-${this.rightDelim}`,e,{trimRight:!0})}if(this.src.startsWith(this.rightDelim,this.offset)){let e=this.pos();return this.advanceBy(this.rightDelim.length),this.mode=`text`,this.makeToken(`RightDelim`,this.rightDelim,e)}if(this.offset>=this.src.length)throw this.err(`unclosed action`,this.pos(),{expected:this.rightDelim,found:`end of input`});let e=this.src[this.offset],t=this.pos();switch(e){case`(`:return this.advanceBy(1),this.makeToken(`LeftParen`,`(`,t);case`)`:return this.advanceBy(1),this.makeToken(`RightParen`,`)`,t);case`|`:return this.advanceBy(1),this.makeToken(`Pipe`,`|`,t);case`,`:return this.advanceBy(1),this.makeToken(`Comma`,`,`,t);case`:`:if(this.src[this.offset+1]===`=`)return this.advanceBy(2),this.makeToken(`Declare`,`:=`,t);throw this.err("expected `:=`",t,{expected:`:=`,found:`:`});case`=`:return this.advanceBy(1),this.makeToken(`Assign`,`=`,t);case`"`:return this.readQuotedString(t);case"`":return this.readRawString(t);case`'`:return this.readChar(t)}if(e===`$`)return this.readVariable(t);if(e!==void 0&&(Yv(e)||Jv(e)&&Yv(this.src[this.offset+1]??``)||e===`.`&&Yv(this.src[this.offset+1]??``)))return this.readNumber(t);if(e===`.`)return this.readDotOrField(t);if(e!==void 0&&ey(e))return this.readIdentifier(t);throw this.err(`unexpected character ${JSON.stringify(e)}`,t,{found:e??`end of input`})}readQuotedString(e){let t=this.offset;for(this.advanceBy(1);this.offset<this.src.length;){let n=this.src[this.offset];if(n===`\\`){this.advanceBy(1),this.offset<this.src.length&&this.advanceBy(1);continue}if(n===`
|
|
60
60
|
`)throw this.err(`newline in interpreted string`,e,{found:`\\n`});if(n===`"`)return this.advanceBy(1),this.makeToken(`String`,this.src.slice(t,this.offset),e);this.advanceBy(1)}throw this.err(`unterminated string literal`,e,{expected:`"`,found:`end of input`})}readRawString(e){let t=this.offset;for(this.advanceBy(1);this.offset<this.src.length;){if(this.src[this.offset]==="`")return this.advanceBy(1),this.makeToken(`String`,this.src.slice(t,this.offset),e);this.advanceBy(1)}throw this.err(`unterminated raw string literal`,e,{expected:"`",found:`end of input`})}readChar(e){let t=this.offset;for(this.advanceBy(1);this.offset<this.src.length;){let n=this.src[this.offset];if(n===`\\`){this.advanceBy(1),this.offset<this.src.length&&this.advanceBy(1);continue}if(n===`
|
|
61
|
-
`)throw this.err(`newline in rune literal`,e,{found:`\\n`});if(n===`'`)return this.advanceBy(1),this.makeToken(`Char`,this.src.slice(t,this.offset),e);this.advanceBy(1)}throw this.err(`unterminated rune literal`,e,{expected:`'`,found:`end of input`})}readNumber(e){let t=this.offset;if(
|
|
61
|
+
`)throw this.err(`newline in rune literal`,e,{found:`\\n`});if(n===`'`)return this.advanceBy(1),this.makeToken(`Char`,this.src.slice(t,this.offset),e);this.advanceBy(1)}throw this.err(`unterminated rune literal`,e,{expected:`'`,found:`end of input`})}readNumber(e){let t=this.offset;if(Jv(this.src[this.offset]??``)&&this.advanceBy(1),this.src[this.offset]===`0`&&this.offset+1<this.src.length){let n=this.src[this.offset+1];if(n===`x`||n===`X`){for(this.advanceBy(2);Xv(this.src[this.offset]??``)||this.src[this.offset]===`_`;)this.advanceBy(1);if(this.src[this.offset]===`.`||this.src[this.offset]===`p`||this.src[this.offset]===`P`)for(;this.isHexFloatTail(this.src[this.offset]??``);)this.advanceBy(1);return this.finishNumber(t,e)}if(n===`o`||n===`O`){for(this.advanceBy(2);Zv(this.src[this.offset]??``)||this.src[this.offset]===`_`;)this.advanceBy(1);return this.finishNumber(t,e)}if(n===`b`||n===`B`){for(this.advanceBy(2);Qv(this.src[this.offset]??``)||this.src[this.offset]===`_`;)this.advanceBy(1);return this.finishNumber(t,e)}}for(;Yv(this.src[this.offset]??``)||this.src[this.offset]===`_`;)this.advanceBy(1);if(this.src[this.offset]===`.`)for(this.advanceBy(1);Yv(this.src[this.offset]??``)||this.src[this.offset]===`_`;)this.advanceBy(1);if(this.src[this.offset]===`e`||this.src[this.offset]===`E`)for(this.advanceBy(1),Jv(this.src[this.offset]??``)&&this.advanceBy(1);Yv(this.src[this.offset]??``);)this.advanceBy(1);return this.src[this.offset]===`i`&&this.advanceBy(1),this.finishNumber(t,e)}isHexFloatTail(e){return Xv(e)||e===`.`||e===`p`||e===`P`||e===`+`||e===`-`||e===`_`}finishNumber(e,t){if(this.offset===e)throw this.err(`expected number`,t,{expected:`digit`});return this.makeToken(`Number`,this.src.slice(e,this.offset),t)}readVariable(e){let t=this.offset;for(this.advanceBy(1);ty(this.src[this.offset]??``);)this.advanceBy(1);for(;this.src[this.offset]===`.`&&ey(this.src[this.offset+1]??``);)for(this.advanceBy(1);ty(this.src[this.offset]??``);)this.advanceBy(1);return this.makeToken(`Variable`,this.src.slice(t,this.offset),e)}readDotOrField(e){let t=this.offset;if(this.advanceBy(1),!ey(this.src[this.offset]??``))return this.makeToken(`Dot`,`.`,e);for(;ty(this.src[this.offset]??``);)this.advanceBy(1);for(;this.src[this.offset]===`.`&&ey(this.src[this.offset+1]??``);)for(this.advanceBy(1);ty(this.src[this.offset]??``);)this.advanceBy(1);return this.makeToken(`Field`,this.src.slice(t,this.offset),e)}readIdentifier(e){let t=this.offset;for(;ty(this.src[this.offset]??``);)this.advanceBy(1);let n=this.src.slice(t,this.offset),r=Wv.get(n);return r?this.makeToken(r,n,e):this.makeToken(`Identifier`,n,e)}skipActionSpaces(){for(;this.offset<this.src.length;){let e=this.src[this.offset];if(e===` `||e===` `||e===`\r`||e===`
|
|
62
62
|
`)this.advanceBy(1);else return}}advanceBy(e){for(let t=0;t<e;t++){let e=this.src[this.offset];this.offset+=1,e===`
|
|
63
|
-
`?(this.line+=1,this.column=1):this.column+=1}}advanceTo(e){for(;this.offset<e;)this.advanceBy(1)}makeToken(e,t,n,r={}){return Object.freeze({type:e,value:t,pos:n,...r.trimLeft===void 0?{}:{trimLeft:r.trimLeft},...r.trimRight===void 0?{}:{trimRight:r.trimRight}})}};function
|
|
64
|
-
`}function
|
|
65
|
-
`;break;case`t`:r+=` `;break;case`r`:r+=`\r`;break;case`\\`:r+=`\\`;break;case`"`:r+=`"`;break;case`'`:r+=`'`;break;case`a`:r+=`\x07`;break;case`b`:r+=`\b`;break;case`f`:r+=`\f`;break;case`v`:r+=`\v`;break;case`0`:case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:{let t=o+(e[i+1]??``)+(e[i+2]??``);i+=2,r+=String.fromCodePoint(Number.parseInt(t,8));break}case`x`:{let t=(e[i+1]??``)+(e[i+2]??``);i+=2,r+=String.fromCodePoint(Number.parseInt(t,16));break}case`u`:{let t=e.slice(i+1,i+5);i+=4,r+=String.fromCodePoint(Number.parseInt(t,16));break}case`U`:{let t=e.slice(i+1,i+9);i+=8,r+=String.fromCodePoint(Number.parseInt(t,16));break}default:throw new Nv(`bad escape sequence \\${o}`,t,{expected:`valid escape sequence`,found:`\\${o}`,source:n})}}return r}function by(e,t,n){let r=yy(`"${e.slice(1,-1).replace(/"/g,`\\"`)}"`,t,n);if(r.length===0)throw new Nv(`empty rune literal`,t,{source:n});return r.codePointAt(0)??0}function xy(e,t){if(t(e)!==!1)for(let n of Sy(e))xy(n,t)}function Sy(e){switch(e.type){case`Text`:case`Comment`:case`Dot`:case`Nil`:case`Bool`:case`Number`:case`String`:case`Identifier`:case`Field`:case`Variable`:case`Break`:case`Continue`:return[];case`List`:return e.nodes;case`Chain`:return[e.node];case`Command`:return e.args;case`Pipe`:return[...e.decls,...e.cmds];case`Action`:return[e.pipe];case`If`:case`Range`:case`With`:return e.elseList?[e.pipe,e.list,e.elseList]:[e.pipe,e.list];case`Template`:return e.pipe?[e.pipe]:[];case`Block`:return e.pipe?[e.pipe,e.list]:[e.list];default:return Wv(e)}}const Cy=Symbol(`go-template-js.MISSING`);function wy(e,t){if(e==null)return Cy;if(e instanceof Map)return e.has(t)?e.get(t):Cy;if(Array.isArray(e))return Cy;if(typeof e==`object`){let n=e;return t in n?n[t]:Cy}return Cy}function Ty(e,t){let n=e;for(let e of t){if(n===Cy)return Cy;n=wy(n,e)}return n}function Ey(e,t){if(Object.is(e,t))return!0;if(e===null||t===null||e===void 0||t===void 0||typeof e!=typeof t)return!1;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length?e.every((e,n)=>Ey(e,t[n])):!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(let[n,r]of e)if(!t.has(n)||!Ey(r,t.get(n)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}if(typeof e==`object`&&typeof t==`object`){let n=Object.keys(e),r=Object.keys(t);return n.length===r.length?n.every(n=>Ey(e[n],t[n])):!1}return!1}const Dy=new WeakSet;function Oy(e){return Dy.add(e),e}function ky(e){return Dy.has(e)}function Ay(e){return e==null||e===!1?!1:typeof e==`number`?e!==0&&!Number.isNaN(e):typeof e==`bigint`?e!==0n:typeof e==`string`||Array.isArray(e)?e.length>0:e instanceof Map||e instanceof Set?e.size>0:typeof e==`object`?Object.keys(e).length>0:!!e}function jy(e,t){return{eq:{fn:(e,...t)=>t.some(t=>Py(e,t)),argTypes:[`comparable`,`comparable`],arity:{kind:`variadic`}},ne:{fn:(e,t)=>!Py(e,t),argTypes:[`comparable`,`comparable`],arity:{kind:`exact`}},lt:{fn:(e,t)=>Fy(e,t)<0,argTypes:[`ordered`,`ordered`],arity:{kind:`exact`}},le:{fn:(e,t)=>Fy(e,t)<=0,argTypes:[`ordered`,`ordered`],arity:{kind:`exact`}},gt:{fn:(e,t)=>Fy(e,t)>0,argTypes:[`ordered`,`ordered`],arity:{kind:`exact`}},ge:{fn:(e,t)=>Fy(e,t)>=0,argTypes:[`ordered`,`ordered`],arity:{kind:`exact`}},len:{fn:e=>Iy(e),argTypes:[`sized`],arity:{kind:`exact`}},index:{fn:(e,...t)=>{let n=e;for(let e of t)n=Ly(n,e);return n},argTypes:[`collection`,`index-key`],arity:{kind:`variadic`}},slice:{fn:(e,...t)=>zy(e,t),argTypes:[`sliceable`,`int`],arity:{kind:`variadic`}},print:{fn:(...t)=>Hy(t,e),argTypes:[`stringifiable`],arity:{kind:`variadic`},returnType:`string`},println:{fn:(...t)=>`${Hy(t,e)}\n`,argTypes:[`stringifiable`],arity:{kind:`variadic`},returnType:`string`},printf:{fn:(n,...r)=>Zy(n,r,e,t),argTypes:[`string`,`stringifiable`],arity:{kind:`variadic`},returnType:`string`},toString:{fn:n=>eb(n,e,t),argTypes:[`value`],arity:{kind:`exact`},returnType:`string`},toStrings:{fn:n=>n.map(n=>eb(n,e,t)),argTypes:[`list`],arity:{kind:`exact`}},call:{fn:(e,...t)=>e(...t),argTypes:[`callable`,`value`],arity:{kind:`variadic`}},html:{fn:(...t)=>Gy(Hy(t,e)),argTypes:[`stringifiable`],arity:{kind:`variadic`},returnType:`string`},js:{fn:(...t)=>Jy(Hy(t,e)),argTypes:[`stringifiable`],arity:{kind:`variadic`},returnType:`string`},urlquery:{fn:(...t)=>Xy(Hy(t,e)),argTypes:[`stringifiable`],arity:{kind:`variadic`},returnType:`string`},not:{fn:e=>!Ay(e),argTypes:[`truthy`],arity:{kind:`exact`}}}}function My(){return{and:Oy({argTypes:[`truthy`,`truthy`],arity:{kind:`variadic`},fn:(...e)=>{let t=!0;for(let n of e)if(t=n(),!Ay(t))return t;return t}}),or:Oy({argTypes:[`truthy`,`truthy`],arity:{kind:`variadic`},fn:(...e)=>{let t=!1;for(let n of e)if(t=n(),Ay(t))return t;return t}})}}function Ny(e,t){return{...jy(e,t),...My()}}function Py(e,t){return typeof e==`number`&&typeof t==`bigint`?BigInt(e)===t:typeof e==`bigint`&&typeof t==`number`?e===BigInt(t):Ey(e,t)}function Fy(e,t){if(typeof e==`bigint`&&typeof t==`bigint`)return e===t?0:e<t?-1:1;if(typeof e==`bigint`||typeof t==`bigint`){let n=typeof e==`bigint`?e:BigInt(Math.trunc(Number(e))),r=typeof t==`bigint`?t:BigInt(Math.trunc(Number(t)));return n===r?0:n<r?-1:1}let n=e,r=t;return n===r?0:n<r?-1:1}function Iy(e){return typeof e==`string`||Array.isArray(e)?e.length:e instanceof Map||e instanceof Set?e.size:Object.keys(e).length}function Ly(e,t){if(Array.isArray(e)||typeof e==`string`){let n=Ry(t,e.length);if(n===e.length)throw Error(`index out of range: ${n}`);return e[n]}if(e instanceof Map)return e.get(t);if(typeof e==`object`&&e){if(typeof t!=`string`)throw Error(`index: object index must be string, got ${By(t)}`);return e[t]}throw Error(`index: cannot index ${By(e)}`)}function Ry(e,t){let n=typeof e==`bigint`?Number(e):e;if(typeof n!=`number`||!Number.isInteger(n))throw Error(`cannot index slice/array with type ${Vy(e)}`);if(n<0||n>t)throw Error(`index out of range: ${String(e)}`);return n}function zy(e,t){if(t.length>3)throw Error(`too many slice indexes: ${t.length}`);if(typeof e==`string`&&t.length>2)throw Error(`cannot 3-index slice a string`);let n=e.length,r=[0,n,n];t.forEach((e,t)=>{r[t]=Ry(e,n)});let[i,a,o]=r;if(i>a)throw Error(`invalid slice index: ${i} > ${a}`);if(a>o)throw Error(`invalid slice index: ${a} > ${o}`);return e.slice(i,a)}function By(e){return e===null?`null`:e===void 0?`undefined`:Array.isArray(e)?`array`:e instanceof Map?`Map`:typeof e}function Vy(e){return e==null?`<nil>`:typeof e==`string`?`string`:typeof e==`boolean`?`bool`:typeof e==`bigint`?`int64`:typeof e==`number`?Number.isInteger(e)?`int`:`float64`:Array.isArray(e)?`[]interface {}`:e instanceof Map||typeof e==`object`?`map[string]interface {}`:typeof e}function Hy(e,t){let n=``,r=!1;for(let i=0;i<e.length;i++){let a=e[i],o=typeof a==`string`;i>0&&!r&&!o&&(n+=` `),n+=Uy(a,t),r=o}return n}function Uy(e,t){return e==null?`<nil>`:typeof e==`string`?e:t(e)}const Wy={"\0":`�`,'"':`"`,"'":`'`,"&":`&`,"<":`<`,">":`>`};function Gy(e){return e.replace(/[\0"'&<>]/g,e=>Wy[e]??e)}const Ky={"\\":`\\\\`,"'":`\\'`,'"':`\\"`,"<":`\\u003C`,">":`\\u003E`,"&":`\\u0026`,"=":`\\u003D`},qy=/^[\p{L}\p{M}\p{N}\p{P}\p{S}]$/u;function Jy(e){let t=``;for(let n of e){let e=Ky[n];if(e!==void 0){t+=e;continue}let r=n.codePointAt(0);if(r<32||r>=128&&!qy.test(n)){t+=`\\u${r.toString(16).toUpperCase().padStart(4,`0`)}`;continue}t+=n}return t}const Yy=new TextEncoder;function Xy(e){let t=``,n=Yy.encode(e);for(let e of n)e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===45||e===46||e===95||e===126?t+=String.fromCharCode(e):e===32?t+=`+`:t+=`%${e.toString(16).toUpperCase().padStart(2,`0`)}`;return t}function Zy(e,t,n,r){let i=``,a=0,o=0;for(;o<e.length;){let s=e[o];if(s!==`%`){i+=s,o+=1;continue}if(e[o+1]===`%`){i+=`%`,o+=2;continue}let c=o+1;for(;c<e.length&&`+-# 0`.includes(e[c]??``);)c+=1;for(;c<e.length&&e[c]!==void 0&&/[0-9]/.test(e[c]);)c+=1;if(e[c]===`.`)for(c+=1;c<e.length&&e[c]!==void 0&&/[0-9]/.test(e[c]);)c+=1;let l=e[c],u=e.slice(o+1,c),d=t[a++];i+=Qy(l??``,u,d,n,r),o=c+1}return i}function Qy(e,t,n,r,i){switch(e){case`s`:return typeof n==`string`?$y(t,n):$y(t,Uy(n,r));case`d`:return typeof n!=`number`&&typeof n!=`bigint`?`%!${e}(${Vy(n)}=${Uy(n,r)})`:$y(t,String(typeof n==`bigint`?n:Math.trunc(n)));case`v`:return $y(t,eb(n,r,i));case`q`:return $y(t,JSON.stringify(Uy(n,r)));case`f`:{if(typeof n!=`number`&&typeof n!=`bigint`)return`%!${e}(${Vy(n)}=${Uy(n,r)})`;let i=t.includes(`.`)?Number(t.split(`.`)[1]):6;return $y(t,Number(n).toFixed(i))}case`t`:return $y(t,Ay(n)?`true`:`false`);case`x`:if(typeof n==`string`){let e=new TextEncoder().encode(n),r=``;for(let t of e)r+=t.toString(16).padStart(2,`0`);return $y(t,r)}return typeof n!=`number`&&typeof n!=`bigint`?`%!${e}(${Vy(n)}=${Uy(n,r)})`:typeof n==`bigint`?$y(t,n.toString(16)):$y(t,Math.trunc(n).toString(16));default:return`%!${e}(${Vy(n)}=${Uy(n,r)})`}}function $y(e,t){let n=e.match(/^([+\-# 0]*)/)?.[1]??``,r=e.slice(n.length).match(/^(\d+)/);if(!r)return t;let i=Number(r[1]);if(t.length>=i)return t;let a=` `.repeat(i-t.length);return n.includes(`-`)?t+a:a+t}function eb(e,t,n){return e==null?`<nil>`:typeof e==`string`?e:n(e)?t(e):Array.isArray(e)?`[${e.map(e=>eb(e,t,n)).join(` `)}]`:e instanceof Map?tb([...e.entries()],t,n):nb(e)?tb(Object.entries(e),t,n):String(e)}function tb(e,t,n){let r=e=>eb(e,t,n),i=e=>typeof e==`number`||typeof e==`bigint`,a=([e],[t])=>{if(i(e)&&i(t))return e<t?-1:+(e>t);if(i(e)!==i(t))return i(e)?-1:1;let[n,a]=[r(e),r(t)];return n<a?-1:+(n>a)};return`map[${[...e].sort(a).map(([e,t])=>`${r(e)}:${r(t)}`).join(` `)}]`}function nb(e){if(typeof e!=`object`||!e||Array.isArray(e)||e instanceof Map||e instanceof Set)return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function rb(e){return{dot:e,root:e,parent:void 0,vars:new Map}}function ib(e,t){return{dot:t,root:e.root,parent:e,vars:new Map}}function ab(e,t){let n=e;for(;n!==void 0;){if(n.vars.has(t))return{found:!0,value:n.vars.get(t)};n=n.parent}return{found:!1}}function ob(e,t,n){e.vars.set(t,n)}const sb=[`string`,`int`,`truncating-int`,`float`,`bool`,`T`,`ordered`,`list`,`dict`,`sized`,`comparable`,`stringifiable`,`liftable`,`callable`,`collection`,`index-key`,`sliceable`,`truthy`,`reflective`,`value`,`serializable`],cb=new Set([`default`,`zero`,`error`]);function lb(e){if(e===void 0)return`default`;if(cb.has(e))return e;throw Error(`EngineConfig.missingKey: expected "default" | "zero" | "error", got ${ub(e)}`)}function ub(e){return typeof e==`string`?JSON.stringify(e):e===null?`null`:e===void 0?`undefined`:typeof e==`bigint`?`${e}n`:typeof e==`number`||typeof e==`boolean`?String(e):typeof e==`symbol`?e.toString():typeof e==`function`?`[Function]`:`[${typeof e}]`}function db(e){if(e!==void 0){if(typeof e!=`object`||!e)throw Error(`EngineConfig.delims: expected { left, right } object, got ${ub(e)}`);if(typeof e.left!=`string`||e.left.length===0)throw Error(`EngineConfig.delims.left: expected non-empty string, got ${ub(e.left)}`);if(typeof e.right!=`string`||e.right.length===0)throw Error(`EngineConfig.delims.right: expected non-empty string, got ${ub(e.right)}`);return{left:e.left,right:e.right}}}function fb(e){switch(e.kind){case`exact`:return!1;case`variadic`:return!0;case`alternating`:return!0}}function pb(e){let t=new Set(sb);for(let[n,r]of Object.entries(e)){if(r.argTypes.forEach((e,r)=>{if(!t.has(e))throw Error(`EngineConfig.funcs.${n}: argTypes[${r}] is ${JSON.stringify(e)}, which is not an ArgType; declare one of ${sb.join(`, `)}`)}),fb(r.arity)&&r.argTypes.length===0)throw Error(`EngineConfig.funcs.${n}: arity ${JSON.stringify(r.arity.kind)} needs at least one declared argType (it reads its repeating slot from the end of argTypes); declare the slots the Go signature has, or use { kind: "exact" }`);if(r.arity.kind===`alternating`&&(!Number.isSafeInteger(r.arity.minimum)||r.arity.minimum<0))throw Error(`EngineConfig.funcs.${n}: arity "alternating" needs a non-negative integer minimum, got ${String(r.arity.minimum)}; the gate rejects every count below it, so a negative or non-finite minimum would disable the lower bound`)}return e}const mb=Object.freeze({kind:`break`}),hb=Object.freeze({kind:`continue`}),gb={kind:`none`};let _b;(class e{source;_evaluate;_defines;_referencedFunctions;_referencedCalls;constructor(e,t,n,r,i){this.source=e,this._evaluate=t,this._defines=n,this._referencedFunctions=r,this._referencedCalls=i}static{_b=(t,n,r,i,a)=>new e(t,n,r,i,a)}defines(){return this._defines}evaluate(e){return this._evaluate(e)}referencedFunctions(){return this._referencedFunctions}referencedCalls(){return this._referencedCalls}});function vb(e){let t=new Set,n=e=>{xy(e,e=>{e.type===`Identifier`&&t.add(e.ident)})};n(e.root);for(let t of e.ownDefines.values())n(t.list);return t}const yb={kind:`dynamic`};function bb(e){switch(e.type){case`String`:return{kind:`literal`,value:e.value};case`Bool`:return{kind:`literal`,value:e.value};case`Nil`:return{kind:`literal`,value:null};case`Number`:{let t=Vb(e);return typeof t==`number`||typeof t==`bigint`?{kind:`literal`,value:t}:yb}case`Pipe`:{if(e.decls.length!==0||e.cmds.length!==1)return yb;let t=e.cmds[0];if(t===void 0)return yb;let n=t.args[0];return n===void 0||n.type!==`Identifier`?yb:{kind:`call`,name:n.ident,args:t.args.slice(1).map(bb)}}default:return yb}}function xb(e){let t=[],n=e=>{xy(e,e=>{if(e.type!==`Command`)return;let n=e.args[0];if(n===void 0||n.type!==`Identifier`)return;let r=e.args.slice(1).map(bb);t.push({name:n.ident,args:r.map(e=>e.kind===`literal`&&typeof e.value==`string`?e.value:null),argExprs:r})})};n(e.root);for(let t of e.ownDefines.values())n(t.list);return t}var Sb=class{fromString;toString;isT;funcs;missingKey;delims;constructor(e){this.fromString=e.fromString;let t=Object.hasOwn(e,`toString`)?e.toString:void 0;this.toString=t??Ab,this.isT=e.isT??Cb,this.missingKey=lb(e.missingKey),this.delims=db(e.delims),this.funcs=pb({...Ny(this.toString,this.isT),...e.funcs??{}})}parse(e,t){let n=sy(e,this.delims,t);return _b(n.source,e=>this.evalParsed(n,e),n.defines,vb(n),xb(n))}compile(e){let t=this.parse(e);return e=>t.evaluate(e)}evaluate(e,t){return e.evaluate(t)}evalParsed(e,t){let n=[],r=rb(t),i={out:n,defines:e.defines,source:e.source};return this.evalList(e.root,r,i),n}evalList(e,t,n){for(let r of e.nodes)this.evalNode(r,t,n)}evalNode(e,t,n){switch(e.type){case`Text`:n.out.push(this.fromString(e.text));return;case`Comment`:return;case`Action`:{let r=this.evalAction(e,t,n);e.pipe.decls.length===0&&this.emitFromValue(r,n);return}case`List`:this.evalList(e,t,n);return;case`If`:this.evalIf(e,t,n);return;case`Range`:this.evalRange(e,t,n);return;case`With`:this.evalWith(e,t,n);return;case`Break`:throw mb;case`Continue`:throw hb;case`Template`:this.evalTemplateInvoke(e,t,n);return;case`Block`:this.evalBlock(e,t,n);return;case`Pipe`:case`Command`:case`Identifier`:case`Field`:case`Variable`:case`Chain`:case`Dot`:case`Nil`:case`Bool`:case`Number`:case`String`:throw new Pv(`unexpected ${e.type} at statement position`,e.pos,{source:n.source});default:Wv(e)}}evalIf(e,t,n){Ay(this.evalPipe(e.pipe,t,n))?this.evalList(e.list,t,n):e.elseList&&this.evalList(e.elseList,t,n)}evalWith(e,t,n){let r=this.evalPipe(e.pipe,t,n);if(Ay(r)){let i=ib(t,r);this.evalList(e.list,i,n)}else e.elseList&&this.evalList(e.elseList,t,n)}evalRange(e,t,n){let r=this.evalPipeWithoutDecls(e.pipe,t,n),i=e.pipe.decls,a=Rb(r);try{if(a.length===0){e.elseList&&this.evalList(e.elseList,t,n);return}for(let[r,o]of a){let a=ib(t,o);if(i.length===1)ob(a,i[0]?.idents[0]??`$`,o);else if(i.length>=2){let e=i[0]?.idents[0]??`$`,t=i[1]?.idents[0]??`$`;ob(a,e,r),ob(a,t,o)}try{this.evalList(e.list,a,n)}catch(e){if(e===hb)continue;throw e}}}catch(e){if(e===mb)return;throw e}}evalTemplateInvoke(e,t,n){let r=ay(n.defines,e.name);if(!r)throw new Pv(`template ${JSON.stringify(e.name)} is not defined`,e.pos,{source:n.source});let i=ib(t,e.pipe?this.evalPipe(e.pipe,t,n):t.dot);this.evalList(r.list,i,{out:n.out,defines:n.defines,source:r.source})}evalBlock(e,t,n){let r=ib(t,e.pipe?this.evalPipe(e.pipe,t,n):t.dot),i=ay(n.defines,e.name)??{list:e.list,source:n.source};this.evalList(i.list,r,{out:n.out,defines:n.defines,source:i.source})}evalAction(e,t,n){return this.evalPipe(e.pipe,t,n)}evalPipe(e,t,n){if(e.cmds.length===0)throw new Pv(`empty pipeline`,e.pos,{source:n.source});let r=this.evalCommand(e.cmds[0],t,n,gb);for(let i=1;i<e.cmds.length;i++){let a=e.cmds[i];r=this.evalCommand(a,t,n,{kind:`value`,value:r})}if(e.decls.length>0)for(let n of e.decls)ob(t,n.idents[0]??`$`,r);return r}evalPipeWithoutDecls(e,t,n){let r={type:`Pipe`,pos:e.pos,decls:[],isAssign:!1,cmds:e.cmds};return this.evalPipe(r,t,n)}evalCommand(e,t,n,r){if(e.args.length===0)throw new Pv(`empty command`,e.pos,{source:n.source});let i=e.args[0];if(i.type!==`Identifier`){if(e.args.length>1)throw new Pv(`cannot apply arguments to a ${i.type} primary; only functions take arguments`,e.pos,{source:n.source});return this.evalPrimary(i,t,n)}let a=this.funcs[i.ident];if(!a)throw new Fv(i.ident,i.pos,{source:n.source,available:Object.keys(this.funcs)});let o=e.args.slice(1),s=ky(a),c=o.map(e=>s?()=>this.evalPrimary(e,t,n):this.evalPrimary(e,t,n));if(r.kind===`value`){let e=r.value;c.push(s?()=>e:e)}return this.invoke(i.ident,a,c,e.pos,n)}invoke(e,t,n,r,i){Tb(e,t,n,r,i.source,this.toString,this.fromString,this.isT);try{return t.fn(...n)}catch(t){throw t instanceof Lv?new Lv(t.funcName,t.argIndex,t.expected,t.receivedSummary,r,{source:i.source}):t instanceof Bv?new Bv(t.message,r,{source:i.source}):t instanceof Mv?t:new Pv(`error calling ${e}: ${Ib(t)}`,r,{source:i.source,cause:t})}}evalPrimary(e,t,n){switch(e.type){case`Dot`:return t.dot;case`Nil`:return null;case`Bool`:return e.value;case`Number`:return Vb(e);case`String`:return e.value;case`Field`:return this.resolveFieldChain(t.dot,e.idents,e.pos,n);case`Variable`:return this.resolveVariable(e.idents,t,e.pos,n);case`Identifier`:{let t=this.funcs[e.ident];if(!t)throw new Fv(e.ident,e.pos,{source:n.source,available:Object.keys(this.funcs)});return this.invoke(e.ident,t,[],e.pos,n)}case`Chain`:return this.resolveFieldChain(this.evalPrimary(e.node,t,n),e.fields,e.pos,n);case`Pipe`:return this.evalPipe(e,t,n);default:throw new Pv(`cannot evaluate ${e.type} as a value`,e.pos,{source:n.source})}}resolveFieldChain(e,t,n,r){let i=Ty(e,t);if(i!==Cy)return i;if(this.missingKey===`error`)throw new zv(t,n,{source:r.source})}resolveVariable(e,t,n,r){let i=e[0]??`$`;if(i===`$`){let i=e.slice(1);return i.length===0?t.root:this.resolveFieldChain(t.root,i,n,r)}let a=ab(t,i);if(!a.found)throw new Pv(`undefined variable ${i}`,n,{source:r.source});let o=e.slice(1);return o.length===0?a.value:this.resolveFieldChain(a.value,o,n,r)}emitFromValue(e,t){if(e==null){t.out.push(this.fromString(`<no value>`));return}if(typeof e==`string`){t.out.push(this.fromString(e));return}if(typeof e==`number`||typeof e==`boolean`||typeof e==`bigint`){t.out.push(this.fromString(String(e)));return}if(this.isT(e)){t.out.push(e);return}t.out.push(this.fromString(eb(e,this.toString,this.isT)))}};const Cb=e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&!(e instanceof Map);function wb(e){return new Sb(e)}function Tb(e,t,n,r,i,a=Ab,o=kb,s=Cb){let{argTypes:c,arity:l}=t,u=Eb(c,l);if(n.length<u.minimum||n.length>u.maximum)throw new Iv(e,u,n.length,r,{source:i});let d=Db(c,l),f=-1,p=-1;for(let t=0;t<n.length;t++){let c=d(t),l=n[t];if(!Ob(c,l,a,s))throw(c===`int`||c===`truncating-int`)&&(typeof l==`number`||typeof l==`bigint`)?new Rv(e,t+1,l,r,{source:i}):new Lv(e,t+1,Fb(c),Lb(l),r,{source:i});if(c===`liftable`&&typeof l==`string`&&(n[t]=o(l)),c===`truncating-int`?n[t]=Math.trunc(Number(l)):(c===`int`||c===`float`)&&(n[t]=Number(l)),c===`ordered`){if(f===-1)f=t;else if(!Mb(n[f],l))throw new Lv(e,t+1,`${Fb(`ordered`)} of the same kind as ${Lb(n[f])}`,Lb(l),r,{source:i})}if(c===`comparable`){if(p===-1)p=t;else if(!Nb(n[p],l))throw new Lv(e,t+1,`${Fb(`comparable`)} of the same kind as ${Lb(n[p])}`,Lb(l),r,{source:i})}}}function Eb(e,t){switch(t.kind){case`exact`:return{minimum:e.length,maximum:e.length};case`variadic`:return{minimum:e.length-1,maximum:1/0};case`alternating`:return{minimum:t.minimum,maximum:1/0}}}function Db(e,t){let n=e.length;switch(t.kind){case`exact`:return t=>e[t];case`variadic`:return t=>e[Math.min(t,n-1)];case`alternating`:return t=>e[t%n]}}function Ob(e,t,n,r){switch(e){case`truthy`:case`reflective`:case`value`:return!0;case`string`:return typeof t==`string`;case`int`:return typeof t==`number`&&Number.isSafeInteger(t)||typeof t==`bigint`&&Number.isSafeInteger(Number(t));case`truncating-int`:return typeof t==`number`&&Number.isFinite(t)||typeof t==`bigint`&&Number.isSafeInteger(Number(t));case`float`:return typeof t==`number`||typeof t==`bigint`&&Number.isFinite(Number(t));case`bool`:return typeof t==`boolean`;case`ordered`:return typeof t==`string`||typeof t==`number`||typeof t==`bigint`||typeof t==`boolean`;case`T`:return r(t);case`list`:return Array.isArray(t);case`dict`:return nb(t);case`sized`:return typeof t==`string`||Array.isArray(t)||t instanceof Map||t instanceof Set||nb(t);case`comparable`:return t==null||typeof t==`string`||typeof t==`number`||typeof t==`bigint`||typeof t==`boolean`||Array.isArray(t)||t instanceof Map||t instanceof Set||nb(t);case`callable`:return typeof t==`function`;case`collection`:return typeof t==`string`||Array.isArray(t)||t instanceof Map||nb(t);case`index-key`:return typeof t==`string`||typeof t==`number`||typeof t==`bigint`;case`sliceable`:return typeof t==`string`||Array.isArray(t);case`stringifiable`:if(typeof t==`string`)return!0;try{return n(t),!0}catch{return!1}case`liftable`:return typeof t==`string`||r(t);case`serializable`:return jb(t);default:throw Error(`invalid ArgType: ${String(e)}`)}}function kb(e){return e}function Ab(e){if(typeof e==`string`)return e;if(e==null)return`<nil>`;if(typeof e==`number`||typeof e==`bigint`||typeof e==`boolean`)return String(e);throw new Lv(`<engine.toString>`,1,`string (or a consumer-supplied toString that flattens T)`,Lb(e),{line:0,column:0,offset:0})}function jb(e){try{return JSON.stringify(e)!==void 0}catch{return!1}}function Mb(e,t){return typeof e==typeof t||typeof e==`number`&&typeof t==`bigint`||typeof e==`bigint`&&typeof t==`number`}function Nb(e,t){let n=Pb(e),r=Pb(t);return n===`nil`||r===`nil`?!0:n===r}function Pb(e){return e==null?`nil`:typeof e==`string`?`string`:typeof e==`number`||typeof e==`bigint`?`number`:typeof e==`boolean`?`boolean`:Array.isArray(e)?`array`:e instanceof Map?`map`:e instanceof Set?`set`:`object`}function Fb(e){switch(e){case`int`:return`integer (safe-integer number or bigint)`;case`truncating-int`:return`integer (finite number, truncated toward zero, or safe-integer bigint)`;case`float`:return`float (number, including NaN/Infinity, or finite-convertible bigint)`;case`T`:return`T (consumer-defined fragment)`;case`ordered`:return`orderable primitive`;case`list`:return`list`;case`dict`:return`dict (plain object)`;case`sized`:return`sized value (string, list, map, set, or dict)`;case`comparable`:return`comparable value (orderable primitive, nil, list, dict, Map, or Set)`;case`stringifiable`:return`stringifiable value (string or convertible via the engine's toString)`;case`liftable`:return`liftable value (T or string, the latter lifted via the engine's fromString)`;case`callable`:return`callable (function value)`;case`collection`:return`collection (string, array, Map, or dict)`;case`index-key`:return`index key (number, bigint, or string)`;case`sliceable`:return`sliceable value (string or array)`;case`serializable`:return`JSON-serializable value`;case`truthy`:case`reflective`:case`value`:case`string`:case`bool`:return e;default:throw Error(`invalid ArgType: ${String(e)}`)}}function Ib(e){return e instanceof Error?e.message:String(e)}function Lb(e){return e===null?`null`:e===void 0?`undefined`:Array.isArray(e)?`array`:e instanceof Map?`Map`:typeof e}function Rb(e){return e==null?[]:Array.isArray(e)?e.map((e,t)=>[t,e]):typeof e==`string`?[...e].map((e,t)=>[t,e]):e instanceof Map?zb([...e.entries()]):e instanceof Set?[...e.values()].map((e,t)=>[t,e]):typeof e==`object`?zb(Object.entries(e)):[]}function zb(e){return[...e].sort((e,t)=>Bb(e[0],t[0]))}function Bb(e,t){if((typeof e==`number`||typeof e==`bigint`)&&(typeof t==`number`||typeof t==`bigint`)){let n=typeof e==`bigint`?Number(e):e,r=typeof t==`bigint`?Number(t):t;return n===r?0:n<r?-1:1}let n=String(e),r=String(t);return n===r?0:n<r?-1:1}function Vb(e){if(e.intValue!==void 0){let t=e.intValue;return t>=BigInt(-(2**53-1))&&t<=BigInt(2**53-1)?Number(t):t}if(e.floatValue!==void 0)return e.floatValue;if(e.complexValue!==void 0)return e.complexValue;throw Error(`internal: NumberNode has none of intValue/floatValue/complexValue — parser invariant violated`)}function Hb(e){if(!/^[+-]?\d+$/.test(e))return 0;let t=Number.parseInt(e,10);return Number.isSafeInteger(t)?t:0}function Ub(e){if(typeof e==`number`)return e;if(typeof e==`bigint`)return Number(e);if(typeof e==`string`){let t=Number.parseFloat(e);return Number.isNaN(t)?0:t}return typeof e==`boolean`?+!!e:0}function Wb(e){if(e===``)return null;let t=1,n=e;return n[0]===`+`?n=n.slice(1):n[0]===`-`&&(t=-1,n=n.slice(1)),n===``?null:/^0x[0-9a-fA-F]+$/i.test(n)?{sign:t,digits:n.slice(2),base:16}:/^0b[01]+$/i.test(n)?{sign:t,digits:n.slice(2),base:2}:/^0o[0-7]+$/i.test(n)?{sign:t,digits:n.slice(2),base:8}:n===`0`?{sign:t,digits:`0`,base:10}:n[0]===`0`?/^0[0-7]+$/.test(n)?{sign:t,digits:n.slice(1),base:8}:null:/^[0-9]+$/.test(n)?{sign:t,digits:n,base:10}:null}function Gb(e){if(typeof e==`number`){let t=Math.trunc(e);return Number.isSafeInteger(t)?t:0}if(typeof e==`bigint`){let t=Number(e);return Number.isSafeInteger(t)?t:0}if(typeof e==`string`){let t=Wb(e);if(t===null)return 0;let n=t.sign*Number.parseInt(t.digits,t.base);return Number.isSafeInteger(n)?n:0}return typeof e==`boolean`?+!!e:0}function Kb(e){if(typeof e==`bigint`)return e;if(typeof e==`number`)return BigInt(Math.trunc(e));if(typeof e==`string`){let t=Wb(e);if(t===null)return 0n;let n=t.base===16?`0x`:t.base===2?`0b`:t.base===8?`0o`:``,r=BigInt(n+t.digits);return t.sign===-1?-r:r}return typeof e==`boolean`&&e?1n:0n}function qb(e){if(!/^[+-]?[0-7]+$/.test(e))return 0;let t=e[0]===`-`?-1:1,n=e[0]===`+`||e[0]===`-`?e.slice(1):e,r=t*Number.parseInt(n,8);return Number.isSafeInteger(r)?r:0}function Jb(e){return JSON.stringify(e)??`null`}function Yb(){return{atoi:{fn:e=>Hb(e),argTypes:[`string`],arity:{kind:`exact`},returnType:`int`},int:{fn:e=>Gb(e),argTypes:[`value`],arity:{kind:`exact`},returnType:`int`},int64:{fn:e=>Kb(e),argTypes:[`value`],arity:{kind:`exact`}},float64:{fn:e=>Ub(e),argTypes:[`value`],arity:{kind:`exact`},returnType:`float`},toDecimal:{fn:e=>qb(e),argTypes:[`string`],arity:{kind:`exact`},returnType:`int`},toRawJson:{fn:e=>Jb(e),argTypes:[`serializable`],arity:{kind:`exact`},returnType:`string`}}}const Xb={h:36e11,m:6e10,s:1e9,ms:1e6,us:1e3,µs:1e3,ns:1};function Zb(e){if(e===`0`)return 0;let t=!1,n=e;if(n.startsWith(`-`)?(t=!0,n=n.slice(1)):n.startsWith(`+`)&&(n=n.slice(1)),!n)return NaN;let r=0,i=/^(\d+(?:\.\d+)?)(ns|µs|us|ms|[smh])/;for(;n.length>0;){let e=i.exec(n);if(!e)return NaN;let t=parseFloat(e[1]??`0`),a=e[2];r+=t*Xb[a],n=n.slice(e[0].length)}return t?-r:r}function Qb(e){if(e===0)return`0s`;let t=!1,n=e;n<0&&(t=!0,n=-n);let r;return r=n<Xb.us?`${Math.floor(n)}ns`:n<Xb.ms?$b(n,Xb.us,3,`µs`):n<Xb.s?$b(n,Xb.ms,6,`ms`):ex(n),t?`-${r}`:r}function $b(e,t,n,r){let i=Math.floor(e/t),a=Math.round(e%t);return a===0?`${i}${r}`:`${i}.${String(a).padStart(n,`0`).replace(/0+$/,``)}${r}`}function ex(e){let t=Math.floor(e/Xb.h);e-=t*Xb.h;let n=Math.floor(e/Xb.m);e-=n*Xb.m;let r=Math.floor(e/Xb.s),i=e-r*Xb.s,a=i===0?`${r}s`:`${r}.${String(Math.round(i)).padStart(9,`0`).replace(/0+$/,``)}s`;return t>0?`${t}h${n}m${a}`:n>0?`${n}m${a}`:a}function tx(e){return e*Xb.s}function nx(e){if(e instanceof Date)return e;if(typeof e==`bigint`)return new Date(Number(e)*1e3);if(typeof e==`number`)return new Date(e*1e3);if(typeof e==`string`){let t=new Date(e);if(!Number.isNaN(t.getTime()))return t;throw Error(`sprig: cannot parse date value ${JSON.stringify(e)}`)}throw Error(`sprig: unsupported date type: ${typeof e}`)}function rx(e,t){let n=t().getTime()-nx(e).getTime();return Qb(Math.round(n/1e3)*1e9)}const ix=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],ax=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],ox=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`],sx=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function cx(e){return e<10?`0${e}`:String(e)}function lx(e){return e<10?`00${e}`:e<100?`0${e}`:String(e)}function ux(e){return e<10?` ${e}`:String(e)}function dx(e){let t=e>=0?`+`:`-`,n=Math.abs(e);return`${t}${cx(Math.floor(n/60))}${cx(n%60)}`}function fx(e){let t=e>=0?`+`:`-`,n=Math.abs(e);return`${t}${cx(Math.floor(n/60))}:${cx(n%60)}`}function px(e){return`${e>=0?`+`:`-`}${cx(Math.floor(Math.abs(e)/60))}`}function mx(e){return e===0?`Z`:dx(e)}function hx(e){return e===0?`Z`:fx(e)}function gx(e){return e===0?`Z`:px(e)}function _x(e,t,n){let r=e*1e6,i=String(r).padStart(9,`0`).slice(0,t);return n?i.replace(/0+$/,``):i}const vx=[[`.000000000`,e=>`.${_x(e.ms,9,!1)}`],[`.999999999`,e=>{let t=_x(e.ms,9,!0);return t?`.${t}`:``}],[`.000000`,e=>`.${_x(e.ms,6,!1)}`],[`.999999`,e=>{let t=_x(e.ms,6,!0);return t?`.${t}`:``}],[`.000`,e=>`.${lx(e.ms)}`],[`.999`,e=>{let t=lx(e.ms).replace(/0+$/,``);return t?`.${t}`:``}],[`January`,e=>ix[e.month-1]??`January`],[`Monday`,e=>ox[e.weekday]??`Monday`],[`Z07:00`,e=>hx(e.offsetMinutes)],[`-07:00`,e=>fx(e.offsetMinutes)],[`Z0700`,e=>mx(e.offsetMinutes)],[`-0700`,e=>dx(e.offsetMinutes)],[`2006`,e=>String(e.year)],[`Jan`,e=>ax[e.month-1]??`Jan`],[`Mon`,e=>sx[e.weekday]??`Mon`],[`MST`,e=>e.tzAbbr],[`-07`,e=>px(e.offsetMinutes)],[`Z07`,e=>gx(e.offsetMinutes)],[`15`,e=>cx(e.hour)],[`01`,e=>cx(e.month)],[`02`,e=>cx(e.day)],[`_2`,e=>ux(e.day)],[`03`,e=>cx(e.hour12)],[`04`,e=>cx(e.minute)],[`05`,e=>cx(e.second)],[`06`,e=>cx(e.year%100)],[`PM`,e=>e.hour>=12?`PM`:`AM`],[`pm`,e=>e.hour>=12?`pm`:`am`],[`1`,e=>String(e.month)],[`2`,e=>String(e.day)],[`3`,e=>String(e.hour12)],[`4`,e=>String(e.minute)],[`5`,e=>String(e.second)]];function yx(e,t){let n=``,r=0;for(;r<e.length;){let i=!1;for(let[a,o]of vx)if(e.startsWith(a,r)){n+=o(t),r+=a.length,i=!0;break}i||(n+=e[r++])}return n}const bx={year:`numeric`,month:`2-digit`,day:`2-digit`,weekday:`long`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1};function xx(e){let t=new Map;for(let n of e)t.set(n.type,n.value);return t}const Sx=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`];function Cx(e,t){let n;try{new Intl.DateTimeFormat(`en-US`,{timeZone:t}),n=t}catch{n=`UTC`}let r=xx(new Intl.DateTimeFormat(`en-US`,{...bx,timeZone:n}).formatToParts(e)),i=parseInt(r.get(`hour`)??`0`,10)%24,a=xx(new Intl.DateTimeFormat(`en-US`,{timeZone:n,timeZoneName:`short`}).formatToParts(e)).get(`timeZoneName`)??n,o=wx(xx(new Intl.DateTimeFormat(`en-US`,{timeZone:n,timeZoneName:`shortOffset`}).formatToParts(e)).get(`timeZoneName`)??`GMT`),s=Sx.indexOf(r.get(`weekday`)??`Sunday`);return{year:parseInt(r.get(`year`)??`2000`,10),month:parseInt(r.get(`month`)??`1`,10),day:parseInt(r.get(`day`)??`1`,10),weekday:s===-1?0:s,hour:i,hour12:i%12||12,minute:parseInt(r.get(`minute`)??`0`,10),second:parseInt(r.get(`second`)??`0`,10),ms:e.getUTCMilliseconds(),tzAbbr:a,offsetMinutes:o}}function wx(e){if(e===`GMT`||e===`UTC`)return 0;let t=e.match(/^GMT([+-])(\d{1,2})(?::(\d{2}))?$/);if(!t)return 0;let n=t[1]===`+`?1:-1,r=parseInt(t[2]??`0`,10),i=parseInt(t[3]??`0`,10);return n*(r*60+i)}function Tx(){return Intl.DateTimeFormat().resolvedOptions().timeZone}function Ex(e,t){return yx(e,Cx(nx(t),Tx()))}function Dx(e,t,n){return yx(e,Cx(nx(t),n))}function Ox(e,t){let n=nx(t),r=Zb(e);return Number.isNaN(r)?n:new Date(n.getTime()+r/1e6)}function kx(e){if(typeof e==`string`){let t=parseInt(e,10);return Number.isNaN(t)?`0s`:Qb(tx(t))}return typeof e==`bigint`?Qb(tx(Number(e))):typeof e==`number`?Qb(tx(e)):`0s`}const Ax=36e11*24*365,jx=36e11*24*30,Mx=36e11*24,Nx=36e11,Px=6e10,Fx=1e9;function Ix(e){let t=Zb(String(e));if(Number.isNaN(t))return`0s`;let n=Math.abs(t);return n>Ax?`${Math.floor(n/Ax)}y`:n>jx?`${Math.floor(n/jx)}mo`:n>Mx?`${Math.floor(n/Mx)}d`:n>Nx?`${Math.floor(n/Nx)}h`:n>Px?`${Math.floor(n/Px)}m`:n>Fx?`${Math.floor(n/Fx)}s`:`0s`}function Lx(e){let t=Cx(nx(e),Tx());return`${t.year}-${String(t.month).padStart(2,`0`)}-${String(t.day).padStart(2,`0`)}`}function Rx(e,t){let n=Cx(nx(e),t);return`${n.year}-${String(n.month).padStart(2,`0`)}-${String(n.day).padStart(2,`0`)}`}function zx(e){return e()}const Bx=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],Vx=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`];function Hx(){return{year:2e3,month:1,day:1,hour:0,minute:0,second:0,ms:0,offsetMinutes:0,isPM:!1,hour12:!1}}function Ux(e,t,n){return[e.slice(t,t+n),t+n]}function Wx(e,t,n,r){let i=t;for(;i<e.length&&i-t<r&&e.charCodeAt(i)>=48&&e.charCodeAt(i)<=57;)i++;if(i-t<n)throw Error(`sprig toDate: expected ${n}-${r} digits at pos ${t}`);return[parseInt(e.slice(t,i),10),i]}function Gx(e,t){for(let[n,r]of Bx.entries())if(e.startsWith(r,t))return[n+1,t+r.length];throw Error(`sprig toDate: expected month name at pos ${t}`)}function Kx(e,t){for(let[n,r]of Vx.entries())if(e.startsWith(r,t))return[n+1,t+r.length];throw Error(`sprig toDate: expected short month name at pos ${t}`)}function qx(e,t){for(let n of[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`])if(e.startsWith(n,t))return t+n.length;throw Error(`sprig toDate: expected weekday name at pos ${t}`)}function Jx(e,t){for(let n of[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`])if(e.startsWith(n,t))return t+n.length;throw Error(`sprig toDate: expected short weekday name at pos ${t}`)}function Yx(e,t){if(e[t]===` `){let[n,r]=Wx(e,t+1,1,1);return[n,r]}return Wx(e,t,1,2)}function Xx(e,t,n){let r=e[t]===`+`?1:e[t]===`-`?-1:0;if(r===0)throw Error(`sprig toDate: expected +/- at pos ${t}`);let i=t+1,[a,o]=Wx(e,i,2,2);i=o;let s=0;if(n&&e[i]===`:`){let[t,n]=Wx(e,i+1,2,2);s=t,i=n}else if(!n){let[t,n]=Wx(e,i,2,2);s=t,i=n}return[r*(a*60+s),i]}function Zx(e,t,n,r){if(e[t]===`Z`)return[0,t+1];if(r){let n=e[t]===`+`?1:e[t]===`-`?-1:0;if(n===0)throw Error(`sprig toDate: expected Z or +/- at pos ${t}`);let[r,i]=Wx(e,t+1,2,2);return[n*r*60,i]}return Xx(e,t,n)}function Qx(e,t){let n=t;for(;n<e.length&&e.charCodeAt(n)>=65&&e.charCodeAt(n)<=90;)n++;if(n===t)throw Error(`sprig toDate: expected timezone abbreviation at pos ${t}`);return n}function $x(e,t,n){let[r,i]=Ux(e,t,n),a=parseInt(r.padEnd(9,`0`),10);return[Math.round(a/1e6),i]}function eS(e,t,n,r){let i={...r};switch(e){case`January`:{let[e,r]=Gx(t,n);return i.month=e,[r,i]}case`Monday`:return[qx(t,n),i];case`Jan`:{let[e,r]=Kx(t,n);return i.month=e,[r,i]}case`Mon`:return[Jx(t,n),i];case`2006`:{let[e,r]=Wx(t,n,4,4);return i.year=e,[r,i]}case`06`:{let[e,r]=Wx(t,n,2,2);return i.year=e<70?2e3+e:1900+e,[r,i]}case`01`:{let[e,r]=Wx(t,n,2,2);return i.month=e,[r,i]}case`1`:{let[e,r]=Wx(t,n,1,2);return i.month=e,[r,i]}case`_2`:{let[e,r]=Yx(t,n);return i.day=e,[r,i]}case`02`:{let[e,r]=Wx(t,n,2,2);return i.day=e,[r,i]}case`2`:{let[e,r]=Wx(t,n,1,2);return i.day=e,[r,i]}case`15`:{let[e,r]=Wx(t,n,2,2);return i.hour=e,[r,i]}case`03`:{let[e,r]=Wx(t,n,2,2);return i.hour=e,i.hour12=!0,[r,i]}case`3`:{let[e,r]=Wx(t,n,1,2);return i.hour=e,i.hour12=!0,[r,i]}case`04`:{let[e,r]=Wx(t,n,2,2);return i.minute=e,[r,i]}case`4`:{let[e,r]=Wx(t,n,1,2);return i.minute=e,[r,i]}case`05`:{let[e,r]=Wx(t,n,2,2);return i.second=e,[r,i]}case`5`:{let[e,r]=Wx(t,n,1,2);return i.second=e,[r,i]}case`PM`:case`pm`:{let e=t.slice(n,n+2).toLowerCase();if(e!==`am`&&e!==`pm`)throw Error(`sprig toDate: expected AM/PM at pos ${n}, got ${JSON.stringify(t.slice(n,n+2))}`);return i.isPM=e===`pm`,i.hour12=!0,[n+2,i]}case`MST`:return[Qx(t,n),i];case`-0700`:{let[e,r]=Xx(t,n,!1);return i.offsetMinutes=e,[r,i]}case`-07:00`:{let[e,r]=Xx(t,n,!0);return i.offsetMinutes=e,[r,i]}case`-07`:{let e=t[n]===`+`?1:t[n]===`-`?-1:0;if(e===0)throw Error(`sprig toDate: expected +/- at pos ${n}`);let[r,a]=Wx(t,n+1,2,2);return i.offsetMinutes=e*r*60,[a,i]}case`Z0700`:{let[e,r]=Zx(t,n,!1,!1);return i.offsetMinutes=e,[r,i]}case`Z07:00`:{let[e,r]=Zx(t,n,!0,!1);return i.offsetMinutes=e,[r,i]}case`Z07`:{let[e,r]=Zx(t,n,!1,!0);return i.offsetMinutes=e,[r,i]}case`.000000000`:{if(t[n]!==`.`)throw Error(`sprig toDate: expected . at pos ${n}`);let[e,r]=$x(t,n+1,9);return i.ms=e,[r,i]}case`.999999999`:{if(t[n]!==`.`)return[n,i];let e=n+1,r=e;for(;r<t.length&&t.charCodeAt(r)>=48&&t.charCodeAt(r)<=57;)r++;let a=t.slice(e,r).padEnd(9,`0`);return i.ms=Math.round(parseInt(a,10)/1e6),[r,i]}case`.000000`:{if(t[n]!==`.`)throw Error(`sprig toDate: expected . at pos ${n}`);let[e,r]=$x(t,n+1,6);return i.ms=e,[r,i]}case`.999999`:{if(t[n]!==`.`)return[n,i];let e=n+1,r=e;for(;r<t.length&&t.charCodeAt(r)>=48&&t.charCodeAt(r)<=57;)r++;let a=t.slice(e,r).padEnd(9,`0`);return i.ms=Math.round(parseInt(a,10)/1e6),[r,i]}case`.000`:{if(t[n]!==`.`)throw Error(`sprig toDate: expected . at pos ${n}`);let[e,r]=$x(t,n+1,3);return i.ms=e,[r,i]}case`.999`:{if(t[n]!==`.`)return[n,i];let e=n+1,r=e;for(;r<t.length&&t.charCodeAt(r)>=48&&t.charCodeAt(r)<=57;)r++;let a=t.slice(e,r).padEnd(3,`0`);return i.ms=parseInt(a,10),[r,i]}}throw Error(`sprig toDate: unhandled token ${e}`)}const tS=`.000000000,.999999999,.000000,.999999,.000,.999,January,Monday,Z07:00,-07:00,Z0700,-0700,2006,Jan,Mon,MST,-07,Z07,15,01,02,_2,03,04,05,06,PM,pm,1,2,3,4,5`.split(`,`);function nS(e,t){let n=0,r=0,i=Hx();for(;n<e.length;){let a=!1;for(let o of tS)if(e.startsWith(o,n)){let[e,s]=eS(o,t,r,i);r=e,i=s,n+=o.length,a=!0;break}if(!a){let i=e.charAt(n);if(t[r]!==i)throw Error(`sprig toDate: expected ${JSON.stringify(i)} at pos ${r}, got ${JSON.stringify(t[r])}`);n++,r++}}if(r!==t.length)throw Error(`sprig toDate: extra characters at pos ${r}: ${JSON.stringify(t.slice(r))}`);if(i.hour12){let e=i.hour%12;i.hour=i.isPM?e+12:e}let a=Date.UTC(i.year,i.month-1,i.day,i.hour,i.minute,i.second,i.ms)-i.offsetMinutes*60*1e3;return new Date(a)}function rS(e,t){return nS(e,t)}function iS(e){return String(Math.floor(nx(e).getTime()/1e3))}function aS(e=()=>new Date){return{now:{fn:()=>zx(e),argTypes:[],arity:{kind:`exact`}},date:{fn:(e,t)=>Ex(e,t),argTypes:[`string`,`value`],arity:{kind:`exact`}},dateInZone:{fn:(e,t,n)=>Dx(e,t,n),argTypes:[`string`,`value`,`string`],arity:{kind:`exact`}},dateModify:{fn:(e,t)=>Ox(e,t),argTypes:[`string`,`value`],arity:{kind:`exact`}},htmlDate:{fn:e=>Lx(e),argTypes:[`value`],arity:{kind:`exact`}},htmlDateInZone:{fn:(e,t)=>Rx(e,t),argTypes:[`value`,`string`],arity:{kind:`exact`}},duration:{fn:e=>kx(e),argTypes:[`value`],arity:{kind:`exact`}},durationRound:{fn:e=>Ix(e),argTypes:[`value`],arity:{kind:`exact`}},toDate:{fn:(e,t)=>rS(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},ago:{fn:t=>rx(t,e),argTypes:[`value`],arity:{kind:`exact`}},unixEpoch:{fn:e=>iS(e),argTypes:[`value`],arity:{kind:`exact`}}}}function oS(e){return e==null||e===!1?!0:typeof e==`number`?e===0||Number.isNaN(e):typeof e==`bigint`?e===0n:typeof e==`string`||Array.isArray(e)?e.length===0:e instanceof Map||e instanceof Set?e.size===0:typeof e==`object`?Object.keys(e).length===0:!1}function sS(...e){for(let t of e)if(!oS(t))return t}function cS(e,t){return oS(t)?e:t}function lS(e){return JSON.parse(e)}function uS(e,t,n){return Ay(n)?e:t}function dS(e){return JSON.stringify(e)??`null`}function fS(e){return JSON.stringify(e,null,2)??`null`}function pS(){return{default:{fn:(e,t)=>cS(e,t),argTypes:[`value`,`truthy`],arity:{kind:`variadic`}},empty:{fn:e=>oS(e),argTypes:[`truthy`],arity:{kind:`exact`}},coalesce:{fn:(...e)=>sS(...e),argTypes:[`truthy`],arity:{kind:`variadic`}},ternary:{fn:(e,t,n)=>uS(e,t,n),argTypes:[`value`,`value`,`truthy`],arity:{kind:`exact`}},fromJson:{fn:e=>lS(e),argTypes:[`string`],arity:{kind:`exact`}},toJson:{fn:e=>dS(e),argTypes:[`serializable`],arity:{kind:`exact`},returnType:`string`},toPrettyJson:{fn:e=>fS(e),argTypes:[`serializable`],arity:{kind:`exact`},returnType:`string`}}}function mS(...e){let t={};for(let n=0;n<e.length;n+=2)t[e[n]]=e[n+1];return t}function hS(e){if(e.kind!==`call`||e.name!==`dict`||e.args.length%2!=0)return null;let t=[];for(let[n,r]of e.args.entries()){if(r.kind!==`literal`||n%2==0&&typeof r.value!=`string`)return null;t.push(r.value)}return mS(...t)}function gS(e,t){return e[t]}function _S(e,t){return t in e}function vS(e){return Object.keys(e)}function yS(e,...t){let n={...e};for(let e of t)for(let[t,r]of Object.entries(e))t in n||(n[t]=r);return n}function bS(e,...t){let n={...e};for(let e of t)Object.assign(n,e);return n}function xS(e,...t){let n=new Set(t),r={};for(let[t,i]of Object.entries(e))n.has(t)||(r[t]=i);return r}function SS(e,...t){let n={};for(let r of t)r in e&&(n[r]=e[r]);return n}function CS(e,...t){let n=[];for(let r of t)e in r&&n.push(r[e]);return n}function wS(e,t,n){return e[t]=n,e}function TS(e,t){return delete e[t],e}function ES(e){return Object.values(e)}function DS(){return{dict:{fn:(...e)=>mS(...e),argTypes:[`string`,`value`],arity:{kind:`alternating`,minimum:0}},get:{fn:(e,t)=>gS(e,t),argTypes:[`dict`,`string`],arity:{kind:`exact`}},set:{fn:(e,t,n)=>wS(e,t,n),argTypes:[`dict`,`string`,`value`],arity:{kind:`exact`}},unset:{fn:(e,t)=>TS(e,t),argTypes:[`dict`,`string`],arity:{kind:`exact`}},keys:{fn:e=>vS(e),argTypes:[`dict`],arity:{kind:`variadic`}},values:{fn:e=>ES(e),argTypes:[`dict`],arity:{kind:`exact`}},pluck:{fn:(e,...t)=>CS(e,...t),argTypes:[`string`,`dict`],arity:{kind:`variadic`}},pick:{fn:(e,...t)=>SS(e,...t),argTypes:[`dict`,`string`],arity:{kind:`variadic`}},omit:{fn:(e,...t)=>xS(e,...t),argTypes:[`dict`,`string`],arity:{kind:`variadic`}},hasKey:{fn:(e,t)=>_S(e,t),argTypes:[`dict`,`string`],arity:{kind:`exact`}},merge:{fn:(e,...t)=>yS(e,...t),argTypes:[`dict`,`dict`],arity:{kind:`variadic`}},mergeOverwrite:{fn:(e,...t)=>bS(e,...t),argTypes:[`dict`,`dict`],arity:{kind:`variadic`}}}}function OS(e){throw new Bv(e)}function kS(){return{fail:{fn:e=>OS(e),argTypes:[`string`],arity:{kind:`exact`}}}}new TextEncoder,new Map(Array.from(`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`).map((e,t)=>[e,t])),new TextDecoder,new TextEncoder,new TextDecoder,new TextEncoder;function AS(...e){for(let t of e)if(oS(t))return!1;return!0}function jS(...e){for(let t of e)if(!oS(t))return!0;return!1}function MS(e,t){return[...e,t]}function NS(e,t){let n=Math.max(1,e),r=[];for(let e=0;e<t.length;e+=n)r.push(t.slice(e,e+n));return r}function PS(e){return e.filter(e=>!oS(e))}function FS(...e){let t=[];for(let n of e)t.push(...n);return t}const IS={line:0,column:0,offset:0};function LS(e,t,n,r){return new Lv(e,t,n,r,IS)}function RS(...e){if(e.length<3)throw LS(`dig`,0,`at least 3 arguments (...keys, default, dict)`,`${e.length} argument${e.length===1?``:`s`}`);let t=e[e.length-1],n=e[e.length-2],r=e.slice(0,-2);if(!BS(t))throw LS(`dig`,e.length-1,`dict`,VS(t));for(let e=0;e<r.length;e++)if(typeof r[e]!=`string`)throw LS(`dig`,e,`string`,VS(r[e]));return zS(t,n,r,e.length)}function zS(e,t,n,r){let i=n[0];if(!Object.hasOwn(e,i))return t;let a=e[i];if(n.length===1)return a;if(!BS(a))throw LS(`dig`,r-1,`dict at intermediate key`,VS(a));return zS(a,t,n.slice(1),r)}function BS(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&!(e instanceof Map)&&!(e instanceof Set)}function VS(e){return e===null?`null`:Array.isArray(e)?`array`:e instanceof Map?`Map`:e instanceof Set?`Set`:typeof e}function HS(e){return e[0]}function US(e,t){return t.some(t=>Ey(t,e))}function WS(e){return e.slice(0,-1)}function GS(e){return e[e.length-1]}function KS(e){return Array.isArray(e)||typeof e==`string`?e.length:e instanceof Map||e instanceof Set?e.size:Object.keys(e).length}function qS(...e){return e}function JS(e,t){return[t,...e]}function YS(e){return e.slice(1)}function XS(e){return[...e].reverse()}function ZS(e,t,n){let r=t===void 0?0:t,i=n===void 0?e.length:n;return e.slice(r,i)}function QS(e){let t=[];for(let n of e)n!=null&&t.push(String(n));return t.sort()}function $S(e){let t=[];for(let n of e)t.some(e=>Ey(e,n))||t.push(n);return t}function eC(e,...t){return e.filter(e=>!t.some(t=>Ey(t,e)))}function tC(){return{list:{fn:(...e)=>qS(...e),argTypes:[`value`],arity:{kind:`variadic`}},first:{fn:e=>HS(e),argTypes:[`list`],arity:{kind:`exact`}},last:{fn:e=>GS(e),argTypes:[`list`],arity:{kind:`exact`}},rest:{fn:e=>YS(e),argTypes:[`list`],arity:{kind:`exact`}},initial:{fn:e=>WS(e),argTypes:[`list`],arity:{kind:`exact`}},len:{fn:e=>KS(e),argTypes:[`sized`],arity:{kind:`exact`}},reverse:{fn:e=>XS(e),argTypes:[`list`],arity:{kind:`exact`}},uniq:{fn:e=>$S(e),argTypes:[`list`],arity:{kind:`exact`}},without:{fn:(e,...t)=>eC(e,...t),argTypes:[`list`,`value`],arity:{kind:`variadic`}},has:{fn:(e,t)=>US(e,t),argTypes:[`value`,`list`],arity:{kind:`exact`}},compact:{fn:e=>PS(e),argTypes:[`list`],arity:{kind:`exact`}},slice:{fn:(e,t,n)=>ZS(e,t,n),argTypes:[`list`,`truncating-int`],arity:{kind:`variadic`}},concat:{fn:(...e)=>FS(...e),argTypes:[`list`],arity:{kind:`variadic`}},chunk:{fn:(e,t)=>NS(e,t),argTypes:[`int`,`list`],arity:{kind:`exact`}},prepend:{fn:(e,t)=>JS(e,t),argTypes:[`list`,`value`],arity:{kind:`exact`}},append:{fn:(e,t)=>MS(e,t),argTypes:[`list`,`value`],arity:{kind:`exact`}},sortAlpha:{fn:e=>QS(e),argTypes:[`list`],arity:{kind:`exact`},returnType:`list`},push:{fn:(e,t)=>MS(e,t),argTypes:[`list`,`value`],arity:{kind:`exact`}},tuple:{fn:(...e)=>qS(...e),argTypes:[`value`],arity:{kind:`variadic`}},dig:{fn:(...e)=>RS(...e),argTypes:[`value`],arity:{kind:`variadic`}},all:{fn:(...e)=>AS(...e),argTypes:[`truthy`],arity:{kind:`variadic`},returnType:`bool`},any:{fn:(...e)=>jS(...e),argTypes:[`truthy`],arity:{kind:`variadic`},returnType:`bool`}}}function nC(...e){return e.reduce((e,t)=>e+t,0)}function rC(e){return e+1}function iC(e){return e+1}function aC(...e){return e.reduce((e,t)=>e+t,0)}function oC(e){return Math.ceil(e)}function sC(e,t){return Math.trunc(e/t)}function cC(e,...t){return t.reduce((e,t)=>e/t,e)}function lC(e){return Math.floor(e)}function uC(...e){return e.reduce((e,t)=>t>e?t:e,-1/0)}function dC(...e){return e.reduce((e,t)=>Math.max(e,t),-1/0)}function fC(...e){return e.reduce((e,t)=>t<e?t:e,1/0)}function pC(...e){return e.reduce((e,t)=>Math.min(e,t),1/0)}function mC(e,t){return e%t}function hC(...e){return e.reduce((e,t)=>e*t,1)}function gC(...e){return e.reduce((e,t)=>e*t,1)}function _C(e,t=0){let n=10**t;return Math.sign(e)*Math.round(Math.abs(e)*n)/n}function vC(e,t,n){let r=[];if(t<e){if(n>=0)return r;for(let i=e;i>t;i+=n)r.push(i);return r}if(n<=0)return r;for(let i=e;i<t;i+=n)r.push(i);return r}function yC(...e){let t=1;switch(e.length){case 0:return``;case 1:{let n=e[0];return n<1&&(t=-1),vC(1,n+t,t).join(` `)}case 2:{let t=e[0],n=e[1],r=n<t?-1:1;return vC(t,n+r,r).join(` `)}case 3:{let n=e[0],r=e[1],i=e[2];return i<n&&(t=-1,r>0)?``:vC(n,i+t,r).join(` `)}default:return``}}function bC(e,t){return e-t}function xC(e,...t){return t.reduce((e,t)=>e-t,e)}function SC(e){return vC(0,e,e<0?-1:1)}function CC(){return{add:{fn:(...e)=>nC(...e),argTypes:[`truncating-int`],arity:{kind:`variadic`}},sub:{fn:(e,t)=>bC(e,t),argTypes:[`truncating-int`,`truncating-int`],arity:{kind:`exact`}},mul:{fn:(...e)=>hC(...e),argTypes:[`truncating-int`,`truncating-int`],arity:{kind:`variadic`}},div:{fn:(e,t)=>sC(e,t),argTypes:[`truncating-int`,`truncating-int`],arity:{kind:`exact`}},mod:{fn:(e,t)=>mC(e,t),argTypes:[`truncating-int`,`truncating-int`],arity:{kind:`exact`}},min:{fn:(...e)=>fC(...e),argTypes:[`truncating-int`,`truncating-int`],arity:{kind:`variadic`}},max:{fn:(...e)=>uC(...e),argTypes:[`truncating-int`,`truncating-int`],arity:{kind:`variadic`}},floor:{fn:e=>lC(e),argTypes:[`float`],arity:{kind:`exact`}},ceil:{fn:e=>oC(e),argTypes:[`float`],arity:{kind:`exact`}},round:{fn:(e,t)=>_C(e,t),argTypes:[`float`,`int`,`float`],arity:{kind:`variadic`}},addf:{fn:(...e)=>aC(...e),argTypes:[`float`],arity:{kind:`variadic`}},subf:{fn:(e,...t)=>xC(e,...t),argTypes:[`float`,`float`],arity:{kind:`variadic`}},mulf:{fn:(...e)=>gC(...e),argTypes:[`float`,`float`],arity:{kind:`variadic`}},divf:{fn:(e,...t)=>cC(e,...t),argTypes:[`float`,`float`],arity:{kind:`variadic`}},add1:{fn:e=>rC(e),argTypes:[`truncating-int`],arity:{kind:`exact`}},add1f:{fn:e=>iC(e),argTypes:[`float`],arity:{kind:`exact`}},maxf:{fn:(...e)=>dC(...e),argTypes:[`float`,`float`],arity:{kind:`variadic`}},minf:{fn:(...e)=>pC(...e),argTypes:[`float`,`float`],arity:{kind:`variadic`}},biggest:{fn:(...e)=>uC(...e),argTypes:[`truncating-int`,`truncating-int`],arity:{kind:`variadic`}},seq:{fn:(...e)=>yC(...e),argTypes:[`int`],arity:{kind:`variadic`},returnType:`string`},until:{fn:e=>SC(e),argTypes:[`int`],arity:{kind:`exact`},returnType:`list`},untilStep:{fn:(e,t,n)=>vC(e,t,n),argTypes:[`int`,`int`,`int`],arity:{kind:`exact`},returnType:`list`}}}Array.from({length:95},(e,t)=>String.fromCharCode(t+32)).join(``);function wC(e){return Array.from(e)}function TC(e,t){return e===``?wC(t):t.split(e)}function EC(e,t){let n=wC(t);return n.length<=e||e<4?t:`${n.slice(0,e-3).join(``)}...`}function DC(e,t,n){let r=wC(n);return t<7||r.length<t||e<0||e>r.length-t+1?n:`...${r.slice(e,e+t-6).join(``)}...`}const J={Invalid:0,Number:1,UpperCase:2,Alphabet:3,Connector:4,Punct:5,Other:6},OC=/^[-_\s]$/,kC=/^\p{P}$/u,AC=/^\p{L}$/u,jC=/^\p{Lu}$/u,MC=/^\p{N}$/u;function NC(e){return e!==void 0&&OC.test(e)}function PC(e){return e!==void 0&&AC.test(e)}function FC(e){return e!==void 0&&jC.test(e)}function IC(e){return e!==void 0&&MC.test(e)}function LC(e){return e!==void 0&&kC.test(e)}function RC(e,t){if(t>=e.length)return{word:{wt:J.Invalid,text:``},next:t};let n=e[t],r=t+1;if(NC(n)){for(;r<e.length&&NC(e[r]);)r++;return{word:{wt:J.Connector,text:e.slice(t,r).join(``)},next:r}}if(LC(n)){for(;r<e.length&&LC(e[r]);)r++;return{word:{wt:J.Punct,text:e.slice(t,r).join(``)},next:r}}if(FC(n)){if(r>=e.length)return{word:{wt:J.UpperCase,text:n},next:r};if(FC(e[r])){let n=r;for(;n<e.length&&FC(e[n]);)n++;return n<e.length&&PC(e[n])?{word:{wt:J.UpperCase,text:e.slice(t,n-1).join(``)},next:n-1}:{word:{wt:J.UpperCase,text:e.slice(t,n).join(``)},next:n}}if(PC(e[r])){let n=r+1;for(;n<e.length&&PC(e[n])&&!FC(e[n]);)n++;return{word:{wt:J.UpperCase,text:e.slice(t,n).join(``)},next:n}}return{word:{wt:J.UpperCase,text:n},next:r}}if(PC(n)){for(;r<e.length&&PC(e[r])&&!FC(e[r]);)r++;return{word:{wt:J.Alphabet,text:e.slice(t,r).join(``)},next:r}}if(IC(n)){for(;r<e.length&&IC(e[r]);)r++;return{word:{wt:J.Number,text:e.slice(t,r).join(``)},next:r}}for(;r<e.length&&!NC(e[r])&&!PC(e[r])&&!IC(e[r])&&!LC(e[r]);)r++;return{word:{wt:J.Other,text:e.slice(t,r).join(``)},next:r}}function zC(e,t,n){if(t.wt!==J.UpperCase&&t.wt!==J.Connector){e.push(t.text);return}for(let r of t.text)NC(r)?e.push(n):FC(r)?e.push(r.toLowerCase()):e.push(r)}function BC(e,t){if(e.length===0)return``;let n=wC(e),r=[],{word:i,next:a}=RC(n,0);for(;a<n.length;){i.wt!==J.Connector&&zC(r,i,t);let e=i,o=i;if({word:i,next:a}=RC(n,a),e.wt===J.Number){for(;i.wt===J.Alphabet||i.wt===J.Number;)zC(r,i,t),{word:i,next:a}=RC(n,a);i.wt!==J.Invalid&&i.wt!==J.Punct&&i.wt!==J.Connector&&r.push(t);continue}if(e.wt===J.Connector){zC(r,o,t);continue}if(e.wt===J.Punct)continue;if(i.wt!==J.Number){i.wt!==J.Connector&&i.wt!==J.Punct&&r.push(t);continue}if(a>=n.length)continue;let s=i;if({word:i,next:a}=RC(n,a),i.wt!==J.Alphabet){zC(r,s,t),i.wt!==J.Connector&&i.wt!==J.Punct&&r.push(t);continue}for(r.push(t),zC(r,s,t);i.wt===J.Alphabet||i.wt===J.Number;)zC(r,i,t),{word:i,next:a}=RC(n,a);i.wt!==J.Invalid&&i.wt!==J.Connector&&i.wt!==J.Punct&&r.push(t)}return zC(r,i,t),r.join(``).toLowerCase()}function VC(e){if(e.length===0)return``;let t=wC(e),n=[],r=0,i=``;for(;r<t.length;){if(i=t[r],r++,!NC(i)){i=i.toUpperCase();break}n.push(i)}if(r>=t.length)return t.length>0&&n.push(i),n.join(``);for(;r<t.length;){let e=i;if(i=t[r],r++,NC(i)&&NC(e)){n.push(e);continue}NC(e)?i=i.toUpperCase():(i=i.toLowerCase(),n.push(e))}return n.push(i),n.join(``)}function HC(e){return VC(e)}function UC(...e){return e.join(` `)}function WC(e,t){return t.includes(e)}function GC(e,t){return t.startsWith(e)}function KC(e,t){return t.endsWith(e)}function qC(e,t){let n=` `.repeat(Math.max(0,e));return t.split(`
|
|
63
|
+
`?(this.line+=1,this.column=1):this.column+=1}}advanceTo(e){for(;this.offset<e;)this.advanceBy(1)}makeToken(e,t,n,r={}){return Object.freeze({type:e,value:t,pos:n,...r.trimLeft===void 0?{}:{trimLeft:r.trimLeft},...r.trimRight===void 0?{}:{trimRight:r.trimRight}})}};function qv(e){return e===` `||e===` `||e===`\r`||e===`
|
|
64
|
+
`}function Jv(e){return e===`+`||e===`-`}function Yv(e){return e>=`0`&&e<=`9`}function Xv(e){return Yv(e)||e>=`a`&&e<=`f`||e>=`A`&&e<=`F`}function Zv(e){return e>=`0`&&e<=`7`}function Qv(e){return e===`0`||e===`1`}function $v(e){return e>=`a`&&e<=`z`||e>=`A`&&e<=`Z`}function ey(e){return $v(e)||e===`_`}function ty(e){return ey(e)||Yv(e)}let ny,ry;function iy(e,t){return ry(e,t)}var ay=class e{static EMPTY=new e(new Map,void 0);#e;#t;constructor(e,t){this.#e=e,this.#t=t}static{ny=(t,n)=>new e(t,n),ry=(e,t)=>e.#e.get(t)??(e.#t&&ry(e.#t,t))}has(e){return ry(this,e)!==void 0}};function oy(e,t,n=ay.EMPTY){return new sy(e,t,n).parseTemplate()}var sy=class{lex;buf=[];defines=new Map;inherit;source;rangeDepth=0;constructor(e,t,n){this.source=e,this.inherit=n,this.lex=t?new Kv(e,t):new Kv(e)}peek(e=0){for(;this.buf.length<=e;)this.buf.push(this.lex.next());return this.buf[e]}next(){return this.buf.length>0?this.buf.shift():this.lex.next()}expect(e,t){let n=this.next();if(n.type!==e)throw this.errAt(n,`expected ${t}`,{expected:t,found:uy(n)});return n}errAt(e,t,n={}){return new Mv(t,e.pos,{...n,source:this.source})}parseTemplate(){let e=this.parseList();if(this.peek().type!==`EOF`){let e=this.peek(),t=this.peek(1);if(e.type===`LeftDelim`&&(t.type===`Else`||t.type===`End`)){let n=t.type===`Else`?`else`:`end`;throw this.errAt(e,`unexpected \`{{${n}}}\` outside of \`if\`, \`range\`, \`with\`, or \`block\``,{found:`{{${n}}}`})}throw this.errAt(e,`unexpected ${uy(e)}`,{found:uy(e)})}return{root:e,defines:ny(this.defines,this.inherit),ownDefines:this.defines,source:this.source}}parseList(){let e=this.peek().pos,t=[];for(;;){let n=this.peek();if(n.type===`EOF`)break;if(n.type===`Text`){this.next(),t.push({type:`Text`,pos:n.pos,text:n.value});continue}if(n.type===`Comment`){this.next();let e=ly(n);t.push({type:`Comment`,pos:n.pos,text:n.value,trim:e});continue}if(n.type===`LeftDelim`){let n=this.peek(1).type;if(n===`Else`||n===`End`)return cy(e,t);let r=this.parseAction();r!==null&&t.push(r);continue}throw this.errAt(n,`unexpected ${uy(n)} at top level`,{found:uy(n)})}return cy(e,t)}parseAction(){let e=this.expect(`LeftDelim`,"`{{`"),t=e.trimLeft===!0,n=this.peek();switch(n.type){case`If`:return this.next(),this.parseBranch(`If`,e.pos,t);case`Range`:return this.next(),this.parseBranch(`Range`,e.pos,t);case`With`:return this.next(),this.parseBranch(`With`,e.pos,t);case`Break`:return this.next(),this.parseBreakOrContinue(`Break`,e.pos,t);case`Continue`:return this.next(),this.parseBreakOrContinue(`Continue`,e.pos,t);case`Template`:return this.next(),this.parseTemplateInvocation(e.pos,t);case`Block`:return this.next(),this.parseBlock(e.pos,t);case`Define`:return this.next(),this.parseDefine(e.pos,t),null;case`RightDelim`:throw this.errAt(n,`empty action`,{expected:`pipeline`});default:{let n=this.parsePipeline(),r=this.expect(`RightDelim`,"`}}`");return{type:`Action`,pos:e.pos,pipe:n,trim:{trimLeft:t,trimRight:r.trimRight===!0}}}}}parseBranch(e,t,n){let r=this.parsePipeline();this.expect(`RightDelim`,"`}}`"),e===`Range`&&(this.rangeDepth+=1);let i=this.parseList();e===`Range`&&--this.rangeDepth;let a=this.parseElsePart(),o={trimLeft:n,trimRight:a.endConsumed?a.endRight:this.consumeEnd()},s=a.list?{pipe:r,list:i,elseList:a.list,trim:o}:{pipe:r,list:i,trim:o};switch(e){case`If`:return{type:`If`,pos:t,...s};case`Range`:return{type:`Range`,pos:t,...s};case`With`:return{type:`With`,pos:t,...s}}}parseBreakOrContinue(e,t,n){if(this.rangeDepth===0)throw new Mv(`{{${e===`Break`?`break`:`continue`}}} outside of {{range}}`,t,{source:this.source});let r={trimLeft:n,trimRight:this.expect(`RightDelim`,"`}}`").trimRight===!0};return e===`Break`?{type:`Break`,pos:t,trim:r}:{type:`Continue`,pos:t,trim:r}}parseElsePart(){if(this.peek().type!==`LeftDelim`||this.peek(1).type!==`Else`)return{list:void 0,endRight:!1,endConsumed:!1};let e=this.next();if(this.next(),this.peek().type===`If`){this.next();let t=this.parseBranch(`If`,e.pos,e.trimLeft===!0);return{list:{type:`List`,pos:e.pos,nodes:[t]},endRight:t.trim.trimRight,endConsumed:!0}}return this.expect(`RightDelim`,"`}}`"),{list:this.parseList(),endRight:!1,endConsumed:!1}}consumeEnd(){return this.expect(`LeftDelim`,"`{{end}}`"),this.expect(`End`,"`end`"),this.expect(`RightDelim`,"`}}`").trimRight===!0}parseTemplateInvocation(e,t){let n=this.parseQuotedName(),r=this.peek().type===`RightDelim`?void 0:this.parsePipeline(),i={trimLeft:t,trimRight:this.expect(`RightDelim`,"`}}`").trimRight===!0};return r?{type:`Template`,pos:e,name:n,pipe:r,trim:i}:{type:`Template`,pos:e,name:n,trim:i}}parseBlock(e,t){let n=this.parseQuotedName(),r=this.peek().type===`RightDelim`?void 0:this.parsePipeline();this.expect(`RightDelim`,"`}}`");let i=this.rangeDepth;this.rangeDepth=0;let a=this.parseList();this.rangeDepth=i;let o={trimLeft:t,trimRight:this.consumeEnd()};return!this.defines.has(n)&&!this.inherit.has(n)&&this.defines.set(n,{list:a,source:this.source}),r?{type:`Block`,pos:e,name:n,pipe:r,list:a,trim:o}:{type:`Block`,pos:e,name:n,list:a,trim:o}}parseDefine(e,t){let n=this.parseQuotedName();this.expect(`RightDelim`,"`}}`");let r=this.rangeDepth;this.rangeDepth=0;let i=this.parseList();if(this.rangeDepth=r,this.consumeEnd(),this.defines.has(n)||this.inherit.has(n))throw new Mv(`redefinition of template ${JSON.stringify(n)}`,i.pos,{source:this.source});this.defines.set(n,{list:i,source:this.source})}parseQuotedName(){let e=this.next();if(e.type!==`String`)throw this.errAt(e,`expected template name (quoted string)`,{expected:`string`,found:uy(e)});return vy(e.value,e.pos,this.source)}parsePipeline(){let e=this.peek().pos,t=this.tryParseDecls(),n=[this.parseCommand()];for(;this.peek().type===`Pipe`;){this.next();let e=this.peek();if(!dy(e.type))throw this.errAt(e,"missing command after `|`",{expected:`command`,found:uy(e)});n.push(this.parseCommand())}return{type:`Pipe`,pos:e,decls:t?.vars??[],isAssign:t?.isAssign??!1,cmds:n}}tryParseDecls(){if(this.peek().type!==`Variable`)return;let e=1;for(;this.peek(e).type===`Comma`;){if(this.peek(e+1).type!==`Variable`)return;e+=2}let t=this.peek(e).type;if(t!==`Declare`&&t!==`Assign`)return;let n=[fy(this.next())];for(;this.peek().type===`Comma`;)this.next(),n.push(fy(this.expect(`Variable`,`$variable`)));return{vars:n,isAssign:this.next().type===`Assign`}}parseCommand(){let e=this.peek().pos,t=[this.parsePrimary()];for(;dy(this.peek().type);)t.push(this.parsePrimary());return{type:`Command`,pos:e,args:t}}parsePrimary(){let e=this.next();switch(e.type){case`Dot`:return{type:`Dot`,pos:e.pos};case`Field`:return{type:`Field`,pos:e.pos,idents:e.value.slice(1).split(`.`)};case`Variable`:return fy(e);case`Identifier`:return{type:`Identifier`,pos:e.pos,ident:e.value};case`String`:return{type:`String`,pos:e.pos,raw:e.value,value:vy(e.value,e.pos,this.source)};case`Number`:return my(e);case`Char`:return hy(e,this.source);case`Bool`:return{type:`Bool`,pos:e.pos,value:e.value===`true`};case`Nil`:return{type:`Nil`,pos:e.pos};case`LeftParen`:return this.parseChainOrPipe(e.pos);default:throw this.errAt(e,`expected command argument, found ${uy(e)}`,{expected:`command argument`,found:uy(e)})}}parseChainOrPipe(e){let t=this.parsePipeline(),n=this.expect(`RightParen`,"`)`"),r=[],i=n.pos.offset+1,a=this.peek();return a.type===`Field`&&a.pos.offset===i&&(this.next(),r.push(...a.value.slice(1).split(`.`))),r.length===0?t:{type:`Chain`,pos:e,node:t,fields:r}}};function cy(e,t){return{type:`List`,pos:e,nodes:t}}function ly(e){return{trimLeft:e.trimLeft===!0,trimRight:e.trimRight===!0}}function uy(e){return e.type===`EOF`?`end of input`:e.value||e.type}function dy(e){switch(e){case`Dot`:case`Field`:case`Variable`:case`Identifier`:case`String`:case`Number`:case`Char`:case`Bool`:case`Nil`:case`LeftParen`:return!0;default:return!1}}function fy(e){return{type:`Variable`,pos:e.pos,idents:py(e.value)}}function py(e){let t=e.indexOf(`.`);return t===-1?[e]:[e.slice(0,t),...e.slice(t+1).split(`.`)]}function my(e){let t=e.value,n=t.replace(/_/g,``),r=n.toLowerCase().endsWith(`i`),i=r?n.slice(0,-1):n,a=!r&&(i.includes(`.`)||!i.startsWith(`0x`)&&!i.startsWith(`0X`)&&/[eE]/.test(i)||(i.startsWith(`0x`)||i.startsWith(`0X`))&&/[pP]/.test(i)),o=!r&&!a,s={type:`Number`,pos:e.pos,text:t,isInt:o,isUint:!1,isFloat:a,isComplex:r};if(o){let e=gy(i);return{...s,intValue:e}}if(a){let e=_y(i);return{...s,floatValue:e}}let c=_y(i);return{...s,complexValue:[0,c]}}function hy(e,t){let n=yy(e.value,e.pos,t);return{type:`Number`,pos:e.pos,text:e.value,isInt:!0,isUint:!1,isFloat:!1,isComplex:!1,intValue:BigInt(n)}}function gy(e){let t=1n,n=e;return n.startsWith(`+`)?n=n.slice(1):n.startsWith(`-`)&&(t=-1n,n=n.slice(1)),t*BigInt(n)}function _y(e){return Number(e)}function vy(e,t,n){if(e.startsWith("`"))return e.slice(1,-1);let r=``;for(let i=1;i<e.length-1;i++){let a=e[i];if(a!==`\\`){r+=a;continue}let o=e[++i];switch(o){case`n`:r+=`
|
|
65
|
+
`;break;case`t`:r+=` `;break;case`r`:r+=`\r`;break;case`\\`:r+=`\\`;break;case`"`:r+=`"`;break;case`'`:r+=`'`;break;case`a`:r+=`\x07`;break;case`b`:r+=`\b`;break;case`f`:r+=`\f`;break;case`v`:r+=`\v`;break;case`0`:case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:{let t=o+(e[i+1]??``)+(e[i+2]??``);i+=2,r+=String.fromCodePoint(Number.parseInt(t,8));break}case`x`:{let t=(e[i+1]??``)+(e[i+2]??``);i+=2,r+=String.fromCodePoint(Number.parseInt(t,16));break}case`u`:{let t=e.slice(i+1,i+5);i+=4,r+=String.fromCodePoint(Number.parseInt(t,16));break}case`U`:{let t=e.slice(i+1,i+9);i+=8,r+=String.fromCodePoint(Number.parseInt(t,16));break}default:throw new Mv(`bad escape sequence \\${o}`,t,{expected:`valid escape sequence`,found:`\\${o}`,source:n})}}return r}function yy(e,t,n){let r=vy(`"${e.slice(1,-1).replace(/"/g,`\\"`)}"`,t,n);if(r.length===0)throw new Mv(`empty rune literal`,t,{source:n});return r.codePointAt(0)??0}function by(e,t){if(t(e)!==!1)for(let n of xy(e))by(n,t)}function xy(e){switch(e.type){case`Text`:case`Comment`:case`Dot`:case`Nil`:case`Bool`:case`Number`:case`String`:case`Identifier`:case`Field`:case`Variable`:case`Break`:case`Continue`:return[];case`List`:return e.nodes;case`Chain`:return[e.node];case`Command`:return e.args;case`Pipe`:return[...e.decls,...e.cmds];case`Action`:return[e.pipe];case`If`:case`Range`:case`With`:return e.elseList?[e.pipe,e.list,e.elseList]:[e.pipe,e.list];case`Template`:return e.pipe?[e.pipe]:[];case`Block`:return e.pipe?[e.pipe,e.list]:[e.list];default:return Uv(e)}}const Sy=Symbol(`go-template-js.MISSING`);function Cy(e,t){if(e==null)return Sy;if(e instanceof Map)return e.has(t)?e.get(t):Sy;if(Array.isArray(e))return Sy;if(typeof e==`object`){let n=e;return t in n?n[t]:Sy}return Sy}function wy(e,t){let n=e;for(let e of t){if(n===Sy)return Sy;n=Cy(n,e)}return n}function Ty(e,t){if(Object.is(e,t))return!0;if(e===null||t===null||e===void 0||t===void 0||typeof e!=typeof t)return!1;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length?e.every((e,n)=>Ty(e,t[n])):!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(let[n,r]of e)if(!t.has(n)||!Ty(r,t.get(n)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}if(typeof e==`object`&&typeof t==`object`){let n=Object.keys(e),r=Object.keys(t);return n.length===r.length?n.every(n=>Ty(e[n],t[n])):!1}return!1}const Ey=new WeakSet;function Dy(e){return Ey.add(e),e}function Oy(e){return Ey.has(e)}function ky(e){return e==null||e===!1?!1:typeof e==`number`?e!==0&&!Number.isNaN(e):typeof e==`bigint`?e!==0n:typeof e==`string`||Array.isArray(e)?e.length>0:e instanceof Map||e instanceof Set?e.size>0:typeof e==`object`?Object.keys(e).length>0:!!e}function Ay(e,t){return{eq:{fn:(e,...t)=>t.some(t=>Ny(e,t)),argTypes:[`comparable`,`comparable`],arity:{kind:`variadic`}},ne:{fn:(e,t)=>!Ny(e,t),argTypes:[`comparable`,`comparable`],arity:{kind:`exact`}},lt:{fn:(e,t)=>Py(e,t)<0,argTypes:[`ordered`,`ordered`],arity:{kind:`exact`}},le:{fn:(e,t)=>Py(e,t)<=0,argTypes:[`ordered`,`ordered`],arity:{kind:`exact`}},gt:{fn:(e,t)=>Py(e,t)>0,argTypes:[`ordered`,`ordered`],arity:{kind:`exact`}},ge:{fn:(e,t)=>Py(e,t)>=0,argTypes:[`ordered`,`ordered`],arity:{kind:`exact`}},len:{fn:e=>Fy(e),argTypes:[`sized`],arity:{kind:`exact`}},index:{fn:(e,...t)=>{let n=e;for(let e of t)n=Iy(n,e);return n},argTypes:[`collection`,`index-key`],arity:{kind:`variadic`}},slice:{fn:(e,...t)=>Ry(e,t),argTypes:[`sliceable`,`int`],arity:{kind:`variadic`}},print:{fn:(...t)=>Vy(t,e),argTypes:[`stringifiable`],arity:{kind:`variadic`},returnType:`string`},println:{fn:(...t)=>`${Vy(t,e)}\n`,argTypes:[`stringifiable`],arity:{kind:`variadic`},returnType:`string`},printf:{fn:(n,...r)=>Xy(n,r,e,t),argTypes:[`string`,`stringifiable`],arity:{kind:`variadic`},returnType:`string`},toString:{fn:n=>$y(n,e,t),argTypes:[`value`],arity:{kind:`exact`},returnType:`string`},toStrings:{fn:n=>n.map(n=>$y(n,e,t)),argTypes:[`list`],arity:{kind:`exact`}},call:{fn:(e,...t)=>e(...t),argTypes:[`callable`,`value`],arity:{kind:`variadic`}},html:{fn:(...t)=>Wy(Vy(t,e)),argTypes:[`stringifiable`],arity:{kind:`variadic`},returnType:`string`},js:{fn:(...t)=>qy(Vy(t,e)),argTypes:[`stringifiable`],arity:{kind:`variadic`},returnType:`string`},urlquery:{fn:(...t)=>Yy(Vy(t,e)),argTypes:[`stringifiable`],arity:{kind:`variadic`},returnType:`string`},not:{fn:e=>!ky(e),argTypes:[`truthy`],arity:{kind:`exact`}}}}function jy(){return{and:Dy({argTypes:[`truthy`,`truthy`],arity:{kind:`variadic`},fn:(...e)=>{let t=!0;for(let n of e)if(t=n(),!ky(t))return t;return t}}),or:Dy({argTypes:[`truthy`,`truthy`],arity:{kind:`variadic`},fn:(...e)=>{let t=!1;for(let n of e)if(t=n(),ky(t))return t;return t}})}}function My(e,t){return{...Ay(e,t),...jy()}}function Ny(e,t){return typeof e==`number`&&typeof t==`bigint`?BigInt(e)===t:typeof e==`bigint`&&typeof t==`number`?e===BigInt(t):Ty(e,t)}function Py(e,t){if(typeof e==`bigint`&&typeof t==`bigint`)return e===t?0:e<t?-1:1;if(typeof e==`bigint`||typeof t==`bigint`){let n=typeof e==`bigint`?e:BigInt(Math.trunc(Number(e))),r=typeof t==`bigint`?t:BigInt(Math.trunc(Number(t)));return n===r?0:n<r?-1:1}let n=e,r=t;return n===r?0:n<r?-1:1}function Fy(e){return typeof e==`string`||Array.isArray(e)?e.length:e instanceof Map||e instanceof Set?e.size:Object.keys(e).length}function Iy(e,t){if(Array.isArray(e)||typeof e==`string`){let n=Ly(t,e.length);if(n===e.length)throw Error(`index out of range: ${n}`);return e[n]}if(e instanceof Map)return e.get(t);if(typeof e==`object`&&e){if(typeof t!=`string`)throw Error(`index: object index must be string, got ${zy(t)}`);return e[t]}throw Error(`index: cannot index ${zy(e)}`)}function Ly(e,t){let n=typeof e==`bigint`?Number(e):e;if(typeof n!=`number`||!Number.isInteger(n))throw Error(`cannot index slice/array with type ${By(e)}`);if(n<0||n>t)throw Error(`index out of range: ${String(e)}`);return n}function Ry(e,t){if(t.length>3)throw Error(`too many slice indexes: ${t.length}`);if(typeof e==`string`&&t.length>2)throw Error(`cannot 3-index slice a string`);let n=e.length,r=[0,n,n];t.forEach((e,t)=>{r[t]=Ly(e,n)});let[i,a,o]=r;if(i>a)throw Error(`invalid slice index: ${i} > ${a}`);if(a>o)throw Error(`invalid slice index: ${a} > ${o}`);return e.slice(i,a)}function zy(e){return e===null?`null`:e===void 0?`undefined`:Array.isArray(e)?`array`:e instanceof Map?`Map`:typeof e}function By(e){return e==null?`<nil>`:typeof e==`string`?`string`:typeof e==`boolean`?`bool`:typeof e==`bigint`?`int64`:typeof e==`number`?Number.isInteger(e)?`int`:`float64`:Array.isArray(e)?`[]interface {}`:e instanceof Map||typeof e==`object`?`map[string]interface {}`:typeof e}function Vy(e,t){let n=``,r=!1;for(let i=0;i<e.length;i++){let a=e[i],o=typeof a==`string`;i>0&&!r&&!o&&(n+=` `),n+=Hy(a,t),r=o}return n}function Hy(e,t){return e==null?`<nil>`:typeof e==`string`?e:t(e)}const Uy={"\0":`�`,'"':`"`,"'":`'`,"&":`&`,"<":`<`,">":`>`};function Wy(e){return e.replace(/[\0"'&<>]/g,e=>Uy[e]??e)}const Gy={"\\":`\\\\`,"'":`\\'`,'"':`\\"`,"<":`\\u003C`,">":`\\u003E`,"&":`\\u0026`,"=":`\\u003D`},Ky=/^[\p{L}\p{M}\p{N}\p{P}\p{S}]$/u;function qy(e){let t=``;for(let n of e){let e=Gy[n];if(e!==void 0){t+=e;continue}let r=n.codePointAt(0);if(r<32||r>=128&&!Ky.test(n)){t+=`\\u${r.toString(16).toUpperCase().padStart(4,`0`)}`;continue}t+=n}return t}const Jy=new TextEncoder;function Yy(e){let t=``,n=Jy.encode(e);for(let e of n)e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===45||e===46||e===95||e===126?t+=String.fromCharCode(e):e===32?t+=`+`:t+=`%${e.toString(16).toUpperCase().padStart(2,`0`)}`;return t}function Xy(e,t,n,r){let i=``,a=0,o=0;for(;o<e.length;){let s=e[o];if(s!==`%`){i+=s,o+=1;continue}if(e[o+1]===`%`){i+=`%`,o+=2;continue}let c=o+1;for(;c<e.length&&`+-# 0`.includes(e[c]??``);)c+=1;for(;c<e.length&&e[c]!==void 0&&/[0-9]/.test(e[c]);)c+=1;if(e[c]===`.`)for(c+=1;c<e.length&&e[c]!==void 0&&/[0-9]/.test(e[c]);)c+=1;let l=e[c],u=e.slice(o+1,c),d=t[a++];i+=Zy(l??``,u,d,n,r),o=c+1}return i}function Zy(e,t,n,r,i){switch(e){case`s`:return typeof n==`string`?Qy(t,n):Qy(t,Hy(n,r));case`d`:return typeof n!=`number`&&typeof n!=`bigint`?`%!${e}(${By(n)}=${Hy(n,r)})`:Qy(t,String(typeof n==`bigint`?n:Math.trunc(n)));case`v`:return Qy(t,$y(n,r,i));case`q`:return Qy(t,JSON.stringify(Hy(n,r)));case`f`:{if(typeof n!=`number`&&typeof n!=`bigint`)return`%!${e}(${By(n)}=${Hy(n,r)})`;let i=t.includes(`.`)?Number(t.split(`.`)[1]):6;return Qy(t,Number(n).toFixed(i))}case`t`:return Qy(t,ky(n)?`true`:`false`);case`x`:if(typeof n==`string`){let e=new TextEncoder().encode(n),r=``;for(let t of e)r+=t.toString(16).padStart(2,`0`);return Qy(t,r)}return typeof n!=`number`&&typeof n!=`bigint`?`%!${e}(${By(n)}=${Hy(n,r)})`:typeof n==`bigint`?Qy(t,n.toString(16)):Qy(t,Math.trunc(n).toString(16));default:return`%!${e}(${By(n)}=${Hy(n,r)})`}}function Qy(e,t){let n=e.match(/^([+\-# 0]*)/)?.[1]??``,r=e.slice(n.length).match(/^(\d+)/);if(!r)return t;let i=Number(r[1]);if(t.length>=i)return t;let a=` `.repeat(i-t.length);return n.includes(`-`)?t+a:a+t}function $y(e,t,n){return e==null?`<nil>`:typeof e==`string`?e:n(e)?t(e):Array.isArray(e)?`[${e.map(e=>$y(e,t,n)).join(` `)}]`:e instanceof Map?eb([...e.entries()],t,n):tb(e)?eb(Object.entries(e),t,n):String(e)}function eb(e,t,n){let r=e=>$y(e,t,n),i=e=>typeof e==`number`||typeof e==`bigint`,a=([e],[t])=>{if(i(e)&&i(t))return e<t?-1:+(e>t);if(i(e)!==i(t))return i(e)?-1:1;let[n,a]=[r(e),r(t)];return n<a?-1:+(n>a)};return`map[${[...e].sort(a).map(([e,t])=>`${r(e)}:${r(t)}`).join(` `)}]`}function tb(e){if(typeof e!=`object`||!e||Array.isArray(e)||e instanceof Map||e instanceof Set)return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function nb(e){return{dot:e,root:e,parent:void 0,vars:new Map}}function rb(e,t){return{dot:t,root:e.root,parent:e,vars:new Map}}function ib(e,t){let n=e;for(;n!==void 0;){if(n.vars.has(t))return{found:!0,value:n.vars.get(t)};n=n.parent}return{found:!1}}function ab(e,t,n){e.vars.set(t,n)}const ob=[`string`,`int`,`truncating-int`,`float`,`bool`,`T`,`ordered`,`list`,`dict`,`sized`,`comparable`,`stringifiable`,`liftable`,`callable`,`collection`,`index-key`,`sliceable`,`truthy`,`reflective`,`value`,`serializable`],sb=new Set([`default`,`zero`,`error`]);function cb(e){if(e===void 0)return`default`;if(sb.has(e))return e;throw Error(`EngineConfig.missingKey: expected "default" | "zero" | "error", got ${lb(e)}`)}function lb(e){return typeof e==`string`?JSON.stringify(e):e===null?`null`:e===void 0?`undefined`:typeof e==`bigint`?`${e}n`:typeof e==`number`||typeof e==`boolean`?String(e):typeof e==`symbol`?e.toString():typeof e==`function`?`[Function]`:`[${typeof e}]`}function ub(e){if(e!==void 0){if(typeof e!=`object`||!e)throw Error(`EngineConfig.delims: expected { left, right } object, got ${lb(e)}`);if(typeof e.left!=`string`||e.left.length===0)throw Error(`EngineConfig.delims.left: expected non-empty string, got ${lb(e.left)}`);if(typeof e.right!=`string`||e.right.length===0)throw Error(`EngineConfig.delims.right: expected non-empty string, got ${lb(e.right)}`);return{left:e.left,right:e.right}}}function db(e){switch(e.kind){case`exact`:return!1;case`variadic`:return!0;case`alternating`:return!0}}function fb(e){let t=new Set(ob);for(let[n,r]of Object.entries(e)){if(r.argTypes.forEach((e,r)=>{if(!t.has(e))throw Error(`EngineConfig.funcs.${n}: argTypes[${r}] is ${JSON.stringify(e)}, which is not an ArgType; declare one of ${ob.join(`, `)}`)}),db(r.arity)&&r.argTypes.length===0)throw Error(`EngineConfig.funcs.${n}: arity ${JSON.stringify(r.arity.kind)} needs at least one declared argType (it reads its repeating slot from the end of argTypes); declare the slots the Go signature has, or use { kind: "exact" }`);if(r.arity.kind===`alternating`&&(!Number.isSafeInteger(r.arity.minimum)||r.arity.minimum<0))throw Error(`EngineConfig.funcs.${n}: arity "alternating" needs a non-negative integer minimum, got ${String(r.arity.minimum)}; the gate rejects every count below it, so a negative or non-finite minimum would disable the lower bound`)}return e}const pb=Object.freeze({kind:`break`}),mb=Object.freeze({kind:`continue`}),hb={kind:`none`};let gb;(class e{source;_evaluate;_defines;_referencedFunctions;_referencedCalls;constructor(e,t,n,r,i){this.source=e,this._evaluate=t,this._defines=n,this._referencedFunctions=r,this._referencedCalls=i}static{gb=(t,n,r,i,a)=>new e(t,n,r,i,a)}defines(){return this._defines}evaluate(e){return this._evaluate(e)}referencedFunctions(){return this._referencedFunctions}referencedCalls(){return this._referencedCalls}});function _b(e){let t=new Set,n=e=>{by(e,e=>{e.type===`Identifier`&&t.add(e.ident)})};n(e.root);for(let t of e.ownDefines.values())n(t.list);return t}const vb={kind:`dynamic`};function yb(e){switch(e.type){case`String`:return{kind:`literal`,value:e.value};case`Bool`:return{kind:`literal`,value:e.value};case`Nil`:return{kind:`literal`,value:null};case`Number`:{let t=Bb(e);return typeof t==`number`||typeof t==`bigint`?{kind:`literal`,value:t}:vb}case`Pipe`:{if(e.decls.length!==0||e.cmds.length!==1)return vb;let t=e.cmds[0];if(t===void 0)return vb;let n=t.args[0];return n===void 0||n.type!==`Identifier`?vb:{kind:`call`,name:n.ident,args:t.args.slice(1).map(yb)}}default:return vb}}function bb(e){let t=[],n=e=>{by(e,e=>{if(e.type!==`Command`)return;let n=e.args[0];if(n===void 0||n.type!==`Identifier`)return;let r=e.args.slice(1).map(yb);t.push({name:n.ident,args:r.map(e=>e.kind===`literal`&&typeof e.value==`string`?e.value:null),argExprs:r})})};n(e.root);for(let t of e.ownDefines.values())n(t.list);return t}var xb=class{fromString;toString;isT;funcs;missingKey;delims;constructor(e){this.fromString=e.fromString;let t=Object.hasOwn(e,`toString`)?e.toString:void 0;this.toString=t??kb,this.isT=e.isT??Sb,this.missingKey=cb(e.missingKey),this.delims=ub(e.delims),this.funcs=fb({...My(this.toString,this.isT),...e.funcs??{}})}parse(e,t){let n=oy(e,this.delims,t);return gb(n.source,e=>this.evalParsed(n,e),n.defines,_b(n),bb(n))}compile(e){let t=this.parse(e);return e=>t.evaluate(e)}evaluate(e,t){return e.evaluate(t)}evalParsed(e,t){let n=[],r=nb(t),i={out:n,defines:e.defines,source:e.source};return this.evalList(e.root,r,i),n}evalList(e,t,n){for(let r of e.nodes)this.evalNode(r,t,n)}evalNode(e,t,n){switch(e.type){case`Text`:n.out.push(this.fromString(e.text));return;case`Comment`:return;case`Action`:{let r=this.evalAction(e,t,n);e.pipe.decls.length===0&&this.emitFromValue(r,n);return}case`List`:this.evalList(e,t,n);return;case`If`:this.evalIf(e,t,n);return;case`Range`:this.evalRange(e,t,n);return;case`With`:this.evalWith(e,t,n);return;case`Break`:throw pb;case`Continue`:throw mb;case`Template`:this.evalTemplateInvoke(e,t,n);return;case`Block`:this.evalBlock(e,t,n);return;case`Pipe`:case`Command`:case`Identifier`:case`Field`:case`Variable`:case`Chain`:case`Dot`:case`Nil`:case`Bool`:case`Number`:case`String`:throw new Nv(`unexpected ${e.type} at statement position`,e.pos,{source:n.source});default:Uv(e)}}evalIf(e,t,n){ky(this.evalPipe(e.pipe,t,n))?this.evalList(e.list,t,n):e.elseList&&this.evalList(e.elseList,t,n)}evalWith(e,t,n){let r=this.evalPipe(e.pipe,t,n);if(ky(r)){let i=rb(t,r);this.evalList(e.list,i,n)}else e.elseList&&this.evalList(e.elseList,t,n)}evalRange(e,t,n){let r=this.evalPipeWithoutDecls(e.pipe,t,n),i=e.pipe.decls,a=Lb(r);try{if(a.length===0){e.elseList&&this.evalList(e.elseList,t,n);return}for(let[r,o]of a){let a=rb(t,o);if(i.length===1)ab(a,i[0]?.idents[0]??`$`,o);else if(i.length>=2){let e=i[0]?.idents[0]??`$`,t=i[1]?.idents[0]??`$`;ab(a,e,r),ab(a,t,o)}try{this.evalList(e.list,a,n)}catch(e){if(e===mb)continue;throw e}}}catch(e){if(e===pb)return;throw e}}evalTemplateInvoke(e,t,n){let r=iy(n.defines,e.name);if(!r)throw new Nv(`template ${JSON.stringify(e.name)} is not defined`,e.pos,{source:n.source});let i=rb(t,e.pipe?this.evalPipe(e.pipe,t,n):t.dot);this.evalList(r.list,i,{out:n.out,defines:n.defines,source:r.source})}evalBlock(e,t,n){let r=rb(t,e.pipe?this.evalPipe(e.pipe,t,n):t.dot),i=iy(n.defines,e.name)??{list:e.list,source:n.source};this.evalList(i.list,r,{out:n.out,defines:n.defines,source:i.source})}evalAction(e,t,n){return this.evalPipe(e.pipe,t,n)}evalPipe(e,t,n){if(e.cmds.length===0)throw new Nv(`empty pipeline`,e.pos,{source:n.source});let r=this.evalCommand(e.cmds[0],t,n,hb);for(let i=1;i<e.cmds.length;i++){let a=e.cmds[i];r=this.evalCommand(a,t,n,{kind:`value`,value:r})}if(e.decls.length>0)for(let n of e.decls)ab(t,n.idents[0]??`$`,r);return r}evalPipeWithoutDecls(e,t,n){let r={type:`Pipe`,pos:e.pos,decls:[],isAssign:!1,cmds:e.cmds};return this.evalPipe(r,t,n)}evalCommand(e,t,n,r){if(e.args.length===0)throw new Nv(`empty command`,e.pos,{source:n.source});let i=e.args[0];if(i.type!==`Identifier`){if(e.args.length>1)throw new Nv(`cannot apply arguments to a ${i.type} primary; only functions take arguments`,e.pos,{source:n.source});return this.evalPrimary(i,t,n)}let a=this.funcs[i.ident];if(!a)throw new Pv(i.ident,i.pos,{source:n.source,available:Object.keys(this.funcs)});let o=e.args.slice(1),s=Oy(a),c=o.map(e=>s?()=>this.evalPrimary(e,t,n):this.evalPrimary(e,t,n));if(r.kind===`value`){let e=r.value;c.push(s?()=>e:e)}return this.invoke(i.ident,a,c,e.pos,n)}invoke(e,t,n,r,i){wb(e,t,n,r,i.source,this.toString,this.fromString,this.isT);try{return t.fn(...n)}catch(t){throw t instanceof Iv?new Iv(t.funcName,t.argIndex,t.expected,t.receivedSummary,r,{source:i.source}):t instanceof zv?new zv(t.message,r,{source:i.source}):t instanceof jv?t:new Nv(`error calling ${e}: ${Fb(t)}`,r,{source:i.source,cause:t})}}evalPrimary(e,t,n){switch(e.type){case`Dot`:return t.dot;case`Nil`:return null;case`Bool`:return e.value;case`Number`:return Bb(e);case`String`:return e.value;case`Field`:return this.resolveFieldChain(t.dot,e.idents,e.pos,n);case`Variable`:return this.resolveVariable(e.idents,t,e.pos,n);case`Identifier`:{let t=this.funcs[e.ident];if(!t)throw new Pv(e.ident,e.pos,{source:n.source,available:Object.keys(this.funcs)});return this.invoke(e.ident,t,[],e.pos,n)}case`Chain`:return this.resolveFieldChain(this.evalPrimary(e.node,t,n),e.fields,e.pos,n);case`Pipe`:return this.evalPipe(e,t,n);default:throw new Nv(`cannot evaluate ${e.type} as a value`,e.pos,{source:n.source})}}resolveFieldChain(e,t,n,r){let i=wy(e,t);if(i!==Sy)return i;if(this.missingKey===`error`)throw new Rv(t,n,{source:r.source})}resolveVariable(e,t,n,r){let i=e[0]??`$`;if(i===`$`){let i=e.slice(1);return i.length===0?t.root:this.resolveFieldChain(t.root,i,n,r)}let a=ib(t,i);if(!a.found)throw new Nv(`undefined variable ${i}`,n,{source:r.source});let o=e.slice(1);return o.length===0?a.value:this.resolveFieldChain(a.value,o,n,r)}emitFromValue(e,t){if(e==null){t.out.push(this.fromString(`<no value>`));return}if(typeof e==`string`){t.out.push(this.fromString(e));return}if(typeof e==`number`||typeof e==`boolean`||typeof e==`bigint`){t.out.push(this.fromString(String(e)));return}if(this.isT(e)){t.out.push(e);return}t.out.push(this.fromString($y(e,this.toString,this.isT)))}};const Sb=e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&!(e instanceof Map);function Cb(e){return new xb(e)}function wb(e,t,n,r,i,a=kb,o=Ob,s=Sb){let{argTypes:c,arity:l}=t,u=Tb(c,l);if(n.length<u.minimum||n.length>u.maximum)throw new Fv(e,u,n.length,r,{source:i});let d=Eb(c,l),f=-1,p=-1;for(let t=0;t<n.length;t++){let c=d(t),l=n[t];if(!Db(c,l,a,s))throw(c===`int`||c===`truncating-int`)&&(typeof l==`number`||typeof l==`bigint`)?new Lv(e,t+1,l,r,{source:i}):new Iv(e,t+1,Pb(c),Ib(l),r,{source:i});if(c===`liftable`&&typeof l==`string`&&(n[t]=o(l)),c===`truncating-int`?n[t]=Math.trunc(Number(l)):(c===`int`||c===`float`)&&(n[t]=Number(l)),c===`ordered`){if(f===-1)f=t;else if(!jb(n[f],l))throw new Iv(e,t+1,`${Pb(`ordered`)} of the same kind as ${Ib(n[f])}`,Ib(l),r,{source:i})}if(c===`comparable`){if(p===-1)p=t;else if(!Mb(n[p],l))throw new Iv(e,t+1,`${Pb(`comparable`)} of the same kind as ${Ib(n[p])}`,Ib(l),r,{source:i})}}}function Tb(e,t){switch(t.kind){case`exact`:return{minimum:e.length,maximum:e.length};case`variadic`:return{minimum:e.length-1,maximum:1/0};case`alternating`:return{minimum:t.minimum,maximum:1/0}}}function Eb(e,t){let n=e.length;switch(t.kind){case`exact`:return t=>e[t];case`variadic`:return t=>e[Math.min(t,n-1)];case`alternating`:return t=>e[t%n]}}function Db(e,t,n,r){switch(e){case`truthy`:case`reflective`:case`value`:return!0;case`string`:return typeof t==`string`;case`int`:return typeof t==`number`&&Number.isSafeInteger(t)||typeof t==`bigint`&&Number.isSafeInteger(Number(t));case`truncating-int`:return typeof t==`number`&&Number.isFinite(t)||typeof t==`bigint`&&Number.isSafeInteger(Number(t));case`float`:return typeof t==`number`||typeof t==`bigint`&&Number.isFinite(Number(t));case`bool`:return typeof t==`boolean`;case`ordered`:return typeof t==`string`||typeof t==`number`||typeof t==`bigint`||typeof t==`boolean`;case`T`:return r(t);case`list`:return Array.isArray(t);case`dict`:return tb(t);case`sized`:return typeof t==`string`||Array.isArray(t)||t instanceof Map||t instanceof Set||tb(t);case`comparable`:return t==null||typeof t==`string`||typeof t==`number`||typeof t==`bigint`||typeof t==`boolean`||Array.isArray(t)||t instanceof Map||t instanceof Set||tb(t);case`callable`:return typeof t==`function`;case`collection`:return typeof t==`string`||Array.isArray(t)||t instanceof Map||tb(t);case`index-key`:return typeof t==`string`||typeof t==`number`||typeof t==`bigint`;case`sliceable`:return typeof t==`string`||Array.isArray(t);case`stringifiable`:if(typeof t==`string`)return!0;try{return n(t),!0}catch{return!1}case`liftable`:return typeof t==`string`||r(t);case`serializable`:return Ab(t);default:throw Error(`invalid ArgType: ${String(e)}`)}}function Ob(e){return e}function kb(e){if(typeof e==`string`)return e;if(e==null)return`<nil>`;if(typeof e==`number`||typeof e==`bigint`||typeof e==`boolean`)return String(e);throw new Iv(`<engine.toString>`,1,`string (or a consumer-supplied toString that flattens T)`,Ib(e),{line:0,column:0,offset:0})}function Ab(e){try{return JSON.stringify(e)!==void 0}catch{return!1}}function jb(e,t){return typeof e==typeof t||typeof e==`number`&&typeof t==`bigint`||typeof e==`bigint`&&typeof t==`number`}function Mb(e,t){let n=Nb(e),r=Nb(t);return n===`nil`||r===`nil`?!0:n===r}function Nb(e){return e==null?`nil`:typeof e==`string`?`string`:typeof e==`number`||typeof e==`bigint`?`number`:typeof e==`boolean`?`boolean`:Array.isArray(e)?`array`:e instanceof Map?`map`:e instanceof Set?`set`:`object`}function Pb(e){switch(e){case`int`:return`integer (safe-integer number or bigint)`;case`truncating-int`:return`integer (finite number, truncated toward zero, or safe-integer bigint)`;case`float`:return`float (number, including NaN/Infinity, or finite-convertible bigint)`;case`T`:return`T (consumer-defined fragment)`;case`ordered`:return`orderable primitive`;case`list`:return`list`;case`dict`:return`dict (plain object)`;case`sized`:return`sized value (string, list, map, set, or dict)`;case`comparable`:return`comparable value (orderable primitive, nil, list, dict, Map, or Set)`;case`stringifiable`:return`stringifiable value (string or convertible via the engine's toString)`;case`liftable`:return`liftable value (T or string, the latter lifted via the engine's fromString)`;case`callable`:return`callable (function value)`;case`collection`:return`collection (string, array, Map, or dict)`;case`index-key`:return`index key (number, bigint, or string)`;case`sliceable`:return`sliceable value (string or array)`;case`serializable`:return`JSON-serializable value`;case`truthy`:case`reflective`:case`value`:case`string`:case`bool`:return e;default:throw Error(`invalid ArgType: ${String(e)}`)}}function Fb(e){return e instanceof Error?e.message:String(e)}function Ib(e){return e===null?`null`:e===void 0?`undefined`:Array.isArray(e)?`array`:e instanceof Map?`Map`:typeof e}function Lb(e){return e==null?[]:Array.isArray(e)?e.map((e,t)=>[t,e]):typeof e==`string`?[...e].map((e,t)=>[t,e]):e instanceof Map?Rb([...e.entries()]):e instanceof Set?[...e.values()].map((e,t)=>[t,e]):typeof e==`object`?Rb(Object.entries(e)):[]}function Rb(e){return[...e].sort((e,t)=>zb(e[0],t[0]))}function zb(e,t){if((typeof e==`number`||typeof e==`bigint`)&&(typeof t==`number`||typeof t==`bigint`)){let n=typeof e==`bigint`?Number(e):e,r=typeof t==`bigint`?Number(t):t;return n===r?0:n<r?-1:1}let n=String(e),r=String(t);return n===r?0:n<r?-1:1}function Bb(e){if(e.intValue!==void 0){let t=e.intValue;return t>=BigInt(-(2**53-1))&&t<=BigInt(2**53-1)?Number(t):t}if(e.floatValue!==void 0)return e.floatValue;if(e.complexValue!==void 0)return e.complexValue;throw Error(`internal: NumberNode has none of intValue/floatValue/complexValue — parser invariant violated`)}function Vb(e){if(!/^[+-]?\d+$/.test(e))return 0;let t=Number.parseInt(e,10);return Number.isSafeInteger(t)?t:0}function Hb(e){if(typeof e==`number`)return e;if(typeof e==`bigint`)return Number(e);if(typeof e==`string`){let t=Number.parseFloat(e);return Number.isNaN(t)?0:t}return typeof e==`boolean`?+!!e:0}function Ub(e){if(e===``)return null;let t=1,n=e;return n[0]===`+`?n=n.slice(1):n[0]===`-`&&(t=-1,n=n.slice(1)),n===``?null:/^0x[0-9a-fA-F]+$/i.test(n)?{sign:t,digits:n.slice(2),base:16}:/^0b[01]+$/i.test(n)?{sign:t,digits:n.slice(2),base:2}:/^0o[0-7]+$/i.test(n)?{sign:t,digits:n.slice(2),base:8}:n===`0`?{sign:t,digits:`0`,base:10}:n[0]===`0`?/^0[0-7]+$/.test(n)?{sign:t,digits:n.slice(1),base:8}:null:/^[0-9]+$/.test(n)?{sign:t,digits:n,base:10}:null}function Wb(e){if(typeof e==`number`){let t=Math.trunc(e);return Number.isSafeInteger(t)?t:0}if(typeof e==`bigint`){let t=Number(e);return Number.isSafeInteger(t)?t:0}if(typeof e==`string`){let t=Ub(e);if(t===null)return 0;let n=t.sign*Number.parseInt(t.digits,t.base);return Number.isSafeInteger(n)?n:0}return typeof e==`boolean`?+!!e:0}function Gb(e){if(typeof e==`bigint`)return e;if(typeof e==`number`)return BigInt(Math.trunc(e));if(typeof e==`string`){let t=Ub(e);if(t===null)return 0n;let n=t.base===16?`0x`:t.base===2?`0b`:t.base===8?`0o`:``,r=BigInt(n+t.digits);return t.sign===-1?-r:r}return typeof e==`boolean`&&e?1n:0n}function Kb(e){if(!/^[+-]?[0-7]+$/.test(e))return 0;let t=e[0]===`-`?-1:1,n=e[0]===`+`||e[0]===`-`?e.slice(1):e,r=t*Number.parseInt(n,8);return Number.isSafeInteger(r)?r:0}function qb(e){return JSON.stringify(e)??`null`}function Jb(){return{atoi:{fn:e=>Vb(e),argTypes:[`string`],arity:{kind:`exact`},returnType:`int`},int:{fn:e=>Wb(e),argTypes:[`value`],arity:{kind:`exact`},returnType:`int`},int64:{fn:e=>Gb(e),argTypes:[`value`],arity:{kind:`exact`}},float64:{fn:e=>Hb(e),argTypes:[`value`],arity:{kind:`exact`},returnType:`float`},toDecimal:{fn:e=>Kb(e),argTypes:[`string`],arity:{kind:`exact`},returnType:`int`},toRawJson:{fn:e=>qb(e),argTypes:[`serializable`],arity:{kind:`exact`},returnType:`string`}}}const Yb={h:36e11,m:6e10,s:1e9,ms:1e6,us:1e3,µs:1e3,ns:1};function Xb(e){if(e===`0`)return 0;let t=!1,n=e;if(n.startsWith(`-`)?(t=!0,n=n.slice(1)):n.startsWith(`+`)&&(n=n.slice(1)),!n)return NaN;let r=0,i=/^(\d+(?:\.\d+)?)(ns|µs|us|ms|[smh])/;for(;n.length>0;){let e=i.exec(n);if(!e)return NaN;let t=parseFloat(e[1]??`0`),a=e[2];r+=t*Yb[a],n=n.slice(e[0].length)}return t?-r:r}function Zb(e){if(e===0)return`0s`;let t=!1,n=e;n<0&&(t=!0,n=-n);let r;return r=n<Yb.us?`${Math.floor(n)}ns`:n<Yb.ms?Qb(n,Yb.us,3,`µs`):n<Yb.s?Qb(n,Yb.ms,6,`ms`):$b(n),t?`-${r}`:r}function Qb(e,t,n,r){let i=Math.floor(e/t),a=Math.round(e%t);return a===0?`${i}${r}`:`${i}.${String(a).padStart(n,`0`).replace(/0+$/,``)}${r}`}function $b(e){let t=Math.floor(e/Yb.h);e-=t*Yb.h;let n=Math.floor(e/Yb.m);e-=n*Yb.m;let r=Math.floor(e/Yb.s),i=e-r*Yb.s,a=i===0?`${r}s`:`${r}.${String(Math.round(i)).padStart(9,`0`).replace(/0+$/,``)}s`;return t>0?`${t}h${n}m${a}`:n>0?`${n}m${a}`:a}function ex(e){return e*Yb.s}function tx(e){if(e instanceof Date)return e;if(typeof e==`bigint`)return new Date(Number(e)*1e3);if(typeof e==`number`)return new Date(e*1e3);if(typeof e==`string`){let t=new Date(e);if(!Number.isNaN(t.getTime()))return t;throw Error(`sprig: cannot parse date value ${JSON.stringify(e)}`)}throw Error(`sprig: unsupported date type: ${typeof e}`)}function nx(e,t){let n=t().getTime()-tx(e).getTime();return Zb(Math.round(n/1e3)*1e9)}const rx=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],ix=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],ax=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`],ox=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function sx(e){return e<10?`0${e}`:String(e)}function cx(e){return e<10?`00${e}`:e<100?`0${e}`:String(e)}function lx(e){return e<10?` ${e}`:String(e)}function ux(e){let t=e>=0?`+`:`-`,n=Math.abs(e);return`${t}${sx(Math.floor(n/60))}${sx(n%60)}`}function dx(e){let t=e>=0?`+`:`-`,n=Math.abs(e);return`${t}${sx(Math.floor(n/60))}:${sx(n%60)}`}function fx(e){return`${e>=0?`+`:`-`}${sx(Math.floor(Math.abs(e)/60))}`}function px(e){return e===0?`Z`:ux(e)}function mx(e){return e===0?`Z`:dx(e)}function hx(e){return e===0?`Z`:fx(e)}function gx(e,t,n){let r=e*1e6,i=String(r).padStart(9,`0`).slice(0,t);return n?i.replace(/0+$/,``):i}const _x=[[`.000000000`,e=>`.${gx(e.ms,9,!1)}`],[`.999999999`,e=>{let t=gx(e.ms,9,!0);return t?`.${t}`:``}],[`.000000`,e=>`.${gx(e.ms,6,!1)}`],[`.999999`,e=>{let t=gx(e.ms,6,!0);return t?`.${t}`:``}],[`.000`,e=>`.${cx(e.ms)}`],[`.999`,e=>{let t=cx(e.ms).replace(/0+$/,``);return t?`.${t}`:``}],[`January`,e=>rx[e.month-1]??`January`],[`Monday`,e=>ax[e.weekday]??`Monday`],[`Z07:00`,e=>mx(e.offsetMinutes)],[`-07:00`,e=>dx(e.offsetMinutes)],[`Z0700`,e=>px(e.offsetMinutes)],[`-0700`,e=>ux(e.offsetMinutes)],[`2006`,e=>String(e.year)],[`Jan`,e=>ix[e.month-1]??`Jan`],[`Mon`,e=>ox[e.weekday]??`Mon`],[`MST`,e=>e.tzAbbr],[`-07`,e=>fx(e.offsetMinutes)],[`Z07`,e=>hx(e.offsetMinutes)],[`15`,e=>sx(e.hour)],[`01`,e=>sx(e.month)],[`02`,e=>sx(e.day)],[`_2`,e=>lx(e.day)],[`03`,e=>sx(e.hour12)],[`04`,e=>sx(e.minute)],[`05`,e=>sx(e.second)],[`06`,e=>sx(e.year%100)],[`PM`,e=>e.hour>=12?`PM`:`AM`],[`pm`,e=>e.hour>=12?`pm`:`am`],[`1`,e=>String(e.month)],[`2`,e=>String(e.day)],[`3`,e=>String(e.hour12)],[`4`,e=>String(e.minute)],[`5`,e=>String(e.second)]];function vx(e,t){let n=``,r=0;for(;r<e.length;){let i=!1;for(let[a,o]of _x)if(e.startsWith(a,r)){n+=o(t),r+=a.length,i=!0;break}i||(n+=e[r++])}return n}const yx={year:`numeric`,month:`2-digit`,day:`2-digit`,weekday:`long`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1};function bx(e){let t=new Map;for(let n of e)t.set(n.type,n.value);return t}const xx=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`];function Sx(e,t){let n;try{new Intl.DateTimeFormat(`en-US`,{timeZone:t}),n=t}catch{n=`UTC`}let r=bx(new Intl.DateTimeFormat(`en-US`,{...yx,timeZone:n}).formatToParts(e)),i=parseInt(r.get(`hour`)??`0`,10)%24,a=bx(new Intl.DateTimeFormat(`en-US`,{timeZone:n,timeZoneName:`short`}).formatToParts(e)).get(`timeZoneName`)??n,o=Cx(bx(new Intl.DateTimeFormat(`en-US`,{timeZone:n,timeZoneName:`shortOffset`}).formatToParts(e)).get(`timeZoneName`)??`GMT`),s=xx.indexOf(r.get(`weekday`)??`Sunday`);return{year:parseInt(r.get(`year`)??`2000`,10),month:parseInt(r.get(`month`)??`1`,10),day:parseInt(r.get(`day`)??`1`,10),weekday:s===-1?0:s,hour:i,hour12:i%12||12,minute:parseInt(r.get(`minute`)??`0`,10),second:parseInt(r.get(`second`)??`0`,10),ms:e.getUTCMilliseconds(),tzAbbr:a,offsetMinutes:o}}function Cx(e){if(e===`GMT`||e===`UTC`)return 0;let t=e.match(/^GMT([+-])(\d{1,2})(?::(\d{2}))?$/);if(!t)return 0;let n=t[1]===`+`?1:-1,r=parseInt(t[2]??`0`,10),i=parseInt(t[3]??`0`,10);return n*(r*60+i)}function wx(){return Intl.DateTimeFormat().resolvedOptions().timeZone}function Tx(e,t){return vx(e,Sx(tx(t),wx()))}function Ex(e,t,n){return vx(e,Sx(tx(t),n))}function Dx(e,t){let n=tx(t),r=Xb(e);return Number.isNaN(r)?n:new Date(n.getTime()+r/1e6)}function Ox(e){if(typeof e==`string`){let t=parseInt(e,10);return Number.isNaN(t)?`0s`:Zb(ex(t))}return typeof e==`bigint`?Zb(ex(Number(e))):typeof e==`number`?Zb(ex(e)):`0s`}const kx=36e11*24*365,Ax=36e11*24*30,jx=36e11*24,Mx=36e11,Nx=6e10,Px=1e9;function Fx(e){let t=Xb(String(e));if(Number.isNaN(t))return`0s`;let n=Math.abs(t);return n>kx?`${Math.floor(n/kx)}y`:n>Ax?`${Math.floor(n/Ax)}mo`:n>jx?`${Math.floor(n/jx)}d`:n>Mx?`${Math.floor(n/Mx)}h`:n>Nx?`${Math.floor(n/Nx)}m`:n>Px?`${Math.floor(n/Px)}s`:`0s`}function Ix(e){let t=Sx(tx(e),wx());return`${t.year}-${String(t.month).padStart(2,`0`)}-${String(t.day).padStart(2,`0`)}`}function Lx(e,t){let n=Sx(tx(e),t);return`${n.year}-${String(n.month).padStart(2,`0`)}-${String(n.day).padStart(2,`0`)}`}function Rx(e){return e()}const zx=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],Bx=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`];function Vx(){return{year:2e3,month:1,day:1,hour:0,minute:0,second:0,ms:0,offsetMinutes:0,isPM:!1,hour12:!1}}function Hx(e,t,n){return[e.slice(t,t+n),t+n]}function Ux(e,t,n,r){let i=t;for(;i<e.length&&i-t<r&&e.charCodeAt(i)>=48&&e.charCodeAt(i)<=57;)i++;if(i-t<n)throw Error(`sprig toDate: expected ${n}-${r} digits at pos ${t}`);return[parseInt(e.slice(t,i),10),i]}function Wx(e,t){for(let[n,r]of zx.entries())if(e.startsWith(r,t))return[n+1,t+r.length];throw Error(`sprig toDate: expected month name at pos ${t}`)}function Gx(e,t){for(let[n,r]of Bx.entries())if(e.startsWith(r,t))return[n+1,t+r.length];throw Error(`sprig toDate: expected short month name at pos ${t}`)}function Kx(e,t){for(let n of[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`])if(e.startsWith(n,t))return t+n.length;throw Error(`sprig toDate: expected weekday name at pos ${t}`)}function qx(e,t){for(let n of[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`])if(e.startsWith(n,t))return t+n.length;throw Error(`sprig toDate: expected short weekday name at pos ${t}`)}function Jx(e,t){if(e[t]===` `){let[n,r]=Ux(e,t+1,1,1);return[n,r]}return Ux(e,t,1,2)}function Yx(e,t,n){let r=e[t]===`+`?1:e[t]===`-`?-1:0;if(r===0)throw Error(`sprig toDate: expected +/- at pos ${t}`);let i=t+1,[a,o]=Ux(e,i,2,2);i=o;let s=0;if(n&&e[i]===`:`){let[t,n]=Ux(e,i+1,2,2);s=t,i=n}else if(!n){let[t,n]=Ux(e,i,2,2);s=t,i=n}return[r*(a*60+s),i]}function Xx(e,t,n,r){if(e[t]===`Z`)return[0,t+1];if(r){let n=e[t]===`+`?1:e[t]===`-`?-1:0;if(n===0)throw Error(`sprig toDate: expected Z or +/- at pos ${t}`);let[r,i]=Ux(e,t+1,2,2);return[n*r*60,i]}return Yx(e,t,n)}function Zx(e,t){let n=t;for(;n<e.length&&e.charCodeAt(n)>=65&&e.charCodeAt(n)<=90;)n++;if(n===t)throw Error(`sprig toDate: expected timezone abbreviation at pos ${t}`);return n}function Qx(e,t,n){let[r,i]=Hx(e,t,n),a=parseInt(r.padEnd(9,`0`),10);return[Math.round(a/1e6),i]}function $x(e,t,n,r){let i={...r};switch(e){case`January`:{let[e,r]=Wx(t,n);return i.month=e,[r,i]}case`Monday`:return[Kx(t,n),i];case`Jan`:{let[e,r]=Gx(t,n);return i.month=e,[r,i]}case`Mon`:return[qx(t,n),i];case`2006`:{let[e,r]=Ux(t,n,4,4);return i.year=e,[r,i]}case`06`:{let[e,r]=Ux(t,n,2,2);return i.year=e<70?2e3+e:1900+e,[r,i]}case`01`:{let[e,r]=Ux(t,n,2,2);return i.month=e,[r,i]}case`1`:{let[e,r]=Ux(t,n,1,2);return i.month=e,[r,i]}case`_2`:{let[e,r]=Jx(t,n);return i.day=e,[r,i]}case`02`:{let[e,r]=Ux(t,n,2,2);return i.day=e,[r,i]}case`2`:{let[e,r]=Ux(t,n,1,2);return i.day=e,[r,i]}case`15`:{let[e,r]=Ux(t,n,2,2);return i.hour=e,[r,i]}case`03`:{let[e,r]=Ux(t,n,2,2);return i.hour=e,i.hour12=!0,[r,i]}case`3`:{let[e,r]=Ux(t,n,1,2);return i.hour=e,i.hour12=!0,[r,i]}case`04`:{let[e,r]=Ux(t,n,2,2);return i.minute=e,[r,i]}case`4`:{let[e,r]=Ux(t,n,1,2);return i.minute=e,[r,i]}case`05`:{let[e,r]=Ux(t,n,2,2);return i.second=e,[r,i]}case`5`:{let[e,r]=Ux(t,n,1,2);return i.second=e,[r,i]}case`PM`:case`pm`:{let e=t.slice(n,n+2).toLowerCase();if(e!==`am`&&e!==`pm`)throw Error(`sprig toDate: expected AM/PM at pos ${n}, got ${JSON.stringify(t.slice(n,n+2))}`);return i.isPM=e===`pm`,i.hour12=!0,[n+2,i]}case`MST`:return[Zx(t,n),i];case`-0700`:{let[e,r]=Yx(t,n,!1);return i.offsetMinutes=e,[r,i]}case`-07:00`:{let[e,r]=Yx(t,n,!0);return i.offsetMinutes=e,[r,i]}case`-07`:{let e=t[n]===`+`?1:t[n]===`-`?-1:0;if(e===0)throw Error(`sprig toDate: expected +/- at pos ${n}`);let[r,a]=Ux(t,n+1,2,2);return i.offsetMinutes=e*r*60,[a,i]}case`Z0700`:{let[e,r]=Xx(t,n,!1,!1);return i.offsetMinutes=e,[r,i]}case`Z07:00`:{let[e,r]=Xx(t,n,!0,!1);return i.offsetMinutes=e,[r,i]}case`Z07`:{let[e,r]=Xx(t,n,!1,!0);return i.offsetMinutes=e,[r,i]}case`.000000000`:{if(t[n]!==`.`)throw Error(`sprig toDate: expected . at pos ${n}`);let[e,r]=Qx(t,n+1,9);return i.ms=e,[r,i]}case`.999999999`:{if(t[n]!==`.`)return[n,i];let e=n+1,r=e;for(;r<t.length&&t.charCodeAt(r)>=48&&t.charCodeAt(r)<=57;)r++;let a=t.slice(e,r).padEnd(9,`0`);return i.ms=Math.round(parseInt(a,10)/1e6),[r,i]}case`.000000`:{if(t[n]!==`.`)throw Error(`sprig toDate: expected . at pos ${n}`);let[e,r]=Qx(t,n+1,6);return i.ms=e,[r,i]}case`.999999`:{if(t[n]!==`.`)return[n,i];let e=n+1,r=e;for(;r<t.length&&t.charCodeAt(r)>=48&&t.charCodeAt(r)<=57;)r++;let a=t.slice(e,r).padEnd(9,`0`);return i.ms=Math.round(parseInt(a,10)/1e6),[r,i]}case`.000`:{if(t[n]!==`.`)throw Error(`sprig toDate: expected . at pos ${n}`);let[e,r]=Qx(t,n+1,3);return i.ms=e,[r,i]}case`.999`:{if(t[n]!==`.`)return[n,i];let e=n+1,r=e;for(;r<t.length&&t.charCodeAt(r)>=48&&t.charCodeAt(r)<=57;)r++;let a=t.slice(e,r).padEnd(3,`0`);return i.ms=parseInt(a,10),[r,i]}}throw Error(`sprig toDate: unhandled token ${e}`)}const eS=`.000000000,.999999999,.000000,.999999,.000,.999,January,Monday,Z07:00,-07:00,Z0700,-0700,2006,Jan,Mon,MST,-07,Z07,15,01,02,_2,03,04,05,06,PM,pm,1,2,3,4,5`.split(`,`);function tS(e,t){let n=0,r=0,i=Vx();for(;n<e.length;){let a=!1;for(let o of eS)if(e.startsWith(o,n)){let[e,s]=$x(o,t,r,i);r=e,i=s,n+=o.length,a=!0;break}if(!a){let i=e.charAt(n);if(t[r]!==i)throw Error(`sprig toDate: expected ${JSON.stringify(i)} at pos ${r}, got ${JSON.stringify(t[r])}`);n++,r++}}if(r!==t.length)throw Error(`sprig toDate: extra characters at pos ${r}: ${JSON.stringify(t.slice(r))}`);if(i.hour12){let e=i.hour%12;i.hour=i.isPM?e+12:e}let a=Date.UTC(i.year,i.month-1,i.day,i.hour,i.minute,i.second,i.ms)-i.offsetMinutes*60*1e3;return new Date(a)}function nS(e,t){return tS(e,t)}function rS(e){return String(Math.floor(tx(e).getTime()/1e3))}function iS(e=()=>new Date){return{now:{fn:()=>Rx(e),argTypes:[],arity:{kind:`exact`}},date:{fn:(e,t)=>Tx(e,t),argTypes:[`string`,`value`],arity:{kind:`exact`}},dateInZone:{fn:(e,t,n)=>Ex(e,t,n),argTypes:[`string`,`value`,`string`],arity:{kind:`exact`}},dateModify:{fn:(e,t)=>Dx(e,t),argTypes:[`string`,`value`],arity:{kind:`exact`}},htmlDate:{fn:e=>Ix(e),argTypes:[`value`],arity:{kind:`exact`}},htmlDateInZone:{fn:(e,t)=>Lx(e,t),argTypes:[`value`,`string`],arity:{kind:`exact`}},duration:{fn:e=>Ox(e),argTypes:[`value`],arity:{kind:`exact`}},durationRound:{fn:e=>Fx(e),argTypes:[`value`],arity:{kind:`exact`}},toDate:{fn:(e,t)=>nS(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},ago:{fn:t=>nx(t,e),argTypes:[`value`],arity:{kind:`exact`}},unixEpoch:{fn:e=>rS(e),argTypes:[`value`],arity:{kind:`exact`}}}}function aS(e){return e==null||e===!1?!0:typeof e==`number`?e===0||Number.isNaN(e):typeof e==`bigint`?e===0n:typeof e==`string`||Array.isArray(e)?e.length===0:e instanceof Map||e instanceof Set?e.size===0:typeof e==`object`?Object.keys(e).length===0:!1}function oS(...e){for(let t of e)if(!aS(t))return t}function sS(e,t){return aS(t)?e:t}function cS(e){return JSON.parse(e)}function lS(e,t,n){return ky(n)?e:t}function uS(e){return JSON.stringify(e)??`null`}function dS(e){return JSON.stringify(e,null,2)??`null`}function fS(){return{default:{fn:(e,t)=>sS(e,t),argTypes:[`value`,`truthy`],arity:{kind:`variadic`}},empty:{fn:e=>aS(e),argTypes:[`truthy`],arity:{kind:`exact`}},coalesce:{fn:(...e)=>oS(...e),argTypes:[`truthy`],arity:{kind:`variadic`}},ternary:{fn:(e,t,n)=>lS(e,t,n),argTypes:[`value`,`value`,`truthy`],arity:{kind:`exact`}},fromJson:{fn:e=>cS(e),argTypes:[`string`],arity:{kind:`exact`}},toJson:{fn:e=>uS(e),argTypes:[`serializable`],arity:{kind:`exact`},returnType:`string`},toPrettyJson:{fn:e=>dS(e),argTypes:[`serializable`],arity:{kind:`exact`},returnType:`string`}}}function pS(...e){let t={};for(let n=0;n<e.length;n+=2)t[e[n]]=e[n+1];return t}function mS(e){if(e.kind!==`call`||e.name!==`dict`||e.args.length%2!=0)return null;let t=[];for(let[n,r]of e.args.entries()){if(r.kind!==`literal`||n%2==0&&typeof r.value!=`string`)return null;t.push(r.value)}return pS(...t)}function hS(e,t){return e[t]}function gS(e,t){return t in e}function _S(e){return Object.keys(e)}function vS(e,...t){let n={...e};for(let e of t)for(let[t,r]of Object.entries(e))t in n||(n[t]=r);return n}function yS(e,...t){let n={...e};for(let e of t)Object.assign(n,e);return n}function bS(e,...t){let n=new Set(t),r={};for(let[t,i]of Object.entries(e))n.has(t)||(r[t]=i);return r}function xS(e,...t){let n={};for(let r of t)r in e&&(n[r]=e[r]);return n}function SS(e,...t){let n=[];for(let r of t)e in r&&n.push(r[e]);return n}function CS(e,t,n){return e[t]=n,e}function wS(e,t){return delete e[t],e}function TS(e){return Object.values(e)}function ES(){return{dict:{fn:(...e)=>pS(...e),argTypes:[`string`,`value`],arity:{kind:`alternating`,minimum:0}},get:{fn:(e,t)=>hS(e,t),argTypes:[`dict`,`string`],arity:{kind:`exact`}},set:{fn:(e,t,n)=>CS(e,t,n),argTypes:[`dict`,`string`,`value`],arity:{kind:`exact`}},unset:{fn:(e,t)=>wS(e,t),argTypes:[`dict`,`string`],arity:{kind:`exact`}},keys:{fn:e=>_S(e),argTypes:[`dict`],arity:{kind:`variadic`}},values:{fn:e=>TS(e),argTypes:[`dict`],arity:{kind:`exact`}},pluck:{fn:(e,...t)=>SS(e,...t),argTypes:[`string`,`dict`],arity:{kind:`variadic`}},pick:{fn:(e,...t)=>xS(e,...t),argTypes:[`dict`,`string`],arity:{kind:`variadic`}},omit:{fn:(e,...t)=>bS(e,...t),argTypes:[`dict`,`string`],arity:{kind:`variadic`}},hasKey:{fn:(e,t)=>gS(e,t),argTypes:[`dict`,`string`],arity:{kind:`exact`}},merge:{fn:(e,...t)=>vS(e,...t),argTypes:[`dict`,`dict`],arity:{kind:`variadic`}},mergeOverwrite:{fn:(e,...t)=>yS(e,...t),argTypes:[`dict`,`dict`],arity:{kind:`variadic`}}}}function DS(e){throw new zv(e)}function OS(){return{fail:{fn:e=>DS(e),argTypes:[`string`],arity:{kind:`exact`}}}}new TextEncoder,new Map(Array.from(`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`).map((e,t)=>[e,t])),new TextDecoder,new TextEncoder,new TextDecoder,new TextEncoder;function kS(...e){for(let t of e)if(aS(t))return!1;return!0}function AS(...e){for(let t of e)if(!aS(t))return!0;return!1}function jS(e,t){return[...e,t]}function MS(e,t){let n=Math.max(1,e),r=[];for(let e=0;e<t.length;e+=n)r.push(t.slice(e,e+n));return r}function NS(e){return e.filter(e=>!aS(e))}function PS(...e){let t=[];for(let n of e)t.push(...n);return t}const FS={line:0,column:0,offset:0};function IS(e,t,n,r){return new Iv(e,t,n,r,FS)}function LS(...e){if(e.length<3)throw IS(`dig`,0,`at least 3 arguments (...keys, default, dict)`,`${e.length} argument${e.length===1?``:`s`}`);let t=e[e.length-1],n=e[e.length-2],r=e.slice(0,-2);if(!zS(t))throw IS(`dig`,e.length-1,`dict`,BS(t));for(let e=0;e<r.length;e++)if(typeof r[e]!=`string`)throw IS(`dig`,e,`string`,BS(r[e]));return RS(t,n,r,e.length)}function RS(e,t,n,r){let i=n[0];if(!Object.hasOwn(e,i))return t;let a=e[i];if(n.length===1)return a;if(!zS(a))throw IS(`dig`,r-1,`dict at intermediate key`,BS(a));return RS(a,t,n.slice(1),r)}function zS(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&!(e instanceof Map)&&!(e instanceof Set)}function BS(e){return e===null?`null`:Array.isArray(e)?`array`:e instanceof Map?`Map`:e instanceof Set?`Set`:typeof e}function VS(e){return e[0]}function HS(e,t){return t.some(t=>Ty(t,e))}function US(e){return e.slice(0,-1)}function WS(e){return e[e.length-1]}function GS(e){return Array.isArray(e)||typeof e==`string`?e.length:e instanceof Map||e instanceof Set?e.size:Object.keys(e).length}function KS(...e){return e}function qS(e,t){return[t,...e]}function JS(e){return e.slice(1)}function YS(e){return[...e].reverse()}function XS(e,t,n){let r=t===void 0?0:t,i=n===void 0?e.length:n;return e.slice(r,i)}function ZS(e){let t=[];for(let n of e)n!=null&&t.push(String(n));return t.sort()}function QS(e){let t=[];for(let n of e)t.some(e=>Ty(e,n))||t.push(n);return t}function $S(e,...t){return e.filter(e=>!t.some(t=>Ty(t,e)))}function eC(){return{list:{fn:(...e)=>KS(...e),argTypes:[`value`],arity:{kind:`variadic`}},first:{fn:e=>VS(e),argTypes:[`list`],arity:{kind:`exact`}},last:{fn:e=>WS(e),argTypes:[`list`],arity:{kind:`exact`}},rest:{fn:e=>JS(e),argTypes:[`list`],arity:{kind:`exact`}},initial:{fn:e=>US(e),argTypes:[`list`],arity:{kind:`exact`}},len:{fn:e=>GS(e),argTypes:[`sized`],arity:{kind:`exact`}},reverse:{fn:e=>YS(e),argTypes:[`list`],arity:{kind:`exact`}},uniq:{fn:e=>QS(e),argTypes:[`list`],arity:{kind:`exact`}},without:{fn:(e,...t)=>$S(e,...t),argTypes:[`list`,`value`],arity:{kind:`variadic`}},has:{fn:(e,t)=>HS(e,t),argTypes:[`value`,`list`],arity:{kind:`exact`}},compact:{fn:e=>NS(e),argTypes:[`list`],arity:{kind:`exact`}},slice:{fn:(e,t,n)=>XS(e,t,n),argTypes:[`list`,`truncating-int`],arity:{kind:`variadic`}},concat:{fn:(...e)=>PS(...e),argTypes:[`list`],arity:{kind:`variadic`}},chunk:{fn:(e,t)=>MS(e,t),argTypes:[`int`,`list`],arity:{kind:`exact`}},prepend:{fn:(e,t)=>qS(e,t),argTypes:[`list`,`value`],arity:{kind:`exact`}},append:{fn:(e,t)=>jS(e,t),argTypes:[`list`,`value`],arity:{kind:`exact`}},sortAlpha:{fn:e=>ZS(e),argTypes:[`list`],arity:{kind:`exact`},returnType:`list`},push:{fn:(e,t)=>jS(e,t),argTypes:[`list`,`value`],arity:{kind:`exact`}},tuple:{fn:(...e)=>KS(...e),argTypes:[`value`],arity:{kind:`variadic`}},dig:{fn:(...e)=>LS(...e),argTypes:[`value`],arity:{kind:`variadic`}},all:{fn:(...e)=>kS(...e),argTypes:[`truthy`],arity:{kind:`variadic`},returnType:`bool`},any:{fn:(...e)=>AS(...e),argTypes:[`truthy`],arity:{kind:`variadic`},returnType:`bool`}}}function tC(...e){return e.reduce((e,t)=>e+t,0)}function nC(e){return e+1}function rC(e){return e+1}function iC(...e){return e.reduce((e,t)=>e+t,0)}function aC(e){return Math.ceil(e)}function oC(e,t){return Math.trunc(e/t)}function sC(e,...t){return t.reduce((e,t)=>e/t,e)}function cC(e){return Math.floor(e)}function lC(...e){return e.reduce((e,t)=>t>e?t:e,-1/0)}function uC(...e){return e.reduce((e,t)=>Math.max(e,t),-1/0)}function dC(...e){return e.reduce((e,t)=>t<e?t:e,1/0)}function fC(...e){return e.reduce((e,t)=>Math.min(e,t),1/0)}function pC(e,t){return e%t}function mC(...e){return e.reduce((e,t)=>e*t,1)}function hC(...e){return e.reduce((e,t)=>e*t,1)}function gC(e,t=0){let n=10**t;return Math.sign(e)*Math.round(Math.abs(e)*n)/n}function _C(e,t,n){let r=[];if(t<e){if(n>=0)return r;for(let i=e;i>t;i+=n)r.push(i);return r}if(n<=0)return r;for(let i=e;i<t;i+=n)r.push(i);return r}function vC(...e){let t=1;switch(e.length){case 0:return``;case 1:{let n=e[0];return n<1&&(t=-1),_C(1,n+t,t).join(` `)}case 2:{let t=e[0],n=e[1],r=n<t?-1:1;return _C(t,n+r,r).join(` `)}case 3:{let n=e[0],r=e[1],i=e[2];return i<n&&(t=-1,r>0)?``:_C(n,i+t,r).join(` `)}default:return``}}function yC(e,t){return e-t}function bC(e,...t){return t.reduce((e,t)=>e-t,e)}function xC(e){return _C(0,e,e<0?-1:1)}function SC(){return{add:{fn:(...e)=>tC(...e),argTypes:[`truncating-int`],arity:{kind:`variadic`}},sub:{fn:(e,t)=>yC(e,t),argTypes:[`truncating-int`,`truncating-int`],arity:{kind:`exact`}},mul:{fn:(...e)=>mC(...e),argTypes:[`truncating-int`,`truncating-int`],arity:{kind:`variadic`}},div:{fn:(e,t)=>oC(e,t),argTypes:[`truncating-int`,`truncating-int`],arity:{kind:`exact`}},mod:{fn:(e,t)=>pC(e,t),argTypes:[`truncating-int`,`truncating-int`],arity:{kind:`exact`}},min:{fn:(...e)=>dC(...e),argTypes:[`truncating-int`,`truncating-int`],arity:{kind:`variadic`}},max:{fn:(...e)=>lC(...e),argTypes:[`truncating-int`,`truncating-int`],arity:{kind:`variadic`}},floor:{fn:e=>cC(e),argTypes:[`float`],arity:{kind:`exact`}},ceil:{fn:e=>aC(e),argTypes:[`float`],arity:{kind:`exact`}},round:{fn:(e,t)=>gC(e,t),argTypes:[`float`,`int`,`float`],arity:{kind:`variadic`}},addf:{fn:(...e)=>iC(...e),argTypes:[`float`],arity:{kind:`variadic`}},subf:{fn:(e,...t)=>bC(e,...t),argTypes:[`float`,`float`],arity:{kind:`variadic`}},mulf:{fn:(...e)=>hC(...e),argTypes:[`float`,`float`],arity:{kind:`variadic`}},divf:{fn:(e,...t)=>sC(e,...t),argTypes:[`float`,`float`],arity:{kind:`variadic`}},add1:{fn:e=>nC(e),argTypes:[`truncating-int`],arity:{kind:`exact`}},add1f:{fn:e=>rC(e),argTypes:[`float`],arity:{kind:`exact`}},maxf:{fn:(...e)=>uC(...e),argTypes:[`float`,`float`],arity:{kind:`variadic`}},minf:{fn:(...e)=>fC(...e),argTypes:[`float`,`float`],arity:{kind:`variadic`}},biggest:{fn:(...e)=>lC(...e),argTypes:[`truncating-int`,`truncating-int`],arity:{kind:`variadic`}},seq:{fn:(...e)=>vC(...e),argTypes:[`int`],arity:{kind:`variadic`},returnType:`string`},until:{fn:e=>xC(e),argTypes:[`int`],arity:{kind:`exact`},returnType:`list`},untilStep:{fn:(e,t,n)=>_C(e,t,n),argTypes:[`int`,`int`,`int`],arity:{kind:`exact`},returnType:`list`}}}Array.from({length:95},(e,t)=>String.fromCharCode(t+32)).join(``);function CC(e){return Array.from(e)}function wC(e,t){return e===``?CC(t):t.split(e)}function TC(e,t){let n=CC(t);return n.length<=e||e<4?t:`${n.slice(0,e-3).join(``)}...`}function EC(e,t,n){let r=CC(n);return t<7||r.length<t||e<0||e>r.length-t+1?n:`...${r.slice(e,e+t-6).join(``)}...`}const J={Invalid:0,Number:1,UpperCase:2,Alphabet:3,Connector:4,Punct:5,Other:6},DC=/^[-_\s]$/,OC=/^\p{P}$/u,kC=/^\p{L}$/u,AC=/^\p{Lu}$/u,jC=/^\p{N}$/u;function MC(e){return e!==void 0&&DC.test(e)}function NC(e){return e!==void 0&&kC.test(e)}function PC(e){return e!==void 0&&AC.test(e)}function FC(e){return e!==void 0&&jC.test(e)}function IC(e){return e!==void 0&&OC.test(e)}function LC(e,t){if(t>=e.length)return{word:{wt:J.Invalid,text:``},next:t};let n=e[t],r=t+1;if(MC(n)){for(;r<e.length&&MC(e[r]);)r++;return{word:{wt:J.Connector,text:e.slice(t,r).join(``)},next:r}}if(IC(n)){for(;r<e.length&&IC(e[r]);)r++;return{word:{wt:J.Punct,text:e.slice(t,r).join(``)},next:r}}if(PC(n)){if(r>=e.length)return{word:{wt:J.UpperCase,text:n},next:r};if(PC(e[r])){let n=r;for(;n<e.length&&PC(e[n]);)n++;return n<e.length&&NC(e[n])?{word:{wt:J.UpperCase,text:e.slice(t,n-1).join(``)},next:n-1}:{word:{wt:J.UpperCase,text:e.slice(t,n).join(``)},next:n}}if(NC(e[r])){let n=r+1;for(;n<e.length&&NC(e[n])&&!PC(e[n]);)n++;return{word:{wt:J.UpperCase,text:e.slice(t,n).join(``)},next:n}}return{word:{wt:J.UpperCase,text:n},next:r}}if(NC(n)){for(;r<e.length&&NC(e[r])&&!PC(e[r]);)r++;return{word:{wt:J.Alphabet,text:e.slice(t,r).join(``)},next:r}}if(FC(n)){for(;r<e.length&&FC(e[r]);)r++;return{word:{wt:J.Number,text:e.slice(t,r).join(``)},next:r}}for(;r<e.length&&!MC(e[r])&&!NC(e[r])&&!FC(e[r])&&!IC(e[r]);)r++;return{word:{wt:J.Other,text:e.slice(t,r).join(``)},next:r}}function RC(e,t,n){if(t.wt!==J.UpperCase&&t.wt!==J.Connector){e.push(t.text);return}for(let r of t.text)MC(r)?e.push(n):PC(r)?e.push(r.toLowerCase()):e.push(r)}function zC(e,t){if(e.length===0)return``;let n=CC(e),r=[],{word:i,next:a}=LC(n,0);for(;a<n.length;){i.wt!==J.Connector&&RC(r,i,t);let e=i,o=i;if({word:i,next:a}=LC(n,a),e.wt===J.Number){for(;i.wt===J.Alphabet||i.wt===J.Number;)RC(r,i,t),{word:i,next:a}=LC(n,a);i.wt!==J.Invalid&&i.wt!==J.Punct&&i.wt!==J.Connector&&r.push(t);continue}if(e.wt===J.Connector){RC(r,o,t);continue}if(e.wt===J.Punct)continue;if(i.wt!==J.Number){i.wt!==J.Connector&&i.wt!==J.Punct&&r.push(t);continue}if(a>=n.length)continue;let s=i;if({word:i,next:a}=LC(n,a),i.wt!==J.Alphabet){RC(r,s,t),i.wt!==J.Connector&&i.wt!==J.Punct&&r.push(t);continue}for(r.push(t),RC(r,s,t);i.wt===J.Alphabet||i.wt===J.Number;)RC(r,i,t),{word:i,next:a}=LC(n,a);i.wt!==J.Invalid&&i.wt!==J.Connector&&i.wt!==J.Punct&&r.push(t)}return RC(r,i,t),r.join(``).toLowerCase()}function BC(e){if(e.length===0)return``;let t=CC(e),n=[],r=0,i=``;for(;r<t.length;){if(i=t[r],r++,!MC(i)){i=i.toUpperCase();break}n.push(i)}if(r>=t.length)return t.length>0&&n.push(i),n.join(``);for(;r<t.length;){let e=i;if(i=t[r],r++,MC(i)&&MC(e)){n.push(e);continue}MC(e)?i=i.toUpperCase():(i=i.toLowerCase(),n.push(e))}return n.push(i),n.join(``)}function VC(e){return BC(e)}function HC(...e){return e.join(` `)}function UC(e,t){return t.includes(e)}function WC(e,t){return t.startsWith(e)}function GC(e,t){return t.endsWith(e)}function KC(e,t){let n=` `.repeat(Math.max(0,e));return t.split(`
|
|
66
66
|
`).map(e=>n+e).join(`
|
|
67
|
-
`)}function
|
|
68
|
-
`,t)}function
|
|
69
|
-
`)){let n=``;for(let i of t.split(/\s+/))i.length!==0&&(n.length===0?n=i:n.length+1+i.length<=e?n+=` ${i}`:(r.push(n),n=i));n.length>0&&r.push(n)}return r.join(t)}function Ew(e,t,n){return Tw(e,t,n)}function Dw(){return{abbrev:{fn:(e,t)=>EC(e,t),argTypes:[`int`,`string`],arity:{kind:`exact`}},abbrevboth:{fn:(e,t,n)=>DC(e,t,n),argTypes:[`int`,`int`,`string`],arity:{kind:`exact`}},camelcase:{fn:e=>HC(e),argTypes:[`string`],arity:{kind:`exact`},returnType:`string`},cat:{fn:(...e)=>UC(...e),argTypes:[`string`],arity:{kind:`variadic`}},contains:{fn:(e,t)=>WC(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},hasPrefix:{fn:(e,t)=>GC(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},hasSuffix:{fn:(e,t)=>KC(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},indent:{fn:(e,t)=>qC(e,t),argTypes:[`int`,`string`],arity:{kind:`exact`}},initials:{fn:e=>JC(e),argTypes:[`string`],arity:{kind:`exact`}},join:{fn:(e,t)=>YC(e,t),argTypes:[`string`,`list`],arity:{kind:`exact`}},kebabcase:{fn:e=>ZC(e),argTypes:[`string`],arity:{kind:`exact`},returnType:`string`},lower:{fn:e=>QC(e),argTypes:[`string`],arity:{kind:`exact`}},nindent:{fn:(e,t)=>$C(e,t),argTypes:[`int`,`string`],arity:{kind:`exact`}},nospace:{fn:e=>ew(e),argTypes:[`string`],arity:{kind:`exact`},returnType:`string`},plural:{fn:(e,t,n)=>tw(e,t,n),argTypes:[`string`,`string`,`int`],arity:{kind:`exact`},returnType:`string`},quote:{fn:(...e)=>nw(...e),argTypes:[`string`],arity:{kind:`variadic`}},regexQuoteMeta:{fn:e=>rw(e),argTypes:[`string`],arity:{kind:`exact`},returnType:`string`},repeat:{fn:(e,t)=>iw(e,t),argTypes:[`int`,`string`],arity:{kind:`exact`}},replace:{fn:(e,t,n)=>aw(e,t,n),argTypes:[`string`,`string`,`string`],arity:{kind:`exact`}},snakecase:{fn:e=>ow(e),argTypes:[`string`],arity:{kind:`exact`},returnType:`string`},split:{fn:(e,t)=>sw(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},splitList:{fn:(e,t)=>cw(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},splitn:{fn:(e,t,n)=>lw(e,t,n),argTypes:[`string`,`int`,`string`],arity:{kind:`exact`},returnType:`dict`},squote:{fn:(...e)=>dw(...e),argTypes:[`string`],arity:{kind:`variadic`}},substr:{fn:(e,t,n)=>fw(e,t,n),argTypes:[`int`,`int`,`string`],arity:{kind:`exact`}},swapcase:{fn:e=>pw(e),argTypes:[`string`],arity:{kind:`exact`},returnType:`string`},title:{fn:e=>gw(e),argTypes:[`string`],arity:{kind:`exact`}},trim:{fn:e=>_w(e),argTypes:[`string`],arity:{kind:`exact`}},trimAll:{fn:(e,t)=>vw(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},trimPrefix:{fn:(e,t)=>yw(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},trimSuffix:{fn:(e,t)=>bw(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},trunc:{fn:(e,t)=>xw(e,t),argTypes:[`int`,`string`],arity:{kind:`exact`}},untitle:{fn:e=>Sw(e),argTypes:[`string`],arity:{kind:`exact`}},upper:{fn:e=>Cw(e),argTypes:[`string`],arity:{kind:`exact`}},wrap:{fn:(e,t)=>ww(e,t),argTypes:[`int`,`string`],arity:{kind:`exact`}},wrapWith:{fn:(e,t,n)=>Ew(e,t,n),argTypes:[`int`,`string`,`string`],arity:{kind:`exact`}}}}function Ow(e,t){let n=kw(e),r=n.copy();return r.style=jl(n.style,t),r}function kw(e){if(!(e instanceof K))throw TypeError(`template function expected a RichText fragment, got ${typeof e==`object`?Object.prototype.toString.call(e):typeof e}`);return e}function Aw(e){return{fn:(t=>Ow(t,e)),argTypes:[`liftable`],arity:{kind:`exact`},returnType:`T`}}function jw(e){return{fn:((t,n)=>Ow(n,new U({[e]:H.parse(t)}))),argTypes:[`string`,`liftable`],arity:{kind:`exact`},returnType:`T`}}function Mw(e,t){return new U({[e]:t})}function Nw(){let e={};for(let t of Tl)e[t]=Aw(Mw(t,!0)),e[`not_${t}`]=Aw(Mw(t,!1));for(let[t,n]of Object.entries(Dl))e[t]=Aw(Mw(n,!0));return e}const Pw={fn:((e,t)=>Ow(t,U.parse(e))),argTypes:[`string`,`liftable`],arity:{kind:`exact`},returnType:`T`},Fw={fn:((e,t)=>Ow(t,new U({link:e}))),argTypes:[`string`,`liftable`],arity:{kind:`exact`},returnType:`T`};function Iw(){return{fg:jw(`color`),bg:jw(`bgcolor`),...Nw(),link:Fw,style:Pw}}function Lw(e,t){let n;try{n=ds(e.trim())}catch(n){throw n instanceof qo?TypeError(`${t} expected a color (#RRGGBB or #RRGGBBAA), got ${JSON.stringify(e)} — to use a palette name here, wrap it: ${t} (color ${JSON.stringify(e)}) …`,{cause:n}):n}return Rw(n,t,JSON.stringify(e))}function Rw(e,t,n){if(e.alpha===0)throw RangeError(`${t} got ${n}, which is fully transparent: it draws no colour of its own, so there is nothing to compute with — use the colour of the surface it sits on, e.g. (color "background")`);return e}function zw(e,t){return{fn:t,argTypes:e,arity:{kind:`exact`},returnType:`string`}}function Bw(e,t,n,r){let i=r===void 0||e>=r.min&&e<=r.max;if(!Number.isFinite(e)||!i){let i=r===void 0?`a finite number`:`within ${r.min}..${r.max} (${r.note})`;throw RangeError(`${t}'s ${n} must be ${i}, got ${e}`)}return e}const Vw=zw([`string`,`int`],((e,t)=>Ys(Lw(e,`darken`),t).hex)),Hw=zw([`string`,`int`],((e,t)=>Ys(Lw(e,`lighten`),-t).hex)),Uw={min:0,max:100,note:`0 = from, 100 = toward`},Ww=zw([`string`,`string`,`float`],((e,t,n)=>fs(Lw(e,`mix`),Lw(t,`mix`),Bw(n,`mix`,`percentage`,Uw)/100).hex)),Gw={min:1,max:21,note:`4.5 = AA body text, 3 = AA large text`},Kw=zw([`string`],(e=>Zs(Lw(e,`contrastOn`)).hex)),qw={depth:V.TRUECOLOR},Jw=e=>zw([`string`,`string`,`float`],((t,n,r)=>{let{depth:i,terminal:a}=e();return Qs(Lw(t,`readableOn`),Lw(n,`readableOn`),Bw(r,`readableOn`,`ratio`,Gw),i,void 0,a).hex})),Yw={hueShift:`shiftHue`,chromaScale:`scaleChroma`,lightnessScale:`scaleLightness`,lightnessShift:`shiftLightness`};function Xw(){let e={};for(let[t,n]of Object.entries(Yw)){let r=t;e[n]=zw([`string`,`float`],((e,t)=>{let i={...As,[r]:Bw(t,n,`amount`)};return Vs.fromRgba(Lw(e,n)).applyKey(i).toRgba().hex}))}return e}function Zw(e=()=>qw){return{darken:Vw,lighten:Hw,mix:Ww,contrastOn:Kw,readableOn:Jw(e),...Xw()}}function Qw(e,t){if(e.length%2!=0)throw RangeError(`ramp's last stop (position ${String(e[e.length-1])}) has no color — stops are <position> <color> pairs`);let n=[];for(let r=0;r<e.length;r+=2)n.push({at:e[r],color:Rw(Us(t,e[r+1]),`ramp`,JSON.stringify(e[r+1]))});return n}function $w(e){return{color:{fn:(t=>Us(e(),t).hex),argTypes:[`string`],arity:{kind:`exact`},returnType:`string`},ramp:{fn:((t,n,...r)=>new gl(rl(n),Qw(r,e())).at(t).hex),argTypes:[`float`,`string`],arity:{kind:`alternating`,minimum:4},returnType:`string`}}}function eT(e,t,n){if(t.length%2!=0)throw RangeError(`last hold (${String(t[t.length-1])} s) has no ${e} — the arguments are <seconds> <${e}> pairs`);let r=[];for(let e=0;e<t.length;e+=2){let i=t[e];if(!Number.isFinite(i)||i<=0)throw RangeError(`hold ${e/2} must be a positive number of seconds, got ${i}`);r.push({seconds:i,value:n(t[e+1])})}return r}function tT(e){return{frames:{fn:((...t)=>bp(new yp(eT(`frame`,t,kw).map(({seconds:e,value:t})=>({seconds:e,text:t}))),e())),argTypes:[`float`,`liftable`],arity:{kind:`alternating`,minimum:2},returnType:`T`},stepped:{fn:((...t)=>{let n=eT(`color`,t,e=>Lw(e,`stepped`));return n[fl(n.map(e=>e.seconds)).at(e())].value.hex}),argTypes:[`float`,`string`],arity:{kind:`alternating`,minimum:2},returnType:`string`}}}function nT(e){return{...Iw(),...Zw(e)}}new U({color:`red`,dim:!0});const rT=/^(?:(?:global|apac|au|eu|us|us-east-\d|us-west-\d|eu-west-\d|eu-central-\d)\.)?(?:anthropic\.|azure_ai\/|bedrock\/|vertex_ai\/)?claude-(?:(?<family>opus|sonnet|haiku)-(?<newMajor>\d+)(?:-(?<newMinor>\d))?|(?<oldMajor>\d+)(?:-(?<oldMinor>\d))?-(?<oldFamily>opus|sonnet|haiku))(?:[-@]\d{8})?(?:-v\d+:\d+)?(?:-latest)?$/i,iT=/^(?<family>opus|sonnet|haiku)\s+(?<major>\d+)(?:\.(?<minor>\d))?$/i;function aT(e){if(!e)return`Claude`;let t=e.trim().replace(/\s*\([^)]*\)\s*$/,``).replace(/\s*\[[^\]]*\]\s*$/,``).trim(),n=t.match(rT);if(n?.groups){let{family:e,newMajor:t,newMinor:r,oldMajor:i,oldMinor:a,oldFamily:o}=n.groups,s=e||o,c=t||i,l=r||a;if(s&&c)return`${s.charAt(0).toUpperCase()+s.slice(1).toLowerCase()} ${l?`${c}.${l}`:c}`}let r=t.match(iT);if(r?.groups){let e=r.groups.family,t=r.groups.major,n=r.groups.minor;return`${e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()} ${n?`${t}.${n}`:t}`}return t||e}function oT(e){let t=e.match(iT);if(!t?.groups)return e;let n=t.groups.family,r=t.groups.major,i=t.groups.minor;return`${n.charAt(0).toUpperCase()}${i?`${r}.${i}`:r}`}function sT(e){let t=e.split(`/`),n=t.length-1;return t.map((e,t)=>{if(t===n)return e;let r=e.match(/^\.*./);return r?r[0]:e}).join(`/`)}function cT(e){return e.toLocaleString()}function lT(e){if(e.length===0)throw Error(`a cascade needs at least one stop, e.g. "0:calm"`);let t=[];for(let[n,r]of e.entries()){let e=r.indexOf(`:`),i=e<0?NaN:Number(r.slice(0,e));if(!Number.isFinite(i))throw Error(`cascade stop ${n} ("${r}") must be "<position>:<result>", e.g. "80:hot" — the position must be a number`);let a=t[n-1];if(a!==void 0&&i<a.at)throw Error(`cascade stops must be in ascending position order; stop ${n} at ${i} follows stop ${n-1} at ${a.at}`);t.push({at:i,text:r.slice(e+1)})}return t}function uT(e,t){if(!Number.isFinite(e))throw Error(`a cascade needs a finite value, got ${e}`);let n=-1;for(;n+1<t.length&&t[n+1].at<=e;)n++;return(n<0?t[0]:t[n]).text}const dT=[`▁`,`▂`,`▃`,`▄`,`▅`,`▆`,`▇`,`█`],fT=dT.length;function pT(e,t){let n=t===void 0?e:t<=0?[]:e.slice(-t);if(n.length===0)return``;let r=n[0],i=n[0];for(let e of n)e<r&&(r=e),e>i&&(i=e);let a=i-r,o=``;for(let e of n){let t=a===0?0:Math.round((e-r)/a*(fT-1));o+=dT[t]}return o}function mT(e){let t=[];for(let n of e.split(`,`)){let e=n.trim();if(e===``)continue;let r=Number(e);if(!Number.isFinite(r))throw TypeError(`sparkline: non-numeric series element ${JSON.stringify(n)}`);t.push(r)}return t}function hT(e,t,n){if(n.length!==0)throw Error(`${e}: takes at most ${t.length} optional argument${t.length===1?``:`s`} (${t.join(`, `)}), got ${t.length+n.length}`)}const gT=Qm(),_T=[...yh];function vT(){return{basename:{fn:e=>y(e),argTypes:[`string`],arity:{kind:`exact`}},dirname:{fn:e=>b(e),argTypes:[`string`],arity:{kind:`exact`}},abbreviatePath:{fn:e=>sT(e),argTypes:[`string`],arity:{kind:`exact`}},int:{fn:e=>Math.trunc(Ov(e)),argTypes:[`value`],arity:{kind:`exact`}},string:{fn:e=>Dv(e),argTypes:[`value`],arity:{kind:`exact`}},bool:{fn:e=>kv(e),argTypes:[`value`],arity:{kind:`exact`}},urlEncode:{fn:e=>encodeURIComponent(e),argTypes:[`string`],arity:{kind:`exact`}},themes:{fn:()=>gT,argTypes:[],arity:{kind:`exact`}},endcaps:{fn:()=>_T,argTypes:[],arity:{kind:`exact`}},sparkline:{fn:(e,t,...n)=>(hT(`sparkline`,[`width`],n),pT(mT(e),t)),argTypes:[`string`,`int`],arity:{kind:`variadic`}},cascade:{fn:(e,...t)=>uT(e,lT(t)),argTypes:[`float`,`string`],arity:{kind:`variadic`}}}}function yT(e){return{minutesUntilReset:{fn:t=>Math.round(Math.max(0,t*1e3-e().getTime())/6e4),argTypes:[`int`],arity:{kind:`exact`}},formatInteger:{fn:e=>cT(e),argTypes:[`int`],arity:{kind:`exact`}},round:{fn:e=>Math.round(e),argTypes:[`float`],arity:{kind:`exact`}},formatModelName:{fn:e=>aT(e),argTypes:[`string`],arity:{kind:`exact`}},shortenModelName:{fn:e=>oT(e),argTypes:[`string`],arity:{kind:`exact`}}}}function bT(e){let{clock:t,drawnAt:n,extraFuncs:r}=e;return wb({fromString:e=>new K(e),toString:e=>e.plain,isT:e=>e instanceof K,clock:t,missingKey:`error`,funcs:{...pS(),...Dw(),...tC(),...CC(),...aS(t),...Yb(),...kS(),...DS(),...nT(n&&(()=>({depth:n()}))),...tT(()=>t().getTime()/1e3),...vT(),...yT(t),...r??{}}})}function xT(e){return ST(e,new Set(e.names()),``)}function ST(e,t,n){return new Proxy(Object.create(null),{has(e,r){if(typeof r!=`string`)return!1;let i=n?`${n}.${r}`:r;if(t.has(i))return!0;let a=`${i}.`;for(let e of t)if(e.startsWith(a))return!0;return!1},get(r,i){if(typeof i!=`string`)return;let a=n?`${n}.${i}`:i;if(t.has(a))return e.getKind(a)===`document`?wT(a,e.readDocument(a)):e.read(a);let o=`${a}.`;for(let n of t)if(n.startsWith(o))return ST(e,t,a)}})}function CT(e,t){return new Proxy(e,{has:(e,t)=>t===`settings`||Reflect.has(e,t),get:(e,n)=>n===`settings`?t:Reflect.get(e,n)})}function wT(e,t){switch(t.kind){case`ok`:return t.value;case`absent`:throw new Av(e,`variable "${e}" has no value yet: its source has not completed a scan`);case`failed`:throw Error(`variable "${e}": ${t.reason}`)}}function TT(e){return s.existsSync(v.join(e,`.git`))}function ET(e){let t=v.resolve(e);for(;;){if(TT(t))return t;let e=v.dirname(t);if(e===t)return;t=e}}function DT(e){let t=ET(e);return t===void 0?{root:v.resolve(e),git:!1}:{root:t,git:!0}}function OT(e,t){return e.kind===`absent`?L(`none`):e.kind===`failed`?e:t.kind===`failed`?t:L(t.kind===`ok`?`tracked`:`gone`)}function kT(e,t){return e.kind!==`ok`||e.value.state===`open`?e:t.kind===`failed`?z(`HEAD: ${t.reason}`):t.kind===`ok`&&t.value===e.value.head?e:{kind:`earlier`,value:e.value}}const AT={OPEN:`open`,MERGED:`merged`,CLOSED:`closed`},jT={opened:`open`,locked:`open`,merged:`merged`,closed:`closed`};function MT(e,t,n){return Object.hasOwn(t,n)?L(t[n]):z(`${e}: unknown state ${JSON.stringify(n)}`)}function NT(e,t,n){return t.ok?L(t.stdout):t.reason===`non-zero`&&n===`absent`||t.reason===`non-zero`&&n===t.exitCode?R:z(PT(e,t))}function PT(e,t){return`${e}: ${[t.reason,t.exitCode==null?null:`exit ${t.exitCode}`,t.error??FT(t.stderr)].filter(Boolean).join(`, `)}`}function FT(e){return e.trim().split(`
|
|
70
|
-
`,1)[0]??``}function
|
|
71
|
-
`)){let e=n.match(/^remote\.(.+)\.url\s+(\S.*)$/);if(!e)continue;let r=t.get(e[1])??[];r.push(e[2].trim()),t.set(e[1],r)}return[...t].map(([e,t])=>({name:e,urls:t}))}function
|
|
72
|
-
`)){if(!l)continue;if(l.startsWith(`# `)){let e=l.slice(2);if(e.startsWith(`branch.oid `)){let t=e.slice(11).trim();n=t===`(initial)`?R:L(t)}else if(e.startsWith(`branch.head `)){let n=e.slice(12).trim();t=n===`(detached)`?`detached`:n}else if(e.startsWith(`branch.upstream `))r=L(e.slice(16).trim());else if(e.startsWith(`branch.ab `)){let t=e.slice(10).trim().match(/^\+(\d+)\s+-(\d+)$/);t&&(i=L({ahead:parseInt(t[1],10),behind:parseInt(t[2],10)}))}continue}let e=l[0];if(e===`1`||e===`2`){let e=l.slice(2,4);e[0]!==`.`&&a++,e[1]!==`.`&&o++}else e===`u`?c++:e===`?`&&s++}let l=`clean`;return c>0?l=`conflicts`:(a||o||s)&&(l=`dirty`),{branch:t,status:l,aheadBehind:i,oid:n,upstream:r,workingTree:{staged:a,unstaged:o,untracked:s,conflicts:c}}}function
|
|
73
|
-
`).length:0)}async getRemotesAsync(e){let t=aE(v.join(this.resolveCommonGitDir(e),`config`));if(t===null)return this.readRemotes(e);let{key:n,stamp:r}=t,i=this.remotesByConfig.get(n);if(i!==void 0&&i.stamp===r)return this.remotesByConfig.delete(n),this.remotesByConfig.set(n,i),i.remotes;let a=this.readRemotes(e);for(this.remotesByConfig.set(n,{stamp:r,remotes:a}),a.then(e=>{let t=this.remotesByConfig.get(n);e.kind!==`ok`&&t?.remotes===a&&this.remotesByConfig.delete(n)},()=>{this.remotesByConfig.get(n)?.remotes===a&&this.remotesByConfig.delete(n)});this.remotesByConfig.size>256;){let e=this.remotesByConfig.keys().next().value;if(e===void 0)break;this.remotesByConfig.delete(e)}return a}remotesByConfig=new Map;async readRemotes(e){return GT(await this.execGitAsync(WT,{cwd:e,timeout:2e3}))}repoNameFrom(e,t){let n=YT(e);return(n===null?null:ZT(n))??v.basename(t)}async getRepoRemoteUrl(e){let t=await this.getRemotesAsync(e);if(t.kind!==`ok`)return t;let n=XT(t.value);return n===null?R:L(n)}async execForgeAsync(e,t,n){return Le({bin:e,args:[...t],cwd:n.cwd,env:{...process.env},timeoutMs:n.timeout,category:`forge`})}async resolvePullRequest(e,t){let n=UT(t);return n===`github`?eE(`gh pr view`,await this.execForgeAsync(RT.github,[`pr`,`view`,`--json`,`number,state,url,headRefOid`],{cwd:e,timeout:5e3}),/no (open )?pull requests? found/i,rE):n===`gitlab`?eE(`glab mr view`,await this.execForgeAsync(RT.gitlab,[`mr`,`view`,`--output`,`json`],{cwd:e,timeout:5e3}),/no (open )?merge requests? (found|available)/i,iE):R}isWorktree(e){try{let t=v.join(e,`.git`);return!!(s.existsSync(t)&&s.statSync(t).isFile())}catch{return!1}}async getCoreAsync(e){k(`[GIT-EXEC] Running git status --porcelain=v2 in ${e}`);let t=NT(`git status --porcelain=v2 --branch`,await this.execGitAsync([`status`,`--porcelain=v2`,`--branch`],{cwd:e,timeout:2e3}),`failed`);return t.kind===`ok`?L(nE(t.value)):t}};const sE=(e,t)=>k(t);var cE=class{slots=new Map;maxWatchers;counters;logger;closed=!1;constructor(e={}){this.maxWatchers=e.maxWatchers??128,this.counters=e.counters,this.logger=e.logger??sE}acquire(e,t,n){if(this.closed)return{release:()=>{}};let r=this.slots.get(e);if(r)return r.refcount++,r.onInvalidate=n,r.lastTouched=Date.now(),this.slots.delete(e),this.slots.set(e,r),this.makeHandle(e);let i={key:e,watchers:[],refcount:1,debounceTimer:null,onInvalidate:n,targets:t,lastTouched:Date.now()};return this.openWatchers(i),this.slots.set(e,i),this.counters&&this.counters.watchersOpened++,this.evictIfNeeded(),this.makeHandle(e)}makeHandle(e){let t=!1;return{release:()=>{if(t)return;t=!0;let n=this.slots.get(e);n&&(n.refcount=Math.max(0,n.refcount-1),n.refcount===0&&(this.closeSlot(n),this.slots.delete(e)))}}}openWatchers(e){let t=()=>{e.debounceTimer||(e.debounceTimer=setTimeout(()=>{e.debounceTimer=null;try{e.onInvalidate()}catch(e){this.logger(`warn`,`watcher invalidate threw: ${e.message}`)}},50),e.debounceTimer.unref())};for(let n of e.targets.files)try{let r=s.watch(n,{persistent:!1},t);r.on(`error`,e=>{this.logger(`warn`,`watcher error ${n}: ${e.message}`)}),e.watchers.push(r)}catch(e){this.logger(`warn`,`watch failed ${n}: ${e.message}`)}for(let n of e.targets.dirs)try{let r=n.filenames?new Set(n.filenames):null,i=s.watch(n.path,{persistent:!1},(e,n)=>{r&&(!n||!r.has(n))||t()});i.on(`error`,e=>{this.logger(`warn`,`watcher error ${n.path}: ${e.message}`)}),e.watchers.push(i)}catch(e){this.logger(`warn`,`watch failed ${n.path}: ${e.message}`)}}closeSlot(e){e.debounceTimer&&=(clearTimeout(e.debounceTimer),null);for(let t of e.watchers)try{t.close()}catch{}e.watchers=[],this.counters&&this.counters.watchersClosed++}evictIfNeeded(){for(;this.slots.size>this.maxWatchers;){let e=this.slots.keys().next().value;if(e===void 0)break;let t=this.slots.get(e);this.closeSlot(t),this.slots.delete(e),this.counters&&this.counters.watchersEvicted++;try{t.onInvalidate()}catch{}this.logger(`info`,`watcher LRU evict ${e}`)}}size(){return this.slots.size}closeAll(){this.closed=!0;for(let e of this.slots.values())this.closeSlot(e);this.slots.clear()}},lE=class{running=new Set;again=new Set;run(e,t){return this.again.add(e),this.running.has(e)?{kind:`queued`}:(this.running.add(e),{kind:`started`,done:this.loop(e,t)})}async loop(e,t){try{do this.again.delete(e),await t();while(this.again.has(e))}finally{this.running.delete(e),this.again.delete(e)}}clear(){this.running.clear(),this.again.clear()}get size(){return this.running.size}};const uE={showSha:!0,showStashCount:!0};function dE(e){let t=Object.keys(e).sort(),n={};for(let r of t)n[r]=e[r];return JSON.stringify(n)}function fE(e){let t=t=>{try{return s.statSync(v.join(e,t)).mtimeMs}catch{return 0}};return{head:t(`HEAD`),index:t(`index`)}}function pE(e,t){return e.head!==t.head||e.index!==t.index}function mE(e){let t=[],n=v.join(e,`refs/heads`);try{s.statSync(n).isDirectory()&&t.push({path:n})}catch{}return{files:[v.join(e,`HEAD`),v.join(e,`index`)],dirs:t}}var hE=class extends oE{entries=new Map;subscribersByRepo=new Map;fetchInFlight=new Map;resolutions=new Map;prCache=new Map;prFetchInFlight=new Map;refreshes=new lE;hits=0;misses=0;invalidations=0;inner;ttlMs;maxEntries;watchers;ownsWatchers;logger;sanityTimer=null;constructor(e={}){super(),this.inner=e.inner??new oE,this.ttlMs=e.ttlMs??3e4,this.maxEntries=e.maxEntries??64,this.logger=e.logger??Gt,e.watchers?(this.watchers=e.watchers,this.ownsWatchers=!1):(this.watchers=new cE({logger:this.logger}),this.ownsWatchers=!0);let t=e.sanityIntervalMs??3e5;t>0&&(this.sanityTimer=setInterval(()=>this.runSanityCheck(),t),this.sanityTimer.unref())}getWatcherRegistry(){return this.watchers}getStats(){return{size:this.entries.size,hits:this.hits,misses:this.misses,invalidations:this.invalidations,watchers:this.watchers.size()}}resolveEffectiveGitDir(e,t){let n=`${e}|${t??``}`,r=Date.now(),i=this.resolutions.get(n);if(i&&r-i.computedAt<this.ttlMs)return this.resolutions.delete(n),this.resolutions.set(n,i),i.dir;let a=this.inner.resolveEffectiveGitDir(e,t);return this.resolutions.set(n,{dir:a,computedAt:r}),a.catch(()=>{this.resolutions.get(n)?.dir===a&&this.resolutions.delete(n)}),this.evictResolutionsIfNeeded(),a}evictResolutionsIfNeeded(){for(;this.resolutions.size>this.maxEntries;){let e=this.resolutions.keys().next().value;if(e===void 0)break;this.resolutions.delete(e)}}async getGitInfo(e,t={},n){let r=await this.resolveEffectiveGitDir(e,n);return r.kind===`ok`?this.getGitInfoForRoot(r.value,t):r}getGitInfoForRoot(e,t){let n=`${e}|${dE(t)}`,r=Date.now(),i=this.entries.get(n);if(i&&r-i.computedAt<this.ttlMs)return this.entries.delete(n),this.entries.set(n,i),this.hits++,Promise.resolve(L(i.info));let a=this.fetchInFlight.get(n);if(a)return a;let o=this.doFetch(e,n,t,r).finally(()=>{this.fetchInFlight.delete(n)});return this.fetchInFlight.set(n,o),o}async doFetch(e,t,n,r){this.misses++;let i=this.inner.resolveGitDir(e),a=fE(i),o=await this.inner.getGitInfo(e,n);if(o.kind!==`ok`)return o;let s=o.value;n.showPullRequest&&(s.pullRequest=await this.getPullRequestCached(e,s.branch)),this.dropEntry(t);let c=this.watchers.acquire(`git:${e}`,mE(i),()=>this.invalidateRepo(e));return this.entries.set(t,{info:s,computedAt:r,mtime:a,watcher:c,repoRoot:e}),this.evictIfNeeded(),o}async getPullRequestCached(e,t){let n=await this.inner.getRepoRemoteUrl(e);if(n.kind===`failed`)return n;if(n.kind===`absent`)return R;let r=n.value,i=`${e}|${t}|${r}`,a=Date.now(),o=this.prCache.get(i);if(o){let e=o.pr.kind===`failed`?45e3:3e5;if(a-o.computedAt<e)return this.prCache.delete(i),this.prCache.set(i,o),o.pr}let s=this.prFetchInFlight.get(i);if(s)return s;let c=this.inner.resolvePullRequest(e,r).then(e=>(this.prCache.set(i,{pr:e,computedAt:Date.now()}),this.evictPrIfNeeded(),e)).finally(()=>{this.prFetchInFlight.delete(i)});return this.prFetchInFlight.set(i,c),c}evictPrIfNeeded(){for(;this.prCache.size>this.maxEntries;){let e=this.prCache.keys().next().value;if(e===void 0)break;this.prCache.delete(e)}}deliverable(e,t){return e.kind===`failed`?(this.logger(`warn`,`git fetch failed (${t}): ${e.reason}`),null):e.kind===`ok`?e.value:null}subscribe(e,t){let n=!1,r=null;return{firstDelivery:(async()=>{let i=await this.resolveEffectiveGitDir(e);if(n)return;if(i.kind!==`ok`){i.kind===`failed`&&this.logger(`warn`,`git resolve failed (subscribe ${e}): ${i.reason}`),this.safeInvoke(t,null);return}let a=i.value,o=this.subscribersByRepo.get(a);if(!o){let t=this.inner.resolveGitDir(a),n=this.watchers.acquire(`git:${a}`,mE(t),()=>this.invalidateRepo(a));o={workingDir:e,repoRoot:a,callbacks:new Set,watcher:n},this.subscribersByRepo.set(a,o)}o.callbacks.add(t),r={repoRoot:a,entry:o};let s=await this.getGitInfoForRoot(a,{...uE});n||this.safeInvoke(t,this.deliverable(s,a))})(),unsubscribe:()=>{if(n=!0,!r)return;let{repoRoot:e,entry:i}=r;i.callbacks.delete(t),i.callbacks.size===0&&(i.watcher.release(),this.subscribersByRepo.delete(e))}}}invalidateRepo(e){let t=0;for(let[n,r]of this.entries)r.repoRoot===e&&(r.watcher.release(),this.entries.delete(n),t++);t>0&&(this.invalidations+=t,this.logger(`info`,`gitCache invalidate ${e} dropped=${t}`)),this.refreshSubscribers(e)}refreshSubscribers(e){let t=this.subscribersByRepo.get(e);!t||t.callbacks.size===0||this.refreshes.run(e,()=>this.refreshOnce(e))}async refreshOnce(e){let t=this.subscribersByRepo.get(e);if(!t||t.callbacks.size===0)return;let n=await this.getGitInfoForRoot(e,{...uE}),r=this.deliverable(n,e),i=this.subscribersByRepo.get(e);if(!(!i||i.callbacks.size===0))for(let e of[...i.callbacks])i.callbacks.has(e)&&this.safeInvoke(e,r)}safeInvoke(e,t){try{e(t)}catch(e){this.logger(`warn`,`git subscriber threw: ${e.message??String(e)}`)}}dropEntry(e){let t=this.entries.get(e);t&&(t.watcher.release(),this.entries.delete(e))}evictIfNeeded(){for(;this.entries.size>this.maxEntries;){let e=this.entries.keys().next().value;if(e===void 0)break;this.dropEntry(e),this.logger(`info`,`gitCache evict ${e}`)}}runSanityCheck(){let e=new Map;for(let t of this.entries.values()){let n=e.get(t.repoRoot);n||(n=fE(this.inner.resolveGitDir(t.repoRoot)),e.set(t.repoRoot,n)),pE(t.mtime,n)&&this.invalidateRepo(t.repoRoot)}}runSanityCheckNow(){this.runSanityCheck()}close(){this.sanityTimer&&=(clearInterval(this.sanityTimer),null);for(let e of this.entries.values())e.watcher.release();this.entries.clear();for(let e of this.subscribersByRepo.values())e.callbacks.clear(),e.watcher.release();this.subscribersByRepo.clear(),this.refreshes.clear(),this.fetchInFlight.clear(),this.prCache.clear(),this.prFetchInFlight.clear(),this.resolutions.clear(),this.ownsWatchers&&this.watchers.closeAll()}};const gE=/\r\n|\r|\n/g,_E=e=>L(e.replace(gE,` `).trim());function vE(e){return t=>{let n=e.exec(t)?.[1];return n===void 0?z(`regex no-match`):L(n.replace(gE,` `))}}const yE=e=>{try{return L(JSON.parse(e))}catch(e){return z(`JSON parse failed: ${e.message}`)}},bE=e=>e.getTime()/1e3,xE=e=>new Date(e*1e3);function SE(e,t){return t.kind!==`ttl`||t.durationMs>=500?t:(k(`declareShell "${e}": ttl ${t.durationMs}ms below floor 500ms; clamping`),{kind:`ttl`,durationMs:500})}function CE(e){let t=/^(\d+(?:\.\d+)?)(ms|s|m|h)$/.exec(e);if(!t)throw RangeError(`Invalid duration: "${e}"`);let n=parseFloat(t[1]);switch(t[2]){case`ms`:return n;case`s`:return n*1e3;case`m`:return n*6e4;case`h`:return n*36e5;default:throw RangeError(`Unexpected duration unit: "${t[2]}"`)}}const wE=`session.id`;function TE(e,t,n){return{where:`output of "${e}" in ${t}`,read:async()=>{let r=await Le({bin:`/bin/sh`,args:[`-c`,e],cwd:t,category:`user-shell`,signal:n});if(!r.ok&&r.reason===`aborted`)throw n.reason;return r.ok?L(r.stdout):z(`shell "${e}" ${r.exitCode===null?[r.reason,r.error].filter(e=>e!==void 0).join(`: `):`exited with code ${r.exitCode}`} in ${t}`)}}}function EE(e,t,n){return{where:`"${e}"`,read:async()=>{try{let r=await ce(e,{encoding:`utf8`,signal:n});return L(t===`first-line`?r.split(/\r?\n/)[0]??``:r)}catch{if(n.aborted)throw n.reason;return z(`file unreadable: ${e}`)}}}}function DE(e,t,n){if(e.kind!==`ok`)return e;let r=t(e.value);return r.kind===`failed`?z(`${r.reason} in ${n}`):r}const OE=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],kE=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],AE=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`],jE=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function ME(e,t){let n=[[`2006`,e=>String(e.getFullYear())],[`January`,e=>OE[e.getMonth()]],[`Monday`,e=>AE[e.getDay()]],[`Jan`,e=>kE[e.getMonth()]],[`Mon`,e=>jE[e.getDay()]],[`15`,e=>String(e.getHours()).padStart(2,`0`)],[`06`,e=>String(e.getFullYear()%100).padStart(2,`0`)],[`01`,e=>String(e.getMonth()+1).padStart(2,`0`)],[`02`,e=>String(e.getDate()).padStart(2,`0`)],[`04`,e=>String(e.getMinutes()).padStart(2,`0`)],[`05`,e=>String(e.getSeconds()).padStart(2,`0`)],[`PM`,e=>e.getHours()<12?`AM`:`PM`],[`pm`,e=>e.getHours()<12?`am`:`pm`],[`1`,e=>String(e.getMonth()+1)],[`2`,e=>String(e.getDate())],[`3`,e=>String(e.getHours()%12||12)],[`4`,e=>String(e.getMinutes())],[`5`,e=>String(e.getSeconds())]],r=``,i=0;for(;i<e.length;){let a=!1;for(let[o,s]of n)if(e.startsWith(o,i)){r+=s(t),i+=o.length,a=!0;break}a||(r+=e[i],i++)}return r}const NE={branch:`string`,sha:`string`,dirty:`boolean`,ahead:`number`,behind:`number`,stash:`number`};function PE(e,t,n,r){if(e===null){if(n!==void 0)return n;let e=NE[t];try{return HE(r,e)}catch{return UE(e)}}switch(t){case`branch`:return e.branch===`detached`?``:e.branch;case`sha`:return ki(e.sha,``);case`dirty`:return e.status!==`clean`;case`ahead`:return ki(e.aheadBehind,{ahead:0,behind:0}).ahead;case`behind`:return ki(e.aheadBehind,{ahead:0,behind:0}).behind;case`stash`:return ki(e.stashCount,0)}}function FE(e){try{return h(e)}catch{return e}}function IE(e){try{return g(e).isDirectory()}catch{return!1}}function LE(e){let t=FE(e);return IE(t)?{dir:t,name:null,leaf:!0}:bv(t)}const RE=e=>`${e.dir}\0${e.name??``}`;var zE=class{watchers=new Map;subscribe(e,t,n){let r=this.watchers.get(e)??this.arm(e);return r.subscribers.set(t,n),r.watcher===null&&n(r.failure),()=>this.unsubscribe(e,t)}arm(e){let t={watcher:null,failure:``,target:LE(e),subscribers:new Map};return t.watcher=this.open(e,t,t.target),this.watchers.set(e,t),t}rearm(e,t){let n=LE(e);if(t.watcher!==null&&RE(n)===RE(t.target))return;let r=this.open(e,t,n);r!==null&&(t.watcher?.close(),t.watcher=r,t.target=n)}open(e,t,n){let{dir:r,name:i}=n,a=v.basename(r);try{return _(r,(n,r)=>{if(!(r===null||i===null||r===i)&&r!==a)return;let o=t.target.leaf;if(this.rearm(e,t),!(!o&&!t.target.leaf))for(let e of t.subscribers.keys())e()})}catch(n){let i=`watch_file ${e}: cannot watch ${r} — ${n instanceof Error?n.message:String(n)}`;t.failure=i;for(let e of t.subscribers.values())e(i);return null}}unsubscribe(e,t){let n=this.watchers.get(e);n&&(n.subscribers.delete(t),n.subscribers.size===0&&(n.watcher?.close(),this.watchers.delete(e)))}dispose(){for(let{watcher:e}of this.watchers.values())e?.close();this.watchers.clear()}size(){return this.watchers.size}},BE=class{buckets=new Map;subscribe(e,t){let n=this.buckets.get(e);if(!n){let t=new Set;n={timer:pe(()=>{for(let e of t)e()},e),callbacks:t},this.buckets.set(e,n)}return n.callbacks.add(t),()=>this.unsubscribe(e,t)}unsubscribe(e,t){let n=this.buckets.get(e);n&&(n.callbacks.delete(t),n.callbacks.size===0&&(de(n.timer),this.buckets.delete(e)))}dispose(){for(let{timer:e}of this.buckets.values())de(e);this.buckets.clear()}bucketCount(){return this.buckets.size}};function VE(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n)return;n=n[e]}return n}function HE(e,t){if(typeof e!=`string`&&typeof e!=`number`&&typeof e!=`boolean`)throw TypeError(`Expected string|number|boolean from payload, got ${typeof e}`);return t===`string`?Dv(e):t===`number`?Ov(e):kv(e)}function UE(e){return e===`number`?0:e===`boolean`?!1:``}var WE=class{inputMetas=new Map;lastErrors=new Map;policyFaults=new Map;watchMgr=new zE;ttlMgr=new BE;gitSubscriptions=new Map;cleanups=[];inFlight=new Map;reads=new lE;abort=new AbortController;drawn=wv.observable.box(V.TRUECOLOR);drawnAt=()=>this.drawn.get();instant=wv.observable.box(null);now=()=>{let e=this.instant.get();if(e===null)throw Error(`the time was read before any render published its instant`);return xE(e)};engine=bT({clock:this.now,drawnAt:this.drawnAt});gitProvider;ownsGitProvider;sessionState;constructor(e,t=``,n,r){this.store=e,this.defaultEmptyValue=t,n?(this.gitProvider=n,this.ownsGitProvider=!1):(this.gitProvider=new hE({sanityIntervalMs:0}),this.ownsGitProvider=!0),this.sessionState=r}get variableStore(){return this.store}declareLiteral(e,t){this.store.defineBox(e,Ev(t),t)}declareFailedDocument(e,t){this.store.defineDocument(e,z(t))}declareInput(e,t,n,r){let i=r===void 0?this.defaultFor(n):r;this.store.defineBox(e,n,i),this.inputMetas.set(e,{path:t,varDefault:r})}declareEnv(e,t,n){let r=process.env[t];if(r!==void 0){this.store.defineBox(e,`string`,r);return}let i=n===void 0?typeof this.defaultEmptyValue==`string`?this.defaultEmptyValue:``:n;this.store.defineBox(e,`string`,i),this.recordError(e,`env var "${t}" is not set`)}declareShell(e,t,n){this.declareSource(e,TE(t,n.cwd,this.abort.signal),SE(e,n.cache),n.parse)}declareFile(e,t,n){this.declareSource(e,EE(t,n.readMode??`whole`,this.abort.signal),n.cache,n.parse)}declareSource(e,t,n,r){let i=this.publisherFor(e,r,t.where),a=()=>this.runSource(e,t,i);a(),this.registerCachePolicy(e,n,a)}publisherFor(e,t,n){switch(t.kind){case`text`:return this.scalarPublisher(e,_E,t.default,n);case`regex`:return this.scalarPublisher(e,vE(t.regex),t.default,n);case`json`:return this.documentPublisher(e,t.default,n)}}scalarPublisher(e,t,n,r){let i=this.stringInitial(n);return this.store.defineBox(e,`string`,i),n=>{let a=DE(n,t,r);this.noteOutcome(e,a),this.store.setBox(e,ki(a,i))}}documentPublisher(e,t,n){let r=t===void 0?R:L(t);this.store.defineDocument(e,r);let i,a=!1;return this.cleanups.push(()=>clearTimeout(i)),o=>{clearTimeout(i);let s=o.kind===`ok`&&o.value.trim()===``?R:o,c=DE(s,yE,n);this.noteOutcome(e,c);let l=c.kind===`ok`||s.kind===`ok`||t===void 0?c:r,u=a&&s.kind===`ok`&&c.kind!==`ok`,d=()=>{a=c.kind===`ok`,this.store.setDocument(e,l)};u?i=setTimeout(d,250):d()}}runSource(e,t,n){let r=this.reads.run(e,()=>t.read().then(n,e=>{if(e!==this.abort.signal.reason)throw e}));r.kind===`started`&&this.track(e,r.done)}track(e,t){let n=t.finally(()=>{this.inFlight.get(e)===n&&this.inFlight.delete(e)});this.inFlight.set(e,n)}async settled(e){let t=Date.now()+e;for(;this.inFlight.size>0;){let e=t-Date.now();if(e<=0)break;let n,r=await Promise.race([Promise.all(this.inFlight.values()).then(()=>`settled`),new Promise(t=>{n=setTimeout(()=>t(`deadline`),e)})]);if(clearTimeout(n),r===`deadline`)break}return[...this.inFlight.keys()]}declareTemplate(e,t,n={}){let r=this.engine.parse(t);this.declareDerived(e,()=>r.evaluate(xT(this.store)).map(e=>e.plain).join(``),n.varDefault)}declareTime(e,t){this.declareDerived(e,()=>ME(t.format,this.now()),t.varDefault)}declareDerived(e,t,n){this.store.defineComputed(e,`string`,()=>{try{let n=t();return this.lastErrors.delete(e),n}catch(t){let r=t instanceof Error?t.message:String(t);if(this.recordError(e,r),n===void 0)throw jv(t)?new Av(e,`variable "${e}": ${r}`):Error(`variable "${e}": ${r}`);return n}})}declareGit(e,t){let n=NE[t.field],r=t.varDefault===void 0?UE(n):HE(t.varDefault,n);this.store.defineBox(e,n,r);let i=this.gitSubscriptions.get(t.cwd);if(!i){let e=new Map,n=this.gitProvider.subscribe(t.cwd,t=>{this.store.runInAction(()=>{for(let[n,r]of e)for(let{name:e,varDefault:i}of r)this.store.setBox(e,PE(t,n,i,this.defaultEmptyValue))})});i={fieldSubs:e,firstDelivery:n.firstDelivery,unsubscribe:n.unsubscribe},this.gitSubscriptions.set(t.cwd,i)}let a=i.fieldSubs.get(t.field);a||(a=[],i.fieldSubs.set(t.field,a)),a.push({name:e,varDefault:t.varDefault}),this.track(e,i.firstDelivery)}declareState(e,t){if(!this.sessionState)throw Error(`declareState("${e}"): SourceRegistry was constructed without a SessionState — state-kind variables require a SessionState (the daemon provides one; tests must supply one)`);let n=this.sessionState,r=t.varDefault??this.stringInitial(void 0);this.store.defineComputed(e,`string`,e=>{let i=e(wE);if(typeof i!=`string`||!i)return r;let a=n.get(i,t.key);return a===null?r:a})}stateRevision(){let e=this.store.has(`session.id`)?this.store.read(wE):``;return this.sessionState!==void 0&&typeof e==`string`&&e!==``?this.sessionState.revision(e):0}applyInput(e){this.store.runInAction(()=>{for(let[t,n]of this.inputMetas){let r=VE(e,n.path),i=this.store.getType(t);if(r!==void 0)try{this.store.setBox(t,HE(r,i)),this.lastErrors.delete(t)}catch(e){this.applyFallback(t,i,n.varDefault,e instanceof Error?e.message:String(e))}else this.applyFallback(t,i,n.varDefault,`input path "${n.path}" not found in payload`)}})}drawAt(e){this.store.runInAction(()=>this.drawn.set(e))}renderAt(e){this.store.runInAction(()=>this.instant.set(e))}getLastError(e){let t=this.lastErrors.get(e),n=this.policyFaults.get(e);return n===void 0?t:t===void 0?n:{timestamp:t.timestamp,message:`${n.message}; ${t.message}`}}cachePolicyFaults(){return this.policyFaults}dispose(){this.abort.abort();for(let e of this.cleanups)e();this.cleanups.length=0;for(let e of this.gitSubscriptions.values())e.unsubscribe();return this.gitSubscriptions.clear(),this.reads.clear(),this.watchMgr.dispose(),this.ttlMgr.dispose(),this.ownsGitProvider&&this.gitProvider.close(),this.store.dispose()}registerCachePolicy(e,t,n){switch(t.kind){case`never`:break;case`ttl`:{let e=this.ttlMgr.subscribe(t.durationMs,n);this.cleanups.push(e);break}case`watch_file`:{let r=this.watchMgr.subscribe(t.path,n,t=>this.notePolicy(e,z(t)));this.cleanups.push(r);break}case`key`:{let r=this.engine.parse(t.template),i=()=>{try{return L(r.evaluate(xT(this.store)).map(e=>e.plain).join(``))}catch(e){return jv(e)?R:z(`cache key: ${e instanceof Error?e.message:String(e)}`)}},a=i();this.notePolicy(e,a);let o=a.kind===`ok`?a.value:void 0,s=(0,wv.reaction)(i,t=>{this.notePolicy(e,t),!(t.kind!==`ok`||t.value===o)&&(o=t.value,n())});this.cleanups.push(s);break}case`depends_on`:{let e=(0,wv.reaction)(()=>t.varNames.map(e=>this.store.changeKey(e)).join(`,`),n);this.cleanups.push(e);break}}}applyFallback(e,t,n,r){if(this.recordError(e,r),n!==void 0){this.store.setBox(e,n);return}try{this.store.setBox(e,HE(this.defaultEmptyValue,t))}catch{this.store.setBox(e,UE(t))}}defaultFor(e){try{return HE(this.defaultEmptyValue,e)}catch{return UE(e)}}stringInitial(e){return e===void 0?typeof this.defaultEmptyValue==`string`?this.defaultEmptyValue:``:e}recordError(e,t){this.lastErrors.set(e,{timestamp:Date.now(),message:t})}notePolicy(e,t){t.kind===`failed`?this.policyFaults.set(e,{timestamp:Date.now(),message:t.reason}):this.policyFaults.delete(e)}noteOutcome(e,t){t.kind===`ok`?this.lastErrors.delete(e):this.recordError(e,t.kind===`failed`?t.reason:`no value`)}};const GE={project_dir:{kind:`input`,path:`workspace.project_dir`,default:``},[wE]:{kind:`input`,path:`session_id`,default:``},transcript_path:{kind:`input`,path:`transcript_path`,default:``},resume_command:{kind:`input`,path:`resumeCommand`,default:``},config_path:{kind:`input`,path:`configPath`,default:``},"theme.effective":{kind:`input`,path:`theme.effective`,default:``},"style.effective":{kind:`input`,path:`style.effective`,default:``},"effect.effective":{kind:`input`,path:`effect.effective`,default:``},"preset.effective":{kind:`input`,path:`preset.effective`,default:``},"preset.customized":{kind:`input`,path:`preset.customized`,type:`boolean`,default:!1},"preset.bundled":{kind:`input`,path:`preset.bundled`,type:`boolean`,default:!0},"endcaps.effective":{kind:`input`,path:`endcaps.effective`,default:``},"variation.effective":{kind:`input`,path:`variation.effective`,default:``},"shade.effective":{kind:`input`,path:`shade.effective`,default:``},"colorCompatibility.effective":{kind:`input`,path:`colorCompatibility.effective`,default:``},"transitions.effective":{kind:`input`,path:`transitions.effective`,type:`boolean`,default:!1},"autoWrap.effective":{kind:`input`,path:`autoWrap.effective`,type:`boolean`,default:!0},"padding.effective":{kind:`input`,path:`padding.effective`,type:`number`,default:1},"updateNotice.effective":{kind:`input`,path:`updateNotice.effective`,type:`boolean`,default:!0},...Object.fromEntries(Pa.map(e=>[La(e),{kind:`input`,path:La(e),type:`boolean`,default:!1}])),"term.cols":{kind:`input`,path:`term.cols`,type:`number`,default:80},"tmux.pane":{kind:`input`,path:`tmux.pane`,default:``},"autocompact.window":{kind:`input`,path:`autocompact.window`,type:`number`,default:-1},...Object.fromEntries([`applied`,`lower`,`higher`].map(e=>[`autocompact.${e}`,{kind:`input`,path:`autocompact.${e}`,type:`number`,default:0}])),"autocompact.error":{kind:`input`,path:`autocompact.error`,default:``},"git.repoUrl":{kind:`input`,path:`git.repoUrl`,default:``}},KE=`ne .tmux.pane ""`;function qE(e,t,n){let r=new Set,i=e=>{for(let t of uv(e??``,n).keys())r.add(t)};for(let t of Object.values(e.segments))i(t.template),i(t.bg),i(t.fg),i(t.when);for(let e of t)for(let t of e_(e))i(t.when),t.kind===`segment`&&(i(t.lead),i(t.trail));for(let t of Object.values(e.variables))t.kind===`template`&&i(t.template),t.kind===`state`&&r.add(wE);for(let t of Object.values(e.actions)){r.add(wE),`copy`in t&&i(t.copy),`open`in t&&i(t.open);let e=`set`in t?Ga.get(t.set):void 0,n=`persist`in t?Wa.get(t.persist):void 0;e!==void 0&&r.add(e),n!==void 0&&r.add(n)}return r}function JE(e,t,n){let r=vv({...n,variables:{...n.variables,...e.variables},segments:{...n.segments,...e.segments}}),i={};for(let a of qE(e,t,n.helpers)){if(_v(a,r))continue;let e=GE[a];if(e===void 0)throw Error(`synthesized chrome reads ".${a}", which it does not declare and PAYLOAD_INPUTS does not supply`);i[a]=e}return i}function YE(e){return e.replace(/[^A-Za-z0-9]+/g,`_`)}var XE=class extends Error{file;issues;warnings;constructor(e,t,n=[]){super(eD(e,t)),this.name=`ConfigError`,this.file=e,this.issues=t,this.warnings=n}};function Y(e,t){let n=0,r;for(let i of t){if(i===``||/^\d+$/.test(i))continue;let t=ZE(e,n,i);if(t===-1)return r===void 0?void 0:QE(e,r);n=t,r=t}return r===void 0?void 0:QE(e,r)}function ZE(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 QE(e,t){let n=1;for(let r=0;r<t&&r<e.length;r++)e.charCodeAt(r)===10&&n++;return n}function $E(e,t){try{return Lr(t),null}catch(n){if(!(n instanceof jr))throw n;return`${e}:${QE(t,n.offset)}: ${n.reason} — the settings menu cannot edit this file until it is fixed`}}function eD(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(`
|
|
74
|
-
`)}const tD=`groups.`,nD=`menus.`,rD=`edit.`,X=`candybar.`,iD=[tD,nD,rD,X];function aD(e){return iD.some(t=>e.startsWith(t))}function oD(e){let t=YE(e);return iD.find(e=>t.startsWith(YE(e)))}function sD(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:Y(e.source,[`root`])})}function cD(e){return e}function lD(e,t,n){return n===void 0?nD+YE(e)+`.`+YE(t):uD(n)}function uD(e){return nD+YE(e)}function dD(e,t){return e+`.`+t}function fD(e){return e+`.page`}const pD=[`closeOnPick`,`paged`,`key`,`distribution`],mD=e=>pD.includes(e),hD=`"closeOnPick" (bool, default false), "paged" (bool, default true), "key" (string, accordion grouping), "distribution" (one of ${Zp.map(e=>`"${e}"`).join(`, `)}; default "van-der-corput")`;function gD(e){for(let t of Object.keys(e))if(!mD(t))throw Error(`unknown {{ menu }} option "${t}" — the options dict takes ${hD}`);let t=(t,n)=>{let r=e[t];if(r===void 0)return n;if(typeof r!=`boolean`)throw Error(`{{ menu }} option "${t}" must be a boolean, got ${JSON.stringify(r)} (e.g. (dict "${t}" ${String(!n)}))`);return r},n=e.key;if(n!==void 0&&typeof n!=`string`)throw Error(`{{ menu }} option "key" must be a string naming the accordion group, got ${JSON.stringify(n)}`);if(n===``)throw Error(`{{ menu }} has an empty accordion key — a shared key must be a non-empty name (or omit "key" for an independent menu)`);let r=e.distribution;if(r!==void 0&&!Qp(r))throw Error(`{{ menu }} option "distribution" must be one of: ${Zp.join(`, `)}; got ${JSON.stringify(r)}`);return{closeOnPick:t(`closeOnPick`,!1),paged:t(`paged`,!0),key:n,distribution:em(r)}}const _D=e=>`from`in e?e.from:e.themes;function vD(e,t,n){return e===`bool`?Ih(t)!==null:`min`in e?Lh(t,e)!==null:Y_(_D(e),n).members.includes(t)}function yD(e,t){if(e===`bool`)return Ph.join(` or `);if(!(`min`in e)){let n=_D(e),{members:r}=Y_(n,t),i=r.map(e=>JSON.stringify(e));if(r.length<=8)return`one of ${i.join(`, `)}`;let a=typeof n==`string`?` "${n}"`:``;return`one of the ${r.length}${a} names, such as ${i.slice(0,3).join(`, `)}`}return`an integer from ${e.min} to ${e.max}`}function bD(e){return{label:e.label,domain:xD(e.domain)}}function xD(e){return e===`theme`?{themes:K_}:e===`bool`||`min`in e?e:{from:e}}function SD(e,t,n,r,i){let a=mr(e.label),{domain:o}=e;if(o===`bool`)return{kind:`inline`,template:`{{ action "${r}" "☑ ${a}" "☐ ${a}" }}`,actions:{[r]:{set:t,cycle:[...Ph]}},variables:{}};if(`from`in o)return CD(t,r,i,o.from,e=>({template:`{{ "${a}" }} {{ carousel "${e.apply}" 0 "${e.open}" }}`,rows:[`{{ picker "${e.apply}" "${e.page}" false true true }}`]}));if(`themes`in o)return CD(t,r,i,o.themes,e=>({template:`{{ action "${e.open}" "${a}" .${n} }} {{ action "${e.open}" (swatch "${e.apply}") }}`,rows:[`{{ swatches "${e.apply}" "${e.page}" }}`,`{{ themePreview "${e.apply}" }}`]}));let s=e=>({set:t,min:o.min,max:o.max,by:e});return{kind:`inline`,template:`{{ action "${r}.down" "◀" }} {{ "${a}" }} {{ .${n} }} {{ action "${r}.up" "▶" }}`,actions:{[`${r}.down`]:s(-o.step),[`${r}.up`]:s(o.step)},variables:{}}}function CD(e,t,n,r,i){let a={variable:n,key:n,member:t},o=dD(n,t),s=`${t}.open`,c=fD(n),l=`${c}.current`,{template:u,rows:d}=i({apply:t,open:s,page:c});return{kind:`picker`,template:u,actions:{[t]:{set:e,from:r},[o]:Sr(n,t),[c]:{set:c,int:!0},[l]:{set:c,to:`-1`},[s]:{do:[o,l]}},variables:{[n]:xr(n,ur),[c]:{kind:`state`,key:c,default:`0`}},list:{ref:a,rows:d}}}function wD(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 ${AD(i)}`,line:Y(e.source,[...t.split(`.`),r])}),null)}function TD(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 ${AD(i)}`,line:Y(e.source,[...t.split(`.`),`default`])});return}return i}}function ED(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 ${AD(i)}`,line:Y(e.source,[...t.split(`.`),r])});return}return i}}function DD(e,t,n){let r=ED(e,t,n,`palette`);if(r!==void 0){if(!e.allowedPalettes.has(r)){e.issues.push({path:`${t}.palette`,message:`Unknown palette "${r}"${Ym(r)}. Expected one of: ${[...e.allowedPalettes].sort().join(`, `)}`,line:Y(e.source,[...t.split(`.`),`palette`])});return}return r}}function OD(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 ${Z(a)}`,line:Y(e.source,[...t.split(`.`),r])});return}return a}}function kD(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function AD(e){return e===null?`null`:Array.isArray(e)?`array`:typeof e}function Z(e){return typeof e==`string`?JSON.stringify(e):e===void 0?`undefined`:String(e)}function jD(e,t,n,r){return kD(r)?(FD(e,n,r,t.noun,new Set(Object.keys(t.fields)),MD(e,t.removed??{},n,r)),ND(e,t.fields,n,r)):(e.issues.push({path:n,message:`${n} must be an object, got ${AD(r)}`,line:Y(e.source,n.split(`.`))}),null)}function MD(e,t,n,r){let i=Object.entries(t).filter(([e])=>r[e]!==void 0);for(let[t,r]of i)ID(e,`${n}.${t}`,`${n}.${t} was removed: ${r}`);return new Set(i.map(([e])=>`${n}.${e}`))}function ND(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 PD=new Set;function FD(e,t,n,r,i,a=PD){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:Y(e.source,[...t.split(`.`),o])})}function ID(e,t,n){return e.issues.push({path:t,message:n,line:Y(e.source,t.split(`.`))}),null}function LD(e,t,n,r){if(!kD(r))return e.issues.push({path:n,message:`${t.noun} must be an object, got ${AD(r)}`,line:Y(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:Y(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:Y(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:Y(e.source,n.split(`.`))}),null;let c=o[0];return i[c].parse(e,`${n}.${c}`,r[c])}function RD(e,t,n,r){if(!kD(r))return e.issues.push({path:n,message:`${n} must be an object, got ${AD(r)}`,line:Y(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 ${AD(i)}`,line:Y(e.source,n.split(`.`))}),null;let a=t.arms;if(!(i in a))return e.issues.push({path:`${n}.${t.tag}`,message:`Unknown ${t.noun} "${i}". Expected one of: ${Object.keys(a).join(`, `)}`,line:Y(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 FD(e,n,r,`${i} ${t.memberNoun} key`,o.keys,l),c}function zD(e,t,n){return{json:$D(ZD(n),e,t),keys:new Set([e,...Object.keys(n)])}}function BD(e){return(...t)=>e()(...t)}function VD(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:Y(n.source,o.split(`.`))}),null}return a}}function HD(){return{required:!1,json:{type:`string`},parse:(e,t,n,r)=>ED(e,t,r,n)}}function UD(){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 ${AD(i)}`,line:Y(e.source,[n])});return}return i}}}}function WD(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 ${Z(o)}`,line:Y(e.source,[i])});return}return o}}}}function GD(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 ${Z(a)}`,line:Y(e.source,[r])});return}return a}}}}function KD(){return{required:!1,json:{type:`string`},parse:(e,t,n,r)=>DD(e,t,r)}}function qD(){return{required:!0,json:{type:`string`},parse:(e,t,n,r)=>wD(e,t,r,n)??void 0}}function JD(e,t){return x(t)?null:`${e} must be an absolute path (\`~\` and relative paths are not expanded), got ${JSON.stringify(t)}`}function YD(){return{required:!0,json:{type:`string`,pattern:`^/`},parse:(e,t,n,r)=>{let i=wD(e,t,r,n);if(i===null)return;let a=JD(`${t}.${n}`,i);return a===null?i:ID(e,`${t}.${n}`,a)??void 0}}}function XD(e){return{required:!1,json:{enum:[...e]},parse:(t,n,r,i)=>OD(t,n,i,r,e)}}function ZD(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 QD(e){return ZD(e.fields)}function $D(e,t,n){let r=e,i={[t]:{const:n},...r.properties},a=[t,...r.required??[]];return{...r,properties:i,required:a}}function eO(e){let t=e.arms;return{anyOf:Object.values(t).map(e=>e.json)}}function tO(e){let t=e.arms;return{anyOf:Object.entries(t).map(([e,t])=>({type:`object`,properties:{[e]:t.json},required:[e],additionalProperties:!1}))}}const nO={required:!1,json:{enum:[...wh]},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: ${wh.join(`, `)}`,line:Y(e.source,[...t.split(`.`),n])});return}return OD(e,t,r,n,wh)}},rO={required:!1,json:{type:`string`},parse:(e,t,n,r)=>{let i=ED(e,t,r,n);return ih(i)?i:DD(e,t,r)}},iO={required:!1,json:{anyOf:[{enum:[...mh]},{type:`string`,pattern:`\\{\\{`}]},parse:(e,t,n,r)=>{let i=r[n];return typeof i==`string`&&ih(i)?i:OD(e,t,r,n,mh)}},aO=/^[^\r\n]*\S[^\r\n]*$/u,oO=RegExp(`^(?:✖|✕)[\\uFE0E\\uFE0F]?$`,`u`),sO={required:!1,json:{type:`string`,pattern:aO.source,not:{pattern:oO.source}},parse:(e,t,n,r)=>{let i=ED(e,t,r,n);if(i===void 0||aO.test(i)&&!oO.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:Y(e.source,[...t.split(`.`),n])})}};function cO(e){return{spec:XD(e),domain:{from:e}}}function lO(){return{spec:UD(),domain:`bool`}}function uO(e){return{spec:e,domain:`text`}}const dO={default_empty_value:uO(HD()),default_separator:uO(HD()),palette:{spec:rO,domain:{themes:`themes`}},style:{spec:HD(),domain:{from:`styles`}},effect:{spec:iO,domain:{from:mh}},preset:{spec:HD(),domain:{from:`presets`}},endcaps:cO(yh),variation:cO(Eh),shade:cO(kh),autoWrap:lO(),padding:{spec:WD(Fh),domain:{...Fh,step:1}},updateNotice:lO(),transitions:lO(),experimentalBand:lO(),experimentalStatusline:lO(),experimentalPane:lO(),colorCompatibility:{spec:nO,domain:{from:wh}},menuGlyph:uO(sO)},fO=Object.fromEntries(Object.entries(dO).map(([e,t])=>[e,t.spec]));function pO(e){return dO[e].domain}function mO(e){let t=pO(e);if(t===`text`)throw Error(`globals.${e} is free text, which no control can change — list it in UNCONTROLLED_GLOBALS instead of SETTINGS`);return t}function hO(e,t){return{required:!1,json:{not:{},description:`not allowed here — ${e}`},parse:(e,n,r,i)=>{i[r]!==void 0&&e.issues.push({path:`${n}.${r}`,message:t(`${n}.${r}`),line:Y(e.source,[...n.split(`.`),r])})}}}function gO(e){return hO(`${e} cannot select a preset`,t=>`${t}: ${e} cannot select a preset. Which preset is active is resolved once, as session pick over globals.preset over "default"; a fragment naming another would be a second authority over that. Set the default arrangement in the top-level globals.preset instead.`)}function _O(e){return hO(`${e} cannot change the settings menu glyph`,t=>`${t}: ${e} cannot change the settings menu glyph — one menu is shared by every preset. Set it in the top-level globals.menuGlyph instead.`)}function vO(e,t,n){return{...e,json:{...e.json,not:{pattern:`\\{\\{`}},parse:(r,i,a,o)=>{let s=o[a];if(typeof s==`string`&&ih(s)){r.issues.push({path:`${i}.${a}`,message:`${i}.${a}: a rule is not allowed here — ${t} ${n}, so it names a value. Write the rule in globals.${a} (or a preset's globals.${a}) instead.`,line:Y(r.source,[...i.split(`.`),a])});return}return e.parse(r,i,a,o)}}}const yO={default_bg:"nothing reads it — a segment with no `bg:` wears the decoration tint of its place in the bar. Delete the key, and author `bg:` on the segments that need a fixed colour.",default_fg:"nothing reads it — a segment with no `fg:` wears text chosen for contrast against its background. Delete the key, and author `fg:` on the segments that need a fixed colour.",default_truncate_marker:'nothing reads it — a segment clipped to its `width:` always ends in "…". Delete the key.',look:`it was renamed "style" — write the same name as style: "<name>"`,progression:`it was renamed "variation", and its values with it: accent (was secondary-accent), duo (was primary-secondary), mono (was primary)`,charset:"the bar always draws Nerd Font glyphs. Delete the key; `cc-candybar doctor` names what your terminal's font is missing."},bO={noun:`globals key`,fields:fO,removed:yO},xO={preset:gO(`a preset`),menuGlyph:_O(`a preset`)},SO={noun:`preset globals key`,fields:{...fO,...xO},removed:yO};function CO(e){return NO(e)&&!(e in xO)}const wO=`is decided later than any rule could be settled`,TO={noun:`editGlobals key`,removed:yO,fields:{...fO,preset:gO(`the editGlobals fragment`),menuGlyph:_O(`the editGlobals fragment`),palette:vO(fO.palette,`the editGlobals fragment`,wO),style:vO(fO.style,`the editGlobals fragment`,wO),effect:vO(fO.effect,`the editGlobals fragment`,wO)}},EO={noun:`theme default key`,fields:{...Object.fromEntries(a_.map(e=>[e,fO[e]])),style:vO(fO.style,`a theme's default`,`is the look that theme wears by name`)}};function DO(e,t){if(!kD(t))return e.issues.push({path:`themeDefaults`,message:`themeDefaults must be an object mapping theme names to { shade, variation, style }, got ${AD(t)}`,line:Y(e.source,[`themeDefaults`])}),{};let n={};for(let[r,i]of Object.entries(t)){let t=`themeDefaults.${r}`;if(!e.allowedPalettes.has(r)){e.issues.push({path:t,message:`${t}: "${r}" is not an installed theme${Ym(r)}. Expected one of: ${[...e.allowedPalettes].sort().join(`, `)}`,line:Y(e.source,[`themeDefaults`,r])});continue}let a=jD(e,EO,t,i);a!==null&&(n[r]=a)}return n}function OO(e,t,n){return n===void 0?{}:jD(e,bO,t,n)??{}}function kO(e,t,n){return jD(e,SO,t,n)??{}}function AO(){return QD(SO)}function jO(e,t,n){return jD(e,TO,t,n)??{}}const MO=new Set(Object.keys(fO));function NO(e){return MO.has(e)}function PO(e){return Object.hasOwn(yO,e)?yO[e]:void 0}function FO(){return[...MO]}const IO={padding:1};function LO(e){let t=new Map;for(let[n,r]of Object.entries(IO)){let i=e[n];t.set(n,typeof i==`number`?i:r)}return t}const RO=/^segments\.([^.]+)\.palette$/,zO=/^presets\.(.+)\.root$/,BO=/^presets\.(.+)\.globals\.([^.]+)$/,VO=/^themeDefaults\.(.+)\.([^.]+)$/;function HO(e){return`presets.${e}.root`}function UO(e,t){return`themeDefaults.${e}.${t}`}const WO=e=>a_.includes(e);function GO(e,t){return`presets.${e}.globals.${t}`}function KO(e){if(NO(e))return{scope:`globals`,field:e};let t=RO.exec(e);if(t)return{scope:`segment-palette`,segment:t[1]};let n=BO.exec(e);if(n&&CO(n[2]))return{scope:`preset-globals`,preset:n[1],field:n[2]};let r=VO.exec(e);if(r&&WO(r[2]))return{scope:`theme-default`,theme:r[1],field:r[2]};let i=zO.exec(e);return i?{scope:`preset-root`,preset:i[1]}:null}function qO(e){switch(e.scope){case`globals`:return[`globals`,e.field];case`preset-globals`:return[`presets`,e.preset,`globals`,e.field];case`segment-palette`:return[`segments`,e.segment,`palette`];case`theme-default`:return[`themeDefaults`,e.theme,e.field]}}const JO=[`location`,`git`,`model-context`,`cost-limits`,`activity`,`session-tools`],YO=[...JO,`other`],XO={location:`location`,git:`git`,"model-context":`model & context`,"cost-limits":`cost & limits`,activity:`activity`,"session-tools":`session tools`,other:`other`},ZO=wb({fromString:e=>e}),QO=`edit.mode`,$O=`edit.configure`,ek=`edit.toggle`,tk=`edit.unconfigure`,nk=[ek,tk],rk=`arrange`,ik=`${rD}draft.`;function ak(e,t){return`${e}:${t}`}const ok={variable:QO,key:QO,member:rk},sk=gr(ok);function ck(e){try{return ZO.parse(e).referencedCalls().some(e=>e.name===`action`&&e.args[0]===`edit.toggle`)}catch{return!1}}function lk(e){if(Object.values(e.actions??{}).some(e=>`do`in e&&e.do.includes(`edit.toggle`)))return!0;for(let t of Object.values(e.segments??{}))for(let e of[t.template,t.bg,t.fg])if(typeof e==`string`&&ck(e))return!0;return!1}function uk(e,t){if(sD(e,t,rD,`edit mode`),!lk(t))return;let{variables:n,actions:r}=dk();t.variables={...t.variables??{},...n},t.actions={...t.actions??{},...r}}function dk(){return{variables:{[QO]:xr(QO,ur),[$O]:xr($O,ur)},actions:{[ek]:Sr(QO,rk),[tk]:{set:$O,to:ur}}}}const fk=`open`;function pk(e,t,n,r){let i={variable:e,key:e,member:fk};return r.variables[e]=xr(e,ur),r.actions[e]=Sr(e,fk),r.segments[e]={template:vr(e,`(?)`,`✕`),...mk(n)},hr(e,i,{kind:`container`,direction:`horizontal`,children:t.map((t,n)=>{let i=`${e}.${n}`;return r.segments[i]={template:t},{kind:`segment`,name:i}})},`drop`)}function mk(e){let[t,...n]=e;return t===void 0?{}:{when:gr(t,...n)}}const hk=`none`;function gk(e){return Us(e,`background`)}var _k=class extends Error{constructor(e,t,n){super(`Invalid ${t} color ${JSON.stringify(e)}: ${n}`),this.name=`ColorSpecError`}};function vk(e,t,n,r,i){let{palette:a,tint:o,text:s}=e,c=yk(n,i),l=c!==hk,u=l?c===void 0?o:bk(a,c,`bg`):gk(a);e.bg=u;let d=yk(r,i),f=d===void 0?l?(e=>e.hex===o.hex?s:Sm(a,e,t))(u):void 0:bk(a,d,`fg`);return new U({...l&&{bgcolor:H.fromRgba(u)},...f!==void 0&&{color:H.fromRgba(f)}})}function yk(e,t){if(e!==void 0)return e.evaluate(t).map(e=>e.plain).join(``)}function bk(e,t,n){try{return Us(e,t)}catch(e){throw e instanceof Hs?new _k(t,n,e.message):e}}const xk=`🔧`,Sk={help:[`-h`,`--help`],version:[`-V`,`--version`]},Ck=[`✚ inserts`,`✖ removes`,`${xk} configures`,`↺ resets layout`],wk=`
|
|
67
|
+
`)}function qC(e){let t=new TextEncoder;return e.split(/\s+/).filter(e=>e.length>0).map(e=>String.fromCharCode(...t.encode(e).slice(0,1))).join(``)}function JC(e,t){let n=[];for(let e of t){if(typeof e==`object`&&e)throw IS(`join`,2,`list of strings/primitives`,`list element of type ${YC(e)}`);n.push(String(e))}return n.join(e)}function YC(e){return Array.isArray(e)?`array`:e instanceof Map?`Map`:e instanceof Set?`Set`:`object`}function XC(e){return zC(e,`-`)}function ZC(e){return e.toLowerCase()}function QC(e,t){return`\n${KC(e,t)}`}function $C(e){return e.replace(/\s+/g,``)}function ew(e,t,n){return n===1?e:t}function tw(...e){return e.map(e=>`"${e}"`).join(` `)}function nw(e){return e.replace(/[\\.+*?()|[\]{}^$]/g,`\\$&`)}function rw(e,t){return t.repeat(Math.max(0,e))}function iw(e,t,n){return wC(e,n).join(t)}function aw(e){return zC(e,`_`)}function ow(e,t){let n=wC(e,t),r={};for(let e=0;e<n.length;e++)r[`_${e}`]=n[e];return r}function sw(e,t){return wC(e,t)}function cw(e,t,n){let r=lw(n,e,t),i={};for(let e=0;e<r.length;e++)i[`_${e}`]=r[e]??``;return i}function lw(e,t,n){if(n===0)return[];let r=wC(t,e);if(n<0||r.length<=n)return r;let i=r.slice(0,n-1),a=r.slice(n-1).join(t);return[...i,a]}function uw(...e){return e.map(e=>`'${e}'`).join(` `)}function dw(e,t,n){let r=CC(n),i=t<0||t>r.length?r.length:t,a=Math.min(Math.max(0,e),i);return r.slice(a,i).join(``)}function fw(e){let t=``;for(let n of e)pw(n)?t+=n.toLowerCase():mw(n)?t+=n.toUpperCase():t+=n;return t}function pw(e){return e!==e.toLowerCase()&&e===e.toUpperCase()}function mw(e){return e!==e.toUpperCase()&&e===e.toLowerCase()}function hw(e){return e.replace(/\b([a-zA-Z])/g,e=>e.toUpperCase())}function gw(e){return e.trim()}function _w(e,t){if(e.length===0)return t;let n=new Set(CC(e)),r=CC(t),i=0;for(;i<r.length&&n.has(r[i]);)i+=1;let a=r.length;for(;a>i&&n.has(r[a-1]);)--a;return r.slice(i,a).join(``)}function vw(e,t){return t.startsWith(e)?t.slice(e.length):t}function yw(e,t){return t.endsWith(e)?t.slice(0,t.length-e.length):t}function bw(e,t){let n=CC(t);if(e<0){let r=-e;return r>=n.length?t:n.slice(n.length-r).join(``)}return e>=n.length?t:n.slice(0,e).join(``)}function xw(e){return e.replace(/\b([A-Z])/g,e=>e.toLowerCase())}function Sw(e){return e.toUpperCase()}function Cw(e,t){return ww(e,`
|
|
68
|
+
`,t)}function ww(e,t,n){if(e<=0)return n;let r=[];for(let t of n.split(`
|
|
69
|
+
`)){let n=``;for(let i of t.split(/\s+/))i.length!==0&&(n.length===0?n=i:n.length+1+i.length<=e?n+=` ${i}`:(r.push(n),n=i));n.length>0&&r.push(n)}return r.join(t)}function Tw(e,t,n){return ww(e,t,n)}function Ew(){return{abbrev:{fn:(e,t)=>TC(e,t),argTypes:[`int`,`string`],arity:{kind:`exact`}},abbrevboth:{fn:(e,t,n)=>EC(e,t,n),argTypes:[`int`,`int`,`string`],arity:{kind:`exact`}},camelcase:{fn:e=>VC(e),argTypes:[`string`],arity:{kind:`exact`},returnType:`string`},cat:{fn:(...e)=>HC(...e),argTypes:[`string`],arity:{kind:`variadic`}},contains:{fn:(e,t)=>UC(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},hasPrefix:{fn:(e,t)=>WC(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},hasSuffix:{fn:(e,t)=>GC(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},indent:{fn:(e,t)=>KC(e,t),argTypes:[`int`,`string`],arity:{kind:`exact`}},initials:{fn:e=>qC(e),argTypes:[`string`],arity:{kind:`exact`}},join:{fn:(e,t)=>JC(e,t),argTypes:[`string`,`list`],arity:{kind:`exact`}},kebabcase:{fn:e=>XC(e),argTypes:[`string`],arity:{kind:`exact`},returnType:`string`},lower:{fn:e=>ZC(e),argTypes:[`string`],arity:{kind:`exact`}},nindent:{fn:(e,t)=>QC(e,t),argTypes:[`int`,`string`],arity:{kind:`exact`}},nospace:{fn:e=>$C(e),argTypes:[`string`],arity:{kind:`exact`},returnType:`string`},plural:{fn:(e,t,n)=>ew(e,t,n),argTypes:[`string`,`string`,`int`],arity:{kind:`exact`},returnType:`string`},quote:{fn:(...e)=>tw(...e),argTypes:[`string`],arity:{kind:`variadic`}},regexQuoteMeta:{fn:e=>nw(e),argTypes:[`string`],arity:{kind:`exact`},returnType:`string`},repeat:{fn:(e,t)=>rw(e,t),argTypes:[`int`,`string`],arity:{kind:`exact`}},replace:{fn:(e,t,n)=>iw(e,t,n),argTypes:[`string`,`string`,`string`],arity:{kind:`exact`}},snakecase:{fn:e=>aw(e),argTypes:[`string`],arity:{kind:`exact`},returnType:`string`},split:{fn:(e,t)=>ow(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},splitList:{fn:(e,t)=>sw(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},splitn:{fn:(e,t,n)=>cw(e,t,n),argTypes:[`string`,`int`,`string`],arity:{kind:`exact`},returnType:`dict`},squote:{fn:(...e)=>uw(...e),argTypes:[`string`],arity:{kind:`variadic`}},substr:{fn:(e,t,n)=>dw(e,t,n),argTypes:[`int`,`int`,`string`],arity:{kind:`exact`}},swapcase:{fn:e=>fw(e),argTypes:[`string`],arity:{kind:`exact`},returnType:`string`},title:{fn:e=>hw(e),argTypes:[`string`],arity:{kind:`exact`}},trim:{fn:e=>gw(e),argTypes:[`string`],arity:{kind:`exact`}},trimAll:{fn:(e,t)=>_w(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},trimPrefix:{fn:(e,t)=>vw(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},trimSuffix:{fn:(e,t)=>yw(e,t),argTypes:[`string`,`string`],arity:{kind:`exact`}},trunc:{fn:(e,t)=>bw(e,t),argTypes:[`int`,`string`],arity:{kind:`exact`}},untitle:{fn:e=>xw(e),argTypes:[`string`],arity:{kind:`exact`}},upper:{fn:e=>Sw(e),argTypes:[`string`],arity:{kind:`exact`}},wrap:{fn:(e,t)=>Cw(e,t),argTypes:[`int`,`string`],arity:{kind:`exact`}},wrapWith:{fn:(e,t,n)=>Tw(e,t,n),argTypes:[`int`,`string`,`string`],arity:{kind:`exact`}}}}function Dw(e,t){let n=Ow(e),r=n.copy();return r.style=jl(n.style,t),r}function Ow(e){if(!(e instanceof K))throw TypeError(`template function expected a RichText fragment, got ${typeof e==`object`?Object.prototype.toString.call(e):typeof e}`);return e}function kw(e){return{fn:(t=>Dw(t,e)),argTypes:[`liftable`],arity:{kind:`exact`},returnType:`T`}}function Aw(e){return{fn:((t,n)=>Dw(n,new U({[e]:H.parse(t)}))),argTypes:[`string`,`liftable`],arity:{kind:`exact`},returnType:`T`}}function jw(e,t){return new U({[e]:t})}function Mw(){let e={};for(let t of Tl)e[t]=kw(jw(t,!0)),e[`not_${t}`]=kw(jw(t,!1));for(let[t,n]of Object.entries(Dl))e[t]=kw(jw(n,!0));return e}const Nw={fn:((e,t)=>Dw(t,U.parse(e))),argTypes:[`string`,`liftable`],arity:{kind:`exact`},returnType:`T`},Pw={fn:((e,t)=>Dw(t,new U({link:e}))),argTypes:[`string`,`liftable`],arity:{kind:`exact`},returnType:`T`};function Fw(){return{fg:Aw(`color`),bg:Aw(`bgcolor`),...Mw(),link:Pw,style:Nw}}function Iw(e,t){let n;try{n=ds(e.trim())}catch(n){throw n instanceof qo?TypeError(`${t} expected a color (#RRGGBB or #RRGGBBAA), got ${JSON.stringify(e)} — to use a palette name here, wrap it: ${t} (color ${JSON.stringify(e)}) …`,{cause:n}):n}return Lw(n,t,JSON.stringify(e))}function Lw(e,t,n){if(e.alpha===0)throw RangeError(`${t} got ${n}, which is fully transparent: it draws no colour of its own, so there is nothing to compute with — use the colour of the surface it sits on, e.g. (color "background")`);return e}function Rw(e,t){return{fn:t,argTypes:e,arity:{kind:`exact`},returnType:`string`}}function zw(e,t,n,r){let i=r===void 0||e>=r.min&&e<=r.max;if(!Number.isFinite(e)||!i){let i=r===void 0?`a finite number`:`within ${r.min}..${r.max} (${r.note})`;throw RangeError(`${t}'s ${n} must be ${i}, got ${e}`)}return e}const Bw=Rw([`string`,`int`],((e,t)=>Ys(Iw(e,`darken`),t).hex)),Vw=Rw([`string`,`int`],((e,t)=>Ys(Iw(e,`lighten`),-t).hex)),Hw={min:0,max:100,note:`0 = from, 100 = toward`},Uw=Rw([`string`,`string`,`float`],((e,t,n)=>fs(Iw(e,`mix`),Iw(t,`mix`),zw(n,`mix`,`percentage`,Hw)/100).hex)),Ww={min:1,max:21,note:`4.5 = AA body text, 3 = AA large text`},Gw=Rw([`string`],(e=>Zs(Iw(e,`contrastOn`)).hex)),Kw={depth:V.TRUECOLOR},qw=e=>Rw([`string`,`string`,`float`],((t,n,r)=>{let{depth:i,terminal:a}=e();return Qs(Iw(t,`readableOn`),Iw(n,`readableOn`),zw(r,`readableOn`,`ratio`,Ww),i,void 0,a).hex})),Jw={hueShift:`shiftHue`,chromaScale:`scaleChroma`,lightnessScale:`scaleLightness`,lightnessShift:`shiftLightness`};function Yw(){let e={};for(let[t,n]of Object.entries(Jw)){let r=t;e[n]=Rw([`string`,`float`],((e,t)=>{let i={...As,[r]:zw(t,n,`amount`)};return Vs.fromRgba(Iw(e,n)).applyKey(i).toRgba().hex}))}return e}function Xw(e=()=>Kw){return{darken:Bw,lighten:Vw,mix:Uw,contrastOn:Gw,readableOn:qw(e),...Yw()}}function Zw(e,t){if(e.length%2!=0)throw RangeError(`ramp's last stop (position ${String(e[e.length-1])}) has no color — stops are <position> <color> pairs`);let n=[];for(let r=0;r<e.length;r+=2)n.push({at:e[r],color:Lw(Us(t,e[r+1]),`ramp`,JSON.stringify(e[r+1]))});return n}function Qw(e){return{color:{fn:(t=>Us(e(),t).hex),argTypes:[`string`],arity:{kind:`exact`},returnType:`string`},ramp:{fn:((t,n,...r)=>new gl(rl(n),Zw(r,e())).at(t).hex),argTypes:[`float`,`string`],arity:{kind:`alternating`,minimum:4},returnType:`string`}}}function $w(e,t,n){if(t.length%2!=0)throw RangeError(`last hold (${String(t[t.length-1])} s) has no ${e} — the arguments are <seconds> <${e}> pairs`);let r=[];for(let e=0;e<t.length;e+=2){let i=t[e];if(!Number.isFinite(i)||i<=0)throw RangeError(`hold ${e/2} must be a positive number of seconds, got ${i}`);r.push({seconds:i,value:n(t[e+1])})}return r}function eT(e){return{frames:{fn:((...t)=>yp(new vp($w(`frame`,t,Ow).map(({seconds:e,value:t})=>({seconds:e,text:t}))),e())),argTypes:[`float`,`liftable`],arity:{kind:`alternating`,minimum:2},returnType:`T`},stepped:{fn:((...t)=>{let n=$w(`color`,t,e=>Iw(e,`stepped`));return n[fl(n.map(e=>e.seconds)).at(e())].value.hex}),argTypes:[`float`,`string`],arity:{kind:`alternating`,minimum:2},returnType:`string`}}}function tT(e){return{...Fw(),...Xw(e)}}new U({color:`red`,dim:!0});const nT=/^(?:(?:global|apac|au|eu|us|us-east-\d|us-west-\d|eu-west-\d|eu-central-\d)\.)?(?:anthropic\.|azure_ai\/|bedrock\/|vertex_ai\/)?claude-(?:(?<family>opus|sonnet|haiku)-(?<newMajor>\d+)(?:-(?<newMinor>\d))?|(?<oldMajor>\d+)(?:-(?<oldMinor>\d))?-(?<oldFamily>opus|sonnet|haiku))(?:[-@]\d{8})?(?:-v\d+:\d+)?(?:-latest)?$/i,rT=/^(?<family>opus|sonnet|haiku)\s+(?<major>\d+)(?:\.(?<minor>\d))?$/i;function iT(e){if(!e)return`Claude`;let t=e.trim().replace(/\s*\([^)]*\)\s*$/,``).replace(/\s*\[[^\]]*\]\s*$/,``).trim(),n=t.match(nT);if(n?.groups){let{family:e,newMajor:t,newMinor:r,oldMajor:i,oldMinor:a,oldFamily:o}=n.groups,s=e||o,c=t||i,l=r||a;if(s&&c)return`${s.charAt(0).toUpperCase()+s.slice(1).toLowerCase()} ${l?`${c}.${l}`:c}`}let r=t.match(rT);if(r?.groups){let e=r.groups.family,t=r.groups.major,n=r.groups.minor;return`${e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()} ${n?`${t}.${n}`:t}`}return t||e}function aT(e){let t=e.match(rT);if(!t?.groups)return e;let n=t.groups.family,r=t.groups.major,i=t.groups.minor;return`${n.charAt(0).toUpperCase()}${i?`${r}.${i}`:r}`}function oT(e){let t=e.split(`/`),n=t.length-1;return t.map((e,t)=>{if(t===n)return e;let r=e.match(/^\.*./);return r?r[0]:e}).join(`/`)}function sT(e){return e.toLocaleString()}function cT(e){if(e.length===0)throw Error(`a cascade needs at least one stop, e.g. "0:calm"`);let t=[];for(let[n,r]of e.entries()){let e=r.indexOf(`:`),i=e<0?NaN:Number(r.slice(0,e));if(!Number.isFinite(i))throw Error(`cascade stop ${n} ("${r}") must be "<position>:<result>", e.g. "80:hot" — the position must be a number`);let a=t[n-1];if(a!==void 0&&i<a.at)throw Error(`cascade stops must be in ascending position order; stop ${n} at ${i} follows stop ${n-1} at ${a.at}`);t.push({at:i,text:r.slice(e+1)})}return t}function lT(e,t){if(!Number.isFinite(e))throw Error(`a cascade needs a finite value, got ${e}`);let n=-1;for(;n+1<t.length&&t[n+1].at<=e;)n++;return(n<0?t[0]:t[n]).text}const uT=[`▁`,`▂`,`▃`,`▄`,`▅`,`▆`,`▇`,`█`],dT=uT.length;function fT(e,t){let n=t===void 0?e:t<=0?[]:e.slice(-t);if(n.length===0)return``;let r=n[0],i=n[0];for(let e of n)e<r&&(r=e),e>i&&(i=e);let a=i-r,o=``;for(let e of n){let t=a===0?0:Math.round((e-r)/a*(dT-1));o+=uT[t]}return o}function pT(e){let t=[];for(let n of e.split(`,`)){let e=n.trim();if(e===``)continue;let r=Number(e);if(!Number.isFinite(r))throw TypeError(`sparkline: non-numeric series element ${JSON.stringify(n)}`);t.push(r)}return t}function mT(e,t,n){if(n.length!==0)throw Error(`${e}: takes at most ${t.length} optional argument${t.length===1?``:`s`} (${t.join(`, `)}), got ${t.length+n.length}`)}const hT=Zm(),gT=[...vh];function _T(){return{basename:{fn:e=>y(e),argTypes:[`string`],arity:{kind:`exact`}},dirname:{fn:e=>b(e),argTypes:[`string`],arity:{kind:`exact`}},abbreviatePath:{fn:e=>oT(e),argTypes:[`string`],arity:{kind:`exact`}},int:{fn:e=>Math.trunc(Dv(e)),argTypes:[`value`],arity:{kind:`exact`}},string:{fn:e=>Ev(e),argTypes:[`value`],arity:{kind:`exact`}},bool:{fn:e=>Ov(e),argTypes:[`value`],arity:{kind:`exact`}},urlEncode:{fn:e=>encodeURIComponent(e),argTypes:[`string`],arity:{kind:`exact`}},themes:{fn:()=>hT,argTypes:[],arity:{kind:`exact`}},endcaps:{fn:()=>gT,argTypes:[],arity:{kind:`exact`}},sparkline:{fn:(e,t,...n)=>(mT(`sparkline`,[`width`],n),fT(pT(e),t)),argTypes:[`string`,`int`],arity:{kind:`variadic`}},cascade:{fn:(e,...t)=>lT(e,cT(t)),argTypes:[`float`,`string`],arity:{kind:`variadic`}}}}function vT(e){return{minutesUntilReset:{fn:t=>Math.round(Math.max(0,t*1e3-e().getTime())/6e4),argTypes:[`int`],arity:{kind:`exact`}},formatInteger:{fn:e=>sT(e),argTypes:[`int`],arity:{kind:`exact`}},round:{fn:e=>Math.round(e),argTypes:[`float`],arity:{kind:`exact`}},formatModelName:{fn:e=>iT(e),argTypes:[`string`],arity:{kind:`exact`}},shortenModelName:{fn:e=>aT(e),argTypes:[`string`],arity:{kind:`exact`}}}}function yT(e){let{clock:t,drawnAt:n,extraFuncs:r}=e;return Cb({fromString:e=>new K(e),toString:e=>e.plain,isT:e=>e instanceof K,clock:t,missingKey:`error`,funcs:{...fS(),...Ew(),...eC(),...SC(),...iS(t),...Jb(),...OS(),...ES(),...tT(n&&(()=>({depth:n()}))),...eT(()=>t().getTime()/1e3),..._T(),...vT(t),...r??{}}})}function bT(e){return xT(e,new Set(e.names()),``)}function xT(e,t,n){return new Proxy(Object.create(null),{has(e,r){if(typeof r!=`string`)return!1;let i=n?`${n}.${r}`:r;if(t.has(i))return!0;let a=`${i}.`;for(let e of t)if(e.startsWith(a))return!0;return!1},get(r,i){if(typeof i!=`string`)return;let a=n?`${n}.${i}`:i;if(t.has(a))return e.getKind(a)===`document`?CT(a,e.readDocument(a)):e.read(a);let o=`${a}.`;for(let n of t)if(n.startsWith(o))return xT(e,t,a)}})}function ST(e,t){return new Proxy(e,{has:(e,t)=>t===`settings`||Reflect.has(e,t),get:(e,n)=>n===`settings`?t:Reflect.get(e,n)})}function CT(e,t){switch(t.kind){case`ok`:return t.value;case`absent`:throw new kv(e,`variable "${e}" has no value yet: its source has not completed a scan`);case`failed`:throw Error(`variable "${e}": ${t.reason}`)}}function wT(e){return s.existsSync(v.join(e,`.git`))}function TT(e){let t=v.resolve(e);for(;;){if(wT(t))return t;let e=v.dirname(t);if(e===t)return;t=e}}function ET(e){let t=TT(e);return t===void 0?{root:v.resolve(e),git:!1}:{root:t,git:!0}}function DT(e,t){return e.kind===`absent`?L(`none`):e.kind===`failed`?e:t.kind===`failed`?t:L(t.kind===`ok`?`tracked`:`gone`)}function OT(e,t){return e.kind!==`ok`||e.value.state===`open`?e:t.kind===`failed`?z(`HEAD: ${t.reason}`):t.kind===`ok`&&t.value===e.value.head?e:{kind:`earlier`,value:e.value}}const kT={OPEN:`open`,MERGED:`merged`,CLOSED:`closed`},AT={opened:`open`,locked:`open`,merged:`merged`,closed:`closed`};function jT(e,t,n){return Object.hasOwn(t,n)?L(t[n]):z(`${e}: unknown state ${JSON.stringify(n)}`)}function MT(e,t,n){return t.ok?L(t.stdout):t.reason===`non-zero`&&n===`absent`||t.reason===`non-zero`&&n===t.exitCode?R:z(NT(e,t))}function NT(e,t){return`${e}: ${[t.reason,t.exitCode==null?null:`exit ${t.exitCode}`,t.error??PT(t.stderr)].filter(Boolean).join(`, `)}`}function PT(e){return e.trim().split(`
|
|
70
|
+
`,1)[0]??``}function FT(e,t){if(e.kind!==`ok`)return e;let n=t(e.value);return n===null?R:L(n)}function IT(e){if(e.kind!==`ok`)return e;let t=e.value.trim();return t?L(t):R}const LT={github:`gh`,gitlab:`glab`};function RT(e){return!e.ok&&e.reason===`spawn-error`&&/ENOENT/i.test(e.error??``)}const zT=/^[A-Za-z]:[\\/]/;function BT(e){let t=e.trim();if(zT.test(t))return null;let n=t.match(/^(?:[^@/]+@)?(\[[^\]]+\]):(.*)$/)??t.match(/^(?:[^@/:]+@)?([^/:]+):(?!\/\/)(.*)$/),r=n?`ssh://${n[1]}/${n[2].replace(/^\/+/,``)}`:t,i;try{i=new URL(r)}catch{return null}return{scheme:i.protocol.replace(/:$/,``),host:i.hostname.toLowerCase(),port:i.port,path:i.pathname.replace(/^\/+/,``).replace(/\/+$/,``)}}function VT(e){return BT(e)?.host||null}function HT(e){let t=VT(e);return t?t===`github.com`||t.endsWith(`.github.com`)?`github`:/(^|\.)gitlab\./.test(t)?`gitlab`:null:null}const UT=[`config`,`--local`,`--get-regexp`,`^remote\\..*\\.url$`];function WT(e){let t=MT(`git config --get-regexp remote url`,e,1);return t.kind===`failed`?t:{kind:`ok`,value:t.kind===`ok`?GT(t.value):[]}}function GT(e){let t=new Map;for(let n of e.split(`
|
|
71
|
+
`)){let e=n.match(/^remote\.(.+)\.url\s+(\S.*)$/);if(!e)continue;let r=t.get(e[1])??[];r.push(e[2].trim()),t.set(e[1],r)}return[...t].map(([e,t])=>({name:e,urls:t}))}function KT(e){return e.urls.find(e=>ZT(e)!==null)??e.urls[0]??null}function qT(e){return e.find(e=>e.name===`origin`)??e[0]??null}function JT(e){let t=qT(e);return t?KT(t):null}function YT(e){let t=qT(e);return t?t.urls.find(e=>HT(e)!==null)??KT(t):null}function XT(e){let t=(BT(e)?.path??e.replace(/[\\/]+$/,``)).split(`/`);return(t[t.length-1]??``).replace(/\.git$/,``)||null}function ZT(e){let t=BT(e);if(!t)return null;let n=t.scheme===`https`?{scheme:`https`,port:t.port}:t.scheme===`http`?{scheme:`http`,port:t.port}:t.scheme===`ssh`||t.scheme===`git`?{scheme:`https`,port:``}:null;if(!n||!t.host)return null;let r=t.path.replace(/\.git$/,``);if(!r)return null;let i=n.port?`${t.host}:${n.port}`:t.host;return`${n.scheme}://${i}/${r}`}function QT(e){let t=JT(e);return t===null?null:ZT(t)}function $T(e,t,n,r){return t.ok?r(t.stdout):RT(t)||t.reason===`non-zero`&&n.test(t.stderr)?R:z(`${e}: ${[t.reason,t.exitCode==null?null:`exit ${t.exitCode}`,t.error??PT(t.stderr)].filter(Boolean).join(`, `)}`)}function eE(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function tE(e){let t=`detached`,n=R,r=R,i=R,a=0,o=0,s=0,c=0;for(let l of e.split(`
|
|
72
|
+
`)){if(!l)continue;if(l.startsWith(`# `)){let e=l.slice(2);if(e.startsWith(`branch.oid `)){let t=e.slice(11).trim();n=t===`(initial)`?R:L(t)}else if(e.startsWith(`branch.head `)){let n=e.slice(12).trim();t=n===`(detached)`?`detached`:n}else if(e.startsWith(`branch.upstream `))r=L(e.slice(16).trim());else if(e.startsWith(`branch.ab `)){let t=e.slice(10).trim().match(/^\+(\d+)\s+-(\d+)$/);t&&(i=L({ahead:parseInt(t[1],10),behind:parseInt(t[2],10)}))}continue}let e=l[0];if(e===`1`||e===`2`){let e=l.slice(2,4);e[0]!==`.`&&a++,e[1]!==`.`&&o++}else e===`u`?c++:e===`?`&&s++}let l=`clean`;return c>0?l=`conflicts`:(a||o||s)&&(l=`dirty`),{branch:t,status:l,aheadBehind:i,oid:n,upstream:r,workingTree:{staged:a,unstaged:o,untracked:s,conflicts:c}}}function nE(e){let t;try{t=JSON.parse(e)}catch(e){return z(`gh pr view: unparseable JSON (${e instanceof Error?e.message:String(e)})`)}if(!eE(t))return z(`gh pr view: JSON is not an object`);let{number:n,state:r,url:i,headRefOid:a}=t;if(typeof n!=`number`||typeof r!=`string`||typeof i!=`string`||typeof a!=`string`)return z(`gh pr view: missing number/state/url/headRefOid`);let o=jT(`gh pr view`,kT,r);return o.kind===`ok`?L({number:n,state:o.value,url:i,head:a}):o}function rE(e){let t;try{t=JSON.parse(e)}catch(e){return z(`glab mr view: unparseable JSON (${e instanceof Error?e.message:String(e)})`)}if(!eE(t))return z(`glab mr view: JSON is not an object`);let n=t.iid,r=t.state,i=t.web_url,a=t.sha;if(typeof n!=`number`||typeof r!=`string`||typeof i!=`string`||typeof a!=`string`)return z(`glab mr view: missing iid/state/web_url/sha`);let o=jT(`glab mr view`,AT,r);return o.kind===`ok`?L({number:n,state:o.value,url:i,head:a}):o}function iE(e){try{let t=s.statSync(e);return{key:`${t.dev}:${t.ino}`,stamp:`${t.mtimeMs}:${t.size}`}}catch{return null}}var aE=class{isGitRepo(e){return wT(e)}async execGitAsync(e,t){return Le({bin:`git`,args:[...e],cwd:t.cwd,env:{...process.env,GIT_OPTIONAL_LOCKS:`0`},timeoutMs:t.timeout,category:`git`})}async resolveEffectiveGitDir(e,t){return this.isWorktree(e)?L(e):t&&this.isGitRepo(t)?L(t):this.isGitRepo(e)?L(e):this.findGitRoot(e)}async findGitRoot(e){let t=TT(e);return t===void 0?R:L(t)}async getGitInfo(e,t={},n){try{return await this.computeGitInfo(e,t,n)}catch(e){return z(`git: ${e instanceof Error?e.message:String(e)}`)}}async computeGitInfo(e,t={},n){let r,i=this.isWorktree(e);if(i)r=e;else if(n&&this.isGitRepo(n))r=n;else if(this.isGitRepo(e))r=e;else{let t=await this.findGitRoot(e);if(t.kind!==`ok`)return t;r=t.value}let a=await this.getCoreAsync(r);if(a.kind!==`ok`)return a;let o={branch:a.value.branch,status:a.value.status,aheadBehind:a.value.aheadBehind,head:a.value.oid};t.showWorkingTree&&(o.workingTree=a.value.workingTree),t.showSha&&(o.sha=FT(a.value.oid,e=>e.slice(0,7))),t.showUpstream&&(o.upstream=a.value.upstream),t.showTag&&(o.tag=await this.getNearestTagAsync(r)),t.showTimeSinceCommit&&(o.committedAt=await this.committedAt(r,a.value.oid)),t.showStashCount&&(o.stashCount=this.getStashCount(r));let s=t.showRepoName||t.showRepoUrl?await this.getRemotesAsync(r):void 0;return s!==void 0&&t.showRepoName&&(o.repoName=FT(s,e=>this.repoNameFrom(e,r)),o.isWorktree=i),s!==void 0&&t.showRepoUrl&&(o.repoUrl=FT(s,QT)),t.showOperation&&(o.operation=this.getOngoingOperation(r)),L(o)}resolveGitDir(e){let t=v.join(e,`.git`);try{if(s.existsSync(t)&&s.statSync(t).isFile()){let n=s.readFileSync(t,`utf-8`).match(/^gitdir:\s*(.+)$/m);if(n?.[1])return v.resolve(e,n[1].trim())}}catch{}return t}getOngoingOperation(e){try{let t=this.resolveGitDir(e);return s.existsSync(v.join(t,`MERGE_HEAD`))?L(`MERGE`):s.existsSync(v.join(t,`CHERRY_PICK_HEAD`))?L(`CHERRY-PICK`):s.existsSync(v.join(t,`REVERT_HEAD`))?L(`REVERT`):s.existsSync(v.join(t,`BISECT_LOG`))?L(`BISECT`):s.existsSync(v.join(t,`rebase-merge`))||s.existsSync(v.join(t,`rebase-apply`))?L(`REBASE`):R}catch(e){return z(`git operation probe: ${e instanceof Error?e.message:String(e)}`)}}async getNearestTagAsync(e){return IT(MT(`git describe --tags`,await this.execGitAsync([`describe`,`--tags`,`--abbrev=0`],{cwd:e,timeout:2e3}),`absent`))}async committedAt(e,t){return t.kind===`ok`?this.commitTimestampMs(e,t.value):t}commitTimes=new Map;async commitTimestampMs(e,t){let n=this.commitTimes.get(t);if(n!==void 0)return this.commitTimes.delete(t),this.commitTimes.set(t,n),n;let r=this.readCommitTimestampMs(e,t);for(this.commitTimes.set(t,r),r.then(e=>{e.kind!==`ok`&&this.commitTimes.get(t)===r&&this.commitTimes.delete(t)},()=>{this.commitTimes.get(t)===r&&this.commitTimes.delete(t)});this.commitTimes.size>256;){let e=this.commitTimes.keys().next().value;if(e===void 0)break;this.commitTimes.delete(e)}return r}async readCommitTimestampMs(e,t){let n=IT(MT(`git log -1`,await this.execGitAsync([`log`,`-1`,`--format=%ct`,t,`--`],{cwd:e,timeout:2e3}),`absent`));if(n.kind!==`ok`)return n;let r=parseInt(n.value,10)*1e3;return Number.isNaN(r)?z(`git log -1: unparseable timestamp "${n.value}"`):L(r)}resolveCommonGitDir(e){let t=this.resolveGitDir(e);try{let e=s.readFileSync(v.join(t,`commondir`),`utf-8`).trim();if(e)return v.resolve(t,e)}catch{}return t}getStashCount(e){let t=v.join(this.resolveCommonGitDir(e),`logs`,`refs`,`stash`),n;try{n=s.readFileSync(t,`utf-8`)}catch(e){return e.code===`ENOENT`?L(0):z(`git stash reflog ${t}: ${e instanceof Error?e.message:String(e)}`)}let r=n.trim();return L(r?r.split(`
|
|
73
|
+
`).length:0)}async getRemotesAsync(e){let t=iE(v.join(this.resolveCommonGitDir(e),`config`));if(t===null)return this.readRemotes(e);let{key:n,stamp:r}=t,i=this.remotesByConfig.get(n);if(i!==void 0&&i.stamp===r)return this.remotesByConfig.delete(n),this.remotesByConfig.set(n,i),i.remotes;let a=this.readRemotes(e);for(this.remotesByConfig.set(n,{stamp:r,remotes:a}),a.then(e=>{let t=this.remotesByConfig.get(n);e.kind!==`ok`&&t?.remotes===a&&this.remotesByConfig.delete(n)},()=>{this.remotesByConfig.get(n)?.remotes===a&&this.remotesByConfig.delete(n)});this.remotesByConfig.size>256;){let e=this.remotesByConfig.keys().next().value;if(e===void 0)break;this.remotesByConfig.delete(e)}return a}remotesByConfig=new Map;async readRemotes(e){return WT(await this.execGitAsync(UT,{cwd:e,timeout:2e3}))}repoNameFrom(e,t){let n=JT(e);return(n===null?null:XT(n))??v.basename(t)}async getRepoRemoteUrl(e){let t=await this.getRemotesAsync(e);if(t.kind!==`ok`)return t;let n=YT(t.value);return n===null?R:L(n)}async execForgeAsync(e,t,n){return Le({bin:e,args:[...t],cwd:n.cwd,env:{...process.env},timeoutMs:n.timeout,category:`forge`})}async resolvePullRequest(e,t){let n=HT(t);return n===`github`?$T(`gh pr view`,await this.execForgeAsync(LT.github,[`pr`,`view`,`--json`,`number,state,url,headRefOid`],{cwd:e,timeout:5e3}),/no (open )?pull requests? found/i,nE):n===`gitlab`?$T(`glab mr view`,await this.execForgeAsync(LT.gitlab,[`mr`,`view`,`--output`,`json`],{cwd:e,timeout:5e3}),/no (open )?merge requests? (found|available)/i,rE):R}isWorktree(e){try{let t=v.join(e,`.git`);return!!(s.existsSync(t)&&s.statSync(t).isFile())}catch{return!1}}async getCoreAsync(e){k(`[GIT-EXEC] Running git status --porcelain=v2 in ${e}`);let t=MT(`git status --porcelain=v2 --branch`,await this.execGitAsync([`status`,`--porcelain=v2`,`--branch`],{cwd:e,timeout:2e3}),`failed`);return t.kind===`ok`?L(tE(t.value)):t}};const oE=(e,t)=>k(t);var sE=class{slots=new Map;maxWatchers;counters;logger;closed=!1;constructor(e={}){this.maxWatchers=e.maxWatchers??128,this.counters=e.counters,this.logger=e.logger??oE}acquire(e,t,n){if(this.closed)return{release:()=>{}};let r=this.slots.get(e);if(r)return r.refcount++,r.onInvalidate=n,r.lastTouched=Date.now(),this.slots.delete(e),this.slots.set(e,r),this.makeHandle(e);let i={key:e,watchers:[],refcount:1,debounceTimer:null,onInvalidate:n,targets:t,lastTouched:Date.now()};return this.openWatchers(i),this.slots.set(e,i),this.counters&&this.counters.watchersOpened++,this.evictIfNeeded(),this.makeHandle(e)}makeHandle(e){let t=!1;return{release:()=>{if(t)return;t=!0;let n=this.slots.get(e);n&&(n.refcount=Math.max(0,n.refcount-1),n.refcount===0&&(this.closeSlot(n),this.slots.delete(e)))}}}openWatchers(e){let t=()=>{e.debounceTimer||(e.debounceTimer=setTimeout(()=>{e.debounceTimer=null;try{e.onInvalidate()}catch(e){this.logger(`warn`,`watcher invalidate threw: ${e.message}`)}},50),e.debounceTimer.unref())};for(let n of e.targets.files)try{let r=s.watch(n,{persistent:!1},t);r.on(`error`,e=>{this.logger(`warn`,`watcher error ${n}: ${e.message}`)}),e.watchers.push(r)}catch(e){this.logger(`warn`,`watch failed ${n}: ${e.message}`)}for(let n of e.targets.dirs)try{let r=n.filenames?new Set(n.filenames):null,i=s.watch(n.path,{persistent:!1},(e,n)=>{r&&(!n||!r.has(n))||t()});i.on(`error`,e=>{this.logger(`warn`,`watcher error ${n.path}: ${e.message}`)}),e.watchers.push(i)}catch(e){this.logger(`warn`,`watch failed ${n.path}: ${e.message}`)}}closeSlot(e){e.debounceTimer&&=(clearTimeout(e.debounceTimer),null);for(let t of e.watchers)try{t.close()}catch{}e.watchers=[],this.counters&&this.counters.watchersClosed++}evictIfNeeded(){for(;this.slots.size>this.maxWatchers;){let e=this.slots.keys().next().value;if(e===void 0)break;let t=this.slots.get(e);this.closeSlot(t),this.slots.delete(e),this.counters&&this.counters.watchersEvicted++;try{t.onInvalidate()}catch{}this.logger(`info`,`watcher LRU evict ${e}`)}}size(){return this.slots.size}closeAll(){this.closed=!0;for(let e of this.slots.values())this.closeSlot(e);this.slots.clear()}},cE=class{running=new Set;again=new Set;run(e,t){return this.again.add(e),this.running.has(e)?{kind:`queued`}:(this.running.add(e),{kind:`started`,done:this.loop(e,t)})}async loop(e,t){try{do this.again.delete(e),await t();while(this.again.has(e))}finally{this.running.delete(e),this.again.delete(e)}}clear(){this.running.clear(),this.again.clear()}get size(){return this.running.size}};const lE={showSha:!0,showStashCount:!0};function uE(e){let t=Object.keys(e).sort(),n={};for(let r of t)n[r]=e[r];return JSON.stringify(n)}function dE(e){let t=t=>{try{return s.statSync(v.join(e,t)).mtimeMs}catch{return 0}};return{head:t(`HEAD`),index:t(`index`)}}function fE(e,t){return e.head!==t.head||e.index!==t.index}function pE(e){let t=[],n=v.join(e,`refs/heads`);try{s.statSync(n).isDirectory()&&t.push({path:n})}catch{}return{files:[v.join(e,`HEAD`),v.join(e,`index`)],dirs:t}}var mE=class extends aE{entries=new Map;subscribersByRepo=new Map;fetchInFlight=new Map;resolutions=new Map;prCache=new Map;prFetchInFlight=new Map;refreshes=new cE;hits=0;misses=0;invalidations=0;inner;ttlMs;maxEntries;watchers;ownsWatchers;logger;sanityTimer=null;constructor(e={}){super(),this.inner=e.inner??new aE,this.ttlMs=e.ttlMs??3e4,this.maxEntries=e.maxEntries??64,this.logger=e.logger??Gt,e.watchers?(this.watchers=e.watchers,this.ownsWatchers=!1):(this.watchers=new sE({logger:this.logger}),this.ownsWatchers=!0);let t=e.sanityIntervalMs??3e5;t>0&&(this.sanityTimer=setInterval(()=>this.runSanityCheck(),t),this.sanityTimer.unref())}getWatcherRegistry(){return this.watchers}getStats(){return{size:this.entries.size,hits:this.hits,misses:this.misses,invalidations:this.invalidations,watchers:this.watchers.size()}}resolveEffectiveGitDir(e,t){let n=`${e}|${t??``}`,r=Date.now(),i=this.resolutions.get(n);if(i&&r-i.computedAt<this.ttlMs)return this.resolutions.delete(n),this.resolutions.set(n,i),i.dir;let a=this.inner.resolveEffectiveGitDir(e,t);return this.resolutions.set(n,{dir:a,computedAt:r}),a.catch(()=>{this.resolutions.get(n)?.dir===a&&this.resolutions.delete(n)}),this.evictResolutionsIfNeeded(),a}evictResolutionsIfNeeded(){for(;this.resolutions.size>this.maxEntries;){let e=this.resolutions.keys().next().value;if(e===void 0)break;this.resolutions.delete(e)}}async getGitInfo(e,t={},n){let r=await this.resolveEffectiveGitDir(e,n);return r.kind===`ok`?this.getGitInfoForRoot(r.value,t):r}getGitInfoForRoot(e,t){let n=`${e}|${uE(t)}`,r=Date.now(),i=this.entries.get(n);if(i&&r-i.computedAt<this.ttlMs)return this.entries.delete(n),this.entries.set(n,i),this.hits++,Promise.resolve(L(i.info));let a=this.fetchInFlight.get(n);if(a)return a;let o=this.doFetch(e,n,t,r).finally(()=>{this.fetchInFlight.delete(n)});return this.fetchInFlight.set(n,o),o}async doFetch(e,t,n,r){this.misses++;let i=this.inner.resolveGitDir(e),a=dE(i),o=await this.inner.getGitInfo(e,n);if(o.kind!==`ok`)return o;let s=o.value;n.showPullRequest&&(s.pullRequest=await this.getPullRequestCached(e,s.branch)),this.dropEntry(t);let c=this.watchers.acquire(`git:${e}`,pE(i),()=>this.invalidateRepo(e));return this.entries.set(t,{info:s,computedAt:r,mtime:a,watcher:c,repoRoot:e}),this.evictIfNeeded(),o}async getPullRequestCached(e,t){let n=await this.inner.getRepoRemoteUrl(e);if(n.kind===`failed`)return n;if(n.kind===`absent`)return R;let r=n.value,i=`${e}|${t}|${r}`,a=Date.now(),o=this.prCache.get(i);if(o){let e=o.pr.kind===`failed`?45e3:3e5;if(a-o.computedAt<e)return this.prCache.delete(i),this.prCache.set(i,o),o.pr}let s=this.prFetchInFlight.get(i);if(s)return s;let c=this.inner.resolvePullRequest(e,r).then(e=>(this.prCache.set(i,{pr:e,computedAt:Date.now()}),this.evictPrIfNeeded(),e)).finally(()=>{this.prFetchInFlight.delete(i)});return this.prFetchInFlight.set(i,c),c}evictPrIfNeeded(){for(;this.prCache.size>this.maxEntries;){let e=this.prCache.keys().next().value;if(e===void 0)break;this.prCache.delete(e)}}deliverable(e,t){return e.kind===`failed`?(this.logger(`warn`,`git fetch failed (${t}): ${e.reason}`),null):e.kind===`ok`?e.value:null}subscribe(e,t){let n=!1,r=null;return{firstDelivery:(async()=>{let i=await this.resolveEffectiveGitDir(e);if(n)return;if(i.kind!==`ok`){i.kind===`failed`&&this.logger(`warn`,`git resolve failed (subscribe ${e}): ${i.reason}`),this.safeInvoke(t,null);return}let a=i.value,o=this.subscribersByRepo.get(a);if(!o){let t=this.inner.resolveGitDir(a),n=this.watchers.acquire(`git:${a}`,pE(t),()=>this.invalidateRepo(a));o={workingDir:e,repoRoot:a,callbacks:new Set,watcher:n},this.subscribersByRepo.set(a,o)}o.callbacks.add(t),r={repoRoot:a,entry:o};let s=await this.getGitInfoForRoot(a,{...lE});n||this.safeInvoke(t,this.deliverable(s,a))})(),unsubscribe:()=>{if(n=!0,!r)return;let{repoRoot:e,entry:i}=r;i.callbacks.delete(t),i.callbacks.size===0&&(i.watcher.release(),this.subscribersByRepo.delete(e))}}}invalidateRepo(e){let t=0;for(let[n,r]of this.entries)r.repoRoot===e&&(r.watcher.release(),this.entries.delete(n),t++);t>0&&(this.invalidations+=t,this.logger(`info`,`gitCache invalidate ${e} dropped=${t}`)),this.refreshSubscribers(e)}refreshSubscribers(e){let t=this.subscribersByRepo.get(e);!t||t.callbacks.size===0||this.refreshes.run(e,()=>this.refreshOnce(e))}async refreshOnce(e){let t=this.subscribersByRepo.get(e);if(!t||t.callbacks.size===0)return;let n=await this.getGitInfoForRoot(e,{...lE}),r=this.deliverable(n,e),i=this.subscribersByRepo.get(e);if(!(!i||i.callbacks.size===0))for(let e of[...i.callbacks])i.callbacks.has(e)&&this.safeInvoke(e,r)}safeInvoke(e,t){try{e(t)}catch(e){this.logger(`warn`,`git subscriber threw: ${e.message??String(e)}`)}}dropEntry(e){let t=this.entries.get(e);t&&(t.watcher.release(),this.entries.delete(e))}evictIfNeeded(){for(;this.entries.size>this.maxEntries;){let e=this.entries.keys().next().value;if(e===void 0)break;this.dropEntry(e),this.logger(`info`,`gitCache evict ${e}`)}}runSanityCheck(){let e=new Map;for(let t of this.entries.values()){let n=e.get(t.repoRoot);n||(n=dE(this.inner.resolveGitDir(t.repoRoot)),e.set(t.repoRoot,n)),fE(t.mtime,n)&&this.invalidateRepo(t.repoRoot)}}runSanityCheckNow(){this.runSanityCheck()}close(){this.sanityTimer&&=(clearInterval(this.sanityTimer),null);for(let e of this.entries.values())e.watcher.release();this.entries.clear();for(let e of this.subscribersByRepo.values())e.callbacks.clear(),e.watcher.release();this.subscribersByRepo.clear(),this.refreshes.clear(),this.fetchInFlight.clear(),this.prCache.clear(),this.prFetchInFlight.clear(),this.resolutions.clear(),this.ownsWatchers&&this.watchers.closeAll()}};const hE=/\r\n|\r|\n/g,gE=e=>L(e.replace(hE,` `).trim());function _E(e){return t=>{let n=e.exec(t)?.[1];return n===void 0?z(`regex no-match`):L(n.replace(hE,` `))}}const vE=e=>{try{return L(JSON.parse(e))}catch(e){return z(`JSON parse failed: ${e.message}`)}},yE=e=>e.getTime()/1e3,bE=e=>new Date(e*1e3);function xE(e,t){return t.kind!==`ttl`||t.durationMs>=500?t:(k(`declareShell "${e}": ttl ${t.durationMs}ms below floor 500ms; clamping`),{kind:`ttl`,durationMs:500})}function SE(e){let t=/^(\d+(?:\.\d+)?)(ms|s|m|h)$/.exec(e);if(!t)throw RangeError(`Invalid duration: "${e}"`);let n=parseFloat(t[1]);switch(t[2]){case`ms`:return n;case`s`:return n*1e3;case`m`:return n*6e4;case`h`:return n*36e5;default:throw RangeError(`Unexpected duration unit: "${t[2]}"`)}}const CE=`session.id`;function wE(e,t,n){return{where:`output of "${e}" in ${t}`,read:async()=>{let r=await Le({bin:`/bin/sh`,args:[`-c`,e],cwd:t,category:`user-shell`,signal:n});if(!r.ok&&r.reason===`aborted`)throw n.reason;return r.ok?L(r.stdout):z(`shell "${e}" ${r.exitCode===null?[r.reason,r.error].filter(e=>e!==void 0).join(`: `):`exited with code ${r.exitCode}`} in ${t}`)}}}function TE(e,t,n){return{where:`"${e}"`,read:async()=>{try{let r=await ce(e,{encoding:`utf8`,signal:n});return L(t===`first-line`?r.split(/\r?\n/)[0]??``:r)}catch{if(n.aborted)throw n.reason;return z(`file unreadable: ${e}`)}}}}function EE(e,t,n){if(e.kind!==`ok`)return e;let r=t(e.value);return r.kind===`failed`?z(`${r.reason} in ${n}`):r}const DE=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],OE=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],kE=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`],AE=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function jE(e,t){let n=[[`2006`,e=>String(e.getFullYear())],[`January`,e=>DE[e.getMonth()]],[`Monday`,e=>kE[e.getDay()]],[`Jan`,e=>OE[e.getMonth()]],[`Mon`,e=>AE[e.getDay()]],[`15`,e=>String(e.getHours()).padStart(2,`0`)],[`06`,e=>String(e.getFullYear()%100).padStart(2,`0`)],[`01`,e=>String(e.getMonth()+1).padStart(2,`0`)],[`02`,e=>String(e.getDate()).padStart(2,`0`)],[`04`,e=>String(e.getMinutes()).padStart(2,`0`)],[`05`,e=>String(e.getSeconds()).padStart(2,`0`)],[`PM`,e=>e.getHours()<12?`AM`:`PM`],[`pm`,e=>e.getHours()<12?`am`:`pm`],[`1`,e=>String(e.getMonth()+1)],[`2`,e=>String(e.getDate())],[`3`,e=>String(e.getHours()%12||12)],[`4`,e=>String(e.getMinutes())],[`5`,e=>String(e.getSeconds())]],r=``,i=0;for(;i<e.length;){let a=!1;for(let[o,s]of n)if(e.startsWith(o,i)){r+=s(t),i+=o.length,a=!0;break}a||(r+=e[i],i++)}return r}const ME={branch:`string`,sha:`string`,dirty:`boolean`,ahead:`number`,behind:`number`,stash:`number`};function NE(e,t,n,r){if(e===null){if(n!==void 0)return n;let e=ME[t];try{return VE(r,e)}catch{return HE(e)}}switch(t){case`branch`:return e.branch===`detached`?``:e.branch;case`sha`:return ki(e.sha,``);case`dirty`:return e.status!==`clean`;case`ahead`:return ki(e.aheadBehind,{ahead:0,behind:0}).ahead;case`behind`:return ki(e.aheadBehind,{ahead:0,behind:0}).behind;case`stash`:return ki(e.stashCount,0)}}function PE(e){try{return h(e)}catch{return e}}function FE(e){try{return g(e).isDirectory()}catch{return!1}}function IE(e){let t=PE(e);return FE(t)?{dir:t,name:null,leaf:!0}:yv(t)}const LE=e=>`${e.dir}\0${e.name??``}`;var RE=class{watchers=new Map;subscribe(e,t,n){let r=this.watchers.get(e)??this.arm(e);return r.subscribers.set(t,n),r.watcher===null&&n(r.failure),()=>this.unsubscribe(e,t)}arm(e){let t={watcher:null,failure:``,target:IE(e),subscribers:new Map};return t.watcher=this.open(e,t,t.target),this.watchers.set(e,t),t}rearm(e,t){let n=IE(e);if(t.watcher!==null&&LE(n)===LE(t.target))return;let r=this.open(e,t,n);r!==null&&(t.watcher?.close(),t.watcher=r,t.target=n)}open(e,t,n){let{dir:r,name:i}=n,a=v.basename(r);try{return _(r,(n,r)=>{if(!(r===null||i===null||r===i)&&r!==a)return;let o=t.target.leaf;if(this.rearm(e,t),!(!o&&!t.target.leaf))for(let e of t.subscribers.keys())e()})}catch(n){let i=`watch_file ${e}: cannot watch ${r} — ${n instanceof Error?n.message:String(n)}`;t.failure=i;for(let e of t.subscribers.values())e(i);return null}}unsubscribe(e,t){let n=this.watchers.get(e);n&&(n.subscribers.delete(t),n.subscribers.size===0&&(n.watcher?.close(),this.watchers.delete(e)))}dispose(){for(let{watcher:e}of this.watchers.values())e?.close();this.watchers.clear()}size(){return this.watchers.size}},zE=class{buckets=new Map;subscribe(e,t){let n=this.buckets.get(e);if(!n){let t=new Set;n={timer:pe(()=>{for(let e of t)e()},e),callbacks:t},this.buckets.set(e,n)}return n.callbacks.add(t),()=>this.unsubscribe(e,t)}unsubscribe(e,t){let n=this.buckets.get(e);n&&(n.callbacks.delete(t),n.callbacks.size===0&&(de(n.timer),this.buckets.delete(e)))}dispose(){for(let{timer:e}of this.buckets.values())de(e);this.buckets.clear()}bucketCount(){return this.buckets.size}};function BE(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n)return;n=n[e]}return n}function VE(e,t){if(typeof e!=`string`&&typeof e!=`number`&&typeof e!=`boolean`)throw TypeError(`Expected string|number|boolean from payload, got ${typeof e}`);return t===`string`?Ev(e):t===`number`?Dv(e):Ov(e)}function HE(e){return e===`number`?0:e===`boolean`?!1:``}var UE=class{inputMetas=new Map;lastErrors=new Map;policyFaults=new Map;watchMgr=new RE;ttlMgr=new zE;gitSubscriptions=new Map;cleanups=[];inFlight=new Map;reads=new cE;abort=new AbortController;drawn=Cv.observable.box(V.TRUECOLOR);drawnAt=()=>this.drawn.get();instant=Cv.observable.box(null);now=()=>{let e=this.instant.get();if(e===null)throw Error(`the time was read before any render published its instant`);return bE(e)};engine=yT({clock:this.now,drawnAt:this.drawnAt});gitProvider;ownsGitProvider;sessionState;constructor(e,t=``,n,r){this.store=e,this.defaultEmptyValue=t,n?(this.gitProvider=n,this.ownsGitProvider=!1):(this.gitProvider=new mE({sanityIntervalMs:0}),this.ownsGitProvider=!0),this.sessionState=r}get variableStore(){return this.store}declareLiteral(e,t){this.store.defineBox(e,Tv(t),t)}declareFailedDocument(e,t){this.store.defineDocument(e,z(t))}declareInput(e,t,n,r){let i=r===void 0?this.defaultFor(n):r;this.store.defineBox(e,n,i),this.inputMetas.set(e,{path:t,varDefault:r})}declareEnv(e,t,n){let r=process.env[t];if(r!==void 0){this.store.defineBox(e,`string`,r);return}let i=n===void 0?typeof this.defaultEmptyValue==`string`?this.defaultEmptyValue:``:n;this.store.defineBox(e,`string`,i),this.recordError(e,`env var "${t}" is not set`)}declareShell(e,t,n){this.declareSource(e,wE(t,n.cwd,this.abort.signal),xE(e,n.cache),n.parse)}declareFile(e,t,n){this.declareSource(e,TE(t,n.readMode??`whole`,this.abort.signal),n.cache,n.parse)}declareSource(e,t,n,r){let i=this.publisherFor(e,r,t.where),a=()=>this.runSource(e,t,i);a(),this.registerCachePolicy(e,n,a)}publisherFor(e,t,n){switch(t.kind){case`text`:return this.scalarPublisher(e,gE,t.default,n);case`regex`:return this.scalarPublisher(e,_E(t.regex),t.default,n);case`json`:return this.documentPublisher(e,t.default,n)}}scalarPublisher(e,t,n,r){let i=this.stringInitial(n);return this.store.defineBox(e,`string`,i),n=>{let a=EE(n,t,r);this.noteOutcome(e,a),this.store.setBox(e,ki(a,i))}}documentPublisher(e,t,n){let r=t===void 0?R:L(t);this.store.defineDocument(e,r);let i,a=!1;return this.cleanups.push(()=>clearTimeout(i)),o=>{clearTimeout(i);let s=o.kind===`ok`&&o.value.trim()===``?R:o,c=EE(s,vE,n);this.noteOutcome(e,c);let l=c.kind===`ok`||s.kind===`ok`||t===void 0?c:r,u=a&&s.kind===`ok`&&c.kind!==`ok`,d=()=>{a=c.kind===`ok`,this.store.setDocument(e,l)};u?i=setTimeout(d,250):d()}}runSource(e,t,n){let r=this.reads.run(e,()=>t.read().then(n,e=>{if(e!==this.abort.signal.reason)throw e}));r.kind===`started`&&this.track(e,r.done)}track(e,t){let n=t.finally(()=>{this.inFlight.get(e)===n&&this.inFlight.delete(e)});this.inFlight.set(e,n)}async settled(e){let t=Date.now()+e;for(;this.inFlight.size>0;){let e=t-Date.now();if(e<=0)break;let n,r=await Promise.race([Promise.all(this.inFlight.values()).then(()=>`settled`),new Promise(t=>{n=setTimeout(()=>t(`deadline`),e)})]);if(clearTimeout(n),r===`deadline`)break}return[...this.inFlight.keys()]}declareTemplate(e,t,n={}){let r=this.engine.parse(t);this.declareDerived(e,()=>r.evaluate(bT(this.store)).map(e=>e.plain).join(``),n.varDefault)}declareTime(e,t){this.declareDerived(e,()=>jE(t.format,this.now()),t.varDefault)}declareDerived(e,t,n){this.store.defineComputed(e,`string`,()=>{try{let n=t();return this.lastErrors.delete(e),n}catch(t){let r=t instanceof Error?t.message:String(t);if(this.recordError(e,r),n===void 0)throw Av(t)?new kv(e,`variable "${e}": ${r}`):Error(`variable "${e}": ${r}`);return n}})}declareGit(e,t){let n=ME[t.field],r=t.varDefault===void 0?HE(n):VE(t.varDefault,n);this.store.defineBox(e,n,r);let i=this.gitSubscriptions.get(t.cwd);if(!i){let e=new Map,n=this.gitProvider.subscribe(t.cwd,t=>{this.store.runInAction(()=>{for(let[n,r]of e)for(let{name:e,varDefault:i}of r)this.store.setBox(e,NE(t,n,i,this.defaultEmptyValue))})});i={fieldSubs:e,firstDelivery:n.firstDelivery,unsubscribe:n.unsubscribe},this.gitSubscriptions.set(t.cwd,i)}let a=i.fieldSubs.get(t.field);a||(a=[],i.fieldSubs.set(t.field,a)),a.push({name:e,varDefault:t.varDefault}),this.track(e,i.firstDelivery)}declareState(e,t){if(!this.sessionState)throw Error(`declareState("${e}"): SourceRegistry was constructed without a SessionState — state-kind variables require a SessionState (the daemon provides one; tests must supply one)`);let n=this.sessionState,r=t.varDefault??this.stringInitial(void 0);this.store.defineComputed(e,`string`,e=>{let i=e(CE);if(typeof i!=`string`||!i)return r;let a=n.get(i,t.key);return a===null?r:a})}stateRevision(){let e=this.store.has(`session.id`)?this.store.read(CE):``;return this.sessionState!==void 0&&typeof e==`string`&&e!==``?this.sessionState.revision(e):0}applyInput(e){this.store.runInAction(()=>{for(let[t,n]of this.inputMetas){let r=BE(e,n.path),i=this.store.getType(t);if(r!==void 0)try{this.store.setBox(t,VE(r,i)),this.lastErrors.delete(t)}catch(e){this.applyFallback(t,i,n.varDefault,e instanceof Error?e.message:String(e))}else this.applyFallback(t,i,n.varDefault,`input path "${n.path}" not found in payload`)}})}drawAt(e){this.store.runInAction(()=>this.drawn.set(e))}renderAt(e){this.store.runInAction(()=>this.instant.set(e))}getLastError(e){let t=this.lastErrors.get(e),n=this.policyFaults.get(e);return n===void 0?t:t===void 0?n:{timestamp:t.timestamp,message:`${n.message}; ${t.message}`}}cachePolicyFaults(){return this.policyFaults}dispose(){this.abort.abort();for(let e of this.cleanups)e();this.cleanups.length=0;for(let e of this.gitSubscriptions.values())e.unsubscribe();return this.gitSubscriptions.clear(),this.reads.clear(),this.watchMgr.dispose(),this.ttlMgr.dispose(),this.ownsGitProvider&&this.gitProvider.close(),this.store.dispose()}registerCachePolicy(e,t,n){switch(t.kind){case`never`:break;case`ttl`:{let e=this.ttlMgr.subscribe(t.durationMs,n);this.cleanups.push(e);break}case`watch_file`:{let r=this.watchMgr.subscribe(t.path,n,t=>this.notePolicy(e,z(t)));this.cleanups.push(r);break}case`key`:{let r=this.engine.parse(t.template),i=()=>{try{return L(r.evaluate(bT(this.store)).map(e=>e.plain).join(``))}catch(e){return Av(e)?R:z(`cache key: ${e instanceof Error?e.message:String(e)}`)}},a=i();this.notePolicy(e,a);let o=a.kind===`ok`?a.value:void 0,s=(0,Cv.reaction)(i,t=>{this.notePolicy(e,t),!(t.kind!==`ok`||t.value===o)&&(o=t.value,n())});this.cleanups.push(s);break}case`depends_on`:{let e=(0,Cv.reaction)(()=>t.varNames.map(e=>this.store.changeKey(e)).join(`,`),n);this.cleanups.push(e);break}}}applyFallback(e,t,n,r){if(this.recordError(e,r),n!==void 0){this.store.setBox(e,n);return}try{this.store.setBox(e,VE(this.defaultEmptyValue,t))}catch{this.store.setBox(e,HE(t))}}defaultFor(e){try{return VE(this.defaultEmptyValue,e)}catch{return HE(e)}}stringInitial(e){return e===void 0?typeof this.defaultEmptyValue==`string`?this.defaultEmptyValue:``:e}recordError(e,t){this.lastErrors.set(e,{timestamp:Date.now(),message:t})}notePolicy(e,t){t.kind===`failed`?this.policyFaults.set(e,{timestamp:Date.now(),message:t.reason}):this.policyFaults.delete(e)}noteOutcome(e,t){t.kind===`ok`?this.lastErrors.delete(e):this.recordError(e,t.kind===`failed`?t.reason:`no value`)}};const WE={project_dir:{kind:`input`,path:`workspace.project_dir`,default:``},[CE]:{kind:`input`,path:`session_id`,default:``},transcript_path:{kind:`input`,path:`transcript_path`,default:``},resume_command:{kind:`input`,path:`resumeCommand`,default:``},config_path:{kind:`input`,path:`configPath`,default:``},"theme.effective":{kind:`input`,path:`theme.effective`,default:``},"style.effective":{kind:`input`,path:`style.effective`,default:``},"effect.effective":{kind:`input`,path:`effect.effective`,default:``},"preset.effective":{kind:`input`,path:`preset.effective`,default:``},"preset.customized":{kind:`input`,path:`preset.customized`,type:`boolean`,default:!1},"preset.bundled":{kind:`input`,path:`preset.bundled`,type:`boolean`,default:!0},"endcaps.effective":{kind:`input`,path:`endcaps.effective`,default:``},"variation.effective":{kind:`input`,path:`variation.effective`,default:``},"shade.effective":{kind:`input`,path:`shade.effective`,default:``},"colorCompatibility.effective":{kind:`input`,path:`colorCompatibility.effective`,default:``},"transitions.effective":{kind:`input`,path:`transitions.effective`,type:`boolean`,default:!1},"autoWrap.effective":{kind:`input`,path:`autoWrap.effective`,type:`boolean`,default:!0},"padding.effective":{kind:`input`,path:`padding.effective`,type:`number`,default:1},"updateNotice.effective":{kind:`input`,path:`updateNotice.effective`,type:`boolean`,default:!0},...Object.fromEntries(Pa.map(e=>[La(e),{kind:`input`,path:La(e),type:`boolean`,default:!1}])),"term.cols":{kind:`input`,path:`term.cols`,type:`number`,default:80},"tmux.pane":{kind:`input`,path:`tmux.pane`,default:``},"autocompact.window":{kind:`input`,path:`autocompact.window`,type:`number`,default:-1},...Object.fromEntries([`applied`,`lower`,`higher`].map(e=>[`autocompact.${e}`,{kind:`input`,path:`autocompact.${e}`,type:`number`,default:0}])),"autocompact.error":{kind:`input`,path:`autocompact.error`,default:``},"git.repoUrl":{kind:`input`,path:`git.repoUrl`,default:``}},GE=`ne .tmux.pane ""`;function KE(e,t,n){let r=new Set,i=e=>{for(let t of lv(e??``,n).keys())r.add(t)};for(let t of Object.values(e.segments))i(t.template),i(t.bg),i(t.fg),i(t.when);for(let e of t)for(let t of $g(e))i(t.when),t.kind===`segment`&&(i(t.lead),i(t.trail));for(let t of Object.values(e.variables))t.kind===`template`&&i(t.template),t.kind===`state`&&r.add(CE);for(let t of Object.values(e.actions)){r.add(CE),`copy`in t&&i(t.copy),`open`in t&&i(t.open);let e=`set`in t?Ga.get(t.set):void 0,n=`persist`in t?Wa.get(t.persist):void 0;e!==void 0&&r.add(e),n!==void 0&&r.add(n)}return r}function qE(e,t,n){let r=_v({...n,variables:{...n.variables,...e.variables},segments:{...n.segments,...e.segments}}),i={};for(let a of KE(e,t,n.helpers)){if(gv(a,r))continue;let e=WE[a];if(e===void 0)throw Error(`synthesized chrome reads ".${a}", which it does not declare and PAYLOAD_INPUTS does not supply`);i[a]=e}return i}function JE(e){return e.replace(/[^A-Za-z0-9]+/g,`_`)}var YE=class extends Error{file;issues;warnings;constructor(e,t,n=[]){super($E(e,t)),this.name=`ConfigError`,this.file=e,this.issues=t,this.warnings=n}};function Y(e,t){let n=0,r;for(let i of t){if(i===``||/^\d+$/.test(i))continue;let t=XE(e,n,i);if(t===-1)return r===void 0?void 0:ZE(e,r);n=t,r=t}return r===void 0?void 0:ZE(e,r)}function XE(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 ZE(e,t){let n=1;for(let r=0;r<t&&r<e.length;r++)e.charCodeAt(r)===10&&n++;return n}function QE(e,t){try{return Lr(t),null}catch(n){if(!(n instanceof jr))throw n;return`${e}:${ZE(t,n.offset)}: ${n.reason} — the settings menu cannot edit this file until it is fixed`}}function $E(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(`
|
|
74
|
+
`)}const eD=`groups.`,tD=`menus.`,nD=`edit.`,X=`candybar.`,rD=[eD,tD,nD,X];function iD(e){return rD.some(t=>e.startsWith(t))}function aD(e){let t=JE(e);return rD.find(e=>t.startsWith(JE(e)))}function oD(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:Y(e.source,[`root`])})}function sD(e){return e}function cD(e,t,n){return n===void 0?tD+JE(e)+`.`+JE(t):lD(n)}function lD(e){return tD+JE(e)}function uD(e,t){return e+`.`+t}function dD(e){return e+`.page`}const fD=[`closeOnPick`,`paged`,`key`,`distribution`],pD=e=>fD.includes(e),mD=`"closeOnPick" (bool, default false), "paged" (bool, default true), "key" (string, accordion grouping), "distribution" (one of ${Xp.map(e=>`"${e}"`).join(`, `)}; default "van-der-corput")`;function hD(e){for(let t of Object.keys(e))if(!pD(t))throw Error(`unknown {{ menu }} option "${t}" — the options dict takes ${mD}`);let t=(t,n)=>{let r=e[t];if(r===void 0)return n;if(typeof r!=`boolean`)throw Error(`{{ menu }} option "${t}" must be a boolean, got ${JSON.stringify(r)} (e.g. (dict "${t}" ${String(!n)}))`);return r},n=e.key;if(n!==void 0&&typeof n!=`string`)throw Error(`{{ menu }} option "key" must be a string naming the accordion group, got ${JSON.stringify(n)}`);if(n===``)throw Error(`{{ menu }} has an empty accordion key — a shared key must be a non-empty name (or omit "key" for an independent menu)`);let r=e.distribution;if(r!==void 0&&!Zp(r))throw Error(`{{ menu }} option "distribution" must be one of: ${Xp.join(`, `)}; got ${JSON.stringify(r)}`);return{closeOnPick:t(`closeOnPick`,!1),paged:t(`paged`,!0),key:n,distribution:$p(r)}}const gD=e=>`from`in e?e.from:e.themes;function _D(e,t,n){return e===`bool`?Fh(t)!==null:`min`in e?Ih(t,e)!==null:J_(gD(e),n).members.includes(t)}function vD(e,t){if(e===`bool`)return Nh.join(` or `);if(!(`min`in e)){let n=gD(e),{members:r}=J_(n,t),i=r.map(e=>JSON.stringify(e));if(r.length<=8)return`one of ${i.join(`, `)}`;let a=typeof n==`string`?` "${n}"`:``;return`one of the ${r.length}${a} names, such as ${i.slice(0,3).join(`, `)}`}return`an integer from ${e.min} to ${e.max}`}function yD(e){return{label:e.label,domain:bD(e.domain)}}function bD(e){return e===`theme`?{themes:G_}:e===`bool`||`min`in e?e:{from:e}}function xD(e,t,n,r,i){let a=mr(e.label),{domain:o}=e;if(o===`bool`)return{kind:`inline`,template:`{{ action "${r}" "☑ ${a}" "☐ ${a}" }}`,actions:{[r]:{set:t,cycle:[...Nh]}},variables:{}};if(`from`in o)return SD(t,r,i,o.from,e=>({template:`{{ "${a}" }} {{ carousel "${e.apply}" 0 "${e.open}" }}`,rows:[`{{ picker "${e.apply}" "${e.page}" false true true }}`]}));if(`themes`in o)return SD(t,r,i,o.themes,e=>({template:`{{ action "${e.open}" "${a}" .${n} }} {{ action "${e.open}" (swatch "${e.apply}") }}`,rows:[`{{ swatches "${e.apply}" "${e.page}" }}`,`{{ themePreview "${e.apply}" }}`]}));let s=e=>({set:t,min:o.min,max:o.max,by:e});return{kind:`inline`,template:`{{ action "${r}.down" "◀" }} {{ "${a}" }} {{ .${n} }} {{ action "${r}.up" "▶" }}`,actions:{[`${r}.down`]:s(-o.step),[`${r}.up`]:s(o.step)},variables:{}}}function SD(e,t,n,r,i){let a={variable:n,key:n,member:t},o=uD(n,t),s=`${t}.open`,c=dD(n),l=`${c}.current`,{template:u,rows:d}=i({apply:t,open:s,page:c});return{kind:`picker`,template:u,actions:{[t]:{set:e,from:r},[o]:Sr(n,t),[c]:{set:c,int:!0},[l]:{set:c,to:`-1`},[s]:{do:[o,l]}},variables:{[n]:xr(n,ur),[c]:{kind:`state`,key:c,default:`0`}},list:{ref:a,rows:d}}}function CD(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 ${kD(i)}`,line:Y(e.source,[...t.split(`.`),r])}),null)}function wD(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 ${kD(i)}`,line:Y(e.source,[...t.split(`.`),`default`])});return}return i}}function TD(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 ${kD(i)}`,line:Y(e.source,[...t.split(`.`),r])});return}return i}}function ED(e,t,n){let r=TD(e,t,n,`palette`);if(r!==void 0){if(!e.allowedPalettes.has(r)){e.issues.push({path:`${t}.palette`,message:`Unknown palette "${r}"${Jm(r)}. Expected one of: ${[...e.allowedPalettes].sort().join(`, `)}`,line:Y(e.source,[...t.split(`.`),`palette`])});return}return r}}function DD(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 ${Z(a)}`,line:Y(e.source,[...t.split(`.`),r])});return}return a}}function OD(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function kD(e){return e===null?`null`:Array.isArray(e)?`array`:typeof e}function Z(e){return typeof e==`string`?JSON.stringify(e):e===void 0?`undefined`:String(e)}function AD(e,t,n,r){return OD(r)?(PD(e,n,r,t.noun,new Set(Object.keys(t.fields)),jD(e,t.removed??{},n,r)),MD(e,t.fields,n,r)):(e.issues.push({path:n,message:`${n} must be an object, got ${kD(r)}`,line:Y(e.source,n.split(`.`))}),null)}function jD(e,t,n,r){let i=Object.entries(t).filter(([e])=>r[e]!==void 0);for(let[t,r]of i)FD(e,`${n}.${t}`,`${n}.${t} was removed: ${r}`);return new Set(i.map(([e])=>`${n}.${e}`))}function MD(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 ND=new Set;function PD(e,t,n,r,i,a=ND){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:Y(e.source,[...t.split(`.`),o])})}function FD(e,t,n){return e.issues.push({path:t,message:n,line:Y(e.source,t.split(`.`))}),null}function ID(e,t,n,r){if(!OD(r))return e.issues.push({path:n,message:`${t.noun} must be an object, got ${kD(r)}`,line:Y(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:Y(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:Y(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:Y(e.source,n.split(`.`))}),null;let c=o[0];return i[c].parse(e,`${n}.${c}`,r[c])}function LD(e,t,n,r){if(!OD(r))return e.issues.push({path:n,message:`${n} must be an object, got ${kD(r)}`,line:Y(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 ${kD(i)}`,line:Y(e.source,n.split(`.`))}),null;let a=t.arms;if(!(i in a))return e.issues.push({path:`${n}.${t.tag}`,message:`Unknown ${t.noun} "${i}". Expected one of: ${Object.keys(a).join(`, `)}`,line:Y(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 PD(e,n,r,`${i} ${t.memberNoun} key`,o.keys,l),c}function RD(e,t,n){return{json:QD(XD(n),e,t),keys:new Set([e,...Object.keys(n)])}}function zD(e){return(...t)=>e()(...t)}function BD(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:Y(n.source,o.split(`.`))}),null}return a}}function VD(){return{required:!1,json:{type:`string`},parse:(e,t,n,r)=>TD(e,t,r,n)}}function HD(){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 ${kD(i)}`,line:Y(e.source,[n])});return}return i}}}}function UD(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 ${Z(o)}`,line:Y(e.source,[i])});return}return o}}}}function WD(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 ${Z(a)}`,line:Y(e.source,[r])});return}return a}}}}function GD(){return{required:!1,json:{type:`string`},parse:(e,t,n,r)=>ED(e,t,r)}}function KD(){return{required:!0,json:{type:`string`},parse:(e,t,n,r)=>CD(e,t,r,n)??void 0}}function qD(e,t){return x(t)?null:`${e} must be an absolute path (\`~\` and relative paths are not expanded), got ${JSON.stringify(t)}`}function JD(){return{required:!0,json:{type:`string`,pattern:`^/`},parse:(e,t,n,r)=>{let i=CD(e,t,r,n);if(i===null)return;let a=qD(`${t}.${n}`,i);return a===null?i:FD(e,`${t}.${n}`,a)??void 0}}}function YD(e){return{required:!1,json:{enum:[...e]},parse:(t,n,r,i)=>DD(t,n,i,r,e)}}function XD(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 ZD(e){return XD(e.fields)}function QD(e,t,n){let r=e,i={[t]:{const:n},...r.properties},a=[t,...r.required??[]];return{...r,properties:i,required:a}}function $D(e){let t=e.arms;return{anyOf:Object.values(t).map(e=>e.json)}}function eO(e){let t=e.arms;return{anyOf:Object.entries(t).map(([e,t])=>({type:`object`,properties:{[e]:t.json},required:[e],additionalProperties:!1}))}}const tO={required:!1,json:{enum:[...Ch]},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: ${Ch.join(`, `)}`,line:Y(e.source,[...t.split(`.`),n])});return}return DD(e,t,r,n,Ch)}},nO={required:!1,json:{type:`string`},parse:(e,t,n,r)=>{let i=TD(e,t,r,n);return rh(i)?i:ED(e,t,r)}},rO={required:!1,json:{anyOf:[{enum:[...ph]},{type:`string`,pattern:`\\{\\{`}]},parse:(e,t,n,r)=>{let i=r[n];return typeof i==`string`&&rh(i)?i:DD(e,t,r,n,ph)}},iO=/^[^\r\n]*\S[^\r\n]*$/u,aO=RegExp(`^(?:✖|✕)[\\uFE0E\\uFE0F]?$`,`u`),oO={required:!1,json:{type:`string`,pattern:iO.source,not:{pattern:aO.source}},parse:(e,t,n,r)=>{let i=TD(e,t,r,n);if(i===void 0||iO.test(i)&&!aO.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:Y(e.source,[...t.split(`.`),n])})}};function sO(e){return{spec:YD(e),domain:{from:e}}}function cO(){return{spec:HD(),domain:`bool`}}function lO(e){return{spec:e,domain:`text`}}const uO={default_empty_value:lO(VD()),default_separator:lO(VD()),palette:{spec:nO,domain:{themes:`themes`}},style:{spec:VD(),domain:{from:`styles`}},effect:{spec:rO,domain:{from:ph}},preset:{spec:VD(),domain:{from:`presets`}},endcaps:sO(vh),variation:sO(Th),shade:sO(Oh),autoWrap:cO(),padding:{spec:UD(Ph),domain:{...Ph,step:1}},updateNotice:cO(),transitions:cO(),experimentalBand:cO(),experimentalStatusline:cO(),experimentalPane:cO(),colorCompatibility:{spec:tO,domain:{from:Ch}},menuGlyph:lO(oO)},dO=Object.fromEntries(Object.entries(uO).map(([e,t])=>[e,t.spec]));function fO(e){return uO[e].domain}function pO(e){let t=fO(e);if(t===`text`)throw Error(`globals.${e} is free text, which no control can change — list it in UNCONTROLLED_GLOBALS instead of SETTINGS`);return t}function mO(e,t){return{required:!1,json:{not:{},description:`not allowed here — ${e}`},parse:(e,n,r,i)=>{i[r]!==void 0&&e.issues.push({path:`${n}.${r}`,message:t(`${n}.${r}`),line:Y(e.source,[...n.split(`.`),r])})}}}function hO(e){return mO(`${e} cannot select a preset`,t=>`${t}: ${e} cannot select a preset. Which preset is active is resolved once, as session pick over globals.preset over "default"; a fragment naming another would be a second authority over that. Set the default arrangement in the top-level globals.preset instead.`)}function gO(e){return mO(`${e} cannot change the settings menu glyph`,t=>`${t}: ${e} cannot change the settings menu glyph — one menu is shared by every preset. Set it in the top-level globals.menuGlyph instead.`)}function _O(e,t,n){return{...e,json:{...e.json,not:{pattern:`\\{\\{`}},parse:(r,i,a,o)=>{let s=o[a];if(typeof s==`string`&&rh(s)){r.issues.push({path:`${i}.${a}`,message:`${i}.${a}: a rule is not allowed here — ${t} ${n}, so it names a value. Write the rule in globals.${a} (or a preset's globals.${a}) instead.`,line:Y(r.source,[...i.split(`.`),a])});return}return e.parse(r,i,a,o)}}}const vO={default_bg:"nothing reads it — a segment with no `bg:` wears the decoration tint of its place in the bar. Delete the key, and author `bg:` on the segments that need a fixed colour.",default_fg:"nothing reads it — a segment with no `fg:` wears text chosen for contrast against its background. Delete the key, and author `fg:` on the segments that need a fixed colour.",default_truncate_marker:'nothing reads it — a segment clipped to its `width:` always ends in "…". Delete the key.',look:`it was renamed "style" — write the same name as style: "<name>"`,progression:`it was renamed "variation", and its values with it: accent (was secondary-accent), duo (was primary-secondary), mono (was primary)`,charset:"the bar always draws Nerd Font glyphs. Delete the key; `cc-candybar doctor` names what your terminal's font is missing."},yO={noun:`globals key`,fields:dO,removed:vO},bO={preset:hO(`a preset`),menuGlyph:gO(`a preset`)},xO={noun:`preset globals key`,fields:{...dO,...bO},removed:vO};function SO(e){return MO(e)&&!(e in bO)}const CO=`is decided later than any rule could be settled`,wO={noun:`editGlobals key`,removed:vO,fields:{...dO,preset:hO(`the editGlobals fragment`),menuGlyph:gO(`the editGlobals fragment`),palette:_O(dO.palette,`the editGlobals fragment`,CO),style:_O(dO.style,`the editGlobals fragment`,CO),effect:_O(dO.effect,`the editGlobals fragment`,CO)}},TO={noun:`theme default key`,fields:{...Object.fromEntries(i_.map(e=>[e,dO[e]])),style:_O(dO.style,`a theme's default`,`is the look that theme wears by name`)}};function EO(e,t){if(!OD(t))return e.issues.push({path:`themeDefaults`,message:`themeDefaults must be an object mapping theme names to { shade, variation, style }, got ${kD(t)}`,line:Y(e.source,[`themeDefaults`])}),{};let n={};for(let[r,i]of Object.entries(t)){let t=`themeDefaults.${r}`;if(!e.allowedPalettes.has(r)){e.issues.push({path:t,message:`${t}: "${r}" is not an installed theme${Jm(r)}. Expected one of: ${[...e.allowedPalettes].sort().join(`, `)}`,line:Y(e.source,[`themeDefaults`,r])});continue}let a=AD(e,TO,t,i);a!==null&&(n[r]=a)}return n}function DO(e,t,n){return n===void 0?{}:AD(e,yO,t,n)??{}}function OO(e,t,n){return AD(e,xO,t,n)??{}}function kO(){return ZD(xO)}function AO(e,t,n){return AD(e,wO,t,n)??{}}const jO=new Set(Object.keys(dO));function MO(e){return jO.has(e)}function NO(e){return Object.hasOwn(vO,e)?vO[e]:void 0}function PO(){return[...jO]}const FO={padding:1};function IO(e){let t=new Map;for(let[n,r]of Object.entries(FO)){let i=e[n];t.set(n,typeof i==`number`?i:r)}return t}const LO=/^segments\.([^.]+)\.palette$/,RO=/^presets\.(.+)\.root$/,zO=/^presets\.(.+)\.globals\.([^.]+)$/,BO=/^themeDefaults\.(.+)\.([^.]+)$/;function VO(e){return`presets.${e}.root`}function HO(e,t){return`themeDefaults.${e}.${t}`}const UO=e=>i_.includes(e);function WO(e,t){return`presets.${e}.globals.${t}`}function GO(e){if(MO(e))return{scope:`globals`,field:e};let t=LO.exec(e);if(t)return{scope:`segment-palette`,segment:t[1]};let n=zO.exec(e);if(n&&SO(n[2]))return{scope:`preset-globals`,preset:n[1],field:n[2]};let r=BO.exec(e);if(r&&UO(r[2]))return{scope:`theme-default`,theme:r[1],field:r[2]};let i=RO.exec(e);return i?{scope:`preset-root`,preset:i[1]}:null}function KO(e){switch(e.scope){case`globals`:return[`globals`,e.field];case`preset-globals`:return[`presets`,e.preset,`globals`,e.field];case`segment-palette`:return[`segments`,e.segment,`palette`];case`theme-default`:return[`themeDefaults`,e.theme,e.field]}}const qO=[`location`,`git`,`model-context`,`cost-limits`,`activity`,`session-tools`],JO=[...qO,`other`],YO={location:`location`,git:`git`,"model-context":`model & context`,"cost-limits":`cost & limits`,activity:`activity`,"session-tools":`session tools`,other:`other`},XO=Cb({fromString:e=>e}),ZO=`edit.mode`,QO=`edit.configure`,$O=`edit.toggle`,ek=`edit.unconfigure`,tk=[$O,ek],nk=`arrange`,rk=`${nD}draft.`;function ik(e,t){return`${e}:${t}`}const ak={variable:ZO,key:ZO,member:nk},ok=gr(ak);function sk(e){try{return XO.parse(e).referencedCalls().some(e=>e.name===`action`&&e.args[0]===`edit.toggle`)}catch{return!1}}function ck(e){if(Object.values(e.actions??{}).some(e=>`do`in e&&e.do.includes(`edit.toggle`)))return!0;for(let t of Object.values(e.segments??{}))for(let e of[t.template,t.bg,t.fg])if(typeof e==`string`&&sk(e))return!0;return!1}function lk(e,t){if(oD(e,t,nD,`edit mode`),!ck(t))return;let{variables:n,actions:r}=uk();t.variables={...t.variables??{},...n},t.actions={...t.actions??{},...r}}function uk(){return{variables:{[ZO]:xr(ZO,ur),[QO]:xr(QO,ur)},actions:{[$O]:Sr(ZO,nk),[ek]:{set:QO,to:ur}}}}const dk=`open`;function fk(e,t,n,r){let i={variable:e,key:e,member:dk};return r.variables[e]=xr(e,ur),r.actions[e]=Sr(e,dk),r.segments[e]={template:vr(e,`(?)`,`✕`),...pk(n)},hr(e,i,{kind:`container`,direction:`horizontal`,children:t.map((t,n)=>{let i=`${e}.${n}`;return r.segments[i]={template:t},{kind:`segment`,name:i}})},`drop`)}function pk(e){let[t,...n]=e;return t===void 0?{}:{when:gr(t,...n)}}const mk=`none`;function hk(e){return Us(e,`background`)}var gk=class extends Error{constructor(e,t,n){super(`Invalid ${t} color ${JSON.stringify(e)}: ${n}`),this.name=`ColorSpecError`}};function _k(e,t,n,r,i){let{palette:a,tint:o,text:s}=e,c=vk(n,i),l=c!==mk,u=l?c===void 0?o:yk(a,c,`bg`):hk(a);e.bg=u;let d=vk(r,i),f=d===void 0?l?(e=>e.hex===o.hex?s:xm(a,e,t))(u):void 0:yk(a,d,`fg`);return new U({...l&&{bgcolor:H.fromRgba(u)},...f!==void 0&&{color:H.fromRgba(f)}})}function vk(e,t){if(e!==void 0)return e.evaluate(t).map(e=>e.plain).join(``)}function yk(e,t,n){try{return Us(e,t)}catch(e){throw e instanceof Hs?new gk(t,n,e.message):e}}const bk=`🔧`,xk={help:[`-h`,`--help`],version:[`-V`,`--version`]},Sk=[`✚ inserts`,`✖ removes`,`${bk} configures`,`↺ resets layout`],Ck=`
|
|
75
75
|
cc-candybar - Beautiful powerline statusline for Claude Code
|
|
76
76
|
|
|
77
77
|
Usage: cc-candybar [options]
|
|
78
78
|
|
|
79
79
|
Standalone Commands:
|
|
80
|
-
${
|
|
81
|
-
${
|
|
80
|
+
${xk.help.join(`, `).padEnd(25)}Show this help
|
|
81
|
+
${xk.version.join(`, `).padEnd(25)}Print the version of this runtime (cc-candybar <version>)
|
|
82
82
|
|
|
83
83
|
Debugging:
|
|
84
84
|
CC_CANDYBAR_DEBUG=1 Enable debug logging for troubleshooting
|
|
@@ -101,7 +101,7 @@ Configuration:
|
|
|
101
101
|
failed row's [fix] to repair it (the same checks \`cc-candybar doctor\` runs).
|
|
102
102
|
|
|
103
103
|
Anywhere the bar shows (?), clicking it reveals these same instructions
|
|
104
|
-
in place. In edit mode: ${
|
|
104
|
+
in place. In edit mode: ${Sk.join(`, `)}.
|
|
105
105
|
|
|
106
106
|
Subcommands:
|
|
107
107
|
install One-shot setup: stages the runtime (native render
|
|
@@ -167,15 +167,15 @@ Config tooling:
|
|
|
167
167
|
config [--json] The effective merged config. (All three query the
|
|
168
168
|
running daemon; none spawn one.)
|
|
169
169
|
|
|
170
|
-
`,
|
|
171
|
-
`).map(e=>e.trim()).filter(e=>e!==``),...e.warnings];return{ok:!1,reason:t,more:n}}case`loaded`:return eA([...e.warnings,...e.unused.map(({kind:e,name:t})=>`${e} "${t}" ${oA[e]}`)])}}},cA="re-run `cc-candybar install`";function lA(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:// — ${cA}`];let{app:t,missing:n}=e.value;return n.kind===`failed`?[`${t} opens cc-candybar://, but ${n.reason} — ${cA}`]:n.value.map(e=>`${e} is missing, and ${t} runs it — ${cA}`)}const uA={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}) — ${cA}`:`the URL handler runs cc-candybar ${e.handler}; the bar runs ${e.bar} — ${cA}`};case`lost`:return eA([...lA(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 dA({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 fA(e,t){return t===`frames`?`run \`node ${e.bundle} frames --lane <band|statusline|pane>\``:e.checkout===null?cA:`run \`just install-rust\` and point the statusLine command at ${e.checkout.root}/bin/cc-candybar-native`}function pA(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 — ${fA(e,`native`)}`];let{bundle:i,source:a}=dA(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} — ${fA(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 — ${fA(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 mA=`this daemon holds no render of this bar (it restarted since the bar was drawn, or has served 64 newer sessions)`,hA={name:`install`,label:`install`,takesMark:!1,probe:({install:e,askedBy: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===`click`?`${mA}, so which client draws it is unknown — run the doctor again once the bar has redrawn`:`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`}:eA([...new Set(i.flatMap(e=>pA(n,r,e)))])}};function gA({postMortems:e},t){return e.kind===`ok`&&t.kind===`ok`?e.value.filter(e=>t.value===null||rn(e.identity,t.value)):[]}function _A(e,t){return e.kind===`failed`?t:t.filter(t=>t.pid!==e.value.pid)}const vA={name:`daemon`,label:`daemon`,takesMark:!1,probe:({daemon:{serving:e,processes:t,read:n}})=>{let r=[...n.kind===`failed`?[`which post-mortems were read could not be read: ${n.reason}`]:[],...t.kind===`failed`?[`the process table could not be read: ${t.reason}`]:[]],i=t.kind===`ok`?_A(e,t.value):[];if(e.kind===`failed`){let t=i.length>0?` — daemon ${i.map(e=>e.pid).join(`, `)} running`:``;return eA([`${e.reason}${t}`,...r])}let{pid:a,rss:o,rssLimit:s,postMortems:c}=e.value,l=gA(e.value,n),u=eA([...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}`]:[],...r,...i.map(e=>`daemon ${e.pid} (started ${e.started}, ${en(e.rss)} MB${e.ppid===1?``:`, child of ${e.ppid}`}) runs beside the one serving the bar (${a}) — \`kill ${e.pid}\``),...an(o,s)?[`the daemon holds ${en(o)} MB of its ${en(s)} MB limit — at the limit it records a post-mortem and restarts`]:[]]),d=l[0];return u.ok||d===void 0?u:{...u,fix:{kind:`post-mortems-read`,through:d.identity}}}},yA=`click 🩺 doctor in the bar's settings menu: if it runs, links work`;function bA(e,t){let n=qk(e);return t.kind===`ok`&&n!==null&&t.value.includes(n)?{kind:`draws`}:e.kind===`known`?Yk(e.terminal):{kind:`unknown`}}function xA({identified:e,tmuxClient:t},n){let r=Jk(e),i=bA(e,n),a=qk(e)===null?yA:`${yA}, 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: ${Xk}`];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 SA={name:`links`,label:`links`,takesMark:!1,probe:({askedBy:e,terminal:t,clicked:n})=>{if(e===`click`)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 eA(xA(t,n))}}},CA={name:`effectRefresh`,label:`effect refresh`,takesMark:!1,probe:({effect:e,placementEffects:t,transitions:n,claudeSettings:r})=>{let i=[...e.kind===`decided`?e.value===`none`?[]:[`the bar wears the ${e.name} effect`]:[`a globals.effect rule can give the bar an effect`],...t.map(({placement:e,effect:t})=>`${e} wears the ${t} effect`),...n?[`placements fade in and dissolve out as they come and go`]:[]];if(i.length===0)return{ok:!0};let a=i.join(` and `),{path:o,statusLine:s}=r;switch(s.kind){case`absent`:return{ok:!1,reason:`${a}, and ${o} sets no statusLine — set "refreshInterval": 1 beside the statusLine command that runs the bar`};case`not-an-object`:return{ok:!1,reason:`${a}, and ${o} sets statusLine to ${JSON.stringify(s.value)}, not a statusLine object — re-run \`cc-candybar install\` to write one`};case`present`:break}let c=s.refreshInterval;return c===1?{ok:!0}:{ok:!1,reason:c===void 0?`${a}, but Claude Code redraws it only on events`:typeof c==`number`&&c>1?`${a}, but Claude Code redraws it only every ${c} s`:`${a}, but statusLine.refreshInterval is ${JSON.stringify(c)}, not a number of seconds Claude Code accepts (its minimum is 1)`,fix:{kind:`claude-settings`,path:[`statusLine`,`refreshInterval`],value:1}}}},wA=e=>[...e].map(e=>`U+${e.codePointAt(0).toString(16).toUpperCase()}`).join(` `);function TA(e){switch(e.kind){case`unreported`:case`unasked`:return`this terminal`;case`unknown`:case`unnamed`:return Jk(e);case`bundling`:case`unread`:case`configured`:return[Lk(e.name),e.version].filter(e=>e!==null).join(` `)}}function EA(e){switch(e.kind){case`unreported`:case`unasked`:return null;case`unknown`:case`unnamed`:return qk(e);case`bundling`:case`unread`:return Lk(e.name);case`configured`:{let t=Lk(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 DA(e){let t=EA(e.terminal);return t===null?void 0:{glyphs:e.glyphs,id:`${t}|${wA(e.glyphs)}`}}const OA={name:`nerdFont`,label:`Nerd Font`,takesMark:!0,probe:({nerdFont:e,marks:t})=>{if(e.kind===`none`)return{ok:!0};if(t.kind===`failed`)return{ok:!1,reason:`the mark book could not be read: ${t.reason}`};let n=DA(e),r=e=>({ok:!1,reason:e,...n!==void 0&&{sighting:n}}),i=e.terminal,a=TA(i);switch(n===void 0?null:t.value.nerdFont?.[n.id]??null){case`drawn`:return{ok:!0};case`boxes`:return r(`${a} draws ${wA(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=Nk[i.name].glyphs.since;if(e===null)return{ok:!0};let t=i.version===null?null:Hk(i.version,e);if(t===!0)return{ok:!0};let n=Lk(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 ${wA(n)} — set a Nerd Font as its font`)}}}};function kA(e){return e.join(`, `)}function AA(e){return`or set missingData: "ignore" on ${kA(e)}`}function jA(e){if(e.kind===`unneeded`)return[];let{segments:t,fact:n}=e;if(n.kind===`failed`)return[`${kA(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`?[`${kA(t)}: ${r} is not installed, so no pull request is ever shown — install it, ${AA(t)}`]:[`${kA(t)}: ${r} is not logged in to ${i} (${a.loggedOut}) — run \`${r} auth login --hostname ${i}\`, ${AA(t)}`]}function MA(e,t){if(e.kind===`unneeded`)return[];let{segments:n,fact:r}=e;return r.kind===`failed`?[`${kA(n)}: ${r.reason}`]:r.value.length===0?[t===`click`?`${kA(n)}: ${mA}, so whether Claude Code sends rate_limits is unseen — run the doctor again once the bar has redrawn`:`${kA(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`]:r.value.includes(`missing`)&&!r.value.includes(`carried`)?[`${kA(n)}: Claude Code sent no rate_limits — it sends them only to Claude.ai subscription sessions; on any other account, set missingData: "ignore" on ${kA(n)}`]:[]}function NA(e){if(e.kind===`unneeded`)return[];let{segments:t,fact:n}=e;switch(n.located.kind){case`ok`:return[];case`absent`:return[`${kA(t)}: memento is not installed (or is disabled) for ${n.claudeConfigDir} — install the memento plugin, ${AA(t)}`];case`failed`:return[`${kA(t)}: whether memento is installed could not be read: ${n.located.reason}`]}}const PA={name:`segmentData`,label:`segment data`,takesMark:!1,probe:({data:e,askedBy:t})=>eA([...jA(e.pullRequests),...MA(e.rateLimits,t),...NA(e.memento)])};function FA({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 ${Qk/1024/1024} MiB of`} the transcript ${e} are not JSON objects — the bar skips them, so what it counts from them is missing`]}}}const IA=[sA,hA,vA,uA,SA,rA,iA,aA,CA,OA,PA,{name:`sessionData`,label:`session data`,takesMark:!1,probe:({transcripts:e,askedBy:t})=>e.kind===`failed`?{ok:!1,reason:e.reason}:e.value.length===0?{ok:!1,reason:t===`click`?`${mA}, so which transcript it reads is unknown — run the doctor again once the bar has redrawn`:`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`}:eA(e.value.flatMap(FA))}],LA=IA.filter(e=>e.takesMark);function RA(e){return IA.map(t=>({check:t,verdict:t.probe(e)}))}function zA(e){return IA.find(t=>t.name===e)}const BA=`${X}doctor.`;function VA(e){let t=`${BA}${e}.`;return{verdict:`${t}verdict`,reason:`${t}reason`,fixable:`${t}fixable`,sighting:`${t}sighting`}}function HA(e,t){let n=e.kind===`seen`?e.tmuxClient:null,r=e.kind===`seen`?qk(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 UA(e,t){let n=e.kind===`seen`?e.tmuxClient:null;return`cols=${t??`-`} clientUtf8=${n===null?`-`:n.utf8?`yes`:`no`}`}function WA(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}=dA(t,e);return`${e.client}/${n.kind}/${r.kind===`uncompared`?`-`:r.kind}`}).join(`,`)||`-`}`}function GA({serving:e,processes:t,read:n}){let r=t.kind===`failed`?`daemons=unread others=-`:`daemons=${t.value.length} others=${_A(e,t.value).map(e=>e.pid).join(`,`)||`-`}`;if(e.kind===`failed`)return`${r} rss=unasked postMortems=unasked`;let{rss:i,rssLimit:a,postMortems:o}=e.value,s=o.kind===`failed`||n.kind===`failed`?`unread`:`${gA(e.value,n).length}/${o.value.length}`;return`${r} rss=${en(i)}/${en(a)} postMortems=${s}`}function KA(e){let t=()=>{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`},n=()=>{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`)}`},r=e.memento.kind===`unneeded`?`-`:e.memento.fact.located.kind===`ok`?`located`:e.memento.fact.located.kind;return`data=pr:${t()},rateLimits:${n()},memento:${r}`}function qA(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 JA(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=DA(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 YA(e,t=[]){return t.length===0?e:`${e} (+${t.length} more — run \`cc-candybar doctor\`)`}function XA(e){return e.flatMap(({check:e,verdict:t})=>{let n=VA(e.name);return t.ok?[{key:n.verdict,value:`ok`},{key:n.reason,value:``},{key:n.fixable,value:Nh},{key:n.sighting,value:``}]:[{key:n.verdict,value:`failed`},{key:n.reason,value:YA(t.reason,t.more)},{key:n.fixable,value:t.fix===void 0?Nh:Mh},{key:n.sighting,value:t.sighting?.glyphs??``}]})}const ZA={copySession:{copy:`{{ .session.id }}`},copyResume:{copy:`{{ .resume_command }}`},openProject:{open:`{{ .project_dir }}`},openTranscript:{open:`{{ .transcript_path }}`},openConfig:{open:`{{ .config_path }}`}};function QA(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(ZA).map(([t,n])=>[`${e}${t}`,n]))}}const $A=`armed`,ej=`disarmed`,tj=`.armed`,nj=e=>e.endsWith(tj);function rj(e,t,n){let r=`${e}${tj}`,i=`${e}.arm`,a=`${e}.disarm`,o=`(eq .${e} "${$A}")`;return{template:`{{ if ${o} }}{{ action "${e}" "${t.confirm}" }} {{ action "${a}" "✕" }}{{ else }}{{ action "${i}" "${t.arm}" }}{{ end }}`,actions:{[i]:{set:r,to:$A},[a]:{set:r,to:ej},[e]:{do:[a,...n]}},armed:o,variables:{[e]:{kind:`state`,key:r,default:ej}},disarm:a}}const ij=RegExp(`^/[^\\s\\x00-\\x1f\\x7f-\\x9f/][^\\x00-\\x1f\\x7f-\\x9f]*$`);function aj(e){return typeof e==`string`&&ij.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 oj(e){let t=aj(e);if(t.kind===`refused`)throw Error(t.reason);return t.line}const sj=[`/compact`,`/model`],cj=`/clear`;function lj(e){let t=t=>`${e}${t.slice(1)}`,n=`${e}clear.slash`,r=rj(`${e}clear`,{arm:cj,confirm:`${cj} ✓ confirm`},[n]);return{template:sj.map(e=>`{{ action "${t(e)}" "${e}" }} `).join(``)+r.template,when:`{{ ${KE} }}`,actions:{...Object.fromEntries(sj.map(e=>[t(e),{slash:oj(e)}])),...r.actions,[n]:{slash:oj(cj)}},variables:r.variables,disarm:r.disarm}}const uj=Array.from({length:10},(e,t)=>(t+1)*1e5),dj=uj[0],fj=uj[uj.length-1];function pj(e){let t;try{t=Ei(e)}catch(e){return z(e instanceof Error?e.message:String(e))}let n=t.autoCompactWindow;return n===void 0?L(`auto`):typeof n==`number`&&Number.isInteger(n)&&n>=dj&&n<=fj?L(n):z(`${e}: autoCompactWindow is ${JSON.stringify(n)}, not a window /autocompact accepts (${dj}–${fj} tokens)`)}function mj(e,t){let n=Math.min(t??fj,fj),r=e===`auto`?n:Math.min(e,n);return{window:e===`auto`?0:e,applied:e===`auto`?0:r,lower:uj.filter(e=>e<r).at(-1)??0,higher:uj.find(e=>e>r&&e<=n)??0}}function hj(e,t){return{template:`{{ if ne .autocompact.error "" }}⇲ ⚠ {{ .autocompact.error }}{{ else }}⇲ {{ if eq .autocompact.window 0 }}auto{{ else }}${t(`.autocompact.applied`)}{{ end }}{{ if ${KE} }}{{ 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:oj(`/autocompact auto`)},...Object.fromEntries(uj.map(t=>[`${e}${t}`,{slash:oj(`/autocompact ${t}`)}]))}}}const gj=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 }}`,_j=`${X}menu`,vj=`open`,yj=`${X}edit`,bj=`${X}toolbar`,xj=QA(X),Sj=`${X}commands`,Cj=lj(`${Sj}.`),wj=`${X}autocompact`,Tj=hj(`${wj}.`,gj),Ej=e=>({kind:`segment`,name:e}),Dj=`${X}tab`,Oj=[{member:`session`,label:`⚡ session`},{member:`look`,label:`🎨 look`},{member:`layout`,label:`📐 layout`},{member:`config`,label:`⚙ config`},{member:`tools`,label:`🧰 tools`}],kj=e=>`${Dj}.${e}`,Aj=e=>`${kj(e)}.toggle`,jj=e=>({variable:Dj,key:Dj,member:e}),Mj=`${X}save`,Nj=`${X}preset.save`,Pj=`${X}preset.delete`,Fj=e=>`${X}${e}`,Ij=e=>`${X}apply.${e}`,Lj=e=>`${X}reset.${e}`,Rj=`${X}themeDefault.save`,zj=`${X}themeDefault.differs`,Bj=`${X}themeDefault.theme`,Vj={when:`{{ .${zj} }}`,template:`{{ action "${Rj}" (printf "⤓ default for %s" .${Bj}) }} {{ swatch "${Ij(`theme`)}" .${Bj} }}`},Hj=`${X}resetAll`,Uj=`${_j}.toggle`,Wj={variable:_j,key:_j,member:vj},Gj=`${X}undo`,Kj=`${X}back`,qj=`${Kj}.step`,Jj=`${X}navigation.back`,Yj=Kj,Xj={template:`{{ if gt .${Jj} 0 }}{{ action "${Kj}" "◁" }}{{ else }}{{ fg (${Tk}) "◁" }}{{ end }}`},Zj=`${X}redo`,Qj=`${X}doctor`,$j=`${Qj}.run`,eM=e=>`${Qj}.fix.${e}`,tM=(e,t)=>`${Qj}.mark.${e}.${t}`,nM=e=>`${Qj}.${e}`,rM={drawn:`[✓ shapes]`,boxes:`[✗ boxes]`},iM=uD(`${X}pickers`),aM=`${X}gear`,oM=`gear`,sM=`${aM}.toggle`,cM={variable:iM,key:iM,member:oM},lM=uD(`${X}gearPickers`),uM=[{template:`{{ themePreview }}`}],dM={template:`{{ layoutPreview }}`},fM={preset:[dM,{when:`{{ not .preset.bundled }}`,template:`{{ action "${Pj}" (printf "🚮 delete %s" .${Ba.preset.effectiveVar}) }}`}],style:uM,variation:[dM],shade:[dM]},pM=(e,t)=>`${X}list.${e}.${t}`,mM=e=>`${X}resettable.${e}`,hM=e=>e.length===0?`false`:`(or ${e.map(e=>`.${mM(e)}`).join(` `)})`,gM={preset:`door`,theme:`look`,style:`gear`,effect:`look`,variation:`gear`,shade:`gear`,endcaps:`look`,transitions:`look`,autoWrap:`layout`,padding:`layout`,updateNotice:`config`,experimentalBand:`config`,experimentalStatusline:`config`,experimentalPane:`config`},_M=e=>e===`gear`?gM.theme:e,vM=Object.keys(Ba).map(e=>{let t=Ba[e],n=mO(t.configKey),r=SD({label:t.label,domain:n},t.sessionKey,t.effectiveVar,Ij(e),gM[e]===`gear`?lM:iM);return{...t,name:e,control:r,beneath:fM[e]??[]}}),yM=e=>vM.filter(t=>gM[t.name]===e),bM=e=>vM.filter(t=>_M(gM[t.name])===e),xM={theme:[hr(aM,cM,{kind:`container`,direction:`horizontal`,children:yM(`gear`).map(PM)},`drop`)]},SM=e=>yM(e).flatMap(e=>[PM(e),...xM[e.name]??[]]);new Set(vM.flatMap(e=>[e.sessionKey,e.configKey]));const CM=rj(Hj,{arm:`⟲`,confirm:`⟲ reset all?`},vM.map(e=>Lj(e.name))),wM=[`unsaved`,`history.undo`,`history.redo`],TM=e=>`${X}${e}`,EM=TM(`unsaved`),DM=(e,t)=>({body:t,shown:`(gt .${TM(e)} 0)`}),OM=[DM(`unsaved`,`{{ action "${Mj}" (printf "💾 save %d" .${EM}) }}`),DM(`history.undo`,`{{ action "${Gj}" "↶" }}`),DM(`history.redo`,`{{ action "${Zj}" "↷" }}`),{body:CM.template,shown:`(or ${hM(vM.map(e=>e.name))} ${CM.armed})`}],kM={when:`{{ or ${OM.map(e=>e.shown).join(` `)} }}`,template:`{{ $sep := "" }}`+OM.map(e=>`{{ if ${e.shown} }}{{ $sep }}${e.body}{{ $sep = " " }}{{ end }}`).join(``)},AM=[{step:CM,place:`door`},{step:Cj,place:`session`}],jM=e=>e.map(e=>e.step.disarm),MM=jM(AM),NM=jM(AM.filter(e=>e.place!==`door`));function PM(e){let t=Fj(e.name);return e.control.kind===`inline`?Ej(t):hr(t,e.control.list.ref,{kind:`container`,direction:`vertical`,children:[...e.control.list.rows,...e.beneath].map((t,n)=>Ej(pM(e.name,n)))},`drop`)}function FM(e){return e===_j}function IM(e){let t=Ej(_j);if(e.kind===`container`&&e.direction===`vertical`){let[n,...r]=e.children;return e.when===void 0&&n!==void 0?{...e,children:[IM(n),...r]}:{kind:`container`,direction:`vertical`,children:[t,e]}}return e.kind===`container`&&e.when===void 0?{...e,children:[t,...e.children]}:{kind:`container`,direction:`horizontal`,children:[t,e]}}function LM(e){return RM(e)>0?e:IM(e)}function RM(e){let t=0;for(let n of e_(e))n.kind===`segment`&&FM(n.name)&&(t+=1);return t}function zM(e,t=!1){let n=t||e.when!==void 0;return e.kind===`segment`?n&&FM(e.name)||e.opens!==void 0&&zM(e.opens.body,!0):e.children.some(e=>zM(e,n))}const BM={session:{direction:`vertical`,content:[Ej(bj),{kind:`container`,direction:`horizontal`,children:[Ej(Sj),Ej(wj)]}],after:[]},look:{direction:`horizontal`,content:[],after:[Ej(Rj)]},layout:{direction:`horizontal`,content:[Ej(Nj),Ej(yj)],after:[]},config:{direction:`horizontal`,content:[],after:[]},tools:{direction:`vertical`,content:[Ej(Qj),...IA.map(e=>Ej(nM(e.name)))],after:[]}},VM=e=>({kind:`container`,direction:BM[e].direction,children:[...BM[e].content,...SM(e),...BM[e].after]});function HM(e){return e.kind===`segment`?FM(e.name)?hr(e.name,Wj,WM,`above`):e:KM(e)}function UM(){return{kind:`container`,direction:`vertical`,children:[{kind:`container`,direction:`horizontal`,children:[Ej(Yj),...SM(`door`),Ej(Mj)]},{kind:`container`,direction:`horizontal`,children:Oj.map(({member:e})=>hr(kj(e),jj(e),VM(e),`drop`))}]}}const WM=UM();function GM(e){let t=new Map;for(let e of e_(WM))e.kind===`segment`&&e.opens!==void 0&&t.set(e.opens.ref.key,e.opens.ref.variable);return[...t].map(([t,n])=>{let r=e.variables[n];if(r?.kind!==`state`||r.default===void 0)throw Error(`settings menu: the door folds "${t}", but "${n}" is not a state variable the menu declares with a default`);let i=`${_j}.fold.${YE(t)}`;return e.actions[i]={set:t,to:r.default},i})}function KM(e){return{...e,children:e.children.map(e=>HM(e))}}function qM(e){let t={variables:{[_j]:xr(_j,ur)},actions:{[Uj]:Sr(_j,vj),[$j]:{doctor:`run`},[yj]:{do:[...nk]},...xj.actions,...Cj.actions,...Tj.actions,[Mj]:{save:!0},[Gj]:{undo:!0},[qj]:{back:!0},[Kj]:{do:[qj,...MM]},[Zj]:{redo:!0},[Nj]:{preset:`save`},[Rj]:{themeDefault:`save`},[Pj]:{preset:`delete`,name:`{{ .${Ba.preset.effectiveVar} }}`}},segments:{[_j]:{template:`{{ $door := ${yr(_j,br(e),br(`✖`))} }}{{ if ${_r(Wj)} }}{{ fg (keptOn (color "error") (bgOf)) $door }}{{ else }}{{ $door }}{{ end }}`},[bj]:{template:xj.template},[Sj]:{template:Cj.template,when:Cj.when},[wj]:{template:Tj.template,bg:Tj.bg,when:Tj.when},[Yj]:Xj,[Mj]:kM,[Rj]:Vj,[Nj]:{template:`{{ action "${Nj}" "+ preset" }}`},[Qj]:{template:`{{ action "${$j}" "🩺 doctor" }}`},[yj]:{template:`{{ action "${yj}" "✎ arrange" "✎ done" }}`}}};t.variables[zj]={kind:`input`,path:`themeDefault.differs`,type:`boolean`,default:!1},t.variables[Bj]={kind:`input`,path:`themeDefault.theme`,type:`string`,default:``},t.variables[Jj]={kind:`input`,path:`navigation.back`,type:`number`,default:0};for(let e of wM)t.variables[TM(e)]={kind:`input`,path:e,type:`number`,default:0};t.variables[Dj]=xr(Dj,`session`);for(let{member:e,label:n}of Oj){t.actions[Aj(e)]=Sr(Dj,e),t.actions[kj(e)]={do:[Aj(e),...NM]};let r=hM(bM(e).map(e=>e.name)),i=`(ternary ${br(` •`)} "" ${r})`,a=e=>`(print ${br(e)} ${i})`;t.segments[kj(e)]={template:`{{ ${yr(kj(e),a(n),a(`▾ ${n}`))} }}`}}return Object.assign(t.variables,Cj.variables,CM.variables),YM(t),JM(t),t.actions[_j]={do:[Uj,...MM,...GM(t)]},t}function JM(e){for(let t of IA){let n=VA(t.name),r=eM(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?Zk:[];for(let n of i)e.actions[tM(t.name,n)]={doctor:`mark`,check:t.name,mark:n};let a=i.map(e=>` {{ action "${tM(t.name,e)}" "${rM[e]}" }}`).join(``);e.segments[nM(t.name)]={when:`{{ ne .${n.verdict} "" }}`,template:`{{ if eq .${n.verdict} "ok" }}✓ ${t.label}{{ else }}✗ ${t.label} — {{ .${n.reason} }}{{ if eq .${n.fixable} "${Mh}" }} {{ action "${r}" "[fix]" }}{{ end }}`+(a===``?``:`{{ if ne .${n.sighting} "" }} {{ .${n.sighting} }}${a}{{ end }}`)+`{{ end }}`}}}function YM(e){for(let t of vM){Object.assign(e.actions,t.control.actions);let n=Lj(t.name);e.actions[n]={reset:t.configKey},e.variables[mM(t.name)]={kind:`input`,path:`resettable.${t.name}`,type:`boolean`,default:!1};let r=`{{ if .${mM(t.name)} }} {{ action "${n}" "↺" }}{{ end }}`;Object.assign(e.variables,t.control.variables),e.segments[Fj(t.name)]={template:`${t.control.template}${r}`},t.control.kind===`picker`&&[...t.control.list.rows.map(e=>({template:e})),...t.beneath].forEach((n,r)=>{e.segments[pM(t.name,r)]=n})}Object.assign(e.actions,CM.actions),e.actions[sM]=Sr(iM,oM),e.segments[aM]={template:`{{ action "${sM}" "⚙" }}`}}function XM(e){let{variables:t,actions:n}=dk();Object.assign(e.variables,t),Object.assign(e.actions,n)}function ZM(e){let t=qM(e.globals.menuGlyph??`🍫`);XM(t);let n={...e.presets},r=[];for(let t of z_(e.presets)){let{node:i}=H_(e,t),a=HM(LM(i));r.push(a),n[t]={...V_(e.presets,t),root:a}}let i=JE(t,r,e);return{...e,variables:{...i,...e.variables,...t.variables},actions:{...e.actions,...t.actions},segments:{...e.segments,...t.segments},presets:n}}const QM=`${rD}live`,$M=[`☐ live`,`☑ live`],eN=`${rD}done`,tN=`${rD}cancel`,nN=`${rD}rewind`,rN=`${rD}changes`,iN=`(gt .${rN} 0)`,aN=`(or ${iN} (gt .${EM} 0))`,oN={variable:QM,key:QM,member:`open`};function sN(e){return`${rD}configuring.p${e}`}function cN(e){return`and ${_r(ok)} (not ${_r(oN)}) (ne .${sN(e)} "true")`}function lN(e){return{kind:`template`,template:`{{ or ${e.map(e=>`(eq .${$O} "${mr(e)}")`).join(` `)} false }}`}}function uN(e,t,n){return`{{ if ${cN(e)} }}${t}{{ else }}${n}{{ end }}`}const dN=`{{ and ${_r(ok)} .preset.customized }}`,fN=aD;function pN(e){return new Map([...q_(e),...hN(e)])}const mN=`${rD}addable`;function hN(e){return new Map([[mN,{members:Object.keys(e.segments).filter(e=>!fN(e)),library:{groups:YO.map(e=>({id:e,label:XO[e]})),entry:t=>{let n=e.segments[t];return{group:n.group??`other`,...n.description!==void 0&&{description:n.description}}}}}]])}function gN(e,t,n){return n.segments[e]={template:t,when:sk,bg:hk},{kind:`segment`,name:e}}function _N(e,t,n){let r=`${rD}${e.presetIdent}.remove.${t}`;return e.artifacts.actions[r]={persist:e.rootKey,removeSegment:n},`{{ fg (${`readableOn (color "error") (bgOf) ${xm}`}) (action "${r}" "✖") }}`}function vN(e){return`{{ if ${_r(ok)} }}${e}{{ end }}`}function yN(e,t){return e.reduce((e,t)=>`{{ if and ${_r(ok)} ${_r(t)} }}true{{ else }}${e}{{ end }}`,t)}function bN(e){return e.flatMap(e=>[...e_(e)].flatMap(e=>e.kind===`segment`&&e.opens?.ref.key===`edit.configure`?[e.opens.ref]:[]))}function xN(e,t,n){return`${ik}${e}.${t}.${n}`}function SN(e,t,n,r){let i=Xg(n),a=`${rD}${e.presetIdent}`,o=ak(e.presetIdent,i);e.configured.push(o);let s=`${a}.configure.${t}`,c=uD(s),l=`${s}.fold`;e.artifacts.actions[l]={set:c,to:ur},e.artifacts.actions[s]={do:[`${s}.open`,l]},e.artifacts.actions[`${s}.open`]={set:$O,to:o};let u={},d=Object.entries(r).map(([r,o])=>{let s=xN(e.presetIdent,i,r),l=`${ik}p${e.presetIdent}.d${t}.${r}`;e.artifacts.variables[l]={kind:`state`,key:s,default:b_(n.settings?.[r]??o.default)},u[r]={id:i,key:s,variable:l};let d=`${a}.setting.${t}.${r}`,f=SD(bD(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 hr(d,f.list.ref,{kind:`container`,direction:`vertical`,children:p},`drop`)});return{term:`{{ action "${s}" "${xk}" }}`,ref:{variable:$O,key:$O,member:o},body:{kind:`container`,direction:`vertical`,children:d},drafts:u}}const CN=`${rD}label:`;function wN(e){if(e.startsWith(CN)){let t=e.slice(CN.length);return t.slice(t.indexOf(`:`)+1)}return e.startsWith(`edit.`)?void 0:e}function TN(e,t,n,r){let{artifacts:i}=n,a=Xg(e),o=`${CN}${a}:${e.name}`;i.segments[o]={template:`{{ "${mr(a)}" }}`,...t.palette!==void 0&&{palette:t.palette}};let s=Object.fromEntries(h_.flatMap(t=>{let n=e.settings?.[t];return n===void 0?[]:[[t,n]]}));return{...hr(o,r.ref,r.body,`drop`,yN([r.ref],`{{ ${cN(n.presetIdent)} }}`)),...Object.keys(s).length>0&&{settings:s},drafts:Object.fromEntries(h_.map(e=>[e,r.drafts[e]]))}}function EN(e,t,n,r){let{presetIdent:i,artifacts:a}=e,o=`${rD}${i}.insert.${t}`,s=`${rD}${i}.insertSeg.${t}`;a.actions[o]={persist:e.rootKey,insertSegmentFrom:mN,anchor:n,relation:r};let c=cD(o),l=lD(s,o,void 0),u=fD(l),d=dD(l,c);return a.variables[l]=xr(l,ur),a.variables[u]={kind:`state`,key:u,default:`0`},a.actions[d]=Sr(l,c),a.actions[u]={set:u,int:!0},{host:s,template:`{{ $m := menu "${o}" "✚" "✕" }}{{ if ${_r({variable:l,key:l,member:c})} }}{{ $m }}{{ else }}{{ fg (${`readableOn (color "success") (bgOf) ${xm}`}) $m }}{{ end }}`}}function DN(e,t){let n=[],r=e.children.findIndex(e=>e.kind===`segment`&&!fN(e.name)),i=e=>DN(e,t);for(let[a,o]of e.children.entries()){if(o.kind===`container`){n.push(i(o));continue}let s=$g(o,i);if(fN(o.name)){n.push(s);continue}let c=Xg(o),l=a===r?[EN(t,String(t.posCounter.n++),c,`before`)]:[],u=String(t.posCounter.n++),d=EN(t,u,c,`after`),f=_N(t,u,c),p=t.segments[o.name],m=SN(t,u,o,g_(p)),h=vN(f),g=vN(m.term),_={kind:`container`,direction:`horizontal`,children:[...l.map(e=>gN(e.host,e.template,t.artifacts)),{...TN(o,p,t,m),lead:h,trail:g},{...s,when:uN(t.presetIdent,`false`,o.when??`true`),lead:h,trail:g,drafts:m.drafts},gN(d.host,d.template,t.artifacts)]};n.push(e.direction===`vertical`?{kind:`container`,direction:`horizontal`,children:[_]}:_)}return{...e,children:n,...e.when!==void 0&&{when:yN(bN(n),uN(t.presetIdent,`true`,e.when))}}}function ON(e,t,n,r,i,a,o){let s=`${rD}${t}.resetLayout`,c=`${rD}${t}.customized`;return r.actions[s]={reset:n},r.segments[c]={template:`{{ action "${s}" "↺ reset layout" }}`,when:dN},{kind:`container`,direction:`vertical`,children:[{kind:`container`,direction:`horizontal`,children:[...i,{kind:`segment`,name:c},a]},kN(e,o)]}}function kN(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),kN(n,t)]}:{...e,children:[...e.children,t]}}function AN(e,t,n,r,i,a){let{node:o}=H_(e,t),s={presetIdent:YE(t),rootKey:HO(t),segments:e.segments,artifacts:n,posCounter:{n:0},configured:[]},c=DN(o,s);return n.variables[sN(s.presetIdent)]=lN(s.configured),ON(c,s.presetIdent,s.rootKey,n,r,i,a)}function jN(e){let t={variables:{},actions:{},segments:{}},n=pk(`${rD}help`,Ck,[ok],t);t.variables[QM]=xr(QM,ur),t.actions[QM]=Sr(QM,oN.member),t.segments[QM]={template:vr(QM,...$M),when:sk};let r={kind:`segment`,name:QM},i=n;t.variables[rN]={kind:`input`,path:`history.sinceEdit`,type:`number`,default:0},t.actions[eN]={do:[Mj,...nk]},t.segments[eN]={template:`{{ if ${aN} }}{{ action "${eN}" "✓ save" }}{{ else }}{{ action "${eN}" "✓ done" }}{{ end }}`,when:sk},t.actions[nN]={rewind:!0},t.actions[tN]={do:[nN,...nk]},t.segments[tN]={template:`{{ action "${tN}" "↩ cancel" }}`,when:`{{ and ${_r(ok)} ${iN} }}`};let a=[{kind:`segment`,name:eN},{kind:`segment`,name:tN}],o={...e.presets},s=[];for(let n of z_(e.presets)){let c=AN(e,n,t,a,r,i);s.push(c),o[n]={...V_(e.presets,n),root:c}}let c=JE(t,s,e);return{...e,variables:{...c,...e.variables,...t.variables},actions:{...e.actions,...t.actions},segments:{...e.segments,...t.segments},presets:o}}function MN(e){return e.op===`remove`?`remove:${e.target}`:`insert:${e.segment}:${e.anchor}:${e.relation}`}function NN(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 PN(e,t,n){let r=Qg(e,new Set(n.map(Zg).filter(e=>e.includes(t)).flat()));return r===e?{seg:e}:{seg:e,id:r}}const FN=/^-?\d+$/;function IN(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 LN(e){return t=>{if(!t)return{ok:!1,reason:`${e} value is required`};if(!FN.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 RN(e,t,n){return r=>r?FN.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 zN(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=>!FN.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 BN(e){return e===`config`?`set-config`:`set-state`}function VN(e,t,n){return t.kind===`int`?LN(`menu page "${e}"`):t.kind===`range`?RN(t.min,t.max,`${n} stepper "${e}"`):IN(t.allowed,`${n} "${e}"`,BN(n))}function HN(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:zN(e,n,t)}))}function UN(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 HN(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,VN(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 WN(e,t,n){let r=[],i=0,a=new WeakMap;return{register(n,a){let o={key:n,allowed:a};UN(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=UN(e,r,n(o),t);return a.set(o,{epoch:i,gate:c}),c}}}const GN=WN({},`config`,QN);function KN(e,t){return GN.register(e,t)}function qN(e){return GN.gateFor(e)}function JN(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:Y_(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:[MN({op:`remove`,target:e.removeSegment})]}}]:`insertSegment`in e?[{key:e.persist,spec:{kind:`allow-list`,allowed:[MN({op:`insert`,segment:e.insertSegment,anchor:e.anchor,relation:e.relation})]}}]:`insertSegmentFrom`in e?[{key:e.persist,spec:{kind:`allow-list`,allowed:Y_(e.insertSegmentFrom,t).members.map(t=>MN({op:`insert`,segment:t,anchor:e.anchor,relation:e.relation}))}}]:[{key:e.persist,spec:{kind:`range`,min:e.min,max:e.max}}]:[]}function YN(e,t){let n=LO(e).get(t);return n===void 0?null:String(n)}function XN(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?KO(n.persist):null;e?.scope===`preset-root`&&t.add(HO(e.preset))}return[...t].map(e=>({key:e,spec:{kind:`allow-list`,allowed:[]}}))}function ZN(e){let t=pN(e);return[...XN(e),...Object.values(e.actions).flatMap(e=>JN(e,t))]}function QN(e){return HN(ZN(e),`config`)}function $N(e,t){return{globals:{...t.globals,...e.globals??{}},variables:{...t.variables,...e.variables??{}},segments:nP(t.segments,eP(t.segments,e.segments??{})),root:F_(e.root??O_,t.root),actions:{...t.actions,...e.actions??{}},styles:{...t.styles,...e.styles??{}},presets:nP(t.presets,tP(t.presets,e.presets??{})),themeDefaults:nP(t.themeDefaults,e.themeDefaults??{}),editGlobals:{...t.editGlobals,...e.editGlobals??{}},helpers:{...t.helpers,...e.helpers??{}}}}function eP(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 tP(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 nP(e,t){return{...e,...Object.fromEntries(Object.entries(t).map(([t,n])=>[t,{...e[t],...n}]))}}function rP(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: ${s_.join(`, `)})`,line:Y(e.source,t.split(`.`))}),null):oP(e,`${t}.cache`,n.cache)}function iP(e){return{required:!0,json:sP(),parse:(t,n,r,i)=>rP(t,n,i,e)??void 0}}const aP={noun:`cache`,arms:{ttl:{json:{type:`string`},parse:(e,t,n)=>typeof n==`string`&&lP(n)?{ttl:n}:ID(e,t,`cache.ttl must be a duration string like "5s", "100ms", "2m", "1h"; got ${Z(n)}`)},watch_file:{json:{type:`string`,pattern:`^/`},parse:(e,t,n)=>{if(typeof n!=`string`)return ID(e,t,`cache.watch_file must be a path string, got ${Z(n)}`);let r=JD(`cache.watch_file`,n);return r===null?{watch_file:n}:ID(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}:ID(e,t,`cache.depends_on must be an array of variable-name strings, got ${Z(n)}`)},key:{json:{type:`string`},parse:(e,t,n)=>typeof n==`string`&&n!==``?{key:n}:ID(e,t,`cache.key must be a non-empty template string, got ${Z(n)}`)},never:{json:{const:!0},parse:(e,t,n)=>n===!0?{never:!0}:ID(e,t,`cache.never must be the literal boolean true, got ${Z(n)}`)}}};function oP(e,t,n){return LD(e,aP,t,n)}function sP(){return tO(aP)}const cP=/^(\d+(?:\.\d+)?)(ms|s|m|h)$/;function lP(e){return cP.test(e)}function uP(e,t,n){if(n===void 0)return{};if(!kD(n))return e.issues.push({path:t,message:`${t} must be an object, got ${AD(n)}`,line:Y(e.source,t.split(`.`))}),{};let r={};for(let[i,a]of Object.entries(n)){let n=RD(e,IP,`${t}.${i}`,a);n!==null&&(r[i]=n)}return r}function dP(){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 ${AD(i)}`,line:Y(e.source,t.split(`.`))});return}return i}}}function fP(){return{required:!0,json:{enum:[...l_]},parse:(e,t,n,r)=>{let i=r.field;if(typeof i!=`string`||!l_.includes(i)){e.issues.push({path:`${t}.field`,message:`git field must be one of: ${l_.join(`, `)}, got ${JSON.stringify(i)}`,line:Y(e.source,[...t.split(`.`),`field`])});return}return i}}}function pP(){return{required:!1,json:{type:[`string`,`number`,`boolean`]},parse:(e,t,n,r)=>{let i=r.type;return TD(e,t,r,i===`number`||i===`boolean`||i===`string`?i:`string`)}}}const mP={noun:`parse`,arms:{text:{json:{const:!0},parse:(e,t,n)=>n===!0?{text:!0}:ID(e,t,`parse.text must be the literal boolean true, got ${Z(n)}`)},regex:{json:{type:`string`},parse:(e,t,n)=>typeof n==`string`?hP(e,t,n):ID(e,t,`parse.regex must be a pattern string, got ${Z(n)}`)},json:{json:{const:!0},parse:(e,t,n)=>n===!0?{json:!0}:ID(e,t,`parse.json must be the literal boolean true, got ${Z(n)}`)}}};function hP(e,t,n){let r;try{new RegExp(n),r=RegExp(`${n}|`).exec(``).length-1}catch(n){return ID(e,t,`parse.regex is not a valid regular expression: ${n.message}`)}return r>=1?{regex:n}:ID(e,t,`parse.regex must contain a capture group — its group 1 is the value; got ${JSON.stringify(n)}`)}function gP(){return{required:!1,json:tO(mP),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:Y(e.source,[...t.split(`.`),`regex`])}),r.parse===void 0?void 0:LD(e,mP,`${t}.parse`,r.parse)??void 0)}}function _P(){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)=>kD(r.parse)&&`json`in r.parse?vP(e,t,r.default):ED(e,t,r,`default`)}}function vP(e,t,n){if(n!==void 0)return yP(n)?n:ID(e,`${t}.default`,`${t}.default must be a JSON value (a json-parsed source's document), got ${Z(n)}`)??void 0}function yP(e){return e!==null&&bP(e)}function bP(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(bP);let t=Object.getPrototypeOf(e);return(t===Object.prototype||t===null)&&Object.values(e).every(bP)}default:return!1}}const xP={value:dP(),default:HD()},SP={path:qD(),type:XD([`string`,`number`,`boolean`]),default:pP()},CP={name:qD(),default:HD()},wP={path:YD(),readMode:XD([`whole`,`first-line`]),parse:gP(),cache:iP(`file`),default:_P()},TP={command:qD(),parse:gP(),cache:iP(`shell`),default:_P()};function EP(e){return{cache:`${e}, so it takes no cache policy — delete the key`}}const DP={template:qD(),default:HD()},OP=EP(`a template variable recomputes whenever a variable it reads changes`),kP={layout:qD(),default:HD()},AP=EP(`a time variable reads the instant its render is drawn at`),jP={field:fP(),default:HD()},MP=EP(`a git variable is refreshed by the daemon's own watch on the repository`),NP={key:qD(),default:HD()},PP=`kind`;function FP(e,t,n={}){return{...zD(PP,e,t),parse:(r,i,a)=>{MD(r,n,i,a);let o=ND(r,t,i,a);return o===null?null:{kind:e,...o}}}}const IP={tag:PP,noun:`source kind`,memberNoun:`variable`,arms:{literal:FP(`literal`,xP),input:FP(`input`,SP),env:FP(`env`,CP),file:FP(`file`,wP),shell:FP(`shell`,TP),template:FP(`template`,DP,OP),time:FP(`time`,kP,AP),git:FP(`git`,jP,MP),state:FP(`state`,NP)}};function LP(){return eO(IP)}function RP(){return{type:`object`,additionalProperties:LP()}}const zP=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`}]]);function BP(e){let t=zP.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)`}}const VP=/^[A-Za-z_][A-Za-z0-9_]*$/,HP={pattern:VP.source},UP={anyOf:[{type:`boolean`},{type:`string`},{type:`integer`}]},WP={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`,...HP}}}]},default:UP}},GP=[`label`,`domain`,`default`],KP=[`min`,`max`,`step`,`atLeast`];function qP(e,t,n){e.issues.push({path:t,message:n,line:Y(e.source,t.split(`.`))})}function JP(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 qP(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 qP(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?qP(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(kD(n)){let{min:r,max:i,step:a=1,atLeast:o}=n;return Object.keys(n).filter(e=>!KP.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}}:qP(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 qP(e,t,`domain must be "bool", a list of words, or { min, max }, got ${Z(n)}`)}function YP(e,t,n){if(!kD(n))return qP(e,t,`${t} must be { label, domain, default }, got ${AD(n)}`);for(let r of Object.keys(n))GP.includes(r)||qP(e,`${t}.${r}`,`Unknown setting key "${r}". Expected one of: ${GP.join(`, `)}`);let{label:r}=n,i=typeof r==`string`&&r.length>0&&!/[\n\r]/.test(r);i||qP(e,`${t}.label`,`a setting needs a one-line, non-empty "label" — the name its control shows, spliced into a synthesized template string — got ${Z(r)}`);let a=JP(e,`${t}.domain`,n.domain);if(!i||a===void 0)return;let o={label:r,domain:a,default:n.default};return!XP(n.default)||!y_(o,n.default)?qP(e,`${t}.default`,`default must be ${C_(o)}, got ${Z(n.default)}`):o}function XP(e){return typeof e==`boolean`||typeof e==`string`||typeof e==`number`}const ZP={theme:`its default for this segment is segments.<name>.palette, and a placement sets its own with settings: { ${p_}: "<theme>" }`,effect:`a placement follows the bar's effect, or sets its own with settings: { effect: "<effect>" }`};function QP(e){return h_.includes(e)}function $P(){return{required:!1,json:{type:`object`,propertyNames:{...HP,not:{enum:[...h_]}},additionalProperties:WP},parse:(e,t,n,r)=>{let i=r[n];if(i===void 0)return;let a=`${t}.${n}`;if(!kD(i))return qP(e,a,`${a} must be an object of name → { label, domain, default }, got ${AD(i)}`);let o=Object.create(null);for(let[t,n]of Object.entries(i)){if(!VP.test(t)){qP(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(QP(t)){qP(e,`${a}.${t}`,`setting "${t}" is one every placement already has — ${ZP[t]}`);continue}let r=YP(e,`${a}.${t}`,n);r!==void 0&&(o[t]=r)}return o}}}const eF=iD.map(e=>e.replace(/\./g,`\\.`)).join(`|`);function tF(){return{required:!1,json:{type:`string`,minLength:1,pattern:`^(?!${eF})[^:/]+$`},parse:(e,t,n,r)=>{let i=r[n];if(i!==void 0)return typeof i==`string`&&i.length>0&&!/[:/]/.test(i)&&!aD(i)?i:qP(e,`${t}.${n}`,`a placement "id" must be a non-empty string without "/" or ":", outside the reserved ${iD.map(e=>`"${e}"`).join(`, `)} namespaces, got ${Z(i)}`)}}}function nF(){return{required:!1,json:{type:`object`,propertyNames:HP,additionalProperties:UP},parse:(e,t,n,r)=>{let i=r[n];if(i===void 0)return;let a=`${t}.${n}`;if(!kD(i))return qP(e,a,`a placement's "settings" must be an object of setting name → value, got ${AD(i)}`);let o=Object.create(null);for(let[t,n]of Object.entries(i))XP(n)?o[t]=n:qP(e,`${a}.${t}`,`setting "${t}" must be a boolean, a word, or a number, got ${AD(n)}`);return o}}}function rF(e){return new Set(Object.keys(e.segments).filter(e=>!aD(e)))}function iF(e,t,n){if(t===void 0)return{};if(!kD(t))return e.issues.push({path:`segments`,message:`segments must be an object, got ${AD(t)}`,line:Y(e.source,[`segments`])}),{};let r={};for(let[i,a]of Object.entries(t)){let t=jD(e,n.has(i)?uF:lF,`segments.${i}`,a);t!==null&&(r[i]=t)}return r}function aF(){return{required:!0,json:{type:`string`},parse:(e,t,n,r)=>r[n]===void 0?ID(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${BP(t.slice(9))}`)??void 0:wD(e,t,r,n)??void 0}}function oF(){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 ${Z(i)}`,line:Y(e.source,[...t.split(`.`),n])})}}}}function sF(){return{required:!1,json:RP(),parse:(e,t,n,r)=>{let i=r[n];if(i!==void 0)return uP(e,`${t}.${n}`,i)}}}const cF={template:aF(),description:HD(),group:XD(JO),width:oF(),justify:XD(w_),truncate:XD(T_),bg:HD(),fg:HD(),when:HD(),palette:KD(),vars:sF(),settings:$P(),missingData:XD(u_)},lF={noun:`segment key`,fields:cF},uF={noun:`segment key`,fields:{...cF,template:HD()}},dF=`#/definitions/LayoutNode`,fF={kind:`container`,direction:`vertical`,children:[]};function pF(e){return{required:!0,json:{const:e},parse:()=>e}}function mF(){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 ${Z(i)}`,line:Y(e.source,[`root`])}),``)}}}function hF(){return{required:!0,json:{enum:[...Jg]},parse:(e,t,n,r)=>{let i=r[n];return typeof i==`string`&&Jg.includes(i)?i:(e.issues.push({path:`${t}.${n}`,message:`a container "direction" must be one of: ${Jg.join(`, `)} (got ${JSON.stringify(i)})`,line:Y(e.source,[`root`])}),`vertical`)}}}function gF(e){return{required:!0,json:{type:`array`,items:{$ref:dF}},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 ${AD(a)}`,line:Y(t.source,[`root`])}),[])}}}const _F={noun:`layout-node key`,fields:{kind:pF(`segment`),name:mF(),when:HD(),id:tF(),settings:nF()}},vF=()=>XD(Zp),yF={noun:`layout-node key`,fields:{kind:pF(`container`),direction:hF(),children:gF(BD(()=>wF)),when:HD(),distribution:vF()}};function bF(){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 ${Z(i)}`,line:Y(e.source,[`root`])}),``)}}}const xF={noun:`layout-node key`,fields:{seg:bF(),when:HD(),id:tF(),settings:nF()}},SF={noun:`layout-node key`,fields:{h:gF(BD(()=>wF)),when:HD(),distribution:vF()}},CF={noun:`layout-node key`,fields:{v:gF(BD(()=>wF)),when:HD(),distribution:vF()}},wF=(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:Y(e.source,[`root`])}),fF):{kind:`segment`,name:n};if(!kD(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 ${AD(n)}`,line:Y(e.source,[`root`])}),fF;if(n.kind===`container`)return jD(e,yF,t,n)??fF;if(n.kind===`segment`)return jD(e,_F,t,n)??fF;if(n.kind===`cells`)return e.issues.push({path:t,message:`kind: "cells" is no longer supported — use the h-arm spelling instead:
|
|
170
|
+
`,wk=`readableOn (mix (color "foreground") (bgOf) 60) (bgOf) 3`,Tk={socket:`TMUX`,pane:`TMUX_PANE`,truecolor:`CLAUDE_CODE_TMUX_TRUECOLOR`};function Ek(e){let t=e[Tk.socket]??``,n=e[Tk.pane]??``;if(t===``||n===``)return null;let r=e[Tk.truecolor]??``;return{socket:t.split(`,`)[0],pane:n,truecolor:r===``?null:r}}const Dk=[`moves`,`can-move`,`still`];function Ok(e){let t=e.context_window?.current_usage;return t===null?`no`:t===void 0?`unknown`:`yes`}const kk=[`carried`,`missing`,`unanswered`];function Ak(e){let t=e.rate_limits;return t?.five_hour!=null||t?.seven_day!=null?`carried`:Ok(e)===`no`?`unanswered`:`missing`}function jk(e){return{path:e.transcript_path,answered:Ok(e)===`yes`}}const Mk=[...Dk,`failed`,`drawing`],Nk=[`statusline`,`frames`],Pk=e=>e?.kind===`frames`?`frames`:`statusline`;var Fk=class{seen=new Map;see(e,t,n,r){let i=Pk(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(({said:t,at:n})=>({...t,ago:e-n}))}ofSession(e){return[...this.seen.values()].filter(t=>t.sessionId===e).map(e=>e.said)}};const Ik={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`}}},Lk=e=>Ik[e];function Rk(e){return Lk(e).glyphs.kind===`bundled`}function zk(e){return Lk(e).glyphs.kind===`configured`}const Bk=e=>Lk(e).label,Vk=[{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 Hk(e,t){let n=t.codePointAt(0);return Vk.some(({since:t,from:r,to:i})=>r<=n&&n<=i&&e!==null&&Gk(e,t)===!0)}const Uk=Object.keys(Ik);function Wk(e){let t=/^\d+(?:\.\d+)*/.exec(e);return t===null?null:t[0].split(`.`).map(Number)}function Gk(e,t){let n=Wk(e),r=Wk(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 Kk(e){for(let t of Uk){let n=Lk(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 qk(e){let t=Uk.find(t=>Lk(t).term===e);return t===void 0?null:{name:t,version:null}}function Jk(e){let t=Kk(e.termtype)??qk(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 Yk(e){let t=e.TERM_PROGRAM,n=Uk.find(e=>Lk(e).program===t),r=n===void 0?qk(e.TERM):{name:n,version:Lk(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 Xk(e){switch(e.kind){case`known`:return Bk(e.terminal.name);case`unknown`:return e.called;case`unnamed`:return e.term||null}}function Zk(e){switch(e.kind){case`known`:return Bk(e.terminal.name);case`unknown`:return e.called;case`unnamed`:return e.term||`this terminal`}}function Qk({name:e,version:t}){let n=Lk(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=Gk(t,n.since);return r===null?{kind:`unsaid`,since:n.since}:r?{kind:`draws`}:{kind:`older`,since:n.since,version:t}}const $k=Uk.filter(e=>Lk(e).links!==null).map(Bk).join(`, `),eA=[`drawn`,`boxes`],tA=1024*1024;function nA(e){switch(e.kind){case`claude-settings`:return`${e.kind} ${e.path.join(`.`)}=${JSON.stringify(e.value)}`;case`post-mortems-read`:return`${e.kind} through=${e.through}`}}function rA(e){let[t,...n]=e;return t===void 0?{ok:!0}:{ok:!1,reason:t,more:n}}const iA=Tk.truecolor;function aA(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 oA={name:`tmuxTruecolor`,label:`tmux truecolor`,takesMark:!1,probe:({tmux:e,claudeSettings:t})=>aA(e,(e,n)=>{if(!e.features.includes(`RGB`)||n.truecolor!==null)return{ok:!0};let r=t.env[iA];return typeof r==`string`&&r!==``?{ok:!1,reason:`${iA} is set in ${t.path} — restart Claude Code to apply`}:{ok:!1,reason:`Claude Code renders the bar in 256 colours inside tmux`,fix:{kind:`claude-settings`,path:[`env`,iA],value:`1`}}})},sA={name:`utf8`,label:`UTF-8`,takesMark:!1,probe:({tmux:e})=>aA(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"})},cA={name:`termWidth`,label:`terminal width`,takesMark:!1,probe:({termCols:e})=>e===null?{ok:!1,reason:`no terminal width was measured (no COLUMNS, and no terminal to ask — or the daemon refused the width sent, which the bar's red strip names), so the bar is laid out as if the terminal were 120 columns wide`}:{ok:!0}},lA={variable:`is never read`,action:`is never clicked`,helper:`is never called`,segment:`is in no preset`},uA={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(`
|
|
171
|
+
`).map(e=>e.trim()).filter(e=>e!==``),...e.warnings];return{ok:!1,reason:t,more:n}}case`loaded`:return rA([...e.warnings,...e.unused.map(({kind:e,name:t})=>`${e} "${t}" ${lA[e]}`)])}}},dA="re-run `cc-candybar install`";function fA(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:// — ${dA}`];let{app:t,missing:n}=e.value;return n.kind===`failed`?[`${t} opens cc-candybar://, but ${n.reason} — ${dA}`]:n.value.map(e=>`${e} is missing, and ${t} runs it — ${dA}`)}const pA={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}) — ${dA}`:`the URL handler runs cc-candybar ${e.handler}; the bar runs ${e.bar} — ${dA}`};case`lost`:return rA([...fA(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 mA({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 hA(e,t){return t===`frames`?`run \`node ${e.bundle} frames --lane <band|statusline|pane>\``:e.checkout===null?dA:`run \`just install-rust\` and point the statusLine command at ${e.checkout.root}/bin/cc-candybar-native`}function gA(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 — ${hA(e,`native`)}`];let{bundle:i,source:a}=mA(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} — ${hA(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 — ${hA(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 _A=`this daemon holds no render of this bar (it restarted since the bar was drawn, or has served 64 newer sessions)`,vA={name:`install`,label:`install`,takesMark:!1,probe:({install:e,askedBy: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===`click`?`${_A}, so which client draws it is unknown — run the doctor again once the bar has redrawn`:`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`}:rA([...new Set(i.flatMap(e=>gA(n,r,e)))])}};function yA({postMortems:e},t){return e.kind===`ok`&&t.kind===`ok`?e.value.filter(e=>t.value===null||rn(e.identity,t.value)):[]}function bA(e,t){return e.kind===`failed`?t:t.filter(t=>t.pid!==e.value.pid)}const xA={name:`daemon`,label:`daemon`,takesMark:!1,probe:({daemon:{serving:e,processes:t,read:n}})=>{let r=[...n.kind===`failed`?[`which post-mortems were read could not be read: ${n.reason}`]:[],...t.kind===`failed`?[`the process table could not be read: ${t.reason}`]:[]],i=t.kind===`ok`?bA(e,t.value):[];if(e.kind===`failed`){let t=i.length>0?` — daemon ${i.map(e=>e.pid).join(`, `)} running`:``;return rA([`${e.reason}${t}`,...r])}let{pid:a,rss:o,rssLimit:s,postMortems:c}=e.value,l=yA(e.value,n),u=rA([...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}`]:[],...r,...i.map(e=>`daemon ${e.pid} (started ${e.started}, ${en(e.rss)} MB${e.ppid===1?``:`, child of ${e.ppid}`}) runs beside the one serving the bar (${a}) — \`kill ${e.pid}\``),...an(o,s)?[`the daemon holds ${en(o)} MB of its ${en(s)} MB limit — at the limit it records a post-mortem and restarts`]:[]]),d=l[0];return u.ok||d===void 0?u:{...u,fix:{kind:`post-mortems-read`,through:d.identity}}}},SA=`click 🩺 doctor in the bar's settings menu: if it runs, links work`;function CA(e,t){let n=Xk(e);return t.kind===`ok`&&n!==null&&t.value.includes(n)?{kind:`draws`}:e.kind===`known`?Qk(e.terminal):{kind:`unknown`}}function wA({identified:e,tmuxClient:t},n){let r=Zk(e),i=CA(e,n),a=Xk(e)===null?SA:`${SA}, 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: ${$k}`];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 TA={name:`links`,label:`links`,takesMark:!1,probe:({askedBy:e,terminal:t,clicked:n})=>{if(e===`click`)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 rA(wA(t,n))}}},EA=e=>e.filter(e=>e.role===`statusline`).map(e=>e.frame),DA={name:`effectRefresh`,label:`effect refresh`,takesMark:!1,probe:({frames:e,claudeSettings:t,askedBy:n})=>{let{path:r,statusLine:i}=t,a=i.kind===`present`?i.refreshInterval:void 0;if(a===1)return{ok:!0};if(e.kind===`failed`)return{ok:!1,reason:e.reason};let o=EA(e.value),s=o.includes(`moves`)?`the bar moves (an effect, a fade, or an animated segment)`:o.includes(`can-move`)?`the bar can start moving (a globals.effect rule, placements that fade in and out, or a placement with an effect of its own that is not drawn now)`:null;if(s===null)return o.includes(`still`)?{ok:!0}:{ok:!1,reason:`${o.length>0?o.includes(`drawing`)?`the bar's latest render has not finished`:`the bar's recent renders failed`:e.value.length>0?"only a `cc-candybar frames` display has drawn this bar, not Claude Code's statusline":n===`click`?_A:`no session of this Claude Code has drawn a statusline for this daemon in the last ${300/60} minutes`}, so whether it moves is unknown — run the doctor again once the bar has redrawn`};switch(i.kind){case`absent`:return{ok:!1,reason:`${s}, and ${r} sets no statusLine — set "refreshInterval": 1 beside the statusLine command that runs the bar`};case`not-an-object`:return{ok:!1,reason:`${s}, and ${r} sets statusLine to ${JSON.stringify(i.value)}, not a statusLine object — re-run \`cc-candybar install\` to write one`};case`present`:return{ok:!1,reason:a===void 0?`${s}, but Claude Code redraws it only on events`:typeof a==`number`&&a>1?`${s}, but Claude Code redraws it only every ${a} s`:`${s}, but statusLine.refreshInterval is ${JSON.stringify(a)}, not a number of seconds Claude Code accepts (its minimum is 1)`,fix:{kind:`claude-settings`,path:[`statusLine`,`refreshInterval`],value:1}}}}},OA=e=>[...e].map(e=>`U+${e.codePointAt(0).toString(16).toUpperCase()}`).join(` `);function kA(e){switch(e.kind){case`unreported`:case`unasked`:return`this terminal`;case`unknown`:case`unnamed`:return Zk(e);case`bundling`:case`unread`:case`configured`:return[Bk(e.name),e.version].filter(e=>e!==null).join(` `)}}function AA(e){switch(e.kind){case`unreported`:case`unasked`:return null;case`unknown`:case`unnamed`:return Xk(e);case`bundling`:case`unread`:return Bk(e.name);case`configured`:{let t=Bk(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 jA(e){let t=AA(e.terminal);return t===null?void 0:{glyphs:e.glyphs,id:`${t}|${OA(e.glyphs)}`}}const MA={name:`nerdFont`,label:`Nerd Font`,takesMark:!0,probe:({nerdFont:e,marks:t})=>{if(e.kind===`none`)return{ok:!0};if(t.kind===`failed`)return{ok:!1,reason:`the mark book could not be read: ${t.reason}`};let n=jA(e),r=e=>({ok:!1,reason:e,...n!==void 0&&{sighting:n}}),i=e.terminal,a=kA(i);switch(n===void 0?null:t.value.nerdFont?.[n.id]??null){case`drawn`:return{ok:!0};case`boxes`:return r(`${a} draws ${OA(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=Ik[i.name].glyphs.since;if(e===null)return{ok:!0};let t=i.version===null?null:Gk(i.version,e);if(t===!0)return{ok:!0};let n=Bk(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 ${OA(n)} — set a Nerd Font as its font`)}}}};function NA(e){return e.join(`, `)}function PA(e){return`or set missingData: "ignore" on ${NA(e)}`}function FA(e){if(e.kind===`unneeded`)return[];let{segments:t,fact:n}=e;if(n.kind===`failed`)return[`${NA(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`?[`${NA(t)}: ${r} is not installed, so no pull request is ever shown — install it, ${PA(t)}`]:[`${NA(t)}: ${r} is not logged in to ${i} (${a.loggedOut}) — run \`${r} auth login --hostname ${i}\`, ${PA(t)}`]}function IA(e,t){if(e.kind===`unneeded`)return[];let{segments:n,fact:r}=e;return r.kind===`failed`?[`${NA(n)}: ${r.reason}`]:r.value.length===0?[t===`click`?`${NA(n)}: ${_A}, so whether Claude Code sends rate_limits is unseen — run the doctor again once the bar has redrawn`:`${NA(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`]:r.value.includes(`missing`)&&!r.value.includes(`carried`)?[`${NA(n)}: Claude Code sent no rate_limits — it sends them only to Claude.ai subscription sessions; on any other account, set missingData: "ignore" on ${NA(n)}`]:[]}function LA(e){if(e.kind===`unneeded`)return[];let{segments:t,fact:n}=e;switch(n.located.kind){case`ok`:return[];case`absent`:return[`${NA(t)}: memento is not installed (or is disabled) for ${n.claudeConfigDir} — install the memento plugin, ${PA(t)}`];case`failed`:return[`${NA(t)}: whether memento is installed could not be read: ${n.located.reason}`]}}const RA={name:`segmentData`,label:`segment data`,takesMark:!1,probe:({data:e,askedBy:t})=>rA([...FA(e.pullRequests),...IA(e.rateLimits,t),...LA(e.memento)])};function zA({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 ${tA/1024/1024} MiB of`} the transcript ${e} are not JSON objects — the bar skips them, so what it counts from them is missing`]}}}const BA=[uA,vA,xA,pA,TA,oA,sA,cA,DA,MA,RA,{name:`sessionData`,label:`session data`,takesMark:!1,probe:({transcripts:e,askedBy:t})=>e.kind===`failed`?{ok:!1,reason:e.reason}:e.value.length===0?{ok:!1,reason:t===`click`?`${_A}, so which transcript it reads is unknown — run the doctor again once the bar has redrawn`:`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`}:rA(e.value.flatMap(zA))}],VA=BA.filter(e=>e.takesMark);function HA(e){return BA.map(t=>({check:t,verdict:t.probe(e)}))}function UA(e){return BA.find(t=>t.name===e)}const WA=`${X}doctor.`;function GA(e){let t=`${WA}${e}.`;return{verdict:`${t}verdict`,reason:`${t}reason`,fixable:`${t}fixable`,sighting:`${t}sighting`}}function KA(e,t){let n=e.kind===`seen`?e.tmuxClient:null,r=e.kind===`seen`?Xk(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 qA(e,t){let n=e.kind===`seen`?e.tmuxClient:null;return`cols=${t??`-`} clientUtf8=${n===null?`-`:n.utf8?`yes`:`no`}`}function JA(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}=mA(t,e);return`${e.client}/${n.kind}/${r.kind===`uncompared`?`-`:r.kind}`}).join(`,`)||`-`}`}function YA({serving:e,processes:t,read:n}){let r=t.kind===`failed`?`daemons=unread others=-`:`daemons=${t.value.length} others=${bA(e,t.value).map(e=>e.pid).join(`,`)||`-`}`;if(e.kind===`failed`)return`${r} rss=unasked postMortems=unasked`;let{rss:i,rssLimit:a,postMortems:o}=e.value,s=o.kind===`failed`||n.kind===`failed`?`unread`:`${yA(e.value,n).length}/${o.value.length}`;return`${r} rss=${en(i)}/${en(a)} postMortems=${s}`}function XA(e){let t=()=>{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`},n=()=>{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`)}`},r=e.memento.kind===`unneeded`?`-`:e.memento.fact.located.kind===`ok`?`located`:e.memento.fact.located.kind;return`data=pr:${t()},rateLimits:${n()},memento:${r}`}function ZA(e){if(e.kind===`failed`)return`frames=failed`;let t=EA(e.value);return`frames=${Mk.map(e=>t.filter(t=>t===e).length).join(`/`)}`}function QA(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 $A(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=jA(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 ej(e,t=[]){return t.length===0?e:`${e} (+${t.length} more — run \`cc-candybar doctor\`)`}function tj(e){return e.flatMap(({check:e,verdict:t})=>{let n=GA(e.name);return t.ok?[{key:n.verdict,value:`ok`},{key:n.reason,value:``},{key:n.fixable,value:Mh},{key:n.sighting,value:``}]:[{key:n.verdict,value:`failed`},{key:n.reason,value:ej(t.reason,t.more)},{key:n.fixable,value:t.fix===void 0?Mh:jh},{key:n.sighting,value:t.sighting?.glyphs??``}]})}const nj={copySession:{copy:`{{ .session.id }}`},copyResume:{copy:`{{ .resume_command }}`},openProject:{open:`{{ .project_dir }}`},openTranscript:{open:`{{ .transcript_path }}`},openConfig:{open:`{{ .config_path }}`}};function rj(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(nj).map(([t,n])=>[`${e}${t}`,n]))}}const ij=`armed`,aj=`disarmed`,oj=`.armed`,sj=e=>e.endsWith(oj);function cj(e,t,n){let r=`${e}${oj}`,i=`${e}.arm`,a=`${e}.disarm`,o=`(eq .${e} "${ij}")`;return{template:`{{ if ${o} }}{{ action "${e}" "${t.confirm}" }} {{ action "${a}" "✕" }}{{ else }}{{ action "${i}" "${t.arm}" }}{{ end }}`,actions:{[i]:{set:r,to:ij},[a]:{set:r,to:aj},[e]:{do:[a,...n]}},armed:o,variables:{[e]:{kind:`state`,key:r,default:aj}},disarm:a}}const lj=RegExp(`^/[^\\s\\x00-\\x1f\\x7f-\\x9f/][^\\x00-\\x1f\\x7f-\\x9f]*$`);function uj(e){return typeof e==`string`&&lj.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 dj(e){let t=uj(e);if(t.kind===`refused`)throw Error(t.reason);return t.line}const fj=[`/compact`,`/model`],pj=`/clear`;function mj(e){let t=t=>`${e}${t.slice(1)}`,n=`${e}clear.slash`,r=cj(`${e}clear`,{arm:pj,confirm:`${pj} ✓ confirm`},[n]);return{template:fj.map(e=>`{{ action "${t(e)}" "${e}" }} `).join(``)+r.template,when:`{{ ${GE} }}`,actions:{...Object.fromEntries(fj.map(e=>[t(e),{slash:dj(e)}])),...r.actions,[n]:{slash:dj(pj)}},variables:r.variables,disarm:r.disarm}}const hj=Array.from({length:10},(e,t)=>(t+1)*1e5),gj=hj[0],_j=hj[hj.length-1];function vj(e){let t;try{t=Ei(e)}catch(e){return z(e instanceof Error?e.message:String(e))}let n=t.autoCompactWindow;return n===void 0?L(`auto`):typeof n==`number`&&Number.isInteger(n)&&n>=gj&&n<=_j?L(n):z(`${e}: autoCompactWindow is ${JSON.stringify(n)}, not a window /autocompact accepts (${gj}–${_j} tokens)`)}function yj(e,t){let n=Math.min(t??_j,_j),r=e===`auto`?n:Math.min(e,n);return{window:e===`auto`?0:e,applied:e===`auto`?0:r,lower:hj.filter(e=>e<r).at(-1)??0,higher:hj.find(e=>e>r&&e<=n)??0}}function bj(e,t){return{template:`{{ if ne .autocompact.error "" }}⇲ ⚠ {{ .autocompact.error }}{{ else }}⇲ {{ if eq .autocompact.window 0 }}auto{{ else }}${t(`.autocompact.applied`)}{{ end }}{{ if ${GE} }}{{ 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:dj(`/autocompact auto`)},...Object.fromEntries(hj.map(t=>[`${e}${t}`,{slash:dj(`/autocompact ${t}`)}]))}}}const xj=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 }}`,Sj=`${X}menu`,Cj=`open`,wj=`${X}edit`,Tj=`${X}toolbar`,Ej=rj(X),Dj=`${X}commands`,Oj=mj(`${Dj}.`),kj=`${X}autocompact`,Aj=bj(`${kj}.`,xj),jj=e=>({kind:`segment`,name:e}),Mj=`${X}tab`,Nj=[{member:`session`,label:`⚡ session`},{member:`look`,label:`🎨 look`},{member:`layout`,label:`📐 layout`},{member:`config`,label:`⚙ config`},{member:`tools`,label:`🧰 tools`}],Pj=e=>`${Mj}.${e}`,Fj=e=>`${Pj(e)}.toggle`,Ij=e=>({variable:Mj,key:Mj,member:e}),Lj=`${X}save`,Rj=`${X}preset.save`,zj=`${X}preset.delete`,Bj=e=>`${X}${e}`,Vj=e=>`${X}apply.${e}`,Hj=e=>`${X}reset.${e}`,Uj=`${X}themeDefault.save`,Wj=`${X}themeDefault.differs`,Gj=`${X}themeDefault.theme`,Kj={when:`{{ .${Wj} }}`,template:`{{ action "${Uj}" (printf "⤓ default for %s" .${Gj}) }} {{ swatch "${Vj(`theme`)}" .${Gj} }}`},qj=`${X}resetAll`,Jj=`${Sj}.toggle`,Yj={variable:Sj,key:Sj,member:Cj},Xj=`${X}undo`,Zj=`${X}back`,Qj=`${Zj}.step`,$j=`${X}navigation.back`,eM=Zj,tM={template:`{{ if gt .${$j} 0 }}{{ action "${Zj}" "◁" }}{{ else }}{{ fg (${wk}) "◁" }}{{ end }}`},nM=`${X}redo`,rM=`${X}doctor`,iM=`${rM}.run`,aM=e=>`${rM}.fix.${e}`,oM=(e,t)=>`${rM}.mark.${e}.${t}`,sM=e=>`${rM}.${e}`,cM={drawn:`[✓ shapes]`,boxes:`[✗ boxes]`},lM=lD(`${X}pickers`),uM=`${X}gear`,dM=`gear`,fM=`${uM}.toggle`,pM={variable:lM,key:lM,member:dM},mM=lD(`${X}gearPickers`),hM=[{template:`{{ themePreview }}`}],gM={template:`{{ layoutPreview }}`},_M={preset:[gM,{when:`{{ not .preset.bundled }}`,template:`{{ action "${zj}" (printf "🚮 delete %s" .${Ba.preset.effectiveVar}) }}`}],style:hM,variation:[gM],shade:[gM]},vM=(e,t)=>`${X}list.${e}.${t}`,yM=e=>`${X}resettable.${e}`,bM=e=>e.length===0?`false`:`(or ${e.map(e=>`.${yM(e)}`).join(` `)})`,xM={preset:`door`,theme:`look`,style:`gear`,effect:`look`,variation:`gear`,shade:`gear`,endcaps:`look`,transitions:`look`,autoWrap:`layout`,padding:`layout`,updateNotice:`config`,experimentalBand:`config`,experimentalStatusline:`config`,experimentalPane:`config`},SM=e=>e===`gear`?xM.theme:e,CM=Object.keys(Ba).map(e=>{let t=Ba[e],n=pO(t.configKey),r=xD({label:t.label,domain:n},t.sessionKey,t.effectiveVar,Vj(e),xM[e]===`gear`?mM:lM);return{...t,name:e,control:r,beneath:_M[e]??[]}}),wM=e=>CM.filter(t=>xM[t.name]===e),TM=e=>CM.filter(t=>SM(xM[t.name])===e),EM={theme:[hr(uM,pM,{kind:`container`,direction:`horizontal`,children:wM(`gear`).map(zM)},`drop`)]},DM=e=>wM(e).flatMap(e=>[zM(e),...EM[e.name]??[]]);new Set(CM.flatMap(e=>[e.sessionKey,e.configKey]));const OM=cj(qj,{arm:`⟲`,confirm:`⟲ reset all?`},CM.map(e=>Hj(e.name))),kM=[`unsaved`,`history.undo`,`history.redo`],AM=e=>`${X}${e}`,jM=AM(`unsaved`),MM=(e,t)=>({body:t,shown:`(gt .${AM(e)} 0)`}),NM=[MM(`unsaved`,`{{ action "${Lj}" (printf "💾 save %d" .${jM}) }}`),MM(`history.undo`,`{{ action "${Xj}" "↶" }}`),MM(`history.redo`,`{{ action "${nM}" "↷" }}`),{body:OM.template,shown:`(or ${bM(CM.map(e=>e.name))} ${OM.armed})`}],PM={when:`{{ or ${NM.map(e=>e.shown).join(` `)} }}`,template:`{{ $sep := "" }}`+NM.map(e=>`{{ if ${e.shown} }}{{ $sep }}${e.body}{{ $sep = " " }}{{ end }}`).join(``)},FM=[{step:OM,place:`door`},{step:Oj,place:`session`}],IM=e=>e.map(e=>e.step.disarm),LM=IM(FM),RM=IM(FM.filter(e=>e.place!==`door`));function zM(e){let t=Bj(e.name);return e.control.kind===`inline`?jj(t):hr(t,e.control.list.ref,{kind:`container`,direction:`vertical`,children:[...e.control.list.rows,...e.beneath].map((t,n)=>jj(vM(e.name,n)))},`drop`)}function BM(e){return e===Sj}function VM(e){let t=jj(Sj);if(e.kind===`container`&&e.direction===`vertical`){let[n,...r]=e.children;return e.when===void 0&&n!==void 0?{...e,children:[VM(n),...r]}:{kind:`container`,direction:`vertical`,children:[t,e]}}return e.kind===`container`&&e.when===void 0?{...e,children:[t,...e.children]}:{kind:`container`,direction:`horizontal`,children:[t,e]}}function HM(e){return UM(e)>0?e:VM(e)}function UM(e){let t=0;for(let n of $g(e))n.kind===`segment`&&BM(n.name)&&(t+=1);return t}function WM(e,t=!1){let n=t||e.when!==void 0;return e.kind===`segment`?n&&BM(e.name)||e.opens!==void 0&&WM(e.opens.body,!0):e.children.some(e=>WM(e,n))}const GM={session:{direction:`vertical`,content:[jj(Tj),{kind:`container`,direction:`horizontal`,children:[jj(Dj),jj(kj)]}],after:[]},look:{direction:`horizontal`,content:[],after:[jj(Uj)]},layout:{direction:`horizontal`,content:[jj(Rj),jj(wj)],after:[]},config:{direction:`horizontal`,content:[],after:[]},tools:{direction:`vertical`,content:[jj(rM),...BA.map(e=>jj(sM(e.name)))],after:[]}},KM=e=>({kind:`container`,direction:GM[e].direction,children:[...GM[e].content,...DM(e),...GM[e].after]});function qM(e){return e.kind===`segment`?BM(e.name)?hr(e.name,Yj,YM,`above`):e:ZM(e)}function JM(){return{kind:`container`,direction:`vertical`,children:[{kind:`container`,direction:`horizontal`,children:[jj(eM),...DM(`door`),jj(Lj)]},{kind:`container`,direction:`horizontal`,children:Nj.map(({member:e})=>hr(Pj(e),Ij(e),KM(e),`drop`))}]}}const YM=JM();function XM(e){let t=new Map;for(let e of $g(YM))e.kind===`segment`&&e.opens!==void 0&&t.set(e.opens.ref.key,e.opens.ref.variable);return[...t].map(([t,n])=>{let r=e.variables[n];if(r?.kind!==`state`||r.default===void 0)throw Error(`settings menu: the door folds "${t}", but "${n}" is not a state variable the menu declares with a default`);let i=`${Sj}.fold.${JE(t)}`;return e.actions[i]={set:t,to:r.default},i})}function ZM(e){return{...e,children:e.children.map(e=>qM(e))}}function QM(e){let t={variables:{[Sj]:xr(Sj,ur)},actions:{[Jj]:Sr(Sj,Cj),[iM]:{doctor:`run`},[wj]:{do:[...tk]},...Ej.actions,...Oj.actions,...Aj.actions,[Lj]:{save:!0},[Xj]:{undo:!0},[Qj]:{back:!0},[Zj]:{do:[Qj,...LM]},[nM]:{redo:!0},[Rj]:{preset:`save`},[Uj]:{themeDefault:`save`},[zj]:{preset:`delete`,name:`{{ .${Ba.preset.effectiveVar} }}`}},segments:{[Sj]:{template:`{{ $door := ${yr(Sj,br(e),br(`✖`))} }}{{ if ${_r(Yj)} }}{{ fg (keptOn (color "error") (bgOf)) $door }}{{ else }}{{ $door }}{{ end }}`},[Tj]:{template:Ej.template},[Dj]:{template:Oj.template,when:Oj.when},[kj]:{template:Aj.template,bg:Aj.bg,when:Aj.when},[eM]:tM,[Lj]:PM,[Uj]:Kj,[Rj]:{template:`{{ action "${Rj}" "+ preset" }}`},[rM]:{template:`{{ action "${iM}" "🩺 doctor" }}`},[wj]:{template:`{{ action "${wj}" "✎ arrange" "✎ done" }}`}}};t.variables[Wj]={kind:`input`,path:`themeDefault.differs`,type:`boolean`,default:!1},t.variables[Gj]={kind:`input`,path:`themeDefault.theme`,type:`string`,default:``},t.variables[$j]={kind:`input`,path:`navigation.back`,type:`number`,default:0};for(let e of kM)t.variables[AM(e)]={kind:`input`,path:e,type:`number`,default:0};t.variables[Mj]=xr(Mj,`session`);for(let{member:e,label:n}of Nj){t.actions[Fj(e)]=Sr(Mj,e),t.actions[Pj(e)]={do:[Fj(e),...RM]};let r=bM(TM(e).map(e=>e.name)),i=`(ternary ${br(` •`)} "" ${r})`,a=e=>`(print ${br(e)} ${i})`;t.segments[Pj(e)]={template:`{{ ${yr(Pj(e),a(n),a(`▾ ${n}`))} }}`}}return Object.assign(t.variables,Oj.variables,OM.variables),eN(t),$M(t),t.actions[Sj]={do:[Jj,...LM,...XM(t)]},t}function $M(e){for(let t of BA){let n=GA(t.name),r=aM(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?eA:[];for(let n of i)e.actions[oM(t.name,n)]={doctor:`mark`,check:t.name,mark:n};let a=i.map(e=>` {{ action "${oM(t.name,e)}" "${cM[e]}" }}`).join(``);e.segments[sM(t.name)]={when:`{{ ne .${n.verdict} "" }}`,template:`{{ if eq .${n.verdict} "ok" }}✓ ${t.label}{{ else }}✗ ${t.label} — {{ .${n.reason} }}{{ if eq .${n.fixable} "${jh}" }} {{ action "${r}" "[fix]" }}{{ end }}`+(a===``?``:`{{ if ne .${n.sighting} "" }} {{ .${n.sighting} }}${a}{{ end }}`)+`{{ end }}`}}}function eN(e){for(let t of CM){Object.assign(e.actions,t.control.actions);let n=Hj(t.name);e.actions[n]={reset:t.configKey},e.variables[yM(t.name)]={kind:`input`,path:`resettable.${t.name}`,type:`boolean`,default:!1};let r=`{{ if .${yM(t.name)} }} {{ action "${n}" "↺" }}{{ end }}`;Object.assign(e.variables,t.control.variables),e.segments[Bj(t.name)]={template:`${t.control.template}${r}`},t.control.kind===`picker`&&[...t.control.list.rows.map(e=>({template:e})),...t.beneath].forEach((n,r)=>{e.segments[vM(t.name,r)]=n})}Object.assign(e.actions,OM.actions),e.actions[fM]=Sr(lM,dM),e.segments[uM]={template:`{{ action "${fM}" "⚙" }}`}}function tN(e){let{variables:t,actions:n}=uk();Object.assign(e.variables,t),Object.assign(e.actions,n)}function nN(e){let t=QM(e.globals.menuGlyph??`🍫`);tN(t);let n={...e.presets},r=[];for(let t of R_(e.presets)){let{node:i}=V_(e,t),a=qM(HM(i));r.push(a),n[t]={...B_(e.presets,t),root:a}}let i=qE(t,r,e);return{...e,variables:{...i,...e.variables,...t.variables},actions:{...e.actions,...t.actions},segments:{...e.segments,...t.segments},presets:n}}const rN=`${nD}live`,iN=[`☐ live`,`☑ live`],aN=`${nD}done`,oN=`${nD}cancel`,sN=`${nD}rewind`,cN=`${nD}changes`,lN=`(gt .${cN} 0)`,uN=`(or ${lN} (gt .${jM} 0))`,dN={variable:rN,key:rN,member:`open`};function fN(e){return`${nD}configuring.p${e}`}function pN(e){return`and ${_r(ak)} (not ${_r(dN)}) (ne .${fN(e)} "true")`}function mN(e){return{kind:`template`,template:`{{ or ${e.map(e=>`(eq .${QO} "${mr(e)}")`).join(` `)} false }}`}}function hN(e,t,n){return`{{ if ${pN(e)} }}${t}{{ else }}${n}{{ end }}`}const gN=`{{ and ${_r(ak)} .preset.customized }}`,_N=iD;function vN(e){return new Map([...K_(e),...bN(e)])}const yN=`${nD}addable`;function bN(e){return new Map([[yN,{members:Object.keys(e.segments).filter(e=>!_N(e)),library:{groups:JO.map(e=>({id:e,label:YO[e]})),entry:t=>{let n=e.segments[t];return{group:n.group??`other`,...n.description!==void 0&&{description:n.description}}}}}]])}function xN(e,t,n){return n.segments[e]={template:t,when:ok,bg:mk},{kind:`segment`,name:e}}function SN(e,t,n){let r=`${nD}${e.presetIdent}.remove.${t}`;return e.artifacts.actions[r]={persist:e.rootKey,removeSegment:n},`{{ fg (${`readableOn (color "error") (bgOf) ${bm}`}) (action "${r}" "✖") }}`}function CN(e){return`{{ if ${_r(ak)} }}${e}{{ end }}`}function wN(e,t){return e.reduce((e,t)=>`{{ if and ${_r(ak)} ${_r(t)} }}true{{ else }}${e}{{ end }}`,t)}function TN(e){return e.flatMap(e=>[...$g(e)].flatMap(e=>e.kind===`segment`&&e.opens?.ref.key===`edit.configure`?[e.opens.ref]:[]))}function EN(e,t,n){return`${rk}${e}.${t}.${n}`}function DN(e,t,n,r){let i=Yg(n),a=`${nD}${e.presetIdent}`,o=ik(e.presetIdent,i);e.configured.push(o);let s=`${a}.configure.${t}`,c=lD(s),l=`${s}.fold`;e.artifacts.actions[l]={set:c,to:ur},e.artifacts.actions[s]={do:[`${s}.open`,l]},e.artifacts.actions[`${s}.open`]={set:QO,to:o};let u={},d=Object.entries(r).map(([r,o])=>{let s=EN(e.presetIdent,i,r),l=`${rk}p${e.presetIdent}.d${t}.${r}`;e.artifacts.variables[l]={kind:`state`,key:s,default:y_(n.settings?.[r]??o.default)},u[r]={id:i,key:s,variable:l};let d=`${a}.setting.${t}.${r}`,f=xD(yD(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 hr(d,f.list.ref,{kind:`container`,direction:`vertical`,children:p},`drop`)});return{term:`{{ action "${s}" "${bk}" }}`,ref:{variable:QO,key:QO,member:o},body:{kind:`container`,direction:`vertical`,children:d},drafts:u}}const ON=`${nD}label:`;function kN(e){if(e.startsWith(ON)){let t=e.slice(ON.length);return t.slice(t.indexOf(`:`)+1)}return e.startsWith(`edit.`)?void 0:e}function AN(e,t,n,r){let{artifacts:i}=n,a=Yg(e),o=`${ON}${a}:${e.name}`;i.segments[o]={template:`{{ "${mr(a)}" }}`,...t.palette!==void 0&&{palette:t.palette}};let s=Object.fromEntries(m_.flatMap(t=>{let n=e.settings?.[t];return n===void 0?[]:[[t,n]]}));return{...hr(o,r.ref,r.body,`drop`,wN([r.ref],`{{ ${pN(n.presetIdent)} }}`)),...Object.keys(s).length>0&&{settings:s},drafts:Object.fromEntries(m_.map(e=>[e,r.drafts[e]]))}}function jN(e,t,n,r){let{presetIdent:i,artifacts:a}=e,o=`${nD}${i}.insert.${t}`,s=`${nD}${i}.insertSeg.${t}`;a.actions[o]={persist:e.rootKey,insertSegmentFrom:yN,anchor:n,relation:r};let c=sD(o),l=cD(s,o,void 0),u=dD(l),d=uD(l,c);return a.variables[l]=xr(l,ur),a.variables[u]={kind:`state`,key:u,default:`0`},a.actions[d]=Sr(l,c),a.actions[u]={set:u,int:!0},{host:s,template:`{{ $m := menu "${o}" "✚" "✕" }}{{ if ${_r({variable:l,key:l,member:c})} }}{{ $m }}{{ else }}{{ fg (${`readableOn (color "success") (bgOf) ${bm}`}) $m }}{{ end }}`}}function MN(e,t){let n=[],r=e.children.findIndex(e=>e.kind===`segment`&&!_N(e.name)),i=e=>MN(e,t);for(let[a,o]of e.children.entries()){if(o.kind===`container`){n.push(i(o));continue}let s=Qg(o,i);if(_N(o.name)){n.push(s);continue}let c=Yg(o),l=a===r?[jN(t,String(t.posCounter.n++),c,`before`)]:[],u=String(t.posCounter.n++),d=jN(t,u,c,`after`),f=SN(t,u,c),p=t.segments[o.name],m=DN(t,u,o,h_(p)),h=CN(f),g=CN(m.term),_={kind:`container`,direction:`horizontal`,children:[...l.map(e=>xN(e.host,e.template,t.artifacts)),{...AN(o,p,t,m),lead:h,trail:g},{...s,when:hN(t.presetIdent,`false`,o.when??`true`),lead:h,trail:g,drafts:m.drafts},xN(d.host,d.template,t.artifacts)]};n.push(e.direction===`vertical`?{kind:`container`,direction:`horizontal`,children:[_]}:_)}return{...e,children:n,...e.when!==void 0&&{when:wN(TN(n),hN(t.presetIdent,`true`,e.when))}}}function NN(e,t,n,r,i,a,o){let s=`${nD}${t}.resetLayout`,c=`${nD}${t}.customized`;return r.actions[s]={reset:n},r.segments[c]={template:`{{ action "${s}" "↺ reset layout" }}`,when:gN},{kind:`container`,direction:`vertical`,children:[{kind:`container`,direction:`horizontal`,children:[...i,{kind:`segment`,name:c},a]},PN(e,o)]}}function PN(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),PN(n,t)]}:{...e,children:[...e.children,t]}}function FN(e,t,n,r,i,a){let{node:o}=V_(e,t),s={presetIdent:JE(t),rootKey:VO(t),segments:e.segments,artifacts:n,posCounter:{n:0},configured:[]},c=MN(o,s);return n.variables[fN(s.presetIdent)]=mN(s.configured),NN(c,s.presetIdent,s.rootKey,n,r,i,a)}function IN(e){let t={variables:{},actions:{},segments:{}},n=fk(`${nD}help`,Sk,[ak],t);t.variables[rN]=xr(rN,ur),t.actions[rN]=Sr(rN,dN.member),t.segments[rN]={template:vr(rN,...iN),when:ok};let r={kind:`segment`,name:rN},i=n;t.variables[cN]={kind:`input`,path:`history.sinceEdit`,type:`number`,default:0},t.actions[aN]={do:[Lj,...tk]},t.segments[aN]={template:`{{ if ${uN} }}{{ action "${aN}" "✓ save" }}{{ else }}{{ action "${aN}" "✓ done" }}{{ end }}`,when:ok},t.actions[sN]={rewind:!0},t.actions[oN]={do:[sN,...tk]},t.segments[oN]={template:`{{ action "${oN}" "↩ cancel" }}`,when:`{{ and ${_r(ak)} ${lN} }}`};let a=[{kind:`segment`,name:aN},{kind:`segment`,name:oN}],o={...e.presets},s=[];for(let n of R_(e.presets)){let c=FN(e,n,t,a,r,i);s.push(c),o[n]={...B_(e.presets,n),root:c}}let c=qE(t,s,e);return{...e,variables:{...c,...e.variables,...t.variables},actions:{...e.actions,...t.actions},segments:{...e.segments,...t.segments},presets:o}}function LN(e){return e.op===`remove`?`remove:${e.target}`:`insert:${e.segment}:${e.anchor}:${e.relation}`}function RN(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 zN(e,t,n){let r=Zg(e,new Set(n.map(Xg).filter(e=>e.includes(t)).flat()));return r===e?{seg:e}:{seg:e,id:r}}const BN=/^-?\d+$/;function VN(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 HN(e){return t=>{if(!t)return{ok:!1,reason:`${e} value is required`};if(!BN.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 UN(e,t,n){return r=>r?BN.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 WN(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=>!BN.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 GN(e){return e===`config`?`set-config`:`set-state`}function KN(e,t,n){return t.kind===`int`?HN(`menu page "${e}"`):t.kind===`range`?UN(t.min,t.max,`${n} stepper "${e}"`):VN(t.allowed,`${n} "${e}"`,GN(n))}function qN(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:WN(e,n,t)}))}function JN(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 qN(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,KN(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 YN(e,t,n){let r=[],i=0,a=new WeakMap;return{register(n,a){let o={key:n,allowed:a};JN(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=JN(e,r,n(o),t);return a.set(o,{epoch:i,gate:c}),c}}}const XN=YN({},`config`,rP);function ZN(e,t){return XN.register(e,t)}function QN(e){return XN.gateFor(e)}function $N(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:J_(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:[LN({op:`remove`,target:e.removeSegment})]}}]:`insertSegment`in e?[{key:e.persist,spec:{kind:`allow-list`,allowed:[LN({op:`insert`,segment:e.insertSegment,anchor:e.anchor,relation:e.relation})]}}]:`insertSegmentFrom`in e?[{key:e.persist,spec:{kind:`allow-list`,allowed:J_(e.insertSegmentFrom,t).members.map(t=>LN({op:`insert`,segment:t,anchor:e.anchor,relation:e.relation}))}}]:[{key:e.persist,spec:{kind:`range`,min:e.min,max:e.max}}]:[]}function eP(e,t){let n=IO(e).get(t);return n===void 0?null:String(n)}function tP(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?GO(n.persist):null;e?.scope===`preset-root`&&t.add(VO(e.preset))}return[...t].map(e=>({key:e,spec:{kind:`allow-list`,allowed:[]}}))}function nP(e){let t=vN(e);return[...tP(e),...Object.values(e.actions).flatMap(e=>$N(e,t))]}function rP(e){return qN(nP(e),`config`)}function iP(e,t){return{globals:{...t.globals,...e.globals??{}},variables:{...t.variables,...e.variables??{}},segments:sP(t.segments,aP(t.segments,e.segments??{})),root:P_(e.root??D_,t.root),actions:{...t.actions,...e.actions??{}},styles:{...t.styles,...e.styles??{}},presets:sP(t.presets,oP(t.presets,e.presets??{})),themeDefaults:sP(t.themeDefaults,e.themeDefaults??{}),editGlobals:{...t.editGlobals,...e.editGlobals??{}},helpers:{...t.helpers,...e.helpers??{}}}}function aP(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 oP(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 sP(e,t){return{...e,...Object.fromEntries(Object.entries(t).map(([t,n])=>[t,{...e[t],...n}]))}}function cP(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: ${o_.join(`, `)})`,line:Y(e.source,t.split(`.`))}),null):dP(e,`${t}.cache`,n.cache)}function lP(e){return{required:!0,json:fP(),parse:(t,n,r,i)=>cP(t,n,i,e)??void 0}}const uP={noun:`cache`,arms:{ttl:{json:{type:`string`},parse:(e,t,n)=>typeof n==`string`&&mP(n)?{ttl:n}:FD(e,t,`cache.ttl must be a duration string like "5s", "100ms", "2m", "1h"; got ${Z(n)}`)},watch_file:{json:{type:`string`,pattern:`^/`},parse:(e,t,n)=>{if(typeof n!=`string`)return FD(e,t,`cache.watch_file must be a path string, got ${Z(n)}`);let r=qD(`cache.watch_file`,n);return r===null?{watch_file:n}:FD(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}:FD(e,t,`cache.depends_on must be an array of variable-name strings, got ${Z(n)}`)},key:{json:{type:`string`},parse:(e,t,n)=>typeof n==`string`&&n!==``?{key:n}:FD(e,t,`cache.key must be a non-empty template string, got ${Z(n)}`)},never:{json:{const:!0},parse:(e,t,n)=>n===!0?{never:!0}:FD(e,t,`cache.never must be the literal boolean true, got ${Z(n)}`)}}};function dP(e,t,n){return ID(e,uP,t,n)}function fP(){return eO(uP)}const pP=/^(\d+(?:\.\d+)?)(ms|s|m|h)$/;function mP(e){return pP.test(e)}function hP(e,t,n){if(n===void 0)return{};if(!OD(n))return e.issues.push({path:t,message:`${t} must be an object, got ${kD(n)}`,line:Y(e.source,t.split(`.`))}),{};let r={};for(let[i,a]of Object.entries(n)){let n=LD(e,VP,`${t}.${i}`,a);n!==null&&(r[i]=n)}return r}function gP(){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 ${kD(i)}`,line:Y(e.source,t.split(`.`))});return}return i}}}function _P(){return{required:!0,json:{enum:[...c_]},parse:(e,t,n,r)=>{let i=r.field;if(typeof i!=`string`||!c_.includes(i)){e.issues.push({path:`${t}.field`,message:`git field must be one of: ${c_.join(`, `)}, got ${JSON.stringify(i)}`,line:Y(e.source,[...t.split(`.`),`field`])});return}return i}}}function vP(){return{required:!1,json:{type:[`string`,`number`,`boolean`]},parse:(e,t,n,r)=>{let i=r.type;return wD(e,t,r,i===`number`||i===`boolean`||i===`string`?i:`string`)}}}const yP={noun:`parse`,arms:{text:{json:{const:!0},parse:(e,t,n)=>n===!0?{text:!0}:FD(e,t,`parse.text must be the literal boolean true, got ${Z(n)}`)},regex:{json:{type:`string`},parse:(e,t,n)=>typeof n==`string`?bP(e,t,n):FD(e,t,`parse.regex must be a pattern string, got ${Z(n)}`)},json:{json:{const:!0},parse:(e,t,n)=>n===!0?{json:!0}:FD(e,t,`parse.json must be the literal boolean true, got ${Z(n)}`)}}};function bP(e,t,n){let r;try{new RegExp(n),r=RegExp(`${n}|`).exec(``).length-1}catch(n){return FD(e,t,`parse.regex is not a valid regular expression: ${n.message}`)}return r>=1?{regex:n}:FD(e,t,`parse.regex must contain a capture group — its group 1 is the value; got ${JSON.stringify(n)}`)}function xP(){return{required:!1,json:eO(yP),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:Y(e.source,[...t.split(`.`),`regex`])}),r.parse===void 0?void 0:ID(e,yP,`${t}.parse`,r.parse)??void 0)}}function SP(){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)=>OD(r.parse)&&`json`in r.parse?CP(e,t,r.default):TD(e,t,r,`default`)}}function CP(e,t,n){if(n!==void 0)return wP(n)?n:FD(e,`${t}.default`,`${t}.default must be a JSON value (a json-parsed source's document), got ${Z(n)}`)??void 0}function wP(e){return e!==null&&TP(e)}function TP(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(TP);let t=Object.getPrototypeOf(e);return(t===Object.prototype||t===null)&&Object.values(e).every(TP)}default:return!1}}const EP={value:gP(),default:VD()},DP={path:KD(),type:YD([`string`,`number`,`boolean`]),default:vP()},OP={name:KD(),default:VD()},kP={path:JD(),readMode:YD([`whole`,`first-line`]),parse:xP(),cache:lP(`file`),default:SP()},AP={command:KD(),parse:xP(),cache:lP(`shell`),default:SP()};function jP(e){return{cache:`${e}, so it takes no cache policy — delete the key`}}const MP={template:KD(),default:VD()},NP=jP(`a template variable recomputes whenever a variable it reads changes`),PP={layout:KD(),default:VD()},FP=jP(`a time variable reads the instant its render is drawn at`),IP={field:_P(),default:VD()},LP=jP(`a git variable is refreshed by the daemon's own watch on the repository`),RP={key:KD(),default:VD()},zP=`kind`;function BP(e,t,n={}){return{...RD(zP,e,t),parse:(r,i,a)=>{jD(r,n,i,a);let o=MD(r,t,i,a);return o===null?null:{kind:e,...o}}}}const VP={tag:zP,noun:`source kind`,memberNoun:`variable`,arms:{literal:BP(`literal`,EP),input:BP(`input`,DP),env:BP(`env`,OP),file:BP(`file`,kP),shell:BP(`shell`,AP),template:BP(`template`,MP,NP),time:BP(`time`,PP,FP),git:BP(`git`,IP,LP),state:BP(`state`,RP)}};function HP(){return $D(VP)}function UP(){return{type:`object`,additionalProperties:HP()}}const WP=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`}]]);function GP(e){let t=WP.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)`}}const KP=/^[A-Za-z_][A-Za-z0-9_]*$/,qP={pattern:KP.source},JP={anyOf:[{type:`boolean`},{type:`string`},{type:`integer`}]},YP={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`,...qP}}}]},default:JP}},XP=[`label`,`domain`,`default`],ZP=[`min`,`max`,`step`,`atLeast`];function QP(e,t,n){e.issues.push({path:t,message:n,line:Y(e.source,t.split(`.`))})}function $P(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 QP(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 QP(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?QP(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(OD(n)){let{min:r,max:i,step:a=1,atLeast:o}=n;return Object.keys(n).filter(e=>!ZP.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}}:QP(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 QP(e,t,`domain must be "bool", a list of words, or { min, max }, got ${Z(n)}`)}function eF(e,t,n){if(!OD(n))return QP(e,t,`${t} must be { label, domain, default }, got ${kD(n)}`);for(let r of Object.keys(n))XP.includes(r)||QP(e,`${t}.${r}`,`Unknown setting key "${r}". Expected one of: ${XP.join(`, `)}`);let{label:r}=n,i=typeof r==`string`&&r.length>0&&!/[\n\r]/.test(r);i||QP(e,`${t}.label`,`a setting needs a one-line, non-empty "label" — the name its control shows, spliced into a synthesized template string — got ${Z(r)}`);let a=$P(e,`${t}.domain`,n.domain);if(!i||a===void 0)return;let o={label:r,domain:a,default:n.default};return!tF(n.default)||!v_(o,n.default)?QP(e,`${t}.default`,`default must be ${S_(o)}, got ${Z(n.default)}`):o}function tF(e){return typeof e==`boolean`||typeof e==`string`||typeof e==`number`}const nF={theme:`its default for this segment is segments.<name>.palette, and a placement sets its own with settings: { ${f_}: "<theme>" }`,effect:`a placement follows the bar's effect, or sets its own with settings: { effect: "<effect>" }`};function rF(e){return m_.includes(e)}function iF(){return{required:!1,json:{type:`object`,propertyNames:{...qP,not:{enum:[...m_]}},additionalProperties:YP},parse:(e,t,n,r)=>{let i=r[n];if(i===void 0)return;let a=`${t}.${n}`;if(!OD(i))return QP(e,a,`${a} must be an object of name → { label, domain, default }, got ${kD(i)}`);let o=Object.create(null);for(let[t,n]of Object.entries(i)){if(!KP.test(t)){QP(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(rF(t)){QP(e,`${a}.${t}`,`setting "${t}" is one every placement already has — ${nF[t]}`);continue}let r=eF(e,`${a}.${t}`,n);r!==void 0&&(o[t]=r)}return o}}}const aF=rD.map(e=>e.replace(/\./g,`\\.`)).join(`|`);function oF(){return{required:!1,json:{type:`string`,minLength:1,pattern:`^(?!${aF})[^:/]+$`},parse:(e,t,n,r)=>{let i=r[n];if(i!==void 0)return typeof i==`string`&&i.length>0&&!/[:/]/.test(i)&&!iD(i)?i:QP(e,`${t}.${n}`,`a placement "id" must be a non-empty string without "/" or ":", outside the reserved ${rD.map(e=>`"${e}"`).join(`, `)} namespaces, got ${Z(i)}`)}}}function sF(){return{required:!1,json:{type:`object`,propertyNames:qP,additionalProperties:JP},parse:(e,t,n,r)=>{let i=r[n];if(i===void 0)return;let a=`${t}.${n}`;if(!OD(i))return QP(e,a,`a placement's "settings" must be an object of setting name → value, got ${kD(i)}`);let o=Object.create(null);for(let[t,n]of Object.entries(i))tF(n)?o[t]=n:QP(e,`${a}.${t}`,`setting "${t}" must be a boolean, a word, or a number, got ${kD(n)}`);return o}}}function cF(e){return new Set(Object.keys(e.segments).filter(e=>!iD(e)))}function lF(e,t,n){if(t===void 0)return{};if(!OD(t))return e.issues.push({path:`segments`,message:`segments must be an object, got ${kD(t)}`,line:Y(e.source,[`segments`])}),{};let r={};for(let[i,a]of Object.entries(t)){let t=AD(e,n.has(i)?hF:mF,`segments.${i}`,a);t!==null&&(r[i]=t)}return r}function uF(){return{required:!0,json:{type:`string`},parse:(e,t,n,r)=>r[n]===void 0?FD(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${GP(t.slice(9))}`)??void 0:CD(e,t,r,n)??void 0}}function dF(){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 ${Z(i)}`,line:Y(e.source,[...t.split(`.`),n])})}}}}function fF(){return{required:!1,json:UP(),parse:(e,t,n,r)=>{let i=r[n];if(i!==void 0)return hP(e,`${t}.${n}`,i)}}}const pF={template:uF(),description:VD(),group:YD(qO),width:dF(),justify:YD(C_),truncate:YD(w_),bg:VD(),fg:VD(),when:VD(),palette:GD(),vars:fF(),settings:iF(),missingData:YD(l_)},mF={noun:`segment key`,fields:pF},hF={noun:`segment key`,fields:{...pF,template:VD()}},gF=`#/definitions/LayoutNode`,_F={kind:`container`,direction:`vertical`,children:[]};function vF(e){return{required:!0,json:{const:e},parse:()=>e}}function yF(){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 ${Z(i)}`,line:Y(e.source,[`root`])}),``)}}}function bF(){return{required:!0,json:{enum:[...qg]},parse:(e,t,n,r)=>{let i=r[n];return typeof i==`string`&&qg.includes(i)?i:(e.issues.push({path:`${t}.${n}`,message:`a container "direction" must be one of: ${qg.join(`, `)} (got ${JSON.stringify(i)})`,line:Y(e.source,[`root`])}),`vertical`)}}}function xF(e){return{required:!0,json:{type:`array`,items:{$ref:gF}},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 ${kD(a)}`,line:Y(t.source,[`root`])}),[])}}}const SF={noun:`layout-node key`,fields:{kind:vF(`segment`),name:yF(),when:VD(),id:oF(),settings:sF()}},CF=()=>YD(Xp),wF={noun:`layout-node key`,fields:{kind:vF(`container`),direction:bF(),children:xF(zD(()=>kF)),when:VD(),distribution:CF()}};function TF(){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 ${Z(i)}`,line:Y(e.source,[`root`])}),``)}}}const EF={noun:`layout-node key`,fields:{seg:TF(),when:VD(),id:oF(),settings:sF()}},DF={noun:`layout-node key`,fields:{h:xF(zD(()=>kF)),when:VD(),distribution:CF()}},OF={noun:`layout-node key`,fields:{v:xF(zD(()=>kF)),when:VD(),distribution:CF()}},kF=(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:Y(e.source,[`root`])}),_F):{kind:`segment`,name:n};if(!OD(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 ${kD(n)}`,line:Y(e.source,[`root`])}),_F;if(n.kind===`container`)return AD(e,wF,t,n)??_F;if(n.kind===`segment`)return AD(e,SF,t,n)??_F;if(n.kind===`cells`)return e.issues.push({path:t,message:`kind: "cells" is no longer supported — use the h-arm spelling instead:
|
|
172
172
|
Old: { kind: "cells", segments: ["seg1", "seg2"] }
|
|
173
|
-
New: { h: ["seg1", "seg2"] }`,line:Y(e.source,[`root`])}),fF;if(n.kind===`group`){let r=jD(e,jF,t,n);return r===null?fF:(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}),NF(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:Y(e.source,[`root`])}),fF}if(a){let r=jD(e,xF,t,n);return r===null?fF:{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=jD(e,SF,t,n);return r===null?fF:{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=jD(e,CF,t,n);return r===null?fF:{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:Y(e.source,[`root`])}),fF};function TF(){return{required:!0,json:{type:`object`,propertyNames:{pattern:E_.source},additionalProperties:{$ref:dF}},parse:(e,t,n,r)=>{let i=r[n];if(!kD(i))return e.issues.push({path:`${t}.${n}`,message:`"rows" must be an object of row name → layout node, got ${AD(i)}`,line:Y(e.source,[...t.split(`.`),n])}),{};let a={};for(let[r,o]of Object.entries(i)){if(!E_.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:Y(e.source,[...t.split(`.`),n,r])});continue}a[r]=wF(e,`${t}.${n}.${r}`,o)}return a}}}const EF={noun:`root key`,fields:{rows:TF(),when:HD(),distribution:vF()}};function DF(e,t,n){return kD(n)&&`rows`in n?jD(e,EF,t,n)??{rows:{}}:wF(e,t,n)}function OF(){return{required:!0,json:{type:`string`,pattern:E_.source},parse:(e,t,n,r)=>{let i=r[n];if(typeof i!=`string`||!E_.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 "${ur}", got ${Z(i)}`,line:Y(e.source,[`root`])});return}return i}}}function kF(){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 ${Z(i)}`,line:Y(e.source,[`root`])});return}return i}}}}function AF(){return{required:!0,json:{type:`string`,pattern:`^[^\\n\\r]*$`},parse:(e,t,n,r)=>{let i=wD(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:Y(e.source,[...t.split(`.`),n])});return}return i}}}}const jF={noun:`layout-node key`,fields:{kind:pF(`group`),name:OF(),label:AF(),open:UD(),direction:XD(Jg),key:kF(),bg:HD(),fg:HD(),when:HD(),distribution:vF(),children:gF(BD(()=>wF))}};function MF(e){return e.key??`groups.`+e.name}function NF(e){let t=tD+e.name;return hr(t,{variable:t,key:MF(e),member:e.name},{kind:`container`,direction:e.direction??`vertical`,children:e.children,...e.distribution!==void 0&&{distribution:e.distribution}},`drop`,e.when)}function PF(e,t,n){e.issues.push({path:t,message:n,line:Y(e.source,[`root`])})}function FF(e,t){sD(e,t,tD,`group nodes`);let n=e.groups;if(n.length===0)return;let r=new Set;for(let t of n)r.has(t.name)&&PF(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}.`)&&MF(t)===MF(r)&&PF(e,t.path,`group "${t.name}" shares key "${MF(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=MF(t);if(i.has(n)||i.set(n,ur),t.open===!0){let r=i.get(n);r!==`closed`&&PF(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=tD+e.name,r=MF(e),c=n.filter(t=>t!==e&&e.path.startsWith(t.path+`.`)).length,l=` `.repeat(c);a[t]=xr(r,i.get(r)),o[t]=Sr(r,e.name),s[t]={template:vr(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 IF=`menu`,LF=`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`,RF=e=>e.kind===`call`&&e.name===`dict`,zF=e=>e.kind===`literal`&&typeof e.value!=`object`,BF=e=>fr(``,e,2)===void 0;function VF(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&&RF(i)?i:void 0,o=a===void 0?r:r.slice(0,-1);if(o.some(RF))return t(`whose options (dict …) is not its last argument — ${LF}`);if(i!==void 0&&a===void 0&&!zF(i)&&BF(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=fr(`whose trigger`,o.length,2);if(s!==void 0)return t(`${s} — ${LF}`);let c=a===void 0?{}:hS(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=gD(c)}catch(e){return t(`with invalid options — ${e.message}`)}let u=l.key;if(u!==void 0){let e=oD(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 "${uD(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 HF(e){let t=wb({fromString:e=>e});try{return t.parse(e).referencedCalls().filter(e=>e.name===IF).map(VF)}catch{return`parse-failed`}}function UF(e){let t=wb({fromString:e=>e});try{return t.parse(e).referencedFunctions().has(IF)}catch{return!1}}function WF(e,t,n){e.issues.push({path:t,message:n,line:Y(e.source,[`root`])})}function GF(e,t){sD(e,t,nD,`{{ menu }} helpers`);for(let[n,r]of Object.entries(t.helpers??{}))UF(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:Y(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`&&UF(i)&&WF(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 e_(N_(t.root)))typeof n.when==`string`&&UF(n.when)&&WF(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||!UF(r))continue;let n=HF(r);if(n!==`parse-failed`)for(let r of n){let n=r.kind===`issue`?r.message:KF(r.apply);n!==void 0&&WF(e,`segments.${t}`,`segment "${t}" has a {{ menu }} ${n}.`)}}}function KF(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(cD(e)===`closed`)return`whose apply action is named "${ur}", which collides with the menu's closed-state sentinel and leaves it unopenable. Rename the action`}function qF(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 z_(e.presets)){let a=new Map,s=new Map;for(let c of e_(H_(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,HF(t.template));let l=i.get(c.name);if(l===`parse-failed`)continue;let u=Xg(c);for(let[e,t]of l.entries()){if(t.kind===`issue`||KF(t.apply)!==void 0)continue;let{apply:i,options:l}=t,d=cD(i),f=lD(u,i,l.key),p=fD(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=dD(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]=Sr(f,d),n[f]=xr(f,ur),n[p]={kind:`state`,key:p,default:`0`},r[p]={set:p,int:!0}}}}return{...e,variables:{...e.variables,...n},actions:{...e.actions,...r}}}const JF=[`set`,`persist`,`copy`,`open`,`reset`,`undo`,`redo`,`back`,`rewind`,`save`,`preset`,`themeDefault`,`doctor`,`ceiling`,`slash`,`do`];function YF(e){return e.ceiling===`set`?[`set`,e.to]:[`clear`]}function XF(e){return`from`in e||`int`in e||`insertSegmentFrom`in e}function ZF(e,t){if(t===void 0)return{};if(!kD(t))return Q(e,`actions`,`actions must be an object, got ${AD(t)}`),{};let n=Object.create(null);for(let[r,i]of Object.entries(t)){let t=QF(e,`actions.${r}`,i);t!==null&&(n[r]=t)}return n}function Q(e,t,n){e.issues.push({path:t,message:n,line:Y(e.source,t.split(`.`))})}function QF(e,t,n){if(!kD(n))return Q(e,t,`${t} must be an action object, got ${AD(n)}`),null;if(`persistWhen`in n)return Q(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 r=JF.filter(e=>e in n);return r.length===1?$F[r[0]](e,t,n):(Q(e,t,`action must declare exactly one of: ${JF.join(`, `)}${r.length>1?` (found: ${r.join(`, `)})`:``}`),null)}const $F={set:(e,t,n)=>NI(e,t,n,`set`,kI),persist:(e,t,n)=>NI(e,t,n,`persist`,AI),copy:eI(`copy`),open:eI(`open`),reset:tI,undo:rI(`undo`),redo:rI(`redo`),back:rI(`back`),rewind:rI(`rewind`),save:rI(`save`),preset:iI,themeDefault:aI,doctor:sI,ceiling:cI,slash:lI,do:uI};function eI(e){return(t,n,r)=>{for(let i of Object.keys(r))i!==e&&Q(t,`${n}.${i}`,`Unknown key "${i}" on a ${e} action. Expected only: ${e}`);let i=wD(t,n,r,e);return i===null?null:{[e]:i}}}function tI(e,t,n){for(let r of Object.keys(n))r!==`reset`&&Q(e,`${t}.${r}`,`Unknown key "${r}" on a reset action. Expected only: reset`);let r=dI(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 nI={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 rI(e){return(t,n,r)=>{for(let i of Object.keys(r))i!==e&&Q(t,`${n}.${i}`,`Unknown key "${i}" on a ${e} action. Expected only: ${e}`);return r[e]===!0?{[e]:!0}:(Q(t,`${n}.${e}`,`${e} must be the literal true (it takes no key — ${nI[e]}), got ${Z(r[e])}`),null)}}function iI(e,t,n){let r=n.preset,i=r===`save`?[`preset`]:[`preset`,`name`];for(let r of Object.keys(n))i.includes(r)||Q(e,`${t}.${r}`,`Unknown key "${r}" on a preset action. Expected only: ${i.join(`, `)}`);if(r!==`save`&&r!==`delete`)return Q(e,`${t}.preset`,`preset must be "save" or "delete", got ${Z(r)}`),null;if(r===`save`)return{preset:`save`};let a=wD(e,t,n,`name`);return a===null?null:{preset:`delete`,name:a}}function aI(e,t,n){for(let r of Object.keys(n))r!==`themeDefault`&&Q(e,`${t}.${r}`,`Unknown key "${r}" on a themeDefault action. Expected only: themeDefault`);return n.themeDefault===`save`?{themeDefault:`save`}:(Q(e,`${t}.themeDefault`,`themeDefault must be "save" (it saves the look the session draws as the active theme's default), got ${Z(n.themeDefault)}`),null)}const oI={run:[`doctor`],fix:[`doctor`,`check`],mark:[`doctor`,`check`,`mark`]};function sI(e,t,n){let r=n.doctor,i=typeof r==`string`&&Object.hasOwn(oI,r),a=i?oI[r]:[...new Set(Object.values(oI).flat())];for(let r of Object.keys(n))a.includes(r)||Q(e,`${t}.${r}`,`Unknown key "${r}" on a doctor action. Expected only: ${a.join(`, `)}`);if(!i)return Q(e,`${t}.doctor`,`doctor must be ${Object.keys(oI).map(e=>`"${e}"`).join(`, `)}, got ${Z(r)}`),null;if(r===`run`)return{doctor:`run`};let o=n.check,s=r===`mark`?LA:IA;if(typeof o!=`string`||!s.some(e=>e.name===o))return Q(e,`${t}.check`,`doctor ${r} must name a check (have: ${s.map(e=>e.name).join(`, `)}), got ${Z(o)}`),null;if(r===`fix`)return{doctor:`fix`,check:o};let c=n.mark;return Zk.includes(c)?{doctor:`mark`,check:o,mark:c}:(Q(e,`${t}.mark`,`doctor mark must be ${Zk.map(e=>`"${e}"`).join(` or `)}, got ${Z(c)}`),null)}function cI(e,t,n){let r=n.ceiling,i=r===`clear`?[`ceiling`]:[`ceiling`,`to`];for(let r of Object.keys(n))i.includes(r)||Q(e,`${t}.${r}`,`Unknown key "${r}" on a ceiling action. Expected only: ${i.join(`, `)}`);if(r===`clear`)return{ceiling:`clear`};if(r!==`set`)return Q(e,`${t}.ceiling`,`ceiling must be "set" or "clear", got ${Z(r)}`),null;let a=n.to;return typeof a!=`string`||a.trim()===``?(Q(e,`${t}.to`,`ceiling set needs \`to\`: a memento ceiling value such as "+100_000", "400000" or "off", got ${Z(a)}`),null):{ceiling:`set`,to:a}}function lI(e,t,n){for(let r of Object.keys(n))r!==`slash`&&Q(e,`${t}.${r}`,`Unknown key "${r}" on a slash action. Expected only: slash`);let r=aj(n.slash);return r.kind===`refused`?(Q(e,`${t}.slash`,r.reason),null):{slash:r.line}}function uI(e,t,n){for(let r of Object.keys(n))r!==`do`&&Q(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===``)?(Q(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 ${Z(r)}`),null):{do:r}}function dI(e,t,n,r,i,a){let o=wD(e,t,r,n);if(o===null)return null;let s=`${t}.${n}`;return o===``?(Q(e,s,i),null):o.includes(`/`)?(Q(e,s,a(o)),null):o}const fI={set:`the SessionState key to write`,persist:`the config globals field to write`};function pI(e,t,n,r){let i=fI[r],a=dI(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 mI(e){return e===`set`?`set-state`:`set-config`}const hI={to:PI(`set`)},gI={to:PI(`persist`)},_I={from:FI(`set`)},vI={from:FI(`persist`)},yI={min:BI(),max:BI(),by:BI()},bI={int:LI()},xI={cycle:II(`set`)},SI={cycle:II(`persist`)},CI={removeSegment:RI(`removeSegment`)},wI={insertSegment:RI(`insertSegment`),anchor:RI(`anchor`),relation:zI()},TI={insertSegmentFrom:FI(`persist`),anchor:RI(`anchor`),relation:zI()},EI={ok:e=>e.min<e.max,issue:e=>({field:`min`,message:`min (${e.min}) must be less than max (${e.max})`})},DI={ok:e=>e.by!==0,issue:()=>({field:`by`,message:`by must be a non-zero integer (the per-click increment; negative steps down)`})};function OI(e,t,n=[],r){let i=Object.keys(t),a=r??i,o=[e],s=(e,n,r)=>ND(e,t,n,r),c=ZD(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?VD(s,...n):s}}const kI=[OI(`set`,hI),OI(`set`,_I),OI(`set`,yI,[EI,DI]),OI(`set`,bI),OI(`set`,xI)],AI=[OI(`persist`,gI),OI(`persist`,vI),OI(`persist`,yI,[EI,DI]),OI(`persist`,SI),OI(`persist`,CI),OI(`persist`,wI,[],[`insertSegment`]),OI(`persist`,TI,[],[`insertSegmentFrom`])];function jI(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 MI(e){let t=jI(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 NI(e,t,n,r,i){let a=pI(e,t,n,r),o=i.filter(e=>e.detect.some(e=>e in n));if(o.length!==1)return Q(e,t,`${MI(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)||Q(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 PI(e){let t=mI(e);return{required:!0,json:{type:`string`},parse:(n,r,i,a)=>dI(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 FI(e){let t=mI(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===``){Q(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){Q(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===``)){Q(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){Q(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){Q(n,s,`${i} array members must be unique — a duplicated value would render the same picker option twice`);return}return r}Q(n,s,`${i} must be a domain name (a string) or an inline domain (an array of strings), got ${Z(o)}`)}}}function II(e){let t=mI(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`)){Q(n,s,`cycle must be an array of strings (the enumerated values a click steps through), got ${AD(o)}`);return}let c=o;if(c.length<2){Q(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){Q(n,s,`cycle members must be non-empty — an empty value cannot be delivered on the ${t} wire`);return}if(u.length>0){Q(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){Q(n,s,`cycle members must be unique — the successor of a duplicated member is ambiguous`);return}return c}}}function LI(){return{required:!0,json:{const:!0},parse:(e,t,n,r)=>{if(r[n]!==!0){Q(e,`${t}.${n}`,`int must be the literal true (declares the key an unbounded integer cursor — a paged picker's page key), got ${Z(r[n])}`);return}return!0}}}function RI(e){return{required:!0,json:{type:`string`},parse:(t,n,r,i)=>{let a=wD(t,n,i,r);if(a===null)return;let o=`${n}.${r}`;if(a===``){Q(t,o,`${e} must be non-empty (a segment name)`);return}if(a.includes(`/`)||a.includes(`:`)){Q(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 zI(){return{required:!0,json:{enum:[`before`,`after`]},parse:(e,t,n,r)=>{let i=r[n];if(i!==`before`&&i!==`after`){Q(e,`${t}.${n}`,`relation must be "before" or "after", got ${Z(i)}`);return}return i}}}function BI(){return{required:!0,json:{type:`integer`},parse:(e,t,n,r)=>{let i=r[n];if(typeof i!=`number`||!Number.isInteger(i)){Q(e,`${t}.${n}`,`${n} must be an integer, got ${Z(i)}`);return}return i}}}function VI(e,t,n){return`${e}: "${t}" is an endcaps shape, not a style — endcaps were renamed from "style" to "endcaps"; write ${n}: "${t}"`}const HI={noun:`style key`,fields:{hueShift:GD(),chromaScale:GD({min:0}),lightnessScale:GD(),lightnessShift:GD()}};function UI(e,t){if(!kD(t))return e.issues.push({path:`styles`,message:`styles must be an object mapping style names to adaptation objects, got ${AD(t)}`,line:Y(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:Y(e.source,[`styles`,r])});continue}if(Sh(r)){e.issues.push({path:`styles.${r}`,message:VI(`styles.${r}`,r,`globals.endcaps`),line:Y(e.source,[`styles`,r])});continue}let t=jD(e,HI,`styles.${r}`,i);t!==null&&(n[r]={...As,...t})}return n}const WI={noun:`preset key`,fields:{root:{required:!1,json:{$ref:`#/definitions/RootFragment`},parse:(e,t,n,r)=>r[n]===void 0?void 0:DF(e,`${t}.${n}`,r[n])},globals:{required:!1,json:AO(),parse:(e,t,n,r)=>r[n]===void 0?void 0:kO(e,`${t}.${n}`,r[n])}}};function GI(e,t){if(!kD(t))return e.issues.push({path:`presets`,message:`presets must be an object mapping preset names to config fragments, got ${AD(t)}`,line:Y(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:Y(e.source,[`presets`,r])});continue}let t=jD(e,WI,`presets.${r}`,i);t!==null&&(n[r]=t)}return n}function KI(e,t){if(t===void 0)return{};if(!kD(t))return e.issues.push({path:`helpers`,message:`helpers must be an object, got ${AD(t)}`,line:Y(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 ${Z(i)}`,line:Y(e.source,[`helpers`,r])});continue}n[r]=i}return n}const qI=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 JI(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 YI(e){let t=qI.get(e);return t===void 0?void 0:`variables.${e} is no longer read: ${JI(t)}`}function XI(e){let t=qI.get(e);return t===void 0?``:` — ".${e}" is no longer a variable: ${JI(t)}; a "${t.segment}" template reads it as ".settings.${t.setting}"`}function ZI(e,t){let n=new Map;for(let e of Object.keys(t)){let t=YE(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:Y(e.source,[`presets`])})}function QI(e,t,n){let r=[[[`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,i,a]of r){if(i===void 0||ih(i)||Object.prototype.hasOwnProperty.call(t.styles,i))continue;let r=`${n.join(`.`)}.style`;e.issues.push({path:r,message:Sh(i)?VI(r,i,a):`${r} "${i}" does not match any declared style (have: ${Object.keys(t.styles).join(`, `)})`,line:Y(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:Y(e.source,[`globals`,`preset`])}),ZI(e,t.presets);let i=vv(t);for(let t of i.names)t!==`settings`&&!t.startsWith(tL)||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:Y(e.source,[`variables`,t])});let a=(t,n,r)=>{RM(t)>1&&e.issues.push({path:n,message:`${n} places the global settings menu anchor "${_j}" ${RM(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:r}),zM(t)&&e.issues.push({path:n,message:`${n} places the global settings menu anchor "${_j}" 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:r}),o(t)&&e.issues.push({path:n,message:`${n} sets "distribution" on a container inside a bar cell — everything inside a cell wears that cell's hue and shade, so it would place nothing. Set it on the row whose children are the cells (the horizontal container) or on the root, which places the rows.`,line:r});let i=new Map;for(let e of e_(t)){if(e.kind!==`segment`)continue;let t=Xg(e);i.set(t,[...i.get(t)??[],e])}for(let[t,a]of i){if(a.length<2)continue;let o=a[1].name,s=Qg(o,new Set(i.keys()));e.issues.push({path:n,message:`${n} has ${a.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: "${o}", id: "${s}" }. A placement without an "id" takes its segment's name.`,line:r})}};function o(e,t=!1){return e.kind===`segment`?!1:t&&e.distribution!==void 0||e.children.some(n=>o(n,t||Yg[e.direction]===`cell`))}let s=(n,r)=>{for(let[a,o]of P_(n,r)){let n=Y(e.source,o.split(`.`));if(a.when!==void 0&&(pL(e,`${o}.when`,a.when,i,{line:n}),fL(e,`${o}.when`,a.when,n)),a.kind===`segment`){if(FM(a.name)){(a.id!==void 0||a.settings!==void 0)&&e.issues.push({path:o,message:`${r} gives the global settings menu anchor "${_j}" an id or settings — the anchor only marks where the menu goes, so place it as the bare name "${_j}"`,line:n});continue}Object.prototype.hasOwnProperty.call(t.segments,a.name)||e.issues.push({path:o,message:`${r} entry "${a.name}" does not match any declared segment${BP(a.name)}`,line:n}),lL(e,t,a,o,n)}}};n.root!==void 0&&s(n.root,`root`);for(let[e,t]of Object.entries(n.presets??{}))t.root!==void 0&&s(t.root,`presets.${e}.root`);let c=new Map([[`root`,M_(t.root)]]);for(let e of z_(t.presets)){let{node:n,path:r}=H_(t,e);c.set(r,n)}for(let[t,n]of c)a(n,t,Y(e.source,t.split(`.`)));bL(e,t,i,()=>!0)}const $I=[`removeSegment`,`insertSegment`,`insertSegmentFrom`];function eL(e,t,n,r,i,a,o){let s=`actions.${n}.${r}`,c=Y(e.source,[`actions`,n,r]);if(!z_(t.presets).includes(a)){e.issues.push({path:s,message:`actions.${n}: "${i}" names preset "${a}" which is not declared (have: ${z_(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(`, `)})${BP(i)}`,line:c})},p=new Set(Zg(H_(t,a).node)),m=(r,i)=>{!zP.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${BP(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 tL=`settings.`;function nL(e,t){return{...e,names:new Set([...e.names,...Object.keys(t).map(e=>tL+e)])}}function rL(e,t,n){let r=e=>`segments.${t}.settings.${e}`,i=(n,i)=>{e.issues.push({path:r(n),message:`${r(n)}: ${i}`,line:Y(e.source,[`segments`,t,`settings`,n])})},a=oL(n);for(let{setting:e,message:t}of a)i(e,t);if(!(a.length>0))for(let{setting:e,message:t}of v_(n,aL(n)))i(e,`the defaults do not stand together: ${t}`)}function iL(e){return oL(e).length>0||v_(e,aL(e)).length>0}function aL(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.default]))}function oL(e){let t=t=>__(sL(e,t))?.atLeast;return Object.keys(e).flatMap(n=>{let r=t(n);if(r===void 0)return[];if(r===n||__(sL(e,r))===void 0)return[{setting:n,message:`atLeast "${r}" must name another range setting of this segment (its range settings: ${cL(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 sL(e,t){return Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}function cL(e,t){return Object.entries(e).filter(([e,n])=>e!==t&&__(n)!==void 0).map(([e])=>e)}function lL(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=g_(a),s=`${r}: placement "${Xg(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(`, `)})`:y_(c,a)?void 0:`sets "${t}" to ${JSON.stringify(a)}${c.domain===`theme`?Ym(a):``}, but it must be ${C_(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])=>y_(o[e],t))||iL(o)))for(let{message:t}of v_(o,c))e.issues.push({path:r,message:`${s}: ${t}`,line:i})}function uL(e,t,n,r,i){n.kind===`template`&&pL(e,`${t}.template`,n.template,r,{segCtx:i}),c_(n)&&`key`in n.cache&&pL(e,`${t}.cache.key`,n.cache.key,r,{segCtx:i})}function dL(e,t,n,r,i){if(!(!c_(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:Y(e.source,[...t.split(`.`),`cache`,`depends_on`])})}}function fL(e,t,n,r){try{ZO.parse(n)}catch(n){e.issues.push({path:t,message:`Template parse error in ${t}: ${n.message}`,line:r})}}function pL(e,t,n,r,i){for(let[a,o]of uv(n,r.helpers)){if(_v(a,r))continue;if(a.startsWith(tL)){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??Y(e.source,t.split(`.`))});continue}if(o!==null){mL(e,o,`Template references unknown variable ".${a}"${XI(a)}`);continue}let n=i?.segCtx===void 0?void 0:`${i.segCtx}.${a}`,s=n!==void 0&&_v(n,r)?` (segment-local vars are namespaced — write ".${n}")`:XI(a);e.issues.push({path:t,message:`Template references unknown variable ".${a}"${s}`,line:i?.line??Y(e.source,t.split(`.`))})}}function mL(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:Y(e.source,[`helpers`,t])})}function hL(e,t,n,r,i){let a=n.set,o=mO(Ba[r].configKey),s=`${a} takes ${yD(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:Y(e.source,[`actions`,t,`min`])});return}let c=vL(n,i);if(c===_L){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:Y(e.source,[`actions`,t,`int`])});return}let l=c.filter(e=>!vD(o,e.value,i));if(l.length!==0){if(a===Ba.style.sessionKey&&(`from`in n&&n.from===`endcaps`||c.every(e=>Sh(e.value)))){let r=Ba.endcaps.sessionKey;e.issues.push(`to`in n?{path:`actions.${t}.to`,message:VI(`actions.${t}.to`,n.to,`set: "${r}", to`),line:Y(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:Y(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<=gL?r.join(`, `):`${r.slice(0,gL).join(`, `)} and ${r.length-gL} 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:Y(e.source,[`actions`,t,n])})}}}const gL=3,_L=Symbol(`any integer`);function vL(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?Y_(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)}]:_L}function yL(e,t){return Object.entries(e).filter(([e])=>t(e))}function bL(e,t,n,r){let i=pN(t),a=J_(i);for(let[n,o]of yL(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 ${Z_(r,i)}`,line:Y(e.source,[`actions`,n,t])});continue}if(!(`set`in o))continue;Ua.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:Y(e.source,[`actions`,n,`set`])});let s=qa.get(o.set);s!==void 0&&hL(e,n,o,s,i)}for(let[n,i]of yL(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&&XF(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:Y(e.source,[`actions`,n,`do`])})});for(let[n,i]of yL(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=KO(r);if(o===null){let t=PO(r);e.issues.push({path:`actions.${n}.${a}`,message:t===void 0?`actions.${n}: "${r}" is not a config globals field (have: ${FO().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:Y(e.source,[`actions`,n,a])});continue}let s=$I.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:Y(e.source,[`actions`,n,a])});continue}if(o.scope===`preset-root`){eL(e,t,n,a,r,o.preset,i);continue}if(o.scope===`preset-globals`&&!z_(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: ${z_(t.presets).join(`, `)})`,line:Y(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${Ym(o.theme)} (have: ${[...e.allowedPalettes].sort().join(`, `)})`,line:Y(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(`, `)})${BP(o.segment)}`,line:Y(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:Y(e.source,[`actions`,n,a])})}}for(let[i,a]of yL(t.variables,r)){uL(e,`variables.${i}`,a,n);let t=YI(i);t!==void 0&&e.issues.push({path:`variables.${i}`,message:t,line:Y(e.source,[`variables`,i])})}for(let[i,a]of yL(t.segments,r)){if(a.vars)for(let[t,r]of Object.entries(a.vars))uL(e,`segments.${i}.vars.${t}`,r,n,i);let r=g_(a);rL(e,i,r);let o=nL(n,r);for(let n of[`template`,`bg`,`fg`,`when`]){let s=a[n];if(typeof s==`string`){pL(e,`segments.${i}.${n}`,s,o,{segCtx:i,settings:r});for(let{name:r,site:a,via:o}of mv(s,t.helpers)){if(Object.prototype.hasOwnProperty.call(t.actions,r))continue;let s=a===`options`?` (in a picker, menu, carousel, swatch, swatches or themePreview)`:``;if(o!==null){mL(e,o,`Template references unknown action "${r}"${s}`);continue}e.issues.push({path:`segments.${i}.${n}`,message:`${n} references unknown action "${r}"${s}`,line:Y(e.source,[`segments`,i,n])})}}}}for(let[i,a]of yL(t.variables,r))dL(e,`variables.${i}`,a,n);for(let[i,a]of yL(t.segments,r))if(a.vars)for(let[t,r]of Object.entries(a.vars))dL(e,`segments.${i}.vars.${t}`,r,n,i)}function xL(e,t,n=()=>!0){let{graph:r,nodeInfo:i}=SL(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:Y(e.source,a?.linePathParts??[`variables`,r])}),!0}if(t===0&&s(c))return!0}return a.set(t,2),o.pop(),!1}}function SL(e){let t=new Set(Object.keys(e.variables)),n=new Map;for(let t of Object.keys(e.variables))n.set(t,{declarationPath:`variables.${t}`,linePathParts:[`variables`,t]});for(let[r,i]of Object.entries(e.segments))if(i.vars)for(let e of Object.keys(i.vars)){let i=`${r}.${e}`;t.add(i),n.set(i,{declarationPath:`segments.${r}.vars.${e}`,linePathParts:[`segments`,r,`vars`,e]})}let r=new Map;for(let e of t)r.set(e,new Set);let i=(n,i)=>{for(let a of uv(i,e.helpers).keys()){if(t.has(a)){r.get(n).add(a);continue}let e=a.split(`.`)[0];e!==a&&t.has(e)&&r.get(n).add(e)}},a=(e,n)=>{if(n.kind===`template`&&i(e,n.template),c_(n)&&(`key`in n.cache&&i(e,n.cache.key),`depends_on`in n.cache))for(let i of n.cache.depends_on)t.has(i)&&r.get(e).add(i)};for(let[t,n]of Object.entries(e.variables))a(t,n);for(let[t,n]of Object.entries(e.segments))if(n.vars)for(let[e,r]of Object.entries(n.vars))a(`${t}.${e}`,r);return{graph:r,nodeInfo:n}}function CL(e){return e===`~`||e.startsWith(`~/`)||e.startsWith(`~\\`)?w.homedir()+e.slice(1):e}function wL(e,t){return v.resolve(e,CL(t))}function TL(e,t){return typeof t==`string`&&t!==``?wL(e,t):void 0}function EL(e){return`plugin ${e.path} was not loaded: ${e.reason}`}const DL=new Set([`data`,`segments`,`helpers`,`actions`]),OL=`plugin.json5`,kL=/^[a-z][a-z0-9_]*$/;function AL(e){let t=v.basename(v.dirname(e));return kL.test(t)?t:void 0}const jL=`plugins.`;function ML(e){return`${jL}${e}.data`}function NL(e){try{return{ok:!0,value:e()}}catch(e){return{ok:!1,reason:PL(e)}}}function PL(e){return e instanceof XE?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 FL(e,t){return e.map(e=>wL(v.dirname(t),e))}function IL(e,t,n,r){let i=new Map;return e.reduce((e,n)=>{let a=AL(n),o=(t,r)=>{let i=new Map(e.rendering);return a!==void 0&&r!==e.config&&i.delete(a),{...e,config:r,rendering:i,dropped:[...e.dropped,{path:n,plugin:a,reason:t}]}};if(v.basename(n)!==`plugin.json5`){let t=`a plugin is a folder holding its ${OL}, and the folder's name is the plugin's: move this file to <dir>/<name>/${OL} and list that`;return o(t,a===void 0?e.config:zL(RL(e.config,a),a,{path:n,plugin:a,reason:t}))}if(a===void 0)return o(`its folder "${v.basename(v.dirname(n))}" is not a plugin name (one matching ${kL}: it prefixes every name the plugin declares)`,e.config);let c=i.get(a);if(c!==void 0)return o(`plugin "${a}" is already listed, from ${c}`,e.config);i.set(a,n);let l=RL(e.config,a),u=NL(()=>{let i=s.readFileSync(n,`utf-8`),o=$N(GL(n,a,{source:i,json:Ar.default.parse(i)},t),l);return r(o,a,l!==e.config),o});if(u.ok)return{...e,config:u.value,loaded:[...e.loaded,n],rendering:new Map([...e.rendering,[a,n]])};let d={path:n,plugin:a,reason:u.reason};return o(u.reason,zL(l,a,d))},{config:n.config,rendering:n.rendering,loaded:[],dropped:[]})}function LL(e){let t=`${jL}${e}.`;return e=>e.startsWith(t)}function RL(e,t){let n=LL(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 zL(e,t,n){return{...e,variables:{...e.variables,[ML(t)]:{kind:`dropped`,reason:EL(n),definition:n.path}}}}function BL(e){return e.startsWith(`plugins.`)?e.slice(8).split(`.`)[0]:void 0}function VL(e,t){let n=new Set([...Object.keys(e.config.variables),...Object.keys(e.config.segments)].map(BL)),r=[...t,...e.dropped].filter(e=>e.plugin===void 0).map(e=>({definition:e.path,notice:EL(e)}));return t=>{let i=BL(t);if(i===void 0)return[];let a=e.config.variables[ML(i)];return a?.kind===`dropped`?[{definition:a.definition,notice:a.reason}]:n.has(i)?[]:r}}function HL(e,t){let n=z_(e.presets).flatMap(t=>[...e_(H_(e,t).node)]).flatMap(e=>e.kind===`segment`?[e]:[]),r=[...new Set([...n.map(e=>e.name),...Object.keys(e.segments)])].map(e=>({name:e,cause:t(e)})).filter(({cause:e})=>e.length>0),i=Object.fromEntries(r.map(({name:e,cause:t})=>[e,UL(e,t.map(e=>e.notice),n.filter(t=>t.name===e))])),a=t=>{let n=BL(t),r=n===void 0?void 0:e.variables[ML(n)];return r?.kind===`dropped`?{definition:r.definition,notice:r.reason}:void 0},o=Object.values(e.variables).some(e=>e.kind===`dropped`),s=o?Object.values(e.segments).flatMap(e=>[`template`,`bg`,`fg`,`when`].flatMap(t=>e[t]===void 0?[]:[e[t]])):[],c=o?Object.values(e.actions).flatMap(e=>`do`in e?[...e.do]:[]):[],l=(e,t)=>[...new Set(e)].flatMap(e=>{let n=e in t?void 0:a(e);return n===void 0?[]:[[e,n]]}),u=l([...s.flatMap(t=>mv(t,e.helpers).map(e=>e.name)),...c],e.actions),d=l(s.flatMap(t=>[...gv(t,e.helpers)]),e.helpers),f=new Set([...r.flatMap(({cause:e})=>e.map(e=>e.definition)),...[...u,...d].map(([,e])=>e.definition)]);return{config:{...e,segments:{...e.segments,...i},actions:{...e.actions,...Object.fromEntries(u.map(([e])=>[e,{copy:`{{ .${ML(BL(e)??``)} }}`}]))},helpers:{...e.helpers,...Object.fromEntries(d.map(([e,t])=>[e,`{{ fail ${JSON.stringify(t.notice)} }}`]))}},reached:f}}function UL(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,WL(e,t)]));return{template:`{{ ${JSON.stringify(r)} }}`,bg:`error`,description:`stands in for a segment whose plugin did not load`,settings:a}}function WL(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 GL(e,t,{source:n,json:r},{checkout:i}){let a=[],o=()=>{throw new XE(e,a)};if(!kD(r))return a.push({path:``,message:`a plugin definition must be an object, got ${AD(r)}`}),o();for(let e of Object.keys(r))DL.has(e)||a.push({path:e,message:e===`plugin`?`a plugin definition does not name itself: its name is its folder's ("${t}") — remove "plugin"`:`a plugin definition may not declare "${e}". Expected only: ${[...DL].join(`, `)}`});let s=ZL(r.data,e,i,a);if(kD(r.segments)||a.push({path:`segments`,message:`"segments" must be an object naming the plugin's segments`}),a.length>0||s===void 0)return o();let c={source:n,issues:a,allowedPalettes:new Set(Qm()),groups:[]},l=uP(c,`data`,{[ML(t)]:{kind:`file`,path:s,parse:{json:!0},cache:{watch_file:s},default:{}}});for(let[e,t]of Object.entries(r.segments))if(!(!kD(t)||!kD(t.vars)))for(let[n,r]of Object.entries(t.vars)){let t=kD(r)?r.kind:void 0;typeof t!=`string`||t===`state`||a.push({path:`segments.${e}.vars.${n}`,message:`a plugin segment's vars may declare only state variables (kind: "state"), never a source such as ${JSON.stringify(t)}: a plugin's only source is its data file`})}let u={variables:l,segments:qL(t,YL(t,iF(c,r.segments,new Set))),helpers:qL(t,KI(c,r.helpers)),actions:qL(t,XL(t,ZF(c,r.actions)))};for(let[e,t]of KL(u))try{ZO.parse(t)}catch(t){a.push({path:e,message:`Template parse error in ${e}: ${t.message}`})}return a.length>0&&o(),u}function*KL(e){for(let[t,n]of Object.entries(e.segments??{}))for(let e of[`template`,`bg`,`fg`,`when`]){let r=n[e];r!==void 0&&(yield[`segments.${t}.${e}`,r])}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??{}))`copy`in n&&(yield[`actions.${t}.copy`,n.copy]),`open`in n&&(yield[`actions.${t}.open`,n.open]),`preset`in n&&n.preset===`delete`&&(yield[`actions.${t}.name`,n.name])}function qL(e,t){return Object.fromEntries(Object.entries(t).map(([t,n])=>[`${jL}${e}.${t}`,n]))}function JL(e,t){return`${jL}${e}.${t}`}function YL(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,n.kind===`state`?{...n,key:JL(e,n.key)}:n]))}]))}function XL(e,t){return Object.fromEntries(Object.entries(t).map(([t,n])=>[t,`set`in n?{...n,set:JL(e,n.set)}:n]))}function ZL(e,t,n,r){if(typeof e==`string`&&e!==``)return wL(v.dirname(t),e);if(kD(e)&&Object.keys(e).length===1&&typeof e.checkout==`string`&&e.checkout!==``){let t=e.checkout;if(v.isAbsolute(t)||t.startsWith(`~`)||v.normalize(t).split(v.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 v.resolve(n.root,t)}if(kD(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 QL(e){let t=[...[...(process.env.XDG_DATA_DIRS||tR()).split(`:`).filter(e=>e!==``)].reverse().map(e=>v.join(e,`cc-candybar`,`plugins`)),$L(),...e===null?[]:[v.join(e,eR)]];return t.filter((e,n)=>t.lastIndexOf(e)===n)}function $L(){let e=process.env.XDG_DATA_HOME||v.join(w.homedir(),`.local`,`share`);return v.join(e,`cc-candybar`,`plugins`)}const eR=v.join(`.cc-candybar`,`plugins`);function tR(){let e=`/usr/local/share:/usr/share`;return process.platform===`darwin`?`${v.join(process.env.HOMEBREW_PREFIX||`/opt/homebrew`,`share`)}:${e}`:e}function nR(e){let t=QL(e),n=new Map,r=[],i=[];for(let e of t){let t=rR(e);if(`error`in t){r.push(t);continue}for(let r of t.folders)n.delete(r),n.set(r,v.join(e,r,OL));for(let n of t.files)i.push({path:v.join(e,n),plugin:void 0,reason:`a plugin is a folder holding its ${OL}: move this file to ${v.join(e,`<name>`,OL)}`})}return{roots:t,definitions:[...n.values()],unchecked:r,strays:i}}function rR(e){try{let t=s.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()||iR(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 iR(e,t){if(!t.isSymbolicLink())return!1;try{return s.statSync(v.join(e,t.name)).isDirectory()}catch{return!0}}const aR=[`json5`,`json`];function oR(e){try{return s.statSync(e,{throwIfNoEntry:!1})===void 0?`absent`:`present`}catch(t){return{path:e,error:t.message}}}function sR(e,t,n){if(n!==void 0)return[n];let r=t??process.cwd();return[...new Set([...e?aR.map(t=>v.join(e,`.cc-candybar.${t}`)):[],...aR.map(e=>v.join(r,`.cc-candybar.${e}`)),...aR.map(e=>`${cR()}.${e}`)])]}function cR(){let e=process.env.XDG_CONFIG_HOME??v.join(w.homedir(),`.config`);return v.join(e,`cc-candybar`,`config`)}function lR(e,t,n){let r=[],i=new Map;for(let a of sR(e,t,n)){let e=oR(a);if(e===`absent`)continue;if(e!==`present`){r.push(e);continue}let t=v.join(s.realpathSync(v.dirname(a)),v.basename(a).replace(/\.(json5|json)$/,``));i.has(t)||i.set(t,a)}let a=[...i.values()].reverse();if(n===void 0)return{kind:`chain`,layers:a,home:uR(a),unchecked:r};let[o]=r,c=n;return a.length>0?{kind:`chain`,layers:a,home:c,unchecked:r}:o===void 0?{kind:`missing`,path:n,home:c}:{kind:`unreadable`,...o,home:c}}function uR(e){let t=cR();return e.find(e=>aR.some(n=>e===`${t}.${n}`))??`${t}.${aR[0]}`}function dR(e,t,n){let r=lR(e,t,n),i=r.kind===`chain`?r.layers:[];return{path:r.home,above:i.filter(e=>e!==r.home),projectDir:e??null,cwd:t??null}}function fR(e){return pR(e).join(`
|
|
174
|
-
`)||null}function
|
|
173
|
+
New: { h: ["seg1", "seg2"] }`,line:Y(e.source,[`root`])}),_F;if(n.kind===`group`){let r=AD(e,IF,t,n);return r===null?_F:(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}),RF(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:Y(e.source,[`root`])}),_F}if(a){let r=AD(e,EF,t,n);return r===null?_F:{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=AD(e,DF,t,n);return r===null?_F:{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=AD(e,OF,t,n);return r===null?_F:{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:Y(e.source,[`root`])}),_F};function AF(){return{required:!0,json:{type:`object`,propertyNames:{pattern:T_.source},additionalProperties:{$ref:gF}},parse:(e,t,n,r)=>{let i=r[n];if(!OD(i))return e.issues.push({path:`${t}.${n}`,message:`"rows" must be an object of row name → layout node, got ${kD(i)}`,line:Y(e.source,[...t.split(`.`),n])}),{};let a={};for(let[r,o]of Object.entries(i)){if(!T_.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:Y(e.source,[...t.split(`.`),n,r])});continue}a[r]=kF(e,`${t}.${n}.${r}`,o)}return a}}}const jF={noun:`root key`,fields:{rows:AF(),when:VD(),distribution:CF()}};function MF(e,t,n){return OD(n)&&`rows`in n?AD(e,jF,t,n)??{rows:{}}:kF(e,t,n)}function NF(){return{required:!0,json:{type:`string`,pattern:T_.source},parse:(e,t,n,r)=>{let i=r[n];if(typeof i!=`string`||!T_.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 "${ur}", got ${Z(i)}`,line:Y(e.source,[`root`])});return}return i}}}function PF(){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 ${Z(i)}`,line:Y(e.source,[`root`])});return}return i}}}}function FF(){return{required:!0,json:{type:`string`,pattern:`^[^\\n\\r]*$`},parse:(e,t,n,r)=>{let i=CD(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:Y(e.source,[...t.split(`.`),n])});return}return i}}}}const IF={noun:`layout-node key`,fields:{kind:vF(`group`),name:NF(),label:FF(),open:HD(),direction:YD(qg),key:PF(),bg:VD(),fg:VD(),when:VD(),distribution:CF(),children:xF(zD(()=>kF))}};function LF(e){return e.key??`groups.`+e.name}function RF(e){let t=eD+e.name;return hr(t,{variable:t,key:LF(e),member:e.name},{kind:`container`,direction:e.direction??`vertical`,children:e.children,...e.distribution!==void 0&&{distribution:e.distribution}},`drop`,e.when)}function zF(e,t,n){e.issues.push({path:t,message:n,line:Y(e.source,[`root`])})}function BF(e,t){oD(e,t,eD,`group nodes`);let n=e.groups;if(n.length===0)return;let r=new Set;for(let t of n)r.has(t.name)&&zF(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}.`)&&LF(t)===LF(r)&&zF(e,t.path,`group "${t.name}" shares key "${LF(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=LF(t);if(i.has(n)||i.set(n,ur),t.open===!0){let r=i.get(n);r!==`closed`&&zF(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=eD+e.name,r=LF(e),c=n.filter(t=>t!==e&&e.path.startsWith(t.path+`.`)).length,l=` `.repeat(c);a[t]=xr(r,i.get(r)),o[t]=Sr(r,e.name),s[t]={template:vr(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 VF=`menu`,HF=`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`,UF=e=>e.kind===`call`&&e.name===`dict`,WF=e=>e.kind===`literal`&&typeof e.value!=`object`,GF=e=>fr(``,e,2)===void 0;function KF(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&&UF(i)?i:void 0,o=a===void 0?r:r.slice(0,-1);if(o.some(UF))return t(`whose options (dict …) is not its last argument — ${HF}`);if(i!==void 0&&a===void 0&&!WF(i)&&GF(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=fr(`whose trigger`,o.length,2);if(s!==void 0)return t(`${s} — ${HF}`);let c=a===void 0?{}:mS(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=hD(c)}catch(e){return t(`with invalid options — ${e.message}`)}let u=l.key;if(u!==void 0){let e=aD(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 "${lD(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 qF(e){let t=Cb({fromString:e=>e});try{return t.parse(e).referencedCalls().filter(e=>e.name===VF).map(KF)}catch{return`parse-failed`}}function JF(e){let t=Cb({fromString:e=>e});try{return t.parse(e).referencedFunctions().has(VF)}catch{return!1}}function YF(e,t,n){e.issues.push({path:t,message:n,line:Y(e.source,[`root`])})}function XF(e,t){oD(e,t,tD,`{{ menu }} helpers`);for(let[n,r]of Object.entries(t.helpers??{}))JF(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:Y(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`&&JF(i)&&YF(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 $g(M_(t.root)))typeof n.when==`string`&&JF(n.when)&&YF(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||!JF(r))continue;let n=qF(r);if(n!==`parse-failed`)for(let r of n){let n=r.kind===`issue`?r.message:ZF(r.apply);n!==void 0&&YF(e,`segments.${t}`,`segment "${t}" has a {{ menu }} ${n}.`)}}}function ZF(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(sD(e)===`closed`)return`whose apply action is named "${ur}", which collides with the menu's closed-state sentinel and leaves it unopenable. Rename the action`}function QF(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 R_(e.presets)){let a=new Map,s=new Map;for(let c of $g(V_(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,qF(t.template));let l=i.get(c.name);if(l===`parse-failed`)continue;let u=Yg(c);for(let[e,t]of l.entries()){if(t.kind===`issue`||ZF(t.apply)!==void 0)continue;let{apply:i,options:l}=t,d=sD(i),f=cD(u,i,l.key),p=dD(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=uD(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]=Sr(f,d),n[f]=xr(f,ur),n[p]={kind:`state`,key:p,default:`0`},r[p]={set:p,int:!0}}}}return{...e,variables:{...e.variables,...n},actions:{...e.actions,...r}}}const $F=[`set`,`persist`,`copy`,`open`,`reset`,`undo`,`redo`,`back`,`rewind`,`save`,`preset`,`themeDefault`,`doctor`,`ceiling`,`slash`,`do`];function eI(e){return e.ceiling===`set`?[`set`,e.to]:[`clear`]}function tI(e){return`from`in e||`int`in e||`insertSegmentFrom`in e}function nI(e,t){if(t===void 0)return{};if(!OD(t))return Q(e,`actions`,`actions must be an object, got ${kD(t)}`),{};let n=Object.create(null);for(let[r,i]of Object.entries(t)){let t=rI(e,`actions.${r}`,i);t!==null&&(n[r]=t)}return n}function Q(e,t,n){e.issues.push({path:t,message:n,line:Y(e.source,t.split(`.`))})}function rI(e,t,n){if(!OD(n))return Q(e,t,`${t} must be an action object, got ${kD(n)}`),null;if(`persistWhen`in n)return Q(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 r=$F.filter(e=>e in n);return r.length===1?iI[r[0]](e,t,n):(Q(e,t,`action must declare exactly one of: ${$F.join(`, `)}${r.length>1?` (found: ${r.join(`, `)})`:``}`),null)}const iI={set:(e,t,n)=>RI(e,t,n,`set`,PI),persist:(e,t,n)=>RI(e,t,n,`persist`,FI),copy:aI(`copy`),open:aI(`open`),reset:oI,undo:cI(`undo`),redo:cI(`redo`),back:cI(`back`),rewind:cI(`rewind`),save:cI(`save`),preset:lI,themeDefault:uI,doctor:fI,ceiling:pI,slash:mI,do:hI};function aI(e){return(t,n,r)=>{for(let i of Object.keys(r))i!==e&&Q(t,`${n}.${i}`,`Unknown key "${i}" on a ${e} action. Expected only: ${e}`);let i=CD(t,n,r,e);return i===null?null:{[e]:i}}}function oI(e,t,n){for(let r of Object.keys(n))r!==`reset`&&Q(e,`${t}.${r}`,`Unknown key "${r}" on a reset action. Expected only: reset`);let r=gI(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 sI={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 cI(e){return(t,n,r)=>{for(let i of Object.keys(r))i!==e&&Q(t,`${n}.${i}`,`Unknown key "${i}" on a ${e} action. Expected only: ${e}`);return r[e]===!0?{[e]:!0}:(Q(t,`${n}.${e}`,`${e} must be the literal true (it takes no key — ${sI[e]}), got ${Z(r[e])}`),null)}}function lI(e,t,n){let r=n.preset,i=r===`save`?[`preset`]:[`preset`,`name`];for(let r of Object.keys(n))i.includes(r)||Q(e,`${t}.${r}`,`Unknown key "${r}" on a preset action. Expected only: ${i.join(`, `)}`);if(r!==`save`&&r!==`delete`)return Q(e,`${t}.preset`,`preset must be "save" or "delete", got ${Z(r)}`),null;if(r===`save`)return{preset:`save`};let a=CD(e,t,n,`name`);return a===null?null:{preset:`delete`,name:a}}function uI(e,t,n){for(let r of Object.keys(n))r!==`themeDefault`&&Q(e,`${t}.${r}`,`Unknown key "${r}" on a themeDefault action. Expected only: themeDefault`);return n.themeDefault===`save`?{themeDefault:`save`}:(Q(e,`${t}.themeDefault`,`themeDefault must be "save" (it saves the look the session draws as the active theme's default), got ${Z(n.themeDefault)}`),null)}const dI={run:[`doctor`],fix:[`doctor`,`check`],mark:[`doctor`,`check`,`mark`]};function fI(e,t,n){let r=n.doctor,i=typeof r==`string`&&Object.hasOwn(dI,r),a=i?dI[r]:[...new Set(Object.values(dI).flat())];for(let r of Object.keys(n))a.includes(r)||Q(e,`${t}.${r}`,`Unknown key "${r}" on a doctor action. Expected only: ${a.join(`, `)}`);if(!i)return Q(e,`${t}.doctor`,`doctor must be ${Object.keys(dI).map(e=>`"${e}"`).join(`, `)}, got ${Z(r)}`),null;if(r===`run`)return{doctor:`run`};let o=n.check,s=r===`mark`?VA:BA;if(typeof o!=`string`||!s.some(e=>e.name===o))return Q(e,`${t}.check`,`doctor ${r} must name a check (have: ${s.map(e=>e.name).join(`, `)}), got ${Z(o)}`),null;if(r===`fix`)return{doctor:`fix`,check:o};let c=n.mark;return eA.includes(c)?{doctor:`mark`,check:o,mark:c}:(Q(e,`${t}.mark`,`doctor mark must be ${eA.map(e=>`"${e}"`).join(` or `)}, got ${Z(c)}`),null)}function pI(e,t,n){let r=n.ceiling,i=r===`clear`?[`ceiling`]:[`ceiling`,`to`];for(let r of Object.keys(n))i.includes(r)||Q(e,`${t}.${r}`,`Unknown key "${r}" on a ceiling action. Expected only: ${i.join(`, `)}`);if(r===`clear`)return{ceiling:`clear`};if(r!==`set`)return Q(e,`${t}.ceiling`,`ceiling must be "set" or "clear", got ${Z(r)}`),null;let a=n.to;return typeof a!=`string`||a.trim()===``?(Q(e,`${t}.to`,`ceiling set needs \`to\`: a memento ceiling value such as "+100_000", "400000" or "off", got ${Z(a)}`),null):{ceiling:`set`,to:a}}function mI(e,t,n){for(let r of Object.keys(n))r!==`slash`&&Q(e,`${t}.${r}`,`Unknown key "${r}" on a slash action. Expected only: slash`);let r=uj(n.slash);return r.kind===`refused`?(Q(e,`${t}.slash`,r.reason),null):{slash:r.line}}function hI(e,t,n){for(let r of Object.keys(n))r!==`do`&&Q(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===``)?(Q(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 ${Z(r)}`),null):{do:r}}function gI(e,t,n,r,i,a){let o=CD(e,t,r,n);if(o===null)return null;let s=`${t}.${n}`;return o===``?(Q(e,s,i),null):o.includes(`/`)?(Q(e,s,a(o)),null):o}const _I={set:`the SessionState key to write`,persist:`the config globals field to write`};function vI(e,t,n,r){let i=_I[r],a=gI(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 yI(e){return e===`set`?`set-state`:`set-config`}const bI={to:zI(`set`)},xI={to:zI(`persist`)},SI={from:BI(`set`)},CI={from:BI(`persist`)},wI={min:GI(),max:GI(),by:GI()},TI={int:HI()},EI={cycle:VI(`set`)},DI={cycle:VI(`persist`)},OI={removeSegment:UI(`removeSegment`)},kI={insertSegment:UI(`insertSegment`),anchor:UI(`anchor`),relation:WI()},AI={insertSegmentFrom:BI(`persist`),anchor:UI(`anchor`),relation:WI()},jI={ok:e=>e.min<e.max,issue:e=>({field:`min`,message:`min (${e.min}) must be less than max (${e.max})`})},MI={ok:e=>e.by!==0,issue:()=>({field:`by`,message:`by must be a non-zero integer (the per-click increment; negative steps down)`})};function NI(e,t,n=[],r){let i=Object.keys(t),a=r??i,o=[e],s=(e,n,r)=>MD(e,t,n,r),c=XD(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?BD(s,...n):s}}const PI=[NI(`set`,bI),NI(`set`,SI),NI(`set`,wI,[jI,MI]),NI(`set`,TI),NI(`set`,EI)],FI=[NI(`persist`,xI),NI(`persist`,CI),NI(`persist`,wI,[jI,MI]),NI(`persist`,DI),NI(`persist`,OI),NI(`persist`,kI,[],[`insertSegment`]),NI(`persist`,AI,[],[`insertSegmentFrom`])];function II(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 LI(e){let t=II(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 RI(e,t,n,r,i){let a=vI(e,t,n,r),o=i.filter(e=>e.detect.some(e=>e in n));if(o.length!==1)return Q(e,t,`${LI(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)||Q(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 zI(e){let t=yI(e);return{required:!0,json:{type:`string`},parse:(n,r,i,a)=>gI(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 BI(e){let t=yI(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===``){Q(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){Q(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===``)){Q(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){Q(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){Q(n,s,`${i} array members must be unique — a duplicated value would render the same picker option twice`);return}return r}Q(n,s,`${i} must be a domain name (a string) or an inline domain (an array of strings), got ${Z(o)}`)}}}function VI(e){let t=yI(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`)){Q(n,s,`cycle must be an array of strings (the enumerated values a click steps through), got ${kD(o)}`);return}let c=o;if(c.length<2){Q(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){Q(n,s,`cycle members must be non-empty — an empty value cannot be delivered on the ${t} wire`);return}if(u.length>0){Q(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){Q(n,s,`cycle members must be unique — the successor of a duplicated member is ambiguous`);return}return c}}}function HI(){return{required:!0,json:{const:!0},parse:(e,t,n,r)=>{if(r[n]!==!0){Q(e,`${t}.${n}`,`int must be the literal true (declares the key an unbounded integer cursor — a paged picker's page key), got ${Z(r[n])}`);return}return!0}}}function UI(e){return{required:!0,json:{type:`string`},parse:(t,n,r,i)=>{let a=CD(t,n,i,r);if(a===null)return;let o=`${n}.${r}`;if(a===``){Q(t,o,`${e} must be non-empty (a segment name)`);return}if(a.includes(`/`)||a.includes(`:`)){Q(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 WI(){return{required:!0,json:{enum:[`before`,`after`]},parse:(e,t,n,r)=>{let i=r[n];if(i!==`before`&&i!==`after`){Q(e,`${t}.${n}`,`relation must be "before" or "after", got ${Z(i)}`);return}return i}}}function GI(){return{required:!0,json:{type:`integer`},parse:(e,t,n,r)=>{let i=r[n];if(typeof i!=`number`||!Number.isInteger(i)){Q(e,`${t}.${n}`,`${n} must be an integer, got ${Z(i)}`);return}return i}}}function KI(e,t,n){return`${e}: "${t}" is an endcaps shape, not a style — endcaps were renamed from "style" to "endcaps"; write ${n}: "${t}"`}const qI={noun:`style key`,fields:{hueShift:WD(),chromaScale:WD({min:0}),lightnessScale:WD(),lightnessShift:WD()}};function JI(e,t){if(!OD(t))return e.issues.push({path:`styles`,message:`styles must be an object mapping style names to adaptation objects, got ${kD(t)}`,line:Y(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:Y(e.source,[`styles`,r])});continue}if(xh(r)){e.issues.push({path:`styles.${r}`,message:KI(`styles.${r}`,r,`globals.endcaps`),line:Y(e.source,[`styles`,r])});continue}let t=AD(e,qI,`styles.${r}`,i);t!==null&&(n[r]={...As,...t})}return n}const YI={noun:`preset key`,fields:{root:{required:!1,json:{$ref:`#/definitions/RootFragment`},parse:(e,t,n,r)=>r[n]===void 0?void 0:MF(e,`${t}.${n}`,r[n])},globals:{required:!1,json:kO(),parse:(e,t,n,r)=>r[n]===void 0?void 0:OO(e,`${t}.${n}`,r[n])}}};function XI(e,t){if(!OD(t))return e.issues.push({path:`presets`,message:`presets must be an object mapping preset names to config fragments, got ${kD(t)}`,line:Y(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:Y(e.source,[`presets`,r])});continue}let t=AD(e,YI,`presets.${r}`,i);t!==null&&(n[r]=t)}return n}function ZI(e,t){if(t===void 0)return{};if(!OD(t))return e.issues.push({path:`helpers`,message:`helpers must be an object, got ${kD(t)}`,line:Y(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 ${Z(i)}`,line:Y(e.source,[`helpers`,r])});continue}n[r]=i}return n}const QI=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 $I(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 eL(e){let t=QI.get(e);return t===void 0?void 0:`variables.${e} is no longer read: ${$I(t)}`}function tL(e){let t=QI.get(e);return t===void 0?``:` — ".${e}" is no longer a variable: ${$I(t)}; a "${t.segment}" template reads it as ".settings.${t.setting}"`}function nL(e,t){let n=new Map;for(let e of Object.keys(t)){let t=JE(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:Y(e.source,[`presets`])})}function rL(e,t,n){let r=[[[`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,i,a]of r){if(i===void 0||rh(i)||Object.prototype.hasOwnProperty.call(t.styles,i))continue;let r=`${n.join(`.`)}.style`;e.issues.push({path:r,message:xh(i)?KI(r,i,a):`${r} "${i}" does not match any declared style (have: ${Object.keys(t.styles).join(`, `)})`,line:Y(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:Y(e.source,[`globals`,`preset`])}),nL(e,t.presets);let i=_v(t);for(let t of i.names)t!==`settings`&&!t.startsWith(oL)||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:Y(e.source,[`variables`,t])});let a=(t,n,r)=>{UM(t)>1&&e.issues.push({path:n,message:`${n} places the global settings menu anchor "${Sj}" ${UM(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:r}),WM(t)&&e.issues.push({path:n,message:`${n} places the global settings menu anchor "${Sj}" 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:r}),o(t)&&e.issues.push({path:n,message:`${n} sets "distribution" on a container inside a bar cell — everything inside a cell wears that cell's hue and shade, so it would place nothing. Set it on the row whose children are the cells (the horizontal container) or on the root, which places the rows.`,line:r});let i=new Map;for(let e of $g(t)){if(e.kind!==`segment`)continue;let t=Yg(e);i.set(t,[...i.get(t)??[],e])}for(let[t,a]of i){if(a.length<2)continue;let o=a[1].name,s=Zg(o,new Set(i.keys()));e.issues.push({path:n,message:`${n} has ${a.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: "${o}", id: "${s}" }. A placement without an "id" takes its segment's name.`,line:r})}};function o(e,t=!1){return e.kind===`segment`?!1:t&&e.distribution!==void 0||e.children.some(n=>o(n,t||Jg[e.direction]===`cell`))}let s=(n,r)=>{for(let[a,o]of N_(n,r)){let n=Y(e.source,o.split(`.`));if(a.when!==void 0&&(vL(e,`${o}.when`,a.when,i,{line:n}),_L(e,`${o}.when`,a.when,n)),a.kind===`segment`){if(BM(a.name)){(a.id!==void 0||a.settings!==void 0)&&e.issues.push({path:o,message:`${r} gives the global settings menu anchor "${Sj}" an id or settings — the anchor only marks where the menu goes, so place it as the bare name "${Sj}"`,line:n});continue}Object.prototype.hasOwnProperty.call(t.segments,a.name)||e.issues.push({path:o,message:`${r} entry "${a.name}" does not match any declared segment${GP(a.name)}`,line:n}),mL(e,t,a,o,n)}}};n.root!==void 0&&s(n.root,`root`);for(let[e,t]of Object.entries(n.presets??{}))t.root!==void 0&&s(t.root,`presets.${e}.root`);let c=new Map([[`root`,j_(t.root)]]);for(let e of R_(t.presets)){let{node:n,path:r}=V_(t,e);c.set(r,n)}for(let[t,n]of c)a(n,t,Y(e.source,t.split(`.`)));TL(e,t,i,()=>!0)}const iL=[`removeSegment`,`insertSegment`,`insertSegmentFrom`];function aL(e,t,n,r,i,a,o){let s=`actions.${n}.${r}`,c=Y(e.source,[`actions`,n,r]);if(!R_(t.presets).includes(a)){e.issues.push({path:s,message:`actions.${n}: "${i}" names preset "${a}" which is not declared (have: ${R_(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(`, `)})${GP(i)}`,line:c})},p=new Set(Xg(V_(t,a).node)),m=(r,i)=>{!WP.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${GP(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 oL=`settings.`;function sL(e,t){return{...e,names:new Set([...e.names,...Object.keys(t).map(e=>oL+e)])}}function cL(e,t,n){let r=e=>`segments.${t}.settings.${e}`,i=(n,i)=>{e.issues.push({path:r(n),message:`${r(n)}: ${i}`,line:Y(e.source,[`segments`,t,`settings`,n])})},a=dL(n);for(let{setting:e,message:t}of a)i(e,t);if(!(a.length>0))for(let{setting:e,message:t}of __(n,uL(n)))i(e,`the defaults do not stand together: ${t}`)}function lL(e){return dL(e).length>0||__(e,uL(e)).length>0}function uL(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.default]))}function dL(e){let t=t=>g_(fL(e,t))?.atLeast;return Object.keys(e).flatMap(n=>{let r=t(n);if(r===void 0)return[];if(r===n||g_(fL(e,r))===void 0)return[{setting:n,message:`atLeast "${r}" must name another range setting of this segment (its range settings: ${pL(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 fL(e,t){return Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}function pL(e,t){return Object.entries(e).filter(([e,n])=>e!==t&&g_(n)!==void 0).map(([e])=>e)}function mL(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=h_(a),s=`${r}: placement "${Yg(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(`, `)})`:v_(c,a)?void 0:`sets "${t}" to ${JSON.stringify(a)}${c.domain===`theme`?Jm(a):``}, but it must be ${S_(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])=>v_(o[e],t))||lL(o)))for(let{message:t}of __(o,c))e.issues.push({path:r,message:`${s}: ${t}`,line:i})}function hL(e,t,n,r,i){n.kind===`template`&&vL(e,`${t}.template`,n.template,r,{segCtx:i}),s_(n)&&`key`in n.cache&&vL(e,`${t}.cache.key`,n.cache.key,r,{segCtx:i})}function gL(e,t,n,r,i){if(!(!s_(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:Y(e.source,[...t.split(`.`),`cache`,`depends_on`])})}}function _L(e,t,n,r){try{XO.parse(n)}catch(n){e.issues.push({path:t,message:`Template parse error in ${t}: ${n.message}`,line:r})}}function vL(e,t,n,r,i){for(let[a,o]of lv(n,r.helpers)){if(gv(a,r))continue;if(a.startsWith(oL)){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??Y(e.source,t.split(`.`))});continue}if(o!==null){yL(e,o,`Template references unknown variable ".${a}"${tL(a)}`);continue}let n=i?.segCtx===void 0?void 0:`${i.segCtx}.${a}`,s=n!==void 0&&gv(n,r)?` (segment-local vars are namespaced — write ".${n}")`:tL(a);e.issues.push({path:t,message:`Template references unknown variable ".${a}"${s}`,line:i?.line??Y(e.source,t.split(`.`))})}}function yL(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:Y(e.source,[`helpers`,t])})}function bL(e,t,n,r,i){let a=n.set,o=pO(Ba[r].configKey),s=`${a} takes ${vD(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:Y(e.source,[`actions`,t,`min`])});return}let c=CL(n,i);if(c===SL){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:Y(e.source,[`actions`,t,`int`])});return}let l=c.filter(e=>!_D(o,e.value,i));if(l.length!==0){if(a===Ba.style.sessionKey&&(`from`in n&&n.from===`endcaps`||c.every(e=>xh(e.value)))){let r=Ba.endcaps.sessionKey;e.issues.push(`to`in n?{path:`actions.${t}.to`,message:KI(`actions.${t}.to`,n.to,`set: "${r}", to`),line:Y(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:Y(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<=xL?r.join(`, `):`${r.slice(0,xL).join(`, `)} and ${r.length-xL} 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:Y(e.source,[`actions`,t,n])})}}}const xL=3,SL=Symbol(`any integer`);function CL(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?J_(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)}]:SL}function wL(e,t){return Object.entries(e).filter(([e])=>t(e))}function TL(e,t,n,r){let i=vN(t),a=q_(i);for(let[n,o]of wL(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 ${X_(r,i)}`,line:Y(e.source,[`actions`,n,t])});continue}if(!(`set`in o))continue;Ua.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:Y(e.source,[`actions`,n,`set`])});let s=qa.get(o.set);s!==void 0&&bL(e,n,o,s,i)}for(let[n,i]of wL(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&&tI(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:Y(e.source,[`actions`,n,`do`])})});for(let[n,i]of wL(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=GO(r);if(o===null){let t=NO(r);e.issues.push({path:`actions.${n}.${a}`,message:t===void 0?`actions.${n}: "${r}" is not a config globals field (have: ${PO().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:Y(e.source,[`actions`,n,a])});continue}let s=iL.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:Y(e.source,[`actions`,n,a])});continue}if(o.scope===`preset-root`){aL(e,t,n,a,r,o.preset,i);continue}if(o.scope===`preset-globals`&&!R_(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: ${R_(t.presets).join(`, `)})`,line:Y(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${Jm(o.theme)} (have: ${[...e.allowedPalettes].sort().join(`, `)})`,line:Y(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(`, `)})${GP(o.segment)}`,line:Y(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:Y(e.source,[`actions`,n,a])})}}for(let[i,a]of wL(t.variables,r)){hL(e,`variables.${i}`,a,n);let t=eL(i);t!==void 0&&e.issues.push({path:`variables.${i}`,message:t,line:Y(e.source,[`variables`,i])})}for(let[i,a]of wL(t.segments,r)){if(a.vars)for(let[t,r]of Object.entries(a.vars))hL(e,`segments.${i}.vars.${t}`,r,n,i);let r=h_(a);cL(e,i,r);let o=sL(n,r);for(let n of[`template`,`bg`,`fg`,`when`]){let s=a[n];if(typeof s==`string`){vL(e,`segments.${i}.${n}`,s,o,{segCtx:i,settings:r});for(let{name:r,site:a,via:o}of pv(s,t.helpers)){if(Object.prototype.hasOwnProperty.call(t.actions,r))continue;let s=a===`options`?` (in a picker, menu, carousel, swatch, swatches or themePreview)`:``;if(o!==null){yL(e,o,`Template references unknown action "${r}"${s}`);continue}e.issues.push({path:`segments.${i}.${n}`,message:`${n} references unknown action "${r}"${s}`,line:Y(e.source,[`segments`,i,n])})}}}}for(let[i,a]of wL(t.variables,r))gL(e,`variables.${i}`,a,n);for(let[i,a]of wL(t.segments,r))if(a.vars)for(let[t,r]of Object.entries(a.vars))gL(e,`segments.${i}.vars.${t}`,r,n,i)}function EL(e,t,n=()=>!0){let{graph:r,nodeInfo:i}=DL(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:Y(e.source,a?.linePathParts??[`variables`,r])}),!0}if(t===0&&s(c))return!0}return a.set(t,2),o.pop(),!1}}function DL(e){let t=new Set(Object.keys(e.variables)),n=new Map;for(let t of Object.keys(e.variables))n.set(t,{declarationPath:`variables.${t}`,linePathParts:[`variables`,t]});for(let[r,i]of Object.entries(e.segments))if(i.vars)for(let e of Object.keys(i.vars)){let i=`${r}.${e}`;t.add(i),n.set(i,{declarationPath:`segments.${r}.vars.${e}`,linePathParts:[`segments`,r,`vars`,e]})}let r=new Map;for(let e of t)r.set(e,new Set);let i=(n,i)=>{for(let a of lv(i,e.helpers).keys()){if(t.has(a)){r.get(n).add(a);continue}let e=a.split(`.`)[0];e!==a&&t.has(e)&&r.get(n).add(e)}},a=(e,n)=>{if(n.kind===`template`&&i(e,n.template),s_(n)&&(`key`in n.cache&&i(e,n.cache.key),`depends_on`in n.cache))for(let i of n.cache.depends_on)t.has(i)&&r.get(e).add(i)};for(let[t,n]of Object.entries(e.variables))a(t,n);for(let[t,n]of Object.entries(e.segments))if(n.vars)for(let[e,r]of Object.entries(n.vars))a(`${t}.${e}`,r);return{graph:r,nodeInfo:n}}function OL(e){return e===`~`||e.startsWith(`~/`)||e.startsWith(`~\\`)?w.homedir()+e.slice(1):e}function kL(e,t){return v.resolve(e,OL(t))}function AL(e,t){return typeof t==`string`&&t!==``?kL(e,t):void 0}function jL(e){return`plugin ${e.path} was not loaded: ${e.reason}`}const ML=new Set([`data`,`segments`,`helpers`,`actions`]),NL=`plugin.json5`,PL=/^[a-z][a-z0-9_]*$/;function FL(e){let t=v.basename(v.dirname(e));return PL.test(t)?t:void 0}const IL=`plugins.`;function LL(e){return`${IL}${e}.data`}function RL(e){try{return{ok:!0,value:e()}}catch(e){return{ok:!1,reason:zL(e)}}}function zL(e){return e instanceof YE?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 BL(e,t){return e.map(e=>kL(v.dirname(t),e))}function VL(e,t,n,r){let i=new Map;return e.reduce((e,n)=>{let a=FL(n),o=(t,r)=>{let i=new Map(e.rendering);return a!==void 0&&r!==e.config&&i.delete(a),{...e,config:r,rendering:i,dropped:[...e.dropped,{path:n,plugin:a,reason:t}]}};if(v.basename(n)!==`plugin.json5`){let t=`a plugin is a folder holding its ${NL}, and the folder's name is the plugin's: move this file to <dir>/<name>/${NL} and list that`;return o(t,a===void 0?e.config:WL(UL(e.config,a),a,{path:n,plugin:a,reason:t}))}if(a===void 0)return o(`its folder "${v.basename(v.dirname(n))}" is not a plugin name (one matching ${PL}: it prefixes every name the plugin declares)`,e.config);let c=i.get(a);if(c!==void 0)return o(`plugin "${a}" is already listed, from ${c}`,e.config);i.set(a,n);let l=UL(e.config,a),u=RL(()=>{let i=s.readFileSync(n,`utf-8`),o=iP(XL(n,a,{source:i,json:Ar.default.parse(i)},t),l);return r(o,a,l!==e.config),o});if(u.ok)return{...e,config:u.value,loaded:[...e.loaded,n],rendering:new Map([...e.rendering,[a,n]])};let d={path:n,plugin:a,reason:u.reason};return o(u.reason,WL(l,a,d))},{config:n.config,rendering:n.rendering,loaded:[],dropped:[]})}function HL(e){let t=`${IL}${e}.`;return e=>e.startsWith(t)}function UL(e,t){let n=HL(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 WL(e,t,n){return{...e,variables:{...e.variables,[LL(t)]:{kind:`dropped`,reason:jL(n),definition:n.path}}}}function GL(e){return e.startsWith(`plugins.`)?e.slice(8).split(`.`)[0]:void 0}function KL(e,t){let n=new Set([...Object.keys(e.config.variables),...Object.keys(e.config.segments)].map(GL)),r=[...t,...e.dropped].filter(e=>e.plugin===void 0).map(e=>({definition:e.path,notice:jL(e)}));return t=>{let i=GL(t);if(i===void 0)return[];let a=e.config.variables[LL(i)];return a?.kind===`dropped`?[{definition:a.definition,notice:a.reason}]:n.has(i)?[]:r}}function qL(e,t){let n=R_(e.presets).flatMap(t=>[...$g(V_(e,t).node)]).flatMap(e=>e.kind===`segment`?[e]:[]),r=[...new Set([...n.map(e=>e.name),...Object.keys(e.segments)])].map(e=>({name:e,cause:t(e)})).filter(({cause:e})=>e.length>0),i=Object.fromEntries(r.map(({name:e,cause:t})=>[e,JL(e,t.map(e=>e.notice),n.filter(t=>t.name===e))])),a=t=>{let n=GL(t),r=n===void 0?void 0:e.variables[LL(n)];return r?.kind===`dropped`?{definition:r.definition,notice:r.reason}:void 0},o=Object.values(e.variables).some(e=>e.kind===`dropped`),s=o?Object.values(e.segments).flatMap(e=>[`template`,`bg`,`fg`,`when`].flatMap(t=>e[t]===void 0?[]:[e[t]])):[],c=o?Object.values(e.actions).flatMap(e=>`do`in e?[...e.do]:[]):[],l=(e,t)=>[...new Set(e)].flatMap(e=>{let n=e in t?void 0:a(e);return n===void 0?[]:[[e,n]]}),u=l([...s.flatMap(t=>pv(t,e.helpers).map(e=>e.name)),...c],e.actions),d=l(s.flatMap(t=>[...hv(t,e.helpers)]),e.helpers),f=new Set([...r.flatMap(({cause:e})=>e.map(e=>e.definition)),...[...u,...d].map(([,e])=>e.definition)]);return{config:{...e,segments:{...e.segments,...i},actions:{...e.actions,...Object.fromEntries(u.map(([e])=>[e,{copy:`{{ .${LL(GL(e)??``)} }}`}]))},helpers:{...e.helpers,...Object.fromEntries(d.map(([e,t])=>[e,`{{ fail ${JSON.stringify(t.notice)} }}`]))}},reached:f}}function JL(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,YL(e,t)]));return{template:`{{ ${JSON.stringify(r)} }}`,bg:`error`,description:`stands in for a segment whose plugin did not load`,settings:a}}function YL(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 XL(e,t,{source:n,json:r},{checkout:i}){let a=[],o=()=>{throw new YE(e,a)};if(!OD(r))return a.push({path:``,message:`a plugin definition must be an object, got ${kD(r)}`}),o();for(let e of Object.keys(r))ML.has(e)||a.push({path:e,message:e===`plugin`?`a plugin definition does not name itself: its name is its folder's ("${t}") — remove "plugin"`:`a plugin definition may not declare "${e}". Expected only: ${[...ML].join(`, `)}`});let s=nR(r.data,e,i,a);if(OD(r.segments)||a.push({path:`segments`,message:`"segments" must be an object naming the plugin's segments`}),a.length>0||s===void 0)return o();let c={source:n,issues:a,allowedPalettes:new Set(Zm()),groups:[]},l=hP(c,`data`,{[LL(t)]:{kind:`file`,path:s,parse:{json:!0},cache:{watch_file:s},default:{}}});for(let[e,t]of Object.entries(r.segments))if(!(!OD(t)||!OD(t.vars)))for(let[n,r]of Object.entries(t.vars)){let t=OD(r)?r.kind:void 0;typeof t!=`string`||t===`state`||a.push({path:`segments.${e}.vars.${n}`,message:`a plugin segment's vars may declare only state variables (kind: "state"), never a source such as ${JSON.stringify(t)}: a plugin's only source is its data file`})}let u={variables:l,segments:QL(t,eR(t,lF(c,r.segments,new Set))),helpers:QL(t,ZI(c,r.helpers)),actions:QL(t,tR(t,nI(c,r.actions)))};for(let[e,t]of ZL(u))try{XO.parse(t)}catch(t){a.push({path:e,message:`Template parse error in ${e}: ${t.message}`})}return a.length>0&&o(),u}function*ZL(e){for(let[t,n]of Object.entries(e.segments??{}))for(let e of[`template`,`bg`,`fg`,`when`]){let r=n[e];r!==void 0&&(yield[`segments.${t}.${e}`,r])}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??{}))`copy`in n&&(yield[`actions.${t}.copy`,n.copy]),`open`in n&&(yield[`actions.${t}.open`,n.open]),`preset`in n&&n.preset===`delete`&&(yield[`actions.${t}.name`,n.name])}function QL(e,t){return Object.fromEntries(Object.entries(t).map(([t,n])=>[`${IL}${e}.${t}`,n]))}function $L(e,t){return`${IL}${e}.${t}`}function eR(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,n.kind===`state`?{...n,key:$L(e,n.key)}:n]))}]))}function tR(e,t){return Object.fromEntries(Object.entries(t).map(([t,n])=>[t,`set`in n?{...n,set:$L(e,n.set)}:n]))}function nR(e,t,n,r){if(typeof e==`string`&&e!==``)return kL(v.dirname(t),e);if(OD(e)&&Object.keys(e).length===1&&typeof e.checkout==`string`&&e.checkout!==``){let t=e.checkout;if(v.isAbsolute(t)||t.startsWith(`~`)||v.normalize(t).split(v.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 v.resolve(n.root,t)}if(OD(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 rR(e){let t=[...[...(process.env.XDG_DATA_DIRS||oR()).split(`:`).filter(e=>e!==``)].reverse().map(e=>v.join(e,`cc-candybar`,`plugins`)),iR(),...e===null?[]:[v.join(e,aR)]];return t.filter((e,n)=>t.lastIndexOf(e)===n)}function iR(){let e=process.env.XDG_DATA_HOME||v.join(w.homedir(),`.local`,`share`);return v.join(e,`cc-candybar`,`plugins`)}const aR=v.join(`.cc-candybar`,`plugins`);function oR(){let e=`/usr/local/share:/usr/share`;return process.platform===`darwin`?`${v.join(process.env.HOMEBREW_PREFIX||`/opt/homebrew`,`share`)}:${e}`:e}function sR(e){let t=rR(e),n=new Map,r=[],i=[];for(let e of t){let t=cR(e);if(`error`in t){r.push(t);continue}for(let r of t.folders)n.delete(r),n.set(r,v.join(e,r,NL));for(let n of t.files)i.push({path:v.join(e,n),plugin:void 0,reason:`a plugin is a folder holding its ${NL}: move this file to ${v.join(e,`<name>`,NL)}`})}return{roots:t,definitions:[...n.values()],unchecked:r,strays:i}}function cR(e){try{let t=s.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()||lR(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 lR(e,t){if(!t.isSymbolicLink())return!1;try{return s.statSync(v.join(e,t.name)).isDirectory()}catch{return!0}}const uR=[`json5`,`json`];function dR(e){try{return s.statSync(e,{throwIfNoEntry:!1})===void 0?`absent`:`present`}catch(t){return{path:e,error:t.message}}}function fR(e,t,n){if(n!==void 0)return[n];let r=t??process.cwd();return[...new Set([...e?uR.map(t=>v.join(e,`.cc-candybar.${t}`)):[],...uR.map(e=>v.join(r,`.cc-candybar.${e}`)),...uR.map(e=>`${pR()}.${e}`)])]}function pR(){let e=process.env.XDG_CONFIG_HOME??v.join(w.homedir(),`.config`);return v.join(e,`cc-candybar`,`config`)}function mR(e,t,n){let r=[],i=new Map;for(let a of fR(e,t,n)){let e=dR(a);if(e===`absent`)continue;if(e!==`present`){r.push(e);continue}let t=v.join(s.realpathSync(v.dirname(a)),v.basename(a).replace(/\.(json5|json)$/,``));i.has(t)||i.set(t,a)}let a=[...i.values()].reverse();if(n===void 0)return{kind:`chain`,layers:a,home:hR(a),unchecked:r};let[o]=r,c=n;return a.length>0?{kind:`chain`,layers:a,home:c,unchecked:r}:o===void 0?{kind:`missing`,path:n,home:c}:{kind:`unreadable`,...o,home:c}}function hR(e){let t=pR();return e.find(e=>uR.some(n=>e===`${t}.${n}`))??`${t}.${uR[0]}`}function gR(e,t,n){let r=mR(e,t,n),i=r.kind===`chain`?r.layers:[];return{path:r.home,above:i.filter(e=>e!==r.home),projectDir:e??null,cwd:t??null}}function _R(e){return vR(e).join(`
|
|
174
|
+
`)||null}function vR(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 yR(e,t){let n=fR(e,t).filter(e=>dR(e)===`present`),r=new Map;for(let e of n){let t=v.dirname(e),n=v.basename(e).replace(/\.(json5|json)$/,``),i=v.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 bR(e,t,n,r){return e===null?{...AR,config:iP(AR.raw,t)}:SR(e,s.readFileSync(e,`utf-8`),t,n,r)}const xR={projectDir:null,checkout:null,beneath:{dropped:[],rendering:new Map}};function SR(e,t,n,r,i){let a=NR(e,t,i,(t,a)=>{let o=VL(BL(t,e),r,{config:n,rendering:r.beneath.rendering},(t,n,r)=>OR(t,n,r,e,i)),s=KL(o,r.beneath.dropped);return{inherited:new Set([...cF(o.config),...a.filter(e=>s(e).length>0)]),layer:{plugins:o,owning:s}}}),{plugins:o,owning:s}=a.layer,c=qL(iP(a.raw,o.config),s);return{source:t,raw:a.raw,warnings:[...a.warnings,...o.dropped.map(jL)],plugins:{loaded:o.loaded,dropped:o.dropped,reached:c.reached,rendering:o.rendering},config:c.config}}const CR=new WeakMap;function wR(e,t,n,r){let i=JSON.stringify([[...r??[]].sort(),e.map(e=>[e,ER(e)])]),a=CR.get(n)??new Map;CR.set(n,a);let o=JSON.stringify([t.projectDir,t.checkout?.root??null]),s=a.get(o);if(s?.key===i)return s.layer;let c=VL(e,t,{config:n,rendering:new Map},(e,t,n)=>OR(e,t,n,`<installed plugins>`,r));return a.set(o,{key:i,layer:c}),c}function TR(e,t,n){return VL(e,{projectDir:null,checkout:n},{config:t,rendering:new Map},(e,t,n)=>OR(e,t,n,`<plugin install>`,void 0)).dropped}function ER(e){try{let t=s.statSync(e);return`${t.ino}:${t.size}:${t.mtimeMs}`}catch(e){return e.code??`unreadable`}}function DR(e,t,n,r,i=e=>s.readFileSync(e,`utf-8`),a){let o={projectDir:r.projectDir,checkout:r.cwd===null?null:ET(r.cwd)},c=sR(o.projectDir),l=wR(c.definitions,o,t,a),u={...l,dropped:[...l.dropped,...c.strays]};n.warned(c.unchecked.map(e=>`Plugin folder could not be listed: ${e.path} — ${e.error}`));let d=u.config,f=[];for(let t of e){n.entered(t);let e=f.at(-1)?.plugins,r=SR(t,i(t),f.at(-1)?.config??d,{...o,beneath:{dropped:[...u.dropped,...f.flatMap(e=>e.plugins.dropped)],rendering:e?.rendering??u.rendering}},a);n.warned(r.warnings),f.push({...r,path:t})}let p=new Set(f.flatMap(e=>[...e.plugins.reached])),m=e=>p.has(e.path),h=u.dropped.filter(m),g=u.dropped.filter(e=>!m(e));n.warned(h.map(jL));let _={checkout:o.checkout,roots:c.roots,loaded:u.loaded,dropped:h,unreached:g,reached:p,rendering:f.at(-1)?.plugins.rendering??u.rendering},v=f.at(-1);if(v===void 0)return{layers:f,base:d,installed:_,config:jR(bR(null,d,xR),`<default>`,a)};try{return{layers:f,base:d,installed:_,config:jR(v,v.path,a)}}catch(e){for(let e of f.slice(0,-1))n.entered(e.path),jR(e,e.path,a);throw n.entered(v.path),e}}function OR(e,t,n,r,i){if(n){jR(kR(e),r,i);return}let a=HL(t),o=[],s={source:``,issues:o,allowedPalettes:new Set,groups:[]};if(TL(s,e,_v(e),a),EL(s,e,a),o.length>0)throw new YE(r,o)}function kR(e){return{config:e,raw:{root:e.root,presets:e.presets},source:``}}const AR={raw:{},source:``,warnings:[],plugins:{loaded:[],dropped:[],reached:new Set,rendering:new Map}};function jR({config:e,raw:t,source:n},r=`<config>`,i=new Set(Zm())){let a=[],o={source:n,issues:a,allowedPalettes:i,groups:[]};if(rL(o,e,t),EL(o,e),a.length>0)throw new YE(r,a);let s=QF(e,a);if(a.length>0)throw new YE(r,a);return IN(nN(s))}function MR(e,t,n=new Set(Zm()),r=PR){return NR(e,t,n,()=>({inherited:r,layer:null})).raw}function NR(e,t,n,r){let i=FR(e,t),a=QE(e,t),o=a===null?[]:[a],s=[],c={source:t,issues:s,allowedPalettes:n??new Set(Zm()),groups:[]};if(!OD(i))throw new YE(e,[{path:``,message:`Config root must be an object, got ${kD(i)}`}],o);let{inherited:l,layer:u}=r(i.plugins===void 0?[]:RR({...c,issues:[]},i.plugins)??[],OD(i.segments)?Object.keys(i.segments):[]),d=IR(c,i,l);if(s.length>0)throw new YE(e,s,o);return{raw:d,warnings:o,layer:u}}const PR=new Set;function FR(e,t){try{return Ar.default.parse(t)}catch(t){let n=t;throw new YE(e,[{path:``,message:`JSON5 syntax error: ${n.message}`,line:n.lineNumber,col:n.columnNumber}])}}function IR(e,t,n){for(let n of Object.keys(t))LR.has(n)||e.issues.push({path:n,message:`Unknown top-level key "${n}". Expected one of: ${[...LR].join(`, `)}`,line:Y(e.source,[n])});let r={};return t.globals!==void 0&&(r.globals=DO(e,`globals`,t.globals)),t.variables!==void 0&&(r.variables=hP(e,`variables`,t.variables)),t.segments!==void 0&&(r.segments=lF(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.
|
|
175
175
|
Replace: layout: [["seg1", "seg2"], ["seg3"]]
|
|
176
176
|
With: root: { v: [{ h: ["seg1", "seg2"] }, "seg3"] }
|
|
177
|
-
Single-row example: root: { h: ["seg1", "seg2"] }`,line:Y(e.source,[`layout`])}),t.root!==void 0&&(r.root=DF(e,`root`,t.root)),t.actions!==void 0&&(r.actions=ZF(e,t.actions)),t.looks!==void 0&&e.issues.push({path:`looks`,message:`"looks" was renamed "styles" — move the block under styles: { … } (and globals.look to globals.style)`,line:Y(e.source,[`looks`])}),t.styles!==void 0&&(r.styles=UI(e,t.styles)),t.themeDefaults!==void 0&&(r.themeDefaults=DO(e,t.themeDefaults)),t.presets!==void 0&&(r.presets=GI(e,t.presets)),t.editGlobals!==void 0&&(r.editGlobals=jO(e,`editGlobals`,t.editGlobals)),t.helpers!==void 0&&(r.helpers=KI(e,t.helpers)),t.plugins!==void 0&&(r.plugins=NR(e,t.plugins)),FF(e,r),GF(e,r),uk(e,r),sD(e,r,X,`the global settings menu`),r}const MR=new Set([`globals`,`variables`,`segments`,`layout`,`looks`,`root`,`actions`,`styles`,`themeDefaults`,`presets`,`editGlobals`,`helpers`,`plugins`]);function NR(e,t){if(Array.isArray(t)&&t.every(e=>typeof e==`string`&&e!==``))return t;e.issues.push({path:`plugins`,message:`"plugins" must be a list of plugin definition paths, got ${AD(t)}`,line:Y(e.source,[`plugins`])})}const PR={},FR=lj(`commands.`),IR=hj(`autocompact.`,e=>`{{ template "formatTokenCount" ${e} }}`),LR=`trimPrefix "/" (trimPrefix .project_dir .current_dir)`,RR=`{{ \$dir := .current_dir }}{{ if and (ne .home "") (or (eq .home .current_dir) (hasPrefix (printf "%s/" .home) .current_dir)) }}{{ \$dir = printf "~%s" (trimPrefix .home .current_dir) }}{{ else }}{{ if or (eq .project_dir .current_dir) (hasPrefix (printf "%s/" .project_dir) .current_dir) }}{{ $dir = ternary (${LR}) (basename .project_dir) (ne (${LR}) "") }}{{ end }}{{ end }}{{ action "copyDir" (abbreviatePath \$dir) }}`,zR=`{{ ${Tk} }}`,BR={min:0,max:100,step:5},VR={warnAt:{label:`warning at %`,domain:BR,default:50},errorAt:{label:`error at %`,domain:{...BR,atLeast:`warnAt`},default:80}};function HR(e){return{budget:{label:`budget $`,domain:{min:0,max:1e4,step:5},default:e},warnAt:{label:`warning at %`,domain:BR,default:80}}}const UR={globals:{palette:`tokyo-night`},variables:{...FR.variables,...GE,current_dir:{kind:`input`,path:`workspace.current_dir`,default:`?`},"model.display_name":{kind:`input`,path:`model.display_name`,default:``},"effort.level":{kind:`input`,path:`effort.level`,default:``},"effort.glyphs":{kind:`literal`,value:`? `},version:{kind:`input`,path:`version`,default:``},home:{kind:`input`,path:`home`,default:``},"tmux.session":{kind:`input`,path:`tmux.session`,default:``},"host.name":{kind:`input`,path:`host.name`,default:``},"host.user":{kind:`input`,path:`host.user`,default:``},"host.ssh":{kind:`input`,path:`host.ssh`,type:`boolean`,default:!1},"git.repoName":{kind:`input`,path:`git.repoName`,default:``},"git.branch":{kind:`input`,path:`git.branch`,default:``},"git.sha":{kind:`input`,path:`git.sha`,default:``},"git.ahead":{kind:`input`,path:`git.ahead`,type:`number`,default:0},"git.behind":{kind:`input`,path:`git.behind`,type:`number`,default:0},"git.staged":{kind:`input`,path:`git.staged`,type:`number`,default:0},"git.unstaged":{kind:`input`,path:`git.unstaged`,type:`number`,default:0},"git.untracked":{kind:`input`,path:`git.untracked`,type:`number`,default:0},"git.conflicts":{kind:`input`,path:`git.conflicts`,type:`number`,default:0},"git.upstream":{kind:`input`,path:`git.upstream`,default:``},"git.tracking":{kind:`input`,path:`git.tracking`,default:``},"git.stash":{kind:`input`,path:`git.stash`,type:`number`,default:0},"git.status":{kind:`input`,path:`git.status`,default:`clean`},"git.operation":{kind:`input`,path:`git.operation`,default:``},"git.timeSinceCommit":{kind:`input`,path:`git.timeSinceCommit`,type:`number`,default:0},"git.color.branch":{kind:`literal`,value:`primary`},"git.color.staged":{kind:`literal`,value:`success`},"git.color.unstaged":{kind:`literal`,value:`warning`},"git.color.untracked":{kind:`literal`,value:`accent`},"git.color.conflicts":{kind:`literal`,value:`error`},"git.color.ahead":{kind:`literal`,value:`success`},"git.color.behind":{kind:`literal`,value:`warning`},"git.color.stash":{kind:`literal`,value:`accent`},"git.detail":{kind:`state`,key:`git-detail`,default:`collapsed`},"git.prNumber":{kind:`input`,path:`git.prNumber`,type:`number`,default:0},"git.prState":{kind:`input`,path:`git.prState`,default:``},"git.prUrl":{kind:`input`,path:`git.prUrl`,default:``},"git.prError":{kind:`input`,path:`git.prError`,default:``},"cache.expiresAt":{kind:`input`,path:`cache.expiresAt`,type:`number`,default:0},"session.cost":{kind:`input`,path:`session.cost`,type:`number`,default:0},"session.tokens":{kind:`input`,path:`session.tokens`,type:`number`,default:0},"today.cost":{kind:`input`,path:`today.cost`,type:`number`,default:0},"today.tokens":{kind:`input`,path:`today.tokens`,type:`number`,default:0},"block.nativeUtilization":{kind:`input`,path:`block.nativeUtilization`,type:`number`,default:0},"block.resetsAt":{kind:`input`,path:`block.resetsAt`,type:`number`,default:0},"weekly.percentage":{kind:`input`,path:`weekly.percentage`,type:`number`,default:0},"weekly.resetsAt":{kind:`input`,path:`weekly.resetsAt`,type:`number`,default:0},"burn.costPerHour":{kind:`input`,path:`burn.costPerHour`,type:`number`,default:-1},"block.etaMinutes":{kind:`input`,path:`block.etaMinutes`,type:`number`,default:-1},"weekly.etaMinutes":{kind:`input`,path:`weekly.etaMinutes`,type:`number`,default:-1},"speed.input":{kind:`input`,path:`speed.input`,type:`number`,default:-1},"speed.output":{kind:`input`,path:`speed.output`,type:`number`,default:-1},"speed.total":{kind:`input`,path:`speed.total`,type:`number`,default:-1},"speed.history":{kind:`input`,path:`speed.history`,type:`string`,default:``},"context.totalTokens":{kind:`input`,path:`context.totalTokens`,type:`number`,default:0},"context.contextLeft":{kind:`input`,path:`context.contextLeft`,type:`number`,default:100},"memento.ceiling":{kind:`input`,path:`memento.ceiling`,type:`number`,default:-1},"memento.off":{kind:`input`,path:`memento.off`,type:`boolean`,default:!1},"memento.session":{kind:`input`,path:`memento.session`,default:``},"memento.error":{kind:`input`,path:`memento.error`,default:``},"metrics.lastResponseTime":{kind:`input`,path:`metrics.lastResponseTime`,type:`number`,default:0},"metrics.responseTime":{kind:`input`,path:`metrics.responseTime`,type:`number`,default:0},"metrics.sessionDuration":{kind:`input`,path:`metrics.sessionDuration`,type:`number`,default:0},"metrics.messageCount":{kind:`input`,path:`metrics.messageCount`,type:`number`,default:0},"metrics.linesAdded":{kind:`input`,path:`metrics.linesAdded`,type:`number`,default:0},"metrics.linesRemoved":{kind:`input`,path:`metrics.linesRemoved`,type:`number`,default:0},"activity.command":{kind:`input`,path:`activity.command`,type:`string`,default:``},"activity.todo.total":{kind:`input`,path:`activity.todo.total`,type:`number`,default:0},"activity.todo.completed":{kind:`input`,path:`activity.todo.completed`,type:`number`,default:0},"activity.todo.position":{kind:`input`,path:`activity.todo.position`,type:`number`,default:0},"activity.todo.active":{kind:`input`,path:`activity.todo.active`,type:`string`,default:``},"activity.tool.running":{kind:`input`,path:`activity.tool.running`,type:`string`,default:``},"activity.tool.done":{kind:`input`,path:`activity.tool.done`,type:`string`,default:``}},segments:{directory:{group:`location`,description:"The current directory, shortened fish-style — `~` under home, project-relative inside the project. Click to copy the full path.",template:RR},model:{group:`model-context`,description:`The active model's display name, followed by the effort gauge (a chevron ladder, climbing on a bubble at max) when an effort level is set.`,template:`✱ {{ formatModelName .model.display_name }}{{ if ne .effort.level "" }} {{ template "effortGauge" . }}{{ end }}`,when:`{{ ne .model.display_name "" }}`},sessionId:{group:`session-tools`,description:`The session id, truncated to 8 characters.`,template:`⌗{{ trunc 8 .session.id }}`,when:`{{ ne .session.id "" }}`},version:{group:`model-context`,description:`The Claude Code version reported in the hook payload.`,template:`◈ v{{ .version }}`,when:`{{ ne .version "" }}`},tmux:{group:`location`,description:`The tmux session name; hidden when not inside tmux.`,template:`tmux:{{ .tmux.session | default "none" }}`,when:`{{ ne .tmux.session "" }}`},host:{group:`location`,description:`user@host on a warning background, shown only over SSH.`,template:`⇄ {{ .host.user | default "?" }}@{{ .host.name | default "?" }}`,bg:`warning`,when:`{{ .host.ssh }}`},gitaculous:{group:`git`,description:`The git state: a summary (branch, ahead/behind, S/U/? flags) that the arrow at its right edge expands to every fact — repo, in-progress operation, sha, upstream ±, stash count, time since the last commit.`,template:`{{ if eq .git.detail "expanded" }}{{ template "gitExpanded" . }}{{ else }}{{ template "gitCollapsed" . }}{{ end }} {{ action "gitDetail" "▸" "◂" }}`,fg:zR,when:`{{ ne .git.branch "" }}`,settings:{aheadBehind:{label:`ahead/behind`,domain:`bool`,default:!0},flags:{label:`dirty flags`,domain:`bool`,default:!0},operation:{label:`operation`,domain:`bool`,default:!0},repo:{label:`repo name`,domain:`bool`,default:!0},sha:{label:`commit hash`,domain:`bool`,default:!0},stash:{label:`stash`,domain:`bool`,default:!0},upstream:{label:`upstream`,domain:`bool`,default:!0},age:{label:`time since commit`,domain:`bool`,default:!0}}},gitPr:{group:`git`,description:"The pull request open for this branch, as a link; `⚠ PR` when the forge lookup failed.",template:`{{ if eq .git.prState "open" }}{{ link .git.prUrl (printf "⇆ #%v" .git.prNumber) }}{{ else }}⚠ PR{{ end }}`,when:`{{ or (eq .git.prState "open") (ne .git.prError "") }}`},toolbar:{group:`session-tools`,description:`Quick actions: copy the session id, and open the project, transcript or repo.`,template:QA(``).template},commands:{group:`session-tools`,description:`Type /compact, /model or /clear into this session; /clear asks for a second click. Hidden when not inside tmux.`,template:FR.template,when:FR.when},themeSwitcher:{group:`session-tools`,description:"`◀ <theme> ▶`: the theme the bar is wearing; ◀ and ▶ switch this session to the previous or next theme, wrapping at the ends.",template:`{{ carousel "stepTheme" 0 }}`},session:{group:`cost-limits`,description:`This session's cost and token total, with a budget warning once a budget is configured.`,template:`§ {{ template "formatCost" .session.cost }} ({{ template "formatTokens" .session.tokens }}){{ template "budgetStatus" (dict "cost" .session.cost "budget" .settings.budget "warn" .settings.warnAt) }}`,settings:HR(0)},today:{group:`cost-limits`,description:`Today's cost and tokens across every session, with a budget warning once a budget is configured.`,template:`☉ {{ template "formatCost" .today.cost }} ({{ template "formatTokens" .today.tokens }}){{ template "budgetStatus" (dict "cost" .today.cost "budget" .settings.budget "warn" .settings.warnAt) }}`,settings:HR(50)},block:{group:`cost-limits`,description:`The 5-hour rate-limit block: percent used and time to reset, heating to warning then error.`,template:`◱ {{ round .block.nativeUtilization }}% ({{ template "formatResetCountdown" .block.resetsAt }})`,bg:`{{ ramp (round .block.nativeUtilization) "step" 0 (tint) .settings.warnAt "warning" .settings.errorAt "error" }}`,settings:VR,when:`{{ gt .block.resetsAt 0 }}`},weekly:{group:`cost-limits`,description:`The weekly rate-limit quota: percent used and time to reset, heating to warning then error.`,template:`◑ {{ round .weekly.percentage }}% ({{ template "formatResetCountdown" .weekly.resetsAt }})`,bg:`{{ ramp (round .weekly.percentage) "step" 0 (tint) .settings.warnAt "warning" .settings.errorAt "error" }}`,settings:VR,when:`{{ gt .weekly.resetsAt 0 }}`},burnrate:{group:`cost-limits`,description:`Spend per hour, with the projected time to the 5-hour and weekly limits.`,template:`⚡ {{ template "formatRate" .burn.costPerHour }} · {{ template "formatEta" .block.etaMinutes }} to 5h · {{ template "formatEta" .weekly.etaMinutes }} to wk`,bg:`{{ ramp .block.etaMinutes "step" -1 (tint) 0 "error" .settings.errorWithin "warning" .settings.warnWithin (tint) }}`,settings:{errorWithin:{label:`error within (min)`,domain:{min:0,max:300,step:5},default:30},warnWithin:{label:`warning within (min)`,domain:{min:0,max:300,step:5,atLeast:`errorWithin`},default:60}},when:`{{ or (gt .block.resetsAt 0) (gt .weekly.resetsAt 0) }}`},speed:{group:`activity`,description:`Token throughput for the latest exchange: output, input, and total.`,template:`⇅ out {{ template "formatSpeed" .speed.output }} · in {{ template "formatSpeed" .speed.input }} · tot {{ template "formatSpeed" .speed.total }}`,when:`{{ gt .session.tokens 0 }}`},tokenSparkline:{group:`activity`,description:`A sparkline of recent token throughput.`,template:`⚡ {{ sparkline .speed.history 24 }}`,when:`{{ ne .speed.history "" }}`},cacheTimer:{group:`activity`,description:"Minutes until the prompt cache expires, or `cold` once it has.",template:`◴ {{ if le (minutesUntilReset .cache.expiresAt) 0 }}cold{{ else }}{{ minutesUntilReset .cache.expiresAt }}m{{ end }}`,fg:`{{ readableOn (color (cascade (minutesUntilReset .cache.expiresAt) "0:error" "9:warning" "21:foreground")) (bgOf) ${xm} }}`,when:`{{ gt .cache.expiresAt 0 }}`},context:{group:`model-context`,description:`Context used, in tokens and percent remaining, heating as it fills.`,template:`◔ {{ formatInteger .context.totalTokens }} ({{ .context.contextLeft }}%)`,bg:`{{ ramp .context.contextLeft "step" 0 "error" 21 "warning" 41 (tint) }}`,when:`{{ gt .context.totalTokens 0 }}`},ceiling:{group:`model-context`,description:`The memento plugin's context ceiling for this session: − and + move it by 100K, ∞ lifts it, ↺ drops this session's own setting.`,template:`{{ if ne .memento.error "" }}⌈ ⚠ {{ .memento.error }} {{ action "ceiling.clear" "↺" }}{{ else }}⌈ {{ if .memento.off }}off{{ else }}{{ template "formatTokenCount" .memento.ceiling }} {{ action "ceiling.lower" "−" }} {{ action "ceiling.raise" "+" }} {{ action "ceiling.off" "∞" }}{{ end }}{{ if ne .memento.session "" }} {{ action "ceiling.clear" "↺" }}{{ end }}{{ end }}`,bg:`{{ if ne .memento.error "" }}{{ color "error" }}{{ else }}{{ tint }}{{ end }}`,when:`{{ or (ge .memento.ceiling 0) (ne .memento.error "") }}`},autocompact:{group:`model-context`,description:`Claude Code's auto-compact window: − and + move it by 100K, ↺ returns it to auto. Clicks type /autocompact into this session, so the controls show only inside tmux.`,template:IR.template,bg:IR.bg,when:IR.when},metrics:{group:`activity`,description:`Response times, session duration, message count, and lines added/removed.`,template:`{{ if .metrics.lastResponseTime }} Δ {{ template "formatResponseTime" .metrics.lastResponseTime }}{{ end }}{{ if .metrics.responseTime }} ⧖ {{ template "formatResponseTime" .metrics.responseTime }}{{ end }}{{ if .metrics.sessionDuration }} ⧗ {{ template "formatDuration" .metrics.sessionDuration }}{{ end }}{{ if .metrics.messageCount }} ◆ {{ .metrics.messageCount }}{{ end }}{{ if .metrics.linesAdded }} + {{ .metrics.linesAdded }}{{ end }}{{ if .metrics.linesRemoved }} - {{ .metrics.linesRemoved }}{{ end }} `,when:`{{ or (gt .metrics.lastResponseTime 0.0) (gt .metrics.responseTime 0.0) (gt .metrics.sessionDuration 0.0) (gt .metrics.messageCount 0) (gt .metrics.linesAdded 0) (gt .metrics.linesRemoved 0) }}`},activity:{group:`activity`,description:`What Claude is doing: the slash command that opened the turn, the in-progress todo, and the tools in flight.`,template:`{{ if .activity.command }} ⌘ {{ .activity.command }}{{ end }}{{ if .activity.todo.total }}{{ if .activity.todo.active }} ☐ {{ .activity.todo.position }}/{{ .activity.todo.total }} {{ abbrev 32 .activity.todo.active }}{{ else }} ☑ {{ .activity.todo.completed }}/{{ .activity.todo.total }}{{ end }}{{ end }}{{ if .activity.tool.running }} ⟳ {{ template "formatToolTally" .activity.tool.running }}{{ end }}{{ if .activity.tool.done }} ✓ {{ template "formatToolTally" .activity.tool.done }}{{ end }} `,when:`{{ or (ne .activity.command "") (gt .activity.todo.total 0) (ne .activity.tool.running "") (ne .activity.tool.done "") }}`}},root:{rows:{identity:{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`host`},{kind:`segment`,name:`directory`},{kind:`segment`,name:`gitaculous`}]},status:{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`model`},{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`context`},{kind:`segment`,name:`ceiling`},{kind:`segment`,name:`autocompact`}]},{kind:`segment`,name:`cacheTimer`},{kind:`segment`,name:`block`},{kind:`segment`,name:`weekly`},{kind:`segment`,name:`activity`}]}}},actions:{...QA(``).actions,...FR.actions,copyDir:{copy:`{{ .current_dir }}`},stepTheme:{set:`theme`,from:`themes`},gitDetail:{set:`git-detail`,cycle:[`collapsed`,`expanded`]},"ceiling.raise":{ceiling:`set`,to:`+100_000`},"ceiling.lower":{ceiling:`set`,to:`-100_000`},"ceiling.off":{ceiling:`set`,to:`off`},"ceiling.clear":{ceiling:`clear`},...IR.actions},styles:{none:{hueShift:0,chromaScale:1,lightnessScale:1,lightnessShift:0},vivid:{hueShift:0,chromaScale:1.35,lightnessScale:1,lightnessShift:0},muted:{hueShift:0,chromaScale:.55,lightnessScale:1,lightnessShift:0},dim:{hueShift:0,chromaScale:1,lightnessScale:.85,lightnessShift:0},bright:{hueShift:0,chromaScale:1,lightnessScale:1,lightnessShift:.08},inverted:{hueShift:0,chromaScale:1,lightnessScale:-1,lightnessShift:1}},themeDefaults:PR,presets:{default:{},compact:{root:{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`directory`},{kind:`segment`,name:`gitaculous`},{kind:`segment`,name:`context`}]},globals:{padding:0}},verbose:{root:{kind:`container`,direction:`vertical`,children:[{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`directory`},{kind:`segment`,name:`gitaculous`},{kind:`segment`,name:`gitPr`}]},{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`model`},{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`context`},{kind:`segment`,name:`ceiling`},{kind:`segment`,name:`autocompact`}]},{kind:`segment`,name:`cacheTimer`},{kind:`segment`,name:`block`},{kind:`segment`,name:`weekly`},{kind:`segment`,name:`burnrate`}]},{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`speed`},{kind:`segment`,name:`tokenSparkline`}]}]}},zen:{root:{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`directory`},{kind:`segment`,name:`context`}]},globals:{endcaps:`plain`,style:`dim`}},git:{root:{kind:`container`,direction:`vertical`,children:[{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`host`},{kind:`segment`,name:`directory`},{kind:`segment`,name:`gitaculous`},{kind:`segment`,name:`gitPr`}]},{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`model`},{kind:`segment`,name:`context`},{kind:`segment`,name:`activity`}]}]}},usage:{root:{kind:`container`,direction:`vertical`,children:[{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`model`},{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`context`},{kind:`segment`,name:`ceiling`},{kind:`segment`,name:`autocompact`}]},{kind:`segment`,name:`cacheTimer`}]},{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`block`},{kind:`segment`,name:`weekly`},{kind:`segment`,name:`burnrate`}]},{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`session`},{kind:`segment`,name:`today`},{kind:`segment`,name:`speed`},{kind:`segment`,name:`tokenSparkline`}]}]}},dense:{root:{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`host`},{kind:`segment`,name:`directory`},{kind:`segment`,name:`gitaculous`},{kind:`segment`,name:`model`},{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`context`},{kind:`segment`,name:`ceiling`},{kind:`segment`,name:`autocompact`}]},{kind:`segment`,name:`cacheTimer`},{kind:`segment`,name:`block`},{kind:`segment`,name:`weekly`},{kind:`segment`,name:`session`},{kind:`segment`,name:`activity`}]},globals:{padding:0}}},editGlobals:{endcaps:`plain`,default_separator:` | `},helpers:{effortGauge:`{{ \$ord := default 0 (get (dict "low" 1 "medium" 2 "high" 3 "xhigh" 4 "max" 5) .effort.level) }}{{ \$glyphs := compact (splitList " " .effort.glyphs) }}{{ $bubble := readableOn (mix (bgOf) (color "accent") 40) (bgOf) 1.08 }}{{ $climbing := readableOn (stepped 1 (color "primary") 1 (color "secondary") 1 (color "accent")) $bubble ${xm} }}{{ \$climb := frames 1 (index \$glyphs 1) 1 (index \$glyphs 3) 1 (index \$glyphs 4) }}{{ if eq \$ord 5 }}{{ fg \$bubble "" }}{{ bg \$bubble (fg \$climbing \$climb) }}{{ fg \$bubble "" }}{{ else }}{{ fg (ramp $ord "step" 0 (${Tk}) 2 (readableOn (color "accent") (bgOf) ${xm})) (index $glyphs $ord) }}{{ end }}`,gitPaint:`{{ fg (readableOn (color .color) (bgOf) ${xm}) .text }}`,gitCollapsed:`{{ template "gitBranch" . }}{{ template "gitAheadBehind" . }}{{ template "gitFlags" . }}`,gitExpanded:`(git){{ template "gitRepo" . }}{{ template "gitOperation" . }}{{ template "gitSha" . }}{{ template "gitFlags" . }} {{ template "gitBranch" . }}{{ template "gitUpstream" . }}{{ template "gitStash" . }}{{ template "gitAge" . }}`,gitBranch:`⎇ {{ template "gitPaint" (dict "color" .git.color.branch "text" .git.branch) }}`,gitRepo:`{{ if and .settings.repo (ne .git.repoName "") }} {{ .git.repoName }}{{ end }}`,gitOperation:`{{ if and .settings.operation (ne .git.operation "") }} [{{ .git.operation }}]{{ end }}`,gitSha:`{{ if and .settings.sha (ne .git.sha "") }} {{ .git.sha }}{{ end }}`,gitFlags:`{{ if and .settings.flags (or (gt .git.staged 0) (gt .git.unstaged 0) (gt .git.untracked 0) (gt .git.conflicts 0)) }} {{ if gt .git.staged 0 }}{{ template "gitPaint" (dict "color" .git.color.staged "text" "S") }}{{ end }}{{ if gt .git.unstaged 0 }}{{ template "gitPaint" (dict "color" .git.color.unstaged "text" "U") }}{{ end }}{{ if gt .git.untracked 0 }}{{ template "gitPaint" (dict "color" .git.color.untracked "text" "?") }}{{ end }}{{ if gt .git.conflicts 0 }}{{ template "gitPaint" (dict "color" .git.color.conflicts "text" (printf "!%v" .git.conflicts)) }}{{ end }}{{ end }}`,gitAheadBehind:`{{ if and .settings.aheadBehind (or (gt .git.ahead 0) (gt .git.behind 0)) }} {{ if gt .git.ahead 0 }}{{ template "gitPaint" (dict "color" .git.color.ahead "text" (printf "+%v" .git.ahead)) }}{{ end }}{{ if and (gt .git.ahead 0) (gt .git.behind 0) }}/{{ end }}{{ if gt .git.behind 0 }}{{ template "gitPaint" (dict "color" .git.color.behind "text" (printf "-%v" .git.behind)) }}{{ end }}{{ end }}`,gitUpstream:`{{ if and .settings.upstream (ne .git.upstream "") }} [{{ .git.upstream }}{{ template "gitAheadBehind" . }}]{{ end }}`,gitStash:`{{ if and .settings.stash (gt .git.stash 0) }} {{ template "gitPaint" (dict "color" .git.color.stash "text" (printf "(%v stashed)" .git.stash)) }}{{ end }}`,gitAge:`{{ if and .settings.age (gt .git.timeSinceCommit 0) }} ◷ {{ template "formatTimeSince" .git.timeSinceCommit }}{{ end }}`,formatCost:'{{ if lt . 0.01 }}<$0.01{{ else }}${{ printf "%.2f" . }}{{ end }}',formatTokenCount:gj(`.`),formatTokens:`{{ template "formatTokenCount" . }} tokens`,formatToolTally:`{{ $names := splitList "," . }}{{ range $i, $pair := $names }}{{ if lt $i 2 }}{{ if $i }} {{ end }}{{ $kv := splitList ":" $pair }}{{ index $kv 0 }}{{ if ne (index $kv 1) "1" }}×{{ index $kv 1 }}{{ end }}{{ end }}{{ end }}{{ if gt (len $names) 2 }} +{{ sub (len $names) 2 }}{{ end }}`,formatRate:`{{ if lt . 0 }}—/hr{{ else }}{{ template "formatCost" . }}/hr{{ end }}`,formatEta:`{{ if lt . 0 }}—{{ else }}{{ template "formatLongTimeRemaining" . }}{{ end }}`,formatSpeed:`{{ if lt . 0 }}—{{ else }}{{ template "formatTokenCount" (round .) }}/s{{ end }}`,formatTokenBreakdown:`{{ $first := true }}{{ if gt .input 0 }}{{ template "formatTokenCount" .input }} in{{ $first = false }}{{ end }}{{ if gt .output 0 }}{{ if not $first }} + {{ end }}{{ template "formatTokenCount" .output }} out{{ $first = false }}{{ end }}{{ if or (gt .cacheCreation 0) (gt .cacheRead 0) }}{{ if not $first }} + {{ end }}{{ template "formatTokenCount" (add .cacheCreation .cacheRead) }} cached{{ $first = false }}{{ end }}{{ if $first }}0 tokens{{ end }}`,budgetStatus:`{{ if or (le .budget 0) (lt .cost 0) }}{{ else }}{{ $pct := minf 100 (mulf (divf .cost .budget) 100) }}{{ $p := printf "%.0f%%" $pct }}{{ if ge $pct .warn }} !{{ $p }}{{ else }}{{ if ge $pct 50 }} +{{ $p }}{{ else }} {{ $p }}{{ end }}{{ end }}{{ end }}`,formatTimeSince:`{{ if lt . 60 }}{{ . }}s{{ else if lt . 3600 }}{{ div . 60 }}m{{ else if lt . 86400 }}{{ div . 3600 }}h{{ else if lt . 604800 }}{{ div . 86400 }}d{{ else }}{{ div . 604800 }}w{{ end }}`,formatDuration:`{{ if lt . 60 }}{{ printf "%.0f" . }}s{{ else if lt . 3600 }}{{ printf "%.0f" (divf . 60) }}m{{ else if lt . 86400 }}{{ printf "%.1f" (divf . 3600) }}h{{ else }}{{ printf "%.1f" (divf . 86400) }}d{{ end }}`,formatResponseTime:`{{ if lt . 60 }}{{ printf "%.1f" . }}s{{ else }}{{ printf "%.1f" (divf . 60) }}m{{ end }}`,formatLongTimeRemaining:`{{ if ge . 1440 }}{{ $d := div . 1440 }}{{ $h := div (mod . 1440) 60 }}{{ if gt $h 0 }}{{ $d }}d {{ $h }}h{{ else }}{{ $d }}d{{ end }}{{ else if ge . 60 }}{{ $h := div . 60 }}{{ $m := mod . 60 }}{{ if gt $m 0 }}{{ $h }}h {{ $m }}m{{ else }}{{ $h }}h{{ end }}{{ else }}{{ . }}m{{ end }}`,formatResetCountdown:`{{ template "formatLongTimeRemaining" (add 1 (minutesUntilReset .)) }}`}},WR=new Set([UR.globals.palette,...Object.keys(UR.themeDefaults),...Object.values(UR.segments).map(e=>e.palette)].filter(e=>e!==void 0)),GR=$N(DR(`<default>`,JSON.stringify(UR),WR),UR),KR=z_(GR.presets);function qR(e){return KR.includes(e)}const JR=Object.freeze({});function YR(e,t){return e.kind===`decided`?t[e.name]??JR:JR}function XR(e,t){return{...e,...Object.fromEntries(a_.map(n=>[n,e[n]??t[n]]))}}function ZR(e){if(!e)return``;try{return QR(g(e))}catch{return``}}function QR(e){return`${e.mtimeMs}:${e.size}`}const $R=new class{slots;head=null;tail=null;constructor(e){this.slots=e}async run(e){await this.acquire();try{return await e()}finally{this.release()}}async acquire(){if(this.slots>0){this.slots--;return}await new Promise(e=>{let t={wake:e,next:null};this.tail?this.tail.next=t:this.head=t,this.tail=t})}release(){let e=this.head;if(!e){this.slots++;return}this.head=e.next,this.head||(this.tail=null),e.wake()}}(8);function ez(e){return((...t)=>$R.run(()=>e(...t)))}const tz=ez(le),nz=ez(ce),rz=ez(ue);async function iz(e,t){return $R.run(async()=>{let n=null;try{n=await se(e,`r`);let r=await n.stat(),{size:i,ino:a}=r,o=QR(r),s=t!==void 0&&(a!==t.ino||i<t.offset),c=s||t===void 0?0:t.offset;if(c>=i)return L({buf:Buffer.alloc(0),start:c,size:i,stamp:o,ino:a,reset:s});let l=Buffer.alloc(i-c),u=0;for(;u<l.length;){let{bytesRead:e}=await n.read(l,u,l.length-u,c+u);if(e===0)break;u+=e}return L({buf:u===l.length?l:l.subarray(0,u),start:c,size:i,stamp:o,ino:a,reset:s})}catch(t){return t.code===`ENOENT`?R:z(`readAppended ${e}: ${t instanceof Error?t.message:String(t)}`)}finally{await n?.close().catch(e=>{k(`transcript-fs: close failed: ${e instanceof Error?e.message:String(e)}`)})}})}async function az(e,t){return $R.run(async()=>{let n=null;try{n=await se(e,`r`);let{size:r}=await n.stat(),i=Math.max(0,r-t),a=Buffer.alloc(r-i),o=0;for(;o<a.length;){let{bytesRead:e}=await n.read(a,o,a.length-o,i+o);if(e===0)break;o+=e}return L({buf:o===a.length?a:a.subarray(0,o),fromStart:i===0})}catch(t){return t.code===`ENOENT`?R:z(`readTail ${e}: ${t instanceof Error?t.message:String(t)}`)}finally{await n?.close().catch(e=>{k(`transcript-fs: close failed: ${e instanceof Error?e.message:String(e)}`)})}})}function oz(e,t){let n;try{n=p(e,l.O_RDONLY|l.O_NONBLOCK)}catch(e){return e.code===`ENOENT`?R:z(e instanceof Error?e.message:String(e))}try{let{size:e}=f(n),r=Math.max(0,e-t),i=Buffer.alloc(e-r),a=0;for(;a<i.length;){let e=m(n,i,a,i.length-a,r+a);if(e===0)break;a+=e}return L({buf:i.subarray(0,a),fromStart:r===0})}catch(e){return z(e instanceof Error?e.message:String(e))}finally{try{c(n)}catch(e){k(`transcript-fs: close failed: ${e instanceof Error?e.message:String(e)}`)}}}const sz=/"(?:cache_read_input_tokens|cache_creation_input_tokens)":[1-9]/;function cz(e){let t;try{t=JSON.parse(e)}catch{return null}let n=t.message?.usage;if(!((n?.cache_read_input_tokens??0)>0||(n?.cache_creation_input_tokens??0)>0))return null;let r=t.timestamp==null?NaN:Date.parse(t.timestamp);return Number.isNaN(r)?null:r}async function lz(e){let t=await uz(e);return t.kind===`ok`?L(Math.floor((t.value+36e5)/1e3)):t}async function uz(e){for(let t of[65536,1048576]){let n=await az(e,t);if(n.kind!==`ok`)return n;let r=dz(n.value.buf,n.value.fromStart);if(r!=null)return L(r);if(n.value.fromStart)return R}return R}function dz(e,t){let n=e.toString(`utf8`).split(`
|
|
178
|
-
`),r=+!t;for(let e=n.length-1;e>=r;e--){let t=n[e];if(!t||!
|
|
177
|
+
Single-row example: root: { h: ["seg1", "seg2"] }`,line:Y(e.source,[`layout`])}),t.root!==void 0&&(r.root=MF(e,`root`,t.root)),t.actions!==void 0&&(r.actions=nI(e,t.actions)),t.looks!==void 0&&e.issues.push({path:`looks`,message:`"looks" was renamed "styles" — move the block under styles: { … } (and globals.look to globals.style)`,line:Y(e.source,[`looks`])}),t.styles!==void 0&&(r.styles=JI(e,t.styles)),t.themeDefaults!==void 0&&(r.themeDefaults=EO(e,t.themeDefaults)),t.presets!==void 0&&(r.presets=XI(e,t.presets)),t.editGlobals!==void 0&&(r.editGlobals=AO(e,`editGlobals`,t.editGlobals)),t.helpers!==void 0&&(r.helpers=ZI(e,t.helpers)),t.plugins!==void 0&&(r.plugins=RR(e,t.plugins)),BF(e,r),XF(e,r),lk(e,r),oD(e,r,X,`the global settings menu`),r}const LR=new Set([`globals`,`variables`,`segments`,`layout`,`looks`,`root`,`actions`,`styles`,`themeDefaults`,`presets`,`editGlobals`,`helpers`,`plugins`]);function RR(e,t){if(Array.isArray(t)&&t.every(e=>typeof e==`string`&&e!==``))return t;e.issues.push({path:`plugins`,message:`"plugins" must be a list of plugin definition paths, got ${kD(t)}`,line:Y(e.source,[`plugins`])})}const zR={},BR=mj(`commands.`),VR=bj(`autocompact.`,e=>`{{ template "formatTokenCount" ${e} }}`),HR=`trimPrefix "/" (trimPrefix .project_dir .current_dir)`,UR=`{{ \$dir := .current_dir }}{{ if and (ne .home "") (or (eq .home .current_dir) (hasPrefix (printf "%s/" .home) .current_dir)) }}{{ \$dir = printf "~%s" (trimPrefix .home .current_dir) }}{{ else }}{{ if or (eq .project_dir .current_dir) (hasPrefix (printf "%s/" .project_dir) .current_dir) }}{{ $dir = ternary (${HR}) (basename .project_dir) (ne (${HR}) "") }}{{ end }}{{ end }}{{ action "copyDir" (abbreviatePath \$dir) }}`,WR=`{{ ${wk} }}`,GR={min:0,max:100,step:5},KR={warnAt:{label:`warning at %`,domain:GR,default:50},errorAt:{label:`error at %`,domain:{...GR,atLeast:`warnAt`},default:80}};function qR(e){return{budget:{label:`budget $`,domain:{min:0,max:1e4,step:5},default:e},warnAt:{label:`warning at %`,domain:GR,default:80}}}const JR={globals:{palette:`tokyo-night`},variables:{...BR.variables,...WE,current_dir:{kind:`input`,path:`workspace.current_dir`,default:`?`},"model.display_name":{kind:`input`,path:`model.display_name`,default:``},"effort.level":{kind:`input`,path:`effort.level`,default:``},"effort.glyphs":{kind:`literal`,value:`? `},version:{kind:`input`,path:`version`,default:``},home:{kind:`input`,path:`home`,default:``},"tmux.session":{kind:`input`,path:`tmux.session`,default:``},"host.name":{kind:`input`,path:`host.name`,default:``},"host.user":{kind:`input`,path:`host.user`,default:``},"host.ssh":{kind:`input`,path:`host.ssh`,type:`boolean`,default:!1},"git.repoName":{kind:`input`,path:`git.repoName`,default:``},"git.branch":{kind:`input`,path:`git.branch`,default:``},"git.sha":{kind:`input`,path:`git.sha`,default:``},"git.ahead":{kind:`input`,path:`git.ahead`,type:`number`,default:0},"git.behind":{kind:`input`,path:`git.behind`,type:`number`,default:0},"git.staged":{kind:`input`,path:`git.staged`,type:`number`,default:0},"git.unstaged":{kind:`input`,path:`git.unstaged`,type:`number`,default:0},"git.untracked":{kind:`input`,path:`git.untracked`,type:`number`,default:0},"git.conflicts":{kind:`input`,path:`git.conflicts`,type:`number`,default:0},"git.upstream":{kind:`input`,path:`git.upstream`,default:``},"git.tracking":{kind:`input`,path:`git.tracking`,default:``},"git.stash":{kind:`input`,path:`git.stash`,type:`number`,default:0},"git.status":{kind:`input`,path:`git.status`,default:`clean`},"git.operation":{kind:`input`,path:`git.operation`,default:``},"git.timeSinceCommit":{kind:`input`,path:`git.timeSinceCommit`,type:`number`,default:0},"git.color.branch":{kind:`literal`,value:`primary`},"git.color.staged":{kind:`literal`,value:`success`},"git.color.unstaged":{kind:`literal`,value:`warning`},"git.color.untracked":{kind:`literal`,value:`accent`},"git.color.conflicts":{kind:`literal`,value:`error`},"git.color.ahead":{kind:`literal`,value:`success`},"git.color.behind":{kind:`literal`,value:`warning`},"git.color.stash":{kind:`literal`,value:`accent`},"git.detail":{kind:`state`,key:`git-detail`,default:`collapsed`},"git.prNumber":{kind:`input`,path:`git.prNumber`,type:`number`,default:0},"git.prState":{kind:`input`,path:`git.prState`,default:``},"git.prUrl":{kind:`input`,path:`git.prUrl`,default:``},"git.prError":{kind:`input`,path:`git.prError`,default:``},"cache.expiresAt":{kind:`input`,path:`cache.expiresAt`,type:`number`,default:0},"session.cost":{kind:`input`,path:`session.cost`,type:`number`,default:0},"session.tokens":{kind:`input`,path:`session.tokens`,type:`number`,default:0},"today.cost":{kind:`input`,path:`today.cost`,type:`number`,default:0},"today.tokens":{kind:`input`,path:`today.tokens`,type:`number`,default:0},"block.nativeUtilization":{kind:`input`,path:`block.nativeUtilization`,type:`number`,default:0},"block.resetsAt":{kind:`input`,path:`block.resetsAt`,type:`number`,default:0},"weekly.percentage":{kind:`input`,path:`weekly.percentage`,type:`number`,default:0},"weekly.resetsAt":{kind:`input`,path:`weekly.resetsAt`,type:`number`,default:0},"burn.costPerHour":{kind:`input`,path:`burn.costPerHour`,type:`number`,default:-1},"block.etaMinutes":{kind:`input`,path:`block.etaMinutes`,type:`number`,default:-1},"weekly.etaMinutes":{kind:`input`,path:`weekly.etaMinutes`,type:`number`,default:-1},"speed.input":{kind:`input`,path:`speed.input`,type:`number`,default:-1},"speed.output":{kind:`input`,path:`speed.output`,type:`number`,default:-1},"speed.total":{kind:`input`,path:`speed.total`,type:`number`,default:-1},"speed.history":{kind:`input`,path:`speed.history`,type:`string`,default:``},"context.totalTokens":{kind:`input`,path:`context.totalTokens`,type:`number`,default:0},"context.contextLeft":{kind:`input`,path:`context.contextLeft`,type:`number`,default:100},"memento.ceiling":{kind:`input`,path:`memento.ceiling`,type:`number`,default:-1},"memento.off":{kind:`input`,path:`memento.off`,type:`boolean`,default:!1},"memento.session":{kind:`input`,path:`memento.session`,default:``},"memento.error":{kind:`input`,path:`memento.error`,default:``},"metrics.lastResponseTime":{kind:`input`,path:`metrics.lastResponseTime`,type:`number`,default:0},"metrics.responseTime":{kind:`input`,path:`metrics.responseTime`,type:`number`,default:0},"metrics.sessionDuration":{kind:`input`,path:`metrics.sessionDuration`,type:`number`,default:0},"metrics.messageCount":{kind:`input`,path:`metrics.messageCount`,type:`number`,default:0},"metrics.linesAdded":{kind:`input`,path:`metrics.linesAdded`,type:`number`,default:0},"metrics.linesRemoved":{kind:`input`,path:`metrics.linesRemoved`,type:`number`,default:0},"activity.command":{kind:`input`,path:`activity.command`,type:`string`,default:``},"activity.todo.total":{kind:`input`,path:`activity.todo.total`,type:`number`,default:0},"activity.todo.completed":{kind:`input`,path:`activity.todo.completed`,type:`number`,default:0},"activity.todo.position":{kind:`input`,path:`activity.todo.position`,type:`number`,default:0},"activity.todo.active":{kind:`input`,path:`activity.todo.active`,type:`string`,default:``},"activity.tool.running":{kind:`input`,path:`activity.tool.running`,type:`string`,default:``},"activity.tool.done":{kind:`input`,path:`activity.tool.done`,type:`string`,default:``}},segments:{directory:{group:`location`,description:"The current directory, shortened fish-style — `~` under home, project-relative inside the project. Click to copy the full path.",template:UR},model:{group:`model-context`,description:`The active model's display name, followed by the effort gauge (a chevron ladder, climbing on a bubble at max) when an effort level is set.`,template:`✱ {{ formatModelName .model.display_name }}{{ if ne .effort.level "" }} {{ template "effortGauge" . }}{{ end }}`,when:`{{ ne .model.display_name "" }}`},sessionId:{group:`session-tools`,description:`The session id, truncated to 8 characters.`,template:`⌗{{ trunc 8 .session.id }}`,when:`{{ ne .session.id "" }}`},version:{group:`model-context`,description:`The Claude Code version reported in the hook payload.`,template:`◈ v{{ .version }}`,when:`{{ ne .version "" }}`},tmux:{group:`location`,description:`The tmux session name; hidden when not inside tmux.`,template:`tmux:{{ .tmux.session | default "none" }}`,when:`{{ ne .tmux.session "" }}`},host:{group:`location`,description:`user@host on a warning background, shown only over SSH.`,template:`⇄ {{ .host.user | default "?" }}@{{ .host.name | default "?" }}`,bg:`warning`,when:`{{ .host.ssh }}`},gitaculous:{group:`git`,description:`The git state: a summary (branch, ahead/behind, S/U/? flags) that the arrow at its right edge expands to every fact — repo, in-progress operation, sha, upstream ±, stash count, time since the last commit.`,template:`{{ if eq .git.detail "expanded" }}{{ template "gitExpanded" . }}{{ else }}{{ template "gitCollapsed" . }}{{ end }} {{ action "gitDetail" "▸" "◂" }}`,fg:WR,when:`{{ ne .git.branch "" }}`,settings:{aheadBehind:{label:`ahead/behind`,domain:`bool`,default:!0},flags:{label:`dirty flags`,domain:`bool`,default:!0},operation:{label:`operation`,domain:`bool`,default:!0},repo:{label:`repo name`,domain:`bool`,default:!0},sha:{label:`commit hash`,domain:`bool`,default:!0},stash:{label:`stash`,domain:`bool`,default:!0},upstream:{label:`upstream`,domain:`bool`,default:!0},age:{label:`time since commit`,domain:`bool`,default:!0}}},gitPr:{group:`git`,description:"The pull request open for this branch, as a link; `⚠ PR` when the forge lookup failed.",template:`{{ if eq .git.prState "open" }}{{ link .git.prUrl (printf "⇆ #%v" .git.prNumber) }}{{ else }}⚠ PR{{ end }}`,when:`{{ or (eq .git.prState "open") (ne .git.prError "") }}`},toolbar:{group:`session-tools`,description:`Quick actions: copy the session id, and open the project, transcript or repo.`,template:rj(``).template},commands:{group:`session-tools`,description:`Type /compact, /model or /clear into this session; /clear asks for a second click. Hidden when not inside tmux.`,template:BR.template,when:BR.when},themeSwitcher:{group:`session-tools`,description:"`◀ <theme> ▶`: the theme the bar is wearing; ◀ and ▶ switch this session to the previous or next theme, wrapping at the ends.",template:`{{ carousel "stepTheme" 0 }}`},session:{group:`cost-limits`,description:`This session's cost and token total, with a budget warning once a budget is configured.`,template:`§ {{ template "formatCost" .session.cost }} ({{ template "formatTokens" .session.tokens }}){{ template "budgetStatus" (dict "cost" .session.cost "budget" .settings.budget "warn" .settings.warnAt) }}`,settings:qR(0)},today:{group:`cost-limits`,description:`Today's cost and tokens across every session, with a budget warning once a budget is configured.`,template:`☉ {{ template "formatCost" .today.cost }} ({{ template "formatTokens" .today.tokens }}){{ template "budgetStatus" (dict "cost" .today.cost "budget" .settings.budget "warn" .settings.warnAt) }}`,settings:qR(50)},block:{group:`cost-limits`,description:`The 5-hour rate-limit block: percent used and time to reset, heating to warning then error.`,template:`◱ {{ round .block.nativeUtilization }}% ({{ template "formatResetCountdown" .block.resetsAt }})`,bg:`{{ ramp (round .block.nativeUtilization) "step" 0 (tint) .settings.warnAt "warning" .settings.errorAt "error" }}`,settings:KR,when:`{{ gt .block.resetsAt 0 }}`},weekly:{group:`cost-limits`,description:`The weekly rate-limit quota: percent used and time to reset, heating to warning then error.`,template:`◑ {{ round .weekly.percentage }}% ({{ template "formatResetCountdown" .weekly.resetsAt }})`,bg:`{{ ramp (round .weekly.percentage) "step" 0 (tint) .settings.warnAt "warning" .settings.errorAt "error" }}`,settings:KR,when:`{{ gt .weekly.resetsAt 0 }}`},burnrate:{group:`cost-limits`,description:`Spend per hour, with the projected time to the 5-hour and weekly limits.`,template:`⚡ {{ template "formatRate" .burn.costPerHour }} · {{ template "formatEta" .block.etaMinutes }} to 5h · {{ template "formatEta" .weekly.etaMinutes }} to wk`,bg:`{{ ramp .block.etaMinutes "step" -1 (tint) 0 "error" .settings.errorWithin "warning" .settings.warnWithin (tint) }}`,settings:{errorWithin:{label:`error within (min)`,domain:{min:0,max:300,step:5},default:30},warnWithin:{label:`warning within (min)`,domain:{min:0,max:300,step:5,atLeast:`errorWithin`},default:60}},when:`{{ or (gt .block.resetsAt 0) (gt .weekly.resetsAt 0) }}`},speed:{group:`activity`,description:`Token throughput for the latest exchange: output, input, and total.`,template:`⇅ out {{ template "formatSpeed" .speed.output }} · in {{ template "formatSpeed" .speed.input }} · tot {{ template "formatSpeed" .speed.total }}`,when:`{{ gt .session.tokens 0 }}`},tokenSparkline:{group:`activity`,description:`A sparkline of recent token throughput.`,template:`⚡ {{ sparkline .speed.history 24 }}`,when:`{{ ne .speed.history "" }}`},cacheTimer:{group:`activity`,description:"Minutes until the prompt cache expires, or `cold` once it has.",template:`◴ {{ if le (minutesUntilReset .cache.expiresAt) 0 }}cold{{ else }}{{ minutesUntilReset .cache.expiresAt }}m{{ end }}`,fg:`{{ readableOn (color (cascade (minutesUntilReset .cache.expiresAt) "0:error" "9:warning" "21:foreground")) (bgOf) ${bm} }}`,when:`{{ gt .cache.expiresAt 0 }}`},context:{group:`model-context`,description:`Context used, in tokens and percent remaining, heating as it fills.`,template:`◔ {{ formatInteger .context.totalTokens }} ({{ .context.contextLeft }}%)`,bg:`{{ ramp .context.contextLeft "step" 0 "error" 21 "warning" 41 (tint) }}`,when:`{{ gt .context.totalTokens 0 }}`},ceiling:{group:`model-context`,description:`The memento plugin's context ceiling for this session: − and + move it by 100K, ∞ lifts it, ↺ drops this session's own setting.`,template:`{{ if ne .memento.error "" }}⌈ ⚠ {{ .memento.error }} {{ action "ceiling.clear" "↺" }}{{ else }}⌈ {{ if .memento.off }}off{{ else }}{{ template "formatTokenCount" .memento.ceiling }} {{ action "ceiling.lower" "−" }} {{ action "ceiling.raise" "+" }} {{ action "ceiling.off" "∞" }}{{ end }}{{ if ne .memento.session "" }} {{ action "ceiling.clear" "↺" }}{{ end }}{{ end }}`,bg:`{{ if ne .memento.error "" }}{{ color "error" }}{{ else }}{{ tint }}{{ end }}`,when:`{{ or (ge .memento.ceiling 0) (ne .memento.error "") }}`},autocompact:{group:`model-context`,description:`Claude Code's auto-compact window: − and + move it by 100K, ↺ returns it to auto. Clicks type /autocompact into this session, so the controls show only inside tmux.`,template:VR.template,bg:VR.bg,when:VR.when},metrics:{group:`activity`,description:`Response times, session duration, message count, and lines added/removed.`,template:`{{ if .metrics.lastResponseTime }} Δ {{ template "formatResponseTime" .metrics.lastResponseTime }}{{ end }}{{ if .metrics.responseTime }} ⧖ {{ template "formatResponseTime" .metrics.responseTime }}{{ end }}{{ if .metrics.sessionDuration }} ⧗ {{ template "formatDuration" .metrics.sessionDuration }}{{ end }}{{ if .metrics.messageCount }} ◆ {{ .metrics.messageCount }}{{ end }}{{ if .metrics.linesAdded }} + {{ .metrics.linesAdded }}{{ end }}{{ if .metrics.linesRemoved }} - {{ .metrics.linesRemoved }}{{ end }} `,when:`{{ or (gt .metrics.lastResponseTime 0.0) (gt .metrics.responseTime 0.0) (gt .metrics.sessionDuration 0.0) (gt .metrics.messageCount 0) (gt .metrics.linesAdded 0) (gt .metrics.linesRemoved 0) }}`},activity:{group:`activity`,description:`What Claude is doing: the slash command that opened the turn, the in-progress todo, and the tools in flight.`,template:`{{ if .activity.command }} ⌘ {{ .activity.command }}{{ end }}{{ if .activity.todo.total }}{{ if .activity.todo.active }} ☐ {{ .activity.todo.position }}/{{ .activity.todo.total }} {{ abbrev 32 .activity.todo.active }}{{ else }} ☑ {{ .activity.todo.completed }}/{{ .activity.todo.total }}{{ end }}{{ end }}{{ if .activity.tool.running }} ⟳ {{ template "formatToolTally" .activity.tool.running }}{{ end }}{{ if .activity.tool.done }} ✓ {{ template "formatToolTally" .activity.tool.done }}{{ end }} `,when:`{{ or (ne .activity.command "") (gt .activity.todo.total 0) (ne .activity.tool.running "") (ne .activity.tool.done "") }}`}},root:{rows:{identity:{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`host`},{kind:`segment`,name:`directory`},{kind:`segment`,name:`gitaculous`}]},status:{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`model`},{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`context`},{kind:`segment`,name:`ceiling`},{kind:`segment`,name:`autocompact`}]},{kind:`segment`,name:`cacheTimer`},{kind:`segment`,name:`block`},{kind:`segment`,name:`weekly`},{kind:`segment`,name:`activity`}]}}},actions:{...rj(``).actions,...BR.actions,copyDir:{copy:`{{ .current_dir }}`},stepTheme:{set:`theme`,from:`themes`},gitDetail:{set:`git-detail`,cycle:[`collapsed`,`expanded`]},"ceiling.raise":{ceiling:`set`,to:`+100_000`},"ceiling.lower":{ceiling:`set`,to:`-100_000`},"ceiling.off":{ceiling:`set`,to:`off`},"ceiling.clear":{ceiling:`clear`},...VR.actions},styles:{none:{hueShift:0,chromaScale:1,lightnessScale:1,lightnessShift:0},vivid:{hueShift:0,chromaScale:1.35,lightnessScale:1,lightnessShift:0},muted:{hueShift:0,chromaScale:.55,lightnessScale:1,lightnessShift:0},dim:{hueShift:0,chromaScale:1,lightnessScale:.85,lightnessShift:0},bright:{hueShift:0,chromaScale:1,lightnessScale:1,lightnessShift:.08},inverted:{hueShift:0,chromaScale:1,lightnessScale:-1,lightnessShift:1}},themeDefaults:zR,presets:{default:{},compact:{root:{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`directory`},{kind:`segment`,name:`gitaculous`},{kind:`segment`,name:`context`}]},globals:{padding:0}},verbose:{root:{kind:`container`,direction:`vertical`,children:[{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`directory`},{kind:`segment`,name:`gitaculous`},{kind:`segment`,name:`gitPr`}]},{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`model`},{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`context`},{kind:`segment`,name:`ceiling`},{kind:`segment`,name:`autocompact`}]},{kind:`segment`,name:`cacheTimer`},{kind:`segment`,name:`block`},{kind:`segment`,name:`weekly`},{kind:`segment`,name:`burnrate`}]},{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`speed`},{kind:`segment`,name:`tokenSparkline`}]}]}},zen:{root:{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`directory`},{kind:`segment`,name:`context`}]},globals:{endcaps:`plain`,style:`dim`}},git:{root:{kind:`container`,direction:`vertical`,children:[{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`host`},{kind:`segment`,name:`directory`},{kind:`segment`,name:`gitaculous`},{kind:`segment`,name:`gitPr`}]},{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`model`},{kind:`segment`,name:`context`},{kind:`segment`,name:`activity`}]}]}},usage:{root:{kind:`container`,direction:`vertical`,children:[{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`model`},{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`context`},{kind:`segment`,name:`ceiling`},{kind:`segment`,name:`autocompact`}]},{kind:`segment`,name:`cacheTimer`}]},{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`block`},{kind:`segment`,name:`weekly`},{kind:`segment`,name:`burnrate`}]},{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`session`},{kind:`segment`,name:`today`},{kind:`segment`,name:`speed`},{kind:`segment`,name:`tokenSparkline`}]}]}},dense:{root:{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`host`},{kind:`segment`,name:`directory`},{kind:`segment`,name:`gitaculous`},{kind:`segment`,name:`model`},{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`context`},{kind:`segment`,name:`ceiling`},{kind:`segment`,name:`autocompact`}]},{kind:`segment`,name:`cacheTimer`},{kind:`segment`,name:`block`},{kind:`segment`,name:`weekly`},{kind:`segment`,name:`session`},{kind:`segment`,name:`activity`}]},globals:{padding:0}}},editGlobals:{endcaps:`plain`,default_separator:` | `},helpers:{effortGauge:`{{ \$ord := default 0 (get (dict "low" 1 "medium" 2 "high" 3 "xhigh" 4 "max" 5) .effort.level) }}{{ \$glyphs := compact (splitList " " .effort.glyphs) }}{{ $bubble := readableOn (mix (bgOf) (color "accent") 40) (bgOf) 1.08 }}{{ $climbing := readableOn (stepped 1 (color "primary") 1 (color "secondary") 1 (color "accent")) $bubble ${bm} }}{{ \$climb := frames 1 (index \$glyphs 1) 1 (index \$glyphs 3) 1 (index \$glyphs 4) }}{{ if eq \$ord 5 }}{{ fg \$bubble "" }}{{ bg \$bubble (fg \$climbing \$climb) }}{{ fg \$bubble "" }}{{ else }}{{ fg (ramp $ord "step" 0 (${wk}) 2 (readableOn (color "accent") (bgOf) ${bm})) (index $glyphs $ord) }}{{ end }}`,gitPaint:`{{ fg (readableOn (color .color) (bgOf) ${bm}) .text }}`,gitCollapsed:`{{ template "gitBranch" . }}{{ template "gitAheadBehind" . }}{{ template "gitFlags" . }}`,gitExpanded:`(git){{ template "gitRepo" . }}{{ template "gitOperation" . }}{{ template "gitSha" . }}{{ template "gitFlags" . }} {{ template "gitBranch" . }}{{ template "gitUpstream" . }}{{ template "gitStash" . }}{{ template "gitAge" . }}`,gitBranch:`⎇ {{ template "gitPaint" (dict "color" .git.color.branch "text" .git.branch) }}`,gitRepo:`{{ if and .settings.repo (ne .git.repoName "") }} {{ .git.repoName }}{{ end }}`,gitOperation:`{{ if and .settings.operation (ne .git.operation "") }} [{{ .git.operation }}]{{ end }}`,gitSha:`{{ if and .settings.sha (ne .git.sha "") }} {{ .git.sha }}{{ end }}`,gitFlags:`{{ if and .settings.flags (or (gt .git.staged 0) (gt .git.unstaged 0) (gt .git.untracked 0) (gt .git.conflicts 0)) }} {{ if gt .git.staged 0 }}{{ template "gitPaint" (dict "color" .git.color.staged "text" "S") }}{{ end }}{{ if gt .git.unstaged 0 }}{{ template "gitPaint" (dict "color" .git.color.unstaged "text" "U") }}{{ end }}{{ if gt .git.untracked 0 }}{{ template "gitPaint" (dict "color" .git.color.untracked "text" "?") }}{{ end }}{{ if gt .git.conflicts 0 }}{{ template "gitPaint" (dict "color" .git.color.conflicts "text" (printf "!%v" .git.conflicts)) }}{{ end }}{{ end }}`,gitAheadBehind:`{{ if and .settings.aheadBehind (or (gt .git.ahead 0) (gt .git.behind 0)) }} {{ if gt .git.ahead 0 }}{{ template "gitPaint" (dict "color" .git.color.ahead "text" (printf "+%v" .git.ahead)) }}{{ end }}{{ if and (gt .git.ahead 0) (gt .git.behind 0) }}/{{ end }}{{ if gt .git.behind 0 }}{{ template "gitPaint" (dict "color" .git.color.behind "text" (printf "-%v" .git.behind)) }}{{ end }}{{ end }}`,gitUpstream:`{{ if and .settings.upstream (ne .git.upstream "") }} [{{ .git.upstream }}{{ template "gitAheadBehind" . }}]{{ end }}`,gitStash:`{{ if and .settings.stash (gt .git.stash 0) }} {{ template "gitPaint" (dict "color" .git.color.stash "text" (printf "(%v stashed)" .git.stash)) }}{{ end }}`,gitAge:`{{ if and .settings.age (gt .git.timeSinceCommit 0) }} ◷ {{ template "formatTimeSince" .git.timeSinceCommit }}{{ end }}`,formatCost:'{{ if lt . 0.01 }}<$0.01{{ else }}${{ printf "%.2f" . }}{{ end }}',formatTokenCount:xj(`.`),formatTokens:`{{ template "formatTokenCount" . }} tokens`,formatToolTally:`{{ $names := splitList "," . }}{{ range $i, $pair := $names }}{{ if lt $i 2 }}{{ if $i }} {{ end }}{{ $kv := splitList ":" $pair }}{{ index $kv 0 }}{{ if ne (index $kv 1) "1" }}×{{ index $kv 1 }}{{ end }}{{ end }}{{ end }}{{ if gt (len $names) 2 }} +{{ sub (len $names) 2 }}{{ end }}`,formatRate:`{{ if lt . 0 }}—/hr{{ else }}{{ template "formatCost" . }}/hr{{ end }}`,formatEta:`{{ if lt . 0 }}—{{ else }}{{ template "formatLongTimeRemaining" . }}{{ end }}`,formatSpeed:`{{ if lt . 0 }}—{{ else }}{{ template "formatTokenCount" (round .) }}/s{{ end }}`,formatTokenBreakdown:`{{ $first := true }}{{ if gt .input 0 }}{{ template "formatTokenCount" .input }} in{{ $first = false }}{{ end }}{{ if gt .output 0 }}{{ if not $first }} + {{ end }}{{ template "formatTokenCount" .output }} out{{ $first = false }}{{ end }}{{ if or (gt .cacheCreation 0) (gt .cacheRead 0) }}{{ if not $first }} + {{ end }}{{ template "formatTokenCount" (add .cacheCreation .cacheRead) }} cached{{ $first = false }}{{ end }}{{ if $first }}0 tokens{{ end }}`,budgetStatus:`{{ if or (le .budget 0) (lt .cost 0) }}{{ else }}{{ $pct := minf 100 (mulf (divf .cost .budget) 100) }}{{ $p := printf "%.0f%%" $pct }}{{ if ge $pct .warn }} !{{ $p }}{{ else }}{{ if ge $pct 50 }} +{{ $p }}{{ else }} {{ $p }}{{ end }}{{ end }}{{ end }}`,formatTimeSince:`{{ if lt . 60 }}{{ . }}s{{ else if lt . 3600 }}{{ div . 60 }}m{{ else if lt . 86400 }}{{ div . 3600 }}h{{ else if lt . 604800 }}{{ div . 86400 }}d{{ else }}{{ div . 604800 }}w{{ end }}`,formatDuration:`{{ if lt . 60 }}{{ printf "%.0f" . }}s{{ else if lt . 3600 }}{{ printf "%.0f" (divf . 60) }}m{{ else if lt . 86400 }}{{ printf "%.1f" (divf . 3600) }}h{{ else }}{{ printf "%.1f" (divf . 86400) }}d{{ end }}`,formatResponseTime:`{{ if lt . 60 }}{{ printf "%.1f" . }}s{{ else }}{{ printf "%.1f" (divf . 60) }}m{{ end }}`,formatLongTimeRemaining:`{{ if ge . 1440 }}{{ $d := div . 1440 }}{{ $h := div (mod . 1440) 60 }}{{ if gt $h 0 }}{{ $d }}d {{ $h }}h{{ else }}{{ $d }}d{{ end }}{{ else if ge . 60 }}{{ $h := div . 60 }}{{ $m := mod . 60 }}{{ if gt $m 0 }}{{ $h }}h {{ $m }}m{{ else }}{{ $h }}h{{ end }}{{ else }}{{ . }}m{{ end }}`,formatResetCountdown:`{{ template "formatLongTimeRemaining" (add 1 (minutesUntilReset .)) }}`}},YR=new Set([JR.globals.palette,...Object.keys(JR.themeDefaults),...Object.values(JR.segments).map(e=>e.palette)].filter(e=>e!==void 0)),XR=iP(MR(`<default>`,JSON.stringify(JR),YR),JR),ZR=R_(XR.presets);function QR(e){return ZR.includes(e)}const $R=Object.freeze({});function ez(e,t){return e.kind===`decided`?t[e.name]??$R:$R}function tz(e,t){return{...e,...Object.fromEntries(i_.map(n=>[n,e[n]??t[n]]))}}function nz(e){if(!e)return``;try{return rz(g(e))}catch{return``}}function rz(e){return`${e.mtimeMs}:${e.size}`}const iz=new class{slots;head=null;tail=null;constructor(e){this.slots=e}async run(e){await this.acquire();try{return await e()}finally{this.release()}}async acquire(){if(this.slots>0){this.slots--;return}await new Promise(e=>{let t={wake:e,next:null};this.tail?this.tail.next=t:this.head=t,this.tail=t})}release(){let e=this.head;if(!e){this.slots++;return}this.head=e.next,this.head||(this.tail=null),e.wake()}}(8);function az(e){return((...t)=>iz.run(()=>e(...t)))}const oz=az(le),sz=az(ce),cz=az(ue);async function lz(e,t){return iz.run(async()=>{let n=null;try{n=await se(e,`r`);let r=await n.stat(),{size:i,ino:a}=r,o=rz(r),s=t!==void 0&&(a!==t.ino||i<t.offset),c=s||t===void 0?0:t.offset;if(c>=i)return L({buf:Buffer.alloc(0),start:c,size:i,stamp:o,ino:a,reset:s});let l=Buffer.alloc(i-c),u=0;for(;u<l.length;){let{bytesRead:e}=await n.read(l,u,l.length-u,c+u);if(e===0)break;u+=e}return L({buf:u===l.length?l:l.subarray(0,u),start:c,size:i,stamp:o,ino:a,reset:s})}catch(t){return t.code===`ENOENT`?R:z(`readAppended ${e}: ${t instanceof Error?t.message:String(t)}`)}finally{await n?.close().catch(e=>{k(`transcript-fs: close failed: ${e instanceof Error?e.message:String(e)}`)})}})}async function uz(e,t){return iz.run(async()=>{let n=null;try{n=await se(e,`r`);let{size:r}=await n.stat(),i=Math.max(0,r-t),a=Buffer.alloc(r-i),o=0;for(;o<a.length;){let{bytesRead:e}=await n.read(a,o,a.length-o,i+o);if(e===0)break;o+=e}return L({buf:o===a.length?a:a.subarray(0,o),fromStart:i===0})}catch(t){return t.code===`ENOENT`?R:z(`readTail ${e}: ${t instanceof Error?t.message:String(t)}`)}finally{await n?.close().catch(e=>{k(`transcript-fs: close failed: ${e instanceof Error?e.message:String(e)}`)})}})}function dz(e,t){let n;try{n=p(e,l.O_RDONLY|l.O_NONBLOCK)}catch(e){return e.code===`ENOENT`?R:z(e instanceof Error?e.message:String(e))}try{let{size:e}=f(n),r=Math.max(0,e-t),i=Buffer.alloc(e-r),a=0;for(;a<i.length;){let e=m(n,i,a,i.length-a,r+a);if(e===0)break;a+=e}return L({buf:i.subarray(0,a),fromStart:r===0})}catch(e){return z(e instanceof Error?e.message:String(e))}finally{try{c(n)}catch(e){k(`transcript-fs: close failed: ${e instanceof Error?e.message:String(e)}`)}}}const fz=/"(?:cache_read_input_tokens|cache_creation_input_tokens)":[1-9]/;function pz(e){let t;try{t=JSON.parse(e)}catch{return null}let n=t.message?.usage;if(!((n?.cache_read_input_tokens??0)>0||(n?.cache_creation_input_tokens??0)>0))return null;let r=t.timestamp==null?NaN:Date.parse(t.timestamp);return Number.isNaN(r)?null:r}async function mz(e){let t=await hz(e);return t.kind===`ok`?L(Math.floor((t.value+36e5)/1e3)):t}async function hz(e){for(let t of[65536,1048576]){let n=await uz(e,t);if(n.kind!==`ok`)return n;let r=gz(n.value.buf,n.value.fromStart);if(r!=null)return L(r);if(n.value.fromStart)return R}return R}function gz(e,t){let n=e.toString(`utf8`).split(`
|
|
178
|
+
`),r=+!t;for(let e=n.length-1;e>=r;e--){let t=n[e];if(!t||!fz.test(t))continue;let r=pz(t);if(r!=null)return r}return null}function _z(e,t){return{...e,claudeConfigDir:Si(t.claudeConfigDir),env:t.mementoEnv}}const vz=v.join(`lib`,`ceiling_config.py`),yz=v.join(`skills`,`ceiling`,`bin`,`ceiling`);function bz(e,t){let n=typeof e==`object`&&e?e.plugins:void 0;if(typeof n!=`object`||!n)throw Error(`${t} has no "plugins" object`);return Object.entries(n).filter(([e])=>e.split(`@`)[0]===`memento`).flatMap(([e,n])=>{if(!Array.isArray(n))throw Error(`${t}: "${e}" is not a list of installs`);return n.map(n=>{let{scope:r,installPath:i,projectPath:a}=n??{};if(typeof r!=`string`||typeof i!=`string`)throw Error(`${t}: an install of "${e}" has no scope/path`);return typeof a==`string`?{key:e,scope:r,installPath:i,projectPath:a}:{key:e,scope:r,installPath:i}})})}function xz(e,t){let n=!0;for(let r of e){if(!s.existsSync(r))continue;let e;try{e=JSON.parse(s.readFileSync(r,`utf8`))?.enabledPlugins?.[t]}catch(e){return z(`memento lookup: ${r}: ${e.message}`)}typeof e==`boolean`&&(n=e)}return L(n)}function Sz(e,t){if(!s.existsSync(e))return R;let n;try{n=bz(JSON.parse(s.readFileSync(e,`utf8`)),e)}catch(e){return z(`memento lookup: ${e.message}`)}let r=n.find(e=>e.projectPath===t)??n.find(e=>e.scope===`user`);if(r===void 0)return R;let i=xz([v.join(v.dirname(v.dirname(e)),`settings.json`),v.join(t,`.claude`,`settings.json`),v.join(t,`.claude`,`settings.local.json`)],r.key);if(i.kind!==`ok`)return i;if(!i.value)return R;let a=[vz,yz].filter(e=>!s.existsSync(v.join(r.installPath,e)));return a.length===0?L(r.installPath):z(`memento at ${r.installPath} has no ${a.join(` or `)} — upgrade the plugin`)}function Cz(e,t=process.env){let n=new Set([`CLAUDE_PROJECT_DIR`,`CLAUDE_CODE_SESSION_ID`,...e.env===void 0?[]:ot]);return{...Object.fromEntries(Object.entries(t).filter(([e])=>!n.has(e))),...e.env,CLAUDE_CODE_SESSION_ID:e.sessionId,CLAUDE_PROJECT_DIR:e.projectDir||e.cwd}}function wz(e){return e.stderr.trim()||e.error||`${e.reason}${e.exitCode===null?``:` (exit ${e.exitCode})`}`}function Tz(e){let t;try{t=JSON.parse(e)}catch{return z(`memento read: not JSON: ${e.trim()}`)}let{ceiling:n,session:r}=t??{},i=n===`off`||typeof n==`number`&&n>=0?n:void 0;return i!==void 0&&(r===null||typeof r==`string`)?L({ceiling:i,session:r}):z(`memento read: unexpected answer: ${e.trim()}`)}async function Ez(e,t){let n=await Le({bin:`python3`,args:[`-c`,`
|
|
179
179
|
import json, math, sys
|
|
180
180
|
sys.path.insert(0, sys.argv[1])
|
|
181
181
|
from ceiling_config import CONFIG_NAME, anchored, ceiling_in, in_force, session_directory
|
|
@@ -184,19 +184,19 @@ ceiling = in_force(directory, anchored(sys.argv[3]))
|
|
|
184
184
|
layer = ceiling_in(directory / CONFIG_NAME)
|
|
185
185
|
print(json.dumps({"ceiling": "off" if ceiling == math.inf else ceiling,
|
|
186
186
|
"session": layer.text if layer else None}))
|
|
187
|
-
`,v.join(e,`lib`),t.sessionId,t.cwd],env:
|
|
188
|
-
`).at(-1).trim();function
|
|
189
|
-
`),c=I([{verb:Ln,args:[s]}]),l=t.kind===`running`?_g(`[${i.busy}]`,c):_g(`[${i.act}]`,I([{verb:Xn,args:[n.sessionId]}]));return[{severity:gg,message:s,lines:[[_g(a,c),l,_g(`[dismiss]`,I([{verb:jn,args:[n.sessionId,WB,r]}])),_g(`[disable]`,I([{verb:Rn,args:[n.sessionId,GB,`false`]},{verb:jn,args:[n.sessionId,KB,`false`]}]))],...o.map(e=>[_g(e,c)])]}]}function $B(e,t){return e.kind===`stale`?{kind:`source`,root:e.root,newer:e.source,running:e.running}:e.kind===`not-source-checkout`&&t!==null&&t.kind===`stale`?{kind:`release`,newer:t.latest,running:t.installed}:null}function eV(e){switch(e.kind){case`current`:return[`info`,`build: current ${JB(e.stamp)}`];case`stale`:return[`info`,`build: stale — source ${JB(e.source)}, running ${JB(e.running)}`];case`not-source-checkout`:return[`info`,`build: not a source checkout`];case`unchecked`:return[`warn`,`build: unchecked: ${e.reason}`]}}function tV(e){switch(e.kind){case`current`:return[`info`,`release: current ${Mi(e.installed)}`];case`stale`:return[`info`,`release: stale — latest ${Mi(e.latest)}, running ${Mi(e.installed)}`];case`ahead`:return[`info`,`release: ahead — running ${Mi(e.installed)}, latest ${Mi(e.latest)}`];case`unchecked`:return[`warn`,`release: unchecked: ${e.reason}`]}}function nV(e){let t=null;return([n,r])=>{r!==t&&(t=r,e(n,r))}}const rV=e=>e.split(/\r?\n/).map(e=>e.trim()).filter(e=>e!==``).at(-1);function iV(e){let t=e.exitCode===null?``:` (exit ${e.exitCode})`,n=rV(e.stderr)??e.error??rV(e.stdout)??`no output`;return`${e.reason}${t}: ${n}`}function aV(){let e=[KN(GB,[`false`]),LB(KB,[`false`]),LB(WB,[])];return()=>e.forEach(e=>e())}function oV(e){let{entryUrl:t,intervalMs:n,releaseIntervalMs:r,registryUrl:i,fetchImpl:a,onApplied:o,log:s}=e,c={kind:`unchecked`,reason:`not sampled yet`},l=null,u=XB,d=null,f=nV(s),p=nV(s),m=()=>$B(c,l);function h(){let e=m(),t=e===null?null:qB(e);(d===null?null:d.identity)!==t&&(d?.dispose(),d=t===null?null:{identity:t,dispose:LB(WB,[t])})}function g(){c=Lg(t,Pg),f(eV(c)),h()}async function _(){l=Ii(Ft,await Fi(Pi,a,i)),p(tV(l)),h()}return{arm(){aV(),g(),setInterval(g,n).unref(),c.kind===`not-source-checkout`&&(_(),setInterval(()=>void _(),r).unref())},notice:e=>QB(m(),u,e),act(){let e=m();if(e===null)throw new q(`apply-update: nothing newer is known to apply`);let t=YB(e);if(u.kind===`running`)throw new q(`apply-update: already ${t.busy}`);u=ZB,s(`info`,`apply-update: ${t.act} — ${t.command.bin} ${t.command.args?.join(` `)??``}`),Le({...t.command,category:`update.apply`,timeoutMs:6e5}).then(n=>{if(n.ok){u=XB,s(`info`,`apply-update: ${t.act} succeeded`),g(),o();return}let r=iV(n);u={kind:`failed`,identity:qB(e),reason:r},s(`error`,`apply-update: ${t.act} failed: ${r}`)})}}}var sV=class{static CACHE_DIR=We();static USAGE_CACHE_DIR=v.join(this.CACHE_DIR,`usage`);static LOCKS_DIR=v.join(this.CACHE_DIR,`locks`);static isLocked(e){let t=v.join(this.LOCKS_DIR,e);if(!s.existsSync(t))return!1;try{let n=s.readFileSync(t,`utf-8`),r=parseInt(n.trim(),10);if(isNaN(r))return k(`Invalid PID in lock file ${e}, removing stale lock`),s.unlinkSync(t),!1;try{return process.kill(r,0),!0}catch(n){return n.code===`ESRCH`?(k(`Removing stale lock file ${e} for dead process ${r}`),s.unlinkSync(t),!1):(k(`Error checking process ${r} for lock ${e}:`,n),!0)}}catch(t){return k(`Error reading lock file ${e}:`,t),!0}}static async acquireLock(e,t=5e3){await this.ensureCacheDirectories();let n=v.join(this.LOCKS_DIR,e),r=Date.now(),i=String(process.pid);for(;Date.now()-r<t;)try{return await s.promises.writeFile(n,i,{flag:`wx`}),k(`Lock acquired for ${e}`),!0}catch(e){if(e.code===`EEXIST`)await he(50);else throw e}return k(`Failed to acquire lock for ${e} within ${t}ms`),!1}static async releaseLock(e){let t=v.join(this.LOCKS_DIR,e);try{await s.promises.unlink(t),k(`Lock released for ${e}`)}catch(t){t.code!==`ENOENT`&&k(`Error releasing lock for ${e}:`,t)}}static async ensureCacheDirectories(){try{await Promise.all([s.promises.mkdir(this.CACHE_DIR,{recursive:!0}),s.promises.mkdir(this.USAGE_CACHE_DIR,{recursive:!0}),s.promises.mkdir(this.LOCKS_DIR,{recursive:!0})])}catch(e){k(`Failed to create cache directories:`,e)}}static createProjectHash(e){return ae(`md5`).update(e).digest(`hex`).substring(0,8)}static async getUsageCache(e,t){await this.ensureCacheDirectories();let n=v.join(this.USAGE_CACHE_DIR,`${e}.json`),r=`${e}.usage.lock`;for(let i=0;i<3;i++){if(this.isLocked(r)){k(`Cache for ${e} is locked, waiting...`),await he(75);continue}try{let r=await s.promises.readFile(n,`utf-8`),i=JSON.parse(r);return!t||i.timestamp>=t?(k(`[CACHE-HIT] ${e} disk cache: found`),this.deserializeDates(i.data)):(k(`${e} cache outdated: cache=${i.timestamp}, latest=${t}`),null)}catch(t){if(t.code===`ENOENT`)return k(`No shared ${e} usage cache found`),null;k(`Attempt ${i+1} failed to read ${e} cache: ${t.message}. Retrying...`),await he(75)}}return k(`Failed to read ${e} cache after 3 attempts.`),null}static deserializeDates(e){return Array.isArray(e)?e.map(e=>({...e,timestamp:new Date(e.timestamp)})):e}static async setUsageCache(e,t,n){let r=`${e}.usage.lock`;if(!await this.acquireLock(r)){k(`Could not acquire lock to set usage cache for ${e}`);return}try{await this.ensureCacheDirectories();let r=v.join(this.USAGE_CACHE_DIR,`${e}.json`),i=JSON.stringify({data:t,timestamp:n||Date.now()});await s.promises.writeFile(r,i,`utf-8`),k(`[CACHE-SET] ${e} disk cache stored`)}catch(t){k(`Failed to save ${e} usage cache:`,t)}finally{await this.releaseLock(r)}}};const cV={"claude-haiku-4-5-20251001":{name:`Claude Haiku 4.5`,input:1,output:5,cache_write_5m:1.25,cache_write_1h:2,cache_read:.1},"claude-haiku-4-5":{name:`Claude Haiku 4.5`,input:1,output:5,cache_write_5m:1.25,cache_write_1h:2,cache_read:.1},"claude-opus-4-20250514":{name:`Claude Opus 4`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-opus-4-1":{name:`Claude Opus 4.1`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-opus-4-1-20250805":{name:`Claude Opus 4.1`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-sonnet-4-20250514":{name:`Claude Sonnet 4`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-4-opus-20250514":{name:`Claude 4 Opus`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-4-sonnet-20250514":{name:`Claude 4 Sonnet`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-sonnet-4-5":{name:`Claude Sonnet 4.5`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-sonnet-4-5-20250929":{name:`Claude Sonnet 4.5`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-opus-4-5":{name:`Claude Opus 4.5`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-opus-4-5-20251101":{name:`Claude Opus 4.5`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-opus-4-6":{name:`Claude Opus 4.6`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-opus-4-6-20260205":{name:`Claude Opus 4.6`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-sonnet-4-6":{name:`Claude Sonnet 4.6`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3}};var lV=class{static executionCache=null;static modelPricingCache=new Map;static GITHUB_PRICING_URL=`https://raw.githubusercontent.com/promptctl/cc-candybar/main/pricing.json`;static async loadDiskCache(){let e=Date.now()-1440*60*1e3;return await sV.getUsageCache(`pricing`,e)}static async saveDiskCache(e){await sV.setUsageCache(`pricing`,e)}static async fetchPricingData(){return new Promise(e=>{let t=new n(this.GITHUB_PRICING_URL),r=me({hostname:t.hostname,path:t.pathname,headers:{"User-Agent":`cc-candybar`,"Cache-Control":`no-cache`},timeout:5e3},t=>{if(t.statusCode!==200){k(`HTTP ${t.statusCode}: ${t.statusMessage}`),e(null);return}let n=``,i=0;t.on(`data`,t=>{if(i+=t.length,i>1048576){k(`Response too large`),r.destroy(),e(null);return}n+=t}),t.on(`end`,()=>{try{let t=JSON.parse(n),r=t._meta,i={};for(let[e,n]of Object.entries(t))e!==`_meta`&&(i[e]=n);this.validatePricingData(i)?(k(`Fetched fresh pricing from GitHub for ${Object.keys(i).length} models`),k(`Pricing last updated: ${r?.updated||`unknown`}`),e(i)):(k(`Invalid pricing data structure`),e(null))}catch(t){k(`Failed to parse JSON:`,t),e(null)}}),t.on(`error`,t=>{k(`Response error:`,t),e(null)})});r.on(`error`,t=>{k(`Request error:`,t),e(null)}),r.on(`timeout`,()=>{k(`Request timeout`),r.destroy(),e(null)}),r.end()})}static async getCurrentPricing(){if(this.executionCache!==null)return k(`[CACHE-HIT] Pricing execution cache: ${Object.keys(this.executionCache).length} models`),this.executionCache;let e=await this.loadDiskCache();if(e)return k(`[CACHE-HIT] Pricing disk cache: ${Object.keys(e).length} models`),this.executionCache=e,k(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(e).length} models`),e;let t=await this.fetchPricingData();return t?(await this.saveDiskCache(t),k(`[CACHE-SET] Pricing disk cache stored: ${Object.keys(t).length} models`),this.executionCache=t,k(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(t).length} models`),t):(k(`[CACHE-FALLBACK] Using offline pricing data: ${Object.keys(cV).length} models`),this.executionCache=cV,k(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(cV).length} models`),cV)}static validatePricingData(e){if(!e||typeof e!=`object`)return!1;for(let[,t]of Object.entries(e)){if(!t||typeof t!=`object`)return!1;let e=t;if(typeof e.input!=`number`||typeof e.output!=`number`||typeof e.cache_read!=`number`)return!1}return!0}static async getModelPricing(e){if(this.modelPricingCache.has(e))return k(`[CACHE-HIT] Model pricing cache: ${e}`),this.modelPricingCache.get(e);let t=await this.getCurrentPricing(),n;return n=t[e]?t[e]:this.fuzzyMatchModel(e,t),this.modelPricingCache.set(e,n),k(`[CACHE-SET] Model pricing cache: ${e}`),n}static fuzzyMatchModel(e,t){let n=e.toLowerCase();for(let[e,r]of Object.entries(t))if(e.toLowerCase()===n)return r;for(let{pattern:e,fallback:r}of[{pattern:[`opus-4-6`,`claude-opus-4-6`],fallback:`claude-opus-4-6-20260205`},{pattern:[`opus-4-5`,`claude-opus-4-5`],fallback:`claude-opus-4-5-20251101`},{pattern:[`opus-4-1`,`claude-opus-4-1`],fallback:`claude-opus-4-1-20250805`},{pattern:[`opus-4`,`claude-opus-4`],fallback:`claude-opus-4-20250514`},{pattern:[`sonnet-4-6`,`sonnet-4.6`,`claude-sonnet-4-6`],fallback:`claude-sonnet-4-6`},{pattern:[`sonnet-4.5`,`4-5-sonnet`,`sonnet-4-5`],fallback:`claude-sonnet-4-5-20250929`},{pattern:[`sonnet-4`,`claude-sonnet-4`],fallback:`claude-sonnet-4-20250514`},{pattern:[`haiku-4.5`,`4-5-haiku`,`haiku-4-5`],fallback:`claude-haiku-4-5-20251001`},{pattern:[`haiku`],fallback:`claude-haiku-4-5-20251001`},{pattern:[`opus`],fallback:`claude-opus-4-20250514`},{pattern:[`sonnet`],fallback:`claude-sonnet-4-5-20250929`}])if(e.some(e=>n.includes(e))&&t[r])return t[r];return t[`claude-sonnet-4-5-20250929`]||{name:`${e} (Unknown Model)`,input:3,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3,output:15}}static async calculateCostForEntry(e){let t=e.message?.usage;if(!t)return 0;let n=this.extractModelId(e),r=await this.getModelPricing(n),i=t.input_tokens||0,a=t.output_tokens||0,o=t.cache_creation_input_tokens||0,s=t.cache_read_input_tokens||0,c=i/1e6*r.input,l=a/1e6*r.output,u=s/1e6*r.cache_read,d=o/1e6*r.cache_write_5m;return c+l+d+u}static extractModelId(e){if(e.model&&typeof e.model==`string`)return e.model;let t=e.message;if(t?.model){let e=t.model;if(typeof e==`string`)return e;let n=e;return(typeof n?.id==`string`?n.id:null)||`claude-sonnet-4-5-20250929`}return e.model_id&&typeof e.model_id==`string`?e.model_id:`claude-sonnet-4-5-20250929`}};const uV=/<command-name>\s*([^<\s][^<]*?)\s*<\/command-name>/;function dV(e){if(typeof e==`string`)return uV.exec(e)?.[1]}function fV(e){let t=e?.todos;if(!Array.isArray(t))return;let n=[];for(let e of t){if(typeof e!=`object`||!e)continue;let{content:t,activeForm:r,status:i}=e,a=i===`in_progress`,o=a&&typeof r==`string`?r:t;typeof o==`string`&&n.push({text:o,active:a,done:i===`completed`})}return n}function pV(e){return typeof e==`string`?e:Array.isArray(e)?e.find(e=>typeof e==`object`&&!!e&&e.type===`text`&&typeof e.text==`string`)?.text??``:``}function mV(e,t){let n=e.message?.content,r=[],i=[],a;if(Array.isArray(n))for(let e of n){if(typeof e!=`object`||!e)continue;let t=e;switch(t.type){case`tool_use`:{let{id:e,name:n}=t;if(typeof e!=`string`||typeof n!=`string`)break;r.push({id:e,name:n}),n===`TodoWrite`&&(a=fV(t.input)??a);break}case`tool_result`:{let e=t.tool_use_id;typeof e==`string`&&i.push(e);break}default:break}}let o=t===`prompt`?dV(pV(n)):void 0;if(!(r.length===0&&i.length===0&&a===void 0&&o===void 0))return{...r.length>0&&{started:r},...i.length>0&&{finished:i},...a!==void 0&&{todos:a},...o!==void 0&&{command:o}}}function hV(e){if(e!==void 0)return[e];let t=ee();return[S(t,`.config`,`claude`),S(t,`.claude`)].filter(e=>d(e))}async function gV(e){let t=[];for(let n of e){let e=S(n,`projects`);if(d(e))try{let n=await tz(e,{withFileTypes:!0});for(let r of n)if(r.isDirectory()){let n=S(e,r.name);t.push(n)}}catch(t){k(`Failed to read projects directory ${e}:`,t)}}return t}async function _V(e,t,n){let r=[],i=S(t,e,`subagents`);try{let t=(await tz(i)).filter(e=>e.startsWith(`agent-`)&&e.endsWith(`.jsonl`));for(let a of t){let t=S(i,a);if(n?.has(t)){r.push(t);continue}try{let n=(await nz(t,`utf-8`)).split(`
|
|
190
|
-
`)[0];n&&JSON.parse(n).sessionId===e&&r.push(t)}catch{k(`Failed to check agent file ${t}`)}}}catch(e){k(`Failed to read subagents directory ${i}:`,e)}return r}function
|
|
191
|
-
`)){let e=TV(n);e&&t.push(e)}return t}async function DV(e){return EV(await nz(e,`utf-8`))}async function OV(e,t){let n=await iz(e,t===void 0?void 0:{offset:t.offset,ino:t.ino});if(n.kind!==`ok`)return n;let{buf:r,start:i,stamp:a,ino:o,reset:s}=n.value,c=r.lastIndexOf(10);return L(c<0?{entries:[],cursor:{offset:i,stamp:a,ino:o},reset:s}:{entries:EV(r.subarray(0,c+1).toString(`utf-8`)),cursor:{offset:i+c+1,stamp:a,ino:o},reset:s})}async function kV(e){return new Promise((t,n)=>{let r=[],i=u(e,{encoding:`utf8`}),a=ge({input:i,crlfDelay:1/0});a.on(`line`,e=>{let t=TV(e);t&&r.push(t)}),a.on(`close`,()=>{t(r)}),a.on(`error`,t=>{k(`Streaming parser error for ${e}:`,t),n(t)}),i.on(`error`,t=>{k(`File stream error for ${e}:`,t),n(t)})})}var AV=class{inflight=new Map;run(e,t){return this.inflight.get(e)??this.start(e,t)}start(e,t){let n=t();this.inflight.set(e,n);let r=()=>{this.inflight.get(e)===n&&this.inflight.delete(e)};return n.then(r,r),n}get size(){return this.inflight.size}};function jV(e,t){let n=e?e.input+e.cacheCreation+e.cacheRead:0,r=e?e.output:0;return{input:n,output:r,total:n+r,atMs:t}}const MV=new Map,NV={cost:0,input:0,output:0,cacheCreation:0,cacheRead:0},PV={cost:null,calculatedCost:null,officialCost:null,tokens:null,tokenBreakdown:null};function FV(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function IV(){let e=new Date;return e.setHours(0,0,0,0),e.setDate(e.getDate()-1),e.getTime()}function LV(){return{input:0,output:0,cacheCreation:0,cacheRead:0}}async function RV(e,t,n,r){let i=FV(new Date(IV())),a=e&&!t?e:void 0,o=a?.entries??0,s=a?.cost??0,c=a?{...a.breakdown}:LV(),l=new Map;if(a)for(let[e,t]of a.days)e>=i&&l.set(e,{...t});for(let e of n){let t=e.message?.usage;if(!t)continue;o++;let n=e.costUSD??await lV.calculateCostForEntry(e.raw);s+=n,c.input+=t.input_tokens||0,c.output+=t.output_tokens||0,c.cacheCreation+=t.cache_creation_input_tokens||0,c.cacheRead+=t.cache_read_input_tokens||0;let r=FV(new Date(e.timestamp));if(r<i)continue;let a=l.get(r)??{...NV};a.cost+=n,a.input+=t.input_tokens||0,a.output+=t.output_tokens||0,a.cacheCreation+=t.cache_creation_input_tokens||0,a.cacheRead+=t.cache_read_input_tokens||0,l.set(r,a)}return{cursor:r,entries:o,cost:s,breakdown:c,days:l}}function zV(e){let t=0,n=0,r=LV(),i=new Map;for(let a of e.values()){t+=a.entries,n+=a.cost,r.input+=a.breakdown.input,r.output+=a.breakdown.output,r.cacheCreation+=a.breakdown.cacheCreation,r.cacheRead+=a.breakdown.cacheRead;for(let[e,t]of a.days){let n=i.get(e)??{...NV};n.cost+=t.cost,n.input+=t.input,n.output+=t.output,n.cacheCreation+=t.cacheCreation,n.cacheRead+=t.cacheRead,i.set(e,n)}}if(t===0)return{sessionInfo:PV,days:i};let a=r.input+r.output+r.cacheCreation+r.cacheRead;return{sessionInfo:{cost:n,calculatedCost:n,officialCost:null,tokens:a,tokenBreakdown:r},days:i}}async function BV(e,t,n){let r=0,i=async()=>{for(;r<e.length;){let t=e[r++];await n(t)}},a=Math.min(t,e.length);await Promise.all(Array.from({length:a},i))}var VV=class{sessions=new Map;flight=new AV;seeded=new Map;seededDay=``;rescanIntervalMs;speedFlight=new AV;staleAgeMs;log;renderTally={hits:0,misses:0};sweeps=0;scans={seed:0,rescan:0};sweepTimer=null;constructor(e={}){this.log=e.logger??Gt,this.staleAgeMs=e.staleAgeMs??864e5,this.rescanIntervalMs=e.rescanIntervalMs??6e4;let t=e.sweepIntervalMs??3e5;t>0&&(this.sweepTimer=setInterval(()=>this.sweepStale(),t),this.sweepTimer.unref())}getStats(){return{size:this.sessions.size,hits:this.renderTally.hits,misses:this.renderTally.misses,sweeps:this.sweeps,seeds:this.scans.seed,rescans:this.scans.rescan}}async getUsageInfo(e,t){let n=await this.ingest(e,t?.transcript_path,this.renderTally);if(n.kind===`failed`)return n;let r=n.kind===`ok`?n.value.sessionInfo:PV,i=t?.cost?.total_cost_usd??null;return L({session:{...r,cost:i??r.cost,officialCost:i}})}async getTodayInfo(e,t,n){let r=FV(xE(n)),i=hV(t);try{await this.ensureSeeded(r,i,n*1e3)}catch(e){return z(`usage seed: ${e instanceof Error?e.message:String(e)}`)}let a=await this.ingest(e?.session_id??``,e?.transcript_path,this.renderTally);if(a.kind===`failed`)return a;let o=i.map(e=>S(e,`projects`)+C),s={...NV},c=!1;for(let[t,{record:n}]of this.sessions){let i=n?.transcriptPath??``,a=t===e?.session_id||o.some(e=>i.startsWith(e))?n?.days??MV:MV;c||=a.has(r);let l=a.get(r)??NV;s.cost+=l.cost,s.input+=l.input,s.output+=l.output,s.cacheCreation+=l.cacheCreation,s.cacheRead+=l.cacheRead}return c?L({cost:s.cost,tokens:s.input+s.output+s.cacheCreation+s.cacheRead,tokenBreakdown:{input:s.input,output:s.output,cacheCreation:s.cacheCreation,cacheRead:s.cacheRead},date:r}):R}async observeSpeed(e,t,n){if(!e)return R;let r=ZR(t);return this.speedFlight.run(`${e}:${r}`,async()=>{let i=await this.ingest(e,t,this.renderTally,r);if(i.kind===`failed`)return i;let a=jV(i.kind===`ok`?i.value.sessionInfo.tokenBreakdown:null,n),{ring:o}=this.hold(e),s;for(let e of o)e.atMs<a.atMs&&(s===void 0||e.atMs>s.atMs)&&(s=e);return o.push(a),o.sort((e,t)=>e.atMs-t.atMs),o.length>64&&o.shift(),L({...s!==void 0&&{prev:s},cur:a,samples:[...o]})})}async ingest(e,t,n,r){if(!e)return R;let i=r??ZR(t),a=this.see(e)?.record;if(a&&i!==``&&a.transcriptStamp===i)return n.hits++,L(a);if(!t)return a?L(a):R;n.misses++;let o;try{o=await this.flight.run(`${e}:${i}`,async()=>{let n=this.sessions.get(e)?.record;return{prior:n,outcome:await this.refold(e,t,n)}})}catch(t){return z(`usage refold (${e}): ${t instanceof Error?t.message:String(t)}`)}let{prior:s,outcome:c}=o;if(c.kind!==`ok`)return c;let l={files:c.value.files,sessionInfo:c.value.sessionInfo,days:c.value.days,transcriptStamp:c.value.mainStamp,transcriptPath:t};return this.sessions.get(e)?.record===s&&(this.hold(e).record=l),L(l)}see(e){let t=this.sessions.get(e);return t&&(t.lastSeenAt=Date.now()),t}hold(e){let t=this.see(e);if(t)return t;let n={lastSeenAt:Date.now(),record:void 0,ring:[]};return this.sessions.set(e,n),n}async refold(e,t,n){let r=await _V(e,b(t),n===void 0?void 0:new Set(n.files.keys())),i=new Map,a=``;for(let e of[t,...r]){let r=n?.files.get(e),o=await OV(e,r?.cursor);if(o.kind===`failed`)return o;if(o.kind===`absent`){r&&i.set(e,r);continue}let{entries:s,cursor:c,reset:l}=o.value;i.set(e,await RV(r,l,s,c)),e===t&&(a=c.stamp)}return L({files:i,...zV(i),mainStamp:a})}ensureSeeded(e,t,n){this.seededDay!==e&&(this.seeded.clear(),this.seededDay=e);let r=t.join(`\0`),i=this.seeded.get(r);if(!i){let e=this.seed(t,`seed`),i={done:e,scanning:e,startedAtMs:n};return this.seeded.set(r,i),this.settle(r,i,e),e}return i.scanning===void 0&&n-i.startedAtMs>=this.rescanIntervalMs&&(i.startedAtMs=n,i.scanning=this.seed(t,`rescan`),this.settle(r,i,i.scanning)),i.done}settle(e,t,n){n.then(()=>{t.scanning=void 0},n=>{this.log(`warn`,`usageStore scan: ${n instanceof Error?n.message:String(n)}`),this.seeded.get(e)===t&&this.seeded.delete(e)})}async scanned(){await Promise.allSettled([...this.seeded.values()].map(e=>e.scanning))}async seed(e,t){let n=Date.now(),r=IV(),i=await gV(e),a=[];for(let e of i){let t;try{t=await tz(e)}catch{continue}for(let n of t){if(!n.endsWith(`.jsonl`))continue;let t=S(e,n),i;try{i=await rz(t)}catch{continue}i.mtimeMs<r||a.push({sessionId:n.slice(0,-6),path:t,stamp:QR(i)})}}let o={hits:0,misses:0};await BV(a,8,async e=>{let n=await this.ingest(e.sessionId,e.path,o,e.stamp);n.kind===`failed`&&this.log(`warn`,`usageStore ${t}: ${n.reason}`)}),this.log(`info`,`usageStore ${t} sessions=${a.length} read=${o.misses} dirs=${e.join(`,`)} ms=${Date.now()-n}`),this.scans[t]++}sweepStale(){let e=Date.now(),t=0,n=0,r=0;for(let[i,{lastSeenAt:a,record:o}]of this.sessions)if(!(e-a<=this.staleAgeMs)){if(o?.days.has(this.seededDay)){n++;continue}this.sessions.delete(i),t++,o===void 0&&r++}return t>0&&this.sweeps++,(t>0||n>0)&&this.log(`info`,`usageStore sweep dropped=${t} noRecord=${r} held=${n}`),t}close(){this.sweepTimer&&=(clearInterval(this.sweepTimer),null),this.sessions.clear(),this.seeded.clear()}},HV=class{thresholds={LOW:50,MEDIUM:80};getContextUsageThresholds(){return this.thresholds}ratioPercentages(e,t){let n=Math.min(100,Math.max(0,Math.round(e/t*100)));return{percentage:n,contextLeftPercentage:Math.max(0,100-n)}}calculateContextFromHookData(e){let t=e.context_window;if(!t?.current_usage)return k(`No current_usage in hook data, falling back to transcript parsing`),null;let n=t.current_usage,r=t.context_window_size,i=(n.input_tokens||0)+(n.cache_creation_input_tokens||0)+(n.cache_read_input_tokens||0);k(`Native current_usage: input=${n.input_tokens}, cache_create=${n.cache_creation_input_tokens}, cache_read=${n.cache_read_input_tokens}, total=${i} (limit: ${r})`);let a=this.ratioPercentages(i,r);return{totalTokens:i,maxTokens:r,percentage:t.used_percentage==null?a.percentage:Math.round(t.used_percentage),contextLeftPercentage:t.remaining_percentage==null?a.contextLeftPercentage:Math.round(t.remaining_percentage)}}async calculateContextTokensFromTranscript(e,t){try{k(`Calculating context tokens from transcript: ${e}`);let n=await SV(e);if(n.length===0)return k(`No entries in transcript`),R;let r=null;for(let e=n.length-1;e>=0;e--){let t=n[e];if(t&&t.message?.usage?.input_tokens&&t.isSidechain!==!0){r=t,k(`Context segment: Found most recent entry at ${t.timestamp.toISOString()}, stopping search`);break}}if(r?.message?.usage){let e=r.message.usage,n=(e.input_tokens||0)+(e.cache_read_input_tokens||0)+(e.cache_creation_input_tokens||0);return k(`Most recent main chain context: ${n} tokens (limit: ${t})`),L({totalTokens:n,maxTokens:t,...this.ratioPercentages(n,t)})}return k(`No main chain entries with usage data found`),R}catch(e){return z(`context transcript: ${e instanceof Error?e.message:String(e)}`)}}async getContextInfo(e){let t=this.calculateContextFromHookData(e);if(t)return L(t);let n=e.context_window?.context_window_size??2e5;return this.calculateContextTokensFromTranscript(e.transcript_path,n)}},UV=class{states=new Map;constructor(e,t,n=256){this.empty=e,this.step=t,this.maxSessions=n}async read(e,t){let n=this.states.get(e),r=ZR(t);if(n&&r!==``&&n.cursor.stamp===r)return this.touch(e,n),{kind:`ok`,value:n.value};let i=await OV(t,n?.cursor);if(i.kind===`failed`)return i;if(i.kind===`absent`)return{kind:`ok`,value:n?.value??this.empty};let{entries:a,cursor:o,reset:s}=i.value,c=s||n===void 0?this.empty:n.value;for(let e of a)c=this.step(c,e);for(this.touch(e,{cursor:o,value:c});this.states.size>this.maxSessions;){let e=this.states.keys().next().value;if(e===void 0)break;this.states.delete(e)}return{kind:`ok`,value:c}}touch(e,t){this.states.delete(e),this.states.set(e,t)}};const WV={messageCount:0,nonPrompts:0,recent:[]},GV=new Set([`turn`,`interrupt`,`claude-code`]);function KV(e,t){if(t.isSidechain)return e;let n=[...e.recent,t];return{messageCount:e.messageCount+ +(t.userEntry===`prompt`),nonPrompts:e.nonPrompts+ +!!GV.has(t.userEntry),recent:n.length>20?n.slice(-20):n}}function qV(e){let t=null,n=null;for(let r of e){let e=r.type||r.message?.role||r.message?.type;if(r.userEntry===`prompt`||r.userEntry===`turn`)t=r.timestamp;else if(e===`assistant`&&t){let e=(r.timestamp.getTime()-t.getTime())/1e3;e>.1&&e<300&&(n=e)}}return n}var JV=class{fold=new UV(WV,KV);async getMetricsInfo(e,t){if(k(`Getting metrics from hook data for session: ${e}`),!t.cost)return R;let n=await this.fold.read(e,t.transcript_path);return n.kind===`failed`?z(`metrics (${e}): ${n.reason}`):L({responseTime:t.cost.total_api_duration_ms/1e3,lastResponseTime:qV(n.value.recent),sessionDuration:t.cost.total_duration_ms/1e3,messageCount:n.value.messageCount,nonPrompts:n.value.nonPrompts,linesAdded:t.cost.total_lines_added,linesRemoved:t.cost.total_lines_removed})}};const YV={command:null,todos:[],pending:[],done:[]};function XV(e,t){let n=e.findIndex(e=>e.name===t);return n<0?[...e,{name:t,count:1}]:e.map((e,t)=>t===n?{name:e.name,count:e.count+1}:e)}function ZV(e,t){switch(t.userEntry){case`prompt`:return{...e,command:t.activity?.command??null,pending:[],done:[]};case`interrupt`:return{...e,pending:[]};case`turn`:case`tool-result`:case`claude-code`:case void 0:return e}}function QV(e,t){if(t.isSidechain)return e;let n=ZV(e,t),r=t.activity;if(r===void 0)return n;let i=n.pending,a=n.done;r.started!==void 0&&(i=[...i,...r.started]);for(let e of r.finished??[]){let t=i.findIndex(t=>t.id===e);t<0||(a=XV(a,i[t].name),i=[...i.slice(0,t),...i.slice(t+1)])}return{...n,pending:i,done:a,todos:r.todos??n.todos}}function $V(e){return{command:e.command,todos:e.todos,running:e.pending.reduce((e,t)=>XV(e,t.name),[]),done:e.done}}var eH=class{fold=new UV(YV,QV);async getActivityInfo(e,t){let n=await this.fold.read(e,t.transcript_path);return n.kind===`failed`?z(`activity (${e}): ${n.reason}`):L($V(n.value))}};function tH(e,t,n,r){return{bin:`tmux`,args:[`-S`,e.socket,...n],timeoutMs:2e3,category:t,stdinInput:r}}function nH(e,t){if(e.ok)return{kind:`ok`,stdout:e.stdout};if(e.reason===`rate-limited`)return{kind:`rate-limited`,reason:e.error??`rate-limited`};let n=e.error??[e.reason,e.stderr.trim()].filter(e=>e!==``).join(`: `);return{kind:`failed`,reason:`tmux ${t[0]} failed (${n})`}}function rH(e,t,n,r){return nH(Re(tH(e,t,n,r)),n)}async function iH(e,t,n){return nH(await Le(tH(e,t,n)),n)}const aH=e=>`${e.socket}\n${e.pane}`;var oH=class{names=new Map;asking=new AV;constructor(e=Date.now){this.now=e}getSessionName(e){let t=aH(e),n=this.names.get(t);if(n&&this.now()-n.at<3e4)return Promise.resolve(n.outcome);let r=this.asking.run(t,()=>this.ask(t,e));return n?Promise.resolve(n.outcome):r}async ask(e,t){k(`Getting tmux session name for pane ${t.pane} on ${t.socket}`);let n=await iH(t,`tmux`,[`display-message`,`-p`,`-t`,t.pane,`#S`]),r=n.kind===`ok`?n.stdout.trim():``,i=n.kind===`ok`?r?L(r):R:z(n.reason);for(this.names.delete(e),this.names.set(e,{outcome:i,at:this.now()});this.names.size>64;)this.names.delete(this.names.keys().next().value);return i}};const sH=e=>JSON.stringify([e.sessionId,e.projectDir,e.cwd,e.claudeConfigDir,e.env===void 0?null:ot.map(t=>e.env?.[t]??null)]);var cH=class{readings=new Map;inFlight=new Map;constructor(e,t=Date.now){this.edge=e,this.now=t}getCeiling(e){let t=sH(e),n=this.readings.get(t);if(n&&this.now()-n.at<1e4)return Promise.resolve(n.outcome);let r=this.inFlight.get(t)??this.fetch(t,e);return n?Promise.resolve(n.outcome):r}fetch(e,t){let n=this.edge.locate(t),r=(n.kind===`ok`?this.edge.read(n.value,t):Promise.resolve(n)).then(t=>{if(this.inFlight.get(e)!==r)return t;for(this.readings.delete(e),this.readings.set(e,{outcome:t,at:this.now()});this.readings.size>64;)this.readings.delete(this.readings.keys().next().value);return t}).finally(()=>{this.inFlight.get(e)===r&&this.inFlight.delete(e)});return this.inFlight.set(e,r),r}move(e,t){let n=this.edge.locate(e);if(n.kind!==`ok`)throw Error(n.kind===`failed`?n.reason:`memento is not installed or not enabled for this project`);let r=sH(e);try{this.edge.move(n.value,e,t)}finally{this.readings.delete(r),this.inFlight.delete(r),this.fetch(r,e)}}};function lH(e){return{gitProvider:new hE({watchers:e.watchers,logger:e.logger}),usageStore:new VV({logger:e.logger}),contextProvider:new HV,metricsProvider:new JV,activityProvider:new eH,tmuxService:new oH,mementoProvider:new cH(wz()),autoCompact:pj,log:e.logger}}function uH(e,t){return e===void 0?!0:e.evaluate(t).map(e=>e.plain).join(``)!==`false`}const dH={kind:`hidden`},fH={kind:`shown`};function pH(e,t){try{return uH(e,t)?fH:dH}catch(e){return{kind:`failed`,message:e instanceof Error?e.message:String(e)}}}function mH(e,t){let n=K.fromFragments(e);return n.end=``,n.overflow=`ignore`,t!==void 0&&!t.isNull&&(n.style=t),n}function hH(e,t,n){e.cellLength>t?e.truncate(t,{mode:n.truncate,marker:`…`}):e.cellLength<t&&e.align(n.justify,t)}function gH({lead:e,text:t,trail:n}){return[...e===void 0?[]:[e],t,...n===void 0?[]:[n]]}function _H({text:e,placement:t,lead:n,trail:r}){return{text:vH(e),placement:t,...n!==void 0&&{lead:vH(n)},...r!==void 0&&{trail:vH(r)}}}function vH(e){let t=e.blankCopy(e.plain);t.style=Lp(e.style).clearMetaAndLinks();for(let{start:n,end:r,style:i}of e.spans)t.stylize(Lp(i).clearMetaAndLinks(),n,r);return t}function yH(e){let t=gH(e);if(t.length===1)return e.text;let n=mH(t);return n.style=e.text.style,n}function bH(e,t){let{width:n,justify:r,truncate:i,baseStyle:a,padding:o,placement:s,lead:c=[],trail:l=[]}=t;if(e.length===0)return[];let u=mH(e,a).pad(o),d=new K(` `.repeat(o)),f={placement:s,...c.length>0&&{lead:mH([d,...c],a)},...l.length>0&&{trail:mH([...l,d],a)}};if(n===`auto`)return[{text:u,...f}];let p={justify:r,truncate:i};return n===`fill`?[{text:u,fill:p,...f}]:(hH(u,n,p),[{text:u,...f}])}const xH=RegExp(`\\x1b\\[[0-9;]*m|${mu.source}`,`g`);function SH(e){return Math.max(0,...e.split(`
|
|
192
|
-
`).map(e=>io(e.replace(
|
|
193
|
-
`);if(i.length>1)return n();let a=Math.max(0,t.width-SH(i[0]??``)),o=Math.floor(a/r.length),s=a-o*r.length;return r.forEach(({at:t,how:n},i)=>{let a=o+(i===r.length-1?s:0),{text:c}=e[t];hH(c,c.cellLength+a,n)}),n()}function wH(e,t){let n=[],r=[],i=()=>{if(!r.length)return;let e=TH(r,t);e.plain.length>0&&n.push(e),r=[]};for(let a of e){let e={frag:a,style:Lp(a.style)};if(e.style.link){i();let r=TH([e],t);r.plain.length>0&&n.push(r)}else r.push(e)}return i(),n}function TH(e,t){let n=t!==void 0&&!t.isNull?t:void 0,r=e.map(e=>EH(e.frag,n?n.add(e.style):e.style)),i=K.fromFragments(r);return i.end=``,i.overflow=`ignore`,r.length===1?i.style=r[0].style:n!==void 0&&(i.style=n),i}function EH(e,t){let n=e.copy();return n.style=t,n}function DH(e,t){if(e.look===void 0)throw Error(`${t} read the render's look before any render resolved one`);return e.look}function OH(e,t,n,r){let i=new Map,a=Object.entries(t);for(let[t,o]of[...a.filter(([,e])=>!(`do`in e)),...a.filter(([,e])=>`do`in e)])i.set(t,kH(e,t,o,n,r,i));return i}function kH(e,t,n,r,i,a){if(`set`in n){let e=r.get(n.set)??n.set;if(`to`in n)return{kind:`set-literal`,key:n.set,value:n.to,stateVar:e};if(`from`in n){let t=Y_(n.from,i);return{kind:`set-option`,key:n.set,stateVar:e,options:[...t.members],paletteOf:t.paletteOf,library:t.library}}return`int`in n?{kind:`set-int`,key:n.set,stateVar:e}:`cycle`in n?{kind:`set-cycle`,key:n.set,stateVar:e,members:n.cycle}:{kind:`set-bounded`,key:n.set,by:n.by}}if(`persist`in n){let e=Wa.get(n.persist)??n.persist;if(`to`in n)return{kind:`persist-literal`,key:n.persist,value:n.to,stateVar:e};if(`from`in n){let t=Y_(n.from,i);return{kind:`persist-option`,key:n.persist,stateVar:e,options:[...t.members],paletteOf:t.paletteOf,library:t.library}}if(`cycle`in n)return{kind:`persist-cycle`,key:n.persist,stateVar:e,members:n.cycle};if(`removeSegment`in n)return{kind:`layout-op`,key:n.persist,op:{op:`remove`,target:n.removeSegment}};if(`insertSegment`in n)return{kind:`layout-op`,key:n.persist,op:{op:`insert`,segment:n.insertSegment,anchor:n.anchor,relation:n.relation}};if(`insertSegmentFrom`in n){let e=Y_(n.insertSegmentFrom,i);return{kind:`layout-op-option`,key:n.persist,anchor:n.anchor,relation:n.relation,options:[...e.members],paletteOf:e.paletteOf,library:e.library}}return{kind:`persist-bounded`,key:n.persist,by:n.by}}if(`copy`in n)return{kind:`copy`,text:MH(e,n.copy,t)};if(`open`in n)return{kind:`open`,target:MH(e,n.open,t)};if(`reset`in n)return{kind:`reset`,key:n.reset};if(`doctor`in n)switch(n.doctor){case`run`:return{kind:`doctor-run`};case`fix`:return{kind:`doctor-fix`,check:n.check};case`mark`:return{kind:`doctor-mark`,check:n.check,mark:n.mark}}if(`ceiling`in n)return{kind:`ceiling`,args:YF(n)};if(`slash`in n)return{kind:`slash`,line:n.slash};if(`undo`in n)return{kind:`undo`};if(`redo`in n)return{kind:`redo`};if(`back`in n)return{kind:`back`};if(`rewind`in n)return{kind:`rewind`};if(`save`in n)return{kind:`save`};if(`preset`in n)return n.preset===`save`?{kind:`preset-save`}:{kind:`preset-delete`,name:MH(e,n.name,t)};if(`themeDefault`in n)return{kind:`theme-default-save`};let[o,...s]=n.do.map(e=>{let n=a.get(e);if(n===void 0)throw Error(`action "${t}" fires "${e}", which is not declared in this config`);return n});return{kind:`do`,head:o,rest:s}}function AH(e){return e.kind===`do`?AH(e.head):e}function jH(e){switch(AH(e).kind){case`set-option`:case`set-int`:case`persist-option`:case`layout-op-option`:return!0;case`set-literal`:case`set-bounded`:case`set-cycle`:case`copy`:case`open`:case`persist-literal`:case`persist-bounded`:case`persist-cycle`:case`reset`:case`layout-op`:case`undo`:case`redo`:case`back`:case`rewind`:case`save`:case`preset-save`:case`preset-delete`:case`theme-default-save`:case`doctor-run`:case`doctor-fix`:case`doctor-mark`:case`ceiling`:case`slash`:case`do`:return!1}}function MH(e,t,n){try{return e(t)}catch(e){throw Error(`Template parse error in actions.${n}: ${e.message}`,{cause:e})}}function NH(e,t){return e.has(t)?Dv(e.read(t)):``}function PH(e,t){return e.evaluate(t).map(e=>e.plain).join(``)}function FH(e,t,n,r){let i=new K(e,{style:U.combine([r,new U({link:t,bold:n})])});return i.overflow=`ignore`,i.end=``,i}function IH(e,t,n=!1){let r=new U({link:t,bold:n?!0:void 0}),i=new K(e.plain,{style:U.combine([Lp(e.style),r])});for(let t of e.spans)i.stylize(U.combine([Lp(t.style),r]),t.start,t.end);return i.overflow=`ignore`,i.end=``,i}function LH(e,t){return Math.max(e.members.indexOf(NH(t,e.stateVar)),0)}function RH(e,t,n,r,i){switch(e.kind){case`set-literal`:{let t=NH(r,e.stateVar);return{effects:[{verb:jn,args:[i,e.key,e.value]}],active:t===e.value}}case`set-option`:{let a=n??t,o=NH(r,e.stateVar);return{effects:[{verb:jn,args:[i,e.key,a]}],active:o===a}}case`set-int`:{let a=n??t,o=NH(r,e.stateVar);return{effects:[{verb:jn,args:[i,e.key,a]}],active:o===a}}case`set-cycle`:{let t=e.members[(LH(e,r)+1)%e.members.length];return{effects:[{verb:jn,args:[i,e.key,t]}],active:!1}}case`set-bounded`:return{effects:[{verb:Mn,args:[i,e.key,String(e.by)]}],active:!1};case`copy`:return{effects:[{verb:Nn,args:[PH(e.text,xT(r))]}],active:!1};case`open`:return{effects:[{verb:Pn,args:[PH(e.target,xT(r))]}],active:!1};case`persist-literal`:{let t=NH(r,e.stateVar);return{effects:[{verb:Rn,args:[i,e.key,e.value]}],active:t===e.value}}case`persist-option`:{let a=n??t,o=NH(r,e.stateVar);return{effects:[{verb:Rn,args:[i,e.key,a]}],active:o===a}}case`persist-cycle`:{let t=e.members[(LH(e,r)+1)%e.members.length];return{effects:[{verb:Rn,args:[i,e.key,t]}],active:!1}}case`persist-bounded`:return{effects:[{verb:zn,args:[i,e.key,String(e.by)]}],active:!1};case`reset`:return{effects:[{verb:Wn,args:[i,e.key]}],active:!1};case`undo`:return{effects:[{verb:Kn,args:[i]}],active:!1};case`redo`:return{effects:[{verb:qn,args:[i]}],active:!1};case`back`:return{effects:[{verb:Jn,args:[i]}],active:!1};case`rewind`:return{effects:[{verb:Yn,args:[i]}],active:!1};case`save`:return{effects:[{verb:Bn,args:[i]}],active:!1};case`preset-save`:return{effects:[{verb:Vn,args:[i]}],active:!1};case`theme-default-save`:return{effects:[{verb:Hn,args:[i]}],active:!1};case`preset-delete`:return{effects:[{verb:Un,args:[i,PH(e.name,xT(r))]}],active:!1};case`doctor-run`:return{effects:[{verb:Zn,args:[i]}],active:!1};case`doctor-fix`:return{effects:[{verb:Qn,args:[i,e.check]}],active:!1};case`doctor-mark`:return{effects:[{verb:$n,args:[i,e.check,e.mark]}],active:!1};case`ceiling`:return{effects:[{verb:tr,args:[i,...e.args]}],active:!1};case`slash`:return{effects:[{verb:nr,args:[i,e.line]}],active:!1};case`layout-op`:return{effects:[{verb:Gn,args:[i,e.key,MN(e.op)]}],active:!1};case`do`:{let a=RH(e.head,t,n,r,i);return{effects:[...a.effects,...e.rest.flatMap(e=>RH(e,t,void 0,r,i).effects)],active:a.active}}case`layout-op-option`:{let r={op:`insert`,segment:n??t,anchor:e.anchor,relation:e.relation};return{effects:[{verb:Gn,args:[i,e.key,MN(r)]}],active:!1}}}}function zH(e,t,n,r){if(n.length===0)throw Error(`action "${e}" needs a display (the clickable text)`);if(t.kind===`set-cycle`||t.kind===`persist-cycle`)return{display:pr(`action "${e}"`,n,t.members.length,LH(t,r)),boundValue:void 0};if(n.length>2)throw Error(`action "${e}" takes a display and an optional bound value, got ${n.length} arguments (per-state displays are a cycle action's form)`);return{display:n[0],boundValue:n[1]?.plain}}function BH(e,t,n){let r=n.compiled.get(e);if(!r)throw Error(`action "${e}" is not declared in this config`);let i=n.store,{display:a,boundValue:o}=zH(e,AH(r),t,i),s=NH(i,`session.id`),{effects:c,active:l}=RH(r,a.plain,o,i,s);return IH(a,I(c),l)}function VH(e){return{action:{fn:(t,...n)=>BH(t,n,e),argTypes:[`string`,`liftable`],arity:{kind:`variadic`},returnType:`T`}}}function HH(e,t){return FH(`✕`,I([{verb:jn,args:[NH(e,`session.id`),t,ur]}]),!1)}function UH(e,t,n){return new U({bgcolor:H.fromRgba(t),color:H.fromRgba(Sm(e,t,n))})}function WH({tint:e,text:t}){return new U({bgcolor:H.fromRgba(e),color:H.fromRgba(t)})}function GH(e,t,n){return new U({color:H.fromRgba(Qs(fm(e,`warning`),t,xm,n))})}function KH(e,t,n){return U.combine([UH(e,t,n),GH(e,t,n)])}function qH(e,t,n){return UH(e.palette,Um(e.palette,e.disclosure,[t],n),n)}function JH(e){let t=H.fromRgba(fm(e,`background`)),n=K.fromFragments(zp.map(n=>new K(`▀`,{style:new U({color:H.fromRgba(fm(e,n)),bgcolor:t})})));return n.overflow=`ignore`,n.end=``,n}const YH=(e,t)=>{let n=typeof e==`string`?new K(e,{style:t}):e;return n.overflow=`ignore`,n.end=``,n},XH=e=>new U({bold:e});function ZH(e,t,n,r,i,a){if(r===void 0)return(n,r,a,o)=>YH(a,U.combine([qH(e,{...n,distribution:t},i),XH(o)]));let o=UH(e.palette,a,i);return(e,t,i,a)=>QH(i,U.combine([o,XH(a)]),r(t,n))}const QH=(e,t,n)=>YH(K.fromFragments([YH(e,t),YH(` `,t),JH(n)]));function $H(e,t){return t===void 0?(e,t,n)=>YH(n):(n,r,i)=>QH(i,void 0,t(r,e))}function eU(e,t,n,r,i){let a=UH(e.palette,i,r);return(e,r,i,o)=>YH(K.fromFragments([YH(o?`[`:` `,a),JH(n(r,t)),YH(o?`]`:` `,a)]))}function tU(e,t,n){let r=t.map(t=>({label:t.label,indices:e.flatMap((e,n)=>e.group===t.id?[n]:[])})).filter(e=>e.indices.length>0);if(r.reduce((e,t)=>e+t.indices.length,0)!==e.length){let n=new Set(t.map(e=>e.id)),r=e.flatMap((e,t)=>n.has(e.group)?[]:[`#${t} (group "${e.group}")`]);throw Error(`library: ${r.join(`, `)} name a group the domain does not list (${[...n].join(`, `)})`)}return n?r.flatMap(e=>nU(e.indices,8).map(t=>[{label:e.label,indices:t}])):[r]}function nU(e,t){return Array.from({length:Math.ceil(e.length/t)},(n,r)=>e.slice(r*t,(r+1)*t))}function rU(e,t){return new K(e).truncate(t,{marker:`…`}).plain}function iU(e){return{current:null,drawnAt:e}}function aU(e,t,n,r,i,a,o){let s={segName:t,placementId:n,palette:r,disclosure:i,tint:a,text:o,bg:void 0,drops:[]};return e.current=s,s}function oU(e,t){let n=e.current;if(n===null)throw Error(`${t} is only available inside a segment's templates — there is no active segment here. Segment-scoped functions cannot be used in variable declarations or layout-node "when" predicates, which are evaluated outside any segment.`);return n}function sU(e){return new K(e).cellLength}function cU(e){return Math.max(1,e.width-e.chromeCols-2*e.padding)}function lU(e){return Math.max(1,cU(e)-(sU(`✕`)+2*e.padding+e.seamCols))}function uU(e,t,n){if(!Number.isFinite(t))return e.length>0?[e.map((e,t)=>t)]:[];let r=Math.max(1,t-n),i=[],a=[],o=0;for(let t=0;t<e.length;t++){let n=e[t];a.length===0?(a=[t],o=n):o+1+n<=r?(a.push(t),o+=1+n):(i.push(a),a=[t],o=n)}return a.length>0&&i.push(a),i}function dU(e,t,n){let r=sU(`←`)+1+sU(`→`)+1,i=uU(e,t,n);return(i.length>1?uU(e,t,n+r):i).map(e=>[{label:``,indices:e}])}function fU(e,t){let n=[];for(let t of e)n.length>0&&n.push(new K(` `)),n.push(t);let r=K.fromFragments(n);return r.overflow=t?`ignore`:void 0,r.end=``,r}function pU(e,t,n,r,i){let a=e.compiled.get(t);if(!a||a.kind!==n)throw Error(`${i} references action "${t}" which must be ${r}, got ${a?`a ${a.kind} action`:`no such action`}`);return a}function mU(e,t,n){let r=e.compiled.get(t),i=r&&AH(r);if(!i||i.kind!==`set-option`&&i.kind!==`persist-option`&&i.kind!==`layout-op-option`)throw Error(`${n} references action "${t}" which must be a set-option, persist-option, or layout-op-option action ({ set, from }, { persist, from }, or { persist, insertSegmentFrom, anchor, relation }), got ${i?`a ${i.kind} action`:`no such action`}`);return i}function hU(e,t,n,r,i,a,o,s,c=[]){let l=a.compiled.get(e),u=a.store,d=NH(u,`session.id`),f=`stateVar`in t?NH(u,t.stateVar):void 0,p=(e,n)=>{let r=t.options[e];return o({index:e,count:t.options.length},r,n,r===f)},m=i?r.kind===`led`?lU(a):cU(a):1/0,h=(r.kind===`led`?0:sU(`✕`)+1)+c.reduce((e,t)=>e+sU(t.glyph)+1,0),g=t.library&&{groups:t.library.groups,entries:t.options.map(t.library.entry)},_=g===void 0?t.options.map((e,t)=>p(t,e)):[],v=g===void 0?dU(_.map(e=>e.cellLength),m,h):tU(g.entries,g.groups,i),y=parseInt(NH(u,n.stateVar),10),b=e=>Math.max(0,v.findIndex(t=>t.some(t=>t.indices.includes(e)))),x=b(f===void 0?-1:t.options.indexOf(f)),S=Number.isInteger(y)?y<0?x:Math.min(y,v.length-1):0,C=v[S]??[],w=e=>I([{verb:jn,args:[d,n.key,String(e)]}]),ee=r.kind===`led`?[]:[{verb:jn,args:[d,...r.writes.flatMap(([e,t])=>[e,t])]}],te=r.kind===`own`&&r.onPick?ee:[],ne=e=>I([...RH(l,e,e,u,d).effects,...te]),T=(e,n)=>IH(e,ne(t.options[n])),re=r.kind===`led`?[]:[FH(`✕`,I(ee),!1,s)];re.push(...c.map(({glyph:e,option:r})=>FH(e,I([...RH(l,r,r,u,d).effects,{verb:jn,args:[d,n.key,String(b(t.options.indexOf(r)))]}]),!1))),S>0&&re.push(FH(`←`,w(S-1),!1));let E=S<v.length-1?[FH(`→`,w(S+1),!1)]:[];if(g===void 0){let e=C.flatMap(e=>e.indices);return[fU([...re,...e.map(e=>T(_[e],e)),...E],i)]}let D=new U({bold:!0}),ie=v.length>1?` ${S+1}/${v.length}`:``,O=C.length===1?[new K(`${C[0].label}${ie}`,{style:D})]:[],ae=[fU([...re,...O,...E],i)];for(let e of C){C.length>1&&ae.push(fU([new K(e.label,{style:D})],i));let n=Math.max(...e.indices.map(e=>sU(t.options[e])));for(let r of e.indices){let e=t.options[r],a=g.entries[r].description,o=a===void 0?void 0:Op(a),s=` `.repeat(n-sU(e)+2),c=o===void 0?e:`${e}${s}${o}`;ae.push(fU([T(p(r,rU(c,m)),r)],i))}}return ae}function gU(e,t){return{picker:{fn:(n,r,i,a,o,...s)=>{hT(`picker "${n}"`,[`closeOnPick`,`paged`,`inBody`],s);let c=pU(e,r,`set-int`,`an int action ({ set, int: true })`,`picker`);if(o===!0&&i===!0)throw Error(`{{ picker "${n}" … }} sets both closeOnPick and inBody; a picker in a body is closed by the body's ✕, so it has no close to fold into a pick`);let l=mU(e,n,`picker`);if(l.library!==void 0)throw Error(`{{ picker "${n}" … }} ranges a catalogue domain, which lays out as one row per member; a catalogue renders in a {{ menu }} body`);let u=oU(t,`{{ picker }}`);if(u.bg===void 0)throw Error(`{{ picker }} is not available while segments.${u.segName}'s own "bg:" is being evaluated — a picker is drawn on that background`);let[d]=hU(n,l,{key:c.key,stateVar:c.stateVar},o===!0?{kind:`led`}:{kind:`own`,writes:[[c.key,`-1`]],onPick:i===!0},a===!0,e,ZH(u,em(void 0),DH(e,`{{ picker }}`),l.paletteOf,t.drawnAt(),u.bg),GH(u.palette,u.bg,t.drawnAt()));return d},argTypes:[`string`,`string`,`bool`],arity:{kind:`variadic`},returnType:`T`}}}function _U(e,t){let n=e.length,r=Math.max(e.indexOf(t),0);return e=>((r+e)%n+n)%n}function vU(e,t,n,r,i){let a=Math.min(Math.floor((t-1)/2),i),o=n,s=0;for(;s<a;){let t=o+e(-(s+1))+1+e(s+1)+1;if(t>r)break;o=t,s+=1}return s}function yU(e,t,n,r,i,a){if(!(`stateVar`in t))throw Error(`carousel references action "${e}", which inserts a segment and holds no current value to centre on — a carousel needs a { set, from } or { persist, from } action`);let o=n.store;if(!o.has(t.stateVar))throw Error(`carousel references action "${e}", whose key "${t.stateVar}" no variable reads back, so there is no current value to centre on — declare { kind: "state", key: "${t.stateVar}" } among the variables`);let s=n.compiled.get(e),c=NH(o,`session.id`),{options:l}=t,u=l.length;if(u===0)return fU([],!0);let d=NH(o,t.stateVar),f=_U(l,d),p=e=>l[f(e)],m=new Map,h=e=>{let t=m.get(e);if(t!==void 0)return t;let n=I(RH(s,p(e),p(e),o,c).effects);return m.set(e,n),n},g=e=>r({index:f(e),count:u},p(e),p(e),p(e)===d),_=new Map,v=e=>{let t=_.get(e);if(t!==void 0)return t;let n=IH(g(e),h(e));return _.set(e,n),n},y=a===void 0?v(0):IH($H(DH(n,`{{ carousel }}`),t.paletteOf)({index:f(0),count:u},p(0),p(0),!1),I(RH(n.compiled.get(a),p(0),void 0,o,c).effects)),b=vU(e=>v(e).cellLength,u,sU(`◀`)+1+y.cellLength+1+sU(`▶`),lU(n),i),x=e=>Array.from({length:b},(t,n)=>v(e*(n+1)));return fU([...x(-1).reverse(),FH(`◀`,h(-1),!1),y,FH(`▶`,h(1),!1),...x(1)],!0)}function bU(e,t){return{carousel:{fn:(n,...r)=>{let[i,a,...o]=r;if(hT(`carousel "${n}"`,[`neighbours`,`centre`],o),i!==void 0&&!(Number.isInteger(i)&&i>=0))throw Error(`carousel "${n}": neighbours must be a whole number ≥ 0 (0 shows only ◀ CURRENT ▶), got ${String(i)}`);if(a!==void 0&&!(typeof a==`string`&&e.compiled.has(a)))throw Error(`carousel "${n}": centre must name a declared action, got ${JSON.stringify(a)}`);if(a!==void 0&&jH(e.compiled.get(a)))throw Error(`carousel "${n}": centre "${a}" writes a value the template binds, and the centre binds none — name an action that writes a fixed value, a cycle, or a do of them`);let s=i??1/0,c=mU(e,n,`carousel`),l=oU(t,`{{ carousel }}`);if(l.bg===void 0)throw Error(`{{ carousel }} is not available while segments.${l.segName}'s own "bg:" is being evaluated — a carousel is drawn on that background`);return yU(n,c,e,ZH(l,em(void 0),DH(e,`{{ carousel }}`),c.paletteOf,t.drawnAt(),l.bg),s,a)},argTypes:[`string`,`value`],arity:{kind:`variadic`},returnType:`T`}}}function xU(e,t,n){let r=mU(e,t,n);if(!(`stateVar`in r))throw Error(`${n} references action "${t}", which inserts a segment and holds no current value — a ${n} needs a { set, from } or { persist, from } action`);if(r.paletteOf===void 0)throw Error(`${n} references action "${t}", whose options are not colour-valued — a swatch draws the palette an option puts in force, as the "themes", "placementThemes" and "styles" domains do`);return r}function SU(e,t,n){let r=Math.imul(e^e>>>16,73244475);return r=Math.imul(r^r>>>16,73244475),r^=r>>>16,(n+1+(r>>>0)%Math.max(t-1,1))%t}function CU(e,t,n,r){let i=xU(e,t,n),a=r??NH(e.store,i.stateVar);if(!i.options.includes(a))throw Error(`${n} "${t}": "${a}" is not one of its options, so it has no palette to draw`);return i.paletteOf(a,DH(e,`{{ ${n} }}`))}function wU(e,t,n){return{swatch:{fn:(t,...n)=>{let[r,...i]=n;if(hT(`swatch "${t}"`,[`option`],i),r!==void 0&&typeof r!=`string`)throw Error(`swatch "${t}": option must be text, got ${JSON.stringify(r)}`);return JH(CU(e,t,`swatch`,r))},argTypes:[`string`,`value`],arity:{kind:`variadic`},returnType:`T`},swatches:{fn:(r,i)=>{let a=xU(e,r,`swatches`),o=pU(e,i,`set-int`,`an int action ({ set, int: true })`,`swatches`),s=oU(t,`{{ swatches }}`);if(s.bg===void 0)throw Error(`{{ swatches }} is not available while segments.${s.segName}'s own "bg:" is being evaluated — a swatch row is drawn on that background`);let c=t.drawnAt(),{options:l}=a,u=l.length,[d]=hU(r,a,{key:o.key,stateVar:o.stateVar},{kind:`led`},!0,e,eU(s,DH(e,`{{ swatches }}`),a.paletteOf,c,s.bg),GH(s.palette,s.bg,c),u===0?[]:(()=>{let t=_U(l,NH(e.store,a.stateVar));return[{glyph:`◀`,option:l[t(-1)]},{glyph:`?`,option:l[SU(n().getTime(),u,t(0))]},{glyph:`▶`,option:l[t(1)]}]})());return d},argTypes:[`string`,`string`],arity:{kind:`exact`},returnType:`T`}}}const TU=[`~/code`,`main`,`opus`,`42%`,`5m`,`$1.20`];function EU(e,t,n,r){let i=Pm(e,n,r),a=(t,n)=>({text:t,colour:n,ink:Sm(e,n,r)});return[[Yp(t).map((n,i)=>{let a=pm(e,n);return{text:TU[i%TU.length],colour:a,ink:t.shade.text(e,n.hue,a,r)}})],[[a(`▾ open`,i.state),a(`menu`,i.plane)],[a(`warn`,fm(e,`warning`)),a(`error`,fm(e,`error`))]]]}function DU(e,t){let n=e.flatMap((e,t)=>e.map(({text:e,colour:n,ink:r},i)=>({gap:t>0&&i===0?` `:``,cell:new K(` ${e} `,{style:WH({tint:n,text:r})})}))),r=[],i=0;for(let{gap:e,cell:a}of n){if(i+=e.length+a.cellLength,i>t)break;e!==``&&r.push(new K(e)),r.push(a)}return r}function OU(e,t,n,r,i){let a=EU(e,t,n,r).map(e=>DU(e,i)),o=K.fromFragments(a.flatMap((e,t)=>t===0?e:[new K(`
|
|
194
|
-
`),...e]));return o.overflow=`ignore`,o.end=``,o}function
|
|
195
|
-
`),...e]));return o.overflow=`ignore`,o.end=``,o}function
|
|
187
|
+
`,v.join(e,`lib`),t.sessionId,t.cwd],env:Cz(t),timeoutMs:3e3,category:`memento.read`});return n.ok?Tz(n.stdout):z(wz(n))}function Dz(e,t,n){let r=Re({bin:v.join(e,yz),args:n.kind===`set`?[`set`,`session`,n.to]:[`clear`,`session`],env:Cz(t),timeoutMs:5e3,category:`memento.move`});if(!r.ok)throw Error(wz(r))}function Oz(e,t){return Sz(wi(e),t)}function kz(){return{locate:e=>Oz(e.claudeConfigDir,e.projectDir),read:Ez,move:Dz}}function Az(e,t,n){let r=n===void 0?``:`CLAUDE_CONFIG_DIR=${Tr(n)} `,i=e.added_dirs.map(e=>` --add-dir ${Tr(e)}`).join(``);return`cd ${Tr(e.project_dir)} && ${r}claude --resume ${Tr(t)}${i}`}function jz(e,t,n){let r=z_(t(`preset`),e.globals.preset,e.presets),i=H_(e,r),a=t(`edit.mode`)===`arrange`?e.editGlobals:{},o=Gg(a.palette,t(`theme`),i.palette),s=tz(i,ez(o,e.themeDefaults));return{preset:r,presetCustomized:n(r),theme:o,style:lh(a.style,t(`style`),s.style,e.styles),effect:_h(a.effect,t(`effect`),s.effect),endcaps:Sh(a.endcaps,t(`endcaps`),s.endcaps),variation:Dh(a.variation,t(`variation`),s.variation),shade:Ah(a.shade,t(`shade`),s.shade),separator:a.default_separator??s.default_separator,autoWrap:Rh(a.autoWrap,t(`autoWrap`),s.autoWrap),padding:Vh(a.padding,t(`padding`),s.padding),updateNotice:zh(a.updateNotice,t(`updateNotice`),s.updateNotice),transitions:Bh(a.transitions,t(`transitions`),s.transitions),colorCompatibility:a.colorCompatibility??s.colorCompatibility??`truecolor`,lanes:Fa(e=>{let n=Na[e].setting;return Xm(a[n],t(n),s[n],!1,Fh)})}}function Mz(e,t){return{endcaps:e.endcaps,separator:e.separator,colorCompatibility:e.colorCompatibility,wrap:e.autoWrap,padding:e.padding,width:t}}function Nz(e){return{theme:e.theme,style:e.style,effect:e.effect,preset:e.preset,variation:e.variation,shade:e.shade,transitions:e.transitions}}function Pz(e){return{preset:{effective:e.preset,customized:e.presetCustomized,bundled:QR(e.preset)},endcaps:{effective:e.endcaps},variation:{effective:e.variation},shade:{effective:e.shade},colorCompatibility:{effective:e.colorCompatibility},autoWrap:{effective:e.autoWrap},padding:{effective:e.padding},updateNotice:{effective:e.updateNotice},transitions:{effective:e.transitions},lanes:Fa(t=>({effective:e.lanes[t]}))}}const Fz={prNumber:!0,prState:!0,prUrl:!0,prError:!0,prEarlier:!0};function Iz(e){return e?.prState===void 0?e?.prError===void 0?e?.prEarlier===void 0?`-`:`earlier-${e.prEarlier}`:`failed`:e.prState}const Lz=10*1e3;function Rz(e,t,n,r){let i=n-(t*1e3-r);if(i<3e5||e<=0)return;let a=e/i,o=(100-e)/a;return Math.max(0,Math.round(o/6e4))}function zz(e,t){if(!(t<60))return e*3600/t}function Bz(e,t,n,r){let i=r-t;if(i<50||i>Lz)return;let a=n-e;if(!(a<=0))return a*1e3/i}function Vz(e){let{prev:t,cur:n}=e;if(t===void 0)return;let r=Bz(t.input,t.atMs,n.input,n.atMs),i=Bz(t.output,t.atMs,n.output,n.atMs),a=Bz(t.total,t.atMs,n.total,n.atMs);if(!(r===void 0&&i===void 0&&a===void 0))return{...r!==void 0&&{input:r},...i!==void 0&&{output:i},...a!==void 0&&{total:a}}}function Hz(e){let{samples:t}=e,n=[];for(let e=1;e<t.length;e++){let r=t[e-1],i=t[e],a=i.atMs-r.atMs;if(a<50||a>Lz)continue;let o=Bz(r.total,r.atMs,i.total,i.atMs);n.push(o??0)}if(n.length!==0)return n.join(`,`)}function Uz(e){let t=e.indexOf(`.`);return t<0?e:e.slice(0,t)}function Wz(e){let t=[],n=(e,n)=>{try{let e=n();return e===``?void 0:e}catch(n){t.push(`host.${e}: ${String(n)}`);return}},r=n(`name`,()=>Uz(w.hostname())),i=n(`user`,()=>w.userInfo().username);return{host:{...r!==void 0&&{name:r},...i!==void 0&&{user:i},...e.ssh!==void 0&&{ssh:e.ssh}},failures:t}}function Gz(e,t){let n=[],r=t=>lv(t,e.helpers).keys(),i=H_(e,t);for(let e of nh){let t=i[e];if(rh(t))for(let e of r(t))n.push(e)}for(let i of $g(V_(e,t).node)){if(i.when)for(let e of r(i.when))n.push(e);i.kind===`segment`&&n.push(...Kz(e,i.name))}return Jz(e,n)}function Kz(e,t){let n=e.segments[t];return n?[n.template,n.when,n.bg,n.fg].flatMap(t=>t?[...lv(t,e.helpers).keys()]:[]):[]}function qz(e,t,n){return Jz(e,[...Kz(e,t),...n.flatMap(t=>[...lv(t,e.helpers).keys()])])}function Jz(e,t){let n=new Map;for(let[t,r]of Object.entries(e.variables))n.set(t,r);for(let[t,r]of Object.entries(e.segments))if(r.vars)for(let[e,i]of Object.entries(r.vars))n.set(`${t}.${e}`,i);let r=[...t],i=new Set,a=t=>lv(t,e.helpers).keys(),o=new Set;for(;r.length>0;){let e=r.pop();for(let t of Xz(n,e)){if(i.has(t))continue;i.add(t);let e=n.get(t);if(e){if(e.kind===`input`)o.add(e.path);else if(e.kind===`template`)for(let t of a(e.template))r.push(t)}}}return o}function Yz(e){let t=new Map;return n=>{let r=t.get(n);if(r!==void 0)return r;let i=Gz(e,n);return t.set(n,i),i}}function Xz(e,t){let n=t;for(;n.length>0;){if(e.has(n))return[n];let t=n.lastIndexOf(`.`);if(t<0)break;n=n.slice(0,t)}let r=`${t}.`,i=[];for(let t of e.keys())t.startsWith(r)&&i.push(t);return i}function Zz(e,t){for(let n of e)if(n===t||n.startsWith(t+`.`))return!0;return!1}function Qz(e){let t=t=>e.has(t),n=t(`git.staged`)||t(`git.unstaged`)||t(`git.untracked`)||t(`git.conflicts`);return{...t(`git.sha`)&&{showSha:!0},...n&&{showWorkingTree:!0},...t(`git.stash`)&&{showStashCount:!0},...(t(`git.upstream`)||t(`git.tracking`))&&{showUpstream:!0},...t(`git.repoName`)&&{showRepoName:!0},...t(`git.repoUrl`)&&{showRepoUrl:!0},...t(`git.operation`)&&{showOperation:!0},...t(`git.timeSinceCommit`)&&{showTimeSinceCommit:!0},...Object.keys(Fz).some(e=>t(`git.${e}`))&&{showPullRequest:!0}}}async function $z(e,t,n,r,i,a,o,{configPath:s,...c}){let l=e=>Zz(i,e),u=bE(t).getTime(),d=o.tmux??null,f=(e,t,n)=>t?n().catch(t=>z(`${e}: ${String(t)}`)):Promise.resolve(R),[p,m,h,g,_,v,y,b,x,S,C]=await Promise.all([f(`git`,l(`git`),()=>n.gitProvider.getGitInfo(r??e.workspace?.current_dir,Qz(i),e.workspace?.project_dir)),f(`session`,l(`session.cost`)||l(`session.tokens`)||l(`burn`),()=>n.usageStore.getUsageInfo(e.session_id,e)),f(`today`,l(`today`),()=>n.usageStore.getTodayInfo(e,o.claudeConfigDir,t)),f(`context`,l(`context`)||l(`autocompact`),()=>n.contextProvider.getContextInfo(e)),f(`metrics`,l(`metrics`)||l(`burn`),()=>n.metricsProvider.getMetricsInfo(e.session_id,e)),f(`activity`,l(`activity`),()=>n.activityProvider.getActivityInfo(e.session_id,e)),f(`tmux`,l(`tmux.session`),()=>d===null?Promise.resolve(R):n.tmuxService.getSessionName(d)),f(`cache`,l(`cache`),()=>mz(e.transcript_path)),f(`speed`,l(`speed`),()=>n.usageStore.observeSpeed(e.session_id,e.transcript_path,u)),f(`memento`,l(`memento`),()=>n.mementoProvider.getCeiling(_z({sessionId:e.session_id,projectDir:e.workspace?.project_dir??``,cwd:r??e.workspace?.current_dir??``},o))),f(`autocompact`,l(`autocompact`),()=>Promise.resolve(n.autoCompact(Ci(Si(o.claudeConfigDir)))))]),w=[],ee=e=>{if(e.kind===`failed`){w.push(e.reason);return}return e.kind===`ok`?e.value:void 0},te=sB(p,u);w.push(...te.failures);let ne=Wz(o);w.push(...ne.failures);let T=ee(m),re=ee(h),E=ee(g),D=ee(_),ie=ee(v),O=ee(y),ae=ee(b),oe=nB(S);S.kind===`failed`&&w.push(`memento: ${S.reason}`);let se=eB(C,E?.maxTokens);C.kind===`failed`&&w.push(`autocompact: ${C.reason}`);for(let e of w)n.log(`warn`,`provider fetch failed: ${e}`);let ce=e.rate_limits?.five_hour,le=e.rate_limits?.seven_day,ue=ce?Rz(ce.used_percentage,ce.resets_at,18e6,u):void 0,de=le?Rz(le.used_percentage,le.resets_at,6048e5,u):void 0,fe=T?.session.cost,pe=D?.sessionDuration,me=l(`burn`)&&fe!=null&&pe!=null?zz(fe,pe):void 0,he=ee(x),ge=he===void 0?void 0:Vz(he),_e=he===void 0?void 0:Hz(he),ve=ge!==void 0||_e!==void 0?{...ge,..._e!==void 0&&{history:_e}}:void 0,ye=oB(process.env.HOME??process.env.USERPROFILE),be=e.workspace?{...e.workspace,current_dir:oB(e.workspace.current_dir)??``,project_dir:oB(e.workspace.project_dir)??``,added_dirs:(e.workspace.added_dirs??[]).map(e=>oB(e)??e)}:e.workspace,xe=T===void 0?void 0:aB({cost:T.session.cost,tokens:T.session.tokens}),Se=re===void 0?void 0:{cost:re.cost,tokens:re.tokens},Ce=D===void 0?void 0:aB({lastResponseTime:D.lastResponseTime,responseTime:D.responseTime,sessionDuration:D.sessionDuration,messageCount:D.messageCount,nonPrompts:D.nonPrompts,linesAdded:D.linesAdded,linesRemoved:D.linesRemoved}),we=ie===void 0?void 0:rB(ie);return{...e,...be!==void 0&&{workspace:be},...ye!==void 0&&{home:ye},...te.git!==void 0&&{git:te.git},...d!==null&&{tmux:{pane:d.pane,...O!==void 0&&{session:O}}},host:ne.host,...Pz(a),history:n.history(e.session_id),navigation:{back:n.navigation(e.session_id)},...c,...s!==null&&{configPath:s},resumeCommand:Az(be,e.session_id,o.claudeConfigDir),...xe!==void 0&&{session:xe},...Se!==void 0&&{today:Se},...me!==void 0&&{burn:{costPerHour:me}},...ve!==void 0&&{speed:ve},...l(`block`)&&ce!==void 0&&{block:{nativeUtilization:ce.used_percentage,resetsAt:ce.resets_at,...ue!==void 0&&{etaMinutes:ue}}},...le!==void 0&&{weekly:{percentage:le.used_percentage,resetsAt:le.resets_at,...de!==void 0&&{etaMinutes:de}}},...ae!==void 0&&{cache:{expiresAt:ae}},...E!==void 0&&{context:{totalTokens:E.totalTokens,contextLeft:E.contextLeftPercentage}},...Ce!==void 0&&{metrics:Ce},...we!==void 0&&{activity:we},...oe!==void 0&&{memento:oe},...se!==void 0&&{autocompact:se}}}function eB(e,t){switch(e.kind){case`absent`:return;case`failed`:return{error:e.reason};case`ok`:return yj(e.value,t)}}const tB=e=>e.trim().split(`
|
|
188
|
+
`).at(-1).trim();function nB(e){switch(e.kind){case`absent`:return;case`failed`:return{error:tB(e.reason)};case`ok`:{let{ceiling:t,session:n}=e.value;return{ceiling:t===`off`?0:t,off:t===`off`,session:n??``}}}}function rB(e){let t=e.todos.findIndex(e=>e.active),n=e.todos.length===0?void 0:{total:e.todos.length,completed:e.todos.filter(e=>e.done).length,...t>=0&&{position:t+1,active:e.todos[t].text}},r=iB(e.running),i=iB(e.done),a=r===void 0&&i===void 0?void 0:{...r!==void 0&&{running:r},...i!==void 0&&{done:i}};if(!(e.command===null&&n===void 0&&a===void 0))return{...e.command!==null&&{command:e.command},...n!==void 0&&{todo:n},...a!==void 0&&{tool:a}}}function iB(e){return e.length===0?void 0:e.map(e=>`${e.name}:${e.count}`).join(`,`)}function aB(e){let t={},n=!1;for(let r of Object.keys(e)){let i=e[r];i!=null&&(t[r]=i,n=!0)}return n?t:void 0}function oB(e){return e===void 0||e.length===0||v.sep!==`\\`?e:e.replace(/\\/g,`/`)}function sB(e,t){if(e.kind===`absent`)return{failures:[]};if(e.kind===`failed`)return{failures:[e.reason]};let n=e.value,r=[],i=(e,t)=>{if(!(t===void 0||t.kind===`absent`)){if(t.kind===`failed`){r.push(`git.${e}: ${t.reason}`);return}return t.value}},a=i(`aheadBehind`,n.aheadBehind),o=i(`sha`,n.sha),s=i(`operation`,n.operation),c=i(`timeSinceCommit`,n.committedAt),l=c===void 0?void 0:Math.floor((t-c)/1e3),u=i(`stash`,n.stashCount),d=i(`upstream`,n.upstream),f=n.upstream===void 0?void 0:i(`tracking`,DT(n.upstream,n.aheadBehind)),p=i(`repoName`,n.repoName),m=i(`repoUrl`,n.repoUrl),h=n.pullRequest===void 0?void 0:OT(n.pullRequest,n.head),g={};switch(h?.kind){case`ok`:g={prNumber:h.value.number,prState:h.value.state,prUrl:h.value.url};break;case`failed`:r.push(`git.pr: ${h.reason}`),g={prError:h.reason};break;case`earlier`:g={prEarlier:h.value.state};break;case`absent`:case void 0:break}return{git:{branch:n.branch,status:n.status,...a!==void 0&&{ahead:a.ahead,behind:a.behind},...n.workingTree!==void 0&&{staged:n.workingTree.staged,unstaged:n.workingTree.unstaged,untracked:n.workingTree.untracked,conflicts:n.workingTree.conflicts},...o!==void 0&&{sha:o},...s!==void 0&&{operation:s},...l!==void 0&&{timeSinceCommit:l},...u!==void 0&&{stash:u},...d!==void 0&&{upstream:d},...f!==void 0&&{tracking:f},...p!==void 0&&{repoName:p},...m!==void 0&&{repoUrl:m},...g},failures:r}}const cB={theme:e=>e.theme.kind===`decided`?e.theme.name:null,preset:e=>e.preset,style:e=>e.style.kind===`decided`?e.style.name:null,effect:e=>e.effect.kind===`decided`?e.effect.name:null,endcaps:e=>e.endcaps,variation:e=>e.variation,shade:e=>e.shade,transitions:e=>e.transitions?jh:Mh,autoWrap:e=>e.autoWrap?jh:Mh,padding:e=>String(e.padding),updateNotice:e=>e.updateNotice?jh:Mh,experimentalBand:e=>e.lanes.band?jh:Mh,experimentalStatusline:e=>e.lanes.statusline?jh:Mh,experimentalPane:e=>e.lanes.pane?jh:Mh},lB=Object.entries(Ba),uB=new Set(Va.map(e=>e.sessionKey)),dB=()=>!1;function fB(e,t){return jz(e,e=>uB.has(e)?t(e):null,dB)}const pB=[`preset`,`theme`];function mB(e,t,n){let r=new Set(pB.slice(0,n).map(e=>Ba[e].sessionKey));return jz(e,e=>r.has(e)?t(e):null,dB)}function hB(e,t){let n=Array.from({length:pB.length+1},(n,r)=>mB(e,t,r));return e=>{let t=pB.indexOf(e);return n[t===-1?pB.length:t]}}function gB(e,t,n,r){return e.flatMap(([e,i])=>{let a=cB[e](t);return a===null||a===cB[e](n(e))?[]:[{...i,value:a,target:r(i)}]})}function _B(e,t,n){return cB[n](fB(e,t))}function vB(e,t){let n=fB(e,t);return gB(lB,n,hB(e,t),t=>yB(e,n.preset,t.configKey))}function yB(e,t,n){return n in(B_(e.presets,t).globals??{})?WO(t,n):n}function bB(e,t,n){let r=z_(t(Ba.preset.sessionKey),e.globals.preset,e.presets),i=GO(n);return{key:i?.scope===`globals`?yB(e,r,i.field):n,globals:H_(e,r)}}function xB(e,t){let{preset:n}=fB(e,t);return wB(e,n).flatMap(({id:e,setting:r,key:i,decl:a,saved:o})=>{let s=t(i),c=s===null?void 0:b_(a,s);return c===void 0||y_(c)===y_(o)?[]:[{preset:n,id:e,setting:r,key:i,value:c}]})}function SB(e,t,n){let r=new Map(n.map(e=>[e.key,e.value]));return R_(e.presets).flatMap(n=>{let i=wB(e,n);return[...new Set(i.filter(e=>r.has(e.key)).map(e=>e.id))].flatMap(e=>{let n=i.filter(t=>t.id===e);return __(Object.fromEntries(n.map(e=>[e.setting,e.decl])),Object.fromEntries(n.map(e=>{let n=r.get(e.key)??t(e.key),i=n===null?void 0:b_(e.decl,n);return[e.setting,i??e.saved]}))).map(({message:t})=>`placement "${e}": ${t}`)})})}const CB=new WeakMap;function wB(e,t){let n=CB.get(e)??new Map;CB.set(e,n);let r=n.get(t);if(r!==void 0)return r;let i=[...$g(V_(e,t).node)].flatMap(t=>t.kind!==`segment`||t.drafts===void 0?[]:Object.entries(t.drafts).map(([n,{id:r,key:i}])=>{let a=h_(e.segments[t.name])[n];return{id:r,setting:n,key:i,decl:a,saved:t.settings?.[n]??a.default}})),a=[...new Map(i.map(e=>[e.key,e])).values()];return n.set(t,a),a}function TB(e,t){let n=fB(e,t);return{from:n.preset,globals:B_(e.presets,n.preset).globals??{},picks:gB(lB.filter(([e])=>e!==`preset`),n,hB(e,t),e=>e.configKey),placements:xB(e,t)}}function EB(e,t){return jz({...e,globals:{palette:t},presets:{}},()=>null,dB)}function DB(e,t){let n=fB(e,t),r=cB.theme(n);if(r===null)return{kind:`rule`};let i=EB(e,r),a=H_(e,n.preset),o=Object.fromEntries(i_.map(e=>[e,cB[e](a[e]===void 0?n:i)]));return{kind:`look`,theme:r,look:o,differs:i_.some(e=>o[e]!==cB[e](i))}}function OB(e){return{sessionKeys:Va.filter(t=>t.configKey===e).map(e=>e.sessionKey),fileKeys:[e,...SO(e)?ZR.map(t=>WO(t,e)):[],...UO(e)?Zm().map(t=>HO(t,e)):[]]}}function kB(e){return new Set(Va.map(e=>e.configKey).filter(t=>OB(t).fileKeys.some(t=>MB(e,jB(t)))))}function AB(e,t,n){let r=vB(e,n),i=new Set(r.map(e=>e.configKey)),a=Ka(e=>i.has(Ba[e].configKey)||t.has(Ba[e].configKey)),o=DB(e,n);return{unsaved:r.length+xB(e,n).length,resettable:a,themeDefault:o.kind===`look`&&o.differs?{differs:!0,theme:o.theme}:{differs:!1}}}function jB(e){let t=GO(e);if(t===null||t.scope===`preset-root`)throw Error(`reset layer "${e}" is not a value path`);return KO(t)}function MB(e,t){let[n,...r]=t;return n===void 0?e!==void 0:typeof e==`object`&&!!e&&MB(e[n],r)}const NB=Zm(),PB=new Set(NB),FB=new Set(vh),IB=e=>e?PB.has(e)?{ok:!0,value:e}:{ok:!1,reason:`unknown theme "${e}" (have: ${NB.join(`, `)})`}:{ok:!1,reason:`theme name is required`},LB=e=>e?FB.has(e)?{ok:!0,value:e}:{ok:!1,reason:`unknown endcaps "${e}" (have: ${vh.join(`, `)})`}:{ok:!1,reason:`endcaps name is required`},RB=new Set([`1`,`true`]),zB=new Set([`0`,`false`]),BB={endcaps:LB,theme:IB,"toolbar-expanded":e=>RB.has(e)?{ok:!0,value:`1`}:zB.has(e)?{ok:!0,value:``}:{ok:!1,reason:`expected boolean-ish (1, 0, true, false), got "${e}"`}},VB=YN(BB,`state`,JB);function HB(e,t){return VB.register(e,t)}function UB(e){return VB.gateFor(e)}function WB(e,t){return`set`in e?`to`in e?[{key:e.set,spec:{kind:`allow-list`,allowed:[e.to]}}]:`from`in e?[{key:e.set,spec:{kind:`allow-list`,allowed:J_(e.from,t).members}}]:`int`in e?[{key:e.set,spec:{kind:`int`}}]:`cycle`in e?[{key:e.set,spec:{kind:`allow-list`,allowed:e.cycle}}]:[{key:e.set,spec:{kind:`range`,min:e.min,max:e.max}}]:[]}function GB(e){return e.filter(e=>e.spec.kind!==`allow-list`||!Object.hasOwn(BB,e.key))}function KB(e,t,n){let r=qa.get(n);if(r!==void 0)return _B(e,t,r);for(let[,t]of d_(e))if(t.key===n)return t.default??null;return null}function qB(e){let t=vN(e);return GB(Object.values(e.actions).flatMap(e=>WB(e,t)))}function JB(e){return qN(qB(e))}const YB=`update.dismissed`,XB=`updateNotice`,ZB=Ba.updateNotice.sessionKey;function QB(e){return e.kind===`source`?e.newer.digest:Mi(e.newer)}const $B=e=>`${e.version} [${jg(e.digest)}]`;function eV(e){switch(e.kind){case`source`:return{headline:`Newer source`,newer:$B(e.newer),running:$B(e.running),act:`rebuild`,busy:`rebuilding…`,command:{bin:`pnpm`,args:[`build`],cwd:e.root}};case`release`:return{headline:`Newer release`,newer:Mi(e.newer),running:Mi(e.running),act:`upgrade`,busy:`upgrading…`,command:{bin:`pnpm`,args:[`dlx`,`${Pi}@${Mi(e.newer)}`,`install`]}}}}const tV={kind:`idle`},nV={kind:`running`};function rV(e,t,n){if(e===null)return[];let r=QB(e);if(!n.enabled||n.dismissed===r)return[];let i=eV(e),a=`${i.headline}: ${i.newer}. You're on ${i.running}.`,o=t.kind===`failed`&&t.identity===r?[`${i.act} failed: ${t.reason}`]:[],s=[a,...o].join(`
|
|
189
|
+
`),c=I([{verb:Ln,args:[s]}]),l=t.kind===`running`?gg(`[${i.busy}]`,c):gg(`[${i.act}]`,I([{verb:Xn,args:[n.sessionId]}]));return[{severity:hg,message:s,lines:[[gg(a,c),l,gg(`[dismiss]`,I([{verb:jn,args:[n.sessionId,YB,r]}])),gg(`[disable]`,I([{verb:Rn,args:[n.sessionId,XB,`false`]},{verb:jn,args:[n.sessionId,ZB,`false`]}]))],...o.map(e=>[gg(e,c)])]}]}function iV(e,t){return e.kind===`stale`?{kind:`source`,root:e.root,newer:e.source,running:e.running}:e.kind===`not-source-checkout`&&t!==null&&t.kind===`stale`?{kind:`release`,newer:t.latest,running:t.installed}:null}function aV(e){switch(e.kind){case`current`:return[`info`,`build: current ${$B(e.stamp)}`];case`stale`:return[`info`,`build: stale — source ${$B(e.source)}, running ${$B(e.running)}`];case`not-source-checkout`:return[`info`,`build: not a source checkout`];case`unchecked`:return[`warn`,`build: unchecked: ${e.reason}`]}}function oV(e){switch(e.kind){case`current`:return[`info`,`release: current ${Mi(e.installed)}`];case`stale`:return[`info`,`release: stale — latest ${Mi(e.latest)}, running ${Mi(e.installed)}`];case`ahead`:return[`info`,`release: ahead — running ${Mi(e.installed)}, latest ${Mi(e.latest)}`];case`unchecked`:return[`warn`,`release: unchecked: ${e.reason}`]}}function sV(e){let t=null;return([n,r])=>{r!==t&&(t=r,e(n,r))}}const cV=e=>e.split(/\r?\n/).map(e=>e.trim()).filter(e=>e!==``).at(-1);function lV(e){let t=e.exitCode===null?``:` (exit ${e.exitCode})`,n=cV(e.stderr)??e.error??cV(e.stdout)??`no output`;return`${e.reason}${t}: ${n}`}function uV(){let e=[ZN(XB,[`false`]),HB(ZB,[`false`]),HB(YB,[])];return()=>e.forEach(e=>e())}function dV(e){let{entryUrl:t,intervalMs:n,releaseIntervalMs:r,registryUrl:i,fetchImpl:a,onApplied:o,log:s}=e,c={kind:`unchecked`,reason:`not sampled yet`},l=null,u=tV,d=null,f=sV(s),p=sV(s),m=()=>iV(c,l);function h(){let e=m(),t=e===null?null:QB(e);(d===null?null:d.identity)!==t&&(d?.dispose(),d=t===null?null:{identity:t,dispose:HB(YB,[t])})}function g(){c=Ig(t,Ng),f(aV(c)),h()}async function _(){l=Ii(Ft,await Fi(Pi,a,i)),p(oV(l)),h()}return{arm(){uV(),g(),setInterval(g,n).unref(),c.kind===`not-source-checkout`&&(_(),setInterval(()=>void _(),r).unref())},notice:e=>rV(m(),u,e),act(){let e=m();if(e===null)throw new q(`apply-update: nothing newer is known to apply`);let t=eV(e);if(u.kind===`running`)throw new q(`apply-update: already ${t.busy}`);u=nV,s(`info`,`apply-update: ${t.act} — ${t.command.bin} ${t.command.args?.join(` `)??``}`),Le({...t.command,category:`update.apply`,timeoutMs:6e5}).then(n=>{if(n.ok){u=tV,s(`info`,`apply-update: ${t.act} succeeded`),g(),o();return}let r=lV(n);u={kind:`failed`,identity:QB(e),reason:r},s(`error`,`apply-update: ${t.act} failed: ${r}`)})}}}var fV=class{static CACHE_DIR=We();static USAGE_CACHE_DIR=v.join(this.CACHE_DIR,`usage`);static LOCKS_DIR=v.join(this.CACHE_DIR,`locks`);static isLocked(e){let t=v.join(this.LOCKS_DIR,e);if(!s.existsSync(t))return!1;try{let n=s.readFileSync(t,`utf-8`),r=parseInt(n.trim(),10);if(isNaN(r))return k(`Invalid PID in lock file ${e}, removing stale lock`),s.unlinkSync(t),!1;try{return process.kill(r,0),!0}catch(n){return n.code===`ESRCH`?(k(`Removing stale lock file ${e} for dead process ${r}`),s.unlinkSync(t),!1):(k(`Error checking process ${r} for lock ${e}:`,n),!0)}}catch(t){return k(`Error reading lock file ${e}:`,t),!0}}static async acquireLock(e,t=5e3){await this.ensureCacheDirectories();let n=v.join(this.LOCKS_DIR,e),r=Date.now(),i=String(process.pid);for(;Date.now()-r<t;)try{return await s.promises.writeFile(n,i,{flag:`wx`}),k(`Lock acquired for ${e}`),!0}catch(e){if(e.code===`EEXIST`)await he(50);else throw e}return k(`Failed to acquire lock for ${e} within ${t}ms`),!1}static async releaseLock(e){let t=v.join(this.LOCKS_DIR,e);try{await s.promises.unlink(t),k(`Lock released for ${e}`)}catch(t){t.code!==`ENOENT`&&k(`Error releasing lock for ${e}:`,t)}}static async ensureCacheDirectories(){try{await Promise.all([s.promises.mkdir(this.CACHE_DIR,{recursive:!0}),s.promises.mkdir(this.USAGE_CACHE_DIR,{recursive:!0}),s.promises.mkdir(this.LOCKS_DIR,{recursive:!0})])}catch(e){k(`Failed to create cache directories:`,e)}}static createProjectHash(e){return ae(`md5`).update(e).digest(`hex`).substring(0,8)}static async getUsageCache(e,t){await this.ensureCacheDirectories();let n=v.join(this.USAGE_CACHE_DIR,`${e}.json`),r=`${e}.usage.lock`;for(let i=0;i<3;i++){if(this.isLocked(r)){k(`Cache for ${e} is locked, waiting...`),await he(75);continue}try{let r=await s.promises.readFile(n,`utf-8`),i=JSON.parse(r);return!t||i.timestamp>=t?(k(`[CACHE-HIT] ${e} disk cache: found`),this.deserializeDates(i.data)):(k(`${e} cache outdated: cache=${i.timestamp}, latest=${t}`),null)}catch(t){if(t.code===`ENOENT`)return k(`No shared ${e} usage cache found`),null;k(`Attempt ${i+1} failed to read ${e} cache: ${t.message}. Retrying...`),await he(75)}}return k(`Failed to read ${e} cache after 3 attempts.`),null}static deserializeDates(e){return Array.isArray(e)?e.map(e=>({...e,timestamp:new Date(e.timestamp)})):e}static async setUsageCache(e,t,n){let r=`${e}.usage.lock`;if(!await this.acquireLock(r)){k(`Could not acquire lock to set usage cache for ${e}`);return}try{await this.ensureCacheDirectories();let r=v.join(this.USAGE_CACHE_DIR,`${e}.json`),i=JSON.stringify({data:t,timestamp:n||Date.now()});await s.promises.writeFile(r,i,`utf-8`),k(`[CACHE-SET] ${e} disk cache stored`)}catch(t){k(`Failed to save ${e} usage cache:`,t)}finally{await this.releaseLock(r)}}};const pV={"claude-haiku-4-5-20251001":{name:`Claude Haiku 4.5`,input:1,output:5,cache_write_5m:1.25,cache_write_1h:2,cache_read:.1},"claude-haiku-4-5":{name:`Claude Haiku 4.5`,input:1,output:5,cache_write_5m:1.25,cache_write_1h:2,cache_read:.1},"claude-opus-4-20250514":{name:`Claude Opus 4`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-opus-4-1":{name:`Claude Opus 4.1`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-opus-4-1-20250805":{name:`Claude Opus 4.1`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-sonnet-4-20250514":{name:`Claude Sonnet 4`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-4-opus-20250514":{name:`Claude 4 Opus`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-4-sonnet-20250514":{name:`Claude 4 Sonnet`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-sonnet-4-5":{name:`Claude Sonnet 4.5`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-sonnet-4-5-20250929":{name:`Claude Sonnet 4.5`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-opus-4-5":{name:`Claude Opus 4.5`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-opus-4-5-20251101":{name:`Claude Opus 4.5`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-opus-4-6":{name:`Claude Opus 4.6`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-opus-4-6-20260205":{name:`Claude Opus 4.6`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-sonnet-4-6":{name:`Claude Sonnet 4.6`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3}};var mV=class{static executionCache=null;static modelPricingCache=new Map;static GITHUB_PRICING_URL=`https://raw.githubusercontent.com/promptctl/cc-candybar/main/pricing.json`;static async loadDiskCache(){let e=Date.now()-1440*60*1e3;return await fV.getUsageCache(`pricing`,e)}static async saveDiskCache(e){await fV.setUsageCache(`pricing`,e)}static async fetchPricingData(){return new Promise(e=>{let t=new n(this.GITHUB_PRICING_URL),r=me({hostname:t.hostname,path:t.pathname,headers:{"User-Agent":`cc-candybar`,"Cache-Control":`no-cache`},timeout:5e3},t=>{if(t.statusCode!==200){k(`HTTP ${t.statusCode}: ${t.statusMessage}`),e(null);return}let n=``,i=0;t.on(`data`,t=>{if(i+=t.length,i>1048576){k(`Response too large`),r.destroy(),e(null);return}n+=t}),t.on(`end`,()=>{try{let t=JSON.parse(n),r=t._meta,i={};for(let[e,n]of Object.entries(t))e!==`_meta`&&(i[e]=n);this.validatePricingData(i)?(k(`Fetched fresh pricing from GitHub for ${Object.keys(i).length} models`),k(`Pricing last updated: ${r?.updated||`unknown`}`),e(i)):(k(`Invalid pricing data structure`),e(null))}catch(t){k(`Failed to parse JSON:`,t),e(null)}}),t.on(`error`,t=>{k(`Response error:`,t),e(null)})});r.on(`error`,t=>{k(`Request error:`,t),e(null)}),r.on(`timeout`,()=>{k(`Request timeout`),r.destroy(),e(null)}),r.end()})}static async getCurrentPricing(){if(this.executionCache!==null)return k(`[CACHE-HIT] Pricing execution cache: ${Object.keys(this.executionCache).length} models`),this.executionCache;let e=await this.loadDiskCache();if(e)return k(`[CACHE-HIT] Pricing disk cache: ${Object.keys(e).length} models`),this.executionCache=e,k(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(e).length} models`),e;let t=await this.fetchPricingData();return t?(await this.saveDiskCache(t),k(`[CACHE-SET] Pricing disk cache stored: ${Object.keys(t).length} models`),this.executionCache=t,k(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(t).length} models`),t):(k(`[CACHE-FALLBACK] Using offline pricing data: ${Object.keys(pV).length} models`),this.executionCache=pV,k(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(pV).length} models`),pV)}static validatePricingData(e){if(!e||typeof e!=`object`)return!1;for(let[,t]of Object.entries(e)){if(!t||typeof t!=`object`)return!1;let e=t;if(typeof e.input!=`number`||typeof e.output!=`number`||typeof e.cache_read!=`number`)return!1}return!0}static async getModelPricing(e){if(this.modelPricingCache.has(e))return k(`[CACHE-HIT] Model pricing cache: ${e}`),this.modelPricingCache.get(e);let t=await this.getCurrentPricing(),n;return n=t[e]?t[e]:this.fuzzyMatchModel(e,t),this.modelPricingCache.set(e,n),k(`[CACHE-SET] Model pricing cache: ${e}`),n}static fuzzyMatchModel(e,t){let n=e.toLowerCase();for(let[e,r]of Object.entries(t))if(e.toLowerCase()===n)return r;for(let{pattern:e,fallback:r}of[{pattern:[`opus-4-6`,`claude-opus-4-6`],fallback:`claude-opus-4-6-20260205`},{pattern:[`opus-4-5`,`claude-opus-4-5`],fallback:`claude-opus-4-5-20251101`},{pattern:[`opus-4-1`,`claude-opus-4-1`],fallback:`claude-opus-4-1-20250805`},{pattern:[`opus-4`,`claude-opus-4`],fallback:`claude-opus-4-20250514`},{pattern:[`sonnet-4-6`,`sonnet-4.6`,`claude-sonnet-4-6`],fallback:`claude-sonnet-4-6`},{pattern:[`sonnet-4.5`,`4-5-sonnet`,`sonnet-4-5`],fallback:`claude-sonnet-4-5-20250929`},{pattern:[`sonnet-4`,`claude-sonnet-4`],fallback:`claude-sonnet-4-20250514`},{pattern:[`haiku-4.5`,`4-5-haiku`,`haiku-4-5`],fallback:`claude-haiku-4-5-20251001`},{pattern:[`haiku`],fallback:`claude-haiku-4-5-20251001`},{pattern:[`opus`],fallback:`claude-opus-4-20250514`},{pattern:[`sonnet`],fallback:`claude-sonnet-4-5-20250929`}])if(e.some(e=>n.includes(e))&&t[r])return t[r];return t[`claude-sonnet-4-5-20250929`]||{name:`${e} (Unknown Model)`,input:3,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3,output:15}}static async calculateCostForEntry(e){let t=e.message?.usage;if(!t)return 0;let n=this.extractModelId(e),r=await this.getModelPricing(n),i=t.input_tokens||0,a=t.output_tokens||0,o=t.cache_creation_input_tokens||0,s=t.cache_read_input_tokens||0,c=i/1e6*r.input,l=a/1e6*r.output,u=s/1e6*r.cache_read,d=o/1e6*r.cache_write_5m;return c+l+d+u}static extractModelId(e){if(e.model&&typeof e.model==`string`)return e.model;let t=e.message;if(t?.model){let e=t.model;if(typeof e==`string`)return e;let n=e;return(typeof n?.id==`string`?n.id:null)||`claude-sonnet-4-5-20250929`}return e.model_id&&typeof e.model_id==`string`?e.model_id:`claude-sonnet-4-5-20250929`}};const hV=/<command-name>\s*([^<\s][^<]*?)\s*<\/command-name>/;function gV(e){if(typeof e==`string`)return hV.exec(e)?.[1]}function _V(e){let t=e?.todos;if(!Array.isArray(t))return;let n=[];for(let e of t){if(typeof e!=`object`||!e)continue;let{content:t,activeForm:r,status:i}=e,a=i===`in_progress`,o=a&&typeof r==`string`?r:t;typeof o==`string`&&n.push({text:o,active:a,done:i===`completed`})}return n}function vV(e){return typeof e==`string`?e:Array.isArray(e)?e.find(e=>typeof e==`object`&&!!e&&e.type===`text`&&typeof e.text==`string`)?.text??``:``}function yV(e,t){let n=e.message?.content,r=[],i=[],a;if(Array.isArray(n))for(let e of n){if(typeof e!=`object`||!e)continue;let t=e;switch(t.type){case`tool_use`:{let{id:e,name:n}=t;if(typeof e!=`string`||typeof n!=`string`)break;r.push({id:e,name:n}),n===`TodoWrite`&&(a=_V(t.input)??a);break}case`tool_result`:{let e=t.tool_use_id;typeof e==`string`&&i.push(e);break}default:break}}let o=t===`prompt`?gV(vV(n)):void 0;if(!(r.length===0&&i.length===0&&a===void 0&&o===void 0))return{...r.length>0&&{started:r},...i.length>0&&{finished:i},...a!==void 0&&{todos:a},...o!==void 0&&{command:o}}}function bV(e){if(e!==void 0)return[e];let t=ee();return[S(t,`.config`,`claude`),S(t,`.claude`)].filter(e=>d(e))}async function xV(e){let t=[];for(let n of e){let e=S(n,`projects`);if(d(e))try{let n=await oz(e,{withFileTypes:!0});for(let r of n)if(r.isDirectory()){let n=S(e,r.name);t.push(n)}}catch(t){k(`Failed to read projects directory ${e}:`,t)}}return t}async function SV(e,t,n){let r=[],i=S(t,e,`subagents`);try{let t=(await oz(i)).filter(e=>e.startsWith(`agent-`)&&e.endsWith(`.jsonl`));for(let a of t){let t=S(i,a);if(n?.has(t)){r.push(t);continue}try{let n=(await sz(t,`utf-8`)).split(`
|
|
190
|
+
`)[0];n&&JSON.parse(n).sessionId===e&&r.push(t)}catch{k(`Failed to check agent file ${t}`)}}}catch(e){k(`Failed to read subagents directory ${i}:`,e)}return r}function CV(e){let t=e.message;if((e.type||t?.role||t?.type)!==`user`)return;if(TV(t)===`tool_result`)return`tool-result`;let n=typeof e.origin==`object`&&e.origin!==null?e.origin.kind:void 0;if(n!==void 0&&n!==`human`)return`turn`;let r=vV(t?.content).trimStart();return r.startsWith(`[Request interrupted by user`)?`interrupt`:e.isMeta===!0||e.isCompactSummary===!0||wV.test(r)?`claude-code`:`prompt`}const wV=/^<(?:command-name|local-command-std(?:out|err)|bash-(?:input|stdout|stderr))>/;function TV(e){let t=e?.content;return Array.isArray(t)&&typeof t[0]==`object`&&t[0]?t[0].type:void 0}const EV=new Map;async function DV(e){try{let t=await cz(e),n=t.size,r=EV.get(e);if(r&&r.mtime===t.mtimeMs&&r.size===n)return k(`[parse-cache] hit ${e}`),EV.delete(e),EV.set(e,r),r.entries;let i;return n>1048576?(k(`Using streaming parser for large file ${e} (${Math.round(n/1024)}KB)`),i=await PV(e)):i=await MV(e),k(`Parsed ${i.length} entries from ${e}`),n>5242880?i:(EV.delete(e),EV.size>=16&&EV.delete(EV.keys().next().value),EV.set(e,{mtime:t.mtimeMs,size:n,entries:i}),i)}catch(t){if(t.code===`ENOENT`)return k(`Transcript not present yet: ${e}`),[];throw t}}function OV(e){if(!e.timestamp)return null;let t=e.message,n=t?.usage,r=CV(e);return{timestamp:new Date(e.timestamp),type:typeof e.type==`string`?e.type:void 0,message:t?{id:typeof t.id==`string`?t.id:void 0,model:typeof t.model==`string`?t.model:void 0,usage:n,role:typeof t.role==`string`?t.role:void 0,type:typeof t.type==`string`?t.type:void 0}:void 0,costUSD:typeof e.costUSD==`number`?e.costUSD:void 0,isSidechain:e.isSidechain===!0,userEntry:r,activity:yV(e,r),raw:{model:typeof e.model==`string`?e.model:void 0,message:t?{id:typeof t.id==`string`?t.id:void 0,model:typeof t.model==`string`?t.model:void 0,usage:n}:void 0,requestId:typeof e.requestId==`string`?e.requestId:void 0}}}function kV(e){let t=e.trim();if(!t)return{kind:`blank`};try{let e=JSON.parse(t);return typeof e==`object`&&e&&!Array.isArray(e)?{kind:`object`,value:e}:{kind:`unparsed`,reason:`not a JSON object`}}catch(e){return{kind:`unparsed`,reason:String(e)}}}function AV(e){let t=kV(e);if(t.kind===`unparsed`)return k(`Failed to parse JSONL line: ${t.reason}`),null;if(t.kind===`blank`)return null;try{return OV(t.value)}catch(e){return k(`Failed to project JSONL line: ${e}`),null}}function jV(e){let t=[];for(let n of e.split(`
|
|
191
|
+
`)){let e=AV(n);e&&t.push(e)}return t}async function MV(e){return jV(await sz(e,`utf-8`))}async function NV(e,t){let n=await lz(e,t===void 0?void 0:{offset:t.offset,ino:t.ino});if(n.kind!==`ok`)return n;let{buf:r,start:i,stamp:a,ino:o,reset:s}=n.value,c=r.lastIndexOf(10);return L(c<0?{entries:[],cursor:{offset:i,stamp:a,ino:o},reset:s}:{entries:jV(r.subarray(0,c+1).toString(`utf-8`)),cursor:{offset:i+c+1,stamp:a,ino:o},reset:s})}async function PV(e){return new Promise((t,n)=>{let r=[],i=u(e,{encoding:`utf8`}),a=ge({input:i,crlfDelay:1/0});a.on(`line`,e=>{let t=AV(e);t&&r.push(t)}),a.on(`close`,()=>{t(r)}),a.on(`error`,t=>{k(`Streaming parser error for ${e}:`,t),n(t)}),i.on(`error`,t=>{k(`File stream error for ${e}:`,t),n(t)})})}var FV=class{inflight=new Map;run(e,t){return this.inflight.get(e)??this.start(e,t)}start(e,t){let n=t();this.inflight.set(e,n);let r=()=>{this.inflight.get(e)===n&&this.inflight.delete(e)};return n.then(r,r),n}get size(){return this.inflight.size}};function IV(e,t){let n=e?e.input+e.cacheCreation+e.cacheRead:0,r=e?e.output:0;return{input:n,output:r,total:n+r,atMs:t}}const LV=new Map,RV={cost:0,input:0,output:0,cacheCreation:0,cacheRead:0},zV={cost:null,calculatedCost:null,officialCost:null,tokens:null,tokenBreakdown:null};function BV(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function VV(){let e=new Date;return e.setHours(0,0,0,0),e.setDate(e.getDate()-1),e.getTime()}function HV(){return{input:0,output:0,cacheCreation:0,cacheRead:0}}async function UV(e,t,n,r){let i=BV(new Date(VV())),a=e&&!t?e:void 0,o=a?.entries??0,s=a?.cost??0,c=a?{...a.breakdown}:HV(),l=new Map;if(a)for(let[e,t]of a.days)e>=i&&l.set(e,{...t});for(let e of n){let t=e.message?.usage;if(!t)continue;o++;let n=e.costUSD??await mV.calculateCostForEntry(e.raw);s+=n,c.input+=t.input_tokens||0,c.output+=t.output_tokens||0,c.cacheCreation+=t.cache_creation_input_tokens||0,c.cacheRead+=t.cache_read_input_tokens||0;let r=BV(new Date(e.timestamp));if(r<i)continue;let a=l.get(r)??{...RV};a.cost+=n,a.input+=t.input_tokens||0,a.output+=t.output_tokens||0,a.cacheCreation+=t.cache_creation_input_tokens||0,a.cacheRead+=t.cache_read_input_tokens||0,l.set(r,a)}return{cursor:r,entries:o,cost:s,breakdown:c,days:l}}function WV(e){let t=0,n=0,r=HV(),i=new Map;for(let a of e.values()){t+=a.entries,n+=a.cost,r.input+=a.breakdown.input,r.output+=a.breakdown.output,r.cacheCreation+=a.breakdown.cacheCreation,r.cacheRead+=a.breakdown.cacheRead;for(let[e,t]of a.days){let n=i.get(e)??{...RV};n.cost+=t.cost,n.input+=t.input,n.output+=t.output,n.cacheCreation+=t.cacheCreation,n.cacheRead+=t.cacheRead,i.set(e,n)}}if(t===0)return{sessionInfo:zV,days:i};let a=r.input+r.output+r.cacheCreation+r.cacheRead;return{sessionInfo:{cost:n,calculatedCost:n,officialCost:null,tokens:a,tokenBreakdown:r},days:i}}async function GV(e,t,n){let r=0,i=async()=>{for(;r<e.length;){let t=e[r++];await n(t)}},a=Math.min(t,e.length);await Promise.all(Array.from({length:a},i))}var KV=class{sessions=new Map;flight=new FV;seeded=new Map;seededDay=``;rescanIntervalMs;speedFlight=new FV;staleAgeMs;log;renderTally={hits:0,misses:0};sweeps=0;scans={seed:0,rescan:0};sweepTimer=null;constructor(e={}){this.log=e.logger??Gt,this.staleAgeMs=e.staleAgeMs??864e5,this.rescanIntervalMs=e.rescanIntervalMs??6e4;let t=e.sweepIntervalMs??3e5;t>0&&(this.sweepTimer=setInterval(()=>this.sweepStale(),t),this.sweepTimer.unref())}getStats(){return{size:this.sessions.size,hits:this.renderTally.hits,misses:this.renderTally.misses,sweeps:this.sweeps,seeds:this.scans.seed,rescans:this.scans.rescan}}async getUsageInfo(e,t){let n=await this.ingest(e,t?.transcript_path,this.renderTally);if(n.kind===`failed`)return n;let r=n.kind===`ok`?n.value.sessionInfo:zV,i=t?.cost?.total_cost_usd??null;return L({session:{...r,cost:i??r.cost,officialCost:i}})}async getTodayInfo(e,t,n){let r=BV(bE(n)),i=bV(t);try{await this.ensureSeeded(r,i,n*1e3)}catch(e){return z(`usage seed: ${e instanceof Error?e.message:String(e)}`)}let a=await this.ingest(e?.session_id??``,e?.transcript_path,this.renderTally);if(a.kind===`failed`)return a;let o=i.map(e=>S(e,`projects`)+C),s={...RV},c=!1;for(let[t,{record:n}]of this.sessions){let i=n?.transcriptPath??``,a=t===e?.session_id||o.some(e=>i.startsWith(e))?n?.days??LV:LV;c||=a.has(r);let l=a.get(r)??RV;s.cost+=l.cost,s.input+=l.input,s.output+=l.output,s.cacheCreation+=l.cacheCreation,s.cacheRead+=l.cacheRead}return c?L({cost:s.cost,tokens:s.input+s.output+s.cacheCreation+s.cacheRead,tokenBreakdown:{input:s.input,output:s.output,cacheCreation:s.cacheCreation,cacheRead:s.cacheRead},date:r}):R}async observeSpeed(e,t,n){if(!e)return R;let r=nz(t);return this.speedFlight.run(`${e}:${r}`,async()=>{let i=await this.ingest(e,t,this.renderTally,r);if(i.kind===`failed`)return i;let a=IV(i.kind===`ok`?i.value.sessionInfo.tokenBreakdown:null,n),{ring:o}=this.hold(e),s;for(let e of o)e.atMs<a.atMs&&(s===void 0||e.atMs>s.atMs)&&(s=e);return o.push(a),o.sort((e,t)=>e.atMs-t.atMs),o.length>64&&o.shift(),L({...s!==void 0&&{prev:s},cur:a,samples:[...o]})})}async ingest(e,t,n,r){if(!e)return R;let i=r??nz(t),a=this.see(e)?.record;if(a&&i!==``&&a.transcriptStamp===i)return n.hits++,L(a);if(!t)return a?L(a):R;n.misses++;let o;try{o=await this.flight.run(`${e}:${i}`,async()=>{let n=this.sessions.get(e)?.record;return{prior:n,outcome:await this.refold(e,t,n)}})}catch(t){return z(`usage refold (${e}): ${t instanceof Error?t.message:String(t)}`)}let{prior:s,outcome:c}=o;if(c.kind!==`ok`)return c;let l={files:c.value.files,sessionInfo:c.value.sessionInfo,days:c.value.days,transcriptStamp:c.value.mainStamp,transcriptPath:t};return this.sessions.get(e)?.record===s&&(this.hold(e).record=l),L(l)}see(e){let t=this.sessions.get(e);return t&&(t.lastSeenAt=Date.now()),t}hold(e){let t=this.see(e);if(t)return t;let n={lastSeenAt:Date.now(),record:void 0,ring:[]};return this.sessions.set(e,n),n}async refold(e,t,n){let r=await SV(e,b(t),n===void 0?void 0:new Set(n.files.keys())),i=new Map,a=``;for(let e of[t,...r]){let r=n?.files.get(e),o=await NV(e,r?.cursor);if(o.kind===`failed`)return o;if(o.kind===`absent`){r&&i.set(e,r);continue}let{entries:s,cursor:c,reset:l}=o.value;i.set(e,await UV(r,l,s,c)),e===t&&(a=c.stamp)}return L({files:i,...WV(i),mainStamp:a})}ensureSeeded(e,t,n){this.seededDay!==e&&(this.seeded.clear(),this.seededDay=e);let r=t.join(`\0`),i=this.seeded.get(r);if(!i){let e=this.seed(t,`seed`),i={done:e,scanning:e,startedAtMs:n};return this.seeded.set(r,i),this.settle(r,i,e),e}return i.scanning===void 0&&n-i.startedAtMs>=this.rescanIntervalMs&&(i.startedAtMs=n,i.scanning=this.seed(t,`rescan`),this.settle(r,i,i.scanning)),i.done}settle(e,t,n){n.then(()=>{t.scanning=void 0},n=>{this.log(`warn`,`usageStore scan: ${n instanceof Error?n.message:String(n)}`),this.seeded.get(e)===t&&this.seeded.delete(e)})}async scanned(){await Promise.allSettled([...this.seeded.values()].map(e=>e.scanning))}async seed(e,t){let n=Date.now(),r=VV(),i=await xV(e),a=[];for(let e of i){let t;try{t=await oz(e)}catch{continue}for(let n of t){if(!n.endsWith(`.jsonl`))continue;let t=S(e,n),i;try{i=await cz(t)}catch{continue}i.mtimeMs<r||a.push({sessionId:n.slice(0,-6),path:t,stamp:rz(i)})}}let o={hits:0,misses:0};await GV(a,8,async e=>{let n=await this.ingest(e.sessionId,e.path,o,e.stamp);n.kind===`failed`&&this.log(`warn`,`usageStore ${t}: ${n.reason}`)}),this.log(`info`,`usageStore ${t} sessions=${a.length} read=${o.misses} dirs=${e.join(`,`)} ms=${Date.now()-n}`),this.scans[t]++}sweepStale(){let e=Date.now(),t=0,n=0,r=0;for(let[i,{lastSeenAt:a,record:o}]of this.sessions)if(!(e-a<=this.staleAgeMs)){if(o?.days.has(this.seededDay)){n++;continue}this.sessions.delete(i),t++,o===void 0&&r++}return t>0&&this.sweeps++,(t>0||n>0)&&this.log(`info`,`usageStore sweep dropped=${t} noRecord=${r} held=${n}`),t}close(){this.sweepTimer&&=(clearInterval(this.sweepTimer),null),this.sessions.clear(),this.seeded.clear()}},qV=class{thresholds={LOW:50,MEDIUM:80};getContextUsageThresholds(){return this.thresholds}ratioPercentages(e,t){let n=Math.min(100,Math.max(0,Math.round(e/t*100)));return{percentage:n,contextLeftPercentage:Math.max(0,100-n)}}calculateContextFromHookData(e){let t=e.context_window;if(!t?.current_usage)return k(`No current_usage in hook data, falling back to transcript parsing`),null;let n=t.current_usage,r=t.context_window_size,i=(n.input_tokens||0)+(n.cache_creation_input_tokens||0)+(n.cache_read_input_tokens||0);k(`Native current_usage: input=${n.input_tokens}, cache_create=${n.cache_creation_input_tokens}, cache_read=${n.cache_read_input_tokens}, total=${i} (limit: ${r})`);let a=this.ratioPercentages(i,r);return{totalTokens:i,maxTokens:r,percentage:t.used_percentage==null?a.percentage:Math.round(t.used_percentage),contextLeftPercentage:t.remaining_percentage==null?a.contextLeftPercentage:Math.round(t.remaining_percentage)}}async calculateContextTokensFromTranscript(e,t){try{k(`Calculating context tokens from transcript: ${e}`);let n=await DV(e);if(n.length===0)return k(`No entries in transcript`),R;let r=null;for(let e=n.length-1;e>=0;e--){let t=n[e];if(t&&t.message?.usage?.input_tokens&&t.isSidechain!==!0){r=t,k(`Context segment: Found most recent entry at ${t.timestamp.toISOString()}, stopping search`);break}}if(r?.message?.usage){let e=r.message.usage,n=(e.input_tokens||0)+(e.cache_read_input_tokens||0)+(e.cache_creation_input_tokens||0);return k(`Most recent main chain context: ${n} tokens (limit: ${t})`),L({totalTokens:n,maxTokens:t,...this.ratioPercentages(n,t)})}return k(`No main chain entries with usage data found`),R}catch(e){return z(`context transcript: ${e instanceof Error?e.message:String(e)}`)}}async getContextInfo(e){let t=this.calculateContextFromHookData(e);if(t)return L(t);let n=e.context_window?.context_window_size??2e5;return this.calculateContextTokensFromTranscript(e.transcript_path,n)}},JV=class{states=new Map;constructor(e,t,n=256){this.empty=e,this.step=t,this.maxSessions=n}async read(e,t){let n=this.states.get(e),r=nz(t);if(n&&r!==``&&n.cursor.stamp===r)return this.touch(e,n),{kind:`ok`,value:n.value};let i=await NV(t,n?.cursor);if(i.kind===`failed`)return i;if(i.kind===`absent`)return{kind:`ok`,value:n?.value??this.empty};let{entries:a,cursor:o,reset:s}=i.value,c=s||n===void 0?this.empty:n.value;for(let e of a)c=this.step(c,e);for(this.touch(e,{cursor:o,value:c});this.states.size>this.maxSessions;){let e=this.states.keys().next().value;if(e===void 0)break;this.states.delete(e)}return{kind:`ok`,value:c}}touch(e,t){this.states.delete(e),this.states.set(e,t)}};const YV={messageCount:0,nonPrompts:0,recent:[]},XV=new Set([`turn`,`interrupt`,`claude-code`]);function ZV(e,t){if(t.isSidechain)return e;let n=[...e.recent,t];return{messageCount:e.messageCount+ +(t.userEntry===`prompt`),nonPrompts:e.nonPrompts+ +!!XV.has(t.userEntry),recent:n.length>20?n.slice(-20):n}}function QV(e){let t=null,n=null;for(let r of e){let e=r.type||r.message?.role||r.message?.type;if(r.userEntry===`prompt`||r.userEntry===`turn`)t=r.timestamp;else if(e===`assistant`&&t){let e=(r.timestamp.getTime()-t.getTime())/1e3;e>.1&&e<300&&(n=e)}}return n}var $V=class{fold=new JV(YV,ZV);async getMetricsInfo(e,t){if(k(`Getting metrics from hook data for session: ${e}`),!t.cost)return R;let n=await this.fold.read(e,t.transcript_path);return n.kind===`failed`?z(`metrics (${e}): ${n.reason}`):L({responseTime:t.cost.total_api_duration_ms/1e3,lastResponseTime:QV(n.value.recent),sessionDuration:t.cost.total_duration_ms/1e3,messageCount:n.value.messageCount,nonPrompts:n.value.nonPrompts,linesAdded:t.cost.total_lines_added,linesRemoved:t.cost.total_lines_removed})}};const eH={command:null,todos:[],pending:[],done:[]};function tH(e,t){let n=e.findIndex(e=>e.name===t);return n<0?[...e,{name:t,count:1}]:e.map((e,t)=>t===n?{name:e.name,count:e.count+1}:e)}function nH(e,t){switch(t.userEntry){case`prompt`:return{...e,command:t.activity?.command??null,pending:[],done:[]};case`interrupt`:return{...e,pending:[]};case`turn`:case`tool-result`:case`claude-code`:case void 0:return e}}function rH(e,t){if(t.isSidechain)return e;let n=nH(e,t),r=t.activity;if(r===void 0)return n;let i=n.pending,a=n.done;r.started!==void 0&&(i=[...i,...r.started]);for(let e of r.finished??[]){let t=i.findIndex(t=>t.id===e);t<0||(a=tH(a,i[t].name),i=[...i.slice(0,t),...i.slice(t+1)])}return{...n,pending:i,done:a,todos:r.todos??n.todos}}function iH(e){return{command:e.command,todos:e.todos,running:e.pending.reduce((e,t)=>tH(e,t.name),[]),done:e.done}}var aH=class{fold=new JV(eH,rH);async getActivityInfo(e,t){let n=await this.fold.read(e,t.transcript_path);return n.kind===`failed`?z(`activity (${e}): ${n.reason}`):L(iH(n.value))}};function oH(e,t,n,r){return{bin:`tmux`,args:[`-S`,e.socket,...n],timeoutMs:2e3,category:t,stdinInput:r}}function sH(e,t){if(e.ok)return{kind:`ok`,stdout:e.stdout};if(e.reason===`rate-limited`)return{kind:`rate-limited`,reason:e.error??`rate-limited`};let n=e.error??[e.reason,e.stderr.trim()].filter(e=>e!==``).join(`: `);return{kind:`failed`,reason:`tmux ${t[0]} failed (${n})`}}function cH(e,t,n,r){return sH(Re(oH(e,t,n,r)),n)}async function lH(e,t,n){return sH(await Le(oH(e,t,n)),n)}const uH=e=>`${e.socket}\n${e.pane}`;var dH=class{names=new Map;asking=new FV;constructor(e=Date.now){this.now=e}getSessionName(e){let t=uH(e),n=this.names.get(t);if(n&&this.now()-n.at<3e4)return Promise.resolve(n.outcome);let r=this.asking.run(t,()=>this.ask(t,e));return n?Promise.resolve(n.outcome):r}async ask(e,t){k(`Getting tmux session name for pane ${t.pane} on ${t.socket}`);let n=await lH(t,`tmux`,[`display-message`,`-p`,`-t`,t.pane,`#S`]),r=n.kind===`ok`?n.stdout.trim():``,i=n.kind===`ok`?r?L(r):R:z(n.reason);for(this.names.delete(e),this.names.set(e,{outcome:i,at:this.now()});this.names.size>64;)this.names.delete(this.names.keys().next().value);return i}};const fH=e=>JSON.stringify([e.sessionId,e.projectDir,e.cwd,e.claudeConfigDir,e.env===void 0?null:ot.map(t=>e.env?.[t]??null)]);var pH=class{readings=new Map;inFlight=new Map;constructor(e,t=Date.now){this.edge=e,this.now=t}getCeiling(e){let t=fH(e),n=this.readings.get(t);if(n&&this.now()-n.at<1e4)return Promise.resolve(n.outcome);let r=this.inFlight.get(t)??this.fetch(t,e);return n?Promise.resolve(n.outcome):r}fetch(e,t){let n=this.edge.locate(t),r=(n.kind===`ok`?this.edge.read(n.value,t):Promise.resolve(n)).then(t=>{if(this.inFlight.get(e)!==r)return t;for(this.readings.delete(e),this.readings.set(e,{outcome:t,at:this.now()});this.readings.size>64;)this.readings.delete(this.readings.keys().next().value);return t}).finally(()=>{this.inFlight.get(e)===r&&this.inFlight.delete(e)});return this.inFlight.set(e,r),r}move(e,t){let n=this.edge.locate(e);if(n.kind!==`ok`)throw Error(n.kind===`failed`?n.reason:`memento is not installed or not enabled for this project`);let r=fH(e);try{this.edge.move(n.value,e,t)}finally{this.readings.delete(r),this.inFlight.delete(r),this.fetch(r,e)}}};function mH(e){return{gitProvider:new mE({watchers:e.watchers,logger:e.logger}),usageStore:new KV({logger:e.logger}),contextProvider:new qV,metricsProvider:new $V,activityProvider:new aH,tmuxService:new dH,mementoProvider:new pH(kz()),autoCompact:vj,log:e.logger}}function hH(e,t){return e===void 0?!0:e.evaluate(t).map(e=>e.plain).join(``)!==`false`}const gH={kind:`hidden`},_H={kind:`shown`};function vH(e,t){try{return hH(e,t)?_H:gH}catch(e){return{kind:`failed`,message:e instanceof Error?e.message:String(e)}}}function yH(e,t){let n=K.fromFragments(e);return n.end=``,n.overflow=`ignore`,t!==void 0&&!t.isNull&&(n.style=t),n}function bH(e,t,n){e.cellLength>t?e.truncate(t,{mode:n.truncate,marker:`…`}):e.cellLength<t&&e.align(n.justify,t)}function xH({lead:e,text:t,trail:n}){return[...e===void 0?[]:[e],t,...n===void 0?[]:[n]]}function SH({text:e,placement:t,lead:n,trail:r}){return{text:CH(e),placement:t,...n!==void 0&&{lead:CH(n)},...r!==void 0&&{trail:CH(r)}}}function CH(e){let t=e.blankCopy(e.plain);t.style=Ip(e.style).clearMetaAndLinks();for(let{start:n,end:r,style:i}of e.spans)t.stylize(Ip(i).clearMetaAndLinks(),n,r);return t}function wH(e){let t=xH(e);if(t.length===1)return e.text;let n=yH(t);return n.style=e.text.style,n}function TH(e,t){let{width:n,justify:r,truncate:i,baseStyle:a,padding:o,placement:s,lead:c=[],trail:l=[]}=t;if(e.length===0)return[];let u=yH(e,a).pad(o),d=new K(` `.repeat(o)),f={placement:s,...c.length>0&&{lead:yH([d,...c],a)},...l.length>0&&{trail:yH([...l,d],a)}};if(n===`auto`)return[{text:u,...f}];let p={justify:r,truncate:i};return n===`fill`?[{text:u,fill:p,...f}]:(bH(u,n,p),[{text:u,...f}])}const EH=RegExp(`\\x1b\\[[0-9;]*m|${mu.source}`,`g`);function DH(e){return Math.max(0,...e.split(`
|
|
192
|
+
`).map(e=>io(e.replace(EH,``))))}function OH(e,t){let n=()=>e.map(e=>({owner:wH(e),placement:e.placement})),r=[];if(e.forEach(({fill:e},t)=>{e!==void 0&&r.push({at:t,how:e})}),r.length===0||!Number.isFinite(t.width))return n();let i=dg(e.map(wH),t).split(`
|
|
193
|
+
`);if(i.length>1)return n();let a=Math.max(0,t.width-DH(i[0]??``)),o=Math.floor(a/r.length),s=a-o*r.length;return r.forEach(({at:t,how:n},i)=>{let a=o+(i===r.length-1?s:0),{text:c}=e[t];bH(c,c.cellLength+a,n)}),n()}function kH(e,t){let n=[],r=[],i=()=>{if(!r.length)return;let e=AH(r,t);e.plain.length>0&&n.push(e),r=[]};for(let a of e){let e={frag:a,style:Ip(a.style)};if(e.style.link){i();let r=AH([e],t);r.plain.length>0&&n.push(r)}else r.push(e)}return i(),n}function AH(e,t){let n=t!==void 0&&!t.isNull?t:void 0,r=e.map(e=>jH(e.frag,n?n.add(e.style):e.style)),i=K.fromFragments(r);return i.end=``,i.overflow=`ignore`,r.length===1?i.style=r[0].style:n!==void 0&&(i.style=n),i}function jH(e,t){let n=e.copy();return n.style=t,n}function MH(e,t){if(e.look===void 0)throw Error(`${t} read the render's look before any render resolved one`);return e.look}function NH(e,t,n,r){let i=new Map,a=Object.entries(t);for(let[t,o]of[...a.filter(([,e])=>!(`do`in e)),...a.filter(([,e])=>`do`in e)])i.set(t,PH(e,t,o,n,r,i));return i}function PH(e,t,n,r,i,a){if(`set`in n){let e=r.get(n.set)??n.set;if(`to`in n)return{kind:`set-literal`,key:n.set,value:n.to,stateVar:e};if(`from`in n){let t=J_(n.from,i);return{kind:`set-option`,key:n.set,stateVar:e,options:[...t.members],paletteOf:t.paletteOf,library:t.library}}return`int`in n?{kind:`set-int`,key:n.set,stateVar:e}:`cycle`in n?{kind:`set-cycle`,key:n.set,stateVar:e,members:n.cycle}:{kind:`set-bounded`,key:n.set,by:n.by}}if(`persist`in n){let e=Wa.get(n.persist)??n.persist;if(`to`in n)return{kind:`persist-literal`,key:n.persist,value:n.to,stateVar:e};if(`from`in n){let t=J_(n.from,i);return{kind:`persist-option`,key:n.persist,stateVar:e,options:[...t.members],paletteOf:t.paletteOf,library:t.library}}if(`cycle`in n)return{kind:`persist-cycle`,key:n.persist,stateVar:e,members:n.cycle};if(`removeSegment`in n)return{kind:`layout-op`,key:n.persist,op:{op:`remove`,target:n.removeSegment}};if(`insertSegment`in n)return{kind:`layout-op`,key:n.persist,op:{op:`insert`,segment:n.insertSegment,anchor:n.anchor,relation:n.relation}};if(`insertSegmentFrom`in n){let e=J_(n.insertSegmentFrom,i);return{kind:`layout-op-option`,key:n.persist,anchor:n.anchor,relation:n.relation,options:[...e.members],paletteOf:e.paletteOf,library:e.library}}return{kind:`persist-bounded`,key:n.persist,by:n.by}}if(`copy`in n)return{kind:`copy`,text:LH(e,n.copy,t)};if(`open`in n)return{kind:`open`,target:LH(e,n.open,t)};if(`reset`in n)return{kind:`reset`,key:n.reset};if(`doctor`in n)switch(n.doctor){case`run`:return{kind:`doctor-run`};case`fix`:return{kind:`doctor-fix`,check:n.check};case`mark`:return{kind:`doctor-mark`,check:n.check,mark:n.mark}}if(`ceiling`in n)return{kind:`ceiling`,args:eI(n)};if(`slash`in n)return{kind:`slash`,line:n.slash};if(`undo`in n)return{kind:`undo`};if(`redo`in n)return{kind:`redo`};if(`back`in n)return{kind:`back`};if(`rewind`in n)return{kind:`rewind`};if(`save`in n)return{kind:`save`};if(`preset`in n)return n.preset===`save`?{kind:`preset-save`}:{kind:`preset-delete`,name:LH(e,n.name,t)};if(`themeDefault`in n)return{kind:`theme-default-save`};let[o,...s]=n.do.map(e=>{let n=a.get(e);if(n===void 0)throw Error(`action "${t}" fires "${e}", which is not declared in this config`);return n});return{kind:`do`,head:o,rest:s}}function FH(e){return e.kind===`do`?FH(e.head):e}function IH(e){switch(FH(e).kind){case`set-option`:case`set-int`:case`persist-option`:case`layout-op-option`:return!0;case`set-literal`:case`set-bounded`:case`set-cycle`:case`copy`:case`open`:case`persist-literal`:case`persist-bounded`:case`persist-cycle`:case`reset`:case`layout-op`:case`undo`:case`redo`:case`back`:case`rewind`:case`save`:case`preset-save`:case`preset-delete`:case`theme-default-save`:case`doctor-run`:case`doctor-fix`:case`doctor-mark`:case`ceiling`:case`slash`:case`do`:return!1}}function LH(e,t,n){try{return e(t)}catch(e){throw Error(`Template parse error in actions.${n}: ${e.message}`,{cause:e})}}function RH(e,t){return e.has(t)?Ev(e.read(t)):``}function zH(e,t){return e.evaluate(t).map(e=>e.plain).join(``)}function BH(e,t,n,r){let i=new K(e,{style:U.combine([r,new U({link:t,bold:n})])});return i.overflow=`ignore`,i.end=``,i}function VH(e,t,n=!1){let r=new U({link:t,bold:n?!0:void 0}),i=new K(e.plain,{style:U.combine([Ip(e.style),r])});for(let t of e.spans)i.stylize(U.combine([Ip(t.style),r]),t.start,t.end);return i.overflow=`ignore`,i.end=``,i}function HH(e,t){return Math.max(e.members.indexOf(RH(t,e.stateVar)),0)}function UH(e,t,n,r,i){switch(e.kind){case`set-literal`:{let t=RH(r,e.stateVar);return{effects:[{verb:jn,args:[i,e.key,e.value]}],active:t===e.value}}case`set-option`:{let a=n??t,o=RH(r,e.stateVar);return{effects:[{verb:jn,args:[i,e.key,a]}],active:o===a}}case`set-int`:{let a=n??t,o=RH(r,e.stateVar);return{effects:[{verb:jn,args:[i,e.key,a]}],active:o===a}}case`set-cycle`:{let t=e.members[(HH(e,r)+1)%e.members.length];return{effects:[{verb:jn,args:[i,e.key,t]}],active:!1}}case`set-bounded`:return{effects:[{verb:Mn,args:[i,e.key,String(e.by)]}],active:!1};case`copy`:return{effects:[{verb:Nn,args:[zH(e.text,bT(r))]}],active:!1};case`open`:return{effects:[{verb:Pn,args:[zH(e.target,bT(r))]}],active:!1};case`persist-literal`:{let t=RH(r,e.stateVar);return{effects:[{verb:Rn,args:[i,e.key,e.value]}],active:t===e.value}}case`persist-option`:{let a=n??t,o=RH(r,e.stateVar);return{effects:[{verb:Rn,args:[i,e.key,a]}],active:o===a}}case`persist-cycle`:{let t=e.members[(HH(e,r)+1)%e.members.length];return{effects:[{verb:Rn,args:[i,e.key,t]}],active:!1}}case`persist-bounded`:return{effects:[{verb:zn,args:[i,e.key,String(e.by)]}],active:!1};case`reset`:return{effects:[{verb:Wn,args:[i,e.key]}],active:!1};case`undo`:return{effects:[{verb:Kn,args:[i]}],active:!1};case`redo`:return{effects:[{verb:qn,args:[i]}],active:!1};case`back`:return{effects:[{verb:Jn,args:[i]}],active:!1};case`rewind`:return{effects:[{verb:Yn,args:[i]}],active:!1};case`save`:return{effects:[{verb:Bn,args:[i]}],active:!1};case`preset-save`:return{effects:[{verb:Vn,args:[i]}],active:!1};case`theme-default-save`:return{effects:[{verb:Hn,args:[i]}],active:!1};case`preset-delete`:return{effects:[{verb:Un,args:[i,zH(e.name,bT(r))]}],active:!1};case`doctor-run`:return{effects:[{verb:Zn,args:[i]}],active:!1};case`doctor-fix`:return{effects:[{verb:Qn,args:[i,e.check]}],active:!1};case`doctor-mark`:return{effects:[{verb:$n,args:[i,e.check,e.mark]}],active:!1};case`ceiling`:return{effects:[{verb:tr,args:[i,...e.args]}],active:!1};case`slash`:return{effects:[{verb:nr,args:[i,e.line]}],active:!1};case`layout-op`:return{effects:[{verb:Gn,args:[i,e.key,LN(e.op)]}],active:!1};case`do`:{let a=UH(e.head,t,n,r,i);return{effects:[...a.effects,...e.rest.flatMap(e=>UH(e,t,void 0,r,i).effects)],active:a.active}}case`layout-op-option`:{let r={op:`insert`,segment:n??t,anchor:e.anchor,relation:e.relation};return{effects:[{verb:Gn,args:[i,e.key,LN(r)]}],active:!1}}}}function WH(e,t,n,r){if(n.length===0)throw Error(`action "${e}" needs a display (the clickable text)`);if(t.kind===`set-cycle`||t.kind===`persist-cycle`)return{display:pr(`action "${e}"`,n,t.members.length,HH(t,r)),boundValue:void 0};if(n.length>2)throw Error(`action "${e}" takes a display and an optional bound value, got ${n.length} arguments (per-state displays are a cycle action's form)`);return{display:n[0],boundValue:n[1]?.plain}}function GH(e,t,n){let r=n.compiled.get(e);if(!r)throw Error(`action "${e}" is not declared in this config`);let i=n.store,{display:a,boundValue:o}=WH(e,FH(r),t,i),s=RH(i,`session.id`),{effects:c,active:l}=UH(r,a.plain,o,i,s);return VH(a,I(c),l)}function KH(e){return{action:{fn:(t,...n)=>GH(t,n,e),argTypes:[`string`,`liftable`],arity:{kind:`variadic`},returnType:`T`}}}function qH(e,t){return BH(`✕`,I([{verb:jn,args:[RH(e,`session.id`),t,ur]}]),!1)}function JH(e,t,n){return new U({bgcolor:H.fromRgba(t),color:H.fromRgba(xm(e,t,n))})}function YH({tint:e,text:t}){return new U({bgcolor:H.fromRgba(e),color:H.fromRgba(t)})}function XH(e,t,n){return new U({color:H.fromRgba(Qs(dm(e,`warning`),t,bm,n))})}function ZH(e,t,n){return U.combine([JH(e,t,n),XH(e,t,n)])}function QH(e,t,n){return JH(e.palette,Hm(e.palette,e.disclosure,[t],n),n)}function $H(e){let t=H.fromRgba(dm(e,`background`)),n=K.fromFragments(Rp.map(n=>new K(`▀`,{style:new U({color:H.fromRgba(dm(e,n)),bgcolor:t})})));return n.overflow=`ignore`,n.end=``,n}const eU=(e,t)=>{let n=typeof e==`string`?new K(e,{style:t}):e;return n.overflow=`ignore`,n.end=``,n},tU=e=>new U({bold:e});function nU(e,t,n,r,i,a){if(r===void 0)return(n,r,a,o)=>eU(a,U.combine([QH(e,{...n,distribution:t},i),tU(o)]));let o=JH(e.palette,a,i);return(e,t,i,a)=>rU(i,U.combine([o,tU(a)]),r(t,n))}const rU=(e,t,n)=>eU(K.fromFragments([eU(e,t),eU(` `,t),$H(n)]));function iU(e,t){return t===void 0?(e,t,n)=>eU(n):(n,r,i)=>rU(i,void 0,t(r,e))}function aU(e,t,n,r,i){let a=JH(e.palette,i,r);return(e,r,i,o)=>eU(K.fromFragments([eU(o?`[`:` `,a),$H(n(r,t)),eU(o?`]`:` `,a)]))}function oU(e,t,n){let r=t.map(t=>({label:t.label,indices:e.flatMap((e,n)=>e.group===t.id?[n]:[])})).filter(e=>e.indices.length>0);if(r.reduce((e,t)=>e+t.indices.length,0)!==e.length){let n=new Set(t.map(e=>e.id)),r=e.flatMap((e,t)=>n.has(e.group)?[]:[`#${t} (group "${e.group}")`]);throw Error(`library: ${r.join(`, `)} name a group the domain does not list (${[...n].join(`, `)})`)}return n?r.flatMap(e=>sU(e.indices,8).map(t=>[{label:e.label,indices:t}])):[r]}function sU(e,t){return Array.from({length:Math.ceil(e.length/t)},(n,r)=>e.slice(r*t,(r+1)*t))}function cU(e,t){return new K(e).truncate(t,{marker:`…`}).plain}function lU(e){return{current:null,drawnAt:e}}function uU(e,t,n,r,i,a,o){let s={segName:t,placementId:n,palette:r,disclosure:i,tint:a,text:o,bg:void 0,drops:[]};return e.current=s,s}function dU(e,t){let n=e.current;if(n===null)throw Error(`${t} is only available inside a segment's templates — there is no active segment here. Segment-scoped functions cannot be used in variable declarations or layout-node "when" predicates, which are evaluated outside any segment.`);return n}function fU(e){return new K(e).cellLength}function pU(e){return Math.max(1,e.width-e.chromeCols-2*e.padding)}function mU(e){return Math.max(1,pU(e)-(fU(`✕`)+2*e.padding+e.seamCols))}function hU(e,t,n){if(!Number.isFinite(t))return e.length>0?[e.map((e,t)=>t)]:[];let r=Math.max(1,t-n),i=[],a=[],o=0;for(let t=0;t<e.length;t++){let n=e[t];a.length===0?(a=[t],o=n):o+1+n<=r?(a.push(t),o+=1+n):(i.push(a),a=[t],o=n)}return a.length>0&&i.push(a),i}function gU(e,t,n){let r=fU(`←`)+1+fU(`→`)+1,i=hU(e,t,n);return(i.length>1?hU(e,t,n+r):i).map(e=>[{label:``,indices:e}])}function _U(e,t){let n=[];for(let t of e)n.length>0&&n.push(new K(` `)),n.push(t);let r=K.fromFragments(n);return r.overflow=t?`ignore`:void 0,r.end=``,r}function vU(e,t,n,r,i){let a=e.compiled.get(t);if(!a||a.kind!==n)throw Error(`${i} references action "${t}" which must be ${r}, got ${a?`a ${a.kind} action`:`no such action`}`);return a}function yU(e,t,n){let r=e.compiled.get(t),i=r&&FH(r);if(!i||i.kind!==`set-option`&&i.kind!==`persist-option`&&i.kind!==`layout-op-option`)throw Error(`${n} references action "${t}" which must be a set-option, persist-option, or layout-op-option action ({ set, from }, { persist, from }, or { persist, insertSegmentFrom, anchor, relation }), got ${i?`a ${i.kind} action`:`no such action`}`);return i}function bU(e,t,n,r,i,a,o,s,c=[]){let l=a.compiled.get(e),u=a.store,d=RH(u,`session.id`),f=`stateVar`in t?RH(u,t.stateVar):void 0,p=(e,n)=>{let r=t.options[e];return o({index:e,count:t.options.length},r,n,r===f)},m=i?r.kind===`led`?mU(a):pU(a):1/0,h=(r.kind===`led`?0:fU(`✕`)+1)+c.reduce((e,t)=>e+fU(t.glyph)+1,0),g=t.library&&{groups:t.library.groups,entries:t.options.map(t.library.entry)},_=g===void 0?t.options.map((e,t)=>p(t,e)):[],v=g===void 0?gU(_.map(e=>e.cellLength),m,h):oU(g.entries,g.groups,i),y=parseInt(RH(u,n.stateVar),10),b=e=>Math.max(0,v.findIndex(t=>t.some(t=>t.indices.includes(e)))),x=b(f===void 0?-1:t.options.indexOf(f)),S=Number.isInteger(y)?y<0?x:Math.min(y,v.length-1):0,C=v[S]??[],w=e=>I([{verb:jn,args:[d,n.key,String(e)]}]),ee=r.kind===`led`?[]:[{verb:jn,args:[d,...r.writes.flatMap(([e,t])=>[e,t])]}],te=r.kind===`own`&&r.onPick?ee:[],ne=e=>I([...UH(l,e,e,u,d).effects,...te]),T=(e,n)=>VH(e,ne(t.options[n])),re=r.kind===`led`?[]:[BH(`✕`,I(ee),!1,s)];re.push(...c.map(({glyph:e,option:r})=>BH(e,I([...UH(l,r,r,u,d).effects,{verb:jn,args:[d,n.key,String(b(t.options.indexOf(r)))]}]),!1))),S>0&&re.push(BH(`←`,w(S-1),!1));let E=S<v.length-1?[BH(`→`,w(S+1),!1)]:[];if(g===void 0){let e=C.flatMap(e=>e.indices);return[_U([...re,...e.map(e=>T(_[e],e)),...E],i)]}let D=new U({bold:!0}),ie=v.length>1?` ${S+1}/${v.length}`:``,O=C.length===1?[new K(`${C[0].label}${ie}`,{style:D})]:[],ae=[_U([...re,...O,...E],i)];for(let e of C){C.length>1&&ae.push(_U([new K(e.label,{style:D})],i));let n=Math.max(...e.indices.map(e=>fU(t.options[e])));for(let r of e.indices){let e=t.options[r],a=g.entries[r].description,o=a===void 0?void 0:Dp(a),s=` `.repeat(n-fU(e)+2),c=o===void 0?e:`${e}${s}${o}`;ae.push(_U([T(p(r,cU(c,m)),r)],i))}}return ae}function xU(e,t){return{picker:{fn:(n,r,i,a,o,...s)=>{mT(`picker "${n}"`,[`closeOnPick`,`paged`,`inBody`],s);let c=vU(e,r,`set-int`,`an int action ({ set, int: true })`,`picker`);if(o===!0&&i===!0)throw Error(`{{ picker "${n}" … }} sets both closeOnPick and inBody; a picker in a body is closed by the body's ✕, so it has no close to fold into a pick`);let l=yU(e,n,`picker`);if(l.library!==void 0)throw Error(`{{ picker "${n}" … }} ranges a catalogue domain, which lays out as one row per member; a catalogue renders in a {{ menu }} body`);let u=dU(t,`{{ picker }}`);if(u.bg===void 0)throw Error(`{{ picker }} is not available while segments.${u.segName}'s own "bg:" is being evaluated — a picker is drawn on that background`);let[d]=bU(n,l,{key:c.key,stateVar:c.stateVar},o===!0?{kind:`led`}:{kind:`own`,writes:[[c.key,`-1`]],onPick:i===!0},a===!0,e,nU(u,$p(void 0),MH(e,`{{ picker }}`),l.paletteOf,t.drawnAt(),u.bg),XH(u.palette,u.bg,t.drawnAt()));return d},argTypes:[`string`,`string`,`bool`],arity:{kind:`variadic`},returnType:`T`}}}function SU(e,t){let n=e.length,r=Math.max(e.indexOf(t),0);return e=>((r+e)%n+n)%n}function CU(e,t,n,r,i){let a=Math.min(Math.floor((t-1)/2),i),o=n,s=0;for(;s<a;){let t=o+e(-(s+1))+1+e(s+1)+1;if(t>r)break;o=t,s+=1}return s}function wU(e,t,n,r,i,a){if(!(`stateVar`in t))throw Error(`carousel references action "${e}", which inserts a segment and holds no current value to centre on — a carousel needs a { set, from } or { persist, from } action`);let o=n.store;if(!o.has(t.stateVar))throw Error(`carousel references action "${e}", whose key "${t.stateVar}" no variable reads back, so there is no current value to centre on — declare { kind: "state", key: "${t.stateVar}" } among the variables`);let s=n.compiled.get(e),c=RH(o,`session.id`),{options:l}=t,u=l.length;if(u===0)return _U([],!0);let d=RH(o,t.stateVar),f=SU(l,d),p=e=>l[f(e)],m=new Map,h=e=>{let t=m.get(e);if(t!==void 0)return t;let n=I(UH(s,p(e),p(e),o,c).effects);return m.set(e,n),n},g=e=>r({index:f(e),count:u},p(e),p(e),p(e)===d),_=new Map,v=e=>{let t=_.get(e);if(t!==void 0)return t;let n=VH(g(e),h(e));return _.set(e,n),n},y=a===void 0?v(0):VH(iU(MH(n,`{{ carousel }}`),t.paletteOf)({index:f(0),count:u},p(0),p(0),!1),I(UH(n.compiled.get(a),p(0),void 0,o,c).effects)),b=CU(e=>v(e).cellLength,u,fU(`◀`)+1+y.cellLength+1+fU(`▶`),mU(n),i),x=e=>Array.from({length:b},(t,n)=>v(e*(n+1)));return _U([...x(-1).reverse(),BH(`◀`,h(-1),!1),y,BH(`▶`,h(1),!1),...x(1)],!0)}function TU(e,t){return{carousel:{fn:(n,...r)=>{let[i,a,...o]=r;if(mT(`carousel "${n}"`,[`neighbours`,`centre`],o),i!==void 0&&!(Number.isInteger(i)&&i>=0))throw Error(`carousel "${n}": neighbours must be a whole number ≥ 0 (0 shows only ◀ CURRENT ▶), got ${String(i)}`);if(a!==void 0&&!(typeof a==`string`&&e.compiled.has(a)))throw Error(`carousel "${n}": centre must name a declared action, got ${JSON.stringify(a)}`);if(a!==void 0&&IH(e.compiled.get(a)))throw Error(`carousel "${n}": centre "${a}" writes a value the template binds, and the centre binds none — name an action that writes a fixed value, a cycle, or a do of them`);let s=i??1/0,c=yU(e,n,`carousel`),l=dU(t,`{{ carousel }}`);if(l.bg===void 0)throw Error(`{{ carousel }} is not available while segments.${l.segName}'s own "bg:" is being evaluated — a carousel is drawn on that background`);return wU(n,c,e,nU(l,$p(void 0),MH(e,`{{ carousel }}`),c.paletteOf,t.drawnAt(),l.bg),s,a)},argTypes:[`string`,`value`],arity:{kind:`variadic`},returnType:`T`}}}function EU(e,t,n){let r=yU(e,t,n);if(!(`stateVar`in r))throw Error(`${n} references action "${t}", which inserts a segment and holds no current value — a ${n} needs a { set, from } or { persist, from } action`);if(r.paletteOf===void 0)throw Error(`${n} references action "${t}", whose options are not colour-valued — a swatch draws the palette an option puts in force, as the "themes", "placementThemes" and "styles" domains do`);return r}function DU(e,t,n){let r=Math.imul(e^e>>>16,73244475);return r=Math.imul(r^r>>>16,73244475),r^=r>>>16,(n+1+(r>>>0)%Math.max(t-1,1))%t}function OU(e,t,n,r){let i=EU(e,t,n),a=r??RH(e.store,i.stateVar);if(!i.options.includes(a))throw Error(`${n} "${t}": "${a}" is not one of its options, so it has no palette to draw`);return i.paletteOf(a,MH(e,`{{ ${n} }}`))}function kU(e,t,n){return{swatch:{fn:(t,...n)=>{let[r,...i]=n;if(mT(`swatch "${t}"`,[`option`],i),r!==void 0&&typeof r!=`string`)throw Error(`swatch "${t}": option must be text, got ${JSON.stringify(r)}`);return $H(OU(e,t,`swatch`,r))},argTypes:[`string`,`value`],arity:{kind:`variadic`},returnType:`T`},swatches:{fn:(r,i)=>{let a=EU(e,r,`swatches`),o=vU(e,i,`set-int`,`an int action ({ set, int: true })`,`swatches`),s=dU(t,`{{ swatches }}`);if(s.bg===void 0)throw Error(`{{ swatches }} is not available while segments.${s.segName}'s own "bg:" is being evaluated — a swatch row is drawn on that background`);let c=t.drawnAt(),{options:l}=a,u=l.length,[d]=bU(r,a,{key:o.key,stateVar:o.stateVar},{kind:`led`},!0,e,aU(s,MH(e,`{{ swatches }}`),a.paletteOf,c,s.bg),XH(s.palette,s.bg,c),u===0?[]:(()=>{let t=SU(l,RH(e.store,a.stateVar));return[{glyph:`◀`,option:l[t(-1)]},{glyph:`?`,option:l[DU(n().getTime(),u,t(0))]},{glyph:`▶`,option:l[t(1)]}]})());return d},argTypes:[`string`,`string`],arity:{kind:`exact`},returnType:`T`}}}const AU=[`~/code`,`main`,`opus`,`42%`,`5m`,`$1.20`];function jU(e,t,n,r){let i=Nm(e,n,r),a=(t,n)=>({text:t,colour:n,ink:xm(e,n,r)});return[[Jp(t).map((n,i)=>{let a=fm(e,n);return{text:AU[i%AU.length],colour:a,ink:t.shade.text(e,n.hue,a,r)}})],[[a(`▾ open`,i.state),a(`menu`,i.plane)],[a(`warn`,dm(e,`warning`)),a(`error`,dm(e,`error`))]]]}function MU(e,t){let n=e.flatMap((e,t)=>e.map(({text:e,colour:n,ink:r},i)=>({gap:t>0&&i===0?` `:``,cell:new K(` ${e} `,{style:YH({tint:n,text:r})})}))),r=[],i=0;for(let{gap:e,cell:a}of n){if(i+=e.length+a.cellLength,i>t)break;e!==``&&r.push(new K(e)),r.push(a)}return r}function NU(e,t,n,r,i){let a=jU(e,t,n,r).map(e=>MU(e,i)),o=K.fromFragments(a.flatMap((e,t)=>t===0?e:[new K(`
|
|
194
|
+
`),...e]));return o.overflow=`ignore`,o.end=``,o}function PU(e,t){return{themePreview:{fn:(...n)=>{let[r,...i]=n;if(mT(`themePreview`,[`applyAction`],i),r!==void 0&&typeof r!=`string`)throw Error(`themePreview: applyAction must name a declared action, got ${JSON.stringify(r)}`);let{palette:a,decor:o}=MH(e,`{{ themePreview }}`);return NU(r===void 0?a:OU(e,r,`themePreview`),o,{...dU(t,`{{ themePreview }}`).disclosure,depth:0},t.drawnAt(),mU(e))},argTypes:[`value`],arity:{kind:`variadic`},returnType:`T`}}}const FU=e=>e.slice(e.lastIndexOf(`.`)+1),IU=(e,t)=>{let n=new K(FU(e));return n.truncate(t,{marker:`…`}),n.plain};function LU(e,t){let n=e.map(e=>e.map(({name:e})=>fU(FU(e)))),r=e=>n.every(n=>n.reduce((t,n)=>t+Math.min(n,e)+2,0)<=t),i=Math.max(1,...n.flat());for(;i>1&&!r(i);)--i;return i}function RU(e,t,n,r){let i=LU(e,r),a=e.map(e=>{let a=[],o=0;for(let{name:s,address:c,palette:l}of e){let e=new K(` ${IU(s,i)} `,{style:YH(Km(l,{kind:`bar`,decor:t,address:c},n))});if(o+=e.cellLength,o>r)break;a.push(e)}return a}),o=K.fromFragments(a.flatMap((e,t)=>t===0?e:[new K(`
|
|
195
|
+
`),...e]));return o.overflow=`ignore`,o.end=``,o}function zU(e,t){return{layoutPreview:{fn:()=>RU(e.layout(),MH(e,`{{ layoutPreview }}`).decor,t.drawnAt(),mU(e)),argTypes:[],arity:{kind:`exact`},returnType:`T`}}}function BU(e,t,n,r){let i=dU(r.activeSegment,`{{ menu }}`),a=r.action,o=cD(i.placementId,e,n.key),s=dD(o),c=sD(e),l=RH(a.store,o)===c,u=RH(a.store,`session.id`),d=l?ur:c,f=BH(pr(`{{ menu "${e}" }}`,t,2,+!!l),I([{verb:jn,args:[u,o,d,s,`0`]}]),!1);return i.drops.push(...l?(()=>{let t=r.activeSegment.drawnAt(),c=Nm(i.palette,i.disclosure,t).plane,l=yU(a,e,`menu`);return bU(e,l,{key:s,stateVar:s},{kind:`own`,writes:[[o,ur],[s,`0`]],onPick:n.closeOnPick},n.paged,a,nU(i,n.distribution,MH(a,`{{ menu }}`),l.paletteOf,t,c),XH(i.palette,c,t))})():[]),f}const VU=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function HU(e,t){let n=t[t.length-1],r=VU(n)?n:void 0,i=r===void 0?t:t.slice(0,-1),a=i.findIndex(e=>typeof e!=`string`);if(a!==-1)throw Error(`{{ menu "${e}" }} display #${a+1} is not text (${JSON.stringify(i[a])}) — a menu binds its trigger text, then an optional trailing (dict …) of options`);return{displays:i,options:hD(r??{})}}function UU(e){return{menu:{fn:(t,...n)=>{let{displays:r,options:i}=HU(t,n);return BU(t,r,i,e)},argTypes:[`string`,`value`],arity:{kind:`variadic`},returnType:`T`}}}function WU(e){let{value:t,max:n,width:r,filled:i,empty:a,colourAt:o}=e,s=GU(t,n,r),c=[];for(let e=0;e<r;e++){let t=e<s,l=t&&o!==void 0?o(e*n/r):void 0;c.push(new K(t?i:a,{style:l===void 0?void 0:new U({color:l})}))}let l=K.fromFragments(c);return l.end=``,l.overflow=`ignore`,l}function GU(e,t,n){return!Number.isFinite(e)||!Number.isFinite(t)||t<=0?0:Math.min(n,Math.max(0,Math.round(e/t*n)))}function KU(e){let t={fn:(()=>{let t=dU(e,`{{ bgOf }}`);if(t.bg===void 0)throw Error(`{{ bgOf }} is not available while segments.${t.segName}'s own "bg:" is being evaluated — the background is what that template computes. Reach for a palette color there instead, e.g. bg: '{{ darken (color "surface") 1 }}'.`);return t.bg.hex}),argTypes:[],arity:{kind:`exact`},returnType:`string`},n={fn:(()=>dU(e,`{{ tint }}`).tint.hex),argTypes:[],arity:{kind:`exact`},returnType:`string`},r={fn:((t,n)=>{let{palette:r}=dU(e,`{{ keptOn }}`),i=Us(r,t),a=Us(r,n),o=No(ec(i,V.TRUECOLOR),ec(a,V.TRUECOLOR)),s=Math.min(bm,Math.max(o,3));return($s(i,e.drawnAt(),(e,t)=>No(e,t(a))>=s)??i).hex}),argTypes:[`string`,`string`],arity:{kind:`exact`},returnType:`string`},i=Qw(()=>dU(e,`{{ color }} / {{ ramp }} / {{ gauge }}`).palette),a={fn:((e,t,n,r,a,o,...s)=>{let c=o===void 0?void 0:[o,...qU(s)];return WU({value:e,max:t,width:n,filled:r,empty:a,colourAt:c===void 0?void 0:e=>String(i.ramp.fn(e,...c))})}),argTypes:[`float`,`float`,`int`,`string`,`string`,`string`],arity:{kind:`variadic`},returnType:`T`};return{...i,bgOf:t,tint:n,keptOn:r,gauge:a}}function qU(e){return e.flatMap(e=>{let t=e.indexOf(`:`),n=t<0?NaN:Number(e.slice(0,t));if(!Number.isFinite(n))throw Error(`{{ gauge }} stop "${e}" must be "<position>:<colour>", e.g. "80:error" or "80:#ff0000"`);return[n,e.slice(t+1)]})}function JU(e){let t=[],n=[];for(let r of e){if(!r.contains(`
|
|
196
196
|
`)){n.push(r);continue}let e=r.split(`
|
|
197
|
-
`);n.push(e[0]);for(let r=1;r<e.length;r++)t.push(n),n=[e[r]]}return t.push(n),t}function WU(e){let t=new Map;return e.map(e=>{let n=`${e.place}.${e.band}`,r=t.get(n)??0;return t.set(n,r+1),{line:e,row:`${n}#${r}`}})}function GU(e,t){let n=[],r=[],i;for(let a of t)(a.band===`own`?n:r).push(a),i??=a.cells.find(t=>t.placement.id===e)?.placement.ground;return{drawing:i===void 0?null:{own:r.length===0?n:[],ground:i},deeper:r}}function KU(e){return{...e,cells:e.cells.map(_H)}}function qU(e,t){let n=t.flatMap(e=>e.filter(e=>e.place===`above`)),r=t.map(e=>e.filter(e=>e.place===`flow`));return[...n,...JU(e,r)]}function JU(e,t){switch(e){case`vertical`:return t.flatMap(e=>e);case`horizontal`:return t.reduce((e,t)=>Math.max(e,t.length),0)===0?[]:[{cells:t.flatMap(e=>e[0]?.cells??[]),band:`own`,place:`flow`},...t.flatMap(e=>e.slice(1))]}}function YU(e,t){let n=(e,r)=>t(e)?e.kind===`segment`?[{cells:[{name:e.name,address:r,settings:e.settings}],band:`own`,place:`flow`}]:qU(e.direction,e.children.map((t,i)=>n(t,[...r,XU(e,i)]))):[];return n(e,[]).map(e=>[...e.cells])}function XU(e,t){return{index:t,count:e.children.length,distribution:e.distribution,axis:Yg[e.direction]}}const ZU={compile(e,t){return{kind:`container`,direction:e.direction,when:t.when,distribution:em(e.distribution),children:e.children.map((e,n)=>t.compileChild(e,t_(t.path,n)))}},render(e,t){return t.gate.kind===`failed`&&t.gate.report(),qU(e.direction,e.children.map((n,r)=>t.renderChild(n,t.gate.kind===`shown`,XU(e,r))))}},QU={drop:e=>e.place,above:()=>`above`},$U={drop:(e,t)=>({lead:t(),stays:e}),above:e=>({lead:e.slice(0,1).flatMap(e=>e.cells),stays:e.slice(1)})},eW={compile(e,t){return{kind:`segment`,when:t.when,name:e.name,id:Xg(e),settings:t.placementSettings(e),...e.opens!==void 0&&{opens:{open:t.parse(gr(e.opens.ref),`opens`),body:t.compileChild(e.opens.body,n_(t.path)),key:e.opens.ref.key,placement:e.opens.placement}},...e.lead!==void 0&&{lead:t.parse(e.lead,`lead`)},...e.trail!==void 0&&{trail:t.parse(e.trail,`trail`)}}},render:(e,t)=>t.placed(e.id,tW(e,t))};function tW(e,t){let n=t.lookupSegment(e.name);if(!n)throw Error(`Layout segment "${e.name}" has no matching segment`);let{seg:r,compiled:i}=n;if(t.gate.kind===`hidden`)return[];let a=CT(t.scope,e.settings);if(t.gate.kind===`failed`)return nW(e,a,t,t.gate.message);try{if(!uH(i.when,a))return[];let n=Bg(e.settings.theme,t.palette),o={id:e.id,effect:e.settings.effect,ground:gk(n)},s=e.opens!==void 0&&uH(e.opens.open,t.scope),{styles:c,fragments:l,lead:u,trail:d,drops:f,open:p}=t.evaluateSegment(e,a,n,t.region,{bg:i.bg,fg:i.fg,body:i.template,lead:e.lead,trail:e.trail},s),m=p?c.trigger:c.closed,h={width:r.width??`auto`,justify:r.justify??`left`,truncate:r.truncate??`right`,baseStyle:m,padding:t.padding,placement:o},g=e.opens,_=g===void 0?[]:t.renderBody(g.body,s,c.disclosure).map(e=>({...e,place:QU[g.placement](e)})),v=UU(wH(l,m)).map((e,t)=>({cells:bH(e,{...h,lead:t===0?wH(u,m):[],trail:t===0?wH(d,m):[]}),band:`own`,place:`flow`})),y=f.map(e=>({cells:bH(wH([e],c.band),{...h,baseStyle:c.band}),band:`deeper`,place:`flow`})),b=(e,t,n)=>bH(wH([e],t),{...h,width:`auto`,baseStyle:t,padding:n}),x=_.findIndex(e=>e.band===`own`),{lead:S,stays:C}=g!==void 0&&x!==-1?$U[g.placement](v,()=>b(t.closeDisclosure(g.key),c.close,t.padding)):{lead:[],stays:v},w=S.flatMap(e=>b(new K(` `.repeat(gH(e).reduce((e,t)=>e+t.cellLength,0))),c.trigger,0)),ee=(e,t)=>e.band===`own`?t===x?S:w:[],te=_.map((e,t)=>({cells:[...ee(e,t),...e.cells],band:`deeper`,place:e.place})),ne=[...C,...y];return t.perSegmentSink!==void 0&&t.perSegmentSink.set(e.id,[...ne.flatMap(e=>e.cells),..._.flatMap(ee)].flatMap(gH)),[...ne,...te]}catch(n){return nW(e,a,t,n.message??String(n))}}function nW(e,t,n,r){n.onSegmentError?.(e.id,r);let i=r.replace(/\s*\n\s*/g,` `);return[{cells:bH([new K(`⚠ ${e.id}: ${i}`,{end:``})],{width:`auto`,justify:`left`,truncate:`right`,padding:0,placement:{id:e.id,effect:`bar`,ground:gk(n.palette)},lead:rW(e.lead,e,t,n),trail:rW(e.trail,e,t,n)}),band:`own`,place:`flow`}]}function rW(e,t,n,r){if(e===void 0)return[];try{return r.evaluateSegment(t,n,r.palette,r.region,{bg:void 0,fg:void 0,body:e,lead:void 0,trail:void 0},!1).fragments}catch(e){return r.onSegmentError?.(t.id,e.message??String(e)),[]}}const iW={container:ZU,segment:eW};function aW(e){return iW[e]}function oW(e){if(`ttl`in e)return{kind:`ttl`,durationMs:CE(e.ttl)};if(`watch_file`in e)return{kind:`watch_file`,path:e.watch_file};if(`depends_on`in e)return{kind:`depends_on`,varNames:e.depends_on};if(`key`in e)return{kind:`key`,template:e.key};if(`never`in e)return{kind:`never`};throw Error(`Unknown CacheDecl discriminator — loader invariant violated: ${JSON.stringify(e)}`)}function sW(e,t){switch(o_(e)){case`json`:return{kind:`json`,default:t};case`regex`:return{kind:`regex`,regex:new RegExp(e.regex),default:t};case`text`:return{kind:`text`,default:t}}}function cW(e,t,n,r){switch(n.kind){case`literal`:e.declareLiteral(t,n.value);break;case`dropped`:e.declareFailedDocument(t,n.reason);break;case`input`:e.declareInput(t,n.path,n.type??`string`,n.default);break;case`env`:e.declareEnv(t,n.name,n.default);break;case`file`:e.declareFile(t,n.path,{readMode:n.readMode,cache:oW(n.cache),parse:sW(n.parse,n.default)});break;case`shell`:e.declareShell(t,n.command,{cwd:r,cache:oW(n.cache),parse:sW(n.parse,n.default)});break;case`template`:e.declareTemplate(t,n.template,{varDefault:n.default});break;case`time`:e.declareTime(t,{format:n.layout,varDefault:n.default});break;case`git`:e.declareGit(t,{field:n.field,cwd:r,varDefault:n.default});break;case`state`:e.declareState(t,{key:n.key,...n.default!==void 0&&{varDefault:n.default}});break}}function lW(e,t){let n=oy.EMPTY;for(let[r,i]of Object.entries(t))try{n=e.parse(`{{ define "${r}" }}${i}{{ end }}`,n).defines()}catch(e){throw Error(`Template parse error in helpers.${r}: ${e.message}`,{cause:e})}return n}const uW=(e,t,n,r,i)=>{let a=XR(t,YR(n,e.themeDefaults));return{variation:Jp[r??Oh(void 0,null,a.variation)],shade:Kp[i??jh(void 0,null,a.shade)]}};function dW(e,t,n){let r=n.cwd,i={store:t.variableStore,compiled:new Map,chromeCols:sg({endcaps:`powerline`}),width:80,padding:1,seamCols:cg({endcaps:`powerline`}),layout:()=>[],look:void 0},a=iU(t.drawnAt),o={action:i,activeSegment:a},s=Object.keys(e.styles),c=z_(e.presets),l=pN(e),u=bT({extraFuncs:{...VH(i),...gU(i,a),...bU(i,a),...kU(i,a),...wU(i,a,t.now),...PU(i,a),...RU(o),...VU(a),styles:{fn:()=>s,argTypes:[],arity:{kind:`exact`}},presets:{fn:()=>c,argTypes:[],arity:{kind:`exact`}}},clock:t.now,drawnAt:t.drawnAt}),d=lW(u,e.helpers),f=e=>u.parse(e,d),p=new Map,m=e=>{let t=p.get(e);if(t!==void 0)return t;let n=f(e);return p.set(e,n),n},h=new Map;for(let[t,n]of Ga)n in e.variables&&h.set(t,n);for(let[t,n]of f_(e))h.has(n.key)||h.set(n.key,t);i.compiled=OH(f,e.actions,h,l);let g=[];for(let[n,i]of Object.entries(e.variables))try{cW(t,n,i,r)}catch(e){g.push(`Variable "${n}": ${e.message??String(e)}`)}for(let[n,i]of Object.entries(e.segments))if(i.vars)for(let[e,a]of Object.entries(i.vars))try{cW(t,`${n}.${e}`,a,r)}catch(t){g.push(`Variable "${n}.${e}": ${t.message??String(t)}`)}let _=Object.create(null);for(let[t,n]of Object.entries(e.segments)){let e=(e,n,r=f)=>{try{return r(e)}catch(e){throw Error(`Template parse error in segments.${t}.${n}: ${e.message}`,{cause:e})}};_[t]={when:n.when===void 0?void 0:e(n.when,`when`,m),template:e(n.template,`template`),bg:n.bg===void 0?void 0:e(n.bg,`bg`),fg:n.fg===void 0?void 0:e(n.fg,`fg`)}}let v=(e,t,n)=>{try{return m(e)}catch(e){throw Error(`Template parse error in ${t}.${n}: ${e.message}`,{cause:e})}},y=t.variableStore,b=t=>{let n=g_(e.segments[t.name]),r=Object.create(null);for(let[e,i]of Object.entries(n))Object.defineProperty(r,e,{enumerable:!0,get:()=>S_(t,e,i,e=>String(y.read(e.variable)))});return Object.freeze(r)},x=(e,t)=>{let n={path:t,when:e.when===void 0?void 0:v(e.when,t,`when`),parse:(e,n)=>v(e,t,n),compileChild:x,placementSettings:b};return aW(e.kind).compile(e,n)},S=new Map;for(let t of c){let{node:n,path:r}=H_(e,t);S.set(t,x(n,r))}let C=new Map(rh.map(e=>[e,new Map])),w=[[`globals`,e.globals],...Object.entries(e.presets).map(([e,t])=>[`presets.${e}.globals`,t.globals??{}])];for(let[e,t]of w)for(let n of rh){let r=t[n];if(!ih(r))continue;let i=`${e}.${n}`,a=C.get(n),o=a.get(r);a.set(r,o===void 0?{where:i,template:fW(f,i,r)}:{where:`${o.where}, ${i}`,template:o.template})}return{segments:_,roots:S,activeSegment:a,menuRuntime:o,globalExpressions:C,loadWarnings:g}}function fW(e,t,n){try{return e(n)}catch(e){throw Error(`${t} is not a valid template: ${e instanceof Error?e.message:String(e)}`)}}function pW(e,t,n){let r=e.globalExpressions.get(t).get(n);if(r===void 0)throw Error(`the ${t} rule ${JSON.stringify(n)} reached the render but no compiled template exists — registerDslConfig and the resolution disagree about isExpression`);return r}function mW(e,t,n,r){try{return t.template.evaluate(n).map(e=>e.plain).join(``)}catch(n){return r({kind:`rule`,slot:e,message:ph(t.where,e,`the rule failed — ${n instanceof Error?n.message:String(n)}`)}),fh[e]}}function hW(e,t){return e.kind===`decided`?e.name:fh[t]}function gW(e){return e.kind===`container`?e.children.flatMap(gW):[...e.name.startsWith(`edit.`)?[]:[e.id],...e.opens===void 0?[]:gW(e.opens.body)]}function _W(e,t,n,r,i,a,o,s,c){let{perSegmentSink:l,onSegmentError:u,onRenderWarning:d}=s??{},f=e=>d?.(e),p=new Set;r.renderAt(a),r.drawAt(Th(o.colorCompatibility));let{preset:m=L_}=c??{},h=U_(e,m),g=c?.style??lh(`none`,e.styles),_=c?.theme??Kg(void 0,null,h.palette),v=uW(e,h,_,c?.variation,c?.shade),y=c?.effect??vh(void 0,null,h.effect),b=(e,t,n)=>({...i,term:{cols:o.width},theme:{effective:e},style:{effective:t},effect:{effective:n}});r.applyInput(b(hW(_,`palette`),hW(g,`style`),hW(y,`effect`))),t.menuRuntime.action.chromeCols=sg(o),t.menuRuntime.action.padding=o.padding,t.menuRuntime.action.width=o.width,t.menuRuntime.action.seamCols=cg(o);let x=xT(n),S=oh(_,e=>{let n=pW(t,`palette`,e);return Gg(mW(`palette`,n,x,f),n.where,e=>f({kind:`rule`,slot:`palette`,message:e}))}),C=oh(g,n=>lh(mW(`style`,pW(t,`style`,n),x,f),e.styles)),w=oh(y,e=>_h(mW(`effect`,pW(t,`effect`,e),x,f)));(S!==_||C!==g||w!==y)&&r.applyInput(b(S.name,C.name,w.name));let ee=S.value,te=Hg(ee,C.value);t.menuRuntime.action.look={basePalette:ee,palette:te,decor:v};let ne=(c?.effects??new $h(``)).motion(w.value,a,{transitions:c?.transitions??Vh(void 0,null,h.transitions),source:{config:t,preset:m,revision:r.stateRevision(),width:o.width},returned:GU,hold:KU});l?.clear();let T=n=>{let r=e.segments[n],i=t.segments[n];return r!==void 0&&i!==void 0?{seg:r,compiled:i}:void 0},re=(e,n,i,a,o,s)=>{try{let c=r.drawnAt(),{tint:l,text:u,disclosure:d}=qm(i,a,c),f=aU(t.activeSegment,e.name,e.id,i,d,l,u),m=vk(f,c,o.bg,o.fg,n),h=()=>Pm(i,d,c);s&&(f.bg=h().state);let g=o.body.evaluate(n),_=f.drops.length>0||s;if(_){let e=h();f.bg=e.state;for(let t of e.shortfalls)p.add(t)}let v=o.lead?.evaluate(n)??[],y=o.trail?.evaluate(n)??[];return{styles:{closed:m,get trigger(){return UH(i,h().state,c)},get band(){return UH(i,h().plane,c)},get close(){return KH(i,h().state,c)},disclosure:d},fragments:g,lead:v,trail:y,drops:f.drops,open:_}}finally{t.activeSegment.current=null}},E=(e,t,r)=>{let i=t?pH(e.when,x):dH,a=i.kind===`failed`?{...i,report:()=>{let t=`when over ${gW(e).join(`, `)||`no placement`}`;f({kind:`when`,where:t,error:i.message,message:`${t}: ${i.message} — what it gates is hidden`})}}:i,s={scope:x,palette:te,gate:a,padding:o.padding,region:r,perSegmentSink:l,onSegmentError:u,evaluateSegment:re,lookupSegment:T,renderChild:(e,t,n)=>E(e,t,Gm(r,n)),renderBody:(e,t,n)=>E(e,a.kind===`shown`&&t,Km(n)),closeDisclosure:e=>HH(n,e),placed:ne.placed};return aW(e.kind).render(e,s)},D=t.roots.get(m);if(D===void 0)throw Error(`Preset "${m}" has no compiled layout — registerDslConfig compiles one per declared preset and effectivePresetName collapses unknown names to "${L_}"; a miss here is merge/policy drift (have: ${[...t.roots.keys()].join(`, `)})`);let ie=e=>{let n=pH(e.when,x);if(e.kind===`container`)return n.kind===`shown`;if(wN(e.name)===void 0)return!1;if(n.kind!==`shown`)return n.kind===`failed`;try{return uH(t.segments[e.name].when,CT(x,e.settings))}catch{return!0}};t.menuRuntime.action.layout=()=>YU(D,ie).map(e=>e.flatMap(({name:e,address:t,settings:n})=>{let r=wN(e);return r===void 0?[]:[{name:r,address:t,palette:Bg(n.theme,te)}]}));let O=WU(E(D,!0,Wm(v))).map(({line:e,row:t})=>{let n=CH(e.cells,o);return fg(n.map(e=>e.owner),o,ne.row(t,n))}).join(`
|
|
198
|
-
`)
|
|
199
|
-
`)||null}function IW(e,t,n,r,i=()=>{}){let{layers:a,config:o,installed:s}=SR(t.layers,GR,{entered:i,warned:e=>n.push(...e)},{projectDir:t.projectDir,cwd:e});i(a.length===1?a[0].path:null);let c=a.at(-1)?.config??GR,l=a.find(e=>e.path===t.home)?.raw??{},u=new kW,d=new WE(u,o.globals.default_empty_value??``,r.gitService,r.sessionState),f;try{f=dW(o,d,{cwd:e}),n.push(...f.loadWarnings),RB(o),qN(o)}catch(e){throw d.dispose(),e}return{config:o,store:u,registry:d,compiled:f,neededInputPaths:Wz(o),lastRenderCellsBySegment:new Map,authoredRoots:NW(c,l),fileHeldSettings:wB(l),unused:[...new Map(a.flatMap(e=>xW(e.raw,c)).map(e=>[`${e.kind}:${e.name}`,e])).values()],plugins:{checkout:s.checkout,roots:s.roots,loaded:[...s.rendering.values()],dropped:[...s.dropped,...a.flatMap(e=>e.plugins.dropped)],unreached:s.unreached,reached:s.reached,rendering:s.rendering}}}function LW(e,t,n,r){let i=lR(e,t,n),a={layers:i.kind===`chain`?i.layers:[],home:i.home,projectDir:e},o=[mR(e,t),fR(i)],s,c=null;try{s=IW(t,a,o,r,e=>{c=e})}catch(e){return e instanceof XE&&o.push(...e.warnings),{layers:a.layers,home:a.home,failedFile:c,warning:FW(o),state:null,error:e instanceof XE||e instanceof Error?e.message:String(e)}}return{layers:a.layers,home:a.home,warning:FW(o),state:s,error:null}}function RW(e,t,n){return IW(e,{layers:[],home:``,projectDir:t},[],n)}var zW=class{entries=new Map;holds=new Map;deps;log;maxEntries;observers;constructor(e,t={}){this.deps=e,this.log=e.log??Gt,this.maxEntries=t.maxEntries??256,this.observers=t.observers??{}}getOrCreate(e,t,n){let r=MW(e,t,n),i=this.entries.get(r);if(i)return this.entries.delete(r),this.entries.set(r,i),i;let a=LW(e,t,n,this.deps);a.state!==null&&this.log(`info`,AW(a.layers,a.state));let o={projectDir:e,cwd:t,configFile:n,configLayers:[],configHome:``,failedFile:null,lastError:a.error,lastWarning:a.warning,state:a.state??RW(t,e,this.deps),watcher:null,watcherKey:null};if(this.serve(o.state),this.entries.set(r,o),this.entries.size>this.maxEntries){let e=this.entries.entries().next().value;if(e!==void 0){let[t,n]=e;n.watcher?.release(),this.entries.delete(t),this.retire(n.state,`evict`)}}return this.refreshWatcher(o,a),this.observers.onReload?.(o),o}hold(e,t,n){let r=this.getOrCreate(e,t,n),{state:i}=r,a=this.holdOf(i);a.holders++;let o=!1;return{entry:r,state:i,[Symbol.dispose]:()=>{if(o)throw Error(`render-cache hold released twice`);o=!0,a.holders--,this.reclaim(i,a)}}}get stats(){let e=0,t=0;for(let n of this.holds.values())n.holders>0&&e++,n.retired!==null&&t++;return{size:this.entries.size,held:e,retired:t}}serve(e){this.holds.set(e,{holders:0,retired:null})}holdOf(e){let t=this.holds.get(e);if(t===void 0)throw Error(`render-cache state never served`);return t}retire(e,t){let n=this.holdOf(e);n.retired={reason:t,held:n.holders},this.reclaim(e,n)}reclaim(e,t){t.retired===null||t.holders>0||(this.holds.delete(e),this.log(`info`,jW(t.retired,e.registry.dispose())))}reload(e,t,n){this.reloadInto(this.getOrCreate(e,t,n))}reloadInto(e){let t=LW(e.projectDir,e.cwd,e.configFile,this.deps);if(e.lastWarning=t.warning,e.lastError=t.error,t.state!==null){this.log(`info`,AW(t.layers,t.state));let n=e.state;e.state=t.state,this.serve(t.state),this.retire(n,`reload`)}this.refreshWatcher(e,t),this.observers.onReload?.(e)}refreshWatcher(e,t){e.configLayers=t.layers,e.configHome=t.home,e.failedFile=t.error===null?null:t.failedFile;let n=PW(e,t.layers),r=`config:${e.projectDir}:${e.cwd}:${e.configFile??``}:${JSON.stringify(n)}`;e.watcher!==null&&e.watcherKey===r||(e.watcher?.release(),e.watcherKey=r,e.watcher=this.deps.watchers.acquire(r,n,()=>this.onConfigChanged(e)))}onConfigChanged(e){this.log(`info`,`config change detected for entry projectDir=${e.projectDir} cwd=${e.cwd}`),this.reloadInto(e)}get size(){return this.entries.size}firstState(){return this.entries.values().next().value?.state??null}};const BW=16384;var VW=class e{startedAt=new Date;requestsTotal=0;requestsErrored=0;requestsTimedOut=0;inFlight=0;watchersOpened=0;watchersClosed=0;watchersEvicted=0;subprocessTotal=0;subprocessInFlight=0;subprocessCount=new Map;subprocessHistogram=new Map;subprocessHistogramRotator=new Map;rollingTimestamps=[];rollingHead=0;launchStats={onStart:e=>{this.subprocessTotal++,this.subprocessInFlight++,this.subprocessCount.set(e,(this.subprocessCount.get(e)??0)+1),this.recordRollingNow()},onEnd:(e,t)=>{this.subprocessInFlight=Math.max(0,this.subprocessInFlight-1),this.recordDuration(e,t)}};recordRollingNow(){let e=Date.now();if(this.rollingTimestamps.length<BW){this.rollingTimestamps.push(e);return}this.rollingTimestamps[this.rollingHead]=e,this.rollingHead=(this.rollingHead+1)%BW}recordDuration(e,t){let n=this.subprocessHistogram.get(e);if(n||(n=[],this.subprocessHistogram.set(e,n)),n.length<16){n.push(t);return}let r=(this.subprocessHistogramRotator.get(e)??0)%16;n[r]=t,this.subprocessHistogramRotator.set(e,r+1)}snapshotSubprocesses(){let e=Date.now()-6e4,t=0;for(let n of this.rollingTimestamps)n>=e&&t++;let n={};for(let[e,t]of this.subprocessCount)t>0&&(n[e]=t);let r={},i={};for(let[e,t]of this.subprocessHistogram){if(t.length===0)continue;let n=[...t].sort((e,t)=>e-t),a=Math.floor(n.length*.5),o=Math.min(n.length-1,Math.floor(n.length*.99)),s=n[a],c=n[o];s!==void 0&&(r[e]=s),c!==void 0&&(i[e]=c)}return{total:this.subprocessTotal,inFlight:this.subprocessInFlight,lastMinute:t,byCategory:n,p50DurationMs:r,p99DurationMs:i}}static referenceSnapshot(){return new e().snapshot({gitCache:{size:0,hits:0,misses:0,invalidations:0,watchers:0},usageCache:{size:0,hits:0,misses:0,sweeps:0},renderCache:{size:0,held:0,retired:0},effectCache:{sessions:0,effects:0},sessionState:{sessions:0,observers:0,revision:0},frameFeeds:{feeds:0,subscribers:0,drawn:0,pushed:0,refused:0,lookups:0,found:0},watchersActive:0,handlerProbes:[],clients:[],bundle:`/`,daemon:{pid:0,rss:0,rssLimit:0,postMortems:{kind:`ok`,value:[]}}})}snapshot(e){let t=process.memoryUsage();return{pid:process.pid,version:Ft,sourceDigest:Fg(),protocolVersion:3,startedAt:this.startedAt.toISOString(),uptimeSec:Math.floor((Date.now()-this.startedAt.getTime())/1e3),rssBytes:t.rss,heapUsedBytes:t.heapUsed,heapTotalBytes:t.heapTotal,externalBytes:t.external,arrayBuffersBytes:t.arrayBuffers,requests:{total:this.requestsTotal,errored:this.requestsErrored,timedOut:this.requestsTimedOut,inFlight:this.inFlight},gitCache:e.gitCache,usageCache:e.usageCache,renderCache:e.renderCache,effectCache:e.effectCache,sessionState:e.sessionState,frameFeeds:e.frameFeeds,watchers:{active:e.watchersActive,opened:this.watchersOpened,closed:this.watchersClosed,evicted:this.watchersEvicted},subprocesses:this.snapshotSubprocesses(),nextRestartReason:e.nextRestartReason??null,handlerProbes:e.handlerProbes,clients:e.clients,bundle:e.bundle,daemon:e.daemon}}};function HW(e,t,n){let r=(r,i,a)=>{let o=i.filter(t).map(t=>({key:t,before:e.get(r,t)}));a();for(let{key:t,before:i}of o)n(r,t,i,e.get(r,t))};return{get:(t,n)=>e.get(t,n),revision:t=>e.revision(t),set:(t,n,i)=>r(t,[n],()=>e.set(t,n,i)),setBatch:(t,n)=>r(t,n.map(e=>e.key),()=>e.setBatch(t,n)),clear:(t,n)=>r(t,[n],()=>e.clear(t,n))}}const UW={load:()=>({}),save:()=>{},flush:()=>{}};var WW=class{sessions;storage;head=0;atom=(0,wv.createAtom)(`SessionState`);constructor(e=UW,t=256){this.maxSessions=t,this.storage=e,this.sessions=new Map,this.hydrateFromStorage()}useStorage(e){this.storage=e,this.hydrateFromStorage()}hydrateFromStorage(){this.sessions=new Map(Object.entries(this.storage.load()).map(([e,t])=>[e,{values:new Map(Object.entries(t)),revision:++this.head}])),this.evictOldest(),this.persist()}get(e,t){this.atom.reportObserved();let n=this.sessions.get(e);return n?(this.touch(e,n),n.values.get(t)??null):null}revision(e){return this.atom.reportObserved(),this.sessions.get(e)?.revision??0}observers(){return this.atom.observers_?.size??0}latestRevision(){return this.head}size(){return this.sessions.size}set(e,t,n){this.setBatch(e,[{key:t,value:n}])}setBatch(e,t){t.length!==0&&(0,wv.runInAction)(()=>{let n=this.sessions.get(e)??{values:new Map,revision:0};t.some(({key:e,value:t})=>n.values.get(e)!==t)&&(n.revision=++this.head);for(let{key:e,value:r}of t)n.values.set(e,r);this.touch(e,n),this.evictOldest(),this.persist(),this.atom.reportChanged()})}clear(e,t){(0,wv.runInAction)(()=>{let n=this.sessions.get(e);n&&(n.values.delete(t)&&(n.revision=++this.head),n.values.size===0?this.sessions.delete(e):this.touch(e,n)),this.persist(),this.atom.reportChanged()})}prune(e){(0,wv.runInAction)(()=>{for(let t of this.sessions.keys())e.has(t)||this.sessions.delete(t);this.persist(),this.atom.reportChanged()})}touch(e,t){this.sessions.delete(e),this.sessions.set(e,t)}evictOldest(){let e=this.sessions.size-this.maxSessions;if(!(e<=0)){for(let t of this.sessions.keys())if(this.sessions.delete(t),--e===0)break}}flush(){this.storage.flush()}persist(){this.storage.save(this.serialize())}serialize(){let e=Object.create(null);for(let[t,{values:n}]of this.sessions)e[t]=Object.fromEntries(n);return e}};function GW(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;for(let t of Object.values(e)){if(typeof t!=`object`||!t||Array.isArray(t))return!1;for(let e of Object.values(t))if(typeof e!=`string`)return!1}return!0}var KW=class{timer=null;pending=null;constructor(e,t=500,n=Gt){this.filePath=e,this.debounceMs=t,this.logger=n}load(){let e;try{e=s.readFileSync(this.filePath,`utf8`)}catch(e){let t=e.code;return t!==`ENOENT`&&this.logger(`warn`,`session-state read failed (${t}); starting empty`),{}}try{let t=JSON.parse(e);return GW(t)?t:(this.logger(`warn`,`session-state load: unexpected shape, starting empty`),{})}catch{return this.logger(`warn`,`session-state load: corrupt JSON, starting empty`),{}}}save(e){this.pending=e,!this.timer&&(this.timer=setTimeout(()=>this.flush(),this.debounceMs),this.timer.unref())}flush(){if(this.timer&&=(clearTimeout(this.timer),null),this.pending===null)return;let e=this.pending;try{s.mkdirSync(v.dirname(this.filePath),{recursive:!0});let t=`${this.filePath}.tmp`;s.writeFileSync(t,JSON.stringify(e),{mode:384}),s.chmodSync(t,384),s.renameSync(t,this.filePath),this.pending=null}catch(e){this.logger(`warn`,`session-state save failed: ${e.message}`)}}};const qW={default_empty_value:`string`,default_separator:`string`,palette:`string`,style:`string`,effect:`string`,preset:`string`,endcaps:`string`,variation:`string`,shade:`string`,autoWrap:`boolean`,padding:`number`,updateNotice:`boolean`,transitions:`boolean`,experimentalBand:`boolean`,experimentalStatusline:`boolean`,experimentalPane:`boolean`,colorCompatibility:`string`,menuGlyph:`string`},JW=new Set([`1`,`true`]),YW=new Set([`0`,`false`,``]);function XW(e,t){let n=xG(e),r=n.scope===`segment-palette`?`string`:qW[n.field];if(r===`string`)return JSON.stringify(t);if(r===`number`){let n=Number(t);if(!Number.isFinite(n))throw Error(`persistValueText: "${e}" expects a number, got "${t}"`);return String(n)}if(JW.has(t))return`true`;if(YW.has(t))return`false`;throw Error(`persistValueText: "${e}" expects boolean-ish (1, 0, true, false), got "${t}"`)}function ZW(e){try{return s.readFileSync(e,`utf8`)}catch(e){if(e.code===`ENOENT`)return null;throw e}}function QW(e,t,n){try{if(t===null){s.rmSync(e,{force:!0});return}s.mkdirSync(v.dirname(e),{recursive:!0}),Ve(e,t)}catch(t){let r=`config write failed (${e}): ${t.message}`;throw n(`error`,r),Error(r)}}function $W(e){return/^\s*$/.test(e)?null:Lr(e)}function eG(e,t){return e!==null&&zr(e,t)!==void 0}function tG(e){if(e.kind===`segment`)return e.when===void 0?e.name:{seg:e.name,when:e.when};if(e.kind===`container`){let{kind:t,direction:n,children:r,...i}=e;return{[n===`horizontal`?`h`:`v`]:r.map(tG),...i}}return e}function nG(e){if(!k_(e))return tG(e);let{rows:t,...n}=e;return{rows:Object.fromEntries(Object.entries(t).map(([e,t])=>[e,tG(t)])),...n}}const rG=UR,iG=rG.segments,aG=rG.presets,oG=rG.root;function sG(e,t,n,r){if(!eG(e,t)&&n===void 0)throw new q(`cannot edit ${r}: neither the config file nor the bundled default declares ${t.join(`.`)}`)}function cG(e,t){let n=qO(t);return t.scope===`segment-palette`&&sG(e,[`segments`,t.segment],iG[t.segment],n.join(`.`)),n}function lG(e){return Lr(qr(e))}function uG(){return Object.entries(oG.rows).map(([e,t])=>{let n=tG(t);return{path:[`root`],fragment:lG({rows:{[e]:n}}),unit:{path:[`root`,`rows`,e],value:n}}})}function dG(e,t){let n=e===null?void 0:zr(e,t);return n===void 0?null:{path:t,fragment:n,unit:null}}function fG(e,t){if(t===void 0)return null;let n=nG(t);return{path:e,fragment:lG(n),unit:{path:e,value:n}}}function pG(e,t){let n=[`presets`,t],r=[...n,`root`],i=aG[t];sG(e,n,i,r.join(`.`));let a=dG(e,r)??fG(r,i?.root);return a!==null&&mi(a.fragment)?a:null}function mG(e,t){let n=pi(t.fragment);return n===null?new Map([[`#`,{path:t.path,unit:t.unit,node:t.fragment}]]):new Map([...e,...n.map(e=>[e.key,{path:[...t.path,`rows`,e.key],unit:t.unit,node:e.value}])])}function hG(e,t){return[...uG(),dG(e,[`root`]),pG(e,t)].filter(e=>e!==null).reduce(mG,new Map)}function gG(e,t,n){for(let{node:r,...i}of hG(e,t).values())if(gi(r,n))return i;throw new q(`${_G(e,t).join(`.`)} holds no placement "${n}" — the bar you clicked is stale (it reloads on the next render), or the action names a placement the layout never held`)}function _G(e,t){return pG(e,t)?.path??[`root`]}function vG(e,t){return t.scope===`preset-root`?_G(e,t.preset):qO(t)}function yG(e,{unit:t}){return t===null?e:si(e,t.path,qr(t.value),Gr)}function bG(e){let t=KO(e);if(t===null)throw Error(`"${e}" is not a valid persist target`);return t}function xG(e){let t=bG(e);if(t.scope===`preset-root`)throw Error(`"${e}" names a layout, not a value`);return t}function SG(e,t,n,r,i){i(t,n,NG(t,r)),QW(t.path,r,e.logger),e.record(t.path,n,r)}function CG(e,t,n){let r=EG(e,t,n);if(r.length>0)throw new q(`refused: ${e.above.join(`, `)} sets ${r.join(`, `)} over ${e.path}, so this click would change nothing on the bar — edit it there`)}const wG=()=>{};function TG(e,t){try{return t()}catch(t){throw!(t instanceof q)||e.above.length===0?t:new q(`${t.message} — or it is declared by ${e.above.join(`, `)}, which the bar does not edit`)}}function EG(e,t,n){let r=DG(e,t);if(r===null)return[];let i=new Set(jG(AG(r),AG(n)));return jG(kG(e,r),kG(e,n)).filter(e=>!i.has(e))}function DG(e,t){try{return OG(e,t)}catch(e){if(e instanceof XE)return null;throw e}}function OG(e,t){return SR(t===null?e.above:[e.path,...e.above],GR,{entered:()=>{},warned:()=>{}},{projectDir:e.projectDir,cwd:e.cwd},n=>n===e.path&&t!==null?t:s.readFileSync(n,`utf8`))}function kG(e,t){let[n]=t.layers;return n?.path===e.path?n.config:t.base}function AG(e){return e.layers.at(-1)?.config??e.base}function jG(e,t,n=``){return!MG(e)||!MG(t)?JSON.stringify(e)===JSON.stringify(t)?[]:[n]:[...new Set([...Object.keys(e),...Object.keys(t)])].flatMap(r=>jG(e[r],t[r],n===``?r:`${n}.${r}`))}function MG(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function NG(e,t){try{return OG(e,t)}catch(e){throw e instanceof XE?new q(`refused: the config file would not load after this click — ${e.message}`):e}}function PG(e,t){let n=xG(t),r=$W(ZW(e)??``),i=r===null?void 0:zr(r,qO(n));return i!==void 0&&`value`in i?i.value:void 0}function FG(e,t,n){IG(e,t,n,[])}function IG(e,t,n,r){let i=ZW(t.path),a=n.reduce((e,[t,n])=>si(e,cG($W(e),xG(t)),XW(t,n),Gr),i??``);SG(e,t,i,TG(t,()=>LG(a,t.path,r,e=>e)),CG)}function LG(e,t,n,r){return n.reduce((e,{preset:n,id:i,setting:a,value:o})=>{let s=r(e,n,i),c=gG($W(s),n,i),l=bi(yG(s,c),c.path,i,a,qr(o));if(l===null)throw new q(`${c.path.join(`.`)} in ${t} has no placement "${i}" — the bar you clicked is stale (it reloads on the next render)`);return l},e)}function RG(e,t,n){let r=$W(e),i=[`presets`,t,`root`];for(let[a,{path:o,unit:s,node:c}]of hG(r,t)){if(!gi(c,n))continue;if(i.every((e,t)=>o[t]===e))return e;let l=s===null?Vr(e,c):qr(s.value);if(a!==`#`)return si(e,[...i,`rows`,a],l,Gr);if(pG(r,t)!==null)throw new q(`cannot give preset "${t}" its own copy of ${o.join(`.`)}: it already stages rows of its own over that tree`);return si(e,i,l,Gr)}return e}function zG(e,t){return li(e,t,t[0]===`presets`&&t.length>2&&!qR(t[1])?2:0)}function BG(e,t,n){let r=n.map(bG),i=ZW(t.path);if(i===null)return;let a=r.reduce((e,t)=>zG(e,vG($W(e),t)),i);a!==i&&SG(e,t,i,a,wG)}function VG(e){let t=e===null?void 0:zr(e,[`presets`]);return t?.kind===`object`?t.entries.map(e=>e.key):[]}function HG(e,t){let n=new Set([...KR,...VG(e),...t.above.flatMap(e=>Object.keys(Ar.default.parse(s.readFileSync(e,`utf8`)).presets??{}))].map(YE));return Array.from({length:n.size+1},(e,t)=>`custom-${t+1}`).find(e=>!n.has(YE(e)))}function UG(e,t,n,r,i,a){let o=ZW(t.path),s=$W(o??``),c=HG(s,t),l=[`presets`,c],u=TG(t,()=>pG(s,n)),d=[...u===null?[]:[[[...l,`root`],u.unit===null?Vr(o??``,u.fragment):qr(u.unit.value)]],...Object.keys(r).length===0?[]:[[[...l,`globals`],qr(r)]]],f=i.map(([e,t])=>{let n=GO(c,e);return[cG(s,xG(n)),XW(n,t)]}),p=[...d,...f].reduce((e,[t,n])=>si(e,t,n,Gr),si(o??``,l,`{}`,Gr));return SG(e,t,o,TG(t,()=>LG(p,t.path,a.map(e=>({...e,preset:c})),RG)),CG),c}function WG(e,t,n,r){let i=ZW(t.path);SG(e,t,i,si(i??``,[`themeDefaults`,n],qr(r),Gr),CG)}function GG(e,t,n){if(qR(n))throw new q(`cannot delete preset "${n}": it is bundled — reset its settings instead`);let r=[`presets`,n],i=ZW(t.path),a=$W(i??``);if(i===null||a===null||zr(a,r)===void 0)throw new q(`cannot delete preset "${n}": ${t.path} declares no ${r.join(`.`)} — the bar you clicked is stale; it reloads on the next render`);let o=zr(a,[`globals`,`preset`]);SG(e,t,i,[r,...o?.kind===`string`&&o.value===n?[[`globals`,`preset`]]:[]].reduce((e,t)=>zG(e,t),i),wG)}function KG(e,t,n,r){let i=bG(n);if(i.scope!==`preset-root`)throw Error(`"${n}" is not a "presets.<name>.root" target`);let a=ZW(t.path),o=r.op===`remove`?r.target:r.anchor,s=TG(t,()=>gG($W(a??``),i.preset,o)),c=yG(a??``,s),{after:l,placed:u}=qG(c,s.path,r,()=>{let e=NG(t,c).config;return z_(e.presets).map(t=>H_(e,t).node)});if(l===null)throw new q(`${s.path.join(`.`)} in ${t.path} has no placement "${o}" — the bar you clicked is stale (it reloads on the next render), or the action names a placement the layout never held`);return SG(e,t,a,l,CG),u}function qG(e,t,n,r){switch(n.op){case`remove`:return{after:vi(e,t,n.target),placed:null};case`insert`:{let i=PN(n.segment,n.anchor,r());return{after:yi(e,t,i,n.anchor,n.relation),placed:i}}}}const JG={load:()=>({}),save:()=>{}},YG=new Set(Va.map(e=>e.sessionKey)),XG=e=>YG.has(e)||e.startsWith(ik),ZG=8*1024*1024,QG={past:[],future:[]},$G=e=>e.kind===`session`?`session:${e.key}`:`file:${e.file}`;var eK=class{state=new Map;constructor(e,t,n=JG){this.sessionState=e,this.logger=t,this.storage=n,this.state=new Map(Object.entries(n.load()))}useStorage(e){this.storage=e,this.state=new Map(Object.entries(e.load()))}depth(e){let{past:t,future:n,savepoint:r}=this.state.get(e)??QG;return{undo:t.length,redo:n.length,sinceEdit:r?.net.length??0}}history(e){return this.state.get(e)??QG}begin(){let e=new Map,t=(t,n)=>{let r=e.get(t)??new Map,i=r.get($G(n));r.set($G(n),i===void 0?n:{...n,before:i.before}),e.set(t,r)},n=new Map;return{sessionState:HW(this.sessionState,e=>XG(e)||e===`edit.mode`,(e,r,i,a)=>{if(r===`edit.mode`){let t=n.get(e);n.set(e,{before:t===void 0?i:t.before,after:a});return}t(e,{kind:`session`,key:r,before:i,after:a})}),file:(e,n,r,i)=>t(e,{kind:`file`,file:n,before:r,after:i}),commit:()=>{let t=new Map(e),r=new Map(n);e.clear(),n.clear();for(let e of new Set([...t.keys(),...r.keys()])){let n=[...t.get(e)?.values()??[]].filter(e=>e.before!==e.after),i=this.history(e),a=n.length===0?i:cK(i,n),o=r.get(e),s=o===void 0?a:fK(a,o);s!==i&&this.put(e,s)}}}}undo(e){let t=this.history(e),n=t.past.at(-1);if(n===void 0)throw new q(`undo: nothing to undo`);return this.apply(e,n,`before`,`undo`,uK(t,n)),n}rewind(e){let t=this.history(e),{savepoint:n}=t;if(n===void 0)throw new q(`rewind: edit mode has no savepoint — nothing to cancel`);let r=n.net.filter(t=>this.read(e,t)!==t.after),i=new Set(r.map($G)),a=n.net.filter(e=>!i.has($G(e))),o=rK(pK(dK(t,n),i));if(this.apply(e,a,`before`,`rewind`,{past:o,future:[],savepoint:{at:o.length,net:[],below:[]}}),r.length>0)throw new q(`rewind: ${r.map(hK).join(`, `)} changed since edit mode opened — kept as it is; everything else edit mode changed was put back`);return a}redo(e){let t=this.history(e),{past:n,future:r}=t,i=r.at(-1);if(i===void 0)throw new q(`redo: nothing to redo`);let a=[...n,i],o=rK(a);return this.apply(e,i,`after`,`redo`,{past:o,future:r.slice(0,-1),...aK(t.savepoint,a.length-o.length,i)}),i}apply(e,t,n,r,i){let a=n===`before`?`after`:`before`,o=t.filter(t=>this.read(e,t)!==t[a]);if(o.length>0){let t=new Set(o.map($G)),{past:n,future:i,savepoint:a}=this.history(e);throw this.put(e,{past:pK(n,t),future:pK(i,t),...a!==void 0&&{savepoint:{at:pK([...n,...[...i].reverse()].slice(0,a.at),t).length,net:a.net.filter(e=>!t.has($G(e))),below:pK(a.below,t)}}}),new q(`${r}: ${o.map(hK).join(`, `)} changed since that edit — refusing to overwrite it; this session's undo history no longer steps it`)}let s=[];try{for(let r of t)this.write(e,r,r[n]),s.push(r);this.put(e,i)}catch(t){try{for(let t of s.reverse())this.write(e,t,t[a])}catch(e){throw Error(`${t.message}; and putting the step back failed, so it is half-applied: ${e.message}`)}throw t}}read(e,t){return t.kind===`session`?this.sessionState.get(e,t.key):ZW(t.file)}write(e,t,n){t.kind===`file`?QW(t.file,n,this.logger):n===null?this.sessionState.clear(e,t.key):this.sessionState.set(e,t.key,n)}put(e,t){let n=new Map(this.state);for(n.delete(e),(t.past.length>0||t.future.length>0||t.savepoint!==void 0)&&n.set(e,t);n.size>32||tK(n)>ZG;){let[e,t]=n.entries().next().value;n.size>1?n.delete(e):t.past.length+t.future.length>0?n.set(e,nK(t)):(this.logger(`warn`,`settings-history: edit mode's changes for session ${e} exceed ${ZG} bytes; cancel is no longer available`),n.delete(e))}this.storage.save(Object.fromEntries(n)),this.state=n}};function tK(e){let t=0;for(let{past:n,future:r,savepoint:i}of e.values())for(let e of[...n,...r,...i===void 0?[]:[i.net,...i.below]])for(let n of e)t+=(n.before?.length??0)+(n.after?.length??0);return t}function nK({past:e,future:t,savepoint:n}){return e.length>0?{past:e.slice(1),future:t,...aK(n,1,[])}:{past:e,future:t.slice(1),...aK(n,0,[])}}function rK(e){return e.slice(-50)}const iK=e=>e===ok.member;function aK(e,t,n){return e===void 0?{}:{savepoint:{at:Math.max(0,e.at-t),net:oK(e.net,n),below:e.below}}}function oK(e,t){let n=new Map(e.map(e=>[$G(e),e]));for(let e of t){let t=n.get($G(e));n.set($G(e),t===void 0?e:{...t,after:e.after})}return[...n.values()].filter(e=>e.before!==e.after)}const sK=e=>e.map(e=>({...e,before:e.after,after:e.before}));function cK(e,t){let n=[...e.past,t],r=rK(n),{savepoint:i}=e,a=i===void 0?0:Math.max(0,i.at-e.past.length);return{past:r,future:[],...aK(i&&{at:Math.min(i.at,e.past.length),net:i.net,below:[...lK(e.future,a),...i.below]},n.length-r.length,t)}}function lK(e,t){let n=Math.min(t,e.length);return e.slice(e.length-n).reverse()}function uK(e,t){return{past:e.past.slice(0,-1),future:rK([...e.future,t]),...aK(e.savepoint,0,sK(t))}}function dK(e,t){let{past:n,future:r}=e,i=n.slice(0,t.at);return[...i,...lK(r,t.at-i.length),...t.below]}function fK(e,t){if(iK(t.after)&&!iK(t.before))return{...e,savepoint:{at:e.past.length,net:[],below:[]}};if(!iK(t.after)&&iK(t.before)){let{past:t,future:n}=e;return{past:t,future:n}}return e}function pK(e,t){return e.map(e=>e.filter(e=>!t.has($G(e)))).filter(e=>e.length>0)}function mK(e){return e.map(hK).join(`, `)}function hK(e){return e.kind===`session`?`session setting "${e.key}"`:e.file}function gK(e){if(typeof e!=`object`||!e)return!1;let t=e,n=e=>e===null||typeof e==`string`;return(t.kind===`session`&&typeof t.key==`string`||t.kind===`file`&&typeof t.file==`string`)&&n(t.before)&&n(t.after)}function _K(e){return Array.isArray(e)&&e.every(e=>Array.isArray(e)&&e.every(gK))}function vK(e){if(typeof e!=`object`||!e)return!1;let t=e;return Number.isInteger(t.at)&&t.at>=0&&Array.isArray(t.net)&&t.net.every(gK)&&_K(t.below)}function yK(e){if(typeof e!=`object`||!e)return!1;let t=e;return _K(t.past)&&_K(t.future)&&(t.savepoint===void 0||vK(t.savepoint))}function bK(e,t){let n=e=>e.kind===`file`||XG(e.key)?!0:(t.add(e.key),!1),r=e=>e.map(e=>e.filter(n)).filter(e=>e.length>0),{savepoint:i}=e,a=r(e.past),o=r(e.future);return i===void 0?{past:a,future:o}:{past:a,future:o,savepoint:{at:r(e.past.slice(0,i.at)).length,net:i.net.filter(n),below:r(i.below)}}}function xK(e,t){return{load:()=>{let n;try{n=s.readFileSync(e,`utf8`)}catch(e){let n=e.code;return n!==`ENOENT`&&t(`warn`,`settings-history read failed (${n}); starting empty`),{}}try{let e=JSON.parse(n);if(typeof e==`object`&&e&&!Array.isArray(e)&&Object.values(e).every(yK)){let n=new Set,r=Object.fromEntries(Object.entries(e).map(([e,t])=>[e,bK(t,n)]));return n.size>0&&t(`warn`,`settings-history load: dropped the changes to ${[...n].map(e=>`"${e}"`).join(`, `)}, no longer a setting`),r}}catch{}return t(`warn`,`settings-history load: unexpected shape, starting empty`),{}},save:n=>{try{s.mkdirSync(v.dirname(e),{recursive:!0}),Ve(e,JSON.stringify(n),384)}catch(e){let n=`settings-history write failed — the change landed but is not undoable: ${e.message}`;throw t(`error`,n),Error(n)}}}}const SK=e=>!XG(e)&&!nj(e)&&e!==`update.dismissed`;var CK=class{past=new Map;depth(e,t,n){return this.restorable(e,t,n).length}restorable(e,t,n){let r=new Map,i=n=>r.has(n)?r.get(n):t.get(e,n),a=[];for(let t of[...this.past.get(e)??[]].reverse())if(t.every(e=>i(e.key)===e.after&&(e.before===null||n.validate(e.key,e.before).ok))){a.unshift(t);for(let e of t)r.set(e.key,e.before)}return a}begin(e){let t=new Map;return{sessionState:HW(e,SK,(e,n,r,i)=>{let a=t.get(e)??new Map,o=a.get(n);a.set(n,{key:n,before:o?o.before:r,after:i}),t.set(e,a)}),commit:()=>{for(let[e,n]of t){let t=[...n.values()].filter(e=>e.before!==e.after);t.length>0&&this.push(e,t)}t.clear()}}}back(e,t,n){let r=this.past.get(e)??[],i=this.restorable(e,t,n),a=i.at(-1),o=r.length-i.length;if(a===void 0)throw this.put(e,i),new q(`back: nothing to go back to${o>0?` (${o} step(s) over a view since gone, discarded)`:``}`);return(0,wv.runInAction)(()=>{let n=a.flatMap(({key:e,before:t})=>t===null?[]:[{key:e,value:t}]);n.length>0&&t.setBatch(e,n);for(let{key:n,before:r}of a)r===null&&t.clear(e,n)}),this.put(e,i.slice(0,-1)),{step:a,discarded:o}}push(e,t){let n=this.past.get(e)??[];this.put(e,[...n,t].slice(-20))}put(e,t){for(this.past.delete(e),t.length>0&&this.past.set(e,t);this.past.size>32;)this.past.delete(this.past.keys().next().value)}};const wK=`click.error`;function TK(e,t,n,r){let i={text:n,at:r,answered:!1};e.set(t,wK,JSON.stringify(i))}function EK(e,t,n){let r=DK(e,t);!(r?.at===n.at&&r.text===n.text)||r.answered||e.set(t,wK,JSON.stringify({...r,answered:!0}))}function DK(e,t){let n=e.get(t,wK);return n===null?null:kK(n)}function OK(e,t,n,r){let i=DK(e,t);return i===null?{kind:`none`}:n<i.at+5?{kind:`held`,error:i}:r===`request`&&!i.answered?{kind:`owed`,error:i}:{kind:`over`}}function kK(e){let t;try{t=JSON.parse(e)}catch{return null}if(typeof t!=`object`||!t)return null;let{text:n,at:r,answered:i}=t;return typeof n==`string`&&typeof r==`number`&&(i===void 0||typeof i==`boolean`)?{text:n,at:r,answered:i===!0}:null}const AK=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function jK(e,t){let n=e=>({kind:`failed`,reason:`${t} ${e}`}),r;try{r=JSON.parse(e)}catch(e){return n(`is not JSON: ${e.message}`)}if(!AK(r))return n(`is not an object`);for(let[e,t]of Object.entries(r)){if(!AK(t))return n(`holds ${JSON.stringify(e)} as something other than its sightings`);for(let[e,r]of Object.entries(t))if(!Zk.includes(r))return n(`marks ${JSON.stringify(e)} ${JSON.stringify(r)}, not ${Zk.join(` or `)}`)}return{kind:`ok`,value:r}}function MK(e,t,n,r){return{...e,[t]:{...e[t],[n]:r}}}function NK(e=v.join(Ue(),`doctor-marks.json`)){let t=()=>{let t;try{t=s.readFileSync(e,`utf8`)}catch(t){return t.code===`ENOENT`?{kind:`ok`,value:{}}:{kind:`failed`,reason:`${e}: ${t.message}`}}return jK(t,e)};return{read:t,record:(n,r,i)=>{let a=t();if(a.kind===`failed`)throw Error(`doctor: the mark book could not be read: ${a.reason}`);s.mkdirSync(v.dirname(e),{recursive:!0}),Ve(e,`${JSON.stringify(MK(a.value,n,r,i),null,2)}\n`)}}}var PK=class extends Error{constructor(e){super(`the doctor looked at ${e} less than a second ago — click again`),this.name=`DoctorBusy`}};const FK={pullRequests:e=>qz(e).showPullRequest===!0,rateLimits:e=>Kz(e,`block`)||Kz(e,`weekly`),memento:e=>Kz(e,`memento`)};function IK(e,t){let n=new Map;for(let r of e_(H_(e,t).node)){if(r.kind!==`segment`)continue;let e=n.get(r.name)??[];r.when&&e.push(r.when),n.set(r.name,e)}let r=[...n.keys()].filter(t=>d_(e.segments[t])===`fail`),i=new Map(r.map(t=>[t,Hz(e,t,n.get(t))])),a=e=>r.filter(t=>FK[e](i.get(t)));return{pullRequests:a(`pullRequests`),rateLimits:a(`rateLimits`),memento:a(`memento`)}}
|
|
197
|
+
`);n.push(e[0]);for(let r=1;r<e.length;r++)t.push(n),n=[e[r]]}return t.push(n),t}function YU(e){let t=new Map;return e.map(e=>{let n=`${e.place}.${e.band}`,r=t.get(n)??0;return t.set(n,r+1),{line:e,row:`${n}#${r}`}})}function XU(e,t){let n=[],r=[],i;for(let a of t)(a.band===`own`?n:r).push(a),i??=a.cells.find(t=>t.placement.id===e)?.placement.ground;return{drawing:i===void 0?null:{own:r.length===0?n:[],ground:i},deeper:r}}function ZU(e){return{...e,cells:e.cells.map(SH)}}function QU(e,t){let n=t.flatMap(e=>e.filter(e=>e.place===`above`)),r=t.map(e=>e.filter(e=>e.place===`flow`));return[...n,...$U(e,r)]}function $U(e,t){switch(e){case`vertical`:return t.flatMap(e=>e);case`horizontal`:return t.reduce((e,t)=>Math.max(e,t.length),0)===0?[]:[{cells:t.flatMap(e=>e[0]?.cells??[]),band:`own`,place:`flow`},...t.flatMap(e=>e.slice(1))]}}function eW(e,t){let n=(e,r)=>t(e)?e.kind===`segment`?[{cells:[{name:e.name,address:r,settings:e.settings}],band:`own`,place:`flow`}]:QU(e.direction,e.children.map((t,i)=>n(t,[...r,tW(e,i)]))):[];return n(e,[]).map(e=>[...e.cells])}function tW(e,t){return{index:t,count:e.children.length,distribution:e.distribution,axis:Jg[e.direction]}}const nW={compile(e,t){return{kind:`container`,direction:e.direction,when:t.when,distribution:$p(e.distribution),children:e.children.map((e,n)=>t.compileChild(e,e_(t.path,n)))}},render(e,t){return t.gate.kind===`failed`&&t.gate.report(),QU(e.direction,e.children.map((n,r)=>t.renderChild(n,t.gate.kind===`shown`,tW(e,r))))}},rW={drop:e=>e.place,above:()=>`above`},iW={drop:(e,t)=>({lead:t(),stays:e}),above:e=>({lead:e.slice(0,1).flatMap(e=>e.cells),stays:e.slice(1)})},aW={compile(e,t){return{kind:`segment`,when:t.when,name:e.name,id:Yg(e),settings:t.placementSettings(e),...e.opens!==void 0&&{opens:{open:t.parse(gr(e.opens.ref),`opens`),body:t.compileChild(e.opens.body,t_(t.path)),key:e.opens.ref.key,placement:e.opens.placement}},...e.lead!==void 0&&{lead:t.parse(e.lead,`lead`)},...e.trail!==void 0&&{trail:t.parse(e.trail,`trail`)}}},render:(e,t)=>t.placed(e.id,oW(e,t))};function oW(e,t){let n=t.lookupSegment(e.name);if(!n)throw Error(`Layout segment "${e.name}" has no matching segment`);let{seg:r,compiled:i}=n;if(t.gate.kind===`hidden`)return[];let a=ST(t.scope,e.settings);if(t.gate.kind===`failed`)return sW(e,a,t,t.gate.message);try{if(!hH(i.when,a))return[];let n=zg(e.settings.theme,t.palette),o={id:e.id,effect:e.settings.effect,ground:hk(n)},s=e.opens!==void 0&&hH(e.opens.open,t.scope),{styles:c,fragments:l,lead:u,trail:d,drops:f,open:p}=t.evaluateSegment(e,a,n,t.region,{bg:i.bg,fg:i.fg,body:i.template,lead:e.lead,trail:e.trail},s),m=p?c.trigger:c.closed,h={width:r.width??`auto`,justify:r.justify??`left`,truncate:r.truncate??`right`,baseStyle:m,padding:t.padding,placement:o},g=e.opens,_=g===void 0?[]:t.renderBody(g.body,s,c.disclosure).map(e=>({...e,place:rW[g.placement](e)})),v=JU(kH(l,m)).map((e,t)=>({cells:TH(e,{...h,lead:t===0?kH(u,m):[],trail:t===0?kH(d,m):[]}),band:`own`,place:`flow`})),y=f.map(e=>({cells:TH(kH([e],c.band),{...h,baseStyle:c.band}),band:`deeper`,place:`flow`})),b=(e,t,n)=>TH(kH([e],t),{...h,width:`auto`,baseStyle:t,padding:n}),x=_.findIndex(e=>e.band===`own`),{lead:S,stays:C}=g!==void 0&&x!==-1?iW[g.placement](v,()=>b(t.closeDisclosure(g.key),c.close,t.padding)):{lead:[],stays:v},w=S.flatMap(e=>b(new K(` `.repeat(xH(e).reduce((e,t)=>e+t.cellLength,0))),c.trigger,0)),ee=(e,t)=>e.band===`own`?t===x?S:w:[],te=_.map((e,t)=>({cells:[...ee(e,t),...e.cells],band:`deeper`,place:e.place})),ne=[...C,...y];return t.perSegmentSink!==void 0&&t.perSegmentSink.set(e.id,[...ne.flatMap(e=>e.cells),..._.flatMap(ee)].flatMap(xH)),[...ne,...te]}catch(n){return sW(e,a,t,n.message??String(n))}}function sW(e,t,n,r){n.onSegmentError?.(e.id,r);let i=r.replace(/\s*\n\s*/g,` `);return[{cells:TH([new K(`⚠ ${e.id}: ${i}`,{end:``})],{width:`auto`,justify:`left`,truncate:`right`,padding:0,placement:{id:e.id,effect:`bar`,ground:hk(n.palette)},lead:cW(e.lead,e,t,n),trail:cW(e.trail,e,t,n)}),band:`own`,place:`flow`}]}function cW(e,t,n,r){if(e===void 0)return[];try{return r.evaluateSegment(t,n,r.palette,r.region,{bg:void 0,fg:void 0,body:e,lead:void 0,trail:void 0},!1).fragments}catch(e){return r.onSegmentError?.(t.id,e.message??String(e)),[]}}const lW={container:nW,segment:aW};function uW(e){return lW[e]}function dW(e){if(`ttl`in e)return{kind:`ttl`,durationMs:SE(e.ttl)};if(`watch_file`in e)return{kind:`watch_file`,path:e.watch_file};if(`depends_on`in e)return{kind:`depends_on`,varNames:e.depends_on};if(`key`in e)return{kind:`key`,template:e.key};if(`never`in e)return{kind:`never`};throw Error(`Unknown CacheDecl discriminator — loader invariant violated: ${JSON.stringify(e)}`)}function fW(e,t){switch(a_(e)){case`json`:return{kind:`json`,default:t};case`regex`:return{kind:`regex`,regex:new RegExp(e.regex),default:t};case`text`:return{kind:`text`,default:t}}}function pW(e,t,n,r){switch(n.kind){case`literal`:e.declareLiteral(t,n.value);break;case`dropped`:e.declareFailedDocument(t,n.reason);break;case`input`:e.declareInput(t,n.path,n.type??`string`,n.default);break;case`env`:e.declareEnv(t,n.name,n.default);break;case`file`:e.declareFile(t,n.path,{readMode:n.readMode,cache:dW(n.cache),parse:fW(n.parse,n.default)});break;case`shell`:e.declareShell(t,n.command,{cwd:r,cache:dW(n.cache),parse:fW(n.parse,n.default)});break;case`template`:e.declareTemplate(t,n.template,{varDefault:n.default});break;case`time`:e.declareTime(t,{format:n.layout,varDefault:n.default});break;case`git`:e.declareGit(t,{field:n.field,cwd:r,varDefault:n.default});break;case`state`:e.declareState(t,{key:n.key,...n.default!==void 0&&{varDefault:n.default}});break}}function mW(e,t){let n=ay.EMPTY;for(let[r,i]of Object.entries(t))try{n=e.parse(`{{ define "${r}" }}${i}{{ end }}`,n).defines()}catch(e){throw Error(`Template parse error in helpers.${r}: ${e.message}`,{cause:e})}return n}const hW=(e,t,n,r,i)=>{let a=tz(t,ez(n,e.themeDefaults));return{variation:qp[r??Dh(void 0,null,a.variation)],shade:Gp[i??Ah(void 0,null,a.shade)]}};function gW(e,t,n){let r=n.cwd,i={store:t.variableStore,compiled:new Map,chromeCols:ag({endcaps:`powerline`}),width:80,padding:1,seamCols:og({endcaps:`powerline`}),layout:()=>[],look:void 0},a=lU(t.drawnAt),o={action:i,activeSegment:a},s=Object.keys(e.styles),c=R_(e.presets),l=vN(e),u=yT({extraFuncs:{...KH(i),...xU(i,a),...TU(i,a),...PU(i,a),...kU(i,a,t.now),...zU(i,a),...UU(o),...KU(a),styles:{fn:()=>s,argTypes:[],arity:{kind:`exact`}},presets:{fn:()=>c,argTypes:[],arity:{kind:`exact`}}},clock:t.now,drawnAt:t.drawnAt}),d=mW(u,e.helpers),f=e=>u.parse(e,d),p=new Map,m=e=>{let t=p.get(e);if(t!==void 0)return t;let n=f(e);return p.set(e,n),n},h=new Map;for(let[t,n]of Ga)n in e.variables&&h.set(t,n);for(let[t,n]of d_(e))h.has(n.key)||h.set(n.key,t);i.compiled=NH(f,e.actions,h,l);let g=[];for(let[n,i]of Object.entries(e.variables))try{pW(t,n,i,r)}catch(e){g.push(`Variable "${n}": ${e.message??String(e)}`)}for(let[n,i]of Object.entries(e.segments))if(i.vars)for(let[e,a]of Object.entries(i.vars))try{pW(t,`${n}.${e}`,a,r)}catch(t){g.push(`Variable "${n}.${e}": ${t.message??String(t)}`)}let _=Object.create(null);for(let[t,n]of Object.entries(e.segments)){let e=(e,n,r=f)=>{try{return r(e)}catch(e){throw Error(`Template parse error in segments.${t}.${n}: ${e.message}`,{cause:e})}};_[t]={when:n.when===void 0?void 0:e(n.when,`when`,m),template:e(n.template,`template`),bg:n.bg===void 0?void 0:e(n.bg,`bg`),fg:n.fg===void 0?void 0:e(n.fg,`fg`)}}let v=(e,t,n)=>{try{return m(e)}catch(e){throw Error(`Template parse error in ${t}.${n}: ${e.message}`,{cause:e})}},y=t.variableStore,b=t=>{let n=h_(e.segments[t.name]),r=Object.create(null);for(let[e,i]of Object.entries(n))Object.defineProperty(r,e,{enumerable:!0,get:()=>x_(t,e,i,e=>String(y.read(e.variable)))});return Object.freeze(r)},x=(e,t)=>{let n={path:t,when:e.when===void 0?void 0:v(e.when,t,`when`),parse:(e,n)=>v(e,t,n),compileChild:x,placementSettings:b};return uW(e.kind).compile(e,n)},S=new Map;for(let t of c){let{node:n,path:r}=V_(e,t);S.set(t,x(n,r))}let C=new Map(nh.map(e=>[e,new Map])),w=[[`globals`,e.globals],...Object.entries(e.presets).map(([e,t])=>[`presets.${e}.globals`,t.globals??{}])];for(let[e,t]of w)for(let n of nh){let r=t[n];if(!rh(r))continue;let i=`${e}.${n}`,a=C.get(n),o=a.get(r);a.set(r,o===void 0?{where:i,template:_W(f,i,r)}:{where:`${o.where}, ${i}`,template:o.template})}return{segments:_,roots:S,activeSegment:a,menuRuntime:o,globalExpressions:C,loadWarnings:g}}function _W(e,t,n){try{return e(n)}catch(e){throw Error(`${t} is not a valid template: ${e instanceof Error?e.message:String(e)}`)}}function vW(e,t,n){let r=e.globalExpressions.get(t).get(n);if(r===void 0)throw Error(`the ${t} rule ${JSON.stringify(n)} reached the render but no compiled template exists — registerDslConfig and the resolution disagree about isExpression`);return r}function yW(e,t,n,r){try{return t.template.evaluate(n).map(e=>e.plain).join(``)}catch(n){return r({kind:`rule`,slot:e,message:fh(t.where,e,`the rule failed — ${n instanceof Error?n.message:String(n)}`)}),dh[e]}}function bW(e,t){return e.kind===`decided`?e.name:dh[t]}function xW(e){return SW(e).filter(e=>!e.name.startsWith(nD)).map(e=>e.id)}function SW(e){return e.kind===`container`?e.children.flatMap(SW):[e,...e.opens===void 0?[]:SW(e.opens.body)]}function CW(...e){return wW(...e).text}function wW(e,t,n,r,i,a,o,s,c){let{perSegmentSink:l,onSegmentError:u,onRenderWarning:d}=s??{},f=e=>d?.(e),p=new Set;r.renderAt(a),r.drawAt(wh(o.colorCompatibility));let{preset:m=I_}=c??{},h=H_(e,m),g=c?.style??ch(`none`,e.styles),_=c?.theme??Gg(void 0,null,h.palette),v=hW(e,h,_,c?.variation,c?.shade),y=c?.effect??_h(void 0,null,h.effect),b=(e,t,n)=>({...i,term:{cols:o.width},theme:{effective:e},style:{effective:t},effect:{effective:n}});r.applyInput(b(bW(_,`palette`),bW(g,`style`),bW(y,`effect`))),t.menuRuntime.action.chromeCols=ag(o),t.menuRuntime.action.padding=o.padding,t.menuRuntime.action.width=o.width,t.menuRuntime.action.seamCols=og(o);let x=bT(n),S=ah(_,e=>{let n=vW(t,`palette`,e);return Wg(yW(`palette`,n,x,f),n.where,e=>f({kind:`rule`,slot:`palette`,message:e}))}),C=ah(g,n=>ch(yW(`style`,vW(t,`style`,n),x,f),e.styles)),w=ah(y,e=>gh(yW(`effect`,vW(t,`effect`,e),x,f)));(S!==_||C!==g||w!==y)&&r.applyInput(b(S.name,C.name,w.name));let ee=S.value,te=Vg(ee,C.value);t.menuRuntime.action.look={basePalette:ee,palette:te,decor:v};let ne=c?.transitions??Bh(void 0,null,h.transitions),T=(c?.effects??new Zh(``)).motion(w.value,a,{transitions:ne,source:{config:t,preset:m,revision:r.stateRevision(),width:o.width},returned:XU,hold:ZU});l?.clear();let re=n=>{let r=e.segments[n],i=t.segments[n];return r!==void 0&&i!==void 0?{seg:r,compiled:i}:void 0},E=(e,n,i,a,o,s)=>{try{let c=r.drawnAt(),{tint:l,text:u,disclosure:d}=Km(i,a,c),f=uU(t.activeSegment,e.name,e.id,i,d,l,u),m=_k(f,c,o.bg,o.fg,n),h=()=>Nm(i,d,c);s&&(f.bg=h().state);let g=o.body.evaluate(n),_=f.drops.length>0||s;if(_){let e=h();f.bg=e.state;for(let t of e.shortfalls)p.add(t)}let v=o.lead?.evaluate(n)??[],y=o.trail?.evaluate(n)??[];return{styles:{closed:m,get trigger(){return JH(i,h().state,c)},get band(){return JH(i,h().plane,c)},get close(){return ZH(i,h().state,c)},disclosure:d},fragments:g,lead:v,trail:y,drops:f.drops,open:_}}finally{t.activeSegment.current=null}},D=(e,t,r)=>{let i=t?vH(e.when,x):gH,a=i.kind===`failed`?{...i,report:()=>{let t=`when over ${xW(e).join(`, `)||`no placement`}`;f({kind:`when`,where:t,error:i.message,message:`${t}: ${i.message} — what it gates is hidden`})}}:i,s={scope:x,palette:te,gate:a,padding:o.padding,region:r,perSegmentSink:l,onSegmentError:u,evaluateSegment:E,lookupSegment:re,renderChild:(e,t,n)=>D(e,t,Wm(r,n)),renderBody:(e,t,n)=>D(e,a.kind===`shown`&&t,Gm(n)),closeDisclosure:e=>qH(n,e),placed:T.placed};return uW(e.kind).render(e,s)},ie=t.roots.get(m);if(ie===void 0)throw Error(`Preset "${m}" has no compiled layout — registerDslConfig compiles one per declared preset and effectivePresetName collapses unknown names to "${I_}"; a miss here is merge/policy drift (have: ${[...t.roots.keys()].join(`, `)})`);let O=e=>{let n=vH(e.when,x);if(e.kind===`container`)return n.kind===`shown`;if(kN(e.name)===void 0)return!1;if(n.kind!==`shown`)return n.kind===`failed`;try{return hH(t.segments[e.name].when,ST(x,e.settings))}catch{return!0}};t.menuRuntime.action.layout=()=>eW(ie,O).map(e=>e.flatMap(({name:e,address:t,settings:n})=>{let r=kN(e);return r===void 0?[]:[{name:r,address:t,palette:zg(n.theme,te)}]}));let ae=YU(D(ie,!0,Um(v))).map(({line:e,row:t})=>{let n=OH(e.cells,o);return ug(n.map(e=>e.owner),o,T.row(t,n))});T.drawn();let oe=ae.some(e=>e.moves)?`moves`:y.kind===`expression`||ne||SW(ie).some(({settings:e})=>e.effect!==`bar`&&e.effect!==`none`)?`can-move`:`still`;for(let e of p)f({kind:`band-floor`,message:e});for(let[e,t]of r.cachePolicyFaults())f({kind:`refresh`,variable:e,error:t.message,message:`variable "${e}" cannot refresh: ${t.message}`});return{text:ae.map(e=>e.text).join(`
|
|
198
|
+
`),motion:oe}}function*TW(e){yield*Object.entries(e.variables??{});for(let[t,n]of Object.entries(e.segments??{}))for(let[e,r]of Object.entries(n.vars??{}))yield[`${t}.${e}`,r]}function*EW(e){for(let t of Object.values(e.segments))for(let e of[t.template,t.bg,t.fg,t.when])e!==void 0&&(yield e);for(let t of R_(e.presets)){for(let n of $g(V_(e,t).node))n.when!==void 0&&(yield n.when);let n=H_(e,t);for(let e of nh){let t=n[e];rh(t)&&(yield t)}}for(let[,t]of TW(e))t.kind===`template`&&(yield t.template),s_(t)&&`key`in t.cache&&(yield t.cache.key);for(let t of Object.values(e.actions))`copy`in t&&(yield t.copy),`open`in t&&(yield t.open),`preset`in t&&t.preset===`delete`&&(yield t.name)}function DW(e,t){return e===t||t.startsWith(`${e}.`)||e.startsWith(`${t}.`)}function OW(e,t){let n=new Set,r=new Set,i=new Set;for(let e of EW(t)){for(let r of lv(e,t.helpers).keys())n.add(r);for(let{name:n}of pv(e,t.helpers))r.add(n);for(let n of mv(e,t.helpers))i.add(n)}for(let[,e]of TW(t))if(s_(e)&&`depends_on`in e.cache)for(let t of e.cache.depends_on)n.add(t);let a=new Set(r);for(let e of r){let n=t.actions[e];if(n!==void 0&&`do`in n)for(let e of n.do)a.add(e)}let o=new Set,s=new Set;for(let e of a){let n=t.actions[e];if(n!==void 0&&(`set`in n&&o.add(n.set),`insertSegment`in n&&s.add(n.insertSegment),`insertSegmentFrom`in n&&Array.isArray(n.insertSegmentFrom)))for(let e of n.insertSegmentFrom)s.add(e)}for(let e of R_(t.presets))for(let n of $g(V_(t,e).node))n.kind===`segment`&&s.add(n.name);let c=(e,t)=>[...n].some(t=>DW(t,e))||t.kind===`state`&&o.has(t.key),l=e=>[...e].filter(e=>!iD(e)),u=(e,t,n)=>l(t).filter(e=>!n(e)).map(t=>({kind:e,name:t})),d=new Map(TW(e));return[...u(`variable`,d.keys(),e=>c(e,d.get(e))),...u(`action`,Object.keys(e.actions??{}),e=>a.has(e)),...u(`helper`,Object.keys(e.helpers??{}),e=>i.has(e)),...u(`segment`,Object.keys(e.segments??{}),e=>s.has(e))]}var kW=class{kind=`box`;cell;lastChangedAt;constructor(e,t,n){this.name=e,this.type=t,FW(e,t,n,`initial value`),this.cell=Cv.observable.box(n,{deep:!1}),this.lastChangedAt=Date.now()}read(){return this.cell.get()}set(e){FW(this.name,this.type,e,`set value`),!Object.is(this.cell.get(),e)&&(this.cell.set(e),this.lastChangedAt=Date.now())}lastUpdatedMs(){return this.lastChangedAt}},AW=class{kind=`computed`;cell;constructor(e,t,n){if(this.name=e,this.type=t,this.cell=(0,Cv.computed)(()=>{let e=n();return FW(this.name,this.type,e,`computed result`),e},{keepAlive:!0}),typeof this.cell.suspend_!=`function`)throw TypeError(`Variable "${e}": this MobX's computed has no suspend_; release() cannot unsubscribe it`);if(typeof this.cell.keepAlive_!=`boolean`)throw TypeError(`Variable "${e}": this MobX's computed has no keepAlive_ flag; release() cannot lift it`)}read(){return this.cell.get()}release(){this.cell.keepAlive_=!1,this.cell.suspend_()}lastUpdatedMs(){return null}},jW=class{kind=`document`;cell;lastChangedAt;constructor(e,t){this.name=e,this.cell=Cv.observable.box(PW(t),{deep:!1}),this.lastChangedAt=Date.now()}read(){return this.cell.get()}set(e){let t=PW(e);NW(this.cell.get(),t)||(this.cell.set(t),this.lastChangedAt=Date.now())}lastUpdatedMs(){return this.lastChangedAt}};function MW(e){return JSON.stringify(e)}function NW(e,t){return MW(e)===MW(t)}function PW(e){return e.kind===`ok`?{kind:`ok`,value:wv(e.value)}:e}function FW(e,t,n,r){let i=Tv(n);if(i!==t)throw TypeError(`Variable "${e}": ${r} type ${i} does not match declared type ${t}`)}var IW=class{nodes=Cv.observable.map(void 0,{deep:!1});defineBox(e,t,n){this.declare(e,new kW(e,t,n))}defineDocument(e,t){this.declare(e,new jW(e,t))}defineComputed(e,t,n){let r=e=>this.read(e);this.declare(e,new AW(e,t,()=>n(r)))}read(e){return this.requireVar(e).read()}readDocument(e){let t=this.requireNode(e);if(t.kind!==`document`)throw TypeError(`Variable "${e}" is a ${t.kind}, not a document`);return t.read()}setDocument(e,t){let n=this.requireNode(e);if(n.kind!==`document`)throw TypeError(`Variable "${e}" is a ${n.kind}, not a document (use defineDocument to create one)`);(0,Cv.runInAction)(()=>n.set(t))}setBox(e,t){let n=this.requireNode(e);if(n.kind!==`box`)throw TypeError(`Variable "${e}" is a ${n.kind}, not a box (use defineBox to create a settable variable)`);(0,Cv.runInAction)(()=>n.set(t))}runInAction(e){(0,Cv.runInAction)(e)}has(e){return this.nodes.has(e)}getType(e){return this.requireVar(e).type}getKind(e){return this.requireNode(e).kind}changeKey(e){let t=this.requireNode(e);if(t.kind===`document`)return MW(t.read());try{return String(t.read())}catch(e){return`failed:${e instanceof Error?e.message:String(e)}`}}getNode(e){let t=this.requireNode(e);return t.kind===`document`?{name:t.name,kind:t.kind,read:()=>t.read(),lastUpdatedMs:()=>t.lastUpdatedMs()}:{name:t.name,type:t.type,kind:t.kind,read:()=>t.read(),lastUpdatedMs:()=>t.lastUpdatedMs()}}names(){return[...this.nodes.keys()]}dispose(){if(this.disposed)return 0;this.disposed=!0;let e=0;return(0,Cv.runInAction)(()=>{for(let t of this.nodes.values())t instanceof AW&&(t.release(),e++)}),e}disposed=!1;requireNode(e){let t=this.nodes.get(e);if(!t)throw ReferenceError(`Unknown variable "${e}"`);return t}requireVar(e){let t=this.requireNode(e);if(t.kind===`document`)throw TypeError(`Variable "${e}" is a document; read its fields by path (.${e}.<field>)`);return t}declare(e,t){if(this.disposed)throw Error(`Variable "${e}": cannot declare on a disposed store`);if(this.nodes.has(e))throw Error(`Variable "${e}" is already declared`);(0,Cv.runInAction)(()=>this.nodes.set(e,t))}};function LW(e,{plugins:t,config:n}){let{checkout:r,loaded:i,dropped:a,unreached:o}=t,s=r===null?`-`:`${r.git?`git`:`dir`}:${r.root}`,c=e=>{let t=FL(e),r=t===void 0?void 0:n.variables[LL(t)];return r?.kind===`file`?r.path:`none`};return`config load ${e.join(` < `)||`<default>`}: plugins loaded=${i.length} dropped=${a.length} unplaced=${o.length} checkout=${s}`+i.map(e=>` +${e} data=${c(e)}`).join(``)+a.map(e=>` -${e.path} (${e.reason})`).join(``)+o.map(e=>` ~${e.path} (${e.reason})`).join(``)}function RW(e,t){return`config disposed reason=${e.reason} released=${t} held=${e.held}`}function zW(e,t,n){return e+`\0`+t+`\0`+(n??``)}function BW(e,t){return new Set(R_(e.presets).filter(n=>V_(e,n).path===`root`?t.root!==void 0:t.presets?.[n]?.root!==void 0))}function VW(e,t){let n=new Map,{roots:r,loaded:i,dropped:a,unreached:o}=e.state.plugins;for(let t of[...fR(e.projectDir,e.cwd,e.configFile),...r,...i,...[...a,...o].map(e=>e.path)]){let{dir:e,name:r}=yv(t),i=n.has(e)?n.get(e):new Set;i?.add(r),n.set(e,i)}for(let e of r){let{dir:t,name:r,leaf:i}=yv(v.join(e,`_`));i&&r===`_`&&n.set(t,null)}return{files:t,dirs:[...n.entries()].sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>t===null?{path:e}:{path:e,filenames:[...t].sort()})}}function HW(e){return e.filter(Boolean).join(`
|
|
199
|
+
`)||null}function UW(e,t,n,r,i=()=>{}){let{layers:a,config:o,installed:s}=DR(t.layers,XR,{entered:i,warned:e=>n.push(...e)},{projectDir:t.projectDir,cwd:e});i(a.length===1?a[0].path:null);let c=a.at(-1)?.config??XR,l=a.find(e=>e.path===t.home)?.raw??{},u=new IW,d=new UE(u,o.globals.default_empty_value??``,r.gitService,r.sessionState),f;try{f=gW(o,d,{cwd:e}),n.push(...f.loadWarnings),UB(o),QN(o)}catch(e){throw d.dispose(),e}return{config:o,store:u,registry:d,compiled:f,neededInputPaths:Yz(o),lastRenderCellsBySegment:new Map,authoredRoots:BW(c,l),fileHeldSettings:kB(l),unused:[...new Map(a.flatMap(e=>OW(e.raw,c)).map(e=>[`${e.kind}:${e.name}`,e])).values()],plugins:{checkout:s.checkout,roots:s.roots,loaded:[...s.rendering.values()],dropped:[...s.dropped,...a.flatMap(e=>e.plugins.dropped)],unreached:s.unreached,reached:s.reached,rendering:s.rendering}}}function WW(e,t,n,r){let i=mR(e,t,n),a={layers:i.kind===`chain`?i.layers:[],home:i.home,projectDir:e},o=[yR(e,t),_R(i)],s,c=null;try{s=UW(t,a,o,r,e=>{c=e})}catch(e){return e instanceof YE&&o.push(...e.warnings),{layers:a.layers,home:a.home,failedFile:c,warning:HW(o),state:null,error:e instanceof YE||e instanceof Error?e.message:String(e)}}return{layers:a.layers,home:a.home,warning:HW(o),state:s,error:null}}function GW(e,t,n){return UW(e,{layers:[],home:``,projectDir:t},[],n)}var KW=class{entries=new Map;holds=new Map;deps;log;maxEntries;observers;constructor(e,t={}){this.deps=e,this.log=e.log??Gt,this.maxEntries=t.maxEntries??256,this.observers=t.observers??{}}getOrCreate(e,t,n){let r=zW(e,t,n),i=this.entries.get(r);if(i)return this.entries.delete(r),this.entries.set(r,i),i;let a=WW(e,t,n,this.deps);a.state!==null&&this.log(`info`,LW(a.layers,a.state));let o={projectDir:e,cwd:t,configFile:n,configLayers:[],configHome:``,failedFile:null,lastError:a.error,lastWarning:a.warning,state:a.state??GW(t,e,this.deps),watcher:null,watcherKey:null};if(this.serve(o.state),this.entries.set(r,o),this.entries.size>this.maxEntries){let e=this.entries.entries().next().value;if(e!==void 0){let[t,n]=e;n.watcher?.release(),this.entries.delete(t),this.retire(n.state,`evict`)}}return this.refreshWatcher(o,a),this.observers.onReload?.(o),o}hold(e,t,n){let r=this.getOrCreate(e,t,n),{state:i}=r,a=this.holdOf(i);a.holders++;let o=!1;return{entry:r,state:i,[Symbol.dispose]:()=>{if(o)throw Error(`render-cache hold released twice`);o=!0,a.holders--,this.reclaim(i,a)}}}get stats(){let e=0,t=0;for(let n of this.holds.values())n.holders>0&&e++,n.retired!==null&&t++;return{size:this.entries.size,held:e,retired:t}}serve(e){this.holds.set(e,{holders:0,retired:null})}holdOf(e){let t=this.holds.get(e);if(t===void 0)throw Error(`render-cache state never served`);return t}retire(e,t){let n=this.holdOf(e);n.retired={reason:t,held:n.holders},this.reclaim(e,n)}reclaim(e,t){t.retired===null||t.holders>0||(this.holds.delete(e),this.log(`info`,RW(t.retired,e.registry.dispose())))}reload(e,t,n){this.reloadInto(this.getOrCreate(e,t,n))}reloadInto(e){let t=WW(e.projectDir,e.cwd,e.configFile,this.deps);if(e.lastWarning=t.warning,e.lastError=t.error,t.state!==null){this.log(`info`,LW(t.layers,t.state));let n=e.state;e.state=t.state,this.serve(t.state),this.retire(n,`reload`)}this.refreshWatcher(e,t),this.observers.onReload?.(e)}refreshWatcher(e,t){e.configLayers=t.layers,e.configHome=t.home,e.failedFile=t.error===null?null:t.failedFile;let n=VW(e,t.layers),r=`config:${e.projectDir}:${e.cwd}:${e.configFile??``}:${JSON.stringify(n)}`;e.watcher!==null&&e.watcherKey===r||(e.watcher?.release(),e.watcherKey=r,e.watcher=this.deps.watchers.acquire(r,n,()=>this.onConfigChanged(e)))}onConfigChanged(e){this.log(`info`,`config change detected for entry projectDir=${e.projectDir} cwd=${e.cwd}`),this.reloadInto(e)}get size(){return this.entries.size}firstState(){return this.entries.values().next().value?.state??null}};const qW=16384;var JW=class e{startedAt=new Date;requestsTotal=0;requestsErrored=0;requestsTimedOut=0;inFlight=0;watchersOpened=0;watchersClosed=0;watchersEvicted=0;subprocessTotal=0;subprocessInFlight=0;subprocessCount=new Map;subprocessHistogram=new Map;subprocessHistogramRotator=new Map;rollingTimestamps=[];rollingHead=0;launchStats={onStart:e=>{this.subprocessTotal++,this.subprocessInFlight++,this.subprocessCount.set(e,(this.subprocessCount.get(e)??0)+1),this.recordRollingNow()},onEnd:(e,t)=>{this.subprocessInFlight=Math.max(0,this.subprocessInFlight-1),this.recordDuration(e,t)}};recordRollingNow(){let e=Date.now();if(this.rollingTimestamps.length<qW){this.rollingTimestamps.push(e);return}this.rollingTimestamps[this.rollingHead]=e,this.rollingHead=(this.rollingHead+1)%qW}recordDuration(e,t){let n=this.subprocessHistogram.get(e);if(n||(n=[],this.subprocessHistogram.set(e,n)),n.length<16){n.push(t);return}let r=(this.subprocessHistogramRotator.get(e)??0)%16;n[r]=t,this.subprocessHistogramRotator.set(e,r+1)}snapshotSubprocesses(){let e=Date.now()-6e4,t=0;for(let n of this.rollingTimestamps)n>=e&&t++;let n={};for(let[e,t]of this.subprocessCount)t>0&&(n[e]=t);let r={},i={};for(let[e,t]of this.subprocessHistogram){if(t.length===0)continue;let n=[...t].sort((e,t)=>e-t),a=Math.floor(n.length*.5),o=Math.min(n.length-1,Math.floor(n.length*.99)),s=n[a],c=n[o];s!==void 0&&(r[e]=s),c!==void 0&&(i[e]=c)}return{total:this.subprocessTotal,inFlight:this.subprocessInFlight,lastMinute:t,byCategory:n,p50DurationMs:r,p99DurationMs:i}}static referenceSnapshot(){return new e().snapshot({gitCache:{size:0,hits:0,misses:0,invalidations:0,watchers:0},usageCache:{size:0,hits:0,misses:0,sweeps:0},renderCache:{size:0,held:0,retired:0},effectCache:{sessions:0,effects:0},sessionState:{sessions:0,observers:0,revision:0},frameFeeds:{feeds:0,subscribers:0,drawn:0,pushed:0,refused:0,lookups:0,found:0},watchersActive:0,handlerProbes:[],clients:[],bundle:`/`,daemon:{pid:0,rss:0,rssLimit:0,postMortems:{kind:`ok`,value:[]}}})}snapshot(e){let t=process.memoryUsage();return{pid:process.pid,version:Ft,sourceDigest:Pg(),protocolVersion:3,startedAt:this.startedAt.toISOString(),uptimeSec:Math.floor((Date.now()-this.startedAt.getTime())/1e3),rssBytes:t.rss,heapUsedBytes:t.heapUsed,heapTotalBytes:t.heapTotal,externalBytes:t.external,arrayBuffersBytes:t.arrayBuffers,requests:{total:this.requestsTotal,errored:this.requestsErrored,timedOut:this.requestsTimedOut,inFlight:this.inFlight},gitCache:e.gitCache,usageCache:e.usageCache,renderCache:e.renderCache,effectCache:e.effectCache,sessionState:e.sessionState,frameFeeds:e.frameFeeds,watchers:{active:e.watchersActive,opened:this.watchersOpened,closed:this.watchersClosed,evicted:this.watchersEvicted},subprocesses:this.snapshotSubprocesses(),nextRestartReason:e.nextRestartReason??null,handlerProbes:e.handlerProbes,clients:e.clients,bundle:e.bundle,daemon:e.daemon}}};function YW(e,t,n){let r=(r,i,a)=>{let o=i.filter(t).map(t=>({key:t,before:e.get(r,t)}));a();for(let{key:t,before:i}of o)n(r,t,i,e.get(r,t))};return{get:(t,n)=>e.get(t,n),revision:t=>e.revision(t),set:(t,n,i)=>r(t,[n],()=>e.set(t,n,i)),setBatch:(t,n)=>r(t,n.map(e=>e.key),()=>e.setBatch(t,n)),clear:(t,n)=>r(t,[n],()=>e.clear(t,n))}}const XW={load:()=>({}),save:()=>{},flush:()=>{}};var ZW=class{sessions;storage;head=0;atom=(0,Cv.createAtom)(`SessionState`);constructor(e=XW,t=256){this.maxSessions=t,this.storage=e,this.sessions=new Map,this.hydrateFromStorage()}useStorage(e){this.storage=e,this.hydrateFromStorage()}hydrateFromStorage(){this.sessions=new Map(Object.entries(this.storage.load()).map(([e,t])=>[e,{values:new Map(Object.entries(t)),revision:++this.head}])),this.evictOldest(),this.persist()}get(e,t){this.atom.reportObserved();let n=this.sessions.get(e);return n?(this.touch(e,n),n.values.get(t)??null):null}revision(e){return this.atom.reportObserved(),this.sessions.get(e)?.revision??0}observers(){return this.atom.observers_?.size??0}latestRevision(){return this.head}size(){return this.sessions.size}set(e,t,n){this.setBatch(e,[{key:t,value:n}])}setBatch(e,t){t.length!==0&&(0,Cv.runInAction)(()=>{let n=this.sessions.get(e)??{values:new Map,revision:0};t.some(({key:e,value:t})=>n.values.get(e)!==t)&&(n.revision=++this.head);for(let{key:e,value:r}of t)n.values.set(e,r);this.touch(e,n),this.evictOldest(),this.persist(),this.atom.reportChanged()})}clear(e,t){(0,Cv.runInAction)(()=>{let n=this.sessions.get(e);n&&(n.values.delete(t)&&(n.revision=++this.head),n.values.size===0?this.sessions.delete(e):this.touch(e,n)),this.persist(),this.atom.reportChanged()})}prune(e){(0,Cv.runInAction)(()=>{for(let t of this.sessions.keys())e.has(t)||this.sessions.delete(t);this.persist(),this.atom.reportChanged()})}touch(e,t){this.sessions.delete(e),this.sessions.set(e,t)}evictOldest(){let e=this.sessions.size-this.maxSessions;if(!(e<=0)){for(let t of this.sessions.keys())if(this.sessions.delete(t),--e===0)break}}flush(){this.storage.flush()}persist(){this.storage.save(this.serialize())}serialize(){let e=Object.create(null);for(let[t,{values:n}]of this.sessions)e[t]=Object.fromEntries(n);return e}};function QW(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;for(let t of Object.values(e)){if(typeof t!=`object`||!t||Array.isArray(t))return!1;for(let e of Object.values(t))if(typeof e!=`string`)return!1}return!0}var $W=class{timer=null;pending=null;constructor(e,t=500,n=Gt){this.filePath=e,this.debounceMs=t,this.logger=n}load(){let e;try{e=s.readFileSync(this.filePath,`utf8`)}catch(e){let t=e.code;return t!==`ENOENT`&&this.logger(`warn`,`session-state read failed (${t}); starting empty`),{}}try{let t=JSON.parse(e);return QW(t)?t:(this.logger(`warn`,`session-state load: unexpected shape, starting empty`),{})}catch{return this.logger(`warn`,`session-state load: corrupt JSON, starting empty`),{}}}save(e){this.pending=e,!this.timer&&(this.timer=setTimeout(()=>this.flush(),this.debounceMs),this.timer.unref())}flush(){if(this.timer&&=(clearTimeout(this.timer),null),this.pending===null)return;let e=this.pending;try{s.mkdirSync(v.dirname(this.filePath),{recursive:!0});let t=`${this.filePath}.tmp`;s.writeFileSync(t,JSON.stringify(e),{mode:384}),s.chmodSync(t,384),s.renameSync(t,this.filePath),this.pending=null}catch(e){this.logger(`warn`,`session-state save failed: ${e.message}`)}}};const eG={default_empty_value:`string`,default_separator:`string`,palette:`string`,style:`string`,effect:`string`,preset:`string`,endcaps:`string`,variation:`string`,shade:`string`,autoWrap:`boolean`,padding:`number`,updateNotice:`boolean`,transitions:`boolean`,experimentalBand:`boolean`,experimentalStatusline:`boolean`,experimentalPane:`boolean`,colorCompatibility:`string`,menuGlyph:`string`},tG=new Set([`1`,`true`]),nG=new Set([`0`,`false`,``]);function rG(e,t){let n=OG(e),r=n.scope===`segment-palette`?`string`:eG[n.field];if(r===`string`)return JSON.stringify(t);if(r===`number`){let n=Number(t);if(!Number.isFinite(n))throw Error(`persistValueText: "${e}" expects a number, got "${t}"`);return String(n)}if(tG.has(t))return`true`;if(nG.has(t))return`false`;throw Error(`persistValueText: "${e}" expects boolean-ish (1, 0, true, false), got "${t}"`)}function iG(e){try{return s.readFileSync(e,`utf8`)}catch(e){if(e.code===`ENOENT`)return null;throw e}}function aG(e,t,n){try{if(t===null){s.rmSync(e,{force:!0});return}s.mkdirSync(v.dirname(e),{recursive:!0}),Ve(e,t)}catch(t){let r=`config write failed (${e}): ${t.message}`;throw n(`error`,r),Error(r)}}function oG(e){return/^\s*$/.test(e)?null:Lr(e)}function sG(e,t){return e!==null&&zr(e,t)!==void 0}function cG(e){if(e.kind===`segment`)return e.when===void 0?e.name:{seg:e.name,when:e.when};if(e.kind===`container`){let{kind:t,direction:n,children:r,...i}=e;return{[n===`horizontal`?`h`:`v`]:r.map(cG),...i}}return e}function lG(e){if(!O_(e))return cG(e);let{rows:t,...n}=e;return{rows:Object.fromEntries(Object.entries(t).map(([e,t])=>[e,cG(t)])),...n}}const uG=JR,dG=uG.segments,fG=uG.presets,pG=uG.root;function mG(e,t,n,r){if(!sG(e,t)&&n===void 0)throw new q(`cannot edit ${r}: neither the config file nor the bundled default declares ${t.join(`.`)}`)}function hG(e,t){let n=KO(t);return t.scope===`segment-palette`&&mG(e,[`segments`,t.segment],dG[t.segment],n.join(`.`)),n}function gG(e){return Lr(qr(e))}function _G(){return Object.entries(pG.rows).map(([e,t])=>{let n=cG(t);return{path:[`root`],fragment:gG({rows:{[e]:n}}),unit:{path:[`root`,`rows`,e],value:n}}})}function vG(e,t){let n=e===null?void 0:zr(e,t);return n===void 0?null:{path:t,fragment:n,unit:null}}function yG(e,t){if(t===void 0)return null;let n=lG(t);return{path:e,fragment:gG(n),unit:{path:e,value:n}}}function bG(e,t){let n=[`presets`,t],r=[...n,`root`],i=fG[t];mG(e,n,i,r.join(`.`));let a=vG(e,r)??yG(r,i?.root);return a!==null&&mi(a.fragment)?a:null}function xG(e,t){let n=pi(t.fragment);return n===null?new Map([[`#`,{path:t.path,unit:t.unit,node:t.fragment}]]):new Map([...e,...n.map(e=>[e.key,{path:[...t.path,`rows`,e.key],unit:t.unit,node:e.value}])])}function SG(e,t){return[..._G(),vG(e,[`root`]),bG(e,t)].filter(e=>e!==null).reduce(xG,new Map)}function CG(e,t,n){for(let{node:r,...i}of SG(e,t).values())if(gi(r,n))return i;throw new q(`${wG(e,t).join(`.`)} holds no placement "${n}" — the bar you clicked is stale (it reloads on the next render), or the action names a placement the layout never held`)}function wG(e,t){return bG(e,t)?.path??[`root`]}function TG(e,t){return t.scope===`preset-root`?wG(e,t.preset):KO(t)}function EG(e,{unit:t}){return t===null?e:si(e,t.path,qr(t.value),Gr)}function DG(e){let t=GO(e);if(t===null)throw Error(`"${e}" is not a valid persist target`);return t}function OG(e){let t=DG(e);if(t.scope===`preset-root`)throw Error(`"${e}" names a layout, not a value`);return t}function kG(e,t,n,r,i){i(t,n,BG(t,r)),aG(t.path,r,e.logger),e.record(t.path,n,r)}function AG(e,t,n){let r=NG(e,t,n);if(r.length>0)throw new q(`refused: ${e.above.join(`, `)} sets ${r.join(`, `)} over ${e.path}, so this click would change nothing on the bar — edit it there`)}const jG=()=>{};function MG(e,t){try{return t()}catch(t){throw!(t instanceof q)||e.above.length===0?t:new q(`${t.message} — or it is declared by ${e.above.join(`, `)}, which the bar does not edit`)}}function NG(e,t,n){let r=PG(e,t);if(r===null)return[];let i=new Set(RG(LG(r),LG(n)));return RG(IG(e,r),IG(e,n)).filter(e=>!i.has(e))}function PG(e,t){try{return FG(e,t)}catch(e){if(e instanceof YE)return null;throw e}}function FG(e,t){return DR(t===null?e.above:[e.path,...e.above],XR,{entered:()=>{},warned:()=>{}},{projectDir:e.projectDir,cwd:e.cwd},n=>n===e.path&&t!==null?t:s.readFileSync(n,`utf8`))}function IG(e,t){let[n]=t.layers;return n?.path===e.path?n.config:t.base}function LG(e){return e.layers.at(-1)?.config??e.base}function RG(e,t,n=``){return!zG(e)||!zG(t)?JSON.stringify(e)===JSON.stringify(t)?[]:[n]:[...new Set([...Object.keys(e),...Object.keys(t)])].flatMap(r=>RG(e[r],t[r],n===``?r:`${n}.${r}`))}function zG(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function BG(e,t){try{return FG(e,t)}catch(e){throw e instanceof YE?new q(`refused: the config file would not load after this click — ${e.message}`):e}}function VG(e,t){let n=OG(t),r=oG(iG(e)??``),i=r===null?void 0:zr(r,KO(n));return i!==void 0&&`value`in i?i.value:void 0}function HG(e,t,n){UG(e,t,n,[])}function UG(e,t,n,r){let i=iG(t.path),a=n.reduce((e,[t,n])=>si(e,hG(oG(e),OG(t)),rG(t,n),Gr),i??``);kG(e,t,i,MG(t,()=>WG(a,t.path,r,e=>e)),AG)}function WG(e,t,n,r){return n.reduce((e,{preset:n,id:i,setting:a,value:o})=>{let s=r(e,n,i),c=CG(oG(s),n,i),l=bi(EG(s,c),c.path,i,a,qr(o));if(l===null)throw new q(`${c.path.join(`.`)} in ${t} has no placement "${i}" — the bar you clicked is stale (it reloads on the next render)`);return l},e)}function GG(e,t,n){let r=oG(e),i=[`presets`,t,`root`];for(let[a,{path:o,unit:s,node:c}]of SG(r,t)){if(!gi(c,n))continue;if(i.every((e,t)=>o[t]===e))return e;let l=s===null?Vr(e,c):qr(s.value);if(a!==`#`)return si(e,[...i,`rows`,a],l,Gr);if(bG(r,t)!==null)throw new q(`cannot give preset "${t}" its own copy of ${o.join(`.`)}: it already stages rows of its own over that tree`);return si(e,i,l,Gr)}return e}function KG(e,t){return li(e,t,t[0]===`presets`&&t.length>2&&!QR(t[1])?2:0)}function qG(e,t,n){let r=n.map(DG),i=iG(t.path);if(i===null)return;let a=r.reduce((e,t)=>KG(e,TG(oG(e),t)),i);a!==i&&kG(e,t,i,a,jG)}function JG(e){let t=e===null?void 0:zr(e,[`presets`]);return t?.kind===`object`?t.entries.map(e=>e.key):[]}function YG(e,t){let n=new Set([...ZR,...JG(e),...t.above.flatMap(e=>Object.keys(Ar.default.parse(s.readFileSync(e,`utf8`)).presets??{}))].map(JE));return Array.from({length:n.size+1},(e,t)=>`custom-${t+1}`).find(e=>!n.has(JE(e)))}function XG(e,t,n,r,i,a){let o=iG(t.path),s=oG(o??``),c=YG(s,t),l=[`presets`,c],u=MG(t,()=>bG(s,n)),d=[...u===null?[]:[[[...l,`root`],u.unit===null?Vr(o??``,u.fragment):qr(u.unit.value)]],...Object.keys(r).length===0?[]:[[[...l,`globals`],qr(r)]]],f=i.map(([e,t])=>{let n=WO(c,e);return[hG(s,OG(n)),rG(n,t)]}),p=[...d,...f].reduce((e,[t,n])=>si(e,t,n,Gr),si(o??``,l,`{}`,Gr));return kG(e,t,o,MG(t,()=>WG(p,t.path,a.map(e=>({...e,preset:c})),GG)),AG),c}function ZG(e,t,n,r){let i=iG(t.path);kG(e,t,i,si(i??``,[`themeDefaults`,n],qr(r),Gr),AG)}function QG(e,t,n){if(QR(n))throw new q(`cannot delete preset "${n}": it is bundled — reset its settings instead`);let r=[`presets`,n],i=iG(t.path),a=oG(i??``);if(i===null||a===null||zr(a,r)===void 0)throw new q(`cannot delete preset "${n}": ${t.path} declares no ${r.join(`.`)} — the bar you clicked is stale; it reloads on the next render`);let o=zr(a,[`globals`,`preset`]);kG(e,t,i,[r,...o?.kind===`string`&&o.value===n?[[`globals`,`preset`]]:[]].reduce((e,t)=>KG(e,t),i),jG)}function $G(e,t,n,r){let i=DG(n);if(i.scope!==`preset-root`)throw Error(`"${n}" is not a "presets.<name>.root" target`);let a=iG(t.path),o=r.op===`remove`?r.target:r.anchor,s=MG(t,()=>CG(oG(a??``),i.preset,o)),c=EG(a??``,s),{after:l,placed:u}=eK(c,s.path,r,()=>{let e=BG(t,c).config;return R_(e.presets).map(t=>V_(e,t).node)});if(l===null)throw new q(`${s.path.join(`.`)} in ${t.path} has no placement "${o}" — the bar you clicked is stale (it reloads on the next render), or the action names a placement the layout never held`);return kG(e,t,a,l,AG),u}function eK(e,t,n,r){switch(n.op){case`remove`:return{after:vi(e,t,n.target),placed:null};case`insert`:{let i=zN(n.segment,n.anchor,r());return{after:yi(e,t,i,n.anchor,n.relation),placed:i}}}}const tK={load:()=>({}),save:()=>{}},nK=new Set(Va.map(e=>e.sessionKey)),rK=e=>nK.has(e)||e.startsWith(rk),iK=8*1024*1024,aK={past:[],future:[]},oK=e=>e.kind===`session`?`session:${e.key}`:`file:${e.file}`;var sK=class{state=new Map;constructor(e,t,n=tK){this.sessionState=e,this.logger=t,this.storage=n,this.state=new Map(Object.entries(n.load()))}useStorage(e){this.storage=e,this.state=new Map(Object.entries(e.load()))}depth(e){let{past:t,future:n,savepoint:r}=this.state.get(e)??aK;return{undo:t.length,redo:n.length,sinceEdit:r?.net.length??0}}history(e){return this.state.get(e)??aK}begin(){let e=new Map,t=(t,n)=>{let r=e.get(t)??new Map,i=r.get(oK(n));r.set(oK(n),i===void 0?n:{...n,before:i.before}),e.set(t,r)},n=new Map;return{sessionState:YW(this.sessionState,e=>rK(e)||e===`edit.mode`,(e,r,i,a)=>{if(r===`edit.mode`){let t=n.get(e);n.set(e,{before:t===void 0?i:t.before,after:a});return}t(e,{kind:`session`,key:r,before:i,after:a})}),file:(e,n,r,i)=>t(e,{kind:`file`,file:n,before:r,after:i}),commit:()=>{let t=new Map(e),r=new Map(n);e.clear(),n.clear();for(let e of new Set([...t.keys(),...r.keys()])){let n=[...t.get(e)?.values()??[]].filter(e=>e.before!==e.after),i=this.history(e),a=n.length===0?i:hK(i,n),o=r.get(e),s=o===void 0?a:yK(a,o);s!==i&&this.put(e,s)}}}}undo(e){let t=this.history(e),n=t.past.at(-1);if(n===void 0)throw new q(`undo: nothing to undo`);return this.apply(e,n,`before`,`undo`,_K(t,n)),n}rewind(e){let t=this.history(e),{savepoint:n}=t;if(n===void 0)throw new q(`rewind: edit mode has no savepoint — nothing to cancel`);let r=n.net.filter(t=>this.read(e,t)!==t.after),i=new Set(r.map(oK)),a=n.net.filter(e=>!i.has(oK(e))),o=uK(bK(vK(t,n),i));if(this.apply(e,a,`before`,`rewind`,{past:o,future:[],savepoint:{at:o.length,net:[],below:[]}}),r.length>0)throw new q(`rewind: ${r.map(SK).join(`, `)} changed since edit mode opened — kept as it is; everything else edit mode changed was put back`);return a}redo(e){let t=this.history(e),{past:n,future:r}=t,i=r.at(-1);if(i===void 0)throw new q(`redo: nothing to redo`);let a=[...n,i],o=uK(a);return this.apply(e,i,`after`,`redo`,{past:o,future:r.slice(0,-1),...fK(t.savepoint,a.length-o.length,i)}),i}apply(e,t,n,r,i){let a=n===`before`?`after`:`before`,o=t.filter(t=>this.read(e,t)!==t[a]);if(o.length>0){let t=new Set(o.map(oK)),{past:n,future:i,savepoint:a}=this.history(e);throw this.put(e,{past:bK(n,t),future:bK(i,t),...a!==void 0&&{savepoint:{at:bK([...n,...[...i].reverse()].slice(0,a.at),t).length,net:a.net.filter(e=>!t.has(oK(e))),below:bK(a.below,t)}}}),new q(`${r}: ${o.map(SK).join(`, `)} changed since that edit — refusing to overwrite it; this session's undo history no longer steps it`)}let s=[];try{for(let r of t)this.write(e,r,r[n]),s.push(r);this.put(e,i)}catch(t){try{for(let t of s.reverse())this.write(e,t,t[a])}catch(e){throw Error(`${t.message}; and putting the step back failed, so it is half-applied: ${e.message}`)}throw t}}read(e,t){return t.kind===`session`?this.sessionState.get(e,t.key):iG(t.file)}write(e,t,n){t.kind===`file`?aG(t.file,n,this.logger):n===null?this.sessionState.clear(e,t.key):this.sessionState.set(e,t.key,n)}put(e,t){let n=new Map(this.state);for(n.delete(e),(t.past.length>0||t.future.length>0||t.savepoint!==void 0)&&n.set(e,t);n.size>32||cK(n)>iK;){let[e,t]=n.entries().next().value;n.size>1?n.delete(e):t.past.length+t.future.length>0?n.set(e,lK(t)):(this.logger(`warn`,`settings-history: edit mode's changes for session ${e} exceed ${iK} bytes; cancel is no longer available`),n.delete(e))}this.storage.save(Object.fromEntries(n)),this.state=n}};function cK(e){let t=0;for(let{past:n,future:r,savepoint:i}of e.values())for(let e of[...n,...r,...i===void 0?[]:[i.net,...i.below]])for(let n of e)t+=(n.before?.length??0)+(n.after?.length??0);return t}function lK({past:e,future:t,savepoint:n}){return e.length>0?{past:e.slice(1),future:t,...fK(n,1,[])}:{past:e,future:t.slice(1),...fK(n,0,[])}}function uK(e){return e.slice(-50)}const dK=e=>e===ak.member;function fK(e,t,n){return e===void 0?{}:{savepoint:{at:Math.max(0,e.at-t),net:pK(e.net,n),below:e.below}}}function pK(e,t){let n=new Map(e.map(e=>[oK(e),e]));for(let e of t){let t=n.get(oK(e));n.set(oK(e),t===void 0?e:{...t,after:e.after})}return[...n.values()].filter(e=>e.before!==e.after)}const mK=e=>e.map(e=>({...e,before:e.after,after:e.before}));function hK(e,t){let n=[...e.past,t],r=uK(n),{savepoint:i}=e,a=i===void 0?0:Math.max(0,i.at-e.past.length);return{past:r,future:[],...fK(i&&{at:Math.min(i.at,e.past.length),net:i.net,below:[...gK(e.future,a),...i.below]},n.length-r.length,t)}}function gK(e,t){let n=Math.min(t,e.length);return e.slice(e.length-n).reverse()}function _K(e,t){return{past:e.past.slice(0,-1),future:uK([...e.future,t]),...fK(e.savepoint,0,mK(t))}}function vK(e,t){let{past:n,future:r}=e,i=n.slice(0,t.at);return[...i,...gK(r,t.at-i.length),...t.below]}function yK(e,t){if(dK(t.after)&&!dK(t.before))return{...e,savepoint:{at:e.past.length,net:[],below:[]}};if(!dK(t.after)&&dK(t.before)){let{past:t,future:n}=e;return{past:t,future:n}}return e}function bK(e,t){return e.map(e=>e.filter(e=>!t.has(oK(e)))).filter(e=>e.length>0)}function xK(e){return e.map(SK).join(`, `)}function SK(e){return e.kind===`session`?`session setting "${e.key}"`:e.file}function CK(e){if(typeof e!=`object`||!e)return!1;let t=e,n=e=>e===null||typeof e==`string`;return(t.kind===`session`&&typeof t.key==`string`||t.kind===`file`&&typeof t.file==`string`)&&n(t.before)&&n(t.after)}function wK(e){return Array.isArray(e)&&e.every(e=>Array.isArray(e)&&e.every(CK))}function TK(e){if(typeof e!=`object`||!e)return!1;let t=e;return Number.isInteger(t.at)&&t.at>=0&&Array.isArray(t.net)&&t.net.every(CK)&&wK(t.below)}function EK(e){if(typeof e!=`object`||!e)return!1;let t=e;return wK(t.past)&&wK(t.future)&&(t.savepoint===void 0||TK(t.savepoint))}function DK(e,t){let n=e=>e.kind===`file`||rK(e.key)?!0:(t.add(e.key),!1),r=e=>e.map(e=>e.filter(n)).filter(e=>e.length>0),{savepoint:i}=e,a=r(e.past),o=r(e.future);return i===void 0?{past:a,future:o}:{past:a,future:o,savepoint:{at:r(e.past.slice(0,i.at)).length,net:i.net.filter(n),below:r(i.below)}}}function OK(e,t){return{load:()=>{let n;try{n=s.readFileSync(e,`utf8`)}catch(e){let n=e.code;return n!==`ENOENT`&&t(`warn`,`settings-history read failed (${n}); starting empty`),{}}try{let e=JSON.parse(n);if(typeof e==`object`&&e&&!Array.isArray(e)&&Object.values(e).every(EK)){let n=new Set,r=Object.fromEntries(Object.entries(e).map(([e,t])=>[e,DK(t,n)]));return n.size>0&&t(`warn`,`settings-history load: dropped the changes to ${[...n].map(e=>`"${e}"`).join(`, `)}, no longer a setting`),r}}catch{}return t(`warn`,`settings-history load: unexpected shape, starting empty`),{}},save:n=>{try{s.mkdirSync(v.dirname(e),{recursive:!0}),Ve(e,JSON.stringify(n),384)}catch(e){let n=`settings-history write failed — the change landed but is not undoable: ${e.message}`;throw t(`error`,n),Error(n)}}}}const kK=e=>!rK(e)&&!sj(e)&&e!==`update.dismissed`;var AK=class{past=new Map;depth(e,t,n){return this.restorable(e,t,n).length}restorable(e,t,n){let r=new Map,i=n=>r.has(n)?r.get(n):t.get(e,n),a=[];for(let t of[...this.past.get(e)??[]].reverse())if(t.every(e=>i(e.key)===e.after&&(e.before===null||n.validate(e.key,e.before).ok))){a.unshift(t);for(let e of t)r.set(e.key,e.before)}return a}begin(e){let t=new Map;return{sessionState:YW(e,kK,(e,n,r,i)=>{let a=t.get(e)??new Map,o=a.get(n);a.set(n,{key:n,before:o?o.before:r,after:i}),t.set(e,a)}),commit:()=>{for(let[e,n]of t){let t=[...n.values()].filter(e=>e.before!==e.after);t.length>0&&this.push(e,t)}t.clear()}}}back(e,t,n){let r=this.past.get(e)??[],i=this.restorable(e,t,n),a=i.at(-1),o=r.length-i.length;if(a===void 0)throw this.put(e,i),new q(`back: nothing to go back to${o>0?` (${o} step(s) over a view since gone, discarded)`:``}`);return(0,Cv.runInAction)(()=>{let n=a.flatMap(({key:e,before:t})=>t===null?[]:[{key:e,value:t}]);n.length>0&&t.setBatch(e,n);for(let{key:n,before:r}of a)r===null&&t.clear(e,n)}),this.put(e,i.slice(0,-1)),{step:a,discarded:o}}push(e,t){let n=this.past.get(e)??[];this.put(e,[...n,t].slice(-20))}put(e,t){for(this.past.delete(e),t.length>0&&this.past.set(e,t);this.past.size>32;)this.past.delete(this.past.keys().next().value)}};const jK=`click.error`;function MK(e,t,n,r){let i={text:n,at:r,answered:!1};e.set(t,jK,JSON.stringify(i))}function NK(e,t,n){let r=PK(e,t);!(r?.at===n.at&&r.text===n.text)||r.answered||e.set(t,jK,JSON.stringify({...r,answered:!0}))}function PK(e,t){let n=e.get(t,jK);return n===null?null:IK(n)}function FK(e,t,n,r){let i=PK(e,t);return i===null?{kind:`none`}:n<i.at+5?{kind:`held`,error:i}:r===`request`&&!i.answered?{kind:`owed`,error:i}:{kind:`over`}}function IK(e){let t;try{t=JSON.parse(e)}catch{return null}if(typeof t!=`object`||!t)return null;let{text:n,at:r,answered:i}=t;return typeof n==`string`&&typeof r==`number`&&(i===void 0||typeof i==`boolean`)?{text:n,at:r,answered:i===!0}:null}const LK=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function RK(e,t){let n=e=>({kind:`failed`,reason:`${t} ${e}`}),r;try{r=JSON.parse(e)}catch(e){return n(`is not JSON: ${e.message}`)}if(!LK(r))return n(`is not an object`);for(let[e,t]of Object.entries(r)){if(!LK(t))return n(`holds ${JSON.stringify(e)} as something other than its sightings`);for(let[e,r]of Object.entries(t))if(!eA.includes(r))return n(`marks ${JSON.stringify(e)} ${JSON.stringify(r)}, not ${eA.join(` or `)}`)}return{kind:`ok`,value:r}}function zK(e,t,n,r){return{...e,[t]:{...e[t],[n]:r}}}function BK(e=v.join(Ue(),`doctor-marks.json`)){let t=()=>{let t;try{t=s.readFileSync(e,`utf8`)}catch(t){return t.code===`ENOENT`?{kind:`ok`,value:{}}:{kind:`failed`,reason:`${e}: ${t.message}`}}return RK(t,e)};return{read:t,record:(n,r,i)=>{let a=t();if(a.kind===`failed`)throw Error(`doctor: the mark book could not be read: ${a.reason}`);s.mkdirSync(v.dirname(e),{recursive:!0}),Ve(e,`${JSON.stringify(zK(a.value,n,r,i),null,2)}\n`)}}}var VK=class extends Error{constructor(e){super(`the doctor looked at ${e} less than a second ago — click again`),this.name=`DoctorBusy`}};const HK={pullRequests:e=>Qz(e).showPullRequest===!0,rateLimits:e=>Zz(e,`block`)||Zz(e,`weekly`),memento:e=>Zz(e,`memento`)};function UK(e,t){let n=new Map;for(let r of $g(V_(e,t).node)){if(r.kind!==`segment`)continue;let e=n.get(r.name)??[];r.when&&e.push(r.when),n.set(r.name,e)}let r=[...n.keys()].filter(t=>u_(e.segments[t])===`fail`),i=new Map(r.map(t=>[t,qz(e,t,n.get(t))])),a=e=>r.filter(t=>HK[e](i.get(t)));return{pullRequests:a(`pullRequests`),rateLimits:a(`rateLimits`),memento:a(`memento`)}}
|
|
200
200
|
/*!
|
|
201
201
|
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
202
202
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -224,9 +224,9 @@ print(json.dumps({"ceiling": "off" if ceiling == math.inf else ceiling,
|
|
|
224
224
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
225
225
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
226
226
|
*/
|
|
227
|
-
function
|
|
227
|
+
function WK(e,t){let n=e.slice(0,t).split(/\r?\n/);return[n.length,n.pop().length+1]}function GK(e,t,n){let r=e.split(/\r?\n/),i=``,a=(Math.log10(t+1)|0)+1;for(let e=t-1;e<=t+1;e++){let o=r[e-1];o&&(i+=e.toString().padEnd(a,` `),i+=`: `,i+=o,i+=`
|
|
228
228
|
`,e===t&&(i+=` `.repeat(a+n+2),i+=`^
|
|
229
|
-
`))}return i}var $=class e extends Error{line;column;codeblock;constructor(e,t){let[n,r]=
|
|
229
|
+
`))}return i}var $=class e extends Error{line;column;codeblock;constructor(e,t){let[n,r]=WK(t.toml,t.ptr),i=GK(t.toml,n,r);super(`Invalid TOML document: ${e}\n\n${i}`,t),this.line=n,this.column=r,this.codeblock=i}static x(t,n,r){throw new e(t,{toml:n.s,ptr:r??n.p})}};
|
|
230
230
|
/*!
|
|
231
231
|
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
232
232
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -254,7 +254,7 @@ function LK(e,t){let n=e.slice(0,t).split(/\r?\n/);return[n.length,n.pop().lengt
|
|
|
254
254
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
255
255
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
256
256
|
*/
|
|
257
|
-
function
|
|
257
|
+
function KK(e){let t=e.p,n=e.s.charCodeAt(e.p++),r=n,i=n===39,a=n===e.s.charCodeAt(e.p)&&n===e.s.charCodeAt(e.p+1);a&&((n=e.s.charCodeAt(e.p+=2))===10?e.p++:n===13&&e.s.charCodeAt(e.p+1)===10&&(e.p+=2));let o=``,s=e.p,c=0;for(;e.p<e.s.length;e.p++)if(n=e.s.charCodeAt(e.p),a&&(n===10||n===13&&e.s.charCodeAt(e.p+1)===10))c&&=3;else if(n<32&&n!==9||n===127)$.x(`control characters are not allowed in strings`,e);else if((!c||c===3)&&n===r&&(!a||e.s.charCodeAt(e.p+1)===r&&e.s.charCodeAt(e.p+2)===r)){if(a&&(e.s.charCodeAt(e.p+3)===r&&e.p++,e.s.charCodeAt(e.p+3)===r&&e.p++),!c){let t=e.s.slice(s,e.p);o=o?o+t:t}return e.p+=a?3:1,o}else if(!c)!i&&n===92&&(o+=e.s.slice(s,s=e.p),c=1);else if(c===1)if(n===120||n===117||n===85){let t=e.p++-1,r=0,i=n===120?2:n===117?4:8;for(let t=0;t<i;t++,e.p++){let t=e.s.charCodeAt(e.p),n=t>=48&&t<=57?t-48:t>=65&&t<=70?t-65+10:t>=97&&t<=102?t-97+10:-1;n<0&&$.x(`invalid non-hex character in unicode escape`,e),r=r<<4|n}(r<0||r>1114111||r>=55296&&r<=57343)&&$.x(`invalid unicode escape`,e,t),o+=String.fromCodePoint(r),s=e.p--,c=0}else a&&(n===32||n===9)?c=2:(n===98?o+=`\b`:n===116?o+=` `:n===110?o+=`
|
|
258
258
|
`:n===102?o+=`\f`:n===114?o+=`\r`:n===101?o+=`\x1B`:n===34?o+=`"`:n===92?o+=`\\`:$.x(`unrecognised escape sequence`,e),s=e.p+1,c=0);else n!==32&&n!==9&&(c===2&&$.x(`invalid escape: only line-ending whitespace may be escaped`,e,s),c=+(!i&&n===92),s=e.p);$.x(`unfinished string`,e,t)}
|
|
259
259
|
/*!
|
|
260
260
|
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
@@ -283,7 +283,7 @@ function zK(e){let t=e.p,n=e.s.charCodeAt(e.p++),r=n,i=n===39,a=n===e.s.charCode
|
|
|
283
283
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
284
284
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
285
285
|
*/
|
|
286
|
-
let
|
|
286
|
+
let qK=/^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i;var JK=class e extends Date{#e=!1;#t=!1;#n=null;constructor(e,t,n){let r=!0,i=!0,a=`Z`,o;if(typeof e==`string`)if(t)prep:{if(t<3){if(+e.slice(11,13)>23){e=``;break prep}t===2?(a=null,e+=`Z`):(o=e.charCodeAt(e.length-1))!==90&&o!==122&&(a=e.slice(e.length-6)),n&&(e=e.slice(0,10)+`T`+e.slice(11))}else t===4&&(e=+e.slice(0,2)>23?``:`0000-01-01T${e}Z`);r=t!==4,i=t!==3}else{let t=e.match(qK);t?(t[1]||(r=!1,e=`0000-01-01T${e}`),i=!!t[2],i&&e[10]===` `&&(e=e.replace(` `,`T`)),t[2]&&+t[2]>23?e=``:(a=t[3]||null,!a&&i&&(e+=`Z`))):e=``}super(e),isNaN(this.getTime())||(this.#e=r,this.#t=i,this.#n=a)}isDateTime(){return this.#e&&this.#t}isLocal(){return!this.#e||!this.#t||!this.#n}isDate(){return this.#e&&!this.#t}isTime(){return this.#t&&!this.#e}isValid(){return this.#e||this.#t}toISOString(){let e=super.toISOString();if(this.isDate())return e.slice(0,10);if(this.isTime())return e.slice(11,23);if(this.#n===null)return e.slice(0,-1);if(this.#n===`Z`||this.#n===`z`)return e;let t=this.#n.slice(1,3)*60+ +this.#n.slice(4,6);return t=this.#n[0]===`-`?t:-t,new Date(this.getTime()-t*6e4).toISOString().slice(0,-1)+this.#n}static wrapAsOffsetDateTime(t,n=`Z`){let r=new e(t);return r.#n=n,r}static wrapAsLocalDateTime(t){let n=new e(t);return n.#n=null,n}static wrapAsLocalDate(t){let n=new e(t);return n.#t=!1,n.#n=null,n}static wrapAsLocalTime(t){let n=new e(t);return n.#e=!1,n.#n=null,n}};
|
|
287
287
|
/*!
|
|
288
288
|
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
289
289
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -311,7 +311,7 @@ let BK=/^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[
|
|
|
311
311
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
312
312
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
313
313
|
*/
|
|
314
|
-
function
|
|
314
|
+
function YK(e,t=10){return t===16?e>47&&e<58||e>64&&e<71||e>96&&e<103:e>47&&e<48+t}function XK(e,t){return e===32||e===9||e===10||e===13||t&&(e===t||e===44)||e===35}function ZK(e,t){let n=e.p,r=e.s.charCodeAt(e.p);if(r===91||r===123){e.d--||$.x(`document contains excessively nested structures. aborting.`,e);let t=r===91?cq(e):sq(e);return e.d++,t}return r===34||r===39?KK(e):r===116?((e.s.charCodeAt(++e.p)!==114||e.s.charCodeAt(++e.p)!==117||e.s.charCodeAt(++e.p)!==101)&&$.x(`invalid value`,e,n),e.p++,!0):r===102?((e.s.charCodeAt(++e.p)!==97||e.s.charCodeAt(++e.p)!==108||e.s.charCodeAt(++e.p)!==115||e.s.charCodeAt(++e.p)!==101)&&$.x(`invalid value`,e,n),e.p++,!1):r===43||r===45?QK(e,e.p,e.s.charCodeAt(++e.p),44-r,t):e.s.charCodeAt(e.p+4)===45&&e.s.charCodeAt(e.p+7)===45?tq(e,r,t):e.s.charCodeAt(e.p+2)===58?nq(e,r,t):QK(e,e.p,r,0,t)}function QK(e,t,n,r,i){let a=n,o=0,s=!1;if(a===105)return(e.s.charCodeAt(++e.p)!==110||e.s.charCodeAt(++e.p)!==102)&&$.x(`invalid value`,e,t),e.p++,(r||1)/0;if(a===110)return(e.s.charCodeAt(++e.p)!==97||e.s.charCodeAt(++e.p)!==110)&&$.x(`invalid value`,e,t),e.p++,NaN;if(a===48){if(++e.p>=e.s.length||XK(a=e.s.charCodeAt(e.p),i))return e.bi===!0?0n:0;if(!r){if(a===120)return $K(e,t,16,i);if(a===98)return $K(e,t,2,i);if(a===111)return $K(e,t,8,i)}a===46?o=2:a===101||a===69?o=4:$.x(`illegal leading zero`,e,t)}else YK(a)||$.x(`invalid value`,e,t);for(;++e.p<e.s.length&&(a=e.s.charCodeAt(e.p),!XK(a,i));)o||=1,a===95?(o&1||$.x(`illegal underscore`,e),o+=11,s=!0):o===1&&a===46?o=2:(o===1||o===3)&&(a===101||a===69)?o=4:o===4&&(a===43||a===45)?o=6:YK(a)?o>9?o-=11:o&1||o++:$.x(`illegal character in numeric literal`,e);if(!o){let t=(n-48)*(r||1);return e.bi===!0?BigInt(t):t}o&1||$.x(`unfinished numeric value`,e,t);let c=e.s.slice(t,e.p);return s&&(c=c.replaceAll(`_`,``)),o>1?parseFloat(c):eq(e,c,10,t)}function $K(e,t,n,r){let i,a=1;for(;++e.p<e.s.length&&(i=e.s.charCodeAt(e.p),!XK(i,r));)i===95?(a&1&&$.x(`illegal underscore`,e),a=3):YK(i,n)?a&1&&a--:$.x(`illegal character in numeric literal`,e);a&1&&$.x(`unfinished numeric value`,e);let o=e.s.slice(t+2,e.p);return a&&(o=o.replaceAll(`_`,``)),eq(e,o,n,t)}function eq(e,t,n,r){if(e.bi!==!0)int:{let i=parseInt(t,n);if(!Number.isSafeInteger(i)){if(e.bi)break int;$.x(`integer value cannot be represented losslessly`,e,r)}return i}return BigInt(n===10?t:(n===2?`0b`:n===8?`0o`:`0x`)+t)}function tq(e,t,n){let r=e.p++,i;if(!YK(t)||!YK(e.s.charCodeAt(e.p++))||!YK(e.s.charCodeAt(e.p++))||!YK(e.s.charCodeAt(e.p++)))return QK(e,e.p=r,t,0,n);if(e.p+=5,YK(e.s.charCodeAt(e.p++))||$.x(`invalid date-time: date part is malformed`,e,r),e.p>=e.s.length||((t=e.s.charCodeAt(e.p))!==32||(i=!0,!YK(e.s.charCodeAt(e.p+1))))&&t!==84&&t!==116)return rq(e,e.s.slice(r,e.p),3,!1,r);if(e.s.charCodeAt(e.p+=3)!==58&&$.x(`invalid date-time: time part is malformed`,e,r),e.s.charCodeAt(e.p+=3)===58&&(e.p+=3),e.s.charCodeAt(e.p)===46)for(;YK(e.s.charCodeAt(++e.p)););if(t=e.s.charCodeAt(e.p)){if(t===90||t===122)return rq(e,e.s.slice(r,++e.p),1,i,r,`[+00:00]`);if(t===43||t===45)return rq(e,e.s.slice(r,e.p+=6),1,i,r,!e.ld&&`[`+e.s.slice(e.p-6,e.p)+`]`)}return rq(e,e.s.slice(r,e.p),2,i,r)}function nq(e,t,n){let r=e.p;if(!YK(t)||!YK(e.s.charCodeAt(++e.p)))return QK(e,--e.p,t,0,n);if(e.s.charCodeAt(e.p+=4)===58&&(e.p+=3),e.s.charCodeAt(e.p)===46)for(;YK(e.s.charCodeAt(++e.p)););return rq(e,e.s.slice(r,e.p),4,!1,r)}function rq(e,t,n,r,i,a){if(e.ld){let a=new JK(t,n,r);return a.isValid()||$.x(`invalid date`,e,i),a}try{switch(a&&(t+=a),n){case 1:return Temporal.ZonedDateTime.from(t);case 2:return Temporal.PlainDateTime.from(t);case 3:return Temporal.PlainDate.from(t);case 4:return Temporal.PlainTime.from(t)}}catch(t){$.x(t instanceof Error?t.message:``+t,e,i)}}
|
|
315
315
|
/*!
|
|
316
316
|
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
317
317
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -339,7 +339,7 @@ function HK(e,t=10){return t===16?e>47&&e<58||e>64&&e<71||e>96&&e<103:e>47&&e<48
|
|
|
339
339
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
340
340
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
341
341
|
*/
|
|
342
|
-
function
|
|
342
|
+
function iq(e){for(;e.p<e.s.length;e.p++){let t=e.s.charCodeAt(e.p);if(t===10)break;if(t===13&&e.s.charCodeAt(e.p+1)===10){e.p++;break}(t<32&&t!==9||t===127)&&$.x(`control characters are not allowed in comments`,e)}}function aq(e,t,n){let r;for(;e.p<e.s.length;){for(;e.p<e.s.length&&((r=e.s.charCodeAt(e.p))===32||r===9||!t&&(r===10||r===13&&e.s.charCodeAt(e.p+1)===10));)e.p++;if(n||r!==35)break;iq(e)}}
|
|
343
343
|
/*!
|
|
344
344
|
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
345
345
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -367,7 +367,7 @@ function ZK(e){for(;e.p<e.s.length;e.p++){let t=e.s.charCodeAt(e.p);if(t===10)br
|
|
|
367
367
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
368
368
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
369
369
|
*/
|
|
370
|
-
function
|
|
370
|
+
function oq(e,t=61){let n,r=0,i=[],a,o=e.s.charCodeAt(n=e.p);do if(o===t)return r||$.x(`unexpected end of key`,e),r===1&&i.push(e.s.slice(a,e.p)),e.p++,i;else o===46?(r||$.x(`illegal empty bare key`,e),r===1&&i.push(e.s.slice(a,e.p)),r=0):!r&&(o===34||o===39)?(o===e.s.charCodeAt(e.p+1)&&o===e.s.charCodeAt(e.p+2)&&$.x(`illegal quoted key: multiline strings are not allowed`,e),i.push(KK(e)),r=2,e.p--):o===32||o===9?r===1&&(i.push(e.s.slice(a,e.p)),r=2):r===2||o<48&&o!==45||o>57&&o<65||o>90&&o<97&&o!==95||o>122?$.x(`illegal character in key`,e):r||(r=1,a=e.p);while(o=e.s.charCodeAt(++e.p));$.x(`incomplete key-value: cannot find end of key`,e,n)}function sq(e){let t=e.p++,n=Object.create(null),r=new Set,i;for(;e.p<e.s.length;){if(aq(e),(i=e.s.charCodeAt(e.p))===125)return e.p++,n;let t,a=n,o=!1,s=e.p,c=oq(e);for(let n=0;n<c.length;n++){n&&(a=o?a[t]:a[t]=Object.create(null)),t=c[n],(o=Object.hasOwn(a,t))&&(typeof a[t]!=`object`||r.has(a[t]))&&$.x(`trying to redefine an already defined value`,e,s);let i=t===`__proto__`;if(e.uk&&(i||t===`constructor`)){a=e.uk!==1&&$.x(`document contains an unsafe property`,e,s);break}!o&&i&&Object.defineProperty(a,t,{enumerable:!0,configurable:!0,writable:!0})}o&&$.x(`trying to redefine an already defined value`,e,s),aq(e,!0,!0);let l=ZK(e,125);if(a&&typeof(a[t]=l)==`object`&&r.add(l),aq(e),(i=e.s.charCodeAt(e.p++))===125)return n;i!==44&&$.x(`expected comma or end of structure`,e,e.p-1)}$.x(`unfinished table`,e,t)}function cq(e){let t=e.p++,n=[],r;for(;e.p<e.s.length;){if(aq(e),(r=e.s.charCodeAt(e.p))===93)return e.p++,n;if(n.push(ZK(e,93)),aq(e),(r=e.s.charCodeAt(e.p++))===93)return n;r!==44&&$.x(`expected comma or end of structure`,e,e.p-1)}$.x(`unfinished array`,e,t)}
|
|
371
371
|
/*!
|
|
372
372
|
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
373
373
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -395,7 +395,7 @@ function $K(e,t=61){let n,r=0,i=[],a,o=e.s.charCodeAt(n=e.p);do if(o===t)return
|
|
|
395
395
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
396
396
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
397
397
|
*/
|
|
398
|
-
function
|
|
398
|
+
function lq(e,t,n,r,i){let a=n,o=r,s,c=!1,l;for(let n=0;n<t.length;n++){if(n){if(a=c?a[s]:a[s]=Object.create(null),o=(l=o[s]).c,i===0&&(l.t===1||l.t===2))return null;if(l.t===2){let e=a.length-1;a=a[e],o=o[e].c}}if(s=t[n],(c=Object.hasOwn(a,s))&&o[s]?.t===0&&o[s]?.d)return null;if(!c){let r=s===`__proto__`;if(e.uk&&(r||s===`constructor`))return!1;r&&(Object.defineProperty(a,s,{enumerable:!0,configurable:!0,writable:!0}),Object.defineProperty(o,s,{enumerable:!0,configurable:!0,writable:!0})),o[s]={t:n<t.length-1&&i===2?3:i,d:!1,i:0,c:Object.create(null)}}}if(l=o[s],l.t!==i&&!(i===1&&l.t===3)||(i===2&&(l.d||(l.d=!0,a[s]=[]),a[s].push(a=Object.create(null)),l.c[l.i++]=l={t:1,d:!1,i:0,c:Object.create(null)}),l.d))return null;if(l.d=!0,i===1)a=c?a[s]:a[s]=Object.create(null);else if(i===0&&c)return null;return[s,a,l.c]}function uq(e,t,n){(t===null||e.uk===2)&&$.x(t===null?`trying to redefine an already defined table or value`:`document contains an unsafe property`,e,n)}function dq(e,t={}){let n={s:e,p:0,d:t.maxDepth??1e3,bi:t.integersAsBigInt??!1,ld:t.useLegacyDate??!0,uk:t.unsafeKeyBehaviour===`throw`?2:+(t.unsafeKeyBehaviour===`drop`)},r=Object.create(null),i=Object.create(null),a,o=!1,s=r,c=i;for(e.charCodeAt(0)===65279&&n.p++,aq(n);n.p<e.length;){if(e.charCodeAt(n.p)===91){let t=e.charCodeAt(++n.p)===91;a=n.p+=+t,o=!1;let l=oq(n,93);t&&(e.charCodeAt(n.p)!==93&&$.x(`expected end of table array declaration`,n),n.p++);let u=lq(n,l,r,i,t?2:1);u?(c=u[2],s=u[1]):(uq(n,u,a),o=!0)}else{a=n.p;let e=lq(n,oq(n),s,c,0);!e&&!o&&uq(n,e,a),aq(n,!0,!0);let t=ZK(n,void 0);e&&!o&&(e[1][e[0]]=t)}aq(n,!0),n.p<e.length&&(a=e.charCodeAt(n.p))!==10&&(a!==13||e.charCodeAt(n.p+1)!==10)&&$.x(`each key-value declaration must be followed by an end-of-line`,n),aq(n)}return r}``.isWellFormed;
|
|
399
399
|
/*!
|
|
400
400
|
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
401
401
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -423,7 +423,7 @@ function nq(e,t,n,r,i){let a=n,o=r,s,c=!1,l;for(let n=0;n<t.length;n++){if(n){if
|
|
|
423
423
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
424
424
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
425
425
|
*/
|
|
426
|
-
const
|
|
426
|
+
const fq=e=>e.codePointAt(0).toString(16).toUpperCase(),pq=String.raw`
|
|
427
427
|
ObjC.import("AppKit");
|
|
428
428
|
ObjC.import("CoreText");
|
|
429
429
|
function lacksOf(font, points) {
|
|
@@ -470,45 +470,45 @@ function run(argv) {
|
|
|
470
470
|
: iterm(argv[1], points),
|
|
471
471
|
);
|
|
472
472
|
}
|
|
473
|
-
`;function
|
|
474
|
-
`).filter(e=>e!==``).map(e=>{let t=e.indexOf(` `);return t<=0?null:{family:e.slice(0,t),ranges:e.slice(t+1).split(/\s+/).filter(e=>e!==``).map(e=>{let[t,n=t]=e.split(`-`).map(e=>parseInt(e,16));return[t,n]})}});if(n.length===0||n.some(e=>e===null))return{kind:`failed`,reason:`fc-match answered ${JSON.stringify(e.slice(0,200))}, not families and their charsets`};let r=n.flatMap(e=>e.ranges),i=[...t].filter(e=>{let t=e.codePointAt(0);return!r.some(([e,n])=>e<=t&&t<=n)});return{kind:`ok`,value:{font:n[0].family,lacks:i}}}const
|
|
475
|
-
`,`:family=${
|
|
476
|
-
`)){let e=/^\s*(\d+)\s+(\d+)\s+(.*)$/.exec(t);if(e===null)continue;let r=e[3].trim();n.set(Number(e[1]),{ppid:Number(e[2]),name:r.slice(r.lastIndexOf(`/`)+1)})}if(!n.has(t))return{kind:`failed`,reason:`process ${t} is not running`};let r=new Set;for(let e=n.get(t);e!==void 0;e=n.get(e.ppid)){if(
|
|
477
|
-
`)){let e=/^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\w{3} \w{3}\s+\d+ [\d:]{8} \d{4})\s+.* (\/.*) daemon$/.exec(r);e===null||!t(e[5])||n.push({pid:Number(e[1]),ppid:Number(e[2]),rss:Number(e[3])*1024,started:`${e[4].replace(/\s+/g,` `)} UTC`})}return n.filter(e=>!n.some(t=>t.ppid===e.pid))}function
|
|
473
|
+
`;function mq(e){let t=Re({bin:`osascript`,args:[`-l`,`JavaScript`,`-e`,pq,...e],timeoutMs:3e3,category:`doctor.font`});if(!t.ok){if(t.reason===`rate-limited`)throw new VK(`the font`);return{kind:`failed`,reason:`osascript failed (${t.error??`${t.reason}: ${t.stderr.trim()}`})`}}let n;try{n=JSON.parse(t.stdout)}catch{return{kind:`failed`,reason:`osascript answered ${JSON.stringify(t.stdout.trim())}, not JSON`}}return typeof n==`object`&&n&&`error`in n?{kind:`failed`,reason:n.error}:{kind:`ok`,value:n}}const hq=e=>e.map(e=>String.fromCodePoint(parseInt(e,16))),gq=e=>[...e].map(fq).join(`,`);function _q(e,t){let n=mq([`font`,e.kind,e.name,gq(t)]);if(n.kind===`failed`)return n;let{lacks:r}=n.value;return{kind:`ok`,value:{font:e.name,lacks:r===null?null:hq(r)}}}function vq(e,t){if(e.font===null)return{kind:`failed`,reason:`iTerm2 profile ${JSON.stringify(e.name)} names no font`};let n=`iTerm2 profile ${JSON.stringify(e.name)}`+(e.nonAscii?`, its non-ASCII font`:``)+(e.powerline?`, built-in Powerline glyphs on`:``),r=e.lacks===null||!e.powerline?e.lacks:e.lacks.filter(e=>!Hk(t,e));return{kind:`ok`,value:{font:e.font,from:n,lacks:r}}}const yq=e=>e.kind===`ok`&&e.value.lacks!==null&&e.value.lacks.length===0;function bq(e,t,n){if(e.length===0)return{kind:`failed`,reason:t===null?`iTerm2 has no profiles in its preferences`:`iTerm2 has no profile named ${JSON.stringify(t)}`};let r=e.map(e=>vq(e,n));if(t!==null)return r[0];let i=r.find(e=>!yq(e));return i===void 0?{kind:`ok`,value:{font:[...new Set(r.flatMap(e=>e.kind===`ok`?[e.value.font]:[]))].join(`, `),from:`every iTerm2 profile, since the session does not say which draws the bar`,lacks:[]}}:i.kind===`failed`?i:{kind:`ok`,value:{...i.value,from:`${i.value.from}, one of its profiles, and the session does not say which draws the bar`}}}function xq(e,t,n){if(process.platform!==`darwin`)return{kind:`failed`,reason:`iTerm2 runs only on macOS`};let r=t.ITERM_PROFILE??null,i=mq([`iterm`,r??``,gq(n)]);return i.kind===`failed`?i:bq(i.value.profiles.map(e=>({...e,lacks:e.lacks===null?null:hq(e.lacks)})),r,e)}function Sq(e,t){let n=e.split(`
|
|
474
|
+
`).filter(e=>e!==``).map(e=>{let t=e.indexOf(` `);return t<=0?null:{family:e.slice(0,t),ranges:e.slice(t+1).split(/\s+/).filter(e=>e!==``).map(e=>{let[t,n=t]=e.split(`-`).map(e=>parseInt(e,16));return[t,n]})}});if(n.length===0||n.some(e=>e===null))return{kind:`failed`,reason:`fc-match answered ${JSON.stringify(e.slice(0,200))}, not families and their charsets`};let r=n.flatMap(e=>e.ranges),i=[...t].filter(e=>{let t=e.codePointAt(0);return!r.some(([e,n])=>e<=t&&t<=n)});return{kind:`ok`,value:{font:n[0].family,lacks:i}}}const Cq=e=>e.replace(/[\\:,=-]/g,`\\$&`);function wq(e,t){let n=Re({bin:`fc-match`,args:[`--sort`,`--format`,`%{family[0]} %{charset}
|
|
475
|
+
`,`:family=${Cq(e)}`],timeoutMs:3e3,category:`doctor.font`});if(!n.ok){if(n.reason===`rate-limited`)throw new VK(`the font`);return{kind:`failed`,reason:`fc-match failed (${n.error??`${n.reason}: ${n.stderr.trim()}`})`}}return Sq(n.stdout,t)}function Tq(e,t){return process.platform===`darwin`?_q(e,t):wq(e.name,t)}function Eq(e,t){let n=t||v.join(e,`.config`);return[v.join(n,`alacritty`,`alacritty.toml`),v.join(n,`alacritty.toml`),v.join(e,`.config`,`alacritty`,`alacritty.toml`),v.join(e,`.alacritty.toml`)]}function Dq(e){return e===`darwin`?`Menlo`:`monospace`}const Oq=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function kq(e){let t=Oq(e.font)?e.font:{},n=Oq(t.normal)?t.normal:{},r=(Oq(e.general)?e.general:{}).import??e.import??[];return{family:typeof n.family==`string`?n.family:null,imports:Array.isArray(r)?r.filter(e=>typeof e==`string`):[]}}function Aq(e,t,n){let r;try{r=s.readFileSync(e,`utf8`)}catch(t){return{kind:`failed`,reason:`cannot read ${e}: ${t.message}`}}let i;try{i=dq(r)}catch(t){return{kind:`failed`,reason:`cannot parse ${e}: ${t.message}`}}let a=kq(i);if(a.family!==null)return{kind:`ok`,value:{family:a.family,from:e}};if(n===5)return{kind:`ok`,value:null};let o=null;for(let r of a.imports){let i=r.startsWith(`~/`)?v.join(t,r.slice(2)):v.resolve(v.dirname(e),r);if(!s.existsSync(i))continue;let a=Aq(i,t,n+1);if(a.kind===`failed`)return a;o=a.value??o}return{kind:`ok`,value:o}}function jq(e,t){let n=w.homedir(),r=Eq(n,e.XDG_CONFIG_HOME).find(e=>s.existsSync(e)),i=r===void 0?{kind:`ok`,value:null}:Aq(r,n,0);if(i.kind===`failed`)return i;let a=i.value?.family??Dq(process.platform),o=i.value?.from??(r===void 0?`Alacritty's default, no config file`:`Alacritty's default, ${r} sets none`),c=Tq({kind:`family`,name:a},t);if(c.kind===`failed`)return c;let{font:l,lacks:u}=c.value;return{kind:`ok`,value:{font:l,from:l===a?o:`${o}; ${a} as fontconfig matches it`,lacks:u}}}const Mq={iterm2:xq,alacritty:(e,t,n)=>jq(t,n)};function Nq(e,t,n){return Mq[e.name](e.version,t,n)}function Pq(e,t){let n;try{n=JSON.parse(e)}catch(e){return{kind:`failed`,reason:`${t} is not JSON: ${e.message}`}}return Array.isArray(n)&&n.every(e=>typeof e==`string`)?{kind:`ok`,value:n}:{kind:`failed`,reason:`${t} is not a list of terminals`}}function Fq(e=v.join(Ue(),`doctor-clicked-terminals.json`)){let t=()=>{let t;try{t=s.readFileSync(e,`utf8`)}catch(t){return t.code===`ENOENT`?{kind:`ok`,value:[]}:{kind:`failed`,reason:`${e}: ${t.message}`}}return Pq(t,e)};return{read:t,record:n=>{let r=t();if(r.kind===`failed`)throw Error(`doctor: the clicked terminals could not be read: ${r.reason}`);r.value.includes(n)||(s.mkdirSync(v.dirname(e),{recursive:!0}),Ve(e,`${JSON.stringify([...r.value,n],null,2)}\n`))}}}function Iq(e,t){let n;try{n=JSON.parse(e)}catch(e){return{kind:`failed`,reason:`${t} is not JSON: ${e.message}`}}let r=n?.through;return typeof r==`string`?{kind:`ok`,value:r}:{kind:`failed`,reason:`${t} names no post-mortem read`}}function Lq(e=v.join(Ue(),`doctor-post-mortems-read.json`)){return{read:()=>{let t;try{t=s.readFileSync(e,`utf8`)}catch(t){return t.code===`ENOENT`?{kind:`ok`,value:null}:{kind:`failed`,reason:`${e}: ${t.message}`}}return Iq(t,e)},record:t=>{s.mkdirSync(v.dirname(e),{recursive:!0}),Ve(e,`${JSON.stringify({through:t},null,2)}\n`)}}}function Rq(e){try{return{kind:`ok`,value:e()}}catch(e){return{kind:`failed`,reason:e instanceof Error?e.message:String(e)}}}const zq={realpath:e=>Rq(()=>s.realpathSync(e)),checkoutOf:Mg,digest:e=>Rq(()=>Ag(e)),nativeShipped:zi(process.platform,process.arch)};function Bq(e,t,n){let r=e.realpath(t);if(r.kind===`failed`)return{kind:`failed`,reason:`the daemon's bundle ${t} cannot be resolved: ${r.reason}`};let i=e.checkoutOf(r.value);return{kind:`ok`,value:{daemon:{bundle:r.value,checkout:i===null?null:{root:i,rustSource:e.digest(v.join(i,`rust-client`))}},nativeShipped:e.nativeShipped,clients:n.map(t=>t===null?{kind:`unreported`}:{kind:`reported`,client:t.kind,bundle:e.realpath(t.bundle),source:t.source})}}}function Vq(e){let t=e.replace(/\n$/,``);if(t===` `)return{kind:`ok`,value:null};let n=t.split(` `),[r,i,a,o,s]=n;return n.length!==5||!/^[1-9]\d*$/.test(o)||!/^[01]$/.test(s)?{kind:`failed`,reason:`tmux answered ${JSON.stringify(e)}, not the five fields asked for`}:{kind:`ok`,value:{features:r.split(`,`).filter(e=>e!==``),termtype:i,termname:a,pid:Number(o),utf8:s===`1`}}}const Hq=/^(sshd|mosh-server)\b/;function Uq(e,t){let n=new Map;for(let t of e.split(`
|
|
476
|
+
`)){let e=/^\s*(\d+)\s+(\d+)\s+(.*)$/.exec(t);if(e===null)continue;let r=e[3].trim();n.set(Number(e[1]),{ppid:Number(e[2]),name:r.slice(r.lastIndexOf(`/`)+1)})}if(!n.has(t))return{kind:`failed`,reason:`process ${t} is not running`};let r=new Set;for(let e=n.get(t);e!==void 0;e=n.get(e.ppid)){if(Hq.test(e.name))return{kind:`ok`,value:!0};if(r.has(e.ppid))break;r.add(e.ppid)}return{kind:`ok`,value:!1}}function Wq(e){let t=Re({bin:`ps`,args:[`-A`,`-o`,`pid=,ppid=,comm=`],timeoutMs:2e3,category:`doctor.process`});if(!t.ok){if(t.reason===`rate-limited`)throw new VK(`the processes`);return{kind:`failed`,reason:`ps failed (${t.error??`${t.reason}: ${t.stderr.trim()}`})`}}return Uq(t.stdout,e)}const Gq=/^(.*)\/(?:dist\/index\.mjs|src\/index\.ts|bin\/cc-candybar)$/;function Kq(e,t){let n=[];for(let r of e.split(`
|
|
477
|
+
`)){let e=/^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\w{3} \w{3}\s+\d+ [\d:]{8} \d{4})\s+.* (\/.*) daemon$/.exec(r);e===null||!t(e[5])||n.push({pid:Number(e[1]),ppid:Number(e[2]),rss:Number(e[3])*1024,started:`${e[4].replace(/\s+/g,` `)} UTC`})}return n.filter(e=>!n.some(t=>t.ppid===e.pid))}function qq(e){let t;try{t=s.realpathSync(e)}catch{return!1}let n=Gq.exec(t)?.[1];return n!==void 0&&s.existsSync(v.join(n,`bin`,`cc-candybar`))}function Jq(){let e=Re({bin:`ps`,args:[`-U`,String(w.userInfo().uid),`-ww`,`-o`,`pid=,ppid=,rss=,lstart=,args=`],timeoutMs:2e3,category:`doctor.daemons`,env:{...process.env,LC_ALL:`C`,TZ:`UTC`}});return e.ok?{kind:`ok`,value:Kq(e.stdout,qq)}:{kind:`failed`,reason:`ps failed (${e.error??`${e.reason}: ${e.stderr.trim()}`})`}}function Yq(e){let t=cH(e,`doctor.tmux`,[`display`,`-p`,`-t`,e.pane,`#{client_termfeatures} #{client_termtype} #{client_termname} #{client_pid} #{client_utf8}`]);if(t.kind===`rate-limited`)throw new VK(`tmux`);return t.kind===`failed`?{kind:`failed`,reason:t.reason}:Vq(t.stdout)}function Xq(e){return{probeTmux:Yq,remoteLogin:Wq,fontInUse:Nq,loadConfig:e,marks:BK(),clicked:Fq(),install:zq,daemons:Jq,postMortemsRead:Lq(),forge:tJ,memento:Oz,transcript:Qq}}function Zq(e,t){let n=e.toString(`utf-8`),r=t?0:n.indexOf(`
|
|
478
478
|
`)+1,i=n.lastIndexOf(`
|
|
479
479
|
`)+1,a=0,o=0;for(let e of n.slice(r,i).split(`
|
|
480
|
-
`)){let t=
|
|
481
|
-
`)};return e.error===null?{...t,kind:`loaded`,unused:e.unused}:{...t,kind:`failed`,error:e.error}}function
|
|
482
|
-
`);let i=
|
|
480
|
+
`)){let t=kV(e);t.kind!==`blank`&&(a++,t.kind===`unparsed`&&o++)}return{lines:a,unparsed:o,whole:t}}function Qq(e){let t=dz(e,tA+1);return t.kind===`ok`?L(Zq(t.value.buf,t.value.fromStart)):t}function $q(e,t){if(t.kind===`failed`)return t;let n=new Map;for(let{path:e,answered:r}of t.value)n.set(e,r||(n.get(e)??!1));return{kind:`ok`,value:[...n].map(([t,n])=>({path:t,answered:n,read:e.transcript(t)}))}}const eJ={github:{loginHost:()=>`github.com`,args:e=>[`auth`,`token`,`--hostname`,e],nonZero:`logged-out`},gitlab:{loginHost:e=>e,args:()=>[`--version`],nonZero:`failed`}};function tJ(e){if(TT(e)===void 0)return{kind:`ok`,value:null};let t=WT(Re({bin:`git`,args:[...UT],cwd:e,env:{...process.env,GIT_OPTIONAL_LOCKS:`0`},timeoutMs:2e3,category:`doctor.forge`}));if(t.kind===`failed`)return t;let n=YT(t.value);if(n===null)return{kind:`ok`,value:null};let r=HT(n);if(r===null)return{kind:`ok`,value:null};let i=LT[r],a=eJ[r],o=a.loginHost(VT(n)),s=Re({bin:i,args:[...a.args(o)],cwd:e,timeoutMs:2e3,category:`doctor.forge`});return nJ(i,o,a.nonZero,s)}function nJ(e,t,n,r){let i=n=>({kind:`ok`,value:{cli:e,host:t,status:n}});return r.ok?i(`ready`):RT(r)?i(`missing`):r.reason===`non-zero`&&n===`logged-out`?i({loggedOut:PT(r.stderr)}):{kind:`failed`,reason:NT(e,r)}}function rJ(e){let t={layers:e.layers,warnings:e.warning===null?[]:e.warning.split(`
|
|
481
|
+
`)};return e.error===null?{...t,kind:`loaded`,unused:e.unused}:{...t,kind:`failed`,error:e.error}}function iJ(e){let{env:t,statusLine:n}=Ei(e);if(t!==void 0&&!Di(t))throw Error(`cannot read ${e}: \`env\` is not an object`);return{path:e,env:t??{},statusLine:n===void 0?{kind:`absent`}:Di(n)?{kind:`present`,refreshInterval:n.refreshInterval}:{kind:`not-an-object`,value:n}}}function aJ(e,t){return t===void 0?{kind:`unreported`}:t===null?{kind:`outside`}:{kind:`inside`,hint:t,client:e.probeTmux(t)}}function oJ(e,t){switch(e.kind){case`unreported`:return{kind:`unreported`};case`outside`:return t===void 0?{kind:`unreported`}:{kind:`seen`,identified:Yk(t),tmuxClient:null};case`inside`:{if(e.client.kind===`failed`)return{kind:`unasked`,reason:e.client.reason};let t=e.client.value;return t===null?{kind:`unasked`,reason:`tmux has no client attached to the pane's session`}:{kind:`seen`,identified:Jk(t),tmuxClient:t}}}}function sJ(e,t,n,r){if(t.kind!==`seen`)return t;let{identified:i,tmuxClient:a}=t,o=n.terminalEnv;if(i.kind!==`known`)return i;let{name:s,version:c}=i.terminal;if(Rk(s))return{kind:`bundling`,name:s,version:c};if(!zk(s))return{kind:`unread`,name:s,version:c};let{ITERM_PROFILE:l,...u}=o??{},d=a===null?{kind:`ok`,value:n.ssh===!0}:e.remoteLogin(a.pid);return{kind:`configured`,name:s,version:c,font:d.kind===`failed`?{kind:`failed`,reason:`whether the terminal is remote could not be asked: ${d.reason}`}:d.value?{kind:`failed`,reason:`the terminal is on the far side of a remote login, so its font is on the machine it runs on`}:e.fontInUse({name:s,version:c},a===null?o??{}:u,r)}}function cJ(e){return{kind:`arrived`,handler:e,bar:Ft}}function lJ(e,t){let[n,...r]=e;return n===void 0?{kind:`unneeded`}:{kind:`needed`,segments:[n,...r],fact:t()}}function uJ(e,t,n,r,i){return{pullRequests:lJ(t.pullRequests,()=>e.forge(n.cwd)),rateLimits:lJ(t.rateLimits,()=>i),memento:lJ(t.memento,()=>({located:e.memento(r,n.projectDir),claudeConfigDir:r}))}}function dJ(e,t,n,r,i,a,o,s){let c=e.loadConfig(n),l=jz(c.config,r,()=>!1),u=aJ(e,t.tmux),d=oJ(u,t.terminalEnv),f=[...new Set([...lg(l),...cg(JSON.stringify(c.config))])].join(``);return{tmux:u,termCols:t.termCols??null,terminal:d,nerdFont:f===``?{kind:`none`}:{kind:`glyphs`,glyphs:f,terminal:sJ(e,d,t,f)},marks:e.marks.read(),clicked:e.clicked.read(),daemon:{serving:i,processes:e.daemons(),read:e.postMortemsRead.read()},config:rJ(c),frames:s,data:uJ(e,UK(c.config,l.preset),n,Si(t.claudeConfigDir),a),transcripts:$q(e,o),claudeSettings:iJ(Ci(Si(t.claudeConfigDir)))}}function fJ(e,t,n){let r=n.claudeSettings.path;switch(t.kind){case`claude-settings`:{let e=si(Ti(r),t.path,JSON.stringify(t.value),Kr);return s.mkdirSync(v.dirname(r),{recursive:!0}),Ve(r,e),{...n,claudeSettings:iJ(r)}}case`post-mortems-read`:return e.postMortemsRead.record(t.through),{...n,daemon:{...n.daemon,read:e.postMortemsRead.read()}};default:return t}}const pJ={connectMs:200,budgetMs:500};async function mJ(e){let n=e.includes(`--json`),r=await hJ();r.kind!==`ok`&&(t.stderr.write(`daemon-stats: ${Pt(r)}\n`),t.exit(1)),n&&t.stdout.write(JSON.stringify(r.value,null,2)+`
|
|
482
|
+
`);let i=gJ(r.value);if(i!==null){t.stderr.write(`daemon-stats: ${i}\n`),t.exitCode=1;return}n||t.stdout.write(wJ(r.value))}function hJ(){return Ot({kind:`stats`},pJ,e=>`stats`in e?e.stats:void 0)}function gJ(e,t=_J){let n=JW.referenceSnapshot(),r=vJ(Object.fromEntries(t.map(e=>[e,n[e]])),e);if(r.length===0)return null;let i=bJ(e.version,e.sourceDigest??null),a=bJ(Ft,Pg());return`the daemon (${i}) reports no ${r.join(`, `)}; it is another build than this client (${a}), and restarts only when its own bundle changes`}const _J=Object.keys(JW.referenceSnapshot());function vJ(e,t,n=``){if(Array.isArray(e))return Array.isArray(t)?[]:[n||`<snapshot>`];if(!yJ(e))return[];if(!yJ(t))return[n||`<snapshot>`];if(`kind`in e)return[];let r=[];for(let i of Object.keys(e)){let a=n===``?i:`${n}.${i}`;i in t?r.push(...vJ(e[i],t[i],a)):r.push(a)}return r}function yJ(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function bJ(e,t){return`${e} [${t===null?`no digest`:jg(t)}]`}function xJ(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/1024/1024).toFixed(1)}MB`}function SJ(e,t){let n=e+t;return n===0?`n/a`:`${(e/n*100).toFixed(1)}%`}function CJ(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m${e%60}s`:`${Math.floor(e/3600)}h${Math.floor(e%3600/60)}m`}function wJ(e){let t=[];t.push(`cc-candybar daemon stats`),t.push(``),t.push(`process`),t.push(` pid ${e.pid}`),t.push(` build ${bJ(e.version,e.sourceDigest)}`),t.push(` protocol ${e.protocolVersion}`),t.push(` startedAt ${e.startedAt}`),t.push(` uptime ${CJ(e.uptimeSec)}`),t.push(` rss ${xJ(e.rssBytes)}`),t.push(` heapUsed ${xJ(e.heapUsedBytes)}`),t.push(` heapTotal ${xJ(e.heapTotalBytes)}`),t.push(` external ${xJ(e.externalBytes)}`),t.push(` arrayBuffers ${xJ(e.arrayBuffersBytes)}`),t.push(``),t.push(`requests`),t.push(` total ${e.requests.total}`),t.push(` errored ${e.requests.errored}`),t.push(` timedOut ${e.requests.timedOut}`),t.push(` inFlight ${e.requests.inFlight}`),t.push(``),t.push(`gitCache`),t.push(` size ${e.gitCache.size}`),t.push(` hit rate ${SJ(e.gitCache.hits,e.gitCache.misses)} (${e.gitCache.hits} / ${e.gitCache.hits+e.gitCache.misses})`),t.push(` invalidations ${e.gitCache.invalidations}`),t.push(``),t.push(`usageCache`),t.push(` size ${e.usageCache.size}`),t.push(` hit rate ${SJ(e.usageCache.hits,e.usageCache.misses)} (${e.usageCache.hits} / ${e.usageCache.hits+e.usageCache.misses})`),t.push(` sweeps ${e.usageCache.sweeps}`),t.push(``),t.push(`renderCache`),t.push(` size ${e.renderCache.size}`),t.push(` held ${e.renderCache.held}`),t.push(` retired ${e.renderCache.retired}`),t.push(``),t.push(`effectCache`),t.push(` sessions ${e.effectCache.sessions}`),t.push(` effects ${e.effectCache.effects}`),t.push(``),t.push(`sessionState`),t.push(` sessions ${e.sessionState.sessions}`),t.push(` observers ${e.sessionState.observers}`),t.push(` revision ${e.sessionState.revision}`),t.push(``),t.push(`watchers`),t.push(` active ${e.watchers.active}`),t.push(` opened ${e.watchers.opened}`),t.push(` closed ${e.watchers.closed}`),t.push(` evicted ${e.watchers.evicted}`),t.push(``),t.push(`subprocesses`),t.push(` total ${e.subprocesses.total}`),t.push(` inFlight ${e.subprocesses.inFlight}`),t.push(` lastMinute ${e.subprocesses.lastMinute}`);let n=Object.entries(e.subprocesses.byCategory),r=n.reduce((e,[t])=>Math.max(e,t.length),13);for(let[i,a]of n){let n=e.subprocesses.p50DurationMs[i],o=e.subprocesses.p99DurationMs[i],s=n!==void 0&&o!==void 0?` (p50 ${n}ms · p99 ${o}ms)`:``;t.push(` ${i.padEnd(r)} ${a}${s}`)}return e.nextRestartReason&&(t.push(``),t.push(`nextRestart ${e.nextRestartReason}`)),t.join(`
|
|
483
483
|
`)+`
|
|
484
|
-
`}const
|
|
485
|
-
`).join(` — `));let t=
|
|
486
|
-
`);return{inMode:n!==`0`,screen:r}}function BJ(e,t){let n=RJ(e,`claude-input.type`,[`load-buffer`,`-b`,LJ,`-`,`;`,`send-keys`,`-t`,e.pane,`C-s`,`;`,`paste-buffer`,`-p`,`-d`,`-b`,LJ,`-t`,e.pane,`;`,`send-keys`,`-t`,e.pane,`Enter`],t);return n.kind===`ok`?{kind:`typed`}:{kind:`refused`,reason:`cc-candybar typed a command moments ago — click again in a second (${n.reason})`}}function VJ(){return{read:zJ,type:BJ}}function HJ(e){if(!e)throw new q(`session id is required`);if(e.includes(`/`)||e.includes(`..`))throw new q(`invalid session id "${e}"`);return e}function UJ(e){return WJ(()=>decodeURIComponent(e))}function WJ(e){try{return e()}catch(e){throw e instanceof URIError?new q(`malformed wire encoding: ${e.message}`):e}}function GJ(e,t){let n=Re({bin:`/usr/bin/pbcopy`,stdinInput:e,category:`click.pbcopy`});if(!n.ok){if(n.reason===`rate-limited`){t.dlog(`warn`,`click.pbcopy rate-limited: ${n.error??``}`);return}throw Error(`pbcopy failed (${n.reason}, exit ${n.exitCode??`null`})`)}}const KJ=(e,t)=>GJ(UJ(e),t),qJ=(e,t)=>{let n=Re({bin:`/usr/bin/open`,args:[`-a`,`Visual Studio Code`,UJ(e)],category:`click.open`});if(!n.ok){if(n.reason===`rate-limited`){t.dlog(`warn`,`click.open rate-limited: ${n.error??``}`);return}throw Error(`open -a "Visual Studio Code" failed (${n.reason}, exit ${n.exitCode??`null`})`)}},JJ=(e,t)=>GJ(UJ(e),t),YJ=(e,t)=>GJ(UJ(e),t),XJ=(e,t)=>{let n=HJ(UJ(e));t.navigating.get(n,`toolbar-expanded`)?t.navigating.clear(n,`toolbar-expanded`):t.navigating.set(n,`toolbar-expanded`,`1`)},ZJ=(e,t)=>{let[n=``,...r]=WJ(()=>ir(e)),i=HJ(n),a=RB(dY(t,i));if(r.length===0)throw new q(`set-state: <key>/<value> is required (have keys: ${a.listKeys().join(`, `)})`);if(r.length%2!=0)throw new q(`set-state: expected even-count <key>/<value> pairs, got ${r.length} segment(s) after session id (have keys: ${a.listKeys().join(`, `)})`);let o=[];for(let e=0;e<r.length;e+=2){let t=r[e],n=r[e+1];if(!t)throw new q(`set-state: empty key at pair ${e/2+1} (expected <sessionId>/<key>/<value>[/<key>/<value>...] segments)`);let i=a.validate(t,n);if(!i.ok)throw new q(`set-state: pair ${e/2+1}: ${i.reason}`);o.push({key:t,value:i.value})}tY(t,i,`set-state`,o),t.navigating.setBatch(i,o);let s=o.map(e=>`${e.key}=${e.value}`).join(` `);t.dlog(`info`,`set-state: ${s} (session=${i})`)},QJ=/^-?\d+$/;function $J(e,t,n,r){let i=e+t;return i>r?e===r?n:r:i<n?e===n?r:n:i}const eY=(e,t)=>{let[n=``,r=``,i=``]=WJ(()=>ir(e)),a=HJ(n);if(!r)throw new q(`step-state: <key> is required (shape: <sessionId>/<key>/<by>)`);if(!QJ.test(i))throw new q(`step-state: delta must be an integer, got "${i}"`);let o=parseInt(i,10),s=dY(t,a),c=RB(s),l=c.rangeParamsFor(r);if(!l)throw new q(`step-state: key "${r}" is not a bounded (range) state key (have keys: ${c.listKeys().join(`, `)})`);let u=t.sessionState.get(a,r),d=u&&QJ.test(u)?nY(l,parseInt(u,10)):rY(`step-state`,r,l,VB(s,e=>t.sessionState.get(a,e),r)),f=$J(d,o,l.min,l.max),p=c.validate(r,String(f));if(!p.ok)throw new q(`step-state: ${p.reason}`);tY(t,a,`step-state`,[{key:r,value:p.value}]),t.navigating.set(a,r,p.value),t.dlog(`info`,`step-state: ${r} ${d}→${p.value} (by ${o}, session=${a})`)};function tY(e,t,n,r){let i=r.filter(e=>e.key.startsWith(ik));if(i.length===0)return;let a=_B(dY(e,t),n=>e.sessionState.get(t,n),i);if(a.length>0)throw new q(`${n}: refused — ${a.join(`; `)}`)}function nY(e,t){return Math.max(e.min,Math.min(e.max,t))}function rY(e,t,n,r){if(r===null)return n.min;if(!QJ.test(r))throw new q(`${e}: "${t}" shows ${JSON.stringify(r)} before any click, not an integer to step`);return nY(n,parseInt(r,10))}const iY=`render-origin`;function aY(e,t,n){return{...e,configFile:t.get(n,`config-override`)??e.configFile}}function oY(e){return JSON.stringify(e)}function sY(e){let t;try{t=JSON.parse(e)}catch{throw new q(`render origin is not JSON: ${e}`)}if(typeof t!=`object`||!t)throw new q(`render origin is not an object: ${e}`);let{projectDir:n,cwd:r,configFile:i}=t;if(typeof n!=`string`||typeof r!=`string`||i!==null&&typeof i!=`string`)throw new q(`render origin has the wrong shape: ${e}`);return{projectDir:n,cwd:r,configFile:i}}function cY(e,t){let n=lY(e,t);if(n===null)throw new q(`session ${t} has not rendered yet — no config to act on`);return n}function lY(e,t){let n=e.sessionState.get(t,iY);return n===null?null:aY(sY(n),e.sessionState,t)}function uY(e,t,n){let r=lY(e,t);if(r===null)return;let{path:i}=fY(r);n.some(e=>e.kind===`file`&&e.file===i)&&e.reloadConfig(r)}function dY(e,t){return e.configFor(cY(e,t))}function fY(e){return dR(e.projectDir,e.cwd,e.configFile??void 0)}function pY(e,t){return{record:(n,r,i)=>e.journal.file(t,n,r,i),logger:e.dlog}}const mY=(e,t)=>{let[n=``,r=``,i=``]=WJ(()=>ir(e)),a=HJ(n),o=cY(t,a),s=t.configFor(o),c=qN(s);if(!r)throw new q(`set-config: <key>/<value> is required (have keys: ${c.listKeys().join(`, `)})`);let l=c.validate(r,i);if(!l.ok)throw new q(`set-config: ${l.reason}`);let u=fY(o),d=hB(s,e=>t.sessionState.get(a,e),r);FG(pY(t,a),u,[[d.key,l.value]]),t.reloadConfig(o),t.dlog(`info`,`set-config: ${d.key}=${l.value} → ${u.path} (session=${a})`)},hY=(e,t)=>{let[n=``,r=``,i=``]=WJ(()=>ir(e)),a=HJ(n);if(!r)throw new q(`step-config: <key> is required (shape: <sessionId>/<key>/<by>)`);if(!QJ.test(i))throw new q(`step-config: delta must be an integer, got "${i}"`);let o=parseInt(i,10),s=cY(t,a),c=t.configFor(s),l=qN(c),u=l.rangeParamsFor(r);if(!u)throw new q(`step-config: key "${r}" is not a bounded (range) config key (have keys: ${l.listKeys().join(`, `)})`);let d=fY(s),f=hB(c,e=>t.sessionState.get(a,e),r),p=PG(d.path,f.key),m=typeof p==`number`?nY(u,p):rY(`step-config`,r,u,YN(f.globals,r)),h=$J(m,o,u.min,u.max),g=l.validate(r,String(h));if(!g.ok)throw new q(`step-config: ${g.reason}`);FG(pY(t,a),d,[[f.key,g.value]]),t.reloadConfig(s),t.dlog(`info`,`step-config: ${f.key} ${m}→${g.value} (by ${o}) → ${d.path} (session=${a})`)},gY=(e,t)=>{let[n=``]=WJ(()=>ir(e)),r=HJ(n),i=cY(t,r),a=t.configFor(i),o=e=>t.sessionState.get(r,e),s=pB(a,o),c=gB(a,o);if(s.length+c.length===0){t.dlog(`info`,`save: nothing unsaved (session=${r})`);return}let l=RB(a),u=s.map(e=>{let t=l.validate(e.sessionKey,e.value);if(!t.ok)throw new q(`save: ${t.reason}`);return[e.target,t.value]});vY(`save`,l,c);let d=fY(i);IG(pY(t,r),d,u,c),t.reloadConfig(i);for(let e of[...s.map(e=>e.sessionKey),...c.map(e=>e.key)])t.sessionState.clear(r,e);t.dlog(`info`,`save: ${[...u.map(([e,t])=>`${e}=${t}`),...c.map(_Y)].join(` `)} → ${d.path} (session=${r})`)},_Y=e=>`${e.preset}/${e.id}.settings.${e.setting}=${b_(e.value)}`;function vY(e,t,n){for(let r of n){let n=t.validate(r.key,b_(r.value));if(!n.ok)throw new q(`${e}: ${n.reason}`)}}const yY=(e,t)=>{let[n=``]=WJ(()=>ir(e)),r=HJ(n),i=cY(t,r),a=t.configFor(i),o=bB(a,e=>t.sessionState.get(r,e)),s=RB(a),c=o.picks.map(e=>{let t=s.validate(e.sessionKey,e.value);if(!t.ok)throw new q(`save-preset: ${t.reason}`);return[e.configKey,t.value]});vY(`save-preset`,s,o.placements);let l=fY(i),u=UG(pY(t,r),l,o.from,o.globals,c,o.placements);t.reloadConfig(i);for(let e of[...Va.map(e=>e.sessionKey),...o.placements.map(e=>e.key)])t.sessionState.clear(r,e);t.sessionState.set(r,Ba.preset.sessionKey,u),t.dlog(`info`,`save-preset: ${[`${u} from=${o.from}`,...c.map(([e,t])=>`${e}=${t}`),...o.placements.map(_Y)].join(` `)} → ${l.path} (session=${r})`)},bY=(e,t)=>{let[n=``]=WJ(()=>ir(e)),r=HJ(n),i=cY(t,r),a=SB(t.configFor(i),e=>t.sessionState.get(r,e));if(a.kind===`rule`)throw new q(`save-theme-default: the theme is chosen by a rule (globals.palette), so there is no name to save as a theme's default — pick one in the menu first`);let o=fY(i);WG(pY(t,r),o,a.theme,a.look),t.reloadConfig(i);let s=new Set(pB(t.configFor(i),e=>t.sessionState.get(r,e)).map(e=>e.sessionKey)),c=a_.map(e=>Ba[e].sessionKey).filter(e=>!s.has(e));for(let e of c)t.sessionState.clear(r,e);t.dlog(`info`,`save-theme-default: ${a.theme} ${a_.map(e=>`${e}=${a.look[e]}`).join(` `)} → ${o.path} (session=${r})`)},xY=(e,t)=>{let[n=``,r=``]=WJ(()=>ir(e)),i=HJ(n);if(!r)throw new q(`delete-preset: <name> is required (shape: <sessionId>/<name>)`);let a=cY(t,i),o=fY(a);GG(pY(t,i),o,r),t.reloadConfig(a);let s=Ba.preset.sessionKey;t.sessionState.get(i,s)===r&&t.sessionState.clear(i,s),t.dlog(`info`,`delete-preset: ${r} ← ${o.path} (session=${i})`)},SY=(e,t)=>{let[n=``,...r]=WJ(()=>ir(e)),i=HJ(n),a=cY(t,i),o=qN(t.configFor(a)).listKeys(),s=r.length===0?[``]:r.filter(e=>!o.includes(e));if(s.length>0)throw new q(`reset-config: unknown config key "${s.join(`", "`)}" (have: ${o.join(`, `)})`);let c=fY(a),l=r.map(CB),u=l.flatMap(e=>e.fileKeys),d=l.flatMap(e=>e.sessionKeys);BG(pY(t,i),c,u),t.reloadConfig(a);for(let e of d)t.sessionState.clear(i,e);t.dlog(`info`,`reset-config: ${[...u,...d.map(e=>`session:${e}`)].join(` `)} ← ${c.path} (session=${i})`)};function CY(e,t){let n=(e,t)=>[...e_(H_(e,t).node)].filter(e=>e.kind===`segment`),r=new Set(z_(t.presets).flatMap(e=>n(t,e).map(t=>ak(YE(e),Xg(t)))));return z_(e.presets).flatMap(t=>n(e,t).map(e=>({member:ak(YE(t),Xg(e)),node:e})).filter(({member:e})=>!r.has(e)))}function wY(e,t){return e.flatMap(({member:e,node:n})=>[...Object.values(n.drafts??{}).map(e=>e.key),...e===t?[$O]:[]])}const TY=(e,t)=>{let[n=``,r=``,i=``]=WJ(()=>ir(e)),a=HJ(n),o=cY(t,a),s=t.configFor(o),c=qN(s);if(!r)throw new q(`apply-layout-op: <key>/<op> is required (have: ${c.listKeys().join(`, `)})`);let l=c.validate(r,i);if(!l.ok)throw new q(`apply-layout-op: ${l.reason}`);let u=NN(l.value);if(u===null)throw new q(`apply-layout-op: "${l.value}" is not a layout op token`);let d=fY(o),f=KG(pY(t,a),d,r,u);t.reloadConfig(o);let p=wY(CY(s,t.configFor(o)),t.sessionState.get(a,$O)).filter(e=>t.sessionState.get(a,e)!==null);for(let e of p)t.sessionState.clear(a,e);t.dlog(`info`,`apply-layout-op: ${r} ${l.value} → ${d.path} placed=${JSON.stringify(f)} released=${JSON.stringify(p)} (session=${a})`)},EY=(e,t)=>{let[n=``]=WJ(()=>ir(e)),r=HJ(n);t.journal.commit();let i=t.history.undo(r);uY(t,r,i),t.dlog(`info`,`undo: restored ${mK(i)} (session=${r})`)},DY=(e,t)=>{let n=HJ(UJ(e)),{step:r,discarded:i}=t.navigation.back(n,t.sessionState,RB(dY(t,n))),a=r.map(e=>`${e.key}=${e.before??`∅`}`).join(` `);t.dlog(`info`,`back: ${a} discarded=${i} (session=${n})`)},OY=(e,t)=>{let n=HJ(UJ(e));t.journal.commit();let r=t.history.rewind(n);uY(t,n,r),t.dlog(`info`,`rewind: put back ${mK(r)||`nothing`} as edit mode found it (session=${n})`)},kY=(e,t)=>{let[n=``]=WJ(()=>ir(e)),r=HJ(n);t.journal.commit();let i=t.history.redo(r);uY(t,r,i),t.dlog(`info`,`redo: re-applied ${mK(i)} (session=${r})`)},AY=(e,t)=>{HJ(UJ(e)),t.applyUpdate()},jY=`client-hints`;function MY(e,t){let n=e.sessionState.get(t,jY);if(n===null)throw new q(`session ${t} has not rendered yet — no client facts are recorded for it`);let r;try{r=JSON.parse(n)}catch{throw new q(`client hints record is not JSON: ${n}`)}if(typeof r!=`object`||!r)throw new q(`client hints record is not an object: ${n}`);return ft(r)}function NY(e,t,n){let r=RA(n);e.sessionState.setBatch(t,XA(r)),e.dlog(`info`,`doctor: ${r.map(e=>`${e.check.name}=${e.verdict.ok?`ok`:`failed(${1+(e.verdict.more?.length??0)})`}`).join(` `)} ${JA(n.nerdFont,n.marks)} ${HA(n.terminal,n.clicked)} ${UA(n.terminal,n.termCols)} ${WA(n.install)} ${GA(n.daemon)} ${KA(n.data)} ${qA(n.transcripts)} (session=${t})`)}function PY(e,t){let n=e.clients.ofSession(t),r;try{r=aJ(e.doctor,MY(e,t),cY(e,t),n=>e.sessionState.get(t,n),{kind:`ok`,value:e.serving()},{kind:`ok`,value:n.map(e=>e.rateLimits)},{kind:`ok`,value:n.map(e=>e.transcript)})}catch(e){throw e instanceof PK?new q(e.message):e}return{...r,urlHandler:tJ(e.clientVersion),install:Nq(e.doctor.install,e.bundle,n.map(e=>e.client)),askedBy:`click`,clicked:FY(e,r)}}function FY(e,{terminal:t,clicked:n}){let r=t.kind===`seen`?qk(t.identified):null;if(r===null||n.kind===`failed`)return n;try{e.doctor.clicked.record(r)}catch(t){return e.dlog(`warn`,`doctor: clicked terminal not filed for ${JSON.stringify(r)}: ${t instanceof Error?t.message:String(t)}`),n}return{kind:`ok`,value:n.value.includes(r)?n.value:[...n.value,r]}}const IY=(e,t)=>{let n=HJ(UJ(e));NY(t,n,PY(t,n))},LY=(e,t)=>{let n=CJ(UJ(e));if(n===null)throw new q(`doctor-probe: the value is not a probe nonce`);t.probes.arrive({nonce:n,handler:t.clientVersion}),t.dlog(`info`,`doctor-probe: arrived nonce=${n} handler=${t.clientVersion??`unreported`}`)},RY=(e,t)=>{let[n=``,r=``]=WJ(()=>ir(e)),i=HJ(n),a=zA(r);if(a===void 0)throw new q(`doctor-fix: unknown check "${r}"`);let o=PY(t,i),s=a.probe(o);if(s.ok||s.fix===void 0)throw new q(`doctor-fix: ${a.label} — ${s.ok?`nothing to fix`:s.reason}`);let c=oJ(t.doctor,s.fix,o);t.dlog(`info`,`doctor-fix: ${a.name} → ${$k(s.fix)} (session=${i})`),NY(t,i,c)},zY=(e,t)=>{let[n=``,r=``,i=``]=WJ(()=>ir(e)),a=HJ(n),o=zA(r);if(o===void 0)throw new q(`doctor-mark: unknown check "${r}"`);if(!Zk.includes(i))throw new q(`doctor-mark: the mark is ${JSON.stringify(i)}, not ${Zk.join(` or `)}`);let s=PY(t,a),c=o.probe(s);if(c.ok||c.sighting===void 0)throw new q(`doctor-mark: ${o.label} — ${c.ok?`nothing to mark`:`shows nothing to look at`}`);if(s.marks.kind===`failed`)throw new q(`doctor-mark: ${s.marks.reason}`);let l=[o.name,c.sighting.id,i];t.doctor.marks.record(...l),t.dlog(`info`,`doctor-mark: ${o.name} ${i} on ${c.sighting.id} (session=${a})`),NY(t,a,{...s,marks:{kind:`ok`,value:MK(s.marks.value,...l)}})},BY=(e,t)=>{let[n=``,...r]=WJ(()=>ir(e)),i=HJ(n),a=cY(t,i),o=Object.values(t.configFor(a).actions).filter(e=>`ceiling`in e).find(e=>{let t=YF(e);return t.length===r.length&&t.every((e,t)=>e===r[t])});if(o===void 0)throw new q(`ceiling: "${r.join(` `)}" is not a move this config declares`);let s=o.ceiling===`set`?{kind:`set`,to:o.to}:{kind:`clear`},c=fz({sessionId:i,projectDir:a.projectDir,cwd:a.cwd},MY(t,i));t.memento.move(c,s),t.dlog(`info`,`ceiling: ${r.join(` `)} (session=${i} claudeConfigDir=${c.claudeConfigDir})`)},VY=(e,t)=>{let[n=``,r=``]=WJ(()=>ir(e)),i=HJ(n),a=Object.values(t.configFor(cY(t,i)).actions).filter(e=>`slash`in e),o=a.find(e=>e.slash===r);if(o===void 0)throw new q(`${JSON.stringify(r)} is not a command this config declares (it declares: ${[...new Set(a.map(e=>e.slash))].join(`, `)||`none`})`);let s=IJ(t.claudeInput,MY(t,i).tmux,o.slash);if(s.kind===`refused`)throw t.dlog(`warn`,`slash: ${r} refused — ${s.reason} (session=${i})`),new q(`${r} was not typed: ${s.reason}`);t.dlog(`info`,`slash: typed ${r} into ${s.pane} (session=${i})`)},HY=`config-override`,UY=new Map([[Nn,KJ],[`load-config`,(e,t)=>{let n=e.indexOf(`/`);if(n===-1)throw new q(`load-config: expected <sessionId>/<path> (missing separator)`);let r=HJ(WJ(()=>decodeURIComponent(e.slice(0,n)))),i=WJ(()=>decodeURIComponent(e.slice(n+1))).trim();if(i!==``){if(!i.startsWith(`/`))throw new q(`load-config: path must be absolute, got "${i}"`);if(!/\.(json5?|json)$/.test(i))throw new q(`load-config: path must end with .json5 or .json, got "${i}"`)}i===``?(t.sessionState.clear(r,HY),t.dlog(`info`,`load-config: override cleared (session=${r})`)):(t.sessionState.set(r,HY,i),t.dlog(`info`,`load-config: ${i} (session=${r})`))}],[Pn,qJ],[jn,ZJ],[Mn,eY],[Rn,mY],[zn,hY],[Wn,SY],[Bn,gY],[Vn,yY],[Hn,bY],[Un,xY],[Gn,TY],[Kn,EY],[qn,kY],[Jn,DY],[Yn,OY],[In,JJ],[Ln,YJ],[Fn,XJ],[Xn,AY],[Zn,IY],[Qn,RY],[$n,zY],[er,LY],[tr,BY],[nr,VY]]),WY=new Set([jn,Mn,Rn,zn,Wn,Bn,Vn,Hn,Un,Gn,Kn,qn,Jn,Yn,Fn,Xn,Zn,Qn,$n,tr,nr]),GY=(e,t)=>{let n=[],r=!1,i=null;for(let{verb:a,value:o}of sr(ar(e))){if(!i&&WY.has(a)){let e=ir(o);e.length>0&&e[0]&&(i=e[0])}let e=UY.get(a);if(!e){n.push(`unknown effect verb "${a}"`);continue}try{e(o,t)}catch(e){e instanceof q||(r=!0),n.push(`${a}: ${e instanceof Error?e.message:String(e)}`)}}if(n.length>0){i&&TK(t.sessionState,i,n.join(`
|
|
487
|
-
`),
|
|
488
|
-
`)){let[e,r]=n.trim().split(` `);e!==void 0&&r===`1`&&t.add(e)}return t}function
|
|
489
|
-
`)){let[e,i,a,o,s,c]=r.trim().split(` `);e===void 0||e===``||i===void 0||Number(a)>0&&(o===`1`||t.has(i))&&(s!==`1`||c===`1`)&&n.add(e)}return n}var SX=class{servers=new Map;loop={kind:`idle`};constructor(e){this.deps=e}follow(){switch(this.loop.kind){case`idle`:this.deps.log(`info`,`visibility following`),this.ask();break;case`asking`:this.loop.following=!0;break;case`due`:break}return()=>this.stop()}stop(){switch(this.loop.kind){case`due`:clearTimeout(this.loop.timer),this.end();return;case`asking`:this.loop.following=!1;return;case`idle`:return}}ask(){let e={kind:`asking`,following:!0};this.loop=e,Promise.resolve().then(()=>this.refresh(this.deps.sockets())).catch(e=>this.deps.log(`error`,`visibility refresh threw: ${T(e)}`)).then(()=>{if(e.following){this.loop={kind:`due`,timer:setTimeout(()=>this.ask(),this.deps.intervalMs).unref()};return}this.end()})}end(){this.deps.log(`info`,`visibility stopped forgot=${this.servers.size}`),this.loop={kind:`idle`},this.servers.clear()}shown(e){if(e==null)return!0;let t=this.servers.get(e.socket);return t?.kind!==`asked`||t.shown.has(e.pane)}async refresh(e){for(let t of this.servers.keys())e.has(t)||this.servers.delete(t);let t=await Promise.all([...e].map(async e=>{let[t,n]=await Promise.all([this.deps.listPanes(e),this.deps.listClients(e)]);return[e,t.kind===`ok`?n.kind===`ok`?{kind:`asked`,shown:xX(t.stdout,bX(n.stdout))}:{kind:`unasked`,reason:n.reason}:{kind:`unasked`,reason:t.reason}]})),n=new Set;for(let[e,r]of t){let t=this.servers.get(e);this.servers.set(e,r),!CX(t,r)&&(n.add(e),this.deps.log(r.kind===`asked`?`info`:`warn`,r.kind===`asked`?`visibility socket=${JSON.stringify(e)} shown=${[...r.shown].join(`,`)||`-`}`:`visibility socket=${JSON.stringify(e)} unasked: ${r.reason} — its panes count as shown`))}n.size>0&&this.deps.onChange(n)}};function CX(e,t){return e===void 0||e.kind!==t.kind?!1:e.kind===`unasked`||t.kind===`unasked`?!0:e.shown.size===t.shown.size&&[...e.shown].every(e=>t.shown.has(e))}const wX={order:-1/0,text:null,failure:null};var TX=class{synced=new Map;constructor(e){this.dir=e}pathFor(e){return v.join(this.dir,`${encodeURIComponent(e)}.txt`)}sync(e,t,n){let r=this.synced.get(e)??wX;if(t<r.order)return{link:this.linkFor(e,n),failure:null};let i=n===r.text&&r.failure===null?null:this.write(e,n);return this.synced.delete(e),this.synced.set(e,{order:t,text:n,failure:i}),this.forgetOldestClean(),{link:this.linkFor(e,n),failure:i}}linkFor(e,t){let n=this.synced.get(e)??wX;return n.text===t?n.failure===null?{kind:`file`,path:this.pathFor(e)}:{kind:`unavailable`,reason:n.failure}:{kind:`unavailable`,reason:`the file holds another render's text until the session's next statusline request`}}forgetOldestClean(){let e=0;for(let t of this.synced.values())t.text===null&&t.failure===null&&e++;for(let[t,n]of this.synced){if(e<=256)return;n.text!==null||n.failure!==null||(this.synced.delete(t),e--)}}write(e,t){let n=this.pathFor(e);try{return t===null?s.rmSync(n,{force:!0}):(s.mkdirSync(this.dir,{recursive:!0,mode:448}),s.writeFileSync(n,t,{mode:384})),null}catch(e){return`${n}: ${e.message}`}}reset(){this.synced.clear();try{return s.rmSync(this.dir,{recursive:!0,force:!0}),null}catch(e){return`${this.dir}: ${e.message}`}}};function EX(e,t){for(let n of Object.entries(t))e.push(n)}const DX={ok:`info`,"bad-request":`warn`,threw:`error`};function OX(e){switch(e.kind){case`ok`:return[];case`bad-request`:return[[`problems`,e.problems.join(`; `)]];case`threw`:return[[`error`,T(e.error)]]}}const kX=/^[^\s"=\\]+$/,AX=e=>kX.test(e)?e:JSON.stringify(e);function jX(e,t,n){let r=[...e,[`took`,`${n}ms`],[`outcome`,t.kind],...OX(t)];return{level:DX[t.kind],line:`render${r.map(([e,t])=>` ${e}=${AX(t)}`).join(``)}`}}function MX(){var e=typeof SuppressedError==`function`?SuppressedError:function(e,t){var n=Error();return n.name=`SuppressedError`,n.error=e,n.suppressed=t,n},t={},n=[];function r(e,t){if(t!=null){if(Object(t)!==t)throw TypeError(`using declarations can only be used with objects, functions, null, or undefined.`);if(e)var r=t[Symbol.asyncDispose||Symbol.for(`Symbol.asyncDispose`)];if(r===void 0&&(r=t[Symbol.dispose||Symbol.for(`Symbol.dispose`)],e))var i=r;if(typeof r!=`function`)throw TypeError(`Object is not disposable.`);i&&(r=function(){try{i.call(t)}catch(e){return Promise.reject(e)}}),n.push({v:t,d:r,a:e})}else e&&n.push({d:t,a:e});return t}return{e:t,u:r.bind(null,!1),a:r.bind(null,!0),d:function(){var r,i=this.e,a=0;function o(){for(;r=n.pop();)try{if(!r.a&&a===1)return a=0,n.push(r),Promise.resolve().then(o);if(r.d){var e=r.d.call(r.v);if(r.a)return a|=2,Promise.resolve(e).then(o,s)}else a|=1}catch(e){return s(e)}if(a===1)return i===t?Promise.resolve():Promise.reject(i);if(i!==t)throw i}function s(n){return i=i===t?n:new e(n,i),o()}return o()}}}const NX=new VW,PX=new xJ,FX=new Mk,IX=i(import.meta.url);Fe(NX.launchStats);const LX=new cE({counters:NX,logger:N}),RX=lH({watchers:LX,logger:N}),{gitProvider:zX,usageStore:BX,mementoProvider:VX}=RX,HX=new WW,UX=new eK(HX,N),WX=new CK,GX=new eg,KX=new gX({render:e=>NZ(e),watch:(e,t)=>(0,wv.reaction)(()=>HX.revision(e),t,{scheduler:e=>fe(e)}),lanes:e=>FZ(e),shown:e=>qX.shown(e.hints.tmux),watching:()=>qX.follow(),periods:hX,now:()=>Date.now(),log:N}),qX=new SX({listPanes:e=>iH({socket:e},`frames.visibility`,[`list-panes`,`-a`,`-F`,vX]),listClients:e=>iH({socket:e},`frames.visibility`,[`list-clients`,`-F`,yX]),sockets:()=>new Set(KX.watched().flatMap(({req:e})=>JX(e))),onChange:e=>KX.wakeWhere(t=>JX(t).some(t=>e.has(t))),intervalMs:1e3,log:N});function JX({hints:{tmux:e}}){return e==null?[]:[e.socket]}const YX=new TX(it()),XX=new zW({gitService:zX,sessionState:HX,watchers:LX,log:N},{observers:{onReload:e=>N(`info`,`config loaded projectDir=${e.projectDir} cwd=${e.cwd} files=${e.configLayers.join(` < `)||`<bundled default>`} error=${e.lastError===null?`none`:JSON.stringify(e.lastError)} warning=${e.lastWarning===null?`none`:JSON.stringify(e.lastWarning)}`)}}),ZX=60*1e3;function QX(){let e=import.meta.url,n=[];e.startsWith(`file://`)&&n.push(i(e)),t.argv[1]&&n.push(t.argv[1]);let r=new Map;for(let e of n)try{r.set(e,s.statSync(e).mtimeMs)}catch{}let a=null,o=()=>{for(let[e,t]of r)try{if(s.statSync(e).mtimeMs!==t){N(`info`,`binary mtime changed (${e}); shutting down`),a&&clearInterval(a),hZ(0);return}}catch(e){N(`warn`,`bin stat failed: ${e.message}`)}};return{arm(){r.size!==0&&(a=setInterval(o,ZX),a.unref())},checkNow:o}}const $X=QX(),eZ=oV({entryUrl:import.meta.url,intervalMs:ZX,releaseIntervalMs:216e5,registryUrl:t.env.CC_CANDYBAR_REGISTRY_URL??`https://registry.npmjs.org`,fetchImpl:fetch,onApplied:()=>$X.checkNow(),log:N});let tZ=null,nZ=null,rZ=0;function iZ(){t.on(`uncaughtException`,e=>{N(`error`,`uncaughtException: ${e.stack||e.message}`),hZ(1)}),t.on(`unhandledRejection`,e=>{N(`error`,`unhandledRejection: ${String(e)}`),hZ(1)});for(let e of[`SIGINT`,`SIGTERM`,`SIGHUP`])t.on(e,()=>{N(`info`,`received ${e}, shutting down`),hZ(0)});try{dZ(t.env)}catch(e){N(`error`,`refusing to boot: ${e.message}`),hZ(1);return}tZ=ba(t.pid);let e=Aa(Ma(tZ));if(!e.decision.allow){N(`warn`,`fork-bomb breaker: ${e.decision.reason}; refusing to boot`),hZ(1);return}nZ=e.registryPath,s.mkdirSync(Ge(),{recursive:!0}),Ye(Ke()),HX.useStorage(new KW(Qe(),500,N)),UX.useStorage(xK($e(),N)),Ca({anchor:Sa(t.env),isAlive:wa,onOrphaned:e=>{N(`info`,`parent watchdog: ${e}; shutting down`),hZ(0)}}),aZ(D.createServer({allowHalfOpen:!1},e=>{gZ(e)}),Ke(),!1)}function aZ(e,n,r){e.removeAllListeners(`error`),e.removeAllListeners(`listening`),e.once(`error`,i=>{if(i.code!==`EADDRINUSE`){N(`error`,`server error: ${i.message}`),hZ(1);return}if(r){N(`info`,`lost rebind race; another daemon is alive — exiting`),t.exit(0);return}oZ(e,n)}),e.listen(n,()=>sZ(n))}function oZ(e,n){let r=ua(da(Xe(n)),(e,t)=>ya(e,t,{readStartTime:va,pidAlive:wa}));if(r.kind===`attach-and-exit`){N(`info`,`EADDRINUSE: ${r.reason} — exiting`),t.exit(0);return}N(`warn`,`EADDRINUSE: ${r.reason} — unlinking stale socket and rebinding`);try{s.unlinkSync(n)}catch(e){if(e.code!==`ENOENT`){N(`error`,`cannot unlink stale socket ${n}: ${e.message}`),hZ(1);return}}aZ(e,n,!0)}function sZ(e){let n=ma(e);if(n.kind!==`present`){N(`warn`,`no ownable socket at bind callback (${n.kind}); exiting`),hZ(0);return}fZ(e);try{s.chmodSync(e,384)}catch(e){N(`warn`,`chmod socket failed: ${e.message}`)}N(`info`,`daemon up: pid=${t.pid} v=3 sock=${e} heapCap=${en(ie.getHeapStatistics().heap_size_limit)}MB rssLimit=${en(rZ)}MB`),bn();let r=YX.reset();r!==null&&N(`warn`,`diagnostic dump wipe failed: ${r}`),$X.arm(),eZ.arm(),uZ().arm(),cZ(e,n.identity)}function cZ(e,n){_a({bound:n,myPid:t.pid,readIdentity:()=>ma(e),readLease:()=>da(Xe(e)),shutdown:e=>hZ(e),log:N}).arm()}let lZ=null;function uZ(){if(lZ===null)throw Error(`daemon: limits not yet established`);return lZ}function dZ(e){rZ=tn(e),lZ=cn(dn(NX.startedAt.getTime(),e=>hZ(e),{rssLimitBytes:rZ}))}function fZ(e){let n=fa(Xe(e),{pid:t.pid,version:3,binPath:t.argv[1],startTime:tZ});n!==null&&N(`warn`,`lease write failed: ${n}`)}let pZ=0,mZ=!1;function hZ(e){if(!mZ){mZ=!0,setTimeout(()=>t.kill(t.pid,`SIGKILL`),500);try{zX.close()}catch(e){N(`warn`,`gitService close failed: ${e.message}`)}try{BX.close()}catch(e){N(`warn`,`usageStore close failed: ${e.message}`)}try{LX.closeAll()}catch(e){N(`warn`,`watcherRegistry close failed: ${e.message}`)}try{HX.flush()}catch(e){N(`warn`,`sessionState flush failed: ${e.message}`)}pa(Ze(),t.pid),nZ!==null&&ja(nZ,t.pid,Oa,e=>s.unlinkSync(e)),t.exit(e)}}function gZ(e){pZ++,NX.inFlight=pZ;let t=!1,n=!0,r=()=>{n&&(n=!1,pZ=Math.max(0,pZ-1),NX.inFlight=pZ)},i=(n,r,i)=>{if(t){r!==null&&N(`warn`,`exit-after-flush dropped: an earlier responder settled this socket`);return}t=!0;let a=r===null?void 0:()=>hZ(r);try{e.end(Ct(n),e=>{e??i(),a?.()})}catch(e){N(`warn`,`response write failed: ${e.message}`),a?.()}},a=!1,o=setTimeout(()=>{a=!0,NX.requestsTimedOut++,i({ok:!1,error:`request exceeded 200ms`,code:`TIMEOUT`,daemonV:3},null,_Z)},200),s=Tt(e=>{wZ(e,()=>a).then(e=>e.kind===`reply`?i(e.resp,e.exitAfterFlush,e.delivered):c(e.sessionId,e.lane)).catch(e=>{N(`error`,`handler threw: ${T(e)}`),i(xZ(e),null,_Z)})},e=>{N(`warn`,`frame parse failed: ${e.message}`),i({ok:!1,error:e.message,code:`BAD_REQUEST`,daemonV:3},null,_Z)}),c=(n,i)=>{if(t||e.destroyed)return;clearTimeout(o),r(),e.off(`data`,s);let a=_X(e),c=KX.subscribe(n,{lane:i,frame:(e,t)=>a(wt(t)),refused:t=>e.end(Ct(t))});t=!0,e.on(`close`,c)};e.on(`data`,s),e.on(`error`,e=>{N(`warn`,`socket error: ${e.message}`)}),e.on(`close`,()=>{clearTimeout(o),r()})}const _Z=()=>{},vZ=e=>({resp:e,exitAfterFlush:null,delivered:_Z}),yZ=e=>({kind:`reply`,...e}),bZ={render:!0,"pane-session":!0,shutdown:!0,stats:!0,click:!0,debug:!0},xZ=e=>({ok:!1,error:e instanceof Error?e.message:T(e),code:`RENDER_FAILED`,daemonV:3}),SZ=(e,t)=>yZ(vZ({ok:!1,error:t,code:e,daemonV:3}));function CZ(e){if(typeof e.sessionId!=`string`||e.sessionId===``)return SZ(`BAD_REQUEST`,`subscribe needs a non-empty string sessionId`);if(e.lane===void 0)return SZ(`VERSION_MISMATCH`,`this client's subscribe names no lane (${Pa.join(`, `)}): it predates the lane toggles — update it`);let t=Ia(e.lane);return t===null?SZ(`BAD_REQUEST`,`subscribe needs a lane, one of ${Pa.join(`, `)}: got ${JSON.stringify(e.lane)}`):{kind:`subscribe`,sessionId:e.sessionId,lane:t}}async function wZ(e,t){return!e||typeof e!=`object`||typeof e.v!=`number`?SZ(`BAD_REQUEST`,`malformed request`):e.v===3?e.kind===`subscribe`?CZ(e):typeof e.kind!=`string`||!Object.hasOwn(bZ,e.kind)?SZ(`BAD_REQUEST`,`unknown kind`):yZ(await TZ(e,t)):(e.v>3?N(`info`,`version mismatch: client=${e.v} > daemon=3; binary likely upgraded — exiting after the response flushes`):N(`info`,`version mismatch: client=${e.v} < daemon=3; client is stale — staying up`),{kind:`reply`,resp:{ok:!1,error:`protocol v${e.v} not supported (daemon at v3)`,code:`VERSION_MISMATCH`,daemonV:3},exitAfterFlush:e.v>3?0:null,delivered:_Z})}async function TZ(e,t){if(e.kind===`shutdown`)return{resp:{ok:!0,output:``},exitAfterFlush:0,delivered:_Z};if(e.kind===`pane-session`){let{socket:t,pane:n}=e;return vZ(typeof t!=`string`||typeof n!=`string`?{ok:!1,error:`pane-session needs a string socket and pane`,code:`BAD_REQUEST`,daemonV:3}:{ok:!0,paneSession:KX.newestWhere(({hints:{tmux:e}})=>e!=null&&e.socket===t&&e.pane===n)})}if(e.kind===`stats`)return vZ({ok:!0,stats:NX.snapshot({gitCache:zX.getStats(),usageCache:BX.getStats(),renderCache:XX.stats,effectCache:GX.getStats(),sessionState:{sessions:HX.size(),observers:HX.observers(),revision:HX.latestRevision()},frameFeeds:KX.getStats(),watchersActive:LX.size(),nextRestartReason:uZ().describeNextRestart(),handlerProbes:PX.list(),clients:FX.list(bE(new Date)),bundle:IX,daemon:uZ().serving()})});if(e.kind===`render`){let n=new Date,r=bE(n),i=n.getTime(),a=[],o=++NX.requestsTotal,s=IZ(e);s.ok&&FX.see(s.req.hookData.session_id,{client:s.req.hints.client??null,rateLimits:s.req.rateLimits,claudeConfigDir:Si(s.req.hints.claudeConfigDir),transcript:jk(s.req.hookData)},r);let c=s.ok?await HZ(s.req,o,r,a).then(({output:e,moves:t,clickShown:n})=>{let r={ok:!0,output:e};return KX.note(s.req.hookData.session_id,s.req,o,{resp:r,drawnAt:i,moves:t,failure:null}),{outcome:{kind:`ok`},resp:r,delivered:n===null?_Z:()=>EK(HX,s.req.hookData.session_id,n)}},e=>({outcome:{kind:`threw`,error:e},resp:xZ(e),delivered:_Z})):LZ(s.problems);c.outcome.kind!==`ok`&&NX.requestsErrored++,EX(a,{timedOut:t()?`Y`:`N`});let{level:l,line:u}=jX(a,c.outcome,Date.now()-i);return N(l,u),{resp:c.resp,exitAfterFlush:null,delivered:c.delivered}}if(e.kind===`click`)return vZ(MZ(e.verb,e.value,xt(e.clientVersion)));if(e.kind===`debug`){if(!pX(e.what))return vZ({ok:!1,error:`unknown debug 'what': ${String(e.what)} (have: ${fX.join(`, `)})`,code:`BAD_REQUEST`,daemonV:3});let t=XX.firstState(),n=t===null?null:{store:t.store,registry:t.registry,config:t.config,compiled:t.compiled,lastRenderBySegment:e.what===`segments`?AZ(t.lastRenderCellsBySegment,t.config.globals.colorCompatibility??`truecolor`):kZ};return vZ({ok:!0,debug:tX(e.what,n)})}throw Error(`no reply for request ${T(e)}`)}function EZ(e,t){let{values:n,tokens:r}=re({args:e.slice(1),options:{config:{type:`string`}},strict:!1,tokens:!0,allowPositionals:!0}),i=[...new Set((r??[]).filter(e=>e.kind===`option`&&e.name!==`config`).map(e=>`--${e.name}`))];return{configFile:TL(t,n.config),unknownFlagsError:i.length>0?`Unknown flags: ${i.join(`, `)}`:null}}const DZ={sessionState:HX,dlog:N,applyUpdate:()=>eZ.act(),doctor:Uq(e=>{let t=[e.projectDir,e.cwd,e.configFile??void 0];XX.reload(...t);let n=XX.getOrCreate(...t);return{layers:n.configLayers,error:n.lastError,warning:n.lastWarning,unused:n.state.unused,config:n.state.config}}),probes:PX,clients:FX,bundle:IX,serving:()=>uZ().serving(),memento:VX,claudeInput:VJ(),history:UX,navigation:WX,configFor:e=>XX.getOrCreate(e.projectDir,e.cwd,e.configFile??void 0).state.config,reloadConfig:e=>XX.reload(e.projectDir,e.cwd,e.configFile??void 0)};DZ.reloadConfig;const OZ={endcaps:`powerline`,colorCompatibility:`truecolor`,wrap:!0,padding:1,width:1/0},kZ=new Map;function AZ(e,t){let n=new Map;for(let[r,i]of e)n.set(r,fg(i,{...OZ,colorCompatibility:t}));return n}const jZ={...RX,history:e=>UX.depth(e)};function MZ(e,t,n){let r=qY.get(e);if(!r)return{ok:!1,error:`unknown click verb: ${e}`,code:`BAD_REQUEST`,daemonV:3};try{return r(t,{...DZ,clientVersion:n}),{ok:!0,output:``}}catch(e){let t=e instanceof q?`BAD_REQUEST`:`RENDER_FAILED`;return{ok:!1,error:String(e instanceof Error?e.message:e),code:t,daemonV:3}}}async function NZ(e){let t=new Date,n=[];try{let{drawn:r,moves:i}=await RZ(e,bE(t),n,`frame`);return{resp:{ok:!0,output:zZ(r,YX.linkFor(e.hookData.session_id,BZ(r)))},drawnAt:t.getTime(),moves:i,failure:null}}catch(e){let{level:r,line:i}=jX(n,{kind:`threw`,error:e},Date.now()-t.getTime());return{resp:xZ(e),drawnAt:t.getTime(),moves:!1,failure:{level:r,line:`frame ${i}`}}}}function PZ(e,t){return Ez(t.config,t=>HX.get(e,t),e=>t.authoredRoots.has(e))}function FZ(e){try{var t=MX();let n=e.hookData.session_id,r=aY(e.requested,HX,n);return PZ(n,t.u(XX.hold(r.projectDir,r.cwd,r.configFile??void 0)).state).lanes}catch(e){t.e=e}finally{t.d()}}function IZ(e){let{report:t}=ZY(e.hookData);for(let e of t.unknownTopLevelFields)N(`info`,`schema: unknown field '${e}' — Anthropic may have added it`);let n=[];for(let e of t.missingRequired)n.push(`missing required field '${e}'`);for(let{path:e,expected:r,got:i}of t.typeMismatches)n.push(`field '${e}' expected ${r}, got ${i}`);if((typeof e.cwd!=`string`||!x(e.cwd))&&n.push(`request 'cwd' is not an absolute path: ${JSON.stringify(e.cwd)}`),(!Array.isArray(e.args)||!e.args.every(e=>typeof e==`string`))&&n.push(`request 'args' is not a list of strings: ${JSON.stringify(e.args)}`),n.length>0)return{ok:!1,problems:n};let r=ft(e),{configFile:i,unknownFlagsError:a}=EZ(e.args,e.cwd);return{ok:!0,req:{...e,hints:r,rateLimits:Ak(e.hookData),requested:{projectDir:e.hookData.workspace.project_dir,cwd:e.cwd,configFile:i??r.configEnv??null},unknownFlagsError:a}}}const LZ=e=>({outcome:{kind:`bad-request`,problems:e},resp:{ok:!1,error:`malformed hookData: ${e.join(`; `)}`,code:`BAD_REQUEST`,daemonV:3},delivered:_Z});async function RZ(e,t,n,r){try{var i=MX();EX(n,{sid:e.hookData.session_id,at:t.toFixed(3)});let{unknownFlagsError:a}=e,o=e.hookData.session_id,s=e.hints,c=pt(e,s),l=mt(c);EX(n,{termCols:String(s.termCols??`?`),termRows:String(s.termRows??`?`),refused:c.map(e=>e.hint).join(`,`)||`-`,client:s.client?.kind??`unreported`,rateLimits:e.rateLimits});let u=aY(e.requested,HX,o),{entry:d,state:f}=i.u(XX.hold(u.projectDir,u.cwd,u.configFile??void 0)),p=s.termCols,m=mX(p??120),h=pg(s.termRows);EX(n,{width:String(m)});let g=t=>HX.get(e.hookData.session_id,t),_=PZ(o,f);EX(n,{lanes:Pa.filter(e=>_.lanes[e]).join(`,`)||`-`});let v=await Jz(e.hookData,t,{...jZ,navigation:e=>WX.depth(e,HX,RB(f.config))},e.cwd,f.neededInputPaths(_.preset),_,s,{...TB(f.config,f.fileHeldSettings,g),configPath:d.configLayers.includes(d.configHome)?d.configHome:null});EX(n,{prompts:String(v.metrics?.messageCount??`-`),nonPrompts:String(v.metrics?.nonPrompts??`-`),pr:jz(v.git)});let y=[],b=Dz(_,m),x=GX.of(o),S=_W(f.config,f.compiled,f.store,f.registry,v,t,b,{perSegmentSink:f.lastRenderCellsBySegment,onRenderWarning:e=>y.push(e)},{...Oz(_),effects:x}),C=OK(HX,o,t,r),w=C.kind===`held`||C.kind===`owed`?C.error:null,ee=w?.text??null,te=[a,l,d.lastError,ee].filter(Boolean).join(`
|
|
490
|
-
`),ne=
|
|
491
|
-
`)),D=
|
|
492
|
-
`}function
|
|
493
|
-
`);return}t.stdout.write(
|
|
494
|
-
`;let t=[`variables (${e.length})`,``],n=e.reduce((e,t)=>Math.max(e,t.name.length),4),r=e.reduce((e,t)=>Math.max(e,(t.source??`—`).length),6),i=e.reduce((e,t)=>Math.max(e,t.type.length),4);for(let a of e){let e=a.ageMs===null?``:` ${
|
|
484
|
+
`}const TJ=e=>({kind:`ok`,value:e}),EJ=e=>({kind:`failed`,reason:e});var DJ=class{arrivals=[];arrive(e){this.arrivals=[...this.arrivals,e].slice(-16)}list(){return this.arrivals}};const OJ=/^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$/;function kJ(e){return OJ.test(e)?e:null}function AJ(e){let t=e.opener();if(t.kind===`failed`)return t;if(t.value===null)return TJ(null);let n=t.value,r=e.script(n);if(r.kind===`failed`)return TJ({app:n,missing:EJ(`its script could not be read (${r.reason})`)});let i=Yi(r.value);return TJ({app:n,missing:i===null?EJ("its script is not one `cc-candybar install` wrote"):TJ([i.node,i.script].filter(t=>!e.exists(t)))})}async function jJ(e,t){let n=e.now()+5e3;for(;e.now()<n;){await e.pause();let n=await e.daemon(),r=n.kind===`ok`?n.value.arrivals.find(e=>e.nonce===t):void 0;if(n.kind===`ok`&&r!==void 0)return{kind:`arrived`,handler:r.handler,bar:n.value.version}}return null}async function MJ(e){if(e.platform!==`darwin`)return{kind:`unsupported`};if(e.sockets.own!==e.sockets.handler)return{kind:`unprobed`,reason:`this shell's daemon is at ${e.sockets.own} (CC_CANDYBAR_SOCKET); the URL handler delivers links to ${e.sockets.handler}`};let t=await e.daemon();if(t.kind===`failed`)return{kind:`unprobed`,reason:`the daemon could not be asked whether a link arrives: ${t.reason}`};let n=e.nonce(),r=e.open(`${kn}://${er}/${n}`);return(r===null?await jJ(e,n):null)??{kind:`lost`,unopened:r,opener:AJ(e)}}function NJ(e,t,n){let r=Re({bin:t,args:[...n],category:e,timeoutMs:5e3});return r.ok?TJ(r.stdout):EJ(r.stderr.trim()||r.error||r.reason)}const PJ=`ObjC.import("AppKit");var u = $.NSWorkspace.sharedWorkspace.URLForApplicationToOpenURL($.NSURL.URLWithString("${kn}://probe"));u.isNil() ? "" : u.path.js`;async function FJ(){let e=await hJ();if(e.kind!==`ok`)return EJ(Pt(e).split(`
|
|
485
|
+
`).join(` — `));let t=gJ(e.value,[`handlerProbes`]);if(t!==null)return EJ(t);let{version:n,handlerProbes:r}=e.value;return TJ({version:n,arrivals:r})}function IJ(){return{platform:process.platform,sockets:{own:Ke(),handler:qe()},now:Date.now,nonce:oe,daemon:FJ,open:e=>{let t=NJ(`doctor.open`,`/usr/bin/open`,[`-g`,e]);return t.kind===`ok`?null:t.reason},pause:()=>new Promise(e=>setTimeout(e,100)),opener:()=>{let e=NJ(`doctor.launch-services`,`/usr/bin/osascript`,[`-l`,`JavaScript`,`-e`,PJ]);if(e.kind===`failed`)return e;let t=e.value.trim();return TJ(t===``?null:t)},script:e=>NJ(`doctor.osadecompile`,`/usr/bin/osadecompile`,[Xi(e)]),exists:s.existsSync}}const LJ=/^─{20,}/,RJ=/^❯(\s|$)/,zJ=/›\s*stashed$/;function BJ(e){if(e.inMode)return{kind:`in-mode`};let t=e.screen.map(e=>e.trimEnd()),n=t.flatMap((e,t)=>LJ.test(e)?[t]:[]).at(-2);return n===void 0||!RJ.test(t[n+1]??``)?{kind:`no-prompt`}:zJ.test(t[n-1]??``)?{kind:`stashed`}:{kind:`ready`}}const VJ={"in-mode":`the Claude Code pane is in tmux copy mode — leave it (q) and click again`,stashed:`Claude Code is holding a stashed prompt (ctrl+s) — restore or send it, then click again`,"no-prompt":`Claude Code is not at its prompt (a dialog or picker is open) — close it and click again`};function HJ(e,t,n){if(t===void 0)return{kind:`refused`,reason:`this session's statusline client reports no tmux facts (it predates this daemon) — rebuild or reinstall cc-candybar`};if(t===null)return{kind:`refused`,reason:`this Claude Code is not running inside tmux — the bar can only type into a tmux pane`};let r=BJ(e.read(t));if(r.kind!==`ready`)return{kind:`refused`,reason:VJ[r.kind]};let i=e.type(t,n);return i.kind===`typed`?{kind:`typed`,pane:t.pane}:i}const UJ=`cc-candybar-slash`;function WJ(e,t,n,r){let i=cH(e,t,n,r);if(i.kind===`failed`)throw Error(i.reason);return i}function GJ(e){let t=WJ(e,`claude-input.read`,[`display`,`-p`,`-t`,e.pane,`#{pane_in_mode}`,`;`,`capture-pane`,`-p`,`-t`,e.pane]);if(t.kind===`rate-limited`)throw Error(t.reason);let[n=``,...r]=t.stdout.split(`
|
|
486
|
+
`);return{inMode:n!==`0`,screen:r}}function KJ(e,t){let n=WJ(e,`claude-input.type`,[`load-buffer`,`-b`,UJ,`-`,`;`,`send-keys`,`-t`,e.pane,`C-s`,`;`,`paste-buffer`,`-p`,`-d`,`-b`,UJ,`-t`,e.pane,`;`,`send-keys`,`-t`,e.pane,`Enter`],t);return n.kind===`ok`?{kind:`typed`}:{kind:`refused`,reason:`cc-candybar typed a command moments ago — click again in a second (${n.reason})`}}function qJ(){return{read:GJ,type:KJ}}function JJ(e){if(!e)throw new q(`session id is required`);if(e.includes(`/`)||e.includes(`..`))throw new q(`invalid session id "${e}"`);return e}function YJ(e){return XJ(()=>decodeURIComponent(e))}function XJ(e){try{return e()}catch(e){throw e instanceof URIError?new q(`malformed wire encoding: ${e.message}`):e}}function ZJ(e,t){let n=Re({bin:`/usr/bin/pbcopy`,stdinInput:e,category:`click.pbcopy`});if(!n.ok){if(n.reason===`rate-limited`){t.dlog(`warn`,`click.pbcopy rate-limited: ${n.error??``}`);return}throw Error(`pbcopy failed (${n.reason}, exit ${n.exitCode??`null`})`)}}const QJ=(e,t)=>ZJ(YJ(e),t),$J=(e,t)=>{let n=Re({bin:`/usr/bin/open`,args:[`-a`,`Visual Studio Code`,YJ(e)],category:`click.open`});if(!n.ok){if(n.reason===`rate-limited`){t.dlog(`warn`,`click.open rate-limited: ${n.error??``}`);return}throw Error(`open -a "Visual Studio Code" failed (${n.reason}, exit ${n.exitCode??`null`})`)}},eY=(e,t)=>ZJ(YJ(e),t),tY=(e,t)=>ZJ(YJ(e),t),nY=(e,t)=>{let n=JJ(YJ(e));t.navigating.get(n,`toolbar-expanded`)?t.navigating.clear(n,`toolbar-expanded`):t.navigating.set(n,`toolbar-expanded`,`1`)},rY=(e,t)=>{let[n=``,...r]=XJ(()=>ir(e)),i=JJ(n),a=UB(_Y(t,i));if(r.length===0)throw new q(`set-state: <key>/<value> is required (have keys: ${a.listKeys().join(`, `)})`);if(r.length%2!=0)throw new q(`set-state: expected even-count <key>/<value> pairs, got ${r.length} segment(s) after session id (have keys: ${a.listKeys().join(`, `)})`);let o=[];for(let e=0;e<r.length;e+=2){let t=r[e],n=r[e+1];if(!t)throw new q(`set-state: empty key at pair ${e/2+1} (expected <sessionId>/<key>/<value>[/<key>/<value>...] segments)`);let i=a.validate(t,n);if(!i.ok)throw new q(`set-state: pair ${e/2+1}: ${i.reason}`);o.push({key:t,value:i.value})}sY(t,i,`set-state`,o),t.navigating.setBatch(i,o);let s=o.map(e=>`${e.key}=${e.value}`).join(` `);t.dlog(`info`,`set-state: ${s} (session=${i})`)},iY=/^-?\d+$/;function aY(e,t,n,r){let i=e+t;return i>r?e===r?n:r:i<n?e===n?r:n:i}const oY=(e,t)=>{let[n=``,r=``,i=``]=XJ(()=>ir(e)),a=JJ(n);if(!r)throw new q(`step-state: <key> is required (shape: <sessionId>/<key>/<by>)`);if(!iY.test(i))throw new q(`step-state: delta must be an integer, got "${i}"`);let o=parseInt(i,10),s=_Y(t,a),c=UB(s),l=c.rangeParamsFor(r);if(!l)throw new q(`step-state: key "${r}" is not a bounded (range) state key (have keys: ${c.listKeys().join(`, `)})`);let u=t.sessionState.get(a,r),d=u&&iY.test(u)?cY(l,parseInt(u,10)):lY(`step-state`,r,l,KB(s,e=>t.sessionState.get(a,e),r)),f=aY(d,o,l.min,l.max),p=c.validate(r,String(f));if(!p.ok)throw new q(`step-state: ${p.reason}`);sY(t,a,`step-state`,[{key:r,value:p.value}]),t.navigating.set(a,r,p.value),t.dlog(`info`,`step-state: ${r} ${d}→${p.value} (by ${o}, session=${a})`)};function sY(e,t,n,r){let i=r.filter(e=>e.key.startsWith(rk));if(i.length===0)return;let a=SB(_Y(e,t),n=>e.sessionState.get(t,n),i);if(a.length>0)throw new q(`${n}: refused — ${a.join(`; `)}`)}function cY(e,t){return Math.max(e.min,Math.min(e.max,t))}function lY(e,t,n,r){if(r===null)return n.min;if(!iY.test(r))throw new q(`${e}: "${t}" shows ${JSON.stringify(r)} before any click, not an integer to step`);return cY(n,parseInt(r,10))}const uY=`render-origin`;function dY(e,t,n){return{...e,configFile:t.get(n,`config-override`)??e.configFile}}function fY(e){return JSON.stringify(e)}function pY(e){let t;try{t=JSON.parse(e)}catch{throw new q(`render origin is not JSON: ${e}`)}if(typeof t!=`object`||!t)throw new q(`render origin is not an object: ${e}`);let{projectDir:n,cwd:r,configFile:i}=t;if(typeof n!=`string`||typeof r!=`string`||i!==null&&typeof i!=`string`)throw new q(`render origin has the wrong shape: ${e}`);return{projectDir:n,cwd:r,configFile:i}}function mY(e,t){let n=hY(e,t);if(n===null)throw new q(`session ${t} has not rendered yet — no config to act on`);return n}function hY(e,t){let n=e.sessionState.get(t,uY);return n===null?null:dY(pY(n),e.sessionState,t)}function gY(e,t,n){let r=hY(e,t);if(r===null)return;let{path:i}=vY(r);n.some(e=>e.kind===`file`&&e.file===i)&&e.reloadConfig(r)}function _Y(e,t){return e.configFor(mY(e,t))}function vY(e){return gR(e.projectDir,e.cwd,e.configFile??void 0)}function yY(e,t){return{record:(n,r,i)=>e.journal.file(t,n,r,i),logger:e.dlog}}const bY=(e,t)=>{let[n=``,r=``,i=``]=XJ(()=>ir(e)),a=JJ(n),o=mY(t,a),s=t.configFor(o),c=QN(s);if(!r)throw new q(`set-config: <key>/<value> is required (have keys: ${c.listKeys().join(`, `)})`);let l=c.validate(r,i);if(!l.ok)throw new q(`set-config: ${l.reason}`);let u=vY(o),d=bB(s,e=>t.sessionState.get(a,e),r);HG(yY(t,a),u,[[d.key,l.value]]),t.reloadConfig(o),t.dlog(`info`,`set-config: ${d.key}=${l.value} → ${u.path} (session=${a})`)},xY=(e,t)=>{let[n=``,r=``,i=``]=XJ(()=>ir(e)),a=JJ(n);if(!r)throw new q(`step-config: <key> is required (shape: <sessionId>/<key>/<by>)`);if(!iY.test(i))throw new q(`step-config: delta must be an integer, got "${i}"`);let o=parseInt(i,10),s=mY(t,a),c=t.configFor(s),l=QN(c),u=l.rangeParamsFor(r);if(!u)throw new q(`step-config: key "${r}" is not a bounded (range) config key (have keys: ${l.listKeys().join(`, `)})`);let d=vY(s),f=bB(c,e=>t.sessionState.get(a,e),r),p=VG(d.path,f.key),m=typeof p==`number`?cY(u,p):lY(`step-config`,r,u,eP(f.globals,r)),h=aY(m,o,u.min,u.max),g=l.validate(r,String(h));if(!g.ok)throw new q(`step-config: ${g.reason}`);HG(yY(t,a),d,[[f.key,g.value]]),t.reloadConfig(s),t.dlog(`info`,`step-config: ${f.key} ${m}→${g.value} (by ${o}) → ${d.path} (session=${a})`)},SY=(e,t)=>{let[n=``]=XJ(()=>ir(e)),r=JJ(n),i=mY(t,r),a=t.configFor(i),o=e=>t.sessionState.get(r,e),s=vB(a,o),c=xB(a,o);if(s.length+c.length===0){t.dlog(`info`,`save: nothing unsaved (session=${r})`);return}let l=UB(a),u=s.map(e=>{let t=l.validate(e.sessionKey,e.value);if(!t.ok)throw new q(`save: ${t.reason}`);return[e.target,t.value]});wY(`save`,l,c);let d=vY(i);UG(yY(t,r),d,u,c),t.reloadConfig(i);for(let e of[...s.map(e=>e.sessionKey),...c.map(e=>e.key)])t.sessionState.clear(r,e);t.dlog(`info`,`save: ${[...u.map(([e,t])=>`${e}=${t}`),...c.map(CY)].join(` `)} → ${d.path} (session=${r})`)},CY=e=>`${e.preset}/${e.id}.settings.${e.setting}=${y_(e.value)}`;function wY(e,t,n){for(let r of n){let n=t.validate(r.key,y_(r.value));if(!n.ok)throw new q(`${e}: ${n.reason}`)}}const TY=(e,t)=>{let[n=``]=XJ(()=>ir(e)),r=JJ(n),i=mY(t,r),a=t.configFor(i),o=TB(a,e=>t.sessionState.get(r,e)),s=UB(a),c=o.picks.map(e=>{let t=s.validate(e.sessionKey,e.value);if(!t.ok)throw new q(`save-preset: ${t.reason}`);return[e.configKey,t.value]});wY(`save-preset`,s,o.placements);let l=vY(i),u=XG(yY(t,r),l,o.from,o.globals,c,o.placements);t.reloadConfig(i);for(let e of[...Va.map(e=>e.sessionKey),...o.placements.map(e=>e.key)])t.sessionState.clear(r,e);t.sessionState.set(r,Ba.preset.sessionKey,u),t.dlog(`info`,`save-preset: ${[`${u} from=${o.from}`,...c.map(([e,t])=>`${e}=${t}`),...o.placements.map(CY)].join(` `)} → ${l.path} (session=${r})`)},EY=(e,t)=>{let[n=``]=XJ(()=>ir(e)),r=JJ(n),i=mY(t,r),a=DB(t.configFor(i),e=>t.sessionState.get(r,e));if(a.kind===`rule`)throw new q(`save-theme-default: the theme is chosen by a rule (globals.palette), so there is no name to save as a theme's default — pick one in the menu first`);let o=vY(i);ZG(yY(t,r),o,a.theme,a.look),t.reloadConfig(i);let s=new Set(vB(t.configFor(i),e=>t.sessionState.get(r,e)).map(e=>e.sessionKey)),c=i_.map(e=>Ba[e].sessionKey).filter(e=>!s.has(e));for(let e of c)t.sessionState.clear(r,e);t.dlog(`info`,`save-theme-default: ${a.theme} ${i_.map(e=>`${e}=${a.look[e]}`).join(` `)} → ${o.path} (session=${r})`)},DY=(e,t)=>{let[n=``,r=``]=XJ(()=>ir(e)),i=JJ(n);if(!r)throw new q(`delete-preset: <name> is required (shape: <sessionId>/<name>)`);let a=mY(t,i),o=vY(a);QG(yY(t,i),o,r),t.reloadConfig(a);let s=Ba.preset.sessionKey;t.sessionState.get(i,s)===r&&t.sessionState.clear(i,s),t.dlog(`info`,`delete-preset: ${r} ← ${o.path} (session=${i})`)},OY=(e,t)=>{let[n=``,...r]=XJ(()=>ir(e)),i=JJ(n),a=mY(t,i),o=QN(t.configFor(a)).listKeys(),s=r.length===0?[``]:r.filter(e=>!o.includes(e));if(s.length>0)throw new q(`reset-config: unknown config key "${s.join(`", "`)}" (have: ${o.join(`, `)})`);let c=vY(a),l=r.map(OB),u=l.flatMap(e=>e.fileKeys),d=l.flatMap(e=>e.sessionKeys);qG(yY(t,i),c,u),t.reloadConfig(a);for(let e of d)t.sessionState.clear(i,e);t.dlog(`info`,`reset-config: ${[...u,...d.map(e=>`session:${e}`)].join(` `)} ← ${c.path} (session=${i})`)};function kY(e,t){let n=(e,t)=>[...$g(V_(e,t).node)].filter(e=>e.kind===`segment`),r=new Set(R_(t.presets).flatMap(e=>n(t,e).map(t=>ik(JE(e),Yg(t)))));return R_(e.presets).flatMap(t=>n(e,t).map(e=>({member:ik(JE(t),Yg(e)),node:e})).filter(({member:e})=>!r.has(e)))}function AY(e,t){return e.flatMap(({member:e,node:n})=>[...Object.values(n.drafts??{}).map(e=>e.key),...e===t?[QO]:[]])}const jY=(e,t)=>{let[n=``,r=``,i=``]=XJ(()=>ir(e)),a=JJ(n),o=mY(t,a),s=t.configFor(o),c=QN(s);if(!r)throw new q(`apply-layout-op: <key>/<op> is required (have: ${c.listKeys().join(`, `)})`);let l=c.validate(r,i);if(!l.ok)throw new q(`apply-layout-op: ${l.reason}`);let u=RN(l.value);if(u===null)throw new q(`apply-layout-op: "${l.value}" is not a layout op token`);let d=vY(o),f=$G(yY(t,a),d,r,u);t.reloadConfig(o);let p=AY(kY(s,t.configFor(o)),t.sessionState.get(a,QO)).filter(e=>t.sessionState.get(a,e)!==null);for(let e of p)t.sessionState.clear(a,e);t.dlog(`info`,`apply-layout-op: ${r} ${l.value} → ${d.path} placed=${JSON.stringify(f)} released=${JSON.stringify(p)} (session=${a})`)},MY=(e,t)=>{let[n=``]=XJ(()=>ir(e)),r=JJ(n);t.journal.commit();let i=t.history.undo(r);gY(t,r,i),t.dlog(`info`,`undo: restored ${xK(i)} (session=${r})`)},NY=(e,t)=>{let n=JJ(YJ(e)),{step:r,discarded:i}=t.navigation.back(n,t.sessionState,UB(_Y(t,n))),a=r.map(e=>`${e.key}=${e.before??`∅`}`).join(` `);t.dlog(`info`,`back: ${a} discarded=${i} (session=${n})`)},PY=(e,t)=>{let n=JJ(YJ(e));t.journal.commit();let r=t.history.rewind(n);gY(t,n,r),t.dlog(`info`,`rewind: put back ${xK(r)||`nothing`} as edit mode found it (session=${n})`)},FY=(e,t)=>{let[n=``]=XJ(()=>ir(e)),r=JJ(n);t.journal.commit();let i=t.history.redo(r);gY(t,r,i),t.dlog(`info`,`redo: re-applied ${xK(i)} (session=${r})`)},IY=(e,t)=>{JJ(YJ(e)),t.applyUpdate()},LY=`client-hints`;function RY(e,t){let n=e.sessionState.get(t,LY);if(n===null)throw new q(`session ${t} has not rendered yet — no client facts are recorded for it`);let r;try{r=JSON.parse(n)}catch{throw new q(`client hints record is not JSON: ${n}`)}if(typeof r!=`object`||!r)throw new q(`client hints record is not an object: ${n}`);return ft(r)}function zY(e,t,n){let r=HA(n);e.sessionState.setBatch(t,tj(r)),e.dlog(`info`,`doctor: ${r.map(e=>`${e.check.name}=${e.verdict.ok?`ok`:`failed(${1+(e.verdict.more?.length??0)})`}`).join(` `)} ${$A(n.nerdFont,n.marks)} ${KA(n.terminal,n.clicked)} ${qA(n.terminal,n.termCols)} ${JA(n.install)} ${YA(n.daemon)} ${XA(n.data)} ${QA(n.transcripts)} ${ZA(n.frames)} (session=${t})`)}function BY(e,t){let n=e.clients.ofSession(t),r;try{r=dJ(e.doctor,RY(e,t),mY(e,t),n=>e.sessionState.get(t,n),{kind:`ok`,value:e.serving()},{kind:`ok`,value:n.map(e=>e.rateLimits)},{kind:`ok`,value:n.map(e=>e.transcript)},{kind:`ok`,value:n.map(({role:e,frame:t})=>({role:e,frame:t}))})}catch(e){throw e instanceof VK?new q(e.message):e}return{...r,urlHandler:cJ(e.clientVersion),install:Bq(e.doctor.install,e.bundle,n.map(e=>e.client)),askedBy:`click`,clicked:VY(e,r)}}function VY(e,{terminal:t,clicked:n}){let r=t.kind===`seen`?Xk(t.identified):null;if(r===null||n.kind===`failed`)return n;try{e.doctor.clicked.record(r)}catch(t){return e.dlog(`warn`,`doctor: clicked terminal not filed for ${JSON.stringify(r)}: ${t instanceof Error?t.message:String(t)}`),n}return{kind:`ok`,value:n.value.includes(r)?n.value:[...n.value,r]}}const HY=(e,t)=>{let n=JJ(YJ(e));zY(t,n,BY(t,n))},UY=(e,t)=>{let n=kJ(YJ(e));if(n===null)throw new q(`doctor-probe: the value is not a probe nonce`);t.probes.arrive({nonce:n,handler:t.clientVersion}),t.dlog(`info`,`doctor-probe: arrived nonce=${n} handler=${t.clientVersion??`unreported`}`)},WY=(e,t)=>{let[n=``,r=``]=XJ(()=>ir(e)),i=JJ(n),a=UA(r);if(a===void 0)throw new q(`doctor-fix: unknown check "${r}"`);let o=BY(t,i),s=a.probe(o);if(s.ok||s.fix===void 0)throw new q(`doctor-fix: ${a.label} — ${s.ok?`nothing to fix`:s.reason}`);let c=fJ(t.doctor,s.fix,o);t.dlog(`info`,`doctor-fix: ${a.name} → ${nA(s.fix)} (session=${i})`),zY(t,i,c)},GY=(e,t)=>{let[n=``,r=``,i=``]=XJ(()=>ir(e)),a=JJ(n),o=UA(r);if(o===void 0)throw new q(`doctor-mark: unknown check "${r}"`);if(!eA.includes(i))throw new q(`doctor-mark: the mark is ${JSON.stringify(i)}, not ${eA.join(` or `)}`);let s=BY(t,a),c=o.probe(s);if(c.ok||c.sighting===void 0)throw new q(`doctor-mark: ${o.label} — ${c.ok?`nothing to mark`:`shows nothing to look at`}`);if(s.marks.kind===`failed`)throw new q(`doctor-mark: ${s.marks.reason}`);let l=[o.name,c.sighting.id,i];t.doctor.marks.record(...l),t.dlog(`info`,`doctor-mark: ${o.name} ${i} on ${c.sighting.id} (session=${a})`),zY(t,a,{...s,marks:{kind:`ok`,value:zK(s.marks.value,...l)}})},KY=(e,t)=>{let[n=``,...r]=XJ(()=>ir(e)),i=JJ(n),a=mY(t,i),o=Object.values(t.configFor(a).actions).filter(e=>`ceiling`in e).find(e=>{let t=eI(e);return t.length===r.length&&t.every((e,t)=>e===r[t])});if(o===void 0)throw new q(`ceiling: "${r.join(` `)}" is not a move this config declares`);let s=o.ceiling===`set`?{kind:`set`,to:o.to}:{kind:`clear`},c=_z({sessionId:i,projectDir:a.projectDir,cwd:a.cwd},RY(t,i));t.memento.move(c,s),t.dlog(`info`,`ceiling: ${r.join(` `)} (session=${i} claudeConfigDir=${c.claudeConfigDir})`)},qY=(e,t)=>{let[n=``,r=``]=XJ(()=>ir(e)),i=JJ(n),a=Object.values(t.configFor(mY(t,i)).actions).filter(e=>`slash`in e),o=a.find(e=>e.slash===r);if(o===void 0)throw new q(`${JSON.stringify(r)} is not a command this config declares (it declares: ${[...new Set(a.map(e=>e.slash))].join(`, `)||`none`})`);let s=HJ(t.claudeInput,RY(t,i).tmux,o.slash);if(s.kind===`refused`)throw t.dlog(`warn`,`slash: ${r} refused — ${s.reason} (session=${i})`),new q(`${r} was not typed: ${s.reason}`);t.dlog(`info`,`slash: typed ${r} into ${s.pane} (session=${i})`)},JY=`config-override`,YY=new Map([[Nn,QJ],[`load-config`,(e,t)=>{let n=e.indexOf(`/`);if(n===-1)throw new q(`load-config: expected <sessionId>/<path> (missing separator)`);let r=JJ(XJ(()=>decodeURIComponent(e.slice(0,n)))),i=XJ(()=>decodeURIComponent(e.slice(n+1))).trim();if(i!==``){if(!i.startsWith(`/`))throw new q(`load-config: path must be absolute, got "${i}"`);if(!/\.(json5?|json)$/.test(i))throw new q(`load-config: path must end with .json5 or .json, got "${i}"`)}i===``?(t.sessionState.clear(r,JY),t.dlog(`info`,`load-config: override cleared (session=${r})`)):(t.sessionState.set(r,JY,i),t.dlog(`info`,`load-config: ${i} (session=${r})`))}],[Pn,$J],[jn,rY],[Mn,oY],[Rn,bY],[zn,xY],[Wn,OY],[Bn,SY],[Vn,TY],[Hn,EY],[Un,DY],[Gn,jY],[Kn,MY],[qn,FY],[Jn,NY],[Yn,PY],[In,eY],[Ln,tY],[Fn,nY],[Xn,IY],[Zn,HY],[Qn,WY],[$n,GY],[er,UY],[tr,KY],[nr,qY]]),XY=new Set([jn,Mn,Rn,zn,Wn,Bn,Vn,Hn,Un,Gn,Kn,qn,Jn,Yn,Fn,Xn,Zn,Qn,$n,tr,nr]),ZY=(e,t)=>{let n=[],r=!1,i=null;for(let{verb:a,value:o}of sr(ar(e))){if(!i&&XY.has(a)){let e=ir(o);e.length>0&&e[0]&&(i=e[0])}let e=YY.get(a);if(!e){n.push(`unknown effect verb "${a}"`);continue}try{e(o,t)}catch(e){e instanceof q||(r=!0),n.push(`${a}: ${e instanceof Error?e.message:String(e)}`)}}if(n.length>0){i&&MK(t.sessionState,i,n.join(`
|
|
487
|
+
`),yE(new Date));let e=`dispatch: ${n.join(`; `)}`;throw r?Error(e):new q(e)}};function QY(e){return(t,n)=>{let r=n.history.begin(),i=n.navigation.begin(r.sessionState),a=[];try{e(t,{...n,sessionState:r.sessionState,journal:r,navigating:i.sessionState})}catch(e){a.push(e)}i.commit();try{r.commit()}catch(e){a.push(e)}if(a.length===1)throw a[0];if(a.length>1)throw Error(a.map(e=>String(e.message??e)).join(`; `))}}const $Y=new Map([...YY,[An,ZY]].map(([e,t])=>[e,QY(t)]));Object.freeze([...$Y.keys()]);const eX=new Set([`hook_event_name`,`session_id`,`session_name`,`transcript_path`,`cwd`,`model`,`workspace`,`version`,`output_style`,`cost`,`context_window`,`exceeds_200k_tokens`,`effort`,`thinking`,`rate_limits`,`vim`,`agent`,`worktree`]),tX=[[`session_id`,`string`],[`transcript_path`,`string`],[`cwd`,`string`],[`model`,`object`],[`model.id`,`string`],[`model.display_name`,`string`],[`workspace`,`object`],[`workspace.current_dir`,`string`],[`workspace.project_dir`,`string`]],nX=[[`workspace.added_dirs`,`string-list`]];function rX(e){let t={missingRequired:[],typeMismatches:[],unknownTopLevelFields:[]},n=typeof e==`object`&&e&&!Array.isArray(e)?e:{};for(let[e,r]of tX){let i=oX(n,e);if(i==null)t.missingRequired.push(e);else{let n=iX(i);n!==r&&t.typeMismatches.push({path:e,expected:r,got:n})}}for(let[e,r]of nX){let i=oX(n,e),a=i===void 0?r:aX(i);a!==r&&t.typeMismatches.push({path:e,expected:r,got:a})}for(let e of Object.keys(n))eX.has(e)||t.unknownTopLevelFields.push(e);return{data:e,report:t}}function iX(e){return Array.isArray(e)?`array`:typeof e==`string`&&!e.isWellFormed()?`ill-formed string`:typeof e}function aX(e){return Array.isArray(e)&&e.every(e=>iX(e)===`string`)?`string-list`:iX(e)}function oX(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n||Array.isArray(n))return;n=n[e]}return n}function sX(e,t){switch(e){case`vars`:return{what:e,vars:cX(t)};case`segments`:return{what:e,segments:pX(t)};case`config`:return{what:e,config:_X(t)}}}function cX(e){if(e===null)return[];let{store:t,registry:n,config:r}=e,i=dX(r),a=t.names().sort(),o=[];for(let e of a){let r=t.getNode(e),a=lX(r),s=n.getLastError(e);o.push({name:e,source:i.get(e)??null,...a,lastError:s===void 0?null:{timestampMs:s.timestamp,message:s.message},ageMs:uX(r.lastUpdatedMs())})}return o}function lX(e){if(e.kind!==`document`)try{return{type:e.type,value:e.read()}}catch(t){return{type:e.type,value:t instanceof Error?t.message:String(t)}}let t=e.read();switch(t.kind){case`ok`:return{type:`document`,value:JSON.stringify(t.value)};case`absent`:return{type:`document`,value:`(not yet scanned)`};case`failed`:return{type:`document`,value:t.reason}}}function uX(e){return e===null?null:Math.max(0,Date.now()-e)}function dX(e){let t=new Map;for(let[n,r]of Object.entries(e.variables))t.set(n,fX(r));for(let[n,r]of Object.entries(e.segments))if(r.vars)for(let[e,i]of Object.entries(r.vars))t.set(`${n}.${e}`,fX(i));return t}function fX(e){return e.kind}function pX(e){if(e===null)return[];let{store:t,config:n,lastRenderBySegment:r}=e,i=new Set(t.names()),a=hX(n),o=mX(n),s=[];for(let e of a){let t=n.segments[e];t&&s.push({name:e,description:t.description??null,template:t.template,referencedVars:gX(t.template,n.helpers,i),placements:(o.get(e)??[]).map(e=>({id:e,lastRender:r.get(e)??null}))})}return s}function mX(e){let t=new Map;for(let n of R_(e.presets))for(let r of $g(V_(e,n).node)){if(r.kind!==`segment`)continue;let e=t.get(r.name)??[],n=Yg(r);e.includes(n)||t.set(r.name,[...e,n])}return t}function hX(e){let t=[],n=new Set;for(let r of $g(j_(e.root)))r.kind===`segment`&&e.segments[r.name]&&!n.has(r.name)&&(t.push(r.name),n.add(r.name));for(let r of Object.keys(e.segments))n.has(r)||(t.push(r),n.add(r));return t}function gX(e,t,n){let r=new Set;for(let i of lv(e,t).keys()){if(n.has(i)){r.add(i);continue}let e=i.split(`.`);for(;e.length>1;){e.pop();let t=e.join(`.`);if(n.has(t)){r.add(t);break}}}return Array.from(r).sort()}function _X(e){return e===null?null:e.config}const vX=[`vars`,`segments`,`config`];function yX(e){return typeof e==`string`&&vX.includes(e)}function bX(e){return Math.max(1,e-2)}const xX={moving:1e3/30,still:1e3};var SX=class{requests=new Map;feeds=new Map;stopWatching=null;drawn=0;pushed=0;refused=0;lookups=0;found=0;constructor(e){this.deps=e}note(e,t,n,r){let i=this.requests.get(e);if(i!==void 0&&i.order>n)return;this.requests.delete(e),this.requests.set(e,{req:t,order:n});for(let e of this.requests.keys()){if(this.requests.size<=256)break;this.feeds.has(e)||this.requests.delete(e)}let a=this.feeds.get(e);if(a===void 0)return;if(a.last!==null&&r.drawnAt<a.last.drawnAt){this.wake(e);return}if(a.noted++,this.countFailure(a,r),this.push(a,r),this.feeds.get(e)!==a)return;let o=this.deps.now();switch(a.phase.kind){case`drawing`:a.phase.superseded={frame:r,at:o};return;case`due`:clearTimeout(a.phase.timer);break;case`waiting`:break}this.schedule(a,r,o,o)}subscribe(e,t){let n=this.requests.get(e);if(n!==void 0&&!this.deps.lanes(n.req)[t.lane])return this.refuse(e,t),()=>{};let r=this.feeds.get(e)??this.open(e);return r.sinks.add(t),r.last!==null&&t.frame(r.last.resp,r.last.bytes),this.deps.log(`info`,`feed sid=${JSON.stringify(e)} subscribed lane=${t.lane} subscribers=${r.sinks.size} data=${this.requests.has(e)?`Y`:`N`}`),()=>this.unsubscribe(r,t)}wake(e){let t=this.feeds.get(e);if(t!==void 0)switch(t.phase.kind){case`drawing`:t.phase.again=!0;return;case`due`:clearTimeout(t.phase.timer),this.draw(t);return;case`waiting`:this.draw(t);return}}wakeWhere(e){for(let{sessionId:t,req:n}of this.watched())e(n)&&this.wake(t)}newestWhere(e){let t=null;for(let[n,{req:r,order:i}]of this.requests)e(r)&&(t===null||i>t.order)&&(t={sessionId:n,order:i});return this.lookups++,t!==null&&this.found++,t?.sessionId??null}watched(){return[...this.feeds.keys()].flatMap(e=>{let t=this.requests.get(e);return t===void 0?[]:[{sessionId:e,req:t.req}]})}getStats(){let e=0;for(let t of this.feeds.values())e+=t.sinks.size;return{feeds:this.feeds.size,subscribers:e,drawn:this.drawn,pushed:this.pushed,refused:this.refused,lookups:this.lookups,found:this.found}}open(e){let t=this.deps.now(),n={sessionId:e,sinks:new Set,unwatch:this.deps.watch(e,()=>this.wake(e)),phase:{kind:`waiting`},last:null,since:t,drawn:0,noted:0,moving:0,unseen:0,failed:0,pushed:0,drawMs:0,summarizedAt:t};return this.feeds.set(e,n),this.stopWatching??=this.deps.watching(),this.draw(n),n}unsubscribe(e,t){!e.sinks.delete(t)||e.sinks.size>0||(e.phase.kind===`due`&&clearTimeout(e.phase.timer),e.unwatch(),this.feeds.delete(e.sessionId),this.feeds.size===0&&(this.stopWatching?.(),this.stopWatching=null),this.summarize(e,`closed`))}draw(e){return this.step(e).catch(t=>{if(this.deps.log(`error`,`feed sid=${JSON.stringify(e.sessionId)} threw: ${T(t)}`),this.feeds.get(e.sessionId)!==e)return;let n=this.deps.now();this.schedule(e,null,n,n)})}async step(e){let t=this.requests.get(e.sessionId);if(t===void 0){e.phase={kind:`waiting`};return}let{req:n}=t,r={kind:`drawing`,again:!1,superseded:null};e.phase=r;let i=this.deps.now(),a=await this.deps.render(n),o=this.deps.now();if(this.drawn++,e.drawn++,e.drawMs+=o-i,this.feeds.get(e.sessionId)!==e||(this.countFailure(e,a),this.requests.get(e.sessionId)===t&&(this.push(e,a),this.feeds.get(e.sessionId)!==e)))return;if(o-e.summarizedAt>=6e4&&this.summarize(e,`running`),r.again){this.draw(e);return}let s=r.superseded??{frame:a,at:i};this.schedule(e,s.frame,s.at,o)}schedule(e,t,n,r){let i=t?.moves===!0,a=i&&this.shown(e);a&&e.moving++,i&&!a&&e.unseen++;let o=a?this.deps.periods.moving:this.deps.periods.still;e.phase={kind:`due`,timer:setTimeout(()=>void this.draw(e),Math.max(0,n+o-r))}}shown(e){let t=this.requests.get(e.sessionId);return t===void 0||this.deps.shown(t.req)}countFailure(e,t){t.failure!==null&&e.failed++}push(e,t){let n=this.requests.get(e.sessionId);if(n!==void 0){let t=this.deps.lanes(n.req);for(let n of[...e.sinks])t[n.lane]||(this.unsubscribe(e,n),this.refuse(e.sessionId,n))}if(e.sinks.size===0)return;let{resp:r}=t,i=JSON.stringify(r);if(e.last?.bytes!==i){e.last={resp:r,bytes:i,drawnAt:t.drawnAt},this.pushed++,e.pushed++,t.failure!==null&&this.deps.log(t.failure.level,t.failure.line);for(let t of e.sinks)t.frame(r,i)}}refuse(e,t){this.refused++,this.deps.log(`info`,`feed sid=${JSON.stringify(e)} refused lane=${t.lane} switched-off`),t.refused({ok:!1,error:Ra(t.lane),code:`SWITCHED_OFF`,daemonV:3})}summarize(e,t){let n=this.deps.now();this.deps.log(`info`,`feed sid=${JSON.stringify(e.sessionId)} ${t} subscribers=${e.sinks.size} lanes=${[...e.sinks].map(e=>e.lane).join(`,`)||`-`} for=${Math.round((n-e.since)/1e3)}s drawn=${e.drawn} noted=${e.noted} moving=${e.moving} unseen=${e.unseen} failed=${e.failed} pushed=${e.pushed} meanDraw=${e.drawn===0?`-`:(e.drawMs/e.drawn).toFixed(2)}ms`),e.summarizedAt=n}};function CX(e){let t=null;return e.on(`drain`,()=>{let n=t;t=null,n!==null&&e.write(n)}),n=>{if(e.writable){if(e.writableNeedDrain){t=n;return}e.write(n)}}}const wX=`#{pane_id} #{session_id} #{session_attached} #{window_active} #{window_zoomed_flag} #{pane_active}`,TX=`#{session_id} #{client_control_mode}`;function EX(e){let t=new Set;for(let n of e.split(`
|
|
488
|
+
`)){let[e,r]=n.trim().split(` `);e!==void 0&&r===`1`&&t.add(e)}return t}function DX(e,t){let n=new Set;for(let r of e.split(`
|
|
489
|
+
`)){let[e,i,a,o,s,c]=r.trim().split(` `);e===void 0||e===``||i===void 0||Number(a)>0&&(o===`1`||t.has(i))&&(s!==`1`||c===`1`)&&n.add(e)}return n}var OX=class{servers=new Map;loop={kind:`idle`};constructor(e){this.deps=e}follow(){switch(this.loop.kind){case`idle`:this.deps.log(`info`,`visibility following`),this.ask();break;case`asking`:this.loop.following=!0;break;case`due`:break}return()=>this.stop()}stop(){switch(this.loop.kind){case`due`:clearTimeout(this.loop.timer),this.end();return;case`asking`:this.loop.following=!1;return;case`idle`:return}}ask(){let e={kind:`asking`,following:!0};this.loop=e,Promise.resolve().then(()=>this.refresh(this.deps.sockets())).catch(e=>this.deps.log(`error`,`visibility refresh threw: ${T(e)}`)).then(()=>{if(e.following){this.loop={kind:`due`,timer:setTimeout(()=>this.ask(),this.deps.intervalMs).unref()};return}this.end()})}end(){this.deps.log(`info`,`visibility stopped forgot=${this.servers.size}`),this.loop={kind:`idle`},this.servers.clear()}shown(e){if(e==null)return!0;let t=this.servers.get(e.socket);return t?.kind!==`asked`||t.shown.has(e.pane)}async refresh(e){for(let t of this.servers.keys())e.has(t)||this.servers.delete(t);let t=await Promise.all([...e].map(async e=>{let[t,n]=await Promise.all([this.deps.listPanes(e),this.deps.listClients(e)]);return[e,t.kind===`ok`?n.kind===`ok`?{kind:`asked`,shown:DX(t.stdout,EX(n.stdout))}:{kind:`unasked`,reason:n.reason}:{kind:`unasked`,reason:t.reason}]})),n=new Set;for(let[e,r]of t){let t=this.servers.get(e);this.servers.set(e,r),!kX(t,r)&&(n.add(e),this.deps.log(r.kind===`asked`?`info`:`warn`,r.kind===`asked`?`visibility socket=${JSON.stringify(e)} shown=${[...r.shown].join(`,`)||`-`}`:`visibility socket=${JSON.stringify(e)} unasked: ${r.reason} — its panes count as shown`))}n.size>0&&this.deps.onChange(n)}};function kX(e,t){return e===void 0||e.kind!==t.kind?!1:e.kind===`unasked`||t.kind===`unasked`?!0:e.shown.size===t.shown.size&&[...e.shown].every(e=>t.shown.has(e))}const AX={order:-1/0,text:null,failure:null};var jX=class{synced=new Map;constructor(e){this.dir=e}pathFor(e){return v.join(this.dir,`${encodeURIComponent(e)}.txt`)}sync(e,t,n){let r=this.synced.get(e)??AX;if(t<r.order)return{link:this.linkFor(e,n),failure:null};let i=n===r.text&&r.failure===null?null:this.write(e,n);return this.synced.delete(e),this.synced.set(e,{order:t,text:n,failure:i}),this.forgetOldestClean(),{link:this.linkFor(e,n),failure:i}}linkFor(e,t){let n=this.synced.get(e)??AX;return n.text===t?n.failure===null?{kind:`file`,path:this.pathFor(e)}:{kind:`unavailable`,reason:n.failure}:{kind:`unavailable`,reason:`the file holds another render's text until the session's next statusline request`}}forgetOldestClean(){let e=0;for(let t of this.synced.values())t.text===null&&t.failure===null&&e++;for(let[t,n]of this.synced){if(e<=256)return;n.text!==null||n.failure!==null||(this.synced.delete(t),e--)}}write(e,t){let n=this.pathFor(e);try{return t===null?s.rmSync(n,{force:!0}):(s.mkdirSync(this.dir,{recursive:!0,mode:448}),s.writeFileSync(n,t,{mode:384})),null}catch(e){return`${n}: ${e.message}`}}reset(){this.synced.clear();try{return s.rmSync(this.dir,{recursive:!0,force:!0}),null}catch(e){return`${this.dir}: ${e.message}`}}};function MX(e,t){for(let n of Object.entries(t))e.push(n)}const NX={ok:`info`,"bad-request":`warn`,threw:`error`};function PX(e){switch(e.kind){case`ok`:return[];case`bad-request`:return[[`problems`,e.problems.join(`; `)]];case`threw`:return[[`error`,T(e.error)]]}}const FX=/^[^\s"=\\]+$/,IX=e=>FX.test(e)?e:JSON.stringify(e);function LX(e,t,n){let r=[...e,[`took`,`${n}ms`],[`outcome`,t.kind],...PX(t)];return{level:NX[t.kind],line:`render${r.map(([e,t])=>` ${e}=${IX(t)}`).join(``)}`}}function RX(){var e=typeof SuppressedError==`function`?SuppressedError:function(e,t){var n=Error();return n.name=`SuppressedError`,n.error=e,n.suppressed=t,n},t={},n=[];function r(e,t){if(t!=null){if(Object(t)!==t)throw TypeError(`using declarations can only be used with objects, functions, null, or undefined.`);if(e)var r=t[Symbol.asyncDispose||Symbol.for(`Symbol.asyncDispose`)];if(r===void 0&&(r=t[Symbol.dispose||Symbol.for(`Symbol.dispose`)],e))var i=r;if(typeof r!=`function`)throw TypeError(`Object is not disposable.`);i&&(r=function(){try{i.call(t)}catch(e){return Promise.reject(e)}}),n.push({v:t,d:r,a:e})}else e&&n.push({d:t,a:e});return t}return{e:t,u:r.bind(null,!1),a:r.bind(null,!0),d:function(){var r,i=this.e,a=0;function o(){for(;r=n.pop();)try{if(!r.a&&a===1)return a=0,n.push(r),Promise.resolve().then(o);if(r.d){var e=r.d.call(r.v);if(r.a)return a|=2,Promise.resolve(e).then(o,s)}else a|=1}catch(e){return s(e)}if(a===1)return i===t?Promise.resolve():Promise.reject(i);if(i!==t)throw i}function s(n){return i=i===t?n:new e(n,i),o()}return o()}}}const zX=new JW,BX=new DJ,VX=new Fk,HX=i(import.meta.url);Fe(zX.launchStats);const UX=new sE({counters:zX,logger:N}),WX=mH({watchers:UX,logger:N}),{gitProvider:GX,usageStore:KX,mementoProvider:qX}=WX,JX=new ZW,YX=new sK(JX,N),XX=new AK,ZX=new Qh,QX=new SX({render:e=>zZ(e),watch:(e,t)=>(0,Cv.reaction)(()=>JX.revision(e),t,{scheduler:e=>fe(e)}),lanes:e=>VZ(e),shown:e=>$X.shown(e.hints.tmux),watching:()=>$X.follow(),periods:xX,now:()=>Date.now(),log:N}),$X=new OX({listPanes:e=>lH({socket:e},`frames.visibility`,[`list-panes`,`-a`,`-F`,wX]),listClients:e=>lH({socket:e},`frames.visibility`,[`list-clients`,`-F`,TX]),sockets:()=>new Set(QX.watched().flatMap(({req:e})=>eZ(e))),onChange:e=>QX.wakeWhere(t=>eZ(t).some(t=>e.has(t))),intervalMs:1e3,log:N});function eZ({hints:{tmux:e}}){return e==null?[]:[e.socket]}const tZ=new jX(it()),nZ=new KW({gitService:GX,sessionState:JX,watchers:UX,log:N},{observers:{onReload:e=>N(`info`,`config loaded projectDir=${e.projectDir} cwd=${e.cwd} files=${e.configLayers.join(` < `)||`<bundled default>`} error=${e.lastError===null?`none`:JSON.stringify(e.lastError)} warning=${e.lastWarning===null?`none`:JSON.stringify(e.lastWarning)}`)}}),rZ=60*1e3;function iZ(){let e=import.meta.url,n=[];e.startsWith(`file://`)&&n.push(i(e)),t.argv[1]&&n.push(t.argv[1]);let r=new Map;for(let e of n)try{r.set(e,s.statSync(e).mtimeMs)}catch{}let a=null,o=()=>{for(let[e,t]of r)try{if(s.statSync(e).mtimeMs!==t){N(`info`,`binary mtime changed (${e}); shutting down`),a&&clearInterval(a),xZ(0);return}}catch(e){N(`warn`,`bin stat failed: ${e.message}`)}};return{arm(){r.size!==0&&(a=setInterval(o,rZ),a.unref())},checkNow:o}}const aZ=iZ(),oZ=dV({entryUrl:import.meta.url,intervalMs:rZ,releaseIntervalMs:216e5,registryUrl:t.env.CC_CANDYBAR_REGISTRY_URL??`https://registry.npmjs.org`,fetchImpl:fetch,onApplied:()=>aZ.checkNow(),log:N});let sZ=null,cZ=null,lZ=0;function uZ(){t.on(`uncaughtException`,e=>{N(`error`,`uncaughtException: ${e.stack||e.message}`),xZ(1)}),t.on(`unhandledRejection`,e=>{N(`error`,`unhandledRejection: ${String(e)}`),xZ(1)});for(let e of[`SIGINT`,`SIGTERM`,`SIGHUP`])t.on(e,()=>{N(`info`,`received ${e}, shutting down`),xZ(0)});try{_Z(t.env)}catch(e){N(`error`,`refusing to boot: ${e.message}`),xZ(1);return}sZ=ba(t.pid);let e=Aa(Ma(sZ));if(!e.decision.allow){N(`warn`,`fork-bomb breaker: ${e.decision.reason}; refusing to boot`),xZ(1);return}cZ=e.registryPath,s.mkdirSync(Ge(),{recursive:!0}),Ye(Ke()),JX.useStorage(new $W(Qe(),500,N)),YX.useStorage(OK($e(),N)),Ca({anchor:Sa(t.env),isAlive:wa,onOrphaned:e=>{N(`info`,`parent watchdog: ${e}; shutting down`),xZ(0)}}),dZ(D.createServer({allowHalfOpen:!1},e=>{SZ(e)}),Ke(),!1)}function dZ(e,n,r){e.removeAllListeners(`error`),e.removeAllListeners(`listening`),e.once(`error`,i=>{if(i.code!==`EADDRINUSE`){N(`error`,`server error: ${i.message}`),xZ(1);return}if(r){N(`info`,`lost rebind race; another daemon is alive — exiting`),t.exit(0);return}fZ(e,n)}),e.listen(n,()=>pZ(n))}function fZ(e,n){let r=ua(da(Xe(n)),(e,t)=>ya(e,t,{readStartTime:va,pidAlive:wa}));if(r.kind===`attach-and-exit`){N(`info`,`EADDRINUSE: ${r.reason} — exiting`),t.exit(0);return}N(`warn`,`EADDRINUSE: ${r.reason} — unlinking stale socket and rebinding`);try{s.unlinkSync(n)}catch(e){if(e.code!==`ENOENT`){N(`error`,`cannot unlink stale socket ${n}: ${e.message}`),xZ(1);return}}dZ(e,n,!0)}function pZ(e){let n=ma(e);if(n.kind!==`present`){N(`warn`,`no ownable socket at bind callback (${n.kind}); exiting`),xZ(0);return}vZ(e);try{s.chmodSync(e,384)}catch(e){N(`warn`,`chmod socket failed: ${e.message}`)}N(`info`,`daemon up: pid=${t.pid} v=3 sock=${e} heapCap=${en(ie.getHeapStatistics().heap_size_limit)}MB rssLimit=${en(lZ)}MB`),bn();let r=tZ.reset();r!==null&&N(`warn`,`diagnostic dump wipe failed: ${r}`),aZ.arm(),oZ.arm(),gZ().arm(),mZ(e,n.identity)}function mZ(e,n){_a({bound:n,myPid:t.pid,readIdentity:()=>ma(e),readLease:()=>da(Xe(e)),shutdown:e=>xZ(e),log:N}).arm()}let hZ=null;function gZ(){if(hZ===null)throw Error(`daemon: limits not yet established`);return hZ}function _Z(e){lZ=tn(e),hZ=cn(dn(zX.startedAt.getTime(),e=>xZ(e),{rssLimitBytes:lZ}))}function vZ(e){let n=fa(Xe(e),{pid:t.pid,version:3,binPath:t.argv[1],startTime:sZ});n!==null&&N(`warn`,`lease write failed: ${n}`)}let yZ=0,bZ=!1;function xZ(e){if(!bZ){bZ=!0,setTimeout(()=>t.kill(t.pid,`SIGKILL`),500);try{GX.close()}catch(e){N(`warn`,`gitService close failed: ${e.message}`)}try{KX.close()}catch(e){N(`warn`,`usageStore close failed: ${e.message}`)}try{UX.closeAll()}catch(e){N(`warn`,`watcherRegistry close failed: ${e.message}`)}try{JX.flush()}catch(e){N(`warn`,`sessionState flush failed: ${e.message}`)}pa(Ze(),t.pid),cZ!==null&&ja(cZ,t.pid,Oa,e=>s.unlinkSync(e)),t.exit(e)}}function SZ(e){yZ++,zX.inFlight=yZ;let t=!1,n=!0,r=()=>{n&&(n=!1,yZ=Math.max(0,yZ-1),zX.inFlight=yZ)},i=(n,r,i)=>{if(t){r!==null&&N(`warn`,`exit-after-flush dropped: an earlier responder settled this socket`);return}t=!0;let a=r===null?void 0:()=>xZ(r);try{e.end(Ct(n),e=>{e??i(),a?.()})}catch(e){N(`warn`,`response write failed: ${e.message}`),a?.()}},a=!1,o=setTimeout(()=>{a=!0,zX.requestsTimedOut++,i({ok:!1,error:`request exceeded 200ms`,code:`TIMEOUT`,daemonV:3},null,CZ)},200),s=Tt(e=>{AZ(e,()=>a).then(e=>e.kind===`reply`?i(e.resp,e.exitAfterFlush,e.delivered):c(e.sessionId,e.lane)).catch(e=>{N(`error`,`handler threw: ${T(e)}`),i(DZ(e),null,CZ)})},e=>{N(`warn`,`frame parse failed: ${e.message}`),i({ok:!1,error:e.message,code:`BAD_REQUEST`,daemonV:3},null,CZ)}),c=(n,i)=>{if(t||e.destroyed)return;clearTimeout(o),r(),e.off(`data`,s);let a=CX(e),c=QX.subscribe(n,{lane:i,frame:(e,t)=>a(wt(t)),refused:t=>e.end(Ct(t))});t=!0,e.on(`close`,c)};e.on(`data`,s),e.on(`error`,e=>{N(`warn`,`socket error: ${e.message}`)}),e.on(`close`,()=>{clearTimeout(o),r()})}const CZ=()=>{},wZ=e=>({resp:e,exitAfterFlush:null,delivered:CZ}),TZ=e=>({kind:`reply`,...e}),EZ={render:!0,"pane-session":!0,shutdown:!0,stats:!0,click:!0,debug:!0},DZ=e=>({ok:!1,error:e instanceof Error?e.message:T(e),code:`RENDER_FAILED`,daemonV:3}),OZ=(e,t)=>TZ(wZ({ok:!1,error:t,code:e,daemonV:3}));function kZ(e){if(typeof e.sessionId!=`string`||e.sessionId===``)return OZ(`BAD_REQUEST`,`subscribe needs a non-empty string sessionId`);if(e.lane===void 0)return OZ(`VERSION_MISMATCH`,`this client's subscribe names no lane (${Pa.join(`, `)}): it predates the lane toggles — update it`);let t=Ia(e.lane);return t===null?OZ(`BAD_REQUEST`,`subscribe needs a lane, one of ${Pa.join(`, `)}: got ${JSON.stringify(e.lane)}`):{kind:`subscribe`,sessionId:e.sessionId,lane:t}}async function AZ(e,t){return!e||typeof e!=`object`||typeof e.v!=`number`?OZ(`BAD_REQUEST`,`malformed request`):e.v===3?e.kind===`subscribe`?kZ(e):typeof e.kind!=`string`||!Object.hasOwn(EZ,e.kind)?OZ(`BAD_REQUEST`,`unknown kind`):TZ(await jZ(e,t)):(e.v>3?N(`info`,`version mismatch: client=${e.v} > daemon=3; binary likely upgraded — exiting after the response flushes`):N(`info`,`version mismatch: client=${e.v} < daemon=3; client is stale — staying up`),{kind:`reply`,resp:{ok:!1,error:`protocol v${e.v} not supported (daemon at v3)`,code:`VERSION_MISMATCH`,daemonV:3},exitAfterFlush:e.v>3?0:null,delivered:CZ})}async function jZ(e,t){if(e.kind===`shutdown`)return{resp:{ok:!0,output:``},exitAfterFlush:0,delivered:CZ};if(e.kind===`pane-session`){let{socket:t,pane:n}=e;return wZ(typeof t!=`string`||typeof n!=`string`?{ok:!1,error:`pane-session needs a string socket and pane`,code:`BAD_REQUEST`,daemonV:3}:{ok:!0,paneSession:QX.newestWhere(({hints:{tmux:e}})=>e!=null&&e.socket===t&&e.pane===n)})}if(e.kind===`stats`)return wZ({ok:!0,stats:zX.snapshot({gitCache:GX.getStats(),usageCache:KX.getStats(),renderCache:nZ.stats,effectCache:ZX.getStats(),sessionState:{sessions:JX.size(),observers:JX.observers(),revision:JX.latestRevision()},frameFeeds:QX.getStats(),watchersActive:UX.size(),nextRestartReason:gZ().describeNextRestart(),handlerProbes:BX.list(),clients:VX.list(yE(new Date)),bundle:HX,daemon:gZ().serving()})});if(e.kind===`render`){let n=new Date,r=yE(n),i=n.getTime(),a=[],o=++zX.requestsTotal,s=HZ(e),c=(e,t)=>VX.see(e.hookData.session_id,{client:e.hints.client??null,rateLimits:e.rateLimits,claudeConfigDir:Si(e.hints.claudeConfigDir),transcript:jk(e.hookData),frame:t},r,o);s.ok&&c(s.req,`drawing`);let l=s.ok?await JZ(s.req,o,r,a).then(({output:e,motion:t,clickShown:n})=>{c(s.req,t);let r={ok:!0,output:e};return QX.note(s.req.hookData.session_id,s.req,o,{resp:r,drawnAt:i,moves:t===`moves`,failure:null}),{outcome:{kind:`ok`},resp:r,delivered:n===null?CZ:()=>NK(JX,s.req.hookData.session_id,n)}},e=>(c(s.req,`failed`),{outcome:{kind:`threw`,error:e},resp:DZ(e),delivered:CZ})):UZ(s.problems);l.outcome.kind!==`ok`&&zX.requestsErrored++,MX(a,{timedOut:t()?`Y`:`N`});let{level:u,line:d}=LX(a,l.outcome,Date.now()-i);return N(u,d),{resp:l.resp,exitAfterFlush:null,delivered:l.delivered}}if(e.kind===`click`)return wZ(RZ(e.verb,e.value,xt(e.clientVersion)));if(e.kind===`debug`){if(!yX(e.what))return wZ({ok:!1,error:`unknown debug 'what': ${String(e.what)} (have: ${vX.join(`, `)})`,code:`BAD_REQUEST`,daemonV:3});let t=nZ.firstState(),n=t===null?null:{store:t.store,registry:t.registry,config:t.config,compiled:t.compiled,lastRenderBySegment:e.what===`segments`?IZ(t.lastRenderCellsBySegment,t.config.globals.colorCompatibility??`truecolor`):FZ};return wZ({ok:!0,debug:sX(e.what,n)})}throw Error(`no reply for request ${T(e)}`)}function MZ(e,t){let{values:n,tokens:r}=re({args:e.slice(1),options:{config:{type:`string`}},strict:!1,tokens:!0,allowPositionals:!0}),i=[...new Set((r??[]).filter(e=>e.kind===`option`&&e.name!==`config`).map(e=>`--${e.name}`))];return{configFile:AL(t,n.config),unknownFlagsError:i.length>0?`Unknown flags: ${i.join(`, `)}`:null}}const NZ={sessionState:JX,dlog:N,applyUpdate:()=>oZ.act(),doctor:Xq(e=>{let t=[e.projectDir,e.cwd,e.configFile??void 0];nZ.reload(...t);let n=nZ.getOrCreate(...t);return{layers:n.configLayers,error:n.lastError,warning:n.lastWarning,unused:n.state.unused,config:n.state.config}}),probes:BX,clients:VX,bundle:HX,serving:()=>gZ().serving(),memento:qX,claudeInput:qJ(),history:YX,navigation:XX,configFor:e=>nZ.getOrCreate(e.projectDir,e.cwd,e.configFile??void 0).state.config,reloadConfig:e=>nZ.reload(e.projectDir,e.cwd,e.configFile??void 0)};NZ.reloadConfig;const PZ={endcaps:`powerline`,colorCompatibility:`truecolor`,wrap:!0,padding:1,width:1/0},FZ=new Map;function IZ(e,t){let n=new Map;for(let[r,i]of e)n.set(r,dg(i,{...PZ,colorCompatibility:t}));return n}const LZ={...WX,history:e=>YX.depth(e)};function RZ(e,t,n){let r=$Y.get(e);if(!r)return{ok:!1,error:`unknown click verb: ${e}`,code:`BAD_REQUEST`,daemonV:3};try{return r(t,{...NZ,clientVersion:n}),{ok:!0,output:``}}catch(e){let t=e instanceof q?`BAD_REQUEST`:`RENDER_FAILED`;return{ok:!1,error:String(e instanceof Error?e.message:e),code:t,daemonV:3}}}async function zZ(e){let t=new Date,n=[];try{let{drawn:r,motion:i}=await WZ(e,yE(t),n,`frame`);return{resp:{ok:!0,output:GZ(r,tZ.linkFor(e.hookData.session_id,KZ(r)))},drawnAt:t.getTime(),moves:i===`moves`,failure:null}}catch(e){let{level:r,line:i}=LX(n,{kind:`threw`,error:e},Date.now()-t.getTime());return{resp:DZ(e),drawnAt:t.getTime(),moves:!1,failure:{level:r,line:`frame ${i}`}}}}function BZ(e,t){return jz(t.config,t=>JX.get(e,t),e=>t.authoredRoots.has(e))}function VZ(e){try{var t=RX();let n=e.hookData.session_id,r=dY(e.requested,JX,n);return BZ(n,t.u(nZ.hold(r.projectDir,r.cwd,r.configFile??void 0)).state).lanes}catch(e){t.e=e}finally{t.d()}}function HZ(e){let{report:t}=rX(e.hookData);for(let e of t.unknownTopLevelFields)N(`info`,`schema: unknown field '${e}' — Anthropic may have added it`);let n=[];for(let e of t.missingRequired)n.push(`missing required field '${e}'`);for(let{path:e,expected:r,got:i}of t.typeMismatches)n.push(`field '${e}' expected ${r}, got ${i}`);if((typeof e.cwd!=`string`||!x(e.cwd))&&n.push(`request 'cwd' is not an absolute path: ${JSON.stringify(e.cwd)}`),(!Array.isArray(e.args)||!e.args.every(e=>typeof e==`string`))&&n.push(`request 'args' is not a list of strings: ${JSON.stringify(e.args)}`),n.length>0)return{ok:!1,problems:n};let r=ft(e),{configFile:i,unknownFlagsError:a}=MZ(e.args,e.cwd);return{ok:!0,req:{...e,hints:r,rateLimits:Ak(e.hookData),requested:{projectDir:e.hookData.workspace.project_dir,cwd:e.cwd,configFile:i??r.configEnv??null},unknownFlagsError:a}}}const UZ=e=>({outcome:{kind:`bad-request`,problems:e},resp:{ok:!1,error:`malformed hookData: ${e.join(`; `)}`,code:`BAD_REQUEST`,daemonV:3},delivered:CZ});async function WZ(e,t,n,r){try{var i=RX();MX(n,{sid:e.hookData.session_id,at:t.toFixed(3)});let{unknownFlagsError:a}=e,o=e.hookData.session_id,s=e.hints,c=pt(e,s),l=mt(c);MX(n,{termCols:String(s.termCols??`?`),termRows:String(s.termRows??`?`),refused:c.map(e=>e.hint).join(`,`)||`-`,client:s.client?.kind??`unreported`,rateLimits:e.rateLimits});let u=dY(e.requested,JX,o),{entry:d,state:f}=i.u(nZ.hold(u.projectDir,u.cwd,u.configFile??void 0)),p=s.termCols,m=bX(p??120),h=fg(s.termRows);MX(n,{width:String(m)});let g=t=>JX.get(e.hookData.session_id,t),_=BZ(o,f);MX(n,{lanes:Pa.filter(e=>_.lanes[e]).join(`,`)||`-`});let v=await $z(e.hookData,t,{...LZ,navigation:e=>XX.depth(e,JX,UB(f.config))},e.cwd,f.neededInputPaths(_.preset),_,s,{...AB(f.config,f.fileHeldSettings,g),configPath:d.configLayers.includes(d.configHome)?d.configHome:null});MX(n,{prompts:String(v.metrics?.messageCount??`-`),nonPrompts:String(v.metrics?.nonPrompts??`-`),pr:Iz(v.git)});let y=[],b=Mz(_,m),x=ZX.of(o),S=wW(f.config,f.compiled,f.store,f.registry,v,t,b,{perSegmentSink:f.lastRenderCellsBySegment,onRenderWarning:e=>y.push(e)},{...Nz(_),effects:x}),C=FK(JX,o,t,r),w=C.kind===`held`||C.kind===`owed`?C.error:null,ee=w?.text??null,te=[a,l,d.lastError,ee].filter(Boolean).join(`
|
|
490
|
+
`),ne=oZ.notice({sessionId:o,dismissed:JX.get(o,YB),enabled:_.updateNotice}),T=d.lastError===null?null:d.failedFile,re=[...d.lastWarning===null?[]:[{kind:`load`,message:d.lastWarning}],...y],E=_g(te,ne,re.map(e=>e.message).join(`
|
|
491
|
+
`)),D=GX.getStats(),ie=KX.getStats(),O=x.lastFrame(),ae=O.own.map(e=>`${e.placement}:${e.effect}@${e.t.toFixed(3)}`).join(`,`)||`-`,oe=e=>e.map(e=>`${e.placement}@${e.t.toFixed(3)}`).join(`,`)||`-`,se=re.map(e=>{switch(e.kind){case`rule`:return`rule:${e.slot}`;case`refresh`:return`refresh:${e.variable}`;case`load`:case`band-floor`:case`when`:return e.kind}}).join(`,`)||`-`;return MX(n,{git:`${D.size}/${D.hits}h/${D.misses}m`,usage:`${ie.size}/${ie.hits}h/${ie.misses}m`,effect:O.effect,effectT:O.t.toFixed(3),effectRows:`${O.made}made/${O.reused}reused`,effectOwn:ae,fadeBasis:O.basis,stateRev:String(O.revision),fades:oe(O.fades),leaves:oe(O.leaves),motion:S.motion,err:te?`Y`:`N`,clickError:C.kind===`none`?`-`:C.kind,upd:String(ne.length),warn:se}),{drawn:{body:S.text,diagnostics:E,failedConfigFile:T,geometry:{width:m,rowCap:h,colorCompatibility:_.colorCompatibility}},motion:S.motion,clickShown:w}}catch(e){i.e=e}finally{i.d()}}function GZ(e,t){return bg(e.body,e.diagnostics,{fullText:t,failedConfigFile:e.failedConfigFile},e.geometry)+`
|
|
492
|
+
`}function KZ(e){return e.diagnostics===null?null:yg(e.diagnostics)}function qZ(e){let t=e.hookData.session_id,{client:n,...r}=e.hints,i=JSON.stringify(r);JX.get(t,`client-hints`)!==i&&JX.set(t,LY,i);let a=fY(e.requested);JX.get(t,`render-origin`)!==a&&JX.set(t,uY,a)}async function JZ(e,t,n,r){qZ(e);let{drawn:i,motion:a,clickShown:o}=await WZ(e,n,r,`request`),{link:s,failure:c}=tZ.sync(e.hookData.session_id,t,KZ(i));return MX(r,{dumpFailed:c===null?`-`:JSON.stringify(c)}),{output:GZ(i,s),motion:a,clickShown:o}}const YZ={connectMs:200,budgetMs:500};async function XZ(e,n){let r=n.includes(`--json`),i=await ZZ(e);if(i.kind!==`ok`&&(t.stderr.write(`${e}: ${Pt(i)}\n`),t.exit(1)),r){t.stdout.write(JSON.stringify(i.value,null,2)+`
|
|
493
|
+
`);return}t.stdout.write(QZ(i.value))}function ZZ(e){return Ot({kind:`debug`,what:e},YZ,e=>`debug`in e?e.debug:void 0)}function QZ(e){switch(e.what){case`vars`:return $Z(e.vars);case`segments`:return eQ(e.segments);case`config`:return tQ(e.config);default:return e}}function $Z(e){if(e.length===0)return`no variables (DSL not active)
|
|
494
|
+
`;let t=[`variables (${e.length})`,``],n=e.reduce((e,t)=>Math.max(e,t.name.length),4),r=e.reduce((e,t)=>Math.max(e,(t.source??`—`).length),6),i=e.reduce((e,t)=>Math.max(e,t.type.length),4);for(let a of e){let e=a.ageMs===null?``:` ${rQ(a.ageMs)}`,o=a.lastError?` ✗ ${a.lastError.message}`:``;t.push(` ${a.name.padEnd(n)} ${(a.source??`—`).padEnd(r)} ${a.type.padEnd(i)} ${nQ(a.value)}${e}${o}`)}return t.join(`
|
|
495
495
|
`)+`
|
|
496
|
-
`}function
|
|
496
|
+
`}function eQ(e){if(e.length===0)return`no segments (DSL not active)
|
|
497
497
|
`;let t=[`segments (${e.length})`,``];for(let n of e){t.push(` ${n.name}`),n.description!==null&&t.push(` shows ${n.description}`),t.push(` template ${n.template}`),n.referencedVars.length>0&&t.push(` vars ${n.referencedVars.join(`, `)}`);for(let{id:e,lastRender:r}of n.placements)r!==null&&t.push(` last ${e}: ${r}`)}return t.join(`
|
|
498
498
|
`)+`
|
|
499
|
-
`}function
|
|
499
|
+
`}function tQ(e){return e===null?`config: DSL not active
|
|
500
500
|
`:JSON.stringify(e,null,2)+`
|
|
501
|
-
`}function
|
|
501
|
+
`}function nQ(e){let t=typeof e==`string`?e:JSON.stringify(e);return t.length>60?t.slice(0,57)+`…`:t}function rQ(e){return e<1e3?`${e}ms`:e<6e4?`${(e/1e3).toFixed(1)}s`:`${Math.floor(e/6e4)}m`}function iQ(){let e=oQ();return e===null?null:s.readFileSync(e,`utf-8`)}function aQ(){let e;try{e=iQ()}catch(e){t.stderr.write(`schema: cannot read bundled schema: ${e instanceof Error?e.message:String(e)}\n`),t.exit(2)}e===null&&(t.stderr.write("schema: bundled schema not found (expected schema/cc-candybar.schema.json). Run `pnpm gen:schema` from a source checkout.\n"),t.exit(2)),t.stdout.write(e),t.exit(0)}function oQ(){let e=v.join(`schema`,`cc-candybar.schema.json`),n=t.argv[1];if(n===void 0)return null;let r=v.dirname(v.resolve(n));for(;;){let t=v.join(r,e);if(s.existsSync(t))return t;let n=v.dirname(r);if(n===r)return null;r=n}}function sQ(e,t){return AL(t,e.CC_CANDYBAR_CONFIG)}const cQ=5e3;function lQ(e,t,n){let r=`/home/tester`,i=Math.floor(n),a=`test0a1b-2c3d-4e5f-6a7b-8c9d0e1f2a3b`,o={current_dir:`${r}/code/cc-candybar/src`,project_dir:`${r}/code/cc-candybar`,added_dirs:[]};return{hook_event_name:`Status`,session_id:a,version:`1.15.0`,home:r,cwd:`${r}/code/cc-candybar/src`,transcript_path:`${r}/.claude/projects/x/test.jsonl`,model:{id:`claude-opus-4-8`,display_name:`Opus 4.8`},effort:{level:`xhigh`},workspace:o,git:{repoName:`cc-candybar`,repoUrl:`https://github.com/promptctl/cc-candybar`,branch:`main`,sha:`abc1234`,ahead:2,behind:1,staged:3,unstaged:2,untracked:1,conflicts:0,upstream:`origin/main`,tracking:`tracked`,stash:1,status:`dirty`,operation:`rebase`,timeSinceCommit:780},session:{cost:.39,tokens:241400},today:{cost:12.5,tokens:34e5},context:{totalTokens:48487,contextLeft:24},metrics:{lastResponseTime:8.2,responseTime:4.2,sessionDuration:930,messageCount:8,linesAdded:512,linesRemoved:88},block:{nativeUtilization:63,resetsAt:i+2*3600},weekly:{percentage:21,resetsAt:i+5*86400},cache:{expiresAt:i+900},tmux:{pane:`%0`,session:`work`},host:{name:`tester-box`,user:`tester`,ssh:!0},autocompact:yj(4e5,1e6),...Pz(e),history:{undo:1,redo:1,sinceEdit:1},navigation:{back:1},unsaved:1,resettable:Ka(()=>!0),themeDefault:{differs:!0,theme:`<theme>`},resumeCommand:Az(o,a,void 0),configPath:t??`${r}/.config/cc-candybar/config.json5`}}function uQ(e,t){let n=mR(e,e),r=_R(n);return r!==null&&t.push(r),n.kind===`chain`?n.layers:[]}async function dQ(e,n=t.cwd()){let r=[],i=AL(n,e)??null,a=i===null?uQ(n,r):[i];if(i!==null){let e;try{e=s.statSync(i,{throwIfNoEntry:!1})}catch(e){return{kind:`unreadable`,path:i,message:e instanceof Error?e.message:String(e)}}if(e!==void 0&&!e.isFile())return{kind:`unreadable`,path:i,message:`not a file`}}let o=yR(n,n);o!==null&&r.push(o);try{return{kind:`clean`,layers:a,warnings:r,rendered:await mQ(a,n,r)}}catch(e){let t=e;return typeof t==`object`&&t&&typeof t.code==`string`&&typeof t.path==`string`&&a.includes(t.path)&&typeof t.message==`string`?{kind:`unreadable`,path:t.path,message:t.message}:(e instanceof YE&&r.push(...e.warnings),{kind:`fatal`,layers:a,message:e instanceof YE||e instanceof Error?e.message:String(e),warnings:r})}}async function fQ(e,t,n){let r=DR(e,XR,{entered:()=>{},warned:e=>n.push(...e)},{projectDir:t,cwd:t}),{config:i}=r,a=new IW,o=new UE(a,i.globals.default_empty_value??``,void 0,new ZW);try{let s=gW(i,o,{cwd:t});n.push(...s.loadWarnings);let c=await o.settled(cQ);return c.length>0&&n.push(`source${c.length===1?``:`s`} still running after ${cQ} ms, rendered with fallback values: ${c.join(`, `)}`),{layers:e,droppedPlugins:[...r.installed.dropped,...r.layers.flatMap(e=>e.plugins.dropped)],config:i,compiled:s,store:a,registry:o}}catch(e){throw o.dispose(),e}}function pQ({layers:e,config:t,compiled:n,store:r,registry:i},a,o,s){let c=new Map,l=new Set;return{rendered:CW(t,n,r,i,lQ(a,e.at(-1)??null,s),s,Mz(a,o),{onSegmentError:(e,t)=>c.set(`segment "${e}"`,t),onRenderWarning:e=>{switch(e.kind){case`rule`:c.set(`${e.slot} rule`,e.message);return;case`when`:c.set(e.where,e.error);return;case`refresh`:c.set(`variable "${e.variable}"`,`cannot refresh: ${e.error}`);return;case`band-floor`:l.add(e.message);return;default:}}},Nz(a)),failures:c,advisories:l}}async function mQ(e,t,n){let r=await fQ(e,t,n),{config:i}=r,a=yE(new Date);try{let e=uV();try{UB(i),QN(i)}finally{e()}let t=z_(null,i.globals.preset,i.presets),o=(e,t)=>{let n=jz(i,t=>t===`preset`?e:null,()=>t),o;try{o=pQ(r,n,200,a)}catch(e){o={failures:new Map([[`render`,e instanceof Error?e.message:String(e)]]),advisories:new Set}}return{preset:e,customized:t,...o}},s=o(t,!1),c=[s,o(t,!0),...R_(i.presets).filter(e=>e!==t).flatMap(e=>[o(e,!1),o(e,!0)])],l=e=>{let n=new Map;for(let t of c)for(let r of e(t)){let e=n.get(r)??new Map;e.set(t.preset,(e.get(t.preset)??new Set).add(t.customized)),n.set(r,e)}return[...n].map(([e,n])=>n.get(t)?.has(!1)?e:`${e} (under ${[...n].map(([e,n])=>[...e===t?[]:[`preset "${e}"`],...n.has(!1)?[]:[`.preset.customized = true`]].join(`, `)).join(`; `)})`)};n.push(...l(e=>e.advisories));let u=l(e=>[...e.failures].map(([e,t])=>`${e}: ${t}`)),d=s.rendered,f=r.droppedPlugins.length,p=[...f>0?[`${f} plugin${f===1?``:`s`} did not load (named in the warnings)`]:[],...u.length>0||d===void 0?[`config renders with ${u.length} render error${u.length===1?``:`s`} (the daemon would show them on the bar):\n`+u.map(e=>` ${e}`).join(`
|
|
502
502
|
`)]:[]];if(p.length>0||d===void 0)throw Error(p.join(`
|
|
503
|
-
`));return d}finally{r.registry.dispose()}}function
|
|
504
|
-
`))delete i[e];r(i,`clone`,`--quiet`,`--depth`,`1`,`--filter=blob:none`,`--sparse`,`--`,e,n),r(i,`-C`,n,`sparse-checkout`,`set`,`--no-cone`,`/${
|
|
505
|
-
`));let c=a.map(e=>{let n=v.basename(e),r=v.join(t,n);return{folder:e,name:n,target:r,placed:
|
|
506
|
-
`,kick:!0,debug:`daemon unavailable (transient: ${e.cause}: ${e.message}) — kicking daemon`};case`permanent`:return{output:
|
|
507
|
-
`).join(` — `)};return{clients:t,rateLimits:t,transcripts:t,serving:t}}return{clients:
|
|
503
|
+
`));return d}finally{r.registry.dispose()}}function hQ(e){return e.map(e=>`warning: ${e}\n`).join(``)}function gQ(e,t=!1){switch(e.kind){case`clean`:return{stdout:`✓ ${e.layers.join(` < `)||`bundled default (no config file found)`}: config OK${e.warnings.length>0?` (${e.warnings.length} warning${e.warnings.length===1?``:`s`})`:``}\n`+(t?`${e.rendered}\n`:``),stderr:hQ(e.warnings),code:0};case`fatal`:return{stdout:``,stderr:hQ(e.warnings)+`✗ ${e.layers.join(` < `)||`<default>`}\n${e.message}\n`,code:1};case`unreadable`:return{stdout:``,stderr:`check: cannot read ${e.path}: ${e.message}\n`,code:2}}}const _Q=`--render`,vQ=`Usage: cc-candybar check [${_Q}] [config-file]\n`;function yQ(e){let t=e.filter(e=>e.startsWith(`--`)),n=e.filter(e=>!e.startsWith(`--`)),r=t.filter(e=>e!==_Q);return r.length>0?{kind:`usage`,message:`check: unknown option ${r.join(` `)}\n${vQ}`}:n.length>1||n[0]===``?{kind:`usage`,message:`check: expected at most one non-empty path\n${vQ}`}:{kind:`run`,target:n[0],render:t.includes(_Q)}}async function bQ(e){let n=yQ(e),r=n.kind===`usage`?{stdout:``,stderr:n.message,code:2}:gQ(await dQ(n.target??sQ(t.env,t.cwd())),n.render);t.stdout.write(r.stdout),t.stderr.write(r.stderr),t.exit(r.code)}const xQ=/^[a-z][a-z0-9+.-]*:\/\//i,SQ=/^[^@\s/]+@[^:\s/]+:/,CQ=/^([A-Za-z0-9-]+\/[A-Za-z0-9._-]+?)(?:\.git)?$/;function wQ(e){if(!URL.canParse(e))return e;let t=new URL(e);return t.password===``?e:(t.password=`***`,t.href)}function TQ(e,t,n){let r=kL(t,e);if(n(r))return{kind:`path`,dir:r};if(xQ.test(e)||SQ.test(e))return{kind:`git`,url:e,shown:wQ(e)};let i=CQ.exec(e);if(i){let e=`https://github.com/${i[1]}.git`;return{kind:`git`,url:e,shown:e}}return{error:`"${e}" is not a directory, a GitHub repo slug (owner/repo) or a git URL`}}function EQ(e,t){let n=v.join(e,aR),r=cR(n);if(`error`in r)throw Error(`${t}: could not list ${aR}: ${r.error}`);if(r.folders.length===0)throw Error(`${t} has no plugins: none at ${aR}/<name>/${NL}`);return r.folders.map(e=>v.join(n,e,NL))}function DQ(e,t,n){let r=(n,...r)=>{let i=Re({bin:`git`,args:r,env:n,category:`plugin.git`});if(!i.ok)throw Error(`git ${r.map(n=>n===e?t:n).join(` `)} failed (${i.reason}): ${i.stderr.trim()||i.error||``}`);return i.stdout},i={...process.env,GIT_TERMINAL_PROMPT:`0`};for(let e of r(i,`rev-parse`,`--local-env-vars`).split(`
|
|
504
|
+
`))delete i[e];r(i,`clone`,`--quiet`,`--depth`,`1`,`--filter=blob:none`,`--sparse`,`--`,e,n),r(i,`-C`,n,`sparse-checkout`,`set`,`--no-cone`,`/${aR}/`)}function OQ(e,t){switch(e.kind){case`path`:return t(e.dir);case`git`:{let n=s.mkdtempSync(v.join(w.tmpdir(),`cc-candybar-plugin-`));try{return DQ(e.url,e.shown,v.join(n,`repo`)),t(v.join(n,`repo`))}finally{s.rmSync(n,{recursive:!0,force:!0})}}}}function kQ(e){let t;try{t=s.lstatSync(e)}catch(e){if(e.code===`ENOENT`)return`installed`;throw e}if(t.isDirectory())return`updated`;if(t.isSymbolicLink())return`replaced`;throw Error(`${e} is a file, not a plugin folder: move it, then install again`)}function AQ(e,t,n,r){switch(r){case`updated`:s.renameSync(v.join(e,NL),v.join(t,NL));return;case`replaced`:s.renameSync(t,n),s.renameSync(e,t);return;case`installed`:s.renameSync(e,t);return}}function jQ(e,t,n){let r=EQ(e,n);s.mkdirSync(t,{recursive:!0});let i=s.mkdtempSync(v.join(t,`.install-`));try{let a=r.map(e=>{let t=v.join(i,v.basename(v.dirname(e)));s.mkdirSync(t);try{s.copyFileSync(e,v.join(t,NL))}catch(e){if(e.code!==`ENOENT`)throw e}return t}),o=TR(a.map(e=>v.join(e,NL)),XR,{root:e,git:!1});if(o.length>0)throw Error(o.map(e=>`${n}: ${v.join(aR,v.relative(i,e.path))} would not load: ${e.reason.split(i).join(v.join(n,aR))}`).join(`
|
|
505
|
+
`));let c=a.map(e=>{let n=v.basename(e),r=v.join(t,n);return{folder:e,name:n,target:r,placed:kQ(r)}}),l=[];try{for(let{folder:e,name:t,target:n,placed:r}of c)AQ(e,n,v.join(i,`.replaced-${t}`),r),l.push(t)}catch(e){throw Error(`${e.message} (placed before it: ${l.join(`, `)||`none`})`)}return c.map(({target:e,placed:t})=>({path:v.join(e,NL),placed:t}))}finally{s.rmSync(i,{recursive:!0,force:!0})}}function MQ(e){let[t,n,...r]=e;if(t!==`install`||n===void 0||r.length>0)return console.error(`Usage: cc-candybar plugin install <path | owner/repo | git URL>`),2;let i=TQ(n,process.cwd(),FE);if(`error`in i)return console.error(`plugin install: ${i.error}`),2;try{let e=i.kind===`path`?i.dir:i.shown,t=OQ(i,t=>jQ(t,iR(),e));for(let{path:n,placed:r}of t)console.log(`${r} plugin ${v.basename(v.dirname(n))} → ${n} (from ${e})`);return 0}catch(e){return console.error(`plugin install: ${e.message}`),1}}const NQ=`${Ap}${kp}`;function PQ(e){return`${NQ}⚠ cc-candybar: ${FQ(e)}${jp}\n`}function FQ(e){switch(e.cause){case`version_mismatch`:{let t=e.daemonV===0?`unknown`:`v${e.daemonV}`;return`protocol mismatch (client v${e.clientV} ≠ daemon ${t})`}case`bad_request`:return`daemon rejected request: ${Op(e.message,60)}`;case`render_failed`:return`render failed: ${Op(e.message,60)}`;case`switched_off`:return`switched off: ${Op(e.message,60)}`;case`malformed_response`:return`malformed daemon response: ${Op(e.message,60)}`}}function IQ(e){switch(e.kind){case`ok`:return{output:e.value,kick:!1,debug:null};case`transient`:return{output:`
|
|
506
|
+
`,kick:!0,debug:`daemon unavailable (transient: ${e.cause}: ${e.message}) — kicking daemon`};case`permanent`:return{output:PQ(e),kick:!1,debug:`daemon refused request (permanent: ${e.cause}) — not kicking`}}}function LQ(e,t){if(e!==void 0&&/^\+?\d+$/.test(e)){let t=Number(e);if(t>0&&t<=4294967295)return t}if(t&&t>0)return t}const RQ=[`SSH_CONNECTION`,`SSH_CLIENT`,`SSH_TTY`];function zQ(e,t,n){return{termCols:LQ(e.COLUMNS,n.columns),termRows:LQ(e.LINES,n.rows),ssh:RQ.some(t=>(e[t]??``)!==``),tmux:Ek(e),configEnv:sQ(e,t),claudeConfigDir:xi(e,t),mementoEnv:st(e,t),terminalEnv:lt(e)}}function BQ(e){return e.clients.map(e=>typeof e==`object`&&e?e:{})}function VQ(e){let t=gJ(e,[`bundle`,`clients`]);if(t!==null)return{kind:`failed`,reason:t};if(typeof e.bundle!=`string`)return{kind:`failed`,reason:`the running daemon (${e.version}) reported its bundle as ${JSON.stringify(e.bundle)}`};let n=BQ(e);return n.every(e=>typeof e.ago==`number`)?{kind:`ok`,value:{bundle:e.bundle,clients:n.map(e=>({client:Dt(e.client)??null,ago:e.ago}))}}:{kind:`failed`,reason:`the running daemon (${e.version}) reported clients without their age: ${JSON.stringify(e.clients)}`}}const HQ=e=>{let{identity:t,artifacts:n}=e??{};return typeof t==`string`&&typeof n==`object`&&!!n&&Object.values(n).every(e=>typeof e==`string`)};function UQ(e){let t=gJ(e,[`daemon`]);if(t!==null)return{kind:`failed`,reason:t};let n=e.daemon,r=n?.postMortems;return typeof n?.pid==`number`&&typeof n.rss==`number`&&typeof n.rssLimit==`number`&&(r?.kind===`ok`&&Array.isArray(r.value)&&r.value.every(HQ)||r?.kind===`failed`&&typeof r.reason==`string`)?{kind:`ok`,value:n}:{kind:`failed`,reason:`the running daemon (${e.version}) reported itself as ${JSON.stringify(e.daemon)}`}}function WQ(e){let t=gJ(e,[`clients`]);if(t!==null)return{kind:`failed`,reason:t};let n=BQ(e);return n.every(e=>typeof e.ago==`number`&&typeof e.claudeConfigDir==`string`&&kk.includes(e.rateLimits))?{kind:`ok`,value:n}:{kind:`failed`,reason:`the running daemon (${e.version}) reported its renders without the rate-limit windows they carried — restart it on this build: ${JSON.stringify(e.clients)}`}}function GQ(e){let t=gJ(e,[`clients`]);if(t!==null)return{kind:`failed`,reason:t};let n=BQ(e);return n.every(e=>{let t=e.transcript;return typeof e.ago==`number`&&typeof t?.path==`string`&&typeof t.answered==`boolean`})?{kind:`ok`,value:n}:{kind:`failed`,reason:`the running daemon (${e.version}) reported its renders without their transcripts — restart it on this build: ${JSON.stringify(e.clients)}`}}function KQ(e){let t=gJ(e,[`clients`]);if(t!==null)return{kind:`failed`,reason:t};let n=BQ(e);return n.every(e=>typeof e.ago==`number`&&typeof e.claudeConfigDir==`string`&&Nk.includes(e.role)&&Mk.includes(e.frame))?{kind:`ok`,value:n}:{kind:`failed`,reason:`the running daemon (${e.version}) reported its renders without what they drew — restart it on this build: ${JSON.stringify(e.clients)}`}}async function qQ(){let e=await hJ();if(e.kind!==`ok`){let t={kind:`failed`,reason:Pt(e).split(`
|
|
507
|
+
`).join(` — `)};return{clients:t,rateLimits:t,transcripts:t,frames:t,serving:t}}return{clients:VQ(e.value),rateLimits:WQ(e.value),transcripts:GQ(e.value),frames:KQ(e.value),serving:UQ(e.value)}}const JQ=` (fix: click the settings menu (${dr} by default) › 🧰 tools › 🩺 doctor, then [fix] on the bar)`,YQ=`mark them ✓ shapes or ✗ boxes in the bar's doctor, and this command reads your mark: the settings menu (${dr} by default) › 🧰 tools › 🩺 doctor`;function XQ({check:e,verdict:t}){return t.ok?`✓ ${e.label}\n`:`✗ ${e.label} — ${t.reason}${t.fix===void 0?``:JQ}\n`+(t.more??[]).map(e=>` ${e}\n`).join(``)+(t.sighting===void 0?``:` look: ${t.sighting.glyphs} — ${YQ}\n`)}function ZQ(e){let t={sessionState:new ZW},n=WW(e.projectDir,e.cwd,e.configFile??void 0,t),r=n.state??GW(e.cwd,e.projectDir,t);return r.registry.dispose(),{layers:n.layers,error:n.error,warning:n.warning,unused:r.unused,config:r.config}}function QQ(e,t){return t.kind===`failed`?t:Bq(e,t.value.bundle,t.value.clients.filter(({ago:e})=>e<=300).map(({client:e})=>e))}function $Q(e,t){return e.kind===`failed`?e:{kind:`ok`,value:e.value.filter(e=>e.ago<=300&&e.claudeConfigDir===t).map(e=>e.rateLimits)}}function e$(e){return e.kind===`failed`?e:{kind:`ok`,value:e.value.filter(e=>e.ago<=300).map(e=>e.transcript)}}function t$(e,t){return e.kind===`failed`?e:{kind:`ok`,value:e.value.filter(e=>e.ago<=300&&e.claudeConfigDir===t).map(({role:e,frame:t})=>({role:e,frame:t}))}}async function n$(e,t,n,r,i,a,o=void 0){let s;try{let c=await n(),l=zQ(r,i,a());s={...dJ(e,l,{projectDir:i,cwd:i,configFile:AL(i,o)??sQ(r,i)??null},()=>null,c.serving,$Q(c.rateLimits,Si(l.claudeConfigDir)),e$(c.transcripts),t$(c.frames,Si(l.claudeConfigDir))),urlHandler:await MJ(t),install:QQ(e.install,c.clients),askedBy:`command`}}catch(e){return{stdout:``,stderr:`doctor: ${e instanceof Error?e.message:String(e)}\n`,code:2}}let c=HA(s);return{stdout:c.map(XQ).join(``),stderr:``,code:+!c.every(e=>e.verdict.ok)}}function r$(){if(t.stderr.isTTY)return t.stderr;let e;try{e=p(`/dev/tty`,`r+`)}catch{return{}}let n=new _e(e),{columns:r}=n;return n.destroy(),{columns:r}}async function i$(e){(e.length>1||e[0]===``||e[0]?.startsWith(`--`))&&(t.stderr.write(`doctor: expected at most one config file
|
|
508
508
|
Usage: cc-candybar doctor [config-file]
|
|
509
|
-
`),t.exit(2));let n=t.cwd(),r=await
|
|
510
|
-
`);return{bytes:t.map((e,t)=>`\x1b[${t+1}H[2K${e}`).join(``)+`\x1B[J`,rows:t.length}}const
|
|
511
|
-
`).map(e=>e.trim().split(` `));return i.some(([e])=>e===n)?
|
|
509
|
+
`),t.exit(2));let n=t.cwd(),r=await n$(Xq(ZQ),IJ(),qQ,t.env,n,r$,e[0]);t.stdout.write(r.stdout),t.stderr.write(r.stderr),t.exit(r.code)}function a$(e,t,n,r,i){let a=null,o=e=>{a===null&&(a=e,s.destroy(),i(e))},s=D.createConnection({path:e}),c={v:3,kind:`subscribe`,sessionId:t,lane:n};return s.once(`connect`,()=>s.write(Ct(c))),s.on(`data`,Tt(e=>{let t=e;!t.ok&&t.code!==`RENDER_FAILED`?o({kind:`refused`,resp:t}):r(t)},e=>o({kind:`failed`,error:e}))),s.on(`error`,e=>o({kind:`failed`,error:e})),s.on(`close`,()=>o({kind:`closed-there`})),{close:()=>o({kind:`closed-here`})}}function o$(e){switch(e.kind){case`failed`:return{kind:`reconnect`,reason:`stream failed (${e.error.message})`,kick:!0};case`closed-there`:return{kind:`reconnect`,reason:`daemon closed the stream`,kick:!1};case`refused`:return e.resp.code===`SWITCHED_OFF`?{kind:`off`,resp:e.resp}:e.resp.code===`TIMEOUT`?{kind:`reconnect`,reason:`the daemon was too busy to open the stream (${e.resp.error})`,kick:!1}:e.resp.code===`BAD_REQUEST`?{kind:`reconnect`,reason:`the daemon does not take subscribe (${e.resp.error}); it restarts on the new build`,kick:!1}:e.resp.code===`VERSION_MISMATCH`&&e.resp.daemonV!==void 0&&e.resp.daemonV<3?{kind:`reconnect`,reason:`the daemon is older than this client (${e.resp.error})`,kick:!0}:{kind:`exit`,reason:`the daemon refused the stream: ${e.resp.code}: ${e.resp.error}`}}}function s$(e,t,n,r){let i=null,a=null,o=!1,s=250,c=(e,t)=>{a=setTimeout(()=>{a=null,((t?r.beforeReconnect?.():void 0)??Promise.resolve()).then(()=>{o||l()})},e)},l=()=>{i=a$(e,t,n,e=>{e.ok&&(s=250),r.frame(e)},e=>{if(e.kind===`closed-here`||o)return;let t=o$(e);switch(t.kind){case`exit`:r.exit(t.reason);return;case`off`:r.off(t.resp),c(5e3,!1);return;case`reconnect`:{r.fault(t.reason,s),t.kick&&fn();let e=s;s=Math.min(2e3,s*2),c(e,!0);return}}})};return l(),{close:()=>{o=!0,a!==null&&clearTimeout(a),i?.close()}}}const c$=[`black`,`red`,`green`,`yellow`,`blue`,`magenta`,`cyan`,`white`,`blackBright`,`redBright`,`greenBright`,`yellowBright`,`blueBright`,`magentaBright`,`cyanBright`,`whiteBright`];function l$(e){if(e===void 0||e.isDefault)return;let t=e.fixedValue;if(t!==void 0)return t.hex;let n=e.type===V.STANDARD&&e.number!==void 0?c$[e.number]:void 0;if(n===void 0)throw Error(`frames: no band colour for ${e.name}`);return n}const u$={bold:`bold`,dim:`dimColor`,italic:`italic`,underline:`underline`,strike:`strikethrough`,reverse:`inverse`,blink:null,blink2:null,conceal:null,underline2:null,frame:null,encircle:null,overline:null},d$=Object.keys(u$);function f$(e,t){let n=l$(t.color),r=l$(t.bgcolor),i={};for(let e of d$){if(t[e]!==!0)continue;let n=u$[e];if(n===null)throw Error(`frames: the band cannot draw ${e} text`);i[n]=!0}return{text:e,...n!==void 0&&{color:n},...r!==void 0&&{backgroundColor:r},...i,...t.link!==void 0&&{href:t.link}}}const p$=new U;function m$(e){return{kind:`bar`,rows:new ef().decode(e).map(e=>{let t=e.plain,n=[],r=0;for(let i of e.spans){if(!(i.style instanceof U))throw Error(`frames: the decoder gave a span a ${typeof i.style} style`);i.start>r&&n.push(f$(t.slice(r,i.start),p$)),n.push(f$(t.slice(i.start,i.end),i.style)),r=i.end}return r<t.length&&n.push(f$(t.slice(r),p$)),n})}}function h$(e){if(!e.ok&&e.code===`SWITCHED_OFF`)return JSON.stringify({kind:`off`,reason:e.error});let t=IQ(zt(e)).output;try{return JSON.stringify(m$(t))}catch(e){let t=Dp(e instanceof Error?e.message:String(e));return JSON.stringify(m$(`${Ap}${kp}⚠ cc-candybar ${t}${jp}\n`))}}const g$={response:e=>JSON.stringify(e),band:h$};function _$(e){return Object.hasOwn(g$,e)}function v$(e,t){return t.kind===`frame`||t.kind!==e.kind?!0:t.kind===`fault`&&e.kind===`fault`&&t.reason!==e.reason}async function y$(e,n){let{values:r,tokens:i}=re({args:e.slice(3),options:{session:{type:`string`},config:{type:`string`},lane:{type:`string`},format:{type:`string`,default:`response`}},strict:!0,tokens:!0}),a=[e[1],...i.flatMap(e=>e.kind===`option`&&e.name===`config`?[e.rawName,e.value]:[])],o=t.cwd(),s=e=>{t.stderr.write(`cc-candybar frames: ${e}\n`)};r.session===``&&(s(`--session needs a session id`),t.exit(2));let c=Ia(r.lane);c===null&&(s(`--lane needs one of ${Pa.join(`, `)}`),t.exit(2)),_$(r.format)||(s(`--format must be one of ${Object.keys(g$).join(`, `)}, got ${JSON.stringify(r.format)}`),t.exit(2));let l=g$[r.format];r.session!==void 0&&r.config!==void 0&&(s(`--config has no effect with --session: the session's own statusline client sends its config`),t.exit(2)),t.stdout.on(`error`,()=>t.exit(0));let u=CX(t.stdout),d=r.session??null,f=null,p=null,m={kind:`none`},h=(e,t)=>{v$(m,e)&&t(),m=e},g=async e=>{let r=await Bt(e,a,o,{...zQ(t.env,o,t.stderr),client:A(`frames`,n)});r.kind!==`ok`&&(s(Pt(r)),r.kind===`transient`&&fn())},_=e=>{p?.close(),p=s$(Ke(),e,c,{frame:e=>h({kind:`frame`},()=>u(`${l(e)}\n`)),off:e=>h({kind:`off`},()=>u(`${l(e)}\n`)),fault:(e,t)=>h({kind:`fault`,reason:e},()=>s(`${e}; reconnecting in ${t}ms`)),exit:e=>{s(e),t.exit(1)},beforeReconnect:()=>f===null?Promise.resolve():g(f)})};if(d!==null){_(d);return}for await(let e of ge({input:t.stdin})){if(e.trim()===``)continue;let t;try{t=JSON.parse(e)}catch(e){s(`stdin line is not JSON: ${e.message}`);continue}if(typeof t.session_id!=`string`||t.session_id===``){s(`stdin line carries no session_id`);continue}f=t,await g(t),t.session_id!==d&&(d=t.session_id,_(d))}t.exit(0)}function b$(e){let t=e.replace(/\n+$/,``).split(`
|
|
510
|
+
`);return{bytes:t.map((e,t)=>`\x1b[${t+1}H[2K${e}`).join(``)+`\x1B[J`,rows:t.length}}const x$=5e3,S$=`usage: cc-candybar bar-pane <claude-code-pane-id, e.g. %3>`;function C$(e,t,n,r){let i=e.split(`
|
|
511
|
+
`).map(e=>e.trim().split(` `));return i.some(([e])=>e===n)?DX(e,EX(t)).has(r)?{kind:`shown`,zoomed:i.some(([e,,,,t])=>e===r&&t===`1`)}:{kind:`hidden`}:{kind:`gone`}}async function w$(e,t){let[n,r]=await Promise.all([lH(e,`bar-pane.tmux`,[`list-panes`,`-a`,`-f`,`#{||:#{==:#{pane_id},${t}},#{==:#{pane_id},${e.pane}}}`,`-F`,wX]),lH(e,`bar-pane.tmux`,[`list-clients`,`-F`,TX])]);return n.kind===`ok`?r.kind===`ok`?{kind:`ok`,placement:C$(n.stdout,r.stdout,t,e.pane)}:r:n}function T$(){let e=Date.now();return t=>{if(t.kind===`ok`)e=Date.now();else if(Date.now()-e>x$)throw Error(`tmux has not answered for ${x$/1e3} s: ${t.reason}`)}}function E$(e){let{positionals:t}=(()=>{try{return re({args:[...e],allowPositionals:!0})}catch(e){throw Error(`${e.message}\n${S$}`)}})(),[n,...r]=t;if(n===void 0||r.length>0||!/^%\d+$/.test(n))throw Error(S$);return{pane:n}}async function D$(e){try{return await O$(e),0}catch(e){return t.stderr.write(`cc-candybar bar-pane: ${e.message}\n`),1}}async function O$(e){let{pane:n}=E$(e),r=Ek(t.env);if(r===null)throw Error(`cc-candybar bar-pane runs in a tmux pane`);if(!t.stdout.isTTY)throw Error(`cc-candybar bar-pane draws on its pane's terminal`);let i=await w$(r,n);if(i.kind!==`ok`)throw Error(i.reason);let a=i.placement;if(a.kind===`gone`)throw Error(`no pane ${n} on this tmux server (${r.socket})`);t.stdout.write(`\x1B[?25l\x1B[?7l`),t.on(`exit`,()=>t.stdout.write(`\x1B[?25h\x1B[?7h`));for(let[e,n]of[[`SIGINT`,130],[`SIGTERM`,143],[`SIGHUP`,129]])t.once(e,()=>t.exit(n));let o=e=>{t.stderr.write(`cc-candybar bar-pane: ${e.message}\n`),t.exit(1)},s=null,c=`waiting for pane ${n}'s bar`,l=()=>s?.said.latest??c,u=``,d=T$(),f=async()=>{if(a.kind!==`shown`)return;let e=b$(l());e.rows!==t.stdout.rows&&!a.zoomed&&d(await lH(r,`bar-pane.tmux`,[`resize-pane`,`-t`,r.pane,`-y`,String(e.rows)])),e.bytes!==u&&t.stdout.write(e.bytes),u=e.bytes},p=null,m=!1,h=()=>{m=!0,p??=(async()=>{try{for(;m;)m=!1,await f()}finally{p=null}})(),p.catch(o)};t.stdout.on(`resize`,()=>{u=``,h()});let g=e=>{if(s?.sessionId===e)return;if(s?.follower.close(),e===null){s=null;return}let t={latest:null},n=e=>{t.latest=e,h()};s={sessionId:e,said:t,follower:s$(Ke(),e,`pane`,{frame:e=>n(IQ(zt(e)).output),off:e=>n(e.error),fault:n,exit:e=>o(Error(e))})}},_=T$();for(;a.kind!==`gone`;){if(a.kind===`hidden`)g(null);else{let e=await Vt(r.socket,n);e.kind===`ok`?(g(e.value),c=e.value===null?`waiting for pane ${n}'s statusline to render on ${Ke()}`:`waiting for pane ${n}'s bar`):(e.kind===`transient`&&(fn(),u=``),c=Pt(e))}h(),await he(500);let e=await w$(r,n);_(e),e.kind===`ok`&&(a=e.placement)}g(null),t.stderr.write(`cc-candybar bar-pane: pane ${n} closed\n`)}const k$=i(import.meta.url),A$=e=>e.some(e=>t.argv.includes(e));function j$(){console.log(Ck)}async function M$(){try{A$(xk.help)&&(j$(),t.exit(0)),A$(xk.version)&&(console.log(`cc-candybar ${Ft}`),t.exit(0));let e=t.argv[2];if(e===`install`&&(await ca(t.argv.slice(3),k$),t.exit(0)),e===`install-url-handler`&&(ra(k$),t.exit(0)),e===`url-handle`){await aa(t.argv[3]);return}if(e===`daemon`){uZ();return}if(e===`daemon-stats`&&(await mJ(t.argv.slice(3)),t.exit(0)),e===`frames`){await y$(t.argv,k$);return}if(e===`check`||e===`lint`){await bQ(t.argv.slice(3));return}if(e===`plugin`&&t.exit(MQ(t.argv.slice(3))),e===`schema`){aQ();return}if(e===`doctor`){await i$(t.argv.slice(3));return}e===`bar-pane`&&t.exit(await D$(t.argv.slice(3))),yX(e)&&(await XZ(e,t.argv.slice(3)),t.exit(0)),t.stdin.isTTY===!0&&(console.error(`Error: This tool requires input from Claude Code
|
|
512
512
|
|
|
513
513
|
cc-candybar is designed to be used as a Claude Code statusLine command.
|
|
514
514
|
It reads hook data from stdin and outputs formatted statusline.
|
|
@@ -524,4 +524,4 @@ Add to ~/.claude/settings.json:
|
|
|
524
524
|
Run with --help for more options.
|
|
525
525
|
|
|
526
526
|
To test output manually:
|
|
527
|
-
echo '{"session_id":"test-session","workspace":{"project_dir":"/path/to/project"},"model":{"id":"claude-sonnet-4-5","display_name":"Claude"}}' | cc-candybar`),t.exit(1)),k(`Working directory: ${t.cwd()}`),k(`Process args:`,t.argv);let n=await o(t.stdin);k(`Received hook data:`,JSON.stringify(n,null,2)),n||(console.error(`Error: No input data received from stdin`),
|
|
527
|
+
echo '{"session_id":"test-session","workspace":{"project_dir":"/path/to/project"},"model":{"id":"claude-sonnet-4-5","display_name":"Claude"}}' | cc-candybar`),t.exit(1)),k(`Working directory: ${t.cwd()}`),k(`Process args:`,t.argv);let n=await o(t.stdin);k(`Received hook data:`,JSON.stringify(n,null,2)),n||(console.error(`Error: No input data received from stdin`),j$(),t.exit(1));let r=IQ(await Bt(n,t.argv,t.cwd(),{...zQ(t.env,t.cwd(),t.stderr),client:A(`node`,k$)}));r.debug!==null&&k(r.debug),r.kick&&fn(),t.stdout.write(r.output),t.exit(0)}catch(e){let n=e instanceof Error?e.message:String(e);console.error(`Error generating statusline:`,n),t.exit(1)}}M$();export{};
|