@yangzhenchen/dsh-balance 0.0.0-stage → 0.4.2

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/package.json CHANGED
@@ -1,6 +1,61 @@
1
1
  {
2
2
  "name": "@yangzhenchen/dsh-balance",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.4.2",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "description": "DeepSeek account balance, DeepSeek peak/off-peak price hints, and a token-activity heatmap (local sessions or account-wide platform usage) pinned above the account avatar in the DeepSeek Harness sidebar.",
8
+ "type": "module",
9
+ "main": "lib/index.js",
10
+ "exports": {
11
+ ".": "./lib/index.js",
12
+ "./client": "./lib/client.js",
13
+ "./package.json": "./package.json"
14
+ },
15
+ "dsh": {
16
+ "manifestVersion": 1,
17
+ "bundle": {
18
+ "patch": "./cordis.patch.yml"
19
+ },
20
+ "client": {
21
+ "platform": "web"
22
+ }
23
+ },
24
+ "files": [
25
+ "lib",
26
+ "scripts",
27
+ "cordis.patch.yml",
28
+ "README.md",
29
+ "LICENSE",
30
+ "preview.png"
31
+ ],
32
+ "keywords": [
33
+ "dsh",
34
+ "deepseek-harness",
35
+ "plugin",
36
+ "balance",
37
+ "tokens",
38
+ "usage",
39
+ "heatmap",
40
+ "pricing",
41
+ "peak",
42
+ "off-peak",
43
+ "sidebar"
44
+ ],
45
+ "author": "yang-zhenchen",
46
+ "license": "MIT",
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "git+https://github.com/yang-zhenchen/dsh-balance.git"
50
+ },
51
+ "homepage": "https://github.com/yang-zhenchen/dsh-balance#readme",
52
+ "bugs": {
53
+ "url": "https://github.com/yang-zhenchen/dsh-balance/issues"
54
+ },
55
+ "peerDependencies": {
56
+ "@deepseek-ai/cordis": "~4.0.5"
57
+ },
58
+ "scripts": {
59
+ "test": "node test/smoke.mjs && node test/usage.mjs && node test/account.mjs && node test/host.mjs"
60
+ }
6
61
  }
