Skip to content

Commit fd25998

Browse files
authored
Merge pull request #5 from codebase/codex/clarify-usage-quotas
Clarify usage quota semantics
2 parents 62cec18 + fe12e7b commit fd25998

4 files changed

Lines changed: 34 additions & 11 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codebase-cli",
3-
"version": "2.0.0-pre.77",
3+
"version": "2.0.0-pre.78",
44
"description": "Codebase CLI — a TypeScript coding agent on the pi-mono runtime. OAuth-aware, any LLM provider, single install.",
55
"keywords": [
66
"ai",

src/commands/builtins/usage.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { mkdtempSync, rmSync } from "node:fs";
22
import { tmpdir } from "node:os";
33
import { join } from "node:path";
44
import { afterEach, describe, expect, it, vi } from "vitest";
5-
import { fetchUsageReport, formatUsageBalance } from "./usage.js";
5+
import { fetchUsageReport, formatTurnQuotas, formatUsageBalance } from "./usage.js";
66

77
let homeDir: string | undefined;
88

@@ -79,6 +79,20 @@ describe("formatUsageBalance", () => {
7979
});
8080
});
8181

82+
describe("formatTurnQuotas", () => {
83+
it("distinguishes turn quotas from metered credits", () => {
84+
expect(formatTurnQuotas({ anyBuildsRemaining: 5, cheapBuildsRemaining: 3 })).toEqual([
85+
"Any-model turn quota remaining: 5",
86+
"Low-cost model turn quota remaining: 3",
87+
"Metered runs require both an eligible turn and credits; builds that fail final QA are not charged.",
88+
]);
89+
});
90+
91+
it("omits quota guidance when the endpoint returns no turn pools", () => {
92+
expect(formatTurnQuotas({ creditsRemaining: 12 })).toEqual([]);
93+
});
94+
});
95+
8296
describe("fetchUsageReport", () => {
8397
it("prints the login hint when no Codebase session exists", async () => {
8498
isolateHome();

src/commands/builtins/usage.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ interface Balance {
2424
*/
2525
export const usage: Command = {
2626
name: "usage",
27-
description: "Show metered credits and included Codebase turn allowances.",
27+
description: "Show metered credits and Codebase turn quotas.",
2828
handler: async (_args, ctx) => {
2929
ctx.emit(await fetchUsageReport());
3030
return { handled: true };
@@ -67,18 +67,27 @@ export async function fetchUsageReport(): Promise<string> {
6767
} else {
6868
lines.push("Monthly allowance was not returned yet; showing remaining credits only.");
6969
}
70-
if (typeof b.anyBuildsRemaining === "number" && b.anyBuildsRemaining >= 0) {
71-
lines.push(`Included web-build turns remaining: ${b.anyBuildsRemaining.toLocaleString()}`);
72-
}
73-
if (typeof b.cheapBuildsRemaining === "number" && b.cheapBuildsRemaining >= 0) {
74-
lines.push(`Included fast coding turns remaining: ${b.cheapBuildsRemaining.toLocaleString()}`);
75-
}
70+
lines.push(...formatTurnQuotas(b));
7671
return lines.join("\n");
7772
} catch (err) {
7873
return `Couldn't fetch usage: ${(err as Error).message}`;
7974
}
8075
}
8176

77+
export function formatTurnQuotas(b: Balance): string[] {
78+
const lines: string[] = [];
79+
if (typeof b.anyBuildsRemaining === "number" && b.anyBuildsRemaining >= 0) {
80+
lines.push(`Any-model turn quota remaining: ${b.anyBuildsRemaining.toLocaleString()}`);
81+
}
82+
if (typeof b.cheapBuildsRemaining === "number" && b.cheapBuildsRemaining >= 0) {
83+
lines.push(`Low-cost model turn quota remaining: ${b.cheapBuildsRemaining.toLocaleString()}`);
84+
}
85+
if (lines.length > 0) {
86+
lines.push("Metered runs require both an eligible turn and credits; builds that fail final QA are not charged.");
87+
}
88+
return lines;
89+
}
90+
8291
export function formatUsageBalance(b: Balance): {
8392
creditLine: string;
8493
days: number | null;

0 commit comments

Comments
 (0)