@jeffreyjyz/opencode-command-code 0.1.4 → 0.1.5
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/index.js +9 -5
- package/dist/usage.d.ts +11 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -549,6 +549,13 @@ function parseIsoUtc(s) {
|
|
|
549
549
|
}
|
|
550
550
|
return Date.UTC(+y, +mo - 1, +d, +h, +mi, Math.floor(+sec)) - offsetMs;
|
|
551
551
|
}
|
|
552
|
+
function monthlyWindow(cap, remaining, periodStart, periodEnd) {
|
|
553
|
+
const used = Math.min(Math.max(cap - remaining, 0), cap);
|
|
554
|
+
const resetAt = periodEnd ? parseIsoUtc(periodEnd) : undefined;
|
|
555
|
+
const start = periodStart ? parseIsoUtc(periodStart) : undefined;
|
|
556
|
+
const durSecs = start !== undefined && resetAt !== undefined ? Math.max(Math.floor((resetAt - start) / 1000), 1) : undefined;
|
|
557
|
+
return { window: { used, cap, resetAt }, durSecs };
|
|
558
|
+
}
|
|
552
559
|
var NAME_RULES = plans_default.nameRules;
|
|
553
560
|
var DEFAULT_NAME = plans_default.defaultName;
|
|
554
561
|
var CAPS = plans_default.caps;
|
|
@@ -611,11 +618,8 @@ async function renderUsage(key) {
|
|
|
611
618
|
}
|
|
612
619
|
lines.push("### Usage windows");
|
|
613
620
|
if (cap) {
|
|
614
|
-
const
|
|
615
|
-
|
|
616
|
-
const start = sub.currentPeriodStart ? parseIsoUtc(sub.currentPeriodStart) : undefined;
|
|
617
|
-
const dur = start !== undefined && resetAt !== undefined ? Math.max(Math.floor((resetAt - start) / 1000), 1) : undefined;
|
|
618
|
-
lines.push(windowLine("Monthly", { used, cap, resetAt }, nowSecs, dur));
|
|
621
|
+
const { window, durSecs } = monthlyWindow(cap, cr.credits.monthlyCredits, sub.currentPeriodStart, sub.currentPeriodEnd);
|
|
622
|
+
lines.push(windowLine("Monthly", { ...window, exceeded: false }, nowSecs, durSecs));
|
|
619
623
|
}
|
|
620
624
|
const five = cr.windowLimits?.fiveHour;
|
|
621
625
|
const weekly = cr.windowLimits?.weekly;
|
package/dist/usage.d.ts
CHANGED
|
@@ -18,6 +18,17 @@ export declare function elapsedPct(resetAtMs: number | undefined, durSecs: numbe
|
|
|
18
18
|
export declare function paceEta(resetAtMs: number | undefined, durSecs: number, used: number, cap: number, nowSecs: number): number | undefined;
|
|
19
19
|
/** ISO 8601 → epoch ms. Handles trailing Z or a ±HH:MM / ±HHMM offset. */
|
|
20
20
|
export declare function parseIsoUtc(s: string): number | undefined;
|
|
21
|
+
/** Assemble the monthly window from the plan cap + subscription period:
|
|
22
|
+
* used = cap − remaining (clamped), reset = period end, durSecs = period
|
|
23
|
+
* length. Mirrors cmduse_core::monthly_window (conformance-pinned). */
|
|
24
|
+
export declare function monthlyWindow(cap: number, remaining: number, periodStart?: string, periodEnd?: string): {
|
|
25
|
+
window: {
|
|
26
|
+
used: number;
|
|
27
|
+
cap: number;
|
|
28
|
+
resetAt?: number;
|
|
29
|
+
};
|
|
30
|
+
durSecs?: number;
|
|
31
|
+
};
|
|
21
32
|
export declare function planMonthlyCap(planId: string): number | undefined;
|
|
22
33
|
export declare function planName(planId: string): string;
|
|
23
34
|
export declare function windowLine(label: string, w: Window, nowSecs: number, durSecs?: number): string;
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jeffreyjyz/opencode-command-code",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Command Code provider + usage dashboard for opencode: two providers (Anthropic wire for Claude, OpenAI wire for everything else) against api.commandcode.ai, live model list, plan gating, /cmd-usage.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"build": "bun build src/index.ts --outdir dist --target bun --external @opencode-ai/plugin
|
|
9
|
+
"build": "bun build src/index.ts --outdir dist --target bun --external @opencode-ai/plugin && tsc -p tsconfig.build.json",
|
|
10
10
|
"test": "bun test",
|
|
11
11
|
"extract": "bun run scripts/extract-gating.ts",
|
|
12
12
|
"typecheck": "tsc --noEmit"
|