feat: append cli_context param to altimate auth URL for PostHog session correlation
Merged
AL
3mo ago+588+588+012345678901234567890123456789-35-35-01234567890123456789
Summary
Appends a cli_context query param to the browser auth URL opened by the CLI during sign-in.
buildCliContext()encodes{ v: 1, machine_id, cli_version }as a base64url JSON blobmachine_idis read from~/.altimate/machine-id(random UUID, non-PII) — the same value already sent to Azure App Insights telemetry- On the frontend,
cli_contextis decoded and passed toposthog.register()+posthog.alias()to link the CLI device to the authenticated user
Companion PR: AltimateAI/altimate-frontend#3106
Requested by @saravmajestic via harness
Summary by cubic
Adds a base64url-encoded cli_context to the CLI auth URL (now in the URL fragment) so the web app can link the browser session to the CLI device in PostHog. Uses a shared, race‑safe machine_id helper with UUID v4 validation and an enforced 512‑byte cap; honors both env and config telemetry opt‑out.
-
Refactors
- Extracted
getOrCreateMachineId()toaltimate/util/machine-id.ts(exclusive-create, UUID v4 check, rejects symlinks/non-regular files; bounded descriptor read enforces the 512‑byte limit, including on race re-reads; returns "" and logs on errors). - Updated telemetry,
altimateplugin, andcli/welcometo use it;buildCliContext()respectsALTIMATE_TELEMETRY_DISABLED=trueandconfig.telemetry.disabled, fails closed (and logs) if config is unreadable;cli_contextappended viabuildAuthorizeUrl()in the URL fragment; docs updated to clarify the device/installation ID and PostHog vs App Insights; added tests.
- Extracted
-
Bug Fixes
- Fixed fresh‑install detection in
cli/welcome.ts: probe file existence only (no minting), avoiding ID creation for config‑opt‑out users. - Prevented auth failures on read‑only
$HOMEby handling directory creation errors and returning an empty ID instead of throwing.
- Fixed fresh‑install detection in