fix: warn on agent-sdk + AUTO_COMPRESS, accept GOOGLE_API_KEY as Gemini alias (#149)#154
fix: warn on agent-sdk + AUTO_COMPRESS, accept GOOGLE_API_KEY as Gemini alias (#149)#154
Conversation
…writes (#151) lstat() check before any I/O now rejects symlinks, closing the bypass where notes.md -> vault.txt passed the .md extension check but the subsequent readFile/writeFile followed the symlink to the real target. Adds a regression test that marks a path as a symlink in the mock and verifies the function returns {success:false, error: "symlinks are not supported"}.
…ni alias (#149) Two changes: 1. detectProvider() now accepts GOOGLE_API_KEY as an alias for GEMINI_API_KEY. Emits a stderr advisory to rename the variable. 2. When no provider key is found and AGENTMEMORY_AUTO_COMPRESS=true, emits a clear warning that agent-sdk will share Claude Code's API quota — the root cause of #149 where a wrong env var name caused silent fallback to agent-sdk during a heavy Opus session.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughUpdated provider selection to treat Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/functions/compress-file.ts`:
- Around line 113-120: The current lstat(absolutePath) symlink check (and
variable absolutePath) is vulnerable to TOCTOU because the file can be swapped
before the later write; instead of relying on lstat alone, open the target with
flags that prevent following symlinks and write via the obtained file
descriptor. Replace the post-check write that currently uses writeFile /
fs.write with an fs.open call using constants.O_NOFOLLOW (and appropriate
O_CREAT/O_TRUNC/O_WRONLY flags), perform the write to the returned fd, fstat if
needed on the fd, then close the fd; keep handling of ENOENT/ELOOP/EINVAL errors
and remove reliance on lstat as the sole protection so the write cannot be
redirected via a swapped symlink.
In `@src/providers/index.ts`:
- Around line 75-77: The current geminiKey assignment uses nullish coalescing
which treats an empty string as a valid value and prevents falling back to
GOOGLE_API_KEY; update the geminiKey initialization in providers (the getEnvVar
calls) to use logical OR (||) so an empty string from
getEnvVar("GEMINI_API_KEY") will fall back to getEnvVar("GOOGLE_API_KEY"), and
keep the subsequent validation that checks for a falsy geminiKey.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 433855f9-b799-42fa-a583-80c73a75953b
📒 Files selected for processing (4)
src/config.tssrc/functions/compress-file.tssrc/providers/index.tstest/compress-file.test.ts
Problem
When
GOOGLE_API_KEYwas set instead ofGEMINI_API_KEY,detectProvider()silently fell through toagent-sdk. WithAGENTMEMORY_AUTO_COMPRESS=true, this routed every compression call through Claude Code's own API quota, burning a Pro subscription dry during heavy sessions (#149).Fix
1.
GOOGLE_API_KEYalias for Gemini (src/config.ts)Many Google SDKs use
GOOGLE_API_KEY. Now accepted as a fallback forGEMINI_API_KEY, with an advisory logged to stderr:2. Startup warning when agent-sdk + AUTO_COMPRESS (
src/config.ts)If no provider key is found and
AGENTMEMORY_AUTO_COMPRESS=true, emits a clear warning before starting:3. Runtime key resolution (
src/providers/index.ts)createBaseProviderforgemininow resolvesGOOGLE_API_KEYas fallback so the alias works end-to-end, not just at detection time.Closes #149.
Summary by CodeRabbit
Bug Fixes
Improvements
Tests