@jovan158/vantage
Version:
See and control what your coding agent does
27 lines (26 loc) • 1.07 kB
JavaScript
// `vantage stats`: usage over the last days, across all recorded sessions.
import { knownSessions } from "../home.js";
import { readSessionEvents } from "../watch.js";
import { sessionStat, renderStats } from "../stats.js";
import { log } from "./output.js";
export async function cmdStats(argv) {
let days = 7;
const i = argv.findIndex((a) => a === "--days" || a.startsWith("--days="));
if (i !== -1) {
const raw = argv[i].includes("=") ? argv[i].split("=")[1] : argv[i + 1];
days = Number(raw);
if (!Number.isInteger(days) || days < 1 || days > 366) {
log(`--days needs a whole number from 1 to 366 (got "${raw ?? ""}")`);
return 1;
}
}
const cwd = process.cwd();
const stats = [];
for (const ref of knownSessions(cwd)) {
const stat = sessionStat(ref, readSessionEvents(ref.cwd, ref.sessionId));
if (stat)
stats.push(stat);
}
process.stdout.write(renderStats(stats, { days, cwd, color: process.stdout.isTTY ?? false }) + "\n");
return 0;
}