claude-statusline 2.1.4 → 2.1.5

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.
@@ -2,7 +2,7 @@
2
2
  import{readFileSync as St}from"fs";import{z as u}from"zod";import{readFileSync as q,existsSync as Q}from"fs";import{homedir as tt}from"os";import{join as P,dirname as et}from"path";import{parse as rt}from"yaml";var I=u.object({cacheTTL:u.number().default(300),cacheDir:u.string().default("/tmp/.claude-statusline-cache"),maxLength:u.number().default(1e3),noEmoji:u.boolean().default(!1),noGitStatus:u.boolean().default(!1),noContextWindow:u.boolean().default(!1),envContext:u.boolean().default(!1),truncate:u.boolean().default(!1),softWrap:u.boolean().default(!1),noSoftWrap:u.boolean().default(!1),forceWidth:u.number().optional(),debugWidth:u.boolean().default(!1),rightMargin:u.number().default(15),symbols:u.object({git:u.string().default("\uF418"),model:u.string().default("\u{F06A9}"),contextWindow:u.string().default("\u26A1\uFE0E"),staged:u.string().default("+"),conflict:u.string().default("\xD7"),stashed:u.string().default("\u2691"),ahead:u.string().default("\u21E1"),behind:u.string().default("\u21E3"),diverged:u.string().default("\u21D5"),renamed:u.string().default("\xBB"),deleted:u.string().default("\u2718")}).default({}),asciiSymbols:u.object({git:u.string().default("@"),model:u.string().default("*"),contextWindow:u.string().default("#"),staged:u.string().default("+"),conflict:u.string().default("C"),stashed:u.string().default("$"),ahead:u.string().default("A"),behind:u.string().default("B"),diverged:u.string().default("D"),renamed:u.string().default(">"),deleted:u.string().default("X")}).default({})}),nt=I.parse({}),ot=["claude-statusline.json","claude-statusline.yaml"];function W(n=process.cwd()){let t={...nt};return t={...t,...st(n)},t={...t,...it()},I.parse(t)}function st(n){let t=[n,et(n),P(tt(),".claude")];for(let r of t)for(let e of ot){let o=P(r,e);if(Q(o))try{let s=q(o,"utf-8");if(e.endsWith(".json"))return JSON.parse(s);if(e.endsWith(".yaml"))return rt(s)}catch{}}return{}}function it(){let n={};if(process.env.CLAUDE_CODE_STATUSLINE_NO_EMOJI==="1"&&(n.noEmoji=!0),process.env.CLAUDE_CODE_STATUSLINE_NO_GITSTATUS==="1"&&(n.noGitStatus=!0),process.env.CLAUDE_CODE_STATUSLINE_NO_CONTEXT_WINDOW==="1"&&(n.noContextWindow=!0),process.env.CLAUDE_CODE_STATUSLINE_ENV_CONTEXT==="1"&&(n.envContext=!0),process.env.CLAUDE_CODE_STATUSLINE_TRUNCATE==="1"&&(n.truncate=!0),process.env.CLAUDE_CODE_STATUSLINE_SOFT_WRAP==="1"&&(n.softWrap=!0),process.env.CLAUDE_CODE_STATUSLINE_NO_SOFT_WRAP==="1"&&(n.noSoftWrap=!0),process.env.CLAUDE_CODE_STATUSLINE_FORCE_WIDTH){let t=parseInt(process.env.CLAUDE_CODE_STATUSLINE_FORCE_WIDTH,10);!isNaN(t)&&t>0&&(n.forceWidth=t)}return process.env.CLAUDE_CODE_STATUSLINE_DEBUG_WIDTH==="1"&&(n.debugWidth=!0),process.env.CLAUDE_CODE_STATUSLINE_CACHE_DIR&&(n.cacheDir=process.env.CLAUDE_CODE_STATUSLINE_CACHE_DIR),n}var at=4096,ct=[/\.\./,/\.\.\\/,/\[/,/;/,/&/,/</,/>/,/`/];function O(n,t){if(!n||typeof n!="string")return!1;let r=n.trimEnd();if(r.length===0||r.length>t.maxLength||!r.includes("{")||!r.includes("}"))return!1;let e=(r.match(/"/g)||[]).length;if(e===0||e%2!==0)return!1;try{JSON.parse(r)}catch{return!1}return!0}function lt(n){if(!n||typeof n!="string"||n.length>at)return!1;for(let t of ct)if(t.test(n))return!1;if(n.includes("${")||n.includes("`")||n.includes("$("))return!1;try{let t=n.replace(/\/+/g,"/").replace(/\\+/g,"\\");if(t.includes("../")||t.includes("..\\")||t.startsWith("/")&&!t.startsWith("/home/")&&!t.startsWith("/Users/")&&!t.startsWith("/tmp/")&&!["/home","/Users","/tmp","/var","/opt"].some(o=>t.startsWith(o)))return!1;if(t.includes(":")&&/^[A-Za-z]:/.test(t)){let r=t.charAt(0).toUpperCase();if(r<"C"||r>"Z")return!1}}catch{return!1}return!0}async function R(n){if(!lt(n))return!1;try{let{access:t}=await import("fs/promises"),{constants:r}=await import("fs");return await t(n,r.R_OK),!0}catch{return!1}}import{readFile as $,writeFile as A,mkdir as ut}from"fs/promises";import{existsSync as k}from"fs";import{join as w}from"path";var T=class{config;constructor(t){this.config=t}async ensureCacheDir(){try{await ut(this.config.cacheDir,{recursive:!0})}catch{}}getCachePath(t){return w(this.config.cacheDir,t)}getTimestampPath(t){return w(this.config.cacheDir,`${t}.time`)}async get(t,r=this.config.cacheTTL){let e=this.getCachePath(t),o=this.getTimestampPath(t);try{if(!k(e)||!k(o))return null;let s=await $(o,"utf-8"),c=parseInt(s.trim(),10);if(isNaN(c)||Math.floor(Date.now()/1e3)-c>=r)return null;let d=await $(e,"utf-8");try{return JSON.parse(d)}catch{return d}}catch{return null}}async set(t,r){let e=this.getCachePath(t),o=this.getTimestampPath(t);try{await this.ensureCacheDir();let s;typeof r=="string"?s=r:s=JSON.stringify(r);let c=Math.floor(Date.now()/1e3);return await Promise.all([A(e,s,"utf-8"),A(o,c.toString(),"utf-8")]),!0}catch{return!1}}async has(t,r=this.config.cacheTTL){return await this.get(t,r)!==null}async delete(t){let r=this.getCachePath(t),e=this.getTimestampPath(t);try{let{unlink:o}=await import("fs/promises");return await Promise.allSettled([o(r),o(e)]),!0}catch{return!1}}async clear(){try{let{readdir:t,unlink:r}=await import("fs/promises"),e=await t(this.config.cacheDir);return await Promise.allSettled(e.map(o=>r(w(this.config.cacheDir,o)))),!0}catch{return!1}}async getStats(){try{let{readdir:t,stat:r}=await import("fs/promises"),e=await t(this.config.cacheDir),o=0,s=0;for(let c of e)if(!c.endsWith(".time")){s++;let i=w(this.config.cacheDir,c);try{let a=await r(i);o+=a.size}catch{}}return{total:s,size:o}}catch{return{total:0,size:0}}}},S={NODE_VERSION:"node_version",PYTHON_VERSION:"python_version",PYTHON3_VERSION:"python3_version",DOCKER_VERSION:"docker_version",GIT_REMOTE_URL:n=>`git_remote_${Buffer.from(n).toString("base64")}`,GIT_BRANCH:n=>`git_branch_${Buffer.from(n).toString("base64")}`};async function D(n,t,r,e=[],o=300){let s=await n.get(t,o);if(s!==null)return s;try{let{exec:c}=await import("child_process"),{promisify:i}=await import("util"),a=i(c),{stdout:l}=await a(`${r} ${e.join(" ")}`,{timeout:5e3,encoding:"utf-8"}),d=l.trim();return d&&await n.set(t,d),d}catch{return null}}import{spawn as dt}from"child_process";async function E(n,t={}){return new Promise((r,e)=>{let o=dt("git",n,{cwd:t.cwd||process.cwd(),stdio:["ignore","pipe","pipe"],timeout:t.timeout||5e3}),s="",c="";o.stdout.on("data",i=>{s+=i.toString()}),o.stderr.on("data",i=>{c+=i.toString()}),o.on("close",i=>{i===0?r(s):e(new Error(`Git command failed with code ${i}: ${c||s}`))}),o.on("error",i=>{e(new Error(`Failed to execute git command: ${i.message}`))})})}async function M(n){try{return await E(["rev-parse","--git-dir"],n?{cwd:n}:{}),!0}catch{return!1}}async function U(n){let t=n?{cwd:n}:{};try{let e=(await E(["branch","--show-current"],t)).trim();if(e)return e}catch{}try{let e=(await E(["rev-parse","--abbrev-ref","HEAD"],t)).trim();if(e&&e!=="HEAD")return e}catch{}try{let e=(await E(["branch","--no-color"],t)).split(`
3
3
  `);for(let o of e)if(o.startsWith("* "))return o.substring(2).trim()}catch{}return null}async function G(n){return E(["status","--porcelain"],n?{cwd:n}:{})}async function L(n){try{return E(["stash","list"],n?{cwd:n}:{})}catch{return""}}async function B(n){try{return(await E(["rev-parse","--abbrev-ref","@{u}"],n?{cwd:n}:{})).trim()}catch{return""}}async function H(n){try{let e=(await E(["rev-list","--count","--left-right","@{u}...HEAD"],n?{cwd:n}:{})).trim().split(" ");if(e.length===2){let o=parseInt(e[0]||"0",10);return{ahead:parseInt(e[1]||"0",10),behind:o}}}catch{}return{ahead:0,behind:0}}var ft={stashed:0,staged:0,modified:0,untracked:0,renamed:0,deleted:0,conflicts:0,ahead:0,behind:0,diverged:!1},v=class{config;cache;constructor(t,r){this.config=t,this.cache=r}async getGitInfo(t){if(this.config.noGitStatus)return null;try{if(!await M(t))return null;let e=await this.getCurrentBranch(t);if(!e)return null;let o=await this.getGitIndicators(t);return{branch:e,indicators:o}}catch{return null}}async getCurrentBranch(t){let r=`${S.GIT_BRANCH(t)}_current`,e=await this.cache.get(r,60);if(e)return e;try{let o=await U(t);return o?(await this.cache.set(r,o),o):null}catch{return null}}async getGitIndicators(t){let r={...ft};try{let o=(await G(t)).split(`
4
4
  `).map(i=>i.trimEnd()).filter(i=>i.length>0);for(let i of o){if(i.length<2)continue;let a=i.charAt(0),l=i.charAt(1);if(a==="U"||l==="U"||a==="A"&&l==="A"||a==="D"&&l==="D")r.conflicts++;else if(a==="?"&&l==="?")r.untracked++;else{switch(a){case"M":r.staged++;break;case"A":r.staged++;break;case"D":r.deleted++;break;case"R":r.renamed++;break;case"C":r.staged++;break}switch(l){case"M":r.modified++;break;case"D":r.deleted++;break;case"R":r.renamed++;break}}}r.stashed=await this.getStashedCount(t);let{ahead:s,behind:c}=await this.getAheadBehind(t);r.ahead=s,r.behind=c,r.diverged=s>0&&c>0}catch{}return r}async getStashedCount(t){try{return(await L(t)).trim().split(`
5
- `).filter(e=>e.trim().length>0).length}catch{return 0}}async getAheadBehind(t){try{return await B(t)?await H(t):{ahead:0,behind:0}}catch{}return{ahead:0,behind:0}}formatIndicators(t,r){let e=[],o=["stashed","renamed","modified","staged","untracked","deleted","conflicts"];return t.stashed>0&&e.push(r.stashed),t.renamed>0&&e.push(r.renamed),t.modified>0&&e.push("!"),t.staged>0&&e.push(r.staged),t.untracked>0&&e.push("?"),t.deleted>0&&e.push(r.deleted),t.conflicts>0&&e.push(r.conflict),t.diverged?e.push(r.diverged):(t.ahead>0&&e.push(r.ahead),t.behind>0&&e.push(r.behind)),e.join("")}formatGitStatus(t,r){let e=this.formatIndicators(t.indicators,r),o=(this.config.noEmoji,r.git);return e?` ${o} ${t.branch} [${e}]`:` ${o} ${t.branch}`}};var j=new Map,mt=1,V={git:"@",model:"*",contextWindow:"#",staged:"+",conflict:"C",stashed:"$",ahead:"A",behind:"B",diverged:"D",renamed:">",deleted:"X"},ht={git:"\uF418",model:"\u{F06A9}",contextWindow:"\u26A1\uFE0E",staged:"+",conflict:"\xD7",stashed:"\u2691",ahead:"\u21E1",behind:"\u21E3",diverged:"\u21D5",renamed:"\xBB",deleted:"\u2718"};async function z(n){let t=process.env.NERD_FONT+"|"+process.env.TERM_PROGRAM+"|"+process.env.TERM,r=`${mt}:${n.noEmoji?"ascii":"nerd"}:${t}`,e=j.get(r);if(e&&Date.now()-e.timestamp<6e4)return e.symbols;let o;return n.noEmoji?o={...V,...n.symbols,...n.asciiSymbols}:(await gt()).hasNerdFont?o={...ht,...n.symbols}:o={...V,...n.asciiSymbols},j.set(r,{symbols:o,timestamp:Date.now()}),o}async function gt(){let n={hasNerdFont:!1,terminal:"",font:"",method:""};if(process.env.NERD_FONT==="1")return n.hasNerdFont=!0,n.method="NERD_FONT env var",n;let t=process.env.TERM_PROGRAM,r=process.env.TERM;if(t&&(n.terminal=t,n.method="TERM_PROGRAM detection",["vscode","ghostty","wezterm","iterm"].includes(t))||r&&(n.terminal=r,n.method="TERM detection",["alacritty","kitty","wezterm","ghostty","xterm-256color"].includes(r)))return n.hasNerdFont=!0,n;let e=await pt();if(e.hasNerdFont)return n.hasNerdFont=!0,n.font=e.font,n.method="font list detection",n;let o=await yt();return o.hasNerdFont?(n.hasNerdFont=!0,n.font=o.font,n.method="installation detection",n):bt().hasNerdFont?(n.hasNerdFont=!0,n.method="environment detection",n):((await Et()).hasNerdFont&&(n.hasNerdFont=!0,n.method="platform-specific detection"),n)}async function pt(){try{let{exec:n}=await import("child_process"),{promisify:t}=await import("util"),r=t(n),e="",o=process.platform;if(o==="linux"?e="fc-list":o==="darwin"&&(e="system_profiler SPFontsDataType 2>/dev/null || system_profiler SPFontsDataType"),e){let{stdout:s}=await r(e,{timeout:3e3,encoding:"utf-8"}),c=[/nerd font/i,/symbols only/i,/jetbrains mono.*nerd/i,/fira code.*nerd/i,/hack.*nerd/i,/source code pro.*nerd/i,/ubuntu mono.*nerd/i,/anonymous pro.*nerd/i];for(let i of c)if(i.test(s)){let a=s.match(/([^:\n]*)(?=\s*(nerd|symbols))/i);return{hasNerdFont:!0,font:(a?a[1]:"Nerd Font")?.trim()||"Nerd Font"}}}}catch{}return{hasNerdFont:!1,font:""}}async function yt(){try{let{access:n,readdir:t}=await import("fs/promises"),{homedir:r}=await import("os"),e=process.platform,o=[];e==="darwin"?o.push(`${r()}/Library/Fonts`,"/System/Library/Fonts","/Library/Fonts"):e==="linux"&&o.push(`${r()}/.local/share/fonts`,`${r()}/.fonts`,"/usr/share/fonts","/usr/local/share/fonts");let s=["jetbrains-mono-nerd-font","fira-code-nerd-font","hack-nerd-font","source-code-pro-nerd-font","ubuntu-mono-nerd-font","anonymous-pro-nerd-font"];for(let c of o)try{await n(c);let i=await t(c);for(let a of i){let l=a.toLowerCase();for(let d of s)if(l.includes(d))return{hasNerdFont:!0,font:a}}}catch{}}catch{}return{hasNerdFont:!1,font:""}}function bt(){let n=["POWERLINE_COMMAND","NERDFONTS","FONT_FAMILY"];for(let t of n){let r=process.env[t];if(r&&r.toLowerCase().includes("nerd"))return{hasNerdFont:!0}}return process.env.VSCODE_PID||process.env.TERM_PROGRAM==="vscode"||process.env.TERM_PROGRAM==="ghostty"||process.env.TERM_PROGRAM==="wezterm"?{hasNerdFont:!0}:{hasNerdFont:!1}}async function Et(){if(process.platform==="darwin")try{let{exec:t}=await import("child_process"),{promisify:r}=await import("util"),e=r(t),{stdout:o}=await e("brew list | grep -i font",{timeout:2e3,encoding:"utf-8"});if(o.includes("nerd"))return{hasNerdFont:!0}}catch{}return{hasNerdFont:!1}}function K(n){return{node:"\uE718",python:"\uE235",docker:"\uF308",git:n.git,model:n.model}}async function x(n){if(n.forceWidth&&n.forceWidth>0)return n.forceWidth;let t=process.env.COLUMNS;if(t){let i=parseInt(t,10);if(!isNaN(i)&&i>0)return i}if(process.stdout.columns&&process.stdout.columns>0)return process.stdout.columns;let r=await Y("tput",["cols"]);if(r)return r;let e=await J();if(e)return e;let o=process.env.CLAUDE_CODE_TERMINAL_WIDTH;if(o){let i=parseInt(o,10);if(!isNaN(i)&&i>0)return i}let s=process.env.TERM_PROGRAM,c=process.env.TERM;return s==="vscode"&&process.env.VSCODE_PID||["ghostty","wezterm","iterm"].includes(s||"")||c&&["alacritty","kitty","wezterm","ghostty","xterm-256color"].includes(c)||process.env.WT_SESSION||process.env.WT_PROFILE_ID?120:80}async function Y(n,t){try{let{exec:r}=await import("child_process"),{promisify:e}=await import("util"),o=e(r),{stdout:s}=await o(`${n} ${t.join(" ")}`,{timeout:1e3,encoding:"utf-8"}),c=parseInt(s.trim(),10);if(!isNaN(c)&&c>0)return c}catch{}return null}async function J(){try{let{exec:n}=await import("child_process"),{promisify:t}=await import("util"),r=t(n),{stdout:e}=await r("stty size",{timeout:1e3,encoding:"utf-8"}),o=e.trim().split(" ");if(o.length===2){let s=parseInt(o[1]||"0",10);if(!isNaN(s)&&s>0)return s}}catch{}return null}async function X(n){if(!n.debugWidth)return;process.stdout.columns;let t=process.env.COLUMNS,r=await Y("tput",["cols"]),e=await J(),o=await x(n)}function F(n,t){return n.length<=t?n:t<4?"..":`${n.substring(0,t-2)}..`}function Z(n,t,r,e){if(n.length+t.length<=r)return"";let o=r-t.length-2;if(o>=5)return`${n.substring(0,o)}..${t}`;let s="",c=t.match(/\[([^\]]+)\]/);c&&(s=c[1]||"");let i=r-s.length-8;if(i>=8){let a=t.substring(0,Math.min(t.length,i));return`${n.substring(0,4)}..${a}..${s?` [${s}]`:""}`}return`${n.substring(0,r)}..`}function y(n){let t=0;for(let r of n){let e=r.codePointAt(0)??0;e>=4352&&(e>=4352&&e<=4447||e>=11904&&e<=42191||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65040&&e<=65049||e>=65072&&e<=65135||e>=65280&&e<=65376||e>=65504&&e<=65510||e>=131072&&e<=196605||e>=196608&&e<=262141)||e>=127744&&e<=129535||e>=9728&&e<=10175||e>=65024&&e<=65039||e>=126976&&e<=127023||e>=57344&&e<=63743||e>=983040&&e<=1048573||e>=1048576&&e<=1114109?t+=2:e>=768&&e<=879||e>=7616&&e<=7679||e>=8400&&e<=8447||e>=65056&&e<=65071||(t+=1)}return t}var _=class{config;cache;constructor(t,r){this.config=t,this.cache=r}async getEnvironmentInfo(){if(!this.config.envContext)return null;let t={},[r,e,o]=await Promise.allSettled([this.getNodeVersion(),this.getPythonVersion(),this.getDockerVersion()]);return r.status==="fulfilled"&&r.value&&(t.node=r.value),e.status==="fulfilled"&&e.value&&(t.python=e.value),o.status==="fulfilled"&&o.value&&(t.docker=o.value),Object.keys(t).length===0?null:t}async getNodeVersion(){let t=S.NODE_VERSION,r=this.config.cacheTTL*96,e=await this.cache.get(t,r);if(e)return e;try{let o=await D(this.cache,t,"node",["--version"],r);return o?o.replace(/^v/,"").trim():null}catch{return null}}async getPythonVersion(){let t=S.PYTHON3_VERSION,r=S.PYTHON_VERSION,e=this.config.cacheTTL*96;try{let o=await D(this.cache,t,"python3",["--version"],e);if(o){let s=o.match(/(\d+\.\d+\.\d+)/);if(s)return s[1]||null}}catch{}try{let o=await D(this.cache,r,"python",["--version"],e);if(o){let s=o.match(/(\d+\.\d+\.\d+)/);if(s)return s[1]||null}}catch{}return null}async getDockerVersion(){let t="docker_version";try{let r=await D(this.cache,t,"docker",["--version"],this.config.cacheTTL*96);if(r){let e=r.match(/Docker version (\d+\.\d+\.\d+)/);if(e)return e[1]||null}return null}catch{return null}}formatEnvironmentInfo(t,r){let e=[];return t.node&&e.push(`${r.node}${t.node}`),t.python&&e.push(`${r.python}${t.python}`),t.docker&&e.push(`${r.docker}${t.docker}`),e.join(" ")}async getAdditionalTools(){return{}}async isToolAvailable(t){try{let{exec:r}=await import("child_process"),{promisify:e}=await import("util");return await e(r)(`command -v ${t}`,{timeout:2e3}),!0}catch{return!1}}getShellEnvironment(){let t=process.env.SHELL||"unknown",r;return t.includes("bash")?r=process.env.BASH_VERSION:t.includes("zsh")?r=process.env.ZSH_VERSION:t.includes("fish")&&(r=process.env.FISH_VERSION),r?{shell:t,shellVersion:r}:{shell:t}}getOSInfo(){let t=process.platform,r=process.arch,e=process.env.OSTYPE||process.env.OS;return e?{platform:t,arch:r,release:e}:{platform:t,arch:r}}},N=class{symbols;constructor(t){this.symbols=t}format(t,r="compact"){switch(r){case"compact":return this.formatCompact(t);case"verbose":return this.formatVerbose(t);case"minimal":return this.formatMinimal(t);default:return this.formatCompact(t)}}formatCompact(t){let r=[];return t.node&&r.push(`Node${t.node}`),t.python&&r.push(`Py${t.python}`),t.docker&&r.push(`Docker${t.docker}`),r.join(" ")}formatVerbose(t){let r=[];return t.node&&r.push(`Node.js v${t.node}`),t.python&&r.push(`Python ${t.python}`),t.docker&&r.push(`Docker ${t.docker}`),r.join(" \u2022 ")}formatMinimal(t){let r=[];if(t.node){let e=t.node.split(".")[0];r.push(`N${e}`)}if(t.python){let e=t.python.split(".")[0];r.push(`P${e}`)}if(t.docker){let e=t.docker.split(".")[0];r.push(`D${e}`)}return r.join(" ")}formatWithIcons(t){let r=[];return t.node&&r.push(`${this.symbols.node}${t.node}`),t.python&&r.push(`${this.symbols.python}${t.python}`),t.docker&&r.push(`${this.symbols.docker}${t.docker}`),r.join(" ")}};async function Ct(){try{let n=W(),t=new T(n),r=new v(n,t),e=new _(n,t);await X(n);let o=await Dt();O(JSON.stringify(o),n)||process.exit(1);let{fullDir:s,modelName:c,contextWindow:i}=wt(o);(!s||!c)&&process.exit(1),await R(s)||process.exit(1);let l=[r.getGitInfo(s),e.getEnvironmentInfo(),z(n)],d;n.truncate&&l.push(x(n));let m=await Promise.all(l),[h,p,b]=m;n.truncate&&m.length>3&&(d=m[3]);let f=await Tt({fullDir:s,modelName:c,contextWindow:i,gitInfo:h,envInfo:p,symbols:b,...d&&{terminalWidth:d},config:n,gitOps:r});process.stdout.write(f)}catch{process.exit(1)}}async function Dt(){try{let n=St(0,"utf-8");return JSON.parse(n.trim())}catch(n){throw new Error(`Failed to read or parse input: ${n instanceof Error?n.message:String(n)}`)}}function wt(n){let t=n.workspace?.current_dir||"",r=n.model?.display_name||"Unknown",e=n.context_window;return{fullDir:t,modelName:r,contextWindow:e}}async function Tt(n){let{fullDir:t,modelName:r,contextWindow:e,gitInfo:o,envInfo:s,symbols:c,terminalWidth:i,config:a,gitOps:l}=n,d=t.split("/").pop()||t.split("\\").pop()||"project",m="";o&&(m=l.formatGitStatus(o,c));let h="";if(s){let g=K(c);h=` ${new N(g).formatWithIcons(s)}`}let p="";if(e&&!a.noContextWindow){let g=vt(e);g!==null&&(p=` ${c.contextWindow}${g}%`)}let b=`${c.model}${r}${h}${p}`,f=`${d}${m} ${b}`;return a.truncate&&(i||process.exit(1),f=_t({statusline:f,projectName:d,gitStatus:m,modelString:b,terminalWidth:i,config:a,symbols:c})),f}function vt(n){try{if(n.used_percentage!==void 0&&n.used_percentage!==null)return Math.max(0,Math.min(100,Math.round(n.used_percentage)));let{current_usage:t,context_window_size:r}=n;if(!r||r===0)return null;if(!t)return 0;let e=t.input_tokens+(t.cache_creation_input_tokens||0)+(t.cache_read_input_tokens||0),o=Math.round(e/r*100);return Math.max(0,Math.min(100,o))}catch{return 0}}function _t(n){let{statusline:t,projectName:r,gitStatus:e,modelString:o,terminalWidth:s,config:c}=n,i=Math.max(s-c.rightMargin,30),a=`${r}${e}`;if(y(t)<=i)return t;let d=y(a);if(d+1<=i)if(c.noSoftWrap){let h=i-d-1,p=F(o,h);return`${a} ${p}`}else{let h=i-d-1,p=/^[󰚩*]/,b=y(o);if(p.test(o)&&b>h)return`${a}
5
+ `).filter(e=>e.trim().length>0).length}catch{return 0}}async getAheadBehind(t){try{return await B(t)?await H(t):{ahead:0,behind:0}}catch{}return{ahead:0,behind:0}}formatIndicators(t,r){let e=[],o=["stashed","renamed","modified","staged","untracked","deleted","conflicts"];return t.stashed>0&&e.push(r.stashed),t.renamed>0&&e.push(r.renamed),t.modified>0&&e.push("!"),t.staged>0&&e.push(r.staged),t.untracked>0&&e.push("?"),t.deleted>0&&e.push(r.deleted),t.conflicts>0&&e.push(r.conflict),t.diverged?e.push(r.diverged):(t.ahead>0&&e.push(r.ahead),t.behind>0&&e.push(r.behind)),e.join("")}formatGitStatus(t,r){let e=this.formatIndicators(t.indicators,r),o=(this.config.noEmoji,r.git);return e?` ${o} ${t.branch} [${e}]`:` ${o} ${t.branch}`}};var j=new Map,mt=1,V={git:"@",model:"*",contextWindow:"#",staged:"+",conflict:"C",stashed:"$",ahead:"A",behind:"B",diverged:"D",renamed:">",deleted:"X"},ht={git:"\uF418",model:"\u{F06A9}",contextWindow:"\u26A1\uFE0E",staged:"+",conflict:"\xD7",stashed:"\u2691",ahead:"\u21E1",behind:"\u21E3",diverged:"\u21D5",renamed:"\xBB",deleted:"\u2718"};async function z(n){let t=process.env.NERD_FONT+"|"+process.env.TERM_PROGRAM+"|"+process.env.TERM,r=`${mt}:${n.noEmoji?"ascii":"nerd"}:${t}`,e=j.get(r);if(e&&Date.now()-e.timestamp<6e4)return e.symbols;let o;return n.noEmoji?o={...V,...n.symbols,...n.asciiSymbols}:(await gt()).hasNerdFont?o={...ht,...n.symbols}:o={...V,...n.asciiSymbols},j.set(r,{symbols:o,timestamp:Date.now()}),o}async function gt(){let n={hasNerdFont:!1,terminal:"",font:"",method:""};if(process.env.NERD_FONT==="1")return n.hasNerdFont=!0,n.method="NERD_FONT env var",n;let t=process.env.TERM_PROGRAM,r=process.env.TERM;if(t&&(n.terminal=t,n.method="TERM_PROGRAM detection",["vscode","ghostty","wezterm","iterm"].includes(t))||r&&(n.terminal=r,n.method="TERM detection",["alacritty","kitty","wezterm","ghostty","xterm-256color"].includes(r)))return n.hasNerdFont=!0,n;let e=await pt();if(e.hasNerdFont)return n.hasNerdFont=!0,n.font=e.font,n.method="font list detection",n;let o=await yt();return o.hasNerdFont?(n.hasNerdFont=!0,n.font=o.font,n.method="installation detection",n):bt().hasNerdFont?(n.hasNerdFont=!0,n.method="environment detection",n):((await Et()).hasNerdFont&&(n.hasNerdFont=!0,n.method="platform-specific detection"),n)}async function pt(){try{let{exec:n}=await import("child_process"),{promisify:t}=await import("util"),r=t(n),e="",o=process.platform;if(o==="linux"?e="fc-list":o==="darwin"&&(e="system_profiler SPFontsDataType 2>/dev/null || system_profiler SPFontsDataType"),e){let{stdout:s}=await r(e,{timeout:3e3,encoding:"utf-8"}),c=[/nerd font/i,/symbols only/i,/jetbrains mono.*nerd/i,/fira code.*nerd/i,/hack.*nerd/i,/source code pro.*nerd/i,/ubuntu mono.*nerd/i,/anonymous pro.*nerd/i];for(let i of c)if(i.test(s)){let a=s.match(/([^:\n]*)(?=\s*(nerd|symbols))/i);return{hasNerdFont:!0,font:(a?a[1]:"Nerd Font")?.trim()||"Nerd Font"}}}}catch{}return{hasNerdFont:!1,font:""}}async function yt(){try{let{access:n,readdir:t}=await import("fs/promises"),{homedir:r}=await import("os"),e=process.platform,o=[];e==="darwin"?o.push(`${r()}/Library/Fonts`,"/System/Library/Fonts","/Library/Fonts"):e==="linux"&&o.push(`${r()}/.local/share/fonts`,`${r()}/.fonts`,"/usr/share/fonts","/usr/local/share/fonts");let s=["jetbrains-mono-nerd-font","fira-code-nerd-font","hack-nerd-font","source-code-pro-nerd-font","ubuntu-mono-nerd-font","anonymous-pro-nerd-font"];for(let c of o)try{await n(c);let i=await t(c);for(let a of i){let l=a.toLowerCase();for(let d of s)if(l.includes(d))return{hasNerdFont:!0,font:a}}}catch{}}catch{}return{hasNerdFont:!1,font:""}}function bt(){let n=["POWERLINE_COMMAND","NERDFONTS","FONT_FAMILY"];for(let t of n){let r=process.env[t];if(r&&r.toLowerCase().includes("nerd"))return{hasNerdFont:!0}}return process.env.VSCODE_PID||process.env.TERM_PROGRAM==="vscode"||process.env.TERM_PROGRAM==="ghostty"||process.env.TERM_PROGRAM==="wezterm"?{hasNerdFont:!0}:{hasNerdFont:!1}}async function Et(){if(process.platform==="darwin")try{let{exec:t}=await import("child_process"),{promisify:r}=await import("util"),e=r(t),{stdout:o}=await e("brew list | grep -i font",{timeout:2e3,encoding:"utf-8"});if(o.includes("nerd"))return{hasNerdFont:!0}}catch{}return{hasNerdFont:!1}}function K(n){return{node:"\uE718",python:"\uE235",docker:"\uF308",git:n.git,model:n.model}}async function x(n){if(n.forceWidth&&n.forceWidth>0)return n.forceWidth;let t=process.env.COLUMNS;if(t){let i=parseInt(t,10);if(!isNaN(i)&&i>0)return i}if(process.stdout.columns&&process.stdout.columns>0)return process.stdout.columns;let r=await Y("tput",["cols"]);if(r)return r;let e=await J();if(e)return e;let o=process.env.CLAUDE_CODE_TERMINAL_WIDTH;if(o){let i=parseInt(o,10);if(!isNaN(i)&&i>0)return i}let s=process.env.TERM_PROGRAM,c=process.env.TERM;return s==="vscode"&&process.env.VSCODE_PID||["ghostty","wezterm","iterm"].includes(s||"")||c&&["alacritty","kitty","wezterm","ghostty","xterm-256color"].includes(c)||process.env.WT_SESSION||process.env.WT_PROFILE_ID?120:80}async function Y(n,t){try{let{exec:r}=await import("child_process"),{promisify:e}=await import("util"),o=e(r),{stdout:s}=await o(`${n} ${t.join(" ")}`,{timeout:1e3,encoding:"utf-8"}),c=parseInt(s.trim(),10);if(!isNaN(c)&&c>0)return c}catch{}return null}async function J(){try{let{exec:n}=await import("child_process"),{promisify:t}=await import("util"),r=t(n),{stdout:e}=await r("stty size",{timeout:1e3,encoding:"utf-8"}),o=e.trim().split(" ");if(o.length===2){let s=parseInt(o[1]||"0",10);if(!isNaN(s)&&s>0)return s}}catch{}return null}async function X(n){if(!n.debugWidth)return;process.stdout.columns;let t=process.env.COLUMNS,r=await Y("tput",["cols"]),e=await J(),o=await x(n)}function F(n,t){return n.length<=t?n:t<4?"..":`${n.substring(0,t-2)}..`}function Z(n,t,r,e){if(n.length+t.length<=r)return"";let o=r-t.length-2;if(o>=5)return`${n.substring(0,o)}..${t}`;let s="",c=t.match(/\[([^\]]+)\]/);c&&(s=c[1]||"");let i=r-s.length-8;if(i>=8){let a=t.substring(0,Math.min(t.length,i));return`${n.substring(0,4)}..${a}..${s?` [${s}]`:""}`}return`${n.substring(0,r)}..`}function y(n){let t=0;for(let r of n){let e=r.codePointAt(0)??0;e>=4352&&(e>=4352&&e<=4447||e>=11904&&e<=42191||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65040&&e<=65049||e>=65072&&e<=65135||e>=65280&&e<=65376||e>=65504&&e<=65510||e>=131072&&e<=196605||e>=196608&&e<=262141)||e>=127744&&e<=129535||e>=9728&&e<=10175||e>=65024&&e<=65039||e>=126976&&e<=127023||e>=57344&&e<=63743||e>=983040&&e<=1048573||e>=1048576&&e<=1114109?t+=2:e>=768&&e<=879||e>=7616&&e<=7679||e>=8400&&e<=8447||e>=65056&&e<=65071||(t+=1)}return t}var _=class{config;cache;constructor(t,r){this.config=t,this.cache=r}async getEnvironmentInfo(){if(!this.config.envContext)return null;let t={},[r,e,o]=await Promise.allSettled([this.getNodeVersion(),this.getPythonVersion(),this.getDockerVersion()]);return r.status==="fulfilled"&&r.value&&(t.node=r.value),e.status==="fulfilled"&&e.value&&(t.python=e.value),o.status==="fulfilled"&&o.value&&(t.docker=o.value),Object.keys(t).length===0?null:t}async getNodeVersion(){let t=S.NODE_VERSION,r=this.config.cacheTTL*96,e=await this.cache.get(t,r);if(e)return e;try{let o=await D(this.cache,t,"node",["--version"],r);return o?o.replace(/^v/,"").trim():null}catch{return null}}async getPythonVersion(){let t=S.PYTHON3_VERSION,r=S.PYTHON_VERSION,e=this.config.cacheTTL*96;try{let o=await D(this.cache,t,"python3",["--version"],e);if(o){let s=o.match(/(\d+\.\d+\.\d+)/);if(s)return s[1]||null}}catch{}try{let o=await D(this.cache,r,"python",["--version"],e);if(o){let s=o.match(/(\d+\.\d+\.\d+)/);if(s)return s[1]||null}}catch{}return null}async getDockerVersion(){let t="docker_version";try{let r=await D(this.cache,t,"docker",["--version"],this.config.cacheTTL*96);if(r){let e=r.match(/Docker version (\d+\.\d+\.\d+)/);if(e)return e[1]||null}return null}catch{return null}}formatEnvironmentInfo(t,r){let e=[];return t.node&&e.push(`${r.node}${t.node}`),t.python&&e.push(`${r.python}${t.python}`),t.docker&&e.push(`${r.docker}${t.docker}`),e.join(" ")}async getAdditionalTools(){return{}}async isToolAvailable(t){try{let{exec:r}=await import("child_process"),{promisify:e}=await import("util");return await e(r)(`command -v ${t}`,{timeout:2e3}),!0}catch{return!1}}getShellEnvironment(){let t=process.env.SHELL||"unknown",r;return t.includes("bash")?r=process.env.BASH_VERSION:t.includes("zsh")?r=process.env.ZSH_VERSION:t.includes("fish")&&(r=process.env.FISH_VERSION),r?{shell:t,shellVersion:r}:{shell:t}}getOSInfo(){let t=process.platform,r=process.arch,e=process.env.OSTYPE||process.env.OS;return e?{platform:t,arch:r,release:e}:{platform:t,arch:r}}},N=class{symbols;constructor(t){this.symbols=t}format(t,r="compact"){switch(r){case"compact":return this.formatCompact(t);case"verbose":return this.formatVerbose(t);case"minimal":return this.formatMinimal(t);default:return this.formatCompact(t)}}formatCompact(t){let r=[];return t.node&&r.push(`Node${t.node}`),t.python&&r.push(`Py${t.python}`),t.docker&&r.push(`Docker${t.docker}`),r.join(" ")}formatVerbose(t){let r=[];return t.node&&r.push(`Node.js v${t.node}`),t.python&&r.push(`Python ${t.python}`),t.docker&&r.push(`Docker ${t.docker}`),r.join(" \u2022 ")}formatMinimal(t){let r=[];if(t.node){let e=t.node.split(".")[0];r.push(`N${e}`)}if(t.python){let e=t.python.split(".")[0];r.push(`P${e}`)}if(t.docker){let e=t.docker.split(".")[0];r.push(`D${e}`)}return r.join(" ")}formatWithIcons(t){let r=[];return t.node&&r.push(`${this.symbols.node}${t.node}`),t.python&&r.push(`${this.symbols.python}${t.python}`),t.docker&&r.push(`${this.symbols.docker}${t.docker}`),r.join(" ")}};async function Ct(){try{let n=W(),t=new T(n),r=new v(n,t),e=new _(n,t);await X(n);let o=await Dt();O(JSON.stringify(o),n)||process.exit(1);let{fullDir:s,modelName:c,contextWindow:i}=wt(o);(!s||!c)&&process.exit(1),await R(s)||process.exit(1);let l=[r.getGitInfo(s),e.getEnvironmentInfo(),z(n)],d;n.truncate&&l.push(x(n));let m=await Promise.all(l),[h,p,b]=m;n.truncate&&m.length>3&&(d=m[3]);let f=await Tt({fullDir:s,modelName:c,contextWindow:i,gitInfo:h,envInfo:p,symbols:b,...d&&{terminalWidth:d},config:n,gitOps:r});process.stdout.write(f)}catch{process.exit(1)}}async function Dt(){try{let n=St(0,"utf-8");return JSON.parse(n.trim())}catch(n){throw new Error(`Failed to read or parse input: ${n instanceof Error?n.message:String(n)}`)}}function wt(n){let t=n.workspace?.current_dir||"",r=n.model?.display_name||"Unknown",e=n.context_window;return{fullDir:t,modelName:r,contextWindow:e}}async function Tt(n){let{fullDir:t,modelName:r,contextWindow:e,gitInfo:o,envInfo:s,symbols:c,terminalWidth:i,config:a,gitOps:l}=n,d=t.split("/").pop()||t.split("\\").pop()||"project",m="";o&&(m=l.formatGitStatus(o,c));let h="";if(s){let g=K(c);h=` ${new N(g).formatWithIcons(s)}`}let p="";if(e&&!a.noContextWindow){let g=vt(e);g!==null&&(p=` ${c.contextWindow}${g}%`)}let b=`${c.model}${r}${h}${p}`,f=`${d}${m} ${b}`;return a.truncate&&(i||process.exit(1),f=_t({statusline:f,projectName:d,gitStatus:m,modelString:b,terminalWidth:i,config:a,symbols:c})),f}function vt(n){try{let{total_input_tokens:t,context_window_size:r,used_percentage:e,current_usage:o}=n;if(!r||r===0)return null;if(e!=null&&e>0)return Math.max(0,Math.min(100,Math.round(e)));if(t&&t>0){let s=Math.round(t/r*100);return Math.max(0,Math.min(100,s))}if(o){let s=o.input_tokens+(o.cache_creation_input_tokens||0)+(o.cache_read_input_tokens||0);if(s>0){let c=Math.round(s/r*100);return Math.max(0,Math.min(100,c))}}return 0}catch{return 0}}function _t(n){let{statusline:t,projectName:r,gitStatus:e,modelString:o,terminalWidth:s,config:c}=n,i=Math.max(s-c.rightMargin,30),a=`${r}${e}`;if(y(t)<=i)return t;let d=y(a);if(d+1<=i)if(c.noSoftWrap){let h=i-d-1,p=F(o,h);return`${a} ${p}`}else{let h=i-d-1,p=/^[󰚩*]/,b=y(o);if(p.test(o)&&b>h)return`${a}
6
6
  ${o}`;let f=Nt(o,h);return`${a} ${f}`}let m=Z(r,e,i,c);return m||F(t,i)}function Nt(n,t){if(y(n)<=t)return n;if(/^[󰚩*]/.test(n))return xt(n,t);let o=!1,s=Array.from(n),c=0,i=s.length,a=-1;for(let f=0;f<s.length;f++){let g=s[f];if(!g)break;g===" "&&(a=f);let C=y(g);if(c+=C,c>t){a>=0?i=a:i=f,o=a>=0;break}}if(i>=s.length)return n;let l=s.length>0?s[0]:"",d=l&&l!==" "&&Buffer.byteLength(l,"utf8")>1;if(!o&&t-c>-3&&!d)return n;if(d&&i<=2&&t>=3){let f=0;for(let g=0;g<s.length;g++){let C=s[g];if(!C)break;if(f+=y(C),f>=3||f>=t){i=g,o=!0;break}}}let m=s.slice(0,i),h=s.slice(i);h.length>0&&h[0]===" "&&h.shift();let p=m.join(""),b=h.join("");return b?`${p}
7
7
  ${b}`:p}function xt(n,t){if(y(n)<=t)return n;let e=Array.from(n),o=[];for(let a=0;a<e.length;a++)e[a]===" "&&o.push(a);let s=-1;for(let a=0;a<e.length;a++){let l=e[a];if(l==="\u26A1"||l==="#"){s=a;break}}if(s>0){let a=e.findIndex((l,d)=>d<s&&l===" ");if(a>0){let l=e.slice(a+1).join("");if(y(l)<=t)return`${e.slice(0,a).join("")}
8
8
  ${l}`}}if(o.length>0){let a=o[0];if(a!==void 0&&a>1){let l=e.slice(0,a).join("");if(y(l)<=t){let m=e.slice(a+1).join("");return m?`${l}