cc-api-statusline 0.1.9 → 0.2.1
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/README.md +2 -2
- package/dist/cc-api-statusline.js +47 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -513,7 +513,7 @@ bun run start
|
|
|
513
513
|
bun run example
|
|
514
514
|
|
|
515
515
|
# Run tests
|
|
516
|
-
bun test
|
|
516
|
+
bun run test
|
|
517
517
|
|
|
518
518
|
# Lint
|
|
519
519
|
bun run lint
|
|
@@ -577,7 +577,7 @@ bun run check
|
|
|
577
577
|
|
|
578
578
|
## Testing
|
|
579
579
|
|
|
580
|
-
- **
|
|
580
|
+
- **578 tests** across **34 test files**
|
|
581
581
|
- Unit tests for all services, renderers, and shared utilities
|
|
582
582
|
- Core execution path tests (A/B/C/D)
|
|
583
583
|
- E2E smoke tests with isolated environments
|
|
@@ -4,7 +4,7 @@ var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
|
4
4
|
// package.json
|
|
5
5
|
var package_default = {
|
|
6
6
|
name: "cc-api-statusline",
|
|
7
|
-
version: "0.1
|
|
7
|
+
version: "0.2.1",
|
|
8
8
|
description: "Claude Code statusline tool that polls API usage from third-party proxy backends",
|
|
9
9
|
type: "module",
|
|
10
10
|
bin: {
|
|
@@ -410,11 +410,13 @@ var DEFAULT_CONFIG = {
|
|
|
410
410
|
},
|
|
411
411
|
colors: {
|
|
412
412
|
auto: {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
413
|
+
tiers: [
|
|
414
|
+
{ color: "cool", maxPercent: 30 },
|
|
415
|
+
{ color: "comfortable", maxPercent: 65 },
|
|
416
|
+
{ color: "warm", maxPercent: 80 },
|
|
417
|
+
{ color: "hot", maxPercent: 90 },
|
|
418
|
+
{ color: "critical", maxPercent: 100 }
|
|
419
|
+
]
|
|
418
420
|
},
|
|
419
421
|
chill: {
|
|
420
422
|
low: "cyan",
|
|
@@ -1497,11 +1499,22 @@ var ANSI_COLORS = {
|
|
|
1497
1499
|
gray: "\x1B[90m",
|
|
1498
1500
|
grey: "\x1B[90m"
|
|
1499
1501
|
};
|
|
1502
|
+
var THEME_COLORS = {
|
|
1503
|
+
cool: "#56B6C2",
|
|
1504
|
+
comfortable: "#6BAF8D",
|
|
1505
|
+
warm: "#C9A84C",
|
|
1506
|
+
hot: "#CB7E55",
|
|
1507
|
+
critical: "#C96B6B"
|
|
1508
|
+
};
|
|
1500
1509
|
var ANSI_RESET = "\x1B[0m";
|
|
1501
1510
|
var ANSI_DIM = "\x1B[2m";
|
|
1502
1511
|
function ansiColor(text, color, capabilities) {
|
|
1503
1512
|
if (!color)
|
|
1504
1513
|
return text;
|
|
1514
|
+
const themeHex = THEME_COLORS[color.toLowerCase()];
|
|
1515
|
+
if (themeHex) {
|
|
1516
|
+
return ansiColor(text, themeHex, capabilities);
|
|
1517
|
+
}
|
|
1505
1518
|
if (ANSI_COLORS[color.toLowerCase()]) {
|
|
1506
1519
|
return `${ANSI_COLORS[color.toLowerCase()]}${text}${ANSI_RESET}`;
|
|
1507
1520
|
}
|
|
@@ -1601,9 +1614,28 @@ function resolveColor(colorName, usagePercent, config) {
|
|
|
1601
1614
|
}
|
|
1602
1615
|
return resolveColorAlias(alias, usagePercent);
|
|
1603
1616
|
}
|
|
1617
|
+
function isTieredEntry(alias) {
|
|
1618
|
+
return "tiers" in alias;
|
|
1619
|
+
}
|
|
1620
|
+
function resolveTieredColor(entry, usagePercent) {
|
|
1621
|
+
if (entry.tiers.length === 0)
|
|
1622
|
+
return null;
|
|
1623
|
+
if (usagePercent === null) {
|
|
1624
|
+
return entry.tiers[0]?.color ?? null;
|
|
1625
|
+
}
|
|
1626
|
+
for (const tier of entry.tiers) {
|
|
1627
|
+
if (usagePercent < tier.maxPercent) {
|
|
1628
|
+
return tier.color;
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
return entry.tiers[entry.tiers.length - 1]?.color ?? null;
|
|
1632
|
+
}
|
|
1604
1633
|
function resolveColorAlias(alias, usagePercent) {
|
|
1605
1634
|
if (!alias)
|
|
1606
1635
|
return null;
|
|
1636
|
+
if (isTieredEntry(alias)) {
|
|
1637
|
+
return resolveTieredColor(alias, usagePercent);
|
|
1638
|
+
}
|
|
1607
1639
|
if (usagePercent === null) {
|
|
1608
1640
|
return alias.low;
|
|
1609
1641
|
}
|
|
@@ -2005,7 +2037,7 @@ function renderQuotaComponent(componentId, quota, layout, displayMode, progressS
|
|
|
2005
2037
|
const valueColor = resolvePartColor("value", usagePercent, componentConfig, globalConfig);
|
|
2006
2038
|
const labelColor = resolvePartColor("label", usagePercent, componentConfig, globalConfig);
|
|
2007
2039
|
const countdownColor = resolvePartColor("countdown", usagePercent, componentConfig, globalConfig);
|
|
2008
|
-
const progress = renderProgress(progressStyle, usagePercent, barSize, barStyle, barColor, null);
|
|
2040
|
+
const progress = renderProgress(progressStyle, usagePercent, barSize, barStyle, barColor, null, renderContext);
|
|
2009
2041
|
const value = ansiColor(`${Math.round(usagePercent)}%`, valueColor, renderContext);
|
|
2010
2042
|
const countdown = renderSecondaryDisplay(quota.resetsAt, quota, componentConfig.countdown, countdownColor, clockFormat, renderContext);
|
|
2011
2043
|
return assembleComponent(layout, label, labelColor, progress, value, countdown, renderContext);
|
|
@@ -2023,7 +2055,7 @@ function renderBalanceComponent(balance, layout, displayMode, progressStyle, bar
|
|
|
2023
2055
|
const barColor = resolvePartColor("bar", effectivePercent, componentConfig, globalConfig);
|
|
2024
2056
|
const valueColor = resolvePartColor("value", effectivePercent, componentConfig, globalConfig);
|
|
2025
2057
|
const labelColor = resolvePartColor("label", effectivePercent, componentConfig, globalConfig);
|
|
2026
|
-
const progress = isUnlimited ? "" : renderProgress(progressStyle, effectivePercent ?? 0, barSize, barStyle, barColor, null);
|
|
2058
|
+
const progress = isUnlimited ? "" : renderProgress(progressStyle, effectivePercent ?? 0, barSize, barStyle, barColor, null, renderContext);
|
|
2027
2059
|
const valueText = isUnlimited ? "∞" : `$${balance.remaining.toFixed(2)}`;
|
|
2028
2060
|
const value = ansiColor(valueText, valueColor, renderContext);
|
|
2029
2061
|
const countdown = "";
|
|
@@ -2056,7 +2088,7 @@ function renderRateLimitComponent(rateLimit, layout, displayMode, progressStyle,
|
|
|
2056
2088
|
const barColor = resolvePartColor("bar", usagePercent, componentConfig, globalConfig);
|
|
2057
2089
|
const valueColor = resolvePartColor("value", usagePercent, componentConfig, globalConfig);
|
|
2058
2090
|
const labelColor = resolvePartColor("label", usagePercent, componentConfig, globalConfig);
|
|
2059
|
-
const progress = usagePercent !== null ? renderProgress(progressStyle, usagePercent, barSize, barStyle, barColor, null) : "";
|
|
2091
|
+
const progress = usagePercent !== null ? renderProgress(progressStyle, usagePercent, barSize, barStyle, barColor, null, renderContext) : "";
|
|
2060
2092
|
const valueText = rateLimit.requestsLimit !== null ? `${rateLimit.requestsUsed}/${rateLimit.requestsLimit}` : `${rateLimit.requestsUsed}`;
|
|
2061
2093
|
const value = ansiColor(valueText, valueColor, renderContext);
|
|
2062
2094
|
const countdown = "";
|
|
@@ -2127,12 +2159,14 @@ function renderLabel(componentId, displayMode, componentConfig, qualifier) {
|
|
|
2127
2159
|
}
|
|
2128
2160
|
return baseLabel;
|
|
2129
2161
|
}
|
|
2130
|
-
function renderProgress(progressStyle, usagePercent, barSize, barStyle, barColor, emptyColor) {
|
|
2162
|
+
function renderProgress(progressStyle, usagePercent, barSize, barStyle, barColor, emptyColor, renderContext) {
|
|
2131
2163
|
switch (progressStyle) {
|
|
2132
2164
|
case "bar":
|
|
2133
2165
|
return renderBar(usagePercent, barSize, barStyle, barColor, emptyColor);
|
|
2134
|
-
case "icon":
|
|
2135
|
-
|
|
2166
|
+
case "icon": {
|
|
2167
|
+
const icon = getProgressIcon(usagePercent, true);
|
|
2168
|
+
return ansiColor(icon, barColor, renderContext);
|
|
2169
|
+
}
|
|
2136
2170
|
case "hidden":
|
|
2137
2171
|
return "";
|
|
2138
2172
|
default:
|
|
@@ -2276,7 +2310,7 @@ function renderDivider(divider) {
|
|
|
2276
2310
|
const padding = divider.padding ?? 1;
|
|
2277
2311
|
const pad = " ".repeat(padding);
|
|
2278
2312
|
const padded = `${pad}${text}${pad}`;
|
|
2279
|
-
return
|
|
2313
|
+
return ansiColor(padded, divider.color ?? "#555753");
|
|
2280
2314
|
}
|
|
2281
2315
|
|
|
2282
2316
|
// src/services/capabilities.ts
|