init-xmcp 1.10.4 → 1.12.0

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.
@@ -1,4 +1,4 @@
1
1
 
2
- > init-xmcp@1.10.4 build /home/runner/work/xmcp/xmcp/packages/init-xmcp
2
+ > init-xmcp@1.12.0 build /home/runner/work/xmcp/xmcp/packages/init-xmcp
3
3
  > tsc
4
4
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # init-xmcp
2
2
 
3
+ ## 1.12.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 6bbf233: Telemetry now sends one `dev:started` event per `xmcp dev` session, adds the command, package manager, deploy target, and a fixed list of enabled framework features to build and dev events, and reports config, compile, and client transpile failures in addition to bundler failures. `create-xmcp-app` and `init-xmcp` send one anonymous event when they finish and honour the same opt-out.
8
+
9
+ ## 1.11.0
10
+
11
+ No changes in this release.
12
+
3
13
  ## 1.10.4
4
14
 
5
15
  No changes in this release.
@@ -0,0 +1,13 @@
1
+ export type ScaffoldReport = {
2
+ command: "create-xmcp-app" | "init-xmcp";
3
+ version: string;
4
+ projectName: string;
5
+ packageManager?: string;
6
+ features: string[];
7
+ duration: number;
8
+ template?: string;
9
+ framework?: string;
10
+ error?: unknown;
11
+ };
12
+ export declare function readProjectName(projectRoot: string): string;
13
+ export declare function reportScaffold(report: ScaffoldReport): Promise<void>;
@@ -0,0 +1,130 @@
1
+ import { createHash, randomBytes } from "crypto";
2
+ import fs from "fs";
3
+ import os from "os";
4
+ import path from "path";
5
+ const TELEMETRY_ENDPOINT = "https://telemetry.xmcp.dev/api/telemetry/events";
6
+ const SEND_TIMEOUT_MS = 2000;
7
+ const ERROR_TYPE_PATTERN = /^[A-Za-z][A-Za-z0-9_]{0,63}$/;
8
+ const KEY_ENABLED = "telemetry.enabled";
9
+ const KEY_NOTIFIED_AT = "telemetry.notifiedAt";
10
+ const KEY_ANONYMOUS_ID = "telemetry.anonymousId";
11
+ const KEY_SALT = "telemetry.salt";
12
+ const PACKAGE_MANAGERS = ["npm", "pnpm", "yarn", "bun"];
13
+ const isCI = !!process.env.CI && process.env.CI !== "false";
14
+ const isDocker = fs.existsSync("/.dockerenv");
15
+ const isWsl = process.platform === "linux" &&
16
+ os.release().toLowerCase().includes("microsoft");
17
+ function isDisabledByEnv() {
18
+ return process.env.XMCP_TELEMETRY_DISABLED?.toLowerCase() === "true";
19
+ }
20
+ const EPHEMERAL_PREFERENCES_PATH = path.join(os.tmpdir(), ".xmcp-cache", "telemetry.json");
21
+ const USER_PREFERENCES_PATH = path.join(os.homedir(), process.platform === "win32" ? "AppData/Local/xmcp" : ".config/xmcp", "telemetry.json");
22
+ function isDisabledByPreferences() {
23
+ return [EPHEMERAL_PREFERENCES_PATH, USER_PREFERENCES_PATH].some((filePath) => readPreferences(filePath)[KEY_ENABLED] === false);
24
+ }
25
+ export function readProjectName(projectRoot) {
26
+ try {
27
+ const packageJson = JSON.parse(fs.readFileSync(path.join(projectRoot, "package.json"), "utf-8"));
28
+ return packageJson.name || path.resolve(projectRoot);
29
+ }
30
+ catch {
31
+ return path.resolve(projectRoot);
32
+ }
33
+ }
34
+ function readPreferences(filePath) {
35
+ return fs.existsSync(filePath)
36
+ ? JSON.parse(fs.readFileSync(filePath, "utf-8"))
37
+ : {};
38
+ }
39
+ function showNotice() {
40
+ console.log("");
41
+ console.log("xmcp collects anonymous usage data to improve the framework.");
42
+ console.log(" No personal information is collected.");
43
+ console.log(" You can learn more and opt-out by visiting: https://xmcp.dev/telemetry");
44
+ console.log(" Or disable with: XMCP_TELEMETRY_DISABLED=true");
45
+ console.log("");
46
+ }
47
+ function toErrorType(error) {
48
+ const name = error instanceof Error ? error.constructor.name : "";
49
+ return ERROR_TYPE_PATTERN.test(name) ? name : "Error";
50
+ }
51
+ function buildPayload(report, preferences) {
52
+ const cpus = os.cpus() ?? [];
53
+ const failed = report.error !== undefined;
54
+ return {
55
+ context: {
56
+ anonymousId: preferences[KEY_ANONYMOUS_ID],
57
+ sessionId: randomBytes(32).toString("hex"),
58
+ projectHash: createHash("sha256")
59
+ .update(String(preferences[KEY_SALT]))
60
+ .update(report.projectName)
61
+ .digest("hex"),
62
+ },
63
+ meta: {
64
+ platform: os.platform(),
65
+ systemRelease: os.release(),
66
+ arch: os.arch(),
67
+ cpuCores: cpus.length,
68
+ cpuModel: cpus.length ? cpus[0].model : null,
69
+ cpuSpeed: cpus.length ? cpus[0].speed : null,
70
+ memoryTotal: Math.trunc(os.totalmem() / Math.pow(1024, 2)),
71
+ isDocker,
72
+ isWsl,
73
+ isCI,
74
+ ciName: null,
75
+ },
76
+ events: [
77
+ {
78
+ eventName: failed ? "scaffold:failed" : "scaffold:completed",
79
+ timestamp: new Date().toISOString(),
80
+ fields: {
81
+ success: !failed,
82
+ duration: report.duration,
83
+ command: report.command,
84
+ packageManager: PACKAGE_MANAGERS.includes(report.packageManager ?? "")
85
+ ? report.packageManager
86
+ : "unknown",
87
+ features: report.features,
88
+ template: report.template,
89
+ framework: report.framework,
90
+ nodeVersion: process.version,
91
+ xmcpVersion: report.version,
92
+ ...(failed
93
+ ? { errorPhase: "scaffold", errorType: toErrorType(report.error) }
94
+ : {}),
95
+ },
96
+ },
97
+ ],
98
+ };
99
+ }
100
+ export async function reportScaffold(report) {
101
+ if (isDisabledByEnv()) {
102
+ return;
103
+ }
104
+ try {
105
+ if (isDisabledByPreferences()) {
106
+ return;
107
+ }
108
+ const filePath = isCI || isDocker ? EPHEMERAL_PREFERENCES_PATH : USER_PREFERENCES_PATH;
109
+ const preferences = readPreferences(filePath);
110
+ if (!preferences[KEY_NOTIFIED_AT]) {
111
+ preferences[KEY_NOTIFIED_AT] = Date.now().toString();
112
+ if (!isCI) {
113
+ showNotice();
114
+ }
115
+ }
116
+ preferences[KEY_ANONYMOUS_ID] ??= randomBytes(32).toString("hex");
117
+ preferences[KEY_SALT] ??= randomBytes(16).toString("hex");
118
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
119
+ fs.writeFileSync(filePath, JSON.stringify(preferences, null, 2), "utf-8");
120
+ await fetch(TELEMETRY_ENDPOINT, {
121
+ method: "POST",
122
+ body: JSON.stringify(buildPayload(report, preferences)),
123
+ headers: { "content-type": "application/json" },
124
+ signal: AbortSignal.timeout(SEND_TIMEOUT_MS),
125
+ });
126
+ }
127
+ catch {
128
+ return;
129
+ }
130
+ }
package/dist/index.js CHANGED
@@ -9,6 +9,7 @@ import { detectPackageManager } from "./helpers/install.js";
9
9
  import fs from "fs-extra";
