Skip to content

feat: enhance cliproxyapi with AMP API keys, GLM-4.7 support, and S3 config backup - #447

Merged
shunkakinoki merged 9 commits into
mainfrom
cliproxyapi-proper-backup
Dec 25, 2025
Merged

feat: enhance cliproxyapi with AMP API keys, GLM-4.7 support, and S3 config backup#447
shunkakinoki merged 9 commits into
mainfrom
cliproxyapi-proper-backup

Conversation

@shunkakinoki

@shunkakinoki shunkakinoki commented Dec 25, 2025

Copy link
Copy Markdown
Owner

Summary

  • Enhance cliproxyapi service reliability with S3 config backup and proper launchd path handling to prevent configuration corruption across service restarts
  • Add AMP API key authentication support and GLM-4.7 model support for improved AI capabilities

Summary by cubic

Adds AMP API key auth, enables GLM-4.7 models, and hardens cliproxyapi with S3-backed config and launchd-safe startup. Improves reliability across restarts and expands model options.

  • New Features

    • S3 backup of the generated config on startup to prevent corrupted state.
    • AMP integration: client API keys and upstream API key support; remote management enabled by default.
    • GLM-4.7 support for OpenRouter (z-ai) and Z-AI providers; added GLM-4.7 Coding Plan in opencode config.
  • Bug Fixes

    • Reliable launchd startup by resolving HOME for .env and using Nix-injected paths for aws/sed.

Written for commit 6fc5a70. Summary will update automatically on new commits.

Copilot AI review requested due to automatic review settings December 25, 2025 08:54
@mesa-dot-dev

mesa-dot-dev Bot commented Dec 25, 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 25, 2025

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

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

Release Notes

  • New Features

    • Added support for new GLM-4.7 AI models via Z-AI provider.
    • Introduced S3 backup functionality for configuration storage.
    • Enhanced AMP integration with upstream API key support.
  • Configuration Updates

    • Simplified API key configuration (optional authentication for open access).
    • Improved environment variable handling for better stability.

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

Walkthrough

Replaces sample API key lines with a single placeholder, adds AMP upstream-api-key and disables localhost-only management, adds GLM-4.7 model entries across providers, generates a build-time substituted startScript (PATH and aws/coreutils adjustments), extends env injection (AMP_UPSTREAM_API_KEY), and adds conditional S3 backup of generated config in the startup script.

Changes

Cohort / File(s) Summary
AMP config & model entries
config/cliproxyapi/config.yaml, config/opencode/opencode.jsonc
Replaced multiple sample API key lines with a single placeholder; added upstream-api-key: "__AMP_UPSTREAM_API_KEY__" and set restrict-management-to-localhost: false; added GLM-4.7 variants: "z-ai/glm-4.7" (openrouter), "glm-4.7" (z-ai), and zai-coding-plan/glm-4.7 (opencode).
Service wiring & startup script
home-manager/services/cliproxyapi/default.nix, home-manager/services/cliproxyapi/scripts/start.sh
Build-time generation of startScript by substituting aws/sed paths; ProgramArguments/ExecStart updated to use the generated script; PATH expanded to include awscli2/coreutils; start.sh uses a fallback-friendly ENV_FILE path, injects AMP_UPSTREAM_API_KEY into templates, and adds conditional S3 upload of the generated config (continues on failure with logs).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Init as Service Manager
  participant Script as startScript
  participant FS as File System
  participant ObjStore as ObjectStore (S3-compatible)
  participant AMP as AMP Upstream

  rect rgb(230,245,255)
    Init->>Script: launch startScript (with substituted paths)
  end

  Script->>FS: read ENV_FILE (fallback-friendly path)
  Script->>Script: inject env vars (incl. AMP_UPSTREAM_API_KEY) into templates
  Script->>FS: write generated config.yaml
  Note over Script,FS: local config created
  alt OBJECTSTORE_* present
    Script->>ObjStore: upload config to S3 endpoint (using OBJECTSTORE_ACCESS_KEY/SECRET)
    alt upload success
      ObjStore-->>Script: 200 OK
      Script->>Init: log success and continue
    else upload fail
      ObjStore-->>Script: error
      Script->>Init: log failure and continue
    end
  else no credentials
    Script->>Init: log missing credentials and continue
  end
  Script->>AMP: (if configured) use upstream key for AMP interactions
  Script->>Init: exit -> service proceeds to start with generated config
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 Hopping through configs with a twitchy nose,
AMP keys tucked in where the upstream flows.
I back up to S3 with a joyful hop,
GLM-4.7’s in the garden — don’t let it stop!
sniff-sniff — configs safe, time for a carrot stop.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: AMP API keys, GLM-4.7 support, and S3 config backup for cliproxyapi service.
Description check ✅ Passed The description comprehensively covers the pull request objectives including S3 backup, AMP authentication, GLM-4.7 support, and launchd path handling improvements.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

