dsh-bottom-info-bar 1.20.3 → 1.20.4

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 (2) hide show
  1. package/lib/index.js +37 -11
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -21,7 +21,7 @@ import { createSelfUpdater } from './self-update.js'
21
21
  import * as hostLocale from './host-locale.js'
22
22
  const t = hostLocale.createHostTranslator()
23
23
 
24
- const DATA_DIR = process.env.DSH_BOTTOM_INFO_BAR_DATA_DIR || join(homedir(), '.dsh', 'dsh-bottom-info-bar')
24
+ const DATA_DIR = process.env.DSH_BOTTOM_INFO_BAR_DATA_DIR || join(dshHomeDir(), 'dsh-bottom-info-bar')
25
25
  const DATA_FILE = join(DATA_DIR, 'usage-records.json')
26
26
  const DATA_BACKUP_FILE = DATA_FILE + '.bak'
27
27
  const DATA_TEMP_FILE = DATA_FILE + '.tmp'
@@ -101,6 +101,13 @@ function dshHomeDir() {
101
101
  const configured = typeof process.env.DSH_HOME === 'string' ? process.env.DSH_HOME.trim() : ''
102
102
  return configured.length > 0 ? configured : join(homedir(), '.dsh')
103
103
  }
104
+ // ---------- 路径唯一入口(P0-3,用户拍板:网页端与桌面端分开) ----------
105
+ // 本插件自己的数据(账本/设置/价目缓存/更新状态)跟随「所在端的家目录」:
106
+ // DSH_HOME 有值 → 数据落该端名下,网页端与桌面端各归各,互不读写;
107
+ // 无值 → 沿用历史默认(与原来逐字相同,老用户路径一字不差,不搬家)。
108
+ // 环境变量 DSH_BOTTOM_INFO_BAR_DATA_DIR 永远优先(测试与特殊部署用)。
109
+ // 登录态文件(~/.codex/auth.json 等)是「人」的身份不是「端」的数据,只读不写,原地不动——
110
+ // 换端不断登,账本分开算,两件事不要混在一起。
104
111
 
105
112
  // 「更新命令」取决于本插件是怎么装上的,两者不能混用:
106
113
  // - npm 安装 → dsh plugin add …@latest;
@@ -310,7 +317,24 @@ const SUBSCRIPTION_RETRY_BACKOFF_MS = 60000 // 订阅刷新失败后的退避期
310
317
  // 订阅源 auth 文件路径(可用环境变量覆盖——测试隔离用,避免测试误读真实登录态);
311
318
  // 本插件只读令牌查询额度,令牌的绑定/续期由独立插件 dsh-chatgpt-sub 维护
312
319
  const CODEX_AUTH_FILE = process.env.DSH_BOTTOM_INFO_BAR_CODEX_AUTH || join(homedir(), '.codex', 'auth.json')
313
- const OPENCODE_AUTH_FILE = process.env.DSH_BOTTOM_INFO_BAR_OPENCODE_AUTH || join(homedir(), '.local', 'share', 'opencode', 'auth.json')
320
+ // 平台共享目录:POSIX 沿用 ~/.local/share;Windows 走 %LOCALAPPDATA%。
321
+ // 平台分支只在这里做一次,调用方只读结果。
322
+ function platformShareDir() {
323
+ if (process.platform === 'win32' && typeof process.env.LOCALAPPDATA === 'string' && process.env.LOCALAPPDATA.length > 0) return process.env.LOCALAPPDATA
324
+ return join(homedir(), '.local', 'share')
325
+ }
326
+ // opencode 登录文件候选位置(按序试读,先命中即用):显式环境变量 → 平台共享目录 → 历史 POSIX 路径。
327
+ // Windows 下真实位置未经实测,用「新老都试」代替「猜一个」:原来认得出来的现在还认得出来,
328
+ // 原来认不出来的现在多一次机会。非 Windows 平台候选归一,与原来逐字相同。
329
+ function opencodeAuthFiles() {
330
+ if (typeof process.env.DSH_BOTTOM_INFO_BAR_OPENCODE_AUTH === 'string' && process.env.DSH_BOTTOM_INFO_BAR_OPENCODE_AUTH.length > 0) {
331
+ return [process.env.DSH_BOTTOM_INFO_BAR_OPENCODE_AUTH]
332
+ }
333
+ const files = [join(platformShareDir(), 'opencode', 'auth.json')]
334
+ const legacy = join(homedir(), '.local', 'share', 'opencode', 'auth.json')
335
+ if (files[0] !== legacy) files.push(legacy)
336
+ return files
337
+ }
314
338
  const COMMAND_CODE_AUTH_FILE = process.env.DSH_BOTTOM_INFO_BAR_COMMAND_CODE_AUTH || join(homedir(), '.commandcode', 'auth.json')
315
339
  const COMMAND_CODE_API_BASE = 'https://api.commandcode.ai'
316
340
  const COMMAND_CODE_PLAN_TOTAL_CREDITS = {
@@ -2416,16 +2440,18 @@ export default {
2416
2440
  const cred = await ctx.credentials.resolve('OPENCODE_GO_API_KEY');
2417
2441
  if (cred && typeof cred.value === 'string' && cred.value.length > 0) return cred.value;
2418
2442
  } catch (err) { /* 回退到 auth.json */ }
2419
- try {
2420
- const auth = JSON.parse(readFileSync(OPENCODE_AUTH_FILE, 'utf8'));
2421
- for (const name of ['opencode-go', 'opencode']) {
2422
- const entry = auth && auth[name];
2423
- if (entry && typeof entry === 'object') {
2424
- if (typeof entry.key === 'string' && entry.key.length > 0) return entry.key;
2425
- if (typeof entry.apiKey === 'string' && entry.apiKey.length > 0) return entry.apiKey;
2443
+ for (const file of opencodeAuthFiles()) {
2444
+ try {
2445
+ const auth = JSON.parse(readFileSync(file, 'utf8'));
2446
+ for (const name of ['opencode-go', 'opencode']) {
2447
+ const entry = auth && auth[name];
2448
+ if (entry && typeof entry === 'object') {
2449
+ if (typeof entry.key === 'string' && entry.key.length > 0) return entry.key;
2450
+ if (typeof entry.apiKey === 'string' && entry.apiKey.length > 0) return entry.apiKey;
2451
+ }
2426
2452
  }
2427
- }
2428
- } catch (err) { /* 未配置 → 返回 null */ }
2453
+ } catch (err) { /* 该候选无文件/损坏 → 试下一个 */ }
2454
+ }
2429
2455
  return null;
2430
2456
  }
2431
2457
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-bottom-info-bar",
3
- "version": "1.20.3",
3
+ "version": "1.20.4",
4
4
  "description": "Shows the current model, balance and spend under the composer.",
5
5
  "keywords": [
6
6
  "deepseek",