kubeagent 0.1.11 → 0.1.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/dist/cli.js +2 -0
- package/dist/telemetry.d.ts +1 -0
- package/dist/telemetry.js +34 -0
- package/dist/telemetry.test.d.ts +1 -0
- package/dist/telemetry.test.js +18 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -26,6 +26,7 @@ import { scanCluster } from "./onboard/cluster-scan.js";
|
|
|
26
26
|
import { formatProjectMarkdown } from "./onboard/code-scan.js";
|
|
27
27
|
import { writeProjectKb, ensureKbDir } from "./kb/writer.js";
|
|
28
28
|
import { checkForUpdate } from "./update-notifier.js";
|
|
29
|
+
import { sendTelemetry } from "./telemetry.js";
|
|
29
30
|
const program = new Command();
|
|
30
31
|
program
|
|
31
32
|
.name("kubeagent")
|
|
@@ -465,3 +466,4 @@ program
|
|
|
465
466
|
program.parse();
|
|
466
467
|
// Non-blocking update check — runs after command completes
|
|
467
468
|
checkForUpdate();
|
|
469
|
+
sendTelemetry(version);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function sendTelemetry(cliVersion: string): void;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { existsSync, writeFileSync, mkdirSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { homedir, platform, arch } from "node:os";
|
|
4
|
+
const TELEMETRY_DIR = join(homedir(), ".kubeagent");
|
|
5
|
+
const SENT_FILE = join(TELEMETRY_DIR, ".telemetry-sent");
|
|
6
|
+
const SERVER = "https://api.kubeagent.net";
|
|
7
|
+
export function sendTelemetry(cliVersion) {
|
|
8
|
+
// Only fire once per machine
|
|
9
|
+
if (existsSync(SENT_FILE))
|
|
10
|
+
return;
|
|
11
|
+
// Mark as sent immediately to avoid duplicate attempts
|
|
12
|
+
try {
|
|
13
|
+
if (!existsSync(TELEMETRY_DIR))
|
|
14
|
+
mkdirSync(TELEMETRY_DIR, { recursive: true });
|
|
15
|
+
writeFileSync(SENT_FILE, new Date().toISOString());
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
// Fire-and-forget — never block the CLI
|
|
21
|
+
const payload = JSON.stringify({
|
|
22
|
+
event: "cli_first_run",
|
|
23
|
+
cliVersion,
|
|
24
|
+
os: platform(),
|
|
25
|
+
arch: arch(),
|
|
26
|
+
nodeVersion: process.version,
|
|
27
|
+
});
|
|
28
|
+
fetch(`${SERVER}/telemetry`, {
|
|
29
|
+
method: "POST",
|
|
30
|
+
headers: { "Content-Type": "application/json" },
|
|
31
|
+
body: payload,
|
|
32
|
+
signal: AbortSignal.timeout(5000),
|
|
33
|
+
}).catch(() => { });
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
const TELEMETRY_DIR = join(homedir(), ".kubeagent");
|
|
5
|
+
const SENT_FILE = join(TELEMETRY_DIR, ".telemetry-sent");
|
|
6
|
+
describe("sendTelemetry", () => {
|
|
7
|
+
it("module exports sendTelemetry function", async () => {
|
|
8
|
+
const mod = await import("./telemetry.js");
|
|
9
|
+
expect(typeof mod.sendTelemetry).toBe("function");
|
|
10
|
+
});
|
|
11
|
+
it("does not throw when called", async () => {
|
|
12
|
+
// If marker file already exists from a real run, this just returns early.
|
|
13
|
+
// If not, it fires a fetch that will fail silently (no server).
|
|
14
|
+
// Either way it should not throw.
|
|
15
|
+
const { sendTelemetry } = await import("./telemetry.js");
|
|
16
|
+
expect(() => sendTelemetry("0.0.0-test")).not.toThrow();
|
|
17
|
+
});
|
|
18
|
+
});
|