package/preview.png ADDED
Binary file
@@ -0,0 +1,69 @@
1
+ // Safely add this plugin to a DSH profile: a link dependency plus the bundle
2
+ // selection, written as 2-space JSON without a BOM. The script only edits the
3
+ // profile manifest; run `pnpm install` in the profile afterwards.
4
+ //
5
+ // Usage:
6
+ // node scripts/enable-bundle.mjs
7
+ // node scripts/enable-bundle.mjs --profile desktop
8
+ // node scripts/enable-bundle.mjs --profile C:\path\to\profile
9
+ import fs from 'node:fs';
10
+ import os from 'node:os';
11
+ import path from 'node:path';
12
+ import { fileURLToPath } from 'node:url';
13
+
14
+ /** The published package name; it is also the Loader module name. */
15
+ const PACKAGE = '@yangzhenchen/dsh-balance';
16
+
17
+ function fail(message) {
18
+ console.error(message);
19
+ process.exit(1);
20
+ }
21
+
22
+ function resolveProfileDir(argv) {
23
+ const at = argv.indexOf('--profile');
24
+ const value = at >= 0 ? argv[at + 1] : 'desktop';
25
+ if (!value) fail('--profile 需要一个值(profile 名称或目录)');
26
+ if (path.isAbsolute(value) || value.includes('/') || value.includes('\\')) return path.resolve(value);
27
+ const home = process.env.DSH_HOME ? path.resolve(process.env.DSH_HOME) : path.join(os.homedir(), '.dsh');
28
+ return path.join(home, 'profiles', value);
29
+ }
30
+
31
+ const pluginDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
32
+ const profileDir = resolveProfileDir(process.argv.slice(2));
33
+ const file = path.join(profileDir, 'package.json');
34
+ if (!fs.existsSync(file)) fail(`找不到 profile manifest:${file}`);
35
+
36
+ const raw = fs.readFileSync(file);
37
+ let text = raw.toString('utf8').replace(/^\uFEFF/u, '');
38
+ let manifest;
39
+ try {
40
+ manifest = JSON.parse(text);
41
+ } catch (error) {
42
+ fail(`没有修改:${file} 不是合法 JSON\n${error.message}\n如果开头有 BOM,先运行 node scripts/repair-profile.mjs`);
43
+ }
44
+ if (manifest === null || typeof manifest !== 'object' || Array.isArray(manifest)) {
45
+ fail(`没有修改:${file} 顶层必须是 JSON 对象`);
46
+ }
47
+
48
+ const spec = `link:${pluginDir.replaceAll('\\', '/')}`;
49
+ const OLD_NAMES = ['dsh-plugin-balance', '@yang-zhenchen/dsh-balance'];
50
+ manifest.dependencies = manifest.dependencies ?? {};
51
+ // Drop stale dependency keys and bundle entries from earlier package names so
52
+ // a rename migrates in place.
53
+ for (const name of OLD_NAMES) delete manifest.dependencies[name];
54
+ manifest.dependencies[PACKAGE] = spec;
55
+ manifest.dsh = manifest.dsh ?? {};
56
+ manifest.dsh.profile = manifest.dsh.profile ?? {};
57
+ manifest.dsh.profile.bundles = (Array.isArray(manifest.dsh.profile.bundles) ? manifest.dsh.profile.bundles : []).filter((name) => !OLD_NAMES.includes(name));
58
+ if (!manifest.dsh.profile.bundles.includes(PACKAGE)) {
59
+ manifest.dsh.profile.bundles.push(PACKAGE);
60
+ }
61
+
62
+ const backup = `${file}.bak-${Date.now()}`;
63
+ fs.copyFileSync(file, backup);
64
+ fs.writeFileSync(file, `${JSON.stringify(manifest, void 0, 2)}\n`, 'utf8');
65
+ console.log(`已写入:${file}`);
66
+ console.log(`依赖:${PACKAGE} => ${spec}`);
67
+ console.log(`bundle:${PACKAGE}`);
68
+ console.log(`备份:${backup}`);
69
+ console.log(`下一步:cd "${profileDir}" 然后运行 pnpm install`);
@@ -0,0 +1,58 @@
1
+ // Repair a DSH profile manifest that was saved as UTF-8 with a BOM.
2
+ //
3
+ // DSH reads <profile>/package.json with JSON.parse, which rejects a leading
4
+ // U+FEFF. This script removes only that BOM, keeps the rest of the file
5
+ // byte-for-byte, validates the JSON first, and writes a backup.
6
+ //
7
+ // Usage:
8
+ // node scripts/repair-profile.mjs
9
+ // node scripts/repair-profile.mjs --profile desktop
10
+ // node scripts/repair-profile.mjs --profile C:\path\to\profile
11
+ import fs from 'node:fs';
12
+ import os from 'node:os';
13
+ import path from 'node:path';
14
+
15
+ function fail(message) {
16
+ console.error(message);
17
+ process.exit(1);
18
+ }
19
+
20
+ function resolveProfileDir(argv) {
21
+ const at = argv.indexOf('--profile');
22
+ const value = at >= 0 ? argv[at + 1] : 'desktop';
23
+ if (!value) fail('--profile 需要一个值(profile 名称或目录)');
24
+ if (path.isAbsolute(value) || value.includes('/') || value.includes('\\')) return path.resolve(value);
25
+ const home = process.env.DSH_HOME ? path.resolve(process.env.DSH_HOME) : path.join(os.homedir(), '.dsh');
26
+ return path.join(home, 'profiles', value);
27
+ }
28
+
29
+ const profileDir = resolveProfileDir(process.argv.slice(2));
30
+ const file = path.join(profileDir, 'package.json');
31
+ if (!fs.existsSync(file)) fail(`找不到 profile manifest:${file}`);
32
+
33
+ const raw = fs.readFileSync(file);
34
+ const hasBom = raw.length >= 3 && raw[0] === 0xef && raw[1] === 0xbb && raw[2] === 0xbf;
35
+ let text = raw.toString('utf8');
36
+ if (hasBom) text = text.replace(/^\uFEFF/u, '');
37
+
38
+ let parsed;
39
+ try {
40
+ parsed = JSON.parse(text);
41
+ } catch (error) {
42
+ fail(`没有修改:${file} 不是合法 JSON\n${error.message}`);
43
+ }
44
+ if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
45
+ fail(`没有修改:${file} 顶层必须是 JSON 对象`);
46
+ }
47
+
48
+ if (!hasBom) {
49
+ console.log(`没有 BOM,无需修复:${file}`);
50
+ process.exit(0);
51
+ }
52
+
53
+ const backup = `${file}.bak-${Date.now()}`;
54
+ fs.copyFileSync(file, backup);
55
+ fs.writeFileSync(file, text, 'utf8');
56
+ console.log(`已移除 BOM:${file}`);
57
+ console.log(`备份:${backup}`);
58
+ console.log('请重新启动 DeepSeek Harness。');