@thelioo/opencode-balancer 0.1.8 → 0.2.1

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.
Files changed (176) hide show
  1. package/INSTALL.txt +53 -25
  2. package/README.md +95 -51
  3. package/dist/core/accounts.ts +404 -0
  4. package/dist/core/database.ts +67 -0
  5. package/dist/core/events.ts +75 -0
  6. package/dist/core/native-auth-suppression.ts +36 -0
  7. package/dist/core/native-connect.ts +31 -0
  8. package/dist/core/path.ts +34 -0
  9. package/dist/core/pending.ts +351 -0
  10. package/dist/core/priority.ts +193 -0
  11. package/dist/core/schema.ts +439 -0
  12. package/dist/core/time.ts +3 -0
  13. package/dist/core/types.ts +72 -0
  14. package/dist/core/usage/index.ts +23 -0
  15. package/dist/core/usage/providers/copilot.ts +243 -0
  16. package/dist/core/usage/providers/openai.ts +179 -0
  17. package/dist/core/usage/redact.ts +80 -0
  18. package/dist/core/usage/store.ts +66 -0
  19. package/dist/core/usage/types.ts +24 -0
  20. package/dist/index.js +173 -4
  21. package/dist/index.js.map +1 -1
  22. package/dist/server/auth-watcher.ts +318 -0
  23. package/dist/server/commands.ts +58 -0
  24. package/dist/server/fetch-patch.ts +162 -0
  25. package/dist/server/index.ts +134 -0
  26. package/dist/server/native.ts +49 -0
  27. package/dist/server/request-balancer.ts +67 -0
  28. package/dist/tui/actions.ts +176 -112
  29. package/dist/tui/balancer-bar-sync.ts +55 -45
  30. package/dist/tui/components/alias-dialog.tsx +71 -56
  31. package/dist/tui/components/dashboard.tsx +530 -358
  32. package/dist/tui/components/priority-screen.tsx +389 -267
  33. package/dist/tui/components/provider-model-dialog.tsx +71 -64
  34. package/dist/tui/components/rename-dialog.tsx +35 -28
  35. package/dist/tui/components/sidebar.tsx +103 -79
  36. package/dist/tui/components/status-indicator.tsx +78 -59
  37. package/dist/tui/components/usage-bar.tsx +18 -7
  38. package/dist/tui/components/usage-display.tsx +32 -16
  39. package/dist/tui/connect.ts +104 -73
  40. package/dist/tui/dashboard-keys.ts +53 -41
  41. package/dist/tui/native-model-apply.ts +45 -36
  42. package/dist/tui/priority-keys.ts +44 -36
  43. package/dist/tui/provider-models.ts +32 -25
  44. package/dist/tui/responsive.ts +10 -7
  45. package/dist/tui/selected-account-bar-sync.ts +23 -23
  46. package/dist/tui/selection-colors.ts +38 -30
  47. package/dist/tui/state.ts +61 -44
  48. package/dist/tui/status-format.ts +24 -20
  49. package/dist/tui/tui.js +165 -153
  50. package/dist/tui/tui.js.map +1 -1
  51. package/dist/tui/tui.tsx +194 -144
  52. package/dist/tui/usage-auto-refresh.ts +52 -45
  53. package/dist/tui/usage-format.ts +9 -9
  54. package/package.json +61 -52
  55. package/dist/core/accounts.d.ts +0 -14
  56. package/dist/core/accounts.js +0 -260
  57. package/dist/core/accounts.js.map +0 -1
  58. package/dist/core/database.d.ts +0 -4
  59. package/dist/core/database.js +0 -69
  60. package/dist/core/database.js.map +0 -1
  61. package/dist/core/events.d.ts +0 -18
  62. package/dist/core/events.js +0 -39
  63. package/dist/core/events.js.map +0 -1
  64. package/dist/core/native-auth-suppression.d.ts +0 -3
  65. package/dist/core/native-auth-suppression.js +0 -19
  66. package/dist/core/native-auth-suppression.js.map +0 -1
  67. package/dist/core/native-connect.d.ts +0 -4
  68. package/dist/core/native-connect.js +0 -19
  69. package/dist/core/native-connect.js.map +0 -1
  70. package/dist/core/path.d.ts +0 -4
  71. package/dist/core/path.js +0 -26
  72. package/dist/core/path.js.map +0 -1
  73. package/dist/core/pending.d.ts +0 -9
  74. package/dist/core/pending.js +0 -237
  75. package/dist/core/pending.js.map +0 -1
  76. package/dist/core/priority.d.ts +0 -20
  77. package/dist/core/priority.js +0 -120
  78. package/dist/core/priority.js.map +0 -1
  79. package/dist/core/schema.d.ts +0 -2
  80. package/dist/core/schema.js +0 -265
  81. package/dist/core/schema.js.map +0 -1
  82. package/dist/core/time.d.ts +0 -1
  83. package/dist/core/time.js +0 -4
  84. package/dist/core/time.js.map +0 -1
  85. package/dist/core/types.d.ts +0 -59
  86. package/dist/core/types.js +0 -2
  87. package/dist/core/types.js.map +0 -1
  88. package/dist/core/usage/index.d.ts +0 -4
  89. package/dist/core/usage/index.js +0 -16
  90. package/dist/core/usage/index.js.map +0 -1
  91. package/dist/core/usage/providers/copilot.d.ts +0 -2
  92. package/dist/core/usage/providers/copilot.js +0 -169
  93. package/dist/core/usage/providers/copilot.js.map +0 -1
  94. package/dist/core/usage/providers/openai.d.ts +0 -2
  95. package/dist/core/usage/providers/openai.js +0 -133
  96. package/dist/core/usage/providers/openai.js.map +0 -1
  97. package/dist/core/usage/redact.d.ts +0 -3
  98. package/dist/core/usage/redact.js +0 -67
  99. package/dist/core/usage/redact.js.map +0 -1
  100. package/dist/core/usage/store.d.ts +0 -4
  101. package/dist/core/usage/store.js +0 -31
  102. package/dist/core/usage/store.js.map +0 -1
  103. package/dist/core/usage/types.d.ts +0 -21
  104. package/dist/core/usage/types.js +0 -2
  105. package/dist/core/usage/types.js.map +0 -1
  106. package/dist/index.d.ts +0 -5
  107. package/dist/server/auth-watcher.d.ts +0 -32
  108. package/dist/server/auth-watcher.js +0 -227
  109. package/dist/server/auth-watcher.js.map +0 -1
  110. package/dist/server/commands.d.ts +0 -2
  111. package/dist/server/commands.js +0 -46
  112. package/dist/server/commands.js.map +0 -1
  113. package/dist/server/fetch-patch.d.ts +0 -3
  114. package/dist/server/fetch-patch.js +0 -118
  115. package/dist/server/fetch-patch.js.map +0 -1
  116. package/dist/server/index.d.ts +0 -8
  117. package/dist/server/index.js +0 -94
  118. package/dist/server/index.js.map +0 -1
  119. package/dist/server/native.d.ts +0 -6
  120. package/dist/server/native.js +0 -35
  121. package/dist/server/native.js.map +0 -1
  122. package/dist/server/request-balancer.d.ts +0 -16
  123. package/dist/server/request-balancer.js +0 -43
  124. package/dist/server/request-balancer.js.map +0 -1
  125. package/dist/tui/actions.d.ts +0 -41
  126. package/dist/tui/actions.js +0 -92
  127. package/dist/tui/actions.js.map +0 -1
  128. package/dist/tui/balancer-bar-sync.d.ts +0 -19
  129. package/dist/tui/balancer-bar-sync.js +0 -45
  130. package/dist/tui/balancer-bar-sync.js.map +0 -1
  131. package/dist/tui/components/alias-dialog.d.ts +0 -4
  132. package/dist/tui/components/dashboard.d.ts +0 -12
  133. package/dist/tui/components/priority-screen.d.ts +0 -9
  134. package/dist/tui/components/provider-model-dialog.d.ts +0 -14
  135. package/dist/tui/components/rename-dialog.d.ts +0 -4
  136. package/dist/tui/components/sidebar.d.ts +0 -10
  137. package/dist/tui/components/status-indicator.d.ts +0 -9
  138. package/dist/tui/components/usage-bar.d.ts +0 -8
  139. package/dist/tui/components/usage-display.d.ts +0 -10
  140. package/dist/tui/connect.d.ts +0 -30
  141. package/dist/tui/connect.js +0 -75
  142. package/dist/tui/connect.js.map +0 -1
  143. package/dist/tui/dashboard-keys.d.ts +0 -45
  144. package/dist/tui/dashboard-keys.js +0 -44
  145. package/dist/tui/dashboard-keys.js.map +0 -1
  146. package/dist/tui/native-model-apply.d.ts +0 -21
  147. package/dist/tui/native-model-apply.js +0 -53
  148. package/dist/tui/native-model-apply.js.map +0 -1
  149. package/dist/tui/priority-keys.d.ts +0 -40
  150. package/dist/tui/priority-keys.js +0 -38
  151. package/dist/tui/priority-keys.js.map +0 -1
  152. package/dist/tui/provider-models.d.ts +0 -19
  153. package/dist/tui/provider-models.js +0 -17
  154. package/dist/tui/provider-models.js.map +0 -1
  155. package/dist/tui/responsive.d.ts +0 -9
  156. package/dist/tui/responsive.js +0 -13
  157. package/dist/tui/responsive.js.map +0 -1
  158. package/dist/tui/selected-account-bar-sync.d.ts +0 -10
  159. package/dist/tui/selected-account-bar-sync.js +0 -26
  160. package/dist/tui/selected-account-bar-sync.js.map +0 -1
  161. package/dist/tui/selection-colors.d.ts +0 -10
  162. package/dist/tui/selection-colors.js +0 -38
  163. package/dist/tui/selection-colors.js.map +0 -1
  164. package/dist/tui/state.d.ts +0 -14
  165. package/dist/tui/state.js +0 -46
  166. package/dist/tui/state.js.map +0 -1
  167. package/dist/tui/status-format.d.ts +0 -15
  168. package/dist/tui/status-format.js +0 -17
  169. package/dist/tui/status-format.js.map +0 -1
  170. package/dist/tui/tui.d.ts +0 -7
  171. package/dist/tui/usage-auto-refresh.d.ts +0 -16
  172. package/dist/tui/usage-auto-refresh.js +0 -46
  173. package/dist/tui/usage-auto-refresh.js.map +0 -1
  174. package/dist/tui/usage-format.d.ts +0 -2
  175. package/dist/tui/usage-format.js +0 -17
  176. package/dist/tui/usage-format.js.map +0 -1
