claude-agent-ledger 0.7.1 → 0.7.2
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.
- package/bin/agent-ledger.ts +18 -6
- package/package.json +1 -1
package/bin/agent-ledger.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { parseAll } from '../src/parser.ts';
|
|
|
6
6
|
import { isKnownModel } from '../src/pricing.ts';
|
|
7
7
|
import { formatTree, formatTreeMarkdown } from '../src/tree.ts';
|
|
8
8
|
import type { LedgerReport, SubagentTreeNode } from '../src/types.ts';
|
|
9
|
+
import packageJson from '../package.json';
|
|
9
10
|
|
|
10
11
|
type Period = 'today' | 'week' | 'month';
|
|
11
12
|
type Plan = 'payg' | 'pro' | 'max';
|
|
@@ -38,8 +39,9 @@ function periodRange(period: Period): { from: Date; to: Date } {
|
|
|
38
39
|
return { from, to };
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
function usage(): never {
|
|
42
|
-
console.error
|
|
42
|
+
function usage(exitCode = 1): never {
|
|
43
|
+
const write = exitCode === 0 ? console.log : console.error;
|
|
44
|
+
write(`Usage:
|
|
43
45
|
agent-ledger <today|week|month> [flags] — aggregate views
|
|
44
46
|
agent-ledger explain <sessionId> — root-cause why one session was expensive (new in 0.6)
|
|
45
47
|
|
|
@@ -73,7 +75,7 @@ Examples:
|
|
|
73
75
|
agent-ledger week --json | jq '.total.cost.totalCost'
|
|
74
76
|
agent-ledger today --budget 50 # CI gate: fail if today > $50
|
|
75
77
|
`);
|
|
76
|
-
process.exit(
|
|
78
|
+
process.exit(exitCode);
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
function parseArgs(argv: string[]): Args {
|
|
@@ -272,15 +274,25 @@ async function explainCmd(sessionPrefix: string | undefined): Promise<void> {
|
|
|
272
274
|
}
|
|
273
275
|
|
|
274
276
|
async function main(): Promise<void> {
|
|
277
|
+
const cliArgs = process.argv.slice(2);
|
|
278
|
+
const command = cliArgs[0];
|
|
279
|
+
if (command === 'help' || cliArgs.includes('--help') || cliArgs.includes('-h')) {
|
|
280
|
+
usage(0);
|
|
281
|
+
}
|
|
282
|
+
if (command === '--version' || command === '-v') {
|
|
283
|
+
console.log(packageJson.version);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
|
|
275
287
|
// Subcommand dispatch.
|
|
276
|
-
if (
|
|
288
|
+
if (command === 'explain') {
|
|
277
289
|
return explainCmd(process.argv[3]);
|
|
278
290
|
}
|
|
279
|
-
if (
|
|
291
|
+
if (command === 'watch') {
|
|
280
292
|
const interval = Number(process.argv[3]) || 10;
|
|
281
293
|
return watchCmd(interval);
|
|
282
294
|
}
|
|
283
|
-
const args = parseArgs(
|
|
295
|
+
const args = parseArgs(cliArgs);
|
|
284
296
|
const { from, to } = periodRange(args.period);
|
|
285
297
|
const t0 = Date.now();
|
|
286
298
|
|