📜 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 6220231 and 6fc5a70.

📒 Files selected for processing (2)
  • config/cliproxyapi/config.yaml
  • home-manager/services/cliproxyapi/scripts/start.sh

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • GLM-4: Entity not found: Issue - Could not find referenced Issue.

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 significantly enhances the cliproxyapi service by improving its reliability and expanding its AI capabilities. It introduces a robust S3-based configuration backup mechanism and refines the service's launch process to ensure configuration stability, particularly in launchd environments. Additionally, it integrates support for AMP API key authentication and incorporates the latest GLM-4.7 model, broadening the range of available AI functionalities.

Highlights

  • Enhanced Service Reliability: Implemented S3 config backup and improved launchd path handling for cliproxyapi to prevent configuration corruption across service restarts.
  • AMP API Key Authentication: Added support for AMP API key authentication for client access and integrated upstream API key handling.
  • GLM-4.7 Model Support: Integrated the new GLM-4.7 model for improved AI capabilities across relevant configurations in both cliproxyapi and opencode.

🧠 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.

@mesa-dot-dev

mesa-dot-dev Bot commented Dec 25, 2025

Copy link
Copy Markdown

Mesa Description

TL;DR

Enhanced cliproxyapi with S3 config backup, AMP API key authentication, GLM-4.7 model support, and improved launchd startup reliability.

What changed?

  • config/cliproxyapi/config.yaml: Clarified API key comments, simplified example API key list, adjusted ampcode configuration, and added glm-4.7 model to openrouter and z-ai providers.
  • config/opencode/opencode.jsonc: Included "GLM-4.7 Coding Plan (via Z-AI)" model under Z-AI provider.
  • home-manager/services/cliproxyapi/default.nix: Refactored cliproxyapi service to embed awscli2 and gnused paths into start.sh at build time, updated ProgramArguments and ExecStart, and added pkgs.awscli2 and pkgs.coreutils to the service's PATH.
  • home-manager/services/cliproxyapi/scripts/start.sh: Explicitly defined ENV_FILE path, parameterized sed command, introduced __AMP_UPSTREAM_API_KEY__ placeholder, and added conditional S3 backup for config.yaml.

Description generated by Mesa. Update settings

@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 enhances the cliproxyapi service by adding support for AMP API keys, the GLM-4.7 model, and S3-based configuration backup for improved reliability. The changes look good overall, introducing valuable features. I've identified a few areas for improvement:

  • A potential security concern with allowing remote management access.
  • A hardcoded user path in a shell script that affects portability.
  • An opportunity to make the S3 backup process more robust by adding a timeout.
    Please see my detailed comments below.

restrict-management-to-localhost: true
# amp-upstream-api-key: "" # Optional - use AMP_API_KEY env var or ~/.local/share/amp/secrets.json
upstream-api-key: "__AMP_UPSTREAM_API_KEY__"
restrict-management-to-localhost: false

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.

security-high high

Changing restrict-management-to-localhost to false allows management access from any remote machine, which significantly increases the attack surface of the service. While access is still protected by a secret key, it's recommended to keep management endpoints restricted to localhost unless remote management is a strict requirement. If remote access is needed, consider firewalling the management port to a trusted set of IP addresses.

CONFIG="$CONFIG_DIR/config.yaml"
ENV_FILE="$HOME/dotfiles/.env"
# Use explicit path since $HOME may not be set correctly in launchd context
ENV_FILE="${HOME:-/Users/shunkakinoki}/dotfiles/.env"

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 hardcoded fallback path /Users/shunkakinoki makes the script non-portable and specific to a single user's machine setup. This harms reusability and maintainability. A better approach would be to pass the home directory path from the Nix configuration (e.g., using config.home.homeDirectory in default.nix) and substitute it into this script, avoiding any hardcoded user-specific paths.

