Add opt-in Codex CLI provider for subscription-auth LLM calls#592
Add opt-in Codex CLI provider for subscription-auth LLM calls#592ivkiwi wants to merge 1 commit into
Conversation
Add opt-in Codex CLI provider for agentmemory compression/summarization without requiring third-party API keys. Keep API-key providers as default priority, with explicit AGENTMEMORY_PREFER_CODEX_SDK=true when user wants Codex first. Constraint: Use supported codex exec surface only; never read private Codex/ChatGPT token files. Rejected: Scrape local Codex auth storage | unsupported, brittle, security-risky. Rejected: Enable Codex fallback implicitly | can burn subscription quota and recurse through hooks. Confidence: high Scope-risk: moderate Directive: Keep AGENTMEMORY_SDK_CHILD guard on subscription-auth child processes; do not enable auto-compress by default. Tested: vitest run test/codex-sdk-provider.test.ts test/env-loader.test.ts; npm run build; live CodexSDKProvider smoke returned OK; agentmemory status healthy. Not-tested: Full suite clean in sandbox; unrelated EPERM/env failures remain in existing tests.
|
Someone is attempting to deploy a commit to the rohitg00's projects Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughThis PR implements an opt-in Codex CLI subscription-auth fallback for agentmemory, allowing users logged into Codex/ChatGPT to enable LLM compression without provisioning an API key. It adds a CodexSDKProvider that shells out to ChangesCodex SDK subscription-auth fallback
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add 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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
test/env-loader.test.ts (1)
23-42:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winHarden setup against ambient
OPENAI_API_KEY_FOR_LLMThe test setup clears
OPENAI_API_KEYbut notOPENAI_API_KEY_FOR_LLM. If the parent environment sets it tofalse, provider-selection assertions can become flaky.Suggested patch
delete process.env["OPENAI_API_KEY"]; + delete process.env["OPENAI_API_KEY_FOR_LLM"]; delete process.env["MINIMAX_API_KEY"];🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/env-loader.test.ts` around lines 23 - 42, In the beforeEach setup block (the anonymous function passed to beforeEach in env-loader.test.ts) you clear many environment variables but miss OPENAI_API_KEY_FOR_LLM; add deletion of process.env["OPENAI_API_KEY_FOR_LLM"] so the test environment is hardened against a parent process setting that variable (update the same beforeEach where sandboxHome is set and other delete process.env[...] calls occur).src/config.ts (1)
335-374:⚠️ Potential issue | 🟠 Major | ⚡ Quick winGate
codex-sdkfallback entries behind explicit opt-in
loadFallbackConfig()acceptscodex-sdkfromFALLBACK_PROVIDERSwithout requiringAGENTMEMORY_ALLOW_CODEX_SDK=true. That bypasses the explicit opt-in safety gate used bydetectProvider()and can unexpectedly invoke subscription-backed calls.Suggested patch
export function loadFallbackConfig(): FallbackConfig { const env = getMergedEnv(); const raw = env["FALLBACK_PROVIDERS"] || ""; const allowAgentSdk = env["AGENTMEMORY_ALLOW_AGENT_SDK"] === "true"; + const allowCodexSdk = env["AGENTMEMORY_ALLOW_CODEX_SDK"] === "true"; const providers = raw @@ .filter((p) => { + if (p === "codex-sdk" && !allowCodexSdk) { + process.stderr.write( + "[agentmemory] Ignoring FALLBACK_PROVIDERS entry 'codex-sdk' " + + "(AGENTMEMORY_ALLOW_CODEX_SDK is not 'true'). Opt in explicitly " + + "with AGENTMEMORY_ALLOW_CODEX_SDK=true if this is intentional.\n", + ); + return false; + } // Honor the same safety gate as detectProvider: agent-sdk is only // permitted as a fallback target when the user has explicitly opted🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/config.ts` around lines 335 - 374, loadFallbackConfig currently permits "codex-sdk" from FALLBACK_PROVIDERS without the explicit opt-in used elsewhere; add an explicit opt-in check like the existing agent-sdk gate: introduce a boolean (e.g. allowCodexSdk = env["AGENTMEMORY_ALLOW_CODEX_SDK"] === "true") and extend the providers filter block in loadFallbackConfig to reject "codex-sdk" when allowCodexSdk is false, emitting a clear stderr message mirroring the agent-sdk message (mentioning AGENTMEMORY_ALLOW_CODEX_SDK and why it's gated) and return false for that entry; reference VALID_PROVIDERS and the providers filter inside loadFallbackConfig when making this change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/config.ts`:
- Around line 335-374: loadFallbackConfig currently permits "codex-sdk" from
FALLBACK_PROVIDERS without the explicit opt-in used elsewhere; add an explicit
opt-in check like the existing agent-sdk gate: introduce a boolean (e.g.
allowCodexSdk = env["AGENTMEMORY_ALLOW_CODEX_SDK"] === "true") and extend the
providers filter block in loadFallbackConfig to reject "codex-sdk" when
allowCodexSdk is false, emitting a clear stderr message mirroring the agent-sdk
message (mentioning AGENTMEMORY_ALLOW_CODEX_SDK and why it's gated) and return
false for that entry; reference VALID_PROVIDERS and the providers filter inside
loadFallbackConfig when making this change.
In `@test/env-loader.test.ts`:
- Around line 23-42: In the beforeEach setup block (the anonymous function
passed to beforeEach in env-loader.test.ts) you clear many environment variables
but miss OPENAI_API_KEY_FOR_LLM; add deletion of
process.env["OPENAI_API_KEY_FOR_LLM"] so the test environment is hardened
against a parent process setting that variable (update the same beforeEach where
sandboxHome is set and other delete process.env[...] calls occur).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 25ef541d-a042-41e5-abe5-d80937d6c202
📒 Files selected for processing (8)
.env.exampleREADME.mdsrc/config.tssrc/providers/codex-sdk.tssrc/providers/index.tssrc/types.tstest/codex-sdk-provider.test.tstest/env-loader.test.ts
Summary
codex-sdkprovider that shells out tocodex execfor compression/summarizationAGENTMEMORY_ALLOW_CODEX_SDK=true, while keeping API-key providers first by defaultAGENTMEMORY_PREFER_CODEX_SDK=truefor users who explicitly want Codex before API-key providersSafety
AGENTMEMORY_SDK_CHILD=1/AGENTMEMORY_CODEX_SDK_CHILD=1to avoid recursive hook capturecodex execwith--ephemeral,--ignore-rules,--sandbox read-only, and--skip-git-repo-checkValidation
./node_modules/.bin/vitest run test/codex-sdk-provider.test.ts test/env-loader.test.tsnpm run buildCodexSDKProvidersmoke test returnedOKagentmemory statushealthy after local linked installNotes
I also ran
npm test, but the full local suite was not clean in my sandbox due existing environment/permission-sensitive failures: embedding provider env selection, fs watcher timeouts, multimodal image writes under~/.agentmemory, and viewer listen permissions/timeouts.Closes #527
Summary by CodeRabbit
New Features
AGENTMEMORY_ALLOW_CODEX_SDK=true, with optional preference override usingAGENTMEMORY_PREFER_CODEX_SDK=true.Documentation
Tests