opencode-go-usage-tui 1.0.1 → 1.2.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,7 +1,15 @@
1
1
  # opencode-go-usage-tui
2
2
 
3
+ <div align="center">
4
+
5
+ 🌏 **语言 / Language:** [简体中文](/README.md) | [English](/README_EN.md)
6
+
7
+ </div>
8
+
3
9
  在 OpenCode 侧边栏实时显示 OpenCode Go 额度用量(5小时/每周/每月)。
4
10
 
11
+ 支持中英双语界面(`/go-lang` 切换,首次启动自动引导选择语言)。
12
+
5
13
  ## 安装
6
14
 
7
15
  ### 方式一:OpenCode 命令安装(推荐)
@@ -45,7 +53,15 @@ npm install -g opencode-go-usage-tui
45
53
  1. **workspace_id**:`wrk_` 开头,在 opencode.ai 控制台 URL 中获取
46
54
  2. **auth cookie**:浏览器 F12 → Application → Cookies → opencode.ai → 复制 `auth` 的值(`Fe26.2*` 开头)
47
55
 
48
- 配置保存在 `~/.config/opencode/go-usage-config.json`。
56
+ 配置保存在 `~/.config/opencode/`:
57
+
58
+ - `go-usage-config.json` — workspace_id(明文,非敏感)
59
+ - `go-auth-cookie.enc` — auth cookie(**AES-256-GCM 加密**)
60
+ - `.encryption-key` — 加密密钥(32 字节随机生成)
61
+
62
+ > 🔒 **安全说明**:cookie 以 AES-256-GCM 加密存储,密钥随机生成且独立保存,文件被备份/同步/日志收集不会泄露 cookie。旧版明文文件(`go-auth-cookie.txt` / config.json 内嵌 cookie)首次读取时**自动迁移**为加密存储并清理明文。
63
+ >
64
+ > ⚠️ 局限:密钥与密文同目录,能防御"被动泄露"(备份/同步),无法防御能读取该目录的本地恶意程序。如需更强保护可改用系统级凭据存储。
49
65
 
50
66
  ### 方式二:环境变量
51
67
 
@@ -79,6 +95,13 @@ Cookie 有效期约 1 年,过期后重新获取。
79
95
  - 用量超过阈值(默认 80%,可用 `OPENCODE_GO_WARN_THRESHOLD` 调整)显示为红色
80
96
  - 点击面板标题可折叠/展开
81
97
  - 配置错误时面板会提示"未配置账号",输入 `/go-config` 即可设置
98
+ - 面板标题显示当前插件版本号(如 `v1.1.0`)
99
+
100
+ ## 语言
101
+
102
+ - 首次安装启动时自动弹出语言选择,选择后若未配置账号会继续引导 `/go-config`
103
+ - 随时执行 `/go-lang` 可切换 中文 / English,语言偏好会记住
104
+ - 自动检测系统语言(中文系统默认中文,其余默认英文)
82
105
 
83
106
  ## 开发
84
107
 