# This prevents corrupted configs from persisting across restarts
if [ -n "${OBJECTSTORE_ENDPOINT:-}" ] && [ -n "${OBJECTSTORE_ACCESS_KEY:-}" ]; then
echo "Uploading config to S3 backup..." >&2
if AWS_ACCESS_KEY_ID="${OBJECTSTORE_ACCESS_KEY}" \

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

The aws s3 cp command could potentially hang, blocking the service from starting. To improve reliability, consider wrapping the command with timeout to prevent it from running indefinitely. The timeout utility is available since pkgs.coreutils is in the PATH.

Suggested change
if AWS_ACCESS_KEY_ID="${OBJECTSTORE_ACCESS_KEY}" \
if timeout 30s AWS_ACCESS_KEY_ID="${OBJECTSTORE_ACCESS_KEY}" \

@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.

1 issue found across 4 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="config/cliproxyapi/config.yaml">

<violation number="1" location="config/cliproxyapi/config.yaml:40">
P2: Changing `restrict-management-to-localhost` from `true` to `false` relaxes a security restriction, allowing remote access to AMP management endpoints. Ensure this is intentional and that proper authentication/authorization is in place to protect these endpoints from unauthorized remote access.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

restrict-management-to-localhost: true
# amp-upstream-api-key: "" # Optional - use AMP_API_KEY env var or ~/.local/share/amp/secrets.json
upstream-api-key: "__AMP_UPSTREAM_API_KEY__"
restrict-management-to-localhost: false

@cubic-dev-ai cubic-dev-ai Bot Dec 25, 2025

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.

P2: Changing restrict-management-to-localhost from true to false relaxes a security restriction, allowing remote access to AMP management endpoints. Ensure this is intentional and that proper authentication/authorization is in place to protect these endpoints from unauthorized remote access.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At config/cliproxyapi/config.yaml, line 40:

<comment>Changing `restrict-management-to-localhost` from `true` to `false` relaxes a security restriction, allowing remote access to AMP management endpoints. Ensure this is intentional and that proper authentication/authorization is in place to protect these endpoints from unauthorized remote access.</comment>

<file context>
@@ -34,11 +33,11 @@ quota-exceeded:
-  restrict-management-to-localhost: true
-# amp-upstream-api-key: &quot;&quot; # Optional - use AMP_API_KEY env var or ~/.local/share/amp/secrets.json
+  upstream-api-key: &quot;__AMP_UPSTREAM_API_KEY__&quot;
+  restrict-management-to-localhost: false
 
 # Gemini API keys (preferred)
</file context>
Fix with Cubic

Copilot AI 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.

Pull request overview

This PR enhances the cliproxyapi service with improved reliability and expanded AI model support. It addresses configuration corruption issues across service restarts by implementing S3-based config backups, adds authentication support for AMP API clients, and enables the GLM-4.7 model for improved AI capabilities.

  • Implements S3 config backup on service start to prevent configuration corruption
  • Adds AMP_API_KEY and AMP_UPSTREAM_API_KEY authentication support
  • Enables GLM-4.7 model support in both OpenRouter and Z-AI providers

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
home-manager/services/cliproxyapi/scripts/start.sh Adds S3 config upload functionality, improves launchd path handling with HOME fallback, and injects new AMP API key placeholders
home-manager/services/cliproxyapi/default.nix Implements path substitution for sed and aws commands using replaceVars, adds awscli2 to PATH for both launchd and systemd services
config/opencode/opencode.jsonc Adds GLM-4.7 Coding Plan model configuration for Z-AI provider
config/cliproxyapi/config.yaml Configures AMP API key authentication, adds GLM-4.7 model to both OpenRouter and Z-AI providers, and enables remote AMP management access

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

CONFIG="$CONFIG_DIR/config.yaml"
ENV_FILE="$HOME/dotfiles/.env"
# Use explicit path since $HOME may not be set correctly in launchd context
ENV_FILE="${HOME:-/Users/shunkakinoki}/dotfiles/.env"

Copilot AI Dec 25, 2025

Copy link

Choose a reason for hiding this comment

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

