Skip to content

feat: seed claude-smart local-mode env defaults on install#60

Merged
yyiilluu merged 1 commit into
mainfrom
fix/local-env-defaults-seed-and-preserve
May 26, 2026
Merged

feat: seed claude-smart local-mode env defaults on install#60
yyiilluu merged 1 commit into
mainfrom
fix/local-env-defaults-seed-and-preserve

Conversation

@yyiilluu
Copy link
Copy Markdown
Contributor

@yyiilluu yyiilluu commented May 26, 2026

Summary

  • Make claude-smart "local mode" self-configuring: when no managed REFLEXIO_API_KEY is present, seed ~/.reflexio/.env with CLAUDE_SMART_USE_LOCAL_CLI=1, CLAUDE_SMART_USE_LOCAL_EMBEDDING=1, and CLAUDE_SMART_READ_ONLY=0 so first-install (or a wiped env file) produces a working setup without hand-editing.
  • Preserve user overrides — existing active assignments win, so CLAUDE_SMART_READ_ONLY=1 set deliberately by a user survives.
  • Keep managed/local state consistent across surfaces: prune REFLEXIO_URL, REFLEXIO_API_KEY, and REFLEXIO_USER_ID from both the env file and the current process env in the no-API-key branch (previously REFLEXIO_USER_ID leaked through in the Python and JS paths).
  • Ship sqlite-vec as 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 — new ensure_local_env_defaults() with prune-then-seed logic.
  • plugin/src/claude_smart/cli.py_configure_reflexio_setup() now calls ensure_local_env_defaults and pops REFLEXIO_USER_ID / REFLEXIO_URL / REFLEXIO_API_KEY / CLAUDE_SMART_MANAGED_SETUP from os.environ in the no-API-key branch.
  • bin/claude-smart.js — JS equivalent (ensureLocalReflexioEnv) for the npm wrapper, plus delete process.env.REFLEXIO_USER_ID in the no-API-key branch.
  • plugin/scripts/smart-install.shclaude_smart_ensure_local_env_defaults + claude_smart_prune_managed_env_keys_for_local, invoked on every install when no REFLEXIO_API_KEY is exported.
  • scripts/setup-claude-smart.sh — interactive ensure_local_env_defaults; local-mode branch now calls remove_env_keys REFLEXIO_API_KEY REFLEXIO_URL REFLEXIO_USER_ID explicitly so a user's CLAUDE_SMART_READ_ONLY=1 is preserved.

install_complete gate: smart-install.sh now treats a missing local-default in ~/.reflexio/.env as "install incomplete," so a hook invocation will re-seed defaults if the file was tampered with.

Dependency: sqlite-vec>=0.1.6 added to plugin/pyproject.toml and plugin/uv.lock.

Tests updated:

  • test_install_setup_default_creates_local_env (was _does_not_create_local_env) — asserts the three defaults are written with 0o600 perms.
  • test_install_setup_ignores_stale_url_without_api_key — asserts REFLEXIO_URL is 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. The cleans_managed_keys case specifically asserts that a pre-existing CLAUDE_SMART_READ_ONLY=1 is 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 -n on modified shell scripts and node --check on bin/claude-smart.js — clean.
  • Manual: fresh install in a sandbox with no ~/.reflexio/.env — confirm file is created with the three defaults and 0o600 perms.
  • Manual: pre-existing CLAUDE_SMART_READ_ONLY=1 in ~/.reflexio/.env — run setup-claude-smart.sh local and confirm value is preserved.
  • Manual: pre-existing managed REFLEXIO_API_KEY in ~/.reflexio/.env — run smart-install.sh with no env-var override and confirm the file is untouched (no defaults seeded).

Summary by CodeRabbit

  • New Features

    • Local installation now works without requiring API credentials
    • Automatic local configuration setup with CLI and embedding support
    • Added native vector storage for improved local search and retrieval
  • Dependencies

    • Added SQLite vector support for local data storage

Review Change Stack

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.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 26, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e6a12e83-9e0e-4a13-8cb1-fc1b6b091a3a

📥 Commits

Reviewing files that changed from the base of the PR and between 5c311d2 and daac221.

⛔ Files ignored due to path filters (1)
  • plugin/uv.lock is excluded by !**/*.lock
📒 Files selected for processing (8)
  • bin/claude-smart.js
  • plugin/pyproject.toml
  • plugin/scripts/smart-install.sh
  • plugin/src/claude_smart/cli.py
  • plugin/src/claude_smart/env_config.py
  • scripts/setup-claude-smart.sh
  • tests/test_cli_install.py
  • tests/test_install_scripts.py

📝 Walkthrough

Walkthrough

This 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 ~/.reflexio/.env, corresponding shell helpers, CLI integration, and comprehensive tests covering the new behavior alongside a sqlite-vec dependency for local embedding.

Changes

Local-mode Reflexio environment setup

Layer / File(s) Summary
Local-mode environment configuration constants and data
bin/claude-smart.js, plugin/src/claude_smart/env_config.py, plugin/pyproject.toml
Environment variable names CLAUDE_SMART_USE_LOCAL_CLI_ENV and CLAUDE_SMART_USE_LOCAL_EMBEDDING_ENV are introduced; default entries for local mode and a prune set for managed keys (REFLEXIO_URL, REFLEXIO_API_KEY, REFLEXIO_USER_ID) are defined; sqlite-vec>=0.1.6 is added as a dependency.
Core environment file management
plugin/src/claude_smart/env_config.py, bin/claude-smart.js
Python ensure_local_env_defaults() reads existing ~/.reflexio/.env, removes prune-key assignments, appends missing local defaults with quoted formatting, persists the file with 0600 permissions, and returns added keys; JavaScript ensureLocalReflexioEnv() helper escapes values and seeds entries into the env file.
Shell script helpers for env management and validation
plugin/scripts/smart-install.sh, scripts/setup-claude-smart.sh
New functions claude_smart_env_append_raw_if_missing() and claude_smart_prune_managed_env_keys_for_local() in smart-install.sh provide raw env appending and selective key removal; install_complete() now requires local CLI/embedding/read-only flags when no API key is set; setup-claude-smart.sh gains append_env_raw() and ensure_local_env_defaults() helpers.
CLI and Node.js installer integration
bin/claude-smart.js, plugin/src/claude_smart/cli.py
When no Reflexio API key is present, loadReflexioSetupEnv() now clears managed-setup markers (REFLEXIO_USER_ID, CLAUDE_SMART_MANAGED_SETUP) and seeds local defaults, reporting newly added keys; Python _configure_reflexio_setup() calls env_config.ensure_local_env_defaults() and prints seeded variables; _run_service() error message formatting is refined.
Test coverage for local-mode behavior
tests/test_cli_install.py, tests/test_install_scripts.py
Tests now verify that local .reflexio/.env is created with CLAUDE_SMART_USE_LOCAL_CLI=1, CLAUDE_SMART_USE_LOCAL_EMBEDDING=1, CLAUDE_SMART_READ_ONLY="0", file mode 0600, and that managed keys are pruned; added tests for env repair on repeated runs and managed-only-to-local env replacement.

Sequence Diagram

sequenceDiagram
  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]"
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • ReflexioAI/claude-smart#32: Hardens install_complete() validation of local-mode Reflexio .env flags in smart-install.sh when REFLEXIO_API_KEY is not set; directly intersects with this PR's validation logic.
  • ReflexioAI/claude-smart#46: Modifies Reflexio env-file initialization for the "no API key/seed local defaults" path in bin/claude-smart.js and ~/.reflexio/.env key handling, closely related to this PR's local-vs-managed setup flow.

Poem

🐰 Local mode blooms without credentials fine,
Environment defaults in dotfiles align,
Pruning managed keys with surgical care,
Shell scripts and Python dance through the air—
Local embedding sings, vector tables gleam bright! ✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/local-env-defaults-seed-and-preserve

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@yyiilluu yyiilluu merged commit 69caffc into main May 26, 2026
6 of 7 checks passed
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.

1 participant