package/INSTALL.txt CHANGED
@@ -1,17 +1,18 @@
1
1
  opencode-balancer installation guide for AI agents
2
2
 
3
3
  Goal
4
- Install @thelioo/opencode-balancer as an opencode npm plugin without removing or rewriting the user's existing opencode configuration.
4
+ Install @thelioo/opencode-balancer as both an opencode server plugin and an opencode TUI plugin without removing or rewriting the user's existing opencode configuration.
5
5
 
6
6
  What this plugin does
7
- opencode-balancer lets opencode users save multiple authenticated accounts per provider, switch active accounts from the Balancer TUI sidebar/dashboard, and automatically retry with another saved account when the active account is rate-limited.
7
+ opencode-balancer lets opencode users save multiple authenticated accounts per provider, manage them from a TUI dashboard, choose provider/model priority, and automatically retry with another healthy account when the active account is rate-limited.
8
8
 
9
9
  Important rules
10
- - Do not run npm install for this plugin. opencode installs npm plugins automatically with Bun at startup.
11
- - Preserve existing opencode config, plugins, comments, formatting, providers, agents, MCP servers, and permissions whenever possible.
10
+ - Do not run npm install, bun install, or other package install commands for this plugin during user setup. opencode installs npm plugins automatically with Bun at startup.
11
+ - Preserve existing opencode config, TUI config, plugins, comments, formatting, providers, agents, MCP servers, and permissions whenever possible.
12
12
  - Use the singular key "plugin", not "plugins".
