opencode-go-usage-tui 1.1.0 → 1.3.0

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
@@ -1,9 +1,24 @@
1
1
  # opencode-go-usage-tui
2
2
 
3
- OpenCode 侧边栏实时显示 OpenCode Go 额度用量(5小时/每周/每月)。
3
+ <div align="center">
4
+
5
+ 🌏 **语言 / Language:** [简体中文](/README.md) | [English](/README_EN.md)
6
+
7
+ </div>
8
+
9
+ 在 OpenCode 侧边栏实时显示 OpenCode Go 额度用量(5小时/每周/每月)与模型请求限额。
4
10
 
5
11
  支持中英双语界面(`/go-lang` 切换,首次启动自动引导选择语言)。
6
12
 
13
+ ## 功能
14
+
15
+ - **双独立面板**:`Go 用量`(额度百分比 + 进度条)+ `模型价格`(请求限额表),可独立折叠
16
+ - **模型请求限额**:从 opencode.ai/docs/go 实时抓取各模型 5小时/每周/每月 请求数上限(无需登录)
17
+ - **关注模型**:`/go-settings` 设置关注的白名单,只显示你关心的模型
18
+ - **刷新间隔可调**:用量刷新和价格刷新间隔均可通过 `/go-settings` 设置(秒)
19
+ - **安全加密**:auth cookie 用 AES-256-GCM 加密存储,旧明文自动迁移
20
+ - **自动提醒**:价格/限额变化时弹 toast 通知,变化历史保留最近 10 次
21
+
7
22
  ## 安装
8
23
 
9
24
  ### 方式一:OpenCode 命令安装(推荐)
@@ -14,7 +29,7 @@
14
29
  opencode-go-usage-tui@latest
15
30
  ```
16
31
 
17
- 回车完成安装,重启 OpenCode 后侧边栏即可看到"Go 用量"面板。
32
+ 回车完成安装,重启 OpenCode 后侧边栏即可看到两个面板。
18
33
 
19
34
  ### 方式二:npm 全局安装
20
35
 
@@ -47,7 +62,15 @@ npm install -g opencode-go-usage-tui
47
62
  1. **workspace_id**:`wrk_` 开头,在 opencode.ai 控制台 URL 中获取
48
63
  2. **auth cookie**:浏览器 F12 → Application → Cookies → opencode.ai → 复制 `auth` 的值(`Fe26.2*` 开头)
49
64
 
50
- 配置保存在 `~/.config/opencode/go-usage-config.json`。
65
+ 配置保存在 `~/.config/opencode/`:
66
+
67
+ - `go-usage-config.json` — workspace_id(明文,非敏感)
68
+ - `go-auth-cookie.enc` — auth cookie(**AES-256-GCM 加密**)
69
+ - `.encryption-key` — 加密密钥(32 字节随机生成)
70
+
71
+ > 🔒 **安全说明**:cookie 以 AES-256-GCM 加密存储,密钥随机生成且独立保存,文件被备份/同步/日志收集不会泄露 cookie。旧版明文文件(`go-auth-cookie.txt` / config.json 内嵌 cookie)首次读取时**自动迁移**为加密存储并清理明文。
72
+ >
73
+ > ⚠️ 局限:密钥与密文同目录,能防御"被动泄露"(备份/同步),无法防御能读取该目录的本地恶意程序。如需更强保护可改用系统级凭据存储。
51
74
 
52
75
  ### 方式二:环境变量
53
76
 
@@ -63,10 +86,25 @@ npm install -g opencode-go-usage-tui
63
86
  ```json
64
87
  {
65
88
  "workspace_id": "wrk_xxxxxxxxxxxx",
66
- "cookie": "Fe26.2*..."
89
+ "cookie": "Fe26.2*...",
90
+ "ui": {
91
+ "usage_panel": true,
92
+ "price_panel": true
93
+ },
94
+ "focus_models": ["grok-4-5"],
95
+ "refresh_interval_sec": 60,
96
+ "pricing_interval_sec": 1800
67
97
  }
