@yugimob/pi-opencode-go-rotation 1.7.4 → 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 CHANGED
@@ -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
 
@@ -118,6 +121,7 @@ Keys are stored in `~/.pi/agent/opencode-keys.json` with file permissions `0600`
118
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
@@ -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;
@@ -7,6 +7,7 @@ export const DEFAULT_COOLDOWN_MINUTES = 60;
7
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
@@ -792,7 +792,7 @@ export function createOpencodeGoRotationExtension(options = {}) {
792
792
  usageStatusTimer = statusTimerApi.setTimeout(() => {
793
793
  usageStatusTimer = undefined;
794
794
  const ctx = usageStatusCtx;
795
- if (!ctx || !ctx.hasUI || !shouldWatchProvider(ctx.model?.provider))
795
+ if (!ctx || !ctx.hasUI || !config.footerUsageEnabled || !shouldWatchProvider(ctx.model?.provider))
796
796
  return;
797
797
  fireUsageStatusRefresh(ctx);
798
798
  startUsageStatusTimer();
@@ -803,7 +803,7 @@ export function createOpencodeGoRotationExtension(options = {}) {
803
803
  }
804
804
  function syncUsageStatus(ctx, force = false) {
805
805
  usageStatusCtx = ctx;
806
- if (shouldWatchProvider(ctx.model?.provider)) {
806
+ if (config.footerUsageEnabled && shouldWatchProvider(ctx.model?.provider)) {
807
807
  startUsageStatusTimer();
808
808
  fireUsageStatusRefresh(ctx, force);
809
809
  return;
@@ -813,7 +813,7 @@ export function createOpencodeGoRotationExtension(options = {}) {
813
813
  }
814
814
  function scheduleUsageStatusRefresh(ctx) {
815
815
  usageStatusCtx = ctx;
816
- if (!shouldWatchProvider(ctx.model?.provider)) {
816
+ if (!config.footerUsageEnabled || !shouldWatchProvider(ctx.model?.provider)) {
817
817
  stopUsageStatusTimer();
818
818
  setUsageStatus(undefined);
819
819
  return;
@@ -832,6 +832,11 @@ export function createOpencodeGoRotationExtension(options = {}) {
832
832
  return;
833
833
  if (!refreshConfig())
834
834
  return;
835
+ if (!config.footerUsageEnabled) {
836
+ stopUsageStatusTimer();
837
+ setUsageStatus(undefined);
838
+ return;
839
+ }
835
840
  ambientKey = config.keys.length === 0 ? await resolveAmbientKey(ctx, config) : undefined;
836
841
  const target = getStatusUsageTarget(config);
837
842
  if (!target) {
@@ -852,7 +857,7 @@ export function createOpencodeGoRotationExtension(options = {}) {
852
857
  usageStatusFetchedAt = receivedAt;
853
858
  if (usageStatusCtx !== ctx)
854
859
  return;
855
- if (!refreshConfig() || getStatusUsageTarget(config)?.bearerToken !== target.bearerToken)
860
+ if (!refreshConfig() || !config.footerUsageEnabled || getStatusUsageTarget(config)?.bearerToken !== target.bearerToken)
856
861
  return;
857
862
  if (target.keyIndex >= 0 && allowsQuotaRotation(config) && usage.ok && hasExhaustedWindow(usage) && getQuotaBlockedUntil(config, target.keyIndex, receivedAt) === undefined) {
858
863
  mutateSharedConfig((freshConfig) => {
@@ -1724,8 +1729,32 @@ export function createOpencodeGoRotationExtension(options = {}) {
1724
1729
  ctx.ui.notify(`Candidate verification ${enabled ? "enabled" : "disabled"}`, "info");
1725
1730
  break;
1726
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
+ }
1727
1756
  default:
1728
- 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");
1729
1758
  }
1730
1759
  },
1731
1760
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yugimob/pi-opencode-go-rotation",
3
- "version": "1.7.4",
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",