10
10
  import path from "path";
11
11
  import { checkNodeVersion } from "./utils/check-node.js";
12
+ import { readProjectName, reportScaffold } from "./helpers/telemetry.js";
12
13
  import { fileURLToPath } from "url";
13
14
  checkNodeVersion();
14
15
  const __filename = fileURLToPath(import.meta.url);
@@ -278,6 +279,22 @@ const program = new Command()
278
279
  }
279
280
  }
280
281
  }
282
+ const scaffoldStartTime = Date.now();
283
+ const getScaffoldReport = () => ({
284
+ command: "init-xmcp",
285
+ version: packageJson.version,
286
+ projectName: readProjectName(projectRoot),
287
+ packageManager,
288
+ framework: detectedFramework,
289
+ features: [
290
+ ...(toolsPath ? ["tools"] : []),
291
+ ...(promptsPath ? ["prompts"] : []),
292
+ ...(resourcesPath ? ["resources"] : []),
293
+ ...(cloudflare ? ["cloudflare"] : []),
294
+ ...(detectedTypeScript ? ["typescript"] : []),
295
+ ],
296
+ duration: Date.now() - scaffoldStartTime,
297
+ });
281
298
  try {
282
299
  console.log(chalk.blue("\n Initializing xmcp..."));
283
300
  await init({
@@ -385,10 +402,12 @@ export class AppModule {}`;
385
402
  console.log(chalk.green(chalk.bgBlack(` ${" ".repeat(maxLength)}`)));
386
403
  }
387
404
  console.log(` \nRun "${packageManager} run dev" to start the development server\n`);
405
+ await reportScaffold(getScaffoldReport());
388
406
  }
389
407
  catch (error) {
390
408
  console.error(chalk.red("\nFailed to initialize xmcp:"));
391
409
  console.error(error);
410
+ await reportScaffold({ ...getScaffoldReport(), error });
392
411
  process.exit(1);
393
412
  }
394
413
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "init-xmcp",
3
- "version": "1.10.4",
3
+ "version": "1.12.0",
4
4
  "author": {
5
5
  "name": "xmcp",
6
6
  "email": "support@xmcp.dev",
@@ -0,0 +1,178 @@
1
+ import { createHash, randomBytes } from "crypto";
2
+ import fs from "fs";
3
+ import os from "os";
4
+ import path from "path";
5
+
6
+ const TELEMETRY_ENDPOINT = "https://telemetry.xmcp.dev/api/telemetry/events";
7
+ const SEND_TIMEOUT_MS = 2000;
8
+ const ERROR_TYPE_PATTERN = /^[A-Za-z][A-Za-z0-9_]{0,63}$/;
9
+
10
+ const KEY_ENABLED = "telemetry.enabled";
11
+ const KEY_NOTIFIED_AT = "telemetry.notifiedAt";
12
+ const KEY_ANONYMOUS_ID = "telemetry.anonymousId";
13
+ const KEY_SALT = "telemetry.salt";
14
+
15
+ const PACKAGE_MANAGERS = ["npm", "pnpm", "yarn", "bun"];
16
+
17
+ type Preferences = Record<string, string | boolean | undefined>;
18
+
19
+ export type ScaffoldReport = {
20
+ command: "create-xmcp-app" | "init-xmcp";
21
+ version: string;
22
+ projectName: string;
23
+ packageManager?: string;
24
+ features: string[];
25
+ duration: number;
26
+ template?: string;
27
+ framework?: string;
28
+ error?: unknown;
29
+ };
30
+
31
+ const isCI = !!process.env.CI && process.env.CI !== "false";
32
+ const isDocker = fs.existsSync("/.dockerenv");
33
+ const isWsl =
34
+ process.platform === "linux" &&
35
+ os.release().toLowerCase().includes("microsoft");
36
+
37
+ function isDisabledByEnv(): boolean {
38
+ return process.env.XMCP_TELEMETRY_DISABLED?.toLowerCase() === "true";
39
+ }
40
+
41
+ const EPHEMERAL_PREFERENCES_PATH = path.join(
42
+ os.tmpdir(),
43
+ ".xmcp-cache",
44
+ "telemetry.json"
45
+ );
46
+
47
+ const USER_PREFERENCES_PATH = path.join(
48
+ os.homedir(),
49
+ process.platform === "win32" ? "AppData/Local/xmcp" : ".config/xmcp",
50
+ "telemetry.json"
51
+ );
52
+
53
+ function isDisabledByPreferences(): boolean {
54
+ return [EPHEMERAL_PREFERENCES_PATH, USER_PREFERENCES_PATH].some(
55
+ (filePath) => readPreferences(filePath)[KEY_ENABLED] === false
56
+ );
57
+ }
58
+
59
+ export function readProjectName(projectRoot: string): string {
60
+ try {
61
+ const packageJson = JSON.parse(
62
+ fs.readFileSync(path.join(projectRoot, "package.json"), "utf-8")
63
+ );
64
+ return packageJson.name || path.resolve(projectRoot);
65
+ } catch {
66
+ return path.resolve(projectRoot);
67
+ }
68
+ }
69
+
70
+ function readPreferences(filePath: string): Preferences {
71
+ return fs.existsSync(filePath)
72
+ ? JSON.parse(fs.readFileSync(filePath, "utf-8"))
73
+ : {};
74
+ }
75
+
76
+ function showNotice(): void {
77
+ console.log("");
78
+ console.log("xmcp collects anonymous usage data to improve the framework.");
79
+ console.log(" No personal information is collected.");
80
+ console.log(
81
+ " You can learn more and opt-out by visiting: https://xmcp.dev/telemetry"
82
+ );
83
+ console.log(" Or disable with: XMCP_TELEMETRY_DISABLED=true");
84
+ console.log("");
85
+ }
86
+
87
+ function toErrorType(error: unknown): string {
88
+ const name = error instanceof Error ? error.constructor.name : "";
89
+ return ERROR_TYPE_PATTERN.test(name) ? name : "Error";
90
+ }
91
+
92
+ function buildPayload(report: ScaffoldReport, preferences: Preferences) {
93
+ const cpus = os.cpus() ?? [];
94
+ const failed = report.error !== undefined;
95
+
96
+ return {
97
+ context: {
98
+ anonymousId: preferences[KEY_ANONYMOUS_ID],
99
+ sessionId: randomBytes(32).toString("hex"),
100
+ projectHash: createHash("sha256")
101
+ .update(String(preferences[KEY_SALT]))
102
+ .update(report.projectName)
103
+ .digest("hex"),
104
+ },
105
+ meta: {
106
+ platform: os.platform(),
107
+ systemRelease: os.release(),
108
+ arch: os.arch(),
109
+ cpuCores: cpus.length,
110
+ cpuModel: cpus.length ? cpus[0].model : null,
111
+ cpuSpeed: cpus.length ? cpus[0].speed : null,
112
+ memoryTotal: Math.trunc(os.totalmem() / Math.pow(1024, 2)),
113
+ isDocker,
114
+ isWsl,
115
+ isCI,
116
+ ciName: null,
117
+ },
118
+ events: [
119
+ {
120
+ eventName: failed ? "scaffold:failed" : "scaffold:completed",
121
+ timestamp: new Date().toISOString(),
122
+ fields: {
123
+ success: !failed,
124
+ duration: report.duration,
125
+ command: report.command,
126
+ packageManager: PACKAGE_MANAGERS.includes(report.packageManager ?? "")
127
+ ? report.packageManager
128
+ : "unknown",
129
+ features: report.features,
130
+ template: report.template,
131
+ framework: report.framework,
132
+ nodeVersion: process.version,
133
+ xmcpVersion: report.version,
134
+ ...(failed
135
+ ? { errorPhase: "scaffold", errorType: toErrorType(report.error) }
136
+ : {}),
137
+ },
138
+ },
139
+ ],
140
+ };
141
+ }
142
+
143
+ export async function reportScaffold(report: ScaffoldReport): Promise<void> {
144
+ if (isDisabledByEnv()) {
145
+ return;
146
+ }
147
+
148
+ try {
149
+ if (isDisabledByPreferences()) {
150
+ return;
151
+ }
152
+
153
+ const filePath =
154
+ isCI || isDocker ? EPHEMERAL_PREFERENCES_PATH : USER_PREFERENCES_PATH;
155
+ const preferences = readPreferences(filePath);
156
+
157
+ if (!preferences[KEY_NOTIFIED_AT]) {
158
+ preferences[KEY_NOTIFIED_AT] = Date.now().toString();
159
+ if (!isCI) {
160
+ showNotice();
161
+ }
162
+ }
163
+ preferences[KEY_ANONYMOUS_ID] ??= randomBytes(32).toString("hex");
164
+ preferences[KEY_SALT] ??= randomBytes(16).toString("hex");
165
+
166
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
167
+ fs.writeFileSync(filePath, JSON.stringify(preferences, null, 2), "utf-8");
168
+
169
+ await fetch(TELEMETRY_ENDPOINT, {
170
+ method: "POST",
171
+ body: JSON.stringify(buildPayload(report, preferences)),
172
+ headers: { "content-type": "application/json" },
173
+ signal: AbortSignal.timeout(SEND_TIMEOUT_MS),
174
+ });
175
+ } catch {
176
+ return;
177
+ }
178
+ }
package/src/index.ts CHANGED
@@ -16,6 +16,7 @@ import { detectPackageManager } from "./helpers/install.js";
16
16
  import fs from "fs-extra";
17
17
  import path from "path";
18
18
  import { checkNodeVersion } from "./utils/check-node.js";
19
+ import { readProjectName, reportScaffold } from "./helpers/telemetry.js";
19
20
  import { fileURLToPath } from "url";
20
21
 
21
22
  checkNodeVersion();
@@ -351,6 +352,23 @@ const program = new Command()
351
352
  }
352
353
  }
353
354
 
355
+ const scaffoldStartTime = Date.now();
356
+ const getScaffoldReport = () => ({
357
+ command: "init-xmcp" as const,
358
+ version: packageJson.version,
359
+ projectName: readProjectName(projectRoot),
360
+ packageManager,
361
+ framework: detectedFramework,
362
+ features: [
363
+ ...(toolsPath ? ["tools"] : []),
364
+ ...(promptsPath ? ["prompts"] : []),
365
+ ...(resourcesPath ? ["resources"] : []),
366
+ ...(cloudflare ? ["cloudflare"] : []),
367
+ ...(detectedTypeScript ? ["typescript"] : []),
368
+ ],
369
+ duration: Date.now() - scaffoldStartTime,
370
+ });
371
+
354
372
  try {
355
373
  console.log(chalk.blue("\n Initializing xmcp..."));
356
374
 
@@ -503,9 +521,11 @@ export class AppModule {}`;
503
521
  console.log(
504
522
  ` \nRun "${packageManager} run dev" to start the development server\n`
505
523
  );
524
+ await reportScaffold(getScaffoldReport());
506
525
  } catch (error) {
507
526
  console.error(chalk.red("\nFailed to initialize xmcp:"));
508
527
  console.error(error);
528
+ await reportScaffold({ ...getScaffoldReport(), error });
509
529
  process.exit(1);
510
530
  }
511
531
  });