@sideboard-ai/core 0.1.198 → 0.1.199
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/{abletime-JINF5KJV.js → abletime-3CSCNAXU.js} +2 -2
- package/dist/{abletime-HR6P4GJH.js → abletime-H74RNIKV.js} +2 -2
- package/dist/{agents-AQQKPD46.js → agents-AVH44CBS.js} +26 -4
- package/dist/{agents-5TZY6LLX.js → agents-BOYOK56K.js} +26 -4
- package/dist/{app-settings-J775CYOO.js → app-settings-FMTDH5RD.js} +3 -1
- package/dist/{app-settings-5KHVKJKO.js → app-settings-MMPLJHWF.js} +3 -1
- package/dist/{chunk-S5GLSRLP.js → chunk-2IQ6W47G.js} +10 -0
- package/dist/{chunk-HZTHWU6A.js → chunk-BLOKJY4U.js} +2 -2
- package/dist/{chunk-E37JHCO3.js → chunk-CA7PWMQ7.js} +1 -1
- package/dist/{chunk-DROELG52.js → chunk-CTABTALL.js} +19 -19
- package/dist/{chunk-SYXSSU7G.js → chunk-DU2ICKLA.js} +355 -4
- package/dist/{chunk-S4QCBBXS.js → chunk-DU4ID3DA.js} +1 -1
- package/dist/{chunk-AH6WIBLY.js → chunk-HQKGK4KO.js} +10 -0
- package/dist/{chunk-EA67VQM2.js → chunk-KI4YI72Y.js} +355 -4
- package/dist/{chunk-6YS5IKD2.js → chunk-PPVN3APP.js} +20 -20
- package/dist/{chunk-KTHRWHA3.js → chunk-PTAMHXBT.js} +1 -1
- package/dist/{chunk-DP4TKAMZ.js → chunk-QFABSE3Q.js} +1 -1
- package/dist/{chunk-6YTI2HBG.js → chunk-S4EEYOSU.js} +2 -2
- package/dist/{coordinator-prompt-IX66YUJ2.js → coordinator-prompt-LB3GA3U4.js} +3 -3
- package/dist/{coordinator-prompt-LYKS3YNG.js → coordinator-prompt-ROWPLVQ3.js} +3 -3
- package/dist/{global-workspace-SNJ2Z6SL.js → global-workspace-C5XKWCRH.js} +3 -3
- package/dist/{global-workspace-4QX6UEOY.js → global-workspace-V2A4YKZ6.js} +3 -3
- package/dist/index.cjs +660 -258
- package/dist/index.d.cts +78 -1
- package/dist/index.d.ts +78 -1
- package/dist/index.js +32 -8
- package/dist/mcp/run-stdio.cjs +289 -254
- package/dist/mcp/run-stdio.js +8 -8
- package/dist/{orchestrator-L2H42HPW.js → orchestrator-AJGDZEAS.js} +5 -5
- package/dist/{orchestrator-6ZNKCPNL.js → orchestrator-NCGYNVYN.js} +5 -5
- package/dist/{workspaces-URMUVGAQ.js → workspaces-GWEKIS3B.js} +3 -3
- package/dist/{workspaces-UTOYGBYB.js → workspaces-WIRJQ6HA.js} +3 -3
- package/dist/{worktree-RM6UWNGZ.js → worktree-QA4J75FI.js} +2 -2
- package/dist/{worktree-R43JOR4V.js → worktree-UI5WJC3A.js} +2 -2
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
isOrchestratorThread
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-S4EEYOSU.js";
|
|
6
6
|
import {
|
|
7
7
|
applyConnectedTeamToCli,
|
|
8
8
|
brightsyMcpServerName,
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
mergeAgentGitAuthEnv,
|
|
18
18
|
resolveAgentGitAuthEnv,
|
|
19
19
|
resolveCodexGitWritableRoots
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-QFABSE3Q.js";
|
|
21
21
|
import {
|
|
22
22
|
enrichPathWithNpmGlobalBin,
|
|
23
23
|
isConductorBundledCli,
|
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
resolveClaudeExecutable,
|
|
36
36
|
unwrapStrippedElectronLaunch,
|
|
37
37
|
wrapElectronAsNodeLaunch
|
|
38
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-HQKGK4KO.js";
|
|
39
39
|
import {
|
|
40
40
|
appDataDir
|
|
41
41
|
} from "./chunk-EQNRWDLN.js";
|
|
@@ -2420,7 +2420,7 @@ var claudeAdapter = {
|
|
|
2420
2420
|
);
|
|
2421
2421
|
}
|
|
2422
2422
|
const mode = permissionMode(thread);
|
|
2423
|
-
const { isOrchestratorThread: isOrchestratorThread2 } = await import("./global-workspace-
|
|
2423
|
+
const { isOrchestratorThread: isOrchestratorThread2 } = await import("./global-workspace-C5XKWCRH.js");
|
|
2424
2424
|
const isOrchestrator = isOrchestratorThread2(thread);
|
|
2425
2425
|
const injectedServers = await buildInjectedMcpServers({
|
|
2426
2426
|
includeSideboard: true,
|
|
@@ -4122,6 +4122,346 @@ function resolveQuotaFallbackAgent(current, preferred) {
|
|
|
4122
4122
|
return ordered.find((a) => a !== current) ?? (current === "cursor" ? "codex" : "cursor");
|
|
4123
4123
|
}
|
|
4124
4124
|
|
|
4125
|
+
// src/agents/claude-usage.ts
|
|
4126
|
+
var WINDOW_META = {
|
|
4127
|
+
five_hour: {
|
|
4128
|
+
label: "5-hour session",
|
|
4129
|
+
shortLabel: "5h",
|
|
4130
|
+
detail: "Rolling 5-hour limit across all models"
|
|
4131
|
+
},
|
|
4132
|
+
seven_day: {
|
|
4133
|
+
label: "Weekly",
|
|
4134
|
+
shortLabel: "wk",
|
|
4135
|
+
detail: "7-day cap across all models"
|
|
4136
|
+
},
|
|
4137
|
+
seven_day_opus: {
|
|
4138
|
+
label: "Opus",
|
|
4139
|
+
shortLabel: "Opus",
|
|
4140
|
+
detail: "Weekly Opus-only cap"
|
|
4141
|
+
},
|
|
4142
|
+
seven_day_sonnet: {
|
|
4143
|
+
label: "Sonnet",
|
|
4144
|
+
shortLabel: "Sonnet",
|
|
4145
|
+
detail: "Weekly Sonnet-only cap"
|
|
4146
|
+
}
|
|
4147
|
+
};
|
|
4148
|
+
var WINDOW_ORDER = [
|
|
4149
|
+
"five_hour",
|
|
4150
|
+
"seven_day",
|
|
4151
|
+
"seven_day_opus",
|
|
4152
|
+
"seven_day_sonnet"
|
|
4153
|
+
];
|
|
4154
|
+
function parseClaudeResetsAt(value) {
|
|
4155
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
4156
|
+
const ms = value > 1e12 ? value : value * 1e3;
|
|
4157
|
+
const d = new Date(ms);
|
|
4158
|
+
return Number.isNaN(d.getTime()) ? null : d.toISOString();
|
|
4159
|
+
}
|
|
4160
|
+
if (typeof value === "string") {
|
|
4161
|
+
const trimmed = value.trim();
|
|
4162
|
+
if (!trimmed) return null;
|
|
4163
|
+
if (/^\d+(\.\d+)?$/.test(trimmed)) {
|
|
4164
|
+
return parseClaudeResetsAt(Number(trimmed));
|
|
4165
|
+
}
|
|
4166
|
+
const d = new Date(trimmed);
|
|
4167
|
+
return Number.isNaN(d.getTime()) ? null : d.toISOString();
|
|
4168
|
+
}
|
|
4169
|
+
return null;
|
|
4170
|
+
}
|
|
4171
|
+
function parseClaudeUtilization(value) {
|
|
4172
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return null;
|
|
4173
|
+
return Math.max(0, Math.min(100, value));
|
|
4174
|
+
}
|
|
4175
|
+
function windowFromRaw(id, raw) {
|
|
4176
|
+
if (!raw || typeof raw !== "object") return null;
|
|
4177
|
+
const row = raw;
|
|
4178
|
+
const used = parseClaudeUtilization(row.utilization ?? row.used_percentage);
|
|
4179
|
+
if (used == null) return null;
|
|
4180
|
+
const meta = WINDOW_META[id];
|
|
4181
|
+
return {
|
|
4182
|
+
id,
|
|
4183
|
+
label: meta.label,
|
|
4184
|
+
shortLabel: meta.shortLabel,
|
|
4185
|
+
detail: meta.detail,
|
|
4186
|
+
usedPercent: used,
|
|
4187
|
+
remainingPercent: Math.max(0, Math.min(100, 100 - used)),
|
|
4188
|
+
resetsAt: parseClaudeResetsAt(row.resets_at)
|
|
4189
|
+
};
|
|
4190
|
+
}
|
|
4191
|
+
function extraUsageFromRaw(raw) {
|
|
4192
|
+
if (!raw || typeof raw !== "object") return void 0;
|
|
4193
|
+
const row = raw;
|
|
4194
|
+
const enabled = row.is_enabled === true || row.enabled === true;
|
|
4195
|
+
if (!enabled && row.is_enabled !== false && row.enabled !== false) return void 0;
|
|
4196
|
+
const usedCredits = numberOrUndef(row.used_credits ?? row.used);
|
|
4197
|
+
const monthlyLimit = numberOrUndef(row.monthly_limit);
|
|
4198
|
+
const usedPercent = parseClaudeUtilization(row.utilization) ?? void 0;
|
|
4199
|
+
return {
|
|
4200
|
+
enabled,
|
|
4201
|
+
...usedCredits != null ? { usedCredits } : {},
|
|
4202
|
+
...monthlyLimit != null ? { monthlyLimit } : {},
|
|
4203
|
+
...usedPercent != null ? { usedPercent } : {}
|
|
4204
|
+
};
|
|
4205
|
+
}
|
|
4206
|
+
function numberOrUndef(value) {
|
|
4207
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return void 0;
|
|
4208
|
+
return value;
|
|
4209
|
+
}
|
|
4210
|
+
function parseClaudeUsagePayload(raw, fetchedAt = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
4211
|
+
if (!raw || typeof raw !== "object") return null;
|
|
4212
|
+
const obj = raw;
|
|
4213
|
+
const source = obj.rate_limits && typeof obj.rate_limits === "object" ? obj.rate_limits : obj;
|
|
4214
|
+
const windows = [];
|
|
4215
|
+
for (const id of WINDOW_ORDER) {
|
|
4216
|
+
const parsed = windowFromRaw(id, source[id]);
|
|
4217
|
+
if (parsed) windows.push(parsed);
|
|
4218
|
+
}
|
|
4219
|
+
if (windows.length === 0) return null;
|
|
4220
|
+
const extra = extraUsageFromRaw(obj.extra_usage ?? source.extra_usage);
|
|
4221
|
+
return {
|
|
4222
|
+
windows,
|
|
4223
|
+
...extra ? { extraUsage: extra } : {},
|
|
4224
|
+
fetchedAt
|
|
4225
|
+
};
|
|
4226
|
+
}
|
|
4227
|
+
function hottestClaudeWindow(usage) {
|
|
4228
|
+
if (usage.windows.length === 0) return null;
|
|
4229
|
+
return usage.windows.reduce((a, b) => b.usedPercent > a.usedPercent ? b : a);
|
|
4230
|
+
}
|
|
4231
|
+
function formatClaudeUsageReset(resetsAt, now = /* @__PURE__ */ new Date()) {
|
|
4232
|
+
if (!resetsAt) return "";
|
|
4233
|
+
const at = new Date(resetsAt);
|
|
4234
|
+
if (Number.isNaN(at.getTime())) return "";
|
|
4235
|
+
const ms = at.getTime() - now.getTime();
|
|
4236
|
+
if (ms <= 0) return "resets soon";
|
|
4237
|
+
const minutes = Math.round(ms / 6e4);
|
|
4238
|
+
if (minutes < 60) return `resets in ${Math.max(1, minutes)}m`;
|
|
4239
|
+
const hours = Math.round(minutes / 60);
|
|
4240
|
+
if (hours < 36) return `resets in ${hours}h`;
|
|
4241
|
+
try {
|
|
4242
|
+
return `resets ${at.toLocaleString(void 0, {
|
|
4243
|
+
weekday: "short",
|
|
4244
|
+
hour: "numeric",
|
|
4245
|
+
minute: "2-digit"
|
|
4246
|
+
})}`;
|
|
4247
|
+
} catch {
|
|
4248
|
+
return `resets ${at.toISOString()}`;
|
|
4249
|
+
}
|
|
4250
|
+
}
|
|
4251
|
+
function formatClaudeUsageResetClock(resetsAt) {
|
|
4252
|
+
if (!resetsAt) return "";
|
|
4253
|
+
const at = new Date(resetsAt);
|
|
4254
|
+
if (Number.isNaN(at.getTime())) return "";
|
|
4255
|
+
try {
|
|
4256
|
+
return at.toLocaleString(void 0, {
|
|
4257
|
+
weekday: "short",
|
|
4258
|
+
month: "short",
|
|
4259
|
+
day: "numeric",
|
|
4260
|
+
hour: "numeric",
|
|
4261
|
+
minute: "2-digit"
|
|
4262
|
+
});
|
|
4263
|
+
} catch {
|
|
4264
|
+
return at.toISOString();
|
|
4265
|
+
}
|
|
4266
|
+
}
|
|
4267
|
+
function formatClaudeUsageFetchedAt(fetchedAt, now = /* @__PURE__ */ new Date()) {
|
|
4268
|
+
const at = new Date(fetchedAt);
|
|
4269
|
+
if (Number.isNaN(at.getTime())) return "";
|
|
4270
|
+
const minutes = Math.max(0, Math.round((now.getTime() - at.getTime()) / 6e4));
|
|
4271
|
+
if (minutes < 1) return "Updated just now";
|
|
4272
|
+
if (minutes < 60) return `Updated ${minutes}m ago`;
|
|
4273
|
+
const hours = Math.round(minutes / 60);
|
|
4274
|
+
if (hours < 36) return `Updated ${hours}h ago`;
|
|
4275
|
+
return `Updated ${formatClaudeUsageResetClock(fetchedAt)}`;
|
|
4276
|
+
}
|
|
4277
|
+
function formatClaudeExtraUsageDetail(extra) {
|
|
4278
|
+
if (!extra.enabled) return "Extra usage off";
|
|
4279
|
+
const bits = ["Extra usage on"];
|
|
4280
|
+
if (extra.usedCredits != null && extra.monthlyLimit != null) {
|
|
4281
|
+
bits.push(`${extra.usedCredits} / ${extra.monthlyLimit} credits this month`);
|
|
4282
|
+
} else if (extra.usedCredits != null) {
|
|
4283
|
+
bits.push(`${extra.usedCredits} credits used`);
|
|
4284
|
+
}
|
|
4285
|
+
if (extra.usedPercent != null) {
|
|
4286
|
+
bits.push(`${Math.round(extra.usedPercent)}% of extra pool`);
|
|
4287
|
+
}
|
|
4288
|
+
return bits.join(" \xB7 ");
|
|
4289
|
+
}
|
|
4290
|
+
function formatClaudeUsageWindowLine(window, now = /* @__PURE__ */ new Date()) {
|
|
4291
|
+
const reset = formatClaudeUsageReset(window.resetsAt, now);
|
|
4292
|
+
const clock = formatClaudeUsageResetClock(window.resetsAt);
|
|
4293
|
+
const left = `${Math.round(window.remainingPercent)}% left`;
|
|
4294
|
+
const used = `${Math.round(window.usedPercent)}% used`;
|
|
4295
|
+
const resetBit = reset ? clock && !reset.includes(clock) ? `${reset} (${clock})` : reset : "";
|
|
4296
|
+
return resetBit ? `${window.label} \u2014 ${window.detail}. ${left} \xB7 ${used} \xB7 ${resetBit}` : `${window.label} \u2014 ${window.detail}. ${left} \xB7 ${used}`;
|
|
4297
|
+
}
|
|
4298
|
+
function formatClaudeUsageTooltip(usage, now = /* @__PURE__ */ new Date()) {
|
|
4299
|
+
const lines = [
|
|
4300
|
+
"Claude Code plan",
|
|
4301
|
+
...usage.windows.map((w) => formatClaudeUsageWindowLine(w, now))
|
|
4302
|
+
];
|
|
4303
|
+
if (usage.extraUsage) {
|
|
4304
|
+
lines.push(formatClaudeExtraUsageDetail(usage.extraUsage));
|
|
4305
|
+
}
|
|
4306
|
+
const fetched = formatClaudeUsageFetchedAt(usage.fetchedAt, now);
|
|
4307
|
+
if (fetched) lines.push(fetched);
|
|
4308
|
+
return lines.join("\n");
|
|
4309
|
+
}
|
|
4310
|
+
function formatClaudeUsageCompact(window) {
|
|
4311
|
+
return `${window.shortLabel} ${Math.round(window.remainingPercent)}%`;
|
|
4312
|
+
}
|
|
4313
|
+
function claudeUsageWindowOverLimit(window) {
|
|
4314
|
+
return window.remainingPercent <= 0 || window.usedPercent >= 100;
|
|
4315
|
+
}
|
|
4316
|
+
function claudeUsageOverLimitWindows(usage) {
|
|
4317
|
+
if (!usage) return [];
|
|
4318
|
+
return usage.windows.filter(claudeUsageWindowOverLimit);
|
|
4319
|
+
}
|
|
4320
|
+
function formatClaudeUsageOverLimitConfirm(windows, now = /* @__PURE__ */ new Date()) {
|
|
4321
|
+
if (windows.length === 0) return "";
|
|
4322
|
+
const parts = windows.map((w) => {
|
|
4323
|
+
const reset = formatClaudeUsageReset(w.resetsAt, now);
|
|
4324
|
+
return reset ? `${w.label} (${reset})` : w.label;
|
|
4325
|
+
});
|
|
4326
|
+
const list = parts.join(", ");
|
|
4327
|
+
const verb = windows.length === 1 ? "is" : "are";
|
|
4328
|
+
return `Claude Code ${list} ${verb} at or over the plan limit. Send this message anyway?`;
|
|
4329
|
+
}
|
|
4330
|
+
|
|
4331
|
+
// src/agents/claude-usage-client.ts
|
|
4332
|
+
import { existsSync as existsSync13, readFileSync as readFileSync5 } from "fs";
|
|
4333
|
+
import { homedir as homedir5 } from "os";
|
|
4334
|
+
import { join as join10 } from "path";
|
|
4335
|
+
var CLAUDE_OAUTH_USAGE_URL = "https://api.anthropic.com/api/oauth/usage";
|
|
4336
|
+
var CLAUDE_USAGE_TTL_MS = 9e4;
|
|
4337
|
+
var CLAUDE_USAGE_ERROR_TTL_MS = 5 * 6e4;
|
|
4338
|
+
var CLAUDE_USAGE_STALE_OK_MS = 30 * 6e4;
|
|
4339
|
+
var KEYCHAIN_SERVICES = ["Claude Code-credentials", "Claude Code"];
|
|
4340
|
+
var cache = null;
|
|
4341
|
+
var errorUntil = 0;
|
|
4342
|
+
var inflight = null;
|
|
4343
|
+
var lastGood = null;
|
|
4344
|
+
var claudeVersion = null;
|
|
4345
|
+
function accessTokenFromCredentialsJson(raw) {
|
|
4346
|
+
const trimmed = raw.trim();
|
|
4347
|
+
if (!trimmed) return null;
|
|
4348
|
+
if (trimmed.startsWith("sk-ant-")) {
|
|
4349
|
+
const token = trimmed.split(/\s+/)[0];
|
|
4350
|
+
return token || null;
|
|
4351
|
+
}
|
|
4352
|
+
try {
|
|
4353
|
+
const parsed = JSON.parse(trimmed);
|
|
4354
|
+
const oauth = parsed.claudeAiOauth && typeof parsed.claudeAiOauth === "object" ? parsed.claudeAiOauth : parsed;
|
|
4355
|
+
const token = oauth.accessToken ?? oauth.access_token;
|
|
4356
|
+
return typeof token === "string" && token.trim() ? token.trim() : null;
|
|
4357
|
+
} catch {
|
|
4358
|
+
return null;
|
|
4359
|
+
}
|
|
4360
|
+
}
|
|
4361
|
+
function claudeCredentialsPath() {
|
|
4362
|
+
const root = process.env.CLAUDE_CONFIG_DIR?.trim() || join10(homedir5(), ".claude");
|
|
4363
|
+
return join10(root, ".credentials.json");
|
|
4364
|
+
}
|
|
4365
|
+
async function readFileAccessToken() {
|
|
4366
|
+
const path = claudeCredentialsPath();
|
|
4367
|
+
if (!existsSync13(path)) return null;
|
|
4368
|
+
try {
|
|
4369
|
+
return accessTokenFromCredentialsJson(readFileSync5(path, "utf8"));
|
|
4370
|
+
} catch {
|
|
4371
|
+
return null;
|
|
4372
|
+
}
|
|
4373
|
+
}
|
|
4374
|
+
async function readKeychainAccessToken() {
|
|
4375
|
+
if (process.platform !== "darwin") return null;
|
|
4376
|
+
for (const service of KEYCHAIN_SERVICES) {
|
|
4377
|
+
const result = await run("security", ["find-generic-password", "-s", service, "-w"], {
|
|
4378
|
+
reject: false,
|
|
4379
|
+
timeoutMs: 4e3
|
|
4380
|
+
});
|
|
4381
|
+
if (result.exitCode !== 0 || !result.stdout.trim()) continue;
|
|
4382
|
+
const token = accessTokenFromCredentialsJson(result.stdout);
|
|
4383
|
+
if (token) return token;
|
|
4384
|
+
}
|
|
4385
|
+
return null;
|
|
4386
|
+
}
|
|
4387
|
+
async function readClaudeAccessToken() {
|
|
4388
|
+
const envToken = process.env.CLAUDE_CODE_OAUTH_TOKEN?.trim();
|
|
4389
|
+
if (envToken) return envToken;
|
|
4390
|
+
const fromFile = await readFileAccessToken();
|
|
4391
|
+
if (fromFile) return fromFile;
|
|
4392
|
+
return readKeychainAccessToken();
|
|
4393
|
+
}
|
|
4394
|
+
async function resolveClaudeUserAgent() {
|
|
4395
|
+
if (claudeVersion) return `claude-code/${claudeVersion}`;
|
|
4396
|
+
try {
|
|
4397
|
+
const claude = resolveClaudeExecutable();
|
|
4398
|
+
const result = await run(claude, ["--version"], { reject: false, timeoutMs: 4e3 });
|
|
4399
|
+
const match = `${result.stdout}
|
|
4400
|
+
${result.stderr}`.match(/(\d+\.\d+\.\d+)/);
|
|
4401
|
+
claudeVersion = match?.[1] ?? "2.1.80";
|
|
4402
|
+
} catch {
|
|
4403
|
+
claudeVersion = "2.1.80";
|
|
4404
|
+
}
|
|
4405
|
+
return `claude-code/${claudeVersion}`;
|
|
4406
|
+
}
|
|
4407
|
+
function staleOk(now) {
|
|
4408
|
+
if (!lastGood) return null;
|
|
4409
|
+
if (now - lastGood.at > CLAUDE_USAGE_STALE_OK_MS) return null;
|
|
4410
|
+
return lastGood.value;
|
|
4411
|
+
}
|
|
4412
|
+
async function getClaudePlanUsage(opts = {}) {
|
|
4413
|
+
const now = opts.now ?? Date.now();
|
|
4414
|
+
if (!opts.force) {
|
|
4415
|
+
if (cache && now - cache.at < CLAUDE_USAGE_TTL_MS) return cache.value;
|
|
4416
|
+
if (now < errorUntil) return staleOk(now);
|
|
4417
|
+
}
|
|
4418
|
+
if (inflight) return inflight;
|
|
4419
|
+
inflight = (async () => {
|
|
4420
|
+
try {
|
|
4421
|
+
const token = await (opts.readAccessToken ?? readClaudeAccessToken)();
|
|
4422
|
+
if (!token) {
|
|
4423
|
+
cache = { at: now, value: null };
|
|
4424
|
+
return null;
|
|
4425
|
+
}
|
|
4426
|
+
const fetchFn = opts.fetch ?? globalThis.fetch;
|
|
4427
|
+
const userAgent = opts.userAgent ?? await resolveClaudeUserAgent();
|
|
4428
|
+
const ac = new AbortController();
|
|
4429
|
+
const timer = setTimeout(() => ac.abort(), 8e3);
|
|
4430
|
+
let res;
|
|
4431
|
+
try {
|
|
4432
|
+
res = await fetchFn(CLAUDE_OAUTH_USAGE_URL, {
|
|
4433
|
+
headers: {
|
|
4434
|
+
Authorization: `Bearer ${token}`,
|
|
4435
|
+
"anthropic-beta": "oauth-2025-04-20",
|
|
4436
|
+
"User-Agent": userAgent
|
|
4437
|
+
},
|
|
4438
|
+
signal: ac.signal
|
|
4439
|
+
});
|
|
4440
|
+
} finally {
|
|
4441
|
+
clearTimeout(timer);
|
|
4442
|
+
}
|
|
4443
|
+
if (res.status === 401 || res.status === 403) {
|
|
4444
|
+
cache = { at: now, value: null };
|
|
4445
|
+
return null;
|
|
4446
|
+
}
|
|
4447
|
+
if (!res.ok) {
|
|
4448
|
+
errorUntil = now + CLAUDE_USAGE_ERROR_TTL_MS;
|
|
4449
|
+
return staleOk(now);
|
|
4450
|
+
}
|
|
4451
|
+
const usage = parseClaudeUsagePayload(await res.json(), new Date(now).toISOString());
|
|
4452
|
+
cache = { at: now, value: usage };
|
|
4453
|
+
if (usage) lastGood = { at: now, value: usage };
|
|
4454
|
+
return usage;
|
|
4455
|
+
} catch {
|
|
4456
|
+
errorUntil = now + CLAUDE_USAGE_ERROR_TTL_MS;
|
|
4457
|
+
return staleOk(now);
|
|
4458
|
+
} finally {
|
|
4459
|
+
inflight = null;
|
|
4460
|
+
}
|
|
4461
|
+
})();
|
|
4462
|
+
return inflight;
|
|
4463
|
+
}
|
|
4464
|
+
|
|
4125
4465
|
// src/agents/install.ts
|
|
4126
4466
|
var SETUP = {
|
|
4127
4467
|
claude: {
|
|
@@ -4426,6 +4766,17 @@ export {
|
|
|
4426
4766
|
isSessionQuotaLimit,
|
|
4427
4767
|
parseSessionQuotaResetAt,
|
|
4428
4768
|
resolveQuotaFallbackAgent,
|
|
4769
|
+
parseClaudeUsagePayload,
|
|
4770
|
+
hottestClaudeWindow,
|
|
4771
|
+
formatClaudeUsageReset,
|
|
4772
|
+
formatClaudeUsageResetClock,
|
|
4773
|
+
formatClaudeUsageFetchedAt,
|
|
4774
|
+
formatClaudeExtraUsageDetail,
|
|
4775
|
+
formatClaudeUsageTooltip,
|
|
4776
|
+
formatClaudeUsageCompact,
|
|
4777
|
+
claudeUsageOverLimitWindows,
|
|
4778
|
+
formatClaudeUsageOverLimitConfirm,
|
|
4779
|
+
getClaudePlanUsage,
|
|
4429
4780
|
getAgentSetupInfo,
|
|
4430
4781
|
listAgentSetupInfo,
|
|
4431
4782
|
resolveLoginCommand,
|
|
@@ -781,6 +781,9 @@ function normalizeAdvanced(raw) {
|
|
|
781
781
|
if (typeof source.showCost === "boolean") {
|
|
782
782
|
out.showCost = source.showCost;
|
|
783
783
|
}
|
|
784
|
+
if (typeof source.confirmClaudeUsageOverLimit === "boolean") {
|
|
785
|
+
out.confirmClaudeUsageOverLimit = source.confirmClaudeUsageOverLimit;
|
|
786
|
+
}
|
|
784
787
|
if (typeof source.autoArchiveOnMerge === "boolean") {
|
|
785
788
|
out.autoArchiveOnMerge = source.autoArchiveOnMerge;
|
|
786
789
|
}
|
|
@@ -1656,6 +1659,9 @@ function updateAdvancedSettings(patch) {
|
|
|
1656
1659
|
if (typeof patch.showCost === "boolean") {
|
|
1657
1660
|
advanced.showCost = patch.showCost;
|
|
1658
1661
|
}
|
|
1662
|
+
if (typeof patch.confirmClaudeUsageOverLimit === "boolean") {
|
|
1663
|
+
advanced.confirmClaudeUsageOverLimit = patch.confirmClaudeUsageOverLimit;
|
|
1664
|
+
}
|
|
1659
1665
|
if (typeof patch.autoArchiveOnMerge === "boolean") {
|
|
1660
1666
|
advanced.autoArchiveOnMerge = patch.autoArchiveOnMerge;
|
|
1661
1667
|
}
|
|
@@ -1718,6 +1724,9 @@ function cowboyModeEnabled(settings = loadAppSettings()) {
|
|
|
1718
1724
|
function showCostEnabled(settings = loadAppSettings()) {
|
|
1719
1725
|
return Boolean(settings.advanced.showCost);
|
|
1720
1726
|
}
|
|
1727
|
+
function confirmClaudeUsageOverLimitEnabled(settings = loadAppSettings()) {
|
|
1728
|
+
return Boolean(settings.advanced.confirmClaudeUsageOverLimit);
|
|
1729
|
+
}
|
|
1721
1730
|
function autoArchiveOnMergeEnabled(settings = loadAppSettings()) {
|
|
1722
1731
|
return Boolean(settings.advanced.autoArchiveOnMerge);
|
|
1723
1732
|
}
|
|
@@ -1917,6 +1926,7 @@ export {
|
|
|
1917
1926
|
deleteBranchOnPurgeEnabled,
|
|
1918
1927
|
cowboyModeEnabled,
|
|
1919
1928
|
showCostEnabled,
|
|
1929
|
+
confirmClaudeUsageOverLimitEnabled,
|
|
1920
1930
|
autoArchiveOnMergeEnabled,
|
|
1921
1931
|
autoCleanupOrphansEnabled,
|
|
1922
1932
|
orchestrationQuotaOnLimit,
|