Repository navigation
fix(cli): note every project .env provider key before it is used - #8056
Conversation
A provider key from a project .env is still used when no own credential competes. Capture vision (OpenRouter, Gemini, Google and both Vertex parts), snapshot --describe, Gemini speech and Lyria music now print one note per key before it is first used, naming the variable and the escaped .env path, as the ElevenLabs note does. The ignoring notes escape the path too, and the media-use skill gets a generated copy of the CLI's terminal-text helper.
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
jrusso1020
left a comment
There was a problem hiding this comment.
APPROVE at caa1b64c
-
Every project
.envkey now gets a note before its first provider request:- capture vision (
contentExtractor.ts:371) snapshot --describe(snapshot.ts:2086)- Gemini speech (
gemini-auth.mjs:19) - Lyria (
bgm.mjs:140)
Each note names the key that path actually reads.
- capture vision (
-
A note is the right strength here. Base URLs, proxies and
NODE_OPTIONSnever load from a project.env, because both loaders accept only a fixed list of names (dotEnv.ts:6-24,heygen.mjs:72-80). -
The shell still wins. A project value never overwrites an existing variable (
dotEnv.ts:100), and a note fires only while the project value is the one in use. Notes print only the name and the escaped path, never the value. -
Tests: locally, 107/107 focused vitest and 59/59 media-use and parity tests pass. Making both note helpers no-ops fails 5 CLI tests and 2 media-use tests. CI is green.
-
Nits, not blocking:
FIGMA_TOKENfrom a project.envis still used with no note, so "every" in the title is slightly broad.- The two HeyGen "Using" notes (
auth/resolver.ts:121,heygen.mjs:297) still print the path withoutterminalText.
Need ✅ · Size ✅ · Reuse ✅ · Simpler ✅
Risk: low. The change only adds stderr output.
— Rames
jrusso1020
left a comment
There was a problem hiding this comment.
Approve at caa1b64c. Each project-.env provider key now prints one escaped note on stderr, naming the key and the file, before the key is used. No key value is ever printed.
Coverage. Each reader notes the key it actually uses:
- Capture vision:
visionCredential()follows the provider-pick order atcontentExtractor.ts:353: OpenRouter, both Vertex parts,GEMINI,GOOGLE. snapshot --describe:geminiKeyName()isGEMINI || GOOGLE.- Gemini speech:
gemini-auth.mjsnotesGEMINIfirst. - Lyria:
bgm.mjsnotesGOOGLEfirst, matchinglyria-recipe.py:58.
Firing. A note fires only when projectEnvDir is set, so shell keys stay silent. The once-flag is set before the await.
#8043 findings. heygen.mjs now imports the shared skills/media-use/scripts/lib/terminal-text.mjs, and both generated copies are byte-identical.
Local verification
- CLI vitest (
dotEnv,contentExtractor,snapshot-contactSheet): 107 passed. - Skill
node --test(gemini-auth,bgm, copy-parity): 15 passed. generate-skill-module-copies.mjs --check: in sync.- Each of 5 mutants was caught:
- M1, drop the once-flag: 3 failures.
- M2,
heygen.mjspath unescaped: "a received .env's Gemini key is used with one note naming the file". - M3, Vertex notes only its first part: "notes both parts…".
- M4, Lyria names the wrong key: "Lyria music with a project .env's Gemini key prints one note".
- M5,
--describenames the wrong key: "notes once that --describe sends frames…".
Non-blocking. Points 1 and 2 predate this PR but are the same class of bug.
packages/cli/src/utils/dotEnv.ts:251printsignored.join(", ")raw. Those key names come from a received.env, so an ESC sequence in a key name reaches the terminal. It's the one "ignoring" line in this file left unescaped.heygen.mjs:297andauth/resolver.ts:121still printjoin(dir, ".env")unescaped and don't use the shared helper.FIGMA_TOKENis inPROJECT_ENV_KEYS(dotEnv.ts:10) and gets used silently (figma/tokens.ts:87and others). The title says "every". Either note it, or narrow the title to the providers the description lists.- Test gaps:
- The escaped "ignoring" lines at
dotEnv.ts:169andheygen.mjs:210have no test. projectKeysNotedis module-level and never reset, so a future test in the same file could swallow another test's note.
- The escaped "ignoring" lines at
Review by Rames
What
A provider key from a project
.envnow prints a one-line stderr note before it is first used. The note names the variable and the.envfile. It covers the keys that #8004 and #8041 leave silent:OPENROUTER_API_KEY,GEMINI_API_KEY,GOOGLE_API_KEY, and both Vertex parts,HYPERFRAMES_VERTEX_PROJECT_IDandHYPERFRAMES_VERTEX_SERVICE_ACCOUNT;snapshot --describe:GEMINI_API_KEYorGOOGLE_API_KEY;gemini-auth.mjs) and Lyria music (bgm.mjs):GEMINI_API_KEYorGOOGLE_API_KEY.The existing "ignoring" notes, in the CLI and in media-use, now escape the path as well.
Why
After #8004 and #8041, a project
.envkey gives way when the person has a competing credential of their own. When they have none, the project key is still used. Only ElevenLabs says so today. A project's OpenRouter, Gemini, Google or Vertex credential is used silently. So captured images, snapshot frames, narration text or music prompts can go to the account behind someone else's key without the person knowing.Related work (follows #8004)
Follows #8004 and #8041. #8004 added the received-project rule and the ElevenLabs note. #8041 extended the rule to the person's own project
.envfor capture vision and for media-use speech and music, and notes ElevenLabs for any project key. This PR gives the remaining provider keys the same note.How
packages/cli/src/utils/dotEnv.tsaddsnoteProjectProviderKey(name, use). It runs only for a key that a project.envset and that survivedyieldReceivedProviderKeysandyieldProjectVisionKeys. It prints once per key per process, and it escapes the path withterminalText. The origin comes from the existinguntrustedEnvOrigin, read as "a received project", or "a project .env" when the file is not received. That matches the ElevenLabs note.contentExtractor.ts) notes each part of the credential it picks. A newvisionCredential()reads the sameVISION_CREDENTIALSlist thatyieldProjectVisionKeysuses, so the noted keys match the ones capture uses.snapshot --describenotes the Gemini key it reads,GEMINI_API_KEYbeforeGOOGLE_API_KEY.skills/media-use/audio/scripts/lib/heygen.mjs:noteProjectElevenLabsKeynow calls a sharednoteProjectProviderKey, and its wording does not change.geminiAuthcalls the shared note before Gemini speech. The Lyria branch ofgenerateBgmDetachedcalls it with the keylyria-recipe.pyreads first.skills/media-use/scripts/lib/terminal-text.mjs. It is a generated copy of the CLI'spackages/cli/src/media-use/lib/terminal-text.mjs, kept in sync bygenerate-skill-module-copies.mjsand the media-use copy-parity check.docs/guides/authentication.mdxand the capture section ofdocs/packages/cli.mdxmention the note.No visible change
Nothing changes except a new stderr note when a provider key from a project
.envis used.Test plan
fails without the fix: each of these fails when the source change is reverted:
contentExtractor.test.ts: a received Gemini key captions with exactly one note, and a received Vertex credential captions with one note per part;snapshot-contactSheet.test.ts:--describewith a project.envGemini key prints one note;dotEnv.test.ts: escaped paths, the once-per-process rule, a key from the person's own.env, silence for a shell key, and an escaped path in the "ignoring" note;gemini-auth.test.mjs: Gemini speech with a received key prints one note with the path escaped;bgm.test.mjs: Lyria music with a project key prints one note.The tests that name a folder with a control character use a plain name on Windows, which refuses those names.
vitest runondotEnv,contentExtractor,snapshot-contactSheet,cli.dotEnv,captureAttempt,media-useandresolverpasses (192 tests). All 260 media-use audio script tests pass. The media-use copy-parity,terminalTextparity and skill import-boundary checks pass.tsc --noEmitfor cli, oxlint, oxfmt, the comment ratchet andcheck-comment-citationspass.Unit tests added/updated
Manual testing performed
Documentation updated (if applicable)
Comments follow CONTRIBUTING.md "Comments": they say why, not what, and a bug fix says what the code must do and how to reproduce the bug