@promptctl/cc-candybar 1.41.1 → 1.41.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.mjs +37 -37
- package/package.json +6 -6
- package/src/config/dsl-types.ts +4 -4
- package/src/config/loader/helpers.ts +1 -1
- package/src/daemon/limits.ts +9 -8
- package/src/dsl/render.ts +30 -30
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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,statSync as o,watch as s}from"node:fs";import c,{basename as l,dirname as u,join as d}from"node:path";import f,{homedir as p}from"node:os";import{spawn as m,spawnSync as h}from"node:child_process";import g from"node:net";import _ from"node:v8";import{URL as v,URLSearchParams as y,fileURLToPath as b}from"node:url";import{parseArgs as x}from"node:util";import{get as S}from"node:https";import{createHash as C}from"node:crypto";import{setTimeout as w}from"node:timers/promises";import{open as ee,readFile as T,readdir as te,stat as ne}from"node:fs/promises";import{createInterface as re}from"node:readline";import{clearInterval as E,setInterval as D}from"node:timers";var ie=Object.create,ae=Object.defineProperty,oe=Object.getOwnPropertyDescriptor,se=Object.getOwnPropertyNames,ce=Object.getPrototypeOf,le=Object.prototype.hasOwnProperty,ue=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),de=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=se(t),a=0,o=i.length,s;a<o;a++)s=i[a],!le.call(e,s)&&s!==n&&ae(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=oe(t,s))||r.enumerable});return e},fe=(e,t,n)=>(n=e==null?{}:ie(ce(e)),de(t||!e||!e.__esModule?ae(n,`default`,{value:e,enumerable:!0}):n,e));function O(e,...t){process.env.CC_CANDYBAR_DEBUG&&console.error(`[DEBUG] ${e}`,...t)}const pe={"click.pbcopy":1e3,"click.open":1e3},me=new Map;function he(e){let t=pe[e];if(t===void 0)return{allowed:!0};let n=me.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 ge(e){me.set(e,Date.now())}function k(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 _e=null;function ve(e){_e=e}async function ye(e){let t=he(e.category);if(!t.allowed)return k(e.category,t.minIntervalMs,t.sinceLastMs);ge(e.category);let n=Date.now();return _e?.onStart(e.category),new Promise(t=>{let r;try{r=m(e.bin,e.args??[],{cwd:e.cwd,env:e.env,stdio:[`pipe`,`pipe`,`pipe`]})}catch(r){_e?.onEnd(e.category,Date.now()-n),t({ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:r instanceof Error?r.message:String(r)});return}let i=``,a=``,o=!1,s=null,c=null,l=!1,u=r=>{o||(o=!0,s&&clearTimeout(s),c&&clearTimeout(c),_e?.onEnd(e.category,Date.now()-n),t(r))};r.stdout?.on(`data`,e=>{i+=e.toString(`utf8`)}),r.stderr?.on(`data`,e=>{a+=e.toString(`utf8`)}),r.on(`error`,e=>{u({ok:!1,reason:`spawn-error`,stdout:i,stderr:a,exitCode:null,signal:null,error:e.message})}),r.on(`close`,(e,t)=>{if(l){u({ok:!1,reason:`timeout`,stdout:i,stderr:a,exitCode:e,signal:t});return}if(e===0){u({ok:!0,stdout:i,stderr:a,exitCode:e});return}u({ok:!1,reason:t?`signal`:`non-zero`,stdout:i,stderr:a,exitCode:e,signal:t})}),e.timeoutMs&&e.timeoutMs>0&&(s=setTimeout(()=>{l=!0,r.pid!==void 0&&(r.kill(`SIGTERM`),c=setTimeout(()=>{r.kill(`SIGKILL`)},250))},e.timeoutMs)),e.stdinInput!==void 0&&r.stdin?r.stdin.end(e.stdinInput):r.stdin&&r.stdin.end()})}function be(e){let t=he(e.category);if(!t.allowed)return k(e.category,t.minIntervalMs,t.sinceLastMs);ge(e.category);let n=Date.now();_e?.onStart(e.category);let r=[`pipe`,`pipe`,`pipe`];try{let t=h(e.bin,e.args??[],{cwd:e.cwd,env:e.env,input:e.stdinInput,timeout:e.timeoutMs&&e.timeoutMs>0?e.timeoutMs:void 0,stdio:r,encoding:`utf8`});_e?.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:t.error.message};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 _e?.onEnd(e.category,Date.now()-n),{ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:t instanceof Error?t.message:String(t)}}}function xe(e){let t=he(e.category);if(!t.allowed)return k(e.category,t.minIntervalMs,t.sinceLastMs);ge(e.category);let n=Date.now();_e?.onStart(e.category);let r=Se(e);return _e?.onEnd(e.category,Date.now()-n),r}function Se(e){let t;try{t=m(e.bin,e.args??[],{cwd:e.cwd,env:e.env,detached:!0,stdio:`ignore`})}catch(e){return{ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:e instanceof Error?e.message:String(e)}}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 Ce(e){let t=process.env[e];return t&&t.length>0?t:void 0}function we(){let e=Ce(`XDG_STATE_HOME`)??c.join(f.homedir(),`.local`,`state`);return c.join(e,`cc-candybar`)}function Te(){let e=Ce(`XDG_CACHE_HOME`)??c.join(f.homedir(),`.cache`);return c.join(e,`cc-candybar`)}function Ee(){return we()}function De(){let e=process.env.CC_CANDYBAR_SOCKET;if(e)return e;let t=f.userInfo().uid;return c.join(`/tmp`,`cc-candybar-${t}`,`socket`)}function Oe(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=f.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 ke(e){Oe(c.dirname(e));for(let t of[e,A(e)])try{if(r.lstatSync(t).isSymbolicLink())throw Error(`path is a symlink: ${t}`)}catch(e){if(e.code!==`ENOENT`)throw e}}function A(e){return`${e}.lease`}function Ae(){return A(De())}function je(){return c.join(we(),`session-state.json`)}function Me(){return c.join(we(),`config-overrides.json`)}function Ne(){let e=process.env.CC_CANDYBAR_DAEMON_REGISTRY_DIR;if(e)return e;let t=f.userInfo().uid;return c.join(`/tmp`,`cc-candybar-${t}`,`daemons`)}function Pe(){return c.join(we(),`spawn.lock`)}function Fe(){return c.join(we(),`spawn.cooldown`)}function Ie(){return c.join(we(),`spawn.backoff`)}function Le(){return c.join(we(),`daemon.log`)}function Re(e){let t=Be(e.termCols),n=Ve(e.ssh);return{...t!==void 0&&{termCols:t},...n!==void 0&&{ssh:n}}}const ze=1e4;function Be(e){if(typeof e!=`number`||!Number.isFinite(e))return;let t=Math.floor(e);if(!(t<=0))return t>ze?ze:t}function Ve(e){return typeof e==`boolean`?e:void 0}var He=class extends Error{constructor(e){super(e),this.name=`ProtocolError`}};function Ue(e){let t=Buffer.from(JSON.stringify(e),`utf8`),n=Buffer.alloc(4);return n.writeUInt32BE(t.length,0),Buffer.concat([n,t])}function We(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 He(`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 He(e instanceof Error?e.message:String(e));e instanceof Error&&(n.cause=e),t(n);return}}}}function Ge(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=We(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(Ue(t))})}async function Ke(e,t,n){let r=null;try{r=await Ze(De(),t.connectMs);let i=await Ge(r,{v:3,...e},t.budgetMs);return Ye(e.kind,i,n)}catch(e){return Xe(e)}finally{r&&r.destroy()}}function qe(e,t){return typeof e==`string`?e:t}function Je(e){return typeof e==`number`&&Number.isInteger(e)&&e>=0?e:0}function Ye(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=qe(r.error,`(no error message)`);switch(r.code){case`VERSION_MISMATCH`:return{kind:`permanent`,cause:`version_mismatch`,clientV:3,daemonV:Je(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 Xe(e){if(e instanceof He||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 Ze(e,t){return new Promise((n,r)=>{let i=g.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 Qe(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 $e={connectMs:50,budgetMs:150},et={connectMs:50,budgetMs:200};function tt(e){let t=e.output;return typeof t==`string`?t:void 0}function nt(e,t,n,r){return Ke({kind:`render`,hookData:e,args:t,cwd:n,...r},$e,tt)}function rt(e,t){return Ke({kind:`click`,verb:e,value:t},et,tt)}let it=null;function at(e){if(it!==null)return it;r.mkdirSync(c.dirname(e),{recursive:!0});try{it=r.statSync(e).size}catch{it=0}return it}function ot(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{}it=0}function j(e,t){let n=`${new Date().toISOString()} [${e}] ${t}\n`;try{let e=Le(),t=at(e);r.appendFileSync(e,n),it=t+Buffer.byteLength(n,`utf8`),it>=5242880&&ot(e)}catch(e){it=null;try{process.stderr.write(`${n}cc-candybar: daemon.log unwritable: ${e.message}\n`)}catch{}}}const st=`CC_CANDYBAR_RSS_LIMIT_MB`;function ct(e){let t=e[st];if(t===void 0)return 2048;let n=/^\d+$/.test(t)?Number(t):NaN;if(!Number.isSafeInteger(n)||n<=0)throw Error(`${st} must be a positive integer (MB), got ${JSON.stringify(t)}`);return n}function lt(e){return ct(e)*2}const ut=1024*1024;function dt(e){return ct(e)*ut}function ft(e){let t=e.rssLimitBytes??2048*ut,n=e.snapshotsKeep??3,r=!1;function i(){if(r)return!0;let i=e.rssBytes();if(i<=t)return!1;r=!0,e.log(`warn`,`RSS ${i} > limit ${t}; writing heap snapshot then shutting down`);try{let t=new Date(e.now()).toISOString().replace(/[:.]/g,`-`),r=c.join(e.snapshotDir,`heap-${t}-${e.pid}.heapsnapshot`),i=e.writeHeapSnapshot(r);e.log(`info`,`heap snapshot written: ${i}`),pt(e.listSnapshots(),n,e.removeFile)}catch(t){e.log(`warn`,`heap snapshot failed: ${t.message}`)}return e.shutdown(0),!0}function a(){let n=e.rssBytes();return n>t*.75?`rss ${n} approaching limit ${t}`:null}function o(e=6e4){let t=setInterval(()=>{i()},e);return t.unref(),{disarm:()=>clearInterval(t)}}return{checkRss:i,describeNextRestart:a,arm:o}}function pt(e,t,n){let r=[...e].sort((e,t)=>{let n=e.slice(e.lastIndexOf(`/`)+1);return t.slice(t.lastIndexOf(`/`)+1).localeCompare(n)});for(let e of r.slice(t))try{n(e)}catch{}}function mt(e,t,n={}){let i=Ee();return{now:()=>Date.now(),pid:process.pid,snapshotDir:i,log:j,rssBytes:()=>process.memoryUsage().rss,writeHeapSnapshot:e=>_.writeHeapSnapshot(e),listSnapshots:()=>{try{return r.readdirSync(i).filter(e=>e.startsWith(`heap-`)&&e.endsWith(`.heapsnapshot`)).map(e=>c.join(i,e))}catch{return[]}},removeFile:e=>r.unlinkSync(e),shutdown:t,startedAtMs:e,...n}}function ht(e={}){if(jt()!==null)return;let n=e.spawn??Mt,r=Ot();if(r.kind===`contended`){let e=_t();e!==null&&e>2e3&&(t.stderr.write(`cc-candybar: spawn-lock held ${e}ms (likely crashed holder) — spawning unlocked\n`),gt(n));return}if(r.kind===`error`){t.stderr.write(`cc-candybar: spawn-lock unavailable (${r.reason}) — spawning unlocked\n`),gt(n);return}try{gt(n)}finally{At()}}function gt(e){wt()&&vt(e)}function _t(){try{let e=r.statSync(Pe());return Date.now()-e.mtimeMs}catch{return null}}function vt(e){try{e()||t.stderr.write(`cc-candybar: daemon spawn returned false (unable to resolve script path?)
|
|
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,statSync as o,watch as s}from"node:fs";import c,{basename as l,dirname as u,join as d}from"node:path";import f,{homedir as p}from"node:os";import{spawn as m,spawnSync as h}from"node:child_process";import g from"node:net";import _ from"node:v8";import{URL as v,URLSearchParams as y,fileURLToPath as b}from"node:url";import{parseArgs as x}from"node:util";import{get as S}from"node:https";import{createHash as C}from"node:crypto";import{setTimeout as w}from"node:timers/promises";import{open as ee,readFile as T,readdir as te,stat as ne}from"node:fs/promises";import{createInterface as re}from"node:readline";import{clearInterval as E,setInterval as D}from"node:timers";var ie=Object.create,ae=Object.defineProperty,oe=Object.getOwnPropertyDescriptor,se=Object.getOwnPropertyNames,ce=Object.getPrototypeOf,le=Object.prototype.hasOwnProperty,ue=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),de=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=se(t),a=0,o=i.length,s;a<o;a++)s=i[a],!le.call(e,s)&&s!==n&&ae(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=oe(t,s))||r.enumerable});return e},fe=(e,t,n)=>(n=e==null?{}:ie(ce(e)),de(t||!e||!e.__esModule?ae(n,`default`,{value:e,enumerable:!0}):n,e));function O(e,...t){process.env.CC_CANDYBAR_DEBUG&&console.error(`[DEBUG] ${e}`,...t)}const pe={"click.pbcopy":1e3,"click.open":1e3},me=new Map;function he(e){let t=pe[e];if(t===void 0)return{allowed:!0};let n=me.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 ge(e){me.set(e,Date.now())}function k(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 _e=null;function ve(e){_e=e}async function ye(e){let t=he(e.category);if(!t.allowed)return k(e.category,t.minIntervalMs,t.sinceLastMs);ge(e.category);let n=Date.now();return _e?.onStart(e.category),new Promise(t=>{let r;try{r=m(e.bin,e.args??[],{cwd:e.cwd,env:e.env,stdio:[`pipe`,`pipe`,`pipe`]})}catch(r){_e?.onEnd(e.category,Date.now()-n),t({ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:r instanceof Error?r.message:String(r)});return}let i=``,a=``,o=!1,s=null,c=null,l=!1,u=r=>{o||(o=!0,s&&clearTimeout(s),c&&clearTimeout(c),_e?.onEnd(e.category,Date.now()-n),t(r))};r.stdout?.on(`data`,e=>{i+=e.toString(`utf8`)}),r.stderr?.on(`data`,e=>{a+=e.toString(`utf8`)}),r.on(`error`,e=>{u({ok:!1,reason:`spawn-error`,stdout:i,stderr:a,exitCode:null,signal:null,error:e.message})}),r.on(`close`,(e,t)=>{if(l){u({ok:!1,reason:`timeout`,stdout:i,stderr:a,exitCode:e,signal:t});return}if(e===0){u({ok:!0,stdout:i,stderr:a,exitCode:e});return}u({ok:!1,reason:t?`signal`:`non-zero`,stdout:i,stderr:a,exitCode:e,signal:t})}),e.timeoutMs&&e.timeoutMs>0&&(s=setTimeout(()=>{l=!0,r.pid!==void 0&&(r.kill(`SIGTERM`),c=setTimeout(()=>{r.kill(`SIGKILL`)},250))},e.timeoutMs)),e.stdinInput!==void 0&&r.stdin?r.stdin.end(e.stdinInput):r.stdin&&r.stdin.end()})}function be(e){let t=he(e.category);if(!t.allowed)return k(e.category,t.minIntervalMs,t.sinceLastMs);ge(e.category);let n=Date.now();_e?.onStart(e.category);let r=[`pipe`,`pipe`,`pipe`];try{let t=h(e.bin,e.args??[],{cwd:e.cwd,env:e.env,input:e.stdinInput,timeout:e.timeoutMs&&e.timeoutMs>0?e.timeoutMs:void 0,stdio:r,encoding:`utf8`});_e?.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:t.error.message};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 _e?.onEnd(e.category,Date.now()-n),{ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:t instanceof Error?t.message:String(t)}}}function xe(e){let t=he(e.category);if(!t.allowed)return k(e.category,t.minIntervalMs,t.sinceLastMs);ge(e.category);let n=Date.now();_e?.onStart(e.category);let r=Se(e);return _e?.onEnd(e.category,Date.now()-n),r}function Se(e){let t;try{t=m(e.bin,e.args??[],{cwd:e.cwd,env:e.env,detached:!0,stdio:`ignore`})}catch(e){return{ok:!1,reason:`spawn-error`,stdout:``,stderr:``,exitCode:null,signal:null,error:e instanceof Error?e.message:String(e)}}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 Ce(e){let t=process.env[e];return t&&t.length>0?t:void 0}function we(){let e=Ce(`XDG_STATE_HOME`)??c.join(f.homedir(),`.local`,`state`);return c.join(e,`cc-candybar`)}function Te(){let e=Ce(`XDG_CACHE_HOME`)??c.join(f.homedir(),`.cache`);return c.join(e,`cc-candybar`)}function Ee(){return we()}function De(){let e=process.env.CC_CANDYBAR_SOCKET;if(e)return e;let t=f.userInfo().uid;return c.join(`/tmp`,`cc-candybar-${t}`,`socket`)}function Oe(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=f.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 ke(e){Oe(c.dirname(e));for(let t of[e,A(e)])try{if(r.lstatSync(t).isSymbolicLink())throw Error(`path is a symlink: ${t}`)}catch(e){if(e.code!==`ENOENT`)throw e}}function A(e){return`${e}.lease`}function Ae(){return A(De())}function je(){return c.join(we(),`session-state.json`)}function Me(){return c.join(we(),`config-overrides.json`)}function Ne(){let e=process.env.CC_CANDYBAR_DAEMON_REGISTRY_DIR;if(e)return e;let t=f.userInfo().uid;return c.join(`/tmp`,`cc-candybar-${t}`,`daemons`)}function Pe(){return c.join(we(),`spawn.lock`)}function Fe(){return c.join(we(),`spawn.cooldown`)}function Ie(){return c.join(we(),`spawn.backoff`)}function Le(){return c.join(we(),`daemon.log`)}function Re(e){let t=Be(e.termCols),n=Ve(e.ssh);return{...t!==void 0&&{termCols:t},...n!==void 0&&{ssh:n}}}const ze=1e4;function Be(e){if(typeof e!=`number`||!Number.isFinite(e))return;let t=Math.floor(e);if(!(t<=0))return t>ze?ze:t}function Ve(e){return typeof e==`boolean`?e:void 0}var He=class extends Error{constructor(e){super(e),this.name=`ProtocolError`}};function Ue(e){let t=Buffer.from(JSON.stringify(e),`utf8`),n=Buffer.alloc(4);return n.writeUInt32BE(t.length,0),Buffer.concat([n,t])}function We(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 He(`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 He(e instanceof Error?e.message:String(e));e instanceof Error&&(n.cause=e),t(n);return}}}}function Ge(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=We(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(Ue(t))})}async function Ke(e,t,n){let r=null;try{r=await Ze(De(),t.connectMs);let i=await Ge(r,{v:3,...e},t.budgetMs);return Ye(e.kind,i,n)}catch(e){return Xe(e)}finally{r&&r.destroy()}}function qe(e,t){return typeof e==`string`?e:t}function Je(e){return typeof e==`number`&&Number.isInteger(e)&&e>=0?e:0}function Ye(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=qe(r.error,`(no error message)`);switch(r.code){case`VERSION_MISMATCH`:return{kind:`permanent`,cause:`version_mismatch`,clientV:3,daemonV:Je(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 Xe(e){if(e instanceof He||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 Ze(e,t){return new Promise((n,r)=>{let i=g.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 Qe(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 $e={connectMs:50,budgetMs:150},et={connectMs:50,budgetMs:200};function tt(e){let t=e.output;return typeof t==`string`?t:void 0}function nt(e,t,n,r){return Ke({kind:`render`,hookData:e,args:t,cwd:n,...r},$e,tt)}function rt(e,t){return Ke({kind:`click`,verb:e,value:t},et,tt)}let it=null;function at(e){if(it!==null)return it;r.mkdirSync(c.dirname(e),{recursive:!0});try{it=r.statSync(e).size}catch{it=0}return it}function ot(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{}it=0}function j(e,t){let n=`${new Date().toISOString()} [${e}] ${t}\n`;try{let e=Le(),t=at(e);r.appendFileSync(e,n),it=t+Buffer.byteLength(n,`utf8`),it>=5242880&&ot(e)}catch(e){it=null;try{process.stderr.write(`${n}cc-candybar: daemon.log unwritable: ${e.message}\n`)}catch{}}}const st=`CC_CANDYBAR_RSS_LIMIT_MB`;function ct(e){let t=e[st];if(t===void 0)return 512;let n=/^\d+$/.test(t)?Number(t):NaN;if(!Number.isSafeInteger(n)||n<=0)throw Error(`${st} must be a positive integer (MB), got ${JSON.stringify(t)}`);return n}function lt(e){return ct(e)*2}const ut=1024*1024;function dt(e){return ct(e)*ut}function ft(e){let t=e.rssLimitBytes??512*ut,n=e.snapshotsKeep??3,r=!1;function i(){if(r)return!0;let i=e.rssBytes();if(i<=t)return!1;r=!0,e.log(`warn`,`RSS ${i} > limit ${t}; writing heap snapshot then shutting down`);try{let t=new Date(e.now()).toISOString().replace(/[:.]/g,`-`),r=c.join(e.snapshotDir,`heap-${t}-${e.pid}.heapsnapshot`),i=e.writeHeapSnapshot(r);e.log(`info`,`heap snapshot written: ${i}`),pt(e.listSnapshots(),n,e.removeFile)}catch(t){e.log(`warn`,`heap snapshot failed: ${t.message}`)}return e.shutdown(0),!0}function a(){let n=e.rssBytes();return n>t*.75?`rss ${n} approaching limit ${t}`:null}function o(e=6e4){let t=setInterval(()=>{i()},e);return t.unref(),{disarm:()=>clearInterval(t)}}return{checkRss:i,describeNextRestart:a,arm:o}}function pt(e,t,n){let r=[...e].sort((e,t)=>{let n=e.slice(e.lastIndexOf(`/`)+1);return t.slice(t.lastIndexOf(`/`)+1).localeCompare(n)});for(let e of r.slice(t))try{n(e)}catch{}}function mt(e,t,n={}){let i=Ee();return{now:()=>Date.now(),pid:process.pid,snapshotDir:i,log:j,rssBytes:()=>process.memoryUsage().rss,writeHeapSnapshot:e=>_.writeHeapSnapshot(e),listSnapshots:()=>{try{return r.readdirSync(i).filter(e=>e.startsWith(`heap-`)&&e.endsWith(`.heapsnapshot`)).map(e=>c.join(i,e))}catch{return[]}},removeFile:e=>r.unlinkSync(e),shutdown:t,startedAtMs:e,...n}}function ht(e={}){if(jt()!==null)return;let n=e.spawn??Mt,r=Ot();if(r.kind===`contended`){let e=_t();e!==null&&e>2e3&&(t.stderr.write(`cc-candybar: spawn-lock held ${e}ms (likely crashed holder) — spawning unlocked\n`),gt(n));return}if(r.kind===`error`){t.stderr.write(`cc-candybar: spawn-lock unavailable (${r.reason}) — spawning unlocked\n`),gt(n);return}try{gt(n)}finally{At()}}function gt(e){wt()&&vt(e)}function _t(){try{let e=r.statSync(Pe());return Date.now()-e.mtimeMs}catch{return null}}function vt(e){try{e()||t.stderr.write(`cc-candybar: daemon spawn returned false (unable to resolve script path?)
|
|
3
3
|
`)}catch(e){t.stderr.write(`cc-candybar: daemon spawn failed: ${e.message}\n`)}}function yt(e,t){return e===null?{kind:`allow`}:e<-1e4?{kind:`allow-future-garbage`,futureMs:-e}:e<t?{kind:`deny`}:{kind:`allow`}}function bt(e){return Math.min(3e3*2**Math.min(Math.max(e,0),5),6e4)}function xt(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 St(e,n){try{r.mkdirSync(c.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 Ct(){try{r.unlinkSync(Ie())}catch(e){e.code!==`ENOENT`&&t.stderr.write(`cc-candybar: could not reset spawn.backoff: ${e.message}\n`)}}function wt(){let e=Fe(),n=Ie(),r=xt(n),i=yt(Tt(e),bt(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`),Et(e),St(n,Math.min(r+1,5)),!0)}function Tt(e){try{return Date.now()-r.statSync(e).mtimeMs}catch{return null}}function Et(e){try{r.mkdirSync(c.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 Dt=null;function Ot(){let e=Pe();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 Dt={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(!kt(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 kt(e){try{let t=r.statSync(e);return Date.now()-t.mtimeMs>1e4}catch{return!0}}function At(){if(!Dt)return;let{fd:e,path:t}=Dt;Dt=null;try{r.closeSync(e)}catch{}try{r.unlinkSync(t)}catch{}}function jt(){try{return r.mkdirSync(Ee(),{recursive:!0}),null}catch(e){return`mkdir ${Ee()}: ${e.message}`}}function Mt(){let e=t.execPath,n=t.argv[1];return n?xe({bin:e,args:[`--max-old-space-size=${lt(t.env)}`,n,`daemon`],category:`daemon-spawn`}).ok:!1}const Nt=`cc-candybar`,M=`dispatch`,Pt=`set-state`,N=`step-state`,Ft=`copy`,It=`open-vscode`,Lt=`show-config-error`,Rt=`show-config-warning`,zt=`set-config`,Bt=`step-config`,Vt=`reset-config`,Ht=`apply-layout-op`,Ut=`undo`,Wt=`redo`;function Gt(e){return e.map(encodeURIComponent).join(`/`)}function Kt(e){return e.length===0?[]:e.split(`/`).map(decodeURIComponent)}function qt(e){return`${Nt}://${M}/${e.map(e=>`e=${encodeURIComponent(`${e.verb}/${Gt(e.args)}`)}`).join(`&`)}`}function Jt(e){return new y(e).getAll(`e`).map(Yt)}function Yt(e){let t=e.indexOf(`/`);return t===-1?{verb:e,value:``}:{verb:e.slice(0,t),value:e.slice(t+1)}}const Xt=`closed`;function Zt(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 Qt(e,t,n,r){let i=Zt(e,t.length,n);if(i!==void 0)throw Error(i);return t.length===1?t[0]:t[r]}function $t(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}function en(e,...t){return`{{ and ${[e,...t].map(e=>`(eq .${e.variable} "${$t(e.member)}")`).join(` `)} }}`}function tn(e,t,n){return`{{ action "${e}" "${$t(t)}" "${$t(n)}" }}`}function P(e,t){return{kind:`state`,key:e,default:t}}function nn(e,t){return{set:e,cycle:[Xt,t]}}const rn=`@promptctl/cc-candybar`,an=`CCCandybarURLHandler`,on=[],sn={"darwin-arm64":`@promptctl/cc-candybar-darwin-arm64`,"darwin-x64":`@promptctl/cc-candybar-darwin-x64`,"linux-x64":`@promptctl/cc-candybar-linux-x64`,"linux-arm64":`@promptctl/cc-candybar-linux-arm64`};function cn(e){return/^[A-Za-z0-9_./=,:-]+$/.test(e)?e:`'${e.replace(/'/g,`'\\''`)}'`}function ln(e,t){return[e,...t].map(cn).join(` `)}function un(){return c.join(f.homedir(),`Applications`,`${an}.app`)}function dn(){return c.join(f.homedir(),`.claude`,`settings.json`)}function fn(){if(process.platform!==`darwin`)throw Error(`URL handler installation requires macOS (found platform: ${process.platform}).`)}function pn(){if(process.platform===`darwin`)return c.join(f.homedir(),`Library`,`Application Support`,`CCCandybar`);let e=process.env.XDG_DATA_HOME??c.join(f.homedir(),`.local`,`share`);return c.join(e,`cc-candybar`)}function mn(){return c.join(pn(),`bin`,`cc-candybar`)}function F(){return c.join(pn(),`dist`,`index.mjs`)}function hn(e,t){return[`on open location L`,`\tdo shell script "'${e.replace(/"/g,`\\"`)}' '${t.replace(/"/g,`\\"`)}' url-handle " & quoted form of L`,`end open location`].join(`
|
|
4
|
-
`)}function gn(e){if(!e)throw Error(`install: process.argv[1] not set`);return e.endsWith(`.mjs`)||e.endsWith(`.js`)?e:c.resolve(c.dirname(e),`..`,`dist`,`index.mjs`)}function _n(t){let n=sn[`${process.platform}-${process.arch}`];if(n){let r=e(t);try{return{kind:`native`,sourcePath:r.resolve(`${n}/bin/cc-candybar`)}}catch{}}return{kind:`node-shim`,sourcePath:c.resolve(c.dirname(t),`..`,`bin`,`cc-candybar`)}}function vn(e,t){c.resolve(e)!==c.resolve(t)&&r.copyFileSync(e,t)}function yn(e){let t=r.openSync(e,`r`);try{let n=Buffer.alloc(2),i=r.readSync(t,n,0,2,0);if(i<2)throw Error(`install: staged render entry at ${e} is truncated (${i} byte(s)). Re-run: pnpm dlx ${rn}@latest install`);return n.toString(`latin1`)===`#!`?`node-shim`:`native`}finally{r.closeSync(t)}}function bn(){let e=gn(process.argv[1]);if(!r.existsSync(e))throw Error(`install: bundled dist not found at ${e}. Reinstall the package.`);let t=_n(e);if(!r.existsSync(t.sourcePath))throw Error(`install: render entry not found at ${t.sourcePath}. Reinstall the package.`);r.mkdirSync(c.dirname(F()),{recursive:!0}),r.mkdirSync(c.dirname(mn()),{recursive:!0}),vn(e,F()),vn(t.sourcePath,mn()),r.chmodSync(mn(),493),r.rmSync(c.join(pn(),`url-handler.mjs`),{force:!0});let n=yn(mn());return process.stdout.write(`Staged cc-candybar v1.41.
|
|
4
|
+
`)}function gn(e){if(!e)throw Error(`install: process.argv[1] not set`);return e.endsWith(`.mjs`)||e.endsWith(`.js`)?e:c.resolve(c.dirname(e),`..`,`dist`,`index.mjs`)}function _n(t){let n=sn[`${process.platform}-${process.arch}`];if(n){let r=e(t);try{return{kind:`native`,sourcePath:r.resolve(`${n}/bin/cc-candybar`)}}catch{}}return{kind:`node-shim`,sourcePath:c.resolve(c.dirname(t),`..`,`bin`,`cc-candybar`)}}function vn(e,t){c.resolve(e)!==c.resolve(t)&&r.copyFileSync(e,t)}function yn(e){let t=r.openSync(e,`r`);try{let n=Buffer.alloc(2),i=r.readSync(t,n,0,2,0);if(i<2)throw Error(`install: staged render entry at ${e} is truncated (${i} byte(s)). Re-run: pnpm dlx ${rn}@latest install`);return n.toString(`latin1`)===`#!`?`node-shim`:`native`}finally{r.closeSync(t)}}function bn(){let e=gn(process.argv[1]);if(!r.existsSync(e))throw Error(`install: bundled dist not found at ${e}. Reinstall the package.`);let t=_n(e);if(!r.existsSync(t.sourcePath))throw Error(`install: render entry not found at ${t.sourcePath}. Reinstall the package.`);r.mkdirSync(c.dirname(F()),{recursive:!0}),r.mkdirSync(c.dirname(mn()),{recursive:!0}),vn(e,F()),vn(t.sourcePath,mn()),r.chmodSync(mn(),493),r.rmSync(c.join(pn(),`url-handler.mjs`),{force:!0});let n=yn(mn());return process.stdout.write(`Staged cc-candybar v1.41.2 runtime at ${pn()}\n`+(n===`native`?` render entry: native binary (${process.platform}-${process.arch})\n`:` render entry: node shim (no native binary for ${process.platform}-${process.arch}; renders are correct but pay node startup)\n`)),{binPath:mn(),distPath:F(),entryKind:n}}function xn(){return[{key:`CFBundleIdentifier`,xml:`<string>com.cccandybar.url-handler</string>`},{key:`CFBundleURLTypes`,xml:[`<array>`,` <dict>`,` <key>CFBundleURLName</key>`,` <string>Claude Powerline Click Action</string>`,` <key>CFBundleURLSchemes</key>`,` <array>`,` <string>${Nt}</string>`,` </array>`,` </dict>`,`</array>`].join(`
|
|
5
5
|
`)}]}function Sn(e){let t=un();r.mkdirSync(c.dirname(t),{recursive:!0}),r.existsSync(t)&&r.rmSync(t,{recursive:!0,force:!0}),process.stdout.write(`Building ${t}\n`);let n=be({bin:`/usr/bin/osacompile`,args:[`-o`,t,`-e`,hn(process.execPath,e)],category:`install.osacompile`});if(!n.ok)throw process.stderr.write(n.stderr),Error(`osacompile failed (${n.reason})`);let i=c.join(t,`Contents`,`Info.plist`);for(let{key:e}of xn())be({bin:`/usr/bin/plutil`,args:[`-remove`,e,i],category:`install.plutil`});for(let{key:e,xml:t}of xn()){let n=be({bin:`/usr/bin/plutil`,args:[`-insert`,e,`-xml`,t,i],category:`install.plutil`});if(!n.ok)throw process.stderr.write(n.stderr),Error(`plutil -insert ${e} failed (${n.reason})`)}process.stdout.write(`Registering ${Nt}:// with Launch Services\n`);let a=be({bin:`/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister`,args:[`-f`,t],category:`install.lsregister`});if(!a.ok)throw process.stderr.write(a.stderr),Error(`lsregister failed (${a.reason})`);process.stdout.write(`✓ ${an}.app installed and registered.\n`),process.stdout.write(` Test: open '${Nt}://hello-world' && pbpaste\n`)}function I(){fn(),Sn(bn().distPath)}function Cn(e,t=Nt){let n=`${t}://`;if(!e.startsWith(n))throw Error(`expected ${n} scheme, got: ${e}`);let r=e.slice(n.length),i=r.indexOf(`/`);return i===-1?{verb:Ft,value:r}:{verb:decodeURIComponent(r.slice(0,i)),value:r.slice(i+1)}}async function wn(e){e||(process.stderr.write(`url-handle: missing URL argument.
|
|
6
6
|
`),process.exit(1));let t;try{t=Cn(e)}catch(e){process.stderr.write(`url-handle: ${e instanceof Error?e.message:String(e)}\n`),process.exit(1)}let n=await rt(t.verb,t.value);n.kind===`ok`&&process.exit(0),n.kind===`transient`&&(ht(),process.stderr.write(`url-handle: daemon unavailable (${n.cause}: ${n.message})\n`),process.exit(1)),process.stderr.write(Tn(n)+`
|
|
7
7
|
`),process.exit(1)}function Tn(e){switch(e.cause){case`version_mismatch`:return`url-handle: daemon rejected click (version mismatch: client v${e.clientV} ≠ daemon v${e.daemonV})`;case`bad_request`:return`url-handle: daemon rejected click (bad request: ${e.message})`;case`render_failed`:return`url-handle: daemon rejected click (handler failed: ${e.message})`;case`malformed_response`:return`url-handle: daemon rejected click (malformed response: ${e.message})`}}function En(){return`✓ install complete.
|
|
@@ -76,29 +76,29 @@ Use 'override' annotation for methods overridden by subclass.`)}}var U=ca(0),ia=
|
|
|
76
76
|
`)throw this.err(`newline in rune literal`,e,{found:`\\n`});if(n===`'`)return this.advanceBy(1),this.makeToken(`Char`,this.src.slice(t,this.offset),e);this.advanceBy(1)}throw this.err(`unterminated rune literal`,e,{expected:`'`,found:`end of input`})}readNumber(e){let t=this.offset;if(vl(this.src[this.offset]??``)&&this.advanceBy(1),this.src[this.offset]===`0`&&this.offset+1<this.src.length){let n=this.src[this.offset+1];if(n===`x`||n===`X`){for(this.advanceBy(2);bl(this.src[this.offset]??``)||this.src[this.offset]===`_`;)this.advanceBy(1);if(this.src[this.offset]===`.`||this.src[this.offset]===`p`||this.src[this.offset]===`P`)for(;this.isHexFloatTail(this.src[this.offset]??``);)this.advanceBy(1);return this.finishNumber(t,e)}if(n===`o`||n===`O`){for(this.advanceBy(2);xl(this.src[this.offset]??``)||this.src[this.offset]===`_`;)this.advanceBy(1);return this.finishNumber(t,e)}if(n===`b`||n===`B`){for(this.advanceBy(2);Sl(this.src[this.offset]??``)||this.src[this.offset]===`_`;)this.advanceBy(1);return this.finishNumber(t,e)}}for(;yl(this.src[this.offset]??``)||this.src[this.offset]===`_`;)this.advanceBy(1);if(this.src[this.offset]===`.`)for(this.advanceBy(1);yl(this.src[this.offset]??``)||this.src[this.offset]===`_`;)this.advanceBy(1);if(this.src[this.offset]===`e`||this.src[this.offset]===`E`)for(this.advanceBy(1),vl(this.src[this.offset]??``)&&this.advanceBy(1);yl(this.src[this.offset]??``);)this.advanceBy(1);return this.src[this.offset]===`i`&&this.advanceBy(1),this.finishNumber(t,e)}isHexFloatTail(e){return bl(e)||e===`.`||e===`p`||e===`P`||e===`+`||e===`-`||e===`_`}finishNumber(e,t){if(this.offset===e)throw this.err(`expected number`,t,{expected:`digit`});return this.makeToken(`Number`,this.src.slice(e,this.offset),t)}readVariable(e){let t=this.offset;for(this.advanceBy(1);Tl(this.src[this.offset]??``);)this.advanceBy(1);for(;this.src[this.offset]===`.`&&wl(this.src[this.offset+1]??``);)for(this.advanceBy(1);Tl(this.src[this.offset]??``);)this.advanceBy(1);return this.makeToken(`Variable`,this.src.slice(t,this.offset),e)}readDotOrField(e){let t=this.offset;if(this.advanceBy(1),!wl(this.src[this.offset]??``))return this.makeToken(`Dot`,`.`,e);for(;Tl(this.src[this.offset]??``);)this.advanceBy(1);for(;this.src[this.offset]===`.`&&wl(this.src[this.offset+1]??``);)for(this.advanceBy(1);Tl(this.src[this.offset]??``);)this.advanceBy(1);return this.makeToken(`Field`,this.src.slice(t,this.offset),e)}readIdentifier(e){let t=this.offset;for(;Tl(this.src[this.offset]??``);)this.advanceBy(1);let n=this.src.slice(t,this.offset),r=ml.get(n);return r?this.makeToken(r,n,e):this.makeToken(`Identifier`,n,e)}skipActionSpaces(){for(;this.offset<this.src.length;){let e=this.src[this.offset];if(e===` `||e===` `||e===`\r`||e===`
|
|
77
77
|
`)this.advanceBy(1);else return}}advanceBy(e){for(let t=0;t<e;t++){let e=this.src[this.offset];this.offset+=1,e===`
|
|
78
78
|
`?(this.line+=1,this.column=1):this.column+=1}}advanceTo(e){for(;this.offset<e;)this.advanceBy(1)}makeToken(e,t,n,r={}){return Object.freeze({type:e,value:t,pos:n,...r.trimLeft===void 0?{}:{trimLeft:r.trimLeft},...r.trimRight===void 0?{}:{trimRight:r.trimRight}})}};function _l(e){return e===` `||e===` `||e===`\r`||e===`
|
|
79
|
-
`}function vl(e){return e===`+`||e===`-`}function yl(e){return e>=`0`&&e<=`9`}function bl(e){return yl(e)||e>=`a`&&e<=`f`||e>=`A`&&e<=`F`}function xl(e){return e>=`0`&&e<=`7`}function Sl(e){return e===`0`||e===`1`}function Cl(e){return e>=`a`&&e<=`z`||e>=`A`&&e<=`Z`}function wl(e){return Cl(e)||e===`_`}function Tl(e){return wl(e)||yl(e)}function
|
|
80
|
-
`;break;case`t`:r+=` `;break;case`r`:r+=`\r`;break;case`\\`:r+=`\\`;break;case`"`:r+=`"`;break;case`'`:r+=`'`;break;case`a`:r+=`\x07`;break;case`b`:r+=`\b`;break;case`f`:r+=`\f`;break;case`v`:r+=`\v`;break;case`0`:case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:{let t=o+(e[i+1]??``)+(e[i+2]??``);i+=2,r+=String.fromCodePoint(Number.parseInt(t,8));break}case`x`:{let t=(e[i+1]??``)+(e[i+2]??``);i+=2,r+=String.fromCodePoint(Number.parseInt(t,16));break}case`u`:{let t=e.slice(i+1,i+5);i+=4,r+=String.fromCodePoint(Number.parseInt(t,16));break}case`U`:{let t=e.slice(i+1,i+9);i+=8,r+=String.fromCodePoint(Number.parseInt(t,16));break}default:throw new il(`bad escape sequence \\${o}`,t,{expected:`valid escape sequence`,found:`\\${o}`,source:n})}}return r}function zl(e,t,n){let r=Rl(`"${e.slice(1,-1).replace(/"/g,`\\"`)}"`,t,n);if(r.length===0)throw new il(`empty rune literal`,t,{source:n});return r.codePointAt(0)??0}function Bl(e,t){if(t(e)!==!1)for(let n of Vl(e))Bl(n,t)}function Vl(e){switch(e.type){case`Text`:case`Comment`:case`Dot`:case`Nil`:case`Bool`:case`Number`:case`String`:case`Identifier`:case`Field`:case`Variable`:case`Break`:case`Continue`:return[];case`List`:return e.nodes;case`Chain`:return[e.node];case`Command`:return e.args;case`Pipe`:return[...e.decls,...e.cmds];case`Action`:return[e.pipe];case`If`:case`Range`:case`With`:return e.elseList?[e.pipe,e.list,e.elseList]:[e.pipe,e.list];case`Template`:return e.pipe?[e.pipe]:[];case`Block`:return e.pipe?[e.pipe,e.list]:[e.list];default:return pl(e)}}const Hl=Symbol(`go-template-js.MISSING`);function Ul(e,t){if(e==null)return Hl;if(e instanceof Map)return e.has(t)?e.get(t):Hl;if(Array.isArray(e))return Hl;if(typeof e==`object`){let n=e;return t in n?n[t]:Hl}return Hl}function Wl(e,t){let n=e;for(let e of t){if(n===Hl)return Hl;n=Ul(n,e)}return n}function Gl(e,t){if(Object.is(e,t))return!0;if(e===null||t===null||e===void 0||t===void 0||typeof e!=typeof t)return!1;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length?e.every((e,n)=>Gl(e,t[n])):!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(let[n,r]of e)if(!t.has(n)||!Gl(r,t.get(n)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}if(typeof e==`object`&&typeof t==`object`){let n=Object.keys(e),r=Object.keys(t);return n.length===r.length?n.every(n=>Gl(e[n],t[n])):!1}return!1}const Kl=new WeakSet;function ql(e){return Kl.add(e),e}function Jl(e){return Kl.has(e)}function Yl(e){return e==null||e===!1?!1:typeof e==`number`?e!==0&&!Number.isNaN(e):typeof e==`bigint`?e!==0n:typeof e==`string`||Array.isArray(e)?e.length>0:e instanceof Map||e instanceof Set?e.size>0:typeof e==`object`?Object.keys(e).length>0:!!e}function Xl(e){return{eq:{fn:(e,...t)=>t.some(t=>$l(e,t)),argTypes:[`comparable`]},ne:{fn:(e,t)=>!$l(e,t),argTypes:[`comparable`,`comparable`]},lt:{fn:(e,t)=>eu(e,t)<0,argTypes:[`ordered`,`ordered`]},le:{fn:(e,t)=>eu(e,t)<=0,argTypes:[`ordered`,`ordered`]},gt:{fn:(e,t)=>eu(e,t)>0,argTypes:[`ordered`,`ordered`]},ge:{fn:(e,t)=>eu(e,t)>=0,argTypes:[`ordered`,`ordered`]},len:{fn:e=>tu(e),argTypes:[`sized`]},index:{fn:(e,...t)=>{let n=e;for(let e of t)n=nu(n,e);return n},argTypes:[`collection`,`index-key`]},slice:{fn:(e,...t)=>{let n=t.length>=1?t[0]:0,r=t.length>=2?t[1]:void 0;return e.slice(n,r)},argTypes:[`sliceable`,`int`]},print:{fn:(...t)=>au(t,e),argTypes:[`stringifiable`],returnType:`string`},println:{fn:(...t)=>`${au(t,e)}\n`,argTypes:[`stringifiable`],returnType:`string`},printf:{fn:(t,...n)=>mu(t,n,e),argTypes:[`string`,`stringifiable`],returnType:`string`},call:{fn:(e,...t)=>e(...t),argTypes:[`callable`,`value`]},html:{fn:(...t)=>cu(au(t,e)),argTypes:[`stringifiable`],returnType:`string`},js:{fn:(...t)=>du(au(t,e)),argTypes:[`stringifiable`],returnType:`string`},urlquery:{fn:(...t)=>pu(au(t,e)),argTypes:[`stringifiable`],returnType:`string`},not:{fn:e=>!Yl(e),argTypes:[`truthy`]}}}function Zl(){return{and:ql({argTypes:[`truthy`],fn:(...e)=>{let t=!0;for(let n of e)if(t=n(),!Yl(t))return t;return t}}),or:ql({argTypes:[`truthy`],fn:(...e)=>{let t=!1;for(let n of e)if(t=n(),Yl(t))return t;return t}})}}function Ql(e){return{...Xl(e),...Zl()}}function $l(e,t){return typeof e==`number`&&typeof t==`bigint`?BigInt(e)===t:typeof e==`bigint`&&typeof t==`number`?e===BigInt(t):Gl(e,t)}function eu(e,t){if(typeof e==`bigint`&&typeof t==`bigint`)return e===t?0:e<t?-1:1;if(typeof e==`bigint`||typeof t==`bigint`){let n=typeof e==`bigint`?e:BigInt(Math.trunc(Number(e))),r=typeof t==`bigint`?t:BigInt(Math.trunc(Number(t)));return n===r?0:n<r?-1:1}let n=e,r=t;return n===r?0:n<r?-1:1}function tu(e){return typeof e==`string`||Array.isArray(e)?e.length:e instanceof Map||e instanceof Set?e.size:Object.keys(e).length}function nu(e,t){if(Array.isArray(e)){let n=Number(t);if(!Number.isInteger(n))throw Error(`index: array index must be integer, got ${ru(t)}`);if(n<0||n>=e.length)throw Error(`index: out of range [${n}] with length ${e.length}`);return e[n]}if(e instanceof Map)return e.get(t);if(typeof e==`string`)return e[Number(t)];if(typeof e==`object`&&e){if(typeof t!=`string`)throw Error(`index: object index must be string, got ${ru(t)}`);return e[t]}throw Error(`index: cannot index ${ru(e)}`)}function ru(e){return e===null?`null`:e===void 0?`undefined`:Array.isArray(e)?`array`:e instanceof Map?`Map`:typeof e}function iu(e){return e==null?`<nil>`:typeof e==`string`?`string`:typeof e==`boolean`?`bool`:typeof e==`bigint`?`int64`:typeof e==`number`?Number.isInteger(e)?`int`:`float64`:Array.isArray(e)?`[]interface {}`:e instanceof Map||typeof e==`object`?`map[string]interface {}`:typeof e}function au(e,t){let n=``,r=!1;for(let i=0;i<e.length;i++){let a=e[i],o=typeof a==`string`;i>0&&!r&&!o&&(n+=` `),n+=ou(a,t),r=o}return n}function ou(e,t){return e==null?`<nil>`:typeof e==`string`?e:t(e)}const su={"\0":`�`,'"':`"`,"'":`'`,"&":`&`,"<":`<`,">":`>`};function cu(e){return e.replace(/[\0"'&<>]/g,e=>su[e]??e)}const lu={"\\":`\\\\`,"'":`\\'`,'"':`\\"`,"<":`\\u003C`,">":`\\u003E`,"&":`\\u0026`,"=":`\\u003D`},uu=/^[\p{L}\p{M}\p{N}\p{P}\p{S}]$/u;function du(e){let t=``;for(let n of e){let e=lu[n];if(e!==void 0){t+=e;continue}let r=n.codePointAt(0);if(r<32||r>=128&&!uu.test(n)){t+=`\\u${r.toString(16).toUpperCase().padStart(4,`0`)}`;continue}t+=n}return t}const fu=new TextEncoder;function pu(e){let t=``,n=fu.encode(e);for(let e of n)e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===45||e===46||e===95||e===126?t+=String.fromCharCode(e):e===32?t+=`+`:t+=`%${e.toString(16).toUpperCase().padStart(2,`0`)}`;return t}function mu(e,t,n){let r=``,i=0,a=0;for(;a<e.length;){let o=e[a];if(o!==`%`){r+=o,a+=1;continue}if(e[a+1]===`%`){r+=`%`,a+=2;continue}let s=a+1;for(;s<e.length&&`+-# 0`.includes(e[s]??``);)s+=1;for(;s<e.length&&e[s]!==void 0&&/[0-9]/.test(e[s]);)s+=1;if(e[s]===`.`)for(s+=1;s<e.length&&e[s]!==void 0&&/[0-9]/.test(e[s]);)s+=1;let c=e[s],l=e.slice(a+1,s),u=t[i++];r+=hu(c??``,l,u,n),a=s+1}return r}function hu(e,t,n,r){switch(e){case`s`:return typeof n==`string`?gu(t,n):gu(t,ou(n,r));case`d`:return typeof n!=`number`&&typeof n!=`bigint`?`%!${e}(${iu(n)}=${ou(n,r)})`:gu(t,String(typeof n==`bigint`?n:Math.trunc(n)));case`v`:return gu(t,_u(n));case`q`:return gu(t,JSON.stringify(ou(n,r)));case`f`:{if(typeof n!=`number`&&typeof n!=`bigint`)return`%!${e}(${iu(n)}=${ou(n,r)})`;let i=t.includes(`.`)?Number(t.split(`.`)[1]):6;return gu(t,Number(n).toFixed(i))}case`t`:return gu(t,Yl(n)?`true`:`false`);case`x`:if(typeof n==`string`){let e=new TextEncoder().encode(n),r=``;for(let t of e)r+=t.toString(16).padStart(2,`0`);return gu(t,r)}return typeof n!=`number`&&typeof n!=`bigint`?`%!${e}(${iu(n)}=${ou(n,r)})`:typeof n==`bigint`?gu(t,n.toString(16)):gu(t,Math.trunc(n).toString(16));default:return`%!${e}(${iu(n)}=${ou(n,r)})`}}function gu(e,t){let n=e.match(/^([+\-# 0]*)/)?.[1]??``,r=e.slice(n.length).match(/^(\d+)/);if(!r)return t;let i=Number(r[1]);if(t.length>=i)return t;let a=` `.repeat(i-t.length);return n.includes(`-`)?t+a:a+t}function _u(e){return e==null?`<nil>`:typeof e==`string`?e:typeof e==`bigint`?e.toString():Array.isArray(e)?`[${e.map(_u).join(` `)}]`:e instanceof Map?`map[${[...e.entries()].map(([e,t])=>`${_u(e)}:${_u(t)}`).join(` `)}]`:typeof e==`object`?`{${Object.values(e).map(_u).join(` `)}}`:String(e)}function vu(e){return{dot:e,root:e,parent:void 0,vars:new Map}}function yu(e,t){return{dot:t,root:e.root,parent:e,vars:new Map}}function bu(e,t){let n=e;for(;n!==void 0;){if(n.vars.has(t))return{found:!0,value:n.vars.get(t)};n=n.parent}return{found:!1}}function xu(e,t,n){e.vars.set(t,n)}const Su=new Set([`default`,`zero`,`error`]);function Cu(e){if(e===void 0)return`default`;if(Su.has(e))return e;throw Error(`EngineConfig.missingKey: expected "default" | "zero" | "error", got ${wu(e)}`)}function wu(e){return typeof e==`string`?JSON.stringify(e):e===null?`null`:e===void 0?`undefined`:typeof e==`bigint`?`${e}n`:typeof e==`number`||typeof e==`boolean`?String(e):typeof e==`symbol`?e.toString():typeof e==`function`?`[Function]`:`[${typeof e}]`}function Tu(e){if(e!==void 0){if(typeof e!=`object`||!e)throw Error(`EngineConfig.delims: expected { left, right } object, got ${wu(e)}`);if(typeof e.left!=`string`||e.left.length===0)throw Error(`EngineConfig.delims.left: expected non-empty string, got ${wu(e.left)}`);if(typeof e.right!=`string`||e.right.length===0)throw Error(`EngineConfig.delims.right: expected non-empty string, got ${wu(e.right)}`);return{left:e.left,right:e.right}}}const Eu=Object.freeze({kind:`break`}),Du=Object.freeze({kind:`continue`}),Ou={kind:`none`};let ku;(class e{source;_evaluate;_referencedFunctions;_referencedCalls;constructor(e,t,n,r){this.source=e,this._evaluate=t,this._referencedFunctions=n,this._referencedCalls=r}static{ku=(t,n,r,i)=>new e(t,n,r,i)}evaluate(e){return this._evaluate(e)}referencedFunctions(){return this._referencedFunctions}referencedCalls(){return this._referencedCalls}});function Au(e){let t=new Set,n=e=>{Bl(e,e=>{e.type===`Identifier`&&t.add(e.ident)})};n(e.root);for(let t of e.defines.values())n(t);return t}const ju={kind:`dynamic`};function Mu(e){switch(e.type){case`String`:return{kind:`literal`,value:e.value};case`Bool`:return{kind:`literal`,value:e.value};case`Nil`:return{kind:`literal`,value:null};case`Number`:{let t=ed(e);return typeof t==`number`||typeof t==`bigint`?{kind:`literal`,value:t}:ju}case`Pipe`:{if(e.decls.length!==0||e.cmds.length!==1)return ju;let t=e.cmds[0];if(t===void 0)return ju;let n=t.args[0];return n===void 0||n.type!==`Identifier`?ju:{kind:`call`,name:n.ident,args:t.args.slice(1).map(Mu)}}default:return ju}}function Nu(e){let t=[],n=e=>{Bl(e,e=>{if(e.type!==`Command`)return;let n=e.args[0];if(n===void 0||n.type!==`Identifier`)return;let r=e.args.slice(1).map(Mu);t.push({name:n.ident,args:r.map(e=>e.kind===`literal`&&typeof e.value==`string`?e.value:null),argExprs:r})})};n(e.root);for(let t of e.defines.values())n(t);return t}var Pu=class{fromString;toString;funcs;missingKey;delims;constructor(e){this.fromString=e.fromString;let t=Object.hasOwn(e,`toString`)?e.toString:void 0;this.toString=t??Uu,this.missingKey=Cu(e.missingKey),this.delims=Tu(e.delims),this.funcs={...Ql(this.toString),...e.funcs??{}}}parse(e){let t=El(e,this.delims);return ku(t.source,e=>this.evalParsed(t,e),Au(t),Nu(t))}compile(e){let t=this.parse(e);return e=>t.evaluate(e)}evaluate(e,t){return e.evaluate(t)}evalParsed(e,t){let n=[],r=vu(t),i={out:n,defines:e.defines,source:e.source};return this.evalList(e.root,r,i),n}evalList(e,t,n){for(let r of e.nodes)this.evalNode(r,t,n)}evalNode(e,t,n){switch(e.type){case`Text`:n.out.push(this.fromString(e.text));return;case`Comment`:return;case`Action`:{let r=this.evalAction(e,t,n);e.pipe.decls.length===0&&this.emitFromValue(r,n);return}case`List`:this.evalList(e,t,n);return;case`If`:this.evalIf(e,t,n);return;case`Range`:this.evalRange(e,t,n);return;case`With`:this.evalWith(e,t,n);return;case`Break`:throw Eu;case`Continue`:throw Du;case`Template`:this.evalTemplateInvoke(e,t,n);return;case`Block`:this.evalBlock(e,t,n);return;case`Pipe`:case`Command`:case`Identifier`:case`Field`:case`Variable`:case`Chain`:case`Dot`:case`Nil`:case`Bool`:case`Number`:case`String`:throw new al(`unexpected ${e.type} at statement position`,e.pos,{source:n.source});default:pl(e)}}evalIf(e,t,n){Yl(this.evalPipe(e.pipe,t,n))?this.evalList(e.list,t,n):e.elseList&&this.evalList(e.elseList,t,n)}evalWith(e,t,n){let r=this.evalPipe(e.pipe,t,n);if(Yl(r)){let i=yu(t,r);this.evalList(e.list,i,n)}else e.elseList&&this.evalList(e.elseList,t,n)}evalRange(e,t,n){let r=this.evalPipeWithoutDecls(e.pipe,t,n),i=e.pipe.decls,a=Zu(r);try{if(a.length===0){e.elseList&&this.evalList(e.elseList,t,n);return}for(let[r,o]of a){let a=yu(t,o);if(i.length===1)xu(a,i[0]?.idents[0]??`$`,o);else if(i.length>=2){let e=i[0]?.idents[0]??`$`,t=i[1]?.idents[0]??`$`;xu(a,e,r),xu(a,t,o)}try{this.evalList(e.list,a,n)}catch(e){if(e===Du)continue;throw e}}}catch(e){if(e===Eu)return;throw e}}evalTemplateInvoke(e,t,n){let r=n.defines.get(e.name);if(!r)throw new al(`template ${JSON.stringify(e.name)} is not defined`,e.pos,{source:n.source});let i=yu(t,e.pipe?this.evalPipe(e.pipe,t,n):t.dot);this.evalList(r,i,n)}evalBlock(e,t,n){let r=yu(t,e.pipe?this.evalPipe(e.pipe,t,n):t.dot),i=n.defines.get(e.name)??e.list;this.evalList(i,r,n)}evalAction(e,t,n){return this.evalPipe(e.pipe,t,n)}evalPipe(e,t,n){if(e.cmds.length===0)throw new al(`empty pipeline`,e.pos,{source:n.source});let r=this.evalCommand(e.cmds[0],t,n,Ou);for(let i=1;i<e.cmds.length;i++){let a=e.cmds[i];r=this.evalCommand(a,t,n,{kind:`value`,value:r})}if(e.decls.length>0)for(let n of e.decls)xu(t,n.idents[0]??`$`,r);return r}evalPipeWithoutDecls(e,t,n){let r={type:`Pipe`,pos:e.pos,decls:[],isAssign:!1,cmds:e.cmds};return this.evalPipe(r,t,n)}evalCommand(e,t,n,r){if(e.args.length===0)throw new al(`empty command`,e.pos,{source:n.source});let i=e.args[0];if(i.type!==`Identifier`){if(e.args.length>1)throw new al(`cannot apply arguments to a ${i.type} primary; only functions take arguments`,e.pos,{source:n.source});return this.evalPrimary(i,t,n)}let a=this.funcs[i.ident];if(!a)throw new ol(i.ident,i.pos,{source:n.source,available:Object.keys(this.funcs)});let o=e.args.slice(1),s=Jl(a),c=o.map(e=>s?()=>this.evalPrimary(e,t,n):this.evalPrimary(e,t,n));if(r.kind===`value`){let e=r.value;c.push(s?()=>e:e)}zu(i.ident,a.argTypes,c,e.pos,n.source,this.toString,a.argTypePattern,this.fromString);try{return a.fn(...c)}catch(t){throw t instanceof sl?new sl(t.funcName,t.argIndex,t.expected,t.receivedSummary,e.pos,{source:n.source}):t instanceof ll?new ll(t.message,e.pos,{source:n.source}):t}}evalPrimary(e,t,n){switch(e.type){case`Dot`:return t.dot;case`Nil`:return null;case`Bool`:return e.value;case`Number`:return ed(e);case`String`:return e.value;case`Field`:return this.resolveFieldChain(t.dot,e.idents,e.pos,n);case`Variable`:return this.resolveVariable(e.idents,t,e.pos,n);case`Identifier`:{let t=this.funcs[e.ident];if(!t)throw new ol(e.ident,e.pos,{source:n.source,available:Object.keys(this.funcs)});return zu(e.ident,t.argTypes,[],e.pos,n.source,this.toString,t.argTypePattern,this.fromString),t.fn()}case`Chain`:return this.resolveFieldChain(this.evalPrimary(e.node,t,n),e.fields,e.pos,n);case`Pipe`:return this.evalPipe(e,t,n);default:throw new al(`cannot evaluate ${e.type} as a value`,e.pos,{source:n.source})}}resolveFieldChain(e,t,n,r){let i=Wl(e,t);if(i!==Hl)return i;if(this.missingKey===`error`)throw new cl(t,n,{source:r.source})}resolveVariable(e,t,n,r){let i=e[0]??`$`;if(i===`$`){let i=e.slice(1);return i.length===0?t.root:this.resolveFieldChain(t.root,i,n,r)}let a=bu(t,i);if(!a.found)throw new al(`undefined variable ${i}`,n,{source:r.source});let o=e.slice(1);return o.length===0?a.value:this.resolveFieldChain(a.value,o,n,r)}emitFromValue(e,t){if(e==null){t.out.push(this.fromString(`<no value>`));return}if(typeof e==`string`){t.out.push(this.fromString(e));return}if(typeof e==`number`||typeof e==`boolean`||typeof e==`bigint`){t.out.push(this.fromString(String(e)));return}if(Array.isArray(e)){t.out.push(this.fromString(Fu(e)));return}if(e instanceof Map){t.out.push(this.fromString(Iu(e)));return}t.out.push(e)}};function Fu(e){return`[${e.map(Lu).join(` `)}]`}function Iu(e){let t=[];for(let[n,r]of e)t.push(`${Lu(n)}:${Lu(r)}`);return`map[${t.join(` `)}]`}function Lu(e){return e==null?`<nil>`:Array.isArray(e)?Fu(e):e instanceof Map?Iu(e):String(e)}function Ru(e){return new Pu(e)}function zu(e,t,n,r,i,a=Uu,o,s=Hu){let c=Bu(t,o),l=-1,u=-1;for(let t=0;t<n.length;t++){let o=c(t),d=n[t];if(!Vu(o,d,a))throw new sl(e,t+1,Yu(o),Xu(d),r,{source:i});if(o===`liftable`&&typeof d==`string`&&(n[t]=s(d)),o===`int`?n[t]=Math.trunc(Number(d)):o===`float`&&(n[t]=Number(d)),o===`ordered`){if(l===-1)l=t;else if(!Ku(n[l],d))throw new sl(e,t+1,`${Yu(`ordered`)} of the same kind as ${Xu(n[l])}`,Xu(d),r,{source:i})}if(o===`comparable`){if(u===-1)u=t;else if(!qu(n[u],d))throw new sl(e,t+1,`${Yu(`comparable`)} of the same kind as ${Xu(n[u])}`,Xu(d),r,{source:i})}}}function Bu(e,t){if(e.length===0)return()=>`value`;if(t===`alternating`){let t=e.length;return n=>e[n%t]}let n=e[e.length-1];return t=>t<e.length?e[t]:n}function Vu(e,t,n){switch(e){case`truthy`:case`reflective`:case`value`:return!0;case`string`:return typeof t==`string`;case`int`:return typeof t==`number`&&Number.isFinite(t)||typeof t==`bigint`&&Number.isSafeInteger(Number(t));case`float`:return typeof t==`number`||typeof t==`bigint`&&Number.isFinite(Number(t));case`bool`:return typeof t==`boolean`;case`ordered`:return typeof t==`string`||typeof t==`number`||typeof t==`bigint`||typeof t==`boolean`;case`T`:return t!=null&&typeof t!=`string`&&typeof t!=`number`&&typeof t!=`boolean`&&typeof t!=`bigint`&&typeof t!=`symbol`;case`list`:return Array.isArray(t);case`dict`:return Wu(t);case`sized`:return typeof t==`string`||Array.isArray(t)||t instanceof Map||t instanceof Set||Wu(t);case`comparable`:return t==null||typeof t==`string`||typeof t==`number`||typeof t==`bigint`||typeof t==`boolean`||Array.isArray(t)||t instanceof Map||t instanceof Set||Wu(t);case`callable`:return typeof t==`function`;case`collection`:return typeof t==`string`||Array.isArray(t)||t instanceof Map||Wu(t);case`index-key`:return typeof t==`string`||typeof t==`number`||typeof t==`bigint`;case`sliceable`:return typeof t==`string`||Array.isArray(t);case`stringifiable`:if(typeof t==`string`)return!0;try{return n(t),!0}catch{return!1}case`liftable`:return typeof t==`string`||t!=null&&typeof t!=`number`&&typeof t!=`boolean`&&typeof t!=`bigint`&&typeof t!=`symbol`;case`serializable`:return Gu(t);default:throw Error(`invalid ArgType: ${String(e)}`)}}function Hu(e){return e}function Uu(e){if(typeof e==`string`)return e;if(e==null)return`<nil>`;if(typeof e==`number`||typeof e==`bigint`||typeof e==`boolean`)return String(e);throw new sl(`<engine.toString>`,1,`string (or a consumer-supplied toString that flattens T)`,Xu(e),{line:0,column:0,offset:0})}function Wu(e){if(typeof e!=`object`||!e||Array.isArray(e)||e instanceof Map||e instanceof Set)return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function Gu(e){try{return JSON.stringify(e)!==void 0}catch{return!1}}function Ku(e,t){return typeof e==typeof t||typeof e==`number`&&typeof t==`bigint`||typeof e==`bigint`&&typeof t==`number`}function qu(e,t){let n=Ju(e),r=Ju(t);return n===`nil`||r===`nil`?!0:n===r}function Ju(e){return e==null?`nil`:typeof e==`string`?`string`:typeof e==`number`||typeof e==`bigint`?`number`:typeof e==`boolean`?`boolean`:Array.isArray(e)?`array`:e instanceof Map?`map`:e instanceof Set?`set`:`object`}function Yu(e){switch(e){case`int`:return`integer (finite number or safe-integer bigint)`;case`float`:return`float (number, including NaN/Infinity, or finite-convertible bigint)`;case`T`:return`T (consumer-defined fragment)`;case`ordered`:return`orderable primitive`;case`list`:return`list`;case`dict`:return`dict (plain object)`;case`sized`:return`sized value (string, list, map, set, or dict)`;case`comparable`:return`comparable value (orderable primitive, nil, list, dict, Map, or Set)`;case`stringifiable`:return`stringifiable value (string or convertible via the engine's toString)`;case`liftable`:return`liftable value (T or string, the latter lifted via the engine's fromString)`;case`callable`:return`callable (function value)`;case`collection`:return`collection (string, array, Map, or dict)`;case`index-key`:return`index key (number, bigint, or string)`;case`sliceable`:return`sliceable value (string or array)`;case`serializable`:return`JSON-serializable value`;case`truthy`:case`reflective`:case`value`:case`string`:case`bool`:return e;default:throw Error(`invalid ArgType: ${String(e)}`)}}function Xu(e){return e===null?`null`:e===void 0?`undefined`:Array.isArray(e)?`array`:e instanceof Map?`Map`:typeof e}function Zu(e){return e==null?[]:Array.isArray(e)?e.map((e,t)=>[t,e]):typeof e==`string`?[...e].map((e,t)=>[t,e]):e instanceof Map?Qu([...e.entries()]):e instanceof Set?[...e.values()].map((e,t)=>[t,e]):typeof e==`object`?Qu(Object.entries(e)):[]}function Qu(e){return[...e].sort((e,t)=>$u(e[0],t[0]))}function $u(e,t){if((typeof e==`number`||typeof e==`bigint`)&&(typeof t==`number`||typeof t==`bigint`)){let n=typeof e==`bigint`?Number(e):e,r=typeof t==`bigint`?Number(t):t;return n===r?0:n<r?-1:1}let n=String(e),r=String(t);return n===r?0:n<r?-1:1}function ed(e){if(e.intValue!==void 0){let t=e.intValue;return t>=BigInt(-(2**53-1))&&t<=BigInt(2**53-1)?Number(t):t}if(e.floatValue!==void 0)return e.floatValue;if(e.complexValue!==void 0)return e.complexValue;throw Error(`internal: NumberNode has none of intValue/floatValue/complexValue — parser invariant violated`)}function td(e){if(!/^[+-]?\d+$/.test(e))return 0;let t=Number.parseInt(e,10);return Number.isSafeInteger(t)?t:0}function nd(e){if(typeof e==`number`)return e;if(typeof e==`bigint`)return Number(e);if(typeof e==`string`){let t=Number.parseFloat(e);return Number.isNaN(t)?0:t}return typeof e==`boolean`?+!!e:0}function rd(e){if(e===``)return null;let t=1,n=e;return n[0]===`+`?n=n.slice(1):n[0]===`-`&&(t=-1,n=n.slice(1)),n===``?null:/^0x[0-9a-fA-F]+$/i.test(n)?{sign:t,digits:n.slice(2),base:16}:/^0b[01]+$/i.test(n)?{sign:t,digits:n.slice(2),base:2}:/^0o[0-7]+$/i.test(n)?{sign:t,digits:n.slice(2),base:8}:n===`0`?{sign:t,digits:`0`,base:10}:n[0]===`0`?/^0[0-7]+$/.test(n)?{sign:t,digits:n.slice(1),base:8}:null:/^[0-9]+$/.test(n)?{sign:t,digits:n,base:10}:null}function id(e){if(typeof e==`number`){let t=Math.trunc(e);return Number.isSafeInteger(t)?t:0}if(typeof e==`bigint`){let t=Number(e);return Number.isSafeInteger(t)?t:0}if(typeof e==`string`){let t=rd(e);if(t===null)return 0;let n=t.sign*Number.parseInt(t.digits,t.base);return Number.isSafeInteger(n)?n:0}return typeof e==`boolean`?+!!e:0}function ad(e){if(typeof e==`bigint`)return e;if(typeof e==`number`)return BigInt(Math.trunc(e));if(typeof e==`string`){let t=rd(e);if(t===null)return 0n;let n=t.base===16?`0x`:t.base===2?`0b`:t.base===8?`0o`:``,r=BigInt(n+t.digits);return t.sign===-1?-r:r}return typeof e==`boolean`&&e?1n:0n}function od(e){if(!/^[+-]?[0-7]+$/.test(e))return 0;let t=e[0]===`-`?-1:1,n=e[0]===`+`||e[0]===`-`?e.slice(1):e,r=t*Number.parseInt(n,8);return Number.isSafeInteger(r)?r:0}function sd(e){return JSON.stringify(e)??`null`}function cd(e){return typeof e==`string`?e:_u(e)}function ld(e){return e.map(cd)}function ud(){return{atoi:{fn:e=>td(e),argTypes:[`string`],returnType:`int`},int:{fn:e=>id(e),argTypes:[`value`],returnType:`int`},int64:{fn:e=>ad(e),argTypes:[`value`]},float64:{fn:e=>nd(e),argTypes:[`value`],returnType:`float`},toString:{fn:e=>cd(e),argTypes:[`value`],returnType:`string`},toStrings:{fn:e=>ld(e),argTypes:[`list`]},toDecimal:{fn:e=>od(e),argTypes:[`string`],returnType:`int`},toRawJson:{fn:e=>sd(e),argTypes:[`serializable`],returnType:`string`}}}const dd={h:36e11,m:6e10,s:1e9,ms:1e6,us:1e3,µs:1e3,ns:1};function fd(e){if(e===`0`)return 0;let t=!1,n=e;if(n.startsWith(`-`)?(t=!0,n=n.slice(1)):n.startsWith(`+`)&&(n=n.slice(1)),!n)return NaN;let r=0,i=/^(\d+(?:\.\d+)?)(ns|µs|us|ms|[smh])/;for(;n.length>0;){let e=i.exec(n);if(!e)return NaN;let t=parseFloat(e[1]??`0`),a=e[2];r+=t*dd[a],n=n.slice(e[0].length)}return t?-r:r}function pd(e){if(e===0)return`0s`;let t=!1,n=e;n<0&&(t=!0,n=-n);let r;return r=n<dd.us?`${Math.floor(n)}ns`:n<dd.ms?md(n,dd.us,3,`µs`):n<dd.s?md(n,dd.ms,6,`ms`):hd(n),t?`-${r}`:r}function md(e,t,n,r){let i=Math.floor(e/t),a=Math.round(e%t);return a===0?`${i}${r}`:`${i}.${String(a).padStart(n,`0`).replace(/0+$/,``)}${r}`}function hd(e){let t=Math.floor(e/dd.h);e-=t*dd.h;let n=Math.floor(e/dd.m);e-=n*dd.m;let r=Math.floor(e/dd.s),i=e-r*dd.s,a=i===0?`${r}s`:`${r}.${String(Math.round(i)).padStart(9,`0`).replace(/0+$/,``)}s`;return t>0?`${t}h${n}m${a}`:n>0?`${n}m${a}`:a}function gd(e){return e*dd.s}function _d(e){if(e instanceof Date)return e;if(typeof e==`bigint`)return new Date(Number(e)*1e3);if(typeof e==`number`)return new Date(e*1e3);if(typeof e==`string`){let t=new Date(e);if(!Number.isNaN(t.getTime()))return t;throw Error(`sprig: cannot parse date value ${JSON.stringify(e)}`)}throw Error(`sprig: unsupported date type: ${typeof e}`)}function vd(e,t){let n=t().getTime()-_d(e).getTime();return pd(Math.round(n/1e3)*1e9)}const yd=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],bd=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],xd=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`],Sd=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function Cd(e){return e<10?`0${e}`:String(e)}function wd(e){return e<10?`00${e}`:e<100?`0${e}`:String(e)}function Td(e){return e<10?` ${e}`:String(e)}function Ed(e){let t=e>=0?`+`:`-`,n=Math.abs(e);return`${t}${Cd(Math.floor(n/60))}${Cd(n%60)}`}function Dd(e){let t=e>=0?`+`:`-`,n=Math.abs(e);return`${t}${Cd(Math.floor(n/60))}:${Cd(n%60)}`}function Od(e){return`${e>=0?`+`:`-`}${Cd(Math.floor(Math.abs(e)/60))}`}function kd(e){return e===0?`Z`:Ed(e)}function Ad(e){return e===0?`Z`:Dd(e)}function jd(e){return e===0?`Z`:Od(e)}function Md(e,t,n){let r=e*1e6,i=String(r).padStart(9,`0`).slice(0,t);return n?i.replace(/0+$/,``):i}const Nd=[[`.000000000`,e=>`.${Md(e.ms,9,!1)}`],[`.999999999`,e=>{let t=Md(e.ms,9,!0);return t?`.${t}`:``}],[`.000000`,e=>`.${Md(e.ms,6,!1)}`],[`.999999`,e=>{let t=Md(e.ms,6,!0);return t?`.${t}`:``}],[`.000`,e=>`.${wd(e.ms)}`],[`.999`,e=>{let t=wd(e.ms).replace(/0+$/,``);return t?`.${t}`:``}],[`January`,e=>yd[e.month-1]??`January`],[`Monday`,e=>xd[e.weekday]??`Monday`],[`Z07:00`,e=>Ad(e.offsetMinutes)],[`-07:00`,e=>Dd(e.offsetMinutes)],[`Z0700`,e=>kd(e.offsetMinutes)],[`-0700`,e=>Ed(e.offsetMinutes)],[`2006`,e=>String(e.year)],[`Jan`,e=>bd[e.month-1]??`Jan`],[`Mon`,e=>Sd[e.weekday]??`Mon`],[`MST`,e=>e.tzAbbr],[`-07`,e=>Od(e.offsetMinutes)],[`Z07`,e=>jd(e.offsetMinutes)],[`15`,e=>Cd(e.hour)],[`01`,e=>Cd(e.month)],[`02`,e=>Cd(e.day)],[`_2`,e=>Td(e.day)],[`03`,e=>Cd(e.hour12)],[`04`,e=>Cd(e.minute)],[`05`,e=>Cd(e.second)],[`06`,e=>Cd(e.year%100)],[`PM`,e=>e.hour>=12?`PM`:`AM`],[`pm`,e=>e.hour>=12?`pm`:`am`],[`1`,e=>String(e.month)],[`2`,e=>String(e.day)],[`3`,e=>String(e.hour12)],[`4`,e=>String(e.minute)],[`5`,e=>String(e.second)]];function Pd(e,t){let n=``,r=0;for(;r<e.length;){let i=!1;for(let[a,o]of Nd)if(e.startsWith(a,r)){n+=o(t),r+=a.length,i=!0;break}i||(n+=e[r++])}return n}const Fd={year:`numeric`,month:`2-digit`,day:`2-digit`,weekday:`long`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1};function Id(e){let t=new Map;for(let n of e)t.set(n.type,n.value);return t}const Ld=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`];function Rd(e,t){let n;try{new Intl.DateTimeFormat(`en-US`,{timeZone:t}),n=t}catch{n=`UTC`}let r=Id(new Intl.DateTimeFormat(`en-US`,{...Fd,timeZone:n}).formatToParts(e)),i=parseInt(r.get(`hour`)??`0`,10)%24,a=Id(new Intl.DateTimeFormat(`en-US`,{timeZone:n,timeZoneName:`short`}).formatToParts(e)).get(`timeZoneName`)??n,o=zd(Id(new Intl.DateTimeFormat(`en-US`,{timeZone:n,timeZoneName:`shortOffset`}).formatToParts(e)).get(`timeZoneName`)??`GMT`),s=Ld.indexOf(r.get(`weekday`)??`Sunday`);return{year:parseInt(r.get(`year`)??`2000`,10),month:parseInt(r.get(`month`)??`1`,10),day:parseInt(r.get(`day`)??`1`,10),weekday:s===-1?0:s,hour:i,hour12:i%12||12,minute:parseInt(r.get(`minute`)??`0`,10),second:parseInt(r.get(`second`)??`0`,10),ms:e.getUTCMilliseconds(),tzAbbr:a,offsetMinutes:o}}function zd(e){if(e===`GMT`||e===`UTC`)return 0;let t=e.match(/^GMT([+-])(\d{1,2})(?::(\d{2}))?$/);if(!t)return 0;let n=t[1]===`+`?1:-1,r=parseInt(t[2]??`0`,10),i=parseInt(t[3]??`0`,10);return n*(r*60+i)}function Bd(){return Intl.DateTimeFormat().resolvedOptions().timeZone}function Vd(e,t){return Pd(e,Rd(_d(t),Bd()))}function Hd(e,t,n){return Pd(e,Rd(_d(t),n))}function Ud(e,t){let n=_d(t),r=fd(e);return Number.isNaN(r)?n:new Date(n.getTime()+r/1e6)}function Wd(e){if(typeof e==`string`){let t=parseInt(e,10);return Number.isNaN(t)?`0s`:pd(gd(t))}return typeof e==`bigint`?pd(gd(Number(e))):typeof e==`number`?pd(gd(e)):`0s`}const Gd=36e11*24*365,Kd=36e11*24*30,qd=36e11*24,Jd=36e11,Yd=6e10,Xd=1e9;function Zd(e){let t=fd(String(e));if(Number.isNaN(t))return`0s`;let n=Math.abs(t);return n>Gd?`${Math.floor(n/Gd)}y`:n>Kd?`${Math.floor(n/Kd)}mo`:n>qd?`${Math.floor(n/qd)}d`:n>Jd?`${Math.floor(n/Jd)}h`:n>Yd?`${Math.floor(n/Yd)}m`:n>Xd?`${Math.floor(n/Xd)}s`:`0s`}function Qd(e){let t=Rd(_d(e),Bd());return`${t.year}-${String(t.month).padStart(2,`0`)}-${String(t.day).padStart(2,`0`)}`}function $d(e,t){let n=Rd(_d(e),t);return`${n.year}-${String(n.month).padStart(2,`0`)}-${String(n.day).padStart(2,`0`)}`}function ef(e){return e()}const tf=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],nf=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`];function rf(){return{year:2e3,month:1,day:1,hour:0,minute:0,second:0,ms:0,offsetMinutes:0,isPM:!1,hour12:!1}}function af(e,t,n){return[e.slice(t,t+n),t+n]}function of(e,t,n,r){let i=t;for(;i<e.length&&i-t<r&&e.charCodeAt(i)>=48&&e.charCodeAt(i)<=57;)i++;if(i-t<n)throw Error(`sprig toDate: expected ${n}-${r} digits at pos ${t}`);return[parseInt(e.slice(t,i),10),i]}function sf(e,t){for(let[n,r]of tf.entries())if(e.startsWith(r,t))return[n+1,t+r.length];throw Error(`sprig toDate: expected month name at pos ${t}`)}function cf(e,t){for(let[n,r]of nf.entries())if(e.startsWith(r,t))return[n+1,t+r.length];throw Error(`sprig toDate: expected short month name at pos ${t}`)}function lf(e,t){for(let n of[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`])if(e.startsWith(n,t))return t+n.length;throw Error(`sprig toDate: expected weekday name at pos ${t}`)}function uf(e,t){for(let n of[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`])if(e.startsWith(n,t))return t+n.length;throw Error(`sprig toDate: expected short weekday name at pos ${t}`)}function df(e,t){if(e[t]===` `){let[n,r]=of(e,t+1,1,1);return[n,r]}return of(e,t,1,2)}function ff(e,t,n){let r=e[t]===`+`?1:e[t]===`-`?-1:0;if(r===0)throw Error(`sprig toDate: expected +/- at pos ${t}`);let i=t+1,[a,o]=of(e,i,2,2);i=o;let s=0;if(n&&e[i]===`:`){let[t,n]=of(e,i+1,2,2);s=t,i=n}else if(!n){let[t,n]=of(e,i,2,2);s=t,i=n}return[r*(a*60+s),i]}function pf(e,t,n,r){if(e[t]===`Z`)return[0,t+1];if(r){let n=e[t]===`+`?1:e[t]===`-`?-1:0;if(n===0)throw Error(`sprig toDate: expected Z or +/- at pos ${t}`);let[r,i]=of(e,t+1,2,2);return[n*r*60,i]}return ff(e,t,n)}function mf(e,t){let n=t;for(;n<e.length&&e.charCodeAt(n)>=65&&e.charCodeAt(n)<=90;)n++;if(n===t)throw Error(`sprig toDate: expected timezone abbreviation at pos ${t}`);return n}function hf(e,t,n){let[r,i]=af(e,t,n),a=parseInt(r.padEnd(9,`0`),10);return[Math.round(a/1e6),i]}function gf(e,t,n,r){let i={...r};switch(e){case`January`:{let[e,r]=sf(t,n);return i.month=e,[r,i]}case`Monday`:return[lf(t,n),i];case`Jan`:{let[e,r]=cf(t,n);return i.month=e,[r,i]}case`Mon`:return[uf(t,n),i];case`2006`:{let[e,r]=of(t,n,4,4);return i.year=e,[r,i]}case`06`:{let[e,r]=of(t,n,2,2);return i.year=e<70?2e3+e:1900+e,[r,i]}case`01`:{let[e,r]=of(t,n,2,2);return i.month=e,[r,i]}case`1`:{let[e,r]=of(t,n,1,2);return i.month=e,[r,i]}case`_2`:{let[e,r]=df(t,n);return i.day=e,[r,i]}case`02`:{let[e,r]=of(t,n,2,2);return i.day=e,[r,i]}case`2`:{let[e,r]=of(t,n,1,2);return i.day=e,[r,i]}case`15`:{let[e,r]=of(t,n,2,2);return i.hour=e,[r,i]}case`03`:{let[e,r]=of(t,n,2,2);return i.hour=e,i.hour12=!0,[r,i]}case`3`:{let[e,r]=of(t,n,1,2);return i.hour=e,i.hour12=!0,[r,i]}case`04`:{let[e,r]=of(t,n,2,2);return i.minute=e,[r,i]}case`4`:{let[e,r]=of(t,n,1,2);return i.minute=e,[r,i]}case`05`:{let[e,r]=of(t,n,2,2);return i.second=e,[r,i]}case`5`:{let[e,r]=of(t,n,1,2);return i.second=e,[r,i]}case`PM`:case`pm`:{let e=t.slice(n,n+2).toLowerCase();if(e!==`am`&&e!==`pm`)throw Error(`sprig toDate: expected AM/PM at pos ${n}, got ${JSON.stringify(t.slice(n,n+2))}`);return i.isPM=e===`pm`,i.hour12=!0,[n+2,i]}case`MST`:return[mf(t,n),i];case`-0700`:{let[e,r]=ff(t,n,!1);return i.offsetMinutes=e,[r,i]}case`-07:00`:{let[e,r]=ff(t,n,!0);return i.offsetMinutes=e,[r,i]}case`-07`:{let e=t[n]===`+`?1:t[n]===`-`?-1:0;if(e===0)throw Error(`sprig toDate: expected +/- at pos ${n}`);let[r,a]=of(t,n+1,2,2);return i.offsetMinutes=e*r*60,[a,i]}case`Z0700`:{let[e,r]=pf(t,n,!1,!1);return i.offsetMinutes=e,[r,i]}case`Z07:00`:{let[e,r]=pf(t,n,!0,!1);return i.offsetMinutes=e,[r,i]}case`Z07`:{let[e,r]=pf(t,n,!1,!0);return i.offsetMinutes=e,[r,i]}case`.000000000`:{if(t[n]!==`.`)throw Error(`sprig toDate: expected . at pos ${n}`);let[e,r]=hf(t,n+1,9);return i.ms=e,[r,i]}case`.999999999`:{if(t[n]!==`.`)return[n,i];let e=n+1,r=e;for(;r<t.length&&t.charCodeAt(r)>=48&&t.charCodeAt(r)<=57;)r++;let a=t.slice(e,r).padEnd(9,`0`);return i.ms=Math.round(parseInt(a,10)/1e6),[r,i]}case`.000000`:{if(t[n]!==`.`)throw Error(`sprig toDate: expected . at pos ${n}`);let[e,r]=hf(t,n+1,6);return i.ms=e,[r,i]}case`.999999`:{if(t[n]!==`.`)return[n,i];let e=n+1,r=e;for(;r<t.length&&t.charCodeAt(r)>=48&&t.charCodeAt(r)<=57;)r++;let a=t.slice(e,r).padEnd(9,`0`);return i.ms=Math.round(parseInt(a,10)/1e6),[r,i]}case`.000`:{if(t[n]!==`.`)throw Error(`sprig toDate: expected . at pos ${n}`);let[e,r]=hf(t,n+1,3);return i.ms=e,[r,i]}case`.999`:{if(t[n]!==`.`)return[n,i];let e=n+1,r=e;for(;r<t.length&&t.charCodeAt(r)>=48&&t.charCodeAt(r)<=57;)r++;let a=t.slice(e,r).padEnd(3,`0`);return i.ms=parseInt(a,10),[r,i]}}throw Error(`sprig toDate: unhandled token ${e}`)}const _f=`.000000000,.999999999,.000000,.999999,.000,.999,January,Monday,Z07:00,-07:00,Z0700,-0700,2006,Jan,Mon,MST,-07,Z07,15,01,02,_2,03,04,05,06,PM,pm,1,2,3,4,5`.split(`,`);function vf(e,t){let n=0,r=0,i=rf();for(;n<e.length;){let a=!1;for(let o of _f)if(e.startsWith(o,n)){let[e,s]=gf(o,t,r,i);r=e,i=s,n+=o.length,a=!0;break}if(!a){let i=e.charAt(n);if(t[r]!==i)throw Error(`sprig toDate: expected ${JSON.stringify(i)} at pos ${r}, got ${JSON.stringify(t[r])}`);n++,r++}}if(r!==t.length)throw Error(`sprig toDate: extra characters at pos ${r}: ${JSON.stringify(t.slice(r))}`);if(i.hour12){let e=i.hour%12;i.hour=i.isPM?e+12:e}let a=Date.UTC(i.year,i.month-1,i.day,i.hour,i.minute,i.second,i.ms)-i.offsetMinutes*60*1e3;return new Date(a)}function yf(e,t){return vf(e,t)}function bf(e){return String(Math.floor(_d(e).getTime()/1e3))}function xf(e=()=>new Date){return{now:{fn:()=>ef(e),argTypes:[]},date:{fn:(e,t)=>Vd(e,t),argTypes:[`string`,`value`]},dateInZone:{fn:(e,t,n)=>Hd(e,t,n),argTypes:[`string`,`value`,`string`]},dateModify:{fn:(e,t)=>Ud(e,t),argTypes:[`string`,`value`]},htmlDate:{fn:e=>Qd(e),argTypes:[`value`]},htmlDateInZone:{fn:(e,t)=>$d(e,t),argTypes:[`value`,`string`]},duration:{fn:e=>Wd(e),argTypes:[`value`]},durationRound:{fn:e=>Zd(e),argTypes:[`value`]},toDate:{fn:(e,t)=>yf(e,t),argTypes:[`string`,`string`]},ago:{fn:t=>vd(t,e),argTypes:[`value`]},unixEpoch:{fn:e=>bf(e),argTypes:[`value`]}}}function Sf(e){return e==null||e===!1?!0:typeof e==`number`?e===0||Number.isNaN(e):typeof e==`bigint`?e===0n:typeof e==`string`||Array.isArray(e)?e.length===0:e instanceof Map||e instanceof Set?e.size===0:typeof e==`object`?Object.keys(e).length===0:!1}function Cf(...e){for(let t of e)if(!Sf(t))return t}function wf(e,t){return Sf(t)?e:t}function Tf(e){return JSON.parse(e)}function Ef(e,t,n){return Yl(n)?e:t}function Df(e){return JSON.stringify(e)??`null`}function Of(e){return JSON.stringify(e,null,2)??`null`}function kf(){return{default:{fn:(e,t)=>wf(e,t),argTypes:[`value`,`truthy`]},empty:{fn:e=>Sf(e),argTypes:[`truthy`]},coalesce:{fn:(...e)=>Cf(...e),argTypes:[`truthy`]},ternary:{fn:(e,t,n)=>Ef(e,t,n),argTypes:[`value`,`value`,`truthy`]},fromJson:{fn:e=>Tf(e),argTypes:[`string`]},toJson:{fn:e=>Df(e),argTypes:[`serializable`],returnType:`string`},toPrettyJson:{fn:e=>Of(e),argTypes:[`serializable`],returnType:`string`}}}function Af(...e){let t={};for(let n=0;n<e.length;n+=2)t[e[n]]=e[n+1];return t}function jf(e){if(e.kind!==`call`||e.name!==`dict`||e.args.length%2!=0)return null;let t=[];for(let[n,r]of e.args.entries()){if(r.kind!==`literal`||n%2==0&&typeof r.value!=`string`)return null;t.push(r.value)}return Af(...t)}function Mf(e,t){return e[t]}function Nf(e,t){return t in e}function Pf(e){return Object.keys(e)}function Ff(e,...t){let n={...e};for(let e of t)for(let[t,r]of Object.entries(e))t in n||(n[t]=r);return n}function If(e,...t){let n={...e};for(let e of t)Object.assign(n,e);return n}function Lf(e,...t){let n=new Set(t),r={};for(let[t,i]of Object.entries(e))n.has(t)||(r[t]=i);return r}function Rf(e,...t){let n={};for(let r of t)r in e&&(n[r]=e[r]);return n}function zf(e,...t){let n=[];for(let r of t)e in r&&n.push(r[e]);return n}function Bf(e,t,n){return e[t]=n,e}function Vf(e,t){return delete e[t],e}function Hf(e){return Object.values(e)}function Uf(){return{dict:{fn:(...e)=>Af(...e),argTypes:[`string`,`value`],argTypePattern:`alternating`},get:{fn:(e,t)=>Mf(e,t),argTypes:[`dict`,`string`]},set:{fn:(e,t,n)=>Bf(e,t,n),argTypes:[`dict`,`string`,`value`]},unset:{fn:(e,t)=>Vf(e,t),argTypes:[`dict`,`string`]},keys:{fn:e=>Pf(e),argTypes:[`dict`]},values:{fn:e=>Hf(e),argTypes:[`dict`]},pluck:{fn:(e,...t)=>zf(e,...t),argTypes:[`string`,`dict`]},pick:{fn:(e,...t)=>Rf(e,...t),argTypes:[`dict`,`string`]},omit:{fn:(e,...t)=>Lf(e,...t),argTypes:[`dict`,`string`]},hasKey:{fn:(e,t)=>Nf(e,t),argTypes:[`dict`,`string`]},merge:{fn:(e,...t)=>Ff(e,...t),argTypes:[`dict`]},mergeOverwrite:{fn:(e,...t)=>If(e,...t),argTypes:[`dict`]}}}new TextEncoder,new Map(Array.from(`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`).map((e,t)=>[e,t])),new TextDecoder,new TextEncoder,new TextDecoder,new TextEncoder;function Wf(...e){for(let t of e)if(Sf(t))return!1;return!0}function Gf(...e){for(let t of e)if(!Sf(t))return!0;return!1}function Kf(e,t){return[...e,t]}function qf(e,t){let n=Math.max(1,e),r=[];for(let e=0;e<t.length;e+=n)r.push(t.slice(e,e+n));return r}function Jf(e){return e.filter(e=>!Sf(e))}function Yf(...e){let t=[];for(let n of e)t.push(...n);return t}const Xf={line:0,column:0,offset:0};function Zf(e,t,n,r){return new sl(e,t,n,r,Xf)}function Qf(...e){if(e.length<3)throw Zf(`dig`,0,`at least 3 arguments (...keys, default, dict)`,`${e.length} argument${e.length===1?``:`s`}`);let t=e[e.length-1],n=e[e.length-2],r=e.slice(0,-2);if(!ep(t))throw Zf(`dig`,e.length-1,`dict`,tp(t));for(let e=0;e<r.length;e++)if(typeof r[e]!=`string`)throw Zf(`dig`,e,`string`,tp(r[e]));return $f(t,n,r,e.length)}function $f(e,t,n,r){let i=n[0];if(!Object.hasOwn(e,i))return t;let a=e[i];if(n.length===1)return a;if(!ep(a))throw Zf(`dig`,r-1,`dict at intermediate key`,tp(a));return $f(a,t,n.slice(1),r)}function ep(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&!(e instanceof Map)&&!(e instanceof Set)}function tp(e){return e===null?`null`:Array.isArray(e)?`array`:e instanceof Map?`Map`:e instanceof Set?`Set`:typeof e}function np(e){return e[0]}function rp(e,t){return t.some(t=>Gl(t,e))}function ip(e){return e.slice(0,-1)}function ap(e){return e[e.length-1]}function op(e){return Array.isArray(e)||typeof e==`string`?e.length:e instanceof Map||e instanceof Set?e.size:Object.keys(e).length}function sp(...e){return e}function cp(e,t){return[t,...e]}function lp(e){return e.slice(1)}function up(e){return[...e].reverse()}function dp(e,t,n){let r=t===void 0?0:t,i=n===void 0?e.length:n;return e.slice(r,i)}function fp(e){let t=[];for(let n of e)n!=null&&t.push(String(n));return t.sort()}function pp(e){let t=[];for(let n of e)t.some(e=>Gl(e,n))||t.push(n);return t}function mp(e,...t){return e.filter(e=>!t.some(t=>Gl(t,e)))}function hp(){return{list:{fn:(...e)=>sp(...e),argTypes:[`value`]},first:{fn:e=>np(e),argTypes:[`list`]},last:{fn:e=>ap(e),argTypes:[`list`]},rest:{fn:e=>lp(e),argTypes:[`list`]},initial:{fn:e=>ip(e),argTypes:[`list`]},len:{fn:e=>op(e),argTypes:[`sized`]},reverse:{fn:e=>up(e),argTypes:[`list`]},uniq:{fn:e=>pp(e),argTypes:[`list`]},without:{fn:(e,...t)=>mp(e,...t),argTypes:[`list`,`value`]},has:{fn:(e,t)=>rp(e,t),argTypes:[`value`,`list`]},compact:{fn:e=>Jf(e),argTypes:[`list`]},slice:{fn:(e,t,n)=>dp(e,t,n),argTypes:[`list`,`int`,`int`]},concat:{fn:(...e)=>Yf(...e),argTypes:[`list`]},chunk:{fn:(e,t)=>qf(e,t),argTypes:[`int`,`list`]},prepend:{fn:(e,t)=>cp(e,t),argTypes:[`list`,`value`]},append:{fn:(e,t)=>Kf(e,t),argTypes:[`list`,`value`]},sortAlpha:{fn:e=>fp(e),argTypes:[`list`],returnType:`list`},push:{fn:(e,t)=>Kf(e,t),argTypes:[`list`,`value`]},tuple:{fn:(...e)=>sp(...e),argTypes:[`value`]},dig:{fn:(...e)=>Qf(...e),argTypes:[`value`]},all:{fn:(...e)=>Wf(...e),argTypes:[`truthy`],returnType:`bool`},any:{fn:(...e)=>Gf(...e),argTypes:[`truthy`],returnType:`bool`}}}function gp(...e){return e.reduce((e,t)=>e+t,0)}function _p(e){return e+1}function vp(e){return e+1}function yp(...e){return e.reduce((e,t)=>e+t,0)}function bp(e){return Math.ceil(e)}function xp(e,t){return Math.trunc(e/t)}function Sp(e,t){return e/t}function Cp(e){return Math.floor(e)}function wp(...e){return e.reduce((e,t)=>t>e?t:e,-1/0)}function Tp(...e){return e.reduce((e,t)=>Math.max(e,t),-1/0)}function Ep(...e){return e.reduce((e,t)=>t<e?t:e,1/0)}function Dp(...e){return e.reduce((e,t)=>Math.min(e,t),1/0)}function Op(e,t){return e%t}function kp(...e){return e.reduce((e,t)=>e*t,1)}function Ap(...e){return e.reduce((e,t)=>e*t,1)}function jp(e,t=0){let n=10**t;return Math.sign(e)*Math.round(Math.abs(e)*n)/n}function Mp(e,t,n){let r=[];if(t<e){if(n>=0)return r;for(let i=e;i>t;i+=n)r.push(i);return r}if(n<=0)return r;for(let i=e;i<t;i+=n)r.push(i);return r}function Np(...e){let t=1;switch(e.length){case 0:return``;case 1:{let n=e[0];return n<1&&(t=-1),Mp(1,n+t,t).join(` `)}case 2:{let t=e[0],n=e[1],r=n<t?-1:1;return Mp(t,n+r,r).join(` `)}case 3:{let n=e[0],r=e[1],i=e[2];return i<n&&(t=-1,r>0)?``:Mp(n,i+t,r).join(` `)}default:return``}}function Pp(e,t){return e-t}function Fp(e,t){return e-t}function Ip(e){return Mp(0,e,e<0?-1:1)}function Lp(){return{add:{fn:(...e)=>gp(...e),argTypes:[`int`]},sub:{fn:(e,t)=>Pp(e,t),argTypes:[`int`,`int`]},mul:{fn:(...e)=>kp(...e),argTypes:[`int`]},div:{fn:(e,t)=>xp(e,t),argTypes:[`int`,`int`]},mod:{fn:(e,t)=>Op(e,t),argTypes:[`int`,`int`]},min:{fn:(...e)=>Ep(...e),argTypes:[`int`]},max:{fn:(...e)=>wp(...e),argTypes:[`int`]},floor:{fn:e=>Cp(e),argTypes:[`float`]},ceil:{fn:e=>bp(e),argTypes:[`float`]},round:{fn:(e,t)=>jp(e,t),argTypes:[`float`,`int`]},addf:{fn:(...e)=>yp(...e),argTypes:[`float`]},subf:{fn:(e,t)=>Fp(e,t),argTypes:[`float`,`float`]},mulf:{fn:(...e)=>Ap(...e),argTypes:[`float`]},divf:{fn:(e,t)=>Sp(e,t),argTypes:[`float`,`float`]},add1:{fn:e=>_p(e),argTypes:[`int`]},add1f:{fn:e=>vp(e),argTypes:[`float`]},maxf:{fn:(...e)=>Tp(...e),argTypes:[`float`]},minf:{fn:(...e)=>Dp(...e),argTypes:[`float`]},biggest:{fn:(...e)=>wp(...e),argTypes:[`int`]},seq:{fn:(...e)=>Np(...e),argTypes:[`int`],returnType:`string`},until:{fn:e=>Ip(e),argTypes:[`int`],returnType:`list`},untilStep:{fn:(e,t,n)=>Mp(e,t,n),argTypes:[`int`,`int`,`int`],returnType:`list`}}}Array.from({length:95},(e,t)=>String.fromCharCode(t+32)).join(``);function Rp(e,t){return t.length<=e||e<4?t:`${t.slice(0,e-3)}...`}function zp(e,t,n){return t<7||n.length<t||e<0||e>n.length-t+1?n:`...${n.slice(e,e+t-6)}...`}const Y={Invalid:0,Number:1,UpperCase:2,Alphabet:3,Connector:4,Punct:5,Other:6},Bp=/^[-_\s]$/,Vp=/^\p{P}$/u,Hp=/^\p{L}$/u,Up=/^\p{Lu}$/u,Wp=/^\p{N}$/u;function Gp(e){return e!==void 0&&Bp.test(e)}function Kp(e){return e!==void 0&&Hp.test(e)}function qp(e){return e!==void 0&&Up.test(e)}function Jp(e){return e!==void 0&&Wp.test(e)}function Yp(e){return e!==void 0&&Vp.test(e)}function Xp(e,t){if(t>=e.length)return{word:{wt:Y.Invalid,text:``},next:t};let n=e[t],r=t+1;if(Gp(n)){for(;r<e.length&&Gp(e[r]);)r++;return{word:{wt:Y.Connector,text:e.slice(t,r).join(``)},next:r}}if(Yp(n)){for(;r<e.length&&Yp(e[r]);)r++;return{word:{wt:Y.Punct,text:e.slice(t,r).join(``)},next:r}}if(qp(n)){if(r>=e.length)return{word:{wt:Y.UpperCase,text:n},next:r};if(qp(e[r])){let n=r;for(;n<e.length&&qp(e[n]);)n++;return n<e.length&&Kp(e[n])?{word:{wt:Y.UpperCase,text:e.slice(t,n-1).join(``)},next:n-1}:{word:{wt:Y.UpperCase,text:e.slice(t,n).join(``)},next:n}}if(Kp(e[r])){let n=r+1;for(;n<e.length&&Kp(e[n])&&!qp(e[n]);)n++;return{word:{wt:Y.UpperCase,text:e.slice(t,n).join(``)},next:n}}return{word:{wt:Y.UpperCase,text:n},next:r}}if(Kp(n)){for(;r<e.length&&Kp(e[r])&&!qp(e[r]);)r++;return{word:{wt:Y.Alphabet,text:e.slice(t,r).join(``)},next:r}}if(Jp(n)){for(;r<e.length&&Jp(e[r]);)r++;return{word:{wt:Y.Number,text:e.slice(t,r).join(``)},next:r}}for(;r<e.length&&!Gp(e[r])&&!Kp(e[r])&&!Jp(e[r])&&!Yp(e[r]);)r++;return{word:{wt:Y.Other,text:e.slice(t,r).join(``)},next:r}}function Zp(e,t,n){if(t.wt!==Y.UpperCase&&t.wt!==Y.Connector){e.push(t.text);return}for(let r of t.text)Gp(r)?e.push(n):qp(r)?e.push(r.toLowerCase()):e.push(r)}function Qp(e,t){if(e.length===0)return``;let n=Array.from(e),r=[],{word:i,next:a}=Xp(n,0);for(;a<n.length;){i.wt!==Y.Connector&&Zp(r,i,t);let e=i,o=i;if({word:i,next:a}=Xp(n,a),e.wt===Y.Number){for(;i.wt===Y.Alphabet||i.wt===Y.Number;)Zp(r,i,t),{word:i,next:a}=Xp(n,a);i.wt!==Y.Invalid&&i.wt!==Y.Punct&&i.wt!==Y.Connector&&r.push(t);continue}if(e.wt===Y.Connector){Zp(r,o,t);continue}if(e.wt===Y.Punct)continue;if(i.wt!==Y.Number){i.wt!==Y.Connector&&i.wt!==Y.Punct&&r.push(t);continue}if(a>=n.length)continue;let s=i;if({word:i,next:a}=Xp(n,a),i.wt!==Y.Alphabet){Zp(r,s,t),i.wt!==Y.Connector&&i.wt!==Y.Punct&&r.push(t);continue}for(r.push(t),Zp(r,s,t);i.wt===Y.Alphabet||i.wt===Y.Number;)Zp(r,i,t),{word:i,next:a}=Xp(n,a);i.wt!==Y.Invalid&&i.wt!==Y.Connector&&i.wt!==Y.Punct&&r.push(t)}return Zp(r,i,t),r.join(``).toLowerCase()}function $p(e){if(e.length===0)return``;let t=Array.from(e),n=[],r=0,i=``;for(;r<t.length;){if(i=t[r],r++,!Gp(i)){i=i.toUpperCase();break}n.push(i)}if(r>=t.length)return t.length>0&&n.push(i),n.join(``);for(;r<t.length;){let e=i;if(i=t[r],r++,Gp(i)&&Gp(e)){n.push(e);continue}Gp(e)?i=i.toUpperCase():(i=i.toLowerCase(),n.push(e))}return n.push(i),n.join(``)}function em(e){return $p(e)}function tm(...e){return e.join(` `)}function nm(e,t){return t.includes(e)}function rm(e,t){return t.startsWith(e)}function im(e,t){return t.endsWith(e)}function am(e,t){let n=` `.repeat(Math.max(0,e));return t.split(`
|
|
79
|
+
`}function vl(e){return e===`+`||e===`-`}function yl(e){return e>=`0`&&e<=`9`}function bl(e){return yl(e)||e>=`a`&&e<=`f`||e>=`A`&&e<=`F`}function xl(e){return e>=`0`&&e<=`7`}function Sl(e){return e===`0`||e===`1`}function Cl(e){return e>=`a`&&e<=`z`||e>=`A`&&e<=`Z`}function wl(e){return Cl(e)||e===`_`}function Tl(e){return wl(e)||yl(e)}let El,Dl;function Ol(e,t){return Dl(e,t)}var kl=class e{static EMPTY=new e(new Map,void 0);#e;#t;constructor(e,t){this.#e=e,this.#t=t}static{El=(t,n)=>new e(t,n),Dl=(e,t)=>e.#e.get(t)??(e.#t&&Dl(e.#t,t))}has(e){return Dl(this,e)!==void 0}};function Al(e,t,n=kl.EMPTY){return new jl(e,t,n).parseTemplate()}var jl=class{lex;buf=[];defines=new Map;inherit;source;rangeDepth=0;constructor(e,t,n){this.source=e,this.inherit=n,this.lex=t?new gl(e,t):new gl(e)}peek(e=0){for(;this.buf.length<=e;)this.buf.push(this.lex.next());return this.buf[e]}next(){return this.buf.length>0?this.buf.shift():this.lex.next()}expect(e,t){let n=this.next();if(n.type!==e)throw this.errAt(n,`expected ${t}`,{expected:t,found:Pl(n)});return n}errAt(e,t,n={}){return new il(t,e.pos,{...n,source:this.source})}parseTemplate(){let e=this.parseList();if(this.peek().type!==`EOF`){let e=this.peek(),t=this.peek(1);if(e.type===`LeftDelim`&&(t.type===`Else`||t.type===`End`)){let n=t.type===`Else`?`else`:`end`;throw this.errAt(e,`unexpected \`{{${n}}}\` outside of \`if\`, \`range\`, \`with\`, or \`block\``,{found:`{{${n}}}`})}throw this.errAt(e,`unexpected ${Pl(e)}`,{found:Pl(e)})}return{root:e,defines:El(this.defines,this.inherit),ownDefines:this.defines,source:this.source}}parseList(){let e=this.peek().pos,t=[];for(;;){let n=this.peek();if(n.type===`EOF`)break;if(n.type===`Text`){this.next(),t.push({type:`Text`,pos:n.pos,text:n.value});continue}if(n.type===`Comment`){this.next();let e=Nl(n);t.push({type:`Comment`,pos:n.pos,text:n.value,trim:e});continue}if(n.type===`LeftDelim`){let n=this.peek(1).type;if(n===`Else`||n===`End`)return Ml(e,t);let r=this.parseAction();r!==null&&t.push(r);continue}throw this.errAt(n,`unexpected ${Pl(n)} at top level`,{found:Pl(n)})}return Ml(e,t)}parseAction(){let e=this.expect(`LeftDelim`,"`{{`"),t=e.trimLeft===!0,n=this.peek();switch(n.type){case`If`:return this.next(),this.parseBranch(`If`,e.pos,t);case`Range`:return this.next(),this.parseBranch(`Range`,e.pos,t);case`With`:return this.next(),this.parseBranch(`With`,e.pos,t);case`Break`:return this.next(),this.parseBreakOrContinue(`Break`,e.pos,t);case`Continue`:return this.next(),this.parseBreakOrContinue(`Continue`,e.pos,t);case`Template`:return this.next(),this.parseTemplateInvocation(e.pos,t);case`Block`:return this.next(),this.parseBlock(e.pos,t);case`Define`:return this.next(),this.parseDefine(e.pos,t),null;case`RightDelim`:throw this.errAt(n,`empty action`,{expected:`pipeline`});default:{let n=this.parsePipeline(),r=this.expect(`RightDelim`,"`}}`");return{type:`Action`,pos:e.pos,pipe:n,trim:{trimLeft:t,trimRight:r.trimRight===!0}}}}}parseBranch(e,t,n){let r=this.parsePipeline();this.expect(`RightDelim`,"`}}`"),e===`Range`&&(this.rangeDepth+=1);let i=this.parseList();e===`Range`&&--this.rangeDepth;let a=this.parseElsePart(),o={trimLeft:n,trimRight:a.endConsumed?a.endRight:this.consumeEnd()},s=a.list?{pipe:r,list:i,elseList:a.list,trim:o}:{pipe:r,list:i,trim:o};switch(e){case`If`:return{type:`If`,pos:t,...s};case`Range`:return{type:`Range`,pos:t,...s};case`With`:return{type:`With`,pos:t,...s}}}parseBreakOrContinue(e,t,n){if(this.rangeDepth===0)throw new il(`{{${e===`Break`?`break`:`continue`}}} outside of {{range}}`,t,{source:this.source});let r={trimLeft:n,trimRight:this.expect(`RightDelim`,"`}}`").trimRight===!0};return e===`Break`?{type:`Break`,pos:t,trim:r}:{type:`Continue`,pos:t,trim:r}}parseElsePart(){if(this.peek().type!==`LeftDelim`||this.peek(1).type!==`Else`)return{list:void 0,endRight:!1,endConsumed:!1};let e=this.next();if(this.next(),this.peek().type===`If`){this.next();let t=this.parseBranch(`If`,e.pos,e.trimLeft===!0);return{list:{type:`List`,pos:e.pos,nodes:[t]},endRight:t.trim.trimRight,endConsumed:!0}}return this.expect(`RightDelim`,"`}}`"),{list:this.parseList(),endRight:!1,endConsumed:!1}}consumeEnd(){return this.expect(`LeftDelim`,"`{{end}}`"),this.expect(`End`,"`end`"),this.expect(`RightDelim`,"`}}`").trimRight===!0}parseTemplateInvocation(e,t){let n=this.parseQuotedName(),r=this.peek().type===`RightDelim`?void 0:this.parsePipeline(),i={trimLeft:t,trimRight:this.expect(`RightDelim`,"`}}`").trimRight===!0};return r?{type:`Template`,pos:e,name:n,pipe:r,trim:i}:{type:`Template`,pos:e,name:n,trim:i}}parseBlock(e,t){let n=this.parseQuotedName(),r=this.peek().type===`RightDelim`?void 0:this.parsePipeline();this.expect(`RightDelim`,"`}}`");let i=this.rangeDepth;this.rangeDepth=0;let a=this.parseList();this.rangeDepth=i;let o={trimLeft:t,trimRight:this.consumeEnd()};return!this.defines.has(n)&&!this.inherit.has(n)&&this.defines.set(n,{list:a,source:this.source}),r?{type:`Block`,pos:e,name:n,pipe:r,list:a,trim:o}:{type:`Block`,pos:e,name:n,list:a,trim:o}}parseDefine(e,t){let n=this.parseQuotedName();this.expect(`RightDelim`,"`}}`");let r=this.rangeDepth;this.rangeDepth=0;let i=this.parseList();if(this.rangeDepth=r,this.consumeEnd(),this.defines.has(n)||this.inherit.has(n))throw new il(`redefinition of template ${JSON.stringify(n)}`,i.pos,{source:this.source});this.defines.set(n,{list:i,source:this.source})}parseQuotedName(){let e=this.next();if(e.type!==`String`)throw this.errAt(e,`expected template name (quoted string)`,{expected:`string`,found:Pl(e)});return Hl(e.value,e.pos,this.source)}parsePipeline(){let e=this.peek().pos,t=this.tryParseDecls(),n=[this.parseCommand()];for(;this.peek().type===`Pipe`;){this.next();let e=this.peek();if(!Fl(e.type))throw this.errAt(e,"missing command after `|`",{expected:`command`,found:Pl(e)});n.push(this.parseCommand())}return{type:`Pipe`,pos:e,decls:t?.vars??[],isAssign:t?.isAssign??!1,cmds:n}}tryParseDecls(){if(this.peek().type!==`Variable`)return;let e=1;for(;this.peek(e).type===`Comma`;){if(this.peek(e+1).type!==`Variable`)return;e+=2}let t=this.peek(e).type;if(t!==`Declare`&&t!==`Assign`)return;let n=[Il(this.next())];for(;this.peek().type===`Comma`;)this.next(),n.push(Il(this.expect(`Variable`,`$variable`)));return{vars:n,isAssign:this.next().type===`Assign`}}parseCommand(){let e=this.peek().pos,t=[this.parsePrimary()];for(;Fl(this.peek().type);)t.push(this.parsePrimary());return{type:`Command`,pos:e,args:t}}parsePrimary(){let e=this.next();switch(e.type){case`Dot`:return{type:`Dot`,pos:e.pos};case`Field`:return{type:`Field`,pos:e.pos,idents:e.value.slice(1).split(`.`)};case`Variable`:return Il(e);case`Identifier`:return{type:`Identifier`,pos:e.pos,ident:e.value};case`String`:return{type:`String`,pos:e.pos,raw:e.value,value:Hl(e.value,e.pos,this.source)};case`Number`:return Rl(e);case`Char`:return zl(e,this.source);case`Bool`:return{type:`Bool`,pos:e.pos,value:e.value===`true`};case`Nil`:return{type:`Nil`,pos:e.pos};case`LeftParen`:return this.parseChainOrPipe(e.pos);default:throw this.errAt(e,`expected command argument, found ${Pl(e)}`,{expected:`command argument`,found:Pl(e)})}}parseChainOrPipe(e){let t=this.parsePipeline(),n=this.expect(`RightParen`,"`)`"),r=[],i=n.pos.offset+1,a=this.peek();return a.type===`Field`&&a.pos.offset===i&&(this.next(),r.push(...a.value.slice(1).split(`.`))),r.length===0?t:{type:`Chain`,pos:e,node:t,fields:r}}};function Ml(e,t){return{type:`List`,pos:e,nodes:t}}function Nl(e){return{trimLeft:e.trimLeft===!0,trimRight:e.trimRight===!0}}function Pl(e){return e.type===`EOF`?`end of input`:e.value||e.type}function Fl(e){switch(e){case`Dot`:case`Field`:case`Variable`:case`Identifier`:case`String`:case`Number`:case`Char`:case`Bool`:case`Nil`:case`LeftParen`:return!0;default:return!1}}function Il(e){return{type:`Variable`,pos:e.pos,idents:Ll(e.value)}}function Ll(e){let t=e.indexOf(`.`);return t===-1?[e]:[e.slice(0,t),...e.slice(t+1).split(`.`)]}function Rl(e){let t=e.value,n=t.replace(/_/g,``),r=n.toLowerCase().endsWith(`i`),i=r?n.slice(0,-1):n,a=!r&&(i.includes(`.`)||!i.startsWith(`0x`)&&!i.startsWith(`0X`)&&/[eE]/.test(i)||(i.startsWith(`0x`)||i.startsWith(`0X`))&&/[pP]/.test(i)),o=!r&&!a,s={type:`Number`,pos:e.pos,text:t,isInt:o,isUint:!1,isFloat:a,isComplex:r};if(o){let e=Bl(i);return{...s,intValue:e}}if(a){let e=Vl(i);return{...s,floatValue:e}}let c=Vl(i);return{...s,complexValue:[0,c]}}function zl(e,t){let n=Ul(e.value,e.pos,t);return{type:`Number`,pos:e.pos,text:e.value,isInt:!0,isUint:!1,isFloat:!1,isComplex:!1,intValue:BigInt(n)}}function Bl(e){let t=1n,n=e;return n.startsWith(`+`)?n=n.slice(1):n.startsWith(`-`)&&(t=-1n,n=n.slice(1)),t*BigInt(n)}function Vl(e){return Number(e)}function Hl(e,t,n){if(e.startsWith("`"))return e.slice(1,-1);let r=``;for(let i=1;i<e.length-1;i++){let a=e[i];if(a!==`\\`){r+=a;continue}let o=e[++i];switch(o){case`n`:r+=`
|
|
80
|
+
`;break;case`t`:r+=` `;break;case`r`:r+=`\r`;break;case`\\`:r+=`\\`;break;case`"`:r+=`"`;break;case`'`:r+=`'`;break;case`a`:r+=`\x07`;break;case`b`:r+=`\b`;break;case`f`:r+=`\f`;break;case`v`:r+=`\v`;break;case`0`:case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:{let t=o+(e[i+1]??``)+(e[i+2]??``);i+=2,r+=String.fromCodePoint(Number.parseInt(t,8));break}case`x`:{let t=(e[i+1]??``)+(e[i+2]??``);i+=2,r+=String.fromCodePoint(Number.parseInt(t,16));break}case`u`:{let t=e.slice(i+1,i+5);i+=4,r+=String.fromCodePoint(Number.parseInt(t,16));break}case`U`:{let t=e.slice(i+1,i+9);i+=8,r+=String.fromCodePoint(Number.parseInt(t,16));break}default:throw new il(`bad escape sequence \\${o}`,t,{expected:`valid escape sequence`,found:`\\${o}`,source:n})}}return r}function Ul(e,t,n){let r=Hl(`"${e.slice(1,-1).replace(/"/g,`\\"`)}"`,t,n);if(r.length===0)throw new il(`empty rune literal`,t,{source:n});return r.codePointAt(0)??0}function Wl(e,t){if(t(e)!==!1)for(let n of Gl(e))Wl(n,t)}function Gl(e){switch(e.type){case`Text`:case`Comment`:case`Dot`:case`Nil`:case`Bool`:case`Number`:case`String`:case`Identifier`:case`Field`:case`Variable`:case`Break`:case`Continue`:return[];case`List`:return e.nodes;case`Chain`:return[e.node];case`Command`:return e.args;case`Pipe`:return[...e.decls,...e.cmds];case`Action`:return[e.pipe];case`If`:case`Range`:case`With`:return e.elseList?[e.pipe,e.list,e.elseList]:[e.pipe,e.list];case`Template`:return e.pipe?[e.pipe]:[];case`Block`:return e.pipe?[e.pipe,e.list]:[e.list];default:return pl(e)}}const Kl=Symbol(`go-template-js.MISSING`);function ql(e,t){if(e==null)return Kl;if(e instanceof Map)return e.has(t)?e.get(t):Kl;if(Array.isArray(e))return Kl;if(typeof e==`object`){let n=e;return t in n?n[t]:Kl}return Kl}function Jl(e,t){let n=e;for(let e of t){if(n===Kl)return Kl;n=ql(n,e)}return n}function Yl(e,t){if(Object.is(e,t))return!0;if(e===null||t===null||e===void 0||t===void 0||typeof e!=typeof t)return!1;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length?e.every((e,n)=>Yl(e,t[n])):!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(let[n,r]of e)if(!t.has(n)||!Yl(r,t.get(n)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}if(typeof e==`object`&&typeof t==`object`){let n=Object.keys(e),r=Object.keys(t);return n.length===r.length?n.every(n=>Yl(e[n],t[n])):!1}return!1}const Xl=new WeakSet;function Zl(e){return Xl.add(e),e}function Ql(e){return Xl.has(e)}function $l(e){return e==null||e===!1?!1:typeof e==`number`?e!==0&&!Number.isNaN(e):typeof e==`bigint`?e!==0n:typeof e==`string`||Array.isArray(e)?e.length>0:e instanceof Map||e instanceof Set?e.size>0:typeof e==`object`?Object.keys(e).length>0:!!e}function eu(e){return{eq:{fn:(e,...t)=>t.some(t=>ru(e,t)),argTypes:[`comparable`]},ne:{fn:(e,t)=>!ru(e,t),argTypes:[`comparable`,`comparable`]},lt:{fn:(e,t)=>iu(e,t)<0,argTypes:[`ordered`,`ordered`]},le:{fn:(e,t)=>iu(e,t)<=0,argTypes:[`ordered`,`ordered`]},gt:{fn:(e,t)=>iu(e,t)>0,argTypes:[`ordered`,`ordered`]},ge:{fn:(e,t)=>iu(e,t)>=0,argTypes:[`ordered`,`ordered`]},len:{fn:e=>au(e),argTypes:[`sized`]},index:{fn:(e,...t)=>{let n=e;for(let e of t)n=ou(n,e);return n},argTypes:[`collection`,`index-key`]},slice:{fn:(e,...t)=>{let n=t.length>=1?t[0]:0,r=t.length>=2?t[1]:void 0;return e.slice(n,r)},argTypes:[`sliceable`,`int`]},print:{fn:(...t)=>lu(t,e),argTypes:[`stringifiable`],returnType:`string`},println:{fn:(...t)=>`${lu(t,e)}\n`,argTypes:[`stringifiable`],returnType:`string`},printf:{fn:(t,...n)=>vu(t,n,e),argTypes:[`string`,`stringifiable`],returnType:`string`},call:{fn:(e,...t)=>e(...t),argTypes:[`callable`,`value`]},html:{fn:(...t)=>fu(lu(t,e)),argTypes:[`stringifiable`],returnType:`string`},js:{fn:(...t)=>hu(lu(t,e)),argTypes:[`stringifiable`],returnType:`string`},urlquery:{fn:(...t)=>_u(lu(t,e)),argTypes:[`stringifiable`],returnType:`string`},not:{fn:e=>!$l(e),argTypes:[`truthy`]}}}function tu(){return{and:Zl({argTypes:[`truthy`],fn:(...e)=>{let t=!0;for(let n of e)if(t=n(),!$l(t))return t;return t}}),or:Zl({argTypes:[`truthy`],fn:(...e)=>{let t=!1;for(let n of e)if(t=n(),$l(t))return t;return t}})}}function nu(e){return{...eu(e),...tu()}}function ru(e,t){return typeof e==`number`&&typeof t==`bigint`?BigInt(e)===t:typeof e==`bigint`&&typeof t==`number`?e===BigInt(t):Yl(e,t)}function iu(e,t){if(typeof e==`bigint`&&typeof t==`bigint`)return e===t?0:e<t?-1:1;if(typeof e==`bigint`||typeof t==`bigint`){let n=typeof e==`bigint`?e:BigInt(Math.trunc(Number(e))),r=typeof t==`bigint`?t:BigInt(Math.trunc(Number(t)));return n===r?0:n<r?-1:1}let n=e,r=t;return n===r?0:n<r?-1:1}function au(e){return typeof e==`string`||Array.isArray(e)?e.length:e instanceof Map||e instanceof Set?e.size:Object.keys(e).length}function ou(e,t){if(Array.isArray(e)){let n=Number(t);if(!Number.isInteger(n))throw Error(`index: array index must be integer, got ${su(t)}`);if(n<0||n>=e.length)throw Error(`index: out of range [${n}] with length ${e.length}`);return e[n]}if(e instanceof Map)return e.get(t);if(typeof e==`string`)return e[Number(t)];if(typeof e==`object`&&e){if(typeof t!=`string`)throw Error(`index: object index must be string, got ${su(t)}`);return e[t]}throw Error(`index: cannot index ${su(e)}`)}function su(e){return e===null?`null`:e===void 0?`undefined`:Array.isArray(e)?`array`:e instanceof Map?`Map`:typeof e}function cu(e){return e==null?`<nil>`:typeof e==`string`?`string`:typeof e==`boolean`?`bool`:typeof e==`bigint`?`int64`:typeof e==`number`?Number.isInteger(e)?`int`:`float64`:Array.isArray(e)?`[]interface {}`:e instanceof Map||typeof e==`object`?`map[string]interface {}`:typeof e}function lu(e,t){let n=``,r=!1;for(let i=0;i<e.length;i++){let a=e[i],o=typeof a==`string`;i>0&&!r&&!o&&(n+=` `),n+=uu(a,t),r=o}return n}function uu(e,t){return e==null?`<nil>`:typeof e==`string`?e:t(e)}const du={"\0":`�`,'"':`"`,"'":`'`,"&":`&`,"<":`<`,">":`>`};function fu(e){return e.replace(/[\0"'&<>]/g,e=>du[e]??e)}const pu={"\\":`\\\\`,"'":`\\'`,'"':`\\"`,"<":`\\u003C`,">":`\\u003E`,"&":`\\u0026`,"=":`\\u003D`},mu=/^[\p{L}\p{M}\p{N}\p{P}\p{S}]$/u;function hu(e){let t=``;for(let n of e){let e=pu[n];if(e!==void 0){t+=e;continue}let r=n.codePointAt(0);if(r<32||r>=128&&!mu.test(n)){t+=`\\u${r.toString(16).toUpperCase().padStart(4,`0`)}`;continue}t+=n}return t}const gu=new TextEncoder;function _u(e){let t=``,n=gu.encode(e);for(let e of n)e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===45||e===46||e===95||e===126?t+=String.fromCharCode(e):e===32?t+=`+`:t+=`%${e.toString(16).toUpperCase().padStart(2,`0`)}`;return t}function vu(e,t,n){let r=``,i=0,a=0;for(;a<e.length;){let o=e[a];if(o!==`%`){r+=o,a+=1;continue}if(e[a+1]===`%`){r+=`%`,a+=2;continue}let s=a+1;for(;s<e.length&&`+-# 0`.includes(e[s]??``);)s+=1;for(;s<e.length&&e[s]!==void 0&&/[0-9]/.test(e[s]);)s+=1;if(e[s]===`.`)for(s+=1;s<e.length&&e[s]!==void 0&&/[0-9]/.test(e[s]);)s+=1;let c=e[s],l=e.slice(a+1,s),u=t[i++];r+=yu(c??``,l,u,n),a=s+1}return r}function yu(e,t,n,r){switch(e){case`s`:return typeof n==`string`?bu(t,n):bu(t,uu(n,r));case`d`:return typeof n!=`number`&&typeof n!=`bigint`?`%!${e}(${cu(n)}=${uu(n,r)})`:bu(t,String(typeof n==`bigint`?n:Math.trunc(n)));case`v`:return bu(t,xu(n));case`q`:return bu(t,JSON.stringify(uu(n,r)));case`f`:{if(typeof n!=`number`&&typeof n!=`bigint`)return`%!${e}(${cu(n)}=${uu(n,r)})`;let i=t.includes(`.`)?Number(t.split(`.`)[1]):6;return bu(t,Number(n).toFixed(i))}case`t`:return bu(t,$l(n)?`true`:`false`);case`x`:if(typeof n==`string`){let e=new TextEncoder().encode(n),r=``;for(let t of e)r+=t.toString(16).padStart(2,`0`);return bu(t,r)}return typeof n!=`number`&&typeof n!=`bigint`?`%!${e}(${cu(n)}=${uu(n,r)})`:typeof n==`bigint`?bu(t,n.toString(16)):bu(t,Math.trunc(n).toString(16));default:return`%!${e}(${cu(n)}=${uu(n,r)})`}}function bu(e,t){let n=e.match(/^([+\-# 0]*)/)?.[1]??``,r=e.slice(n.length).match(/^(\d+)/);if(!r)return t;let i=Number(r[1]);if(t.length>=i)return t;let a=` `.repeat(i-t.length);return n.includes(`-`)?t+a:a+t}function xu(e){return e==null?`<nil>`:typeof e==`string`?e:typeof e==`bigint`?e.toString():Array.isArray(e)?`[${e.map(xu).join(` `)}]`:e instanceof Map?`map[${[...e.entries()].map(([e,t])=>`${xu(e)}:${xu(t)}`).join(` `)}]`:typeof e==`object`?`{${Object.values(e).map(xu).join(` `)}}`:String(e)}function Su(e){return{dot:e,root:e,parent:void 0,vars:new Map}}function Cu(e,t){return{dot:t,root:e.root,parent:e,vars:new Map}}function wu(e,t){let n=e;for(;n!==void 0;){if(n.vars.has(t))return{found:!0,value:n.vars.get(t)};n=n.parent}return{found:!1}}function Tu(e,t,n){e.vars.set(t,n)}const Eu=new Set([`default`,`zero`,`error`]);function Du(e){if(e===void 0)return`default`;if(Eu.has(e))return e;throw Error(`EngineConfig.missingKey: expected "default" | "zero" | "error", got ${Ou(e)}`)}function Ou(e){return typeof e==`string`?JSON.stringify(e):e===null?`null`:e===void 0?`undefined`:typeof e==`bigint`?`${e}n`:typeof e==`number`||typeof e==`boolean`?String(e):typeof e==`symbol`?e.toString():typeof e==`function`?`[Function]`:`[${typeof e}]`}function ku(e){if(e!==void 0){if(typeof e!=`object`||!e)throw Error(`EngineConfig.delims: expected { left, right } object, got ${Ou(e)}`);if(typeof e.left!=`string`||e.left.length===0)throw Error(`EngineConfig.delims.left: expected non-empty string, got ${Ou(e.left)}`);if(typeof e.right!=`string`||e.right.length===0)throw Error(`EngineConfig.delims.right: expected non-empty string, got ${Ou(e.right)}`);return{left:e.left,right:e.right}}}const Au=Object.freeze({kind:`break`}),ju=Object.freeze({kind:`continue`}),Mu={kind:`none`};let Nu;(class e{source;_evaluate;_defines;_referencedFunctions;_referencedCalls;constructor(e,t,n,r,i){this.source=e,this._evaluate=t,this._defines=n,this._referencedFunctions=r,this._referencedCalls=i}static{Nu=(t,n,r,i,a)=>new e(t,n,r,i,a)}defines(){return this._defines}evaluate(e){return this._evaluate(e)}referencedFunctions(){return this._referencedFunctions}referencedCalls(){return this._referencedCalls}});function Pu(e){let t=new Set,n=e=>{Wl(e,e=>{e.type===`Identifier`&&t.add(e.ident)})};n(e.root);for(let t of e.ownDefines.values())n(t.list);return t}const Fu={kind:`dynamic`};function Iu(e){switch(e.type){case`String`:return{kind:`literal`,value:e.value};case`Bool`:return{kind:`literal`,value:e.value};case`Nil`:return{kind:`literal`,value:null};case`Number`:{let t=id(e);return typeof t==`number`||typeof t==`bigint`?{kind:`literal`,value:t}:Fu}case`Pipe`:{if(e.decls.length!==0||e.cmds.length!==1)return Fu;let t=e.cmds[0];if(t===void 0)return Fu;let n=t.args[0];return n===void 0||n.type!==`Identifier`?Fu:{kind:`call`,name:n.ident,args:t.args.slice(1).map(Iu)}}default:return Fu}}function Lu(e){let t=[],n=e=>{Wl(e,e=>{if(e.type!==`Command`)return;let n=e.args[0];if(n===void 0||n.type!==`Identifier`)return;let r=e.args.slice(1).map(Iu);t.push({name:n.ident,args:r.map(e=>e.kind===`literal`&&typeof e.value==`string`?e.value:null),argExprs:r})})};n(e.root);for(let t of e.ownDefines.values())n(t.list);return t}var Ru=class{fromString;toString;funcs;missingKey;delims;constructor(e){this.fromString=e.fromString;let t=Object.hasOwn(e,`toString`)?e.toString:void 0;this.toString=t??qu,this.missingKey=Du(e.missingKey),this.delims=ku(e.delims),this.funcs={...nu(this.toString),...e.funcs??{}}}parse(e,t){let n=Al(e,this.delims,t);return Nu(n.source,e=>this.evalParsed(n,e),n.defines,Pu(n),Lu(n))}compile(e){let t=this.parse(e);return e=>t.evaluate(e)}evaluate(e,t){return e.evaluate(t)}evalParsed(e,t){let n=[],r=Su(t),i={out:n,defines:e.defines,source:e.source};return this.evalList(e.root,r,i),n}evalList(e,t,n){for(let r of e.nodes)this.evalNode(r,t,n)}evalNode(e,t,n){switch(e.type){case`Text`:n.out.push(this.fromString(e.text));return;case`Comment`:return;case`Action`:{let r=this.evalAction(e,t,n);e.pipe.decls.length===0&&this.emitFromValue(r,n);return}case`List`:this.evalList(e,t,n);return;case`If`:this.evalIf(e,t,n);return;case`Range`:this.evalRange(e,t,n);return;case`With`:this.evalWith(e,t,n);return;case`Break`:throw Au;case`Continue`:throw ju;case`Template`:this.evalTemplateInvoke(e,t,n);return;case`Block`:this.evalBlock(e,t,n);return;case`Pipe`:case`Command`:case`Identifier`:case`Field`:case`Variable`:case`Chain`:case`Dot`:case`Nil`:case`Bool`:case`Number`:case`String`:throw new al(`unexpected ${e.type} at statement position`,e.pos,{source:n.source});default:pl(e)}}evalIf(e,t,n){$l(this.evalPipe(e.pipe,t,n))?this.evalList(e.list,t,n):e.elseList&&this.evalList(e.elseList,t,n)}evalWith(e,t,n){let r=this.evalPipe(e.pipe,t,n);if($l(r)){let i=Cu(t,r);this.evalList(e.list,i,n)}else e.elseList&&this.evalList(e.elseList,t,n)}evalRange(e,t,n){let r=this.evalPipeWithoutDecls(e.pipe,t,n),i=e.pipe.decls,a=td(r);try{if(a.length===0){e.elseList&&this.evalList(e.elseList,t,n);return}for(let[r,o]of a){let a=Cu(t,o);if(i.length===1)Tu(a,i[0]?.idents[0]??`$`,o);else if(i.length>=2){let e=i[0]?.idents[0]??`$`,t=i[1]?.idents[0]??`$`;Tu(a,e,r),Tu(a,t,o)}try{this.evalList(e.list,a,n)}catch(e){if(e===ju)continue;throw e}}}catch(e){if(e===Au)return;throw e}}evalTemplateInvoke(e,t,n){let r=Ol(n.defines,e.name);if(!r)throw new al(`template ${JSON.stringify(e.name)} is not defined`,e.pos,{source:n.source});let i=Cu(t,e.pipe?this.evalPipe(e.pipe,t,n):t.dot);this.evalList(r.list,i,{out:n.out,defines:n.defines,source:r.source})}evalBlock(e,t,n){let r=Cu(t,e.pipe?this.evalPipe(e.pipe,t,n):t.dot),i=Ol(n.defines,e.name)??{list:e.list,source:n.source};this.evalList(i.list,r,{out:n.out,defines:n.defines,source:i.source})}evalAction(e,t,n){return this.evalPipe(e.pipe,t,n)}evalPipe(e,t,n){if(e.cmds.length===0)throw new al(`empty pipeline`,e.pos,{source:n.source});let r=this.evalCommand(e.cmds[0],t,n,Mu);for(let i=1;i<e.cmds.length;i++){let a=e.cmds[i];r=this.evalCommand(a,t,n,{kind:`value`,value:r})}if(e.decls.length>0)for(let n of e.decls)Tu(t,n.idents[0]??`$`,r);return r}evalPipeWithoutDecls(e,t,n){let r={type:`Pipe`,pos:e.pos,decls:[],isAssign:!1,cmds:e.cmds};return this.evalPipe(r,t,n)}evalCommand(e,t,n,r){if(e.args.length===0)throw new al(`empty command`,e.pos,{source:n.source});let i=e.args[0];if(i.type!==`Identifier`){if(e.args.length>1)throw new al(`cannot apply arguments to a ${i.type} primary; only functions take arguments`,e.pos,{source:n.source});return this.evalPrimary(i,t,n)}let a=this.funcs[i.ident];if(!a)throw new ol(i.ident,i.pos,{source:n.source,available:Object.keys(this.funcs)});let o=e.args.slice(1),s=Ql(a),c=o.map(e=>s?()=>this.evalPrimary(e,t,n):this.evalPrimary(e,t,n));if(r.kind===`value`){let e=r.value;c.push(s?()=>e:e)}Uu(i.ident,a.argTypes,c,e.pos,n.source,this.toString,a.argTypePattern,this.fromString);try{return a.fn(...c)}catch(t){throw t instanceof sl?new sl(t.funcName,t.argIndex,t.expected,t.receivedSummary,e.pos,{source:n.source}):t instanceof ll?new ll(t.message,e.pos,{source:n.source}):t}}evalPrimary(e,t,n){switch(e.type){case`Dot`:return t.dot;case`Nil`:return null;case`Bool`:return e.value;case`Number`:return id(e);case`String`:return e.value;case`Field`:return this.resolveFieldChain(t.dot,e.idents,e.pos,n);case`Variable`:return this.resolveVariable(e.idents,t,e.pos,n);case`Identifier`:{let t=this.funcs[e.ident];if(!t)throw new ol(e.ident,e.pos,{source:n.source,available:Object.keys(this.funcs)});return Uu(e.ident,t.argTypes,[],e.pos,n.source,this.toString,t.argTypePattern,this.fromString),t.fn()}case`Chain`:return this.resolveFieldChain(this.evalPrimary(e.node,t,n),e.fields,e.pos,n);case`Pipe`:return this.evalPipe(e,t,n);default:throw new al(`cannot evaluate ${e.type} as a value`,e.pos,{source:n.source})}}resolveFieldChain(e,t,n,r){let i=Jl(e,t);if(i!==Kl)return i;if(this.missingKey===`error`)throw new cl(t,n,{source:r.source})}resolveVariable(e,t,n,r){let i=e[0]??`$`;if(i===`$`){let i=e.slice(1);return i.length===0?t.root:this.resolveFieldChain(t.root,i,n,r)}let a=wu(t,i);if(!a.found)throw new al(`undefined variable ${i}`,n,{source:r.source});let o=e.slice(1);return o.length===0?a.value:this.resolveFieldChain(a.value,o,n,r)}emitFromValue(e,t){if(e==null){t.out.push(this.fromString(`<no value>`));return}if(typeof e==`string`){t.out.push(this.fromString(e));return}if(typeof e==`number`||typeof e==`boolean`||typeof e==`bigint`){t.out.push(this.fromString(String(e)));return}if(Array.isArray(e)){t.out.push(this.fromString(zu(e)));return}if(e instanceof Map){t.out.push(this.fromString(Bu(e)));return}t.out.push(e)}};function zu(e){return`[${e.map(Vu).join(` `)}]`}function Bu(e){let t=[];for(let[n,r]of e)t.push(`${Vu(n)}:${Vu(r)}`);return`map[${t.join(` `)}]`}function Vu(e){return e==null?`<nil>`:Array.isArray(e)?zu(e):e instanceof Map?Bu(e):String(e)}function Hu(e){return new Ru(e)}function Uu(e,t,n,r,i,a=qu,o,s=Ku){let c=Wu(t,o),l=-1,u=-1;for(let t=0;t<n.length;t++){let o=c(t),d=n[t];if(!Gu(o,d,a))throw new sl(e,t+1,$u(o),ed(d),r,{source:i});if(o===`liftable`&&typeof d==`string`&&(n[t]=s(d)),o===`int`?n[t]=Math.trunc(Number(d)):o===`float`&&(n[t]=Number(d)),o===`ordered`){if(l===-1)l=t;else if(!Xu(n[l],d))throw new sl(e,t+1,`${$u(`ordered`)} of the same kind as ${ed(n[l])}`,ed(d),r,{source:i})}if(o===`comparable`){if(u===-1)u=t;else if(!Zu(n[u],d))throw new sl(e,t+1,`${$u(`comparable`)} of the same kind as ${ed(n[u])}`,ed(d),r,{source:i})}}}function Wu(e,t){if(e.length===0)return()=>`value`;if(t===`alternating`){let t=e.length;return n=>e[n%t]}let n=e[e.length-1];return t=>t<e.length?e[t]:n}function Gu(e,t,n){switch(e){case`truthy`:case`reflective`:case`value`:return!0;case`string`:return typeof t==`string`;case`int`:return typeof t==`number`&&Number.isFinite(t)||typeof t==`bigint`&&Number.isSafeInteger(Number(t));case`float`:return typeof t==`number`||typeof t==`bigint`&&Number.isFinite(Number(t));case`bool`:return typeof t==`boolean`;case`ordered`:return typeof t==`string`||typeof t==`number`||typeof t==`bigint`||typeof t==`boolean`;case`T`:return t!=null&&typeof t!=`string`&&typeof t!=`number`&&typeof t!=`boolean`&&typeof t!=`bigint`&&typeof t!=`symbol`;case`list`:return Array.isArray(t);case`dict`:return Ju(t);case`sized`:return typeof t==`string`||Array.isArray(t)||t instanceof Map||t instanceof Set||Ju(t);case`comparable`:return t==null||typeof t==`string`||typeof t==`number`||typeof t==`bigint`||typeof t==`boolean`||Array.isArray(t)||t instanceof Map||t instanceof Set||Ju(t);case`callable`:return typeof t==`function`;case`collection`:return typeof t==`string`||Array.isArray(t)||t instanceof Map||Ju(t);case`index-key`:return typeof t==`string`||typeof t==`number`||typeof t==`bigint`;case`sliceable`:return typeof t==`string`||Array.isArray(t);case`stringifiable`:if(typeof t==`string`)return!0;try{return n(t),!0}catch{return!1}case`liftable`:return typeof t==`string`||t!=null&&typeof t!=`number`&&typeof t!=`boolean`&&typeof t!=`bigint`&&typeof t!=`symbol`;case`serializable`:return Yu(t);default:throw Error(`invalid ArgType: ${String(e)}`)}}function Ku(e){return e}function qu(e){if(typeof e==`string`)return e;if(e==null)return`<nil>`;if(typeof e==`number`||typeof e==`bigint`||typeof e==`boolean`)return String(e);throw new sl(`<engine.toString>`,1,`string (or a consumer-supplied toString that flattens T)`,ed(e),{line:0,column:0,offset:0})}function Ju(e){if(typeof e!=`object`||!e||Array.isArray(e)||e instanceof Map||e instanceof Set)return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function Yu(e){try{return JSON.stringify(e)!==void 0}catch{return!1}}function Xu(e,t){return typeof e==typeof t||typeof e==`number`&&typeof t==`bigint`||typeof e==`bigint`&&typeof t==`number`}function Zu(e,t){let n=Qu(e),r=Qu(t);return n===`nil`||r===`nil`?!0:n===r}function Qu(e){return e==null?`nil`:typeof e==`string`?`string`:typeof e==`number`||typeof e==`bigint`?`number`:typeof e==`boolean`?`boolean`:Array.isArray(e)?`array`:e instanceof Map?`map`:e instanceof Set?`set`:`object`}function $u(e){switch(e){case`int`:return`integer (finite number or safe-integer bigint)`;case`float`:return`float (number, including NaN/Infinity, or finite-convertible bigint)`;case`T`:return`T (consumer-defined fragment)`;case`ordered`:return`orderable primitive`;case`list`:return`list`;case`dict`:return`dict (plain object)`;case`sized`:return`sized value (string, list, map, set, or dict)`;case`comparable`:return`comparable value (orderable primitive, nil, list, dict, Map, or Set)`;case`stringifiable`:return`stringifiable value (string or convertible via the engine's toString)`;case`liftable`:return`liftable value (T or string, the latter lifted via the engine's fromString)`;case`callable`:return`callable (function value)`;case`collection`:return`collection (string, array, Map, or dict)`;case`index-key`:return`index key (number, bigint, or string)`;case`sliceable`:return`sliceable value (string or array)`;case`serializable`:return`JSON-serializable value`;case`truthy`:case`reflective`:case`value`:case`string`:case`bool`:return e;default:throw Error(`invalid ArgType: ${String(e)}`)}}function ed(e){return e===null?`null`:e===void 0?`undefined`:Array.isArray(e)?`array`:e instanceof Map?`Map`:typeof e}function td(e){return e==null?[]:Array.isArray(e)?e.map((e,t)=>[t,e]):typeof e==`string`?[...e].map((e,t)=>[t,e]):e instanceof Map?nd([...e.entries()]):e instanceof Set?[...e.values()].map((e,t)=>[t,e]):typeof e==`object`?nd(Object.entries(e)):[]}function nd(e){return[...e].sort((e,t)=>rd(e[0],t[0]))}function rd(e,t){if((typeof e==`number`||typeof e==`bigint`)&&(typeof t==`number`||typeof t==`bigint`)){let n=typeof e==`bigint`?Number(e):e,r=typeof t==`bigint`?Number(t):t;return n===r?0:n<r?-1:1}let n=String(e),r=String(t);return n===r?0:n<r?-1:1}function id(e){if(e.intValue!==void 0){let t=e.intValue;return t>=BigInt(-(2**53-1))&&t<=BigInt(2**53-1)?Number(t):t}if(e.floatValue!==void 0)return e.floatValue;if(e.complexValue!==void 0)return e.complexValue;throw Error(`internal: NumberNode has none of intValue/floatValue/complexValue — parser invariant violated`)}function ad(e){if(!/^[+-]?\d+$/.test(e))return 0;let t=Number.parseInt(e,10);return Number.isSafeInteger(t)?t:0}function od(e){if(typeof e==`number`)return e;if(typeof e==`bigint`)return Number(e);if(typeof e==`string`){let t=Number.parseFloat(e);return Number.isNaN(t)?0:t}return typeof e==`boolean`?+!!e:0}function sd(e){if(e===``)return null;let t=1,n=e;return n[0]===`+`?n=n.slice(1):n[0]===`-`&&(t=-1,n=n.slice(1)),n===``?null:/^0x[0-9a-fA-F]+$/i.test(n)?{sign:t,digits:n.slice(2),base:16}:/^0b[01]+$/i.test(n)?{sign:t,digits:n.slice(2),base:2}:/^0o[0-7]+$/i.test(n)?{sign:t,digits:n.slice(2),base:8}:n===`0`?{sign:t,digits:`0`,base:10}:n[0]===`0`?/^0[0-7]+$/.test(n)?{sign:t,digits:n.slice(1),base:8}:null:/^[0-9]+$/.test(n)?{sign:t,digits:n,base:10}:null}function cd(e){if(typeof e==`number`){let t=Math.trunc(e);return Number.isSafeInteger(t)?t:0}if(typeof e==`bigint`){let t=Number(e);return Number.isSafeInteger(t)?t:0}if(typeof e==`string`){let t=sd(e);if(t===null)return 0;let n=t.sign*Number.parseInt(t.digits,t.base);return Number.isSafeInteger(n)?n:0}return typeof e==`boolean`?+!!e:0}function ld(e){if(typeof e==`bigint`)return e;if(typeof e==`number`)return BigInt(Math.trunc(e));if(typeof e==`string`){let t=sd(e);if(t===null)return 0n;let n=t.base===16?`0x`:t.base===2?`0b`:t.base===8?`0o`:``,r=BigInt(n+t.digits);return t.sign===-1?-r:r}return typeof e==`boolean`&&e?1n:0n}function ud(e){if(!/^[+-]?[0-7]+$/.test(e))return 0;let t=e[0]===`-`?-1:1,n=e[0]===`+`||e[0]===`-`?e.slice(1):e,r=t*Number.parseInt(n,8);return Number.isSafeInteger(r)?r:0}function dd(e){return JSON.stringify(e)??`null`}function fd(e){return typeof e==`string`?e:xu(e)}function pd(e){return e.map(fd)}function md(){return{atoi:{fn:e=>ad(e),argTypes:[`string`],returnType:`int`},int:{fn:e=>cd(e),argTypes:[`value`],returnType:`int`},int64:{fn:e=>ld(e),argTypes:[`value`]},float64:{fn:e=>od(e),argTypes:[`value`],returnType:`float`},toString:{fn:e=>fd(e),argTypes:[`value`],returnType:`string`},toStrings:{fn:e=>pd(e),argTypes:[`list`]},toDecimal:{fn:e=>ud(e),argTypes:[`string`],returnType:`int`},toRawJson:{fn:e=>dd(e),argTypes:[`serializable`],returnType:`string`}}}const hd={h:36e11,m:6e10,s:1e9,ms:1e6,us:1e3,µs:1e3,ns:1};function gd(e){if(e===`0`)return 0;let t=!1,n=e;if(n.startsWith(`-`)?(t=!0,n=n.slice(1)):n.startsWith(`+`)&&(n=n.slice(1)),!n)return NaN;let r=0,i=/^(\d+(?:\.\d+)?)(ns|µs|us|ms|[smh])/;for(;n.length>0;){let e=i.exec(n);if(!e)return NaN;let t=parseFloat(e[1]??`0`),a=e[2];r+=t*hd[a],n=n.slice(e[0].length)}return t?-r:r}function _d(e){if(e===0)return`0s`;let t=!1,n=e;n<0&&(t=!0,n=-n);let r;return r=n<hd.us?`${Math.floor(n)}ns`:n<hd.ms?vd(n,hd.us,3,`µs`):n<hd.s?vd(n,hd.ms,6,`ms`):yd(n),t?`-${r}`:r}function vd(e,t,n,r){let i=Math.floor(e/t),a=Math.round(e%t);return a===0?`${i}${r}`:`${i}.${String(a).padStart(n,`0`).replace(/0+$/,``)}${r}`}function yd(e){let t=Math.floor(e/hd.h);e-=t*hd.h;let n=Math.floor(e/hd.m);e-=n*hd.m;let r=Math.floor(e/hd.s),i=e-r*hd.s,a=i===0?`${r}s`:`${r}.${String(Math.round(i)).padStart(9,`0`).replace(/0+$/,``)}s`;return t>0?`${t}h${n}m${a}`:n>0?`${n}m${a}`:a}function bd(e){return e*hd.s}function xd(e){if(e instanceof Date)return e;if(typeof e==`bigint`)return new Date(Number(e)*1e3);if(typeof e==`number`)return new Date(e*1e3);if(typeof e==`string`){let t=new Date(e);if(!Number.isNaN(t.getTime()))return t;throw Error(`sprig: cannot parse date value ${JSON.stringify(e)}`)}throw Error(`sprig: unsupported date type: ${typeof e}`)}function Sd(e,t){let n=t().getTime()-xd(e).getTime();return _d(Math.round(n/1e3)*1e9)}const Cd=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],wd=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],Td=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`],Ed=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function Dd(e){return e<10?`0${e}`:String(e)}function Od(e){return e<10?`00${e}`:e<100?`0${e}`:String(e)}function kd(e){return e<10?` ${e}`:String(e)}function Ad(e){let t=e>=0?`+`:`-`,n=Math.abs(e);return`${t}${Dd(Math.floor(n/60))}${Dd(n%60)}`}function jd(e){let t=e>=0?`+`:`-`,n=Math.abs(e);return`${t}${Dd(Math.floor(n/60))}:${Dd(n%60)}`}function Md(e){return`${e>=0?`+`:`-`}${Dd(Math.floor(Math.abs(e)/60))}`}function Nd(e){return e===0?`Z`:Ad(e)}function Pd(e){return e===0?`Z`:jd(e)}function Fd(e){return e===0?`Z`:Md(e)}function Id(e,t,n){let r=e*1e6,i=String(r).padStart(9,`0`).slice(0,t);return n?i.replace(/0+$/,``):i}const Ld=[[`.000000000`,e=>`.${Id(e.ms,9,!1)}`],[`.999999999`,e=>{let t=Id(e.ms,9,!0);return t?`.${t}`:``}],[`.000000`,e=>`.${Id(e.ms,6,!1)}`],[`.999999`,e=>{let t=Id(e.ms,6,!0);return t?`.${t}`:``}],[`.000`,e=>`.${Od(e.ms)}`],[`.999`,e=>{let t=Od(e.ms).replace(/0+$/,``);return t?`.${t}`:``}],[`January`,e=>Cd[e.month-1]??`January`],[`Monday`,e=>Td[e.weekday]??`Monday`],[`Z07:00`,e=>Pd(e.offsetMinutes)],[`-07:00`,e=>jd(e.offsetMinutes)],[`Z0700`,e=>Nd(e.offsetMinutes)],[`-0700`,e=>Ad(e.offsetMinutes)],[`2006`,e=>String(e.year)],[`Jan`,e=>wd[e.month-1]??`Jan`],[`Mon`,e=>Ed[e.weekday]??`Mon`],[`MST`,e=>e.tzAbbr],[`-07`,e=>Md(e.offsetMinutes)],[`Z07`,e=>Fd(e.offsetMinutes)],[`15`,e=>Dd(e.hour)],[`01`,e=>Dd(e.month)],[`02`,e=>Dd(e.day)],[`_2`,e=>kd(e.day)],[`03`,e=>Dd(e.hour12)],[`04`,e=>Dd(e.minute)],[`05`,e=>Dd(e.second)],[`06`,e=>Dd(e.year%100)],[`PM`,e=>e.hour>=12?`PM`:`AM`],[`pm`,e=>e.hour>=12?`pm`:`am`],[`1`,e=>String(e.month)],[`2`,e=>String(e.day)],[`3`,e=>String(e.hour12)],[`4`,e=>String(e.minute)],[`5`,e=>String(e.second)]];function Rd(e,t){let n=``,r=0;for(;r<e.length;){let i=!1;for(let[a,o]of Ld)if(e.startsWith(a,r)){n+=o(t),r+=a.length,i=!0;break}i||(n+=e[r++])}return n}const zd={year:`numeric`,month:`2-digit`,day:`2-digit`,weekday:`long`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1};function Bd(e){let t=new Map;for(let n of e)t.set(n.type,n.value);return t}const Vd=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`];function Hd(e,t){let n;try{new Intl.DateTimeFormat(`en-US`,{timeZone:t}),n=t}catch{n=`UTC`}let r=Bd(new Intl.DateTimeFormat(`en-US`,{...zd,timeZone:n}).formatToParts(e)),i=parseInt(r.get(`hour`)??`0`,10)%24,a=Bd(new Intl.DateTimeFormat(`en-US`,{timeZone:n,timeZoneName:`short`}).formatToParts(e)).get(`timeZoneName`)??n,o=Ud(Bd(new Intl.DateTimeFormat(`en-US`,{timeZone:n,timeZoneName:`shortOffset`}).formatToParts(e)).get(`timeZoneName`)??`GMT`),s=Vd.indexOf(r.get(`weekday`)??`Sunday`);return{year:parseInt(r.get(`year`)??`2000`,10),month:parseInt(r.get(`month`)??`1`,10),day:parseInt(r.get(`day`)??`1`,10),weekday:s===-1?0:s,hour:i,hour12:i%12||12,minute:parseInt(r.get(`minute`)??`0`,10),second:parseInt(r.get(`second`)??`0`,10),ms:e.getUTCMilliseconds(),tzAbbr:a,offsetMinutes:o}}function Ud(e){if(e===`GMT`||e===`UTC`)return 0;let t=e.match(/^GMT([+-])(\d{1,2})(?::(\d{2}))?$/);if(!t)return 0;let n=t[1]===`+`?1:-1,r=parseInt(t[2]??`0`,10),i=parseInt(t[3]??`0`,10);return n*(r*60+i)}function Wd(){return Intl.DateTimeFormat().resolvedOptions().timeZone}function Gd(e,t){return Rd(e,Hd(xd(t),Wd()))}function Kd(e,t,n){return Rd(e,Hd(xd(t),n))}function qd(e,t){let n=xd(t),r=gd(e);return Number.isNaN(r)?n:new Date(n.getTime()+r/1e6)}function Jd(e){if(typeof e==`string`){let t=parseInt(e,10);return Number.isNaN(t)?`0s`:_d(bd(t))}return typeof e==`bigint`?_d(bd(Number(e))):typeof e==`number`?_d(bd(e)):`0s`}const Yd=36e11*24*365,Xd=36e11*24*30,Zd=36e11*24,Qd=36e11,$d=6e10,ef=1e9;function tf(e){let t=gd(String(e));if(Number.isNaN(t))return`0s`;let n=Math.abs(t);return n>Yd?`${Math.floor(n/Yd)}y`:n>Xd?`${Math.floor(n/Xd)}mo`:n>Zd?`${Math.floor(n/Zd)}d`:n>Qd?`${Math.floor(n/Qd)}h`:n>$d?`${Math.floor(n/$d)}m`:n>ef?`${Math.floor(n/ef)}s`:`0s`}function nf(e){let t=Hd(xd(e),Wd());return`${t.year}-${String(t.month).padStart(2,`0`)}-${String(t.day).padStart(2,`0`)}`}function rf(e,t){let n=Hd(xd(e),t);return`${n.year}-${String(n.month).padStart(2,`0`)}-${String(n.day).padStart(2,`0`)}`}function af(e){return e()}const of=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],sf=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`];function cf(){return{year:2e3,month:1,day:1,hour:0,minute:0,second:0,ms:0,offsetMinutes:0,isPM:!1,hour12:!1}}function lf(e,t,n){return[e.slice(t,t+n),t+n]}function uf(e,t,n,r){let i=t;for(;i<e.length&&i-t<r&&e.charCodeAt(i)>=48&&e.charCodeAt(i)<=57;)i++;if(i-t<n)throw Error(`sprig toDate: expected ${n}-${r} digits at pos ${t}`);return[parseInt(e.slice(t,i),10),i]}function df(e,t){for(let[n,r]of of.entries())if(e.startsWith(r,t))return[n+1,t+r.length];throw Error(`sprig toDate: expected month name at pos ${t}`)}function ff(e,t){for(let[n,r]of sf.entries())if(e.startsWith(r,t))return[n+1,t+r.length];throw Error(`sprig toDate: expected short month name at pos ${t}`)}function pf(e,t){for(let n of[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`])if(e.startsWith(n,t))return t+n.length;throw Error(`sprig toDate: expected weekday name at pos ${t}`)}function mf(e,t){for(let n of[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`])if(e.startsWith(n,t))return t+n.length;throw Error(`sprig toDate: expected short weekday name at pos ${t}`)}function hf(e,t){if(e[t]===` `){let[n,r]=uf(e,t+1,1,1);return[n,r]}return uf(e,t,1,2)}function gf(e,t,n){let r=e[t]===`+`?1:e[t]===`-`?-1:0;if(r===0)throw Error(`sprig toDate: expected +/- at pos ${t}`);let i=t+1,[a,o]=uf(e,i,2,2);i=o;let s=0;if(n&&e[i]===`:`){let[t,n]=uf(e,i+1,2,2);s=t,i=n}else if(!n){let[t,n]=uf(e,i,2,2);s=t,i=n}return[r*(a*60+s),i]}function _f(e,t,n,r){if(e[t]===`Z`)return[0,t+1];if(r){let n=e[t]===`+`?1:e[t]===`-`?-1:0;if(n===0)throw Error(`sprig toDate: expected Z or +/- at pos ${t}`);let[r,i]=uf(e,t+1,2,2);return[n*r*60,i]}return gf(e,t,n)}function vf(e,t){let n=t;for(;n<e.length&&e.charCodeAt(n)>=65&&e.charCodeAt(n)<=90;)n++;if(n===t)throw Error(`sprig toDate: expected timezone abbreviation at pos ${t}`);return n}function yf(e,t,n){let[r,i]=lf(e,t,n),a=parseInt(r.padEnd(9,`0`),10);return[Math.round(a/1e6),i]}function bf(e,t,n,r){let i={...r};switch(e){case`January`:{let[e,r]=df(t,n);return i.month=e,[r,i]}case`Monday`:return[pf(t,n),i];case`Jan`:{let[e,r]=ff(t,n);return i.month=e,[r,i]}case`Mon`:return[mf(t,n),i];case`2006`:{let[e,r]=uf(t,n,4,4);return i.year=e,[r,i]}case`06`:{let[e,r]=uf(t,n,2,2);return i.year=e<70?2e3+e:1900+e,[r,i]}case`01`:{let[e,r]=uf(t,n,2,2);return i.month=e,[r,i]}case`1`:{let[e,r]=uf(t,n,1,2);return i.month=e,[r,i]}case`_2`:{let[e,r]=hf(t,n);return i.day=e,[r,i]}case`02`:{let[e,r]=uf(t,n,2,2);return i.day=e,[r,i]}case`2`:{let[e,r]=uf(t,n,1,2);return i.day=e,[r,i]}case`15`:{let[e,r]=uf(t,n,2,2);return i.hour=e,[r,i]}case`03`:{let[e,r]=uf(t,n,2,2);return i.hour=e,i.hour12=!0,[r,i]}case`3`:{let[e,r]=uf(t,n,1,2);return i.hour=e,i.hour12=!0,[r,i]}case`04`:{let[e,r]=uf(t,n,2,2);return i.minute=e,[r,i]}case`4`:{let[e,r]=uf(t,n,1,2);return i.minute=e,[r,i]}case`05`:{let[e,r]=uf(t,n,2,2);return i.second=e,[r,i]}case`5`:{let[e,r]=uf(t,n,1,2);return i.second=e,[r,i]}case`PM`:case`pm`:{let e=t.slice(n,n+2).toLowerCase();if(e!==`am`&&e!==`pm`)throw Error(`sprig toDate: expected AM/PM at pos ${n}, got ${JSON.stringify(t.slice(n,n+2))}`);return i.isPM=e===`pm`,i.hour12=!0,[n+2,i]}case`MST`:return[vf(t,n),i];case`-0700`:{let[e,r]=gf(t,n,!1);return i.offsetMinutes=e,[r,i]}case`-07:00`:{let[e,r]=gf(t,n,!0);return i.offsetMinutes=e,[r,i]}case`-07`:{let e=t[n]===`+`?1:t[n]===`-`?-1:0;if(e===0)throw Error(`sprig toDate: expected +/- at pos ${n}`);let[r,a]=uf(t,n+1,2,2);return i.offsetMinutes=e*r*60,[a,i]}case`Z0700`:{let[e,r]=_f(t,n,!1,!1);return i.offsetMinutes=e,[r,i]}case`Z07:00`:{let[e,r]=_f(t,n,!0,!1);return i.offsetMinutes=e,[r,i]}case`Z07`:{let[e,r]=_f(t,n,!1,!0);return i.offsetMinutes=e,[r,i]}case`.000000000`:{if(t[n]!==`.`)throw Error(`sprig toDate: expected . at pos ${n}`);let[e,r]=yf(t,n+1,9);return i.ms=e,[r,i]}case`.999999999`:{if(t[n]!==`.`)return[n,i];let e=n+1,r=e;for(;r<t.length&&t.charCodeAt(r)>=48&&t.charCodeAt(r)<=57;)r++;let a=t.slice(e,r).padEnd(9,`0`);return i.ms=Math.round(parseInt(a,10)/1e6),[r,i]}case`.000000`:{if(t[n]!==`.`)throw Error(`sprig toDate: expected . at pos ${n}`);let[e,r]=yf(t,n+1,6);return i.ms=e,[r,i]}case`.999999`:{if(t[n]!==`.`)return[n,i];let e=n+1,r=e;for(;r<t.length&&t.charCodeAt(r)>=48&&t.charCodeAt(r)<=57;)r++;let a=t.slice(e,r).padEnd(9,`0`);return i.ms=Math.round(parseInt(a,10)/1e6),[r,i]}case`.000`:{if(t[n]!==`.`)throw Error(`sprig toDate: expected . at pos ${n}`);let[e,r]=yf(t,n+1,3);return i.ms=e,[r,i]}case`.999`:{if(t[n]!==`.`)return[n,i];let e=n+1,r=e;for(;r<t.length&&t.charCodeAt(r)>=48&&t.charCodeAt(r)<=57;)r++;let a=t.slice(e,r).padEnd(3,`0`);return i.ms=parseInt(a,10),[r,i]}}throw Error(`sprig toDate: unhandled token ${e}`)}const xf=`.000000000,.999999999,.000000,.999999,.000,.999,January,Monday,Z07:00,-07:00,Z0700,-0700,2006,Jan,Mon,MST,-07,Z07,15,01,02,_2,03,04,05,06,PM,pm,1,2,3,4,5`.split(`,`);function Sf(e,t){let n=0,r=0,i=cf();for(;n<e.length;){let a=!1;for(let o of xf)if(e.startsWith(o,n)){let[e,s]=bf(o,t,r,i);r=e,i=s,n+=o.length,a=!0;break}if(!a){let i=e.charAt(n);if(t[r]!==i)throw Error(`sprig toDate: expected ${JSON.stringify(i)} at pos ${r}, got ${JSON.stringify(t[r])}`);n++,r++}}if(r!==t.length)throw Error(`sprig toDate: extra characters at pos ${r}: ${JSON.stringify(t.slice(r))}`);if(i.hour12){let e=i.hour%12;i.hour=i.isPM?e+12:e}let a=Date.UTC(i.year,i.month-1,i.day,i.hour,i.minute,i.second,i.ms)-i.offsetMinutes*60*1e3;return new Date(a)}function Cf(e,t){return Sf(e,t)}function wf(e){return String(Math.floor(xd(e).getTime()/1e3))}function Tf(e=()=>new Date){return{now:{fn:()=>af(e),argTypes:[]},date:{fn:(e,t)=>Gd(e,t),argTypes:[`string`,`value`]},dateInZone:{fn:(e,t,n)=>Kd(e,t,n),argTypes:[`string`,`value`,`string`]},dateModify:{fn:(e,t)=>qd(e,t),argTypes:[`string`,`value`]},htmlDate:{fn:e=>nf(e),argTypes:[`value`]},htmlDateInZone:{fn:(e,t)=>rf(e,t),argTypes:[`value`,`string`]},duration:{fn:e=>Jd(e),argTypes:[`value`]},durationRound:{fn:e=>tf(e),argTypes:[`value`]},toDate:{fn:(e,t)=>Cf(e,t),argTypes:[`string`,`string`]},ago:{fn:t=>Sd(t,e),argTypes:[`value`]},unixEpoch:{fn:e=>wf(e),argTypes:[`value`]}}}function Ef(e){return e==null||e===!1?!0:typeof e==`number`?e===0||Number.isNaN(e):typeof e==`bigint`?e===0n:typeof e==`string`||Array.isArray(e)?e.length===0:e instanceof Map||e instanceof Set?e.size===0:typeof e==`object`?Object.keys(e).length===0:!1}function Df(...e){for(let t of e)if(!Ef(t))return t}function Of(e,t){return Ef(t)?e:t}function kf(e){return JSON.parse(e)}function Af(e,t,n){return $l(n)?e:t}function jf(e){return JSON.stringify(e)??`null`}function Mf(e){return JSON.stringify(e,null,2)??`null`}function Nf(){return{default:{fn:(e,t)=>Of(e,t),argTypes:[`value`,`truthy`]},empty:{fn:e=>Ef(e),argTypes:[`truthy`]},coalesce:{fn:(...e)=>Df(...e),argTypes:[`truthy`]},ternary:{fn:(e,t,n)=>Af(e,t,n),argTypes:[`value`,`value`,`truthy`]},fromJson:{fn:e=>kf(e),argTypes:[`string`]},toJson:{fn:e=>jf(e),argTypes:[`serializable`],returnType:`string`},toPrettyJson:{fn:e=>Mf(e),argTypes:[`serializable`],returnType:`string`}}}function Pf(...e){let t={};for(let n=0;n<e.length;n+=2)t[e[n]]=e[n+1];return t}function Ff(e){if(e.kind!==`call`||e.name!==`dict`||e.args.length%2!=0)return null;let t=[];for(let[n,r]of e.args.entries()){if(r.kind!==`literal`||n%2==0&&typeof r.value!=`string`)return null;t.push(r.value)}return Pf(...t)}function If(e,t){return e[t]}function Lf(e,t){return t in e}function Rf(e){return Object.keys(e)}function zf(e,...t){let n={...e};for(let e of t)for(let[t,r]of Object.entries(e))t in n||(n[t]=r);return n}function Bf(e,...t){let n={...e};for(let e of t)Object.assign(n,e);return n}function Vf(e,...t){let n=new Set(t),r={};for(let[t,i]of Object.entries(e))n.has(t)||(r[t]=i);return r}function Hf(e,...t){let n={};for(let r of t)r in e&&(n[r]=e[r]);return n}function Uf(e,...t){let n=[];for(let r of t)e in r&&n.push(r[e]);return n}function Wf(e,t,n){return e[t]=n,e}function Gf(e,t){return delete e[t],e}function Kf(e){return Object.values(e)}function qf(){return{dict:{fn:(...e)=>Pf(...e),argTypes:[`string`,`value`],argTypePattern:`alternating`},get:{fn:(e,t)=>If(e,t),argTypes:[`dict`,`string`]},set:{fn:(e,t,n)=>Wf(e,t,n),argTypes:[`dict`,`string`,`value`]},unset:{fn:(e,t)=>Gf(e,t),argTypes:[`dict`,`string`]},keys:{fn:e=>Rf(e),argTypes:[`dict`]},values:{fn:e=>Kf(e),argTypes:[`dict`]},pluck:{fn:(e,...t)=>Uf(e,...t),argTypes:[`string`,`dict`]},pick:{fn:(e,...t)=>Hf(e,...t),argTypes:[`dict`,`string`]},omit:{fn:(e,...t)=>Vf(e,...t),argTypes:[`dict`,`string`]},hasKey:{fn:(e,t)=>Lf(e,t),argTypes:[`dict`,`string`]},merge:{fn:(e,...t)=>zf(e,...t),argTypes:[`dict`]},mergeOverwrite:{fn:(e,...t)=>Bf(e,...t),argTypes:[`dict`]}}}new TextEncoder,new Map(Array.from(`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`).map((e,t)=>[e,t])),new TextDecoder,new TextEncoder,new TextDecoder,new TextEncoder;function Jf(...e){for(let t of e)if(Ef(t))return!1;return!0}function Yf(...e){for(let t of e)if(!Ef(t))return!0;return!1}function Xf(e,t){return[...e,t]}function Zf(e,t){let n=Math.max(1,e),r=[];for(let e=0;e<t.length;e+=n)r.push(t.slice(e,e+n));return r}function Qf(e){return e.filter(e=>!Ef(e))}function $f(...e){let t=[];for(let n of e)t.push(...n);return t}const ep={line:0,column:0,offset:0};function tp(e,t,n,r){return new sl(e,t,n,r,ep)}function np(...e){if(e.length<3)throw tp(`dig`,0,`at least 3 arguments (...keys, default, dict)`,`${e.length} argument${e.length===1?``:`s`}`);let t=e[e.length-1],n=e[e.length-2],r=e.slice(0,-2);if(!ip(t))throw tp(`dig`,e.length-1,`dict`,ap(t));for(let e=0;e<r.length;e++)if(typeof r[e]!=`string`)throw tp(`dig`,e,`string`,ap(r[e]));return rp(t,n,r,e.length)}function rp(e,t,n,r){let i=n[0];if(!Object.hasOwn(e,i))return t;let a=e[i];if(n.length===1)return a;if(!ip(a))throw tp(`dig`,r-1,`dict at intermediate key`,ap(a));return rp(a,t,n.slice(1),r)}function ip(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&!(e instanceof Map)&&!(e instanceof Set)}function ap(e){return e===null?`null`:Array.isArray(e)?`array`:e instanceof Map?`Map`:e instanceof Set?`Set`:typeof e}function op(e){return e[0]}function sp(e,t){return t.some(t=>Yl(t,e))}function cp(e){return e.slice(0,-1)}function lp(e){return e[e.length-1]}function up(e){return Array.isArray(e)||typeof e==`string`?e.length:e instanceof Map||e instanceof Set?e.size:Object.keys(e).length}function dp(...e){return e}function fp(e,t){return[t,...e]}function pp(e){return e.slice(1)}function mp(e){return[...e].reverse()}function hp(e,t,n){let r=t===void 0?0:t,i=n===void 0?e.length:n;return e.slice(r,i)}function gp(e){let t=[];for(let n of e)n!=null&&t.push(String(n));return t.sort()}function _p(e){let t=[];for(let n of e)t.some(e=>Yl(e,n))||t.push(n);return t}function vp(e,...t){return e.filter(e=>!t.some(t=>Yl(t,e)))}function yp(){return{list:{fn:(...e)=>dp(...e),argTypes:[`value`]},first:{fn:e=>op(e),argTypes:[`list`]},last:{fn:e=>lp(e),argTypes:[`list`]},rest:{fn:e=>pp(e),argTypes:[`list`]},initial:{fn:e=>cp(e),argTypes:[`list`]},len:{fn:e=>up(e),argTypes:[`sized`]},reverse:{fn:e=>mp(e),argTypes:[`list`]},uniq:{fn:e=>_p(e),argTypes:[`list`]},without:{fn:(e,...t)=>vp(e,...t),argTypes:[`list`,`value`]},has:{fn:(e,t)=>sp(e,t),argTypes:[`value`,`list`]},compact:{fn:e=>Qf(e),argTypes:[`list`]},slice:{fn:(e,t,n)=>hp(e,t,n),argTypes:[`list`,`int`,`int`]},concat:{fn:(...e)=>$f(...e),argTypes:[`list`]},chunk:{fn:(e,t)=>Zf(e,t),argTypes:[`int`,`list`]},prepend:{fn:(e,t)=>fp(e,t),argTypes:[`list`,`value`]},append:{fn:(e,t)=>Xf(e,t),argTypes:[`list`,`value`]},sortAlpha:{fn:e=>gp(e),argTypes:[`list`],returnType:`list`},push:{fn:(e,t)=>Xf(e,t),argTypes:[`list`,`value`]},tuple:{fn:(...e)=>dp(...e),argTypes:[`value`]},dig:{fn:(...e)=>np(...e),argTypes:[`value`]},all:{fn:(...e)=>Jf(...e),argTypes:[`truthy`],returnType:`bool`},any:{fn:(...e)=>Yf(...e),argTypes:[`truthy`],returnType:`bool`}}}function bp(...e){return e.reduce((e,t)=>e+t,0)}function xp(e){return e+1}function Sp(e){return e+1}function Cp(...e){return e.reduce((e,t)=>e+t,0)}function wp(e){return Math.ceil(e)}function Tp(e,t){return Math.trunc(e/t)}function Ep(e,t){return e/t}function Dp(e){return Math.floor(e)}function Op(...e){return e.reduce((e,t)=>t>e?t:e,-1/0)}function kp(...e){return e.reduce((e,t)=>Math.max(e,t),-1/0)}function Ap(...e){return e.reduce((e,t)=>t<e?t:e,1/0)}function jp(...e){return e.reduce((e,t)=>Math.min(e,t),1/0)}function Mp(e,t){return e%t}function Np(...e){return e.reduce((e,t)=>e*t,1)}function Pp(...e){return e.reduce((e,t)=>e*t,1)}function Fp(e,t=0){let n=10**t;return Math.sign(e)*Math.round(Math.abs(e)*n)/n}function Ip(e,t,n){let r=[];if(t<e){if(n>=0)return r;for(let i=e;i>t;i+=n)r.push(i);return r}if(n<=0)return r;for(let i=e;i<t;i+=n)r.push(i);return r}function Lp(...e){let t=1;switch(e.length){case 0:return``;case 1:{let n=e[0];return n<1&&(t=-1),Ip(1,n+t,t).join(` `)}case 2:{let t=e[0],n=e[1],r=n<t?-1:1;return Ip(t,n+r,r).join(` `)}case 3:{let n=e[0],r=e[1],i=e[2];return i<n&&(t=-1,r>0)?``:Ip(n,i+t,r).join(` `)}default:return``}}function Rp(e,t){return e-t}function zp(e,t){return e-t}function Bp(e){return Ip(0,e,e<0?-1:1)}function Vp(){return{add:{fn:(...e)=>bp(...e),argTypes:[`int`]},sub:{fn:(e,t)=>Rp(e,t),argTypes:[`int`,`int`]},mul:{fn:(...e)=>Np(...e),argTypes:[`int`]},div:{fn:(e,t)=>Tp(e,t),argTypes:[`int`,`int`]},mod:{fn:(e,t)=>Mp(e,t),argTypes:[`int`,`int`]},min:{fn:(...e)=>Ap(...e),argTypes:[`int`]},max:{fn:(...e)=>Op(...e),argTypes:[`int`]},floor:{fn:e=>Dp(e),argTypes:[`float`]},ceil:{fn:e=>wp(e),argTypes:[`float`]},round:{fn:(e,t)=>Fp(e,t),argTypes:[`float`,`int`]},addf:{fn:(...e)=>Cp(...e),argTypes:[`float`]},subf:{fn:(e,t)=>zp(e,t),argTypes:[`float`,`float`]},mulf:{fn:(...e)=>Pp(...e),argTypes:[`float`]},divf:{fn:(e,t)=>Ep(e,t),argTypes:[`float`,`float`]},add1:{fn:e=>xp(e),argTypes:[`int`]},add1f:{fn:e=>Sp(e),argTypes:[`float`]},maxf:{fn:(...e)=>kp(...e),argTypes:[`float`]},minf:{fn:(...e)=>jp(...e),argTypes:[`float`]},biggest:{fn:(...e)=>Op(...e),argTypes:[`int`]},seq:{fn:(...e)=>Lp(...e),argTypes:[`int`],returnType:`string`},until:{fn:e=>Bp(e),argTypes:[`int`],returnType:`list`},untilStep:{fn:(e,t,n)=>Ip(e,t,n),argTypes:[`int`,`int`,`int`],returnType:`list`}}}Array.from({length:95},(e,t)=>String.fromCharCode(t+32)).join(``);function Hp(e,t){return t.length<=e||e<4?t:`${t.slice(0,e-3)}...`}function Up(e,t,n){return t<7||n.length<t||e<0||e>n.length-t+1?n:`...${n.slice(e,e+t-6)}...`}const Y={Invalid:0,Number:1,UpperCase:2,Alphabet:3,Connector:4,Punct:5,Other:6},Wp=/^[-_\s]$/,Gp=/^\p{P}$/u,Kp=/^\p{L}$/u,qp=/^\p{Lu}$/u,Jp=/^\p{N}$/u;function Yp(e){return e!==void 0&&Wp.test(e)}function Xp(e){return e!==void 0&&Kp.test(e)}function Zp(e){return e!==void 0&&qp.test(e)}function Qp(e){return e!==void 0&&Jp.test(e)}function $p(e){return e!==void 0&&Gp.test(e)}function em(e,t){if(t>=e.length)return{word:{wt:Y.Invalid,text:``},next:t};let n=e[t],r=t+1;if(Yp(n)){for(;r<e.length&&Yp(e[r]);)r++;return{word:{wt:Y.Connector,text:e.slice(t,r).join(``)},next:r}}if($p(n)){for(;r<e.length&&$p(e[r]);)r++;return{word:{wt:Y.Punct,text:e.slice(t,r).join(``)},next:r}}if(Zp(n)){if(r>=e.length)return{word:{wt:Y.UpperCase,text:n},next:r};if(Zp(e[r])){let n=r;for(;n<e.length&&Zp(e[n]);)n++;return n<e.length&&Xp(e[n])?{word:{wt:Y.UpperCase,text:e.slice(t,n-1).join(``)},next:n-1}:{word:{wt:Y.UpperCase,text:e.slice(t,n).join(``)},next:n}}if(Xp(e[r])){let n=r+1;for(;n<e.length&&Xp(e[n])&&!Zp(e[n]);)n++;return{word:{wt:Y.UpperCase,text:e.slice(t,n).join(``)},next:n}}return{word:{wt:Y.UpperCase,text:n},next:r}}if(Xp(n)){for(;r<e.length&&Xp(e[r])&&!Zp(e[r]);)r++;return{word:{wt:Y.Alphabet,text:e.slice(t,r).join(``)},next:r}}if(Qp(n)){for(;r<e.length&&Qp(e[r]);)r++;return{word:{wt:Y.Number,text:e.slice(t,r).join(``)},next:r}}for(;r<e.length&&!Yp(e[r])&&!Xp(e[r])&&!Qp(e[r])&&!$p(e[r]);)r++;return{word:{wt:Y.Other,text:e.slice(t,r).join(``)},next:r}}function tm(e,t,n){if(t.wt!==Y.UpperCase&&t.wt!==Y.Connector){e.push(t.text);return}for(let r of t.text)Yp(r)?e.push(n):Zp(r)?e.push(r.toLowerCase()):e.push(r)}function nm(e,t){if(e.length===0)return``;let n=Array.from(e),r=[],{word:i,next:a}=em(n,0);for(;a<n.length;){i.wt!==Y.Connector&&tm(r,i,t);let e=i,o=i;if({word:i,next:a}=em(n,a),e.wt===Y.Number){for(;i.wt===Y.Alphabet||i.wt===Y.Number;)tm(r,i,t),{word:i,next:a}=em(n,a);i.wt!==Y.Invalid&&i.wt!==Y.Punct&&i.wt!==Y.Connector&&r.push(t);continue}if(e.wt===Y.Connector){tm(r,o,t);continue}if(e.wt===Y.Punct)continue;if(i.wt!==Y.Number){i.wt!==Y.Connector&&i.wt!==Y.Punct&&r.push(t);continue}if(a>=n.length)continue;let s=i;if({word:i,next:a}=em(n,a),i.wt!==Y.Alphabet){tm(r,s,t),i.wt!==Y.Connector&&i.wt!==Y.Punct&&r.push(t);continue}for(r.push(t),tm(r,s,t);i.wt===Y.Alphabet||i.wt===Y.Number;)tm(r,i,t),{word:i,next:a}=em(n,a);i.wt!==Y.Invalid&&i.wt!==Y.Connector&&i.wt!==Y.Punct&&r.push(t)}return tm(r,i,t),r.join(``).toLowerCase()}function rm(e){if(e.length===0)return``;let t=Array.from(e),n=[],r=0,i=``;for(;r<t.length;){if(i=t[r],r++,!Yp(i)){i=i.toUpperCase();break}n.push(i)}if(r>=t.length)return t.length>0&&n.push(i),n.join(``);for(;r<t.length;){let e=i;if(i=t[r],r++,Yp(i)&&Yp(e)){n.push(e);continue}Yp(e)?i=i.toUpperCase():(i=i.toLowerCase(),n.push(e))}return n.push(i),n.join(``)}function im(e){return rm(e)}function am(...e){return e.join(` `)}function om(e,t){return t.includes(e)}function sm(e,t){return t.startsWith(e)}function cm(e,t){return t.endsWith(e)}function lm(e,t){let n=` `.repeat(Math.max(0,e));return t.split(`
|
|
81
81
|
`).map(e=>n+e).join(`
|
|
82
|
-
`)}function
|
|
83
|
-
`,t)}function
|
|
84
|
-
`)){let n=``;for(let i of t.split(/\s+/))i.length!==0&&(n.length===0?n=i:n.length+1+i.length<=e?n+=` ${i}`:(r.push(n),n=i));n.length>0&&r.push(n)}return r.join(t)}function
|
|
85
|
-
`)}function
|
|
86
|
-
`)?r.slice(0,-1):r}return $o(new Uo([...e],n),{colorSystem:t.colorCompatibility})}const ah=[`vertical`,`horizontal`];function*oh(e){if(yield e,e.kind===`container`)for(let t of e.children)yield*oh(t)}const sh=[`ttl`,`watch_file`,`depends_on`,`key`,`never`];function ch(e){return e.kind!==`literal`&&e.kind!==`input`&&e.kind!==`env`&&e.kind!==`state`}const lh=[`branch`,`sha`,`dirty`,`ahead`,`behind`,`stash`],uh=[`file`,`shell`,`git`],dh=[`left`,`center`,`right`],fh=[`right`,`left`,`middle`];var ph=ue(((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]/})),mh=ue(((e,t)=>{let n=ph();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)}}})),hh=ue(((e,t)=>{let n=mh(),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(),te[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===`
|
|
82
|
+
`)}function um(e){let t=new TextEncoder;return e.split(/\s+/).filter(e=>e.length>0).map(e=>String.fromCharCode(...t.encode(e).slice(0,1))).join(``)}function dm(e,t){let n=[];for(let e of t){if(typeof e==`object`&&e)throw tp(`join`,2,`list of strings/primitives`,`list element of type ${fm(e)}`);n.push(String(e))}return n.join(e)}function fm(e){return Array.isArray(e)?`array`:e instanceof Map?`Map`:e instanceof Set?`Set`:`object`}function pm(e){return nm(e,`-`)}function mm(e){return e.toLowerCase()}function hm(e,t){return`\n${lm(e,t)}`}function gm(e){return e.replace(/\s+/g,``)}function _m(e,t,n){return n===1?e:t}function vm(...e){return e.map(e=>`"${e}"`).join(` `)}function ym(e){return e.replace(/[\\.+*?()|[\]{}^$]/g,`\\$&`)}function bm(e,t){return t.repeat(Math.max(0,e))}function xm(e,t,n){return n.split(e).join(t)}function Sm(e){return nm(e,`_`)}function Cm(e,t){let n=t.split(e),r={};for(let e=0;e<n.length;e++)r[`_${e}`]=n[e];return r}function wm(e,t){return t.split(e)}function Tm(e,t,n){let r=Em(n,e,t),i={};for(let e=0;e<r.length;e++)i[`_${e}`]=r[e]??``;return i}function Em(e,t,n){if(n===0)return[];let r=t===``?Array.from(e):e.split(t);if(n<0||r.length<=n)return r;let i=r.slice(0,n-1),a=r.slice(n-1).join(t);return[...i,a]}function Dm(...e){return e.map(e=>`'${e}'`).join(` `)}function Om(e,t,n){let r=t<0||t>n.length?n.length:t,i=Math.min(Math.max(0,e),r);return n.slice(i,r)}function km(e){let t=``;for(let n of e)Am(n)?t+=n.toLowerCase():jm(n)?t+=n.toUpperCase():t+=n;return t}function Am(e){return e!==e.toLowerCase()&&e===e.toUpperCase()}function jm(e){return e!==e.toUpperCase()&&e===e.toLowerCase()}function Mm(e){return e.replace(/\b([a-zA-Z])/g,e=>e.toUpperCase())}function Nm(e){return e.trim()}function Pm(e,t){if(e.length===0)return t;let n=new Set([...e]),r=0;for(;r<t.length&&n.has(t[r]);)r+=1;let i=t.length;for(;i>r&&n.has(t[i-1]);)--i;return t.slice(r,i)}function Fm(e,t){return t.startsWith(e)?t.slice(e.length):t}function Im(e,t){return t.endsWith(e)?t.slice(0,t.length-e.length):t}function Lm(e,t){if(e<0){let n=-e;return n>=t.length?t:t.slice(t.length-n)}return e>=t.length?t:t.slice(0,e)}function Rm(e){return e.replace(/\b([A-Z])/g,e=>e.toLowerCase())}function zm(e){return e.toUpperCase()}function Bm(e,t){return Vm(e,`
|
|
83
|
+
`,t)}function Vm(e,t,n){if(e<=0)return n;let r=[];for(let t of n.split(`
|
|
84
|
+
`)){let n=``;for(let i of t.split(/\s+/))i.length!==0&&(n.length===0?n=i:n.length+1+i.length<=e?n+=` ${i}`:(r.push(n),n=i));n.length>0&&r.push(n)}return r.join(t)}function Hm(e,t,n){return Vm(e,t,n)}function Um(){return{abbrev:{fn:(e,t)=>Hp(e,t),argTypes:[`int`,`string`]},abbrevboth:{fn:(e,t,n)=>Up(e,t,n),argTypes:[`int`,`int`,`string`]},camelcase:{fn:e=>im(e),argTypes:[`string`],returnType:`string`},cat:{fn:(...e)=>am(...e),argTypes:[`string`]},contains:{fn:(e,t)=>om(e,t),argTypes:[`string`,`string`]},hasPrefix:{fn:(e,t)=>sm(e,t),argTypes:[`string`,`string`]},hasSuffix:{fn:(e,t)=>cm(e,t),argTypes:[`string`,`string`]},indent:{fn:(e,t)=>lm(e,t),argTypes:[`int`,`string`]},initials:{fn:e=>um(e),argTypes:[`string`]},join:{fn:(e,t)=>dm(e,t),argTypes:[`string`,`list`]},kebabcase:{fn:e=>pm(e),argTypes:[`string`],returnType:`string`},lower:{fn:e=>mm(e),argTypes:[`string`]},nindent:{fn:(e,t)=>hm(e,t),argTypes:[`int`,`string`]},nospace:{fn:e=>gm(e),argTypes:[`string`],returnType:`string`},plural:{fn:(e,t,n)=>_m(e,t,n),argTypes:[`string`,`string`,`int`],returnType:`string`},quote:{fn:(...e)=>vm(...e),argTypes:[`string`]},regexQuoteMeta:{fn:e=>ym(e),argTypes:[`string`],returnType:`string`},repeat:{fn:(e,t)=>bm(e,t),argTypes:[`int`,`string`]},replace:{fn:(e,t,n)=>xm(e,t,n),argTypes:[`string`,`string`,`string`]},snakecase:{fn:e=>Sm(e),argTypes:[`string`],returnType:`string`},split:{fn:(e,t)=>Cm(e,t),argTypes:[`string`,`string`]},splitList:{fn:(e,t)=>wm(e,t),argTypes:[`string`,`string`]},splitn:{fn:(e,t,n)=>Tm(e,t,n),argTypes:[`string`,`int`,`string`],returnType:`dict`},squote:{fn:(...e)=>Dm(...e),argTypes:[`string`]},substr:{fn:(e,t,n)=>Om(e,t,n),argTypes:[`int`,`int`,`string`]},swapcase:{fn:e=>km(e),argTypes:[`string`],returnType:`string`},title:{fn:e=>Mm(e),argTypes:[`string`]},trim:{fn:e=>Nm(e),argTypes:[`string`]},trimAll:{fn:(e,t)=>Pm(e,t),argTypes:[`string`,`string`]},trimPrefix:{fn:(e,t)=>Fm(e,t),argTypes:[`string`,`string`]},trimSuffix:{fn:(e,t)=>Im(e,t),argTypes:[`string`,`string`]},trunc:{fn:(e,t)=>Lm(e,t),argTypes:[`int`,`string`]},untitle:{fn:e=>Rm(e),argTypes:[`string`]},upper:{fn:e=>zm(e),argTypes:[`string`]},wrap:{fn:(e,t)=>Bm(e,t),argTypes:[`int`,`string`]},wrapWith:{fn:(e,t,n)=>Hm(e,t,n),argTypes:[`int`,`string`,`string`]}}}var Wm=class extends Error{file;issues;constructor(e,t){super(qm(e,t)),this.name=`ConfigError`,this.file=e,this.issues=t}};function X(e,t){let n=0,r;for(let i of t){if(i===``||/^\d+$/.test(i))continue;let t=Gm(e,n,i);if(t===-1)return r===void 0?void 0:Km(e,r);n=t,r=t}return r===void 0?void 0:Km(e,r)}function Gm(e,t,n){let r=n.replace(/[\\^$.*+?()[\]{}|]/g,`\\$&`),i=RegExp(`(?:["']${r}["']|\\b${r}\\b)\\s*:`,`g`);i.lastIndex=t;let a=i.exec(e);return a?a.index:-1}function Km(e,t){let n=1;for(let r=0;r<t&&r<e.length;r++)e.charCodeAt(r)===10&&n++;return n}function qm(e,t){if(t.length===0)return`${e}: invalid config (no details)`;let n=[`Invalid config in ${e} (${t.length} issue${t.length===1?``:`s`}):`];for(let e of t){let t=[];e.line!==void 0&&t.push(`line ${e.line}${e.col===void 0?``:`:${e.col}`}`),e.path&&t.push(e.path);let r=t.length>0?`[${t.join(` • `)}] `:``;n.push(` ${r}${e.message}`)}return n.join(`
|
|
85
|
+
`)}function Jm(e,t,n,r){for(let i of[`variables`,`actions`,`segments`])for(let a of Object.keys(t[i]??{}))a.startsWith(n)&&e.issues.push({path:`${i}.${a}`,message:`"${a}" is in the reserved "${n}" namespace (synthesized by ${r}) — rename it`,line:X(e.source,[`root`])})}const Ym=`edit.`,Xm=`edit.mode`,Zm=`edit.toggle`,Qm=`open`,$m={variable:Xm,member:Qm},eh=en($m);function th(e){let t=Hu({fromString:e=>e});try{return t.parse(e).referencedCalls().some(e=>e.name===`action`&&e.args[0]===`edit.toggle`)}catch{return!1}}function nh(e){for(let t of Object.values(e.segments??{}))for(let e of[t.template,t.bg,t.fg])if(typeof e==`string`&&th(e))return!0;return!1}function rh(e,t){if(Jm(e,t,Ym,`edit mode`),!nh(t))return;let n={[Xm]:P(Xm,Xt)},r={[Zm]:nn(Xm,Qm)};t.variables={...t.variables??{},...n},t.actions={...t.actions??{},...r}}const ih={unicode:{},ascii:{glyph:`>`}},ah={unicode:{},ascii:{left:`(`,right:`)`}};function oh(e,t,n){switch(e){case`capsule`:return new Yo(ah[t]);case`plain`:return new Xo(n===void 0?{}:{separator:n});case`powerline`:return new Jo(ih[t]);default:return e}}function sh(e){switch(e){case`powerline`:return 1;case`capsule`:return 2;case`plain`:return 0;default:return e}}function ch(e,t){if(e.length===0)return``;let n=oh(t.style,t.charset,t.separator);if(t.wrap&&Number.isFinite(t.width)){let r=$o(new ds([...e],{joiner:n}),{width:t.width,colorSystem:t.colorCompatibility});return r.endsWith(`
|
|
86
|
+
`)?r.slice(0,-1):r}return $o(new Uo([...e],n),{colorSystem:t.colorCompatibility})}const lh=[`vertical`,`horizontal`];function*uh(e){if(yield e,e.kind===`container`)for(let t of e.children)yield*uh(t)}const dh=[`ttl`,`watch_file`,`depends_on`,`key`,`never`];function fh(e){return e.kind!==`literal`&&e.kind!==`input`&&e.kind!==`env`&&e.kind!==`state`}const ph=[`branch`,`sha`,`dirty`,`ahead`,`behind`,`stash`],mh=[`file`,`shell`,`git`],hh=[`left`,`center`,`right`],gh=[`right`,`left`,`middle`];var _h=ue(((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]/})),vh=ue(((e,t)=>{let n=_h();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)}}})),yh=ue(((e,t)=>{let n=vh(),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(),te[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===`
|
|
87
87
|
`?(s++,c=0):e?c+=e.length:c++,e&&(o+=e.length),e}let x={default(){switch(_){case` `:case`\v`:case`\f`:case` `:case`\xA0`:case``:case`
|
|
88
88
|
`:case`\r`:case`\u2028`:case`\u2029`:b();return;case`/`:b(),p=`comment`;return;case void 0:return b(),S(`eof`)}if(n.isSpaceSeparator(_)){b();return}return x[i]()},comment(){switch(_){case`*`:b(),p=`multiLineComment`;return;case`/`:b(),p=`singleLineComment`;return}throw E(b())},multiLineComment(){switch(_){case`*`:b(),p=`multiLineCommentAsterisk`;return;case void 0:throw E(b())}b()},multiLineCommentAsterisk(){switch(_){case`*`:b();return;case`/`:b(),p=`default`;return;case void 0:throw E(b())}b(),p=`multiLineComment`},singleLineComment(){switch(_){case`
|
|
89
89
|
`:case`\r`:case`\u2028`:case`\u2029`:b(),p=`default`;return;case void 0:return b(),S(`eof`)}b()},value(){switch(_){case`{`:case`[`:return S(`punctuator`,b());case`n`:return b(),C(`ull`),S(`null`,null);case`t`:return b(),C(`rue`),S(`boolean`,!0);case`f`:return b(),C(`alse`),S(`boolean`,!1);case`-`:case`+`:b()===`-`&&(g=-1),p=`sign`;return;case`.`:m=b(),p=`decimalPointLeading`;return;case`0`:m=b(),p=`zero`;return;case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:case`8`:case`9`:m=b(),p=`decimalInteger`;return;case`I`:return b(),C(`nfinity`),S(`numeric`,1/0);case`N`:return b(),C(`aN`),S(`numeric`,NaN);case`"`:case`'`:h=b()===`"`,m=``,p=`string`;return}throw E(b())},identifierNameStartEscape(){if(_!==`u`)throw E(b());b();let e=T();switch(e){case`$`:case`_`:break;default:if(!n.isIdStartChar(e))throw ie();break}m+=e,p=`identifierName`},identifierName(){switch(_){case`$`:case`_`:case``:case``:m+=b();return;case`\\`:b(),p=`identifierNameEscape`;return}if(n.isIdContinueChar(_)){m+=b();return}return S(`identifier`,m)},identifierNameEscape(){if(_!==`u`)throw E(b());b();let e=T();switch(e){case`$`:case`_`:case``:case``:break;default:if(!n.isIdContinueChar(e))throw ie();break}m+=e,p=`identifierName`},sign(){switch(_){case`.`:m=b(),p=`decimalPointLeading`;return;case`0`:m=b(),p=`zero`;return;case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:case`8`:case`9`:m=b(),p=`decimalInteger`;return;case`I`:return b(),C(`nfinity`),S(`numeric`,g*(1/0));case`N`:return b(),C(`aN`),S(`numeric`,NaN)}throw E(b())},zero(){switch(_){case`.`:m+=b(),p=`decimalPoint`;return;case`e`:case`E`:m+=b(),p=`decimalExponent`;return;case`x`:case`X`:m+=b(),p=`hexadecimal`;return}return S(`numeric`,g*0)},decimalInteger(){switch(_){case`.`:m+=b(),p=`decimalPoint`;return;case`e`:case`E`:m+=b(),p=`decimalExponent`;return}if(n.isDigit(_)){m+=b();return}return S(`numeric`,g*Number(m))},decimalPointLeading(){if(n.isDigit(_)){m+=b(),p=`decimalFraction`;return}throw E(b())},decimalPoint(){switch(_){case`e`:case`E`:m+=b(),p=`decimalExponent`;return}if(n.isDigit(_)){m+=b(),p=`decimalFraction`;return}return S(`numeric`,g*Number(m))},decimalFraction(){switch(_){case`e`:case`E`:m+=b(),p=`decimalExponent`;return}if(n.isDigit(_)){m+=b();return}return S(`numeric`,g*Number(m))},decimalExponent(){switch(_){case`+`:case`-`:m+=b(),p=`decimalExponentSign`;return}if(n.isDigit(_)){m+=b(),p=`decimalExponentInteger`;return}throw E(b())},decimalExponentSign(){if(n.isDigit(_)){m+=b(),p=`decimalExponentInteger`;return}throw E(b())},decimalExponentInteger(){if(n.isDigit(_)){m+=b();return}return S(`numeric`,g*Number(m))},hexadecimal(){if(n.isHexDigit(_)){m+=b(),p=`hexadecimalInteger`;return}throw E(b())},hexadecimalInteger(){if(n.isHexDigit(_)){m+=b();return}return S(`numeric`,g*Number(m))},string(){switch(_){case`\\`:b(),m+=w();return;case`"`:if(h)return b(),S(`string`,m);m+=b();return;case`'`:if(!h)return b(),S(`string`,m);m+=b();return;case`
|
|
90
90
|
`:case`\r`:throw E(b());case`\u2028`:case`\u2029`:ae(_);break;case void 0:throw E(b())}m+=b()},start(){switch(_){case`{`:case`[`:return S(`punctuator`,b())}p=`value`},beforePropertyName(){switch(_){case`$`:case`_`:m=b(),p=`identifierName`;return;case`\\`:b(),p=`identifierNameStartEscape`;return;case`}`:return S(`punctuator`,b());case`"`:case`'`:h=b()===`"`,p=`string`;return}if(n.isIdStartChar(_)){m+=b(),p=`identifierName`;return}throw E(b())},afterPropertyName(){if(_===`:`)return S(`punctuator`,b());throw E(b())},beforePropertyValue(){p=`value`},afterPropertyValue(){switch(_){case`,`:case`}`:return S(`punctuator`,b())}throw E(b())},beforeArrayValue(){if(_===`]`)return S(`punctuator`,b());p=`value`},afterArrayValue(){switch(_){case`,`:case`]`:return S(`punctuator`,b())}throw E(b())},end(){throw E(b())}};function S(e,t){return{type:e,value:t,line:s,column:c}}function C(e){for(let t of e){if(y()!==t)throw E(b());b()}}function w(){switch(y()){case`b`:return b(),`\b`;case`f`:return b(),`\f`;case`n`:return b(),`
|
|
91
91
|
`;case`r`:return b(),`\r`;case`t`:return b(),` `;case`v`:return b(),`\v`;case`0`:if(b(),n.isDigit(y()))throw E(b());return`\0`;case`x`:return b(),ee();case`u`:return b(),T();case`
|
|
92
92
|
`:case`\u2028`:case`\u2029`:return b(),``;case`\r`:return b(),y()===`
|
|
93
|
-
`&&b(),``;case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:case`8`:case`9`:throw E(b());case void 0:throw E(b())}return b()}function ee(){let e=``,t=y();if(!n.isHexDigit(t)||(e+=b(),t=y(),!n.isHexDigit(t)))throw E(b());return e+=b(),String.fromCodePoint(parseInt(e,16))}function T(){let e=``,t=4;for(;t-- >0;){let t=y();if(!n.isHexDigit(t))throw E(b());e+=b()}return String.fromCodePoint(parseInt(e,16))}let te={start(){if(l.type===`eof`)throw D();ne()},beforePropertyName(){switch(l.type){case`identifier`:case`string`:u=l.value,i=`afterPropertyName`;return;case`punctuator`:re();return;case`eof`:throw D()}},afterPropertyName(){if(l.type===`eof`)throw D();i=`beforePropertyValue`},beforePropertyValue(){if(l.type===`eof`)throw D();ne()},beforeArrayValue(){if(l.type===`eof`)throw D();if(l.type===`punctuator`&&l.value===`]`){re();return}ne()},afterPropertyValue(){if(l.type===`eof`)throw D();switch(l.value){case`,`:i=`beforePropertyName`;return;case`}`:re()}},afterArrayValue(){if(l.type===`eof`)throw D();switch(l.value){case`,`:i=`beforeArrayValue`;return;case`]`:re()}},end(){}};function ne(){let e;switch(l.type){case`punctuator`:switch(l.value){case`{`:e={};break;case`[`:e=[];break}break;case`null`:case`boolean`:case`numeric`:case`string`:e=l.value;break}if(d===void 0)d=e;else{let t=a[a.length-1];Array.isArray(t)?t.push(e):Object.defineProperty(t,u,{value:e,writable:!0,enumerable:!0,configurable:!0})}if(typeof e==`object`&&e)a.push(e),i=Array.isArray(e)?`beforeArrayValue`:`beforePropertyName`;else{let e=a[a.length-1];i=e==null?`end`:Array.isArray(e)?`afterArrayValue`:`afterPropertyValue`}}function re(){a.pop();let e=a[a.length-1];i=e==null?`end`:Array.isArray(e)?`afterArrayValue`:`afterPropertyValue`}function E(e){return se(e===void 0?`JSON5: invalid end of input at ${s}:${c}`:`JSON5: invalid character '${oe(e)}' at ${s}:${c}`)}function D(){return se(`JSON5: invalid end of input at ${s}:${c}`)}function ie(){return c-=5,se(`JSON5: invalid identifier character at ${s}:${c}`)}function ae(e){console.warn(`JSON5: '${oe(e)}' in strings is not valid ECMAScript; consider escaping`)}function oe(e){let t={"'":`\\'`,'"':`\\"`,"\\":`\\\\`,"\b":`\\b`,"\f":`\\f`,"\n":`\\n`,"\r":`\\r`," ":`\\t`,"\v":`\\v`,"\0":`\\0`,"\u2028":`\\u2028`,"\u2029":`\\u2029`};if(t[e])return t[e];if(e<` `){let t=e.charCodeAt(0).toString(16);return`\\x`+(`00`+t).substring(t.length)}return e}function se(e){let t=SyntaxError(e);return t.lineNumber=s,t.columnNumber=c,t}})),
|
|
93
|
+
`&&b(),``;case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:case`8`:case`9`:throw E(b());case void 0:throw E(b())}return b()}function ee(){let e=``,t=y();if(!n.isHexDigit(t)||(e+=b(),t=y(),!n.isHexDigit(t)))throw E(b());return e+=b(),String.fromCodePoint(parseInt(e,16))}function T(){let e=``,t=4;for(;t-- >0;){let t=y();if(!n.isHexDigit(t))throw E(b());e+=b()}return String.fromCodePoint(parseInt(e,16))}let te={start(){if(l.type===`eof`)throw D();ne()},beforePropertyName(){switch(l.type){case`identifier`:case`string`:u=l.value,i=`afterPropertyName`;return;case`punctuator`:re();return;case`eof`:throw D()}},afterPropertyName(){if(l.type===`eof`)throw D();i=`beforePropertyValue`},beforePropertyValue(){if(l.type===`eof`)throw D();ne()},beforeArrayValue(){if(l.type===`eof`)throw D();if(l.type===`punctuator`&&l.value===`]`){re();return}ne()},afterPropertyValue(){if(l.type===`eof`)throw D();switch(l.value){case`,`:i=`beforePropertyName`;return;case`}`:re()}},afterArrayValue(){if(l.type===`eof`)throw D();switch(l.value){case`,`:i=`beforeArrayValue`;return;case`]`:re()}},end(){}};function ne(){let e;switch(l.type){case`punctuator`:switch(l.value){case`{`:e={};break;case`[`:e=[];break}break;case`null`:case`boolean`:case`numeric`:case`string`:e=l.value;break}if(d===void 0)d=e;else{let t=a[a.length-1];Array.isArray(t)?t.push(e):Object.defineProperty(t,u,{value:e,writable:!0,enumerable:!0,configurable:!0})}if(typeof e==`object`&&e)a.push(e),i=Array.isArray(e)?`beforeArrayValue`:`beforePropertyName`;else{let e=a[a.length-1];i=e==null?`end`:Array.isArray(e)?`afterArrayValue`:`afterPropertyValue`}}function re(){a.pop();let e=a[a.length-1];i=e==null?`end`:Array.isArray(e)?`afterArrayValue`:`afterPropertyValue`}function E(e){return se(e===void 0?`JSON5: invalid end of input at ${s}:${c}`:`JSON5: invalid character '${oe(e)}' at ${s}:${c}`)}function D(){return se(`JSON5: invalid end of input at ${s}:${c}`)}function ie(){return c-=5,se(`JSON5: invalid identifier character at ${s}:${c}`)}function ae(e){console.warn(`JSON5: '${oe(e)}' in strings is not valid ECMAScript; consider escaping`)}function oe(e){let t={"'":`\\'`,'"':`\\"`,"\\":`\\\\`,"\b":`\\b`,"\f":`\\f`,"\n":`\\n`,"\r":`\\r`," ":`\\t`,"\v":`\\v`,"\0":`\\0`,"\u2028":`\\u2028`,"\u2029":`\\u2029`};if(t[e])return t[e];if(e<` `){let t=e.charCodeAt(0).toString(16);return`\\x`+(`00`+t).substring(t.length)}return e}function se(e){let t=SyntaxError(e);return t.lineNumber=s,t.columnNumber=c,t}})),bh=ue(((e,t)=>{let n=vh();t.exports=function(e,t,r){let i=[],a=``,o,s,c=``,l;if(typeof t==`object`&&t&&!Array.isArray(t)&&(r=t.space,l=t.quote,t=t.replacer),typeof t==`function`)s=t;else if(Array.isArray(t)){o=[];for(let e of t){let t;typeof e==`string`?t=e:(typeof e==`number`||e instanceof String||e instanceof Number)&&(t=String(e)),t!==void 0&&o.indexOf(t)<0&&o.push(t)}}return r instanceof Number?r=Number(r):r instanceof String&&(r=String(r)),typeof r==`number`?r>0&&(r=Math.min(10,Math.floor(r)),c=` `.substr(0,r)):typeof r==`string`&&(c=r.substr(0,10)),u(``,{"":e});function u(e,t){let n=t[e];switch(n!=null&&(typeof n.toJSON5==`function`?n=n.toJSON5(e):typeof n.toJSON==`function`&&(n=n.toJSON(e))),s&&(n=s.call(t,e,n)),n instanceof Number?n=Number(n):n instanceof String?n=String(n):n instanceof Boolean&&(n=n.valueOf()),n){case null:return`null`;case!0:return`true`;case!1:return`false`}if(typeof n==`string`)return d(n,!1);if(typeof n==`number`)return String(n);if(typeof n==`object`)return Array.isArray(n)?m(n):f(n)}function d(e){let t={"'":.1,'"':.2},r={"'":`\\'`,'"':`\\"`,"\\":`\\\\`,"\b":`\\b`,"\f":`\\f`,"\n":`\\n`,"\r":`\\r`," ":`\\t`,"\v":`\\v`,"\0":`\\0`,"\u2028":`\\u2028`,"\u2029":`\\u2029`},i=``;for(let a=0;a<e.length;a++){let o=e[a];switch(o){case`'`:case`"`:t[o]++,i+=o;continue;case`\0`:if(n.isDigit(e[a+1])){i+=`\\x00`;continue}}if(r[o]){i+=r[o];continue}if(o<` `){let e=o.charCodeAt(0).toString(16);i+=`\\x`+(`00`+e).substring(e.length);continue}i+=o}let a=l||Object.keys(t).reduce((e,n)=>t[e]<t[n]?e:n);return i=i.replace(new RegExp(a,`g`),r[a]),a+i+a}function f(e){if(i.indexOf(e)>=0)throw TypeError(`Converting circular structure to JSON5`);i.push(e);let t=a;a+=c;let n=o||Object.keys(e),r=[];for(let t of n){let n=u(t,e);if(n!==void 0){let e=p(t)+`:`;c!==``&&(e+=` `),e+=n,r.push(e)}}let s;if(r.length===0)s=`{}`;else{let e;if(c===``)e=r.join(`,`),s=`{`+e+`}`;else{let n=`,
|
|
94
94
|
`+a;e=r.join(n),s=`{
|
|
95
95
|
`+a+e+`,
|
|
96
96
|
`+t+`}`}}return i.pop(),a=t,s}function p(e){if(e.length===0)return d(e,!0);let t=String.fromCodePoint(e.codePointAt(0));if(!n.isIdStartChar(t))return d(e,!0);for(let r=t.length;r<e.length;r++)if(!n.isIdContinueChar(String.fromCodePoint(e.codePointAt(r))))return d(e,!0);return e}function m(e){if(i.indexOf(e)>=0)throw TypeError(`Converting circular structure to JSON5`);i.push(e);let t=a;a+=c;let n=[];for(let t=0;t<e.length;t++){let r=u(String(t),e);n.push(r===void 0?`null`:r)}let r;if(n.length===0)r=`[]`;else if(c===``)r=`[`+n.join(`,`)+`]`;else{let e=`,
|
|
97
97
|
`+a,i=n.join(e);r=`[
|
|
98
98
|
`+a+i+`,
|
|
99
|
-
`+t+`]`}return i.pop(),a=t,r}}})),_h=fe(ue(((e,t)=>{t.exports={parse:hh(),stringify:gh()}}))(),1);function vh(e,t,n,r){let i=n[r];return typeof i==`string`?i:(e.issues.push({path:`${t}.${r}`,message:`${t}.${r} must be a string, got ${wh(i)}`,line:X(e.source,[...t.split(`.`),r])}),null)}function yh(e,t,n,r){let i=n.default;if(i!==void 0){if(!(r===`string`&&typeof i==`string`||r===`number`&&typeof i==`number`||r===`boolean`&&typeof i==`boolean`)){e.issues.push({path:`${t}.default`,message:`default must be a ${r}, got ${wh(i)}`,line:X(e.source,[...t.split(`.`),`default`])});return}return i}}function bh(e,t,n,r){let i=n[r];if(i!==void 0){if(typeof i!=`string`){e.issues.push({path:`${t}.${r}`,message:`${t}.${r} must be a string, got ${wh(i)}`,line:X(e.source,[...t.split(`.`),r])});return}return i}}function xh(e,t,n){let r=bh(e,t,n,`palette`);if(r!==void 0){if(!e.allowedPalettes.has(r)){e.issues.push({path:`${t}.palette`,message:`Unknown palette "${r}". Expected one of: ${[...e.allowedPalettes].sort().join(`, `)}`,line:X(e.source,[...t.split(`.`),`palette`])});return}return r}}function Sh(e,t,n,r,i){let a=n[r];if(a!==void 0){if(typeof a!=`string`||!i.includes(a)){e.issues.push({path:`${t}.${r}`,message:`${t}.${r} must be one of: ${i.join(`, `)}; got ${Th(a)}`,line:X(e.source,[...t.split(`.`),r])});return}return a}}function Ch(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function wh(e){return e===null?`null`:Array.isArray(e)?`array`:typeof e}function Th(e){return typeof e==`string`?JSON.stringify(e):e===void 0?`undefined`:String(e)}function Eh(e,t,n,r){return Ch(r)?(Oh(e,n,r,t.noun,new Set(Object.keys(t.fields))),Dh(e,t.fields,n,r)):(e.issues.push({path:n,message:`${n} must be an object, got ${wh(r)}`,line:X(e.source,n.split(`.`))}),null)}function Dh(e,t,n,r){let i=t,a={},o=!0;for(let[t,s]of Object.entries(i)){let i=s.parse(e,n,t,r);i===void 0?s.required&&(o=!1):a[t]=i}return o?a:null}function Oh(e,t,n,r,i){for(let a of Object.keys(n))i.has(a)||e.issues.push({path:`${t}.${a}`,message:`Unknown ${r} "${a}". Expected one of: ${[...i].join(`, `)}`,line:X(e.source,[...t.split(`.`),a])})}function kh(e,t,n,r){if(!Ch(r))return e.issues.push({path:n,message:`${t.noun} must be an object, got ${wh(r)}`,line:X(e.source,n.split(`.`))}),null;let i=t.arms,a=Object.keys(i),o=Object.keys(r).filter(e=>e in i),s=Object.keys(r).filter(e=>!(e in i));for(let r of s)e.issues.push({path:`${n}.${r}`,message:`Unknown ${t.noun} key "${r}". Expected exactly one of: ${a.join(`, `)}`,line:X(e.source,[...n.split(`.`),r])});if(o.length===0)return e.issues.push({path:n,message:`${t.noun} must declare exactly one of: ${a.join(`, `)}`,line:X(e.source,n.split(`.`))}),null;if(o.length>1)return e.issues.push({path:n,message:`${t.noun} must declare exactly one of: ${a.join(`, `)} (found: ${o.join(`, `)})`,line:X(e.source,n.split(`.`))}),null;let c=o[0];return i[c].parse(e,`${n}.${c}`,r[c])}function Ah(e,t,n,r){if(!Ch(r))return e.issues.push({path:n,message:`${n} must be an object, got ${wh(r)}`,line:X(e.source,n.split(`.`))}),null;let i=r[t.tag];if(typeof i!=`string`)return e.issues.push({path:`${n}.${t.tag}`,message:`${n}.${t.tag} must be a string, got ${wh(i)}`,line:X(e.source,n.split(`.`))}),null;let a=t.arms;return i in a?a[i].parse(e,n,r):(e.issues.push({path:`${n}.${t.tag}`,message:`Unknown ${t.noun} "${i}". Expected one of: ${Object.keys(a).join(`, `)}`,line:X(e.source,[...n.split(`.`),t.tag])}),null)}function jh(e){return(...t)=>e()(...t)}function Mh(e,...t){return(n,r,i)=>{let a=e(n,r,i);if(a===null)return null;for(let e of t){if(e.ok(a))continue;let{field:t,message:i}=e.issue(a),o=t===``?r:`${r}.${t}`;return n.issues.push({path:o,message:i,line:X(n.source,o.split(`.`))}),null}return a}}function Z(){return{required:!1,json:{type:`string`},parse:(e,t,n,r)=>bh(e,t,r,n)}}function Nh(){return{required:!1,json:{type:`boolean`},parse:(e,t,n,r)=>{let i=r[n];if(i!==void 0){if(typeof i!=`boolean`){e.issues.push({path:`${t}.${n}`,message:`${n} must be a boolean, got ${wh(i)}`,line:X(e.source,[n])});return}return i}}}}function Ph(e){let{min:t,max:n}=e;return{required:!1,json:{type:`integer`,minimum:t,maximum:n},parse:(e,r,i,a)=>{let o=a[i];if(o!==void 0){if(typeof o!=`number`||!Number.isInteger(o)||o<t||o>n){e.issues.push({path:`${r}.${i}`,message:`${i} must be an integer between ${t} and ${n}, got ${Th(o)}`,line:X(e.source,[i])});return}return o}}}}function Fh(e={}){let{min:t}=e;return{required:!1,json:{type:`number`,...t!==void 0&&{minimum:t}},parse:(e,n,r,i)=>{let a=i[r];if(a!==void 0){if(typeof a!=`number`||!Number.isFinite(a)||t!==void 0&&a<t){let i=t===void 0?`a finite number`:`a finite number >= ${t}`;e.issues.push({path:`${n}.${r}`,message:`${r} must be ${i}, got ${Th(a)}`,line:X(e.source,[r])});return}return a}}}}function Ih(){return{required:!1,json:{type:`string`},parse:(e,t,n,r)=>xh(e,t,r)}}function Lh(){return{required:!0,json:{type:`string`},parse:(e,t,n,r)=>vh(e,t,r,n)??void 0}}function Rh(e){return{required:!1,json:{enum:[...e]},parse:(t,n,r,i)=>Sh(t,n,i,r,e)}}function zh(e,t={closed:!0}){let n=e,r={},i=[];for(let[e,t]of Object.entries(n))r[e]=t.json,t.required&&i.push(e);return{type:`object`,properties:r,...i.length>0&&{required:i},...t.closed&&{additionalProperties:!1}}}function Bh(e){return zh(e.fields)}function Vh(e,t,n){let r=e,i={[t]:{const:n},...r.properties},a=[t,...r.required??[]];return{...r,properties:i,required:a}}function Hh(e){let t=e.arms;return{anyOf:Object.values(t).map(e=>e.json)}}function Uh(e){let t=e.arms;return{anyOf:Object.entries(t).map(([e,t])=>({type:`object`,properties:{[e]:t.json},required:[e],additionalProperties:!1}))}}function Wh(e,t){return{globals:{...t.globals,...e.globals??{}},variables:{...t.variables,...e.variables??{}},segments:{...t.segments,...e.segments??{}},root:e.root===void 0?t.root:e.root,actions:{...t.actions,...e.actions??{}},looks:{...t.looks,...e.looks??{}},presets:{...t.presets,...e.presets??{}},editGlobals:{...t.editGlobals,...e.editGlobals??{}},helpers:{...t.helpers,...e.helpers??{}}}}function Gh(e,t){let n=Object.entries(t);if(n.length===0)return e;let r=Object.assign(Object.create(null),e.segments);for(let[e,t]of n){let n=r[e];n!==void 0&&(r[e]={...n,palette:t})}return{...e,segments:r}}const Kh={required:!1,json:{enum:[...Ac]},parse:(e,t,n,r)=>{if(r[n]===`auto`){e.issues.push({path:`${t}.${n}`,message:`${t}.${n}: "auto" is not supported — the render daemon runs detached, so terminal detection would read the daemon's environment, not your terminal's. Pick an explicit depth: ${Ac.join(`, `)}`,line:X(e.source,[...t.split(`.`),n])});return}return Sh(e,t,r,n,Ac)}},qh={default_bg:Z(),default_fg:Z(),default_empty_value:Z(),default_separator:Z(),default_truncate_marker:Z(),palette:Ih(),look:Z(),preset:Z(),style:Rh(Ec),autoWrap:Nh(),padding:Ph(Pc),charset:Rh(kc),colorCompatibility:Kh},Jh={noun:`globals key`,fields:qh};function Yh(e){return{required:!1,json:{not:{},description:`not allowed here — ${e} cannot select a preset`},parse:(t,n,r,i)=>{i[r]!==void 0&&t.issues.push({path:`${n}.${r}`,message:`${n}.${r}: ${e} cannot select a preset. Which preset is active is resolved once, as session pick over globals.preset over "default"; a fragment naming another would be a second authority over that. Set the default arrangement in the top-level globals.preset instead.`,line:X(t.source,[...n.split(`.`),r])})}}}const Xh={noun:`preset globals key`,fields:{...qh,preset:Yh(`a preset`)}},Zh={noun:`editGlobals key`,fields:{...qh,preset:Yh(`the editGlobals fragment`)}};function Qh(e,t,n){return n===void 0?{}:Eh(e,Jh,t,n)??{}}function $h(e,t,n){return Eh(e,Xh,t,n)??{}}function eg(){return Bh(Xh)}function tg(e,t,n){return Eh(e,Zh,t,n)??{}}const ng=new Set(Object.keys(Jh.fields));function rg(e){return ng.has(e)}function ig(){return[...ng]}const ag={padding:1};function og(e){let t=new Map;for(let[n,r]of Object.entries(ag)){let i=e[n];t.set(n,typeof i==`number`?i:r)}return t}function sg(e,t,n,r){return n.cache===void 0?(uh.includes(r)&&e.issues.push({path:`${t}.cache`,message:`${r} variables must declare a cache policy (one of: ${sh.join(`, `)})`,line:X(e.source,t.split(`.`))}),null):pg(e,`${t}.cache`,n.cache)}function cg(e,t,n){if(n.cache!==void 0)return pg(e,`${t}.cache`,n.cache)??void 0}function lg(e){return{required:!0,json:gg(),parse:(t,n,r,i)=>sg(t,n,i,e)??void 0}}function ug(){return{required:!1,json:gg(),parse:(e,t,n,r)=>cg(e,t,r)}}function dg(e,t,n){return e.issues.push({path:t,message:n,line:X(e.source,t.split(`.`))}),null}const fg={noun:`cache`,arms:{ttl:{json:{type:`string`},parse:(e,t,n)=>typeof n==`string`&&vg(n)?{ttl:n}:dg(e,t,`cache.ttl must be a duration string like "5s", "100ms", "2m", "1h"; got ${Th(n)}`)},watch_file:{json:{type:`string`},parse:(e,t,n)=>typeof n==`string`&&n!==``?{watch_file:n}:dg(e,t,`cache.watch_file must be a non-empty path string, got ${Th(n)}`)},depends_on:{json:{type:`array`,items:{type:`string`}},parse:(e,t,n)=>Array.isArray(n)&&n.every(e=>typeof e==`string`)?{depends_on:n}:dg(e,t,`cache.depends_on must be an array of variable-name strings, got ${Th(n)}`)},key:{json:{type:`string`},parse:(e,t,n)=>typeof n==`string`&&n!==``?{key:n}:dg(e,t,`cache.key must be a non-empty template string, got ${Th(n)}`)},never:{json:{const:!0},parse:(e,t,n)=>n===!0?{never:!0}:dg(e,t,`cache.never must be the literal boolean true, got ${Th(n)}`)}}};function pg(e,t,n){return kh(e,fg,t,n)}const mg={noun:`time-variable cache`,arms:{ttl:fg.arms.ttl}};function hg(){return{required:!1,json:Uh(mg),parse:(e,t,n,r)=>r.cache===void 0?void 0:kh(e,mg,`${t}.cache`,r.cache)??void 0}}function gg(){return Uh(fg)}const _g=/^(\d+(?:\.\d+)?)(ms|s|m|h)$/;function vg(e){return _g.test(e)}function yg(e,t,n){if(n===void 0)return{};if(!Ch(n))return e.issues.push({path:t,message:`${t} must be an object, got ${wh(n)}`,line:X(e.source,t.split(`.`))}),{};let r={};for(let[i,a]of Object.entries(n)){let n=Ah(e,Ng,`${t}.${i}`,a);n!==null&&(r[i]=n)}return r}function bg(){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 ${wh(i)}`,line:X(e.source,t.split(`.`))});return}return i}}}function xg(){return{required:!0,json:{enum:[...lh]},parse:(e,t,n,r)=>{let i=r.field;if(typeof i!=`string`||!lh.includes(i)){e.issues.push({path:`${t}.field`,message:`git field must be one of: ${lh.join(`, `)}, got ${JSON.stringify(i)}`,line:X(e.source,[...t.split(`.`),`field`])});return}return i}}}function Sg(){return{required:!1,json:{type:[`string`,`number`,`boolean`]},parse:(e,t,n,r)=>{let i=r.type;return yh(e,t,r,i===`number`||i===`boolean`||i===`string`?i:`string`)}}}const Cg={value:bg(),default:Z()},wg={path:Lh(),type:Rh([`string`,`number`,`boolean`]),default:Sg()},Tg={name:Lh(),default:Z()},Eg={path:Lh(),readMode:Rh([`whole`,`first-line`]),regex:Z(),cache:lg(`file`),default:Z()},Dg={command:Lh(),regex:Z(),cache:lg(`shell`),default:Z()},Og={template:Lh(),cache:ug(),default:Z()},kg={layout:Lh(),cache:hg(),default:Z()},Ag={field:xg(),cache:lg(`git`),default:Z()},jg={key:Lh(),default:Z()};function Mg(e,t){return{json:Vh(zh(t),`kind`,e),parse:(n,r,i)=>{let a=Dh(n,t,r,i);return a===null?null:{kind:e,...a}}}}const Ng={tag:`kind`,noun:`source kind`,arms:{literal:Mg(`literal`,Cg),input:Mg(`input`,wg),env:Mg(`env`,Tg),file:Mg(`file`,Eg),shell:Mg(`shell`,Dg),template:Mg(`template`,Og),time:Mg(`time`,kg),git:Mg(`git`,Ag),state:Mg(`state`,jg)}};function Pg(){return Hh(Ng)}function Fg(){return{type:`object`,additionalProperties:Pg()}}function Ig(e,t){if(t===void 0)return{};if(!Ch(t))return e.issues.push({path:`segments`,message:`segments must be an object, got ${wh(t)}`,line:X(e.source,[`segments`])}),{};let n={};for(let[r,i]of Object.entries(t)){let t=Eh(e,zg,`segments.${r}`,i);t!==null&&(n[r]=t)}return n}function Lg(){return{required:!1,json:{anyOf:[{const:`auto`},{type:`integer`,minimum:1}]},parse:(e,t,n,r)=>{let i=r[n];if(i!==void 0){if(i===`auto`)return`auto`;if(typeof i==`number`&&Number.isInteger(i)&&i>0)return i;e.issues.push({path:`${t}.${n}`,message:`width must be "auto" or a positive integer, got ${Th(i)}`,line:X(e.source,[...t.split(`.`),n])})}}}}function Rg(){return{required:!1,json:Fg(),parse:(e,t,n,r)=>{let i=r[n];if(i!==void 0)return yg(e,`${t}.${n}`,i)}}}const zg={noun:`segment key`,fields:{template:Lh(),width:Lg(),justify:Rh(dh),truncate:Rh(fh),bg:Z(),fg:Z(),when:Z(),palette:Ih(),vars:Rg()}},Bg=`#/definitions/LayoutNode`,Vg={kind:`container`,direction:`vertical`,children:[]};function Hg(e){return{required:!0,json:{const:e},parse:()=>e}}function Ug(){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 ${Th(i)}`,line:X(e.source,[`root`])}),``)}}}function Wg(){return{required:!0,json:{enum:[...ah]},parse:(e,t,n,r)=>{let i=r[n];return typeof i==`string`&&ah.includes(i)?i:(e.issues.push({path:`${t}.${n}`,message:`a container "direction" must be one of: ${ah.join(`, `)} (got ${JSON.stringify(i)})`,line:X(e.source,[`root`])}),`vertical`)}}}function Gg(e){return{required:!0,json:{type:`array`,items:{$ref:Bg}},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 ${wh(a)}`,line:X(t.source,[`root`])}),[])}}}const Kg={noun:`layout-node key`,fields:{kind:Hg(`segment`),name:Ug(),when:Z()}},qg={noun:`layout-node key`,fields:{kind:Hg(`container`),direction:Wg(),children:Gg(jh(()=>Qg)),when:Z()}};function Jg(){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 ${Th(i)}`,line:X(e.source,[`root`])}),``)}}}const Yg={noun:`layout-node key`,fields:{seg:Jg(),when:Z()}},Xg={noun:`layout-node key`,fields:{h:Gg(jh(()=>Qg)),when:Z()}},Zg={noun:`layout-node key`,fields:{v:Gg(jh(()=>Qg)),when:Z()}},Qg=(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:X(e.source,[`root`])}),Vg):{kind:`segment`,name:n};if(!Ch(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 ${wh(n)}`,line:X(e.source,[`root`])}),Vg;if(n.kind===`container`)return Eh(e,qg,t,n)??Vg;if(n.kind===`segment`)return Eh(e,Kg,t,n)??Vg;if(n.kind===`cells`)return e.issues.push({path:t,message:`kind: "cells" is no longer supported — use the h-arm spelling instead:
|
|
99
|
+
`+t+`]`}return i.pop(),a=t,r}}})),xh=fe(ue(((e,t)=>{t.exports={parse:yh(),stringify:bh()}}))(),1);function Sh(e,t,n,r){let i=n[r];return typeof i==`string`?i:(e.issues.push({path:`${t}.${r}`,message:`${t}.${r} must be a string, got ${Oh(i)}`,line:X(e.source,[...t.split(`.`),r])}),null)}function Ch(e,t,n,r){let i=n.default;if(i!==void 0){if(!(r===`string`&&typeof i==`string`||r===`number`&&typeof i==`number`||r===`boolean`&&typeof i==`boolean`)){e.issues.push({path:`${t}.default`,message:`default must be a ${r}, got ${Oh(i)}`,line:X(e.source,[...t.split(`.`),`default`])});return}return i}}function wh(e,t,n,r){let i=n[r];if(i!==void 0){if(typeof i!=`string`){e.issues.push({path:`${t}.${r}`,message:`${t}.${r} must be a string, got ${Oh(i)}`,line:X(e.source,[...t.split(`.`),r])});return}return i}}function Th(e,t,n){let r=wh(e,t,n,`palette`);if(r!==void 0){if(!e.allowedPalettes.has(r)){e.issues.push({path:`${t}.palette`,message:`Unknown palette "${r}". Expected one of: ${[...e.allowedPalettes].sort().join(`, `)}`,line:X(e.source,[...t.split(`.`),`palette`])});return}return r}}function Eh(e,t,n,r,i){let a=n[r];if(a!==void 0){if(typeof a!=`string`||!i.includes(a)){e.issues.push({path:`${t}.${r}`,message:`${t}.${r} must be one of: ${i.join(`, `)}; got ${kh(a)}`,line:X(e.source,[...t.split(`.`),r])});return}return a}}function Dh(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Oh(e){return e===null?`null`:Array.isArray(e)?`array`:typeof e}function kh(e){return typeof e==`string`?JSON.stringify(e):e===void 0?`undefined`:String(e)}function Ah(e,t,n,r){return Dh(r)?(Mh(e,n,r,t.noun,new Set(Object.keys(t.fields))),jh(e,t.fields,n,r)):(e.issues.push({path:n,message:`${n} must be an object, got ${Oh(r)}`,line:X(e.source,n.split(`.`))}),null)}function jh(e,t,n,r){let i=t,a={},o=!0;for(let[t,s]of Object.entries(i)){let i=s.parse(e,n,t,r);i===void 0?s.required&&(o=!1):a[t]=i}return o?a:null}function Mh(e,t,n,r,i){for(let a of Object.keys(n))i.has(a)||e.issues.push({path:`${t}.${a}`,message:`Unknown ${r} "${a}". Expected one of: ${[...i].join(`, `)}`,line:X(e.source,[...t.split(`.`),a])})}function Nh(e,t,n,r){if(!Dh(r))return e.issues.push({path:n,message:`${t.noun} must be an object, got ${Oh(r)}`,line:X(e.source,n.split(`.`))}),null;let i=t.arms,a=Object.keys(i),o=Object.keys(r).filter(e=>e in i),s=Object.keys(r).filter(e=>!(e in i));for(let r of s)e.issues.push({path:`${n}.${r}`,message:`Unknown ${t.noun} key "${r}". Expected exactly one of: ${a.join(`, `)}`,line:X(e.source,[...n.split(`.`),r])});if(o.length===0)return e.issues.push({path:n,message:`${t.noun} must declare exactly one of: ${a.join(`, `)}`,line:X(e.source,n.split(`.`))}),null;if(o.length>1)return e.issues.push({path:n,message:`${t.noun} must declare exactly one of: ${a.join(`, `)} (found: ${o.join(`, `)})`,line:X(e.source,n.split(`.`))}),null;let c=o[0];return i[c].parse(e,`${n}.${c}`,r[c])}function Ph(e,t,n,r){if(!Dh(r))return e.issues.push({path:n,message:`${n} must be an object, got ${Oh(r)}`,line:X(e.source,n.split(`.`))}),null;let i=r[t.tag];if(typeof i!=`string`)return e.issues.push({path:`${n}.${t.tag}`,message:`${n}.${t.tag} must be a string, got ${Oh(i)}`,line:X(e.source,n.split(`.`))}),null;let a=t.arms;return i in a?a[i].parse(e,n,r):(e.issues.push({path:`${n}.${t.tag}`,message:`Unknown ${t.noun} "${i}". Expected one of: ${Object.keys(a).join(`, `)}`,line:X(e.source,[...n.split(`.`),t.tag])}),null)}function Fh(e){return(...t)=>e()(...t)}function Ih(e,...t){return(n,r,i)=>{let a=e(n,r,i);if(a===null)return null;for(let e of t){if(e.ok(a))continue;let{field:t,message:i}=e.issue(a),o=t===``?r:`${r}.${t}`;return n.issues.push({path:o,message:i,line:X(n.source,o.split(`.`))}),null}return a}}function Z(){return{required:!1,json:{type:`string`},parse:(e,t,n,r)=>wh(e,t,r,n)}}function Lh(){return{required:!1,json:{type:`boolean`},parse:(e,t,n,r)=>{let i=r[n];if(i!==void 0){if(typeof i!=`boolean`){e.issues.push({path:`${t}.${n}`,message:`${n} must be a boolean, got ${Oh(i)}`,line:X(e.source,[n])});return}return i}}}}function Rh(e){let{min:t,max:n}=e;return{required:!1,json:{type:`integer`,minimum:t,maximum:n},parse:(e,r,i,a)=>{let o=a[i];if(o!==void 0){if(typeof o!=`number`||!Number.isInteger(o)||o<t||o>n){e.issues.push({path:`${r}.${i}`,message:`${i} must be an integer between ${t} and ${n}, got ${kh(o)}`,line:X(e.source,[i])});return}return o}}}}function zh(e={}){let{min:t}=e;return{required:!1,json:{type:`number`,...t!==void 0&&{minimum:t}},parse:(e,n,r,i)=>{let a=i[r];if(a!==void 0){if(typeof a!=`number`||!Number.isFinite(a)||t!==void 0&&a<t){let i=t===void 0?`a finite number`:`a finite number >= ${t}`;e.issues.push({path:`${n}.${r}`,message:`${r} must be ${i}, got ${kh(a)}`,line:X(e.source,[r])});return}return a}}}}function Bh(){return{required:!1,json:{type:`string`},parse:(e,t,n,r)=>Th(e,t,r)}}function Vh(){return{required:!0,json:{type:`string`},parse:(e,t,n,r)=>Sh(e,t,r,n)??void 0}}function Hh(e){return{required:!1,json:{enum:[...e]},parse:(t,n,r,i)=>Eh(t,n,i,r,e)}}function Uh(e,t={closed:!0}){let n=e,r={},i=[];for(let[e,t]of Object.entries(n))r[e]=t.json,t.required&&i.push(e);return{type:`object`,properties:r,...i.length>0&&{required:i},...t.closed&&{additionalProperties:!1}}}function Wh(e){return Uh(e.fields)}function Gh(e,t,n){let r=e,i={[t]:{const:n},...r.properties},a=[t,...r.required??[]];return{...r,properties:i,required:a}}function Kh(e){let t=e.arms;return{anyOf:Object.values(t).map(e=>e.json)}}function qh(e){let t=e.arms;return{anyOf:Object.entries(t).map(([e,t])=>({type:`object`,properties:{[e]:t.json},required:[e],additionalProperties:!1}))}}function Jh(e,t){return{globals:{...t.globals,...e.globals??{}},variables:{...t.variables,...e.variables??{}},segments:{...t.segments,...e.segments??{}},root:e.root===void 0?t.root:e.root,actions:{...t.actions,...e.actions??{}},looks:{...t.looks,...e.looks??{}},presets:{...t.presets,...e.presets??{}},editGlobals:{...t.editGlobals,...e.editGlobals??{}},helpers:{...t.helpers,...e.helpers??{}}}}function Yh(e,t){let n=Object.entries(t);if(n.length===0)return e;let r=Object.assign(Object.create(null),e.segments);for(let[e,t]of n){let n=r[e];n!==void 0&&(r[e]={...n,palette:t})}return{...e,segments:r}}const Xh={required:!1,json:{enum:[...Ac]},parse:(e,t,n,r)=>{if(r[n]===`auto`){e.issues.push({path:`${t}.${n}`,message:`${t}.${n}: "auto" is not supported — the render daemon runs detached, so terminal detection would read the daemon's environment, not your terminal's. Pick an explicit depth: ${Ac.join(`, `)}`,line:X(e.source,[...t.split(`.`),n])});return}return Eh(e,t,r,n,Ac)}},Zh={default_bg:Z(),default_fg:Z(),default_empty_value:Z(),default_separator:Z(),default_truncate_marker:Z(),palette:Bh(),look:Z(),preset:Z(),style:Hh(Ec),autoWrap:Lh(),padding:Rh(Pc),charset:Hh(kc),colorCompatibility:Xh},Qh={noun:`globals key`,fields:Zh};function $h(e){return{required:!1,json:{not:{},description:`not allowed here — ${e} cannot select a preset`},parse:(t,n,r,i)=>{i[r]!==void 0&&t.issues.push({path:`${n}.${r}`,message:`${n}.${r}: ${e} cannot select a preset. Which preset is active is resolved once, as session pick over globals.preset over "default"; a fragment naming another would be a second authority over that. Set the default arrangement in the top-level globals.preset instead.`,line:X(t.source,[...n.split(`.`),r])})}}}const eg={noun:`preset globals key`,fields:{...Zh,preset:$h(`a preset`)}},tg={noun:`editGlobals key`,fields:{...Zh,preset:$h(`the editGlobals fragment`)}};function ng(e,t,n){return n===void 0?{}:Ah(e,Qh,t,n)??{}}function rg(e,t,n){return Ah(e,eg,t,n)??{}}function ig(){return Wh(eg)}function ag(e,t,n){return Ah(e,tg,t,n)??{}}const og=new Set(Object.keys(Qh.fields));function sg(e){return og.has(e)}function cg(){return[...og]}const lg={padding:1};function ug(e){let t=new Map;for(let[n,r]of Object.entries(lg)){let i=e[n];t.set(n,typeof i==`number`?i:r)}return t}function dg(e,t,n,r){return n.cache===void 0?(mh.includes(r)&&e.issues.push({path:`${t}.cache`,message:`${r} variables must declare a cache policy (one of: ${dh.join(`, `)})`,line:X(e.source,t.split(`.`))}),null):_g(e,`${t}.cache`,n.cache)}function fg(e,t,n){if(n.cache!==void 0)return _g(e,`${t}.cache`,n.cache)??void 0}function pg(e){return{required:!0,json:bg(),parse:(t,n,r,i)=>dg(t,n,i,e)??void 0}}function mg(){return{required:!1,json:bg(),parse:(e,t,n,r)=>fg(e,t,r)}}function hg(e,t,n){return e.issues.push({path:t,message:n,line:X(e.source,t.split(`.`))}),null}const gg={noun:`cache`,arms:{ttl:{json:{type:`string`},parse:(e,t,n)=>typeof n==`string`&&Sg(n)?{ttl:n}:hg(e,t,`cache.ttl must be a duration string like "5s", "100ms", "2m", "1h"; got ${kh(n)}`)},watch_file:{json:{type:`string`},parse:(e,t,n)=>typeof n==`string`&&n!==``?{watch_file:n}:hg(e,t,`cache.watch_file must be a non-empty path string, got ${kh(n)}`)},depends_on:{json:{type:`array`,items:{type:`string`}},parse:(e,t,n)=>Array.isArray(n)&&n.every(e=>typeof e==`string`)?{depends_on:n}:hg(e,t,`cache.depends_on must be an array of variable-name strings, got ${kh(n)}`)},key:{json:{type:`string`},parse:(e,t,n)=>typeof n==`string`&&n!==``?{key:n}:hg(e,t,`cache.key must be a non-empty template string, got ${kh(n)}`)},never:{json:{const:!0},parse:(e,t,n)=>n===!0?{never:!0}:hg(e,t,`cache.never must be the literal boolean true, got ${kh(n)}`)}}};function _g(e,t,n){return Nh(e,gg,t,n)}const vg={noun:`time-variable cache`,arms:{ttl:gg.arms.ttl}};function yg(){return{required:!1,json:qh(vg),parse:(e,t,n,r)=>r.cache===void 0?void 0:Nh(e,vg,`${t}.cache`,r.cache)??void 0}}function bg(){return qh(gg)}const xg=/^(\d+(?:\.\d+)?)(ms|s|m|h)$/;function Sg(e){return xg.test(e)}function Cg(e,t,n){if(n===void 0)return{};if(!Dh(n))return e.issues.push({path:t,message:`${t} must be an object, got ${Oh(n)}`,line:X(e.source,t.split(`.`))}),{};let r={};for(let[i,a]of Object.entries(n)){let n=Ph(e,Lg,`${t}.${i}`,a);n!==null&&(r[i]=n)}return r}function wg(){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 ${Oh(i)}`,line:X(e.source,t.split(`.`))});return}return i}}}function Tg(){return{required:!0,json:{enum:[...ph]},parse:(e,t,n,r)=>{let i=r.field;if(typeof i!=`string`||!ph.includes(i)){e.issues.push({path:`${t}.field`,message:`git field must be one of: ${ph.join(`, `)}, got ${JSON.stringify(i)}`,line:X(e.source,[...t.split(`.`),`field`])});return}return i}}}function Eg(){return{required:!1,json:{type:[`string`,`number`,`boolean`]},parse:(e,t,n,r)=>{let i=r.type;return Ch(e,t,r,i===`number`||i===`boolean`||i===`string`?i:`string`)}}}const Dg={value:wg(),default:Z()},Og={path:Vh(),type:Hh([`string`,`number`,`boolean`]),default:Eg()},kg={name:Vh(),default:Z()},Ag={path:Vh(),readMode:Hh([`whole`,`first-line`]),regex:Z(),cache:pg(`file`),default:Z()},jg={command:Vh(),regex:Z(),cache:pg(`shell`),default:Z()},Mg={template:Vh(),cache:mg(),default:Z()},Ng={layout:Vh(),cache:yg(),default:Z()},Pg={field:Tg(),cache:pg(`git`),default:Z()},Fg={key:Vh(),default:Z()};function Ig(e,t){return{json:Gh(Uh(t),`kind`,e),parse:(n,r,i)=>{let a=jh(n,t,r,i);return a===null?null:{kind:e,...a}}}}const Lg={tag:`kind`,noun:`source kind`,arms:{literal:Ig(`literal`,Dg),input:Ig(`input`,Og),env:Ig(`env`,kg),file:Ig(`file`,Ag),shell:Ig(`shell`,jg),template:Ig(`template`,Mg),time:Ig(`time`,Ng),git:Ig(`git`,Pg),state:Ig(`state`,Fg)}};function Rg(){return Kh(Lg)}function zg(){return{type:`object`,additionalProperties:Rg()}}function Bg(e,t){if(t===void 0)return{};if(!Dh(t))return e.issues.push({path:`segments`,message:`segments must be an object, got ${Oh(t)}`,line:X(e.source,[`segments`])}),{};let n={};for(let[r,i]of Object.entries(t)){let t=Ah(e,Ug,`segments.${r}`,i);t!==null&&(n[r]=t)}return n}function Vg(){return{required:!1,json:{anyOf:[{const:`auto`},{type:`integer`,minimum:1}]},parse:(e,t,n,r)=>{let i=r[n];if(i!==void 0){if(i===`auto`)return`auto`;if(typeof i==`number`&&Number.isInteger(i)&&i>0)return i;e.issues.push({path:`${t}.${n}`,message:`width must be "auto" or a positive integer, got ${kh(i)}`,line:X(e.source,[...t.split(`.`),n])})}}}}function Hg(){return{required:!1,json:zg(),parse:(e,t,n,r)=>{let i=r[n];if(i!==void 0)return Cg(e,`${t}.${n}`,i)}}}const Ug={noun:`segment key`,fields:{template:Vh(),width:Vg(),justify:Hh(hh),truncate:Hh(gh),bg:Z(),fg:Z(),when:Z(),palette:Bh(),vars:Hg()}},Wg=`#/definitions/LayoutNode`,Gg={kind:`container`,direction:`vertical`,children:[]};function Kg(e){return{required:!0,json:{const:e},parse:()=>e}}function qg(){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 ${kh(i)}`,line:X(e.source,[`root`])}),``)}}}function Jg(){return{required:!0,json:{enum:[...lh]},parse:(e,t,n,r)=>{let i=r[n];return typeof i==`string`&&lh.includes(i)?i:(e.issues.push({path:`${t}.${n}`,message:`a container "direction" must be one of: ${lh.join(`, `)} (got ${JSON.stringify(i)})`,line:X(e.source,[`root`])}),`vertical`)}}}function Yg(e){return{required:!0,json:{type:`array`,items:{$ref:Wg}},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 ${Oh(a)}`,line:X(t.source,[`root`])}),[])}}}const Xg={noun:`layout-node key`,fields:{kind:Kg(`segment`),name:qg(),when:Z()}},Zg={noun:`layout-node key`,fields:{kind:Kg(`container`),direction:Jg(),children:Yg(Fh(()=>n_)),when:Z()}};function Qg(){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 ${kh(i)}`,line:X(e.source,[`root`])}),``)}}}const $g={noun:`layout-node key`,fields:{seg:Qg(),when:Z()}},e_={noun:`layout-node key`,fields:{h:Yg(Fh(()=>n_)),when:Z()}},t_={noun:`layout-node key`,fields:{v:Yg(Fh(()=>n_)),when:Z()}},n_=(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:X(e.source,[`root`])}),Gg):{kind:`segment`,name:n};if(!Dh(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 ${Oh(n)}`,line:X(e.source,[`root`])}),Gg;if(n.kind===`container`)return Ah(e,Zg,t,n)??Gg;if(n.kind===`segment`)return Ah(e,Xg,t,n)??Gg;if(n.kind===`cells`)return e.issues.push({path:t,message:`kind: "cells" is no longer supported — use the h-arm spelling instead:
|
|
100
100
|
Old: { kind: "cells", segments: ["seg1", "seg2"] }
|
|
101
|
-
New: { h: ["seg1", "seg2"] }`,line:X(e.source,[`root`])}),Vg;if(n.kind===`group`){let r=Eh(e,i_,t,n);return r===null?Vg:(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}),o_(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:X(e.source,[`root`])}),Vg}if(a){let r=Eh(e,Yg,t,n);return r===null?Vg:{kind:`segment`,name:r.seg,...r.when!==void 0&&{when:r.when}}}if(r){let r=Eh(e,Xg,t,n);return r===null?Vg:{kind:`container`,direction:`horizontal`,children:r.h,...r.when!==void 0&&{when:r.when}}}if(i){let r=Eh(e,Zg,t,n);return r===null?Vg:{kind:`container`,direction:`vertical`,children:r.v,...r.when!==void 0&&{when:r.when}}}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:X(e.source,[`root`])}),Vg},$g=`groups.`,e_=/^[A-Za-z_][A-Za-z0-9_]*$/;function t_(){return{required:!0,json:{type:`string`,pattern:e_.source},parse:(e,t,n,r)=>{let i=r[n];if(typeof i!=`string`||!e_.test(i)||i===`closed`){e.issues.push({path:`${t}.${n}`,message:`a group "name" must be an identifier (letters, digits, _; not starting with a digit) and not the reserved "${Xt}", got ${Th(i)}`,line:X(e.source,[`root`])});return}return i}}}function n_(){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 ${Th(i)}`,line:X(e.source,[`root`])});return}return i}}}}function r_(){return{required:!0,json:{type:`string`,pattern:`^[^\\n\\r]*$`},parse:(e,t,n,r)=>{let i=vh(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:X(e.source,[...t.split(`.`),n])});return}return i}}}}const i_={noun:`layout-node key`,fields:{kind:Hg(`group`),name:t_(),label:r_(),open:Nh(),direction:Rh(ah),key:n_(),bg:Z(),fg:Z(),when:Z(),children:Gg(jh(()=>Qg))}};function a_(e){return e.key??`groups.`+e.name}function o_(e){let t=$g+e.name;return{kind:`container`,direction:`vertical`,children:[{kind:`segment`,name:t},{kind:`container`,direction:e.direction??`vertical`,children:e.children,when:en({variable:t,member:e.name})}],...e.when!==void 0&&{when:e.when}}}function s_(e,t,n){e.issues.push({path:t,message:n,line:X(e.source,[`root`])})}function c_(e,t){Wm(e,t,$g,`group nodes`);let n=e.groups;if(n.length===0)return;let r=new Set;for(let t of n)r.has(t.name)&&s_(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}.`)&&a_(t)===a_(r)&&s_(e,t.path,`group "${t.name}" shares key "${a_(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=a_(t);if(i.has(n)||i.set(n,Xt),t.open===!0){let r=i.get(n);r!==`closed`&&s_(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=$g+e.name,r=a_(e),c=n.filter(t=>t!==e&&e.path.startsWith(t.path+`.`)).length,l=` `.repeat(c);a[t]=P(r,i.get(r)),o[t]=nn(r,e.name),s[t]={template:tn(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}}function l_(e){return e.replace(/[^A-Za-z0-9]+/g,`_`)}const u_=`menus.`;function d_(e){return e}function f_(e,t,n){return n===void 0?u_+l_(e)+`.`+l_(t):u_+l_(n)}function p_(e,t){return e+`.`+t}function m_(e){return e+`.page`}function h_(e){for(let t of Object.keys(e))if(t!==`closeOnPick`&&t!==`paged`&&t!==`key`)throw Error(`unknown {{ menu }} option "${t}" — the options dict takes "closeOnPick" (bool, default false), "paged" (bool, default true), "key" (string, accordion grouping)`);let t=(t,n)=>{let r=e[t];if(r===void 0)return n;if(typeof r!=`boolean`)throw Error(`{{ menu }} option "${t}" must be a boolean, got ${JSON.stringify(r)} (e.g. (dict "${t}" ${String(!n)}))`);return r},n=e.key;if(n!==void 0&&typeof n!=`string`)throw Error(`{{ menu }} option "key" must be a string naming the accordion group, got ${JSON.stringify(n)}`);if(n===``)throw Error(`{{ menu }} has an empty accordion key — a shared key must be a non-empty name (or omit "key" for an independent menu)`);return{closeOnPick:t(`closeOnPick`,!1),paged:t(`paged`,!0),key:n}}const g_=`menu`,__=`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`,v_=e=>e.kind===`call`&&e.name===`dict`,y_=e=>e.kind===`literal`&&typeof e.value!=`object`,b_=e=>Zt(``,e,2)===void 0;function x_(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&&v_(i)?i:void 0,o=a===void 0?r:r.slice(0,-1);if(o.some(v_))return t(`whose options (dict …) is not its last argument — ${__}`);if(i!==void 0&&a===void 0&&!y_(i)&&b_(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=Zt(`whose trigger`,o.length,2);if(s!==void 0)return t(`${s} — ${__}`);let c=a===void 0?{}:jf(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)`);try{return{kind:`ok`,apply:n.value,options:h_(c)}}catch(e){return t(`with invalid options — ${e.message}`)}}function S_(e){let t=Ru({fromString:e=>e});try{return t.parse(e).referencedCalls().filter(e=>e.name===g_).map(x_)}catch{return`parse-failed`}}function C_(e){let t=Ru({fromString:e=>e});try{return t.parse(e).referencedFunctions().has(g_)}catch{return!1}}function w_(e,t,n){e.issues.push({path:t,message:n,line:X(e.source,[`root`])})}function T_(e,t){Wm(e,t,u_,`{{ menu }} helpers`);for(let[n,r]of Object.entries(t.helpers??{}))C_(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:X(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`&&C_(i)&&w_(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.`)}let r=new Map;if(t.root!==void 0)for(let n of oh(t.root))typeof n.when==`string`&&C_(n.when)&&w_(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.`),n.kind===`segment`&&r.set(n.name,(r.get(n.name)??0)+1);for(let[t,i]of Object.entries(n))C_(i.template)&&(r.get(t)??0)>1&&w_(e,`segments.${t}`,`segment "${t}" hosts a {{ menu }} and is placed in the layout more than once — a menu's open-state is keyed by segment name, so the copies would share one state (clicking one would toggle both). Give each placement its own named segment.`);let i=new Set,a={},o=new Set,s=new Map;for(let[t,r]of Object.entries(n)){if(!C_(r.template))continue;let n=S_(r.template);if(n!==`parse-failed`)for(let r of n){if(r.kind===`issue`){w_(e,`segments.${t}`,`segment "${t}" has a {{ menu }} ${r.message}.`);continue}let{apply:n,options:c}=r;if(n===``){w_(e,`segments.${t}`,`segment "${t}" has a {{ menu }} 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.`);continue}let l=d_(n);if(l===`closed`){w_(e,`segments.${t}`,`segment "${t}" has a {{ menu }} whose apply action is named "${Xt}", which collides with the menu's closed-state sentinel and leaves it unopenable. Rename the action.`);continue}let u=f_(t,n,c.key),d=m_(u),f=c.key===void 0?`ind${t}${n}`:`key${c.key}`,p=[u,d].find(e=>{let t=s.get(e);return t!==void 0&&t!==f});if(p!==void 0){w_(e,`segments.${t}`,`two {{ menu }} disclosures normalize to the same state key ("${p}") 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}s.set(u,f),s.set(d,f);let m=p_(u,l);if(o.has(m)){w_(e,`segments.${t}`,`two {{ menu }} disclosures resolve to the same identity ("${m}") — ${c.key===void 0?`a segment cannot contain two menus over the same apply action "${n}"`:`menus sharing key "${c.key}" must have distinct apply actions`}.`);continue}o.add(m),i.add(u),a[m]=nn(u,l)}}if(i.size===0)return;let c={};for(let e of i){c[e]=P(e,Xt);let t=m_(e);c[t]={kind:`state`,key:t,default:`0`},a[t]={set:t,int:!0}}t.variables={...t.variables??{},...c},t.actions={...t.actions??{},...a}}const E_=/^segments\.([^.]+)\.palette$/,D_=/^presets\.(.+)\.rootOps$/;function O_(e){return`presets.${e}.rootOps`}function k_(e){if(rg(e))return{scope:`globals`,field:e};let t=E_.exec(e);if(t)return{scope:`segment-palette`,segment:t[1]};let n=D_.exec(e);return n?{scope:`preset-root-ops`,preset:n[1]}:null}const A_=`open`;function j_(e,t,n,r,i){let a={variable:e,member:A_};r.variables[e]=P(e,Xt),r.actions[e]=nn(e,A_),r.segments[e]={template:tn(e,`(?)`,`✕`),...i,...M_(n)};let o=en(a,...n),s=t.map((t,n)=>{let a=`${e}.${n}`;return r.segments[a]={template:t,...i},{kind:`segment`,name:a}});return{trigger:{kind:`segment`,name:e},body:{kind:`container`,direction:`horizontal`,children:s,when:o}}}function M_(e){let[t,...n]=e;return t===void 0?{}:{when:en(t,...n)}}const N_=[`+ inserts here`,`- removes the one left of it`,`↺ undoes edits`],P_=[`☐ this session only`,`☑ default for every session`],F_=`
|
|
101
|
+
New: { h: ["seg1", "seg2"] }`,line:X(e.source,[`root`])}),Gg;if(n.kind===`group`){let r=Ah(e,c_,t,n);return r===null?Gg:(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}),u_(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:X(e.source,[`root`])}),Gg}if(a){let r=Ah(e,$g,t,n);return r===null?Gg:{kind:`segment`,name:r.seg,...r.when!==void 0&&{when:r.when}}}if(r){let r=Ah(e,e_,t,n);return r===null?Gg:{kind:`container`,direction:`horizontal`,children:r.h,...r.when!==void 0&&{when:r.when}}}if(i){let r=Ah(e,t_,t,n);return r===null?Gg:{kind:`container`,direction:`vertical`,children:r.v,...r.when!==void 0&&{when:r.when}}}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:X(e.source,[`root`])}),Gg},r_=`groups.`,i_=/^[A-Za-z_][A-Za-z0-9_]*$/;function a_(){return{required:!0,json:{type:`string`,pattern:i_.source},parse:(e,t,n,r)=>{let i=r[n];if(typeof i!=`string`||!i_.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 "${Xt}", got ${kh(i)}`,line:X(e.source,[`root`])});return}return i}}}function o_(){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 ${kh(i)}`,line:X(e.source,[`root`])});return}return i}}}}function s_(){return{required:!0,json:{type:`string`,pattern:`^[^\\n\\r]*$`},parse:(e,t,n,r)=>{let i=Sh(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:X(e.source,[...t.split(`.`),n])});return}return i}}}}const c_={noun:`layout-node key`,fields:{kind:Kg(`group`),name:a_(),label:s_(),open:Lh(),direction:Hh(lh),key:o_(),bg:Z(),fg:Z(),when:Z(),children:Yg(Fh(()=>n_))}};function l_(e){return e.key??`groups.`+e.name}function u_(e){let t=r_+e.name;return{kind:`container`,direction:`vertical`,children:[{kind:`segment`,name:t},{kind:`container`,direction:e.direction??`vertical`,children:e.children,when:en({variable:t,member:e.name})}],...e.when!==void 0&&{when:e.when}}}function d_(e,t,n){e.issues.push({path:t,message:n,line:X(e.source,[`root`])})}function f_(e,t){Jm(e,t,r_,`group nodes`);let n=e.groups;if(n.length===0)return;let r=new Set;for(let t of n)r.has(t.name)&&d_(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}.`)&&l_(t)===l_(r)&&d_(e,t.path,`group "${t.name}" shares key "${l_(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=l_(t);if(i.has(n)||i.set(n,Xt),t.open===!0){let r=i.get(n);r!==`closed`&&d_(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=r_+e.name,r=l_(e),c=n.filter(t=>t!==e&&e.path.startsWith(t.path+`.`)).length,l=` `.repeat(c);a[t]=P(r,i.get(r)),o[t]=nn(r,e.name),s[t]={template:tn(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}}function p_(e){return e.replace(/[^A-Za-z0-9]+/g,`_`)}const m_=`menus.`;function h_(e){return e}function g_(e,t,n){return n===void 0?m_+p_(e)+`.`+p_(t):m_+p_(n)}function __(e,t){return e+`.`+t}function v_(e){return e+`.page`}function y_(e){for(let t of Object.keys(e))if(t!==`closeOnPick`&&t!==`paged`&&t!==`key`)throw Error(`unknown {{ menu }} option "${t}" — the options dict takes "closeOnPick" (bool, default false), "paged" (bool, default true), "key" (string, accordion grouping)`);let t=(t,n)=>{let r=e[t];if(r===void 0)return n;if(typeof r!=`boolean`)throw Error(`{{ menu }} option "${t}" must be a boolean, got ${JSON.stringify(r)} (e.g. (dict "${t}" ${String(!n)}))`);return r},n=e.key;if(n!==void 0&&typeof n!=`string`)throw Error(`{{ menu }} option "key" must be a string naming the accordion group, got ${JSON.stringify(n)}`);if(n===``)throw Error(`{{ menu }} has an empty accordion key — a shared key must be a non-empty name (or omit "key" for an independent menu)`);return{closeOnPick:t(`closeOnPick`,!1),paged:t(`paged`,!0),key:n}}const b_=`menu`,x_=`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`,S_=e=>e.kind===`call`&&e.name===`dict`,C_=e=>e.kind===`literal`&&typeof e.value!=`object`,w_=e=>Zt(``,e,2)===void 0;function T_(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&&S_(i)?i:void 0,o=a===void 0?r:r.slice(0,-1);if(o.some(S_))return t(`whose options (dict …) is not its last argument — ${x_}`);if(i!==void 0&&a===void 0&&!C_(i)&&w_(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=Zt(`whose trigger`,o.length,2);if(s!==void 0)return t(`${s} — ${x_}`);let c=a===void 0?{}:Ff(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)`);try{return{kind:`ok`,apply:n.value,options:y_(c)}}catch(e){return t(`with invalid options — ${e.message}`)}}function E_(e){let t=Hu({fromString:e=>e});try{return t.parse(e).referencedCalls().filter(e=>e.name===b_).map(T_)}catch{return`parse-failed`}}function D_(e){let t=Hu({fromString:e=>e});try{return t.parse(e).referencedFunctions().has(b_)}catch{return!1}}function O_(e,t,n){e.issues.push({path:t,message:n,line:X(e.source,[`root`])})}function k_(e,t){Jm(e,t,m_,`{{ menu }} helpers`);for(let[n,r]of Object.entries(t.helpers??{}))D_(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:X(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`&&D_(i)&&O_(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.`)}let r=new Map;if(t.root!==void 0)for(let n of uh(t.root))typeof n.when==`string`&&D_(n.when)&&O_(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.`),n.kind===`segment`&&r.set(n.name,(r.get(n.name)??0)+1);for(let[t,i]of Object.entries(n))D_(i.template)&&(r.get(t)??0)>1&&O_(e,`segments.${t}`,`segment "${t}" hosts a {{ menu }} and is placed in the layout more than once — a menu's open-state is keyed by segment name, so the copies would share one state (clicking one would toggle both). Give each placement its own named segment.`);let i=new Set,a={},o=new Set,s=new Map;for(let[t,r]of Object.entries(n)){if(!D_(r.template))continue;let n=E_(r.template);if(n!==`parse-failed`)for(let r of n){if(r.kind===`issue`){O_(e,`segments.${t}`,`segment "${t}" has a {{ menu }} ${r.message}.`);continue}let{apply:n,options:c}=r;if(n===``){O_(e,`segments.${t}`,`segment "${t}" has a {{ menu }} 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.`);continue}let l=h_(n);if(l===`closed`){O_(e,`segments.${t}`,`segment "${t}" has a {{ menu }} whose apply action is named "${Xt}", which collides with the menu's closed-state sentinel and leaves it unopenable. Rename the action.`);continue}let u=g_(t,n,c.key),d=v_(u),f=c.key===void 0?`ind${t}${n}`:`key${c.key}`,p=[u,d].find(e=>{let t=s.get(e);return t!==void 0&&t!==f});if(p!==void 0){O_(e,`segments.${t}`,`two {{ menu }} disclosures normalize to the same state key ("${p}") 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}s.set(u,f),s.set(d,f);let m=__(u,l);if(o.has(m)){O_(e,`segments.${t}`,`two {{ menu }} disclosures resolve to the same identity ("${m}") — ${c.key===void 0?`a segment cannot contain two menus over the same apply action "${n}"`:`menus sharing key "${c.key}" must have distinct apply actions`}.`);continue}o.add(m),i.add(u),a[m]=nn(u,l)}}if(i.size===0)return;let c={};for(let e of i){c[e]=P(e,Xt);let t=v_(e);c[t]={kind:`state`,key:t,default:`0`},a[t]={set:t,int:!0}}t.variables={...t.variables??{},...c},t.actions={...t.actions??{},...a}}const A_=/^segments\.([^.]+)\.palette$/,j_=/^presets\.(.+)\.rootOps$/;function M_(e){return`presets.${e}.rootOps`}function N_(e){if(sg(e))return{scope:`globals`,field:e};let t=A_.exec(e);if(t)return{scope:`segment-palette`,segment:t[1]};let n=j_.exec(e);return n?{scope:`preset-root-ops`,preset:n[1]}:null}const P_=`open`;function F_(e,t,n,r,i){let a={variable:e,member:P_};r.variables[e]=P(e,Xt),r.actions[e]=nn(e,P_),r.segments[e]={template:tn(e,`(?)`,`✕`),...i,...I_(n)};let o=en(a,...n),s=t.map((t,n)=>{let a=`${e}.${n}`;return r.segments[a]={template:t,...i},{kind:`segment`,name:a}});return{trigger:{kind:`segment`,name:e},body:{kind:`container`,direction:`horizontal`,children:s,when:o}}}function I_(e){let[t,...n]=e;return t===void 0?{}:{when:en(t,...n)}}const L_=[`+ inserts here`,`- removes the one left of it`,`↺ undoes edits`],R_=[`☐ this session only`,`☑ default for every session`],z_=`
|
|
102
102
|
cc-candybar - Beautiful powerline statusline for Claude Code
|
|
103
103
|
|
|
104
104
|
Usage: cc-candybar [options]
|
|
@@ -119,10 +119,10 @@ Configuration:
|
|
|
119
119
|
needed, and writing your own \`root\` cannot delete it. Click
|
|
120
120
|
☰ ▸ on the bar for preset switching, edit mode, and a config menu
|
|
121
121
|
of clickable theme/look/style/wrap/padding controls. The \`persist?\`
|
|
122
|
-
checkbox there chooses where a change lands: ${
|
|
122
|
+
checkbox there chooses where a change lands: ${R_.join(`, `)}.
|
|
123
123
|
|
|
124
124
|
Anywhere the bar shows (?), clicking it reveals these same instructions
|
|
125
|
-
in place. In edit mode: ${
|
|
125
|
+
in place. In edit mode: ${L_.join(`, `)}.
|
|
126
126
|
|
|
127
127
|
Subcommands:
|
|
128
128
|
install One-shot setup: stages the runtime (native render
|
|
@@ -153,38 +153,38 @@ Config tooling:
|
|
|
153
153
|
config [--json] The effective merged config. (All three query the
|
|
154
154
|
running daemon; none spawn one.)
|
|
155
155
|
|
|
156
|
-
`,I_=`settings.`,L_=`${I_}menu`,R_=Jm,z_=`${I_}edit`,B_=`${I_}persist`,V_=`${I_}config`,H_=B_,U_={variable:L_,member:R_},W_=en(U_,{variable:V_,member:R_}),G_=`${I_}help.persist`,K_={bg:`surface`,fg:`foreground`},q_=`${I_}pickers`,J_=[{name:`preset`,sessionKey:`preset`,configKey:`preset`,effectiveVar:`preset.effective`,glyph:`▦`,domain:`presets`}],Y_=[{name:`theme`,sessionKey:`theme`,configKey:`palette`,effectiveVar:`theme.effective`,glyph:`🎨`,domain:`themes`},{name:`look`,sessionKey:`look`,configKey:`look`,effectiveVar:`look.effective`,glyph:`◐`,domain:`looks`},{name:`style`,sessionKey:`style`,configKey:`style`,effectiveVar:`style.effective`,glyph:`✦`,domain:`styles`}],X_={name:`wrap`,sessionKey:`autoWrap`,configKey:`autoWrap`},Z_={name:`padding`,sessionKey:`padding`,configKey:`padding`},Q_=`${I_}${X_.name}`,$_=`${I_}${Z_.name}`,ev=[...J_,...Y_];new Set([...ev,X_,Z_].flatMap(e=>[e.sessionKey,e.configKey]));const tv=e=>`${I_}${e}`,nv=e=>`${I_}apply.${e}`,rv=e=>`${I_}reset.${e}`,iv=en(U_);function av(e){return e===L_}function ov(e){let t={kind:`segment`,name:L_};if(e.kind===`segment`)return{kind:`container`,direction:`horizontal`,children:[e,t],...e.when!==void 0&&{when:e.when}};let[n,...r]=e.children;return e.direction===`vertical`&&n!==void 0&&n.when===void 0?{...e,children:[ov(n),...r]}:{...e,children:[...e.children,t]}}function sv(e){return cv(e)>0?e:ov(e)}function cv(e){return e.kind===`segment`?+!!av(e.name):e.children.reduce((e,t)=>e+cv(t),0)}function lv(e,t){return e.kind===`segment`?av(e.name)?{kind:`container`,direction:`vertical`,children:[e,{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:B_},t.trigger,...J_.map(e=>({kind:`segment`,name:tv(e.name)})),{kind:`segment`,name:V_},{kind:`segment`,name:z_}],when:iv},t.body,{kind:`container`,direction:`horizontal`,children:[...Y_.map(e=>({kind:`segment`,name:tv(e.name)})),{kind:`segment`,name:Q_},{kind:`segment`,name:$_}],when:W_}]}:e:{...e,children:e.children.map(e=>lv(e,t))}}function uv(e,t,n,r){let i=d_(t),a=f_(e,t,r),o=m_(a);n.variables[a]=P(a,Xt),n.variables[o]={kind:`state`,key:o,default:`0`},n.actions[p_(a,i)]=nn(a,i),n.actions[o]={set:o,int:!0}}function dv(){let e={variables:{[L_]:P(L_,Xt)},actions:{[L_]:nn(L_,R_),[V_]:nn(V_,R_),[B_]:{set:H_,cycle:[Mc,jc]}},segments:{[L_]:{template:tn(L_,`☰ ▸`,`☰ ▾`),...K_},[B_]:{template:`{{ action "${B_}" "☐ persist?" "☑ persist?" }}`,...K_},[V_]:{template:tn(V_,`⚙ config ▸`,`⚙ config ▾`),...K_},[Q_]:{template:`{{ action "${nv(`wrap`)}" "wrap: on" "wrap: off" }} {{ action "${rv(`wrap`)}" "↺" }}`,...K_},[$_]:{template:`{{ action "${nv(`padding`)}.down" "◀" }} padding {{ .padding.effective }} {{ action "${nv(`padding`)}.up" "▶" }} {{ action "${rv(`padding`)}" "↺" }}`,...K_},[z_]:{template:`{{ action "${qm}" "✎ edit" "✎ done" }}`,...K_}}};return e.variables[H_]={kind:`state`,key:H_,default:Mc},e.variables[V_]=P(V_,Xt),fv(e),{artifacts:e,help:j_(G_,P_,[U_],e,K_)}}function fv(e){for(let t of ev){let n=tv(t.name),r=nv(t.name);e.segments[n]={template:`${t.glyph} {{ .${t.effectiveVar} }} {{ menu "${r}" "▸" "▾" (dict "key" "${q_}" "closeOnPick" true) }} {{ action "${rv(t.name)}" "↺" }}`,...K_},e.actions[r]={set:t.sessionKey,persist:t.configKey,persistWhen:H_,from:t.domain},e.actions[rv(t.name)]={reset:t.configKey},uv(n,r,e,q_)}e.actions[nv(X_.name)]={set:X_.sessionKey,persist:X_.configKey,persistWhen:H_,cycle:[...Nc]},e.actions[rv(X_.name)]={reset:X_.configKey};for(let t of[-1,1])e.actions[`${nv(Z_.name)}.${t<0?`down`:`up`}`]={set:Z_.sessionKey,persist:Z_.configKey,persistWhen:H_,...Pc,by:t};e.actions[rv(Z_.name)]={reset:Z_.configKey}}function pv(e){e.variables[Km]=P(Km,Xt),e.actions[qm]=nn(Km,Jm)}const mv=`session.id`;function hv(e){return Object.prototype.hasOwnProperty.call(e.variables,mv)}function gv(e){if(!hv(e))return e;let{artifacts:t,help:n}=dv();pv(t);let r={...e.presets};for(let t of Jc(e.presets)){let{node:i}=Zc(e,t);r[t]={...Xc(e.presets,t),root:lv(sv(i),n)}}return{...e,variables:{...e.variables,...t.variables},actions:{...e.actions,...t.actions},segments:{...e.segments,...t.segments},presets:r}}const _v=`preset.customized`,vv=`{{ .${_v} }}`;function yv(e){return e.startsWith(`edit.`)||e.startsWith(`menus.`)||e.startsWith(`groups.`)||e.startsWith(`settings.`)}function bv(e){return`${Gm}addable.${e}`}function xv(e){let t=Object.keys(e.segments).filter(e=>!yv(e)),n=new Map;for(let r of Jc(e.presets)){let{node:i}=Zc(e,r),a=Vc(i);n.set(bv(r),t.filter(e=>!a.has(e)))}return n}function Sv(e,t,n,r){let i=`${Gm}${e}.remove.${l_(n)}`,a=`${Gm}${e}.removeSeg.${l_(n)}`;return r.actions[i]={persist:t,removeSegment:n},r.segments[a]={template:`{{ action "${i}" "-" }}`,when:Xm},{kind:`segment`,name:a}}function Cv(e,t,n,r,i,a,o){let s=`${Gm}${e}.insert.${n}`,c=`${Gm}${e}.insertSeg.${n}`;o.actions[s]={persist:t,insertSegmentFrom:r,anchor:i,relation:a};let l=d_(s),u=f_(c,s,void 0),d=m_(u),f=p_(u,l);return o.variables[u]=P(u,Xt),o.variables[d]={kind:`state`,key:d,default:`0`},o.actions[f]=nn(u,l),o.actions[d]={set:d,int:!0},o.segments[c]={template:`{{ menu "${s}" "+" "✕" }}`,when:Xm},{kind:`segment`,name:c}}function wv(e,t,n,r,i,a){let o=[],s=e.children.reduce((e,t,n)=>t.kind===`segment`&&!yv(t.name)?n:e,-1);for(let[c,l]of e.children.entries()){if(l.kind===`container`){o.push(wv(l,t,n,r,i,a));continue}if(yv(l.name)){o.push(l);continue}o.push(Cv(t,n,String(a.n++),r,l.name,`before`,i)),o.push(l),o.push(Sv(t,n,l.name,i)),c===s&&o.push(Cv(t,n,String(a.n++),r,l.name,`after`,i))}return{...e,children:o}}function Tv(e,t,n,r,i,a){let o=`${Gm}${n}.resetLayout`,s=`${Gm}${n}.customized`;i.actions[o]={reset:r},i.ensured[_v]={kind:`input`,path:_v,type:`boolean`,default:!1};let c=$t(t);return i.segments[s]={template:`{{ action "${o}" "↺ ${c} customized" }}`,when:vv},{kind:`container`,direction:`vertical`,children:[{kind:`segment`,name:s},Ev(e,a.trigger),a.body],...e.when!==void 0&&{when:e.when}}}function Ev(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),Ev(n,t)]}:{...e,children:[...e.children,t]}}function Dv(e,t,n,r){let{node:i}=Zc(e,t),a=O_(t),o=bv(t),s=l_(t),c={n:0};return Tv(wv(i.kind===`container`?i:{kind:`container`,direction:`horizontal`,children:[i],...i.when!==void 0&&{when:i.when}},s,a,o,n,c),t,s,a,n,r)}function Ov(e){if(!(`edit.toggle`in e.actions))return e;let t={variables:{},ensured:{},actions:{},segments:{}},n=j_(`${Gm}help`,N_,[Ym],t),r={...e.presets};for(let i of Jc(e.presets)){let a=Dv(e,i,t,n);r[i]={...Xc(e.presets,i),root:a}}return{...e,variables:{...t.ensured,...e.variables,...t.variables},actions:{...e.actions,...t.actions},segments:{...e.segments,...t.segments},presets:r}}const kv=[`set`,`persist`,`copy`,`open`,`reset`,`undo`,`redo`],Av=`persistWhen`;function jv(e){return Av in e}function Mv(e){return jv(e)?`to`in e?[{set:e.set,to:e.to},{persist:e.persist,to:e.to}]:`from`in e?[{set:e.set,from:e.from},{persist:e.persist,from:e.from}]:`cycle`in e?[{set:e.set,cycle:e.cycle},{persist:e.persist,cycle:e.cycle}]:[{set:e.set,min:e.min,max:e.max,by:e.by},{persist:e.persist,min:e.min,max:e.max,by:e.by}]:[e]}function Nv(e){return`set`in e}function Pv(e){return`persist`in e}function Fv(e){return`reset`in e}function Iv(e){return`undo`in e}function Lv(e){return`redo`in e}function Rv(e,t){if(t===void 0)return{};if(!Ch(t))return Q(e,`actions`,`actions must be an object, got ${wh(t)}`),{};let n=Object.create(null);for(let[r,i]of Object.entries(t)){let t=zv(e,`actions.${r}`,i);t!==null&&(n[r]=t)}return n}function Q(e,t,n){e.issues.push({path:t,message:n,line:X(e.source,t.split(`.`))})}function zv(e,t,n){if(!Ch(n))return Q(e,t,`${t} must be an action object, got ${wh(n)}`),null;if(`persistWhen`in n)return gy(e,t,n,`dual`,py);let r=kv.filter(e=>e in n);return r.length===1?Bv[r[0]](e,t,n):(Q(e,t,`action must declare exactly one of: ${kv.join(`, `)}${r.length>1?` (found: ${r.join(`, `)})`:``}`),null)}const Bv={set:(e,t,n)=>gy(e,t,n,`set`,dy),persist:(e,t,n)=>gy(e,t,n,`persist`,fy),copy:Vv(`copy`),open:Vv(`open`),reset:Hv,undo:Uv(`undo`),redo:Uv(`redo`)};function Vv(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=vh(t,n,r,e);return i===null?null:{[e]:i}}}function Hv(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=Wv(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}}function Uv(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 — it steps the ONE global history over the whole overrides layer), got ${Th(r[e])}`),null)}}function Wv(e,t,n,r,i,a){let o=vh(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 Gv={set:[[`set`,`the SessionState key to write`]],persist:[[`persist`,`the config globals field to write`]],dual:[[`set`,`the SessionState key written while persistWhen is off`],[`persist`,`the config globals field written while persistWhen is on`],[Av,`the SessionState key whose boolean value chooses the destination`]]};function Kv(e,t,n,r){let i={},a=Gv[r],o=!0;for(let[r,s]of a){if(!(r in n)){Q(e,t,`${r} is required here (${s}) — a dual-destination action declares ${a.map(([e])=>e).join(`, `)} together, plus one value source`),o=!1;continue}let c=Wv(e,t,r,n,`${r} key must be non-empty (${s})`,e=>`${r} key "${e}" contains "/" — keys must be slash-free`);if(c===null){o=!1;continue}i[r]=c}return o?i:null}function qv(e){return e===`set`?`set-state`:e===`persist`?`set-config`:`set-state/set-config`}const Jv={to:_y(`set`)},Yv={to:_y(`persist`)},Xv={from:vy(`set`)},Zv={from:vy(`persist`)},Qv={min:Cy(),max:Cy(),by:Cy()},$v={int:by()},ey={cycle:yy(`set`)},ty={to:_y(`dual`)},ny={from:vy(`dual`)},ry={cycle:yy(`dual`)},iy={cycle:yy(`persist`)},ay={removeSegment:xy(`removeSegment`)},oy={insertSegment:xy(`insertSegment`),anchor:xy(`anchor`),relation:Sy()},sy={insertSegmentFrom:vy(`persist`),anchor:xy(`anchor`),relation:Sy()},cy={ok:e=>e.min<e.max,issue:e=>({field:`min`,message:`min (${e.min}) must be less than max (${e.max})`})},ly={ok:e=>e.by!==0,issue:()=>({field:`by`,message:`by must be a non-zero integer (the per-click increment; negative steps down)`})};function uy(e,t,n=[],r){let i=Object.keys(t),a=r??i,o=Gv[e].map(([e])=>e),s=(e,n,r)=>Dh(e,t,n,r),c=zh(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?Mh(s,...n):s}}const dy=[uy(`set`,Jv),uy(`set`,Xv),uy(`set`,Qv,[cy,ly]),uy(`set`,$v),uy(`set`,ey)],fy=[uy(`persist`,Yv),uy(`persist`,Zv),uy(`persist`,Qv,[cy,ly]),uy(`persist`,iy),uy(`persist`,ay),uy(`persist`,oy,[],[`insertSegment`]),uy(`persist`,sy,[],[`insertSegmentFrom`])],py=[uy(`dual`,ty),uy(`dual`,ny),uy(`dual`,Qv,[cy,ly]),uy(`dual`,ry)];function my(e){let t=[`"to" (a literal value)`,`"from" (an option domain — a registered domain name like "themes"/"styles"/"looks", 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 hy(e){let t=my(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 gy(e,t,n,r,i){let a=Kv(e,t,n,r),o=i.filter(e=>e.detect.some(e=>e in n));if(o.length!==1)return Q(e,t,`${hy(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 _y(e){let t=qv(e);return{required:!0,json:{type:`string`},parse:(n,r,i,a)=>Wv(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 vy(e){let t=qv(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 ${Th(o)}`)}}}function yy(e){let t=qv(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 ${wh(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 by(){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 ${Th(r[n])}`);return}return!0}}}function xy(e){return{required:!0,json:{type:`string`},parse:(t,n,r,i)=>{let a=vh(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 Sy(){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 ${Th(i)}`);return}return i}}}function Cy(){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 ${Th(i)}`);return}return i}}}const wy={noun:`look key`,fields:{hueShift:Fh(),chromaScale:Fh({min:0}),lightnessScale:Fh(),lightnessShift:Fh()}};function Ty(e,t){if(!Ch(t))return e.issues.push({path:`looks`,message:`looks must be an object mapping look names to adaptation objects, got ${wh(t)}`,line:X(e.source,[`looks`])}),{};let n={};for(let[r,i]of Object.entries(t)){if(r===``||r.includes(`/`)){e.issues.push({path:`looks.${r}`,message:`look name ${JSON.stringify(r)} must be non-empty and slash-free — a look picker writes the name on the set-state wire, which rejects empty values and splits on "/"`,line:X(e.source,[`looks`,r])});continue}let t=Eh(e,wy,`looks.${r}`,i);t!==null&&(n[r]={...Da,...t})}return n}const Ey={noun:`preset key`,fields:{root:{required:!1,json:{$ref:Bg},parse:(e,t,n,r)=>r[n]===void 0?void 0:Qg(e,`${t}.${n}`,r[n])},globals:{required:!1,json:eg(),parse:(e,t,n,r)=>r[n]===void 0?void 0:$h(e,`${t}.${n}`,r[n])}}};function Dy(e,t){if(!Ch(t))return e.issues.push({path:`presets`,message:`presets must be an object mapping preset names to config fragments, got ${wh(t)}`,line:X(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:X(e.source,[`presets`,r])});continue}let t=Eh(e,Ey,`presets.${r}`,i);t!==null&&(n[r]=t)}return n}function Oy(e,t){if(t===void 0)return{};if(!Ch(t))return e.issues.push({path:`helpers`,message:`helpers must be an object, got ${wh(t)}`,line:X(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 ${Th(i)}`,line:X(e.source,[`helpers`,r])});continue}n[r]=i}return n}const ky=new Map;function Ay(e,t){ky.set(e,{permanent:!0,resolve:t})}Ay(`themes`,()=>Sc()),Ay(`styles`,()=>Ec),Ay(`charsets`,()=>kc),Ay(`colorCompatibilities`,()=>Ac);function jy(e){return new Map([[`looks`,Object.keys(e.looks)],[`presets`,Jc(e.presets)]])}function My(e){return[...new Set([...ky.keys(),...e.keys()])]}function Ny(e,t){if(typeof e!=`string`)return e;let n=t.get(e);if(n)return n;let r=ky.get(e);if(r)return r.resolve();throw Error(`unknown option domain "${e}" (have: ${My(t).join(`, `)})`)}const Py=/{{([\s\S]*?)}}/g,Fy=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`[^`]*`/g,Iy=/(?<![A-Za-z0-9_)])\.([A-Za-z_][\w]*(?:\.[A-Za-z_][\w]*)*)/g;function Ly(e){let t=new Set,n;for(Py.lastIndex=0;(n=Py.exec(e))!==null;){let e=n[1].replace(Fy,``),r;for(Iy.lastIndex=0;(r=Iy.exec(e))!==null;)t.add(r[1])}return t}const Ry=/\baction\s+$/;function zy(e){let t=new Set;Py.lastIndex=0;let n;for(;(n=Py.exec(e))!==null;){let e=n[1],r=0,i;for(Fy.lastIndex=0;(i=Fy.exec(e))!==null;)Ry.test(e.slice(r,i.index))&&t.add(i[0].slice(1,-1)),r=i.index+i[0].length}return t}const By=/\b(picker|menu)\s+$/;function Vy(e){let t=new Set;Py.lastIndex=0;let n;for(;(n=Py.exec(e))!==null;){let e=n[1],r=0,i=0,a;for(Fy.lastIndex=0;(a=Fy.exec(e))!==null;){let n=By.exec(e.slice(r,a.index));n!==null&&(i=n[1]===`picker`?2:1),i>0&&(t.add(a[0].slice(1,-1)),i--),r=a.index+a[0].length}}return t}function Hy(e,t){if(t.has(e))return!0;let n=`${e}.`;for(let e of t)if(e.startsWith(n))return!0;return!1}const Uy={gitTaculous:`gitaculous`};function Wy(e,t){let n=new Map;for(let e of Object.keys(t)){let t=l_(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:X(e.source,[`presets`])})}function Gy(e,t){t.globals.look!==void 0&&!Object.prototype.hasOwnProperty.call(t.looks,t.globals.look)&&e.issues.push({path:`globals.look`,message:`globals.look "${t.globals.look}" does not match any declared look (have: ${Object.keys(t.looks).join(`, `)})`,line:X(e.source,[`globals`,`look`])}),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:X(e.source,[`globals`,`preset`])}),Wy(e,t.presets);let n=jy(t);for(let[r,i]of Object.entries(t.actions))!(`set`in i)||!(`from`in i)||typeof i.from!=`string`||My(n).includes(i.from)||e.issues.push({path:`actions.${r}.from`,message:`actions.${r} from: references unknown option domain "${i.from}" (have: ${My(n).join(`, `)})`,line:X(e.source,[`actions`,r,`from`])});for(let[n,r]of Object.entries(t.actions)){if(!jv(r))continue;let i=r[Av];Yy(t,i)||e.issues.push({path:`actions.${n}.${Av}`,message:`actions.${n} ${Av}: "${i}" is not a declared state key — a dual action's selector must name a { kind: "state", key: "${i}" } variable, or the destination can never change`,line:X(e.source,[`actions`,n,Av])})}for(let[n,r]of Object.entries(t.actions)){let i=`persist`in r?r.persist:`reset`in r?r.reset:null;if(i===null)continue;let a=`persist`in r?`persist`:`reset`,o=k_(i);if(o===null){e.issues.push({path:`actions.${n}.${a}`,message:`actions.${n}: "${i}" is not a config globals field (have: ${ig().join(`, `)}), a "segments.<name>.palette" target, or a "presets.<name>.rootOps" target`,line:X(e.source,[`actions`,n,a])});continue}if(o.scope===`preset-root-ops`){Ky(e,t,n,a,i,o.preset,r);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}: "${i}" names segment "${o.segment}" which is not declared (have segments: ${Object.keys(t.segments).join(`, `)})`,line:X(e.source,[`actions`,n,a])});continue}`min`in r&&e.issues.push({path:`actions.${n}.${a}`,message:`actions.${n}: "${i}" is a segment palette target and cannot use a bounded stepper (min/max/by) — use "to", "from", or "cycle" instead`,line:X(e.source,[`actions`,n,a])})}}let r=new Set(Object.keys(t.variables));for(let[e,n]of Object.entries(t.segments))if(n.vars)for(let t of Object.keys(n.vars))r.add(`${e}.${t}`);let i=hv(t),a=(n,a,o)=>{cv(n)>1&&e.issues.push({path:a,message:`${a} places the global settings menu anchor "${L_}" ${cv(n)} 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:o});for(let s of oh(n))if(s.when!==void 0&&$y(e,`${a}.when`,s.when,r,{line:o}),s.kind===`segment`){if(av(s.name)){i||e.issues.push({path:a,message:`${a} places the global settings menu anchor "${L_}", but this config declares no "${mv}" variable — the menu is a click surface and every click composes a URL from "${mv}", so it is not synthesized for a config without it. Declare a "${mv}" variable (any config merged onto the bundled default inherits one) or remove the anchor placement.`,line:o});continue}if(!Object.prototype.hasOwnProperty.call(t.segments,s.name)){let t=Uy[s.name],n=t===void 0?``:` (the built-in segment "${s.name}" was renamed to "${t}" — update this reference)`;e.issues.push({path:a,message:`${a} entry "${s.name}" does not match any declared segment${n}`,line:o})}}},o=eb(e.source);a(t.root,o,X(e.source,[o]));for(let[n,r]of Object.entries(t.presets))r.root!==void 0&&a(r.root,`presets.${n}.root`,X(e.source,[`presets`,n,`root`]));for(let[n,i]of Object.entries(t.variables))Zy(e,`variables.${n}`,i,r);for(let[n,i]of Object.entries(t.segments)){if(i.vars)for(let[t,a]of Object.entries(i.vars))Zy(e,`segments.${n}.vars.${t}`,a,r,n);for(let a of[`template`,`bg`,`fg`,`when`]){let o=i[a];if(typeof o==`string`){$y(e,`segments.${n}.${a}`,o,r,{segCtx:n});for(let r of zy(o))Object.prototype.hasOwnProperty.call(t.actions,r)||e.issues.push({path:`segments.${n}.${a}`,message:`${a} references unknown action "${r}"`,line:X(e.source,[`segments`,n,a])});for(let r of Vy(o))Object.prototype.hasOwnProperty.call(t.actions,r)||e.issues.push({path:`segments.${n}.${a}`,message:`${a} references unknown action "${r}" (in a picker or menu)`,line:X(e.source,[`segments`,n,a])})}}}for(let[n,i]of Object.entries(t.variables))Qy(e,`variables.${n}`,i,r);for(let[n,i]of Object.entries(t.segments))if(i.vars)for(let[t,a]of Object.entries(i.vars))Qy(e,`segments.${n}.vars.${t}`,a,r,n);(Jy(t)||Xy(t))&&!Object.prototype.hasOwnProperty.call(t.variables,`session.id`)&&e.issues.push({path:`variables.session.id`,message:`state reads and action set-writes require a global "session.id" variable (segment-local declarations do not satisfy this — declareState/set-state both read the global box; conventionally { kind: "input", path: "session_id" })`,line:X(e.source,[`variables`])})}function Ky(e,t,n,r,i,a,o){let s=`actions.${n}.${r}`,c=X(e.source,[`actions`,n,r]);if(!Jc(t.presets).includes(a)){e.issues.push({path:s,message:`actions.${n}: "${i}" names preset "${a}" which is not declared (have: ${Jc(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>.rootOps" 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=e=>!Object.prototype.hasOwnProperty.call(t.segments,e);l&&`removeSegment`in o&&f(o.removeSegment)&&e.issues.push({path:s,message:`actions.${n}: removeSegment "${o.removeSegment}" is not a declared segment (have: ${Object.keys(t.segments).join(`, `)})`,line:c}),u&&`insertSegment`in o&&(f(o.insertSegment)&&e.issues.push({path:s,message:`actions.${n}: insertSegment "${o.insertSegment}" is not a declared segment (have: ${Object.keys(t.segments).join(`, `)})`,line:c}),f(o.anchor)&&e.issues.push({path:s,message:`actions.${n}: anchor "${o.anchor}" is not a declared segment (have: ${Object.keys(t.segments).join(`, `)})`,line:c})),d&&`insertSegmentFrom`in o&&f(o.anchor)&&e.issues.push({path:s,message:`actions.${n}: anchor "${o.anchor}" is not a declared segment (have: ${Object.keys(t.segments).join(`, `)})`,line:c})}function qy(e){return[...Object.values(e.variables),...Object.values(e.segments).flatMap(e=>Object.values(e.vars??{}))].filter(e=>e.kind===`state`)}function Jy(e){return qy(e).length>0}function Yy(e,t){return qy(e).some(e=>e.kind===`state`&&e.key===t)}function Xy(e){return Object.values(e.actions).some(e=>Nv(e)||Pv(e)||Fv(e)||Iv(e)||Lv(e))}function Zy(e,t,n,r,i){n.kind===`template`&&$y(e,`${t}.template`,n.template,r,{segCtx:i}),ch(n)&&n.cache&&`key`in n.cache&&$y(e,`${t}.cache.key`,n.cache.key,r,{segCtx:i})}function Qy(e,t,n,r,i){if(ch(n)&&n.cache&&`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.has(o))continue;let s=i===void 0?void 0:`${i}.${o}`,c=s!==void 0&&r.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:X(e.source,[...t.split(`.`),`cache`,`depends_on`])})}}function $y(e,t,n,r,i){for(let a of Ly(n)){if(Hy(a,r))continue;let n=i?.segCtx===void 0?void 0:`${i.segCtx}.${a}`,o=n!==void 0&&Hy(n,r)?` (segment-local vars are namespaced — write ".${n}")`:``;e.issues.push({path:t,message:`Template references unknown variable ".${a}"${o}`,line:i?.line??X(e.source,t.split(`.`))})}}function eb(e){try{let t=_h.default.parse(e);if(Ch(t)&&`root`in t)return`root`}catch{}return`layout`}function tb(e,t){let{graph:n,nodeInfo:r}=nb(t),i=new Map,a=[];for(let e of n.keys())i.set(e,0);for(let e of n.keys())if(i.get(e)===0&&o(e))return;function o(t){i.set(t,1),a.push(t);for(let s of n.get(t)??[]){let t=i.get(s);if(t===1){let t=a.indexOf(s),n=[...a.slice(t),s],i=n[0],o=r.get(i);return e.issues.push({path:o?.declarationPath??`variables.${i}`,message:`Dependency cycle: ${n.join(` → `)}`,line:X(e.source,o?.linePathParts??[`variables`,i])}),!0}if(t===0&&o(s))return!0}return i.set(t,2),a.pop(),!1}}function nb(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=(e,n)=>{for(let i of Ly(n)){if(t.has(i)){r.get(e).add(i);continue}let n=i.split(`.`)[0];n!==i&&t.has(n)&&r.get(e).add(n)}},a=(e,n)=>{if(n.kind===`template`&&i(e,n.template),ch(n)&&(n.cache&&`key`in n.cache&&i(e,n.cache.key),n.cache&&`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}}const rb=[`json5`,`json`];function ib(e){return e===`~`||e.startsWith(`~/`)||e.startsWith(`~\\`)?f.homedir()+e.slice(1):e}function ab(e,t,n){if(n)return[n];let r=process.env.CC_CANDYBAR_CONFIG;if(r)return[ib(r)];let i=t??process.cwd(),a=process.env.XDG_CONFIG_HOME??c.join(f.homedir(),`.config`);return[...e?rb.map(t=>c.join(e,`.cc-candybar.${t}`)):[],...rb.map(e=>c.join(i,`.cc-candybar.${e}`)),...rb.map(e=>c.join(a,`cc-candybar`,`config.${e}`))]}function ob(e,t,n){return ab(e,t,n).find(r.existsSync)??null}function sb(e,t){let n=ab(e,t),i=new Set,a=[];for(let e of n)i.has(e)||(i.add(e),r.existsSync(e)&&a.push(e));let o=new Map;for(let e of a){let t=c.dirname(e),n=c.basename(e).replace(/\.(json5|json)$/,``),r=c.join(t,n);o.has(r)||o.set(r,[]),o.get(r).push(e)}let s=[...o.values()].filter(e=>e.length>1);return s.length===0?null:`config-extension collision: ${s.map(e=>{let[t,...n]=e;return`${t} shadows ${n.join(`, `)}`}).join(`; `)} — remove the duplicate`}function cb(e,t,n){let i=e===null?``:r.readFileSync(e,`utf-8`);return{config:Wh(e===null?{}:ub(e,i,n),t),source:i}}function lb(e,t=`<config>`,n=``,r=new Set(Sc())){let i=[],a={source:n,issues:i,allowedPalettes:r,groups:[]};if(Gy(a,e),tb(a,e),i.length>0)throw new Bm(t,i);return Ov(gv(e))}function ub(e,t,n=new Set(Sc())){let r=db(e,t),i=[],a={source:t,issues:i,allowedPalettes:n,groups:[]};if(!Ch(r))throw new Bm(e,[{path:``,message:`Config root must be an object, got ${wh(r)}`}]);let o=fb(a,r);if(i.length>0)throw new Bm(e,i);return o}function db(e,t){try{return _h.default.parse(t)}catch(t){let n=t;throw new Bm(e,[{path:``,message:`JSON5 syntax error: ${n.message}`,line:n.lineNumber,col:n.columnNumber}])}}function fb(e,t){for(let n of Object.keys(t))pb.has(n)||e.issues.push({path:n,message:`Unknown top-level key "${n}". Expected one of: ${[...pb].join(`, `)}`,line:X(e.source,[n])});let n={};return t.globals!==void 0&&(n.globals=Qh(e,`globals`,t.globals)),t.variables!==void 0&&(n.variables=yg(e,`variables`,t.variables)),t.segments!==void 0&&(n.segments=Ig(e,t.segments)),t.layout!==void 0&&e.issues.push({path:`layout`,message:`"layout" is no longer supported — use "root" with the A-grammar instead.
|
|
156
|
+
`,B_=`settings.`,V_=`${B_}menu`,H_=Qm,U_=`${B_}edit`,W_=`${B_}persist`,G_=`${B_}config`,K_=W_,q_={variable:V_,member:H_},J_=en(q_,{variable:G_,member:H_}),Y_=`${B_}help.persist`,X_={bg:`surface`,fg:`foreground`},Z_=`${B_}pickers`,Q_=[{name:`preset`,sessionKey:`preset`,configKey:`preset`,effectiveVar:`preset.effective`,glyph:`▦`,domain:`presets`}],$_=[{name:`theme`,sessionKey:`theme`,configKey:`palette`,effectiveVar:`theme.effective`,glyph:`🎨`,domain:`themes`},{name:`look`,sessionKey:`look`,configKey:`look`,effectiveVar:`look.effective`,glyph:`◐`,domain:`looks`},{name:`style`,sessionKey:`style`,configKey:`style`,effectiveVar:`style.effective`,glyph:`✦`,domain:`styles`}],ev={name:`wrap`,sessionKey:`autoWrap`,configKey:`autoWrap`},tv={name:`padding`,sessionKey:`padding`,configKey:`padding`},nv=`${B_}${ev.name}`,rv=`${B_}${tv.name}`,iv=[...Q_,...$_];new Set([...iv,ev,tv].flatMap(e=>[e.sessionKey,e.configKey]));const av=e=>`${B_}${e}`,ov=e=>`${B_}apply.${e}`,sv=e=>`${B_}reset.${e}`,cv=en(q_);function lv(e){return e===V_}function uv(e){let t={kind:`segment`,name:V_};if(e.kind===`segment`)return{kind:`container`,direction:`horizontal`,children:[e,t],...e.when!==void 0&&{when:e.when}};let[n,...r]=e.children;return e.direction===`vertical`&&n!==void 0&&n.when===void 0?{...e,children:[uv(n),...r]}:{...e,children:[...e.children,t]}}function dv(e){return fv(e)>0?e:uv(e)}function fv(e){return e.kind===`segment`?+!!lv(e.name):e.children.reduce((e,t)=>e+fv(t),0)}function pv(e,t){return e.kind===`segment`?lv(e.name)?{kind:`container`,direction:`vertical`,children:[e,{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:W_},t.trigger,...Q_.map(e=>({kind:`segment`,name:av(e.name)})),{kind:`segment`,name:G_},{kind:`segment`,name:U_}],when:cv},t.body,{kind:`container`,direction:`horizontal`,children:[...$_.map(e=>({kind:`segment`,name:av(e.name)})),{kind:`segment`,name:nv},{kind:`segment`,name:rv}],when:J_}]}:e:{...e,children:e.children.map(e=>pv(e,t))}}function mv(e,t,n,r){let i=h_(t),a=g_(e,t,r),o=v_(a);n.variables[a]=P(a,Xt),n.variables[o]={kind:`state`,key:o,default:`0`},n.actions[__(a,i)]=nn(a,i),n.actions[o]={set:o,int:!0}}function hv(){let e={variables:{[V_]:P(V_,Xt)},actions:{[V_]:nn(V_,H_),[G_]:nn(G_,H_),[W_]:{set:K_,cycle:[Mc,jc]}},segments:{[V_]:{template:tn(V_,`☰ ▸`,`☰ ▾`),...X_},[W_]:{template:`{{ action "${W_}" "☐ persist?" "☑ persist?" }}`,...X_},[G_]:{template:tn(G_,`⚙ config ▸`,`⚙ config ▾`),...X_},[nv]:{template:`{{ action "${ov(`wrap`)}" "wrap: on" "wrap: off" }} {{ action "${sv(`wrap`)}" "↺" }}`,...X_},[rv]:{template:`{{ action "${ov(`padding`)}.down" "◀" }} padding {{ .padding.effective }} {{ action "${ov(`padding`)}.up" "▶" }} {{ action "${sv(`padding`)}" "↺" }}`,...X_},[U_]:{template:`{{ action "${Zm}" "✎ edit" "✎ done" }}`,...X_}}};return e.variables[K_]={kind:`state`,key:K_,default:Mc},e.variables[G_]=P(G_,Xt),gv(e),{artifacts:e,help:F_(Y_,R_,[q_],e,X_)}}function gv(e){for(let t of iv){let n=av(t.name),r=ov(t.name);e.segments[n]={template:`${t.glyph} {{ .${t.effectiveVar} }} {{ menu "${r}" "▸" "▾" (dict "key" "${Z_}" "closeOnPick" true) }} {{ action "${sv(t.name)}" "↺" }}`,...X_},e.actions[r]={set:t.sessionKey,persist:t.configKey,persistWhen:K_,from:t.domain},e.actions[sv(t.name)]={reset:t.configKey},mv(n,r,e,Z_)}e.actions[ov(ev.name)]={set:ev.sessionKey,persist:ev.configKey,persistWhen:K_,cycle:[...Nc]},e.actions[sv(ev.name)]={reset:ev.configKey};for(let t of[-1,1])e.actions[`${ov(tv.name)}.${t<0?`down`:`up`}`]={set:tv.sessionKey,persist:tv.configKey,persistWhen:K_,...Pc,by:t};e.actions[sv(tv.name)]={reset:tv.configKey}}function _v(e){e.variables[Xm]=P(Xm,Xt),e.actions[Zm]=nn(Xm,Qm)}const vv=`session.id`;function yv(e){return Object.prototype.hasOwnProperty.call(e.variables,vv)}function bv(e){if(!yv(e))return e;let{artifacts:t,help:n}=hv();_v(t);let r={...e.presets};for(let t of Jc(e.presets)){let{node:i}=Zc(e,t);r[t]={...Xc(e.presets,t),root:pv(dv(i),n)}}return{...e,variables:{...e.variables,...t.variables},actions:{...e.actions,...t.actions},segments:{...e.segments,...t.segments},presets:r}}const xv=`preset.customized`,Sv=`{{ .${xv} }}`;function Cv(e){return e.startsWith(`edit.`)||e.startsWith(`menus.`)||e.startsWith(`groups.`)||e.startsWith(`settings.`)}function wv(e){return`${Ym}addable.${e}`}function Tv(e){let t=Object.keys(e.segments).filter(e=>!Cv(e)),n=new Map;for(let r of Jc(e.presets)){let{node:i}=Zc(e,r),a=Vc(i);n.set(wv(r),t.filter(e=>!a.has(e)))}return n}function Ev(e,t,n,r){let i=`${Ym}${e}.remove.${p_(n)}`,a=`${Ym}${e}.removeSeg.${p_(n)}`;return r.actions[i]={persist:t,removeSegment:n},r.segments[a]={template:`{{ action "${i}" "-" }}`,when:eh},{kind:`segment`,name:a}}function Dv(e,t,n,r,i,a,o){let s=`${Ym}${e}.insert.${n}`,c=`${Ym}${e}.insertSeg.${n}`;o.actions[s]={persist:t,insertSegmentFrom:r,anchor:i,relation:a};let l=h_(s),u=g_(c,s,void 0),d=v_(u),f=__(u,l);return o.variables[u]=P(u,Xt),o.variables[d]={kind:`state`,key:d,default:`0`},o.actions[f]=nn(u,l),o.actions[d]={set:d,int:!0},o.segments[c]={template:`{{ menu "${s}" "+" "✕" }}`,when:eh},{kind:`segment`,name:c}}function Ov(e,t,n,r,i,a){let o=[],s=e.children.reduce((e,t,n)=>t.kind===`segment`&&!Cv(t.name)?n:e,-1);for(let[c,l]of e.children.entries()){if(l.kind===`container`){o.push(Ov(l,t,n,r,i,a));continue}if(Cv(l.name)){o.push(l);continue}o.push(Dv(t,n,String(a.n++),r,l.name,`before`,i)),o.push(l),o.push(Ev(t,n,l.name,i)),c===s&&o.push(Dv(t,n,String(a.n++),r,l.name,`after`,i))}return{...e,children:o}}function kv(e,t,n,r,i,a){let o=`${Ym}${n}.resetLayout`,s=`${Ym}${n}.customized`;i.actions[o]={reset:r},i.ensured[xv]={kind:`input`,path:xv,type:`boolean`,default:!1};let c=$t(t);return i.segments[s]={template:`{{ action "${o}" "↺ ${c} customized" }}`,when:Sv},{kind:`container`,direction:`vertical`,children:[{kind:`segment`,name:s},Av(e,a.trigger),a.body],...e.when!==void 0&&{when:e.when}}}function Av(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),Av(n,t)]}:{...e,children:[...e.children,t]}}function jv(e,t,n,r){let{node:i}=Zc(e,t),a=M_(t),o=wv(t),s=p_(t),c={n:0};return kv(Ov(i.kind===`container`?i:{kind:`container`,direction:`horizontal`,children:[i],...i.when!==void 0&&{when:i.when}},s,a,o,n,c),t,s,a,n,r)}function Mv(e){if(!(`edit.toggle`in e.actions))return e;let t={variables:{},ensured:{},actions:{},segments:{}},n=F_(`${Ym}help`,L_,[$m],t),r={...e.presets};for(let i of Jc(e.presets)){let a=jv(e,i,t,n);r[i]={...Xc(e.presets,i),root:a}}return{...e,variables:{...t.ensured,...e.variables,...t.variables},actions:{...e.actions,...t.actions},segments:{...e.segments,...t.segments},presets:r}}const Nv=[`set`,`persist`,`copy`,`open`,`reset`,`undo`,`redo`],Pv=`persistWhen`;function Fv(e){return Pv in e}function Iv(e){return Fv(e)?`to`in e?[{set:e.set,to:e.to},{persist:e.persist,to:e.to}]:`from`in e?[{set:e.set,from:e.from},{persist:e.persist,from:e.from}]:`cycle`in e?[{set:e.set,cycle:e.cycle},{persist:e.persist,cycle:e.cycle}]:[{set:e.set,min:e.min,max:e.max,by:e.by},{persist:e.persist,min:e.min,max:e.max,by:e.by}]:[e]}function Lv(e){return`set`in e}function Rv(e){return`persist`in e}function zv(e){return`reset`in e}function Bv(e){return`undo`in e}function Vv(e){return`redo`in e}function Hv(e,t){if(t===void 0)return{};if(!Dh(t))return Q(e,`actions`,`actions must be an object, got ${Oh(t)}`),{};let n=Object.create(null);for(let[r,i]of Object.entries(t)){let t=Uv(e,`actions.${r}`,i);t!==null&&(n[r]=t)}return n}function Q(e,t,n){e.issues.push({path:t,message:n,line:X(e.source,t.split(`.`))})}function Uv(e,t,n){if(!Dh(n))return Q(e,t,`${t} must be an action object, got ${Oh(n)}`),null;if(`persistWhen`in n)return by(e,t,n,`dual`,_y);let r=Nv.filter(e=>e in n);return r.length===1?Wv[r[0]](e,t,n):(Q(e,t,`action must declare exactly one of: ${Nv.join(`, `)}${r.length>1?` (found: ${r.join(`, `)})`:``}`),null)}const Wv={set:(e,t,n)=>by(e,t,n,`set`,hy),persist:(e,t,n)=>by(e,t,n,`persist`,gy),copy:Gv(`copy`),open:Gv(`open`),reset:Kv,undo:qv(`undo`),redo:qv(`redo`)};function Gv(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=Sh(t,n,r,e);return i===null?null:{[e]:i}}}function Kv(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=Jv(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}}function qv(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 — it steps the ONE global history over the whole overrides layer), got ${kh(r[e])}`),null)}}function Jv(e,t,n,r,i,a){let o=Sh(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 Yv={set:[[`set`,`the SessionState key to write`]],persist:[[`persist`,`the config globals field to write`]],dual:[[`set`,`the SessionState key written while persistWhen is off`],[`persist`,`the config globals field written while persistWhen is on`],[Pv,`the SessionState key whose boolean value chooses the destination`]]};function Xv(e,t,n,r){let i={},a=Yv[r],o=!0;for(let[r,s]of a){if(!(r in n)){Q(e,t,`${r} is required here (${s}) — a dual-destination action declares ${a.map(([e])=>e).join(`, `)} together, plus one value source`),o=!1;continue}let c=Jv(e,t,r,n,`${r} key must be non-empty (${s})`,e=>`${r} key "${e}" contains "/" — keys must be slash-free`);if(c===null){o=!1;continue}i[r]=c}return o?i:null}function Zv(e){return e===`set`?`set-state`:e===`persist`?`set-config`:`set-state/set-config`}const Qv={to:xy(`set`)},$v={to:xy(`persist`)},ey={from:Sy(`set`)},ty={from:Sy(`persist`)},ny={min:Dy(),max:Dy(),by:Dy()},ry={int:wy()},iy={cycle:Cy(`set`)},ay={to:xy(`dual`)},oy={from:Sy(`dual`)},sy={cycle:Cy(`dual`)},cy={cycle:Cy(`persist`)},ly={removeSegment:Ty(`removeSegment`)},uy={insertSegment:Ty(`insertSegment`),anchor:Ty(`anchor`),relation:Ey()},dy={insertSegmentFrom:Sy(`persist`),anchor:Ty(`anchor`),relation:Ey()},fy={ok:e=>e.min<e.max,issue:e=>({field:`min`,message:`min (${e.min}) must be less than max (${e.max})`})},py={ok:e=>e.by!==0,issue:()=>({field:`by`,message:`by must be a non-zero integer (the per-click increment; negative steps down)`})};function my(e,t,n=[],r){let i=Object.keys(t),a=r??i,o=Yv[e].map(([e])=>e),s=(e,n,r)=>jh(e,t,n,r),c=Uh(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?Ih(s,...n):s}}const hy=[my(`set`,Qv),my(`set`,ey),my(`set`,ny,[fy,py]),my(`set`,ry),my(`set`,iy)],gy=[my(`persist`,$v),my(`persist`,ty),my(`persist`,ny,[fy,py]),my(`persist`,cy),my(`persist`,ly),my(`persist`,uy,[],[`insertSegment`]),my(`persist`,dy,[],[`insertSegmentFrom`])],_y=[my(`dual`,ay),my(`dual`,oy),my(`dual`,ny,[fy,py]),my(`dual`,sy)];function vy(e){let t=[`"to" (a literal value)`,`"from" (an option domain — a registered domain name like "themes"/"styles"/"looks", 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 yy(e){let t=vy(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 by(e,t,n,r,i){let a=Xv(e,t,n,r),o=i.filter(e=>e.detect.some(e=>e in n));if(o.length!==1)return Q(e,t,`${yy(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 xy(e){let t=Zv(e);return{required:!0,json:{type:`string`},parse:(n,r,i,a)=>Jv(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 Sy(e){let t=Zv(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 ${kh(o)}`)}}}function Cy(e){let t=Zv(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 ${Oh(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 wy(){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 ${kh(r[n])}`);return}return!0}}}function Ty(e){return{required:!0,json:{type:`string`},parse:(t,n,r,i)=>{let a=Sh(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 Ey(){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 ${kh(i)}`);return}return i}}}function Dy(){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 ${kh(i)}`);return}return i}}}const Oy={noun:`look key`,fields:{hueShift:zh(),chromaScale:zh({min:0}),lightnessScale:zh(),lightnessShift:zh()}};function ky(e,t){if(!Dh(t))return e.issues.push({path:`looks`,message:`looks must be an object mapping look names to adaptation objects, got ${Oh(t)}`,line:X(e.source,[`looks`])}),{};let n={};for(let[r,i]of Object.entries(t)){if(r===``||r.includes(`/`)){e.issues.push({path:`looks.${r}`,message:`look name ${JSON.stringify(r)} must be non-empty and slash-free — a look picker writes the name on the set-state wire, which rejects empty values and splits on "/"`,line:X(e.source,[`looks`,r])});continue}let t=Ah(e,Oy,`looks.${r}`,i);t!==null&&(n[r]={...Da,...t})}return n}const Ay={noun:`preset key`,fields:{root:{required:!1,json:{$ref:Wg},parse:(e,t,n,r)=>r[n]===void 0?void 0:n_(e,`${t}.${n}`,r[n])},globals:{required:!1,json:ig(),parse:(e,t,n,r)=>r[n]===void 0?void 0:rg(e,`${t}.${n}`,r[n])}}};function jy(e,t){if(!Dh(t))return e.issues.push({path:`presets`,message:`presets must be an object mapping preset names to config fragments, got ${Oh(t)}`,line:X(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:X(e.source,[`presets`,r])});continue}let t=Ah(e,Ay,`presets.${r}`,i);t!==null&&(n[r]=t)}return n}function My(e,t){if(t===void 0)return{};if(!Dh(t))return e.issues.push({path:`helpers`,message:`helpers must be an object, got ${Oh(t)}`,line:X(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 ${kh(i)}`,line:X(e.source,[`helpers`,r])});continue}n[r]=i}return n}const Ny=new Map;function Py(e,t){Ny.set(e,{permanent:!0,resolve:t})}Py(`themes`,()=>Sc()),Py(`styles`,()=>Ec),Py(`charsets`,()=>kc),Py(`colorCompatibilities`,()=>Ac);function Fy(e){return new Map([[`looks`,Object.keys(e.looks)],[`presets`,Jc(e.presets)]])}function Iy(e){return[...new Set([...Ny.keys(),...e.keys()])]}function Ly(e,t){if(typeof e!=`string`)return e;let n=t.get(e);if(n)return n;let r=Ny.get(e);if(r)return r.resolve();throw Error(`unknown option domain "${e}" (have: ${Iy(t).join(`, `)})`)}const Ry=/{{([\s\S]*?)}}/g,zy=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`[^`]*`/g,By=/(?<![A-Za-z0-9_)])\.([A-Za-z_][\w]*(?:\.[A-Za-z_][\w]*)*)/g;function Vy(e){let t=new Set,n;for(Ry.lastIndex=0;(n=Ry.exec(e))!==null;){let e=n[1].replace(zy,``),r;for(By.lastIndex=0;(r=By.exec(e))!==null;)t.add(r[1])}return t}const Hy=/\baction\s+$/;function Uy(e){let t=new Set;Ry.lastIndex=0;let n;for(;(n=Ry.exec(e))!==null;){let e=n[1],r=0,i;for(zy.lastIndex=0;(i=zy.exec(e))!==null;)Hy.test(e.slice(r,i.index))&&t.add(i[0].slice(1,-1)),r=i.index+i[0].length}return t}const Wy=/\b(picker|menu)\s+$/;function Gy(e){let t=new Set;Ry.lastIndex=0;let n;for(;(n=Ry.exec(e))!==null;){let e=n[1],r=0,i=0,a;for(zy.lastIndex=0;(a=zy.exec(e))!==null;){let n=Wy.exec(e.slice(r,a.index));n!==null&&(i=n[1]===`picker`?2:1),i>0&&(t.add(a[0].slice(1,-1)),i--),r=a.index+a[0].length}}return t}function Ky(e,t){if(t.has(e))return!0;let n=`${e}.`;for(let e of t)if(e.startsWith(n))return!0;return!1}const qy={gitTaculous:`gitaculous`};function Jy(e,t){let n=new Map;for(let e of Object.keys(t)){let t=p_(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:X(e.source,[`presets`])})}function Yy(e,t){t.globals.look!==void 0&&!Object.prototype.hasOwnProperty.call(t.looks,t.globals.look)&&e.issues.push({path:`globals.look`,message:`globals.look "${t.globals.look}" does not match any declared look (have: ${Object.keys(t.looks).join(`, `)})`,line:X(e.source,[`globals`,`look`])}),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:X(e.source,[`globals`,`preset`])}),Jy(e,t.presets);let n=Fy(t);for(let[r,i]of Object.entries(t.actions))!(`set`in i)||!(`from`in i)||typeof i.from!=`string`||Iy(n).includes(i.from)||e.issues.push({path:`actions.${r}.from`,message:`actions.${r} from: references unknown option domain "${i.from}" (have: ${Iy(n).join(`, `)})`,line:X(e.source,[`actions`,r,`from`])});for(let[n,r]of Object.entries(t.actions)){if(!Fv(r))continue;let i=r[Pv];$y(t,i)||e.issues.push({path:`actions.${n}.${Pv}`,message:`actions.${n} ${Pv}: "${i}" is not a declared state key — a dual action's selector must name a { kind: "state", key: "${i}" } variable, or the destination can never change`,line:X(e.source,[`actions`,n,Pv])})}for(let[n,r]of Object.entries(t.actions)){let i=`persist`in r?r.persist:`reset`in r?r.reset:null;if(i===null)continue;let a=`persist`in r?`persist`:`reset`,o=N_(i);if(o===null){e.issues.push({path:`actions.${n}.${a}`,message:`actions.${n}: "${i}" is not a config globals field (have: ${cg().join(`, `)}), a "segments.<name>.palette" target, or a "presets.<name>.rootOps" target`,line:X(e.source,[`actions`,n,a])});continue}if(o.scope===`preset-root-ops`){Xy(e,t,n,a,i,o.preset,r);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}: "${i}" names segment "${o.segment}" which is not declared (have segments: ${Object.keys(t.segments).join(`, `)})`,line:X(e.source,[`actions`,n,a])});continue}`min`in r&&e.issues.push({path:`actions.${n}.${a}`,message:`actions.${n}: "${i}" is a segment palette target and cannot use a bounded stepper (min/max/by) — use "to", "from", or "cycle" instead`,line:X(e.source,[`actions`,n,a])})}}let r=new Set(Object.keys(t.variables));for(let[e,n]of Object.entries(t.segments))if(n.vars)for(let t of Object.keys(n.vars))r.add(`${e}.${t}`);let i=yv(t),a=(n,a,o)=>{fv(n)>1&&e.issues.push({path:a,message:`${a} places the global settings menu anchor "${V_}" ${fv(n)} 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:o});for(let s of uh(n))if(s.when!==void 0&&rb(e,`${a}.when`,s.when,r,{line:o}),s.kind===`segment`){if(lv(s.name)){i||e.issues.push({path:a,message:`${a} places the global settings menu anchor "${V_}", but this config declares no "${vv}" variable — the menu is a click surface and every click composes a URL from "${vv}", so it is not synthesized for a config without it. Declare a "${vv}" variable (any config merged onto the bundled default inherits one) or remove the anchor placement.`,line:o});continue}if(!Object.prototype.hasOwnProperty.call(t.segments,s.name)){let t=qy[s.name],n=t===void 0?``:` (the built-in segment "${s.name}" was renamed to "${t}" — update this reference)`;e.issues.push({path:a,message:`${a} entry "${s.name}" does not match any declared segment${n}`,line:o})}}},o=ib(e.source);a(t.root,o,X(e.source,[o]));for(let[n,r]of Object.entries(t.presets))r.root!==void 0&&a(r.root,`presets.${n}.root`,X(e.source,[`presets`,n,`root`]));for(let[n,i]of Object.entries(t.variables))tb(e,`variables.${n}`,i,r);for(let[n,i]of Object.entries(t.segments)){if(i.vars)for(let[t,a]of Object.entries(i.vars))tb(e,`segments.${n}.vars.${t}`,a,r,n);for(let a of[`template`,`bg`,`fg`,`when`]){let o=i[a];if(typeof o==`string`){rb(e,`segments.${n}.${a}`,o,r,{segCtx:n});for(let r of Uy(o))Object.prototype.hasOwnProperty.call(t.actions,r)||e.issues.push({path:`segments.${n}.${a}`,message:`${a} references unknown action "${r}"`,line:X(e.source,[`segments`,n,a])});for(let r of Gy(o))Object.prototype.hasOwnProperty.call(t.actions,r)||e.issues.push({path:`segments.${n}.${a}`,message:`${a} references unknown action "${r}" (in a picker or menu)`,line:X(e.source,[`segments`,n,a])})}}}for(let[n,i]of Object.entries(t.variables))nb(e,`variables.${n}`,i,r);for(let[n,i]of Object.entries(t.segments))if(i.vars)for(let[t,a]of Object.entries(i.vars))nb(e,`segments.${n}.vars.${t}`,a,r,n);(Qy(t)||eb(t))&&!Object.prototype.hasOwnProperty.call(t.variables,`session.id`)&&e.issues.push({path:`variables.session.id`,message:`state reads and action set-writes require a global "session.id" variable (segment-local declarations do not satisfy this — declareState/set-state both read the global box; conventionally { kind: "input", path: "session_id" })`,line:X(e.source,[`variables`])})}function Xy(e,t,n,r,i,a,o){let s=`actions.${n}.${r}`,c=X(e.source,[`actions`,n,r]);if(!Jc(t.presets).includes(a)){e.issues.push({path:s,message:`actions.${n}: "${i}" names preset "${a}" which is not declared (have: ${Jc(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>.rootOps" 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=e=>!Object.prototype.hasOwnProperty.call(t.segments,e);l&&`removeSegment`in o&&f(o.removeSegment)&&e.issues.push({path:s,message:`actions.${n}: removeSegment "${o.removeSegment}" is not a declared segment (have: ${Object.keys(t.segments).join(`, `)})`,line:c}),u&&`insertSegment`in o&&(f(o.insertSegment)&&e.issues.push({path:s,message:`actions.${n}: insertSegment "${o.insertSegment}" is not a declared segment (have: ${Object.keys(t.segments).join(`, `)})`,line:c}),f(o.anchor)&&e.issues.push({path:s,message:`actions.${n}: anchor "${o.anchor}" is not a declared segment (have: ${Object.keys(t.segments).join(`, `)})`,line:c})),d&&`insertSegmentFrom`in o&&f(o.anchor)&&e.issues.push({path:s,message:`actions.${n}: anchor "${o.anchor}" is not a declared segment (have: ${Object.keys(t.segments).join(`, `)})`,line:c})}function Zy(e){return[...Object.values(e.variables),...Object.values(e.segments).flatMap(e=>Object.values(e.vars??{}))].filter(e=>e.kind===`state`)}function Qy(e){return Zy(e).length>0}function $y(e,t){return Zy(e).some(e=>e.kind===`state`&&e.key===t)}function eb(e){return Object.values(e.actions).some(e=>Lv(e)||Rv(e)||zv(e)||Bv(e)||Vv(e))}function tb(e,t,n,r,i){n.kind===`template`&&rb(e,`${t}.template`,n.template,r,{segCtx:i}),fh(n)&&n.cache&&`key`in n.cache&&rb(e,`${t}.cache.key`,n.cache.key,r,{segCtx:i})}function nb(e,t,n,r,i){if(fh(n)&&n.cache&&`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.has(o))continue;let s=i===void 0?void 0:`${i}.${o}`,c=s!==void 0&&r.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:X(e.source,[...t.split(`.`),`cache`,`depends_on`])})}}function rb(e,t,n,r,i){for(let a of Vy(n)){if(Ky(a,r))continue;let n=i?.segCtx===void 0?void 0:`${i.segCtx}.${a}`,o=n!==void 0&&Ky(n,r)?` (segment-local vars are namespaced — write ".${n}")`:``;e.issues.push({path:t,message:`Template references unknown variable ".${a}"${o}`,line:i?.line??X(e.source,t.split(`.`))})}}function ib(e){try{let t=xh.default.parse(e);if(Dh(t)&&`root`in t)return`root`}catch{}return`layout`}function ab(e,t){let{graph:n,nodeInfo:r}=ob(t),i=new Map,a=[];for(let e of n.keys())i.set(e,0);for(let e of n.keys())if(i.get(e)===0&&o(e))return;function o(t){i.set(t,1),a.push(t);for(let s of n.get(t)??[]){let t=i.get(s);if(t===1){let t=a.indexOf(s),n=[...a.slice(t),s],i=n[0],o=r.get(i);return e.issues.push({path:o?.declarationPath??`variables.${i}`,message:`Dependency cycle: ${n.join(` → `)}`,line:X(e.source,o?.linePathParts??[`variables`,i])}),!0}if(t===0&&o(s))return!0}return i.set(t,2),a.pop(),!1}}function ob(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=(e,n)=>{for(let i of Vy(n)){if(t.has(i)){r.get(e).add(i);continue}let n=i.split(`.`)[0];n!==i&&t.has(n)&&r.get(e).add(n)}},a=(e,n)=>{if(n.kind===`template`&&i(e,n.template),fh(n)&&(n.cache&&`key`in n.cache&&i(e,n.cache.key),n.cache&&`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}}const sb=[`json5`,`json`];function cb(e){return e===`~`||e.startsWith(`~/`)||e.startsWith(`~\\`)?f.homedir()+e.slice(1):e}function lb(e,t,n){if(n)return[n];let r=process.env.CC_CANDYBAR_CONFIG;if(r)return[cb(r)];let i=t??process.cwd(),a=process.env.XDG_CONFIG_HOME??c.join(f.homedir(),`.config`);return[...e?sb.map(t=>c.join(e,`.cc-candybar.${t}`)):[],...sb.map(e=>c.join(i,`.cc-candybar.${e}`)),...sb.map(e=>c.join(a,`cc-candybar`,`config.${e}`))]}function ub(e,t,n){return lb(e,t,n).find(r.existsSync)??null}function db(e,t){let n=lb(e,t),i=new Set,a=[];for(let e of n)i.has(e)||(i.add(e),r.existsSync(e)&&a.push(e));let o=new Map;for(let e of a){let t=c.dirname(e),n=c.basename(e).replace(/\.(json5|json)$/,``),r=c.join(t,n);o.has(r)||o.set(r,[]),o.get(r).push(e)}let s=[...o.values()].filter(e=>e.length>1);return s.length===0?null:`config-extension collision: ${s.map(e=>{let[t,...n]=e;return`${t} shadows ${n.join(`, `)}`}).join(`; `)} — remove the duplicate`}function fb(e,t,n){let i=e===null?``:r.readFileSync(e,`utf-8`);return{config:Jh(e===null?{}:mb(e,i,n),t),source:i}}function pb(e,t=`<config>`,n=``,r=new Set(Sc())){let i=[],a={source:n,issues:i,allowedPalettes:r,groups:[]};if(Yy(a,e),ab(a,e),i.length>0)throw new Wm(t,i);return Mv(bv(e))}function mb(e,t,n=new Set(Sc())){let r=hb(e,t),i=[],a={source:t,issues:i,allowedPalettes:n,groups:[]};if(!Dh(r))throw new Wm(e,[{path:``,message:`Config root must be an object, got ${Oh(r)}`}]);let o=gb(a,r);if(i.length>0)throw new Wm(e,i);return o}function hb(e,t){try{return xh.default.parse(t)}catch(t){let n=t;throw new Wm(e,[{path:``,message:`JSON5 syntax error: ${n.message}`,line:n.lineNumber,col:n.columnNumber}])}}function gb(e,t){for(let n of Object.keys(t))_b.has(n)||e.issues.push({path:n,message:`Unknown top-level key "${n}". Expected one of: ${[..._b].join(`, `)}`,line:X(e.source,[n])});let n={};return t.globals!==void 0&&(n.globals=ng(e,`globals`,t.globals)),t.variables!==void 0&&(n.variables=Cg(e,`variables`,t.variables)),t.segments!==void 0&&(n.segments=Bg(e,t.segments)),t.layout!==void 0&&e.issues.push({path:`layout`,message:`"layout" is no longer supported — use "root" with the A-grammar instead.
|
|
157
157
|
Replace: layout: [["seg1", "seg2"], ["seg3"]]
|
|
158
158
|
With: root: { v: [{ h: ["seg1", "seg2"] }, "seg3"] }
|
|
159
|
-
Single-row example: root: { h: ["seg1", "seg2"] }`,line:X(e.source,[`layout`])}),t.root!==void 0&&(n.root=
|
|
160
|
-
`),r=+!t;for(let e=n.length-1;e>=r;e--){let t=n[e];if(!t||!mb.test(t))continue;let r=hb(t);if(r!=null)return r}return null}function yb(e,t,n){let r=Yc(t(`preset`),e.globals.preset,e.presets),i=Qc(e,r),a=t(`edit.mode`)===`open`?e.editGlobals:{};return{preset:r,presetCustomized:n(r),theme:bc(a.palette,t(`theme`),i.palette),look:wc(a.look,t(`look`),i.look,e.looks),style:Oc(a.style,t(`style`),i.style),separator:a.default_separator??i.default_separator,autoWrap:Lc(a.autoWrap,t(`autoWrap`),i.autoWrap),padding:Rc(a.padding,t(`padding`),i.padding),charset:a.charset??i.charset??`unicode`,colorCompatibility:a.colorCompatibility??i.colorCompatibility??`truecolor`}}const bb=10*1e3;function xb(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 Sb(e,t){if(!(t<60))return e*3600/t}function Cb(e,t,n,r){let i=r-t;if(i<50||i>bb)return;let a=n-e;if(!(a<=0))return a*1e3/i}function wb(e){let{prev:t,cur:n}=e;if(t===void 0)return;let r=Cb(t.input,t.atMs,n.input,n.atMs),i=Cb(t.output,t.atMs,n.output,n.atMs),a=Cb(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 Tb(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>bb)continue;let o=Cb(r.total,r.atMs,i.total,i.atMs);n.push(o??0)}if(n.length!==0)return n.join(`,`)}function Eb(e){let t=e.indexOf(`.`);return t<0?e:e.slice(0,t)}function Db(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`,()=>Eb(f.hostname())),i=n(`user`,()=>f.userInfo().username);return{host:{...r!==void 0&&{name:r},...i!==void 0&&{user:i},...e.ssh!==void 0&&{ssh:e.ssh}},failures:t}}function Ob(e){let t=new Map;for(let[n,r]of Object.entries(e.variables))t.set(n,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}`,i);let n=[],r=new Set;for(let t of oh(e.root)){if(t.when)for(let e of Ly(t.when))n.push(e);if(t.kind!==`segment`)continue;let r=e.segments[t.name];if(r){for(let e of[r.template,r.when,r.bg,r.fg])if(e)for(let t of Ly(e))n.push(t)}}let i=new Set;for(;n.length>0;){let e=n.pop();for(let a of kb(t,e)){if(r.has(a))continue;r.add(a);let e=t.get(a);if(e){if(e.kind===`input`)i.add(e.path);else if(e.kind===`template`)for(let t of Ly(e.template))n.push(t)}}}return i}function kb(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 Ab(e,t){for(let n of e)if(n===t||n.startsWith(t+`.`))return!0;return!1}function jb(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`)&&{showUpstream:!0},...t(`git.repoName`)&&{showRepoName:!0},...t(`git.repoUrl`)&&{showRepoUrl:!0},...t(`git.operation`)&&{showOperation:!0},...t(`git.timeSinceCommit`)&&{showTimeSinceCommit:!0},...(t(`git.prNumber`)||t(`git.prState`)||t(`git.prUrl`)||t(`git.prError`))&&{showPullRequest:!0}}}async function Mb(e,t,n,r,i,a){let o=e=>Ab(r,e),s=(t.clock??(()=>new Date))().getTime(),c=(e,t,n)=>t?n().catch(t=>Xn(`${e}: ${String(t)}`)):Promise.resolve(B),[l,u,d,f,p,m,h,g]=await Promise.all([c(`git`,o(`git`),()=>t.gitProvider.getGitInfo(n??e.workspace?.current_dir,jb(r),e.workspace?.project_dir)),c(`session`,o(`session.cost`)||o(`session.tokens`)||o(`burn`),()=>t.usageStore.getUsageInfo(e.session_id,e)),c(`today`,o(`today`),()=>t.usageStore.getTodayInfo(e)),c(`context`,o(`context`),()=>t.contextProvider.getContextInfo(e)),c(`metrics`,o(`metrics`)||o(`burn`),()=>t.metricsProvider.getMetricsInfo(e.session_id,e)),c(`tmux`,o(`tmux`),()=>t.tmuxService.getSessionId()),c(`cache`,o(`cache`),()=>gb(e.transcript_path)),c(`speed`,o(`speed`),()=>t.usageStore.observeSpeed(e.session_id,e.transcript_path,s))]),_=[],v=e=>{if(e.kind===`failed`){_.push(e.reason);return}return e.kind===`ok`?e.value:void 0},y=Fb(l);_.push(...y.failures);let b=Db(a);_.push(...b.failures);let x=v(u),S=v(d),C=v(f),w=v(p),ee=v(m),T=v(h);for(let e of _)t.log(`warn`,`provider fetch failed: ${e}`);let te=e.rate_limits?.five_hour,ne=e.rate_limits?.seven_day,re=te?xb(te.used_percentage,te.resets_at,18e6,s):void 0,E=ne?xb(ne.used_percentage,ne.resets_at,6048e5,s):void 0,D=x?.session.cost,ie=w?.sessionDuration,ae=o(`burn`)&&D!=null&&ie!=null?Sb(D,ie):void 0,oe=v(g),se=oe===void 0?void 0:wb(oe),ce=oe===void 0?void 0:Tb(oe),le=se!==void 0||ce!==void 0?{...se,...ce!==void 0&&{history:ce}}:void 0,ue=Pb(process.env.HOME??process.env.USERPROFILE),de=e.workspace?{...e.workspace,current_dir:Pb(e.workspace.current_dir)??``,project_dir:Pb(e.workspace.project_dir)??``}:e.workspace,fe=x===void 0?void 0:Nb({cost:x.session.cost,tokens:x.session.tokens}),O=S===void 0?void 0:{cost:S.cost,tokens:S.tokens},pe=w===void 0?void 0:Nb({lastResponseTime:w.lastResponseTime,responseTime:w.responseTime,sessionDuration:w.sessionDuration,messageCount:w.messageCount,linesAdded:w.linesAdded,linesRemoved:w.linesRemoved});return{...e,...de!==void 0&&{workspace:de},...ue!==void 0&&{home:ue},...y.git!==void 0&&{git:y.git},...ee!==void 0&&{tmux:{session:ee}},host:b.host,theme:{effective:i.theme},look:{effective:i.look},preset:{effective:i.preset,customized:i.presetCustomized},style:{effective:i.style},charset:{effective:i.charset},colorCompatibility:{effective:i.colorCompatibility},autoWrap:{effective:i.autoWrap},padding:{effective:i.padding},...fe!==void 0&&{session:fe},...O!==void 0&&{today:O},...ae!==void 0&&{burn:{costPerHour:ae}},...le!==void 0&&{speed:le},...o(`block`)&&te!==void 0&&{block:{nativeUtilization:te.used_percentage,resetsAt:te.resets_at,...re!==void 0&&{etaMinutes:re}}},...ne!==void 0&&{weekly:{percentage:ne.used_percentage,resetsAt:ne.resets_at,...E!==void 0&&{etaMinutes:E}}},...T!==void 0&&{cache:{expiresAt:T}},...C!==void 0&&{context:{totalTokens:C.totalTokens,contextLeft:C.contextLeftPercentage}},...pe!==void 0&&{metrics:pe}}}function Nb(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 Pb(e){return e===void 0||e.length===0||c.sep!==`\\`?e:e.replace(/\\/g,`/`)}function Fb(e){if(e.kind===`absent`)return{failures:[]};if(e.kind===`failed`)return{failures:[e.reason]};let t=e.value,n=[],r=(e,t)=>{if(!(t===void 0||t.kind===`absent`)){if(t.kind===`failed`){n.push(`git.${e}: ${t.reason}`);return}return t.value}},i=r(`aheadBehind`,t.aheadBehind),a=r(`sha`,t.sha),o=r(`operation`,t.operation),s=r(`timeSinceCommit`,t.timeSinceCommit),c=r(`stash`,t.stashCount),l=r(`upstream`,t.upstream),u=r(`repoName`,t.repoName),d=r(`repoUrl`,t.repoUrl),f=t.pullRequest,p={};return f?.kind===`ok`?(p.prNumber=f.value.number,p.prState=f.value.state,p.prUrl=f.value.url):f?.kind===`failed`&&(n.push(`git.pr: ${f.reason}`),p.prError=f.reason),{git:{branch:t.branch,status:t.status,...i!==void 0&&{ahead:i.ahead,behind:i.behind},...t.workingTree!==void 0&&{staged:t.workingTree.staged,unstaged:t.workingTree.unstaged,untracked:t.workingTree.untracked,conflicts:t.workingTree.conflicts},...a!==void 0&&{sha:a},...o!==void 0&&{operation:o},...s!==void 0&&{timeSinceCommit:s},...c!==void 0&&{stash:c},...l!==void 0&&{upstream:l},...u!==void 0&&{repoName:u},...d!==void 0&&{repoUrl:d},...p},failures:n}}const Ib=`trimPrefix "/" (trimPrefix .project_dir .current_dir)`,Lb=`{{ \$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 (${Ib}) (basename .project_dir) (ne (${Ib}) "") }}{{ end }}{{ end }}{{ abbreviatePath \$dir }}`,Rb={branch:`primary`,staged:`success`,unstaged:`warning`,untracked:`accent`,conflicts:`error`,ahead:`success`,behind:`warning`,stash:`accent`},zb=(e,t)=>`{{ fg (color "${Rb[e]}") ${t} }}`,Bb=`{{ readableOn (mix (color "foreground") (bgOf) 60) (bgOf) 3 }}`,Vb=`{{ if or (gt .git.staged 0) (gt .git.unstaged 0) (gt .git.untracked 0) (gt .git.conflicts 0) }} ({{ \$first := true }}{{ if gt .git.staged 0 }}${zb(`staged`,`(printf "+%v" .git.staged)`)}{{ $first = false }}{{ end }}{{ if gt .git.unstaged 0 }}{{ if not $first }} {{ end }}${zb(`unstaged`,`(printf "~%v" .git.unstaged)`)}{{ $first = false }}{{ end }}{{ if gt .git.untracked 0 }}{{ if not $first }} {{ end }}${zb(`untracked`,`(printf "?%v" .git.untracked)`)}{{ $first = false }}{{ end }}{{ if gt .git.conflicts 0 }}{{ if not $first }} {{ end }}${zb(`conflicts`,`(printf "!%v" .git.conflicts)`)}{{ $first = false }}{{ end }}){{ end }}`,Hb=`{{ if ne .git.repoName "" }}{{ .git.repoName }} {{ end }}⎇ ${zb(`branch`,`.git.branch`)}{{ if .git.sha }} ♯ {{ .git.sha }}{{ end }}{{ if or (gt .git.ahead 0) (gt .git.behind 0) }} {{ if gt .git.ahead 0 }}${zb(`ahead`,`(printf "↑%v" .git.ahead)`)}{{ end }}{{ if gt .git.behind 0 }}${zb(`behind`,`(printf "↓%v" .git.behind)`)}{{ end }}{{ end }}`+Vb+`{{ if .git.upstream }} →{{ .git.upstream }}{{ end }}{{ if gt .git.stash 0 }} ${zb(`stash`,`(printf "⧇ %v" .git.stash)`)}{{ end }} {{ if eq .git.status "conflicts" }}{{ fg (color "error") "⚠" }}{{ else }}{{ if eq .git.status "dirty" }}{{ fg (color "warning") "●" }}{{ else }}{{ fg (color "success") "✓" }}{{ end }}{{ end }}`;function Ub(e,t){return`{{ if ge (round ${e}) ${t} }}error{{ else }}{{ if ge (round ${e}) 50 }}warning{{ else }}panel{{ end }}{{ end }}`}function Wb(e){return`{{ if ge (round ${e}) 50 }}button-color-foreground{{ else }}foreground{{ end }}`}function Gb(e,t,n){return`{{ if lt ${e} 0 }}panel{{ else }}{{ if lt ${e} ${n} }}error{{ else }}{{ if lt ${e} ${t} }}warning{{ else }}panel{{ end }}{{ end }}{{ end }}`}function Kb(e,t){return`{{ if lt ${e} 0 }}foreground{{ else }}{{ if lt ${e} ${t} }}button-color-foreground{{ else }}foreground{{ end }}{{ end }}`}const qb={globals:{palette:`tokyo-night`},variables:{current_dir:{kind:`input`,path:`workspace.current_dir`,default:`?`},project_dir:{kind:`input`,path:`workspace.project_dir`,default:``},transcript_path:{kind:`input`,path:`transcript_path`,default:``},"model.display_name":{kind:`input`,path:`model.display_name`,default:``},"session.id":{kind:`input`,path:`session_id`,default:``},version:{kind:`input`,path:`version`,default:``},"theme.effective":{kind:`input`,path:`theme.effective`,default:``},"look.effective":{kind:`input`,path:`look.effective`,default:``},"preset.effective":{kind:`input`,path:`preset.effective`,default:``},"preset.customized":{kind:`input`,path:`preset.customized`,type:`boolean`,default:!1},"style.effective":{kind:`input`,path:`style.effective`,default:``},"charset.effective":{kind:`input`,path:`charset.effective`,default:``},"colorCompatibility.effective":{kind:`input`,path:`colorCompatibility.effective`,default:``},"autoWrap.effective":{kind:`input`,path:`autoWrap.effective`,type:`boolean`,default:!0},"padding.effective":{kind:`input`,path:`padding.effective`,type:`number`,default:1},"term.cols":{kind:`input`,path:`term.cols`,type:`number`,default:80},"hue.step":{kind:`literal`,value:14},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.repoUrl":{kind:`input`,path:`git.repoUrl`,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.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.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},"session.budget.amount":{kind:`literal`,value:0},"session.budget.warningThreshold":{kind:`literal`,value:80},"today.cost":{kind:`input`,path:`today.cost`,type:`number`,default:0},"today.tokens":{kind:`input`,path:`today.tokens`,type:`number`,default:0},"today.budget.amount":{kind:`literal`,value:50},"today.budget.warningThreshold":{kind:`literal`,value:80},"block.nativeUtilization":{kind:`input`,path:`block.nativeUtilization`,type:`number`,default:0},"block.resetsAt":{kind:`input`,path:`block.resetsAt`,type:`number`,default:0},"block.budget.warningThreshold":{kind:`literal`,value:80},"weekly.percentage":{kind:`input`,path:`weekly.percentage`,type:`number`,default:0},"weekly.resetsAt":{kind:`input`,path:`weekly.resetsAt`,type:`number`,default:0},"weekly.budget.warningThreshold":{kind:`literal`,value:80},"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},"burn.eta.warnMinutes":{kind:`literal`,value:60},"burn.eta.errorMinutes":{kind:`literal`,value:30},"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},"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}},segments:{directory:{template:Lb,bg:`surface`,fg:`foreground`},model:{template:`✱ {{ formatModelName .model.display_name }}`,bg:`panel`,fg:`foreground`,when:`{{ ne .model.display_name "" }}`},sessionId:{template:`⌗{{ trunc 8 .session.id }}`,bg:`surface`,fg:`foreground`,when:`{{ ne .session.id "" }}`},version:{template:`◈ v{{ .version }}`,bg:`surface`,fg:`foreground`,when:`{{ ne .version "" }}`},tmux:{template:`tmux:{{ .tmux.session | default "none" }}`,bg:`surface-active`,fg:`foreground`,when:`{{ ne .tmux.session "" }}`},host:{template:`⇄ {{ .host.user | default "?" }}@{{ .host.name | default "?" }}`,bg:`warning`,fg:`{{ contrastOn (bgOf) }}`,when:`{{ .host.ssh }}`},git:{template:Hb,bg:`surface-active`,fg:Bb,when:`{{ ne .git.branch "" }}`},gitaculous:{template:`(git){{ if ne .git.repoName "" }} {{ .git.repoName }}{{ end }}{{ if ne .git.operation "" }} [{{ .git.operation }}]{{ end }}{{ if ne .git.sha "" }} {{ .git.sha }}{{ end }}{{ if or (gt .git.staged 0) (gt .git.unstaged 0) (gt .git.untracked 0) (gt .git.conflicts 0) }} {{ if gt .git.staged 0 }}${zb(`staged`,`"S"`)}{{ end }}{{ if gt .git.unstaged 0 }}${zb(`unstaged`,`"U"`)}{{ end }}{{ if gt .git.untracked 0 }}${zb(`untracked`,`"?"`)}{{ end }}{{ if gt .git.conflicts 0 }}${zb(`conflicts`,`(printf "!%v" .git.conflicts)`)}{{ end }}{{ end }} ⎇ ${zb(`branch`,`.git.branch`)}{{ if ne .git.upstream "" }} [{{ .git.upstream }}{{ if or (gt .git.ahead 0) (gt .git.behind 0) }} {{ if gt .git.ahead 0 }}${zb(`ahead`,`(printf "+%v" .git.ahead)`)}{{ end }}{{ if and (gt .git.ahead 0) (gt .git.behind 0) }}/{{ end }}{{ if gt .git.behind 0 }}${zb(`behind`,`(printf "-%v" .git.behind)`)}{{ end }}{{ end }}]{{ end }}{{ if gt .git.stash 0 }} ${zb(`stash`,`(printf "(%v stashed)" .git.stash)`)}{{ end }}{{ if gt .git.timeSinceCommit 0 }} ◷ {{ template "formatTimeSince" .git.timeSinceCommit }}{{ end }}`,bg:`surface-active`,fg:Bb,when:`{{ ne .git.branch "" }}`},gitPr:{template:`{{ if ne .git.prUrl "" }}{{ link .git.prUrl (printf "⇆ #%v" .git.prNumber) }}{{ else }}⚠ PR{{ end }}`,bg:`surface-active`,fg:`foreground`,when:`{{ or (ne .git.prUrl "") (ne .git.prError "") }}`},toolbar:{template:`{{ action "copySession" "⎘ id" }} {{ action "openProject" "↗ proj" }} {{ action "openTranscript" "↗ log" }}{{ if ne .git.repoUrl "" }} {{ link .git.repoUrl "↗ repo" }}{{ end }} {{ action "edit.toggle" "✎ edit" "✎ done" }}`,bg:`surface`,fg:`foreground`},session:{template:`§ {{ template "formatCost" .session.cost }} ({{ template "formatTokens" .session.tokens }}){{ template "budgetStatus" (dict "cost" .session.cost "budget" .session.budget.amount "warn" .session.budget.warningThreshold) }}`,bg:`surface`,fg:`foreground`},today:{template:`☉ {{ template "formatCost" .today.cost }} ({{ template "formatTokens" .today.tokens }}){{ template "budgetStatus" (dict "cost" .today.cost "budget" .today.budget.amount "warn" .today.budget.warningThreshold) }}`,bg:`surface`,fg:`foreground`},block:{template:`◱ {{ round .block.nativeUtilization }}% ({{ template "formatLongTimeRemaining" (minutesUntilReset .block.resetsAt) }})`,bg:Ub(`.block.nativeUtilization`,`.block.budget.warningThreshold`),fg:Wb(`.block.nativeUtilization`),when:`{{ gt .block.resetsAt 0 }}`},weekly:{template:`◑ {{ round .weekly.percentage }}% ({{ template "formatLongTimeRemaining" (minutesUntilReset .weekly.resetsAt) }})`,bg:Ub(`.weekly.percentage`,`.weekly.budget.warningThreshold`),fg:Wb(`.weekly.percentage`),when:`{{ gt .weekly.resetsAt 0 }}`},burnrate:{template:`⚡ {{ template "formatRate" .burn.costPerHour }} · {{ template "formatEta" .block.etaMinutes }} to 5h · {{ template "formatEta" .weekly.etaMinutes }} to wk`,bg:Gb(`.block.etaMinutes`,`.burn.eta.warnMinutes`,`.burn.eta.errorMinutes`),fg:Kb(`.block.etaMinutes`,`.burn.eta.warnMinutes`),when:`{{ or (gt .block.resetsAt 0) (gt .weekly.resetsAt 0) }}`},speed:{template:`⇅ out {{ template "formatSpeed" .speed.output }} · in {{ template "formatSpeed" .speed.input }} · tot {{ template "formatSpeed" .speed.total }}`,bg:`panel`,fg:`foreground`,when:`{{ gt .session.tokens 0 }}`},tokenSparkline:{template:`⚡ {{ sparkline .speed.history 24 }}`,bg:`panel`,fg:`foreground`,when:`{{ ne .speed.history "" }}`},cacheTimer:{template:`◴ {{ if le (minutesUntilReset .cache.expiresAt) 0 }}cold{{ else }}{{ minutesUntilReset .cache.expiresAt }}m{{ end }}`,bg:`surface`,fg:`{{ if le (minutesUntilReset .cache.expiresAt) 8 }}error{{ else }}{{ if le (minutesUntilReset .cache.expiresAt) 20 }}warning{{ else }}foreground{{ end }}{{ end }}`,when:`{{ gt .cache.expiresAt 0 }}`},context:{template:`◔ {{ formatInteger .context.totalTokens }} ({{ .context.contextLeft }}%)`,bg:`{{ if le .context.contextLeft 20 }}error{{ else }}{{ if le .context.contextLeft 40 }}warning{{ else }}surface-active{{ end }}{{ end }}`,fg:`{{ if le .context.contextLeft 40 }}button-color-foreground{{ else }}foreground{{ end }}`,when:`{{ gt .context.totalTokens 0 }}`},metrics:{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 }} `,bg:`panel`,fg:`foreground`,when:`{{ or .metrics.lastResponseTime .metrics.responseTime .metrics.sessionDuration .metrics.messageCount .metrics.linesAdded .metrics.linesRemoved }}`},charsetControl:{template:`{{ .charset.effective }} {{ menu "applyCharsetForever" "▸" "▾" }} {{ action "resetCharset" "↺" }}`,bg:`surface`,fg:`foreground`},colorCompatControl:{template:`{{ .colorCompatibility.effective }} {{ menu "applyColorCompatForever" "▸" "▾" }} {{ action "resetColorCompat" "↺" }}`,bg:`surface`,fg:`foreground`},directoryPaletteControl:{template:`🎨 directory {{ menu "applyDirectoryPaletteForever" "▸" "▾" }} {{ action "resetDirectoryPalette" "↺" }}`,bg:`surface`,fg:`foreground`}},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:`toolbar`},{kind:`group`,name:`settings`,label:`⚙ terminal`,direction:`horizontal`,children:[`charsetControl`,`colorCompatControl`,`directoryPaletteControl`]}]},{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`model`},{kind:`segment`,name:`context`},{kind:`segment`,name:`cacheTimer`},{kind:`segment`,name:`block`},{kind:`segment`,name:`weekly`}]}]},actions:{copySession:{copy:`{{ .session.id }}`},copyDir:{copy:`{{ .current_dir }}`},openProject:{open:`{{ .project_dir }}`},openTranscript:{open:`{{ .transcript_path }}`},applyCharsetForever:{persist:`charset`,from:`charsets`},resetCharset:{reset:`charset`},applyColorCompatForever:{persist:`colorCompatibility`,from:`colorCompatibilities`},resetColorCompat:{reset:`colorCompatibility`},applyDirectoryPaletteForever:{persist:`segments.directory.palette`,from:`themes`},resetDirectoryPalette:{reset:`segments.directory.palette`}},looks:{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}},presets:{default:{},compact:{root:{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`directory`},{kind:`segment`,name:`git`},{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:`segment`,name:`toolbar`}]},{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`model`},{kind:`segment`,name:`context`},{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`}]}]}}},editGlobals:{style:`plain`,default_separator:` | `},helpers:{formatCost:'{{ if lt . 0.01 }}<$0.01{{ else }}${{ printf "%.2f" . }}{{ end }}',formatTokenCount:`{{ if ge . 1000000 }}{{ printf "%.1f" (divf . 1000000) }}M{{ else if ge . 1000 }}{{ printf "%.1f" (divf . 1000) }}K{{ else }}{{ . }}{{ end }}`,formatTokens:`{{ template "formatTokenCount" . }} tokens`,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 }}`}},Jb=new Set([qb.globals.palette,...Object.values(qb.segments).map(e=>e.palette)].filter(e=>e!==void 0)),Yb=Wh(ub(`<default>`,JSON.stringify(qb),Jb),qb);function Xb(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 Zb(e){return typeof e==`string`?e:String(e)}function Qb(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 $b(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")`)}const ex=/^(?:(?:global|apac|au|eu|us|us-east-\d|us-west-\d|eu-west-\d|eu-central-\d)\.)?(?:anthropic\.|azure_ai\/|bedrock\/|vertex_ai\/)?claude-(?:(?<family>opus|sonnet|haiku)-(?<newMajor>\d+)(?:-(?<newMinor>\d))?|(?<oldMajor>\d+)(?:-(?<oldMinor>\d))?-(?<oldFamily>opus|sonnet|haiku))(?:[-@]\d{8})?(?:-v\d+:\d+)?(?:-latest)?$/i,tx=/^(?<family>opus|sonnet|haiku)\s+(?<major>\d+)(?:\.(?<minor>\d))?$/i;function nx(e){if(!e)return`Claude`;let t=e.trim().replace(/\s*\([^)]*\)\s*$/,``).replace(/\s*\[[^\]]*\]\s*$/,``).trim(),n=t.match(ex);if(n?.groups){let{family:e,newMajor:t,newMinor:r,oldMajor:i,oldMinor:a,oldFamily:o}=n.groups,s=e||o,c=t||i,l=r||a;if(s&&c)return`${s.charAt(0).toUpperCase()+s.slice(1).toLowerCase()} ${l?`${c}.${l}`:c}`}let r=t.match(tx);if(r?.groups){let e=r.groups.family,t=r.groups.major,n=r.groups.minor;return`${e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()} ${n?`${t}.${n}`:t}`}return t||e}function rx(e){let t=e.match(tx);if(!t?.groups)return e;let n=t.groups.family,r=t.groups.major,i=t.groups.minor;return`${n.charAt(0).toUpperCase()}${i?`${r}.${i}`:r}`}function ix(e){let t=e.split(`/`),n=t.length-1;return t.map((e,t)=>{if(t===n)return e;let r=e.match(/^\.*./);return r?r[0]:e}).join(`/`)}function ax(e){return e.toLocaleString()}const ox=[`▁`,`▂`,`▃`,`▄`,`▅`,`▆`,`▇`,`█`],sx=ox.length;function cx(e,t){let n=t===void 0?e:t<=0?[]:e.slice(-t);if(n.length===0)return``;let r=n[0],i=n[0];for(let e of n)e<r&&(r=e),e>i&&(i=e);let a=i-r,o=``;for(let e of n){let t=a===0?0:Math.round((e-r)/a*(sx-1));o+=ox[t]}return o}function lx(e){let t=[];for(let n of e.split(`,`)){let e=n.trim();if(e===``)continue;let r=Number(e);if(!Number.isFinite(r))throw TypeError(`sparkline: non-numeric series element ${JSON.stringify(n)}`);t.push(r)}return t}const ux=Sc(),dx=[...Ec];function fx(){return{basename:{fn:e=>l(e),argTypes:[`string`]},dirname:{fn:e=>u(e),argTypes:[`string`]},abbreviatePath:{fn:e=>ix(e),argTypes:[`string`]},int:{fn:e=>Qb(e),argTypes:[`value`]},string:{fn:e=>Zb(e),argTypes:[`value`]},bool:{fn:e=>$b(e),argTypes:[`value`]},urlEncode:{fn:e=>encodeURIComponent(e),argTypes:[`string`]},themes:{fn:()=>ux,argTypes:[]},styles:{fn:()=>dx,argTypes:[]},sparkline:{fn:(e,t)=>cx(lx(e),t),argTypes:[`string`,`int`]}}}function px(e=()=>new Date){return{minutesUntilReset:{fn:t=>Math.round(Math.max(0,t*1e3-e().getTime())/6e4),argTypes:[`int`]},formatInteger:{fn:e=>ax(e),argTypes:[`int`]},round:{fn:e=>Math.round(e),argTypes:[`float`]},formatModelName:{fn:e=>nx(e),argTypes:[`string`]},shortenModelName:{fn:e=>rx(e),argTypes:[`string`]}}}function mx(e,t=()=>new Date){return Ru({fromString:e=>new Ho(e),toString:e=>e.plain,clock:t,missingKey:`error`,funcs:{...kf(),...zm(),...hp(),...Lp(),...xf(t),...ud(),...Uf(),...gc(),...fx(),...px(t),...e??{}}})}function hx(e){return gx(e,new Set(e.names()),``)}function gx(e,t,n){return new Proxy(Object.create(null),{has(e,r){if(typeof r!=`string`)return!1;let i=n?`${n}.${r}`:r;if(t.has(i))return!0;let a=`${i}.`;for(let e of t)if(e.startsWith(a))return!0;return!1},get(r,i){if(typeof i!=`string`)return;let a=n?`${n}.${i}`:i;if(t.has(a))return e.read(a);let o=`${a}.`;for(let n of t)if(n.startsWith(o))return gx(e,t,a)}})}function _x(e,t){return t.kind!==`ttl`||t.durationMs>=500?t:(O(`declareShell "${e}": ttl ${t.durationMs}ms below floor 500ms; clamping`),{kind:`ttl`,durationMs:500})}function vx(e){let t=/^(\d+(?:\.\d+)?)(ms|s|m|h)$/.exec(e);if(!t)throw RangeError(`Invalid duration: "${e}"`);let n=parseFloat(t[1]);switch(t[2]){case`ms`:return n;case`s`:return n*1e3;case`m`:return n*6e4;case`h`:return n*36e5;default:throw RangeError(`Unexpected duration unit: "${t[2]}"`)}}async function yx(e){let t=await ye({bin:`/bin/sh`,args:[`-c`,e],category:`user-shell`});return t.ok?{stdout:t.stdout,exitCode:t.exitCode??0}:{stdout:t.stdout,exitCode:t.exitCode??1}}async function bx(e,t,n){let r;try{r=await T(e,`utf8`)}catch{return{error:`file unreadable: ${e}`}}if(n!==void 0){let t=new RegExp(n).exec(r);return t?.[1]?{content:t[1].replace(/\n/g,` `)}:{error:`regex no-match in "${e}"`}}return t===`first-line`?{content:(r.split(`
|
|
161
|
-
`)[0]??``).trim()}:{content:r.replace(/\n/g,` `).trim()}}const xx=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],Sx=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],Cx=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`],wx=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function Tx(e,t){let n=[[`2006`,e=>String(e.getFullYear())],[`January`,e=>xx[e.getMonth()]],[`Monday`,e=>Cx[e.getDay()]],[`Jan`,e=>Sx[e.getMonth()]],[`Mon`,e=>wx[e.getDay()]],[`15`,e=>String(e.getHours()).padStart(2,`0`)],[`06`,e=>String(e.getFullYear()%100).padStart(2,`0`)],[`01`,e=>String(e.getMonth()+1).padStart(2,`0`)],[`02`,e=>String(e.getDate()).padStart(2,`0`)],[`04`,e=>String(e.getMinutes()).padStart(2,`0`)],[`05`,e=>String(e.getSeconds()).padStart(2,`0`)],[`PM`,e=>e.getHours()<12?`AM`:`PM`],[`pm`,e=>e.getHours()<12?`am`:`pm`],[`1`,e=>String(e.getMonth()+1)],[`2`,e=>String(e.getDate())],[`3`,e=>String(e.getHours()%12||12)],[`4`,e=>String(e.getMinutes())],[`5`,e=>String(e.getSeconds())]],r=``,i=0;for(;i<e.length;){let a=!1;for(let[o,s]of n)if(e.startsWith(o,i)){r+=s(t),i+=o.length,a=!0;break}a||(r+=e[i],i++)}return r}const Ex={branch:`string`,sha:`string`,dirty:`boolean`,ahead:`number`,behind:`number`,stash:`number`};function Dx(e,t,n,r){if(e===null){if(n!==void 0)return n;let e=Ex[t];try{return jx(r,e)}catch{return Mx(e)}}switch(t){case`branch`:return e.branch===`detached`?``:e.branch;case`sha`:return Zn(e.sha,``);case`dirty`:return e.status!==`clean`;case`ahead`:return Zn(e.aheadBehind,{ahead:0,behind:0}).ahead;case`behind`:return Zn(e.aheadBehind,{ahead:0,behind:0}).behind;case`stash`:return Zn(e.stashCount,0)}}var Ox=class{watchers=new Map;subscribe(e,t){let n=this.watchers.get(e);if(!n){let t=new Set,r;try{r=s(e,()=>{for(let e of t)e()})}catch{return()=>{}}n={watcher:r,callbacks:t},this.watchers.set(e,n)}return n.callbacks.add(t),()=>this.unsubscribe(e,t)}unsubscribe(e,t){let n=this.watchers.get(e);n&&(n.callbacks.delete(t),n.callbacks.size===0&&(n.watcher.close(),this.watchers.delete(e)))}dispose(){for(let{watcher:e}of this.watchers.values())e.close();this.watchers.clear()}size(){return this.watchers.size}},kx=class{buckets=new Map;subscribe(e,t){let n=this.buckets.get(e);if(!n){let t=new Set;n={timer:D(()=>{for(let e of t)e()},e),callbacks:t},this.buckets.set(e,n)}return n.callbacks.add(t),()=>this.unsubscribe(e,t)}unsubscribe(e,t){let n=this.buckets.get(e);n&&(n.callbacks.delete(t),n.callbacks.size===0&&(E(n.timer),this.buckets.delete(e)))}dispose(){for(let{timer:e}of this.buckets.values())E(e);this.buckets.clear()}bucketCount(){return this.buckets.size}};function Ax(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n)return;n=n[e]}return n}function jx(e,t){if(typeof e!=`string`&&typeof e!=`number`&&typeof e!=`boolean`)throw TypeError(`Expected string|number|boolean from payload, got ${typeof e}`);return t===`string`?Zb(e):t===`number`?Qb(e):$b(e)}function Mx(e){return e===`number`?0:e===`boolean`?!1:``}var Nx=class{inputMetas=new Map;lastErrors=new Map;watchMgr=new Ox;ttlMgr=new kx;gitSubscriptions=new Map;cleanups=[];inFlight=new Set;engine=mx();gitProvider;ownsGitProvider;sessionState;constructor(e,t=``,n,r){this.store=e,this.defaultEmptyValue=t,n?(this.gitProvider=n,this.ownsGitProvider=!1):(this.gitProvider=new Or({sanityIntervalMs:0}),this.ownsGitProvider=!0),this.sessionState=r}get variableStore(){return this.store}declareLiteral(e,t){this.store.defineBox(e,Xb(t),t)}declareInput(e,t,n,r){let i=r===void 0?this.defaultFor(n):r;this.store.defineBox(e,n,i),this.inputMetas.set(e,{path:t,varDefault:r})}declareEnv(e,t,n){let r=process.env[t];if(r!==void 0){this.store.defineBox(e,`string`,r);return}let i=n===void 0?typeof this.defaultEmptyValue==`string`?this.defaultEmptyValue:``:n;this.store.defineBox(e,`string`,i),this.recordError(e,`env var "${t}" is not set`)}declareShell(e,t,n){let r=_x(e,n.cache);this.store.defineBox(e,`string`,this.stringInitial(n.varDefault));let i=()=>void this.updateFromShell(e,t,n.regex,n.varDefault);i(),this.registerCachePolicy(e,r,i)}declareFile(e,t,n){this.store.defineBox(e,`string`,this.stringInitial(n.varDefault));let r=()=>void this.updateFromFile(e,t,n.readMode,n.regex,n.varDefault);r(),this.registerCachePolicy(e,n.cache,r)}declareTemplate(e,t,n={}){let r=this.engine.parse(t);this.store.defineComputed(e,`string`,t=>{let i=hx(this.store);try{let t=r.evaluate(i).map(e=>e.plain).join(``);return this.lastErrors.delete(e),t}catch(t){return this.recordError(e,t instanceof Error?t.message:String(t)),this.stringInitial(n.varDefault)}}),this.store.read(e)}declareTime(e,t){let n=t.ttlMs??1e3;this.store.defineBox(e,`string`,(e=>{try{return Tx(t.format,e)}catch{return this.stringInitial(t.varDefault)}})(new Date));let r=this.ttlMgr.subscribe(n,()=>{try{this.store.setBox(e,Tx(t.format,new Date)),this.lastErrors.delete(e)}catch(n){this.applyFallback(e,`string`,t.varDefault,n instanceof Error?n.message:String(n))}});this.cleanups.push(r)}declareGit(e,t){let n=Ex[t.field],r=t.varDefault===void 0?Mx(n):jx(t.varDefault,n);this.store.defineBox(e,n,r);let i=this.gitSubscriptions.get(t.cwd);if(!i){let e=new Map;i={fieldSubs:e,unsubscribe:this.gitProvider.subscribe(t.cwd,t=>{this.store.runInAction(()=>{for(let[n,r]of e)for(let{name:e,varDefault:i}of r)this.store.setBox(e,Dx(t,n,i,this.defaultEmptyValue))})})},this.gitSubscriptions.set(t.cwd,i)}let a=i.fieldSubs.get(t.field);a||(a=[],i.fieldSubs.set(t.field,a)),a.push({name:e,varDefault:t.varDefault})}declareState(e,t){if(!this.sessionState)throw Error(`declareState("${e}"): SourceRegistry was constructed without a SessionState — state-kind variables require a SessionState (the daemon provides one; tests must supply one)`);let n=this.sessionState,r=t.varDefault??this.stringInitial(void 0);this.store.defineComputed(e,`string`,e=>{let i=e(`session.id`);if(typeof i!=`string`||!i)return r;let a=n.get(i,t.key);return a===null?r:a})}applyInput(e){this.store.runInAction(()=>{for(let[t,n]of this.inputMetas){let r=Ax(e,n.path),i=this.store.getType(t);if(r!==void 0)try{this.store.setBox(t,jx(r,i)),this.lastErrors.delete(t)}catch(e){this.applyFallback(t,i,n.varDefault,e instanceof Error?e.message:String(e))}else this.applyFallback(t,i,n.varDefault,`input path "${n.path}" not found in payload`)}})}getLastError(e){return this.lastErrors.get(e)}dispose(){for(let e of this.cleanups)e();this.cleanups.length=0;for(let e of this.gitSubscriptions.values())e.unsubscribe();this.gitSubscriptions.clear(),this.watchMgr.dispose(),this.ttlMgr.dispose(),this.ownsGitProvider&&this.gitProvider.close()}registerCachePolicy(e,t,n){switch(t.kind){case`never`:break;case`ttl`:{let e=this.ttlMgr.subscribe(t.durationMs,n);this.cleanups.push(e);break}case`watch_file`:{let e=this.watchMgr.subscribe(t.path,n);this.cleanups.push(e);break}case`key`:{let e=this.engine.parse(t.template),r=(0,q.reaction)(()=>{let t=hx(this.store);try{return e.evaluate(t).map(e=>e.plain).join(``)}catch{return``}},n);this.cleanups.push(r);break}case`depends_on`:{let e=(0,q.reaction)(()=>t.varNames.map(e=>String(this.store.read(e))).join(`,`),n);this.cleanups.push(e);break}}}async updateFromShell(e,t,n,r){if(!this.inFlight.has(e)){this.inFlight.add(e);try{let{stdout:i,exitCode:a}=await yx(t);if(a!==0){this.applyFallback(e,`string`,r,`shell "${t}" exited with code ${a}`);return}if(n!==void 0){let a=new RegExp(n).exec(i);if(!a?.[1]){this.applyFallback(e,`string`,r,`regex no-match in output of "${t}"`);return}this.store.setBox(e,a[1].replace(/\n/g,` `))}else this.store.setBox(e,i.replace(/\n/g,` `).trim());this.lastErrors.delete(e)}finally{this.inFlight.delete(e)}}}async updateFromFile(e,t,n,r,i){if(!this.inFlight.has(e)){this.inFlight.add(e);try{let a=await bx(t,n,r);if(a.error!==void 0){this.applyFallback(e,`string`,i,a.error);return}this.store.setBox(e,a.content??``),this.lastErrors.delete(e)}finally{this.inFlight.delete(e)}}}applyFallback(e,t,n,r){if(this.recordError(e,r),n!==void 0){this.store.setBox(e,n);return}try{this.store.setBox(e,jx(this.defaultEmptyValue,t))}catch{this.store.setBox(e,Mx(t))}}defaultFor(e){try{return jx(this.defaultEmptyValue,e)}catch{return Mx(e)}}stringInitial(e){return e===void 0?typeof this.defaultEmptyValue==`string`?this.defaultEmptyValue:``:e}recordError(e,t){this.lastErrors.set(e,{timestamp:Date.now(),message:t})}};const Px=new Map,Fx=new Map;function Ix(e){let t=vc(e),n=Px.get(t);if(n!==void 0)return n;let r=ao(t);if(r===null)throw Error(`Palette "${e}" (resolved "${t}") did not resolve in the theme registry — allowed names and the registry are inconsistent`);return Px.set(t,r),r}function Lx(e,t){let n=`${e.name} ${t.hueShift} ${t.chromaScale} ${t.lightnessScale} ${t.lightnessShift}`,r=Fx.get(n);if(r!==void 0)return r;let i=vo(e,t);return Fx.set(n,i),i}function Rx(e,t){let n=[],r=[],i=()=>{if(!r.length)return;let e=zx(r,t);e.plain.length>0&&n.push(e),r=[]};for(let a of e)if(a.style.link){i();let e=zx([a],t);e.plain.length>0&&n.push(e)}else r.push(a);return i(),n}function zx(e,t){let n=t!==void 0&&!t.isNull?e.map(e=>Bx(e,t)):e,r=Ho.fromFragments(n);return r.end=``,r.noWrap=!0,n.length===1?r.style=n[0].style:t!==void 0&&!t.isNull&&(r.style=t),r}function Bx(e,t){let n=e.copy();return n.style=t.add(e.style),n}function Vx(e,t){return e===void 0?!0:e.evaluate(t).map(e=>e.plain).join(``)!==`false`}function Hx(e,t){let n=Ho.fromFragments(e);return n.end=``,n.noWrap=!0,t!==void 0&&!t.isNull&&(n.style=t),n}function Ux(e,t){let{width:n,justify:r,truncate:i,truncateMarker:a=`…`,baseStyle:o,padding:s}=t;if(e.length===0)return[];let c=Hx(e,o).pad(s);return n===`auto`||(c.cellLength>n?c.truncate(n,{mode:i,marker:a}):c.cellLength<n&&c.align(r,n)),[c]}var Wx=class extends Error{constructor(e,t,n){super(`Invalid ${t} color ${JSON.stringify(e)}: ${n}`),this.name=`ColorSpecError`}};function Gx(e,t,n,r,i,a){let o={segName:t,palette:n,bg:void 0};e.current=o;let s=Kx(r,a),c=s===void 0?void 0:qx(n,s,`bg`);o.bg=c;let l=Kx(i,a),u=l===void 0?void 0:qx(n,l,`fg`);return new G({bgcolor:c===void 0?void 0:ua.fromRgba(c),color:u===void 0?void 0:ua.fromRgba(u)})}function Kx(e,t){if(e!==void 0)return e.evaluate(t).map(e=>e.plain).join(``)}function qx(e,t,n){try{return za(e,t)}catch(e){throw e instanceof Ia?new Wx(t,n,e.message):e}}const Jx=new Map([[`palette`,`theme.effective`],[`preset`,`preset.effective`],[`look`,`look.effective`],[`style`,`style.effective`],[`charset`,`charset.effective`],[`colorCompatibility`,`colorCompatibility.effective`],[`autoWrap`,`autoWrap.effective`],[`padding`,`padding.effective`]]);function Yx(e,t,n,r){let i=new Map;for(let[a,o]of Object.entries(t))i.set(a,Xx(e,a,o,n,r));return i}function Xx(e,t,n,r,i){if(jv(n)){let[a,o]=Mv(n);return Zx(r.get(n.persistWhen)??n.persistWhen,n.set,Xx(e,t,a,r,i),Xx(e,t,o,r,i))}if(`set`in n){let e=r.get(n.set)??n.set;return`to`in n?{kind:`set-literal`,key:n.set,value:n.to,stateVar:e}:`from`in n?{kind:`set-option`,key:n.set,stateVar:e,options:[...Ny(n.from,i)]}:`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=Jx.get(n.persist)??n.persist;return`to`in n?{kind:`persist-literal`,key:n.persist,value:n.to,stateVar:e}:`from`in n?{kind:`persist-option`,key:n.persist,stateVar:e,options:[...Ny(n.from,i)]}:`cycle`in n?{kind:`persist-cycle`,key:n.persist,stateVar:e,members:n.cycle}:`removeSegment`in n?{kind:`layout-op`,key:n.persist,op:{op:`remove`,target:n.removeSegment}}:`insertSegment`in n?{kind:`layout-op`,key:n.persist,op:{op:`insert`,segment:n.insertSegment,anchor:n.anchor,relation:n.relation}}:`insertSegmentFrom`in n?{kind:`layout-op-option`,key:n.persist,anchor:n.anchor,relation:n.relation,options:[...Ny(n.insertSegmentFrom,i)]}:{kind:`persist-bounded`,key:n.persist,by:n.by}}return`copy`in n?{kind:`copy`,text:$x(e,n.copy,t)}:`open`in n?{kind:`open`,target:$x(e,n.open,t)}:`reset`in n?{kind:`reset`,key:n.reset}:`undo`in n?{kind:`undo`}:{kind:`redo`}}function Zx(e,t,n,r){return{kind:`dual`,selector:e,session:`stateVar`in n&&`stateVar`in r?{...n,stateVar:r.stateVar}:n,durable:r,sessionKey:t}}function Qx(e,t){return e.kind===`dual`?Fc(eS(t,e.selector))===!0?e.durable:e.session:e}function $x(e,t,n){try{return e(t)}catch(e){throw Error(`Template parse error in actions.${n}: ${e.message}`,{cause:e})}}function eS(e,t){return e.has(t)?Zb(e.read(t)):``}function tS(e,t){return e.evaluate(t).map(e=>e.plain).join(``)}function nS(e,t,n){let r=new Ho(e,{style:new G({link:t,bold:n})});return r.noWrap=!0,r.end=``,r}function rS(e,t){return Math.max(e.members.indexOf(eS(t,e.stateVar)),0)}function iS(e,t,n,r,i){switch(e.kind){case`set-literal`:{let t=eS(r,e.stateVar);return{effects:[{verb:Pt,args:[i,e.key,e.value]}],active:t===e.value}}case`set-option`:{let a=n??t,o=eS(r,e.stateVar);return{effects:[{verb:Pt,args:[i,e.key,a]}],active:o===a}}case`set-int`:{let a=n??t,o=eS(r,e.stateVar);return{effects:[{verb:Pt,args:[i,e.key,a]}],active:o===a}}case`set-cycle`:{let t=e.members[(rS(e,r)+1)%e.members.length];return{effects:[{verb:Pt,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:Ft,args:[tS(e.text,hx(r))]}],active:!1};case`open`:return{effects:[{verb:It,args:[tS(e.target,hx(r))]}],active:!1};case`persist-literal`:{let t=eS(r,e.stateVar);return{effects:[{verb:zt,args:[i,e.key,e.value]}],active:t===e.value}}case`persist-option`:{let a=n??t,o=eS(r,e.stateVar);return{effects:[{verb:zt,args:[i,e.key,a]}],active:o===a}}case`persist-cycle`:{let t=e.members[(rS(e,r)+1)%e.members.length];return{effects:[{verb:zt,args:[i,e.key,t]}],active:!1}}case`persist-bounded`:return{effects:[{verb:Bt,args:[i,e.key,String(e.by)]}],active:!1};case`reset`:return{effects:[{verb:Vt,args:[i,e.key]}],active:!1};case`undo`:return{effects:[{verb:Ut,args:[i]}],active:!1};case`redo`:return{effects:[{verb:Wt,args:[i]}],active:!1};case`layout-op`:return{effects:[{verb:Ht,args:[i,e.key,zc(e.op)]}],active:!1};case`dual`:{let a=Qx(e,r),{effects:o,active:s}=iS(a,t,n,r,i);return a===e.durable?{effects:o.map(t=>({...t,args:[...t.args,e.sessionKey]})),active:s}:{effects:o,active:s}}case`layout-op-option`:{let r={op:`insert`,segment:n??t,anchor:e.anchor,relation:e.relation};return{effects:[{verb:Ht,args:[i,e.key,zc(r)]}],active:!1}}}}function aS(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:Qt(`action "${e}"`,n,t.members.length,rS(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]}}function oS(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}=aS(e,Qx(r,i),t,i),{effects:s,active:c}=iS(r,a,o,i,eS(i,`session.id`));return nS(a,qt(s),c)}function sS(e){return{action:{fn:(t,...n)=>oS(t,n,e),argTypes:[`string`,`string`],returnType:`T`}}}function cS(e){return new Ho(e).cellLength}function lS(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 uS(e,t){let n=[];for(let t of e)n.length>0&&n.push(new Ho(` `)),n.push(t);let r=Ho.fromFragments(n);return r.noWrap=t,r.end=``,r}function dS(e,t,n,r){let i=e.compiled.get(t);if(!i||i.kind!==n)throw Error(`picker references action "${t}" which must be ${r}, got ${i?`a ${i.kind} action`:`no such action`}`);return i}function fS(e,t){let n=e.compiled.get(t),r=n&&Qx(n,e.store);if(!r||r.kind!==`set-option`&&r.kind!==`persist-option`&&r.kind!==`layout-op-option`)throw Error(`picker 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 ${r?`a ${r.kind} action`:`no such action`}`);return r}function pS(e,t,n,r,i,a){let o=fS(a,e),s=a.compiled.get(e),c=a.store,l=eS(c,`session.id`),u=`stateVar`in o?eS(c,o.stateVar):void 0,d=o.options.map(cS),f=i?Math.max(1,Qb(c.read(`term.cols`))-rh(a.stripStyle)-2*a.padding):1/0,p=cS(`✕`)+1,m=cS(`←`)+1+cS(`→`)+1,h=lS(d,f,p),g=h.length>1?lS(d,f,p+m):h,_=parseInt(eS(c,t.stateVar),10),v=Number.isInteger(_)?Math.max(0,Math.min(_,g.length-1)):0,y=g[v]??[],b=e=>qt([{verb:Pt,args:[l,t.key,String(e)]}]),x=n.flatMap(([e,t])=>[e,t]),S=qt([{verb:Pt,args:[l,...x]}]),C=r?[{verb:Pt,args:[l,...x]}]:[],w=e=>{let{effects:t}=iS(s,e,e,c,l),n=t.length===1?t[0]:void 0;return n?.verb===`set-state`?qt([{verb:Pt,args:[...n.args,...r?x:[]]}]):qt([...t,...C])},ee=[nS(`✕`,S,!1)];v>0&&ee.push(nS(`←`,b(v-1),!1));for(let e of y){let t=o.options[e];ee.push(nS(t,w(t),t===u))}return v<g.length-1&&ee.push(nS(`→`,b(v+1),!1)),uS(ee,i)}function mS(e){return{picker:{fn:(t,n,r,i)=>{let a=dS(e,n,`set-int`,`an int action ({ set, int: true })`);return pS(t,{key:a.key,stateVar:a.stateVar},[[a.key,`-1`]],r===!0,i===!0,e)},argTypes:[`string`,`string`,`bool`,`bool`],returnType:`T`}}}const hS=Symbol(`cc-candybar.menuDrop`);function gS(e){return e.flatMap(e=>e[hS]??[])}function _S(e,t,n,r){let i=r.activeSegment.current;if(i===null)throw Error(`{{ menu }} rendered with no active segment placement — the render walk must publish one before evaluating a segment template`);let a=r.action,o=f_(i.segName,e,n.key),s=m_(o),c=d_(e),l=eS(a.store,o)===c,u=eS(a.store,`session.id`),d=l?Xt:c,f=nS(Qt(`{{ menu "${e}" }}`,t,2,+!!l),qt([{verb:Pt,args:[u,o,d,s,`0`]}]),!1);return f[hS]=l?[pS(e,{key:s,stateVar:s},[[o,Xt],[s,`0`]],n.closeOnPick,n.paged,a)]:[],f}const vS=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function yS(e,t){let n=t[t.length-1],r=vS(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:h_(r??{})}}function bS(e){return{menu:{fn:(t,...n)=>{let{displays:r,options:i}=yS(t,n);return _S(t,r,i,e)},argTypes:[`string`,`value`],returnType:`T`}}}function xS(){return{current:null}}function SS(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 CS(e){let t={fn:(()=>{let t=SS(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:[],returnType:`string`};return{...hc(()=>SS(e,`color`).palette),bgOf:t}}function wS(e){let t=[],n=[];for(let r of e){if(!r.contains(`
|
|
159
|
+
Single-row example: root: { h: ["seg1", "seg2"] }`,line:X(e.source,[`layout`])}),t.root!==void 0&&(n.root=n_(e,`root`,t.root)),t.actions!==void 0&&(n.actions=Hv(e,t.actions)),t.looks!==void 0&&(n.looks=ky(e,t.looks)),t.presets!==void 0&&(n.presets=jy(e,t.presets)),t.editGlobals!==void 0&&(n.editGlobals=ag(e,`editGlobals`,t.editGlobals)),t.helpers!==void 0&&(n.helpers=My(e,t.helpers)),f_(e,n),k_(e,n),rh(e,n),Jm(e,n,B_,`the global settings menu`),n}const _b=new Set([`globals`,`variables`,`segments`,`layout`,`root`,`actions`,`looks`,`presets`,`editGlobals`,`helpers`]),vb=/"(?:cache_read_input_tokens|cache_creation_input_tokens)":[1-9]/;function yb(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 bb(e){let t=await xb(e);return t.kind===`ok`?z(Math.floor((t.value+36e5)/1e3)):t}async function xb(e){for(let t of[65536,1048576]){let n=await zr(e,t);if(n.kind!==`ok`)return n;let r=Sb(n.value.buf,n.value.fromStart);if(r!=null)return z(r);if(n.value.fromStart)return B}return B}function Sb(e,t){let n=e.toString(`utf8`).split(`
|
|
160
|
+
`),r=+!t;for(let e=n.length-1;e>=r;e--){let t=n[e];if(!t||!vb.test(t))continue;let r=yb(t);if(r!=null)return r}return null}function Cb(e,t,n){let r=Yc(t(`preset`),e.globals.preset,e.presets),i=Qc(e,r),a=t(`edit.mode`)===`open`?e.editGlobals:{};return{preset:r,presetCustomized:n(r),theme:bc(a.palette,t(`theme`),i.palette),look:wc(a.look,t(`look`),i.look,e.looks),style:Oc(a.style,t(`style`),i.style),separator:a.default_separator??i.default_separator,autoWrap:Lc(a.autoWrap,t(`autoWrap`),i.autoWrap),padding:Rc(a.padding,t(`padding`),i.padding),charset:a.charset??i.charset??`unicode`,colorCompatibility:a.colorCompatibility??i.colorCompatibility??`truecolor`}}const wb=10*1e3;function Tb(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 Eb(e,t){if(!(t<60))return e*3600/t}function Db(e,t,n,r){let i=r-t;if(i<50||i>wb)return;let a=n-e;if(!(a<=0))return a*1e3/i}function Ob(e){let{prev:t,cur:n}=e;if(t===void 0)return;let r=Db(t.input,t.atMs,n.input,n.atMs),i=Db(t.output,t.atMs,n.output,n.atMs),a=Db(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 kb(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>wb)continue;let o=Db(r.total,r.atMs,i.total,i.atMs);n.push(o??0)}if(n.length!==0)return n.join(`,`)}function Ab(e){let t=e.indexOf(`.`);return t<0?e:e.slice(0,t)}function jb(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`,()=>Ab(f.hostname())),i=n(`user`,()=>f.userInfo().username);return{host:{...r!==void 0&&{name:r},...i!==void 0&&{user:i},...e.ssh!==void 0&&{ssh:e.ssh}},failures:t}}function Mb(e){let t=new Map;for(let[n,r]of Object.entries(e.variables))t.set(n,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}`,i);let n=[],r=new Set;for(let t of uh(e.root)){if(t.when)for(let e of Vy(t.when))n.push(e);if(t.kind!==`segment`)continue;let r=e.segments[t.name];if(r){for(let e of[r.template,r.when,r.bg,r.fg])if(e)for(let t of Vy(e))n.push(t)}}let i=new Set;for(;n.length>0;){let e=n.pop();for(let a of Nb(t,e)){if(r.has(a))continue;r.add(a);let e=t.get(a);if(e){if(e.kind===`input`)i.add(e.path);else if(e.kind===`template`)for(let t of Vy(e.template))n.push(t)}}}return i}function Nb(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 Pb(e,t){for(let n of e)if(n===t||n.startsWith(t+`.`))return!0;return!1}function Fb(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`)&&{showUpstream:!0},...t(`git.repoName`)&&{showRepoName:!0},...t(`git.repoUrl`)&&{showRepoUrl:!0},...t(`git.operation`)&&{showOperation:!0},...t(`git.timeSinceCommit`)&&{showTimeSinceCommit:!0},...(t(`git.prNumber`)||t(`git.prState`)||t(`git.prUrl`)||t(`git.prError`))&&{showPullRequest:!0}}}async function Ib(e,t,n,r,i,a){let o=e=>Pb(r,e),s=(t.clock??(()=>new Date))().getTime(),c=(e,t,n)=>t?n().catch(t=>Xn(`${e}: ${String(t)}`)):Promise.resolve(B),[l,u,d,f,p,m,h,g]=await Promise.all([c(`git`,o(`git`),()=>t.gitProvider.getGitInfo(n??e.workspace?.current_dir,Fb(r),e.workspace?.project_dir)),c(`session`,o(`session.cost`)||o(`session.tokens`)||o(`burn`),()=>t.usageStore.getUsageInfo(e.session_id,e)),c(`today`,o(`today`),()=>t.usageStore.getTodayInfo(e)),c(`context`,o(`context`),()=>t.contextProvider.getContextInfo(e)),c(`metrics`,o(`metrics`)||o(`burn`),()=>t.metricsProvider.getMetricsInfo(e.session_id,e)),c(`tmux`,o(`tmux`),()=>t.tmuxService.getSessionId()),c(`cache`,o(`cache`),()=>bb(e.transcript_path)),c(`speed`,o(`speed`),()=>t.usageStore.observeSpeed(e.session_id,e.transcript_path,s))]),_=[],v=e=>{if(e.kind===`failed`){_.push(e.reason);return}return e.kind===`ok`?e.value:void 0},y=zb(l);_.push(...y.failures);let b=jb(a);_.push(...b.failures);let x=v(u),S=v(d),C=v(f),w=v(p),ee=v(m),T=v(h);for(let e of _)t.log(`warn`,`provider fetch failed: ${e}`);let te=e.rate_limits?.five_hour,ne=e.rate_limits?.seven_day,re=te?Tb(te.used_percentage,te.resets_at,18e6,s):void 0,E=ne?Tb(ne.used_percentage,ne.resets_at,6048e5,s):void 0,D=x?.session.cost,ie=w?.sessionDuration,ae=o(`burn`)&&D!=null&&ie!=null?Eb(D,ie):void 0,oe=v(g),se=oe===void 0?void 0:Ob(oe),ce=oe===void 0?void 0:kb(oe),le=se!==void 0||ce!==void 0?{...se,...ce!==void 0&&{history:ce}}:void 0,ue=Rb(process.env.HOME??process.env.USERPROFILE),de=e.workspace?{...e.workspace,current_dir:Rb(e.workspace.current_dir)??``,project_dir:Rb(e.workspace.project_dir)??``}:e.workspace,fe=x===void 0?void 0:Lb({cost:x.session.cost,tokens:x.session.tokens}),O=S===void 0?void 0:{cost:S.cost,tokens:S.tokens},pe=w===void 0?void 0:Lb({lastResponseTime:w.lastResponseTime,responseTime:w.responseTime,sessionDuration:w.sessionDuration,messageCount:w.messageCount,linesAdded:w.linesAdded,linesRemoved:w.linesRemoved});return{...e,...de!==void 0&&{workspace:de},...ue!==void 0&&{home:ue},...y.git!==void 0&&{git:y.git},...ee!==void 0&&{tmux:{session:ee}},host:b.host,theme:{effective:i.theme},look:{effective:i.look},preset:{effective:i.preset,customized:i.presetCustomized},style:{effective:i.style},charset:{effective:i.charset},colorCompatibility:{effective:i.colorCompatibility},autoWrap:{effective:i.autoWrap},padding:{effective:i.padding},...fe!==void 0&&{session:fe},...O!==void 0&&{today:O},...ae!==void 0&&{burn:{costPerHour:ae}},...le!==void 0&&{speed:le},...o(`block`)&&te!==void 0&&{block:{nativeUtilization:te.used_percentage,resetsAt:te.resets_at,...re!==void 0&&{etaMinutes:re}}},...ne!==void 0&&{weekly:{percentage:ne.used_percentage,resetsAt:ne.resets_at,...E!==void 0&&{etaMinutes:E}}},...T!==void 0&&{cache:{expiresAt:T}},...C!==void 0&&{context:{totalTokens:C.totalTokens,contextLeft:C.contextLeftPercentage}},...pe!==void 0&&{metrics:pe}}}function Lb(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 Rb(e){return e===void 0||e.length===0||c.sep!==`\\`?e:e.replace(/\\/g,`/`)}function zb(e){if(e.kind===`absent`)return{failures:[]};if(e.kind===`failed`)return{failures:[e.reason]};let t=e.value,n=[],r=(e,t)=>{if(!(t===void 0||t.kind===`absent`)){if(t.kind===`failed`){n.push(`git.${e}: ${t.reason}`);return}return t.value}},i=r(`aheadBehind`,t.aheadBehind),a=r(`sha`,t.sha),o=r(`operation`,t.operation),s=r(`timeSinceCommit`,t.timeSinceCommit),c=r(`stash`,t.stashCount),l=r(`upstream`,t.upstream),u=r(`repoName`,t.repoName),d=r(`repoUrl`,t.repoUrl),f=t.pullRequest,p={};return f?.kind===`ok`?(p.prNumber=f.value.number,p.prState=f.value.state,p.prUrl=f.value.url):f?.kind===`failed`&&(n.push(`git.pr: ${f.reason}`),p.prError=f.reason),{git:{branch:t.branch,status:t.status,...i!==void 0&&{ahead:i.ahead,behind:i.behind},...t.workingTree!==void 0&&{staged:t.workingTree.staged,unstaged:t.workingTree.unstaged,untracked:t.workingTree.untracked,conflicts:t.workingTree.conflicts},...a!==void 0&&{sha:a},...o!==void 0&&{operation:o},...s!==void 0&&{timeSinceCommit:s},...c!==void 0&&{stash:c},...l!==void 0&&{upstream:l},...u!==void 0&&{repoName:u},...d!==void 0&&{repoUrl:d},...p},failures:n}}const Bb=`trimPrefix "/" (trimPrefix .project_dir .current_dir)`,Vb=`{{ \$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 (${Bb}) (basename .project_dir) (ne (${Bb}) "") }}{{ end }}{{ end }}{{ abbreviatePath \$dir }}`,Hb={branch:`primary`,staged:`success`,unstaged:`warning`,untracked:`accent`,conflicts:`error`,ahead:`success`,behind:`warning`,stash:`accent`},Ub=(e,t)=>`{{ fg (color "${Hb[e]}") ${t} }}`,Wb=`{{ readableOn (mix (color "foreground") (bgOf) 60) (bgOf) 3 }}`,Gb=`{{ if or (gt .git.staged 0) (gt .git.unstaged 0) (gt .git.untracked 0) (gt .git.conflicts 0) }} ({{ \$first := true }}{{ if gt .git.staged 0 }}${Ub(`staged`,`(printf "+%v" .git.staged)`)}{{ $first = false }}{{ end }}{{ if gt .git.unstaged 0 }}{{ if not $first }} {{ end }}${Ub(`unstaged`,`(printf "~%v" .git.unstaged)`)}{{ $first = false }}{{ end }}{{ if gt .git.untracked 0 }}{{ if not $first }} {{ end }}${Ub(`untracked`,`(printf "?%v" .git.untracked)`)}{{ $first = false }}{{ end }}{{ if gt .git.conflicts 0 }}{{ if not $first }} {{ end }}${Ub(`conflicts`,`(printf "!%v" .git.conflicts)`)}{{ $first = false }}{{ end }}){{ end }}`,Kb=`{{ if ne .git.repoName "" }}{{ .git.repoName }} {{ end }}⎇ ${Ub(`branch`,`.git.branch`)}{{ if .git.sha }} ♯ {{ .git.sha }}{{ end }}{{ if or (gt .git.ahead 0) (gt .git.behind 0) }} {{ if gt .git.ahead 0 }}${Ub(`ahead`,`(printf "↑%v" .git.ahead)`)}{{ end }}{{ if gt .git.behind 0 }}${Ub(`behind`,`(printf "↓%v" .git.behind)`)}{{ end }}{{ end }}`+Gb+`{{ if .git.upstream }} →{{ .git.upstream }}{{ end }}{{ if gt .git.stash 0 }} ${Ub(`stash`,`(printf "⧇ %v" .git.stash)`)}{{ end }} {{ if eq .git.status "conflicts" }}{{ fg (color "error") "⚠" }}{{ else }}{{ if eq .git.status "dirty" }}{{ fg (color "warning") "●" }}{{ else }}{{ fg (color "success") "✓" }}{{ end }}{{ end }}`;function qb(e,t){return`{{ if ge (round ${e}) ${t} }}error{{ else }}{{ if ge (round ${e}) 50 }}warning{{ else }}panel{{ end }}{{ end }}`}function Jb(e){return`{{ if ge (round ${e}) 50 }}button-color-foreground{{ else }}foreground{{ end }}`}function Yb(e,t,n){return`{{ if lt ${e} 0 }}panel{{ else }}{{ if lt ${e} ${n} }}error{{ else }}{{ if lt ${e} ${t} }}warning{{ else }}panel{{ end }}{{ end }}{{ end }}`}function Xb(e,t){return`{{ if lt ${e} 0 }}foreground{{ else }}{{ if lt ${e} ${t} }}button-color-foreground{{ else }}foreground{{ end }}{{ end }}`}const Zb={globals:{palette:`tokyo-night`},variables:{current_dir:{kind:`input`,path:`workspace.current_dir`,default:`?`},project_dir:{kind:`input`,path:`workspace.project_dir`,default:``},transcript_path:{kind:`input`,path:`transcript_path`,default:``},"model.display_name":{kind:`input`,path:`model.display_name`,default:``},"session.id":{kind:`input`,path:`session_id`,default:``},version:{kind:`input`,path:`version`,default:``},"theme.effective":{kind:`input`,path:`theme.effective`,default:``},"look.effective":{kind:`input`,path:`look.effective`,default:``},"preset.effective":{kind:`input`,path:`preset.effective`,default:``},"preset.customized":{kind:`input`,path:`preset.customized`,type:`boolean`,default:!1},"style.effective":{kind:`input`,path:`style.effective`,default:``},"charset.effective":{kind:`input`,path:`charset.effective`,default:``},"colorCompatibility.effective":{kind:`input`,path:`colorCompatibility.effective`,default:``},"autoWrap.effective":{kind:`input`,path:`autoWrap.effective`,type:`boolean`,default:!0},"padding.effective":{kind:`input`,path:`padding.effective`,type:`number`,default:1},"term.cols":{kind:`input`,path:`term.cols`,type:`number`,default:80},"hue.step":{kind:`literal`,value:14},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.repoUrl":{kind:`input`,path:`git.repoUrl`,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.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.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},"session.budget.amount":{kind:`literal`,value:0},"session.budget.warningThreshold":{kind:`literal`,value:80},"today.cost":{kind:`input`,path:`today.cost`,type:`number`,default:0},"today.tokens":{kind:`input`,path:`today.tokens`,type:`number`,default:0},"today.budget.amount":{kind:`literal`,value:50},"today.budget.warningThreshold":{kind:`literal`,value:80},"block.nativeUtilization":{kind:`input`,path:`block.nativeUtilization`,type:`number`,default:0},"block.resetsAt":{kind:`input`,path:`block.resetsAt`,type:`number`,default:0},"block.budget.warningThreshold":{kind:`literal`,value:80},"weekly.percentage":{kind:`input`,path:`weekly.percentage`,type:`number`,default:0},"weekly.resetsAt":{kind:`input`,path:`weekly.resetsAt`,type:`number`,default:0},"weekly.budget.warningThreshold":{kind:`literal`,value:80},"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},"burn.eta.warnMinutes":{kind:`literal`,value:60},"burn.eta.errorMinutes":{kind:`literal`,value:30},"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},"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}},segments:{directory:{template:Vb,bg:`surface`,fg:`foreground`},model:{template:`✱ {{ formatModelName .model.display_name }}`,bg:`panel`,fg:`foreground`,when:`{{ ne .model.display_name "" }}`},sessionId:{template:`⌗{{ trunc 8 .session.id }}`,bg:`surface`,fg:`foreground`,when:`{{ ne .session.id "" }}`},version:{template:`◈ v{{ .version }}`,bg:`surface`,fg:`foreground`,when:`{{ ne .version "" }}`},tmux:{template:`tmux:{{ .tmux.session | default "none" }}`,bg:`surface-active`,fg:`foreground`,when:`{{ ne .tmux.session "" }}`},host:{template:`⇄ {{ .host.user | default "?" }}@{{ .host.name | default "?" }}`,bg:`warning`,fg:`{{ contrastOn (bgOf) }}`,when:`{{ .host.ssh }}`},git:{template:Kb,bg:`surface-active`,fg:Wb,when:`{{ ne .git.branch "" }}`},gitaculous:{template:`(git){{ if ne .git.repoName "" }} {{ .git.repoName }}{{ end }}{{ if ne .git.operation "" }} [{{ .git.operation }}]{{ end }}{{ if ne .git.sha "" }} {{ .git.sha }}{{ end }}{{ if or (gt .git.staged 0) (gt .git.unstaged 0) (gt .git.untracked 0) (gt .git.conflicts 0) }} {{ if gt .git.staged 0 }}${Ub(`staged`,`"S"`)}{{ end }}{{ if gt .git.unstaged 0 }}${Ub(`unstaged`,`"U"`)}{{ end }}{{ if gt .git.untracked 0 }}${Ub(`untracked`,`"?"`)}{{ end }}{{ if gt .git.conflicts 0 }}${Ub(`conflicts`,`(printf "!%v" .git.conflicts)`)}{{ end }}{{ end }} ⎇ ${Ub(`branch`,`.git.branch`)}{{ if ne .git.upstream "" }} [{{ .git.upstream }}{{ if or (gt .git.ahead 0) (gt .git.behind 0) }} {{ if gt .git.ahead 0 }}${Ub(`ahead`,`(printf "+%v" .git.ahead)`)}{{ end }}{{ if and (gt .git.ahead 0) (gt .git.behind 0) }}/{{ end }}{{ if gt .git.behind 0 }}${Ub(`behind`,`(printf "-%v" .git.behind)`)}{{ end }}{{ end }}]{{ end }}{{ if gt .git.stash 0 }} ${Ub(`stash`,`(printf "(%v stashed)" .git.stash)`)}{{ end }}{{ if gt .git.timeSinceCommit 0 }} ◷ {{ template "formatTimeSince" .git.timeSinceCommit }}{{ end }}`,bg:`surface-active`,fg:Wb,when:`{{ ne .git.branch "" }}`},gitPr:{template:`{{ if ne .git.prUrl "" }}{{ link .git.prUrl (printf "⇆ #%v" .git.prNumber) }}{{ else }}⚠ PR{{ end }}`,bg:`surface-active`,fg:`foreground`,when:`{{ or (ne .git.prUrl "") (ne .git.prError "") }}`},toolbar:{template:`{{ action "copySession" "⎘ id" }} {{ action "openProject" "↗ proj" }} {{ action "openTranscript" "↗ log" }}{{ if ne .git.repoUrl "" }} {{ link .git.repoUrl "↗ repo" }}{{ end }} {{ action "edit.toggle" "✎ edit" "✎ done" }}`,bg:`surface`,fg:`foreground`},session:{template:`§ {{ template "formatCost" .session.cost }} ({{ template "formatTokens" .session.tokens }}){{ template "budgetStatus" (dict "cost" .session.cost "budget" .session.budget.amount "warn" .session.budget.warningThreshold) }}`,bg:`surface`,fg:`foreground`},today:{template:`☉ {{ template "formatCost" .today.cost }} ({{ template "formatTokens" .today.tokens }}){{ template "budgetStatus" (dict "cost" .today.cost "budget" .today.budget.amount "warn" .today.budget.warningThreshold) }}`,bg:`surface`,fg:`foreground`},block:{template:`◱ {{ round .block.nativeUtilization }}% ({{ template "formatLongTimeRemaining" (minutesUntilReset .block.resetsAt) }})`,bg:qb(`.block.nativeUtilization`,`.block.budget.warningThreshold`),fg:Jb(`.block.nativeUtilization`),when:`{{ gt .block.resetsAt 0 }}`},weekly:{template:`◑ {{ round .weekly.percentage }}% ({{ template "formatLongTimeRemaining" (minutesUntilReset .weekly.resetsAt) }})`,bg:qb(`.weekly.percentage`,`.weekly.budget.warningThreshold`),fg:Jb(`.weekly.percentage`),when:`{{ gt .weekly.resetsAt 0 }}`},burnrate:{template:`⚡ {{ template "formatRate" .burn.costPerHour }} · {{ template "formatEta" .block.etaMinutes }} to 5h · {{ template "formatEta" .weekly.etaMinutes }} to wk`,bg:Yb(`.block.etaMinutes`,`.burn.eta.warnMinutes`,`.burn.eta.errorMinutes`),fg:Xb(`.block.etaMinutes`,`.burn.eta.warnMinutes`),when:`{{ or (gt .block.resetsAt 0) (gt .weekly.resetsAt 0) }}`},speed:{template:`⇅ out {{ template "formatSpeed" .speed.output }} · in {{ template "formatSpeed" .speed.input }} · tot {{ template "formatSpeed" .speed.total }}`,bg:`panel`,fg:`foreground`,when:`{{ gt .session.tokens 0 }}`},tokenSparkline:{template:`⚡ {{ sparkline .speed.history 24 }}`,bg:`panel`,fg:`foreground`,when:`{{ ne .speed.history "" }}`},cacheTimer:{template:`◴ {{ if le (minutesUntilReset .cache.expiresAt) 0 }}cold{{ else }}{{ minutesUntilReset .cache.expiresAt }}m{{ end }}`,bg:`surface`,fg:`{{ if le (minutesUntilReset .cache.expiresAt) 8 }}error{{ else }}{{ if le (minutesUntilReset .cache.expiresAt) 20 }}warning{{ else }}foreground{{ end }}{{ end }}`,when:`{{ gt .cache.expiresAt 0 }}`},context:{template:`◔ {{ formatInteger .context.totalTokens }} ({{ .context.contextLeft }}%)`,bg:`{{ if le .context.contextLeft 20 }}error{{ else }}{{ if le .context.contextLeft 40 }}warning{{ else }}surface-active{{ end }}{{ end }}`,fg:`{{ if le .context.contextLeft 40 }}button-color-foreground{{ else }}foreground{{ end }}`,when:`{{ gt .context.totalTokens 0 }}`},metrics:{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 }} `,bg:`panel`,fg:`foreground`,when:`{{ or .metrics.lastResponseTime .metrics.responseTime .metrics.sessionDuration .metrics.messageCount .metrics.linesAdded .metrics.linesRemoved }}`},charsetControl:{template:`{{ .charset.effective }} {{ menu "applyCharsetForever" "▸" "▾" }} {{ action "resetCharset" "↺" }}`,bg:`surface`,fg:`foreground`},colorCompatControl:{template:`{{ .colorCompatibility.effective }} {{ menu "applyColorCompatForever" "▸" "▾" }} {{ action "resetColorCompat" "↺" }}`,bg:`surface`,fg:`foreground`},directoryPaletteControl:{template:`🎨 directory {{ menu "applyDirectoryPaletteForever" "▸" "▾" }} {{ action "resetDirectoryPalette" "↺" }}`,bg:`surface`,fg:`foreground`}},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:`toolbar`},{kind:`group`,name:`settings`,label:`⚙ terminal`,direction:`horizontal`,children:[`charsetControl`,`colorCompatControl`,`directoryPaletteControl`]}]},{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`model`},{kind:`segment`,name:`context`},{kind:`segment`,name:`cacheTimer`},{kind:`segment`,name:`block`},{kind:`segment`,name:`weekly`}]}]},actions:{copySession:{copy:`{{ .session.id }}`},copyDir:{copy:`{{ .current_dir }}`},openProject:{open:`{{ .project_dir }}`},openTranscript:{open:`{{ .transcript_path }}`},applyCharsetForever:{persist:`charset`,from:`charsets`},resetCharset:{reset:`charset`},applyColorCompatForever:{persist:`colorCompatibility`,from:`colorCompatibilities`},resetColorCompat:{reset:`colorCompatibility`},applyDirectoryPaletteForever:{persist:`segments.directory.palette`,from:`themes`},resetDirectoryPalette:{reset:`segments.directory.palette`}},looks:{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}},presets:{default:{},compact:{root:{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`directory`},{kind:`segment`,name:`git`},{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:`segment`,name:`toolbar`}]},{kind:`container`,direction:`horizontal`,children:[{kind:`segment`,name:`model`},{kind:`segment`,name:`context`},{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`}]}]}}},editGlobals:{style:`plain`,default_separator:` | `},helpers:{formatCost:'{{ if lt . 0.01 }}<$0.01{{ else }}${{ printf "%.2f" . }}{{ end }}',formatTokenCount:`{{ if ge . 1000000 }}{{ printf "%.1f" (divf . 1000000) }}M{{ else if ge . 1000 }}{{ printf "%.1f" (divf . 1000) }}K{{ else }}{{ . }}{{ end }}`,formatTokens:`{{ template "formatTokenCount" . }} tokens`,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 }}`}},Qb=new Set([Zb.globals.palette,...Object.values(Zb.segments).map(e=>e.palette)].filter(e=>e!==void 0)),$b=Jh(mb(`<default>`,JSON.stringify(Zb),Qb),Zb);function ex(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 tx(e){return typeof e==`string`?e:String(e)}function nx(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 rx(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")`)}const ix=/^(?:(?:global|apac|au|eu|us|us-east-\d|us-west-\d|eu-west-\d|eu-central-\d)\.)?(?:anthropic\.|azure_ai\/|bedrock\/|vertex_ai\/)?claude-(?:(?<family>opus|sonnet|haiku)-(?<newMajor>\d+)(?:-(?<newMinor>\d))?|(?<oldMajor>\d+)(?:-(?<oldMinor>\d))?-(?<oldFamily>opus|sonnet|haiku))(?:[-@]\d{8})?(?:-v\d+:\d+)?(?:-latest)?$/i,ax=/^(?<family>opus|sonnet|haiku)\s+(?<major>\d+)(?:\.(?<minor>\d))?$/i;function ox(e){if(!e)return`Claude`;let t=e.trim().replace(/\s*\([^)]*\)\s*$/,``).replace(/\s*\[[^\]]*\]\s*$/,``).trim(),n=t.match(ix);if(n?.groups){let{family:e,newMajor:t,newMinor:r,oldMajor:i,oldMinor:a,oldFamily:o}=n.groups,s=e||o,c=t||i,l=r||a;if(s&&c)return`${s.charAt(0).toUpperCase()+s.slice(1).toLowerCase()} ${l?`${c}.${l}`:c}`}let r=t.match(ax);if(r?.groups){let e=r.groups.family,t=r.groups.major,n=r.groups.minor;return`${e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()} ${n?`${t}.${n}`:t}`}return t||e}function sx(e){let t=e.match(ax);if(!t?.groups)return e;let n=t.groups.family,r=t.groups.major,i=t.groups.minor;return`${n.charAt(0).toUpperCase()}${i?`${r}.${i}`:r}`}function cx(e){let t=e.split(`/`),n=t.length-1;return t.map((e,t)=>{if(t===n)return e;let r=e.match(/^\.*./);return r?r[0]:e}).join(`/`)}function lx(e){return e.toLocaleString()}const ux=[`▁`,`▂`,`▃`,`▄`,`▅`,`▆`,`▇`,`█`],dx=ux.length;function fx(e,t){let n=t===void 0?e:t<=0?[]:e.slice(-t);if(n.length===0)return``;let r=n[0],i=n[0];for(let e of n)e<r&&(r=e),e>i&&(i=e);let a=i-r,o=``;for(let e of n){let t=a===0?0:Math.round((e-r)/a*(dx-1));o+=ux[t]}return o}function px(e){let t=[];for(let n of e.split(`,`)){let e=n.trim();if(e===``)continue;let r=Number(e);if(!Number.isFinite(r))throw TypeError(`sparkline: non-numeric series element ${JSON.stringify(n)}`);t.push(r)}return t}const mx=Sc(),hx=[...Ec];function gx(){return{basename:{fn:e=>l(e),argTypes:[`string`]},dirname:{fn:e=>u(e),argTypes:[`string`]},abbreviatePath:{fn:e=>cx(e),argTypes:[`string`]},int:{fn:e=>nx(e),argTypes:[`value`]},string:{fn:e=>tx(e),argTypes:[`value`]},bool:{fn:e=>rx(e),argTypes:[`value`]},urlEncode:{fn:e=>encodeURIComponent(e),argTypes:[`string`]},themes:{fn:()=>mx,argTypes:[]},styles:{fn:()=>hx,argTypes:[]},sparkline:{fn:(e,t)=>fx(px(e),t),argTypes:[`string`,`int`]}}}function _x(e=()=>new Date){return{minutesUntilReset:{fn:t=>Math.round(Math.max(0,t*1e3-e().getTime())/6e4),argTypes:[`int`]},formatInteger:{fn:e=>lx(e),argTypes:[`int`]},round:{fn:e=>Math.round(e),argTypes:[`float`]},formatModelName:{fn:e=>ox(e),argTypes:[`string`]},shortenModelName:{fn:e=>sx(e),argTypes:[`string`]}}}function vx(e,t=()=>new Date){return Hu({fromString:e=>new Ho(e),toString:e=>e.plain,clock:t,missingKey:`error`,funcs:{...Nf(),...Um(),...yp(),...Vp(),...Tf(t),...md(),...qf(),...gc(),...gx(),..._x(t),...e??{}}})}function yx(e){return bx(e,new Set(e.names()),``)}function bx(e,t,n){return new Proxy(Object.create(null),{has(e,r){if(typeof r!=`string`)return!1;let i=n?`${n}.${r}`:r;if(t.has(i))return!0;let a=`${i}.`;for(let e of t)if(e.startsWith(a))return!0;return!1},get(r,i){if(typeof i!=`string`)return;let a=n?`${n}.${i}`:i;if(t.has(a))return e.read(a);let o=`${a}.`;for(let n of t)if(n.startsWith(o))return bx(e,t,a)}})}function xx(e,t){return t.kind!==`ttl`||t.durationMs>=500?t:(O(`declareShell "${e}": ttl ${t.durationMs}ms below floor 500ms; clamping`),{kind:`ttl`,durationMs:500})}function Sx(e){let t=/^(\d+(?:\.\d+)?)(ms|s|m|h)$/.exec(e);if(!t)throw RangeError(`Invalid duration: "${e}"`);let n=parseFloat(t[1]);switch(t[2]){case`ms`:return n;case`s`:return n*1e3;case`m`:return n*6e4;case`h`:return n*36e5;default:throw RangeError(`Unexpected duration unit: "${t[2]}"`)}}async function Cx(e){let t=await ye({bin:`/bin/sh`,args:[`-c`,e],category:`user-shell`});return t.ok?{stdout:t.stdout,exitCode:t.exitCode??0}:{stdout:t.stdout,exitCode:t.exitCode??1}}async function wx(e,t,n){let r;try{r=await T(e,`utf8`)}catch{return{error:`file unreadable: ${e}`}}if(n!==void 0){let t=new RegExp(n).exec(r);return t?.[1]?{content:t[1].replace(/\n/g,` `)}:{error:`regex no-match in "${e}"`}}return t===`first-line`?{content:(r.split(`
|
|
161
|
+
`)[0]??``).trim()}:{content:r.replace(/\n/g,` `).trim()}}const Tx=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],Ex=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],Dx=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`],Ox=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function kx(e,t){let n=[[`2006`,e=>String(e.getFullYear())],[`January`,e=>Tx[e.getMonth()]],[`Monday`,e=>Dx[e.getDay()]],[`Jan`,e=>Ex[e.getMonth()]],[`Mon`,e=>Ox[e.getDay()]],[`15`,e=>String(e.getHours()).padStart(2,`0`)],[`06`,e=>String(e.getFullYear()%100).padStart(2,`0`)],[`01`,e=>String(e.getMonth()+1).padStart(2,`0`)],[`02`,e=>String(e.getDate()).padStart(2,`0`)],[`04`,e=>String(e.getMinutes()).padStart(2,`0`)],[`05`,e=>String(e.getSeconds()).padStart(2,`0`)],[`PM`,e=>e.getHours()<12?`AM`:`PM`],[`pm`,e=>e.getHours()<12?`am`:`pm`],[`1`,e=>String(e.getMonth()+1)],[`2`,e=>String(e.getDate())],[`3`,e=>String(e.getHours()%12||12)],[`4`,e=>String(e.getMinutes())],[`5`,e=>String(e.getSeconds())]],r=``,i=0;for(;i<e.length;){let a=!1;for(let[o,s]of n)if(e.startsWith(o,i)){r+=s(t),i+=o.length,a=!0;break}a||(r+=e[i],i++)}return r}const Ax={branch:`string`,sha:`string`,dirty:`boolean`,ahead:`number`,behind:`number`,stash:`number`};function jx(e,t,n,r){if(e===null){if(n!==void 0)return n;let e=Ax[t];try{return Fx(r,e)}catch{return Ix(e)}}switch(t){case`branch`:return e.branch===`detached`?``:e.branch;case`sha`:return Zn(e.sha,``);case`dirty`:return e.status!==`clean`;case`ahead`:return Zn(e.aheadBehind,{ahead:0,behind:0}).ahead;case`behind`:return Zn(e.aheadBehind,{ahead:0,behind:0}).behind;case`stash`:return Zn(e.stashCount,0)}}var Mx=class{watchers=new Map;subscribe(e,t){let n=this.watchers.get(e);if(!n){let t=new Set,r;try{r=s(e,()=>{for(let e of t)e()})}catch{return()=>{}}n={watcher:r,callbacks:t},this.watchers.set(e,n)}return n.callbacks.add(t),()=>this.unsubscribe(e,t)}unsubscribe(e,t){let n=this.watchers.get(e);n&&(n.callbacks.delete(t),n.callbacks.size===0&&(n.watcher.close(),this.watchers.delete(e)))}dispose(){for(let{watcher:e}of this.watchers.values())e.close();this.watchers.clear()}size(){return this.watchers.size}},Nx=class{buckets=new Map;subscribe(e,t){let n=this.buckets.get(e);if(!n){let t=new Set;n={timer:D(()=>{for(let e of t)e()},e),callbacks:t},this.buckets.set(e,n)}return n.callbacks.add(t),()=>this.unsubscribe(e,t)}unsubscribe(e,t){let n=this.buckets.get(e);n&&(n.callbacks.delete(t),n.callbacks.size===0&&(E(n.timer),this.buckets.delete(e)))}dispose(){for(let{timer:e}of this.buckets.values())E(e);this.buckets.clear()}bucketCount(){return this.buckets.size}};function Px(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n)return;n=n[e]}return n}function Fx(e,t){if(typeof e!=`string`&&typeof e!=`number`&&typeof e!=`boolean`)throw TypeError(`Expected string|number|boolean from payload, got ${typeof e}`);return t===`string`?tx(e):t===`number`?nx(e):rx(e)}function Ix(e){return e===`number`?0:e===`boolean`?!1:``}var Lx=class{inputMetas=new Map;lastErrors=new Map;watchMgr=new Mx;ttlMgr=new Nx;gitSubscriptions=new Map;cleanups=[];inFlight=new Set;engine=vx();gitProvider;ownsGitProvider;sessionState;constructor(e,t=``,n,r){this.store=e,this.defaultEmptyValue=t,n?(this.gitProvider=n,this.ownsGitProvider=!1):(this.gitProvider=new Or({sanityIntervalMs:0}),this.ownsGitProvider=!0),this.sessionState=r}get variableStore(){return this.store}declareLiteral(e,t){this.store.defineBox(e,ex(t),t)}declareInput(e,t,n,r){let i=r===void 0?this.defaultFor(n):r;this.store.defineBox(e,n,i),this.inputMetas.set(e,{path:t,varDefault:r})}declareEnv(e,t,n){let r=process.env[t];if(r!==void 0){this.store.defineBox(e,`string`,r);return}let i=n===void 0?typeof this.defaultEmptyValue==`string`?this.defaultEmptyValue:``:n;this.store.defineBox(e,`string`,i),this.recordError(e,`env var "${t}" is not set`)}declareShell(e,t,n){let r=xx(e,n.cache);this.store.defineBox(e,`string`,this.stringInitial(n.varDefault));let i=()=>void this.updateFromShell(e,t,n.regex,n.varDefault);i(),this.registerCachePolicy(e,r,i)}declareFile(e,t,n){this.store.defineBox(e,`string`,this.stringInitial(n.varDefault));let r=()=>void this.updateFromFile(e,t,n.readMode,n.regex,n.varDefault);r(),this.registerCachePolicy(e,n.cache,r)}declareTemplate(e,t,n={}){let r=this.engine.parse(t);this.store.defineComputed(e,`string`,t=>{let i=yx(this.store);try{let t=r.evaluate(i).map(e=>e.plain).join(``);return this.lastErrors.delete(e),t}catch(t){return this.recordError(e,t instanceof Error?t.message:String(t)),this.stringInitial(n.varDefault)}}),this.store.read(e)}declareTime(e,t){let n=t.ttlMs??1e3;this.store.defineBox(e,`string`,(e=>{try{return kx(t.format,e)}catch{return this.stringInitial(t.varDefault)}})(new Date));let r=this.ttlMgr.subscribe(n,()=>{try{this.store.setBox(e,kx(t.format,new Date)),this.lastErrors.delete(e)}catch(n){this.applyFallback(e,`string`,t.varDefault,n instanceof Error?n.message:String(n))}});this.cleanups.push(r)}declareGit(e,t){let n=Ax[t.field],r=t.varDefault===void 0?Ix(n):Fx(t.varDefault,n);this.store.defineBox(e,n,r);let i=this.gitSubscriptions.get(t.cwd);if(!i){let e=new Map;i={fieldSubs:e,unsubscribe:this.gitProvider.subscribe(t.cwd,t=>{this.store.runInAction(()=>{for(let[n,r]of e)for(let{name:e,varDefault:i}of r)this.store.setBox(e,jx(t,n,i,this.defaultEmptyValue))})})},this.gitSubscriptions.set(t.cwd,i)}let a=i.fieldSubs.get(t.field);a||(a=[],i.fieldSubs.set(t.field,a)),a.push({name:e,varDefault:t.varDefault})}declareState(e,t){if(!this.sessionState)throw Error(`declareState("${e}"): SourceRegistry was constructed without a SessionState — state-kind variables require a SessionState (the daemon provides one; tests must supply one)`);let n=this.sessionState,r=t.varDefault??this.stringInitial(void 0);this.store.defineComputed(e,`string`,e=>{let i=e(`session.id`);if(typeof i!=`string`||!i)return r;let a=n.get(i,t.key);return a===null?r:a})}applyInput(e){this.store.runInAction(()=>{for(let[t,n]of this.inputMetas){let r=Px(e,n.path),i=this.store.getType(t);if(r!==void 0)try{this.store.setBox(t,Fx(r,i)),this.lastErrors.delete(t)}catch(e){this.applyFallback(t,i,n.varDefault,e instanceof Error?e.message:String(e))}else this.applyFallback(t,i,n.varDefault,`input path "${n.path}" not found in payload`)}})}getLastError(e){return this.lastErrors.get(e)}dispose(){for(let e of this.cleanups)e();this.cleanups.length=0;for(let e of this.gitSubscriptions.values())e.unsubscribe();this.gitSubscriptions.clear(),this.watchMgr.dispose(),this.ttlMgr.dispose(),this.ownsGitProvider&&this.gitProvider.close()}registerCachePolicy(e,t,n){switch(t.kind){case`never`:break;case`ttl`:{let e=this.ttlMgr.subscribe(t.durationMs,n);this.cleanups.push(e);break}case`watch_file`:{let e=this.watchMgr.subscribe(t.path,n);this.cleanups.push(e);break}case`key`:{let e=this.engine.parse(t.template),r=(0,q.reaction)(()=>{let t=yx(this.store);try{return e.evaluate(t).map(e=>e.plain).join(``)}catch{return``}},n);this.cleanups.push(r);break}case`depends_on`:{let e=(0,q.reaction)(()=>t.varNames.map(e=>String(this.store.read(e))).join(`,`),n);this.cleanups.push(e);break}}}async updateFromShell(e,t,n,r){if(!this.inFlight.has(e)){this.inFlight.add(e);try{let{stdout:i,exitCode:a}=await Cx(t);if(a!==0){this.applyFallback(e,`string`,r,`shell "${t}" exited with code ${a}`);return}if(n!==void 0){let a=new RegExp(n).exec(i);if(!a?.[1]){this.applyFallback(e,`string`,r,`regex no-match in output of "${t}"`);return}this.store.setBox(e,a[1].replace(/\n/g,` `))}else this.store.setBox(e,i.replace(/\n/g,` `).trim());this.lastErrors.delete(e)}finally{this.inFlight.delete(e)}}}async updateFromFile(e,t,n,r,i){if(!this.inFlight.has(e)){this.inFlight.add(e);try{let a=await wx(t,n,r);if(a.error!==void 0){this.applyFallback(e,`string`,i,a.error);return}this.store.setBox(e,a.content??``),this.lastErrors.delete(e)}finally{this.inFlight.delete(e)}}}applyFallback(e,t,n,r){if(this.recordError(e,r),n!==void 0){this.store.setBox(e,n);return}try{this.store.setBox(e,Fx(this.defaultEmptyValue,t))}catch{this.store.setBox(e,Ix(t))}}defaultFor(e){try{return Fx(this.defaultEmptyValue,e)}catch{return Ix(e)}}stringInitial(e){return e===void 0?typeof this.defaultEmptyValue==`string`?this.defaultEmptyValue:``:e}recordError(e,t){this.lastErrors.set(e,{timestamp:Date.now(),message:t})}};const Rx=new Map,zx=new Map;function Bx(e){let t=vc(e),n=Rx.get(t);if(n!==void 0)return n;let r=ao(t);if(r===null)throw Error(`Palette "${e}" (resolved "${t}") did not resolve in the theme registry — allowed names and the registry are inconsistent`);return Rx.set(t,r),r}function Vx(e,t){let n=`${e.name} ${t.hueShift} ${t.chromaScale} ${t.lightnessScale} ${t.lightnessShift}`,r=zx.get(n);if(r!==void 0)return r;let i=vo(e,t);return zx.set(n,i),i}function Hx(e,t){let n=[],r=[],i=()=>{if(!r.length)return;let e=Ux(r,t);e.plain.length>0&&n.push(e),r=[]};for(let a of e)if(a.style.link){i();let e=Ux([a],t);e.plain.length>0&&n.push(e)}else r.push(a);return i(),n}function Ux(e,t){let n=t!==void 0&&!t.isNull?e.map(e=>Wx(e,t)):e,r=Ho.fromFragments(n);return r.end=``,r.noWrap=!0,n.length===1?r.style=n[0].style:t!==void 0&&!t.isNull&&(r.style=t),r}function Wx(e,t){let n=e.copy();return n.style=t.add(e.style),n}function Gx(e,t){return e===void 0?!0:e.evaluate(t).map(e=>e.plain).join(``)!==`false`}function Kx(e,t){let n=Ho.fromFragments(e);return n.end=``,n.noWrap=!0,t!==void 0&&!t.isNull&&(n.style=t),n}function qx(e,t){let{width:n,justify:r,truncate:i,truncateMarker:a=`…`,baseStyle:o,padding:s}=t;if(e.length===0)return[];let c=Kx(e,o).pad(s);return n===`auto`||(c.cellLength>n?c.truncate(n,{mode:i,marker:a}):c.cellLength<n&&c.align(r,n)),[c]}var Jx=class extends Error{constructor(e,t,n){super(`Invalid ${t} color ${JSON.stringify(e)}: ${n}`),this.name=`ColorSpecError`}};function Yx(e,t,n,r,i,a){let o={segName:t,palette:n,bg:void 0};e.current=o;let s=Xx(r,a),c=s===void 0?void 0:Zx(n,s,`bg`);o.bg=c;let l=Xx(i,a),u=l===void 0?void 0:Zx(n,l,`fg`);return new G({bgcolor:c===void 0?void 0:ua.fromRgba(c),color:u===void 0?void 0:ua.fromRgba(u)})}function Xx(e,t){if(e!==void 0)return e.evaluate(t).map(e=>e.plain).join(``)}function Zx(e,t,n){try{return za(e,t)}catch(e){throw e instanceof Ia?new Jx(t,n,e.message):e}}const Qx=new Map([[`palette`,`theme.effective`],[`preset`,`preset.effective`],[`look`,`look.effective`],[`style`,`style.effective`],[`charset`,`charset.effective`],[`colorCompatibility`,`colorCompatibility.effective`],[`autoWrap`,`autoWrap.effective`],[`padding`,`padding.effective`]]);function $x(e,t,n,r){let i=new Map;for(let[a,o]of Object.entries(t))i.set(a,eS(e,a,o,n,r));return i}function eS(e,t,n,r,i){if(Fv(n)){let[a,o]=Iv(n);return tS(r.get(n.persistWhen)??n.persistWhen,n.set,eS(e,t,a,r,i),eS(e,t,o,r,i))}if(`set`in n){let e=r.get(n.set)??n.set;return`to`in n?{kind:`set-literal`,key:n.set,value:n.to,stateVar:e}:`from`in n?{kind:`set-option`,key:n.set,stateVar:e,options:[...Ly(n.from,i)]}:`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=Qx.get(n.persist)??n.persist;return`to`in n?{kind:`persist-literal`,key:n.persist,value:n.to,stateVar:e}:`from`in n?{kind:`persist-option`,key:n.persist,stateVar:e,options:[...Ly(n.from,i)]}:`cycle`in n?{kind:`persist-cycle`,key:n.persist,stateVar:e,members:n.cycle}:`removeSegment`in n?{kind:`layout-op`,key:n.persist,op:{op:`remove`,target:n.removeSegment}}:`insertSegment`in n?{kind:`layout-op`,key:n.persist,op:{op:`insert`,segment:n.insertSegment,anchor:n.anchor,relation:n.relation}}:`insertSegmentFrom`in n?{kind:`layout-op-option`,key:n.persist,anchor:n.anchor,relation:n.relation,options:[...Ly(n.insertSegmentFrom,i)]}:{kind:`persist-bounded`,key:n.persist,by:n.by}}return`copy`in n?{kind:`copy`,text:rS(e,n.copy,t)}:`open`in n?{kind:`open`,target:rS(e,n.open,t)}:`reset`in n?{kind:`reset`,key:n.reset}:`undo`in n?{kind:`undo`}:{kind:`redo`}}function tS(e,t,n,r){return{kind:`dual`,selector:e,session:`stateVar`in n&&`stateVar`in r?{...n,stateVar:r.stateVar}:n,durable:r,sessionKey:t}}function nS(e,t){return e.kind===`dual`?Fc(iS(t,e.selector))===!0?e.durable:e.session:e}function rS(e,t,n){try{return e(t)}catch(e){throw Error(`Template parse error in actions.${n}: ${e.message}`,{cause:e})}}function iS(e,t){return e.has(t)?tx(e.read(t)):``}function aS(e,t){return e.evaluate(t).map(e=>e.plain).join(``)}function oS(e,t,n){let r=new Ho(e,{style:new G({link:t,bold:n})});return r.noWrap=!0,r.end=``,r}function sS(e,t){return Math.max(e.members.indexOf(iS(t,e.stateVar)),0)}function cS(e,t,n,r,i){switch(e.kind){case`set-literal`:{let t=iS(r,e.stateVar);return{effects:[{verb:Pt,args:[i,e.key,e.value]}],active:t===e.value}}case`set-option`:{let a=n??t,o=iS(r,e.stateVar);return{effects:[{verb:Pt,args:[i,e.key,a]}],active:o===a}}case`set-int`:{let a=n??t,o=iS(r,e.stateVar);return{effects:[{verb:Pt,args:[i,e.key,a]}],active:o===a}}case`set-cycle`:{let t=e.members[(sS(e,r)+1)%e.members.length];return{effects:[{verb:Pt,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:Ft,args:[aS(e.text,yx(r))]}],active:!1};case`open`:return{effects:[{verb:It,args:[aS(e.target,yx(r))]}],active:!1};case`persist-literal`:{let t=iS(r,e.stateVar);return{effects:[{verb:zt,args:[i,e.key,e.value]}],active:t===e.value}}case`persist-option`:{let a=n??t,o=iS(r,e.stateVar);return{effects:[{verb:zt,args:[i,e.key,a]}],active:o===a}}case`persist-cycle`:{let t=e.members[(sS(e,r)+1)%e.members.length];return{effects:[{verb:zt,args:[i,e.key,t]}],active:!1}}case`persist-bounded`:return{effects:[{verb:Bt,args:[i,e.key,String(e.by)]}],active:!1};case`reset`:return{effects:[{verb:Vt,args:[i,e.key]}],active:!1};case`undo`:return{effects:[{verb:Ut,args:[i]}],active:!1};case`redo`:return{effects:[{verb:Wt,args:[i]}],active:!1};case`layout-op`:return{effects:[{verb:Ht,args:[i,e.key,zc(e.op)]}],active:!1};case`dual`:{let a=nS(e,r),{effects:o,active:s}=cS(a,t,n,r,i);return a===e.durable?{effects:o.map(t=>({...t,args:[...t.args,e.sessionKey]})),active:s}:{effects:o,active:s}}case`layout-op-option`:{let r={op:`insert`,segment:n??t,anchor:e.anchor,relation:e.relation};return{effects:[{verb:Ht,args:[i,e.key,zc(r)]}],active:!1}}}}function lS(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:Qt(`action "${e}"`,n,t.members.length,sS(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]}}function uS(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}=lS(e,nS(r,i),t,i),{effects:s,active:c}=cS(r,a,o,i,iS(i,`session.id`));return oS(a,qt(s),c)}function dS(e){return{action:{fn:(t,...n)=>uS(t,n,e),argTypes:[`string`,`string`],returnType:`T`}}}function fS(e){return new Ho(e).cellLength}function pS(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 mS(e,t){let n=[];for(let t of e)n.length>0&&n.push(new Ho(` `)),n.push(t);let r=Ho.fromFragments(n);return r.noWrap=t,r.end=``,r}function hS(e,t,n,r){let i=e.compiled.get(t);if(!i||i.kind!==n)throw Error(`picker references action "${t}" which must be ${r}, got ${i?`a ${i.kind} action`:`no such action`}`);return i}function gS(e,t){let n=e.compiled.get(t),r=n&&nS(n,e.store);if(!r||r.kind!==`set-option`&&r.kind!==`persist-option`&&r.kind!==`layout-op-option`)throw Error(`picker 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 ${r?`a ${r.kind} action`:`no such action`}`);return r}function _S(e,t,n,r,i,a){let o=gS(a,e),s=a.compiled.get(e),c=a.store,l=iS(c,`session.id`),u=`stateVar`in o?iS(c,o.stateVar):void 0,d=o.options.map(fS),f=i?Math.max(1,nx(c.read(`term.cols`))-sh(a.stripStyle)-2*a.padding):1/0,p=fS(`✕`)+1,m=fS(`←`)+1+fS(`→`)+1,h=pS(d,f,p),g=h.length>1?pS(d,f,p+m):h,_=parseInt(iS(c,t.stateVar),10),v=Number.isInteger(_)?Math.max(0,Math.min(_,g.length-1)):0,y=g[v]??[],b=e=>qt([{verb:Pt,args:[l,t.key,String(e)]}]),x=n.flatMap(([e,t])=>[e,t]),S=qt([{verb:Pt,args:[l,...x]}]),C=r?[{verb:Pt,args:[l,...x]}]:[],w=e=>{let{effects:t}=cS(s,e,e,c,l),n=t.length===1?t[0]:void 0;return n?.verb===`set-state`?qt([{verb:Pt,args:[...n.args,...r?x:[]]}]):qt([...t,...C])},ee=[oS(`✕`,S,!1)];v>0&&ee.push(oS(`←`,b(v-1),!1));for(let e of y){let t=o.options[e];ee.push(oS(t,w(t),t===u))}return v<g.length-1&&ee.push(oS(`→`,b(v+1),!1)),mS(ee,i)}function vS(e){return{picker:{fn:(t,n,r,i)=>{let a=hS(e,n,`set-int`,`an int action ({ set, int: true })`);return _S(t,{key:a.key,stateVar:a.stateVar},[[a.key,`-1`]],r===!0,i===!0,e)},argTypes:[`string`,`string`,`bool`,`bool`],returnType:`T`}}}const yS=Symbol(`cc-candybar.menuDrop`);function bS(e){return e.flatMap(e=>e[yS]??[])}function xS(e,t,n,r){let i=r.activeSegment.current;if(i===null)throw Error(`{{ menu }} rendered with no active segment placement — the render walk must publish one before evaluating a segment template`);let a=r.action,o=g_(i.segName,e,n.key),s=v_(o),c=h_(e),l=iS(a.store,o)===c,u=iS(a.store,`session.id`),d=l?Xt:c,f=oS(Qt(`{{ menu "${e}" }}`,t,2,+!!l),qt([{verb:Pt,args:[u,o,d,s,`0`]}]),!1);return f[yS]=l?[_S(e,{key:s,stateVar:s},[[o,Xt],[s,`0`]],n.closeOnPick,n.paged,a)]:[],f}const SS=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function CS(e,t){let n=t[t.length-1],r=SS(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:y_(r??{})}}function wS(e){return{menu:{fn:(t,...n)=>{let{displays:r,options:i}=CS(t,n);return xS(t,r,i,e)},argTypes:[`string`,`value`],returnType:`T`}}}function TS(){return{current:null}}function ES(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 DS(e){let t={fn:(()=>{let t=ES(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:[],returnType:`string`};return{...hc(()=>ES(e,`color`).palette),bgOf:t}}function OS(e){let t=[],n=[];for(let r of e){if(!r.contains(`
|
|
162
162
|
`)){n.push(r);continue}let e=r.split(`
|
|
163
|
-
`);n.push(e[0]);for(let r=1;r<e.length;r++)t.push(n),n=[e[r]]}return t.push(n),t}function
|
|
164
|
-
`)}const PS=/^-?\d+$/;function FS(e,t,n){return e===void 0?t:Math.max(t,Math.min(n,e))}function IS(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 LS(e){return t=>{if(!t)return{ok:!1,reason:`${e} value is required`};if(!PS.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 RS(e,t,n){return r=>r?PS.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 zS(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=>!PS.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,seed:FS(r[0].seed,t,i)}}return{kind:`int`}}function BS(e){return e===`config`?`set-config`:`set-state`}function VS(e,t,n){return t.kind===`int`?LS(`menu page "${e}"`):t.kind===`range`?RS(t.min,t.max,`${n} stepper "${e}"`):IS(t.allowed,`${n} "${e}"`,BS(n))}function HS(e,t,n){return VS(e,zS(e,t,n),n)}function US(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:zS(e,n,t)}))}function WS(e,t=`state`){let n=new Map(Object.entries(e).map(([e,t])=>[e,{validator:t,permanent:!0}]));function r(){let e=[];for(let[t,r]of n)r.permanent&&e.push(t);return e}return{register(e,i){if(!e)throw Error(`register: key is required`);if(e.includes(`/`))throw Error(`register: key "${e}" contains "/" — the wire shape splits on "/" so a slash-bearing key cannot be addressed. Use a slash-free key.`);let a=n.get(e);if(a){if(a.permanent)throw Error(`register: key "${e}" is a built-in ${t} key and cannot be re-claimed (built-in keys: ${[...r()].join(`, `)})`);if(a.kind!==i.kind)throw Error(`register: key "${e}" is already a ${a.kind} ${t} key; cannot also register it as ${i.kind}. A ${t} key has one key shape — a menu page index (int) and a button allow-list cannot share a key.`);a.specs.push(i),a.validator=HS(e,a.specs,t)}else{let r=[i];n.set(e,{permanent:!1,kind:i.kind,validator:HS(e,r,t),specs:r})}let o=!0;return()=>{if(!o)return;o=!1;let r=n.get(e);if(!r||r.permanent)return;let a=r.specs.indexOf(i);a>=0&&r.specs.splice(a,1),r.specs.length===0?n.delete(e):r.validator=HS(e,r.specs,t)}},validate(e,r){let i=n.get(e);return i?i.validator(r):{ok:!1,reason:`unknown ${t} key "${e}" (have: ${[...n.keys()].join(`, `)})`}},listKeys(){return[...n.keys()]},listBaselineKeys(){return r()},rangeParamsFor(e){let r=n.get(e);if(!r||r.permanent||r.kind!==`range`)return null;let i=zS(e,r.specs,t);if(i.kind!==`range`)throw Error(`rangeParamsFor: key "${e}" holds range specs but the merge produced a ${i.kind} spec — the entry-kind invariant is broken.`);return{min:i.min,max:i.max,seed:i.seed}}}}const GS=Sc(),KS=new Set(GS),qS=new Set(Ec),JS=e=>e?KS.has(e)?{ok:!0,value:e}:{ok:!1,reason:`unknown theme "${e}" (have: ${GS.join(`, `)})`}:{ok:!1,reason:`theme name is required`},YS=e=>e?qS.has(e)?{ok:!0,value:e}:{ok:!1,reason:`unknown style "${e}" (have: ${Ec.join(`, `)})`}:{ok:!1,reason:`style name is required`},XS=new Set([`1`,`true`]),ZS=new Set([`0`,`false`]),QS=WS({style:YS,theme:JS,"toolbar-expanded":e=>XS.has(e)?{ok:!0,value:`1`}:ZS.has(e)?{ok:!0,value:``}:{ok:!1,reason:`expected boolean-ish (1, 0, true, false), got "${e}"`}});function $S(){return QS.listKeys()}function eC(e,t){return QS.register(e,t)}function tC(e,t){return QS.validate(e,t)}function nC(e){return QS.rangeParamsFor(e)}function rC(e,t,n){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:Ny(e.from,n)}}]:`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,seed:FS(t.get(e.set),e.min,e.max)}}]:[]}function iC(e){let t=new Set(QS.listBaselineKeys());return e.filter(e=>e.spec.kind!==`allow-list`||!t.has(e.key))}function aC(e){let t=new Map,n=/^-?\d+$/;for(let r of Object.values(e.variables)){if(r.kind!==`state`)continue;let e=r.default;e!==void 0&&n.test(e)&&t.set(r.key,parseInt(e,10))}for(let[n,r]of og(e.globals))t.set(n,r);return t}function oC(e){let t=aC(e),n=jy(e);return iC(Object.values(e.actions).flatMap(Mv).flatMap(e=>rC(e,t,n)))}function sC(e){return US(oC(e))}const cC=WS({},`config`);function lC(){return cC.listKeys()}function uC(e,t){return cC.validate(e,t)}function dC(e){return cC.rangeParamsFor(e)}function fC(e,t,n){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:Ny(e.from,n)}}]:`cycle`in e?[{key:e.persist,spec:{kind:`allow-list`,allowed:e.cycle}}]:`removeSegment`in e?[{key:e.persist,spec:{kind:`allow-list`,allowed:[zc({op:`remove`,target:e.removeSegment})]}}]:`insertSegment`in e?[{key:e.persist,spec:{kind:`allow-list`,allowed:[zc({op:`insert`,segment:e.insertSegment,anchor:e.anchor,relation:e.relation})]}}]:`insertSegmentFrom`in e?[{key:e.persist,spec:{kind:`allow-list`,allowed:Ny(e.insertSegmentFrom,n).map(t=>zc({op:`insert`,segment:t,anchor:e.anchor,relation:e.relation}))}}]:[{key:e.persist,spec:{kind:`range`,min:e.min,max:e.max,seed:FS(t.get(e.persist),e.min,e.max)}}]:[]}function pC(e){return og(e.globals)}function mC(e){let t=new Set;for(let n of gC(e)){let e=`persist`in n?n.persist:`reset`in n?n.reset:null;if(e===null)continue;let r=k_(e);r?.scope===`preset-root-ops`&&t.add(r.preset)}return[...t].map(e=>({key:O_(e),spec:{kind:`allow-list`,allowed:[]}}))}function hC(e){let t=pC(e),n=new Map([...jy(e),...xv(e)]);return[...mC(e),...gC(e).flatMap(e=>fC(e,t,n))]}function gC(e){return Object.values(e.actions).flatMap(Mv)}function _C(e){return US(hC(e),`config`)}function vC(e,t){return cC.register(e,t)}const yC=(e,t)=>O(t),bC={default_bg:`string`,default_fg:`string`,default_empty_value:`string`,default_separator:`string`,default_truncate_marker:`string`,palette:`string`,look:`string`,preset:`string`,style:`string`,autoWrap:`boolean`,padding:`number`,charset:`string`,colorCompatibility:`string`},xC=new Set([`1`,`true`]),SC=new Set([`0`,`false`,``]);function CC(e,t){let n=k_(e);if(n===null)throw Error(`coercePersistValue: "${e}" is not a valid persist target`);if(n.scope===`segment-palette`||n.scope===`preset-root-ops`)return t;let r=bC[n.field];if(r===`string`)return t;if(r===`number`){let n=Number(t);if(!Number.isFinite(n))throw Error(`coercePersistValue: "${e}" expects a number, got "${t}"`);return n}if(xC.has(t))return!0;if(SC.has(t))return!1;throw Error(`coercePersistValue: "${e}" expects boolean-ish (1, 0, true, false), got "${t}"`)}function wC(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;for(let[t,n]of Object.entries(e)){let e=k_(t);if(e===null)return!1;let r=e.scope===`globals`?bC[e.field]:`string`;if(r===`number`&&typeof n!=`number`||r===`boolean`&&typeof n!=`boolean`||r===`string`&&typeof n!=`string`)return!1}return!0}function TC(e,t){let n;try{n=r.readFileSync(e,`utf8`)}catch(e){let n=e.code;return n!==`ENOENT`&&t(`warn`,`config-overrides read failed (${n}); starting empty`),{}}try{let e=JSON.parse(n);return wC(e)?e:(t(`warn`,`config-overrides load: unexpected shape, starting empty`),{})}catch{return t(`warn`,`config-overrides load: corrupt JSON, starting empty`),{}}}function EC(e){let t=Object.create(null);for(let[n,r]of Object.entries(e))rg(n)&&(t[n]=r);return t}function DC(e){let t=Object.create(null);for(let[n,r]of Object.entries(e)){let e=k_(n);e?.scope===`segment-palette`&&typeof r==`string`&&(t[e.segment]=r)}return t}function OC(e,t){let n=Object.create(null);for(let[r,i]of Object.entries(e)){let e=k_(r);if(!(e?.scope!==`preset-root-ops`||typeof i!=`string`)){try{let t=JSON.parse(i);if(Array.isArray(t)&&t.every(e=>typeof e==`string`)){n[e.preset]=t;continue}}catch{}t(`warn`,`config-overrides: "${r}" is not a valid op-token list, dropping`)}}return n}function kC(e,t=yC){return EC(TC(e,t))}function AC(e,t=yC){let n=TC(e,t);return{globals:EC(n),segmentPalette:DC(n),presetRootOps:OC(n,t)}}function jC(e,t,n,i){try{r.mkdirSync(c.dirname(e),{recursive:!0});let t=`${e}.tmp`;r.writeFileSync(t,JSON.stringify(n),{mode:384}),r.chmodSync(t,384),r.renameSync(t,e)}catch(e){let n=`${t} write failed: ${e.message}`;throw i(`error`,n),Error(n)}}function MC(e,t,n){jC(e,`config-overrides`,t,n)}function NC(e,t,n,r){let i=TC(e,r),a=i[t];if(n===void 0){if(!(t in i))return a;let n={...i};delete n[t],MC(e,n,r)}else MC(e,{...i,[t]:n},r);return a}function PC(e,t,n,r=yC){GC(e,{key:t,from:NC(e,t,n,r)??null,to:n},r)}function FC(e,t,n=yC){t in TC(e,n)&&GC(e,{key:t,from:NC(e,t,void 0,n)??null,to:null},n)}function IC(e,t,n,r){NC(e,t,n===null?void 0:n,r)}const LC={past:[],future:[]};function RC(e){return c.join(c.dirname(e),`config-overrides-history.json`)}function zC(e){return e===null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`}function BC(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.key==`string`&&zC(t.from)&&zC(t.to)}function VC(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=e;return Array.isArray(t.past)&&t.past.every(BC)&&Array.isArray(t.future)&&t.future.every(BC)}function HC(e,t){let n=RC(e),i;try{i=r.readFileSync(n,`utf8`)}catch(e){let n=e.code;return n!==`ENOENT`&&t(`warn`,`config-overrides-history read failed (${n}); starting empty`),LC}try{let e=JSON.parse(i);return VC(e)?e:(t(`warn`,`config-overrides-history load: unexpected shape, starting empty`),LC)}catch{return t(`warn`,`config-overrides-history load: corrupt JSON, starting empty`),LC}}function UC(e,t,n){jC(RC(e),`config-overrides-history`,t,n)}function WC(e,t,n){let r=[...e,t];return r.length>n?r.slice(r.length-n):r}function GC(e,t,n){UC(e,{past:WC(HC(e,n).past,t,50),future:[]},n)}function KC(e,t=yC){let n=HC(e,t),r=n.past[n.past.length-1];return r===void 0?null:(IC(e,r.key,r.from,t),UC(e,{past:n.past.slice(0,-1),future:WC(n.future,r,50)},t),r)}function qC(e,t=yC){let n=HC(e,t),r=n.future[n.future.length-1];return r===void 0?null:(IC(e,r.key,r.to,t),UC(e,{past:WC(n.past,r,50),future:n.future.slice(0,-1)},t),r)}var JC=class{kind=`box`;cell;lastSetAt;constructor(e,t,n){this.name=e,this.type=t,XC(e,t,n,`initial value`),this.cell=q.observable.box(n,{deep:!1}),this.lastSetAt=Date.now()}read(){return this.cell.get()}set(e){XC(this.name,this.type,e,`set value`),this.cell.set(e),this.lastSetAt=Date.now()}lastUpdatedMs(){return this.lastSetAt}},YC=class{kind=`computed`;cell;constructor(e,t,n){this.name=e,this.type=t,this.cell=(0,q.computed)(()=>{let e=n();return XC(this.name,this.type,e,`computed result`),e},{keepAlive:!0})}read(){return this.cell.get()}lastUpdatedMs(){return null}};function XC(e,t,n,r){let i=Xb(n);if(i!==t)throw TypeError(`Variable "${e}": ${r} type ${i} does not match declared type ${t}`)}var ZC=class{nodes=new Map;defineBox(e,t,n){this.assertNotDefined(e),this.nodes.set(e,new JC(e,t,n))}defineComputed(e,t,n){this.assertNotDefined(e);let r=e=>this.read(e);this.nodes.set(e,new YC(e,t,()=>n(r)))}read(e){return this.requireNode(e).read()}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,q.runInAction)(()=>n.set(t))}runInAction(e){(0,q.runInAction)(e)}has(e){return this.nodes.has(e)}getType(e){return this.requireNode(e).type}getKind(e){return this.requireNode(e).kind}getNode(e){let t=this.requireNode(e);return{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}assertNotDefined(e){if(this.nodes.has(e))throw Error(`Variable "${e}" is already declared`)}};function QC(e,t,n){return e+`\0`+t+`\0`+(n??``)}var $C=class{entries=new Map;deps;maxEntries;constructor(e,t={}){this.deps=e,this.maxEntries=t.maxEntries??256}getOrCreate(e,t,n){let r=QC(e,t,n),i=this.entries.get(r);if(i)return this.entries.delete(r),this.entries.set(r,i),i;let a={projectDir:e,cwd:t,configFile:n,configFilePath:null,lastError:null,lastWarning:null,state:null,watcher:null};if(this.reloadInto(a),this.entries.set(r,a),this.entries.size>this.maxEntries){let e=this.entries.keys().next().value;if(e!==void 0){let t=this.entries.get(e);t?.state?.registry.dispose(),t?.state?.validatorDisposers.forEach(e=>e()),t?.watcher?.release(),this.entries.delete(e)}}return a}reloadInto(e){let t=ob(e.projectDir,e.cwd,e.configFile);e.lastWarning=sb(e.projectDir,e.cwd);let n;try{n=this.buildState(e,t)}catch(n){e.lastError=n instanceof Bm||n instanceof Error?n.message:String(n),this.refreshWatcher(e,t);return}if(e.state?.registry.dispose(),e.state?.validatorDisposers.forEach(e=>e()),e.lastError=null,e.state=n,n.compiled.loadWarnings.length>0){let t=n.compiled.loadWarnings.join(`
|
|
163
|
+
`);n.push(e[0]);for(let r=1;r<e.length;r++)t.push(n),n=[e[r]]}return t.push(n),t}function kS(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?[]:[t.flatMap(e=>e[0]??[]),...t.flatMap(e=>e.slice(1))]}}const AS={container:{compile(e,t){return{kind:`container`,direction:e.direction,when:t.when,children:e.children.map((e,n)=>t.compileChild(e,`${t.path}.children[${n}]`))}},render(e,t){return kS(e.direction,e.children.map(e=>t.renderChild(e,t.visible)))}},segment:{compile(e,t){return{kind:`segment`,when:t.when,name:e.name}},render(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,a=t.nextHueShift();if(!t.visible)return[];try{if(!Gx(i.when,t.scope))return[];let n=i.palette===void 0?t.look:Da,o=Vx(i.palette??t.basePalette,{...n,hueShift:n.hueShift+a}),s=t.enterSegment(e.name,o,i.bg,i.fg),c=i.template.evaluate(t.scope),l=t.exitSegment(c),u=l.length>0?t.focusTint(s):s,d={width:r.width??`auto`,justify:r.justify??`left`,truncate:r.truncate??`right`,baseStyle:u,padding:t.padding},f=OS(Hx(c,u)).map(e=>qx(e,d)),p=l.map(e=>qx(Hx([e],u),d)),m=[...f,...p];return t.perSegmentSink!==void 0&&t.perSegmentSink.set(e.name,m.flat()),m}catch(n){let r=n.message??String(n);return t.onSegmentError?.(e.name,r),[[new Ho(`⚠ ${e.name}: ${r}`)]]}}}};function jS(e){return AS[e]}function MS(e){if(`ttl`in e)return{kind:`ttl`,durationMs:Sx(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 NS(e,t,n,r){switch(n.kind){case`literal`:e.declareLiteral(t,n.value);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,regex:n.regex,cache:MS(n.cache),varDefault:n.default});break;case`shell`:e.declareShell(t,n.command,{regex:n.regex,cache:MS(n.cache),varDefault:n.default});break;case`template`:e.declareTemplate(t,n.template,{varDefault:n.default});break;case`time`:e.declareTime(t,{format:n.layout,ttlMs:n.cache?Sx(n.cache.ttl):void 0,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 PS(e,t){let n=kl.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}function FS(e,t,n){let r=n?.cwd??process.cwd(),i={store:t.variableStore,compiled:new Map,stripStyle:`powerline`,padding:1},a=TS(),o={action:i,activeSegment:a},s=Object.keys(e.looks),c=Jc(e.presets),l=new Map([...Fy(e),...Tv(e)]),u=vx({...dS(i),...vS(i),...wS(o),...DS(a),looks:{fn:()=>s,argTypes:[]},presets:{fn:()=>c,argTypes:[]}},n?.clock),d=PS(u,e.helpers),f=e=>u.parse(e,d),p=new Map;for(let[t,n]of Object.entries(e.variables))n.kind===`state`&&!p.has(n.key)&&p.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`&&!p.has(r.key)&&p.set(r.key,`${t}.${e}`);i.compiled=$x(f,e.actions,p,l);let m=[];for(let[n,i]of Object.entries(e.variables))try{NS(t,n,i,r)}catch(e){m.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{NS(t,`${n}.${e}`,a,r)}catch(t){m.push(`Variable "${n}.${e}": ${t.message??String(t)}`)}let h=Object.create(null);for(let[t,n]of Object.entries(e.segments)){let e=(e,n)=>{try{return f(e)}catch(e){throw Error(`Template parse error in segments.${t}.${n}: ${e.message}`,{cause:e})}};h[t]={when:n.when===void 0?void 0:e(n.when,`when`),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`),palette:n.palette===void 0?void 0:Bx(n.palette)}}let g=(e,t,n)=>{try{return f(e)}catch(e){throw Error(`Template parse error in ${t}.${n}: ${e.message}`,{cause:e})}},_=(e,t)=>{let n={path:t,when:e.when===void 0?void 0:g(e.when,t,`when`),compileChild:_};return jS(e.kind).compile(e,n)},v=new Map;for(let t of c){let{node:n,path:r}=Zc(e,t);v.set(t,_(n,r))}return{segments:h,roots:v,activeSegment:a,menuRuntime:o,loadWarnings:m}}function IS(e){let t=e.bgcolor;return t===void 0?e:new G({bgcolor:ua.fromRgba(Ka(t.getTruecolor(),1)),color:e.color})}function LS(e,t,n,r,i,a,o,s,c){let{perSegmentSink:l,onSegmentError:u}=s??{},{look:d=Da,preset:f=Kc}=c??{};r.applyInput({...i,term:{cols:o.width}}),t.menuRuntime.action.stripStyle=o.style,t.menuRuntime.action.padding=o.padding;let p=yx(n),m=n.has(`hue.step`)?Number(n.read(`hue.step`)):0,h=Number.isFinite(m)?m:0;l?.clear();let g={value:0},_=()=>{let e=g.value*h;return g.value+=1,e},v=n=>{let r=e.segments[n],i=t.segments[n];return r!==void 0&&i!==void 0?{seg:r,compiled:i}:void 0},y=(e,n,r,i)=>Yx(t.activeSegment,e,n,r,i,p),b=e=>(t.activeSegment.current=null,bS(e)),x=(e,t)=>{let n={scope:p,basePalette:a,look:d,visible:t&&Gx(e.when,p),padding:o.padding,nextHueShift:_,perSegmentSink:l,onSegmentError:u,enterSegment:y,exitSegment:b,focusTint:IS,lookupSegment:v,renderChild:x};return jS(e.kind).render(e,n)},S=t.roots.get(f);if(S===void 0)throw Error(`Preset "${f}" has no compiled layout — registerDslConfig compiles one per declared preset and effectivePresetName collapses unknown names to "${Kc}"; a miss here is merge/policy drift (have: ${[...t.roots.keys()].join(`, `)})`);return x(S,!0).map(e=>ch(e,o)).join(`
|
|
164
|
+
`)}const RS=/^-?\d+$/;function zS(e,t,n){return e===void 0?t:Math.max(t,Math.min(n,e))}function BS(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 VS(e){return t=>{if(!t)return{ok:!1,reason:`${e} value is required`};if(!RS.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 HS(e,t,n){return r=>r?RS.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 US(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=>!RS.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,seed:zS(r[0].seed,t,i)}}return{kind:`int`}}function WS(e){return e===`config`?`set-config`:`set-state`}function GS(e,t,n){return t.kind===`int`?VS(`menu page "${e}"`):t.kind===`range`?HS(t.min,t.max,`${n} stepper "${e}"`):BS(t.allowed,`${n} "${e}"`,WS(n))}function KS(e,t,n){return GS(e,US(e,t,n),n)}function qS(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:US(e,n,t)}))}function JS(e,t=`state`){let n=new Map(Object.entries(e).map(([e,t])=>[e,{validator:t,permanent:!0}]));function r(){let e=[];for(let[t,r]of n)r.permanent&&e.push(t);return e}return{register(e,i){if(!e)throw Error(`register: key is required`);if(e.includes(`/`))throw Error(`register: key "${e}" contains "/" — the wire shape splits on "/" so a slash-bearing key cannot be addressed. Use a slash-free key.`);let a=n.get(e);if(a){if(a.permanent)throw Error(`register: key "${e}" is a built-in ${t} key and cannot be re-claimed (built-in keys: ${[...r()].join(`, `)})`);if(a.kind!==i.kind)throw Error(`register: key "${e}" is already a ${a.kind} ${t} key; cannot also register it as ${i.kind}. A ${t} key has one key shape — a menu page index (int) and a button allow-list cannot share a key.`);a.specs.push(i),a.validator=KS(e,a.specs,t)}else{let r=[i];n.set(e,{permanent:!1,kind:i.kind,validator:KS(e,r,t),specs:r})}let o=!0;return()=>{if(!o)return;o=!1;let r=n.get(e);if(!r||r.permanent)return;let a=r.specs.indexOf(i);a>=0&&r.specs.splice(a,1),r.specs.length===0?n.delete(e):r.validator=KS(e,r.specs,t)}},validate(e,r){let i=n.get(e);return i?i.validator(r):{ok:!1,reason:`unknown ${t} key "${e}" (have: ${[...n.keys()].join(`, `)})`}},listKeys(){return[...n.keys()]},listBaselineKeys(){return r()},rangeParamsFor(e){let r=n.get(e);if(!r||r.permanent||r.kind!==`range`)return null;let i=US(e,r.specs,t);if(i.kind!==`range`)throw Error(`rangeParamsFor: key "${e}" holds range specs but the merge produced a ${i.kind} spec — the entry-kind invariant is broken.`);return{min:i.min,max:i.max,seed:i.seed}}}}const YS=Sc(),XS=new Set(YS),ZS=new Set(Ec),QS=e=>e?XS.has(e)?{ok:!0,value:e}:{ok:!1,reason:`unknown theme "${e}" (have: ${YS.join(`, `)})`}:{ok:!1,reason:`theme name is required`},$S=e=>e?ZS.has(e)?{ok:!0,value:e}:{ok:!1,reason:`unknown style "${e}" (have: ${Ec.join(`, `)})`}:{ok:!1,reason:`style name is required`},eC=new Set([`1`,`true`]),tC=new Set([`0`,`false`]),nC=JS({style:$S,theme:QS,"toolbar-expanded":e=>eC.has(e)?{ok:!0,value:`1`}:tC.has(e)?{ok:!0,value:``}:{ok:!1,reason:`expected boolean-ish (1, 0, true, false), got "${e}"`}});function rC(){return nC.listKeys()}function iC(e,t){return nC.register(e,t)}function aC(e,t){return nC.validate(e,t)}function oC(e){return nC.rangeParamsFor(e)}function sC(e,t,n){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:Ly(e.from,n)}}]:`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,seed:zS(t.get(e.set),e.min,e.max)}}]:[]}function cC(e){let t=new Set(nC.listBaselineKeys());return e.filter(e=>e.spec.kind!==`allow-list`||!t.has(e.key))}function lC(e){let t=new Map,n=/^-?\d+$/;for(let r of Object.values(e.variables)){if(r.kind!==`state`)continue;let e=r.default;e!==void 0&&n.test(e)&&t.set(r.key,parseInt(e,10))}for(let[n,r]of ug(e.globals))t.set(n,r);return t}function uC(e){let t=lC(e),n=Fy(e);return cC(Object.values(e.actions).flatMap(Iv).flatMap(e=>sC(e,t,n)))}function dC(e){return qS(uC(e))}const fC=JS({},`config`);function pC(){return fC.listKeys()}function mC(e,t){return fC.validate(e,t)}function hC(e){return fC.rangeParamsFor(e)}function gC(e,t,n){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:Ly(e.from,n)}}]:`cycle`in e?[{key:e.persist,spec:{kind:`allow-list`,allowed:e.cycle}}]:`removeSegment`in e?[{key:e.persist,spec:{kind:`allow-list`,allowed:[zc({op:`remove`,target:e.removeSegment})]}}]:`insertSegment`in e?[{key:e.persist,spec:{kind:`allow-list`,allowed:[zc({op:`insert`,segment:e.insertSegment,anchor:e.anchor,relation:e.relation})]}}]:`insertSegmentFrom`in e?[{key:e.persist,spec:{kind:`allow-list`,allowed:Ly(e.insertSegmentFrom,n).map(t=>zc({op:`insert`,segment:t,anchor:e.anchor,relation:e.relation}))}}]:[{key:e.persist,spec:{kind:`range`,min:e.min,max:e.max,seed:zS(t.get(e.persist),e.min,e.max)}}]:[]}function _C(e){return ug(e.globals)}function vC(e){let t=new Set;for(let n of bC(e)){let e=`persist`in n?n.persist:`reset`in n?n.reset:null;if(e===null)continue;let r=N_(e);r?.scope===`preset-root-ops`&&t.add(r.preset)}return[...t].map(e=>({key:M_(e),spec:{kind:`allow-list`,allowed:[]}}))}function yC(e){let t=_C(e),n=new Map([...Fy(e),...Tv(e)]);return[...vC(e),...bC(e).flatMap(e=>gC(e,t,n))]}function bC(e){return Object.values(e.actions).flatMap(Iv)}function xC(e){return qS(yC(e),`config`)}function SC(e,t){return fC.register(e,t)}const CC=(e,t)=>O(t),wC={default_bg:`string`,default_fg:`string`,default_empty_value:`string`,default_separator:`string`,default_truncate_marker:`string`,palette:`string`,look:`string`,preset:`string`,style:`string`,autoWrap:`boolean`,padding:`number`,charset:`string`,colorCompatibility:`string`},TC=new Set([`1`,`true`]),EC=new Set([`0`,`false`,``]);function DC(e,t){let n=N_(e);if(n===null)throw Error(`coercePersistValue: "${e}" is not a valid persist target`);if(n.scope===`segment-palette`||n.scope===`preset-root-ops`)return t;let r=wC[n.field];if(r===`string`)return t;if(r===`number`){let n=Number(t);if(!Number.isFinite(n))throw Error(`coercePersistValue: "${e}" expects a number, got "${t}"`);return n}if(TC.has(t))return!0;if(EC.has(t))return!1;throw Error(`coercePersistValue: "${e}" expects boolean-ish (1, 0, true, false), got "${t}"`)}function OC(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;for(let[t,n]of Object.entries(e)){let e=N_(t);if(e===null)return!1;let r=e.scope===`globals`?wC[e.field]:`string`;if(r===`number`&&typeof n!=`number`||r===`boolean`&&typeof n!=`boolean`||r===`string`&&typeof n!=`string`)return!1}return!0}function kC(e,t){let n;try{n=r.readFileSync(e,`utf8`)}catch(e){let n=e.code;return n!==`ENOENT`&&t(`warn`,`config-overrides read failed (${n}); starting empty`),{}}try{let e=JSON.parse(n);return OC(e)?e:(t(`warn`,`config-overrides load: unexpected shape, starting empty`),{})}catch{return t(`warn`,`config-overrides load: corrupt JSON, starting empty`),{}}}function AC(e){let t=Object.create(null);for(let[n,r]of Object.entries(e))sg(n)&&(t[n]=r);return t}function jC(e){let t=Object.create(null);for(let[n,r]of Object.entries(e)){let e=N_(n);e?.scope===`segment-palette`&&typeof r==`string`&&(t[e.segment]=r)}return t}function MC(e,t){let n=Object.create(null);for(let[r,i]of Object.entries(e)){let e=N_(r);if(!(e?.scope!==`preset-root-ops`||typeof i!=`string`)){try{let t=JSON.parse(i);if(Array.isArray(t)&&t.every(e=>typeof e==`string`)){n[e.preset]=t;continue}}catch{}t(`warn`,`config-overrides: "${r}" is not a valid op-token list, dropping`)}}return n}function NC(e,t=CC){return AC(kC(e,t))}function PC(e,t=CC){let n=kC(e,t);return{globals:AC(n),segmentPalette:jC(n),presetRootOps:MC(n,t)}}function FC(e,t,n,i){try{r.mkdirSync(c.dirname(e),{recursive:!0});let t=`${e}.tmp`;r.writeFileSync(t,JSON.stringify(n),{mode:384}),r.chmodSync(t,384),r.renameSync(t,e)}catch(e){let n=`${t} write failed: ${e.message}`;throw i(`error`,n),Error(n)}}function IC(e,t,n){FC(e,`config-overrides`,t,n)}function LC(e,t,n,r){let i=kC(e,r),a=i[t];if(n===void 0){if(!(t in i))return a;let n={...i};delete n[t],IC(e,n,r)}else IC(e,{...i,[t]:n},r);return a}function RC(e,t,n,r=CC){YC(e,{key:t,from:LC(e,t,n,r)??null,to:n},r)}function zC(e,t,n=CC){t in kC(e,n)&&YC(e,{key:t,from:LC(e,t,void 0,n)??null,to:null},n)}function BC(e,t,n,r){LC(e,t,n===null?void 0:n,r)}const VC={past:[],future:[]};function HC(e){return c.join(c.dirname(e),`config-overrides-history.json`)}function UC(e){return e===null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`}function WC(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.key==`string`&&UC(t.from)&&UC(t.to)}function GC(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=e;return Array.isArray(t.past)&&t.past.every(WC)&&Array.isArray(t.future)&&t.future.every(WC)}function KC(e,t){let n=HC(e),i;try{i=r.readFileSync(n,`utf8`)}catch(e){let n=e.code;return n!==`ENOENT`&&t(`warn`,`config-overrides-history read failed (${n}); starting empty`),VC}try{let e=JSON.parse(i);return GC(e)?e:(t(`warn`,`config-overrides-history load: unexpected shape, starting empty`),VC)}catch{return t(`warn`,`config-overrides-history load: corrupt JSON, starting empty`),VC}}function qC(e,t,n){FC(HC(e),`config-overrides-history`,t,n)}function JC(e,t,n){let r=[...e,t];return r.length>n?r.slice(r.length-n):r}function YC(e,t,n){qC(e,{past:JC(KC(e,n).past,t,50),future:[]},n)}function XC(e,t=CC){let n=KC(e,t),r=n.past[n.past.length-1];return r===void 0?null:(BC(e,r.key,r.from,t),qC(e,{past:n.past.slice(0,-1),future:JC(n.future,r,50)},t),r)}function ZC(e,t=CC){let n=KC(e,t),r=n.future[n.future.length-1];return r===void 0?null:(BC(e,r.key,r.to,t),qC(e,{past:JC(n.past,r,50),future:n.future.slice(0,-1)},t),r)}var QC=class{kind=`box`;cell;lastSetAt;constructor(e,t,n){this.name=e,this.type=t,ew(e,t,n,`initial value`),this.cell=q.observable.box(n,{deep:!1}),this.lastSetAt=Date.now()}read(){return this.cell.get()}set(e){ew(this.name,this.type,e,`set value`),this.cell.set(e),this.lastSetAt=Date.now()}lastUpdatedMs(){return this.lastSetAt}},$C=class{kind=`computed`;cell;constructor(e,t,n){this.name=e,this.type=t,this.cell=(0,q.computed)(()=>{let e=n();return ew(this.name,this.type,e,`computed result`),e},{keepAlive:!0})}read(){return this.cell.get()}lastUpdatedMs(){return null}};function ew(e,t,n,r){let i=ex(n);if(i!==t)throw TypeError(`Variable "${e}": ${r} type ${i} does not match declared type ${t}`)}var tw=class{nodes=new Map;defineBox(e,t,n){this.assertNotDefined(e),this.nodes.set(e,new QC(e,t,n))}defineComputed(e,t,n){this.assertNotDefined(e);let r=e=>this.read(e);this.nodes.set(e,new $C(e,t,()=>n(r)))}read(e){return this.requireNode(e).read()}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,q.runInAction)(()=>n.set(t))}runInAction(e){(0,q.runInAction)(e)}has(e){return this.nodes.has(e)}getType(e){return this.requireNode(e).type}getKind(e){return this.requireNode(e).kind}getNode(e){let t=this.requireNode(e);return{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}assertNotDefined(e){if(this.nodes.has(e))throw Error(`Variable "${e}" is already declared`)}};function nw(e,t,n){return e+`\0`+t+`\0`+(n??``)}var rw=class{entries=new Map;deps;maxEntries;constructor(e,t={}){this.deps=e,this.maxEntries=t.maxEntries??256}getOrCreate(e,t,n){let r=nw(e,t,n),i=this.entries.get(r);if(i)return this.entries.delete(r),this.entries.set(r,i),i;let a={projectDir:e,cwd:t,configFile:n,configFilePath:null,lastError:null,lastWarning:null,state:null,watcher:null};if(this.reloadInto(a),this.entries.set(r,a),this.entries.size>this.maxEntries){let e=this.entries.keys().next().value;if(e!==void 0){let t=this.entries.get(e);t?.state?.registry.dispose(),t?.state?.validatorDisposers.forEach(e=>e()),t?.watcher?.release(),this.entries.delete(e)}}return a}reloadInto(e){let t=ub(e.projectDir,e.cwd,e.configFile);e.lastWarning=db(e.projectDir,e.cwd);let n;try{n=this.buildState(e,t)}catch(n){e.lastError=n instanceof Wm||n instanceof Error?n.message:String(n),this.refreshWatcher(e,t);return}if(e.state?.registry.dispose(),e.state?.validatorDisposers.forEach(e=>e()),e.lastError=null,e.state=n,n.compiled.loadWarnings.length>0){let t=n.compiled.loadWarnings.join(`
|
|
165
165
|
`);e.lastWarning=e.lastWarning?e.lastWarning+`
|
|
166
|
-
`+t:t}this.refreshWatcher(e,t)}buildState(e,t){let{config:n,source:r}=cb(t,Yb),i=AC(Me(),j),a=Gh(Wh({globals:$c(i.globals,n.presets)},n),i.segmentPalette),o=el(i.presetRootOps,n.presets),s=lb(nl(a,o),t??`<default>`,r),c=new ZC,l=new Nx(c,s.globals.default_empty_value??``,this.deps.gitService,this.deps.sessionState),u,d=[];try{u=jS(s,l,{cwd:e.cwd});for(let{key:e,spec:t}of sC(s))d.push(eC(e,t));for(let{key:e,spec:t}of _C(s))d.push(vC(e,t))}catch(e){for(let e of d)e();throw l.dispose(),e}return{config:s,store:c,registry:l,compiled:u,neededInputPaths:Ob(s),lastRenderCellsBySegment:new Map,validatorDisposers:d,presetRootOps:o}}refreshWatcher(e,t){(t!==e.configFilePath||e.watcher===null)&&(e.configFilePath=t,this.rebindWatcher(e,t))}rebindWatcher(e,t){e.watcher&&=(e.watcher.release(),null);let n=[...ab(e.projectDir,e.cwd,e.configFile),Me()],i=new Map;for(let e of n){let t=c.dirname(e);if(!r.existsSync(t))continue;let n=c.basename(e);i.has(t)||i.set(t,new Set),i.get(t).add(n)}let a=[...i.entries()].map(([e,t])=>({path:e,filenames:[...t]})),o=`config:${e.projectDir}:${e.cwd}:${e.configFile??``}:${t??`<none>`}`;e.watcher=this.deps.watchers.acquire(o,{files:t===null?[]:[t],dirs:a},()=>this.onConfigChanged(e))}onConfigChanged(e){j(`info`,`config change detected for entry projectDir=${e.projectDir} cwd=${e.cwd}`),this.reloadInto(e)}get size(){return this.entries.size}firstPopulatedState(){for(let e of this.entries.values())if(e.state!==null)return e.state;return null}};const ew=16384;var tw=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<ew){this.rollingTimestamps.push(e);return}this.rollingTimestamps[this.rollingHead]=e,this.rollingHead=(this.rollingHead+1)%ew}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: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},watchers:{active:e.watchersActive,opened:this.watchersOpened,closed:this.watchersClosed,evicted:this.watchersEvicted},subprocesses:this.snapshotSubprocesses(),nextRestartReason:e.nextRestartReason??null}}};const nw={load:()=>({}),save:()=>{},flush:()=>{}};function rw(e){let t=new Map;for(let[n,r]of Object.entries(e))t.set(n,new Map(Object.entries(r)));return t}var iw=class{sessions;storage;atom=(0,q.createAtom)(`SessionState`);constructor(e=nw,t=256){this.maxSessions=t,this.storage=e,this.sessions=new Map,this.hydrateFromStorage()}useStorage(e){this.storage=e,this.hydrateFromStorage()}hydrateFromStorage(){this.sessions=rw(this.storage.load()),this.evictOldest(),this.persist()}get(e,t){this.atom.reportObserved();let n=this.sessions.get(e);return n?(this.touch(e,n),n.get(t)??null):null}set(e,t,n){this.setBatch(e,[{key:t,value:n}])}setBatch(e,t){t.length!==0&&(0,q.runInAction)(()=>{let n=this.sessions.get(e)??new Map;for(let{key:e,value:r}of t)n.set(e,r);this.touch(e,n),this.evictOldest(),this.persist(),this.atom.reportChanged()})}clear(e,t){(0,q.runInAction)(()=>{let n=this.sessions.get(e);n&&(n.delete(t),n.size===0?this.sessions.delete(e):this.touch(e,n)),this.persist(),this.atom.reportChanged()})}prune(e){(0,q.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,n]of this.sessions)e[t]=Object.fromEntries(n);return e}};const aw=(e,t)=>O(t);function ow(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 sw=class{timer=null;pending=null;constructor(e,t=500,n=aw){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 ow(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(c.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}`)}}},$=class extends Error{constructor(e){super(e),this.name=`BadVerbArgs`}};function cw(e){if(!e)throw new $(`session id is required`);if(e.includes(`/`)||e.includes(`..`))throw new $(`invalid session id "${e}"`);return e}function lw(e){return uw(()=>decodeURIComponent(e))}function uw(e){try{return e()}catch(e){throw e instanceof URIError?new $(`malformed wire encoding: ${e.message}`):e}}function dw(e,t){let n=be({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 fw=(e,t)=>dw(lw(e),t),pw=(e,t)=>{let n=be({bin:`/usr/bin/open`,args:[`-a`,`Visual Studio Code`,lw(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`})`)}},mw=(e,t)=>dw(lw(e),t),hw=(e,t)=>dw(lw(e),t),gw=(e,t)=>{let n=cw(lw(e));t.sessionState.get(n,`toolbar-expanded`)?t.sessionState.clear(n,`toolbar-expanded`):t.sessionState.set(n,`toolbar-expanded`,`1`)},_w=(e,t)=>{let[n=``,...r]=uw(()=>Kt(e)),i=cw(n);if(r.length===0)throw new $(`set-state: <key>/<value> is required (have keys: ${$S().join(`, `)})`);if(r.length%2!=0)throw new $(`set-state: expected even-count <key>/<value> pairs, got ${r.length} segment(s) after session id (have keys: ${$S().join(`, `)})`);let a=[];for(let e=0;e<r.length;e+=2){let t=r[e],n=r[e+1];if(!t)throw new $(`set-state: empty key at pair ${e/2+1} (expected <sessionId>/<key>/<value>[/<key>/<value>...] segments)`);let i=tC(t,n);if(!i.ok)throw new $(`set-state: pair ${e/2+1}: ${i.reason}`);a.push({key:t,value:i.value})}t.sessionState.setBatch(i,a);let o=a.map(e=>`${e.key}=${e.value}`).join(` `);t.dlog(`info`,`set-state: ${o} (session=${i})`)},vw=/^-?\d+$/;function yw(e,t,n){return e>n?t:e<t?n:e}function bw(e,t,n,r){if(e){if(!$S().includes(e))throw new $(`${r}: unknown session key "${e}" to release (have: ${$S().join(`, `)})`);n.sessionState.clear(t,e),n.dlog(`info`,`${r}: released session key ${e} (session=${t})`)}}const xw=(e,t)=>{let[n=``,r=``,i=``]=uw(()=>Kt(e)),a=cw(n);if(!r)throw new $(`step-state: <key> is required (shape: <sessionId>/<key>/<by>)`);if(!vw.test(i))throw new $(`step-state: delta must be an integer, got "${i}"`);let o=parseInt(i,10),s=nC(r);if(!s)throw new $(`step-state: key "${r}" is not a bounded (range) state key (have keys: ${$S().join(`, `)})`);let c=t.sessionState.get(a,r),l=c&&vw.test(c)?Math.max(s.min,Math.min(s.max,parseInt(c,10))):s.seed,u=yw(l+o,s.min,s.max),d=tC(r,String(u));if(!d.ok)throw new $(`step-state: ${d.reason}`);t.sessionState.set(a,r,d.value),t.dlog(`info`,`step-state: ${r} ${l}→${d.value} (by ${o}, session=${a})`)};function Sw(e){if(!rg(e))throw Error(`step-config: "${e}" validated as a bounded config-writable key but is not a Globals field — registration/loader invariant broken`)}const Cw=(e,t)=>{let[n=``,r=``,i=``,a=``]=uw(()=>Kt(e)),o=cw(n);if(!r)throw new $(`set-config: <key>/<value> is required (have keys: ${lC().join(`, `)})`);let s=uC(r,i);if(!s.ok)throw new $(`set-config: ${s.reason}`);let c=CC(r,s.value);PC(Me(),r,c,t.dlog),t.dlog(`info`,`set-config: ${r}=${s.value} (session=${o})`),bw(a,o,t,`set-config`)},ww=(e,t)=>{let[n=``,r=``,i=``,a=``]=uw(()=>Kt(e)),o=cw(n);if(!r)throw new $(`step-config: <key> is required (shape: <sessionId>/<key>/<by>)`);if(!vw.test(i))throw new $(`step-config: delta must be an integer, got "${i}"`);let s=parseInt(i,10),c=dC(r);if(!c)throw new $(`step-config: key "${r}" is not a bounded (range) config key (have keys: ${lC().join(`, `)})`);Sw(r);let l=kC(Me(),t.dlog)[r],u=typeof l==`number`?Math.max(c.min,Math.min(c.max,l)):c.seed,d=yw(u+s,c.min,c.max),f=uC(r,String(d));if(!f.ok)throw new $(`step-config: ${f.reason}`);let p=CC(r,f.value);PC(Me(),r,p,t.dlog),t.dlog(`info`,`step-config: ${r} ${u}→${f.value} (by ${s}, session=${o})`),bw(a,o,t,`step-config`)},Tw=(e,t)=>{let[n=``,r=``]=uw(()=>Kt(e)),i=cw(n);if(!r||!lC().includes(r))throw new $(`reset-config: unknown config key "${r}" (have: ${lC().join(`, `)})`);FC(Me(),r,t.dlog),t.dlog(`info`,`reset-config: ${r} (session=${i})`)},Ew=(e,t)=>{let[n=``,r=``,i=``]=uw(()=>Kt(e)),a=cw(n);if(!r)throw new $(`apply-layout-op: <key>/<op> is required (have: ${lC().join(`, `)})`);let o=uC(r,i);if(!o.ok)throw new $(`apply-layout-op: ${o.reason}`);let s=k_(r);if(s===null||s.scope!==`preset-root-ops`)throw new $(`apply-layout-op: "${r}" is not a "presets.<name>.rootOps" target`);let c=AC(Me(),t.dlog).presetRootOps[s.preset]??[],l=JSON.stringify([...c,o.value]);PC(Me(),r,l,t.dlog),t.dlog(`info`,`apply-layout-op: ${r} += ${o.value} (session=${a})`)},Dw=(e,t)=>{let[n=``]=uw(()=>Kt(e)),r=cw(n),i=KC(Me(),t.dlog);if(i===null)throw new $(`undo: history is empty, nothing to undo`);t.dlog(`info`,`undo: ${i.key} (session=${r})`)},Ow=(e,t)=>{let[n=``]=uw(()=>Kt(e)),r=cw(n),i=qC(Me(),t.dlog);if(i===null)throw new $(`redo: nothing to redo`);t.dlog(`info`,`redo: ${i.key} (session=${r})`)},kw=`config-override`,Aw=new Map([[Ft,fw],[`load-config`,(e,t)=>{let n=e.indexOf(`/`);if(n===-1)throw new $(`load-config: expected <sessionId>/<path> (missing separator)`);let r=cw(uw(()=>decodeURIComponent(e.slice(0,n)))),i=uw(()=>decodeURIComponent(e.slice(n+1))).trim();if(i!==``){if(!i.startsWith(`/`))throw new $(`load-config: path must be absolute, got "${i}"`);if(!/\.(json5?|json)$/.test(i))throw new $(`load-config: path must end with .json5 or .json, got "${i}"`)}i===``?(t.sessionState.clear(r,kw),t.dlog(`info`,`load-config: override cleared (session=${r})`)):(t.sessionState.set(r,kw,i),t.dlog(`info`,`load-config: ${i} (session=${r})`))}],[It,pw],[Pt,_w],[N,xw],[zt,Cw],[Bt,ww],[Vt,Tw],[Ht,Ew],[Ut,Dw],[Wt,Ow],[Lt,mw],[Rt,hw],[`toolbar-toggle`,gw]]),jw=(e,t)=>{let n=[],r=!1,i=null;for(let{verb:a,value:o}of Jt(e)){if(!i&&(a===`set-state`||a===`step-state`||a===`set-config`||a===`step-config`||a===`reset-config`||a===`apply-layout-op`||a===`undo`||a===`redo`||a===`toolbar-toggle`)){let e=Kt(o);e.length>0&&e[0]&&(i=e[0])}let e=Aw.get(a);if(!e){n.push(`unknown effect verb "${a}"`);continue}try{e(o,t)}catch(e){e instanceof $||(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(`
|
|
167
|
-
`));let e=`dispatch: ${n.join(`; `)}`;throw r?Error(e):new $(e)}},Mw=new Map([...Aw,[M,jw]]);Object.freeze([...Mw.keys()]);const Nw=new Set([`hook_event_name`,`session_id`,`session_name`,`transcript_path`,`cwd`,`model`,`workspace`,`version`,`output_style`,`cost`,`context_window`,`exceeds_200k_tokens`,`effort`,`thinking`,`rate_limits`,`vim`,`agent`,`worktree`]),Pw=[[`session_id`,`string`],[`transcript_path`,`string`],[`cwd`,`string`],[`model`,`object`],[`model.id`,`string`],[`model.display_name`,`string`],[`workspace`,`object`],[`workspace.current_dir`,`string`],[`workspace.project_dir`,`string`]];function Fw(e){let t={missingRequired:[],typeMismatches:[],unknownTopLevelFields:[]},n=typeof e==`object`&&e&&!Array.isArray(e)?e:{};for(let[e,r]of Pw){let i=Iw(n,e);if(i==null)t.missingRequired.push(e);else{let n=Array.isArray(i)?`array`:typeof i;(r===`object`?n!==`object`:n!==r)&&t.typeMismatches.push({path:e,expected:r,got:n})}}for(let e of Object.keys(n))Nw.has(e)||t.unknownTopLevelFields.push(e);return{data:e,report:t}}function Iw(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 Lw(e,t){switch(e){case`vars`:return{what:e,vars:Rw(t)};case`segments`:return{what:e,segments:Hw(t)};case`config`:return{what:e,config:Gw(t)}}}function Rw(e){if(e===null)return[];let{store:t,registry:n,config:r}=e,i=Bw(r),a=t.names().sort(),o=[];for(let e of a){let r=t.getNode(e),a=n.getLastError(e);o.push({name:e,source:i.get(e)??null,type:r.type,value:r.read(),lastError:a===void 0?null:{timestampMs:a.timestamp,message:a.message},ageMs:zw(r.lastUpdatedMs())})}return o}function zw(e){return e===null?null:Math.max(0,Date.now()-e)}function Bw(e){let t=new Map;for(let[n,r]of Object.entries(e.variables))t.set(n,Vw(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}`,Vw(i));return t}function Vw(e){return e.kind}function Hw(e){if(e===null)return[];let{store:t,config:n,lastRenderBySegment:r}=e,i=new Set(t.names()),a=Uw(n),o=[];for(let e of a){let t=n.segments[e];t&&o.push({name:e,template:t.template,referencedVars:Ww(t.template,i),lastRender:r.get(e)??null})}return o}function Uw(e){let t=[],n=new Set;for(let r of oh(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 Ww(e,t){let n=new Set;for(let r of Ly(e)){if(t.has(r)){n.add(r);continue}let e=r.split(`.`);for(;e.length>1;){e.pop();let r=e.join(`.`);if(t.has(r)){n.add(r);break}}}return Array.from(n).sort()}function Gw(e){return e===null?null:e.config}const Kw=[`vars`,`segments`,`config`];function qw(e){return typeof e==`string`&&Kw.includes(e)}function Jw(e){return Math.max(1,e-2)}var Yw=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 O(`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);O(`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{O(`Calculating context tokens from transcript: ${e}`);let n=await Wr(e);if(n.length===0)return O(`No entries in transcript`),B;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,O(`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 O(`Most recent main chain context: ${n} tokens (limit: ${t})`),z({totalTokens:n,maxTokens:t,...this.ratioPercentages(n,t)})}return O(`No main chain entries with usage data found`),B}catch(e){return Xn(`context transcript: ${e instanceof Error?e.message:String(e)}`)}}async getContextInfo(e){let t=this.calculateContextFromHookData(e);if(t)return z(t);let n=e.context_window?.context_window_size??2e5;return this.calculateContextTokensFromTranscript(e.transcript_path,n)}};function Xw(e){let t=e.type||e.message?.role||e.message?.type,n=e.type===`user`&&e.message?.firstContentType===`tool_result`;return t===`user`&&!n}var Zw=class{state=new Map;calculateLastResponseTime(e){if(e.length===0)return null;let t=null,n=null;for(let r of e){let e=r.type||r.message?.role||r.message?.type;if(Xw(r))t=r.timestamp;else if(e===`assistant`&&t){let e=(r.timestamp.getTime()-t.getTime())/1e3;e>.1&&e<300&&(n=e)}}return n}async foldMetrics(e,t){let n=this.state.get(e),r=Mr(t);if(n&&r!==0&&n.cursor.mtimeMs===r)return this.state.delete(e),this.state.set(e,n),{kind:`ok`,value:{messageCount:n.messageCount,recent:[...n.recent]}};let i=await Jr(t,n?.cursor);if(i.kind===`failed`)return i;if(i.kind===`absent`)return{kind:`ok`,value:{messageCount:n?.messageCount??0,recent:[...n?.recent??[]]}};let{entries:a,cursor:o,reset:s}=i.value,c=n&&!s?n:void 0,l=c?.messageCount??0,u=c?[...c.recent]:[];for(let e of a)e.isSidechain||(Xw(e)&&l++,u.push(e));for(u.length>20&&(u=u.slice(-20)),this.state.delete(e),this.state.set(e,{cursor:o,messageCount:l,recent:u});this.state.size>256;){let e=this.state.keys().next().value;if(e===void 0)break;this.state.delete(e)}return{kind:`ok`,value:{messageCount:l,recent:[...u]}}}async getMetricsInfo(e,t){if(O(`Getting metrics from hook data for session: ${e}`),!t.cost)return B;let n=await this.foldMetrics(e,t.transcript_path);return n.kind===`failed`?Xn(`metrics (${e}): ${n.reason}`):z({responseTime:t.cost.total_api_duration_ms/1e3,lastResponseTime:this.calculateLastResponseTime(n.value.recent),sessionDuration:t.cost.total_duration_ms/1e3,messageCount:n.value.messageCount,linesAdded:t.cost.total_lines_added,linesRemoved:t.cost.total_lines_removed})}};const Qw=new Map;function $w(e){if(!e)return``;let t=e.indexOf(`,`);return t<0?e:e.slice(0,t)}var eT=class{async getSessionId(){if(!process.env.TMUX_PANE)return B;let e=$w(process.env.TMUX),t=Qw.get(e);if(t!==void 0)return t;O(`Getting tmux session ID, TMUX_PANE: ${process.env.TMUX_PANE}`);let n=await ye({bin:`tmux`,args:[`display-message`,`-p`,`#S`],timeoutMs:1e3,category:`tmux`}),r=n.ok?n.stdout.trim()?z(n.stdout.trim()):B:Xn(`tmux display-message: ${n.reason}`);return Qw.set(e,r),r}isInTmux(){return!!process.env.TMUX_PANE}};function tT(e){return e<32||e===127||e>=128&&e<=159}function nT(e,t){let n=``;for(let t of e)n+=tT(t.codePointAt(0)??0)?` `:t;n=n.replace(/\s+/g,` `).trim();let r=``,i=0;for(let e of n){if(i===t)return r.replace(/.$/u,`…`);r+=e,i++}return r}const rT=`\x1B[38;2;255;255;255m`,iT=`\x1B[48;2;200;40;40m`,aT=`\x1B[0m`,oT=new tw;ve(oT.launchStats);const sT=new xr({counters:oT,logger:j}),cT=new Or({watchers:sT,logger:j}),lT=new oi,uT=new iw,dT=new Yw,fT=new Zw,pT=new eT,mT=new $C({gitService:cT,sessionState:uT,watchers:sT});let hT=null,gT=null,_T=0;function vT(){t.on(`uncaughtException`,e=>{j(`error`,`uncaughtException: ${e.stack||e.message}`),kT(1)}),t.on(`unhandledRejection`,e=>{j(`error`,`unhandledRejection: ${String(e)}`),kT(1)});for(let e of[`SIGINT`,`SIGTERM`,`SIGHUP`])t.on(e,()=>{j(`info`,`received ${e}, shutting down`),kT(0)});try{_T=dt(t.env)}catch(e){j(`error`,`refusing to boot: ${e.message}`),kT(1);return}hT=Rn(t.pid);let e=qn(Yn(hT));if(!e.decision.allow){j(`warn`,`fork-bomb breaker: ${e.decision.reason}; refusing to boot`),kT(1);return}gT=e.registryPath,r.mkdirSync(Ee(),{recursive:!0}),ke(De()),uT.useStorage(new sw(je(),500,j)),Vn({anchor:Bn(t.env),isAlive:Hn,onOrphaned:e=>{j(`info`,`parent watchdog: ${e}; shutting down`),kT(0)}}),yT(g.createServer({allowHalfOpen:!1},e=>{AT(e)}),De(),!1)}function yT(e,n,r){e.removeAllListeners(`error`),e.removeAllListeners(`listening`),e.once(`error`,i=>{if(i.code!==`EADDRINUSE`){j(`error`,`server error: ${i.message}`),kT(1);return}if(r){j(`info`,`lost rebind race; another daemon is alive — exiting`),t.exit(0);return}bT(e,n)}),e.listen(n,()=>xT(n))}function bT(e,n){let i=kn(An(A(n)),(e,t)=>Ln(e,t,{readStartTime:L,pidAlive:Hn}));if(i.kind===`attach-and-exit`){j(`info`,`EADDRINUSE: ${i.reason} — exiting`),t.exit(0);return}j(`warn`,`EADDRINUSE: ${i.reason} — unlinking stale socket and rebinding`);try{r.unlinkSync(n)}catch(e){if(e.code!==`ENOENT`){j(`error`,`cannot unlink stale socket ${n}: ${e.message}`),kT(1);return}}yT(e,n,!0)}function xT(e){let n=Nn(e);if(n.kind!==`present`){j(`warn`,`no ownable socket at bind callback (${n.kind}); exiting`),kT(0);return}ET(e);try{r.chmodSync(e,384)}catch(e){j(`warn`,`chmod socket failed: ${e.message}`)}j(`info`,`daemon up: pid=${t.pid} v=3 sock=${e} heapCap=${Math.round(_.getHeapStatistics().heap_size_limit/1048576)}MB rssLimit=${Math.round(_T/1048576)}MB`),Ct(),CT(),TT(),ST(e,n.identity)}function ST(e,n){In({bound:n,myPid:t.pid,readIdentity:()=>Nn(e),readLease:()=>An(A(e)),shutdown:e=>kT(e),log:j}).arm()}function CT(){let e=import.meta.url,n=[];e.startsWith(`file://`)&&n.push(b(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{}if(i.size===0)return;let a=setInterval(()=>{for(let[e,t]of i)try{if(r.statSync(e).mtimeMs!==t){j(`info`,`binary mtime changed (${e}); shutting down`),clearInterval(a),kT(0);return}}catch(e){j(`warn`,`bin stat failed: ${e.message}`)}},6e4);a.unref()}let wT=null;function TT(){wT=ft(mt(oT.startedAt.getTime(),e=>kT(e),{rssLimitBytes:_T})),wT.arm()}function ET(e){let n=jn(A(e),{pid:t.pid,version:3,binPath:t.argv[1],startTime:hT});n!==null&&j(`warn`,`lease write failed: ${n}`)}let DT=0,OT=!1;function kT(e){if(!OT){OT=!0,setTimeout(()=>t.kill(t.pid,`SIGKILL`),500);try{cT.close()}catch(e){j(`warn`,`gitService close failed: ${e.message}`)}try{lT.close()}catch(e){j(`warn`,`usageStore close failed: ${e.message}`)}try{sT.closeAll()}catch(e){j(`warn`,`watcherRegistry close failed: ${e.message}`)}try{uT.flush()}catch(e){j(`warn`,`sessionState flush failed: ${e.message}`)}Mn(Ae(),t.pid),gT!==null&&Jn(gT,t.pid,Gn,e=>r.unlinkSync(e)),t.exit(e)}}function AT(e){DT++,oT.inFlight=DT;let t=!1,n=(n,r)=>{if(t){r!==null&&j(`warn`,`exit-after-flush dropped: an earlier responder settled this socket`);return}t=!0;let i=r===null?void 0:()=>kT(r);try{e.end(Ue(n),i)}catch(e){j(`warn`,`response write failed: ${e.message}`),i?.()}},r=setTimeout(()=>{oT.requestsTimedOut++,n({ok:!1,error:`request exceeded 200ms`,code:`TIMEOUT`,daemonV:3},null)},200),i=We(e=>{MT(e).then(e=>n(e.resp,e.exitAfterFlush)).catch(e=>{j(`error`,`handler threw: ${e?.stack||e}`),n({ok:!1,error:String(e?.message||e),code:`RENDER_FAILED`,daemonV:3},null)})},e=>{j(`warn`,`frame parse failed: ${e.message}`),n({ok:!1,error:e.message,code:`BAD_REQUEST`,daemonV:3},null)});e.on(`data`,i),e.on(`error`,e=>{j(`warn`,`socket error: ${e.message}`)}),e.on(`close`,()=>{clearTimeout(r),DT=Math.max(0,DT-1),oT.inFlight=DT})}const jT=e=>({resp:e,exitAfterFlush:null});async function MT(e){if(!e||typeof e!=`object`||typeof e.v!=`number`)return jT({ok:!1,error:`malformed request`,code:`BAD_REQUEST`,daemonV:3});if(e.v!==3)return e.v>3?j(`info`,`version mismatch: client=${e.v} > daemon=3; binary likely upgraded — exiting after the response flushes`):j(`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 jT({ok:!0,stats:oT.snapshot({gitCache:cT.getStats(),usageCache:lT.getStats(),renderCacheSize:mT.size,watchersActive:sT.size(),nextRestartReason:wT?.describeNextRestart()??null})});if(e.kind===`render`){oT.requestsTotal++;let t=Date.now();try{let{report:n}=Fw(e.hookData);for(let e of n.unknownTopLevelFields)j(`info`,`schema: unknown field '${e}' — Anthropic may have added it`);let r=[];for(let e of n.missingRequired)r.push(`missing required field '${e}'`);for(let{path:e,expected:t,got:i}of n.typeMismatches)r.push(`field '${e}' expected ${t}, got ${i}`);if(e.cwd===``&&r.push(`request 'cwd' is empty`),r.length>0)return oT.requestsErrored++,j(`warn`,`BAD_REQUEST: ${r.join(`; `)}`),jT({ok:!1,error:`malformed hookData: ${r.join(`; `)}`,code:`BAD_REQUEST`,daemonV:3});let i=e.hookData.workspace.project_dir,{configFile:a,unknownFlagsError:o}=FT(e.args),s=e.hookData.session_id,c=uT.get(s,`config-override`)??a,l=mT.getOrCreate(i,e.cwd,c),u=Re(e),d=u.termCols,f=Jw(d??120),p={...zT,width:f},m=``;if(l.state!==null){let t=l.state.presetRootOps,n=yb(l.state.config,t=>uT.get(e.hookData.session_id,t),e=>tl(t,e)),r=await Mb(e.hookData,UT,e.cwd,l.state.neededInputPaths,n,u),i=Ix(n.theme);p.style=n.style,p.separator=n.separator,p.wrap=n.autoWrap,p.padding=n.padding,p.charset=n.charset,p.colorCompatibility=n.colorCompatibility,m=NS(l.state.config,l.state.compiled,l.state.store,l.state.registry,r,i,p,{perSegmentSink:l.state.lastRenderCellsBySegment},{look:Tc(l.state.config.looks,n.look),preset:n.preset})}let h=uT.get(e.hookData.session_id,`click.error`);h&&uT.clear(e.hookData.session_id,`click.error`);let g=[o,l.lastError,h].filter(Boolean).join(`
|
|
168
|
-
`)||null,_=
|
|
169
|
-
`})}catch(e){throw
|
|
170
|
-
`)}function
|
|
171
|
-
`);return e?`${i}\n${e}`:i}const
|
|
172
|
-
`);return}t.stdout.write(
|
|
166
|
+
`+t:t}this.refreshWatcher(e,t)}buildState(e,t){let{config:n,source:r}=fb(t,$b),i=PC(Me(),j),a=Yh(Jh({globals:$c(i.globals,n.presets)},n),i.segmentPalette),o=el(i.presetRootOps,n.presets),s=pb(nl(a,o),t??`<default>`,r),c=new tw,l=new Lx(c,s.globals.default_empty_value??``,this.deps.gitService,this.deps.sessionState),u,d=[];try{u=FS(s,l,{cwd:e.cwd});for(let{key:e,spec:t}of dC(s))d.push(iC(e,t));for(let{key:e,spec:t}of xC(s))d.push(SC(e,t))}catch(e){for(let e of d)e();throw l.dispose(),e}return{config:s,store:c,registry:l,compiled:u,neededInputPaths:Mb(s),lastRenderCellsBySegment:new Map,validatorDisposers:d,presetRootOps:o}}refreshWatcher(e,t){(t!==e.configFilePath||e.watcher===null)&&(e.configFilePath=t,this.rebindWatcher(e,t))}rebindWatcher(e,t){e.watcher&&=(e.watcher.release(),null);let n=[...lb(e.projectDir,e.cwd,e.configFile),Me()],i=new Map;for(let e of n){let t=c.dirname(e);if(!r.existsSync(t))continue;let n=c.basename(e);i.has(t)||i.set(t,new Set),i.get(t).add(n)}let a=[...i.entries()].map(([e,t])=>({path:e,filenames:[...t]})),o=`config:${e.projectDir}:${e.cwd}:${e.configFile??``}:${t??`<none>`}`;e.watcher=this.deps.watchers.acquire(o,{files:t===null?[]:[t],dirs:a},()=>this.onConfigChanged(e))}onConfigChanged(e){j(`info`,`config change detected for entry projectDir=${e.projectDir} cwd=${e.cwd}`),this.reloadInto(e)}get size(){return this.entries.size}firstPopulatedState(){for(let e of this.entries.values())if(e.state!==null)return e.state;return null}};const iw=16384;var aw=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<iw){this.rollingTimestamps.push(e);return}this.rollingTimestamps[this.rollingHead]=e,this.rollingHead=(this.rollingHead+1)%iw}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: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},watchers:{active:e.watchersActive,opened:this.watchersOpened,closed:this.watchersClosed,evicted:this.watchersEvicted},subprocesses:this.snapshotSubprocesses(),nextRestartReason:e.nextRestartReason??null}}};const ow={load:()=>({}),save:()=>{},flush:()=>{}};function sw(e){let t=new Map;for(let[n,r]of Object.entries(e))t.set(n,new Map(Object.entries(r)));return t}var cw=class{sessions;storage;atom=(0,q.createAtom)(`SessionState`);constructor(e=ow,t=256){this.maxSessions=t,this.storage=e,this.sessions=new Map,this.hydrateFromStorage()}useStorage(e){this.storage=e,this.hydrateFromStorage()}hydrateFromStorage(){this.sessions=sw(this.storage.load()),this.evictOldest(),this.persist()}get(e,t){this.atom.reportObserved();let n=this.sessions.get(e);return n?(this.touch(e,n),n.get(t)??null):null}set(e,t,n){this.setBatch(e,[{key:t,value:n}])}setBatch(e,t){t.length!==0&&(0,q.runInAction)(()=>{let n=this.sessions.get(e)??new Map;for(let{key:e,value:r}of t)n.set(e,r);this.touch(e,n),this.evictOldest(),this.persist(),this.atom.reportChanged()})}clear(e,t){(0,q.runInAction)(()=>{let n=this.sessions.get(e);n&&(n.delete(t),n.size===0?this.sessions.delete(e):this.touch(e,n)),this.persist(),this.atom.reportChanged()})}prune(e){(0,q.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,n]of this.sessions)e[t]=Object.fromEntries(n);return e}};const lw=(e,t)=>O(t);function uw(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 dw=class{timer=null;pending=null;constructor(e,t=500,n=lw){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 uw(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(c.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}`)}}},$=class extends Error{constructor(e){super(e),this.name=`BadVerbArgs`}};function fw(e){if(!e)throw new $(`session id is required`);if(e.includes(`/`)||e.includes(`..`))throw new $(`invalid session id "${e}"`);return e}function pw(e){return mw(()=>decodeURIComponent(e))}function mw(e){try{return e()}catch(e){throw e instanceof URIError?new $(`malformed wire encoding: ${e.message}`):e}}function hw(e,t){let n=be({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 gw=(e,t)=>hw(pw(e),t),_w=(e,t)=>{let n=be({bin:`/usr/bin/open`,args:[`-a`,`Visual Studio Code`,pw(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`})`)}},vw=(e,t)=>hw(pw(e),t),yw=(e,t)=>hw(pw(e),t),bw=(e,t)=>{let n=fw(pw(e));t.sessionState.get(n,`toolbar-expanded`)?t.sessionState.clear(n,`toolbar-expanded`):t.sessionState.set(n,`toolbar-expanded`,`1`)},xw=(e,t)=>{let[n=``,...r]=mw(()=>Kt(e)),i=fw(n);if(r.length===0)throw new $(`set-state: <key>/<value> is required (have keys: ${rC().join(`, `)})`);if(r.length%2!=0)throw new $(`set-state: expected even-count <key>/<value> pairs, got ${r.length} segment(s) after session id (have keys: ${rC().join(`, `)})`);let a=[];for(let e=0;e<r.length;e+=2){let t=r[e],n=r[e+1];if(!t)throw new $(`set-state: empty key at pair ${e/2+1} (expected <sessionId>/<key>/<value>[/<key>/<value>...] segments)`);let i=aC(t,n);if(!i.ok)throw new $(`set-state: pair ${e/2+1}: ${i.reason}`);a.push({key:t,value:i.value})}t.sessionState.setBatch(i,a);let o=a.map(e=>`${e.key}=${e.value}`).join(` `);t.dlog(`info`,`set-state: ${o} (session=${i})`)},Sw=/^-?\d+$/;function Cw(e,t,n){return e>n?t:e<t?n:e}function ww(e,t,n,r){if(e){if(!rC().includes(e))throw new $(`${r}: unknown session key "${e}" to release (have: ${rC().join(`, `)})`);n.sessionState.clear(t,e),n.dlog(`info`,`${r}: released session key ${e} (session=${t})`)}}const Tw=(e,t)=>{let[n=``,r=``,i=``]=mw(()=>Kt(e)),a=fw(n);if(!r)throw new $(`step-state: <key> is required (shape: <sessionId>/<key>/<by>)`);if(!Sw.test(i))throw new $(`step-state: delta must be an integer, got "${i}"`);let o=parseInt(i,10),s=oC(r);if(!s)throw new $(`step-state: key "${r}" is not a bounded (range) state key (have keys: ${rC().join(`, `)})`);let c=t.sessionState.get(a,r),l=c&&Sw.test(c)?Math.max(s.min,Math.min(s.max,parseInt(c,10))):s.seed,u=Cw(l+o,s.min,s.max),d=aC(r,String(u));if(!d.ok)throw new $(`step-state: ${d.reason}`);t.sessionState.set(a,r,d.value),t.dlog(`info`,`step-state: ${r} ${l}→${d.value} (by ${o}, session=${a})`)};function Ew(e){if(!sg(e))throw Error(`step-config: "${e}" validated as a bounded config-writable key but is not a Globals field — registration/loader invariant broken`)}const Dw=(e,t)=>{let[n=``,r=``,i=``,a=``]=mw(()=>Kt(e)),o=fw(n);if(!r)throw new $(`set-config: <key>/<value> is required (have keys: ${pC().join(`, `)})`);let s=mC(r,i);if(!s.ok)throw new $(`set-config: ${s.reason}`);let c=DC(r,s.value);RC(Me(),r,c,t.dlog),t.dlog(`info`,`set-config: ${r}=${s.value} (session=${o})`),ww(a,o,t,`set-config`)},Ow=(e,t)=>{let[n=``,r=``,i=``,a=``]=mw(()=>Kt(e)),o=fw(n);if(!r)throw new $(`step-config: <key> is required (shape: <sessionId>/<key>/<by>)`);if(!Sw.test(i))throw new $(`step-config: delta must be an integer, got "${i}"`);let s=parseInt(i,10),c=hC(r);if(!c)throw new $(`step-config: key "${r}" is not a bounded (range) config key (have keys: ${pC().join(`, `)})`);Ew(r);let l=NC(Me(),t.dlog)[r],u=typeof l==`number`?Math.max(c.min,Math.min(c.max,l)):c.seed,d=Cw(u+s,c.min,c.max),f=mC(r,String(d));if(!f.ok)throw new $(`step-config: ${f.reason}`);let p=DC(r,f.value);RC(Me(),r,p,t.dlog),t.dlog(`info`,`step-config: ${r} ${u}→${f.value} (by ${s}, session=${o})`),ww(a,o,t,`step-config`)},kw=(e,t)=>{let[n=``,r=``]=mw(()=>Kt(e)),i=fw(n);if(!r||!pC().includes(r))throw new $(`reset-config: unknown config key "${r}" (have: ${pC().join(`, `)})`);zC(Me(),r,t.dlog),t.dlog(`info`,`reset-config: ${r} (session=${i})`)},Aw=(e,t)=>{let[n=``,r=``,i=``]=mw(()=>Kt(e)),a=fw(n);if(!r)throw new $(`apply-layout-op: <key>/<op> is required (have: ${pC().join(`, `)})`);let o=mC(r,i);if(!o.ok)throw new $(`apply-layout-op: ${o.reason}`);let s=N_(r);if(s===null||s.scope!==`preset-root-ops`)throw new $(`apply-layout-op: "${r}" is not a "presets.<name>.rootOps" target`);let c=PC(Me(),t.dlog).presetRootOps[s.preset]??[],l=JSON.stringify([...c,o.value]);RC(Me(),r,l,t.dlog),t.dlog(`info`,`apply-layout-op: ${r} += ${o.value} (session=${a})`)},jw=(e,t)=>{let[n=``]=mw(()=>Kt(e)),r=fw(n),i=XC(Me(),t.dlog);if(i===null)throw new $(`undo: history is empty, nothing to undo`);t.dlog(`info`,`undo: ${i.key} (session=${r})`)},Mw=(e,t)=>{let[n=``]=mw(()=>Kt(e)),r=fw(n),i=ZC(Me(),t.dlog);if(i===null)throw new $(`redo: nothing to redo`);t.dlog(`info`,`redo: ${i.key} (session=${r})`)},Nw=`config-override`,Pw=new Map([[Ft,gw],[`load-config`,(e,t)=>{let n=e.indexOf(`/`);if(n===-1)throw new $(`load-config: expected <sessionId>/<path> (missing separator)`);let r=fw(mw(()=>decodeURIComponent(e.slice(0,n)))),i=mw(()=>decodeURIComponent(e.slice(n+1))).trim();if(i!==``){if(!i.startsWith(`/`))throw new $(`load-config: path must be absolute, got "${i}"`);if(!/\.(json5?|json)$/.test(i))throw new $(`load-config: path must end with .json5 or .json, got "${i}"`)}i===``?(t.sessionState.clear(r,Nw),t.dlog(`info`,`load-config: override cleared (session=${r})`)):(t.sessionState.set(r,Nw,i),t.dlog(`info`,`load-config: ${i} (session=${r})`))}],[It,_w],[Pt,xw],[N,Tw],[zt,Dw],[Bt,Ow],[Vt,kw],[Ht,Aw],[Ut,jw],[Wt,Mw],[Lt,vw],[Rt,yw],[`toolbar-toggle`,bw]]),Fw=(e,t)=>{let n=[],r=!1,i=null;for(let{verb:a,value:o}of Jt(e)){if(!i&&(a===`set-state`||a===`step-state`||a===`set-config`||a===`step-config`||a===`reset-config`||a===`apply-layout-op`||a===`undo`||a===`redo`||a===`toolbar-toggle`)){let e=Kt(o);e.length>0&&e[0]&&(i=e[0])}let e=Pw.get(a);if(!e){n.push(`unknown effect verb "${a}"`);continue}try{e(o,t)}catch(e){e instanceof $||(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(`
|
|
167
|
+
`));let e=`dispatch: ${n.join(`; `)}`;throw r?Error(e):new $(e)}},Iw=new Map([...Pw,[M,Fw]]);Object.freeze([...Iw.keys()]);const Lw=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`]),Rw=[[`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`]];function zw(e){let t={missingRequired:[],typeMismatches:[],unknownTopLevelFields:[]},n=typeof e==`object`&&e&&!Array.isArray(e)?e:{};for(let[e,r]of Rw){let i=Bw(n,e);if(i==null)t.missingRequired.push(e);else{let n=Array.isArray(i)?`array`:typeof i;(r===`object`?n!==`object`:n!==r)&&t.typeMismatches.push({path:e,expected:r,got:n})}}for(let e of Object.keys(n))Lw.has(e)||t.unknownTopLevelFields.push(e);return{data:e,report:t}}function Bw(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 Vw(e,t){switch(e){case`vars`:return{what:e,vars:Hw(t)};case`segments`:return{what:e,segments:Kw(t)};case`config`:return{what:e,config:Yw(t)}}}function Hw(e){if(e===null)return[];let{store:t,registry:n,config:r}=e,i=Ww(r),a=t.names().sort(),o=[];for(let e of a){let r=t.getNode(e),a=n.getLastError(e);o.push({name:e,source:i.get(e)??null,type:r.type,value:r.read(),lastError:a===void 0?null:{timestampMs:a.timestamp,message:a.message},ageMs:Uw(r.lastUpdatedMs())})}return o}function Uw(e){return e===null?null:Math.max(0,Date.now()-e)}function Ww(e){let t=new Map;for(let[n,r]of Object.entries(e.variables))t.set(n,Gw(r));for(let[n,r]of Object.entries(e.segments))if(r.vars)for(let[e,i]of Object.entries(r.vars))t.set(`${n}.${e}`,Gw(i));return t}function Gw(e){return e.kind}function Kw(e){if(e===null)return[];let{store:t,config:n,lastRenderBySegment:r}=e,i=new Set(t.names()),a=qw(n),o=[];for(let e of a){let t=n.segments[e];t&&o.push({name:e,template:t.template,referencedVars:Jw(t.template,i),lastRender:r.get(e)??null})}return o}function qw(e){let t=[],n=new Set;for(let r of uh(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 Jw(e,t){let n=new Set;for(let r of Vy(e)){if(t.has(r)){n.add(r);continue}let e=r.split(`.`);for(;e.length>1;){e.pop();let r=e.join(`.`);if(t.has(r)){n.add(r);break}}}return Array.from(n).sort()}function Yw(e){return e===null?null:e.config}const Xw=[`vars`,`segments`,`config`];function Zw(e){return typeof e==`string`&&Xw.includes(e)}function Qw(e){return Math.max(1,e-2)}var $w=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 O(`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);O(`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{O(`Calculating context tokens from transcript: ${e}`);let n=await Wr(e);if(n.length===0)return O(`No entries in transcript`),B;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,O(`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 O(`Most recent main chain context: ${n} tokens (limit: ${t})`),z({totalTokens:n,maxTokens:t,...this.ratioPercentages(n,t)})}return O(`No main chain entries with usage data found`),B}catch(e){return Xn(`context transcript: ${e instanceof Error?e.message:String(e)}`)}}async getContextInfo(e){let t=this.calculateContextFromHookData(e);if(t)return z(t);let n=e.context_window?.context_window_size??2e5;return this.calculateContextTokensFromTranscript(e.transcript_path,n)}};function eT(e){let t=e.type||e.message?.role||e.message?.type,n=e.type===`user`&&e.message?.firstContentType===`tool_result`;return t===`user`&&!n}var tT=class{state=new Map;calculateLastResponseTime(e){if(e.length===0)return null;let t=null,n=null;for(let r of e){let e=r.type||r.message?.role||r.message?.type;if(eT(r))t=r.timestamp;else if(e===`assistant`&&t){let e=(r.timestamp.getTime()-t.getTime())/1e3;e>.1&&e<300&&(n=e)}}return n}async foldMetrics(e,t){let n=this.state.get(e),r=Mr(t);if(n&&r!==0&&n.cursor.mtimeMs===r)return this.state.delete(e),this.state.set(e,n),{kind:`ok`,value:{messageCount:n.messageCount,recent:[...n.recent]}};let i=await Jr(t,n?.cursor);if(i.kind===`failed`)return i;if(i.kind===`absent`)return{kind:`ok`,value:{messageCount:n?.messageCount??0,recent:[...n?.recent??[]]}};let{entries:a,cursor:o,reset:s}=i.value,c=n&&!s?n:void 0,l=c?.messageCount??0,u=c?[...c.recent]:[];for(let e of a)e.isSidechain||(eT(e)&&l++,u.push(e));for(u.length>20&&(u=u.slice(-20)),this.state.delete(e),this.state.set(e,{cursor:o,messageCount:l,recent:u});this.state.size>256;){let e=this.state.keys().next().value;if(e===void 0)break;this.state.delete(e)}return{kind:`ok`,value:{messageCount:l,recent:[...u]}}}async getMetricsInfo(e,t){if(O(`Getting metrics from hook data for session: ${e}`),!t.cost)return B;let n=await this.foldMetrics(e,t.transcript_path);return n.kind===`failed`?Xn(`metrics (${e}): ${n.reason}`):z({responseTime:t.cost.total_api_duration_ms/1e3,lastResponseTime:this.calculateLastResponseTime(n.value.recent),sessionDuration:t.cost.total_duration_ms/1e3,messageCount:n.value.messageCount,linesAdded:t.cost.total_lines_added,linesRemoved:t.cost.total_lines_removed})}};const nT=new Map;function rT(e){if(!e)return``;let t=e.indexOf(`,`);return t<0?e:e.slice(0,t)}var iT=class{async getSessionId(){if(!process.env.TMUX_PANE)return B;let e=rT(process.env.TMUX),t=nT.get(e);if(t!==void 0)return t;O(`Getting tmux session ID, TMUX_PANE: ${process.env.TMUX_PANE}`);let n=await ye({bin:`tmux`,args:[`display-message`,`-p`,`#S`],timeoutMs:1e3,category:`tmux`}),r=n.ok?n.stdout.trim()?z(n.stdout.trim()):B:Xn(`tmux display-message: ${n.reason}`);return nT.set(e,r),r}isInTmux(){return!!process.env.TMUX_PANE}};function aT(e){return e<32||e===127||e>=128&&e<=159}function oT(e,t){let n=``;for(let t of e)n+=aT(t.codePointAt(0)??0)?` `:t;n=n.replace(/\s+/g,` `).trim();let r=``,i=0;for(let e of n){if(i===t)return r.replace(/.$/u,`…`);r+=e,i++}return r}const sT=`\x1B[38;2;255;255;255m`,cT=`\x1B[48;2;200;40;40m`,lT=`\x1B[0m`,uT=new aw;ve(uT.launchStats);const dT=new xr({counters:uT,logger:j}),fT=new Or({watchers:dT,logger:j}),pT=new oi,mT=new cw,hT=new $w,gT=new tT,_T=new iT,vT=new rw({gitService:fT,sessionState:mT,watchers:dT});let yT=null,bT=null,xT=0;function ST(){t.on(`uncaughtException`,e=>{j(`error`,`uncaughtException: ${e.stack||e.message}`),NT(1)}),t.on(`unhandledRejection`,e=>{j(`error`,`unhandledRejection: ${String(e)}`),NT(1)});for(let e of[`SIGINT`,`SIGTERM`,`SIGHUP`])t.on(e,()=>{j(`info`,`received ${e}, shutting down`),NT(0)});try{xT=dt(t.env)}catch(e){j(`error`,`refusing to boot: ${e.message}`),NT(1);return}yT=Rn(t.pid);let e=qn(Yn(yT));if(!e.decision.allow){j(`warn`,`fork-bomb breaker: ${e.decision.reason}; refusing to boot`),NT(1);return}bT=e.registryPath,r.mkdirSync(Ee(),{recursive:!0}),ke(De()),mT.useStorage(new dw(je(),500,j)),Vn({anchor:Bn(t.env),isAlive:Hn,onOrphaned:e=>{j(`info`,`parent watchdog: ${e}; shutting down`),NT(0)}}),CT(g.createServer({allowHalfOpen:!1},e=>{PT(e)}),De(),!1)}function CT(e,n,r){e.removeAllListeners(`error`),e.removeAllListeners(`listening`),e.once(`error`,i=>{if(i.code!==`EADDRINUSE`){j(`error`,`server error: ${i.message}`),NT(1);return}if(r){j(`info`,`lost rebind race; another daemon is alive — exiting`),t.exit(0);return}wT(e,n)}),e.listen(n,()=>TT(n))}function wT(e,n){let i=kn(An(A(n)),(e,t)=>Ln(e,t,{readStartTime:L,pidAlive:Hn}));if(i.kind===`attach-and-exit`){j(`info`,`EADDRINUSE: ${i.reason} — exiting`),t.exit(0);return}j(`warn`,`EADDRINUSE: ${i.reason} — unlinking stale socket and rebinding`);try{r.unlinkSync(n)}catch(e){if(e.code!==`ENOENT`){j(`error`,`cannot unlink stale socket ${n}: ${e.message}`),NT(1);return}}CT(e,n,!0)}function TT(e){let n=Nn(e);if(n.kind!==`present`){j(`warn`,`no ownable socket at bind callback (${n.kind}); exiting`),NT(0);return}AT(e);try{r.chmodSync(e,384)}catch(e){j(`warn`,`chmod socket failed: ${e.message}`)}j(`info`,`daemon up: pid=${t.pid} v=3 sock=${e} heapCap=${Math.round(_.getHeapStatistics().heap_size_limit/1048576)}MB rssLimit=${Math.round(xT/1048576)}MB`),Ct(),DT(),kT(),ET(e,n.identity)}function ET(e,n){In({bound:n,myPid:t.pid,readIdentity:()=>Nn(e),readLease:()=>An(A(e)),shutdown:e=>NT(e),log:j}).arm()}function DT(){let e=import.meta.url,n=[];e.startsWith(`file://`)&&n.push(b(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{}if(i.size===0)return;let a=setInterval(()=>{for(let[e,t]of i)try{if(r.statSync(e).mtimeMs!==t){j(`info`,`binary mtime changed (${e}); shutting down`),clearInterval(a),NT(0);return}}catch(e){j(`warn`,`bin stat failed: ${e.message}`)}},6e4);a.unref()}let OT=null;function kT(){OT=ft(mt(uT.startedAt.getTime(),e=>NT(e),{rssLimitBytes:xT})),OT.arm()}function AT(e){let n=jn(A(e),{pid:t.pid,version:3,binPath:t.argv[1],startTime:yT});n!==null&&j(`warn`,`lease write failed: ${n}`)}let jT=0,MT=!1;function NT(e){if(!MT){MT=!0,setTimeout(()=>t.kill(t.pid,`SIGKILL`),500);try{fT.close()}catch(e){j(`warn`,`gitService close failed: ${e.message}`)}try{pT.close()}catch(e){j(`warn`,`usageStore close failed: ${e.message}`)}try{dT.closeAll()}catch(e){j(`warn`,`watcherRegistry close failed: ${e.message}`)}try{mT.flush()}catch(e){j(`warn`,`sessionState flush failed: ${e.message}`)}Mn(Ae(),t.pid),bT!==null&&Jn(bT,t.pid,Gn,e=>r.unlinkSync(e)),t.exit(e)}}function PT(e){jT++,uT.inFlight=jT;let t=!1,n=(n,r)=>{if(t){r!==null&&j(`warn`,`exit-after-flush dropped: an earlier responder settled this socket`);return}t=!0;let i=r===null?void 0:()=>NT(r);try{e.end(Ue(n),i)}catch(e){j(`warn`,`response write failed: ${e.message}`),i?.()}},r=setTimeout(()=>{uT.requestsTimedOut++,n({ok:!1,error:`request exceeded 200ms`,code:`TIMEOUT`,daemonV:3},null)},200),i=We(e=>{IT(e).then(e=>n(e.resp,e.exitAfterFlush)).catch(e=>{j(`error`,`handler threw: ${e?.stack||e}`),n({ok:!1,error:String(e?.message||e),code:`RENDER_FAILED`,daemonV:3},null)})},e=>{j(`warn`,`frame parse failed: ${e.message}`),n({ok:!1,error:e.message,code:`BAD_REQUEST`,daemonV:3},null)});e.on(`data`,i),e.on(`error`,e=>{j(`warn`,`socket error: ${e.message}`)}),e.on(`close`,()=>{clearTimeout(r),jT=Math.max(0,jT-1),uT.inFlight=jT})}const FT=e=>({resp:e,exitAfterFlush:null});async function IT(e){if(!e||typeof e!=`object`||typeof e.v!=`number`)return FT({ok:!1,error:`malformed request`,code:`BAD_REQUEST`,daemonV:3});if(e.v!==3)return e.v>3?j(`info`,`version mismatch: client=${e.v} > daemon=3; binary likely upgraded — exiting after the response flushes`):j(`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 FT({ok:!0,stats:uT.snapshot({gitCache:fT.getStats(),usageCache:pT.getStats(),renderCacheSize:vT.size,watchersActive:dT.size(),nextRestartReason:OT?.describeNextRestart()??null})});if(e.kind===`render`){uT.requestsTotal++;let t=Date.now();try{let{report:n}=zw(e.hookData);for(let e of n.unknownTopLevelFields)j(`info`,`schema: unknown field '${e}' — Anthropic may have added it`);let r=[];for(let e of n.missingRequired)r.push(`missing required field '${e}'`);for(let{path:e,expected:t,got:i}of n.typeMismatches)r.push(`field '${e}' expected ${t}, got ${i}`);if(e.cwd===``&&r.push(`request 'cwd' is empty`),r.length>0)return uT.requestsErrored++,j(`warn`,`BAD_REQUEST: ${r.join(`; `)}`),FT({ok:!1,error:`malformed hookData: ${r.join(`; `)}`,code:`BAD_REQUEST`,daemonV:3});let i=e.hookData.workspace.project_dir,{configFile:a,unknownFlagsError:o}=zT(e.args),s=e.hookData.session_id,c=mT.get(s,`config-override`)??a,l=vT.getOrCreate(i,e.cwd,c),u=Re(e),d=u.termCols,f=Qw(d??120),p={...UT,width:f},m=``;if(l.state!==null){let t=l.state.presetRootOps,n=Cb(l.state.config,t=>mT.get(e.hookData.session_id,t),e=>tl(t,e)),r=await Ib(e.hookData,qT,e.cwd,l.state.neededInputPaths,n,u),i=Bx(n.theme);p.style=n.style,p.separator=n.separator,p.wrap=n.autoWrap,p.padding=n.padding,p.charset=n.charset,p.colorCompatibility=n.colorCompatibility,m=LS(l.state.config,l.state.compiled,l.state.store,l.state.registry,r,i,p,{perSegmentSink:l.state.lastRenderCellsBySegment},{look:Tc(l.state.config.looks,n.look),preset:n.preset})}let h=mT.get(e.hookData.session_id,`click.error`);h&&mT.clear(e.hookData.session_id,`click.error`);let g=[o,l.lastError,h].filter(Boolean).join(`
|
|
168
|
+
`)||null,_=VT(m,g,l.lastWarning),v=Date.now()-t,y=fT.getStats(),b=pT.getStats();return j(`info`,`render sid=${e.hookData.session_id??`?`} took=${v}ms termCols=${d??`?`} width=${f} git=${y.size}/${y.hits}h/${y.misses}m usage=${b.size}/${b.hits}h/${b.misses}m err=${l.lastError?`Y`:`N`} warn=${l.lastWarning?`Y`:`N`}`),FT({ok:!0,output:_+`
|
|
169
|
+
`})}catch(e){throw uT.requestsErrored++,e}}if(e.kind===`click`)return FT(await JT(e.verb,e.value));if(e.kind===`debug`){if(!Zw(e.what))return FT({ok:!1,error:`unknown debug 'what': ${String(e.what)} (have: ${Xw.join(`, `)})`,code:`BAD_REQUEST`,daemonV:3});let t=vT.firstPopulatedState(),n=t===null?null:{store:t.store,registry:t.registry,config:t.config,compiled:t.compiled,lastRenderBySegment:e.what===`segments`?KT(t.lastRenderCellsBySegment,t.config.globals.charset??`unicode`,t.config.globals.colorCompatibility??`truecolor`):GT};return FT({ok:!0,debug:Vw(e.what,n)})}return FT({ok:!1,error:`unknown kind`,code:`BAD_REQUEST`,daemonV:3})}const LT=`\x1B]8;;`,RT=`\x1B]8;;\x1B\\`;function zT(e){let{values:t,tokens:n}=x({args:e.slice(1),options:{config:{type:`string`}},strict:!1,tokens:!0,allowPositionals:!0}),r=[...new Set((n??[]).filter(e=>e.kind===`option`&&e.name!==`config`).map(e=>`--${e.name}`))],i=t.config;return{configFile:i===void 0?void 0:cb(i),unknownFlagsError:r.length>0?`Unknown flags: ${r.join(`, `)}`:null}}function BT(e,t,n,r){let i=qt([{verb:e,args:[t]}]),a=t.split(/\r\n|\r|\n/).map(e=>oT(e,120)).filter(Boolean).slice(0,8);return a.length===0?``:[`${LT}${i}\\${n}${r} ⚠ ${a[0]} ${lT}${RT}`,...a.slice(1).map(e=>`${LT}${i}\\${n}${r} ${e} ${lT}${RT}`)].join(`
|
|
170
|
+
`)}function VT(e,t,n){let r=[];if(t&&r.push(BT(Lt,t,cT,sT)),n&&r.push(BT(Rt,n,`\x1B[48;2;220;160;40m`,`\x1B[38;2;0;0;0m`)),r.length===0)return e;let i=r.join(`
|
|
171
|
+
`);return e?`${i}\n${e}`:i}const HT={sessionState:mT,dlog:j},UT={style:`powerline`,colorCompatibility:`truecolor`,wrap:!0,padding:1,charset:`unicode`},WT={...UT,width:1/0},GT=new Map;function KT(e,t,n){let r=new Map;for(let[i,a]of e)r.set(i,ch(a,{...WT,charset:t,colorCompatibility:n}));return r}const qT={gitProvider:fT,usageStore:pT,contextProvider:hT,metricsProvider:gT,tmuxService:_T,log:j,clock:()=>new Date};function JT(e,t){let n=Iw.get(e);if(!n)return{ok:!1,error:`unknown click verb: ${e}`,code:`BAD_REQUEST`,daemonV:3};try{return n(t,HT),{ok:!0,output:``}}catch(e){let t=e instanceof $?`BAD_REQUEST`:`RENDER_FAILED`;return{ok:!1,error:String(e instanceof Error?e.message:e),code:t,daemonV:3}}}const YT={connectMs:200,budgetMs:500};async function XT(e){let n=e.includes(`--json`),r=await ZT();if(r.kind!==`ok`&&(t.stderr.write(`daemon-stats: ${Qe(r)}\n`),t.exit(1)),n){t.stdout.write(JSON.stringify(r.value,null,2)+`
|
|
172
|
+
`);return}t.stdout.write(tE(r.value))}function ZT(){return Ke({kind:`stats`},YT,e=>`stats`in e?e.stats:void 0)}function QT(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/1024/1024).toFixed(1)}MB`}function $T(e,t){let n=e+t;return n===0?`n/a`:`${(e/n*100).toFixed(1)}%`}function eE(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 tE(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(` startedAt ${e.startedAt}`),t.push(` uptime ${eE(e.uptimeSec)}`),t.push(` rss ${QT(e.rssBytes)}`),t.push(` heapUsed ${QT(e.heapUsedBytes)}`),t.push(` heapTotal ${QT(e.heapTotalBytes)}`),t.push(` external ${QT(e.externalBytes)}`),t.push(` arrayBuffers ${QT(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 ${$T(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 ${$T(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(`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(`
|
|
173
173
|
`)+`
|
|
174
|
-
`}const
|
|
175
|
-
`);return}t.stdout.write(
|
|
176
|
-
`;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);for(let i of e){let e=i.ageMs===null?``:` ${
|
|
174
|
+
`}const nE={connectMs:200,budgetMs:500};async function rE(e,n){let r=n.includes(`--json`),i=await iE(e);if(i.kind!==`ok`&&(t.stderr.write(`${e}: ${Qe(i)}\n`),t.exit(1)),r){t.stdout.write(JSON.stringify(i.value,null,2)+`
|
|
175
|
+
`);return}t.stdout.write(aE(i.value))}function iE(e){return Ke({kind:`debug`,what:e},nE,e=>`debug`in e?e.debug:void 0)}function aE(e){switch(e.what){case`vars`:return oE(e.vars);case`segments`:return sE(e.segments);case`config`:return cE(e.config);default:return e}}function oE(e){if(e.length===0)return`no variables (DSL not active)
|
|
176
|
+
`;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);for(let i of e){let e=i.ageMs===null?``:` ${uE(i.ageMs)}`,a=i.lastError?` ✗ ${i.lastError.message}`:``;t.push(` ${i.name.padEnd(n)} ${(i.source??`—`).padEnd(r)} ${i.type.padEnd(7)} ${lE(i.value)}${e}${a}`)}return t.join(`
|
|
177
177
|
`)+`
|
|
178
|
-
`}function
|
|
178
|
+
`}function sE(e){if(e.length===0)return`no segments (DSL not active)
|
|
179
179
|
`;let t=[`segments (${e.length})`,``];for(let n of e)t.push(` ${n.name}`),t.push(` template ${n.template}`),n.referencedVars.length>0&&t.push(` vars ${n.referencedVars.join(`, `)}`),n.lastRender!==null&&t.push(` last ${n.lastRender}`);return t.join(`
|
|
180
180
|
`)+`
|
|
181
|
-
`}function
|
|
181
|
+
`}function cE(e){return e===null?`config: DSL not active
|
|
182
182
|
`:JSON.stringify(e,null,2)+`
|
|
183
|
-
`}function
|
|
184
|
-
`));return c.rendered}finally{s.dispose()}}function
|
|
183
|
+
`}function lE(e){let t=typeof e==`string`?e:JSON.stringify(e);return t.length>60?t.slice(0,57)+`…`:t}function uE(e){return e<1e3?`${e}ms`:e<6e4?`${(e/1e3).toFixed(1)}s`:`${Math.floor(e/6e4)}m`}function dE(){let e=pE();return e===null?null:r.readFileSync(e,`utf-8`)}function fE(){let e;try{e=dE()}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 pE(){let e=c.join(`schema`,`cc-candybar.schema.json`),n=t.argv[1];if(n===void 0)return null;let i=c.dirname(c.resolve(n));for(;;){let t=c.join(i,e);if(r.existsSync(t))return t;let n=c.dirname(i);if(n===i)return null;i=n}}function mE(e){let t=`/home/tester`,n=Math.floor(Date.now()/1e3);return{hook_event_name:`Status`,session_id:`test0a1b-2c3d-4e5f-6a7b-8c9d0e1f2a3b`,version:`1.15.0`,home:t,cwd:`${t}/code/cc-candybar/src`,transcript_path:`${t}/.claude/projects/x/test.jsonl`,model:{id:`claude-opus-4-8`,display_name:`Opus 4.8`},workspace:{current_dir:`${t}/code/cc-candybar/src`,project_dir:`${t}/code/cc-candybar`},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`,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:n+2*3600},weekly:{percentage:21,resetsAt:n+5*86400},cache:{expiresAt:n+900},tmux:{session:`work`},host:{name:`tester-box`,user:`tester`,ssh:!0},theme:{effective:e.theme},look:{effective:e.look},preset:{effective:e.preset,customized:e.presetCustomized},style:{effective:e.style},charset:{effective:e.charset},colorCompatibility:{effective:e.colorCompatibility},autoWrap:{effective:e.autoWrap},padding:{effective:e.padding}}}function hE(e,n=t.cwd()){let i=e===void 0?ub(n,n):c.resolve(cb(e));if(e!==void 0&&i!==null){let e;try{e=r.statSync(i,{throwIfNoEntry:!1})}catch(e){return{kind:`unreadable`,path:i,message:e instanceof Error?e.message:String(e)}}if(e!==void 0&&!e.isFile())return{kind:`unreadable`,path:i,message:`not a file`}}let a=[],o=db(n,n);o!==null&&a.push(o);try{return{kind:`clean`,configPath:i,warnings:a,rendered:gE(i,n,a)}}catch(e){let t=e;return i!==null&&typeof t==`object`&&t&&typeof t.code==`string`&&t.path===i&&typeof t.message==`string`?{kind:`unreadable`,path:i,message:t.message}:{kind:`fatal`,configPath:i,message:e instanceof Wm||e instanceof Error?e.message:String(e),warnings:a}}}function gE(e,t,n){let{config:r,source:i}=fb(e,$b),a=pb(r,e??`<default>`,i),o=new tw,s=new Lx(o,a.globals.default_empty_value??``,void 0,new cw);try{let e=FS(a,s,{cwd:t});n.push(...e.loadWarnings),dC(a);let r=Cb(a,()=>null,()=>!1),i=t=>{let n=new Map;return{rendered:LS(a,e,o,s,mE(t),Bx(t.theme),{style:t.style,separator:t.separator,width:200,colorCompatibility:t.colorCompatibility,wrap:t.autoWrap,padding:t.padding,charset:t.charset},{onSegmentError:(e,t)=>n.set(e,t)},{look:Tc(a.looks,t.look),preset:t.preset}),segmentErrors:n}},c=i(r),l=i({...r,presetCustomized:!0}),u=[...[...c.segmentErrors].map(([e,t])=>`segment "${e}": ${t}`),...[...l.segmentErrors].filter(([e])=>!c.segmentErrors.has(e)).map(([e,t])=>`segment "${e}": ${t} (under .preset.customized = true)`)];if(u.length>0)throw Error(`config renders with ${u.length} segment error${u.length===1?``:`s`} (the daemon would render ⚠ error cells):\n`+u.map(e=>` ${e}`).join(`
|
|
184
|
+
`));return c.rendered}finally{s.dispose()}}function _E(e){return e.map(e=>`warning: ${e}\n`).join(``)}function vE(e){switch(e.kind){case`clean`:return{stdout:`✓ ${e.configPath??`bundled default (no config file found)`}: config OK${e.warnings.length>0?` (${e.warnings.length} warning${e.warnings.length===1?``:`s`})`:``}\n`,stderr:_E(e.warnings),code:0};case`fatal`:return{stdout:``,stderr:_E(e.warnings)+`✗ ${e.configPath??`<default>`}\n${e.message}\n`,code:1};case`unreadable`:return{stdout:``,stderr:`check: cannot read ${e.path}: ${e.message}\n`,code:2}}}function yE(e){(e.length>1||e[0]===``)&&(t.stderr.write(`check: expected at most one non-empty path
|
|
185
185
|
Usage: cc-candybar check [config-file]
|
|
186
|
-
`),t.exit(2));let n=
|
|
187
|
-
`,kick:!0,debug:`daemon unavailable (transient: ${e.cause}: ${e.message}) — kicking daemon`};case`permanent`:return{output:
|
|
186
|
+
`),t.exit(2));let n=vE(hE(e[0]));t.stdout.write(n.stdout),t.stderr.write(n.stderr),t.exit(n.code)}const bE=`${cT}${sT}`;function xE(e){return`${bE}⚠ cc-candybar: ${SE(e)}${lT}\n`}function SE(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: ${oT(e.message,60)}`;case`render_failed`:return`render failed: ${oT(e.message,60)}`;case`malformed_response`:return`malformed daemon response: ${oT(e.message,60)}`}}function CE(e){switch(e.kind){case`ok`:return{output:e.value,kick:!1,debug:null};case`transient`:return{output:`
|
|
187
|
+
`,kick:!0,debug:`daemon unavailable (transient: ${e.cause}: ${e.message}) — kicking daemon`};case`permanent`:return{output:xE(e),kick:!1,debug:`daemon refused request (permanent: ${e.cause}) — not kicking`}}}function wE(){let e=t.env.COLUMNS;if(e){let t=parseInt(e,10);if(!isNaN(t)&&t>0)return t}let n=t.stderr.columns;if(n&&n>0)return n}const TE=[`SSH_CONNECTION`,`SSH_CLIENT`,`SSH_TTY`];function EE(){return TE.some(e=>(t.env[e]??``)!==``)}function DE(){console.log(z_)}async function OE(){try{(t.argv.includes(`--help`)||t.argv.includes(`-h`))&&(DE(),t.exit(0));let e=t.argv[2];if(e===`install`&&(Dn(t.argv.slice(3)),t.exit(0)),e===`install-url-handler`&&(I(),t.exit(0)),e===`url-handle`){await wn(t.argv[3]);return}if(e===`daemon`){ST();return}if(e===`daemon-stats`&&(await XT(t.argv.slice(3)),t.exit(0)),e===`check`||e===`lint`){yE(t.argv.slice(3));return}if(e===`schema`){fE();return}Zw(e)&&(await rE(e,t.argv.slice(3)),t.exit(0)),t.stdin.isTTY===!0&&(console.error(`Error: This tool requires input from Claude Code
|
|
188
188
|
|
|
189
189
|
cc-candybar is designed to be used as a Claude Code statusLine command.
|
|
190
190
|
It reads hook data from stdin and outputs formatted statusline.
|
|
@@ -200,4 +200,4 @@ Add to ~/.claude/settings.json:
|
|
|
200
200
|
Run with --help for more options.
|
|
201
201
|
|
|
202
202
|
To test output manually:
|
|
203
|
-
echo '{"session_id":"test-session","workspace":{"project_dir":"/path/to/project"},"model":{"id":"claude-sonnet-4-5","display_name":"Claude"}}' | cc-candybar --style=powerline`),t.exit(1)),O(`Working directory: ${t.cwd()}`),O(`Process args:`,t.argv);let r=await n(t.stdin);O(`Received hook data:`,JSON.stringify(r,null,2)),r||(console.error(`Error: No input data received from stdin`),
|
|
203
|
+
echo '{"session_id":"test-session","workspace":{"project_dir":"/path/to/project"},"model":{"id":"claude-sonnet-4-5","display_name":"Claude"}}' | cc-candybar --style=powerline`),t.exit(1)),O(`Working directory: ${t.cwd()}`),O(`Process args:`,t.argv);let r=await n(t.stdin);O(`Received hook data:`,JSON.stringify(r,null,2)),r||(console.error(`Error: No input data received from stdin`),DE(),t.exit(1));let i=CE(await nt(r,t.argv,t.cwd(),{termCols:wE(),ssh:EE()}));i.debug!==null&&O(i.debug),i.kick&&ht(),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)}}OE();export{};
|