68
98
  ```
69
99
 
100
+ | 字段 | 说明 |
101
+ | ---- | ---- |
102
+ | `ui.usage_panel` | 显示/隐藏用量面板(默认 true) |
103
+ | `ui.price_panel` | 显示/隐藏价格面板(默认 true) |
104
+ | `focus_models` | 关注模型白名单(空数组显示全部) |
105
+ | `refresh_interval_sec` | 用量刷新间隔秒数(默认 60) |
106
+ | `pricing_interval_sec` | 价格刷新间隔秒数(默认 1800) |
107
+
70
108
  ## 获取 auth cookie
71
109
 
72
110
  1. Chrome 登录 opencode.ai
@@ -77,11 +115,19 @@ Cookie 有效期约 1 年,过期后重新获取。
77
115
 
78
116
  ## 使用
79
117
 
80
- - 侧边栏面板每 60 秒自动刷新(可用 `OPENCODE_GO_CHECK_INTERVAL` 环境变量调整,单位毫秒)
118
+ - **`/go-config`**:设置 workspace_id auth cookie
119
+ - **`/go-settings`**:设置关注模型、用量刷新间隔、价格刷新间隔
120
+ - **`/go-lang`**:切换 中文 / English
81
121
  - 用量超过阈值(默认 80%,可用 `OPENCODE_GO_WARN_THRESHOLD` 调整)显示为红色
82
122
  - 点击面板标题可折叠/展开
83
- - 配置错误时面板会提示"未配置账号",输入 `/go-config` 即可设置
84
- - 面板标题显示当前插件版本号(如 `v1.1.0`)
123
+ - 面板标题显示当前插件版本号(如 `v1.3.0`)
124
+
125
+ ## 模型请求限额面板
126
+
127
+ - 独立面板显示各模型的 5小时/每周/每月 请求数上限,表格风格两端对齐
128
+ - 从 opencode.ai/docs/go 实时抓取公开数据(无需登录)
129
+ - 默认每 30 分钟自动刷新(可用 `/go-settings` 或 `pricing_interval_sec` 调整)
130
+ - 每次刷新自动对比上次数据,变化时 toast 提醒,历史保留最近 10 次到 `go-pricing-data.json`
85
131
 
86
132
  ## 语言
87
133
 
package/README_EN.md CHANGED
@@ -1,9 +1,24 @@
1
1
  # opencode-go-usage-tui
2
2
 
3
- Display your OpenCode Go quota usage (5h / weekly / monthly) in the OpenCode sidebar in real time.
3
+ <div align="center">
4
+
5
+ 🌏 **Language / 语言:** [English](/README_EN.md) | [简体中文](/README.md)
6
+
7
+ </div>
8
+
9
+ Display your OpenCode Go quota usage (5h / weekly / monthly) and model request limits in the OpenCode sidebar in real time.
4
10
 
5
11
  Bilingual UI (Chinese / English) — switch with `/go-lang`, or pick a language during the first-run onboarding.
6
12
 
13
+ ## Features
14
+
15
+ - **Two independent panels**: `Go Usage` (quota percentage + progress bar) + `Model Pricing` (request limits table), each collapsible independently
16
+ - **Model request limits**: scrapes real-time 5h / weekly / monthly request caps per model from opencode.ai/docs/go (no login required)
17
+ - **Focused models**: use `/go-settings` to whitelist only the models you care about
18
+ - **Adjustable refresh intervals**: set usage and pricing refresh intervals via `/go-settings` (in seconds)
19
+ - **Secure storage**: auth cookie encrypted with AES-256-GCM, legacy plaintext auto-migrated
20
+ - **Change alerts**: toast notification when prices/limits change; last 10 changes kept
21
+
7
22
  ## Install
8
23
 
9
24
  ### Option 1: Install via OpenCode command (recommended)
@@ -14,7 +29,7 @@ In OpenCode, press **`Ctrl+P`** to open the command palette, search for **`insta
14
29
  opencode-go-usage-tui@latest
