@hashimkarim/usagestat 2.0.0-alpha.1
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/LICENSE +21 -0
- package/README.md +96 -0
- package/bin/usagestat.cjs +3 -0
- package/bin/usagestatd.cjs +3 -0
- package/launcher.cjs +118 -0
- package/package.json +37 -0
- package/platforms.json +32 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Hashim-K
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# usagestat native backend through npm
|
|
2
|
+
|
|
3
|
+
Install the v2 backend alpha explicitly through the `alpha` npm tag. It contains
|
|
4
|
+
the CLI, daemon, local dashboard and provider plugins. Windows/macOS bar frontends
|
|
5
|
+
are not included. Desktop login/reboot, browser authentication and minimum-OS
|
|
6
|
+
acceptance remain pending; Windows/macOS binaries are unsigned.
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npm install --global @hashimkarim/usagestat@alpha --include=optional --ignore-scripts
|
|
10
|
+
usagestat --version
|
|
11
|
+
usagestat doctor
|
|
12
|
+
usagestat --json list
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Use Node.js 24 or newer and npm 11.5.1 or newer. Exact-version optional platform
|
|
16
|
+
packages contain the Rust CLI, daemon, plugins, icons and license notices.
|
|
17
|
+
Installation needs no Rust compiler, shell scripts or download hooks. It does
|
|
18
|
+
not start a daemon or install a login service. Native packages also remain
|
|
19
|
+
available separately for users who do not need Node.
|
|
20
|
+
|
|
21
|
+
Candidate npm targets are Linux x64/ARM64 with glibc 2.39+, macOS 13.5+ on Intel/Apple
|
|
22
|
+
Silicon, and Windows 10 / Server 2016+ x64. musl/Alpine, Windows ARM64 and 32-bit
|
|
23
|
+
systems are unsupported. Stable packages include only qualified targets;
|
|
24
|
+
macOS/Windows minimum-system qualification and signing are still pending.
|
|
25
|
+
The Rust macOS artifact targets 11.0; the npm wrapper's higher floor comes from
|
|
26
|
+
[Node.js 24's platform requirements](https://github.com/nodejs/node/blob/v24.x/BUILDING.md#platform-list).
|
|
27
|
+
|
|
28
|
+
To use a background daemon after a durable global installation:
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
usagestat daemon enable
|
|
32
|
+
usagestat daemon status
|
|
33
|
+
usagestat dashboard
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The native CLI registers its actual sibling backend with the current user's
|
|
37
|
+
systemd, LaunchAgent or Task Scheduler. Login startup does not require Node or
|
|
38
|
+
an interactive shell. Configuration, history, T3 keys and credentials stay in
|
|
39
|
+
the usual per-user locations outside npm's package/cache directories. Existing
|
|
40
|
+
native/Homebrew/bar installations retain ownership until an explicit owner
|
|
41
|
+
switch. Use `daemon enable --switch-owner` only when intentionally transferring
|
|
42
|
+
this profile to the npm installation.
|
|
43
|
+
|
|
44
|
+
For an explicit update, record the old package version and `daemon status --json`,
|
|
45
|
+
including its independent `running` and `autostart` values. For an existing managed
|
|
46
|
+
installation, stop and disable the daemon before replacing its files. This releases
|
|
47
|
+
Windows executable locks. Use the same durable npm global prefix:
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
usagestat daemon status --json
|
|
51
|
+
usagestat daemon disable
|
|
52
|
+
npm install --global @hashimkarim/usagestat@VERSION --include=optional --ignore-scripts
|
|
53
|
+
usagestat --version
|
|
54
|
+
usagestat doctor
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
After a successful install, restore the saved state using the retained registration:
|
|
58
|
+
|
|
59
|
+
| Previous running / autostart | Commands after installation |
|
|
60
|
+
| --- | --- |
|
|
61
|
+
| Yes / Yes | `usagestat daemon autostart on`, then `usagestat daemon start` |
|
|
62
|
+
| No / Yes | `usagestat daemon autostart on`; leave it stopped |
|
|
63
|
+
| Yes / No | `usagestat daemon start`; leave autostart off |
|
|
64
|
+
| No / No | Leave both off |
|
|
65
|
+
|
|
66
|
+
An installation that never registered a daemon needs only the npm install and
|
|
67
|
+
verification steps. T3 intent, keys and user data survive replacement. Verify
|
|
68
|
+
health with `daemon status --json` after starting. If installation is interrupted
|
|
69
|
+
or the replacement fails, keep startup off and reinstall the recorded previous
|
|
70
|
+
exact npm version, then restore the state above. Keep that package available until
|
|
71
|
+
the update is verified. These are explicit recovery steps; npm replacement is not
|
|
72
|
+
an automatic transaction. When changing a Node version manager or npm global
|
|
73
|
+
prefix, unregister the old installation first, install into the new durable
|
|
74
|
+
prefix, and explicitly transfer ownership with `daemon enable --switch-owner`.
|
|
75
|
+
Restore the previous running/autostart preferences afterward.
|
|
76
|
+
|
|
77
|
+
Before removal:
|
|
78
|
+
|
|
79
|
+
```sh
|
|
80
|
+
usagestat daemon unregister
|
|
81
|
+
npm uninstall --global @hashimkarim/usagestat --ignore-scripts
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Unregister removes the owned login entry while retaining user data and saved
|
|
85
|
+
preferences. Lifecycle hooks are never required for cleanup. Do not
|
|
86
|
+
remove the files of a running Windows service. A one-off
|
|
87
|
+
`npm exec --package=@hashimkarim/usagestat@alpha -- usagestat --version` is suitable for
|
|
88
|
+
CLI use; persistent startup from the temporary `_npx`/`_cacache` path is rejected.
|
|
89
|
+
Project-local installations can own startup only while their directory remains
|
|
90
|
+
durable. Prefer a global installation for services.
|
|
91
|
+
|
|
92
|
+
`native-package-missing` means optional dependencies were omitted: reinstall with
|
|
93
|
+
`--include=optional`. Version/integrity failures require reinstalling the exact
|
|
94
|
+
main-package version. A package cannot remove native OS/glibc requirements.
|
|
95
|
+
On Windows, use npm's generated `.cmd` command shims from Command Prompt, or the
|
|
96
|
+
`.cmd` command from PowerShell when its script policy blocks the generated `.ps1`.
|
package/launcher.cjs
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const os = require('node:os');
|
|
6
|
+
const crypto = require('node:crypto');
|
|
7
|
+
const { spawn } = require('node:child_process');
|
|
8
|
+
|
|
9
|
+
function failure(code, message) {
|
|
10
|
+
const error = new Error(message);
|
|
11
|
+
error.code = code;
|
|
12
|
+
throw error;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function selectTarget(platform, architecture, glibc) {
|
|
16
|
+
if (platform === 'linux') {
|
|
17
|
+
if (!glibc) failure('unsupported-libc', 'This package requires glibc 2.39 or newer; musl/Alpine is not supported.');
|
|
18
|
+
const [major, minor] = glibc.split('.').map(Number);
|
|
19
|
+
if (!(major > 2 || (major === 2 && minor >= 39))) {
|
|
20
|
+
failure('glibc-too-old', `Detected glibc ${glibc}; the native backend requires glibc 2.39 or newer.`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const key = `${platform}-${architecture}${platform === 'linux' ? '-gnu' : ''}`;
|
|
24
|
+
if (!['linux-x64-gnu', 'linux-arm64-gnu', 'darwin-x64', 'darwin-arm64', 'win32-x64'].includes(key)) {
|
|
25
|
+
failure('unsupported-target', `No native backend is available for ${platform}/${architecture}.`);
|
|
26
|
+
}
|
|
27
|
+
return key;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function sha256(bytes) { return crypto.createHash('sha256').update(bytes).digest('hex'); }
|
|
31
|
+
|
|
32
|
+
function resolveNative(command, packageRoot = __dirname) {
|
|
33
|
+
if (!['usagestat', 'usagestatd'].includes(command)) failure('invalid-command', 'Unknown backend command.');
|
|
34
|
+
if (Number(process.versions.node.split('.')[0]) < 24) failure('node-too-old', 'Use Node.js 24 or newer.');
|
|
35
|
+
const own = JSON.parse(fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf8'));
|
|
36
|
+
const platforms = JSON.parse(fs.readFileSync(path.join(packageRoot, 'platforms.json'), 'utf8'));
|
|
37
|
+
const glibc = process.platform === 'linux' ? process.report.getReport().header.glibcVersionRuntime : undefined;
|
|
38
|
+
const target = selectTarget(process.platform, process.arch, glibc);
|
|
39
|
+
const selected = platforms[target];
|
|
40
|
+
if (!selected) failure('target-not-qualified', `This release does not include a qualified ${target} backend. Use a supported release channel.`);
|
|
41
|
+
if (process.platform === 'darwin' && Number(os.release().split('.')[0]) < 22) {
|
|
42
|
+
failure('macos-too-old', 'This npm wrapper uses Node.js 24, which requires macOS 13.5 or newer.');
|
|
43
|
+
}
|
|
44
|
+
if (process.platform === 'win32' && Number(os.release().split('.')[0]) < 10) {
|
|
45
|
+
failure('windows-too-old', 'The native backend requires Windows 10 / Server 2016 or newer.');
|
|
46
|
+
}
|
|
47
|
+
let manifestPath;
|
|
48
|
+
try { manifestPath = require.resolve(`${selected.package}/package.json`, { paths: [packageRoot] }); }
|
|
49
|
+
catch { failure('native-package-missing', `Missing ${selected.package}@${own.version}. Reinstall ${own.name} with optional dependencies enabled (--include=optional). Installation scripts are not required.`); }
|
|
50
|
+
const nativeRoot = fs.realpathSync(path.dirname(manifestPath));
|
|
51
|
+
const nativePackage = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
|
52
|
+
if (nativePackage.name !== selected.package || nativePackage.version !== own.version) {
|
|
53
|
+
failure('native-version-mismatch', 'CLI and native payload versions differ. Reinstall the exact main-package version with optional dependencies enabled.');
|
|
54
|
+
}
|
|
55
|
+
const manifestBytes = fs.readFileSync(path.join(nativeRoot, 'native-manifest.json'));
|
|
56
|
+
if (sha256(manifestBytes) !== selected.manifestSha256) failure('native-integrity', 'Native manifest integrity failed. Reinstall this package.');
|
|
57
|
+
const native = JSON.parse(manifestBytes);
|
|
58
|
+
if (native.schemaVersion !== 1 || native.version !== own.version || native.os !== process.platform || native.arch !== process.arch) {
|
|
59
|
+
failure('native-metadata-mismatch', 'The installed native payload does not match this version and platform.');
|
|
60
|
+
}
|
|
61
|
+
for (const item of native.files) {
|
|
62
|
+
if (!item.path || item.path.includes('\\') || item.path.includes(':') || item.path.split('/').some(p => ['', '.', '..'].includes(p))) {
|
|
63
|
+
failure('native-integrity', 'Invalid native resource path. Reinstall this package.');
|
|
64
|
+
}
|
|
65
|
+
const file = path.join(nativeRoot, ...item.path.split('/'));
|
|
66
|
+
const stat = fs.lstatSync(file);
|
|
67
|
+
if (!stat.isFile() || !fs.realpathSync(file).startsWith(nativeRoot + path.sep) || stat.size !== item.size || sha256(fs.readFileSync(file)) !== item.sha256) {
|
|
68
|
+
failure('native-integrity', 'Native binary or resource integrity failed. Reinstall this package.');
|
|
69
|
+
}
|
|
70
|
+
if (item.executable && process.platform !== 'win32' && !(stat.mode & 0o111)) {
|
|
71
|
+
failure('native-not-executable', 'Native executable permissions are missing. Reinstall this package.');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const filename = command + (process.platform === 'win32' ? '.exe' : '');
|
|
75
|
+
if (!native.executables[filename]) failure('native-integrity', 'Native executable is absent from the manifest.');
|
|
76
|
+
return path.join(nativeRoot, filename);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function launch(command) {
|
|
80
|
+
try {
|
|
81
|
+
const binary = resolveNative(command);
|
|
82
|
+
// Native siblings/resources remain together. The CLI therefore registers
|
|
83
|
+
// the real daemon path, never this Node wrapper or an interactive PATH shim.
|
|
84
|
+
const child = spawn(binary, process.argv.slice(2), { stdio: 'inherit', shell: false });
|
|
85
|
+
const handlers = new Map();
|
|
86
|
+
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
|
|
87
|
+
const handler = () => {
|
|
88
|
+
if (child.exitCode !== null || child.signalCode !== null) return;
|
|
89
|
+
// Windows console events already reach the native child. Node's kill
|
|
90
|
+
// emulation is an abrupt termination, so allow console cleanup first.
|
|
91
|
+
if (process.platform === 'win32' && signal !== 'SIGTERM') {
|
|
92
|
+
const timer = setTimeout(() => { if (child.exitCode === null && child.signalCode === null) child.kill(); }, 5000);
|
|
93
|
+
timer.unref();
|
|
94
|
+
} else { child.kill(signal); }
|
|
95
|
+
};
|
|
96
|
+
handlers.set(signal, handler);
|
|
97
|
+
process.on(signal, handler);
|
|
98
|
+
}
|
|
99
|
+
const cleanup = () => { for (const [signal, handler] of handlers) process.removeListener(signal, handler); };
|
|
100
|
+
child.once('error', error => {
|
|
101
|
+
cleanup();
|
|
102
|
+
process.stderr.write(`usagestat npm: native-start-failed: ${error.code || 'unknown'}. Reinstall the matching native package.\n`);
|
|
103
|
+
process.exitCode = 1;
|
|
104
|
+
});
|
|
105
|
+
child.once('exit', (code, signal) => {
|
|
106
|
+
cleanup();
|
|
107
|
+
if (signal && process.platform !== 'win32') process.kill(process.pid, signal);
|
|
108
|
+
else process.exitCode = code === null ? 1 : code;
|
|
109
|
+
});
|
|
110
|
+
} catch (error) {
|
|
111
|
+
// Do not dump JSON/native files or inherited environment on failure.
|
|
112
|
+
const known = error.code && !['ENOENT', 'EACCES', 'EPERM'].includes(error.code);
|
|
113
|
+
process.stderr.write(`usagestat npm: ${known ? error.code : 'native-package-unusable'}: ${known ? error.message : 'Native package files are missing or inaccessible; reinstall with optional dependencies enabled.'}\n`);
|
|
114
|
+
process.exitCode = 1;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
module.exports = { launch, resolveNative, selectTarget };
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"bin": {
|
|
3
|
+
"usagestat": "bin/usagestat.cjs",
|
|
4
|
+
"usagestatd": "bin/usagestatd.cjs"
|
|
5
|
+
},
|
|
6
|
+
"description": "Native agent usage backend CLI and daemon",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=24",
|
|
9
|
+
"npm": ">=11.5.1"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"bin",
|
|
13
|
+
"launcher.cjs",
|
|
14
|
+
"platforms.json",
|
|
15
|
+
"LICENSE",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"name": "@hashimkarim/usagestat",
|
|
20
|
+
"optionalDependencies": {
|
|
21
|
+
"@hashimkarim/usagestat-darwin-arm64": "2.0.0-alpha.1",
|
|
22
|
+
"@hashimkarim/usagestat-darwin-x64": "2.0.0-alpha.1",
|
|
23
|
+
"@hashimkarim/usagestat-linux-arm64-gnu": "2.0.0-alpha.1",
|
|
24
|
+
"@hashimkarim/usagestat-linux-x64-gnu": "2.0.0-alpha.1",
|
|
25
|
+
"@hashimkarim/usagestat-win32-x64": "2.0.0-alpha.1"
|
|
26
|
+
},
|
|
27
|
+
"private": false,
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public",
|
|
30
|
+
"registry": "https://registry.npmjs.org/"
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/hashimkarim/usagestat.git"
|
|
35
|
+
},
|
|
36
|
+
"version": "2.0.0-alpha.1"
|
|
37
|
+
}
|
package/platforms.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"darwin-arm64": {
|
|
3
|
+
"manifestSha256": "6ed806a95bbf08a756b941840257c00d50b4210b6a71d1014a4e0e0b93aacae4",
|
|
4
|
+
"minimumSystem": "11.0",
|
|
5
|
+
"minimumSystemQualified": false,
|
|
6
|
+
"package": "@hashimkarim/usagestat-darwin-arm64"
|
|
7
|
+
},
|
|
8
|
+
"darwin-x64": {
|
|
9
|
+
"manifestSha256": "8dddb0141f78fb67262d3900b5b1a01cf6b1419c71b04fdbc3809d213305e0b3",
|
|
10
|
+
"minimumSystem": "11.0",
|
|
11
|
+
"minimumSystemQualified": false,
|
|
12
|
+
"package": "@hashimkarim/usagestat-darwin-x64"
|
|
13
|
+
},
|
|
14
|
+
"linux-arm64-gnu": {
|
|
15
|
+
"manifestSha256": "d7a8d304c3a0f2ea171fdcfbe24957e518047e94202eacb1858fd46408ebffd7",
|
|
16
|
+
"minimumSystem": "glibc 2.39",
|
|
17
|
+
"minimumSystemQualified": true,
|
|
18
|
+
"package": "@hashimkarim/usagestat-linux-arm64-gnu"
|
|
19
|
+
},
|
|
20
|
+
"linux-x64-gnu": {
|
|
21
|
+
"manifestSha256": "ee90e752809179942c6d341ec685fcbc5bf1ca7e116c09e39daed392d3dcab26",
|
|
22
|
+
"minimumSystem": "glibc 2.39",
|
|
23
|
+
"minimumSystemQualified": true,
|
|
24
|
+
"package": "@hashimkarim/usagestat-linux-x64-gnu"
|
|
25
|
+
},
|
|
26
|
+
"win32-x64": {
|
|
27
|
+
"manifestSha256": "62a1fa8cd4962a4d82daa00e560f88c81383fcbba0338beb22d64cc0e3980625",
|
|
28
|
+
"minimumSystem": "Windows 10 / Server 2016",
|
|
29
|
+
"minimumSystemQualified": false,
|
|
30
|
+
"package": "@hashimkarim/usagestat-win32-x64"
|
|
31
|
+
}
|
|
32
|
+
}
|