claude-statusline-powerline
Version:
Beautiful powerline-style statusline for Claude Code with git integration, session tracking, and cost monitoring
114 lines • 4.91 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.ContextSegment = void 0;
const fs = __importStar(require("node:fs"));
const path = __importStar(require("node:path"));
const font_profiles_1 = require("../font-profiles");
const token_formatting_1 = require("../utils/token-formatting");
const base_1 = require("./base");
class ContextSegment extends base_1.BaseSegment {
constructor() {
super(...arguments);
this.name = 'context';
}
build(data, config) {
const context_info = this.get_context_info(data);
if (!context_info)
return null;
const style_override = this.getSegmentConfig(config);
const font_profile = (0, font_profiles_1.get_font_profile)(config.font_profile);
const brain_icon = (0, font_profiles_1.get_symbol)(font_profile, 'brain', style_override?.icons);
let display = '';
if (context_info.session_type === 'cold') {
display = `${brain_icon} Cold`;
}
else {
const formatted_tokens = (0, token_formatting_1.format_tokens)(context_info.total_cache_tokens);
display = `${brain_icon} ${formatted_tokens} cached (${context_info.cache_hit_rate}% reused)`;
}
const theme = config.current_theme?.segments.context;
if (!theme) {
// Fallback if theme is not available
return this.createSegment(display, '\x1b[46m', // teal bg fallback
'\x1b[97m', // white fg fallback
'\x1b[36m', // teal separator fallback
config.separators.context, style_override);
}
return this.createSegment(display, theme.background, theme.foreground, theme.separator_color, config.separators.context, style_override);
}
get_context_info(data) {
if (!data.session_id)
return null;
// Direct session file path using session ID - no discovery needed
const session_file = path.join(process.env.HOME || '', '.claude/projects', data.workspace.current_dir.replace(/\//g, '-'), `${data.session_id}.jsonl`);
try {
const content = fs.readFileSync(session_file, 'utf8');
let total_cache_read = 0;
let total_cache_creation = 0;
// Simple parsing - just sum the cache usage
for (const line of content.trim().split('\n')) {
try {
const entry = JSON.parse(line);
const usage = entry.message?.usage;
if (usage) {
total_cache_read += usage.cache_read_input_tokens || 0;
total_cache_creation +=
usage.cache_creation_input_tokens || 0;
}
}
catch {
// Skip malformed lines
}
}
const total_cache_tokens = total_cache_read + total_cache_creation;
if (total_cache_tokens === 0)
return null;
const cache_hit_rate = Math.round((total_cache_read / total_cache_tokens) * 100);
const session_type = total_cache_read > 10000 ? 'warm' : 'cold';
return {
cache_hit_rate,
total_cache_tokens: total_cache_read,
session_type,
};
}
catch {
// File doesn't exist or can't be read
return null;
}
}
}
exports.ContextSegment = ContextSegment;
//# sourceMappingURL=context.js.map