modelstat 0.0.12 → 0.0.13
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/README.md +3 -3
- package/dist/cli.mjs +57 -13
- package/dist/cli.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,9 +22,9 @@ modelstat connect
|
|
|
22
22
|
Or via npm / pnpm / bun:
|
|
23
23
|
|
|
24
24
|
```bash
|
|
25
|
-
npm install -g modelstat && modelstat connect
|
|
26
|
-
pnpm add -g modelstat && modelstat connect
|
|
27
|
-
bun add -g modelstat && modelstat connect
|
|
25
|
+
npm install -g @modelstat/agent && modelstat connect
|
|
26
|
+
pnpm add -g @modelstat/agent && modelstat connect
|
|
27
|
+
bun add -g @modelstat/agent && modelstat connect
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
`modelstat connect` installs a **launchd user agent** on macOS (at `~/Library/LaunchAgents/ai.modelstat.agent.plist`) or a **systemd user unit** on Linux (at `~/.config/systemd/user/modelstat.service`). The daemon starts automatically on login.
|
package/dist/cli.mjs
CHANGED
|
@@ -8908,6 +8908,7 @@ function generateUuidV7() {
|
|
|
8908
8908
|
}
|
|
8909
8909
|
async function cmdSelfRegister() {
|
|
8910
8910
|
const deviceUuid = state.deviceUuid ?? generateUuidV7();
|
|
8911
|
+
const fresh = !state.deviceUuid;
|
|
8911
8912
|
const fingerprint = {
|
|
8912
8913
|
hostname: hostname2(),
|
|
8913
8914
|
os_family: osFamily(),
|
|
@@ -8916,6 +8917,14 @@ async function cmdSelfRegister() {
|
|
|
8916
8917
|
agent: "modelstat-agent-dev",
|
|
8917
8918
|
agent_version: AGENT_VERSION3
|
|
8918
8919
|
};
|
|
8920
|
+
if (fresh) {
|
|
8921
|
+
process.stdout.write(` \x1B[2mgenerated UUIDv7 ${deviceUuid.slice(0, 8)}\u2026\x1B[0m
|
|
8922
|
+
`);
|
|
8923
|
+
}
|
|
8924
|
+
process.stdout.write(
|
|
8925
|
+
` \x1B[2m\u2192 POST ${state.apiUrl}/v1/devices/self-register\x1B[0m
|
|
8926
|
+
`
|
|
8927
|
+
);
|
|
8919
8928
|
const res = await selfRegister({
|
|
8920
8929
|
device_uuid: deviceUuid,
|
|
8921
8930
|
fingerprint
|
|
@@ -8925,16 +8934,12 @@ async function cmdSelfRegister() {
|
|
|
8925
8934
|
state.setBearer(res.device_secret);
|
|
8926
8935
|
state.setClaimCode(res.claim_code);
|
|
8927
8936
|
state.setClaimUrl(res.claim_url);
|
|
8928
|
-
|
|
8929
|
-
|
|
8930
|
-
|
|
8931
|
-
|
|
8932
|
-
|
|
8933
|
-
|
|
8934
|
-
console.log(` ${res.claim_url}`);
|
|
8935
|
-
console.log(` code: ${res.claim_code}`);
|
|
8936
|
-
console.log();
|
|
8937
|
-
console.log(` state: ${state.storePath}`);
|
|
8937
|
+
process.stdout.write(` \x1B[32m\u2713\x1B[0m registered device_id=${res.device_id}
|
|
8938
|
+
`);
|
|
8939
|
+
process.stdout.write(` \x1B[32m\u2713\x1B[0m secret ${res.secret_prefix}\u2026 (hashed on server, never re-sent)
|
|
8940
|
+
`);
|
|
8941
|
+
process.stdout.write(` \x1B[32m\u2713\x1B[0m claim code ${res.claim_code}
|
|
8942
|
+
`);
|
|
8938
8943
|
}
|
|
8939
8944
|
async function cmdAwaitClaim() {
|
|
8940
8945
|
const secret = state.bearer;
|
|
@@ -8971,8 +8976,38 @@ function emitEvent(opts, event, fields = {}) {
|
|
|
8971
8976
|
);
|
|
8972
8977
|
}
|
|
8973
8978
|
async function cmdConnect(opts) {
|
|
8979
|
+
const step = (msg) => {
|
|
8980
|
+
if (opts.json) return;
|
|
8981
|
+
process.stdout.write(`\x1B[1;36m\u25B8\x1B[0m ${msg}
|
|
8982
|
+
`);
|
|
8983
|
+
};
|
|
8984
|
+
const ok = (msg) => {
|
|
8985
|
+
if (opts.json) return;
|
|
8986
|
+
process.stdout.write(` \x1B[32m\u2713\x1B[0m ${msg}
|
|
8987
|
+
`);
|
|
8988
|
+
};
|
|
8989
|
+
const warn = (msg) => {
|
|
8990
|
+
if (opts.json) return;
|
|
8991
|
+
process.stdout.write(` \x1B[33m\u26A0\x1B[0m ${msg}
|
|
8992
|
+
`);
|
|
8993
|
+
};
|
|
8994
|
+
const hasLegacyBearer = !!state.bearer && !state.bearer.startsWith("ds_live_");
|
|
8995
|
+
const hasLegacyClaim = !!state.claimUrl && state.claimUrl.includes("/c/");
|
|
8996
|
+
if (hasLegacyBearer || hasLegacyClaim) {
|
|
8997
|
+
step("Legacy state detected from an older version \u2014 wiping");
|
|
8998
|
+
state.setBearer(null);
|
|
8999
|
+
state.setDeviceId(null);
|
|
9000
|
+
state.setDeviceUuid(null);
|
|
9001
|
+
state.setClaimCode(null);
|
|
9002
|
+
state.setClaimUrl(null);
|
|
9003
|
+
ok("clean slate");
|
|
9004
|
+
}
|
|
8974
9005
|
if (!state.deviceUuid || !state.bearer || !state.deviceId) {
|
|
9006
|
+
step("Registering this device with modelstat.ai");
|
|
8975
9007
|
await cmdSelfRegister();
|
|
9008
|
+
} else {
|
|
9009
|
+
step("Re-using existing device identity");
|
|
9010
|
+
ok(`device ${state.deviceId}`);
|
|
8976
9011
|
}
|
|
8977
9012
|
const claimCode = state.claimCode ?? "(unknown)";
|
|
8978
9013
|
const claimUrl = state.claimUrl ?? `https://modelstat.ai/d/${claimCode}`;
|
|
@@ -8985,36 +9020,45 @@ async function cmdConnect(opts) {
|
|
|
8985
9020
|
agent_url: agentUrl
|
|
8986
9021
|
});
|
|
8987
9022
|
if (platform4() === "darwin") {
|
|
9023
|
+
step("Installing menu-bar tray (macOS)");
|
|
8988
9024
|
try {
|
|
8989
9025
|
const src = bundledTrayAppPath();
|
|
8990
9026
|
if (src) {
|
|
8991
9027
|
const out = installTrayApp(src);
|
|
8992
|
-
if (out)
|
|
9028
|
+
if (out) {
|
|
9029
|
+
emitEvent(opts, "tray_installed", { path: out.installedAt });
|
|
9030
|
+
ok(`tray at ${out.installedAt}`);
|
|
9031
|
+
}
|
|
8993
9032
|
} else {
|
|
8994
9033
|
emitEvent(opts, "tray_not_bundled", {});
|
|
9034
|
+
warn("no bundled tray \u2014 skipping (install Xcode CLI tools and re-run to get the icon)");
|
|
8995
9035
|
}
|
|
8996
9036
|
} catch (e) {
|
|
8997
9037
|
emitEvent(opts, "tray_install_failed", { error: e.message });
|
|
9038
|
+
warn(`tray install skipped: ${e.message}`);
|
|
8998
9039
|
}
|
|
8999
9040
|
}
|
|
9041
|
+
step("Installing background service so the agent survives reboots");
|
|
9000
9042
|
let serviceOk = false;
|
|
9001
9043
|
try {
|
|
9002
9044
|
const svc = installService();
|
|
9003
9045
|
serviceOk = true;
|
|
9004
9046
|
emitEvent(opts, "service_installed", { path: svc.path, logs: svc.logs });
|
|
9047
|
+
ok(`${platform4() === "darwin" ? "launchd" : "systemd --user"}: ${svc.path}`);
|
|
9005
9048
|
} catch (e) {
|
|
9006
9049
|
emitEvent(opts, "service_install_failed", { error: e.message });
|
|
9050
|
+
warn(`couldn't install service: ${e.message}`);
|
|
9051
|
+
warn("will run in the foreground instead \u2014 don't close this terminal");
|
|
9007
9052
|
}
|
|
9008
9053
|
if (!opts.json) {
|
|
9009
9054
|
const tray = trayStatus();
|
|
9010
|
-
const svcOk = serviceOk;
|
|
9011
9055
|
const line = "\u2501".repeat(60);
|
|
9012
9056
|
console.log();
|
|
9013
9057
|
console.log(line);
|
|
9014
9058
|
console.log(` \u2713 Device registered \u2014 streaming your AI usage to modelstat.`);
|
|
9015
9059
|
console.log();
|
|
9016
9060
|
console.log(
|
|
9017
|
-
` service : \x1B[${
|
|
9061
|
+
` service : \x1B[${serviceOk ? "32" : "33"}m${serviceOk ? "installed" : "foreground"}\x1B[0m`
|
|
9018
9062
|
);
|
|
9019
9063
|
if (platform4() === "darwin") {
|
|
9020
9064
|
console.log(
|