UNPKG

ccpet

Version:

A Claude Code status line script that displays a virtual pet

6 lines (5 loc) 20.9 kB
#!/usr/bin/env node "use strict";var j=Object.create;var A=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var K=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty;var V=(o,e)=>{for(var t in e)A(o,t,{get:e[t],enumerable:!0})},w=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of X(e))!J.call(o,s)&&s!==t&&A(o,s,{get:()=>e[s],enumerable:!(n=B(e,s))||n.enumerable});return o};var g=(o,e,t)=>(t=o!=null?j(K(o)):{},w(e||!o||!o.__esModule?A(t,"default",{value:o,enumerable:!0}):t,o)),q=o=>w(A({},"__esModule",{value:!0}),o);var ce={};V(ce,{ClaudeCodeStatusLine:()=>S,StatusBarFormatter:()=>y,activate:()=>re,deactivate:()=>ae,main:()=>ie});module.exports=q(ce);function W(){let o=process.env.COLORTERM,e=process.env.TERM;return!!(o==="truecolor"||o==="24bit"||e&&(["iterm","iterm2","alacritty","kitty","wezterm"].some(n=>e.toLowerCase().includes(n))||e.includes("256color"))||process.env.WT_SESSION)}function z(o){let e=o.replace("#",""),t=parseInt(e.substring(0,2),16),n=parseInt(e.substring(2,4),16),s=parseInt(e.substring(4,6),16);return{r:t,g:n,b:s}}function Q(o,e,t){let n=[{r:0,g:0,b:0},{r:128,g:0,b:0},{r:0,g:128,b:0},{r:128,g:128,b:0},{r:0,g:0,b:128},{r:128,g:0,b:128},{r:0,g:128,b:128},{r:192,g:192,b:192},{r:128,g:128,b:128},{r:255,g:0,b:0},{r:0,g:255,b:0},{r:255,g:255,b:0},{r:0,g:0,b:255},{r:255,g:0,b:255},{r:0,g:255,b:255},{r:255,g:255,b:255}],s=0,r=1/0;for(let i=0;i<n.length;i++){let a=n[i],l=Math.sqrt(Math.pow(o-a.r,2)+Math.pow(e-a.g,2)+Math.pow(t-a.b,2));l<r&&(r=l,s=i)}for(let i=0;i<216;i++){let a=16+i,l=Math.floor(i/36)*51,h=Math.floor(i%36/6)*51,O=i%6*51,C=Math.sqrt(Math.pow(o-l,2)+Math.pow(e-h,2)+Math.pow(t-O,2));C<r&&(r=C,s=a)}for(let i=0;i<24;i++){let a=232+i,l=8+i*10,h=Math.sqrt(Math.pow(o-l,2)+Math.pow(e-l,2)+Math.pow(t-l,2));h<r&&(r=h,s=a)}return s}function Z(o,e,t){return`\x1B[38;2;${o};${e};${t}m`}function ee(o,e=!1,t=!1){if(o==="RESET")return"\x1B[0m";let{r:n,g:s,b:r}=z(o);if(W()){let l=Z(n,s,r);return t?`\x1B[1m${l}`:l}let i=Q(n,s,r);if(e&&i<8)return`\x1B[1;3${i}m`;let a=`\x1B[38;5;${i}m`;return t?`\x1B[1m${a}`:a}function M(o){let e={};for(let[t,n]of Object.entries(o))if(t==="RESET")e[t]="\x1B[0m";else{let s=n.split(":"),r=s[0],i=s.includes("bright"),a=s.includes("bold");e[t]=ee(r,i,a)}return e}var f=g(require("fs")),x=g(require("path")),U=g(require("os")),m={colors:{petExpression:"#FFFF00:bright:bold",energyBar:"#00FF00",energyValue:"#00FFFF",accumulatedTokens:"#778899",lifetimeTokens:"#FF00FF",sessionInput:"#00FF00",sessionOutput:"#FFFF00",sessionCached:"#F4A460",sessionTotal:"#FFFFFF",contextLength:"#00DDFF",contextPercentage:"#0099DD",contextPercentageUsable:"#90EE90",cost:"#FFD700"},pet:{animationEnabled:!0,decayRate:.0231,emojiEnabled:!0},display:{maxLines:3,line2:{enabled:!0,items:["input","output","cached","total"]},line3:{enabled:!0,items:["context-length","context-percentage","context-percentage-usable","cost"]}}},E=class{configDir;configFile;cachedConfig=null;constructor(){this.configDir=x.join(U.homedir(),".claude-pet"),this.configFile=x.join(this.configDir,"config.json")}ensureConfigDir(){f.existsSync(this.configDir)||f.mkdirSync(this.configDir,{recursive:!0})}loadConfig(){if(this.cachedConfig)return this.cachedConfig;if(this.ensureConfigDir(),!f.existsSync(this.configFile))return this.saveConfig(m),this.cachedConfig=m,m;try{let e=f.readFileSync(this.configFile,"utf8"),t=JSON.parse(e);return this.cachedConfig=this.mergeWithDefaults(t),this.cachedConfig}catch(e){let t=e instanceof Error?e.message:"Unknown error";return console.warn("Failed to load config, using defaults:",t),this.cachedConfig=m,m}}mergeWithDefaults(e){return{colors:{...m.colors,...e.colors},pet:{...m.pet,...e.pet},display:{...m.display,...e.display,line2:{...m.display.line2,...e.display?.line2},line3:{...m.display.line3,...e.display?.line3}}}}saveConfig(e){this.ensureConfigDir(),f.writeFileSync(this.configFile,JSON.stringify(e,null,2),"utf8"),this.cachedConfig=e}getConfig(){return this.loadConfig()}setColorConfig(e,t){let n=this.loadConfig();n.colors[e]=t,this.saveConfig(n)}setPetConfig(e,t){let n=this.loadConfig();n.pet[e]=t,this.saveConfig(n)}setDisplayConfig(e,t){let n=this.loadConfig();e==="maxLines"?n.display.maxLines=Math.min(3,Math.max(1,Number(t))):e==="line2.enabled"?n.display.line2.enabled=!!t:e==="line2.items"?n.display.line2.items=Array.isArray(t)?t:t.split(",").map(s=>s.trim()):e==="line3.enabled"?n.display.line3.enabled=!!t:e==="line3.items"&&(n.display.line3.items=Array.isArray(t)?t:t.split(",").map(s=>s.trim())),this.saveConfig(n)}resetConfig(){this.saveConfig(m)}listConfig(){let e=this.getConfig();return JSON.stringify(e,null,2)}getConfigPath(){return this.configFile}};var _=(r=>(r.CAT="cat",r.DOG="dog",r.RABBIT="rabbit",r.PANDA="panda",r.FOX="fox",r))(_||{});function te(){try{let e=new E().getConfig();return{PET_EXPRESSION:e.colors.petExpression||"#FFFF00:bright:bold",ENERGY_BAR:e.colors.energyBar||"#00FF00",ENERGY_VALUE:e.colors.energyValue||"#00FFFF",ACCUMULATED_TOKENS:e.colors.accumulatedTokens||"#778899",LIFETIME_TOKENS:e.colors.lifetimeTokens||"#FF00FF",SESSION_INPUT:e.colors.sessionInput||"#00FF00",SESSION_OUTPUT:e.colors.sessionOutput||"#FFFF00",SESSION_CACHED:e.colors.sessionCached||"#F4A460",SESSION_TOTAL:e.colors.sessionTotal||"#FFFFFF",CONTEXT_LENGTH:e.colors.contextLength||"#00DDFF",CONTEXT_PERCENTAGE:e.colors.contextPercentage||"#0099DD",CONTEXT_PERCENTAGE_USABLE:e.colors.contextPercentageUsable||"#90EE90",COST:e.colors.cost||"#FFD700",RESET:"RESET"}}catch{return{PET_EXPRESSION:"#FFFF00:bright:bold",ENERGY_BAR:"#00FF00",ENERGY_VALUE:"#00FFFF",ACCUMULATED_TOKENS:"#778899",LIFETIME_TOKENS:"#FF00FF",SESSION_INPUT:"#00FF00",SESSION_OUTPUT:"#FFFF00",SESSION_CACHED:"#F4A460",SESSION_TOTAL:"#FFFFFF",CONTEXT_LENGTH:"#00DDFF",CONTEXT_PERCENTAGE:"#0099DD",CONTEXT_PERCENTAGE_USABLE:"#90EE90",COST:"#FFD700",RESET:"RESET"}}}var P={cat:{id:"cat",name:"\u732B",emoji:"\u{1F431}"},dog:{id:"dog",name:"\u72D7",emoji:"\u{1F436}"},rabbit:{id:"rabbit",name:"\u5154\u5B50",emoji:"\u{1F430}"},panda:{id:"panda",name:"\u718A\u732B",emoji:"\u{1F43C}"},fox:{id:"fox",name:"\u72D0\u72F8",emoji:"\u{1F98A}"}},c={INITIAL_ENERGY:100,HAPPY_EXPRESSION_THRESHOLD:80,HAPPY_EXPRESSION:"(^_^)",ENERGY_BAR_LENGTH:10,STATUS_BAR_PRIORITY:100,FILLED_BAR_CHAR:"\u25CF",EMPTY_BAR_CHAR:"\u25CB",STATE_THRESHOLDS:{HAPPY:80,HUNGRY:40,SICK:10,DEAD:0},STATE_EXPRESSIONS:{HAPPY:"(^_^)",HUNGRY:"(o_o)",SICK:"(u_u)",DEAD:"(x_x)"},ANIMATED_EXPRESSIONS:{HAPPY:["(^_^)","(^o^)","(^_^)","(^v^)"],HUNGRY:["(o_o)","(O_O)","(o_o)","(-_-)"],SICK:["(u_u)","(T_T)","(u_u)","(>_<)"],DEAD:["(x_x)","(X_X)","(x_x)","(+_+)"]},TIME_DECAY:{DECAY_CHECK_INTERVAL:6e4,DECAY_RATE:.0231,MINIMUM_DECAY_INTERVAL:6e4},FEEDING:{TOKENS_PER_ENERGY:1e6},ANIMAL:{DEFAULT_TYPE:"cat"},COLORS:M(te())};var F=class o{state;deps;observers=[];constructor(e,t){this.state={...e},this.deps=t,this._updateExpression()}getState(){return{...this.state}}subscribe(e){return this.observers.push(e),()=>{let t=this.observers.indexOf(e);t>-1&&this.observers.splice(t,1)}}feed(e){try{let t=this.state.accumulatedTokens+e,{TOKENS_PER_ENERGY:n}=this.deps.config.FEEDING,s=Math.floor(t/n),r=t%n;this.state={...this.state,accumulatedTokens:r,lastFeedTime:new Date,totalTokensConsumed:this.state.totalTokensConsumed+e,totalLifetimeTokens:this.state.totalLifetimeTokens+e},s>0&&this.addEnergy(s)}catch(t){console.error("Pet feeding failed:",t)}}applyTimeDecay(){try{let e=new Date,{TIME_DECAY:t}=this.deps.config,n=this.state.lastDecayTime||this.state.lastFeedTime,s=(e.getTime()-n.getTime())/(1e3*60);if(s>0){let r=t?t.DECAY_RATE/(t.DECAY_CHECK_INTERVAL/6e4):.023148148148148147,i=s*r,a=t?t.MINIMUM_DECAY_INTERVAL/(1e3*60):0;i>0&&s>=a&&(this.decreaseEnergy(i),this.state={...this.state,lastDecayTime:e})}}catch(e){console.error("Pet time decay failed:",e)}}addEnergy(e){try{if(typeof e!="number"||e<0||isNaN(e))throw new Error(`Invalid energy amount: ${e}. Must be a non-negative number.`);let t=new Date;this.state={...this.state,energy:Math.min(100,this.state.energy+e),lastFeedTime:t,lastDecayTime:t},this._updateExpression(),this._notify()}catch(t){throw console.error("Pet addEnergy failed:",t),t}}decreaseEnergy(e){try{if(typeof e!="number"||e<0||isNaN(e))throw new Error(`Invalid energy amount: ${e}. Must be a non-negative number.`);this.state={...this.state,energy:Math.max(0,this.state.energy-e)},this._updateExpression(),this._notify()}catch(t){throw console.error("Pet decreaseEnergy failed:",t),t}}getCurrentEnergy(){return this.state.energy}getCurrentAnimalType(){return this.state.animalType}static getRandomAnimalType(){let e=Object.values(_),t=Math.floor(Math.random()*e.length);return e[t]}getAnimalEmoji(){return P[this.state.animalType]?.emoji||P.cat.emoji}isDead(){return this.state.energy===0}resetToInitialState(){try{let e=new Date,t=o.getRandomAnimalType();this.state={energy:this.deps.config.INITIAL_ENERGY,expression:this.deps.config.STATE_EXPRESSIONS.HAPPY,animalType:t,birthTime:e,lastFeedTime:e,totalTokensConsumed:0,accumulatedTokens:0,totalLifetimeTokens:0,lastDecayTime:e,sessionTotalInputTokens:0,sessionTotalOutputTokens:0,sessionTotalCachedTokens:0},console.log(`Pet reborn as ${t} type`),this._updateExpression(),this._notify()}catch(e){throw console.error("Pet resetToInitialState failed:",e),e}}_updateExpression(){if(!this.deps?.config)return;let{STATE_THRESHOLDS:e,STATE_EXPRESSIONS:t}=this.deps.config;this.state.energy>=e.HAPPY?this.state.expression=t.HAPPY:this.state.energy>=e.HUNGRY?this.state.expression=t.HUNGRY:this.state.energy>=e.SICK?this.state.expression=t.SICK:this.state.expression=t.DEAD}getAnimatedExpression(e=!1,t=0,n=!0){let{STATE_THRESHOLDS:s,ANIMATED_EXPRESSIONS:r}=this.deps.config,i;if(!e||!r)i=this.state.expression;else{let a;this.state.energy>=s.HAPPY?a=r.HAPPY:this.state.energy>=s.HUNGRY?a=r.HUNGRY:this.state.energy>=s.SICK?a=r.SICK:a=r.DEAD;let l=t%a.length;i=a[l]}return n?`${this.getAnimalEmoji()}${i}`:i}_notify(){this.observers.forEach(e=>{try{e(this.getState())}catch(t){console.error("Observer notification failed:",t)}})}};var y=class{testMode;configService;constructor(e=!1,t){this.testMode=e,this.configService=t||new E}formatPetDisplay(e,t){try{let n=this.configService.getConfig(),s=[],r=this.formatPetLine(e,t);s.push(r);let i=this.getSessionData(e);if(n.display.line2?.enabled&&(n.display.maxLines||2)>=2){let a=this.formatConfigurableLine(n.display.line2.items||[],i);a&&s.push(a)}if(n.display.line3?.enabled&&(n.display.maxLines||2)>=3){let a=this.formatConfigurableLine(n.display.line3.items||[],i);a&&s.push(a)}return s.join((this.testMode,` `))}catch(n){return console.error("Failed to format pet display:",n),console.error("Error stack:",n instanceof Error?n.stack:"No stack trace"),"(?) ERROR"}}formatPetLine(e,t){let n=this.generateEnergyBar(e.energy),s=e.energy.toFixed(2),r=this.formatTokenCount(e.accumulatedTokens),i=this.formatTokenCount(e.totalLifetimeTokens),a=t||e.expression;return this.testMode?`${a} ${n} ${s} (${r}) \u{1F496}${i}`:`${c.COLORS.PET_EXPRESSION}${a}${c.COLORS.RESET} ${c.COLORS.ENERGY_BAR}${n}${c.COLORS.RESET} ${c.COLORS.ENERGY_VALUE}${s}${c.COLORS.RESET} ${c.COLORS.ACCUMULATED_TOKENS}(${r})${c.COLORS.RESET} ${c.COLORS.LIFETIME_TOKENS}\u{1F496}${i}${c.COLORS.RESET}`}getSessionData(e){let t={};if(e.sessionTotalInputTokens!==void 0&&(t.input={value:this.formatTokenCount(e.sessionTotalInputTokens),color:c.COLORS.SESSION_INPUT}),e.sessionTotalOutputTokens!==void 0&&(t.output={value:this.formatTokenCount(e.sessionTotalOutputTokens),color:c.COLORS.SESSION_OUTPUT}),e.sessionTotalCachedTokens!==void 0&&(t.cached={value:this.formatTokenCount(e.sessionTotalCachedTokens),color:c.COLORS.SESSION_CACHED}),e.sessionTotalInputTokens!==void 0&&e.sessionTotalOutputTokens!==void 0&&e.sessionTotalCachedTokens!==void 0){let n=e.sessionTotalInputTokens+e.sessionTotalOutputTokens+e.sessionTotalCachedTokens;t.total={value:this.formatTokenCount(n),color:c.COLORS.SESSION_TOTAL}}return e.sessionTotalCostUsd!==void 0&&(t.cost={value:`$${e.sessionTotalCostUsd.toFixed(2)}`,color:c.COLORS.COST}),e.contextLength!==void 0&&(t["context-length"]={value:this.formatTokenCount(e.contextLength),color:c.COLORS.CONTEXT_LENGTH}),e.contextPercentage!==void 0&&(t["context-percentage"]={value:isNaN(e.contextPercentage)?"0.0%":`${e.contextPercentage.toFixed(1)}%`,color:c.COLORS.CONTEXT_PERCENTAGE}),e.contextPercentageUsable!==void 0&&(t["context-percentage-usable"]={value:isNaN(e.contextPercentageUsable)?"0.0%":`${e.contextPercentageUsable.toFixed(1)}%`,color:c.COLORS.CONTEXT_PERCENTAGE_USABLE}),t}formatConfigurableLine(e,t){let n=[];for(let s of e)if(t[s]){let r=t[s],i;s==="context-length"||s==="context-percentage"?i="Ctx":s==="context-percentage-usable"?i="Ctx(u)":s==="cost"?i="Cost":i=s.charAt(0).toUpperCase()+s.slice(1),this.testMode?n.push(`${i}: ${r.value}`):n.push(`${r.color}${i}: ${r.value}${c.COLORS.RESET}`)}return n.length>0?n.join(" "):""}generateEnergyBar(e){try{if(isNaN(e))return"??????????";let t=Math.max(0,Math.min(100,e)),n=Math.round(t/100*c.ENERGY_BAR_LENGTH),s=c.ENERGY_BAR_LENGTH-n;return c.FILLED_BAR_CHAR.repeat(n)+c.EMPTY_BAR_CHAR.repeat(s)}catch(t){return console.error("Failed to generate energy bar:",t),"??????????"}}formatTokenCount(e){try{return isNaN(e)?"?":e>=1e6?`${(e/1e6).toFixed(2)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toString()}catch(t){return console.error("Failed to format token count:",t),"?"}}};var T=g(require("fs")),R=g(require("path")),G=g(require("os")),N=class{stateFilePath;constructor(){let e=G.homedir(),t=R.join(e,".claude-pet");this.stateFilePath=R.join(t,"pet-state.json"),this.ensureDirectoryExists(t)}loadState(){try{if(!T.existsSync(this.stateFilePath))return null;let e=T.readFileSync(this.stateFilePath,"utf8"),t=JSON.parse(e);return t.lastFeedTime&&(t.lastFeedTime=new Date(t.lastFeedTime)),t.lastDecayTime&&(t.lastDecayTime=new Date(t.lastDecayTime)),t.birthTime&&(t.birthTime=new Date(t.birthTime)),t.totalLifetimeTokens===void 0&&(t.totalLifetimeTokens=t.totalTokensConsumed||0),t.animalType===void 0&&(t.animalType=c.ANIMAL.DEFAULT_TYPE,console.log(`Migrating existing pet to default animal type: ${t.animalType}`)),Object.values(_).includes(t.animalType)||(console.warn(`Invalid animal type found: ${t.animalType}, using default`),t.animalType=c.ANIMAL.DEFAULT_TYPE),t.birthTime===void 0&&(t.birthTime=t.lastFeedTime||new Date,console.log(`Adding birthTime for existing pet: ${t.birthTime.toISOString()}`)),t}catch(e){return console.error("Failed to load pet state:",e),null}}saveState(e){try{let t=JSON.stringify(e,null,2);T.writeFileSync(this.stateFilePath,t,"utf8")}catch(t){console.error("Failed to save pet state:",t)}}ensureDirectoryExists(e){try{T.existsSync(e)||T.mkdirSync(e,{recursive:!0})}catch(t){console.error("Failed to create pet storage directory:",t)}}};var p=g(require("fs")),Y=g(require("readline")),k=g(require("path")),b=k.join(process.env.HOME||"",".claude-pet","session-tracker.json");function ne(o){try{if(!p.existsSync(b))return null;let e=p.readFileSync(b,"utf8");return JSON.parse(e)[o]||null}catch{return null}}function se(o){try{let e=k.dirname(b);p.existsSync(e)||p.mkdirSync(e,{recursive:!0});let t={};if(p.existsSync(b)){let n=p.readFileSync(b,"utf8");t=JSON.parse(n)}t[o.sessionId]=o,p.writeFileSync(b,JSON.stringify(t,null,2))}catch(e){console.error("Failed to save session tracker:",e)}}async function $(o){let e=0,t=0,n=0,s=0,r=0,i=0,a=0,l="",h="",O="";try{if(!p.existsSync(o))return{inputTokens:0,outputTokens:0,cachedTokens:0,totalTokens:0,sessionTotalInputTokens:0,sessionTotalOutputTokens:0,sessionTotalCachedTokens:0,contextLength:0};let C=p.createReadStream(o),H=Y.createInterface({input:C,crlfDelay:1/0}),v=[];for await(let d of H)if(d.trim()!=="")try{let u=JSON.parse(d);u.sessionId&&(l=u.sessionId),v.push(u)}catch{continue}if(!l)return{inputTokens:0,outputTokens:0,cachedTokens:0,totalTokens:0,sessionTotalInputTokens:0,sessionTotalOutputTokens:0,sessionTotalCachedTokens:0,contextLength:0};let I=ne(l),L=!I;for(let d of v){let u=d.usage||d.message&&d.message.usage;if(u&&(s+=u.input_tokens||0,r+=u.output_tokens||0,i+=(u.cache_creation_input_tokens||0)+(u.cache_read_input_tokens||0),a=(u.input_tokens||0)+(u.cache_read_input_tokens||0)+(u.cache_creation_input_tokens||0)),I&&!L){if(d.uuid===I.lastProcessedUuid){L=!0;continue}continue}u&&(e+=u.input_tokens||0,t+=u.output_tokens||0,n+=(u.cache_creation_input_tokens||0)+(u.cache_read_input_tokens||0)),d.uuid&&(h=d.uuid),d.timestamp&&(O=d.timestamp)}if(h){let d={sessionId:l,lastProcessedUuid:h,lastProcessedTimestamp:O,totalProcessedTokens:(I?.totalProcessedTokens||0)+e+t+n};se(d)}return{inputTokens:e,outputTokens:t,cachedTokens:n,totalTokens:e+t+n,sessionTotalInputTokens:s,sessionTotalOutputTokens:r,sessionTotalCachedTokens:i,contextLength:a}}catch(C){return console.error("Failed to process JSONL transcript:",C),{inputTokens:0,outputTokens:0,cachedTokens:0,totalTokens:0,sessionTotalInputTokens:0,sessionTotalOutputTokens:0,sessionTotalCachedTokens:0,contextLength:0}}}var D=class{callCount=0;testMode;COUNTER_FILE=require("path").join(require("os").homedir(),".claude-pet","animation-counter.json");constructor(e=!1){this.testMode=e,e||this.loadCounter()}loadCounter(){try{let e=require("fs");if(e.existsSync(this.COUNTER_FILE)){let t=JSON.parse(e.readFileSync(this.COUNTER_FILE,"utf8"));this.callCount=t.callCount||0}}catch{this.callCount=0}}saveCounter(){try{let e=require("fs"),n=require("path").dirname(this.COUNTER_FILE);e.existsSync(n)||e.mkdirSync(n,{recursive:!0});let s={callCount:this.callCount,lastUpdate:Date.now()};e.writeFileSync(this.COUNTER_FILE,JSON.stringify(s))}catch{}}recordCall(){this.testMode||(this.callCount++,this.saveCounter())}shouldEnableAnimation(){return!this.testMode}getFrameIndex(){return this.callCount}},S=class{pet;formatter;storage;configService;animationCounter;constructor(e=!1,t){this.animationCounter=new D(e),this.storage=new N,this.configService=t||new E,this.formatter=new y(e,t);let n=this.storage.loadState(),s=new Date,r=n||{energy:c.INITIAL_ENERGY,expression:c.HAPPY_EXPRESSION,animalType:F.getRandomAnimalType(),birthTime:s,lastFeedTime:s,totalTokensConsumed:0,accumulatedTokens:0,totalLifetimeTokens:0};this.pet=new F(r,{config:c}),n&&this.pet.applyTimeDecay()}async processTokensAndGetStatusDisplay(e){try{this.animationCounter.recordCall(),this.pet.applyTimeDecay();let t=await $(e.transcript_path);t.totalTokens>0&&this.pet.feed(t.totalTokens);let n=this.pet.getState();n.sessionTotalInputTokens=t.sessionTotalInputTokens,n.sessionTotalOutputTokens=t.sessionTotalOutputTokens,n.sessionTotalCachedTokens=t.sessionTotalCachedTokens,n.sessionTotalCostUsd=e.cost.total_cost_usd,n.contextLength=t.contextLength,t.contextLength!==void 0&&(n.contextPercentage=Math.min(100,t.contextLength/2e5*100),n.contextPercentageUsable=Math.min(100,t.contextLength/16e4*100));let s=this.animationCounter.shouldEnableAnimation(),r=this.animationCounter.getFrameIndex(),a=this.configService.getConfig().pet.emojiEnabled??!0,l=this.pet.getAnimatedExpression(s,r,a);return this.formatter.formatPetDisplay(n,l)}catch(t){console.error("Token processing failed:",t),this.pet.applyTimeDecay();let n=this.pet.getState();return this.formatter.formatPetDisplay(n)}}getStatusDisplay(){this.animationCounter.recordCall(),this.pet.applyTimeDecay();let e=this.pet.getState(),t=this.animationCounter.shouldEnableAnimation(),n=this.animationCounter.getFrameIndex(),r=this.configService.getConfig().pet.emojiEnabled??!0,i=this.pet.getAnimatedExpression(t,n,r);return this.formatter.formatPetDisplay(e,i)}saveState(){this.storage.saveState(this.pet.getState())}adoptNewPet(){this.pet.isDead()&&(this.pet.resetToInitialState(),this.saveState(),typeof window<"u"&&window.vscode?.postMessage&&window.vscode.postMessage({command:"showInformationMessage",text:"Successfully adopted a new pet! Your pet is now happy and full of energy."}))}isPetDead(){return this.pet.isDead()}};function oe(){return new Promise(o=>{let e="";process.stdin.setEncoding("utf8"),process.stdin.on("data",t=>{e+=t}),process.stdin.on("end",()=>{o(e.trim())})})}async function ie(){try{let o=await oe();if(!o){let s=new S,r=s.getStatusDisplay();s.saveState(),process.stdout.write(r);return}let e;try{e=JSON.parse(o)}catch{let r=new S,i=r.getStatusDisplay();r.saveState(),process.stdout.write(i);return}let t=new S,n=await t.processTokensAndGetStatusDisplay(e);t.saveState(),process.stdout.write(n)}catch(o){process.stdout.write("(?) ERROR"),process.stderr.write(`Pet status error: ${o} `),process.exit(1)}}function re(o){let e=new S;o.subscriptions.push({command:"claude-pet.adoptNewPet",callback:()=>{e.adoptNewPet()}}),typeof window<"u"&&window.vscode?.commands&&window.vscode.commands.registerCommand("claude-pet.adoptNewPet",()=>{e.adoptNewPet()})}function ae(){}0&&(module.exports={ClaudeCodeStatusLine,StatusBarFormatter,activate,deactivate,main}); //# sourceMappingURL=ccpet.js.map