The HOME variable fallback uses a hardcoded username. While this may work for the specific user environment, consider making this more maintainable by using a configurable value passed from the Nix configuration where HOME is already set in the launchd Environment (line 21 of default.nix). The script could validate that HOME is set before using it, and fail early if it's not rather than falling back to a hardcoded path.

Copilot uses AI. Check for mistakes.

# Upload config to S3 to ensure backup is always correct
# This prevents corrupted configs from persisting across restarts
if [ -n "${OBJECTSTORE_ENDPOINT:-}" ] && [ -n "${OBJECTSTORE_ACCESS_KEY:-}" ]; then

Copilot AI Dec 25, 2025

Copy link

Choose a reason for hiding this comment

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

The S3 backup check only validates OBJECTSTORE_ENDPOINT and OBJECTSTORE_ACCESS_KEY, but the AWS CLI also requires OBJECTSTORE_SECRET_KEY to function properly. If the secret key is missing, the aws s3 cp command will fail. Add a check for OBJECTSTORE_SECRET_KEY in the condition to prevent attempting uploads that are guaranteed to fail.

Suggested change
if [ -n "${OBJECTSTORE_ENDPOINT:-}" ] && [ -n "${OBJECTSTORE_ACCESS_KEY:-}" ]; then
if [ -n "${OBJECTSTORE_ENDPOINT:-}" ] && [ -n "${OBJECTSTORE_ACCESS_KEY:-}" ] && [ -n "${OBJECTSTORE_SECRET_KEY:-}" ]; then

