33 */
44import { Command } from 'commander' ;
55import chalk from 'chalk' ;
6- import { discoverSessionFiles , calculateDetailedStats , fmt , formatTokens , ENVIRONMENTAL } from '../helpers' ;
6+ import { discoverSessionFiles , calculateDetailedStats , formatTokens , ENVIRONMENTAL } from '../helpers' ;
77import type { PeriodStats } from '../../../vscode-extension/src/types' ;
88
99export const environmentalCommand = new Command ( 'environmental' )
@@ -38,7 +38,7 @@ export const environmentalCommand = new Command('environmental')
3838 console . log ( chalk . dim ( 'Methodology: Estimates based on industry averages for AI inference' ) ) ;
3939 console . log ( chalk . dim ( ` CO₂: ${ ENVIRONMENTAL . CO2_PER_1K_TOKENS } gCO₂e per 1K tokens` ) ) ;
4040 console . log ( chalk . dim ( ` Water: ${ ENVIRONMENTAL . WATER_USAGE_PER_1K_TOKENS } L per 1K tokens` ) ) ;
41- console . log ( chalk . dim ( ` Tree absorption: ${ fmt ( ENVIRONMENTAL . CO2_ABSORPTION_PER_TREE_PER_YEAR ) } g CO₂/year\n` ) ) ;
41+ console . log ( chalk . dim ( ` Tree absorption: ${ formatCo2 ( ENVIRONMENTAL . CO2_ABSORPTION_PER_TREE_PER_YEAR ) } CO₂/year\n` ) ) ;
4242
4343 for ( const period of periods ) {
4444 printEnvironmentalStats ( period . label , period . emoji , period . stats ) ;
@@ -75,6 +75,14 @@ export const environmentalCommand = new Command('environmental')
7575 console . log ( chalk . dim ( `Last updated: ${ stats . lastUpdated . toLocaleString ( ) } \n` ) ) ;
7676 } ) ;
7777
78+ /** Format CO₂ in grams, switching to kg notation when ≥ 1 000 g */
79+ function formatCo2 ( grams : number ) : string {
80+ if ( grams >= 1000 ) {
81+ return `${ ( grams / 1000 ) . toFixed ( 2 ) } kgCO₂e` ;
82+ }
83+ return `${ grams . toFixed ( 3 ) } gCO₂e` ;
84+ }
85+
7886function printEnvironmentalStats ( label : string , emoji : string , stats : PeriodStats ) : void {
7987 console . log ( chalk . bold ( `${ emoji } ${ label } ` ) ) ;
8088 console . log ( chalk . dim ( '─' . repeat ( 55 ) ) ) ;
@@ -86,7 +94,7 @@ function printEnvironmentalStats(label: string, emoji: string, stats: PeriodStat
8694 }
8795
8896 console . log ( ` Tokens used: ${ chalk . bold . yellow ( formatTokens ( stats . tokens ) ) } ` ) ;
89- console . log ( ` CO₂ emissions: ${ chalk . bold ( stats . co2 . toFixed ( 3 ) ) } gCO₂e ` ) ;
97+ console . log ( ` CO₂ emissions: ${ chalk . bold ( formatCo2 ( stats . co2 ) ) } ` ) ;
9098 console . log ( ` Water usage: ${ chalk . bold ( stats . waterUsage . toFixed ( 3 ) ) } liters` ) ;
9199
92100 if ( stats . treesEquivalent > 0 ) {
0 commit comments