feat: seed claude-smart local-mode env defaults on install#60
Conversation
Write CLAUDE_SMART_USE_LOCAL_CLI=1, CLAUDE_SMART_USE_LOCAL_EMBEDDING=1, and CLAUDE_SMART_READ_ONLY=0 into ~/.reflexio/.env when no managed REFLEXIO_API_KEY is present. Existing user values win, so an explicit CLAUDE_SMART_READ_ONLY=1 is preserved. Pruning REFLEXIO_URL, REFLEXIO_API_KEY, and REFLEXIO_USER_ID from both file and process env keeps managed/local state in sync. Also adds sqlite-vec as a runtime dep so the native KNN accelerator is available by default.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (8)
📝 WalkthroughWalkthroughThis PR adds local-mode Reflexio environment configuration support, enabling Claude Smart to operate without managed API credentials. It introduces environment variable constants, a Python function to seed and manage ChangesLocal-mode Reflexio environment setup
Sequence DiagramsequenceDiagram
participant Installer as Installer (bin/setup-claude-smart.sh)
participant ConfigPy as ConfigPy (env_config.py)
participant EnvFile as ~/.reflexio/.env
participant CLI as CLI (_configure_reflexio_setup)
Installer->>EnvFile: Check if file exists
Installer->>ConfigPy: Call ensure_local_env_defaults()
ConfigPy->>EnvFile: Read existing entries
ConfigPy->>ConfigPy: Prune managed keys (REFLEXIO_API_KEY, URL, USER_ID)
ConfigPy->>ConfigPy: Preserve non-pruned user entries
ConfigPy->>EnvFile: Append missing CLAUDE_SMART_USE_LOCAL_CLI=1
ConfigPy->>EnvFile: Append missing CLAUDE_SMART_USE_LOCAL_EMBEDDING=1
ConfigPy->>EnvFile: Append/upsert CLAUDE_SMART_READ_ONLY="0"
ConfigPy->>EnvFile: Write with mode 0600
CLI->>ConfigPy: ensure_local_env_defaults() on no API key
ConfigPy-->>CLI: Return list of added keys
CLI->>Installer: Print "Seeded: [keys]"
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Summary
REFLEXIO_API_KEYis present, seed~/.reflexio/.envwithCLAUDE_SMART_USE_LOCAL_CLI=1,CLAUDE_SMART_USE_LOCAL_EMBEDDING=1, andCLAUDE_SMART_READ_ONLY=0so first-install (or a wiped env file) produces a working setup without hand-editing.CLAUDE_SMART_READ_ONLY=1set deliberately by a user survives.REFLEXIO_URL,REFLEXIO_API_KEY, andREFLEXIO_USER_IDfrom both the env file and the current process env in the no-API-key branch (previouslyREFLEXIO_USER_IDleaked through in the Python and JS paths).sqlite-vecas a runtime dep so the native SQLite vector KNN accelerator is available by default; reflexio still falls back to Python ranking if missing.Changes
Local-mode env seeding (four parallel implementations, kept in sync):
plugin/src/claude_smart/env_config.py— newensure_local_env_defaults()with prune-then-seed logic.plugin/src/claude_smart/cli.py—_configure_reflexio_setup()now callsensure_local_env_defaultsand popsREFLEXIO_USER_ID/REFLEXIO_URL/REFLEXIO_API_KEY/CLAUDE_SMART_MANAGED_SETUPfromos.environin the no-API-key branch.bin/claude-smart.js— JS equivalent (ensureLocalReflexioEnv) for the npm wrapper, plusdelete process.env.REFLEXIO_USER_IDin the no-API-key branch.plugin/scripts/smart-install.sh—claude_smart_ensure_local_env_defaults+claude_smart_prune_managed_env_keys_for_local, invoked on every install when noREFLEXIO_API_KEYis exported.scripts/setup-claude-smart.sh— interactiveensure_local_env_defaults; local-mode branch now callsremove_env_keys REFLEXIO_API_KEY REFLEXIO_URL REFLEXIO_USER_IDexplicitly so a user'sCLAUDE_SMART_READ_ONLY=1is preserved.install_completegate:smart-install.shnow treats a missing local-default in~/.reflexio/.envas "install incomplete," so a hook invocation will re-seed defaults if the file was tampered with.Dependency:
sqlite-vec>=0.1.6added toplugin/pyproject.tomlandplugin/uv.lock.Tests updated:
test_install_setup_default_creates_local_env(was_does_not_create_local_env) — asserts the three defaults are written with0o600perms.test_install_setup_ignores_stale_url_without_api_key— assertsREFLEXIO_URLis gone from both env and file, and the defaults are written.test_smart_install_repairs_local_env_defaults(was_does_not_create_local_env_defaults) — covers the shell-side install gate.test_setup_script_local_mode_creates_env,test_setup_script_local_mode_cleans_managed_keys,test_setup_script_local_mode_replaces_managed_only_env— cover the interactive setup script. Thecleans_managed_keyscase specifically asserts that a pre-existingCLAUDE_SMART_READ_ONLY=1is preserved (not overwritten with"0").test_node_installer_ignores_stale_url_without_api_key— asserts the JS wrapper emits the expected "Seeded ..." message and writes the defaults.Test Plan
uv run --project plugin pytest tests/test_cli_install.py tests/test_install_scripts.py— 90 passed.uv run --project plugin pyright src/claude_smart/env_config.py src/claude_smart/cli.py— 0 errors.uv run --project plugin ruff check plugin/src/claude_smart/env_config.py— clean.bash -non modified shell scripts andnode --checkonbin/claude-smart.js— clean.~/.reflexio/.env— confirm file is created with the three defaults and0o600perms.CLAUDE_SMART_READ_ONLY=1in~/.reflexio/.env— runsetup-claude-smart.sh localand confirm value is preserved.REFLEXIO_API_KEYin~/.reflexio/.env— runsmart-install.shwith no env-var override and confirm the file is untouched (no defaults seeded).Summary by CodeRabbit
New Features
Dependencies