@promptctl/cc-candybar 1.133.0 → 1.134.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +50 -50
- package/package.json +5 -5
- package/schema/cc-candybar.schema.json +1 -0
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{createRequire as e}from"node:module";import t from"node:process";import{json as n}from"node:stream/consumers";import r,{createReadStream as i,existsSync as a,realpathSync as o,statSync as s,watch as c}from"node:fs";import l,{basename as u,dirname as d,isAbsolute as f,join as p,sep as m}from"node:path";import h,{homedir as g}from"node:os";import{spawn as _,spawnSync as v}from"node:child_process";import{inspect as y,parseArgs as b,types as x}from"node:util";import S from"node:net";import C from"node:v8";import{URL as ee,URLSearchParams as te,fileURLToPath as ne,pathToFileURL as re}from"node:url";import ie,{createHash as ae,randomUUID as w}from"node:crypto";import{open as T,readFile as oe,readdir as E,stat as se}from"node:fs/promises";import{clearInterval as ce,setInterval as le}from"node:timers";import{get as ue}from"node:https";import{setTimeout as de}from"node:timers/promises";import{createInterface as fe}from"node:readline";var pe=Object.create,me=Object.defineProperty,he=Object.getOwnPropertyDescriptor,ge=Object.getOwnPropertyNames,_e=Object.getPrototypeOf,ve=Object.prototype.hasOwnProperty,ye=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),be=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=ge(t),a=0,o=i.length,s;a<o;a++)s=i[a],!ve.call(e,s)&&s!==n&&me(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=he(t,s))||r.enumerable});return e},xe=(e,t,n)=>(n=e==null?{}:pe(_e(e)),be(t||!e||!e.__esModule?me(n,`default`,{value:e,enumerable:!0}):n,e));function D(e,...t){process.env.CC_CANDYBAR_DEBUG&&console.error(`[DEBUG] ${e}`,...t)}function Se(e,t){return x.isNativeError(e)?e.code===`ENOENT`&&t!==void 0&&!a(t)?`working directory does not exist: ${t}`:e.message:String(e)}const Ce={"click.pbcopy":1e3,"click.open":1e3,"doctor.tmux":1e3,"doctor.font":1e3,"doctor.process":1e3,"claude-input.type":1e3},we=new Map;function Te(e){let t=Ce[e];if(t===void 0)return{allowed:!0};let n=we.get(e);if(n===void 0)return{allowed:!0};let r=Date.now()-n;return r>=t?{allowed:!0}:{allowed:!1,minIntervalMs:t,sinceLastMs:r}}function Ee(e){we.set(e,Date.now())}function De(e){return e.env??process.env}function Oe(e,t,n){return{ok:!1,reason:`rate-limited`,stdout:``,stderr:``,exitCode:null,signal:null,error:`rate-limited: ${e} min interval ${t}ms, last start ${n}ms ago`}}let ke=null;function Ae(e){ke=e}function je(e,t){try{process.kill(-e,t)}catch(e){if(e.code!==`ESRCH`)throw e}}async function Me(e){if(e.signal?.aborted)return{ok:!1,reason:`aborted`,stdout:``,stderr:``,exitCode:null,signal:null};let t=Te(e.category);if(!t.allowed)return Oe(e.category,t.minIntervalMs,t.sinceLastMs);Ee(e.category);let n=Date.now();return ke?.onStart(e.category),new Promise(t=>{let r;try{r=_(e.bin,e.args??[],{cwd:e.cwd,env:De(e),stdio:[`pipe`,`pipe`,`pipe`],detached:!0})}catch(r){ke?.onEnd(e.category,Date.now()-n),t({ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:Se(r,e.cwd)});return}let i=``,a=``,o=!1,s=null,c=null,l=null,u=()=>m(`aborted`),d=t=>{o||(o=!0,s&&clearTimeout(s),c&&clearTimeout(c),e.signal?.removeEventListener(`abort`,u),ke?.onEnd(e.category,Date.now()-n),t())},f=e=>d(()=>t(e)),p=(e,t)=>{try{je(e,t)}catch(e){f({ok:!1,reason:`signal-refused`,stdout:i,stderr:a,exitCode:null,signal:null,error:e instanceof Error?e.message:String(e)})}},m=t=>{l=t,s&&clearTimeout(s),e.signal?.removeEventListener(`abort`,u);let n=r.pid;n!==void 0&&(c=setTimeout(()=>p(n,`SIGKILL`),250),p(n,`SIGTERM`))};r.stdout?.on(`data`,e=>{i+=e.toString(`utf8`)}),r.stderr?.on(`data`,e=>{a+=e.toString(`utf8`)}),r.on(`error`,t=>{f({ok:!1,reason:`spawn-error`,stdout:i,stderr:a,exitCode:null,signal:null,error:Se(t,e.cwd)})}),r.on(`close`,(e,t)=>{if(l!==null){f({ok:!1,reason:l,stdout:i,stderr:a,exitCode:e,signal:t});return}if(e===0){f({ok:!0,stdout:i,stderr:a,exitCode:e});return}f({ok:!1,reason:t?`signal`:`non-zero`,stdout:i,stderr:a,exitCode:e,signal:t})}),e.timeoutMs&&e.timeoutMs>0&&(s=setTimeout(()=>m(`timeout`),e.timeoutMs)),e.signal?.addEventListener(`abort`,u,{once:!0}),e.stdinInput!==void 0&&r.stdin?r.stdin.end(e.stdinInput):r.stdin&&r.stdin.end()})}function Ne(e){let t=Te(e.category);if(!t.allowed)return Oe(e.category,t.minIntervalMs,t.sinceLastMs);Ee(e.category);let n=Date.now();ke?.onStart(e.category);let r=[`pipe`,`pipe`,`pipe`];try{let t=v(e.bin,e.args??[],{cwd:e.cwd,env:De(e),input:e.stdinInput,timeout:e.timeoutMs&&e.timeoutMs>0?e.timeoutMs:void 0,stdio:r,encoding:`utf8`});ke?.onEnd(e.category,Date.now()-n);let i=typeof t.stdout==`string`?t.stdout:``,a=typeof t.stderr==`string`?t.stderr:``;if(t.error)return{ok:!1,reason:t.error.code===`ETIMEDOUT`?`timeout`:`spawn-error`,stdout:i,stderr:a,exitCode:null,signal:t.signal??null,error:Se(t.error,e.cwd)};if(t.status===0)return{ok:!0,stdout:i,stderr:a,exitCode:t.status};let o=e.timeoutMs!==void 0&&e.timeoutMs>0;return{ok:!1,reason:t.signal?o&&t.signal===`SIGTERM`?`timeout`:`signal`:`non-zero`,stdout:i,stderr:a,exitCode:t.status,signal:t.signal??null}}catch(t){return ke?.onEnd(e.category,Date.now()-n),{ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:Se(t,e.cwd)}}}function Pe(e){let t=Te(e.category);if(!t.allowed)return Oe(e.category,t.minIntervalMs,t.sinceLastMs);Ee(e.category);let n=Date.now();ke?.onStart(e.category);let r=Fe(e);return ke?.onEnd(e.category,Date.now()-n),r}function Fe(e){let t;try{t=_(e.bin,e.args??[],{cwd:e.cwd,env:De(e),detached:!0,stdio:`ignore`})}catch(t){return{ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:Se(t,e.cwd)}}return t.once(`error`,()=>{}),t.pid===void 0?{ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:`spawn(${e.bin}): no pid (binary not found or unexecutable)`}:(t.unref(),{ok:!0,stdout:``,stderr:``,exitCode:null})}function Ie(e,t,n){let i=`${e}.tmp`,a=n??r.statSync(e,{throwIfNoEntry:!1})?.mode;try{r.writeFileSync(i,t,a===void 0?{}:{mode:a}),r.renameSync(i,e)}catch(e){throw r.rmSync(i,{force:!0}),e}}function Le(e,t){let n=e[t];return n&&n.length>0?n:void 0}function Re(e=process.env){let t=Le(e,`XDG_STATE_HOME`)??l.join(h.homedir(),`.local`,`state`);return l.join(t,`cc-candybar`)}function ze(){let e=Le(process.env,`XDG_CACHE_HOME`)??l.join(h.homedir(),`.cache`);return l.join(e,`cc-candybar`)}function Be(){return Re()}function Ve(){return process.env.CC_CANDYBAR_SOCKET||He()}function He(){let e=h.userInfo().uid;return l.join(`/tmp`,`cc-candybar-${e}`,`socket`)}function Ue(e){r.mkdirSync(e,{recursive:!0,mode:448});let t=r.lstatSync(e);if(t.isSymbolicLink())throw Error(`directory is a symlink: ${e}`);if(!t.isDirectory())throw Error(`not a directory: ${e}`);let n=h.userInfo().uid;if(typeof n==`number`&&t.uid!==n)throw Error(`directory is not owned by uid ${n}: ${e} (owner uid=${t.uid})`);if(t.mode&63)throw Error(`directory has unsafe permissions: ${e} (mode=${(t.mode&511).toString(8)}, expected 0700)`)}function We(e){Ue(l.dirname(e));for(let t of[e,Ge(e)])try{if(r.lstatSync(t).isSymbolicLink())throw Error(`path is a symlink: ${t}`)}catch(e){if(e.code!==`ENOENT`)throw e}}function Ge(e){return`${e}.lease`}function Ke(){return Ge(Ve())}function qe(){return l.join(Re(),`session-state.json`)}function Je(){return l.join(Re(),`settings-history.json`)}function Ye(){let e=process.env.CC_CANDYBAR_DAEMON_REGISTRY_DIR;if(e)return e;let t=h.userInfo().uid;return l.join(`/tmp`,`cc-candybar-${t}`,`daemons`)}function Xe(){return l.join(Re(),`spawn.lock`)}function Ze(){return l.join(Re(),`spawn.cooldown`)}function Qe(){return l.join(Re(),`spawn.backoff`)}function $e(){return l.join(Re(),`diagnostics`)}function et(e=process.env){return l.join(Re(e),`daemon.log`)}const tt=[`MEMENTO_CONFIG_HOME`,`XDG_CONFIG_HOME`];function nt(e,t){return Object.fromEntries(tt.flatMap(n=>{let r=e[n]??``;return r===``?[]:[[n,l.resolve(t,r)]]}))}const rt=[`TERM_PROGRAM`,`TERM_PROGRAM_VERSION`,`TERM`,`ITERM_PROFILE`,`XDG_CONFIG_HOME`];function it(e){return Object.fromEntries(rt.flatMap(t=>{let n=e[t]??``;return n===``?[]:[[t,n]]}))}const at=Object.keys({termCols:!0,termRows:!0,ssh:!0,tmux:!0,configEnv:!0,claudeConfigDir:!0,mementoEnv:!0,terminalEnv:!0});function ot(e){let t=pt(e.termCols),n=pt(e.termRows),r=mt(e.ssh),i=ft(e.tmux),a=dt(e.configEnv),o=dt(e.claudeConfigDir),s=lt(e.mementoEnv),c=ut(e.terminalEnv);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}}}function st(e,t){return at.filter(n=>e[n]!==void 0&&t[n]===void 0).map(t=>({hint:t,sent:e[t]}))}function ct(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 lt(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=e,n=tt.filter(e=>t[e]!==void 0);return n.every(e=>dt(t[e])!==void 0)?Object.fromEntries(n.map(e=>[e,t[e]])):void 0}function ut(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=e,n=rt.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 dt(e){return typeof e==`string`&&l.isAbsolute(e)?e:void 0}function ft(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 O=1e4;function pt(e){if(typeof e!=`number`||!Number.isFinite(e))return;let t=Math.floor(e);if(!(t<=0))return t>O?O:t}function mt(e){return typeof e==`boolean`?e:void 0}function ht(e){return typeof e==`string`&&e!==``&&e.length<=64?e:null}var gt=class extends Error{constructor(e){super(e),this.name=`ProtocolError`}};function k(e){let t=Buffer.from(JSON.stringify(e),`utf8`),n=Buffer.alloc(4);return n.writeUInt32BE(t.length,0),Buffer.concat([n,t])}function _t(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 gt(`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 gt(e instanceof Error?e.message:String(e));e instanceof Error&&(n.cause=e),t(n);return}}}}function vt(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=_t(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(k(t))})}async function yt(e,t,n){let r=null;try{r=await wt(Ve(),t.connectMs);let i=await vt(r,{v:3,...e},t.budgetMs);return St(e.kind,i,n)}catch(e){return Ct(e)}finally{r&&r.destroy()}}function bt(e,t){return typeof e==`string`?e:t}function xt(e){return typeof e==`number`&&Number.isInteger(e)&&e>=0?e:0}function St(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=bt(r.error,`(no error message)`);switch(r.code){case`VERSION_MISMATCH`:return{kind:`permanent`,cause:`version_mismatch`,clientV:3,daemonV:xt(r.daemonV)};case`TIMEOUT`:return{kind:`transient`,cause:`timeout`,message:i};case`BAD_REQUEST`:return{kind:`permanent`,cause:`bad_request`,message:i};case`RENDER_FAILED`:return{kind:`permanent`,cause:`render_failed`,message:i};default:return{kind:`permanent`,cause:`malformed_response`,message:`unknown error code: ${String(r.code)}`}}}function Ct(e){if(e instanceof gt||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 wt(e,t){return new Promise((n,r)=>{let i=S.createConnection({path:e}),a=setTimeout(()=>{i.destroy(),r(Error(`CONNECT_TIMEOUT`))},t);i.once(`connect`,()=>{clearTimeout(a),n(i)}),i.once(`error`,e=>{clearTimeout(a),r(e)})})}function Tt(e){if(e.kind===`transient`)return`daemon unavailable (${e.cause}: ${e.message})\nHint: daemon may not be running. Run \`cc-candybar\` once to spawn it.`;switch(e.cause){case`version_mismatch`:{let t=e.daemonV===0?`unknown`:`v${e.daemonV}`;return`daemon protocol mismatch (client v${e.clientV} ≠ daemon ${t})`}case`bad_request`:case`render_failed`:case`malformed_response`:return`daemon error (${e.cause}): ${e.message}`}}const Et=`1.133.0`,Dt={connectMs:50,budgetMs:150},Ot={connectMs:50,budgetMs:200};function kt(e){let t=e.output;return typeof t==`string`?t:void 0}function At(e,t,n,r){return yt({kind:`render`,hookData:e,args:t,cwd:n,...r},Dt,kt)}function jt(e,t){return yt({kind:`click`,verb:e,value:t,clientVersion:Et},Ot,kt)}let Mt=null;function Nt(e){if(Mt!==null)return Mt;r.mkdirSync(l.dirname(e),{recursive:!0});try{Mt=r.statSync(e).size}catch{Mt=0}return Mt}function Pt(e){for(let t=2;t>=1;t--){let n=`${e}.${t}`,i=`${e}.${t+1}`;try{r.renameSync(n,i)}catch{}}try{r.renameSync(e,`${e}.1`)}catch{}Mt=0}const Ft=(e,t)=>D(t);function A(e,t){let n=`${new Date().toISOString()} [${e}] ${t}\n`;try{let e=et(),t=Nt(e);r.appendFileSync(e,n),Mt=t+Buffer.byteLength(n,`utf8`),Mt>=5242880&&Pt(e)}catch(e){Mt=null;try{process.stderr.write(`${n}cc-candybar: daemon.log unwritable: ${e.message}\n`)}catch{}}}function It(e){let t=[];for(let n of e){let e=n.read();if(e.kind===`text`)return`# memory report from: ${n.name}\n${e.text}`;t.push(`# ${n.name}: unavailable — ${e.reason}`)}return[`# memory report: no probe answered`,...t.length>0?t:[`# no probe is known for this platform`]].join(`
|
|
2
|
+
import{createRequire as e}from"node:module";import t from"node:process";import{json as n}from"node:stream/consumers";import r,{createReadStream as i,existsSync as a,realpathSync as o,statSync as s,watch as c}from"node:fs";import l,{basename as u,dirname as d,isAbsolute as f,join as p,sep as m}from"node:path";import h,{homedir as g}from"node:os";import{spawn as _,spawnSync as v}from"node:child_process";import{inspect as y,parseArgs as b,types as x}from"node:util";import S from"node:net";import C from"node:v8";import{URL as ee,URLSearchParams as te,fileURLToPath as ne,pathToFileURL as re}from"node:url";import ie,{createHash as ae,randomUUID as w}from"node:crypto";import{open as T,readFile as oe,readdir as E,stat as se}from"node:fs/promises";import{clearInterval as ce,setInterval as le}from"node:timers";import{get as ue}from"node:https";import{setTimeout as de}from"node:timers/promises";import{createInterface as fe}from"node:readline";var pe=Object.create,me=Object.defineProperty,he=Object.getOwnPropertyDescriptor,ge=Object.getOwnPropertyNames,_e=Object.getPrototypeOf,ve=Object.prototype.hasOwnProperty,ye=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),be=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=ge(t),a=0,o=i.length,s;a<o;a++)s=i[a],!ve.call(e,s)&&s!==n&&me(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=he(t,s))||r.enumerable});return e},xe=(e,t,n)=>(n=e==null?{}:pe(_e(e)),be(t||!e||!e.__esModule?me(n,`default`,{value:e,enumerable:!0}):n,e));function D(e,...t){process.env.CC_CANDYBAR_DEBUG&&console.error(`[DEBUG] ${e}`,...t)}function Se(e,t){return x.isNativeError(e)?e.code===`ENOENT`&&t!==void 0&&!a(t)?`working directory does not exist: ${t}`:e.message:String(e)}const Ce={"click.pbcopy":1e3,"click.open":1e3,"doctor.tmux":1e3,"doctor.font":1e3,"doctor.process":1e3,"claude-input.type":1e3},we=new Map;function Te(e){let t=Ce[e];if(t===void 0)return{allowed:!0};let n=we.get(e);if(n===void 0)return{allowed:!0};let r=Date.now()-n;return r>=t?{allowed:!0}:{allowed:!1,minIntervalMs:t,sinceLastMs:r}}function Ee(e){we.set(e,Date.now())}function De(e){return e.env??process.env}function Oe(e,t,n){return{ok:!1,reason:`rate-limited`,stdout:``,stderr:``,exitCode:null,signal:null,error:`rate-limited: ${e} min interval ${t}ms, last start ${n}ms ago`}}let ke=null;function Ae(e){ke=e}function je(e,t){try{process.kill(-e,t)}catch(e){if(e.code!==`ESRCH`)throw e}}async function Me(e){if(e.signal?.aborted)return{ok:!1,reason:`aborted`,stdout:``,stderr:``,exitCode:null,signal:null};let t=Te(e.category);if(!t.allowed)return Oe(e.category,t.minIntervalMs,t.sinceLastMs);Ee(e.category);let n=Date.now();return ke?.onStart(e.category),new Promise(t=>{let r;try{r=_(e.bin,e.args??[],{cwd:e.cwd,env:De(e),stdio:[`pipe`,`pipe`,`pipe`],detached:!0})}catch(r){ke?.onEnd(e.category,Date.now()-n),t({ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:Se(r,e.cwd)});return}let i=``,a=``,o=!1,s=null,c=null,l=null,u=()=>m(`aborted`),d=t=>{o||(o=!0,s&&clearTimeout(s),c&&clearTimeout(c),e.signal?.removeEventListener(`abort`,u),ke?.onEnd(e.category,Date.now()-n),t())},f=e=>d(()=>t(e)),p=(e,t)=>{try{je(e,t)}catch(e){f({ok:!1,reason:`signal-refused`,stdout:i,stderr:a,exitCode:null,signal:null,error:e instanceof Error?e.message:String(e)})}},m=t=>{l=t,s&&clearTimeout(s),e.signal?.removeEventListener(`abort`,u);let n=r.pid;n!==void 0&&(c=setTimeout(()=>p(n,`SIGKILL`),250),p(n,`SIGTERM`))};r.stdout?.on(`data`,e=>{i+=e.toString(`utf8`)}),r.stderr?.on(`data`,e=>{a+=e.toString(`utf8`)}),r.on(`error`,t=>{f({ok:!1,reason:`spawn-error`,stdout:i,stderr:a,exitCode:null,signal:null,error:Se(t,e.cwd)})}),r.on(`close`,(e,t)=>{if(l!==null){f({ok:!1,reason:l,stdout:i,stderr:a,exitCode:e,signal:t});return}if(e===0){f({ok:!0,stdout:i,stderr:a,exitCode:e});return}f({ok:!1,reason:t?`signal`:`non-zero`,stdout:i,stderr:a,exitCode:e,signal:t})}),e.timeoutMs&&e.timeoutMs>0&&(s=setTimeout(()=>m(`timeout`),e.timeoutMs)),e.signal?.addEventListener(`abort`,u,{once:!0}),e.stdinInput!==void 0&&r.stdin?r.stdin.end(e.stdinInput):r.stdin&&r.stdin.end()})}function Ne(e){let t=Te(e.category);if(!t.allowed)return Oe(e.category,t.minIntervalMs,t.sinceLastMs);Ee(e.category);let n=Date.now();ke?.onStart(e.category);let r=[`pipe`,`pipe`,`pipe`];try{let t=v(e.bin,e.args??[],{cwd:e.cwd,env:De(e),input:e.stdinInput,timeout:e.timeoutMs&&e.timeoutMs>0?e.timeoutMs:void 0,stdio:r,encoding:`utf8`});ke?.onEnd(e.category,Date.now()-n);let i=typeof t.stdout==`string`?t.stdout:``,a=typeof t.stderr==`string`?t.stderr:``;if(t.error)return{ok:!1,reason:t.error.code===`ETIMEDOUT`?`timeout`:`spawn-error`,stdout:i,stderr:a,exitCode:null,signal:t.signal??null,error:Se(t.error,e.cwd)};if(t.status===0)return{ok:!0,stdout:i,stderr:a,exitCode:t.status};let o=e.timeoutMs!==void 0&&e.timeoutMs>0;return{ok:!1,reason:t.signal?o&&t.signal===`SIGTERM`?`timeout`:`signal`:`non-zero`,stdout:i,stderr:a,exitCode:t.status,signal:t.signal??null}}catch(t){return ke?.onEnd(e.category,Date.now()-n),{ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:Se(t,e.cwd)}}}function Pe(e){let t=Te(e.category);if(!t.allowed)return Oe(e.category,t.minIntervalMs,t.sinceLastMs);Ee(e.category);let n=Date.now();ke?.onStart(e.category);let r=Fe(e);return ke?.onEnd(e.category,Date.now()-n),r}function Fe(e){let t;try{t=_(e.bin,e.args??[],{cwd:e.cwd,env:De(e),detached:!0,stdio:`ignore`})}catch(t){return{ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:Se(t,e.cwd)}}return t.once(`error`,()=>{}),t.pid===void 0?{ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:`spawn(${e.bin}): no pid (binary not found or unexecutable)`}:(t.unref(),{ok:!0,stdout:``,stderr:``,exitCode:null})}function Ie(e,t,n){let i=`${e}.tmp`,a=n??r.statSync(e,{throwIfNoEntry:!1})?.mode;try{r.writeFileSync(i,t,a===void 0?{}:{mode:a}),r.renameSync(i,e)}catch(e){throw r.rmSync(i,{force:!0}),e}}function Le(e,t){let n=e[t];return n&&n.length>0?n:void 0}function Re(e=process.env){let t=Le(e,`XDG_STATE_HOME`)??l.join(h.homedir(),`.local`,`state`);return l.join(t,`cc-candybar`)}function ze(){let e=Le(process.env,`XDG_CACHE_HOME`)??l.join(h.homedir(),`.cache`);return l.join(e,`cc-candybar`)}function Be(){return Re()}function Ve(){return process.env.CC_CANDYBAR_SOCKET||He()}function He(){let e=h.userInfo().uid;return l.join(`/tmp`,`cc-candybar-${e}`,`socket`)}function Ue(e){r.mkdirSync(e,{recursive:!0,mode:448});let t=r.lstatSync(e);if(t.isSymbolicLink())throw Error(`directory is a symlink: ${e}`);if(!t.isDirectory())throw Error(`not a directory: ${e}`);let n=h.userInfo().uid;if(typeof n==`number`&&t.uid!==n)throw Error(`directory is not owned by uid ${n}: ${e} (owner uid=${t.uid})`);if(t.mode&63)throw Error(`directory has unsafe permissions: ${e} (mode=${(t.mode&511).toString(8)}, expected 0700)`)}function We(e){Ue(l.dirname(e));for(let t of[e,Ge(e)])try{if(r.lstatSync(t).isSymbolicLink())throw Error(`path is a symlink: ${t}`)}catch(e){if(e.code!==`ENOENT`)throw e}}function Ge(e){return`${e}.lease`}function Ke(){return Ge(Ve())}function qe(){return l.join(Re(),`session-state.json`)}function Je(){return l.join(Re(),`settings-history.json`)}function Ye(){let e=process.env.CC_CANDYBAR_DAEMON_REGISTRY_DIR;if(e)return e;let t=h.userInfo().uid;return l.join(`/tmp`,`cc-candybar-${t}`,`daemons`)}function Xe(){return l.join(Re(),`spawn.lock`)}function Ze(){return l.join(Re(),`spawn.cooldown`)}function Qe(){return l.join(Re(),`spawn.backoff`)}function $e(){return l.join(Re(),`diagnostics`)}function et(e=process.env){return l.join(Re(e),`daemon.log`)}const tt=[`MEMENTO_CONFIG_HOME`,`XDG_CONFIG_HOME`];function nt(e,t){return Object.fromEntries(tt.flatMap(n=>{let r=e[n]??``;return r===``?[]:[[n,l.resolve(t,r)]]}))}const rt=[`TERM_PROGRAM`,`TERM_PROGRAM_VERSION`,`TERM`,`ITERM_PROFILE`,`XDG_CONFIG_HOME`];function it(e){return Object.fromEntries(rt.flatMap(t=>{let n=e[t]??``;return n===``?[]:[[t,n]]}))}const at=Object.keys({termCols:!0,termRows:!0,ssh:!0,tmux:!0,configEnv:!0,claudeConfigDir:!0,mementoEnv:!0,terminalEnv:!0});function ot(e){let t=pt(e.termCols),n=pt(e.termRows),r=mt(e.ssh),i=ft(e.tmux),a=dt(e.configEnv),o=dt(e.claudeConfigDir),s=lt(e.mementoEnv),c=ut(e.terminalEnv);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}}}function st(e,t){return at.filter(n=>e[n]!==void 0&&t[n]===void 0).map(t=>({hint:t,sent:e[t]}))}function ct(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 lt(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=e,n=tt.filter(e=>t[e]!==void 0);return n.every(e=>dt(t[e])!==void 0)?Object.fromEntries(n.map(e=>[e,t[e]])):void 0}function ut(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=e,n=rt.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 dt(e){return typeof e==`string`&&l.isAbsolute(e)?e:void 0}function ft(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 O=1e4;function pt(e){if(typeof e!=`number`||!Number.isFinite(e))return;let t=Math.floor(e);if(!(t<=0))return t>O?O:t}function mt(e){return typeof e==`boolean`?e:void 0}function ht(e){return typeof e==`string`&&e!==``&&e.length<=64?e:null}var gt=class extends Error{constructor(e){super(e),this.name=`ProtocolError`}};function k(e){let t=Buffer.from(JSON.stringify(e),`utf8`),n=Buffer.alloc(4);return n.writeUInt32BE(t.length,0),Buffer.concat([n,t])}function _t(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 gt(`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 gt(e instanceof Error?e.message:String(e));e instanceof Error&&(n.cause=e),t(n);return}}}}function vt(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=_t(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(k(t))})}async function yt(e,t,n){let r=null;try{r=await wt(Ve(),t.connectMs);let i=await vt(r,{v:3,...e},t.budgetMs);return St(e.kind,i,n)}catch(e){return Ct(e)}finally{r&&r.destroy()}}function bt(e,t){return typeof e==`string`?e:t}function xt(e){return typeof e==`number`&&Number.isInteger(e)&&e>=0?e:0}function St(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=bt(r.error,`(no error message)`);switch(r.code){case`VERSION_MISMATCH`:return{kind:`permanent`,cause:`version_mismatch`,clientV:3,daemonV:xt(r.daemonV)};case`TIMEOUT`:return{kind:`transient`,cause:`timeout`,message:i};case`BAD_REQUEST`:return{kind:`permanent`,cause:`bad_request`,message:i};case`RENDER_FAILED`:return{kind:`permanent`,cause:`render_failed`,message:i};default:return{kind:`permanent`,cause:`malformed_response`,message:`unknown error code: ${String(r.code)}`}}}function Ct(e){if(e instanceof gt||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 wt(e,t){return new Promise((n,r)=>{let i=S.createConnection({path:e}),a=setTimeout(()=>{i.destroy(),r(Error(`CONNECT_TIMEOUT`))},t);i.once(`connect`,()=>{clearTimeout(a),n(i)}),i.once(`error`,e=>{clearTimeout(a),r(e)})})}function Tt(e){if(e.kind===`transient`)return`daemon unavailable (${e.cause}: ${e.message})\nHint: daemon may not be running. Run \`cc-candybar\` once to spawn it.`;switch(e.cause){case`version_mismatch`:{let t=e.daemonV===0?`unknown`:`v${e.daemonV}`;return`daemon protocol mismatch (client v${e.clientV} ≠ daemon ${t})`}case`bad_request`:case`render_failed`:case`malformed_response`:return`daemon error (${e.cause}): ${e.message}`}}const Et=`1.134.0`,Dt={connectMs:50,budgetMs:150},Ot={connectMs:50,budgetMs:200};function kt(e){let t=e.output;return typeof t==`string`?t:void 0}function At(e,t,n,r){return yt({kind:`render`,hookData:e,args:t,cwd:n,...r},Dt,kt)}function jt(e,t){return yt({kind:`click`,verb:e,value:t,clientVersion:Et},Ot,kt)}let Mt=null;function Nt(e){if(Mt!==null)return Mt;r.mkdirSync(l.dirname(e),{recursive:!0});try{Mt=r.statSync(e).size}catch{Mt=0}return Mt}function Pt(e){for(let t=2;t>=1;t--){let n=`${e}.${t}`,i=`${e}.${t+1}`;try{r.renameSync(n,i)}catch{}}try{r.renameSync(e,`${e}.1`)}catch{}Mt=0}const Ft=(e,t)=>D(t);function A(e,t){let n=`${new Date().toISOString()} [${e}] ${t}\n`;try{let e=et(),t=Nt(e);r.appendFileSync(e,n),Mt=t+Buffer.byteLength(n,`utf8`),Mt>=5242880&&Pt(e)}catch(e){Mt=null;try{process.stderr.write(`${n}cc-candybar: daemon.log unwritable: ${e.message}\n`)}catch{}}}function It(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 Lt(e,t){return e===`darwin`?[Rt(`footprint`,[`-p`,String(t)]),Rt(`vmmap`,[`--summary`,String(t)])]:e===`linux`?[zt(`/proc/self/smaps_rollup`),zt(`/proc/self/status`)]:[]}function Rt(e,t){return{name:`${e} ${t.join(` `)}`,read:()=>{let n=Ne({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}`}${Bt(n.stderr)}`}}}}function zt(e){return{name:e,read:()=>{try{let t=r.readFileSync(e,`utf8`);return t.trim().length>0?{kind:`text`,text:t}:{kind:`unavailable`,reason:`empty file`}}catch(e){return{kind:`unavailable`,reason:e.message}}}}}function Bt(e){let t=e.split(`
|
|
4
4
|
`).map(e=>e.trim()).find(e=>e.length>0);return t===void 0?``:` (${t})`}const Vt=`CC_CANDYBAR_RSS_LIMIT_MB`;function Ht(e){let t=e[Vt];if(t===void 0)return 512;let n=/^\d+$/.test(t)?Number(t):NaN;if(!Number.isSafeInteger(n)||n<=0)throw Error(`${Vt} must be a positive integer (MB), got ${JSON.stringify(t)}`);return n}function Ut(e){return Ht(e)*2}const j=1024*1024;function Wt(e){return Ht(e)*j}const Gt={memoryReport:{prefix:`memory-`,suffix:`.txt`},heapSnapshot:{prefix:`heap-`,suffix:`.heapsnapshot`}};function Kt(e,t,n){let{prefix:r,suffix:i}=Gt[t];return l.join(e,`${r}${n}${i}`)}function qt(e){for(let t of Object.keys(Gt)){let{prefix:n,suffix:r}=Gt[t];if(e.startsWith(n)&&e.endsWith(r))return t}return null}function Jt(e){let t=e.rssLimitBytes??512*j,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 Yt(e.log,`memory report`,()=>{let t=Kt(e.snapshotDir,`memoryReport`,o);e.writeMemoryReport(t,e.captureMemoryReport()),e.log(`info`,`memory report written: ${t}`)}),Yt(e.log,`heap snapshot`,()=>{let t=Kt(e.snapshotDir,`heapSnapshot`,o);e.log(`info`,`heap snapshot written: ${e.writeHeapSnapshot(t)}`)}),Yt(e.log,`artifact rotation`,()=>{Xt(e.listArtifacts(),n,e.removeFile)}),e.shutdown(0),!0}function a(){let{rss:n,heapTotal:r}=e.memoryBytes();return n>t*.75?`rss ${n} approaching limit ${t} (v8 heap ${r})`:null}function o(e=6e4){let t=setInterval(()=>{i()},e);return t.unref(),{disarm:()=>clearInterval(t)}}return{checkRss:i,describeNextRestart:a,arm:o}}function Yt(e,t,n){try{n()}catch(n){e(`warn`,`${t} failed: ${n.message}`)}}function M(e){let t=e.slice(e.lastIndexOf(`/`)+1),n=qt(t);if(n===null)return t;let{prefix:r,suffix:i}=Gt[n];return t.slice(r.length,t.length-i.length)}function Xt(e,t,n){let r=new Map;for(let t of e){let e=M(t),n=r.get(e);n===void 0?r.set(e,[t]):n.push(t)}let i=[...r.keys()].sort((e,t)=>t.localeCompare(e));for(let e of i.slice(t))for(let t of r.get(e)??[])try{n(t)}catch{}}function Zt(e,t,n={}){let i=Be();return{now:()=>Date.now(),pid:process.pid,snapshotDir:i,log:A,memoryBytes:()=>{let e=process.memoryUsage();return{rss:e.rss,heapTotal:e.heapTotal}},captureMemoryReport:()=>It(Lt(process.platform,process.pid)),writeMemoryReport:(e,t)=>r.writeFileSync(e,t,{mode:384}),writeHeapSnapshot:e=>C.writeHeapSnapshot(e),listArtifacts:()=>{try{return r.readdirSync(i).filter(e=>qt(e)!==null).map(e=>l.join(i,e))}catch{return[]}},removeFile:e=>r.unlinkSync(e),shutdown:t,startedAtMs:e,...n}}function Qt(e={}){if(hn()!==null)return;let n=e.spawn??gn,r=fn();if(r.kind===`contended`){let e=en();e!==null&&e>2e3&&(t.stderr.write(`cc-candybar: spawn-lock held ${e}ms (likely crashed holder) — spawning unlocked\n`),$t(n));return}if(r.kind===`error`){t.stderr.write(`cc-candybar: spawn-lock unavailable (${r.reason}) — spawning unlocked\n`),$t(n);return}try{$t(n)}finally{mn()}}function $t(e){cn()&&tn(e)}function en(){try{let e=r.statSync(Xe());return Date.now()-e.mtimeMs}catch{return null}}function tn(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 nn(e,t){return e===null?{kind:`allow`}:e<-1e4?{kind:`allow-future-garbage`,futureMs:-e}:e<t?{kind:`deny`}:{kind:`allow`}}function rn(e){return Math.min(3e3*2**Math.min(Math.max(e,0),5),6e4)}function an(e){try{let t=r.readFileSync(e,`utf8`).trim(),n=Number(t);return!Number.isInteger(n)||n<0?0:Math.min(n,5)}catch{return 0}}function on(e,n){try{r.mkdirSync(l.dirname(e),{recursive:!0}),r.writeFileSync(e,String(n),{mode:384})}catch(e){t.stderr.write(`cc-candybar: could not record spawn.backoff: ${e.message}\n`)}}function sn(){try{r.unlinkSync(Qe())}catch(e){e.code!==`ENOENT`&&t.stderr.write(`cc-candybar: could not reset spawn.backoff: ${e.message}\n`)}}function cn(){let e=Ze(),n=Qe(),r=an(n),i=nn(ln(e),rn(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`),un(e),on(n,Math.min(r+1,5)),!0)}function ln(e){try{return Date.now()-r.statSync(e).mtimeMs}catch{return null}}function un(e){try{r.mkdirSync(l.dirname(e),{recursive:!0}),r.writeFileSync(e,`${t.pid} ${Date.now()}\n`,{mode:384})}catch(e){t.stderr.write(`cc-candybar: could not record spawn.cooldown: ${e.message}\n`)}}let dn=null;function fn(){let e=Xe();for(let n=0;n<2;n++){try{let n=r.openSync(e,`wx`,384);try{r.writeSync(n,JSON.stringify({pid:t.pid,ts:Date.now()}))}catch{}return dn={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(!pn(e))return{kind:`contended`};try{r.unlinkSync(e)}catch(e){if(e.code!==`ENOENT`)return{kind:`error`,reason:`unlink stale spawn.lock: ${e.message}`}}}return{kind:`contended`}}function pn(e){try{let t=r.statSync(e);return Date.now()-t.mtimeMs>1e4}catch{return!0}}function mn(){if(!dn)return;let{fd:e,path:t}=dn;dn=null;try{r.closeSync(e)}catch{}try{r.unlinkSync(t)}catch{}}function hn(){try{return r.mkdirSync(Be(),{recursive:!0}),null}catch(e){return`mkdir ${Be()}: ${e.message}`}}function gn(){let e=t.execPath,n=t.argv[1];return n?Pe({bin:e,args:[`--max-old-space-size=${Ut(t.env)}`,n,`daemon`],category:`daemon-spawn`}).ok:!1}const _n=`cc-candybar`,vn=`dispatch`,yn=`set-state`,N=`step-state`,bn=`copy`,xn=`open-vscode`,Sn=`toolbar-toggle`,Cn=`show-config-error`,wn=`show-config-warning`,P=`set-config`,Tn=`step-config`,En=`save`,Dn=`save-preset`,On=`save-theme-default`,kn=`delete-preset`,An=`reset-config`,jn=`apply-layout-op`,Mn=`undo`,Nn=`redo`,Pn=`back`,Fn=`rewind`,In=`apply-update`,Ln=`doctor-run`,Rn=`doctor-fix`,zn=`doctor-mark`,Bn=`doctor-probe`,Vn=`ceiling`,Hn=`slash`;function Un(e){return e.map(encodeURIComponent).join(`/`)}function Wn(e){return e.length===0?[]:e.split(`/`).map(decodeURIComponent)}function Gn(e){return`${_n}://${vn}/${e.map(e=>`e=${encodeURIComponent(`${e.verb}/${Un(e.args)}`)}`).join(`&`)}`}function Kn(e){return new te(e).getAll(`e`).map(Xn)}const qn=new Set([yn,An]);function Jn(e){return e.reduce((e,t)=>{let n=e.at(-1),r=n&&Yn(n,t);return r?[...e.slice(0,-1),r]:[...e,t]},[])}function Yn(e,t){if(e.verb!==t.verb||!qn.has(e.verb))return;let[n,r]=[Xn(e.value),Xn(t.value)];return n.verb===r.verb?{verb:e.verb,value:`${n.verb}/${n.value}/${r.value}`}:void 0}function Xn(e){let t=e.indexOf(`/`);return t===-1?{verb:e,value:``}:{verb:e.slice(0,t),value:e.slice(t+1)}}const Zn=`closed`,Qn=`🍫`;function $n(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 er(e,t,n,r){let i=$n(e,t.length,n);if(i!==void 0)throw Error(i);return t.length===1?t[0]:t[r]}function tr(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}function nr(e,t,n,r,i){return{kind:`segment`,name:e,opens:{ref:t,body:n,placement:r},...i!==void 0&&{when:i}}}function rr(e,...t){return`{{ and ${[e,...t].map(ir).join(` `)} }}`}function ir(e){return`(eq .${e.variable} "${tr(e.member)}")`}function ar(e,t,n){return`{{ ${or(e,sr(t),sr(n))} }}`}function or(e,t,n){return`action "${e}" ${t} ${n}`}function sr(e){return`"${tr(e)}"`}function cr(e,t){return{kind:`state`,key:e,default:t}}function lr(e,t){return{set:e,cycle:[Zn,t]}}const ur=/^[A-Za-z0-9_./,:@%+-][A-Za-z0-9_./,:@%+=-]*$/;function dr(e){return`'${e.replaceAll(`'`,`'\\''`)}'`}function fr(e){return ur.test(e)?e:dr(e)}var pr=ye(((e,t)=>{t.exports.Space_Separator=/[\u1680\u2000-\u200A\u202F\u205F\u3000]/,t.exports.ID_Start=/[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE83\uDE86-\uDE89\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]/,t.exports.ID_Continue=/[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u08D4-\u08E1\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u09FC\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9-\u0AFF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C80-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D00-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D54-\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19D9\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1CD0-\u1CD2\u1CD4-\u1CF9\u1D00-\u1DF9\u1DFB-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE3E\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC00-\uDC4A\uDC50-\uDC59\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDE00-\uDE3E\uDE47\uDE50-\uDE83\uDE86-\uDE99\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC36\uDC38-\uDC40\uDC50-\uDC59\uDC72-\uDC8F\uDC92-\uDCA7\uDCA9-\uDCB6\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD36\uDD3A\uDD3C\uDD3D\uDD3F-\uDD47\uDD50-\uDD59]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD838[\uDC00-\uDC06\uDC08-\uDC18\uDC1B-\uDC21\uDC23\uDC24\uDC26-\uDC2A]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6\uDD00-\uDD4A\uDD50-\uDD59]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/})),mr=ye(((e,t)=>{let n=pr();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)}}})),hr=ye(((e,t)=>{let n=mr(),r,i,a,o,s,c,l,u,d;t.exports=function(e,t){r=String(e),i=`start`,a=[],o=0,s=1,c=0,l=void 0,u=void 0,d=void 0;do l=v(),re[i]();while(l.type!==`eof`);return typeof t==`function`?f({"":d},``,t):d};function f(e,t,n){let r=e[t];if(typeof r==`object`&&r)if(Array.isArray(r))for(let e=0;e<r.length;e++){let t=String(e),i=f(r,t,n);i===void 0?delete r[t]:Object.defineProperty(r,t,{value:i,writable:!0,enumerable:!0,configurable:!0})}else for(let e in r){let t=f(r,e,n);t===void 0?delete r[e]:Object.defineProperty(r,e,{value:t,writable:!0,enumerable:!0,configurable:!0})}return n.call(e,t,r)}let p,m,h,g,_;function v(){for(p=`default`,m=``,h=!1,g=1;;){_=y();let e=x[p]();if(e)return e}}function y(){if(r[o])return String.fromCodePoint(r.codePointAt(o))}function b(){let e=y();return e===`
|
|
@@ -53,7 +53,7 @@ import{createRequire as e}from"node:module";import t from"node:process";import{j
|
|
|
53
53
|
`))throw Error(`renderStripCells: rich-js strip output did not end its last line`);return s.slice(0,-1)}function Lm(e){return Math.min(20,e??20)}const Rm={heading:`ERROR`,glyph:`⚠`,colors:$d},zm={heading:`WARNING`,glyph:`⚠`,colors:ef},Bm={heading:`UPDATE`,glyph:`⬆`,colors:ef};function Vm(e,t){return{text:Jd(e),link:t}}function Hm(e,t,n){let[r,...i]=[Um(e,Rm,Cn),t,Um(n,zm,wn)].flat();return r===void 0?null:{channels:[r,...i]}}function Um(e,t,n){let r=Gn([{verb:n,args:[e]}]),[i,...a]=e.split(/\r\n|\r|\n/).map(e=>Vm(e,r)).filter(e=>e.text!==``).map(e=>[e]);return i===void 0?[]:[{severity:t,message:e,lines:[i,...a]}]}function Wm(e){return e.channels.map(e=>`${e.severity.heading}\n${e.message}\n`).join(`
|
|
54
54
|
`)}function Gm(e,t,n,r){if(t===null)return e;let i=Km(r),a=t.channels.flatMap(e=>qm(e,i)),o=n.failedConfigFile!==null||a.length>r.rowCap,s=a.slice(0,r.rowCap-Number(o)),c=o?[Jm(t,n,a.length-s.length,i)]:[],l=[...s,...c].join(`
|
|
55
55
|
`);return e?`${l}\n${e}`:l}function Km(e){return{endcaps:`plain`,separator:``,width:e.width,wrap:!0,padding:0,charset:`unicode`,colorCompatibility:e.colorCompatibility}}function qm(e,t){let n=new H({bgcolor:e.severity.colors.bg,color:e.severity.colors.fg}),r=go(Math.max(2,t.width-1)),i=(e,t)=>new G(`${e} `,{style:t,end:``,overflow:`ignore`});return e.lines.flatMap((a,o)=>Im([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=>xo(e,r)).map(e=>i(e,t))})],t).split(`
|
|
56
|
-
`))}function Jm(e,t,n,r){let{colors:i}=e.channels[0].severity,{fullText:a,failedConfigFile:o}=t,s=new H({bgcolor:i.bg,color:i.fg}),c=(e,t)=>new G(e,{style:t,end:``,overflow:`ignore`}),l=n>0?[c(`${n} more rows · `,s),a.kind===`file`?c(`open full text`,s.withLink(re(a.path).href)):c(`full text unavailable: ${Jd(a.reason)}`,s)]:[],u=o===null?[]:[c(`${l.length>0?` · `:``}open `,s),c(Jd(o),s.withLink(re(o).href))],d=[c(`↳ `,s),...l,...u.slice(0,-1)],f=d.reduce((e,t)=>e+t.cellLength,0),p=u.slice(-1).map(e=>e.truncate(Math.max(1,r.width-f),{mode:`middle`})),m=G.fromFragments([...d,...p]).truncate(r.width);return m.overflow=`ignore`,Im([m],r)}const Ym=e=>!e.startsWith(`.`)&&!e.endsWith(`~`);function Xm(e,t){return t.isSymbolicLink()?Buffer.from(r.readlinkSync(e)):r.readFileSync(e)}function Zm(e,t){return r.readdirSync(t).filter(Ym).sort().flatMap(n=>{let i=l.join(t,n),a=r.lstatSync(i,{throwIfNoEntry:!1});return a===void 0?[]:a.isDirectory()?Zm(e,i):[[l.relative(e,i).split(l.sep).join(`/`),Xm(i,a)]]})}function Qm(e){let t=ie.createHash(`sha256`);for(let[n,r]of Zm(e,e))t.update(n).update(`\0`).update(r).update(`\0`);return t.digest(`hex`)}const $m=e=>e.slice(0,7);function eh(e){return l.dirname(l.dirname(e))}function th(){return{version:Et,digest:`0483a2bce61e3008d6eb6339b9acde3868543415558ce41f95656e79bca851d7`}}function nh(e){let t=JSON.parse(r.readFileSync(l.join(e,`package.json`),`utf8`)),n=typeof t==`object`&&t?t.version:void 0;if(typeof n!=`string`)throw Error(`${l.join(e,`package.json`)} has no version string`);return n}function rh(e,t){try{let n=eh(ne(e)),i=l.join(n,`src`);if(!r.existsSync(i))return{kind:`not-source-checkout`};let a=t(),o=Qm(i);return o===a.digest?{kind:`current`,root:n,stamp:a}:{kind:`stale`,root:n,source:{version:nh(n),digest:o},running:a}}catch(e){return{kind:`unchecked`,reason:e.message}}}var K=class extends Error{constructor(e){super(e),this.name=`BadVerbArgs`}};const ih=new Map;function ah(e){let t=sh(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 oh(e,t){return e===`bar`?t:ah(e)}function sh(e){let t=ih.get(e);if(t!==void 0)return t;let n=kc(e);return n===null?null:(ih.set(e,n),n)}function ch(e,t){return lh(e,`${t.hueShift} ${t.chromaScale} ${t.lightnessScale} ${t.lightnessShift}`,()=>Vc(e,t))}const lh=tf();function uh(e){let t=sh(e);return t===null?null:{kind:`decided`,name:e,value:t}}function dh(e,t,n){let r=uh(e);return r===null?(n(jp(t,`palette`,`"${e}" names no installed theme${pp(e)}`)),ph()):r}function fh(e,t,n){return Cp(e,t,n,ph(),uh)}function ph(){return{kind:`decided`,name:mp,value:ah(mp)}}const mh=[`vertical`,`horizontal`],hh={vertical:`row`,horizontal:`cell`};function gh(e){return e.id??e.name}function _h(e){return[...bh(e)].flatMap(e=>e.kind===`segment`?[gh(e)]:[])}function vh(e,t){if(!t.has(e))return e;let n=2;for(;t.has(`${e}-${n}`);)n++;return`${e}-${n}`}function yh(e,t){return e.opens===void 0?e:{...e,opens:{...e.opens,body:t(e.opens.body)}}}function*bh(e){yield e;for(let t of wh(e))yield*bh(t)}const xh=(e,t)=>`${e}.children[${t}]`,Sh=e=>`${e}.opens.body`;function*Ch(e,t){if(yield[e,t],e.kind===`container`)for(let[n,r]of e.children.entries())yield*Ch(r,xh(t,n));else e.opens!==void 0&&(yield*Ch(e.opens.body,Sh(t)))}function wh(e){return e.kind===`container`?e.children:e.opens===void 0?[]:[e.opens.body]}const Th=[`shade`,`variation`,`style`];function Eh(e){return e===void 0||`text`in e?`text`:`regex`in e?`regex`:`json`}const Dh=[`ttl`,`watch_file`,`depends_on`,`key`,`never`];function Oh(e){return e.kind===`file`||e.kind===`shell`}const kh=[`branch`,`sha`,`dirty`,`ahead`,`behind`,`stash`],Ah=`theme`,jh=`effect`,Mh=[Ah,jh];function Nh(e){return{...e.settings,[Ah]:{label:Ah,domain:`theme`,default:e.palette??`bar`},[jh]:{label:jh,domain:Np,default:`bar`}}}function Ph(e){let t=e?.domain;return typeof t==`object`&&`min`in t?t:void 0}function Fh(e,t){return Object.entries(e).flatMap(([n,r])=>{let i=Ph(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 Ih(e,t){let{domain:n}=e;return n===`bool`?typeof t==`boolean`:n===`theme`?typeof t==`string`&&yp(t):`min`in n?typeof t==`number`&&Number.isInteger(t)&&t>=n.min&&t<=n.max:typeof t==`string`&&n.includes(t)}function Lh(e){return String(e)}function Rh(e,t){let{domain:n}=e;if(typeof n==`object`&&`min`in n)return im(t,n)??void 0;let r=n===`bool`?t===`true`?!0:t===`false`?!1:t:t;return Ih(e,r)?r:void 0}function zh(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:Rh(n,o))??i}function Bh(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 Vh=[`left`,`center`,`right`],Hh=[`right`,`left`,`middle`],Uh=/^[A-Za-z_][A-Za-z0-9_]*$/;function Wh(e){return`#${e+1}`}const Gh={rows:{}};function Kh(e){return`rows`in e}function qh(e){return Object.fromEntries(e.map((e,t)=>[Wh(t),e]))}function Jh(e){if(e.kind===`container`&&e.direction===`vertical`){let{kind:t,direction:n,children:r,...i}=e;return{...i,rows:qh(r)}}let{when:t,...n}=e;return{...t!==void 0&&{when:t},rows:qh([n])}}function Yh(e){let{rows:t,...n}=e;return{kind:`container`,direction:`vertical`,children:Object.values(t),...n}}function Xh(e){return Kh(e)?Yh(e):e}function*Zh(e,t){if(!Kh(e)){yield*Ch(e,t);return}yield[Yh(e),t];for(let[n,r]of Object.entries(e.rows))yield*Ch(r,`${t}.rows.${n}`)}function Qh(e,t){return Kh(e)?{...t,...e,rows:{...t.rows,...e.rows}}:Jh(e)}function $h(e){if(!Kh(e))return!0;let{rows:t,...n}=e;return Object.values(n).some(e=>e!==void 0)||Object.keys(t).length>0}const eg=`default`,tg={};function ng(e){return[...new Set([eg,...Object.keys(e)])]}function rg(e,t,n){return bp(void 0,e,t,eg,n)}function ig(e,t){let n={[eg]:tg,...e}[t];if(n===void 0)throw Error(`Preset "${t}" is not declared in this config — effectivePresetName collapses unknown names to "${eg}", which always resolves; a miss here means a raw name reached this function without going through that resolution`);return n}function ag(e,t){let n=ig(e.presets,t).root??Gh;return{node:Yh(Qh(n,e.root)),path:$h(n)?`presets.${t}.root`:`root`}}function og(e,t){return{...e.globals,...ig(e.presets,t).globals}}const sg=new Map;function cg(e,t,n){sg.set(e,{permanent:!0,resolve:t,paletteOf:n})}cg(`themes`,()=>gp(),e=>ah(e));const lg=`placementThemes`;cg(lg,_p,(e,t)=>oh(e,t.palette)),cg(`endcaps`,()=>Lp),cg(`variations`,()=>qp),cg(`shades`,()=>Xp),cg(`charsets`,()=>Hp),cg(`colorCompatibilities`,()=>Gp);function ug(e){return new Map([[`styles`,{members:Object.keys(e.styles),paletteOf:(t,n)=>ch(n.basePalette,e.styles[t])}],[`presets`,{members:ng(e.presets)}]])}function dg(e){return[...new Set([...sg.keys(),...e.keys()])]}function fg(e,t){if(typeof e!=`string`)return{members:e};let n=t.get(e);if(n)return n;let r=sg.get(e);if(r)return{members:r.resolve(),paletteOf:r.paletteOf};throw Error(mg(e,t))}const pg=new Map([[`looks`,`styles`],[`progressions`,`variations`]]);function mg(e,t){let n=pg.get(e);return`unknown option domain "${e}"${n===void 0?``:` — it was renamed "${n}"; write from: "${n}"`} (have: ${dg(t).join(`, `)})`}const hg=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`[^`]*`/g;function*gg(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 _g=`[A-Za-z_]\\w*(?:\\.[A-Za-z_]\\w*)*`,vg=RegExp(`^(?:(\\$)(?:\\.(${_g}))?|\\.(${_g})?)(?=[\\s)]|$)`);function yg(e,t,n){let r=vg.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 bg=/^(\w+)\b\s*([\s\S]*)$/;function*xg(e,t){let n=[t];for(let r of gg(e)){let e=r.replace(/^-(?=\s)/,``).trim(),[,i=``,a=``]=bg.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:yg(r[1],s,t);continue}yield{code:e,dot:o},i===`if`&&n.push(o),i===`with`&&n.push(yg(a,o,t)),(i===`range`||i===`define`||i===`block`)&&n.push(null)}}const Sg=/(?<![.$])\btemplate\s+$/;function*Cg(e,t,n){let r=0;for(let i of[...e.matchAll(hg)]){let a=i.index+i[0].length;Sg.test(e.slice(r,i.index))&&(yield{name:i[0].slice(1,-1),at:yg(e.slice(a),t,n)}),r=a}}function*wg(e,t){let n=new Set;function*r(e,i,a,o){for(let{code:s,dot:c}of[...xg(e,i)]){yield{code:s,dot:c,root:i,via:a};for(let e of[...Cg(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 Tg=RegExp(`(?<![A-Za-z0-9_)$])(\\$?)\\.(${_g})`,`g`);function*Eg({code:e,dot:t,root:n}){let r=e.replace(hg,``);for(let e of[...r.matchAll(Tg)]){let r=e[1]===`$`?n:t;r!==null&&(yield`${r}${e[2]}`)}}function Dg(e,t){let n=new Map;for(let r of wg(e,t))for(let e of Eg(r))n.has(e)||n.set(e,r.via);return n}const Og=/(?<![.$])\b(action|picker|menu|carousel|swatches|swatch|themePreview)\s+$/,kg={action:1,picker:2,menu:1,carousel:2,swatch:1,swatches:2,themePreview:1};function*Ag(e){let t=0,n=0,r=0,i=`action`;for(let a of[...e.matchAll(hg)]){let o=e.slice(t,a.index),s=Og.exec(o);if(s!==null)n=kg[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 jg(e,t){let n=new Map;for(let{code:r,via:i}of wg(e,t))for(let{name:e,site:t}of Ag(r)){let r=`${e}\0${i??`\0`}`;n.has(r)||n.set(r,{name:e,site:t,via:i})}return[...n.values()]}function Mg(e,t){return new Set([...Ng(e,t)].filter(e=>Object.hasOwn(t,e)))}function Ng(e,t){let n=new Set;for(let{code:r,dot:i,root:a}of wg(e,t))for(let{name:e}of Cg(r,i,a))n.add(e);return n}function Pg(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 Fg(e){let t=new Set,n=new Set,r=(e,r)=>{t.add(e),Ig(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 Ig(e){return e.kind===`dropped`||(e.kind===`shell`||e.kind===`file`)&&Eh(e.parse)===`json`}function Lg(e){let t=l.basename(e),n=l.dirname(e);for(;;){let r=Rg(n);if(r!==null)return{dir:r,name:t,leaf:n===l.dirname(e)};t=l.basename(n),n=l.dirname(n)}}function Rg(e){try{return r.statSync(e).isDirectory()?r.realpathSync(e):null}catch{return null}}var zg=ye((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()===Bt}function s(e){let t=e?.constructor;return!!t&&(t.name===`GeneratorFunction`||t.displayName===`GeneratorFunction`)}function c(e,t,n){It(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 Lt.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=Vt,n=Vt){let r=new Wt(e);return t!==Vt&&(r.onBOL=new Set([t])),n!==Vt&&(r.onBUOL=new Set([n])),r}function _(e,t){return At(e,t)}function v(e,t,n){return e===null||typeof e!=`object`&&typeof e!=`function`||tt(e)?e:Array.isArray(e)?sn.array(e,{name:n}):o(e)?sn.object(e,void 0,{name:n}):u(e)?sn.map(e,{name:n}):d(e)?sn.set(e,{name:n}):typeof e!=`function`||We(e)||Qe(e)?e:s(e)?Wn(e):In(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:We(n.value)?1:(It(r,t,ee(e,this,t,n,!1)),2)}function S(e,t,n,r){let i=ee(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 ye(s.i?.name??a.toString(),e,(t=s.i?.autoAction)!=null&&t)};return i==`field`?function(e){var t;let n=e;return We(n)||(n=c(n)),(t=s.i)!=null&&t.bound&&(n=n.bind(this),n.isMobxAction=!0),n}:i==`method`?(We(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 ee(e,t,n,r,i=P.safeDescriptors){var a,o,s;let{value:c}=r;return(a=t.i)!=null&&a.bound&&(c=c.bind(e.v??e.h)),{value:ye(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 te(e,t){return{t:e,i:t,o:ne,u:re}}function ne(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)||!Qe(e.h[t]))&&this.u(e,t,n,!1)===null?0:Qe(n.value)?1:(It(r,t,ae(e,0,0,n,!1,!1)),2)}function re(e,t,n,r){let i=ae(e,0,0,n,this.i?.bound);return e.l(t,i,r)}function ie(e,t,n){var r;let{name:i,addInitializer:a}=n;return Qe(t)||(t=Wn(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 ae(e,t,n,r,i,a=P.safeDescriptors){let{value:o}=r;return Qe(o)||(o=Wn(o)),i&&(o=o.bind(e.v??e.h),o.isMobXFlow=!0),{value:o,configurable:!a||e.p,enumerable:!1,writable:!a}}function w(e,t){return{t:e,i:t,o:T,u:oe}}function T(e,t,n){return this.u(e,t,n,!1)===null?0:1}function oe(e,t,n,r){return e.m(t,Ft({},this.i,{get:n.get,set:n.set}),r)}function E(e,t,n){function r(e){let n=Ft({},i.i,{get:t,context:e});return n.name||=`ObservableObject.${a.toString()}`,new yn(n)}let i=e,{name:a,addInitializer:o}=n,s;return o(function(){let e=Ct(this)[j],n=this,i=e.j.get(a);i instanceof yn&&i.derivation!==t&&e.j.delete(a),(e.O??=new Map).set(a,()=>r(n))}),function(){let e=this[j],n=e.j.get(a);if(n instanceof yn&&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 se(e,t){return{t:e,i:t,o:ce,u:le}}function ce(e,t,n){return this.u(e,t,n,!1)===null?0:1}function le(e,t,n,r){return e.S(t,n.value,this.i?.A??v,r)}function ue(e,t,n){function r(e,t){let n=Ct(e)[j];return(n.V??=new Map).set(o,()=>new _n(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[j]??r(this,t.get.call(this)))._(o)},set(e){return(this[j]??r(this,e)).M(o,e)},init(e){return r(this,e),e}}}function de(e){return{t:Jt,i:e,o:fe,u:pe}}function fe(e,t,n,r){var i,a,o;if(n.get)return dn.o(e,t,n,r);if(n.set){let i=We(n.set)?n.set:ye(t.toString(),n.set);return r===e.h?e.l(t,{configurable:!P.safeDescriptors||e.p,set:i})===null?0:2:(It(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?Gn:Wn).o(e,t,n,r):((a=this.i)!=null&&a.autoBind?Rn:In).o(e,t,n,r);let c=!1===this.i?.deep?nn:sn;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 pe(e,t,n,r){var i;return n.get?dn.u(e,t,n,r):n.set?e.l(t,{configurable:!P.safeDescriptors||e.p,set:ye(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?nn:sn).u(e,t,n,r))}function me(e,t){return Ft(function(n,r){if(r&&typeof r.kind==`string`)return t(e,n,r)},e)}function he(e){return e||Xt}function ge(e){return me(e,ue)}function _e(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 ve(e){return me(e,E)}function ye(e,t,n=!1,r){function i(){return be(0,n,t,r||this,arguments)}return i.isMobxAction=!0,i.toString=()=>t.toString(),hn&&(gn.value=e,It(i,`name`,gn)),i}function be(e,t,n,r,i){let a=xe(0,t);try{return n.apply(r,i)}catch(e){throw a.N=e,e}finally{D(a)}}function xe(e,t){let n=P.trackingDerivation,r=!t||!n;Pe();let i=P.allowStateChanges;r&&Oe();let a={R:r,k:n,C:i,I:P.allowStateReads,P:!1,T:0,B:mn++,D:pn};return pn=a.B,a}function D(e){pn!==e.B&&t(30),pn=e.D,e.N!==void 0&&(P.suppressReactionErrors=!0),Fe(),e.R&&ke(e.k),P.suppressReactionErrors=!1}function Se(e,t){let n=function(e){let t=P.allowStateChanges;return P.allowStateChanges=e,t}(e);try{return t()}finally{(function(e){P.allowStateChanges=e})(n)}}function Ce(e){return e instanceof bn}function we(e){switch(e.K){case 0:return!1;case-1:case 2:return!0;case 1:{let t=Oe(),n=e.L,r=n.length;for(let i=0;i<r;i++){let r=n[i];if(N(r)){if(P.disableErrorBoundaries)r.get();else try{r.get()}catch{return ke(t),!0}if(e.K===2)return ke(t),!0}}return Ae(e),ke(t),!1}}}function Te(e,t,n){Ae(e),e.$=Array(e.U===0?100:e.L.length),e.W=0,e.U=++P.runId;let r=P.trackingDerivation,i;if(P.trackingDerivation=e,P.inBatch++,!0===P.disableErrorBoundaries)i=t.call(n);else try{i=t.call(n)}catch(e){i=new bn(e)}return P.inBatch--,P.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&&Me(n,e),n.diffValue=0}for(;i--;){let t=n[i];t.diffValue===1&&(t.diffValue=0,je(t,e))}r!==0&&(e.K=r,e.q())}(e),i}function Ee(e){let t=e.L;e.L=[];let n=t.length;for(;n--;)Me(t[n],e);e.K=-1}function De(e){let t=Oe();try{return e()}finally{ke(t)}}function Oe(){let e=P.trackingDerivation;return P.trackingDerivation=null,e}function ke(e){P.trackingDerivation=e}function Ae(e){if(e.K===0)return;e.K=0;let t=e.L,n=t.length;for(;n--;)t[n].F=0}function je(e,t){(e.H??=new Set).add(t),e.F>t.K&&(e.F=t.K)}function Me(e,t){let n=e.H;n&&(n.delete(t),n.size===0&&Ne(e))}function Ne(e){!1===e.isPendingUnobservation&&(e.isPendingUnobservation=!0,P.pendingUnobservations.push(e))}function Pe(){P.inBatch++}function Fe(){--P.inBatch===0&&(ze(),!P.isRunningUnobservations&&P.pendingUnobservations.length>0&&function(){P.isRunningUnobservations=!0;try{let e=P.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 yn&&n.G())}P.pendingUnobservations=[]}finally{P.isRunningUnobservations=!1}}())}function Ie(e){var t;e.isBeingObserved||(e.isBeingObserved=!0,e.onBO(),(t=e.L)==null||t.forEach(Ie))}function Le(e){let t=P.trackingDerivation;return t===null?((!e.H||e.H.size===0)&&P.inBatch>0&&Ne(e),!1):(t.U!==e.J&&(e.J=t.U,t.$[t.W++]=e,!e.isBeingObserved&&P.trackingContext&&(e.isBeingObserved=!0,e.onBO())),e.isBeingObserved)}function Re(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 ze(){P.inBatch>0||P.isRunningReactions||Dn(Be)}function Be(){P.isRunningReactions=!0;let e=P.pendingReactions,t=0;for(;e.length>0;){++t===En&&(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()}P.isRunningReactions=!1}function Ve(e){return me(e,C)}function He(e){return function(t,n){return n&&typeof n.kind==`string`?C(e?Nn:jn,t,n):r(t)?ye(t.name||`<unnamed action>`,t,e):r(n)?ye(t,n,e):i(t)?Ve(b(e?An:kn,{name:t,autoAction:e})):void 0}}function Ue(e){return be(0,!1,e,this,void 0)}function We(e){return r(e)&&!0===e.isMobxAction}function Ge(e,t=zt){function n(){e(a)}var r;let i=t?.name??`Autorun`,a;if(t.scheduler||t.delay){let e=Ke(t),r=!1;a=new Tn(i,()=>{r||(r=!0,e(()=>{r=!1,a.isDisposed||a.track(n)}))},t.onError,t.requiresObservable)}else a=new Tn(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 Ke(e){return e.scheduler?e.scheduler:e.delay?t=>setTimeout(t,e.delay):zn}function qe(e,t,n,i){let a=typeof i==`function`?Et(t,n):Et(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 Je(e,t,n,r){let i=Ut(t);return kt(()=>{let t=Ct(e,r)[j];Ht(i).forEach(e=>{t.u(e,i[e],!n||!(e in n)||n[e])})}),e}function Ye(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(Ye)),t}function Xe(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),Xe)),t}function Ze(e){r(e.cancel)&&e.cancel()}function Qe(e){return!0===e?.isMobXFlow}function $e(e,t){var n;if(t===void 0)return N(e);if(!1===Tt(e))return!1;let r=e[j];return(n=r.O)!=null&&n.has(t)?!0:r.j.has(t)?N(Et(e,t)):!1}function et(e,t){if(!e)return!1;if(t!==void 0){if(Tt(e)){var n,r;let i=e[j];return i.j.has(t)||!((n=i.O)==null||!n.has(t))||!((r=i.V)==null||!r.has(t))}return!1}return Tt(e)||!!e[j]||Gt(e)||On(e)||N(e)}function tt(e){return et(e)}function nt(e){return Tt(e)?e[j].nt():rr(e)||or(e)?Array.from(e.keys()):bt(e)?e.map((e,t)=>t):void t(5)}function rt(e,n){return Tt(e)?e[j].et(n):rr(e)||or(e)?e.has(n):bt(e)?n>=0&&n<e.length:void t(10)}function it(e){if(Tt(e))return e[j].it();t(38)}function at(e,t,n){if(N(e)){let r,i=!0;return Ge(()=>{let a=e.get();if(!i||n){let n=Oe();t({observableKind:`computed`,debugObjectName:e.tt,type:Yn,object:e,newValue:a,oldValue:r}),ke(n)}i=!1,r=a})}return n&&t({observableKind:`value`,debugObjectName:e.tt,object:e,type:Yn,newValue:e.rt,oldValue:void 0}),mt(e,t)}function ot(e,t,n){return e.set(t,n),n}function st(e,t){if(typeof e!=`object`||!e||e instanceof Date||!tt(e))return e;if(vn(e)||N(e))return st(e.get(),t);if(t.has(e))return t.get(e);if(bt(e)){let n=ot(t,e,Array(e.length));return e.forEach((e,r)=>{n[r]=st(e,t)}),n}if(or(e)){let n=ot(t,e,new Set);return e.forEach(e=>{n.add(st(e,t))}),n}if(rr(e)){let n=ot(t,e,new Map);return e.forEach((e,r)=>{n.set(r,st(e,t))}),n}{let n=ot(t,e,{});return it(e).forEach(r=>{Lt.propertyIsEnumerable.call(e,r)&&(n[r]=st(e[r],t))}),n}}function ct(e,t){Pe();try{return e.apply(t)}finally{Fe()}}function lt(e,t,n){let r;if(typeof n.timeout==`number`){let e=Error(`WHEN_TIMEOUT`);r=setTimeout(()=>{if(!a[j].isDisposed){if(a(),!n.onError)throw e;n.onError(e)}},n.timeout)}n.name=`When`;let i=ye(`When-effect`,t);var a=Ge(t=>{Se(!1,e)&&(t.dispose(),r&&clearTimeout(r),i())},n);return a}function ut(e){return e[j]}function dt(e){return e.st!==void 0&&e.st.length>0}function ft(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 O(e,n){let r=Oe();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{ke(r)}}function pt(e){return e.ot!==void 0&&e.ot.length>0}function mt(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 ht(e,t){let n=Oe(),r=e.ot;if(r){r=r.slice();for(let e=0,n=r.length;e<n;e++)r[e](t);ke(n)}}function gt(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!==Lt;){let t=A(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 k(e,t){typeof Array.prototype[e]==`function`&&(Qn[e]=t(e))}function _t(e){return function(){let t=this[j];t.ct.reportObserved();let n=t.ht(t.j);return n[e].apply(n,arguments)}}function vt(e){return function(t,n){let r=this[j];return r.ct.reportObserved(),r.ht(r.j)[e]((e,r)=>t.call(n,e,r,this))}}function yt(e){return function(){let t=this[j];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 bt(e){return a(e)&&$n(e[j])}function xt(e){return e[Symbol.toStringTag]=`MapIterator`,Nt(e)}function St(e){return e[Symbol.toStringTag]=`SetIterator`,Nt(e)}function Ct(e,t){if(p(e,j))return e;let n=t?.name??`ObservableObject`;return c(e,j,new lr(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 M[r]??(M[r]=de({deep:t,autoBind:n}))}(e):void 0}(t))),e}function wt(e){return sr[e]||(sr[e]={get(){return this[j]._(e)},set(t){return this[j].M(e,t)}})}function Tt(e){return!!a(e)&&ur(e[j])}function Et(e,n){if(typeof e==`object`&&e){if(bt(e))return n!==void 0&&t(23),e[j].ct;if(or(e))return e.ct;if(rr(e)){if(n===void 0)return e.lt;let r=e.ft.get(n)||e.dt.get(n);return r||t(25,n,Ot(e)),r}if(Tt(e)){if(!n)return t(26);let r=e[j],i=r.j.get(n)??r.vt(n)??r.bt(n);return i||t(27,n,Ot(e)),i}if(Gt(e)||N(e)||On(e))return e}else if(r(e)&&On(e[j]))return e[j];t(28)}function Dt(e,n){return e||t(29),n===void 0?Gt(e)||N(e)||On(e)||rr(e)||or(e)?e:e[j]?e[j]:void t(24,e):Dt(Et(e,n))}function Ot(e,t){let n;if(t!==void 0)n=Et(e,t);else{if(We(e))return e.name;n=Tt(e)||rr(e)||or(e)?Dt(e):Et(e)}return n.tt}function kt(e){let t=Oe();Pe();try{return e()}finally{Fe(),ke(t)}}function At(e,t,n=-1){return jt(e,t,n)}function jt(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=dr.call(e);if(s!==dr.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=Mt(e),t=Mt(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(!jt(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)||!jt(e[o],t[o],n-1,i,a))return!1}}return i.pop(),a.pop(),!0}function Mt(e){return bt(e)?e.slice():u(e)||rr(e)||d(e)||or(e)?Array.from(e.entries()):e}function Nt(e){return e[Symbol.iterator]=Pt,Ft(Object.create(fr),e)}function Pt(){return this}Object.defineProperty(e,`__esModule`,{value:!0});let Ft=Object.assign,A=Object.getOwnPropertyDescriptor,It=Object.defineProperty,Lt=Object.prototype,Rt=[];Object.freeze(Rt);let zt={};Object.freeze(zt);let Bt=Object.toString(),Vt=()=>{},Ht=Reflect.ownKeys,Ut=Object.getOwnPropertyDescriptors,j=Symbol(`mobx administration`);var Wt=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 Le(this)}reportChanged(){Pe(),Re(this),Fe()}toString(){return this.tt}};let Gt=l(`Atom`,Wt),Kt=Object.is,qt={t:`override`,o:function(){return 0},u:function(){t(44,this.t)}},Jt=`true`,Yt=de(),M=[Yt],Xt={deep:!0,name:void 0,defaultDecorator:void 0};Object.freeze(Xt);let Zt=se(`observable`),Qt=se(`observable.ref`,{A:y}),$t=se(`observable.shallow`,{A:function(e,t,n){return e==null||Tt(e)||bt(e)||rr(e)||or(e)?e:Array.isArray(e)?sn.array(e,{name:n,deep:!1}):o(e)?sn.object(e,void 0,{name:n,deep:!1}):u(e)?sn.map(e,{name:n,deep:!1}):d(e)?sn.set(e,{name:n,deep:!1}):void 0}}),en=se(`observable.struct`,{A:function(e,t){return At(e,t)?t:e}}),tn={box(e,t){let n=he(t);return new _n(e,_e(n),n.name,!0,n.equals)},array(e,t){let n=he(t);return function(e,t,n=`ObservableArray`,r=!1){return kt(()=>{let i=new Zn(n,t,r);It(i.j,j,{enumerable:!1,writable:!1,configurable:!0,value:i});let a=new Proxy(i.j,Xn);return i.v=a,e&&e.length&&i.wt(0,0,e),a})}(e,_e(n),n.name)},map(e,t){let n=he(t);return new nr(e,_e(n),n.name)},set(e,t){let n=he(t);return new ar(e,_e(n),n.name)},object:(e,t,n)=>kt(()=>Je(function(e,t){var n;return(n=(e=Ct(e,t))[j]).v??(n.v=new Proxy(e,Kn))}({},n),e,t))},nn=ge(Qt),rn=ge($t),an=ge(Zt),on=ge(en);var sn=Ft(function(e,t,n){return t&&typeof t.kind==`string`?ue(Zt,e,t):tt(e)?e:o(e)?sn.object(e,t,n):Array.isArray(e)?sn.array(e,t):u(e)?sn.map(e,t):d(e)?sn.set(e,t):typeof e==`object`&&e?e:sn.box(e,t)},Zt,tn);let cn=`computed`,ln=w(cn),un=ve(w(`computed.struct`,{equals:_})),dn=function(e,t){if(t&&typeof t.kind==`string`)return E(ln,e,t);if(o(e))return ve(w(cn,e));let n=o(t)?t:{};return n.get=e,n.name||=e.name||``,new yn(n)};var fn;Ft(dn,ln);let pn=0,mn=1,hn=(fn=A(()=>{},`name`)?.configurable)!=null&&fn,gn={value:`action`,configurable:!0,writable:!1,enumerable:!1};var _n=class extends Wt{constructor(e,t,n=`ObservableValue`,r=!0,i=Kt){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))!==P.UNCHANGED&&this.Ot(e)}jt(e){if(dt(this)){let t=O(this,{object:this,type:Yn,newValue:e});if(!t)return P.UNCHANGED;e=t.newValue}return e=this.A(e,this.rt,this.tt),this.xt(this.rt,e)?P.UNCHANGED:e}Ot(e){let t=this.rt;this.rt=e,this.reportChanged(),pt(this)&&ht(this,{type:Yn,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 vn=l(`ObservableValue`,_n);var yn=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 bn(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=ye(`ComputedValue-setter`,e.set)),this.xt=e.equals||Kt,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),P.inBatch!==0||this.H&&this.H.size!==0||this.Mt){let e=this.isBeingObserved;if(Le(this),we(this)){let e=P.trackingContext;e||!this.Mt&&!this.isBeingObserved||(P.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),P.trackingContext=e}else !e&&this.isBeingObserved&&this.L.forEach(Ie)}else we(this)&&(this.Nt(),Pe(),this.rt=this.Rt(!1),Fe());let e=this.rt;if(Ce(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||Ce(e)||Ce(n)||!this.xt(e,n);return r&&(this.rt=n),r}Rt(e){let t;if(this.isComputing=!0,e)t=Te(this,this.derivation,this.At);else if(!0===P.disableErrorBoundaries)t=this.derivation.call(this.At);else try{t=this.derivation.call(this.At)}catch(e){t=new bn(e)}return this.isComputing=!1,t}G(){this.Mt||(Ee(this),this.rt=void 0)}Nt(){}toString(){return`${this.tt}[${this.derivation.toString()}]`}valueOf(){return f(this.get())}[Symbol.toPrimitive](){return this.valueOf()}};let N=l(`ComputedValue`,yn);var bn=class{constructor(e){this.cause=void 0,this.cause=e}};let xn=[`mobxGuid`,`spyListeners`,`enforceActions`,`computedRequiresReaction`,`reactionRequiresObservable`,`observableRequiresReaction`,`allowStateReads`,`disableErrorBoundaries`,`runId`,`UNCHANGED`];var Sn=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 Cn=!0,wn=!1,P=function(){let e=globalThis;return e.__mobxInstanceCount>0&&!e.__mobxGlobals&&(Cn=!1),e.__mobxGlobals&&e.__mobxGlobals.version!==7&&(Cn=!1),Cn?e.__mobxGlobals?(e.__mobxInstanceCount+=1,e.__mobxGlobals.UNCHANGED||(e.__mobxGlobals.UNCHANGED={}),e.__mobxGlobals):(e.__mobxInstanceCount=1,e.__mobxGlobals=new Sn):(setTimeout(()=>{wn||t(35)},1),new Sn)}();var Tn=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,P.pendingReactions.push(this),ze())}X(){if(!this.isDisposed){Pe(),this.isScheduled=!1;let e=P.trackingContext;if(P.trackingContext=this,we(this)){this.isTrackPending=!0;try{this.Et()}catch(e){this.Pt(e)}}P.trackingContext=e,Fe()}}track(e){if(this.isDisposed)return;Pe(),this.isRunning=!0;let t=P.trackingContext;P.trackingContext=this;let n=Te(this,e,void 0);P.trackingContext=t,this.isRunning=!1,this.isTrackPending=!1,this.isDisposed&&Ee(this),Ce(n)&&this.Pt(n.cause),Fe()}Pt(e){if(this.kt)this.kt(e,this);else{if(P.disableErrorBoundaries)throw e;P.suppressReactionErrors||console.error(`[mobx] uncaught error in '${this}'`,e),P.globalReactionErrorHandlers.forEach(t=>t(e,this))}}dispose(){var e;this.isDisposed||(this.isDisposed=!0,(e=this.It)==null||e.call(this),this.isRunning||(Pe(),Ee(this),Fe()))}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[j]=this,`dispose`in Symbol&&typeof Symbol.dispose==`symbol`&&(t[Symbol.dispose]=t),t}toString(){return`Reaction[${this.tt}]`}};let En=100,Dn=e=>e(),On=l(`Reaction`,Tn),kn=`action`,An=`autoAction`,jn=b(kn),Mn=b(`action.bound`,{bound:!0}),Nn=b(An,{autoAction:!0}),Pn=b(`autoAction.bound`,{autoAction:!0,bound:!0}),Fn=He(!1);Ft(Fn,jn);let In=He(!0);Ft(In,Nn);let Ln=Ve(Mn),Rn=Ve(Pn),zn=e=>e(),Bn=`always`;var Vn=class extends Error{constructor(){super(`FLOW_CANCELLED`),Object.setPrototypeOf(this,new.target.prototype),this.name=`FlowCancellationError`}toString(){return`Error: ${this.message}`}};let Hn=te(`flow`),Un=te(`flow.bound`,{bound:!0}),Wn=Ft(function(e,t){if(t&&typeof t.kind==`string`)return ie(Hn,e,t);let n=e,i=n.name||`flow`,a=function(){let e=arguments,t=Fn(i,n).apply(this,e),a,o,s=new Promise(function(e,n){function s(e){let r;o=void 0;try{r=Fn(i,t.next).call(t,e)}catch(e){return n(e)}l(r)}function c(e){let r;o=void 0;try{r=Fn(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=Fn(i,function(){try{o&&Ze(o);let e=t.return(void 0),n=Promise.resolve(e.value);n.then(Vt,Vt),Ze(n),a(new Vn)}catch(e){a(e)}}),s};return a.isMobXFlow=!0,a},Hn),Gn=me(Un,ie),Kn={has:(e,t)=>ut(e).et(t),get:(e,t)=>ut(e).Tt(t),set(e,t,n){var r;return!!i(t)&&((r=ut(e).Bt(t,n,!0))==null||r)},deleteProperty(e,t){var n;return!!i(t)&&((n=ut(e).Dt(t,!0))==null||n)},defineProperty(e,t,n){var r;return(r=ut(e).l(t,n))==null||r},ownKeys:e=>ut(e).it(),preventExtensions(e){t(13)}},qn=Symbol(`mobx-keys`),Jn=`splice`,Yn=`update`,Xn={get(e,t){let n=e[j];return t===j?n:t===`length`?n.Kt():typeof t!=`string`||isNaN(t)?p(Qn,t)?Qn[t]:e[t]:n.Tt(parseInt(t))},set(e,t,n){let r=e[j];return t===`length`?r.Lt(n):typeof t==`symbol`||isNaN(t)?e[t]=n:r.Bt(parseInt(t),n),!0},preventExtensions(){t(15)}};var Zn=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 Wt(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=Rt),dt(this)){let r=O(this,{object:this.v,type:Jn,index:e,removedCount:t,added:n});if(!r)return Rt;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=pt(this),i=r?{observableKind:`array`,object:this.v,type:Yn,debugObjectName:this.ct.tt,index:e,newValue:t,oldValue:n}:null;this.ct.reportChanged(),r&&ht(this,i)}Ft(e,t,n){let r=pt(this),i=r?{observableKind:`array`,object:this.v,debugObjectName:this.ct.tt,type:Jn,index:e,removed:n,added:t,removedCount:n.length,addedCount:t.length}:null;this.ct.reportChanged(),r&&ht(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(dt(this)){let n=O(this,{type:Yn,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)}}},Qn={clear(){return this.splice(0)},replace(e){let t=this[j];return t.wt(0,t.j.length,e)},toJSON(){return this.slice()},splice(e,t,...n){let r=this[j];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[j].wt(e,t,n)},push(...e){let t=this[j];return t.wt(t.j.length,0,e),t.j.length},pop(){return this.splice(Math.max(this[j].j.length-1,0),1)[0]},shift(){return this.splice(0,1)[0]},unshift(...e){let t=this[j];return t.wt(0,0,e),t.j.length},reverse(){return P.trackingDerivation&&t(37,`reverse`),this.replace(this.slice().reverse()),this},sort(){P.trackingDerivation&&t(37,`sort`);let e=this.slice();return e.sort.apply(e,arguments),this.replace(e),this},remove(e){let t=this[j],n=t.ht(t.j).indexOf(e);return n>-1&&(this.splice(n,1),!0)}};k(`at`,_t),k(`concat`,_t),k(`flat`,_t),k(`includes`,_t),k(`indexOf`,_t),k(`join`,_t),k(`lastIndexOf`,_t),k(`slice`,_t),k(`toString`,_t),k(`toLocaleString`,_t),k(`toSorted`,_t),k(`toSpliced`,_t),k(`with`,_t),k(`every`,vt),k(`filter`,vt),k(`find`,vt),k(`findIndex`,vt),k(`findLast`,vt),k(`findLastIndex`,vt),k(`flatMap`,vt),k(`forEach`,vt),k(`map`,vt),k(`some`,vt),k(`toReversed`,vt),k(`reduce`,yt),k(`reduceRight`,yt);let $n=l(`ObservableArrayAdministration`,Zn),er={},tr=`delete`;var nr=class{constructor(e,t=v,n=`ObservableMap`){this.A=void 0,this.tt=void 0,this[j]=er,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,kt(()=>{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(!P.trackingDerivation)return this.et(e);let t=this.dt.get(e);if(!t){let n=t=new _n(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(dt(this)){let r=O(this,{type:n?Yn:`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(dt(this)&&!O(this,{type:tr,object:this,name:e}))return!1;if(this.et(e)){let t=pt(this),n=t?{observableKind:`map`,debugObjectName:this.tt,type:tr,object:this,oldValue:this.ft.get(e).rt,name:e}:null;return ct(()=>{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&&ht(this,n),!0}return!1}Gt(e,t){let n=this.ft.get(e);if((t=n.jt(t))!==P.UNCHANGED){let r=pt(this),i=r?{observableKind:`map`,debugObjectName:this.tt,type:Yn,object:this,oldValue:n.rt,name:e,newValue:t}:null;n.Ot(t),r&&ht(this,i)}}Jt(e,t){ct(()=>{var n;let r=new _n(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=pt(this);n&&ht(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 xt({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 xt({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 rr(e)&&(e=new Map(e)),ct(()=>{o(e)?function(e){let t=Object.keys(e),n=Object.getOwnPropertySymbols(e);return n.length?[...t,...n.filter(t=>Lt.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(){ct(()=>{De(()=>{for(let e of this.keys())this.delete(e)})})}replace(e){return ct(()=>{let n=function(e){if(u(e)||rr(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`}},rr=l(`ObservableMap`,nr);let ir={};var ar=class{constructor(e,t=v,n=`ObservableSet`){this.tt=void 0,this[j]=ir,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),kt(()=>{this.ct=g(this.tt),e&&this.replace(e)})}Wt(e){return this.dehancer===void 0?e:this.dehancer(e)}clear(){ct(()=>{De(()=>{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(dt(this)){let t=O(this,{type:`add`,object:this,newValue:e});if(!t)return this;e=t.newValue}if(!this.has(e)){ct(()=>{e=this.A(e,void 0),this.ft.add(e),this.ct.reportChanged()});let t=pt(this);t&&ht(this,t?{observableKind:`set`,debugObjectName:this.tt,type:`add`,object:this,newValue:e}:null)}return this}delete(e){if(dt(this)&&!O(this,{type:tr,object:this,oldValue:e}))return!1;if(this.has(e)){let t=pt(this),n=t?{observableKind:`set`,debugObjectName:this.tt,type:tr,object:this,oldValue:e}:null;return ct(()=>{this.ct.reportChanged(),this.ft.delete(e)}),t&&ht(this,n),!0}return!1}has(e){return this.ct.reportObserved(),this.ft.has(this.Wt(e))}entries(){let e=this.values();return St({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 St({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 or(e)&&(e=new Set(e)),Array.isArray(e)||d(e)?ct(()=>{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`}},or=l(`ObservableSet`,ar);let sr=Object.create(null),cr=`remove`;var lr=class{constructor(e,t=new Map,n,r=Yt){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 Wt(`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 yn)return n.set(t),!0;if(dt(this)){let n=O(this,{type:Yn,object:this.v||this.h,name:e,newValue:t});if(!n)return null;t=n.newValue}if((t=n.jt(t))!==P.UNCHANGED){let r=pt(this),i=r?{type:Yn,observableKind:`object`,debugObjectName:this.tt,object:this.v||this.h,oldValue:n.rt,name:e,newValue:t}:null;n.Ot(t),r&&ht(this,i)}return!0}Tt(e){return P.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(!P.trackingDerivation)return e in this.h;this.Qt||=new Map;let t=this.Qt.get(e);return t||(t=new _n(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{Pe();let r=this.Dt(e);if(!r)return r;if(dt(this)){let n=O(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=Ft({},t,{value:r}))}if(n){if(!Reflect.defineProperty(this.h,e,t))return!1}else It(this.h,e,t);this.Yt(e,t.value)}finally{Fe()}return!0}S(e,t,n,r=!1){try{Pe();let i=this.Dt(e);if(!i)return i;if(dt(this)){let n=O(this,{object:this.v||this.h,name:e,type:`add`,newValue:t});if(!n)return null;t=n.newValue}let a=wt(e),o={configurable:!P.safeDescriptors||this.p,enumerable:!0,get:a.get,set:a.set};if(r){if(!Reflect.defineProperty(this.h,e,o))return!1}else It(this.h,e,o);let s=new _n(t,n,`ObservableObject.key`,!1);this.j.set(e,s),this.Yt(e,s.rt)}finally{Fe()}return!0}m(e,t,n=!1){try{Pe();let r=this.Dt(e);if(!r)return r;if(dt(this)&&!O(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=wt(e),a={configurable:!P.safeDescriptors||this.p,enumerable:!1,get:i.get,set:i.set};if(n){if(!Reflect.defineProperty(this.h,e,a))return!1}else It(this.h,e,a);this.j.set(e,new yn(t)),this.Yt(e,void 0)}finally{Fe()}return!0}Dt(e,t=!1){if(!p(this.h,e))return!0;if(dt(this)&&!O(this,{object:this.v||this.h,name:e,type:cr}))return null;try{var n;Pe();let r=pt(this),i=this.j.get(e),a;if(i||!r||(a=A(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 _n&&(a=i.rt),Re(i)),this.lt.reportChanged(),(n=this.Qt)==null||(n=n.get(e))==null||n.set(e in this.h),r&&r&&ht(this,{type:cr,observableKind:`object`,object:this.v||this.h,debugObjectName:this.tt,oldValue:a,name:e})}finally{Fe()}return!0}Yt(e,t){var n;let r=pt(this);r&&r&&ht(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(),Ht(this.h)}nt(){return this.lt.reportObserved(),Object.keys(this.h)}};let ur=l(`ObservableObjectAdministration`,lr),dr=Lt.toString,fr=globalThis.Iterator?.prototype||{};e.$mobx=j,e.FlowCancellationError=Vn,e.ObservableMap=nr,e.ObservableSet=ar,e.Reaction=Tn,e._allowStateChanges=Se,e._allowStateChangesInsideComputed=Ue,e._allowStateReadsEnd=function(e){P.allowStateReads=e},e._allowStateReadsStart=function(e){let t=P.allowStateReads;return P.allowStateReads=e,t},e._autoAction=In,e._autoActionBound=Rn,e._endAction=D,e._getAdministration=Dt,e._getGlobalState=function(){return P},e._interceptReads=function(e,t,n){let r;return rr(e)||bt(e)||vn(e)?r=Dt(e):Tt(e)&&(r=Dt(e,t)),r.dehancer=typeof t==`function`?t:n,()=>{r.dehancer=void 0}},e._isComputingDerivation=function(){return P.trackingDerivation!==null},e._resetGlobalState=function(){let e=new Sn;for(let t in e)xn.indexOf(t)===-1&&(P[t]=e[t]);P.allowStateChanges=!P.enforceActions},e._startAction=xe,e.action=Fn,e.actionBound=Ln,e.autorun=Ge,e.compareDefault=Kt,e.compareIdentity=function(e,t){return e===t},e.compareShallow=function(e,t){return At(e,t,1)},e.compareStructural=_,e.computed=dn,e.computedStruct=un,e.configure=function(e){!0===e.isolateGlobalState&&function(){if((P.pendingReactions.length||P.inBatch||P.isRunningReactions)&&t(36),wn=!0,Cn){let e=globalThis;--e.__mobxInstanceCount===0&&(e.__mobxGlobals=void 0),P=new Sn}}();let{enforceActions:n}=e;if(n!==void 0){let e=n===Bn?Bn:n===`observed`;P.enforceActions=e,P.allowStateChanges=!0!==e&&e!==Bn}[`computedRequiresReaction`,`reactionRequiresObservable`,`observableRequiresReaction`,`disableErrorBoundaries`,`safeDescriptors`].forEach(t=>{t in e&&(P[t]=!!e[t])}),P.allowStateReads=!P.observableRequiresReaction,e.reactionScheduler&&function(e){let t=Dn;Dn=n=>e(()=>t(n))}(e.reactionScheduler)},e.createAtom=g,e.defineProperty=function(e,n,r){if(Tt(e))return e[j].l(n,r);t(39)},e.entries=function(e){return Tt(e)?nt(e).map(t=>[t,e[t]]):rr(e)?nt(e).map(t=>[t,e.get(t)]):or(e)?Array.from(e.entries()):bt(e)?e.map((e,t)=>[t,e]):void t(7)},e.extendObservable=Je,e.flow=Wn,e.flowBound=Gn,e.flowResult=function(e){return e},e.get=function(e,n){if(rt(e,n))return Tt(e)?e[j].Tt(n):rr(e)?e.get(n):bt(e)?e[n]:void t(11)},e.getAtom=Et,e.getDebugName=Ot,e.getDependencyTree=function(e,t){return Ye(Et(e,t))},e.getObserverTree=function(e,t){return Xe(Et(e,t))},e.has=rt,e.intercept=function(e,t,n){return r(n)?function(e,t,n){return ft(Dt(e,t),n)}(e,t,n):function(e,t){return ft(Dt(e),t)}(e,t)},e.isAction=We,e.isBoxedObservable=vn,e.isComputed=function(e){return $e(e)},e.isComputedProp=function(e,t){return $e(e,t)},e.isFlow=Qe,e.isFlowCancellationError=function(e){return e instanceof Vn},e.isObservable=tt,e.isObservableArray=bt,e.isObservableMap=rr,e.isObservableObject=Tt,e.isObservableProp=function(e,t){return et(e,t)},e.isObservableSet=or,e.keys=nt,e.makeAutoObservable=function(e,t,n){return o(e)?Je(e,e,t,n):(kt(()=>{let r=Ct(e,n)[j];if(!e[qn]){let t=Object.getPrototypeOf(e),n=new Set([...Ht(e),...Ht(t)]);n.delete(`constructor`),n.delete(j),c(t,qn,n)}e[qn].forEach(e=>gt(r,e,!t||!(e in t)||t[e]))}),e)},e.makeObservable=function(e,t,n){return kt(()=>{let r=Ct(e,n)[j];Ht(t).forEach(e=>gt(r,e,t[e]))}),e},e.observable=sn,e.observableDeep=an,e.observableRef=nn,e.observableShallow=rn,e.observableStruct=on,e.observe=function(e,t,n,i){return r(n)?function(e,t,n,r){return at(Dt(e,t),n,r)}(e,t,n,i):function(e,t,n){let r=Dt(e);if(bt(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(!rr(e)&&!or(e)&&!Tt(e))return at(r,t,n);return mt(r,t)}(e,t,n)},e.onBecomeObserved=function(e,t,n){return qe(`onBO`,e,t,n)},e.onBecomeUnobserved=function(e,t,n){return qe(`onBUO`,e,t,n)},e.onReactionError=function(e){return P.globalReactionErrorHandlers.push(e),()=>{let t=P.globalReactionErrorHandlers.indexOf(e);t>=0&&P.globalReactionErrorHandlers.splice(t,1)}},e.override=qt,e.ownKeys=it,e.reaction=function(e,t,n=zt){function r(){if(p=!1,h.isDisposed)return;let t=!1,r=d;h.track(()=>{let n=Se(!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=Fn(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=Ke(n),d,f=!0,p=!1,m=n.equals||Kt,h=new Tn(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){Tt(e)?e[j].Dt(n):rr(e)||or(e)?e.delete(n):bt(e)?(typeof n!=`number`&&(n=parseInt(n,10)),e.splice(n,1)):t(9)},e.runInAction=Ue,e.set=function e(n,r,i){if(arguments.length===2&&!or(n)){Pe();let t=r;try{for(let r in t)e(n,r,t[r])}finally{Fe()}return}Tt(n)?n[j].Bt(r,i):rr(n)?n.set(r,i):or(n)?n.add(r):bt(n)?(typeof r!=`number`&&(r=parseInt(r,10)),r<0&&t(42,r),Pe(),r>=n.length&&(n.length=r+1),n[r]=i,Fe()):t(8)},e.spy=function(){return console.warn(`[mobx.spy] Is a no-op in production builds`),function(){}},e.toJS=function(e){return st(e,new Map)},e.transaction=ct,e.untracked=De,e.values=function(e){return Tt(e)?nt(e).map(t=>e[t]):rr(e)?nt(e).map(t=>e.get(t)):or(e)?Array.from(e.values()):bt(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 Ft(Promise.reject(Error(`WHEN_ABORTED`)),{cancel:()=>null});let r,i,a=new Promise((n,a)=>{var o;let s=lt(e,n,Ft({},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):lt(e,t,n||{})}})),Bg=ye((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++M.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=ie(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 ee(e){let t=Object.keys(e),n=Object.getOwnPropertySymbols(e);return n.length?[...t,...n.filter(t=>o.propertyIsEnumerable.call(e,t))]:t}let te=Reflect.ownKeys;function ne(e){return typeof e==`string`?e:typeof e==`symbol`?e.toString():new String(e).toString()}function re(e){return e===null?null:typeof e==`object`?``+e:e}function ie(e,t){return o.hasOwnProperty.call(e,t)}let ae=Object.getOwnPropertyDescriptors;function w(e,t){return!!(e&t)}function T(e,t,n){return n?e|=t:e&=~t,e}function oe(e,t){t.includes(e.kind)||n(`The decorator applied to '${String(e.name)}' cannot be used on a ${e.kind} element`)}let E=Symbol(`mobx administration`);var se=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 w(this.flags_,1)}set isBeingObserved(e){this.flags_=T(this.flags_,1,e)}get isPendingUnobservation(){return w(this.flags_,2)}set isPendingUnobservation(e){this.flags_=T(this.flags_,2,e)}get diffValue(){return+!!w(this.flags_,4)}set diffValue(e){this.flags_=T(this.flags_,4,e===1)}onBO(){this.onBOL&&this.onBOL.forEach(e=>e())}onBUO(){this.onBUOL&&this.onBUOL.forEach(e=>e())}reportObserved(){return ln(this)}reportChanged(){an(),un(this),on()}toString(){return this.name_}};let ce=b(`Atom`,se);function le(e,t=f,n=f){let r=new se(e);return t!==f&&(r.onBOL=new Set([t])),n!==f&&(r.onBUOL=new Set([n])),r}function ue(e,t){return e===t}function de(e,t){return Pi(e,t)}function fe(e,t){return Pi(e,t,1)}let pe=Object.is;function me(e,t,n){return e===null||typeof e!=`object`&&typeof e!=`function`||br(e)?e:Array.isArray(e)?O.array(e,{name:n}):g(e)?O.object(e,void 0,{name:n}):x(e)?O.map(e,{name:n}):C(e)?O.set(e,{name:n}):typeof e==`function`&&!Rn(e)&&!dr(e)?_(e)?sr(e):Pn(n,e):e}function he(e,t,r){if(e==null||Ei(e)||fi(e)||F(e)||vi(e))return e;if(Array.isArray(e))return O.array(e,{name:r,deep:!1});if(g(e))return O.object(e,void 0,{name:r,deep:!1});if(x(e))return O.map(e,{name:r,deep:!1});if(C(e))return O.set(e,{name:r,deep:!1});n(`The shallow modifier / decorator can only used in combination with arrays, objects, maps and sets`)}function ge(e){return e}function _e(e,t){return br(e)&&n(`observable.struct should not be used with observable values`),Pi(e,t)?t:e}let ve=`override`,ye={annotationType_:ve,make_:xe,extend_:D};function be(e){return e.annotationType_===ve}function xe(e,t){return e.isPlainObject_&&n(`Cannot apply '${this.annotationType_}' to '${e.name_}.${t.toString()}':\n'${this.annotationType_}' cannot be used on plain objects.`),ie(e.appliedAnnotations_,t)||n(`'${e.name_}.${t.toString()}' is annotated with '${this.annotationType_}', but no such annotated member was found on prototype.`),0}function D(e,t,r,i){n(44,this.annotationType_)}function Se(e,t){return{annotationType_:e,options_:t,make_:Ce,extend_:we}}function Ce(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:Rn(n.value)?1:(a(r,t,De(e,this,t,n,!1)),2)}function we(e,t,n,r){let i=De(e,this,t,n);return e.defineProperty_(t,i,r)}function Te(e,t,r){oe(r,[`method`,`field`]);let{kind:i,name:a,addInitializer:o}=r,s=e,c=e=>xt(s.options_?.name??a.toString(),e,s.options_?.autoAction??!1);if(i==`field`)return function(e){var t;let n=e;return Rn(n)||(n=c(n)),(t=s.options_)!=null&&t.bound&&(n=n.bind(this),n.isMobxAction=!0),n};if(i==`method`){var l;return Rn(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 Ee(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 De(e,t,n,r,i=M.safeDescriptors){var a,o;Ee(e,t,n,r);let{value:s}=r;return(a=t.options_)!=null&&a.bound&&(s=s.bind(e.proxy_??e.target_)),{value:xt(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 Oe(e,t){return{annotationType_:e,options_:t,make_:ke,extend_:Ae}}function ke(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&&(!ie(e.target_,t)||!dr(e.target_[t]))&&this.extend_(e,t,n,!1)===null?0:dr(n.value)?1:(a(r,t,Ne(e,this,t,n,!1,!1)),2)}function Ae(e,t,n,r){let i=Ne(e,this,t,n,this.options_?.bound);return e.defineProperty_(t,i,r)}function je(e,t,n){var r;oe(n,[`method`]);let{name:i,addInitializer:a}=n;return dr(t)||(t=sr(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 Me(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 Ne(e,t,n,r,i,a=M.safeDescriptors){Me(e,t,n,r);let{value:o}=r;return dr(o)||(o=sr(o)),i&&(o=o.bind(e.proxy_??e.target_),o.isMobXFlow=!0),{value:o,configurable:a?e.isPlainObject_:!0,enumerable:!1,writable:!a}}function Pe(e,t){return{annotationType_:e,options_:t,make_:Fe,extend_:Ie}}function Fe(e,t,n){return this.extend_(e,t,n,!1)===null?0:1}function Ie(e,t,n,i){return Re(e,this,t,n),e.defineComputedProperty_(t,r({},this.options_,{get:n.get,set:n.set}),i)}function Le(e,t,n){oe(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 At(o)}return o(function(){let e=Ci(this)[E],n=this,r=e.values_.get(a);r instanceof At&&r.derivation!==t&&e.values_.delete(a),(e.lazyComputedKeys_??=new Map).set(a,()=>c(n,e))}),function(){let e=this[E],n=e.values_.get(a);if(n instanceof At&&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 Re(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 ze(e,t){return{annotationType_:e,options_:t,make_:Be,extend_:Ve}}function Be(e,t,n){return this.extend_(e,t,n,!1)===null?0:1}function Ve(e,t,n,r){return Ue(e,this,t,n),e.defineObservableProperty_(t,n.value,this.options_?.enhancer_??me,r)}function He(e,t,r){if(r.kind===`field`)throw n(`Please use \`@observable accessor ${String(r.name)}\` instead of \`@observable ${String(r.name)}\``);oe(r,[`accessor`]);let i=e,{kind:a,name:o}=r;if(a!==`accessor`)return;function s(e,t){let n=Ci(e)[E];return(n.lazyObservableKeys_??=new Map).set(o,()=>new Ot(t,i.options_?.enhancer_??me,`${n.name_}.${o.toString()}`,!1)),n}return{get(){return(this[E]??s(this,t.get.call(this))).getObservablePropValue_(o)},set(e){return(this[E]??s(this,e)).setObservablePropValue_(o,e)},init(e){return s(this,e),e}}}function Ue(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 We=Ge();function Ge(e){return{annotationType_:`true`,options_:e,make_:Je,extend_:Ye}}let Ke=[We];function qe(e){let t=e.deep!==!1,n=!!e.autoBind,r=!t|(n?2:0);return Ke[r]??(Ke[r]=Ge({deep:t,autoBind:n}))}function Je(e,t,n,r){var i;if(n.get)return k.make_(e,t,n,r);if(n.set){let i=Rn(n.set)?n.set:xt(t.toString(),n.set);return r===e.target_?e.defineProperty_(t,{configurable:M.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?cr:sr).make_(e,t,n,r)}return((o=this.options_)!=null&&o.autoBind?In:Pn).make_(e,t,n,r)}let c=this.options_?.deep===!1?lt:O;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 Ye(e,t,n,r){var i;return n.get?k.extend_(e,t,n,r):n.set?e.defineProperty_(t,{configurable:M.safeDescriptors?e.isPlainObject_:!0,set:xt(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?lt:O).extend_(e,t,n,r))}function Xe(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 Ze={deep:!0,name:void 0,defaultDecorator:void 0};Object.freeze(Ze);function Qe(e){return e||Ze}let $e=ze(`observable`),et=ze(`observable.ref`,{enhancer_:ge}),tt=ze(`observable.shallow`,{enhancer_:he}),nt=ze(`observable.struct`,{enhancer_:_e});function rt(e){return Xe(e,He)}function it(e){return e.deep===!0?me:e.deep===!1?ge:ot(e.defaultDecorator)}function at(e){return e?e.defaultDecorator??qe(e):void 0}function ot(e){return e?e.options_?.enhancer_??me:me}function st(e,t,n){return t&&typeof t.kind==`string`?He($e,e,t):br(e)?e:g(e)?O.object(e,t,n):Array.isArray(e)?O.array(e,t):x(e)?O.map(e,t):C(e)?O.set(e,t):typeof e==`object`&&e?e:O.box(e,t)}let ct={box(e,t){let n=Qe(t);return new Ot(e,it(n),n.name,!0,n.equals)},array(e,t){let n=Qe(t);return ai(e,it(n),n.name)},map(e,t){let n=Qe(t);return new hi(e,it(n),n.name)},set(e,t){let n=Qe(t);return new _i(e,it(n),n.name)},object(e,t,n){return Mi(()=>Yn(Wr({},n),e,t))}},lt=rt(et),ut=rt(tt),dt=rt($e),ft=rt(nt);var O=r(st,$e,ct);let pt=`computed`;function mt(e){return Xe(e,Le)}let ht=Pe(pt),gt=mt(Pe(`computed.struct`,{equals:de})),k=function(e,t){if(t&&typeof t.kind==`string`)return Le(ht,e,t);if(g(e))return mt(Pe(pt,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 At(r)};r(k,ht);let _t=0,vt=1,yt=i(()=>{},`name`)?.configurable??!1,bt={value:`action`,configurable:!0,writable:!1,enumerable:!1};function xt(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 St(e,r,t,i||this,arguments)}return o.isMobxAction=!0,o.toString=()=>t.toString(),yt&&(bt.value=e,a(o,`name`,bt)),o}function St(e,t,n,r,i){let a=Ct(e,t,r,i);try{return n.apply(r,i)}catch(e){throw a.error_=e,e}finally{wt(a)}}function Ct(e,t,n,r){let i=N()&&!!e,a=0;i&&(a=Date.now(),xn({type:P,name:e,object:n,arguments:r?Array.from(r):s}));let o=M.trackingDerivation,c=!t||!o;an();let l=M.allowStateChanges;c&&(Ht(),l=Et(!0));let u=M.allowStateReads;j(!0);let d={runAsAction_:c,prevDerivation_:o,prevAllowStateChanges_:l,prevAllowStateReads_:u,notifySpy_:i,startTime_:a,actionId_:vt++,parentActionId_:_t};return _t=d.actionId_,d}function wt(e){_t!==e.actionId_&&n(30),_t=e.parentActionId_,e.error_!==void 0&&(M.suppressReactionErrors=!0),Dt(e.prevAllowStateChanges_),Wt(e.prevAllowStateReads_),on(),e.runAsAction_&&Ut(e.prevDerivation_),e.notifySpy_&&Cn({time:Date.now()-e.startTime_}),M.suppressReactionErrors=!1}function Tt(e,t){let n=Et(e);try{return t()}finally{Dt(n)}}function Et(e){let t=M.allowStateChanges;return M.allowStateChanges=e,t}function Dt(e){M.allowStateChanges=e}var Ot=class extends se{constructor(e,t,n=`ObservableValue@`+u(),r=!0,i=pe){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&&N()&&bn({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!==M.UNCHANGED){let n=N();n&&xn({type:ni,object:this,observableKind:`value`,debugObjectName:this.name_,newValue:e,oldValue:t}),this.setNewValue_(e),n&&Cn()}}prepareNewValue_(e){if(A(this),Gr(this)){let t=qr(this,{object:this,type:ni,newValue:e});if(!t)return M.UNCHANGED;e=t.newValue}return e=this.enhancer_(e,this.value_,this.name_),this.equals_(this.value_,e)?M.UNCHANGED:e}setNewValue_(e){let t=this.value_;this.value_=e,this.reportChanged(),Jr(this)&&Xr(this,{type:ni,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 re(this.get())}[Symbol.toPrimitive](){return this.valueOf()}};let kt=b(`ObservableValue`,Ot);var At=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 Mt(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_=xt(this.name_+`-setter`,e.set)),this.equals_=e.equals||pe,this.scope_=e.context,this.requiresReaction_=e.requiresReaction,this.keepAlive_=!!e.keepAlive}onBecomeStale_(){fn(this)}onBO(){this.onBOL&&this.onBOL.forEach(e=>e())}onBUO(){this.onBUOL&&this.onBUOL.forEach(e=>e())}get isComputing(){return w(this.flags_,1)}set isComputing(e){this.flags_=T(this.flags_,1,e)}get isRunningSetter(){return w(this.flags_,2)}set isRunningSetter(e){this.flags_=T(this.flags_,2,e)}get isBeingObserved(){return w(this.flags_,4)}set isBeingObserved(e){this.flags_=T(this.flags_,4,e)}get isPendingUnobservation(){return w(this.flags_,8)}set isPendingUnobservation(e){this.flags_=T(this.flags_,8,e)}get diffValue(){return+!!w(this.flags_,16)}set diffValue(e){this.flags_=T(this.flags_,16,e===1)}get(){if(this.isComputing&&n(32,this.name_,this.derivation),M.inBatch===0&&(!this.observers_||this.observers_.size===0)&&!this.keepAlive_)Pt(this)&&(this.warnAboutUntrackedRead_(),an(),this.value_=this.computeValue_(!1),on());else{let e=this.isBeingObserved;if(ln(this),Pt(this)){let e=M.trackingContext;!e&&(this.keepAlive_||this.isBeingObserved)&&(M.trackingContext=this),this.trackAndCompute()&&dn(this),M.trackingContext=e}else !e&&this.isBeingObserved&&this.observing_.forEach(cn)}let e=this.value_;if(Nt(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||Nt(e)||Nt(n)||!this.equals_(e,n);return r&&(this.value_=n,N()&&bn({observableKind:`computed`,debugObjectName:this.name_,object:this.scope_,type:`update`,oldValue:e,newValue:n})),r}computeValue_(e){this.isComputing=!0;let t=Et(!1),n;if(e)n=Lt(this,this.derivation,this.scope_);else if(M.disableErrorBoundaries===!0)n=this.derivation.call(this.scope_);else try{n=this.derivation.call(this.scope_)}catch(e){n=new Mt(e)}return Dt(t),this.isComputing=!1,n}suspend_(){this.keepAlive_||(Bt(this),this.value_=void 0)}warnAboutUntrackedRead_(){(typeof this.requiresReaction_==`boolean`?this.requiresReaction_:M.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 re(this.get())}[Symbol.toPrimitive](){return this.valueOf()}};let jt=b(`ComputedValue`,At);var Mt=class{constructor(e){this.cause=void 0,this.cause=e}};function Nt(e){return e instanceof Mt}function Pt(e){switch(e.dependenciesState_){case 0:return!1;case-1:case 2:return!0;case 1:{let t=j(!0),n=Ht(),r=e.observing_,i=r.length;for(let a=0;a<i;a++){let i=r[a];if(jt(i)){if(M.disableErrorBoundaries)i.get();else try{i.get()}catch{return Ut(n),Wt(t),!0}if(e.dependenciesState_===2)return Ut(n),Wt(t),!0}}return Gt(e),Ut(n),Wt(t),!1}}}function Ft(){return M.trackingDerivation!==null}function A(e){let t=!!e.observers_&&e.observers_.size>0;!M.allowStateChanges&&(t||M.enforceActions===`always`)&&console.warn(`[MobX] `+(M.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 It(e){!M.allowStateReads&&M.observableRequiresReaction&&console.warn(`[mobx] Observable '${e.name_}' being read outside a reactive context.`)}function Lt(e,t,n){let r=j(!0);Gt(e),e.newObserving_=Array(e.runId_===0?100:e.observing_.length),e.unboundDepsCount_=0,e.runId_=++M.runId;let i=M.trackingDerivation;M.trackingDerivation=e,M.inBatch++;let a;if(M.disableErrorBoundaries===!0)a=t.call(n);else try{a=t.call(n)}catch(e){a=new Mt(e)}return M.inBatch--,M.trackingDerivation=i,zt(e),Rt(e),Wt(r),a}function Rt(e){e.observing_.length===0&&(typeof e.requiresObservable_==`boolean`?e.requiresObservable_:M.reactionRequiresObservable)&&console.warn(`[mobx] Derivation '${e.name_}' is created/updated without reading any observable value.`)}function zt(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&&nn(n,e),n.diffValue=0}for(;i--;){let t=n[i];t.diffValue===1&&(t.diffValue=0,tn(t,e))}r!==0&&(e.dependenciesState_=r,e.onBecomeStale_())}function Bt(e){let t=e.observing_;e.observing_=[];let n=t.length;for(;n--;)nn(t[n],e);e.dependenciesState_=-1}function Vt(e){let t=Ht();try{return e()}finally{Ut(t)}}function Ht(){let e=M.trackingDerivation;return M.trackingDerivation=null,e}function Ut(e){M.trackingDerivation=e}function j(e){let t=M.allowStateReads;return M.allowStateReads=e,t}function Wt(e){M.allowStateReads=e}function Gt(e){if(e.dependenciesState_===0)return;e.dependenciesState_=0;let t=e.observing_,n=t.length;for(;n--;)t[n].lowestObserverState_=0}let Kt=[`mobxGuid`,`spyListeners`,`enforceActions`,`computedRequiresReaction`,`reactionRequiresObservable`,`observableRequiresReaction`,`allowStateReads`,`disableErrorBoundaries`,`runId`,`UNCHANGED`];var qt=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 Jt=!0,Yt=!1,M=function(){let e=globalThis;return e.__mobxInstanceCount>0&&!e.__mobxGlobals&&(Jt=!1),e.__mobxGlobals&&e.__mobxGlobals.version!==7&&(Jt=!1),Jt?e.__mobxGlobals?(e.__mobxInstanceCount+=1,e.__mobxGlobals.UNCHANGED||(e.__mobxGlobals.UNCHANGED={}),e.__mobxGlobals):(e.__mobxInstanceCount=1,e.__mobxGlobals=new qt):(setTimeout(()=>{Yt||n(35)},1),new qt)}();function Xt(){if((M.pendingReactions.length||M.inBatch||M.isRunningReactions)&&n(36),Yt=!0,Jt){let e=globalThis;--e.__mobxInstanceCount===0&&(e.__mobxGlobals=void 0),M=new qt}}function Zt(){return M}function Qt(){let e=new qt;for(let t in e)Kt.indexOf(t)===-1&&(M[t]=e[t]);M.allowStateChanges=!M.enforceActions}function $t(e){return!!e.observers_&&e.observers_.size>0}function en(e){return e.observers_??new Set}function tn(e,t){(e.observers_??=new Set).add(t),e.lowestObserverState_>t.dependenciesState_&&(e.lowestObserverState_=t.dependenciesState_)}function nn(e,t){let n=e.observers_;n&&(n.delete(t),n.size===0&&rn(e))}function rn(e){e.isPendingUnobservation===!1&&(e.isPendingUnobservation=!0,M.pendingUnobservations.push(e))}function an(){M.inBatch++}function on(){--M.inBatch===0&&(gn(),!M.isRunningUnobservations&&M.pendingUnobservations.length>0&&sn())}function sn(){M.isRunningUnobservations=!0;try{let e=M.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 At&&n.suspend_())}M.pendingUnobservations=[]}finally{M.isRunningUnobservations=!1}}function cn(e){var t;e.isBeingObserved||(e.isBeingObserved=!0,e.onBO(),(t=e.observing_)==null||t.forEach(cn))}function ln(e){It(e);let t=M.trackingDerivation;return t===null?((!e.observers_||e.observers_.size===0)&&M.inBatch>0&&rn(e),!1):(t.runId_!==e.lastAccessedBy_&&(e.lastAccessedBy_=t.runId_,t.newObserving_[t.unboundDepsCount_++]=e,!e.isBeingObserved&&M.trackingContext&&(e.isBeingObserved=!0,e.onBO())),e.isBeingObserved)}function un(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 dn(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 fn(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 pn=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 w(this.flags_,1)}set isDisposed(e){this.flags_=T(this.flags_,1,e)}get isScheduled(){return w(this.flags_,2)}set isScheduled(e){this.flags_=T(this.flags_,2,e)}get isTrackPending(){return w(this.flags_,4)}set isTrackPending(e){this.flags_=T(this.flags_,4,e)}get isRunning(){return w(this.flags_,8)}set isRunning(e){this.flags_=T(this.flags_,8,e)}get diffValue(){return+!!w(this.flags_,16)}set diffValue(e){this.flags_=T(this.flags_,16,e===1)}onBecomeStale_(){this.schedule_()}schedule_(){this.isScheduled||(this.isScheduled=!0,M.pendingReactions.push(this),gn())}runReaction_(){if(!this.isDisposed){an(),this.isScheduled=!1;let e=M.trackingContext;if(M.trackingContext=this,Pt(this)){this.isTrackPending=!0;try{this.onInvalidate_(),this.isTrackPending&&N()&&bn({name:this.name_,type:`scheduled-reaction`})}catch(e){this.reportExceptionInDerivation_(e)}}M.trackingContext=e,on()}}track(e){if(this.isDisposed)return;an();let t=N(),n;t&&(n=Date.now(),xn({name:this.name_,type:`reaction`})),this.isRunning=!0;let r=M.trackingContext;M.trackingContext=this;let i=Lt(this,e,void 0);M.trackingContext=r,this.isRunning=!1,this.isTrackPending=!1,this.isDisposed&&Bt(this),Nt(i)&&this.reportExceptionInDerivation_(i.cause),t&&Cn({time:Date.now()-n}),on()}reportExceptionInDerivation_(e){if(this.errorHandler_){this.errorHandler_(e,this);return}if(M.disableErrorBoundaries)throw e;let t=`[mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: '${this}'`;M.suppressReactionErrors?console.warn(`[mobx] (error in reaction '${this.name_}' suppressed, fix error of causing action below)`):console.error(t,e),N()&&bn({type:`error`,name:this.name_,message:t,error:``+e}),M.globalReactionErrorHandlers.forEach(t=>t(e,this))}dispose(){if(!this.isDisposed){var e;this.isDisposed=!0,(e=this.removeAbortListener_)==null||e.call(this),this.isRunning||(an(),Bt(this),on())}}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[E]=this,`dispose`in Symbol&&typeof Symbol.dispose==`symbol`&&(t[Symbol.dispose]=t),t}toString(){return`Reaction[${this.name_}]`}};function mn(e){return M.globalReactionErrorHandlers.push(e),()=>{let t=M.globalReactionErrorHandlers.indexOf(e);t>=0&&M.globalReactionErrorHandlers.splice(t,1)}}let hn=e=>e();function gn(){M.inBatch>0||M.isRunningReactions||hn(_n)}function _n(){M.isRunningReactions=!0;let e=M.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_()}M.isRunningReactions=!1}let vn=b(`Reaction`,pn);function yn(e){let t=hn;hn=n=>e(()=>t(n))}function N(){return!!M.spyListeners.length}function bn(e){if(!M.spyListeners.length)return;let t=M.spyListeners;for(let n=0,r=t.length;n<r;n++)t[n](e)}function xn(e){bn(r({},e,{spyReportStart:!0}))}let Sn={type:`report-end`,spyReportEnd:!0};function Cn(e){bn(e?r({},e,{type:`report-end`,spyReportEnd:!0}):Sn)}function wn(e){return M.spyListeners.push(e),d(()=>{M.spyListeners=M.spyListeners.filter(t=>t!==e)})}let P=`action`,Tn=`autoAction`,En=`<unnamed action>`,Dn=Se(P),On=Se(`action.bound`,{bound:!0}),kn=Se(Tn,{autoAction:!0}),An=Se(`autoAction.bound`,{autoAction:!0,bound:!0});function jn(e){return Xe(e,Te)}function Mn(e){return function(t,r){if(r&&typeof r.kind==`string`)return Te(e?kn:Dn,t,r);if(p(t))return xt(t.name||En,t,e);if(p(r))return xt(t,r,e);if(m(t))return jn(Se(e?Tn:P,{name:t,autoAction:e}));n("Invalid arguments for `action`")}}let Nn=Mn(!1);r(Nn,Dn);let Pn=Mn(!0);r(Pn,kn);let Fn=jn(On),In=jn(An);function Ln(e){return St(e.name||En,!1,e,this,void 0)}function Rn(e){return p(e)&&e.isMobxAction===!0}function zn(e,t=c){var r;p(e)||n(`Autorun expects a function as first argument`),Rn(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 pn(i,function(){this.track(s)},t.onError,t.requiresObservable);else{let e=Vn(t),n=!1;o=new pn(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 Bn=e=>e();function Vn(e){return e.scheduler?e.scheduler:e.delay?t=>setTimeout(t,e.delay):Bn}function Hn(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=Nn(a,r.onError?Un(r.onError,t):t),s=!r.scheduler&&!r.delay,l=Vn(r),d=!0,f=!1,m,h=r.equals||pe,_=new pn(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=Tt(!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 Un(e,t){return function(){try{return t.apply(this,arguments)}catch(t){e.call(this,t)}}}function Wn(e,t,n){return Kn(`onBO`,e,t,n)}function Gn(e,t,n){return Kn(`onBUO`,e,t,n)}function Kn(e,t,n,r){let i=typeof r==`function`?ki(t,n):ki(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 qn=`always`;function Jn(e){e.isolateGlobalState===!0&&Xt();let{enforceActions:t}=e;if(t!==void 0){let e=t===qn?qn:t===`observed`;M.enforceActions=e,M.allowStateChanges=!(e===!0||e===qn)}[`computedRequiresReaction`,`reactionRequiresObservable`,`observableRequiresReaction`,`disableErrorBoundaries`,`safeDescriptors`].forEach(t=>{t in e&&(M[t]=!!e[t])}),M.allowStateReads=!M.observableRequiresReaction,M.disableErrorBoundaries===!0&&console.warn("WARNING: Debug feature only. MobX will NOT recover from errors when `disableErrorBoundaries` is enabled."),e.reactionScheduler&&yn(e.reactionScheduler)}function Yn(e,t,r,i){arguments.length>4&&n(`'extendObservable' expected 2-4 arguments`),typeof e!=`object`&&n(`'extendObservable' expects an object as first argument`),F(e)&&n(`'extendObservable' should not be used on maps, use map.merge instead`),g(t)||n(`'extendObservable' only accepts plain objects as second argument`),(br(t)||br(r))&&n(`Extending an object with another observable (object) is not supported`);let a=ae(t);return Mi(()=>{let t=Ci(e,i)[E];te(a).forEach(e=>{t.extend_(e,a[e],r&&e in r?r[e]:!0)})}),e}function Xn(e,t){return Zn(ki(e,t))}function Zn(e){let t={name:e.name_};return e.observing_&&e.observing_.length>0&&(t.dependencies=er(e.observing_).map(Zn)),t}function Qn(e,t){return $n(ki(e,t))}function $n(e){let t={name:e.name_};return $t(e)&&(t.observers=Array.from(en(e),$n)),t}function er(e){return Array.from(new Set(e))}let tr=0;var nr=class extends Error{constructor(){super(`FLOW_CANCELLED`),Object.setPrototypeOf(this,new.target.prototype),this.name=`FlowCancellationError`}toString(){return`Error: ${this.message}`}};function rr(e){return e instanceof nr}function ir(e){return Xe(e,je)}let ar=Oe(`flow`),or=Oe(`flow.bound`,{bound:!0}),sr=r(function(e,t){if(t&&typeof t.kind==`string`)return je(ar,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=++tr,a=Nn(`${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=Nn(`${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=Nn(`${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=Nn(`${i} - runid: ${n} - cancel`,function(){try{s&&lr(s);let e=a.return(void 0),t=Promise.resolve(e.value);t.then(f,f),lr(t),o(new nr)}catch(e){o(e)}}),c};return a.isMobXFlow=!0,a},ar),cr=ir(or);function lr(e){p(e.cancel)&&e.cancel()}function ur(e){return e}function dr(e){return e?.isMobXFlow===!0}function fr(e,t,r){let i;if(F(e)||fi(e)||kt(e))i=Ai(e);else if(Ei(e)){if(!m(t))return n(`InterceptReads can only be used with a specific property, not with an object in general`);i=Ai(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 pr(e,t,n){return p(n)?hr(e,t,n):mr(e,t)}function mr(e,t){return Kr(Ai(e),t)}function hr(e,t,n){return Kr(Ai(e,t),n)}function gr(e,t){var n;if(t===void 0)return jt(e);if(Ei(e)===!1)return!1;let r=e[E];return(n=r.lazyComputedKeys_)!=null&&n.has(t)?!0:r.values_.has(t)?jt(ki(e,t)):!1}function _r(e){return arguments.length>1?n(`isComputed expects only 1 argument. Use isComputedProp to inspect the observability of a property`):gr(e)}function vr(e,t){return m(t)?gr(e,t):n(`isComputed expected a property name as second argument`)}function yr(e,t){if(!e)return!1;if(t!==void 0){if(F(e)||fi(e))return n(`isObservable(object, propertyName) is not supported for arrays and maps. Use map.has or array.length instead.`);if(Ei(e)){var r,i;let n=e[E];return n.values_.has(t)||!!((r=n.lazyComputedKeys_)!=null&&r.has(t))||!!((i=n.lazyObservableKeys_)!=null&&i.has(t))}return!1}return Ei(e)||!!e[E]||ce(e)||vn(e)||jt(e)}function br(e){return arguments.length!==1&&n(`isObservable expects only 1 argument. Use isObservableProp to inspect the observability of a property`),yr(e)}function xr(e,t){return m(t)?yr(e,t):n(`expected a property name as second argument`)}function Sr(e){if(Ei(e))return e[E].keys_();if(F(e)||vi(e))return Array.from(e.keys());if(fi(e))return e.map((e,t)=>t);n(5)}function Cr(e){if(Ei(e))return Sr(e).map(t=>e[t]);if(F(e))return Sr(e).map(t=>e.get(t));if(vi(e))return Array.from(e.values());if(fi(e))return e.slice();n(6)}function wr(e){if(Ei(e))return Sr(e).map(t=>[t,e[t]]);if(F(e))return Sr(e).map(t=>[t,e.get(t)]);if(vi(e))return Array.from(e.entries());if(fi(e))return e.map((e,t)=>[t,e]);n(7)}function Tr(e,t,r){if(arguments.length===2&&!vi(e)){an();let n=t;try{for(let t in n)Tr(e,t,n[t])}finally{on()}return}Ei(e)?e[E].set_(t,r):F(e)?e.set(t,r):vi(e)?e.add(t):fi(e)?(typeof t!=`number`&&(t=parseInt(t,10)),t<0&&n(42,t),an(),t>=e.length&&(e.length=t+1),e[t]=r,on()):n(8)}function Er(e,t){Ei(e)?e[E].delete_(t):F(e)||vi(e)?e.delete(t):fi(e)?(typeof t!=`number`&&(t=parseInt(t,10)),e.splice(t,1)):n(9)}function Dr(e,t){if(Ei(e))return e[E].has_(t);if(F(e)||vi(e))return e.has(t);if(fi(e))return t>=0&&t<e.length;n(10)}function Or(e,t){if(Dr(e,t)){if(Ei(e))return e[E].get_(t);if(F(e))return e.get(t);if(fi(e))return e[t];n(11)}}function kr(e,t,r){if(Ei(e))return e[E].defineProperty_(t,r);n(39)}function Ar(e){if(Ei(e))return e[E].ownKeys_();n(38)}function jr(e,t,n,r){return p(n)?Nr(e,t,n,r):Mr(e,t,n)}function Mr(e,t,r){let i=Ai(e);if(fi(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(F(e))r===!0&&n("`observe` doesn't support fireImmediately=true in combination with maps.");else if(vi(e))r===!0&&n("`observe` doesn't support fireImmediately=true in combination with sets.");else if(Ei(e))r===!0&&n("`observe` doesn't support the fire immediately property for observable objects.");else return Pr(i,t,r);return Yr(i,t)}function Nr(e,t,n,r){return Pr(Ai(e,t),n,r)}function Pr(e,t,n){if(jt(e)){let r=!0,i;return zn(()=>{let a=e.get();if(!r||n){let n=Ht();t({observableKind:`computed`,debugObjectName:e.name_,type:ni,object:e,newValue:a,oldValue:i}),Ut(n)}r=!1,i=a})}return n&&t({observableKind:`value`,debugObjectName:e.name_,object:e,type:ni,newValue:e.value_,oldValue:void 0}),Yr(e,t)}function Fr(e,t,n){return e.set(t,n),n}function Ir(e,t){if(typeof e!=`object`||!e||e instanceof Date||!br(e))return e;if(kt(e)||jt(e))return Ir(e.get(),t);if(t.has(e))return t.get(e);if(fi(e)){let n=Fr(t,e,Array(e.length));return e.forEach((e,r)=>{n[r]=Ir(e,t)}),n}if(vi(e)){let n=Fr(t,e,new Set);return e.forEach(e=>{n.add(Ir(e,t))}),n}if(F(e)){let n=Fr(t,e,new Map);return e.forEach((e,r)=>{n.set(r,Ir(e,t))}),n}else{let n=Fr(t,e,{});return Ar(e).forEach(r=>{o.propertyIsEnumerable.call(e,r)&&(n[r]=Ir(e[r],t))}),n}}function Lr(e,t){return t&&n(`toJS no longer supports options`),Ir(e,new Map)}function Rr(e,t=void 0){an();try{return e.apply(t)}finally{on()}}function zr(e,t,n){return arguments.length===1||t&&typeof t==`object`?Vr(e,t):Br(e,t,n||{})}function Br(e,t,n){let r;if(typeof n.timeout==`number`){let e=Error(`WHEN_TIMEOUT`);r=setTimeout(()=>{if(!a[E].isDisposed)if(a(),n.onError)n.onError(e);else throw e},n.timeout)}n.name=n.name||`When@`+u();let i=xt(n.name+`-effect`,t);var a=zn(t=>{Tt(!1,e)&&(t.dispose(),r&&clearTimeout(r),i())},n);return a}function Vr(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=Br(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 Hr(e){return e[E]}let Ur={has(e,t){return Hr(e).has_(t)},get(e,t){return Hr(e).get_(t)},set(e,t,n){return m(t)?Hr(e).set_(t,n,!0)??!0:!1},deleteProperty(e,t){return m(t)?Hr(e).delete_(t,!0)??!0:!1},defineProperty(e,t,n){return Hr(e).defineProperty_(t,n)??!0},ownKeys(e){return Hr(e).ownKeys_()},preventExtensions(e){n(13)}};function Wr(e,t){var n;return e=Ci(e,t),(n=e[E]).proxy_??(n.proxy_=new Proxy(e,Ur))}function Gr(e){return e.interceptors_!==void 0&&e.interceptors_.length>0}function Kr(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 qr(e,t){let r=Ht();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{Ut(r)}}function Jr(e){return e.changeListeners_!==void 0&&e.changeListeners_.length>0}function Yr(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 Xr(e,t){let n=Ht(),r=e.changeListeners_;if(r){r=r.slice();for(let e=0,n=r.length;e<n;e++)r[e](t);Ut(n)}}function Zr(e,t,n){return Mi(()=>{let r=Ci(e,n)[E];te(t).forEach(e=>ei(r,e,t[e]))}),e}let Qr=Symbol(`mobx-keys`);function $r(e,t,r){return!g(e)&&!g(Object.getPrototypeOf(e))&&n(`'makeAutoObservable' can only be used for classes that don't have a superclass`),Ei(e)&&n(`makeAutoObservable can only be used on objects not already made observable`),g(e)?Yn(e,e,t,r):(Mi(()=>{let n=Ci(e,r)[E];if(!e[Qr]){let t=Object.getPrototypeOf(e),n=new Set([...te(e),...te(t)]);n.delete(`constructor`),n.delete(E),v(t,Qr,n)}e[Qr].forEach(e=>ei(n,e,t&&e in t?t[e]:!0))}),e)}function ei(e,t,r){if(r===!0&&(r=e.defaultAnnotation_),r===!1)return;Oi(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)}Di(e,r,t)}let ti=`splice`,ni=`update`,ri={get(e,t){let n=e[E];return t===E?n:t===`length`?n.getArrayLength_():typeof t==`string`&&!isNaN(t)?n.get_(parseInt(t)):ie(oi,t)?oi[t]:e[t]},set(e,t,n){let r=e[E];return t===`length`?r.setArrayLength_(n):typeof t==`symbol`||isNaN(t)?e[t]=n:r.set_(parseInt(t),n),!0},preventExtensions(){n(15)}};var ii=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 se(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){A(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),Gr(this)){let r=qr(this,{object:this.proxy_,type:ti,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_&&N(),i=Jr(this),a=i||r?{observableKind:`array`,object:this.proxy_,type:ni,debugObjectName:this.atom_.name_,index:e,newValue:t,oldValue:n}:null;r&&xn(a),this.atom_.reportChanged(),i&&Xr(this,a),r&&Cn()}notifyArraySplice_(e,t,n){let r=!this.owned_&&N(),i=Jr(this),a=i||r?{observableKind:`array`,object:this.proxy_,debugObjectName:this.atom_.name_,type:ti,index:e,removed:n,added:t,removedCount:n.length,addedCount:t.length}:null;r&&xn(a),this.atom_.reportChanged(),i&&Xr(this,a),r&&Cn()}get_(e){return this.atom_.reportObserved(),this.dehanceValue_(this.values_[e])}set_(e,t){let n=this.values_;if(e<n.length){A(this.atom_);let r=n[e];if(Gr(this)){let n=qr(this,{type:ni,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 ai(e,t,n=`ObservableArray@`+u(),r=!1){return Mi(()=>{let i=new ii(n,t,r);y(i.values_,E,i);let a=new Proxy(i.values_,ri);return i.proxy_=a,e&&e.length&&i.spliceWithArray_(0,0,e),a})}var oi={clear(){return this.splice(0)},replace(e){let t=this[E];return t.spliceWithArray_(0,t.values_.length,e)},toJSON(){return this.slice()},splice(e,t,...n){let r=this[E];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[E].spliceWithArray_(e,t,n)},push(...e){let t=this[E];return t.spliceWithArray_(t.values_.length,0,e),t.values_.length},pop(){return this.splice(Math.max(this[E].values_.length-1,0),1)[0]},shift(){return this.splice(0,1)[0]},unshift(...e){let t=this[E];return t.spliceWithArray_(0,0,e),t.values_.length},reverse(){return M.trackingDerivation&&n(37,`reverse`),this.replace(this.slice().reverse()),this},sort(){M.trackingDerivation&&n(37,`sort`);let e=this.slice();return e.sort.apply(e,arguments),this.replace(e),this},remove(e){let t=this[E],n=t.dehanceValues_(t.values_).indexOf(e);return n>-1?(this.splice(n,1),!0):!1}};si(`at`,ci),si(`concat`,ci),si(`flat`,ci),si(`includes`,ci),si(`indexOf`,ci),si(`join`,ci),si(`lastIndexOf`,ci),si(`slice`,ci),si(`toString`,ci),si(`toLocaleString`,ci),si(`toSorted`,ci),si(`toSpliced`,ci),si(`with`,ci),si(`every`,li),si(`filter`,li),si(`find`,li),si(`findIndex`,li),si(`findLast`,li),si(`findLastIndex`,li),si(`flatMap`,li),si(`forEach`,li),si(`map`,li),si(`some`,li),si(`toReversed`,li),si(`reduce`,ui),si(`reduceRight`,ui);function si(e,t){typeof Array.prototype[e]==`function`&&(oi[e]=t(e))}function ci(e){return function(){let t=this[E];t.atom_.reportObserved();let n=t.dehanceValues_(t.values_);return n[e].apply(n,arguments)}}function li(e){return function(t,n){let r=this[E];return r.atom_.reportObserved(),r.dehanceValues_(r.values_)[e]((e,r)=>t.call(n,e,r,this))}}function ui(e){return function(){let t=this[E];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 di=b(`ObservableArrayAdministration`,ii);function fi(e){return h(e)&&di(e[E])}let pi={},mi=`delete`;var hi=class{constructor(e,t=me,n=`ObservableMap@`+u()){this.enhancer_=void 0,this.name_=void 0,this[E]=pi,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,Mi(()=>{this.keysAtom_=le(`${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(!M.trackingDerivation)return this.has_(e);let t=this.hasMap_.get(e);if(!t){let n=t=new Ot(this.has_(e),ge,`${this.name_}.${ne(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(Gr(this)){let r=qr(this,{type:n?ni:`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(A(this.keysAtom_),Gr(this)&&!qr(this,{type:mi,object:this,name:e}))return!1;if(this.has_(e)){let t=N(),n=Jr(this),r=n||t?{observableKind:`map`,debugObjectName:this.name_,type:mi,object:this,oldValue:this.data_.get(e).value_,name:e}:null;return t&&xn(r),Rr(()=>{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&&Xr(this,r),t&&Cn(),!0}return!1}updateValue_(e,t){let n=this.data_.get(e);if(t=n.prepareNewValue_(t),t!==M.UNCHANGED){let r=N(),i=Jr(this),a=i||r?{observableKind:`map`,debugObjectName:this.name_,type:ni,object:this,oldValue:n.value_,name:e,newValue:t}:null;r&&xn(a),n.setNewValue_(t),i&&Xr(this,a),r&&Cn()}}addValue_(e,t){A(this.keysAtom_),Rr(()=>{var n;let r=new Ot(t,this.enhancer_,`${this.name_}.${ne(e)}`,!1);this.data_.set(e,r),t=r.value_,(n=this.hasMap_.get(e))==null||n.setNewValue_(!0),this.keysAtom_.reportChanged()});let n=N(),r=Jr(this),i=r||n?{observableKind:`map`,debugObjectName:this.name_,type:`add`,object:this,name:e,newValue:t}:null;n&&xn(i),r&&Xr(this,i),n&&Cn()}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 I({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 I({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 F(e)&&(e=new Map(e)),Rr(()=>{g(e)?ee(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(){Rr(()=>{Vt(()=>{for(let e of this.keys())this.delete(e)})})}replace(e){return Rr(()=>{let t=L(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`}},F=b(`ObservableMap`,hi);function I(e){return e[Symbol.toStringTag]=`MapIterator`,Ri(e)}function L(e){if(x(e)||F(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 gi={};var _i=class{constructor(e,t=me,n=`ObservableSet@`+u()){this.name_=void 0,this[E]=gi,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),Mi(()=>{this.atom_=le(this.name_),e&&this.replace(e)})}dehanceValue_(e){return this.dehancer===void 0?e:this.dehancer(e)}clear(){Rr(()=>{Vt(()=>{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(A(this.atom_),Gr(this)){let t=qr(this,{type:`add`,object:this,newValue:e});if(!t)return this;e=t.newValue}if(!this.has(e)){Rr(()=>{e=this.enhancer_(e,void 0),this.data_.add(e),this.atom_.reportChanged()});let t=N(),n=Jr(this),r=n||t?{observableKind:`set`,debugObjectName:this.name_,type:`add`,object:this,newValue:e}:null;t&&xn(r),n&&Xr(this,r),t&&Cn()}return this}delete(e){if(Gr(this)&&!qr(this,{type:mi,object:this,oldValue:e}))return!1;if(this.has(e)){let t=N(),n=Jr(this),r=n||t?{observableKind:`set`,debugObjectName:this.name_,type:mi,object:this,oldValue:e}:null;return t&&xn(r),Rr(()=>{this.atom_.reportChanged(),this.data_.delete(e)}),n&&Xr(this,r),t&&Cn(),!0}return!1}has(e){return this.atom_.reportObserved(),this.data_.has(this.dehanceValue_(e))}entries(){let e=this.values();return yi({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 yi({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 vi(e)&&(e=new Set(e)),Array.isArray(e)||C(e)?Rr(()=>{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`}},vi=b(`ObservableSet`,_i);function yi(e){return e[Symbol.toStringTag]=`SetIterator`,Ri(e)}let bi=Object.create(null),xi=`remove`;var Si=class{constructor(e,t=new Map,r,i=We){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 se(`${this.name_}.keys`),this.isPlainObject_=g(this.target_),Bi(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 At)return n.set(t),!0;if(Gr(this)){let n=qr(this,{type:ni,object:this.proxy_||this.target_,name:e,newValue:t});if(!n)return null;t=n.newValue}if(t=n.prepareNewValue_(t),t!==M.UNCHANGED){let r=Jr(this),i=N(),a=r||i?{type:ni,observableKind:`object`,debugObjectName:this.name_,object:this.proxy_||this.target_,oldValue:n.value_,name:e,newValue:t}:null;i&&xn(a),n.setNewValue_(t),r&&Xr(this,a),i&&Cn()}return!0}get_(e){return M.trackingDerivation&&!ie(this.target_,e)&&this.has_(e),this.target_[e]}set_(e,t,n=!1){return ie(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(!M.trackingDerivation)return e in this.target_;this.pendingKeys_||=new Map;let t=this.pendingKeys_.get(e);return t||(t=new Ot(e in this.target_,ge,`${this.name_}.${ne(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);Oi(this,n,e);let i=n.extend_(this,e,t,r);return i&&Di(this,n,e),i}defineProperty_(e,t,n=!1){A(this.keysAtom_);try{an();let i=this.delete_(e);if(!i)return i;if(Gr(this)){let n=qr(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{on()}return!0}defineObservableProperty_(e,t,n,r=!1){A(this.keysAtom_);try{an();let i=this.delete_(e);if(!i)return i;if(Gr(this)){let n=qr(this,{object:this.proxy_||this.target_,name:e,type:`add`,newValue:t});if(!n)return null;t=n.newValue}let o=Ti(e),s={configurable:M.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 Ot(t,n,`${this.name_}.${e.toString()}`,!1);this.values_.set(e,c),this.notifyPropertyAddition_(e,c.value_)}finally{on()}return!0}defineComputedProperty_(e,t,n=!1){A(this.keysAtom_);try{an();let r=this.delete_(e);if(!r)return r;if(Gr(this)&&!qr(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=Ti(e),o={configurable:M.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 At(t)),this.notifyPropertyAddition_(e,void 0)}finally{on()}return!0}delete_(e,t=!1){if(A(this.keysAtom_),!ie(this.target_,e))return!0;if(Gr(this)&&!qr(this,{object:this.proxy_||this.target_,name:e,type:xi}))return null;try{var n;an();let r=Jr(this),a=N(),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 Ot&&(s=o.value_),un(o)),this.keysAtom_.reportChanged(),(n=this.pendingKeys_)==null||(n=n.get(e))==null||n.set(e in this.target_),r||a){let t={type:xi,observableKind:`object`,object:this.proxy_||this.target_,debugObjectName:this.name_,oldValue:s,name:e};a&&xn(t),r&&Xr(this,t),a&&Cn()}}finally{on()}return!0}notifyPropertyAddition_(e,t){var n;let r=Jr(this),i=N();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&&xn(n),r&&Xr(this,n),i&&Cn()}(n=this.pendingKeys_)==null||(n=n.get(e))==null||n.set(!0),this.keysAtom_.reportChanged()}ownKeys_(){return this.keysAtom_.reportObserved(),te(this.target_)}keys_(){return this.keysAtom_.reportObserved(),Object.keys(this.target_)}};function Ci(e,t){if(t&&Ei(e)&&n(`Options can't be provided for already observable objects.`),ie(e,E))return Ai(e)instanceof Si||n(`Cannot convert '${ji(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,E,new Si(e,new Map,String(r),at(t))),e}let wi=b(`ObservableObjectAdministration`,Si);function Ti(e){return bi[e]||(bi[e]={get(){return this[E].getObservablePropValue_(e)},set(t){return this[E].setObservablePropValue_(e,t)}})}function Ei(e){return h(e)?wi(e[E]):!1}function Di(e,t,n){e.appliedAnnotations_[n]=t}function Oi(e,t,r){if(Bi(t)||n(`Cannot annotate '${e.name_}.${r.toString()}': Invalid annotation.`),!be(t)&&ie(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 ki(e,t){if(typeof e==`object`&&e){if(fi(e))return t!==void 0&&n(23),e[E].atom_;if(vi(e))return e.atom_;if(F(e)){if(t===void 0)return e.keysAtom_;let r=e.data_.get(t)||e.hasMap_.get(t);return r||n(25,t,ji(e)),r}if(Ei(e)){if(!t)return n(26);let r=e[E],i=r.values_.get(t)??r.materializeLazyComputed_(t)??r.materializeLazyObservable_(t);return i||n(27,t,ji(e)),i}if(ce(e)||jt(e)||vn(e))return e}else if(p(e)&&vn(e[E]))return e[E];n(28)}function Ai(e,t){if(e||n(29),t!==void 0)return Ai(ki(e,t));if(ce(e)||jt(e)||vn(e)||F(e)||vi(e))return e;if(e[E])return e[E];n(24,e)}function ji(e,t){let n;if(t!==void 0)n=ki(e,t);else if(Rn(e))return e.name;else n=Ei(e)||F(e)||vi(e)?Ai(e):ki(e);return n.name_}function Mi(e){let t=Ht(),n=Et(!0);an();try{return e()}finally{on(),Dt(n),Ut(t)}}let Ni=o.toString;function Pi(e,t,n=-1){return Fi(e,t,n)}function Fi(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=Ni.call(e);if(o!==Ni.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=Ii(e),t=Ii(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(!Fi(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(!(ie(t,o)&&Fi(e[o],t[o],n-1,r,i)))return!1}}return r.pop(),i.pop(),!0}function Ii(e){return fi(e)?e.slice():x(e)||F(e)||C(e)||vi(e)?Array.from(e.entries()):e}let Li=globalThis.Iterator?.prototype||{};function Ri(e){return e[Symbol.iterator]=zi,r(Object.create(Li),e)}function zi(){return this}function Bi(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:wn,extras:{getDebugName:ji},$mobx:E}),e.$mobx=E,e.FlowCancellationError=nr,e.ObservableMap=hi,e.ObservableSet=_i,e.Reaction=pn,e._allowStateChanges=Tt,e._allowStateChangesInsideComputed=Ln,e._allowStateReadsEnd=Wt,e._allowStateReadsStart=j,e._autoAction=Pn,e._autoActionBound=In,e._endAction=wt,e._getAdministration=Ai,e._getGlobalState=Zt,e._interceptReads=fr,e._isComputingDerivation=Ft,e._resetGlobalState=Qt,e._startAction=Ct,e.action=Nn,e.actionBound=Fn,e.autorun=zn,e.compareDefault=pe,e.compareIdentity=ue,e.compareShallow=fe,e.compareStructural=de,e.computed=k,e.computedStruct=gt,e.configure=Jn,e.createAtom=le,e.defineProperty=kr,e.entries=wr,e.extendObservable=Yn,e.flow=sr,e.flowBound=cr,e.flowResult=ur,e.get=Or,e.getAtom=ki,e.getDebugName=ji,e.getDependencyTree=Xn,e.getObserverTree=Qn,e.has=Dr,e.intercept=pr,e.isAction=Rn,e.isBoxedObservable=kt,e.isComputed=_r,e.isComputedProp=vr,e.isFlow=dr,e.isFlowCancellationError=rr,e.isObservable=br,e.isObservableArray=fi,e.isObservableMap=F,e.isObservableObject=Ei,e.isObservableProp=xr,e.isObservableSet=vi,e.keys=Sr,e.makeAutoObservable=$r,e.makeObservable=Zr,e.observable=O,e.observableDeep=dt,e.observableRef=lt,e.observableShallow=ut,e.observableStruct=ft,e.observe=jr,e.onBecomeObserved=Wn,e.onBecomeUnobserved=Gn,e.onReactionError=mn,e.override=ye,e.ownKeys=Ar,e.reaction=Hn,e.remove=Er,e.runInAction=Ln,e.set=Tr,e.spy=wn,e.toJS=Lr,e.transaction=Rr,e.untracked=Vt,e.values=Cr,e.when=zr})),Vg=ye(((e,t)=>{process.env.NODE_ENV===`production`?t.exports=zg():t.exports=Bg()}))();function Hg(e){if(Array.isArray(e))return Object.freeze(e.map(Hg));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]=Hg(r);return Object.freeze(t)}return e}function Ug(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 Wg(e){return typeof e==`string`?e:String(e)}function Gg(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 Kg(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 qg=class extends Error{constructor(e,t){super(t),this.variable=e}};function Jg(e){return e instanceof qg||e instanceof Error&&e.cause!==void 0&&Jg(e.cause)}var Yg=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?i_(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}},Xg=class extends Yg{name=`ParseError`;kind=`ParseError`;expected;found;constructor(e,t,n={}){super(e,t,n),this.expected=n.expected,this.found=n.found}},Zg=class extends Yg{name=`EvalError`;kind=`EvalError`},Qg=class extends Zg{name=`FuncNotFoundError`;kind=`FuncNotFoundError`;funcName;suggestions;constructor(e,t,n={}){let r=a_(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}},$g=class extends Zg{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}},e_=class extends Zg{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}},t_=class extends e_{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)}`}},n_=class extends Zg{name=`MissingFieldError`;kind=`MissingFieldError`;path;constructor(e,t,n={}){super(`field "${e.join(`.`)}" not found on receiver`,t,n),this.path=e}},r_=class extends Zg{name=`FailError`;kind=`FailError`;constructor(e,t={line:0,column:0,offset:0},n={}){super(e,t,n)}};function i_(e,t){let n=e.split(`
|
|
56
|
+
`))}function Jm(e,t,n,r){let{colors:i}=e.channels[0].severity,{fullText:a,failedConfigFile:o}=t,s=new H({bgcolor:i.bg,color:i.fg}),c=(e,t)=>new G(e,{style:t,end:``,overflow:`ignore`}),l=n>0?[c(`${n} more rows · `,s),a.kind===`file`?c(`open full text`,s.withLink(re(a.path).href)):c(`full text unavailable: ${Jd(a.reason)}`,s)]:[],u=o===null?[]:[c(`${l.length>0?` · `:``}open `,s),c(Jd(o),s.withLink(re(o).href))],d=[c(`↳ `,s),...l,...u.slice(0,-1)],f=d.reduce((e,t)=>e+t.cellLength,0),p=u.slice(-1).map(e=>e.truncate(Math.max(1,r.width-f),{mode:`middle`})),m=G.fromFragments([...d,...p]).truncate(r.width);return m.overflow=`ignore`,Im([m],r)}const Ym=e=>!e.startsWith(`.`)&&!e.endsWith(`~`);function Xm(e,t){return t.isSymbolicLink()?Buffer.from(r.readlinkSync(e)):r.readFileSync(e)}function Zm(e,t){return r.readdirSync(t).filter(Ym).sort().flatMap(n=>{let i=l.join(t,n),a=r.lstatSync(i,{throwIfNoEntry:!1});return a===void 0?[]:a.isDirectory()?Zm(e,i):[[l.relative(e,i).split(l.sep).join(`/`),Xm(i,a)]]})}function Qm(e){let t=ie.createHash(`sha256`);for(let[n,r]of Zm(e,e))t.update(n).update(`\0`).update(r).update(`\0`);return t.digest(`hex`)}const $m=e=>e.slice(0,7);function eh(e){return l.dirname(l.dirname(e))}function th(){return{version:Et,digest:`9fbbbe3fb9c046f7d8228a2341459f0a4a9b605bf37cef1b55fa7748c7f9f853`}}function nh(e){let t=JSON.parse(r.readFileSync(l.join(e,`package.json`),`utf8`)),n=typeof t==`object`&&t?t.version:void 0;if(typeof n!=`string`)throw Error(`${l.join(e,`package.json`)} has no version string`);return n}function rh(e,t){try{let n=eh(ne(e)),i=l.join(n,`src`);if(!r.existsSync(i))return{kind:`not-source-checkout`};let a=t(),o=Qm(i);return o===a.digest?{kind:`current`,root:n,stamp:a}:{kind:`stale`,root:n,source:{version:nh(n),digest:o},running:a}}catch(e){return{kind:`unchecked`,reason:e.message}}}var K=class extends Error{constructor(e){super(e),this.name=`BadVerbArgs`}};const ih=new Map;function ah(e){let t=sh(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 oh(e,t){return e===`bar`?t:ah(e)}function sh(e){let t=ih.get(e);if(t!==void 0)return t;let n=kc(e);return n===null?null:(ih.set(e,n),n)}function ch(e,t){return lh(e,`${t.hueShift} ${t.chromaScale} ${t.lightnessScale} ${t.lightnessShift}`,()=>Vc(e,t))}const lh=tf();function uh(e){let t=sh(e);return t===null?null:{kind:`decided`,name:e,value:t}}function dh(e,t,n){let r=uh(e);return r===null?(n(jp(t,`palette`,`"${e}" names no installed theme${pp(e)}`)),ph()):r}function fh(e,t,n){return Cp(e,t,n,ph(),uh)}function ph(){return{kind:`decided`,name:mp,value:ah(mp)}}const mh=[`vertical`,`horizontal`],hh={vertical:`row`,horizontal:`cell`};function gh(e){return e.id??e.name}function _h(e){return[...bh(e)].flatMap(e=>e.kind===`segment`?[gh(e)]:[])}function vh(e,t){if(!t.has(e))return e;let n=2;for(;t.has(`${e}-${n}`);)n++;return`${e}-${n}`}function yh(e,t){return e.opens===void 0?e:{...e,opens:{...e.opens,body:t(e.opens.body)}}}function*bh(e){yield e;for(let t of wh(e))yield*bh(t)}const xh=(e,t)=>`${e}.children[${t}]`,Sh=e=>`${e}.opens.body`;function*Ch(e,t){if(yield[e,t],e.kind===`container`)for(let[n,r]of e.children.entries())yield*Ch(r,xh(t,n));else e.opens!==void 0&&(yield*Ch(e.opens.body,Sh(t)))}function wh(e){return e.kind===`container`?e.children:e.opens===void 0?[]:[e.opens.body]}const Th=[`shade`,`variation`,`style`];function Eh(e){return e===void 0||`text`in e?`text`:`regex`in e?`regex`:`json`}const Dh=[`ttl`,`watch_file`,`depends_on`,`key`,`never`];function Oh(e){return e.kind===`file`||e.kind===`shell`}const kh=[`branch`,`sha`,`dirty`,`ahead`,`behind`,`stash`],Ah=`theme`,jh=`effect`,Mh=[Ah,jh];function Nh(e){return{...e.settings,[Ah]:{label:Ah,domain:`theme`,default:e.palette??`bar`},[jh]:{label:jh,domain:Np,default:`bar`}}}function Ph(e){let t=e?.domain;return typeof t==`object`&&`min`in t?t:void 0}function Fh(e,t){return Object.entries(e).flatMap(([n,r])=>{let i=Ph(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 Ih(e,t){let{domain:n}=e;return n===`bool`?typeof t==`boolean`:n===`theme`?typeof t==`string`&&yp(t):`min`in n?typeof t==`number`&&Number.isInteger(t)&&t>=n.min&&t<=n.max:typeof t==`string`&&n.includes(t)}function Lh(e){return String(e)}function Rh(e,t){let{domain:n}=e;if(typeof n==`object`&&`min`in n)return im(t,n)??void 0;let r=n===`bool`?t===`true`?!0:t===`false`?!1:t:t;return Ih(e,r)?r:void 0}function zh(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:Rh(n,o))??i}function Bh(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 Vh=[`left`,`center`,`right`],Hh=[`right`,`left`,`middle`],Uh=/^[A-Za-z_][A-Za-z0-9_]*$/;function Wh(e){return`#${e+1}`}const Gh={rows:{}};function Kh(e){return`rows`in e}function qh(e){return Object.fromEntries(e.map((e,t)=>[Wh(t),e]))}function Jh(e){if(e.kind===`container`&&e.direction===`vertical`){let{kind:t,direction:n,children:r,...i}=e;return{...i,rows:qh(r)}}let{when:t,...n}=e;return{...t!==void 0&&{when:t},rows:qh([n])}}function Yh(e){let{rows:t,...n}=e;return{kind:`container`,direction:`vertical`,children:Object.values(t),...n}}function Xh(e){return Kh(e)?Yh(e):e}function*Zh(e,t){if(!Kh(e)){yield*Ch(e,t);return}yield[Yh(e),t];for(let[n,r]of Object.entries(e.rows))yield*Ch(r,`${t}.rows.${n}`)}function Qh(e,t){return Kh(e)?{...t,...e,rows:{...t.rows,...e.rows}}:Jh(e)}function $h(e){if(!Kh(e))return!0;let{rows:t,...n}=e;return Object.values(n).some(e=>e!==void 0)||Object.keys(t).length>0}const eg=`default`,tg={};function ng(e){return[...new Set([eg,...Object.keys(e)])]}function rg(e,t,n){return bp(void 0,e,t,eg,n)}function ig(e,t){let n={[eg]:tg,...e}[t];if(n===void 0)throw Error(`Preset "${t}" is not declared in this config — effectivePresetName collapses unknown names to "${eg}", which always resolves; a miss here means a raw name reached this function without going through that resolution`);return n}function ag(e,t){let n=ig(e.presets,t).root??Gh;return{node:Yh(Qh(n,e.root)),path:$h(n)?`presets.${t}.root`:`root`}}function og(e,t){return{...e.globals,...ig(e.presets,t).globals}}const sg=new Map;function cg(e,t,n){sg.set(e,{permanent:!0,resolve:t,paletteOf:n})}cg(`themes`,()=>gp(),e=>ah(e));const lg=`placementThemes`;cg(lg,_p,(e,t)=>oh(e,t.palette)),cg(`endcaps`,()=>Lp),cg(`variations`,()=>qp),cg(`shades`,()=>Xp),cg(`charsets`,()=>Hp),cg(`colorCompatibilities`,()=>Gp);function ug(e){return new Map([[`styles`,{members:Object.keys(e.styles),paletteOf:(t,n)=>ch(n.basePalette,e.styles[t])}],[`presets`,{members:ng(e.presets)}]])}function dg(e){return[...new Set([...sg.keys(),...e.keys()])]}function fg(e,t){if(typeof e!=`string`)return{members:e};let n=t.get(e);if(n)return n;let r=sg.get(e);if(r)return{members:r.resolve(),paletteOf:r.paletteOf};throw Error(mg(e,t))}const pg=new Map([[`looks`,`styles`],[`progressions`,`variations`]]);function mg(e,t){let n=pg.get(e);return`unknown option domain "${e}"${n===void 0?``:` — it was renamed "${n}"; write from: "${n}"`} (have: ${dg(t).join(`, `)})`}const hg=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`[^`]*`/g;function*gg(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 _g=`[A-Za-z_]\\w*(?:\\.[A-Za-z_]\\w*)*`,vg=RegExp(`^(?:(\\$)(?:\\.(${_g}))?|\\.(${_g})?)(?=[\\s)]|$)`);function yg(e,t,n){let r=vg.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 bg=/^(\w+)\b\s*([\s\S]*)$/;function*xg(e,t){let n=[t];for(let r of gg(e)){let e=r.replace(/^-(?=\s)/,``).trim(),[,i=``,a=``]=bg.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:yg(r[1],s,t);continue}yield{code:e,dot:o},i===`if`&&n.push(o),i===`with`&&n.push(yg(a,o,t)),(i===`range`||i===`define`||i===`block`)&&n.push(null)}}const Sg=/(?<![.$])\btemplate\s+$/;function*Cg(e,t,n){let r=0;for(let i of[...e.matchAll(hg)]){let a=i.index+i[0].length;Sg.test(e.slice(r,i.index))&&(yield{name:i[0].slice(1,-1),at:yg(e.slice(a),t,n)}),r=a}}function*wg(e,t){let n=new Set;function*r(e,i,a,o){for(let{code:s,dot:c}of[...xg(e,i)]){yield{code:s,dot:c,root:i,via:a};for(let e of[...Cg(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 Tg=RegExp(`(?<![A-Za-z0-9_)$])(\\$?)\\.(${_g})`,`g`);function*Eg({code:e,dot:t,root:n}){let r=e.replace(hg,``);for(let e of[...r.matchAll(Tg)]){let r=e[1]===`$`?n:t;r!==null&&(yield`${r}${e[2]}`)}}function Dg(e,t){let n=new Map;for(let r of wg(e,t))for(let e of Eg(r))n.has(e)||n.set(e,r.via);return n}const Og=/(?<![.$])\b(action|picker|menu|carousel|swatches|swatch|themePreview)\s+$/,kg={action:1,picker:2,menu:1,carousel:2,swatch:1,swatches:2,themePreview:1};function*Ag(e){let t=0,n=0,r=0,i=`action`;for(let a of[...e.matchAll(hg)]){let o=e.slice(t,a.index),s=Og.exec(o);if(s!==null)n=kg[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 jg(e,t){let n=new Map;for(let{code:r,via:i}of wg(e,t))for(let{name:e,site:t}of Ag(r)){let r=`${e}\0${i??`\0`}`;n.has(r)||n.set(r,{name:e,site:t,via:i})}return[...n.values()]}function Mg(e,t){return new Set([...Ng(e,t)].filter(e=>Object.hasOwn(t,e)))}function Ng(e,t){let n=new Set;for(let{code:r,dot:i,root:a}of wg(e,t))for(let{name:e}of Cg(r,i,a))n.add(e);return n}function Pg(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 Fg(e){let t=new Set,n=new Set,r=(e,r)=>{t.add(e),Ig(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 Ig(e){return e.kind===`dropped`||(e.kind===`shell`||e.kind===`file`)&&Eh(e.parse)===`json`}function Lg(e){let t=l.basename(e),n=l.dirname(e);for(;;){let r=Rg(n);if(r!==null)return{dir:r,name:t,leaf:n===l.dirname(e)};t=l.basename(n),n=l.dirname(n)}}function Rg(e){try{return r.statSync(e).isDirectory()?r.realpathSync(e):null}catch{return null}}var zg=ye((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()===Bt}function s(e){let t=e?.constructor;return!!t&&(t.name===`GeneratorFunction`||t.displayName===`GeneratorFunction`)}function c(e,t,n){It(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 Lt.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=Vt,n=Vt){let r=new Wt(e);return t!==Vt&&(r.onBOL=new Set([t])),n!==Vt&&(r.onBUOL=new Set([n])),r}function _(e,t){return At(e,t)}function v(e,t,n){return e===null||typeof e!=`object`&&typeof e!=`function`||tt(e)?e:Array.isArray(e)?sn.array(e,{name:n}):o(e)?sn.object(e,void 0,{name:n}):u(e)?sn.map(e,{name:n}):d(e)?sn.set(e,{name:n}):typeof e!=`function`||We(e)||Qe(e)?e:s(e)?Wn(e):In(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:We(n.value)?1:(It(r,t,ee(e,this,t,n,!1)),2)}function S(e,t,n,r){let i=ee(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 ye(s.i?.name??a.toString(),e,(t=s.i?.autoAction)!=null&&t)};return i==`field`?function(e){var t;let n=e;return We(n)||(n=c(n)),(t=s.i)!=null&&t.bound&&(n=n.bind(this),n.isMobxAction=!0),n}:i==`method`?(We(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 ee(e,t,n,r,i=P.safeDescriptors){var a,o,s;let{value:c}=r;return(a=t.i)!=null&&a.bound&&(c=c.bind(e.v??e.h)),{value:ye(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 te(e,t){return{t:e,i:t,o:ne,u:re}}function ne(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)||!Qe(e.h[t]))&&this.u(e,t,n,!1)===null?0:Qe(n.value)?1:(It(r,t,ae(e,0,0,n,!1,!1)),2)}function re(e,t,n,r){let i=ae(e,0,0,n,this.i?.bound);return e.l(t,i,r)}function ie(e,t,n){var r;let{name:i,addInitializer:a}=n;return Qe(t)||(t=Wn(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 ae(e,t,n,r,i,a=P.safeDescriptors){let{value:o}=r;return Qe(o)||(o=Wn(o)),i&&(o=o.bind(e.v??e.h),o.isMobXFlow=!0),{value:o,configurable:!a||e.p,enumerable:!1,writable:!a}}function w(e,t){return{t:e,i:t,o:T,u:oe}}function T(e,t,n){return this.u(e,t,n,!1)===null?0:1}function oe(e,t,n,r){return e.m(t,Ft({},this.i,{get:n.get,set:n.set}),r)}function E(e,t,n){function r(e){let n=Ft({},i.i,{get:t,context:e});return n.name||=`ObservableObject.${a.toString()}`,new yn(n)}let i=e,{name:a,addInitializer:o}=n,s;return o(function(){let e=Ct(this)[j],n=this,i=e.j.get(a);i instanceof yn&&i.derivation!==t&&e.j.delete(a),(e.O??=new Map).set(a,()=>r(n))}),function(){let e=this[j],n=e.j.get(a);if(n instanceof yn&&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 se(e,t){return{t:e,i:t,o:ce,u:le}}function ce(e,t,n){return this.u(e,t,n,!1)===null?0:1}function le(e,t,n,r){return e.S(t,n.value,this.i?.A??v,r)}function ue(e,t,n){function r(e,t){let n=Ct(e)[j];return(n.V??=new Map).set(o,()=>new _n(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[j]??r(this,t.get.call(this)))._(o)},set(e){return(this[j]??r(this,e)).M(o,e)},init(e){return r(this,e),e}}}function de(e){return{t:Jt,i:e,o:fe,u:pe}}function fe(e,t,n,r){var i,a,o;if(n.get)return dn.o(e,t,n,r);if(n.set){let i=We(n.set)?n.set:ye(t.toString(),n.set);return r===e.h?e.l(t,{configurable:!P.safeDescriptors||e.p,set:i})===null?0:2:(It(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?Gn:Wn).o(e,t,n,r):((a=this.i)!=null&&a.autoBind?Rn:In).o(e,t,n,r);let c=!1===this.i?.deep?nn:sn;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 pe(e,t,n,r){var i;return n.get?dn.u(e,t,n,r):n.set?e.l(t,{configurable:!P.safeDescriptors||e.p,set:ye(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?nn:sn).u(e,t,n,r))}function me(e,t){return Ft(function(n,r){if(r&&typeof r.kind==`string`)return t(e,n,r)},e)}function he(e){return e||Xt}function ge(e){return me(e,ue)}function _e(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 ve(e){return me(e,E)}function ye(e,t,n=!1,r){function i(){return be(0,n,t,r||this,arguments)}return i.isMobxAction=!0,i.toString=()=>t.toString(),hn&&(gn.value=e,It(i,`name`,gn)),i}function be(e,t,n,r,i){let a=xe(0,t);try{return n.apply(r,i)}catch(e){throw a.N=e,e}finally{D(a)}}function xe(e,t){let n=P.trackingDerivation,r=!t||!n;Pe();let i=P.allowStateChanges;r&&Oe();let a={R:r,k:n,C:i,I:P.allowStateReads,P:!1,T:0,B:mn++,D:pn};return pn=a.B,a}function D(e){pn!==e.B&&t(30),pn=e.D,e.N!==void 0&&(P.suppressReactionErrors=!0),Fe(),e.R&&ke(e.k),P.suppressReactionErrors=!1}function Se(e,t){let n=function(e){let t=P.allowStateChanges;return P.allowStateChanges=e,t}(e);try{return t()}finally{(function(e){P.allowStateChanges=e})(n)}}function Ce(e){return e instanceof bn}function we(e){switch(e.K){case 0:return!1;case-1:case 2:return!0;case 1:{let t=Oe(),n=e.L,r=n.length;for(let i=0;i<r;i++){let r=n[i];if(N(r)){if(P.disableErrorBoundaries)r.get();else try{r.get()}catch{return ke(t),!0}if(e.K===2)return ke(t),!0}}return Ae(e),ke(t),!1}}}function Te(e,t,n){Ae(e),e.$=Array(e.U===0?100:e.L.length),e.W=0,e.U=++P.runId;let r=P.trackingDerivation,i;if(P.trackingDerivation=e,P.inBatch++,!0===P.disableErrorBoundaries)i=t.call(n);else try{i=t.call(n)}catch(e){i=new bn(e)}return P.inBatch--,P.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&&Me(n,e),n.diffValue=0}for(;i--;){let t=n[i];t.diffValue===1&&(t.diffValue=0,je(t,e))}r!==0&&(e.K=r,e.q())}(e),i}function Ee(e){let t=e.L;e.L=[];let n=t.length;for(;n--;)Me(t[n],e);e.K=-1}function De(e){let t=Oe();try{return e()}finally{ke(t)}}function Oe(){let e=P.trackingDerivation;return P.trackingDerivation=null,e}function ke(e){P.trackingDerivation=e}function Ae(e){if(e.K===0)return;e.K=0;let t=e.L,n=t.length;for(;n--;)t[n].F=0}function je(e,t){(e.H??=new Set).add(t),e.F>t.K&&(e.F=t.K)}function Me(e,t){let n=e.H;n&&(n.delete(t),n.size===0&&Ne(e))}function Ne(e){!1===e.isPendingUnobservation&&(e.isPendingUnobservation=!0,P.pendingUnobservations.push(e))}function Pe(){P.inBatch++}function Fe(){--P.inBatch===0&&(ze(),!P.isRunningUnobservations&&P.pendingUnobservations.length>0&&function(){P.isRunningUnobservations=!0;try{let e=P.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 yn&&n.G())}P.pendingUnobservations=[]}finally{P.isRunningUnobservations=!1}}())}function Ie(e){var t;e.isBeingObserved||(e.isBeingObserved=!0,e.onBO(),(t=e.L)==null||t.forEach(Ie))}function Le(e){let t=P.trackingDerivation;return t===null?((!e.H||e.H.size===0)&&P.inBatch>0&&Ne(e),!1):(t.U!==e.J&&(e.J=t.U,t.$[t.W++]=e,!e.isBeingObserved&&P.trackingContext&&(e.isBeingObserved=!0,e.onBO())),e.isBeingObserved)}function Re(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 ze(){P.inBatch>0||P.isRunningReactions||Dn(Be)}function Be(){P.isRunningReactions=!0;let e=P.pendingReactions,t=0;for(;e.length>0;){++t===En&&(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()}P.isRunningReactions=!1}function Ve(e){return me(e,C)}function He(e){return function(t,n){return n&&typeof n.kind==`string`?C(e?Nn:jn,t,n):r(t)?ye(t.name||`<unnamed action>`,t,e):r(n)?ye(t,n,e):i(t)?Ve(b(e?An:kn,{name:t,autoAction:e})):void 0}}function Ue(e){return be(0,!1,e,this,void 0)}function We(e){return r(e)&&!0===e.isMobxAction}function Ge(e,t=zt){function n(){e(a)}var r;let i=t?.name??`Autorun`,a;if(t.scheduler||t.delay){let e=Ke(t),r=!1;a=new Tn(i,()=>{r||(r=!0,e(()=>{r=!1,a.isDisposed||a.track(n)}))},t.onError,t.requiresObservable)}else a=new Tn(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 Ke(e){return e.scheduler?e.scheduler:e.delay?t=>setTimeout(t,e.delay):zn}function qe(e,t,n,i){let a=typeof i==`function`?Et(t,n):Et(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 Je(e,t,n,r){let i=Ut(t);return kt(()=>{let t=Ct(e,r)[j];Ht(i).forEach(e=>{t.u(e,i[e],!n||!(e in n)||n[e])})}),e}function Ye(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(Ye)),t}function Xe(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),Xe)),t}function Ze(e){r(e.cancel)&&e.cancel()}function Qe(e){return!0===e?.isMobXFlow}function $e(e,t){var n;if(t===void 0)return N(e);if(!1===Tt(e))return!1;let r=e[j];return(n=r.O)!=null&&n.has(t)?!0:r.j.has(t)?N(Et(e,t)):!1}function et(e,t){if(!e)return!1;if(t!==void 0){if(Tt(e)){var n,r;let i=e[j];return i.j.has(t)||!((n=i.O)==null||!n.has(t))||!((r=i.V)==null||!r.has(t))}return!1}return Tt(e)||!!e[j]||Gt(e)||On(e)||N(e)}function tt(e){return et(e)}function nt(e){return Tt(e)?e[j].nt():rr(e)||or(e)?Array.from(e.keys()):bt(e)?e.map((e,t)=>t):void t(5)}function rt(e,n){return Tt(e)?e[j].et(n):rr(e)||or(e)?e.has(n):bt(e)?n>=0&&n<e.length:void t(10)}function it(e){if(Tt(e))return e[j].it();t(38)}function at(e,t,n){if(N(e)){let r,i=!0;return Ge(()=>{let a=e.get();if(!i||n){let n=Oe();t({observableKind:`computed`,debugObjectName:e.tt,type:Yn,object:e,newValue:a,oldValue:r}),ke(n)}i=!1,r=a})}return n&&t({observableKind:`value`,debugObjectName:e.tt,object:e,type:Yn,newValue:e.rt,oldValue:void 0}),mt(e,t)}function ot(e,t,n){return e.set(t,n),n}function st(e,t){if(typeof e!=`object`||!e||e instanceof Date||!tt(e))return e;if(vn(e)||N(e))return st(e.get(),t);if(t.has(e))return t.get(e);if(bt(e)){let n=ot(t,e,Array(e.length));return e.forEach((e,r)=>{n[r]=st(e,t)}),n}if(or(e)){let n=ot(t,e,new Set);return e.forEach(e=>{n.add(st(e,t))}),n}if(rr(e)){let n=ot(t,e,new Map);return e.forEach((e,r)=>{n.set(r,st(e,t))}),n}{let n=ot(t,e,{});return it(e).forEach(r=>{Lt.propertyIsEnumerable.call(e,r)&&(n[r]=st(e[r],t))}),n}}function ct(e,t){Pe();try{return e.apply(t)}finally{Fe()}}function lt(e,t,n){let r;if(typeof n.timeout==`number`){let e=Error(`WHEN_TIMEOUT`);r=setTimeout(()=>{if(!a[j].isDisposed){if(a(),!n.onError)throw e;n.onError(e)}},n.timeout)}n.name=`When`;let i=ye(`When-effect`,t);var a=Ge(t=>{Se(!1,e)&&(t.dispose(),r&&clearTimeout(r),i())},n);return a}function ut(e){return e[j]}function dt(e){return e.st!==void 0&&e.st.length>0}function ft(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 O(e,n){let r=Oe();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{ke(r)}}function pt(e){return e.ot!==void 0&&e.ot.length>0}function mt(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 ht(e,t){let n=Oe(),r=e.ot;if(r){r=r.slice();for(let e=0,n=r.length;e<n;e++)r[e](t);ke(n)}}function gt(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!==Lt;){let t=A(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 k(e,t){typeof Array.prototype[e]==`function`&&(Qn[e]=t(e))}function _t(e){return function(){let t=this[j];t.ct.reportObserved();let n=t.ht(t.j);return n[e].apply(n,arguments)}}function vt(e){return function(t,n){let r=this[j];return r.ct.reportObserved(),r.ht(r.j)[e]((e,r)=>t.call(n,e,r,this))}}function yt(e){return function(){let t=this[j];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 bt(e){return a(e)&&$n(e[j])}function xt(e){return e[Symbol.toStringTag]=`MapIterator`,Nt(e)}function St(e){return e[Symbol.toStringTag]=`SetIterator`,Nt(e)}function Ct(e,t){if(p(e,j))return e;let n=t?.name??`ObservableObject`;return c(e,j,new lr(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 M[r]??(M[r]=de({deep:t,autoBind:n}))}(e):void 0}(t))),e}function wt(e){return sr[e]||(sr[e]={get(){return this[j]._(e)},set(t){return this[j].M(e,t)}})}function Tt(e){return!!a(e)&&ur(e[j])}function Et(e,n){if(typeof e==`object`&&e){if(bt(e))return n!==void 0&&t(23),e[j].ct;if(or(e))return e.ct;if(rr(e)){if(n===void 0)return e.lt;let r=e.ft.get(n)||e.dt.get(n);return r||t(25,n,Ot(e)),r}if(Tt(e)){if(!n)return t(26);let r=e[j],i=r.j.get(n)??r.vt(n)??r.bt(n);return i||t(27,n,Ot(e)),i}if(Gt(e)||N(e)||On(e))return e}else if(r(e)&&On(e[j]))return e[j];t(28)}function Dt(e,n){return e||t(29),n===void 0?Gt(e)||N(e)||On(e)||rr(e)||or(e)?e:e[j]?e[j]:void t(24,e):Dt(Et(e,n))}function Ot(e,t){let n;if(t!==void 0)n=Et(e,t);else{if(We(e))return e.name;n=Tt(e)||rr(e)||or(e)?Dt(e):Et(e)}return n.tt}function kt(e){let t=Oe();Pe();try{return e()}finally{Fe(),ke(t)}}function At(e,t,n=-1){return jt(e,t,n)}function jt(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=dr.call(e);if(s!==dr.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=Mt(e),t=Mt(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(!jt(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)||!jt(e[o],t[o],n-1,i,a))return!1}}return i.pop(),a.pop(),!0}function Mt(e){return bt(e)?e.slice():u(e)||rr(e)||d(e)||or(e)?Array.from(e.entries()):e}function Nt(e){return e[Symbol.iterator]=Pt,Ft(Object.create(fr),e)}function Pt(){return this}Object.defineProperty(e,`__esModule`,{value:!0});let Ft=Object.assign,A=Object.getOwnPropertyDescriptor,It=Object.defineProperty,Lt=Object.prototype,Rt=[];Object.freeze(Rt);let zt={};Object.freeze(zt);let Bt=Object.toString(),Vt=()=>{},Ht=Reflect.ownKeys,Ut=Object.getOwnPropertyDescriptors,j=Symbol(`mobx administration`);var Wt=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 Le(this)}reportChanged(){Pe(),Re(this),Fe()}toString(){return this.tt}};let Gt=l(`Atom`,Wt),Kt=Object.is,qt={t:`override`,o:function(){return 0},u:function(){t(44,this.t)}},Jt=`true`,Yt=de(),M=[Yt],Xt={deep:!0,name:void 0,defaultDecorator:void 0};Object.freeze(Xt);let Zt=se(`observable`),Qt=se(`observable.ref`,{A:y}),$t=se(`observable.shallow`,{A:function(e,t,n){return e==null||Tt(e)||bt(e)||rr(e)||or(e)?e:Array.isArray(e)?sn.array(e,{name:n,deep:!1}):o(e)?sn.object(e,void 0,{name:n,deep:!1}):u(e)?sn.map(e,{name:n,deep:!1}):d(e)?sn.set(e,{name:n,deep:!1}):void 0}}),en=se(`observable.struct`,{A:function(e,t){return At(e,t)?t:e}}),tn={box(e,t){let n=he(t);return new _n(e,_e(n),n.name,!0,n.equals)},array(e,t){let n=he(t);return function(e,t,n=`ObservableArray`,r=!1){return kt(()=>{let i=new Zn(n,t,r);It(i.j,j,{enumerable:!1,writable:!1,configurable:!0,value:i});let a=new Proxy(i.j,Xn);return i.v=a,e&&e.length&&i.wt(0,0,e),a})}(e,_e(n),n.name)},map(e,t){let n=he(t);return new nr(e,_e(n),n.name)},set(e,t){let n=he(t);return new ar(e,_e(n),n.name)},object:(e,t,n)=>kt(()=>Je(function(e,t){var n;return(n=(e=Ct(e,t))[j]).v??(n.v=new Proxy(e,Kn))}({},n),e,t))},nn=ge(Qt),rn=ge($t),an=ge(Zt),on=ge(en);var sn=Ft(function(e,t,n){return t&&typeof t.kind==`string`?ue(Zt,e,t):tt(e)?e:o(e)?sn.object(e,t,n):Array.isArray(e)?sn.array(e,t):u(e)?sn.map(e,t):d(e)?sn.set(e,t):typeof e==`object`&&e?e:sn.box(e,t)},Zt,tn);let cn=`computed`,ln=w(cn),un=ve(w(`computed.struct`,{equals:_})),dn=function(e,t){if(t&&typeof t.kind==`string`)return E(ln,e,t);if(o(e))return ve(w(cn,e));let n=o(t)?t:{};return n.get=e,n.name||=e.name||``,new yn(n)};var fn;Ft(dn,ln);let pn=0,mn=1,hn=(fn=A(()=>{},`name`)?.configurable)!=null&&fn,gn={value:`action`,configurable:!0,writable:!1,enumerable:!1};var _n=class extends Wt{constructor(e,t,n=`ObservableValue`,r=!0,i=Kt){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))!==P.UNCHANGED&&this.Ot(e)}jt(e){if(dt(this)){let t=O(this,{object:this,type:Yn,newValue:e});if(!t)return P.UNCHANGED;e=t.newValue}return e=this.A(e,this.rt,this.tt),this.xt(this.rt,e)?P.UNCHANGED:e}Ot(e){let t=this.rt;this.rt=e,this.reportChanged(),pt(this)&&ht(this,{type:Yn,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 vn=l(`ObservableValue`,_n);var yn=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 bn(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=ye(`ComputedValue-setter`,e.set)),this.xt=e.equals||Kt,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),P.inBatch!==0||this.H&&this.H.size!==0||this.Mt){let e=this.isBeingObserved;if(Le(this),we(this)){let e=P.trackingContext;e||!this.Mt&&!this.isBeingObserved||(P.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),P.trackingContext=e}else !e&&this.isBeingObserved&&this.L.forEach(Ie)}else we(this)&&(this.Nt(),Pe(),this.rt=this.Rt(!1),Fe());let e=this.rt;if(Ce(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||Ce(e)||Ce(n)||!this.xt(e,n);return r&&(this.rt=n),r}Rt(e){let t;if(this.isComputing=!0,e)t=Te(this,this.derivation,this.At);else if(!0===P.disableErrorBoundaries)t=this.derivation.call(this.At);else try{t=this.derivation.call(this.At)}catch(e){t=new bn(e)}return this.isComputing=!1,t}G(){this.Mt||(Ee(this),this.rt=void 0)}Nt(){}toString(){return`${this.tt}[${this.derivation.toString()}]`}valueOf(){return f(this.get())}[Symbol.toPrimitive](){return this.valueOf()}};let N=l(`ComputedValue`,yn);var bn=class{constructor(e){this.cause=void 0,this.cause=e}};let xn=[`mobxGuid`,`spyListeners`,`enforceActions`,`computedRequiresReaction`,`reactionRequiresObservable`,`observableRequiresReaction`,`allowStateReads`,`disableErrorBoundaries`,`runId`,`UNCHANGED`];var Sn=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 Cn=!0,wn=!1,P=function(){let e=globalThis;return e.__mobxInstanceCount>0&&!e.__mobxGlobals&&(Cn=!1),e.__mobxGlobals&&e.__mobxGlobals.version!==7&&(Cn=!1),Cn?e.__mobxGlobals?(e.__mobxInstanceCount+=1,e.__mobxGlobals.UNCHANGED||(e.__mobxGlobals.UNCHANGED={}),e.__mobxGlobals):(e.__mobxInstanceCount=1,e.__mobxGlobals=new Sn):(setTimeout(()=>{wn||t(35)},1),new Sn)}();var Tn=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,P.pendingReactions.push(this),ze())}X(){if(!this.isDisposed){Pe(),this.isScheduled=!1;let e=P.trackingContext;if(P.trackingContext=this,we(this)){this.isTrackPending=!0;try{this.Et()}catch(e){this.Pt(e)}}P.trackingContext=e,Fe()}}track(e){if(this.isDisposed)return;Pe(),this.isRunning=!0;let t=P.trackingContext;P.trackingContext=this;let n=Te(this,e,void 0);P.trackingContext=t,this.isRunning=!1,this.isTrackPending=!1,this.isDisposed&&Ee(this),Ce(n)&&this.Pt(n.cause),Fe()}Pt(e){if(this.kt)this.kt(e,this);else{if(P.disableErrorBoundaries)throw e;P.suppressReactionErrors||console.error(`[mobx] uncaught error in '${this}'`,e),P.globalReactionErrorHandlers.forEach(t=>t(e,this))}}dispose(){var e;this.isDisposed||(this.isDisposed=!0,(e=this.It)==null||e.call(this),this.isRunning||(Pe(),Ee(this),Fe()))}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[j]=this,`dispose`in Symbol&&typeof Symbol.dispose==`symbol`&&(t[Symbol.dispose]=t),t}toString(){return`Reaction[${this.tt}]`}};let En=100,Dn=e=>e(),On=l(`Reaction`,Tn),kn=`action`,An=`autoAction`,jn=b(kn),Mn=b(`action.bound`,{bound:!0}),Nn=b(An,{autoAction:!0}),Pn=b(`autoAction.bound`,{autoAction:!0,bound:!0}),Fn=He(!1);Ft(Fn,jn);let In=He(!0);Ft(In,Nn);let Ln=Ve(Mn),Rn=Ve(Pn),zn=e=>e(),Bn=`always`;var Vn=class extends Error{constructor(){super(`FLOW_CANCELLED`),Object.setPrototypeOf(this,new.target.prototype),this.name=`FlowCancellationError`}toString(){return`Error: ${this.message}`}};let Hn=te(`flow`),Un=te(`flow.bound`,{bound:!0}),Wn=Ft(function(e,t){if(t&&typeof t.kind==`string`)return ie(Hn,e,t);let n=e,i=n.name||`flow`,a=function(){let e=arguments,t=Fn(i,n).apply(this,e),a,o,s=new Promise(function(e,n){function s(e){let r;o=void 0;try{r=Fn(i,t.next).call(t,e)}catch(e){return n(e)}l(r)}function c(e){let r;o=void 0;try{r=Fn(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=Fn(i,function(){try{o&&Ze(o);let e=t.return(void 0),n=Promise.resolve(e.value);n.then(Vt,Vt),Ze(n),a(new Vn)}catch(e){a(e)}}),s};return a.isMobXFlow=!0,a},Hn),Gn=me(Un,ie),Kn={has:(e,t)=>ut(e).et(t),get:(e,t)=>ut(e).Tt(t),set(e,t,n){var r;return!!i(t)&&((r=ut(e).Bt(t,n,!0))==null||r)},deleteProperty(e,t){var n;return!!i(t)&&((n=ut(e).Dt(t,!0))==null||n)},defineProperty(e,t,n){var r;return(r=ut(e).l(t,n))==null||r},ownKeys:e=>ut(e).it(),preventExtensions(e){t(13)}},qn=Symbol(`mobx-keys`),Jn=`splice`,Yn=`update`,Xn={get(e,t){let n=e[j];return t===j?n:t===`length`?n.Kt():typeof t!=`string`||isNaN(t)?p(Qn,t)?Qn[t]:e[t]:n.Tt(parseInt(t))},set(e,t,n){let r=e[j];return t===`length`?r.Lt(n):typeof t==`symbol`||isNaN(t)?e[t]=n:r.Bt(parseInt(t),n),!0},preventExtensions(){t(15)}};var Zn=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 Wt(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=Rt),dt(this)){let r=O(this,{object:this.v,type:Jn,index:e,removedCount:t,added:n});if(!r)return Rt;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=pt(this),i=r?{observableKind:`array`,object:this.v,type:Yn,debugObjectName:this.ct.tt,index:e,newValue:t,oldValue:n}:null;this.ct.reportChanged(),r&&ht(this,i)}Ft(e,t,n){let r=pt(this),i=r?{observableKind:`array`,object:this.v,debugObjectName:this.ct.tt,type:Jn,index:e,removed:n,added:t,removedCount:n.length,addedCount:t.length}:null;this.ct.reportChanged(),r&&ht(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(dt(this)){let n=O(this,{type:Yn,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)}}},Qn={clear(){return this.splice(0)},replace(e){let t=this[j];return t.wt(0,t.j.length,e)},toJSON(){return this.slice()},splice(e,t,...n){let r=this[j];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[j].wt(e,t,n)},push(...e){let t=this[j];return t.wt(t.j.length,0,e),t.j.length},pop(){return this.splice(Math.max(this[j].j.length-1,0),1)[0]},shift(){return this.splice(0,1)[0]},unshift(...e){let t=this[j];return t.wt(0,0,e),t.j.length},reverse(){return P.trackingDerivation&&t(37,`reverse`),this.replace(this.slice().reverse()),this},sort(){P.trackingDerivation&&t(37,`sort`);let e=this.slice();return e.sort.apply(e,arguments),this.replace(e),this},remove(e){let t=this[j],n=t.ht(t.j).indexOf(e);return n>-1&&(this.splice(n,1),!0)}};k(`at`,_t),k(`concat`,_t),k(`flat`,_t),k(`includes`,_t),k(`indexOf`,_t),k(`join`,_t),k(`lastIndexOf`,_t),k(`slice`,_t),k(`toString`,_t),k(`toLocaleString`,_t),k(`toSorted`,_t),k(`toSpliced`,_t),k(`with`,_t),k(`every`,vt),k(`filter`,vt),k(`find`,vt),k(`findIndex`,vt),k(`findLast`,vt),k(`findLastIndex`,vt),k(`flatMap`,vt),k(`forEach`,vt),k(`map`,vt),k(`some`,vt),k(`toReversed`,vt),k(`reduce`,yt),k(`reduceRight`,yt);let $n=l(`ObservableArrayAdministration`,Zn),er={},tr=`delete`;var nr=class{constructor(e,t=v,n=`ObservableMap`){this.A=void 0,this.tt=void 0,this[j]=er,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,kt(()=>{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(!P.trackingDerivation)return this.et(e);let t=this.dt.get(e);if(!t){let n=t=new _n(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(dt(this)){let r=O(this,{type:n?Yn:`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(dt(this)&&!O(this,{type:tr,object:this,name:e}))return!1;if(this.et(e)){let t=pt(this),n=t?{observableKind:`map`,debugObjectName:this.tt,type:tr,object:this,oldValue:this.ft.get(e).rt,name:e}:null;return ct(()=>{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&&ht(this,n),!0}return!1}Gt(e,t){let n=this.ft.get(e);if((t=n.jt(t))!==P.UNCHANGED){let r=pt(this),i=r?{observableKind:`map`,debugObjectName:this.tt,type:Yn,object:this,oldValue:n.rt,name:e,newValue:t}:null;n.Ot(t),r&&ht(this,i)}}Jt(e,t){ct(()=>{var n;let r=new _n(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=pt(this);n&&ht(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 xt({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 xt({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 rr(e)&&(e=new Map(e)),ct(()=>{o(e)?function(e){let t=Object.keys(e),n=Object.getOwnPropertySymbols(e);return n.length?[...t,...n.filter(t=>Lt.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(){ct(()=>{De(()=>{for(let e of this.keys())this.delete(e)})})}replace(e){return ct(()=>{let n=function(e){if(u(e)||rr(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`}},rr=l(`ObservableMap`,nr);let ir={};var ar=class{constructor(e,t=v,n=`ObservableSet`){this.tt=void 0,this[j]=ir,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),kt(()=>{this.ct=g(this.tt),e&&this.replace(e)})}Wt(e){return this.dehancer===void 0?e:this.dehancer(e)}clear(){ct(()=>{De(()=>{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(dt(this)){let t=O(this,{type:`add`,object:this,newValue:e});if(!t)return this;e=t.newValue}if(!this.has(e)){ct(()=>{e=this.A(e,void 0),this.ft.add(e),this.ct.reportChanged()});let t=pt(this);t&&ht(this,t?{observableKind:`set`,debugObjectName:this.tt,type:`add`,object:this,newValue:e}:null)}return this}delete(e){if(dt(this)&&!O(this,{type:tr,object:this,oldValue:e}))return!1;if(this.has(e)){let t=pt(this),n=t?{observableKind:`set`,debugObjectName:this.tt,type:tr,object:this,oldValue:e}:null;return ct(()=>{this.ct.reportChanged(),this.ft.delete(e)}),t&&ht(this,n),!0}return!1}has(e){return this.ct.reportObserved(),this.ft.has(this.Wt(e))}entries(){let e=this.values();return St({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 St({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 or(e)&&(e=new Set(e)),Array.isArray(e)||d(e)?ct(()=>{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`}},or=l(`ObservableSet`,ar);let sr=Object.create(null),cr=`remove`;var lr=class{constructor(e,t=new Map,n,r=Yt){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 Wt(`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 yn)return n.set(t),!0;if(dt(this)){let n=O(this,{type:Yn,object:this.v||this.h,name:e,newValue:t});if(!n)return null;t=n.newValue}if((t=n.jt(t))!==P.UNCHANGED){let r=pt(this),i=r?{type:Yn,observableKind:`object`,debugObjectName:this.tt,object:this.v||this.h,oldValue:n.rt,name:e,newValue:t}:null;n.Ot(t),r&&ht(this,i)}return!0}Tt(e){return P.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(!P.trackingDerivation)return e in this.h;this.Qt||=new Map;let t=this.Qt.get(e);return t||(t=new _n(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{Pe();let r=this.Dt(e);if(!r)return r;if(dt(this)){let n=O(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=Ft({},t,{value:r}))}if(n){if(!Reflect.defineProperty(this.h,e,t))return!1}else It(this.h,e,t);this.Yt(e,t.value)}finally{Fe()}return!0}S(e,t,n,r=!1){try{Pe();let i=this.Dt(e);if(!i)return i;if(dt(this)){let n=O(this,{object:this.v||this.h,name:e,type:`add`,newValue:t});if(!n)return null;t=n.newValue}let a=wt(e),o={configurable:!P.safeDescriptors||this.p,enumerable:!0,get:a.get,set:a.set};if(r){if(!Reflect.defineProperty(this.h,e,o))return!1}else It(this.h,e,o);let s=new _n(t,n,`ObservableObject.key`,!1);this.j.set(e,s),this.Yt(e,s.rt)}finally{Fe()}return!0}m(e,t,n=!1){try{Pe();let r=this.Dt(e);if(!r)return r;if(dt(this)&&!O(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=wt(e),a={configurable:!P.safeDescriptors||this.p,enumerable:!1,get:i.get,set:i.set};if(n){if(!Reflect.defineProperty(this.h,e,a))return!1}else It(this.h,e,a);this.j.set(e,new yn(t)),this.Yt(e,void 0)}finally{Fe()}return!0}Dt(e,t=!1){if(!p(this.h,e))return!0;if(dt(this)&&!O(this,{object:this.v||this.h,name:e,type:cr}))return null;try{var n;Pe();let r=pt(this),i=this.j.get(e),a;if(i||!r||(a=A(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 _n&&(a=i.rt),Re(i)),this.lt.reportChanged(),(n=this.Qt)==null||(n=n.get(e))==null||n.set(e in this.h),r&&r&&ht(this,{type:cr,observableKind:`object`,object:this.v||this.h,debugObjectName:this.tt,oldValue:a,name:e})}finally{Fe()}return!0}Yt(e,t){var n;let r=pt(this);r&&r&&ht(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(),Ht(this.h)}nt(){return this.lt.reportObserved(),Object.keys(this.h)}};let ur=l(`ObservableObjectAdministration`,lr),dr=Lt.toString,fr=globalThis.Iterator?.prototype||{};e.$mobx=j,e.FlowCancellationError=Vn,e.ObservableMap=nr,e.ObservableSet=ar,e.Reaction=Tn,e._allowStateChanges=Se,e._allowStateChangesInsideComputed=Ue,e._allowStateReadsEnd=function(e){P.allowStateReads=e},e._allowStateReadsStart=function(e){let t=P.allowStateReads;return P.allowStateReads=e,t},e._autoAction=In,e._autoActionBound=Rn,e._endAction=D,e._getAdministration=Dt,e._getGlobalState=function(){return P},e._interceptReads=function(e,t,n){let r;return rr(e)||bt(e)||vn(e)?r=Dt(e):Tt(e)&&(r=Dt(e,t)),r.dehancer=typeof t==`function`?t:n,()=>{r.dehancer=void 0}},e._isComputingDerivation=function(){return P.trackingDerivation!==null},e._resetGlobalState=function(){let e=new Sn;for(let t in e)xn.indexOf(t)===-1&&(P[t]=e[t]);P.allowStateChanges=!P.enforceActions},e._startAction=xe,e.action=Fn,e.actionBound=Ln,e.autorun=Ge,e.compareDefault=Kt,e.compareIdentity=function(e,t){return e===t},e.compareShallow=function(e,t){return At(e,t,1)},e.compareStructural=_,e.computed=dn,e.computedStruct=un,e.configure=function(e){!0===e.isolateGlobalState&&function(){if((P.pendingReactions.length||P.inBatch||P.isRunningReactions)&&t(36),wn=!0,Cn){let e=globalThis;--e.__mobxInstanceCount===0&&(e.__mobxGlobals=void 0),P=new Sn}}();let{enforceActions:n}=e;if(n!==void 0){let e=n===Bn?Bn:n===`observed`;P.enforceActions=e,P.allowStateChanges=!0!==e&&e!==Bn}[`computedRequiresReaction`,`reactionRequiresObservable`,`observableRequiresReaction`,`disableErrorBoundaries`,`safeDescriptors`].forEach(t=>{t in e&&(P[t]=!!e[t])}),P.allowStateReads=!P.observableRequiresReaction,e.reactionScheduler&&function(e){let t=Dn;Dn=n=>e(()=>t(n))}(e.reactionScheduler)},e.createAtom=g,e.defineProperty=function(e,n,r){if(Tt(e))return e[j].l(n,r);t(39)},e.entries=function(e){return Tt(e)?nt(e).map(t=>[t,e[t]]):rr(e)?nt(e).map(t=>[t,e.get(t)]):or(e)?Array.from(e.entries()):bt(e)?e.map((e,t)=>[t,e]):void t(7)},e.extendObservable=Je,e.flow=Wn,e.flowBound=Gn,e.flowResult=function(e){return e},e.get=function(e,n){if(rt(e,n))return Tt(e)?e[j].Tt(n):rr(e)?e.get(n):bt(e)?e[n]:void t(11)},e.getAtom=Et,e.getDebugName=Ot,e.getDependencyTree=function(e,t){return Ye(Et(e,t))},e.getObserverTree=function(e,t){return Xe(Et(e,t))},e.has=rt,e.intercept=function(e,t,n){return r(n)?function(e,t,n){return ft(Dt(e,t),n)}(e,t,n):function(e,t){return ft(Dt(e),t)}(e,t)},e.isAction=We,e.isBoxedObservable=vn,e.isComputed=function(e){return $e(e)},e.isComputedProp=function(e,t){return $e(e,t)},e.isFlow=Qe,e.isFlowCancellationError=function(e){return e instanceof Vn},e.isObservable=tt,e.isObservableArray=bt,e.isObservableMap=rr,e.isObservableObject=Tt,e.isObservableProp=function(e,t){return et(e,t)},e.isObservableSet=or,e.keys=nt,e.makeAutoObservable=function(e,t,n){return o(e)?Je(e,e,t,n):(kt(()=>{let r=Ct(e,n)[j];if(!e[qn]){let t=Object.getPrototypeOf(e),n=new Set([...Ht(e),...Ht(t)]);n.delete(`constructor`),n.delete(j),c(t,qn,n)}e[qn].forEach(e=>gt(r,e,!t||!(e in t)||t[e]))}),e)},e.makeObservable=function(e,t,n){return kt(()=>{let r=Ct(e,n)[j];Ht(t).forEach(e=>gt(r,e,t[e]))}),e},e.observable=sn,e.observableDeep=an,e.observableRef=nn,e.observableShallow=rn,e.observableStruct=on,e.observe=function(e,t,n,i){return r(n)?function(e,t,n,r){return at(Dt(e,t),n,r)}(e,t,n,i):function(e,t,n){let r=Dt(e);if(bt(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(!rr(e)&&!or(e)&&!Tt(e))return at(r,t,n);return mt(r,t)}(e,t,n)},e.onBecomeObserved=function(e,t,n){return qe(`onBO`,e,t,n)},e.onBecomeUnobserved=function(e,t,n){return qe(`onBUO`,e,t,n)},e.onReactionError=function(e){return P.globalReactionErrorHandlers.push(e),()=>{let t=P.globalReactionErrorHandlers.indexOf(e);t>=0&&P.globalReactionErrorHandlers.splice(t,1)}},e.override=qt,e.ownKeys=it,e.reaction=function(e,t,n=zt){function r(){if(p=!1,h.isDisposed)return;let t=!1,r=d;h.track(()=>{let n=Se(!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=Fn(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=Ke(n),d,f=!0,p=!1,m=n.equals||Kt,h=new Tn(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){Tt(e)?e[j].Dt(n):rr(e)||or(e)?e.delete(n):bt(e)?(typeof n!=`number`&&(n=parseInt(n,10)),e.splice(n,1)):t(9)},e.runInAction=Ue,e.set=function e(n,r,i){if(arguments.length===2&&!or(n)){Pe();let t=r;try{for(let r in t)e(n,r,t[r])}finally{Fe()}return}Tt(n)?n[j].Bt(r,i):rr(n)?n.set(r,i):or(n)?n.add(r):bt(n)?(typeof r!=`number`&&(r=parseInt(r,10)),r<0&&t(42,r),Pe(),r>=n.length&&(n.length=r+1),n[r]=i,Fe()):t(8)},e.spy=function(){return console.warn(`[mobx.spy] Is a no-op in production builds`),function(){}},e.toJS=function(e){return st(e,new Map)},e.transaction=ct,e.untracked=De,e.values=function(e){return Tt(e)?nt(e).map(t=>e[t]):rr(e)?nt(e).map(t=>e.get(t)):or(e)?Array.from(e.values()):bt(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 Ft(Promise.reject(Error(`WHEN_ABORTED`)),{cancel:()=>null});let r,i,a=new Promise((n,a)=>{var o;let s=lt(e,n,Ft({},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):lt(e,t,n||{})}})),Bg=ye((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++M.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=ie(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 ee(e){let t=Object.keys(e),n=Object.getOwnPropertySymbols(e);return n.length?[...t,...n.filter(t=>o.propertyIsEnumerable.call(e,t))]:t}let te=Reflect.ownKeys;function ne(e){return typeof e==`string`?e:typeof e==`symbol`?e.toString():new String(e).toString()}function re(e){return e===null?null:typeof e==`object`?``+e:e}function ie(e,t){return o.hasOwnProperty.call(e,t)}let ae=Object.getOwnPropertyDescriptors;function w(e,t){return!!(e&t)}function T(e,t,n){return n?e|=t:e&=~t,e}function oe(e,t){t.includes(e.kind)||n(`The decorator applied to '${String(e.name)}' cannot be used on a ${e.kind} element`)}let E=Symbol(`mobx administration`);var se=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 w(this.flags_,1)}set isBeingObserved(e){this.flags_=T(this.flags_,1,e)}get isPendingUnobservation(){return w(this.flags_,2)}set isPendingUnobservation(e){this.flags_=T(this.flags_,2,e)}get diffValue(){return+!!w(this.flags_,4)}set diffValue(e){this.flags_=T(this.flags_,4,e===1)}onBO(){this.onBOL&&this.onBOL.forEach(e=>e())}onBUO(){this.onBUOL&&this.onBUOL.forEach(e=>e())}reportObserved(){return ln(this)}reportChanged(){an(),un(this),on()}toString(){return this.name_}};let ce=b(`Atom`,se);function le(e,t=f,n=f){let r=new se(e);return t!==f&&(r.onBOL=new Set([t])),n!==f&&(r.onBUOL=new Set([n])),r}function ue(e,t){return e===t}function de(e,t){return Pi(e,t)}function fe(e,t){return Pi(e,t,1)}let pe=Object.is;function me(e,t,n){return e===null||typeof e!=`object`&&typeof e!=`function`||br(e)?e:Array.isArray(e)?O.array(e,{name:n}):g(e)?O.object(e,void 0,{name:n}):x(e)?O.map(e,{name:n}):C(e)?O.set(e,{name:n}):typeof e==`function`&&!Rn(e)&&!dr(e)?_(e)?sr(e):Pn(n,e):e}function he(e,t,r){if(e==null||Ei(e)||fi(e)||F(e)||vi(e))return e;if(Array.isArray(e))return O.array(e,{name:r,deep:!1});if(g(e))return O.object(e,void 0,{name:r,deep:!1});if(x(e))return O.map(e,{name:r,deep:!1});if(C(e))return O.set(e,{name:r,deep:!1});n(`The shallow modifier / decorator can only used in combination with arrays, objects, maps and sets`)}function ge(e){return e}function _e(e,t){return br(e)&&n(`observable.struct should not be used with observable values`),Pi(e,t)?t:e}let ve=`override`,ye={annotationType_:ve,make_:xe,extend_:D};function be(e){return e.annotationType_===ve}function xe(e,t){return e.isPlainObject_&&n(`Cannot apply '${this.annotationType_}' to '${e.name_}.${t.toString()}':\n'${this.annotationType_}' cannot be used on plain objects.`),ie(e.appliedAnnotations_,t)||n(`'${e.name_}.${t.toString()}' is annotated with '${this.annotationType_}', but no such annotated member was found on prototype.`),0}function D(e,t,r,i){n(44,this.annotationType_)}function Se(e,t){return{annotationType_:e,options_:t,make_:Ce,extend_:we}}function Ce(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:Rn(n.value)?1:(a(r,t,De(e,this,t,n,!1)),2)}function we(e,t,n,r){let i=De(e,this,t,n);return e.defineProperty_(t,i,r)}function Te(e,t,r){oe(r,[`method`,`field`]);let{kind:i,name:a,addInitializer:o}=r,s=e,c=e=>xt(s.options_?.name??a.toString(),e,s.options_?.autoAction??!1);if(i==`field`)return function(e){var t;let n=e;return Rn(n)||(n=c(n)),(t=s.options_)!=null&&t.bound&&(n=n.bind(this),n.isMobxAction=!0),n};if(i==`method`){var l;return Rn(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 Ee(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 De(e,t,n,r,i=M.safeDescriptors){var a,o;Ee(e,t,n,r);let{value:s}=r;return(a=t.options_)!=null&&a.bound&&(s=s.bind(e.proxy_??e.target_)),{value:xt(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 Oe(e,t){return{annotationType_:e,options_:t,make_:ke,extend_:Ae}}function ke(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&&(!ie(e.target_,t)||!dr(e.target_[t]))&&this.extend_(e,t,n,!1)===null?0:dr(n.value)?1:(a(r,t,Ne(e,this,t,n,!1,!1)),2)}function Ae(e,t,n,r){let i=Ne(e,this,t,n,this.options_?.bound);return e.defineProperty_(t,i,r)}function je(e,t,n){var r;oe(n,[`method`]);let{name:i,addInitializer:a}=n;return dr(t)||(t=sr(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 Me(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 Ne(e,t,n,r,i,a=M.safeDescriptors){Me(e,t,n,r);let{value:o}=r;return dr(o)||(o=sr(o)),i&&(o=o.bind(e.proxy_??e.target_),o.isMobXFlow=!0),{value:o,configurable:a?e.isPlainObject_:!0,enumerable:!1,writable:!a}}function Pe(e,t){return{annotationType_:e,options_:t,make_:Fe,extend_:Ie}}function Fe(e,t,n){return this.extend_(e,t,n,!1)===null?0:1}function Ie(e,t,n,i){return Re(e,this,t,n),e.defineComputedProperty_(t,r({},this.options_,{get:n.get,set:n.set}),i)}function Le(e,t,n){oe(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 At(o)}return o(function(){let e=Ci(this)[E],n=this,r=e.values_.get(a);r instanceof At&&r.derivation!==t&&e.values_.delete(a),(e.lazyComputedKeys_??=new Map).set(a,()=>c(n,e))}),function(){let e=this[E],n=e.values_.get(a);if(n instanceof At&&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 Re(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 ze(e,t){return{annotationType_:e,options_:t,make_:Be,extend_:Ve}}function Be(e,t,n){return this.extend_(e,t,n,!1)===null?0:1}function Ve(e,t,n,r){return Ue(e,this,t,n),e.defineObservableProperty_(t,n.value,this.options_?.enhancer_??me,r)}function He(e,t,r){if(r.kind===`field`)throw n(`Please use \`@observable accessor ${String(r.name)}\` instead of \`@observable ${String(r.name)}\``);oe(r,[`accessor`]);let i=e,{kind:a,name:o}=r;if(a!==`accessor`)return;function s(e,t){let n=Ci(e)[E];return(n.lazyObservableKeys_??=new Map).set(o,()=>new Ot(t,i.options_?.enhancer_??me,`${n.name_}.${o.toString()}`,!1)),n}return{get(){return(this[E]??s(this,t.get.call(this))).getObservablePropValue_(o)},set(e){return(this[E]??s(this,e)).setObservablePropValue_(o,e)},init(e){return s(this,e),e}}}function Ue(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 We=Ge();function Ge(e){return{annotationType_:`true`,options_:e,make_:Je,extend_:Ye}}let Ke=[We];function qe(e){let t=e.deep!==!1,n=!!e.autoBind,r=!t|(n?2:0);return Ke[r]??(Ke[r]=Ge({deep:t,autoBind:n}))}function Je(e,t,n,r){var i;if(n.get)return k.make_(e,t,n,r);if(n.set){let i=Rn(n.set)?n.set:xt(t.toString(),n.set);return r===e.target_?e.defineProperty_(t,{configurable:M.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?cr:sr).make_(e,t,n,r)}return((o=this.options_)!=null&&o.autoBind?In:Pn).make_(e,t,n,r)}let c=this.options_?.deep===!1?lt:O;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 Ye(e,t,n,r){var i;return n.get?k.extend_(e,t,n,r):n.set?e.defineProperty_(t,{configurable:M.safeDescriptors?e.isPlainObject_:!0,set:xt(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?lt:O).extend_(e,t,n,r))}function Xe(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 Ze={deep:!0,name:void 0,defaultDecorator:void 0};Object.freeze(Ze);function Qe(e){return e||Ze}let $e=ze(`observable`),et=ze(`observable.ref`,{enhancer_:ge}),tt=ze(`observable.shallow`,{enhancer_:he}),nt=ze(`observable.struct`,{enhancer_:_e});function rt(e){return Xe(e,He)}function it(e){return e.deep===!0?me:e.deep===!1?ge:ot(e.defaultDecorator)}function at(e){return e?e.defaultDecorator??qe(e):void 0}function ot(e){return e?e.options_?.enhancer_??me:me}function st(e,t,n){return t&&typeof t.kind==`string`?He($e,e,t):br(e)?e:g(e)?O.object(e,t,n):Array.isArray(e)?O.array(e,t):x(e)?O.map(e,t):C(e)?O.set(e,t):typeof e==`object`&&e?e:O.box(e,t)}let ct={box(e,t){let n=Qe(t);return new Ot(e,it(n),n.name,!0,n.equals)},array(e,t){let n=Qe(t);return ai(e,it(n),n.name)},map(e,t){let n=Qe(t);return new hi(e,it(n),n.name)},set(e,t){let n=Qe(t);return new _i(e,it(n),n.name)},object(e,t,n){return Mi(()=>Yn(Wr({},n),e,t))}},lt=rt(et),ut=rt(tt),dt=rt($e),ft=rt(nt);var O=r(st,$e,ct);let pt=`computed`;function mt(e){return Xe(e,Le)}let ht=Pe(pt),gt=mt(Pe(`computed.struct`,{equals:de})),k=function(e,t){if(t&&typeof t.kind==`string`)return Le(ht,e,t);if(g(e))return mt(Pe(pt,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 At(r)};r(k,ht);let _t=0,vt=1,yt=i(()=>{},`name`)?.configurable??!1,bt={value:`action`,configurable:!0,writable:!1,enumerable:!1};function xt(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 St(e,r,t,i||this,arguments)}return o.isMobxAction=!0,o.toString=()=>t.toString(),yt&&(bt.value=e,a(o,`name`,bt)),o}function St(e,t,n,r,i){let a=Ct(e,t,r,i);try{return n.apply(r,i)}catch(e){throw a.error_=e,e}finally{wt(a)}}function Ct(e,t,n,r){let i=N()&&!!e,a=0;i&&(a=Date.now(),xn({type:P,name:e,object:n,arguments:r?Array.from(r):s}));let o=M.trackingDerivation,c=!t||!o;an();let l=M.allowStateChanges;c&&(Ht(),l=Et(!0));let u=M.allowStateReads;j(!0);let d={runAsAction_:c,prevDerivation_:o,prevAllowStateChanges_:l,prevAllowStateReads_:u,notifySpy_:i,startTime_:a,actionId_:vt++,parentActionId_:_t};return _t=d.actionId_,d}function wt(e){_t!==e.actionId_&&n(30),_t=e.parentActionId_,e.error_!==void 0&&(M.suppressReactionErrors=!0),Dt(e.prevAllowStateChanges_),Wt(e.prevAllowStateReads_),on(),e.runAsAction_&&Ut(e.prevDerivation_),e.notifySpy_&&Cn({time:Date.now()-e.startTime_}),M.suppressReactionErrors=!1}function Tt(e,t){let n=Et(e);try{return t()}finally{Dt(n)}}function Et(e){let t=M.allowStateChanges;return M.allowStateChanges=e,t}function Dt(e){M.allowStateChanges=e}var Ot=class extends se{constructor(e,t,n=`ObservableValue@`+u(),r=!0,i=pe){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&&N()&&bn({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!==M.UNCHANGED){let n=N();n&&xn({type:ni,object:this,observableKind:`value`,debugObjectName:this.name_,newValue:e,oldValue:t}),this.setNewValue_(e),n&&Cn()}}prepareNewValue_(e){if(A(this),Gr(this)){let t=qr(this,{object:this,type:ni,newValue:e});if(!t)return M.UNCHANGED;e=t.newValue}return e=this.enhancer_(e,this.value_,this.name_),this.equals_(this.value_,e)?M.UNCHANGED:e}setNewValue_(e){let t=this.value_;this.value_=e,this.reportChanged(),Jr(this)&&Xr(this,{type:ni,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 re(this.get())}[Symbol.toPrimitive](){return this.valueOf()}};let kt=b(`ObservableValue`,Ot);var At=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 Mt(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_=xt(this.name_+`-setter`,e.set)),this.equals_=e.equals||pe,this.scope_=e.context,this.requiresReaction_=e.requiresReaction,this.keepAlive_=!!e.keepAlive}onBecomeStale_(){fn(this)}onBO(){this.onBOL&&this.onBOL.forEach(e=>e())}onBUO(){this.onBUOL&&this.onBUOL.forEach(e=>e())}get isComputing(){return w(this.flags_,1)}set isComputing(e){this.flags_=T(this.flags_,1,e)}get isRunningSetter(){return w(this.flags_,2)}set isRunningSetter(e){this.flags_=T(this.flags_,2,e)}get isBeingObserved(){return w(this.flags_,4)}set isBeingObserved(e){this.flags_=T(this.flags_,4,e)}get isPendingUnobservation(){return w(this.flags_,8)}set isPendingUnobservation(e){this.flags_=T(this.flags_,8,e)}get diffValue(){return+!!w(this.flags_,16)}set diffValue(e){this.flags_=T(this.flags_,16,e===1)}get(){if(this.isComputing&&n(32,this.name_,this.derivation),M.inBatch===0&&(!this.observers_||this.observers_.size===0)&&!this.keepAlive_)Pt(this)&&(this.warnAboutUntrackedRead_(),an(),this.value_=this.computeValue_(!1),on());else{let e=this.isBeingObserved;if(ln(this),Pt(this)){let e=M.trackingContext;!e&&(this.keepAlive_||this.isBeingObserved)&&(M.trackingContext=this),this.trackAndCompute()&&dn(this),M.trackingContext=e}else !e&&this.isBeingObserved&&this.observing_.forEach(cn)}let e=this.value_;if(Nt(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||Nt(e)||Nt(n)||!this.equals_(e,n);return r&&(this.value_=n,N()&&bn({observableKind:`computed`,debugObjectName:this.name_,object:this.scope_,type:`update`,oldValue:e,newValue:n})),r}computeValue_(e){this.isComputing=!0;let t=Et(!1),n;if(e)n=Lt(this,this.derivation,this.scope_);else if(M.disableErrorBoundaries===!0)n=this.derivation.call(this.scope_);else try{n=this.derivation.call(this.scope_)}catch(e){n=new Mt(e)}return Dt(t),this.isComputing=!1,n}suspend_(){this.keepAlive_||(Bt(this),this.value_=void 0)}warnAboutUntrackedRead_(){(typeof this.requiresReaction_==`boolean`?this.requiresReaction_:M.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 re(this.get())}[Symbol.toPrimitive](){return this.valueOf()}};let jt=b(`ComputedValue`,At);var Mt=class{constructor(e){this.cause=void 0,this.cause=e}};function Nt(e){return e instanceof Mt}function Pt(e){switch(e.dependenciesState_){case 0:return!1;case-1:case 2:return!0;case 1:{let t=j(!0),n=Ht(),r=e.observing_,i=r.length;for(let a=0;a<i;a++){let i=r[a];if(jt(i)){if(M.disableErrorBoundaries)i.get();else try{i.get()}catch{return Ut(n),Wt(t),!0}if(e.dependenciesState_===2)return Ut(n),Wt(t),!0}}return Gt(e),Ut(n),Wt(t),!1}}}function Ft(){return M.trackingDerivation!==null}function A(e){let t=!!e.observers_&&e.observers_.size>0;!M.allowStateChanges&&(t||M.enforceActions===`always`)&&console.warn(`[MobX] `+(M.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 It(e){!M.allowStateReads&&M.observableRequiresReaction&&console.warn(`[mobx] Observable '${e.name_}' being read outside a reactive context.`)}function Lt(e,t,n){let r=j(!0);Gt(e),e.newObserving_=Array(e.runId_===0?100:e.observing_.length),e.unboundDepsCount_=0,e.runId_=++M.runId;let i=M.trackingDerivation;M.trackingDerivation=e,M.inBatch++;let a;if(M.disableErrorBoundaries===!0)a=t.call(n);else try{a=t.call(n)}catch(e){a=new Mt(e)}return M.inBatch--,M.trackingDerivation=i,zt(e),Rt(e),Wt(r),a}function Rt(e){e.observing_.length===0&&(typeof e.requiresObservable_==`boolean`?e.requiresObservable_:M.reactionRequiresObservable)&&console.warn(`[mobx] Derivation '${e.name_}' is created/updated without reading any observable value.`)}function zt(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&&nn(n,e),n.diffValue=0}for(;i--;){let t=n[i];t.diffValue===1&&(t.diffValue=0,tn(t,e))}r!==0&&(e.dependenciesState_=r,e.onBecomeStale_())}function Bt(e){let t=e.observing_;e.observing_=[];let n=t.length;for(;n--;)nn(t[n],e);e.dependenciesState_=-1}function Vt(e){let t=Ht();try{return e()}finally{Ut(t)}}function Ht(){let e=M.trackingDerivation;return M.trackingDerivation=null,e}function Ut(e){M.trackingDerivation=e}function j(e){let t=M.allowStateReads;return M.allowStateReads=e,t}function Wt(e){M.allowStateReads=e}function Gt(e){if(e.dependenciesState_===0)return;e.dependenciesState_=0;let t=e.observing_,n=t.length;for(;n--;)t[n].lowestObserverState_=0}let Kt=[`mobxGuid`,`spyListeners`,`enforceActions`,`computedRequiresReaction`,`reactionRequiresObservable`,`observableRequiresReaction`,`allowStateReads`,`disableErrorBoundaries`,`runId`,`UNCHANGED`];var qt=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 Jt=!0,Yt=!1,M=function(){let e=globalThis;return e.__mobxInstanceCount>0&&!e.__mobxGlobals&&(Jt=!1),e.__mobxGlobals&&e.__mobxGlobals.version!==7&&(Jt=!1),Jt?e.__mobxGlobals?(e.__mobxInstanceCount+=1,e.__mobxGlobals.UNCHANGED||(e.__mobxGlobals.UNCHANGED={}),e.__mobxGlobals):(e.__mobxInstanceCount=1,e.__mobxGlobals=new qt):(setTimeout(()=>{Yt||n(35)},1),new qt)}();function Xt(){if((M.pendingReactions.length||M.inBatch||M.isRunningReactions)&&n(36),Yt=!0,Jt){let e=globalThis;--e.__mobxInstanceCount===0&&(e.__mobxGlobals=void 0),M=new qt}}function Zt(){return M}function Qt(){let e=new qt;for(let t in e)Kt.indexOf(t)===-1&&(M[t]=e[t]);M.allowStateChanges=!M.enforceActions}function $t(e){return!!e.observers_&&e.observers_.size>0}function en(e){return e.observers_??new Set}function tn(e,t){(e.observers_??=new Set).add(t),e.lowestObserverState_>t.dependenciesState_&&(e.lowestObserverState_=t.dependenciesState_)}function nn(e,t){let n=e.observers_;n&&(n.delete(t),n.size===0&&rn(e))}function rn(e){e.isPendingUnobservation===!1&&(e.isPendingUnobservation=!0,M.pendingUnobservations.push(e))}function an(){M.inBatch++}function on(){--M.inBatch===0&&(gn(),!M.isRunningUnobservations&&M.pendingUnobservations.length>0&&sn())}function sn(){M.isRunningUnobservations=!0;try{let e=M.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 At&&n.suspend_())}M.pendingUnobservations=[]}finally{M.isRunningUnobservations=!1}}function cn(e){var t;e.isBeingObserved||(e.isBeingObserved=!0,e.onBO(),(t=e.observing_)==null||t.forEach(cn))}function ln(e){It(e);let t=M.trackingDerivation;return t===null?((!e.observers_||e.observers_.size===0)&&M.inBatch>0&&rn(e),!1):(t.runId_!==e.lastAccessedBy_&&(e.lastAccessedBy_=t.runId_,t.newObserving_[t.unboundDepsCount_++]=e,!e.isBeingObserved&&M.trackingContext&&(e.isBeingObserved=!0,e.onBO())),e.isBeingObserved)}function un(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 dn(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 fn(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 pn=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 w(this.flags_,1)}set isDisposed(e){this.flags_=T(this.flags_,1,e)}get isScheduled(){return w(this.flags_,2)}set isScheduled(e){this.flags_=T(this.flags_,2,e)}get isTrackPending(){return w(this.flags_,4)}set isTrackPending(e){this.flags_=T(this.flags_,4,e)}get isRunning(){return w(this.flags_,8)}set isRunning(e){this.flags_=T(this.flags_,8,e)}get diffValue(){return+!!w(this.flags_,16)}set diffValue(e){this.flags_=T(this.flags_,16,e===1)}onBecomeStale_(){this.schedule_()}schedule_(){this.isScheduled||(this.isScheduled=!0,M.pendingReactions.push(this),gn())}runReaction_(){if(!this.isDisposed){an(),this.isScheduled=!1;let e=M.trackingContext;if(M.trackingContext=this,Pt(this)){this.isTrackPending=!0;try{this.onInvalidate_(),this.isTrackPending&&N()&&bn({name:this.name_,type:`scheduled-reaction`})}catch(e){this.reportExceptionInDerivation_(e)}}M.trackingContext=e,on()}}track(e){if(this.isDisposed)return;an();let t=N(),n;t&&(n=Date.now(),xn({name:this.name_,type:`reaction`})),this.isRunning=!0;let r=M.trackingContext;M.trackingContext=this;let i=Lt(this,e,void 0);M.trackingContext=r,this.isRunning=!1,this.isTrackPending=!1,this.isDisposed&&Bt(this),Nt(i)&&this.reportExceptionInDerivation_(i.cause),t&&Cn({time:Date.now()-n}),on()}reportExceptionInDerivation_(e){if(this.errorHandler_){this.errorHandler_(e,this);return}if(M.disableErrorBoundaries)throw e;let t=`[mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: '${this}'`;M.suppressReactionErrors?console.warn(`[mobx] (error in reaction '${this.name_}' suppressed, fix error of causing action below)`):console.error(t,e),N()&&bn({type:`error`,name:this.name_,message:t,error:``+e}),M.globalReactionErrorHandlers.forEach(t=>t(e,this))}dispose(){if(!this.isDisposed){var e;this.isDisposed=!0,(e=this.removeAbortListener_)==null||e.call(this),this.isRunning||(an(),Bt(this),on())}}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[E]=this,`dispose`in Symbol&&typeof Symbol.dispose==`symbol`&&(t[Symbol.dispose]=t),t}toString(){return`Reaction[${this.name_}]`}};function mn(e){return M.globalReactionErrorHandlers.push(e),()=>{let t=M.globalReactionErrorHandlers.indexOf(e);t>=0&&M.globalReactionErrorHandlers.splice(t,1)}}let hn=e=>e();function gn(){M.inBatch>0||M.isRunningReactions||hn(_n)}function _n(){M.isRunningReactions=!0;let e=M.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_()}M.isRunningReactions=!1}let vn=b(`Reaction`,pn);function yn(e){let t=hn;hn=n=>e(()=>t(n))}function N(){return!!M.spyListeners.length}function bn(e){if(!M.spyListeners.length)return;let t=M.spyListeners;for(let n=0,r=t.length;n<r;n++)t[n](e)}function xn(e){bn(r({},e,{spyReportStart:!0}))}let Sn={type:`report-end`,spyReportEnd:!0};function Cn(e){bn(e?r({},e,{type:`report-end`,spyReportEnd:!0}):Sn)}function wn(e){return M.spyListeners.push(e),d(()=>{M.spyListeners=M.spyListeners.filter(t=>t!==e)})}let P=`action`,Tn=`autoAction`,En=`<unnamed action>`,Dn=Se(P),On=Se(`action.bound`,{bound:!0}),kn=Se(Tn,{autoAction:!0}),An=Se(`autoAction.bound`,{autoAction:!0,bound:!0});function jn(e){return Xe(e,Te)}function Mn(e){return function(t,r){if(r&&typeof r.kind==`string`)return Te(e?kn:Dn,t,r);if(p(t))return xt(t.name||En,t,e);if(p(r))return xt(t,r,e);if(m(t))return jn(Se(e?Tn:P,{name:t,autoAction:e}));n("Invalid arguments for `action`")}}let Nn=Mn(!1);r(Nn,Dn);let Pn=Mn(!0);r(Pn,kn);let Fn=jn(On),In=jn(An);function Ln(e){return St(e.name||En,!1,e,this,void 0)}function Rn(e){return p(e)&&e.isMobxAction===!0}function zn(e,t=c){var r;p(e)||n(`Autorun expects a function as first argument`),Rn(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 pn(i,function(){this.track(s)},t.onError,t.requiresObservable);else{let e=Vn(t),n=!1;o=new pn(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 Bn=e=>e();function Vn(e){return e.scheduler?e.scheduler:e.delay?t=>setTimeout(t,e.delay):Bn}function Hn(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=Nn(a,r.onError?Un(r.onError,t):t),s=!r.scheduler&&!r.delay,l=Vn(r),d=!0,f=!1,m,h=r.equals||pe,_=new pn(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=Tt(!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 Un(e,t){return function(){try{return t.apply(this,arguments)}catch(t){e.call(this,t)}}}function Wn(e,t,n){return Kn(`onBO`,e,t,n)}function Gn(e,t,n){return Kn(`onBUO`,e,t,n)}function Kn(e,t,n,r){let i=typeof r==`function`?ki(t,n):ki(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 qn=`always`;function Jn(e){e.isolateGlobalState===!0&&Xt();let{enforceActions:t}=e;if(t!==void 0){let e=t===qn?qn:t===`observed`;M.enforceActions=e,M.allowStateChanges=!(e===!0||e===qn)}[`computedRequiresReaction`,`reactionRequiresObservable`,`observableRequiresReaction`,`disableErrorBoundaries`,`safeDescriptors`].forEach(t=>{t in e&&(M[t]=!!e[t])}),M.allowStateReads=!M.observableRequiresReaction,M.disableErrorBoundaries===!0&&console.warn("WARNING: Debug feature only. MobX will NOT recover from errors when `disableErrorBoundaries` is enabled."),e.reactionScheduler&&yn(e.reactionScheduler)}function Yn(e,t,r,i){arguments.length>4&&n(`'extendObservable' expected 2-4 arguments`),typeof e!=`object`&&n(`'extendObservable' expects an object as first argument`),F(e)&&n(`'extendObservable' should not be used on maps, use map.merge instead`),g(t)||n(`'extendObservable' only accepts plain objects as second argument`),(br(t)||br(r))&&n(`Extending an object with another observable (object) is not supported`);let a=ae(t);return Mi(()=>{let t=Ci(e,i)[E];te(a).forEach(e=>{t.extend_(e,a[e],r&&e in r?r[e]:!0)})}),e}function Xn(e,t){return Zn(ki(e,t))}function Zn(e){let t={name:e.name_};return e.observing_&&e.observing_.length>0&&(t.dependencies=er(e.observing_).map(Zn)),t}function Qn(e,t){return $n(ki(e,t))}function $n(e){let t={name:e.name_};return $t(e)&&(t.observers=Array.from(en(e),$n)),t}function er(e){return Array.from(new Set(e))}let tr=0;var nr=class extends Error{constructor(){super(`FLOW_CANCELLED`),Object.setPrototypeOf(this,new.target.prototype),this.name=`FlowCancellationError`}toString(){return`Error: ${this.message}`}};function rr(e){return e instanceof nr}function ir(e){return Xe(e,je)}let ar=Oe(`flow`),or=Oe(`flow.bound`,{bound:!0}),sr=r(function(e,t){if(t&&typeof t.kind==`string`)return je(ar,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=++tr,a=Nn(`${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=Nn(`${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=Nn(`${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=Nn(`${i} - runid: ${n} - cancel`,function(){try{s&&lr(s);let e=a.return(void 0),t=Promise.resolve(e.value);t.then(f,f),lr(t),o(new nr)}catch(e){o(e)}}),c};return a.isMobXFlow=!0,a},ar),cr=ir(or);function lr(e){p(e.cancel)&&e.cancel()}function ur(e){return e}function dr(e){return e?.isMobXFlow===!0}function fr(e,t,r){let i;if(F(e)||fi(e)||kt(e))i=Ai(e);else if(Ei(e)){if(!m(t))return n(`InterceptReads can only be used with a specific property, not with an object in general`);i=Ai(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 pr(e,t,n){return p(n)?hr(e,t,n):mr(e,t)}function mr(e,t){return Kr(Ai(e),t)}function hr(e,t,n){return Kr(Ai(e,t),n)}function gr(e,t){var n;if(t===void 0)return jt(e);if(Ei(e)===!1)return!1;let r=e[E];return(n=r.lazyComputedKeys_)!=null&&n.has(t)?!0:r.values_.has(t)?jt(ki(e,t)):!1}function _r(e){return arguments.length>1?n(`isComputed expects only 1 argument. Use isComputedProp to inspect the observability of a property`):gr(e)}function vr(e,t){return m(t)?gr(e,t):n(`isComputed expected a property name as second argument`)}function yr(e,t){if(!e)return!1;if(t!==void 0){if(F(e)||fi(e))return n(`isObservable(object, propertyName) is not supported for arrays and maps. Use map.has or array.length instead.`);if(Ei(e)){var r,i;let n=e[E];return n.values_.has(t)||!!((r=n.lazyComputedKeys_)!=null&&r.has(t))||!!((i=n.lazyObservableKeys_)!=null&&i.has(t))}return!1}return Ei(e)||!!e[E]||ce(e)||vn(e)||jt(e)}function br(e){return arguments.length!==1&&n(`isObservable expects only 1 argument. Use isObservableProp to inspect the observability of a property`),yr(e)}function xr(e,t){return m(t)?yr(e,t):n(`expected a property name as second argument`)}function Sr(e){if(Ei(e))return e[E].keys_();if(F(e)||vi(e))return Array.from(e.keys());if(fi(e))return e.map((e,t)=>t);n(5)}function Cr(e){if(Ei(e))return Sr(e).map(t=>e[t]);if(F(e))return Sr(e).map(t=>e.get(t));if(vi(e))return Array.from(e.values());if(fi(e))return e.slice();n(6)}function wr(e){if(Ei(e))return Sr(e).map(t=>[t,e[t]]);if(F(e))return Sr(e).map(t=>[t,e.get(t)]);if(vi(e))return Array.from(e.entries());if(fi(e))return e.map((e,t)=>[t,e]);n(7)}function Tr(e,t,r){if(arguments.length===2&&!vi(e)){an();let n=t;try{for(let t in n)Tr(e,t,n[t])}finally{on()}return}Ei(e)?e[E].set_(t,r):F(e)?e.set(t,r):vi(e)?e.add(t):fi(e)?(typeof t!=`number`&&(t=parseInt(t,10)),t<0&&n(42,t),an(),t>=e.length&&(e.length=t+1),e[t]=r,on()):n(8)}function Er(e,t){Ei(e)?e[E].delete_(t):F(e)||vi(e)?e.delete(t):fi(e)?(typeof t!=`number`&&(t=parseInt(t,10)),e.splice(t,1)):n(9)}function Dr(e,t){if(Ei(e))return e[E].has_(t);if(F(e)||vi(e))return e.has(t);if(fi(e))return t>=0&&t<e.length;n(10)}function Or(e,t){if(Dr(e,t)){if(Ei(e))return e[E].get_(t);if(F(e))return e.get(t);if(fi(e))return e[t];n(11)}}function kr(e,t,r){if(Ei(e))return e[E].defineProperty_(t,r);n(39)}function Ar(e){if(Ei(e))return e[E].ownKeys_();n(38)}function jr(e,t,n,r){return p(n)?Nr(e,t,n,r):Mr(e,t,n)}function Mr(e,t,r){let i=Ai(e);if(fi(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(F(e))r===!0&&n("`observe` doesn't support fireImmediately=true in combination with maps.");else if(vi(e))r===!0&&n("`observe` doesn't support fireImmediately=true in combination with sets.");else if(Ei(e))r===!0&&n("`observe` doesn't support the fire immediately property for observable objects.");else return Pr(i,t,r);return Yr(i,t)}function Nr(e,t,n,r){return Pr(Ai(e,t),n,r)}function Pr(e,t,n){if(jt(e)){let r=!0,i;return zn(()=>{let a=e.get();if(!r||n){let n=Ht();t({observableKind:`computed`,debugObjectName:e.name_,type:ni,object:e,newValue:a,oldValue:i}),Ut(n)}r=!1,i=a})}return n&&t({observableKind:`value`,debugObjectName:e.name_,object:e,type:ni,newValue:e.value_,oldValue:void 0}),Yr(e,t)}function Fr(e,t,n){return e.set(t,n),n}function Ir(e,t){if(typeof e!=`object`||!e||e instanceof Date||!br(e))return e;if(kt(e)||jt(e))return Ir(e.get(),t);if(t.has(e))return t.get(e);if(fi(e)){let n=Fr(t,e,Array(e.length));return e.forEach((e,r)=>{n[r]=Ir(e,t)}),n}if(vi(e)){let n=Fr(t,e,new Set);return e.forEach(e=>{n.add(Ir(e,t))}),n}if(F(e)){let n=Fr(t,e,new Map);return e.forEach((e,r)=>{n.set(r,Ir(e,t))}),n}else{let n=Fr(t,e,{});return Ar(e).forEach(r=>{o.propertyIsEnumerable.call(e,r)&&(n[r]=Ir(e[r],t))}),n}}function Lr(e,t){return t&&n(`toJS no longer supports options`),Ir(e,new Map)}function Rr(e,t=void 0){an();try{return e.apply(t)}finally{on()}}function zr(e,t,n){return arguments.length===1||t&&typeof t==`object`?Vr(e,t):Br(e,t,n||{})}function Br(e,t,n){let r;if(typeof n.timeout==`number`){let e=Error(`WHEN_TIMEOUT`);r=setTimeout(()=>{if(!a[E].isDisposed)if(a(),n.onError)n.onError(e);else throw e},n.timeout)}n.name=n.name||`When@`+u();let i=xt(n.name+`-effect`,t);var a=zn(t=>{Tt(!1,e)&&(t.dispose(),r&&clearTimeout(r),i())},n);return a}function Vr(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=Br(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 Hr(e){return e[E]}let Ur={has(e,t){return Hr(e).has_(t)},get(e,t){return Hr(e).get_(t)},set(e,t,n){return m(t)?Hr(e).set_(t,n,!0)??!0:!1},deleteProperty(e,t){return m(t)?Hr(e).delete_(t,!0)??!0:!1},defineProperty(e,t,n){return Hr(e).defineProperty_(t,n)??!0},ownKeys(e){return Hr(e).ownKeys_()},preventExtensions(e){n(13)}};function Wr(e,t){var n;return e=Ci(e,t),(n=e[E]).proxy_??(n.proxy_=new Proxy(e,Ur))}function Gr(e){return e.interceptors_!==void 0&&e.interceptors_.length>0}function Kr(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 qr(e,t){let r=Ht();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{Ut(r)}}function Jr(e){return e.changeListeners_!==void 0&&e.changeListeners_.length>0}function Yr(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 Xr(e,t){let n=Ht(),r=e.changeListeners_;if(r){r=r.slice();for(let e=0,n=r.length;e<n;e++)r[e](t);Ut(n)}}function Zr(e,t,n){return Mi(()=>{let r=Ci(e,n)[E];te(t).forEach(e=>ei(r,e,t[e]))}),e}let Qr=Symbol(`mobx-keys`);function $r(e,t,r){return!g(e)&&!g(Object.getPrototypeOf(e))&&n(`'makeAutoObservable' can only be used for classes that don't have a superclass`),Ei(e)&&n(`makeAutoObservable can only be used on objects not already made observable`),g(e)?Yn(e,e,t,r):(Mi(()=>{let n=Ci(e,r)[E];if(!e[Qr]){let t=Object.getPrototypeOf(e),n=new Set([...te(e),...te(t)]);n.delete(`constructor`),n.delete(E),v(t,Qr,n)}e[Qr].forEach(e=>ei(n,e,t&&e in t?t[e]:!0))}),e)}function ei(e,t,r){if(r===!0&&(r=e.defaultAnnotation_),r===!1)return;Oi(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)}Di(e,r,t)}let ti=`splice`,ni=`update`,ri={get(e,t){let n=e[E];return t===E?n:t===`length`?n.getArrayLength_():typeof t==`string`&&!isNaN(t)?n.get_(parseInt(t)):ie(oi,t)?oi[t]:e[t]},set(e,t,n){let r=e[E];return t===`length`?r.setArrayLength_(n):typeof t==`symbol`||isNaN(t)?e[t]=n:r.set_(parseInt(t),n),!0},preventExtensions(){n(15)}};var ii=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 se(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){A(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),Gr(this)){let r=qr(this,{object:this.proxy_,type:ti,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_&&N(),i=Jr(this),a=i||r?{observableKind:`array`,object:this.proxy_,type:ni,debugObjectName:this.atom_.name_,index:e,newValue:t,oldValue:n}:null;r&&xn(a),this.atom_.reportChanged(),i&&Xr(this,a),r&&Cn()}notifyArraySplice_(e,t,n){let r=!this.owned_&&N(),i=Jr(this),a=i||r?{observableKind:`array`,object:this.proxy_,debugObjectName:this.atom_.name_,type:ti,index:e,removed:n,added:t,removedCount:n.length,addedCount:t.length}:null;r&&xn(a),this.atom_.reportChanged(),i&&Xr(this,a),r&&Cn()}get_(e){return this.atom_.reportObserved(),this.dehanceValue_(this.values_[e])}set_(e,t){let n=this.values_;if(e<n.length){A(this.atom_);let r=n[e];if(Gr(this)){let n=qr(this,{type:ni,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 ai(e,t,n=`ObservableArray@`+u(),r=!1){return Mi(()=>{let i=new ii(n,t,r);y(i.values_,E,i);let a=new Proxy(i.values_,ri);return i.proxy_=a,e&&e.length&&i.spliceWithArray_(0,0,e),a})}var oi={clear(){return this.splice(0)},replace(e){let t=this[E];return t.spliceWithArray_(0,t.values_.length,e)},toJSON(){return this.slice()},splice(e,t,...n){let r=this[E];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[E].spliceWithArray_(e,t,n)},push(...e){let t=this[E];return t.spliceWithArray_(t.values_.length,0,e),t.values_.length},pop(){return this.splice(Math.max(this[E].values_.length-1,0),1)[0]},shift(){return this.splice(0,1)[0]},unshift(...e){let t=this[E];return t.spliceWithArray_(0,0,e),t.values_.length},reverse(){return M.trackingDerivation&&n(37,`reverse`),this.replace(this.slice().reverse()),this},sort(){M.trackingDerivation&&n(37,`sort`);let e=this.slice();return e.sort.apply(e,arguments),this.replace(e),this},remove(e){let t=this[E],n=t.dehanceValues_(t.values_).indexOf(e);return n>-1?(this.splice(n,1),!0):!1}};si(`at`,ci),si(`concat`,ci),si(`flat`,ci),si(`includes`,ci),si(`indexOf`,ci),si(`join`,ci),si(`lastIndexOf`,ci),si(`slice`,ci),si(`toString`,ci),si(`toLocaleString`,ci),si(`toSorted`,ci),si(`toSpliced`,ci),si(`with`,ci),si(`every`,li),si(`filter`,li),si(`find`,li),si(`findIndex`,li),si(`findLast`,li),si(`findLastIndex`,li),si(`flatMap`,li),si(`forEach`,li),si(`map`,li),si(`some`,li),si(`toReversed`,li),si(`reduce`,ui),si(`reduceRight`,ui);function si(e,t){typeof Array.prototype[e]==`function`&&(oi[e]=t(e))}function ci(e){return function(){let t=this[E];t.atom_.reportObserved();let n=t.dehanceValues_(t.values_);return n[e].apply(n,arguments)}}function li(e){return function(t,n){let r=this[E];return r.atom_.reportObserved(),r.dehanceValues_(r.values_)[e]((e,r)=>t.call(n,e,r,this))}}function ui(e){return function(){let t=this[E];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 di=b(`ObservableArrayAdministration`,ii);function fi(e){return h(e)&&di(e[E])}let pi={},mi=`delete`;var hi=class{constructor(e,t=me,n=`ObservableMap@`+u()){this.enhancer_=void 0,this.name_=void 0,this[E]=pi,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,Mi(()=>{this.keysAtom_=le(`${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(!M.trackingDerivation)return this.has_(e);let t=this.hasMap_.get(e);if(!t){let n=t=new Ot(this.has_(e),ge,`${this.name_}.${ne(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(Gr(this)){let r=qr(this,{type:n?ni:`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(A(this.keysAtom_),Gr(this)&&!qr(this,{type:mi,object:this,name:e}))return!1;if(this.has_(e)){let t=N(),n=Jr(this),r=n||t?{observableKind:`map`,debugObjectName:this.name_,type:mi,object:this,oldValue:this.data_.get(e).value_,name:e}:null;return t&&xn(r),Rr(()=>{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&&Xr(this,r),t&&Cn(),!0}return!1}updateValue_(e,t){let n=this.data_.get(e);if(t=n.prepareNewValue_(t),t!==M.UNCHANGED){let r=N(),i=Jr(this),a=i||r?{observableKind:`map`,debugObjectName:this.name_,type:ni,object:this,oldValue:n.value_,name:e,newValue:t}:null;r&&xn(a),n.setNewValue_(t),i&&Xr(this,a),r&&Cn()}}addValue_(e,t){A(this.keysAtom_),Rr(()=>{var n;let r=new Ot(t,this.enhancer_,`${this.name_}.${ne(e)}`,!1);this.data_.set(e,r),t=r.value_,(n=this.hasMap_.get(e))==null||n.setNewValue_(!0),this.keysAtom_.reportChanged()});let n=N(),r=Jr(this),i=r||n?{observableKind:`map`,debugObjectName:this.name_,type:`add`,object:this,name:e,newValue:t}:null;n&&xn(i),r&&Xr(this,i),n&&Cn()}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 I({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 I({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 F(e)&&(e=new Map(e)),Rr(()=>{g(e)?ee(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(){Rr(()=>{Vt(()=>{for(let e of this.keys())this.delete(e)})})}replace(e){return Rr(()=>{let t=L(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`}},F=b(`ObservableMap`,hi);function I(e){return e[Symbol.toStringTag]=`MapIterator`,Ri(e)}function L(e){if(x(e)||F(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 gi={};var _i=class{constructor(e,t=me,n=`ObservableSet@`+u()){this.name_=void 0,this[E]=gi,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),Mi(()=>{this.atom_=le(this.name_),e&&this.replace(e)})}dehanceValue_(e){return this.dehancer===void 0?e:this.dehancer(e)}clear(){Rr(()=>{Vt(()=>{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(A(this.atom_),Gr(this)){let t=qr(this,{type:`add`,object:this,newValue:e});if(!t)return this;e=t.newValue}if(!this.has(e)){Rr(()=>{e=this.enhancer_(e,void 0),this.data_.add(e),this.atom_.reportChanged()});let t=N(),n=Jr(this),r=n||t?{observableKind:`set`,debugObjectName:this.name_,type:`add`,object:this,newValue:e}:null;t&&xn(r),n&&Xr(this,r),t&&Cn()}return this}delete(e){if(Gr(this)&&!qr(this,{type:mi,object:this,oldValue:e}))return!1;if(this.has(e)){let t=N(),n=Jr(this),r=n||t?{observableKind:`set`,debugObjectName:this.name_,type:mi,object:this,oldValue:e}:null;return t&&xn(r),Rr(()=>{this.atom_.reportChanged(),this.data_.delete(e)}),n&&Xr(this,r),t&&Cn(),!0}return!1}has(e){return this.atom_.reportObserved(),this.data_.has(this.dehanceValue_(e))}entries(){let e=this.values();return yi({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 yi({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 vi(e)&&(e=new Set(e)),Array.isArray(e)||C(e)?Rr(()=>{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`}},vi=b(`ObservableSet`,_i);function yi(e){return e[Symbol.toStringTag]=`SetIterator`,Ri(e)}let bi=Object.create(null),xi=`remove`;var Si=class{constructor(e,t=new Map,r,i=We){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 se(`${this.name_}.keys`),this.isPlainObject_=g(this.target_),Bi(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 At)return n.set(t),!0;if(Gr(this)){let n=qr(this,{type:ni,object:this.proxy_||this.target_,name:e,newValue:t});if(!n)return null;t=n.newValue}if(t=n.prepareNewValue_(t),t!==M.UNCHANGED){let r=Jr(this),i=N(),a=r||i?{type:ni,observableKind:`object`,debugObjectName:this.name_,object:this.proxy_||this.target_,oldValue:n.value_,name:e,newValue:t}:null;i&&xn(a),n.setNewValue_(t),r&&Xr(this,a),i&&Cn()}return!0}get_(e){return M.trackingDerivation&&!ie(this.target_,e)&&this.has_(e),this.target_[e]}set_(e,t,n=!1){return ie(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(!M.trackingDerivation)return e in this.target_;this.pendingKeys_||=new Map;let t=this.pendingKeys_.get(e);return t||(t=new Ot(e in this.target_,ge,`${this.name_}.${ne(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);Oi(this,n,e);let i=n.extend_(this,e,t,r);return i&&Di(this,n,e),i}defineProperty_(e,t,n=!1){A(this.keysAtom_);try{an();let i=this.delete_(e);if(!i)return i;if(Gr(this)){let n=qr(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{on()}return!0}defineObservableProperty_(e,t,n,r=!1){A(this.keysAtom_);try{an();let i=this.delete_(e);if(!i)return i;if(Gr(this)){let n=qr(this,{object:this.proxy_||this.target_,name:e,type:`add`,newValue:t});if(!n)return null;t=n.newValue}let o=Ti(e),s={configurable:M.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 Ot(t,n,`${this.name_}.${e.toString()}`,!1);this.values_.set(e,c),this.notifyPropertyAddition_(e,c.value_)}finally{on()}return!0}defineComputedProperty_(e,t,n=!1){A(this.keysAtom_);try{an();let r=this.delete_(e);if(!r)return r;if(Gr(this)&&!qr(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=Ti(e),o={configurable:M.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 At(t)),this.notifyPropertyAddition_(e,void 0)}finally{on()}return!0}delete_(e,t=!1){if(A(this.keysAtom_),!ie(this.target_,e))return!0;if(Gr(this)&&!qr(this,{object:this.proxy_||this.target_,name:e,type:xi}))return null;try{var n;an();let r=Jr(this),a=N(),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 Ot&&(s=o.value_),un(o)),this.keysAtom_.reportChanged(),(n=this.pendingKeys_)==null||(n=n.get(e))==null||n.set(e in this.target_),r||a){let t={type:xi,observableKind:`object`,object:this.proxy_||this.target_,debugObjectName:this.name_,oldValue:s,name:e};a&&xn(t),r&&Xr(this,t),a&&Cn()}}finally{on()}return!0}notifyPropertyAddition_(e,t){var n;let r=Jr(this),i=N();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&&xn(n),r&&Xr(this,n),i&&Cn()}(n=this.pendingKeys_)==null||(n=n.get(e))==null||n.set(!0),this.keysAtom_.reportChanged()}ownKeys_(){return this.keysAtom_.reportObserved(),te(this.target_)}keys_(){return this.keysAtom_.reportObserved(),Object.keys(this.target_)}};function Ci(e,t){if(t&&Ei(e)&&n(`Options can't be provided for already observable objects.`),ie(e,E))return Ai(e)instanceof Si||n(`Cannot convert '${ji(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,E,new Si(e,new Map,String(r),at(t))),e}let wi=b(`ObservableObjectAdministration`,Si);function Ti(e){return bi[e]||(bi[e]={get(){return this[E].getObservablePropValue_(e)},set(t){return this[E].setObservablePropValue_(e,t)}})}function Ei(e){return h(e)?wi(e[E]):!1}function Di(e,t,n){e.appliedAnnotations_[n]=t}function Oi(e,t,r){if(Bi(t)||n(`Cannot annotate '${e.name_}.${r.toString()}': Invalid annotation.`),!be(t)&&ie(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 ki(e,t){if(typeof e==`object`&&e){if(fi(e))return t!==void 0&&n(23),e[E].atom_;if(vi(e))return e.atom_;if(F(e)){if(t===void 0)return e.keysAtom_;let r=e.data_.get(t)||e.hasMap_.get(t);return r||n(25,t,ji(e)),r}if(Ei(e)){if(!t)return n(26);let r=e[E],i=r.values_.get(t)??r.materializeLazyComputed_(t)??r.materializeLazyObservable_(t);return i||n(27,t,ji(e)),i}if(ce(e)||jt(e)||vn(e))return e}else if(p(e)&&vn(e[E]))return e[E];n(28)}function Ai(e,t){if(e||n(29),t!==void 0)return Ai(ki(e,t));if(ce(e)||jt(e)||vn(e)||F(e)||vi(e))return e;if(e[E])return e[E];n(24,e)}function ji(e,t){let n;if(t!==void 0)n=ki(e,t);else if(Rn(e))return e.name;else n=Ei(e)||F(e)||vi(e)?Ai(e):ki(e);return n.name_}function Mi(e){let t=Ht(),n=Et(!0);an();try{return e()}finally{on(),Dt(n),Ut(t)}}let Ni=o.toString;function Pi(e,t,n=-1){return Fi(e,t,n)}function Fi(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=Ni.call(e);if(o!==Ni.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=Ii(e),t=Ii(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(!Fi(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(!(ie(t,o)&&Fi(e[o],t[o],n-1,r,i)))return!1}}return r.pop(),i.pop(),!0}function Ii(e){return fi(e)?e.slice():x(e)||F(e)||C(e)||vi(e)?Array.from(e.entries()):e}let Li=globalThis.Iterator?.prototype||{};function Ri(e){return e[Symbol.iterator]=zi,r(Object.create(Li),e)}function zi(){return this}function Bi(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:wn,extras:{getDebugName:ji},$mobx:E}),e.$mobx=E,e.FlowCancellationError=nr,e.ObservableMap=hi,e.ObservableSet=_i,e.Reaction=pn,e._allowStateChanges=Tt,e._allowStateChangesInsideComputed=Ln,e._allowStateReadsEnd=Wt,e._allowStateReadsStart=j,e._autoAction=Pn,e._autoActionBound=In,e._endAction=wt,e._getAdministration=Ai,e._getGlobalState=Zt,e._interceptReads=fr,e._isComputingDerivation=Ft,e._resetGlobalState=Qt,e._startAction=Ct,e.action=Nn,e.actionBound=Fn,e.autorun=zn,e.compareDefault=pe,e.compareIdentity=ue,e.compareShallow=fe,e.compareStructural=de,e.computed=k,e.computedStruct=gt,e.configure=Jn,e.createAtom=le,e.defineProperty=kr,e.entries=wr,e.extendObservable=Yn,e.flow=sr,e.flowBound=cr,e.flowResult=ur,e.get=Or,e.getAtom=ki,e.getDebugName=ji,e.getDependencyTree=Xn,e.getObserverTree=Qn,e.has=Dr,e.intercept=pr,e.isAction=Rn,e.isBoxedObservable=kt,e.isComputed=_r,e.isComputedProp=vr,e.isFlow=dr,e.isFlowCancellationError=rr,e.isObservable=br,e.isObservableArray=fi,e.isObservableMap=F,e.isObservableObject=Ei,e.isObservableProp=xr,e.isObservableSet=vi,e.keys=Sr,e.makeAutoObservable=$r,e.makeObservable=Zr,e.observable=O,e.observableDeep=dt,e.observableRef=lt,e.observableShallow=ut,e.observableStruct=ft,e.observe=jr,e.onBecomeObserved=Wn,e.onBecomeUnobserved=Gn,e.onReactionError=mn,e.override=ye,e.ownKeys=Ar,e.reaction=Hn,e.remove=Er,e.runInAction=Ln,e.set=Tr,e.spy=wn,e.toJS=Lr,e.transaction=Rr,e.untracked=Vt,e.values=Cr,e.when=zr})),Vg=ye(((e,t)=>{process.env.NODE_ENV===`production`?t.exports=zg():t.exports=Bg()}))();function Hg(e){if(Array.isArray(e))return Object.freeze(e.map(Hg));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]=Hg(r);return Object.freeze(t)}return e}function Ug(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 Wg(e){return typeof e==`string`?e:String(e)}function Gg(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 Kg(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 qg=class extends Error{constructor(e,t){super(t),this.variable=e}};function Jg(e){return e instanceof qg||e instanceof Error&&e.cause!==void 0&&Jg(e.cause)}var Yg=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?i_(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}},Xg=class extends Yg{name=`ParseError`;kind=`ParseError`;expected;found;constructor(e,t,n={}){super(e,t,n),this.expected=n.expected,this.found=n.found}},Zg=class extends Yg{name=`EvalError`;kind=`EvalError`},Qg=class extends Zg{name=`FuncNotFoundError`;kind=`FuncNotFoundError`;funcName;suggestions;constructor(e,t,n={}){let r=a_(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}},$g=class extends Zg{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}},e_=class extends Zg{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}},t_=class extends e_{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)}`}},n_=class extends Zg{name=`MissingFieldError`;kind=`MissingFieldError`;path;constructor(e,t,n={}){super(`field "${e.join(`.`)}" not found on receiver`,t,n),this.path=e}},r_=class extends Zg{name=`FailError`;kind=`FailError`;constructor(e,t={line:0,column:0,offset:0},n={}){super(e,t,n)}};function i_(e,t){let n=e.split(`
|
|
57
57
|
`),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(`
|
|
58
58
|
`)}function a_(e,t){if(t.length===0)return[];let n=t.map(t=>({name:t,dist:o_(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 o_(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 s_(e){throw Error(`unhandled node kind: ${JSON.stringify(e)}`)}const c_=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`]]),l_={left:`{{`,right:`}}`};var u_=class{src;leftDelim;rightDelim;offset=0;line=1;column=1;mode=`text`;pending;constructor(e,t=l_){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 Xg(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&&d_(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);d_(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);d_(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(;d_(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`;d_(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&&(p_(e)||f_(e)&&p_(this.src[this.offset+1]??``)||e===`.`&&p_(this.src[this.offset+1]??``)))return this.readNumber(t);if(e===`.`)return this.readDotOrField(t);if(e!==void 0&&v_(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===`
|
|
59
59
|
`)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===`
|
|
@@ -141,15 +141,15 @@ Config tooling:
|
|
|
141
141
|
config [--json] The effective merged config. (All three query the
|
|
142
142
|
running daemon; none spawn one.)
|
|
143
143
|
|
|
144
|
-
`,MD=`readableOn (mix (color "foreground") (bgOf) 60) (bgOf) 3`,ND={socket:`TMUX`,pane:`TMUX_PANE`,truecolor:`CLAUDE_CODE_TMUX_TRUECOLOR`};function PD(e){let t=e[ND.socket]??``,n=e[ND.pane]??``;if(t===``||n===``)return null;let r=e[ND.truecolor]??``;return{socket:t.split(`,`)[0],pane:n,truecolor:r===``?null:r}}const FD={kitty:`0.36.0`,wezterm:`20220319`,ghostty:null},ID=[{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
|
|
145
|
-
`).map(e=>e.trim()).filter(e=>e!==``),...e.warnings];return{ok:!1,reason:t,more:n}}case`loaded`:return YD([...e.warnings,...e.unused.map(({kind:e,name:t})=>`${e} "${t}" ${QD[e]}`)])}}},eO="re-run `cc-candybar install`";function tO(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:// — ${eO}`];let{app:t,missing:n}=e.value;return n.kind===`failed`?[`${t} opens cc-candybar://, but ${n.reason} — ${eO}`]:n.value.map(e=>`${e} is missing, and ${t} runs it — ${eO}`)}const nO={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}) — ${eO}`:`the URL handler runs cc-candybar ${e.handler}; the bar runs ${e.bar} — ${eO}`};case`lost`:return YD([...tO(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}`])}}},rO={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}}}},iO=e=>[...e].map(e=>`U+${e.codePointAt(0).toString(16).toUpperCase()}`).join(` `);function aO(e){switch(e.kind){case`unreported`:case`unasked`:return`this terminal`;case`unknown`:return e.called===``?`this terminal`:e.called;case`bundling`:case`configured`:return[RD[e.name],e.version].filter(e=>e!==null).join(` `)}}function oO(e){switch(e.kind){case`unreported`:case`unasked`:return null;case`unknown`:return e.called===``?null:e.called;case`bundling`:return RD[e.name];case`configured`:{let t=RD[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 sO(e){let t=oO(e.terminal);return t===null?void 0:{glyphs:e.glyphs,id:`${t}|${iO(e.glyphs)}`}}const cO=`or set globals.charset to "ascii" to draw the bar without them`,lO=[$D,nO,ZD,rO,{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=sO(e),r=e=>({ok:!1,reason:e,...n!==void 0&&{sighting:n}}),i=e.terminal,a=aO(i);switch(n===void 0?null:t.value.nerdFont?.[n.id]??null){case`drawn`:return{ok:!0};case`boxes`:return r(`${a} draws ${iO(e.glyphs)} as boxes — set a Nerd Font as its font, ${cO}`);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`:return r(`the doctor cannot read ${a}'s font`);case`bundling`:{let e=FD[i.name];if(e===null)return{ok:!0};let t=i.version===null?null:UD(i.version,e);if(t===!0)return{ok:!0};let n=RD[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, ${cO}`)}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, ${cO}`):n.length===0?{ok:!0}:r(`${a} draws with ${e} (${t}), which has no ${iO(n)} — set a Nerd Font as its font, ${cO}`)}}}}],uO=lO.filter(e=>e.takesMark);function dO(e){return lO.map(t=>({check:t,verdict:t.probe(e)}))}function fO(e){return lO.find(t=>t.name===e)}const pO=`${Y}doctor.`;function mO(e){let t=`${pO}${e}.`;return{verdict:`${t}verdict`,reason:`${t}reason`,fixable:`${t}fixable`,sighting:`${t}sighting`}}function hO(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`bundling`: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=sO(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 gO(e,t=[]){return t.length===0?e:`${e} (+${t.length} more — run \`cc-candybar doctor\`)`}function _O(e){return e.flatMap(({check:e,verdict:t})=>{let n=mO(e.name);return t.ok?[{key:n.verdict,value:`ok`},{key:n.reason,value:``},{key:n.fixable,value:em},{key:n.sighting,value:``}]:[{key:n.verdict,value:`failed`},{key:n.reason,value:gO(t.reason,t.more)},{key:n.fixable,value:t.fix===void 0?em:$p},{key:n.sighting,value:t.sighting?.glyphs??``}]})}const vO={copySession:{copy:`{{ .session.id }}`},copyResume:{copy:`{{ .resume_command }}`},openProject:{open:`{{ .project_dir }}`},openTranscript:{open:`{{ .transcript_path }}`},openConfig:{open:`{{ .config_path }}`}};function yO(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(vO).map(([t,n])=>[`${e}${t}`,n]))}}const bO=`armed`,xO=`disarmed`,SO=`.armed`,CO=e=>e.endsWith(SO);function wO(e,t,n){let r=`${e}${SO}`,i=`${e}.arm`,a=`${e}.disarm`,o=`(eq .${e} "${bO}")`;return{template:`{{ if ${o} }}{{ action "${e}" "${t.confirm}" }} {{ action "${a}" "✕" }}{{ else }}{{ action "${i}" "${t.arm}" }}{{ end }}`,actions:{[i]:{set:r,to:bO},[a]:{set:r,to:xO},[e]:{do:[a,...n]}},armed:o,variables:{[e]:{kind:`state`,key:r,default:xO}},disarm:a}}const TO=RegExp(`^/[^\\s\\x00-\\x1f\\x7f-\\x9f/][^\\x00-\\x1f\\x7f-\\x9f]*$`);function EO(e){return typeof e==`string`&&TO.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 DO(e){let t=EO(e);if(t.kind===`refused`)throw Error(t.reason);return t.line}const OO=[`/compact`,`/model`],kO=`/clear`;function AO(e){let t=t=>`${e}${t.slice(1)}`,n=`${e}clear.slash`,r=wO(`${e}clear`,{arm:kO,confirm:`${kO} ✓ confirm`},[n]);return{template:OO.map(e=>`{{ action "${t(e)}" "${e}" }} `).join(``)+r.template,when:`{{ ${tT} }}`,actions:{...Object.fromEntries(OO.map(e=>[t(e),{slash:DO(e)}])),...r.actions,[n]:{slash:DO(kO)}},variables:r.variables,disarm:r.disarm}}const jO=Array.from({length:10},(e,t)=>(t+1)*1e5),MO=jO[0],NO=jO[jO.length-1];function PO(e){let t;try{t=pi(e)}catch(e){return L(e instanceof Error?e.message:String(e))}let n=t.autoCompactWindow;return n===void 0?F(`auto`):typeof n==`number`&&Number.isInteger(n)&&n>=MO&&n<=NO?F(n):L(`${e}: autoCompactWindow is ${JSON.stringify(n)}, not a window /autocompact accepts (${MO}–${NO} tokens)`)}function FO(e,t){let n=Math.min(t??NO,NO),r=e===`auto`?n:Math.min(e,n);return{window:e===`auto`?0:e,applied:e===`auto`?0:r,lower:jO.filter(e=>e<r).at(-1)??0,higher:jO.find(e=>e>r&&e<=n)??0}}function IO(e,t){return{template:`{{ if ne .autocompact.error "" }}⇲ ⚠ {{ .autocompact.error }}{{ else }}⇲ {{ if eq .autocompact.window 0 }}auto{{ else }}${t(`.autocompact.applied`)}{{ end }}{{ if ${tT} }}{{ 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:DO(`/autocompact auto`)},...Object.fromEntries(jO.map(t=>[`${e}${t}`,{slash:DO(`/autocompact ${t}`)}]))}}}const LO=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 }}`,RO=`${Y}menu`,zO=`open`,BO=`${Y}edit`,VO=`${Y}toolbar`,HO=yO(Y),UO=`${Y}commands`,WO=AO(`${UO}.`),GO=`${Y}autocompact`,KO=IO(`${GO}.`,LO),qO=e=>({kind:`segment`,name:e}),JO=`${Y}tab`,YO=[{member:`session`,label:`⚡ session`},{member:`look`,label:`🎨 look`},{member:`layout`,label:`📐 layout`},{member:`config`,label:`⚙ config`},{member:`tools`,label:`🧰 tools`}],XO=e=>`${JO}.${e}`,ZO=e=>`${XO(e)}.toggle`,QO=e=>({variable:JO,key:JO,member:e}),$O=`${Y}save`,ek=`${Y}preset.save`,tk=`${Y}preset.delete`,nk=e=>`${Y}${e}`,rk=e=>`${Y}apply.${e}`,ik=e=>`${Y}reset.${e}`,ak=`${Y}themeDefault.save`,ok=`${Y}themeDefault.differs`,sk=`${Y}themeDefault.theme`,ck={when:`{{ .${ok} }}`,template:`{{ action "${ak}" (printf "⤓ default for %s" .${sk}) }} {{ swatch "${rk(`theme`)}" .${sk} }}`},lk=`${Y}resetAll`,uk=`${RO}.toggle`,dk={variable:RO,key:RO,member:zO},fk=`${Y}undo`,pk=`${Y}back`,mk=`${pk}.step`,hk=`${Y}navigation.back`,gk=pk,_k={template:`{{ if gt .${hk} 0 }}{{ action "${pk}" "◁" }}{{ else }}{{ fg (${MD}) "◁" }}{{ end }}`},vk=`${Y}redo`,yk=`${Y}doctor`,bk=`${yk}.run`,xk=e=>`${yk}.fix.${e}`,Sk=(e,t)=>`${yk}.mark.${e}.${t}`,Ck=e=>`${yk}.${e}`,wk={drawn:`[✓ shapes]`,boxes:`[✗ boxes]`},Tk=yT(`${Y}pickers`),Ek=`${Y}gear`,Dk=`gear`,Ok=`${Ek}.toggle`,kk={variable:Tk,key:Tk,member:Dk},Ak=yT(`${Y}gearPickers`),jk=[{template:`{{ themePreview }}`}],Mk={template:`{{ layoutPreview }}`},Nk={preset:[Mk,{when:`{{ not .preset.bundled }}`,template:`{{ action "${tk}" (printf "🚮 delete %s" .${ba.preset.effectiveVar}) }}`}],style:jk,variation:[Mk],shade:[Mk]},Pk=(e,t)=>`${Y}list.${e}.${t}`,Fk=e=>`${Y}resettable.${e}`,Ik=e=>e.length===0?`false`:`(or ${e.map(e=>`.${Fk(e)}`).join(` `)})`,Lk={preset:`door`,theme:`look`,style:`gear`,effect:`look`,variation:`gear`,shade:`gear`,endcaps:`look`,transitions:`look`,autoWrap:`layout`,padding:`layout`,updateNotice:`config`},Rk=e=>e===`gear`?Lk.theme:e,zk=Object.keys(ba).map(e=>{let t=ba[e],n=SE(t.configKey),r=jT({label:t.label,domain:n},t.sessionKey,t.effectiveVar,rk(e),Lk[e]===`gear`?Ak:Tk);return{...t,name:e,control:r,beneath:Nk[e]??[]}}),Bk=e=>zk.filter(t=>Lk[t.name]===e),Vk=e=>zk.filter(t=>Rk(Lk[t.name])===e),Hk={theme:[nr(Ek,kk,{kind:`container`,direction:`horizontal`,children:Bk(`gear`).map(tA)},`drop`)]},Uk=e=>Bk(e).flatMap(e=>[tA(e),...Hk[e.name]??[]]);new Set(zk.flatMap(e=>[e.sessionKey,e.configKey]));const Wk=wO(lk,{arm:`⟲`,confirm:`⟲ reset all?`},zk.map(e=>ik(e.name))),Gk=[`unsaved`,`history.undo`,`history.redo`],Kk=e=>`${Y}${e}`,qk=Kk(`unsaved`),Jk=(e,t)=>({body:t,shown:`(gt .${Kk(e)} 0)`}),Yk=[Jk(`unsaved`,`{{ action "${$O}" (printf "💾 save %d" .${qk}) }}`),Jk(`history.undo`,`{{ action "${fk}" "↶" }}`),Jk(`history.redo`,`{{ action "${vk}" "↷" }}`),{body:Wk.template,shown:`(or ${Ik(zk.map(e=>e.name))} ${Wk.armed})`}],Xk={when:`{{ or ${Yk.map(e=>e.shown).join(` `)} }}`,template:`{{ $sep := "" }}`+Yk.map(e=>`{{ if ${e.shown} }}{{ $sep }}${e.body}{{ $sep = " " }}{{ end }}`).join(``)},Zk=[{step:Wk,place:`door`},{step:WO,place:`session`}],Qk=e=>e.map(e=>e.step.disarm),$k=Qk(Zk),eA=Qk(Zk.filter(e=>e.place!==`door`));function tA(e){let t=nk(e.name);return e.control.kind===`inline`?qO(t):nr(t,e.control.list.ref,{kind:`container`,direction:`vertical`,children:[...e.control.list.rows,...e.beneath].map((t,n)=>qO(Pk(e.name,n)))},`drop`)}function nA(e){return e===RO}function rA(e){let t=qO(RO);if(e.kind===`container`&&e.direction===`vertical`){let[n,...r]=e.children;return e.when===void 0&&n!==void 0?{...e,children:[rA(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 iA(e){return aA(e)>0?e:rA(e)}function aA(e){let t=0;for(let n of bh(e))n.kind===`segment`&&nA(n.name)&&(t+=1);return t}function oA(e,t=!1){let n=t||e.when!==void 0;return e.kind===`segment`?n&&nA(e.name)||e.opens!==void 0&&oA(e.opens.body,!0):e.children.some(e=>oA(e,n))}const sA={session:{direction:`vertical`,content:[qO(VO),{kind:`container`,direction:`horizontal`,children:[qO(UO),qO(GO)]}],after:[]},look:{direction:`horizontal`,content:[],after:[qO(ak)]},layout:{direction:`horizontal`,content:[qO(ek),qO(BO)],after:[]},config:{direction:`horizontal`,content:[],after:[]},tools:{direction:`vertical`,content:[qO(yk),...lO.map(e=>qO(Ck(e.name)))],after:[]}},cA=e=>({kind:`container`,direction:sA[e].direction,children:[...sA[e].content,...Uk(e),...sA[e].after]});function lA(e){return e.kind===`segment`?nA(e.name)?nr(e.name,dk,dA,`above`):e:pA(e)}function uA(){return{kind:`container`,direction:`vertical`,children:[{kind:`container`,direction:`horizontal`,children:[qO(gk),...Uk(`door`),qO($O)]},{kind:`container`,direction:`horizontal`,children:YO.map(({member:e})=>nr(XO(e),QO(e),cA(e),`drop`))}]}}const dA=uA();function fA(e){let t=new Map;for(let e of bh(dA))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=`${RO}.fold.${iT(t)}`;return e.actions[i]={set:t,to:r.default},i})}function pA(e){return{...e,children:e.children.map(e=>lA(e))}}function mA(e){let t={variables:{[RO]:cr(RO,Zn)},actions:{[uk]:lr(RO,zO),[bk]:{doctor:`run`},[BO]:{do:[...lD]},...HO.actions,...WO.actions,...KO.actions,[$O]:{save:!0},[fk]:{undo:!0},[mk]:{back:!0},[pk]:{do:[mk,...$k]},[vk]:{redo:!0},[ek]:{preset:`save`},[ak]:{themeDefault:`save`},[tk]:{preset:`delete`,name:`{{ .${ba.preset.effectiveVar} }}`}},segments:{[RO]:{template:`{{ $door := ${or(RO,sr(e),sr(`✖`))} }}{{ if ${ir(dk)} }}{{ fg (keptOn (color "error") (bgOf)) $door }}{{ else }}{{ $door }}{{ end }}`},[VO]:{template:HO.template},[UO]:{template:WO.template,when:WO.when},[GO]:{template:KO.template,bg:KO.bg,when:KO.when},[gk]:_k,[$O]:Xk,[ak]:ck,[ek]:{template:`{{ action "${ek}" "+ preset" }}`},[yk]:{template:`{{ action "${bk}" "🩺 doctor" }}`},[BO]:{template:`{{ action "${BO}" "✎ arrange" "✎ done" }}`}}};t.variables[ok]={kind:`input`,path:`themeDefault.differs`,type:`boolean`,default:!1},t.variables[sk]={kind:`input`,path:`themeDefault.theme`,type:`string`,default:``},t.variables[hk]={kind:`input`,path:`navigation.back`,type:`number`,default:0};for(let e of Gk)t.variables[Kk(e)]={kind:`input`,path:e,type:`number`,default:0};t.variables[JO]=cr(JO,`session`);for(let{member:e,label:n}of YO){t.actions[ZO(e)]=lr(JO,e),t.actions[XO(e)]={do:[ZO(e),...eA]};let r=Ik(Vk(e).map(e=>e.name)),i=`(ternary ${sr(` •`)} "" ${r})`,a=e=>`(print ${sr(e)} ${i})`;t.segments[XO(e)]={template:`{{ ${or(XO(e),a(n),a(`▾ ${n}`))} }}`}}return Object.assign(t.variables,WO.variables,Wk.variables),gA(t),hA(t),t.actions[RO]={do:[uk,...$k,...fA(t)]},t}function hA(e){for(let t of lO){let n=mO(t.name),r=xk(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?JD:[];for(let n of i)e.actions[Sk(t.name,n)]={doctor:`mark`,check:t.name,mark:n};let a=i.map(e=>` {{ action "${Sk(t.name,e)}" "${wk[e]}" }}`).join(``);e.segments[Ck(t.name)]={when:`{{ ne .${n.verdict} "" }}`,template:`{{ if eq .${n.verdict} "ok" }}✓ ${t.label}{{ else }}✗ ${t.label} — {{ .${n.reason} }}{{ if eq .${n.fixable} "${$p}" }} {{ action "${r}" "[fix]" }}{{ end }}`+(a===``?``:`{{ if ne .${n.sighting} "" }} {{ .${n.sighting} }}${a}{{ end }}`)+`{{ end }}`}}}function gA(e){for(let t of zk){Object.assign(e.actions,t.control.actions);let n=ik(t.name);e.actions[n]={reset:t.configKey},e.variables[Fk(t.name)]={kind:`input`,path:`resettable.${t.name}`,type:`boolean`,default:!1};let r=`{{ if .${Fk(t.name)} }} {{ action "${n}" "↺" }}{{ end }}`;Object.assign(e.variables,t.control.variables),e.segments[nk(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[Pk(t.name,r)]=n})}Object.assign(e.actions,Wk.actions),e.actions[Ok]=lr(Tk,Dk),e.segments[Ek]={template:`{{ action "${Ok}" "⚙" }}`}}function _A(e){let{variables:t,actions:n}=vD();Object.assign(e.variables,t),Object.assign(e.actions,n)}function vA(e){let t=mA(e.globals.menuGlyph??`🍫`);_A(t);let n={...e.presets},r=[];for(let t of ng(e.presets)){let{node:i}=ag(e,t),a=lA(iA(i));r.push(a),n[t]={...ig(e.presets,t),root:a}}let i=rT(t,r,e);return{...e,variables:{...i,...e.variables,...t.variables},actions:{...e.actions,...t.actions},segments:{...e.segments,...t.segments},presets:n}}const yA=`${fT}live`,bA=[`☐ live`,`☑ live`],xA=`${fT}done`,SA=`${fT}cancel`,CA=`${fT}rewind`,wA=`${fT}changes`,TA=`(gt .${wA} 0)`,EA=`(or ${TA} (gt .${qk} 0))`,DA={variable:yA,key:yA,member:`open`};function OA(e){return`${fT}configuring.p${e}`}function kA(e){return`and ${ir(pD)} (not ${ir(DA)}) (ne .${OA(e)} "true")`}function AA(e){return{kind:`template`,template:`{{ or ${e.map(e=>`(eq .${oD} "${tr(e)}")`).join(` `)} false }}`}}function jA(e,t,n){return`{{ if ${kA(e)} }}${t}{{ else }}${n}{{ end }}`}const MA=`{{ and ${ir(pD)} .preset.customized }}`,NA=mT;function PA(e){return new Map([...ug(e),...IA(e)])}const FA=`${fT}addable`;function IA(e){return new Map([[FA,{members:Object.keys(e.segments).filter(e=>!NA(e)),library:{groups:nD.map(e=>({id:e,label:rD[e]})),entry:t=>{let n=e.segments[t];return{group:n.group??`other`,...n.description!==void 0&&{description:n.description}}}}}]])}function LA(e,t,n){return n.segments[e]={template:t,when:mD,bg:SD},{kind:`segment`,name:e}}function RA(e,t,n){let r=`${fT}${e.presetIdent}.remove.${t}`;return e.artifacts.actions[r]={persist:e.rootKey,removeSegment:n},`{{ fg (${`readableOn (color "error") (bgOf) ${zf}`}) (action "${r}" "✖") }}`}function zA(e){return`{{ if ${ir(pD)} }}${e}{{ end }}`}function BA(e,t){return e.reduce((e,t)=>`{{ if and ${ir(pD)} ${ir(t)} }}true{{ else }}${e}{{ end }}`,t)}function VA(e){return e.flatMap(e=>[...bh(e)].flatMap(e=>e.kind===`segment`&&e.opens?.ref.key===`edit.configure`?[e.opens.ref]:[]))}function HA(e,t,n){return`${dD}${e}.${t}.${n}`}function UA(e,t,n,r){let i=gh(n),a=`${fT}${e.presetIdent}`,o=fD(e.presetIdent,i);e.configured.push(o);let s=`${a}.configure.${t}`,c=yT(s),l=`${s}.fold`;e.artifacts.actions[l]={set:c,to:Zn},e.artifacts.actions[s]={do:[`${s}.open`,l]},e.artifacts.actions[`${s}.open`]={set:oD,to:o};let u={},d=Object.entries(r).map(([r,o])=>{let s=HA(e.presetIdent,i,r),l=`${dD}p${e.presetIdent}.d${t}.${r}`;e.artifacts.variables[l]={kind:`state`,key:s,default:Lh(n.settings?.[r]??o.default)},u[r]={id:i,key:s,variable:l};let d=`${a}.setting.${t}.${r}`,f=jT(kT(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 nr(d,f.list.ref,{kind:`container`,direction:`vertical`,children:p},`drop`)});return{term:`{{ action "${s}" "${OD}" }}`,ref:{variable:oD,key:oD,member:o},body:{kind:`container`,direction:`vertical`,children:d},drafts:u}}const WA=`${fT}label:`;function GA(e){if(e.startsWith(WA)){let t=e.slice(WA.length);return t.slice(t.indexOf(`:`)+1)}return e.startsWith(`edit.`)?void 0:e}function KA(e,t,n,r){let{artifacts:i}=n,a=gh(e),o=`${WA}${a}:${e.name}`;i.segments[o]={template:`{{ "${tr(a)}" }}`,...t.palette!==void 0&&{palette:t.palette}};let s=Object.fromEntries(Mh.flatMap(t=>{let n=e.settings?.[t];return n===void 0?[]:[[t,n]]}));return{...nr(o,r.ref,r.body,`drop`,BA([r.ref],`{{ ${kA(n.presetIdent)} }}`)),...Object.keys(s).length>0&&{settings:s},drafts:Object.fromEntries(Mh.map(e=>[e,r.drafts[e]]))}}function qA(e,t,n,r){let{presetIdent:i,artifacts:a}=e,o=`${fT}${i}.insert.${t}`,s=`${fT}${i}.insertSeg.${t}`;a.actions[o]={persist:e.rootKey,insertSegmentFrom:FA,anchor:n,relation:r};let c=_T(o),l=vT(s,o,void 0),u=xT(l),d=bT(l,c);return a.variables[l]=cr(l,Zn),a.variables[u]={kind:`state`,key:u,default:`0`},a.actions[d]=lr(l,c),a.actions[u]={set:u,int:!0},{host:s,template:`{{ $m := menu "${o}" "✚" "✕" }}{{ if ${ir({variable:l,key:l,member:c})} }}{{ $m }}{{ else }}{{ fg (${`readableOn (color "success") (bgOf) ${zf}`}) $m }}{{ end }}`}}function JA(e,t){let n=[],r=e.children.findIndex(e=>e.kind===`segment`&&!NA(e.name)),i=e=>JA(e,t);for(let[a,o]of e.children.entries()){if(o.kind===`container`){n.push(i(o));continue}let s=yh(o,i);if(NA(o.name)){n.push(s);continue}let c=gh(o),l=a===r?[qA(t,String(t.posCounter.n++),c,`before`)]:[],u=String(t.posCounter.n++),d=qA(t,u,c,`after`),f=RA(t,u,c),p=t.segments[o.name],m=UA(t,u,o,Nh(p)),h=zA(f),g=zA(m.term),_={kind:`container`,direction:`horizontal`,children:[...l.map(e=>LA(e.host,e.template,t.artifacts)),{...KA(o,p,t,m),lead:h,trail:g},{...s,when:jA(t.presetIdent,`false`,o.when??`true`),lead:h,trail:g,drafts:m.drafts},LA(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:BA(VA(n),jA(t.presetIdent,`true`,e.when))}}}function YA(e,t,n,r,i,a,o){let s=`${fT}${t}.resetLayout`,c=`${fT}${t}.customized`;return r.actions[s]={reset:n},r.segments[c]={template:`{{ action "${s}" "↺ reset layout" }}`,when:MA},{kind:`container`,direction:`vertical`,children:[{kind:`container`,direction:`horizontal`,children:[...i,{kind:`segment`,name:c},a]},XA(e,o)]}}function XA(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),XA(n,t)]}:{...e,children:[...e.children,t]}}function ZA(e,t,n,r,i,a){let{node:o}=ag(e,t),s={presetIdent:iT(t),rootKey:YE(t),segments:e.segments,artifacts:n,posCounter:{n:0},configured:[]},c=JA(o,s);return n.variables[OA(s.presetIdent)]=AA(s.configured),YA(c,s.presetIdent,s.rootKey,n,r,i,a)}function QA(e){let t={variables:{},actions:{},segments:{}},n=bD(`${fT}help`,AD,[pD],t);t.variables[yA]=cr(yA,Zn),t.actions[yA]=lr(yA,DA.member),t.segments[yA]={template:ar(yA,...bA),when:mD};let r={kind:`segment`,name:yA},i=n;t.variables[wA]={kind:`input`,path:`history.sinceEdit`,type:`number`,default:0},t.actions[xA]={do:[$O,...lD]},t.segments[xA]={template:`{{ if ${EA} }}{{ action "${xA}" "✓ save" }}{{ else }}{{ action "${xA}" "✓ done" }}{{ end }}`,when:mD},t.actions[CA]={rewind:!0},t.actions[SA]={do:[CA,...lD]},t.segments[SA]={template:`{{ action "${SA}" "↩ cancel" }}`,when:`{{ and ${ir(pD)} ${TA} }}`};let a=[{kind:`segment`,name:xA},{kind:`segment`,name:SA}],o={...e.presets},s=[];for(let n of ng(e.presets)){let c=ZA(e,n,t,a,r,i);s.push(c),o[n]={...ig(e.presets,n),root:c}}let c=rT(t,s,e);return{...e,variables:{...c,...e.variables,...t.variables},actions:{...e.actions,...t.actions},segments:{...e.segments,...t.segments},presets:o}}function $A(e){return e.op===`remove`?`remove:${e.target}`:`insert:${e.segment}:${e.anchor}:${e.relation}`}function ej(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 tj(e,t,n){let r=vh(e,new Set(n.map(_h).filter(e=>e.includes(t)).flat()));return r===e?{seg:e}:{seg:e,id:r}}const nj=/^-?\d+$/;function rj(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 ij(e){return t=>{if(!t)return{ok:!1,reason:`${e} value is required`};if(!nj.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 aj(e,t,n){return r=>r?nj.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 oj(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=>!nj.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 sj(e){return e===`config`?`set-config`:`set-state`}function cj(e,t,n){return t.kind===`int`?ij(`menu page "${e}"`):t.kind===`range`?aj(t.min,t.max,`${n} stepper "${e}"`):rj(t.allowed,`${n} "${e}"`,sj(n))}function lj(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:oj(e,n,t)}))}function uj(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 lj(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,cj(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 dj(e,t,n){let r=[],i=0,a=new WeakMap;return{register(n,a){let o={key:n,allowed:a};uj(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=uj(e,r,n(o),t);return a.set(o,{epoch:i,gate:c}),c}}}const fj=dj({},`config`,yj);function pj(e,t){return fj.register(e,t)}function mj(e){return fj.gateFor(e)}function hj(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:fg(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:[$A({op:`remove`,target:e.removeSegment})]}}]:`insertSegment`in e?[{key:e.persist,spec:{kind:`allow-list`,allowed:[$A({op:`insert`,segment:e.insertSegment,anchor:e.anchor,relation:e.relation})]}}]:`insertSegmentFrom`in e?[{key:e.persist,spec:{kind:`allow-list`,allowed:fg(e.insertSegmentFrom,t).members.map(t=>$A({op:`insert`,segment:t,anchor:e.anchor,relation:e.relation}))}}]:[{key:e.persist,spec:{kind:`range`,min:e.min,max:e.max}}]:[]}function gj(e,t){let n=WE(e).get(t);return n===void 0?null:String(n)}function _j(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?$E(n.persist):null;e?.scope===`preset-root`&&t.add(YE(e.preset))}return[...t].map(e=>({key:e,spec:{kind:`allow-list`,allowed:[]}}))}function vj(e){let t=PA(e);return[..._j(e),...Object.values(e.actions).flatMap(e=>hj(e,t))]}function yj(e){return lj(vj(e),`config`)}function bj(e,t){return{globals:{...t.globals,...e.globals??{}},variables:{...t.variables,...e.variables??{}},segments:Cj(t.segments,xj(t.segments,e.segments??{})),root:Qh(e.root??Gh,t.root),actions:{...t.actions,...e.actions??{}},styles:{...t.styles,...e.styles??{}},presets:Cj(t.presets,Sj(t.presets,e.presets??{})),themeDefaults:Cj(t.themeDefaults,e.themeDefaults??{}),editGlobals:{...t.editGlobals,...e.editGlobals??{}},helpers:{...t.helpers,...e.helpers??{}}}}function xj(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 Sj(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 Cj(e,t){return{...e,...Object.fromEntries(Object.entries(t).map(([t,n])=>[t,{...e[t],...n}]))}}function wj(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: ${Dh.join(`, `)})`,line:J(e.source,t.split(`.`))}),null):Dj(e,`${t}.cache`,n.cache)}function Tj(e){return{required:!0,json:Oj(),parse:(t,n,r,i)=>wj(t,n,i,e)??void 0}}const Ej={noun:`cache`,arms:{ttl:{json:{type:`string`},parse:(e,t,n)=>typeof n==`string`&&Aj(n)?{ttl:n}:WT(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 WT(e,t,`cache.watch_file must be a path string, got ${Z(n)}`);let r=nE(`cache.watch_file`,n);return r===null?{watch_file:n}:WT(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}:WT(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}:WT(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}:WT(e,t,`cache.never must be the literal boolean true, got ${Z(n)}`)}}};function Dj(e,t,n){return GT(e,Ej,t,n)}function Oj(){return lE(Ej)}const kj=/^(\d+(?:\.\d+)?)(ms|s|m|h)$/;function Aj(e){return kj.test(e)}function jj(e,t,n){if(n===void 0)return{};if(!RT(n))return e.issues.push({path:t,message:`${t} must be an object, got ${X(n)}`,line:J(e.source,t.split(`.`))}),{};let r={};for(let[i,a]of Object.entries(n)){let n=KT(e,rM,`${t}.${i}`,a);n!==null&&(r[i]=n)}return r}function Mj(){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 ${X(i)}`,line:J(e.source,t.split(`.`))});return}return i}}}function Nj(){return{required:!0,json:{enum:[...kh]},parse:(e,t,n,r)=>{let i=r.field;if(typeof i!=`string`||!kh.includes(i)){e.issues.push({path:`${t}.field`,message:`git field must be one of: ${kh.join(`, `)}, got ${JSON.stringify(i)}`,line:J(e.source,[...t.split(`.`),`field`])});return}return i}}}function Pj(){return{required:!1,json:{type:[`string`,`number`,`boolean`]},parse:(e,t,n,r)=>{let i=r.type;return PT(e,t,r,i===`number`||i===`boolean`||i===`string`?i:`string`)}}}const Fj={noun:`parse`,arms:{text:{json:{const:!0},parse:(e,t,n)=>n===!0?{text:!0}:WT(e,t,`parse.text must be the literal boolean true, got ${Z(n)}`)},regex:{json:{type:`string`},parse:(e,t,n)=>typeof n==`string`?Ij(e,t,n):WT(e,t,`parse.regex must be a pattern string, got ${Z(n)}`)},json:{json:{const:!0},parse:(e,t,n)=>n===!0?{json:!0}:WT(e,t,`parse.json must be the literal boolean true, got ${Z(n)}`)}}};function Ij(e,t,n){let r;try{new RegExp(n),r=RegExp(`${n}|`).exec(``).length-1}catch(n){return WT(e,t,`parse.regex is not a valid regular expression: ${n.message}`)}return r>=1?{regex:n}:WT(e,t,`parse.regex must contain a capture group — its group 1 is the value; got ${JSON.stringify(n)}`)}function Lj(){return{required:!1,json:lE(Fj),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:J(e.source,[...t.split(`.`),`regex`])}),r.parse===void 0?void 0:GT(e,Fj,`${t}.parse`,r.parse)??void 0)}}function Rj(){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)=>RT(r.parse)&&`json`in r.parse?zj(e,t,r.default):FT(e,t,r,`default`)}}function zj(e,t,n){if(n!==void 0)return Bj(n)?n:WT(e,`${t}.default`,`${t}.default must be a JSON value (a json-parsed source's document), got ${Z(n)}`)??void 0}function Bj(e){return e!==null&&Vj(e)}function Vj(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(Vj);let t=Object.getPrototypeOf(e);return(t===Object.prototype||t===null)&&Object.values(e).every(Vj)}default:return!1}}const Hj={value:Mj(),default:XT()},Uj={path:tE(),type:iE([`string`,`number`,`boolean`]),default:Pj()},Wj={name:tE(),default:XT()},Gj={path:rE(),readMode:iE([`whole`,`first-line`]),parse:Lj(),cache:Tj(`file`),default:Rj()},Kj={command:tE(),parse:Lj(),cache:Tj(`shell`),default:Rj()};function qj(e){return{cache:`${e}, so it takes no cache policy — delete the key`}}const Jj={template:tE(),default:XT()},Yj=qj(`a template variable recomputes whenever a variable it reads changes`),Xj={layout:tE(),default:XT()},Zj=qj(`a time variable reads the instant its render is drawn at`),Qj={field:Nj(),default:XT()},$j=qj(`a git variable is refreshed by the daemon's own watch on the repository`),eM={key:tE(),default:XT()},tM=`kind`;function nM(e,t,n={}){return{...qT(tM,e,t),parse:(r,i,a)=>{BT(r,n,i,a);let o=VT(r,t,i,a);return o===null?null:{kind:e,...o}}}}const rM={tag:tM,noun:`source kind`,memberNoun:`variable`,arms:{literal:nM(`literal`,Hj),input:nM(`input`,Uj),env:nM(`env`,Wj),file:nM(`file`,Gj),shell:nM(`shell`,Kj),template:nM(`template`,Jj,Yj),time:nM(`time`,Xj,Zj),git:nM(`git`,Qj,$j),state:nM(`state`,eM)}};function iM(){return cE(rM)}function aM(){return{type:`object`,additionalProperties:iM()}}const oM=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`,folder:`examples/plugins/lit`}]]);function sM(e){let t=oM.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 in cc-candybar's ${t.folder} — install that folder in a plugin root (docs/segment-authoring.md, "Installing a plugin instead of listing it"), then update this reference)`}}const cM=/^[A-Za-z_][A-Za-z0-9_]*$/,lM={pattern:cM.source},uM={anyOf:[{type:`boolean`},{type:`string`},{type:`integer`}]},dM={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`,...lM}}}]},default:uM}},fM=[`label`,`domain`,`default`],pM=[`min`,`max`,`step`,`atLeast`];function mM(e,t,n){e.issues.push({path:t,message:n,line:J(e.source,t.split(`.`))})}function hM(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 mM(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 mM(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?mM(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(RT(n)){let{min:r,max:i,step:a=1,atLeast:o}=n;return Object.keys(n).filter(e=>!pM.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}}:mM(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 mM(e,t,`domain must be "bool", a list of words, or { min, max }, got ${Z(n)}`)}function gM(e,t,n){if(!RT(n))return mM(e,t,`${t} must be { label, domain, default }, got ${X(n)}`);for(let r of Object.keys(n))fM.includes(r)||mM(e,`${t}.${r}`,`Unknown setting key "${r}". Expected one of: ${fM.join(`, `)}`);let{label:r}=n,i=typeof r==`string`&&r.length>0&&!/[\n\r]/.test(r);i||mM(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=hM(e,`${t}.domain`,n.domain);if(!i||a===void 0)return;let o={label:r,domain:a,default:n.default};return!_M(n.default)||!Ih(o,n.default)?mM(e,`${t}.default`,`default must be ${Bh(o)}, got ${Z(n.default)}`):o}function _M(e){return typeof e==`boolean`||typeof e==`string`||typeof e==`number`}const vM={theme:`its default for this segment is segments.<name>.palette, and a placement sets its own with settings: { ${Ah}: "<theme>" }`,effect:`a placement follows the bar's effect, or sets its own with settings: { effect: "<effect>" }`};function yM(e){return Mh.includes(e)}function bM(){return{required:!1,json:{type:`object`,propertyNames:{...lM,not:{enum:[...Mh]}},additionalProperties:dM},parse:(e,t,n,r)=>{let i=r[n];if(i===void 0)return;let a=`${t}.${n}`;if(!RT(i))return mM(e,a,`${a} must be an object of name → { label, domain, default }, got ${X(i)}`);let o=Object.create(null);for(let[t,n]of Object.entries(i)){if(!cM.test(t)){mM(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(yM(t)){mM(e,`${a}.${t}`,`setting "${t}" is one every placement already has — ${vM[t]}`);continue}let r=gM(e,`${a}.${t}`,n);r!==void 0&&(o[t]=r)}return o}}}const xM=pT.map(e=>e.replace(/\./g,`\\.`)).join(`|`);function SM(){return{required:!1,json:{type:`string`,minLength:1,pattern:`^(?!${xM})[^:/]+$`},parse:(e,t,n,r)=>{let i=r[n];if(i!==void 0)return typeof i==`string`&&i.length>0&&!/[:/]/.test(i)&&!mT(i)?i:mM(e,`${t}.${n}`,`a placement "id" must be a non-empty string without "/" or ":", outside the reserved ${pT.map(e=>`"${e}"`).join(`, `)} namespaces, got ${Z(i)}`)}}}function CM(){return{required:!1,json:{type:`object`,propertyNames:lM,additionalProperties:uM},parse:(e,t,n,r)=>{let i=r[n];if(i===void 0)return;let a=`${t}.${n}`;if(!RT(i))return mM(e,a,`a placement's "settings" must be an object of setting name → value, got ${X(i)}`);let o=Object.create(null);for(let[t,n]of Object.entries(i))_M(n)?o[t]=n:mM(e,`${a}.${t}`,`setting "${t}" must be a boolean, a word, or a number, got ${X(n)}`);return o}}}function wM(e){return new Set(Object.keys(e.segments).filter(e=>!mT(e)))}function TM(e,t,n){if(t===void 0)return{};if(!RT(t))return e.issues.push({path:`segments`,message:`segments must be an object, got ${X(t)}`,line:J(e.source,[`segments`])}),{};let r={};for(let[i,a]of Object.entries(t)){let t=zT(e,n.has(i)?jM:AM,`segments.${i}`,a);t!==null&&(r[i]=t)}return r}function EM(){return{required:!0,json:{type:`string`},parse:(e,t,n,r)=>r[n]===void 0?WT(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${sM(t.slice(9))}`)??void 0:NT(e,t,r,n)??void 0}}function DM(){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:J(e.source,[...t.split(`.`),n])})}}}}function OM(){return{required:!1,json:aM(),parse:(e,t,n,r)=>{let i=r[n];if(i!==void 0)return jj(e,`${t}.${n}`,i)}}}const kM={template:EM(),description:XT(),group:iE(tD),width:DM(),justify:iE(Vh),truncate:iE(Hh),bg:XT(),fg:XT(),when:XT(),palette:eE(),vars:OM(),settings:bM()},AM={noun:`segment key`,fields:kM},jM={noun:`segment key`,fields:{...kM,template:XT()}},MM=`#/definitions/LayoutNode`,NM={kind:`container`,direction:`vertical`,children:[]};function PM(e){return{required:!0,json:{const:e},parse:()=>e}}function FM(){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:J(e.source,[`root`])}),``)}}}function IM(){return{required:!0,json:{enum:[...mh]},parse:(e,t,n,r)=>{let i=r[n];return typeof i==`string`&&mh.includes(i)?i:(e.issues.push({path:`${t}.${n}`,message:`a container "direction" must be one of: ${mh.join(`, `)} (got ${JSON.stringify(i)})`,line:J(e.source,[`root`])}),`vertical`)}}}function LM(e){return{required:!0,json:{type:`array`,items:{$ref:MM}},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 ${X(a)}`,line:J(t.source,[`root`])}),[])}}}const RM={noun:`layout-node key`,fields:{kind:PM(`segment`),name:FM(),when:XT(),id:SM(),settings:CM()}},zM=()=>iE(hf),BM={noun:`layout-node key`,fields:{kind:PM(`container`),direction:IM(),children:LM(JT(()=>GM)),when:XT(),distribution:zM()}};function VM(){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:J(e.source,[`root`])}),``)}}}const HM={noun:`layout-node key`,fields:{seg:VM(),when:XT(),id:SM(),settings:CM()}},UM={noun:`layout-node key`,fields:{h:LM(JT(()=>GM)),when:XT(),distribution:zM()}},WM={noun:`layout-node key`,fields:{v:LM(JT(()=>GM)),when:XT(),distribution:zM()}},GM=(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:J(e.source,[`root`])}),NM):{kind:`segment`,name:n};if(!RT(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 ${X(n)}`,line:J(e.source,[`root`])}),NM;if(n.kind===`container`)return zT(e,BM,t,n)??NM;if(n.kind===`segment`)return zT(e,RM,t,n)??NM;if(n.kind===`cells`)return e.issues.push({path:t,message:`kind: "cells" is no longer supported — use the h-arm spelling instead:
|
|
144
|
+
`,MD=`readableOn (mix (color "foreground") (bgOf) 60) (bgOf) 3`,ND={socket:`TMUX`,pane:`TMUX_PANE`,truecolor:`CLAUDE_CODE_TMUX_TRUECOLOR`};function PD(e){let t=e[ND.socket]??``,n=e[ND.pane]??``;if(t===``||n===``)return null;let r=e[ND.truecolor]??``;return{socket:t.split(`,`)[0],pane:n,truecolor:r===``?null:r}}const FD={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:`20220319`}},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`}}},ID=e=>FD[e];function LD(e){return ID(e).glyphs.kind===`bundled`}function RD(e){return ID(e).glyphs.kind===`configured`}const zD=e=>ID(e).label,BD=[{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 VD(e,t){let n=t.codePointAt(0);return BD.some(({since:t,from:r,to:i})=>r<=n&&n<=i&&e!==null&&WD(e,t)===!0)}const HD=Object.keys(FD);function UD(e){let t=/^\d+(?:\.\d+)*/.exec(e);return t===null?null:t[0].split(`.`).map(Number)}function WD(e,t){let n=UD(e),r=UD(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 GD(e){for(let t of HD){let n=ID(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 KD(e){let t=HD.find(t=>ID(t).term===e);return t===void 0?null:{name:t,version:null}}function qD(e){let t=GD(e.termtype)??KD(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 JD(e){let t=e.TERM_PROGRAM,n=HD.find(e=>ID(e).program===t),r=n===void 0?KD(e.TERM):{name:n,version:ID(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 YD(e){switch(e.kind){case`known`:return zD(e.terminal.name);case`unknown`:return e.called;case`unnamed`:return e.term||null}}function XD(e){switch(e.kind){case`known`:return zD(e.terminal.name);case`unknown`:return e.called;case`unnamed`:return e.term||`this terminal`}}function ZD({name:e,version:t}){let n=ID(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=WD(t,n.since);return r===null?{kind:`unsaid`,since:n.since}:r?{kind:`draws`}:{kind:`older`,since:n.since,version:t}}const QD=HD.filter(e=>ID(e).links!==null).map(zD).join(`, `),$D=[`drawn`,`boxes`];function eO(e){let[t,...n]=e;return t===void 0?{ok:!0}:{ok:!1,reason:t,more:n}}const tO=ND.truecolor,nO={name:`tmuxTruecolor`,label:`tmux truecolor`,takesMark:!1,probe:({tmux:e,claudeSettings: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`:{if(e.client.kind===`failed`)return{ok:!1,reason:`tmux could not be asked: ${e.client.reason}`};if(e.client.value===null||!e.client.value.features.includes(`RGB`)||e.hint.truecolor!==null)return{ok:!0};let n=t.env[tO];return typeof n==`string`&&n!==``?{ok:!1,reason:`${tO} 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`,tO],value:`1`}}}}}},rO={variable:`is never read`,action:`is never clicked`,helper:`is never called`,segment:`is in no preset`},iO={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(`
|
|
145
|
+
`).map(e=>e.trim()).filter(e=>e!==``),...e.warnings];return{ok:!1,reason:t,more:n}}case`loaded`:return eO([...e.warnings,...e.unused.map(({kind:e,name:t})=>`${e} "${t}" ${rO[e]}`)])}}},aO="re-run `cc-candybar install`";function oO(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:// — ${aO}`];let{app:t,missing:n}=e.value;return n.kind===`failed`?[`${t} opens cc-candybar://, but ${n.reason} — ${aO}`]:n.value.map(e=>`${e} is missing, and ${t} runs it — ${aO}`)}const sO={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}) — ${aO}`:`the URL handler runs cc-candybar ${e.handler}; the bar runs ${e.bar} — ${aO}`};case`lost`:return eO([...oO(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}`])}}},cO=`click 🩺 doctor in the bar's settings menu: if it runs, links work`;function lO(e,t){let n=YD(e);return t.kind===`ok`&&n!==null&&t.value.includes(n)?{kind:`draws`}:e.kind===`known`?ZD(e.terminal):{kind:`unknown`}}function uO({identified:e,tmuxClient:t},n){let r=XD(e),i=lO(e,n),a=YD(e)===null?cO:`${cO}, 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: ${QD}`];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 dO={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 eO(uO(t,n))}}},fO={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}}}},pO=e=>[...e].map(e=>`U+${e.codePointAt(0).toString(16).toUpperCase()}`).join(` `);function mO(e){switch(e.kind){case`unreported`:case`unasked`:return`this terminal`;case`unknown`:case`unnamed`:return XD(e);case`bundling`:case`unread`:case`configured`:return[zD(e.name),e.version].filter(e=>e!==null).join(` `)}}function hO(e){switch(e.kind){case`unreported`:case`unasked`:return null;case`unknown`:case`unnamed`:return YD(e);case`bundling`:case`unread`:return zD(e.name);case`configured`:{let t=zD(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 gO(e){let t=hO(e.terminal);return t===null?void 0:{glyphs:e.glyphs,id:`${t}|${pO(e.glyphs)}`}}const _O=`or set globals.charset to "ascii" to draw the bar without them`,vO=[iO,sO,dO,nO,fO,{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=gO(e),r=e=>({ok:!1,reason:e,...n!==void 0&&{sighting:n}}),i=e.terminal,a=mO(i);switch(n===void 0?null:t.value.nerdFont?.[n.id]??null){case`drawn`:return{ok:!0};case`boxes`:return r(`${a} draws ${pO(e.glyphs)} as boxes — set a Nerd Font as its font, ${_O}`);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=FD[i.name].glyphs.since;if(e===null)return{ok:!0};let t=i.version===null?null:WD(i.version,e);if(t===!0)return{ok:!0};let n=zD(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, ${_O}`)}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, ${_O}`):n.length===0?{ok:!0}:r(`${a} draws with ${e} (${t}), which has no ${pO(n)} — set a Nerd Font as its font, ${_O}`)}}}}],yO=vO.filter(e=>e.takesMark);function bO(e){return vO.map(t=>({check:t,verdict:t.probe(e)}))}function xO(e){return vO.find(t=>t.name===e)}const SO=`${Y}doctor.`;function CO(e){let t=`${SO}${e}.`;return{verdict:`${t}verdict`,reason:`${t}reason`,fixable:`${t}fixable`,sighting:`${t}sighting`}}function wO(e,t){let n=e.kind===`seen`?e.tmuxClient:null,r=e.kind===`seen`?YD(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 TO(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=gO(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 EO(e,t=[]){return t.length===0?e:`${e} (+${t.length} more — run \`cc-candybar doctor\`)`}function DO(e){return e.flatMap(({check:e,verdict:t})=>{let n=CO(e.name);return t.ok?[{key:n.verdict,value:`ok`},{key:n.reason,value:``},{key:n.fixable,value:em},{key:n.sighting,value:``}]:[{key:n.verdict,value:`failed`},{key:n.reason,value:EO(t.reason,t.more)},{key:n.fixable,value:t.fix===void 0?em:$p},{key:n.sighting,value:t.sighting?.glyphs??``}]})}const OO={copySession:{copy:`{{ .session.id }}`},copyResume:{copy:`{{ .resume_command }}`},openProject:{open:`{{ .project_dir }}`},openTranscript:{open:`{{ .transcript_path }}`},openConfig:{open:`{{ .config_path }}`}};function kO(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(OO).map(([t,n])=>[`${e}${t}`,n]))}}const AO=`armed`,jO=`disarmed`,MO=`.armed`,NO=e=>e.endsWith(MO);function PO(e,t,n){let r=`${e}${MO}`,i=`${e}.arm`,a=`${e}.disarm`,o=`(eq .${e} "${AO}")`;return{template:`{{ if ${o} }}{{ action "${e}" "${t.confirm}" }} {{ action "${a}" "✕" }}{{ else }}{{ action "${i}" "${t.arm}" }}{{ end }}`,actions:{[i]:{set:r,to:AO},[a]:{set:r,to:jO},[e]:{do:[a,...n]}},armed:o,variables:{[e]:{kind:`state`,key:r,default:jO}},disarm:a}}const FO=RegExp(`^/[^\\s\\x00-\\x1f\\x7f-\\x9f/][^\\x00-\\x1f\\x7f-\\x9f]*$`);function IO(e){return typeof e==`string`&&FO.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 LO(e){let t=IO(e);if(t.kind===`refused`)throw Error(t.reason);return t.line}const RO=[`/compact`,`/model`],zO=`/clear`;function BO(e){let t=t=>`${e}${t.slice(1)}`,n=`${e}clear.slash`,r=PO(`${e}clear`,{arm:zO,confirm:`${zO} ✓ confirm`},[n]);return{template:RO.map(e=>`{{ action "${t(e)}" "${e}" }} `).join(``)+r.template,when:`{{ ${tT} }}`,actions:{...Object.fromEntries(RO.map(e=>[t(e),{slash:LO(e)}])),...r.actions,[n]:{slash:LO(zO)}},variables:r.variables,disarm:r.disarm}}const VO=Array.from({length:10},(e,t)=>(t+1)*1e5),HO=VO[0],UO=VO[VO.length-1];function WO(e){let t;try{t=pi(e)}catch(e){return L(e instanceof Error?e.message:String(e))}let n=t.autoCompactWindow;return n===void 0?F(`auto`):typeof n==`number`&&Number.isInteger(n)&&n>=HO&&n<=UO?F(n):L(`${e}: autoCompactWindow is ${JSON.stringify(n)}, not a window /autocompact accepts (${HO}–${UO} tokens)`)}function GO(e,t){let n=Math.min(t??UO,UO),r=e===`auto`?n:Math.min(e,n);return{window:e===`auto`?0:e,applied:e===`auto`?0:r,lower:VO.filter(e=>e<r).at(-1)??0,higher:VO.find(e=>e>r&&e<=n)??0}}function KO(e,t){return{template:`{{ if ne .autocompact.error "" }}⇲ ⚠ {{ .autocompact.error }}{{ else }}⇲ {{ if eq .autocompact.window 0 }}auto{{ else }}${t(`.autocompact.applied`)}{{ end }}{{ if ${tT} }}{{ 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:LO(`/autocompact auto`)},...Object.fromEntries(VO.map(t=>[`${e}${t}`,{slash:LO(`/autocompact ${t}`)}]))}}}const qO=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 }}`,JO=`${Y}menu`,YO=`open`,XO=`${Y}edit`,ZO=`${Y}toolbar`,QO=kO(Y),$O=`${Y}commands`,ek=BO(`${$O}.`),tk=`${Y}autocompact`,nk=KO(`${tk}.`,qO),rk=e=>({kind:`segment`,name:e}),ik=`${Y}tab`,ak=[{member:`session`,label:`⚡ session`},{member:`look`,label:`🎨 look`},{member:`layout`,label:`📐 layout`},{member:`config`,label:`⚙ config`},{member:`tools`,label:`🧰 tools`}],ok=e=>`${ik}.${e}`,sk=e=>`${ok(e)}.toggle`,ck=e=>({variable:ik,key:ik,member:e}),lk=`${Y}save`,uk=`${Y}preset.save`,dk=`${Y}preset.delete`,fk=e=>`${Y}${e}`,pk=e=>`${Y}apply.${e}`,mk=e=>`${Y}reset.${e}`,hk=`${Y}themeDefault.save`,gk=`${Y}themeDefault.differs`,_k=`${Y}themeDefault.theme`,vk={when:`{{ .${gk} }}`,template:`{{ action "${hk}" (printf "⤓ default for %s" .${_k}) }} {{ swatch "${pk(`theme`)}" .${_k} }}`},yk=`${Y}resetAll`,bk=`${JO}.toggle`,xk={variable:JO,key:JO,member:YO},Sk=`${Y}undo`,Ck=`${Y}back`,wk=`${Ck}.step`,Tk=`${Y}navigation.back`,Ek=Ck,Dk={template:`{{ if gt .${Tk} 0 }}{{ action "${Ck}" "◁" }}{{ else }}{{ fg (${MD}) "◁" }}{{ end }}`},Ok=`${Y}redo`,kk=`${Y}doctor`,Ak=`${kk}.run`,jk=e=>`${kk}.fix.${e}`,Mk=(e,t)=>`${kk}.mark.${e}.${t}`,Nk=e=>`${kk}.${e}`,Pk={drawn:`[✓ shapes]`,boxes:`[✗ boxes]`},Fk=yT(`${Y}pickers`),Ik=`${Y}gear`,Lk=`gear`,Rk=`${Ik}.toggle`,zk={variable:Fk,key:Fk,member:Lk},Bk=yT(`${Y}gearPickers`),Vk=[{template:`{{ themePreview }}`}],Hk={template:`{{ layoutPreview }}`},Uk={preset:[Hk,{when:`{{ not .preset.bundled }}`,template:`{{ action "${dk}" (printf "🚮 delete %s" .${ba.preset.effectiveVar}) }}`}],style:Vk,variation:[Hk],shade:[Hk]},Wk=(e,t)=>`${Y}list.${e}.${t}`,Gk=e=>`${Y}resettable.${e}`,Kk=e=>e.length===0?`false`:`(or ${e.map(e=>`.${Gk(e)}`).join(` `)})`,qk={preset:`door`,theme:`look`,style:`gear`,effect:`look`,variation:`gear`,shade:`gear`,endcaps:`look`,transitions:`look`,autoWrap:`layout`,padding:`layout`,updateNotice:`config`},Jk=e=>e===`gear`?qk.theme:e,Yk=Object.keys(ba).map(e=>{let t=ba[e],n=SE(t.configKey),r=jT({label:t.label,domain:n},t.sessionKey,t.effectiveVar,pk(e),qk[e]===`gear`?Bk:Fk);return{...t,name:e,control:r,beneath:Uk[e]??[]}}),Xk=e=>Yk.filter(t=>qk[t.name]===e),Zk=e=>Yk.filter(t=>Jk(qk[t.name])===e),Qk={theme:[nr(Ik,zk,{kind:`container`,direction:`horizontal`,children:Xk(`gear`).map(dA)},`drop`)]},$k=e=>Xk(e).flatMap(e=>[dA(e),...Qk[e.name]??[]]);new Set(Yk.flatMap(e=>[e.sessionKey,e.configKey]));const eA=PO(yk,{arm:`⟲`,confirm:`⟲ reset all?`},Yk.map(e=>mk(e.name))),tA=[`unsaved`,`history.undo`,`history.redo`],nA=e=>`${Y}${e}`,rA=nA(`unsaved`),iA=(e,t)=>({body:t,shown:`(gt .${nA(e)} 0)`}),aA=[iA(`unsaved`,`{{ action "${lk}" (printf "💾 save %d" .${rA}) }}`),iA(`history.undo`,`{{ action "${Sk}" "↶" }}`),iA(`history.redo`,`{{ action "${Ok}" "↷" }}`),{body:eA.template,shown:`(or ${Kk(Yk.map(e=>e.name))} ${eA.armed})`}],oA={when:`{{ or ${aA.map(e=>e.shown).join(` `)} }}`,template:`{{ $sep := "" }}`+aA.map(e=>`{{ if ${e.shown} }}{{ $sep }}${e.body}{{ $sep = " " }}{{ end }}`).join(``)},sA=[{step:eA,place:`door`},{step:ek,place:`session`}],cA=e=>e.map(e=>e.step.disarm),lA=cA(sA),uA=cA(sA.filter(e=>e.place!==`door`));function dA(e){let t=fk(e.name);return e.control.kind===`inline`?rk(t):nr(t,e.control.list.ref,{kind:`container`,direction:`vertical`,children:[...e.control.list.rows,...e.beneath].map((t,n)=>rk(Wk(e.name,n)))},`drop`)}function fA(e){return e===JO}function pA(e){let t=rk(JO);if(e.kind===`container`&&e.direction===`vertical`){let[n,...r]=e.children;return e.when===void 0&&n!==void 0?{...e,children:[pA(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 mA(e){return hA(e)>0?e:pA(e)}function hA(e){let t=0;for(let n of bh(e))n.kind===`segment`&&fA(n.name)&&(t+=1);return t}function gA(e,t=!1){let n=t||e.when!==void 0;return e.kind===`segment`?n&&fA(e.name)||e.opens!==void 0&&gA(e.opens.body,!0):e.children.some(e=>gA(e,n))}const _A={session:{direction:`vertical`,content:[rk(ZO),{kind:`container`,direction:`horizontal`,children:[rk($O),rk(tk)]}],after:[]},look:{direction:`horizontal`,content:[],after:[rk(hk)]},layout:{direction:`horizontal`,content:[rk(uk),rk(XO)],after:[]},config:{direction:`horizontal`,content:[],after:[]},tools:{direction:`vertical`,content:[rk(kk),...vO.map(e=>rk(Nk(e.name)))],after:[]}},vA=e=>({kind:`container`,direction:_A[e].direction,children:[..._A[e].content,...$k(e),..._A[e].after]});function yA(e){return e.kind===`segment`?fA(e.name)?nr(e.name,xk,xA,`above`):e:CA(e)}function bA(){return{kind:`container`,direction:`vertical`,children:[{kind:`container`,direction:`horizontal`,children:[rk(Ek),...$k(`door`),rk(lk)]},{kind:`container`,direction:`horizontal`,children:ak.map(({member:e})=>nr(ok(e),ck(e),vA(e),`drop`))}]}}const xA=bA();function SA(e){let t=new Map;for(let e of bh(xA))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=`${JO}.fold.${iT(t)}`;return e.actions[i]={set:t,to:r.default},i})}function CA(e){return{...e,children:e.children.map(e=>yA(e))}}function wA(e){let t={variables:{[JO]:cr(JO,Zn)},actions:{[bk]:lr(JO,YO),[Ak]:{doctor:`run`},[XO]:{do:[...lD]},...QO.actions,...ek.actions,...nk.actions,[lk]:{save:!0},[Sk]:{undo:!0},[wk]:{back:!0},[Ck]:{do:[wk,...lA]},[Ok]:{redo:!0},[uk]:{preset:`save`},[hk]:{themeDefault:`save`},[dk]:{preset:`delete`,name:`{{ .${ba.preset.effectiveVar} }}`}},segments:{[JO]:{template:`{{ $door := ${or(JO,sr(e),sr(`✖`))} }}{{ if ${ir(xk)} }}{{ fg (keptOn (color "error") (bgOf)) $door }}{{ else }}{{ $door }}{{ end }}`},[ZO]:{template:QO.template},[$O]:{template:ek.template,when:ek.when},[tk]:{template:nk.template,bg:nk.bg,when:nk.when},[Ek]:Dk,[lk]:oA,[hk]:vk,[uk]:{template:`{{ action "${uk}" "+ preset" }}`},[kk]:{template:`{{ action "${Ak}" "🩺 doctor" }}`},[XO]:{template:`{{ action "${XO}" "✎ arrange" "✎ done" }}`}}};t.variables[gk]={kind:`input`,path:`themeDefault.differs`,type:`boolean`,default:!1},t.variables[_k]={kind:`input`,path:`themeDefault.theme`,type:`string`,default:``},t.variables[Tk]={kind:`input`,path:`navigation.back`,type:`number`,default:0};for(let e of tA)t.variables[nA(e)]={kind:`input`,path:e,type:`number`,default:0};t.variables[ik]=cr(ik,`session`);for(let{member:e,label:n}of ak){t.actions[sk(e)]=lr(ik,e),t.actions[ok(e)]={do:[sk(e),...uA]};let r=Kk(Zk(e).map(e=>e.name)),i=`(ternary ${sr(` •`)} "" ${r})`,a=e=>`(print ${sr(e)} ${i})`;t.segments[ok(e)]={template:`{{ ${or(ok(e),a(n),a(`▾ ${n}`))} }}`}}return Object.assign(t.variables,ek.variables,eA.variables),EA(t),TA(t),t.actions[JO]={do:[bk,...lA,...SA(t)]},t}function TA(e){for(let t of vO){let n=CO(t.name),r=jk(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?$D:[];for(let n of i)e.actions[Mk(t.name,n)]={doctor:`mark`,check:t.name,mark:n};let a=i.map(e=>` {{ action "${Mk(t.name,e)}" "${Pk[e]}" }}`).join(``);e.segments[Nk(t.name)]={when:`{{ ne .${n.verdict} "" }}`,template:`{{ if eq .${n.verdict} "ok" }}✓ ${t.label}{{ else }}✗ ${t.label} — {{ .${n.reason} }}{{ if eq .${n.fixable} "${$p}" }} {{ action "${r}" "[fix]" }}{{ end }}`+(a===``?``:`{{ if ne .${n.sighting} "" }} {{ .${n.sighting} }}${a}{{ end }}`)+`{{ end }}`}}}function EA(e){for(let t of Yk){Object.assign(e.actions,t.control.actions);let n=mk(t.name);e.actions[n]={reset:t.configKey},e.variables[Gk(t.name)]={kind:`input`,path:`resettable.${t.name}`,type:`boolean`,default:!1};let r=`{{ if .${Gk(t.name)} }} {{ action "${n}" "↺" }}{{ end }}`;Object.assign(e.variables,t.control.variables),e.segments[fk(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[Wk(t.name,r)]=n})}Object.assign(e.actions,eA.actions),e.actions[Rk]=lr(Fk,Lk),e.segments[Ik]={template:`{{ action "${Rk}" "⚙" }}`}}function DA(e){let{variables:t,actions:n}=vD();Object.assign(e.variables,t),Object.assign(e.actions,n)}function OA(e){let t=wA(e.globals.menuGlyph??`🍫`);DA(t);let n={...e.presets},r=[];for(let t of ng(e.presets)){let{node:i}=ag(e,t),a=yA(mA(i));r.push(a),n[t]={...ig(e.presets,t),root:a}}let i=rT(t,r,e);return{...e,variables:{...i,...e.variables,...t.variables},actions:{...e.actions,...t.actions},segments:{...e.segments,...t.segments},presets:n}}const kA=`${fT}live`,AA=[`☐ live`,`☑ live`],jA=`${fT}done`,MA=`${fT}cancel`,NA=`${fT}rewind`,PA=`${fT}changes`,FA=`(gt .${PA} 0)`,IA=`(or ${FA} (gt .${rA} 0))`,LA={variable:kA,key:kA,member:`open`};function RA(e){return`${fT}configuring.p${e}`}function zA(e){return`and ${ir(pD)} (not ${ir(LA)}) (ne .${RA(e)} "true")`}function BA(e){return{kind:`template`,template:`{{ or ${e.map(e=>`(eq .${oD} "${tr(e)}")`).join(` `)} false }}`}}function VA(e,t,n){return`{{ if ${zA(e)} }}${t}{{ else }}${n}{{ end }}`}const HA=`{{ and ${ir(pD)} .preset.customized }}`,UA=mT;function WA(e){return new Map([...ug(e),...KA(e)])}const GA=`${fT}addable`;function KA(e){return new Map([[GA,{members:Object.keys(e.segments).filter(e=>!UA(e)),library:{groups:nD.map(e=>({id:e,label:rD[e]})),entry:t=>{let n=e.segments[t];return{group:n.group??`other`,...n.description!==void 0&&{description:n.description}}}}}]])}function qA(e,t,n){return n.segments[e]={template:t,when:mD,bg:SD},{kind:`segment`,name:e}}function JA(e,t,n){let r=`${fT}${e.presetIdent}.remove.${t}`;return e.artifacts.actions[r]={persist:e.rootKey,removeSegment:n},`{{ fg (${`readableOn (color "error") (bgOf) ${zf}`}) (action "${r}" "✖") }}`}function YA(e){return`{{ if ${ir(pD)} }}${e}{{ end }}`}function XA(e,t){return e.reduce((e,t)=>`{{ if and ${ir(pD)} ${ir(t)} }}true{{ else }}${e}{{ end }}`,t)}function ZA(e){return e.flatMap(e=>[...bh(e)].flatMap(e=>e.kind===`segment`&&e.opens?.ref.key===`edit.configure`?[e.opens.ref]:[]))}function QA(e,t,n){return`${dD}${e}.${t}.${n}`}function $A(e,t,n,r){let i=gh(n),a=`${fT}${e.presetIdent}`,o=fD(e.presetIdent,i);e.configured.push(o);let s=`${a}.configure.${t}`,c=yT(s),l=`${s}.fold`;e.artifacts.actions[l]={set:c,to:Zn},e.artifacts.actions[s]={do:[`${s}.open`,l]},e.artifacts.actions[`${s}.open`]={set:oD,to:o};let u={},d=Object.entries(r).map(([r,o])=>{let s=QA(e.presetIdent,i,r),l=`${dD}p${e.presetIdent}.d${t}.${r}`;e.artifacts.variables[l]={kind:`state`,key:s,default:Lh(n.settings?.[r]??o.default)},u[r]={id:i,key:s,variable:l};let d=`${a}.setting.${t}.${r}`,f=jT(kT(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 nr(d,f.list.ref,{kind:`container`,direction:`vertical`,children:p},`drop`)});return{term:`{{ action "${s}" "${OD}" }}`,ref:{variable:oD,key:oD,member:o},body:{kind:`container`,direction:`vertical`,children:d},drafts:u}}const ej=`${fT}label:`;function tj(e){if(e.startsWith(ej)){let t=e.slice(ej.length);return t.slice(t.indexOf(`:`)+1)}return e.startsWith(`edit.`)?void 0:e}function nj(e,t,n,r){let{artifacts:i}=n,a=gh(e),o=`${ej}${a}:${e.name}`;i.segments[o]={template:`{{ "${tr(a)}" }}`,...t.palette!==void 0&&{palette:t.palette}};let s=Object.fromEntries(Mh.flatMap(t=>{let n=e.settings?.[t];return n===void 0?[]:[[t,n]]}));return{...nr(o,r.ref,r.body,`drop`,XA([r.ref],`{{ ${zA(n.presetIdent)} }}`)),...Object.keys(s).length>0&&{settings:s},drafts:Object.fromEntries(Mh.map(e=>[e,r.drafts[e]]))}}function rj(e,t,n,r){let{presetIdent:i,artifacts:a}=e,o=`${fT}${i}.insert.${t}`,s=`${fT}${i}.insertSeg.${t}`;a.actions[o]={persist:e.rootKey,insertSegmentFrom:GA,anchor:n,relation:r};let c=_T(o),l=vT(s,o,void 0),u=xT(l),d=bT(l,c);return a.variables[l]=cr(l,Zn),a.variables[u]={kind:`state`,key:u,default:`0`},a.actions[d]=lr(l,c),a.actions[u]={set:u,int:!0},{host:s,template:`{{ $m := menu "${o}" "✚" "✕" }}{{ if ${ir({variable:l,key:l,member:c})} }}{{ $m }}{{ else }}{{ fg (${`readableOn (color "success") (bgOf) ${zf}`}) $m }}{{ end }}`}}function ij(e,t){let n=[],r=e.children.findIndex(e=>e.kind===`segment`&&!UA(e.name)),i=e=>ij(e,t);for(let[a,o]of e.children.entries()){if(o.kind===`container`){n.push(i(o));continue}let s=yh(o,i);if(UA(o.name)){n.push(s);continue}let c=gh(o),l=a===r?[rj(t,String(t.posCounter.n++),c,`before`)]:[],u=String(t.posCounter.n++),d=rj(t,u,c,`after`),f=JA(t,u,c),p=t.segments[o.name],m=$A(t,u,o,Nh(p)),h=YA(f),g=YA(m.term),_={kind:`container`,direction:`horizontal`,children:[...l.map(e=>qA(e.host,e.template,t.artifacts)),{...nj(o,p,t,m),lead:h,trail:g},{...s,when:VA(t.presetIdent,`false`,o.when??`true`),lead:h,trail:g,drafts:m.drafts},qA(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:XA(ZA(n),VA(t.presetIdent,`true`,e.when))}}}function aj(e,t,n,r,i,a,o){let s=`${fT}${t}.resetLayout`,c=`${fT}${t}.customized`;return r.actions[s]={reset:n},r.segments[c]={template:`{{ action "${s}" "↺ reset layout" }}`,when:HA},{kind:`container`,direction:`vertical`,children:[{kind:`container`,direction:`horizontal`,children:[...i,{kind:`segment`,name:c},a]},oj(e,o)]}}function oj(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),oj(n,t)]}:{...e,children:[...e.children,t]}}function sj(e,t,n,r,i,a){let{node:o}=ag(e,t),s={presetIdent:iT(t),rootKey:YE(t),segments:e.segments,artifacts:n,posCounter:{n:0},configured:[]},c=ij(o,s);return n.variables[RA(s.presetIdent)]=BA(s.configured),aj(c,s.presetIdent,s.rootKey,n,r,i,a)}function cj(e){let t={variables:{},actions:{},segments:{}},n=bD(`${fT}help`,AD,[pD],t);t.variables[kA]=cr(kA,Zn),t.actions[kA]=lr(kA,LA.member),t.segments[kA]={template:ar(kA,...AA),when:mD};let r={kind:`segment`,name:kA},i=n;t.variables[PA]={kind:`input`,path:`history.sinceEdit`,type:`number`,default:0},t.actions[jA]={do:[lk,...lD]},t.segments[jA]={template:`{{ if ${IA} }}{{ action "${jA}" "✓ save" }}{{ else }}{{ action "${jA}" "✓ done" }}{{ end }}`,when:mD},t.actions[NA]={rewind:!0},t.actions[MA]={do:[NA,...lD]},t.segments[MA]={template:`{{ action "${MA}" "↩ cancel" }}`,when:`{{ and ${ir(pD)} ${FA} }}`};let a=[{kind:`segment`,name:jA},{kind:`segment`,name:MA}],o={...e.presets},s=[];for(let n of ng(e.presets)){let c=sj(e,n,t,a,r,i);s.push(c),o[n]={...ig(e.presets,n),root:c}}let c=rT(t,s,e);return{...e,variables:{...c,...e.variables,...t.variables},actions:{...e.actions,...t.actions},segments:{...e.segments,...t.segments},presets:o}}function lj(e){return e.op===`remove`?`remove:${e.target}`:`insert:${e.segment}:${e.anchor}:${e.relation}`}function uj(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 dj(e,t,n){let r=vh(e,new Set(n.map(_h).filter(e=>e.includes(t)).flat()));return r===e?{seg:e}:{seg:e,id:r}}const fj=/^-?\d+$/;function pj(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 mj(e){return t=>{if(!t)return{ok:!1,reason:`${e} value is required`};if(!fj.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 hj(e,t,n){return r=>r?fj.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 gj(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=>!fj.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 _j(e){return e===`config`?`set-config`:`set-state`}function vj(e,t,n){return t.kind===`int`?mj(`menu page "${e}"`):t.kind===`range`?hj(t.min,t.max,`${n} stepper "${e}"`):pj(t.allowed,`${n} "${e}"`,_j(n))}function yj(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:gj(e,n,t)}))}function bj(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 yj(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,vj(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 xj(e,t,n){let r=[],i=0,a=new WeakMap;return{register(n,a){let o={key:n,allowed:a};bj(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=bj(e,r,n(o),t);return a.set(o,{epoch:i,gate:c}),c}}}const Sj=xj({},`config`,kj);function Cj(e,t){return Sj.register(e,t)}function wj(e){return Sj.gateFor(e)}function Tj(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:fg(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:[lj({op:`remove`,target:e.removeSegment})]}}]:`insertSegment`in e?[{key:e.persist,spec:{kind:`allow-list`,allowed:[lj({op:`insert`,segment:e.insertSegment,anchor:e.anchor,relation:e.relation})]}}]:`insertSegmentFrom`in e?[{key:e.persist,spec:{kind:`allow-list`,allowed:fg(e.insertSegmentFrom,t).members.map(t=>lj({op:`insert`,segment:t,anchor:e.anchor,relation:e.relation}))}}]:[{key:e.persist,spec:{kind:`range`,min:e.min,max:e.max}}]:[]}function Ej(e,t){let n=WE(e).get(t);return n===void 0?null:String(n)}function Dj(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?$E(n.persist):null;e?.scope===`preset-root`&&t.add(YE(e.preset))}return[...t].map(e=>({key:e,spec:{kind:`allow-list`,allowed:[]}}))}function Oj(e){let t=WA(e);return[...Dj(e),...Object.values(e.actions).flatMap(e=>Tj(e,t))]}function kj(e){return yj(Oj(e),`config`)}function Aj(e,t){return{globals:{...t.globals,...e.globals??{}},variables:{...t.variables,...e.variables??{}},segments:Nj(t.segments,jj(t.segments,e.segments??{})),root:Qh(e.root??Gh,t.root),actions:{...t.actions,...e.actions??{}},styles:{...t.styles,...e.styles??{}},presets:Nj(t.presets,Mj(t.presets,e.presets??{})),themeDefaults:Nj(t.themeDefaults,e.themeDefaults??{}),editGlobals:{...t.editGlobals,...e.editGlobals??{}},helpers:{...t.helpers,...e.helpers??{}}}}function jj(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 Mj(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 Nj(e,t){return{...e,...Object.fromEntries(Object.entries(t).map(([t,n])=>[t,{...e[t],...n}]))}}function Pj(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: ${Dh.join(`, `)})`,line:J(e.source,t.split(`.`))}),null):Lj(e,`${t}.cache`,n.cache)}function Fj(e){return{required:!0,json:Rj(),parse:(t,n,r,i)=>Pj(t,n,i,e)??void 0}}const Ij={noun:`cache`,arms:{ttl:{json:{type:`string`},parse:(e,t,n)=>typeof n==`string`&&Bj(n)?{ttl:n}:WT(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 WT(e,t,`cache.watch_file must be a path string, got ${Z(n)}`);let r=nE(`cache.watch_file`,n);return r===null?{watch_file:n}:WT(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}:WT(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}:WT(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}:WT(e,t,`cache.never must be the literal boolean true, got ${Z(n)}`)}}};function Lj(e,t,n){return GT(e,Ij,t,n)}function Rj(){return lE(Ij)}const zj=/^(\d+(?:\.\d+)?)(ms|s|m|h)$/;function Bj(e){return zj.test(e)}function Vj(e,t,n){if(n===void 0)return{};if(!RT(n))return e.issues.push({path:t,message:`${t} must be an object, got ${X(n)}`,line:J(e.source,t.split(`.`))}),{};let r={};for(let[i,a]of Object.entries(n)){let n=KT(e,pM,`${t}.${i}`,a);n!==null&&(r[i]=n)}return r}function Hj(){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 ${X(i)}`,line:J(e.source,t.split(`.`))});return}return i}}}function Uj(){return{required:!0,json:{enum:[...kh]},parse:(e,t,n,r)=>{let i=r.field;if(typeof i!=`string`||!kh.includes(i)){e.issues.push({path:`${t}.field`,message:`git field must be one of: ${kh.join(`, `)}, got ${JSON.stringify(i)}`,line:J(e.source,[...t.split(`.`),`field`])});return}return i}}}function Wj(){return{required:!1,json:{type:[`string`,`number`,`boolean`]},parse:(e,t,n,r)=>{let i=r.type;return PT(e,t,r,i===`number`||i===`boolean`||i===`string`?i:`string`)}}}const Gj={noun:`parse`,arms:{text:{json:{const:!0},parse:(e,t,n)=>n===!0?{text:!0}:WT(e,t,`parse.text must be the literal boolean true, got ${Z(n)}`)},regex:{json:{type:`string`},parse:(e,t,n)=>typeof n==`string`?Kj(e,t,n):WT(e,t,`parse.regex must be a pattern string, got ${Z(n)}`)},json:{json:{const:!0},parse:(e,t,n)=>n===!0?{json:!0}:WT(e,t,`parse.json must be the literal boolean true, got ${Z(n)}`)}}};function Kj(e,t,n){let r;try{new RegExp(n),r=RegExp(`${n}|`).exec(``).length-1}catch(n){return WT(e,t,`parse.regex is not a valid regular expression: ${n.message}`)}return r>=1?{regex:n}:WT(e,t,`parse.regex must contain a capture group — its group 1 is the value; got ${JSON.stringify(n)}`)}function qj(){return{required:!1,json:lE(Gj),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:J(e.source,[...t.split(`.`),`regex`])}),r.parse===void 0?void 0:GT(e,Gj,`${t}.parse`,r.parse)??void 0)}}function Jj(){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)=>RT(r.parse)&&`json`in r.parse?Yj(e,t,r.default):FT(e,t,r,`default`)}}function Yj(e,t,n){if(n!==void 0)return Xj(n)?n:WT(e,`${t}.default`,`${t}.default must be a JSON value (a json-parsed source's document), got ${Z(n)}`)??void 0}function Xj(e){return e!==null&&Zj(e)}function Zj(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(Zj);let t=Object.getPrototypeOf(e);return(t===Object.prototype||t===null)&&Object.values(e).every(Zj)}default:return!1}}const Qj={value:Hj(),default:XT()},$j={path:tE(),type:iE([`string`,`number`,`boolean`]),default:Wj()},eM={name:tE(),default:XT()},tM={path:rE(),readMode:iE([`whole`,`first-line`]),parse:qj(),cache:Fj(`file`),default:Jj()},nM={command:tE(),parse:qj(),cache:Fj(`shell`),default:Jj()};function rM(e){return{cache:`${e}, so it takes no cache policy — delete the key`}}const iM={template:tE(),default:XT()},aM=rM(`a template variable recomputes whenever a variable it reads changes`),oM={layout:tE(),default:XT()},sM=rM(`a time variable reads the instant its render is drawn at`),cM={field:Uj(),default:XT()},lM=rM(`a git variable is refreshed by the daemon's own watch on the repository`),uM={key:tE(),default:XT()},dM=`kind`;function fM(e,t,n={}){return{...qT(dM,e,t),parse:(r,i,a)=>{BT(r,n,i,a);let o=VT(r,t,i,a);return o===null?null:{kind:e,...o}}}}const pM={tag:dM,noun:`source kind`,memberNoun:`variable`,arms:{literal:fM(`literal`,Qj),input:fM(`input`,$j),env:fM(`env`,eM),file:fM(`file`,tM),shell:fM(`shell`,nM),template:fM(`template`,iM,aM),time:fM(`time`,oM,sM),git:fM(`git`,cM,lM),state:fM(`state`,uM)}};function mM(){return cE(pM)}function hM(){return{type:`object`,additionalProperties:mM()}}const gM=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`,folder:`examples/plugins/lit`}]]);function _M(e){let t=gM.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 in cc-candybar's ${t.folder} — install that folder in a plugin root (docs/segment-authoring.md, "Installing a plugin instead of listing it"), then update this reference)`}}const vM=/^[A-Za-z_][A-Za-z0-9_]*$/,yM={pattern:vM.source},bM={anyOf:[{type:`boolean`},{type:`string`},{type:`integer`}]},xM={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`,...yM}}}]},default:bM}},SM=[`label`,`domain`,`default`],CM=[`min`,`max`,`step`,`atLeast`];function wM(e,t,n){e.issues.push({path:t,message:n,line:J(e.source,t.split(`.`))})}function TM(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 wM(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 wM(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?wM(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(RT(n)){let{min:r,max:i,step:a=1,atLeast:o}=n;return Object.keys(n).filter(e=>!CM.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}}:wM(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 wM(e,t,`domain must be "bool", a list of words, or { min, max }, got ${Z(n)}`)}function EM(e,t,n){if(!RT(n))return wM(e,t,`${t} must be { label, domain, default }, got ${X(n)}`);for(let r of Object.keys(n))SM.includes(r)||wM(e,`${t}.${r}`,`Unknown setting key "${r}". Expected one of: ${SM.join(`, `)}`);let{label:r}=n,i=typeof r==`string`&&r.length>0&&!/[\n\r]/.test(r);i||wM(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=TM(e,`${t}.domain`,n.domain);if(!i||a===void 0)return;let o={label:r,domain:a,default:n.default};return!DM(n.default)||!Ih(o,n.default)?wM(e,`${t}.default`,`default must be ${Bh(o)}, got ${Z(n.default)}`):o}function DM(e){return typeof e==`boolean`||typeof e==`string`||typeof e==`number`}const OM={theme:`its default for this segment is segments.<name>.palette, and a placement sets its own with settings: { ${Ah}: "<theme>" }`,effect:`a placement follows the bar's effect, or sets its own with settings: { effect: "<effect>" }`};function kM(e){return Mh.includes(e)}function AM(){return{required:!1,json:{type:`object`,propertyNames:{...yM,not:{enum:[...Mh]}},additionalProperties:xM},parse:(e,t,n,r)=>{let i=r[n];if(i===void 0)return;let a=`${t}.${n}`;if(!RT(i))return wM(e,a,`${a} must be an object of name → { label, domain, default }, got ${X(i)}`);let o=Object.create(null);for(let[t,n]of Object.entries(i)){if(!vM.test(t)){wM(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(kM(t)){wM(e,`${a}.${t}`,`setting "${t}" is one every placement already has — ${OM[t]}`);continue}let r=EM(e,`${a}.${t}`,n);r!==void 0&&(o[t]=r)}return o}}}const jM=pT.map(e=>e.replace(/\./g,`\\.`)).join(`|`);function MM(){return{required:!1,json:{type:`string`,minLength:1,pattern:`^(?!${jM})[^:/]+$`},parse:(e,t,n,r)=>{let i=r[n];if(i!==void 0)return typeof i==`string`&&i.length>0&&!/[:/]/.test(i)&&!mT(i)?i:wM(e,`${t}.${n}`,`a placement "id" must be a non-empty string without "/" or ":", outside the reserved ${pT.map(e=>`"${e}"`).join(`, `)} namespaces, got ${Z(i)}`)}}}function NM(){return{required:!1,json:{type:`object`,propertyNames:yM,additionalProperties:bM},parse:(e,t,n,r)=>{let i=r[n];if(i===void 0)return;let a=`${t}.${n}`;if(!RT(i))return wM(e,a,`a placement's "settings" must be an object of setting name → value, got ${X(i)}`);let o=Object.create(null);for(let[t,n]of Object.entries(i))DM(n)?o[t]=n:wM(e,`${a}.${t}`,`setting "${t}" must be a boolean, a word, or a number, got ${X(n)}`);return o}}}function PM(e){return new Set(Object.keys(e.segments).filter(e=>!mT(e)))}function FM(e,t,n){if(t===void 0)return{};if(!RT(t))return e.issues.push({path:`segments`,message:`segments must be an object, got ${X(t)}`,line:J(e.source,[`segments`])}),{};let r={};for(let[i,a]of Object.entries(t)){let t=zT(e,n.has(i)?VM:BM,`segments.${i}`,a);t!==null&&(r[i]=t)}return r}function IM(){return{required:!0,json:{type:`string`},parse:(e,t,n,r)=>r[n]===void 0?WT(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${_M(t.slice(9))}`)??void 0:NT(e,t,r,n)??void 0}}function LM(){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:J(e.source,[...t.split(`.`),n])})}}}}function RM(){return{required:!1,json:hM(),parse:(e,t,n,r)=>{let i=r[n];if(i!==void 0)return Vj(e,`${t}.${n}`,i)}}}const zM={template:IM(),description:XT(),group:iE(tD),width:LM(),justify:iE(Vh),truncate:iE(Hh),bg:XT(),fg:XT(),when:XT(),palette:eE(),vars:RM(),settings:AM()},BM={noun:`segment key`,fields:zM},VM={noun:`segment key`,fields:{...zM,template:XT()}},HM=`#/definitions/LayoutNode`,UM={kind:`container`,direction:`vertical`,children:[]};function WM(e){return{required:!0,json:{const:e},parse:()=>e}}function GM(){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:J(e.source,[`root`])}),``)}}}function KM(){return{required:!0,json:{enum:[...mh]},parse:(e,t,n,r)=>{let i=r[n];return typeof i==`string`&&mh.includes(i)?i:(e.issues.push({path:`${t}.${n}`,message:`a container "direction" must be one of: ${mh.join(`, `)} (got ${JSON.stringify(i)})`,line:J(e.source,[`root`])}),`vertical`)}}}function qM(e){return{required:!0,json:{type:`array`,items:{$ref:HM}},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 ${X(a)}`,line:J(t.source,[`root`])}),[])}}}const JM={noun:`layout-node key`,fields:{kind:WM(`segment`),name:GM(),when:XT(),id:MM(),settings:NM()}},YM=()=>iE(hf),XM={noun:`layout-node key`,fields:{kind:WM(`container`),direction:KM(),children:qM(JT(()=>tN)),when:XT(),distribution:YM()}};function ZM(){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:J(e.source,[`root`])}),``)}}}const QM={noun:`layout-node key`,fields:{seg:ZM(),when:XT(),id:MM(),settings:NM()}},$M={noun:`layout-node key`,fields:{h:qM(JT(()=>tN)),when:XT(),distribution:YM()}},eN={noun:`layout-node key`,fields:{v:qM(JT(()=>tN)),when:XT(),distribution:YM()}},tN=(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:J(e.source,[`root`])}),UM):{kind:`segment`,name:n};if(!RT(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 ${X(n)}`,line:J(e.source,[`root`])}),UM;if(n.kind===`container`)return zT(e,XM,t,n)??UM;if(n.kind===`segment`)return zT(e,JM,t,n)??UM;if(n.kind===`cells`)return e.issues.push({path:t,message:`kind: "cells" is no longer supported — use the h-arm spelling instead:
|
|
146
146
|
Old: { kind: "cells", segments: ["seg1", "seg2"] }
|
|
147
|
-
New: { h: ["seg1", "seg2"] }`,line:J(e.source,[`root`])}),NM;if(n.kind===`group`){let r=zT(e,QM,t,n);return r===null?NM:(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}),eN(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:J(e.source,[`root`])}),NM}if(a){let r=zT(e,HM,t,n);return r===null?NM:{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=zT(e,UM,t,n);return r===null?NM:{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=zT(e,WM,t,n);return r===null?NM:{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:J(e.source,[`root`])}),NM};function KM(){return{required:!0,json:{type:`object`,propertyNames:{pattern:Uh.source},additionalProperties:{$ref:MM}},parse:(e,t,n,r)=>{let i=r[n];if(!RT(i))return e.issues.push({path:`${t}.${n}`,message:`"rows" must be an object of row name → layout node, got ${X(i)}`,line:J(e.source,[...t.split(`.`),n])}),{};let a={};for(let[r,o]of Object.entries(i)){if(!Uh.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:J(e.source,[...t.split(`.`),n,r])});continue}a[r]=GM(e,`${t}.${n}.${r}`,o)}return a}}}const qM={noun:`root key`,fields:{rows:KM(),when:XT(),distribution:zM()}};function JM(e,t,n){return RT(n)&&`rows`in n?zT(e,qM,t,n)??{rows:{}}:GM(e,t,n)}function YM(){return{required:!0,json:{type:`string`,pattern:Uh.source},parse:(e,t,n,r)=>{let i=r[n];if(typeof i!=`string`||!Uh.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 "${Zn}", got ${Z(i)}`,line:J(e.source,[`root`])});return}return i}}}function XM(){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:J(e.source,[`root`])});return}return i}}}}function ZM(){return{required:!0,json:{type:`string`,pattern:`^[^\\n\\r]*$`},parse:(e,t,n,r)=>{let i=NT(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:J(e.source,[...t.split(`.`),n])});return}return i}}}}const QM={noun:`layout-node key`,fields:{kind:PM(`group`),name:YM(),label:ZM(),open:ZT(),direction:iE(mh),key:XM(),bg:XT(),fg:XT(),when:XT(),distribution:zM(),children:LM(JT(()=>GM))}};function $M(e){return e.key??`groups.`+e.name}function eN(e){let t=uT+e.name;return nr(t,{variable:t,key:$M(e),member:e.name},{kind:`container`,direction:e.direction??`vertical`,children:e.children,...e.distribution!==void 0&&{distribution:e.distribution}},`drop`,e.when)}function tN(e,t,n){e.issues.push({path:t,message:n,line:J(e.source,[`root`])})}function nN(e,t){gT(e,t,uT,`group nodes`);let n=e.groups;if(n.length===0)return;let r=new Set;for(let t of n)r.has(t.name)&&tN(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}.`)&&$M(t)===$M(r)&&tN(e,t.path,`group "${t.name}" shares key "${$M(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=$M(t);if(i.has(n)||i.set(n,Zn),t.open===!0){let r=i.get(n);r!==`closed`&&tN(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=uT+e.name,r=$M(e),c=n.filter(t=>t!==e&&e.path.startsWith(t.path+`.`)).length,l=` `.repeat(c);a[t]=cr(r,i.get(r)),o[t]=lr(r,e.name),s[t]={template:ar(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 rN=`menu`,iN=`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`,aN=e=>e.kind===`call`&&e.name===`dict`,oN=e=>e.kind===`literal`&&typeof e.value!=`object`,sN=e=>$n(``,e,2)===void 0;function cN(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&&aN(i)?i:void 0,o=a===void 0?r:r.slice(0,-1);if(o.some(aN))return t(`whose options (dict …) is not its last argument — ${iN}`);if(i!==void 0&&a===void 0&&!oN(i)&&sN(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=$n(`whose trigger`,o.length,2);if(s!==void 0)return t(`${s} — ${iN}`);let c=a===void 0?{}:Mb(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=TT(c)}catch(e){return t(`with invalid options — ${e.message}`)}let u=l.key;if(u!==void 0){let e=hT(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 "${yT(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 lN(e){let t=Vv({fromString:e=>e});try{return t.parse(e).referencedCalls().filter(e=>e.name===rN).map(cN)}catch{return`parse-failed`}}function uN(e){let t=Vv({fromString:e=>e});try{return t.parse(e).referencedFunctions().has(rN)}catch{return!1}}function dN(e,t,n){e.issues.push({path:t,message:n,line:J(e.source,[`root`])})}function fN(e,t){gT(e,t,dT,`{{ menu }} helpers`);for(let[n,r]of Object.entries(t.helpers??{}))uN(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:J(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`&&uN(i)&&dN(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 bh(Xh(t.root)))typeof n.when==`string`&&uN(n.when)&&dN(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||!uN(r))continue;let n=lN(r);if(n!==`parse-failed`)for(let r of n){let n=r.kind===`issue`?r.message:pN(r.apply);n!==void 0&&dN(e,`segments.${t}`,`segment "${t}" has a {{ menu }} ${n}.`)}}}function pN(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(_T(e)===`closed`)return`whose apply action is named "${Zn}", which collides with the menu's closed-state sentinel and leaves it unopenable. Rename the action`}function mN(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 ng(e.presets)){let a=new Map,s=new Map;for(let c of bh(ag(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,lN(t.template));let l=i.get(c.name);if(l===`parse-failed`)continue;let u=gh(c);for(let[e,t]of l.entries()){if(t.kind===`issue`||pN(t.apply)!==void 0)continue;let{apply:i,options:l}=t,d=_T(i),f=vT(u,i,l.key),p=xT(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=bT(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]=lr(f,d),n[f]=cr(f,Zn),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 hN=[`set`,`persist`,`copy`,`open`,`reset`,`undo`,`redo`,`back`,`rewind`,`save`,`preset`,`themeDefault`,`doctor`,`ceiling`,`slash`,`do`];function gN(e){return e.ceiling===`set`?[`set`,e.to]:[`clear`]}function _N(e){return`from`in e||`int`in e||`insertSegmentFrom`in e}function vN(e,t){if(t===void 0)return{};if(!RT(t))return Q(e,`actions`,`actions must be an object, got ${X(t)}`),{};let n=Object.create(null);for(let[r,i]of Object.entries(t)){let t=yN(e,`actions.${r}`,i);t!==null&&(n[r]=t)}return n}function Q(e,t,n){e.issues.push({path:t,message:n,line:J(e.source,t.split(`.`))})}function yN(e,t,n){if(!RT(n))return Q(e,t,`${t} must be an action object, got ${X(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=hN.filter(e=>e in n);return r.length===1?bN[r[0]](e,t,n):(Q(e,t,`action must declare exactly one of: ${hN.join(`, `)}${r.length>1?` (found: ${r.join(`, `)})`:``}`),null)}const bN={set:(e,t,n)=>eP(e,t,n,`set`,XN),persist:(e,t,n)=>eP(e,t,n,`persist`,ZN),copy:xN(`copy`),open:xN(`open`),reset:SN,undo:wN(`undo`),redo:wN(`redo`),back:wN(`back`),rewind:wN(`rewind`),save:wN(`save`),preset:TN,themeDefault:EN,doctor:ON,ceiling:kN,slash:AN,do:jN};function xN(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=NT(t,n,r,e);return i===null?null:{[e]:i}}}function SN(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=MN(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 CN={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 wN(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 — ${CN[e]}), got ${Z(r[e])}`),null)}}function TN(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=NT(e,t,n,`name`);return a===null?null:{preset:`delete`,name:a}}function EN(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 DN={run:[`doctor`],fix:[`doctor`,`check`],mark:[`doctor`,`check`,`mark`]};function ON(e,t,n){let r=n.doctor,i=typeof r==`string`&&Object.hasOwn(DN,r),a=i?DN[r]:[...new Set(Object.values(DN).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(DN).map(e=>`"${e}"`).join(`, `)}, got ${Z(r)}`),null;if(r===`run`)return{doctor:`run`};let o=n.check,s=r===`mark`?uO:lO;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 JD.includes(c)?{doctor:`mark`,check:o,mark:c}:(Q(e,`${t}.mark`,`doctor mark must be ${JD.map(e=>`"${e}"`).join(` or `)}, got ${Z(c)}`),null)}function kN(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 AN(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=EO(n.slash);return r.kind===`refused`?(Q(e,`${t}.slash`,r.reason),null):{slash:r.line}}function jN(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 MN(e,t,n,r,i,a){let o=NT(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 NN={set:`the SessionState key to write`,persist:`the config globals field to write`};function PN(e,t,n,r){let i=NN[r],a=MN(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 FN(e){return e===`set`?`set-state`:`set-config`}const IN={to:tP(`set`)},LN={to:tP(`persist`)},RN={from:nP(`set`)},zN={from:nP(`persist`)},BN={min:sP(),max:sP(),by:sP()},VN={int:iP()},HN={cycle:rP(`set`)},UN={cycle:rP(`persist`)},WN={removeSegment:aP(`removeSegment`)},GN={insertSegment:aP(`insertSegment`),anchor:aP(`anchor`),relation:oP()},KN={insertSegmentFrom:nP(`persist`),anchor:aP(`anchor`),relation:oP()},qN={ok:e=>e.min<e.max,issue:e=>({field:`min`,message:`min (${e.min}) must be less than max (${e.max})`})},JN={ok:e=>e.by!==0,issue:()=>({field:`by`,message:`by must be a non-zero integer (the per-click increment; negative steps down)`})};function YN(e,t,n=[],r){let i=Object.keys(t),a=r??i,o=[e],s=(e,n,r)=>VT(e,t,n,r),c=aE(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?YT(s,...n):s}}const XN=[YN(`set`,IN),YN(`set`,RN),YN(`set`,BN,[qN,JN]),YN(`set`,VN),YN(`set`,HN)],ZN=[YN(`persist`,LN),YN(`persist`,zN),YN(`persist`,BN,[qN,JN]),YN(`persist`,UN),YN(`persist`,WN),YN(`persist`,GN,[],[`insertSegment`]),YN(`persist`,KN,[],[`insertSegmentFrom`])];function QN(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 $N(e){let t=QN(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 eP(e,t,n,r,i){let a=PN(e,t,n,r),o=i.filter(e=>e.detect.some(e=>e in n));if(o.length!==1)return Q(e,t,`${$N(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 tP(e){let t=FN(e);return{required:!0,json:{type:`string`},parse:(n,r,i,a)=>MN(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 nP(e){let t=FN(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 rP(e){let t=FN(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 ${X(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 iP(){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 aP(e){return{required:!0,json:{type:`string`},parse:(t,n,r,i)=>{let a=NT(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 oP(){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 sP(){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 cP(e,t,n){return`${e}: "${t}" is an endcaps shape, not a style — endcaps were renamed from "style" to "endcaps"; write ${n}: "${t}"`}const lP={noun:`style key`,fields:{hueShift:$T(),chromaScale:$T({min:0}),lightnessScale:$T(),lightnessShift:$T()}};function uP(e,t){if(!RT(t))return e.issues.push({path:`styles`,message:`styles must be an object mapping style names to adaptation objects, got ${X(t)}`,line:J(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:J(e.source,[`styles`,r])});continue}if(Bp(r)){e.issues.push({path:`styles.${r}`,message:cP(`styles.${r}`,r,`globals.endcaps`),line:J(e.source,[`styles`,r])});continue}let t=zT(e,lP,`styles.${r}`,i);t!==null&&(n[r]={...Ls,...t})}return n}const dP={noun:`preset key`,fields:{root:{required:!1,json:{$ref:`#/definitions/RootFragment`},parse:(e,t,n,r)=>r[n]===void 0?void 0:JM(e,`${t}.${n}`,r[n])},globals:{required:!1,json:RE(),parse:(e,t,n,r)=>r[n]===void 0?void 0:LE(e,`${t}.${n}`,r[n])}}};function fP(e,t){if(!RT(t))return e.issues.push({path:`presets`,message:`presets must be an object mapping preset names to config fragments, got ${X(t)}`,line:J(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:J(e.source,[`presets`,r])});continue}let t=zT(e,dP,`presets.${r}`,i);t!==null&&(n[r]=t)}return n}function pP(e,t){if(t===void 0)return{};if(!RT(t))return e.issues.push({path:`helpers`,message:`helpers must be an object, got ${X(t)}`,line:J(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:J(e.source,[`helpers`,r])});continue}n[r]=i}return n}const mP=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 hP(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 gP(e){let t=mP.get(e);return t===void 0?void 0:`variables.${e} is no longer read: ${hP(t)}`}function _P(e){let t=mP.get(e);return t===void 0?``:` — ".${e}" is no longer a variable: ${hP(t)}; a "${t.segment}" template reads it as ".settings.${t.setting}"`}function vP(e,t){let n=new Map;for(let e of Object.keys(t)){let t=iT(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:J(e.source,[`presets`])})}function yP(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||Sp(i)||Object.prototype.hasOwnProperty.call(t.styles,i))continue;let r=`${n.join(`.`)}.style`;e.issues.push({path:r,message:Bp(i)?cP(r,i,a):`${r} "${i}" does not match any declared style (have: ${Object.keys(t.styles).join(`, `)})`,line:J(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:J(e.source,[`globals`,`preset`])}),vP(e,t.presets),HP(e,t);let i=Fg(t);for(let t of i.names)t!==`settings`&&!t.startsWith(SP)||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:J(e.source,[`variables`,t])});let a=(t,n,r)=>{aA(t)>1&&e.issues.push({path:n,message:`${n} places the global settings menu anchor "${RO}" ${aA(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}),oA(t)&&e.issues.push({path:n,message:`${n} places the global settings menu anchor "${RO}" 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 bh(t)){if(e.kind!==`segment`)continue;let t=gh(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=vh(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||hh[e.direction]===`cell`))}let s=(n,r)=>{for(let[a,o]of Zh(n,r)){let n=J(e.source,o.split(`.`));if(a.when!==void 0&&(PP(e,`${o}.when`,a.when,i,{line:n}),NP(e,`${o}.when`,a.when,n)),a.kind===`segment`){if(nA(a.name)){(a.id!==void 0||a.settings!==void 0)&&e.issues.push({path:o,message:`${r} gives the global settings menu anchor "${RO}" an id or settings — the anchor only marks where the menu goes, so place it as the bare name "${RO}"`,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${sM(a.name)}`,line:n}),AP(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`,Yh(t.root)]]);for(let e of ng(t.presets)){let{node:n,path:r}=ag(t,e);c.set(r,n)}for(let[t,n]of c)a(n,t,J(e.source,t.split(`.`)));VP(e,t,i,()=>!0)}const bP=[`removeSegment`,`insertSegment`,`insertSegmentFrom`];function xP(e,t,n,r,i,a,o){let s=`actions.${n}.${r}`,c=J(e.source,[`actions`,n,r]);if(!ng(t.presets).includes(a)){e.issues.push({path:s,message:`actions.${n}: "${i}" names preset "${a}" which is not declared (have: ${ng(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(`, `)})${sM(i)}`,line:c})},p=new Set(_h(ag(t,a).node)),m=(r,i)=>{!oM.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${sM(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 SP=`settings.`;function CP(e,t){return{...e,names:new Set([...e.names,...Object.keys(t).map(e=>SP+e)])}}function wP(e,t,n){let r=e=>`segments.${t}.settings.${e}`,i=(n,i)=>{e.issues.push({path:r(n),message:`${r(n)}: ${i}`,line:J(e.source,[`segments`,t,`settings`,n])})},a=DP(n);for(let{setting:e,message:t}of a)i(e,t);if(!(a.length>0))for(let{setting:e,message:t}of Fh(n,EP(n)))i(e,`the defaults do not stand together: ${t}`)}function TP(e){return DP(e).length>0||Fh(e,EP(e)).length>0}function EP(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.default]))}function DP(e){let t=t=>Ph(OP(e,t))?.atLeast;return Object.keys(e).flatMap(n=>{let r=t(n);if(r===void 0)return[];if(r===n||Ph(OP(e,r))===void 0)return[{setting:n,message:`atLeast "${r}" must name another range setting of this segment (its range settings: ${kP(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 OP(e,t){return Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}function kP(e,t){return Object.entries(e).filter(([e,n])=>e!==t&&Ph(n)!==void 0).map(([e])=>e)}function AP(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=Nh(a),s=`${r}: placement "${gh(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(`, `)})`:Ih(c,a)?void 0:`sets "${t}" to ${JSON.stringify(a)}${c.domain===`theme`?pp(a):``}, but it must be ${Bh(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])=>Ih(o[e],t))||TP(o)))for(let{message:t}of Fh(o,c))e.issues.push({path:r,message:`${s}: ${t}`,line:i})}function jP(e,t,n,r,i){n.kind===`template`&&PP(e,`${t}.template`,n.template,r,{segCtx:i}),Oh(n)&&`key`in n.cache&&PP(e,`${t}.cache.key`,n.cache.key,r,{segCtx:i})}function MP(e,t,n,r,i){if(!(!Oh(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:J(e.source,[...t.split(`.`),`cache`,`depends_on`])})}}function NP(e,t,n,r){try{iD.parse(n)}catch(n){e.issues.push({path:t,message:`Template parse error in ${t}: ${n.message}`,line:r})}}function PP(e,t,n,r,i){for(let[a,o]of Dg(n,r.helpers)){if(Pg(a,r))continue;if(a.startsWith(SP)){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??J(e.source,t.split(`.`))});continue}if(o!==null){FP(e,o,`Template references unknown variable ".${a}"${_P(a)}`);continue}let n=i?.segCtx===void 0?void 0:`${i.segCtx}.${a}`,s=n!==void 0&&Pg(n,r)?` (segment-local vars are namespaced — write ".${n}")`:_P(a);e.issues.push({path:t,message:`Template references unknown variable ".${a}"${s}`,line:i?.line??J(e.source,t.split(`.`))})}}function FP(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:J(e.source,[`helpers`,t])})}function IP(e,t,n,r,i){let a=n.set,o=SE(ba[r].configKey),s=`${a} takes ${OT(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:J(e.source,[`actions`,t,`min`])});return}let c=zP(n,i);if(c===RP){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:J(e.source,[`actions`,t,`int`])});return}let l=c.filter(e=>!DT(o,e.value,i));if(l.length!==0){if(a===ba.style.sessionKey&&(`from`in n&&n.from===`endcaps`||c.every(e=>Bp(e.value)))){let r=ba.endcaps.sessionKey;e.issues.push(`to`in n?{path:`actions.${t}.to`,message:cP(`actions.${t}.to`,n.to,`set: "${r}", to`),line:J(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:J(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<=LP?r.join(`, `):`${r.slice(0,LP).join(`, `)} and ${r.length-LP} 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:J(e.source,[`actions`,t,n])})}}}const LP=3,RP=Symbol(`any integer`);function zP(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?fg(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)}]:RP}function BP(e,t){return Object.entries(e).filter(([e])=>t(e))}function VP(e,t,n,r){let i=PA(t),a=dg(i);for(let[n,o]of BP(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 ${mg(r,i)}`,line:J(e.source,[`actions`,n,t])});continue}if(!(`set`in o))continue;Ca.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:J(e.source,[`actions`,n,`set`])});let s=Da.get(o.set);s!==void 0&&IP(e,n,o,s,i)}for(let[n,i]of BP(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&&_N(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:J(e.source,[`actions`,n,`do`])})});for(let[n,i]of BP(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=$E(r);if(o===null){e.issues.push({path:`actions.${n}.${a}`,message:`actions.${n}: "${r}" is not a config globals field (have: ${HE().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`,line:J(e.source,[`actions`,n,a])});continue}let s=bP.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:J(e.source,[`actions`,n,a])});continue}if(o.scope===`preset-root`){xP(e,t,n,a,r,o.preset,i);continue}if(o.scope===`preset-globals`&&!ng(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: ${ng(t.presets).join(`, `)})`,line:J(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${pp(o.theme)} (have: ${[...e.allowedPalettes].sort().join(`, `)})`,line:J(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(`, `)})${sM(o.segment)}`,line:J(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:J(e.source,[`actions`,n,a])})}}for(let[i,a]of BP(t.variables,r)){jP(e,`variables.${i}`,a,n);let t=gP(i);t!==void 0&&e.issues.push({path:`variables.${i}`,message:t,line:J(e.source,[`variables`,i])})}for(let[i,a]of BP(t.segments,r)){if(a.vars)for(let[t,r]of Object.entries(a.vars))jP(e,`segments.${i}.vars.${t}`,r,n,i);let r=Nh(a);wP(e,i,r);let o=CP(n,r);for(let n of[`template`,`bg`,`fg`,`when`]){let s=a[n];if(typeof s==`string`){PP(e,`segments.${i}.${n}`,s,o,{segCtx:i,settings:r});for(let{name:r,site:a,via:o}of jg(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){FP(e,o,`Template references unknown action "${r}"${s}`);continue}e.issues.push({path:`segments.${i}.${n}`,message:`${n} references unknown action "${r}"${s}`,line:J(e.source,[`segments`,i,n])})}}}}for(let[i,a]of BP(t.variables,r))MP(e,`variables.${i}`,a,n);for(let[i,a]of BP(t.segments,r))if(a.vars)for(let[t,r]of Object.entries(a.vars))MP(e,`segments.${i}.vars.${t}`,r,n,i)}function HP(e,t){let n=new Set;for(let r of ng(t.presets)){let i=og(t,r),a=[{},t.editGlobals];for(let o of a){let a=o.charset??i.charset??`unicode`,s=o.default_separator??i.default_separator;if(a!==`ascii`||Up(s??``))continue;let c=o.default_separator===void 0?ig(t.presets,r).globals?.default_separator===void 0?[`globals`]:[`presets`,r,`globals`]:[`editGlobals`],l=[...c,`default_separator`].join(`.`);n.has(l)||(n.add(l),e.issues.push({path:l,message:`${l} ${JSON.stringify(s)} is not ASCII, but charset is "ascii" — under ascii a joiner draws only ASCII; write an ASCII separator or set charset: "unicode"`,line:J(e.source,[...c,`default_separator`])}))}}}function UP(e,t,n=()=>!0){let{graph:r,nodeInfo:i}=WP(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:J(e.source,a?.linePathParts??[`variables`,r])}),!0}if(t===0&&s(c))return!0}return a.set(t,2),o.pop(),!1}}function WP(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 Dg(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),Oh(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 GP(e){return e===`~`||e.startsWith(`~/`)||e.startsWith(`~\\`)?h.homedir()+e.slice(1):e}function KP(e,t){return l.resolve(e,GP(t))}function qP(e,t){return typeof t==`string`&&t!==``?KP(e,t):void 0}function JP(e){return`plugin ${e.path} was not loaded: ${e.reason}`}const YP=new Set([`data`,`segments`,`helpers`,`actions`]),XP=`plugin.json5`,ZP=/^[a-z][a-z0-9_]*$/;function QP(e){let t=l.basename(l.dirname(e));return ZP.test(t)?t:void 0}const $P=`plugins.`;function eF(e){return`${$P}${e}.data`}function tF(e){try{return{ok:!0,value:e()}}catch(e){return{ok:!1,reason:nF(e)}}}function nF(e){return e instanceof aT?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 rF(e,t){return e.map(e=>KP(l.dirname(t),e))}function iF(e,t,n,i){let a=new Map;return e.reduce((e,n)=>{let o=QP(n),s=(t,r)=>{let i=new Map(e.rendering);return o!==void 0&&r!==e.config&&i.delete(o),{...e,config:r,rendering:i,dropped:[...e.dropped,{path:n,plugin:o,reason:t}]}};if(l.basename(n)!==`plugin.json5`){let t=`a plugin is a folder holding its ${XP}, and the folder's name is the plugin's: move this file to <dir>/<name>/${XP} and list that`;return s(t,o===void 0?e.config:sF(oF(e.config,o),o,{path:n,plugin:o,reason:t}))}if(o===void 0)return s(`its folder "${l.basename(l.dirname(n))}" is not a plugin name (one matching ${ZP}: it prefixes every name the plugin declares)`,e.config);let c=a.get(o);if(c!==void 0)return s(`plugin "${o}" is already listed, from ${c}`,e.config);a.set(o,n);let u=oF(e.config,o),d=tF(()=>{let a=r.readFileSync(n,`utf-8`),s=bj(pF(n,o,{source:a,json:_r.default.parse(a)},t),u);return i(s,o,u!==e.config),s});if(d.ok)return{...e,config:d.value,loaded:[...e.loaded,n],rendering:new Map([...e.rendering,[o,n]])};let f={path:n,plugin:o,reason:d.reason};return s(d.reason,sF(u,o,f))},{config:n.config,rendering:n.rendering,loaded:[],dropped:[]})}function aF(e){let t=`${$P}${e}.`;return e=>e.startsWith(t)}function oF(e,t){let n=aF(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 sF(e,t,n){return{...e,variables:{...e.variables,[eF(t)]:{kind:`dropped`,reason:JP(n),definition:n.path}}}}function cF(e){return e.startsWith(`plugins.`)?e.slice(8).split(`.`)[0]:void 0}function lF(e,t){let n=new Set([...Object.keys(e.config.variables),...Object.keys(e.config.segments)].map(cF)),r=[...t,...e.dropped].filter(e=>e.plugin===void 0).map(e=>({definition:e.path,notice:JP(e)}));return t=>{let i=cF(t);if(i===void 0)return[];let a=e.config.variables[eF(i)];return a?.kind===`dropped`?[{definition:a.definition,notice:a.reason}]:n.has(i)?[]:r}}function uF(e,t){let n=ng(e.presets).flatMap(t=>[...bh(ag(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,dF(e,t.map(e=>e.notice),n.filter(t=>t.name===e))])),a=t=>{let n=cF(t),r=n===void 0?void 0:e.variables[eF(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=>jg(t,e.helpers).map(e=>e.name)),...c],e.actions),d=l(s.flatMap(t=>[...Ng(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:`{{ .${eF(cF(e)??``)} }}`}]))},helpers:{...e.helpers,...Object.fromEntries(d.map(([e,t])=>[e,`{{ fail ${JSON.stringify(t.notice)} }}`]))}},reached:f}}function dF(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,fF(e,t)]));return{template:`{{ ${JSON.stringify(r)} }}`,bg:`error`,description:`stands in for a segment whose plugin did not load`,settings:a}}function fF(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 pF(e,t,{source:n,json:r},{checkout:i}){let a=[],o=()=>{throw new aT(e,a)};if(!RT(r))return a.push({path:``,message:`a plugin definition must be an object, got ${X(r)}`}),o();for(let e of Object.keys(r))YP.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: ${[...YP].join(`, `)}`});let s=gF(r.data,e,i,a);if(RT(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(gp()),groups:[]},l=jj(c,`data`,{[eF(t)]:{kind:`file`,path:s,parse:{json:!0},cache:{watch_file:s},default:{}}});for(let[e,t]of Object.entries(r.segments))RT(t)&&`vars`in t&&a.push({path:`segments.${e}.vars`,message:`a plugin segment may not declare "vars": a plugin's only source is its data file`});let u={variables:l,segments:hF(t,TM(c,r.segments,new Set)),helpers:hF(t,pP(c,r.helpers)),actions:hF(t,vN(c,r.actions))};for(let[e,t]of mF(u))try{iD.parse(t)}catch(t){a.push({path:e,message:`Template parse error in ${e}: ${t.message}`})}return a.length>0&&o(),u}function*mF(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 hF(e,t){return Object.fromEntries(Object.entries(t).map(([t,n])=>[`${$P}${e}.${t}`,n]))}function gF(e,t,n,r){if(typeof e==`string`&&e!==``)return KP(l.dirname(t),e);if(RT(e)&&Object.keys(e).length===1&&typeof e.checkout==`string`&&e.checkout!==``){let t=e.checkout;if(l.isAbsolute(t)||t.startsWith(`~`)||l.normalize(t).split(l.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 l.resolve(n.root,t)}if(RT(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 _F(e){let t=(process.env.XDG_DATA_DIRS||vF()).split(`:`).filter(e=>e!==``),n=process.env.XDG_DATA_HOME||l.join(h.homedir(),`.local`,`share`),r=[...[...t].reverse().map(e=>l.join(e,`cc-candybar`,`plugins`)),l.join(n,`cc-candybar`,`plugins`),...e===null?[]:[l.join(e,`.cc-candybar`,`plugins`)]];return r.filter((e,t)=>r.lastIndexOf(e)===t)}function vF(){let e=`/usr/local/share:/usr/share`;return process.platform===`darwin`?`${l.join(process.env.HOMEBREW_PREFIX||`/opt/homebrew`,`share`)}:${e}`:e}function yF(e){let t=_F(e),n=new Map,r=[],i=[];for(let e of t){let t=bF(e);if(`error`in t){r.push(t);continue}for(let r of t.folders)n.delete(r),n.set(r,l.join(e,r,XP));for(let n of t.files)i.push({path:l.join(e,n),plugin:void 0,reason:`a plugin is a folder holding its ${XP}: move this file to ${l.join(e,`<name>`,XP)}`})}return{roots:t,definitions:[...n.values()],unchecked:r,strays:i}}function bF(e){try{let t=r.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()||xF(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 xF(e,t){if(!t.isSymbolicLink())return!1;try{return r.statSync(l.join(e,t.name)).isDirectory()}catch{return!0}}const SF=[`json5`,`json`];function CF(e){try{return r.statSync(e,{throwIfNoEntry:!1})===void 0?`absent`:`present`}catch(t){return{path:e,error:t.message}}}function wF(e,t,n){if(n!==void 0)return[n];let r=t??process.cwd();return[...new Set([...e?SF.map(t=>l.join(e,`.cc-candybar.${t}`)):[],...SF.map(e=>l.join(r,`.cc-candybar.${e}`)),...SF.map(e=>`${TF()}.${e}`)])]}function TF(){let e=process.env.XDG_CONFIG_HOME??l.join(h.homedir(),`.config`);return l.join(e,`cc-candybar`,`config`)}function EF(e,t,n){let i=[],a=new Map;for(let o of wF(e,t,n)){let e=CF(o);if(e===`absent`)continue;if(e!==`present`){i.push(e);continue}let t=l.join(r.realpathSync(l.dirname(o)),l.basename(o).replace(/\.(json5|json)$/,``));a.has(t)||a.set(t,o)}let o=[...a.values()].reverse();if(n===void 0)return{kind:`chain`,layers:o,home:DF(o),unchecked:i};let[s]=i,c=n;return o.length>0?{kind:`chain`,layers:o,home:c,unchecked:i}:s===void 0?{kind:`missing`,path:n,home:c}:{kind:`unreadable`,...s,home:c}}function DF(e){let t=TF();return e.find(e=>SF.some(n=>e===`${t}.${n}`))??`${t}.${SF[0]}`}function OF(e,t,n){let r=EF(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 kF(e){return AF(e).join(`
|
|
148
|
-
`)||null}function
|
|
147
|
+
New: { h: ["seg1", "seg2"] }`,line:J(e.source,[`root`])}),UM;if(n.kind===`group`){let r=zT(e,cN,t,n);return r===null?UM:(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}),uN(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:J(e.source,[`root`])}),UM}if(a){let r=zT(e,QM,t,n);return r===null?UM:{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=zT(e,$M,t,n);return r===null?UM:{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=zT(e,eN,t,n);return r===null?UM:{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:J(e.source,[`root`])}),UM};function nN(){return{required:!0,json:{type:`object`,propertyNames:{pattern:Uh.source},additionalProperties:{$ref:HM}},parse:(e,t,n,r)=>{let i=r[n];if(!RT(i))return e.issues.push({path:`${t}.${n}`,message:`"rows" must be an object of row name → layout node, got ${X(i)}`,line:J(e.source,[...t.split(`.`),n])}),{};let a={};for(let[r,o]of Object.entries(i)){if(!Uh.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:J(e.source,[...t.split(`.`),n,r])});continue}a[r]=tN(e,`${t}.${n}.${r}`,o)}return a}}}const rN={noun:`root key`,fields:{rows:nN(),when:XT(),distribution:YM()}};function iN(e,t,n){return RT(n)&&`rows`in n?zT(e,rN,t,n)??{rows:{}}:tN(e,t,n)}function aN(){return{required:!0,json:{type:`string`,pattern:Uh.source},parse:(e,t,n,r)=>{let i=r[n];if(typeof i!=`string`||!Uh.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 "${Zn}", got ${Z(i)}`,line:J(e.source,[`root`])});return}return i}}}function oN(){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:J(e.source,[`root`])});return}return i}}}}function sN(){return{required:!0,json:{type:`string`,pattern:`^[^\\n\\r]*$`},parse:(e,t,n,r)=>{let i=NT(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:J(e.source,[...t.split(`.`),n])});return}return i}}}}const cN={noun:`layout-node key`,fields:{kind:WM(`group`),name:aN(),label:sN(),open:ZT(),direction:iE(mh),key:oN(),bg:XT(),fg:XT(),when:XT(),distribution:YM(),children:qM(JT(()=>tN))}};function lN(e){return e.key??`groups.`+e.name}function uN(e){let t=uT+e.name;return nr(t,{variable:t,key:lN(e),member:e.name},{kind:`container`,direction:e.direction??`vertical`,children:e.children,...e.distribution!==void 0&&{distribution:e.distribution}},`drop`,e.when)}function dN(e,t,n){e.issues.push({path:t,message:n,line:J(e.source,[`root`])})}function fN(e,t){gT(e,t,uT,`group nodes`);let n=e.groups;if(n.length===0)return;let r=new Set;for(let t of n)r.has(t.name)&&dN(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}.`)&&lN(t)===lN(r)&&dN(e,t.path,`group "${t.name}" shares key "${lN(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=lN(t);if(i.has(n)||i.set(n,Zn),t.open===!0){let r=i.get(n);r!==`closed`&&dN(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=uT+e.name,r=lN(e),c=n.filter(t=>t!==e&&e.path.startsWith(t.path+`.`)).length,l=` `.repeat(c);a[t]=cr(r,i.get(r)),o[t]=lr(r,e.name),s[t]={template:ar(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 pN=`menu`,mN=`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`,hN=e=>e.kind===`call`&&e.name===`dict`,gN=e=>e.kind===`literal`&&typeof e.value!=`object`,_N=e=>$n(``,e,2)===void 0;function vN(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&&hN(i)?i:void 0,o=a===void 0?r:r.slice(0,-1);if(o.some(hN))return t(`whose options (dict …) is not its last argument — ${mN}`);if(i!==void 0&&a===void 0&&!gN(i)&&_N(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=$n(`whose trigger`,o.length,2);if(s!==void 0)return t(`${s} — ${mN}`);let c=a===void 0?{}:Mb(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=TT(c)}catch(e){return t(`with invalid options — ${e.message}`)}let u=l.key;if(u!==void 0){let e=hT(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 "${yT(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 yN(e){let t=Vv({fromString:e=>e});try{return t.parse(e).referencedCalls().filter(e=>e.name===pN).map(vN)}catch{return`parse-failed`}}function bN(e){let t=Vv({fromString:e=>e});try{return t.parse(e).referencedFunctions().has(pN)}catch{return!1}}function xN(e,t,n){e.issues.push({path:t,message:n,line:J(e.source,[`root`])})}function SN(e,t){gT(e,t,dT,`{{ menu }} helpers`);for(let[n,r]of Object.entries(t.helpers??{}))bN(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:J(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`&&bN(i)&&xN(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 bh(Xh(t.root)))typeof n.when==`string`&&bN(n.when)&&xN(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||!bN(r))continue;let n=yN(r);if(n!==`parse-failed`)for(let r of n){let n=r.kind===`issue`?r.message:CN(r.apply);n!==void 0&&xN(e,`segments.${t}`,`segment "${t}" has a {{ menu }} ${n}.`)}}}function CN(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(_T(e)===`closed`)return`whose apply action is named "${Zn}", which collides with the menu's closed-state sentinel and leaves it unopenable. Rename the action`}function wN(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 ng(e.presets)){let a=new Map,s=new Map;for(let c of bh(ag(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,yN(t.template));let l=i.get(c.name);if(l===`parse-failed`)continue;let u=gh(c);for(let[e,t]of l.entries()){if(t.kind===`issue`||CN(t.apply)!==void 0)continue;let{apply:i,options:l}=t,d=_T(i),f=vT(u,i,l.key),p=xT(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=bT(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]=lr(f,d),n[f]=cr(f,Zn),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 TN=[`set`,`persist`,`copy`,`open`,`reset`,`undo`,`redo`,`back`,`rewind`,`save`,`preset`,`themeDefault`,`doctor`,`ceiling`,`slash`,`do`];function EN(e){return e.ceiling===`set`?[`set`,e.to]:[`clear`]}function DN(e){return`from`in e||`int`in e||`insertSegmentFrom`in e}function ON(e,t){if(t===void 0)return{};if(!RT(t))return Q(e,`actions`,`actions must be an object, got ${X(t)}`),{};let n=Object.create(null);for(let[r,i]of Object.entries(t)){let t=kN(e,`actions.${r}`,i);t!==null&&(n[r]=t)}return n}function Q(e,t,n){e.issues.push({path:t,message:n,line:J(e.source,t.split(`.`))})}function kN(e,t,n){if(!RT(n))return Q(e,t,`${t} must be an action object, got ${X(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=TN.filter(e=>e in n);return r.length===1?AN[r[0]](e,t,n):(Q(e,t,`action must declare exactly one of: ${TN.join(`, `)}${r.length>1?` (found: ${r.join(`, `)})`:``}`),null)}const AN={set:(e,t,n)=>uP(e,t,n,`set`,oP),persist:(e,t,n)=>uP(e,t,n,`persist`,sP),copy:jN(`copy`),open:jN(`open`),reset:MN,undo:PN(`undo`),redo:PN(`redo`),back:PN(`back`),rewind:PN(`rewind`),save:PN(`save`),preset:FN,themeDefault:IN,doctor:RN,ceiling:zN,slash:BN,do:VN};function jN(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=NT(t,n,r,e);return i===null?null:{[e]:i}}}function MN(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=HN(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 NN={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 PN(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 — ${NN[e]}), got ${Z(r[e])}`),null)}}function FN(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=NT(e,t,n,`name`);return a===null?null:{preset:`delete`,name:a}}function IN(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 LN={run:[`doctor`],fix:[`doctor`,`check`],mark:[`doctor`,`check`,`mark`]};function RN(e,t,n){let r=n.doctor,i=typeof r==`string`&&Object.hasOwn(LN,r),a=i?LN[r]:[...new Set(Object.values(LN).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(LN).map(e=>`"${e}"`).join(`, `)}, got ${Z(r)}`),null;if(r===`run`)return{doctor:`run`};let o=n.check,s=r===`mark`?yO:vO;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 $D.includes(c)?{doctor:`mark`,check:o,mark:c}:(Q(e,`${t}.mark`,`doctor mark must be ${$D.map(e=>`"${e}"`).join(` or `)}, got ${Z(c)}`),null)}function zN(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 BN(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=IO(n.slash);return r.kind===`refused`?(Q(e,`${t}.slash`,r.reason),null):{slash:r.line}}function VN(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 HN(e,t,n,r,i,a){let o=NT(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 UN={set:`the SessionState key to write`,persist:`the config globals field to write`};function WN(e,t,n,r){let i=UN[r],a=HN(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 GN(e){return e===`set`?`set-state`:`set-config`}const KN={to:dP(`set`)},qN={to:dP(`persist`)},JN={from:fP(`set`)},YN={from:fP(`persist`)},XN={min:_P(),max:_P(),by:_P()},ZN={int:mP()},QN={cycle:pP(`set`)},$N={cycle:pP(`persist`)},eP={removeSegment:hP(`removeSegment`)},tP={insertSegment:hP(`insertSegment`),anchor:hP(`anchor`),relation:gP()},nP={insertSegmentFrom:fP(`persist`),anchor:hP(`anchor`),relation:gP()},rP={ok:e=>e.min<e.max,issue:e=>({field:`min`,message:`min (${e.min}) must be less than max (${e.max})`})},iP={ok:e=>e.by!==0,issue:()=>({field:`by`,message:`by must be a non-zero integer (the per-click increment; negative steps down)`})};function aP(e,t,n=[],r){let i=Object.keys(t),a=r??i,o=[e],s=(e,n,r)=>VT(e,t,n,r),c=aE(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?YT(s,...n):s}}const oP=[aP(`set`,KN),aP(`set`,JN),aP(`set`,XN,[rP,iP]),aP(`set`,ZN),aP(`set`,QN)],sP=[aP(`persist`,qN),aP(`persist`,YN),aP(`persist`,XN,[rP,iP]),aP(`persist`,$N),aP(`persist`,eP),aP(`persist`,tP,[],[`insertSegment`]),aP(`persist`,nP,[],[`insertSegmentFrom`])];function cP(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 lP(e){let t=cP(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 uP(e,t,n,r,i){let a=WN(e,t,n,r),o=i.filter(e=>e.detect.some(e=>e in n));if(o.length!==1)return Q(e,t,`${lP(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 dP(e){let t=GN(e);return{required:!0,json:{type:`string`},parse:(n,r,i,a)=>HN(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 fP(e){let t=GN(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 pP(e){let t=GN(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 ${X(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 mP(){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 hP(e){return{required:!0,json:{type:`string`},parse:(t,n,r,i)=>{let a=NT(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 gP(){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 _P(){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 vP(e,t,n){return`${e}: "${t}" is an endcaps shape, not a style — endcaps were renamed from "style" to "endcaps"; write ${n}: "${t}"`}const yP={noun:`style key`,fields:{hueShift:$T(),chromaScale:$T({min:0}),lightnessScale:$T(),lightnessShift:$T()}};function bP(e,t){if(!RT(t))return e.issues.push({path:`styles`,message:`styles must be an object mapping style names to adaptation objects, got ${X(t)}`,line:J(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:J(e.source,[`styles`,r])});continue}if(Bp(r)){e.issues.push({path:`styles.${r}`,message:vP(`styles.${r}`,r,`globals.endcaps`),line:J(e.source,[`styles`,r])});continue}let t=zT(e,yP,`styles.${r}`,i);t!==null&&(n[r]={...Ls,...t})}return n}const xP={noun:`preset key`,fields:{root:{required:!1,json:{$ref:`#/definitions/RootFragment`},parse:(e,t,n,r)=>r[n]===void 0?void 0:iN(e,`${t}.${n}`,r[n])},globals:{required:!1,json:RE(),parse:(e,t,n,r)=>r[n]===void 0?void 0:LE(e,`${t}.${n}`,r[n])}}};function SP(e,t){if(!RT(t))return e.issues.push({path:`presets`,message:`presets must be an object mapping preset names to config fragments, got ${X(t)}`,line:J(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:J(e.source,[`presets`,r])});continue}let t=zT(e,xP,`presets.${r}`,i);t!==null&&(n[r]=t)}return n}function CP(e,t){if(t===void 0)return{};if(!RT(t))return e.issues.push({path:`helpers`,message:`helpers must be an object, got ${X(t)}`,line:J(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:J(e.source,[`helpers`,r])});continue}n[r]=i}return n}const wP=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 TP(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 EP(e){let t=wP.get(e);return t===void 0?void 0:`variables.${e} is no longer read: ${TP(t)}`}function DP(e){let t=wP.get(e);return t===void 0?``:` — ".${e}" is no longer a variable: ${TP(t)}; a "${t.segment}" template reads it as ".settings.${t.setting}"`}function OP(e,t){let n=new Map;for(let e of Object.keys(t)){let t=iT(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:J(e.source,[`presets`])})}function kP(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||Sp(i)||Object.prototype.hasOwnProperty.call(t.styles,i))continue;let r=`${n.join(`.`)}.style`;e.issues.push({path:r,message:Bp(i)?vP(r,i,a):`${r} "${i}" does not match any declared style (have: ${Object.keys(t.styles).join(`, `)})`,line:J(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:J(e.source,[`globals`,`preset`])}),OP(e,t.presets),QP(e,t);let i=Fg(t);for(let t of i.names)t!==`settings`&&!t.startsWith(MP)||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:J(e.source,[`variables`,t])});let a=(t,n,r)=>{hA(t)>1&&e.issues.push({path:n,message:`${n} places the global settings menu anchor "${JO}" ${hA(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}),gA(t)&&e.issues.push({path:n,message:`${n} places the global settings menu anchor "${JO}" 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 bh(t)){if(e.kind!==`segment`)continue;let t=gh(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=vh(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||hh[e.direction]===`cell`))}let s=(n,r)=>{for(let[a,o]of Zh(n,r)){let n=J(e.source,o.split(`.`));if(a.when!==void 0&&(WP(e,`${o}.when`,a.when,i,{line:n}),UP(e,`${o}.when`,a.when,n)),a.kind===`segment`){if(fA(a.name)){(a.id!==void 0||a.settings!==void 0)&&e.issues.push({path:o,message:`${r} gives the global settings menu anchor "${JO}" an id or settings — the anchor only marks where the menu goes, so place it as the bare name "${JO}"`,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${_M(a.name)}`,line:n}),BP(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`,Yh(t.root)]]);for(let e of ng(t.presets)){let{node:n,path:r}=ag(t,e);c.set(r,n)}for(let[t,n]of c)a(n,t,J(e.source,t.split(`.`)));ZP(e,t,i,()=>!0)}const AP=[`removeSegment`,`insertSegment`,`insertSegmentFrom`];function jP(e,t,n,r,i,a,o){let s=`actions.${n}.${r}`,c=J(e.source,[`actions`,n,r]);if(!ng(t.presets).includes(a)){e.issues.push({path:s,message:`actions.${n}: "${i}" names preset "${a}" which is not declared (have: ${ng(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(`, `)})${_M(i)}`,line:c})},p=new Set(_h(ag(t,a).node)),m=(r,i)=>{!gM.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${_M(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 MP=`settings.`;function NP(e,t){return{...e,names:new Set([...e.names,...Object.keys(t).map(e=>MP+e)])}}function PP(e,t,n){let r=e=>`segments.${t}.settings.${e}`,i=(n,i)=>{e.issues.push({path:r(n),message:`${r(n)}: ${i}`,line:J(e.source,[`segments`,t,`settings`,n])})},a=LP(n);for(let{setting:e,message:t}of a)i(e,t);if(!(a.length>0))for(let{setting:e,message:t}of Fh(n,IP(n)))i(e,`the defaults do not stand together: ${t}`)}function FP(e){return LP(e).length>0||Fh(e,IP(e)).length>0}function IP(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.default]))}function LP(e){let t=t=>Ph(RP(e,t))?.atLeast;return Object.keys(e).flatMap(n=>{let r=t(n);if(r===void 0)return[];if(r===n||Ph(RP(e,r))===void 0)return[{setting:n,message:`atLeast "${r}" must name another range setting of this segment (its range settings: ${zP(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 RP(e,t){return Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}function zP(e,t){return Object.entries(e).filter(([e,n])=>e!==t&&Ph(n)!==void 0).map(([e])=>e)}function BP(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=Nh(a),s=`${r}: placement "${gh(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(`, `)})`:Ih(c,a)?void 0:`sets "${t}" to ${JSON.stringify(a)}${c.domain===`theme`?pp(a):``}, but it must be ${Bh(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])=>Ih(o[e],t))||FP(o)))for(let{message:t}of Fh(o,c))e.issues.push({path:r,message:`${s}: ${t}`,line:i})}function VP(e,t,n,r,i){n.kind===`template`&&WP(e,`${t}.template`,n.template,r,{segCtx:i}),Oh(n)&&`key`in n.cache&&WP(e,`${t}.cache.key`,n.cache.key,r,{segCtx:i})}function HP(e,t,n,r,i){if(!(!Oh(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:J(e.source,[...t.split(`.`),`cache`,`depends_on`])})}}function UP(e,t,n,r){try{iD.parse(n)}catch(n){e.issues.push({path:t,message:`Template parse error in ${t}: ${n.message}`,line:r})}}function WP(e,t,n,r,i){for(let[a,o]of Dg(n,r.helpers)){if(Pg(a,r))continue;if(a.startsWith(MP)){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??J(e.source,t.split(`.`))});continue}if(o!==null){GP(e,o,`Template references unknown variable ".${a}"${DP(a)}`);continue}let n=i?.segCtx===void 0?void 0:`${i.segCtx}.${a}`,s=n!==void 0&&Pg(n,r)?` (segment-local vars are namespaced — write ".${n}")`:DP(a);e.issues.push({path:t,message:`Template references unknown variable ".${a}"${s}`,line:i?.line??J(e.source,t.split(`.`))})}}function GP(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:J(e.source,[`helpers`,t])})}function KP(e,t,n,r,i){let a=n.set,o=SE(ba[r].configKey),s=`${a} takes ${OT(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:J(e.source,[`actions`,t,`min`])});return}let c=YP(n,i);if(c===JP){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:J(e.source,[`actions`,t,`int`])});return}let l=c.filter(e=>!DT(o,e.value,i));if(l.length!==0){if(a===ba.style.sessionKey&&(`from`in n&&n.from===`endcaps`||c.every(e=>Bp(e.value)))){let r=ba.endcaps.sessionKey;e.issues.push(`to`in n?{path:`actions.${t}.to`,message:vP(`actions.${t}.to`,n.to,`set: "${r}", to`),line:J(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:J(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<=qP?r.join(`, `):`${r.slice(0,qP).join(`, `)} and ${r.length-qP} 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:J(e.source,[`actions`,t,n])})}}}const qP=3,JP=Symbol(`any integer`);function YP(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?fg(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)}]:JP}function XP(e,t){return Object.entries(e).filter(([e])=>t(e))}function ZP(e,t,n,r){let i=WA(t),a=dg(i);for(let[n,o]of XP(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 ${mg(r,i)}`,line:J(e.source,[`actions`,n,t])});continue}if(!(`set`in o))continue;Ca.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:J(e.source,[`actions`,n,`set`])});let s=Da.get(o.set);s!==void 0&&KP(e,n,o,s,i)}for(let[n,i]of XP(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&&DN(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:J(e.source,[`actions`,n,`do`])})});for(let[n,i]of XP(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=$E(r);if(o===null){e.issues.push({path:`actions.${n}.${a}`,message:`actions.${n}: "${r}" is not a config globals field (have: ${HE().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`,line:J(e.source,[`actions`,n,a])});continue}let s=AP.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:J(e.source,[`actions`,n,a])});continue}if(o.scope===`preset-root`){jP(e,t,n,a,r,o.preset,i);continue}if(o.scope===`preset-globals`&&!ng(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: ${ng(t.presets).join(`, `)})`,line:J(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${pp(o.theme)} (have: ${[...e.allowedPalettes].sort().join(`, `)})`,line:J(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(`, `)})${_M(o.segment)}`,line:J(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:J(e.source,[`actions`,n,a])})}}for(let[i,a]of XP(t.variables,r)){VP(e,`variables.${i}`,a,n);let t=EP(i);t!==void 0&&e.issues.push({path:`variables.${i}`,message:t,line:J(e.source,[`variables`,i])})}for(let[i,a]of XP(t.segments,r)){if(a.vars)for(let[t,r]of Object.entries(a.vars))VP(e,`segments.${i}.vars.${t}`,r,n,i);let r=Nh(a);PP(e,i,r);let o=NP(n,r);for(let n of[`template`,`bg`,`fg`,`when`]){let s=a[n];if(typeof s==`string`){WP(e,`segments.${i}.${n}`,s,o,{segCtx:i,settings:r});for(let{name:r,site:a,via:o}of jg(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){GP(e,o,`Template references unknown action "${r}"${s}`);continue}e.issues.push({path:`segments.${i}.${n}`,message:`${n} references unknown action "${r}"${s}`,line:J(e.source,[`segments`,i,n])})}}}}for(let[i,a]of XP(t.variables,r))HP(e,`variables.${i}`,a,n);for(let[i,a]of XP(t.segments,r))if(a.vars)for(let[t,r]of Object.entries(a.vars))HP(e,`segments.${i}.vars.${t}`,r,n,i)}function QP(e,t){let n=new Set;for(let r of ng(t.presets)){let i=og(t,r),a=[{},t.editGlobals];for(let o of a){let a=o.charset??i.charset??`unicode`,s=o.default_separator??i.default_separator;if(a!==`ascii`||Up(s??``))continue;let c=o.default_separator===void 0?ig(t.presets,r).globals?.default_separator===void 0?[`globals`]:[`presets`,r,`globals`]:[`editGlobals`],l=[...c,`default_separator`].join(`.`);n.has(l)||(n.add(l),e.issues.push({path:l,message:`${l} ${JSON.stringify(s)} is not ASCII, but charset is "ascii" — under ascii a joiner draws only ASCII; write an ASCII separator or set charset: "unicode"`,line:J(e.source,[...c,`default_separator`])}))}}}function $P(e,t,n=()=>!0){let{graph:r,nodeInfo:i}=eF(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:J(e.source,a?.linePathParts??[`variables`,r])}),!0}if(t===0&&s(c))return!0}return a.set(t,2),o.pop(),!1}}function eF(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 Dg(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),Oh(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 tF(e){return e===`~`||e.startsWith(`~/`)||e.startsWith(`~\\`)?h.homedir()+e.slice(1):e}function nF(e,t){return l.resolve(e,tF(t))}function rF(e,t){return typeof t==`string`&&t!==``?nF(e,t):void 0}function iF(e){return`plugin ${e.path} was not loaded: ${e.reason}`}const aF=new Set([`data`,`segments`,`helpers`,`actions`]),oF=`plugin.json5`,sF=/^[a-z][a-z0-9_]*$/;function cF(e){let t=l.basename(l.dirname(e));return sF.test(t)?t:void 0}const lF=`plugins.`;function uF(e){return`${lF}${e}.data`}function dF(e){try{return{ok:!0,value:e()}}catch(e){return{ok:!1,reason:fF(e)}}}function fF(e){return e instanceof aT?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 pF(e,t){return e.map(e=>nF(l.dirname(t),e))}function mF(e,t,n,i){let a=new Map;return e.reduce((e,n)=>{let o=cF(n),s=(t,r)=>{let i=new Map(e.rendering);return o!==void 0&&r!==e.config&&i.delete(o),{...e,config:r,rendering:i,dropped:[...e.dropped,{path:n,plugin:o,reason:t}]}};if(l.basename(n)!==`plugin.json5`){let t=`a plugin is a folder holding its ${oF}, and the folder's name is the plugin's: move this file to <dir>/<name>/${oF} and list that`;return s(t,o===void 0?e.config:_F(gF(e.config,o),o,{path:n,plugin:o,reason:t}))}if(o===void 0)return s(`its folder "${l.basename(l.dirname(n))}" is not a plugin name (one matching ${sF}: it prefixes every name the plugin declares)`,e.config);let c=a.get(o);if(c!==void 0)return s(`plugin "${o}" is already listed, from ${c}`,e.config);a.set(o,n);let u=gF(e.config,o),d=dF(()=>{let a=r.readFileSync(n,`utf-8`),s=Aj(CF(n,o,{source:a,json:_r.default.parse(a)},t),u);return i(s,o,u!==e.config),s});if(d.ok)return{...e,config:d.value,loaded:[...e.loaded,n],rendering:new Map([...e.rendering,[o,n]])};let f={path:n,plugin:o,reason:d.reason};return s(d.reason,_F(u,o,f))},{config:n.config,rendering:n.rendering,loaded:[],dropped:[]})}function hF(e){let t=`${lF}${e}.`;return e=>e.startsWith(t)}function gF(e,t){let n=hF(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 _F(e,t,n){return{...e,variables:{...e.variables,[uF(t)]:{kind:`dropped`,reason:iF(n),definition:n.path}}}}function vF(e){return e.startsWith(`plugins.`)?e.slice(8).split(`.`)[0]:void 0}function yF(e,t){let n=new Set([...Object.keys(e.config.variables),...Object.keys(e.config.segments)].map(vF)),r=[...t,...e.dropped].filter(e=>e.plugin===void 0).map(e=>({definition:e.path,notice:iF(e)}));return t=>{let i=vF(t);if(i===void 0)return[];let a=e.config.variables[uF(i)];return a?.kind===`dropped`?[{definition:a.definition,notice:a.reason}]:n.has(i)?[]:r}}function bF(e,t){let n=ng(e.presets).flatMap(t=>[...bh(ag(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,xF(e,t.map(e=>e.notice),n.filter(t=>t.name===e))])),a=t=>{let n=vF(t),r=n===void 0?void 0:e.variables[uF(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=>jg(t,e.helpers).map(e=>e.name)),...c],e.actions),d=l(s.flatMap(t=>[...Ng(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:`{{ .${uF(vF(e)??``)} }}`}]))},helpers:{...e.helpers,...Object.fromEntries(d.map(([e,t])=>[e,`{{ fail ${JSON.stringify(t.notice)} }}`]))}},reached:f}}function xF(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,SF(e,t)]));return{template:`{{ ${JSON.stringify(r)} }}`,bg:`error`,description:`stands in for a segment whose plugin did not load`,settings:a}}function SF(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 CF(e,t,{source:n,json:r},{checkout:i}){let a=[],o=()=>{throw new aT(e,a)};if(!RT(r))return a.push({path:``,message:`a plugin definition must be an object, got ${X(r)}`}),o();for(let e of Object.keys(r))aF.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: ${[...aF].join(`, `)}`});let s=EF(r.data,e,i,a);if(RT(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(gp()),groups:[]},l=Vj(c,`data`,{[uF(t)]:{kind:`file`,path:s,parse:{json:!0},cache:{watch_file:s},default:{}}});for(let[e,t]of Object.entries(r.segments))RT(t)&&`vars`in t&&a.push({path:`segments.${e}.vars`,message:`a plugin segment may not declare "vars": a plugin's only source is its data file`});let u={variables:l,segments:TF(t,FM(c,r.segments,new Set)),helpers:TF(t,CP(c,r.helpers)),actions:TF(t,ON(c,r.actions))};for(let[e,t]of wF(u))try{iD.parse(t)}catch(t){a.push({path:e,message:`Template parse error in ${e}: ${t.message}`})}return a.length>0&&o(),u}function*wF(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 TF(e,t){return Object.fromEntries(Object.entries(t).map(([t,n])=>[`${lF}${e}.${t}`,n]))}function EF(e,t,n,r){if(typeof e==`string`&&e!==``)return nF(l.dirname(t),e);if(RT(e)&&Object.keys(e).length===1&&typeof e.checkout==`string`&&e.checkout!==``){let t=e.checkout;if(l.isAbsolute(t)||t.startsWith(`~`)||l.normalize(t).split(l.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 l.resolve(n.root,t)}if(RT(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 DF(e){let t=(process.env.XDG_DATA_DIRS||OF()).split(`:`).filter(e=>e!==``),n=process.env.XDG_DATA_HOME||l.join(h.homedir(),`.local`,`share`),r=[...[...t].reverse().map(e=>l.join(e,`cc-candybar`,`plugins`)),l.join(n,`cc-candybar`,`plugins`),...e===null?[]:[l.join(e,`.cc-candybar`,`plugins`)]];return r.filter((e,t)=>r.lastIndexOf(e)===t)}function OF(){let e=`/usr/local/share:/usr/share`;return process.platform===`darwin`?`${l.join(process.env.HOMEBREW_PREFIX||`/opt/homebrew`,`share`)}:${e}`:e}function kF(e){let t=DF(e),n=new Map,r=[],i=[];for(let e of t){let t=AF(e);if(`error`in t){r.push(t);continue}for(let r of t.folders)n.delete(r),n.set(r,l.join(e,r,oF));for(let n of t.files)i.push({path:l.join(e,n),plugin:void 0,reason:`a plugin is a folder holding its ${oF}: move this file to ${l.join(e,`<name>`,oF)}`})}return{roots:t,definitions:[...n.values()],unchecked:r,strays:i}}function AF(e){try{let t=r.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()||jF(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 jF(e,t){if(!t.isSymbolicLink())return!1;try{return r.statSync(l.join(e,t.name)).isDirectory()}catch{return!0}}const MF=[`json5`,`json`];function NF(e){try{return r.statSync(e,{throwIfNoEntry:!1})===void 0?`absent`:`present`}catch(t){return{path:e,error:t.message}}}function PF(e,t,n){if(n!==void 0)return[n];let r=t??process.cwd();return[...new Set([...e?MF.map(t=>l.join(e,`.cc-candybar.${t}`)):[],...MF.map(e=>l.join(r,`.cc-candybar.${e}`)),...MF.map(e=>`${FF()}.${e}`)])]}function FF(){let e=process.env.XDG_CONFIG_HOME??l.join(h.homedir(),`.config`);return l.join(e,`cc-candybar`,`config`)}function IF(e,t,n){let i=[],a=new Map;for(let o of PF(e,t,n)){let e=NF(o);if(e===`absent`)continue;if(e!==`present`){i.push(e);continue}let t=l.join(r.realpathSync(l.dirname(o)),l.basename(o).replace(/\.(json5|json)$/,``));a.has(t)||a.set(t,o)}let o=[...a.values()].reverse();if(n===void 0)return{kind:`chain`,layers:o,home:LF(o),unchecked:i};let[s]=i,c=n;return o.length>0?{kind:`chain`,layers:o,home:c,unchecked:i}:s===void 0?{kind:`missing`,path:n,home:c}:{kind:`unreadable`,...s,home:c}}function LF(e){let t=FF();return e.find(e=>MF.some(n=>e===`${t}.${n}`))??`${t}.${MF[0]}`}function RF(e,t,n){let r=IF(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 zF(e){return BF(e).join(`
|
|
148
|
+
`)||null}function BF(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 VF(e,t){let n=PF(e,t).filter(e=>NF(e)===`present`),r=new Map;for(let e of n){let t=l.dirname(e),n=l.basename(e).replace(/\.(json5|json)$/,``),i=l.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 HF(e,t,n,i){return e===null?{...ZF,config:Aj(ZF.raw,t)}:WF(e,r.readFileSync(e,`utf-8`),t,n,i)}const UF={projectDir:null,checkout:null,beneath:{dropped:[],rendering:new Map}};function WF(e,t,n,r,i){let a=eI(e,t,i,(t,a)=>{let o=mF(pF(t,e),r,{config:n,rendering:r.beneath.rendering},(t,n,r)=>YF(t,n,r,e,i)),s=yF(o,r.beneath.dropped);return{inherited:new Set([...PM(o.config),...a.filter(e=>s(e).length>0)]),layer:{plugins:o,owning:s}}}),{plugins:o,owning:s}=a.layer,c=bF(Aj(a.raw,o.config),s);return{source:t,raw:a.raw,warnings:[...a.warnings,...o.dropped.map(iF)],plugins:{loaded:o.loaded,dropped:o.dropped,reached:c.reached,rendering:o.rendering},config:c.config}}const GF=new WeakMap;function KF(e,t,n,r){let i=JSON.stringify([[...r??[]].sort(),e.map(e=>[e,qF(e)])]),a=GF.get(n)??new Map;GF.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=mF(e,t,{config:n,rendering:new Map},(e,t,n)=>YF(e,t,n,`<installed plugins>`,r));return a.set(o,{key:i,layer:c}),c}function qF(e){try{let t=r.statSync(e);return`${t.ino}:${t.size}:${t.mtimeMs}`}catch(e){return e.code??`unreadable`}}function JF(e,t,n,i,a=e=>r.readFileSync(e,`utf-8`),o){let s={projectDir:i.projectDir,checkout:i.cwd===null?null:VC(i.cwd)},c=kF(s.projectDir),l=KF(c.definitions,s,t,o),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=WF(t,a(t),f.at(-1)?.config??d,{...s,beneath:{dropped:[...u.dropped,...f.flatMap(e=>e.plugins.dropped)],rendering:e?.rendering??u.rendering}},o);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(iF));let _={checkout:s.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:QF(HF(null,d,UF),`<default>`,o)};try{return{layers:f,base:d,installed:_,config:QF(v,v.path,o)}}catch(e){for(let e of f.slice(0,-1))n.entered(e.path),QF(e,e.path,o);throw n.entered(v.path),e}}function YF(e,t,n,r,i){if(n){QF(XF(e),r,i);return}let a=hF(t),o=[],s={source:``,issues:o,allowedPalettes:new Set,groups:[]};if(ZP(s,e,Fg(e),a),$P(s,e,a),o.length>0)throw new aT(r,o)}function XF(e){return{config:e,raw:{root:e.root,presets:e.presets},source:``}}const ZF={raw:{},source:``,warnings:[],plugins:{loaded:[],dropped:[],reached:new Set,rendering:new Map}};function QF({config:e,raw:t,source:n},r=`<config>`,i=new Set(gp())){let a=[],o={source:n,issues:a,allowedPalettes:i,groups:[]};if(kP(o,e,t),$P(o,e),a.length>0)throw new aT(r,a);let s=wN(e,a);if(a.length>0)throw new aT(r,a);return cj(OA(s))}function $F(e,t,n=new Set(gp()),r=tI){return eI(e,t,n,()=>({inherited:r,layer:null})).raw}function eI(e,t,n,r){let i=nI(e,t),a=cT(e,t),o=a===null?[]:[a],s=[],c={source:t,issues:s,allowedPalettes:n??new Set(gp()),groups:[]};if(!RT(i))throw new aT(e,[{path:``,message:`Config root must be an object, got ${X(i)}`}],o);let{inherited:l,layer:u}=r(i.plugins===void 0?[]:aI({...c,issues:[]},i.plugins)??[],RT(i.segments)?Object.keys(i.segments):[]),d=rI(c,i,l);if(s.length>0)throw new aT(e,s,o);return{raw:d,warnings:o,layer:u}}const tI=new Set;function nI(e,t){try{return _r.default.parse(t)}catch(t){let n=t;throw new aT(e,[{path:``,message:`JSON5 syntax error: ${n.message}`,line:n.lineNumber,col:n.columnNumber}])}}function rI(e,t,n){for(let n of Object.keys(t))iI.has(n)||e.issues.push({path:n,message:`Unknown top-level key "${n}". Expected one of: ${[...iI].join(`, `)}`,line:J(e.source,[n])});let r={};return t.globals!==void 0&&(r.globals=IE(e,`globals`,t.globals)),t.variables!==void 0&&(r.variables=Vj(e,`variables`,t.variables)),t.segments!==void 0&&(r.segments=FM(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.
|
|
149
149
|
Replace: layout: [["seg1", "seg2"], ["seg3"]]
|
|
150
150
|
With: root: { v: [{ h: ["seg1", "seg2"] }, "seg3"] }
|
|
151
|
-
Single-row example: root: { h: ["seg1", "seg2"] }`,line:J(e.source,[`layout`])}),t.root!==void 0&&(r.root=JM(e,`root`,t.root)),t.actions!==void 0&&(r.actions=vN(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:J(e.source,[`looks`])}),t.styles!==void 0&&(r.styles=uP(e,t.styles)),t.themeDefaults!==void 0&&(r.themeDefaults=FE(e,t.themeDefaults)),t.presets!==void 0&&(r.presets=fP(e,t.presets)),t.editGlobals!==void 0&&(r.editGlobals=zE(e,`editGlobals`,t.editGlobals)),t.helpers!==void 0&&(r.helpers=pP(e,t.helpers)),t.plugins!==void 0&&(r.plugins=YF(e,t.plugins)),nN(e,r),fN(e,r),_D(e,r),gT(e,r,Y,`the global settings menu`),r}const JF=new Set([`globals`,`variables`,`segments`,`layout`,`looks`,`root`,`actions`,`styles`,`themeDefaults`,`presets`,`editGlobals`,`helpers`,`plugins`]);function YF(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 ${X(t)}`,line:J(e.source,[`plugins`])})}const XF={},ZF=AO(`commands.`),QF=IO(`autocompact.`,e=>`{{ template "formatTokenCount" ${e} }}`),$F=`trimPrefix "/" (trimPrefix .project_dir .current_dir)`,eI=`{{ \$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 (${$F}) (basename .project_dir) (ne (${$F}) "") }}{{ end }}{{ end }}{{ action "copyDir" (abbreviatePath \$dir) }}`,tI=`{{ ${MD} }}`,nI={min:0,max:100,step:5},rI={warnAt:{label:`warning at %`,domain:nI,default:50},errorAt:{label:`error at %`,domain:{...nI,atLeast:`warnAt`},default:80}};function iI(e){return{budget:{label:`budget $`,domain:{min:0,max:1e4,step:5},default:e},warnAt:{label:`warning at %`,domain:nI,default:80}}}const aI={globals:{palette:`tokyo-night`},variables:{...ZF.variables,...eT,current_dir:{kind:`input`,path:`workspace.current_dir`,default:`?`},"model.display_name":{kind:`input`,path:`model.display_name`,default:``},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:eI},model:{group:`model-context`,description:`The active model's display name.`,template:`✱ {{ formatModelName .model.display_name }}`,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:tI,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:yO(``).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:ZF.template,when:ZF.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:iI(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:iI(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:rI,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:rI,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) ${zf} }}`,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:QF.template,bg:QF.bg,when:QF.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:{...yO(``).actions,...ZF.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`},...QF.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:XF,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:{gitPaint:`{{ fg (readableOn (color .color) (bgOf) ${zf}) .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:LO(`.`),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 .)) }}`}},oI=new Set([aI.globals.palette,...Object.keys(aI.themeDefaults),...Object.values(aI.segments).map(e=>e.palette)].filter(e=>e!==void 0)),sI=bj(UF(`<default>`,JSON.stringify(aI),oI),aI),cI=ng(sI.presets);function lI(e){return cI.includes(e)}const uI=Object.freeze({});function dI(e,t){return e.kind===`decided`?t[e.name]??uI:uI}function fI(e,t){return{...e,...Object.fromEntries(Th.map(n=>[n,e[n]??t[n]]))}}function pI(e){if(!e)return``;try{return mI(s(e))}catch{return``}}function mI(e){return`${e.mtimeMs}:${e.size}`}const hI=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 gI(e){return((...t)=>hI.run(()=>e(...t)))}const _I=gI(E),vI=gI(oe),yI=gI(se);async function bI(e,t){return hI.run(async()=>{let n=null;try{n=await T(e,`r`);let r=await n.stat(),{size:i,ino:a}=r,o=mI(r),s=t!==void 0&&(a!==t.ino||i<t.offset),c=s||t===void 0?0:t.offset;if(c>=i)return F({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 F({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`?I:L(`readAppended ${e}: ${t instanceof Error?t.message:String(t)}`)}finally{await n?.close().catch(e=>{D(`transcript-fs: close failed: ${e instanceof Error?e.message:String(e)}`)})}})}async function xI(e,t){return hI.run(async()=>{let n=null;try{n=await T(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 F({buf:o===a.length?a:a.subarray(0,o),fromStart:i===0})}catch(t){return t.code===`ENOENT`?I:L(`readTail ${e}: ${t instanceof Error?t.message:String(t)}`)}finally{await n?.close().catch(e=>{D(`transcript-fs: close failed: ${e instanceof Error?e.message:String(e)}`)})}})}const SI=/"(?:cache_read_input_tokens|cache_creation_input_tokens)":[1-9]/;function CI(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 wI(e){let t=await TI(e);return t.kind===`ok`?F(Math.floor((t.value+36e5)/1e3)):t}async function TI(e){for(let t of[65536,1048576]){let n=await xI(e,t);if(n.kind!==`ok`)return n;let r=EI(n.value.buf,n.value.fromStart);if(r!=null)return F(r);if(n.value.fromStart)return I}return I}function EI(e,t){let n=e.toString(`utf8`).split(`
|
|
152
|
-
`),r=+!t;for(let e=n.length-1;e>=r;e--){let t=n[e];if(!t||!
|
|
151
|
+
Single-row example: root: { h: ["seg1", "seg2"] }`,line:J(e.source,[`layout`])}),t.root!==void 0&&(r.root=iN(e,`root`,t.root)),t.actions!==void 0&&(r.actions=ON(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:J(e.source,[`looks`])}),t.styles!==void 0&&(r.styles=bP(e,t.styles)),t.themeDefaults!==void 0&&(r.themeDefaults=FE(e,t.themeDefaults)),t.presets!==void 0&&(r.presets=SP(e,t.presets)),t.editGlobals!==void 0&&(r.editGlobals=zE(e,`editGlobals`,t.editGlobals)),t.helpers!==void 0&&(r.helpers=CP(e,t.helpers)),t.plugins!==void 0&&(r.plugins=aI(e,t.plugins)),fN(e,r),SN(e,r),_D(e,r),gT(e,r,Y,`the global settings menu`),r}const iI=new Set([`globals`,`variables`,`segments`,`layout`,`looks`,`root`,`actions`,`styles`,`themeDefaults`,`presets`,`editGlobals`,`helpers`,`plugins`]);function aI(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 ${X(t)}`,line:J(e.source,[`plugins`])})}const oI={},sI=BO(`commands.`),cI=KO(`autocompact.`,e=>`{{ template "formatTokenCount" ${e} }}`),lI=`trimPrefix "/" (trimPrefix .project_dir .current_dir)`,uI=`{{ \$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 (${lI}) (basename .project_dir) (ne (${lI}) "") }}{{ end }}{{ end }}{{ action "copyDir" (abbreviatePath \$dir) }}`,dI=`{{ ${MD} }}`,fI={min:0,max:100,step:5},pI={warnAt:{label:`warning at %`,domain:fI,default:50},errorAt:{label:`error at %`,domain:{...fI,atLeast:`warnAt`},default:80}};function mI(e){return{budget:{label:`budget $`,domain:{min:0,max:1e4,step:5},default:e},warnAt:{label:`warning at %`,domain:fI,default:80}}}const hI={globals:{palette:`tokyo-night`},variables:{...sI.variables,...eT,current_dir:{kind:`input`,path:`workspace.current_dir`,default:`?`},"model.display_name":{kind:`input`,path:`model.display_name`,default:``},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:uI},model:{group:`model-context`,description:`The active model's display name.`,template:`✱ {{ formatModelName .model.display_name }}`,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:dI,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:kO(``).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:sI.template,when:sI.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:mI(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:mI(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:pI,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:pI,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) ${zf} }}`,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:cI.template,bg:cI.bg,when:cI.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:{...kO(``).actions,...sI.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`},...cI.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:oI,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:{gitPaint:`{{ fg (readableOn (color .color) (bgOf) ${zf}) .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:qO(`.`),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 .)) }}`}},gI=new Set([hI.globals.palette,...Object.keys(hI.themeDefaults),...Object.values(hI.segments).map(e=>e.palette)].filter(e=>e!==void 0)),_I=Aj($F(`<default>`,JSON.stringify(hI),gI),hI),vI=ng(_I.presets);function yI(e){return vI.includes(e)}const bI=Object.freeze({});function xI(e,t){return e.kind===`decided`?t[e.name]??bI:bI}function SI(e,t){return{...e,...Object.fromEntries(Th.map(n=>[n,e[n]??t[n]]))}}function CI(e){if(!e)return``;try{return wI(s(e))}catch{return``}}function wI(e){return`${e.mtimeMs}:${e.size}`}const TI=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 EI(e){return((...t)=>TI.run(()=>e(...t)))}const DI=EI(E),OI=EI(oe),kI=EI(se);async function AI(e,t){return TI.run(async()=>{let n=null;try{n=await T(e,`r`);let r=await n.stat(),{size:i,ino:a}=r,o=wI(r),s=t!==void 0&&(a!==t.ino||i<t.offset),c=s||t===void 0?0:t.offset;if(c>=i)return F({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 F({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`?I:L(`readAppended ${e}: ${t instanceof Error?t.message:String(t)}`)}finally{await n?.close().catch(e=>{D(`transcript-fs: close failed: ${e instanceof Error?e.message:String(e)}`)})}})}async function jI(e,t){return TI.run(async()=>{let n=null;try{n=await T(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 F({buf:o===a.length?a:a.subarray(0,o),fromStart:i===0})}catch(t){return t.code===`ENOENT`?I:L(`readTail ${e}: ${t instanceof Error?t.message:String(t)}`)}finally{await n?.close().catch(e=>{D(`transcript-fs: close failed: ${e instanceof Error?e.message:String(e)}`)})}})}const MI=/"(?:cache_read_input_tokens|cache_creation_input_tokens)":[1-9]/;function NI(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 PI(e){let t=await FI(e);return t.kind===`ok`?F(Math.floor((t.value+36e5)/1e3)):t}async function FI(e){for(let t of[65536,1048576]){let n=await jI(e,t);if(n.kind!==`ok`)return n;let r=II(n.value.buf,n.value.fromStart);if(r!=null)return F(r);if(n.value.fromStart)return I}return I}function II(e,t){let n=e.toString(`utf8`).split(`
|
|
152
|
+
`),r=+!t;for(let e=n.length-1;e>=r;e--){let t=n[e];if(!t||!MI.test(t))continue;let r=NI(t);if(r!=null)return r}return null}function LI(e,t){return{...e,claudeConfigDir:li(t.claudeConfigDir),env:t.mementoEnv}}const RI=l.join(`lib`,`ceiling_config.py`),zI=l.join(`skills`,`ceiling`,`bin`,`ceiling`);function BI(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 VI(e,t){let n=!0;for(let i of e){if(!r.existsSync(i))continue;let e;try{e=JSON.parse(r.readFileSync(i,`utf8`))?.enabledPlugins?.[t]}catch(e){return L(`memento lookup: ${i}: ${e.message}`)}typeof e==`boolean`&&(n=e)}return F(n)}function HI(e,t){if(!r.existsSync(e))return I;let n;try{n=BI(JSON.parse(r.readFileSync(e,`utf8`)),e)}catch(e){return L(`memento lookup: ${e.message}`)}let i=n.find(e=>e.projectPath===t)??n.find(e=>e.scope===`user`);if(i===void 0)return I;let a=VI([l.join(l.dirname(l.dirname(e)),`settings.json`),l.join(t,`.claude`,`settings.json`),l.join(t,`.claude`,`settings.local.json`)],i.key);if(a.kind!==`ok`)return a;if(!a.value)return I;let o=[RI,zI].filter(e=>!r.existsSync(l.join(i.installPath,e)));return o.length===0?F(i.installPath):L(`memento at ${i.installPath} has no ${o.join(` or `)} — upgrade the plugin`)}function UI(e,t=process.env){let n=new Set([`CLAUDE_PROJECT_DIR`,`CLAUDE_CODE_SESSION_ID`,...e.env===void 0?[]:tt]);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 WI(e){return e.stderr.trim()||e.error||`${e.reason}${e.exitCode===null?``:` (exit ${e.exitCode})`}`}function GI(e){let t;try{t=JSON.parse(e)}catch{return L(`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`)?F({ceiling:i,session:r}):L(`memento read: unexpected answer: ${e.trim()}`)}async function KI(e,t){let n=await Me({bin:`python3`,args:[`-c`,`
|
|
153
153
|
import json, math, sys
|
|
154
154
|
sys.path.insert(0, sys.argv[1])
|
|
155
155
|
from ceiling_config import CONFIG_NAME, anchored, ceiling_in, in_force, session_directory
|
|
@@ -158,18 +158,18 @@ ceiling = in_force(directory, anchored(sys.argv[3]))
|
|
|
158
158
|
layer = ceiling_in(directory / CONFIG_NAME)
|
|
159
159
|
print(json.dumps({"ceiling": "off" if ceiling == math.inf else ceiling,
|
|
160
160
|
"session": layer.text if layer else None}))
|
|
161
|
-
`,l.join(e,`lib`),t.sessionId,t.cwd],env:
|
|
162
|
-
`).at(-1).trim();function
|
|
163
|
-
`),c=Gn([{verb:wn,args:[s]}]),l=t.kind===`running`?Vm(`[${i.busy}]`,c):Vm(`[${i.act}]`,Gn([{verb:In,args:[n.sessionId]}]));return[{severity:Bm,message:s,lines:[[Vm(a,c),l,Vm(`[dismiss]`,Gn([{verb:yn,args:[n.sessionId,tR,r]}])),Vm(`[disable]`,Gn([{verb:P,args:[n.sessionId,nR,`false`]},{verb:yn,args:[n.sessionId,rR,`false`]}]))],...o.map(e=>[Vm(e,c)])]}]}function uR(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 dR(e){switch(e.kind){case`current`:return[`info`,`build: current ${aR(e.stamp)}`];case`stale`:return[`info`,`build: stale — source ${aR(e.source)}, running ${aR(e.running)}`];case`not-source-checkout`:return[`info`,`build: not a source checkout`];case`unchecked`:return[`warn`,`build: unchecked: ${e.reason}`]}}function fR(e){switch(e.kind){case`current`:return[`info`,`release: current ${yi(e.installed)}`];case`stale`:return[`info`,`release: stale — latest ${yi(e.latest)}, running ${yi(e.installed)}`];case`ahead`:return[`info`,`release: ahead — running ${yi(e.installed)}, latest ${yi(e.latest)}`];case`unchecked`:return[`warn`,`release: unchecked: ${e.reason}`]}}function pR(e){let t=null;return([n,r])=>{r!==t&&(t=r,e(n,r))}}const mR=e=>e.split(/\r?\n/).map(e=>e.trim()).filter(e=>e!==``).at(-1);function hR(e){let t=e.exitCode===null?``:` (exit ${e.exitCode})`,n=mR(e.stderr)??e.error??mR(e.stdout)??`no output`;return`${e.reason}${t}: ${n}`}function gR(){let e=[pj(nR,[`false`]),JL(rR,[`false`]),JL(tR,[])];return()=>e.forEach(e=>e())}function _R(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=sR,d=null,f=pR(s),p=pR(s),m=()=>uR(c,l);function h(){let e=m(),t=e===null?null:iR(e);(d===null?null:d.identity)!==t&&(d?.dispose(),d=t===null?null:{identity:t,dispose:JL(tR,[t])})}function g(){c=rh(t,th),f(dR(c)),h()}async function _(){l=Ci(Et,await Si(xi,a,i)),p(fR(l)),h()}return{arm(){gR(),g(),setInterval(g,n).unref(),c.kind===`not-source-checkout`&&(_(),setInterval(()=>void _(),r).unref())},notice:e=>lR(m(),u,e),act(){let e=m();if(e===null)throw new K(`apply-update: nothing newer is known to apply`);let t=oR(e);if(u.kind===`running`)throw new K(`apply-update: already ${t.busy}`);u=cR,s(`info`,`apply-update: ${t.act} — ${t.command.bin} ${t.command.args?.join(` `)??``}`),Me({...t.command,category:`update.apply`,timeoutMs:6e5}).then(n=>{if(n.ok){u=sR,s(`info`,`apply-update: ${t.act} succeeded`),g(),o();return}let r=hR(n);u={kind:`failed`,identity:iR(e),reason:r},s(`error`,`apply-update: ${t.act} failed: ${r}`)})}}}var vR=class{static CACHE_DIR=ze();static USAGE_CACHE_DIR=l.join(this.CACHE_DIR,`usage`);static LOCKS_DIR=l.join(this.CACHE_DIR,`locks`);static isLocked(e){let t=l.join(this.LOCKS_DIR,e);if(!r.existsSync(t))return!1;try{let n=r.readFileSync(t,`utf-8`),i=parseInt(n.trim(),10);if(isNaN(i))return D(`Invalid PID in lock file ${e}, removing stale lock`),r.unlinkSync(t),!1;try{return process.kill(i,0),!0}catch(n){return n.code===`ESRCH`?(D(`Removing stale lock file ${e} for dead process ${i}`),r.unlinkSync(t),!1):(D(`Error checking process ${i} for lock ${e}:`,n),!0)}}catch(t){return D(`Error reading lock file ${e}:`,t),!0}}static async acquireLock(e,t=5e3){await this.ensureCacheDirectories();let n=l.join(this.LOCKS_DIR,e),i=Date.now(),a=String(process.pid);for(;Date.now()-i<t;)try{return await r.promises.writeFile(n,a,{flag:`wx`}),D(`Lock acquired for ${e}`),!0}catch(e){if(e.code===`EEXIST`)await de(50);else throw e}return D(`Failed to acquire lock for ${e} within ${t}ms`),!1}static async releaseLock(e){let t=l.join(this.LOCKS_DIR,e);try{await r.promises.unlink(t),D(`Lock released for ${e}`)}catch(t){t.code!==`ENOENT`&&D(`Error releasing lock for ${e}:`,t)}}static async ensureCacheDirectories(){try{await Promise.all([r.promises.mkdir(this.CACHE_DIR,{recursive:!0}),r.promises.mkdir(this.USAGE_CACHE_DIR,{recursive:!0}),r.promises.mkdir(this.LOCKS_DIR,{recursive:!0})])}catch(e){D(`Failed to create cache directories:`,e)}}static createProjectHash(e){return ae(`md5`).update(e).digest(`hex`).substring(0,8)}static async getUsageCache(e,t){await this.ensureCacheDirectories();let n=l.join(this.USAGE_CACHE_DIR,`${e}.json`),i=`${e}.usage.lock`;for(let a=0;a<3;a++){if(this.isLocked(i)){D(`Cache for ${e} is locked, waiting...`),await de(75);continue}try{let i=await r.promises.readFile(n,`utf-8`),a=JSON.parse(i);return!t||a.timestamp>=t?(D(`[CACHE-HIT] ${e} disk cache: found`),this.deserializeDates(a.data)):(D(`${e} cache outdated: cache=${a.timestamp}, latest=${t}`),null)}catch(t){if(t.code===`ENOENT`)return D(`No shared ${e} usage cache found`),null;D(`Attempt ${a+1} failed to read ${e} cache: ${t.message}. Retrying...`),await de(75)}}return D(`Failed to read ${e} cache after 3 attempts.`),null}static deserializeDates(e){return Array.isArray(e)?e.map(e=>({...e,timestamp:new Date(e.timestamp)})):e}static async setUsageCache(e,t,n){let i=`${e}.usage.lock`;if(!await this.acquireLock(i)){D(`Could not acquire lock to set usage cache for ${e}`);return}try{await this.ensureCacheDirectories();let i=l.join(this.USAGE_CACHE_DIR,`${e}.json`),a=JSON.stringify({data:t,timestamp:n||Date.now()});await r.promises.writeFile(i,a,`utf-8`),D(`[CACHE-SET] ${e} disk cache stored`)}catch(t){D(`Failed to save ${e} usage cache:`,t)}finally{await this.releaseLock(i)}}};const yR={"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 bR=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 vR.getUsageCache(`pricing`,e)}static async saveDiskCache(e){await vR.setUsageCache(`pricing`,e)}static async fetchPricingData(){return new Promise(e=>{let t=new ee(this.GITHUB_PRICING_URL),n=ue({hostname:t.hostname,path:t.pathname,headers:{"User-Agent":`cc-candybar`,"Cache-Control":`no-cache`},timeout:5e3},t=>{if(t.statusCode!==200){D(`HTTP ${t.statusCode}: ${t.statusMessage}`),e(null);return}let r=``,i=0;t.on(`data`,t=>{if(i+=t.length,i>1048576){D(`Response too large`),n.destroy(),e(null);return}r+=t}),t.on(`end`,()=>{try{let t=JSON.parse(r),n=t._meta,i={};for(let[e,n]of Object.entries(t))e!==`_meta`&&(i[e]=n);this.validatePricingData(i)?(D(`Fetched fresh pricing from GitHub for ${Object.keys(i).length} models`),D(`Pricing last updated: ${n?.updated||`unknown`}`),e(i)):(D(`Invalid pricing data structure`),e(null))}catch(t){D(`Failed to parse JSON:`,t),e(null)}}),t.on(`error`,t=>{D(`Response error:`,t),e(null)})});n.on(`error`,t=>{D(`Request error:`,t),e(null)}),n.on(`timeout`,()=>{D(`Request timeout`),n.destroy(),e(null)}),n.end()})}static async getCurrentPricing(){if(this.executionCache!==null)return D(`[CACHE-HIT] Pricing execution cache: ${Object.keys(this.executionCache).length} models`),this.executionCache;let e=await this.loadDiskCache();if(e)return D(`[CACHE-HIT] Pricing disk cache: ${Object.keys(e).length} models`),this.executionCache=e,D(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(e).length} models`),e;let t=await this.fetchPricingData();return t?(await this.saveDiskCache(t),D(`[CACHE-SET] Pricing disk cache stored: ${Object.keys(t).length} models`),this.executionCache=t,D(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(t).length} models`),t):(D(`[CACHE-FALLBACK] Using offline pricing data: ${Object.keys(yR).length} models`),this.executionCache=yR,D(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(yR).length} models`),yR)}static validatePricingData(e){if(!e||typeof e!=`object`)return!1;for(let[,t]of Object.entries(e)){if(!t||typeof t!=`object`)return!1;let e=t;if(typeof e.input!=`number`||typeof e.output!=`number`||typeof e.cache_read!=`number`)return!1}return!0}static async getModelPricing(e){if(this.modelPricingCache.has(e))return D(`[CACHE-HIT] Model pricing cache: ${e}`),this.modelPricingCache.get(e);let t=await this.getCurrentPricing(),n;return n=t[e]?t[e]:this.fuzzyMatchModel(e,t),this.modelPricingCache.set(e,n),D(`[CACHE-SET] Model pricing cache: ${e}`),n}static fuzzyMatchModel(e,t){let n=e.toLowerCase();for(let[e,r]of Object.entries(t))if(e.toLowerCase()===n)return r;for(let{pattern:e,fallback:r}of[{pattern:[`opus-4-6`,`claude-opus-4-6`],fallback:`claude-opus-4-6-20260205`},{pattern:[`opus-4-5`,`claude-opus-4-5`],fallback:`claude-opus-4-5-20251101`},{pattern:[`opus-4-1`,`claude-opus-4-1`],fallback:`claude-opus-4-1-20250805`},{pattern:[`opus-4`,`claude-opus-4`],fallback:`claude-opus-4-20250514`},{pattern:[`sonnet-4-6`,`sonnet-4.6`,`claude-sonnet-4-6`],fallback:`claude-sonnet-4-6`},{pattern:[`sonnet-4.5`,`4-5-sonnet`,`sonnet-4-5`],fallback:`claude-sonnet-4-5-20250929`},{pattern:[`sonnet-4`,`claude-sonnet-4`],fallback:`claude-sonnet-4-20250514`},{pattern:[`haiku-4.5`,`4-5-haiku`,`haiku-4-5`],fallback:`claude-haiku-4-5-20251001`},{pattern:[`haiku`],fallback:`claude-haiku-4-5-20251001`},{pattern:[`opus`],fallback:`claude-opus-4-20250514`},{pattern:[`sonnet`],fallback:`claude-sonnet-4-5-20250929`}])if(e.some(e=>n.includes(e))&&t[r])return t[r];return t[`claude-sonnet-4-5-20250929`]||{name:`${e} (Unknown Model)`,input:3,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3,output:15}}static async calculateCostForEntry(e){let t=e.message?.usage;if(!t)return 0;let n=this.extractModelId(e),r=await this.getModelPricing(n),i=t.input_tokens||0,a=t.output_tokens||0,o=t.cache_creation_input_tokens||0,s=t.cache_read_input_tokens||0,c=i/1e6*r.input,l=a/1e6*r.output,u=s/1e6*r.cache_read,d=o/1e6*r.cache_write_5m;return c+l+d+u}static extractModelId(e){if(e.model&&typeof e.model==`string`)return e.model;let t=e.message;if(t?.model){let e=t.model;if(typeof e==`string`)return e;let n=e;return(typeof n?.id==`string`?n.id:null)||`claude-sonnet-4-5-20250929`}return e.model_id&&typeof e.model_id==`string`?e.model_id:`claude-sonnet-4-5-20250929`}};const xR=/<command-name>\s*([^<\s][^<]*?)\s*<\/command-name>/;function SR(e){if(typeof e==`string`)return xR.exec(e)?.[1]}function CR(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 wR(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 TR(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=CR(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`?SR(wR(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 ER(e){if(e!==void 0)return[e];let t=g();return[p(t,`.config`,`claude`),p(t,`.claude`)].filter(e=>a(e))}async function DR(e){let t=[];for(let n of e){let e=p(n,`projects`);if(a(e))try{let n=await _I(e,{withFileTypes:!0});for(let r of n)if(r.isDirectory()){let n=p(e,r.name);t.push(n)}}catch(t){D(`Failed to read projects directory ${e}:`,t)}}return t}async function OR(e,t,n){let r=[],i=p(t,e,`subagents`);try{let t=(await _I(i)).filter(e=>e.startsWith(`agent-`)&&e.endsWith(`.jsonl`));for(let a of t){let t=p(i,a);if(n?.has(t)){r.push(t);continue}try{let n=(await vI(t,`utf-8`)).split(`
|
|
164
|
-
`)[0];n&&JSON.parse(n).sessionId===e&&r.push(t)}catch{D(`Failed to check agent file ${t}`)}}}catch(e){D(`Failed to read subagents directory ${i}:`,e)}return r}function
|
|
165
|
-
`))if(n.trim())try{let e=PR(JSON.parse(n));e&&t.push(e)}catch(e){D(`Failed to parse JSONL line: ${e}`);continue}return t}async function IR(e){return FR(await vI(e,`utf-8`))}async function LR(e,t){let n=await bI(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 F(c<0?{entries:[],cursor:{offset:i,stamp:a,ino:o},reset:s}:{entries:FR(r.subarray(0,c+1).toString(`utf-8`)),cursor:{offset:i+c+1,stamp:a,ino:o},reset:s})}async function RR(e){return new Promise((t,n)=>{let r=[],a=i(e,{encoding:`utf8`}),o=fe({input:a,crlfDelay:1/0});o.on(`line`,e=>{let t=e.trim();if(t)try{let e=PR(JSON.parse(t));e&&r.push(e)}catch(e){D(`Failed to parse JSONL line: ${e}`)}}),o.on(`close`,()=>{t(r)}),o.on(`error`,t=>{D(`Streaming parser error for ${e}:`,t),n(t)}),a.on(`error`,t=>{D(`File stream error for ${e}:`,t),n(t)})})}var zR=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 BR(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 VR=new Map,HR={cost:0,input:0,output:0,cacheCreation:0,cacheRead:0},UR={cost:null,calculatedCost:null,officialCost:null,tokens:null,tokenBreakdown:null};function WR(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function GR(){let e=new Date;return e.setHours(0,0,0,0),e.setDate(e.getDate()-1),e.getTime()}function KR(){return{input:0,output:0,cacheCreation:0,cacheRead:0}}async function qR(e,t,n,r){let i=WR(new Date(GR())),a=e&&!t?e:void 0,o=a?.entries??0,s=a?.cost??0,c=a?{...a.breakdown}:KR(),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 bR.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=WR(new Date(e.timestamp));if(r<i)continue;let a=l.get(r)??{...HR};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 JR(e){let t=0,n=0,r=KR(),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)??{...HR};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:UR,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 YR(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 XR=class{sessions=new Map;flight=new zR;seeded=new Map;seededDay=``;rescanIntervalMs;speedFlight=new zR;staleAgeMs;log;renderTally={hits:0,misses:0};sweeps=0;scans={seed:0,rescan:0};sweepTimer=null;constructor(e={}){this.log=e.logger??Ft,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:UR,i=t?.cost?.total_cost_usd??null;return F({session:{...r,cost:i??r.cost,officialCost:i}})}async getTodayInfo(e,t,n){let r=WR(Aw(n)),i=ER(t);try{await this.ensureSeeded(r,i,n*1e3)}catch(e){return L(`usage seed: ${e instanceof Error?e.message:String(e)}`)}let a=await this.ingest(e?.session_id??``,e?.transcript_path,this.renderTally);if(a.kind===`failed`)return a;let o=i.map(e=>p(e,`projects`)+m),s={...HR},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??VR:VR;c||=a.has(r);let l=a.get(r)??HR;s.cost+=l.cost,s.input+=l.input,s.output+=l.output,s.cacheCreation+=l.cacheCreation,s.cacheRead+=l.cacheRead}return c?F({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}):I}async observeSpeed(e,t,n){if(!e)return I;let r=pI(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=BR(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(),F({...s!==void 0&&{prev:s},cur:a,samples:[...o]})})}async ingest(e,t,n,r){if(!e)return I;let i=r??pI(t),a=this.see(e)?.record;if(a&&i!==``&&a.transcriptStamp===i)return n.hits++,F(a);if(!t)return a?F(a):I;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 L(`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),F(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 OR(e,d(t),n===void 0?void 0:new Set(n.files.keys())),i=new Map,a=``;for(let e of[t,...r]){let r=n?.files.get(e),o=await LR(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 qR(r,l,s,c)),e===t&&(a=c.stamp)}return F({files:i,...JR(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=GR(),i=await DR(e),a=[];for(let e of i){let t;try{t=await _I(e)}catch{continue}for(let n of t){if(!n.endsWith(`.jsonl`))continue;let t=p(e,n),i;try{i=await yI(t)}catch{continue}i.mtimeMs<r||a.push({sessionId:n.slice(0,-6),path:t,stamp:mI(i)})}}let o={hits:0,misses:0};await YR(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()}},ZR=class{thresholds={LOW:50,MEDIUM:80};getContextUsageThresholds(){return this.thresholds}ratioPercentages(e,t){let n=Math.min(100,Math.max(0,Math.round(e/t*100)));return{percentage:n,contextLeftPercentage:Math.max(0,100-n)}}calculateContextFromHookData(e){let t=e.context_window;if(!t?.current_usage)return D(`No current_usage in hook data, falling back to transcript parsing`),null;let n=t.current_usage,r=t.context_window_size,i=(n.input_tokens||0)+(n.cache_creation_input_tokens||0)+(n.cache_read_input_tokens||0);D(`Native current_usage: input=${n.input_tokens}, cache_create=${n.cache_creation_input_tokens}, cache_read=${n.cache_read_input_tokens}, total=${i} (limit: ${r})`);let a=this.ratioPercentages(i,r);return{totalTokens:i,maxTokens:r,percentage:t.used_percentage==null?a.percentage:Math.round(t.used_percentage),contextLeftPercentage:t.remaining_percentage==null?a.contextLeftPercentage:Math.round(t.remaining_percentage)}}async calculateContextTokensFromTranscript(e,t){try{D(`Calculating context tokens from transcript: ${e}`);let n=await NR(e);if(n.length===0)return D(`No entries in transcript`),I;let r=null;for(let e=n.length-1;e>=0;e--){let t=n[e];if(t&&t.message?.usage?.input_tokens&&t.isSidechain!==!0){r=t,D(`Context segment: Found most recent entry at ${t.timestamp.toISOString()}, stopping search`);break}}if(r?.message?.usage){let e=r.message.usage,n=(e.input_tokens||0)+(e.cache_read_input_tokens||0)+(e.cache_creation_input_tokens||0);return D(`Most recent main chain context: ${n} tokens (limit: ${t})`),F({totalTokens:n,maxTokens:t,...this.ratioPercentages(n,t)})}return D(`No main chain entries with usage data found`),I}catch(e){return L(`context transcript: ${e instanceof Error?e.message:String(e)}`)}}async getContextInfo(e){let t=this.calculateContextFromHookData(e);if(t)return F(t);let n=e.context_window?.context_window_size??2e5;return this.calculateContextTokensFromTranscript(e.transcript_path,n)}},QR=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=pI(t);if(n&&r!==``&&n.cursor.stamp===r)return this.touch(e,n),{kind:`ok`,value:n.value};let i=await LR(t,n?.cursor);if(i.kind===`failed`)return i;if(i.kind===`absent`)return{kind:`ok`,value:n?.value??this.empty};let{entries:a,cursor:o,reset:s}=i.value,c=s||n===void 0?this.empty:n.value;for(let e of a)c=this.step(c,e);for(this.touch(e,{cursor:o,value:c});this.states.size>this.maxSessions;){let e=this.states.keys().next().value;if(e===void 0)break;this.states.delete(e)}return{kind:`ok`,value:c}}touch(e,t){this.states.delete(e),this.states.set(e,t)}};const $R={messageCount:0,nonPrompts:0,recent:[]},ez=new Set([`turn`,`interrupt`,`claude-code`]);function tz(e,t){if(t.isSidechain)return e;let n=[...e.recent,t];return{messageCount:e.messageCount+ +(t.userEntry===`prompt`),nonPrompts:e.nonPrompts+ +!!ez.has(t.userEntry),recent:n.length>20?n.slice(-20):n}}function nz(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 rz=class{fold=new QR($R,tz);async getMetricsInfo(e,t){if(D(`Getting metrics from hook data for session: ${e}`),!t.cost)return I;let n=await this.fold.read(e,t.transcript_path);return n.kind===`failed`?L(`metrics (${e}): ${n.reason}`):F({responseTime:t.cost.total_api_duration_ms/1e3,lastResponseTime:nz(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 iz={command:null,todos:[],pending:[],done:[]};function az(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 oz(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 sz(e,t){if(t.isSidechain)return e;let n=oz(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=az(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 cz(e){return{command:e.command,todos:e.todos,running:e.pending.reduce((e,t)=>az(e,t.name),[]),done:e.done}}var lz=class{fold=new QR(iz,sz);async getActivityInfo(e,t){let n=await this.fold.read(e,t.transcript_path);return n.kind===`failed`?L(`activity (${e}): ${n.reason}`):F(cz(n.value))}};function uz(e,t,n,r){return{bin:`tmux`,args:[`-S`,e.socket,...n],timeoutMs:2e3,category:t,stdinInput:r}}function dz(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 fz(e,t,n,r){return dz(Ne(uz(e,t,n,r)),n)}async function pz(e,t,n){return dz(await Me(uz(e,t,n)),n)}const mz=e=>`${e.socket}\n${e.pane}`;var hz=class{names=new Map;asking=new zR;constructor(e=Date.now){this.now=e}getSessionName(e){let t=mz(e),n=this.names.get(t);if(n&&this.now()-n.at<3e4)return Promise.resolve(n.outcome);let r=this.asking.run(t,()=>this.ask(t,e));return n?Promise.resolve(n.outcome):r}async ask(e,t){D(`Getting tmux session name for pane ${t.pane} on ${t.socket}`);let n=await pz(t,`tmux`,[`display-message`,`-p`,`-t`,t.pane,`#S`]),r=n.kind===`ok`?n.stdout.trim():``,i=n.kind===`ok`?r?F(r):I:L(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 gz=e=>JSON.stringify([e.sessionId,e.projectDir,e.cwd,e.claudeConfigDir,e.env===void 0?null:tt.map(t=>e.env?.[t]??null)]);var _z=class{readings=new Map;inFlight=new Map;constructor(e,t=Date.now){this.edge=e,this.now=t}getCeiling(e){let t=gz(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=gz(e);try{this.edge.move(n.value,e,t)}finally{this.readings.delete(r),this.inFlight.delete(r),this.fetch(r,e)}}};function vz(e){return{gitProvider:new ww({watchers:e.watchers,logger:e.logger}),usageStore:new XR({logger:e.logger}),contextProvider:new ZR,metricsProvider:new rz,activityProvider:new lz,tmuxService:new hz,mementoProvider:new _z(RI()),autoCompact:PO,log:e.logger}}function yz(e,t){return e===void 0?!0:e.evaluate(t).map(e=>e.plain).join(``)!==`false`}const bz={kind:`hidden`},xz={kind:`shown`};function Sz(e,t){try{return yz(e,t)?xz:bz}catch(e){return{kind:`failed`,message:e instanceof Error?e.message:String(e)}}}function Cz(e,t){let n=G.fromFragments(e);return n.end=``,n.overflow=`ignore`,t!==void 0&&!t.isNull&&(n.style=t),n}function wz(e,t,n){e.cellLength>t?e.truncate(t,{mode:n.truncate,marker:`…`}):e.cellLength<t&&e.align(n.justify,t)}function Tz({lead:e,text:t,trail:n}){return[...e===void 0?[]:[e],t,...n===void 0?[]:[n]]}function Ez({text:e,placement:t,lead:n,trail:r}){return{text:Dz(e),placement:t,...n!==void 0&&{lead:Dz(n)},...r!==void 0&&{trail:Dz(r)}}}function Dz(e){let t=e.blankCopy(e.plain);t.style=dm(e.style).clearMetaAndLinks();for(let{start:n,end:r,style:i}of e.spans)t.stylize(dm(i).clearMetaAndLinks(),n,r);return t}function Oz(e){let t=Tz(e);if(t.length===1)return e.text;let n=Cz(t);return n.style=e.text.style,n}function kz(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=Cz(e,a).pad(o),d=new G(` `.repeat(o)),f={placement:s,...c.length>0&&{lead:Cz([d,...c],a)},...l.length>0&&{trail:Cz([...l,d],a)}};if(n===`auto`)return[{text:u,...f}];let p={justify:r,truncate:i};return n===`fill`?[{text:u,fill:p,...f}]:(wz(u,n,p),[{text:u,...f}])}function Az(e,t){let n=()=>e.map(e=>({owner:Oz(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=Im(e.map(Oz),t).split(`
|
|
166
|
-
`);if(i.length>1)return n();let a=Math.max(0,t.width-Cm(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];wz(c,c.cellLength+a,n)}),n()}function jz(e,t){let n=[],r=[],i=()=>{if(!r.length)return;let e=Mz(r,t);e.plain.length>0&&n.push(e),r=[]};for(let a of e){let e={frag:a,style:dm(a.style)};if(e.style.link){i();let r=Mz([e],t);r.plain.length>0&&n.push(r)}else r.push(e)}return i(),n}function Mz(e,t){let n=t!==void 0&&!t.isNull?t:void 0,r=e.map(e=>Nz(e.frag,n?n.add(e.style):e.style)),i=G.fromFragments(r);return i.end=``,i.overflow=`ignore`,r.length===1?i.style=r[0].style:n!==void 0&&(i.style=n),i}function Nz(e,t){let n=e.copy();return n.style=t,n}function Pz(e,t){if(e.look===void 0)throw Error(`${t} read the render's look before any render resolved one`);return e.look}function Fz(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,Iz(e,t,o,n,r,i));return i}function Iz(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=fg(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=fg(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=fg(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:zz(e,n.copy,t)};if(`open`in n)return{kind:`open`,target:zz(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:gN(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:zz(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 Lz(e){return e.kind===`do`?Lz(e.head):e}function Rz(e){switch(Lz(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 zz(e,t,n){try{return e(t)}catch(e){throw Error(`Template parse error in actions.${n}: ${e.message}`,{cause:e})}}function Bz(e,t){return e.has(t)?Wg(e.read(t)):``}function Vz(e,t){return e.evaluate(t).map(e=>e.plain).join(``)}function Hz(e,t,n,r){let i=new G(e,{style:H.combine([r,new H({link:t,bold:n})])});return i.overflow=`ignore`,i.end=``,i}function Uz(e,t,n=!1){let r=new H({link:t,bold:n?!0:void 0}),i=new G(e.plain,{style:H.combine([dm(e.style),r])});for(let t of e.spans)i.stylize(H.combine([dm(t.style),r]),t.start,t.end);return i.overflow=`ignore`,i.end=``,i}function Wz(e,t){return Math.max(e.members.indexOf(Bz(t,e.stateVar)),0)}function Gz(e,t,n,r,i){switch(e.kind){case`set-literal`:{let t=Bz(r,e.stateVar);return{effects:[{verb:yn,args:[i,e.key,e.value]}],active:t===e.value}}case`set-option`:{let a=n??t,o=Bz(r,e.stateVar);return{effects:[{verb:yn,args:[i,e.key,a]}],active:o===a}}case`set-int`:{let a=n??t,o=Bz(r,e.stateVar);return{effects:[{verb:yn,args:[i,e.key,a]}],active:o===a}}case`set-cycle`:{let t=e.members[(Wz(e,r)+1)%e.members.length];return{effects:[{verb:yn,args:[i,e.key,t]}],active:!1}}case`set-bounded`:return{effects:[{verb:N,args:[i,e.key,String(e.by)]}],active:!1};case`copy`:return{effects:[{verb:bn,args:[Vz(e.text,FC(r))]}],active:!1};case`open`:return{effects:[{verb:xn,args:[Vz(e.target,FC(r))]}],active:!1};case`persist-literal`:{let t=Bz(r,e.stateVar);return{effects:[{verb:P,args:[i,e.key,e.value]}],active:t===e.value}}case`persist-option`:{let a=n??t,o=Bz(r,e.stateVar);return{effects:[{verb:P,args:[i,e.key,a]}],active:o===a}}case`persist-cycle`:{let t=e.members[(Wz(e,r)+1)%e.members.length];return{effects:[{verb:P,args:[i,e.key,t]}],active:!1}}case`persist-bounded`:return{effects:[{verb:Tn,args:[i,e.key,String(e.by)]}],active:!1};case`reset`:return{effects:[{verb:An,args:[i,e.key]}],active:!1};case`undo`:return{effects:[{verb:Mn,args:[i]}],active:!1};case`redo`:return{effects:[{verb:Nn,args:[i]}],active:!1};case`back`:return{effects:[{verb:Pn,args:[i]}],active:!1};case`rewind`:return{effects:[{verb:Fn,args:[i]}],active:!1};case`save`:return{effects:[{verb:En,args:[i]}],active:!1};case`preset-save`:return{effects:[{verb:Dn,args:[i]}],active:!1};case`theme-default-save`:return{effects:[{verb:On,args:[i]}],active:!1};case`preset-delete`:return{effects:[{verb:kn,args:[i,Vz(e.name,FC(r))]}],active:!1};case`doctor-run`:return{effects:[{verb:Ln,args:[i]}],active:!1};case`doctor-fix`:return{effects:[{verb:Rn,args:[i,e.check]}],active:!1};case`doctor-mark`:return{effects:[{verb:zn,args:[i,e.check,e.mark]}],active:!1};case`ceiling`:return{effects:[{verb:Vn,args:[i,...e.args]}],active:!1};case`slash`:return{effects:[{verb:Hn,args:[i,e.line]}],active:!1};case`layout-op`:return{effects:[{verb:jn,args:[i,e.key,$A(e.op)]}],active:!1};case`do`:{let a=Gz(e.head,t,n,r,i);return{effects:[...a.effects,...e.rest.flatMap(e=>Gz(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:jn,args:[i,e.key,$A(r)]}],active:!1}}}}function Kz(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:er(`action "${e}"`,n,t.members.length,Wz(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 qz(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}=Kz(e,Lz(r),t,i),s=Bz(i,`session.id`),{effects:c,active:l}=Gz(r,a.plain,o,i,s);return Uz(a,Gn(c),l)}function Jz(e){return{action:{fn:(t,...n)=>qz(t,n,e),argTypes:[`string`,`liftable`],arity:{kind:`variadic`},returnType:`T`}}}function Yz(e,t){return Hz(`✕`,Gn([{verb:yn,args:[Bz(e,`session.id`),t,Zn]}]),!1)}function Xz(e,t,n){return new H({bgcolor:V.fromRgba(t),color:V.fromRgba(Bf(e,t,n))})}function Zz({tint:e,text:t}){return new H({bgcolor:V.fromRgba(e),color:V.fromRgba(t)})}function Qz(e,t,n){return new H({color:V.fromRgba(ac(Af(e,`warning`),t,zf,n))})}function $z(e,t,n){return H.combine([Xz(e,t,n),Qz(e,t,n)])}function eB(e,t,n){return Xz(e.palette,sp(e.palette,e.disclosure,[t],n),n)}function tB(e){let t=V.fromRgba(Af(e,`background`)),n=G.fromFragments(nf.map(n=>new G(`▀`,{style:new H({color:V.fromRgba(Af(e,n)),bgcolor:t})})));return n.overflow=`ignore`,n.end=``,n}const nB=(e,t)=>{let n=typeof e==`string`?new G(e,{style:t}):e;return n.overflow=`ignore`,n.end=``,n},rB=e=>new H({bold:e});function iB(e,t,n,r,i,a){if(r===void 0)return(n,r,a,o)=>nB(a,H.combine([eB(e,{...n,distribution:t},i),rB(o)]));let o=Xz(e.palette,a,i);return(e,t,i,a)=>aB(i,H.combine([o,rB(a)]),r(t,n))}const aB=(e,t,n)=>nB(G.fromFragments([nB(e,t),nB(` `,t),tB(n)]));function oB(e,t){return t===void 0?(e,t,n)=>nB(n):(n,r,i)=>aB(i,void 0,t(r,e))}function sB(e,t,n,r,i){let a=Xz(e.palette,i,r);return(e,r,i,o)=>nB(G.fromFragments([nB(o?`[`:` `,a),tB(n(r,t)),nB(o?`]`:` `,a)]))}function cB(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=>lB(e.indices,8).map(t=>[{label:e.label,indices:t}])):[r]}function lB(e,t){return Array.from({length:Math.ceil(e.length/t)},(n,r)=>e.slice(r*t,(r+1)*t))}function uB(e,t){return new G(e).truncate(t,{marker:`…`}).plain}function dB(e){return{current:null,drawnAt:e}}function fB(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 pB(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 mB(e){return new G(e).cellLength}function hB(e){return Math.max(1,e.width-e.chromeCols-2*e.padding)}function gB(e){return Math.max(1,hB(e)-(mB(`✕`)+2*e.padding+e.seamCols))}function _B(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 vB(e,t,n){let r=mB(`←`)+1+mB(`→`)+1,i=_B(e,t,n);return(i.length>1?_B(e,t,n+r):i).map(e=>[{label:``,indices:e}])}function yB(e,t){let n=[];for(let t of e)n.length>0&&n.push(new G(` `)),n.push(t);let r=G.fromFragments(n);return r.overflow=t?`ignore`:void 0,r.end=``,r}function bB(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 xB(e,t,n){let r=e.compiled.get(t),i=r&&Lz(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 SB(e,t,n,r,i,a,o,s,c=[]){let l=a.compiled.get(e),u=a.store,d=Bz(u,`session.id`),f=`stateVar`in t?Bz(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`?gB(a):hB(a):1/0,h=(r.kind===`led`?0:mB(`✕`)+1)+c.reduce((e,t)=>e+mB(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?vB(_.map(e=>e.cellLength),m,h):cB(g.entries,g.groups,i),y=parseInt(Bz(u,n.stateVar),10),b=e=>Math.max(0,v.findIndex(t=>t.some(t=>t.indices.includes(e)))),x=b(f===void 0?-1:t.options.indexOf(f)),S=Number.isInteger(y)?y<0?x:Math.min(y,v.length-1):0,C=v[S]??[],ee=e=>Gn([{verb:yn,args:[d,n.key,String(e)]}]),te=r.kind===`led`?[]:[{verb:yn,args:[d,...r.writes.flatMap(([e,t])=>[e,t])]}],ne=r.kind===`own`&&r.onPick?te:[],re=e=>Gn([...Gz(l,e,e,u,d).effects,...ne]),ie=(e,n)=>Uz(e,re(t.options[n])),ae=r.kind===`led`?[]:[Hz(`✕`,Gn(te),!1,s)];ae.push(...c.map(({glyph:e,option:r})=>Hz(e,Gn([...Gz(l,r,r,u,d).effects,{verb:yn,args:[d,n.key,String(b(t.options.indexOf(r)))]}]),!1))),S>0&&ae.push(Hz(`←`,ee(S-1),!1));let w=S<v.length-1?[Hz(`→`,ee(S+1),!1)]:[];if(g===void 0){let e=C.flatMap(e=>e.indices);return[yB([...ae,...e.map(e=>ie(_[e],e)),...w],i)]}let T=new H({bold:!0}),oe=v.length>1?` ${S+1}/${v.length}`:``,E=C.length===1?[new G(`${C[0].label}${oe}`,{style:T})]:[],se=[yB([...ae,...E,...w],i)];for(let e of C){C.length>1&&se.push(yB([new G(e.label,{style:T})],i));let n=Math.max(...e.indices.map(e=>mB(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:Jd(a),s=` `.repeat(n-mB(e)+2),c=o===void 0?e:`${e}${s}${o}`;se.push(yB([ie(p(r,uB(c,m)),r)],i))}}return se}function CB(e,t){return{picker:{fn:(n,r,i,a,o,...s)=>{kC(`picker "${n}"`,[`closeOnPick`,`paged`,`inBody`],s);let c=bB(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=xB(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=pB(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]=SB(n,l,{key:c.key,stateVar:c.stateVar},o===!0?{kind:`led`}:{kind:`own`,writes:[[c.key,`-1`]],onPick:i===!0},a===!0,e,iB(u,vf(void 0),Pz(e,`{{ picker }}`),l.paletteOf,t.drawnAt(),u.bg),Qz(u.palette,u.bg,t.drawnAt()));return d},argTypes:[`string`,`string`,`bool`],arity:{kind:`variadic`},returnType:`T`}}}function wB(e,t){let n=e.length,r=Math.max(e.indexOf(t),0);return e=>((r+e)%n+n)%n}function TB(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 EB(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=Bz(o,`session.id`),{options:l}=t,u=l.length;if(u===0)return yB([],!0);let d=Bz(o,t.stateVar),f=wB(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=Gn(Gz(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=Uz(g(e),h(e));return _.set(e,n),n},y=a===void 0?v(0):Uz(oB(Pz(n,`{{ carousel }}`),t.paletteOf)({index:f(0),count:u},p(0),p(0),!1),Gn(Gz(n.compiled.get(a),p(0),void 0,o,c).effects)),b=TB(e=>v(e).cellLength,u,mB(`◀`)+1+y.cellLength+1+mB(`▶`),gB(n),i),x=e=>Array.from({length:b},(t,n)=>v(e*(n+1)));return yB([...x(-1).reverse(),Hz(`◀`,h(-1),!1),y,Hz(`▶`,h(1),!1),...x(1)],!0)}function DB(e,t){return{carousel:{fn:(n,...r)=>{let[i,a,...o]=r;if(kC(`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&&Rz(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=xB(e,n,`carousel`),l=pB(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 EB(n,c,e,iB(l,vf(void 0),Pz(e,`{{ carousel }}`),c.paletteOf,t.drawnAt(),l.bg),s,a)},argTypes:[`string`,`value`],arity:{kind:`variadic`},returnType:`T`}}}function OB(e,t,n){let r=xB(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 kB(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 AB(e,t,n,r){let i=OB(e,t,n),a=r??Bz(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,Pz(e,`{{ ${n} }}`))}function jB(e,t,n){return{swatch:{fn:(t,...n)=>{let[r,...i]=n;if(kC(`swatch "${t}"`,[`option`],i),r!==void 0&&typeof r!=`string`)throw Error(`swatch "${t}": option must be text, got ${JSON.stringify(r)}`);return tB(AB(e,t,`swatch`,r))},argTypes:[`string`,`value`],arity:{kind:`variadic`},returnType:`T`},swatches:{fn:(r,i)=>{let a=OB(e,r,`swatches`),o=bB(e,i,`set-int`,`an int action ({ set, int: true })`,`swatches`),s=pB(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]=SB(r,a,{key:o.key,stateVar:o.stateVar},{kind:`led`},!0,e,sB(s,Pz(e,`{{ swatches }}`),a.paletteOf,c,s.bg),Qz(s.palette,s.bg,c),u===0?[]:(()=>{let t=wB(l,Bz(e.store,a.stateVar));return[{glyph:`◀`,option:l[t(-1)]},{glyph:`?`,option:l[kB(n().getTime(),u,t(0))]},{glyph:`▶`,option:l[t(1)]}]})());return d},argTypes:[`string`,`string`],arity:{kind:`exact`},returnType:`T`}}}const MB=[`~/code`,`main`,`opus`,`42%`,`5m`,`$1.20`];function NB(e,t,n,r){let i=Qf(e,n,r),a=(t,n)=>({text:t,colour:n,ink:Bf(e,n,r)});return[[pf(t).map((n,i)=>{let a=jf(e,n);return{text:MB[i%MB.length],colour:a,ink:t.shade.text(e,n.hue,a,r)}})],[[a(`▾ open`,i.state),a(`menu`,i.plane)],[a(`warn`,Af(e,`warning`)),a(`error`,Af(e,`error`))]]]}function PB(e,t){let n=e.flatMap((e,t)=>e.map(({text:e,colour:n,ink:r},i)=>({gap:t>0&&i===0?` `:``,cell:new G(` ${e} `,{style:Zz({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 G(e)),r.push(a)}return r}function FB(e,t,n,r,i){let a=NB(e,t,n,r).map(e=>PB(e,i)),o=G.fromFragments(a.flatMap((e,t)=>t===0?e:[new G(`
|
|
167
|
-
`),...e]));return o.overflow=`ignore`,o.end=``,o}function
|
|
168
|
-
`),...e]));return o.overflow=`ignore`,o.end=``,o}function
|
|
161
|
+
`,l.join(e,`lib`),t.sessionId,t.cwd],env:UI(t),timeoutMs:3e3,category:`memento.read`});return n.ok?GI(n.stdout):L(WI(n))}function qI(e,t,n){let r=Ne({bin:l.join(e,zI),args:n.kind===`set`?[`set`,`session`,n.to]:[`clear`,`session`],env:UI(t),timeoutMs:5e3,category:`memento.move`});if(!r.ok)throw Error(WI(r))}function JI(){return{locate:e=>HI(di(e.claudeConfigDir),e.projectDir),read:KI,move:qI}}function YI(e,t,n){let r=n===void 0?``:`CLAUDE_CONFIG_DIR=${fr(n)} `,i=e.added_dirs.map(e=>` --add-dir ${fr(e)}`).join(``);return`cd ${fr(e.project_dir)} && ${r}claude --resume ${fr(t)}${i}`}function XI(e,t,n){let r=rg(t(`preset`),e.globals.preset,e.presets),i=og(e,r),a=t(`edit.mode`)===`arrange`?e.editGlobals:{},o=fh(a.palette,t(`theme`),i.palette),s=SI(i,xI(o,e.themeDefaults));return{preset:r,presetCustomized:n(r),theme:o,style:Op(a.style,t(`style`),s.style,e.styles),effect:Ip(a.effect,t(`effect`),s.effect),endcaps:Vp(a.endcaps,t(`endcaps`),s.endcaps),variation:Yp(a.variation,t(`variation`),s.variation),shade:Qp(a.shade,t(`shade`),s.shade),separator:a.default_separator??s.default_separator,autoWrap:om(a.autoWrap,t(`autoWrap`),s.autoWrap),padding:lm(a.padding,t(`padding`),s.padding),charset:a.charset??s.charset??`unicode`,updateNotice:sm(a.updateNotice,t(`updateNotice`),s.updateNotice),transitions:cm(a.transitions,t(`transitions`),s.transitions),colorCompatibility:a.colorCompatibility??s.colorCompatibility??`truecolor`}}function ZI(e,t){return{endcaps:e.endcaps,separator:e.separator,colorCompatibility:e.colorCompatibility,wrap:e.autoWrap,padding:e.padding,charset:e.charset,width:t}}function QI(e){return{theme:e.theme,style:e.style,effect:e.effect,preset:e.preset,variation:e.variation,shade:e.shade,transitions:e.transitions}}function $I(e){return{preset:{effective:e.preset,customized:e.presetCustomized,bundled:yI(e.preset)},endcaps:{effective:e.endcaps},variation:{effective:e.variation},shade:{effective:e.shade},charset:{effective:e.charset},colorCompatibility:{effective:e.colorCompatibility},autoWrap:{effective:e.autoWrap},padding:{effective:e.padding},updateNotice:{effective:e.updateNotice},transitions:{effective:e.transitions}}}const eL={prNumber:!0,prState:!0,prUrl:!0,prError:!0,prEarlier:!0};function tL(e){return e?.prState===void 0?e?.prError===void 0?e?.prEarlier===void 0?`-`:`earlier-${e.prEarlier}`:`failed`:e.prState}const nL=10*1e3;function rL(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 iL(e,t){if(!(t<60))return e*3600/t}function aL(e,t,n,r){let i=r-t;if(i<50||i>nL)return;let a=n-e;if(!(a<=0))return a*1e3/i}function oL(e){let{prev:t,cur:n}=e;if(t===void 0)return;let r=aL(t.input,t.atMs,n.input,n.atMs),i=aL(t.output,t.atMs,n.output,n.atMs),a=aL(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 sL(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>nL)continue;let o=aL(r.total,r.atMs,i.total,i.atMs);n.push(o??0)}if(n.length!==0)return n.join(`,`)}function cL(e){let t=e.indexOf(`.`);return t<0?e:e.slice(0,t)}function lL(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`,()=>cL(h.hostname())),i=n(`user`,()=>h.userInfo().username);return{host:{...r!==void 0&&{name:r},...i!==void 0&&{user:i},...e.ssh!==void 0&&{ssh:e.ssh}},failures:t}}function uL(e,t){let n=new Map;for(let[t,r]of Object.entries(e.variables))n.set(t,r);for(let[t,r]of Object.entries(e.segments))if(r.vars)for(let[e,i]of Object.entries(r.vars))n.set(`${t}.${e}`,i);let r=[],i=new Set,a=t=>Dg(t,e.helpers).keys(),o=og(e,t);for(let e of xp){let t=o[e];if(Sp(t))for(let e of a(t))r.push(e)}for(let n of bh(ag(e,t).node)){if(n.when)for(let e of a(n.when))r.push(e);if(n.kind!==`segment`)continue;let t=e.segments[n.name];if(t){for(let e of[t.template,t.when,t.bg,t.fg])if(e)for(let t of a(e))r.push(t)}}let s=new Set;for(;r.length>0;){let e=r.pop();for(let t of fL(n,e)){if(i.has(t))continue;i.add(t);let e=n.get(t);if(e){if(e.kind===`input`)s.add(e.path);else if(e.kind===`template`)for(let t of a(e.template))r.push(t)}}}return s}function dL(e){let t=new Map;return n=>{let r=t.get(n);if(r!==void 0)return r;let i=uL(e,n);return t.set(n,i),i}}function fL(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 pL(e,t){for(let n of e)if(n===t||n.startsWith(t+`.`))return!0;return!1}function mL(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(eL).some(e=>t(`git.${e}`))&&{showPullRequest:!0}}}async function hL(e,t,n,r,i,a,o,{configPath:s,...c}){let l=e=>pL(i,e),u=Aw(t).getTime(),d=o.tmux??null,f=(e,t,n)=>t?n().catch(t=>L(`${e}: ${String(t)}`)):Promise.resolve(I),[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,mL(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(I):n.tmuxService.getSessionName(d)),f(`cache`,l(`cache`),()=>PI(e.transcript_path)),f(`speed`,l(`speed`),()=>n.usageStore.observeSpeed(e.session_id,e.transcript_path,u)),f(`memento`,l(`memento`),()=>n.mementoProvider.getCeiling(LI({sessionId:e.session_id,projectDir:e.workspace?.project_dir??``,cwd:r??e.workspace?.current_dir??``},o))),f(`autocompact`,l(`autocompact`),()=>Promise.resolve(n.autoCompact(ui(li(o.claudeConfigDir)))))]),ee=[],te=e=>{if(e.kind===`failed`){ee.push(e.reason);return}return e.kind===`ok`?e.value:void 0},ne=CL(p,u);ee.push(...ne.failures);let re=lL(o);ee.push(...re.failures);let ie=te(m),ae=te(h),w=te(g),T=te(_),oe=te(v),E=te(y),se=te(b),ce=vL(S);S.kind===`failed`&&ee.push(`memento: ${S.reason}`);let le=gL(C,w?.maxTokens);C.kind===`failed`&&ee.push(`autocompact: ${C.reason}`);for(let e of ee)n.log(`warn`,`provider fetch failed: ${e}`);let ue=e.rate_limits?.five_hour,de=e.rate_limits?.seven_day,fe=ue?rL(ue.used_percentage,ue.resets_at,18e6,u):void 0,pe=de?rL(de.used_percentage,de.resets_at,6048e5,u):void 0,me=ie?.session.cost,he=T?.sessionDuration,ge=l(`burn`)&&me!=null&&he!=null?iL(me,he):void 0,_e=te(x),ve=_e===void 0?void 0:oL(_e),ye=_e===void 0?void 0:sL(_e),be=ve!==void 0||ye!==void 0?{...ve,...ye!==void 0&&{history:ye}}:void 0,xe=SL(process.env.HOME??process.env.USERPROFILE),D=e.workspace?{...e.workspace,current_dir:SL(e.workspace.current_dir)??``,project_dir:SL(e.workspace.project_dir)??``,added_dirs:(e.workspace.added_dirs??[]).map(e=>SL(e)??e)}:e.workspace,Se=ie===void 0?void 0:xL({cost:ie.session.cost,tokens:ie.session.tokens}),Ce=ae===void 0?void 0:{cost:ae.cost,tokens:ae.tokens},we=T===void 0?void 0:xL({lastResponseTime:T.lastResponseTime,responseTime:T.responseTime,sessionDuration:T.sessionDuration,messageCount:T.messageCount,nonPrompts:T.nonPrompts,linesAdded:T.linesAdded,linesRemoved:T.linesRemoved}),Te=oe===void 0?void 0:yL(oe);return{...e,...D!==void 0&&{workspace:D},...xe!==void 0&&{home:xe},...ne.git!==void 0&&{git:ne.git},...d!==null&&{tmux:{pane:d.pane,...E!==void 0&&{session:E}}},host:re.host,...$I(a),history:n.history(e.session_id),navigation:{back:n.navigation(e.session_id)},...c,...s!==null&&{configPath:s},resumeCommand:YI(D,e.session_id,o.claudeConfigDir),...Se!==void 0&&{session:Se},...Ce!==void 0&&{today:Ce},...ge!==void 0&&{burn:{costPerHour:ge}},...be!==void 0&&{speed:be},...l(`block`)&&ue!==void 0&&{block:{nativeUtilization:ue.used_percentage,resetsAt:ue.resets_at,...fe!==void 0&&{etaMinutes:fe}}},...de!==void 0&&{weekly:{percentage:de.used_percentage,resetsAt:de.resets_at,...pe!==void 0&&{etaMinutes:pe}}},...se!==void 0&&{cache:{expiresAt:se}},...w!==void 0&&{context:{totalTokens:w.totalTokens,contextLeft:w.contextLeftPercentage}},...we!==void 0&&{metrics:we},...Te!==void 0&&{activity:Te},...ce!==void 0&&{memento:ce},...le!==void 0&&{autocompact:le}}}function gL(e,t){switch(e.kind){case`absent`:return;case`failed`:return{error:e.reason};case`ok`:return GO(e.value,t)}}const _L=e=>e.trim().split(`
|
|
162
|
+
`).at(-1).trim();function vL(e){switch(e.kind){case`absent`:return;case`failed`:return{error:_L(e.reason)};case`ok`:{let{ceiling:t,session:n}=e.value;return{ceiling:t===`off`?0:t,off:t===`off`,session:n??``}}}}function yL(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=bL(e.running),i=bL(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 bL(e){return e.length===0?void 0:e.map(e=>`${e.name}:${e.count}`).join(`,`)}function xL(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 SL(e){return e===void 0||e.length===0||l.sep!==`\\`?e:e.replace(/\\/g,`/`)}function CL(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`,HC(n.upstream,n.aheadBehind)),p=i(`repoName`,n.repoName),m=i(`repoUrl`,n.repoUrl),h=n.pullRequest===void 0?void 0:UC(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 wL={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?$p:em,autoWrap:e=>e.autoWrap?$p:em,padding:e=>String(e.padding),updateNotice:e=>e.updateNotice?$p:em},TL=Object.entries(ba),EL=new Set(xa.map(e=>e.sessionKey)),DL=()=>!1;function OL(e,t){return XI(e,e=>EL.has(e)?t(e):null,DL)}const kL=[`preset`,`theme`];function AL(e,t,n){let r=new Set(kL.slice(0,n).map(e=>ba[e].sessionKey));return XI(e,e=>r.has(e)?t(e):null,DL)}function jL(e,t){let n=Array.from({length:kL.length+1},(n,r)=>AL(e,t,r));return e=>{let t=kL.indexOf(e);return n[t===-1?kL.length:t]}}function ML(e,t,n,r){return e.flatMap(([e,i])=>{let a=wL[e](t);return a===null||a===wL[e](n(e))?[]:[{...i,value:a,target:r(i)}]})}function NL(e,t,n){return wL[n](OL(e,t))}function PL(e,t){let n=OL(e,t);return ML(TL,n,jL(e,t),t=>FL(e,n.preset,t.configKey))}function FL(e,t,n){return n in(ig(e.presets,t).globals??{})?QE(t,n):n}function IL(e,t,n){let r=rg(t(ba.preset.sessionKey),e.globals.preset,e.presets),i=$E(n);return{key:i?.scope===`globals`?FL(e,r,i.field):n,globals:og(e,r)}}function LL(e,t){let{preset:n}=OL(e,t);return BL(e,n).flatMap(({id:e,setting:r,key:i,decl:a,saved:o})=>{let s=t(i),c=s===null?void 0:Rh(a,s);return c===void 0||Lh(c)===Lh(o)?[]:[{preset:n,id:e,setting:r,key:i,value:c}]})}function RL(e,t,n){let r=new Map(n.map(e=>[e.key,e.value]));return ng(e.presets).flatMap(n=>{let i=BL(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 Fh(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:Rh(e.decl,n);return[e.setting,i??e.saved]}))).map(({message:t})=>`placement "${e}": ${t}`)})})}const zL=new WeakMap;function BL(e,t){let n=zL.get(e)??new Map;zL.set(e,n);let r=n.get(t);if(r!==void 0)return r;let i=[...bh(ag(e,t).node)].flatMap(t=>t.kind!==`segment`||t.drafts===void 0?[]:Object.entries(t.drafts).map(([n,{id:r,key:i}])=>{let a=Nh(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 VL(e,t){let n=OL(e,t);return{from:n.preset,globals:ig(e.presets,n.preset).globals??{},picks:ML(TL.filter(([e])=>e!==`preset`),n,jL(e,t),e=>e.configKey),placements:LL(e,t)}}function HL(e,t){return XI({...e,globals:{palette:t},presets:{}},()=>null,DL)}function UL(e,t){let n=OL(e,t),r=wL.theme(n);if(r===null)return{kind:`rule`};let i=HL(e,r),a=og(e,n.preset),o=Object.fromEntries(Th.map(e=>[e,wL[e](a[e]===void 0?n:i)]));return{kind:`look`,theme:r,look:o,differs:Th.some(e=>o[e]!==wL[e](i))}}function WL(e){return{sessionKeys:xa.filter(t=>t.configKey===e).map(e=>e.sessionKey),fileKeys:[e,...jE(e)?vI.map(t=>QE(t,e)):[],...ZE(e)?gp().map(t=>XE(t,e)):[]]}}function GL(e){return new Set(xa.map(e=>e.configKey).filter(t=>WL(t).fileKeys.some(t=>JL(e,qL(t)))))}function KL(e,t,n){let r=PL(e,n),i=new Set(r.map(e=>e.configKey)),a=Ea(e=>i.has(ba[e].configKey)||t.has(ba[e].configKey)),o=UL(e,n);return{unsaved:r.length+LL(e,n).length,resettable:a,themeDefault:o.kind===`look`&&o.differs?{differs:!0,theme:o.theme}:{differs:!1}}}function qL(e){let t=$E(e);if(t===null||t.scope===`preset-root`)throw Error(`reset layer "${e}" is not a value path`);return eD(t)}function JL(e,t){let[n,...r]=t;return n===void 0?e!==void 0:typeof e==`object`&&!!e&&JL(e[n],r)}const YL=gp(),XL=new Set(YL),ZL=new Set(Lp),QL=e=>e?XL.has(e)?{ok:!0,value:e}:{ok:!1,reason:`unknown theme "${e}" (have: ${YL.join(`, `)})`}:{ok:!1,reason:`theme name is required`},$L=e=>e?ZL.has(e)?{ok:!0,value:e}:{ok:!1,reason:`unknown endcaps "${e}" (have: ${Lp.join(`, `)})`}:{ok:!1,reason:`endcaps name is required`},eR=new Set([`1`,`true`]),tR=new Set([`0`,`false`]),nR={endcaps:$L,theme:QL,"toolbar-expanded":e=>eR.has(e)?{ok:!0,value:`1`}:tR.has(e)?{ok:!0,value:``}:{ok:!1,reason:`expected boolean-ish (1, 0, true, false), got "${e}"`}},rR=xj(nR,`state`,uR);function iR(e,t){return rR.register(e,t)}function aR(e){return rR.gateFor(e)}function oR(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:fg(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 sR(e){return e.filter(e=>e.spec.kind!==`allow-list`||!Object.hasOwn(nR,e.key))}function cR(e,t,n){let r=Da.get(n);if(r!==void 0)return NL(e,t,r);let i=Object.values(e.variables).find(e=>e.kind===`state`&&e.key===n);return i?.kind===`state`?i.default??null:null}function lR(e){let t=WA(e);return sR(Object.values(e.actions).flatMap(e=>oR(e,t)))}function uR(e){return yj(lR(e))}const dR=`update.dismissed`,fR=`updateNotice`,pR=ba.updateNotice.sessionKey;function mR(e){return e.kind===`source`?e.newer.digest:yi(e.newer)}const hR=e=>`${e.version} [${$m(e.digest)}]`;function gR(e){switch(e.kind){case`source`:return{headline:`Newer source`,newer:hR(e.newer),running:hR(e.running),act:`rebuild`,busy:`rebuilding…`,command:{bin:`pnpm`,args:[`build`],cwd:e.root}};case`release`:return{headline:`Newer release`,newer:yi(e.newer),running:yi(e.running),act:`upgrade`,busy:`upgrading…`,command:{bin:`pnpm`,args:[`dlx`,`${xi}@${yi(e.newer)}`,`install`]}}}}const _R={kind:`idle`},vR={kind:`running`};function yR(e,t,n){if(e===null)return[];let r=mR(e);if(!n.enabled||n.dismissed===r)return[];let i=gR(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(`
|
|
163
|
+
`),c=Gn([{verb:wn,args:[s]}]),l=t.kind===`running`?Vm(`[${i.busy}]`,c):Vm(`[${i.act}]`,Gn([{verb:In,args:[n.sessionId]}]));return[{severity:Bm,message:s,lines:[[Vm(a,c),l,Vm(`[dismiss]`,Gn([{verb:yn,args:[n.sessionId,dR,r]}])),Vm(`[disable]`,Gn([{verb:P,args:[n.sessionId,fR,`false`]},{verb:yn,args:[n.sessionId,pR,`false`]}]))],...o.map(e=>[Vm(e,c)])]}]}function bR(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 xR(e){switch(e.kind){case`current`:return[`info`,`build: current ${hR(e.stamp)}`];case`stale`:return[`info`,`build: stale — source ${hR(e.source)}, running ${hR(e.running)}`];case`not-source-checkout`:return[`info`,`build: not a source checkout`];case`unchecked`:return[`warn`,`build: unchecked: ${e.reason}`]}}function SR(e){switch(e.kind){case`current`:return[`info`,`release: current ${yi(e.installed)}`];case`stale`:return[`info`,`release: stale — latest ${yi(e.latest)}, running ${yi(e.installed)}`];case`ahead`:return[`info`,`release: ahead — running ${yi(e.installed)}, latest ${yi(e.latest)}`];case`unchecked`:return[`warn`,`release: unchecked: ${e.reason}`]}}function CR(e){let t=null;return([n,r])=>{r!==t&&(t=r,e(n,r))}}const wR=e=>e.split(/\r?\n/).map(e=>e.trim()).filter(e=>e!==``).at(-1);function TR(e){let t=e.exitCode===null?``:` (exit ${e.exitCode})`,n=wR(e.stderr)??e.error??wR(e.stdout)??`no output`;return`${e.reason}${t}: ${n}`}function ER(){let e=[Cj(fR,[`false`]),iR(pR,[`false`]),iR(dR,[])];return()=>e.forEach(e=>e())}function DR(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=_R,d=null,f=CR(s),p=CR(s),m=()=>bR(c,l);function h(){let e=m(),t=e===null?null:mR(e);(d===null?null:d.identity)!==t&&(d?.dispose(),d=t===null?null:{identity:t,dispose:iR(dR,[t])})}function g(){c=rh(t,th),f(xR(c)),h()}async function _(){l=Ci(Et,await Si(xi,a,i)),p(SR(l)),h()}return{arm(){ER(),g(),setInterval(g,n).unref(),c.kind===`not-source-checkout`&&(_(),setInterval(()=>void _(),r).unref())},notice:e=>yR(m(),u,e),act(){let e=m();if(e===null)throw new K(`apply-update: nothing newer is known to apply`);let t=gR(e);if(u.kind===`running`)throw new K(`apply-update: already ${t.busy}`);u=vR,s(`info`,`apply-update: ${t.act} — ${t.command.bin} ${t.command.args?.join(` `)??``}`),Me({...t.command,category:`update.apply`,timeoutMs:6e5}).then(n=>{if(n.ok){u=_R,s(`info`,`apply-update: ${t.act} succeeded`),g(),o();return}let r=TR(n);u={kind:`failed`,identity:mR(e),reason:r},s(`error`,`apply-update: ${t.act} failed: ${r}`)})}}}var OR=class{static CACHE_DIR=ze();static USAGE_CACHE_DIR=l.join(this.CACHE_DIR,`usage`);static LOCKS_DIR=l.join(this.CACHE_DIR,`locks`);static isLocked(e){let t=l.join(this.LOCKS_DIR,e);if(!r.existsSync(t))return!1;try{let n=r.readFileSync(t,`utf-8`),i=parseInt(n.trim(),10);if(isNaN(i))return D(`Invalid PID in lock file ${e}, removing stale lock`),r.unlinkSync(t),!1;try{return process.kill(i,0),!0}catch(n){return n.code===`ESRCH`?(D(`Removing stale lock file ${e} for dead process ${i}`),r.unlinkSync(t),!1):(D(`Error checking process ${i} for lock ${e}:`,n),!0)}}catch(t){return D(`Error reading lock file ${e}:`,t),!0}}static async acquireLock(e,t=5e3){await this.ensureCacheDirectories();let n=l.join(this.LOCKS_DIR,e),i=Date.now(),a=String(process.pid);for(;Date.now()-i<t;)try{return await r.promises.writeFile(n,a,{flag:`wx`}),D(`Lock acquired for ${e}`),!0}catch(e){if(e.code===`EEXIST`)await de(50);else throw e}return D(`Failed to acquire lock for ${e} within ${t}ms`),!1}static async releaseLock(e){let t=l.join(this.LOCKS_DIR,e);try{await r.promises.unlink(t),D(`Lock released for ${e}`)}catch(t){t.code!==`ENOENT`&&D(`Error releasing lock for ${e}:`,t)}}static async ensureCacheDirectories(){try{await Promise.all([r.promises.mkdir(this.CACHE_DIR,{recursive:!0}),r.promises.mkdir(this.USAGE_CACHE_DIR,{recursive:!0}),r.promises.mkdir(this.LOCKS_DIR,{recursive:!0})])}catch(e){D(`Failed to create cache directories:`,e)}}static createProjectHash(e){return ae(`md5`).update(e).digest(`hex`).substring(0,8)}static async getUsageCache(e,t){await this.ensureCacheDirectories();let n=l.join(this.USAGE_CACHE_DIR,`${e}.json`),i=`${e}.usage.lock`;for(let a=0;a<3;a++){if(this.isLocked(i)){D(`Cache for ${e} is locked, waiting...`),await de(75);continue}try{let i=await r.promises.readFile(n,`utf-8`),a=JSON.parse(i);return!t||a.timestamp>=t?(D(`[CACHE-HIT] ${e} disk cache: found`),this.deserializeDates(a.data)):(D(`${e} cache outdated: cache=${a.timestamp}, latest=${t}`),null)}catch(t){if(t.code===`ENOENT`)return D(`No shared ${e} usage cache found`),null;D(`Attempt ${a+1} failed to read ${e} cache: ${t.message}. Retrying...`),await de(75)}}return D(`Failed to read ${e} cache after 3 attempts.`),null}static deserializeDates(e){return Array.isArray(e)?e.map(e=>({...e,timestamp:new Date(e.timestamp)})):e}static async setUsageCache(e,t,n){let i=`${e}.usage.lock`;if(!await this.acquireLock(i)){D(`Could not acquire lock to set usage cache for ${e}`);return}try{await this.ensureCacheDirectories();let i=l.join(this.USAGE_CACHE_DIR,`${e}.json`),a=JSON.stringify({data:t,timestamp:n||Date.now()});await r.promises.writeFile(i,a,`utf-8`),D(`[CACHE-SET] ${e} disk cache stored`)}catch(t){D(`Failed to save ${e} usage cache:`,t)}finally{await this.releaseLock(i)}}};const kR={"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 AR=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 OR.getUsageCache(`pricing`,e)}static async saveDiskCache(e){await OR.setUsageCache(`pricing`,e)}static async fetchPricingData(){return new Promise(e=>{let t=new ee(this.GITHUB_PRICING_URL),n=ue({hostname:t.hostname,path:t.pathname,headers:{"User-Agent":`cc-candybar`,"Cache-Control":`no-cache`},timeout:5e3},t=>{if(t.statusCode!==200){D(`HTTP ${t.statusCode}: ${t.statusMessage}`),e(null);return}let r=``,i=0;t.on(`data`,t=>{if(i+=t.length,i>1048576){D(`Response too large`),n.destroy(),e(null);return}r+=t}),t.on(`end`,()=>{try{let t=JSON.parse(r),n=t._meta,i={};for(let[e,n]of Object.entries(t))e!==`_meta`&&(i[e]=n);this.validatePricingData(i)?(D(`Fetched fresh pricing from GitHub for ${Object.keys(i).length} models`),D(`Pricing last updated: ${n?.updated||`unknown`}`),e(i)):(D(`Invalid pricing data structure`),e(null))}catch(t){D(`Failed to parse JSON:`,t),e(null)}}),t.on(`error`,t=>{D(`Response error:`,t),e(null)})});n.on(`error`,t=>{D(`Request error:`,t),e(null)}),n.on(`timeout`,()=>{D(`Request timeout`),n.destroy(),e(null)}),n.end()})}static async getCurrentPricing(){if(this.executionCache!==null)return D(`[CACHE-HIT] Pricing execution cache: ${Object.keys(this.executionCache).length} models`),this.executionCache;let e=await this.loadDiskCache();if(e)return D(`[CACHE-HIT] Pricing disk cache: ${Object.keys(e).length} models`),this.executionCache=e,D(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(e).length} models`),e;let t=await this.fetchPricingData();return t?(await this.saveDiskCache(t),D(`[CACHE-SET] Pricing disk cache stored: ${Object.keys(t).length} models`),this.executionCache=t,D(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(t).length} models`),t):(D(`[CACHE-FALLBACK] Using offline pricing data: ${Object.keys(kR).length} models`),this.executionCache=kR,D(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(kR).length} models`),kR)}static validatePricingData(e){if(!e||typeof e!=`object`)return!1;for(let[,t]of Object.entries(e)){if(!t||typeof t!=`object`)return!1;let e=t;if(typeof e.input!=`number`||typeof e.output!=`number`||typeof e.cache_read!=`number`)return!1}return!0}static async getModelPricing(e){if(this.modelPricingCache.has(e))return D(`[CACHE-HIT] Model pricing cache: ${e}`),this.modelPricingCache.get(e);let t=await this.getCurrentPricing(),n;return n=t[e]?t[e]:this.fuzzyMatchModel(e,t),this.modelPricingCache.set(e,n),D(`[CACHE-SET] Model pricing cache: ${e}`),n}static fuzzyMatchModel(e,t){let n=e.toLowerCase();for(let[e,r]of Object.entries(t))if(e.toLowerCase()===n)return r;for(let{pattern:e,fallback:r}of[{pattern:[`opus-4-6`,`claude-opus-4-6`],fallback:`claude-opus-4-6-20260205`},{pattern:[`opus-4-5`,`claude-opus-4-5`],fallback:`claude-opus-4-5-20251101`},{pattern:[`opus-4-1`,`claude-opus-4-1`],fallback:`claude-opus-4-1-20250805`},{pattern:[`opus-4`,`claude-opus-4`],fallback:`claude-opus-4-20250514`},{pattern:[`sonnet-4-6`,`sonnet-4.6`,`claude-sonnet-4-6`],fallback:`claude-sonnet-4-6`},{pattern:[`sonnet-4.5`,`4-5-sonnet`,`sonnet-4-5`],fallback:`claude-sonnet-4-5-20250929`},{pattern:[`sonnet-4`,`claude-sonnet-4`],fallback:`claude-sonnet-4-20250514`},{pattern:[`haiku-4.5`,`4-5-haiku`,`haiku-4-5`],fallback:`claude-haiku-4-5-20251001`},{pattern:[`haiku`],fallback:`claude-haiku-4-5-20251001`},{pattern:[`opus`],fallback:`claude-opus-4-20250514`},{pattern:[`sonnet`],fallback:`claude-sonnet-4-5-20250929`}])if(e.some(e=>n.includes(e))&&t[r])return t[r];return t[`claude-sonnet-4-5-20250929`]||{name:`${e} (Unknown Model)`,input:3,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3,output:15}}static async calculateCostForEntry(e){let t=e.message?.usage;if(!t)return 0;let n=this.extractModelId(e),r=await this.getModelPricing(n),i=t.input_tokens||0,a=t.output_tokens||0,o=t.cache_creation_input_tokens||0,s=t.cache_read_input_tokens||0,c=i/1e6*r.input,l=a/1e6*r.output,u=s/1e6*r.cache_read,d=o/1e6*r.cache_write_5m;return c+l+d+u}static extractModelId(e){if(e.model&&typeof e.model==`string`)return e.model;let t=e.message;if(t?.model){let e=t.model;if(typeof e==`string`)return e;let n=e;return(typeof n?.id==`string`?n.id:null)||`claude-sonnet-4-5-20250929`}return e.model_id&&typeof e.model_id==`string`?e.model_id:`claude-sonnet-4-5-20250929`}};const jR=/<command-name>\s*([^<\s][^<]*?)\s*<\/command-name>/;function MR(e){if(typeof e==`string`)return jR.exec(e)?.[1]}function NR(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 PR(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 FR(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=NR(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`?MR(PR(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 IR(e){if(e!==void 0)return[e];let t=g();return[p(t,`.config`,`claude`),p(t,`.claude`)].filter(e=>a(e))}async function LR(e){let t=[];for(let n of e){let e=p(n,`projects`);if(a(e))try{let n=await DI(e,{withFileTypes:!0});for(let r of n)if(r.isDirectory()){let n=p(e,r.name);t.push(n)}}catch(t){D(`Failed to read projects directory ${e}:`,t)}}return t}async function RR(e,t,n){let r=[],i=p(t,e,`subagents`);try{let t=(await DI(i)).filter(e=>e.startsWith(`agent-`)&&e.endsWith(`.jsonl`));for(let a of t){let t=p(i,a);if(n?.has(t)){r.push(t);continue}try{let n=(await OI(t,`utf-8`)).split(`
|
|
164
|
+
`)[0];n&&JSON.parse(n).sessionId===e&&r.push(t)}catch{D(`Failed to check agent file ${t}`)}}}catch(e){D(`Failed to read subagents directory ${i}:`,e)}return r}function zR(e){let t=e.message;if((e.type||t?.role||t?.type)!==`user`)return;if(VR(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=PR(t?.content).trimStart();return r.startsWith(`[Request interrupted by user`)?`interrupt`:e.isMeta===!0||e.isCompactSummary===!0||BR.test(r)?`claude-code`:`prompt`}const BR=/^<(?:command-name|local-command-std(?:out|err)|bash-(?:input|stdout|stderr))>/;function VR(e){let t=e?.content;return Array.isArray(t)&&typeof t[0]==`object`&&t[0]?t[0].type:void 0}const HR=new Map;async function UR(e){try{let t=await kI(e),n=t.size,r=HR.get(e);if(r&&r.mtime===t.mtimeMs&&r.size===n)return D(`[parse-cache] hit ${e}`),HR.delete(e),HR.set(e,r),r.entries;let i;return n>1048576?(D(`Using streaming parser for large file ${e} (${Math.round(n/1024)}KB)`),i=await JR(e)):i=await KR(e),D(`Parsed ${i.length} entries from ${e}`),n>5242880?i:(HR.delete(e),HR.size>=16&&HR.delete(HR.keys().next().value),HR.set(e,{mtime:t.mtimeMs,size:n,entries:i}),i)}catch(t){if(t.code===`ENOENT`)return D(`Transcript not present yet: ${e}`),[];throw t}}function WR(e){if(!e.timestamp)return null;let t=e.message,n=t?.usage,r=zR(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:FR(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 GR(e){let t=[];for(let n of e.split(`
|
|
165
|
+
`))if(n.trim())try{let e=WR(JSON.parse(n));e&&t.push(e)}catch(e){D(`Failed to parse JSONL line: ${e}`);continue}return t}async function KR(e){return GR(await OI(e,`utf-8`))}async function qR(e,t){let n=await AI(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 F(c<0?{entries:[],cursor:{offset:i,stamp:a,ino:o},reset:s}:{entries:GR(r.subarray(0,c+1).toString(`utf-8`)),cursor:{offset:i+c+1,stamp:a,ino:o},reset:s})}async function JR(e){return new Promise((t,n)=>{let r=[],a=i(e,{encoding:`utf8`}),o=fe({input:a,crlfDelay:1/0});o.on(`line`,e=>{let t=e.trim();if(t)try{let e=WR(JSON.parse(t));e&&r.push(e)}catch(e){D(`Failed to parse JSONL line: ${e}`)}}),o.on(`close`,()=>{t(r)}),o.on(`error`,t=>{D(`Streaming parser error for ${e}:`,t),n(t)}),a.on(`error`,t=>{D(`File stream error for ${e}:`,t),n(t)})})}var YR=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 XR(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 ZR=new Map,QR={cost:0,input:0,output:0,cacheCreation:0,cacheRead:0},$R={cost:null,calculatedCost:null,officialCost:null,tokens:null,tokenBreakdown:null};function ez(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function tz(){let e=new Date;return e.setHours(0,0,0,0),e.setDate(e.getDate()-1),e.getTime()}function nz(){return{input:0,output:0,cacheCreation:0,cacheRead:0}}async function rz(e,t,n,r){let i=ez(new Date(tz())),a=e&&!t?e:void 0,o=a?.entries??0,s=a?.cost??0,c=a?{...a.breakdown}:nz(),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 AR.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=ez(new Date(e.timestamp));if(r<i)continue;let a=l.get(r)??{...QR};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 iz(e){let t=0,n=0,r=nz(),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)??{...QR};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:$R,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 az(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 oz=class{sessions=new Map;flight=new YR;seeded=new Map;seededDay=``;rescanIntervalMs;speedFlight=new YR;staleAgeMs;log;renderTally={hits:0,misses:0};sweeps=0;scans={seed:0,rescan:0};sweepTimer=null;constructor(e={}){this.log=e.logger??Ft,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:$R,i=t?.cost?.total_cost_usd??null;return F({session:{...r,cost:i??r.cost,officialCost:i}})}async getTodayInfo(e,t,n){let r=ez(Aw(n)),i=IR(t);try{await this.ensureSeeded(r,i,n*1e3)}catch(e){return L(`usage seed: ${e instanceof Error?e.message:String(e)}`)}let a=await this.ingest(e?.session_id??``,e?.transcript_path,this.renderTally);if(a.kind===`failed`)return a;let o=i.map(e=>p(e,`projects`)+m),s={...QR},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??ZR:ZR;c||=a.has(r);let l=a.get(r)??QR;s.cost+=l.cost,s.input+=l.input,s.output+=l.output,s.cacheCreation+=l.cacheCreation,s.cacheRead+=l.cacheRead}return c?F({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}):I}async observeSpeed(e,t,n){if(!e)return I;let r=CI(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=XR(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(),F({...s!==void 0&&{prev:s},cur:a,samples:[...o]})})}async ingest(e,t,n,r){if(!e)return I;let i=r??CI(t),a=this.see(e)?.record;if(a&&i!==``&&a.transcriptStamp===i)return n.hits++,F(a);if(!t)return a?F(a):I;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 L(`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),F(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 RR(e,d(t),n===void 0?void 0:new Set(n.files.keys())),i=new Map,a=``;for(let e of[t,...r]){let r=n?.files.get(e),o=await qR(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 rz(r,l,s,c)),e===t&&(a=c.stamp)}return F({files:i,...iz(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=tz(),i=await LR(e),a=[];for(let e of i){let t;try{t=await DI(e)}catch{continue}for(let n of t){if(!n.endsWith(`.jsonl`))continue;let t=p(e,n),i;try{i=await kI(t)}catch{continue}i.mtimeMs<r||a.push({sessionId:n.slice(0,-6),path:t,stamp:wI(i)})}}let o={hits:0,misses:0};await az(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()}},sz=class{thresholds={LOW:50,MEDIUM:80};getContextUsageThresholds(){return this.thresholds}ratioPercentages(e,t){let n=Math.min(100,Math.max(0,Math.round(e/t*100)));return{percentage:n,contextLeftPercentage:Math.max(0,100-n)}}calculateContextFromHookData(e){let t=e.context_window;if(!t?.current_usage)return D(`No current_usage in hook data, falling back to transcript parsing`),null;let n=t.current_usage,r=t.context_window_size,i=(n.input_tokens||0)+(n.cache_creation_input_tokens||0)+(n.cache_read_input_tokens||0);D(`Native current_usage: input=${n.input_tokens}, cache_create=${n.cache_creation_input_tokens}, cache_read=${n.cache_read_input_tokens}, total=${i} (limit: ${r})`);let a=this.ratioPercentages(i,r);return{totalTokens:i,maxTokens:r,percentage:t.used_percentage==null?a.percentage:Math.round(t.used_percentage),contextLeftPercentage:t.remaining_percentage==null?a.contextLeftPercentage:Math.round(t.remaining_percentage)}}async calculateContextTokensFromTranscript(e,t){try{D(`Calculating context tokens from transcript: ${e}`);let n=await UR(e);if(n.length===0)return D(`No entries in transcript`),I;let r=null;for(let e=n.length-1;e>=0;e--){let t=n[e];if(t&&t.message?.usage?.input_tokens&&t.isSidechain!==!0){r=t,D(`Context segment: Found most recent entry at ${t.timestamp.toISOString()}, stopping search`);break}}if(r?.message?.usage){let e=r.message.usage,n=(e.input_tokens||0)+(e.cache_read_input_tokens||0)+(e.cache_creation_input_tokens||0);return D(`Most recent main chain context: ${n} tokens (limit: ${t})`),F({totalTokens:n,maxTokens:t,...this.ratioPercentages(n,t)})}return D(`No main chain entries with usage data found`),I}catch(e){return L(`context transcript: ${e instanceof Error?e.message:String(e)}`)}}async getContextInfo(e){let t=this.calculateContextFromHookData(e);if(t)return F(t);let n=e.context_window?.context_window_size??2e5;return this.calculateContextTokensFromTranscript(e.transcript_path,n)}},cz=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=CI(t);if(n&&r!==``&&n.cursor.stamp===r)return this.touch(e,n),{kind:`ok`,value:n.value};let i=await qR(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 lz={messageCount:0,nonPrompts:0,recent:[]},uz=new Set([`turn`,`interrupt`,`claude-code`]);function dz(e,t){if(t.isSidechain)return e;let n=[...e.recent,t];return{messageCount:e.messageCount+ +(t.userEntry===`prompt`),nonPrompts:e.nonPrompts+ +!!uz.has(t.userEntry),recent:n.length>20?n.slice(-20):n}}function fz(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 pz=class{fold=new cz(lz,dz);async getMetricsInfo(e,t){if(D(`Getting metrics from hook data for session: ${e}`),!t.cost)return I;let n=await this.fold.read(e,t.transcript_path);return n.kind===`failed`?L(`metrics (${e}): ${n.reason}`):F({responseTime:t.cost.total_api_duration_ms/1e3,lastResponseTime:fz(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 mz={command:null,todos:[],pending:[],done:[]};function hz(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 gz(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 _z(e,t){if(t.isSidechain)return e;let n=gz(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=hz(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 vz(e){return{command:e.command,todos:e.todos,running:e.pending.reduce((e,t)=>hz(e,t.name),[]),done:e.done}}var yz=class{fold=new cz(mz,_z);async getActivityInfo(e,t){let n=await this.fold.read(e,t.transcript_path);return n.kind===`failed`?L(`activity (${e}): ${n.reason}`):F(vz(n.value))}};function bz(e,t,n,r){return{bin:`tmux`,args:[`-S`,e.socket,...n],timeoutMs:2e3,category:t,stdinInput:r}}function xz(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 Sz(e,t,n,r){return xz(Ne(bz(e,t,n,r)),n)}async function Cz(e,t,n){return xz(await Me(bz(e,t,n)),n)}const wz=e=>`${e.socket}\n${e.pane}`;var Tz=class{names=new Map;asking=new YR;constructor(e=Date.now){this.now=e}getSessionName(e){let t=wz(e),n=this.names.get(t);if(n&&this.now()-n.at<3e4)return Promise.resolve(n.outcome);let r=this.asking.run(t,()=>this.ask(t,e));return n?Promise.resolve(n.outcome):r}async ask(e,t){D(`Getting tmux session name for pane ${t.pane} on ${t.socket}`);let n=await Cz(t,`tmux`,[`display-message`,`-p`,`-t`,t.pane,`#S`]),r=n.kind===`ok`?n.stdout.trim():``,i=n.kind===`ok`?r?F(r):I:L(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 Ez=e=>JSON.stringify([e.sessionId,e.projectDir,e.cwd,e.claudeConfigDir,e.env===void 0?null:tt.map(t=>e.env?.[t]??null)]);var Dz=class{readings=new Map;inFlight=new Map;constructor(e,t=Date.now){this.edge=e,this.now=t}getCeiling(e){let t=Ez(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=Ez(e);try{this.edge.move(n.value,e,t)}finally{this.readings.delete(r),this.inFlight.delete(r),this.fetch(r,e)}}};function Oz(e){return{gitProvider:new ww({watchers:e.watchers,logger:e.logger}),usageStore:new oz({logger:e.logger}),contextProvider:new sz,metricsProvider:new pz,activityProvider:new yz,tmuxService:new Tz,mementoProvider:new Dz(JI()),autoCompact:WO,log:e.logger}}function kz(e,t){return e===void 0?!0:e.evaluate(t).map(e=>e.plain).join(``)!==`false`}const Az={kind:`hidden`},jz={kind:`shown`};function Mz(e,t){try{return kz(e,t)?jz:Az}catch(e){return{kind:`failed`,message:e instanceof Error?e.message:String(e)}}}function Nz(e,t){let n=G.fromFragments(e);return n.end=``,n.overflow=`ignore`,t!==void 0&&!t.isNull&&(n.style=t),n}function Pz(e,t,n){e.cellLength>t?e.truncate(t,{mode:n.truncate,marker:`…`}):e.cellLength<t&&e.align(n.justify,t)}function Fz({lead:e,text:t,trail:n}){return[...e===void 0?[]:[e],t,...n===void 0?[]:[n]]}function Iz({text:e,placement:t,lead:n,trail:r}){return{text:Lz(e),placement:t,...n!==void 0&&{lead:Lz(n)},...r!==void 0&&{trail:Lz(r)}}}function Lz(e){let t=e.blankCopy(e.plain);t.style=dm(e.style).clearMetaAndLinks();for(let{start:n,end:r,style:i}of e.spans)t.stylize(dm(i).clearMetaAndLinks(),n,r);return t}function Rz(e){let t=Fz(e);if(t.length===1)return e.text;let n=Nz(t);return n.style=e.text.style,n}function zz(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=Nz(e,a).pad(o),d=new G(` `.repeat(o)),f={placement:s,...c.length>0&&{lead:Nz([d,...c],a)},...l.length>0&&{trail:Nz([...l,d],a)}};if(n===`auto`)return[{text:u,...f}];let p={justify:r,truncate:i};return n===`fill`?[{text:u,fill:p,...f}]:(Pz(u,n,p),[{text:u,...f}])}function Bz(e,t){let n=()=>e.map(e=>({owner:Rz(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=Im(e.map(Rz),t).split(`
|
|
166
|
+
`);if(i.length>1)return n();let a=Math.max(0,t.width-Cm(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];Pz(c,c.cellLength+a,n)}),n()}function Vz(e,t){let n=[],r=[],i=()=>{if(!r.length)return;let e=Hz(r,t);e.plain.length>0&&n.push(e),r=[]};for(let a of e){let e={frag:a,style:dm(a.style)};if(e.style.link){i();let r=Hz([e],t);r.plain.length>0&&n.push(r)}else r.push(e)}return i(),n}function Hz(e,t){let n=t!==void 0&&!t.isNull?t:void 0,r=e.map(e=>Uz(e.frag,n?n.add(e.style):e.style)),i=G.fromFragments(r);return i.end=``,i.overflow=`ignore`,r.length===1?i.style=r[0].style:n!==void 0&&(i.style=n),i}function Uz(e,t){let n=e.copy();return n.style=t,n}function Wz(e,t){if(e.look===void 0)throw Error(`${t} read the render's look before any render resolved one`);return e.look}function Gz(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,Kz(e,t,o,n,r,i));return i}function Kz(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=fg(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=fg(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=fg(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:Yz(e,n.copy,t)};if(`open`in n)return{kind:`open`,target:Yz(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:EN(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:Yz(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 qz(e){return e.kind===`do`?qz(e.head):e}function Jz(e){switch(qz(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 Yz(e,t,n){try{return e(t)}catch(e){throw Error(`Template parse error in actions.${n}: ${e.message}`,{cause:e})}}function Xz(e,t){return e.has(t)?Wg(e.read(t)):``}function Zz(e,t){return e.evaluate(t).map(e=>e.plain).join(``)}function Qz(e,t,n,r){let i=new G(e,{style:H.combine([r,new H({link:t,bold:n})])});return i.overflow=`ignore`,i.end=``,i}function $z(e,t,n=!1){let r=new H({link:t,bold:n?!0:void 0}),i=new G(e.plain,{style:H.combine([dm(e.style),r])});for(let t of e.spans)i.stylize(H.combine([dm(t.style),r]),t.start,t.end);return i.overflow=`ignore`,i.end=``,i}function eB(e,t){return Math.max(e.members.indexOf(Xz(t,e.stateVar)),0)}function tB(e,t,n,r,i){switch(e.kind){case`set-literal`:{let t=Xz(r,e.stateVar);return{effects:[{verb:yn,args:[i,e.key,e.value]}],active:t===e.value}}case`set-option`:{let a=n??t,o=Xz(r,e.stateVar);return{effects:[{verb:yn,args:[i,e.key,a]}],active:o===a}}case`set-int`:{let a=n??t,o=Xz(r,e.stateVar);return{effects:[{verb:yn,args:[i,e.key,a]}],active:o===a}}case`set-cycle`:{let t=e.members[(eB(e,r)+1)%e.members.length];return{effects:[{verb:yn,args:[i,e.key,t]}],active:!1}}case`set-bounded`:return{effects:[{verb:N,args:[i,e.key,String(e.by)]}],active:!1};case`copy`:return{effects:[{verb:bn,args:[Zz(e.text,FC(r))]}],active:!1};case`open`:return{effects:[{verb:xn,args:[Zz(e.target,FC(r))]}],active:!1};case`persist-literal`:{let t=Xz(r,e.stateVar);return{effects:[{verb:P,args:[i,e.key,e.value]}],active:t===e.value}}case`persist-option`:{let a=n??t,o=Xz(r,e.stateVar);return{effects:[{verb:P,args:[i,e.key,a]}],active:o===a}}case`persist-cycle`:{let t=e.members[(eB(e,r)+1)%e.members.length];return{effects:[{verb:P,args:[i,e.key,t]}],active:!1}}case`persist-bounded`:return{effects:[{verb:Tn,args:[i,e.key,String(e.by)]}],active:!1};case`reset`:return{effects:[{verb:An,args:[i,e.key]}],active:!1};case`undo`:return{effects:[{verb:Mn,args:[i]}],active:!1};case`redo`:return{effects:[{verb:Nn,args:[i]}],active:!1};case`back`:return{effects:[{verb:Pn,args:[i]}],active:!1};case`rewind`:return{effects:[{verb:Fn,args:[i]}],active:!1};case`save`:return{effects:[{verb:En,args:[i]}],active:!1};case`preset-save`:return{effects:[{verb:Dn,args:[i]}],active:!1};case`theme-default-save`:return{effects:[{verb:On,args:[i]}],active:!1};case`preset-delete`:return{effects:[{verb:kn,args:[i,Zz(e.name,FC(r))]}],active:!1};case`doctor-run`:return{effects:[{verb:Ln,args:[i]}],active:!1};case`doctor-fix`:return{effects:[{verb:Rn,args:[i,e.check]}],active:!1};case`doctor-mark`:return{effects:[{verb:zn,args:[i,e.check,e.mark]}],active:!1};case`ceiling`:return{effects:[{verb:Vn,args:[i,...e.args]}],active:!1};case`slash`:return{effects:[{verb:Hn,args:[i,e.line]}],active:!1};case`layout-op`:return{effects:[{verb:jn,args:[i,e.key,lj(e.op)]}],active:!1};case`do`:{let a=tB(e.head,t,n,r,i);return{effects:[...a.effects,...e.rest.flatMap(e=>tB(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:jn,args:[i,e.key,lj(r)]}],active:!1}}}}function nB(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:er(`action "${e}"`,n,t.members.length,eB(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 rB(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}=nB(e,qz(r),t,i),s=Xz(i,`session.id`),{effects:c,active:l}=tB(r,a.plain,o,i,s);return $z(a,Gn(c),l)}function iB(e){return{action:{fn:(t,...n)=>rB(t,n,e),argTypes:[`string`,`liftable`],arity:{kind:`variadic`},returnType:`T`}}}function aB(e,t){return Qz(`✕`,Gn([{verb:yn,args:[Xz(e,`session.id`),t,Zn]}]),!1)}function oB(e,t,n){return new H({bgcolor:V.fromRgba(t),color:V.fromRgba(Bf(e,t,n))})}function sB({tint:e,text:t}){return new H({bgcolor:V.fromRgba(e),color:V.fromRgba(t)})}function cB(e,t,n){return new H({color:V.fromRgba(ac(Af(e,`warning`),t,zf,n))})}function lB(e,t,n){return H.combine([oB(e,t,n),cB(e,t,n)])}function uB(e,t,n){return oB(e.palette,sp(e.palette,e.disclosure,[t],n),n)}function dB(e){let t=V.fromRgba(Af(e,`background`)),n=G.fromFragments(nf.map(n=>new G(`▀`,{style:new H({color:V.fromRgba(Af(e,n)),bgcolor:t})})));return n.overflow=`ignore`,n.end=``,n}const fB=(e,t)=>{let n=typeof e==`string`?new G(e,{style:t}):e;return n.overflow=`ignore`,n.end=``,n},pB=e=>new H({bold:e});function mB(e,t,n,r,i,a){if(r===void 0)return(n,r,a,o)=>fB(a,H.combine([uB(e,{...n,distribution:t},i),pB(o)]));let o=oB(e.palette,a,i);return(e,t,i,a)=>hB(i,H.combine([o,pB(a)]),r(t,n))}const hB=(e,t,n)=>fB(G.fromFragments([fB(e,t),fB(` `,t),dB(n)]));function gB(e,t){return t===void 0?(e,t,n)=>fB(n):(n,r,i)=>hB(i,void 0,t(r,e))}function _B(e,t,n,r,i){let a=oB(e.palette,i,r);return(e,r,i,o)=>fB(G.fromFragments([fB(o?`[`:` `,a),dB(n(r,t)),fB(o?`]`:` `,a)]))}function vB(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=>yB(e.indices,8).map(t=>[{label:e.label,indices:t}])):[r]}function yB(e,t){return Array.from({length:Math.ceil(e.length/t)},(n,r)=>e.slice(r*t,(r+1)*t))}function bB(e,t){return new G(e).truncate(t,{marker:`…`}).plain}function xB(e){return{current:null,drawnAt:e}}function SB(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 CB(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 wB(e){return new G(e).cellLength}function TB(e){return Math.max(1,e.width-e.chromeCols-2*e.padding)}function EB(e){return Math.max(1,TB(e)-(wB(`✕`)+2*e.padding+e.seamCols))}function DB(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 OB(e,t,n){let r=wB(`←`)+1+wB(`→`)+1,i=DB(e,t,n);return(i.length>1?DB(e,t,n+r):i).map(e=>[{label:``,indices:e}])}function kB(e,t){let n=[];for(let t of e)n.length>0&&n.push(new G(` `)),n.push(t);let r=G.fromFragments(n);return r.overflow=t?`ignore`:void 0,r.end=``,r}function AB(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 jB(e,t,n){let r=e.compiled.get(t),i=r&&qz(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 MB(e,t,n,r,i,a,o,s,c=[]){let l=a.compiled.get(e),u=a.store,d=Xz(u,`session.id`),f=`stateVar`in t?Xz(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`?EB(a):TB(a):1/0,h=(r.kind===`led`?0:wB(`✕`)+1)+c.reduce((e,t)=>e+wB(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?OB(_.map(e=>e.cellLength),m,h):vB(g.entries,g.groups,i),y=parseInt(Xz(u,n.stateVar),10),b=e=>Math.max(0,v.findIndex(t=>t.some(t=>t.indices.includes(e)))),x=b(f===void 0?-1:t.options.indexOf(f)),S=Number.isInteger(y)?y<0?x:Math.min(y,v.length-1):0,C=v[S]??[],ee=e=>Gn([{verb:yn,args:[d,n.key,String(e)]}]),te=r.kind===`led`?[]:[{verb:yn,args:[d,...r.writes.flatMap(([e,t])=>[e,t])]}],ne=r.kind===`own`&&r.onPick?te:[],re=e=>Gn([...tB(l,e,e,u,d).effects,...ne]),ie=(e,n)=>$z(e,re(t.options[n])),ae=r.kind===`led`?[]:[Qz(`✕`,Gn(te),!1,s)];ae.push(...c.map(({glyph:e,option:r})=>Qz(e,Gn([...tB(l,r,r,u,d).effects,{verb:yn,args:[d,n.key,String(b(t.options.indexOf(r)))]}]),!1))),S>0&&ae.push(Qz(`←`,ee(S-1),!1));let w=S<v.length-1?[Qz(`→`,ee(S+1),!1)]:[];if(g===void 0){let e=C.flatMap(e=>e.indices);return[kB([...ae,...e.map(e=>ie(_[e],e)),...w],i)]}let T=new H({bold:!0}),oe=v.length>1?` ${S+1}/${v.length}`:``,E=C.length===1?[new G(`${C[0].label}${oe}`,{style:T})]:[],se=[kB([...ae,...E,...w],i)];for(let e of C){C.length>1&&se.push(kB([new G(e.label,{style:T})],i));let n=Math.max(...e.indices.map(e=>wB(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:Jd(a),s=` `.repeat(n-wB(e)+2),c=o===void 0?e:`${e}${s}${o}`;se.push(kB([ie(p(r,bB(c,m)),r)],i))}}return se}function NB(e,t){return{picker:{fn:(n,r,i,a,o,...s)=>{kC(`picker "${n}"`,[`closeOnPick`,`paged`,`inBody`],s);let c=AB(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=jB(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=CB(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]=MB(n,l,{key:c.key,stateVar:c.stateVar},o===!0?{kind:`led`}:{kind:`own`,writes:[[c.key,`-1`]],onPick:i===!0},a===!0,e,mB(u,vf(void 0),Wz(e,`{{ picker }}`),l.paletteOf,t.drawnAt(),u.bg),cB(u.palette,u.bg,t.drawnAt()));return d},argTypes:[`string`,`string`,`bool`],arity:{kind:`variadic`},returnType:`T`}}}function PB(e,t){let n=e.length,r=Math.max(e.indexOf(t),0);return e=>((r+e)%n+n)%n}function FB(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 IB(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=Xz(o,`session.id`),{options:l}=t,u=l.length;if(u===0)return kB([],!0);let d=Xz(o,t.stateVar),f=PB(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=Gn(tB(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=$z(g(e),h(e));return _.set(e,n),n},y=a===void 0?v(0):$z(gB(Wz(n,`{{ carousel }}`),t.paletteOf)({index:f(0),count:u},p(0),p(0),!1),Gn(tB(n.compiled.get(a),p(0),void 0,o,c).effects)),b=FB(e=>v(e).cellLength,u,wB(`◀`)+1+y.cellLength+1+wB(`▶`),EB(n),i),x=e=>Array.from({length:b},(t,n)=>v(e*(n+1)));return kB([...x(-1).reverse(),Qz(`◀`,h(-1),!1),y,Qz(`▶`,h(1),!1),...x(1)],!0)}function LB(e,t){return{carousel:{fn:(n,...r)=>{let[i,a,...o]=r;if(kC(`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&&Jz(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=jB(e,n,`carousel`),l=CB(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 IB(n,c,e,mB(l,vf(void 0),Wz(e,`{{ carousel }}`),c.paletteOf,t.drawnAt(),l.bg),s,a)},argTypes:[`string`,`value`],arity:{kind:`variadic`},returnType:`T`}}}function RB(e,t,n){let r=jB(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 zB(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 BB(e,t,n,r){let i=RB(e,t,n),a=r??Xz(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,Wz(e,`{{ ${n} }}`))}function VB(e,t,n){return{swatch:{fn:(t,...n)=>{let[r,...i]=n;if(kC(`swatch "${t}"`,[`option`],i),r!==void 0&&typeof r!=`string`)throw Error(`swatch "${t}": option must be text, got ${JSON.stringify(r)}`);return dB(BB(e,t,`swatch`,r))},argTypes:[`string`,`value`],arity:{kind:`variadic`},returnType:`T`},swatches:{fn:(r,i)=>{let a=RB(e,r,`swatches`),o=AB(e,i,`set-int`,`an int action ({ set, int: true })`,`swatches`),s=CB(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]=MB(r,a,{key:o.key,stateVar:o.stateVar},{kind:`led`},!0,e,_B(s,Wz(e,`{{ swatches }}`),a.paletteOf,c,s.bg),cB(s.palette,s.bg,c),u===0?[]:(()=>{let t=PB(l,Xz(e.store,a.stateVar));return[{glyph:`◀`,option:l[t(-1)]},{glyph:`?`,option:l[zB(n().getTime(),u,t(0))]},{glyph:`▶`,option:l[t(1)]}]})());return d},argTypes:[`string`,`string`],arity:{kind:`exact`},returnType:`T`}}}const HB=[`~/code`,`main`,`opus`,`42%`,`5m`,`$1.20`];function UB(e,t,n,r){let i=Qf(e,n,r),a=(t,n)=>({text:t,colour:n,ink:Bf(e,n,r)});return[[pf(t).map((n,i)=>{let a=jf(e,n);return{text:HB[i%HB.length],colour:a,ink:t.shade.text(e,n.hue,a,r)}})],[[a(`▾ open`,i.state),a(`menu`,i.plane)],[a(`warn`,Af(e,`warning`)),a(`error`,Af(e,`error`))]]]}function WB(e,t){let n=e.flatMap((e,t)=>e.map(({text:e,colour:n,ink:r},i)=>({gap:t>0&&i===0?` `:``,cell:new G(` ${e} `,{style:sB({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 G(e)),r.push(a)}return r}function GB(e,t,n,r,i){let a=UB(e,t,n,r).map(e=>WB(e,i)),o=G.fromFragments(a.flatMap((e,t)=>t===0?e:[new G(`
|
|
167
|
+
`),...e]));return o.overflow=`ignore`,o.end=``,o}function KB(e,t){return{themePreview:{fn:(...n)=>{let[r,...i]=n;if(kC(`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}=Wz(e,`{{ themePreview }}`);return GB(r===void 0?a:BB(e,r,`themePreview`),o,{...CB(t,`{{ themePreview }}`).disclosure,depth:0},t.drawnAt(),EB(e))},argTypes:[`value`],arity:{kind:`variadic`},returnType:`T`}}}const qB=e=>e.slice(e.lastIndexOf(`.`)+1),JB=(e,t)=>{let n=new G(qB(e));return n.truncate(t,{marker:`…`}),n.plain};function YB(e,t){let n=e.map(e=>e.map(({name:e})=>wB(qB(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 XB(e,t,n,r){let i=YB(e,r),a=e.map(e=>{let a=[],o=0;for(let{name:s,address:c,palette:l}of e){let e=new G(` ${JB(s,i)} `,{style:sB(dp(l,{kind:`bar`,decor:t,address:c},n))});if(o+=e.cellLength,o>r)break;a.push(e)}return a}),o=G.fromFragments(a.flatMap((e,t)=>t===0?e:[new G(`
|
|
168
|
+
`),...e]));return o.overflow=`ignore`,o.end=``,o}function ZB(e,t){return{layoutPreview:{fn:()=>XB(e.layout(),Wz(e,`{{ layoutPreview }}`).decor,t.drawnAt(),EB(e)),argTypes:[],arity:{kind:`exact`},returnType:`T`}}}function QB(e,t,n,r){let i=CB(r.activeSegment,`{{ menu }}`),a=r.action,o=vT(i.placementId,e,n.key),s=xT(o),c=_T(e),l=Xz(a.store,o)===c,u=Xz(a.store,`session.id`),d=l?Zn:c,f=Qz(er(`{{ menu "${e}" }}`,t,2,+!!l),Gn([{verb:yn,args:[u,o,d,s,`0`]}]),!1);return i.drops.push(...l?(()=>{let t=r.activeSegment.drawnAt(),c=Qf(i.palette,i.disclosure,t).plane,l=jB(a,e,`menu`);return MB(e,l,{key:s,stateVar:s},{kind:`own`,writes:[[o,Zn],[s,`0`]],onPick:n.closeOnPick},n.paged,a,mB(i,n.distribution,Wz(a,`{{ menu }}`),l.paletteOf,t,c),cB(i.palette,c,t))})():[]),f}const $B=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function eV(e,t){let n=t[t.length-1],r=$B(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:TT(r??{})}}function tV(e){return{menu:{fn:(t,...n)=>{let{displays:r,options:i}=eV(t,n);return QB(t,r,i,e)},argTypes:[`string`,`value`],arity:{kind:`variadic`},returnType:`T`}}}function nV(e){let{value:t,max:n,width:r,filled:i,empty:a,colourAt:o}=e,s=rV(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 G(t?i:a,{style:l===void 0?void 0:new H({color:l})}))}let l=G.fromFragments(c);return l.end=``,l.overflow=`ignore`,l}function rV(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 iV(e){let t={fn:(()=>{let t=CB(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:(()=>CB(e,`{{ tint }}`).tint.hex),argTypes:[],arity:{kind:`exact`},returnType:`string`},r={fn:((t,n)=>{let{palette:r}=CB(e,`{{ keptOn }}`),i=Xs(r,t),a=Xs(r,n),o=Ho(sc(i,B.TRUECOLOR),sc(a,B.TRUECOLOR)),s=Math.min(zf,Math.max(o,3));return(oc(i,e.drawnAt(),(e,t)=>Ho(e,t(a))>=s)??i).hex}),argTypes:[`string`,`string`],arity:{kind:`exact`},returnType:`string`},i=hC(()=>CB(e,`{{ color }} / {{ ramp }} / {{ gauge }}`).palette),a={fn:((e,t,n,r,a,o,...s)=>{let c=o===void 0?void 0:[o,...aV(s)];return nV({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 aV(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 oV(e){let t=[],n=[];for(let r of e){if(!r.contains(`
|
|
169
169
|
`)){n.push(r);continue}let e=r.split(`
|
|
170
|
-
`);n.push(e[0]);for(let r=1;r<e.length;r++)t.push(n),n=[e[r]]}return t.push(n),t}function ZB(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 QB(e,t){let n=[],r=[],i;for(let a of t)(a.band===`own`?n:r).push(a),i??=a.cells.find(t=>t.placement.id===e)?.placement.ground;return{drawing:i===void 0?null:{own:r.length===0?n:[],ground:i},deeper:r}}function $B(e){return{...e,cells:e.cells.map(Ez)}}function eV(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,...tV(e,r)]}function tV(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 nV(e,t){let n=(e,r)=>t(e)?e.kind===`segment`?[{cells:[{name:e.name,address:r,settings:e.settings}],band:`own`,place:`flow`}]:eV(e.direction,e.children.map((t,i)=>n(t,[...r,rV(e,i)]))):[];return n(e,[]).map(e=>[...e.cells])}function rV(e,t){return{index:t,count:e.children.length,distribution:e.distribution,axis:hh[e.direction]}}const iV={compile(e,t){return{kind:`container`,direction:e.direction,when:t.when,distribution:vf(e.distribution),children:e.children.map((e,n)=>t.compileChild(e,xh(t.path,n)))}},render(e,t){return t.gate.kind===`failed`&&t.gate.report(),eV(e.direction,e.children.map((n,r)=>t.renderChild(n,t.gate.kind===`shown`,rV(e,r))))}},aV={drop:e=>e.place,above:()=>`above`},oV={drop:(e,t)=>({lead:t(),stays:e}),above:e=>({lead:e.slice(0,1).flatMap(e=>e.cells),stays:e.slice(1)})},sV={compile(e,t){return{kind:`segment`,when:t.when,name:e.name,id:gh(e),settings:t.placementSettings(e),...e.opens!==void 0&&{opens:{open:t.parse(rr(e.opens.ref),`opens`),body:t.compileChild(e.opens.body,Sh(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,cV(e,t))};function cV(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=LC(t.scope,e.settings);if(t.gate.kind===`failed`)return lV(e,a,t,t.gate.message);try{if(!yz(i.when,a))return[];let n=oh(e.settings.theme,t.palette),o={id:e.id,effect:e.settings.effect,ground:CD(n)},s=e.opens!==void 0&&yz(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:aV[g.placement](e)})),v=XB(jz(l,m)).map((e,t)=>({cells:kz(e,{...h,lead:t===0?jz(u,m):[],trail:t===0?jz(d,m):[]}),band:`own`,place:`flow`})),y=f.map(e=>({cells:kz(jz([e],c.band),{...h,baseStyle:c.band}),band:`deeper`,place:`flow`})),b=(e,t,n)=>kz(jz([e],t),{...h,width:`auto`,baseStyle:t,padding:n}),x=_.findIndex(e=>e.band===`own`),{lead:S,stays:C}=g!==void 0&&x!==-1?oV[g.placement](v,()=>b(t.closeDisclosure(g.key),c.close,t.padding)):{lead:[],stays:v},ee=S.flatMap(e=>b(new G(` `.repeat(Tz(e).reduce((e,t)=>e+t.cellLength,0))),c.trigger,0)),te=(e,t)=>e.band===`own`?t===x?S:ee:[],ne=_.map((e,t)=>({cells:[...te(e,t),...e.cells],band:`deeper`,place:e.place})),re=[...C,...y];return t.perSegmentSink!==void 0&&t.perSegmentSink.set(e.id,[...re.flatMap(e=>e.cells),..._.flatMap(te)].flatMap(Tz)),[...re,...ne]}catch(n){return lV(e,a,t,n.message??String(n))}}function lV(e,t,n,r){n.onSegmentError?.(e.id,r);let i=r.replace(/\s*\n\s*/g,` `);return[{cells:kz([new G(`⚠ ${e.id}: ${i}`,{end:``})],{width:`auto`,justify:`left`,truncate:`right`,padding:0,placement:{id:e.id,effect:`bar`,ground:CD(n.palette)},lead:uV(e.lead,e,t,n),trail:uV(e.trail,e,t,n)}),band:`own`,place:`flow`}]}function uV(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 dV={container:iV,segment:sV};function fV(e){return dV[e]}function pV(e){if(`ttl`in e)return{kind:`ttl`,durationMs:Mw(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 mV(e,t){switch(Eh(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 hV(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:pV(n.cache),parse:mV(n.parse,n.default)});break;case`shell`:e.declareShell(t,n.command,{cwd:r,cache:pV(n.cache),parse:mV(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 gV(e,t){let n=C_.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 _V=(e,t,n,r,i)=>{let a=fI(t,dI(n,e.themeDefaults));return{variation:ff[r??Yp(void 0,null,a.variation)],shade:uf[i??Qp(void 0,null,a.shade)]}};function vV(e,t,n){let r=n.cwd,i={store:t.variableStore,compiled:new Map,chromeCols:jm({endcaps:`powerline`,charset:Wp}),width:80,padding:1,seamCols:Mm({endcaps:`powerline`,charset:Wp}),layout:()=>[],look:void 0},a=dB(t.drawnAt),o={action:i,activeSegment:a},s=Object.keys(e.styles),c=ng(e.presets),l=PA(e),u=PC({extraFuncs:{...Jz(i),...CB(i,a),...DB(i,a),...IB(i,a),...jB(i,a,t.now),...VB(i,a),...GB(o),...JB(a),styles:{fn:()=>s,argTypes:[],arity:{kind:`exact`}},presets:{fn:()=>c,argTypes:[],arity:{kind:`exact`}}},clock:t.now,drawnAt:t.drawnAt}),d=gV(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 Ta)n in e.variables&&h.set(t,n);for(let[t,n]of Object.entries(e.variables))n.kind===`state`&&!h.has(n.key)&&h.set(n.key,t);for(let[t,n]of Object.entries(e.segments))if(n.vars)for(let[e,r]of Object.entries(n.vars))r.kind===`state`&&!h.has(r.key)&&h.set(r.key,`${t}.${e}`);i.compiled=Fz(f,e.actions,h,l);let g=[];for(let[n,i]of Object.entries(e.variables))try{hV(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{hV(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=Nh(e.segments[t.name]),r=Object.create(null);for(let[e,i]of Object.entries(n))Object.defineProperty(r,e,{enumerable:!0,get:()=>zh(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 fV(e.kind).compile(e,n)},S=new Map;for(let t of c){let{node:n,path:r}=ag(e,t);S.set(t,x(n,r))}let C=new Map(xp.map(e=>[e,new Map])),ee=[[`globals`,e.globals],...Object.entries(e.presets).map(([e,t])=>[`presets.${e}.globals`,t.globals??{}])];for(let[e,t]of ee)for(let n of xp){let r=t[n];if(!Sp(r))continue;let i=`${e}.${n}`,a=C.get(n),o=a.get(r);a.set(r,o===void 0?{where:i,template:yV(f,i,r)}:{where:`${o.where}, ${i}`,template:o.template})}return{segments:_,roots:S,activeSegment:a,menuRuntime:o,globalExpressions:C,loadWarnings:g}}function yV(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 bV(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 xV(e,t,n,r){try{return t.template.evaluate(n).map(e=>e.plain).join(``)}catch(n){return r({kind:`rule`,slot:e,message:jp(t.where,e,`the rule failed — ${n instanceof Error?n.message:String(n)}`)}),Ap[e]}}function SV(e,t){return e.kind===`decided`?e.name:Ap[t]}function CV(e){return e.kind===`container`?e.children.flatMap(CV):[...e.name.startsWith(`edit.`)?[]:[e.id],...e.opens===void 0?[]:CV(e.opens.body)]}function wV(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(Kp(o.colorCompatibility));let{preset:m=eg}=c??{},h=og(e,m),g=c?.style??Dp(`none`,e.styles),_=c?.theme??fh(void 0,null,h.palette),v=_V(e,h,_,c?.variation,c?.shade),y=c?.effect??Ip(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(SV(_,`palette`),SV(g,`style`),SV(y,`effect`))),t.menuRuntime.action.chromeCols=jm(o),t.menuRuntime.action.padding=o.padding,t.menuRuntime.action.width=o.width,t.menuRuntime.action.seamCols=Mm(o);let x=FC(n),S=wp(_,e=>{let n=bV(t,`palette`,e);return dh(xV(`palette`,n,x,f),n.where,e=>f({kind:`rule`,slot:`palette`,message:e}))}),C=wp(g,n=>Dp(xV(`style`,bV(t,`style`,n),x,f),e.styles)),ee=wp(y,e=>Fp(xV(`effect`,bV(t,`effect`,e),x,f)));(S!==_||C!==g||ee!==y)&&r.applyInput(b(S.name,C.name,ee.name));let te=S.value,ne=ch(te,C.value);t.menuRuntime.action.look={basePalette:te,palette:ne,decor:v};let re=(c?.effects??new xm(``)).motion(ee.value,a,{transitions:c?.transitions??cm(void 0,null,h.transitions),source:{config:t,preset:m,revision:r.stateRevision(),width:o.width},returned:QB,hold:$B});l?.clear();let ie=n=>{let r=e.segments[n],i=t.segments[n];return r!==void 0&&i!==void 0?{seg:r,compiled:i}:void 0},ae=(e,n,i,a,o,s)=>{try{let c=r.drawnAt(),{tint:l,text:u,disclosure:d}=dp(i,a,c),f=fB(t.activeSegment,e.name,e.id,i,d,l,u),m=TD(f,c,o.bg,o.fg,n),h=()=>Qf(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 Xz(i,h().state,c)},get band(){return Xz(i,h().plane,c)},get close(){return $z(i,h().state,c)},disclosure:d},fragments:g,lead:v,trail:y,drops:f.drops,open:_}}finally{t.activeSegment.current=null}},w=(e,t,r)=>{let i=t?Sz(e.when,x):bz,a=i.kind===`failed`?{...i,report:()=>{let t=`when over ${CV(e).join(`, `)||`no placement`}`;f({kind:`when`,where:t,error:i.message,message:`${t}: ${i.message} — what it gates is hidden`})}}:i,s={scope:x,palette:ne,gate:a,padding:o.padding,region:r,perSegmentSink:l,onSegmentError:u,evaluateSegment:ae,lookupSegment:ie,renderChild:(e,t,n)=>w(e,t,lp(r,n)),renderBody:(e,t,n)=>w(e,a.kind===`shown`&&t,up(n)),closeDisclosure:e=>Yz(n,e),placed:re.placed};return fV(e.kind).render(e,s)},T=t.roots.get(m);if(T===void 0)throw Error(`Preset "${m}" has no compiled layout — registerDslConfig compiles one per declared preset and effectivePresetName collapses unknown names to "${eg}"; a miss here is merge/policy drift (have: ${[...t.roots.keys()].join(`, `)})`);let oe=e=>{let n=Sz(e.when,x);if(e.kind===`container`)return n.kind===`shown`;if(GA(e.name)===void 0)return!1;if(n.kind!==`shown`)return n.kind===`failed`;try{return yz(t.segments[e.name].when,LC(x,e.settings))}catch{return!0}};t.menuRuntime.action.layout=()=>nV(T,oe).map(e=>e.flatMap(({name:e,address:t,settings:n})=>{let r=GA(e);return r===void 0?[]:[{name:r,address:t,palette:oh(n.theme,ne)}]}));let E=ZB(w(T,!0,cp(v))).map(({line:e,row:t})=>{let n=Az(e.cells,o);return Im(n.map(e=>e.owner),o,re.row(t,n))}).join(`
|
|
171
|
-
`);re.drawn();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 E}function*
|
|
172
|
-
`)||null}function HV(e,t,n,r,i=()=>{}){let{layers:a,config:o,installed:s}=RF(t.layers,sI,{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??sI,l=a.find(e=>e.path===t.home)?.raw??{},u=new IV,d=new $w(u,o.globals.default_empty_value??``,r.gitService,r.sessionState),f;try{f=vV(o,d,{cwd:e}),n.push(...f.loadWarnings),YL(o),mj(o)}catch(e){throw d.dispose(),e}return{config:o,store:u,registry:d,compiled:f,neededInputPaths:tL(o),lastRenderCellsBySegment:new Map,authoredRoots:zV(c,l),fileHeldSettings:FL(l),unused:[...new Map(a.flatMap(e=>OV(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 UV(e,t,n,r){let i=EF(e,t,n),a={layers:i.kind===`chain`?i.layers:[],home:i.home,projectDir:e},o=[jF(e,t),kF(i)],s,c=null;try{s=HV(t,a,o,r,e=>{c=e})}catch(e){return e instanceof aT&&o.push(...e.warnings),{layers:a.layers,home:a.home,failedFile:c,warning:VV(o),state:null,error:e instanceof aT||e instanceof Error?e.message:String(e)}}return{layers:a.layers,home:a.home,warning:VV(o),state:s,error:null}}function WV(e,t,n){return HV(e,{layers:[],home:``,projectDir:t},[],n)}var GV=class{entries=new Map;deps;maxEntries;observers;constructor(e,t={}){this.deps=e,this.maxEntries=t.maxEntries??256,this.observers=t.observers??{}}getOrCreate(e,t,n){let r=RV(e,t,n),i=this.entries.get(r);if(i)return this.entries.delete(r),this.entries.set(r,i),i;let a=UV(e,t,n,this.deps);a.state!==null&&A(`info`,LV(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??WV(t,e,this.deps),watcher:null,watcherKey:null};if(this.entries.set(r,o),this.entries.size>this.maxEntries){let e=this.entries.entries().next().value;if(e!==void 0){let[t,n]=e;n.state.registry.dispose(),n.watcher?.release(),this.entries.delete(t)}}return this.refreshWatcher(o,a),this.observers.onReload?.(o),o}reload(e,t,n){this.reloadInto(this.getOrCreate(e,t,n))}reloadInto(e){let t=UV(e.projectDir,e.cwd,e.configFile,this.deps);e.lastWarning=t.warning,e.lastError=t.error,t.state!==null&&(A(`info`,LV(t.layers,t.state)),e.state.registry.dispose(),e.state=t.state),this.refreshWatcher(e,t),this.observers.onReload?.(e)}refreshWatcher(e,t){e.configLayers=t.layers,e.configHome=t.home,e.failedFile=t.error===null?null:t.failedFile;let n=BV(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){A(`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 KV=16384;var qV=class{startedAt=new Date;requestsTotal=0;requestsErrored=0;requestsTimedOut=0;inFlight=0;watchersOpened=0;watchersClosed=0;watchersEvicted=0;subprocessTotal=0;subprocessInFlight=0;subprocessCount=new Map;subprocessHistogram=new Map;subprocessHistogramRotator=new Map;rollingTimestamps=[];rollingHead=0;launchStats={onStart:e=>{this.subprocessTotal++,this.subprocessInFlight++,this.subprocessCount.set(e,(this.subprocessCount.get(e)??0)+1),this.recordRollingNow()},onEnd:(e,t)=>{this.subprocessInFlight=Math.max(0,this.subprocessInFlight-1),this.recordDuration(e,t)}};recordRollingNow(){let e=Date.now();if(this.rollingTimestamps.length<KV){this.rollingTimestamps.push(e);return}this.rollingTimestamps[this.rollingHead]=e,this.rollingHead=(this.rollingHead+1)%KV}recordDuration(e,t){let n=this.subprocessHistogram.get(e);if(n||(n=[],this.subprocessHistogram.set(e,n)),n.length<16){n.push(t);return}let r=(this.subprocessHistogramRotator.get(e)??0)%16;n[r]=t,this.subprocessHistogramRotator.set(e,r+1)}snapshotSubprocesses(){let e=Date.now()-6e4,t=0;for(let n of this.rollingTimestamps)n>=e&&t++;let n={};for(let[e,t]of this.subprocessCount)t>0&&(n[e]=t);let r={},i={};for(let[e,t]of this.subprocessHistogram){if(t.length===0)continue;let n=[...t].sort((e,t)=>e-t),a=Math.floor(n.length*.5),o=Math.min(n.length-1,Math.floor(n.length*.99)),s=n[a],c=n[o];s!==void 0&&(r[e]=s),c!==void 0&&(i[e]=c)}return{total:this.subprocessTotal,inFlight:this.subprocessInFlight,lastMinute:t,byCategory:n,p50DurationMs:r,p99DurationMs:i}}snapshot(e){let t=process.memoryUsage();return{pid:process.pid,version:Et,protocolVersion:3,startedAt:this.startedAt.toISOString(),uptimeSec:Math.floor((Date.now()-this.startedAt.getTime())/1e3),rssBytes:t.rss,heapUsedBytes:t.heapUsed,heapTotalBytes:t.heapTotal,externalBytes:t.external,arrayBuffersBytes:t.arrayBuffers,requests:{total:this.requestsTotal,errored:this.requestsErrored,timedOut:this.requestsTimedOut,inFlight:this.inFlight},gitCache:e.gitCache,usageCache:e.usageCache,renderCache:{size:e.renderCacheSize},effectCache:e.effectCache,watchers:{active:e.watchersActive,opened:this.watchersOpened,closed:this.watchersClosed,evicted:this.watchersEvicted},subprocesses:this.snapshotSubprocesses(),nextRestartReason:e.nextRestartReason??null,handlerProbes:e.handlerProbes}}};function JV(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 YV={load:()=>({}),save:()=>{},flush:()=>{}};var XV=class{sessions;storage;head=0;atom=(0,Vg.createAtom)(`SessionState`);constructor(e=YV,t=256){this.maxSessions=t,this.storage=e,this.sessions=new Map,this.hydrateFromStorage()}useStorage(e){this.storage=e,this.hydrateFromStorage()}hydrateFromStorage(){this.sessions=new Map(Object.entries(this.storage.load()).map(([e,t])=>[e,{values:new Map(Object.entries(t)),revision:++this.head}])),this.evictOldest(),this.persist()}get(e,t){this.atom.reportObserved();let n=this.sessions.get(e);return n?(this.touch(e,n),n.values.get(t)??null):null}revision(e){return this.atom.reportObserved(),this.sessions.get(e)?.revision??0}set(e,t,n){this.setBatch(e,[{key:t,value:n}])}setBatch(e,t){t.length!==0&&(0,Vg.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,Vg.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,Vg.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 ZV(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 QV=class{timer=null;pending=null;constructor(e,t=500,n=Ft){this.filePath=e,this.debounceMs=t,this.logger=n}load(){let e;try{e=r.readFileSync(this.filePath,`utf8`)}catch(e){let t=e.code;return t!==`ENOENT`&&this.logger(`warn`,`session-state read failed (${t}); starting empty`),{}}try{let t=JSON.parse(e);return ZV(t)?t:(this.logger(`warn`,`session-state load: unexpected shape, starting empty`),{})}catch{return this.logger(`warn`,`session-state load: corrupt JSON, starting empty`),{}}}save(e){this.pending=e,!this.timer&&(this.timer=setTimeout(()=>this.flush(),this.debounceMs),this.timer.unref())}flush(){if(this.timer&&=(clearTimeout(this.timer),null),this.pending===null)return;let e=this.pending;try{r.mkdirSync(l.dirname(this.filePath),{recursive:!0});let t=`${this.filePath}.tmp`;r.writeFileSync(t,JSON.stringify(e),{mode:384}),r.chmodSync(t,384),r.renameSync(t,this.filePath),this.pending=null}catch(e){this.logger(`warn`,`session-state save failed: ${e.message}`)}}};const $V={default_empty_value:`string`,default_separator:`string`,palette:`string`,style:`string`,effect:`string`,preset:`string`,endcaps:`string`,variation:`string`,shade:`string`,autoWrap:`boolean`,padding:`number`,charset:`string`,updateNotice:`boolean`,transitions:`boolean`,colorCompatibility:`string`,menuGlyph:`string`},eH=new Set([`1`,`true`]),tH=new Set([`0`,`false`,``]);function nH(e,t){let n=DH(e),r=n.scope===`segment-palette`?`string`:$V[n.field];if(r===`string`)return JSON.stringify(t);if(r===`number`){let n=Number(t);if(!Number.isFinite(n))throw Error(`persistValueText: "${e}" expects a number, got "${t}"`);return String(n)}if(eH.has(t))return`true`;if(tH.has(t))return`false`;throw Error(`persistValueText: "${e}" expects boolean-ish (1, 0, true, false), got "${t}"`)}function rH(e){try{return r.readFileSync(e,`utf8`)}catch(e){if(e.code===`ENOENT`)return null;throw e}}function iH(e,t,n){try{if(t===null){r.rmSync(e,{force:!0});return}r.mkdirSync(l.dirname(e),{recursive:!0}),Ie(e,t)}catch(t){let r=`config write failed (${e}): ${t.message}`;throw n(`error`,r),Error(r)}}function aH(e){return/^\s*$/.test(e)?null:wr(e)}function oH(e,t){return e!==null&&Er(e,t)!==void 0}function sH(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(sH),...i}}return e}function cH(e){if(!Kh(e))return sH(e);let{rows:t,...n}=e;return{rows:Object.fromEntries(Object.entries(t).map(([e,t])=>[e,sH(t)])),...n}}const lH=aI,uH=lH.segments,dH=lH.presets,fH=lH.root;function pH(e,t,n,r){if(!oH(e,t)&&n===void 0)throw new K(`cannot edit ${r}: neither the config file nor the bundled default declares ${t.join(`.`)}`)}function mH(e,t){let n=eD(t);return t.scope===`segment-palette`&&pH(e,[`segments`,t.segment],uH[t.segment],n.join(`.`)),n}function hH(e){return wr(Pr(e))}function gH(){return Object.entries(fH.rows).map(([e,t])=>{let n=sH(t);return{path:[`root`],fragment:hH({rows:{[e]:n}}),unit:{path:[`root`,`rows`,e],value:n}}})}function _H(e,t){let n=e===null?void 0:Er(e,t);return n===void 0?null:{path:t,fragment:n,unit:null}}function vH(e,t){if(t===void 0)return null;let n=cH(t);return{path:e,fragment:hH(n),unit:{path:e,value:n}}}function yH(e,t){let n=[`presets`,t],r=[...n,`root`],i=dH[t];pH(e,n,i,r.join(`.`));let a=_H(e,r)??vH(r,i?.root);return a!==null&&ti(a.fragment)?a:null}function bH(e,t){let n=ei(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 xH(e,t){return[...gH(),_H(e,[`root`]),yH(e,t)].filter(e=>e!==null).reduce(bH,new Map)}function SH(e,t,n){for(let{node:r,...i}of xH(e,t).values())if(ri(r,n))return i;throw new K(`${CH(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 CH(e,t){return yH(e,t)?.path??[`root`]}function wH(e,t){return t.scope===`preset-root`?CH(e,t.preset):eD(t)}function TH(e,{unit:t}){return t===null?e:Jr(e,t.path,Pr(t.value),Mr)}function EH(e){let t=$E(e);if(t===null)throw Error(`"${e}" is not a valid persist target`);return t}function DH(e){let t=EH(e);if(t.scope===`preset-root`)throw Error(`"${e}" names a layout, not a value`);return t}function OH(e,t,n,r,i){i(t,n,zH(t,r)),iH(t.path,r,e.logger),e.record(t.path,n,r)}function kH(e,t,n){let r=MH(e,t,n);if(r.length>0)throw new K(`refused: ${e.above.join(`, `)} sets ${r.join(`, `)} over ${e.path}, so this click would change nothing on the bar — edit it there`)}const AH=()=>{};function jH(e,t){try{return t()}catch(t){throw!(t instanceof K)||e.above.length===0?t:new K(`${t.message} — or it is declared by ${e.above.join(`, `)}, which the bar does not edit`)}}function MH(e,t,n){let r=NH(e,t);if(r===null)return[];let i=new Set(LH(IH(r),IH(n)));return LH(FH(e,r),FH(e,n)).filter(e=>!i.has(e))}function NH(e,t){try{return PH(e,t)}catch(e){if(e instanceof aT)return null;throw e}}function PH(e,t){return RF(t===null?e.above:[e.path,...e.above],sI,{entered:()=>{},warned:()=>{}},{projectDir:e.projectDir,cwd:e.cwd},n=>n===e.path&&t!==null?t:r.readFileSync(n,`utf8`))}function FH(e,t){let[n]=t.layers;return n?.path===e.path?n.config:t.base}function IH(e){return e.layers.at(-1)?.config??e.base}function LH(e,t,n=``){return!RH(e)||!RH(t)?JSON.stringify(e)===JSON.stringify(t)?[]:[n]:[...new Set([...Object.keys(e),...Object.keys(t)])].flatMap(r=>LH(e[r],t[r],n===``?r:`${n}.${r}`))}function RH(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function zH(e,t){try{return PH(e,t)}catch(e){throw e instanceof aT?new K(`refused: the config file would not load after this click — ${e.message}`):e}}function BH(e,t){let n=DH(t),r=aH(rH(e)??``),i=r===null?void 0:Er(r,eD(n));return i!==void 0&&`value`in i?i.value:void 0}function VH(e,t,n){HH(e,t,n,[])}function HH(e,t,n,r){let i=rH(t.path),a=n.reduce((e,[t,n])=>Jr(e,mH(aH(e),DH(t)),nH(t,n),Mr),i??``);OH(e,t,i,jH(t,()=>UH(a,t.path,r,e=>e)),kH)}function UH(e,t,n,r){return n.reduce((e,{preset:n,id:i,setting:a,value:o})=>{let s=r(e,n,i),c=SH(aH(s),n,i),l=si(TH(s,c),c.path,i,a,Pr(o));if(l===null)throw new K(`${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 WH(e,t,n){let r=aH(e),i=[`presets`,t,`root`];for(let[a,{path:o,unit:s,node:c}]of xH(r,t)){if(!ri(c,n))continue;if(i.every((e,t)=>o[t]===e))return e;let l=s===null?Or(e,c):Pr(s.value);if(a!==`#`)return Jr(e,[...i,`rows`,a],l,Mr);if(yH(r,t)!==null)throw new K(`cannot give preset "${t}" its own copy of ${o.join(`.`)}: it already stages rows of its own over that tree`);return Jr(e,i,l,Mr)}return e}function GH(e,t){return Xr(e,t,t[0]===`presets`&&t.length>2&&!lI(t[1])?2:0)}function KH(e,t,n){let r=n.map(EH),i=rH(t.path);if(i===null)return;let a=r.reduce((e,t)=>GH(e,wH(aH(e),t)),i);a!==i&&OH(e,t,i,a,AH)}function qH(e){let t=e===null?void 0:Er(e,[`presets`]);return t?.kind===`object`?t.entries.map(e=>e.key):[]}function JH(e,t){let n=new Set([...cI,...qH(e),...t.above.flatMap(e=>Object.keys(_r.default.parse(r.readFileSync(e,`utf8`)).presets??{}))].map(iT));return Array.from({length:n.size+1},(e,t)=>`custom-${t+1}`).find(e=>!n.has(iT(e)))}function YH(e,t,n,r,i,a){let o=rH(t.path),s=aH(o??``),c=JH(s,t),l=[`presets`,c],u=jH(t,()=>yH(s,n)),d=[...u===null?[]:[[[...l,`root`],u.unit===null?Or(o??``,u.fragment):Pr(u.unit.value)]],...Object.keys(r).length===0?[]:[[[...l,`globals`],Pr(r)]]],f=i.map(([e,t])=>{let n=QE(c,e);return[mH(s,DH(n)),nH(n,t)]}),p=[...d,...f].reduce((e,[t,n])=>Jr(e,t,n,Mr),Jr(o??``,l,`{}`,Mr));return OH(e,t,o,jH(t,()=>UH(p,t.path,a.map(e=>({...e,preset:c})),WH)),kH),c}function XH(e,t,n,r){let i=rH(t.path);OH(e,t,i,Jr(i??``,[`themeDefaults`,n],Pr(r),Mr),kH)}function ZH(e,t,n){if(lI(n))throw new K(`cannot delete preset "${n}": it is bundled — reset its settings instead`);let r=[`presets`,n],i=rH(t.path),a=aH(i??``);if(i===null||a===null||Er(a,r)===void 0)throw new K(`cannot delete preset "${n}": ${t.path} declares no ${r.join(`.`)} — the bar you clicked is stale; it reloads on the next render`);let o=Er(a,[`globals`,`preset`]);OH(e,t,i,[r,...o?.kind===`string`&&o.value===n?[[`globals`,`preset`]]:[]].reduce((e,t)=>GH(e,t),i),AH)}function QH(e,t,n,r){let i=EH(n);if(i.scope!==`preset-root`)throw Error(`"${n}" is not a "presets.<name>.root" target`);let a=rH(t.path),o=r.op===`remove`?r.target:r.anchor,s=jH(t,()=>SH(aH(a??``),i.preset,o)),c=TH(a??``,s),{after:l,placed:u}=$H(c,s.path,r,()=>{let e=zH(t,c).config;return ng(e.presets).map(t=>ag(e,t).node)});if(l===null)throw new K(`${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 OH(e,t,a,l,kH),u}function $H(e,t,n,r){switch(n.op){case`remove`:return{after:ai(e,t,n.target),placed:null};case`insert`:{let i=tj(n.segment,n.anchor,r());return{after:oi(e,t,i,n.anchor,n.relation),placed:i}}}}const eU={load:()=>({}),save:()=>{}},tU=new Set(xa.map(e=>e.sessionKey)),nU=e=>tU.has(e)||e.startsWith(dD),rU=8*1024*1024,iU={past:[],future:[]},aU=e=>e.kind===`session`?`session:${e.key}`:`file:${e.file}`;var oU=class{state=new Map;constructor(e,t,n=eU){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)??iU;return{undo:t.length,redo:n.length,sinceEdit:r?.net.length??0}}history(e){return this.state.get(e)??iU}begin(){let e=new Map,t=(t,n)=>{let r=e.get(t)??new Map,i=r.get(aU(n));r.set(aU(n),i===void 0?n:{...n,before:i.before}),e.set(t,r)},n=new Map;return{sessionState:JV(this.sessionState,e=>nU(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:mU(i,n),o=r.get(e),s=o===void 0?a:vU(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 K(`undo: nothing to undo`);return this.apply(e,n,`before`,`undo`,gU(t,n)),n}rewind(e){let t=this.history(e),{savepoint:n}=t;if(n===void 0)throw new K(`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(aU)),a=n.net.filter(e=>!i.has(aU(e))),o=lU(yU(_U(t,n),i));if(this.apply(e,a,`before`,`rewind`,{past:o,future:[],savepoint:{at:o.length,net:[],below:[]}}),r.length>0)throw new K(`rewind: ${r.map(xU).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 K(`redo: nothing to redo`);let a=[...n,i],o=lU(a);return this.apply(e,i,`after`,`redo`,{past:o,future:r.slice(0,-1),...dU(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(aU)),{past:n,future:i,savepoint:a}=this.history(e);throw this.put(e,{past:yU(n,t),future:yU(i,t),...a!==void 0&&{savepoint:{at:yU([...n,...[...i].reverse()].slice(0,a.at),t).length,net:a.net.filter(e=>!t.has(aU(e))),below:yU(a.below,t)}}}),new K(`${r}: ${o.map(xU).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):rH(t.file)}write(e,t,n){t.kind===`file`?iH(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||sU(n)>rU;){let[e,t]=n.entries().next().value;n.size>1?n.delete(e):t.past.length+t.future.length>0?n.set(e,cU(t)):(this.logger(`warn`,`settings-history: edit mode's changes for session ${e} exceed ${rU} bytes; cancel is no longer available`),n.delete(e))}this.storage.save(Object.fromEntries(n)),this.state=n}};function sU(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 cU({past:e,future:t,savepoint:n}){return e.length>0?{past:e.slice(1),future:t,...dU(n,1,[])}:{past:e,future:t.slice(1),...dU(n,0,[])}}function lU(e){return e.slice(-50)}const uU=e=>e===pD.member;function dU(e,t,n){return e===void 0?{}:{savepoint:{at:Math.max(0,e.at-t),net:fU(e.net,n),below:e.below}}}function fU(e,t){let n=new Map(e.map(e=>[aU(e),e]));for(let e of t){let t=n.get(aU(e));n.set(aU(e),t===void 0?e:{...t,after:e.after})}return[...n.values()].filter(e=>e.before!==e.after)}const pU=e=>e.map(e=>({...e,before:e.after,after:e.before}));function mU(e,t){let n=[...e.past,t],r=lU(n),{savepoint:i}=e,a=i===void 0?0:Math.max(0,i.at-e.past.length);return{past:r,future:[],...dU(i&&{at:Math.min(i.at,e.past.length),net:i.net,below:[...hU(e.future,a),...i.below]},n.length-r.length,t)}}function hU(e,t){let n=Math.min(t,e.length);return e.slice(e.length-n).reverse()}function gU(e,t){return{past:e.past.slice(0,-1),future:lU([...e.future,t]),...dU(e.savepoint,0,pU(t))}}function _U(e,t){let{past:n,future:r}=e,i=n.slice(0,t.at);return[...i,...hU(r,t.at-i.length),...t.below]}function vU(e,t){if(uU(t.after)&&!uU(t.before))return{...e,savepoint:{at:e.past.length,net:[],below:[]}};if(!uU(t.after)&&uU(t.before)){let{past:t,future:n}=e;return{past:t,future:n}}return e}function yU(e,t){return e.map(e=>e.filter(e=>!t.has(aU(e)))).filter(e=>e.length>0)}function bU(e){return e.map(xU).join(`, `)}function xU(e){return e.kind===`session`?`session setting "${e.key}"`:e.file}function SU(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 CU(e){return Array.isArray(e)&&e.every(e=>Array.isArray(e)&&e.every(SU))}function wU(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(SU)&&CU(t.below)}function TU(e){if(typeof e!=`object`||!e)return!1;let t=e;return CU(t.past)&&CU(t.future)&&(t.savepoint===void 0||wU(t.savepoint))}function EU(e,t){let n=e=>e.kind===`file`||nU(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 DU(e,t){return{load:()=>{let n;try{n=r.readFileSync(e,`utf8`)}catch(e){let n=e.code;return n!==`ENOENT`&&t(`warn`,`settings-history read failed (${n}); starting empty`),{}}try{let e=JSON.parse(n);if(typeof e==`object`&&e&&!Array.isArray(e)&&Object.values(e).every(TU)){let n=new Set,r=Object.fromEntries(Object.entries(e).map(([e,t])=>[e,EU(t,n)]));return n.size>0&&t(`warn`,`settings-history load: dropped the changes to ${[...n].map(e=>`"${e}"`).join(`, `)}, no longer a setting`),r}}catch{}return t(`warn`,`settings-history load: unexpected shape, starting empty`),{}},save:n=>{try{r.mkdirSync(l.dirname(e),{recursive:!0}),Ie(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 OU=e=>!nU(e)&&!CO(e)&&e!==`update.dismissed`;var kU=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:JV(e,OU,(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 K(`back: nothing to go back to${o>0?` (${o} step(s) over a view since gone, discarded)`:``}`);return(0,Vg.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 AU=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function jU(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(!AU(r))return n(`is not an object`);for(let[e,t]of Object.entries(r)){if(!AU(t))return n(`holds ${JSON.stringify(e)} as something other than its sightings`);for(let[e,r]of Object.entries(t))if(!JD.includes(r))return n(`marks ${JSON.stringify(e)} ${JSON.stringify(r)}, not ${JD.join(` or `)}`)}return{kind:`ok`,value:r}}function MU(e,t,n,r){return{...e,[t]:{...e[t],[n]:r}}}function NU(e=l.join(Re(),`doctor-marks.json`)){let t=()=>{let t;try{t=r.readFileSync(e,`utf8`)}catch(t){return t.code===`ENOENT`?{kind:`ok`,value:{}}:{kind:`failed`,reason:`${e}: ${t.message}`}}return jU(t,e)};return{read:t,record:(n,i,a)=>{let o=t();if(o.kind===`failed`)throw Error(`doctor: the mark book could not be read: ${o.reason}`);r.mkdirSync(l.dirname(e),{recursive:!0}),Ie(e,`${JSON.stringify(MU(o.value,n,i,a),null,2)}\n`)}}}var PU=class extends Error{constructor(e){super(`the doctor looked at ${e} less than a second ago — click again`),this.name=`DoctorBusy`}};
|
|
170
|
+
`);n.push(e[0]);for(let r=1;r<e.length;r++)t.push(n),n=[e[r]]}return t.push(n),t}function sV(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 cV(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 lV(e){return{...e,cells:e.cells.map(Iz)}}function uV(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,...dV(e,r)]}function dV(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 fV(e,t){let n=(e,r)=>t(e)?e.kind===`segment`?[{cells:[{name:e.name,address:r,settings:e.settings}],band:`own`,place:`flow`}]:uV(e.direction,e.children.map((t,i)=>n(t,[...r,pV(e,i)]))):[];return n(e,[]).map(e=>[...e.cells])}function pV(e,t){return{index:t,count:e.children.length,distribution:e.distribution,axis:hh[e.direction]}}const mV={compile(e,t){return{kind:`container`,direction:e.direction,when:t.when,distribution:vf(e.distribution),children:e.children.map((e,n)=>t.compileChild(e,xh(t.path,n)))}},render(e,t){return t.gate.kind===`failed`&&t.gate.report(),uV(e.direction,e.children.map((n,r)=>t.renderChild(n,t.gate.kind===`shown`,pV(e,r))))}},hV={drop:e=>e.place,above:()=>`above`},gV={drop:(e,t)=>({lead:t(),stays:e}),above:e=>({lead:e.slice(0,1).flatMap(e=>e.cells),stays:e.slice(1)})},_V={compile(e,t){return{kind:`segment`,when:t.when,name:e.name,id:gh(e),settings:t.placementSettings(e),...e.opens!==void 0&&{opens:{open:t.parse(rr(e.opens.ref),`opens`),body:t.compileChild(e.opens.body,Sh(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,vV(e,t))};function vV(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=LC(t.scope,e.settings);if(t.gate.kind===`failed`)return yV(e,a,t,t.gate.message);try{if(!kz(i.when,a))return[];let n=oh(e.settings.theme,t.palette),o={id:e.id,effect:e.settings.effect,ground:CD(n)},s=e.opens!==void 0&&kz(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:hV[g.placement](e)})),v=oV(Vz(l,m)).map((e,t)=>({cells:zz(e,{...h,lead:t===0?Vz(u,m):[],trail:t===0?Vz(d,m):[]}),band:`own`,place:`flow`})),y=f.map(e=>({cells:zz(Vz([e],c.band),{...h,baseStyle:c.band}),band:`deeper`,place:`flow`})),b=(e,t,n)=>zz(Vz([e],t),{...h,width:`auto`,baseStyle:t,padding:n}),x=_.findIndex(e=>e.band===`own`),{lead:S,stays:C}=g!==void 0&&x!==-1?gV[g.placement](v,()=>b(t.closeDisclosure(g.key),c.close,t.padding)):{lead:[],stays:v},ee=S.flatMap(e=>b(new G(` `.repeat(Fz(e).reduce((e,t)=>e+t.cellLength,0))),c.trigger,0)),te=(e,t)=>e.band===`own`?t===x?S:ee:[],ne=_.map((e,t)=>({cells:[...te(e,t),...e.cells],band:`deeper`,place:e.place})),re=[...C,...y];return t.perSegmentSink!==void 0&&t.perSegmentSink.set(e.id,[...re.flatMap(e=>e.cells),..._.flatMap(te)].flatMap(Fz)),[...re,...ne]}catch(n){return yV(e,a,t,n.message??String(n))}}function yV(e,t,n,r){n.onSegmentError?.(e.id,r);let i=r.replace(/\s*\n\s*/g,` `);return[{cells:zz([new G(`⚠ ${e.id}: ${i}`,{end:``})],{width:`auto`,justify:`left`,truncate:`right`,padding:0,placement:{id:e.id,effect:`bar`,ground:CD(n.palette)},lead:bV(e.lead,e,t,n),trail:bV(e.trail,e,t,n)}),band:`own`,place:`flow`}]}function bV(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 xV={container:mV,segment:_V};function SV(e){return xV[e]}function CV(e){if(`ttl`in e)return{kind:`ttl`,durationMs:Mw(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 wV(e,t){switch(Eh(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 TV(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:CV(n.cache),parse:wV(n.parse,n.default)});break;case`shell`:e.declareShell(t,n.command,{cwd:r,cache:CV(n.cache),parse:wV(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 EV(e,t){let n=C_.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 DV=(e,t,n,r,i)=>{let a=SI(t,xI(n,e.themeDefaults));return{variation:ff[r??Yp(void 0,null,a.variation)],shade:uf[i??Qp(void 0,null,a.shade)]}};function OV(e,t,n){let r=n.cwd,i={store:t.variableStore,compiled:new Map,chromeCols:jm({endcaps:`powerline`,charset:Wp}),width:80,padding:1,seamCols:Mm({endcaps:`powerline`,charset:Wp}),layout:()=>[],look:void 0},a=xB(t.drawnAt),o={action:i,activeSegment:a},s=Object.keys(e.styles),c=ng(e.presets),l=WA(e),u=PC({extraFuncs:{...iB(i),...NB(i,a),...LB(i,a),...KB(i,a),...VB(i,a,t.now),...ZB(i,a),...tV(o),...iV(a),styles:{fn:()=>s,argTypes:[],arity:{kind:`exact`}},presets:{fn:()=>c,argTypes:[],arity:{kind:`exact`}}},clock:t.now,drawnAt:t.drawnAt}),d=EV(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 Ta)n in e.variables&&h.set(t,n);for(let[t,n]of Object.entries(e.variables))n.kind===`state`&&!h.has(n.key)&&h.set(n.key,t);for(let[t,n]of Object.entries(e.segments))if(n.vars)for(let[e,r]of Object.entries(n.vars))r.kind===`state`&&!h.has(r.key)&&h.set(r.key,`${t}.${e}`);i.compiled=Gz(f,e.actions,h,l);let g=[];for(let[n,i]of Object.entries(e.variables))try{TV(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{TV(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=Nh(e.segments[t.name]),r=Object.create(null);for(let[e,i]of Object.entries(n))Object.defineProperty(r,e,{enumerable:!0,get:()=>zh(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 SV(e.kind).compile(e,n)},S=new Map;for(let t of c){let{node:n,path:r}=ag(e,t);S.set(t,x(n,r))}let C=new Map(xp.map(e=>[e,new Map])),ee=[[`globals`,e.globals],...Object.entries(e.presets).map(([e,t])=>[`presets.${e}.globals`,t.globals??{}])];for(let[e,t]of ee)for(let n of xp){let r=t[n];if(!Sp(r))continue;let i=`${e}.${n}`,a=C.get(n),o=a.get(r);a.set(r,o===void 0?{where:i,template:kV(f,i,r)}:{where:`${o.where}, ${i}`,template:o.template})}return{segments:_,roots:S,activeSegment:a,menuRuntime:o,globalExpressions:C,loadWarnings:g}}function kV(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 AV(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 jV(e,t,n,r){try{return t.template.evaluate(n).map(e=>e.plain).join(``)}catch(n){return r({kind:`rule`,slot:e,message:jp(t.where,e,`the rule failed — ${n instanceof Error?n.message:String(n)}`)}),Ap[e]}}function MV(e,t){return e.kind===`decided`?e.name:Ap[t]}function NV(e){return e.kind===`container`?e.children.flatMap(NV):[...e.name.startsWith(`edit.`)?[]:[e.id],...e.opens===void 0?[]:NV(e.opens.body)]}function PV(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(Kp(o.colorCompatibility));let{preset:m=eg}=c??{},h=og(e,m),g=c?.style??Dp(`none`,e.styles),_=c?.theme??fh(void 0,null,h.palette),v=DV(e,h,_,c?.variation,c?.shade),y=c?.effect??Ip(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(MV(_,`palette`),MV(g,`style`),MV(y,`effect`))),t.menuRuntime.action.chromeCols=jm(o),t.menuRuntime.action.padding=o.padding,t.menuRuntime.action.width=o.width,t.menuRuntime.action.seamCols=Mm(o);let x=FC(n),S=wp(_,e=>{let n=AV(t,`palette`,e);return dh(jV(`palette`,n,x,f),n.where,e=>f({kind:`rule`,slot:`palette`,message:e}))}),C=wp(g,n=>Dp(jV(`style`,AV(t,`style`,n),x,f),e.styles)),ee=wp(y,e=>Fp(jV(`effect`,AV(t,`effect`,e),x,f)));(S!==_||C!==g||ee!==y)&&r.applyInput(b(S.name,C.name,ee.name));let te=S.value,ne=ch(te,C.value);t.menuRuntime.action.look={basePalette:te,palette:ne,decor:v};let re=(c?.effects??new xm(``)).motion(ee.value,a,{transitions:c?.transitions??cm(void 0,null,h.transitions),source:{config:t,preset:m,revision:r.stateRevision(),width:o.width},returned:cV,hold:lV});l?.clear();let ie=n=>{let r=e.segments[n],i=t.segments[n];return r!==void 0&&i!==void 0?{seg:r,compiled:i}:void 0},ae=(e,n,i,a,o,s)=>{try{let c=r.drawnAt(),{tint:l,text:u,disclosure:d}=dp(i,a,c),f=SB(t.activeSegment,e.name,e.id,i,d,l,u),m=TD(f,c,o.bg,o.fg,n),h=()=>Qf(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 oB(i,h().state,c)},get band(){return oB(i,h().plane,c)},get close(){return lB(i,h().state,c)},disclosure:d},fragments:g,lead:v,trail:y,drops:f.drops,open:_}}finally{t.activeSegment.current=null}},w=(e,t,r)=>{let i=t?Mz(e.when,x):Az,a=i.kind===`failed`?{...i,report:()=>{let t=`when over ${NV(e).join(`, `)||`no placement`}`;f({kind:`when`,where:t,error:i.message,message:`${t}: ${i.message} — what it gates is hidden`})}}:i,s={scope:x,palette:ne,gate:a,padding:o.padding,region:r,perSegmentSink:l,onSegmentError:u,evaluateSegment:ae,lookupSegment:ie,renderChild:(e,t,n)=>w(e,t,lp(r,n)),renderBody:(e,t,n)=>w(e,a.kind===`shown`&&t,up(n)),closeDisclosure:e=>aB(n,e),placed:re.placed};return SV(e.kind).render(e,s)},T=t.roots.get(m);if(T===void 0)throw Error(`Preset "${m}" has no compiled layout — registerDslConfig compiles one per declared preset and effectivePresetName collapses unknown names to "${eg}"; a miss here is merge/policy drift (have: ${[...t.roots.keys()].join(`, `)})`);let oe=e=>{let n=Mz(e.when,x);if(e.kind===`container`)return n.kind===`shown`;if(tj(e.name)===void 0)return!1;if(n.kind!==`shown`)return n.kind===`failed`;try{return kz(t.segments[e.name].when,LC(x,e.settings))}catch{return!0}};t.menuRuntime.action.layout=()=>fV(T,oe).map(e=>e.flatMap(({name:e,address:t,settings:n})=>{let r=tj(e);return r===void 0?[]:[{name:r,address:t,palette:oh(n.theme,ne)}]}));let E=sV(w(T,!0,cp(v))).map(({line:e,row:t})=>{let n=Bz(e.cells,o);return Im(n.map(e=>e.owner),o,re.row(t,n))}).join(`
|
|
171
|
+
`);re.drawn();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 E}function*FV(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*IV(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 ng(e.presets)){for(let n of bh(ag(e,t).node))n.when!==void 0&&(yield n.when);let n=og(e,t);for(let e of xp){let t=n[e];Sp(t)&&(yield t)}}for(let[,t]of FV(e))t.kind===`template`&&(yield t.template),Oh(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 LV(e,t){return e===t||t.startsWith(`${e}.`)||e.startsWith(`${t}.`)}function RV(e,t){let n=new Set,r=new Set,i=new Set;for(let e of IV(t)){for(let r of Dg(e,t.helpers).keys())n.add(r);for(let{name:n}of jg(e,t.helpers))r.add(n);for(let n of Mg(e,t.helpers))i.add(n)}for(let[,e]of FV(t))if(Oh(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 ng(t.presets))for(let n of bh(ag(t,e).node))n.kind===`segment`&&s.add(n.name);let c=(e,t)=>[...n].some(t=>LV(t,e))||t.kind===`state`&&o.has(t.key),l=e=>[...e].filter(e=>!mT(e)),u=(e,t,n)=>l(t).filter(e=>!n(e)).map(t=>({kind:e,name:t})),d=new Map(FV(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 zV=class{kind=`box`;cell;lastChangedAt;constructor(e,t,n){this.name=e,this.type=t,GV(e,t,n,`initial value`),this.cell=Vg.observable.box(n,{deep:!1}),this.lastChangedAt=Date.now()}read(){return this.cell.get()}set(e){GV(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}},BV=class{kind=`computed`;cell;constructor(e,t,n){this.name=e,this.type=t,this.cell=(0,Vg.computed)(()=>{let e=n();return GV(this.name,this.type,e,`computed result`),e},{keepAlive:!0})}read(){return this.cell.get()}lastUpdatedMs(){return null}},VV=class{kind=`document`;cell;lastChangedAt;constructor(e,t){this.name=e,this.cell=Vg.observable.box(WV(t),{deep:!1}),this.lastChangedAt=Date.now()}read(){return this.cell.get()}set(e){let t=WV(e);UV(this.cell.get(),t)||(this.cell.set(t),this.lastChangedAt=Date.now())}lastUpdatedMs(){return this.lastChangedAt}};function HV(e){return JSON.stringify(e)}function UV(e,t){return HV(e)===HV(t)}function WV(e){return e.kind===`ok`?{kind:`ok`,value:Hg(e.value)}:e}function GV(e,t,n,r){let i=Ug(n);if(i!==t)throw TypeError(`Variable "${e}": ${r} type ${i} does not match declared type ${t}`)}var KV=class{nodes=Vg.observable.map(void 0,{deep:!1});defineBox(e,t,n){this.declare(e,new zV(e,t,n))}defineDocument(e,t){this.declare(e,new VV(e,t))}defineComputed(e,t,n){let r=e=>this.read(e);this.declare(e,new BV(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,Vg.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,Vg.runInAction)(()=>n.set(t))}runInAction(e){(0,Vg.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 HV(t.read());try{return String(t.read())}catch(e){return`failed:${e instanceof Error?e.message:String(e)}`}}getNode(e){let t=this.requireNode(e);return t.kind===`document`?{name:t.name,kind:t.kind,read:()=>t.read(),lastUpdatedMs:()=>t.lastUpdatedMs()}:{name:t.name,type:t.type,kind:t.kind,read:()=>t.read(),lastUpdatedMs:()=>t.lastUpdatedMs()}}names(){return[...this.nodes.keys()]}requireNode(e){let t=this.nodes.get(e);if(!t)throw ReferenceError(`Unknown variable "${e}"`);return t}requireVar(e){let t=this.requireNode(e);if(t.kind===`document`)throw TypeError(`Variable "${e}" is a document; read its fields by path (.${e}.<field>)`);return t}declare(e,t){if(this.nodes.has(e))throw Error(`Variable "${e}" is already declared`);(0,Vg.runInAction)(()=>this.nodes.set(e,t))}};function qV(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=cF(e),r=t===void 0?void 0:n.variables[uF(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 JV(e,t,n){return e+`\0`+t+`\0`+(n??``)}function YV(e,t){return new Set(ng(e.presets).filter(n=>ag(e,n).path===`root`?t.root!==void 0:t.presets?.[n]?.root!==void 0))}function XV(e,t){let n=new Map,{roots:r,loaded:i,dropped:a,unreached:o}=e.state.plugins;for(let t of[...PF(e.projectDir,e.cwd,e.configFile),...r,...i,...[...a,...o].map(e=>e.path)]){let{dir:e,name:r}=Lg(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}=Lg(l.join(e,`_`));i&&r===`_`&&n.set(t,null)}return{files:t,dirs:[...n.entries()].sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>t===null?{path:e}:{path:e,filenames:[...t].sort()})}}function ZV(e){return e.filter(Boolean).join(`
|
|
172
|
+
`)||null}function QV(e,t,n,r,i=()=>{}){let{layers:a,config:o,installed:s}=JF(t.layers,_I,{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??_I,l=a.find(e=>e.path===t.home)?.raw??{},u=new KV,d=new $w(u,o.globals.default_empty_value??``,r.gitService,r.sessionState),f;try{f=OV(o,d,{cwd:e}),n.push(...f.loadWarnings),aR(o),wj(o)}catch(e){throw d.dispose(),e}return{config:o,store:u,registry:d,compiled:f,neededInputPaths:dL(o),lastRenderCellsBySegment:new Map,authoredRoots:YV(c,l),fileHeldSettings:GL(l),unused:[...new Map(a.flatMap(e=>RV(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 $V(e,t,n,r){let i=IF(e,t,n),a={layers:i.kind===`chain`?i.layers:[],home:i.home,projectDir:e},o=[VF(e,t),zF(i)],s,c=null;try{s=QV(t,a,o,r,e=>{c=e})}catch(e){return e instanceof aT&&o.push(...e.warnings),{layers:a.layers,home:a.home,failedFile:c,warning:ZV(o),state:null,error:e instanceof aT||e instanceof Error?e.message:String(e)}}return{layers:a.layers,home:a.home,warning:ZV(o),state:s,error:null}}function eH(e,t,n){return QV(e,{layers:[],home:``,projectDir:t},[],n)}var tH=class{entries=new Map;deps;maxEntries;observers;constructor(e,t={}){this.deps=e,this.maxEntries=t.maxEntries??256,this.observers=t.observers??{}}getOrCreate(e,t,n){let r=JV(e,t,n),i=this.entries.get(r);if(i)return this.entries.delete(r),this.entries.set(r,i),i;let a=$V(e,t,n,this.deps);a.state!==null&&A(`info`,qV(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??eH(t,e,this.deps),watcher:null,watcherKey:null};if(this.entries.set(r,o),this.entries.size>this.maxEntries){let e=this.entries.entries().next().value;if(e!==void 0){let[t,n]=e;n.state.registry.dispose(),n.watcher?.release(),this.entries.delete(t)}}return this.refreshWatcher(o,a),this.observers.onReload?.(o),o}reload(e,t,n){this.reloadInto(this.getOrCreate(e,t,n))}reloadInto(e){let t=$V(e.projectDir,e.cwd,e.configFile,this.deps);e.lastWarning=t.warning,e.lastError=t.error,t.state!==null&&(A(`info`,qV(t.layers,t.state)),e.state.registry.dispose(),e.state=t.state),this.refreshWatcher(e,t),this.observers.onReload?.(e)}refreshWatcher(e,t){e.configLayers=t.layers,e.configHome=t.home,e.failedFile=t.error===null?null:t.failedFile;let n=XV(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){A(`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 nH=16384;var rH=class{startedAt=new Date;requestsTotal=0;requestsErrored=0;requestsTimedOut=0;inFlight=0;watchersOpened=0;watchersClosed=0;watchersEvicted=0;subprocessTotal=0;subprocessInFlight=0;subprocessCount=new Map;subprocessHistogram=new Map;subprocessHistogramRotator=new Map;rollingTimestamps=[];rollingHead=0;launchStats={onStart:e=>{this.subprocessTotal++,this.subprocessInFlight++,this.subprocessCount.set(e,(this.subprocessCount.get(e)??0)+1),this.recordRollingNow()},onEnd:(e,t)=>{this.subprocessInFlight=Math.max(0,this.subprocessInFlight-1),this.recordDuration(e,t)}};recordRollingNow(){let e=Date.now();if(this.rollingTimestamps.length<nH){this.rollingTimestamps.push(e);return}this.rollingTimestamps[this.rollingHead]=e,this.rollingHead=(this.rollingHead+1)%nH}recordDuration(e,t){let n=this.subprocessHistogram.get(e);if(n||(n=[],this.subprocessHistogram.set(e,n)),n.length<16){n.push(t);return}let r=(this.subprocessHistogramRotator.get(e)??0)%16;n[r]=t,this.subprocessHistogramRotator.set(e,r+1)}snapshotSubprocesses(){let e=Date.now()-6e4,t=0;for(let n of this.rollingTimestamps)n>=e&&t++;let n={};for(let[e,t]of this.subprocessCount)t>0&&(n[e]=t);let r={},i={};for(let[e,t]of this.subprocessHistogram){if(t.length===0)continue;let n=[...t].sort((e,t)=>e-t),a=Math.floor(n.length*.5),o=Math.min(n.length-1,Math.floor(n.length*.99)),s=n[a],c=n[o];s!==void 0&&(r[e]=s),c!==void 0&&(i[e]=c)}return{total:this.subprocessTotal,inFlight:this.subprocessInFlight,lastMinute:t,byCategory:n,p50DurationMs:r,p99DurationMs:i}}snapshot(e){let t=process.memoryUsage();return{pid:process.pid,version:Et,protocolVersion:3,startedAt:this.startedAt.toISOString(),uptimeSec:Math.floor((Date.now()-this.startedAt.getTime())/1e3),rssBytes:t.rss,heapUsedBytes:t.heapUsed,heapTotalBytes:t.heapTotal,externalBytes:t.external,arrayBuffersBytes:t.arrayBuffers,requests:{total:this.requestsTotal,errored:this.requestsErrored,timedOut:this.requestsTimedOut,inFlight:this.inFlight},gitCache:e.gitCache,usageCache:e.usageCache,renderCache:{size:e.renderCacheSize},effectCache:e.effectCache,watchers:{active:e.watchersActive,opened:this.watchersOpened,closed:this.watchersClosed,evicted:this.watchersEvicted},subprocesses:this.snapshotSubprocesses(),nextRestartReason:e.nextRestartReason??null,handlerProbes:e.handlerProbes}}};function iH(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 aH={load:()=>({}),save:()=>{},flush:()=>{}};var oH=class{sessions;storage;head=0;atom=(0,Vg.createAtom)(`SessionState`);constructor(e=aH,t=256){this.maxSessions=t,this.storage=e,this.sessions=new Map,this.hydrateFromStorage()}useStorage(e){this.storage=e,this.hydrateFromStorage()}hydrateFromStorage(){this.sessions=new Map(Object.entries(this.storage.load()).map(([e,t])=>[e,{values:new Map(Object.entries(t)),revision:++this.head}])),this.evictOldest(),this.persist()}get(e,t){this.atom.reportObserved();let n=this.sessions.get(e);return n?(this.touch(e,n),n.values.get(t)??null):null}revision(e){return this.atom.reportObserved(),this.sessions.get(e)?.revision??0}set(e,t,n){this.setBatch(e,[{key:t,value:n}])}setBatch(e,t){t.length!==0&&(0,Vg.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,Vg.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,Vg.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 sH(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 cH=class{timer=null;pending=null;constructor(e,t=500,n=Ft){this.filePath=e,this.debounceMs=t,this.logger=n}load(){let e;try{e=r.readFileSync(this.filePath,`utf8`)}catch(e){let t=e.code;return t!==`ENOENT`&&this.logger(`warn`,`session-state read failed (${t}); starting empty`),{}}try{let t=JSON.parse(e);return sH(t)?t:(this.logger(`warn`,`session-state load: unexpected shape, starting empty`),{})}catch{return this.logger(`warn`,`session-state load: corrupt JSON, starting empty`),{}}}save(e){this.pending=e,!this.timer&&(this.timer=setTimeout(()=>this.flush(),this.debounceMs),this.timer.unref())}flush(){if(this.timer&&=(clearTimeout(this.timer),null),this.pending===null)return;let e=this.pending;try{r.mkdirSync(l.dirname(this.filePath),{recursive:!0});let t=`${this.filePath}.tmp`;r.writeFileSync(t,JSON.stringify(e),{mode:384}),r.chmodSync(t,384),r.renameSync(t,this.filePath),this.pending=null}catch(e){this.logger(`warn`,`session-state save failed: ${e.message}`)}}};const lH={default_empty_value:`string`,default_separator:`string`,palette:`string`,style:`string`,effect:`string`,preset:`string`,endcaps:`string`,variation:`string`,shade:`string`,autoWrap:`boolean`,padding:`number`,charset:`string`,updateNotice:`boolean`,transitions:`boolean`,colorCompatibility:`string`,menuGlyph:`string`},uH=new Set([`1`,`true`]),dH=new Set([`0`,`false`,``]);function fH(e,t){let n=LH(e),r=n.scope===`segment-palette`?`string`:lH[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(uH.has(t))return`true`;if(dH.has(t))return`false`;throw Error(`persistValueText: "${e}" expects boolean-ish (1, 0, true, false), got "${t}"`)}function pH(e){try{return r.readFileSync(e,`utf8`)}catch(e){if(e.code===`ENOENT`)return null;throw e}}function mH(e,t,n){try{if(t===null){r.rmSync(e,{force:!0});return}r.mkdirSync(l.dirname(e),{recursive:!0}),Ie(e,t)}catch(t){let r=`config write failed (${e}): ${t.message}`;throw n(`error`,r),Error(r)}}function hH(e){return/^\s*$/.test(e)?null:wr(e)}function gH(e,t){return e!==null&&Er(e,t)!==void 0}function _H(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(_H),...i}}return e}function vH(e){if(!Kh(e))return _H(e);let{rows:t,...n}=e;return{rows:Object.fromEntries(Object.entries(t).map(([e,t])=>[e,_H(t)])),...n}}const yH=hI,bH=yH.segments,xH=yH.presets,SH=yH.root;function CH(e,t,n,r){if(!gH(e,t)&&n===void 0)throw new K(`cannot edit ${r}: neither the config file nor the bundled default declares ${t.join(`.`)}`)}function wH(e,t){let n=eD(t);return t.scope===`segment-palette`&&CH(e,[`segments`,t.segment],bH[t.segment],n.join(`.`)),n}function TH(e){return wr(Pr(e))}function EH(){return Object.entries(SH.rows).map(([e,t])=>{let n=_H(t);return{path:[`root`],fragment:TH({rows:{[e]:n}}),unit:{path:[`root`,`rows`,e],value:n}}})}function DH(e,t){let n=e===null?void 0:Er(e,t);return n===void 0?null:{path:t,fragment:n,unit:null}}function OH(e,t){if(t===void 0)return null;let n=vH(t);return{path:e,fragment:TH(n),unit:{path:e,value:n}}}function kH(e,t){let n=[`presets`,t],r=[...n,`root`],i=xH[t];CH(e,n,i,r.join(`.`));let a=DH(e,r)??OH(r,i?.root);return a!==null&&ti(a.fragment)?a:null}function AH(e,t){let n=ei(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 jH(e,t){return[...EH(),DH(e,[`root`]),kH(e,t)].filter(e=>e!==null).reduce(AH,new Map)}function MH(e,t,n){for(let{node:r,...i}of jH(e,t).values())if(ri(r,n))return i;throw new K(`${NH(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 NH(e,t){return kH(e,t)?.path??[`root`]}function PH(e,t){return t.scope===`preset-root`?NH(e,t.preset):eD(t)}function FH(e,{unit:t}){return t===null?e:Jr(e,t.path,Pr(t.value),Mr)}function IH(e){let t=$E(e);if(t===null)throw Error(`"${e}" is not a valid persist target`);return t}function LH(e){let t=IH(e);if(t.scope===`preset-root`)throw Error(`"${e}" names a layout, not a value`);return t}function RH(e,t,n,r,i){i(t,n,YH(t,r)),mH(t.path,r,e.logger),e.record(t.path,n,r)}function zH(e,t,n){let r=HH(e,t,n);if(r.length>0)throw new K(`refused: ${e.above.join(`, `)} sets ${r.join(`, `)} over ${e.path}, so this click would change nothing on the bar — edit it there`)}const BH=()=>{};function VH(e,t){try{return t()}catch(t){throw!(t instanceof K)||e.above.length===0?t:new K(`${t.message} — or it is declared by ${e.above.join(`, `)}, which the bar does not edit`)}}function HH(e,t,n){let r=UH(e,t);if(r===null)return[];let i=new Set(qH(KH(r),KH(n)));return qH(GH(e,r),GH(e,n)).filter(e=>!i.has(e))}function UH(e,t){try{return WH(e,t)}catch(e){if(e instanceof aT)return null;throw e}}function WH(e,t){return JF(t===null?e.above:[e.path,...e.above],_I,{entered:()=>{},warned:()=>{}},{projectDir:e.projectDir,cwd:e.cwd},n=>n===e.path&&t!==null?t:r.readFileSync(n,`utf8`))}function GH(e,t){let[n]=t.layers;return n?.path===e.path?n.config:t.base}function KH(e){return e.layers.at(-1)?.config??e.base}function qH(e,t,n=``){return!JH(e)||!JH(t)?JSON.stringify(e)===JSON.stringify(t)?[]:[n]:[...new Set([...Object.keys(e),...Object.keys(t)])].flatMap(r=>qH(e[r],t[r],n===``?r:`${n}.${r}`))}function JH(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function YH(e,t){try{return WH(e,t)}catch(e){throw e instanceof aT?new K(`refused: the config file would not load after this click — ${e.message}`):e}}function XH(e,t){let n=LH(t),r=hH(pH(e)??``),i=r===null?void 0:Er(r,eD(n));return i!==void 0&&`value`in i?i.value:void 0}function ZH(e,t,n){QH(e,t,n,[])}function QH(e,t,n,r){let i=pH(t.path),a=n.reduce((e,[t,n])=>Jr(e,wH(hH(e),LH(t)),fH(t,n),Mr),i??``);RH(e,t,i,VH(t,()=>$H(a,t.path,r,e=>e)),zH)}function $H(e,t,n,r){return n.reduce((e,{preset:n,id:i,setting:a,value:o})=>{let s=r(e,n,i),c=MH(hH(s),n,i),l=si(FH(s,c),c.path,i,a,Pr(o));if(l===null)throw new K(`${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 eU(e,t,n){let r=hH(e),i=[`presets`,t,`root`];for(let[a,{path:o,unit:s,node:c}]of jH(r,t)){if(!ri(c,n))continue;if(i.every((e,t)=>o[t]===e))return e;let l=s===null?Or(e,c):Pr(s.value);if(a!==`#`)return Jr(e,[...i,`rows`,a],l,Mr);if(kH(r,t)!==null)throw new K(`cannot give preset "${t}" its own copy of ${o.join(`.`)}: it already stages rows of its own over that tree`);return Jr(e,i,l,Mr)}return e}function tU(e,t){return Xr(e,t,t[0]===`presets`&&t.length>2&&!yI(t[1])?2:0)}function nU(e,t,n){let r=n.map(IH),i=pH(t.path);if(i===null)return;let a=r.reduce((e,t)=>tU(e,PH(hH(e),t)),i);a!==i&&RH(e,t,i,a,BH)}function rU(e){let t=e===null?void 0:Er(e,[`presets`]);return t?.kind===`object`?t.entries.map(e=>e.key):[]}function iU(e,t){let n=new Set([...vI,...rU(e),...t.above.flatMap(e=>Object.keys(_r.default.parse(r.readFileSync(e,`utf8`)).presets??{}))].map(iT));return Array.from({length:n.size+1},(e,t)=>`custom-${t+1}`).find(e=>!n.has(iT(e)))}function aU(e,t,n,r,i,a){let o=pH(t.path),s=hH(o??``),c=iU(s,t),l=[`presets`,c],u=VH(t,()=>kH(s,n)),d=[...u===null?[]:[[[...l,`root`],u.unit===null?Or(o??``,u.fragment):Pr(u.unit.value)]],...Object.keys(r).length===0?[]:[[[...l,`globals`],Pr(r)]]],f=i.map(([e,t])=>{let n=QE(c,e);return[wH(s,LH(n)),fH(n,t)]}),p=[...d,...f].reduce((e,[t,n])=>Jr(e,t,n,Mr),Jr(o??``,l,`{}`,Mr));return RH(e,t,o,VH(t,()=>$H(p,t.path,a.map(e=>({...e,preset:c})),eU)),zH),c}function oU(e,t,n,r){let i=pH(t.path);RH(e,t,i,Jr(i??``,[`themeDefaults`,n],Pr(r),Mr),zH)}function sU(e,t,n){if(yI(n))throw new K(`cannot delete preset "${n}": it is bundled — reset its settings instead`);let r=[`presets`,n],i=pH(t.path),a=hH(i??``);if(i===null||a===null||Er(a,r)===void 0)throw new K(`cannot delete preset "${n}": ${t.path} declares no ${r.join(`.`)} — the bar you clicked is stale; it reloads on the next render`);let o=Er(a,[`globals`,`preset`]);RH(e,t,i,[r,...o?.kind===`string`&&o.value===n?[[`globals`,`preset`]]:[]].reduce((e,t)=>tU(e,t),i),BH)}function cU(e,t,n,r){let i=IH(n);if(i.scope!==`preset-root`)throw Error(`"${n}" is not a "presets.<name>.root" target`);let a=pH(t.path),o=r.op===`remove`?r.target:r.anchor,s=VH(t,()=>MH(hH(a??``),i.preset,o)),c=FH(a??``,s),{after:l,placed:u}=lU(c,s.path,r,()=>{let e=YH(t,c).config;return ng(e.presets).map(t=>ag(e,t).node)});if(l===null)throw new K(`${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 RH(e,t,a,l,zH),u}function lU(e,t,n,r){switch(n.op){case`remove`:return{after:ai(e,t,n.target),placed:null};case`insert`:{let i=dj(n.segment,n.anchor,r());return{after:oi(e,t,i,n.anchor,n.relation),placed:i}}}}const uU={load:()=>({}),save:()=>{}},dU=new Set(xa.map(e=>e.sessionKey)),fU=e=>dU.has(e)||e.startsWith(dD),pU=8*1024*1024,mU={past:[],future:[]},hU=e=>e.kind===`session`?`session:${e.key}`:`file:${e.file}`;var gU=class{state=new Map;constructor(e,t,n=uU){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)??mU;return{undo:t.length,redo:n.length,sinceEdit:r?.net.length??0}}history(e){return this.state.get(e)??mU}begin(){let e=new Map,t=(t,n)=>{let r=e.get(t)??new Map,i=r.get(hU(n));r.set(hU(n),i===void 0?n:{...n,before:i.before}),e.set(t,r)},n=new Map;return{sessionState:iH(this.sessionState,e=>fU(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:wU(i,n),o=r.get(e),s=o===void 0?a:OU(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 K(`undo: nothing to undo`);return this.apply(e,n,`before`,`undo`,EU(t,n)),n}rewind(e){let t=this.history(e),{savepoint:n}=t;if(n===void 0)throw new K(`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(hU)),a=n.net.filter(e=>!i.has(hU(e))),o=yU(kU(DU(t,n),i));if(this.apply(e,a,`before`,`rewind`,{past:o,future:[],savepoint:{at:o.length,net:[],below:[]}}),r.length>0)throw new K(`rewind: ${r.map(jU).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 K(`redo: nothing to redo`);let a=[...n,i],o=yU(a);return this.apply(e,i,`after`,`redo`,{past:o,future:r.slice(0,-1),...xU(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(hU)),{past:n,future:i,savepoint:a}=this.history(e);throw this.put(e,{past:kU(n,t),future:kU(i,t),...a!==void 0&&{savepoint:{at:kU([...n,...[...i].reverse()].slice(0,a.at),t).length,net:a.net.filter(e=>!t.has(hU(e))),below:kU(a.below,t)}}}),new K(`${r}: ${o.map(jU).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):pH(t.file)}write(e,t,n){t.kind===`file`?mH(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||_U(n)>pU;){let[e,t]=n.entries().next().value;n.size>1?n.delete(e):t.past.length+t.future.length>0?n.set(e,vU(t)):(this.logger(`warn`,`settings-history: edit mode's changes for session ${e} exceed ${pU} bytes; cancel is no longer available`),n.delete(e))}this.storage.save(Object.fromEntries(n)),this.state=n}};function _U(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 vU({past:e,future:t,savepoint:n}){return e.length>0?{past:e.slice(1),future:t,...xU(n,1,[])}:{past:e,future:t.slice(1),...xU(n,0,[])}}function yU(e){return e.slice(-50)}const bU=e=>e===pD.member;function xU(e,t,n){return e===void 0?{}:{savepoint:{at:Math.max(0,e.at-t),net:SU(e.net,n),below:e.below}}}function SU(e,t){let n=new Map(e.map(e=>[hU(e),e]));for(let e of t){let t=n.get(hU(e));n.set(hU(e),t===void 0?e:{...t,after:e.after})}return[...n.values()].filter(e=>e.before!==e.after)}const CU=e=>e.map(e=>({...e,before:e.after,after:e.before}));function wU(e,t){let n=[...e.past,t],r=yU(n),{savepoint:i}=e,a=i===void 0?0:Math.max(0,i.at-e.past.length);return{past:r,future:[],...xU(i&&{at:Math.min(i.at,e.past.length),net:i.net,below:[...TU(e.future,a),...i.below]},n.length-r.length,t)}}function TU(e,t){let n=Math.min(t,e.length);return e.slice(e.length-n).reverse()}function EU(e,t){return{past:e.past.slice(0,-1),future:yU([...e.future,t]),...xU(e.savepoint,0,CU(t))}}function DU(e,t){let{past:n,future:r}=e,i=n.slice(0,t.at);return[...i,...TU(r,t.at-i.length),...t.below]}function OU(e,t){if(bU(t.after)&&!bU(t.before))return{...e,savepoint:{at:e.past.length,net:[],below:[]}};if(!bU(t.after)&&bU(t.before)){let{past:t,future:n}=e;return{past:t,future:n}}return e}function kU(e,t){return e.map(e=>e.filter(e=>!t.has(hU(e)))).filter(e=>e.length>0)}function AU(e){return e.map(jU).join(`, `)}function jU(e){return e.kind===`session`?`session setting "${e.key}"`:e.file}function MU(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 NU(e){return Array.isArray(e)&&e.every(e=>Array.isArray(e)&&e.every(MU))}function PU(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(MU)&&NU(t.below)}function FU(e){if(typeof e!=`object`||!e)return!1;let t=e;return NU(t.past)&&NU(t.future)&&(t.savepoint===void 0||PU(t.savepoint))}function IU(e,t){let n=e=>e.kind===`file`||fU(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 LU(e,t){return{load:()=>{let n;try{n=r.readFileSync(e,`utf8`)}catch(e){let n=e.code;return n!==`ENOENT`&&t(`warn`,`settings-history read failed (${n}); starting empty`),{}}try{let e=JSON.parse(n);if(typeof e==`object`&&e&&!Array.isArray(e)&&Object.values(e).every(FU)){let n=new Set,r=Object.fromEntries(Object.entries(e).map(([e,t])=>[e,IU(t,n)]));return n.size>0&&t(`warn`,`settings-history load: dropped the changes to ${[...n].map(e=>`"${e}"`).join(`, `)}, no longer a setting`),r}}catch{}return t(`warn`,`settings-history load: unexpected shape, starting empty`),{}},save:n=>{try{r.mkdirSync(l.dirname(e),{recursive:!0}),Ie(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 RU=e=>!fU(e)&&!NO(e)&&e!==`update.dismissed`;var zU=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:iH(e,RU,(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 K(`back: nothing to go back to${o>0?` (${o} step(s) over a view since gone, discarded)`:``}`);return(0,Vg.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 BU=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function VU(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(!BU(r))return n(`is not an object`);for(let[e,t]of Object.entries(r)){if(!BU(t))return n(`holds ${JSON.stringify(e)} as something other than its sightings`);for(let[e,r]of Object.entries(t))if(!$D.includes(r))return n(`marks ${JSON.stringify(e)} ${JSON.stringify(r)}, not ${$D.join(` or `)}`)}return{kind:`ok`,value:r}}function HU(e,t,n,r){return{...e,[t]:{...e[t],[n]:r}}}function UU(e=l.join(Re(),`doctor-marks.json`)){let t=()=>{let t;try{t=r.readFileSync(e,`utf8`)}catch(t){return t.code===`ENOENT`?{kind:`ok`,value:{}}:{kind:`failed`,reason:`${e}: ${t.message}`}}return VU(t,e)};return{read:t,record:(n,i,a)=>{let o=t();if(o.kind===`failed`)throw Error(`doctor: the mark book could not be read: ${o.reason}`);r.mkdirSync(l.dirname(e),{recursive:!0}),Ie(e,`${JSON.stringify(HU(o.value,n,i,a),null,2)}\n`)}}}var WU=class extends Error{constructor(e){super(`the doctor looked at ${e} less than a second ago — click again`),this.name=`DoctorBusy`}};
|
|
173
173
|
/*!
|
|
174
174
|
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
175
175
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -197,9 +197,9 @@ print(json.dumps({"ceiling": "off" if ceiling == math.inf else ceiling,
|
|
|
197
197
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
198
198
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
199
199
|
*/
|
|
200
|
-
function
|
|
200
|
+
function GU(e,t){let n=e.slice(0,t).split(/\r?\n/);return[n.length,n.pop().length+1]}function KU(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+=`
|
|
201
201
|
`,e===t&&(i+=` `.repeat(a+n+2),i+=`^
|
|
202
|
-
`))}return i}var $=class e extends Error{line;column;codeblock;constructor(e,t){let[n,r]=
|
|
202
|
+
`))}return i}var $=class e extends Error{line;column;codeblock;constructor(e,t){let[n,r]=GU(t.toml,t.ptr),i=KU(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})}};
|
|
203
203
|
/*!
|
|
204
204
|
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
205
205
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -227,7 +227,7 @@ function FU(e,t){let n=e.slice(0,t).split(/\r?\n/);return[n.length,n.pop().lengt
|
|
|
227
227
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
228
228
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
229
229
|
*/
|
|
230
|
-
function
|
|
230
|
+
function qU(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+=`
|
|
231
231
|
`: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)}
|
|
232
232
|
/*!
|
|
233
233
|
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
@@ -256,7 +256,7 @@ function LU(e){let t=e.p,n=e.s.charCodeAt(e.p++),r=n,i=n===39,a=n===e.s.charCode
|
|
|
256
256
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
257
257
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
258
258
|
*/
|
|
259
|
-
let
|
|
259
|
+
let JU=/^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i;var YU=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(JU);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}};
|
|
260
260
|
/*!
|
|
261
261
|
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
262
262
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -284,7 +284,7 @@ let RU=/^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[
|
|
|
284
284
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
285
285
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
286
286
|
*/
|
|
287
|
-
function
|
|
287
|
+
function XU(e,t=10){return t===16?e>47&&e<58||e>64&&e<71||e>96&&e<103:e>47&&e<48+t}function ZU(e,t){return e===32||e===9||e===10||e===13||t&&(e===t||e===44)||e===35}function QU(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?lW(e):cW(e);return e.d++,t}return r===34||r===39?qU(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?$U(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?nW(e,r,t):e.s.charCodeAt(e.p+2)===58?rW(e,r,t):$U(e,e.p,r,0,t)}function $U(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||ZU(a=e.s.charCodeAt(e.p),i))return e.bi===!0?0n:0;if(!r){if(a===120)return eW(e,t,16,i);if(a===98)return eW(e,t,2,i);if(a===111)return eW(e,t,8,i)}a===46?o=2:a===101||a===69?o=4:$.x(`illegal leading zero`,e,t)}else XU(a)||$.x(`invalid value`,e,t);for(;++e.p<e.s.length&&(a=e.s.charCodeAt(e.p),!ZU(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:XU(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):tW(e,c,10,t)}function eW(e,t,n,r){let i,a=1;for(;++e.p<e.s.length&&(i=e.s.charCodeAt(e.p),!ZU(i,r));)i===95?(a&1&&$.x(`illegal underscore`,e),a=3):XU(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(`_`,``)),tW(e,o,n,t)}function tW(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 nW(e,t,n){let r=e.p++,i;if(!XU(t)||!XU(e.s.charCodeAt(e.p++))||!XU(e.s.charCodeAt(e.p++))||!XU(e.s.charCodeAt(e.p++)))return $U(e,e.p=r,t,0,n);if(e.p+=5,XU(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,!XU(e.s.charCodeAt(e.p+1))))&&t!==84&&t!==116)return iW(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(;XU(e.s.charCodeAt(++e.p)););if(t=e.s.charCodeAt(e.p)){if(t===90||t===122)return iW(e,e.s.slice(r,++e.p),1,i,r,`[+00:00]`);if(t===43||t===45)return iW(e,e.s.slice(r,e.p+=6),1,i,r,!e.ld&&`[`+e.s.slice(e.p-6,e.p)+`]`)}return iW(e,e.s.slice(r,e.p),2,i,r)}function rW(e,t,n){let r=e.p;if(!XU(t)||!XU(e.s.charCodeAt(++e.p)))return $U(e,--e.p,t,0,n);if(e.s.charCodeAt(e.p+=4)===58&&(e.p+=3),e.s.charCodeAt(e.p)===46)for(;XU(e.s.charCodeAt(++e.p)););return iW(e,e.s.slice(r,e.p),4,!1,r)}function iW(e,t,n,r,i,a){if(e.ld){let a=new YU(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)}}
|
|
288
288
|
/*!
|
|
289
289
|
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
290
290
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -312,7 +312,7 @@ function BU(e,t=10){return t===16?e>47&&e<58||e>64&&e<71||e>96&&e<103:e>47&&e<48
|
|
|
312
312
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
313
313
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
314
314
|
*/
|
|
315
|
-
function
|
|
315
|
+
function aW(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 oW(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;aW(e)}}
|
|
316
316
|
/*!
|
|
317
317
|
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
318
318
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -340,7 +340,7 @@ function YU(e){for(;e.p<e.s.length;e.p++){let t=e.s.charCodeAt(e.p);if(t===10)br
|
|
|
340
340
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
341
341
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
342
342
|
*/
|
|
343
|
-
function
|
|
343
|
+
function sW(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(qU(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 cW(e){let t=e.p++,n=Object.create(null),r=new Set,i;for(;e.p<e.s.length;){if(oW(e),(i=e.s.charCodeAt(e.p))===125)return e.p++,n;let t,a=n,o=!1,s=e.p,c=sW(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),oW(e,!0,!0);let l=QU(e,125);if(a&&typeof(a[t]=l)==`object`&&r.add(l),oW(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 lW(e){let t=e.p++,n=[],r;for(;e.p<e.s.length;){if(oW(e),(r=e.s.charCodeAt(e.p))===93)return e.p++,n;if(n.push(QU(e,93)),oW(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)}
|
|
344
344
|
/*!
|
|
345
345
|
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
346
346
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -368,7 +368,7 @@ function ZU(e,t=61){let n,r=0,i=[],a,o=e.s.charCodeAt(n=e.p);do if(o===t)return
|
|
|
368
368
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
369
369
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
370
370
|
*/
|
|
371
|
-
function
|
|
371
|
+
function uW(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 dW(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 fW(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++,oW(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=sW(n,93);t&&(e.charCodeAt(n.p)!==93&&$.x(`expected end of table array declaration`,n),n.p++);let u=uW(n,l,r,i,t?2:1);u?(c=u[2],s=u[1]):(dW(n,u,a),o=!0)}else{a=n.p;let e=uW(n,sW(n),s,c,0);!e&&!o&&dW(n,e,a),oW(n,!0,!0);let t=QU(n,void 0);e&&!o&&(e[1][e[0]]=t)}oW(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),oW(n)}return r}``.isWellFormed;
|
|
372
372
|
/*!
|
|
373
373
|
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
374
374
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -396,7 +396,7 @@ function eW(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
|
|
|
396
396
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
397
397
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
398
398
|
*/
|
|
399
|
-
const
|
|
399
|
+
const pW=e=>e.codePointAt(0).toString(16).toUpperCase(),mW=String.raw`
|
|
400
400
|
ObjC.import("AppKit");
|
|
401
401
|
ObjC.import("CoreText");
|
|
402
402
|
function lacksOf(font, points) {
|
|
@@ -443,34 +443,34 @@ function run(argv) {
|
|
|
443
443
|
: iterm(argv[1], points),
|
|
444
444
|
);
|
|
445
445
|
}
|
|
446
|
-
`;function
|
|
447
|
-
`).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
|
|
448
|
-
`,`:family=${
|
|
449
|
-
`)){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(
|
|
450
|
-
`)};return e.error===null?{...t,kind:`loaded`,unused:e.unused}:{...t,kind:`failed`,error:e.error}}function
|
|
451
|
-
`);return}t.stdout.write(
|
|
446
|
+
`;function hW(e){let t=Ne({bin:`osascript`,args:[`-l`,`JavaScript`,`-e`,mW,...e],timeoutMs:3e3,category:`doctor.font`});if(!t.ok){if(t.reason===`rate-limited`)throw new WU(`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 gW=e=>e.map(e=>String.fromCodePoint(parseInt(e,16))),_W=e=>[...e].map(pW).join(`,`);function vW(e,t){let n=hW([`font`,e.kind,e.name,_W(t)]);if(n.kind===`failed`)return n;let{lacks:r}=n.value;return{kind:`ok`,value:{font:e.name,lacks:r===null?null:gW(r)}}}function yW(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=>!VD(t,e));return{kind:`ok`,value:{font:e.font,from:n,lacks:r}}}const bW=e=>e.kind===`ok`&&e.value.lacks!==null&&e.value.lacks.length===0;function xW(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=>yW(e,n));if(t!==null)return r[0];let i=r.find(e=>!bW(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 SW(e,t,n){if(process.platform!==`darwin`)return{kind:`failed`,reason:`iTerm2 runs only on macOS`};let r=t.ITERM_PROFILE??null,i=hW([`iterm`,r??``,_W(n)]);return i.kind===`failed`?i:xW(i.value.profiles.map(e=>({...e,lacks:e.lacks===null?null:gW(e.lacks)})),r,e)}function CW(e,t){let n=e.split(`
|
|
447
|
+
`).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 wW=e=>e.replace(/[\\:,=-]/g,`\\$&`);function TW(e,t){let n=Ne({bin:`fc-match`,args:[`--sort`,`--format`,`%{family[0]} %{charset}
|
|
448
|
+
`,`:family=${wW(e)}`],timeoutMs:3e3,category:`doctor.font`});if(!n.ok){if(n.reason===`rate-limited`)throw new WU(`the font`);return{kind:`failed`,reason:`fc-match failed (${n.error??`${n.reason}: ${n.stderr.trim()}`})`}}return CW(n.stdout,t)}function EW(e,t){return process.platform===`darwin`?vW(e,t):TW(e.name,t)}function DW(e,t){let n=t||l.join(e,`.config`);return[l.join(n,`alacritty`,`alacritty.toml`),l.join(n,`alacritty.toml`),l.join(e,`.config`,`alacritty`,`alacritty.toml`),l.join(e,`.alacritty.toml`)]}function OW(e){return e===`darwin`?`Menlo`:`monospace`}const kW=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function AW(e){let t=kW(e.font)?e.font:{},n=kW(t.normal)?t.normal:{},r=(kW(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 jW(e,t,n){let i;try{i=r.readFileSync(e,`utf8`)}catch(t){return{kind:`failed`,reason:`cannot read ${e}: ${t.message}`}}let a;try{a=fW(i)}catch(t){return{kind:`failed`,reason:`cannot parse ${e}: ${t.message}`}}let o=AW(a);if(o.family!==null)return{kind:`ok`,value:{family:o.family,from:e}};if(n===5)return{kind:`ok`,value:null};let s=null;for(let i of o.imports){let a=i.startsWith(`~/`)?l.join(t,i.slice(2)):l.resolve(l.dirname(e),i);if(!r.existsSync(a))continue;let o=jW(a,t,n+1);if(o.kind===`failed`)return o;s=o.value??s}return{kind:`ok`,value:s}}function MW(e,t){let n=h.homedir(),i=DW(n,e.XDG_CONFIG_HOME).find(e=>r.existsSync(e)),a=i===void 0?{kind:`ok`,value:null}:jW(i,n,0);if(a.kind===`failed`)return a;let o=a.value?.family??OW(process.platform),s=a.value?.from??(i===void 0?`Alacritty's default, no config file`:`Alacritty's default, ${i} sets none`),c=EW({kind:`family`,name:o},t);if(c.kind===`failed`)return c;let{font:l,lacks:u}=c.value;return{kind:`ok`,value:{font:l,from:l===o?s:`${s}; ${o} as fontconfig matches it`,lacks:u}}}const NW={iterm2:SW,alacritty:(e,t,n)=>MW(t,n)};function PW(e,t,n){return NW[e.name](e.version,t,n)}function FW(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 IW(e=l.join(Re(),`doctor-clicked-terminals.json`)){let t=()=>{let t;try{t=r.readFileSync(e,`utf8`)}catch(t){return t.code===`ENOENT`?{kind:`ok`,value:[]}:{kind:`failed`,reason:`${e}: ${t.message}`}}return FW(t,e)};return{read:t,record:n=>{let i=t();if(i.kind===`failed`)throw Error(`doctor: the clicked terminals could not be read: ${i.reason}`);i.value.includes(n)||(r.mkdirSync(l.dirname(e),{recursive:!0}),Ie(e,`${JSON.stringify([...i.value,n],null,2)}\n`))}}}function LW(e){let t=e.replace(/\n$/,``);if(t===` `)return{kind:`ok`,value:null};let n=t.split(` `),[r,i,a,o]=n;return n.length!==4||!/^[1-9]\d*$/.test(o)?{kind:`failed`,reason:`tmux answered ${JSON.stringify(e)}, not the four fields asked for`}:{kind:`ok`,value:{features:r.split(`,`).filter(e=>e!==``),termtype:i,termname:a,pid:Number(o)}}}const RW=/^(sshd|mosh-server)\b/;function zW(e,t){let n=new Map;for(let t of e.split(`
|
|
449
|
+
`)){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(RW.test(e.name))return{kind:`ok`,value:!0};if(r.has(e.ppid))break;r.add(e.ppid)}return{kind:`ok`,value:!1}}function BW(e){let t=Ne({bin:`ps`,args:[`-A`,`-o`,`pid=,ppid=,comm=`],timeoutMs:2e3,category:`doctor.process`});if(!t.ok){if(t.reason===`rate-limited`)throw new WU(`the processes`);return{kind:`failed`,reason:`ps failed (${t.error??`${t.reason}: ${t.stderr.trim()}`})`}}return zW(t.stdout,e)}function VW(e){let t=Sz(e,`doctor.tmux`,[`display`,`-p`,`-t`,e.pane,`#{client_termfeatures} #{client_termtype} #{client_termname} #{client_pid}`]);if(t.kind===`rate-limited`)throw new WU(`tmux`);return t.kind===`failed`?{kind:`failed`,reason:t.reason}:LW(t.stdout)}function HW(e){return{probeTmux:VW,remoteLogin:BW,fontInUse:PW,loadConfig:e,marks:UU(),clicked:IW()}}function UW(e){let t={layers:e.layers,warnings:e.warning===null?[]:e.warning.split(`
|
|
450
|
+
`)};return e.error===null?{...t,kind:`loaded`,unused:e.unused}:{...t,kind:`failed`,error:e.error}}function WW(e){let{env:t,statusLine:n}=pi(e);if(t!==void 0&&!mi(t))throw Error(`cannot read ${e}: \`env\` is not an object`);return{path:e,env:t??{},statusLine:n===void 0?{kind:`absent`}:mi(n)?{kind:`present`,refreshInterval:n.refreshInterval}:{kind:`not-an-object`,value:n}}}function GW(e,t){return t===void 0?{kind:`unreported`}:t===null?{kind:`outside`}:{kind:`inside`,hint:t,client:e.probeTmux(t)}}function KW(e,t){switch(e.kind){case`unreported`:return{kind:`unreported`};case`outside`:return t===void 0?{kind:`unreported`}:{kind:`seen`,identified:JD(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:qD(t),tmuxClient:t}}}}function qW(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(LD(s))return{kind:`bundling`,name:s,version:c};if(!RD(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 JW(e){return{kind:`arrived`,handler:e,bar:Et}}function YW(e,t,n){let r=new Map;for(let i of bh(ag(e,t).node)){if(i.kind!==`segment`)continue;let t=Nh(e.segments[i.name])[jh],a=zh(i,jh,t,e=>n(e.key));a===`bar`||a===`none`||r.set(i.drafts?.effect?.id??gh(i),a)}return[...r].map(([e,t])=>({placement:e,effect:t}))}function XW(e,t,n,r){let i=e.loadConfig(n),a=XI(i.config,r,()=>!1),o=GW(e,t.tmux),s=KW(o,t.terminalEnv),c=[...new Set([...Fm(a),...Pm(JSON.stringify(i.config))])].join(``);return{tmux:o,terminal:s,nerdFont:c===``?{kind:`none`}:{kind:`glyphs`,glyphs:c,terminal:qW(e,s,t,c)},marks:e.marks.read(),clicked:e.clicked.read(),config:UW(i),effect:a.effect,placementEffects:YW(i.config,a.preset,r),transitions:a.transitions,claudeSettings:WW(ui(li(t.claudeConfigDir)))}}function ZW(e,t){let n=t.claudeSettings.path;switch(e.kind){case`claude-settings`:{let i=Jr(fi(n),e.path,JSON.stringify(e.value),Nr);return r.mkdirSync(l.dirname(n),{recursive:!0}),Ie(n,i),{...t,claudeSettings:WW(n)}}default:return e.kind}}const QW={connectMs:200,budgetMs:500};async function $W(e){let n=e.includes(`--json`),r=await eG();if(r.kind!==`ok`&&(t.stderr.write(`daemon-stats: ${Tt(r)}\n`),t.exit(1)),n){t.stdout.write(JSON.stringify(r.value,null,2)+`
|
|
451
|
+
`);return}t.stdout.write(iG(r.value))}function eG(){return yt({kind:`stats`},QW,e=>`stats`in e?e.stats:void 0)}function tG(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/1024/1024).toFixed(1)}MB`}function nG(e,t){let n=e+t;return n===0?`n/a`:`${(e/n*100).toFixed(1)}%`}function rG(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 iG(e){let t=[];t.push(`cc-candybar daemon stats`),t.push(``),t.push(`process`),t.push(` pid ${e.pid}`),t.push(` version ${e.version}`),t.push(` protocol ${e.protocolVersion}`),t.push(` startedAt ${e.startedAt}`),t.push(` uptime ${rG(e.uptimeSec)}`),t.push(` rss ${tG(e.rssBytes)}`),t.push(` heapUsed ${tG(e.heapUsedBytes)}`),t.push(` heapTotal ${tG(e.heapTotalBytes)}`),t.push(` external ${tG(e.externalBytes)}`),t.push(` arrayBuffers ${tG(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 ${nG(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 ${nG(e.usageCache.hits,e.usageCache.misses)} (${e.usageCache.hits} / ${e.usageCache.hits+e.usageCache.misses})`),t.push(` sweeps ${e.usageCache.sweeps}`),t.push(``),t.push(`renderCache`),t.push(` size ${e.renderCache.size}`),t.push(``),t.push(`effectCache`),t.push(` sessions ${e.effectCache.sessions}`),t.push(` effects ${e.effectCache.effects}`),t.push(``),t.push(`watchers`),t.push(` active ${e.watchers.active}`),t.push(` opened ${e.watchers.opened}`),t.push(` closed ${e.watchers.closed}`),t.push(` evicted ${e.watchers.evicted}`),t.push(``),t.push(`subprocesses`),t.push(` total ${e.subprocesses.total}`),t.push(` inFlight ${e.subprocesses.inFlight}`),t.push(` lastMinute ${e.subprocesses.lastMinute}`);let n=Object.entries(e.subprocesses.byCategory),r=n.reduce((e,[t])=>Math.max(e,t.length),13);for(let[i,a]of n){let n=e.subprocesses.p50DurationMs[i],o=e.subprocesses.p99DurationMs[i],s=n!==void 0&&o!==void 0?` (p50 ${n}ms · p99 ${o}ms)`:``;t.push(` ${i.padEnd(r)} ${a}${s}`)}return e.nextRestartReason&&(t.push(``),t.push(`nextRestart ${e.nextRestartReason}`)),t.join(`
|
|
452
452
|
`)+`
|
|
453
|
-
`}const
|
|
454
|
-
`).join(` — `));let{version:t,handlerProbes:n}=e.value;return Array.isArray(n)?
|
|
455
|
-
`);return{inMode:n!==`0`,screen:r}}function pG(e,t){let n=dG(e,`claude-input.type`,[`load-buffer`,`-b`,uG,`-`,`;`,`send-keys`,`-t`,e.pane,`C-s`,`;`,`paste-buffer`,`-p`,`-d`,`-b`,uG,`-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 mG(){return{read:fG,type:pG}}function hG(e){if(!e)throw new K(`session id is required`);if(e.includes(`/`)||e.includes(`..`))throw new K(`invalid session id "${e}"`);return e}function gG(e){return _G(()=>decodeURIComponent(e))}function _G(e){try{return e()}catch(e){throw e instanceof URIError?new K(`malformed wire encoding: ${e.message}`):e}}function vG(e,t){let n=Ne({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 yG=(e,t)=>vG(gG(e),t),bG=(e,t)=>{let n=Ne({bin:`/usr/bin/open`,args:[`-a`,`Visual Studio Code`,gG(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`})`)}},xG=(e,t)=>vG(gG(e),t),SG=(e,t)=>vG(gG(e),t),CG=(e,t)=>{let n=hG(gG(e));t.navigating.get(n,`toolbar-expanded`)?t.navigating.clear(n,`toolbar-expanded`):t.navigating.set(n,`toolbar-expanded`,`1`)},wG=(e,t)=>{let[n=``,...r]=_G(()=>Wn(e)),i=hG(n),a=YL(IG(t,i));if(r.length===0)throw new K(`set-state: <key>/<value> is required (have keys: ${a.listKeys().join(`, `)})`);if(r.length%2!=0)throw new K(`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 K(`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 K(`set-state: pair ${e/2+1}: ${i.reason}`);o.push({key:t,value:i.value})}OG(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})`)},TG=/^-?\d+$/;function EG(e,t,n,r){let i=e+t;return i>r?e===r?n:r:i<n?e===n?r:n:i}const DG=(e,t)=>{let[n=``,r=``,i=``]=_G(()=>Wn(e)),a=hG(n);if(!r)throw new K(`step-state: <key> is required (shape: <sessionId>/<key>/<by>)`);if(!TG.test(i))throw new K(`step-state: delta must be an integer, got "${i}"`);let o=parseInt(i,10),s=IG(t,a),c=YL(s),l=c.rangeParamsFor(r);if(!l)throw new K(`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&&TG.test(u)?kG(l,parseInt(u,10)):AG(`step-state`,r,l,QL(s,e=>t.sessionState.get(a,e),r)),f=EG(d,o,l.min,l.max),p=c.validate(r,String(f));if(!p.ok)throw new K(`step-state: ${p.reason}`);OG(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 OG(e,t,n,r){let i=r.filter(e=>e.key.startsWith(dD));if(i.length===0)return;let a=OL(IG(e,t),n=>e.sessionState.get(t,n),i);if(a.length>0)throw new K(`${n}: refused — ${a.join(`; `)}`)}function kG(e,t){return Math.max(e.min,Math.min(e.max,t))}function AG(e,t,n,r){if(r===null)return n.min;if(!TG.test(r))throw new K(`${e}: "${t}" shows ${JSON.stringify(r)} before any click, not an integer to step`);return kG(n,parseInt(r,10))}const jG=`render-origin`;function MG(e){return JSON.stringify(e)}function NG(e){let t;try{t=JSON.parse(e)}catch{throw new K(`render origin is not JSON: ${e}`)}if(typeof t!=`object`||!t)throw new K(`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 K(`render origin has the wrong shape: ${e}`);return{projectDir:n,cwd:r,configFile:i}}function PG(e,t){let n=e.sessionState.get(t,jG);if(n===null)throw new K(`session ${t} has not rendered yet — no config to act on`);return NG(n)}function FG(e,t,n){let r=e.sessionState.get(t,jG);if(r===null)return;let i=NG(r),{path:a}=LG(i);n.some(e=>e.kind===`file`&&e.file===a)&&e.reloadConfig(i)}function IG(e,t){return e.configFor(PG(e,t))}function LG(e){return OF(e.projectDir,e.cwd,e.configFile??void 0)}function RG(e,t){return{record:(n,r,i)=>e.journal.file(t,n,r,i),logger:e.dlog}}const zG=(e,t)=>{let[n=``,r=``,i=``]=_G(()=>Wn(e)),a=hG(n),o=PG(t,a),s=t.configFor(o),c=mj(s);if(!r)throw new K(`set-config: <key>/<value> is required (have keys: ${c.listKeys().join(`, `)})`);let l=c.validate(r,i);if(!l.ok)throw new K(`set-config: ${l.reason}`);let u=LG(o),d=EL(s,e=>t.sessionState.get(a,e),r);VH(RG(t,a),u,[[d.key,l.value]]),t.reloadConfig(o),t.dlog(`info`,`set-config: ${d.key}=${l.value} → ${u.path} (session=${a})`)},BG=(e,t)=>{let[n=``,r=``,i=``]=_G(()=>Wn(e)),a=hG(n);if(!r)throw new K(`step-config: <key> is required (shape: <sessionId>/<key>/<by>)`);if(!TG.test(i))throw new K(`step-config: delta must be an integer, got "${i}"`);let o=parseInt(i,10),s=PG(t,a),c=t.configFor(s),l=mj(c),u=l.rangeParamsFor(r);if(!u)throw new K(`step-config: key "${r}" is not a bounded (range) config key (have keys: ${l.listKeys().join(`, `)})`);let d=LG(s),f=EL(c,e=>t.sessionState.get(a,e),r),p=BH(d.path,f.key),m=typeof p==`number`?kG(u,p):AG(`step-config`,r,u,gj(f.globals,r)),h=EG(m,o,u.min,u.max),g=l.validate(r,String(h));if(!g.ok)throw new K(`step-config: ${g.reason}`);VH(RG(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})`)},VG=(e,t)=>{let[n=``]=_G(()=>Wn(e)),r=hG(n),i=PG(t,r),a=t.configFor(i),o=e=>t.sessionState.get(r,e),s=wL(a,o),c=DL(a,o);if(s.length+c.length===0){t.dlog(`info`,`save: nothing unsaved (session=${r})`);return}let l=YL(a),u=s.map(e=>{let t=l.validate(e.sessionKey,e.value);if(!t.ok)throw new K(`save: ${t.reason}`);return[e.target,t.value]});UG(`save`,l,c);let d=LG(i);HH(RG(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(HG)].join(` `)} → ${d.path} (session=${r})`)},HG=e=>`${e.preset}/${e.id}.settings.${e.setting}=${Lh(e.value)}`;function UG(e,t,n){for(let r of n){let n=t.validate(r.key,Lh(r.value));if(!n.ok)throw new K(`${e}: ${n.reason}`)}}const WG=(e,t)=>{let[n=``]=_G(()=>Wn(e)),r=hG(n),i=PG(t,r),a=t.configFor(i),o=jL(a,e=>t.sessionState.get(r,e)),s=YL(a),c=o.picks.map(e=>{let t=s.validate(e.sessionKey,e.value);if(!t.ok)throw new K(`save-preset: ${t.reason}`);return[e.configKey,t.value]});UG(`save-preset`,s,o.placements);let l=LG(i),u=YH(RG(t,r),l,o.from,o.globals,c,o.placements);t.reloadConfig(i);for(let e of[...xa.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(HG)].join(` `)} → ${l.path} (session=${r})`)},GG=(e,t)=>{let[n=``]=_G(()=>Wn(e)),r=hG(n),i=PG(t,r),a=NL(t.configFor(i),e=>t.sessionState.get(r,e));if(a.kind===`rule`)throw new K(`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=LG(i);XH(RG(t,r),o,a.theme,a.look),t.reloadConfig(i);let s=new Set(wL(t.configFor(i),e=>t.sessionState.get(r,e)).map(e=>e.sessionKey)),c=Th.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} ${Th.map(e=>`${e}=${a.look[e]}`).join(` `)} → ${o.path} (session=${r})`)},KG=(e,t)=>{let[n=``,r=``]=_G(()=>Wn(e)),i=hG(n);if(!r)throw new K(`delete-preset: <name> is required (shape: <sessionId>/<name>)`);let a=PG(t,i),o=LG(a);ZH(RG(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})`)},qG=(e,t)=>{let[n=``,...r]=_G(()=>Wn(e)),i=hG(n),a=PG(t,i),o=mj(t.configFor(a)).listKeys(),s=r.length===0?[``]:r.filter(e=>!o.includes(e));if(s.length>0)throw new K(`reset-config: unknown config key "${s.join(`", "`)}" (have: ${o.join(`, `)})`);let c=LG(a),l=r.map(PL),u=l.flatMap(e=>e.fileKeys),d=l.flatMap(e=>e.sessionKeys);KH(RG(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 JG(e,t){let n=(e,t)=>[...bh(ag(e,t).node)].filter(e=>e.kind===`segment`),r=new Set(ng(t.presets).flatMap(e=>n(t,e).map(t=>fD(iT(e),gh(t)))));return ng(e.presets).flatMap(t=>n(e,t).map(e=>({member:fD(iT(t),gh(e)),node:e})).filter(({member:e})=>!r.has(e)))}function YG(e,t){return e.flatMap(({member:e,node:n})=>[...Object.values(n.drafts??{}).map(e=>e.key),...e===t?[oD]:[]])}const XG=(e,t)=>{let[n=``,r=``,i=``]=_G(()=>Wn(e)),a=hG(n),o=PG(t,a),s=t.configFor(o),c=mj(s);if(!r)throw new K(`apply-layout-op: <key>/<op> is required (have: ${c.listKeys().join(`, `)})`);let l=c.validate(r,i);if(!l.ok)throw new K(`apply-layout-op: ${l.reason}`);let u=ej(l.value);if(u===null)throw new K(`apply-layout-op: "${l.value}" is not a layout op token`);let d=LG(o),f=QH(RG(t,a),d,r,u);t.reloadConfig(o);let p=YG(JG(s,t.configFor(o)),t.sessionState.get(a,oD)).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})`)},ZG=(e,t)=>{let[n=``]=_G(()=>Wn(e)),r=hG(n);t.journal.commit();let i=t.history.undo(r);FG(t,r,i),t.dlog(`info`,`undo: restored ${bU(i)} (session=${r})`)},QG=(e,t)=>{let n=hG(gG(e)),{step:r,discarded:i}=t.navigation.back(n,t.sessionState,YL(IG(t,n))),a=r.map(e=>`${e.key}=${e.before??`∅`}`).join(` `);t.dlog(`info`,`back: ${a} discarded=${i} (session=${n})`)},$G=(e,t)=>{let n=hG(gG(e));t.journal.commit();let r=t.history.rewind(n);FG(t,n,r),t.dlog(`info`,`rewind: put back ${bU(r)||`nothing`} as edit mode found it (session=${n})`)},eK=(e,t)=>{let[n=``]=_G(()=>Wn(e)),r=hG(n);t.journal.commit();let i=t.history.redo(r);FG(t,r,i),t.dlog(`info`,`redo: re-applied ${bU(i)} (session=${r})`)},tK=(e,t)=>{hG(gG(e)),t.applyUpdate()},nK=`client-hints`;function rK(e,t){let n=e.sessionState.get(t,nK);if(n===null)throw new K(`session ${t} has not rendered yet — no client facts are recorded for it`);let r;try{r=JSON.parse(n)}catch{throw new K(`client hints record is not JSON: ${n}`)}if(typeof r!=`object`||!r)throw new K(`client hints record is not an object: ${n}`);return ot(r)}function iK(e,t,n){let r=dO(n);e.sessionState.setBatch(t,_O(r)),e.dlog(`info`,`doctor: ${r.map(e=>`${e.check.name}=${e.verdict.ok?`ok`:`failed(${1+(e.verdict.more?.length??0)})`}`).join(` `)} ${hO(n.nerdFont,n.marks)} (session=${t})`)}function aK(e,t){let n;try{n=LW(e.doctor,rK(e,t),PG(e,t),n=>e.sessionState.get(t,n))}catch(e){throw e instanceof PU?new K(e.message):e}return{...n,urlHandler:FW(e.clientVersion)}}const oK=(e,t)=>{let n=hG(gG(e));iK(t,n,aK(t,n))},sK=(e,t)=>{let n=XW(gG(e));if(n===null)throw new K(`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`}`)},cK=(e,t)=>{let[n=``,r=``]=_G(()=>Wn(e)),i=hG(n),a=fO(r);if(a===void 0)throw new K(`doctor-fix: unknown check "${r}"`);let o=aK(t,i),s=a.probe(o);if(s.ok||s.fix===void 0)throw new K(`doctor-fix: ${a.label} — ${s.ok?`nothing to fix`:s.reason}`);let c=RW(s.fix,o);t.dlog(`info`,`doctor-fix: ${a.name} → ${s.fix.kind} ${s.fix.path.join(`.`)}=${JSON.stringify(s.fix.value)} (session=${i})`),iK(t,i,c)},lK=(e,t)=>{let[n=``,r=``,i=``]=_G(()=>Wn(e)),a=hG(n),o=fO(r);if(o===void 0)throw new K(`doctor-mark: unknown check "${r}"`);if(!JD.includes(i))throw new K(`doctor-mark: the mark is ${JSON.stringify(i)}, not ${JD.join(` or `)}`);let s=aK(t,a),c=o.probe(s);if(c.ok||c.sighting===void 0)throw new K(`doctor-mark: ${o.label} — ${c.ok?`nothing to mark`:`shows nothing to look at`}`);if(s.marks.kind===`failed`)throw new K(`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})`),iK(t,a,{...s,marks:{kind:`ok`,value:MU(s.marks.value,...l)}})},uK=(e,t)=>{let[n=``,...r]=_G(()=>Wn(e)),i=hG(n),a=PG(t,i),o=Object.values(t.configFor(a).actions).filter(e=>`ceiling`in e).find(e=>{let t=gN(e);return t.length===r.length&&t.every((e,t)=>e===r[t])});if(o===void 0)throw new K(`ceiling: "${r.join(` `)}" is not a move this config declares`);let s=o.ceiling===`set`?{kind:`set`,to:o.to}:{kind:`clear`},c=DI({sessionId:i,projectDir:a.projectDir,cwd:a.cwd},rK(t,i));t.memento.move(c,s),t.dlog(`info`,`ceiling: ${r.join(` `)} (session=${i} claudeConfigDir=${c.claudeConfigDir})`)},dK=(e,t)=>{let[n=``,r=``]=_G(()=>Wn(e)),i=hG(n),a=Object.values(t.configFor(PG(t,i)).actions).filter(e=>`slash`in e),o=a.find(e=>e.slash===r);if(o===void 0)throw new K(`${JSON.stringify(r)} is not a command this config declares (it declares: ${[...new Set(a.map(e=>e.slash))].join(`, `)||`none`})`);let s=lG(t.claudeInput,rK(t,i).tmux,o.slash);if(s.kind===`refused`)throw t.dlog(`warn`,`slash: ${r} refused — ${s.reason} (session=${i})`),new K(`${r} was not typed: ${s.reason}`);t.dlog(`info`,`slash: typed ${r} into ${s.pane} (session=${i})`)},fK=`config-override`,pK=new Map([[bn,yG],[`load-config`,(e,t)=>{let n=e.indexOf(`/`);if(n===-1)throw new K(`load-config: expected <sessionId>/<path> (missing separator)`);let r=hG(_G(()=>decodeURIComponent(e.slice(0,n)))),i=_G(()=>decodeURIComponent(e.slice(n+1))).trim();if(i!==``){if(!i.startsWith(`/`))throw new K(`load-config: path must be absolute, got "${i}"`);if(!/\.(json5?|json)$/.test(i))throw new K(`load-config: path must end with .json5 or .json, got "${i}"`)}i===``?(t.sessionState.clear(r,fK),t.dlog(`info`,`load-config: override cleared (session=${r})`)):(t.sessionState.set(r,fK,i),t.dlog(`info`,`load-config: ${i} (session=${r})`))}],[xn,bG],[yn,wG],[N,DG],[P,zG],[Tn,BG],[An,qG],[En,VG],[Dn,WG],[On,GG],[kn,KG],[jn,XG],[Mn,ZG],[Nn,eK],[Pn,QG],[Fn,$G],[Cn,xG],[wn,SG],[Sn,CG],[In,tK],[Ln,oK],[Rn,cK],[zn,lK],[Bn,sK],[Vn,uK],[Hn,dK]]),mK=new Set([yn,N,P,Tn,An,En,Dn,On,kn,jn,Mn,Nn,Pn,Fn,Sn,In,Ln,Rn,zn,Vn,Hn]),hK=(e,t)=>{let n=[],r=!1,i=null;for(let{verb:a,value:o}of Jn(Kn(e))){if(!i&&mK.has(a)){let e=Wn(o);e.length>0&&e[0]&&(i=e[0])}let e=pK.get(a);if(!e){n.push(`unknown effect verb "${a}"`);continue}try{e(o,t)}catch(e){e instanceof K||(r=!0),n.push(`${a}: ${e instanceof Error?e.message:String(e)}`)}}if(n.length>0){i&&t.sessionState.set(i,`click.error`,n.join(`
|
|
456
|
-
`));let e=`dispatch: ${n.join(`; `)}`;throw r?Error(e):new K(e)}};function gK(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 _K=new Map([...pK,[vn,hK]].map(([e,t])=>[e,gK(t)]));Object.freeze([..._K.keys()]);const vK=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`]),yK=[[`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`]],bK=[[`workspace.added_dirs`,`string-list`]];function xK(e){let t={missingRequired:[],typeMismatches:[],unknownTopLevelFields:[]},n=typeof e==`object`&&e&&!Array.isArray(e)?e:{};for(let[e,r]of yK){let i=wK(n,e);if(i==null)t.missingRequired.push(e);else{let n=SK(i);n!==r&&t.typeMismatches.push({path:e,expected:r,got:n})}}for(let[e,r]of bK){let i=wK(n,e),a=i===void 0?r:CK(i);a!==r&&t.typeMismatches.push({path:e,expected:r,got:a})}for(let e of Object.keys(n))vK.has(e)||t.unknownTopLevelFields.push(e);return{data:e,report:t}}function SK(e){return Array.isArray(e)?`array`:typeof e==`string`&&!e.isWellFormed()?`ill-formed string`:typeof e}function CK(e){return Array.isArray(e)&&e.every(e=>SK(e)===`string`)?`string-list`:SK(e)}function wK(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 TK(e,t){switch(e){case`vars`:return{what:e,vars:EK(t)};case`segments`:return{what:e,segments:jK(t)};case`config`:return{what:e,config:FK(t)}}}function EK(e){if(e===null)return[];let{store:t,registry:n,config:r}=e,i=kK(r),a=t.names().sort(),o=[];for(let e of a){let r=t.getNode(e),a=DK(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:OK(r.lastUpdatedMs())})}return o}function DK(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 OK(e){return e===null?null:Math.max(0,Date.now()-e)}function kK(e){let t=new Map;for(let[n,r]of Object.entries(e.variables))t.set(n,AK(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}`,AK(i));return t}function AK(e){return e.kind}function jK(e){if(e===null)return[];let{store:t,config:n,lastRenderBySegment:r}=e,i=new Set(t.names()),a=NK(n),o=MK(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:PK(t.template,n.helpers,i),placements:(o.get(e)??[]).map(e=>({id:e,lastRender:r.get(e)??null}))})}return s}function MK(e){let t=new Map;for(let n of ng(e.presets))for(let r of bh(ag(e,n).node)){if(r.kind!==`segment`)continue;let e=t.get(r.name)??[],n=gh(r);e.includes(n)||t.set(r.name,[...e,n])}return t}function NK(e){let t=[],n=new Set;for(let r of bh(Yh(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 PK(e,t,n){let r=new Set;for(let i of Dg(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 FK(e){return e===null?null:e.config}const IK=[`vars`,`segments`,`config`];function LK(e){return typeof e==`string`&&IK.includes(e)}function RK(e){return Math.max(1,e-2)}var zK=class{written=new Map;constructor(e){this.dir=e}pathFor(e){return l.join(this.dir,`${encodeURIComponent(e)}.txt`)}sync(e,t){let n=this.pathFor(e);if(t===(this.written.get(e)??null))return null;try{return t===null?(r.rmSync(n,{force:!0}),this.written.delete(e)):(r.mkdirSync(this.dir,{recursive:!0,mode:448}),r.writeFileSync(n,t,{mode:384}),this.written.set(e,t)),null}catch(e){return`${n}: ${e.message}`}}reset(){this.written.clear();try{return r.rmSync(this.dir,{recursive:!0,force:!0}),null}catch(e){return`${this.dir}: ${e.message}`}}};function BK(e,t){for(let n of Object.entries(t))e.push(n)}const VK={ok:`info`,"bad-request":`warn`,threw:`error`};function HK(e){switch(e.kind){case`ok`:return[];case`bad-request`:return[[`problems`,e.problems.join(`; `)]];case`threw`:return[[`error`,y(e.error)]]}}const UK=/^[^\s"=\\]+$/,WK=e=>UK.test(e)?e:JSON.stringify(e);function GK(e,t,n){let r=[...e,[`took`,`${n}ms`],[`outcome`,t.kind],...HK(t)];return{level:VK[t.kind],line:`render${r.map(([e,t])=>` ${e}=${WK(t)}`).join(``)}`}}const KK=new qV,qK=new JW;Ae(KK.launchStats);const JK=new _w({counters:KK,logger:A}),YK=vz({watchers:JK,logger:A}),{gitProvider:XK,usageStore:ZK,mementoProvider:QK}=YK,$K=new XV,eq=new oU($K,A),tq=new kU,nq=new Sm,rq=new zK($e()),iq=new GV({gitService:XK,sessionState:$K,watchers:JK},{observers:{onReload:e=>A(`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)}`)}}),aq=60*1e3;function oq(){let e=import.meta.url,n=[];e.startsWith(`file://`)&&n.push(ne(e)),t.argv[1]&&n.push(t.argv[1]);let i=new Map;for(let e of n)try{i.set(e,r.statSync(e).mtimeMs)}catch{}let a=null,o=()=>{for(let[e,t]of i)try{if(r.statSync(e).mtimeMs!==t){A(`info`,`binary mtime changed (${e}); shutting down`),a&&clearInterval(a),Sq(0);return}}catch(e){A(`warn`,`bin stat failed: ${e.message}`)}};return{arm(){i.size!==0&&(a=setInterval(o,aq),a.unref())},checkNow:o}}const sq=oq(),cq=_R({entryUrl:import.meta.url,intervalMs:aq,releaseIntervalMs:216e5,registryUrl:t.env.CC_CANDYBAR_REGISTRY_URL??`https://registry.npmjs.org`,fetchImpl:fetch,onApplied:()=>sq.checkNow(),log:A});let lq=null,uq=null,dq=0;function fq(){t.on(`uncaughtException`,e=>{A(`error`,`uncaughtException: ${e.stack||e.message}`),Sq(1)}),t.on(`unhandledRejection`,e=>{A(`error`,`unhandledRejection: ${String(e)}`),Sq(1)});for(let e of[`SIGINT`,`SIGTERM`,`SIGHUP`])t.on(e,()=>{A(`info`,`received ${e}, shutting down`),Sq(0)});try{dq=Wt(t.env)}catch(e){A(`error`,`refusing to boot: ${e.message}`),Sq(1);return}lq=sa(t.pid);let e=_a(ya(lq));if(!e.decision.allow){A(`warn`,`fork-bomb breaker: ${e.decision.reason}; refusing to boot`),Sq(1);return}uq=e.registryPath,r.mkdirSync(Be(),{recursive:!0}),We(Ve()),$K.useStorage(new QV(qe(),500,A)),eq.useStorage(DU(Je(),A)),ua({anchor:la(t.env),isAlive:da,onOrphaned:e=>{A(`info`,`parent watchdog: ${e}; shutting down`),Sq(0)}}),pq(S.createServer({allowHalfOpen:!1},e=>{Cq(e)}),Ve(),!1)}function pq(e,n,r){e.removeAllListeners(`error`),e.removeAllListeners(`listening`),e.once(`error`,i=>{if(i.code!==`EADDRINUSE`){A(`error`,`server error: ${i.message}`),Sq(1);return}if(r){A(`info`,`lost rebind race; another daemon is alive — exiting`),t.exit(0);return}mq(e,n)}),e.listen(n,()=>hq(n))}function mq(e,n){let i=Zi(Qi(Ge(n)),(e,t)=>oa(e,t,{readStartTime:aa,pidAlive:da}));if(i.kind===`attach-and-exit`){A(`info`,`EADDRINUSE: ${i.reason} — exiting`),t.exit(0);return}A(`warn`,`EADDRINUSE: ${i.reason} — unlinking stale socket and rebinding`);try{r.unlinkSync(n)}catch(e){if(e.code!==`ENOENT`){A(`error`,`cannot unlink stale socket ${n}: ${e.message}`),Sq(1);return}}pq(e,n,!0)}function hq(e){let n=ta(e);if(n.kind!==`present`){A(`warn`,`no ownable socket at bind callback (${n.kind}); exiting`),Sq(0);return}yq(e);try{r.chmodSync(e,384)}catch(e){A(`warn`,`chmod socket failed: ${e.message}`)}A(`info`,`daemon up: pid=${t.pid} v=3 sock=${e} heapCap=${Math.round(C.getHeapStatistics().heap_size_limit/1048576)}MB rssLimit=${Math.round(dq/1048576)}MB`),sn();let i=rq.reset();i!==null&&A(`warn`,`diagnostic dump wipe failed: ${i}`),sq.arm(),cq.arm(),vq(),gq(e,n.identity)}function gq(e,n){ia({bound:n,myPid:t.pid,readIdentity:()=>ta(e),readLease:()=>Qi(Ge(e)),shutdown:e=>Sq(e),log:A}).arm()}let _q=null;function vq(){_q=Jt(Zt(KK.startedAt.getTime(),e=>Sq(e),{rssLimitBytes:dq})),_q.arm()}function yq(e){let n=$i(Ge(e),{pid:t.pid,version:3,binPath:t.argv[1],startTime:lq});n!==null&&A(`warn`,`lease write failed: ${n}`)}let bq=0,xq=!1;function Sq(e){if(!xq){xq=!0,setTimeout(()=>t.kill(t.pid,`SIGKILL`),500);try{XK.close()}catch(e){A(`warn`,`gitService close failed: ${e.message}`)}try{ZK.close()}catch(e){A(`warn`,`usageStore close failed: ${e.message}`)}try{JK.closeAll()}catch(e){A(`warn`,`watcherRegistry close failed: ${e.message}`)}try{$K.flush()}catch(e){A(`warn`,`sessionState flush failed: ${e.message}`)}ea(Ke(),t.pid),uq!==null&&va(uq,t.pid,ha,e=>r.unlinkSync(e)),t.exit(e)}}function Cq(e){bq++,KK.inFlight=bq;let t=!1,n=(n,r)=>{if(t){r!==null&&A(`warn`,`exit-after-flush dropped: an earlier responder settled this socket`);return}t=!0;let i=r===null?void 0:()=>Sq(r);try{e.end(k(n),i)}catch(e){A(`warn`,`response write failed: ${e.message}`),i?.()}},r=!1,i=setTimeout(()=>{r=!0,KK.requestsTimedOut++,n({ok:!1,error:`request exceeded 200ms`,code:`TIMEOUT`,daemonV:3},null)},200),a=_t(e=>{Eq(e,()=>r).then(e=>n(e.resp,e.exitAfterFlush)).catch(e=>{A(`error`,`handler threw: ${y(e)}`),n(Tq(e),null)})},e=>{A(`warn`,`frame parse failed: ${e.message}`),n({ok:!1,error:e.message,code:`BAD_REQUEST`,daemonV:3},null)});e.on(`data`,a),e.on(`error`,e=>{A(`warn`,`socket error: ${e.message}`)}),e.on(`close`,()=>{clearTimeout(i),bq=Math.max(0,bq-1),KK.inFlight=bq})}const wq=e=>({resp:e,exitAfterFlush:null}),Tq=e=>({ok:!1,error:e instanceof Error?e.message:y(e),code:`RENDER_FAILED`,daemonV:3});async function Eq(e,t){if(!e||typeof e!=`object`||typeof e.v!=`number`)return wq({ok:!1,error:`malformed request`,code:`BAD_REQUEST`,daemonV:3});if(e.v!==3)return e.v>3?A(`info`,`version mismatch: client=${e.v} > daemon=3; binary likely upgraded — exiting after the response flushes`):A(`info`,`version mismatch: client=${e.v} < daemon=3; client is stale — staying up`),{resp:{ok:!1,error:`protocol v${e.v} not supported (daemon at v3)`,code:`VERSION_MISMATCH`,daemonV:3},exitAfterFlush:e.v>3?0:null};if(e.kind===`shutdown`)return{resp:{ok:!0,output:``},exitAfterFlush:0};if(e.kind===`stats`)return wq({ok:!0,stats:KK.snapshot({gitCache:XK.getStats(),usageCache:ZK.getStats(),renderCacheSize:iq.size,effectCache:nq.getStats(),watchersActive:JK.size(),nextRestartReason:_q?.describeNextRestart()??null,handlerProbes:qK.list()})});if(e.kind===`render`){KK.requestsTotal++;let n=new Date,r=kw(n),i=n.getTime(),a=[],o=await Pq(e,r,a).catch(e=>({outcome:{kind:`threw`,error:e},resp:Tq(e)}));o.outcome.kind!==`ok`&&KK.requestsErrored++,BK(a,{timedOut:t()?`Y`:`N`});let{level:s,line:c}=GK(a,o.outcome,Date.now()-i);return A(s,c),wq(o.resp)}if(e.kind===`click`)return wq(Nq(e.verb,e.value,ht(e.clientVersion)));if(e.kind===`debug`){if(!LK(e.what))return wq({ok:!1,error:`unknown debug 'what': ${String(e.what)} (have: ${IK.join(`, `)})`,code:`BAD_REQUEST`,daemonV:3});let t=iq.firstState(),n=t===null?null:{store:t.store,registry:t.registry,config:t.config,compiled:t.compiled,lastRenderBySegment:e.what===`segments`?jq(t.lastRenderCellsBySegment,t.config.globals.charset??`unicode`,t.config.globals.colorCompatibility??`truecolor`):Aq};return wq({ok:!0,debug:TK(e.what,n)})}return wq({ok:!1,error:`unknown kind`,code:`BAD_REQUEST`,daemonV:3})}function Dq(e,t){let{values:n,tokens:r}=b({args:e.slice(1),options:{config:{type:`string`}},strict:!1,tokens:!0,allowPositionals:!0}),i=[...new Set((r??[]).filter(e=>e.kind===`option`&&e.name!==`config`).map(e=>`--${e.name}`))];return{configFile:qP(t,n.config),unknownFlagsError:i.length>0?`Unknown flags: ${i.join(`, `)}`:null}}const Oq={sessionState:$K,dlog:A,applyUpdate:()=>cq.act(),doctor:AW(e=>{let t=[e.projectDir,e.cwd,e.configFile??void 0];iq.reload(...t);let n=iq.getOrCreate(...t);return{layers:n.configLayers,error:n.lastError,warning:n.lastWarning,unused:n.state.unused,config:n.state.config}}),probes:qK,memento:QK,claudeInput:mG(),history:eq,navigation:tq,configFor:e=>iq.getOrCreate(e.projectDir,e.cwd,e.configFile??void 0).state.config,reloadConfig:e=>iq.reload(e.projectDir,e.cwd,e.configFile??void 0)};Oq.reloadConfig;const kq={endcaps:`powerline`,colorCompatibility:`truecolor`,wrap:!0,padding:1,charset:Wp,width:1/0},Aq=new Map;function jq(e,t,n){let r=new Map;for(let[i,a]of e)r.set(i,Im(a,{...kq,charset:t,colorCompatibility:n}));return r}const Mq={...YK,history:e=>eq.depth(e)};function Nq(e,t,n){let r=_K.get(e);if(!r)return{ok:!1,error:`unknown click verb: ${e}`,code:`BAD_REQUEST`,daemonV:3};try{return r(t,{...Oq,clientVersion:n}),{ok:!0,output:``}}catch(e){let t=e instanceof K?`BAD_REQUEST`:`RENDER_FAILED`;return{ok:!1,error:String(e instanceof Error?e.message:e),code:t,daemonV:3}}}async function Pq(e,t,n){let{report:r}=xK(e.hookData);for(let e of r.unknownTopLevelFields)A(`info`,`schema: unknown field '${e}' — Anthropic may have added it`);let i=[];for(let e of r.missingRequired)i.push(`missing required field '${e}'`);for(let{path:e,expected:t,got:n}of r.typeMismatches)i.push(`field '${e}' expected ${t}, got ${n}`);if(f(e.cwd)||i.push(`request 'cwd' is not an absolute path: "${e.cwd}"`),i.length>0)return{outcome:{kind:`bad-request`,problems:i},resp:{ok:!1,error:`malformed hookData: ${i.join(`; `)}`,code:`BAD_REQUEST`,daemonV:3}};BK(n,{sid:e.hookData.session_id,at:t.toFixed(3)});let a=e.hookData.workspace.project_dir,{configFile:o,unknownFlagsError:s}=Dq(e.args,e.cwd),c=e.hookData.session_id,l=ot(e),u=st(e,l),d=ct(u);BK(n,{termCols:String(l.termCols??`?`),termRows:String(l.termRows??`?`),refused:u.map(e=>e.hint).join(`,`)||`-`});let p=JSON.stringify(l);$K.get(c,`client-hints`)!==p&&$K.set(c,nK,p);let m=$K.get(c,`config-override`)??o??l.configEnv,h=iq.getOrCreate(a,e.cwd,m),g=MG({projectDir:a,cwd:e.cwd,configFile:m??null});$K.get(c,`render-origin`)!==g&&$K.set(c,jG,g);let _=l.termCols,v=RK(_??120),y=Lm(l.termRows);BK(n,{width:String(v)});let{authoredRoots:b}=h.state,x=t=>$K.get(e.hookData.session_id,t),S=BI(h.state.config,x,e=>b.has(e)),C=await aL(e.hookData,t,{...Mq,navigation:e=>tq.depth(e,$K,YL(h.state.config))},e.cwd,h.state.neededInputPaths(S.preset),S,l,{...IL(h.state.config,h.state.fileHeldSettings,x),configPath:h.configLayers.includes(h.configHome)?h.configHome:null});BK(n,{prompts:String(C.metrics?.messageCount??`-`),nonPrompts:String(C.metrics?.nonPrompts??`-`),pr:GI(C.git)});let ee=[],te=VI(S,v),ne=nq.of(c),re=wV(h.state.config,h.state.compiled,h.state.store,h.state.registry,C,t,te,{perSegmentSink:h.state.lastRenderCellsBySegment,onRenderWarning:e=>ee.push(e)},{...HI(S),effects:ne}),ie=$K.get(e.hookData.session_id,`click.error`);ie&&$K.clear(e.hookData.session_id,`click.error`);let ae=[s,d,h.lastError,ie].filter(Boolean).join(`
|
|
457
|
-
`),w=
|
|
458
|
-
`)),se=
|
|
459
|
-
`}}}const
|
|
460
|
-
`);return}t.stdout.write(
|
|
461
|
-
`;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?``:` ${
|
|
453
|
+
`}const aG=e=>({kind:`ok`,value:e}),oG=e=>({kind:`failed`,reason:e});var sG=class{arrivals=[];arrive(e){this.arrivals=[...this.arrivals,e].slice(-16)}list(){return this.arrivals}};const cG=/^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$/;function lG(e){return cG.test(e)?e:null}function uG(e){let t=e.opener();if(t.kind===`failed`)return t;if(t.value===null)return aG(null);let n=t.value,r=e.script(n);if(r.kind===`failed`)return aG({app:n,missing:oG(`its script could not be read (${r.reason})`)});let i=Fi(r.value);return aG({app:n,missing:i===null?oG("its script is not one `cc-candybar install` wrote"):aG([i.node,i.script].filter(t=>!e.exists(t)))})}async function dG(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 fG(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(`${_n}://${Bn}/${n}`);return(r===null?await dG(e,n):null)??{kind:`lost`,unopened:r,opener:uG(e)}}function pG(e,t,n){let r=Ne({bin:t,args:[...n],category:e,timeoutMs:5e3});return r.ok?aG(r.stdout):oG(r.stderr.trim()||r.error||r.reason)}const mG=`ObjC.import("AppKit");var u = $.NSWorkspace.sharedWorkspace.URLForApplicationToOpenURL($.NSURL.URLWithString("${_n}://probe"));u.isNil() ? "" : u.path.js`;async function hG(){let e=await eG();if(e.kind!==`ok`)return oG(Tt(e).split(`
|
|
454
|
+
`).join(` — `));let{version:t,handlerProbes:n}=e.value;return Array.isArray(n)?aG({version:t,arrivals:n}):oG(`the running daemon (${t}) predates this check`)}function gG(){return{platform:process.platform,sockets:{own:Ve(),handler:He()},now:Date.now,nonce:w,daemon:hG,open:e=>{let t=pG(`doctor.open`,`/usr/bin/open`,[`-g`,e]);return t.kind===`ok`?null:t.reason},pause:()=>new Promise(e=>setTimeout(e,100)),opener:()=>{let e=pG(`doctor.launch-services`,`/usr/bin/osascript`,[`-l`,`JavaScript`,`-e`,mG]);if(e.kind===`failed`)return e;let t=e.value.trim();return aG(t===``?null:t)},script:e=>pG(`doctor.osadecompile`,`/usr/bin/osadecompile`,[Ii(e)]),exists:r.existsSync}}const _G=/^─{20,}/,vG=/^❯(\s|$)/,yG=/›\s*stashed$/;function bG(e){if(e.inMode)return{kind:`in-mode`};let t=e.screen.map(e=>e.trimEnd()),n=t.flatMap((e,t)=>_G.test(e)?[t]:[]).at(-2);return n===void 0||!vG.test(t[n+1]??``)?{kind:`no-prompt`}:yG.test(t[n-1]??``)?{kind:`stashed`}:{kind:`ready`}}const xG={"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 SG(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=bG(e.read(t));if(r.kind!==`ready`)return{kind:`refused`,reason:xG[r.kind]};let i=e.type(t,n);return i.kind===`typed`?{kind:`typed`,pane:t.pane}:i}const CG=`cc-candybar-slash`;function wG(e,t,n,r){let i=Sz(e,t,n,r);if(i.kind===`failed`)throw Error(i.reason);return i}function TG(e){let t=wG(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(`
|
|
455
|
+
`);return{inMode:n!==`0`,screen:r}}function EG(e,t){let n=wG(e,`claude-input.type`,[`load-buffer`,`-b`,CG,`-`,`;`,`send-keys`,`-t`,e.pane,`C-s`,`;`,`paste-buffer`,`-p`,`-d`,`-b`,CG,`-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 DG(){return{read:TG,type:EG}}function OG(e){if(!e)throw new K(`session id is required`);if(e.includes(`/`)||e.includes(`..`))throw new K(`invalid session id "${e}"`);return e}function kG(e){return AG(()=>decodeURIComponent(e))}function AG(e){try{return e()}catch(e){throw e instanceof URIError?new K(`malformed wire encoding: ${e.message}`):e}}function jG(e,t){let n=Ne({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 MG=(e,t)=>jG(kG(e),t),NG=(e,t)=>{let n=Ne({bin:`/usr/bin/open`,args:[`-a`,`Visual Studio Code`,kG(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`})`)}},PG=(e,t)=>jG(kG(e),t),FG=(e,t)=>jG(kG(e),t),IG=(e,t)=>{let n=OG(kG(e));t.navigating.get(n,`toolbar-expanded`)?t.navigating.clear(n,`toolbar-expanded`):t.navigating.set(n,`toolbar-expanded`,`1`)},LG=(e,t)=>{let[n=``,...r]=AG(()=>Wn(e)),i=OG(n),a=aR(YG(t,i));if(r.length===0)throw new K(`set-state: <key>/<value> is required (have keys: ${a.listKeys().join(`, `)})`);if(r.length%2!=0)throw new K(`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 K(`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 K(`set-state: pair ${e/2+1}: ${i.reason}`);o.push({key:t,value:i.value})}VG(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})`)},RG=/^-?\d+$/;function zG(e,t,n,r){let i=e+t;return i>r?e===r?n:r:i<n?e===n?r:n:i}const BG=(e,t)=>{let[n=``,r=``,i=``]=AG(()=>Wn(e)),a=OG(n);if(!r)throw new K(`step-state: <key> is required (shape: <sessionId>/<key>/<by>)`);if(!RG.test(i))throw new K(`step-state: delta must be an integer, got "${i}"`);let o=parseInt(i,10),s=YG(t,a),c=aR(s),l=c.rangeParamsFor(r);if(!l)throw new K(`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&&RG.test(u)?HG(l,parseInt(u,10)):UG(`step-state`,r,l,cR(s,e=>t.sessionState.get(a,e),r)),f=zG(d,o,l.min,l.max),p=c.validate(r,String(f));if(!p.ok)throw new K(`step-state: ${p.reason}`);VG(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 VG(e,t,n,r){let i=r.filter(e=>e.key.startsWith(dD));if(i.length===0)return;let a=RL(YG(e,t),n=>e.sessionState.get(t,n),i);if(a.length>0)throw new K(`${n}: refused — ${a.join(`; `)}`)}function HG(e,t){return Math.max(e.min,Math.min(e.max,t))}function UG(e,t,n,r){if(r===null)return n.min;if(!RG.test(r))throw new K(`${e}: "${t}" shows ${JSON.stringify(r)} before any click, not an integer to step`);return HG(n,parseInt(r,10))}const WG=`render-origin`;function GG(e){return JSON.stringify(e)}function KG(e){let t;try{t=JSON.parse(e)}catch{throw new K(`render origin is not JSON: ${e}`)}if(typeof t!=`object`||!t)throw new K(`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 K(`render origin has the wrong shape: ${e}`);return{projectDir:n,cwd:r,configFile:i}}function qG(e,t){let n=e.sessionState.get(t,WG);if(n===null)throw new K(`session ${t} has not rendered yet — no config to act on`);return KG(n)}function JG(e,t,n){let r=e.sessionState.get(t,WG);if(r===null)return;let i=KG(r),{path:a}=XG(i);n.some(e=>e.kind===`file`&&e.file===a)&&e.reloadConfig(i)}function YG(e,t){return e.configFor(qG(e,t))}function XG(e){return RF(e.projectDir,e.cwd,e.configFile??void 0)}function ZG(e,t){return{record:(n,r,i)=>e.journal.file(t,n,r,i),logger:e.dlog}}const QG=(e,t)=>{let[n=``,r=``,i=``]=AG(()=>Wn(e)),a=OG(n),o=qG(t,a),s=t.configFor(o),c=wj(s);if(!r)throw new K(`set-config: <key>/<value> is required (have keys: ${c.listKeys().join(`, `)})`);let l=c.validate(r,i);if(!l.ok)throw new K(`set-config: ${l.reason}`);let u=XG(o),d=IL(s,e=>t.sessionState.get(a,e),r);ZH(ZG(t,a),u,[[d.key,l.value]]),t.reloadConfig(o),t.dlog(`info`,`set-config: ${d.key}=${l.value} → ${u.path} (session=${a})`)},$G=(e,t)=>{let[n=``,r=``,i=``]=AG(()=>Wn(e)),a=OG(n);if(!r)throw new K(`step-config: <key> is required (shape: <sessionId>/<key>/<by>)`);if(!RG.test(i))throw new K(`step-config: delta must be an integer, got "${i}"`);let o=parseInt(i,10),s=qG(t,a),c=t.configFor(s),l=wj(c),u=l.rangeParamsFor(r);if(!u)throw new K(`step-config: key "${r}" is not a bounded (range) config key (have keys: ${l.listKeys().join(`, `)})`);let d=XG(s),f=IL(c,e=>t.sessionState.get(a,e),r),p=XH(d.path,f.key),m=typeof p==`number`?HG(u,p):UG(`step-config`,r,u,Ej(f.globals,r)),h=zG(m,o,u.min,u.max),g=l.validate(r,String(h));if(!g.ok)throw new K(`step-config: ${g.reason}`);ZH(ZG(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})`)},eK=(e,t)=>{let[n=``]=AG(()=>Wn(e)),r=OG(n),i=qG(t,r),a=t.configFor(i),o=e=>t.sessionState.get(r,e),s=PL(a,o),c=LL(a,o);if(s.length+c.length===0){t.dlog(`info`,`save: nothing unsaved (session=${r})`);return}let l=aR(a),u=s.map(e=>{let t=l.validate(e.sessionKey,e.value);if(!t.ok)throw new K(`save: ${t.reason}`);return[e.target,t.value]});nK(`save`,l,c);let d=XG(i);QH(ZG(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(tK)].join(` `)} → ${d.path} (session=${r})`)},tK=e=>`${e.preset}/${e.id}.settings.${e.setting}=${Lh(e.value)}`;function nK(e,t,n){for(let r of n){let n=t.validate(r.key,Lh(r.value));if(!n.ok)throw new K(`${e}: ${n.reason}`)}}const rK=(e,t)=>{let[n=``]=AG(()=>Wn(e)),r=OG(n),i=qG(t,r),a=t.configFor(i),o=VL(a,e=>t.sessionState.get(r,e)),s=aR(a),c=o.picks.map(e=>{let t=s.validate(e.sessionKey,e.value);if(!t.ok)throw new K(`save-preset: ${t.reason}`);return[e.configKey,t.value]});nK(`save-preset`,s,o.placements);let l=XG(i),u=aU(ZG(t,r),l,o.from,o.globals,c,o.placements);t.reloadConfig(i);for(let e of[...xa.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(tK)].join(` `)} → ${l.path} (session=${r})`)},iK=(e,t)=>{let[n=``]=AG(()=>Wn(e)),r=OG(n),i=qG(t,r),a=UL(t.configFor(i),e=>t.sessionState.get(r,e));if(a.kind===`rule`)throw new K(`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=XG(i);oU(ZG(t,r),o,a.theme,a.look),t.reloadConfig(i);let s=new Set(PL(t.configFor(i),e=>t.sessionState.get(r,e)).map(e=>e.sessionKey)),c=Th.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} ${Th.map(e=>`${e}=${a.look[e]}`).join(` `)} → ${o.path} (session=${r})`)},aK=(e,t)=>{let[n=``,r=``]=AG(()=>Wn(e)),i=OG(n);if(!r)throw new K(`delete-preset: <name> is required (shape: <sessionId>/<name>)`);let a=qG(t,i),o=XG(a);sU(ZG(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})`)},oK=(e,t)=>{let[n=``,...r]=AG(()=>Wn(e)),i=OG(n),a=qG(t,i),o=wj(t.configFor(a)).listKeys(),s=r.length===0?[``]:r.filter(e=>!o.includes(e));if(s.length>0)throw new K(`reset-config: unknown config key "${s.join(`", "`)}" (have: ${o.join(`, `)})`);let c=XG(a),l=r.map(WL),u=l.flatMap(e=>e.fileKeys),d=l.flatMap(e=>e.sessionKeys);nU(ZG(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 sK(e,t){let n=(e,t)=>[...bh(ag(e,t).node)].filter(e=>e.kind===`segment`),r=new Set(ng(t.presets).flatMap(e=>n(t,e).map(t=>fD(iT(e),gh(t)))));return ng(e.presets).flatMap(t=>n(e,t).map(e=>({member:fD(iT(t),gh(e)),node:e})).filter(({member:e})=>!r.has(e)))}function cK(e,t){return e.flatMap(({member:e,node:n})=>[...Object.values(n.drafts??{}).map(e=>e.key),...e===t?[oD]:[]])}const lK=(e,t)=>{let[n=``,r=``,i=``]=AG(()=>Wn(e)),a=OG(n),o=qG(t,a),s=t.configFor(o),c=wj(s);if(!r)throw new K(`apply-layout-op: <key>/<op> is required (have: ${c.listKeys().join(`, `)})`);let l=c.validate(r,i);if(!l.ok)throw new K(`apply-layout-op: ${l.reason}`);let u=uj(l.value);if(u===null)throw new K(`apply-layout-op: "${l.value}" is not a layout op token`);let d=XG(o),f=cU(ZG(t,a),d,r,u);t.reloadConfig(o);let p=cK(sK(s,t.configFor(o)),t.sessionState.get(a,oD)).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})`)},uK=(e,t)=>{let[n=``]=AG(()=>Wn(e)),r=OG(n);t.journal.commit();let i=t.history.undo(r);JG(t,r,i),t.dlog(`info`,`undo: restored ${AU(i)} (session=${r})`)},dK=(e,t)=>{let n=OG(kG(e)),{step:r,discarded:i}=t.navigation.back(n,t.sessionState,aR(YG(t,n))),a=r.map(e=>`${e.key}=${e.before??`∅`}`).join(` `);t.dlog(`info`,`back: ${a} discarded=${i} (session=${n})`)},fK=(e,t)=>{let n=OG(kG(e));t.journal.commit();let r=t.history.rewind(n);JG(t,n,r),t.dlog(`info`,`rewind: put back ${AU(r)||`nothing`} as edit mode found it (session=${n})`)},pK=(e,t)=>{let[n=``]=AG(()=>Wn(e)),r=OG(n);t.journal.commit();let i=t.history.redo(r);JG(t,r,i),t.dlog(`info`,`redo: re-applied ${AU(i)} (session=${r})`)},mK=(e,t)=>{OG(kG(e)),t.applyUpdate()},hK=`client-hints`;function gK(e,t){let n=e.sessionState.get(t,hK);if(n===null)throw new K(`session ${t} has not rendered yet — no client facts are recorded for it`);let r;try{r=JSON.parse(n)}catch{throw new K(`client hints record is not JSON: ${n}`)}if(typeof r!=`object`||!r)throw new K(`client hints record is not an object: ${n}`);return ot(r)}function _K(e,t,n){let r=bO(n);e.sessionState.setBatch(t,DO(r)),e.dlog(`info`,`doctor: ${r.map(e=>`${e.check.name}=${e.verdict.ok?`ok`:`failed(${1+(e.verdict.more?.length??0)})`}`).join(` `)} ${TO(n.nerdFont,n.marks)} ${wO(n.terminal,n.clicked)} (session=${t})`)}function vK(e,t){let n;try{n=XW(e.doctor,gK(e,t),qG(e,t),n=>e.sessionState.get(t,n))}catch(e){throw e instanceof WU?new K(e.message):e}return{...n,urlHandler:JW(e.clientVersion),askedBy:`click`,clicked:yK(e,n)}}function yK(e,{terminal:t,clicked:n}){let r=t.kind===`seen`?YD(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 bK=(e,t)=>{let n=OG(kG(e));_K(t,n,vK(t,n))},xK=(e,t)=>{let n=lG(kG(e));if(n===null)throw new K(`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`}`)},SK=(e,t)=>{let[n=``,r=``]=AG(()=>Wn(e)),i=OG(n),a=xO(r);if(a===void 0)throw new K(`doctor-fix: unknown check "${r}"`);let o=vK(t,i),s=a.probe(o);if(s.ok||s.fix===void 0)throw new K(`doctor-fix: ${a.label} — ${s.ok?`nothing to fix`:s.reason}`);let c=ZW(s.fix,o);t.dlog(`info`,`doctor-fix: ${a.name} → ${s.fix.kind} ${s.fix.path.join(`.`)}=${JSON.stringify(s.fix.value)} (session=${i})`),_K(t,i,c)},CK=(e,t)=>{let[n=``,r=``,i=``]=AG(()=>Wn(e)),a=OG(n),o=xO(r);if(o===void 0)throw new K(`doctor-mark: unknown check "${r}"`);if(!$D.includes(i))throw new K(`doctor-mark: the mark is ${JSON.stringify(i)}, not ${$D.join(` or `)}`);let s=vK(t,a),c=o.probe(s);if(c.ok||c.sighting===void 0)throw new K(`doctor-mark: ${o.label} — ${c.ok?`nothing to mark`:`shows nothing to look at`}`);if(s.marks.kind===`failed`)throw new K(`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})`),_K(t,a,{...s,marks:{kind:`ok`,value:HU(s.marks.value,...l)}})},wK=(e,t)=>{let[n=``,...r]=AG(()=>Wn(e)),i=OG(n),a=qG(t,i),o=Object.values(t.configFor(a).actions).filter(e=>`ceiling`in e).find(e=>{let t=EN(e);return t.length===r.length&&t.every((e,t)=>e===r[t])});if(o===void 0)throw new K(`ceiling: "${r.join(` `)}" is not a move this config declares`);let s=o.ceiling===`set`?{kind:`set`,to:o.to}:{kind:`clear`},c=LI({sessionId:i,projectDir:a.projectDir,cwd:a.cwd},gK(t,i));t.memento.move(c,s),t.dlog(`info`,`ceiling: ${r.join(` `)} (session=${i} claudeConfigDir=${c.claudeConfigDir})`)},TK=(e,t)=>{let[n=``,r=``]=AG(()=>Wn(e)),i=OG(n),a=Object.values(t.configFor(qG(t,i)).actions).filter(e=>`slash`in e),o=a.find(e=>e.slash===r);if(o===void 0)throw new K(`${JSON.stringify(r)} is not a command this config declares (it declares: ${[...new Set(a.map(e=>e.slash))].join(`, `)||`none`})`);let s=SG(t.claudeInput,gK(t,i).tmux,o.slash);if(s.kind===`refused`)throw t.dlog(`warn`,`slash: ${r} refused — ${s.reason} (session=${i})`),new K(`${r} was not typed: ${s.reason}`);t.dlog(`info`,`slash: typed ${r} into ${s.pane} (session=${i})`)},EK=`config-override`,DK=new Map([[bn,MG],[`load-config`,(e,t)=>{let n=e.indexOf(`/`);if(n===-1)throw new K(`load-config: expected <sessionId>/<path> (missing separator)`);let r=OG(AG(()=>decodeURIComponent(e.slice(0,n)))),i=AG(()=>decodeURIComponent(e.slice(n+1))).trim();if(i!==``){if(!i.startsWith(`/`))throw new K(`load-config: path must be absolute, got "${i}"`);if(!/\.(json5?|json)$/.test(i))throw new K(`load-config: path must end with .json5 or .json, got "${i}"`)}i===``?(t.sessionState.clear(r,EK),t.dlog(`info`,`load-config: override cleared (session=${r})`)):(t.sessionState.set(r,EK,i),t.dlog(`info`,`load-config: ${i} (session=${r})`))}],[xn,NG],[yn,LG],[N,BG],[P,QG],[Tn,$G],[An,oK],[En,eK],[Dn,rK],[On,iK],[kn,aK],[jn,lK],[Mn,uK],[Nn,pK],[Pn,dK],[Fn,fK],[Cn,PG],[wn,FG],[Sn,IG],[In,mK],[Ln,bK],[Rn,SK],[zn,CK],[Bn,xK],[Vn,wK],[Hn,TK]]),OK=new Set([yn,N,P,Tn,An,En,Dn,On,kn,jn,Mn,Nn,Pn,Fn,Sn,In,Ln,Rn,zn,Vn,Hn]),kK=(e,t)=>{let n=[],r=!1,i=null;for(let{verb:a,value:o}of Jn(Kn(e))){if(!i&&OK.has(a)){let e=Wn(o);e.length>0&&e[0]&&(i=e[0])}let e=DK.get(a);if(!e){n.push(`unknown effect verb "${a}"`);continue}try{e(o,t)}catch(e){e instanceof K||(r=!0),n.push(`${a}: ${e instanceof Error?e.message:String(e)}`)}}if(n.length>0){i&&t.sessionState.set(i,`click.error`,n.join(`
|
|
456
|
+
`));let e=`dispatch: ${n.join(`; `)}`;throw r?Error(e):new K(e)}};function AK(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 jK=new Map([...DK,[vn,kK]].map(([e,t])=>[e,AK(t)]));Object.freeze([...jK.keys()]);const MK=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`]),NK=[[`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`]],PK=[[`workspace.added_dirs`,`string-list`]];function FK(e){let t={missingRequired:[],typeMismatches:[],unknownTopLevelFields:[]},n=typeof e==`object`&&e&&!Array.isArray(e)?e:{};for(let[e,r]of NK){let i=RK(n,e);if(i==null)t.missingRequired.push(e);else{let n=IK(i);n!==r&&t.typeMismatches.push({path:e,expected:r,got:n})}}for(let[e,r]of PK){let i=RK(n,e),a=i===void 0?r:LK(i);a!==r&&t.typeMismatches.push({path:e,expected:r,got:a})}for(let e of Object.keys(n))MK.has(e)||t.unknownTopLevelFields.push(e);return{data:e,report:t}}function IK(e){return Array.isArray(e)?`array`:typeof e==`string`&&!e.isWellFormed()?`ill-formed string`:typeof e}function LK(e){return Array.isArray(e)&&e.every(e=>IK(e)===`string`)?`string-list`:IK(e)}function RK(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 zK(e,t){switch(e){case`vars`:return{what:e,vars:BK(t)};case`segments`:return{what:e,segments:GK(t)};case`config`:return{what:e,config:YK(t)}}}function BK(e){if(e===null)return[];let{store:t,registry:n,config:r}=e,i=UK(r),a=t.names().sort(),o=[];for(let e of a){let r=t.getNode(e),a=VK(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:HK(r.lastUpdatedMs())})}return o}function VK(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 HK(e){return e===null?null:Math.max(0,Date.now()-e)}function UK(e){let t=new Map;for(let[n,r]of Object.entries(e.variables))t.set(n,WK(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}`,WK(i));return t}function WK(e){return e.kind}function GK(e){if(e===null)return[];let{store:t,config:n,lastRenderBySegment:r}=e,i=new Set(t.names()),a=qK(n),o=KK(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:JK(t.template,n.helpers,i),placements:(o.get(e)??[]).map(e=>({id:e,lastRender:r.get(e)??null}))})}return s}function KK(e){let t=new Map;for(let n of ng(e.presets))for(let r of bh(ag(e,n).node)){if(r.kind!==`segment`)continue;let e=t.get(r.name)??[],n=gh(r);e.includes(n)||t.set(r.name,[...e,n])}return t}function qK(e){let t=[],n=new Set;for(let r of bh(Yh(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 JK(e,t,n){let r=new Set;for(let i of Dg(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 YK(e){return e===null?null:e.config}const XK=[`vars`,`segments`,`config`];function ZK(e){return typeof e==`string`&&XK.includes(e)}function QK(e){return Math.max(1,e-2)}var $K=class{written=new Map;constructor(e){this.dir=e}pathFor(e){return l.join(this.dir,`${encodeURIComponent(e)}.txt`)}sync(e,t){let n=this.pathFor(e);if(t===(this.written.get(e)??null))return null;try{return t===null?(r.rmSync(n,{force:!0}),this.written.delete(e)):(r.mkdirSync(this.dir,{recursive:!0,mode:448}),r.writeFileSync(n,t,{mode:384}),this.written.set(e,t)),null}catch(e){return`${n}: ${e.message}`}}reset(){this.written.clear();try{return r.rmSync(this.dir,{recursive:!0,force:!0}),null}catch(e){return`${this.dir}: ${e.message}`}}};function eq(e,t){for(let n of Object.entries(t))e.push(n)}const tq={ok:`info`,"bad-request":`warn`,threw:`error`};function nq(e){switch(e.kind){case`ok`:return[];case`bad-request`:return[[`problems`,e.problems.join(`; `)]];case`threw`:return[[`error`,y(e.error)]]}}const rq=/^[^\s"=\\]+$/,iq=e=>rq.test(e)?e:JSON.stringify(e);function aq(e,t,n){let r=[...e,[`took`,`${n}ms`],[`outcome`,t.kind],...nq(t)];return{level:tq[t.kind],line:`render${r.map(([e,t])=>` ${e}=${iq(t)}`).join(``)}`}}const oq=new rH,sq=new sG;Ae(oq.launchStats);const cq=new _w({counters:oq,logger:A}),lq=Oz({watchers:cq,logger:A}),{gitProvider:uq,usageStore:dq,mementoProvider:fq}=lq,pq=new oH,mq=new gU(pq,A),hq=new zU,gq=new Sm,_q=new $K($e()),vq=new tH({gitService:uq,sessionState:pq,watchers:cq},{observers:{onReload:e=>A(`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)}`)}}),yq=60*1e3;function bq(){let e=import.meta.url,n=[];e.startsWith(`file://`)&&n.push(ne(e)),t.argv[1]&&n.push(t.argv[1]);let i=new Map;for(let e of n)try{i.set(e,r.statSync(e).mtimeMs)}catch{}let a=null,o=()=>{for(let[e,t]of i)try{if(r.statSync(e).mtimeMs!==t){A(`info`,`binary mtime changed (${e}); shutting down`),a&&clearInterval(a),Iq(0);return}}catch(e){A(`warn`,`bin stat failed: ${e.message}`)}};return{arm(){i.size!==0&&(a=setInterval(o,yq),a.unref())},checkNow:o}}const xq=bq(),Sq=DR({entryUrl:import.meta.url,intervalMs:yq,releaseIntervalMs:216e5,registryUrl:t.env.CC_CANDYBAR_REGISTRY_URL??`https://registry.npmjs.org`,fetchImpl:fetch,onApplied:()=>xq.checkNow(),log:A});let Cq=null,wq=null,Tq=0;function Eq(){t.on(`uncaughtException`,e=>{A(`error`,`uncaughtException: ${e.stack||e.message}`),Iq(1)}),t.on(`unhandledRejection`,e=>{A(`error`,`unhandledRejection: ${String(e)}`),Iq(1)});for(let e of[`SIGINT`,`SIGTERM`,`SIGHUP`])t.on(e,()=>{A(`info`,`received ${e}, shutting down`),Iq(0)});try{Tq=Wt(t.env)}catch(e){A(`error`,`refusing to boot: ${e.message}`),Iq(1);return}Cq=sa(t.pid);let e=_a(ya(Cq));if(!e.decision.allow){A(`warn`,`fork-bomb breaker: ${e.decision.reason}; refusing to boot`),Iq(1);return}wq=e.registryPath,r.mkdirSync(Be(),{recursive:!0}),We(Ve()),pq.useStorage(new cH(qe(),500,A)),mq.useStorage(LU(Je(),A)),ua({anchor:la(t.env),isAlive:da,onOrphaned:e=>{A(`info`,`parent watchdog: ${e}; shutting down`),Iq(0)}}),Dq(S.createServer({allowHalfOpen:!1},e=>{Lq(e)}),Ve(),!1)}function Dq(e,n,r){e.removeAllListeners(`error`),e.removeAllListeners(`listening`),e.once(`error`,i=>{if(i.code!==`EADDRINUSE`){A(`error`,`server error: ${i.message}`),Iq(1);return}if(r){A(`info`,`lost rebind race; another daemon is alive — exiting`),t.exit(0);return}Oq(e,n)}),e.listen(n,()=>kq(n))}function Oq(e,n){let i=Zi(Qi(Ge(n)),(e,t)=>oa(e,t,{readStartTime:aa,pidAlive:da}));if(i.kind===`attach-and-exit`){A(`info`,`EADDRINUSE: ${i.reason} — exiting`),t.exit(0);return}A(`warn`,`EADDRINUSE: ${i.reason} — unlinking stale socket and rebinding`);try{r.unlinkSync(n)}catch(e){if(e.code!==`ENOENT`){A(`error`,`cannot unlink stale socket ${n}: ${e.message}`),Iq(1);return}}Dq(e,n,!0)}function kq(e){let n=ta(e);if(n.kind!==`present`){A(`warn`,`no ownable socket at bind callback (${n.kind}); exiting`),Iq(0);return}Nq(e);try{r.chmodSync(e,384)}catch(e){A(`warn`,`chmod socket failed: ${e.message}`)}A(`info`,`daemon up: pid=${t.pid} v=3 sock=${e} heapCap=${Math.round(C.getHeapStatistics().heap_size_limit/1048576)}MB rssLimit=${Math.round(Tq/1048576)}MB`),sn();let i=_q.reset();i!==null&&A(`warn`,`diagnostic dump wipe failed: ${i}`),xq.arm(),Sq.arm(),Mq(),Aq(e,n.identity)}function Aq(e,n){ia({bound:n,myPid:t.pid,readIdentity:()=>ta(e),readLease:()=>Qi(Ge(e)),shutdown:e=>Iq(e),log:A}).arm()}let jq=null;function Mq(){jq=Jt(Zt(oq.startedAt.getTime(),e=>Iq(e),{rssLimitBytes:Tq})),jq.arm()}function Nq(e){let n=$i(Ge(e),{pid:t.pid,version:3,binPath:t.argv[1],startTime:Cq});n!==null&&A(`warn`,`lease write failed: ${n}`)}let Pq=0,Fq=!1;function Iq(e){if(!Fq){Fq=!0,setTimeout(()=>t.kill(t.pid,`SIGKILL`),500);try{uq.close()}catch(e){A(`warn`,`gitService close failed: ${e.message}`)}try{dq.close()}catch(e){A(`warn`,`usageStore close failed: ${e.message}`)}try{cq.closeAll()}catch(e){A(`warn`,`watcherRegistry close failed: ${e.message}`)}try{pq.flush()}catch(e){A(`warn`,`sessionState flush failed: ${e.message}`)}ea(Ke(),t.pid),wq!==null&&va(wq,t.pid,ha,e=>r.unlinkSync(e)),t.exit(e)}}function Lq(e){Pq++,oq.inFlight=Pq;let t=!1,n=(n,r)=>{if(t){r!==null&&A(`warn`,`exit-after-flush dropped: an earlier responder settled this socket`);return}t=!0;let i=r===null?void 0:()=>Iq(r);try{e.end(k(n),i)}catch(e){A(`warn`,`response write failed: ${e.message}`),i?.()}},r=!1,i=setTimeout(()=>{r=!0,oq.requestsTimedOut++,n({ok:!1,error:`request exceeded 200ms`,code:`TIMEOUT`,daemonV:3},null)},200),a=_t(e=>{Bq(e,()=>r).then(e=>n(e.resp,e.exitAfterFlush)).catch(e=>{A(`error`,`handler threw: ${y(e)}`),n(zq(e),null)})},e=>{A(`warn`,`frame parse failed: ${e.message}`),n({ok:!1,error:e.message,code:`BAD_REQUEST`,daemonV:3},null)});e.on(`data`,a),e.on(`error`,e=>{A(`warn`,`socket error: ${e.message}`)}),e.on(`close`,()=>{clearTimeout(i),Pq=Math.max(0,Pq-1),oq.inFlight=Pq})}const Rq=e=>({resp:e,exitAfterFlush:null}),zq=e=>({ok:!1,error:e instanceof Error?e.message:y(e),code:`RENDER_FAILED`,daemonV:3});async function Bq(e,t){if(!e||typeof e!=`object`||typeof e.v!=`number`)return Rq({ok:!1,error:`malformed request`,code:`BAD_REQUEST`,daemonV:3});if(e.v!==3)return e.v>3?A(`info`,`version mismatch: client=${e.v} > daemon=3; binary likely upgraded — exiting after the response flushes`):A(`info`,`version mismatch: client=${e.v} < daemon=3; client is stale — staying up`),{resp:{ok:!1,error:`protocol v${e.v} not supported (daemon at v3)`,code:`VERSION_MISMATCH`,daemonV:3},exitAfterFlush:e.v>3?0:null};if(e.kind===`shutdown`)return{resp:{ok:!0,output:``},exitAfterFlush:0};if(e.kind===`stats`)return Rq({ok:!0,stats:oq.snapshot({gitCache:uq.getStats(),usageCache:dq.getStats(),renderCacheSize:vq.size,effectCache:gq.getStats(),watchersActive:cq.size(),nextRestartReason:jq?.describeNextRestart()??null,handlerProbes:sq.list()})});if(e.kind===`render`){oq.requestsTotal++;let n=new Date,r=kw(n),i=n.getTime(),a=[],o=await Jq(e,r,a).catch(e=>({outcome:{kind:`threw`,error:e},resp:zq(e)}));o.outcome.kind!==`ok`&&oq.requestsErrored++,eq(a,{timedOut:t()?`Y`:`N`});let{level:s,line:c}=aq(a,o.outcome,Date.now()-i);return A(s,c),Rq(o.resp)}if(e.kind===`click`)return Rq(qq(e.verb,e.value,ht(e.clientVersion)));if(e.kind===`debug`){if(!ZK(e.what))return Rq({ok:!1,error:`unknown debug 'what': ${String(e.what)} (have: ${XK.join(`, `)})`,code:`BAD_REQUEST`,daemonV:3});let t=vq.firstState(),n=t===null?null:{store:t.store,registry:t.registry,config:t.config,compiled:t.compiled,lastRenderBySegment:e.what===`segments`?Gq(t.lastRenderCellsBySegment,t.config.globals.charset??`unicode`,t.config.globals.colorCompatibility??`truecolor`):Wq};return Rq({ok:!0,debug:zK(e.what,n)})}return Rq({ok:!1,error:`unknown kind`,code:`BAD_REQUEST`,daemonV:3})}function Vq(e,t){let{values:n,tokens:r}=b({args:e.slice(1),options:{config:{type:`string`}},strict:!1,tokens:!0,allowPositionals:!0}),i=[...new Set((r??[]).filter(e=>e.kind===`option`&&e.name!==`config`).map(e=>`--${e.name}`))];return{configFile:rF(t,n.config),unknownFlagsError:i.length>0?`Unknown flags: ${i.join(`, `)}`:null}}const Hq={sessionState:pq,dlog:A,applyUpdate:()=>Sq.act(),doctor:HW(e=>{let t=[e.projectDir,e.cwd,e.configFile??void 0];vq.reload(...t);let n=vq.getOrCreate(...t);return{layers:n.configLayers,error:n.lastError,warning:n.lastWarning,unused:n.state.unused,config:n.state.config}}),probes:sq,memento:fq,claudeInput:DG(),history:mq,navigation:hq,configFor:e=>vq.getOrCreate(e.projectDir,e.cwd,e.configFile??void 0).state.config,reloadConfig:e=>vq.reload(e.projectDir,e.cwd,e.configFile??void 0)};Hq.reloadConfig;const Uq={endcaps:`powerline`,colorCompatibility:`truecolor`,wrap:!0,padding:1,charset:Wp,width:1/0},Wq=new Map;function Gq(e,t,n){let r=new Map;for(let[i,a]of e)r.set(i,Im(a,{...Uq,charset:t,colorCompatibility:n}));return r}const Kq={...lq,history:e=>mq.depth(e)};function qq(e,t,n){let r=jK.get(e);if(!r)return{ok:!1,error:`unknown click verb: ${e}`,code:`BAD_REQUEST`,daemonV:3};try{return r(t,{...Hq,clientVersion:n}),{ok:!0,output:``}}catch(e){let t=e instanceof K?`BAD_REQUEST`:`RENDER_FAILED`;return{ok:!1,error:String(e instanceof Error?e.message:e),code:t,daemonV:3}}}async function Jq(e,t,n){let{report:r}=FK(e.hookData);for(let e of r.unknownTopLevelFields)A(`info`,`schema: unknown field '${e}' — Anthropic may have added it`);let i=[];for(let e of r.missingRequired)i.push(`missing required field '${e}'`);for(let{path:e,expected:t,got:n}of r.typeMismatches)i.push(`field '${e}' expected ${t}, got ${n}`);if(f(e.cwd)||i.push(`request 'cwd' is not an absolute path: "${e.cwd}"`),i.length>0)return{outcome:{kind:`bad-request`,problems:i},resp:{ok:!1,error:`malformed hookData: ${i.join(`; `)}`,code:`BAD_REQUEST`,daemonV:3}};eq(n,{sid:e.hookData.session_id,at:t.toFixed(3)});let a=e.hookData.workspace.project_dir,{configFile:o,unknownFlagsError:s}=Vq(e.args,e.cwd),c=e.hookData.session_id,l=ot(e),u=st(e,l),d=ct(u);eq(n,{termCols:String(l.termCols??`?`),termRows:String(l.termRows??`?`),refused:u.map(e=>e.hint).join(`,`)||`-`});let p=JSON.stringify(l);pq.get(c,`client-hints`)!==p&&pq.set(c,hK,p);let m=pq.get(c,`config-override`)??o??l.configEnv,h=vq.getOrCreate(a,e.cwd,m),g=GG({projectDir:a,cwd:e.cwd,configFile:m??null});pq.get(c,`render-origin`)!==g&&pq.set(c,WG,g);let _=l.termCols,v=QK(_??120),y=Lm(l.termRows);eq(n,{width:String(v)});let{authoredRoots:b}=h.state,x=t=>pq.get(e.hookData.session_id,t),S=XI(h.state.config,x,e=>b.has(e)),C=await hL(e.hookData,t,{...Kq,navigation:e=>hq.depth(e,pq,aR(h.state.config))},e.cwd,h.state.neededInputPaths(S.preset),S,l,{...KL(h.state.config,h.state.fileHeldSettings,x),configPath:h.configLayers.includes(h.configHome)?h.configHome:null});eq(n,{prompts:String(C.metrics?.messageCount??`-`),nonPrompts:String(C.metrics?.nonPrompts??`-`),pr:tL(C.git)});let ee=[],te=ZI(S,v),ne=gq.of(c),re=PV(h.state.config,h.state.compiled,h.state.store,h.state.registry,C,t,te,{perSegmentSink:h.state.lastRenderCellsBySegment,onRenderWarning:e=>ee.push(e)},{...QI(S),effects:ne}),ie=pq.get(e.hookData.session_id,`click.error`);ie&&pq.clear(e.hookData.session_id,`click.error`);let ae=[s,d,h.lastError,ie].filter(Boolean).join(`
|
|
457
|
+
`),w=Sq.notice({sessionId:c,dismissed:pq.get(c,dR),enabled:S.updateNotice}),T=h.lastError===null?null:h.failedFile,oe=[...h.lastWarning===null?[]:[{kind:`load`,message:h.lastWarning}],...ee],E=Hm(ae,w,oe.map(e=>e.message).join(`
|
|
458
|
+
`)),se=_q.sync(c,E===null?null:Wm(E));se!==null&&A(`warn`,`diagnostic dump failed: ${se}`);let ce=Gm(re,E,{fullText:se===null?{kind:`file`,path:_q.pathFor(c)}:{kind:`unavailable`,reason:se},failedConfigFile:T},{width:v,rowCap:y,colorCompatibility:S.colorCompatibility}),le=uq.getStats(),ue=dq.getStats(),de=ne.lastFrame(),fe=de.own.map(e=>`${e.placement}:${e.effect}@${e.t.toFixed(3)}`).join(`,`)||`-`,pe=e=>e.map(e=>`${e.placement}@${e.t.toFixed(3)}`).join(`,`)||`-`,me=oe.map(e=>{switch(e.kind){case`rule`:return`rule:${e.slot}`;case`refresh`:return`refresh:${e.variable}`;case`load`:case`band-floor`:case`when`:return e.kind}}).join(`,`)||`-`;return eq(n,{git:`${le.size}/${le.hits}h/${le.misses}m`,usage:`${ue.size}/${ue.hits}h/${ue.misses}m`,effect:de.effect,effectT:de.t.toFixed(3),effectRows:`${de.made}made/${de.reused}reused`,effectOwn:fe,fadeBasis:de.basis,stateRev:String(de.revision),fades:pe(de.fades),leaves:pe(de.leaves),err:ae?`Y`:`N`,upd:String(w.length),warn:me}),{outcome:{kind:`ok`},resp:{ok:!0,output:ce+`
|
|
459
|
+
`}}}const Yq={connectMs:200,budgetMs:500};async function Xq(e,n){let r=n.includes(`--json`),i=await Zq(e);if(i.kind!==`ok`&&(t.stderr.write(`${e}: ${Tt(i)}\n`),t.exit(1)),r){t.stdout.write(JSON.stringify(i.value,null,2)+`
|
|
460
|
+
`);return}t.stdout.write(Qq(i.value))}function Zq(e){return yt({kind:`debug`,what:e},Yq,e=>`debug`in e?e.debug:void 0)}function Qq(e){switch(e.what){case`vars`:return $q(e.vars);case`segments`:return eJ(e.segments);case`config`:return tJ(e.config);default:return e}}function $q(e){if(e.length===0)return`no variables (DSL not active)
|
|
461
|
+
`;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?``:` ${rJ(a.ageMs)}`,o=a.lastError?` ✗ ${a.lastError.message}`:``;t.push(` ${a.name.padEnd(n)} ${(a.source??`—`).padEnd(r)} ${a.type.padEnd(i)} ${nJ(a.value)}${e}${o}`)}return t.join(`
|
|
462
462
|
`)+`
|
|
463
|
-
`}function
|
|
463
|
+
`}function eJ(e){if(e.length===0)return`no segments (DSL not active)
|
|
464
464
|
`;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(`
|
|
465
465
|
`)+`
|
|
466
|
-
`}function
|
|
466
|
+
`}function tJ(e){return e===null?`config: DSL not active
|
|
467
467
|
`:JSON.stringify(e,null,2)+`
|
|
468
|
-
`}function
|
|
468
|
+
`}function nJ(e){let t=typeof e==`string`?e:JSON.stringify(e);return t.length>60?t.slice(0,57)+`…`:t}function rJ(e){return e<1e3?`${e}ms`:e<6e4?`${(e/1e3).toFixed(1)}s`:`${Math.floor(e/6e4)}m`}function iJ(){let e=oJ();return e===null?null:r.readFileSync(e,`utf-8`)}function aJ(){let e;try{e=iJ()}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 oJ(){let e=l.join(`schema`,`cc-candybar.schema.json`),n=t.argv[1];if(n===void 0)return null;let i=l.dirname(l.resolve(n));for(;;){let t=l.join(i,e);if(r.existsSync(t))return t;let n=l.dirname(i);if(n===i)return null;i=n}}function sJ(e,t){return rF(t,e.CC_CANDYBAR_CONFIG)}const cJ=5e3;function lJ(e,t,n){let r=`/home/tester`,i=Math.floor(n),a=`test0a1b-2c3d-4e5f-6a7b-8c9d0e1f2a3b`,o={current_dir:`${r}/code/cc-candybar/src`,project_dir:`${r}/code/cc-candybar`,added_dirs:[]};return{hook_event_name:`Status`,session_id:a,version:`1.15.0`,home:r,cwd:`${r}/code/cc-candybar/src`,transcript_path:`${r}/.claude/projects/x/test.jsonl`,model:{id:`claude-opus-4-8`,display_name:`Opus 4.8`},workspace:o,git:{repoName:`cc-candybar`,repoUrl:`https://github.com/promptctl/cc-candybar`,branch:`main`,sha:`abc1234`,ahead:2,behind:1,staged:3,unstaged:2,untracked:1,conflicts:0,upstream:`origin/main`,tracking:`tracked`,stash:1,status:`dirty`,operation:`rebase`,timeSinceCommit:780},session:{cost:.39,tokens:241400},today:{cost:12.5,tokens:34e5},context:{totalTokens:48487,contextLeft:24},metrics:{lastResponseTime:8.2,responseTime:4.2,sessionDuration:930,messageCount:8,linesAdded:512,linesRemoved:88},block:{nativeUtilization:63,resetsAt:i+2*3600},weekly:{percentage:21,resetsAt:i+5*86400},cache:{expiresAt:i+900},tmux:{pane:`%0`,session:`work`},host:{name:`tester-box`,user:`tester`,ssh:!0},autocompact:GO(4e5,1e6),...$I(e),history:{undo:1,redo:1,sinceEdit:1},navigation:{back:1},unsaved:1,resettable:Ea(()=>!0),themeDefault:{differs:!0,theme:`<theme>`},resumeCommand:YI(o,a,void 0),configPath:t??`${r}/.config/cc-candybar/config.json5`}}function uJ(e,t){let n=IF(e,e),r=zF(n);return r!==null&&t.push(r),n.kind===`chain`?n.layers:[]}async function dJ(e,n=t.cwd()){let i=[],a=rF(n,e)??null,o=a===null?uJ(n,i):[a];if(a!==null){let e;try{e=r.statSync(a,{throwIfNoEntry:!1})}catch(e){return{kind:`unreadable`,path:a,message:e instanceof Error?e.message:String(e)}}if(e!==void 0&&!e.isFile())return{kind:`unreadable`,path:a,message:`not a file`}}let s=VF(n,n);s!==null&&i.push(s);try{return{kind:`clean`,layers:o,warnings:i,rendered:await mJ(o,n,i)}}catch(e){let t=e;return typeof t==`object`&&t&&typeof t.code==`string`&&typeof t.path==`string`&&o.includes(t.path)&&typeof t.message==`string`?{kind:`unreadable`,path:t.path,message:t.message}:(e instanceof aT&&i.push(...e.warnings),{kind:`fatal`,layers:o,message:e instanceof aT||e instanceof Error?e.message:String(e),warnings:i})}}async function fJ(e,t,n){let r=JF(e,_I,{entered:()=>{},warned:e=>n.push(...e)},{projectDir:t,cwd:t}),{config:i}=r,a=new KV,o=new $w(a,i.globals.default_empty_value??``,void 0,new oH);try{let s=OV(i,o,{cwd:t});n.push(...s.loadWarnings);let c=await o.settled(cJ);return c.length>0&&n.push(`source${c.length===1?``:`s`} still running after ${cJ} 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 pJ({layers:e,config:t,compiled:n,store:r,registry:i},a,o,s){let c=new Map,l=new Set;return{rendered:PV(t,n,r,i,lJ(a,e.at(-1)??null,s),s,ZI(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:}}},QI(a)),failures:c,advisories:l}}async function mJ(e,t,n){let r=await fJ(e,t,n),{config:i}=r,a=kw(new Date);try{let e=ER();try{aR(i),wj(i)}finally{e()}let t=rg(null,i.globals.preset,i.presets),o=(e,t)=>{let n=XI(i,t=>t===`preset`?e:null,()=>t),o;try{o=pJ(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),...ng(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(`
|
|
469
469
|
`)]:[]];if(p.length>0||d===void 0)throw Error(p.join(`
|
|
470
|
-
`));return d}finally{r.registry.dispose()}}function
|
|
471
|
-
`,kick:!0,debug:`daemon unavailable (transient: ${e.cause}: ${e.message}) — kicking daemon`};case`permanent`:return{output:
|
|
470
|
+
`));return d}finally{r.registry.dispose()}}function hJ(e){return e.map(e=>`warning: ${e}\n`).join(``)}function gJ(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:hJ(e.warnings),code:0};case`fatal`:return{stdout:``,stderr:hJ(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 _J=`--render`,vJ=`Usage: cc-candybar check [${_J}] [config-file]\n`;function yJ(e){let t=e.filter(e=>e.startsWith(`--`)),n=e.filter(e=>!e.startsWith(`--`)),r=t.filter(e=>e!==_J);return r.length>0?{kind:`usage`,message:`check: unknown option ${r.join(` `)}\n${vJ}`}:n.length>1||n[0]===``?{kind:`usage`,message:`check: expected at most one non-empty path\n${vJ}`}:{kind:`run`,target:n[0],render:t.includes(_J)}}async function bJ(e){let n=yJ(e),r=n.kind===`usage`?{stdout:``,stderr:n.message,code:2}:gJ(await dJ(n.target??sJ(t.env,t.cwd())),n.render);t.stdout.write(r.stdout),t.stderr.write(r.stderr),t.exit(r.code)}const xJ=`${Zd}${Xd}`;function SJ(e){return`${xJ}⚠ cc-candybar: ${CJ(e)}[0m\n`}function CJ(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: ${Yd(e.message,60)}`;case`render_failed`:return`render failed: ${Yd(e.message,60)}`;case`malformed_response`:return`malformed daemon response: ${Yd(e.message,60)}`}}function wJ(e){switch(e.kind){case`ok`:return{output:e.value,kick:!1,debug:null};case`transient`:return{output:`
|
|
471
|
+
`,kick:!0,debug:`daemon unavailable (transient: ${e.cause}: ${e.message}) — kicking daemon`};case`permanent`:return{output:SJ(e),kick:!1,debug:`daemon refused request (permanent: ${e.cause}) — not kicking`}}}function TJ(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 EJ=[`SSH_CONNECTION`,`SSH_CLIENT`,`SSH_TTY`];function DJ(e,t,n){return{termCols:TJ(e.COLUMNS,n.columns),termRows:TJ(e.LINES,n.rows),ssh:EJ.some(t=>(e[t]??``)!==``),tmux:PD(e),configEnv:sJ(e,t),claudeConfigDir:ci(e,t),mementoEnv:nt(e,t),terminalEnv:it(e)}}const OJ=` (fix: click the settings menu (${Qn} by default) › 🧰 tools › 🩺 doctor, then [fix] on the bar)`,kJ=`mark them ✓ shapes or ✗ boxes in the bar's doctor, and this command reads your mark: the settings menu (${Qn} by default) › 🧰 tools › 🩺 doctor`;function AJ({check:e,verdict:t}){return t.ok?`✓ ${e.label}\n`:`✗ ${e.label} — ${t.reason}${t.fix===void 0?``:OJ}\n`+(t.more??[]).map(e=>` ${e}\n`).join(``)+(t.sighting===void 0?``:` look: ${t.sighting.glyphs} — ${kJ}\n`)}function jJ(e){let t={sessionState:new oH},n=$V(e.projectDir,e.cwd,e.configFile??void 0,t),r=n.state??eH(e.cwd,e.projectDir,t);return r.registry.dispose(),{layers:n.layers,error:n.error,warning:n.warning,unused:r.unused,config:r.config}}async function MJ(e,t,n,r,i=void 0){let a;try{a={...XW(e,DJ(n,r,{}),{projectDir:r,cwd:r,configFile:rF(r,i)??sJ(n,r)??null},()=>null),urlHandler:await fG(t),askedBy:`command`}}catch(e){return{stdout:``,stderr:`doctor: ${e instanceof Error?e.message:String(e)}\n`,code:2}}let o=bO(a);return{stdout:o.map(AJ).join(``),stderr:``,code:+!o.every(e=>e.verdict.ok)}}async function NJ(e){(e.length>1||e[0]===``||e[0]?.startsWith(`--`))&&(t.stderr.write(`doctor: expected at most one config file
|
|
472
472
|
Usage: cc-candybar doctor [config-file]
|
|
473
|
-
`),t.exit(2));let n=t.cwd(),r=await
|
|
473
|
+
`),t.exit(2));let n=t.cwd(),r=await MJ(HW(jJ),gG(),t.env,n,e[0]);t.stdout.write(r.stdout),t.stderr.write(r.stderr),t.exit(r.code)}const PJ=e=>e.some(e=>t.argv.includes(e));function FJ(){console.log(jD)}async function IJ(){try{PJ(kD.help)&&(FJ(),t.exit(0)),PJ(kD.version)&&(console.log(`cc-candybar ${Et}`),t.exit(0));let e=t.argv[2];if(e===`install`&&(await Yi(t.argv.slice(3)),t.exit(0)),e===`install-url-handler`&&(Wi(),t.exit(0)),e===`url-handle`){await Ki(t.argv[3]);return}if(e===`daemon`){Eq();return}if(e===`daemon-stats`&&(await $W(t.argv.slice(3)),t.exit(0)),e===`check`||e===`lint`){await bJ(t.argv.slice(3));return}if(e===`schema`){aJ();return}if(e===`doctor`){await NJ(t.argv.slice(3));return}ZK(e)&&(await Xq(e,t.argv.slice(3)),t.exit(0)),t.stdin.isTTY===!0&&(console.error(`Error: This tool requires input from Claude Code
|
|
474
474
|
|
|
475
475
|
cc-candybar is designed to be used as a Claude Code statusLine command.
|
|
476
476
|
It reads hook data from stdin and outputs formatted statusline.
|
|
@@ -486,4 +486,4 @@ Add to ~/.claude/settings.json:
|
|
|
486
486
|
Run with --help for more options.
|
|
487
487
|
|
|
488
488
|
To test output manually:
|
|
489
|
-
echo '{"session_id":"test-session","workspace":{"project_dir":"/path/to/project"},"model":{"id":"claude-sonnet-4-5","display_name":"Claude"}}' | cc-candybar`),t.exit(1)),D(`Working directory: ${t.cwd()}`),D(`Process args:`,t.argv);let r=await n(t.stdin);D(`Received hook data:`,JSON.stringify(r,null,2)),r||(console.error(`Error: No input data received from stdin`),
|
|
489
|
+
echo '{"session_id":"test-session","workspace":{"project_dir":"/path/to/project"},"model":{"id":"claude-sonnet-4-5","display_name":"Claude"}}' | cc-candybar`),t.exit(1)),D(`Working directory: ${t.cwd()}`),D(`Process args:`,t.argv);let r=await n(t.stdin);D(`Received hook data:`,JSON.stringify(r,null,2)),r||(console.error(`Error: No input data received from stdin`),FJ(),t.exit(1));let i=wJ(await At(r,t.argv,t.cwd(),DJ(t.env,t.cwd(),t.stderr)));i.debug!==null&&D(i.debug),i.kick&&Qt(),t.stdout.write(i.output),t.exit(0)}catch(e){let n=e instanceof Error?e.message:String(e);console.error(`Error generating statusline:`,n),t.exit(1)}}IJ();export{};
|