@neilurk12/pi-clean-footer 0.3.0 → 0.3.1

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.
Files changed (2) hide show
  1. package/dist/index.js +7 -7
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import _ from"path";import ge from"os";import te from"path";import{existsSync as V,readFileSync as X}from"fs";var j=["model","directory","git","context","tokensFull","tokensNoCache","tokensTotal","toks"],N=["default","minimal","compact","dense","focus","muted"],p=[{minWidth:100,left:["model","directory","git","toks"],right:["context","tokensFull"]},{minWidth:80,left:["model","directory","git"],right:["context","tokensNoCache"]},{minWidth:60,left:["model","directory","git"],right:["context","tokensTotal"]},{minWidth:40,left:["model","directory","git"],right:["context"]},{minWidth:0,left:["model"],right:["context"]}],A=[{minWidth:0,left:["model"],right:["context"]}],U=[{minWidth:80,left:["model","git"],right:["context","tokensTotal"]},{minWidth:0,left:["model"],right:["context"]}],G=[{minWidth:100,left:["model","directory","git","toks"],right:["context","tokensFull"]},{minWidth:60,left:["model","git"],right:["context","tokensNoCache"]},{minWidth:0,left:["model"],right:["context"]}],B=[{minWidth:0,left:["model"],right:["context"]}],O={default:{},minimal:{separator:" \xB7 ",showDirectory:!1,showGit:!1,showTokens:!1,layouts:A},compact:{separator:" \xB7 ",showDirectory:!1,showCacheRead:!1,showCacheWrites:!1,layouts:U},dense:{showCacheRead:!0,showCacheWrites:!0,layouts:G},focus:{showDirectory:!1,showGit:!1,showTokens:!1,layouts:B},muted:{colors:{model:"muted",directory:"dim",git:"muted",gitDirty:"warning",contextNormal:"muted",contextWarning:"warning",contextDanger:"error",tokens:"dim",separator:"dim"}}},f={preset:"default",enabled:!0,showGit:!0,showTokens:!0,showCache:!0,showCacheRead:!0,showCacheWrites:!1,showContext:!0,showDirectory:!0,showEffort:!0,showToks:!0,separator:" | ",layouts:p,gitRefreshDebounceMs:500,contextWarningPercent:70,contextDangerPercent:85,modelAliases:{},colors:{model:"accent",directory:"dim",git:"success",gitDirty:"warning",contextNormal:"success",contextWarning:"warning",contextDanger:"error",tokens:"muted",separator:"dim"}};function b(e,t){return{...e,...t,modelAliases:{...e.modelAliases??{},...t.modelAliases??{}},colors:{...e.colors??{},...t.colors??{}}}}function T(e){let t=[],o=z(e.preset,t),r=O[o],n=b(r,e),s=H(n.layouts);return{config:{...f,...n,preset:o,separator:typeof n.separator=="string"?n.separator:f.separator,layouts:s.layouts,gitRefreshDebounceMs:Q(n.gitRefreshDebounceMs,f.gitRefreshDebounceMs),contextWarningPercent:k(n.contextWarningPercent,f.contextWarningPercent),contextDangerPercent:k(n.contextDangerPercent,f.contextDangerPercent),modelAliases:{...f.modelAliases,...r.modelAliases??{},...e.modelAliases??{}},colors:{...f.colors,...r.colors??{},...e.colors??{}}},loadedPaths:[],warnings:[...t,...s.warnings]}}function z(e,t){return e===void 0||e==="default"?"default":typeof e!="string"?(t.push("preset must be a string; using default preset"),"default"):N.includes(e)?e:(t.push(`unknown preset '${e}'; using default preset`),"default")}function H(e){let t=[];if(e===void 0)return{layouts:p,warnings:t};if(!Array.isArray(e))return{layouts:p,warnings:["layouts must be an array; using default layouts"]};let o=e.flatMap((r,n)=>{if(!J(r))return t.push(`layouts[${n}] must be an object; skipping`),[];let s=K(r.minWidth);if(s===void 0)return t.push(`layouts[${n}].minWidth must be a non-negative number; skipping`),[];let d=x(r.left,`layouts[${n}].left`,t),u=x(r.right,`layouts[${n}].right`,t,new Set(d));return d.length===0&&u.length===0?(t.push(`layouts[${n}] has no visible segments; skipping`),[]):[{minWidth:s,left:d,right:u}]});return o.length===0?(t.push("no valid layouts configured; using default layouts"),{layouts:p,warnings:t}):{layouts:[...o].sort((r,n)=>n.minWidth-r.minWidth),warnings:t}}function x(e,t,o,r=new Set){if(!Array.isArray(e))return o.push(`${t} must be an array; using empty segment list`),[];let n=[];for(let s of e){if(!q(s)){o.push(`${t} contains unknown segment '${String(s)}'; omitting`);continue}if(r.has(s)){o.push(`${t} contains duplicate segment '${s}'; omitting`);continue}r.add(s),n.push(s)}return n}function q(e){return typeof e=="string"&&j.includes(e)}function J(e){return typeof e=="object"&&e!==null}function K(e){return typeof e=="number"&&Number.isFinite(e)&&e>=0?e:void 0}function Q(e,t){return typeof e=="number"&&Number.isFinite(e)&&e>0?e:t}function k(e,t){return typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=100?e:t}function F(e,t){return Y([e,t])}function Y(e){let t=[],o={},r;for(let s of e)if(V(s))try{let d=JSON.parse(X(s,"utf8"));o=b(o,d),t.push(s)}catch(d){r=`${s}: ${d instanceof Error?d.message:String(d)}`}let n=T(o);return{config:n.config,loadedPaths:t,warnings:n.warnings,error:r}}import{execFile as Z}from"child_process";import{promisify as ee}from"util";var R=ee(Z);function S(e){let t={inRepo:!1,dirtyCount:0},o,r=[];e.onChange&&r.push(e.onChange);async function n(){if(!e.enabled){t={inRepo:!1,dirtyCount:0};return}try{let[u,i]=await Promise.all([R("git",["branch","--show-current"],{cwd:e.cwd,timeout:2e3}),R("git",["status","--porcelain"],{cwd:e.cwd,timeout:2e3})]),a=u.stdout.trim()||"detached",g=i.stdout.split(`
2
- `).filter(Boolean).length;t={inRepo:!0,branch:a,dirtyCount:g}}catch{t={inRepo:!1,dirtyCount:0}}for(let u of r)u()}function s(){d(),o=setTimeout(()=>{o=void 0,n()},e.debounceMs)}function d(){o&&(clearTimeout(o),o=void 0)}return{get state(){return t},schedule:s,clear:d,refresh:n,onChange(u){return r.push(u),()=>{let i=r.indexOf(u);i>=0&&r.splice(i,1)}}}}function P(e){var o,r,n,s,d;let t={input:0,output:0,cacheRead:0,cacheWrite:0};for(let u of e){if(u.type!=="message"||((o=u.message)==null?void 0:o.role)!=="assistant")continue;let i=u.message;t.input+=((r=i.usage)==null?void 0:r.input)??0,t.output+=((n=i.usage)==null?void 0:n.output)??0,t.cacheRead+=((s=i.usage)==null?void 0:s.cacheRead)??0,t.cacheWrite+=((d=i.usage)==null?void 0:d.cacheWrite)??0}return t}function y(e){if(typeof e!="string")return;let t=e.toLowerCase();if(t==="medium")return"med";if(t==="extra-high"||t==="extra_high"||t==="x-high")return"xhigh";if(["low","med","high","xhigh"].includes(t))return t}function c(e){return!Number.isFinite(e)||e<=0?"0":e<1e3?`${Math.round(e)}`:e<1e6?`${(e/1e3).toFixed(e<1e4?1:0)}k`:`${(e/1e6).toFixed(1)}m`}var C=class{#t;#n;#d;#e;#o;#c;#g;#f;#l;#r;#s={input:0,output:0,cacheRead:0,cacheWrite:0};#a=0;#i=void 0;#u=void 0;constructor(t){this.#g=t.globalConfigPath,this.#f=t.getProjectConfigPath,this.#l=t.getThinkingLevel,this.#r=t.onRenderNeeded,this.#t=f,this.#n={config:this.#t,loadedPaths:[],warnings:[]},this.#d=void 0,this.#e=void 0,this.#o=!0,this.#c=""}async start(t){this.#s={input:0,output:0,cacheRead:0,cacheWrite:0},this.#a=0,this.#c=t.cwd,this.#n=F(this.#g,this.#f(t.cwd)),this.#t=this.#n.config,this.#d=y(this.#l()),this.#o=this.#t.enabled,this.#o&&(this.#h(t.cwd),await this.#e.refresh())}shutdown(){var t;(t=this.#e)==null||t.clear(),this.#e=void 0,this.#s={input:0,output:0,cacheRead:0,cacheWrite:0},this.#a=0,this.#i=void 0,this.#u=void 0}#h(t){this.#e=S({cwd:t,debounceMs:this.#t.gitRefreshDebounceMs,enabled:this.#t.showGit,onChange:()=>this.#r()})}onThinkingLevel(t){this.#d=y(t),this.#r()}onModelSelect(){this.#r()}onMessageStart(t){t==="assistant"&&(this.#i=Date.now())}onMessageEnd(t,o){if(t==="assistant"){if(this.#i!==void 0&&o&&o>0){let r=Date.now()-this.#i;r>0&&(this.#u=o/(r/1e3))}this.#i=void 0,this.#r()}}onToolEnd(t){var o;["bash","edit","write"].includes(t)&&((o=this.#e)==null||o.schedule()),this.#r()}onUserBash(){var t;(t=this.#e)==null||t.schedule()}async refresh(){var t;await((t=this.#e)==null?void 0:t.refresh())}async reload(t){var o;this.#s={input:0,output:0,cacheRead:0,cacheWrite:0},this.#a=0,this.#i=void 0,this.#u=void 0,this.#n=F(this.#g,this.#f(t.cwd)),this.#t=this.#n.config,this.#o=this.#t.enabled,(o=this.#e)==null||o.clear(),this.#e=void 0,this.#o&&(this.#h(this.#c),await this.#e.refresh()),this.#r()}async toggle(){var t;return this.#s={input:0,output:0,cacheRead:0,cacheWrite:0},this.#a=0,this.#i=void 0,this.#u=void 0,this.#o=!this.#o,this.#o?(this.#d=y(this.#l()),this.#h(this.#c),await this.#e.refresh()):((t=this.#e)==null||t.clear(),this.#e=void 0),this.#r(),this.#o}getFooterInput(t){var r,n,s,d,u,i;let o=t.sessionManager.getBranch();return o.length!==this.#a&&(this.#s=P(o),this.#a=o.length),{modelId:((r=t.model)==null?void 0:r.id)??"no-model",thinkingLevel:this.#d,directory:te.basename(t.cwd),gitBranch:(n=this.#e)==null?void 0:n.state.branch,gitDirtyCount:((s=this.#e)==null?void 0:s.state.dirtyCount)??0,contextUsed:((u=(d=t.getContextUsage)==null?void 0:d.call(t))==null?void 0:u.tokens)??0,contextMax:(i=t.model)==null?void 0:i.contextWindow,totals:this.#s,lastTokPerSec:this.#u,config:this.#t}}get isEnabled(){return this.#o}get loadedError(){return this.#n.error}get loadedWarnings(){return this.#n.warnings}get loadedPaths(){return this.#n.loadedPaths}get config(){return this.#t}};import{truncateToWidth as h,visibleWidth as W}from"@earendil-works/pi-tui";function L(e,t,o,r){let n=e.filter(Boolean).join(o),s=t.filter(Boolean).join(o);return oe(n,s,r)}function oe(e,t,o){if(!t)return h(e,o);if(!e)return h(t,o);let r=o-W(e)-W(t);if(r>=1)return h(e+" ".repeat(r)+t,o);let n=Math.max(1,Math.floor((o-1)/2));return h(e,n)+" "+h(t,o-n-1)}function v(e,t){if(t[e])return t[e];let o=e.toLowerCase(),r=o.includes("/")?o.split("/").pop():o;if(t[r])return t[r];if(r.includes("claude")&&r.includes("sonnet"))return r.includes("4-5")||r.includes("4.5")?"sonnet-4.5":r.includes("4")?"sonnet-4":"sonnet";if(r.includes("claude")&&r.includes("opus"))return"opus";if(r.includes("claude")&&r.includes("haiku"))return"haiku";let n=r.match(/gpt-5(?:[.-][a-z0-9]+)*/);if(n)return n[0];let s=r.match(/gpt-4(?:[.-][a-z0-9]+)*/);if(s)return s[0];let d=r.match(/gemini-[a-z0-9.-]+/);return d?d[0].replace(/-preview.*/,""):r.length>24?`${r.slice(0,21)}\u2026`:r}function I(e,t){let o=e.input+e.output,r=`\u2191${c(e.input)} \u2193${c(e.output)} \u03A3${c(o)}`,n=[t.showCacheRead?`\u21AF${c(e.cacheRead)}`:void 0,t.showCacheWrites?`\u21A5${c(e.cacheWrite)}`:void 0].filter(Boolean),s=n.length?`${r} ${n.join(" ")}`:r;return t.cf(t.color,s)}function $(e,t,o){let r=e.input+e.output,n=`\u2191${c(e.input)} \u2193${c(e.output)} \u03A3${c(r)}`;return t(o,n)}function M(e,t,o){let r=e.input+e.output;return t(o,`\u03A3${c(r)}`)}function D(e,t,o){let r=(d,u)=>t.fg(d,u),n=ne(e,r),s=r(e.config.colors.separator,e.config.separator);return[ue(n,s,e.config.layouts,o)]}function ne(e,t){let o=e.config,r=o.showCache&&o.showCacheRead,n=o.showCache&&o.showCacheWrites;return{model:re(e,t),directory:o.showDirectory?ie(e,t):void 0,git:o.showGit?se(e,t):void 0,context:o.showContext?ae(e,t):void 0,tokensFull:o.showTokens?I(e.totals,{showCacheRead:r,showCacheWrites:n,cf:t,color:o.colors.tokens}):void 0,tokensNoCache:o.showTokens?$(e.totals,t,o.colors.tokens):void 0,tokensTotal:o.showTokens?M(e.totals,t,o.colors.tokens):void 0,toks:o.showToks?de(e,t):void 0}}function re(e,t){let o=v(e.modelId,e.config.modelAliases),r=e.config.showEffort&&e.thinkingLevel?` \u2022 ${e.thinkingLevel}`:"";return t(e.config.colors.model,`${o}${r}`)}function ie(e,t){if(e.directory)return t(e.config.colors.directory,e.directory)}function se(e,t){if(!e.gitBranch)return;let o=t(e.config.colors.git,e.gitBranch);return e.gitDirtyCount<=0?o:`${o} ${t(e.config.colors.gitDirty,`\u25CF${e.gitDirtyCount}`)}`}function ae(e,t){let o=`ctx ${c(e.contextUsed)}/${e.contextMax?c(e.contextMax):"--"}`;if(!e.contextMax||e.contextMax<=0)return t("dim",o);let r=e.contextUsed/e.contextMax*100;return r>=e.config.contextDangerPercent?t(e.config.colors.contextDanger,o):r>=e.config.contextWarningPercent?t(e.config.colors.contextWarning,o):t(e.config.colors.contextNormal,o)}function de(e,t){if(!(e.lastTokPerSec===void 0||e.lastTokPerSec<=0))return t(e.config.colors.tokens,`${Math.round(e.lastTokPerSec)} tok/s`)}function ue(e,t,o,r){let n=ce(o,r),s=E(n.left,e),d=E(n.right,e);return L(s,d,t,r)}function ce(e,t){return e.find(o=>t>=o.minWidth)??e[e.length-1]}function E(e,t){return e.map(o=>t[o]).filter(o=>!!o)}function Be(e){let t=_.join(ge.homedir(),".pi","agent","clean-footer.json"),o=i=>_.join(i,".pi","clean-footer.json"),r=()=>{},n=new C({globalConfigPath:t,getProjectConfigPath:o,getThinkingLevel:()=>{var i;return(i=e.getThinkingLevel)==null?void 0:i.call(e)},onRenderNeeded:()=>r()});e.registerCommand("footer",{description:"Toggle, refresh, or configure the clean footer",handler:async(i,a)=>{let g=i.trim();if(g==="refresh"){await n.refresh(),a.hasUI&&a.ui.notify("Footer refreshed","info");return}if(g==="reload"){await n.reload(a),a.hasUI&&n.isEnabled&&s(a),a.hasUI&&!n.isEnabled&&a.ui.setFooter(void 0),r(),d(a);return}if(g==="config"){u(a);return}let l=await n.toggle();a.hasUI&&(l?(s(a),a.ui.notify("Clean footer enabled","info")):(a.ui.setFooter(void 0),a.ui.notify("Default footer restored","info")))}}),e.on("session_start",async(i,a)=>{await n.start(a),a.hasUI&&n.loadedError&&n.isEnabled&&a.ui.notify(`Config error: ${n.loadedError}`,"error"),a.hasUI&&n.isEnabled&&s(a)}),e.on("session_shutdown",(i,a)=>{n.shutdown(),r=()=>{},a.hasUI&&a.ui.setFooter(void 0)}),e.on("thinking_level_select",i=>{n.onThinkingLevel(i.level)}),e.on("model_select",()=>{n.onModelSelect()}),e.on("message_start",i=>{n.onMessageStart(i.message.role)}),e.on("message_end",i=>{var l;let a=i.message,g;if(a.role==="assistant"){let m=a,w=m.usage??((l=m.message)==null?void 0:l.usage);g=w==null?void 0:w.output}n.onMessageEnd(a.role,g)}),e.on("tool_execution_end",i=>{n.onToolEnd(i.toolName)}),e.on("user_bash",()=>{n.onUserBash()});function s(i){i.hasUI&&i.ui.setFooter((a,g)=>(r=()=>a.requestRender(),{invalidate(){},render(l){let m=n.getFooterInput(i);return D(m,g,l)}}))}function d(i){i.hasUI&&(n.loadedError?i.ui.notify(`Clean footer config error: ${n.loadedError}`,"error"):n.loadedWarnings.length>0?i.ui.notify(`Clean footer config loaded with warnings: ${n.loadedWarnings.join("; ")}`,"warning"):i.ui.notify("Clean footer config loaded","info"))}function u(i){if(!i.hasUI)return;let a=n.loadedPaths.length?n.loadedPaths.join(`
3
- `):"none",g=n.loadedWarnings.length?n.loadedWarnings.join(`
4
- `):"none",l=o(i.cwd);i.ui.notify(["Clean footer config",`global: ${t}`,`project: ${l}`,`loaded:
5
- ${a}`,n.loadedError?`error: ${n.loadedError}`:"error: none",`warnings:
6
- ${g}`,`preset: ${n.config.preset}`,`resolved: ${JSON.stringify(n.config)}`].join(`
7
- `),"info")}}export{Be as default};
1
+ import N from"path";import Se from"os";import se from"path";import{existsSync as Z,readFileSync as ee}from"fs";var j=["model","directory","git","context","tokensFull","tokensNoCache","tokensTotal","toks"],U=["default","minimal","compact","dense","focus","muted"],m=[{minWidth:100,left:["model","directory","git","toks"],right:["context","tokensFull"]},{minWidth:80,left:["model","directory","git","toks"],right:["context","tokensNoCache"]},{minWidth:60,left:["model","directory","git","toks"],right:["context","tokensTotal"]},{minWidth:40,left:["model","directory","git"],right:["context"]},{minWidth:0,left:["model"],right:["context"]}],G=[{minWidth:0,left:["model"],right:["context"]}],B=[{minWidth:80,left:["model","git"],right:["context","tokensTotal"]},{minWidth:0,left:["model"],right:["context"]}],H=[{minWidth:100,left:["model","directory","git","toks"],right:["context","tokensFull"]},{minWidth:60,left:["model","git"],right:["context","tokensNoCache"]},{minWidth:0,left:["model"],right:["context"]}],z=[{minWidth:0,left:["model"],right:["context"]}],K={default:{},minimal:{separator:" \xB7 ",showDirectory:!1,showGit:!1,showTokens:!1,layouts:G},compact:{separator:" \xB7 ",showDirectory:!1,showCacheRead:!1,showCacheWrites:!1,layouts:B},dense:{showCacheRead:!0,showCacheWrites:!0,layouts:H},focus:{showDirectory:!1,showGit:!1,showTokens:!1,layouts:z},muted:{colors:{model:"muted",directory:"dim",git:"muted",gitDirty:"warning",contextNormal:"muted",contextWarning:"warning",contextDanger:"error",tokens:"dim",separator:"dim"}}},l={preset:"default",enabled:!0,showGit:!0,showTokens:!0,showCache:!0,showCacheRead:!0,showCacheWrites:!1,showContext:!0,showDirectory:!0,showEffort:!0,separator:" | ",layouts:m,gitRefreshDebounceMs:500,contextWarningPercent:70,contextDangerPercent:85,modelAliases:{},colors:{model:"accent",directory:"dim",git:"success",gitDirty:"warning",contextNormal:"success",contextWarning:"warning",contextDanger:"error",tokens:"muted",separator:"dim"}};function C(e,t){return{...e,...t,modelAliases:{...e.modelAliases??{},...t.modelAliases??{}},colors:{...e.colors??{},...t.colors??{}}}}function F(e){let t=[],n=J(e.preset,t),o=K[n],r=C(o,e),s=q(r.layouts);return{config:{...l,...r,preset:n,separator:typeof r.separator=="string"?r.separator:l.separator,layouts:s.layouts,gitRefreshDebounceMs:Q(r.gitRefreshDebounceMs,l.gitRefreshDebounceMs),contextWarningPercent:T(r.contextWarningPercent,l.contextWarningPercent),contextDangerPercent:T(r.contextDangerPercent,l.contextDangerPercent),modelAliases:{...l.modelAliases,...o.modelAliases??{},...e.modelAliases??{}},colors:{...l.colors,...o.colors??{},...e.colors??{}}},loadedPaths:[],warnings:[...t,...s.warnings]}}function J(e,t){return e===void 0||e==="default"?"default":typeof e!="string"?(t.push("preset must be a string; using default preset"),"default"):U.includes(e)?e:(t.push(`unknown preset '${e}'; using default preset`),"default")}function q(e){let t=[];if(e===void 0)return{layouts:m,warnings:t};if(!Array.isArray(e))return{layouts:m,warnings:["layouts must be an array; using default layouts"]};let n=e.flatMap((o,r)=>{if(!X(o))return t.push(`layouts[${r}] must be an object; skipping`),[];let s=Y(o.minWidth);if(s===void 0)return t.push(`layouts[${r}].minWidth must be a non-negative number; skipping`),[];let d=w(o.left,`layouts[${r}].left`,t),u=w(o.right,`layouts[${r}].right`,t,new Set(d));return d.length===0&&u.length===0?(t.push(`layouts[${r}] has no visible segments; skipping`),[]):[{minWidth:s,left:d,right:u}]});return n.length===0?(t.push("no valid layouts configured; using default layouts"),{layouts:m,warnings:t}):{layouts:[...n].sort((o,r)=>r.minWidth-o.minWidth),warnings:t}}function w(e,t,n,o=new Set){if(!Array.isArray(e))return n.push(`${t} must be an array; using empty segment list`),[];let r=[];for(let s of e){if(!V(s)){n.push(`${t} contains unknown segment '${String(s)}'; omitting`);continue}if(o.has(s)){n.push(`${t} contains duplicate segment '${s}'; omitting`);continue}o.add(s),r.push(s)}return r}function V(e){return typeof e=="string"&&j.includes(e)}function X(e){return typeof e=="object"&&e!==null}function Y(e){return typeof e=="number"&&Number.isFinite(e)&&e>=0?e:void 0}function Q(e,t){return typeof e=="number"&&Number.isFinite(e)&&e>0?e:t}function T(e,t){return typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=100?e:t}function x(e,t){return te([e,t])}function te(e){let t=[],n={},o;for(let s of e)if(Z(s))try{let d=JSON.parse(ee(s,"utf8"));n=C(n,d),t.push(s)}catch(d){o=`${s}: ${d instanceof Error?d.message:String(d)}`}let r=F(n);return{config:r.config,loadedPaths:t,warnings:r.warnings,error:o}}import{execFile as oe}from"child_process";import{promisify as ne}from"util";var k=ne(oe);function S(e){let t={inRepo:!1,dirtyCount:0},n,o=[];e.onChange&&o.push(e.onChange);async function r(){if(!e.enabled){t={inRepo:!1,dirtyCount:0};return}try{let[u,i]=await Promise.all([k("git",["branch","--show-current"],{cwd:e.cwd,timeout:2e3}),k("git",["status","--porcelain"],{cwd:e.cwd,timeout:2e3})]),a=u.stdout.trim()||"detached",f=i.stdout.split(`
2
+ `).filter(Boolean).length;t={inRepo:!0,branch:a,dirtyCount:f}}catch{t={inRepo:!1,dirtyCount:0}}for(let u of o)u()}function s(){d(),n=setTimeout(()=>{n=void 0,r()},e.debounceMs)}function d(){n&&(clearTimeout(n),n=void 0)}return{get state(){return t},schedule:s,clear:d,refresh:r,onChange(u){return o.push(u),()=>{let i=o.indexOf(u);i>=0&&o.splice(i,1)}}}}function v(e){var n,o,r,s,d;let t={input:0,output:0,cacheRead:0,cacheWrite:0};for(let u of e){if(u.type!=="message"||((n=u.message)==null?void 0:n.role)!=="assistant")continue;let i=u.message;t.input+=((o=i.usage)==null?void 0:o.input)??0,t.output+=((r=i.usage)==null?void 0:r.output)??0,t.cacheRead+=((s=i.usage)==null?void 0:s.cacheRead)??0,t.cacheWrite+=((d=i.usage)==null?void 0:d.cacheWrite)??0}return t}function p(e){if(typeof e!="string")return;let t=e.toLowerCase();if(t==="medium")return"med";if(t==="extra-high"||t==="extra_high"||t==="x-high")return"xhigh";if(["low","med","high","xhigh"].includes(t))return t}function c(e){return!Number.isFinite(e)||e<=0?"0":e<1e3?`${Math.round(e)}`:e<1e6?`${(e/1e3).toFixed(e<1e4?1:0)}k`:`${(e/1e6).toFixed(1)}m`}var re={edit:"edit",write:"write",bash:"bash",ctx_shell:"bash",read:"read",ctx_read:"read",Agent:"agent",agent_browser:"browser"},ie=[["gitnexus_","nexus"],["context7_","docs"]],R=8;function _(e){if(!e)return"";let t=re[e];if(t)return t;for(let[n,o]of ie)if(e.startsWith(n))return o;return e.length>R?e.slice(0,R):e}var ae=.25,de=.67,ue=.5,fe=1,ce=.5,le=300,ge=5e3,he=[". ",".. ","..."];function me(e){let t=0;for(let n of e){let o=n.codePointAt(0)??0;o>=32&&o<=126?t+=ae:o>=19968&&o<=40959||o>=13312&&o<=19903||o>=63744&&o<=64255||o>=12352&&o<=12447||o>=12448&&o<=12543||o>=44032&&o<=55215||o>=11904&&o<=12255||o>=12544&&o<=12590||o>=12784&&o<=12799||o>=65281&&o<=65374||o>=65381&&o<=65439?t+=de:o>=12288&&o<=12351?t+=ue:o>65535?t+=fe:t+=ce}return Math.ceil(t)}var y=class{#n;#i;#a;#t;#r;#u;#m;#p;#y;#o;#f={input:0,output:0,cacheRead:0,cacheWrite:0};#c=0;#e=void 0;#s=0;#C="";#l=0;#g=void 0;#d=void 0;constructor(t){this.#m=t.globalConfigPath,this.#p=t.getProjectConfigPath,this.#y=t.getThinkingLevel,this.#o=t.onRenderNeeded,this.#n=l,this.#i={config:this.#n,loadedPaths:[],warnings:[]},this.#a=void 0,this.#t=void 0,this.#r=!0,this.#u=""}async start(t){this.#f={input:0,output:0,cacheRead:0,cacheWrite:0},this.#c=0,this.#u=t.cwd,this.#i=x(this.#m,this.#p(t.cwd)),this.#n=this.#i.config,this.#a=p(this.#y()),this.#r=this.#n.enabled,this.#r&&(this.#x(t.cwd),await this.#t.refresh())}shutdown(){var t;(t=this.#t)==null||t.clear(),this.#t=void 0,this.#b()}#x(t){this.#t=S({cwd:t,debounceMs:this.#n.gitRefreshDebounceMs,enabled:this.#n.showGit,onChange:()=>this.#o()})}onThinkingLevel(t){this.#a=p(t),this.#o()}onModelSelect(){this.#o()}onMessageStart(t){t==="assistant"&&(this.#w(),this.#e={startTime:Date.now(),estimatedTokens:0,hasObservedOutput:!1,displayState:{state:"pending"}},this.#o())}onToolExecutionStart(t){this.#s++,this.#C=_(t)+"...",this.#l=0,this.#F(),this.#o()}onToolExecutionUpdate(t){}onToolExecutionEnd(t){var n;this.#s=Math.max(0,this.#s-1),this.#s===0&&this.#h(),["bash","edit","write"].includes(t)&&((n=this.#t)==null||n.schedule()),this.#o()}onMessageUpdate(t,n,o){if(!this.#e||!n||t!=="text_delta"&&t!=="thinking_delta"&&t!=="toolcall_delta")return;this.#e.estimatedTokens+=me(n),this.#e.hasObservedOutput=!0;let r=(Date.now()-this.#e.startTime)/1e3;if(r>0){let s=o&&o>0?o:this.#e.estimatedTokens;this.#e.displayState={state:"rate",value:s/r,approximate:!(o&&o>0)}}this.#o()}onMessageEnd(t,n){if(t==="assistant"){if(this.#s=0,this.#h(),this.#e){let o=(Date.now()-this.#e.startTime)/1e3;n&&n>0&&o>0?(this.#e.displayState={state:"rate",value:n/o,approximate:!1},this.#T()):this.#e.hasObservedOutput&&o>0?(this.#e.displayState={state:"rate",value:this.#e.estimatedTokens/o,approximate:!0},this.#T()):this.#e=void 0}this.#o()}}onMessageAbort(){if(this.#e)if(this.#e.hasObservedOutput){let t=(Date.now()-this.#e.startTime)/1e3;t>0&&(this.#e.displayState={state:"rate",value:this.#e.estimatedTokens/t,approximate:!0})}else this.#e=void 0;this.#o()}#b(){this.#f={input:0,output:0,cacheRead:0,cacheWrite:0},this.#c=0,this.#e=void 0,this.#s=0,this.#C="",this.#l=0,this.#h(),this.#w()}#F(){this.#h(),this.#g=setInterval(()=>{this.#l=(this.#l+1)%he.length,this.#o()},le)}#h(){this.#g&&(clearInterval(this.#g),this.#g=void 0)}#T(){this.#w(),this.#d=setTimeout(()=>{this.#d=void 0,this.#e&&(this.#e=void 0,this.#o())},ge)}#w(){this.#d&&(clearTimeout(this.#d),this.#d=void 0)}onUserBash(){var t;(t=this.#t)==null||t.schedule()}async refresh(){var t;await((t=this.#t)==null?void 0:t.refresh())}async reload(t){var n;this.#b(),this.#i=x(this.#m,this.#p(t.cwd)),this.#n=this.#i.config,this.#r=this.#n.enabled,(n=this.#t)==null||n.clear(),this.#t=void 0,this.#r&&(this.#x(this.#u),await this.#t.refresh()),this.#o()}async toggle(){var t;return this.#b(),this.#r=!this.#r,this.#r?(this.#a=p(this.#y()),this.#x(this.#u),await this.#t.refresh()):((t=this.#t)==null||t.clear(),this.#t=void 0),this.#o(),this.#r}getFooterInput(t){var o,r,s,d,u,i;let n=t.sessionManager.getBranch();return n.length!==this.#c&&(this.#f=v(n),this.#c=n.length),{modelId:((o=t.model)==null?void 0:o.id)??"no-model",thinkingLevel:this.#a,directory:se.basename(t.cwd),gitBranch:(r=this.#t)==null?void 0:r.state.branch,gitDirtyCount:((s=this.#t)==null?void 0:s.state.dirtyCount)??0,contextUsed:((u=(d=t.getContextUsage)==null?void 0:d.call(t))==null?void 0:u.tokens)??0,contextMax:(i=t.model)==null?void 0:i.contextWindow,totals:this.#f,toksState:this.#k(),config:this.#n}}#k(){var t;return this.#s>0?{state:"activity",label:this.#C}:((t=this.#e)==null?void 0:t.displayState)??{state:"hidden"}}get isEnabled(){return this.#r}get loadedError(){return this.#i.error}get loadedWarnings(){return this.#i.warnings}get loadedPaths(){return this.#i.loadedPaths}get config(){return this.#n}};import{truncateToWidth as h,visibleWidth as E}from"@earendil-works/pi-tui";function I(e,t,n,o){let r=e.filter(Boolean).join(n),s=t.filter(Boolean).join(n);return pe(r,s,o)}function pe(e,t,n){if(!t)return h(e,n);if(!e)return h(t,n);let o=n-E(e)-E(t);if(o>=1)return h(e+" ".repeat(o)+t,n);let r=Math.max(1,Math.floor((n-1)/2));return h(e,r)+" "+h(t,n-r-1)}function L(e,t){if(t[e])return t[e];let n=e.toLowerCase(),o=n.includes("/")?n.split("/").pop():n;if(t[o])return t[o];if(o.includes("claude")&&o.includes("sonnet"))return o.includes("4-5")||o.includes("4.5")?"sonnet-4.5":o.includes("4")?"sonnet-4":"sonnet";if(o.includes("claude")&&o.includes("opus"))return"opus";if(o.includes("claude")&&o.includes("haiku"))return"haiku";let r=o.match(/gpt-5(?:[.-][a-z0-9]+)*/);if(r)return r[0];let s=o.match(/gpt-4(?:[.-][a-z0-9]+)*/);if(s)return s[0];let d=o.match(/gemini-[a-z0-9.-]+/);return d?d[0].replace(/-preview.*/,""):o.length>24?`${o.slice(0,21)}\u2026`:o}function P(e,t){let n=e.input+e.output,o=`\u2191${c(e.input)} \u2193${c(e.output)} \u03A3${c(n)}`,r=[t.showCacheRead?`\u21AF${c(e.cacheRead)}`:void 0,t.showCacheWrites?`\u21A5${c(e.cacheWrite)}`:void 0].filter(Boolean),s=r.length?`${o} ${r.join(" ")}`:o;return t.cf(t.color,s)}function W(e,t,n){let o=e.input+e.output,r=`\u2191${c(e.input)} \u2193${c(e.output)} \u03A3${c(o)}`;return t(n,r)}function M(e,t,n){let o=e.input+e.output;return t(n,`\u03A3${c(o)}`)}function D(e,t,n){let o=(d,u)=>t.fg(d,u),r=ye(e,o),s=o(e.config.colors.separator,e.config.separator);return[Fe(r,s,e.config.layouts,n)]}function ye(e,t){let n=e.config,o=n.showCache&&n.showCacheRead,r=n.showCache&&n.showCacheWrites;return{model:Ce(e,t),directory:n.showDirectory?xe(e,t):void 0,git:n.showGit?be(e,t):void 0,context:n.showContext?we(e,t):void 0,tokensFull:n.showTokens?P(e.totals,{showCacheRead:o,showCacheWrites:r,cf:t,color:n.colors.tokens}):void 0,tokensNoCache:n.showTokens?W(e.totals,t,n.colors.tokens):void 0,tokensTotal:n.showTokens?M(e.totals,t,n.colors.tokens):void 0,toks:Te(e,t)}}function Ce(e,t){let n=L(e.modelId,e.config.modelAliases),o=e.config.showEffort&&e.thinkingLevel?` \u2022 ${e.thinkingLevel}`:"";return t(e.config.colors.model,`${n}${o}`)}function xe(e,t){if(e.directory)return t(e.config.colors.directory,e.directory)}function be(e,t){if(!e.gitBranch)return;let n=t(e.config.colors.git,e.gitBranch);return e.gitDirtyCount<=0?n:`${n} ${t(e.config.colors.gitDirty,`\u25CF${e.gitDirtyCount}`)}`}function we(e,t){let n=`ctx ${c(e.contextUsed)}/${e.contextMax?c(e.contextMax):"--"}`;if(!e.contextMax||e.contextMax<=0)return t("dim",n);let o=e.contextUsed/e.contextMax*100;return o>=e.config.contextDangerPercent?t(e.config.colors.contextDanger,n):o>=e.config.contextWarningPercent?t(e.config.colors.contextWarning,n):t(e.config.colors.contextNormal,n)}function Te(e,t){let n=e.toksState;if(n.state==="hidden")return;if(n.state==="activity")return t(e.config.colors.tokens,n.label);if(n.state==="pending")return t(e.config.colors.tokens,"\u2026 tok/s");let o=Math.round(n.value);return n.approximate?t(e.config.colors.tokens,`\u2248${o} tok/s`):t(e.config.colors.tokens,`${o} tok/s`)}function Fe(e,t,n,o){let r=ke(n,o),s=$(r.left,e),d=$(r.right,e);return I(s,d,t,o)}function ke(e,t){return e.find(n=>t>=n.minWidth)??e[e.length-1]}function $(e,t){return e.map(n=>t[n]).filter(n=>!!n)}function A(e){return e!==null&&typeof e=="object"&&"usage"in e&&e.usage!==null&&typeof e.usage=="object"}function b(e){if(e===null||typeof e!="object")return;let t=e,n=A(t)?t.usage.output:void 0;if(typeof n=="number"&&Number.isFinite(n)&&n>0)return n;let o=t.message;if(o!==null&&typeof o=="object"&&A(o)){let r=o.usage.output;if(typeof r=="number"&&Number.isFinite(r)&&r>0)return r}}function st(e){let t=N.join(Se.homedir(),".pi","agent","clean-footer.json"),n=i=>N.join(i,".pi","clean-footer.json"),o=()=>{},r=new y({globalConfigPath:t,getProjectConfigPath:n,getThinkingLevel:()=>{var i;return(i=e.getThinkingLevel)==null?void 0:i.call(e)},onRenderNeeded:()=>o()});e.registerCommand("footer",{description:"Toggle, refresh, or configure the clean footer",handler:async(i,a)=>{let f=i.trim();if(f==="refresh"){await r.refresh(),a.hasUI&&a.ui.notify("Footer refreshed","info");return}if(f==="reload"){await r.reload(a),a.hasUI&&r.isEnabled&&s(a),a.hasUI&&!r.isEnabled&&a.ui.setFooter(void 0),o(),d(a);return}if(f==="config"){u(a);return}let g=await r.toggle();a.hasUI&&(g?(s(a),a.ui.notify("Clean footer enabled","info")):(a.ui.setFooter(void 0),a.ui.notify("Default footer restored","info")))}}),e.on("session_start",async(i,a)=>{await r.start(a),a.hasUI&&r.loadedError&&r.isEnabled&&a.ui.notify(`Config error: ${r.loadedError}`,"error"),a.hasUI&&r.isEnabled&&s(a)}),e.on("session_shutdown",(i,a)=>{r.shutdown(),o=()=>{},a.hasUI&&a.ui.setFooter(void 0)}),e.on("thinking_level_select",i=>{r.onThinkingLevel(i.level)}),e.on("model_select",()=>{r.onModelSelect()}),e.on("message_start",i=>{r.onMessageStart(i.message.role)}),e.on("message_end",i=>{let a=i.message,f=a.role==="assistant"?b(a):void 0;r.onMessageEnd(a.role,f)}),e.on("message_update",i=>{let a=i.assistantMessageEvent;if(i.message.role==="assistant"){let f="delta"in a?a.delta:void 0,g=b(i.message);r.onMessageUpdate(a.type,f,g)}}),e.on("tool_execution_start",i=>{r.onToolExecutionStart(i.toolName)}),e.on("tool_execution_update",i=>{r.onToolExecutionUpdate(i.toolName)}),e.on("tool_execution_end",i=>{r.onToolExecutionEnd(i.toolName)}),e.on("user_bash",()=>{r.onUserBash()});function s(i){i.hasUI&&i.ui.setFooter((a,f)=>(o=()=>a.requestRender(),{invalidate(){},render(g){let O=r.getFooterInput(i);return D(O,f,g)}}))}function d(i){i.hasUI&&(r.loadedError?i.ui.notify(`Clean footer config error: ${r.loadedError}`,"error"):r.loadedWarnings.length>0?i.ui.notify(`Clean footer config loaded with warnings: ${r.loadedWarnings.join("; ")}`,"warning"):i.ui.notify("Clean footer config loaded","info"))}function u(i){if(!i.hasUI)return;let a=r.loadedPaths.length?r.loadedPaths.join(`
3
+ `):"none",f=r.loadedWarnings.length?r.loadedWarnings.join(`
4
+ `):"none",g=n(i.cwd);i.ui.notify(["Clean footer config",`global: ${t}`,`project: ${g}`,`loaded:
5
+ ${a}`,r.loadedError?`error: ${r.loadedError}`:"error: none",`warnings:
6
+ ${f}`,`preset: ${r.config.preset}`,`resolved: ${JSON.stringify(r.config)}`].join(`
7
+ `),"info")}}export{st as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neilurk12/pi-clean-footer",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Clean, minimal, and lightweight powerline-style footer extension for pi coding agent.",
5
5
  "type": "module",
6
6
  "keywords": [