Copilot uses AI. Check for mistakes.
@@ -197,6 +197,9 @@
"models": {
"glm-4.6": {
"name": "GLM-4.6 (via Z-AI)",

Copilot AI Dec 25, 2025

Copy link

Choose a reason for hiding this comment

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

There is a trailing comma after the "name" field which violates JSON syntax. While JSONC (JSON with Comments) may be more lenient in some parsers, trailing commas after the last property in an object are not universally supported and could cause parsing errors.

Copilot uses AI. Check for mistakes.
restrict-management-to-localhost: true
# amp-upstream-api-key: "" # Optional - use AMP_API_KEY env var or ~/.local/share/amp/secrets.json
upstream-api-key: "__AMP_UPSTREAM_API_KEY__"
restrict-management-to-localhost: false

Copilot AI Dec 25, 2025

Copy link

Choose a reason for hiding this comment

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

The restrict-management-to-localhost setting is being changed from true to false. This opens up management endpoints to non-localhost access which could be a security risk if the API is exposed to untrusted networks. Ensure this change is intentional and that the management secret key is strong enough to prevent unauthorized access from remote locations.

Suggested change
restrict-management-to-localhost: false
restrict-management-to-localhost: true

Copilot uses AI. Check for mistakes.
Comment thread config/cliproxyapi/config.yaml Outdated
# api-keys:
# - "your-api-key-1"
# - "your-api-key-2"
# API keys for client authentication (e.g., Amp CLI)

Copilot AI Dec 25, 2025

Copy link

Choose a reason for hiding this comment

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

The comment says "API keys for client authentication (e.g., Amp CLI)" but only a single placeholder is configured. If multiple API keys are expected for different clients, the comment should clarify that additional keys can be added. Alternatively, if only one key is intended, consider updating the comment to match this single-key pattern or add a comment explaining how to add more keys.

Suggested change
# API keys for client authentication (e.g., Amp CLI)
# API keys for client authentication (e.g., Amp CLI). Add one or more keys as list items below.

Copilot uses AI. Check for mistakes.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread config/cliproxyapi/config.yaml Outdated
Comment on lines +16 to +18
# API keys for client authentication (e.g., Amp CLI)
api-keys:
- "__AMP_API_KEY__"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid enabling client auth with an empty API key

The template now always emits api-keys with a placeholder, and the start script replaces missing AMP_API_KEY with an empty string. If AMP_API_KEY is unset (common when not using Amp), the generated config will contain a blank key (""), which flips auth behavior compared to the previous config (no api-keys). Depending on cliproxyapi’s handling, this either blocks all clients (no one can authenticate) or allows unauthenticated access via an empty key. Consider omitting api-keys entirely when the env var is missing or rendering an empty list instead.

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 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 8a38e34 and 6220231.

📒 Files selected for processing (4)
  • config/cliproxyapi/config.yaml
  • config/opencode/opencode.jsonc
  • home-manager/services/cliproxyapi/default.nix
  • home-manager/services/cliproxyapi/scripts/start.sh
🧰 Additional context used
📓 Path-based instructions (10)
**/*.{json,yaml,yml,toml}

📄 CodeRabbit inference engine (.cursor/rules/formatting.mdc)

**/*.{json,yaml,yml,toml}: Use consistent indentation (2 spaces) in configuration files
Sort keys alphabetically when possible in configuration files
Use clear, descriptive names in configuration files

Files:

  • config/cliproxyapi/config.yaml
**/*.{yaml,yml,toml}

📄 CodeRabbit inference engine (.cursor/rules/formatting.mdc)

Add comments for complex configurations

Files:

  • config/cliproxyapi/config.yaml
**/*.nix

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.nix: Use nixfmt for formatting all Nix files
Document complex configurations with comments in Nix files

**/*.nix: Use 2 spaces for indentation in Nix files
Keep line length under 100 characters in Nix files
Sort attribute sets alphabetically in Nix files
Use consistent spacing around operators in Nix files
Format lists and sets consistently in Nix files

Use treefmt.toml for formatting Nix files

**/*.nix: Use mkOption for configurable options in Nix modules
Implement proper typing for all options in Nix modules
Follow the Nix expression language style guide

Files:

  • home-manager/services/cliproxyapi/default.nix
**/default.nix

📄 CodeRabbit inference engine (CLAUDE.md)

Use default.nix files for module exports

Files:

  • home-manager/services/cliproxyapi/default.nix
home-manager/services/*/default.nix

📄 CodeRabbit inference engine (.cursor/rules/home-manager.mdc)

Service configurations should be located in home-manager/services/<name>/ with proper service definitions and correct dependency handling

Files:

  • home-manager/services/cliproxyapi/default.nix
home-manager/services/**/default.nix

📄 CodeRabbit inference engine (.cursor/rules/home-manager.mdc)

Service configurations must include proper service definitions, handle dependencies correctly, and document service parameters

Files:

  • home-manager/services/cliproxyapi/default.nix
home-manager/**/*.nix

📄 CodeRabbit inference engine (.cursor/rules/home-manager.mdc)

home-manager/**/*.nix: Use typed options whenever possible in Nix configurations
Document all configuration options in Nix modules and programs
Follow home-manager's module structure and keep configurations modular
Use proper indentation and formatting in Nix configuration files

Files:

  • home-manager/services/cliproxyapi/default.nix
home-manager/services/**/*.nix

📄 CodeRabbit inference engine (.cursor/rules/nix.mdc)

Service configurations in home-manager/services/ should follow systemd service conventions, include proper service dependencies, and have clear documentation for service parameters

Files:

  • home-manager/services/cliproxyapi/default.nix
**/*.{js,jsx,ts,tsx,json,jsonc,md}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Use Biome for code formatting as configured in biome.json

Files:

  • config/opencode/opencode.jsonc
**/*.{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/start.sh
🧠 Learnings (4)
📓 Common learnings
Learnt from: CR
Repo: shunkakinoki/dotfiles PR: 0
File: .cursor/rules/general.mdc:0-0
Timestamp: 2025-11-25T09:34:40.062Z
Learning: Document all major changes in Nix configurations
📚 Learning: 2025-11-25T09:34:55.014Z
Learnt from: CR
Repo: shunkakinoki/dotfiles PR: 0
File: .cursor/rules/home-manager.mdc:0-0
Timestamp: 2025-11-25T09:34:55.014Z
Learning: Applies to home-manager/programs/**/*.nix : Follow program-specific best practices in program configuration files

Applied to files:

  • home-manager/services/cliproxyapi/default.nix
📚 Learning: 2025-11-25T09:34:55.014Z
Learnt from: CR
Repo: shunkakinoki/dotfiles PR: 0
File: .cursor/rules/home-manager.mdc:0-0
Timestamp: 2025-11-25T09:34:55.014Z
Learning: Applies to home-manager/services/**/default.nix : Service configurations must include proper service definitions, handle dependencies correctly, and document service parameters

Applied to files:

  • home-manager/services/cliproxyapi/default.nix
📚 Learning: 2025-11-25T09:35:01.066Z
Learnt from: CR
Repo: shunkakinoki/dotfiles PR: 0
File: .cursor/rules/nix.mdc:0-0
Timestamp: 2025-11-25T09:35:01.066Z
Learning: Applies to home-manager/services/**/*.nix : Service configurations in `home-manager/services/` should follow systemd service conventions, include proper service dependencies, and have clear documentation for service parameters

Applied to files:

  • home-manager/services/cliproxyapi/default.nix
⏰ 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). (15)
  • GitHub Check: Agent
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: lua-hammerspoon
  • GitHub Check: lua-neovim
  • GitHub Check: lua-neovim-test
  • GitHub Check: nix-darwin
  • GitHub Check: shellcheck
  • GitHub Check: e2e-run (MacOS, macos-latest)
  • GitHub Check: shellspec
  • GitHub Check: e2e-run (NixOS, ubuntu-latest)
  • GitHub Check: e2e-run (Ubuntu, ubuntu-latest)
  • GitHub Check: nix-nixos
  • GitHub Check: nix-linux
  • GitHub Check: docker-build-push (linux/arm64, arm64, ubuntu-24.04-arm)
  • GitHub Check: docker-build-push (linux/amd64, amd64, ubuntu-latest)
🔇 Additional comments (8)
config/opencode/opencode.jsonc (1)

200-203: LGTM!

The new GLM-4.7 model entry is properly formatted and consistent with the existing model configuration structure.

home-manager/services/cliproxyapi/default.nix (3)

4-9: Good use of build-time variable substitution.

The replaceVars pattern ensures consistent binary paths and follows Nix best practices for script generation.


13-35: LGTM!

Darwin launchd configuration correctly references the new startScript and includes awscli2 in the PATH for S3 backup operations.


37-59: LGTM!

Linux systemd configuration mirrors the Darwin changes appropriately, with correct PATH management and startScript reference.

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

30-36: LGTM!

Variable substitution pattern correctly uses the @sed@ placeholder and properly adds AMP API key handling.

config/cliproxyapi/config.yaml (3)

16-18: LGTM!

API keys configuration properly uses template placeholder that matches the substitution in start.sh.


72-87: LGTM!

GLM-4.7 model entries are properly configured for both openrouter and z-ai providers, consistent with the corresponding changes in opencode.jsonc.


36-40: Verify security implication of AMP integration management setting.

The configuration shows ampcode.restrict-management-to-localhost: false in the AMP integration section. This is distinct from the main management API setting (remote-management.allow-remote: true), which is clearly documented with security notes.

Before flagging this as a critical security issue, clarify:

  • What management endpoints does the ampcode.restrict-management-to-localhost setting control?
  • Is this a secondary management API for the AMP integration specifically?
  • What are the security implications of exposing AMP's management endpoints to remote access?

The setting name is self-documenting, but its security risk depends on what it actually controls in the application.

Comment on lines +8 to +9
# Use explicit path since $HOME may not be set correctly in launchd context
ENV_FILE="${HOME:-/Users/shunkakinoki}/dotfiles/.env"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Hardcoded user path breaks portability.

The fallback path /Users/shunkakinoki will fail for other users or on Linux systems. Consider using a more portable approach or failing explicitly when HOME is not set.

🔎 Suggested refactor for portable path handling
-# Use explicit path since $HOME may not be set correctly in launchd context
-ENV_FILE="${HOME:-/Users/shunkakinoki}/dotfiles/.env"
+# Use explicit path since $HOME may not be set correctly in launchd context
+# Fail explicitly if HOME is not set rather than using a hardcoded path
+if [ -z "${HOME:-}" ]; then
+  echo "ERROR: HOME environment variable not set" >&2
+  exit 1
+fi
+ENV_FILE="$HOME/dotfiles/.env"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Use explicit path since $HOME may not be set correctly in launchd context
ENV_FILE="${HOME:-/Users/shunkakinoki}/dotfiles/.env"
# Use explicit path since $HOME may not be set correctly in launchd context
# Fail explicitly if HOME is not set rather than using a hardcoded path
if [ -z "${HOME:-}" ]; then
echo "ERROR: HOME environment variable not set" >&2
exit 1
fi
ENV_FILE="$HOME/dotfiles/.env"
🤖 Prompt for AI Agents
In home-manager/services/cliproxyapi/scripts/start.sh around lines 8-9, remove
the hardcoded fallback /Users/shunkakinoki and instead require a valid HOME:
check if $HOME is set and non-empty and exit with a clear error if it isn't,
then construct ENV_FILE using "$HOME/dotfiles/.env" (no hardcoded user path) so
the script is portable across users and platforms.

Comment on lines +41 to +58
# Upload config to S3 to ensure backup is always correct
# This prevents corrupted configs from persisting across restarts
if [ -n "${OBJECTSTORE_ENDPOINT:-}" ] && [ -n "${OBJECTSTORE_ACCESS_KEY:-}" ]; then
echo "Uploading config to S3 backup..." >&2
if AWS_ACCESS_KEY_ID="${OBJECTSTORE_ACCESS_KEY}" \
AWS_SECRET_ACCESS_KEY="${OBJECTSTORE_SECRET_KEY}" \
@aws@ s3 cp \
--endpoint-url="${OBJECTSTORE_ENDPOINT}" \
--no-progress \
"$CONFIG" \
"s3://cliproxyapi/config/config.yaml" 2>&1; then
echo "✅ Config backup uploaded" >&2
else
echo "⚠️ Config backup failed (continuing anyway)" >&2
fi
else
echo "⚠️ S3 config backup skipped: missing credentials" >&2
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

S3 backup logic has performance and configurability concerns.

Two issues to consider:

  1. Synchronous backup delays startup: The S3 upload happens synchronously during service initialization, which can significantly delay startup if there are network issues.

  2. Hardcoded bucket name: Line 51 uses a hardcoded bucket name "cliproxyapi" instead of using the ${OBJECTSTORE_BUCKET} variable that's already exported on line 24.

🔎 Suggested improvements

For the hardcoded bucket name, use the environment variable:

-      "s3://cliproxyapi/config/config.yaml" 2>&1; then
+      "s3://${OBJECTSTORE_BUCKET}/config/config.yaml" 2>&1; then

For the startup delay concern, consider:

  • Making the S3 backup asynchronous (backgrounded)
  • Or moving it to the separate backup service that already runs periodically
  • Or adding a timeout to the AWS CLI command
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Upload config to S3 to ensure backup is always correct
# This prevents corrupted configs from persisting across restarts
if [ -n "${OBJECTSTORE_ENDPOINT:-}" ] && [ -n "${OBJECTSTORE_ACCESS_KEY:-}" ]; then
echo "Uploading config to S3 backup..." >&2
if AWS_ACCESS_KEY_ID="${OBJECTSTORE_ACCESS_KEY}" \
AWS_SECRET_ACCESS_KEY="${OBJECTSTORE_SECRET_KEY}" \
@aws@ s3 cp \
--endpoint-url="${OBJECTSTORE_ENDPOINT}" \
--no-progress \
"$CONFIG" \
"s3://cliproxyapi/config/config.yaml" 2>&1; then
echo "✅ Config backup uploaded" >&2
else
echo "⚠️ Config backup failed (continuing anyway)" >&2
fi
else
echo "⚠️ S3 config backup skipped: missing credentials" >&2
fi
# Upload config to S3 to ensure backup is always correct
# This prevents corrupted configs from persisting across restarts
if [ -n "${OBJECTSTORE_ENDPOINT:-}" ] && [ -n "${OBJECTSTORE_ACCESS_KEY:-}" ]; then
echo "Uploading config to S3 backup..." >&2
if AWS_ACCESS_KEY_ID="${OBJECTSTORE_ACCESS_KEY}" \
AWS_SECRET_ACCESS_KEY="${OBJECTSTORE_SECRET_KEY}" \
@aws@ s3 cp \
--endpoint-url="${OBJECTSTORE_ENDPOINT}" \
--no-progress \
"$CONFIG" \
"s3://${OBJECTSTORE_BUCKET}/config/config.yaml" 2>&1; then
echo "✅ Config backup uploaded" >&2
else
echo "⚠️ Config backup failed (continuing anyway)" >&2
fi
else
echo "⚠️ S3 config backup skipped: missing credentials" >&2
fi

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.

2 participants