Skip to content

Commit 770fab1

Browse files
committed
fix(opencode): accept the nested usage envelope
GET /zen/go/v1/usage returns usage.rolling.percent with an absolute resetsAt, not the flat rollingUsage.usagePercent with a relative resetInSec the adapter validated. Every response therefore failed validation and the card degraded to the authenticated-only /models check, hiding all three quota windows. Both shapes are now accepted, so an older deployment is unchanged. Signed-off-by: Álvaro Tejero Cantero <[email protected]>
1 parent e8632e7 commit 770fab1

4 files changed

Lines changed: 46 additions & 10 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Fixes
6+
7+
- The OpenCode Go adapter accepts the endpoint's nested `usage.rolling` / `percent` / `resetsAt` envelope, so the 5-hour, weekly and monthly windows survive the API's change instead of degrading to the authenticated-only card. The older flat `rollingUsage` / `resetInSec` shape is still parsed, so an older deployment is unchanged.
8+
59
## 2.2.4 - 2026-11-04
610

711
A bug-fix release for Dux Shell 2.0 and 2.1, the shell formerly called DankMaterialShell. The Claude card stops polling Anthropic's usage endpoint while it is rate-limited, sharing one backoff across every bar, and the bar fades numbers that are no longer fresh. The docs and settings strings use the Dux Shell names, and the documented checkout install works again. Settings, profiles, pins and history carry over unchanged; no restart is needed.

‎providers/native/opencode.bash‎

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,32 +66,46 @@ fetch_opencode_native() {
6666
fi
6767

6868
if [ "$http_status" = "200" ] && jq -e '
69+
# The endpoint moved from a flat rollingUsage/resetInSec envelope to a
70+
# nested usage.rolling/percent/resetsAt one; both are accepted so an older
71+
# deployment keeps working.
72+
def windows:
73+
if (.usage | type) == "object" then .usage
74+
else {rolling: .rollingUsage, weekly: .weeklyUsage, monthly: .monthlyUsage} end;
6975
def valid_window:
7076
type == "object"
71-
and (.usagePercent | type == "number" and . >= 0 and . <= 100)
72-
and (.resetInSec | type == "number" and . >= 0);
73-
(.rollingUsage | valid_window)
74-
and (.weeklyUsage | valid_window)
75-
and (.monthlyUsage | valid_window)
77+
and ((.percent // .usagePercent) | type == "number" and . >= 0 and . <= 100);
78+
windows as $w
79+
| ($w.rolling | valid_window) and ($w.weekly | valid_window) and ($w.monthly | valid_window)
7680
' "$tmp_body" >/dev/null 2>&1; then
7781
jq -c '
82+
def windows:
83+
if (.usage | type) == "object" then .usage
84+
else {rolling: .rollingUsage, weekly: .weeklyUsage, monthly: .monthlyUsage} end;
85+
# A nested window carries an absolute resetsAt; the flat one carried a
86+
# relative resetInSec.
87+
def reset_at($w):
88+
if ($w.resetsAt | type) == "string" and ($w.resetsAt | length) > 0 then $w.resetsAt
89+
elif ($w.resetInSec | type) == "number" then ((now + $w.resetInSec) | todate)
90+
else null end;
7891
def make_window($w; $minutes; $label): {
79-
usedPercent: $w.usagePercent,
92+
usedPercent: ($w.percent // $w.usagePercent),
8093
windowMinutes: $minutes,
81-
resetsAt: ((now + $w.resetInSec) | todate),
94+
resetsAt: reset_at($w),
8295
resetDescription: $label
8396
};
8497
. as $body |
98+
windows as $w |
8599
{
86100
provider: "opencode",
87101
source: "opencode-usage",
88102
usage: {
89103
identity: {providerID: "opencode", accountEmail: "OpenCode Go account", loginMethod: "api-key"},
90104
accountEmail: "OpenCode Go account",
91105
loginMethod: "api-key",
92-
primary: make_window($body.rollingUsage; 300; "5h"),
93-
secondary: make_window($body.weeklyUsage; 10080; "weekly"),
94-
tertiary: make_window($body.monthlyUsage; 43200; "monthly"),
106+
primary: make_window($w.rolling; 300; "5h"),
107+
secondary: make_window($w.weekly; 10080; "weekly"),
108+
tertiary: make_window($w.monthly; 43200; "monthly"),
95109
updatedAt: (now | todate)
96110
},
97111
credits: {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"useBalance": false,
3+
"usage": {
4+
"rolling": { "status": "ok", "percent": 0, "resetsAt": "2026-11-08T15:24:56.000Z" },
5+
"weekly": { "status": "ok", "percent": 19, "resetsAt": "2026-11-09T00:00:00.000Z" },
6+
"monthly": { "status": "ok", "percent": 75, "resetsAt": "2026-11-14T14:38:46.000Z" }
7+
}
8+
}

‎tests/test-opencode.sh‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ case "$url" in
4242
*zen/go/v1/usage*)
4343
case "${OC_USAGE_MODE:-ok}" in
4444
ok) [ -n "$out" ] && cp "${OC_FIXTURE_DIR}/opencode-usage.json" "$out"; status=200 ;;
45+
live) [ -n "$out" ] && cp "${OC_FIXTURE_DIR}/opencode-usage-live.json" "$out"; status=200 ;;
4546
unauthorized) [ -n "$out" ] && cp "${OC_FIXTURE_DIR}/opencode-error-401.json" "$out"; status=401 ;;
4647
forbidden) [ -n "$out" ] && cp "${OC_FIXTURE_DIR}/opencode-error-403.json" "$out"; status=403 ;;
4748
down) [ -n "$out" ] && printf '' > "$out"; status=500 ;;
@@ -77,6 +78,15 @@ out="$(OC_USAGE_MODE=ok run env -u OPENCODE_API_KEY OPENCODE_API_KEY=user_test)"
7778
[ "$(jq -r '.[0].usage.identity.accountEmail' <<<"$out")" = "OpenCode Go account" ] || fail "identity"
7879
[ "$(grep -c '^Authorization: Bearer user_test$' "$HDR_LOG")" -ge 1 ] || fail "auth header forwarded"
7980

81+
# 1b. The endpoint's nested envelope (usage.rolling/percent/resetsAt) parses to
82+
# the same windows, so a server that moved on is not read as unavailable.
83+
out="$(OC_USAGE_MODE=live run env -u OPENCODE_API_KEY OPENCODE_API_KEY=user_test)"
84+
[ "$(jq -r '.[0].source' <<<"$out")" = "opencode-usage" ] || fail "live source"
85+
[ "$(jq -r '.[0].usage.primary.usedPercent' <<<"$out")" = "0" ] || fail "live 5h percent"
86+
[ "$(jq -r '.[0].usage.primary.resetsAt' <<<"$out")" = "2026-11-08T15:24:56.000Z" ] || fail "live 5h reset"
87+
[ "$(jq -r '.[0].usage.secondary.usedPercent' <<<"$out")" = "19" ] || fail "live weekly percent"
88+
[ "$(jq -r '.[0].usage.tertiary.usedPercent' <<<"$out")" = "75" ] || fail "live monthly percent"
89+
8090
# 2. A local auth.json credential is a safe fallback for graphical sessions.
8191
CLI_HOME="$TMP/cli-home"
8292
mkdir -p "$CLI_HOME/.local/share/opencode"

0 commit comments

Comments
 (0)