@@ -21,20 +21,16 @@ let machineIdModule: typeof import('node-machine-id') | null = null
2121let systeminformationModule : typeof import ( 'systeminformation' ) | null = null
2222
2323async function getMachineId ( ) : Promise < string > {
24- try {
25- if ( ! machineIdModule ) {
26- machineIdModule = await import ( 'node-machine-id' )
27- }
28- const id = await machineIdModule . machineId ( )
29- // Validate that we got a real machine ID, not an empty or placeholder value
30- if ( ! id || id === 'unknown' || id . length < 8 ) {
31- throw new Error ( 'Invalid machine ID returned' )
32- }
33- return id
34- } catch ( error ) {
35- // Re-throw to signal that enhanced fingerprinting should fall back to legacy
36- throw error
24+ if ( ! machineIdModule ) {
25+ machineIdModule = await import ( 'node-machine-id' )
3726 }
27+ const id = await machineIdModule . machineId ( )
28+ // Validate that we got a real machine ID, not an empty or placeholder value.
29+ // Throwing here triggers the legacy fallback in calculateFingerprint().
30+ if ( ! id || id === 'unknown' || id . length < 8 ) {
31+ throw new Error ( 'Invalid machine ID returned' )
32+ }
33+ return id
3834}
3935
4036async function getSystemInfo ( ) : Promise < {
@@ -141,6 +137,25 @@ function calculateLegacyFingerprint(): string {
141137 return `codebuff-cli-${ randomSuffix } `
142138}
143139
140+ /**
141+ * Cached fingerprint promise. Populated on first call and reused for the
142+ * process lifetime so every auth step in a session ships the same fingerprint
143+ * to the server.
144+ */
145+ let cachedFingerprintPromise : Promise < string > | null = null
146+
147+ /**
148+ * Returns the process-wide CLI fingerprint, computing it on first call.
149+ * Safe to call from multiple places — the first caller wins and the rest
150+ * await the same promise.
151+ */
152+ export function getFingerprintId ( ) : Promise < string > {
153+ if ( ! cachedFingerprintPromise ) {
154+ cachedFingerprintPromise = calculateFingerprint ( )
155+ }
156+ return cachedFingerprintPromise
157+ }
158+
144159/**
145160 * Main fingerprint function.
146161 * Tries enhanced fingerprinting first, falls back to legacy if it fails.
0 commit comments