package/README_EN.md ADDED
@@ -0,0 +1,117 @@
1
+ # opencode-go-usage-tui
2
+
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) in the OpenCode sidebar in real time.
10
+
11
+ Bilingual UI (Chinese / English) — switch with `/go-lang`, or pick a language during the first-run onboarding.
12
+
13
+ ## Install
14
+
15
+ ### Option 1: Install via OpenCode command (recommended)
16
+
17
+ In OpenCode, press **`Ctrl+P`** to open the command palette, search for **`install plugin`**, and enter:
18
+
19
+ ```
20
+ opencode-go-usage-tui@latest
21
+ ```
22
+
23
+ Press Enter, restart OpenCode, and the "Go Usage" panel will appear in the sidebar.
24
+
25
+ ### Option 2: npm global install
26
+
27
+ ```bash
28
+ npm install -g opencode-go-usage-tui
29
+ ```
30
+
31
+ Then add it to the `plugin` array in `~/.config/opencode/tui.json`:
32
+
33
+ ```json
34
+ {
35
+ "plugin": ["opencode-go-usage-tui@latest"]
36
+ }
37
+ ```
38
+
39
+ Restart OpenCode.
40
+
41
+ ## Configuration
42
+
43
+ ### Option 1: Slash command (recommended)
44
+
45
+ Run in the TUI:
46
+
47
+ ```
48
+ /go-config
49
+ ```
50
+
51
+ Enter two values (unique per user — get them by logging into opencode.ai):
52
+
53
+ 1. **workspace_id**: starts with `wrk_`, found in the opencode.ai console URL
54
+ 2. **auth cookie**: in your browser, F12 → Application → Cookies → opencode.ai → copy the `auth` value (starts with `Fe26.2*`)
55
+
56
+ Config is saved to `~/.config/opencode/`:
57
+
58
+ - `go-usage-config.json` — workspace_id (plain text, not sensitive)
59
+ - `go-auth-cookie.enc` — auth cookie (**AES-256-GCM encrypted**)
60
+ - `.encryption-key` — encryption key (random 32 bytes)
61
+
62
+ > 🔒 **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.
63
+ >
64
+ > ⚠️ 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.
65
+
66
+ ### Option 2: Environment variables
67
+
68
+ | Variable | Description |
69
+ | -------- | ----------- |
70
+ | `OPENCODE_GO_WORKSPACE_ID` | Workspace ID |
71
+ | `OPENCODE_GO_AUTH_COOKIE` | Auth cookie value |
72
+
73
+ ### Option 3: Config file
74
+
75
+ Create `~/.config/opencode/go-usage-config.json` manually:
76
+
77
+ ```json
78
+ {
79
+ "workspace_id": "wrk_xxxxxxxxxxxx",
80
+ "cookie": "Fe26.2*..."
81
+ }
82
+ ```
83
+
84
+ ## Getting the auth cookie
85
+
86
+ 1. Log into opencode.ai in Chrome
87
+ 2. Press F12 to open DevTools → Application → Cookies → select opencode.ai
88
+ 3. Find `auth`, copy its Value
89
+
90
+ The cookie is valid for about 1 year; get a new one after it expires.
91
+
92
+ ## Usage
93
+
94
+ - The sidebar panel auto-refreshes every 60 seconds (adjustable via `OPENCODE_GO_CHECK_INTERVAL`, in milliseconds)
95
+ - Usage above the threshold (default 80%, adjustable via `OPENCODE_GO_WARN_THRESHOLD`) is shown in red
96
+ - Click the panel title to collapse/expand
97
+ - If misconfigured, the panel shows "Not configured" — run `/go-config` to set up
98
+ - The panel title shows the current plugin version (e.g. `v1.1.0`)
99
+
100
+ ## Language
101
+
102
+ - On first install, a language picker pops up automatically; if the account isn't configured yet, it continues into the `/go-config` onboarding
103
+ - Run `/go-lang` anytime to switch between 中文 / English; your preference is remembered
104
+ - Auto-detects system language (Chinese systems default to 中文, everything else defaults to English)
105
+
106
+ ## Development
107
+
108
+ ```bash
109
+ # Build
110
+ bun run build.tui.mjs
111
+ # or
112
+ npm run build
113
+ ```
114
+
115
+ ## License
116
+
117
+ MIT
package/build.tui.mjs CHANGED
@@ -1,5 +1,8 @@
1
1
  import * as esbuild from "esbuild"
2
2
  import { solidPlugin } from "esbuild-plugin-solid"
3
+ import { readFileSync } from "node:fs"
4
+
5
+ const pkg = JSON.parse(readFileSync("package.json", "utf8"))
3
6
 
4
7
  await esbuild.build({
5
8
  entryPoints: ["src/index.tsx"],
@@ -7,7 +10,8 @@ await esbuild.build({
7
10
  format: "esm",
8
11
  platform: "node",
9
12
  bundle: true,
10
- external: ["@opencode-ai/*", "@opentui/*", "solid-js", "node:fs", "node:path"],
13
+ external: ["@opencode-ai/*", "@opentui/*", "solid-js", "node:fs", "node:path", "node:crypto"],
11
14
  plugins: [solidPlugin({ solid: { moduleName: "@opentui/solid", generate: "universal" } })],
15
+ define: { __PLUGIN_VERSION__: JSON.stringify(pkg.version) },
12
16
  logLevel: "info",
13
17
  })