-
Notifications
You must be signed in to change notification settings - Fork 1
feat: embed Laminar project key into release binaries #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Telemetry key injection. | ||
| // | ||
| // At build time, `packages/opencode/script/build.ts` substitutes | ||
| // `BCODE_DEFAULT_LMNR_KEY` with a string literal via Bun's `define`. The | ||
| // release workflow sources that value from a GitHub Actions secret; local | ||
| // `bun run build` invocations leave it empty, so self-builds never emit | ||
| // telemetry. | ||
| // | ||
| // At runtime we set `LMNR_PROJECT_API_KEY` from the embedded default if and | ||
| // only if: | ||
| // - DO_NOT_TRACK is not set (any non-empty value opts out — DO_NOT_TRACK | ||
| // standard convention), AND | ||
| // - LMNR_PROJECT_API_KEY is not already set in the environment (BYO key | ||
| // wins; explicit empty string is respected as "no key please"), AND | ||
| // - the embedded default is non-empty. | ||
| // | ||
| // `applyTelemetryKey()` is invoked as a side effect on module import (last | ||
| // statement of this file). Because `packages/opencode/src/index.ts` imports | ||
| // this module before any other module that might consume the env var, the | ||
| // gate is guaranteed to run before any downstream module-load code can | ||
| // observe `LMNR_PROJECT_API_KEY` — sidestepping ESM static-import hoisting | ||
| // entirely. | ||
|
|
||
| declare const BCODE_DEFAULT_LMNR_KEY: string | ||
|
|
||
| export const applyTelemetryKey = () => { | ||
| // DO_NOT_TRACK: presence with any non-empty value opts out, per the | ||
| // de-facto standard (consoledonottrack.com, Astro, Homebrew, npm). | ||
| if (process.env.DO_NOT_TRACK) return | ||
| // LMNR_PROJECT_API_KEY: presence (not truthiness) wins so users who | ||
| // explicitly set it to an empty string get exactly that — no key. | ||
| if (process.env.LMNR_PROJECT_API_KEY !== undefined) return | ||
| // `typeof` first: in dev (no Bun `define` substitution) the identifier is | ||
| // undeclared and a direct read throws ReferenceError. | ||
| if (typeof BCODE_DEFAULT_LMNR_KEY === "undefined" || !BCODE_DEFAULT_LMNR_KEY) return | ||
| process.env.LMNR_PROJECT_API_KEY = BCODE_DEFAULT_LMNR_KEY | ||
| } | ||
|
|
||
| // Run as an import side effect: this module is imported as the very first | ||
| // import of `packages/opencode/src/index.ts`, so by the time any other | ||
| // module's top-level code reads `LMNR_PROJECT_API_KEY` the gate has already | ||
| // resolved. | ||
| applyTelemetryKey() | ||
|
|
||
| export * as Telemetry from "./telemetry" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Use a presence check for
DO_NOT_TRACK(!== undefined) to match the documented "is set" opt-out gate.Prompt for AI agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonʼt change. The DO_NOT_TRACK convention (consoledonottrack.com) is "set to a non-empty value to opt out" —
DO_NOT_TRACK=1opts out,DO_NOT_TRACK=(empty) does not. The current truthiness check matches that exactly:""is falsy and falls through;"1"/"true"/"0"(non-empty strings) all opt out. Switching to!== undefinedwould change the contract so that exporting an emptyDO_NOT_TRACKopts out, which contradicts the standard.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback! I've saved this as a new learning to improve future reviews.