13
13
  - Add the plugin only if it is not already present.
14
- - Prefer @thelioo/opencode-balancer@latest for user installs.
14
+ - Prefer @thelioo/opencode-balancer (without @latest) for user installs.
15
+ - Keep config changes minimal and do not remove unrelated user settings.
15
16
 
16
17
  Steps
17
18
  1. Locate the user's opencode config.
@@ -25,43 +26,70 @@ Steps
25
26
  - If the config is JSONC, keep JSONC syntax valid.
26
27
  - If the config is JSON, keep JSON syntax valid.
27
28
 
28
- 3. Add this plugin entry:
29
- @thelioo/opencode-balancer@latest
29
+ 3. Add this plugin entry to the opencode config plugin array:
30
+ @thelioo/opencode-balancer
30
31
 
31
- 4. Save the config.
32
+ 4. Locate the user's opencode TUI config.
33
+ - Prefer ~/.config/opencode/tui.jsonc if it exists.
34
+ - Otherwise use ~/.config/opencode/tui.json if it exists.
35
+ - If neither exists, create ~/.config/opencode/tui.json with a minimal JSON object.
32
36
 
33
- 5. Show the user the final plugin array.
37
+ 5. Ensure the TUI config has a top-level plugin array.
38
+ - If plugin already exists and is an array, keep all existing entries.
39
+ - If plugin is missing, create it.
40
+ - If the config is JSONC, keep JSONC syntax valid.
41
+ - If the config is JSON, keep JSON syntax valid.
42
+
43
+ 6. Add this plugin entry to the TUI config plugin array:
44
+ @thelioo/opencode-balancer
45
+
46
+ 7. Save both configs.
34
47
 
