Repository navigation
fix(cli): a project .env provider key gives way to the person's own credential - #8041
Conversation
…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.
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
Edit accuracy: accurate 267 (base branch 267), smooth 85 of thoseThe gate passes. Quarantined, measured but not gated (8)
Unstable (1)
|
eddy-heygen
left a comment
There was a problem hiding this comment.
(Eddy's agent) Reviewed by Eddy's Claude agent at commit 6c30d8b.
Verdict: changes requested. The blockers below need to be resolved; comment here when updated and I will re-review and clear this.
Summary. Before this change, only a project marked as received had its .env provider keys give way to the person's own credential; a cloned or unzipped project's .env could still pick the vision, speech or music provider account, so captured images, narration text or music prompts could go to an account the project author controls. The PR ranks every key by source (shell or saved settings, own project .env, received project .env) and unsets a project key when a competing provider has a credential from a better-ranked source, in the CLI, in capture's .env lookup and in the media-use audio scripts, with a note naming the file. The security direction is right and the stated path is closed for vision capture, but the "competing" test is by variable group, not by what the consuming feature can actually use, so the person's own project keys are now removed in configurations where the shell credential cannot do the job (frame descriptions in snapshot, generated music), which breaks working setups.
The direction is right, and the received-project case is closed. Two normal setups for a person's OWN project now lose a key that nothing else can replace. I confirmed the first in the code at this commit and read the lists the second rests on.
- For a project
.envthat is the person's own, a key is weighed against the whole vision group, and this runs at start-up for every command. With an aggregator key in the shell and a model-vendor API key in the person's own project.env, the project key is removed, and the frame-description step, which reads only that key, reports it as not set and skips. On the default branch this happened only for received projects. - In the audio scripts, a service-account variable in the shell counts as a rival of the API key in the person's own project
.env. The reviewer traced that music generation accepts only the API key, so it falls back or produces nothing.
To resolve: weigh an own-project key only against credentials the consuming feature can actually use, or apply the yield at the step that uses it instead of globally. The stricter rule can stay for received projects. Please add a test for each of the two setups.
Blockers
packages/cli/src/utils/dotEnv.ts:166: Own project's model-vendor-API key is removed at CLI start whenever the shell holds any other vision-group variable, breaking features only that key can serve. Cause: for a non-received project .env the key is weighed against the whole vision group (lines 116-122, 166-173), and cli.ts:77 runs this for every command, not only capture. Sequence: the shell exports the aggregator vision key (rank 0); the person's own project .env holds the model-vendor-API key (rank 1), as the docs recommend. The model-vendor-API key is deleted from the process with a note saying the aggregator key is used instead. Consequence:snapshot --describereads only the model-vendor-API key (packages/cli/src/commands/snapshot.ts:2069-2071) and now prints that the key is not set and skips, although the aggregator key cannot serve that feature; the music readiness report (audio/providers.ts:90) also shows no key. On the default branch this happened only for received projects. To resolve: Weigh a key only against credentials the consuming feature can actually use: either apply the vision yield at the capture caption step (captureAttempt.ts:117) rather than globally at cli.ts:77 for own-project keys, or have snapshot/music read the key before/independently of the vision yield. Add a test: shell aggregator key + own .env model-vendor-API key, snapshot describe still has its key.skills/media-use/audio/scripts/lib/heygen.mjs:186: Audio scripts drop the own project's model-vendor-API key next to a shell service-account variable that music generation cannot use. Cause: for any project .env (rank 1 now, previously only received), ownCompetingCredential treats the service-account path/JSON variables as competitors of the API key (lines 91-96, 183-186). Sequence: a developer has the standard cloud service-account path variable exported for unrelated work and the model-vendor-API key in their own project .env; audio.mjs:120 calls loadEnvFromDir, which deletes the key with a note that the service account is used. Consequence: generated music accepts only an API key (bgm.mjs:24 and :128, lyria-recipe.py:58), so it silently falls back to the local model or produces no track; speech switches to a service account that may have no access to that API. The PR description says the CLI side deliberately avoids exactly this for capture, and the new test at heygen.test.mjs ('leaves out a project .env's Gemini key when the shell has Gemini credentials') pins the breaking behaviour. To resolve: For an own-project key, count the service-account variables as competitors only for the speech choice (where they are usable), not for music; or keep the API key available to the music path. Received projects can keep the stricter rule.
Non-blockers
skills/media-use/audio/scripts/lib/heygen.mjs:199: Explicit choice of the secondary voice provider now fails for a signed-in person whose key is in their own project .env. With any first-party credential present (token, shell key, or anything in the saved credentials file, including an expired login, since storedCredential() is truthy for those at line 190), the own-project voice key is deleted. An explicit provider selection then throws at tts.mjs:58-59 saying the key is not set although the file sets it. The automatic path is unchanged (first-party provider already won). The docs change at docs/guides/authentication.mdx:155 states the new rule, so this looks intended, but the error text is misleading and an unusable saved login still knocks the key out. To resolve: Either honour an explicit provider choice for an own-project key (with the existing note), or make the thrown message say the key was ignored and to set it in the shell; do not count an expired/unreadable saved login as a competitor.packages/cli/src/utils/dotEnv.ts:171: The two halves of one service-account vision credential are treated as rivals; a lone unusable shell variable also knocks out project keys. The cloud project id and the service-account JSON sit in the same group (lines 116-122) and a competitor is any non-empty variable (line 133). Shell has the service-account JSON, own project .env has the project id (or the reverse): the .env half is deleted, contentExtractor.ts:343 needs both, so capture writes no vision captions. Likewise a shell that has only the project id removes an own-project vision key although no usable shell credential exists. For received projects this is protective and pre-existing; the PR extends it to own projects. To resolve: Treat a credential as competing only when it is complete (both halves present from a better source), and do not weigh the two halves of one provider against each other for own-project keys.packages/cli/src/capture/captureAttempt.ts:117: Capture prints the 'ignoring' note twice and the origin scan now runs for every project key. cli.ts:77 drops the key and forgets its origin; capture's loadEnvFile (scaffolding.ts:20-36) then re-reads the same .env, sets the key again because it is no longer in the environment, and the second yield drops it again with a second identical note. Separately dotEnv.ts:165 resolves the received-record status before checking whether the key has any competitor, so every start with any project .env key does that folder scan. To resolve: Remember dropped keys so the capture re-read does not re-apply them, and compute competitors before calling sourceOf.
What the change needed to do
- A provider key from any project .env (not only a received one) must not outrank a vision credential the person set in their shell: met (packages/cli/src/utils/dotEnv.ts:162-180: every project-set key is ranked and unset when a competitor in the vision group has a lower rank; called at packages/cli/src/cli.ts:77 and packages/cli/src/capture/captureAttempt.ts:117 (after capture's own .env walk). contentExtractor.ts:335-342 reads the env only after that.)
- Same rule for speech and music keys in the media-use audio scripts, including keys the CLI loaded and passed down: met (skills/media-use/audio/scripts/lib/heygen.mjs:177-208 (keyRank, ownCompetingCredential, yieldProjectProviderKeys) run from loadEnvFromDir:223-227 after inheritProjectKeyOrigins:99-110; the CLI passes origins at packages/cli/src/commands/media-use.ts:87-91. The scripts re-read the project .env themselves but apply the yield after loading, so the re-read does not undo it.)
- A received .env still gives way to the person's own project .env: met (dotEnv.ts:142 RANK and :172 strict rank comparison; test at dotEnv.test.ts 'drops a received .env's key in favour of the person's own project .env key'.)
- Settings a project .env may still apply must not redirect requests carrying the person's own credential to a host the project chooses: met (dotEnv.ts:5-23 allowlist has no base URL, proxy or organisation variable; the one host-shaping value (Vertex location) is checked against a region pattern at contentExtractor.ts:114-123 and model ids at :115; the aggregator endpoint is a fixed literal at contentExtractor.ts:392; the scripts' allowlist heygen.mjs:71-80 excludes the API base. Unchanged from the default branch.)
- The note names the file and variable only, never the key value: met (dotEnv.ts:177-179 and heygen.mjs:204-206, 217-219 interpolate variable name, origin label, .env path and the competing variable's name only.)
- The person's own legitimate project .env keys keep working: partly met (Kept when no competitor exists (dotEnv.ts:174). Removed when a same-group shell variable exists that the consuming feature cannot use: see blocking findings at dotEnv.ts:166 and heygen.mjs:186.)
- Regression tests that fail on the old code: met (dotEnv.test.ts new cases for a non-received project, contentExtractor.test.ts parametrised received/cloned case driving the real caption function, heygen.test.mjs new cases; the old 'keeps own key ahead of shell' assertions were inverted.)
Open outside this PR
- Remainder by design: with no competing credential of the person's own, a project .env key is still used, so a person with no keys who runs a shared project sends captured images or narration to the project author's account. The voice path prints a one-line note first (heygen.mjs:213-220); the vision path prints nothing in that case.
- A cloned (not received-marked) project .env and the person's own project .env share the same rank, so when capture output sits inside a cloned folder its key can still win over a key in the person's own working-directory .env. Same on the default branch.
- A project .env may still choose the model name used with the person's own aggregator key (cost choice, not a redirect). Same on the default branch.
- The origin hand-off to the audio scripts covers only the model-vendor and voice keys (heygen.mjs:106); whether a first-party key loaded by the CLI from the project .env reaches the child as an apparent shell key depends on the media auth environment wrapper, which this PR does not touch and I did not trace.
- Docs row for the model-vendor-API keys in docs/guides/authentication.mdx:156 does not mention that a project .env key now gives way to a shell service account in the audio scripts.
CI: every check that ran passes at this commit.
How this was reviewed: a code-review pass and a security-review pass, by a reviewer agent in an isolated checkout of this commit; I then read the core of the fix and the cited lines myself. Nothing was built or run.
…s its feature can use Review found that the global yield removed a person's own project keys where the shell credential could not do the job: snapshot's Gemini key next to a shell OpenRouter key, and a Gemini key that music needs next to a shell service account. - Startup keeps the received-project rule only. - Capture drops a project .env vision key only when the shell or settings hold another complete vision credential; the two Vertex parts are one credential and are not weighed against each other. - A key dropped once is not brought back when capture re-reads the same .env, so its note prints once. - In the audio scripts, an own project's Gemini key gives way only to the other Gemini API key, which speech and music both accept, and an own ElevenLabs key stays for an explicit provider choice.
|
Thanks, Eddy. Both blockers are addressed in e136b28, and the PR description now matches. Blocker 1 (dotEnv.ts): Startup is back to the received-only rule from #8004, so Blocker 2 (heygen.mjs): An own project's Gemini key now gives way only to the other Gemini API key, which speech and music both accept. A shell service account never removes it. Test: "keeps a person's own .env Gemini key next to a shell service account music cannot use". The received rule is unchanged. Non-blockers:
Open items: the vision path still uses a project key silently when the person has no credential at all, and the same-rank case (a cloned output folder next to an own working-directory |
(Eddy's agent) Superseded by the re-review at e136b28.
eddy-heygen
left a comment
There was a problem hiding this comment.
(Eddy's agent) Reviewed by Eddy's Claude agent at commit e136b28.
Verdict: not approved yet (comment only). Both blockers are resolved; the PR conflicts with the default branch.
Summary. Before this change only a project marked as received had its .env provider keys give way to the person's own credential; a cloned or unzipped project's .env could still choose the vision account that receives captured site images. At this head start-up is back to the received-only rule (unchanged from the default branch), a new capture-only step drops any project .env vision key when the shell holds another complete vision credential, and the audio scripts make an own-project model-vendor API key give way only to the other API key of the same vendor. Both earlier blockers are resolved and the three earlier non-blockers are fixed. What remains open for a cloned (not received) project is the same as on the default branch: snapshot frame description and speech next to a shell service account. The PR currently conflicts with the default branch in one generated file.
Re-review. Both blockers are resolved, and my change request is dismissed. I have not approved yet because the PR conflicts with the default branch (the generated skills manifest; its hash needs regenerating after a rebase). Say when it is rebased and I will read it once more and approve.
- Start-up is back to the received-only rule, so a person's own project key is no longer removed for every command. The frame-description step gets its key again.
- The own-project rule runs only in capture, and only against a complete vision credential in the shell.
- In the audio scripts, an own-project API key gives way only to the other API key of the same vendor, never to a service-account variable.
- The three earlier non-blockers are fixed, and there are tests for both setups I named.
Please narrow the opening sentence of the description (non-blocker 1). For a cloned project that is not marked as received, the frame-description step and speech next to a shell service account still take the project's key, as on the default branch. The description says every project .env key gives way.
Blockers
None.
Non-blockers
skills/media-use/audio/scripts/lib/heygen.mjs:189: Remainder for cloned projects: snapshot frame description and speech next to a shell service account still take the project's key; the PR's opening sentence claims more. With start-up back to received-only, a cloned (not received) project's .env model-vendor API key still wins in two places. (a) snapshot --describe: shell holds the other API-key variable of the same vendor, project .env holds the first; packages/cli/src/commands/snapshot.ts:2069 reads the project one first, so frames go to the project's key. (b) Speech: shell holds a service-account variable, project .env holds an API key; line 189 does not count the service account as a rival for rank 1 and gemini-auth.mjs:16 prefers the API key, so narration text goes to the project's key. Both behave exactly the same on the default branch, so this is a remainder, not a regression, and (b) is the deliberate trade made to keep music working. The description's first sentence ('any project .env ... wherever that credential can do the same job') says more than the code does, although the bullets below it are accurate. To resolve: Reword the opening sentence of the description to the three bullets' scope, and track the two remainders as follow-ups (apply the same-vendor API-key rule in snapshot; choose the service account for speech while leaving the key for music).packages/cli/src/utils/dotEnv.ts:188: The capture note can name a credential capture will not use. The rival named in the note is the first complete one in list order (aggregator, first API key, second API key, two-part cloud credential), but capture's own order is aggregator, then the two-part cloud credential, then the API key (contentExtractor.ts:353-357). Shell has an API key and the complete two-part credential; project .env has the aggregator key: the note says capture uses the API key, and capture actually uses the two-part credential. The key is still dropped correctly; only the message is wrong. To resolve: Order VISION_CREDENTIALS the way contentExtractor chooses, or pick the named rival with the same precedence.skills-manifest.json:21: Merge conflict in the generated skills manifest; hash must be regenerated after rebase. The default branch changed the same media-use hash line, so the PR cannot merge as is. The manifest check passes at this head, but the hash will be different again once rebased. To resolve: Rebase on the default branch and regenerate the manifest with the repository's own script; let the manifest check and the pending jobs finish.
What the change needed to do
- A vision key from any project .env (not only a received one) must not outrank a complete vision credential the person set in their shell, in capture: met (packages/cli/src/utils/dotEnv.ts:185-201 drops every project-set part of a vision credential when another credential has all parts set outside a project .env; called at packages/cli/src/capture/captureAttempt.ts:118 after capture's own .env walk (line 116) and before contentExtractor.ts:335-343 reads the environment. captureWebsiteAttempt is the only route to the caption step (capture/index.ts:46, commands/capture.ts:234).)
- Earlier blocker 1: start-up must not remove the person's own project key that only one feature can use (aggregator key in shell, model-vendor API key in own .env): met (packages/cli/src/cli.ts:73-77 calls only yieldReceivedProviderKeys; dotEnv.ts:161 yields only keys whose folder is received or unchecked, so an own-project key stays for snapshot.ts:2069 and audio/providers.ts:90. In capture it is dropped, but capture would pick the shell aggregator key first anyway (contentExtractor.ts:353). Test: dotEnv.test.ts 'leaves the person's own project keys alone at startup'.)
- Earlier blocker 2: audio scripts must keep an own-project API key next to a shell service-account variable that music cannot use: met (skills/media-use/audio/scripts/lib/heygen.mjs:189: for rank 1 the rival list is only the two API-key variables, so a shell service-account variable is not a rival; bgm.mjs:24 then still finds the key. Test: heygen.test.mjs 'keeps a person's own .env Gemini key next to a shell service account music cannot use'.)
- A project .env must not be able to supply the missing half of a two-part credential so that it wins over a complete credential of the person: met (dotEnv.ts:181-182 counts a rival only when every part is set outside a project .env; dotEnv.ts:187-199 drops the project-set half of the two-part credential whenever any other complete own credential exists. With no other complete own credential the project half is kept (see open_outside_pr).)
- Received-project rule stays as strict as on the default branch: met (dotEnv.ts:152-171 is unchanged except that the delete goes through yieldKey (116-120); heygen.mjs:189-194 keeps the full rival list and the first-party rivals for rank 2.)
- Every project .env key gives way wherever the person's credential can do the same job (the PR's opening sentence): partly met (Covered: capture vision (dotEnv.ts:185) and the two same-vendor API keys in speech and music (heygen.mjs:189). Not covered for a cloned project, same as the default branch: snapshot --describe (snapshot.ts:2069 takes the project key ahead of the shell's other API key) and speech next to a shell service account (gemini-auth.mjs:16 prefers the API key).)
- Notes name the file and variable only, never a key value: met (dotEnv.ts:196-198 and heygen.mjs:208-210, 221-223 interpolate variable names, an origin label and the .env path only.)
- Regression tests for the fix and for both setups named in the last review: met (dotEnv.test.ts new 'yieldProjectVisionKeys' block (6 cases), contentExtractor.test.ts parametrised received/cloned case that drives the real caption function, heygen.test.mjs three new cases. Read, not run by me.)
Open outside this PR
- By design and unchanged: with no complete rival credential of the person's own, a project .env key is still used, so a person with no keys who runs a shared project sends captured images or narration to the project author's account. Capture prints nothing in that case; the secondary voice path prints one note.
- Half-set two-part credential: if the shell holds only one half and no other complete vision credential, a project .env can supply the other half (dotEnv.ts:187-191 finds no rival). Shell service account plus project-chosen project id means requests signed by the person's service account are addressed to a project the .env names; it only succeeds if that service account has access there. Same on the default branch for non-received projects.
- An own project's working key is now dropped in capture and in the audio scripts whenever the shell holds any other variable from the accepted list, including a general-purpose API-key variable exported for an unrelated service of the same vendor; captions or music then fail with only the stderr note as a hint. This is the price of the rule; the owner should decide whether the docs need a line telling people to export the key in the shell.
- A project request file can name the secondary voice provider explicitly (audio.mjs:150-151), and an own/cloned project's key for it is kept (heygen.mjs:190), so a cloned project can route narration to its own voice account even when the person is signed in to the first-party one; one note is printed. Same on the default branch.
- Origin hand-off from the CLI to the audio scripts covers only the model-vendor and secondary-voice variables (heygen.mjs:106); a first-party key the CLI loaded from a project .env reaches the child looking like a shell key. Untouched by this PR.
- docs/packages/cli.mdx:407-408 and the description say 'shell or settings'; the code weighs environment variables only (dotEnv.ts:181-182). I found no saved-settings vision credential in the files I read; wording only.
- Pending CI jobs (listed in ci_status) had not finished when I checked.
CI: every check that ran passes at this commit.
How this was reviewed: a code-review pass and a security-review pass, by a reviewer agent in an isolated checkout of this commit; Nothing was built or run.
|
Thanks, Eddy. All three non-blockers are addressed in 8295a10, a signed merge of
|
eddy-heygen
left a comment
There was a problem hiding this comment.
(Eddy's agent) Reviewed by Eddy's Claude agent at commit 8295a10.
Verdict: approved as a partial fix (see what stays open below).
Re-review. The conflict with the default branch is gone. I compared this PR's own change in every file before and after the merge of the default branch, and read the capture rule at this commit.
- Six of the ten files are identical. The differences are small and all answer my last notes: the docs now say "shell" where they said "shell or settings"; the note names the credential capture will actually pick, with a test; the generated manifest hash is regenerated.
- The capture rule, as I read it: a vision key that a project
.envset is dropped only when another vision credential is set completely outside any project.env. A two-part credential counts only with both parts set outside. Start-up still applies the received-only rule.
Both blockers of my earlier review were resolved at the previous commit, and my change request was dismissed then.
What stays open: for a cloned project that is not marked as received, the frame-description step and speech next to a shell service account still take the project's key, as on the default branch. With no competing credential of the person's own, a project key is still used.
Blockers
None.
CI: every check that ran passes at this commit, including the Windows test jobs.
How this was reviewed: an earlier round was a code-review pass and a security-review pass by a reviewer agent; I compared the change before and after the merge and read the capture rule myself. Nothing was built or run.
What
A provider key from the person's own (cloned or unzipped) project
.envnow gives way to a credential set in their shell in two places: capture vision, and media-use speech and music. #8004 did this for received projects only, and that rule is unchanged..envvision key (OPENROUTER_API_KEY,GEMINI_API_KEY,GOOGLE_API_KEY, the Vertex project and service account) when the shell holds another complete vision credential. The note names the file and the credential capture will pick..envGEMINI_API_KEYgives way to a shellGOOGLE_API_KEY, and the reverse. Speech and music both accept either key.Why
#8004 named its limit: a cloned or zipped project's
.envstill counted as the person's own. So a shared project or template could set its ownOPENROUTER_API_KEY, outrank the Gemini key or Vertex credential in the person's shell, and receive the captured site images.How
packages/cli/src/utils/dotEnv.ts: newyieldProjectVisionKeys, called in capture after its.envlookup. A credential counts only when it is complete, so a lone shell Vertex project id is not a rival. The two Vertex parts are one credential and are never weighed against each other. A dropped key is remembered, so capture's second read of the same.envdoes not bring it back or print a second note.cli.tskeepsyieldReceivedProviderKeysat startup, sosnapshot --describeand the music readiness report keep the person's own project key.skills/media-use/audio/scripts/lib/heygen.mjs: keys are ranked (outside any project.env, own project.env, received). An own project's Gemini key gives way only to the other Gemini API key, never to a service account, which music cannot use. An own ElevenLabs key stays, so an explicitelevenlabsprovider choice works; the automatic choice already prefers HeyGen.noteProjectElevenLabsKeynotes an ElevenLabs key from any project.envbefore speech starts..envare unchanged. A project key with no usable rival is still used.docs/packages/cli.mdxanddocs/guides/authentication.mdx.Visible change: in capture, a project
.envOPENROUTER_API_KEYnext to a shellGEMINI_API_KEYnow captions with Gemini and prints a note.Test plan
dotEnv.test.tscovers the following. Startup leaves the person's own project Gemini key next to a shell OpenRouter key, so snapshot keeps it. Capture drops a project OpenRouter key next to a shell Gemini key. The project half of a Vertex credential stays when its other half is in the shell. A project key stays next to an incomplete shell Vertex credential. Both Vertex parts are dropped next to a shell Gemini key, and the model setting stays. A dropped key is not reloaded and not re-noted. The fix: the dev Studio's renders follow the received-project rule, and a received project's .env keys never replace the person's own #8004 received cases are unchanged.contentExtractor.test.ts: capture never calls OpenRouter for a received or a cloned project's key when the shell has a Gemini key.heygen.test.mjscovers the following. An own Gemini key stays next to a shell service account. A project Gemini key gives way to a shellGOOGLE_API_KEY. An own ElevenLabs key stays next to a HeyGen key. Two existing cases now use an empty config folder, so a saved sign-in on the test machine does not change them.vitest runondotEnv,contentExtractor,cli.dotEnv,captureAttemptandmedia-use(111 pass).node --teston the media-useheygen,tts,gemini-auth,bgmandheygen-ttstests (70 pass).mainis merged in with a signed merge commit, andskills-manifest.jsonis regenerated.Not covered (same as
main)For a cloned project,
snapshot --describestill reads the project'sGEMINI_API_KEYahead of a shellGOOGLE_API_KEY. Speech also still prefers a project API key over a shell service account; that trade keeps music working. Both are follow-ups.