Skip to content

Commit 33de593

Browse files
author
saravmajestic
committed
feat: append cli_context param to altimate auth URL for PostHog session correlation
Adds a base64url-encoded cli_context query param to the browser auth URL opened by the CLI. The blob carries { v, machine_id, cli_version } so the frontend can call posthog.register / posthog.alias and link the CLI device to the authenticated user without any PII traveling in the URL.
1 parent 28caf71 commit 33de593

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

packages/opencode/src/altimate/plugin/altimate.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { createServer } from "http"
33
import { randomBytes } from "crypto"
44
import open from "open"
55
import { AltimateApi } from "../api/client"
6+
import fs from "fs"
7+
import os from "os"
8+
import path from "path"
9+
import { InstallationVersion } from "@opencode-ai/core/installation/version"
610

711
// Loopback port range the CLI listens on for the browser to deliver the gateway
812
// credential after sign-in. We prefer 7317 (mnemonic + otherwise unused in this
@@ -24,6 +28,19 @@ const DEFAULT_WEB_URL = "https://app.myaltimate.com"
2428
// the token exchange at a local backend when the web has no BACKEND_API_URL to
2529
// deliver.
2630
const DEFAULT_API_URL = "https://api.myaltimate.com"
31+
// Build a base64url-encoded context blob so the frontend can correlate this
32+
// browser auth session with CLI telemetry. Fields are minimal and non-PII:
33+
// machine_id is a random UUID stored locally, never an email or real identity.
34+
function buildCliContext(): string {
35+
let machineId = ""
36+
try {
37+
machineId = fs.readFileSync(path.join(os.homedir(), ".altimate", "machine-id"), "utf8").trim()
38+
} catch {
39+
// machine-id not yet written — omit gracefully
40+
}
41+
const ctx = { v: 1, machine_id: machineId, cli_version: InstallationVersion }
42+
return Buffer.from(JSON.stringify(ctx)).toString("base64url")
43+
}
2744

2845
// The one-time login_token is POSTed to the callback-supplied API base, so that
2946
// base must be trusted — otherwise a crafted callback could exfiltrate the token
@@ -308,7 +325,8 @@ export async function AltimateAuthPlugin(_input: PluginInput): Promise<Hooks> {
308325
const authorizeUrl =
309326
`${webUrl}/register?client=altimate-code` +
310327
`&redirect=${encodeURIComponent(redirect)}` +
311-
`&state=${state}`
328+
`&state=${state}` +
329+
`&cli_context=${encodeURIComponent(buildCliContext())}`
312330

313331
// Try to open the browser. Failure is silent because the URL is
314332
// already surfaced elsewhere: the auth dialog in packages/tui/src/

0 commit comments

Comments
 (0)