@jeffreyjyz/opencode-command-code 0.1.5 → 0.1.7
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/gating.d.ts +6 -0
- package/dist/index.js +33 -2
- package/dist/usage.d.ts +5 -0
- package/package.json +1 -2
package/dist/gating.d.ts
CHANGED
|
@@ -10,6 +10,12 @@ export declare const PLAN_RULES: Record<string, {
|
|
|
10
10
|
* category rules. Empirically probed — the CLI bundle misses these because it
|
|
11
11
|
* tracks category via serving lane, not per-model plan entitlements. */
|
|
12
12
|
export declare const HARD_BLOCKED: Record<string, string[]>;
|
|
13
|
+
/** ISO timestamp the snapshot was extracted (absent on pre-metadata files). */
|
|
14
|
+
export declare const GATE_EXTRACTED_AT: string | undefined;
|
|
15
|
+
/** Command Code CLI version the snapshot was scraped from. */
|
|
16
|
+
export declare const GATE_CLI_VERSION: string | undefined;
|
|
17
|
+
/** Warn once per process when gating.json is older than 30 days. */
|
|
18
|
+
export declare function warnIfGatingStale(): void;
|
|
13
19
|
export declare function canonicalizeModelId(model: string): string;
|
|
14
20
|
/** Bare model id with any provider qualifier stripped: everything after the
|
|
15
21
|
* FIRST colon ("anthropic:claude-opus-5" → "claude-opus-5"). Matches
|
package/dist/index.js
CHANGED
|
@@ -71,6 +71,8 @@ async function resolveKey(getAuth) {
|
|
|
71
71
|
}
|
|
72
72
|
// ../core/gating.json
|
|
73
73
|
var gating_default = {
|
|
74
|
+
extractedAt: "2026-09-12T06:01:01.385Z",
|
|
75
|
+
cliVersion: "1.38.2",
|
|
74
76
|
categories: {
|
|
75
77
|
"claude-sonnet-5": "premium",
|
|
76
78
|
"claude-sonnet-4-6": "premium",
|
|
@@ -311,6 +313,19 @@ var PLAN_RULES = gating_default.plans;
|
|
|
311
313
|
var HARD_BLOCKED = gating_default.hardBlocked;
|
|
312
314
|
var KNOWN_MODELS = gating_default.knownModels;
|
|
313
315
|
var MODEL_ALIASES = gating_default.aliases;
|
|
316
|
+
var GATE_EXTRACTED_AT = gating_default.extractedAt;
|
|
317
|
+
var GATE_CLI_VERSION = gating_default.cliVersion;
|
|
318
|
+
var GATE_STALE_DAYS = 30;
|
|
319
|
+
var staleWarned = false;
|
|
320
|
+
function warnIfGatingStale() {
|
|
321
|
+
if (staleWarned || !GATE_EXTRACTED_AT)
|
|
322
|
+
return;
|
|
323
|
+
const days = Math.floor((Date.now() - Date.parse(GATE_EXTRACTED_AT)) / 86400000);
|
|
324
|
+
if (days > GATE_STALE_DAYS) {
|
|
325
|
+
staleWarned = true;
|
|
326
|
+
console.warn(`[command-code] gating snapshot is ${days}d old (CLI ${GATE_CLI_VERSION ?? "?"}) \u2014 run \`bun run extract\` from the repo root`);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
314
329
|
function findKnown(s) {
|
|
315
330
|
const k = s.toLowerCase();
|
|
316
331
|
return KNOWN_MODELS.find((m) => m.toLowerCase() === k);
|
|
@@ -382,6 +397,7 @@ function splitModels(models) {
|
|
|
382
397
|
return { claude, open };
|
|
383
398
|
}
|
|
384
399
|
async function loadModels(key) {
|
|
400
|
+
warnIfGatingStale();
|
|
385
401
|
let models;
|
|
386
402
|
if (cache && Date.now() - cache.at < CACHE_TTL_MS) {
|
|
387
403
|
models = cache.models;
|
|
@@ -458,10 +474,11 @@ function money(v) {
|
|
|
458
474
|
return `$${v.toFixed(2)}`;
|
|
459
475
|
}
|
|
460
476
|
function compact(n) {
|
|
477
|
+
const round1 = (v) => Math.round(v * 10) / 10;
|
|
461
478
|
if (n >= 1e6)
|
|
462
|
-
return `${(n / 1e6).toFixed(1)}M`;
|
|
479
|
+
return `${round1(n / 1e6).toFixed(1)}M`;
|
|
463
480
|
if (n >= 1000)
|
|
464
|
-
return `${(n / 1000).toFixed(1)}K`;
|
|
481
|
+
return `${round1(n / 1000).toFixed(1)}K`;
|
|
465
482
|
return `${n}`;
|
|
466
483
|
}
|
|
467
484
|
function bar(used, cap) {
|
|
@@ -563,6 +580,17 @@ var PLANS = plans_default.plans;
|
|
|
563
580
|
function planMonthlyCap(planId) {
|
|
564
581
|
return CAPS[planName(planId)] ?? undefined;
|
|
565
582
|
}
|
|
583
|
+
function planRuleMatched(planId) {
|
|
584
|
+
const id = planId.toLowerCase();
|
|
585
|
+
return NAME_RULES.some((rule) => rule.needles.every((n) => id.includes(n)));
|
|
586
|
+
}
|
|
587
|
+
var unknownPlanWarned = false;
|
|
588
|
+
function warnUnknownPlanOnce(planId) {
|
|
589
|
+
if (unknownPlanWarned)
|
|
590
|
+
return;
|
|
591
|
+
unknownPlanWarned = true;
|
|
592
|
+
console.warn(`[command-code] unknown plan id '${planId}' \u2014 showing Free; update core/plans.json`);
|
|
593
|
+
}
|
|
566
594
|
function planName(planId) {
|
|
567
595
|
const id = planId.toLowerCase();
|
|
568
596
|
for (const rule of NAME_RULES) {
|
|
@@ -602,6 +630,9 @@ async function renderUsage(key) {
|
|
|
602
630
|
return;
|
|
603
631
|
})
|
|
604
632
|
]);
|
|
633
|
+
if (sub.planId && sub.planId !== "free" && !planRuleMatched(sub.planId)) {
|
|
634
|
+
warnUnknownPlanOnce(sub.planId);
|
|
635
|
+
}
|
|
605
636
|
const lines = [];
|
|
606
637
|
lines.push(`## Command Code \u2014 ${planName(sub.planId)} (${sub.status})
|
|
607
638
|
`);
|
package/dist/usage.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { type Window } from "./api";
|
|
|
2
2
|
export declare const FIVE_HOUR_SECS: number;
|
|
3
3
|
export declare const WEEKLY_SECS: number;
|
|
4
4
|
export declare function money(v: number): string;
|
|
5
|
+
/** Mirrors cmduse_core::compact. `toFixed` alone disagreed with Rust's `{:.1}`
|
|
6
|
+
* at `.x5` ties; round half-away-from-zero explicitly so both ports match. */
|
|
5
7
|
export declare function compact(n: number): string;
|
|
6
8
|
export declare function bar(used: number, cap: number): string;
|
|
7
9
|
export declare function pctStr(used: number, cap: number): string;
|
|
@@ -30,6 +32,9 @@ export declare function monthlyWindow(cap: number, remaining: number, periodStar
|
|
|
30
32
|
durSecs?: number;
|
|
31
33
|
};
|
|
32
34
|
export declare function planMonthlyCap(planId: string): number | undefined;
|
|
35
|
+
/** True when `planId` matched a NAME_RULES entry (not the DEFAULT_NAME
|
|
36
|
+
* fallback). Mirrors cmduse_core::plan_rule_matched. */
|
|
37
|
+
export declare function planRuleMatched(planId: string): boolean;
|
|
33
38
|
export declare function planName(planId: string): string;
|
|
34
39
|
export declare function windowLine(label: string, w: Window, nowSecs: number, durSecs?: number): string;
|
|
35
40
|
export declare function plansTable(current: string): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jeffreyjyz/opencode-command-code",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
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",
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
"scripts": {
|
|
9
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
|
-
"extract": "bun run scripts/extract-gating.ts",
|
|
12
11
|
"typecheck": "tsc --noEmit"
|
|
13
12
|
},
|
|
14
13
|
"dependencies": {
|