@feiyang666/dsh-usage-plugin 1.9.1 → 1.9.3

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,6 @@
1
1
  {
2
2
  "name": "@feiyang666/dsh-usage-plugin",
3
- "version": "1.9.1",
3
+ "version": "1.9.3",
4
4
  "description": "DeepSeek Harness usage & cost tracker plugin: per-call token/cache-hit stats, peak/off-peak billing, DeepSeek balance query, CSV/JSON/PNG export with custom destination, and persistent local storage. Ships a host half plus a web client half in one npm package; installs into a DSH profile as a dsh.bundle with one command (dsh plugin --profile web add @feiyang666/dsh-usage-plugin).",
5
5
  "keywords": [
6
6
  "deepseek",
@@ -21,9 +21,17 @@
21
21
  "url": "git+https://github.com/feiyang-dev/dsh-usage-plugin.git"
22
22
  },
23
23
  "contributors": [
24
+ {
25
+ "name": "Martin-soaring-dev",
26
+ "url": "https://github.com/Martin-soaring-dev"
27
+ },
24
28
  {
25
29
  "name": "liu3734",
26
30
  "url": "https://github.com/liu3734"
31
+ },
32
+ {
33
+ "name": "mumuer1024",
34
+ "url": "https://github.com/mumuer1024"
27
35
  }
28
36
  ],
29
37
  "homepage": "https://github.com/feiyang-dev/dsh-usage-plugin#readme",
package/scripts/wire.js CHANGED
@@ -1,108 +1,109 @@
1
- /**
2
- * dsh-usage-plugin — wiring script (LEGACY fallback).
3
- *
4
- * PREFERRED INSTALL: this package declares `dsh.bundle`, so it auto-activates
5
- * with a single command and NO manual wiring:
6
- *
7
- * dsh plugin --profile web add @feiyang666/dsh-usage-plugin
8
- *
9
- * This script exists only for the manual fallback path (installing the package
10
- * by hand into a profile's node_modules): it appends the plugin row to the
11
- * profile's `cordis.patch.yml` so the plugin loads with the web app:
12
- *
13
- * npm run wire
14
- *
15
- * It is idempotent: running it again never duplicates the row. If it cannot
16
- * find a profile patch it prints what to add manually and exits non-zero.
17
- */
18
- import { readFileSync, writeFileSync, existsSync, readdirSync } from "node:fs";
19
- import { resolve, join, dirname } from "node:path";
20
- import { fileURLToPath } from "node:url";
21
-
22
- const here = dirname(fileURLToPath(import.meta.url));
23
- const pkgDir = resolve(here, "..");
24
- const ROW_ID = "usage-plugin";
25
- const PACKAGE_NAME = JSON.parse(readFileSync(join(pkgDir, "package.json"), "utf8")).name || "dsh-usage-plugin";
26
-
27
- function candidateRoots() {
28
- const roots = [];
29
- // When installed at <profilesRoot>/node_modules/dsh-usage-plugin, the
30
- // profiles root is two levels up; try several depths for other layouts.
31
- for (let up = 1; up <= 4; up++) {
32
- let p = pkgDir;
33
- for (let i = 0; i < up; i++) p = resolve(p, "..");
34
- roots.push(p);
35
- }
36
- if (process.env.DSH_HOME) {
37
- roots.push(join(process.env.DSH_HOME, "profiles"));
38
- roots.push(process.env.DSH_HOME);
39
- }
40
- return roots;
41
- }
42
-
43
- function findPatches(roots) {
44
- const seen = new Set();
45
- const patches = [];
46
- for (const root of roots) {
47
- let entries;
48
- try {
49
- entries = readdirSync(root, { withFileTypes: true });
50
- } catch {
51
- continue;
52
- }
53
- for (const entry of entries) {
54
- if (!entry.isDirectory() || entry.name === "node_modules") continue;
55
- const patch = join(root, entry.name, "cordis.patch.yml");
56
- if (existsSync(patch) && !seen.has(patch)) {
57
- seen.add(patch);
58
- patches.push(patch);
59
- }
60
- }
61
- }
62
- return patches;
63
- }
64
-
65
- function alreadyWired(text) {
66
- return text.includes(`id: ${ROW_ID}`);
67
- }
68
-
69
- function wire(patchPath) {
70
- const text = readFileSync(patchPath, "utf8");
71
- if (alreadyWired(text)) {
72
- console.log(`[dsh-usage-plugin] already wired in ${patchPath}`);
73
- return true;
74
- }
75
- const block =
76
- "\n# " + PACKAGE_NAME + ": usage & cost tracking (installed via npm).\n" +
77
- "- insert:\n" +
78
- " - id: " + ROW_ID + "\n" +
79
- " name: '" + PACKAGE_NAME + "'\n" +
80
- " inject:\n" +
81
- " - fs\n" +
82
- " - webServer\n" +
83
- " - subprocess\n" +
84
- " - credentials\n" +
85
- " - sandboxPolicy\n" +
86
- " - agents\n";
87
- writeFileSync(patchPath, text.endsWith("\n") ? text + block : text + "\n" + block, "utf8");
88
- console.log(`[dsh-usage-plugin] wired into ${patchPath}`);
89
- return true;
90
- }
91
-
92
- const patches = findPatches(candidateRoots());
93
- if (patches.length === 0) {
94
- console.error(
95
- "[dsh-usage-plugin] no DSH profile patch found. Preferred: install with `dsh plugin --profile web add " + PACKAGE_NAME + "` (auto-wires via dsh.bundle, no manual editing).\n" +
96
- "Manual fallback add this row to your profile's cordis.patch.yml, then restart the app:\n\n" +
97
- "- insert:\n" +
98
- " - id: " + ROW_ID + "\n" +
99
- " name: '" + PACKAGE_NAME + "'\n"
100
- );
101
- process.exit(1);
102
- }
103
- let ok = true;
104
- for (const patch of patches) ok = wire(patch) && ok;
105
- if (ok) {
106
- console.log("[dsh-usage-plugin] done. Restart the DeepSeek Harness web app for the plugin to load.");
107
- }
108
- process.exit(ok ? 0 : 1);
1
+ /**
2
+ * dsh-usage-plugin — wiring script (LEGACY fallback).
3
+ *
4
+ * PREFERRED INSTALL: this package declares `dsh.bundle`, so it auto-activates
5
+ * with a single command and NO manual wiring:
6
+ *
7
+ * dsh plugin --profile web add @feiyang666/dsh-usage-plugin
8
+ *
9
+ * This script exists only for the manual fallback path (installing the package
10
+ * by hand into a profile's node_modules): it appends the plugin row to the
11
+ * profile's `cordis.patch.yml` so the plugin loads with the web app:
12
+ *
13
+ * npm run wire
14
+ *
15
+ * It is idempotent: running it again never duplicates the row. If it cannot
16
+ * find a profile patch it prints what to add manually and exits non-zero.
17
+ */
18
+ import { readFileSync, writeFileSync, existsSync, readdirSync } from "node:fs";
19
+ import { resolve, join, dirname } from "node:path";
20
+ import { fileURLToPath } from "node:url";
21
+
22
+ const here = dirname(fileURLToPath(import.meta.url));
23
+ const pkgDir = resolve(here, "..");
24
+ const ROW_ID = "usage-plugin";
25
+ const PACKAGE_NAME = JSON.parse(readFileSync(join(pkgDir, "package.json"), "utf8")).name || "dsh-usage-plugin";
26
+
27
+ function candidateRoots() {
28
+ const roots = [];
29
+ // When installed at <profilesRoot>/node_modules/dsh-usage-plugin, the
30
+ // profiles root is two levels up; try several depths for other layouts.
31
+ for (let up = 1; up <= 4; up++) {
32
+ let p = pkgDir;
33
+ for (let i = 0; i < up; i++) p = resolve(p, "..");
34
+ roots.push(p);
35
+ }
36
+ if (process.env.DSH_HOME) {
37
+ roots.push(join(process.env.DSH_HOME, "profiles"));
38
+ roots.push(process.env.DSH_HOME);
39
+ }
40
+ return roots;
41
+ }
42
+
43
+ function findPatches(roots) {
44
+ const seen = new Set();
45
+ const patches = [];
46
+ for (const root of roots) {
47
+ let entries;
48
+ try {
49
+ entries = readdirSync(root, { withFileTypes: true });
50
+ } catch {
51
+ continue;
52
+ }
53
+ for (const entry of entries) {
54
+ if (!entry.isDirectory() || entry.name === "node_modules") continue;
55
+ const patch = join(root, entry.name, "cordis.patch.yml");
56
+ if (existsSync(patch) && !seen.has(patch)) {
57
+ seen.add(patch);
58
+ patches.push(patch);
59
+ }
60
+ }
61
+ }
62
+ return patches;
63
+ }
64
+
65
+ function alreadyWired(text) {
66
+ return text.includes(`id: ${ROW_ID}`);
67
+ }
68
+
69
+ function wire(patchPath) {
70
+ const text = readFileSync(patchPath, "utf8");
71
+ if (alreadyWired(text)) {
72
+ console.log(`[dsh-usage-plugin] already wired in ${patchPath}`);
73
+ return true;
74
+ }
75
+ const block =
76
+ "\n# " + PACKAGE_NAME + ": usage & cost tracking (installed via npm).\n" +
77
+ "- insert:\n" +
78
+ " - id: " + ROW_ID + "\n" +
79
+ " name: '" + PACKAGE_NAME + "'\n" +
80
+ " inject:\n" +
81
+ " - fs\n" +
82
+ " - webServer\n" +
83
+ " - subprocess\n" +
84
+ " - credentials\n" +
85
+ " - settings\n" +
86
+ " - sandboxPolicy\n" +
87
+ " - agents\n";
88
+ writeFileSync(patchPath, text.endsWith("\n") ? text + block : text + "\n" + block, "utf8");
89
+ console.log(`[dsh-usage-plugin] wired into ${patchPath}`);
90
+ return true;
91
+ }
92
+
93
+ const patches = findPatches(candidateRoots());
94
+ if (patches.length === 0) {
95
+ console.error(
96
+ "[dsh-usage-plugin] no DSH profile patch found. Preferred: install with `dsh plugin --profile web add " + PACKAGE_NAME + "` (auto-wires via dsh.bundle, no manual editing).\n" +
97
+ "Manual fallback — add this row to your profile's cordis.patch.yml, then restart the app:\n\n" +
98
+ "- insert:\n" +
99
+ " - id: " + ROW_ID + "\n" +
100
+ " name: '" + PACKAGE_NAME + "'\n"
101
+ );
102
+ process.exit(1);
103
+ }
104
+ let ok = true;
105
+ for (const patch of patches) ok = wire(patch) && ok;
106
+ if (ok) {
107
+ console.log("[dsh-usage-plugin] done. Restart the DeepSeek Harness web app for the plugin to load.");
108
+ }
109
+ process.exit(ok ? 0 : 1);