@hasna/economy 0.2.35 → 0.2.36
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.
|
@@ -63,9 +63,14 @@ interface BriefOptions {
|
|
|
63
63
|
since?: string;
|
|
64
64
|
machine?: string;
|
|
65
65
|
now?: Date;
|
|
66
|
+
currentMachineId?: string;
|
|
67
|
+
localSyncAt?: Date;
|
|
68
|
+
}
|
|
69
|
+
interface BriefCommandDeps {
|
|
70
|
+
beforeRead?: () => void | Promise<void>;
|
|
66
71
|
}
|
|
67
72
|
export declare function buildBrief(db: Database, opts?: BriefOptions): EconomyBrief;
|
|
68
73
|
export declare function renderBriefText(brief: EconomyBrief): string;
|
|
69
|
-
export declare function registerBriefCommand(program: Command): void;
|
|
74
|
+
export declare function registerBriefCommand(program: Command, deps?: BriefCommandDeps): void;
|
|
70
75
|
export {};
|
|
71
76
|
//# sourceMappingURL=brief.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"brief.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/brief.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,KAAK,EAAE,aAAa,IAAI,QAAQ,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"brief.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/brief.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,KAAK,EAAE,aAAa,IAAI,QAAQ,EAAE,MAAM,cAAc,CAAA;AAa7D,KAAK,WAAW,GAAG,OAAO,GAAG,MAAM,CAAA;AAEnC,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,MAAM,CAAA;IACpB,aAAa,EAAE,MAAM,CAAA;IACrB,iBAAiB,EAAE,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B,EAAE,CAAA;IAC/B,QAAQ,EAAE,eAAe,EAAE,CAAA;IAC3B,MAAM,EAAE,aAAa,EAAE,CAAA;IACvB,QAAQ,EAAE,eAAe,EAAE,CAAA;IAC3B,SAAS,EAAE;QACT,QAAQ,EAAE,qBAAqB,EAAE,CAAA;QACjC,gBAAgB,EAAE,MAAM,CAAA;QACxB,eAAe,EAAE,MAAM,CAAA;KACxB,CAAA;CACF;AAcD,UAAU,YAAY;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,GAAG,CAAC,EAAE,IAAI,CAAA;IACV,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,WAAW,CAAC,EAAE,IAAI,CAAA;CACnB;AAED,UAAU,gBAAgB;IACxB,UAAU,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACxC;AAknBD,wBAAgB,UAAU,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,GAAE,YAAiB,GAAG,YAAY,CAmD9E;AAyDD,wBAAgB,eAAe,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAyE3D;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,GAAE,gBAAqB,GAAG,IAAI,CAgCxF"}
|
package/dist/cli/index.js
CHANGED
|
@@ -7234,7 +7234,7 @@ function accountBreakdownToBriefRow(row) {
|
|
|
7234
7234
|
last_active: row.last_active
|
|
7235
7235
|
};
|
|
7236
7236
|
}
|
|
7237
|
-
function queryFreshness(db, now, machine) {
|
|
7237
|
+
function queryFreshness(db, now, machine, localSync) {
|
|
7238
7238
|
const requestFilter = machine ? " AND machine_id = ?" : "";
|
|
7239
7239
|
const requestRows = db.prepare(`
|
|
7240
7240
|
SELECT machine_id, MAX(timestamp) as max_request_at
|
|
@@ -7266,6 +7266,18 @@ function queryFreshness(db, now, machine) {
|
|
|
7266
7266
|
current.merge_sync_age = formatAge(syncAt, now);
|
|
7267
7267
|
machines.set(row.machine_id, current);
|
|
7268
7268
|
}
|
|
7269
|
+
if (localSync && (!machine || machine === localSync.machineId)) {
|
|
7270
|
+
const current = machines.get(localSync.machineId) ?? {
|
|
7271
|
+
machine_id: localSync.machineId,
|
|
7272
|
+
max_request_at: null,
|
|
7273
|
+
request_age: "never",
|
|
7274
|
+
last_merge_sync_at: null,
|
|
7275
|
+
merge_sync_age: "never"
|
|
7276
|
+
};
|
|
7277
|
+
current.last_merge_sync_at = latestTimestamp(current.last_merge_sync_at, localSync.syncedAt);
|
|
7278
|
+
current.merge_sync_age = formatAge(current.last_merge_sync_at, now);
|
|
7279
|
+
machines.set(localSync.machineId, current);
|
|
7280
|
+
}
|
|
7269
7281
|
const rows = [...machines.values()].sort((a, b) => a.machine_id.localeCompare(b.machine_id));
|
|
7270
7282
|
return {
|
|
7271
7283
|
machines: rows,
|
|
@@ -7312,7 +7324,7 @@ function buildBrief(db, opts = {}) {
|
|
|
7312
7324
|
machines,
|
|
7313
7325
|
agents: queryAgentSinceRows(db, since.timestamp, machine),
|
|
7314
7326
|
accounts: queryAccountSinceRows(db, since.timestamp, machine),
|
|
7315
|
-
freshness: queryFreshness(db, now, machine)
|
|
7327
|
+
freshness: queryFreshness(db, now, machine, opts.currentMachineId && opts.localSyncAt ? { machineId: opts.currentMachineId, syncedAt: opts.localSyncAt.toISOString() } : undefined)
|
|
7316
7328
|
};
|
|
7317
7329
|
}
|
|
7318
7330
|
function formatUsd(usd) {
|
|
@@ -7430,12 +7442,22 @@ function renderBriefText(brief) {
|
|
|
7430
7442
|
return lines.join(`
|
|
7431
7443
|
`);
|
|
7432
7444
|
}
|
|
7433
|
-
function registerBriefCommand(program) {
|
|
7434
|
-
program.command("brief").description("Fleet-wide usage brief with tokens, cache, cost, breakdowns, and freshness").option("--since <duration-or-date>", "Since window for breakdown tables (24h, 7d, ISO date)", "24h").option("--machine <id|all>", "Filter to one machine, or all machines", "all").option("--json", "Output JSON").action((opts) => {
|
|
7445
|
+
function registerBriefCommand(program, deps = {}) {
|
|
7446
|
+
program.command("brief").description("Fleet-wide usage brief with tokens, cache, cost, breakdowns, and freshness").option("--since <duration-or-date>", "Since window for breakdown tables (24h, 7d, ISO date)", "24h").option("--machine <id|all>", "Filter to one machine, or all machines", "all").option("--json", "Output JSON").action(async (opts) => {
|
|
7435
7447
|
try {
|
|
7448
|
+
let localSyncAt;
|
|
7449
|
+
if (deps.beforeRead) {
|
|
7450
|
+
await deps.beforeRead();
|
|
7451
|
+
localSyncAt = new Date;
|
|
7452
|
+
}
|
|
7436
7453
|
const db = openDatabase();
|
|
7437
7454
|
ensurePricingSeeded(db);
|
|
7438
|
-
const brief = buildBrief(db, {
|
|
7455
|
+
const brief = buildBrief(db, {
|
|
7456
|
+
since: opts.since,
|
|
7457
|
+
machine: opts.machine,
|
|
7458
|
+
currentMachineId: localSyncAt ? getMachineId() : undefined,
|
|
7459
|
+
localSyncAt
|
|
7460
|
+
});
|
|
7439
7461
|
if (opts.json) {
|
|
7440
7462
|
console.log(JSON.stringify(brief, null, 2));
|
|
7441
7463
|
return;
|
|
@@ -9058,7 +9080,7 @@ billingCmd.command("show").description("Show actual billing totals vs our estima
|
|
|
9058
9080
|
});
|
|
9059
9081
|
registerBrainsCommand(program);
|
|
9060
9082
|
registerTodosCommand(program);
|
|
9061
|
-
registerBriefCommand(program);
|
|
9083
|
+
registerBriefCommand(program, { beforeRead: autoSync });
|
|
9062
9084
|
registerExtendedCommands(program);
|
|
9063
9085
|
registerFleetCommands(program);
|
|
9064
9086
|
registerEventsCommands(program, { source: "economy" });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hasna/economy",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.36",
|
|
4
4
|
"description": "AI coding cost tracker — CLI + MCP server + REST API + web dashboard for Claude Code, Codex, Gemini, OpenCode, Cursor, Pi, and Hermes",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|