@mnemom/mnemom 0.17.38-next.1 → 0.17.38-next.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/dist/commands/agent-run.d.ts +10 -2
- package/dist/commands/agent-run.js +12 -6
- package/dist/commands/scan.d.ts +1 -1
- package/dist/commands/scan.js +7 -14
- package/dist/lib/runner/executor-client.d.ts +6 -0
- package/dist/lib/runner/executor-client.js +6 -0
- package/dist/lib/runner/job.d.ts +12 -3
- package/dist/lib/runner/job.js +30 -2
- package/dist/lib/scan/caps.d.ts +1 -35
- package/dist/lib/scan/caps.js +2 -67
- package/dist/lib/scan/cost-per-pr.d.ts +1 -93
- package/dist/lib/scan/cost-per-pr.js +2 -101
- package/dist/lib/scan/credential.d.ts +2 -26
- package/dist/lib/scan/credential.js +5 -58
- package/dist/lib/scan/failure.d.ts +1 -10
- package/dist/lib/scan/failure.js +2 -43
- package/dist/lib/scan/pr-source.d.ts +1 -57
- package/dist/lib/scan/pr-source.js +2 -132
- package/dist/lib/scan/report-email.d.ts +7 -104
- package/dist/lib/scan/report-email.js +25 -97
- package/dist/lib/scan/scan.d.ts +1 -69
- package/dist/lib/scan/scan.js +2 -195
- package/dist/lib/scan/share.d.ts +3 -1
- package/dist/lib/scan/spend/ai-tool-detect.d.ts +1 -6
- package/dist/lib/scan/spend/ai-tool-detect.js +2 -18
- package/dist/lib/scan/spend/anthropic-usage.d.ts +1 -76
- package/dist/lib/scan/spend/anthropic-usage.js +2 -269
- package/dist/lib/scan/spend/prices.d.ts +1 -33
- package/dist/lib/scan/spend/prices.js +2 -57
- package/dist/lib/scan/spend/spend-estimate.d.ts +1 -30
- package/dist/lib/scan/spend/spend-estimate.js +2 -70
- package/dist/lib/scan/spend/spend-tiers.d.ts +1 -16
- package/dist/lib/scan/spend/spend-tiers.js +6 -26
- package/dist/lib/scan/spend/token-rate.d.ts +1 -30
- package/dist/lib/scan/spend/token-rate.js +2 -54
- package/dist/vendor/shared/org-scan-core/caps.d.ts +35 -0
- package/dist/vendor/shared/org-scan-core/caps.js +68 -0
- package/dist/vendor/shared/org-scan-core/cost-per-pr.d.ts +93 -0
- package/dist/vendor/shared/org-scan-core/cost-per-pr.js +101 -0
- package/dist/vendor/shared/org-scan-core/credential.d.ts +43 -0
- package/dist/vendor/shared/org-scan-core/credential.js +74 -0
- package/dist/vendor/shared/org-scan-core/failure.d.ts +10 -0
- package/dist/vendor/shared/org-scan-core/failure.js +43 -0
- package/dist/vendor/shared/org-scan-core/index.d.ts +18 -0
- package/dist/vendor/shared/org-scan-core/index.js +19 -0
- package/dist/vendor/shared/org-scan-core/pr-source.d.ts +61 -0
- package/dist/vendor/shared/org-scan-core/pr-source.js +138 -0
- package/dist/vendor/shared/org-scan-core/report-build.d.ts +120 -0
- package/dist/vendor/shared/org-scan-core/report-build.js +119 -0
- package/dist/vendor/shared/org-scan-core/scan.d.ts +75 -0
- package/dist/vendor/shared/org-scan-core/scan.js +202 -0
- package/dist/vendor/shared/org-scan-core/spend/ai-tool-detect.d.ts +6 -0
- package/dist/vendor/shared/org-scan-core/spend/ai-tool-detect.js +18 -0
- package/dist/vendor/shared/org-scan-core/spend/anthropic-usage.d.ts +76 -0
- package/dist/vendor/shared/org-scan-core/spend/anthropic-usage.js +270 -0
- package/dist/{lib/scan → vendor/shared/org-scan-core}/spend/cost-corpus.v1.js +1 -0
- package/dist/vendor/shared/org-scan-core/spend/prices.d.ts +33 -0
- package/dist/vendor/shared/org-scan-core/spend/prices.js +58 -0
- package/dist/vendor/shared/org-scan-core/spend/spend-estimate.d.ts +30 -0
- package/dist/vendor/shared/org-scan-core/spend/spend-estimate.js +71 -0
- package/dist/vendor/shared/org-scan-core/spend/spend-select.d.ts +16 -0
- package/dist/vendor/shared/org-scan-core/spend/spend-select.js +26 -0
- package/dist/vendor/shared/org-scan-core/spend/token-rate.d.ts +30 -0
- package/dist/vendor/shared/org-scan-core/spend/token-rate.js +55 -0
- package/package.json +1 -1
- /package/dist/{lib/scan → vendor/shared/org-scan-core}/spend/cost-corpus.v1.d.ts +0 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export type AiTool = "claude_code" | "codex" | "copilot" | "gemini";
|
|
2
|
+
export interface TokenPrice {
|
|
3
|
+
/** USD per 1M input tokens. */
|
|
4
|
+
inputPerMTok: number;
|
|
5
|
+
/** USD per 1M output tokens. */
|
|
6
|
+
outputPerMTok: number;
|
|
7
|
+
model: string;
|
|
8
|
+
}
|
|
9
|
+
export interface PriceBand {
|
|
10
|
+
low: TokenPrice;
|
|
11
|
+
high: TokenPrice;
|
|
12
|
+
/** Page the prices were read from. */
|
|
13
|
+
source: string;
|
|
14
|
+
}
|
|
15
|
+
export declare const PRICES_AS_OF = "2026-10-28";
|
|
16
|
+
export declare const TOOL_PRICES: Record<Exclude<AiTool, "copilot">, PriceBand>;
|
|
17
|
+
/**
|
|
18
|
+
* GitHub Copilot bills per premium request, not per token
|
|
19
|
+
* (https://docs.github.com/en/copilot/concepts/billing/copilot-requests),
|
|
20
|
+
* so it has no token price of its own. Its agent routes to the other vendors' models, so its band is
|
|
21
|
+
* the union of the other three: cheapest low to dearest high. An assumption, stated here once.
|
|
22
|
+
*/
|
|
23
|
+
export declare function copilotBand(): PriceBand;
|
|
24
|
+
/**
|
|
25
|
+
* Share of billed tokens that are input (the rest output). Agent loops re-read large context and
|
|
26
|
+
* write little, so input dominates. An ASSUMPTION used both to turn our known run cost into
|
|
27
|
+
* tokens-per-line and to price those tokens for each tool; it cancels to first order when the
|
|
28
|
+
* tool's input/output price ratio matches ours, and is the main source of the range's width.
|
|
29
|
+
*/
|
|
30
|
+
export declare const INPUT_SHARE = 0.9;
|
|
31
|
+
export declare function bandFor(tool: AiTool): PriceBand;
|
|
32
|
+
/** USD per token at the assumed input/output mix. */
|
|
33
|
+
export declare function blendedUsdPerToken(p: TokenPrice): number;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// GENERATED from shared/org-scan-core/src/spend/prices.ts by cli/scripts/sync-org-scan-core.mjs; do not edit.
|
|
2
|
+
// MNE-9268: public list prices for the AI coding tools the Tier-3 spend estimator can name.
|
|
3
|
+
// Constants, not magic numbers: every row carries its source page and the date it was read.
|
|
4
|
+
// USD per million tokens (input / output), standard (non-batch) list price. A band is the cheapest
|
|
5
|
+
// and the dearest model a tool's coding agent plausibly runs on, so the estimate is a RANGE.
|
|
6
|
+
// Re-read the pages and bump PRICES_AS_OF when they move; a stale price widens nothing silently,
|
|
7
|
+
// it just shifts the range, which is why the date ships with the estimate's method text.
|
|
8
|
+
export const PRICES_AS_OF = "2026-10-28";
|
|
9
|
+
export const TOOL_PRICES = {
|
|
10
|
+
claude_code: {
|
|
11
|
+
source: "https://platform.claude.com/docs/en/about-claude/pricing",
|
|
12
|
+
low: { model: "Claude Sonnet 5.5", inputPerMTok: 2, outputPerMTok: 10 },
|
|
13
|
+
high: { model: "Claude Opus 5", inputPerMTok: 5, outputPerMTok: 25 },
|
|
14
|
+
},
|
|
15
|
+
codex: {
|
|
16
|
+
source: "https://developers.openai.com/api/docs/pricing",
|
|
17
|
+
low: { model: "gpt-5.3-codex (standard)", inputPerMTok: 1.75, outputPerMTok: 14 },
|
|
18
|
+
high: { model: "gpt-5.3-codex (fast)", inputPerMTok: 3.5, outputPerMTok: 28 },
|
|
19
|
+
},
|
|
20
|
+
gemini: {
|
|
21
|
+
source: "https://ai.google.dev/gemini-api/docs/pricing",
|
|
22
|
+
// Gemini 3.8 Flash is $0.75/$3.75 through 2026-12-31 and $1.50/$7.50 from 2027-01-01; the
|
|
23
|
+
// post-promotion price is used so the lower bound does not expire in two months.
|
|
24
|
+
low: { model: "Gemini 3.8 Flash (from 2027-01-01)", inputPerMTok: 1.5, outputPerMTok: 7.5 },
|
|
25
|
+
high: { model: "Gemini 3.1 Pro (prompts up to 200k)", inputPerMTok: 2, outputPerMTok: 12 },
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* GitHub Copilot bills per premium request, not per token
|
|
30
|
+
* (https://docs.github.com/en/copilot/concepts/billing/copilot-requests),
|
|
31
|
+
* so it has no token price of its own. Its agent routes to the other vendors' models, so its band is
|
|
32
|
+
* the union of the other three: cheapest low to dearest high. An assumption, stated here once.
|
|
33
|
+
*/
|
|
34
|
+
export function copilotBand() {
|
|
35
|
+
const bands = Object.values(TOOL_PRICES);
|
|
36
|
+
const blend = (p) => p.inputPerMTok * INPUT_SHARE + p.outputPerMTok * (1 - INPUT_SHARE);
|
|
37
|
+
const low = bands.map((b) => b.low).sort((a, b) => blend(a) - blend(b))[0];
|
|
38
|
+
const high = bands.map((b) => b.high).sort((a, b) => blend(b) - blend(a))[0];
|
|
39
|
+
return {
|
|
40
|
+
low,
|
|
41
|
+
high,
|
|
42
|
+
source: "union of the claude_code, codex and gemini bands (per-request billing)",
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Share of billed tokens that are input (the rest output). Agent loops re-read large context and
|
|
47
|
+
* write little, so input dominates. An ASSUMPTION used both to turn our known run cost into
|
|
48
|
+
* tokens-per-line and to price those tokens for each tool; it cancels to first order when the
|
|
49
|
+
* tool's input/output price ratio matches ours, and is the main source of the range's width.
|
|
50
|
+
*/
|
|
51
|
+
export const INPUT_SHARE = 0.9;
|
|
52
|
+
export function bandFor(tool) {
|
|
53
|
+
return tool === "copilot" ? copilotBand() : TOOL_PRICES[tool];
|
|
54
|
+
}
|
|
55
|
+
/** USD per token at the assumed input/output mix. */
|
|
56
|
+
export function blendedUsdPerToken(p) {
|
|
57
|
+
return (p.inputPerMTok * INPUT_SHARE + p.outputPerMTok * (1 - INPUT_SHARE)) / 1_000_000;
|
|
58
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type AiTool } from "./prices.js";
|
|
2
|
+
import { type TokenRate } from "./token-rate.js";
|
|
3
|
+
/** AI-assisted PRs needed before a range is worth printing. */
|
|
4
|
+
export declare const MIN_AI_PRS = 10;
|
|
5
|
+
/** Per-PR input. `markText` is commit messages / PR body, read for tool marks and dropped. */
|
|
6
|
+
export interface SpendPrInput {
|
|
7
|
+
additions: number;
|
|
8
|
+
deletions: number;
|
|
9
|
+
markText: string;
|
|
10
|
+
/** Tools already detected inside the PR source (so the body never leaves it). Wins over markText. */
|
|
11
|
+
tools?: AiTool[];
|
|
12
|
+
}
|
|
13
|
+
export type NoSpendReason = "too_few_ai_prs" | "no_rate" | "invalid_input";
|
|
14
|
+
export type SpendEstimate = {
|
|
15
|
+
kind: "range";
|
|
16
|
+
lowUsd: number;
|
|
17
|
+
highUsd: number;
|
|
18
|
+
aiPrs: number;
|
|
19
|
+
scannedPrs: number;
|
|
20
|
+
byTool: Partial<Record<AiTool, number>>;
|
|
21
|
+
/** One line, labelled estimate, passes claim-lint. */
|
|
22
|
+
line: string;
|
|
23
|
+
} | {
|
|
24
|
+
kind: "none";
|
|
25
|
+
reason: NoSpendReason;
|
|
26
|
+
aiPrs: number;
|
|
27
|
+
scannedPrs: number;
|
|
28
|
+
line: string;
|
|
29
|
+
};
|
|
30
|
+
export declare function estimateSpend(prs: unknown, rate?: TokenRate | null): SpendEstimate;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// GENERATED from shared/org-scan-core/src/spend/spend-estimate.ts by cli/scripts/sync-org-scan-core.mjs; do not edit.
|
|
2
|
+
// MNE-9268: Tier-3 spend RANGE estimator. Pure and in-memory: takes per-PR counts and mark text, returns
|
|
3
|
+
// one labelled estimate line or an explicit "no estimate". Nothing is stored, fetched or logged.
|
|
4
|
+
//
|
|
5
|
+
// No line is produced when there are too few AI-assisted PRs to price (MIN_AI_PRS). That is a
|
|
6
|
+
// data-sufficiency threshold on the evidence behind the range, nothing to do with how large a
|
|
7
|
+
// reporting cohort is. Default-OFF behind ORG_SCAN_MODE via estimateSpendIfEnabled.
|
|
8
|
+
import { AI_TOOLS, detectAiTools } from "./ai-tool-detect.js";
|
|
9
|
+
import { PRICES_AS_OF, bandFor, blendedUsdPerToken } from "./prices.js";
|
|
10
|
+
import { DERIVED_TOKEN_RATE } from "./token-rate.js";
|
|
11
|
+
/** AI-assisted PRs needed before a range is worth printing. */
|
|
12
|
+
export const MIN_AI_PRS = 10;
|
|
13
|
+
/** Fixed strings only: a failure never carries input or an error message into the output. */
|
|
14
|
+
const NONE_LINES = {
|
|
15
|
+
too_few_ai_prs: "No spend estimate: too few AI-assisted PRs in this scan to price a range.",
|
|
16
|
+
no_rate: "No spend estimate: the cost reference data is not sufficient to price a range.",
|
|
17
|
+
invalid_input: "No spend estimate: the PR counts could not be read.",
|
|
18
|
+
};
|
|
19
|
+
const isCount = (n) => typeof n === "number" && Number.isFinite(n) && n >= 0;
|
|
20
|
+
function none(reason, aiPrs, scannedPrs) {
|
|
21
|
+
return { kind: "none", reason, aiPrs, scannedPrs, line: NONE_LINES[reason] };
|
|
22
|
+
}
|
|
23
|
+
function validPr(p) {
|
|
24
|
+
if (typeof p !== "object" || p === null)
|
|
25
|
+
return false;
|
|
26
|
+
const o = p;
|
|
27
|
+
return (isCount(o.additions) &&
|
|
28
|
+
isCount(o.deletions) &&
|
|
29
|
+
typeof o.markText === "string" &&
|
|
30
|
+
(o.tools === undefined ||
|
|
31
|
+
(Array.isArray(o.tools) && o.tools.every((t) => AI_TOOLS.includes(t)))));
|
|
32
|
+
}
|
|
33
|
+
/** Two significant figures so the range does not claim precision it lacks ($2.4, not $2; 0 stays $0). */
|
|
34
|
+
function usd(n) {
|
|
35
|
+
return `$${n.toLocaleString("en-US", { maximumSignificantDigits: 2 })}`;
|
|
36
|
+
}
|
|
37
|
+
export function estimateSpend(prs, rate = DERIVED_TOKEN_RATE) {
|
|
38
|
+
if (!Array.isArray(prs))
|
|
39
|
+
return none("invalid_input", 0, 0);
|
|
40
|
+
const scanned = prs.length;
|
|
41
|
+
if (!prs.every(validPr))
|
|
42
|
+
return none("invalid_input", 0, scanned);
|
|
43
|
+
let aiPrs = 0;
|
|
44
|
+
let low = 0;
|
|
45
|
+
let high = 0;
|
|
46
|
+
const byTool = {};
|
|
47
|
+
for (const p of prs) {
|
|
48
|
+
const tools = p.tools ?? detectAiTools(p.markText);
|
|
49
|
+
if (tools.length === 0)
|
|
50
|
+
continue;
|
|
51
|
+
aiPrs += 1;
|
|
52
|
+
for (const t of tools)
|
|
53
|
+
byTool[t] = (byTool[t] ?? 0) + 1;
|
|
54
|
+
if (!rate)
|
|
55
|
+
continue;
|
|
56
|
+
const lines = p.additions + p.deletions;
|
|
57
|
+
// A PR carrying several marks is priced once, across the widest band of the tools named.
|
|
58
|
+
const bands = tools.map(bandFor);
|
|
59
|
+
const lo = Math.min(...bands.map((b) => blendedUsdPerToken(b.low)));
|
|
60
|
+
const hi = Math.max(...bands.map((b) => blendedUsdPerToken(b.high)));
|
|
61
|
+
low += lines * rate.low * lo;
|
|
62
|
+
high += lines * rate.high * hi;
|
|
63
|
+
}
|
|
64
|
+
if (aiPrs < MIN_AI_PRS)
|
|
65
|
+
return none("too_few_ai_prs", aiPrs, scanned);
|
|
66
|
+
if (!rate)
|
|
67
|
+
return none("no_rate", aiPrs, scanned);
|
|
68
|
+
const line = `Estimate, AI tool spend: ${usd(low)} to ${usd(high)} across ${aiPrs} AI-assisted PRs ` +
|
|
69
|
+
`(public list prices as of ${PRICES_AS_OF} times a tokens-per-line rate from our own agents' PRs; not billing data).`;
|
|
70
|
+
return { kind: "range", lowUsd: low, highUsd: high, aiPrs, scannedPrs: scanned, byTool, line };
|
|
71
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SpendEstimate } from "./spend-estimate.js";
|
|
2
|
+
export type SpendTier = 1 | 2 | 3;
|
|
3
|
+
export interface SpendSelection {
|
|
4
|
+
/** null when the evidence is too thin: print nothing. */
|
|
5
|
+
tier: SpendTier | null;
|
|
6
|
+
line: string | null;
|
|
7
|
+
/** May this line leave the machine in a share payload? Never for a self-reported figure. */
|
|
8
|
+
shareable: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function selectSpend(i: {
|
|
11
|
+
measuredUsd?: number;
|
|
12
|
+
/** Fraction of measured tokens from requests over 200k context; shown only with a measured figure. */
|
|
13
|
+
over200kShare?: number | null;
|
|
14
|
+
selfReportedUsd?: number | null;
|
|
15
|
+
estimate: SpendEstimate;
|
|
16
|
+
}): SpendSelection;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const usd = (n) => `$${n.toLocaleString("en-US", { maximumFractionDigits: 2 })}`;
|
|
2
|
+
const isUsd = (n) => typeof n === "number" && Number.isFinite(n) && n > 0;
|
|
3
|
+
const pct = (f) => `${Math.round(f * 100)}%`;
|
|
4
|
+
const isShare = (n) => typeof n === "number" && Number.isFinite(n) && n >= 0 && n <= 1;
|
|
5
|
+
export function selectSpend(i) {
|
|
6
|
+
if (isUsd(i.measuredUsd)) {
|
|
7
|
+
return {
|
|
8
|
+
tier: 1,
|
|
9
|
+
line: `Tier 1, measured: ${usd(i.measuredUsd)} of Anthropic usage over the period${isShare(i.over200kShare)
|
|
10
|
+
? ` (${pct(i.over200kShare)} of tokens in requests over 200k context)`
|
|
11
|
+
: ""}.`,
|
|
12
|
+
shareable: true,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
if (isUsd(i.selfReportedUsd)) {
|
|
16
|
+
return {
|
|
17
|
+
tier: 2,
|
|
18
|
+
line: `Tier 2, self-reported: about ${usd(i.selfReportedUsd)} a month (given by you; not verified, not sent, not saved).`,
|
|
19
|
+
shareable: false,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
if (i.estimate.kind === "range") {
|
|
23
|
+
return { tier: 3, line: `Tier 3, ${i.estimate.line}`, shareable: true };
|
|
24
|
+
}
|
|
25
|
+
return { tier: null, line: null, shareable: false };
|
|
26
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Rows needed before the rate is trusted at all (data sufficiency, not a group size). */
|
|
2
|
+
export declare const MIN_CORPUS_ROWS = 5;
|
|
3
|
+
export interface CostRowShape {
|
|
4
|
+
repo: string;
|
|
5
|
+
pr: number;
|
|
6
|
+
additions: number;
|
|
7
|
+
deletions: number;
|
|
8
|
+
cost_usd: number;
|
|
9
|
+
runs: number;
|
|
10
|
+
models: string[];
|
|
11
|
+
}
|
|
12
|
+
export interface TokenRate {
|
|
13
|
+
/** Price-equivalent tokens per changed (added + deleted) line: 25th percentile. */
|
|
14
|
+
low: number;
|
|
15
|
+
median: number;
|
|
16
|
+
/** 75th percentile. */
|
|
17
|
+
high: number;
|
|
18
|
+
rows: number;
|
|
19
|
+
}
|
|
20
|
+
/** Linear-interpolated quantile of a sorted array. */
|
|
21
|
+
export declare function quantile(sorted: number[], q: number): number;
|
|
22
|
+
/**
|
|
23
|
+
* Derive the rate from corpus rows: per-row tokens/line, then the 25th, 50th and 75th percentile.
|
|
24
|
+
* Rows that fail validation are dropped (not repaired); fewer than MIN_CORPUS_ROWS valid rows
|
|
25
|
+
* returns null, never a rate built on a handful.
|
|
26
|
+
*/
|
|
27
|
+
export declare function deriveTokenRate(rows: unknown): TokenRate | null;
|
|
28
|
+
export declare const CORPUS_AS_OF: string;
|
|
29
|
+
/** The shipped rate: derived once from the committed fixture. */
|
|
30
|
+
export declare const DERIVED_TOKEN_RATE: TokenRate | null;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// GENERATED from shared/org-scan-core/src/spend/token-rate.ts by cli/scripts/sync-org-scan-core.mjs; do not edit.
|
|
2
|
+
// MNE-9268: tokens-per-changed-line and its spread, DERIVED from our own agents' PRs whose run cost is
|
|
3
|
+
// known (cost-corpus.v1.json, built by build-cost-corpus.mjs from the ADW "Run cost" PR comments).
|
|
4
|
+
// Nothing here is a typed-in rate: change the fixture and the rate moves, and token-rate.test.ts pins
|
|
5
|
+
// the derivation. Tokens are price-equivalent: cost / (our model's blended list price per token).
|
|
6
|
+
import rawCorpus from "./cost-corpus.v1.js";
|
|
7
|
+
import { TOOL_PRICES, blendedUsdPerToken } from "./prices.js";
|
|
8
|
+
/** Rows needed before the rate is trusted at all (data sufficiency, not a group size). */
|
|
9
|
+
export const MIN_CORPUS_ROWS = 5;
|
|
10
|
+
/** Our agents ran on Sonnet-family models in every corpus row; price their tokens as that. */
|
|
11
|
+
const BASIS_USD_PER_TOKEN = blendedUsdPerToken(TOOL_PRICES.claude_code.low);
|
|
12
|
+
const isCount = (n) => typeof n === "number" && Number.isFinite(n) && n >= 0;
|
|
13
|
+
function validRow(r) {
|
|
14
|
+
if (typeof r !== "object" || r === null)
|
|
15
|
+
return false;
|
|
16
|
+
const o = r;
|
|
17
|
+
return (isCount(o.additions) &&
|
|
18
|
+
isCount(o.deletions) &&
|
|
19
|
+
o.additions + o.deletions > 0 &&
|
|
20
|
+
isCount(o.cost_usd) &&
|
|
21
|
+
o.cost_usd > 0);
|
|
22
|
+
}
|
|
23
|
+
/** Linear-interpolated quantile of a sorted array. */
|
|
24
|
+
export function quantile(sorted, q) {
|
|
25
|
+
if (sorted.length === 0)
|
|
26
|
+
return NaN;
|
|
27
|
+
const pos = (sorted.length - 1) * q;
|
|
28
|
+
const lo = Math.floor(pos);
|
|
29
|
+
const hi = Math.ceil(pos);
|
|
30
|
+
return sorted[lo] + (sorted[hi] - sorted[lo]) * (pos - lo);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Derive the rate from corpus rows: per-row tokens/line, then the 25th, 50th and 75th percentile.
|
|
34
|
+
* Rows that fail validation are dropped (not repaired); fewer than MIN_CORPUS_ROWS valid rows
|
|
35
|
+
* returns null, never a rate built on a handful.
|
|
36
|
+
*/
|
|
37
|
+
export function deriveTokenRate(rows) {
|
|
38
|
+
if (!Array.isArray(rows))
|
|
39
|
+
return null;
|
|
40
|
+
const per = rows
|
|
41
|
+
.filter(validRow)
|
|
42
|
+
.map((r) => r.cost_usd / (r.additions + r.deletions) / BASIS_USD_PER_TOKEN)
|
|
43
|
+
.sort((a, b) => a - b);
|
|
44
|
+
if (per.length < MIN_CORPUS_ROWS)
|
|
45
|
+
return null;
|
|
46
|
+
return {
|
|
47
|
+
low: quantile(per, 0.25),
|
|
48
|
+
median: quantile(per, 0.5),
|
|
49
|
+
high: quantile(per, 0.75),
|
|
50
|
+
rows: per.length,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export const CORPUS_AS_OF = rawCorpus.as_of;
|
|
54
|
+
/** The shipped rate: derived once from the committed fixture. */
|
|
55
|
+
export const DERIVED_TOKEN_RATE = deriveTokenRate(rawCorpus.rows);
|
package/package.json
CHANGED
|
File without changes
|