MCPcopy
hub / github.com/coder/mux / loadOrCreateDistinctId

Method loadOrCreateDistinctId

src/node/services/telemetryService.ts:233–258  ·  view source on GitHub ↗

* Load existing distinct ID or create a new one. * Persisted in ~/.mux/telemetry_id for cross-session identity.

()

Source from the content-addressed store, hash-verified

231 * Persisted in ~/.mux/telemetry_id for cross-session identity.
232 */
233 private async loadOrCreateDistinctId(): Promise<string> {
234 const idPath = path.join(this.muxHome, TELEMETRY_ID_FILE);
235
236 try {
237 // Try to read existing ID
238 const id = (await fs.readFile(idPath, "utf-8")).trim();
239 if (id) {
240 return id;
241 }
242 } catch {
243 // File doesn't exist or read error, will create new ID
244 }
245
246 // Generate new ID
247 const newId = randomUUID();
248
249 try {
250 // Ensure directory exists
251 await fs.mkdir(this.muxHome, { recursive: true });
252 await fs.writeFile(idPath, newId, "utf-8");
253 } catch {
254 // Silently ignore persistence failures
255 }
256
257 return newId;
258 }
259
260 /**
261 * Get base properties included with all events

Callers 1

initializeMethod · 0.95

Calls 2

readFileMethod · 0.65
writeFileMethod · 0.65

Tested by

no test coverage detected