35
- 6. Tell the user to restart opencode.
48
+ 8. Show the user both final plugin arrays.
49
+
50
+ 9. Tell the user to restart opencode.
36
51
 
37
52
  Expected config shape
38
53
  {
39
54
  "$schema": "https://opencode.ai/config.json",
40
- "plugin": ["@thelioo/opencode-balancer@latest"]
55
+ "plugin": ["@thelioo/opencode-balancer"]
56
+ }
57
+
58
+ Expected TUI config shape
59
+ {
60
+ "$schema": "https://opencode.ai/tui.json",
61
+ "plugin": ["@thelioo/opencode-balancer"]
41
62
  }
42
63
 
43
64
  After restart
44
- 1. Tell the user to run opencode's native connect flow:
45
- /connect <provider>
65
+ 1. Tell the user to open the Balancer dashboard using one of these options:
66
+ - Press Ctrl+B.
67
+ - Run /balancer.
68
+ - Open "Open Balancer Dashboard" from the opencode command palette.
69
+ - Use the Balancer button in the sidebar if visible.
70
+
71
+ 2. Tell the user to choose "New account" in the dashboard, or press C, to start opencode's native provider connection flow.
46
72
 
47
- 2. Tell the user to use the Balancer TUI modal/sidebar to save the detected pending connection with an alias.
73
+ 3. Tell the user to complete the provider connection in opencode. The plugin detects the changed provider credentials and saves them from the TUI workflow automatically. If the credentials match an existing saved account, the saved account is refreshed instead of duplicated.
48
74
 
49
- 3. If the Balancer dashboard is not visible, tell the user to open it from the opencode command palette.
75
+ 4. Tell the user to open the priority matrix from the dashboard header, or press P, to configure automatic balancing:
76
+ - Press B to turn automatic balancing on or off.
77
+ - Press Enter on a provider to choose its model.
78
+ - Use Shift+Up and Shift+Down to reorder provider priority.
79
+ - Press Space to enable or disable a provider.
50
80
 
51
- 4. Remind the user to restart opencode after any later config changes.
81
+ 5. Remind the user to restart opencode after any later config changes.
52
82
 
53
83
  Security note
54
84
  The plugin stores saved provider credentials locally in balancer.sqlite under the opencode config directory, usually ~/.config/opencode/balancer.sqlite or OPENCODE_CONFIG_DIR/balancer.sqlite. Keep this file private and never commit, paste, or share it.
55
85
 
56
- Fallback commands
57
- /balancer commands are compatibility and troubleshooting fallbacks. Alias creation is handled by the TUI pending-connection flow.
58
- /balancer help
59
- /balancer list
60
- /balancer status
61
- /balancer use <provider> <alias>
62
- /balancer active <provider>
86
+ TUI-only workflow
87
+ /balancer opens the Balancer dashboard in the TUI. Account management, provider/model priority, supported usage snapshots, and balancing settings are handled from the TUI only.
63
88
 
64
89
  Verification
65
- - Confirm the opencode config contains @thelioo/opencode-balancer@latest in the plugin array.
90
+ - Confirm the opencode config contains @thelioo/opencode-balancer in the plugin array.
91
+ - Confirm the opencode TUI config contains @thelioo/opencode-balancer in the plugin array.
66
92
  - Confirm no existing plugin entries were removed.
