#!/usr/bin/env node /** * token-optimizer-savings -- what the optimizer saved, over time, in dollars. * * WHY THIS EXISTS. The analytics ledger has carried verified, priced savings * for a long time, and the only way to read it was to ask an agent to call the * `get_optimization_report` MCP tool. That is the wrong shape for the question: * "what did this save me this week" is asked by a person at a shell, usually * while deciding whether to keep the thing installed, and it was unanswerable * without a running agent and a tool call. * * It is also a different question from the one that tool answers. That report * breaks a caller-supplied date range down by tool, hook and MCP server. This * one breaks the last day, week and month down by MODEL and CLIENT, because * those are the dimensions a bill is denominated in. * * THERE IS NO `--reset`. The competing tool has one, and it deletes its ledger. * Ours is shared: the dashboard, the action and hook reports and the MCP report * all read the same rows, so a flag on this command that emptied it would * destroy four other surfaces to clear one. Clearing analytics is the * analytics layer's decision to offer, not this reader's. */ import type { AnalyticsEntry } from '../analytics/analytics-types.js'; import type { AnalyticsRollup } from '../analytics/analytics-rollup.js'; import { type OperatorPriceTableStatus } from '../analytics/operator-prices.js'; import { type SavingsReport } from './windows.js'; import { type ProxyInput } from './proxy.js'; import { type GateWindow } from './gate.js'; export interface Options { readonly topN: number; /** * How to write the report. * * ONE FIELD, NOT A FLAG PER FORMAT. A boolean per rendering lets two of them * be true at once, and the command then has to pick a winner that nobody * asked for; a single value makes a contradiction an argument error instead. */ readonly format: SavingsFormat; readonly help: boolean; /** * An explicit proxy ledger, or undefined to take the one * `TOKEN_OPTIMIZER_PROXY_ACCOUNTING` names. UNDEFINED IS NOT "NONE": there is * no flag that suppresses the second input, because a report that silently * dropped half of what the product does is the defect this command had. */ readonly proxyLedger?: string; /** * A percentage every measured half must reach, or undefined for no gate. * * A REPORT AND A GATE ARE TWO DIFFERENT QUESTIONS, which is why this is a * flag and not the default: rendering what happened must not start failing * because a figure moved, and a rollout that needs a bar needs a status code * rather than a table somebody reads. */ readonly minSavings?: number; /** The window the gate measures. Only meaningful with `minSavings`. */ readonly window: GateWindow; /** Clients that must each have traffic in that window and meet the bar. */ readonly requireClients: readonly string[]; } /** * The renderings this command can write. * * `text` is for a person, `json` is lossless and is what a consumer should * parse, and `csv` is the one flat table a spreadsheet or a stored series * wants -- see savings/csv.ts for what an empty cell means there. */ export declare const SAVINGS_FORMAT: Readonly<{ readonly Text: "text"; readonly Json: "json"; readonly Csv: "csv"; }>; export type SavingsFormat = (typeof SAVINGS_FORMAT)[keyof typeof SAVINGS_FORMAT]; export declare function parseArguments(args: readonly string[]): Options | string; /** * Both halves of the analytics store, read at one point in time. * * ONE READ, NOT TWO, BECAUSE A PRUNE CAN LAND BETWEEN THEM. The retention pass * moves a day from rows into totals; a reader that fetched the rows first and * the totals second would count that day twice, and one that fetched them the * other way round would miss it. Taking both from a single call makes either * mistake impossible to write. */ export interface AnalyticsInput { /** Every analytics row, newest or oldest first -- the windows do not care. */ readonly entries: readonly AnalyticsEntry[]; /** Days already folded into totals, which the windows read alongside rows. */ readonly rollups: readonly AnalyticsRollup[]; } export interface MainDependencies { /** Every row and every folded day, from one read -- see `AnalyticsInput`. */ readonly analytics?: () => Promise; readonly now?: () => Date; readonly write?: (text: string) => void; /** * The proxy ledger's state, already read. Never throws -- see * `loadProxyInput`, whose four states are the point of the type. */ readonly proxy?: (path: string | undefined, now: Date) => Promise; } export declare function proxyJson(proxy: ProxyInput): Record; export declare function savingsJson(report: SavingsReport, proxy: ProxyInput, priceTable?: OperatorPriceTableStatus): Record; export declare function main(args: readonly string[], dependencies?: MainDependencies): Promise; //# sourceMappingURL=cli.d.ts.map