fix(cli): DO_NOT_TRACK and HYPERFRAMES_NO_TELEMETRY turn telemetry off the same way everywhere (#8781)

* fix(cli): DO_NOT_TRACK and HYPERFRAMES_NO_TELEMETRY turn telemetry off the same way everywhere

* fix(skills): the standalone media-use skill reads telemetry opt-outs through the shared check

* ci: run the edit accuracy bench when the shared telemetry opt-out check changes
This commit is contained in:
Miguel Ángel
2026-11-25 00:43:19 +00:00
committed by GitHub
parent c5ed60fc83
commit 20b020d192
17 changed files with 128 additions and 30 deletions
+1 -1
View File
@@ -250,7 +250,7 @@ jobs:
- "packages/cli/src/ui/**"
- "packages/cli/src/{background-removal,registry,telemetry}/**"
- "packages/cli/src/capture/{captureCompositionFrame,captureTimeout,navigateForCapture,readBoundedResponse}.ts"
- "packages/cli/src/media-use/lib/config-lock.mjs"
- "packages/cli/src/media-use/lib/{config-lock,telemetry-opt-out}.mjs"
- "packages/cli/src/auth/**"
- "packages/cli/scripts/**"
- "packages/core/stubs/**"
@@ -0,0 +1,6 @@
export type TelemetryOptOutVariable = "HYPERFRAMES_NO_TELEMETRY" | "DO_NOT_TRACK";
export const TELEMETRY_OPT_OUT_VARIABLES: readonly TelemetryOptOutVariable[];
export const TELEMETRY_OPT_OUT_VALUES: readonly string[];
export function telemetryOptOutVariable(
variables: Readonly<Record<string, string | undefined>>,
): TelemetryOptOutVariable | null;
@@ -0,0 +1,14 @@
// The one rule for "telemetry is off" in a process's environment. It has no imports, so the CLI, the media-use
// skill scripts (published as standalone files) and Studio's build configs can all read it.
export const TELEMETRY_OPT_OUT_VARIABLES = ["HYPERFRAMES_NO_TELEMETRY", "DO_NOT_TRACK"];
export const TELEMETRY_OPT_OUT_VALUES = ["1", "true", "yes", "on"];
/** The variable in `variables` that turns telemetry off, or null when none does. */
export function telemetryOptOutVariable(variables) {
for (const name of TELEMETRY_OPT_OUT_VARIABLES) {
const value = variables[name];
if (typeof value === "string" && TELEMETRY_OPT_OUT_VALUES.includes(value.trim().toLowerCase()))
return name;
}
return null;
}
@@ -0,0 +1,23 @@
import { strict as assert } from "node:assert";
import { test } from "node:test";
import { telemetryOptOutVariable } from "./telemetry-opt-out.mjs";
test("names the variable that turns telemetry off, the HyperFrames one first", () => {
assert.equal(telemetryOptOutVariable({ DO_NOT_TRACK: "1" }), "DO_NOT_TRACK");
assert.equal(
telemetryOptOutVariable({ HYPERFRAMES_NO_TELEMETRY: "yes" }),
"HYPERFRAMES_NO_TELEMETRY",
);
assert.equal(
telemetryOptOutVariable({ DO_NOT_TRACK: "1", HYPERFRAMES_NO_TELEMETRY: "on" }),
"HYPERFRAMES_NO_TELEMETRY",
);
});
test("reads every affirmative spelling, and nothing else, as an opt-out", () => {
for (const value of ["1", "true", "YES", " on "])
assert.equal(telemetryOptOutVariable({ DO_NOT_TRACK: value }), "DO_NOT_TRACK", value);
for (const value of ["", "0", "false", "no", "off"])
assert.equal(telemetryOptOutVariable({ DO_NOT_TRACK: value }), null, value);
assert.equal(telemetryOptOutVariable({}), null);
});
+2 -2
View File
@@ -8,6 +8,7 @@ import { homedir } from "node:os";
import { dirname, join } from "node:path";
import { withFileLock } from "./config-lock.mjs";
import { globalMediaDir } from "./media-home.mjs";
import { telemetryOptOutVariable } from "./telemetry-opt-out.mjs";
const POSTHOG_API_KEY = "phc_zjjbX0PnWxERXrMHhkEJWj9A9BhGVLRReICgsfTMmpx";
const POSTHOG_HOST = "https://us.i.posthog.com";
@@ -41,8 +42,7 @@ export function optedOut() {
// `hyperframes telemetry disable` writes telemetryEnabled: false to the
// shared config; one opt-out must cover the CLI and the media-use scripts.
readSharedConfig().telemetryEnabled === false ||
process.env.HYPERFRAMES_NO_TELEMETRY === "1" ||
process.env.DO_NOT_TRACK === "1" ||
telemetryOptOutVariable(process.env) !== null ||
process.env.CI === "true" ||
process.env.CI === "1" ||
process.env.NODE_ENV === "development"
@@ -59,6 +59,25 @@ test("optedOut respects DO_NOT_TRACK / HYPERFRAMES_NO_TELEMETRY / CI", () => {
}
});
// fails without the fix: the media-use scripts took only "1", so DO_NOT_TRACK=true silenced the CLI and not them.
for (const [name, value] of [
["DO_NOT_TRACK", "true"],
["DO_NOT_TRACK", "yes"],
["DO_NOT_TRACK", " ON "],
["HYPERFRAMES_NO_TELEMETRY", "TRUE"],
]) {
test(`optedOut respects ${name}=${JSON.stringify(value)}, as the CLI does`, () => {
const saved = { ...process.env };
try {
withoutTelemetryOptOut();
process.env[name] = value;
assert.equal(optedOut(), true);
} finally {
restoreEnv(saved);
}
});
}
test("optedOut honors telemetryEnabled: false from the shared config", () => {
const savedEnv = { ...process.env };
const { root, home } = sandbox();
+3 -17
View File
@@ -1,3 +1,4 @@
import { telemetryOptOutVariable } from "../media-use/lib/telemetry-opt-out.mjs";
import { isDevMode } from "../utils/env.js";
import { POSTHOG_API_KEY } from "./posthogKey.js";
@@ -13,28 +14,13 @@ export type TelemetryStatus = {
source: TelemetryStatusSource;
};
const ENV_OPT_OUT_VALUES = new Set(["1", "true", "yes", "on"]);
/**
* Parse privacy-control environment variables consistently at every CLI
* surface. Be liberal about common affirmative spellings so an explicit
* opt-out never silently becomes an opt-in.
*/
function isEnvOptOutValue(value: string | undefined): boolean {
return value !== undefined && ENV_OPT_OUT_VALUES.has(value.trim().toLowerCase());
}
/**
* Return the runtime/build override that suppresses telemetry before the
* persisted preference is considered.
*/
export function telemetryRuntimeOverride(): Exclude<TelemetryStatusSource, "config"> | null {
if (isEnvOptOutValue(process.env["HYPERFRAMES_NO_TELEMETRY"])) {
return "HYPERFRAMES_NO_TELEMETRY";
}
if (isEnvOptOutValue(process.env["DO_NOT_TRACK"])) {
return "DO_NOT_TRACK";
}
const envOptOut = telemetryOptOutVariable(process.env);
if (envOptOut) return envOptOut;
if (isDevMode()) {
return "dev_mode";
}
+8 -6
View File
@@ -43,15 +43,17 @@ function isApiKeyConfigured(): boolean {
return POSTHOG_API_KEY.startsWith("phc_");
}
// VITE_HYPERFRAMES_NO_TELEMETRY mirrors the CLI's HYPERFRAMES_NO_TELEMETRY=1
// opt-out so HeyGen's own dev/CI builds can suppress telemetry from the studio
// bundle the same way. Vite injects it at build time. Match the CLI's
// affirmative privacy-control spellings.
declare const __HF_TELEMETRY_OPT_OUT_VALUES__: readonly string[] | undefined;
// VITE_HYPERFRAMES_NO_TELEMETRY opts a build out, in the spellings Studio's build injects from the CLI's
// shared check; a bundle built without them treats any value as an opt-out.
// `import.meta.env` may be undefined in non-Vite bundlers (Next.js Turbopack).
function isBuildTimeOptOut(): boolean {
try {
const v = import.meta.env.VITE_HYPERFRAMES_NO_TELEMETRY as string | undefined;
return v !== undefined && ["1", "true", "yes", "on"].includes(v.trim().toLowerCase());
const value = (import.meta.env.VITE_HYPERFRAMES_NO_TELEMETRY as string | undefined)?.trim();
if (!value) return false;
if (typeof __HF_TELEMETRY_OPT_OUT_VALUES__ === "undefined") return true;
return __HF_TELEMETRY_OPT_OUT_VALUES__.includes(value.toLowerCase());
} catch {
return false;
}
+2
View File
@@ -1,4 +1,5 @@
import { defineConfig } from "tsup";
import { TELEMETRY_OPT_OUT_DEFINE } from "./vite.telemetry";
export default defineConfig({
tsconfig: "tsconfig.lib.json",
@@ -13,6 +14,7 @@ export default defineConfig({
dts: true,
clean: false,
splitting: true,
define: TELEMETRY_OPT_OUT_DEFINE,
external: [
"@codemirror/autocomplete",
"@codemirror/commands",
+2
View File
@@ -25,6 +25,7 @@ import {
PREVIEW_ALLOWED_HOSTS_ENV,
previewAllowedHostsFromEnv,
} from "../studio-server/src/helpers/requestIdentity";
import { TELEMETRY_OPT_OUT_DEFINE } from "./vite.telemetry";
async function loadRuntimeSourceForDev(
server: import("vite").ViteDevServer,
@@ -366,6 +367,7 @@ export default defineConfig({
plugins: [react(), tailwindcss(), devProjectApi()],
define: {
__STUDIO_VERSION__: JSON.stringify(studioPkg.version),
...TELEMETRY_OPT_OUT_DEFINE,
},
resolve: {
alias: {
+6
View File
@@ -0,0 +1,6 @@
import { TELEMETRY_OPT_OUT_VALUES } from "../cli/src/media-use/lib/telemetry-opt-out.mjs";
/** The opt-out spellings Studio's browser code compares its build flag against. */
export const TELEMETRY_OPT_OUT_DEFINE = {
__HF_TELEMETRY_OPT_OUT_VALUES__: JSON.stringify(TELEMETRY_OPT_OUT_VALUES),
};
@@ -32,6 +32,7 @@ export const MEDIA_USE_COPY_NAMES = [
"received-env.mjs",
"recipe-store.mjs",
"telemetry.mjs",
"telemetry-opt-out.mjs",
"terminal-text.mjs",
"transcriptCutFade.mjs",
"words.mjs",
+5
View File
@@ -16,6 +16,11 @@ export const skillModuleCopies = [
"packages/cli/src/media-use/lib/received-env.mjs",
["skills/media-use/scripts/lib/received-env.mjs"],
],
["packages/cli/src/media-use/lib/telemetry.mjs", ["skills/media-use/scripts/lib/telemetry.mjs"]],
[
"packages/cli/src/media-use/lib/telemetry-opt-out.mjs",
["skills/media-use/scripts/lib/telemetry-opt-out.mjs"],
],
[
"packages/cli/src/media-use/lib/openverse.mjs",
["skills/media-use/audio/scripts/lib/openverse.mjs"],
+2 -2
View File
@@ -18,8 +18,8 @@
"files": 13
},
"media-use": {
"hash": "7aa1e3701f3a10c0",
"files": 134
"hash": "ff2fa3c4eb8a7bc1",
"files": 135
},
"remotion-to-hyperframes": {
"hash": "3a1dd4a513701ef6",
@@ -0,0 +1,14 @@
// The one rule for "telemetry is off" in a process's environment. It has no imports, so the CLI, the media-use
// skill scripts (published as standalone files) and Studio's build configs can all read it.
export const TELEMETRY_OPT_OUT_VARIABLES = ["HYPERFRAMES_NO_TELEMETRY", "DO_NOT_TRACK"];
export const TELEMETRY_OPT_OUT_VALUES = ["1", "true", "yes", "on"];
/** The variable in `variables` that turns telemetry off, or null when none does. */
export function telemetryOptOutVariable(variables) {
for (const name of TELEMETRY_OPT_OUT_VARIABLES) {
const value = variables[name];
if (typeof value === "string" && TELEMETRY_OPT_OUT_VALUES.includes(value.trim().toLowerCase()))
return name;
}
return null;
}
+2 -2
View File
@@ -8,6 +8,7 @@ import { homedir } from "node:os";
import { dirname, join } from "node:path";
import { withFileLock } from "./config-lock.mjs";
import { globalMediaDir } from "./media-home.mjs";
import { telemetryOptOutVariable } from "./telemetry-opt-out.mjs";
const POSTHOG_API_KEY = "phc_zjjbX0PnWxERXrMHhkEJWj9A9BhGVLRReICgsfTMmpx";
const POSTHOG_HOST = "https://us.i.posthog.com";
@@ -41,8 +42,7 @@ export function optedOut() {
// `hyperframes telemetry disable` writes telemetryEnabled: false to the
// shared config; one opt-out must cover the CLI and the media-use scripts.
readSharedConfig().telemetryEnabled === false ||
process.env.HYPERFRAMES_NO_TELEMETRY === "1" ||
process.env.DO_NOT_TRACK === "1" ||
telemetryOptOutVariable(process.env) !== null ||
process.env.CI === "true" ||
process.env.CI === "1" ||
process.env.NODE_ENV === "development"
@@ -73,6 +73,24 @@ test("optedOut still honors the env opt-outs", () => {
}
});
// fails without the fix: the skill took only "1", so DO_NOT_TRACK=true silenced the CLI and not it.
for (const [name, value] of [
["DO_NOT_TRACK", "true"],
["DO_NOT_TRACK", "yes"],
["DO_NOT_TRACK", " ON "],
["HYPERFRAMES_NO_TELEMETRY", "TRUE"],
]) {
test(`optedOut respects ${name}=${JSON.stringify(value)}, as the CLI does`, () => {
writeConfig(null);
process.env[name] = value;
try {
assert.equal(optedOut(), true);
} finally {
delete process.env[name];
}
});
}
test("optedOut reads the shared config from HYPERFRAMES_CONFIG_DIR when it is set", () => {
writeConfig(null);
const configDir = join(home, "elsewhere");