@promptctl/cc-candybar 1.7.2 → 1.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import e from"node:process";import{json as t}from"node:stream/consumers";import n,{createReadStream as r,existsSync as i,watch as a}from"node:fs";import o,{basename as s,dirname as c,join as l}from"node:path";import u,{homedir as d}from"node:os";import{spawn as f,spawnSync as p}from"node:child_process";import m from"node:net";import{URL as h,URLSearchParams as g,fileURLToPath as _}from"node:url";import{parseArgs as v}from"node:util";import{get as y}from"node:https";import{createHash as b}from"node:crypto";import{setTimeout as x}from"node:timers/promises";import{open as S,readFile as C,readdir as ee,stat as te}from"node:fs/promises";import{createInterface as w}from"node:readline";import{clearInterval as ne,setInterval as re}from"node:timers";import ie from"node:v8";var T=Object.create,E=Object.defineProperty,ae=Object.getOwnPropertyDescriptor,oe=Object.getOwnPropertyNames,se=Object.getPrototypeOf,ce=Object.prototype.hasOwnProperty,D=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),le=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=oe(t),a=0,o=i.length,s;a<o;a++)s=i[a],!ce.call(e,s)&&s!==n&&E(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=ae(t,s))||r.enumerable});return e},ue=(e,t,n)=>(n=e==null?{}:T(se(e)),le(t||!e||!e.__esModule?E(n,`default`,{value:e,enumerable:!0}):n,e));function O(e,...t){process.env.CC_CANDYBAR_DEBUG&&console.error(`[DEBUG] ${e}`,...t)}const de={"click.pbcopy":1e3,"click.open":1e3},fe=new Map;function pe(e){let t=de[e];if(t===void 0)return{allowed:!0};let n=fe.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 me(e){fe.set(e,Date.now())}function he(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 ge=null;function k(e){ge=e}async function _e(e){let t=pe(e.category);if(!t.allowed)return he(e.category,t.minIntervalMs,t.sinceLastMs);me(e.category);let n=Date.now();return ge?.onStart(e.category),new Promise(t=>{let r;try{r=f(e.bin,e.args??[],{cwd:e.cwd,env:e.env,stdio:[`pipe`,`pipe`,`pipe`]})}catch(r){ge?.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),ge?.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 ve(e){let t=pe(e.category);if(!t.allowed)return he(e.category,t.minIntervalMs,t.sinceLastMs);me(e.category);let n=Date.now();ge?.onStart(e.category);let r=[`pipe`,`pipe`,`pipe`];try{let t=p(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`});ge?.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 ge?.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 ye(e){let t=pe(e.category);if(!t.allowed)return he(e.category,t.minIntervalMs,t.sinceLastMs);me(e.category);let n=Date.now();ge?.onStart(e.category);let r=be(e);return ge?.onEnd(e.category,Date.now()-n),r}function be(e){let t;try{t=f(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 xe(e){let t=process.env[e];return t&&t.length>0?t:void 0}function Se(){let e=xe(`XDG_STATE_HOME`)??o.join(u.homedir(),`.local`,`state`);return o.join(e,`cc-candybar`)}function Ce(){let e=xe(`XDG_CACHE_HOME`)??o.join(u.homedir(),`.cache`);return o.join(e,`cc-candybar`)}function we(){return Se()}function Te(){let e=process.env.CC_CANDYBAR_SOCKET;if(e)return e;let t=u.userInfo().uid;return o.join(`/tmp`,`cc-candybar-${t}`,`socket`)}function Ee(e){let t=o.dirname(e);n.mkdirSync(t,{recursive:!0,mode:448});let r=n.lstatSync(t);if(r.isSymbolicLink())throw Error(`socket parent is a symlink: ${t}`);if(!r.isDirectory())throw Error(`socket parent is not a directory: ${t}`);let i=u.userInfo().uid;if(typeof i==`number`&&r.uid!==i)throw Error(`socket parent is not owned by uid ${i}: ${t} (owner uid=${r.uid})`);if(r.mode&63)throw Error(`socket parent has unsafe permissions: ${t} (mode=${(r.mode&511).toString(8)}, expected 0700)`);try{if(n.lstatSync(e).isSymbolicLink())throw Error(`socket path is a symlink: ${e}`)}catch(e){if(e.code!==`ENOENT`)throw e}}function De(){return o.join(Se(),`pid`)}function Oe(){return o.join(Se(),`session-state.json`)}function ke(){return o.join(Se(),`spawn.lock`)}function A(){return o.join(Se(),`daemon.log`)}const Ae=1e4;function je(e){if(typeof e!=`number`||!Number.isFinite(e))return;let t=Math.floor(e);if(!(t<=0))return t>Ae?Ae:t}var Me=class extends Error{constructor(e){super(e),this.name=`ProtocolError`}};function Ne(e){let t=Buffer.from(JSON.stringify(e),`utf8`),n=Buffer.alloc(4);return n.writeUInt32BE(t.length,0),Buffer.concat([n,t])}function Pe(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 Me(`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 Me(e instanceof Error?e.message:String(e));e instanceof Error&&(n.cause=e),t(n);return}}}}function Fe(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=Pe(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(Ne(t))})}async function Ie(e,t,n){let r=null;try{r=await Ve(Te(),t.connectMs);let i=await Fe(r,{v:3,...e},t.budgetMs);return ze(e.kind,i,n)}catch(e){return Be(e)}finally{r&&r.destroy()}}function Le(e,t){return typeof e==`string`?e:t}function Re(e){return typeof e==`number`&&Number.isInteger(e)&&e>=0?e:0}function ze(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=Le(r.error,`(no error message)`);switch(r.code){case`VERSION_MISMATCH`:return{kind:`permanent`,cause:`version_mismatch`,clientV:3,daemonV:Re(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 Be(e){if(e instanceof Me||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 Ve(e,t){return new Promise((n,r)=>{let i=m.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 He(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 Ue={connectMs:50,budgetMs:150},We={connectMs:50,budgetMs:200};function Ge(e){let t=e.output;return typeof t==`string`?t:void 0}function Ke(e,t,n,r){return Ie({kind:`render`,hookData:e,args:t,cwd:n,termCols:r},Ue,Ge)}function qe(e,t){return Ie({kind:`click`,verb:e,value:t},We,Ge)}function Je(t={}){if(tt()!==null)return;let n=t.spawn??nt,r=Qe();if(r.kind===`contended`){let t=Ye();t!==null&&t>2e3&&(e.stderr.write(`cc-candybar: spawn-lock held ${t}ms (likely crashed holder) — spawning unlocked\n`),Xe(n));return}if(r.kind===`error`){e.stderr.write(`cc-candybar: spawn-lock unavailable (${r.reason}) — spawning unlocked\n`),Xe(n);return}try{Xe(n)}finally{et()}}function Ye(){try{let e=n.statSync(ke());return Date.now()-e.mtimeMs}catch{return null}}function Xe(t){try{t()||e.stderr.write(`cc-candybar: daemon spawn returned false (unable to resolve script path?)
3
- `)}catch(t){e.stderr.write(`cc-candybar: daemon spawn failed: ${t.message}\n`)}}let Ze=null;function Qe(){let t=ke();for(let r=0;r<2;r++){try{let r=n.openSync(t,`wx`,384);try{n.writeSync(r,JSON.stringify({pid:e.pid,ts:Date.now()}))}catch{}return Ze={fd:r,path:t},{kind:`held`}}catch(e){let n=e.code;if(n!==`EEXIST`)return{kind:`error`,reason:`openSync(${t}): ${n??e.message}`}}if(!$e(t))return{kind:`contended`};try{n.unlinkSync(t)}catch(e){if(e.code!==`ENOENT`)return{kind:`error`,reason:`unlink stale spawn.lock: ${e.message}`}}}return{kind:`contended`}}function $e(e){try{let t=n.statSync(e);return Date.now()-t.mtimeMs>1e4}catch{return!0}}function et(){if(!Ze)return;let{fd:e,path:t}=Ze;Ze=null;try{n.closeSync(e)}catch{}try{n.unlinkSync(t)}catch{}}function tt(){try{return n.mkdirSync(we(),{recursive:!0}),null}catch(e){return`mkdir ${we()}: ${e.message}`}}function nt(){let t=e.execPath,n=e.argv[1];return n?ye({bin:t,args:[`--max-old-space-size=400`,n,`daemon`],category:`daemon-spawn`}).ok:!1}const rt=`cc-candybar`,it=`dispatch`,at=`set-state`,ot=`step-state`,st=`copy`,ct=`open-vscode`,lt=`show-config-error`,ut=`show-config-warning`;function dt(e){return e.map(encodeURIComponent).join(`/`)}function ft(e){return e.length===0?[]:e.split(`/`).map(decodeURIComponent)}function pt(e){return`${rt}://${it}/${e.map(e=>`e=${encodeURIComponent(`${e.verb}/${dt(e.args)}`)}`).join(`&`)}`}function mt(e){return new g(e).getAll(`e`).map(ht)}function ht(e){let t=e.indexOf(`/`);return t===-1?{verb:e,value:``}:{verb:e.slice(0,t),value:e.slice(t+1)}}const gt=`@promptctl/cc-candybar`,_t=`CCCandybarURLHandler`,vt=[];function yt(e){return/^[A-Za-z0-9_./=,:-]+$/.test(e)?e:`'${e.replace(/'/g,`'\\''`)}'`}function bt(e){return[`pnpm`,`dlx`,`${gt}@1.7.2`,...e.map(yt)].join(` `)}function xt(){return o.join(u.homedir(),`Applications`,`${_t}.app`)}function St(){return o.join(u.homedir(),`.claude`,`settings.json`)}function Ct(){if(process.platform!==`darwin`)throw Error(`URL handler installation requires macOS (found platform: ${process.platform}).`)}function wt(){return o.join(u.homedir(),`Library`,`Application Support`,`CCCandybar`)}function Tt(){return o.join(wt(),`url-handler.mjs`)}function Et(e,t,n){let r=e.replace(/"/g,`\\"`),i=t.replace(/"/g,`\\"`);return[`on open location L`,`\tdo shell script "NODE_PATH='${n.replace(/"/g,`\\"`)}' '${r}' '${i}' url-handle " & quoted form of L`,`end open location`].join(`
3
+ `)}catch(t){e.stderr.write(`cc-candybar: daemon spawn failed: ${t.message}\n`)}}let Ze=null;function Qe(){let t=ke();for(let r=0;r<2;r++){try{let r=n.openSync(t,`wx`,384);try{n.writeSync(r,JSON.stringify({pid:e.pid,ts:Date.now()}))}catch{}return Ze={fd:r,path:t},{kind:`held`}}catch(e){let n=e.code;if(n!==`EEXIST`)return{kind:`error`,reason:`openSync(${t}): ${n??e.message}`}}if(!$e(t))return{kind:`contended`};try{n.unlinkSync(t)}catch(e){if(e.code!==`ENOENT`)return{kind:`error`,reason:`unlink stale spawn.lock: ${e.message}`}}}return{kind:`contended`}}function $e(e){try{let t=n.statSync(e);return Date.now()-t.mtimeMs>1e4}catch{return!0}}function et(){if(!Ze)return;let{fd:e,path:t}=Ze;Ze=null;try{n.closeSync(e)}catch{}try{n.unlinkSync(t)}catch{}}function tt(){try{return n.mkdirSync(we(),{recursive:!0}),null}catch(e){return`mkdir ${we()}: ${e.message}`}}function nt(){let t=e.execPath,n=e.argv[1];return n?ye({bin:t,args:[`--max-old-space-size=400`,n,`daemon`],category:`daemon-spawn`}).ok:!1}const rt=`cc-candybar`,it=`dispatch`,at=`set-state`,ot=`step-state`,st=`copy`,ct=`open-vscode`,lt=`show-config-error`,ut=`show-config-warning`;function dt(e){return e.map(encodeURIComponent).join(`/`)}function ft(e){return e.length===0?[]:e.split(`/`).map(decodeURIComponent)}function pt(e){return`${rt}://${it}/${e.map(e=>`e=${encodeURIComponent(`${e.verb}/${dt(e.args)}`)}`).join(`&`)}`}function mt(e){return new g(e).getAll(`e`).map(ht)}function ht(e){let t=e.indexOf(`/`);return t===-1?{verb:e,value:``}:{verb:e.slice(0,t),value:e.slice(t+1)}}const gt=`@promptctl/cc-candybar`,_t=`CCCandybarURLHandler`,vt=[];function yt(e){return/^[A-Za-z0-9_./=,:-]+$/.test(e)?e:`'${e.replace(/'/g,`'\\''`)}'`}function bt(e){return[`pnpm`,`dlx`,`${gt}@1.7.3`,...e.map(yt)].join(` `)}function xt(){return o.join(u.homedir(),`Applications`,`${_t}.app`)}function St(){return o.join(u.homedir(),`.claude`,`settings.json`)}function Ct(){if(process.platform!==`darwin`)throw Error(`URL handler installation requires macOS (found platform: ${process.platform}).`)}function wt(){return o.join(u.homedir(),`Library`,`Application Support`,`CCCandybar`)}function Tt(){return o.join(wt(),`url-handler.mjs`)}function Et(e,t,n){let r=e.replace(/"/g,`\\"`),i=t.replace(/"/g,`\\"`);return[`on open location L`,`\tdo shell script "NODE_PATH='${n.replace(/"/g,`\\"`)}' '${r}' '${i}' url-handle " & quoted form of L`,`end open location`].join(`
4
4
  `)}function Dt(e){if(!e)throw Error(`install-url-handler: process.argv[1] not set`);return e.endsWith(`.mjs`)||e.endsWith(`.js`)?e:o.resolve(o.dirname(e),`..`,`dist`,`index.mjs`)}function Ot(){let e=Dt(process.argv[1]);if(!n.existsSync(e))throw Error(`install-url-handler: bundled dist not found at ${e}. Reinstall the package.`);n.mkdirSync(wt(),{recursive:!0});let t=Tt();return n.copyFileSync(e,t),t}function kt(){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>${rt}</string>`,` </array>`,` </dict>`,`</array>`].join(`
5
5
  `)}]}function At(){Ct();let e=Ot();process.stdout.write(`Copied dist to ${e}\n`);let t=Dt(process.argv[1]),r=o.join(o.dirname(t),`..`,`node_modules`);if(!n.existsSync(r))throw Error(`install-url-handler: node_modules not found at ${r}. Install deps first.`);let i=xt();n.mkdirSync(o.dirname(i),{recursive:!0}),n.existsSync(i)&&n.rmSync(i,{recursive:!0,force:!0}),process.stdout.write(`Building ${i}\n`);let a=ve({bin:`/usr/bin/osacompile`,args:[`-o`,i,`-e`,Et(process.execPath,e,r)],category:`install.osacompile`});if(!a.ok)throw process.stderr.write(a.stderr),Error(`osacompile failed (${a.reason})`);let s=o.join(i,`Contents`,`Info.plist`);for(let{key:e}of kt())ve({bin:`/usr/bin/plutil`,args:[`-remove`,e,s],category:`install.plutil`});for(let{key:e,xml:t}of kt()){let n=ve({bin:`/usr/bin/plutil`,args:[`-insert`,e,`-xml`,t,s],category:`install.plutil`});if(!n.ok)throw process.stderr.write(n.stderr),Error(`plutil -insert ${e} failed (${n.reason})`)}process.stdout.write(`Registering ${rt}:// with Launch Services\n`);let c=ve({bin:`/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister`,args:[`-f`,i],category:`install.lsregister`});if(!c.ok)throw process.stderr.write(c.stderr),Error(`lsregister failed (${c.reason})`);process.stdout.write(`✓ ${_t}.app installed and registered.\n`),process.stdout.write(` Test: open '${rt}://hello-world' && pbpaste\n`)}function jt(e,t=rt){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:st,value:r}:{verb:decodeURIComponent(r.slice(0,i)),value:r.slice(i+1)}}async function Mt(e){e||(process.stderr.write(`url-handle: missing URL argument.
6
6
  `),process.exit(1));let t;try{t=jt(e)}catch(e){process.stderr.write(`url-handle: ${e instanceof Error?e.message:String(e)}\n`),process.exit(1)}let n=await qe(t.verb,t.value);n.kind===`ok`&&process.exit(0),n.kind===`transient`&&(Je(),process.stderr.write(`url-handle: daemon unavailable (${n.cause}: ${n.message})\n`),process.exit(1)),process.stderr.write(Nt(n)+`
@@ -81,7 +81,7 @@ Use 'override' annotation for methods overridden by subclass.`)}}var $i=aa(0),ea
81
81
  `)),r.push(...this.renderOptionRow(n[e],e,t));return r}renderNoMatchRow(e){let t=` ${Br(`(no matches)`,V(e))} `,n=this.disabled?new J({color:`#666666`,bgcolor:`#333333`,dim:!0}):new J({color:this.resolvePalette(`foreground`),bgcolor:this.resolvePalette(`surface`),dim:!0});return[new Y(` `,n),new Y(t,n),new Y(` `,n)]}renderOptionRow(e,t,n){let r=` ${Br(e.label,V(n))} `,i=e.idx===this.selectedIndex,a=t===this.highlightedIndex,o=this.disabled?new J({color:`#666666`,bgcolor:`#333333`,dim:!0}):a?new J({color:this.resolvePalette(`text-primary`),bgcolor:this.resolvePalette(`primary-muted`)}):i?new J({color:this.resolvePalette(`on-primary`),bgcolor:this.resolvePalette(`primary`)}):new J({color:this.resolvePalette(`foreground`),bgcolor:this.resolvePalette(`surface`)});return[new Y(` `,o),new Y(r,o),new Y(` `,o)]}maxLabelLen(){let e=0;for(let t of this.options){let n=B(t);n>e&&(e=n)}return e}measure(e){let t=this.maxLabelLen()+4;return{minimum:t,maximum:t}}resolvePalette(e){let t=this._theme.palette.get(e);return W.fromRgba(t)}}})();var Eo=function(e,t,n){for(var r=arguments.length>2,i=0;i<t.length;i++)n=r?t[i].call(e,n):t[i].call(e);return r?n:void 0},Do=function(e,t,n,r,i,a){function o(e){if(e!==void 0&&typeof e!=`function`)throw TypeError(`Function expected`);return e}for(var s=r.kind,c=s===`getter`?`get`:s===`setter`?`set`:`value`,l=!t&&e?r.static?e:e.prototype:null,u=t||(l?Object.getOwnPropertyDescriptor(l,r.name):{}),d,f=!1,p=n.length-1;p>=0;p--){var m={};for(var h in r)m[h]=h===`access`?{}:r[h];for(var h in r.access)m.access[h]=r.access[h];m.addInitializer=function(e){if(f)throw TypeError(`Cannot add initializers after decoration has completed`);a.push(o(e||null))};var g=(0,n[p])(s===`accessor`?{get:u.get,set:u.set}:u[c],m);if(s===`accessor`){if(g===void 0)continue;if(typeof g!=`object`||!g)throw TypeError(`Object expected`);(d=o(g.get))&&(u.get=d),(d=o(g.set))&&(u.set=d),(d=o(g.init))&&i.unshift(d)}else (d=o(g))&&(s===`field`?i.unshift(d):u[c]=d)}l&&Object.defineProperty(l,r.name,u),f=!0};(()=>{var e,t,n,r,i;let a=Qa,o=[],s,c=[],l=[],u,d=[],f=[],p,m=[],h=[],g,_=[],v=[],y,b=[],x=[],S,C=[],ee=[],te,w,ne,re;return class extends a{static{let ie=typeof Symbol==`function`&&Symbol.metadata?Object.create(a[Symbol.metadata]??null):void 0;s=[X.observable],u=[(e=X.observable).ref.bind(e)],p=[(t=X.observable).ref.bind(t)],g=[(n=X.observable).ref.bind(n)],y=[(r=X.observable).ref.bind(r)],S=[(i=X.observable).ref.bind(i)],te=[X.action],w=[X.action],ne=[X.action],re=[X.action],Do(this,null,s,{kind:`accessor`,name:`value`,static:!1,private:!1,access:{has:e=>`value`in e,get:e=>e.value,set:(e,t)=>{e.value=t}},metadata:ie},c,l),Do(this,null,u,{kind:`accessor`,name:`min`,static:!1,private:!1,access:{has:e=>`min`in e,get:e=>e.min,set:(e,t)=>{e.min=t}},metadata:ie},d,f),Do(this,null,p,{kind:`accessor`,name:`max`,static:!1,private:!1,access:{has:e=>`max`in e,get:e=>e.max,set:(e,t)=>{e.max=t}},metadata:ie},m,h),Do(this,null,g,{kind:`accessor`,name:`step`,static:!1,private:!1,access:{has:e=>`step`in e,get:e=>e.step,set:(e,t)=>{e.step=t}},metadata:ie},_,v),Do(this,null,y,{kind:`accessor`,name:`width`,static:!1,private:!1,access:{has:e=>`width`in e,get:e=>e.width,set:(e,t)=>{e.width=t}},metadata:ie},b,x),Do(this,null,S,{kind:`accessor`,name:`_theme`,static:!1,private:!1,access:{has:e=>`_theme`in e,get:e=>e._theme,set:(e,t)=>{e._theme=t}},metadata:ie},C,ee),Do(this,null,te,{kind:`method`,name:`setTheme`,static:!1,private:!1,access:{has:e=>`setTheme`in e,get:e=>e.setTheme},metadata:ie},null,o),Do(this,null,w,{kind:`method`,name:`handleKey`,static:!1,private:!1,access:{has:e=>`handleKey`in e,get:e=>e.handleKey},metadata:ie},null,o),Do(this,null,ne,{kind:`method`,name:`handleMouse`,static:!1,private:!1,access:{has:e=>`handleMouse`in e,get:e=>e.handleMouse},metadata:ie},null,o),Do(this,null,re,{kind:`method`,name:`setValue`,static:!1,private:!1,access:{has:e=>`setValue`in e,get:e=>e.setValue},metadata:ie},null,o),ie&&Object.defineProperty(this,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:ie})}id=Eo(this,o);focusable=!0;#e=Eo(this,c,void 0);get value(){return this.#e}set value(e){this.#e=e}#t=(Eo(this,l),Eo(this,d,void 0));get min(){return this.#t}set min(e){this.#t=e}#n=(Eo(this,f),Eo(this,m,void 0));get max(){return this.#n}set max(e){this.#n=e}#r=(Eo(this,h),Eo(this,_,void 0));get step(){return this.#r}set step(e){this.#r=e}#i=(Eo(this,v),Eo(this,b,void 0));get width(){return this.#i}set width(e){this.#i=e}#a=(Eo(this,x),Eo(this,C,void 0));get _theme(){return this.#a}set _theme(e){this.#a=e}_dragging=(Eo(this,ee),!1);constructor(e={}){super(),this.id=e.id??`slider-${Math.random().toString(36).slice(2,8)}`,this.min=e.min??0,this.max=e.max??100,this.step=e.step??1;let t=e.width??20;if(!Number.isInteger(t)||t<1)throw RangeError(`Slider width must be a positive integer; got ${t}`);this.width=t,this.value=Oo(e.value??this.min,this.min,this.max,this.step),this.disabled=e.disabled??!1,this._theme=e.theme??Ji}setTheme(e){this._theme=e}handleKey(e){if(!this.disabled)switch(e.key){case`left`:this.setValue(this.value-this.step),e.stop();return;case`right`:this.setValue(this.value+this.step),e.stop();return;case`home`:this.setValue(this.min),e.stop();return;case`end`:this.setValue(this.max),e.stop();return}}handleMouse(e){if(!this.disabled){if(e.type===`mouse_down`){this._dragging=!0,this.setValueFromMouseX(e.x);return}if(e.type===`mouse_move`){this._dragging&&this.setValueFromMouseX(e.x);return}if(e.type===`mouse_up`){let t=this._dragging;this._dragging=!1,t&&(this.setValueFromMouseX(e.x),this.emitSubmit());return}}}setValue(e){let t=Oo(e,this.min,this.max,this.step);t!==this.value&&(this.value=t,this.emitChange())}setValueFromMouseX(e){let t=this.bounds;if(!t)return;let n=Math.max(1,this.width-1),r=Math.max(0,Math.min(this.width-1,e-t.x))/n,i=this.min+r*(this.max-this.min);this.setValue(i)}render(e){let t=e.asciiOnly?`-`:`─`,n=e.asciiOnly?`*`:`●`,r=this.max-this.min,i=r===0?0:(this.value-this.min)/r,a=Math.round(i*(this.width-1)),o={underline:this.focused},s=this.disabled?new J({color:`#666666`,bgcolor:`#333333`,dim:!0,...o}):new J({color:this.resolvePalette(`primary`),...o}),c=this.disabled?new J({color:`#666666`,bgcolor:`#333333`,dim:!0,...o}):new J({color:this.resolvePalette(`surface`),...o}),l=this.disabled?new J({color:`#666666`,bgcolor:`#333333`,dim:!0,bold:!0,...o}):new J({color:this.resolvePalette(`primary`),bold:!0,...o}),u=[];a>0&&u.push(new Y(t.repeat(a),s)),u.push(new Y(n,l));let d=this.width-a-1;return d>0&&u.push(new Y(t.repeat(d),c)),u}measure(e){return{minimum:this.width,maximum:this.width}}resolvePalette(e){let t=this._theme.palette.get(e);return W.fromRgba(t)}}})();function Oo(e,t,n,r){let i=Math.max(t,Math.min(n,e));if(r<=0)return i;let a=t+Math.round((i-t)/r)*r;return Math.max(t,Math.min(n,a))}new TextEncoder,new TextDecoder(`utf-8`),new TextDecoder(`ascii`);function ko(e,t){if(!(e instanceof Sa))throw TypeError(`template function expected a RichText fragment, got ${typeof e==`object`?Object.prototype.toString.call(e):typeof e}`);let n=e.copy();return n.style=e.style.add(t),n}function Ao(e){return{fn:(t=>ko(t,e)),argTypes:[`liftable`],returnType:`T`}}function jo(){let e={};for(let t of Object.keys(gi))e[t]=Ao(new J({color:W.parse(t)}));return e}const Mo={fn:((e,t)=>{if(!Number.isInteger(e)||e<0||e>255)throw RangeError(`color index ${e} is out of range (0-255)`);return ko(t,new J({color:W.fromAnsi(e)}))}),argTypes:[`number`,`liftable`],returnType:`T`},No=/^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$/,Po={fn:((e,t)=>{if(!No.test(e))throw RangeError(`hex expected #RRGGBB or #RRGGBBAA, got ${JSON.stringify(e)}`);return ko(t,new J({color:W.parse(e)}))}),argTypes:[`string`,`liftable`],returnType:`T`},Fo={fn:((e,t,n,r)=>ko(r,new J({color:W.fromRgb(e,t,n)}))),argTypes:[`number`,`number`,`number`,`liftable`],returnType:`T`},Io={fn:((e,t)=>ko(t,new J({bgcolor:W.parse(e)}))),argTypes:[`string`,`liftable`],returnType:`T`};function Lo(e,t){return new J({[e]:t})}function Ro(){let e={};for(let t of na)e[t]=Ao(Lo(t,!0)),e[`not_${t}`]=Ao(Lo(t,!1));for(let[t,n]of Object.entries(ia))e[t]=Ao(Lo(n,!0));return e}const zo={fn:((e,t)=>ko(t,J.parse(e))),argTypes:[`string`,`liftable`],returnType:`T`},Bo={fn:((e,t)=>ko(t,new J({link:e}))),argTypes:[`string`,`liftable`],returnType:`T`};function Vo(){return{...jo(),color:Mo,hex:Po,rgb:Fo,on:Io,...Ro(),link:Bo,style:zo}}const Ho=/^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$/;function Uo(e){if(!Ho.test(e))throw RangeError(`palette background expected #RRGGBB or #RRGGBBAA, got ${JSON.stringify(e)}`);return W.parse(e).getTruecolor()}function Wo(e,t,n,r){let i=e.resolve(t,n===void 0?void 0:{against:n});if(i===null){let e=n===void 0?`; for specs with alpha or auto-contrast, use paletteOver`:``;throw Error(`palette spec ${JSON.stringify(t)} did not resolve — check the spec string is valid and the variable exists${e}`)}return ko(r,new J({color:W.fromRgba(i)}))}const Go=/^[A-Za-z_][A-Za-z0-9_]*$/;function Ko(e){let t={};for(let n of e.palette.vars.keys()){if(!Go.test(n))continue;let r=n;t[r]={fn:(t=>Wo(e,r,void 0,t)),argTypes:[`liftable`],returnType:`T`}}return t}function qo(e){return{fn:((t,n)=>Wo(e,t,void 0,n)),argTypes:[`string`,`liftable`],returnType:`T`}}function Jo(e){return{fn:((t,n,r)=>Wo(e,t,Uo(n),r)),argTypes:[`string`,`string`,`liftable`],returnType:`T`}}function Yo(e){return{fn:((t,n)=>Wo(e,`auto`,Uo(t),n)),argTypes:[`string`,`liftable`],returnType:`T`}}function Xo(e){return{...Ko(e),palette:qo(e),paletteOver:Jo(e),auto:Yo(e)}}function Zo(){return Vo()}new J({color:`red`,dim:!0});const Qo={dark:`textual-dark`,light:`textual-light`};function $o(e){return Qo[e]??e}function es(e,t){return e??t??`textual-dark`}function ts(){return Object.keys(Qo)}function ns(){return[...Vi(),...ts()]}const rs=[`powerline`,`capsule`,`plain`];function is(e){return rs.includes(e)}function as(e,t){let n=e??t??`powerline`;return is(n)?n:`powerline`}var os=class extends Error{file;issues;constructor(e,t){super(ls(e,t)),this.name=`ConfigError`,this.file=e,this.issues=t}};function Q(e,t){let n=0,r;for(let i of t){if(i===``||/^\d+$/.test(i))continue;let t=ss(e,n,i);if(t===-1)return r===void 0?void 0:cs(e,r);n=t,r=t}return r===void 0?void 0:cs(e,r)}function ss(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 cs(e,t){let n=1;for(let r=0;r<t&&r<e.length;r++)e.charCodeAt(r)===10&&n++;return n}function ls(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(`
82
82
  `)}function us(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 ${gs(i)}`,line:Q(e.source,[...t.split(`.`),r])}),null)}function ds(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 ${gs(i)}`,line:Q(e.source,[...t.split(`.`),`default`])});return}return i}}function fs(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 ${gs(i)}`,line:Q(e.source,[...t.split(`.`),r])});return}return i}}function ps(e,t,n){let r=fs(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:Q(e.source,[...t.split(`.`),`palette`])});return}return r}}function ms(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 ${_s(a)}`,line:Q(e.source,[...t.split(`.`),r])});return}return a}}function hs(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function gs(e){return e===null?`null`:Array.isArray(e)?`array`:typeof e}function _s(e){return typeof e==`string`?JSON.stringify(e):e===void 0?`undefined`:String(e)}function vs(e,t,n,r){return hs(r)?(bs(e,n,r,t.noun,new Set(Object.keys(t.fields))),ys(e,t.fields,n,r)):(e.issues.push({path:n,message:`${n} must be an object, got ${gs(r)}`,line:Q(e.source,n.split(`.`))}),null)}function ys(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 bs(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:Q(e.source,[...t.split(`.`),a])})}function xs(e,t,n,r){if(!hs(r))return e.issues.push({path:n,message:`${t.noun} must be an object, got ${gs(r)}`,line:Q(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:Q(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:Q(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:Q(e.source,n.split(`.`))}),null;let c=o[0];return i[c].parse(e,`${n}.${c}`,r[c])}function Ss(e,t,n,r){if(!hs(r))return e.issues.push({path:n,message:`${n} must be an object, got ${gs(r)}`,line:Q(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 ${gs(i)}`,line:Q(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:Q(e.source,[...n.split(`.`),t.tag])}),null)}function Cs(e){return(...t)=>e()(...t)}function ws(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:Q(n.source,o.split(`.`))}),null}return a}}function Ts(){return{required:!1,json:{type:`string`},parse:(e,t,n,r)=>fs(e,t,r,n)}}function Es(){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 ${gs(i)}`,line:Q(e.source,[n])});return}return i}}}}function Ds(){return{required:!1,json:{type:`string`},parse:(e,t,n,r)=>ps(e,t,r)}}function Os(){return{required:!0,json:{type:`string`},parse:(e,t,n,r)=>us(e,t,r,n)??void 0}}function ks(e){return{required:!1,json:{enum:[...e]},parse:(t,n,r,i)=>ms(t,n,i,r,e)}}function As(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 js(e,t,n){let r=e,i={[t]:{const:n},...r.properties},a=[t,...r.required??[]];return{...r,properties:i,required:a}}function Ms(e){let t=e.arms;return{anyOf:Object.values(t).map(e=>e.json)}}function Ns(e){let t=e.arms;return{anyOf:Object.entries(t).map(([e,t])=>({type:`object`,properties:{[e]:t.json},required:[e],additionalProperties:!1}))}}function Ps(e,t=Zn){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??{}},helpers:{...t.helpers,...e.helpers??{}}}}const Fs={noun:`globals key`,fields:{default_bg:Ts(),default_fg:Ts(),default_empty_value:Ts(),default_separator:Ts(),default_truncate_marker:Ts(),palette:Ds(),style:ks(rs)}};function Is(e,t){return t===void 0?{}:vs(e,Fs,`globals`,t)??{}}function Ls(e,t,n,r){return n.cache===void 0?(Rn.includes(r)&&e.issues.push({path:`${t}.cache`,message:`${r} variables must declare a cache policy (one of: ${R.join(`, `)})`,line:Q(e.source,t.split(`.`))}),null):Us(e,`${t}.cache`,n.cache)}function Rs(e,t,n){if(n.cache!==void 0)return Us(e,`${t}.cache`,n.cache)??void 0}function zs(e){return{required:!0,json:Ks(),parse:(t,n,r,i)=>Ls(t,n,i,e)??void 0}}function Bs(){return{required:!1,json:Ks(),parse:(e,t,n,r)=>Rs(e,t,r)}}function Vs(e,t,n){return e.issues.push({path:t,message:n,line:Q(e.source,t.split(`.`))}),null}const Hs={noun:`cache`,arms:{ttl:{json:{type:`string`},parse:(e,t,n)=>typeof n==`string`&&Js(n)?{ttl:n}:Vs(e,t,`cache.ttl must be a duration string like "5s", "100ms", "2m", "1h"; got ${_s(n)}`)},watch_file:{json:{type:`string`},parse:(e,t,n)=>typeof n==`string`&&n!==``?{watch_file:n}:Vs(e,t,`cache.watch_file must be a non-empty path string, got ${_s(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}:Vs(e,t,`cache.depends_on must be an array of variable-name strings, got ${_s(n)}`)},key:{json:{type:`string`},parse:(e,t,n)=>typeof n==`string`&&n!==``?{key:n}:Vs(e,t,`cache.key must be a non-empty template string, got ${_s(n)}`)},never:{json:{const:!0},parse:(e,t,n)=>n===!0?{never:!0}:Vs(e,t,`cache.never must be the literal boolean true, got ${_s(n)}`)}}};function Us(e,t,n){return xs(e,Hs,t,n)}const Ws={noun:`time-variable cache`,arms:{ttl:Hs.arms.ttl}};function Gs(){return{required:!1,json:Ns(Ws),parse:(e,t,n,r)=>r.cache===void 0?void 0:xs(e,Ws,`${t}.cache`,r.cache)??void 0}}function Ks(){return Ns(Hs)}const qs=/^(\d+(?:\.\d+)?)(ms|s|m|h)$/;function Js(e){return qs.test(e)}function Ys(e,t,n){if(n===void 0)return{};if(!hs(n))return e.issues.push({path:t,message:`${t} must be an object, got ${gs(n)}`,line:Q(e.source,t.split(`.`))}),{};let r={};for(let[i,a]of Object.entries(n)){let n=Ss(e,lc,`${t}.${i}`,a);n!==null&&(r[i]=n)}return r}function Xs(){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 ${gs(i)}`,line:Q(e.source,t.split(`.`))});return}return i}}}function Zs(){return{required:!0,json:{enum:[...Ln]},parse:(e,t,n,r)=>{let i=r.field;if(typeof i!=`string`||!Ln.includes(i)){e.issues.push({path:`${t}.field`,message:`git field must be one of: ${Ln.join(`, `)}, got ${JSON.stringify(i)}`,line:Q(e.source,[...t.split(`.`),`field`])});return}return i}}}function Qs(){return{required:!1,json:{type:[`string`,`number`,`boolean`]},parse:(e,t,n,r)=>{let i=r.type;return ds(e,t,r,i===`number`||i===`boolean`||i===`string`?i:`string`)}}}const $s={value:Xs(),default:Ts()},ec={path:Os(),type:ks([`string`,`number`,`boolean`]),default:Qs()},tc={name:Os(),default:Ts()},nc={path:Os(),readMode:ks([`whole`,`first-line`]),regex:Ts(),cache:zs(`file`),default:Ts()},rc={command:Os(),regex:Ts(),cache:zs(`shell`),default:Ts()},ic={template:Os(),cache:Bs(),default:Ts()},ac={layout:Os(),cache:Gs(),default:Ts()},oc={field:Zs(),cache:zs(`git`),default:Ts()},sc={key:Os(),default:Ts()};function cc(e,t){return{json:js(As(t),`kind`,e),parse:(n,r,i)=>{let a=ys(n,t,r,i);return a===null?null:{kind:e,...a}}}}const lc={tag:`kind`,noun:`source kind`,arms:{literal:cc(`literal`,$s),input:cc(`input`,ec),env:cc(`env`,tc),file:cc(`file`,nc),shell:cc(`shell`,rc),template:cc(`template`,ic),time:cc(`time`,ac),git:cc(`git`,oc),state:cc(`state`,sc)}};function uc(){return Ms(lc)}function dc(){return{type:`object`,additionalProperties:uc()}}function fc(e,t){if(t===void 0)return{};if(!hs(t))return e.issues.push({path:`segments`,message:`segments must be an object, got ${gs(t)}`,line:Q(e.source,[`segments`])}),{};let n={};for(let[r,i]of Object.entries(t)){let t=vs(e,hc,`segments.${r}`,i);t!==null&&(n[r]=t)}return n}function pc(){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 ${_s(i)}`,line:Q(e.source,[...t.split(`.`),n])})}}}}function mc(){return{required:!1,json:dc(),parse:(e,t,n,r)=>{let i=r[n];if(i!==void 0)return Ys(e,`${t}.${n}`,i)}}}const hc={noun:`segment key`,fields:{template:Os(),width:pc(),justify:ks(zn),truncate:ks(Bn),bg:Ts(),fg:Ts(),when:Ts(),palette:Ds(),vars:mc()}},gc={kind:`container`,direction:`vertical`,children:[]};function _c(e){return{required:!0,json:{const:e},parse:()=>e}}function vc(){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 ${_s(i)}`,line:Q(e.source,[`root`])}),``)}}}function yc(){return{required:!0,json:{enum:[...Pn]},parse:(e,t,n,r)=>{let i=r[n];return typeof i==`string`&&Pn.includes(i)?i:(e.issues.push({path:`${t}.${n}`,message:`a container "direction" must be one of: ${Pn.join(`, `)} (got ${JSON.stringify(i)})`,line:Q(e.source,[`root`])}),`vertical`)}}}function bc(e){return{required:!0,json:{type:`array`,items:{$ref:`#/definitions/LayoutNode`}},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 ${gs(a)}`,line:Q(t.source,[`root`])}),[])}}}const xc={noun:`layout-node key`,fields:{kind:_c(`segment`),name:vc(),when:Ts()}},Sc={noun:`layout-node key`,fields:{kind:_c(`container`),direction:yc(),children:bc(Cs(()=>Dc)),when:Ts()}};function Cc(){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 ${_s(i)}`,line:Q(e.source,[`root`])}),``)}}}const wc={noun:`layout-node key`,fields:{seg:Cc(),when:Ts()}},Tc={noun:`layout-node key`,fields:{h:bc(Cs(()=>Dc)),when:Ts()}},Ec={noun:`layout-node key`,fields:{v:bc(Cs(()=>Dc)),when:Ts()}},Dc=(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:Q(e.source,[`root`])}),gc):{kind:`segment`,name:n};if(!hs(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 ${gs(n)}`,line:Q(e.source,[`root`])}),gc;if(n.kind===`container`)return vs(e,Sc,t,n)??gc;if(n.kind===`segment`)return vs(e,xc,t,n)??gc;if(n.kind===`cells`)return e.issues.push({path:t,message:`kind: "cells" is no longer supported — use the h-arm spelling instead:
83
83
  Old: { kind: "cells", segments: ["seg1", "seg2"] }
84
- New: { h: ["seg1", "seg2"] }`,line:Q(e.source,[`root`])}),gc;if(n.kind===`group`){let r=vs(e,Pc,t,n);return r===null?gc:(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}),Ic(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:Q(e.source,[`root`])}),gc}if(a){let r=vs(e,wc,t,n);return r===null?gc:{kind:`segment`,name:r.seg,...r.when!==void 0&&{when:r.when}}}if(r){let r=vs(e,Tc,t,n);return r===null?gc:{kind:`container`,direction:`horizontal`,children:r.h,...r.when!==void 0&&{when:r.when}}}if(i){let r=vs(e,Ec,t,n);return r===null?gc:{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:Q(e.source,[`root`])}),gc},Oc=`groups.`,kc=`closed`,Ac=/^[A-Za-z_][A-Za-z0-9_]*$/;function jc(){return{required:!0,json:{type:`string`,pattern:Ac.source},parse:(e,t,n,r)=>{let i=r[n];if(typeof i!=`string`||!Ac.test(i)||i===kc){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 "${kc}", got ${_s(i)}`,line:Q(e.source,[`root`])});return}return i}}}function Mc(){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 ${_s(i)}`,line:Q(e.source,[`root`])});return}return i}}}}function Nc(){return{required:!0,json:{type:`string`,pattern:`^[^\\n\\r]*$`},parse:(e,t,n,r)=>{let i=us(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:Q(e.source,[...t.split(`.`),n])});return}return i}}}}const Pc={noun:`layout-node key`,fields:{kind:_c(`group`),name:jc(),label:Nc(),open:Es(),direction:ks(Pn),key:Mc(),bg:Ts(),fg:Ts(),when:Ts(),children:bc(Cs(()=>Dc))}};function Fc(e){return e.key??`groups.`+e.name}function Ic(e){let t=Oc+e.name;return{kind:`container`,direction:`vertical`,children:[{kind:`segment`,name:t},{kind:`container`,direction:e.direction??`vertical`,children:e.children,when:`{{ eq .${t} "${e.name}" }}`}],...e.when!==void 0&&{when:e.when}}}function Lc(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}function Rc(e,t,n){e.issues.push({path:t,message:n,line:Q(e.source,[`root`])})}function zc(e,t){let n=e.groups;if(n.length===0)return;for(let n of[`variables`,`actions`,`segments`])for(let r of Object.keys(t[n]??{}))r.startsWith(`groups.`)&&Rc(e,`${n}.${r}`,`"${r}" is in the reserved "${Oc}" namespace (synthesized by group nodes) — rename it`);let r=new Set;for(let t of n)r.has(t.name)&&Rc(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}.`)&&Fc(t)===Fc(r)&&Rc(e,t.path,`group "${t.name}" shares key "${Fc(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=Fc(t);if(i.has(n)||i.set(n,kc),t.open===!0){let r=i.get(n);r!==kc&&Rc(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=Oc+e.name,r=Fc(e),c=Lc(e.label),l=n.filter(t=>t!==e&&e.path.startsWith(t.path+`.`)).length,u=` `.repeat(l);a[t]={kind:`state`,key:r,default:i.get(r)},o[t]={set:r,cycle:[kc,e.name]},s[t]={template:`{{ action "${t}" "${u}▸ ${c}" "${u}▾ ${c}" }}`,...e.bg!==void 0&&{bg:e.bg},...e.fg!==void 0&&{fg:e.fg}}}t.variables={...t.variables??{},...a},t.actions={...t.actions??{},...o},t.segments={...t.segments??{},...s}}const Bc=[`themes`,`styles`],Vc=[`set`,`copy`,`open`];function Hc(e){return`set`in e}function Uc(e,t){if(t===void 0)return{};if(!hs(t))return Wc(e,`actions`,`actions must be an object, got ${gs(t)}`),{};let n=Object.create(null);for(let[r,i]of Object.entries(t)){let t=Gc(e,`actions.${r}`,i);t!==null&&(n[r]=t)}return n}function Wc(e,t,n){e.issues.push({path:t,message:n,line:Q(e.source,t.split(`.`))})}function Gc(e,t,n){if(!hs(n))return Wc(e,t,`${t} must be an action object, got ${gs(n)}`),null;let r=Vc.filter(e=>e in n);return r.length===1?Kc[r[0]](e,t,n):(Wc(e,t,`action must declare exactly one of: ${Vc.join(`, `)}${r.length>1?` (found: ${r.join(`, `)})`:``}`),null)}const Kc={set:ol,copy:qc(`copy`),open:qc(`open`)};function qc(e){return(t,n,r)=>{for(let i of Object.keys(r))i!==e&&Wc(t,`${n}.${i}`,`Unknown key "${i}" on a ${e} action. Expected only: ${e}`);let i=us(t,n,r,e);return i===null?null:{[e]:i}}}function Jc(e,t,n,r,i,a){let o=us(e,t,r,n);if(o===null)return null;let s=`${t}.${n}`;return o===``?(Wc(e,s,i),null):o.includes(`/`)?(Wc(e,s,a(o)),null):o}function Yc(e,t,n){return Jc(e,t,`set`,n,`set key must be non-empty (the SessionState key to write)`,e=>`set key "${e}" contains "/" — state keys must be slash-free`)}const Xc={to:sl()},Zc={from:cl()},Qc={min:dl(),max:dl(),by:dl()},$c={int:ul()},el={cycle:ll()},tl={ok:e=>e.min<e.max,issue:e=>({field:`min`,message:`min (${e.min}) must be less than max (${e.max})`})},nl={ok:e=>e.by!==0,issue:()=>({field:`by`,message:`by must be a non-zero integer (the per-click increment; negative steps down)`})};function rl(e,...t){let n=Object.keys(e),r=(t,n,r)=>ys(t,e,n,r),i=As(e);return{detect:n,allowed:[`set`,...n],label:n.join(`/`),json:{type:`object`,properties:{set:{type:`string`},...i.properties},required:[`set`,...i.required??[]],additionalProperties:!1},parse:t.length?ws(r,...t):r}}const il=[rl(Xc),rl(Zc),rl(Qc,tl,nl),rl($c),rl(el)],al=`a set action declares exactly one value source: "to" (a literal value), "from" (an option domain: ${Bc.join(`/`)}), "min"/"max"/"by" (a bounded step), "int" (an unbounded integer cursor), or "cycle" (an enumerated domain stepped in order)`;function ol(e,t,n){let r=Yc(e,t,n),i=il.filter(e=>e.detect.some(e=>e in n));if(i.length!==1)return Wc(e,t,`${al}${i.length>1?` — found: ${i.map(e=>e.label).join(`, `)}`:``}`),null;let a=i[0];for(let r of Object.keys(n))a.allowed.includes(r)||Wc(e,`${t}.${r}`,`Unknown key "${r}" on this set action. Expected one of: ${a.allowed.join(`, `)}`);let o=a.parse(e,t,n);return r===null||o===null?null:{set:r,...o}}function sl(){return{required:!0,json:{type:`string`},parse:(e,t,n,r)=>Jc(e,t,n,r,`set value must be non-empty — an empty value cannot be delivered on the set-state wire`,e=>`set value "${e}" contains "/" — set values must be slash-free`)??void 0}}function cl(){return{required:!0,json:{enum:[...Bc]},parse:(e,t,n,r)=>{let i=r[n];if(typeof i!=`string`||!Bc.includes(i)){Wc(e,`${t}.${n}`,`from must be one of: ${Bc.join(`, `)}, got ${_s(i)}`);return}return i}}}function ll(){return{required:!0,json:{type:`array`,items:{type:`string`,minLength:1},minItems:2,uniqueItems:!0},parse:(e,t,n,r)=>{let i=r[n],a=`${t}.${n}`;if(!Array.isArray(i)||i.some(e=>typeof e!=`string`)){Wc(e,a,`cycle must be an array of strings (the enumerated values a click steps through), got ${gs(i)}`);return}let o=i;if(o.length<2){Wc(e,a,`cycle needs at least two members (one member has no successor — use a literal "to")`);return}let s=o.some(e=>e===``),c=o.filter(e=>e.includes(`/`));if(s){Wc(e,a,`cycle members must be non-empty — an empty value cannot be delivered on the set-state wire`);return}if(c.length>0){Wc(e,a,`cycle member(s) ${c.map(e=>`"${e}"`).join(`, `)} contain "/" — set values must be slash-free`);return}if(new Set(o).size!==o.length){Wc(e,a,`cycle members must be unique — the successor of a duplicated member is ambiguous`);return}return o}}}function ul(){return{required:!0,json:{const:!0},parse:(e,t,n,r)=>{if(r[n]!==!0){Wc(e,`${t}.${n}`,`int must be the literal true (declares the key an unbounded integer cursor — a paged picker's page key), got ${_s(r[n])}`);return}return!0}}}function dl(){return{required:!0,json:{type:`integer`},parse:(e,t,n,r)=>{let i=r[n];if(typeof i!=`number`||!Number.isInteger(i)){Wc(e,`${t}.${n}`,`${n} must be an integer, got ${_s(i)}`);return}return i}}}function fl(e,t){if(t===void 0)return{};if(!hs(t))return e.issues.push({path:`helpers`,message:`helpers must be an object, got ${gs(t)}`,line:Q(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 ${_s(i)}`,line:Q(e.source,[`helpers`,r])});continue}n[r]=i}return n}const pl=/{{([\s\S]*?)}}/g,ml=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`[^`]*`/g,hl=/(?<![A-Za-z0-9_)])\.([A-Za-z_][\w]*(?:\.[A-Za-z_][\w]*)*)/g;function gl(e){let t=new Set,n;for(pl.lastIndex=0;(n=pl.exec(e))!==null;){let e=n[1].replace(ml,``),r;for(hl.lastIndex=0;(r=hl.exec(e))!==null;)t.add(r[1])}return t}const _l=/\baction\s+$/;function vl(e){let t=new Set;pl.lastIndex=0;let n;for(;(n=pl.exec(e))!==null;){let e=n[1],r=0,i;for(ml.lastIndex=0;(i=ml.exec(e))!==null;)_l.test(e.slice(r,i.index))&&t.add(i[0].slice(1,-1)),r=i.index+i[0].length}return t}const yl=/\bpicker\s+$/;function bl(e){let t=new Set;pl.lastIndex=0;let n;for(;(n=pl.exec(e))!==null;){let e=n[1],r=0,i=0,a;for(ml.lastIndex=0;(a=ml.exec(e))!==null;)yl.test(e.slice(r,a.index))&&(i=2),i>0&&(t.add(a[0].slice(1,-1)),i--),r=a.index+a[0].length}return t}function xl(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 Sl={gitTaculous:`gitaculous`};function Cl(e,t){let n=new Set(Object.keys(t.variables));for(let[e,r]of Object.entries(t.segments))if(r.vars)for(let t of Object.keys(r.vars))n.add(`${e}.${t}`);let r=kl(e.source),i=Q(e.source,[r]);for(let a of Fn(t.root))if(a.when!==void 0&&Ol(e,`${r}.when`,a.when,n,{line:i}),a.kind===`segment`&&!Object.prototype.hasOwnProperty.call(t.segments,a.name)){let t=Sl[a.name],n=t===void 0?``:` (the built-in segment "${a.name}" was renamed to "${t}" — update this reference)`;e.issues.push({path:r,message:`${r} entry "${a.name}" does not match any declared segment${n}`,line:i})}for(let[r,i]of Object.entries(t.variables))El(e,`variables.${r}`,i,n);for(let[r,i]of Object.entries(t.segments)){if(i.vars)for(let[t,a]of Object.entries(i.vars))El(e,`segments.${r}.vars.${t}`,a,n,r);for(let a of[`template`,`bg`,`fg`,`when`]){let o=i[a];if(typeof o==`string`){Ol(e,`segments.${r}.${a}`,o,n,{segCtx:r});for(let n of vl(o))Object.prototype.hasOwnProperty.call(t.actions,n)||e.issues.push({path:`segments.${r}.${a}`,message:`${a} references unknown action "${n}"`,line:Q(e.source,[`segments`,r,a])});for(let n of bl(o))Object.prototype.hasOwnProperty.call(t.actions,n)||e.issues.push({path:`segments.${r}.${a}`,message:`${a} references unknown action "${n}" (in a picker)`,line:Q(e.source,[`segments`,r,a])})}}}for(let[r,i]of Object.entries(t.variables))Dl(e,`variables.${r}`,i,n);for(let[r,i]of Object.entries(t.segments))if(i.vars)for(let[t,a]of Object.entries(i.vars))Dl(e,`segments.${r}.vars.${t}`,a,n,r);(wl(t)||Tl(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:Q(e.source,[`variables`])})}function wl(e){for(let t of Object.values(e.variables))if(t.kind===`state`)return!0;for(let t of Object.values(e.segments))if(t.vars){for(let e of Object.values(t.vars))if(e.kind===`state`)return!0}return!1}function Tl(e){return Object.values(e.actions).some(Hc)}function El(e,t,n,r,i){n.kind===`template`&&Ol(e,`${t}.template`,n.template,r,{segCtx:i}),In(n)&&n.cache&&`key`in n.cache&&Ol(e,`${t}.cache.key`,n.cache.key,r,{segCtx:i})}function Dl(e,t,n,r,i){if(In(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:Q(e.source,[...t.split(`.`),`cache`,`depends_on`])})}}function Ol(e,t,n,r,i){for(let a of gl(n)){if(xl(a,r))continue;let n=i?.segCtx===void 0?void 0:`${i.segCtx}.${a}`,o=n!==void 0&&xl(n,r)?` (segment-local vars are namespaced — write ".${n}")`:``;e.issues.push({path:t,message:`Template references unknown variable ".${a}"${o}`,line:i?.line??Q(e.source,t.split(`.`))})}}function kl(e){try{let t=Wn.default.parse(e);if(hs(t)&&`root`in t)return`root`}catch{}return`layout`}function Al(e,t){let{graph:n,nodeInfo:r}=jl(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:Q(e.source,o?.linePathParts??[`variables`,i])}),!0}if(t===0&&o(s))return!0}return i.set(t,2),a.pop(),!1}}function jl(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 gl(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),In(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 Ml=[`json5`,`json`];function Nl(e){return e===`~`||e.startsWith(`~/`)||e.startsWith(`~\\`)?u.homedir()+e.slice(1):e}function Pl(e,t,n){if(n)return[n];let r=process.env.CC_CANDYBAR_CONFIG;if(r)return[Nl(r)];let i=t??process.cwd(),a=process.env.XDG_CONFIG_HOME??o.join(u.homedir(),`.config`);return[...e?Ml.map(t=>o.join(e,`.cc-candybar.${t}`)):[],...Ml.map(e=>o.join(i,`.cc-candybar.${e}`)),...Ml.map(e=>o.join(a,`cc-candybar`,`config.${e}`))]}function Fl(e,t,r){return Pl(e,t,r).find(n.existsSync)??null}function Il(e,t){let r=Pl(e,t),i=new Set,a=[];for(let e of r)i.has(e)||(i.add(e),n.existsSync(e)&&a.push(e));let s=new Map;for(let e of a){let t=o.dirname(e),n=o.basename(e).replace(/\.(json5|json)$/,``),r=o.join(t,n);s.has(r)||s.set(r,[]),s.get(r).push(e)}let c=[...s.values()].filter(e=>e.length>1);return c.length===0?null:`config-extension collision: ${c.map(e=>{let[t,...n]=e;return`${t} shadows ${n.join(`, `)}`}).join(`; `)} — remove the duplicate`}function Ll(e,t=Zn,r){let i=e===null?``:n.readFileSync(e,`utf-8`);return{config:Ps(e===null?{}:zl(e,i,r),t),source:i}}function Rl(e,t=`<config>`,n=``,r=new Set(ns())){let i=[],a={source:n,issues:i,allowedPalettes:r,groups:[]};if(Cl(a,e),Al(a,e),i.length>0)throw new os(t,i);return e}function zl(e,t,n=new Set(ns())){let r=Bl(e,t),i=[],a={source:t,issues:i,allowedPalettes:n,groups:[]};if(!hs(r))throw new os(e,[{path:``,message:`Config root must be an object, got ${gs(r)}`}]);let o=Vl(a,r);if(i.length>0)throw new os(e,i);return o}function Bl(e,t){try{return Wn.default.parse(t)}catch(t){let n=t;throw new os(e,[{path:``,message:`JSON5 syntax error: ${n.message}`,line:n.lineNumber,col:n.columnNumber}])}}function Vl(e,t){for(let n of Object.keys(t))Hl.has(n)||e.issues.push({path:n,message:`Unknown top-level key "${n}". Expected one of: ${[...Hl].join(`, `)}`,line:Q(e.source,[n])});let n={};return t.globals!==void 0&&(n.globals=Is(e,t.globals)),t.variables!==void 0&&(n.variables=Ys(e,`variables`,t.variables)),t.segments!==void 0&&(n.segments=fc(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.
84
+ New: { h: ["seg1", "seg2"] }`,line:Q(e.source,[`root`])}),gc;if(n.kind===`group`){let r=vs(e,Pc,t,n);return r===null?gc:(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}),Ic(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:Q(e.source,[`root`])}),gc}if(a){let r=vs(e,wc,t,n);return r===null?gc:{kind:`segment`,name:r.seg,...r.when!==void 0&&{when:r.when}}}if(r){let r=vs(e,Tc,t,n);return r===null?gc:{kind:`container`,direction:`horizontal`,children:r.h,...r.when!==void 0&&{when:r.when}}}if(i){let r=vs(e,Ec,t,n);return r===null?gc:{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:Q(e.source,[`root`])}),gc},Oc=`groups.`,kc=`closed`,Ac=/^[A-Za-z_][A-Za-z0-9_]*$/;function jc(){return{required:!0,json:{type:`string`,pattern:Ac.source},parse:(e,t,n,r)=>{let i=r[n];if(typeof i!=`string`||!Ac.test(i)||i===kc){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 "${kc}", got ${_s(i)}`,line:Q(e.source,[`root`])});return}return i}}}function Mc(){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 ${_s(i)}`,line:Q(e.source,[`root`])});return}return i}}}}function Nc(){return{required:!0,json:{type:`string`,pattern:`^[^\\n\\r]*$`},parse:(e,t,n,r)=>{let i=us(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:Q(e.source,[...t.split(`.`),n])});return}return i}}}}const Pc={noun:`layout-node key`,fields:{kind:_c(`group`),name:jc(),label:Nc(),open:Es(),direction:ks(Pn),key:Mc(),bg:Ts(),fg:Ts(),when:Ts(),children:bc(Cs(()=>Dc))}};function Fc(e){return e.key??`groups.`+e.name}function Ic(e){let t=Oc+e.name;return{kind:`container`,direction:`vertical`,children:[{kind:`segment`,name:t},{kind:`container`,direction:e.direction??`vertical`,children:e.children,when:`{{ eq .${t} "${e.name}" }}`}],...e.when!==void 0&&{when:e.when}}}function Lc(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}function Rc(e,t,n){e.issues.push({path:t,message:n,line:Q(e.source,[`root`])})}function zc(e,t){let n=e.groups;if(n.length===0)return;for(let n of[`variables`,`actions`,`segments`])for(let r of Object.keys(t[n]??{}))r.startsWith(`groups.`)&&Rc(e,`${n}.${r}`,`"${r}" is in the reserved "${Oc}" namespace (synthesized by group nodes) — rename it`);let r=new Set;for(let t of n)r.has(t.name)&&Rc(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}.`)&&Fc(t)===Fc(r)&&Rc(e,t.path,`group "${t.name}" shares key "${Fc(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=Fc(t);if(i.has(n)||i.set(n,kc),t.open===!0){let r=i.get(n);r!==kc&&Rc(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=Oc+e.name,r=Fc(e),c=Lc(e.label),l=n.filter(t=>t!==e&&e.path.startsWith(t.path+`.`)).length,u=` `.repeat(l);a[t]={kind:`state`,key:r,default:i.get(r)},o[t]={set:r,cycle:[kc,e.name]},s[t]={template:`{{ action "${t}" "${u}${c} ▸" "${u}${c} ▾" }}`,...e.bg!==void 0&&{bg:e.bg},...e.fg!==void 0&&{fg:e.fg}}}t.variables={...t.variables??{},...a},t.actions={...t.actions??{},...o},t.segments={...t.segments??{},...s}}const Bc=[`themes`,`styles`],Vc=[`set`,`copy`,`open`];function Hc(e){return`set`in e}function Uc(e,t){if(t===void 0)return{};if(!hs(t))return Wc(e,`actions`,`actions must be an object, got ${gs(t)}`),{};let n=Object.create(null);for(let[r,i]of Object.entries(t)){let t=Gc(e,`actions.${r}`,i);t!==null&&(n[r]=t)}return n}function Wc(e,t,n){e.issues.push({path:t,message:n,line:Q(e.source,t.split(`.`))})}function Gc(e,t,n){if(!hs(n))return Wc(e,t,`${t} must be an action object, got ${gs(n)}`),null;let r=Vc.filter(e=>e in n);return r.length===1?Kc[r[0]](e,t,n):(Wc(e,t,`action must declare exactly one of: ${Vc.join(`, `)}${r.length>1?` (found: ${r.join(`, `)})`:``}`),null)}const Kc={set:ol,copy:qc(`copy`),open:qc(`open`)};function qc(e){return(t,n,r)=>{for(let i of Object.keys(r))i!==e&&Wc(t,`${n}.${i}`,`Unknown key "${i}" on a ${e} action. Expected only: ${e}`);let i=us(t,n,r,e);return i===null?null:{[e]:i}}}function Jc(e,t,n,r,i,a){let o=us(e,t,r,n);if(o===null)return null;let s=`${t}.${n}`;return o===``?(Wc(e,s,i),null):o.includes(`/`)?(Wc(e,s,a(o)),null):o}function Yc(e,t,n){return Jc(e,t,`set`,n,`set key must be non-empty (the SessionState key to write)`,e=>`set key "${e}" contains "/" — state keys must be slash-free`)}const Xc={to:sl()},Zc={from:cl()},Qc={min:dl(),max:dl(),by:dl()},$c={int:ul()},el={cycle:ll()},tl={ok:e=>e.min<e.max,issue:e=>({field:`min`,message:`min (${e.min}) must be less than max (${e.max})`})},nl={ok:e=>e.by!==0,issue:()=>({field:`by`,message:`by must be a non-zero integer (the per-click increment; negative steps down)`})};function rl(e,...t){let n=Object.keys(e),r=(t,n,r)=>ys(t,e,n,r),i=As(e);return{detect:n,allowed:[`set`,...n],label:n.join(`/`),json:{type:`object`,properties:{set:{type:`string`},...i.properties},required:[`set`,...i.required??[]],additionalProperties:!1},parse:t.length?ws(r,...t):r}}const il=[rl(Xc),rl(Zc),rl(Qc,tl,nl),rl($c),rl(el)],al=`a set action declares exactly one value source: "to" (a literal value), "from" (an option domain: ${Bc.join(`/`)}), "min"/"max"/"by" (a bounded step), "int" (an unbounded integer cursor), or "cycle" (an enumerated domain stepped in order)`;function ol(e,t,n){let r=Yc(e,t,n),i=il.filter(e=>e.detect.some(e=>e in n));if(i.length!==1)return Wc(e,t,`${al}${i.length>1?` — found: ${i.map(e=>e.label).join(`, `)}`:``}`),null;let a=i[0];for(let r of Object.keys(n))a.allowed.includes(r)||Wc(e,`${t}.${r}`,`Unknown key "${r}" on this set action. Expected one of: ${a.allowed.join(`, `)}`);let o=a.parse(e,t,n);return r===null||o===null?null:{set:r,...o}}function sl(){return{required:!0,json:{type:`string`},parse:(e,t,n,r)=>Jc(e,t,n,r,`set value must be non-empty — an empty value cannot be delivered on the set-state wire`,e=>`set value "${e}" contains "/" — set values must be slash-free`)??void 0}}function cl(){return{required:!0,json:{enum:[...Bc]},parse:(e,t,n,r)=>{let i=r[n];if(typeof i!=`string`||!Bc.includes(i)){Wc(e,`${t}.${n}`,`from must be one of: ${Bc.join(`, `)}, got ${_s(i)}`);return}return i}}}function ll(){return{required:!0,json:{type:`array`,items:{type:`string`,minLength:1},minItems:2,uniqueItems:!0},parse:(e,t,n,r)=>{let i=r[n],a=`${t}.${n}`;if(!Array.isArray(i)||i.some(e=>typeof e!=`string`)){Wc(e,a,`cycle must be an array of strings (the enumerated values a click steps through), got ${gs(i)}`);return}let o=i;if(o.length<2){Wc(e,a,`cycle needs at least two members (one member has no successor — use a literal "to")`);return}let s=o.some(e=>e===``),c=o.filter(e=>e.includes(`/`));if(s){Wc(e,a,`cycle members must be non-empty — an empty value cannot be delivered on the set-state wire`);return}if(c.length>0){Wc(e,a,`cycle member(s) ${c.map(e=>`"${e}"`).join(`, `)} contain "/" — set values must be slash-free`);return}if(new Set(o).size!==o.length){Wc(e,a,`cycle members must be unique — the successor of a duplicated member is ambiguous`);return}return o}}}function ul(){return{required:!0,json:{const:!0},parse:(e,t,n,r)=>{if(r[n]!==!0){Wc(e,`${t}.${n}`,`int must be the literal true (declares the key an unbounded integer cursor — a paged picker's page key), got ${_s(r[n])}`);return}return!0}}}function dl(){return{required:!0,json:{type:`integer`},parse:(e,t,n,r)=>{let i=r[n];if(typeof i!=`number`||!Number.isInteger(i)){Wc(e,`${t}.${n}`,`${n} must be an integer, got ${_s(i)}`);return}return i}}}function fl(e,t){if(t===void 0)return{};if(!hs(t))return e.issues.push({path:`helpers`,message:`helpers must be an object, got ${gs(t)}`,line:Q(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 ${_s(i)}`,line:Q(e.source,[`helpers`,r])});continue}n[r]=i}return n}const pl=/{{([\s\S]*?)}}/g,ml=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`[^`]*`/g,hl=/(?<![A-Za-z0-9_)])\.([A-Za-z_][\w]*(?:\.[A-Za-z_][\w]*)*)/g;function gl(e){let t=new Set,n;for(pl.lastIndex=0;(n=pl.exec(e))!==null;){let e=n[1].replace(ml,``),r;for(hl.lastIndex=0;(r=hl.exec(e))!==null;)t.add(r[1])}return t}const _l=/\baction\s+$/;function vl(e){let t=new Set;pl.lastIndex=0;let n;for(;(n=pl.exec(e))!==null;){let e=n[1],r=0,i;for(ml.lastIndex=0;(i=ml.exec(e))!==null;)_l.test(e.slice(r,i.index))&&t.add(i[0].slice(1,-1)),r=i.index+i[0].length}return t}const yl=/\bpicker\s+$/;function bl(e){let t=new Set;pl.lastIndex=0;let n;for(;(n=pl.exec(e))!==null;){let e=n[1],r=0,i=0,a;for(ml.lastIndex=0;(a=ml.exec(e))!==null;)yl.test(e.slice(r,a.index))&&(i=2),i>0&&(t.add(a[0].slice(1,-1)),i--),r=a.index+a[0].length}return t}function xl(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 Sl={gitTaculous:`gitaculous`};function Cl(e,t){let n=new Set(Object.keys(t.variables));for(let[e,r]of Object.entries(t.segments))if(r.vars)for(let t of Object.keys(r.vars))n.add(`${e}.${t}`);let r=kl(e.source),i=Q(e.source,[r]);for(let a of Fn(t.root))if(a.when!==void 0&&Ol(e,`${r}.when`,a.when,n,{line:i}),a.kind===`segment`&&!Object.prototype.hasOwnProperty.call(t.segments,a.name)){let t=Sl[a.name],n=t===void 0?``:` (the built-in segment "${a.name}" was renamed to "${t}" — update this reference)`;e.issues.push({path:r,message:`${r} entry "${a.name}" does not match any declared segment${n}`,line:i})}for(let[r,i]of Object.entries(t.variables))El(e,`variables.${r}`,i,n);for(let[r,i]of Object.entries(t.segments)){if(i.vars)for(let[t,a]of Object.entries(i.vars))El(e,`segments.${r}.vars.${t}`,a,n,r);for(let a of[`template`,`bg`,`fg`,`when`]){let o=i[a];if(typeof o==`string`){Ol(e,`segments.${r}.${a}`,o,n,{segCtx:r});for(let n of vl(o))Object.prototype.hasOwnProperty.call(t.actions,n)||e.issues.push({path:`segments.${r}.${a}`,message:`${a} references unknown action "${n}"`,line:Q(e.source,[`segments`,r,a])});for(let n of bl(o))Object.prototype.hasOwnProperty.call(t.actions,n)||e.issues.push({path:`segments.${r}.${a}`,message:`${a} references unknown action "${n}" (in a picker)`,line:Q(e.source,[`segments`,r,a])})}}}for(let[r,i]of Object.entries(t.variables))Dl(e,`variables.${r}`,i,n);for(let[r,i]of Object.entries(t.segments))if(i.vars)for(let[t,a]of Object.entries(i.vars))Dl(e,`segments.${r}.vars.${t}`,a,n,r);(wl(t)||Tl(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:Q(e.source,[`variables`])})}function wl(e){for(let t of Object.values(e.variables))if(t.kind===`state`)return!0;for(let t of Object.values(e.segments))if(t.vars){for(let e of Object.values(t.vars))if(e.kind===`state`)return!0}return!1}function Tl(e){return Object.values(e.actions).some(Hc)}function El(e,t,n,r,i){n.kind===`template`&&Ol(e,`${t}.template`,n.template,r,{segCtx:i}),In(n)&&n.cache&&`key`in n.cache&&Ol(e,`${t}.cache.key`,n.cache.key,r,{segCtx:i})}function Dl(e,t,n,r,i){if(In(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:Q(e.source,[...t.split(`.`),`cache`,`depends_on`])})}}function Ol(e,t,n,r,i){for(let a of gl(n)){if(xl(a,r))continue;let n=i?.segCtx===void 0?void 0:`${i.segCtx}.${a}`,o=n!==void 0&&xl(n,r)?` (segment-local vars are namespaced — write ".${n}")`:``;e.issues.push({path:t,message:`Template references unknown variable ".${a}"${o}`,line:i?.line??Q(e.source,t.split(`.`))})}}function kl(e){try{let t=Wn.default.parse(e);if(hs(t)&&`root`in t)return`root`}catch{}return`layout`}function Al(e,t){let{graph:n,nodeInfo:r}=jl(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:Q(e.source,o?.linePathParts??[`variables`,i])}),!0}if(t===0&&o(s))return!0}return i.set(t,2),a.pop(),!1}}function jl(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 gl(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),In(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 Ml=[`json5`,`json`];function Nl(e){return e===`~`||e.startsWith(`~/`)||e.startsWith(`~\\`)?u.homedir()+e.slice(1):e}function Pl(e,t,n){if(n)return[n];let r=process.env.CC_CANDYBAR_CONFIG;if(r)return[Nl(r)];let i=t??process.cwd(),a=process.env.XDG_CONFIG_HOME??o.join(u.homedir(),`.config`);return[...e?Ml.map(t=>o.join(e,`.cc-candybar.${t}`)):[],...Ml.map(e=>o.join(i,`.cc-candybar.${e}`)),...Ml.map(e=>o.join(a,`cc-candybar`,`config.${e}`))]}function Fl(e,t,r){return Pl(e,t,r).find(n.existsSync)??null}function Il(e,t){let r=Pl(e,t),i=new Set,a=[];for(let e of r)i.has(e)||(i.add(e),n.existsSync(e)&&a.push(e));let s=new Map;for(let e of a){let t=o.dirname(e),n=o.basename(e).replace(/\.(json5|json)$/,``),r=o.join(t,n);s.has(r)||s.set(r,[]),s.get(r).push(e)}let c=[...s.values()].filter(e=>e.length>1);return c.length===0?null:`config-extension collision: ${c.map(e=>{let[t,...n]=e;return`${t} shadows ${n.join(`, `)}`}).join(`; `)} — remove the duplicate`}function Ll(e,t=Zn,r){let i=e===null?``:n.readFileSync(e,`utf-8`);return{config:Ps(e===null?{}:zl(e,i,r),t),source:i}}function Rl(e,t=`<config>`,n=``,r=new Set(ns())){let i=[],a={source:n,issues:i,allowedPalettes:r,groups:[]};if(Cl(a,e),Al(a,e),i.length>0)throw new os(t,i);return e}function zl(e,t,n=new Set(ns())){let r=Bl(e,t),i=[],a={source:t,issues:i,allowedPalettes:n,groups:[]};if(!hs(r))throw new os(e,[{path:``,message:`Config root must be an object, got ${gs(r)}`}]);let o=Vl(a,r);if(i.length>0)throw new os(e,i);return o}function Bl(e,t){try{return Wn.default.parse(t)}catch(t){let n=t;throw new os(e,[{path:``,message:`JSON5 syntax error: ${n.message}`,line:n.lineNumber,col:n.columnNumber}])}}function Vl(e,t){for(let n of Object.keys(t))Hl.has(n)||e.issues.push({path:n,message:`Unknown top-level key "${n}". Expected one of: ${[...Hl].join(`, `)}`,line:Q(e.source,[n])});let n={};return t.globals!==void 0&&(n.globals=Is(e,t.globals)),t.variables!==void 0&&(n.variables=Ys(e,`variables`,t.variables)),t.segments!==void 0&&(n.segments=fc(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.
85
85
  Replace: layout: [["seg1", "seg2"], ["seg3"]]
86
86
  With: root: { v: [{ h: ["seg1", "seg2"] }, "seg3"] }
87
87
  Single-row example: root: { h: ["seg1", "seg2"] }`,line:Q(e.source,[`layout`])}),t.root!==void 0&&(n.root=Dc(e,`root`,t.root)),t.actions!==void 0&&(n.actions=Uc(e,t.actions)),t.helpers!==void 0&&(n.helpers=fl(e,t.helpers)),zc(e,n),n}const Hl=new Set([`globals`,`variables`,`segments`,`layout`,`root`,`actions`,`helpers`]),Ul=/"(?:cache_read_input_tokens|cache_creation_input_tokens)":[1-9]/;function Wl(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 Gl(e){let t=await Kl(e);return t.kind===`ok`?N(Math.floor((t.value+36e5)/1e3)):t}async function Kl(e){for(let t of[65536,1048576]){let n=await mn(e,t);if(n.kind!==`ok`)return n;let r=ql(n.value.buf,n.value.fromStart);if(r!=null)return N(r);if(n.value.fromStart)return Bt}return Bt}function ql(e,t){let n=e.toString(`utf8`).split(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptctl/cc-candybar",
3
- "version": "1.7.2",
3
+ "version": "1.7.3",
4
4
  "description": "Statusline renderer for Claude Code — a JSON5-configurable DSL with daemon-cached data sources, byte-clean palette-aware composition, and OSC8 click verbs.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.mjs",
@@ -91,10 +91,10 @@
91
91
  "mobx": "^6.15.0"
92
92
  },
93
93
  "optionalDependencies": {
94
- "@promptctl/cc-candybar-darwin-arm64": "1.7.2",
95
- "@promptctl/cc-candybar-darwin-x64": "1.7.2",
96
- "@promptctl/cc-candybar-linux-x64": "1.7.2",
97
- "@promptctl/cc-candybar-linux-arm64": "1.7.2"
94
+ "@promptctl/cc-candybar-darwin-arm64": "1.7.3",
95
+ "@promptctl/cc-candybar-darwin-x64": "1.7.3",
96
+ "@promptctl/cc-candybar-linux-x64": "1.7.3",
97
+ "@promptctl/cc-candybar-linux-arm64": "1.7.3"
98
98
  },
99
99
  "pnpm": {
100
100
  "supportedArchitectures": {
@@ -654,8 +654,13 @@ export function synthesizeGroupDecls(
654
654
  // sibling-held key counts as the first member, so the toggle renders ▸ and
655
655
  // clicks to its own name — expand, auto-closing the sibling on a shared key.
656
656
  actions[name] = { set: key, cycle: [GROUP_CLOSED, g.name] };
657
+ // [LAW:representation] The disclosure glyph trails the label it gates, so an
658
+ // arrow reads as belonging to the text on its LEFT — adjacent toggles
659
+ // ("details ▸" "links ▸") stay unambiguous even when abutted. `indent` is a
660
+ // structural left-margin (nesting depth) and stays leading; the glyph is a
661
+ // trailing affordance on the label, never a prefix.
657
662
  segments[name] = {
658
- template: `{{ action "${name}" "${indent}${GROUP_GLYPH_CLOSED} ${label}" "${indent}${GROUP_GLYPH_OPEN} ${label}" }}`,
663
+ template: `{{ action "${name}" "${indent}${label} ${GROUP_GLYPH_CLOSED}" "${indent}${label} ${GROUP_GLYPH_OPEN}" }}`,
659
664
  ...(g.bg !== undefined && { bg: g.bg }),
660
665
  ...(g.fg !== undefined && { fg: g.fg }),
661
666
  };