@yugimob/pi-opencode-go-rotation 1.7.3 → 1.7.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/README.md +9 -5
- package/dist/config-store.d.ts +2 -1
- package/dist/config-store.js +7 -1
- package/dist/config-ui.js +15 -0
- package/dist/index.js +84 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -60,13 +60,13 @@ The extension has three recovery paths:
|
|
|
60
60
|
|
|
61
61
|
1. **Usage-verified Go quota exhaustion**: when OpenCode Go returns HTTP 429, the extension sends the active key only to `https://opencode.ai/zen/go/v1/usage`. A key with a `rate-limited` window or a window at 100% is blocked until the latest reported reset, and the next candidate is activated. With `verifyCandidates` enabled, candidate keys are checked the same way before they are selected, so an exhausted key is blocked and skipped instead of being tried. Rotation prefers keys outside transient cooldown, but can clear a cooldown rather than keep using an exhausted key. When every key is quota-blocked, rotation stops and reports the earliest reset instead of cycling.
|
|
62
62
|
2. **Transient limit errors** (`full` only): when the usage endpoint is unavailable, does not report an exhausted window, or does not finish within 10 seconds, the extension aborts a timed-out usage request, marks the current key as on cooldown, and switches to the next key that is not quota-blocked. Under `quota-only` and `off` the key stays active and the extension reports the limit instead of rotating.
|
|
63
|
-
3. **Silent stalls**: when an `opencode-go` provider request has no response or stream activity for the watchdog window, the extension aborts the hung turn and
|
|
63
|
+
3. **Silent stalls**: when an `opencode-go` provider request has no response or stream activity for the watchdog window, the extension aborts the hung turn and, after the run settles, automatically restarts the request through a hidden continuation message. There is no retry cap: every stall schedules another continuation. It rotates under `full`; otherwise the continuation uses the same key. Setting `retry.enabled: false` in pi's settings also disables the continuation.
|
|
64
64
|
|
|
65
65
|
Checks happen at decision points only: a candidate is verified when `verifyCandidates` is enabled and it is about to be selected, and a key with a recorded block is left alone until its stored reset passes. Normal requests are not pre-checked. With the interactive footer active, the periodic footer refresh also re-checks the active key and, unless `rotationPolicy` is `off`, records a block if a window is full, so the next request can rotate before it fails.
|
|
66
66
|
|
|
67
67
|
Fixed-window Go plan quota errors reported at message end follow the same policy: a parseable reset timestamp is authoritative; without one, `quota-only` and `off` record the cooldown-length block without rotating, and `full` rotates. A response-hook rotation is deduplicated so the matching message-end error cannot rotate twice.
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
Rotations driven by a 429 or a response hook rely on pi's built-in auto-retry and its `retry.maxRetries`. A watchdog abort cannot use that retry because pi skips aborted runs, so the extension schedules its own continuation, with no cap.
|
|
70
70
|
|
|
71
71
|
Cooldowns default to 60 minutes. Quota blocks expire at their persisted deadline. Manual `/opencode use <n>` and `/opencode next` clear both restrictions on the selected key.
|
|
72
72
|
|
|
@@ -83,6 +83,8 @@ The rolling 5-hour window is omitted from the footer.
|
|
|
83
83
|
|
|
84
84
|
It refreshes on session start, model changes, turns, key rotations, manual key commands, and every 5 minutes. Under `quota-only` and `full`, a window at 100% or rate-limited blocks the active key until the window's reset and the next request moves to another key; under `off` the footer reports the window without changing keys. The key name — or `env`/`auth` for an unmanaged key — leads the line, and switching to another provider clears it.
|
|
85
85
|
|
|
86
|
+
Running `/opencode footer off` or setting `footerUsageEnabled` to `false` hides the line and stops the periodic refresh, including its pre-emptive quota blocking. `/opencode usage` still fetches usage on demand.
|
|
87
|
+
|
|
86
88
|
## Commands
|
|
87
89
|
|
|
88
90
|
| Command | Description |
|
|
@@ -99,6 +101,7 @@ It refreshes on session start, model changes, turns, key rotations, manual key c
|
|
|
99
101
|
| `/opencode cooldown <min>` | Set or view cooldown duration in minutes |
|
|
100
102
|
| `/opencode policy [off\|quota-only\|full]` | Set or view the automatic rotation policy |
|
|
101
103
|
| `/opencode verify <on\|off>` | Enable or disable candidate usage verification before switching |
|
|
104
|
+
| `/opencode footer [on\|off]` | Show or change the footer usage line |
|
|
102
105
|
| `/opencode events` | Show recent watchdog timeout history (last 10) |
|
|
103
106
|
| `/opencode watchdog [status\|on\|off\|<seconds>]` | Configure silent-stall detection |
|
|
104
107
|
|
|
@@ -115,9 +118,10 @@ Keys are stored in `~/.pi/agent/opencode-keys.json` with file permissions `0600`
|
|
|
115
118
|
"activeKeyIndex": 0,
|
|
116
119
|
"cooldownMinutes": 60,
|
|
117
120
|
"watchdogEnabled": true,
|
|
118
|
-
"watchdogIdleMs":
|
|
121
|
+
"watchdogIdleMs": 300000,
|
|
119
122
|
"rotationPolicy": "quota-only",
|
|
120
123
|
"verifyCandidates": false,
|
|
124
|
+
"footerUsageEnabled": true,
|
|
121
125
|
"cooldowns": {},
|
|
122
126
|
"quotaBlockedUntil": {},
|
|
123
127
|
"authImportDeclined": false
|
|
@@ -137,12 +141,12 @@ Pair with pi's auto-retry for best results. In `~/.pi/agent/settings.json`:
|
|
|
137
141
|
}
|
|
138
142
|
```
|
|
139
143
|
|
|
140
|
-
Set `maxRetries` to at least the number of keys so all keys get a chance before pi gives up.
|
|
144
|
+
Set `maxRetries` to at least the number of keys so all keys get a chance before pi gives up. This applies to 429 and response-hook rotations. The watchdog continuation ignores `maxRetries` and has no cap, so it keeps restarting a silent stall; `retry.enabled: false` turns it off.
|
|
141
145
|
|
|
142
146
|
## Limitations
|
|
143
147
|
|
|
144
148
|
- The watchdog is scoped to the `opencode-go` provider only. Other providers are not aborted, and the watchdog rotates only under `rotationPolicy` `full`.
|
|
145
|
-
- A legitimate long-running request with no stream activity can be treated as stalled and aborted; tune with `/opencode watchdog <seconds>` or disable with `/opencode watchdog off`.
|
|
149
|
+
- The watchdog defaults to a 5-minute idle window. A legitimate long-running request with no stream activity can be treated as stalled and aborted; tune with `/opencode watchdog <seconds>` or disable with `/opencode watchdog off`.
|
|
146
150
|
- Under `quota-only`, a bare 429, an HTTP 401, an unconfirmed usage result, and a watchdog stall never switch keys; the extension reports them and leaves the active key in place. `full` restores the earlier behavior.
|
|
147
151
|
- When all non-quota-blocked keys are transiently cooling down (`full` only), the extension may clear the next eligible key's cooldown. It never automatically clears or force-selects a quota-blocked key.
|
|
148
152
|
- When all keys are quota-blocked, automatic rotation stops on the current runtime key; each key becomes eligible again automatically when its stored reset deadline passes, or immediately after `/opencode reset`.
|
package/dist/config-store.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const CONFIG_PATH_ENV = "PI_OPENCODE_ROTATION_CONFIG";
|
|
2
2
|
export declare const DEFAULT_COOLDOWN_MINUTES = 60;
|
|
3
|
-
export declare const DEFAULT_WATCHDOG_IDLE_MS =
|
|
3
|
+
export declare const DEFAULT_WATCHDOG_IDLE_MS = 300000;
|
|
4
4
|
export type RotationPolicy = "off" | "quota-only" | "full";
|
|
5
5
|
export interface KeyEntry {
|
|
6
6
|
name: string;
|
|
@@ -14,6 +14,7 @@ export interface Config {
|
|
|
14
14
|
watchdogIdleMs: number;
|
|
15
15
|
rotationPolicy: RotationPolicy;
|
|
16
16
|
verifyCandidates: boolean;
|
|
17
|
+
footerUsageEnabled: boolean;
|
|
17
18
|
cooldowns: Record<number, number>;
|
|
18
19
|
quotaBlockedUntil: Record<number, number>;
|
|
19
20
|
authImportDeclined: boolean;
|
package/dist/config-store.js
CHANGED
|
@@ -4,9 +4,10 @@ import { dirname, join } from "node:path";
|
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
5
|
export const CONFIG_PATH_ENV = "PI_OPENCODE_ROTATION_CONFIG";
|
|
6
6
|
export const DEFAULT_COOLDOWN_MINUTES = 60;
|
|
7
|
-
export const DEFAULT_WATCHDOG_IDLE_MS =
|
|
7
|
+
export const DEFAULT_WATCHDOG_IDLE_MS = 300_000;
|
|
8
8
|
const DEFAULT_ROTATION_POLICY = "quota-only";
|
|
9
9
|
const DEFAULT_VERIFY_CANDIDATES = false;
|
|
10
|
+
const DEFAULT_FOOTER_USAGE = true;
|
|
10
11
|
const CONFIG_FILE_MODE = 0o600;
|
|
11
12
|
const LOCK_TIMEOUT_MS = 10_000;
|
|
12
13
|
const LOCK_STALE_MS = 30_000;
|
|
@@ -28,6 +29,7 @@ export function createEmptyConfig() {
|
|
|
28
29
|
watchdogIdleMs: DEFAULT_WATCHDOG_IDLE_MS,
|
|
29
30
|
rotationPolicy: DEFAULT_ROTATION_POLICY,
|
|
30
31
|
verifyCandidates: DEFAULT_VERIFY_CANDIDATES,
|
|
32
|
+
footerUsageEnabled: DEFAULT_FOOTER_USAGE,
|
|
31
33
|
cooldowns: {},
|
|
32
34
|
quotaBlockedUntil: {},
|
|
33
35
|
authImportDeclined: false,
|
|
@@ -90,6 +92,9 @@ function parseConfig(value, path) {
|
|
|
90
92
|
const verifyCandidates = value.verifyCandidates ?? DEFAULT_VERIFY_CANDIDATES;
|
|
91
93
|
if (typeof verifyCandidates !== "boolean")
|
|
92
94
|
throw new ConfigLoadError(path, "verifyCandidates is invalid");
|
|
95
|
+
const footerUsageEnabled = value.footerUsageEnabled ?? DEFAULT_FOOTER_USAGE;
|
|
96
|
+
if (typeof footerUsageEnabled !== "boolean")
|
|
97
|
+
throw new ConfigLoadError(path, "footerUsageEnabled is invalid");
|
|
93
98
|
const authImportDeclined = value.authImportDeclined ?? false;
|
|
94
99
|
if (typeof authImportDeclined !== "boolean")
|
|
95
100
|
throw new ConfigLoadError(path, "authImportDeclined is invalid");
|
|
@@ -101,6 +106,7 @@ function parseConfig(value, path) {
|
|
|
101
106
|
watchdogIdleMs,
|
|
102
107
|
rotationPolicy,
|
|
103
108
|
verifyCandidates,
|
|
109
|
+
footerUsageEnabled,
|
|
104
110
|
authImportDeclined,
|
|
105
111
|
cooldowns: parseNumberRecord(value.cooldowns, "cooldowns", path),
|
|
106
112
|
quotaBlockedUntil: parseNumberRecord(value.quotaBlockedUntil, "quotaBlockedUntil", path),
|
package/dist/config-ui.js
CHANGED
|
@@ -470,6 +470,13 @@ export async function openOpencodeConfig(ctx) {
|
|
|
470
470
|
values: ["on", "off"],
|
|
471
471
|
description: "Check a candidate key's usage before switching to it.",
|
|
472
472
|
});
|
|
473
|
+
items.push({
|
|
474
|
+
id: "footerUsage",
|
|
475
|
+
label: "Footer usage",
|
|
476
|
+
currentValue: current.footerUsageEnabled ? "on" : "off",
|
|
477
|
+
values: ["on", "off"],
|
|
478
|
+
description: "Show the active key's OpenCode Go usage in the footer and refresh it periodically.",
|
|
479
|
+
});
|
|
473
480
|
items.push({
|
|
474
481
|
id: "watchdogIdle",
|
|
475
482
|
label: "Watchdog idle",
|
|
@@ -559,6 +566,14 @@ export async function openOpencodeConfig(ctx) {
|
|
|
559
566
|
}) === undefined)
|
|
560
567
|
rebuild("verifyCandidates");
|
|
561
568
|
}
|
|
569
|
+
if (id === "footerUsage") {
|
|
570
|
+
const enabled = value === "on";
|
|
571
|
+
if (persist((fresh) => {
|
|
572
|
+
fresh.footerUsageEnabled = enabled;
|
|
573
|
+
}) === undefined)
|
|
574
|
+
rebuild("footerUsage");
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
562
577
|
};
|
|
563
578
|
rebuild();
|
|
564
579
|
const component = {
|
package/dist/index.js
CHANGED
|
@@ -14,12 +14,34 @@ const USAGE_STATUS_KEY = "opencode-go-usage";
|
|
|
14
14
|
const USAGE_STATUS_REFRESH_MS = 60_000;
|
|
15
15
|
const USAGE_STATUS_STALE_MS = 300_000;
|
|
16
16
|
const USAGE_STATUS_DEBOUNCE_MS = 2_000;
|
|
17
|
+
const WATCHDOG_RETRY_MESSAGE_TYPE = "opencode-go-timeout-retry";
|
|
18
|
+
const WATCHDOG_RETRY_PROMPT = "Continue.";
|
|
17
19
|
function getCooldownMs(config) {
|
|
18
20
|
return (config.cooldownMinutes || DEFAULT_COOLDOWN_MINUTES) * 60_000;
|
|
19
21
|
}
|
|
20
22
|
function getWatchdogIdleMs(config) {
|
|
21
23
|
return config.watchdogIdleMs > 0 ? config.watchdogIdleMs : DEFAULT_WATCHDOG_IDLE_MS;
|
|
22
24
|
}
|
|
25
|
+
function retryEnabled(ctx) {
|
|
26
|
+
try {
|
|
27
|
+
const getSettings = ctx.getSettings;
|
|
28
|
+
if (typeof getSettings !== "function")
|
|
29
|
+
return true;
|
|
30
|
+
const enabled = getSettings.call(ctx).retry?.enabled;
|
|
31
|
+
return enabled !== false;
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function hasUsableKey(config, currentTime) {
|
|
38
|
+
if (config.keys.length === 0)
|
|
39
|
+
return true;
|
|
40
|
+
const keyIndex = pickAvailableKeyIndex(config, currentTime);
|
|
41
|
+
if (keyIndex === undefined)
|
|
42
|
+
return false;
|
|
43
|
+
return getQuotaBlockedUntil(config, keyIndex, currentTime) === undefined;
|
|
44
|
+
}
|
|
23
45
|
export function shouldWatchProvider(provider) {
|
|
24
46
|
return provider === PROVIDER;
|
|
25
47
|
}
|
|
@@ -670,6 +692,7 @@ export function createOpencodeGoRotationExtension(options = {}) {
|
|
|
670
692
|
let watchdogAbortMessage;
|
|
671
693
|
let watchdogTimeoutInfo;
|
|
672
694
|
let watchdogRequestTimedOut = false;
|
|
695
|
+
let watchdogRetryPending = false;
|
|
673
696
|
let usageDecisionEpoch = 0;
|
|
674
697
|
let requestRateLimitState;
|
|
675
698
|
const watchdogEvents = [];
|
|
@@ -769,7 +792,7 @@ export function createOpencodeGoRotationExtension(options = {}) {
|
|
|
769
792
|
usageStatusTimer = statusTimerApi.setTimeout(() => {
|
|
770
793
|
usageStatusTimer = undefined;
|
|
771
794
|
const ctx = usageStatusCtx;
|
|
772
|
-
if (!ctx || !ctx.hasUI || !shouldWatchProvider(ctx.model?.provider))
|
|
795
|
+
if (!ctx || !ctx.hasUI || !config.footerUsageEnabled || !shouldWatchProvider(ctx.model?.provider))
|
|
773
796
|
return;
|
|
774
797
|
fireUsageStatusRefresh(ctx);
|
|
775
798
|
startUsageStatusTimer();
|
|
@@ -780,7 +803,7 @@ export function createOpencodeGoRotationExtension(options = {}) {
|
|
|
780
803
|
}
|
|
781
804
|
function syncUsageStatus(ctx, force = false) {
|
|
782
805
|
usageStatusCtx = ctx;
|
|
783
|
-
if (shouldWatchProvider(ctx.model?.provider)) {
|
|
806
|
+
if (config.footerUsageEnabled && shouldWatchProvider(ctx.model?.provider)) {
|
|
784
807
|
startUsageStatusTimer();
|
|
785
808
|
fireUsageStatusRefresh(ctx, force);
|
|
786
809
|
return;
|
|
@@ -790,7 +813,7 @@ export function createOpencodeGoRotationExtension(options = {}) {
|
|
|
790
813
|
}
|
|
791
814
|
function scheduleUsageStatusRefresh(ctx) {
|
|
792
815
|
usageStatusCtx = ctx;
|
|
793
|
-
if (!shouldWatchProvider(ctx.model?.provider)) {
|
|
816
|
+
if (!config.footerUsageEnabled || !shouldWatchProvider(ctx.model?.provider)) {
|
|
794
817
|
stopUsageStatusTimer();
|
|
795
818
|
setUsageStatus(undefined);
|
|
796
819
|
return;
|
|
@@ -809,6 +832,11 @@ export function createOpencodeGoRotationExtension(options = {}) {
|
|
|
809
832
|
return;
|
|
810
833
|
if (!refreshConfig())
|
|
811
834
|
return;
|
|
835
|
+
if (!config.footerUsageEnabled) {
|
|
836
|
+
stopUsageStatusTimer();
|
|
837
|
+
setUsageStatus(undefined);
|
|
838
|
+
return;
|
|
839
|
+
}
|
|
812
840
|
ambientKey = config.keys.length === 0 ? await resolveAmbientKey(ctx, config) : undefined;
|
|
813
841
|
const target = getStatusUsageTarget(config);
|
|
814
842
|
if (!target) {
|
|
@@ -829,7 +857,7 @@ export function createOpencodeGoRotationExtension(options = {}) {
|
|
|
829
857
|
usageStatusFetchedAt = receivedAt;
|
|
830
858
|
if (usageStatusCtx !== ctx)
|
|
831
859
|
return;
|
|
832
|
-
if (!refreshConfig() || getStatusUsageTarget(config)?.bearerToken !== target.bearerToken)
|
|
860
|
+
if (!refreshConfig() || !config.footerUsageEnabled || getStatusUsageTarget(config)?.bearerToken !== target.bearerToken)
|
|
833
861
|
return;
|
|
834
862
|
if (target.keyIndex >= 0 && allowsQuotaRotation(config) && usage.ok && hasExhaustedWindow(usage) && getQuotaBlockedUntil(config, target.keyIndex, receivedAt) === undefined) {
|
|
835
863
|
mutateSharedConfig((freshConfig) => {
|
|
@@ -1003,7 +1031,7 @@ export function createOpencodeGoRotationExtension(options = {}) {
|
|
|
1003
1031
|
return { rotated: false };
|
|
1004
1032
|
const currentTime = now();
|
|
1005
1033
|
if (config.keys.length <= 1 || !allowsWatchdogRotation(config)) {
|
|
1006
|
-
return { keyName: applyActiveKey(config, ctx.modelRegistry, currentTime), rotated: false };
|
|
1034
|
+
return { keyName: applyActiveKey(config, ctx.modelRegistry, currentTime) ?? ambientKey?.name, rotated: false };
|
|
1007
1035
|
}
|
|
1008
1036
|
if (shouldRotateAfterWatchdogTimeout(timeoutInfo, rateLimitAlreadyRotated)) {
|
|
1009
1037
|
const previousIndex = config.activeKeyIndex;
|
|
@@ -1049,11 +1077,16 @@ export function createOpencodeGoRotationExtension(options = {}) {
|
|
|
1049
1077
|
activeKey: rotation.keyName,
|
|
1050
1078
|
...timeoutInfo,
|
|
1051
1079
|
});
|
|
1080
|
+
const currentTime = now();
|
|
1081
|
+
const willRetry = rotation.keyName !== undefined && hasUsableKey(config, currentTime) && retryEnabled(ctx);
|
|
1082
|
+
watchdogRetryPending = willRetry;
|
|
1052
1083
|
watchdogAbortPending = true;
|
|
1053
|
-
watchdogAbortMessage =
|
|
1084
|
+
watchdogAbortMessage = willRetry
|
|
1054
1085
|
? `OpenCode Go timeout: ${formatTimeoutInfo(timeoutInfo)}; ${rotation.rotated ? "rotated to" : "using"} ${rotation.keyName}; retrying.`
|
|
1055
|
-
:
|
|
1056
|
-
|
|
1086
|
+
: rotation.keyName
|
|
1087
|
+
? `OpenCode Go timeout: ${formatTimeoutInfo(timeoutInfo)}; using ${rotation.keyName}.`
|
|
1088
|
+
: `OpenCode Go timeout: ${formatTimeoutInfo(timeoutInfo)}; no other key available.`;
|
|
1089
|
+
ctx.ui.notify(watchdogAbortMessage, willRetry ? "info" : "warning");
|
|
1057
1090
|
ctx.abort();
|
|
1058
1091
|
},
|
|
1059
1092
|
timers: options.timers,
|
|
@@ -1101,6 +1134,7 @@ export function createOpencodeGoRotationExtension(options = {}) {
|
|
|
1101
1134
|
invalidateAutomaticDecisions();
|
|
1102
1135
|
requestRateLimitState = undefined;
|
|
1103
1136
|
clearWatchdogTimeoutGuard();
|
|
1137
|
+
watchdogRetryPending = false;
|
|
1104
1138
|
setUsageStatus(undefined);
|
|
1105
1139
|
stopUsageStatusTimer();
|
|
1106
1140
|
usageStatusCtx = ctx;
|
|
@@ -1695,8 +1729,32 @@ export function createOpencodeGoRotationExtension(options = {}) {
|
|
|
1695
1729
|
ctx.ui.notify(`Candidate verification ${enabled ? "enabled" : "disabled"}`, "info");
|
|
1696
1730
|
break;
|
|
1697
1731
|
}
|
|
1732
|
+
case "footer": {
|
|
1733
|
+
const value = parts[1];
|
|
1734
|
+
if (value === undefined) {
|
|
1735
|
+
ctx.ui.notify(`Footer usage: ${config.footerUsageEnabled ? "on" : "off"}`, "info");
|
|
1736
|
+
return;
|
|
1737
|
+
}
|
|
1738
|
+
if (value !== "on" && value !== "off") {
|
|
1739
|
+
ctx.ui.notify(`Usage: /opencode footer <on|off> (currently ${config.footerUsageEnabled ? "on" : "off"})`, "info");
|
|
1740
|
+
return;
|
|
1741
|
+
}
|
|
1742
|
+
const enabled = value === "on";
|
|
1743
|
+
const result = mutateSharedConfig((freshConfig) => {
|
|
1744
|
+
freshConfig.footerUsageEnabled = enabled;
|
|
1745
|
+
return true;
|
|
1746
|
+
});
|
|
1747
|
+
if (result !== true) {
|
|
1748
|
+
if (configError)
|
|
1749
|
+
ctx.ui.notify(`OpenCode: ${configError}.`, "error");
|
|
1750
|
+
return;
|
|
1751
|
+
}
|
|
1752
|
+
ctx.ui.notify(enabled ? "Footer usage enabled" : "Footer usage disabled", "info");
|
|
1753
|
+
syncUsageStatus(ctx, true);
|
|
1754
|
+
break;
|
|
1755
|
+
}
|
|
1698
1756
|
default:
|
|
1699
|
-
ctx.ui.notify("Usage: /opencode [config|status|usage|quota|events|use <n>|next|add <name> <key>|import|rm <n>|reset|cooldown <min>|policy [off|quota-only|full]|verify <on|off>|watchdog [status|on|off|<seconds>]]", "info");
|
|
1757
|
+
ctx.ui.notify("Usage: /opencode [config|status|usage|quota|events|use <n>|next|add <name> <key>|import|rm <n>|reset|cooldown <min>|policy [off|quota-only|full]|verify <on|off>|footer [on|off]|watchdog [status|on|off|<seconds>]]", "info");
|
|
1700
1758
|
}
|
|
1701
1759
|
},
|
|
1702
1760
|
});
|
|
@@ -1711,11 +1769,28 @@ export function createOpencodeGoRotationExtension(options = {}) {
|
|
|
1711
1769
|
cleanupLifecycleState();
|
|
1712
1770
|
scheduleUsageStatusRefresh(ctx);
|
|
1713
1771
|
});
|
|
1772
|
+
pi.on("agent_settled", (event, ctx) => {
|
|
1773
|
+
if (!watchdogRetryPending)
|
|
1774
|
+
return;
|
|
1775
|
+
watchdogRetryPending = false;
|
|
1776
|
+
if (!event.aborted || ctx.model?.provider !== PROVIDER || !ctx.isIdle())
|
|
1777
|
+
return;
|
|
1778
|
+
if (!refreshConfig())
|
|
1779
|
+
return;
|
|
1780
|
+
if (!hasUsableKey(config, now()))
|
|
1781
|
+
return;
|
|
1782
|
+
pi.sendMessage({
|
|
1783
|
+
customType: WATCHDOG_RETRY_MESSAGE_TYPE,
|
|
1784
|
+
content: [{ type: "text", text: WATCHDOG_RETRY_PROMPT }],
|
|
1785
|
+
display: false,
|
|
1786
|
+
}, { triggerTurn: true });
|
|
1787
|
+
});
|
|
1714
1788
|
pi.on("session_shutdown", () => {
|
|
1715
1789
|
stopUsageStatusTimer();
|
|
1716
1790
|
setUsageStatus(undefined);
|
|
1717
1791
|
usageStatusCtx = undefined;
|
|
1718
1792
|
ambientKey = undefined;
|
|
1793
|
+
watchdogRetryPending = false;
|
|
1719
1794
|
cleanupLifecycleState();
|
|
1720
1795
|
});
|
|
1721
1796
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yugimob/pi-opencode-go-rotation",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.5",
|
|
4
4
|
"description": "Rotate between multiple OpenCode Go API keys with reactive 429, rate-limit, and watchdog stall detection, plus live footer usage for the active key",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|