67
- - Remind the user that opencode must be restarted before the plugin UI and fallback commands become available.
93
+ - Confirm the user restarted opencode after the config change.
94
+ - Confirm the Balancer dashboard opens with Ctrl+B, /balancer, or the command palette.
95
+ - Confirm at least one account can be connected from the dashboard before helping configure balancing.
package/README.md CHANGED
@@ -2,32 +2,33 @@
2
2
 
3
3
  # opencode-balancer
4
4
 
5
- _Use multiple accounts per opencode provider and switch automatically when one hits a rate limit._
5
+ _Use multiple accounts and provider/model priorities in opencode, then fail over automatically when one account hits a limit._
6
6
 
7
7
  [![npm version](https://img.shields.io/npm/v/@thelioo/opencode-balancer?style=flat-square)](https://www.npmjs.com/package/@thelioo/opencode-balancer)
8
8
  [![TypeScript](https://img.shields.io/badge/TypeScript-blue?style=flat-square&logo=typescript&logoColor=white)](https://www.typescriptlang.org)
9
9
  [![opencode plugin](https://img.shields.io/badge/opencode-plugin-111?style=flat-square)](https://opencode.ai/docs/plugins)
10
10
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow?style=flat-square)](LICENSE)
11
11
 
12
- [Features](#features) | [Installation](#installation) | [Usage](#usage) | [Fallback Commands](#fallback-commands) | [Troubleshooting](#troubleshooting)
12
+ [Features](#features) | [Installation](#installation) | [Usage](#usage) | [Troubleshooting](#troubleshooting)
13
13
 
14
14
  </div>
15
15
 
16
- `opencode-balancer` is an [opencode](https://opencode.ai/) plugin that lets you save multiple authenticated accounts for the same provider, give each one a friendly alias, and keep working when the active account becomes rate-limited.
16
+ `opencode-balancer` is an [opencode](https://opencode.ai/) server and TUI plugin that lets you keep several authenticated accounts, choose which provider/model should be used first, and keep working when the current account becomes rate-limited.
17
17
 
18
- It works with opencode's existing auth flow: connect a provider, save the detected credentials from the Balancer TUI, then let the plugin inject the active account credentials into future model requests.
18
+ It integrates with opencode's native provider connection flow. Use the plugin dashboard to connect accounts, inspect usage, switch active accounts, configure provider priority, and enable or disable automatic balancing.
19
19
 
20
20
  > [!NOTE]
21
21
  > This plugin manages credentials already configured through opencode. It does not create accounts, bypass provider limits, or modify provider-side quotas.
22
22
 
23
23
  ## Features
24
24
 
25
- - **Multiple accounts per provider**: Save aliases like `work`, `personal`, or `backup` for the same provider.
26
- - **Automatic failover**: Switches to another saved account on retryable rate-limit/server responses.
27
- - **TUI-first account management**: Save aliases, switch accounts, and inspect pending connections from the Balancer sidebar/dashboard.
28
- - **OAuth-friendly setup**: Uses opencode's native `/connect` flow, then prompts you to save the detected credentials in the TUI.
29
- - **Agent tool support**: Exposes a `balancer_command` tool so opencode agents can manage accounts when asked.
30
- - **Local credential store**: Saves account credentials and status data under your opencode config directory.
25
+ - **Multiple accounts per provider**: Save and activate separate accounts for the same provider.
26
+ - **Automatic failover**: Retries with another healthy account after retryable responses such as `429`, `500`, `502`, `503`, `504`, or `529`.
27
+ - **Provider priority matrix**: Choose one model per provider, reorder failover priority, and disable providers from the balancer.
28
+ - **TUI dashboard**: Open a control center from the command palette, `/balancer`, `Ctrl+B`, or the sidebar.
29
+ - **Native connect flow**: Start opencode's provider connection from the dashboard and save the detected account automatically.
30
+ - **Usage snapshots**: Shows per-account usage when the provider exposes supported usage data.
31
+ - **Local credential store**: Saves accounts, usage snapshots, events, and priority settings under your opencode config directory.
31
32
 
32
33
  ## Installation
33
34
 
@@ -44,68 +45,94 @@ Or read the local guide: [INSTALL.txt](INSTALL.txt).
44
45
 
45
46
  ### Option B: Manual Setup
46
47
 
47
- Add the plugin to your opencode config:
48
+ Add the plugin to your opencode config so the server hooks can run:
48
49
 
49
50
  ```json
50
51
  {
51
52
  "$schema": "https://opencode.ai/config.json",
52
- "plugin": ["@thelioo/opencode-balancer@latest"]
53
+ "plugin": ["@thelioo/opencode-balancer"]
53
54
  }
54
55
  ```
55
56
 
56
- Then restart opencode.
57
+ Then add the same plugin to your opencode TUI config so the dashboard can load:
58
+
59
+ ```json
60
+ {
61
+ "$schema": "https://opencode.ai/tui.json",
62
+ "plugin": ["@thelioo/opencode-balancer"]
63
+ }
64
+ ```
65
+
66
+ Use the package name without an explicit `@latest` tag so opencode can refresh to newer published versions on restart.
67
+
68
+ Then restart opencode. The same package provides both the server hooks and the TUI dashboard.
57
69
 
58
70
  > [!TIP]
59
- > No manual `npm install` is required. opencode automatically installs npm plugins with Bun at startup and caches them locally.
71
+ > No manual `npm install` is required. opencode installs npm plugins automatically with Bun at startup and caches them locally.
60
72
 
61
73
  ## Usage
62
74
 
63
- ### Save Your First Account
75
+ ### Open The Dashboard
64
76
 
65
- Connect a provider with opencode's native flow:
77
+ Open the Balancer dashboard with any of these entry points:
66
78
 
67
- ```text
68
- /connect anthropic
69
- ```
79
+ - Press `Ctrl+B`.
80
+ - Run `/balancer` from opencode to open the dashboard.
81
+ - Open **Open Balancer Dashboard** from the command palette.
82
+ - Click the Balancer dashboard button in the sidebar.
70
83
 
71
- After the connection is detected, use the Balancer TUI modal or sidebar to save it with an alias such as `work`.
84
+ The dashboard is the primary workflow for account management. It works on compact and full terminal layouts.
72
85
 
73
- ### Add Another Account
86
+ ### Connect An Account
74
87
 
75
- Connect the same provider with a different account, then save the new pending connection from the Balancer TUI:
88
+ In the dashboard, choose **New account** or press `C`. The plugin opens opencode's native provider connection flow.
76
89
 
77
- ```text
78
- /connect anthropic
79
- ```
90
+ After the provider auth changes, `opencode-balancer` detects the new credentials and saves them as an account. If the credentials match an existing saved account, the saved account is refreshed instead of duplicated.
80
91
 
81
92
  ### Manage Accounts
82
93
 
83
- Use the Balancer sidebar or dashboard to switch accounts, view usage, and review pending connections. If the dashboard is not visible, open it from opencode's command palette.
94
+ Use the dashboard and sidebar to:
95
+
96
+ - Activate an account for a provider.
97
+ - Rename an account.
98
+ - Remove an account after confirmation.
99
+ - View supported usage snapshots when the provider exposes compatible usage data.
84
100
 
85
- When the active account receives a retryable response such as `429`, `500`, `502`, `503`, `504`, or `529`, the plugin marks it as temporarily rate-limited and retries with another available account for the same provider.
101
+ Aliases are normalized to lowercase and may contain letters, numbers, dots, hyphens, and underscores.
86
102
 
87
- ## Fallback Commands
103
+ ### Configure Automatic Balancing
88
104
 
89
- `opencode-balancer` is TUI-first. `/balancer` commands are compatibility and troubleshooting fallbacks, not the primary account management workflow. Alias creation is intentionally handled by the TUI pending-connection flow.
105
+ Open the priority matrix from the dashboard header or press `P`.
90
106
 
91
- | Command | Description |
92
- | --- | --- |
93
- | `/balancer help` | Show fallback commands. |
94
- | `/balancer list` | List saved accounts as `provider/alias`. |
95
- | `/balancer status` | Show saved and pending counts. |
96
- | `/balancer use <provider> <alias>` | Switch the active account for a provider. |
97
- | `/balancer active <provider>` | Show the active account for a provider. |
107
+ In the priority matrix you can:
98
108
 
99
- Aliases are normalized to lowercase and may contain letters, numbers, dots, hyphens, and underscores.
109
+ - Press `B` to enable or disable automatic balancing.
110
+ - Pick the model used for each provider with `Enter`.
111
+ - Reorder providers with `Shift+Up` and `Shift+Down`.
112
+ - Enable or disable individual providers with `Space`.
113
+
114
+ When balancing is on, the priority matrix decides the provider/model for each message. The plugin selects the first enabled provider with a configured model and a healthy saved account. When a retryable error is returned, the current account is temporarily marked as rate-limited and another healthy account for that provider is used when available.
115
+
116
+ When balancing is off, opencode keeps its native provider/model selection. The plugin only applies the selected saved account when needed.
117
+
118
+ ## TUI Entry Points
119
+
120
+ `opencode-balancer` is managed from the TUI. Use one of these entry points to open the dashboard:
121
+
122
+ - `Ctrl+B`
123
+ - `/balancer`
124
+ - **Open Balancer Dashboard** in the command palette
125
+ - The Balancer sidebar button
100
126
 
101
127
  ## How It Works
102
128
 
103
- `opencode-balancer` hooks into opencode's plugin lifecycle and request flow:
129
+ `opencode-balancer` combines server hooks with a TUI module:
104
130
 
105
- 1. It watches opencode auth changes and records detected provider credentials as pending connections.
106
- 2. The Balancer TUI saves pending connections under provider-specific aliases.
107
- 3. Before model requests, the plugin selects the active account for the request provider.
108
- 4. If the provider returns a retryable rate-limit or server response, the plugin marks the account as temporarily unavailable and retries with another saved account.
131
+ 1. The TUI dashboard opens opencode's native connect flow and stores changed provider credentials as saved accounts.
132
+ 2. The dashboard stores selected accounts, per-provider models, balancing state, usage snapshots, and priority order in a local SQLite database.
133
+ 3. Before a chat request, server hooks choose the active account and, when balancing is enabled, the provider/model from the priority matrix.
134
+ 4. A fetch patch injects the selected account credentials into the provider request.
135
+ 5. Retryable provider responses mark the account as temporarily rate-limited and trigger a retry with another healthy account when balancing is enabled.
109
136
 
110
137
  Saved account data is written to:
111
138
 
@@ -121,12 +148,29 @@ If `OPENCODE_CONFIG_DIR` is set, the plugin uses that directory instead.
121
148
  ## Local Development
122
149
 
123
150
  ```bash
124
- npm install
125
- npm run check
126
- npm run build
151
+ bun install
152
+ bun run check
153
+ bun run build
154
+ bun test
155
+ ```
156
+
157
+ Releases use Changesets:
158
+
159
+ ```bash
160
+ bun run changeset
161
+ bun run version
162
+ bun run release
163
+ ```
164
+
165
+ To test a local checkout with opencode, point your opencode config to the package directory:
166
+
167
+ ```json
168
+ {
169
+ "plugin": ["file:///absolute/path/to/opencode-balancer"]
170
+ }
127
171
  ```
128
172
 
129
- To test a local checkout with opencode, point your config to the package directory:
173
+ And add the same local path to your TUI config:
130
174
 
131
175
  ```json
132
176
  {
@@ -138,11 +182,11 @@ To test a local checkout with opencode, point your config to the package directo
138
182
 
139
183
  | Problem | What to try |
140
184
  | --- | --- |
141
- | Plugin does not load | Confirm `plugin` is singular, restart opencode, and check that the package name is `@thelioo/opencode-balancer@latest`. |
142
- | `/balancer` is unavailable | Restart opencode after editing the config. |
143
- | No connection detected | Run `/connect <provider>` first, then save the pending connection from the Balancer TUI modal/sidebar. |
144
- | Account is not switching | Open the Balancer sidebar/dashboard and confirm there is another saved account for the same provider. |
145
- | Need command-line fallback | Run `/balancer help` for compatibility commands. |
185
+ | Plugin does not load | Confirm `plugin` is singular in opencode config, restart opencode, and check that the package name is `@thelioo/opencode-balancer`. |
186
+ | Dashboard does not open | Confirm `tui.json` also contains the plugin, restart opencode, then try `Ctrl+B`, `/balancer`, or the command palette. |
187
+ | Account was not saved | Use **New account** from the Balancer dashboard and complete opencode's native provider connection flow. |
188
+ | Provider is skipped | Open the priority matrix and confirm the provider is enabled and has a model selected. |
189
+ | Account is not switching | Confirm there is another non-disabled saved account for the same provider and automatic balancing is on. |
146
190
 
147
191
  ## Resources
148
192