feat(cc-config,lanes): per-profile quota, and three fixes that made a write look lost

Closes #19, #20, #21, #27.

#19 — a saved auth profile now reports how much of its account's quota is
already spent, which is the only number that decides which one is worth
switching to. Nothing under CLAUDE_HOME records it, so it comes from the same
endpoint the CLI's own /usage reads, answered for whichever account's OAuth
token is presented. It is a POST and a button, never a poll: every profile that
is not the active one is normally expired, so answering means refreshing it
first, and a refresh ROTATES the stored refresh token. The rotated pair is
written straight back — dropping it would leave the profile holding a
credential Anthropic has already retired, i.e. an account needing a fresh
login. The token is read, put in an Authorization header, and never returned,
logged or echoed; what leaves the server is two percentages and two reset
times.

#20 — a settings patch that changes nothing wrote nothing but still took a
timestamped backup, so opening the config panel quietly grew a backup
directory inside every lane. patchSettings now compares the rendered output
with what is already on disk and returns early, fixed once where all callers
route through. A lane's git exclude also picks up .claude/.cc-config-backups/
beside settings.local.json.

#21 — the router apply route was the only mutating lane route that never
broadcast its lane. The write reached disk and the column, but the client's
cached row kept the old router_profile forever: the picker looked right until
the user switched lanes and back, at which point the effect re-read the stale
row and flipped the selection to the previous profile. One broadcastLane, plus
a lane-switch guard so an apply that resolves after the user has moved on no
longer paints its result onto whichever lane is now on screen.

#27 — Add-lane in worktree mode left the dialog up after a clean setup with a
dead confirm button and no obvious way out. It closes itself when nothing
failed, and when something did, the summary stays and the confirm becomes a
real Close.
This commit is contained in:
2026-09-17 22:20:32 +07:00
parent b0e8368c1d
commit 5ba9e07d78
25 changed files with 1169 additions and 30 deletions
+87
View File
@@ -1297,6 +1297,25 @@ const schemas = {
},
},
},
CcConfigUsageWindow: {
type: "object",
nullable: true,
description: "One quota window as the account reports it.",
properties: {
utilization: {
type: "number",
nullable: true,
description: "Percent of the window's allowance already spent, 0-100.",
example: 48,
},
resetsAt: {
type: "string",
format: "date-time",
nullable: true,
description: "When the window rolls over, when the account reports one.",
},
},
},
};
// ── Reusable parameters (inlined per-operation to match base style) ────
@@ -2649,6 +2668,74 @@ const paths = {
},
},
},
"/api/cc-config/profiles/usage": {
post: {
tags: ["CcConfig"],
summary: "How much of a saved profile's account quota is already spent",
description:
"Answers `{ name, refreshed, fiveHour, sevenDay, checkedAt }`, each window being `{ utilization, resetsAt }` - a percentage and a rollover time. There is no local source for it: nothing under `CLAUDE_HOME` records a utilization and the credentials file carries only `subscriptionType`/`rateLimitTier`, so the server asks the endpoint the CLI's own `/usage` reads (`GET https://api.anthropic.com/api/oauth/usage`) with that profile's OAuth token.\n\nA POST, and behind the same-origin guard, because answering it is a WRITE. A saved profile's access token lasts hours, so every profile that is not the active one is normally expired; reading its usage refreshes it first, and the refresh ROTATES the stored credentials - Anthropic retires the refresh token it was handed. The new pair is written straight back into the profile file, because a refresh whose result is dropped leaves an account that can never be activated again without a fresh `claude auth login`. A still-valid token is used as-is and nothing is rewritten; a token that looks valid but is refused is retried once through the refresh. Nothing calls this on a timer - it is one profile per user request. The OAuth token is sent to Anthropic and nowhere else, and never appears in the response.",
operationId: "ccConfigProfileUsage",
requestBody: {
required: true,
content: {
"application/json": {
schema: {
type: "object",
required: ["name"],
properties: { name: { type: "string", example: "work" } },
},
},
},
},
responses: {
200: {
description: "Percentages and reset times for the two quota windows.",
content: {
"application/json": {
schema: {
type: "object",
properties: {
name: { type: "string" },
refreshed: {
type: "boolean",
description: "True when the stored token was expired and had to be rotated.",
},
fiveHour: { $ref: "#/components/schemas/CcConfigUsageWindow" },
sevenDay: { $ref: "#/components/schemas/CcConfigUsageWindow" },
checkedAt: { type: "string", format: "date-time" },
},
},
},
},
},
401: {
description: "`EUNAUTHORIZED` - the account refused the token even after a refresh.",
content: {
"application/json": { schema: { $ref: "#/components/schemas/ErrorResponse" } },
},
},
404: {
description: "`ENOTFOUND` - no profile by that name.",
content: {
"application/json": { schema: { $ref: "#/components/schemas/ErrorResponse" } },
},
},
409: {
description:
"`ENOREFRESH`/`ENOAUTH` - the profile holds no usable token; re-save it from a login.",
content: {
"application/json": { schema: { $ref: "#/components/schemas/ErrorResponse" } },
},
},
502: {
description: "`EUPSTREAM` - Anthropic's token or usage endpoint did not cooperate.",
content: {
"application/json": { schema: { $ref: "#/components/schemas/ErrorResponse" } },
},
},
},
},
},
};
module.exports = { tags, schemas, paths };