Skip to content

fix(cli): note every project .env provider key before it is used - #8043

Closed
michaelwang11394 wants to merge 2 commits into
mainfrom
sec-low26b-1117
Closed

michaelwang11394 wants to merge 2 commits into
mainfrom
sec-low26b-1117

Conversation

@michaelwang11394

Copy link
Copy Markdown
Contributor

What

A provider key from a project .env now prints a one-line stderr note before it is first used. The note names the variable and the .env file. This covers the providers #8041 leaves silent:

  • capture image descriptions: OPENROUTER_API_KEY, GEMINI_API_KEY / GOOGLE_API_KEY, and the Vertex service account HYPERFRAMES_VERTEX_SERVICE_ACCOUNT;
  • snapshot --describe: GEMINI_API_KEY / GOOGLE_API_KEY;
  • media-use Gemini speech (gemini-auth.mjs) and Lyria music (bgm.mjs): GEMINI_API_KEY / GOOGLE_API_KEY.

The "ignoring" notes from #8041 now escape the path as well.

Why

#8041 makes a project .env key give way when the person has a competing credential of their own. When the person has no competing credential, the project key is still used. #8041 notes that case for ElevenLabs only. A project's OpenRouter, Gemini, Google or Vertex credential is still used silently, so images, 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 builds on #8041 (stacked on fix-project-env-provider-keys). #8004 added the received-project rule and the ElevenLabs note. #8041 extends the rule to any project .env and notes ElevenLabs for any project key. This PR gives the remaining providers the same note. Merge #8041 first.

How

  • packages/cli/src/utils/dotEnv.ts: the source lookup inside yieldProjectProviderKeys moves to a module-level projectEnvSource(dir), so the new noteProjectProviderKey(name, use) uses the same ranks and origin wording. The note prints only for a key set by a project .env that survived yieldProjectProviderKeys. It prints once per key per process, and it escapes the path with terminalText.
  • Capture vision (contentExtractor.ts) notes the key the chosen provider reads. That is OPENROUTER_API_KEY, the Vertex service account, or GEMINI_API_KEY before GOOGLE_API_KEY. snapshot --describe notes the Gemini key the same way.
  • skills/media-use/audio/scripts/lib/heygen.mjs: noteProjectElevenLabsKey now calls a shared noteProjectProviderKey, and its wording does not change. A local copy of core's terminalText keeps the skill standalone. geminiAuth calls the shared note before Gemini speech. The Lyria branch of generateBgmDetached calls it with the key lyria-recipe.py reads first.
  • The wording matches fix(cli): a project .env provider key gives way to the person's own credential #8041: Using <VAR> from <path>, <a project .env | a received project>: <what> goes to that key's <provider> account.
  • Keys from the shell or saved settings print nothing new.
  • Docs: the variable table in docs/guides/authentication.mdx and the capture section of docs/packages/cli.mdx mention the note.

No visible change

Nothing changes except a new stderr note when a provider key from a project .env is used.

Test plan

  • fails without the fix: each of these fails when the source change is reverted:

    • contentExtractor.test.ts: a received Gemini key, and a received Vertex service account, each caption with exactly one note;
    • snapshot-contactSheet.test.ts: --describe with a project .env Gemini key prints one 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.
  • dotEnv.test.ts covers an escaped path, the once-per-process rule, a key from the person's own project .env, and silence for a shell key. The tests that name folders with a control character skip that part on Windows, which refuses such names.

  • vitest run on dotEnv, contentExtractor, snapshot-contactSheet, cli.dotEnv, captureAttempt and media-use passes (142 tests). All 259 media-use audio script tests pass.

  • tsc --noEmit for cli, oxlint, oxfmt, the comment ratchet and check-comment-citations pass.

  • 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

…redential

A project .env could set OPENROUTER_API_KEY, GEMINI_API_KEY, GOOGLE_API_KEY,
the Vertex settings or ELEVENLABS_API_KEY and outrank a credential the person
set in their shell or saved settings. The earlier rule covered only received
projects; a cloned or downloaded project still won.

Now every project .env provider key is unset, with a note naming the file,
when a competing provider has a credential from a surer source: the shell or
saved settings first, then the person's own project .env, then a received
one. A project key with no competing credential is still used, model and
timeout settings still apply, and the media-use scripts note an ElevenLabs
key from any project .env before speech starts.

In the CLI process an own-project key yields only within the vision choice;
the media-use scripts remake the Gemini audio choice from the passed key
origins.
A provider key from a project .env is still used when no own credential
competes. Capture vision (OpenRouter, Gemini and the Vertex service account),
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
ElevenLabs already does. The ignoring notes escape the path too.
jrusso1020
jrusso1020 previously approved these changes Nov 17, 2026

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving at 9cddadae (stacked on #8041; the merge order is yours).

  • One shared helper. noteProjectProviderKey(name, use) in dotEnv.ts, and its media-use copy in heygen.mjs, notes once per key per process. It only notes when projectEnvDir(name) is set, meaning the live process.env value is still the one the project .env supplied. A key that has given way to yours (#8041) never notes. noteProjectElevenLabsKey is now a wrapper, with the same wording as before.
  • The noted name matches the key actually read.
    • contentExtractor and snapshot --describe read GEMINI_API_KEY || GOOGLE_API_KEY, and geminiKeyName() picks the same one.
    • gemini-auth.mjs does the same.
    • Lyria notes GOOGLE_API_KEY first, matching lyria-recipe.py.
    • OpenRouter and the Vertex service account are noted by their own names.
  • Terminal safety. The .env path now goes through terminalText in both the new note and the existing "ignoring … from …" line, in both the CLI and media-use copies. The origin strings are fixed (receivedEnvOrigin returns one of three constants), so nothing else in the line comes from the project.
  • Tests. The body's "fails without the fix" line names the new cases: contentExtractor, snapshot contact sheet, dotEnv, bgm and gemini-auth.

Non-blocking:

  • heygen.mjs adds another hand copy of terminalText. media-use already has the drift-tested terminal-text.mjs from #8013, so importing that would avoid a third copy.
  • Because this targets #8041's branch, only part of CI ran (7 pass, 1 pending). Full CI will run once it's retargeted to main.

— Rames

Base automatically changed from fix-project-env-provider-keys to main November 17, 2026 07:58
@michaelwang11394
michaelwang11394 dismissed jrusso1020’s stale review November 17, 2026 07:58

The base branch was changed.

@mintlify

mintlify Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
hyperframes 🟢 Ready View Preview Nov 17, 2026, 8:02 AM

💡 Tip: Enable Automations to automatically generate PRs for you.

@michaelwang11394

Copy link
Copy Markdown
Contributor Author

Replaced by #8056. #8041 merged in a narrower shape, so this change is rebuilt on main instead of on #8041's branch. The goal is the same: a one-line note whenever a provider key from a project .env is used. It covers capture vision (including the Vertex service account), snapshot --describe, Gemini speech and Lyria. It keeps the review fixes from here.

This branch was successfully deployed

1 active deployment
staging - docs — 9cddadae Deployed Nov 17, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants