Skip to content

fix(cliproxyapi): read API key from .env and skip dotfiles sync on Linux - #462

Merged
shunkakinoki merged 2 commits into
mainfrom
fix/cliproxyapi-api-keys-from-env
Dec 28, 2025
Merged

fix(cliproxyapi): read API key from .env and skip dotfiles sync on Linux#462
shunkakinoki merged 2 commits into
mainfrom
fix/cliproxyapi-api-keys-from-env

Conversation

@shunkakinoki

@shunkakinoki shunkakinoki commented Dec 28, 2025

Copy link
Copy Markdown
Owner

Summary

  • Read CLIPROXY_API_KEY from .env file for API authentication on Linux
  • Skip redundant auth file sync to ~/dotfiles/objectstore/auths/ on Linux (macOS behavior preserved)

Changes

API Key from .env

  • Source .env file to get CLIPROXY_API_KEY
  • Enable API key authentication only when the key is set

Skip dotfiles sync on Linux

  • start.sh: Bootstrap from dotfiles is now Darwin-only
  • backup-auth.sh: Sync to dotfiles is now Darwin-only
  • default.nix: Removed dotfiles path from Linux systemd path watcher

On Linux, auth files now only sync between:

  • R2 cloud storage
  • ~/.cli-proxy-api/objectstore/auths/
  • ~/.ccs/cliproxy/auth/

Test plan

  • make format passes
  • make shell-test passes (242 examples, 0 failures)
  • Verified dotfiles/objectstore/auths stays empty after backup service runs on Linux

🤖 Generated with Claude Code

@cursor

cursor Bot commented Dec 28, 2025

Copy link
Copy Markdown

You have run out of free Bugbot PR reviews for this billing cycle. This will reset on January 27.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

@mesa-dot-dev

mesa-dot-dev Bot commented Dec 28, 2025

Copy link
Copy Markdown

You do not have enough credits to review this pull request. Please purchase more credits to continue.

@coderabbitai

coderabbitai Bot commented Dec 28, 2025

Copy link
Copy Markdown

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Example env file now includes CLIPROXY_API_KEY and clearer local-use wording.
  • Bug Fixes / Behavior

    • Prevents empty/default API keys from being injected on Linux.
    • Dotfiles bootstrap and auth back-sync are now macOS-only; Linux skips those steps.
    • Reduced monitored paths that trigger backups.
  • Tests

    • Added test to verify API keys remain commented when the env var is empty.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

Platform-specific bootstrap and auth sync behavior were restricted to macOS; Linux no longer bootstraps/syncs dotfiles when objectstore is empty. The Linux startup now only injects CLIPROXY_API_KEY when it is non-empty. Example env and tests were updated accordingly; a path watch in default.nix was reduced.

Changes

Cohort / File(s) Summary
Environment configuration
\.env.example
Wording adjusted to copy to .env; added CLIPROXY_API_KEY=your-api-key-here; GITHUB_TOKEN remains as a commented example.
Startup script
home-manager/services/cliproxyapi/scripts/start.sh
Dotfiles bootstrap when objectstore is empty is now guarded to Darwin only; Linux API-key uncomment/substitution runs only when CLIPROXY_API_KEY is non-empty and uses the raw value. Comments clarified.
Backup sync script
home-manager/services/cliproxyapi/scripts/backup-auth.sh
Dotfiles back-sync is now performed only on Darwin (wrapped in a Darwin guard); Linux skips the dotfiles sync.
Service configuration
home-manager/services/cliproxyapi/default.nix
Removed objectstore/auths from systemd.user.paths.cliproxyapi-backup.PathChanged so that path no longer triggers the backup service.
Test spec
spec/cliproxyapi_spec.sh
Linux condition updated to require non-empty CLIPROXY_API_KEY; new test verifies api-keys remain commented when the key is empty.

Sequence Diagram(s)

(Skipped — changes are localized platform guards and conditional injections without a new multi-component sequential flow that requires visualization.)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I hopped through scripts at break of dawn,
Guarding keys until they're truly drawn.
Darwin keeps the dotfiles tight,
Linux waits for keylight.
Tests listen close — all errors gone. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main changes: reading CLIPROXY_API_KEY from .env and skipping dotfiles sync on Linux.
Description check ✅ Passed The description is directly related to the changeset, providing clear context about API key sourcing and platform-specific behavior changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/cliproxyapi-api-keys-from-env

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 41e77f1 and f2d3d62.

📒 Files selected for processing (3)
  • home-manager/services/cliproxyapi/default.nix
  • home-manager/services/cliproxyapi/scripts/backup-auth.sh
  • home-manager/services/cliproxyapi/scripts/start.sh
💤 Files with no reviewable changes (1)
  • home-manager/services/cliproxyapi/default.nix
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{sh,bash}

📄 CodeRabbit inference engine (CLAUDE.md)

Use shfmt with 2-space indentation for shell scripts

**/*.{sh,bash}: Use 2 spaces for indentation in shell scripts
Add proper shebang lines to shell scripts
Follow shellcheck recommendations in shell scripts
Document complex commands in shell scripts
Use consistent variable naming in shell scripts

Files:

  • home-manager/services/cliproxyapi/scripts/backup-auth.sh
  • home-manager/services/cliproxyapi/scripts/start.sh
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
  • GitHub Check: docker-build-push (linux/arm64, arm64, ubuntu-24.04-arm)
  • GitHub Check: docker-build-push (linux/amd64, amd64, ubuntu-latest)
  • GitHub Check: nix-darwin
  • GitHub Check: nix-linux
  • GitHub Check: nix-nixos
  • GitHub Check: e2e-run (NixOS, ubuntu-latest)
  • GitHub Check: e2e-run (Ubuntu, ubuntu-latest)
  • GitHub Check: e2e-run (MacOS, macos-latest)
  • GitHub Check: shell-lint
  • GitHub Check: shell-test
  • GitHub Check: lua-neovim
  • GitHub Check: lua-hammerspoon
  • GitHub Check: lua-neovim-test
🔇 Additional comments (2)
home-manager/services/cliproxyapi/scripts/start.sh (1)

52-61: LGTM: Darwin-only bootstrap logic is correct.

The conditional check properly restricts the bootstrap behavior to macOS, preventing Linux from creating redundant auth file copies. The directory checks and rsync command are appropriately implemented.

home-manager/services/cliproxyapi/scripts/backup-auth.sh (1)

79-85: LGTM! Clean platform-specific implementation.

The macOS-only guard for dotfiles sync is well-implemented:

  • Platform detection using uname is correct and idiomatic
  • Comments clearly explain the rationale for skipping on Linux
  • Indentation follows the 2-space guideline
  • Aligns with PR objectives to prevent duplicate auth file copies on Linux

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.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @shunkakinoki, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the API key handling for the cliproxyapi service, specifically on Linux systems. It introduces a conditional check to ensure that API key authentication is only enabled when a valid CLIPROXY_API_KEY is provided, preventing the generation of empty or misconfigured API key entries. Additionally, it updates the example environment file for better developer guidance and includes relevant test case additions.

Highlights

  • API Key Configuration Logic: Modified the start.sh script to conditionally enable API key authentication on Linux. API keys will now only be uncommented and configured if the CLIPROXY_API_KEY environment variable is explicitly set and not empty.
  • Preventing Empty API Key Configuration: The change prevents the api-keys configuration from being set to an empty string when the CLIPROXY_API_KEY environment variable is missing or empty, avoiding potential misconfigurations.
  • Documentation Update: Added CLIPROXY_API_KEY to the .env.example file to provide clear documentation for developers on how to configure the API key.
  • Test Coverage: Enhanced the cliproxyapi_spec.sh tests to include a new scenario verifying that API keys remain commented out on Linux when CLIPROXY_API_KEY is empty, ensuring the new conditional logic works as expected.
  • Dependency Updates: Updated various project dependencies in flake.lock, including devenv, home-manager, neovim-nightly-overlay, neovim-src, nixpkgs, and NUR.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

- Only enable api-keys auth on Linux when CLIPROXY_API_KEY is set
- Prevents empty string "" in api-keys when env var is missing
- Add CLIPROXY_API_KEY to .env.example
- Add test for empty key behavior

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@mesa-dot-dev

mesa-dot-dev Bot commented Dec 28, 2025

Copy link
Copy Markdown

Mesa Description

TL;DR

Fixes cliproxyapi to only enable API key authentication on Linux when CLIPROXY_API_KEY is explicitly set and not empty, preventing misconfigurations and documenting the variable in .env.example.

What changed?

  • .env.example: Updated instructions for copying and added CLIPROXY_API_KEY for documentation.
  • flake.lock: Refreshed Nix flake dependencies.
  • home-manager/services/cliproxyapi/scripts/start.sh: Modified to conditionally enable client authentication for cliproxyapi on Linux, only if CLIPROXY_API_KEY is set and non-empty.
  • spec/cliproxyapi_spec.sh: Refined test logic for API key configuration on Linux, ensuring it's only uncommented when CLIPROXY_API_KEY is non-empty, and added a test case for the empty key scenario.

Description generated by Mesa. Update settings

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly ensures that API key authentication for cliproxyapi on Linux is only enabled when CLIPROXY_API_KEY is set, preventing issues with empty keys. The changes to .env.example and the new test case for an empty key are good additions.

My review includes one high-severity finding in start.sh where an API key with special characters could break the sed command. I've provided a code suggestion to properly escape the key before its use. I've also added a medium-severity comment to the test file, recommending a new test case to cover this special character scenario to make the test suite more robust.

Comment on lines 75 to 78
@sed@ -i \
-e "s|^# api-keys:|api-keys:|" \
-e "s|^# - \"__CLIPROXY_API_KEY__\"| - \"${CLIPROXY_API_KEY:-}\"|" \
-e "s|^# - \"__CLIPROXY_API_KEY__\"| - \"${CLIPROXY_API_KEY}\"|" \
"$CONFIG"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The CLIPROXY_API_KEY variable is used directly in a sed replacement string. If the API key contains special characters for sed (like &, \, or the | delimiter), it can break the substitution command or lead to unexpected results. It's safer to escape the variable before using it.

For example, if CLIPROXY_API_KEY was foo&bar, the & in the replacement part would be substituted with the entire matched pattern (# - "__CLIPROXY_API_KEY__"), which is not the desired behavior.

Suggested change
@sed@ -i \
-e "s|^# api-keys:|api-keys:|" \
-e "s|^# - \"__CLIPROXY_API_KEY__\"| - \"${CLIPROXY_API_KEY:-}\"|" \
-e "s|^# - \"__CLIPROXY_API_KEY__\"| - \"${CLIPROXY_API_KEY}\"|" \
"$CONFIG"
ESCAPED_API_KEY=$(printf '%s\n' "${CLIPROXY_API_KEY}" | @sed@ -e 's/[&\\|]/\\&/g')
@sed@ -i \
-e "s|^# api-keys:|api-keys:|" \
-e "s|^# - \"__CLIPROXY_API_KEY__\"| - \"$ESCAPED_API_KEY\"|" "$CONFIG"

Comment thread spec/cliproxyapi_spec.sh
Comment on lines +164 to +193
It 'keeps api-keys commented on Linux when CLIPROXY_API_KEY is empty'
# Create test script that simulates Linux behavior with empty key
cat >"$TEMP_HOME/test_linux_empty_apikey.sh" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
CONFIG_DIR="$HOME/.cli-proxy-api"
TEMPLATE="$CONFIG_DIR/config.template.yaml"
CONFIG="$CONFIG_DIR/config.yaml"
CLIPROXY_API_KEY=""

# Copy template to config
cp "$TEMPLATE" "$CONFIG"

# Simulate Linux behavior with empty key (should NOT uncomment)
if [ -n "${CLIPROXY_API_KEY:-}" ]; then
sed \
-e "s|^# api-keys:|api-keys:|" \
-e "s|^# - \"__CLIPROXY_API_KEY__\"| - \"${CLIPROXY_API_KEY}\"|" \
"$CONFIG" > "$CONFIG.tmp" && mv "$CONFIG.tmp" "$CONFIG"
fi

cat "$CONFIG"
EOF
chmod +x "$TEMP_HOME/test_linux_empty_apikey.sh"

When run bash -c "HOME='$TEMP_HOME' bash '$TEMP_HOME/test_linux_empty_apikey.sh'"
The output should include '# api-keys:'
The output should include '# - "__CLIPROXY_API_KEY__"'
The status should be success
End

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This is a great test for the empty API key case! To make the tests more robust, consider adding another test case for when CLIPROXY_API_KEY contains special characters that have meaning in sed replacement strings (e.g., &, \, |). This would help ensure the script is resilient against a wider range of possible key values, especially with the proposed fix in start.sh.

@shunkakinoki
shunkakinoki enabled auto-merge (squash) December 28, 2025 04:57
@shunkakinoki shunkakinoki changed the title fix(cliproxyapi): read CLIPROXY_API_KEY from .env file fix(cliproxyapi): read API key from .env and skip dotfiles sync on Linux Dec 28, 2025
On Linux, auth files are now only synced between R2, ~/.cli-proxy-api/objectstore/auths/, and ~/.ccs/cliproxy/auth/. The redundant copy to ~/dotfiles/objectstore/auths/ is skipped to avoid duplicate files.

macOS behavior is preserved - auth files still sync to dotfiles for git tracking.

Changes:
- start.sh: Bootstrap from dotfiles is now Darwin-only
- backup-auth.sh: Sync to dotfiles is now Darwin-only
- default.nix: Removed dotfiles path from Linux systemd path watcher

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@shunkakinoki
shunkakinoki merged commit 2c799a3 into main Dec 28, 2025
32 checks passed
@shunkakinoki
shunkakinoki deleted the fix/cliproxyapi-api-keys-from-env branch December 28, 2025 06:05
@coderabbitai coderabbitai Bot mentioned this pull request Mar 13, 2026
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