dsh-token-chart 0.1.1 → 0.1.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/lib/index.js +39 -6
- package/package.json +1 -1
- package/src/index.ts +36 -5
package/lib/index.js
CHANGED
|
@@ -409,25 +409,58 @@ export function apply(ctx) {
|
|
|
409
409
|
warn('dsh-token-chart: could not read own manifest (%s)', String(error));
|
|
410
410
|
}
|
|
411
411
|
})();
|
|
412
|
+
/**
|
|
413
|
+
* Profile directories worth probing, nearest first.
|
|
414
|
+
*
|
|
415
|
+
* `DSH_PROFILE_DIR` is exported into a profile's *shell calls*, not into the
|
|
416
|
+
* host process, so the desktop app never has it; walking up from this module
|
|
417
|
+
* finds the same directory anyway. The walk also covers pnpm's nested layout,
|
|
418
|
+
* where the package sits under
|
|
419
|
+
* `node_modules/.pnpm/<name>@<version>/node_modules/<name>`.
|
|
420
|
+
*/
|
|
421
|
+
function profileDirCandidates() {
|
|
422
|
+
const list = [];
|
|
423
|
+
const configured = process.env.DSH_PROFILE_DIR;
|
|
424
|
+
if (typeof configured === 'string' && configured.trim() !== '')
|
|
425
|
+
list.push(configured.trim());
|
|
426
|
+
try {
|
|
427
|
+
let dir = path.dirname(fileURLToPath(import.meta.url));
|
|
428
|
+
for (let depth = 0; depth < 8; depth += 1) {
|
|
429
|
+
const parent = path.dirname(dir);
|
|
430
|
+
if (parent === dir)
|
|
431
|
+
break;
|
|
432
|
+
dir = parent;
|
|
433
|
+
list.push(dir);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
catch {
|
|
437
|
+
/* the probe below degrades to `unknown` */
|
|
438
|
+
}
|
|
439
|
+
return list;
|
|
440
|
+
}
|
|
412
441
|
/**
|
|
413
442
|
* How this profile installed the plugin. Only a registry install can update
|
|
414
443
|
* itself: a `link:`/`file:` dependency and an unmounted checkout (the row is
|
|
415
444
|
* mounted from a patch layer, which is how this plugin usually runs) must be
|
|
416
445
|
* updated where they are developed.
|
|
446
|
+
*
|
|
447
|
+
* The profile is the nearest ancestor manifest that declares this package as a
|
|
448
|
+
* dependency — that holds for a registry install and for a linked checkout
|
|
449
|
+
* alike, and it needs no environment variable.
|
|
417
450
|
*/
|
|
418
451
|
function installKind() {
|
|
419
|
-
const dir
|
|
420
|
-
if (typeof dir === 'string' && dir.trim() !== '') {
|
|
452
|
+
for (const dir of profileDirCandidates()) {
|
|
421
453
|
try {
|
|
422
|
-
const profile = JSON.parse(readFileSync(path.join(dir
|
|
454
|
+
const profile = JSON.parse(readFileSync(path.join(dir, 'package.json'), 'utf8'));
|
|
423
455
|
const spec = String(profile?.dependencies?.[manifest.name] ?? '');
|
|
456
|
+
if (spec === '')
|
|
457
|
+
continue;
|
|
424
458
|
if (spec.startsWith('link:') || spec.startsWith('file:'))
|
|
425
459
|
return { kind: 'local', spec };
|
|
426
|
-
|
|
427
|
-
return { kind: 'registry', spec };
|
|
460
|
+
return { kind: 'registry', spec };
|
|
428
461
|
}
|
|
429
462
|
catch {
|
|
430
|
-
/*
|
|
463
|
+
/* try the next candidate */
|
|
431
464
|
}
|
|
432
465
|
}
|
|
433
466
|
// No profile dependency: distinguish a checkout from an unknown install.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-token-chart",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Token usage statistics and chart visualization for DeepSeek Harness: per-session drawer, today / last 3 / last 7 days panel, and chart configuration.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
package/src/index.ts
CHANGED
|
@@ -434,22 +434,53 @@ export function apply(ctx: HostContext): void {
|
|
|
434
434
|
}
|
|
435
435
|
})()
|
|
436
436
|
|
|
437
|
+
/**
|
|
438
|
+
* Profile directories worth probing, nearest first.
|
|
439
|
+
*
|
|
440
|
+
* `DSH_PROFILE_DIR` is exported into a profile's *shell calls*, not into the
|
|
441
|
+
* host process, so the desktop app never has it; walking up from this module
|
|
442
|
+
* finds the same directory anyway. The walk also covers pnpm's nested layout,
|
|
443
|
+
* where the package sits under
|
|
444
|
+
* `node_modules/.pnpm/<name>@<version>/node_modules/<name>`.
|
|
445
|
+
*/
|
|
446
|
+
function profileDirCandidates(): string[] {
|
|
447
|
+
const list: string[] = []
|
|
448
|
+
const configured = process.env.DSH_PROFILE_DIR
|
|
449
|
+
if (typeof configured === 'string' && configured.trim() !== '') list.push(configured.trim())
|
|
450
|
+
try {
|
|
451
|
+
let dir = path.dirname(fileURLToPath(import.meta.url))
|
|
452
|
+
for (let depth = 0; depth < 8; depth += 1) {
|
|
453
|
+
const parent = path.dirname(dir)
|
|
454
|
+
if (parent === dir) break
|
|
455
|
+
dir = parent
|
|
456
|
+
list.push(dir)
|
|
457
|
+
}
|
|
458
|
+
} catch {
|
|
459
|
+
/* the probe below degrades to `unknown` */
|
|
460
|
+
}
|
|
461
|
+
return list
|
|
462
|
+
}
|
|
463
|
+
|
|
437
464
|
/**
|
|
438
465
|
* How this profile installed the plugin. Only a registry install can update
|
|
439
466
|
* itself: a `link:`/`file:` dependency and an unmounted checkout (the row is
|
|
440
467
|
* mounted from a patch layer, which is how this plugin usually runs) must be
|
|
441
468
|
* updated where they are developed.
|
|
469
|
+
*
|
|
470
|
+
* The profile is the nearest ancestor manifest that declares this package as a
|
|
471
|
+
* dependency — that holds for a registry install and for a linked checkout
|
|
472
|
+
* alike, and it needs no environment variable.
|
|
442
473
|
*/
|
|
443
474
|
function installKind(): VersionReport['install'] {
|
|
444
|
-
const dir
|
|
445
|
-
if (typeof dir === 'string' && dir.trim() !== '') {
|
|
475
|
+
for (const dir of profileDirCandidates()) {
|
|
446
476
|
try {
|
|
447
|
-
const profile = JSON.parse(readFileSync(path.join(dir
|
|
477
|
+
const profile = JSON.parse(readFileSync(path.join(dir, 'package.json'), 'utf8'))
|
|
448
478
|
const spec = String(profile?.dependencies?.[manifest.name] ?? '')
|
|
479
|
+
if (spec === '') continue
|
|
449
480
|
if (spec.startsWith('link:') || spec.startsWith('file:')) return { kind: 'local', spec }
|
|
450
|
-
|
|
481
|
+
return { kind: 'registry', spec }
|
|
451
482
|
} catch {
|
|
452
|
-
/*
|
|
483
|
+
/* try the next candidate */
|
|
453
484
|
}
|
|
454
485
|
}
|
|
455
486
|
// No profile dependency: distinguish a checkout from an unknown install.
|