15
30
  ```
16
31
 
17
- Press Enter, restart OpenCode, and the "Go Usage" panel will appear in the sidebar.
32
+ Press Enter, restart OpenCode, and both panels will appear in the sidebar.
18
33
 
19
34
  ### Option 2: npm global install
20
35
 
@@ -47,7 +62,15 @@ Enter two values (unique per user — get them by logging into opencode.ai):
47
62
  1. **workspace_id**: starts with `wrk_`, found in the opencode.ai console URL
48
63
  2. **auth cookie**: in your browser, F12 → Application → Cookies → opencode.ai → copy the `auth` value (starts with `Fe26.2*`)
49
64
 
50
- Config is saved to `~/.config/opencode/go-usage-config.json`.
65
+ Config is saved to `~/.config/opencode/`:
66
+
67
+ - `go-usage-config.json` — workspace_id (plain text, not sensitive)
68
+ - `go-auth-cookie.enc` — auth cookie (**AES-256-GCM encrypted**)
69
+ - `.encryption-key` — encryption key (random 32 bytes)
70
+
71
+ > 🔒 **Security**: The cookie is stored encrypted with AES-256-GCM, with a randomly generated key stored separately — backups, syncs, and logs cannot leak the cookie. Legacy plaintext files (`go-auth-cookie.txt` / cookie embedded in config.json) are **auto-migrated** to encrypted storage on first read, and the plaintext is cleaned up.
72
+ >
73
+ > ⚠️ Limitation: The key lives in the same directory as the ciphertext. This defends against passive leaks (backups/sync) but not against local malware that can read your user directory. Use system credential storage (Windows DPAPI / macOS Keychain) for stronger protection.
51
74
 
52
75
  ### Option 2: Environment variables
53
76
 
@@ -63,10 +86,25 @@ Create `~/.config/opencode/go-usage-config.json` manually:
63
86
  ```json
64
87
  {
65
88
  "workspace_id": "wrk_xxxxxxxxxxxx",
66
- "cookie": "Fe26.2*..."
89
+ "cookie": "Fe26.2*...",
90
+ "ui": {
91
+ "usage_panel": true,
92
+ "price_panel": true
93
+ },
94
+ "focus_models": ["grok-4-5"],
95
+ "refresh_interval_sec": 60,
96
+ "pricing_interval_sec": 1800
67
97
  }
68
98
  ```
69
99
 
100
+ | Field | Description |
101
+ | ----- | ----------- |
102
+ | `ui.usage_panel` | Show/hide usage panel (default true) |
103
+ | `ui.price_panel` | Show/hide pricing panel (default true) |
104
+ | `focus_models` | Focused model whitelist (empty array shows all) |
105
+ | `refresh_interval_sec` | Usage refresh interval in seconds (default 60) |
106
+ | `pricing_interval_sec` | Pricing refresh interval in seconds (default 1800) |
107
+
70
108
  ## Getting the auth cookie
71
109
 
72
110
  1. Log into opencode.ai in Chrome
@@ -77,11 +115,19 @@ The cookie is valid for about 1 year; get a new one after it expires.
77
115
 
78
116
  ## Usage
79
117
 
80
- - The sidebar panel auto-refreshes every 60 seconds (adjustable via `OPENCODE_GO_CHECK_INTERVAL`, in milliseconds)
118
+ - **`/go-config`**: set workspace_id and auth cookie
119
+ - **`/go-settings`**: set focused models, usage refresh interval, pricing refresh interval
120
+ - **`/go-lang`**: switch between 中文 / English
81
121
  - Usage above the threshold (default 80%, adjustable via `OPENCODE_GO_WARN_THRESHOLD`) is shown in red
82
122
  - Click the panel title to collapse/expand
83
- - If misconfigured, the panel shows "Not configured" run `/go-config` to set up
84
- - The panel title shows the current plugin version (e.g. `v1.1.0`)
123
+ - The panel title shows the current plugin version (e.g. `v1.3.0`)
124
+
125
+ ## Model request limits panel
126
+
127
+ - Independent panel showing each model's 5h / weekly / monthly request caps, table style with two-end alignment
128
+ - Scraped live from opencode.ai/docs/go (public data, no login)
129
+ - Auto-refreshes every 30 minutes by default (adjustable via `/go-settings` or `pricing_interval_sec`)
130
+ - Each refresh diffs against the last snapshot; toast on change; last 10 changes kept in `go-pricing-data.json`
85
131
 
86
132
  ## Language
87
133
 
package/build.tui.mjs CHANGED
@@ -10,7 +10,7 @@ await esbuild.build({
10
10
  format: "esm",
11
11
  platform: "node",
12
12
  bundle: true,
13
- external: ["@opencode-ai/*", "@opentui/*", "solid-js", "node:fs", "node:path"],
13
+ external: ["@opencode-ai/*", "@opentui/*", "solid-js", "node:fs", "node:path", "node:crypto"],
14
14
  plugins: [solidPlugin({ solid: { moduleName: "@opentui/solid", generate: "universal" } })],
15
15
  define: { __PLUGIN_VERSION__: JSON.stringify(pkg.version) },
16
16
  logLevel: "info",